@splitsoftware/splitio-commons 1.16.1-rc.1 → 1.16.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 +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 +4 -8
- package/cjs/storages/AbstractSegmentsCacheSync.js +1 -6
- 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/inLocalStorage/MySegmentsCacheInLocal.js +23 -2
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +4 -16
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +5 -1
- 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 +23 -19
- package/cjs/sync/streaming/SSEHandler/index.js +7 -8
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +8 -4
- package/cjs/sync/streaming/constants.js +2 -3
- package/cjs/sync/streaming/parseUtils.js +14 -9
- package/cjs/sync/streaming/pushManager.js +29 -52
- package/cjs/sync/submitters/telemetrySubmitter.js +0 -2
- package/cjs/sync/syncManagerOnline.js +14 -24
- package/cjs/utils/constants/index.js +1 -1
- 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 +5 -9
- package/esm/storages/AbstractSegmentsCacheSync.js +1 -6
- 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/inLocalStorage/MySegmentsCacheInLocal.js +23 -2
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -17
- package/esm/storages/inMemory/MySegmentsCacheInMemory.js +5 -1
- 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 +21 -17
- package/esm/sync/streaming/SSEHandler/index.js +8 -9
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +8 -4
- package/esm/sync/streaming/constants.js +1 -2
- package/esm/sync/streaming/parseUtils.js +12 -8
- package/esm/sync/streaming/pushManager.js +31 -53
- package/esm/sync/submitters/telemetrySubmitter.js +0 -2
- package/esm/sync/syncManagerOnline.js +15 -25
- package/esm/utils/constants/index.js +1 -1
- package/esm/utils/settingsValidation/index.js +1 -5
- package/package.json +1 -1
- package/src/dtos/types.ts +14 -12
- 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 +6 -11
- package/src/services/splitHttpClient.ts +1 -1
- package/src/services/types.ts +2 -3
- package/src/storages/AbstractSegmentsCacheSync.ts +2 -6
- package/src/storages/AbstractSplitsCacheAsync.ts +2 -2
- package/src/storages/AbstractSplitsCacheSync.ts +6 -4
- package/src/storages/KeyBuilder.ts +0 -3
- package/src/storages/KeyBuilderCS.ts +9 -0
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +26 -2
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +5 -20
- package/src/storages/inMemory/MySegmentsCacheInMemory.ts +7 -1
- package/src/storages/inMemory/SplitsCacheInMemory.ts +7 -13
- package/src/storages/types.ts +6 -5
- 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 -7
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +20 -16
- package/src/sync/streaming/SSEClient/index.ts +4 -6
- package/src/sync/streaming/SSEHandler/index.ts +11 -13
- package/src/sync/streaming/SSEHandler/types.ts +13 -25
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +11 -7
- 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 +1 -2
- package/src/sync/streaming/parseUtils.ts +19 -11
- package/src/sync/streaming/pushManager.ts +37 -64
- package/src/sync/streaming/types.ts +9 -11
- package/src/sync/submitters/telemetrySubmitter.ts +0 -2
- package/src/sync/submitters/types.ts +1 -3
- package/src/sync/syncManagerOnline.ts +11 -19
- package/src/types.ts +1 -26
- package/src/utils/constants/index.ts +1 -1
- package/src/utils/settingsValidation/index.ts +1 -5
- package/types/dtos/types.d.ts +14 -11
- 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 +2 -6
- package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
- package/types/storages/AbstractSplitsCacheSync.d.ts +3 -3
- package/types/storages/KeyBuilder.d.ts +0 -1
- package/types/storages/KeyBuilderCS.d.ts +2 -0
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +3 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +1 -1
- package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +3 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -2
- package/types/storages/types.d.ts +4 -4
- 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 +6 -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 -2
- 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 +1 -2
- 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 +8 -9
- package/types/sync/submitters/types.d.ts +1 -3
- package/types/types.d.ts +0 -25
- package/types/utils/constants/index.d.ts +1 -1
- 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_MY_SEGMENTS_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_MY_SEGMENTS_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_MY_SEGMENTS_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,20 +54,16 @@ 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 + "/
|
|
64
|
+
var url = urls.sdk + "/memberships/" + encodeURIComponent(userMatchingKey);
|
|
65
65
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.MY_SEGMENT));
|
|
66
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));
|
|
70
|
-
},
|
|
71
67
|
/**
|
|
72
68
|
* Post events.
|
|
73
69
|
*
|
|
@@ -18,16 +18,11 @@ var AbstractSegmentsCacheSync = /** @class */ (function () {
|
|
|
18
18
|
* For client-side synchronizer: the method is not used.
|
|
19
19
|
*/
|
|
20
20
|
AbstractSegmentsCacheSync.prototype.setChangeNumber = function (name, changeNumber) { return true; };
|
|
21
|
-
/**
|
|
22
|
-
* For server-side synchronizer: get the change number of `name` segment.
|
|
23
|
-
* For client-side synchronizer: the method is not used.
|
|
24
|
-
*/
|
|
25
|
-
AbstractSegmentsCacheSync.prototype.getChangeNumber = function (name) { return -1; };
|
|
26
21
|
/**
|
|
27
22
|
* For server-side synchronizer: the method is not used.
|
|
28
23
|
* For client-side synchronizer: reset the cache with the given list of segments.
|
|
29
24
|
*/
|
|
30
|
-
AbstractSegmentsCacheSync.prototype.resetSegments = function (names) { return true; };
|
|
25
|
+
AbstractSegmentsCacheSync.prototype.resetSegments = function (names, changeNumber) { return true; };
|
|
31
26
|
return AbstractSegmentsCacheSync;
|
|
32
27
|
}());
|
|
33
28
|
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
|
}
|
|
@@ -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) {
|
|
@@ -51,11 +52,22 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
51
52
|
/**
|
|
52
53
|
* Reset (update) the cached list of segments with the given list, removing and adding segments if necessary.
|
|
53
54
|
*
|
|
54
|
-
* @param {string[]}
|
|
55
|
+
* @param {string[]} names list of segment names
|
|
55
56
|
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
56
57
|
*/
|
|
57
|
-
MySegmentsCacheInLocal.prototype.resetSegments = function (names) {
|
|
58
|
+
MySegmentsCacheInLocal.prototype.resetSegments = function (names, changeNumber) {
|
|
58
59
|
var _this = this;
|
|
60
|
+
try {
|
|
61
|
+
if (changeNumber) {
|
|
62
|
+
localStorage.setItem(this.keys.buildTillKey(), changeNumber + '');
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
localStorage.removeItem(this.keys.buildTillKey());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
this.log.error(e);
|
|
70
|
+
}
|
|
59
71
|
var isDiff = false;
|
|
60
72
|
var index;
|
|
61
73
|
// Scan current values from localStorage
|
|
@@ -119,6 +131,15 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
119
131
|
MySegmentsCacheInLocal.prototype.getKeysCount = function () {
|
|
120
132
|
return 1;
|
|
121
133
|
};
|
|
134
|
+
MySegmentsCacheInLocal.prototype.getChangeNumber = function () {
|
|
135
|
+
var n = -1;
|
|
136
|
+
var value = localStorage.getItem(this.keys.buildTillKey());
|
|
137
|
+
if (value !== null) {
|
|
138
|
+
value = parseInt(value, 10);
|
|
139
|
+
return (0, lang_1.isNaNNumber)(value) ? n : value;
|
|
140
|
+
}
|
|
141
|
+
return n;
|
|
142
|
+
};
|
|
122
143
|
return MySegmentsCacheInLocal;
|
|
123
144
|
}(AbstractSegmentsCacheSync_1.AbstractSegmentsCacheSync));
|
|
124
145
|
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;
|
|
@@ -35,8 +35,9 @@ var MySegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
35
35
|
* @param {string[]} names list of segment names
|
|
36
36
|
* @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
|
|
37
37
|
*/
|
|
38
|
-
MySegmentsCacheInMemory.prototype.resetSegments = function (names) {
|
|
38
|
+
MySegmentsCacheInMemory.prototype.resetSegments = function (names, changeNumber) {
|
|
39
39
|
var _this = this;
|
|
40
|
+
this.cn = changeNumber;
|
|
40
41
|
var isDiff = false;
|
|
41
42
|
var index;
|
|
42
43
|
var storedSegmentKeys = Object.keys(this.segmentCache);
|
|
@@ -66,6 +67,9 @@ var MySegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
66
67
|
}
|
|
67
68
|
return isDiff;
|
|
68
69
|
};
|
|
70
|
+
MySegmentsCacheInMemory.prototype.getChangeNumber = function () {
|
|
71
|
+
return this.cn || -1;
|
|
72
|
+
};
|
|
69
73
|
MySegmentsCacheInMemory.prototype.getRegisteredSegments = function () {
|
|
70
74
|
return Object.keys(this.segmentCache);
|
|
71
75
|
};
|
|
@@ -5,7 +5,6 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var AbstractSplitsCacheSync_1 = require("../AbstractSplitsCacheSync");
|
|
6
6
|
var lang_1 = require("../../utils/lang");
|
|
7
7
|
var sets_1 = require("../../utils/lang/sets");
|
|
8
|
-
var constants_1 = require("../../utils/constants");
|
|
9
8
|
/**
|
|
10
9
|
* Default ISplitsCacheSync implementation that stores split definitions in memory.
|
|
11
10
|
* Supported by all JS runtimes.
|
|
@@ -18,7 +17,6 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
18
17
|
_this.ttCache = {};
|
|
19
18
|
_this.changeNumber = -1;
|
|
20
19
|
_this.segmentsCount = 0;
|
|
21
|
-
_this.largeSegmentsCount = 0;
|
|
22
20
|
_this.flagSetsCache = {};
|
|
23
21
|
_this.flagSetsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
24
22
|
return _this;
|
|
@@ -28,7 +26,6 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
28
26
|
this.ttCache = {};
|
|
29
27
|
this.changeNumber = -1;
|
|
30
28
|
this.segmentsCount = 0;
|
|
31
|
-
this.largeSegmentsCount = 0;
|
|
32
29
|
};
|
|
33
30
|
SplitsCacheInMemory.prototype.addSplit = function (name, split) {
|
|
34
31
|
var previousSplit = this.getSplit(name);
|
|
@@ -38,11 +35,9 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
38
35
|
if (!this.ttCache[previousTtName])
|
|
39
36
|
delete this.ttCache[previousTtName];
|
|
40
37
|
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
41
|
-
//
|
|
42
|
-
if ((0, AbstractSplitsCacheSync_1.
|
|
38
|
+
// Subtract from segments count for the previous version of this Split
|
|
39
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(previousSplit))
|
|
43
40
|
this.segmentsCount--;
|
|
44
|
-
if ((0, AbstractSplitsCacheSync_1.usesMatcher)(previousSplit, constants_1.IN_LARGE_SEGMENT))
|
|
45
|
-
this.largeSegmentsCount--;
|
|
46
41
|
}
|
|
47
42
|
if (split) {
|
|
48
43
|
// Store the Split.
|
|
@@ -52,10 +47,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
52
47
|
this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
|
|
53
48
|
this.addToFlagSets(split);
|
|
54
49
|
// Add to segments count for the new version of the Split
|
|
55
|
-
if ((0, AbstractSplitsCacheSync_1.
|
|
50
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
|
|
56
51
|
this.segmentsCount++;
|
|
57
|
-
if ((0, AbstractSplitsCacheSync_1.usesMatcher)(split, constants_1.IN_LARGE_SEGMENT))
|
|
58
|
-
this.largeSegmentsCount++;
|
|
59
52
|
return true;
|
|
60
53
|
}
|
|
61
54
|
else {
|
|
@@ -73,10 +66,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
73
66
|
delete this.ttCache[ttName];
|
|
74
67
|
this.removeFromFlagSets(split.name, split.sets);
|
|
75
68
|
// Update the segments count.
|
|
76
|
-
if ((0, AbstractSplitsCacheSync_1.
|
|
69
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
|
|
77
70
|
this.segmentsCount--;
|
|
78
|
-
if ((0, AbstractSplitsCacheSync_1.usesMatcher)(split, constants_1.IN_LARGE_SEGMENT))
|
|
79
|
-
this.largeSegmentsCount--;
|
|
80
71
|
return true;
|
|
81
72
|
}
|
|
82
73
|
else {
|
|
@@ -99,8 +90,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
99
90
|
SplitsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
|
|
100
91
|
return (0, lang_1.isFiniteNumber)(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
|
|
101
92
|
};
|
|
102
|
-
SplitsCacheInMemory.prototype.
|
|
103
|
-
return this.getChangeNumber() === -1 ||
|
|
93
|
+
SplitsCacheInMemory.prototype.usesSegments = function () {
|
|
94
|
+
return this.getChangeNumber() === -1 || this.segmentsCount > 0;
|
|
104
95
|
};
|
|
105
96
|
SplitsCacheInMemory.prototype.getNamesByFlagSets = function (flagSets) {
|
|
106
97
|
var _this = this;
|
|
@@ -5,21 +5,14 @@ exports.mySegmentsFetcherFactory = void 0;
|
|
|
5
5
|
* Factory of MySegments fetcher.
|
|
6
6
|
* MySegments fetcher is a wrapper around `mySegments` API service that parses the response and handle errors.
|
|
7
7
|
*/
|
|
8
|
-
function mySegmentsFetcherFactory(
|
|
8
|
+
function mySegmentsFetcherFactory(fetchMemberships) {
|
|
9
9
|
return function mySegmentsFetcher(userMatchingKey, noCache,
|
|
10
|
-
// Optional decorator for `
|
|
10
|
+
// Optional decorator for `fetchMemberships` promise, such as timeout or time tracker
|
|
11
11
|
decorator) {
|
|
12
|
-
var mySegmentsPromise =
|
|
12
|
+
var mySegmentsPromise = fetchMemberships(userMatchingKey, noCache);
|
|
13
13
|
if (decorator)
|
|
14
14
|
mySegmentsPromise = decorator(mySegmentsPromise);
|
|
15
|
-
|
|
16
|
-
return mySegmentsPromise
|
|
17
|
-
.then(function (resp) { return resp.json(); })
|
|
18
|
-
.then(function (json) {
|
|
19
|
-
return json.mySegments ?
|
|
20
|
-
json.mySegments.map(function (segment) { return segment.name; }) :
|
|
21
|
-
json.myLargeSegments;
|
|
22
|
-
});
|
|
15
|
+
return mySegmentsPromise.then(function (resp) { return resp.json(); });
|
|
23
16
|
};
|
|
24
17
|
}
|
|
25
18
|
exports.mySegmentsFetcherFactory = mySegmentsFetcherFactory;
|
|
@@ -23,7 +23,7 @@ function greedyFetch(fetchSegmentChanges, since, segmentName, noCache, targetTil
|
|
|
23
23
|
*/
|
|
24
24
|
function segmentChangesFetcherFactory(fetchSegmentChanges) {
|
|
25
25
|
return function segmentChangesFetcher(since, segmentName, noCache, till,
|
|
26
|
-
// Optional decorator for `
|
|
26
|
+
// Optional decorator for `fetchSegmentChanges` promise, such as timeout or time tracker
|
|
27
27
|
decorator) {
|
|
28
28
|
var segmentsPromise = greedyFetch(fetchSegmentChanges, since, segmentName, noCache, till);
|
|
29
29
|
if (decorator)
|
|
@@ -7,7 +7,6 @@ var splitsSyncTask_1 = require("./syncTasks/splitsSyncTask");
|
|
|
7
7
|
var key_1 = require("../../utils/key");
|
|
8
8
|
var constants_1 = require("../../readiness/constants");
|
|
9
9
|
var constants_2 = require("../../logger/constants");
|
|
10
|
-
var constants_3 = require("../../utils/constants");
|
|
11
10
|
/**
|
|
12
11
|
* Expose start / stop mechanism for polling data from services.
|
|
13
12
|
* For client-side API with multiple clients.
|
|
@@ -16,74 +15,59 @@ function pollingManagerCSFactory(params) {
|
|
|
16
15
|
var splitApi = params.splitApi, storage = params.storage, readiness = params.readiness, settings = params.settings;
|
|
17
16
|
var log = settings.log;
|
|
18
17
|
var splitsSyncTask = (0, splitsSyncTask_1.splitsSyncTaskFactory)(splitApi.fetchSplitChanges, storage, readiness, settings, true);
|
|
19
|
-
// Map of matching keys to their corresponding MySegmentsSyncTask
|
|
18
|
+
// Map of matching keys to their corresponding MySegmentsSyncTask.
|
|
20
19
|
var mySegmentsSyncTasks = {};
|
|
21
20
|
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
22
|
-
var
|
|
21
|
+
var mySegmentsSyncTask = add(matchingKey, readiness, storage);
|
|
23
22
|
function startMySegmentsSyncTasks() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(0, lang_1.forOwn)(mySegmentsSyncTasks, function (_a) {
|
|
27
|
-
var msSyncTask = _a.msSyncTask, mlsSyncTask = _a.mlsSyncTask;
|
|
28
|
-
if (splitsHaveSegments)
|
|
29
|
-
msSyncTask.start();
|
|
30
|
-
else
|
|
31
|
-
msSyncTask.stop(); // smart pausing
|
|
32
|
-
if (mlsSyncTask) {
|
|
33
|
-
if (splitsHaveLargeSegments)
|
|
34
|
-
mlsSyncTask.start();
|
|
35
|
-
else
|
|
36
|
-
mlsSyncTask.stop(); // smart pausing
|
|
37
|
-
}
|
|
23
|
+
(0, lang_1.forOwn)(mySegmentsSyncTasks, function (mySegmentsSyncTask) {
|
|
24
|
+
mySegmentsSyncTask.start();
|
|
38
25
|
});
|
|
39
26
|
}
|
|
40
27
|
function stopMySegmentsSyncTasks() {
|
|
41
|
-
(0, lang_1.forOwn)(mySegmentsSyncTasks, function (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
mlsSyncTask && mlsSyncTask.stop();
|
|
28
|
+
(0, lang_1.forOwn)(mySegmentsSyncTasks, function (mySegmentsSyncTask) {
|
|
29
|
+
if (mySegmentsSyncTask.isRunning())
|
|
30
|
+
mySegmentsSyncTask.stop();
|
|
45
31
|
});
|
|
46
32
|
}
|
|
33
|
+
// smart pausing
|
|
47
34
|
readiness.splits.on(constants_1.SDK_SPLITS_ARRIVED, function () {
|
|
48
|
-
if (splitsSyncTask.isRunning())
|
|
49
|
-
|
|
35
|
+
if (!splitsSyncTask.isRunning())
|
|
36
|
+
return; // noop if not doing polling
|
|
37
|
+
var splitsHaveSegments = storage.splits.usesSegments();
|
|
38
|
+
if (splitsHaveSegments !== mySegmentsSyncTask.isRunning()) {
|
|
39
|
+
log.info(constants_2.POLLING_SMART_PAUSING, [splitsHaveSegments ? 'ON' : 'OFF']);
|
|
40
|
+
if (splitsHaveSegments) {
|
|
41
|
+
startMySegmentsSyncTasks();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
stopMySegmentsSyncTasks();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
50
47
|
});
|
|
51
48
|
function add(matchingKey, readiness, storage) {
|
|
52
|
-
var
|
|
53
|
-
readiness.segments.emit(constants_1.SDK_SEGMENTS_ARRIVED); }, settings, matchingKey, settings.scheduler.segmentsRefreshRate, 'mySegmentsUpdater');
|
|
54
|
-
var mlsSyncTask;
|
|
55
|
-
if (settings.sync.largeSegmentsEnabled) {
|
|
56
|
-
mlsSyncTask = (0, mySegmentsSyncTask_1.mySegmentsSyncTaskFactory)(splitApi.fetchMyLargeSegments, storage.largeSegments, function () { if (readiness.largeSegments && storage.splits.usesMatcher(constants_3.IN_LARGE_SEGMENT))
|
|
57
|
-
readiness.largeSegments.emit(constants_1.SDK_SEGMENTS_ARRIVED); }, settings, matchingKey, settings.scheduler.largeSegmentsRefreshRate, 'myLargeSegmentsUpdater');
|
|
58
|
-
}
|
|
49
|
+
var mySegmentsSyncTask = (0, mySegmentsSyncTask_1.mySegmentsSyncTaskFactory)(splitApi.fetchMemberships, storage, readiness, settings, matchingKey);
|
|
59
50
|
// smart ready
|
|
60
51
|
function smartReady() {
|
|
61
|
-
if (!readiness.isReady())
|
|
62
|
-
|
|
63
|
-
readiness.largeSegments.emit(constants_1.SDK_SEGMENTS_ARRIVED);
|
|
64
|
-
if (!storage.splits.usesMatcher(constants_3.IN_SEGMENT))
|
|
65
|
-
readiness.segments.emit(constants_1.SDK_SEGMENTS_ARRIVED);
|
|
66
|
-
}
|
|
52
|
+
if (!readiness.isReady() && !storage.splits.usesSegments())
|
|
53
|
+
readiness.segments.emit(constants_1.SDK_SEGMENTS_ARRIVED);
|
|
67
54
|
}
|
|
68
|
-
if (storage.splits.
|
|
69
|
-
readiness.splits.once(constants_1.SDK_SPLITS_ARRIVED, smartReady);
|
|
70
|
-
else
|
|
55
|
+
if (!storage.splits.usesSegments())
|
|
71
56
|
setTimeout(smartReady, 0);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
57
|
+
else
|
|
58
|
+
readiness.splits.once(constants_1.SDK_SPLITS_ARRIVED, smartReady);
|
|
59
|
+
mySegmentsSyncTasks[matchingKey] = mySegmentsSyncTask;
|
|
60
|
+
return mySegmentsSyncTask;
|
|
77
61
|
}
|
|
78
62
|
return {
|
|
79
63
|
splitsSyncTask: splitsSyncTask,
|
|
80
|
-
segmentsSyncTask:
|
|
81
|
-
largeSegmentsSyncTask: mlsSyncTask,
|
|
64
|
+
segmentsSyncTask: mySegmentsSyncTask,
|
|
82
65
|
// Start periodic fetching (polling)
|
|
83
66
|
start: function () {
|
|
84
67
|
log.info(constants_2.POLLING_START);
|
|
85
68
|
splitsSyncTask.start();
|
|
86
|
-
|
|
69
|
+
if (storage.splits.usesSegments())
|
|
70
|
+
startMySegmentsSyncTasks();
|
|
87
71
|
},
|
|
88
72
|
// Stop periodic fetching (polling)
|
|
89
73
|
stop: function () {
|
|
@@ -97,10 +81,8 @@ function pollingManagerCSFactory(params) {
|
|
|
97
81
|
// fetch splits and segments
|
|
98
82
|
syncAll: function () {
|
|
99
83
|
var promises = [splitsSyncTask.execute()];
|
|
100
|
-
(0, lang_1.forOwn)(mySegmentsSyncTasks, function (
|
|
101
|
-
|
|
102
|
-
promises.push(msSyncTask.execute());
|
|
103
|
-
mlsSyncTask && promises.push(mlsSyncTask.execute());
|
|
84
|
+
(0, lang_1.forOwn)(mySegmentsSyncTasks, function (mySegmentsSyncTask) {
|
|
85
|
+
promises.push(mySegmentsSyncTask.execute());
|
|
104
86
|
});
|
|
105
87
|
return Promise.all(promises);
|
|
106
88
|
},
|