@splitsoftware/splitio-commons 3.1.1-rc.10 → 3.1.1-rc.12
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 +3 -0
- package/cjs/evaluator/condition/index.js +2 -2
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/cjs/evaluator/index.js +81 -71
- package/cjs/listeners/browser.js +2 -1
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +15 -20
- package/cjs/logger/messages/debug.js +5 -6
- package/cjs/logger/messages/error.js +3 -3
- package/cjs/logger/messages/info.js +3 -4
- package/cjs/logger/messages/warn.js +6 -7
- package/cjs/platform/browser.js +15 -0
- package/cjs/platform/getEventSource/browser.js +8 -0
- package/cjs/platform/getEventSource/eventsource.js +480 -0
- package/cjs/platform/getEventSource/node.js +26 -0
- package/cjs/platform/getFetch/browser.js +9 -0
- package/cjs/platform/getFetch/node.js +27 -0
- package/cjs/platform/getOptions/node.js +25 -0
- package/cjs/platform/node.js +17 -0
- package/cjs/presets/serverSide.js +2 -2
- package/cjs/readiness/constants.js +5 -4
- package/cjs/readiness/readinessManager.js +23 -23
- package/cjs/readiness/sdkReadinessManager.js +1 -17
- package/cjs/sdkClient/client.js +24 -50
- package/cjs/sdkClient/clientInputValidation.js +6 -17
- package/cjs/sdkClient/sdkClient.js +3 -60
- package/cjs/sdkClient/sdkLifecycle.js +74 -0
- package/cjs/sdkClient/trackMethod.js +56 -0
- package/cjs/sdkFactory/index.js +11 -15
- package/cjs/sdkManager/index.js +5 -5
- package/cjs/services/authProvider.js +80 -0
- package/cjs/services/decorateHeaders.js +2 -1
- package/cjs/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +15 -16
- package/cjs/services/secureSplitHttpClient.js +36 -0
- package/cjs/services/serviceApi.js +147 -0
- package/cjs/services/splitApi.js +24 -10
- package/cjs/services/splitHttpClient.js +3 -5
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
- package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
- package/cjs/storages/KeyBuilder.js +6 -6
- package/cjs/storages/KeyBuilderCS.js +5 -5
- package/cjs/storages/KeyBuilderSS.js +2 -2
- package/cjs/storages/getRolloutPlan.js +3 -3
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +195 -0
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +12 -11
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +122 -0
- package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +7 -6
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +79 -77
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +214 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
- package/cjs/storages/pluggable/index.js +2 -2
- package/cjs/storages/setRolloutPlan.js +4 -4
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
- package/cjs/sync/polling/pollingManagerCS.js +86 -81
- package/cjs/sync/polling/pollingManagerSS.js +44 -36
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +13 -0
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/definitionChangesUpdater.js +207 -0
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +19 -20
- package/cjs/sync/streaming/constants.js +4 -3
- package/cjs/sync/streaming/parseUtils.js +14 -14
- package/cjs/sync/streaming/pushManager.js +22 -26
- package/cjs/sync/submitters/eventsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
- package/cjs/sync/submitters/telemetrySubmitter.js +3 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +5 -5
- package/cjs/utils/Backoff.js +35 -3
- package/cjs/utils/EventEmitter.js +391 -0
- package/cjs/utils/filter/bloomFilter.js +37 -0
- package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
- package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
- package/cjs/utils/inputValidation/definitions.js +25 -0
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/target.js +22 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/settingsValidation/index.js +2 -0
- package/cjs/utils/settingsValidation/splitFilters.js +3 -3
- package/cjs/utils/settingsValidation/url.js +6 -2
- package/esm/evaluator/condition/index.js +2 -2
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/esm/evaluator/index.js +80 -71
- package/esm/listeners/browser.js +2 -1
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +12 -17
- package/esm/logger/messages/debug.js +5 -6
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +3 -4
- package/esm/logger/messages/warn.js +6 -7
- package/esm/platform/browser.js +12 -0
- package/esm/platform/getEventSource/browser.js +4 -0
- package/esm/platform/getEventSource/eventsource.js +480 -0
- package/esm/platform/getEventSource/node.js +20 -0
- package/esm/platform/getFetch/browser.js +5 -0
- package/esm/platform/getFetch/node.js +22 -0
- package/esm/platform/getOptions/node.js +20 -0
- package/esm/platform/node.js +14 -0
- package/esm/presets/serverSide.js +2 -2
- package/esm/readiness/constants.js +4 -3
- package/esm/readiness/readinessManager.js +24 -24
- package/esm/readiness/sdkReadinessManager.js +2 -18
- package/esm/sdkClient/client.js +23 -50
- package/esm/sdkClient/clientInputValidation.js +8 -19
- package/esm/sdkClient/sdkClient.js +3 -60
- package/esm/sdkClient/sdkLifecycle.js +70 -0
- package/esm/sdkClient/trackMethod.js +52 -0
- package/esm/sdkFactory/index.js +12 -16
- package/esm/sdkManager/index.js +6 -6
- package/esm/services/authProvider.js +76 -0
- package/esm/services/decorateHeaders.js +2 -1
- package/esm/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +13 -13
- package/esm/services/secureSplitHttpClient.js +32 -0
- package/esm/services/serviceApi.js +143 -0
- package/esm/services/splitApi.js +24 -10
- package/esm/services/splitHttpClient.js +3 -5
- package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
- package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
- package/esm/storages/KeyBuilder.js +6 -6
- package/esm/storages/KeyBuilderCS.js +5 -5
- package/esm/storages/KeyBuilderSS.js +2 -2
- package/esm/storages/getRolloutPlan.js +3 -3
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +192 -0
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +9 -8
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +119 -0
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +4 -3
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +78 -76
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +211 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/setRolloutPlan.js +4 -4
- package/esm/storages/utils.js +1 -0
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
- package/esm/sync/polling/pollingManagerCS.js +87 -82
- package/esm/sync/polling/pollingManagerSS.js +44 -36
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +9 -0
- package/esm/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/esm/sync/polling/updaters/definitionChangesUpdater.js +201 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
- package/esm/sync/streaming/SSEHandler/index.js +3 -2
- package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +19 -20
- package/esm/sync/streaming/constants.js +3 -2
- package/esm/sync/streaming/parseUtils.js +11 -11
- package/esm/sync/streaming/pushManager.js +24 -28
- package/esm/sync/submitters/eventsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionsSubmitter.js +5 -4
- package/esm/sync/submitters/telemetrySubmitter.js +3 -4
- package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +4 -4
- package/esm/utils/Backoff.js +35 -3
- package/esm/utils/EventEmitter.js +387 -0
- package/esm/utils/filter/bloomFilter.js +33 -0
- package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
- package/esm/utils/inputValidation/definitionExistence.js +15 -0
- package/esm/utils/inputValidation/definitions.js +21 -0
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/target.js +18 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/settingsValidation/index.js +2 -0
- package/esm/utils/settingsValidation/splitFilters.js +3 -3
- package/esm/utils/settingsValidation/url.js +6 -2
- package/package.json +1 -1
- package/src/dtos/types.ts +4 -4
- package/src/services/authProvider.ts +2 -2
- package/src/{sync/streaming/AuthClient/index.ts → services/fetchAuth.ts} +3 -4
- package/src/services/splitApi.ts +1 -1
- package/src/services/types.ts +21 -4
- package/src/storages/AbstractDefinitionsCacheAsync.ts +3 -3
- package/src/storages/AbstractDefinitionsCacheSync.ts +2 -2
- package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +2 -2
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +3 -3
- package/src/storages/inMemory/DefinitionsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -2
- package/src/storages/inRedis/DefinitionsCacheInRedis.ts +6 -4
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +7 -5
- package/src/storages/pluggable/DefinitionsCachePluggable.ts +4 -2
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +5 -3
- package/src/storages/types.ts +6 -6
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +5 -5
- package/src/sync/polling/types.ts +22 -1
- package/src/sync/polling/updaters/definitionChangesUpdater.ts +26 -20
- package/src/sync/streaming/SSEClient/index.ts +1 -1
- package/src/sync/streaming/SSEClient/types.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/DefinitionsUpdateWorker.ts +15 -11
- package/src/sync/streaming/UpdateWorkers/types.ts +6 -0
- package/src/sync/streaming/parseUtils.ts +3 -4
- package/src/sync/streaming/pushManager.ts +4 -3
- package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
- package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
- package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +0 -200
- package/cjs/sync/streaming/AuthClient/types.js +0 -2
- package/cjs/utils/inputValidation/splits.js +0 -25
- package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
- package/esm/storages/AbstractSplitsCacheSync.js +0 -71
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
- package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
- package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
- package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -194
- package/esm/sync/streaming/AuthClient/types.js +0 -1
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
- package/src/sync/streaming/AuthClient/types.ts +0 -19
|
@@ -6,8 +6,7 @@ var Backoff_1 = require("../../utils/Backoff");
|
|
|
6
6
|
var SSEHandler_1 = require("./SSEHandler");
|
|
7
7
|
var MySegmentsUpdateWorker_1 = require("./UpdateWorkers/MySegmentsUpdateWorker");
|
|
8
8
|
var SegmentsUpdateWorker_1 = require("./UpdateWorkers/SegmentsUpdateWorker");
|
|
9
|
-
var
|
|
10
|
-
var AuthClient_1 = require("./AuthClient");
|
|
9
|
+
var DefinitionsUpdateWorker_1 = require("./UpdateWorkers/DefinitionsUpdateWorker");
|
|
11
10
|
var lang_1 = require("../../utils/lang");
|
|
12
11
|
var SSEClient_1 = require("./SSEClient");
|
|
13
12
|
var key_1 = require("../../utils/key");
|
|
@@ -22,8 +21,9 @@ var constants_3 = require("../../utils/constants");
|
|
|
22
21
|
* - for server-side if key is not provided in settings.
|
|
23
22
|
* - for client-side, with support for multiple clients, if key is provided in settings
|
|
24
23
|
*/
|
|
25
|
-
function pushManagerFactory(params, pollingManager) {
|
|
26
|
-
|
|
24
|
+
function pushManagerFactory(params, pollingManager, definitionsUpdateWorkerFactory) {
|
|
25
|
+
if (definitionsUpdateWorkerFactory === void 0) { definitionsUpdateWorkerFactory = DefinitionsUpdateWorker_1.DefinitionsUpdateWorker; }
|
|
26
|
+
var settings = params.settings, storage = params.storage, serviceApi = params.serviceApi, platform = params.platform, telemetryTracker = params.telemetryTracker;
|
|
27
27
|
// `userKey` is the matching key of main client in client-side SDK.
|
|
28
28
|
// It can be used to check if running on client-side or server-side SDK.
|
|
29
29
|
var userKey = (0, key_1.checkIfServerSide)(settings) ? undefined : (0, key_1.getMatching)(settings.core.key);
|
|
@@ -37,7 +37,6 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
37
37
|
log.warn(constants_2.STREAMING_FALLBACK, [e]);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
var authenticate = (0, AuthClient_1.authenticateFactory)(splitApi.fetchAuth);
|
|
41
40
|
// init feedback loop
|
|
42
41
|
var pushEmitter = new platform.EventEmitter();
|
|
43
42
|
var sseHandler = (0, SSEHandler_1.SSEHandlerFactory)(log, pushEmitter, telemetryTracker);
|
|
@@ -45,19 +44,17 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
45
44
|
// init workers
|
|
46
45
|
// MySegmentsUpdateWorker (client-side) are initiated in `add` method
|
|
47
46
|
var segmentsUpdateWorker = userKey ? undefined : (0, SegmentsUpdateWorker_1.SegmentsUpdateWorker)(log, pollingManager.segmentsSyncTask, storage.segments);
|
|
48
|
-
// For server-side we pass the segmentsSyncTask, used by
|
|
49
|
-
var
|
|
50
|
-
// [Only for client-side] map of hashes to user keys, to dispatch membership update events to the corresponding MySegmentsUpdateWorker
|
|
51
|
-
var userKeyHashes = {};
|
|
47
|
+
// For server-side we pass the segmentsSyncTask, used by DefinitionsUpdateWorker to fetch new segments
|
|
48
|
+
var definitionsUpdateWorker = definitionsUpdateWorkerFactory(params, pollingManager);
|
|
52
49
|
// [Only for client-side] map of user keys to their corresponding hash64 and MySegmentsUpdateWorkers.
|
|
53
50
|
// Hash64 is used to process membership update events and dispatch actions to the corresponding MySegmentsUpdateWorker.
|
|
54
51
|
var clients = {};
|
|
55
52
|
// [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
|
|
56
53
|
var connectForNewClient = false;
|
|
57
|
-
// flag that indicates if `stop/disconnectPush` was called, either by the SyncManager, when the client is destroyed, or due to a
|
|
54
|
+
// flag that indicates if `stop/disconnectPush` was called, either by the SyncManager, when the client is destroyed, or due to a PUSH_NON_RETRYABLE_ERROR error.
|
|
58
55
|
// It is used to halt the `connectPush` process if it was in progress.
|
|
59
56
|
var disconnected;
|
|
60
|
-
// flag that indicates a
|
|
57
|
+
// flag that indicates a PUSH_NON_RETRYABLE_ERROR, condition with which starting pushManager again is ignored.
|
|
61
58
|
// true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
|
|
62
59
|
var disabled; // `disabled` implies `disconnected === true`
|
|
63
60
|
/** PushManager functions related to initialization */
|
|
@@ -93,14 +90,14 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
93
90
|
log.info(constants_2.STREAMING_CONNECTING);
|
|
94
91
|
disconnected = false;
|
|
95
92
|
var userKeys = userKey ? Object.keys(clients) : undefined;
|
|
96
|
-
|
|
93
|
+
serviceApi.fetchAuth(userKeys).then(function (authData) {
|
|
97
94
|
if (disconnected)
|
|
98
95
|
return;
|
|
99
|
-
// 'pushEnabled: false' is handled as a
|
|
96
|
+
// 'pushEnabled: false' is handled as a PUSH_NON_RETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
|
|
100
97
|
// close the sseClient in case the org has been bloqued while the instance was connected to streaming
|
|
101
98
|
if (!authData.pushEnabled) {
|
|
102
99
|
log.info(constants_2.STREAMING_DISABLED);
|
|
103
|
-
pushEmitter.emit(constants_1.
|
|
100
|
+
pushEmitter.emit(constants_1.PUSH_NON_RETRYABLE_ERROR);
|
|
104
101
|
return;
|
|
105
102
|
}
|
|
106
103
|
// [Only for client-side] don't open SSE connection if a new shared client was added, since it means that a new authentication is taking place
|
|
@@ -115,7 +112,7 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
115
112
|
// Handle 4XX HTTP errors: 401 (invalid SDK Key) or 400 (using incorrect SDK Key, i.e., client-side SDK Key on server-side)
|
|
116
113
|
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
117
114
|
telemetryTracker.streamingEvent(constants_3.AUTH_REJECTION);
|
|
118
|
-
pushEmitter.emit(constants_1.
|
|
115
|
+
pushEmitter.emit(constants_1.PUSH_NON_RETRYABLE_ERROR);
|
|
119
116
|
return;
|
|
120
117
|
}
|
|
121
118
|
// Handle other HTTP and network errors as recoverable errors
|
|
@@ -139,7 +136,7 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
139
136
|
}
|
|
140
137
|
// cancel scheduled fetch retries of Splits, Segments, and MySegments Update Workers
|
|
141
138
|
function stopWorkers() {
|
|
142
|
-
|
|
139
|
+
definitionsUpdateWorker.stop();
|
|
143
140
|
if (userKey)
|
|
144
141
|
(0, lang_1.forOwn)(clients, function (_a) {
|
|
145
142
|
var worker = _a.worker;
|
|
@@ -155,7 +152,7 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
155
152
|
connectPushRetryBackoff.reset();
|
|
156
153
|
});
|
|
157
154
|
/** Fallback to polling without retry due to: STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE and Authentication errors */
|
|
158
|
-
pushEmitter.on(constants_1.
|
|
155
|
+
pushEmitter.on(constants_1.PUSH_NON_RETRYABLE_ERROR, function handleNonRetryableError() {
|
|
159
156
|
disabled = true;
|
|
160
157
|
// Note: `stopWorkers` is been called twice, but it is not harmful
|
|
161
158
|
disconnectPush();
|
|
@@ -181,9 +178,12 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
181
178
|
connectPush();
|
|
182
179
|
});
|
|
183
180
|
/** Functions related to synchronization (Queues and Workers in the spec) */
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
pushEmitter.on(constants_1.
|
|
181
|
+
// Some notification types are specific to the Feature flags or Configs SDKs. Their handlers are
|
|
182
|
+
// registered unconditionally, since the SDK only subscribes to the channels of its own entities.
|
|
183
|
+
pushEmitter.on(constants_1.SPLIT_KILL, definitionsUpdateWorker.killDefinition);
|
|
184
|
+
pushEmitter.on(constants_1.SPLIT_UPDATE, definitionsUpdateWorker.put);
|
|
185
|
+
pushEmitter.on(constants_1.CONFIG_UPDATE, definitionsUpdateWorker.put);
|
|
186
|
+
pushEmitter.on(constants_1.RB_SEGMENT_UPDATE, definitionsUpdateWorker.put);
|
|
187
187
|
function handleMySegmentsUpdate(parsedData) {
|
|
188
188
|
switch (parsedData.u) {
|
|
189
189
|
case types_1.UpdateStrategy.BoundedFetchRequest: {
|
|
@@ -206,7 +206,7 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
206
206
|
case types_1.UpdateStrategy.KeyList: {
|
|
207
207
|
var keyList = void 0, added_1, removed_1;
|
|
208
208
|
try {
|
|
209
|
-
keyList = (0, parseUtils_1.
|
|
209
|
+
keyList = (0, parseUtils_1.parseCompressedData)(parsedData.d, parsedData.c);
|
|
210
210
|
added_1 = new Set(keyList.a);
|
|
211
211
|
removed_1 = new Set(keyList.r);
|
|
212
212
|
}
|
|
@@ -285,9 +285,7 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
285
285
|
},
|
|
286
286
|
// [Only for client-side]
|
|
287
287
|
add: function (userKey, mySegmentsSyncTask) {
|
|
288
|
-
|
|
289
|
-
if (!userKeyHashes[hash]) {
|
|
290
|
-
userKeyHashes[hash] = userKey;
|
|
288
|
+
if (!clients[userKey]) {
|
|
291
289
|
clients[userKey] = {
|
|
292
290
|
hash64: (0, murmur3_64_1.hash64)(userKey),
|
|
293
291
|
worker: (0, MySegmentsUpdateWorker_1.MySegmentsUpdateWorker)(log, storage, mySegmentsSyncTask, telemetryTracker)
|
|
@@ -308,8 +306,6 @@ function pushManagerFactory(params, pollingManager) {
|
|
|
308
306
|
},
|
|
309
307
|
// [Only for client-side]
|
|
310
308
|
remove: function (userKey) {
|
|
311
|
-
var hash = (0, AuthClient_1.hashUserKey)(userKey);
|
|
312
|
-
delete userKeyHashes[hash];
|
|
313
309
|
delete clients[userKey];
|
|
314
310
|
}
|
|
315
311
|
});
|
|
@@ -7,7 +7,7 @@ var constants_1 = require("../../logger/constants");
|
|
|
7
7
|
* Submitter that periodically posts tracked events
|
|
8
8
|
*/
|
|
9
9
|
function eventsSubmitterFactory(params) {
|
|
10
|
-
var _a = params.settings, log = _a.log, eventsPushRate = _a.scheduler.eventsPushRate, eventsFirstPushWindow = _a.startup.eventsFirstPushWindow, postEventsBulk = params.
|
|
10
|
+
var _a = params.settings, log = _a.log, eventsPushRate = _a.scheduler.eventsPushRate, eventsFirstPushWindow = _a.startup.eventsFirstPushWindow, postEventsBulk = params.serviceApi.postEventsBulk, events = params.storage.events;
|
|
11
11
|
// don't retry events.
|
|
12
12
|
var submitter = (0, submitter_1.submitterFactory)(log, postEventsBulk, events, eventsPushRate);
|
|
13
13
|
// Set a timer for the first push window of events.
|
|
@@ -29,7 +29,7 @@ var IMPRESSIONS_COUNT_RATE = 1800000; // 30 minutes
|
|
|
29
29
|
* Submitter that periodically posts impression counts
|
|
30
30
|
*/
|
|
31
31
|
function impressionCountsSubmitterFactory(params) {
|
|
32
|
-
var log = params.settings.log, postTestImpressionsCount = params.
|
|
32
|
+
var log = params.settings.log, postTestImpressionsCount = params.serviceApi.postTestImpressionsCount, impressionCounts = params.storage.impressionCounts;
|
|
33
33
|
// retry impressions counts only once.
|
|
34
34
|
return (0, submitter_1.submitterFactory)(log, postTestImpressionsCount, impressionCounts, IMPRESSIONS_COUNT_RATE, fromImpressionCountsCollector, 1);
|
|
35
35
|
}
|
|
@@ -14,7 +14,7 @@ function fromImpressionsCollector(sendLabels, data) {
|
|
|
14
14
|
dto.push({
|
|
15
15
|
f: name,
|
|
16
16
|
i: value.map(function (entry) {
|
|
17
|
-
|
|
17
|
+
return {
|
|
18
18
|
k: entry.keyName,
|
|
19
19
|
t: entry.treatment,
|
|
20
20
|
m: entry.time,
|
|
@@ -22,9 +22,10 @@ function fromImpressionsCollector(sendLabels, data) {
|
|
|
22
22
|
r: sendLabels ? entry.label : undefined,
|
|
23
23
|
b: entry.bucketingKey,
|
|
24
24
|
pt: entry.pt,
|
|
25
|
-
properties: entry.properties
|
|
25
|
+
properties: entry.properties,
|
|
26
|
+
// @TODO: add entityType to public SplitIO.ImpressionDTO type
|
|
27
|
+
et: entry.entityType, // Definition type
|
|
26
28
|
};
|
|
27
|
-
return keyImpression;
|
|
28
29
|
})
|
|
29
30
|
});
|
|
30
31
|
});
|
|
@@ -35,7 +36,7 @@ exports.fromImpressionsCollector = fromImpressionsCollector;
|
|
|
35
36
|
* Submitter that periodically posts impressions data
|
|
36
37
|
*/
|
|
37
38
|
function impressionsSubmitterFactory(params) {
|
|
38
|
-
var _a = params.settings, log = _a.log, impressionsRefreshRate = _a.scheduler.impressionsRefreshRate, labelsEnabled = _a.core.labelsEnabled, postTestImpressionsBulk = params.
|
|
39
|
+
var _a = params.settings, log = _a.log, impressionsRefreshRate = _a.scheduler.impressionsRefreshRate, labelsEnabled = _a.core.labelsEnabled, postTestImpressionsBulk = params.serviceApi.postTestImpressionsBulk, impressions = params.storage.impressions;
|
|
39
40
|
// retry impressions only once.
|
|
40
41
|
var syncTask = (0, submitter_1.submitterFactory)(log, postTestImpressionsBulk, impressions, impressionsRefreshRate, fromImpressionsCollector.bind(undefined, labelsEnabled), 1);
|
|
41
42
|
// register impressions submitter to be executed when impressions cache is full
|
|
@@ -107,18 +107,17 @@ function telemetrySubmitterFactory(params) {
|
|
|
107
107
|
var telemetry = params.storage.telemetry, now = params.platform.now;
|
|
108
108
|
if (!telemetry || !now)
|
|
109
109
|
return; // No submitter created if telemetry cache is not defined
|
|
110
|
-
var settings = params.settings, _a = params.settings, log = _a.log, telemetryRefreshRate = _a.scheduler.telemetryRefreshRate,
|
|
110
|
+
var settings = params.settings, _a = params.settings, log = _a.log, telemetryRefreshRate = _a.scheduler.telemetryRefreshRate, serviceApi = params.serviceApi, readiness = params.readiness;
|
|
111
111
|
var stopTimer = (0, timer_1.timer)(now);
|
|
112
|
-
var submitter = (0, submitter_1.firstPushWindowDecorator)((0, submitter_1.submitterFactory)(log,
|
|
112
|
+
var submitter = (0, submitter_1.firstPushWindowDecorator)((0, submitter_1.submitterFactory)(log, serviceApi.postMetricsUsage, telemetry, telemetryRefreshRate, undefined, 0, true), telemetryRefreshRate);
|
|
113
113
|
readiness.gate.once(constants_2.SDK_READY_FROM_CACHE, function () {
|
|
114
114
|
telemetry.recordTimeUntilReadyFromCache(stopTimer());
|
|
115
115
|
});
|
|
116
|
-
sdkReadinessManager.incInternalReadyCbCount();
|
|
117
116
|
readiness.gate.once(constants_2.SDK_READY, function () {
|
|
118
117
|
telemetry.recordTimeUntilReady(stopTimer());
|
|
119
118
|
// Post config data when the SDK is ready and if the telemetry submitter was started
|
|
120
119
|
if (submitter.isRunning()) {
|
|
121
|
-
var postMetricsConfigTask = (0, submitter_1.submitterFactory)(log,
|
|
120
|
+
var postMetricsConfigTask = (0, submitter_1.submitterFactory)(log, serviceApi.postMetricsConfig, telemetryCacheConfigAdapter(telemetry, settings), 0, undefined, 0, true);
|
|
122
121
|
postMetricsConfigTask.execute();
|
|
123
122
|
}
|
|
124
123
|
});
|
|
@@ -8,7 +8,7 @@ var UNIQUE_KEYS_RATE = 900000; // 15 minutes
|
|
|
8
8
|
* Submitter that periodically posts impression counts
|
|
9
9
|
*/
|
|
10
10
|
function uniqueKeysSubmitterFactory(params) {
|
|
11
|
-
var _a = params.settings, log = _a.log, key = _a.core.key, _b = params.
|
|
11
|
+
var _a = params.settings, log = _a.log, key = _a.core.key, _b = params.serviceApi, postUniqueKeysBulkCs = _b.postUniqueKeysBulkCs, postUniqueKeysBulkSs = _b.postUniqueKeysBulkSs, uniqueKeys = params.storage.uniqueKeys;
|
|
12
12
|
var isClientSide = key !== undefined;
|
|
13
13
|
var postUniqueKeysBulk = isClientSide ? postUniqueKeysBulkCs : postUniqueKeysBulkSs;
|
|
14
14
|
var syncTask = (0, submitter_1.submitterFactory)(log, postUniqueKeysBulk, uniqueKeys, UNIQUE_KEYS_RATE);
|
|
@@ -7,7 +7,7 @@ var constants_2 = require("../logger/constants");
|
|
|
7
7
|
var consent_1 = require("../consent");
|
|
8
8
|
var constants_3 = require("../utils/constants");
|
|
9
9
|
var constants_4 = require("../readiness/constants");
|
|
10
|
-
var
|
|
10
|
+
var AbstractDefinitionsCacheSync_1 = require("../storages/AbstractDefinitionsCacheSync");
|
|
11
11
|
/**
|
|
12
12
|
* Online SyncManager factory.
|
|
13
13
|
* Can be used for server-side API, and client-side API with or without multiple clients.
|
|
@@ -29,7 +29,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
29
29
|
pushManagerFactory(params, pollingManager) :
|
|
30
30
|
undefined;
|
|
31
31
|
/** Submitter Manager */
|
|
32
|
-
// It is not
|
|
32
|
+
// It is not injected as push and polling managers, because at the moment it is required
|
|
33
33
|
var submitterManager = (0, submitterManager_1.submitterManagerFactory)(params);
|
|
34
34
|
/** Sync Manager logic */
|
|
35
35
|
function startPolling() {
|
|
@@ -77,7 +77,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
77
77
|
if (startFirstTime) {
|
|
78
78
|
// Emits SDK_READY_FROM_CACHE
|
|
79
79
|
if (!cacheMetadata.initialCacheLoad) {
|
|
80
|
-
readiness.
|
|
80
|
+
readiness.definitions.emit(constants_4.SDK_DEFINITIONS_CACHE_LOADED, cacheMetadata);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
// start syncing splits and segments
|
|
@@ -136,7 +136,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
136
136
|
if (pushManager) {
|
|
137
137
|
if (pollingManager.isRunning()) {
|
|
138
138
|
// if doing polling, we must start the periodic fetch of data
|
|
139
|
-
if ((0,
|
|
139
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegmentsSync)(storage))
|
|
140
140
|
mySegmentsSyncTask.start();
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
@@ -146,7 +146,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
else {
|
|
149
|
-
if ((0,
|
|
149
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegmentsSync)(storage))
|
|
150
150
|
mySegmentsSyncTask.start();
|
|
151
151
|
}
|
|
152
152
|
}
|
package/cjs/utils/Backoff.js
CHANGED
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Backoff = void 0;
|
|
4
4
|
var Backoff = /** @class */ (function () {
|
|
5
5
|
/**
|
|
6
|
-
* Schedule function calls with exponential backoff
|
|
6
|
+
* Schedule function calls with exponential backoff.
|
|
7
|
+
* @param cb - The function to call. Must return a promise if used with `scheduleCallAsync`.
|
|
7
8
|
*/
|
|
8
9
|
function Backoff(cb, baseMillis, maxMillis) {
|
|
9
10
|
this.baseMillis = Backoff.__TEST__BASE_MILLIS || baseMillis || Backoff.DEFAULT_BASE_MILLIS;
|
|
@@ -20,19 +21,50 @@ var Backoff = /** @class */ (function () {
|
|
|
20
21
|
var delayInMillis = Math.min(this.baseMillis * Math.pow(2, this.attempts), this.maxMillis);
|
|
21
22
|
if (this.timeoutID)
|
|
22
23
|
clearTimeout(this.timeoutID);
|
|
24
|
+
this.attempts++;
|
|
23
25
|
this.timeoutID = setTimeout(function () {
|
|
24
26
|
_this.timeoutID = undefined;
|
|
25
27
|
_this.cb();
|
|
26
28
|
}, delayInMillis);
|
|
27
|
-
this.attempts++;
|
|
28
29
|
return delayInMillis;
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Schedule a delayed call to `cb`
|
|
33
|
+
* @returns a promise that resolves/rejects with the result of the `cb` function, which must return a promise.
|
|
34
|
+
*/
|
|
35
|
+
Backoff.prototype.scheduleCallAsync = function () {
|
|
36
|
+
var _this = this;
|
|
37
|
+
var delayInMillis = Math.min(this.baseMillis * Math.pow(2, this.attempts), this.maxMillis);
|
|
38
|
+
if (this.timeoutID)
|
|
39
|
+
clearTimeout(this.timeoutID);
|
|
40
|
+
this.attempts++;
|
|
41
|
+
return new Promise(function (resolve, reject) {
|
|
42
|
+
_this.pending = { resolve: resolve, reject: reject };
|
|
43
|
+
_this.timeoutID = setTimeout(function () {
|
|
44
|
+
_this.timeoutID = undefined;
|
|
45
|
+
_this.pending = undefined;
|
|
46
|
+
_this.cb().then(resolve, reject);
|
|
47
|
+
}, delayInMillis);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Reset the backoff attempts, canceling any scheduled `cb` call. If a `scheduleCallAsync` call is pending
|
|
52
|
+
* and the caller wants to settle it immediately instead of waiting for `cb` to be invoked, pass `settle`:
|
|
53
|
+
* `{ value }` to resolve, or `{ error }` to reject.
|
|
54
|
+
*/
|
|
55
|
+
Backoff.prototype.reset = function (settle) {
|
|
31
56
|
this.attempts = 0;
|
|
32
57
|
if (this.timeoutID) {
|
|
33
58
|
clearTimeout(this.timeoutID);
|
|
34
59
|
this.timeoutID = undefined;
|
|
35
60
|
}
|
|
61
|
+
if (settle && this.pending) {
|
|
62
|
+
if ('value' in settle)
|
|
63
|
+
this.pending.resolve(settle.value);
|
|
64
|
+
else
|
|
65
|
+
this.pending.reject(settle.error);
|
|
66
|
+
this.pending = undefined;
|
|
67
|
+
}
|
|
36
68
|
};
|
|
37
69
|
Backoff.DEFAULT_BASE_MILLIS = 1000; // 1 second
|
|
38
70
|
Backoff.DEFAULT_MAX_MILLIS = 1800000; // 30 minutes
|