@splitsoftware/splitio-commons 3.1.1-rc.10 → 3.1.1-rc.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +3 -0
- package/cjs/evaluator/condition/index.js +2 -2
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/cjs/evaluator/index.js +81 -71
- package/cjs/listeners/browser.js +2 -1
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +15 -20
- package/cjs/logger/messages/debug.js +5 -6
- package/cjs/logger/messages/error.js +3 -3
- package/cjs/logger/messages/info.js +3 -4
- package/cjs/logger/messages/warn.js +6 -7
- package/cjs/platform/browser.js +15 -0
- package/cjs/platform/getEventSource/browser.js +8 -0
- package/cjs/platform/getEventSource/eventsource.js +480 -0
- package/cjs/platform/getEventSource/node.js +26 -0
- package/cjs/platform/getFetch/browser.js +9 -0
- package/cjs/platform/getFetch/node.js +27 -0
- package/cjs/platform/getOptions/node.js +25 -0
- package/cjs/platform/node.js +17 -0
- package/cjs/presets/serverSide.js +2 -2
- package/cjs/readiness/constants.js +5 -4
- package/cjs/readiness/readinessManager.js +23 -23
- package/cjs/readiness/sdkReadinessManager.js +1 -17
- package/cjs/sdkClient/client.js +24 -50
- package/cjs/sdkClient/clientInputValidation.js +6 -17
- package/cjs/sdkClient/sdkClient.js +3 -60
- package/cjs/sdkClient/sdkLifecycle.js +74 -0
- package/cjs/sdkClient/trackMethod.js +56 -0
- package/cjs/sdkFactory/index.js +11 -15
- package/cjs/sdkManager/index.js +5 -5
- package/cjs/services/authProvider.js +80 -0
- package/cjs/services/decorateHeaders.js +2 -1
- package/cjs/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +15 -16
- package/cjs/services/secureSplitHttpClient.js +36 -0
- package/cjs/services/serviceApi.js +147 -0
- package/cjs/services/splitApi.js +24 -10
- package/cjs/services/splitHttpClient.js +3 -5
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
- package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
- package/cjs/storages/KeyBuilder.js +6 -6
- package/cjs/storages/KeyBuilderCS.js +5 -5
- package/cjs/storages/KeyBuilderSS.js +2 -2
- package/cjs/storages/getRolloutPlan.js +3 -3
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +195 -0
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +12 -11
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +122 -0
- package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +7 -6
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +79 -77
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +214 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
- package/cjs/storages/pluggable/index.js +2 -2
- package/cjs/storages/setRolloutPlan.js +4 -4
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
- package/cjs/sync/polling/pollingManagerCS.js +86 -81
- package/cjs/sync/polling/pollingManagerSS.js +44 -36
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +13 -0
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/definitionChangesUpdater.js +207 -0
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +19 -20
- package/cjs/sync/streaming/constants.js +4 -3
- package/cjs/sync/streaming/parseUtils.js +14 -14
- package/cjs/sync/streaming/pushManager.js +22 -26
- package/cjs/sync/submitters/eventsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
- package/cjs/sync/submitters/telemetrySubmitter.js +3 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +5 -5
- package/cjs/utils/Backoff.js +35 -3
- package/cjs/utils/EventEmitter.js +391 -0
- package/cjs/utils/filter/bloomFilter.js +37 -0
- package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
- package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
- package/cjs/utils/inputValidation/definitions.js +25 -0
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/target.js +22 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/settingsValidation/index.js +2 -0
- package/cjs/utils/settingsValidation/splitFilters.js +3 -3
- package/cjs/utils/settingsValidation/url.js +6 -2
- package/esm/evaluator/condition/index.js +2 -2
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/esm/evaluator/index.js +80 -71
- package/esm/listeners/browser.js +2 -1
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +12 -17
- package/esm/logger/messages/debug.js +5 -6
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +3 -4
- package/esm/logger/messages/warn.js +6 -7
- package/esm/platform/browser.js +12 -0
- package/esm/platform/getEventSource/browser.js +4 -0
- package/esm/platform/getEventSource/eventsource.js +480 -0
- package/esm/platform/getEventSource/node.js +20 -0
- package/esm/platform/getFetch/browser.js +5 -0
- package/esm/platform/getFetch/node.js +22 -0
- package/esm/platform/getOptions/node.js +20 -0
- package/esm/platform/node.js +14 -0
- package/esm/presets/serverSide.js +2 -2
- package/esm/readiness/constants.js +4 -3
- package/esm/readiness/readinessManager.js +24 -24
- package/esm/readiness/sdkReadinessManager.js +2 -18
- package/esm/sdkClient/client.js +23 -50
- package/esm/sdkClient/clientInputValidation.js +8 -19
- package/esm/sdkClient/sdkClient.js +3 -60
- package/esm/sdkClient/sdkLifecycle.js +70 -0
- package/esm/sdkClient/trackMethod.js +52 -0
- package/esm/sdkFactory/index.js +12 -16
- package/esm/sdkManager/index.js +6 -6
- package/esm/services/authProvider.js +76 -0
- package/esm/services/decorateHeaders.js +2 -1
- package/esm/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +13 -13
- package/esm/services/secureSplitHttpClient.js +32 -0
- package/esm/services/serviceApi.js +143 -0
- package/esm/services/splitApi.js +24 -10
- package/esm/services/splitHttpClient.js +3 -5
- package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
- package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
- package/esm/storages/KeyBuilder.js +6 -6
- package/esm/storages/KeyBuilderCS.js +5 -5
- package/esm/storages/KeyBuilderSS.js +2 -2
- package/esm/storages/getRolloutPlan.js +3 -3
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +192 -0
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +9 -8
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +119 -0
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +4 -3
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +78 -76
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +211 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/setRolloutPlan.js +4 -4
- package/esm/storages/utils.js +1 -0
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
- package/esm/sync/polling/pollingManagerCS.js +87 -82
- package/esm/sync/polling/pollingManagerSS.js +44 -36
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +9 -0
- package/esm/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
- package/esm/sync/polling/updaters/definitionChangesUpdater.js +201 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
- package/esm/sync/streaming/SSEHandler/index.js +3 -2
- package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +19 -20
- package/esm/sync/streaming/constants.js +3 -2
- package/esm/sync/streaming/parseUtils.js +11 -11
- package/esm/sync/streaming/pushManager.js +24 -28
- package/esm/sync/submitters/eventsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
- package/esm/sync/submitters/impressionsSubmitter.js +5 -4
- package/esm/sync/submitters/telemetrySubmitter.js +3 -4
- package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +4 -4
- package/esm/utils/Backoff.js +35 -3
- package/esm/utils/EventEmitter.js +387 -0
- package/esm/utils/filter/bloomFilter.js +33 -0
- package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
- package/esm/utils/inputValidation/definitionExistence.js +15 -0
- package/esm/utils/inputValidation/definitions.js +21 -0
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/target.js +18 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/settingsValidation/index.js +2 -0
- package/esm/utils/settingsValidation/splitFilters.js +3 -3
- package/esm/utils/settingsValidation/url.js +6 -2
- package/package.json +1 -1
- package/src/dtos/types.ts +4 -4
- package/src/services/authProvider.ts +2 -2
- package/src/{sync/streaming/AuthClient/index.ts → services/fetchAuth.ts} +3 -4
- package/src/services/splitApi.ts +1 -1
- package/src/services/types.ts +21 -4
- package/src/storages/AbstractDefinitionsCacheAsync.ts +3 -3
- package/src/storages/AbstractDefinitionsCacheSync.ts +2 -2
- package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +2 -2
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +3 -3
- package/src/storages/inMemory/DefinitionsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -2
- package/src/storages/inRedis/DefinitionsCacheInRedis.ts +6 -4
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +7 -5
- package/src/storages/pluggable/DefinitionsCachePluggable.ts +4 -2
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +5 -3
- package/src/storages/types.ts +6 -6
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +5 -5
- package/src/sync/polling/types.ts +22 -1
- package/src/sync/polling/updaters/definitionChangesUpdater.ts +26 -20
- package/src/sync/streaming/SSEClient/index.ts +1 -1
- package/src/sync/streaming/SSEClient/types.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/DefinitionsUpdateWorker.ts +15 -11
- package/src/sync/streaming/UpdateWorkers/types.ts +6 -0
- package/src/sync/streaming/parseUtils.ts +3 -4
- package/src/sync/streaming/pushManager.ts +4 -3
- package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
- package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
- package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +0 -200
- package/cjs/sync/streaming/AuthClient/types.js +0 -2
- package/cjs/utils/inputValidation/splits.js +0 -25
- package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
- package/esm/storages/AbstractSplitsCacheSync.js +0 -71
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
- package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
- package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
- package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -194
- package/esm/sync/streaming/AuthClient/types.js +0 -1
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
- package/src/sync/streaming/AuthClient/types.ts +0 -19
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.splitChangesUpdaterFactory = exports.computeMutation = exports.parseSegments = void 0;
|
|
4
|
-
var timeout_1 = require("../../../utils/promise/timeout");
|
|
5
|
-
var constants_1 = require("../../../readiness/constants");
|
|
6
|
-
var constants_2 = require("../../../logger/constants");
|
|
7
|
-
var lang_1 = require("../../../utils/lang");
|
|
8
|
-
var constants_3 = require("../../../utils/constants");
|
|
9
|
-
var sets_1 = require("../../../utils/lang/sets");
|
|
10
|
-
var constants_4 = require("../../streaming/constants");
|
|
11
|
-
// Checks that all registered segments have been fetched (changeNumber !== -1 for every segment).
|
|
12
|
-
// Returns a promise that could be rejected.
|
|
13
|
-
// @TODO review together with Segments and MySegments storage APIs
|
|
14
|
-
function checkAllSegmentsExist(segments) {
|
|
15
|
-
var registeredSegments = Promise.resolve(segments.getRegisteredSegments());
|
|
16
|
-
return registeredSegments.then(function (segmentNames) {
|
|
17
|
-
return Promise.all(segmentNames.map(function (segmentName) { return segments.getChangeNumber(segmentName); }))
|
|
18
|
-
.then(function (changeNumbers) { return changeNumbers.every(function (changeNumber) { return changeNumber !== undefined; }); });
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Collect segments from a raw FF or RBS definition.
|
|
23
|
-
* Exported for testing purposes.
|
|
24
|
-
*/
|
|
25
|
-
function parseSegments(ruleEntity, matcherType) {
|
|
26
|
-
if (matcherType === void 0) { matcherType = constants_3.IN_SEGMENT; }
|
|
27
|
-
var _a = ruleEntity, conditions = _a.conditions, excluded = _a.excluded;
|
|
28
|
-
var segments = new Set();
|
|
29
|
-
if (excluded && excluded.segments) {
|
|
30
|
-
excluded.segments.forEach(function (_a) {
|
|
31
|
-
var type = _a.type, name = _a.name;
|
|
32
|
-
if ((type === constants_3.STANDARD_SEGMENT && matcherType === constants_3.IN_SEGMENT) || (type === constants_3.RULE_BASED_SEGMENT && matcherType === constants_3.IN_RULE_BASED_SEGMENT)) {
|
|
33
|
-
segments.add(name);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (conditions) {
|
|
38
|
-
for (var i = 0; i < conditions.length; i++) {
|
|
39
|
-
var matchers = conditions[i].matcherGroup.matchers;
|
|
40
|
-
matchers.forEach(function (matcher) {
|
|
41
|
-
if (matcher.matcherType === matcherType)
|
|
42
|
-
segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return segments;
|
|
47
|
-
}
|
|
48
|
-
exports.parseSegments = parseSegments;
|
|
49
|
-
/**
|
|
50
|
-
* If there are defined filters and one feature flag doesn't match with them, its status is changed to 'ARCHIVE' to avoid storing it
|
|
51
|
-
* If there is `bySet` filter, `byName` and `byPrefix` filters are ignored
|
|
52
|
-
*
|
|
53
|
-
* @param featureFlag - feature flag to be evaluated
|
|
54
|
-
* @param filters - splitFiltersValidation bySet | byName
|
|
55
|
-
*/
|
|
56
|
-
function matchFilters(featureFlag, filters) {
|
|
57
|
-
var _a = filters.groupedFilters, setsFilter = _a.bySet, namesFilter = _a.byName, prefixFilter = _a.byPrefix;
|
|
58
|
-
if (setsFilter.length > 0)
|
|
59
|
-
return featureFlag.sets && featureFlag.sets.some(function (featureFlagSet) { return setsFilter.indexOf(featureFlagSet) > -1; });
|
|
60
|
-
var namesFilterConfigured = namesFilter.length > 0;
|
|
61
|
-
var prefixFilterConfigured = prefixFilter.length > 0;
|
|
62
|
-
if (!namesFilterConfigured && !prefixFilterConfigured)
|
|
63
|
-
return true;
|
|
64
|
-
var matchNames = namesFilterConfigured && namesFilter.indexOf(featureFlag.name) > -1;
|
|
65
|
-
var matchPrefix = prefixFilterConfigured && prefixFilter.some(function (prefix) { return (0, lang_1.startsWith)(featureFlag.name, prefix); });
|
|
66
|
-
return matchNames || matchPrefix;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Given the list of splits from /splitChanges endpoint, it returns the mutations,
|
|
70
|
-
* i.e., an object with added splits, removed splits and used segments.
|
|
71
|
-
* Exported for testing purposes.
|
|
72
|
-
*/
|
|
73
|
-
function computeMutation(rules, segments, filters) {
|
|
74
|
-
return rules.reduce(function (accum, ruleEntity) {
|
|
75
|
-
if (ruleEntity.status !== 'ARCHIVED' && (!filters || matchFilters(ruleEntity, filters))) {
|
|
76
|
-
accum.added.push(ruleEntity);
|
|
77
|
-
parseSegments(ruleEntity).forEach(function (segmentName) {
|
|
78
|
-
segments.add(segmentName);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
accum.removed.push(ruleEntity);
|
|
83
|
-
}
|
|
84
|
-
accum.names.push(ruleEntity.name);
|
|
85
|
-
return accum;
|
|
86
|
-
}, { added: [], removed: [], names: [] });
|
|
87
|
-
}
|
|
88
|
-
exports.computeMutation = computeMutation;
|
|
89
|
-
/**
|
|
90
|
-
* factory of SplitChanges updater, a task that:
|
|
91
|
-
* - fetches split changes using `splitChangesFetcher`
|
|
92
|
-
* - updates `splitsCache`
|
|
93
|
-
* - uses `splitsEventEmitter` to emit events related to split data updates
|
|
94
|
-
*
|
|
95
|
-
* @param log - Logger instance
|
|
96
|
-
* @param splitChangesFetcher - Fetcher of `/splitChanges`
|
|
97
|
-
* @param splits - Splits storage, with sync or async methods
|
|
98
|
-
* @param segments - Segments storage, with sync or async methods
|
|
99
|
-
* @param splitsEventEmitter - Optional readiness manager. Not required for synchronizer or producer mode.
|
|
100
|
-
* @param requestTimeoutBeforeReady - How long the updater will wait for the request to timeout. Default 0, i.e., never timeout.
|
|
101
|
-
* @param retriesOnFailureBeforeReady - How many retries on `/splitChanges` we the updater do in case of failure or timeout. Default 0, i.e., no retries.
|
|
102
|
-
*/
|
|
103
|
-
function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFiltersValidation, splitsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, isClientSide) {
|
|
104
|
-
if (requestTimeoutBeforeReady === void 0) { requestTimeoutBeforeReady = 0; }
|
|
105
|
-
if (retriesOnFailureBeforeReady === void 0) { retriesOnFailureBeforeReady = 0; }
|
|
106
|
-
var splits = storage.splits, rbSegments = storage.rbSegments, segments = storage.segments;
|
|
107
|
-
var startingUp = true;
|
|
108
|
-
/** timeout decorator for `splitChangesFetcher` promise */
|
|
109
|
-
function _promiseDecorator(promise) {
|
|
110
|
-
if (startingUp && requestTimeoutBeforeReady)
|
|
111
|
-
promise = (0, timeout_1.timeout)(requestTimeoutBeforeReady, promise);
|
|
112
|
-
return promise;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* SplitChanges updater returns a promise that resolves with a `false` boolean value if it fails to fetch splits or synchronize them with the storage.
|
|
116
|
-
* Returned promise will not be rejected.
|
|
117
|
-
*
|
|
118
|
-
* @param noCache - true to revalidate data to fetch
|
|
119
|
-
* @param till - query param to bypass CDN requests
|
|
120
|
-
*/
|
|
121
|
-
return function splitChangesUpdater(noCache, till, instantUpdate) {
|
|
122
|
-
/**
|
|
123
|
-
* @param since - current changeNumber at splitsCache
|
|
124
|
-
* @param retry - current number of retry attempts
|
|
125
|
-
*/
|
|
126
|
-
function _splitChangesUpdater(sinces, retry) {
|
|
127
|
-
if (retry === void 0) { retry = 0; }
|
|
128
|
-
var since = sinces[0], rbSince = sinces[1];
|
|
129
|
-
log.debug(constants_2.SYNC_SPLITS_FETCH, sinces);
|
|
130
|
-
return Promise.resolve(instantUpdate ?
|
|
131
|
-
instantUpdate.type === constants_4.SPLIT_UPDATE ?
|
|
132
|
-
// IFFU edge case: a change to a flag that adds an IN_RULE_BASED_SEGMENT matcher that is not present yet
|
|
133
|
-
Promise.resolve(rbSegments.contains(parseSegments(instantUpdate.payload, constants_3.IN_RULE_BASED_SEGMENT))).then(function (contains) {
|
|
134
|
-
return contains ?
|
|
135
|
-
{ ff: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
|
|
136
|
-
splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator);
|
|
137
|
-
}) :
|
|
138
|
-
{ rbs: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
|
|
139
|
-
splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator))
|
|
140
|
-
.then(function (splitChanges) {
|
|
141
|
-
var usedSegments = new Set();
|
|
142
|
-
var updatedFlags = [];
|
|
143
|
-
var ffUpdate = false;
|
|
144
|
-
if (splitChanges.ff) {
|
|
145
|
-
var _a = computeMutation(splitChanges.ff.d || [], usedSegments, splitFiltersValidation), added = _a.added, removed = _a.removed, names = _a.names;
|
|
146
|
-
updatedFlags = names;
|
|
147
|
-
log.debug(constants_2.SYNC_SPLITS_UPDATE, [added.length, removed.length]);
|
|
148
|
-
ffUpdate = splits.update(added, removed, splitChanges.ff.t);
|
|
149
|
-
}
|
|
150
|
-
var rbsUpdate = false;
|
|
151
|
-
if (splitChanges.rbs) {
|
|
152
|
-
var _b = computeMutation(splitChanges.rbs.d || [], usedSegments), added = _b.added, removed = _b.removed;
|
|
153
|
-
log.debug(constants_2.SYNC_RBS_UPDATE, [added.length, removed.length]);
|
|
154
|
-
rbsUpdate = rbSegments.update(added, removed, splitChanges.rbs.t);
|
|
155
|
-
}
|
|
156
|
-
return Promise.all([ffUpdate, rbsUpdate,
|
|
157
|
-
// @TODO if at least 1 segment fetch fails due to 404 and other segments are updated in the storage, SDK_UPDATE is not emitted
|
|
158
|
-
segments.registerSegments((0, sets_1.setToArray)(usedSegments))
|
|
159
|
-
]).then(function (_a) {
|
|
160
|
-
var ffChanged = _a[0], rbsChanged = _a[1];
|
|
161
|
-
if (storage.save)
|
|
162
|
-
storage.save();
|
|
163
|
-
startingUp = false;
|
|
164
|
-
if (splitsEventEmitter) {
|
|
165
|
-
// To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
|
|
166
|
-
return Promise.resolve(!splitsEventEmitter.splitsArrived || ((ffChanged || rbsChanged) && (isClientSide || checkAllSegmentsExist(segments))))
|
|
167
|
-
.catch(function () { return false; } /** noop. just to handle a possible `checkAllSegmentsExist` rejection, before emitting SDK event */)
|
|
168
|
-
.then(function (emitSplitsArrivedEvent) {
|
|
169
|
-
// emit SDK events
|
|
170
|
-
if (emitSplitsArrivedEvent) {
|
|
171
|
-
var metadata = {
|
|
172
|
-
type: updatedFlags.length > 0 ? constants_1.FLAGS_UPDATE : constants_1.SEGMENTS_UPDATE,
|
|
173
|
-
names: updatedFlags.length > 0 ? updatedFlags : []
|
|
174
|
-
};
|
|
175
|
-
splitsEventEmitter.emit(constants_1.SDK_SPLITS_ARRIVED, metadata);
|
|
176
|
-
}
|
|
177
|
-
return true;
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return true;
|
|
181
|
-
});
|
|
182
|
-
})
|
|
183
|
-
.catch(function (error) {
|
|
184
|
-
if (startingUp && retriesOnFailureBeforeReady > retry) {
|
|
185
|
-
retry += 1;
|
|
186
|
-
log.warn(constants_2.SYNC_SPLITS_FETCH_RETRY, [retry, error]);
|
|
187
|
-
return _splitChangesUpdater(sinces, retry);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
startingUp = false;
|
|
191
|
-
log.warn(constants_2.SYNC_SPLITS_FETCH_FAILS, [error]);
|
|
192
|
-
}
|
|
193
|
-
return false;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
// `getChangeNumber` never rejects or throws error
|
|
197
|
-
return Promise.all([splits.getChangeNumber(), rbSegments.getChangeNumber()]).then(_splitChangesUpdater);
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
exports.splitChangesUpdaterFactory = splitChangesUpdaterFactory;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateSplits = void 0;
|
|
4
|
-
var constants_1 = require("../../logger/constants");
|
|
5
|
-
var lang_1 = require("../lang");
|
|
6
|
-
var split_1 = require("./split");
|
|
7
|
-
function validateSplits(log, maybeSplits, method, listName, item) {
|
|
8
|
-
if (listName === void 0) { listName = 'feature flag names'; }
|
|
9
|
-
if (item === void 0) { item = 'feature flag name'; }
|
|
10
|
-
if (Array.isArray(maybeSplits) && maybeSplits.length > 0) {
|
|
11
|
-
var validatedArray_1 = [];
|
|
12
|
-
// Remove invalid values
|
|
13
|
-
maybeSplits.forEach(function (maybeSplit) {
|
|
14
|
-
var splitName = (0, split_1.validateSplit)(log, maybeSplit, method, item);
|
|
15
|
-
if (splitName)
|
|
16
|
-
validatedArray_1.push(splitName);
|
|
17
|
-
});
|
|
18
|
-
// Strip off duplicated values if we have valid split names then return
|
|
19
|
-
if (validatedArray_1.length)
|
|
20
|
-
return (0, lang_1.uniq)(validatedArray_1);
|
|
21
|
-
}
|
|
22
|
-
log.error(constants_1.ERROR_EMPTY_ARRAY, [method, listName]);
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
exports.validateSplits = validateSplits;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
/**
|
|
3
|
-
* This class provides a skeletal implementation of the ISplitsCacheAsync interface
|
|
4
|
-
* to minimize the effort required to implement this interface.
|
|
5
|
-
*/
|
|
6
|
-
var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
7
|
-
function AbstractSplitsCacheAsync() {
|
|
8
|
-
}
|
|
9
|
-
AbstractSplitsCacheAsync.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
10
|
-
var _this = this;
|
|
11
|
-
return Promise.all([
|
|
12
|
-
this.setChangeNumber(changeNumber),
|
|
13
|
-
Promise.all(toAdd.map(function (addedFF) { return _this.addSplit(addedFF); })),
|
|
14
|
-
Promise.all(toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }))
|
|
15
|
-
]).then(function (_a) {
|
|
16
|
-
var added = _a[1], removed = _a[2];
|
|
17
|
-
return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
// @TODO revisit segment-related methods ('usesSegments', 'getRegisteredSegments', 'registerSegments')
|
|
21
|
-
// noop, just keeping the interface. This is used by standalone client-side API only, and so only implemented by InMemory and InLocalStorage.
|
|
22
|
-
AbstractSplitsCacheAsync.prototype.usesSegments = function () {
|
|
23
|
-
return Promise.resolve(true);
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
27
|
-
* Used for SPLIT_KILL push notifications.
|
|
28
|
-
*
|
|
29
|
-
* @returns a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the operation successed updating the split or `false` if no split is updated,
|
|
30
|
-
* for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
|
|
31
|
-
* The promise will never be rejected.
|
|
32
|
-
*/
|
|
33
|
-
AbstractSplitsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
34
|
-
var _this = this;
|
|
35
|
-
return this.getSplit(name).then(function (split) {
|
|
36
|
-
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
37
|
-
var newSplit = objectAssign({}, split);
|
|
38
|
-
newSplit.killed = true;
|
|
39
|
-
newSplit.defaultTreatment = defaultTreatment;
|
|
40
|
-
newSplit.changeNumber = changeNumber;
|
|
41
|
-
return _this.addSplit(newSplit);
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}).catch(function () { return false; });
|
|
45
|
-
};
|
|
46
|
-
return AbstractSplitsCacheAsync;
|
|
47
|
-
}());
|
|
48
|
-
export { AbstractSplitsCacheAsync };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import { IN_SEGMENT, IN_LARGE_SEGMENT } from '../utils/constants';
|
|
3
|
-
/**
|
|
4
|
-
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
5
|
-
* to minimize the effort required to implement this interface.
|
|
6
|
-
*/
|
|
7
|
-
var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
8
|
-
function AbstractSplitsCacheSync() {
|
|
9
|
-
}
|
|
10
|
-
AbstractSplitsCacheSync.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
11
|
-
var _this = this;
|
|
12
|
-
var updated = toAdd.map(function (addedFF) { return _this.addSplit(addedFF); }).some(function (result) { return result; });
|
|
13
|
-
updated = toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }).some(function (result) { return result; }) || updated;
|
|
14
|
-
this.setChangeNumber(changeNumber);
|
|
15
|
-
return updated;
|
|
16
|
-
};
|
|
17
|
-
AbstractSplitsCacheSync.prototype.getSplits = function (names) {
|
|
18
|
-
var _this = this;
|
|
19
|
-
var splits = {};
|
|
20
|
-
names.forEach(function (name) {
|
|
21
|
-
splits[name] = _this.getSplit(name);
|
|
22
|
-
});
|
|
23
|
-
return splits;
|
|
24
|
-
};
|
|
25
|
-
AbstractSplitsCacheSync.prototype.getAll = function () {
|
|
26
|
-
var _this = this;
|
|
27
|
-
return this.getSplitNames().map(function (key) { return _this.getSplit(key); });
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
31
|
-
* Used for SPLIT_KILL push notifications.
|
|
32
|
-
*
|
|
33
|
-
* @returns `true` if the operation successed updating the split, or `false` if no split is updated,
|
|
34
|
-
* for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
|
|
35
|
-
*/
|
|
36
|
-
AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
37
|
-
var split = this.getSplit(name);
|
|
38
|
-
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
39
|
-
var newSplit = objectAssign({}, split);
|
|
40
|
-
newSplit.killed = true;
|
|
41
|
-
newSplit.defaultTreatment = defaultTreatment;
|
|
42
|
-
newSplit.changeNumber = changeNumber;
|
|
43
|
-
return this.addSplit(newSplit);
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
46
|
-
};
|
|
47
|
-
return AbstractSplitsCacheSync;
|
|
48
|
-
}());
|
|
49
|
-
export { AbstractSplitsCacheSync };
|
|
50
|
-
/**
|
|
51
|
-
* Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
|
|
52
|
-
* This util is intended to simplify the implementation of `splitsCache::usesSegments` method
|
|
53
|
-
*/
|
|
54
|
-
export function usesSegments(ruleEntity) {
|
|
55
|
-
var conditions = ruleEntity.conditions || [];
|
|
56
|
-
for (var i = 0; i < conditions.length; i++) {
|
|
57
|
-
var matchers = conditions[i].matcherGroup.matchers;
|
|
58
|
-
for (var j = 0; j < matchers.length; j++) {
|
|
59
|
-
var matcher = matchers[j].matcherType;
|
|
60
|
-
if (matcher === IN_SEGMENT || matcher === IN_LARGE_SEGMENT)
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
var excluded = ruleEntity.excluded;
|
|
65
|
-
if (excluded && excluded.segments && excluded.segments.length > 0)
|
|
66
|
-
return true;
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
export function usesSegmentsSync(storage) {
|
|
70
|
-
return storage.splits.usesSegments() || storage.rbSegments.usesSegments();
|
|
71
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
|
-
import { AbstractSplitsCacheSync, usesSegments } from '../AbstractSplitsCacheSync';
|
|
3
|
-
import { isFiniteNumber, toNumber, isNaNNumber } from '../../utils/lang';
|
|
4
|
-
import { LOG_PREFIX } from './constants';
|
|
5
|
-
import { setToArray } from '../../utils/lang/sets';
|
|
6
|
-
var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
7
|
-
__extends(SplitsCacheInLocal, _super);
|
|
8
|
-
function SplitsCacheInLocal(settings, keys, storage) {
|
|
9
|
-
var _this = _super.call(this) || this;
|
|
10
|
-
_this.keys = keys;
|
|
11
|
-
_this.log = settings.log;
|
|
12
|
-
_this.flagSetsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
13
|
-
_this.storage = storage;
|
|
14
|
-
return _this;
|
|
15
|
-
}
|
|
16
|
-
SplitsCacheInLocal.prototype._decrementCount = function (key) {
|
|
17
|
-
var count = toNumber(this.storage.getItem(key)) - 1;
|
|
18
|
-
if (count > 0)
|
|
19
|
-
this.storage.setItem(key, count + '');
|
|
20
|
-
else
|
|
21
|
-
this.storage.removeItem(key);
|
|
22
|
-
};
|
|
23
|
-
SplitsCacheInLocal.prototype._decrementCounts = function (split) {
|
|
24
|
-
try {
|
|
25
|
-
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
26
|
-
this._decrementCount(ttKey);
|
|
27
|
-
if (usesSegments(split)) {
|
|
28
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
29
|
-
this._decrementCount(segmentsCountKey);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
this.log.error(LOG_PREFIX + e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
SplitsCacheInLocal.prototype._incrementCounts = function (split) {
|
|
37
|
-
try {
|
|
38
|
-
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
39
|
-
this.storage.setItem(ttKey, (toNumber(this.storage.getItem(ttKey)) + 1) + '');
|
|
40
|
-
if (usesSegments(split)) {
|
|
41
|
-
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
42
|
-
this.storage.setItem(segmentsCountKey, (toNumber(this.storage.getItem(segmentsCountKey)) + 1) + '');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
this.log.error(LOG_PREFIX + e);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Removes all splits cache related data from localStorage (splits, counters, changeNumber and lastUpdated).
|
|
51
|
-
* We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
|
|
52
|
-
*/
|
|
53
|
-
SplitsCacheInLocal.prototype.clear = function () {
|
|
54
|
-
var _this = this;
|
|
55
|
-
// collect item keys
|
|
56
|
-
var len = this.storage.length;
|
|
57
|
-
var accum = [];
|
|
58
|
-
for (var cur = 0; cur < len; cur++) {
|
|
59
|
-
var key = this.storage.key(cur);
|
|
60
|
-
if (key != null && this.keys.isSplitsCacheKey(key))
|
|
61
|
-
accum.push(key);
|
|
62
|
-
}
|
|
63
|
-
// remove items
|
|
64
|
-
accum.forEach(function (key) {
|
|
65
|
-
_this.storage.removeItem(key);
|
|
66
|
-
});
|
|
67
|
-
this.hasSync = false;
|
|
68
|
-
};
|
|
69
|
-
SplitsCacheInLocal.prototype.addSplit = function (split) {
|
|
70
|
-
var name = split.name;
|
|
71
|
-
var splitKey = this.keys.buildSplitKey(name);
|
|
72
|
-
var splitFromStorage = this.storage.getItem(splitKey);
|
|
73
|
-
var previousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : null;
|
|
74
|
-
if (previousSplit) {
|
|
75
|
-
this._decrementCounts(previousSplit);
|
|
76
|
-
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
77
|
-
}
|
|
78
|
-
this.storage.setItem(splitKey, JSON.stringify(split));
|
|
79
|
-
this._incrementCounts(split);
|
|
80
|
-
this.addToFlagSets(split);
|
|
81
|
-
return true;
|
|
82
|
-
};
|
|
83
|
-
SplitsCacheInLocal.prototype.removeSplit = function (name) {
|
|
84
|
-
var split = this.getSplit(name);
|
|
85
|
-
if (!split)
|
|
86
|
-
return false;
|
|
87
|
-
this.storage.removeItem(this.keys.buildSplitKey(name));
|
|
88
|
-
this._decrementCounts(split);
|
|
89
|
-
this.removeFromFlagSets(split.name, split.sets);
|
|
90
|
-
return true;
|
|
91
|
-
};
|
|
92
|
-
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
93
|
-
var item = this.storage.getItem(this.keys.buildSplitKey(name));
|
|
94
|
-
return item && JSON.parse(item);
|
|
95
|
-
};
|
|
96
|
-
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
97
|
-
try {
|
|
98
|
-
this.storage.setItem(this.keys.buildSplitsTillKey(), changeNumber + '');
|
|
99
|
-
// update "last updated" timestamp with current time
|
|
100
|
-
this.storage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
|
|
101
|
-
this.hasSync = true;
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
catch (e) {
|
|
105
|
-
this.log.error(LOG_PREFIX + e);
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
SplitsCacheInLocal.prototype.getChangeNumber = function () {
|
|
110
|
-
var n = -1;
|
|
111
|
-
var value = this.storage.getItem(this.keys.buildSplitsTillKey());
|
|
112
|
-
if (value !== null) {
|
|
113
|
-
value = parseInt(value, 10);
|
|
114
|
-
return isNaNNumber(value) ? n : value;
|
|
115
|
-
}
|
|
116
|
-
return n;
|
|
117
|
-
};
|
|
118
|
-
SplitsCacheInLocal.prototype.getSplitNames = function () {
|
|
119
|
-
var len = this.storage.length;
|
|
120
|
-
var accum = [];
|
|
121
|
-
var cur = 0;
|
|
122
|
-
while (cur < len) {
|
|
123
|
-
var key = this.storage.key(cur);
|
|
124
|
-
if (key != null && this.keys.isSplitKey(key))
|
|
125
|
-
accum.push(this.keys.extractKey(key));
|
|
126
|
-
cur++;
|
|
127
|
-
}
|
|
128
|
-
return accum;
|
|
129
|
-
};
|
|
130
|
-
SplitsCacheInLocal.prototype.trafficTypeExists = function (trafficType) {
|
|
131
|
-
var ttCount = toNumber(this.storage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
|
|
132
|
-
return isFiniteNumber(ttCount) && ttCount > 0;
|
|
133
|
-
};
|
|
134
|
-
SplitsCacheInLocal.prototype.usesSegments = function () {
|
|
135
|
-
// If cache hasn't been synchronized with the cloud, assume we need them.
|
|
136
|
-
if (!this.hasSync)
|
|
137
|
-
return true;
|
|
138
|
-
var storedCount = this.storage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
139
|
-
var splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
140
|
-
return isFiniteNumber(splitsWithSegmentsCount) ?
|
|
141
|
-
splitsWithSegmentsCount > 0 :
|
|
142
|
-
true;
|
|
143
|
-
};
|
|
144
|
-
SplitsCacheInLocal.prototype.getNamesByFlagSets = function (flagSets) {
|
|
145
|
-
var _this = this;
|
|
146
|
-
return flagSets.map(function (flagSet) {
|
|
147
|
-
var flagSetKey = _this.keys.buildFlagSetKey(flagSet);
|
|
148
|
-
var flagSetFromStorage = _this.storage.getItem(flagSetKey);
|
|
149
|
-
return new Set(flagSetFromStorage ? JSON.parse(flagSetFromStorage) : []);
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
SplitsCacheInLocal.prototype.addToFlagSets = function (featureFlag) {
|
|
153
|
-
var _this = this;
|
|
154
|
-
if (!featureFlag.sets)
|
|
155
|
-
return;
|
|
156
|
-
featureFlag.sets.forEach(function (featureFlagSet) {
|
|
157
|
-
if (_this.flagSetsFilter.length > 0 && !_this.flagSetsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
|
|
158
|
-
return;
|
|
159
|
-
var flagSetKey = _this.keys.buildFlagSetKey(featureFlagSet);
|
|
160
|
-
var flagSetFromStorage = _this.storage.getItem(flagSetKey);
|
|
161
|
-
var flagSetCache = new Set(flagSetFromStorage ? JSON.parse(flagSetFromStorage) : []);
|
|
162
|
-
if (flagSetCache.has(featureFlag.name))
|
|
163
|
-
return;
|
|
164
|
-
flagSetCache.add(featureFlag.name);
|
|
165
|
-
_this.storage.setItem(flagSetKey, JSON.stringify(setToArray(flagSetCache)));
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
SplitsCacheInLocal.prototype.removeFromFlagSets = function (featureFlagName, flagSets) {
|
|
169
|
-
var _this = this;
|
|
170
|
-
if (!flagSets)
|
|
171
|
-
return;
|
|
172
|
-
flagSets.forEach(function (flagSet) {
|
|
173
|
-
_this.removeNames(flagSet, featureFlagName);
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
SplitsCacheInLocal.prototype.removeNames = function (flagSetName, featureFlagName) {
|
|
177
|
-
var flagSetKey = this.keys.buildFlagSetKey(flagSetName);
|
|
178
|
-
var flagSetFromStorage = this.storage.getItem(flagSetKey);
|
|
179
|
-
if (!flagSetFromStorage)
|
|
180
|
-
return;
|
|
181
|
-
var flagSetCache = new Set(JSON.parse(flagSetFromStorage));
|
|
182
|
-
flagSetCache.delete(featureFlagName);
|
|
183
|
-
if (flagSetCache.size === 0) {
|
|
184
|
-
this.storage.removeItem(flagSetKey);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
this.storage.setItem(flagSetKey, JSON.stringify(setToArray(flagSetCache)));
|
|
188
|
-
};
|
|
189
|
-
return SplitsCacheInLocal;
|
|
190
|
-
}(AbstractSplitsCacheSync));
|
|
191
|
-
export { SplitsCacheInLocal };
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
|
-
import { AbstractSplitsCacheSync, usesSegments } from '../AbstractSplitsCacheSync';
|
|
3
|
-
import { isFiniteNumber } from '../../utils/lang';
|
|
4
|
-
/**
|
|
5
|
-
* Default ISplitsCacheSync implementation that stores split definitions in memory.
|
|
6
|
-
*/
|
|
7
|
-
var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
8
|
-
__extends(SplitsCacheInMemory, _super);
|
|
9
|
-
function SplitsCacheInMemory(splitFiltersValidation) {
|
|
10
|
-
var _this = _super.call(this) || this;
|
|
11
|
-
_this.splitsCache = {};
|
|
12
|
-
_this.ttCache = {};
|
|
13
|
-
_this.changeNumber = -1;
|
|
14
|
-
_this.segmentsCount = 0;
|
|
15
|
-
_this.flagSetsCache = {};
|
|
16
|
-
_this.flagSetsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
17
|
-
return _this;
|
|
18
|
-
}
|
|
19
|
-
SplitsCacheInMemory.prototype.clear = function () {
|
|
20
|
-
this.splitsCache = {};
|
|
21
|
-
this.ttCache = {};
|
|
22
|
-
this.changeNumber = -1;
|
|
23
|
-
this.segmentsCount = 0;
|
|
24
|
-
this.flagSetsCache = {};
|
|
25
|
-
};
|
|
26
|
-
SplitsCacheInMemory.prototype.addSplit = function (split) {
|
|
27
|
-
var name = split.name;
|
|
28
|
-
var previousSplit = this.getSplit(name);
|
|
29
|
-
if (previousSplit) { // We had this Split already
|
|
30
|
-
var previousTtName = previousSplit.trafficTypeName;
|
|
31
|
-
this.ttCache[previousTtName]--;
|
|
32
|
-
if (!this.ttCache[previousTtName])
|
|
33
|
-
delete this.ttCache[previousTtName];
|
|
34
|
-
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
35
|
-
// Subtract from segments count for the previous version of this Split
|
|
36
|
-
if (usesSegments(previousSplit))
|
|
37
|
-
this.segmentsCount--;
|
|
38
|
-
}
|
|
39
|
-
// Store the Split.
|
|
40
|
-
this.splitsCache[name] = split;
|
|
41
|
-
// Update TT cache
|
|
42
|
-
var ttName = split.trafficTypeName;
|
|
43
|
-
this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
|
|
44
|
-
this.addToFlagSets(split);
|
|
45
|
-
// Add to segments count for the new version of the Split
|
|
46
|
-
if (usesSegments(split))
|
|
47
|
-
this.segmentsCount++;
|
|
48
|
-
return true;
|
|
49
|
-
};
|
|
50
|
-
SplitsCacheInMemory.prototype.removeSplit = function (name) {
|
|
51
|
-
var split = this.getSplit(name);
|
|
52
|
-
if (!split)
|
|
53
|
-
return false;
|
|
54
|
-
// Delete the Split
|
|
55
|
-
delete this.splitsCache[name];
|
|
56
|
-
var ttName = split.trafficTypeName;
|
|
57
|
-
this.ttCache[ttName]--; // Update tt cache
|
|
58
|
-
if (!this.ttCache[ttName])
|
|
59
|
-
delete this.ttCache[ttName];
|
|
60
|
-
this.removeFromFlagSets(split.name, split.sets);
|
|
61
|
-
// Update the segments count.
|
|
62
|
-
if (usesSegments(split))
|
|
63
|
-
this.segmentsCount--;
|
|
64
|
-
return true;
|
|
65
|
-
};
|
|
66
|
-
SplitsCacheInMemory.prototype.getSplit = function (name) {
|
|
67
|
-
return this.splitsCache[name] || null;
|
|
68
|
-
};
|
|
69
|
-
SplitsCacheInMemory.prototype.setChangeNumber = function (changeNumber) {
|
|
70
|
-
this.changeNumber = changeNumber;
|
|
71
|
-
return true;
|
|
72
|
-
};
|
|
73
|
-
SplitsCacheInMemory.prototype.getChangeNumber = function () {
|
|
74
|
-
return this.changeNumber;
|
|
75
|
-
};
|
|
76
|
-
SplitsCacheInMemory.prototype.getSplitNames = function () {
|
|
77
|
-
return Object.keys(this.splitsCache);
|
|
78
|
-
};
|
|
79
|
-
SplitsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
|
|
80
|
-
return isFiniteNumber(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
|
|
81
|
-
};
|
|
82
|
-
SplitsCacheInMemory.prototype.usesSegments = function () {
|
|
83
|
-
return this.getChangeNumber() === -1 || this.segmentsCount > 0;
|
|
84
|
-
};
|
|
85
|
-
SplitsCacheInMemory.prototype.getNamesByFlagSets = function (flagSets) {
|
|
86
|
-
var _this = this;
|
|
87
|
-
return flagSets.map(function (flagSet) { return _this.flagSetsCache[flagSet] || new Set(); });
|
|
88
|
-
};
|
|
89
|
-
SplitsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
|
|
90
|
-
var _this = this;
|
|
91
|
-
if (!featureFlag.sets)
|
|
92
|
-
return;
|
|
93
|
-
featureFlag.sets.forEach(function (featureFlagSet) {
|
|
94
|
-
if (_this.flagSetsFilter.length > 0 && !_this.flagSetsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
|
|
95
|
-
return;
|
|
96
|
-
if (!_this.flagSetsCache[featureFlagSet])
|
|
97
|
-
_this.flagSetsCache[featureFlagSet] = new Set([]);
|
|
98
|
-
_this.flagSetsCache[featureFlagSet].add(featureFlag.name);
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
SplitsCacheInMemory.prototype.removeFromFlagSets = function (featureFlagName, flagSets) {
|
|
102
|
-
var _this = this;
|
|
103
|
-
if (!flagSets)
|
|
104
|
-
return;
|
|
105
|
-
flagSets.forEach(function (flagSet) {
|
|
106
|
-
_this.removeNames(flagSet, featureFlagName);
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
SplitsCacheInMemory.prototype.removeNames = function (flagSetName, featureFlagName) {
|
|
110
|
-
if (!this.flagSetsCache[flagSetName])
|
|
111
|
-
return;
|
|
112
|
-
this.flagSetsCache[flagSetName].delete(featureFlagName);
|
|
113
|
-
if (this.flagSetsCache[flagSetName].size === 0)
|
|
114
|
-
delete this.flagSetsCache[flagSetName];
|
|
115
|
-
};
|
|
116
|
-
return SplitsCacheInMemory;
|
|
117
|
-
}(AbstractSplitsCacheSync));
|
|
118
|
-
export { SplitsCacheInMemory };
|