@splitsoftware/splitio-commons 2.0.2 → 2.0.3-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 +4 -0
- package/cjs/evaluator/index.js +2 -0
- package/cjs/listeners/browser.js +4 -6
- package/cjs/sdkClient/client.js +13 -13
- 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 +3 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -3
- 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 +13 -13
- 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 +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -4
- 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 +11 -11
- 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 +4 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +5 -4
- 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 +17 -18
- 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 +2 -8
- package/types/splitio.d.ts +4 -0
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
2.0.2 (December 3, 2024)
|
|
2
6
|
- 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.
|
|
3
7
|
- 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/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.track = splitJSON.trackImpressions;
|
|
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.track = splitJSON.trackImpressions;
|
|
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][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].label);
|
|
60
|
+
stopTelemetryTracker(queue[0] && queue[0][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].label);
|
|
86
|
+
stopTelemetryTracker(queue[0] && queue[0][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, track = evaluation.track;
|
|
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
|
+
}, track]);
|
|
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
|
|
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
|
+
trackImpressions: splitObject.trackImpressions !== false
|
|
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 expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
@@ -40,10 +40,10 @@ function InLocalStorage(options) {
|
|
|
40
40
|
segments: segments,
|
|
41
41
|
largeSegments: largeSegments,
|
|
42
42
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
43
|
-
impressionCounts:
|
|
43
|
+
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
44
44
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
45
45
|
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
46
|
-
uniqueKeys:
|
|
46
|
+
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
47
47
|
destroy: function () { },
|
|
48
48
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
|
|
49
49
|
shared: function (matchingKey) {
|
|
@@ -55,6 +55,7 @@ function InLocalStorage(options) {
|
|
|
55
55
|
impressionCounts: this.impressionCounts,
|
|
56
56
|
events: this.events,
|
|
57
57
|
telemetry: this.telemetry,
|
|
58
|
+
uniqueKeys: this.uniqueKeys,
|
|
58
59
|
destroy: function () { }
|
|
59
60
|
};
|
|
60
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
|
|
@@ -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
|
},
|
|
@@ -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
|
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
82
78
|
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
83
79
|
var currentHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
@@ -93,9 +89,9 @@ function PluggableStorage(options) {
|
|
|
93
89
|
}
|
|
94
90
|
else {
|
|
95
91
|
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
96
|
-
if (impressionCountsCache
|
|
92
|
+
if (impressionCountsCache.start)
|
|
97
93
|
impressionCountsCache.start();
|
|
98
|
-
if (uniqueKeysCache
|
|
94
|
+
if (uniqueKeysCache.start)
|
|
99
95
|
uniqueKeysCache.start();
|
|
100
96
|
if (telemetry && telemetry.recordConfig)
|
|
101
97
|
telemetry.recordConfig();
|
|
@@ -116,9 +112,9 @@ function PluggableStorage(options) {
|
|
|
116
112
|
uniqueKeys: uniqueKeysCache,
|
|
117
113
|
// Stop periodic flush and disconnect the underlying storage
|
|
118
114
|
destroy: function () {
|
|
119
|
-
return Promise.all(
|
|
120
|
-
impressionCountsCache
|
|
121
|
-
uniqueKeysCache
|
|
115
|
+
return Promise.all(isSynchronizer ? [] : [
|
|
116
|
+
impressionCountsCache.stop && impressionCountsCache.stop(),
|
|
117
|
+
uniqueKeysCache.stop && uniqueKeysCache.stop(),
|
|
122
118
|
]).then(function () { return wrapper.disconnect(); });
|
|
123
119
|
},
|
|
124
120
|
// 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 impression = _a[0], track = _a[1];
|
|
19
|
+
return track === false ?
|
|
20
|
+
noneStrategy.process(impression) :
|
|
21
|
+
strategy.process(impression);
|
|
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[0]; }));
|
|
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 behaviour if modified by integrations or impressionListener
|
|
50
|
-
impression: (0, objectAssign_1.objectAssign)({},
|
|
49
|
+
impression: (0, objectAssign_1.objectAssign)({}, impressions[i][0]),
|
|
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
|
}
|
|
@@ -6,29 +6,19 @@ var time_1 = require("../../utils/time");
|
|
|
6
6
|
* Optimized strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
|
|
7
7
|
*
|
|
8
8
|
* @param impressionsObserver - impression observer. previous time (pt property) is included in impression instances
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
9
|
+
* @param impressionCounts - cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
|
|
10
|
+
* @returns Optimized strategy
|
|
11
11
|
*/
|
|
12
|
-
function strategyOptimizedFactory(impressionsObserver,
|
|
12
|
+
function strategyOptimizedFactory(impressionsObserver, impressionCounts) {
|
|
13
13
|
return {
|
|
14
|
-
process: function (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Checks if the impression should be added in queue to be sent
|
|
23
|
-
if (!impression.pt || impression.pt < (0, time_1.truncateTimeFrame)(now)) {
|
|
24
|
-
impressionsToStore.push(impression);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
impressionsToStore: impressionsToStore,
|
|
29
|
-
impressionsToListener: impressions,
|
|
30
|
-
deduped: impressions.length - impressionsToStore.length
|
|
31
|
-
};
|
|
14
|
+
process: function (impression) {
|
|
15
|
+
impression.pt = impressionsObserver.testAndSet(impression);
|
|
16
|
+
var now = Date.now();
|
|
17
|
+
// Increments impression counter per featureName
|
|
18
|
+
if (impression.pt)
|
|
19
|
+
impressionCounts.track(impression.feature, now, 1);
|
|
20
|
+
// Checks if the impression should be added in queue to be sent
|
|
21
|
+
return (!impression.pt || impression.pt < (0, time_1.truncateTimeFrame)(now)) ? true : false;
|
|
32
22
|
}
|
|
33
23
|
};
|
|
34
24
|
}
|
package/esm/evaluator/index.js
CHANGED
|
@@ -98,12 +98,14 @@ function getEvaluation(log, splitJSON, key, attributes, storage) {
|
|
|
98
98
|
return evaluation.then(function (result) {
|
|
99
99
|
result.changeNumber = split_1.getChangeNumber();
|
|
100
100
|
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
101
|
+
result.track = splitJSON.trackImpressions;
|
|
101
102
|
return result;
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
105
|
else {
|
|
105
106
|
evaluation.changeNumber = split_1.getChangeNumber(); // Always sync and optional
|
|
106
107
|
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
108
|
+
evaluation.track = splitJSON.trackImpressions;
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
return evaluation;
|