@splitsoftware/splitio-commons 2.0.3-rc.0 → 2.0.3
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 +2 -3
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/cjs/evaluator/index.js +0 -2
- package/cjs/evaluator/matchers/large_segment.js +0 -6
- package/cjs/evaluator/matchers/segment.js +0 -6
- 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/inLocalStorage/index.js +3 -4
- package/cjs/storages/inMemory/InMemoryStorage.js +3 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -4
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/index.js +13 -9
- package/cjs/storages/pluggable/index.js +19 -15
- 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 +2 -1
- 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/esm/evaluator/index.js +0 -2
- package/esm/evaluator/matchers/large_segment.js +0 -6
- package/esm/evaluator/matchers/segment.js +0 -6
- 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/inLocalStorage/index.js +4 -5
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -5
- package/esm/storages/inRedis/SplitsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/index.js +14 -10
- package/esm/storages/pluggable/index.js +20 -16
- 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 +2 -1
- 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/package.json +1 -1
- package/src/dtos/types.ts +1 -2
- package/src/evaluator/index.ts +0 -2
- package/src/evaluator/matchers/large_segment.ts +0 -7
- package/src/evaluator/matchers/segment.ts +0 -7
- 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/inLocalStorage/index.ts +4 -5
- package/src/storages/inMemory/InMemoryStorage.ts +4 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -5
- package/src/storages/inRedis/SplitsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/index.ts +10 -10
- package/src/storages/pluggable/index.ts +20 -16
- package/src/storages/types.ts +2 -2
- 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 +2 -2
- 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/settingsValidation/index.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/splitio.d.ts +1 -5
package/CHANGES.txt
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
2.
|
|
2
|
-
-
|
|
3
|
-
- Updated implementation of the impressions tracker and strategies to support feature flags with impressions tracking disabled.
|
|
1
|
+
2.0.3 (January 9, 2025)
|
|
2
|
+
- Bugfixing - Properly handle rejected promises when using targeting rules with segment matchers in consumer modes (e.g., Redis and Pluggable storages).
|
|
4
3
|
|
|
5
4
|
2.0.2 (December 3, 2024)
|
|
6
5
|
- 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.
|
package/LICENSE
CHANGED
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;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.largeSegmentMatcherContext = void 0;
|
|
4
|
-
var thenable_1 = require("../../utils/promise/thenable");
|
|
5
4
|
function largeSegmentMatcherContext(largeSegmentName, storage) {
|
|
6
5
|
return function largeSegmentMatcher(key) {
|
|
7
6
|
var isInLargeSegment = storage.largeSegments ? storage.largeSegments.isInSegment(largeSegmentName, key) : false;
|
|
8
|
-
if ((0, thenable_1.thenable)(isInLargeSegment)) {
|
|
9
|
-
isInLargeSegment.then(function (result) {
|
|
10
|
-
return result;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
7
|
return isInLargeSegment;
|
|
14
8
|
};
|
|
15
9
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.segmentMatcherContext = void 0;
|
|
4
|
-
var thenable_1 = require("../../utils/promise/thenable");
|
|
5
4
|
function segmentMatcherContext(segmentName, storage) {
|
|
6
5
|
return function segmentMatcher(key) {
|
|
7
6
|
var isInSegment = storage.segments.isInSegment(segmentName, key);
|
|
8
|
-
if ((0, thenable_1.thenable)(isInSegment)) {
|
|
9
|
-
isInSegment.then(function (result) {
|
|
10
|
-
return result;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
7
|
return isInSegment;
|
|
14
8
|
};
|
|
15
9
|
}
|
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) {
|
|
@@ -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, 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
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: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
43
|
+
impressionCounts: impressionsMode !== constants_2.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
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: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
46
|
+
uniqueKeys: impressionsMode === constants_2.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
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,7 +55,6 @@ function InLocalStorage(options) {
|
|
|
55
55
|
impressionCounts: this.impressionCounts,
|
|
56
56
|
events: this.events,
|
|
57
57
|
telemetry: this.telemetry,
|
|
58
|
-
uniqueKeys: this.uniqueKeys,
|
|
59
58
|
destroy: function () { }
|
|
60
59
|
};
|
|
61
60
|
},
|
|
@@ -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
|
},
|
|
@@ -241,9 +241,9 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
241
241
|
this.log.error(constants_1.LOG_PREFIX + this.redisError);
|
|
242
242
|
return Promise.reject(this.redisError);
|
|
243
243
|
}
|
|
244
|
-
var splits = {};
|
|
245
244
|
var keys = names.map(function (name) { return _this.keys.buildSplitKey(name); });
|
|
246
245
|
return (_a = this.redis).mget.apply(_a, keys).then(function (splitDefinitions) {
|
|
246
|
+
var splits = {};
|
|
247
247
|
names.forEach(function (name, idx) {
|
|
248
248
|
var split = splitDefinitions[idx];
|
|
249
249
|
splits[name] = split && JSON.parse(split);
|
|
@@ -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
|
};
|
|
@@ -54,26 +54,30 @@ 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, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize;
|
|
57
|
+
var onReadyCb = params.onReadyCb, settings = params.settings, _a = params.settings, log = _a.log, mode = _a.mode, impressionsMode = _a.sync.impressionsMode, _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 isSyncronizer = 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) || isSyncronizer ?
|
|
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
|
-
|
|
73
|
-
|
|
68
|
+
var impressionCountsCache = impressionsMode !== constants_1.DEBUG || isSyncronizer ?
|
|
69
|
+
isPartialConsumer ?
|
|
70
|
+
new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() :
|
|
71
|
+
new ImpressionCountsCachePluggable_1.ImpressionCountsCachePluggable(log, keys.buildImpressionsCountKey(), wrapper) :
|
|
72
|
+
undefined;
|
|
73
|
+
var uniqueKeysCache = impressionsMode === constants_1.NONE || isSyncronizer ?
|
|
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;
|
|
74
78
|
// Connects to wrapper and emits SDK_READY event on main client
|
|
75
79
|
var connectPromise = wrapper.connect().then(function () {
|
|
76
|
-
if (
|
|
80
|
+
if (isSyncronizer) {
|
|
77
81
|
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
78
82
|
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
79
83
|
var currentHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
@@ -89,9 +93,9 @@ function PluggableStorage(options) {
|
|
|
89
93
|
}
|
|
90
94
|
else {
|
|
91
95
|
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
92
|
-
if (impressionCountsCache.start)
|
|
96
|
+
if (impressionCountsCache && impressionCountsCache.start)
|
|
93
97
|
impressionCountsCache.start();
|
|
94
|
-
if (uniqueKeysCache.start)
|
|
98
|
+
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
95
99
|
uniqueKeysCache.start();
|
|
96
100
|
if (telemetry && telemetry.recordConfig)
|
|
97
101
|
telemetry.recordConfig();
|
|
@@ -112,9 +116,9 @@ function PluggableStorage(options) {
|
|
|
112
116
|
uniqueKeys: uniqueKeysCache,
|
|
113
117
|
// Stop periodic flush and disconnect the underlying storage
|
|
114
118
|
destroy: function () {
|
|
115
|
-
return Promise.all(
|
|
116
|
-
impressionCountsCache.stop && impressionCountsCache.stop(),
|
|
117
|
-
uniqueKeysCache.stop && uniqueKeysCache.stop(),
|
|
119
|
+
return Promise.all(isSyncronizer ? [] : [
|
|
120
|
+
impressionCountsCache && impressionCountsCache.stop && impressionCountsCache.stop(),
|
|
121
|
+
uniqueKeysCache && uniqueKeysCache.stop && uniqueKeysCache.stop(),
|
|
118
122
|
]).then(function () { return wrapper.disconnect(); });
|
|
119
123
|
},
|
|
120
124
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
@@ -309,12 +309,14 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
309
309
|
// Reconnects in case of a new client.
|
|
310
310
|
// Run in next event-loop cycle to save authentication calls
|
|
311
311
|
// in case multiple clients are created in the current cycle.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
connectForNewClient
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
312
|
+
if (this.isRunning()) {
|
|
313
|
+
setTimeout(function checkForReconnect() {
|
|
314
|
+
if (connectForNewClient) {
|
|
315
|
+
connectForNewClient = false;
|
|
316
|
+
connectPush();
|
|
317
|
+
}
|
|
318
|
+
}, 0);
|
|
319
|
+
}
|
|
318
320
|
}
|
|
319
321
|
},
|
|
320
322
|
// [Only for client-side]
|
|
@@ -30,7 +30,9 @@ 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
|
-
|
|
33
|
+
if (impressionCounts) {
|
|
34
|
+
// retry impressions counts only once.
|
|
35
|
+
return (0, submitter_1.submitterFactory)(log, postTestImpressionsCount, impressionCounts, IMPRESSIONS_COUNT_RATE, 'impression counts', fromImpressionCountsCollector, 1);
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
exports.impressionCountsSubmitterFactory = impressionCountsSubmitterFactory;
|
|
@@ -9,11 +9,14 @@ 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)
|
|
13
|
-
(0, impressionCountsSubmitter_1.impressionCountsSubmitterFactory)(params),
|
|
14
|
-
(0, uniqueKeysSubmitter_1.uniqueKeysSubmitterFactory)(params)
|
|
12
|
+
(0, eventsSubmitter_1.eventsSubmitterFactory)(params)
|
|
15
13
|
];
|
|
14
|
+
var impressionCountsSubmitter = (0, impressionCountsSubmitter_1.impressionCountsSubmitterFactory)(params);
|
|
15
|
+
if (impressionCountsSubmitter)
|
|
16
|
+
submitters.push(impressionCountsSubmitter);
|
|
16
17
|
var telemetrySubmitter = (0, telemetrySubmitter_1.telemetrySubmitterFactory)(params);
|
|
18
|
+
if (params.storage.uniqueKeys)
|
|
19
|
+
submitters.push((0, uniqueKeysSubmitter_1.uniqueKeysSubmitterFactory)(params));
|
|
17
20
|
return {
|
|
18
21
|
// `onlyTelemetry` true if SDK is created with userConsent not GRANTED
|
|
19
22
|
start: function (onlyTelemetry) {
|
|
@@ -118,6 +118,8 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
118
118
|
if (!pollingManager)
|
|
119
119
|
return;
|
|
120
120
|
var mySegmentsSyncTask = pollingManager.add(matchingKey, readinessManager, storage);
|
|
121
|
+
if (syncEnabled && pushManager)
|
|
122
|
+
pushManager.add(matchingKey, mySegmentsSyncTask);
|
|
121
123
|
if (running) {
|
|
122
124
|
if (syncEnabled) {
|
|
123
125
|
if (pushManager) {
|
|
@@ -131,7 +133,6 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
131
133
|
// of segments since `syncAll` was already executed when starting the main client
|
|
132
134
|
mySegmentsSyncTask.execute();
|
|
133
135
|
}
|
|
134
|
-
pushManager.add(matchingKey, mySegmentsSyncTask);
|
|
135
136
|
}
|
|
136
137
|
else {
|
|
137
138
|
if (storage.splits.usesSegments())
|
|
@@ -25,7 +25,7 @@ function eventTrackerFactory(settings, eventsCache, whenInit, integrationsManage
|
|
|
25
25
|
whenInit(function () {
|
|
26
26
|
// Wrap in a timeout because we don't want it to be blocking.
|
|
27
27
|
setTimeout(function () {
|
|
28
|
-
// copy of event, to avoid unexpected
|
|
28
|
+
// copy of event, to avoid unexpected behavior if modified by integrations
|
|
29
29
|
var eventDataCopy = (0, objectAssign_1.objectAssign)({}, eventData);
|
|
30
30
|
if (properties)
|
|
31
31
|
eventDataCopy.properties = (0, objectAssign_1.objectAssign)({}, properties);
|