@splitsoftware/splitio-commons 2.1.0-rc.1 → 2.1.0-rc.2
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 +5 -1
- package/LICENSE +1 -1
- package/cjs/evaluator/index.js +2 -0
- package/cjs/listeners/browser.js +4 -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/inLocalStorage/index.js +4 -3
- package/cjs/storages/inMemory/InMemoryStorage.js +5 -7
- package/cjs/storages/inMemory/InMemoryStorageCS.js +6 -7
- package/cjs/storages/inRedis/index.js +9 -13
- package/cjs/storages/pluggable/index.js +15 -19
- package/cjs/sync/submitters/impressionCountsSubmitter.js +2 -4
- package/cjs/sync/submitters/submitterManager.js +3 -6
- 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/esm/evaluator/index.js +2 -0
- package/esm/listeners/browser.js +1 -3
- 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/inLocalStorage/index.js +5 -4
- package/esm/storages/inMemory/InMemoryStorage.js +6 -8
- package/esm/storages/inMemory/InMemoryStorageCS.js +7 -8
- package/esm/storages/inRedis/index.js +10 -14
- package/esm/storages/pluggable/index.js +16 -20
- package/esm/sync/submitters/impressionCountsSubmitter.js +2 -4
- package/esm/sync/submitters/submitterManager.js +3 -6
- 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/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/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/inLocalStorage/index.ts +5 -4
- package/src/storages/inMemory/InMemoryStorage.ts +6 -6
- package/src/storages/inMemory/InMemoryStorageCS.ts +7 -6
- package/src/storages/inRedis/index.ts +10 -10
- package/src/storages/pluggable/index.ts +16 -20
- package/src/storages/types.ts +2 -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/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/types/splitio.d.ts +4 -0
package/CHANGES.txt
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
2.1.0 (January XX, 2025)
|
|
2
|
+
- Added `impressionsDisabled` property to SDK Manager's `SplitView` type.
|
|
2
3
|
- Added two new configuration options for the SDK storage in browsers when using storage type `LOCALSTORAGE`:
|
|
3
4
|
- `storage.expirationDays` to specify the validity period of the rollout cache.
|
|
4
5
|
- `storage.clearOnInit` to clear the rollout cache on SDK initialization.
|
|
5
|
-
- Updated
|
|
6
|
+
- Updated implementation of the impressions tracker and strategies to support feature flags with impressions tracking disabled.
|
|
7
|
+
- Updated SDK_READY_FROM_CACHE event when using the `LOCALSTORAGE` storage type to be emitted alongside the SDK_READY event if it has not already been emitted.
|
|
8
|
+
|
|
9
|
+
2.0.3 (January 9, 2025)
|
|
6
10
|
- Bugfixing - Properly handle rejected promises when using targeting rules with segment matchers in consumer modes (e.g., Redis and Pluggable storages).
|
|
7
11
|
|
|
8
12
|
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);
|
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) {
|
|
@@ -28,7 +28,7 @@ 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
34
|
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys);
|
|
@@ -39,10 +39,10 @@ function InLocalStorage(options) {
|
|
|
39
39
|
segments: segments,
|
|
40
40
|
largeSegments: largeSegments,
|
|
41
41
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
42
|
-
impressionCounts:
|
|
42
|
+
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
43
43
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
44
44
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
45
|
-
uniqueKeys:
|
|
45
|
+
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
46
46
|
validateCache: function () {
|
|
47
47
|
return (0, validateCache_1.validateCache)(options, settings, keys, splits, segments, largeSegments);
|
|
48
48
|
},
|
|
@@ -57,6 +57,7 @@ function InLocalStorage(options) {
|
|
|
57
57
|
impressionCounts: this.impressionCounts,
|
|
58
58
|
events: this.events,
|
|
59
59
|
telemetry: this.telemetry,
|
|
60
|
+
uniqueKeys: this.uniqueKeys,
|
|
60
61
|
destroy: function () { }
|
|
61
62
|
};
|
|
62
63
|
},
|
|
@@ -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
|
}
|
|
@@ -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,30 +54,26 @@ 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 (
|
|
76
|
+
if (isSynchronizer) {
|
|
81
77
|
// @TODO reuse InLocalStorage::validateCache logic
|
|
82
78
|
// In standalone or producer mode, clear storage if SDK key, flags filter criteria or flags spec version was modified
|
|
83
79
|
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
@@ -94,9 +90,9 @@ function PluggableStorage(options) {
|
|
|
94
90
|
}
|
|
95
91
|
else {
|
|
96
92
|
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
97
|
-
if (impressionCountsCache
|
|
93
|
+
if (impressionCountsCache.start)
|
|
98
94
|
impressionCountsCache.start();
|
|
99
|
-
if (uniqueKeysCache
|
|
95
|
+
if (uniqueKeysCache.start)
|
|
100
96
|
uniqueKeysCache.start();
|
|
101
97
|
if (telemetry && telemetry.recordConfig)
|
|
102
98
|
telemetry.recordConfig();
|
|
@@ -117,9 +113,9 @@ function PluggableStorage(options) {
|
|
|
117
113
|
uniqueKeys: uniqueKeysCache,
|
|
118
114
|
// Stop periodic flush and disconnect the underlying storage
|
|
119
115
|
destroy: function () {
|
|
120
|
-
return Promise.all(
|
|
121
|
-
impressionCountsCache
|
|
122
|
-
uniqueKeysCache
|
|
116
|
+
return Promise.all(isSynchronizer ? [] : [
|
|
117
|
+
impressionCountsCache.stop && impressionCountsCache.stop(),
|
|
118
|
+
uniqueKeysCache.stop && uniqueKeysCache.stop(),
|
|
123
119
|
]).then(function () { return wrapper.disconnect(); });
|
|
124
120
|
},
|
|
125
121
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
@@ -30,9 +30,7 @@ var IMPRESSIONS_COUNT_RATE = 1800000; // 30 minutes
|
|
|
30
30
|
*/
|
|
31
31
|
function impressionCountsSubmitterFactory(params) {
|
|
32
32
|
var log = params.settings.log, postTestImpressionsCount = params.splitApi.postTestImpressionsCount, impressionCounts = params.storage.impressionCounts;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return (0, submitter_1.submitterFactory)(log, postTestImpressionsCount, impressionCounts, IMPRESSIONS_COUNT_RATE, 'impression counts', fromImpressionCountsCollector, 1);
|
|
36
|
-
}
|
|
33
|
+
// retry impressions counts only once.
|
|
34
|
+
return (0, submitter_1.submitterFactory)(log, postTestImpressionsCount, impressionCounts, IMPRESSIONS_COUNT_RATE, 'impression counts', fromImpressionCountsCollector, 1);
|
|
37
35
|
}
|
|
38
36
|
exports.impressionCountsSubmitterFactory = impressionCountsSubmitterFactory;
|
|
@@ -9,14 +9,11 @@ var uniqueKeysSubmitter_1 = require("./uniqueKeysSubmitter");
|
|
|
9
9
|
function submitterManagerFactory(params) {
|
|
10
10
|
var submitters = [
|
|
11
11
|
(0, impressionsSubmitter_1.impressionsSubmitterFactory)(params),
|
|
12
|
-
(0, eventsSubmitter_1.eventsSubmitterFactory)(params)
|
|
12
|
+
(0, eventsSubmitter_1.eventsSubmitterFactory)(params),
|
|
13
|
+
(0, impressionCountsSubmitter_1.impressionCountsSubmitterFactory)(params),
|
|
14
|
+
(0, uniqueKeysSubmitter_1.uniqueKeysSubmitterFactory)(params)
|
|
13
15
|
];
|
|
14
|
-
var impressionCountsSubmitter = (0, impressionCountsSubmitter_1.impressionCountsSubmitterFactory)(params);
|
|
15
|
-
if (impressionCountsSubmitter)
|
|
16
|
-
submitters.push(impressionCountsSubmitter);
|
|
17
16
|
var telemetrySubmitter = (0, telemetrySubmitter_1.telemetrySubmitterFactory)(params);
|
|
18
|
-
if (params.storage.uniqueKeys)
|
|
19
|
-
submitters.push((0, uniqueKeysSubmitter_1.uniqueKeysSubmitterFactory)(params));
|
|
20
17
|
return {
|
|
21
18
|
// `onlyTelemetry` true if SDK is created with userConsent not GRANTED
|
|
22
19
|
start: function (onlyTelemetry) {
|
|
@@ -7,38 +7,37 @@ var constants_1 = require("../logger/constants");
|
|
|
7
7
|
var constants_2 = require("../utils/constants");
|
|
8
8
|
/**
|
|
9
9
|
* Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
|
|
10
|
-
*
|
|
11
|
-
* @param impressionsCache - cache to save impressions
|
|
12
|
-
* @param metadata - runtime metadata (ip, hostname and version)
|
|
13
|
-
* @param impressionListener - optional impression listener
|
|
14
|
-
* @param integrationsManager - optional integrations manager
|
|
15
|
-
* @param strategy - strategy for impressions tracking.
|
|
16
10
|
*/
|
|
17
|
-
function impressionsTrackerFactory(settings, impressionsCache, strategy, whenInit, integrationsManager, telemetryCache) {
|
|
11
|
+
function impressionsTrackerFactory(settings, impressionsCache, noneStrategy, strategy, whenInit, integrationsManager, telemetryCache) {
|
|
18
12
|
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
19
13
|
return {
|
|
20
14
|
track: function (impressions, attributes) {
|
|
21
15
|
if (settings.userConsent === constants_2.CONSENT_DECLINED)
|
|
22
16
|
return;
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
var impressionsToStore = impressions.filter(function (_a) {
|
|
18
|
+
var imp = _a.imp, disabled = _a.disabled;
|
|
19
|
+
return disabled ?
|
|
20
|
+
noneStrategy.process(imp) :
|
|
21
|
+
strategy.process(imp);
|
|
22
|
+
});
|
|
23
|
+
var impressionsLength = impressions.length;
|
|
24
|
+
var impressionsToStoreLength = impressionsToStore.length;
|
|
25
|
+
if (impressionsToStoreLength) {
|
|
26
|
+
var res = impressionsCache.track(impressionsToStore.map(function (item) { return item.imp; }));
|
|
28
27
|
// If we're on an async storage, handle error and log it.
|
|
29
28
|
if ((0, thenable_1.thenable)(res)) {
|
|
30
29
|
res.then(function () {
|
|
31
|
-
log.info(constants_1.IMPRESSIONS_TRACKER_SUCCESS, [
|
|
30
|
+
log.info(constants_1.IMPRESSIONS_TRACKER_SUCCESS, [impressionsLength]);
|
|
32
31
|
}).catch(function (err) {
|
|
33
|
-
log.error(constants_1.ERROR_IMPRESSIONS_TRACKER, [
|
|
32
|
+
log.error(constants_1.ERROR_IMPRESSIONS_TRACKER, [impressionsLength, err]);
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
35
|
else {
|
|
37
36
|
// Record when impressionsCache is sync only (standalone mode)
|
|
38
37
|
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
39
38
|
if (telemetryCache) {
|
|
40
|
-
telemetryCache.recordImpressionStats(constants_2.QUEUED,
|
|
41
|
-
telemetryCache.recordImpressionStats(constants_2.DEDUPED,
|
|
39
|
+
telemetryCache.recordImpressionStats(constants_2.QUEUED, impressionsToStoreLength);
|
|
40
|
+
telemetryCache.recordImpressionStats(constants_2.DEDUPED, impressionsLength - impressionsToStoreLength);
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
@@ -47,7 +46,7 @@ function impressionsTrackerFactory(settings, impressionsCache, strategy, whenIni
|
|
|
47
46
|
var _loop_1 = function (i) {
|
|
48
47
|
var impressionData = {
|
|
49
48
|
// copy of impression, to avoid unexpected behavior if modified by integrations or impressionListener
|
|
50
|
-
impression: (0, objectAssign_1.objectAssign)({},
|
|
49
|
+
impression: (0, objectAssign_1.objectAssign)({}, impressions[i].imp),
|
|
51
50
|
attributes: attributes,
|
|
52
51
|
ip: ip,
|
|
53
52
|
hostname: hostname,
|
|
@@ -69,7 +68,7 @@ function impressionsTrackerFactory(settings, impressionsCache, strategy, whenIni
|
|
|
69
68
|
});
|
|
70
69
|
});
|
|
71
70
|
};
|
|
72
|
-
for (var i = 0; i <
|
|
71
|
+
for (var i = 0; i < impressionsLength; i++) {
|
|
73
72
|
_loop_1(i);
|
|
74
73
|
}
|
|
75
74
|
}
|
|
@@ -5,20 +5,13 @@ exports.strategyDebugFactory = void 0;
|
|
|
5
5
|
* Debug strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
|
|
6
6
|
*
|
|
7
7
|
* @param impressionsObserver - impression observer. Previous time (pt property) is included in impression instances
|
|
8
|
-
* @returns
|
|
8
|
+
* @returns Debug strategy
|
|
9
9
|
*/
|
|
10
10
|
function strategyDebugFactory(impressionsObserver) {
|
|
11
11
|
return {
|
|
12
|
-
process: function (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
impression.pt = impressionsObserver.testAndSet(impression);
|
|
16
|
-
});
|
|
17
|
-
return {
|
|
18
|
-
impressionsToStore: impressions,
|
|
19
|
-
impressionsToListener: impressions,
|
|
20
|
-
deduped: 0
|
|
21
|
-
};
|
|
12
|
+
process: function (impression) {
|
|
13
|
+
impression.pt = impressionsObserver.testAndSet(impression);
|
|
14
|
+
return true;
|
|
22
15
|
}
|
|
23
16
|
};
|
|
24
17
|
}
|
|
@@ -4,25 +4,20 @@ exports.strategyNoneFactory = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* None strategy for impressions tracker.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param impressionCounts - cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
|
|
8
8
|
* @param uniqueKeysTracker - unique keys tracker in charge of tracking the unique keys per split.
|
|
9
|
-
* @returns
|
|
9
|
+
* @returns None strategy
|
|
10
10
|
*/
|
|
11
|
-
function strategyNoneFactory(
|
|
11
|
+
function strategyNoneFactory(impressionCounts, uniqueKeysTracker) {
|
|
12
12
|
return {
|
|
13
|
-
process: function (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
impressionsToStore: [],
|
|
23
|
-
impressionsToListener: impressions,
|
|
24
|
-
deduped: 0
|
|
25
|
-
};
|
|
13
|
+
process: function (impression) {
|
|
14
|
+
var now = Date.now();
|
|
15
|
+
// Increments impression counter per featureName
|
|
16
|
+
impressionCounts.track(impression.feature, now, 1);
|
|
17
|
+
// Keep track by unique key
|
|
18
|
+
uniqueKeysTracker.track(impression.keyName, impression.feature);
|
|
19
|
+
// Do not store impressions
|
|
20
|
+
return false;
|
|
26
21
|
}
|
|
27
22
|
};
|
|
28
23
|
}
|