@splitsoftware/splitio-commons 1.17.1-rc.3 → 1.17.1-rc.5
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 +28 -28
- package/LICENSE +1 -1
- package/README.md +4 -3
- package/cjs/consent/sdkUserConsent.js +4 -2
- package/cjs/evaluator/matchers/index.js +1 -3
- package/cjs/evaluator/matchers/matcherTypes.js +0 -1
- package/cjs/evaluator/matchers/segment.js +0 -6
- package/cjs/evaluator/matchersTransform/index.js +1 -4
- package/cjs/evaluator/matchersTransform/segment.js +1 -3
- package/cjs/logger/constants.js +2 -2
- package/cjs/logger/messages/info.js +1 -1
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/readiness/readinessManager.js +11 -12
- package/cjs/readiness/sdkReadinessManager.js +6 -5
- package/cjs/sdkClient/sdkClient.js +5 -5
- package/cjs/sdkClient/sdkClientMethod.js +1 -3
- package/cjs/sdkClient/sdkClientMethodCS.js +17 -15
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +17 -15
- package/cjs/sdkFactory/index.js +11 -38
- package/cjs/services/decorateHeaders.js +6 -1
- package/cjs/services/splitApi.js +5 -5
- package/cjs/services/splitHttpClient.js +5 -2
- package/cjs/storages/AbstractSegmentsCacheSync.js +12 -41
- package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
- package/cjs/storages/AbstractSplitsCacheSync.js +8 -2
- package/cjs/storages/KeyBuilderCS.js +5 -23
- package/cjs/storages/dataLoader.js +33 -65
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +52 -29
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +9 -1
- package/cjs/storages/inLocalStorage/index.js +3 -12
- package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -20
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +40 -9
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +8 -8
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +10 -7
- package/cjs/storages/inRedis/RedisAdapter.js +1 -1
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/cjs/storages/inRedis/index.js +11 -5
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +2 -2
- package/cjs/storages/pluggable/inMemoryWrapper.js +1 -1
- package/cjs/storages/pluggable/index.js +32 -37
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +7 -2
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +8 -5
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +1 -1
- package/cjs/sync/polling/pollingManagerSS.js +3 -3
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +21 -15
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +11 -2
- package/cjs/sync/streaming/AuthClient/index.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +5 -3
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +48 -107
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +3 -3
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/parseUtils.js +9 -14
- package/cjs/sync/streaming/pushManager.js +67 -69
- package/cjs/sync/syncTask.js +2 -2
- package/cjs/trackers/eventTracker.js +9 -11
- package/cjs/trackers/impressionsTracker.js +13 -15
- package/cjs/trackers/uniqueKeysTracker.js +3 -5
- package/cjs/utils/constants/index.js +4 -5
- package/cjs/utils/settingsValidation/index.js +1 -2
- package/cjs/utils/settingsValidation/storage/storageCS.js +12 -1
- package/esm/consent/sdkUserConsent.js +4 -2
- package/esm/evaluator/matchers/index.js +1 -3
- package/esm/evaluator/matchers/matcherTypes.js +0 -1
- package/esm/evaluator/matchers/segment.js +0 -6
- package/esm/evaluator/matchersTransform/index.js +1 -4
- package/esm/evaluator/matchersTransform/segment.js +1 -3
- package/esm/logger/constants.js +1 -1
- package/esm/logger/messages/info.js +1 -1
- package/esm/logger/messages/warn.js +1 -1
- package/esm/readiness/readinessManager.js +11 -12
- package/esm/readiness/sdkReadinessManager.js +6 -5
- package/esm/sdkClient/sdkClient.js +5 -5
- package/esm/sdkClient/sdkClientMethod.js +1 -3
- package/esm/sdkClient/sdkClientMethodCS.js +15 -13
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +15 -13
- package/esm/sdkFactory/index.js +12 -39
- package/esm/services/decorateHeaders.js +4 -0
- package/esm/services/splitApi.js +6 -6
- package/esm/services/splitHttpClient.js +6 -3
- package/esm/storages/AbstractSegmentsCacheSync.js +12 -41
- package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
- package/esm/storages/AbstractSplitsCacheSync.js +9 -3
- package/esm/storages/KeyBuilderCS.js +4 -21
- package/esm/storages/dataLoader.js +31 -62
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +52 -29
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +9 -1
- package/esm/storages/inLocalStorage/index.js +5 -14
- package/esm/storages/inMemory/InMemoryStorageCS.js +3 -20
- package/esm/storages/inMemory/MySegmentsCacheInMemory.js +40 -9
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/SplitsCacheInMemory.js +8 -8
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +10 -7
- package/esm/storages/inRedis/RedisAdapter.js +1 -1
- package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/esm/storages/inRedis/index.js +11 -5
- package/esm/storages/pluggable/SegmentsCachePluggable.js +2 -2
- package/esm/storages/pluggable/inMemoryWrapper.js +1 -1
- package/esm/storages/pluggable/index.js +32 -37
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +8 -3
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +8 -5
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/esm/sync/polling/pollingManagerCS.js +1 -1
- package/esm/sync/polling/pollingManagerSS.js +3 -3
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +21 -15
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/esm/sync/polling/updaters/splitChangesUpdater.js +12 -3
- package/esm/sync/streaming/AuthClient/index.js +1 -1
- package/esm/sync/streaming/SSEHandler/index.js +6 -4
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +49 -108
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +3 -3
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/parseUtils.js +8 -12
- package/esm/sync/streaming/pushManager.js +70 -72
- package/esm/sync/syncTask.js +2 -2
- package/esm/trackers/eventTracker.js +9 -11
- package/esm/trackers/impressionsTracker.js +13 -15
- package/esm/trackers/uniqueKeysTracker.js +3 -5
- package/esm/utils/constants/index.js +2 -3
- package/esm/utils/settingsValidation/index.js +1 -2
- package/esm/utils/settingsValidation/storage/storageCS.js +10 -0
- package/package.json +1 -1
- package/src/consent/sdkUserConsent.ts +3 -2
- package/src/dtos/types.ts +7 -21
- package/src/evaluator/matchers/index.ts +0 -2
- package/src/evaluator/matchers/matcherTypes.ts +0 -1
- package/src/evaluator/matchers/segment.ts +0 -7
- package/src/evaluator/matchersTransform/index.ts +1 -4
- package/src/evaluator/matchersTransform/segment.ts +3 -5
- package/src/logger/constants.ts +1 -1
- package/src/logger/messages/info.ts +1 -1
- package/src/logger/messages/warn.ts +1 -1
- package/src/readiness/readinessManager.ts +12 -16
- package/src/readiness/sdkReadinessManager.ts +7 -7
- package/src/readiness/types.ts +2 -3
- package/src/sdkClient/sdkClient.ts +5 -5
- package/src/sdkClient/sdkClientMethod.ts +1 -4
- package/src/sdkClient/sdkClientMethodCS.ts +14 -11
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +14 -11
- package/src/sdkFactory/index.ts +13 -42
- package/src/sdkFactory/types.ts +1 -5
- package/src/services/decorateHeaders.ts +5 -0
- package/src/services/splitApi.ts +7 -7
- package/src/services/splitHttpClient.ts +7 -4
- package/src/services/types.ts +2 -2
- package/src/storages/AbstractSegmentsCacheSync.ts +12 -53
- package/src/storages/AbstractSplitsCacheAsync.ts +8 -0
- package/src/storages/AbstractSplitsCacheSync.ts +11 -4
- package/src/storages/KeyBuilderCS.ts +5 -34
- package/src/storages/dataLoader.ts +33 -63
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +59 -29
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +10 -1
- package/src/storages/inLocalStorage/index.ts +6 -16
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -23
- package/src/storages/inMemory/MySegmentsCacheInMemory.ts +44 -10
- package/src/storages/inMemory/SegmentsCacheInMemory.ts +1 -1
- package/src/storages/inMemory/SplitsCacheInMemory.ts +8 -7
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +11 -7
- package/src/storages/inRedis/RedisAdapter.ts +1 -1
- package/src/storages/inRedis/SegmentsCacheInRedis.ts +2 -2
- package/src/storages/inRedis/index.ts +12 -6
- package/src/storages/pluggable/SegmentsCachePluggable.ts +2 -2
- package/src/storages/pluggable/inMemoryWrapper.ts +1 -1
- package/src/storages/pluggable/index.ts +33 -38
- package/src/storages/types.ts +15 -15
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +7 -3
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +10 -8
- package/src/sync/polling/fetchers/segmentChangesFetcher.ts +1 -1
- package/src/sync/polling/fetchers/types.ts +2 -3
- package/src/sync/polling/pollingManagerCS.ts +4 -4
- package/src/sync/polling/pollingManagerSS.ts +2 -3
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +5 -4
- package/src/sync/polling/types.ts +6 -7
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +22 -19
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -2
- package/src/sync/polling/updaters/splitChangesUpdater.ts +12 -4
- package/src/sync/streaming/AuthClient/index.ts +1 -1
- package/src/sync/streaming/SSEClient/index.ts +6 -4
- package/src/sync/streaming/SSEHandler/index.ts +8 -5
- package/src/sync/streaming/SSEHandler/types.ts +15 -15
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +49 -116
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +4 -4
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/types.ts +2 -2
- package/src/sync/streaming/constants.ts +2 -2
- package/src/sync/streaming/parseUtils.ts +11 -19
- package/src/sync/streaming/pushManager.ts +72 -73
- package/src/sync/streaming/types.ts +10 -10
- package/src/sync/submitters/types.ts +5 -8
- package/src/sync/syncTask.ts +2 -2
- package/src/trackers/eventTracker.ts +7 -10
- package/src/trackers/impressionsTracker.ts +9 -12
- package/src/trackers/types.ts +0 -1
- package/src/trackers/uniqueKeysTracker.ts +4 -6
- package/src/types.ts +9 -16
- package/src/utils/constants/index.ts +2 -3
- package/src/utils/settingsValidation/index.ts +2 -3
- package/src/utils/settingsValidation/storage/storageCS.ts +13 -0
- package/src/utils/settingsValidation/types.ts +1 -1
- package/types/dtos/types.d.ts +7 -18
- package/types/evaluator/matchersTransform/segment.d.ts +2 -2
- package/types/logger/constants.d.ts +1 -1
- package/types/readiness/readinessManager.d.ts +2 -2
- package/types/readiness/sdkReadinessManager.d.ts +3 -2
- package/types/readiness/types.d.ts +2 -3
- package/types/sdkClient/sdkClientMethod.d.ts +1 -1
- package/types/sdkFactory/types.d.ts +1 -4
- package/types/services/decorateHeaders.d.ts +1 -0
- package/types/services/splitApi.d.ts +1 -1
- package/types/services/splitHttpClient.d.ts +1 -1
- package/types/services/types.d.ts +2 -2
- package/types/storages/AbstractSegmentsCacheSync.d.ts +11 -9
- package/types/storages/AbstractSplitsCacheAsync.d.ts +5 -0
- package/types/storages/AbstractSplitsCacheSync.d.ts +6 -1
- package/types/storages/KeyBuilderCS.d.ts +2 -9
- package/types/storages/dataLoader.d.ts +6 -17
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +14 -4
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +6 -0
- package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +9 -3
- package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +1 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -1
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -4
- package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/index.d.ts +1 -1
- package/types/storages/pluggable/SegmentsCachePluggable.d.ts +1 -1
- package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -1
- package/types/storages/types.d.ts +11 -11
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +2 -2
- package/types/sync/polling/fetchers/types.d.ts +2 -2
- package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +2 -2
- package/types/sync/polling/types.d.ts +4 -7
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +3 -4
- package/types/sync/streaming/SSEHandler/types.d.ts +14 -16
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +2 -4
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -2
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +2 -3
- package/types/sync/streaming/UpdateWorkers/types.d.ts +2 -2
- package/types/sync/streaming/constants.d.ts +2 -2
- package/types/sync/streaming/parseUtils.d.ts +5 -4
- package/types/sync/streaming/types.d.ts +8 -8
- package/types/sync/submitters/types.d.ts +4 -7
- package/types/trackers/eventTracker.d.ts +1 -1
- package/types/trackers/impressionsTracker.d.ts +1 -1
- package/types/trackers/types.d.ts +0 -1
- package/types/types.d.ts +9 -15
- package/types/utils/constants/index.d.ts +2 -3
- package/types/utils/settingsValidation/storage/storageCS.d.ts +5 -0
- package/types/utils/settingsValidation/types.d.ts +1 -1
- package/cjs/evaluator/matchers/large_segment.js +0 -16
- package/cjs/sdkClient/identity.js +0 -7
- package/esm/evaluator/matchers/large_segment.js +0 -12
- package/esm/sdkClient/identity.js +0 -3
- package/src/evaluator/matchers/large_segment.ts +0 -18
- package/src/sdkClient/identity.ts +0 -5
- package/types/evaluator/matchers/large_segment.d.ts +0 -5
- package/types/evaluator/matchers/sember_inlist.d.ts +0 -3
- package/types/evaluator/matchersTransform/set.d.ts +0 -5
- package/types/evaluator/matchersTransform/string.d.ts +0 -7
- package/types/sdkClient/identity.d.ts +0 -2
- package/types/storages/AbstractMySegmentsCacheSync.d.ts +0 -39
- package/types/storages/AbstractSplitsCache.d.ts +0 -46
- package/types/sync/streaming/mySegmentsV2utils.d.ts +0 -27
- package/types/sync/streaming/pushManagerCS_Spec1_3.d.ts +0 -9
- package/types/sync/streaming/pushManager_Spec1_3.d.ts +0 -9
- package/types/trackers/impressionObserver/utils.d.ts +0 -5
- package/types/utils/inputValidation/sdkKey.d.ts +0 -7
- package/types/utils/inputValidation/splitExistance.d.ts +0 -7
- package/types/utils/inputValidation/trafficTypeExistance.d.ts +0 -9
- package/types/utils/redis/RedisMock.d.ts +0 -4
- package/types/utils/settingsValidation/logger/globalLogLevel.d.ts +0 -8
- /package/types/utils/{semVer.d.ts → Semver.d.ts} +0 -0
|
@@ -11,26 +11,57 @@ var MySegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
11
11
|
_this.segmentCache = {};
|
|
12
12
|
return _this;
|
|
13
13
|
}
|
|
14
|
+
MySegmentsCacheInMemory.prototype.clear = function () {
|
|
15
|
+
this.segmentCache = {};
|
|
16
|
+
};
|
|
14
17
|
MySegmentsCacheInMemory.prototype.addToSegment = function (name) {
|
|
15
|
-
if (this.segmentCache[name])
|
|
16
|
-
return false;
|
|
17
18
|
this.segmentCache[name] = true;
|
|
18
19
|
return true;
|
|
19
20
|
};
|
|
20
21
|
MySegmentsCacheInMemory.prototype.removeFromSegment = function (name) {
|
|
21
|
-
if (!this.segmentCache[name])
|
|
22
|
-
return false;
|
|
23
22
|
delete this.segmentCache[name];
|
|
24
23
|
return true;
|
|
25
24
|
};
|
|
26
25
|
MySegmentsCacheInMemory.prototype.isInSegment = function (name) {
|
|
27
26
|
return this.segmentCache[name] === true;
|
|
28
27
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Reset (update) the cached list of segments with the given list, removing and adding segments if necessary.
|
|
30
|
+
* @NOTE based on the way we use segments in the browser, this way is the best option
|
|
31
|
+
*
|
|
32
|
+
* @param {string[]} names list of segment names
|
|
33
|
+
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
34
|
+
*/
|
|
35
|
+
MySegmentsCacheInMemory.prototype.resetSegments = function (names) {
|
|
36
|
+
var _this = this;
|
|
37
|
+
var isDiff = false;
|
|
38
|
+
var index;
|
|
39
|
+
var storedSegmentKeys = Object.keys(this.segmentCache);
|
|
40
|
+
// Extreme fast => everything is empty
|
|
41
|
+
if (names.length === 0 && storedSegmentKeys.length === names.length)
|
|
42
|
+
return isDiff;
|
|
43
|
+
// Quick path
|
|
44
|
+
if (storedSegmentKeys.length !== names.length) {
|
|
45
|
+
isDiff = true;
|
|
46
|
+
this.segmentCache = {};
|
|
47
|
+
names.forEach(function (s) {
|
|
48
|
+
_this.addToSegment(s);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Slowest path => we need to find at least 1 difference because
|
|
53
|
+
for (index = 0; index < names.length && this.isInSegment(names[index]); index++) {
|
|
54
|
+
// TODO: why empty statement?
|
|
55
|
+
}
|
|
56
|
+
if (index < names.length) {
|
|
57
|
+
isDiff = true;
|
|
58
|
+
this.segmentCache = {};
|
|
59
|
+
names.forEach(function (s) {
|
|
60
|
+
_this.addToSegment(s);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return isDiff;
|
|
34
65
|
};
|
|
35
66
|
MySegmentsCacheInMemory.prototype.getRegisteredSegments = function () {
|
|
36
67
|
return Object.keys(this.segmentCache);
|
|
@@ -66,7 +66,7 @@ var SegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
66
66
|
};
|
|
67
67
|
SegmentsCacheInMemory.prototype.getChangeNumber = function (name) {
|
|
68
68
|
var value = this.segmentChangeNumber[name];
|
|
69
|
-
return isIntegerNumber(value) ? value :
|
|
69
|
+
return isIntegerNumber(value) ? value : undefined;
|
|
70
70
|
};
|
|
71
71
|
return SegmentsCacheInMemory;
|
|
72
72
|
}(AbstractSegmentsCacheSync));
|
|
@@ -13,7 +13,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
13
13
|
_this.splitsCache = {};
|
|
14
14
|
_this.ttCache = {};
|
|
15
15
|
_this.changeNumber = -1;
|
|
16
|
-
_this.
|
|
16
|
+
_this.splitsWithSegmentsCount = 0;
|
|
17
17
|
_this.flagSetsCache = {};
|
|
18
18
|
_this.flagSetsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
19
19
|
return _this;
|
|
@@ -22,7 +22,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
22
22
|
this.splitsCache = {};
|
|
23
23
|
this.ttCache = {};
|
|
24
24
|
this.changeNumber = -1;
|
|
25
|
-
this.
|
|
25
|
+
this.splitsWithSegmentsCount = 0;
|
|
26
26
|
};
|
|
27
27
|
SplitsCacheInMemory.prototype.addSplit = function (name, split) {
|
|
28
28
|
var previousSplit = this.getSplit(name);
|
|
@@ -32,9 +32,9 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
32
32
|
if (!this.ttCache[previousTtName])
|
|
33
33
|
delete this.ttCache[previousTtName];
|
|
34
34
|
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (usesSegments(previousSplit)) { // Substract from segments count for the previous version of this Split.
|
|
36
|
+
this.splitsWithSegmentsCount--;
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
if (split) {
|
|
40
40
|
// Store the Split.
|
|
@@ -45,7 +45,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
45
45
|
this.addToFlagSets(split);
|
|
46
46
|
// Add to segments count for the new version of the Split
|
|
47
47
|
if (usesSegments(split))
|
|
48
|
-
this.
|
|
48
|
+
this.splitsWithSegmentsCount++;
|
|
49
49
|
return true;
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
@@ -64,7 +64,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
64
64
|
this.removeFromFlagSets(split.name, split.sets);
|
|
65
65
|
// Update the segments count.
|
|
66
66
|
if (usesSegments(split))
|
|
67
|
-
this.
|
|
67
|
+
this.splitsWithSegmentsCount--;
|
|
68
68
|
return true;
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
@@ -88,7 +88,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
88
88
|
return isFiniteNumber(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
|
|
89
89
|
};
|
|
90
90
|
SplitsCacheInMemory.prototype.usesSegments = function () {
|
|
91
|
-
return this.getChangeNumber() === -1 || this.
|
|
91
|
+
return this.getChangeNumber() === -1 || this.splitsWithSegmentsCount > 0;
|
|
92
92
|
};
|
|
93
93
|
SplitsCacheInMemory.prototype.getNamesByFlagSets = function (flagSets) {
|
|
94
94
|
var _this = this;
|
|
@@ -18,10 +18,9 @@ export function shouldRecordTelemetry(_a) {
|
|
|
18
18
|
return settings.mode !== LOCALHOST_MODE && (settings.core.key === undefined || Math.random() <= ACCEPTANCE_RANGE);
|
|
19
19
|
}
|
|
20
20
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
21
|
-
function TelemetryCacheInMemory(splits, segments
|
|
21
|
+
function TelemetryCacheInMemory(splits, segments) {
|
|
22
22
|
this.splits = splits;
|
|
23
23
|
this.segments = segments;
|
|
24
|
-
this.largeSegments = largeSegments;
|
|
25
24
|
// isEmpty flag
|
|
26
25
|
this.e = true;
|
|
27
26
|
this.notReadyUsage = 0;
|
|
@@ -37,7 +36,10 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
37
36
|
this.tags = [];
|
|
38
37
|
this.exceptions = {};
|
|
39
38
|
this.latencies = {};
|
|
40
|
-
this.updatesFromSSE = {
|
|
39
|
+
this.updatesFromSSE = {
|
|
40
|
+
sp: 0,
|
|
41
|
+
ms: 0
|
|
42
|
+
};
|
|
41
43
|
}
|
|
42
44
|
TelemetryCacheInMemory.prototype.isEmpty = function () { return this.e; };
|
|
43
45
|
TelemetryCacheInMemory.prototype.clear = function () { };
|
|
@@ -57,8 +59,6 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
57
59
|
spC: this.splits && this.splits.getSplitNames().length,
|
|
58
60
|
seC: this.segments && this.segments.getRegisteredSegments().length,
|
|
59
61
|
skC: this.segments && this.segments.getKeysCount(),
|
|
60
|
-
lsC: this.largeSegments && this.largeSegments.getRegisteredSegments().length,
|
|
61
|
-
lskC: this.largeSegments && this.largeSegments.getKeysCount(),
|
|
62
62
|
sL: this.getSessionLength(),
|
|
63
63
|
eQ: this.getEventStats(QUEUED),
|
|
64
64
|
eD: this.getEventStats(DROPPED),
|
|
@@ -190,11 +190,14 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
190
190
|
};
|
|
191
191
|
TelemetryCacheInMemory.prototype.popUpdatesFromSSE = function () {
|
|
192
192
|
var result = this.updatesFromSSE;
|
|
193
|
-
this.updatesFromSSE = {
|
|
193
|
+
this.updatesFromSSE = {
|
|
194
|
+
sp: 0,
|
|
195
|
+
ms: 0,
|
|
196
|
+
};
|
|
194
197
|
return result;
|
|
195
198
|
};
|
|
196
199
|
TelemetryCacheInMemory.prototype.recordUpdatesFromSSE = function (type) {
|
|
197
|
-
this.updatesFromSSE[type]
|
|
200
|
+
this.updatesFromSSE[type]++;
|
|
198
201
|
this.e = false;
|
|
199
202
|
};
|
|
200
203
|
return TelemetryCacheInMemory;
|
|
@@ -17,7 +17,7 @@ var DEFAULT_OPTIONS = {
|
|
|
17
17
|
var DEFAULT_LIBRARY_OPTIONS = {
|
|
18
18
|
enableOfflineQueue: false,
|
|
19
19
|
connectTimeout: DEFAULT_OPTIONS.connectionTimeout,
|
|
20
|
-
lazyConnect: false
|
|
20
|
+
lazyConnect: false
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* Redis adapter on top of the library of choice (written with ioredis) for some extra control.
|
|
@@ -34,10 +34,10 @@ var SegmentsCacheInRedis = /** @class */ (function () {
|
|
|
34
34
|
var _this = this;
|
|
35
35
|
return this.redis.get(this.keys.buildSegmentTillKey(name)).then(function (value) {
|
|
36
36
|
var i = parseInt(value, 10);
|
|
37
|
-
return isNaNNumber(i) ?
|
|
37
|
+
return isNaNNumber(i) ? undefined : i;
|
|
38
38
|
}).catch(function (e) {
|
|
39
39
|
_this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from segments storage. Error: ' + e);
|
|
40
|
-
return
|
|
40
|
+
return undefined;
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
SegmentsCacheInRedis.prototype.registerSegments = function (segments) {
|
|
@@ -9,17 +9,23 @@ import { TelemetryCacheInRedis } from './TelemetryCacheInRedis';
|
|
|
9
9
|
import { UniqueKeysCacheInRedis } from './UniqueKeysCacheInRedis';
|
|
10
10
|
import { ImpressionCountsCacheInRedis } from './ImpressionCountsCacheInRedis';
|
|
11
11
|
import { metadataBuilder } from '../utils';
|
|
12
|
+
var RD;
|
|
13
|
+
try {
|
|
14
|
+
// Using `require` to prevent error when bundling or importing the SDK in a .mjs file, since ioredis is a CommonJS module.
|
|
15
|
+
// Redis storage is not supported with .mjs files.
|
|
16
|
+
RD = require('./RedisAdapter').RedisAdapter;
|
|
17
|
+
}
|
|
18
|
+
catch (error) { /* empty */ }
|
|
12
19
|
/**
|
|
13
|
-
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
20
|
+
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.js
|
|
14
21
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
15
22
|
*/
|
|
16
23
|
export function InRedisStorage(options) {
|
|
17
24
|
if (options === void 0) { options = {}; }
|
|
18
|
-
// Lazy loading to prevent error when bundling or importing the SDK in a .mjs file, since ioredis is a CommonJS module.
|
|
19
|
-
// Redis storage is not supported with .mjs files.
|
|
20
|
-
var RD = require('./RedisAdapter').RedisAdapter;
|
|
21
25
|
var prefix = validatePrefix(options.prefix);
|
|
22
26
|
function InRedisStorageFactory(params) {
|
|
27
|
+
if (!RD)
|
|
28
|
+
throw new Error('The SDK Redis storage is unavailable. Make sure your runtime environment supports CommonJS (`require`) so the `ioredis` dependency can be imported.');
|
|
23
29
|
var onReadyCb = params.onReadyCb, settings = params.settings, _a = params.settings, log = _a.log, impressionsMode = _a.sync.impressionsMode;
|
|
24
30
|
var metadata = metadataBuilder(settings);
|
|
25
31
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
@@ -27,7 +33,7 @@ export function InRedisStorage(options) {
|
|
|
27
33
|
var telemetry = new TelemetryCacheInRedis(log, keys, redisClient);
|
|
28
34
|
var impressionCountsCache = impressionsMode !== DEBUG ? new ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
|
|
29
35
|
var uniqueKeysCache = impressionsMode === NONE ? new UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;
|
|
30
|
-
//
|
|
36
|
+
// Subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
31
37
|
redisClient.on('connect', function () {
|
|
32
38
|
onReadyCb();
|
|
33
39
|
if (impressionCountsCache)
|
|
@@ -63,10 +63,10 @@ var SegmentsCachePluggable = /** @class */ (function () {
|
|
|
63
63
|
var _this = this;
|
|
64
64
|
return this.wrapper.get(this.keys.buildSegmentTillKey(name)).then(function (value) {
|
|
65
65
|
var i = parseInt(value, 10);
|
|
66
|
-
return isNaNNumber(i) ?
|
|
66
|
+
return isNaNNumber(i) ? undefined : i;
|
|
67
67
|
}).catch(function (e) {
|
|
68
68
|
_this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from segments storage. Error: ' + e);
|
|
69
|
-
return
|
|
69
|
+
return undefined;
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
@@ -5,7 +5,7 @@ import { setToArray, _Set } from '../../utils/lang/sets';
|
|
|
5
5
|
* The `_cache` property is the object were items are stored.
|
|
6
6
|
* Intended for testing purposes.
|
|
7
7
|
*
|
|
8
|
-
* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves
|
|
8
|
+
* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves inmediatelly.
|
|
9
9
|
*/
|
|
10
10
|
export function inMemoryWrapperFactory(connDelay) {
|
|
11
11
|
var _cache = {};
|
|
@@ -55,7 +55,6 @@ export function PluggableStorage(options) {
|
|
|
55
55
|
var metadata = metadataBuilder(settings);
|
|
56
56
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
57
57
|
var wrapper = wrapperAdapter(log, options.wrapper);
|
|
58
|
-
var connectPromise;
|
|
59
58
|
var isSyncronizer = mode === undefined; // If mode is not defined, the synchronizer is running
|
|
60
59
|
var isPartialConsumer = mode === CONSUMER_PARTIAL_MODE;
|
|
61
60
|
var telemetry = shouldRecordTelemetry(params) || isSyncronizer ?
|
|
@@ -73,6 +72,37 @@ export function PluggableStorage(options) {
|
|
|
73
72
|
settings.core.key === undefined ? new UniqueKeysCacheInMemory() : new UniqueKeysCacheInMemoryCS() :
|
|
74
73
|
new UniqueKeysCachePluggable(log, keys.buildUniqueKeysKey(), wrapper) :
|
|
75
74
|
undefined;
|
|
75
|
+
// Connects to wrapper and emits SDK_READY event on main client
|
|
76
|
+
var connectPromise = wrapper.connect().then(function () {
|
|
77
|
+
if (isSyncronizer) {
|
|
78
|
+
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
79
|
+
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
80
|
+
var currentHash = getStorageHash(settings);
|
|
81
|
+
if (hash !== currentHash) {
|
|
82
|
+
log.info(LOG_PREFIX + 'Storage HASH has changed (SDK key, flags filter criteria or flags spec version was modified). Clearing cache');
|
|
83
|
+
return wrapper.getKeysByPrefix(keys.prefix + ".").then(function (storageKeys) {
|
|
84
|
+
return Promise.all(storageKeys.map(function (storageKey) { return wrapper.del(storageKey); }));
|
|
85
|
+
}).then(function () { return wrapper.set(keys.buildHashKey(), currentHash); });
|
|
86
|
+
}
|
|
87
|
+
}).then(function () {
|
|
88
|
+
onReadyCb();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
93
|
+
if (impressionCountsCache && impressionCountsCache.start)
|
|
94
|
+
impressionCountsCache.start();
|
|
95
|
+
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
96
|
+
uniqueKeysCache.start();
|
|
97
|
+
if (telemetry && telemetry.recordConfig)
|
|
98
|
+
telemetry.recordConfig();
|
|
99
|
+
onReadyCb();
|
|
100
|
+
}
|
|
101
|
+
}).catch(function (e) {
|
|
102
|
+
e = e || new Error('Error connecting wrapper');
|
|
103
|
+
onReadyCb(e);
|
|
104
|
+
return e; // Propagate error for shared clients
|
|
105
|
+
});
|
|
76
106
|
return {
|
|
77
107
|
splits: new SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
78
108
|
segments: new SegmentsCachePluggable(log, keys, wrapper),
|
|
@@ -81,41 +111,6 @@ export function PluggableStorage(options) {
|
|
|
81
111
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
82
112
|
telemetry: telemetry,
|
|
83
113
|
uniqueKeys: uniqueKeysCache,
|
|
84
|
-
init: function () {
|
|
85
|
-
if (connectPromise)
|
|
86
|
-
return connectPromise;
|
|
87
|
-
// Connects to wrapper and emits SDK_READY event on main client
|
|
88
|
-
return connectPromise = wrapper.connect().then(function () {
|
|
89
|
-
if (isSyncronizer) {
|
|
90
|
-
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
91
|
-
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
92
|
-
var currentHash = getStorageHash(settings);
|
|
93
|
-
if (hash !== currentHash) {
|
|
94
|
-
log.info(LOG_PREFIX + 'Storage HASH has changed (SDK key, flags filter criteria or flags spec version was modified). Clearing cache');
|
|
95
|
-
return wrapper.getKeysByPrefix(keys.prefix + ".").then(function (storageKeys) {
|
|
96
|
-
return Promise.all(storageKeys.map(function (storageKey) { return wrapper.del(storageKey); }));
|
|
97
|
-
}).then(function () { return wrapper.set(keys.buildHashKey(), currentHash); });
|
|
98
|
-
}
|
|
99
|
-
}).then(function () {
|
|
100
|
-
onReadyCb();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
105
|
-
if (impressionCountsCache && impressionCountsCache.start)
|
|
106
|
-
impressionCountsCache.start();
|
|
107
|
-
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
108
|
-
uniqueKeysCache.start();
|
|
109
|
-
if (telemetry && telemetry.recordConfig)
|
|
110
|
-
telemetry.recordConfig();
|
|
111
|
-
onReadyCb();
|
|
112
|
-
}
|
|
113
|
-
}).catch(function (e) {
|
|
114
|
-
e = e || new Error('Error connecting wrapper');
|
|
115
|
-
onReadyCb(e);
|
|
116
|
-
return e; // Propagate error for shared clients
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
114
|
// Stop periodic flush and disconnect the underlying storage
|
|
120
115
|
destroy: function () {
|
|
121
116
|
return Promise.all(isSyncronizer ? [] : [
|
|
@@ -125,7 +120,7 @@ export function PluggableStorage(options) {
|
|
|
125
120
|
},
|
|
126
121
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
127
122
|
shared: function (_, onReadyCb) {
|
|
128
|
-
|
|
123
|
+
connectPromise.then(onReadyCb);
|
|
129
124
|
return __assign(__assign({}, this), {
|
|
130
125
|
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
131
126
|
destroy: function () { } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { forOwn } from '../../../utils/lang';
|
|
2
2
|
import { syncTaskFactory } from '../../syncTask';
|
|
3
3
|
import { CONTROL } from '../../../utils/constants';
|
|
4
|
-
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../../../readiness/constants';
|
|
4
|
+
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../../../readiness/constants';
|
|
5
5
|
import { SYNC_OFFLINE_DATA, ERROR_SYNC_OFFLINE_LOADING } from '../../../logger/constants';
|
|
6
6
|
/**
|
|
7
7
|
* Offline equivalent of `splitChangesUpdaterFactory`
|
|
@@ -43,8 +43,13 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
43
43
|
readiness.splits.emit(SDK_SPLITS_ARRIVED);
|
|
44
44
|
if (startingUp) {
|
|
45
45
|
startingUp = false;
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
Promise.resolve(splitsCache.checkCache()).then(function (cacheReady) {
|
|
47
|
+
// Emits SDK_READY_FROM_CACHE
|
|
48
|
+
if (cacheReady)
|
|
49
|
+
readiness.splits.emit(SDK_SPLITS_CACHE_LOADED);
|
|
50
|
+
// Emits SDK_READY
|
|
51
|
+
readiness.segments.emit(SDK_SEGMENTS_ARRIVED);
|
|
52
|
+
});
|
|
48
53
|
}
|
|
49
54
|
return true;
|
|
50
55
|
});
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
* Factory of MySegments fetcher.
|
|
3
3
|
* MySegments fetcher is a wrapper around `mySegments` API service that parses the response and handle errors.
|
|
4
4
|
*/
|
|
5
|
-
export function mySegmentsFetcherFactory(
|
|
6
|
-
return function mySegmentsFetcher(userMatchingKey, noCache,
|
|
7
|
-
// Optional decorator for `
|
|
5
|
+
export function mySegmentsFetcherFactory(fetchMySegments) {
|
|
6
|
+
return function mySegmentsFetcher(userMatchingKey, noCache,
|
|
7
|
+
// Optional decorator for `fetchMySegments` promise, such as timeout or time tracker
|
|
8
8
|
decorator) {
|
|
9
|
-
var mySegmentsPromise =
|
|
9
|
+
var mySegmentsPromise = fetchMySegments(userMatchingKey, noCache);
|
|
10
10
|
if (decorator)
|
|
11
11
|
mySegmentsPromise = decorator(mySegmentsPromise);
|
|
12
|
-
|
|
12
|
+
// Extract segment names
|
|
13
|
+
return mySegmentsPromise
|
|
14
|
+
.then(function (resp) { return resp.json(); })
|
|
15
|
+
.then(function (json) { return json.mySegments.map(function (segment) { return segment.name; }); });
|
|
13
16
|
};
|
|
14
17
|
}
|
|
@@ -20,7 +20,7 @@ function greedyFetch(fetchSegmentChanges, since, segmentName, noCache, targetTil
|
|
|
20
20
|
*/
|
|
21
21
|
export function segmentChangesFetcherFactory(fetchSegmentChanges) {
|
|
22
22
|
return function segmentChangesFetcher(since, segmentName, noCache, till,
|
|
23
|
-
// Optional decorator for `
|
|
23
|
+
// Optional decorator for `fetchMySegments` promise, such as timeout or time tracker
|
|
24
24
|
decorator) {
|
|
25
25
|
var segmentsPromise = greedyFetch(fetchSegmentChanges, since, segmentName, noCache, till);
|
|
26
26
|
if (decorator)
|
|
@@ -43,7 +43,7 @@ export function pollingManagerCSFactory(params) {
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
function add(matchingKey, readiness, storage) {
|
|
46
|
-
var mySegmentsSyncTask = mySegmentsSyncTaskFactory(splitApi.
|
|
46
|
+
var mySegmentsSyncTask = mySegmentsSyncTaskFactory(splitApi.fetchMySegments, storage, readiness, settings, matchingKey);
|
|
47
47
|
// smart ready
|
|
48
48
|
function smartReady() {
|
|
49
49
|
if (!readiness.isReady() && !storage.splits.usesSegments())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { splitsSyncTaskFactory } from './syncTasks/splitsSyncTask';
|
|
2
2
|
import { segmentsSyncTaskFactory } from './syncTasks/segmentsSyncTask';
|
|
3
|
-
import { thenable } from '../../utils/promise/thenable';
|
|
4
3
|
import { POLLING_START, POLLING_STOP, LOG_PREFIX_SYNC_POLLING } from '../../logger/constants';
|
|
5
4
|
/**
|
|
6
5
|
* Expose start / stop mechanism for pulling data from services.
|
|
@@ -19,9 +18,10 @@ export function pollingManagerSSFactory(params) {
|
|
|
19
18
|
log.debug(LOG_PREFIX_SYNC_POLLING + ("Splits will be refreshed each " + settings.scheduler.featuresRefreshRate + " millis"));
|
|
20
19
|
log.debug(LOG_PREFIX_SYNC_POLLING + ("Segments will be refreshed each " + settings.scheduler.segmentsRefreshRate + " millis"));
|
|
21
20
|
var startingUp = splitsSyncTask.start();
|
|
22
|
-
if (
|
|
21
|
+
if (startingUp) {
|
|
23
22
|
startingUp.then(function () {
|
|
24
|
-
|
|
23
|
+
if (splitsSyncTask.isRunning())
|
|
24
|
+
segmentsSyncTask.start();
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
},
|
|
@@ -4,6 +4,6 @@ import { mySegmentsUpdaterFactory } from '../updaters/mySegmentsUpdater';
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a sync task that periodically executes a `mySegmentsUpdater` task
|
|
6
6
|
*/
|
|
7
|
-
export function mySegmentsSyncTaskFactory(
|
|
8
|
-
return syncTaskFactory(settings.log, mySegmentsUpdaterFactory(settings.log, mySegmentsFetcherFactory(
|
|
7
|
+
export function mySegmentsSyncTaskFactory(fetchMySegments, storage, readiness, settings, matchingKey) {
|
|
8
|
+
return syncTaskFactory(settings.log, mySegmentsUpdaterFactory(settings.log, mySegmentsFetcherFactory(fetchMySegments), storage.splits, storage.segments, readiness.segments, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, matchingKey), settings.scheduler.segmentsRefreshRate, 'mySegmentsUpdater');
|
|
9
9
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { timeout } from '../../../utils/promise/timeout';
|
|
2
2
|
import { SDK_SEGMENTS_ARRIVED } from '../../../readiness/constants';
|
|
3
3
|
import { SYNC_MYSEGMENTS_FETCH_RETRY } from '../../../logger/constants';
|
|
4
|
-
import { MEMBERSHIPS_LS_UPDATE } from '../../streaming/constants';
|
|
5
4
|
/**
|
|
6
5
|
* factory of MySegments updater, a task that:
|
|
7
6
|
* - fetches mySegments using `mySegmentsFetcher`
|
|
8
7
|
* - updates `mySegmentsCache`
|
|
9
8
|
* - uses `segmentsEventEmitter` to emit events related to segments data updates
|
|
10
9
|
*/
|
|
11
|
-
export function mySegmentsUpdaterFactory(log, mySegmentsFetcher,
|
|
12
|
-
var splits = storage.splits, segments = storage.segments, largeSegments = storage.largeSegments;
|
|
10
|
+
export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, splitsCache, mySegmentsCache, segmentsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, matchingKey) {
|
|
13
11
|
var readyOnAlreadyExistentState = true;
|
|
14
12
|
var startingUp = true;
|
|
15
13
|
/** timeout and telemetry decorator for `splitChangesFetcher` promise */
|
|
@@ -21,27 +19,36 @@ export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmen
|
|
|
21
19
|
// @TODO if allowing pluggable storages, handle async execution
|
|
22
20
|
function updateSegments(segmentsData) {
|
|
23
21
|
var shouldNotifyUpdate;
|
|
24
|
-
if (segmentsData
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
segments.resetSegments(segmentsData);
|
|
22
|
+
if (Array.isArray(segmentsData)) {
|
|
23
|
+
// Update the list of segment names available
|
|
24
|
+
shouldNotifyUpdate = mySegmentsCache.resetSegments(segmentsData);
|
|
28
25
|
}
|
|
29
26
|
else {
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
// Add/Delete the segment
|
|
28
|
+
var name_1 = segmentsData.name, add = segmentsData.add;
|
|
29
|
+
if (mySegmentsCache.isInSegment(name_1) !== add) {
|
|
30
|
+
shouldNotifyUpdate = true;
|
|
31
|
+
if (add)
|
|
32
|
+
mySegmentsCache.addToSegment(name_1);
|
|
33
|
+
else
|
|
34
|
+
mySegmentsCache.removeFromSegment(name_1);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
shouldNotifyUpdate = false;
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
// Notify update if required
|
|
34
|
-
if (
|
|
41
|
+
if (splitsCache.usesSegments() && (shouldNotifyUpdate || readyOnAlreadyExistentState)) {
|
|
35
42
|
readyOnAlreadyExistentState = false;
|
|
36
43
|
segmentsEventEmitter.emit(SDK_SEGMENTS_ARRIVED);
|
|
37
44
|
}
|
|
38
45
|
}
|
|
39
|
-
function _mySegmentsUpdater(retry, segmentsData, noCache
|
|
46
|
+
function _mySegmentsUpdater(retry, segmentsData, noCache) {
|
|
40
47
|
var updaterPromise = segmentsData ?
|
|
41
48
|
// If segmentsData is provided, there is no need to fetch mySegments
|
|
42
49
|
new Promise(function (res) { updateSegments(segmentsData); res(true); }) :
|
|
43
50
|
// If not provided, fetch mySegments
|
|
44
|
-
mySegmentsFetcher(matchingKey, noCache,
|
|
51
|
+
mySegmentsFetcher(matchingKey, noCache, _promiseDecorator).then(function (segments) {
|
|
45
52
|
// Only when we have downloaded segments completely, we should not keep retrying anymore
|
|
46
53
|
startingUp = false;
|
|
47
54
|
updateSegments(segments);
|
|
@@ -68,9 +75,8 @@ export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmen
|
|
|
68
75
|
* (2) an object with a segment name and action (true: add, or false: delete) to update the storage,
|
|
69
76
|
* (3) or `undefined`, for which the updater will fetch mySegments in order to sync the storage.
|
|
70
77
|
* @param {boolean | undefined} noCache true to revalidate data to fetch
|
|
71
|
-
* @param {boolean | undefined} till query param to bypass CDN requests
|
|
72
78
|
*/
|
|
73
|
-
return function mySegmentsUpdater(segmentsData, noCache
|
|
74
|
-
return _mySegmentsUpdater(0, segmentsData, noCache
|
|
79
|
+
return function mySegmentsUpdater(segmentsData, noCache) {
|
|
80
|
+
return _mySegmentsUpdater(0, segmentsData, noCache);
|
|
75
81
|
};
|
|
76
82
|
}
|
|
@@ -20,9 +20,9 @@ export function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segment
|
|
|
20
20
|
var sincePromise = Promise.resolve(segments.getChangeNumber(segmentName));
|
|
21
21
|
return sincePromise.then(function (since) {
|
|
22
22
|
// if fetchOnlyNew flag, avoid processing already fetched segments
|
|
23
|
-
if (fetchOnlyNew && since !==
|
|
23
|
+
if (fetchOnlyNew && since !== undefined)
|
|
24
24
|
return -1;
|
|
25
|
-
return segmentChangesFetcher(since, segmentName, noCache, till).then(function (changes) {
|
|
25
|
+
return segmentChangesFetcher(since || -1, segmentName, noCache, till).then(function (changes) {
|
|
26
26
|
var changeNumber = -1;
|
|
27
27
|
var results = [];
|
|
28
28
|
changes.forEach(function (x) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _Set, setToArray } from '../../../utils/lang/sets';
|
|
2
2
|
import { timeout } from '../../../utils/promise/timeout';
|
|
3
|
-
import { SDK_SPLITS_ARRIVED } from '../../../readiness/constants';
|
|
3
|
+
import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../../../readiness/constants';
|
|
4
4
|
import { SYNC_SPLITS_FETCH, SYNC_SPLITS_NEW, SYNC_SPLITS_REMOVED, SYNC_SPLITS_SEGMENTS, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
|
|
5
5
|
import { startsWith } from '../../../utils/lang';
|
|
6
6
|
import { IN_SEGMENT } from '../../../utils/constants';
|
|
@@ -11,7 +11,7 @@ function checkAllSegmentsExist(segments) {
|
|
|
11
11
|
var registeredSegments = Promise.resolve(segments.getRegisteredSegments());
|
|
12
12
|
return registeredSegments.then(function (segmentNames) {
|
|
13
13
|
return Promise.all(segmentNames.map(function (segmentName) { return segments.getChangeNumber(segmentName); }))
|
|
14
|
-
.then(function (changeNumbers) { return changeNumbers.every(function (changeNumber) { return changeNumber !==
|
|
14
|
+
.then(function (changeNumbers) { return changeNumbers.every(function (changeNumber) { return changeNumber !== undefined; }); });
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -121,7 +121,7 @@ export function splitChangesUpdaterFactory(log, splitChangesFetcher, splits, seg
|
|
|
121
121
|
function _splitChangesUpdater(since, retry) {
|
|
122
122
|
if (retry === void 0) { retry = 0; }
|
|
123
123
|
log.debug(SYNC_SPLITS_FETCH, [since]);
|
|
124
|
-
|
|
124
|
+
var fetcherPromise = Promise.resolve(splitUpdateNotification ?
|
|
125
125
|
{ splits: [splitUpdateNotification.payload], till: splitUpdateNotification.changeNumber } :
|
|
126
126
|
splitChangesFetcher(since, noCache, till, _promiseDecorator))
|
|
127
127
|
.then(function (splitChanges) {
|
|
@@ -165,6 +165,15 @@ export function splitChangesUpdaterFactory(log, splitChangesFetcher, splits, seg
|
|
|
165
165
|
}
|
|
166
166
|
return false;
|
|
167
167
|
});
|
|
168
|
+
// After triggering the requests, if we have cached splits information let's notify that to emit SDK_READY_FROM_CACHE.
|
|
169
|
+
// Wrapping in a promise since checkCache can be async.
|
|
170
|
+
if (splitsEventEmitter && startingUp) {
|
|
171
|
+
Promise.resolve(splits.checkCache()).then(function (isCacheReady) {
|
|
172
|
+
if (isCacheReady)
|
|
173
|
+
splitsEventEmitter.emit(SDK_SPLITS_CACHE_LOADED);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return fetcherPromise;
|
|
168
177
|
}
|
|
169
178
|
var sincePromise = Promise.resolve(splits.getChangeNumber()); // `getChangeNumber` never rejects or throws error
|
|
170
179
|
return sincePromise.then(_splitChangesUpdater);
|
|
@@ -10,7 +10,7 @@ import { hash } from '../../../utils/murmur3/murmur3';
|
|
|
10
10
|
export function authenticateFactory(fetchAuth) {
|
|
11
11
|
/**
|
|
12
12
|
* Run authentication requests to Auth Server, and returns a promise that resolves with the decoded JTW token.
|
|
13
|
-
* @param {string[] | undefined} userKeys set of user Keys to track
|
|
13
|
+
* @param {string[] | undefined} userKeys set of user Keys to track MY_SEGMENTS_CHANGES. It is undefined for server-side API.
|
|
14
14
|
*/
|
|
15
15
|
return function authenticate(userKeys) {
|
|
16
16
|
return fetchAuth(userKeys)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorParser, messageParser } from './NotificationParser';
|
|
2
2
|
import { notificationKeeperFactory } from './NotificationKeeper';
|
|
3
|
-
import { PUSH_RETRYABLE_ERROR, PUSH_NONRETRYABLE_ERROR, OCCUPANCY, CONTROL,
|
|
3
|
+
import { PUSH_RETRYABLE_ERROR, PUSH_NONRETRYABLE_ERROR, OCCUPANCY, CONTROL, MY_SEGMENTS_UPDATE, MY_SEGMENTS_UPDATE_V2, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE } from '../constants';
|
|
4
4
|
import { STREAMING_PARSING_ERROR_FAILS, ERROR_STREAMING_SSE, STREAMING_PARSING_MESSAGE_FAILS, STREAMING_NEW_MESSAGE } from '../../../logger/constants';
|
|
5
5
|
import { ABLY_ERROR, NON_REQUESTED, SSE_CONNECTION_ERROR } from '../../../utils/constants';
|
|
6
6
|
/**
|
|
@@ -65,18 +65,20 @@ export function SSEHandlerFactory(log, pushEmitter, telemetryTracker) {
|
|
|
65
65
|
}
|
|
66
66
|
var parsedData = messageWithParsedData.parsedData, data = messageWithParsedData.data, channel = messageWithParsedData.channel, timestamp = messageWithParsedData.timestamp;
|
|
67
67
|
log.debug(STREAMING_NEW_MESSAGE, [data]);
|
|
68
|
-
// we only handle update events if streaming is up
|
|
68
|
+
// we only handle update events if streaming is up.
|
|
69
69
|
if (!notificationKeeper.isStreamingUp() && [OCCUPANCY, CONTROL].indexOf(parsedData.type) === -1)
|
|
70
70
|
return;
|
|
71
71
|
switch (parsedData.type) {
|
|
72
72
|
/* update events */
|
|
73
73
|
case SPLIT_UPDATE:
|
|
74
74
|
case SEGMENT_UPDATE:
|
|
75
|
-
case
|
|
76
|
-
case MEMBERSHIPS_LS_UPDATE:
|
|
75
|
+
case MY_SEGMENTS_UPDATE_V2:
|
|
77
76
|
case SPLIT_KILL:
|
|
78
77
|
pushEmitter.emit(parsedData.type, parsedData);
|
|
79
78
|
break;
|
|
79
|
+
case MY_SEGMENTS_UPDATE:
|
|
80
|
+
pushEmitter.emit(parsedData.type, parsedData, channel);
|
|
81
|
+
break;
|
|
80
82
|
/* occupancy & control events, handled by NotificationManagerKeeper */
|
|
81
83
|
case OCCUPANCY:
|
|
82
84
|
notificationKeeper.handleOccupancyEvent(parsedData.metrics.publishers, channel, timestamp);
|