@splitsoftware/splitio-commons 2.2.1-rc.1 → 2.2.1-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +2 -2
- package/README.md +0 -1
- package/cjs/evaluator/combiners/and.js +6 -2
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +5 -6
- package/cjs/evaluator/index.js +7 -7
- package/cjs/evaluator/matchers/index.js +1 -3
- package/cjs/evaluator/matchers/matcherTypes.js +0 -1
- package/cjs/evaluator/matchersTransform/index.js +0 -4
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +0 -1
- package/cjs/logger/constants.js +3 -4
- package/cjs/logger/messages/debug.js +2 -3
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/sdkFactory/index.js +3 -0
- package/cjs/services/splitApi.js +4 -3
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -5
- package/cjs/storages/KeyBuilder.js +0 -9
- package/cjs/storages/KeyBuilderCS.js +0 -3
- package/cjs/storages/KeyBuilderSS.js +0 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/cjs/storages/inLocalStorage/index.js +1 -5
- package/cjs/storages/inLocalStorage/validateCache.js +1 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/cjs/storages/inRedis/index.js +12 -6
- package/cjs/storages/pluggable/index.js +0 -2
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +4 -51
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +33 -51
- package/cjs/sync/streaming/SSEHandler/index.js +0 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +77 -106
- package/cjs/sync/streaming/constants.js +1 -2
- package/cjs/sync/streaming/pushManager.js +16 -3
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/utils/constants/index.js +2 -3
- package/esm/evaluator/combiners/and.js +6 -2
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +5 -6
- package/esm/evaluator/index.js +7 -7
- package/esm/evaluator/matchers/index.js +1 -3
- package/esm/evaluator/matchers/matcherTypes.js +0 -1
- package/esm/evaluator/matchersTransform/index.js +0 -4
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +0 -1
- package/esm/logger/constants.js +0 -1
- package/esm/logger/messages/debug.js +2 -3
- package/esm/logger/messages/warn.js +1 -1
- package/esm/sdkFactory/index.js +4 -1
- package/esm/services/splitApi.js +4 -3
- package/esm/storages/AbstractSplitsCacheSync.js +2 -5
- package/esm/storages/KeyBuilder.js +0 -9
- package/esm/storages/KeyBuilderCS.js +0 -3
- package/esm/storages/KeyBuilderSS.js +0 -3
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/esm/storages/inLocalStorage/index.js +1 -5
- package/esm/storages/inLocalStorage/validateCache.js +1 -2
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/esm/storages/inRedis/index.js +12 -6
- package/esm/storages/pluggable/index.js +0 -2
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +4 -51
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +33 -51
- package/esm/sync/streaming/SSEHandler/index.js +1 -2
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +73 -102
- package/esm/sync/streaming/constants.js +0 -1
- package/esm/sync/streaming/pushManager.js +19 -6
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/utils/constants/index.js +1 -2
- package/package.json +1 -1
- package/src/dtos/types.ts +8 -32
- package/src/evaluator/Engine.ts +1 -1
- package/src/evaluator/combiners/and.ts +4 -5
- package/src/evaluator/combiners/ifelseif.ts +9 -7
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +12 -12
- package/src/evaluator/index.ts +7 -7
- package/src/evaluator/matchers/index.ts +1 -3
- package/src/evaluator/matchers/matcherTypes.ts +0 -1
- package/src/evaluator/matchersTransform/index.ts +0 -3
- package/src/evaluator/parser/index.ts +3 -3
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +4 -5
- package/src/logger/constants.ts +0 -1
- package/src/logger/messages/debug.ts +2 -3
- package/src/logger/messages/warn.ts +1 -1
- package/src/sdkFactory/index.ts +4 -1
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +4 -3
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +3 -6
- package/src/storages/KeyBuilder.ts +0 -12
- package/src/storages/KeyBuilderCS.ts +0 -4
- package/src/storages/KeyBuilderSS.ts +0 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +14 -10
- package/src/storages/inLocalStorage/index.ts +1 -5
- package/src/storages/inLocalStorage/validateCache.ts +1 -3
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +0 -4
- package/src/storages/inRedis/index.ts +15 -8
- package/src/storages/pluggable/index.ts +0 -2
- package/src/storages/types.ts +2 -33
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +4 -62
- package/src/sync/polling/fetchers/types.ts +0 -1
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- package/src/sync/polling/syncTasks/splitsSyncTask.ts +1 -1
- package/src/sync/polling/types.ts +2 -2
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +42 -61
- package/src/sync/streaming/SSEHandler/index.ts +1 -2
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +68 -98
- package/src/sync/streaming/constants.ts +0 -1
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +18 -6
- package/src/sync/streaming/types.ts +2 -3
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/utils/constants/index.ts +1 -2
- package/src/utils/lang/index.ts +1 -1
- package/cjs/evaluator/matchers/rbsegment.js +0 -44
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -117
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +0 -61
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +0 -64
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +0 -64
- package/esm/evaluator/matchers/rbsegment.js +0 -40
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -114
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +0 -58
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +0 -61
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +0 -61
- package/src/evaluator/matchers/rbsegment.ts +0 -62
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +0 -136
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +0 -68
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +0 -79
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +0 -76
package/CHANGES.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
2.
|
|
2
|
-
-
|
|
1
|
+
2.2.1 (May 7, 2025)
|
|
2
|
+
- Updated Redis storage to avoid lazy require of the `ioredis` dependency when the SDK is initialized.
|
|
3
3
|
|
|
4
4
|
2.2.0 (March 28, 2025)
|
|
5
5
|
- Added a new optional argument to the client `getTreatment` methods to allow passing additional evaluation options, such as a map of properties to append to the generated impressions sent to Split backend. Read more in our docs.
|
package/README.md
CHANGED
|
@@ -27,7 +27,6 @@ Split has built and maintains SDKs for:
|
|
|
27
27
|
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
|
|
28
28
|
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
|
|
29
29
|
* Angular [Github](https://github.com/splitio/angular-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/6495326064397-Angular-utilities)
|
|
30
|
-
* Elixir thin-client [Github](https://github.com/splitio/elixir-thin-client) [Docs](https://help.split.io/hc/en-us/articles/26988707417869-Elixir-Thin-Client-SDK)
|
|
31
30
|
* Flutter [Github](https://github.com/splitio/flutter-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/8096158017165-Flutter-plugin)
|
|
32
31
|
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
|
|
33
32
|
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
|
|
@@ -11,8 +11,12 @@ function andCombinerContext(log, matchers) {
|
|
|
11
11
|
log.debug(constants_1.ENGINE_COMBINER_AND, [hasMatchedAll]);
|
|
12
12
|
return hasMatchedAll;
|
|
13
13
|
}
|
|
14
|
-
return function andCombiner(
|
|
15
|
-
var
|
|
14
|
+
return function andCombiner() {
|
|
15
|
+
var params = [];
|
|
16
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
17
|
+
params[_i] = arguments[_i];
|
|
18
|
+
}
|
|
19
|
+
var matcherResults = matchers.map(function (matcher) { return matcher.apply(void 0, params); });
|
|
16
20
|
// If any matching result is a thenable we should use Promise.all
|
|
17
21
|
if ((0, lang_1.findIndex)(matcherResults, thenable_1.thenable) !== -1) {
|
|
18
22
|
return Promise.all(matcherResults).then(andResults);
|
|
@@ -14,12 +14,12 @@ function ifElseIfCombinerContext(log, predicates) {
|
|
|
14
14
|
label: labels_1.UNSUPPORTED_MATCHER_TYPE
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
17
|
+
function computeTreatment(predicateResults) {
|
|
18
|
+
var len = predicateResults.length;
|
|
19
|
+
for (var i = 0; i < len; i++) {
|
|
19
20
|
var evaluation = predicateResults[i];
|
|
20
21
|
if (evaluation !== undefined) {
|
|
21
|
-
|
|
22
|
-
log.debug(constants_2.ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
22
|
+
log.debug(constants_2.ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
23
23
|
return evaluation;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -33,9 +33,9 @@ function ifElseIfCombinerContext(log, predicates) {
|
|
|
33
33
|
var predicateResults = predicates.map(function (evaluator) { return evaluator(key, seed, trafficAllocation, trafficAllocationSeed, attributes, splitEvaluator); });
|
|
34
34
|
// if we find a thenable
|
|
35
35
|
if ((0, lang_1.findIndex)(predicateResults, thenable_1.thenable) !== -1) {
|
|
36
|
-
return Promise.all(predicateResults).then(function (results) { return
|
|
36
|
+
return Promise.all(predicateResults).then(function (results) { return computeTreatment(results); });
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return computeTreatment(predicateResults);
|
|
39
39
|
}
|
|
40
40
|
// if there is none predicates, then there was an error in parsing phase
|
|
41
41
|
if (!Array.isArray(predicates) || predicates.length === 0) {
|
|
@@ -7,12 +7,11 @@ var labels_1 = require("../../utils/labels");
|
|
|
7
7
|
// Build Evaluation object if and only if matchingResult is true
|
|
8
8
|
function match(log, matchingResult, bucketingKey, seed, treatments, label) {
|
|
9
9
|
if (matchingResult) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
true;
|
|
10
|
+
var treatment = (0, engineUtils_1.getTreatment)(log, bucketingKey, seed, treatments);
|
|
11
|
+
return {
|
|
12
|
+
treatment: treatment,
|
|
13
|
+
label: label
|
|
14
|
+
};
|
|
16
15
|
}
|
|
17
16
|
// else we should notify the engine to continue evaluating
|
|
18
17
|
return undefined;
|
package/cjs/evaluator/index.js
CHANGED
|
@@ -29,12 +29,12 @@ function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
|
29
29
|
return treatmentException;
|
|
30
30
|
}
|
|
31
31
|
if ((0, thenable_1.thenable)(parsedSplit)) {
|
|
32
|
-
return parsedSplit.then(function (split) { return getEvaluation(log,
|
|
32
|
+
return parsedSplit.then(function (split) { return getEvaluation(log, split, key, attributes, storage); }).catch(
|
|
33
33
|
// Exception on async `getSplit` storage. For example, when the storage is redis or
|
|
34
34
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
35
35
|
function () { return treatmentException; });
|
|
36
36
|
}
|
|
37
|
-
return getEvaluation(log,
|
|
37
|
+
return getEvaluation(log, parsedSplit, key, attributes, storage);
|
|
38
38
|
}
|
|
39
39
|
exports.evaluateFeature = evaluateFeature;
|
|
40
40
|
function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
@@ -47,13 +47,13 @@ function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
|
47
47
|
return treatmentsException(splitNames);
|
|
48
48
|
}
|
|
49
49
|
return (0, thenable_1.thenable)(parsedSplits) ?
|
|
50
|
-
parsedSplits.then(function (splits) { return getEvaluations(log,
|
|
50
|
+
parsedSplits.then(function (splits) { return getEvaluations(log, splitNames, splits, key, attributes, storage); })
|
|
51
51
|
.catch(function () {
|
|
52
52
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
53
53
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
54
54
|
return treatmentsException(splitNames);
|
|
55
55
|
}) :
|
|
56
|
-
getEvaluations(log,
|
|
56
|
+
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
57
57
|
}
|
|
58
58
|
exports.evaluateFeatures = evaluateFeatures;
|
|
59
59
|
function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
|
|
@@ -90,7 +90,7 @@ function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, met
|
|
|
90
90
|
evaluate(storedFlagNames);
|
|
91
91
|
}
|
|
92
92
|
exports.evaluateFeaturesByFlagSets = evaluateFeaturesByFlagSets;
|
|
93
|
-
function getEvaluation(log,
|
|
93
|
+
function getEvaluation(log, splitJSON, key, attributes, storage) {
|
|
94
94
|
var evaluation = {
|
|
95
95
|
treatment: constants_1.CONTROL,
|
|
96
96
|
label: labels_1.SPLIT_NOT_FOUND,
|
|
@@ -116,11 +116,11 @@ function getEvaluation(log, key, splitJSON, attributes, storage) {
|
|
|
116
116
|
}
|
|
117
117
|
return evaluation;
|
|
118
118
|
}
|
|
119
|
-
function getEvaluations(log,
|
|
119
|
+
function getEvaluations(log, splitNames, splits, key, attributes, storage) {
|
|
120
120
|
var result = {};
|
|
121
121
|
var thenables = [];
|
|
122
122
|
splitNames.forEach(function (splitName) {
|
|
123
|
-
var evaluation = getEvaluation(log,
|
|
123
|
+
var evaluation = getEvaluation(log, splits[splitName], key, attributes, storage);
|
|
124
124
|
if ((0, thenable_1.thenable)(evaluation)) {
|
|
125
125
|
thenables.push(evaluation.then(function (res) {
|
|
126
126
|
result[splitName] = res;
|
|
@@ -24,7 +24,6 @@ var semver_gte_1 = require("./semver_gte");
|
|
|
24
24
|
var semver_lte_1 = require("./semver_lte");
|
|
25
25
|
var semver_between_1 = require("./semver_between");
|
|
26
26
|
var semver_inlist_1 = require("./semver_inlist");
|
|
27
|
-
var rbsegment_1 = require("./rbsegment");
|
|
28
27
|
var matchers = [
|
|
29
28
|
undefined,
|
|
30
29
|
all_1.allMatcherContext,
|
|
@@ -49,8 +48,7 @@ var matchers = [
|
|
|
49
48
|
semver_lte_1.lessThanEqualToSemverMatcherContext,
|
|
50
49
|
semver_between_1.betweenSemverMatcherContext,
|
|
51
50
|
semver_inlist_1.inListSemverMatcherContext,
|
|
52
|
-
large_segment_1.largeSegmentMatcherContext,
|
|
53
|
-
rbsegment_1.ruleBasedSegmentMatcherContext // IN_RULE_BASED_SEGMENT: 24
|
|
51
|
+
large_segment_1.largeSegmentMatcherContext, // IN_LARGE_SEGMENT: 23
|
|
54
52
|
];
|
|
55
53
|
/**
|
|
56
54
|
* Matcher factory.
|
|
@@ -81,10 +81,6 @@ function matchersTransform(matchers) {
|
|
|
81
81
|
type === matcherTypes_1.matcherTypes.LESS_THAN_OR_EQUAL_TO_SEMVER) {
|
|
82
82
|
value = stringMatcherData;
|
|
83
83
|
}
|
|
84
|
-
else if (type === matcherTypes_1.matcherTypes.IN_RULE_BASED_SEGMENT) {
|
|
85
|
-
value = (0, segment_1.segmentTransform)(userDefinedSegmentMatcherData);
|
|
86
|
-
dataType = matcherTypes_1.matcherDataTypes.NOT_SPECIFIED;
|
|
87
|
-
}
|
|
88
84
|
return {
|
|
89
85
|
attribute: attribute,
|
|
90
86
|
negate: negate,
|
|
@@ -53,9 +53,9 @@ function parser(log, conditions, storage) {
|
|
|
53
53
|
// and break the loop
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
|
-
predicates.push((0, condition_1.conditionContext)(log, (0, and_1.andCombinerContext)(log, expressions),
|
|
56
|
+
predicates.push((0, condition_1.conditionContext)(log, (0, and_1.andCombinerContext)(log, expressions), treatments_1.Treatments.parse(partitions), label, conditionType));
|
|
57
57
|
}
|
|
58
|
-
//
|
|
58
|
+
// Instanciate evaluator given the set of conditions using if else if logic
|
|
59
59
|
return (0, ifelseif_1.ifElseIfCombinerContext)(log, predicates);
|
|
60
60
|
}
|
|
61
61
|
exports.parser = parser;
|
|
@@ -52,7 +52,6 @@ function getProcessingFunction(matcherTypeID, dataType) {
|
|
|
52
52
|
case matcherTypes_1.matcherTypes.BETWEEN:
|
|
53
53
|
return dataType === 'DATETIME' ? convertions_1.zeroSinceSS : undefined;
|
|
54
54
|
case matcherTypes_1.matcherTypes.IN_SPLIT_TREATMENT:
|
|
55
|
-
case matcherTypes_1.matcherTypes.IN_RULE_BASED_SEGMENT:
|
|
56
55
|
return dependencyProcessor;
|
|
57
56
|
default:
|
|
58
57
|
return undefined;
|
package/cjs/logger/constants.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENGINE_VALUE_NO_ATTRIBUTES = exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.ENGINE_MATCHER_RESULT = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.
|
|
4
|
-
exports.ERROR_HTTP = exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.WARN_LOWERCASE_FLAGSET = exports.WARN_INVALID_FLAGSET = exports.STREAMING_PARSING_SPLIT_UPDATE = exports.STREAMING_PARSING_MEMBERSHIPS_UPDATE = exports.WARN_SDK_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY =
|
|
5
|
-
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN =
|
|
3
|
+
exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.ENGINE_MATCHER_RESULT = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_UPDATE = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
|
+
exports.ERROR_STORAGE_INVALID = exports.ERROR_HTTP = exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.WARN_LOWERCASE_FLAGSET = exports.WARN_INVALID_FLAGSET = exports.STREAMING_PARSING_SPLIT_UPDATE = exports.STREAMING_PARSING_MEMBERSHIPS_UPDATE = exports.WARN_SDK_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = void 0;
|
|
5
|
+
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
8
8
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -26,7 +26,6 @@ exports.RETRIEVE_MANAGER = 29;
|
|
|
26
26
|
exports.SYNC_OFFLINE_DATA = 30;
|
|
27
27
|
exports.SYNC_SPLITS_FETCH = 31;
|
|
28
28
|
exports.SYNC_SPLITS_UPDATE = 32;
|
|
29
|
-
exports.SYNC_RBS_UPDATE = 33;
|
|
30
29
|
exports.STREAMING_NEW_MESSAGE = 35;
|
|
31
30
|
exports.SYNC_TASK_START = 36;
|
|
32
31
|
exports.SYNC_TASK_EXECUTE = 37;
|
|
@@ -23,9 +23,8 @@ exports.codesDebug = info_1.codesInfo.concat([
|
|
|
23
23
|
[c.RETRIEVE_MANAGER, 'Retrieving manager instance.'],
|
|
24
24
|
// synchronizer
|
|
25
25
|
[c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Feature flags data: \n%s'],
|
|
26
|
-
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up feature flags update using since = %s
|
|
27
|
-
[c.SYNC_SPLITS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s. Removed feature flags %s.'],
|
|
28
|
-
[c.SYNC_RBS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New rule-based segments %s. Removed rule-based segments %s.'],
|
|
26
|
+
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up feature flags update using since = %s'],
|
|
27
|
+
[c.SYNC_SPLITS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s. Removed feature flags %s. Segment names collected %s'],
|
|
29
28
|
[c.STREAMING_NEW_MESSAGE, c.LOG_PREFIX_SYNC_STREAMING + 'New SSE message received, with data: %s.'],
|
|
30
29
|
[c.SYNC_TASK_START, c.LOG_PREFIX_SYNC + ': Starting %s. Running each %s millis'],
|
|
31
30
|
[c.SYNC_TASK_EXECUTE, c.LOG_PREFIX_SYNC + ': Running %s'],
|
|
@@ -35,7 +35,7 @@ exports.codesWarn = error_1.codesError.concat([
|
|
|
35
35
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': feature flag filter configuration must be a non-empty array of filter objects.'],
|
|
36
36
|
[c.WARN_SDK_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
37
37
|
[c.STREAMING_PARSING_MEMBERSHIPS_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching Memberships due to an error processing %s notification: %s'],
|
|
38
|
-
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing
|
|
38
|
+
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing SPLIT_UPDATE notification: %s'],
|
|
39
39
|
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
40
40
|
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
|
41
41
|
[c.WARN_FLAGSET_WITHOUT_FLAGS, '%s: you passed %s flag set that does not contain cached feature flag names. Please double check what flag sets are in use in the Split user interface.'],
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -45,6 +45,9 @@ function sdkFactory(params) {
|
|
|
45
45
|
readiness.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
|
|
46
46
|
readiness.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
47
47
|
},
|
|
48
|
+
onReadyFromCacheCb: function () {
|
|
49
|
+
readiness.splits.emit(constants_2.SDK_SPLITS_CACHE_LOADED);
|
|
50
|
+
}
|
|
48
51
|
});
|
|
49
52
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
50
53
|
var clients = {};
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -20,6 +20,7 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
20
20
|
var urls = settings.urls;
|
|
21
21
|
var filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
|
|
22
22
|
var SplitSDKImpressionsMode = settings.sync.impressionsMode;
|
|
23
|
+
var flagSpecVersion = settings.sync.flagSpecVersion;
|
|
23
24
|
var splitHttpClient = (0, splitHttpClient_1.splitHttpClientFactory)(settings, platform);
|
|
24
25
|
return {
|
|
25
26
|
// @TODO throw errors if health check requests fail, to log them in the Synchronizer
|
|
@@ -32,7 +33,7 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
32
33
|
return splitHttpClient(url).then(function () { return true; }).catch(function () { return false; });
|
|
33
34
|
},
|
|
34
35
|
fetchAuth: function (userMatchingKeys) {
|
|
35
|
-
var url = urls.auth + "/v2/auth?s=" +
|
|
36
|
+
var url = urls.auth + "/v2/auth?s=" + flagSpecVersion;
|
|
36
37
|
if (userMatchingKeys) { // `userMatchingKeys` is undefined in server-side
|
|
37
38
|
var queryParams = userMatchingKeys.map(userKeyToQueryParam).join('&');
|
|
38
39
|
if (queryParams)
|
|
@@ -40,8 +41,8 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
40
41
|
}
|
|
41
42
|
return splitHttpClient(url, undefined, telemetryTracker.trackHttp(constants_1.TOKEN));
|
|
42
43
|
},
|
|
43
|
-
fetchSplitChanges: function (since, noCache, till
|
|
44
|
-
var url = urls.sdk + "/splitChanges?s=" +
|
|
44
|
+
fetchSplitChanges: function (since, noCache, till) {
|
|
45
|
+
var url = urls.sdk + "/splitChanges?s=" + flagSpecVersion + "&since=" + since + (filterQueryString || '') + (till ? '&till=' + till : '');
|
|
45
46
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.SPLITS))
|
|
46
47
|
.catch(function (err) {
|
|
47
48
|
if (err.statusCode === 414)
|
|
@@ -53,8 +53,8 @@ exports.AbstractSplitsCacheSync = AbstractSplitsCacheSync;
|
|
|
53
53
|
* Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
|
|
54
54
|
* This util is intended to simplify the implementation of `splitsCache::usesSegments` method
|
|
55
55
|
*/
|
|
56
|
-
function usesSegments(
|
|
57
|
-
var conditions =
|
|
56
|
+
function usesSegments(split) {
|
|
57
|
+
var conditions = split.conditions || [];
|
|
58
58
|
for (var i = 0; i < conditions.length; i++) {
|
|
59
59
|
var matchers = conditions[i].matcherGroup.matchers;
|
|
60
60
|
for (var j = 0; j < matchers.length; j++) {
|
|
@@ -63,9 +63,6 @@ function usesSegments(ruleEntity) {
|
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
var excluded = ruleEntity.excluded;
|
|
67
|
-
if (excluded && excluded.segments && excluded.segments.length > 0)
|
|
68
|
-
return true;
|
|
69
66
|
return false;
|
|
70
67
|
}
|
|
71
68
|
exports.usesSegments = usesSegments;
|
|
@@ -28,15 +28,6 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
28
28
|
KeyBuilder.prototype.buildSplitKeyPrefix = function () {
|
|
29
29
|
return this.prefix + ".split.";
|
|
30
30
|
};
|
|
31
|
-
KeyBuilder.prototype.buildRBSegmentKey = function (rbsegmentName) {
|
|
32
|
-
return this.prefix + ".rbsegment." + rbsegmentName;
|
|
33
|
-
};
|
|
34
|
-
KeyBuilder.prototype.buildRBSegmentsTillKey = function () {
|
|
35
|
-
return this.prefix + ".rbsegments.till";
|
|
36
|
-
};
|
|
37
|
-
KeyBuilder.prototype.buildRBSegmentKeyPrefix = function () {
|
|
38
|
-
return this.prefix + ".rbsegment.";
|
|
39
|
-
};
|
|
40
31
|
KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) {
|
|
41
32
|
return this.prefix + ".segment." + segmentName;
|
|
42
33
|
};
|
|
@@ -35,9 +35,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
35
35
|
KeyBuilderCS.prototype.isSplitKey = function (key) {
|
|
36
36
|
return (0, lang_1.startsWith)(key, this.prefix + ".split.");
|
|
37
37
|
};
|
|
38
|
-
KeyBuilderCS.prototype.isRBSegmentKey = function (key) {
|
|
39
|
-
return (0, lang_1.startsWith)(key, this.prefix + ".rbsegment.");
|
|
40
|
-
};
|
|
41
38
|
KeyBuilderCS.prototype.buildSplitsWithSegmentCountKey = function () {
|
|
42
39
|
return this.prefix + ".splits.usingSegments";
|
|
43
40
|
};
|
|
@@ -42,9 +42,6 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
42
42
|
KeyBuilderSS.prototype.searchPatternForSplitKeys = function () {
|
|
43
43
|
return this.buildSplitKeyPrefix() + "*";
|
|
44
44
|
};
|
|
45
|
-
KeyBuilderSS.prototype.searchPatternForRBSegmentKeys = function () {
|
|
46
|
-
return this.buildRBSegmentKeyPrefix() + "*";
|
|
47
|
-
};
|
|
48
45
|
/* Telemetry keys */
|
|
49
46
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
50
47
|
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + exports.METHOD_NAMES[method] + "/" + bucket;
|
|
@@ -41,13 +41,15 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
41
41
|
};
|
|
42
42
|
SplitsCacheInLocal.prototype._incrementCounts = function (split) {
|
|
43
43
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
localStorage.setItem(ttKey, (0, lang_1.toNumber)(localStorage.getItem(ttKey)) + 1);
|
|
47
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
48
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
44
|
+
if (split) {
|
|
45
|
+
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
49
46
|
// @ts-expect-error
|
|
50
|
-
localStorage.setItem(
|
|
47
|
+
localStorage.setItem(ttKey, (0, lang_1.toNumber)(localStorage.getItem(ttKey)) + 1);
|
|
48
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
49
|
+
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
50
|
+
// @ts-expect-error
|
|
51
|
+
localStorage.setItem(segmentsCountKey, (0, lang_1.toNumber)(localStorage.getItem(segmentsCountKey)) + 1);
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
catch (e) {
|
|
@@ -156,9 +158,12 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
156
158
|
return true;
|
|
157
159
|
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
158
160
|
var splitsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
|
|
159
|
-
|
|
160
|
-
splitsWithSegmentsCount > 0
|
|
161
|
-
|
|
161
|
+
if ((0, lang_1.isFiniteNumber)(splitsWithSegmentsCount)) {
|
|
162
|
+
return splitsWithSegmentsCount > 0;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
162
167
|
};
|
|
163
168
|
SplitsCacheInLocal.prototype.getNamesByFlagSets = function (flagSets) {
|
|
164
169
|
var _this = this;
|
|
@@ -8,7 +8,6 @@ var KeyBuilder_1 = require("../KeyBuilder");
|
|
|
8
8
|
var KeyBuilderCS_1 = require("../KeyBuilderCS");
|
|
9
9
|
var isLocalStorageAvailable_1 = require("../../utils/env/isLocalStorageAvailable");
|
|
10
10
|
var SplitsCacheInLocal_1 = require("./SplitsCacheInLocal");
|
|
11
|
-
var RBSegmentsCacheInLocal_1 = require("./RBSegmentsCacheInLocal");
|
|
12
11
|
var MySegmentsCacheInLocal_1 = require("./MySegmentsCacheInLocal");
|
|
13
12
|
var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
|
|
14
13
|
var constants_1 = require("./constants");
|
|
@@ -33,12 +32,10 @@ function InLocalStorage(options) {
|
|
|
33
32
|
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
34
33
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
35
34
|
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys);
|
|
36
|
-
var rbSegments = new RBSegmentsCacheInLocal_1.RBSegmentsCacheInLocal(settings, keys);
|
|
37
35
|
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
38
36
|
var largeSegments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey));
|
|
39
37
|
return {
|
|
40
38
|
splits: splits,
|
|
41
|
-
rbSegments: rbSegments,
|
|
42
39
|
segments: segments,
|
|
43
40
|
largeSegments: largeSegments,
|
|
44
41
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -47,14 +44,13 @@ function InLocalStorage(options) {
|
|
|
47
44
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
48
45
|
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
49
46
|
validateCache: function () {
|
|
50
|
-
return (0, validateCache_1.validateCache)(options, settings, keys, splits,
|
|
47
|
+
return (0, validateCache_1.validateCache)(options, settings, keys, splits, segments, largeSegments);
|
|
51
48
|
},
|
|
52
49
|
destroy: function () { },
|
|
53
50
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
|
|
54
51
|
shared: function (matchingKey) {
|
|
55
52
|
return {
|
|
56
53
|
splits: this.splits,
|
|
57
|
-
rbSegments: this.rbSegments,
|
|
58
54
|
segments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey)),
|
|
59
55
|
largeSegments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey)),
|
|
60
56
|
impressions: this.impressions,
|
|
@@ -57,12 +57,11 @@ function validateExpiration(options, settings, keys, currentTimestamp, isThereCa
|
|
|
57
57
|
*
|
|
58
58
|
* @returns `true` if cache is ready to be used, `false` otherwise (cache was cleared or there is no cache)
|
|
59
59
|
*/
|
|
60
|
-
function validateCache(options, settings, keys, splits,
|
|
60
|
+
function validateCache(options, settings, keys, splits, segments, largeSegments) {
|
|
61
61
|
var currentTimestamp = Date.now();
|
|
62
62
|
var isThereCache = splits.getChangeNumber() > -1;
|
|
63
63
|
if (validateExpiration(options, settings, keys, currentTimestamp, isThereCache)) {
|
|
64
64
|
splits.clear();
|
|
65
|
-
rbSegments.clear();
|
|
66
65
|
segments.clear();
|
|
67
66
|
largeSegments.clear();
|
|
68
67
|
// Update last clear timestamp
|
|
@@ -9,7 +9,6 @@ var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory")
|
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
11
|
var UniqueKeysCacheInMemory_1 = require("./UniqueKeysCacheInMemory");
|
|
12
|
-
var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
|
|
13
12
|
/**
|
|
14
13
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
15
14
|
*
|
|
@@ -18,11 +17,9 @@ var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
|
|
|
18
17
|
function InMemoryStorageFactory(params) {
|
|
19
18
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
20
19
|
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
21
|
-
var rbSegments = new RBSegmentsCacheInMemory_1.RBSegmentsCacheInMemory();
|
|
22
20
|
var segments = new SegmentsCacheInMemory_1.SegmentsCacheInMemory();
|
|
23
21
|
var storage = {
|
|
24
22
|
splits: splits,
|
|
25
|
-
rbSegments: rbSegments,
|
|
26
23
|
segments: segments,
|
|
27
24
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
28
25
|
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
@@ -9,7 +9,6 @@ var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory")
|
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
11
|
var UniqueKeysCacheInMemoryCS_1 = require("./UniqueKeysCacheInMemoryCS");
|
|
12
|
-
var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
|
|
13
12
|
/**
|
|
14
13
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
15
14
|
*
|
|
@@ -18,12 +17,10 @@ var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
|
|
|
18
17
|
function InMemoryStorageCSFactory(params) {
|
|
19
18
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
20
19
|
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
21
|
-
var rbSegments = new RBSegmentsCacheInMemory_1.RBSegmentsCacheInMemory();
|
|
22
20
|
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
23
21
|
var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
24
22
|
var storage = {
|
|
25
23
|
splits: splits,
|
|
26
|
-
rbSegments: rbSegments,
|
|
27
24
|
segments: segments,
|
|
28
25
|
largeSegments: largeSegments,
|
|
29
26
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -36,7 +33,6 @@ function InMemoryStorageCSFactory(params) {
|
|
|
36
33
|
shared: function () {
|
|
37
34
|
return {
|
|
38
35
|
splits: this.splits,
|
|
39
|
-
rbSegments: this.rbSegments,
|
|
40
36
|
segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
41
37
|
largeSegments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
42
38
|
impressions: this.impressions,
|
|
@@ -12,25 +12,32 @@ var TelemetryCacheInRedis_1 = require("./TelemetryCacheInRedis");
|
|
|
12
12
|
var UniqueKeysCacheInRedis_1 = require("./UniqueKeysCacheInRedis");
|
|
13
13
|
var ImpressionCountsCacheInRedis_1 = require("./ImpressionCountsCacheInRedis");
|
|
14
14
|
var utils_1 = require("../utils");
|
|
15
|
-
var
|
|
15
|
+
var RD;
|
|
16
|
+
try {
|
|
17
|
+
// Using `require` to prevent error when bundling or importing the SDK in a .mjs file, since ioredis is a CommonJS module.
|
|
18
|
+
// Redis storage is not supported with .mjs files.
|
|
19
|
+
RD = require('./RedisAdapter').RedisAdapter;
|
|
20
|
+
}
|
|
21
|
+
catch (error) { /* empty */ }
|
|
16
22
|
/**
|
|
17
23
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.js
|
|
18
24
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
19
25
|
*/
|
|
20
26
|
function InRedisStorage(options) {
|
|
21
27
|
if (options === void 0) { options = {}; }
|
|
22
|
-
// Lazy loading to prevent error when bundling or importing the SDK in a .mjs file, since ioredis is a CommonJS module.
|
|
23
|
-
// Redis storage is not supported with .mjs files.
|
|
24
|
-
var RD = require('./RedisAdapter').RedisAdapter;
|
|
25
28
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
26
29
|
function InRedisStorageFactory(params) {
|
|
27
|
-
|
|
30
|
+
if (!RD)
|
|
31
|
+
throw new Error('The SDK Redis storage is not available. Your runtime environment must support CommonJS (`require`) to import the ioredis dependency.');
|
|
32
|
+
var onReadyFromCacheCb = params.onReadyFromCacheCb, onReadyCb = params.onReadyCb, settings = params.settings, log = params.settings.log;
|
|
28
33
|
var metadata = (0, utils_1.metadataBuilder)(settings);
|
|
29
34
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
30
35
|
var redisClient = new RD(log, options.options || {});
|
|
31
36
|
var telemetry = new TelemetryCacheInRedis_1.TelemetryCacheInRedis(log, keys, redisClient);
|
|
32
37
|
var impressionCountsCache = new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient);
|
|
33
38
|
var uniqueKeysCache = new UniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient);
|
|
39
|
+
// RedisAdapter queues operations before connection
|
|
40
|
+
onReadyFromCacheCb();
|
|
34
41
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
35
42
|
redisClient.on('connect', function () {
|
|
36
43
|
onReadyCb();
|
|
@@ -41,7 +48,6 @@ function InRedisStorage(options) {
|
|
|
41
48
|
});
|
|
42
49
|
return {
|
|
43
50
|
splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
|
|
44
|
-
rbSegments: new RBSegmentsCacheInRedis_1.RBSegmentsCacheInRedis(log, keys, redisClient),
|
|
45
51
|
segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
|
|
46
52
|
impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
47
53
|
impressionCounts: impressionCountsCache,
|
|
@@ -22,7 +22,6 @@ var UniqueKeysCacheInMemory_1 = require("../inMemory/UniqueKeysCacheInMemory");
|
|
|
22
22
|
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
23
23
|
var utils_1 = require("../utils");
|
|
24
24
|
var constants_2 = require("../pluggable/constants");
|
|
25
|
-
var RBSegmentsCachePluggable_1 = require("./RBSegmentsCachePluggable");
|
|
26
25
|
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
27
26
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
28
27
|
/**
|
|
@@ -106,7 +105,6 @@ function PluggableStorage(options) {
|
|
|
106
105
|
});
|
|
107
106
|
return {
|
|
108
107
|
splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
109
|
-
rbSegments: new RBSegmentsCachePluggable_1.RBSegmentsCachePluggable(log, keys, wrapper),
|
|
110
108
|
segments: new SegmentsCachePluggable_1.SegmentsCachePluggable(log, keys, wrapper),
|
|
111
109
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable_1.ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
112
110
|
impressionCounts: impressionCountsCache,
|