@splitsoftware/splitio-commons 2.1.1-rc.0 → 2.1.1-rc.1
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 +3 -0
- 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/error.js +1 -1
- package/cjs/logger/messages/warn.js +2 -2
- package/cjs/sdkClient/client.js +29 -19
- package/cjs/sdkClient/clientAttributesDecoration.js +19 -25
- package/cjs/sdkClient/clientInputValidation.js +28 -26
- package/cjs/services/splitApi.js +2 -2
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -5
- package/cjs/storages/KeyBuilder.js +0 -9
- package/cjs/storages/KeyBuilderCS.js +1 -4
- package/cjs/storages/KeyBuilderSS.js +0 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/cjs/storages/inLocalStorage/index.js +0 -4
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/cjs/storages/inRedis/index.js +0 -2
- package/cjs/storages/pluggable/index.js +0 -2
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- 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 +35 -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/submitters/impressionsSubmitter.js +3 -2
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/trackers/strategy/strategyOptimized.js +3 -0
- package/cjs/utils/constants/index.js +2 -3
- package/cjs/utils/inputValidation/eventProperties.js +12 -1
- package/cjs/utils/inputValidation/index.js +3 -1
- 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/error.js +1 -1
- package/esm/logger/messages/warn.js +2 -2
- package/esm/sdkClient/client.js +29 -19
- package/esm/sdkClient/clientAttributesDecoration.js +19 -25
- package/esm/sdkClient/clientInputValidation.js +29 -27
- package/esm/services/splitApi.js +2 -2
- package/esm/storages/AbstractSplitsCacheSync.js +2 -5
- package/esm/storages/KeyBuilder.js +0 -9
- package/esm/storages/KeyBuilderCS.js +1 -4
- package/esm/storages/KeyBuilderSS.js +0 -3
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/esm/storages/inLocalStorage/index.js +0 -4
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/esm/storages/inRedis/index.js +0 -2
- package/esm/storages/pluggable/index.js +0 -2
- package/esm/storages/utils.js +1 -0
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- 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 +35 -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/submitters/impressionsSubmitter.js +3 -2
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/trackers/strategy/strategyOptimized.js +3 -0
- package/esm/utils/constants/index.js +1 -2
- package/esm/utils/inputValidation/eventProperties.js +10 -0
- package/esm/utils/inputValidation/index.js +1 -0
- 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/error.ts +1 -1
- package/src/logger/messages/warn.ts +2 -2
- package/src/sdkClient/client.ts +31 -21
- package/src/sdkClient/clientAttributesDecoration.ts +20 -27
- package/src/sdkClient/clientInputValidation.ts +30 -27
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +2 -2
- 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 +1 -5
- package/src/storages/KeyBuilderSS.ts +0 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +14 -10
- package/src/storages/inLocalStorage/index.ts +0 -4
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +0 -4
- package/src/storages/inRedis/index.ts +0 -2
- package/src/storages/pluggable/index.ts +0 -2
- package/src/storages/types.ts +1 -33
- package/src/storages/utils.ts +1 -0
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +1 -2
- package/src/sync/polling/fetchers/types.ts +0 -1
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- 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 +44 -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/submitters/impressionsSubmitter.ts +3 -2
- package/src/sync/submitters/types.ts +23 -33
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/trackers/strategy/strategyOptimized.ts +3 -0
- package/src/utils/constants/index.ts +1 -2
- package/src/utils/inputValidation/eventProperties.ts +10 -0
- package/src/utils/inputValidation/index.ts +1 -0
- package/src/utils/lang/index.ts +1 -1
- package/types/splitio.d.ts +100 -35
- package/cjs/evaluator/matchers/rbsegment.js +0 -43
- 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 -39
- 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 -61
- 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/esm/sdkClient/client.js
CHANGED
|
@@ -15,6 +15,14 @@ function treatmentsNotReady(featureFlagNames) {
|
|
|
15
15
|
});
|
|
16
16
|
return evaluations;
|
|
17
17
|
}
|
|
18
|
+
function stringify(options) {
|
|
19
|
+
if (options && options.properties) {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.stringify(options.properties);
|
|
22
|
+
}
|
|
23
|
+
catch ( /* JSON.stringify should never throw with validated options, but handling just in case */_a) { /* JSON.stringify should never throw with validated options, but handling just in case */ }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
18
26
|
/**
|
|
19
27
|
* Creator of base client with getTreatments and track methods.
|
|
20
28
|
*/
|
|
@@ -22,13 +30,13 @@ export function clientFactory(params) {
|
|
|
22
30
|
var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, eventTracker = params.eventTracker, telemetryTracker = params.telemetryTracker;
|
|
23
31
|
var log = settings.log, mode = settings.mode;
|
|
24
32
|
var isAsync = isConsumerMode(mode);
|
|
25
|
-
function getTreatment(key, featureFlagName, attributes, withConfig, methodName) {
|
|
33
|
+
function getTreatment(key, featureFlagName, attributes, options, withConfig, methodName) {
|
|
26
34
|
if (withConfig === void 0) { withConfig = false; }
|
|
27
35
|
if (methodName === void 0) { methodName = GET_TREATMENT; }
|
|
28
36
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENT_WITH_CONFIG : TREATMENT);
|
|
29
37
|
var wrapUp = function (evaluationResult) {
|
|
30
38
|
var queue = [];
|
|
31
|
-
var treatment = processEvaluation(evaluationResult, featureFlagName, key,
|
|
39
|
+
var treatment = processEvaluation(evaluationResult, featureFlagName, key, stringify(options), withConfig, methodName, queue);
|
|
32
40
|
impressionsTracker.track(queue, attributes);
|
|
33
41
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
34
42
|
return treatment;
|
|
@@ -40,18 +48,19 @@ export function clientFactory(params) {
|
|
|
40
48
|
treatmentNotReady;
|
|
41
49
|
return thenable(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
|
|
42
50
|
}
|
|
43
|
-
function getTreatmentWithConfig(key, featureFlagName, attributes) {
|
|
44
|
-
return getTreatment(key, featureFlagName, attributes, true, GET_TREATMENT_WITH_CONFIG);
|
|
51
|
+
function getTreatmentWithConfig(key, featureFlagName, attributes, options) {
|
|
52
|
+
return getTreatment(key, featureFlagName, attributes, options, true, GET_TREATMENT_WITH_CONFIG);
|
|
45
53
|
}
|
|
46
|
-
function getTreatments(key, featureFlagNames, attributes, withConfig, methodName) {
|
|
54
|
+
function getTreatments(key, featureFlagNames, attributes, options, withConfig, methodName) {
|
|
47
55
|
if (withConfig === void 0) { withConfig = false; }
|
|
48
56
|
if (methodName === void 0) { methodName = GET_TREATMENTS; }
|
|
49
57
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENTS_WITH_CONFIG : TREATMENTS);
|
|
50
58
|
var wrapUp = function (evaluationResults) {
|
|
51
59
|
var queue = [];
|
|
52
60
|
var treatments = {};
|
|
61
|
+
var properties = stringify(options);
|
|
53
62
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
54
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key,
|
|
63
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, properties, withConfig, methodName, queue);
|
|
55
64
|
});
|
|
56
65
|
impressionsTracker.track(queue, attributes);
|
|
57
66
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
@@ -64,10 +73,10 @@ export function clientFactory(params) {
|
|
|
64
73
|
treatmentsNotReady(featureFlagNames);
|
|
65
74
|
return thenable(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
66
75
|
}
|
|
67
|
-
function getTreatmentsWithConfig(key, featureFlagNames, attributes) {
|
|
68
|
-
return getTreatments(key, featureFlagNames, attributes, true, GET_TREATMENTS_WITH_CONFIG);
|
|
76
|
+
function getTreatmentsWithConfig(key, featureFlagNames, attributes, options) {
|
|
77
|
+
return getTreatments(key, featureFlagNames, attributes, options, true, GET_TREATMENTS_WITH_CONFIG);
|
|
69
78
|
}
|
|
70
|
-
function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method, methodName) {
|
|
79
|
+
function getTreatmentsByFlagSets(key, flagSetNames, attributes, options, withConfig, method, methodName) {
|
|
71
80
|
if (withConfig === void 0) { withConfig = false; }
|
|
72
81
|
if (method === void 0) { method = TREATMENTS_BY_FLAGSETS; }
|
|
73
82
|
if (methodName === void 0) { methodName = GET_TREATMENTS_BY_FLAG_SETS; }
|
|
@@ -75,9 +84,9 @@ export function clientFactory(params) {
|
|
|
75
84
|
var wrapUp = function (evaluationResults) {
|
|
76
85
|
var queue = [];
|
|
77
86
|
var treatments = {};
|
|
78
|
-
var
|
|
79
|
-
Object.keys(
|
|
80
|
-
treatments[featureFlagName] = processEvaluation(
|
|
87
|
+
var properties = stringify(options);
|
|
88
|
+
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
89
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, properties, withConfig, methodName, queue);
|
|
81
90
|
});
|
|
82
91
|
impressionsTracker.track(queue, attributes);
|
|
83
92
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
@@ -90,17 +99,17 @@ export function clientFactory(params) {
|
|
|
90
99
|
{};
|
|
91
100
|
return thenable(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
92
101
|
}
|
|
93
|
-
function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes) {
|
|
94
|
-
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
|
|
102
|
+
function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes, options) {
|
|
103
|
+
return getTreatmentsByFlagSets(key, flagSetNames, attributes, options, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
|
|
95
104
|
}
|
|
96
|
-
function getTreatmentsByFlagSet(key, flagSetName, attributes) {
|
|
97
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET, GET_TREATMENTS_BY_FLAG_SET);
|
|
105
|
+
function getTreatmentsByFlagSet(key, flagSetName, attributes, options) {
|
|
106
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, false, TREATMENTS_BY_FLAGSET, GET_TREATMENTS_BY_FLAG_SET);
|
|
98
107
|
}
|
|
99
|
-
function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes) {
|
|
100
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
108
|
+
function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes, options) {
|
|
109
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
101
110
|
}
|
|
102
111
|
// Internal function
|
|
103
|
-
function processEvaluation(evaluation, featureFlagName, key,
|
|
112
|
+
function processEvaluation(evaluation, featureFlagName, key, properties, withConfig, invokingMethodName, queue) {
|
|
104
113
|
var matchingKey = getMatching(key);
|
|
105
114
|
var bucketingKey = getBucketing(key);
|
|
106
115
|
var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a, impressionsDisabled = evaluation.impressionsDisabled;
|
|
@@ -116,6 +125,7 @@ export function clientFactory(params) {
|
|
|
116
125
|
bucketingKey: bucketingKey,
|
|
117
126
|
label: label,
|
|
118
127
|
changeNumber: changeNumber,
|
|
128
|
+
properties: properties
|
|
119
129
|
},
|
|
120
130
|
disabled: impressionsDisabled
|
|
121
131
|
});
|
|
@@ -15,40 +15,35 @@ export function clientAttributesDecoration(log, client) {
|
|
|
15
15
|
var clientGetTreatmentsWithConfigByFlagSets = client.getTreatmentsWithConfigByFlagSets;
|
|
16
16
|
var clientGetTreatmentsByFlagSet = client.getTreatmentsByFlagSet;
|
|
17
17
|
var clientGetTreatmentsWithConfigByFlagSet = client.getTreatmentsWithConfigByFlagSet;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return clientGetTreatment(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes));
|
|
18
|
+
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
19
|
+
return clientGetTreatment(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes), maybeOptions);
|
|
21
20
|
}
|
|
22
|
-
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
23
|
-
return clientGetTreatmentWithConfig(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes));
|
|
21
|
+
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
22
|
+
return clientGetTreatmentWithConfig(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes), maybeOptions);
|
|
24
23
|
}
|
|
25
|
-
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
26
|
-
return clientGetTreatments(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes));
|
|
24
|
+
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
25
|
+
return clientGetTreatments(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes), maybeOptions);
|
|
27
26
|
}
|
|
28
|
-
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
29
|
-
return clientGetTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes));
|
|
27
|
+
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
28
|
+
return clientGetTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes), maybeOptions);
|
|
30
29
|
}
|
|
31
|
-
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
32
|
-
return clientGetTreatmentsByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
|
|
30
|
+
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
31
|
+
return clientGetTreatmentsByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes), maybeOptions);
|
|
33
32
|
}
|
|
34
|
-
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
35
|
-
return clientGetTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
|
|
33
|
+
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
34
|
+
return clientGetTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes), maybeOptions);
|
|
36
35
|
}
|
|
37
|
-
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
38
|
-
return clientGetTreatmentsByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
|
|
36
|
+
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
37
|
+
return clientGetTreatmentsByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes), maybeOptions);
|
|
39
38
|
}
|
|
40
|
-
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
41
|
-
return clientGetTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
|
|
42
|
-
}
|
|
43
|
-
function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
44
|
-
return clientTrack(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties);
|
|
39
|
+
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
40
|
+
return clientGetTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes), maybeOptions);
|
|
45
41
|
}
|
|
46
42
|
function combineAttributes(maybeAttributes) {
|
|
47
43
|
var storedAttributes = attributeStorage.getAll();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return maybeAttributes;
|
|
44
|
+
return Object.keys(storedAttributes).length > 0 ?
|
|
45
|
+
objectAssign({}, storedAttributes, maybeAttributes) :
|
|
46
|
+
maybeAttributes;
|
|
52
47
|
}
|
|
53
48
|
return objectAssign(client, {
|
|
54
49
|
getTreatment: getTreatment,
|
|
@@ -59,7 +54,6 @@ export function clientAttributesDecoration(log, client) {
|
|
|
59
54
|
getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
|
|
60
55
|
getTreatmentsByFlagSet: getTreatmentsByFlagSet,
|
|
61
56
|
getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
|
|
62
|
-
track: track,
|
|
63
57
|
/**
|
|
64
58
|
* Add an attribute to client's in memory attributes storage
|
|
65
59
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
|
|
2
|
+
import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfOperational, validateEvaluationOptions } from '../utils/inputValidation';
|
|
3
3
|
import { startsWith } from '../utils/lang';
|
|
4
4
|
import { CONTROL, CONTROL_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG, TRACK_FN_LABEL } from '../utils/constants';
|
|
5
5
|
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
@@ -14,7 +14,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
14
14
|
/**
|
|
15
15
|
* Avoid repeating this validations code
|
|
16
16
|
*/
|
|
17
|
-
function validateEvaluationParams(maybeKey, maybeNameOrNames, maybeAttributes,
|
|
17
|
+
function validateEvaluationParams(methodName, maybeKey, maybeNameOrNames, maybeAttributes, maybeOptions) {
|
|
18
18
|
var key = validateKey(log, maybeKey, methodName);
|
|
19
19
|
var nameOrNames = methodName.indexOf('ByFlagSet') > -1 ?
|
|
20
20
|
validateFlagSets(log, methodName, maybeNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet) :
|
|
@@ -23,40 +23,42 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
23
23
|
validateSplit(log, maybeNameOrNames, methodName);
|
|
24
24
|
var attributes = validateAttributes(log, maybeAttributes, methodName);
|
|
25
25
|
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
|
|
26
|
+
var options = validateEvaluationOptions(log, maybeOptions, methodName);
|
|
26
27
|
validateIfOperational(log, readinessManager, methodName, nameOrNames);
|
|
27
28
|
var valid = isNotDestroyed && key && nameOrNames && attributes !== false;
|
|
28
29
|
return {
|
|
29
30
|
valid: valid,
|
|
30
31
|
key: key,
|
|
31
32
|
nameOrNames: nameOrNames,
|
|
32
|
-
attributes: attributes
|
|
33
|
+
attributes: attributes,
|
|
34
|
+
options: options
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
function wrapResult(value) {
|
|
36
38
|
return isAsync ? Promise.resolve(value) : value;
|
|
37
39
|
}
|
|
38
|
-
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
39
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
40
|
+
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
41
|
+
var params = validateEvaluationParams(GET_TREATMENT, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
40
42
|
if (params.valid) {
|
|
41
|
-
return client.getTreatment(params.key, params.nameOrNames, params.attributes);
|
|
43
|
+
return client.getTreatment(params.key, params.nameOrNames, params.attributes, params.options);
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
return wrapResult(CONTROL);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
48
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
49
|
+
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
50
|
+
var params = validateEvaluationParams(GET_TREATMENT_WITH_CONFIG, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
49
51
|
if (params.valid) {
|
|
50
|
-
return client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes);
|
|
52
|
+
return client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes, params.options);
|
|
51
53
|
}
|
|
52
54
|
else {
|
|
53
55
|
return wrapResult(objectAssign({}, CONTROL_WITH_CONFIG));
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
57
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
58
|
+
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
59
|
+
var params = validateEvaluationParams(GET_TREATMENTS, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
58
60
|
if (params.valid) {
|
|
59
|
-
return client.getTreatments(params.key, params.nameOrNames, params.attributes);
|
|
61
|
+
return client.getTreatments(params.key, params.nameOrNames, params.attributes, params.options);
|
|
60
62
|
}
|
|
61
63
|
else {
|
|
62
64
|
var res_1 = {};
|
|
@@ -65,10 +67,10 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
65
67
|
return wrapResult(res_1);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
69
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
70
|
+
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
71
|
+
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
70
72
|
if (params.valid) {
|
|
71
|
-
return client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes);
|
|
73
|
+
return client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes, params.options);
|
|
72
74
|
}
|
|
73
75
|
else {
|
|
74
76
|
var res_2 = {};
|
|
@@ -77,37 +79,37 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
77
79
|
return wrapResult(res_2);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
|
-
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
81
|
-
var params = validateEvaluationParams(maybeKey, maybeFlagSets, maybeAttributes,
|
|
82
|
+
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
83
|
+
var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
82
84
|
if (params.valid) {
|
|
83
|
-
return client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes);
|
|
85
|
+
return client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes, params.options);
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
88
|
return wrapResult({});
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
|
-
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
90
|
-
var params = validateEvaluationParams(maybeKey, maybeFlagSets, maybeAttributes,
|
|
91
|
+
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
92
|
+
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
91
93
|
if (params.valid) {
|
|
92
|
-
return client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes);
|
|
94
|
+
return client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes, params.options);
|
|
93
95
|
}
|
|
94
96
|
else {
|
|
95
97
|
return wrapResult({});
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
|
-
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
99
|
-
var params = validateEvaluationParams(maybeKey, [maybeFlagSet], maybeAttributes,
|
|
100
|
+
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
101
|
+
var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
100
102
|
if (params.valid) {
|
|
101
|
-
return client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes);
|
|
103
|
+
return client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options);
|
|
102
104
|
}
|
|
103
105
|
else {
|
|
104
106
|
return wrapResult({});
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
|
-
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
108
|
-
var params = validateEvaluationParams(maybeKey, [maybeFlagSet], maybeAttributes,
|
|
109
|
+
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
110
|
+
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
109
111
|
if (params.valid) {
|
|
110
|
-
return client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes);
|
|
112
|
+
return client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options);
|
|
111
113
|
}
|
|
112
114
|
else {
|
|
113
115
|
return wrapResult({});
|
package/esm/services/splitApi.js
CHANGED
|
@@ -38,8 +38,8 @@ export function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
38
38
|
}
|
|
39
39
|
return splitHttpClient(url, undefined, telemetryTracker.trackHttp(TOKEN));
|
|
40
40
|
},
|
|
41
|
-
fetchSplitChanges: function (since, noCache, till
|
|
42
|
-
var url = urls.sdk + "/splitChanges?s=" + flagSpecVersion + "&since=" + since + (
|
|
41
|
+
fetchSplitChanges: function (since, noCache, till) {
|
|
42
|
+
var url = urls.sdk + "/splitChanges?s=" + flagSpecVersion + "&since=" + since + (filterQueryString || '') + (till ? '&till=' + till : '');
|
|
43
43
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SPLITS))
|
|
44
44
|
.catch(function (err) {
|
|
45
45
|
if (err.statusCode === 414)
|
|
@@ -57,8 +57,8 @@ export { AbstractSplitsCacheSync };
|
|
|
57
57
|
* Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
|
|
58
58
|
* This util is intended to simplify the implementation of `splitsCache::usesSegments` method
|
|
59
59
|
*/
|
|
60
|
-
export function usesSegments(
|
|
61
|
-
var conditions =
|
|
60
|
+
export function usesSegments(split) {
|
|
61
|
+
var conditions = split.conditions || [];
|
|
62
62
|
for (var i = 0; i < conditions.length; i++) {
|
|
63
63
|
var matchers = conditions[i].matcherGroup.matchers;
|
|
64
64
|
for (var j = 0; j < matchers.length; j++) {
|
|
@@ -67,8 +67,5 @@ export function usesSegments(ruleEntity) {
|
|
|
67
67
|
return true;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
var excluded = ruleEntity.excluded;
|
|
71
|
-
if (excluded && excluded.segments && excluded.segments.length > 0)
|
|
72
|
-
return true;
|
|
73
70
|
return false;
|
|
74
71
|
}
|
|
@@ -24,15 +24,6 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
24
24
|
KeyBuilder.prototype.buildSplitKeyPrefix = function () {
|
|
25
25
|
return this.prefix + ".split.";
|
|
26
26
|
};
|
|
27
|
-
KeyBuilder.prototype.buildRBSegmentKey = function (rbsegmentName) {
|
|
28
|
-
return this.prefix + ".rbsegment." + rbsegmentName;
|
|
29
|
-
};
|
|
30
|
-
KeyBuilder.prototype.buildRBSegmentsTillKey = function () {
|
|
31
|
-
return this.prefix + ".rbsegments.till";
|
|
32
|
-
};
|
|
33
|
-
KeyBuilder.prototype.buildRBSegmentKeyPrefix = function () {
|
|
34
|
-
return this.prefix + ".rbsegment.";
|
|
35
|
-
};
|
|
36
27
|
KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) {
|
|
37
28
|
return this.prefix + ".segment." + segmentName;
|
|
38
29
|
};
|
|
@@ -6,7 +6,7 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
6
6
|
function KeyBuilderCS(prefix, matchingKey) {
|
|
7
7
|
var _this = _super.call(this, prefix) || this;
|
|
8
8
|
_this.matchingKey = matchingKey;
|
|
9
|
-
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet
|
|
9
|
+
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet)\\.");
|
|
10
10
|
return _this;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -32,9 +32,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
32
32
|
KeyBuilderCS.prototype.isSplitKey = function (key) {
|
|
33
33
|
return startsWith(key, this.prefix + ".split.");
|
|
34
34
|
};
|
|
35
|
-
KeyBuilderCS.prototype.isRBSegmentKey = function (key) {
|
|
36
|
-
return startsWith(key, this.prefix + ".rbsegment.");
|
|
37
|
-
};
|
|
38
35
|
KeyBuilderCS.prototype.buildSplitsWithSegmentCountKey = function () {
|
|
39
36
|
return this.prefix + ".splits.usingSegments";
|
|
40
37
|
};
|
|
@@ -39,9 +39,6 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
39
39
|
KeyBuilderSS.prototype.searchPatternForSplitKeys = function () {
|
|
40
40
|
return this.buildSplitKeyPrefix() + "*";
|
|
41
41
|
};
|
|
42
|
-
KeyBuilderSS.prototype.searchPatternForRBSegmentKeys = function () {
|
|
43
|
-
return this.buildRBSegmentKeyPrefix() + "*";
|
|
44
|
-
};
|
|
45
42
|
/* Telemetry keys */
|
|
46
43
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
47
44
|
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
|
|
@@ -44,13 +44,15 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
44
44
|
};
|
|
45
45
|
SplitsCacheInLocal.prototype._incrementCounts = function (split) {
|
|
46
46
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
localStorage.setItem(ttKey, toNumber(localStorage.getItem(ttKey)) + 1);
|
|
50
|
-
if (usesSegments(split)) {
|
|
51
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
47
|
+
if (split) {
|
|
48
|
+
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
52
49
|
// @ts-expect-error
|
|
53
|
-
localStorage.setItem(
|
|
50
|
+
localStorage.setItem(ttKey, toNumber(localStorage.getItem(ttKey)) + 1);
|
|
51
|
+
if (usesSegments(split)) {
|
|
52
|
+
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
localStorage.setItem(segmentsCountKey, toNumber(localStorage.getItem(segmentsCountKey)) + 1);
|
|
55
|
+
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
catch (e) {
|
|
@@ -172,9 +174,12 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
172
174
|
return true;
|
|
173
175
|
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
174
176
|
var splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
175
|
-
|
|
176
|
-
splitsWithSegmentsCount > 0
|
|
177
|
-
|
|
177
|
+
if (isFiniteNumber(splitsWithSegmentsCount)) {
|
|
178
|
+
return splitsWithSegmentsCount > 0;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
178
183
|
};
|
|
179
184
|
/**
|
|
180
185
|
* Check if the splits information is already stored in browser LocalStorage.
|
|
@@ -13,7 +13,6 @@ import { STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
|
13
13
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
14
14
|
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
15
15
|
import { getMatching } from '../../utils/key';
|
|
16
|
-
import { RBSegmentsCacheInLocal } from './RBSegmentsCacheInLocal';
|
|
17
16
|
/**
|
|
18
17
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
19
18
|
*/
|
|
@@ -31,12 +30,10 @@ export function InLocalStorage(options) {
|
|
|
31
30
|
var keys = new KeyBuilderCS(prefix, matchingKey);
|
|
32
31
|
var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
33
32
|
var splits = new SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
34
|
-
var rbSegments = new RBSegmentsCacheInLocal(settings, keys);
|
|
35
33
|
var segments = new MySegmentsCacheInLocal(log, keys);
|
|
36
34
|
var largeSegments = new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey));
|
|
37
35
|
return {
|
|
38
36
|
splits: splits,
|
|
39
|
-
rbSegments: rbSegments,
|
|
40
37
|
segments: segments,
|
|
41
38
|
largeSegments: largeSegments,
|
|
42
39
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -49,7 +46,6 @@ export function InLocalStorage(options) {
|
|
|
49
46
|
shared: function (matchingKey) {
|
|
50
47
|
return {
|
|
51
48
|
splits: this.splits,
|
|
52
|
-
rbSegments: this.rbSegments,
|
|
53
49
|
segments: new MySegmentsCacheInLocal(log, new KeyBuilderCS(prefix, matchingKey)),
|
|
54
50
|
largeSegments: new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey)),
|
|
55
51
|
impressions: this.impressions,
|
|
@@ -6,7 +6,6 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
|
6
6
|
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
8
|
import { UniqueKeysCacheInMemory } from './UniqueKeysCacheInMemory';
|
|
9
|
-
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
10
9
|
/**
|
|
11
10
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
12
11
|
*
|
|
@@ -15,11 +14,9 @@ import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
|
15
14
|
export function InMemoryStorageFactory(params) {
|
|
16
15
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
17
16
|
var splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
18
|
-
var rbSegments = new RBSegmentsCacheInMemory();
|
|
19
17
|
var segments = new SegmentsCacheInMemory();
|
|
20
18
|
var storage = {
|
|
21
19
|
splits: splits,
|
|
22
|
-
rbSegments: rbSegments,
|
|
23
20
|
segments: segments,
|
|
24
21
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
25
22
|
impressionCounts: new ImpressionCountsCacheInMemory(),
|
|
@@ -6,7 +6,6 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
|
6
6
|
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
8
|
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
|
|
9
|
-
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
10
9
|
/**
|
|
11
10
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
12
11
|
*
|
|
@@ -15,12 +14,10 @@ import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
|
15
14
|
export function InMemoryStorageCSFactory(params) {
|
|
16
15
|
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
17
16
|
var splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
18
|
-
var rbSegments = new RBSegmentsCacheInMemory();
|
|
19
17
|
var segments = new MySegmentsCacheInMemory();
|
|
20
18
|
var largeSegments = new MySegmentsCacheInMemory();
|
|
21
19
|
var storage = {
|
|
22
20
|
splits: splits,
|
|
23
|
-
rbSegments: rbSegments,
|
|
24
21
|
segments: segments,
|
|
25
22
|
largeSegments: largeSegments,
|
|
26
23
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -33,7 +30,6 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
33
30
|
shared: function () {
|
|
34
31
|
return {
|
|
35
32
|
splits: this.splits,
|
|
36
|
-
rbSegments: this.rbSegments,
|
|
37
33
|
segments: new MySegmentsCacheInMemory(),
|
|
38
34
|
largeSegments: new MySegmentsCacheInMemory(),
|
|
39
35
|
impressions: this.impressions,
|
|
@@ -9,7 +9,6 @@ import { TelemetryCacheInRedis } from './TelemetryCacheInRedis';
|
|
|
9
9
|
import { UniqueKeysCacheInRedis } from './UniqueKeysCacheInRedis';
|
|
10
10
|
import { ImpressionCountsCacheInRedis } from './ImpressionCountsCacheInRedis';
|
|
11
11
|
import { metadataBuilder } from '../utils';
|
|
12
|
-
import { RBSegmentsCacheInRedis } from './RBSegmentsCacheInRedis';
|
|
13
12
|
/**
|
|
14
13
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.js
|
|
15
14
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -38,7 +37,6 @@ export function InRedisStorage(options) {
|
|
|
38
37
|
});
|
|
39
38
|
return {
|
|
40
39
|
splits: new SplitsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
|
|
41
|
-
rbSegments: new RBSegmentsCacheInRedis(log, keys, redisClient),
|
|
42
40
|
segments: new SegmentsCacheInRedis(log, keys, redisClient),
|
|
43
41
|
impressions: new ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
44
42
|
impressionCounts: impressionCountsCache,
|
|
@@ -19,7 +19,6 @@ import { UniqueKeysCacheInMemory } from '../inMemory/UniqueKeysCacheInMemory';
|
|
|
19
19
|
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
20
20
|
import { metadataBuilder } from '../utils';
|
|
21
21
|
import { LOG_PREFIX } from '../pluggable/constants';
|
|
22
|
-
import { RBSegmentsCachePluggable } from './RBSegmentsCachePluggable';
|
|
23
22
|
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
24
23
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
25
24
|
/**
|
|
@@ -102,7 +101,6 @@ export function PluggableStorage(options) {
|
|
|
102
101
|
});
|
|
103
102
|
return {
|
|
104
103
|
splits: new SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
105
|
-
rbSegments: new RBSegmentsCachePluggable(log, keys, wrapper),
|
|
106
104
|
segments: new SegmentsCachePluggable(log, keys, wrapper),
|
|
107
105
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
108
106
|
impressionCounts: impressionCountsCache,
|
package/esm/storages/utils.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* SplitChanges fetcher is a wrapper around `splitChanges` API service that parses the response and handle errors.
|
|
4
4
|
*/
|
|
5
5
|
export function splitChangesFetcherFactory(fetchSplitChanges) {
|
|
6
|
-
return function splitChangesFetcher(since, noCache, till,
|
|
6
|
+
return function splitChangesFetcher(since, noCache, till,
|
|
7
7
|
// Optional decorator for `fetchSplitChanges` promise, such as timeout or time tracker
|
|
8
8
|
decorator) {
|
|
9
|
-
var splitsPromise = fetchSplitChanges(since, noCache, till
|
|
9
|
+
var splitsPromise = fetchSplitChanges(since, noCache, till);
|
|
10
10
|
if (decorator)
|
|
11
11
|
splitsPromise = decorator(splitsPromise);
|
|
12
12
|
return splitsPromise.then(function (resp) { return resp.json(); });
|
|
@@ -31,10 +31,10 @@ export function pollingManagerCSFactory(params) {
|
|
|
31
31
|
readiness.splits.on(SDK_SPLITS_ARRIVED, function () {
|
|
32
32
|
if (!splitsSyncTask.isRunning())
|
|
33
33
|
return; // noop if not doing polling
|
|
34
|
-
var
|
|
35
|
-
if (
|
|
36
|
-
log.info(POLLING_SMART_PAUSING, [
|
|
37
|
-
if (
|
|
34
|
+
var splitsHaveSegments = storage.splits.usesSegments();
|
|
35
|
+
if (splitsHaveSegments !== mySegmentsSyncTask.isRunning()) {
|
|
36
|
+
log.info(POLLING_SMART_PAUSING, [splitsHaveSegments ? 'ON' : 'OFF']);
|
|
37
|
+
if (splitsHaveSegments) {
|
|
38
38
|
startMySegmentsSyncTasks();
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
@@ -46,10 +46,10 @@ export function pollingManagerCSFactory(params) {
|
|
|
46
46
|
var mySegmentsSyncTask = mySegmentsSyncTaskFactory(splitApi.fetchMemberships, storage, readiness, settings, matchingKey);
|
|
47
47
|
// smart ready
|
|
48
48
|
function smartReady() {
|
|
49
|
-
if (!readiness.isReady() && !storage.splits.usesSegments()
|
|
49
|
+
if (!readiness.isReady() && !storage.splits.usesSegments())
|
|
50
50
|
readiness.segments.emit(SDK_SEGMENTS_ARRIVED);
|
|
51
51
|
}
|
|
52
|
-
if (!storage.splits.usesSegments()
|
|
52
|
+
if (!storage.splits.usesSegments())
|
|
53
53
|
setTimeout(smartReady, 0);
|
|
54
54
|
else
|
|
55
55
|
readiness.splits.once(SDK_SPLITS_ARRIVED, smartReady);
|
|
@@ -63,7 +63,7 @@ export function pollingManagerCSFactory(params) {
|
|
|
63
63
|
start: function () {
|
|
64
64
|
log.info(POLLING_START);
|
|
65
65
|
splitsSyncTask.start();
|
|
66
|
-
if (storage.splits.usesSegments()
|
|
66
|
+
if (storage.splits.usesSegments())
|
|
67
67
|
startMySegmentsSyncTasks();
|
|
68
68
|
},
|
|
69
69
|
// Stop periodic fetching (polling)
|
|
@@ -9,7 +9,7 @@ import { MEMBERSHIPS_LS_UPDATE } from '../../streaming/constants';
|
|
|
9
9
|
* - uses `segmentsEventEmitter` to emit events related to segments data updates
|
|
10
10
|
*/
|
|
11
11
|
export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmentsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, matchingKey) {
|
|
12
|
-
var splits = storage.splits,
|
|
12
|
+
var splits = storage.splits, segments = storage.segments, largeSegments = storage.largeSegments;
|
|
13
13
|
var readyOnAlreadyExistentState = true;
|
|
14
14
|
var startingUp = true;
|
|
15
15
|
/** timeout and telemetry decorator for `splitChangesFetcher` promise */
|
|
@@ -31,7 +31,7 @@ export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmen
|
|
|
31
31
|
shouldNotifyUpdate = largeSegments.resetSegments(segmentsData.ls || {}) || shouldNotifyUpdate;
|
|
32
32
|
}
|
|
33
33
|
// Notify update if required
|
|
34
|
-
if (
|
|
34
|
+
if (splits.usesSegments() && (shouldNotifyUpdate || readyOnAlreadyExistentState)) {
|
|
35
35
|
readyOnAlreadyExistentState = false;
|
|
36
36
|
segmentsEventEmitter.emit(SDK_SEGMENTS_ARRIVED);
|
|
37
37
|
}
|