@splitsoftware/splitio-commons 2.0.3-rc.0 → 2.1.0-rc.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 +0 -4
- package/README.md +2 -2
- package/cjs/evaluator/index.js +0 -2
- package/cjs/listeners/browser.js +6 -4
- package/cjs/listeners/node.js +2 -2
- package/cjs/sdkClient/client.js +13 -13
- package/cjs/sdkClient/sdkClient.js +1 -1
- package/cjs/sdkFactory/index.js +14 -9
- package/cjs/sdkManager/index.js +1 -2
- package/cjs/storages/AbstractSplitsCacheAsync.js +0 -7
- package/cjs/storages/AbstractSplitsCacheSync.js +0 -7
- package/cjs/storages/KeyBuilderCS.js +3 -0
- package/cjs/storages/dataLoader.js +3 -2
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +1 -57
- package/cjs/storages/inLocalStorage/index.js +8 -7
- package/cjs/storages/inLocalStorage/validateCache.js +80 -0
- package/cjs/storages/inMemory/InMemoryStorage.js +3 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -4
- package/cjs/storages/inRedis/index.js +13 -9
- package/cjs/storages/pluggable/index.js +21 -16
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +3 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -10
- package/cjs/sync/streaming/pushManager.js +8 -6
- package/cjs/sync/submitters/impressionCountsSubmitter.js +4 -2
- package/cjs/sync/submitters/submitterManager.js +6 -3
- package/cjs/sync/syncManagerOnline.js +10 -4
- package/cjs/trackers/eventTracker.js +1 -1
- package/cjs/trackers/impressionsTracker.js +19 -18
- package/cjs/trackers/strategy/strategyDebug.js +11 -4
- package/cjs/trackers/strategy/strategyNone.js +16 -11
- package/cjs/trackers/strategy/strategyOptimized.js +21 -11
- package/cjs/utils/settingsValidation/index.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/esm/evaluator/index.js +0 -2
- package/esm/listeners/browser.js +3 -1
- package/esm/listeners/node.js +2 -2
- package/esm/sdkClient/client.js +13 -13
- package/esm/sdkClient/sdkClient.js +1 -1
- package/esm/sdkFactory/index.js +15 -10
- package/esm/sdkManager/index.js +1 -2
- package/esm/storages/AbstractSplitsCacheAsync.js +0 -7
- package/esm/storages/AbstractSplitsCacheSync.js +0 -7
- package/esm/storages/KeyBuilderCS.js +3 -0
- package/esm/storages/dataLoader.js +2 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +1 -57
- package/esm/storages/inLocalStorage/index.js +9 -8
- package/esm/storages/inLocalStorage/validateCache.js +76 -0
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -5
- package/esm/storages/inRedis/index.js +14 -10
- package/esm/storages/pluggable/index.js +22 -17
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +3 -2
- package/esm/sync/polling/updaters/splitChangesUpdater.js +2 -11
- package/esm/sync/streaming/pushManager.js +8 -6
- package/esm/sync/submitters/impressionCountsSubmitter.js +4 -2
- package/esm/sync/submitters/submitterManager.js +6 -3
- package/esm/sync/syncManagerOnline.js +10 -4
- package/esm/trackers/eventTracker.js +1 -1
- package/esm/trackers/impressionsTracker.js +19 -18
- package/esm/trackers/strategy/strategyDebug.js +11 -4
- package/esm/trackers/strategy/strategyNone.js +16 -11
- package/esm/trackers/strategy/strategyOptimized.js +21 -11
- package/esm/utils/settingsValidation/index.js +1 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +1 -1
- package/package.json +1 -1
- package/src/dtos/types.ts +1 -2
- package/src/evaluator/index.ts +0 -2
- package/src/evaluator/types.ts +1 -1
- package/src/listeners/browser.ts +3 -1
- package/src/listeners/node.ts +2 -2
- package/src/sdkClient/client.ts +11 -11
- package/src/sdkClient/sdkClient.ts +1 -1
- package/src/sdkFactory/index.ts +16 -11
- package/src/sdkFactory/types.ts +1 -1
- package/src/sdkManager/index.ts +1 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +0 -8
- package/src/storages/AbstractSplitsCacheSync.ts +0 -8
- package/src/storages/KeyBuilderCS.ts +4 -0
- package/src/storages/dataLoader.ts +3 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +1 -66
- package/src/storages/inLocalStorage/index.ts +12 -13
- package/src/storages/inLocalStorage/validateCache.ts +92 -0
- package/src/storages/inMemory/InMemoryStorage.ts +4 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -5
- package/src/storages/inRedis/index.ts +10 -10
- package/src/storages/pluggable/index.ts +22 -17
- package/src/storages/types.ts +3 -6
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +6 -5
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -11
- package/src/sync/streaming/pushManager.ts +8 -6
- package/src/sync/submitters/impressionCountsSubmitter.ts +4 -2
- package/src/sync/submitters/submitterManager.ts +4 -3
- package/src/sync/submitters/uniqueKeysSubmitter.ts +3 -2
- package/src/sync/syncManagerOnline.ts +11 -5
- package/src/trackers/eventTracker.ts +1 -1
- package/src/trackers/impressionsTracker.ts +19 -18
- package/src/trackers/strategy/strategyDebug.ts +11 -4
- package/src/trackers/strategy/strategyNone.ts +17 -11
- package/src/trackers/strategy/strategyOptimized.ts +20 -10
- package/src/trackers/types.ts +8 -2
- package/src/utils/lang/index.ts +1 -1
- package/src/utils/settingsValidation/index.ts +1 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/splitio.d.ts +26 -6
- package/cjs/utils/constants/browser.js +0 -5
- package/esm/utils/constants/browser.js +0 -2
- package/src/utils/constants/browser.ts +0 -2
package/CHANGES.txt
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
2.1.0 (January XX, 2025)
|
|
2
|
-
- Added `trackImpressions` property to SDK Manager's `SplitView` type.
|
|
3
|
-
- Updated implementation of the impressions tracker and strategies to support feature flags with impressions tracking disabled.
|
|
4
|
-
|
|
5
1
|
2.0.2 (December 3, 2024)
|
|
6
2
|
- Updated the factory `init` and `destroy` methods to support re-initialization after destruction. This update ensures compatibility of the React SDK with React Strict Mode, where the factory's `init` and `destroy` effects are executed an extra time to validate proper resource cleanup.
|
|
7
3
|
- Bugfixing - Sanitize the `SplitSDKMachineName` header value to avoid exceptions on HTTP/S requests when it contains non ISO-8859-1 characters (Related to issue https://github.com/splitio/javascript-client/issues/847).
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ This library is compatible with JavaScript ES5 and above.
|
|
|
14
14
|
Please see [Contributors Guide](CONTRIBUTORS-GUIDE.md) to find all you need to submit a Pull Request (PR).
|
|
15
15
|
|
|
16
16
|
## License
|
|
17
|
-
Licensed under the Apache License, Version 2.0. See: [Apache License](
|
|
17
|
+
Licensed under the Apache License, Version 2.0. See: [Apache License](https://www.apache.org/licenses/).
|
|
18
18
|
|
|
19
19
|
## About Split
|
|
20
20
|
|
|
@@ -46,4 +46,4 @@ For a comprehensive list of open source projects visit our [Github page](https:/
|
|
|
46
46
|
|
|
47
47
|
**Learn more about Split:**
|
|
48
48
|
|
|
49
|
-
Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](
|
|
49
|
+
Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](https://help.split.io) for more detailed information.
|
package/cjs/evaluator/index.js
CHANGED
|
@@ -104,14 +104,12 @@ 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.track = splitJSON.trackImpressions;
|
|
108
107
|
return result;
|
|
109
108
|
});
|
|
110
109
|
}
|
|
111
110
|
else {
|
|
112
111
|
evaluation.changeNumber = split_1.getChangeNumber(); // Always sync and optional
|
|
113
112
|
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
114
|
-
evaluation.track = splitJSON.trackImpressions;
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
115
|
return evaluation;
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -3,8 +3,9 @@ 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");
|
|
6
7
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
7
|
-
var
|
|
8
|
+
var constants_2 = require("../logger/constants");
|
|
8
9
|
var consent_1 = require("../consent");
|
|
9
10
|
var VISIBILITYCHANGE_EVENT = 'visibilitychange';
|
|
10
11
|
var PAGEHIDE_EVENT = 'pagehide';
|
|
@@ -27,7 +28,7 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
27
28
|
* Called when SplitFactory is initialized, it adds event listeners to close streaming and flush impressions and events.
|
|
28
29
|
*/
|
|
29
30
|
BrowserSignalListener.prototype.start = function () {
|
|
30
|
-
this.settings.log.debug(
|
|
31
|
+
this.settings.log.debug(constants_2.CLEANUP_REGISTERING, [EVENT_NAME]);
|
|
31
32
|
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
32
33
|
// Flush data whenever the page is hidden or unloaded.
|
|
33
34
|
document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
@@ -43,7 +44,7 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
43
44
|
* Called when client is destroyed, it removes event listeners.
|
|
44
45
|
*/
|
|
45
46
|
BrowserSignalListener.prototype.stop = function () {
|
|
46
|
-
this.settings.log.debug(
|
|
47
|
+
this.settings.log.debug(constants_2.CLEANUP_DEREGISTERING, [EVENT_NAME]);
|
|
47
48
|
if (typeof document !== 'undefined' && document.removeEventListener) {
|
|
48
49
|
document.removeEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
49
50
|
}
|
|
@@ -62,9 +63,10 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
62
63
|
var _a = this.settings.urls, events = _a.events, telemetry = _a.telemetry;
|
|
63
64
|
// Flush impressions & events data if there is user consent
|
|
64
65
|
if ((0, consent_1.isConsentGranted)(this.settings)) {
|
|
66
|
+
var sim = this.settings.sync.impressionsMode;
|
|
65
67
|
var extraMetadata = {
|
|
66
68
|
// sim stands for Sync/Split Impressions Mode
|
|
67
|
-
sim:
|
|
69
|
+
sim: sim === constants_1.OPTIMIZED ? constants_1.OPTIMIZED : sim === constants_1.DEBUG ? constants_1.DEBUG : constants_1.NONE
|
|
68
70
|
};
|
|
69
71
|
this._flushData(events + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
70
72
|
this._flushData(events + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
package/cjs/listeners/node.js
CHANGED
|
@@ -43,7 +43,7 @@ var NodeSignalListener = /** @class */ (function () {
|
|
|
43
43
|
var wrapUp = function () {
|
|
44
44
|
// Cleaned up, remove handlers.
|
|
45
45
|
_this.stop();
|
|
46
|
-
// This handler prevented the default
|
|
46
|
+
// This handler prevented the default behavior, start again.
|
|
47
47
|
// eslint-disable-next-line no-undef
|
|
48
48
|
process.kill(process.pid, SIGTERM);
|
|
49
49
|
};
|
|
@@ -56,7 +56,7 @@ var NodeSignalListener = /** @class */ (function () {
|
|
|
56
56
|
this.settings.log.error(constants_1.LOG_PREFIX_CLEANUP + "Error with Split SDK graceful shutdown: " + err);
|
|
57
57
|
}
|
|
58
58
|
if ((0, thenable_1.thenable)(handlerResult)) {
|
|
59
|
-
// Always exit, even with errors. The promise is returned for UT
|
|
59
|
+
// Always exit, even with errors. The promise is returned for UT purposes.
|
|
60
60
|
return handlerResult.then(wrapUp).catch(wrapUp);
|
|
61
61
|
}
|
|
62
62
|
else {
|
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]
|
|
36
|
+
stopTelemetryTracker(queue[0] && queue[0].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]
|
|
60
|
+
stopTelemetryTracker(queue[0] && queue[0].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]
|
|
86
|
+
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
87
87
|
return treatments;
|
|
88
88
|
};
|
|
89
89
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
@@ -106,19 +106,19 @@ 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;
|
|
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
|
-
queue.push(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
queue.push({
|
|
114
|
+
feature: featureFlagName,
|
|
115
|
+
keyName: matchingKey,
|
|
116
|
+
treatment: treatment,
|
|
117
|
+
time: Date.now(),
|
|
118
|
+
bucketingKey: bucketingKey,
|
|
119
|
+
label: label,
|
|
120
|
+
changeNumber: changeNumber
|
|
121
|
+
});
|
|
122
122
|
}
|
|
123
123
|
if (withConfig) {
|
|
124
124
|
return {
|
|
@@ -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.stop();
|
|
53
|
+
uniqueKeysTracker && uniqueKeysTracker.stop();
|
|
54
54
|
}
|
|
55
55
|
// Stop background jobs
|
|
56
56
|
syncManager && syncManager.stop();
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -51,14 +51,19 @@ 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 = (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory());
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
var uniqueKeysTracker = impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
55
|
+
var strategy;
|
|
56
|
+
switch (impressionsMode) {
|
|
57
|
+
case constants_3.OPTIMIZED:
|
|
58
|
+
strategy = (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts);
|
|
59
|
+
break;
|
|
60
|
+
case constants_3.NONE:
|
|
61
|
+
strategy = (0, strategyNone_1.strategyNoneFactory)(storage.impressionCounts, uniqueKeysTracker);
|
|
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);
|
|
62
67
|
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, whenInit, integrationsManager, storage.telemetry);
|
|
63
68
|
// splitApi is used by SyncManager and Browser signal listener
|
|
64
69
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
@@ -77,7 +82,7 @@ function sdkFactory(params) {
|
|
|
77
82
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
78
83
|
(0, apiKey_1.validateAndTrackApiKey)(log, settings.core.authorizationKey);
|
|
79
84
|
readiness.init();
|
|
80
|
-
uniqueKeysTracker.start();
|
|
85
|
+
uniqueKeysTracker && uniqueKeysTracker.start();
|
|
81
86
|
syncManager && syncManager.start();
|
|
82
87
|
signalListener && signalListener.start();
|
|
83
88
|
initCallbacks.forEach(function (cb) { return cb(); });
|
package/cjs/sdkManager/index.js
CHANGED
|
@@ -28,8 +28,7 @@ function objectToView(splitObject) {
|
|
|
28
28
|
treatments: collectTreatments(splitObject),
|
|
29
29
|
configs: splitObject.configurations || {},
|
|
30
30
|
sets: splitObject.sets || [],
|
|
31
|
-
defaultTreatment: splitObject.defaultTreatment
|
|
32
|
-
trackImpressions: splitObject.trackImpressions !== false
|
|
31
|
+
defaultTreatment: splitObject.defaultTreatment
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
function objectsToViews(splitObjects) {
|
|
@@ -14,13 +14,6 @@ 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
|
-
};
|
|
24
17
|
/**
|
|
25
18
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
26
19
|
* Used for SPLIT_KILL push notifications.
|
|
@@ -30,13 +30,6 @@ 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
|
-
};
|
|
40
33
|
/**
|
|
41
34
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
42
35
|
* Used for SPLIT_KILL push notifications.
|
|
@@ -32,6 +32,9 @@ 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
|
+
};
|
|
35
38
|
return KeyBuilderCS;
|
|
36
39
|
}(KeyBuilder_1.KeyBuilder));
|
|
37
40
|
exports.KeyBuilderCS = KeyBuilderCS;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dataLoaderFactory = void 0;
|
|
4
|
-
|
|
4
|
+
// This value might be eventually set via a config parameter
|
|
5
|
+
var DEFAULT_CACHE_EXPIRATION_IN_MILLIS = 864000000; // 10 days
|
|
5
6
|
/**
|
|
6
7
|
* Factory of client-side storage loader
|
|
7
8
|
*
|
|
@@ -25,7 +26,7 @@ function dataLoaderFactory(preloadedData) {
|
|
|
25
26
|
return;
|
|
26
27
|
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;
|
|
27
28
|
var storedSince = storage.splits.getChangeNumber();
|
|
28
|
-
var expirationTimestamp = Date.now() -
|
|
29
|
+
var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
29
30
|
// Do not load data if current localStorage data is more recent,
|
|
30
31
|
// or if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
31
32
|
if (storedSince > since || lastUpdated < expirationTimestamp)
|
|
@@ -5,21 +5,17 @@ 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");
|
|
9
8
|
var sets_1 = require("../../utils/lang/sets");
|
|
10
9
|
/**
|
|
11
10
|
* ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
|
|
12
11
|
*/
|
|
13
12
|
var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
14
13
|
(0, tslib_1.__extends)(SplitsCacheInLocal, _super);
|
|
15
|
-
function SplitsCacheInLocal(settings, keys
|
|
14
|
+
function SplitsCacheInLocal(settings, keys) {
|
|
16
15
|
var _this = _super.call(this) || this;
|
|
17
16
|
_this.keys = keys;
|
|
18
17
|
_this.log = settings.log;
|
|
19
|
-
_this.storageHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
20
18
|
_this.flagSetsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
21
|
-
_this._checkExpiration(expirationTimestamp);
|
|
22
|
-
_this._checkFilterQuery();
|
|
23
19
|
return _this;
|
|
24
20
|
}
|
|
25
21
|
SplitsCacheInLocal.prototype._decrementCount = function (key) {
|
|
@@ -67,7 +63,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
67
63
|
* We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
|
|
68
64
|
*/
|
|
69
65
|
SplitsCacheInLocal.prototype.clear = function () {
|
|
70
|
-
this.log.info(constants_1.LOG_PREFIX + 'Flushing Splits data from localStorage');
|
|
71
66
|
// collect item keys
|
|
72
67
|
var len = localStorage.length;
|
|
73
68
|
var accum = [];
|
|
@@ -119,18 +114,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
119
114
|
return item && JSON.parse(item);
|
|
120
115
|
};
|
|
121
116
|
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
|
-
}
|
|
134
117
|
try {
|
|
135
118
|
localStorage.setItem(this.keys.buildSplitsTillKey(), changeNumber + '');
|
|
136
119
|
// update "last updated" timestamp with current time
|
|
@@ -181,45 +164,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
181
164
|
return true;
|
|
182
165
|
}
|
|
183
166
|
};
|
|
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
|
-
};
|
|
223
167
|
SplitsCacheInLocal.prototype.getNamesByFlagSets = function (flagSets) {
|
|
224
168
|
var _this = this;
|
|
225
169
|
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");
|
|
13
12
|
var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
|
|
14
13
|
var constants_1 = require("./constants");
|
|
15
14
|
var constants_2 = require("../../utils/constants");
|
|
16
15
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
17
16
|
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
18
17
|
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,11 +28,10 @@ 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, impressionsMode = _a.sync.impressionsMode;
|
|
32
32
|
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
33
33
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
34
|
-
var
|
|
35
|
-
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
34
|
+
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys);
|
|
36
35
|
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
37
36
|
var largeSegments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey));
|
|
38
37
|
return {
|
|
@@ -40,10 +39,13 @@ function InLocalStorage(options) {
|
|
|
40
39
|
segments: segments,
|
|
41
40
|
largeSegments: largeSegments,
|
|
42
41
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
43
|
-
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
42
|
+
impressionCounts: impressionsMode !== constants_2.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
44
43
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
45
44
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
46
|
-
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
45
|
+
uniqueKeys: impressionsMode === constants_2.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
46
|
+
validateCache: function () {
|
|
47
|
+
return (0, validateCache_1.validateCache)(options, settings, keys, splits, segments, largeSegments);
|
|
48
|
+
},
|
|
47
49
|
destroy: function () { },
|
|
48
50
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
|
|
49
51
|
shared: function (matchingKey) {
|
|
@@ -55,7 +57,6 @@ function InLocalStorage(options) {
|
|
|
55
57
|
impressionCounts: this.impressionCounts,
|
|
56
58
|
events: this.events,
|
|
57
59
|
telemetry: this.telemetry,
|
|
58
|
-
uniqueKeys: this.uniqueKeys,
|
|
59
60
|
destroy: function () { }
|
|
60
61
|
};
|
|
61
62
|
},
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCache = void 0;
|
|
4
|
+
var lang_1 = require("../../utils/lang");
|
|
5
|
+
var KeyBuilder_1 = require("../KeyBuilder");
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
// milliseconds in a day
|
|
8
|
+
var DEFAULT_CACHE_EXPIRATION_IN_DAYS = 10;
|
|
9
|
+
var MILLIS_IN_A_DAY = 86400000;
|
|
10
|
+
/**
|
|
11
|
+
* Validates if cache should be cleared and sets the cache `hash` if needed.
|
|
12
|
+
*
|
|
13
|
+
* @returns `true` if cache should be cleared, `false` otherwise
|
|
14
|
+
*/
|
|
15
|
+
function validateExpiration(options, settings, keys, currentTimestamp, isThereCache) {
|
|
16
|
+
var log = settings.log;
|
|
17
|
+
// Check expiration
|
|
18
|
+
var lastUpdatedTimestamp = parseInt(localStorage.getItem(keys.buildLastUpdatedKey()), 10);
|
|
19
|
+
if (!(0, lang_1.isNaNNumber)(lastUpdatedTimestamp)) {
|
|
20
|
+
var cacheExpirationInDays = (0, lang_1.isFiniteNumber)(options.expirationDays) && options.expirationDays >= 1 ? options.expirationDays : DEFAULT_CACHE_EXPIRATION_IN_DAYS;
|
|
21
|
+
var expirationTimestamp = currentTimestamp - MILLIS_IN_A_DAY * cacheExpirationInDays;
|
|
22
|
+
if (lastUpdatedTimestamp < expirationTimestamp) {
|
|
23
|
+
log.info(constants_1.LOG_PREFIX + 'Cache expired more than ' + cacheExpirationInDays + ' days ago. Cleaning up cache');
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Check hash
|
|
28
|
+
var storageHashKey = keys.buildHashKey();
|
|
29
|
+
var storageHash = localStorage.getItem(storageHashKey);
|
|
30
|
+
var currentStorageHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
31
|
+
if (storageHash !== currentStorageHash) {
|
|
32
|
+
try {
|
|
33
|
+
localStorage.setItem(storageHashKey, currentStorageHash);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
log.error(constants_1.LOG_PREFIX + e);
|
|
37
|
+
}
|
|
38
|
+
if (isThereCache) {
|
|
39
|
+
log.info(constants_1.LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version has changed. Cleaning up cache');
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false; // No cache to clear
|
|
43
|
+
}
|
|
44
|
+
// Clear on init
|
|
45
|
+
if (options.clearOnInit) {
|
|
46
|
+
var lastClearTimestamp = parseInt(localStorage.getItem(keys.buildLastClear()), 10);
|
|
47
|
+
if ((0, lang_1.isNaNNumber)(lastClearTimestamp) || lastClearTimestamp < currentTimestamp - MILLIS_IN_A_DAY) {
|
|
48
|
+
log.info(constants_1.LOG_PREFIX + 'clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache');
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Clean cache if:
|
|
55
|
+
* - it has expired, i.e., its `lastUpdated` timestamp is older than the given `expirationTimestamp`
|
|
56
|
+
* - its hash has changed, i.e., the SDK key, flags filter criteria or flags spec version was modified
|
|
57
|
+
* - `clearOnInit` was set and cache was not cleared in the last 24 hours
|
|
58
|
+
*
|
|
59
|
+
* @returns `true` if cache is ready to be used, `false` otherwise (cache was cleared or there is no cache)
|
|
60
|
+
*/
|
|
61
|
+
function validateCache(options, settings, keys, splits, segments, largeSegments) {
|
|
62
|
+
var currentTimestamp = Date.now();
|
|
63
|
+
var isThereCache = splits.getChangeNumber() > -1;
|
|
64
|
+
if (validateExpiration(options, settings, keys, currentTimestamp, isThereCache)) {
|
|
65
|
+
splits.clear();
|
|
66
|
+
segments.clear();
|
|
67
|
+
largeSegments.clear();
|
|
68
|
+
// Update last clear timestamp
|
|
69
|
+
try {
|
|
70
|
+
localStorage.setItem(keys.buildLastClear(), currentTimestamp + '');
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
settings.log.error(constants_1.LOG_PREFIX + e);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
// Check if ready from cache
|
|
78
|
+
return isThereCache;
|
|
79
|
+
}
|
|
80
|
+
exports.validateCache = validateCache;
|
|
@@ -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, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__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: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
25
|
+
impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
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: new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory(),
|
|
28
|
+
uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : undefined,
|
|
29
29
|
destroy: function () { }
|
|
30
30
|
};
|
|
31
31
|
// @TODO revisit storage logic in localhost mode
|
|
@@ -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, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__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: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
27
|
+
impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
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: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
30
|
+
uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
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,7 +39,6 @@ function InMemoryStorageCSFactory(params) {
|
|
|
39
39
|
impressionCounts: this.impressionCounts,
|
|
40
40
|
events: this.events,
|
|
41
41
|
telemetry: this.telemetry,
|
|
42
|
-
uniqueKeys: this.uniqueKeys,
|
|
43
42
|
destroy: function () { }
|
|
44
43
|
};
|
|
45
44
|
},
|
|
@@ -23,18 +23,20 @@ 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, _a = params.settings, log = _a.log, impressionsMode = _a.sync.impressionsMode;
|
|
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 = new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient);
|
|
32
|
-
var uniqueKeysCache = new UniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient);
|
|
31
|
+
var impressionCountsCache = impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
|
|
32
|
+
var uniqueKeysCache = impressionsMode === constants_1.NONE ? new UniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;
|
|
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
|
-
impressionCountsCache
|
|
37
|
-
|
|
36
|
+
if (impressionCountsCache)
|
|
37
|
+
impressionCountsCache.start();
|
|
38
|
+
if (uniqueKeysCache)
|
|
39
|
+
uniqueKeysCache.start();
|
|
38
40
|
// Synchronize config
|
|
39
41
|
telemetry.recordConfig();
|
|
40
42
|
});
|
|
@@ -49,10 +51,12 @@ function InRedisStorage(options) {
|
|
|
49
51
|
// When using REDIS we should:
|
|
50
52
|
// 1- Disconnect from the storage
|
|
51
53
|
destroy: function () {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
var promises = [];
|
|
55
|
+
if (impressionCountsCache)
|
|
56
|
+
promises.push(impressionCountsCache.stop());
|
|
57
|
+
if (uniqueKeysCache)
|
|
58
|
+
promises.push(uniqueKeysCache.stop());
|
|
59
|
+
return Promise.all(promises).then(function () { redisClient.disconnect(); });
|
|
56
60
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
57
61
|
}
|
|
58
62
|
};
|