@splitsoftware/splitio-commons 1.16.1-rc.1 → 1.16.1-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +4 -0
- package/cjs/logger/constants.js +5 -4
- package/cjs/logger/messages/info.js +2 -1
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/readiness/readinessManager.js +7 -12
- package/cjs/services/splitApi.js +5 -9
- package/cjs/storages/AbstractSegmentsCacheSync.js +41 -12
- package/cjs/storages/AbstractSplitsCacheAsync.js +2 -2
- package/cjs/storages/AbstractSplitsCacheSync.js +7 -5
- package/cjs/storages/KeyBuilder.js +0 -3
- package/cjs/storages/KeyBuilderCS.js +6 -0
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +29 -52
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +4 -16
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +9 -40
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +6 -15
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +4 -11
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +33 -51
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +14 -20
- package/cjs/sync/streaming/AuthClient/index.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +3 -6
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +15 -9
- package/cjs/sync/streaming/constants.js +3 -4
- package/cjs/sync/streaming/parseUtils.js +14 -9
- package/cjs/sync/streaming/pushManager.js +29 -55
- package/cjs/sync/submitters/telemetrySubmitter.js +0 -2
- package/cjs/sync/syncManagerOnline.js +14 -24
- package/cjs/utils/constants/index.js +4 -5
- package/cjs/utils/settingsValidation/index.js +1 -5
- package/esm/logger/constants.js +2 -1
- package/esm/logger/messages/info.js +2 -1
- package/esm/logger/messages/warn.js +1 -1
- package/esm/readiness/readinessManager.js +7 -12
- package/esm/services/splitApi.js +6 -10
- package/esm/storages/AbstractSegmentsCacheSync.js +41 -12
- package/esm/storages/AbstractSplitsCacheAsync.js +2 -2
- package/esm/storages/AbstractSplitsCacheSync.js +5 -3
- package/esm/storages/KeyBuilder.js +0 -3
- package/esm/storages/KeyBuilderCS.js +6 -0
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +29 -52
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -17
- package/esm/storages/inMemory/MySegmentsCacheInMemory.js +9 -40
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -16
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +4 -11
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/esm/sync/polling/pollingManagerCS.js +34 -52
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +12 -18
- package/esm/sync/streaming/AuthClient/index.js +1 -1
- package/esm/sync/streaming/SSEHandler/index.js +4 -7
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +15 -9
- package/esm/sync/streaming/constants.js +2 -3
- package/esm/sync/streaming/parseUtils.js +12 -8
- package/esm/sync/streaming/pushManager.js +32 -57
- package/esm/sync/submitters/telemetrySubmitter.js +0 -2
- package/esm/sync/syncManagerOnline.js +15 -25
- package/esm/utils/constants/index.js +2 -3
- package/esm/utils/settingsValidation/index.js +1 -5
- package/package.json +1 -1
- package/src/dtos/types.ts +7 -8
- package/src/logger/constants.ts +2 -1
- package/src/logger/messages/info.ts +2 -1
- package/src/logger/messages/warn.ts +1 -1
- package/src/readiness/readinessManager.ts +7 -9
- package/src/readiness/types.ts +0 -1
- package/src/services/splitApi.ts +7 -12
- package/src/services/splitHttpClient.ts +1 -1
- package/src/services/types.ts +2 -3
- package/src/storages/AbstractSegmentsCacheSync.ts +53 -12
- package/src/storages/AbstractSplitsCacheAsync.ts +2 -2
- package/src/storages/AbstractSplitsCacheSync.ts +7 -5
- package/src/storages/KeyBuilder.ts +0 -3
- package/src/storages/KeyBuilderCS.ts +9 -0
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +26 -56
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +5 -20
- package/src/storages/inMemory/MySegmentsCacheInMemory.ts +10 -44
- package/src/storages/inMemory/SplitsCacheInMemory.ts +7 -13
- package/src/storages/types.ts +10 -8
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +7 -14
- package/src/sync/polling/fetchers/segmentChangesFetcher.ts +1 -1
- package/src/sync/polling/fetchers/types.ts +2 -2
- package/src/sync/polling/pollingManagerCS.ts +29 -61
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +12 -13
- package/src/sync/polling/types.ts +8 -8
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +17 -18
- package/src/sync/streaming/AuthClient/index.ts +1 -1
- package/src/sync/streaming/SSEClient/index.ts +4 -6
- package/src/sync/streaming/SSEHandler/index.ts +5 -9
- package/src/sync/streaming/SSEHandler/types.ts +13 -25
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +17 -12
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/types.ts +2 -2
- package/src/sync/streaming/constants.ts +2 -3
- package/src/sync/streaming/parseUtils.ts +19 -11
- package/src/sync/streaming/pushManager.ts +38 -68
- package/src/sync/streaming/types.ts +11 -13
- package/src/sync/submitters/telemetrySubmitter.ts +0 -2
- package/src/sync/submitters/types.ts +3 -6
- package/src/sync/syncManagerOnline.ts +11 -19
- package/src/types.ts +1 -26
- package/src/utils/constants/index.ts +2 -3
- package/src/utils/settingsValidation/index.ts +1 -5
- package/types/dtos/types.d.ts +7 -8
- package/types/logger/constants.d.ts +2 -1
- package/types/readiness/types.d.ts +0 -1
- package/types/services/decorateHeaders.d.ts +2 -0
- package/types/services/splitApi.d.ts +1 -1
- package/types/services/splitHttpClient.d.ts +1 -1
- package/types/services/types.d.ts +2 -3
- package/types/storages/AbstractSegmentsCacheSync.d.ts +9 -11
- package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
- package/types/storages/AbstractSplitsCacheSync.d.ts +4 -4
- package/types/storages/KeyBuilder.d.ts +0 -1
- package/types/storages/KeyBuilderCS.d.ts +2 -0
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +2 -12
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +1 -1
- package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +3 -9
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -2
- package/types/storages/types.d.ts +8 -7
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +2 -2
- package/types/sync/polling/fetchers/types.d.ts +2 -2
- package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +4 -3
- package/types/sync/polling/types.d.ts +8 -12
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +3 -2
- package/types/sync/streaming/SSEHandler/types.d.ts +13 -22
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +2 -3
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +2 -1
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +3 -2
- package/types/sync/streaming/UpdateWorkers/types.d.ts +2 -2
- package/types/sync/streaming/constants.d.ts +2 -3
- package/types/sync/streaming/parseUtils.d.ts +4 -5
- package/types/sync/streaming/pushManager.d.ts +0 -2
- package/types/sync/streaming/pushManagerCS_Spec1_3.d.ts +9 -0
- package/types/sync/streaming/pushManager_Spec1_3.d.ts +9 -0
- package/types/sync/streaming/types.d.ts +9 -10
- package/types/sync/submitters/types.d.ts +3 -6
- package/types/types.d.ts +0 -25
- package/types/utils/constants/index.d.ts +2 -3
- package/types/utils/settingsValidation/index.d.ts +0 -2
package/CHANGES.txt
CHANGED
package/cjs/logger/constants.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = void 0;
|
|
3
|
+
exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.ENGINE_MATCHER_RESULT = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_SEGMENTS = exports.SYNC_SPLITS_REMOVED = exports.SYNC_SPLITS_NEW = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
|
+
exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.WARN_LOWERCASE_FLAGSET = exports.WARN_INVALID_FLAGSET = exports.STREAMING_PARSING_SPLIT_UPDATE = exports.STREAMING_PARSING_MEMBERSHIP_UPDATE = exports.WARN_SDK_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = void 0;
|
|
5
|
+
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
8
8
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -40,6 +40,7 @@ exports.IMPRESSION = 102;
|
|
|
40
40
|
exports.IMPRESSION_QUEUEING = 103;
|
|
41
41
|
exports.NEW_SHARED_CLIENT = 104;
|
|
42
42
|
exports.NEW_FACTORY = 105;
|
|
43
|
+
exports.POLLING_SMART_PAUSING = 106;
|
|
43
44
|
exports.POLLING_START = 107;
|
|
44
45
|
exports.POLLING_STOP = 108;
|
|
45
46
|
exports.SYNC_SPLITS_FETCH_RETRY = 109;
|
|
@@ -81,7 +82,7 @@ exports.WARN_SPLITS_FILTER_IGNORED = 219;
|
|
|
81
82
|
exports.WARN_SPLITS_FILTER_INVALID = 220;
|
|
82
83
|
exports.WARN_SPLITS_FILTER_EMPTY = 221;
|
|
83
84
|
exports.WARN_SDK_KEY = 222;
|
|
84
|
-
exports.
|
|
85
|
+
exports.STREAMING_PARSING_MEMBERSHIP_UPDATE = 223;
|
|
85
86
|
exports.STREAMING_PARSING_SPLIT_UPDATE = 224;
|
|
86
87
|
exports.WARN_INVALID_FLAGSET = 225;
|
|
87
88
|
exports.WARN_LOWERCASE_FLAGSET = 226;
|
|
@@ -20,10 +20,11 @@ exports.codesInfo = warn_1.codesWarn.concat([
|
|
|
20
20
|
[c.USER_CONSENT_NOT_UPDATED, 'UserConsent: call had no effect because it was the current consent status (%s).'],
|
|
21
21
|
[c.USER_CONSENT_INITIAL, 'Starting the SDK with %s user consent. No data will be sent.'],
|
|
22
22
|
// synchronizer
|
|
23
|
+
[c.POLLING_SMART_PAUSING, c.LOG_PREFIX_SYNC_POLLING + 'Turning segments data polling %s.'],
|
|
23
24
|
[c.POLLING_START, c.LOG_PREFIX_SYNC_POLLING + 'Starting polling'],
|
|
24
25
|
[c.POLLING_STOP, c.LOG_PREFIX_SYNC_POLLING + 'Stopping polling'],
|
|
25
26
|
[c.SYNC_SPLITS_FETCH_RETRY, c.LOG_PREFIX_SYNC_SPLITS + 'Retrying download of feature flags #%s. Reason: %s'],
|
|
26
|
-
[c.SUBMITTERS_PUSH_FULL_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full %s queue and
|
|
27
|
+
[c.SUBMITTERS_PUSH_FULL_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full %s queue and resetting timer.'],
|
|
27
28
|
[c.SUBMITTERS_PUSH, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Pushing %s.'],
|
|
28
29
|
[c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds, and connecting streaming in %s seconds.'],
|
|
29
30
|
[c.STREAMING_RECONNECT, c.LOG_PREFIX_SYNC_STREAMING + 'Attempting to reconnect streaming in %s seconds.'],
|
|
@@ -34,7 +34,7 @@ exports.codesWarn = error_1.codesError.concat([
|
|
|
34
34
|
[c.WARN_SPLITS_FILTER_INVALID, c.LOG_PREFIX_SETTINGS + ': feature flag filter at position %s is invalid. It must be an object with a valid filter type ("bySet", "byName" or "byPrefix") and a list of "values".'],
|
|
35
35
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': feature flag filter configuration must be a non-empty array of filter objects.'],
|
|
36
36
|
[c.WARN_SDK_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
37
|
-
[c.
|
|
37
|
+
[c.STREAMING_PARSING_MEMBERSHIP_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching Memberships due to an error processing %s notification: %s'],
|
|
38
38
|
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing SPLIT_UPDATE notification: %s'],
|
|
39
39
|
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
40
40
|
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
|
@@ -9,16 +9,17 @@ function splitsEventEmitterFactory(EventEmitter) {
|
|
|
9
9
|
splitsCacheLoaded: false,
|
|
10
10
|
});
|
|
11
11
|
// `isSplitKill` condition avoids an edge-case of wrongly emitting SDK_READY if:
|
|
12
|
-
// - `/
|
|
12
|
+
// - `/memberships` fetch and SPLIT_KILL occurs before `/splitChanges` fetch, and
|
|
13
13
|
// - storage has cached splits (for which case `splitsStorage.killLocally` can return true)
|
|
14
14
|
splitsEventEmitter.on(constants_1.SDK_SPLITS_ARRIVED, function (isSplitKill) { if (!isSplitKill)
|
|
15
15
|
splitsEventEmitter.splitsArrived = true; });
|
|
16
16
|
splitsEventEmitter.once(constants_1.SDK_SPLITS_CACHE_LOADED, function () { splitsEventEmitter.splitsCacheLoaded = true; });
|
|
17
17
|
return splitsEventEmitter;
|
|
18
18
|
}
|
|
19
|
-
function segmentsEventEmitterFactory(EventEmitter
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
function segmentsEventEmitterFactory(EventEmitter) {
|
|
20
|
+
var segmentsEventEmitter = (0, objectAssign_1.objectAssign)(new EventEmitter(), {
|
|
21
|
+
segmentsArrived: false
|
|
22
|
+
});
|
|
22
23
|
segmentsEventEmitter.once(constants_1.SDK_SEGMENTS_ARRIVED, function () { segmentsEventEmitter.segmentsArrived = true; });
|
|
23
24
|
return segmentsEventEmitter;
|
|
24
25
|
}
|
|
@@ -27,9 +28,8 @@ function segmentsEventEmitterFactory(EventEmitter, segmentsArrived) {
|
|
|
27
28
|
*/
|
|
28
29
|
function readinessManagerFactory(EventEmitter, settings, splits) {
|
|
29
30
|
if (splits === void 0) { splits = splitsEventEmitterFactory(EventEmitter); }
|
|
30
|
-
var
|
|
31
|
+
var readyTimeout = settings.startup.readyTimeout;
|
|
31
32
|
var segments = segmentsEventEmitterFactory(EventEmitter);
|
|
32
|
-
var largeSegments = largeSegmentsEnabled ? segmentsEventEmitterFactory(EventEmitter, !waitForLargeSegments) : undefined;
|
|
33
33
|
var gate = new EventEmitter();
|
|
34
34
|
// emit SDK_READY_FROM_CACHE
|
|
35
35
|
var isReadyFromCache = false;
|
|
@@ -53,8 +53,6 @@ function readinessManagerFactory(EventEmitter, settings, splits) {
|
|
|
53
53
|
var isReady = false;
|
|
54
54
|
splits.on(constants_1.SDK_SPLITS_ARRIVED, checkIsReadyOrUpdate);
|
|
55
55
|
segments.on(constants_1.SDK_SEGMENTS_ARRIVED, checkIsReadyOrUpdate);
|
|
56
|
-
if (largeSegments)
|
|
57
|
-
largeSegments.on(constants_1.SDK_SEGMENTS_ARRIVED, checkIsReadyOrUpdate);
|
|
58
56
|
var isDestroyed = false;
|
|
59
57
|
function checkIsReadyFromCache() {
|
|
60
58
|
isReadyFromCache = true;
|
|
@@ -80,7 +78,7 @@ function readinessManagerFactory(EventEmitter, settings, splits) {
|
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
80
|
else {
|
|
83
|
-
if (splits.splitsArrived && segments.segmentsArrived
|
|
81
|
+
if (splits.splitsArrived && segments.segmentsArrived) {
|
|
84
82
|
clearTimeout(readyTimeoutId);
|
|
85
83
|
isReady = true;
|
|
86
84
|
try {
|
|
@@ -97,7 +95,6 @@ function readinessManagerFactory(EventEmitter, settings, splits) {
|
|
|
97
95
|
return {
|
|
98
96
|
splits: splits,
|
|
99
97
|
segments: segments,
|
|
100
|
-
largeSegments: largeSegments,
|
|
101
98
|
gate: gate,
|
|
102
99
|
shared: function () {
|
|
103
100
|
refCount++;
|
|
@@ -112,8 +109,6 @@ function readinessManagerFactory(EventEmitter, settings, splits) {
|
|
|
112
109
|
destroy: function () {
|
|
113
110
|
isDestroyed = true;
|
|
114
111
|
segments.removeAllListeners();
|
|
115
|
-
if (largeSegments)
|
|
116
|
-
largeSegments.removeAllListeners();
|
|
117
112
|
gate.removeAllListeners();
|
|
118
113
|
clearTimeout(readyTimeoutId);
|
|
119
114
|
if (refCount > 0)
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -54,19 +54,15 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
54
54
|
var url = urls.sdk + "/segmentChanges/" + segmentName + "?since=" + since + (till ? '&till=' + till : '');
|
|
55
55
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.SEGMENT));
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
fetchMemberships: function (userMatchingKey, noCache) {
|
|
58
58
|
/**
|
|
59
59
|
* URI encoding of user keys in order to:
|
|
60
|
-
* - avoid 400 responses (due to URI malformed). E.g.: '/api/
|
|
61
|
-
* - avoid 404 responses. E.g.: '/api/
|
|
60
|
+
* - avoid 400 responses (due to URI malformed). E.g.: '/api/memberships/%'
|
|
61
|
+
* - avoid 404 responses. E.g.: '/api/memberships/foo/bar'
|
|
62
62
|
* - match user keys with special characters. E.g.: 'foo%bar', 'foo/bar'
|
|
63
63
|
*/
|
|
64
|
-
var url = urls.sdk + "/
|
|
65
|
-
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.
|
|
66
|
-
},
|
|
67
|
-
fetchMyLargeSegments: function (userMatchingKey, noCache) {
|
|
68
|
-
var url = urls.sdk + "/myLargeSegments/" + encodeURIComponent(userMatchingKey);
|
|
69
|
-
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.MY_LARGE_SEGMENT));
|
|
64
|
+
var url = urls.sdk + "/memberships/" + encodeURIComponent(userMatchingKey);
|
|
65
|
+
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.MEMBERSHIPS));
|
|
70
66
|
},
|
|
71
67
|
/**
|
|
72
68
|
* Post events.
|
|
@@ -9,25 +9,54 @@ var AbstractSegmentsCacheSync = /** @class */ (function () {
|
|
|
9
9
|
function AbstractSegmentsCacheSync() {
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* For client-side synchronizer: the method is not used.
|
|
14
|
-
*/
|
|
15
|
-
AbstractSegmentsCacheSync.prototype.registerSegments = function (names) { return false; };
|
|
16
|
-
/**
|
|
17
|
-
* For server-side synchronizer: set the change number of `name` segment.
|
|
18
|
-
* For client-side synchronizer: the method is not used.
|
|
12
|
+
* clear the cache.
|
|
19
13
|
*/
|
|
20
|
-
AbstractSegmentsCacheSync.prototype.
|
|
14
|
+
AbstractSegmentsCacheSync.prototype.clear = function () {
|
|
15
|
+
this.resetSegments({});
|
|
16
|
+
};
|
|
21
17
|
/**
|
|
22
|
-
* For server-side synchronizer:
|
|
18
|
+
* For server-side synchronizer: add the given list of segments to the cache, with an empty list of keys. The segments that already exist are not modified.
|
|
23
19
|
* For client-side synchronizer: the method is not used.
|
|
24
20
|
*/
|
|
25
|
-
AbstractSegmentsCacheSync.prototype.
|
|
21
|
+
AbstractSegmentsCacheSync.prototype.registerSegments = function (names) { return false; };
|
|
26
22
|
/**
|
|
27
23
|
* For server-side synchronizer: the method is not used.
|
|
28
|
-
* For client-side synchronizer:
|
|
24
|
+
* For client-side synchronizer: it resets or updates the cache.
|
|
29
25
|
*/
|
|
30
|
-
AbstractSegmentsCacheSync.prototype.resetSegments = function (
|
|
26
|
+
AbstractSegmentsCacheSync.prototype.resetSegments = function (segmentsData) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
this.setChangeNumber(undefined, segmentsData.cn);
|
|
29
|
+
var _a = segmentsData, added = _a.added, removed = _a.removed;
|
|
30
|
+
if (added && removed) {
|
|
31
|
+
var isDiff_1 = false;
|
|
32
|
+
added.forEach(function (segment) {
|
|
33
|
+
isDiff_1 = _this.addToSegment(segment) || isDiff_1;
|
|
34
|
+
});
|
|
35
|
+
removed.forEach(function (segment) {
|
|
36
|
+
isDiff_1 = _this.removeFromSegment(segment) || isDiff_1;
|
|
37
|
+
});
|
|
38
|
+
return isDiff_1;
|
|
39
|
+
}
|
|
40
|
+
var names = (segmentsData.k || []).map(function (s) { return s.n; }).sort();
|
|
41
|
+
var storedSegmentKeys = this.getRegisteredSegments().sort();
|
|
42
|
+
// Extreme fast => everything is empty
|
|
43
|
+
if (!names.length && !storedSegmentKeys.length)
|
|
44
|
+
return false;
|
|
45
|
+
var index = 0;
|
|
46
|
+
while (index < names.length && index < storedSegmentKeys.length && names[index] === storedSegmentKeys[index])
|
|
47
|
+
index++;
|
|
48
|
+
// Quick path => no changes
|
|
49
|
+
if (index === names.length && index === storedSegmentKeys.length)
|
|
50
|
+
return false;
|
|
51
|
+
// Slowest path => add and/or remove segments
|
|
52
|
+
for (var removeIndex = index; removeIndex < storedSegmentKeys.length; removeIndex++) {
|
|
53
|
+
this.removeFromSegment(storedSegmentKeys[removeIndex]);
|
|
54
|
+
}
|
|
55
|
+
for (var addIndex = index; addIndex < names.length; addIndex++) {
|
|
56
|
+
this.addToSegment(names[addIndex]);
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
31
60
|
return AbstractSegmentsCacheSync;
|
|
32
61
|
}());
|
|
33
62
|
exports.AbstractSegmentsCacheSync = AbstractSegmentsCacheSync;
|
|
@@ -9,9 +9,9 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
9
9
|
var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
10
10
|
function AbstractSplitsCacheAsync() {
|
|
11
11
|
}
|
|
12
|
-
// @TODO revisit segment-related methods ('
|
|
12
|
+
// @TODO revisit segment-related methods ('usesSegments', 'getRegisteredSegments', 'registerSegments')
|
|
13
13
|
// noop, just keeping the interface. This is used by standalone client-side API only, and so only implemented by InMemory and InLocalStorage.
|
|
14
|
-
AbstractSplitsCacheAsync.prototype.
|
|
14
|
+
AbstractSplitsCacheAsync.prototype.usesSegments = function () {
|
|
15
15
|
return Promise.resolve(true);
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.usesSegments = exports.AbstractSplitsCacheSync = void 0;
|
|
4
4
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
5
|
+
var constants_1 = require("../utils/constants");
|
|
5
6
|
/**
|
|
6
7
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
7
8
|
* to minimize the effort required to implement this interface.
|
|
@@ -62,17 +63,18 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
62
63
|
exports.AbstractSplitsCacheSync = AbstractSplitsCacheSync;
|
|
63
64
|
/**
|
|
64
65
|
* Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
|
|
65
|
-
* This util is intended to simplify the implementation of `splitsCache::
|
|
66
|
+
* This util is intended to simplify the implementation of `splitsCache::usesSegments` method
|
|
66
67
|
*/
|
|
67
|
-
function
|
|
68
|
+
function usesSegments(split) {
|
|
68
69
|
var conditions = split.conditions || [];
|
|
69
70
|
for (var i = 0; i < conditions.length; i++) {
|
|
70
71
|
var matchers = conditions[i].matcherGroup.matchers;
|
|
71
72
|
for (var j = 0; j < matchers.length; j++) {
|
|
72
|
-
|
|
73
|
+
var matcher = matchers[j].matcherType;
|
|
74
|
+
if (matcher === constants_1.IN_SEGMENT || matcher === constants_1.IN_LARGE_SEGMENT)
|
|
73
75
|
return true;
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
return false;
|
|
77
79
|
}
|
|
78
|
-
exports.
|
|
80
|
+
exports.usesSegments = usesSegments;
|
|
@@ -40,9 +40,6 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
40
40
|
KeyBuilder.prototype.buildSplitsWithSegmentCountKey = function () {
|
|
41
41
|
return this.prefix + ".splits.usingSegments";
|
|
42
42
|
};
|
|
43
|
-
KeyBuilder.prototype.buildSplitsWithLargeSegmentCountKey = function () {
|
|
44
|
-
return this.prefix + ".splits.usingLargeSegments";
|
|
45
|
-
};
|
|
46
43
|
KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) {
|
|
47
44
|
return this.prefix + ".segment." + segmentName;
|
|
48
45
|
};
|
|
@@ -35,6 +35,9 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
35
35
|
KeyBuilderCS.prototype.isSplitsCacheKey = function (key) {
|
|
36
36
|
return this.regexSplitsCacheKey.test(key);
|
|
37
37
|
};
|
|
38
|
+
KeyBuilderCS.prototype.buildTillKey = function () {
|
|
39
|
+
return this.prefix + "." + this.matchingKey + ".segments.till";
|
|
40
|
+
};
|
|
38
41
|
return KeyBuilderCS;
|
|
39
42
|
}(KeyBuilder_1.KeyBuilder));
|
|
40
43
|
exports.KeyBuilderCS = KeyBuilderCS;
|
|
@@ -50,6 +53,9 @@ function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
|
|
|
50
53
|
},
|
|
51
54
|
extractOldSegmentKey: function () {
|
|
52
55
|
return undefined;
|
|
56
|
+
},
|
|
57
|
+
buildTillKey: function () {
|
|
58
|
+
return prefix + "." + matchingKey + ".largeSegments.till";
|
|
53
59
|
}
|
|
54
60
|
};
|
|
55
61
|
}
|
|
@@ -45,7 +45,7 @@ function dataLoaderFactory(preloadedData) {
|
|
|
45
45
|
return Array.isArray(userIds) && userIds.indexOf(userId) > -1;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
storage.segments.resetSegments(mySegmentsData);
|
|
48
|
+
storage.segments.resetSegments({ k: mySegmentsData.map(function (s) { return ({ n: s }); }) });
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
exports.dataLoaderFactory = dataLoaderFactory;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MySegmentsCacheInLocal = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var lang_1 = require("../../utils/lang");
|
|
5
6
|
var AbstractSegmentsCacheSync_1 = require("../AbstractSegmentsCacheSync");
|
|
6
7
|
var constants_1 = require("./constants");
|
|
7
8
|
var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
@@ -13,19 +14,11 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
13
14
|
return _this;
|
|
14
15
|
// There is not need to flush segments cache like splits cache, since resetSegments receives the up-to-date list of active segments
|
|
15
16
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Removes list of segments from localStorage
|
|
18
|
-
* @NOTE this method is not being used at the moment.
|
|
19
|
-
*/
|
|
20
|
-
MySegmentsCacheInLocal.prototype.clear = function () {
|
|
21
|
-
this.log.info(constants_1.LOG_PREFIX + 'Flushing MySegments data from localStorage');
|
|
22
|
-
// We cannot simply call `localStorage.clear()` since that implies removing user items from the storage
|
|
23
|
-
// We could optimize next sentence, since it implies iterating over all localStorage items
|
|
24
|
-
this.resetSegments([]);
|
|
25
|
-
};
|
|
26
17
|
MySegmentsCacheInLocal.prototype.addToSegment = function (name) {
|
|
27
18
|
var segmentKey = this.keys.buildSegmentNameKey(name);
|
|
28
19
|
try {
|
|
20
|
+
if (localStorage.getItem(segmentKey) === constants_1.DEFINED)
|
|
21
|
+
return false;
|
|
29
22
|
localStorage.setItem(segmentKey, constants_1.DEFINED);
|
|
30
23
|
return true;
|
|
31
24
|
}
|
|
@@ -37,6 +30,8 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
37
30
|
MySegmentsCacheInLocal.prototype.removeFromSegment = function (name) {
|
|
38
31
|
var segmentKey = this.keys.buildSegmentNameKey(name);
|
|
39
32
|
try {
|
|
33
|
+
if (localStorage.getItem(segmentKey) !== constants_1.DEFINED)
|
|
34
|
+
return false;
|
|
40
35
|
localStorage.removeItem(segmentKey);
|
|
41
36
|
return true;
|
|
42
37
|
}
|
|
@@ -48,30 +43,22 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
48
43
|
MySegmentsCacheInLocal.prototype.isInSegment = function (name) {
|
|
49
44
|
return localStorage.getItem(this.keys.buildSegmentNameKey(name)) === constants_1.DEFINED;
|
|
50
45
|
};
|
|
51
|
-
|
|
52
|
-
* Reset (update) the cached list of segments with the given list, removing and adding segments if necessary.
|
|
53
|
-
*
|
|
54
|
-
* @param {string[]} segmentNames list of segment names
|
|
55
|
-
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
56
|
-
*/
|
|
57
|
-
MySegmentsCacheInLocal.prototype.resetSegments = function (names) {
|
|
46
|
+
MySegmentsCacheInLocal.prototype.getRegisteredSegments = function () {
|
|
58
47
|
var _this = this;
|
|
59
|
-
var isDiff = false;
|
|
60
|
-
var index;
|
|
61
48
|
// Scan current values from localStorage
|
|
62
|
-
|
|
49
|
+
return Object.keys(localStorage).reduce(function (accum, key) {
|
|
63
50
|
var segmentName = _this.keys.extractSegmentName(key);
|
|
64
51
|
if (segmentName) {
|
|
65
52
|
accum.push(segmentName);
|
|
66
53
|
}
|
|
67
54
|
else {
|
|
68
|
-
// @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block
|
|
55
|
+
// @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block
|
|
69
56
|
segmentName = _this.keys.extractOldSegmentKey(key);
|
|
70
57
|
if (segmentName) { // this was an old segment key, let's clean up.
|
|
71
58
|
var newSegmentKey = _this.keys.buildSegmentNameKey(segmentName);
|
|
72
59
|
try {
|
|
73
60
|
// If the new format key is not there, create it.
|
|
74
|
-
if (!localStorage.getItem(newSegmentKey)
|
|
61
|
+
if (!localStorage.getItem(newSegmentKey)) {
|
|
75
62
|
localStorage.setItem(newSegmentKey, constants_1.DEFINED);
|
|
76
63
|
// we are migrating a segment, let's track it.
|
|
77
64
|
accum.push(segmentName);
|
|
@@ -85,40 +72,30 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
85
72
|
}
|
|
86
73
|
return accum;
|
|
87
74
|
}, []);
|
|
88
|
-
// Extreme fast => everything is empty
|
|
89
|
-
if (names.length === 0 && storedSegmentNames.length === names.length)
|
|
90
|
-
return isDiff;
|
|
91
|
-
// Quick path
|
|
92
|
-
if (storedSegmentNames.length !== names.length) {
|
|
93
|
-
isDiff = true;
|
|
94
|
-
storedSegmentNames.forEach(function (name) { return _this.removeFromSegment(name); });
|
|
95
|
-
names.forEach(function (name) { return _this.addToSegment(name); });
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
// Slowest path => we need to find at least 1 difference because
|
|
99
|
-
for (index = 0; index < names.length && storedSegmentNames.indexOf(names[index]) !== -1; index++) {
|
|
100
|
-
// TODO: why empty statement?
|
|
101
|
-
}
|
|
102
|
-
if (index < names.length) {
|
|
103
|
-
isDiff = true;
|
|
104
|
-
storedSegmentNames.forEach(function (name) { return _this.removeFromSegment(name); });
|
|
105
|
-
names.forEach(function (name) { return _this.addToSegment(name); });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return isDiff;
|
|
109
|
-
};
|
|
110
|
-
MySegmentsCacheInLocal.prototype.getRegisteredSegments = function () {
|
|
111
|
-
var _this = this;
|
|
112
|
-
return Object.keys(localStorage).reduce(function (accum, key) {
|
|
113
|
-
var segmentName = _this.keys.extractSegmentName(key);
|
|
114
|
-
if (segmentName)
|
|
115
|
-
accum.push(segmentName);
|
|
116
|
-
return accum;
|
|
117
|
-
}, []);
|
|
118
75
|
};
|
|
119
76
|
MySegmentsCacheInLocal.prototype.getKeysCount = function () {
|
|
120
77
|
return 1;
|
|
121
78
|
};
|
|
79
|
+
MySegmentsCacheInLocal.prototype.setChangeNumber = function (name, changeNumber) {
|
|
80
|
+
try {
|
|
81
|
+
if (changeNumber)
|
|
82
|
+
localStorage.setItem(this.keys.buildTillKey(), changeNumber + '');
|
|
83
|
+
else
|
|
84
|
+
localStorage.removeItem(this.keys.buildTillKey());
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
this.log.error(e);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
MySegmentsCacheInLocal.prototype.getChangeNumber = function () {
|
|
91
|
+
var n = -1;
|
|
92
|
+
var value = localStorage.getItem(this.keys.buildTillKey());
|
|
93
|
+
if (value !== null) {
|
|
94
|
+
value = parseInt(value, 10);
|
|
95
|
+
return (0, lang_1.isNaNNumber)(value) ? n : value;
|
|
96
|
+
}
|
|
97
|
+
return n;
|
|
98
|
+
};
|
|
122
99
|
return MySegmentsCacheInLocal;
|
|
123
100
|
}(AbstractSegmentsCacheSync_1.AbstractSegmentsCacheSync));
|
|
124
101
|
exports.MySegmentsCacheInLocal = MySegmentsCacheInLocal;
|
|
@@ -7,7 +7,6 @@ var lang_1 = require("../../utils/lang");
|
|
|
7
7
|
var constants_1 = require("./constants");
|
|
8
8
|
var sets_1 = require("../../utils/lang/sets");
|
|
9
9
|
var KeyBuilder_1 = require("../KeyBuilder");
|
|
10
|
-
var constants_2 = require("../../utils/constants");
|
|
11
10
|
/**
|
|
12
11
|
* ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
|
|
13
12
|
*/
|
|
@@ -41,14 +40,10 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
41
40
|
if (split) {
|
|
42
41
|
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
43
42
|
this._decrementCount(ttKey);
|
|
44
|
-
if ((0, AbstractSplitsCacheSync_1.
|
|
43
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
45
44
|
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
46
45
|
this._decrementCount(segmentsCountKey);
|
|
47
46
|
}
|
|
48
|
-
if ((0, AbstractSplitsCacheSync_1.usesMatcher)(split, constants_2.IN_LARGE_SEGMENT)) {
|
|
49
|
-
var segmentsCountKey = this.keys.buildSplitsWithLargeSegmentCountKey();
|
|
50
|
-
this._decrementCount(segmentsCountKey);
|
|
51
|
-
}
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
49
|
catch (e) {
|
|
@@ -61,16 +56,11 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
61
56
|
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
62
57
|
// @ts-expect-error
|
|
63
58
|
localStorage.setItem(ttKey, (0, lang_1.toNumber)(localStorage.getItem(ttKey)) + 1);
|
|
64
|
-
if ((0, AbstractSplitsCacheSync_1.
|
|
59
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
65
60
|
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
66
61
|
// @ts-expect-error
|
|
67
62
|
localStorage.setItem(segmentsCountKey, (0, lang_1.toNumber)(localStorage.getItem(segmentsCountKey)) + 1);
|
|
68
63
|
}
|
|
69
|
-
if ((0, AbstractSplitsCacheSync_1.usesMatcher)(split, constants_2.IN_LARGE_SEGMENT)) {
|
|
70
|
-
var segmentsCountKey = this.keys.buildSplitsWithLargeSegmentCountKey();
|
|
71
|
-
// @ts-expect-error
|
|
72
|
-
localStorage.setItem(segmentsCountKey, (0, lang_1.toNumber)(localStorage.getItem(segmentsCountKey)) + 1);
|
|
73
|
-
}
|
|
74
64
|
}
|
|
75
65
|
}
|
|
76
66
|
catch (e) {
|
|
@@ -183,13 +173,11 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
183
173
|
var ttCount = (0, lang_1.toNumber)(localStorage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
|
|
184
174
|
return (0, lang_1.isFiniteNumber)(ttCount) && ttCount > 0;
|
|
185
175
|
};
|
|
186
|
-
SplitsCacheInLocal.prototype.
|
|
176
|
+
SplitsCacheInLocal.prototype.usesSegments = function () {
|
|
187
177
|
// If cache hasn't been synchronized with the cloud, assume we need them.
|
|
188
178
|
if (!this.hasSync)
|
|
189
179
|
return true;
|
|
190
|
-
var storedCount = localStorage.getItem(
|
|
191
|
-
this.keys.buildSplitsWithSegmentCountKey() :
|
|
192
|
-
this.keys.buildSplitsWithLargeSegmentCountKey());
|
|
180
|
+
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
193
181
|
var splitsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
|
|
194
182
|
if ((0, lang_1.isFiniteNumber)(splitsWithSegmentsCount)) {
|
|
195
183
|
return splitsWithSegmentsCount > 0;
|
|
@@ -14,57 +14,26 @@ var MySegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
14
14
|
_this.segmentCache = {};
|
|
15
15
|
return _this;
|
|
16
16
|
}
|
|
17
|
-
MySegmentsCacheInMemory.prototype.clear = function () {
|
|
18
|
-
this.segmentCache = {};
|
|
19
|
-
};
|
|
20
17
|
MySegmentsCacheInMemory.prototype.addToSegment = function (name) {
|
|
18
|
+
if (this.segmentCache[name])
|
|
19
|
+
return false;
|
|
21
20
|
this.segmentCache[name] = true;
|
|
22
21
|
return true;
|
|
23
22
|
};
|
|
24
23
|
MySegmentsCacheInMemory.prototype.removeFromSegment = function (name) {
|
|
24
|
+
if (!this.segmentCache[name])
|
|
25
|
+
return false;
|
|
25
26
|
delete this.segmentCache[name];
|
|
26
27
|
return true;
|
|
27
28
|
};
|
|
28
29
|
MySegmentsCacheInMemory.prototype.isInSegment = function (name) {
|
|
29
30
|
return this.segmentCache[name] === true;
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
37
|
-
*/
|
|
38
|
-
MySegmentsCacheInMemory.prototype.resetSegments = function (names) {
|
|
39
|
-
var _this = this;
|
|
40
|
-
var isDiff = false;
|
|
41
|
-
var index;
|
|
42
|
-
var storedSegmentKeys = Object.keys(this.segmentCache);
|
|
43
|
-
// Extreme fast => everything is empty
|
|
44
|
-
if (names.length === 0 && storedSegmentKeys.length === names.length)
|
|
45
|
-
return isDiff;
|
|
46
|
-
// Quick path
|
|
47
|
-
if (storedSegmentKeys.length !== names.length) {
|
|
48
|
-
isDiff = true;
|
|
49
|
-
this.segmentCache = {};
|
|
50
|
-
names.forEach(function (s) {
|
|
51
|
-
_this.addToSegment(s);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Slowest path => we need to find at least 1 difference because
|
|
56
|
-
for (index = 0; index < names.length && this.isInSegment(names[index]); index++) {
|
|
57
|
-
// TODO: why empty statement?
|
|
58
|
-
}
|
|
59
|
-
if (index < names.length) {
|
|
60
|
-
isDiff = true;
|
|
61
|
-
this.segmentCache = {};
|
|
62
|
-
names.forEach(function (s) {
|
|
63
|
-
_this.addToSegment(s);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return isDiff;
|
|
32
|
+
MySegmentsCacheInMemory.prototype.setChangeNumber = function (name, changeNumber) {
|
|
33
|
+
this.cn = changeNumber;
|
|
34
|
+
};
|
|
35
|
+
MySegmentsCacheInMemory.prototype.getChangeNumber = function () {
|
|
36
|
+
return this.cn || -1;
|
|
68
37
|
};
|
|
69
38
|
MySegmentsCacheInMemory.prototype.getRegisteredSegments = function () {
|
|
70
39
|
return Object.keys(this.segmentCache);
|