@splitsoftware/splitio-commons 3.1.1-rc.1 → 3.1.1-rc.10
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 +10 -1
- package/cjs/evaluator/condition/index.js +2 -2
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
- package/cjs/evaluator/index.js +71 -76
- package/cjs/listeners/browser.js +1 -2
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +20 -15
- package/cjs/logger/messages/debug.js +6 -5
- package/cjs/logger/messages/error.js +3 -3
- package/cjs/logger/messages/info.js +4 -3
- package/cjs/logger/messages/warn.js +7 -6
- package/cjs/presets/serverSide.js +2 -2
- package/cjs/readiness/constants.js +4 -5
- package/cjs/readiness/readinessManager.js +23 -23
- package/cjs/readiness/sdkReadinessManager.js +17 -1
- package/cjs/sdkClient/client.js +51 -27
- package/cjs/sdkClient/clientInputValidation.js +17 -6
- package/cjs/sdkClient/sdkClient.js +60 -3
- package/cjs/sdkFactory/index.js +15 -11
- package/cjs/sdkManager/index.js +5 -5
- package/cjs/services/decorateHeaders.js +1 -2
- package/cjs/services/splitApi.js +1 -14
- package/cjs/services/splitHttpClient.js +5 -3
- package/cjs/storages/AbstractSplitsCacheAsync.js +51 -0
- package/cjs/storages/AbstractSplitsCacheSync.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/MySegmentsCacheInLocal.js +2 -1
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +194 -0
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +121 -0
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +8 -5
- package/cjs/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +77 -77
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +212 -0
- package/cjs/storages/pluggable/index.js +2 -2
- package/cjs/storages/setRolloutPlan.js +4 -4
- package/cjs/storages/utils.js +0 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +15 -24
- package/cjs/sync/polling/pollingManagerCS.js +20 -20
- package/cjs/sync/polling/pollingManagerSS.js +15 -15
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +13 -0
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
- package/cjs/sync/streaming/AuthClient/index.js +1 -1
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +1 -1
- package/cjs/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +19 -16
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/parseUtils.js +11 -11
- package/cjs/sync/streaming/pushManager.js +16 -16
- package/cjs/sync/submitters/eventsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionsSubmitter.js +4 -5
- package/cjs/sync/submitters/telemetrySubmitter.js +4 -3
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +7 -12
- package/cjs/utils/Backoff.js +0 -20
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/{definition.js → split.js} +10 -10
- package/cjs/utils/inputValidation/{definitionExistence.js → splitExistence.js} +6 -6
- package/cjs/utils/inputValidation/splits.js +25 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/settingsValidation/index.js +0 -2
- package/cjs/utils/settingsValidation/splitFilters.js +3 -3
- package/cjs/utils/settingsValidation/url.js +2 -6
- package/esm/evaluator/condition/index.js +2 -2
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
- package/esm/evaluator/index.js +71 -75
- package/esm/listeners/browser.js +1 -2
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +17 -12
- package/esm/logger/messages/debug.js +6 -5
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +4 -3
- package/esm/logger/messages/warn.js +7 -6
- package/esm/presets/serverSide.js +2 -2
- package/esm/readiness/constants.js +3 -4
- package/esm/readiness/readinessManager.js +24 -24
- package/esm/readiness/sdkReadinessManager.js +18 -2
- package/esm/sdkClient/client.js +51 -26
- package/esm/sdkClient/clientInputValidation.js +19 -8
- package/esm/sdkClient/sdkClient.js +60 -3
- package/esm/sdkFactory/index.js +16 -12
- package/esm/sdkManager/index.js +6 -6
- package/esm/services/decorateHeaders.js +1 -2
- package/esm/services/splitApi.js +1 -14
- package/esm/services/splitHttpClient.js +5 -3
- package/esm/storages/AbstractSplitsCacheAsync.js +48 -0
- package/esm/storages/AbstractSplitsCacheSync.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/MySegmentsCacheInLocal.js +2 -1
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +191 -0
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/SplitsCacheInMemory.js +118 -0
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +8 -5
- package/esm/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +76 -76
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/esm/storages/pluggable/SplitsCachePluggable.js +209 -0
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/setRolloutPlan.js +4 -4
- package/esm/storages/utils.js +0 -1
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +16 -25
- package/esm/sync/polling/pollingManagerCS.js +17 -17
- package/esm/sync/polling/pollingManagerSS.js +15 -15
- package/esm/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +9 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
- package/esm/sync/streaming/AuthClient/index.js +1 -1
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
- package/esm/sync/streaming/SSEHandler/index.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +18 -15
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/parseUtils.js +9 -9
- package/esm/sync/streaming/pushManager.js +18 -18
- package/esm/sync/submitters/eventsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionsSubmitter.js +4 -5
- package/esm/sync/submitters/telemetrySubmitter.js +4 -3
- package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +6 -11
- package/esm/utils/Backoff.js +0 -20
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/{definition.js → split.js} +8 -8
- package/esm/utils/inputValidation/splitExistence.js +15 -0
- package/esm/utils/inputValidation/splits.js +21 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/settingsValidation/index.js +0 -2
- package/esm/utils/settingsValidation/splitFilters.js +3 -3
- package/esm/utils/settingsValidation/url.js +2 -6
- package/package.json +6 -7
- package/src/dtos/types.ts +1 -1
- package/src/evaluator/index.ts +11 -5
- package/src/evaluator/types.ts +1 -0
- package/src/presets/serverSide.ts +3 -3
- package/src/sdkClient/client.ts +3 -4
- package/src/sdkClient/sdkLifecycle.ts +3 -0
- package/src/services/authProvider.ts +41 -19
- package/src/services/secureSplitHttpClient.ts +10 -18
- package/src/services/serviceApi.ts +27 -24
- package/src/services/splitApi.ts +10 -9
- package/src/services/types.ts +5 -4
- package/src/storages/inRedis/RedisAdapter.ts +8 -5
- package/src/sync/polling/pollingManagerCS.ts +80 -78
- package/src/sync/polling/pollingManagerSS.ts +49 -45
- package/src/sync/polling/updaters/definitionChangesUpdater.ts +3 -3
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/streaming/AuthClient/index.ts +14 -15
- package/src/sync/streaming/AuthClient/types.ts +9 -13
- package/src/sync/streaming/SSEClient/index.ts +2 -2
- package/src/sync/streaming/SSEClient/types.ts +2 -2
- package/src/sync/streaming/SSEHandler/index.ts +2 -1
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/constants.ts +1 -0
- package/src/sync/streaming/pushManager.ts +32 -42
- package/src/sync/streaming/types.ts +3 -2
- package/src/sync/submitters/impressionsSubmitter.ts +3 -3
- package/src/sync/submitters/types.ts +2 -2
- package/src/sync/syncManagerOnline.ts +2 -8
- package/src/utils/Backoff.ts +16 -4
- package/types/splitio.d.ts +5 -4
- package/cjs/platform/browser.js +0 -15
- package/cjs/platform/getEventSource/browser.js +0 -8
- package/cjs/platform/getEventSource/eventsource.js +0 -480
- package/cjs/platform/getEventSource/node.js +0 -26
- package/cjs/platform/getFetch/browser.js +0 -9
- package/cjs/platform/getFetch/node.js +0 -27
- package/cjs/platform/getOptions/node.js +0 -25
- package/cjs/platform/node.js +0 -17
- package/cjs/sdkClient/sdkLifecycle.js +0 -72
- package/cjs/sdkClient/trackMethod.js +0 -56
- package/cjs/services/authProvider.js +0 -67
- package/cjs/services/secureSplitHttpClient.js +0 -39
- package/cjs/services/serviceApi.js +0 -145
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +0 -51
- package/cjs/storages/AbstractDefinitionsCacheSync.js +0 -76
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -194
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +0 -121
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +0 -212
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +0 -13
- package/cjs/utils/EventEmitter.js +0 -391
- package/cjs/utils/filter/bloomFilter.js +0 -37
- package/cjs/utils/inputValidation/definitions.js +0 -25
- package/cjs/utils/inputValidation/target.js +0 -22
- package/esm/platform/browser.js +0 -12
- package/esm/platform/getEventSource/browser.js +0 -4
- package/esm/platform/getEventSource/eventsource.js +0 -480
- package/esm/platform/getEventSource/node.js +0 -20
- package/esm/platform/getFetch/browser.js +0 -5
- package/esm/platform/getFetch/node.js +0 -22
- package/esm/platform/getOptions/node.js +0 -20
- package/esm/platform/node.js +0 -14
- package/esm/sdkClient/sdkLifecycle.js +0 -68
- package/esm/sdkClient/trackMethod.js +0 -52
- package/esm/services/authProvider.js +0 -63
- package/esm/services/secureSplitHttpClient.js +0 -35
- package/esm/services/serviceApi.js +0 -141
- package/esm/storages/AbstractDefinitionsCacheAsync.js +0 -48
- package/esm/storages/AbstractDefinitionsCacheSync.js +0 -71
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -191
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +0 -118
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +0 -209
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +0 -9
- package/esm/utils/EventEmitter.js +0 -387
- package/esm/utils/filter/bloomFilter.js +0 -33
- package/esm/utils/inputValidation/definitionExistence.js +0 -15
- package/esm/utils/inputValidation/definitions.js +0 -21
- package/esm/utils/inputValidation/target.js +0 -18
|
@@ -107,17 +107,18 @@ 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, splitApi = params.splitApi, readiness = params.readiness, sdkReadinessManager = params.sdkReadinessManager;
|
|
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, splitApi.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();
|
|
116
117
|
readiness.gate.once(constants_2.SDK_READY, function () {
|
|
117
118
|
telemetry.recordTimeUntilReady(stopTimer());
|
|
118
119
|
// Post config data when the SDK is ready and if the telemetry submitter was started
|
|
119
120
|
if (submitter.isRunning()) {
|
|
120
|
-
var postMetricsConfigTask = (0, submitter_1.submitterFactory)(log,
|
|
121
|
+
var postMetricsConfigTask = (0, submitter_1.submitterFactory)(log, splitApi.postMetricsConfig, telemetryCacheConfigAdapter(telemetry, settings), 0, undefined, 0, true);
|
|
121
122
|
postMetricsConfigTask.execute();
|
|
122
123
|
}
|
|
123
124
|
});
|
|
@@ -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.splitApi, 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,9 +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
|
|
11
|
-
var splitChangesFetcher_1 = require("./polling/fetchers/splitChangesFetcher");
|
|
12
|
-
var segmentChangesFetcher_1 = require("./polling/fetchers/segmentChangesFetcher");
|
|
10
|
+
var AbstractSplitsCacheSync_1 = require("../storages/AbstractSplitsCacheSync");
|
|
13
11
|
/**
|
|
14
12
|
* Online SyncManager factory.
|
|
15
13
|
* Can be used for server-side API, and client-side API with or without multiple clients.
|
|
@@ -17,24 +15,21 @@ var segmentChangesFetcher_1 = require("./polling/fetchers/segmentChangesFetcher"
|
|
|
17
15
|
* @param pollingManagerFactory - allows to specialize the SyncManager for server-side or client-side API by passing
|
|
18
16
|
* `pollingManagerSSFactory` or `pollingManagerCSFactory` respectively.
|
|
19
17
|
* @param pushManagerFactory - optional to build a SyncManager with or without streaming support
|
|
20
|
-
* @param definitionChangesFetcherFactory - optional to replace the default split changes fetcher
|
|
21
18
|
*/
|
|
22
|
-
function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory
|
|
23
|
-
if (definitionFetcherFactory === void 0) { definitionFetcherFactory = splitChangesFetcher_1.splitChangesFetcherFactory; }
|
|
24
|
-
if (segmentFetcherFactory === void 0) { segmentFetcherFactory = function (params) { return (0, segmentChangesFetcher_1.segmentChangesFetcherFactory)(params.serviceApi.fetchSegmentChanges); }; }
|
|
19
|
+
function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
25
20
|
/**
|
|
26
21
|
* SyncManager factory for modular SDK
|
|
27
22
|
*/
|
|
28
23
|
return function (params) {
|
|
29
24
|
var settings = params.settings, _a = params.settings, log = _a.log, streamingEnabled = _a.streamingEnabled, syncEnabled = _a.sync.enabled, telemetryTracker = params.telemetryTracker, storage = params.storage, readiness = params.readiness;
|
|
30
25
|
/** Polling Manager */
|
|
31
|
-
var pollingManager = pollingManagerFactory && pollingManagerFactory(params
|
|
26
|
+
var pollingManager = pollingManagerFactory && pollingManagerFactory(params);
|
|
32
27
|
/** Push Manager */
|
|
33
28
|
var pushManager = syncEnabled && streamingEnabled && pollingManager && pushManagerFactory ?
|
|
34
29
|
pushManagerFactory(params, pollingManager) :
|
|
35
30
|
undefined;
|
|
36
31
|
/** Submitter Manager */
|
|
37
|
-
// It is not
|
|
32
|
+
// It is not inyected as push and polling managers, because at the moment it is required
|
|
38
33
|
var submitterManager = (0, submitterManager_1.submitterManagerFactory)(params);
|
|
39
34
|
/** Sync Manager logic */
|
|
40
35
|
function startPolling() {
|
|
@@ -82,7 +77,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory, def
|
|
|
82
77
|
if (startFirstTime) {
|
|
83
78
|
// Emits SDK_READY_FROM_CACHE
|
|
84
79
|
if (!cacheMetadata.initialCacheLoad) {
|
|
85
|
-
readiness.
|
|
80
|
+
readiness.splits.emit(constants_4.SDK_SPLITS_CACHE_LOADED, cacheMetadata);
|
|
86
81
|
}
|
|
87
82
|
}
|
|
88
83
|
// start syncing splits and segments
|
|
@@ -141,7 +136,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory, def
|
|
|
141
136
|
if (pushManager) {
|
|
142
137
|
if (pollingManager.isRunning()) {
|
|
143
138
|
// if doing polling, we must start the periodic fetch of data
|
|
144
|
-
if ((0,
|
|
139
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegmentsSync)(storage))
|
|
145
140
|
mySegmentsSyncTask.start();
|
|
146
141
|
}
|
|
147
142
|
else {
|
|
@@ -151,7 +146,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory, def
|
|
|
151
146
|
}
|
|
152
147
|
}
|
|
153
148
|
else {
|
|
154
|
-
if ((0,
|
|
149
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegmentsSync)(storage))
|
|
155
150
|
mySegmentsSyncTask.start();
|
|
156
151
|
}
|
|
157
152
|
}
|
package/cjs/utils/Backoff.js
CHANGED
|
@@ -27,26 +27,6 @@ var Backoff = /** @class */ (function () {
|
|
|
27
27
|
this.attempts++;
|
|
28
28
|
return delayInMillis;
|
|
29
29
|
};
|
|
30
|
-
/**
|
|
31
|
-
* Schedule a delayed call to `cb`
|
|
32
|
-
* @returns a promise that resolves/rejects with the result of the `cb` function, which must return a promise.
|
|
33
|
-
*/
|
|
34
|
-
Backoff.prototype.scheduleCallAsync = function () {
|
|
35
|
-
var _this = this;
|
|
36
|
-
var delayInMillis = Math.min(this.baseMillis * Math.pow(2, this.attempts), this.maxMillis);
|
|
37
|
-
if (this.timeoutID)
|
|
38
|
-
clearTimeout(this.timeoutID);
|
|
39
|
-
this.attempts++;
|
|
40
|
-
return new Promise(function (resolve, reject) {
|
|
41
|
-
_this.timeoutID = setTimeout(function () {
|
|
42
|
-
_this.timeoutID = undefined;
|
|
43
|
-
_this.cb().then(resolve, reject);
|
|
44
|
-
}, delayInMillis);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Reset the backoff attempts
|
|
49
|
-
*/
|
|
50
30
|
Backoff.prototype.reset = function () {
|
|
51
31
|
this.attempts = 0;
|
|
52
32
|
if (this.timeoutID) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateEvaluationOptions = exports.validateTrafficTypeExistence = exports.
|
|
3
|
+
exports.validateEvaluationOptions = exports.validateTrafficTypeExistence = exports.validateSplitExistence = exports.validateIfOperational = exports.validateIfReadyFromCache = exports.validateIfNotDestroyed = exports.validateTrafficType = exports.validateSplits = exports.validateSplit = exports.validateKey = exports.validateEventProperties = exports.validateEventValue = exports.validateEvent = exports.validateAttributes = exports.releaseApiKey = exports.validateAndTrackApiKey = exports.validateApiKey = void 0;
|
|
4
4
|
var apiKey_1 = require("./apiKey");
|
|
5
5
|
Object.defineProperty(exports, "validateApiKey", { enumerable: true, get: function () { return apiKey_1.validateApiKey; } });
|
|
6
6
|
Object.defineProperty(exports, "validateAndTrackApiKey", { enumerable: true, get: function () { return apiKey_1.validateAndTrackApiKey; } });
|
|
@@ -15,18 +15,18 @@ var eventProperties_1 = require("./eventProperties");
|
|
|
15
15
|
Object.defineProperty(exports, "validateEventProperties", { enumerable: true, get: function () { return eventProperties_1.validateEventProperties; } });
|
|
16
16
|
var key_1 = require("./key");
|
|
17
17
|
Object.defineProperty(exports, "validateKey", { enumerable: true, get: function () { return key_1.validateKey; } });
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "
|
|
20
|
-
var
|
|
21
|
-
Object.defineProperty(exports, "
|
|
18
|
+
var split_1 = require("./split");
|
|
19
|
+
Object.defineProperty(exports, "validateSplit", { enumerable: true, get: function () { return split_1.validateSplit; } });
|
|
20
|
+
var splits_1 = require("./splits");
|
|
21
|
+
Object.defineProperty(exports, "validateSplits", { enumerable: true, get: function () { return splits_1.validateSplits; } });
|
|
22
22
|
var trafficType_1 = require("./trafficType");
|
|
23
23
|
Object.defineProperty(exports, "validateTrafficType", { enumerable: true, get: function () { return trafficType_1.validateTrafficType; } });
|
|
24
24
|
var isOperational_1 = require("./isOperational");
|
|
25
25
|
Object.defineProperty(exports, "validateIfNotDestroyed", { enumerable: true, get: function () { return isOperational_1.validateIfNotDestroyed; } });
|
|
26
26
|
Object.defineProperty(exports, "validateIfReadyFromCache", { enumerable: true, get: function () { return isOperational_1.validateIfReadyFromCache; } });
|
|
27
27
|
Object.defineProperty(exports, "validateIfOperational", { enumerable: true, get: function () { return isOperational_1.validateIfOperational; } });
|
|
28
|
-
var
|
|
29
|
-
Object.defineProperty(exports, "
|
|
28
|
+
var splitExistence_1 = require("./splitExistence");
|
|
29
|
+
Object.defineProperty(exports, "validateSplitExistence", { enumerable: true, get: function () { return splitExistence_1.validateSplitExistence; } });
|
|
30
30
|
var trafficTypeExistence_1 = require("./trafficTypeExistence");
|
|
31
31
|
Object.defineProperty(exports, "validateTrafficTypeExistence", { enumerable: true, get: function () { return trafficTypeExistence_1.validateTrafficTypeExistence; } });
|
|
32
32
|
var eventProperties_2 = require("./eventProperties");
|
|
@@ -9,15 +9,15 @@ function validateIfNotDestroyed(log, readinessManager, method) {
|
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
exports.validateIfNotDestroyed = validateIfNotDestroyed;
|
|
12
|
-
function validateIfReadyFromCache(log, readinessManager, method) {
|
|
12
|
+
function validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames) {
|
|
13
13
|
if (readinessManager.isReadyFromCache())
|
|
14
14
|
return true;
|
|
15
|
-
log.warn(constants_1.CLIENT_NOT_READY_FROM_CACHE, [method]);
|
|
15
|
+
log.warn(constants_1.CLIENT_NOT_READY_FROM_CACHE, [method, featureFlagNameOrNames ? " for feature flag ".concat(featureFlagNameOrNames.toString()) : '']);
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
exports.validateIfReadyFromCache = validateIfReadyFromCache;
|
|
19
19
|
// Operational means that the SDK is ready to evaluate (not destroyed and ready from cache)
|
|
20
|
-
function validateIfOperational(log, readinessManager, method) {
|
|
21
|
-
return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method);
|
|
20
|
+
function validateIfOperational(log, readinessManager, method, featureFlagNameOrNames) {
|
|
21
|
+
return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames);
|
|
22
22
|
}
|
|
23
23
|
exports.validateIfOperational = validateIfOperational;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateSplit = void 0;
|
|
4
4
|
var constants_1 = require("../../logger/constants");
|
|
5
5
|
var lang_1 = require("../lang");
|
|
6
6
|
// include BOM and nbsp
|
|
7
7
|
var TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/;
|
|
8
|
-
function
|
|
8
|
+
function validateSplit(log, maybeSplit, method, item) {
|
|
9
9
|
if (item === void 0) { item = 'feature flag name'; }
|
|
10
|
-
if (
|
|
10
|
+
if (maybeSplit == undefined) { // eslint-disable-line eqeqeq
|
|
11
11
|
log.error(constants_1.ERROR_NULL, [method, item]);
|
|
12
12
|
}
|
|
13
|
-
else if (!(0, lang_1.isString)(
|
|
13
|
+
else if (!(0, lang_1.isString)(maybeSplit)) {
|
|
14
14
|
log.error(constants_1.ERROR_INVALID, [method, item]);
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
if (TRIMMABLE_SPACES_REGEX.test(
|
|
18
|
-
log.warn(constants_1.WARN_TRIMMING, [method, item,
|
|
19
|
-
|
|
17
|
+
if (TRIMMABLE_SPACES_REGEX.test(maybeSplit)) {
|
|
18
|
+
log.warn(constants_1.WARN_TRIMMING, [method, item, maybeSplit]);
|
|
19
|
+
maybeSplit = maybeSplit.trim();
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
21
|
+
if (maybeSplit.length > 0) {
|
|
22
|
+
return maybeSplit;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
log.error(constants_1.ERROR_EMPTY, [method, item]);
|
|
@@ -27,4 +27,4 @@ function validateDefinition(log, maybeDefinition, method, item) {
|
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
exports.
|
|
30
|
+
exports.validateSplit = validateSplit;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateSplitExistence = void 0;
|
|
4
4
|
var labels_1 = require("../labels");
|
|
5
5
|
var constants_1 = require("../../logger/constants");
|
|
6
6
|
/**
|
|
7
7
|
* This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
|
|
8
|
-
* But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a
|
|
8
|
+
* But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a split twice.
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
10
|
+
function validateSplitExistence(log, readinessManager, splitName, labelOrSplitObj, method) {
|
|
11
11
|
if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
|
|
12
|
-
if (
|
|
13
|
-
log.warn(constants_1.
|
|
12
|
+
if (labelOrSplitObj === labels_1.SPLIT_NOT_FOUND || labelOrSplitObj === labels_1.FALLBACK_SPLIT_NOT_FOUND || labelOrSplitObj == null) {
|
|
13
|
+
log.warn(constants_1.WARN_NOT_EXISTENT_SPLIT, [method, splitName]);
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
|
-
exports.
|
|
19
|
+
exports.validateSplitExistence = validateSplitExistence;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSplits = void 0;
|
|
4
|
+
var constants_1 = require("../../logger/constants");
|
|
5
|
+
var lang_1 = require("../lang");
|
|
6
|
+
var split_1 = require("./split");
|
|
7
|
+
function validateSplits(log, maybeSplits, method, listName, item) {
|
|
8
|
+
if (listName === void 0) { listName = 'feature flag names'; }
|
|
9
|
+
if (item === void 0) { item = 'feature flag name'; }
|
|
10
|
+
if (Array.isArray(maybeSplits) && maybeSplits.length > 0) {
|
|
11
|
+
var validatedArray_1 = [];
|
|
12
|
+
// Remove invalid values
|
|
13
|
+
maybeSplits.forEach(function (maybeSplit) {
|
|
14
|
+
var splitName = (0, split_1.validateSplit)(log, maybeSplit, method, item);
|
|
15
|
+
if (splitName)
|
|
16
|
+
validatedArray_1.push(splitName);
|
|
17
|
+
});
|
|
18
|
+
// Strip off duplicated values if we have valid split names then return
|
|
19
|
+
if (validatedArray_1.length)
|
|
20
|
+
return (0, lang_1.uniq)(validatedArray_1);
|
|
21
|
+
}
|
|
22
|
+
log.error(constants_1.ERROR_EMPTY_ARRAY, [method, listName]);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
exports.validateSplits = validateSplits;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FALLBACK_SPLIT_NOT_FOUND = exports.PREREQUISITES_NOT_MET = exports.UNSUPPORTED_MATCHER_TYPE = exports.NOT_IN_SPLIT = exports.SPLIT_ARCHIVED = exports.EXCEPTION = exports.SDK_NOT_READY = exports.SPLIT_NOT_FOUND = exports.NO_CONDITION_MATCH = exports.SPLIT_KILLED = void 0;
|
|
4
4
|
var fallbackTreatmentsCalculator_1 = require("../../evaluator/fallbackTreatmentsCalculator");
|
|
5
5
|
exports.SPLIT_KILLED = 'killed';
|
|
6
6
|
exports.NO_CONDITION_MATCH = 'default rule';
|
|
7
|
-
exports.
|
|
7
|
+
exports.SPLIT_NOT_FOUND = 'definition not found';
|
|
8
8
|
exports.SDK_NOT_READY = 'not ready';
|
|
9
9
|
exports.EXCEPTION = 'exception';
|
|
10
10
|
exports.SPLIT_ARCHIVED = 'archived';
|
|
11
11
|
exports.NOT_IN_SPLIT = 'not in split';
|
|
12
12
|
exports.UNSUPPORTED_MATCHER_TYPE = 'targeting rule type unsupported by sdk';
|
|
13
13
|
exports.PREREQUISITES_NOT_MET = 'prerequisites not met';
|
|
14
|
-
exports.
|
|
14
|
+
exports.FALLBACK_SPLIT_NOT_FOUND = fallbackTreatmentsCalculator_1.FALLBACK_PREFIX + exports.SPLIT_NOT_FOUND;
|
|
@@ -55,8 +55,6 @@ exports.base = {
|
|
|
55
55
|
streaming: 'https://streaming.split.io',
|
|
56
56
|
// Telemetry Server
|
|
57
57
|
telemetry: 'https://telemetry.split.io/api',
|
|
58
|
-
// Configs Server
|
|
59
|
-
configs: 'https://configs.split.io',
|
|
60
58
|
},
|
|
61
59
|
// Defines which kind of storage we should instantiate.
|
|
62
60
|
storage: undefined,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateFlagSets = exports.validateSplitFilters = void 0;
|
|
4
|
-
var
|
|
4
|
+
var splits_1 = require("../inputValidation/splits");
|
|
5
5
|
var constants_1 = require("../../logger/constants");
|
|
6
6
|
var objectAssign_1 = require("../lang/objectAssign");
|
|
7
7
|
var lang_1 = require("../lang");
|
|
@@ -45,7 +45,7 @@ function validateFilterType(maybeFilterType) {
|
|
|
45
45
|
*/
|
|
46
46
|
function validateSplitFilter(log, type, values, maxLength) {
|
|
47
47
|
// validate and remove invalid and duplicated values
|
|
48
|
-
var result = (0,
|
|
48
|
+
var result = (0, splits_1.validateSplits)(log, values, constants_1.LOG_PREFIX_SETTINGS, "".concat(type, " filter"), "".concat(type, " filter value"));
|
|
49
49
|
if (result) {
|
|
50
50
|
if (type === 'bySet') {
|
|
51
51
|
result = sanitizeFlagSets(log, result, constants_1.LOG_PREFIX_SETTINGS);
|
|
@@ -172,7 +172,7 @@ function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
172
172
|
}
|
|
173
173
|
exports.validateSplitFilters = validateSplitFilters;
|
|
174
174
|
function validateFlagSets(log, method, flagSets, flagSetsInConfig) {
|
|
175
|
-
var sets = (0,
|
|
175
|
+
var sets = (0, splits_1.validateSplits)(log, flagSets, method, 'flag sets', 'flag set');
|
|
176
176
|
var toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
|
|
177
177
|
if (flagSetsInConfig.length > 0) {
|
|
178
178
|
toReturn = toReturn.filter(function (flagSet) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.url = void 0;
|
|
4
|
-
var telemetryEndpointMatcher = /^\/v1\/
|
|
4
|
+
var telemetryEndpointMatcher = /^\/v1\/metrics\/(config|usage)/;
|
|
5
5
|
var eventsEndpointMatcher = /^\/(testImpressions|metrics|events)/;
|
|
6
|
-
var authEndpointMatcher = /^\/
|
|
6
|
+
var authEndpointMatcher = /^\/v2\/auth/;
|
|
7
7
|
var streamingEndpointMatcher = /^\/(sse|event-stream)/;
|
|
8
|
-
var configsEndpointMatcher = /^\/v1\/(configs|segmentChanges)/;
|
|
9
8
|
/**
|
|
10
9
|
* Get URL based on a given target (path).
|
|
11
10
|
* ATM, it is only used for testing purposes.
|
|
@@ -27,9 +26,6 @@ function url(settings, target) {
|
|
|
27
26
|
if (streamingEndpointMatcher.test(target)) {
|
|
28
27
|
return "".concat(settings.urls.streaming).concat(target);
|
|
29
28
|
}
|
|
30
|
-
if (configsEndpointMatcher.test(target)) {
|
|
31
|
-
return "".concat(settings.urls.configs).concat(target);
|
|
32
|
-
}
|
|
33
29
|
return "".concat(settings.urls.sdk).concat(target);
|
|
34
30
|
}
|
|
35
31
|
exports.url = url;
|
|
@@ -7,7 +7,7 @@ function match(log, matchingResult, bucketingKey, seed, treatments, label) {
|
|
|
7
7
|
return treatments ? // Feature flag
|
|
8
8
|
{
|
|
9
9
|
treatment: getTreatment(log, bucketingKey, seed, treatments),
|
|
10
|
-
label: label
|
|
10
|
+
label: label
|
|
11
11
|
} : // Rule-based segment
|
|
12
12
|
true;
|
|
13
13
|
}
|
|
@@ -20,7 +20,7 @@ export function conditionContext(log, matcherEvaluator, treatments, label, condi
|
|
|
20
20
|
// Whitelisting has more priority than traffic allocation, so we don't apply this filtering to those conditions.
|
|
21
21
|
if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation, key.bucketingKey, trafficAllocationSeed)) {
|
|
22
22
|
return {
|
|
23
|
-
|
|
23
|
+
treatment: undefined,
|
|
24
24
|
label: NOT_IN_SPLIT
|
|
25
25
|
};
|
|
26
26
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { isObject, isString } from '../../../utils/lang';
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var FallbackDiscardReason;
|
|
3
|
+
(function (FallbackDiscardReason) {
|
|
4
|
+
FallbackDiscardReason["FlagName"] = "Invalid flag name (max 100 chars, no spaces)";
|
|
5
|
+
FallbackDiscardReason["Treatment"] = "Invalid treatment (max 100 chars and must match pattern)";
|
|
6
|
+
})(FallbackDiscardReason || (FallbackDiscardReason = {}));
|
|
4
7
|
var TREATMENT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
|
|
5
8
|
export function isValidFlagName(name) {
|
|
6
9
|
return name.length <= 100 && !name.includes(' ');
|
|
@@ -16,7 +19,7 @@ function sanitizeGlobal(logger, treatment) {
|
|
|
16
19
|
if (treatment === undefined)
|
|
17
20
|
return undefined;
|
|
18
21
|
if (!isValidTreatment(treatment)) {
|
|
19
|
-
logger.error("Fallback treatments - Discarded fallback: ".concat(
|
|
22
|
+
logger.error("Fallback treatments - Discarded fallback: ".concat(FallbackDiscardReason.Treatment));
|
|
20
23
|
return undefined;
|
|
21
24
|
}
|
|
22
25
|
return treatment;
|
|
@@ -28,11 +31,11 @@ function sanitizeByFlag(logger, byFlagFallbacks) {
|
|
|
28
31
|
Object.keys(byFlagFallbacks).forEach(function (flag) {
|
|
29
32
|
var t = byFlagFallbacks[flag];
|
|
30
33
|
if (!isValidFlagName(flag)) {
|
|
31
|
-
logger.error("Fallback treatments - Discarded flag '".concat(flag, "': ").concat(
|
|
34
|
+
logger.error("Fallback treatments - Discarded flag '".concat(flag, "': ").concat(FallbackDiscardReason.FlagName));
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
34
37
|
if (!isValidTreatment(t)) {
|
|
35
|
-
logger.error("Fallback treatments - Discarded treatment for flag '".concat(flag, "': ").concat(
|
|
38
|
+
logger.error("Fallback treatments - Discarded treatment for flag '".concat(flag, "': ").concat(FallbackDiscardReason.Treatment));
|
|
36
39
|
return;
|
|
37
40
|
}
|
|
38
41
|
sanitizedByFlag[flag] = t;
|
package/esm/evaluator/index.js
CHANGED
|
@@ -1,62 +1,57 @@
|
|
|
1
1
|
import { engineParser } from './Engine';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
|
-
import { EXCEPTION,
|
|
3
|
+
import { EXCEPTION, SPLIT_NOT_FOUND } from '../utils/labels';
|
|
4
4
|
import { CONTROL } from '../utils/constants';
|
|
5
5
|
import { returnSetsUnion, setToArray } from '../utils/lang/sets';
|
|
6
6
|
import { WARN_FLAGSET_WITHOUT_FLAGS } from '../logger/constants';
|
|
7
|
-
|
|
8
|
-
var EVALUATION_EXCEPTION = {
|
|
7
|
+
var treatmentException = {
|
|
9
8
|
treatment: CONTROL,
|
|
10
9
|
label: EXCEPTION,
|
|
11
10
|
config: null
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
treatment: CONTROL,
|
|
15
|
-
label: DEFINITION_NOT_FOUND,
|
|
16
|
-
config: null
|
|
17
|
-
};
|
|
18
|
-
function treatmentsException(definitionNames) {
|
|
12
|
+
function treatmentsException(splitNames) {
|
|
19
13
|
var evaluations = {};
|
|
20
|
-
|
|
21
|
-
evaluations[
|
|
14
|
+
splitNames.forEach(function (splitName) {
|
|
15
|
+
evaluations[splitName] = treatmentException;
|
|
22
16
|
});
|
|
23
17
|
return evaluations;
|
|
24
18
|
}
|
|
25
|
-
export function evaluateFeature(log, key,
|
|
26
|
-
var
|
|
19
|
+
export function evaluateFeature(log, key, splitName, attributes, storage, options) {
|
|
20
|
+
var parsedSplit;
|
|
27
21
|
try {
|
|
28
|
-
|
|
22
|
+
parsedSplit = storage.splits.getSplit(splitName);
|
|
29
23
|
}
|
|
30
24
|
catch (e) {
|
|
31
|
-
// Exception on sync storage. Not possible ATM with InMemory and InLocal storages.
|
|
32
|
-
return
|
|
25
|
+
// Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
|
|
26
|
+
return treatmentException;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Exception on async storage. For example, when the storage is redis or
|
|
28
|
+
if (thenable(parsedSplit)) {
|
|
29
|
+
return parsedSplit.then(function (split) { return getEvaluation(log, key, split, attributes, storage, options); }).catch(
|
|
30
|
+
// Exception on async `getSplit` storage. For example, when the storage is redis or
|
|
38
31
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
39
|
-
function () { return
|
|
40
|
-
|
|
32
|
+
function () { return treatmentException; });
|
|
33
|
+
}
|
|
34
|
+
return getEvaluation(log, key, parsedSplit, attributes, storage, options);
|
|
41
35
|
}
|
|
42
|
-
export function evaluateFeatures(log, key,
|
|
43
|
-
var
|
|
36
|
+
export function evaluateFeatures(log, key, splitNames, attributes, storage, options) {
|
|
37
|
+
var parsedSplits;
|
|
44
38
|
try {
|
|
45
|
-
|
|
39
|
+
parsedSplits = storage.splits.getSplits(splitNames);
|
|
46
40
|
}
|
|
47
41
|
catch (e) {
|
|
48
|
-
// Exception on sync storage. Not possible ATM with InMemory and InLocal storages.
|
|
49
|
-
return treatmentsException(
|
|
42
|
+
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
|
|
43
|
+
return treatmentsException(splitNames);
|
|
50
44
|
}
|
|
51
|
-
return thenable(
|
|
52
|
-
|
|
53
|
-
.catch(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
return thenable(parsedSplits) ?
|
|
46
|
+
parsedSplits.then(function (splits) { return getEvaluations(log, key, splitNames, splits, attributes, storage, options); })
|
|
47
|
+
.catch(function () {
|
|
48
|
+
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
49
|
+
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
50
|
+
return treatmentsException(splitNames);
|
|
51
|
+
}) :
|
|
52
|
+
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage, options);
|
|
58
53
|
}
|
|
59
|
-
export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
|
|
54
|
+
export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method, options) {
|
|
60
55
|
var storedFlagNames;
|
|
61
56
|
function evaluate(featureFlagsByFlagSets) {
|
|
62
57
|
var featureFlags = new Set();
|
|
@@ -70,12 +65,12 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
|
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
67
|
return featureFlags.size ?
|
|
73
|
-
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage) :
|
|
68
|
+
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage, options) :
|
|
74
69
|
{};
|
|
75
70
|
}
|
|
76
71
|
// get features by flag sets
|
|
77
72
|
try {
|
|
78
|
-
storedFlagNames = storage.
|
|
73
|
+
storedFlagNames = storage.splits.getNamesByFlagSets(flagSets);
|
|
79
74
|
}
|
|
80
75
|
catch (e) {
|
|
81
76
|
// return empty evaluations
|
|
@@ -84,51 +79,52 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
|
|
|
84
79
|
// evaluate related features
|
|
85
80
|
return thenable(storedFlagNames) ?
|
|
86
81
|
storedFlagNames.then(function (storedFlagNames) { return evaluate(storedFlagNames); })
|
|
87
|
-
.catch(function () {
|
|
82
|
+
.catch(function () {
|
|
83
|
+
return {};
|
|
84
|
+
}) :
|
|
88
85
|
evaluate(storedFlagNames);
|
|
89
86
|
}
|
|
90
|
-
function getEvaluation(log, key,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
function getEvaluation(log, key, splitJSON, attributes, storage, options) {
|
|
88
|
+
var evaluation = {
|
|
89
|
+
treatment: CONTROL,
|
|
90
|
+
label: SPLIT_NOT_FOUND,
|
|
91
|
+
config: null
|
|
92
|
+
};
|
|
93
|
+
if (splitJSON) {
|
|
94
|
+
var split = engineParser(log, splitJSON, storage);
|
|
95
|
+
evaluation = split.getTreatment(key, attributes, evaluateFeature);
|
|
96
|
+
// If the storage is async and the evaluated flag uses segments or dependencies, evaluation is thenable
|
|
97
|
+
if (thenable(evaluation)) {
|
|
98
|
+
return evaluation.then(function (result) {
|
|
99
|
+
result.changeNumber = splitJSON.changeNumber;
|
|
100
|
+
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
101
|
+
// @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
|
|
102
|
+
result.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || splitJSON.impressionsDisabled;
|
|
103
|
+
return result;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
evaluation.changeNumber = splitJSON.changeNumber;
|
|
108
|
+
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
109
|
+
// @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
|
|
110
|
+
evaluation.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || splitJSON.impressionsDisabled;
|
|
111
|
+
}
|
|
97
112
|
}
|
|
98
|
-
return
|
|
113
|
+
return evaluation;
|
|
99
114
|
}
|
|
100
|
-
function getEvaluations(log, key,
|
|
115
|
+
function getEvaluations(log, key, splitNames, splits, attributes, storage, options) {
|
|
101
116
|
var result = {};
|
|
102
117
|
var thenables = [];
|
|
103
|
-
|
|
104
|
-
var evaluation = getEvaluation(log, key,
|
|
105
|
-
thenable(evaluation)
|
|
118
|
+
splitNames.forEach(function (splitName) {
|
|
119
|
+
var evaluation = getEvaluation(log, key, splits[splitName], attributes, storage, options);
|
|
120
|
+
if (thenable(evaluation)) {
|
|
106
121
|
thenables.push(evaluation.then(function (res) {
|
|
107
|
-
result[
|
|
108
|
-
}))
|
|
109
|
-
|
|
122
|
+
result[splitName] = res;
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
result[splitName] = evaluation;
|
|
127
|
+
}
|
|
110
128
|
});
|
|
111
129
|
return thenables.length > 0 ? Promise.all(thenables).then(function () { return result; }) : result;
|
|
112
130
|
}
|
|
113
|
-
export function evaluateDefaultTreatment(definitionName, storage) {
|
|
114
|
-
var definition;
|
|
115
|
-
try {
|
|
116
|
-
definition = storage.definitions.get(definitionName);
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
return EVALUATION_EXCEPTION;
|
|
120
|
-
}
|
|
121
|
-
return thenable(definition) ?
|
|
122
|
-
definition.then(getDefaultTreatment).catch(function () { return EVALUATION_EXCEPTION; }) :
|
|
123
|
-
getDefaultTreatment(definition);
|
|
124
|
-
}
|
|
125
|
-
function getDefaultTreatment(definition) {
|
|
126
|
-
if (definition) {
|
|
127
|
-
return {
|
|
128
|
-
treatment: definition.defaultTreatment,
|
|
129
|
-
label: NO_CONDITION_MATCH,
|
|
130
|
-
definition: definition,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return EVALUATION_DEFINITION_NOT_FOUND;
|
|
134
|
-
}
|
package/esm/listeners/browser.js
CHANGED
|
@@ -10,8 +10,7 @@ var EVENT_NAME = 'for visibilitychange and pagehide events.';
|
|
|
10
10
|
* We'll listen for events over the window object.
|
|
11
11
|
*/
|
|
12
12
|
var BrowserSignalListener = /** @class */ (function () {
|
|
13
|
-
function BrowserSignalListener(
|
|
14
|
-
var syncManager = _a.syncManager, settings = _a.settings, storage = _a.storage, serviceApi = _a.serviceApi;
|
|
13
|
+
function BrowserSignalListener(syncManager, settings, storage, serviceApi) {
|
|
15
14
|
this.syncManager = syncManager;
|
|
16
15
|
this.settings = settings;
|
|
17
16
|
this.storage = storage;
|