@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
|
@@ -60,8 +60,8 @@ exports.AbstractSplitsCacheSync = AbstractSplitsCacheSync;
|
|
|
60
60
|
* Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
|
|
61
61
|
* This util is intended to simplify the implementation of `splitsCache::usesSegments` method
|
|
62
62
|
*/
|
|
63
|
-
function usesSegments(
|
|
64
|
-
var conditions =
|
|
63
|
+
function usesSegments(split) {
|
|
64
|
+
var conditions = split.conditions || [];
|
|
65
65
|
for (var i = 0; i < conditions.length; i++) {
|
|
66
66
|
var matchers = conditions[i].matcherGroup.matchers;
|
|
67
67
|
for (var j = 0; j < matchers.length; j++) {
|
|
@@ -70,9 +70,6 @@ function usesSegments(ruleEntity) {
|
|
|
70
70
|
return true;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
var excluded = ruleEntity.excluded;
|
|
74
|
-
if (excluded && excluded.segments && excluded.segments.length > 0)
|
|
75
|
-
return true;
|
|
76
73
|
return false;
|
|
77
74
|
}
|
|
78
75
|
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
|
};
|
|
@@ -9,7 +9,7 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
9
9
|
function KeyBuilderCS(prefix, matchingKey) {
|
|
10
10
|
var _this = _super.call(this, prefix) || this;
|
|
11
11
|
_this.matchingKey = matchingKey;
|
|
12
|
-
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet
|
|
12
|
+
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet)\\.");
|
|
13
13
|
return _this;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -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;
|
|
@@ -47,13 +47,15 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
47
47
|
};
|
|
48
48
|
SplitsCacheInLocal.prototype._incrementCounts = function (split) {
|
|
49
49
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
localStorage.setItem(ttKey, (0, lang_1.toNumber)(localStorage.getItem(ttKey)) + 1);
|
|
53
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
54
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
50
|
+
if (split) {
|
|
51
|
+
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
55
52
|
// @ts-expect-error
|
|
56
|
-
localStorage.setItem(
|
|
53
|
+
localStorage.setItem(ttKey, (0, lang_1.toNumber)(localStorage.getItem(ttKey)) + 1);
|
|
54
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
55
|
+
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
localStorage.setItem(segmentsCountKey, (0, lang_1.toNumber)(localStorage.getItem(segmentsCountKey)) + 1);
|
|
58
|
+
}
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
catch (e) {
|
|
@@ -175,9 +177,12 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
175
177
|
return true;
|
|
176
178
|
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
177
179
|
var splitsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
|
|
178
|
-
|
|
179
|
-
splitsWithSegmentsCount > 0
|
|
180
|
-
|
|
180
|
+
if ((0, lang_1.isFiniteNumber)(splitsWithSegmentsCount)) {
|
|
181
|
+
return splitsWithSegmentsCount > 0;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
181
186
|
};
|
|
182
187
|
/**
|
|
183
188
|
* Check if the splits information is already stored in browser LocalStorage.
|
|
@@ -16,7 +16,6 @@ var constants_2 = require("../../utils/constants");
|
|
|
16
16
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
17
17
|
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
18
18
|
var key_1 = require("../../utils/key");
|
|
19
|
-
var RBSegmentsCacheInLocal_1 = require("./RBSegmentsCacheInLocal");
|
|
20
19
|
/**
|
|
21
20
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
22
21
|
*/
|
|
@@ -34,12 +33,10 @@ function InLocalStorage(options) {
|
|
|
34
33
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
35
34
|
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
36
35
|
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
37
|
-
var rbSegments = new RBSegmentsCacheInLocal_1.RBSegmentsCacheInLocal(settings, keys);
|
|
38
36
|
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
39
37
|
var largeSegments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey));
|
|
40
38
|
return {
|
|
41
39
|
splits: splits,
|
|
42
|
-
rbSegments: rbSegments,
|
|
43
40
|
segments: segments,
|
|
44
41
|
largeSegments: largeSegments,
|
|
45
42
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -52,7 +49,6 @@ function InLocalStorage(options) {
|
|
|
52
49
|
shared: function (matchingKey) {
|
|
53
50
|
return {
|
|
54
51
|
splits: this.splits,
|
|
55
|
-
rbSegments: this.rbSegments,
|
|
56
52
|
segments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey)),
|
|
57
53
|
largeSegments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey)),
|
|
58
54
|
impressions: this.impressions,
|
|
@@ -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,7 +12,6 @@ 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 RBSegmentsCacheInRedis_1 = require("./RBSegmentsCacheInRedis");
|
|
16
15
|
/**
|
|
17
16
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.js
|
|
18
17
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -41,7 +40,6 @@ function InRedisStorage(options) {
|
|
|
41
40
|
});
|
|
42
41
|
return {
|
|
43
42
|
splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
|
|
44
|
-
rbSegments: new RBSegmentsCacheInRedis_1.RBSegmentsCacheInRedis(log, keys, redisClient),
|
|
45
43
|
segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
|
|
46
44
|
impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
47
45
|
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
|
/**
|
|
@@ -105,7 +104,6 @@ function PluggableStorage(options) {
|
|
|
105
104
|
});
|
|
106
105
|
return {
|
|
107
106
|
splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
108
|
-
rbSegments: new RBSegmentsCachePluggable_1.RBSegmentsCachePluggable(log, keys, wrapper),
|
|
109
107
|
segments: new SegmentsCachePluggable_1.SegmentsCachePluggable(log, keys, wrapper),
|
|
110
108
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable_1.ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
111
109
|
impressionCounts: impressionCountsCache,
|
package/cjs/storages/utils.js
CHANGED
|
@@ -6,10 +6,10 @@ exports.splitChangesFetcherFactory = void 0;
|
|
|
6
6
|
* SplitChanges fetcher is a wrapper around `splitChanges` API service that parses the response and handle errors.
|
|
7
7
|
*/
|
|
8
8
|
function splitChangesFetcherFactory(fetchSplitChanges) {
|
|
9
|
-
return function splitChangesFetcher(since, noCache, till,
|
|
9
|
+
return function splitChangesFetcher(since, noCache, till,
|
|
10
10
|
// Optional decorator for `fetchSplitChanges` promise, such as timeout or time tracker
|
|
11
11
|
decorator) {
|
|
12
|
-
var splitsPromise = fetchSplitChanges(since, noCache, till
|
|
12
|
+
var splitsPromise = fetchSplitChanges(since, noCache, till);
|
|
13
13
|
if (decorator)
|
|
14
14
|
splitsPromise = decorator(splitsPromise);
|
|
15
15
|
return splitsPromise.then(function (resp) { return resp.json(); });
|
|
@@ -34,10 +34,10 @@ function pollingManagerCSFactory(params) {
|
|
|
34
34
|
readiness.splits.on(constants_1.SDK_SPLITS_ARRIVED, function () {
|
|
35
35
|
if (!splitsSyncTask.isRunning())
|
|
36
36
|
return; // noop if not doing polling
|
|
37
|
-
var
|
|
38
|
-
if (
|
|
39
|
-
log.info(constants_2.POLLING_SMART_PAUSING, [
|
|
40
|
-
if (
|
|
37
|
+
var splitsHaveSegments = storage.splits.usesSegments();
|
|
38
|
+
if (splitsHaveSegments !== mySegmentsSyncTask.isRunning()) {
|
|
39
|
+
log.info(constants_2.POLLING_SMART_PAUSING, [splitsHaveSegments ? 'ON' : 'OFF']);
|
|
40
|
+
if (splitsHaveSegments) {
|
|
41
41
|
startMySegmentsSyncTasks();
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
@@ -49,10 +49,10 @@ function pollingManagerCSFactory(params) {
|
|
|
49
49
|
var mySegmentsSyncTask = (0, mySegmentsSyncTask_1.mySegmentsSyncTaskFactory)(splitApi.fetchMemberships, storage, readiness, settings, matchingKey);
|
|
50
50
|
// smart ready
|
|
51
51
|
function smartReady() {
|
|
52
|
-
if (!readiness.isReady() && !storage.splits.usesSegments()
|
|
52
|
+
if (!readiness.isReady() && !storage.splits.usesSegments())
|
|
53
53
|
readiness.segments.emit(constants_1.SDK_SEGMENTS_ARRIVED);
|
|
54
54
|
}
|
|
55
|
-
if (!storage.splits.usesSegments()
|
|
55
|
+
if (!storage.splits.usesSegments())
|
|
56
56
|
setTimeout(smartReady, 0);
|
|
57
57
|
else
|
|
58
58
|
readiness.splits.once(constants_1.SDK_SPLITS_ARRIVED, smartReady);
|
|
@@ -66,7 +66,7 @@ function pollingManagerCSFactory(params) {
|
|
|
66
66
|
start: function () {
|
|
67
67
|
log.info(constants_2.POLLING_START);
|
|
68
68
|
splitsSyncTask.start();
|
|
69
|
-
if (storage.splits.usesSegments()
|
|
69
|
+
if (storage.splits.usesSegments())
|
|
70
70
|
startMySegmentsSyncTasks();
|
|
71
71
|
},
|
|
72
72
|
// Stop periodic fetching (polling)
|
|
@@ -12,7 +12,7 @@ var constants_3 = require("../../streaming/constants");
|
|
|
12
12
|
* - uses `segmentsEventEmitter` to emit events related to segments data updates
|
|
13
13
|
*/
|
|
14
14
|
function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmentsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, matchingKey) {
|
|
15
|
-
var splits = storage.splits,
|
|
15
|
+
var splits = storage.splits, segments = storage.segments, largeSegments = storage.largeSegments;
|
|
16
16
|
var readyOnAlreadyExistentState = true;
|
|
17
17
|
var startingUp = true;
|
|
18
18
|
/** timeout and telemetry decorator for `splitChangesFetcher` promise */
|
|
@@ -34,7 +34,7 @@ function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmentsEvent
|
|
|
34
34
|
shouldNotifyUpdate = largeSegments.resetSegments(segmentsData.ls || {}) || shouldNotifyUpdate;
|
|
35
35
|
}
|
|
36
36
|
// Notify update if required
|
|
37
|
-
if (
|
|
37
|
+
if (splits.usesSegments() && (shouldNotifyUpdate || readyOnAlreadyExistentState)) {
|
|
38
38
|
readyOnAlreadyExistentState = false;
|
|
39
39
|
segmentsEventEmitter.emit(constants_1.SDK_SEGMENTS_ARRIVED);
|
|
40
40
|
}
|
|
@@ -39,7 +39,7 @@ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, read
|
|
|
39
39
|
* Returned promise will not be rejected.
|
|
40
40
|
*
|
|
41
41
|
* @param fetchOnlyNew - if true, only fetch the segments that not exists, i.e., which `changeNumber` is equal to -1.
|
|
42
|
-
* This param is used by SplitUpdateWorker on server-side SDK, to fetch new registered segments on SPLIT_UPDATE
|
|
42
|
+
* This param is used by SplitUpdateWorker on server-side SDK, to fetch new registered segments on SPLIT_UPDATE notifications.
|
|
43
43
|
* @param segmentName - segment name to fetch. By passing `undefined` it fetches the list of segments registered at the storage
|
|
44
44
|
* @param noCache - true to revalidate data to fetch on a SEGMENT_UPDATE notifications.
|
|
45
45
|
* @param till - till target for the provided segmentName, for CDN bypass.
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitChangesUpdaterFactory = exports.
|
|
3
|
+
exports.splitChangesUpdaterFactory = exports.computeSplitsMutation = exports.parseSegments = void 0;
|
|
4
4
|
var timeout_1 = require("../../../utils/promise/timeout");
|
|
5
5
|
var constants_1 = require("../../../readiness/constants");
|
|
6
6
|
var constants_2 = require("../../../logger/constants");
|
|
7
7
|
var lang_1 = require("../../../utils/lang");
|
|
8
8
|
var constants_3 = require("../../../utils/constants");
|
|
9
9
|
var sets_1 = require("../../../utils/lang/sets");
|
|
10
|
-
var constants_4 = require("../../streaming/constants");
|
|
11
10
|
// Checks that all registered segments have been fetched (changeNumber !== -1 for every segment).
|
|
12
11
|
// Returns a promise that could be rejected.
|
|
13
12
|
// @TODO review together with Segments and MySegments storage APIs
|
|
@@ -22,14 +21,13 @@ function checkAllSegmentsExist(segments) {
|
|
|
22
21
|
* Collect segments from a raw split definition.
|
|
23
22
|
* Exported for testing purposes.
|
|
24
23
|
*/
|
|
25
|
-
function parseSegments(
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
var segments = new Set(excluded && excluded.segments);
|
|
24
|
+
function parseSegments(_a) {
|
|
25
|
+
var conditions = _a.conditions;
|
|
26
|
+
var segments = new Set();
|
|
29
27
|
for (var i = 0; i < conditions.length; i++) {
|
|
30
28
|
var matchers = conditions[i].matcherGroup.matchers;
|
|
31
29
|
matchers.forEach(function (matcher) {
|
|
32
|
-
if (matcher.matcherType ===
|
|
30
|
+
if (matcher.matcherType === constants_3.IN_SEGMENT)
|
|
33
31
|
segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
|
|
34
32
|
});
|
|
35
33
|
}
|
|
@@ -60,21 +58,24 @@ function matchFilters(featureFlag, filters) {
|
|
|
60
58
|
* i.e., an object with added splits, removed splits and used segments.
|
|
61
59
|
* Exported for testing purposes.
|
|
62
60
|
*/
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
function computeSplitsMutation(entries, filters) {
|
|
62
|
+
var segments = new Set();
|
|
63
|
+
var computed = entries.reduce(function (accum, split) {
|
|
64
|
+
if (split.status === 'ACTIVE' && matchFilters(split, filters)) {
|
|
65
|
+
accum.added.push(split);
|
|
66
|
+
parseSegments(split).forEach(function (segmentName) {
|
|
68
67
|
segments.add(segmentName);
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
70
|
else {
|
|
72
|
-
accum.removed.push(
|
|
71
|
+
accum.removed.push(split);
|
|
73
72
|
}
|
|
74
73
|
return accum;
|
|
75
|
-
}, { added: [], removed: [] });
|
|
74
|
+
}, { added: [], removed: [], segments: [] });
|
|
75
|
+
computed.segments = (0, sets_1.setToArray)(segments);
|
|
76
|
+
return computed;
|
|
76
77
|
}
|
|
77
|
-
exports.
|
|
78
|
+
exports.computeSplitsMutation = computeSplitsMutation;
|
|
78
79
|
/**
|
|
79
80
|
* factory of SplitChanges updater, a task that:
|
|
80
81
|
* - fetches split changes using `splitChangesFetcher`
|
|
@@ -92,7 +93,7 @@ exports.computeMutation = computeMutation;
|
|
|
92
93
|
function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFiltersValidation, splitsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, isClientSide) {
|
|
93
94
|
if (requestTimeoutBeforeReady === void 0) { requestTimeoutBeforeReady = 0; }
|
|
94
95
|
if (retriesOnFailureBeforeReady === void 0) { retriesOnFailureBeforeReady = 0; }
|
|
95
|
-
var splits = storage.splits,
|
|
96
|
+
var splits = storage.splits, segments = storage.segments;
|
|
96
97
|
var startingUp = true;
|
|
97
98
|
/** timeout decorator for `splitChangesFetcher` promise */
|
|
98
99
|
function _promiseDecorator(promise) {
|
|
@@ -107,48 +108,31 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFilt
|
|
|
107
108
|
* @param noCache - true to revalidate data to fetch
|
|
108
109
|
* @param till - query param to bypass CDN requests
|
|
109
110
|
*/
|
|
110
|
-
return function splitChangesUpdater(noCache, till,
|
|
111
|
+
return function splitChangesUpdater(noCache, till, splitUpdateNotification) {
|
|
111
112
|
/**
|
|
112
113
|
* @param since - current changeNumber at splitsCache
|
|
113
114
|
* @param retry - current number of retry attempts
|
|
114
115
|
*/
|
|
115
|
-
function _splitChangesUpdater(
|
|
116
|
+
function _splitChangesUpdater(since, retry) {
|
|
116
117
|
if (retry === void 0) { retry = 0; }
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// IFFU edge case: a change to a flag that adds an IN_RULE_BASED_SEGMENT matcher that is not present yet
|
|
122
|
-
Promise.resolve(rbSegments.contains(parseSegments(instantUpdate.payload, constants_3.IN_RULE_BASED_SEGMENT))).then(function (contains) {
|
|
123
|
-
return contains ?
|
|
124
|
-
{ ff: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
|
|
125
|
-
splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator);
|
|
126
|
-
}) :
|
|
127
|
-
{ rbs: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
|
|
128
|
-
splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator))
|
|
118
|
+
log.debug(constants_2.SYNC_SPLITS_FETCH, [since]);
|
|
119
|
+
var fetcherPromise = Promise.resolve(splitUpdateNotification ?
|
|
120
|
+
{ splits: [splitUpdateNotification.payload], till: splitUpdateNotification.changeNumber } :
|
|
121
|
+
splitChangesFetcher(since, noCache, till, _promiseDecorator))
|
|
129
122
|
.then(function (splitChanges) {
|
|
130
123
|
startingUp = false;
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
var rbsUpdate = false;
|
|
139
|
-
if (splitChanges.rbs) {
|
|
140
|
-
var _b = computeMutation(splitChanges.rbs.d, usedSegments), added = _b.added, removed = _b.removed;
|
|
141
|
-
log.debug(constants_2.SYNC_RBS_UPDATE, [added.length, removed.length]);
|
|
142
|
-
rbsUpdate = rbSegments.update(added, removed, splitChanges.rbs.t);
|
|
143
|
-
}
|
|
144
|
-
return Promise.all([ffUpdate, rbsUpdate,
|
|
145
|
-
// @TODO if at least 1 segment fetch fails due to 404 and other segments are updated in the storage, SDK_UPDATE is not emitted
|
|
146
|
-
segments.registerSegments((0, sets_1.setToArray)(usedSegments))
|
|
124
|
+
var mutation = computeSplitsMutation(splitChanges.splits, splitFiltersValidation);
|
|
125
|
+
log.debug(constants_2.SYNC_SPLITS_UPDATE, [mutation.added.length, mutation.removed.length, mutation.segments.length]);
|
|
126
|
+
// Write into storage
|
|
127
|
+
// @TODO call `setChangeNumber` only if the other storage operations have succeeded, in order to keep storage consistency
|
|
128
|
+
return Promise.all([
|
|
129
|
+
splits.update(mutation.added, mutation.removed, splitChanges.till),
|
|
130
|
+
segments.registerSegments(mutation.segments)
|
|
147
131
|
]).then(function (_a) {
|
|
148
|
-
var
|
|
132
|
+
var isThereUpdate = _a[0];
|
|
149
133
|
if (splitsEventEmitter) {
|
|
150
134
|
// To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
|
|
151
|
-
return Promise.resolve(!splitsEventEmitter.splitsArrived || (
|
|
135
|
+
return Promise.resolve(!splitsEventEmitter.splitsArrived || (since !== splitChanges.till && isThereUpdate && (isClientSide || checkAllSegmentsExist(segments))))
|
|
152
136
|
.catch(function () { return false; } /** noop. just to handle a possible `checkAllSegmentsExist` rejection, before emitting SDK event */)
|
|
153
137
|
.then(function (emitSplitsArrivedEvent) {
|
|
154
138
|
// emit SDK events
|
|
@@ -165,7 +149,7 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFilt
|
|
|
165
149
|
if (startingUp && retriesOnFailureBeforeReady > retry) {
|
|
166
150
|
retry += 1;
|
|
167
151
|
log.info(constants_2.SYNC_SPLITS_FETCH_RETRY, [retry, error]);
|
|
168
|
-
return _splitChangesUpdater(
|
|
152
|
+
return _splitChangesUpdater(since, retry);
|
|
169
153
|
}
|
|
170
154
|
else {
|
|
171
155
|
startingUp = false;
|
|
@@ -182,8 +166,8 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFilt
|
|
|
182
166
|
}
|
|
183
167
|
return fetcherPromise;
|
|
184
168
|
}
|
|
185
|
-
// `getChangeNumber` never rejects or throws error
|
|
186
|
-
return
|
|
169
|
+
var sincePromise = Promise.resolve(splits.getChangeNumber()); // `getChangeNumber` never rejects or throws error
|
|
170
|
+
return sincePromise.then(_splitChangesUpdater);
|
|
187
171
|
};
|
|
188
172
|
}
|
|
189
173
|
exports.splitChangesUpdaterFactory = splitChangesUpdaterFactory;
|
|
@@ -78,7 +78,6 @@ function SSEHandlerFactory(log, pushEmitter, telemetryTracker) {
|
|
|
78
78
|
case constants_1.MEMBERSHIPS_MS_UPDATE:
|
|
79
79
|
case constants_1.MEMBERSHIPS_LS_UPDATE:
|
|
80
80
|
case constants_1.SPLIT_KILL:
|
|
81
|
-
case constants_1.RB_SEGMENT_UPDATE:
|
|
82
81
|
pushEmitter.emit(parsedData.type, parsedData);
|
|
83
82
|
break;
|
|
84
83
|
/* occupancy & control events, handled by NotificationManagerKeeper */
|