@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
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.definitionChangesUpdaterFactory = 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
|
+
var thenable_1 = require("../../../utils/promise/thenable");
|
|
12
|
+
/**
|
|
13
|
+
* Collect segments from a raw FF or RBS definition.
|
|
14
|
+
* Exported for testing purposes.
|
|
15
|
+
*/
|
|
16
|
+
function parseSegments(ruleEntity, matcherType) {
|
|
17
|
+
if (matcherType === void 0) { matcherType = constants_3.IN_SEGMENT; }
|
|
18
|
+
var _a = ruleEntity, conditions = _a.conditions, excluded = _a.excluded;
|
|
19
|
+
var segments = new Set();
|
|
20
|
+
if (excluded && excluded.segments) {
|
|
21
|
+
excluded.segments.forEach(function (_a) {
|
|
22
|
+
var type = _a.type, name = _a.name;
|
|
23
|
+
if ((type === constants_3.STANDARD_SEGMENT && matcherType === constants_3.IN_SEGMENT) || (type === constants_3.RULE_BASED_SEGMENT && matcherType === constants_3.IN_RULE_BASED_SEGMENT)) {
|
|
24
|
+
segments.add(name);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (conditions) {
|
|
29
|
+
for (var i = 0; i < conditions.length; i++) {
|
|
30
|
+
var matchers = conditions[i].matcherGroup.matchers;
|
|
31
|
+
matchers.forEach(function (matcher) {
|
|
32
|
+
if (matcher.matcherType === matcherType)
|
|
33
|
+
segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return segments;
|
|
38
|
+
}
|
|
39
|
+
exports.parseSegments = parseSegments;
|
|
40
|
+
/**
|
|
41
|
+
* If there are defined filters and one definition doesn't match with them, its status is changed to 'ARCHIVE' to avoid storing it
|
|
42
|
+
* If there is `bySet` filter, `byName` and `byPrefix` filters are ignored
|
|
43
|
+
*
|
|
44
|
+
* @param definition - definition to be evaluated
|
|
45
|
+
* @param filters - splitFiltersValidation bySet | byName
|
|
46
|
+
*/
|
|
47
|
+
function matchFilters(definition, filters) {
|
|
48
|
+
var _a = filters.groupedFilters, setsFilter = _a.bySet, namesFilter = _a.byName, prefixFilter = _a.byPrefix;
|
|
49
|
+
if (setsFilter.length > 0)
|
|
50
|
+
return definition.sets && definition.sets.some(function (definitionSet) { return setsFilter.indexOf(definitionSet) > -1; });
|
|
51
|
+
var namesFilterConfigured = namesFilter.length > 0;
|
|
52
|
+
var prefixFilterConfigured = prefixFilter.length > 0;
|
|
53
|
+
if (!namesFilterConfigured && !prefixFilterConfigured)
|
|
54
|
+
return true;
|
|
55
|
+
var matchNames = namesFilterConfigured && namesFilter.indexOf(definition.name) > -1;
|
|
56
|
+
var matchPrefix = prefixFilterConfigured && prefixFilter.some(function (prefix) { return (0, lang_1.startsWith)(definition.name, prefix); });
|
|
57
|
+
return matchNames || matchPrefix;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Given the list of definitions from /splitChanges or /configs endpoint, it returns the mutations,
|
|
61
|
+
* i.e., an object with added definitions, removed definitions, and used segments.
|
|
62
|
+
* Exported for testing purposes.
|
|
63
|
+
*/
|
|
64
|
+
function computeMutation(update, segments, filters) {
|
|
65
|
+
return update.updated.reduce(function (accum, ruleEntity) {
|
|
66
|
+
if (!filters || matchFilters(ruleEntity, filters)) {
|
|
67
|
+
accum.updated.push(ruleEntity);
|
|
68
|
+
parseSegments(ruleEntity).forEach(function (segmentName) {
|
|
69
|
+
segments.add(segmentName);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
accum.removed.push(ruleEntity.name);
|
|
74
|
+
}
|
|
75
|
+
accum.names.push(ruleEntity.name);
|
|
76
|
+
return accum;
|
|
77
|
+
}, { updated: [], removed: update.removed, names: update.removed.slice() });
|
|
78
|
+
}
|
|
79
|
+
exports.computeMutation = computeMutation;
|
|
80
|
+
function convertInstantUpdateToDefinitionChanges(instantUpdate) {
|
|
81
|
+
var payload = instantUpdate.payload, changeNumber = instantUpdate.changeNumber;
|
|
82
|
+
return payload.status === 'ARCHIVED' ?
|
|
83
|
+
{ till: changeNumber, updated: [], removed: [payload.name] } :
|
|
84
|
+
{ till: changeNumber, updated: [payload], removed: [] };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Factory of DefinitionChanges updater, a task that:
|
|
88
|
+
* - fetches definition changes using `definitionChangesFetcher`
|
|
89
|
+
* - updates definitions storage
|
|
90
|
+
* - uses `definitionsEventEmitter` to emit events related to definition data updates
|
|
91
|
+
*
|
|
92
|
+
* @param log - Logger instance
|
|
93
|
+
* @param definitionChangesFetcher - Fetcher of `/splitChanges` or `/configs`
|
|
94
|
+
* @param definitions - Definitions storage, with sync or async methods
|
|
95
|
+
* @param segments - Segments storage, with sync or async methods
|
|
96
|
+
* @param definitionsEventEmitter - Optional readiness manager. Not required for synchronizer or producer mode.
|
|
97
|
+
* @param requestTimeoutBeforeReady - How long the updater will wait for the request to timeout. Default 0, i.e., never timeout.
|
|
98
|
+
* @param retriesOnFailureBeforeReady - How many retries on `/splitChanges` or `/configs` we the updater do in case of failure or timeout. Default 0, i.e., no retries.
|
|
99
|
+
*/
|
|
100
|
+
function definitionChangesUpdaterFactory(log, definitionChangesFetcher, storage, splitFiltersValidation, definitionsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, segmentsSyncTask // undefined for client-side
|
|
101
|
+
) {
|
|
102
|
+
if (requestTimeoutBeforeReady === void 0) { requestTimeoutBeforeReady = 0; }
|
|
103
|
+
if (retriesOnFailureBeforeReady === void 0) { retriesOnFailureBeforeReady = 0; }
|
|
104
|
+
var definitions = storage.definitions, rbSegments = storage.rbSegments, segments = storage.segments;
|
|
105
|
+
var startingUp = true;
|
|
106
|
+
/** timeout decorator for `definitionChangesFetcher` promise */
|
|
107
|
+
function _promiseDecorator(promise) {
|
|
108
|
+
if (startingUp && requestTimeoutBeforeReady)
|
|
109
|
+
promise = (0, timeout_1.timeout)(requestTimeoutBeforeReady, promise);
|
|
110
|
+
return promise;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* DefinitionChanges updater returns a promise that resolves with a `false` boolean value if it fails to fetch definitions or synchronize them with the storage.
|
|
114
|
+
* Returned promise will not be rejected.
|
|
115
|
+
*
|
|
116
|
+
* @param noCache - true to revalidate data to fetch
|
|
117
|
+
* @param till - query param to bypass CDN requests
|
|
118
|
+
*/
|
|
119
|
+
return function definitionChangesUpdater(noCache, till, instantUpdate, pcns) {
|
|
120
|
+
/**
|
|
121
|
+
* @param since - current changeNumber at definitionsCache
|
|
122
|
+
* @param retry - current number of retry attempts
|
|
123
|
+
*/
|
|
124
|
+
function _definitionChangesUpdater(sinces, retry) {
|
|
125
|
+
if (retry === void 0) { retry = 0; }
|
|
126
|
+
var since = sinces[0], rbSince = sinces[1];
|
|
127
|
+
// If provided, `since` and `rbSince` must not be higher than it, to avoid missing an update that the scoped `pcn` indicates hasn't been fetched yet.
|
|
128
|
+
if (pcns) {
|
|
129
|
+
if (pcns.since !== undefined && pcns.since < since)
|
|
130
|
+
since = pcns.since;
|
|
131
|
+
if (pcns.rbSince !== undefined && pcns.rbSince < rbSince)
|
|
132
|
+
rbSince = pcns.rbSince;
|
|
133
|
+
}
|
|
134
|
+
var definitionChangesRequest = instantUpdate ?
|
|
135
|
+
instantUpdate.type === constants_4.RB_SEGMENT_UPDATE ?
|
|
136
|
+
{ rbs: convertInstantUpdateToDefinitionChanges(instantUpdate) } :
|
|
137
|
+
// IFFU edge case: a change to definition that adds an IN_RULE_BASED_SEGMENT matcher that is not present yet
|
|
138
|
+
Promise.resolve(rbSegments.contains(parseSegments(instantUpdate.payload, constants_3.IN_RULE_BASED_SEGMENT))).then(function (contains) {
|
|
139
|
+
return contains ?
|
|
140
|
+
{ d: convertInstantUpdateToDefinitionChanges(instantUpdate) } :
|
|
141
|
+
definitionChangesFetcher(since, noCache, till, rbSince, _promiseDecorator);
|
|
142
|
+
}) :
|
|
143
|
+
definitionChangesFetcher(since, noCache, till, rbSince, _promiseDecorator);
|
|
144
|
+
if ((0, thenable_1.thenable)(definitionChangesRequest))
|
|
145
|
+
log.debug(constants_2.SYNC_FETCH, [definitionChangesFetcher.type, since, rbSince]);
|
|
146
|
+
return Promise.resolve(definitionChangesRequest)
|
|
147
|
+
.then(function (definitionChanges) {
|
|
148
|
+
var usedSegments = new Set();
|
|
149
|
+
var updatedDefinitions = [];
|
|
150
|
+
var ffUpdate = false;
|
|
151
|
+
if (definitionChanges.d) {
|
|
152
|
+
var _a = computeMutation(definitionChanges.d, usedSegments, splitFiltersValidation), updated = _a.updated, removed = _a.removed, names = _a.names;
|
|
153
|
+
updatedDefinitions = names;
|
|
154
|
+
log.debug(constants_2.SYNC_UPDATE, [definitionChangesFetcher.type, updated.length, removed.length]);
|
|
155
|
+
ffUpdate = definitions.update(updated, removed, definitionChanges.d.till);
|
|
156
|
+
}
|
|
157
|
+
var rbsUpdate = false;
|
|
158
|
+
if (definitionChanges.rbs) {
|
|
159
|
+
var _b = computeMutation(definitionChanges.rbs, usedSegments), updated = _b.updated, removed = _b.removed;
|
|
160
|
+
log.debug(constants_2.SYNC_UPDATE, ['rule-based segments', updated.length, removed.length]);
|
|
161
|
+
rbsUpdate = rbSegments.update(updated, removed, definitionChanges.rbs.till);
|
|
162
|
+
}
|
|
163
|
+
return Promise.all([ffUpdate, rbsUpdate,
|
|
164
|
+
// @TODO if at least 1 segment fetch fails due to 404 and other segments are updated in the storage, SDK_UPDATE is not emitted
|
|
165
|
+
segments.registerSegments((0, sets_1.setToArray)(usedSegments))
|
|
166
|
+
]).then(function (_a) {
|
|
167
|
+
var ffChanged = _a[0], rbsChanged = _a[1];
|
|
168
|
+
if (storage.save)
|
|
169
|
+
storage.save();
|
|
170
|
+
startingUp = false;
|
|
171
|
+
if (definitionsEventEmitter) {
|
|
172
|
+
// To emit SDK_DEFINITIONS_ARRIVED for server-side SDK, we must wait for all registered segments to be fetched
|
|
173
|
+
return Promise.resolve(!definitionsEventEmitter.definitionsArrived || ((ffChanged || rbsChanged) && (!segmentsSyncTask || segmentsSyncTask.execute(true))))
|
|
174
|
+
.catch(function () { return false; } /** noop. just to handle a possible `checkAllSegmentsExist` rejection, before emitting SDK event */)
|
|
175
|
+
.then(function (emitSplitsArrivedEvent) {
|
|
176
|
+
// emit SDK events
|
|
177
|
+
if (emitSplitsArrivedEvent) {
|
|
178
|
+
var metadata = {
|
|
179
|
+
type: updatedDefinitions.length > 0 ? definitionChangesFetcher.type === 'configs' ? constants_1.CONFIGS_UPDATE : constants_1.FLAGS_UPDATE : constants_1.SEGMENTS_UPDATE,
|
|
180
|
+
names: updatedDefinitions.length > 0 ? updatedDefinitions : []
|
|
181
|
+
};
|
|
182
|
+
definitionsEventEmitter.emit(constants_1.SDK_DEFINITIONS_ARRIVED, metadata);
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
});
|
|
189
|
+
})
|
|
190
|
+
.catch(function (error) {
|
|
191
|
+
if (startingUp && retriesOnFailureBeforeReady > retry) {
|
|
192
|
+
retry += 1;
|
|
193
|
+
log.warn(constants_2.SYNC_FETCH_RETRY, [definitionChangesFetcher.type, retry, error]);
|
|
194
|
+
return _definitionChangesUpdater(sinces, retry);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
startingUp = false;
|
|
198
|
+
log.warn(constants_2.SYNC_FETCH_FAILS, [definitionChangesFetcher.type, error]);
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// `getChangeNumber` never rejects or throws error
|
|
204
|
+
return Promise.all([definitions.getChangeNumber(), rbSegments.getChangeNumber()]).then(_definitionChangesUpdater);
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
exports.definitionChangesUpdaterFactory = definitionChangesUpdaterFactory;
|
|
@@ -5,7 +5,7 @@ var timeout_1 = require("../../../utils/promise/timeout");
|
|
|
5
5
|
var constants_1 = require("../../../readiness/constants");
|
|
6
6
|
var constants_2 = require("../../../logger/constants");
|
|
7
7
|
var constants_3 = require("../../streaming/constants");
|
|
8
|
-
var
|
|
8
|
+
var AbstractDefinitionsCacheSync_1 = require("../../../storages/AbstractDefinitionsCacheSync");
|
|
9
9
|
/**
|
|
10
10
|
* factory of MySegments updater, a task that:
|
|
11
11
|
* - fetches mySegments using `mySegmentsFetcher`
|
|
@@ -37,7 +37,7 @@ function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmentsEvent
|
|
|
37
37
|
if (storage.save)
|
|
38
38
|
storage.save();
|
|
39
39
|
// Notify update if required
|
|
40
|
-
if ((0,
|
|
40
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegmentsSync)(storage) && (shouldNotifyUpdate || readyOnAlreadyExistentState)) {
|
|
41
41
|
readyOnAlreadyExistentState = false;
|
|
42
42
|
segmentsEventEmitter.emit(constants_1.SDK_SEGMENTS_ARRIVED, { type: constants_1.SEGMENTS_UPDATE, names: [] });
|
|
43
43
|
}
|
|
@@ -56,7 +56,7 @@ function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmentsEvent
|
|
|
56
56
|
return updaterPromise.catch(function (error) {
|
|
57
57
|
if (startingUp && retriesOnFailureBeforeReady > retry) {
|
|
58
58
|
retry += 1;
|
|
59
|
-
log.warn(constants_2.
|
|
59
|
+
log.warn(constants_2.SYNC_FETCH_RETRY, ['memberships', retry, error]);
|
|
60
60
|
return _mySegmentsUpdater(retry); // no need to forward `segmentList` and `noCache` params
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
@@ -23,7 +23,7 @@ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, read
|
|
|
23
23
|
return promise;
|
|
24
24
|
}
|
|
25
25
|
function updateSegment(segmentName, noCache, till, fetchOnlyNew, retries) {
|
|
26
|
-
log.debug("".concat(constants_2.
|
|
26
|
+
log.debug("".concat(constants_2.LOG_PREFIX_SYNC, "Processing segment ").concat(segmentName));
|
|
27
27
|
var sincePromise = Promise.resolve(segments.getChangeNumber(segmentName));
|
|
28
28
|
return sincePromise.then(function (since) {
|
|
29
29
|
// if fetchOnlyNew flag, avoid processing already fetched segments
|
|
@@ -31,14 +31,14 @@ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, read
|
|
|
31
31
|
false :
|
|
32
32
|
segmentChangesFetcher(since || -1, segmentName, noCache, till, _promiseDecorator).then(function (changes) {
|
|
33
33
|
return Promise.all(changes.map(function (x) {
|
|
34
|
-
log.debug("".concat(constants_2.
|
|
34
|
+
log.debug("".concat(constants_2.LOG_PREFIX_SYNC, "Processing ").concat(segmentName, " with since = ").concat(x.since, " and till = ").concat(x.till, ". Added: ").concat(x.added.length, ". Removed: ").concat(x.removed.length));
|
|
35
35
|
return segments.update(segmentName, x.added, x.removed, x.till);
|
|
36
36
|
})).then(function (updates) {
|
|
37
37
|
return updates.some(function (update) { return update; });
|
|
38
38
|
});
|
|
39
39
|
}).catch(function (error) {
|
|
40
40
|
if (retries) {
|
|
41
|
-
log.warn("".concat(constants_2.
|
|
41
|
+
log.warn("".concat(constants_2.LOG_PREFIX_SYNC, "Retrying fetch of segment ").concat(segmentName, " (attempt #").concat(retries, "). Reason: ").concat(error));
|
|
42
42
|
return updateSegment(segmentName, noCache, till, fetchOnlyNew, retries - 1);
|
|
43
43
|
}
|
|
44
44
|
throw error;
|
|
@@ -57,7 +57,7 @@ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, read
|
|
|
57
57
|
* @param till - till target for the provided segmentName, for CDN bypass.
|
|
58
58
|
*/
|
|
59
59
|
return function segmentChangesUpdater(fetchOnlyNew, segmentName, noCache, till) {
|
|
60
|
-
log.debug("".concat(constants_2.
|
|
60
|
+
log.debug("".concat(constants_2.LOG_PREFIX_SYNC, "Started segments update"));
|
|
61
61
|
// If not a segment name provided, read list of available segments names to be updated.
|
|
62
62
|
var segmentsPromise = Promise.resolve(segmentName ? [segmentName] : segments.getRegisteredSegments());
|
|
63
63
|
return segmentsPromise.then(function (segmentNames) {
|
|
@@ -66,7 +66,7 @@ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, read
|
|
|
66
66
|
// if at least one segment fetch succeeded, mark segments ready
|
|
67
67
|
if (shouldUpdateFlags.some(function (update) { return update; }) || readyOnAlreadyExistentState) {
|
|
68
68
|
readyOnAlreadyExistentState = false;
|
|
69
|
-
if (readiness) {
|
|
69
|
+
if (readiness && !fetchOnlyNew) {
|
|
70
70
|
var metadata = {
|
|
71
71
|
type: constants_1.SEGMENTS_UPDATE,
|
|
72
72
|
names: []
|
|
@@ -87,7 +87,7 @@ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, read
|
|
|
87
87
|
log.error("".concat(constants_2.LOG_PREFIX_INSTANTIATION, ": you passed a client-side type authorizationKey, please grab an SDK Key from Harness FME UI that is of type server-side."));
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
log.warn("".concat(constants_2.
|
|
90
|
+
log.warn("".concat(constants_2.LOG_PREFIX_SYNC, "Error while doing fetch of segments. ").concat(error));
|
|
91
91
|
}
|
|
92
92
|
return false;
|
|
93
93
|
});
|
|
@@ -73,7 +73,7 @@ function notificationKeeperFactory(pushEmitter, telemetryTracker) {
|
|
|
73
73
|
c.cTime = timestamp;
|
|
74
74
|
if (controlType === constants_2.ControlType.STREAMING_DISABLED) {
|
|
75
75
|
telemetryTracker.streamingEvent(constants_1.STREAMING_STATUS, constants_1.DISABLED);
|
|
76
|
-
pushEmitter.emit(constants_2.
|
|
76
|
+
pushEmitter.emit(constants_2.PUSH_NON_RETRYABLE_ERROR);
|
|
77
77
|
}
|
|
78
78
|
else if (hasPublishers) {
|
|
79
79
|
if (controlType === constants_2.ControlType.STREAMING_PAUSED && hasResumed) {
|
|
@@ -51,7 +51,7 @@ function SSEHandlerFactory(log, pushEmitter, telemetryTracker) {
|
|
|
51
51
|
pushEmitter.emit(constants_1.PUSH_RETRYABLE_ERROR);
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
|
-
pushEmitter.emit(constants_1.
|
|
54
|
+
pushEmitter.emit(constants_1.PUSH_NON_RETRYABLE_ERROR);
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
/* NotificationProcessor */
|
|
@@ -74,6 +74,7 @@ function SSEHandlerFactory(log, pushEmitter, telemetryTracker) {
|
|
|
74
74
|
switch (parsedData.type) {
|
|
75
75
|
/* update events */
|
|
76
76
|
case constants_1.SPLIT_UPDATE:
|
|
77
|
+
case constants_1.CONFIG_UPDATE:
|
|
77
78
|
case constants_1.SEGMENT_UPDATE:
|
|
78
79
|
case constants_1.MEMBERSHIPS_MS_UPDATE:
|
|
79
80
|
case constants_1.MEMBERSHIPS_LS_UPDATE:
|
package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DefinitionsUpdateWorker = void 0;
|
|
4
4
|
var constants_1 = require("../../../logger/constants");
|
|
5
5
|
var constants_2 = require("../../../readiness/constants");
|
|
6
6
|
var Backoff_1 = require("../../../utils/Backoff");
|
|
@@ -9,35 +9,34 @@ var constants_4 = require("../constants");
|
|
|
9
9
|
var parseUtils_1 = require("../parseUtils");
|
|
10
10
|
var constants_5 = require("./constants");
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* DefinitionsUpdateWorker factory for Flags SDKs, where notifications pcn and changeNumber are environment-scoped
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
|
|
14
|
+
function DefinitionsUpdateWorker(params, pollingManager) {
|
|
15
|
+
var log = params.settings.log, storage = params.storage, telemetryTracker = params.telemetryTracker, definitionsEventEmitter = params.readiness.definitions;
|
|
16
|
+
var definitionsSyncTask = pollingManager.definitionsSyncTask;
|
|
17
|
+
var ff = DefinitionsUpdateWorker(storage.definitions);
|
|
18
|
+
var rbs = DefinitionsUpdateWorker(storage.rbSegments);
|
|
19
|
+
function DefinitionsUpdateWorker(cache) {
|
|
18
20
|
var maxChangeNumber = -1;
|
|
19
21
|
var handleNewEvent = false;
|
|
20
22
|
var isHandlingEvent;
|
|
21
23
|
var cdnBypass;
|
|
22
24
|
var instantUpdate;
|
|
23
|
-
var backoff = new Backoff_1.Backoff(
|
|
24
|
-
function
|
|
25
|
+
var backoff = new Backoff_1.Backoff(__handleDefinitionUpdateCall, constants_5.FETCH_BACKOFF_BASE, constants_5.FETCH_BACKOFF_MAX_WAIT);
|
|
26
|
+
function __handleDefinitionUpdateCall() {
|
|
25
27
|
isHandlingEvent = true;
|
|
26
28
|
if (maxChangeNumber > cache.getChangeNumber()) {
|
|
27
29
|
handleNewEvent = false;
|
|
28
30
|
// fetch splits revalidating data if cached
|
|
29
|
-
|
|
31
|
+
definitionsSyncTask.execute(true, cdnBypass ? maxChangeNumber : undefined, instantUpdate).then(function () {
|
|
30
32
|
if (!isHandlingEvent)
|
|
31
33
|
return; // halt if `stop` has been called
|
|
32
34
|
if (handleNewEvent) {
|
|
33
|
-
|
|
35
|
+
__handleDefinitionUpdateCall();
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
38
|
if (instantUpdate)
|
|
37
39
|
telemetryTracker.trackUpdatesFromSSE(constants_3.SPLITS);
|
|
38
|
-
// fetch new registered segments for server-side API. Not retrying on error
|
|
39
|
-
if (segmentsSyncTask)
|
|
40
|
-
segmentsSyncTask.execute(true);
|
|
41
40
|
var attempts = backoff.attempts + 1;
|
|
42
41
|
if (ff.isSync() && rbs.isSync()) {
|
|
43
42
|
log.debug("Refresh completed".concat(cdnBypass ? ' bypassing the CDN' : '', " in ").concat(attempts, " attempts."));
|
|
@@ -55,7 +54,7 @@ function SplitsUpdateWorker(log, storage, splitsSyncTask, splitsEventEmitter, te
|
|
|
55
54
|
else {
|
|
56
55
|
backoff.reset();
|
|
57
56
|
cdnBypass = true;
|
|
58
|
-
|
|
57
|
+
__handleDefinitionUpdateCall();
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
});
|
|
@@ -83,7 +82,7 @@ function SplitsUpdateWorker(log, storage, splitsSyncTask, splitsEventEmitter, te
|
|
|
83
82
|
instantUpdate = { payload: payload, changeNumber: changeNumber, type: type };
|
|
84
83
|
}
|
|
85
84
|
if (backoff.timeoutID || !isHandlingEvent)
|
|
86
|
-
|
|
85
|
+
__handleDefinitionUpdateCall();
|
|
87
86
|
backoff.reset();
|
|
88
87
|
},
|
|
89
88
|
stop: function () {
|
|
@@ -99,7 +98,7 @@ function SplitsUpdateWorker(log, storage, splitsSyncTask, splitsEventEmitter, te
|
|
|
99
98
|
put: function (parsedData) {
|
|
100
99
|
if (parsedData.d && parsedData.c !== undefined) {
|
|
101
100
|
try {
|
|
102
|
-
var payload = (0, parseUtils_1.
|
|
101
|
+
var payload = (0, parseUtils_1.parseUpdatePayload)(parsedData.c, parsedData.d);
|
|
103
102
|
if (payload) {
|
|
104
103
|
(parsedData.type === constants_4.RB_SEGMENT_UPDATE ? rbs : ff).put(parsedData, payload);
|
|
105
104
|
return;
|
|
@@ -118,11 +117,11 @@ function SplitsUpdateWorker(log, storage, splitsSyncTask, splitsEventEmitter, te
|
|
|
118
117
|
* @param splitName - name of split to kill
|
|
119
118
|
* @param defaultTreatment - default treatment value
|
|
120
119
|
*/
|
|
121
|
-
|
|
120
|
+
killDefinition: function (_a) {
|
|
122
121
|
var changeNumber = _a.changeNumber, splitName = _a.splitName, defaultTreatment = _a.defaultTreatment;
|
|
123
|
-
if (storage.
|
|
122
|
+
if (storage.definitions.killLocally(splitName, defaultTreatment, changeNumber)) {
|
|
124
123
|
// trigger an SDK_UPDATE if Split was killed locally
|
|
125
|
-
|
|
124
|
+
definitionsEventEmitter.emit(constants_2.SDK_DEFINITIONS_ARRIVED, true);
|
|
126
125
|
}
|
|
127
126
|
// queues the SplitChanges fetch (only if changeNumber is newer)
|
|
128
127
|
ff.put({ changeNumber: changeNumber });
|
|
@@ -133,4 +132,4 @@ function SplitsUpdateWorker(log, storage, splitsSyncTask, splitsEventEmitter, te
|
|
|
133
132
|
}
|
|
134
133
|
};
|
|
135
134
|
}
|
|
136
|
-
exports.
|
|
135
|
+
exports.DefinitionsUpdateWorker = DefinitionsUpdateWorker;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControlType = exports.OCCUPANCY = exports.CONTROL = exports.RB_SEGMENT_UPDATE = exports.SPLIT_UPDATE = exports.SPLIT_KILL = exports.SEGMENT_UPDATE = exports.MEMBERSHIPS_LS_UPDATE = exports.MEMBERSHIPS_MS_UPDATE = exports.PUSH_SUBSYSTEM_DOWN = exports.PUSH_SUBSYSTEM_UP = exports.PUSH_RETRYABLE_ERROR = exports.
|
|
3
|
+
exports.ControlType = exports.OCCUPANCY = exports.CONTROL = exports.RB_SEGMENT_UPDATE = exports.CONFIG_UPDATE = exports.SPLIT_UPDATE = exports.SPLIT_KILL = exports.SEGMENT_UPDATE = exports.MEMBERSHIPS_LS_UPDATE = exports.MEMBERSHIPS_MS_UPDATE = exports.PUSH_SUBSYSTEM_DOWN = exports.PUSH_SUBSYSTEM_UP = exports.PUSH_RETRYABLE_ERROR = exports.PUSH_NON_RETRYABLE_ERROR = exports.SECONDS_BEFORE_EXPIRATION = void 0;
|
|
4
4
|
// time for refresh token
|
|
5
5
|
exports.SECONDS_BEFORE_EXPIRATION = 600;
|
|
6
6
|
// Internal SDK events, subscribed by SyncManager and PushManager
|
|
@@ -8,7 +8,7 @@ exports.SECONDS_BEFORE_EXPIRATION = 600;
|
|
|
8
8
|
* emitted on SSE and Authenticate non-recoverable errors, STREAMING_DISABLED control notification and authentication with pushEnabled false
|
|
9
9
|
* triggers `handleNonRetryableError` call
|
|
10
10
|
*/
|
|
11
|
-
exports.
|
|
11
|
+
exports.PUSH_NON_RETRYABLE_ERROR = 'PUSH_NON_RETRYABLE_ERROR';
|
|
12
12
|
/**
|
|
13
13
|
* emitted on SSE and Authenticate recoverable errors
|
|
14
14
|
* triggers `handleRetryableError` call
|
|
@@ -20,7 +20,7 @@ exports.PUSH_RETRYABLE_ERROR = 'PUSH_RETRYABLE_ERROR';
|
|
|
20
20
|
*/
|
|
21
21
|
exports.PUSH_SUBSYSTEM_UP = 'PUSH_SUBSYSTEM_UP';
|
|
22
22
|
/**
|
|
23
|
-
* emitted on STREAMING_PAUSED control notification, OCCUPANCY equal to 0,
|
|
23
|
+
* emitted on STREAMING_PAUSED control notification, OCCUPANCY equal to 0, PUSH_NON_RETRYABLE_ERROR and PUSH_RETRYABLE_ERROR events.
|
|
24
24
|
* triggers `startPolling` and `stopWorkers` calls
|
|
25
25
|
*/
|
|
26
26
|
exports.PUSH_SUBSYSTEM_DOWN = 'PUSH_SUBSYSTEM_DOWN';
|
|
@@ -30,6 +30,7 @@ exports.MEMBERSHIPS_LS_UPDATE = 'MEMBERSHIPS_LS_UPDATE';
|
|
|
30
30
|
exports.SEGMENT_UPDATE = 'SEGMENT_UPDATE';
|
|
31
31
|
exports.SPLIT_KILL = 'SPLIT_KILL';
|
|
32
32
|
exports.SPLIT_UPDATE = 'SPLIT_UPDATE';
|
|
33
|
+
exports.CONFIG_UPDATE = 'CONFIG_UPDATE';
|
|
33
34
|
exports.RB_SEGMENT_UPDATE = 'RB_SEGMENT_UPDATE';
|
|
34
35
|
// Control-type push notifications, handled by NotificationKeeper
|
|
35
36
|
exports.CONTROL = 'CONTROL';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDelay = exports.
|
|
3
|
+
exports.getDelay = exports.parseUpdatePayload = exports.isInBitmap = exports.parseBitmap = exports.parseCompressedData = void 0;
|
|
4
4
|
var decompress_1 = require("../../utils/decompress");
|
|
5
5
|
var base64_1 = require("../../utils/base64");
|
|
6
6
|
var murmur3_1 = require("../../utils/murmur3/murmur3");
|
|
@@ -33,24 +33,24 @@ function decompress(data, compression) {
|
|
|
33
33
|
throw new Error("Invalid compression algorithm #".concat(compression));
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* Decode, decompress and parse the provided 'data' into
|
|
36
|
+
* Decode, decompress and parse the provided 'data' into an object of type T
|
|
37
37
|
*
|
|
38
38
|
* @param data - base64 encoded string
|
|
39
39
|
* @param compression - 1 GZIP, 2 ZLIB
|
|
40
40
|
* @param avoidPrecisionLoss - true as default, set it as false if dont need to avoid precission loss
|
|
41
|
-
* @returns
|
|
41
|
+
* @returns parsed object
|
|
42
42
|
* @throws if data string cannot be decoded, decompressed or parsed
|
|
43
43
|
*/
|
|
44
|
-
function
|
|
44
|
+
function parseCompressedData(data, compression, avoidPrecisionLoss) {
|
|
45
45
|
if (avoidPrecisionLoss === void 0) { avoidPrecisionLoss = true; }
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
// replace numbers to strings, to avoid losing precision
|
|
46
|
+
var binData = decompress(data, compression);
|
|
47
|
+
var str = Uint8ArrayToString(binData);
|
|
48
|
+
// replace numbers to strings, to avoid losing precision (e.g., 64-bit IDs in KeyList)
|
|
49
49
|
if (avoidPrecisionLoss)
|
|
50
|
-
|
|
51
|
-
return JSON.parse(
|
|
50
|
+
str = str.replace(/\d+/g, '"$&"');
|
|
51
|
+
return JSON.parse(str);
|
|
52
52
|
}
|
|
53
|
-
exports.
|
|
53
|
+
exports.parseCompressedData = parseCompressedData;
|
|
54
54
|
/**
|
|
55
55
|
* Decode, decompress and parse the provided 'data' into a Bitmap object
|
|
56
56
|
*
|
|
@@ -79,14 +79,14 @@ function isInBitmap(bitmap, hash64hex) {
|
|
|
79
79
|
}
|
|
80
80
|
exports.isInBitmap = isInBitmap;
|
|
81
81
|
/**
|
|
82
|
-
* Parse
|
|
82
|
+
* Parse notifications for instant updates
|
|
83
83
|
*/
|
|
84
|
-
function
|
|
84
|
+
function parseUpdatePayload(compression, data) {
|
|
85
85
|
return compression > 0 ?
|
|
86
|
-
|
|
86
|
+
parseCompressedData(data, compression, false) :
|
|
87
87
|
JSON.parse((0, base64_1.decodeFromBase64)(data));
|
|
88
88
|
}
|
|
89
|
-
exports.
|
|
89
|
+
exports.parseUpdatePayload = parseUpdatePayload;
|
|
90
90
|
var DEFAULT_MAX_INTERVAL = 60000;
|
|
91
91
|
function getDelay(parsedData, matchingKey) {
|
|
92
92
|
if (parsedData.h === 0)
|