@splitsoftware/splitio-commons 3.1.1-rc.10 → 3.1.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 +2 -0
- package/cjs/evaluator/condition/index.js +2 -2
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/cjs/evaluator/index.js +81 -71
- package/cjs/listeners/browser.js +2 -1
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +15 -20
- package/cjs/logger/messages/debug.js +5 -6
- package/cjs/logger/messages/error.js +3 -3
- package/cjs/logger/messages/info.js +3 -4
- package/cjs/logger/messages/warn.js +6 -7
- package/cjs/platform/browser.js +15 -0
- package/cjs/platform/getEventSource/browser.js +8 -0
- package/cjs/platform/getEventSource/eventsource.js +480 -0
- package/cjs/platform/getEventSource/node.js +26 -0
- package/cjs/platform/getFetch/browser.js +9 -0
- package/cjs/platform/getFetch/node.js +27 -0
- package/cjs/platform/getOptions/node.js +25 -0
- package/cjs/platform/node.js +17 -0
- package/cjs/presets/serverSide.js +2 -2
- package/cjs/readiness/constants.js +5 -4
- package/cjs/readiness/readinessManager.js +23 -23
- package/cjs/readiness/sdkReadinessManager.js +1 -17
- package/cjs/sdkClient/client.js +24 -50
- package/cjs/sdkClient/clientInputValidation.js +6 -17
- package/cjs/sdkClient/sdkClient.js +3 -60
- package/cjs/sdkClient/sdkLifecycle.js +74 -0
- package/cjs/sdkClient/trackMethod.js +56 -0
- package/cjs/sdkFactory/index.js +11 -15
- package/cjs/sdkManager/index.js +5 -5
- package/cjs/services/authProvider.js +80 -0
- package/cjs/services/decorateHeaders.js +2 -1
- package/cjs/services/secureSplitHttpClient.js +36 -0
- package/cjs/services/serviceApi.js +147 -0
- package/cjs/services/splitApi.js +24 -10
- package/cjs/services/splitHttpClient.js +3 -5
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
- package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
- package/cjs/storages/KeyBuilder.js +6 -6
- package/cjs/storages/KeyBuilderCS.js +5 -5
- package/cjs/storages/KeyBuilderSS.js +2 -2
- package/cjs/storages/getRolloutPlan.js +3 -3
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
- 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/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +77 -77
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/index.js +2 -2
- package/cjs/storages/setRolloutPlan.js +4 -4
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
- package/cjs/sync/polling/pollingManagerCS.js +86 -81
- package/cjs/sync/polling/pollingManagerSS.js +44 -36
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +13 -0
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +66 -69
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/streaming/AuthClient/index.js +13 -14
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +16 -19
- package/cjs/sync/streaming/constants.js +4 -3
- package/cjs/sync/streaming/parseUtils.js +11 -11
- package/cjs/sync/streaming/pushManager.js +20 -25
- package/cjs/sync/submitters/eventsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
- package/cjs/sync/submitters/telemetrySubmitter.js +3 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +5 -5
- package/cjs/utils/Backoff.js +35 -3
- package/cjs/utils/EventEmitter.js +391 -0
- package/cjs/utils/filter/bloomFilter.js +37 -0
- package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
- package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
- package/cjs/utils/inputValidation/definitions.js +25 -0
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/target.js +22 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/settingsValidation/index.js +2 -0
- package/cjs/utils/settingsValidation/splitFilters.js +3 -3
- package/cjs/utils/settingsValidation/url.js +6 -2
- package/esm/evaluator/condition/index.js +2 -2
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/esm/evaluator/index.js +80 -71
- package/esm/listeners/browser.js +2 -1
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +12 -17
- package/esm/logger/messages/debug.js +5 -6
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +3 -4
- package/esm/logger/messages/warn.js +6 -7
- package/esm/platform/browser.js +12 -0
- package/esm/platform/getEventSource/browser.js +4 -0
- package/esm/platform/getEventSource/eventsource.js +480 -0
- package/esm/platform/getEventSource/node.js +20 -0
- package/esm/platform/getFetch/browser.js +5 -0
- package/esm/platform/getFetch/node.js +22 -0
- package/esm/platform/getOptions/node.js +20 -0
- package/esm/platform/node.js +14 -0
- package/esm/presets/serverSide.js +2 -2
- package/esm/readiness/constants.js +4 -3
- package/esm/readiness/readinessManager.js +24 -24
- package/esm/readiness/sdkReadinessManager.js +2 -18
- package/esm/sdkClient/client.js +23 -50
- package/esm/sdkClient/clientInputValidation.js +8 -19
- package/esm/sdkClient/sdkClient.js +3 -60
- package/esm/sdkClient/sdkLifecycle.js +70 -0
- package/esm/sdkClient/trackMethod.js +52 -0
- package/esm/sdkFactory/index.js +12 -16
- package/esm/sdkManager/index.js +6 -6
- package/esm/services/authProvider.js +76 -0
- package/esm/services/decorateHeaders.js +2 -1
- package/esm/services/secureSplitHttpClient.js +32 -0
- package/esm/services/serviceApi.js +143 -0
- package/esm/services/splitApi.js +24 -10
- package/esm/services/splitHttpClient.js +3 -5
- package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
- package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
- package/esm/storages/KeyBuilder.js +6 -6
- package/esm/storages/KeyBuilderCS.js +5 -5
- package/esm/storages/KeyBuilderSS.js +2 -2
- package/esm/storages/getRolloutPlan.js +3 -3
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
- 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/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +76 -76
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/setRolloutPlan.js +4 -4
- package/esm/storages/utils.js +1 -0
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
- package/esm/sync/polling/pollingManagerCS.js +87 -82
- package/esm/sync/polling/pollingManagerSS.js +44 -36
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +9 -0
- package/esm/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/esm/sync/polling/updaters/definitionChangesUpdater.js +191 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/streaming/AuthClient/index.js +11 -11
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
- package/esm/sync/streaming/SSEHandler/index.js +3 -2
- package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +15 -18
- package/esm/sync/streaming/constants.js +3 -2
- package/esm/sync/streaming/parseUtils.js +9 -9
- package/esm/sync/streaming/pushManager.js +22 -27
- package/esm/sync/submitters/eventsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionsSubmitter.js +5 -4
- package/esm/sync/submitters/telemetrySubmitter.js +3 -4
- package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +4 -4
- package/esm/utils/Backoff.js +35 -3
- package/esm/utils/EventEmitter.js +387 -0
- package/esm/utils/filter/bloomFilter.js +33 -0
- package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
- package/esm/utils/inputValidation/definitionExistence.js +15 -0
- package/esm/utils/inputValidation/definitions.js +21 -0
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/target.js +18 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/settingsValidation/index.js +2 -0
- package/esm/utils/settingsValidation/splitFilters.js +3 -3
- package/esm/utils/settingsValidation/url.js +6 -2
- package/package.json +1 -1
- package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
- package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
- package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
- package/cjs/utils/inputValidation/splits.js +0 -25
- package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
- package/esm/storages/AbstractSplitsCacheSync.js +0 -71
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
- package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
- package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
- package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -194
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { timeout } from '../../../utils/promise/timeout';
|
|
2
|
-
import { SDK_SPLITS_ARRIVED, FLAGS_UPDATE, SEGMENTS_UPDATE } from '../../../readiness/constants';
|
|
3
|
-
import { SYNC_SPLITS_FETCH, SYNC_SPLITS_UPDATE, SYNC_RBS_UPDATE, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
|
|
4
|
-
import { startsWith } from '../../../utils/lang';
|
|
5
|
-
import { IN_RULE_BASED_SEGMENT, IN_SEGMENT, RULE_BASED_SEGMENT, STANDARD_SEGMENT } from '../../../utils/constants';
|
|
6
|
-
import { setToArray } from '../../../utils/lang/sets';
|
|
7
|
-
import { SPLIT_UPDATE } from '../../streaming/constants';
|
|
8
|
-
// Checks that all registered segments have been fetched (changeNumber !== -1 for every segment).
|
|
9
|
-
// Returns a promise that could be rejected.
|
|
10
|
-
// @TODO review together with Segments and MySegments storage APIs
|
|
11
|
-
function checkAllSegmentsExist(segments) {
|
|
12
|
-
var registeredSegments = Promise.resolve(segments.getRegisteredSegments());
|
|
13
|
-
return registeredSegments.then(function (segmentNames) {
|
|
14
|
-
return Promise.all(segmentNames.map(function (segmentName) { return segments.getChangeNumber(segmentName); }))
|
|
15
|
-
.then(function (changeNumbers) { return changeNumbers.every(function (changeNumber) { return changeNumber !== undefined; }); });
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Collect segments from a raw FF or RBS definition.
|
|
20
|
-
* Exported for testing purposes.
|
|
21
|
-
*/
|
|
22
|
-
export function parseSegments(ruleEntity, matcherType) {
|
|
23
|
-
if (matcherType === void 0) { matcherType = IN_SEGMENT; }
|
|
24
|
-
var _a = ruleEntity, conditions = _a.conditions, excluded = _a.excluded;
|
|
25
|
-
var segments = new Set();
|
|
26
|
-
if (excluded && excluded.segments) {
|
|
27
|
-
excluded.segments.forEach(function (_a) {
|
|
28
|
-
var type = _a.type, name = _a.name;
|
|
29
|
-
if ((type === STANDARD_SEGMENT && matcherType === IN_SEGMENT) || (type === RULE_BASED_SEGMENT && matcherType === IN_RULE_BASED_SEGMENT)) {
|
|
30
|
-
segments.add(name);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
if (conditions) {
|
|
35
|
-
for (var i = 0; i < conditions.length; i++) {
|
|
36
|
-
var matchers = conditions[i].matcherGroup.matchers;
|
|
37
|
-
matchers.forEach(function (matcher) {
|
|
38
|
-
if (matcher.matcherType === matcherType)
|
|
39
|
-
segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return segments;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* If there are defined filters and one feature flag doesn't match with them, its status is changed to 'ARCHIVE' to avoid storing it
|
|
47
|
-
* If there is `bySet` filter, `byName` and `byPrefix` filters are ignored
|
|
48
|
-
*
|
|
49
|
-
* @param featureFlag - feature flag to be evaluated
|
|
50
|
-
* @param filters - splitFiltersValidation bySet | byName
|
|
51
|
-
*/
|
|
52
|
-
function matchFilters(featureFlag, filters) {
|
|
53
|
-
var _a = filters.groupedFilters, setsFilter = _a.bySet, namesFilter = _a.byName, prefixFilter = _a.byPrefix;
|
|
54
|
-
if (setsFilter.length > 0)
|
|
55
|
-
return featureFlag.sets && featureFlag.sets.some(function (featureFlagSet) { return setsFilter.indexOf(featureFlagSet) > -1; });
|
|
56
|
-
var namesFilterConfigured = namesFilter.length > 0;
|
|
57
|
-
var prefixFilterConfigured = prefixFilter.length > 0;
|
|
58
|
-
if (!namesFilterConfigured && !prefixFilterConfigured)
|
|
59
|
-
return true;
|
|
60
|
-
var matchNames = namesFilterConfigured && namesFilter.indexOf(featureFlag.name) > -1;
|
|
61
|
-
var matchPrefix = prefixFilterConfigured && prefixFilter.some(function (prefix) { return startsWith(featureFlag.name, prefix); });
|
|
62
|
-
return matchNames || matchPrefix;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Given the list of splits from /splitChanges endpoint, it returns the mutations,
|
|
66
|
-
* i.e., an object with added splits, removed splits and used segments.
|
|
67
|
-
* Exported for testing purposes.
|
|
68
|
-
*/
|
|
69
|
-
export function computeMutation(rules, segments, filters) {
|
|
70
|
-
return rules.reduce(function (accum, ruleEntity) {
|
|
71
|
-
if (ruleEntity.status !== 'ARCHIVED' && (!filters || matchFilters(ruleEntity, filters))) {
|
|
72
|
-
accum.added.push(ruleEntity);
|
|
73
|
-
parseSegments(ruleEntity).forEach(function (segmentName) {
|
|
74
|
-
segments.add(segmentName);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
accum.removed.push(ruleEntity);
|
|
79
|
-
}
|
|
80
|
-
accum.names.push(ruleEntity.name);
|
|
81
|
-
return accum;
|
|
82
|
-
}, { added: [], removed: [], names: [] });
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* factory of SplitChanges updater, a task that:
|
|
86
|
-
* - fetches split changes using `splitChangesFetcher`
|
|
87
|
-
* - updates `splitsCache`
|
|
88
|
-
* - uses `splitsEventEmitter` to emit events related to split data updates
|
|
89
|
-
*
|
|
90
|
-
* @param log - Logger instance
|
|
91
|
-
* @param splitChangesFetcher - Fetcher of `/splitChanges`
|
|
92
|
-
* @param splits - Splits storage, with sync or async methods
|
|
93
|
-
* @param segments - Segments storage, with sync or async methods
|
|
94
|
-
* @param splitsEventEmitter - Optional readiness manager. Not required for synchronizer or producer mode.
|
|
95
|
-
* @param requestTimeoutBeforeReady - How long the updater will wait for the request to timeout. Default 0, i.e., never timeout.
|
|
96
|
-
* @param retriesOnFailureBeforeReady - How many retries on `/splitChanges` we the updater do in case of failure or timeout. Default 0, i.e., no retries.
|
|
97
|
-
*/
|
|
98
|
-
export function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFiltersValidation, splitsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, isClientSide) {
|
|
99
|
-
if (requestTimeoutBeforeReady === void 0) { requestTimeoutBeforeReady = 0; }
|
|
100
|
-
if (retriesOnFailureBeforeReady === void 0) { retriesOnFailureBeforeReady = 0; }
|
|
101
|
-
var splits = storage.splits, rbSegments = storage.rbSegments, segments = storage.segments;
|
|
102
|
-
var startingUp = true;
|
|
103
|
-
/** timeout decorator for `splitChangesFetcher` promise */
|
|
104
|
-
function _promiseDecorator(promise) {
|
|
105
|
-
if (startingUp && requestTimeoutBeforeReady)
|
|
106
|
-
promise = timeout(requestTimeoutBeforeReady, promise);
|
|
107
|
-
return promise;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* SplitChanges updater returns a promise that resolves with a `false` boolean value if it fails to fetch splits or synchronize them with the storage.
|
|
111
|
-
* Returned promise will not be rejected.
|
|
112
|
-
*
|
|
113
|
-
* @param noCache - true to revalidate data to fetch
|
|
114
|
-
* @param till - query param to bypass CDN requests
|
|
115
|
-
*/
|
|
116
|
-
return function splitChangesUpdater(noCache, till, instantUpdate) {
|
|
117
|
-
/**
|
|
118
|
-
* @param since - current changeNumber at splitsCache
|
|
119
|
-
* @param retry - current number of retry attempts
|
|
120
|
-
*/
|
|
121
|
-
function _splitChangesUpdater(sinces, retry) {
|
|
122
|
-
if (retry === void 0) { retry = 0; }
|
|
123
|
-
var since = sinces[0], rbSince = sinces[1];
|
|
124
|
-
log.debug(SYNC_SPLITS_FETCH, sinces);
|
|
125
|
-
return Promise.resolve(instantUpdate ?
|
|
126
|
-
instantUpdate.type === SPLIT_UPDATE ?
|
|
127
|
-
// IFFU edge case: a change to a flag that adds an IN_RULE_BASED_SEGMENT matcher that is not present yet
|
|
128
|
-
Promise.resolve(rbSegments.contains(parseSegments(instantUpdate.payload, IN_RULE_BASED_SEGMENT))).then(function (contains) {
|
|
129
|
-
return contains ?
|
|
130
|
-
{ ff: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
|
|
131
|
-
splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator);
|
|
132
|
-
}) :
|
|
133
|
-
{ rbs: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
|
|
134
|
-
splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator))
|
|
135
|
-
.then(function (splitChanges) {
|
|
136
|
-
var usedSegments = new Set();
|
|
137
|
-
var updatedFlags = [];
|
|
138
|
-
var ffUpdate = false;
|
|
139
|
-
if (splitChanges.ff) {
|
|
140
|
-
var _a = computeMutation(splitChanges.ff.d || [], usedSegments, splitFiltersValidation), added = _a.added, removed = _a.removed, names = _a.names;
|
|
141
|
-
updatedFlags = names;
|
|
142
|
-
log.debug(SYNC_SPLITS_UPDATE, [added.length, removed.length]);
|
|
143
|
-
ffUpdate = splits.update(added, removed, splitChanges.ff.t);
|
|
144
|
-
}
|
|
145
|
-
var rbsUpdate = false;
|
|
146
|
-
if (splitChanges.rbs) {
|
|
147
|
-
var _b = computeMutation(splitChanges.rbs.d || [], usedSegments), added = _b.added, removed = _b.removed;
|
|
148
|
-
log.debug(SYNC_RBS_UPDATE, [added.length, removed.length]);
|
|
149
|
-
rbsUpdate = rbSegments.update(added, removed, splitChanges.rbs.t);
|
|
150
|
-
}
|
|
151
|
-
return Promise.all([ffUpdate, rbsUpdate,
|
|
152
|
-
// @TODO if at least 1 segment fetch fails due to 404 and other segments are updated in the storage, SDK_UPDATE is not emitted
|
|
153
|
-
segments.registerSegments(setToArray(usedSegments))
|
|
154
|
-
]).then(function (_a) {
|
|
155
|
-
var ffChanged = _a[0], rbsChanged = _a[1];
|
|
156
|
-
if (storage.save)
|
|
157
|
-
storage.save();
|
|
158
|
-
startingUp = false;
|
|
159
|
-
if (splitsEventEmitter) {
|
|
160
|
-
// To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
|
|
161
|
-
return Promise.resolve(!splitsEventEmitter.splitsArrived || ((ffChanged || rbsChanged) && (isClientSide || checkAllSegmentsExist(segments))))
|
|
162
|
-
.catch(function () { return false; } /** noop. just to handle a possible `checkAllSegmentsExist` rejection, before emitting SDK event */)
|
|
163
|
-
.then(function (emitSplitsArrivedEvent) {
|
|
164
|
-
// emit SDK events
|
|
165
|
-
if (emitSplitsArrivedEvent) {
|
|
166
|
-
var metadata = {
|
|
167
|
-
type: updatedFlags.length > 0 ? FLAGS_UPDATE : SEGMENTS_UPDATE,
|
|
168
|
-
names: updatedFlags.length > 0 ? updatedFlags : []
|
|
169
|
-
};
|
|
170
|
-
splitsEventEmitter.emit(SDK_SPLITS_ARRIVED, metadata);
|
|
171
|
-
}
|
|
172
|
-
return true;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return true;
|
|
176
|
-
});
|
|
177
|
-
})
|
|
178
|
-
.catch(function (error) {
|
|
179
|
-
if (startingUp && retriesOnFailureBeforeReady > retry) {
|
|
180
|
-
retry += 1;
|
|
181
|
-
log.warn(SYNC_SPLITS_FETCH_RETRY, [retry, error]);
|
|
182
|
-
return _splitChangesUpdater(sinces, retry);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
startingUp = false;
|
|
186
|
-
log.warn(SYNC_SPLITS_FETCH_FAILS, [error]);
|
|
187
|
-
}
|
|
188
|
-
return false;
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
// `getChangeNumber` never rejects or throws error
|
|
192
|
-
return Promise.all([splits.getChangeNumber(), rbSegments.getChangeNumber()]).then(_splitChangesUpdater);
|
|
193
|
-
};
|
|
194
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FALLBACK_SPLIT_NOT_FOUND, SPLIT_NOT_FOUND } from '../labels';
|
|
2
|
-
import { WARN_NOT_EXISTENT_SPLIT } from '../../logger/constants';
|
|
3
|
-
/**
|
|
4
|
-
* 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.
|
|
5
|
-
* 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.
|
|
6
|
-
*/
|
|
7
|
-
export function validateSplitExistence(log, readinessManager, splitName, labelOrSplitObj, method) {
|
|
8
|
-
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
|
|
9
|
-
if (labelOrSplitObj === SPLIT_NOT_FOUND || labelOrSplitObj === FALLBACK_SPLIT_NOT_FOUND || labelOrSplitObj == null) {
|
|
10
|
-
log.warn(WARN_NOT_EXISTENT_SPLIT, [method, splitName]);
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
|
|
2
|
-
import { uniq } from '../lang';
|
|
3
|
-
import { validateSplit } from './split';
|
|
4
|
-
export function validateSplits(log, maybeSplits, method, listName, item) {
|
|
5
|
-
if (listName === void 0) { listName = 'feature flag names'; }
|
|
6
|
-
if (item === void 0) { item = 'feature flag name'; }
|
|
7
|
-
if (Array.isArray(maybeSplits) && maybeSplits.length > 0) {
|
|
8
|
-
var validatedArray_1 = [];
|
|
9
|
-
// Remove invalid values
|
|
10
|
-
maybeSplits.forEach(function (maybeSplit) {
|
|
11
|
-
var splitName = validateSplit(log, maybeSplit, method, item);
|
|
12
|
-
if (splitName)
|
|
13
|
-
validatedArray_1.push(splitName);
|
|
14
|
-
});
|
|
15
|
-
// Strip off duplicated values if we have valid split names then return
|
|
16
|
-
if (validatedArray_1.length)
|
|
17
|
-
return uniq(validatedArray_1);
|
|
18
|
-
}
|
|
19
|
-
log.error(ERROR_EMPTY_ARRAY, [method, listName]);
|
|
20
|
-
return false;
|
|
21
|
-
}
|