@splitsoftware/splitio-commons 2.1.0-rc.1 → 2.1.0
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 +4 -5
- package/LICENSE +1 -1
- package/cjs/evaluator/index.js +2 -0
- package/cjs/listeners/browser.js +4 -6
- package/cjs/readiness/readinessManager.js +0 -6
- package/cjs/sdkClient/client.js +14 -11
- package/cjs/sdkClient/sdkClient.js +1 -1
- package/cjs/sdkFactory/index.js +9 -14
- package/cjs/sdkManager/index.js +2 -1
- package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
- package/cjs/storages/AbstractSplitsCacheSync.js +7 -0
- package/cjs/storages/KeyBuilderCS.js +0 -3
- package/cjs/storages/dataLoader.js +2 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +57 -1
- package/cjs/storages/inLocalStorage/index.js +7 -8
- package/cjs/storages/inMemory/InMemoryStorage.js +5 -7
- package/cjs/storages/inMemory/InMemoryStorageCS.js +6 -7
- package/cjs/storages/inRedis/constants.js +1 -1
- package/cjs/storages/inRedis/index.js +9 -13
- package/cjs/storages/pluggable/index.js +16 -21
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +10 -1
- package/cjs/sync/submitters/impressionCountsSubmitter.js +2 -4
- package/cjs/sync/submitters/submitterManager.js +3 -6
- package/cjs/sync/syncManagerOnline.js +3 -8
- package/cjs/trackers/impressionsTracker.js +17 -18
- package/cjs/trackers/strategy/strategyDebug.js +4 -11
- package/cjs/trackers/strategy/strategyNone.js +11 -16
- package/cjs/trackers/strategy/strategyOptimized.js +11 -21
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/constants/browser.js +5 -0
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/esm/evaluator/index.js +2 -0
- package/esm/listeners/browser.js +1 -3
- package/esm/readiness/readinessManager.js +0 -6
- package/esm/sdkClient/client.js +14 -11
- package/esm/sdkClient/sdkClient.js +1 -1
- package/esm/sdkFactory/index.js +10 -15
- package/esm/sdkManager/index.js +2 -1
- package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
- package/esm/storages/AbstractSplitsCacheSync.js +7 -0
- package/esm/storages/KeyBuilderCS.js +0 -3
- package/esm/storages/dataLoader.js +1 -2
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +57 -1
- package/esm/storages/inLocalStorage/index.js +8 -9
- package/esm/storages/inMemory/InMemoryStorage.js +6 -8
- package/esm/storages/inMemory/InMemoryStorageCS.js +7 -8
- package/esm/storages/inRedis/constants.js +1 -1
- package/esm/storages/inRedis/index.js +10 -14
- package/esm/storages/pluggable/index.js +17 -22
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +11 -2
- package/esm/sync/submitters/impressionCountsSubmitter.js +2 -4
- package/esm/sync/submitters/submitterManager.js +3 -6
- package/esm/sync/syncManagerOnline.js +3 -8
- package/esm/trackers/impressionsTracker.js +17 -18
- package/esm/trackers/strategy/strategyDebug.js +4 -11
- package/esm/trackers/strategy/strategyNone.js +11 -16
- package/esm/trackers/strategy/strategyOptimized.js +11 -21
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/constants/browser.js +2 -0
- package/esm/utils/settingsValidation/storage/storageCS.js +1 -1
- package/package.json +1 -1
- package/src/dtos/types.ts +2 -1
- package/src/evaluator/index.ts +2 -0
- package/src/evaluator/types.ts +1 -1
- package/src/listeners/browser.ts +1 -3
- package/src/readiness/readinessManager.ts +0 -5
- package/src/sdkClient/client.ts +19 -15
- package/src/sdkClient/sdkClient.ts +1 -1
- package/src/sdkFactory/index.ts +11 -16
- package/src/sdkFactory/types.ts +1 -1
- package/src/sdkManager/index.ts +2 -1
- package/src/storages/AbstractSplitsCacheAsync.ts +8 -0
- package/src/storages/AbstractSplitsCacheSync.ts +8 -0
- package/src/storages/KeyBuilderCS.ts +0 -4
- package/src/storages/dataLoader.ts +1 -3
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +66 -1
- package/src/storages/inLocalStorage/index.ts +13 -12
- package/src/storages/inMemory/InMemoryStorage.ts +6 -6
- package/src/storages/inMemory/InMemoryStorageCS.ts +7 -6
- package/src/storages/inRedis/constants.ts +1 -1
- package/src/storages/inRedis/index.ts +10 -10
- package/src/storages/pluggable/index.ts +17 -22
- package/src/storages/types.ts +6 -3
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +11 -2
- package/src/sync/submitters/impressionCountsSubmitter.ts +2 -4
- package/src/sync/submitters/submitterManager.ts +3 -4
- package/src/sync/submitters/uniqueKeysSubmitter.ts +2 -3
- package/src/sync/syncManagerOnline.ts +3 -9
- package/src/trackers/impressionsTracker.ts +18 -19
- package/src/trackers/strategy/strategyDebug.ts +4 -11
- package/src/trackers/strategy/strategyNone.ts +11 -17
- package/src/trackers/strategy/strategyOptimized.ts +10 -20
- package/src/trackers/types.ts +13 -8
- package/src/trackers/uniqueKeysTracker.ts +1 -1
- package/src/utils/constants/browser.ts +2 -0
- package/src/utils/lang/index.ts +1 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +1 -1
- package/types/splitio.d.ts +5 -25
- package/cjs/storages/inLocalStorage/validateCache.js +0 -79
- package/esm/storages/inLocalStorage/validateCache.js +0 -75
- package/src/storages/inLocalStorage/validateCache.ts +0 -91
package/CHANGES.txt
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
2.1.0 (January
|
|
2
|
-
- Added
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
- Updated SDK_READY_FROM_CACHE event when using `LOCALSTORAGE` storage type to be emitted alongside SDK_READY event in case it has not been emitted.
|
|
1
|
+
2.1.0 (January 17, 2025)
|
|
2
|
+
- Added support for the new impressions tracking toggle available on feature flags, both respecting the setting and including the new field being returned on `SplitView` type objects. Read more in our docs.
|
|
3
|
+
|
|
4
|
+
2.0.3 (January 9, 2025)
|
|
6
5
|
- Bugfixing - Properly handle rejected promises when using targeting rules with segment matchers in consumer modes (e.g., Redis and Pluggable storages).
|
|
7
6
|
|
|
8
7
|
2.0.2 (December 3, 2024)
|
package/LICENSE
CHANGED
package/cjs/evaluator/index.js
CHANGED
|
@@ -104,12 +104,14 @@ function getEvaluation(log, splitJSON, key, attributes, storage) {
|
|
|
104
104
|
return evaluation.then(function (result) {
|
|
105
105
|
result.changeNumber = split_1.getChangeNumber();
|
|
106
106
|
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
107
|
+
result.impressionsDisabled = splitJSON.impressionsDisabled;
|
|
107
108
|
return result;
|
|
108
109
|
});
|
|
109
110
|
}
|
|
110
111
|
else {
|
|
111
112
|
evaluation.changeNumber = split_1.getChangeNumber(); // Always sync and optional
|
|
112
113
|
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
114
|
+
evaluation.impressionsDisabled = splitJSON.impressionsDisabled;
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
return evaluation;
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BrowserSignalListener = void 0;
|
|
4
4
|
var impressionsSubmitter_1 = require("../sync/submitters/impressionsSubmitter");
|
|
5
5
|
var impressionCountsSubmitter_1 = require("../sync/submitters/impressionCountsSubmitter");
|
|
6
|
-
var constants_1 = require("../utils/constants");
|
|
7
6
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
8
|
-
var
|
|
7
|
+
var constants_1 = require("../logger/constants");
|
|
9
8
|
var consent_1 = require("../consent");
|
|
10
9
|
var VISIBILITYCHANGE_EVENT = 'visibilitychange';
|
|
11
10
|
var PAGEHIDE_EVENT = 'pagehide';
|
|
@@ -28,7 +27,7 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
28
27
|
* Called when SplitFactory is initialized, it adds event listeners to close streaming and flush impressions and events.
|
|
29
28
|
*/
|
|
30
29
|
BrowserSignalListener.prototype.start = function () {
|
|
31
|
-
this.settings.log.debug(
|
|
30
|
+
this.settings.log.debug(constants_1.CLEANUP_REGISTERING, [EVENT_NAME]);
|
|
32
31
|
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
33
32
|
// Flush data whenever the page is hidden or unloaded.
|
|
34
33
|
document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
@@ -44,7 +43,7 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
44
43
|
* Called when client is destroyed, it removes event listeners.
|
|
45
44
|
*/
|
|
46
45
|
BrowserSignalListener.prototype.stop = function () {
|
|
47
|
-
this.settings.log.debug(
|
|
46
|
+
this.settings.log.debug(constants_1.CLEANUP_DEREGISTERING, [EVENT_NAME]);
|
|
48
47
|
if (typeof document !== 'undefined' && document.removeEventListener) {
|
|
49
48
|
document.removeEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
50
49
|
}
|
|
@@ -63,10 +62,9 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
63
62
|
var _a = this.settings.urls, events = _a.events, telemetry = _a.telemetry;
|
|
64
63
|
// Flush impressions & events data if there is user consent
|
|
65
64
|
if ((0, consent_1.isConsentGranted)(this.settings)) {
|
|
66
|
-
var sim = this.settings.sync.impressionsMode;
|
|
67
65
|
var extraMetadata = {
|
|
68
66
|
// sim stands for Sync/Split Impressions Mode
|
|
69
|
-
sim:
|
|
67
|
+
sim: this.settings.sync.impressionsMode
|
|
70
68
|
};
|
|
71
69
|
this._flushData(events + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
72
70
|
this._flushData(events + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.readinessManagerFactory = void 0;
|
|
4
4
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
5
5
|
var constants_1 = require("./constants");
|
|
6
|
-
var constants_2 = require("../utils/constants");
|
|
7
6
|
function splitsEventEmitterFactory(EventEmitter) {
|
|
8
7
|
var splitsEventEmitter = (0, objectAssign_1.objectAssign)(new EventEmitter(), {
|
|
9
8
|
splitsArrived: false,
|
|
@@ -84,7 +83,6 @@ function readinessManagerFactory(EventEmitter, settings, splits, isShared) {
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
function checkIsReadyOrUpdate(diff) {
|
|
87
|
-
var _a;
|
|
88
86
|
if (isDestroyed)
|
|
89
87
|
return;
|
|
90
88
|
if (isReady) {
|
|
@@ -103,10 +101,6 @@ function readinessManagerFactory(EventEmitter, settings, splits, isShared) {
|
|
|
103
101
|
isReady = true;
|
|
104
102
|
try {
|
|
105
103
|
syncLastUpdate();
|
|
106
|
-
if (!isReadyFromCache && ((_a = settings.storage) === null || _a === void 0 ? void 0 : _a.type) === constants_2.STORAGE_LOCALSTORAGE) {
|
|
107
|
-
isReadyFromCache = true;
|
|
108
|
-
gate.emit(constants_1.SDK_READY_FROM_CACHE);
|
|
109
|
-
}
|
|
110
104
|
gate.emit(constants_1.SDK_READY);
|
|
111
105
|
}
|
|
112
106
|
catch (e) {
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -33,7 +33,7 @@ function clientFactory(params) {
|
|
|
33
33
|
var queue = [];
|
|
34
34
|
var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
35
35
|
impressionsTracker.track(queue, attributes);
|
|
36
|
-
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
36
|
+
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
37
37
|
return treatment;
|
|
38
38
|
};
|
|
39
39
|
var evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
@@ -57,7 +57,7 @@ function clientFactory(params) {
|
|
|
57
57
|
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
58
58
|
});
|
|
59
59
|
impressionsTracker.track(queue, attributes);
|
|
60
|
-
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
60
|
+
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
61
61
|
return treatments;
|
|
62
62
|
};
|
|
63
63
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
@@ -83,7 +83,7 @@ function clientFactory(params) {
|
|
|
83
83
|
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
84
84
|
});
|
|
85
85
|
impressionsTracker.track(queue, attributes);
|
|
86
|
-
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
86
|
+
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
87
87
|
return treatments;
|
|
88
88
|
};
|
|
89
89
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
@@ -106,18 +106,21 @@ function clientFactory(params) {
|
|
|
106
106
|
function processEvaluation(evaluation, featureFlagName, key, attributes, withConfig, invokingMethodName, queue) {
|
|
107
107
|
var matchingKey = (0, key_1.getMatching)(key);
|
|
108
108
|
var bucketingKey = (0, key_1.getBucketing)(key);
|
|
109
|
-
var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a;
|
|
109
|
+
var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a, impressionsDisabled = evaluation.impressionsDisabled;
|
|
110
110
|
log.info(constants_2.IMPRESSION, [featureFlagName, matchingKey, treatment, label]);
|
|
111
111
|
if ((0, splitExistence_1.validateSplitExistence)(log, readinessManager, featureFlagName, label, invokingMethodName)) {
|
|
112
112
|
log.info(constants_2.IMPRESSION_QUEUEING);
|
|
113
113
|
queue.push({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
imp: {
|
|
115
|
+
feature: featureFlagName,
|
|
116
|
+
keyName: matchingKey,
|
|
117
|
+
treatment: treatment,
|
|
118
|
+
time: Date.now(),
|
|
119
|
+
bucketingKey: bucketingKey,
|
|
120
|
+
label: label,
|
|
121
|
+
changeNumber: changeNumber,
|
|
122
|
+
},
|
|
123
|
+
disabled: impressionsDisabled
|
|
121
124
|
});
|
|
122
125
|
}
|
|
123
126
|
if (withConfig) {
|
|
@@ -50,7 +50,7 @@ function sdkClientFactory(params, isSharedClient) {
|
|
|
50
50
|
(0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
|
|
51
51
|
telemetryTracker.sessionLength();
|
|
52
52
|
signalListener && signalListener.stop();
|
|
53
|
-
uniqueKeysTracker
|
|
53
|
+
uniqueKeysTracker.stop();
|
|
54
54
|
}
|
|
55
55
|
// Stop background jobs
|
|
56
56
|
syncManager && syncManager.stop();
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -51,19 +51,14 @@ function sdkFactory(params) {
|
|
|
51
51
|
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
52
52
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
53
53
|
var observer = impressionsObserverFactory();
|
|
54
|
-
var uniqueKeysTracker =
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
break;
|
|
63
|
-
default:
|
|
64
|
-
strategy = (0, strategyDebug_1.strategyDebugFactory)(observer);
|
|
65
|
-
}
|
|
66
|
-
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, strategy, whenInit, integrationsManager, storage.telemetry);
|
|
54
|
+
var uniqueKeysTracker = (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory());
|
|
55
|
+
var noneStrategy = (0, strategyNone_1.strategyNoneFactory)(storage.impressionCounts, uniqueKeysTracker);
|
|
56
|
+
var strategy = impressionsMode === constants_3.OPTIMIZED ?
|
|
57
|
+
(0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts) :
|
|
58
|
+
impressionsMode === constants_3.DEBUG ?
|
|
59
|
+
(0, strategyDebug_1.strategyDebugFactory)(observer) :
|
|
60
|
+
noneStrategy;
|
|
61
|
+
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, noneStrategy, strategy, whenInit, integrationsManager, storage.telemetry);
|
|
67
62
|
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, whenInit, integrationsManager, storage.telemetry);
|
|
68
63
|
// splitApi is used by SyncManager and Browser signal listener
|
|
69
64
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
@@ -82,7 +77,7 @@ function sdkFactory(params) {
|
|
|
82
77
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
83
78
|
(0, apiKey_1.validateAndTrackApiKey)(log, settings.core.authorizationKey);
|
|
84
79
|
readiness.init();
|
|
85
|
-
uniqueKeysTracker
|
|
80
|
+
uniqueKeysTracker.start();
|
|
86
81
|
syncManager && syncManager.start();
|
|
87
82
|
signalListener && signalListener.start();
|
|
88
83
|
initCallbacks.forEach(function (cb) { return cb(); });
|
package/cjs/sdkManager/index.js
CHANGED
|
@@ -28,7 +28,8 @@ function objectToView(splitObject) {
|
|
|
28
28
|
treatments: collectTreatments(splitObject),
|
|
29
29
|
configs: splitObject.configurations || {},
|
|
30
30
|
sets: splitObject.sets || [],
|
|
31
|
-
defaultTreatment: splitObject.defaultTreatment
|
|
31
|
+
defaultTreatment: splitObject.defaultTreatment,
|
|
32
|
+
impressionsDisabled: splitObject.impressionsDisabled === true
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
function objectsToViews(splitObjects) {
|
|
@@ -14,6 +14,13 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
14
14
|
AbstractSplitsCacheAsync.prototype.usesSegments = function () {
|
|
15
15
|
return Promise.resolve(true);
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Check if the splits information is already stored in cache.
|
|
19
|
+
* Noop, just keeping the interface. This is used by client-side implementations only.
|
|
20
|
+
*/
|
|
21
|
+
AbstractSplitsCacheAsync.prototype.checkCache = function () {
|
|
22
|
+
return Promise.resolve(false);
|
|
23
|
+
};
|
|
17
24
|
/**
|
|
18
25
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
19
26
|
* Used for SPLIT_KILL push notifications.
|
|
@@ -30,6 +30,13 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
30
30
|
var _this = this;
|
|
31
31
|
return this.getSplitNames().map(function (key) { return _this.getSplit(key); });
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Check if the splits information is already stored in cache. This data can be preloaded.
|
|
35
|
+
* It is used as condition to emit SDK_SPLITS_CACHE_LOADED, and then SDK_READY_FROM_CACHE.
|
|
36
|
+
*/
|
|
37
|
+
AbstractSplitsCacheSync.prototype.checkCache = function () {
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
33
40
|
/**
|
|
34
41
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
35
42
|
* Used for SPLIT_KILL push notifications.
|
|
@@ -32,9 +32,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
32
32
|
KeyBuilderCS.prototype.buildTillKey = function () {
|
|
33
33
|
return this.prefix + "." + this.matchingKey + ".segments.till";
|
|
34
34
|
};
|
|
35
|
-
KeyBuilderCS.prototype.buildLastClear = function () {
|
|
36
|
-
return this.prefix + ".lastClear";
|
|
37
|
-
};
|
|
38
35
|
return KeyBuilderCS;
|
|
39
36
|
}(KeyBuilder_1.KeyBuilder));
|
|
40
37
|
exports.KeyBuilderCS = KeyBuilderCS;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dataLoaderFactory = void 0;
|
|
4
|
-
|
|
5
|
-
var DEFAULT_CACHE_EXPIRATION_IN_MILLIS = 864000000; // 10 days
|
|
4
|
+
var browser_1 = require("../utils/constants/browser");
|
|
6
5
|
/**
|
|
7
6
|
* Factory of client-side storage loader
|
|
8
7
|
*
|
|
@@ -26,7 +25,7 @@ function dataLoaderFactory(preloadedData) {
|
|
|
26
25
|
return;
|
|
27
26
|
var _a = preloadedData.lastUpdated, lastUpdated = _a === void 0 ? -1 : _a, _b = preloadedData.segmentsData, segmentsData = _b === void 0 ? {} : _b, _c = preloadedData.since, since = _c === void 0 ? -1 : _c, _d = preloadedData.splitsData, splitsData = _d === void 0 ? {} : _d;
|
|
28
27
|
var storedSince = storage.splits.getChangeNumber();
|
|
29
|
-
var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
28
|
+
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
30
29
|
// Do not load data if current localStorage data is more recent,
|
|
31
30
|
// or if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
32
31
|
if (storedSince > since || lastUpdated < expirationTimestamp)
|
|
@@ -5,17 +5,21 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var AbstractSplitsCacheSync_1 = require("../AbstractSplitsCacheSync");
|
|
6
6
|
var lang_1 = require("../../utils/lang");
|
|
7
7
|
var constants_1 = require("./constants");
|
|
8
|
+
var KeyBuilder_1 = require("../KeyBuilder");
|
|
8
9
|
var sets_1 = require("../../utils/lang/sets");
|
|
9
10
|
/**
|
|
10
11
|
* ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
|
|
11
12
|
*/
|
|
12
13
|
var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
13
14
|
(0, tslib_1.__extends)(SplitsCacheInLocal, _super);
|
|
14
|
-
function SplitsCacheInLocal(settings, keys) {
|
|
15
|
+
function SplitsCacheInLocal(settings, keys, expirationTimestamp) {
|
|
15
16
|
var _this = _super.call(this) || this;
|
|
16
17
|
_this.keys = keys;
|
|
17
18
|
_this.log = settings.log;
|
|
19
|
+
_this.storageHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
18
20
|
_this.flagSetsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
21
|
+
_this._checkExpiration(expirationTimestamp);
|
|
22
|
+
_this._checkFilterQuery();
|
|
19
23
|
return _this;
|
|
20
24
|
}
|
|
21
25
|
SplitsCacheInLocal.prototype._decrementCount = function (key) {
|
|
@@ -63,6 +67,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
63
67
|
* We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
|
|
64
68
|
*/
|
|
65
69
|
SplitsCacheInLocal.prototype.clear = function () {
|
|
70
|
+
this.log.info(constants_1.LOG_PREFIX + 'Flushing Splits data from localStorage');
|
|
66
71
|
// collect item keys
|
|
67
72
|
var len = localStorage.length;
|
|
68
73
|
var accum = [];
|
|
@@ -114,6 +119,18 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
114
119
|
return item && JSON.parse(item);
|
|
115
120
|
};
|
|
116
121
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
122
|
+
// when using a new split query, we must update it at the store
|
|
123
|
+
if (this.updateNewFilter) {
|
|
124
|
+
this.log.info(constants_1.LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
125
|
+
var storageHashKey = this.keys.buildHashKey();
|
|
126
|
+
try {
|
|
127
|
+
localStorage.setItem(storageHashKey, this.storageHash);
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
this.log.error(constants_1.LOG_PREFIX + e);
|
|
131
|
+
}
|
|
132
|
+
this.updateNewFilter = false;
|
|
133
|
+
}
|
|
117
134
|
try {
|
|
118
135
|
localStorage.setItem(this.keys.buildSplitsTillKey(), changeNumber + '');
|
|
119
136
|
// update "last updated" timestamp with current time
|
|
@@ -164,6 +181,45 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
164
181
|
return true;
|
|
165
182
|
}
|
|
166
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* Check if the splits information is already stored in browser LocalStorage.
|
|
186
|
+
* In this function we could add more code to check if the data is valid.
|
|
187
|
+
* @override
|
|
188
|
+
*/
|
|
189
|
+
SplitsCacheInLocal.prototype.checkCache = function () {
|
|
190
|
+
return this.getChangeNumber() > -1;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
194
|
+
*
|
|
195
|
+
* @param expirationTimestamp - if the value is not a number, data will not be cleaned
|
|
196
|
+
*/
|
|
197
|
+
SplitsCacheInLocal.prototype._checkExpiration = function (expirationTimestamp) {
|
|
198
|
+
var value = localStorage.getItem(this.keys.buildLastUpdatedKey());
|
|
199
|
+
if (value !== null) {
|
|
200
|
+
value = parseInt(value, 10);
|
|
201
|
+
if (!(0, lang_1.isNaNNumber)(value) && expirationTimestamp && value < expirationTimestamp)
|
|
202
|
+
this.clear();
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
// @TODO eventually remove `_checkFilterQuery`. Cache should be cleared at the storage level, reusing same logic than PluggableStorage
|
|
206
|
+
SplitsCacheInLocal.prototype._checkFilterQuery = function () {
|
|
207
|
+
var storageHashKey = this.keys.buildHashKey();
|
|
208
|
+
var storageHash = localStorage.getItem(storageHashKey);
|
|
209
|
+
if (storageHash !== this.storageHash) {
|
|
210
|
+
try {
|
|
211
|
+
// mark cache to update the new query filter on first successful splits fetch
|
|
212
|
+
this.updateNewFilter = true;
|
|
213
|
+
// if there is cache, clear it
|
|
214
|
+
if (this.checkCache())
|
|
215
|
+
this.clear();
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
this.log.error(constants_1.LOG_PREFIX + e);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// if the filter didn't change, nothing is done
|
|
222
|
+
};
|
|
167
223
|
SplitsCacheInLocal.prototype.getNamesByFlagSets = function (flagSets) {
|
|
168
224
|
var _this = this;
|
|
169
225
|
return flagSets.map(function (flagSet) {
|
|
@@ -9,13 +9,13 @@ var KeyBuilderCS_1 = require("../KeyBuilderCS");
|
|
|
9
9
|
var isLocalStorageAvailable_1 = require("../../utils/env/isLocalStorageAvailable");
|
|
10
10
|
var SplitsCacheInLocal_1 = require("./SplitsCacheInLocal");
|
|
11
11
|
var MySegmentsCacheInLocal_1 = require("./MySegmentsCacheInLocal");
|
|
12
|
+
var browser_1 = require("../../utils/constants/browser");
|
|
12
13
|
var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
|
|
13
14
|
var constants_1 = require("./constants");
|
|
14
15
|
var constants_2 = require("../../utils/constants");
|
|
15
16
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
16
17
|
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
17
18
|
var key_1 = require("../../utils/key");
|
|
18
|
-
var validateCache_1 = require("./validateCache");
|
|
19
19
|
/**
|
|
20
20
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
21
21
|
*/
|
|
@@ -28,10 +28,11 @@ function InLocalStorage(options) {
|
|
|
28
28
|
params.settings.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
|
|
29
29
|
return (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
|
|
30
30
|
}
|
|
31
|
-
var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize
|
|
31
|
+
var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize;
|
|
32
32
|
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
33
33
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
34
|
-
var
|
|
34
|
+
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
35
|
+
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
35
36
|
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
36
37
|
var largeSegments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey));
|
|
37
38
|
return {
|
|
@@ -39,13 +40,10 @@ function InLocalStorage(options) {
|
|
|
39
40
|
segments: segments,
|
|
40
41
|
largeSegments: largeSegments,
|
|
41
42
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
42
|
-
impressionCounts:
|
|
43
|
+
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
43
44
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
44
45
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
45
|
-
uniqueKeys:
|
|
46
|
-
validateCache: function () {
|
|
47
|
-
return (0, validateCache_1.validateCache)(options, settings, keys, splits, segments, largeSegments);
|
|
48
|
-
},
|
|
46
|
+
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
49
47
|
destroy: function () { },
|
|
50
48
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
|
|
51
49
|
shared: function (matchingKey) {
|
|
@@ -57,6 +55,7 @@ function InLocalStorage(options) {
|
|
|
57
55
|
impressionCounts: this.impressionCounts,
|
|
58
56
|
events: this.events,
|
|
59
57
|
telemetry: this.telemetry,
|
|
58
|
+
uniqueKeys: this.uniqueKeys,
|
|
60
59
|
destroy: function () { }
|
|
61
60
|
};
|
|
62
61
|
},
|
|
@@ -15,17 +15,17 @@ var UniqueKeysCacheInMemory_1 = require("./UniqueKeysCacheInMemory");
|
|
|
15
15
|
* @param params - parameters required by EventsCacheSync
|
|
16
16
|
*/
|
|
17
17
|
function InMemoryStorageFactory(params) {
|
|
18
|
-
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize,
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
19
19
|
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
20
20
|
var segments = new SegmentsCacheInMemory_1.SegmentsCacheInMemory();
|
|
21
21
|
var storage = {
|
|
22
22
|
splits: splits,
|
|
23
23
|
segments: segments,
|
|
24
24
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
25
|
-
impressionCounts:
|
|
25
|
+
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
26
26
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
27
27
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
28
|
-
uniqueKeys:
|
|
28
|
+
uniqueKeys: new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory(),
|
|
29
29
|
destroy: function () { }
|
|
30
30
|
};
|
|
31
31
|
// @TODO revisit storage logic in localhost mode
|
|
@@ -34,10 +34,8 @@ function InMemoryStorageFactory(params) {
|
|
|
34
34
|
var noopTrack = function () { return true; };
|
|
35
35
|
storage.impressions.track = noopTrack;
|
|
36
36
|
storage.events.track = noopTrack;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (storage.uniqueKeys)
|
|
40
|
-
storage.uniqueKeys.track = noopTrack;
|
|
37
|
+
storage.impressionCounts.track = noopTrack;
|
|
38
|
+
storage.uniqueKeys.track = noopTrack;
|
|
41
39
|
}
|
|
42
40
|
return storage;
|
|
43
41
|
}
|
|
@@ -15,7 +15,7 @@ var UniqueKeysCacheInMemoryCS_1 = require("./UniqueKeysCacheInMemoryCS");
|
|
|
15
15
|
* @param params - parameters required by EventsCacheSync
|
|
16
16
|
*/
|
|
17
17
|
function InMemoryStorageCSFactory(params) {
|
|
18
|
-
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize,
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
|
|
19
19
|
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
20
20
|
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
21
21
|
var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
@@ -24,10 +24,10 @@ function InMemoryStorageCSFactory(params) {
|
|
|
24
24
|
segments: segments,
|
|
25
25
|
largeSegments: largeSegments,
|
|
26
26
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
27
|
-
impressionCounts:
|
|
27
|
+
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
28
28
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
29
29
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
30
|
-
uniqueKeys:
|
|
30
|
+
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
31
31
|
destroy: function () { },
|
|
32
32
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key)
|
|
33
33
|
shared: function () {
|
|
@@ -39,6 +39,7 @@ function InMemoryStorageCSFactory(params) {
|
|
|
39
39
|
impressionCounts: this.impressionCounts,
|
|
40
40
|
events: this.events,
|
|
41
41
|
telemetry: this.telemetry,
|
|
42
|
+
uniqueKeys: this.uniqueKeys,
|
|
42
43
|
destroy: function () { }
|
|
43
44
|
};
|
|
44
45
|
},
|
|
@@ -49,10 +50,8 @@ function InMemoryStorageCSFactory(params) {
|
|
|
49
50
|
var noopTrack = function () { return true; };
|
|
50
51
|
storage.impressions.track = noopTrack;
|
|
51
52
|
storage.events.track = noopTrack;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (storage.uniqueKeys)
|
|
55
|
-
storage.uniqueKeys.track = noopTrack;
|
|
53
|
+
storage.impressionCounts.track = noopTrack;
|
|
54
|
+
storage.uniqueKeys.track = noopTrack;
|
|
56
55
|
}
|
|
57
56
|
return storage;
|
|
58
57
|
}
|
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TTL_REFRESH = exports.REFRESH_RATE = exports.DEFAULT_CACHE_SIZE = exports.LOG_PREFIX = void 0;
|
|
4
4
|
exports.LOG_PREFIX = 'storage:redis: ';
|
|
5
5
|
exports.DEFAULT_CACHE_SIZE = 30000;
|
|
6
|
-
exports.REFRESH_RATE = 300000; //
|
|
6
|
+
exports.REFRESH_RATE = 300000; // 300000 ms = start after 5 mins
|
|
7
7
|
exports.TTL_REFRESH = 3600; // 1hr
|
|
@@ -23,20 +23,18 @@ function InRedisStorage(options) {
|
|
|
23
23
|
var RD = require('./RedisAdapter').RedisAdapter;
|
|
24
24
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
25
25
|
function InRedisStorageFactory(params) {
|
|
26
|
-
var onReadyCb = params.onReadyCb, settings = params.settings,
|
|
26
|
+
var onReadyCb = params.onReadyCb, settings = params.settings, log = params.settings.log;
|
|
27
27
|
var metadata = (0, utils_1.metadataBuilder)(settings);
|
|
28
28
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
29
29
|
var redisClient = new RD(log, options.options || {});
|
|
30
30
|
var telemetry = new TelemetryCacheInRedis_1.TelemetryCacheInRedis(log, keys, redisClient);
|
|
31
|
-
var impressionCountsCache =
|
|
32
|
-
var uniqueKeysCache =
|
|
31
|
+
var impressionCountsCache = new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient);
|
|
32
|
+
var uniqueKeysCache = new UniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient);
|
|
33
33
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
34
34
|
redisClient.on('connect', function () {
|
|
35
35
|
onReadyCb();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (uniqueKeysCache)
|
|
39
|
-
uniqueKeysCache.start();
|
|
36
|
+
impressionCountsCache.start();
|
|
37
|
+
uniqueKeysCache.start();
|
|
40
38
|
// Synchronize config
|
|
41
39
|
telemetry.recordConfig();
|
|
42
40
|
});
|
|
@@ -51,12 +49,10 @@ function InRedisStorage(options) {
|
|
|
51
49
|
// When using REDIS we should:
|
|
52
50
|
// 1- Disconnect from the storage
|
|
53
51
|
destroy: function () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
promises.push(uniqueKeysCache.stop());
|
|
59
|
-
return Promise.all(promises).then(function () { redisClient.disconnect(); });
|
|
52
|
+
return Promise.all([
|
|
53
|
+
impressionCountsCache.stop(),
|
|
54
|
+
uniqueKeysCache.stop()
|
|
55
|
+
]).then(function () { redisClient.disconnect(); });
|
|
60
56
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
61
57
|
}
|
|
62
58
|
};
|
|
@@ -54,32 +54,27 @@ function PluggableStorage(options) {
|
|
|
54
54
|
validatePluggableStorageOptions(options);
|
|
55
55
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
56
56
|
function PluggableStorageFactory(params) {
|
|
57
|
-
var onReadyCb = params.onReadyCb, settings = params.settings, _a = params.settings, log = _a.log, mode = _a.mode,
|
|
57
|
+
var onReadyCb = params.onReadyCb, settings = params.settings, _a = params.settings, log = _a.log, mode = _a.mode, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize;
|
|
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
|
|
61
|
+
var isSynchronizer = mode === undefined; // If mode is not defined, the synchronizer is running
|
|
62
62
|
var isPartialConsumer = mode === constants_1.CONSUMER_PARTIAL_MODE;
|
|
63
|
-
var telemetry = (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ||
|
|
63
|
+
var telemetry = (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) || isSynchronizer ?
|
|
64
64
|
isPartialConsumer ?
|
|
65
65
|
new TelemetryCacheInMemory_1.TelemetryCacheInMemory() :
|
|
66
66
|
new TelemetryCachePluggable_1.TelemetryCachePluggable(log, keys, wrapper) :
|
|
67
67
|
undefined;
|
|
68
|
-
var impressionCountsCache =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
undefined
|
|
73
|
-
|
|
74
|
-
isPartialConsumer ?
|
|
75
|
-
settings.core.key === undefined ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() :
|
|
76
|
-
new UniqueKeysCachePluggable_1.UniqueKeysCachePluggable(log, keys.buildUniqueKeysKey(), wrapper) :
|
|
77
|
-
undefined;
|
|
68
|
+
var impressionCountsCache = isPartialConsumer ?
|
|
69
|
+
new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() :
|
|
70
|
+
new ImpressionCountsCachePluggable_1.ImpressionCountsCachePluggable(log, keys.buildImpressionsCountKey(), wrapper);
|
|
71
|
+
var uniqueKeysCache = isPartialConsumer ?
|
|
72
|
+
settings.core.key === undefined ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() :
|
|
73
|
+
new UniqueKeysCachePluggable_1.UniqueKeysCachePluggable(log, keys.buildUniqueKeysKey(), wrapper);
|
|
78
74
|
// Connects to wrapper and emits SDK_READY event on main client
|
|
79
75
|
var connectPromise = wrapper.connect().then(function () {
|
|
80
|
-
if (
|
|
81
|
-
//
|
|
82
|
-
// In standalone or producer mode, clear storage if SDK key, flags filter criteria or flags spec version was modified
|
|
76
|
+
if (isSynchronizer) {
|
|
77
|
+
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
83
78
|
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
84
79
|
var currentHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
85
80
|
if (hash !== currentHash) {
|
|
@@ -94,9 +89,9 @@ function PluggableStorage(options) {
|
|
|
94
89
|
}
|
|
95
90
|
else {
|
|
96
91
|
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
97
|
-
if (impressionCountsCache
|
|
92
|
+
if (impressionCountsCache.start)
|
|
98
93
|
impressionCountsCache.start();
|
|
99
|
-
if (uniqueKeysCache
|
|
94
|
+
if (uniqueKeysCache.start)
|
|
100
95
|
uniqueKeysCache.start();
|
|
101
96
|
if (telemetry && telemetry.recordConfig)
|
|
102
97
|
telemetry.recordConfig();
|
|
@@ -117,9 +112,9 @@ function PluggableStorage(options) {
|
|
|
117
112
|
uniqueKeys: uniqueKeysCache,
|
|
118
113
|
// Stop periodic flush and disconnect the underlying storage
|
|
119
114
|
destroy: function () {
|
|
120
|
-
return Promise.all(
|
|
121
|
-
impressionCountsCache
|
|
122
|
-
uniqueKeysCache
|
|
115
|
+
return Promise.all(isSynchronizer ? [] : [
|
|
116
|
+
impressionCountsCache.stop && impressionCountsCache.stop(),
|
|
117
|
+
uniqueKeysCache.stop && uniqueKeysCache.stop(),
|
|
123
118
|
]).then(function () { return wrapper.disconnect(); });
|
|
124
119
|
},
|
|
125
120
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|