@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
|
@@ -30,32 +30,24 @@ function InLocalStorage(options) {
|
|
|
30
30
|
params.settings.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
|
|
31
31
|
return (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
|
|
32
32
|
}
|
|
33
|
-
var
|
|
33
|
+
var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
|
|
34
34
|
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
35
35
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
36
36
|
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
37
37
|
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
38
38
|
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
39
|
-
var largeSegments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey));
|
|
40
39
|
return {
|
|
41
40
|
splits: splits,
|
|
42
41
|
segments: segments,
|
|
43
|
-
largeSegments: largeSegments,
|
|
44
42
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
45
43
|
impressionCounts: impressionsMode !== constants_2.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
46
44
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
47
45
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
48
46
|
uniqueKeys: impressionsMode === constants_2.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
49
|
-
init: function () {
|
|
50
|
-
if (settings.mode === constants_2.LOCALHOST_MODE || splits.getChangeNumber() > -1) {
|
|
51
|
-
Promise.resolve().then(onReadyFromCacheCb);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
47
|
destroy: function () {
|
|
55
48
|
var _a;
|
|
56
49
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
57
50
|
this.segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
58
|
-
this.largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
59
51
|
this.impressions.clear();
|
|
60
52
|
this.impressionCounts && this.impressionCounts.clear();
|
|
61
53
|
this.events.clear();
|
|
@@ -63,10 +55,10 @@ function InLocalStorage(options) {
|
|
|
63
55
|
},
|
|
64
56
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
65
57
|
shared: function (matchingKey) {
|
|
58
|
+
var childKeysBuilder = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
66
59
|
return {
|
|
67
60
|
splits: this.splits,
|
|
68
|
-
segments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log,
|
|
69
|
-
largeSegments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey)),
|
|
61
|
+
segments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, childKeysBuilder),
|
|
70
62
|
impressions: this.impressions,
|
|
71
63
|
impressionCounts: this.impressionCounts,
|
|
72
64
|
events: this.events,
|
|
@@ -74,7 +66,6 @@ function InLocalStorage(options) {
|
|
|
74
66
|
destroy: function () {
|
|
75
67
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
76
68
|
this.segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
77
|
-
this.largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
78
69
|
}
|
|
79
70
|
};
|
|
80
71
|
},
|
|
@@ -9,22 +9,18 @@ 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 key_1 = require("../../utils/key");
|
|
13
|
-
var dataLoader_1 = require("../dataLoader");
|
|
14
12
|
/**
|
|
15
13
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
16
14
|
*
|
|
17
15
|
* @param params parameters required by EventsCacheSync
|
|
18
16
|
*/
|
|
19
17
|
function InMemoryStorageCSFactory(params) {
|
|
20
|
-
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
|
|
21
19
|
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
22
20
|
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
23
|
-
var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
24
21
|
var storage = {
|
|
25
22
|
splits: splits,
|
|
26
23
|
segments: segments,
|
|
27
|
-
largeSegments: largeSegments,
|
|
28
24
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
29
25
|
impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
30
26
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
@@ -34,23 +30,16 @@ function InMemoryStorageCSFactory(params) {
|
|
|
34
30
|
destroy: function () {
|
|
35
31
|
this.splits.clear();
|
|
36
32
|
this.segments.clear();
|
|
37
|
-
this.largeSegments.clear();
|
|
38
33
|
this.impressions.clear();
|
|
39
34
|
this.impressionCounts && this.impressionCounts.clear();
|
|
40
35
|
this.events.clear();
|
|
41
36
|
this.uniqueKeys && this.uniqueKeys.clear();
|
|
42
37
|
},
|
|
43
38
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
|
|
44
|
-
shared: function (
|
|
45
|
-
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
46
|
-
var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
47
|
-
if (preloadedData) {
|
|
48
|
-
(0, dataLoader_1.loadData)(preloadedData, { segments: segments, largeSegments: largeSegments }, matchingKey);
|
|
49
|
-
}
|
|
39
|
+
shared: function () {
|
|
50
40
|
return {
|
|
51
41
|
splits: this.splits,
|
|
52
|
-
segments:
|
|
53
|
-
largeSegments: largeSegments,
|
|
42
|
+
segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
54
43
|
impressions: this.impressions,
|
|
55
44
|
impressionCounts: this.impressionCounts,
|
|
56
45
|
events: this.events,
|
|
@@ -59,7 +48,6 @@ function InMemoryStorageCSFactory(params) {
|
|
|
59
48
|
destroy: function () {
|
|
60
49
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
61
50
|
this.segments.clear();
|
|
62
|
-
this.largeSegments.clear();
|
|
63
51
|
}
|
|
64
52
|
};
|
|
65
53
|
},
|
|
@@ -75,11 +63,6 @@ function InMemoryStorageCSFactory(params) {
|
|
|
75
63
|
if (storage.uniqueKeys)
|
|
76
64
|
storage.uniqueKeys.track = noopTrack;
|
|
77
65
|
}
|
|
78
|
-
if (preloadedData) {
|
|
79
|
-
(0, dataLoader_1.loadData)(preloadedData, storage, (0, key_1.getMatching)(params.settings.core.key));
|
|
80
|
-
if (splits.getChangeNumber() > -1)
|
|
81
|
-
onReadyFromCacheCb();
|
|
82
|
-
}
|
|
83
66
|
return storage;
|
|
84
67
|
}
|
|
85
68
|
exports.InMemoryStorageCSFactory = InMemoryStorageCSFactory;
|
|
@@ -14,26 +14,57 @@ var MySegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
14
14
|
_this.segmentCache = {};
|
|
15
15
|
return _this;
|
|
16
16
|
}
|
|
17
|
+
MySegmentsCacheInMemory.prototype.clear = function () {
|
|
18
|
+
this.segmentCache = {};
|
|
19
|
+
};
|
|
17
20
|
MySegmentsCacheInMemory.prototype.addToSegment = function (name) {
|
|
18
|
-
if (this.segmentCache[name])
|
|
19
|
-
return false;
|
|
20
21
|
this.segmentCache[name] = true;
|
|
21
22
|
return true;
|
|
22
23
|
};
|
|
23
24
|
MySegmentsCacheInMemory.prototype.removeFromSegment = function (name) {
|
|
24
|
-
if (!this.segmentCache[name])
|
|
25
|
-
return false;
|
|
26
25
|
delete this.segmentCache[name];
|
|
27
26
|
return true;
|
|
28
27
|
};
|
|
29
28
|
MySegmentsCacheInMemory.prototype.isInSegment = function (name) {
|
|
30
29
|
return this.segmentCache[name] === true;
|
|
31
30
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Reset (update) the cached list of segments with the given list, removing and adding segments if necessary.
|
|
33
|
+
* @NOTE based on the way we use segments in the browser, this way is the best option
|
|
34
|
+
*
|
|
35
|
+
* @param {string[]} names list of segment names
|
|
36
|
+
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
37
|
+
*/
|
|
38
|
+
MySegmentsCacheInMemory.prototype.resetSegments = function (names) {
|
|
39
|
+
var _this = this;
|
|
40
|
+
var isDiff = false;
|
|
41
|
+
var index;
|
|
42
|
+
var storedSegmentKeys = Object.keys(this.segmentCache);
|
|
43
|
+
// Extreme fast => everything is empty
|
|
44
|
+
if (names.length === 0 && storedSegmentKeys.length === names.length)
|
|
45
|
+
return isDiff;
|
|
46
|
+
// Quick path
|
|
47
|
+
if (storedSegmentKeys.length !== names.length) {
|
|
48
|
+
isDiff = true;
|
|
49
|
+
this.segmentCache = {};
|
|
50
|
+
names.forEach(function (s) {
|
|
51
|
+
_this.addToSegment(s);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Slowest path => we need to find at least 1 difference because
|
|
56
|
+
for (index = 0; index < names.length && this.isInSegment(names[index]); index++) {
|
|
57
|
+
// TODO: why empty statement?
|
|
58
|
+
}
|
|
59
|
+
if (index < names.length) {
|
|
60
|
+
isDiff = true;
|
|
61
|
+
this.segmentCache = {};
|
|
62
|
+
names.forEach(function (s) {
|
|
63
|
+
_this.addToSegment(s);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return isDiff;
|
|
37
68
|
};
|
|
38
69
|
MySegmentsCacheInMemory.prototype.getRegisteredSegments = function () {
|
|
39
70
|
return Object.keys(this.segmentCache);
|
|
@@ -69,7 +69,7 @@ var SegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
69
69
|
};
|
|
70
70
|
SegmentsCacheInMemory.prototype.getChangeNumber = function (name) {
|
|
71
71
|
var value = this.segmentChangeNumber[name];
|
|
72
|
-
return (0, lang_1.isIntegerNumber)(value) ? value :
|
|
72
|
+
return (0, lang_1.isIntegerNumber)(value) ? value : undefined;
|
|
73
73
|
};
|
|
74
74
|
return SegmentsCacheInMemory;
|
|
75
75
|
}(AbstractSegmentsCacheSync_1.AbstractSegmentsCacheSync));
|
|
@@ -16,7 +16,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
16
16
|
_this.splitsCache = {};
|
|
17
17
|
_this.ttCache = {};
|
|
18
18
|
_this.changeNumber = -1;
|
|
19
|
-
_this.
|
|
19
|
+
_this.splitsWithSegmentsCount = 0;
|
|
20
20
|
_this.flagSetsCache = {};
|
|
21
21
|
_this.flagSetsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
22
22
|
return _this;
|
|
@@ -25,7 +25,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
25
25
|
this.splitsCache = {};
|
|
26
26
|
this.ttCache = {};
|
|
27
27
|
this.changeNumber = -1;
|
|
28
|
-
this.
|
|
28
|
+
this.splitsWithSegmentsCount = 0;
|
|
29
29
|
};
|
|
30
30
|
SplitsCacheInMemory.prototype.addSplit = function (name, split) {
|
|
31
31
|
var previousSplit = this.getSplit(name);
|
|
@@ -35,9 +35,9 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
35
35
|
if (!this.ttCache[previousTtName])
|
|
36
36
|
delete this.ttCache[previousTtName];
|
|
37
37
|
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(previousSplit)) { // Substract from segments count for the previous version of this Split.
|
|
39
|
+
this.splitsWithSegmentsCount--;
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
if (split) {
|
|
43
43
|
// Store the Split.
|
|
@@ -48,7 +48,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
48
48
|
this.addToFlagSets(split);
|
|
49
49
|
// Add to segments count for the new version of the Split
|
|
50
50
|
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
|
|
51
|
-
this.
|
|
51
|
+
this.splitsWithSegmentsCount++;
|
|
52
52
|
return true;
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
@@ -67,7 +67,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
67
67
|
this.removeFromFlagSets(split.name, split.sets);
|
|
68
68
|
// Update the segments count.
|
|
69
69
|
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
|
|
70
|
-
this.
|
|
70
|
+
this.splitsWithSegmentsCount--;
|
|
71
71
|
return true;
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
@@ -91,7 +91,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
91
91
|
return (0, lang_1.isFiniteNumber)(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
|
|
92
92
|
};
|
|
93
93
|
SplitsCacheInMemory.prototype.usesSegments = function () {
|
|
94
|
-
return this.getChangeNumber() === -1 || this.
|
|
94
|
+
return this.getChangeNumber() === -1 || this.splitsWithSegmentsCount > 0;
|
|
95
95
|
};
|
|
96
96
|
SplitsCacheInMemory.prototype.getNamesByFlagSets = function (flagSets) {
|
|
97
97
|
var _this = this;
|
|
@@ -23,10 +23,9 @@ function shouldRecordTelemetry(_a) {
|
|
|
23
23
|
}
|
|
24
24
|
exports.shouldRecordTelemetry = shouldRecordTelemetry;
|
|
25
25
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
26
|
-
function TelemetryCacheInMemory(splits, segments
|
|
26
|
+
function TelemetryCacheInMemory(splits, segments) {
|
|
27
27
|
this.splits = splits;
|
|
28
28
|
this.segments = segments;
|
|
29
|
-
this.largeSegments = largeSegments;
|
|
30
29
|
// isEmpty flag
|
|
31
30
|
this.e = true;
|
|
32
31
|
this.notReadyUsage = 0;
|
|
@@ -42,7 +41,10 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
42
41
|
this.tags = [];
|
|
43
42
|
this.exceptions = {};
|
|
44
43
|
this.latencies = {};
|
|
45
|
-
this.updatesFromSSE = {
|
|
44
|
+
this.updatesFromSSE = {
|
|
45
|
+
sp: 0,
|
|
46
|
+
ms: 0
|
|
47
|
+
};
|
|
46
48
|
}
|
|
47
49
|
TelemetryCacheInMemory.prototype.isEmpty = function () { return this.e; };
|
|
48
50
|
TelemetryCacheInMemory.prototype.clear = function () { };
|
|
@@ -62,8 +64,6 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
62
64
|
spC: this.splits && this.splits.getSplitNames().length,
|
|
63
65
|
seC: this.segments && this.segments.getRegisteredSegments().length,
|
|
64
66
|
skC: this.segments && this.segments.getKeysCount(),
|
|
65
|
-
lsC: this.largeSegments && this.largeSegments.getRegisteredSegments().length,
|
|
66
|
-
lskC: this.largeSegments && this.largeSegments.getKeysCount(),
|
|
67
67
|
sL: this.getSessionLength(),
|
|
68
68
|
eQ: this.getEventStats(constants_1.QUEUED),
|
|
69
69
|
eD: this.getEventStats(constants_1.DROPPED),
|
|
@@ -195,11 +195,14 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
195
195
|
};
|
|
196
196
|
TelemetryCacheInMemory.prototype.popUpdatesFromSSE = function () {
|
|
197
197
|
var result = this.updatesFromSSE;
|
|
198
|
-
this.updatesFromSSE = {
|
|
198
|
+
this.updatesFromSSE = {
|
|
199
|
+
sp: 0,
|
|
200
|
+
ms: 0,
|
|
201
|
+
};
|
|
199
202
|
return result;
|
|
200
203
|
};
|
|
201
204
|
TelemetryCacheInMemory.prototype.recordUpdatesFromSSE = function (type) {
|
|
202
|
-
this.updatesFromSSE[type]
|
|
205
|
+
this.updatesFromSSE[type]++;
|
|
203
206
|
this.e = false;
|
|
204
207
|
};
|
|
205
208
|
return TelemetryCacheInMemory;
|
|
@@ -20,7 +20,7 @@ var DEFAULT_OPTIONS = {
|
|
|
20
20
|
var DEFAULT_LIBRARY_OPTIONS = {
|
|
21
21
|
enableOfflineQueue: false,
|
|
22
22
|
connectTimeout: DEFAULT_OPTIONS.connectionTimeout,
|
|
23
|
-
lazyConnect: false
|
|
23
|
+
lazyConnect: false
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
26
|
* Redis adapter on top of the library of choice (written with ioredis) for some extra control.
|
|
@@ -37,10 +37,10 @@ var SegmentsCacheInRedis = /** @class */ (function () {
|
|
|
37
37
|
var _this = this;
|
|
38
38
|
return this.redis.get(this.keys.buildSegmentTillKey(name)).then(function (value) {
|
|
39
39
|
var i = parseInt(value, 10);
|
|
40
|
-
return (0, lang_1.isNaNNumber)(i) ?
|
|
40
|
+
return (0, lang_1.isNaNNumber)(i) ? undefined : i;
|
|
41
41
|
}).catch(function (e) {
|
|
42
42
|
_this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from segments storage. Error: ' + e);
|
|
43
|
-
return
|
|
43
|
+
return undefined;
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
46
|
SegmentsCacheInRedis.prototype.registerSegments = function (segments) {
|
|
@@ -12,17 +12,23 @@ 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 RD;
|
|
16
|
+
try {
|
|
17
|
+
// Using `require` to prevent error when bundling or importing the SDK in a .mjs file, since ioredis is a CommonJS module.
|
|
18
|
+
// Redis storage is not supported with .mjs files.
|
|
19
|
+
RD = require('./RedisAdapter').RedisAdapter;
|
|
20
|
+
}
|
|
21
|
+
catch (error) { /* empty */ }
|
|
15
22
|
/**
|
|
16
|
-
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
23
|
+
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.js
|
|
17
24
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
18
25
|
*/
|
|
19
26
|
function InRedisStorage(options) {
|
|
20
27
|
if (options === void 0) { options = {}; }
|
|
21
|
-
// Lazy loading to prevent error when bundling or importing the SDK in a .mjs file, since ioredis is a CommonJS module.
|
|
22
|
-
// Redis storage is not supported with .mjs files.
|
|
23
|
-
var RD = require('./RedisAdapter').RedisAdapter;
|
|
24
28
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
25
29
|
function InRedisStorageFactory(params) {
|
|
30
|
+
if (!RD)
|
|
31
|
+
throw new Error('The SDK Redis storage is unavailable. Make sure your runtime environment supports CommonJS (`require`) so the `ioredis` dependency can be imported.');
|
|
26
32
|
var onReadyCb = params.onReadyCb, settings = params.settings, _a = params.settings, log = _a.log, impressionsMode = _a.sync.impressionsMode;
|
|
27
33
|
var metadata = (0, utils_1.metadataBuilder)(settings);
|
|
28
34
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
@@ -30,7 +36,7 @@ function InRedisStorage(options) {
|
|
|
30
36
|
var telemetry = new TelemetryCacheInRedis_1.TelemetryCacheInRedis(log, keys, redisClient);
|
|
31
37
|
var impressionCountsCache = impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
|
|
32
38
|
var uniqueKeysCache = impressionsMode === constants_1.NONE ? new UniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;
|
|
33
|
-
//
|
|
39
|
+
// Subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
34
40
|
redisClient.on('connect', function () {
|
|
35
41
|
onReadyCb();
|
|
36
42
|
if (impressionCountsCache)
|
|
@@ -66,10 +66,10 @@ var SegmentsCachePluggable = /** @class */ (function () {
|
|
|
66
66
|
var _this = this;
|
|
67
67
|
return this.wrapper.get(this.keys.buildSegmentTillKey(name)).then(function (value) {
|
|
68
68
|
var i = parseInt(value, 10);
|
|
69
|
-
return (0, lang_1.isNaNNumber)(i) ?
|
|
69
|
+
return (0, lang_1.isNaNNumber)(i) ? undefined : i;
|
|
70
70
|
}).catch(function (e) {
|
|
71
71
|
_this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from segments storage. Error: ' + e);
|
|
72
|
-
return
|
|
72
|
+
return undefined;
|
|
73
73
|
});
|
|
74
74
|
};
|
|
75
75
|
/**
|
|
@@ -8,7 +8,7 @@ var sets_1 = require("../../utils/lang/sets");
|
|
|
8
8
|
* The `_cache` property is the object were items are stored.
|
|
9
9
|
* Intended for testing purposes.
|
|
10
10
|
*
|
|
11
|
-
* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves
|
|
11
|
+
* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves inmediatelly.
|
|
12
12
|
*/
|
|
13
13
|
function inMemoryWrapperFactory(connDelay) {
|
|
14
14
|
var _cache = {};
|
|
@@ -58,7 +58,6 @@ function PluggableStorage(options) {
|
|
|
58
58
|
var metadata = (0, utils_1.metadataBuilder)(settings);
|
|
59
59
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
60
60
|
var wrapper = (0, wrapperAdapter_1.wrapperAdapter)(log, options.wrapper);
|
|
61
|
-
var connectPromise;
|
|
62
61
|
var isSyncronizer = mode === undefined; // If mode is not defined, the synchronizer is running
|
|
63
62
|
var isPartialConsumer = mode === constants_1.CONSUMER_PARTIAL_MODE;
|
|
64
63
|
var telemetry = (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) || isSyncronizer ?
|
|
@@ -76,6 +75,37 @@ function PluggableStorage(options) {
|
|
|
76
75
|
settings.core.key === undefined ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() :
|
|
77
76
|
new UniqueKeysCachePluggable_1.UniqueKeysCachePluggable(log, keys.buildUniqueKeysKey(), wrapper) :
|
|
78
77
|
undefined;
|
|
78
|
+
// Connects to wrapper and emits SDK_READY event on main client
|
|
79
|
+
var connectPromise = wrapper.connect().then(function () {
|
|
80
|
+
if (isSyncronizer) {
|
|
81
|
+
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
82
|
+
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
83
|
+
var currentHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
84
|
+
if (hash !== currentHash) {
|
|
85
|
+
log.info(constants_2.LOG_PREFIX + 'Storage HASH has changed (SDK key, flags filter criteria or flags spec version was modified). Clearing cache');
|
|
86
|
+
return wrapper.getKeysByPrefix(keys.prefix + ".").then(function (storageKeys) {
|
|
87
|
+
return Promise.all(storageKeys.map(function (storageKey) { return wrapper.del(storageKey); }));
|
|
88
|
+
}).then(function () { return wrapper.set(keys.buildHashKey(), currentHash); });
|
|
89
|
+
}
|
|
90
|
+
}).then(function () {
|
|
91
|
+
onReadyCb();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
96
|
+
if (impressionCountsCache && impressionCountsCache.start)
|
|
97
|
+
impressionCountsCache.start();
|
|
98
|
+
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
99
|
+
uniqueKeysCache.start();
|
|
100
|
+
if (telemetry && telemetry.recordConfig)
|
|
101
|
+
telemetry.recordConfig();
|
|
102
|
+
onReadyCb();
|
|
103
|
+
}
|
|
104
|
+
}).catch(function (e) {
|
|
105
|
+
e = e || new Error('Error connecting wrapper');
|
|
106
|
+
onReadyCb(e);
|
|
107
|
+
return e; // Propagate error for shared clients
|
|
108
|
+
});
|
|
79
109
|
return {
|
|
80
110
|
splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
81
111
|
segments: new SegmentsCachePluggable_1.SegmentsCachePluggable(log, keys, wrapper),
|
|
@@ -84,41 +114,6 @@ function PluggableStorage(options) {
|
|
|
84
114
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable_1.EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
85
115
|
telemetry: telemetry,
|
|
86
116
|
uniqueKeys: uniqueKeysCache,
|
|
87
|
-
init: function () {
|
|
88
|
-
if (connectPromise)
|
|
89
|
-
return connectPromise;
|
|
90
|
-
// Connects to wrapper and emits SDK_READY event on main client
|
|
91
|
-
return connectPromise = wrapper.connect().then(function () {
|
|
92
|
-
if (isSyncronizer) {
|
|
93
|
-
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
94
|
-
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
95
|
-
var currentHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
96
|
-
if (hash !== currentHash) {
|
|
97
|
-
log.info(constants_2.LOG_PREFIX + 'Storage HASH has changed (SDK key, flags filter criteria or flags spec version was modified). Clearing cache');
|
|
98
|
-
return wrapper.getKeysByPrefix(keys.prefix + ".").then(function (storageKeys) {
|
|
99
|
-
return Promise.all(storageKeys.map(function (storageKey) { return wrapper.del(storageKey); }));
|
|
100
|
-
}).then(function () { return wrapper.set(keys.buildHashKey(), currentHash); });
|
|
101
|
-
}
|
|
102
|
-
}).then(function () {
|
|
103
|
-
onReadyCb();
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
108
|
-
if (impressionCountsCache && impressionCountsCache.start)
|
|
109
|
-
impressionCountsCache.start();
|
|
110
|
-
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
111
|
-
uniqueKeysCache.start();
|
|
112
|
-
if (telemetry && telemetry.recordConfig)
|
|
113
|
-
telemetry.recordConfig();
|
|
114
|
-
onReadyCb();
|
|
115
|
-
}
|
|
116
|
-
}).catch(function (e) {
|
|
117
|
-
e = e || new Error('Error connecting wrapper');
|
|
118
|
-
onReadyCb(e);
|
|
119
|
-
return e; // Propagate error for shared clients
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
117
|
// Stop periodic flush and disconnect the underlying storage
|
|
123
118
|
destroy: function () {
|
|
124
119
|
return Promise.all(isSyncronizer ? [] : [
|
|
@@ -128,7 +123,7 @@ function PluggableStorage(options) {
|
|
|
128
123
|
},
|
|
129
124
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
130
125
|
shared: function (_, onReadyCb) {
|
|
131
|
-
|
|
126
|
+
connectPromise.then(onReadyCb);
|
|
132
127
|
return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, this), {
|
|
133
128
|
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
134
129
|
destroy: function () { } });
|
|
@@ -46,8 +46,13 @@ function fromObjectUpdaterFactory(splitsParser, storage, readiness, settings) {
|
|
|
46
46
|
readiness.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
|
|
47
47
|
if (startingUp) {
|
|
48
48
|
startingUp = false;
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
Promise.resolve(splitsCache.checkCache()).then(function (cacheReady) {
|
|
50
|
+
// Emits SDK_READY_FROM_CACHE
|
|
51
|
+
if (cacheReady)
|
|
52
|
+
readiness.splits.emit(constants_2.SDK_SPLITS_CACHE_LOADED);
|
|
53
|
+
// Emits SDK_READY
|
|
54
|
+
readiness.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
55
|
+
});
|
|
51
56
|
}
|
|
52
57
|
return true;
|
|
53
58
|
});
|
|
@@ -5,14 +5,17 @@ exports.mySegmentsFetcherFactory = void 0;
|
|
|
5
5
|
* Factory of MySegments fetcher.
|
|
6
6
|
* MySegments fetcher is a wrapper around `mySegments` API service that parses the response and handle errors.
|
|
7
7
|
*/
|
|
8
|
-
function mySegmentsFetcherFactory(
|
|
9
|
-
return function mySegmentsFetcher(userMatchingKey, noCache,
|
|
10
|
-
// Optional decorator for `
|
|
8
|
+
function mySegmentsFetcherFactory(fetchMySegments) {
|
|
9
|
+
return function mySegmentsFetcher(userMatchingKey, noCache,
|
|
10
|
+
// Optional decorator for `fetchMySegments` promise, such as timeout or time tracker
|
|
11
11
|
decorator) {
|
|
12
|
-
var mySegmentsPromise =
|
|
12
|
+
var mySegmentsPromise = fetchMySegments(userMatchingKey, noCache);
|
|
13
13
|
if (decorator)
|
|
14
14
|
mySegmentsPromise = decorator(mySegmentsPromise);
|
|
15
|
-
|
|
15
|
+
// Extract segment names
|
|
16
|
+
return mySegmentsPromise
|
|
17
|
+
.then(function (resp) { return resp.json(); })
|
|
18
|
+
.then(function (json) { return json.mySegments.map(function (segment) { return segment.name; }); });
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
exports.mySegmentsFetcherFactory = mySegmentsFetcherFactory;
|
|
@@ -23,7 +23,7 @@ function greedyFetch(fetchSegmentChanges, since, segmentName, noCache, targetTil
|
|
|
23
23
|
*/
|
|
24
24
|
function segmentChangesFetcherFactory(fetchSegmentChanges) {
|
|
25
25
|
return function segmentChangesFetcher(since, segmentName, noCache, till,
|
|
26
|
-
// Optional decorator for `
|
|
26
|
+
// Optional decorator for `fetchMySegments` promise, such as timeout or time tracker
|
|
27
27
|
decorator) {
|
|
28
28
|
var segmentsPromise = greedyFetch(fetchSegmentChanges, since, segmentName, noCache, till);
|
|
29
29
|
if (decorator)
|
|
@@ -46,7 +46,7 @@ function pollingManagerCSFactory(params) {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
function add(matchingKey, readiness, storage) {
|
|
49
|
-
var mySegmentsSyncTask = (0, mySegmentsSyncTask_1.mySegmentsSyncTaskFactory)(splitApi.
|
|
49
|
+
var mySegmentsSyncTask = (0, mySegmentsSyncTask_1.mySegmentsSyncTaskFactory)(splitApi.fetchMySegments, storage, readiness, settings, matchingKey);
|
|
50
50
|
// smart ready
|
|
51
51
|
function smartReady() {
|
|
52
52
|
if (!readiness.isReady() && !storage.splits.usesSegments())
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.pollingManagerSSFactory = void 0;
|
|
4
4
|
var splitsSyncTask_1 = require("./syncTasks/splitsSyncTask");
|
|
5
5
|
var segmentsSyncTask_1 = require("./syncTasks/segmentsSyncTask");
|
|
6
|
-
var thenable_1 = require("../../utils/promise/thenable");
|
|
7
6
|
var constants_1 = require("../../logger/constants");
|
|
8
7
|
/**
|
|
9
8
|
* Expose start / stop mechanism for pulling data from services.
|
|
@@ -22,9 +21,10 @@ function pollingManagerSSFactory(params) {
|
|
|
22
21
|
log.debug(constants_1.LOG_PREFIX_SYNC_POLLING + ("Splits will be refreshed each " + settings.scheduler.featuresRefreshRate + " millis"));
|
|
23
22
|
log.debug(constants_1.LOG_PREFIX_SYNC_POLLING + ("Segments will be refreshed each " + settings.scheduler.segmentsRefreshRate + " millis"));
|
|
24
23
|
var startingUp = splitsSyncTask.start();
|
|
25
|
-
if (
|
|
24
|
+
if (startingUp) {
|
|
26
25
|
startingUp.then(function () {
|
|
27
|
-
|
|
26
|
+
if (splitsSyncTask.isRunning())
|
|
27
|
+
segmentsSyncTask.start();
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
},
|
|
@@ -7,7 +7,7 @@ var mySegmentsUpdater_1 = require("../updaters/mySegmentsUpdater");
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates a sync task that periodically executes a `mySegmentsUpdater` task
|
|
9
9
|
*/
|
|
10
|
-
function mySegmentsSyncTaskFactory(
|
|
11
|
-
return (0, syncTask_1.syncTaskFactory)(settings.log, (0, mySegmentsUpdater_1.mySegmentsUpdaterFactory)(settings.log, (0, mySegmentsFetcher_1.mySegmentsFetcherFactory)(
|
|
10
|
+
function mySegmentsSyncTaskFactory(fetchMySegments, storage, readiness, settings, matchingKey) {
|
|
11
|
+
return (0, syncTask_1.syncTaskFactory)(settings.log, (0, mySegmentsUpdater_1.mySegmentsUpdaterFactory)(settings.log, (0, mySegmentsFetcher_1.mySegmentsFetcherFactory)(fetchMySegments), storage.splits, storage.segments, readiness.segments, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, matchingKey), settings.scheduler.segmentsRefreshRate, 'mySegmentsUpdater');
|
|
12
12
|
}
|
|
13
13
|
exports.mySegmentsSyncTaskFactory = mySegmentsSyncTaskFactory;
|