@splitsoftware/splitio-commons 1.1.1-rc.0 → 1.2.1-rc.2
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 +1 -1
- package/cjs/evaluator/Engine.js +6 -6
- package/cjs/evaluator/combiners/and.js +1 -1
- package/cjs/evaluator/combiners/ifelseif.js +2 -2
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/condition/index.js +4 -4
- package/cjs/evaluator/index.js +5 -5
- package/cjs/evaluator/matchers/cont_all.js +1 -1
- package/cjs/evaluator/matchers/cont_any.js +1 -1
- package/cjs/evaluator/matchers/cont_str.js +1 -1
- package/cjs/evaluator/matchers/dependency.js +1 -1
- package/cjs/evaluator/matchers/eq_set.js +1 -1
- package/cjs/evaluator/matchers/ew.js +3 -3
- package/cjs/evaluator/matchers/part_of.js +1 -1
- package/cjs/evaluator/matchers/segment.js +1 -1
- package/cjs/evaluator/matchers/sw.js +1 -1
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/evaluator/matchersTransform/index.js +12 -12
- package/cjs/evaluator/parser/index.js +6 -6
- package/cjs/evaluator/treatments/index.js +1 -1
- package/cjs/evaluator/value/index.js +1 -1
- package/cjs/evaluator/value/sanitize.js +4 -4
- package/cjs/integrations/browser.js +3 -3
- package/cjs/integrations/ga/GaToSplit.js +14 -14
- package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +1 -1
- package/cjs/integrations/ga/SplitToGa.js +1 -1
- package/cjs/listeners/browser.js +1 -1
- package/cjs/listeners/node.js +1 -1
- package/cjs/logger/constants.js +3 -1
- package/cjs/logger/index.js +2 -2
- package/cjs/logger/messages/debug.js +1 -1
- package/cjs/logger/messages/error.js +1 -1
- package/cjs/logger/messages/info.js +4 -4
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/logger/sdkLogger.js +1 -1
- package/cjs/readiness/readinessManager.js +2 -2
- package/cjs/readiness/sdkReadinessManager.js +4 -4
- package/cjs/sdkClient/client.js +11 -10
- package/cjs/sdkClient/clientAttributesDecoration.js +4 -4
- package/cjs/sdkClient/clientCS.js +4 -3
- package/cjs/sdkClient/clientInputValidation.js +14 -14
- package/cjs/sdkClient/sdkClient.js +3 -3
- package/cjs/sdkClient/sdkClientMethod.js +1 -1
- package/cjs/sdkClient/sdkClientMethodCS.js +6 -6
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +8 -8
- package/cjs/sdkFactory/index.js +8 -8
- package/cjs/sdkManager/index.js +11 -11
- package/cjs/services/splitApi.js +3 -2
- package/cjs/services/splitHttpClient.js +3 -3
- package/cjs/storages/KeyBuilder.js +2 -2
- package/cjs/storages/KeyBuilderCS.js +2 -2
- package/cjs/storages/KeyBuilderSS.js +1 -1
- package/cjs/storages/findLatencyIndex.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -12
- package/cjs/storages/inLocalStorage/index.js +3 -3
- package/cjs/storages/inMemory/AttributesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/LatenciesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +2 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/LatenciesCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +16 -10
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +3 -3
- package/cjs/storages/inRedis/index.js +1 -1
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +3 -3
- package/cjs/storages/pluggable/inMemoryWrapper.js +4 -4
- package/cjs/storages/pluggable/index.js +4 -4
- package/cjs/sync/offline/LocalhostFromFile.js +1 -1
- package/cjs/sync/offline/LocalhostFromObject.js +1 -1
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +13 -13
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +3 -3
- package/cjs/sync/offline/syncManagerOffline.js +1 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -2
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +8 -7
- package/cjs/sync/polling/pollingManagerSS.js +5 -4
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -2
- package/cjs/sync/streaming/AuthClient/index.js +4 -5
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +3 -3
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +1 -1
- package/cjs/sync/streaming/pushManager.js +39 -35
- package/cjs/sync/submitters/eventsSyncTask.js +1 -1
- package/cjs/sync/submitters/impressionCountsSyncTask.js +1 -1
- package/cjs/sync/submitters/impressionsSyncTask.js +3 -3
- package/cjs/sync/submitters/metricsSyncTask.js +3 -3
- package/cjs/sync/submitters/submitterManager.js +6 -5
- package/cjs/sync/submitters/submitterSyncTask.js +1 -1
- package/cjs/sync/syncManagerOnline.js +12 -12
- package/cjs/trackers/eventTracker.js +3 -3
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +1 -1
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +1 -1
- package/cjs/trackers/impressionsTracker.js +3 -3
- package/cjs/utils/MinEvents.js +2 -1
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +4 -4
- package/cjs/utils/inputValidation/attributes.js +2 -2
- package/cjs/utils/inputValidation/event.js +1 -1
- package/cjs/utils/inputValidation/eventProperties.js +7 -5
- package/cjs/utils/inputValidation/eventValue.js +1 -1
- package/cjs/utils/inputValidation/key.js +6 -5
- package/cjs/utils/inputValidation/preloadedData.js +8 -8
- package/cjs/utils/inputValidation/split.js +1 -1
- package/cjs/utils/inputValidation/splits.js +2 -2
- package/cjs/utils/inputValidation/trafficType.js +1 -1
- package/cjs/utils/inputValidation/trafficTypeExistance.js +1 -1
- package/cjs/utils/jwt/index.js +1 -1
- package/cjs/utils/key/index.js +3 -3
- package/cjs/utils/lang/index.js +2 -14
- package/cjs/utils/murmur3/common.js +1 -1
- package/cjs/utils/murmur3/legacy.js +44 -0
- package/cjs/utils/murmur3/murmur3.js +10 -10
- package/cjs/utils/murmur3/murmur3_128.js +1 -1
- package/cjs/utils/murmur3/murmur3_128_x86.js +37 -37
- package/cjs/utils/murmur3/murmur3_64.js +1 -1
- package/cjs/utils/promise/timeout.js +1 -1
- package/cjs/utils/settingsValidation/index.js +5 -10
- package/cjs/utils/settingsValidation/integrations/configurable.js +1 -1
- package/cjs/utils/settingsValidation/integrations/pluggable.js +1 -1
- package/cjs/utils/settingsValidation/localhost/builtin.js +2 -2
- package/cjs/utils/settingsValidation/logger/builtinLogger.js +3 -3
- package/cjs/utils/settingsValidation/logger/commons.js +1 -1
- package/cjs/utils/settingsValidation/logger/pluggableLogger.js +1 -1
- package/cjs/utils/settingsValidation/runtime/browser.js +10 -0
- package/cjs/utils/settingsValidation/runtime/node.js +22 -0
- package/cjs/utils/settingsValidation/splitFilters.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/cjs/utils/timeTracker/index.js +3 -3
- package/esm/evaluator/matchers/ew.js +4 -4
- package/esm/logger/messages/info.js +3 -3
- package/esm/sdkClient/client.js +2 -1
- package/esm/sdkClient/clientCS.js +2 -1
- package/esm/services/splitApi.js +2 -1
- package/esm/services/splitHttpClient.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +7 -1
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +1 -1
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +2 -1
- package/esm/sync/polling/pollingManagerSS.js +2 -1
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/streaming/AuthClient/index.js +1 -2
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/esm/sync/streaming/pushManager.js +27 -23
- package/esm/sync/submitters/submitterManager.js +2 -1
- package/esm/sync/syncManagerOnline.js +12 -12
- package/esm/utils/inputValidation/eventProperties.js +4 -2
- package/esm/utils/inputValidation/key.js +2 -1
- package/esm/utils/lang/index.js +2 -13
- package/esm/utils/murmur3/legacy.js +39 -0
- package/esm/utils/promise/timeout.js +1 -1
- package/esm/utils/settingsValidation/index.js +1 -6
- package/esm/utils/settingsValidation/runtime/browser.js +6 -0
- package/esm/utils/settingsValidation/runtime/node.js +17 -0
- package/package.json +8 -7
- package/src/evaluator/matchers/ew.ts +4 -4
- package/src/logger/.DS_Store +0 -0
- package/src/logger/messages/info.ts +3 -3
- package/src/logger/types.ts +4 -0
- package/src/sdkClient/client.ts +2 -1
- package/src/sdkClient/clientCS.ts +3 -1
- package/src/services/splitHttpClient.ts +1 -1
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +1 -1
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +2 -1
- package/src/sync/polling/fetchers/types.ts +1 -0
- package/src/sync/polling/pollingManagerCS.ts +3 -6
- package/src/sync/polling/pollingManagerSS.ts +3 -8
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +2 -1
- package/src/sync/polling/types.ts +0 -12
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -1
- package/src/sync/streaming/AuthClient/index.ts +1 -2
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
- package/src/sync/streaming/pushManager.ts +31 -38
- package/src/sync/streaming/types.ts +5 -25
- package/src/sync/submitters/submitterManager.ts +4 -8
- package/src/sync/syncManagerOnline.ts +16 -22
- package/src/types.ts +5 -1
- package/src/utils/inputValidation/eventProperties.ts +4 -2
- package/src/utils/lang/index.ts +0 -14
- package/src/utils/murmur3/legacy.ts +48 -0
- package/src/utils/promise/timeout.ts +1 -1
- package/src/utils/settingsValidation/index.ts +1 -6
- package/src/utils/settingsValidation/runtime/browser.ts +6 -0
- package/src/utils/settingsValidation/runtime/node.ts +22 -0
- package/src/utils/settingsValidation/types.ts +6 -6
- package/types/integrations/ga/GaToSplitPlugin.d.ts +3 -0
- package/types/integrations/ga/SplitToGaPlugin.d.ts +4 -0
- package/types/logger/browser/{DebugLogger.d.ts → debugLogger.d.ts} +0 -0
- package/types/logger/browser/{ErrorLogger.d.ts → errorLogger.d.ts} +0 -0
- package/types/logger/browser/{InfoLogger.d.ts → infoLogger.d.ts} +0 -0
- package/types/logger/browser/{WarnLogger.d.ts → warnLogger.d.ts} +0 -0
- package/types/logger/codes.d.ts +2 -0
- package/types/logger/codesConstants.d.ts +117 -0
- package/types/logger/codesConstantsBrowser.d.ts +2 -0
- package/types/logger/codesConstantsNode.d.ts +14 -0
- package/types/logger/codesDebug.d.ts +1 -0
- package/types/logger/codesDebugBrowser.d.ts +1 -0
- package/types/logger/codesDebugNode.d.ts +1 -0
- package/types/logger/codesError.d.ts +1 -0
- package/types/logger/codesErrorNode.d.ts +1 -0
- package/types/logger/codesInfo.d.ts +1 -0
- package/types/logger/codesWarn.d.ts +1 -0
- package/types/logger/codesWarnNode.d.ts +1 -0
- package/types/logger/debugLogger.d.ts +2 -0
- package/types/logger/errorLogger.d.ts +2 -0
- package/types/logger/infoLogger.d.ts +2 -0
- package/types/logger/messages/debugBrowser.d.ts +1 -0
- package/types/logger/messages/debugNode.d.ts +1 -0
- package/types/logger/messages/errorNode.d.ts +1 -0
- package/types/logger/messages/warnNode.d.ts +1 -0
- package/types/logger/noopLogger.d.ts +2 -0
- package/types/logger/types.d.ts +4 -0
- package/types/logger/warnLogger.d.ts +2 -0
- package/types/sdkClient/clientAttributesDecoration.d.ts +1 -1
- package/types/sdkManager/sdkManagerMethod.d.ts +6 -0
- package/types/storages/getRegisteredSegments.d.ts +10 -0
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +51 -0
- package/types/storages/inMemory/index.d.ts +10 -0
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +0 -0
- package/types/storages/parseSegments.d.ts +6 -0
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +2 -0
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +1 -1
- package/types/sync/polling/fetchers/types.d.ts +1 -1
- package/types/sync/polling/pollingManagerCS.d.ts +2 -5
- package/types/sync/polling/pollingManagerSS.d.ts +2 -5
- package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +35 -0
- package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +35 -0
- package/types/sync/polling/types.d.ts +0 -11
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +1 -1
- package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
- package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -1
- package/types/sync/streaming/pushManager.d.ts +3 -7
- package/types/sync/streaming/pushManagerCS.d.ts +1 -0
- package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
- package/types/sync/streaming/pushManagerSS.d.ts +1 -0
- package/types/sync/streaming/types.d.ts +3 -23
- package/types/sync/submitters/submitterManager.d.ts +2 -4
- package/types/sync/submitters/telemetrySyncTask.d.ts +17 -0
- package/types/sync/syncManagerFromFile.d.ts +2 -0
- package/types/sync/syncManagerFromObject.d.ts +2 -0
- package/types/sync/syncManagerOffline.d.ts +9 -0
- package/types/sync/syncManagerOnline.d.ts +3 -3
- package/types/trackers/telemetryRecorder.d.ts +0 -0
- package/types/types.d.ts +1 -0
- package/types/utils/EventEmitter.d.ts +4 -0
- package/types/utils/lang/errors.d.ts +10 -0
- package/types/utils/lang/index.d.ts +0 -4
- package/types/utils/murmur3/commons.d.ts +12 -0
- package/types/utils/murmur3/legacy.d.ts +2 -0
- package/types/utils/settingsValidation/buildMetadata.d.ts +3 -0
- package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
- package/types/utils/settingsValidation/logger.d.ts +11 -0
- package/types/utils/settingsValidation/runtime/browser.d.ts +4 -0
- package/types/utils/settingsValidation/runtime/node.d.ts +5 -0
- package/types/utils/settingsValidation/types.d.ts +6 -6
package/esm/utils/lang/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the target string ends with the sub string.
|
|
4
4
|
*/
|
|
@@ -179,21 +179,10 @@ export function merge(target, source) {
|
|
|
179
179
|
});
|
|
180
180
|
if (rest && rest.length) {
|
|
181
181
|
var nextSource = rest.splice(0, 1)[0];
|
|
182
|
-
res = merge.apply(void 0,
|
|
182
|
+
res = merge.apply(void 0, __spreadArray([res, nextSource], rest, false));
|
|
183
183
|
}
|
|
184
184
|
return res;
|
|
185
185
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Shallow clone an object
|
|
188
|
-
*/
|
|
189
|
-
export function shallowClone(obj) {
|
|
190
|
-
var keys = Object.keys(obj);
|
|
191
|
-
var output = {};
|
|
192
|
-
for (var i = 0; i < keys.length; i++) {
|
|
193
|
-
output[keys[i]] = obj[keys[i]];
|
|
194
|
-
}
|
|
195
|
-
return output;
|
|
196
|
-
}
|
|
197
186
|
/**
|
|
198
187
|
* Checks if the target string starts with the sub string.
|
|
199
188
|
*/
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Deprecated hashing function, used for split bucketing. Replaced by murmur3
|
|
2
|
+
//
|
|
3
|
+
// JAVA reference implementation for the hashing function.
|
|
4
|
+
//
|
|
5
|
+
// int h = 0;
|
|
6
|
+
// for (int i = 0; i < key.length(); i++) {
|
|
7
|
+
// h = 31 * h + key.charAt(i);
|
|
8
|
+
// }
|
|
9
|
+
// return h ^ seed; // XOR the hash and seed
|
|
10
|
+
//
|
|
11
|
+
function ToInteger(x) {
|
|
12
|
+
x = Number(x);
|
|
13
|
+
return x < 0 ? Math.ceil(x) : Math.floor(x);
|
|
14
|
+
}
|
|
15
|
+
function modulo(a, b) {
|
|
16
|
+
return a - Math.floor(a / b) * b;
|
|
17
|
+
}
|
|
18
|
+
function ToUint32(x) {
|
|
19
|
+
return modulo(ToInteger(x), Math.pow(2, 32));
|
|
20
|
+
}
|
|
21
|
+
function ToInt32(x) {
|
|
22
|
+
var uint32 = ToUint32(x);
|
|
23
|
+
if (uint32 >= Math.pow(2, 31)) {
|
|
24
|
+
return uint32 - Math.pow(2, 32);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return uint32;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function hash(str, seed) {
|
|
31
|
+
var h = 0;
|
|
32
|
+
for (var i = 0; i < str.length; i++) {
|
|
33
|
+
h = ToInt32(ToInt32(31 * h) + str.charCodeAt(i));
|
|
34
|
+
}
|
|
35
|
+
return ToInt32(h ^ seed);
|
|
36
|
+
}
|
|
37
|
+
export function bucket(str, seed) {
|
|
38
|
+
return Math.abs(hash(str, seed) % 100) + 1;
|
|
39
|
+
}
|
|
@@ -3,7 +3,7 @@ export function timeout(ms, promise) {
|
|
|
3
3
|
return promise;
|
|
4
4
|
return new Promise(function (resolve, reject) {
|
|
5
5
|
var tid = setTimeout(function () {
|
|
6
|
-
reject(new Error("Operation timed out because it exceeded the configured time limit of " + ms + "ms."));
|
|
6
|
+
reject(new Error("Operation timed out because it exceeded the configured time limit of " + ms + " ms."));
|
|
7
7
|
}, ms);
|
|
8
8
|
promise.then(function (res) {
|
|
9
9
|
clearTimeout(tid);
|
|
@@ -64,10 +64,6 @@ var base = {
|
|
|
64
64
|
impressionsMode: OPTIMIZED,
|
|
65
65
|
localhostMode: undefined
|
|
66
66
|
},
|
|
67
|
-
runtime: {
|
|
68
|
-
ip: false,
|
|
69
|
-
hostname: false
|
|
70
|
-
},
|
|
71
67
|
// Logger
|
|
72
68
|
log: undefined
|
|
73
69
|
};
|
|
@@ -114,8 +110,7 @@ export function settingsValidation(config, validationParams) {
|
|
|
114
110
|
}
|
|
115
111
|
// Current ip/hostname information
|
|
116
112
|
// @ts-ignore, modify readonly prop
|
|
117
|
-
|
|
118
|
-
withDefaults.runtime = runtime(withDefaults);
|
|
113
|
+
withDefaults.runtime = runtime(withDefaults);
|
|
119
114
|
// ensure a valid list of integrations.
|
|
120
115
|
// `integrations` returns an array of valid integration items.
|
|
121
116
|
// @ts-ignore, modify readonly prop
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import osFunction from 'os';
|
|
2
|
+
import ipFunction from 'ip';
|
|
3
|
+
import { UNKNOWN, NA, CONSUMER_MODE } from '../../constants';
|
|
4
|
+
export function validateRuntime(settings) {
|
|
5
|
+
var isIPAddressesEnabled = settings.core.IPAddressesEnabled === true;
|
|
6
|
+
var isConsumerMode = settings.mode === CONSUMER_MODE;
|
|
7
|
+
// If the values are not available, default to false (for standalone) or "unknown" (for consumer mode, to be used on Redis keys)
|
|
8
|
+
var ip = ipFunction.address() || (isConsumerMode ? UNKNOWN : false);
|
|
9
|
+
var hostname = osFunction.hostname() || (isConsumerMode ? UNKNOWN : false);
|
|
10
|
+
if (!isIPAddressesEnabled) { // If IPAddresses setting is not enabled, set as false (for standalone) or "NA" (for consumer mode, to be used on Redis keys)
|
|
11
|
+
ip = hostname = isConsumerMode ? NA : false;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
ip: ip,
|
|
15
|
+
hostname: hostname
|
|
16
|
+
};
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splitsoftware/splitio-commons",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1-rc.2",
|
|
4
4
|
"description": "Split Javascript SDK common components",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"check:lint": "eslint src --ext .js,.ts",
|
|
21
21
|
"check:types": "tsc --noEmit",
|
|
22
22
|
"build": "npm run build:cjs && npm run build:esm",
|
|
23
|
-
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types
|
|
24
|
-
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs
|
|
23
|
+
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
|
|
24
|
+
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
|
|
25
25
|
"test": "jest",
|
|
26
26
|
"test:coverage": "jest --coverage",
|
|
27
27
|
"publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
|
|
@@ -44,11 +44,12 @@
|
|
|
44
44
|
"bugs": "https://github.com/splitio/javascript-commons/issues",
|
|
45
45
|
"homepage": "https://github.com/splitio/javascript-commons#readme",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"tslib": "^2.1
|
|
47
|
+
"tslib": "^2.3.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/google.analytics": "0.0.40",
|
|
51
51
|
"@types/ioredis": "^4.28.0",
|
|
52
|
+
"@types/ip": "^1.1.0",
|
|
52
53
|
"@types/jest": "^27.0.0",
|
|
53
54
|
"@types/lodash": "^4.14.162",
|
|
54
55
|
"@typescript-eslint/eslint-plugin": "^4.2.0",
|
|
@@ -58,17 +59,17 @@
|
|
|
58
59
|
"eslint": "^7.32.0",
|
|
59
60
|
"eslint-plugin-compat": "3.7.0",
|
|
60
61
|
"eslint-plugin-import": "^2.25.3",
|
|
61
|
-
"fetch-mock": "^9.
|
|
62
|
+
"fetch-mock": "^9.11.0",
|
|
62
63
|
"ioredis": "^4.28.0",
|
|
63
64
|
"jest": "^27.2.3",
|
|
64
65
|
"jest-localstorage-mock": "^2.4.3",
|
|
65
66
|
"js-yaml": "^3.14.0",
|
|
66
67
|
"lodash": "^4.17.21",
|
|
67
|
-
"node-fetch": "^2.6.
|
|
68
|
+
"node-fetch": "^2.6.7",
|
|
68
69
|
"redis-server": "1.2.2",
|
|
69
70
|
"rimraf": "^3.0.2",
|
|
70
71
|
"ts-jest": "^27.0.5",
|
|
71
|
-
"typescript": "
|
|
72
|
+
"typescript": "4.4.4"
|
|
72
73
|
},
|
|
73
74
|
"sideEffects": false
|
|
74
75
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ENGINE_MATCHER_ENDS_WITH } from '../../logger/constants';
|
|
2
2
|
import { ILogger } from '../../logger/types';
|
|
3
|
-
import { endsWith
|
|
3
|
+
import { endsWith } from '../../utils/lang';
|
|
4
4
|
|
|
5
5
|
export function endsWithMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
|
|
6
6
|
return function endsWithMatcher(runtimeAttr: string): boolean {
|
|
7
|
-
let
|
|
7
|
+
let strEndsWith = ruleAttr.some(e => endsWith(runtimeAttr, e));
|
|
8
8
|
|
|
9
|
-
log.debug(ENGINE_MATCHER_ENDS_WITH, [runtimeAttr, ruleAttr,
|
|
9
|
+
log.debug(ENGINE_MATCHER_ENDS_WITH, [runtimeAttr, ruleAttr, strEndsWith]);
|
|
10
10
|
|
|
11
|
-
return
|
|
11
|
+
return strEndsWith;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
Binary file
|
|
@@ -23,10 +23,10 @@ export const codesInfo: [number, string][] = codesWarn.concat([
|
|
|
23
23
|
[c.SUBMITTERS_PUSH_FULL_EVENTS_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full events queue and reseting timer.'],
|
|
24
24
|
[c.SUBMITTERS_PUSH, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Pushing %s %s.'],
|
|
25
25
|
[c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds, and connecting streaming in %s seconds.'],
|
|
26
|
-
[c.STREAMING_RECONNECT, c.LOG_PREFIX_SYNC_STREAMING + 'Attempting to reconnect in %s seconds.'],
|
|
27
|
-
[c.STREAMING_CONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Connecting
|
|
26
|
+
[c.STREAMING_RECONNECT, c.LOG_PREFIX_SYNC_STREAMING + 'Attempting to reconnect streaming in %s seconds.'],
|
|
27
|
+
[c.STREAMING_CONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Connecting streaming.'],
|
|
28
28
|
[c.STREAMING_DISABLED, c.LOG_PREFIX_SYNC_STREAMING + 'Streaming is disabled for given Api key. Switching to polling mode.'],
|
|
29
|
-
[c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting
|
|
29
|
+
[c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting streaming.'],
|
|
30
30
|
[c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
|
|
31
31
|
[c.SYNC_CONTINUE_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming couldn\'t connect. Continue polling.'],
|
|
32
32
|
[c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming (re)connected. Syncing and stopping polling.'],
|
package/src/logger/types.ts
CHANGED
|
@@ -9,11 +9,15 @@ export interface ILoggerOptions {
|
|
|
9
9
|
export interface ILogger {
|
|
10
10
|
setLogLevel(logLevel: LogLevel): void
|
|
11
11
|
|
|
12
|
+
debug(msg: unknown): void
|
|
12
13
|
debug(msg: string | number, args?: any[]): void
|
|
13
14
|
|
|
15
|
+
info(msg: unknown): void
|
|
14
16
|
info(msg: string | number, args?: any[]): void
|
|
15
17
|
|
|
18
|
+
warn(msg: unknown): void
|
|
16
19
|
warn(msg: string | number, args?: any[]): void
|
|
17
20
|
|
|
21
|
+
error(msg: unknown): void
|
|
18
22
|
error(msg: string | number, args?: any[]): void
|
|
19
23
|
}
|
package/src/sdkClient/client.ts
CHANGED
|
@@ -123,6 +123,7 @@ export function clientFactory(params: IClientFactoryParams): SplitIO.IClient | S
|
|
|
123
123
|
getTreatmentWithConfig,
|
|
124
124
|
getTreatments,
|
|
125
125
|
getTreatmentsWithConfig,
|
|
126
|
-
track
|
|
126
|
+
track,
|
|
127
|
+
isBrowserClient: false
|
|
127
128
|
} as SplitIO.IClient | SplitIO.IAsyncClient;
|
|
128
129
|
}
|
|
@@ -23,6 +23,8 @@ export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: Sp
|
|
|
23
23
|
getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
|
|
24
24
|
|
|
25
25
|
// Key is bound to the `track` method. Same thing happens with trafficType but only if provided
|
|
26
|
-
track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key)
|
|
26
|
+
track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
|
|
27
|
+
|
|
28
|
+
isBrowserClient: true
|
|
27
29
|
}) as SplitIO.ICsClient;
|
|
28
30
|
}
|
|
@@ -6,9 +6,10 @@ import { IMySegmentsFetcher } from './types';
|
|
|
6
6
|
* Factory of MySegments fetcher.
|
|
7
7
|
* MySegments fetcher is a wrapper around `mySegments` API service that parses the response and handle errors.
|
|
8
8
|
*/
|
|
9
|
-
export function mySegmentsFetcherFactory(fetchMySegments: IFetchMySegments
|
|
9
|
+
export function mySegmentsFetcherFactory(fetchMySegments: IFetchMySegments): IMySegmentsFetcher {
|
|
10
10
|
|
|
11
11
|
return function mySegmentsFetcher(
|
|
12
|
+
userMatchingKey: string,
|
|
12
13
|
noCache?: boolean,
|
|
13
14
|
// Optional decorator for `fetchMySegments` promise, such as timeout or time tracker
|
|
14
15
|
decorator?: (promise: Promise<IResponse>) => Promise<IResponse>
|
|
@@ -15,6 +15,7 @@ export type ISegmentChangesFetcher = (
|
|
|
15
15
|
) => Promise<ISegmentChangesResponse[]>
|
|
16
16
|
|
|
17
17
|
export type IMySegmentsFetcher = (
|
|
18
|
+
userMatchingKey: string,
|
|
18
19
|
noCache?: boolean,
|
|
19
20
|
decorator?: (promise: Promise<IResponse>) => Promise<IResponse>
|
|
20
21
|
) => Promise<string[]>
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { ISegmentsSyncTask, ISplitsSyncTask, IPollingManagerCS } from './types';
|
|
2
2
|
import { forOwn } from '../../utils/lang';
|
|
3
3
|
import { IReadinessManager } from '../../readiness/types';
|
|
4
|
-
import { ISplitApi } from '../../services/types';
|
|
5
4
|
import { IStorageSync } from '../../storages/types';
|
|
6
5
|
import { mySegmentsSyncTaskFactory } from './syncTasks/mySegmentsSyncTask';
|
|
7
6
|
import { splitsSyncTaskFactory } from './syncTasks/splitsSyncTask';
|
|
8
|
-
import { ISettings } from '../../types';
|
|
9
7
|
import { getMatching } from '../../utils/key';
|
|
10
8
|
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../../readiness/constants';
|
|
11
9
|
import { POLLING_SMART_PAUSING, POLLING_START, POLLING_STOP } from '../../logger/constants';
|
|
10
|
+
import { ISyncManagerFactoryParams } from '../types';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Expose start / stop mechanism for polling data from services.
|
|
15
14
|
* For client-side API with multiple clients.
|
|
16
15
|
*/
|
|
17
16
|
export function pollingManagerCSFactory(
|
|
18
|
-
|
|
19
|
-
storage: IStorageSync,
|
|
20
|
-
readiness: IReadinessManager,
|
|
21
|
-
settings: ISettings,
|
|
17
|
+
params: ISyncManagerFactoryParams
|
|
22
18
|
): IPollingManagerCS {
|
|
23
19
|
|
|
20
|
+
const { splitApi, storage, readiness, settings } = params;
|
|
24
21
|
const log = settings.log;
|
|
25
22
|
|
|
26
23
|
const splitsSyncTask: ISplitsSyncTask = splitsSyncTaskFactory(splitApi.fetchSplitChanges, storage, readiness, settings);
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
import { splitsSyncTaskFactory } from './syncTasks/splitsSyncTask';
|
|
2
2
|
import { segmentsSyncTaskFactory } from './syncTasks/segmentsSyncTask';
|
|
3
|
-
import { IStorageSync } from '../../storages/types';
|
|
4
|
-
import { IReadinessManager } from '../../readiness/types';
|
|
5
|
-
import { ISplitApi } from '../../services/types';
|
|
6
|
-
import { ISettings } from '../../types';
|
|
7
3
|
import { IPollingManager, ISegmentsSyncTask, ISplitsSyncTask } from './types';
|
|
8
4
|
import { thenable } from '../../utils/promise/thenable';
|
|
9
5
|
import { POLLING_START, POLLING_STOP, LOG_PREFIX_SYNC_POLLING } from '../../logger/constants';
|
|
6
|
+
import { ISyncManagerFactoryParams } from '../types';
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Expose start / stop mechanism for pulling data from services.
|
|
13
10
|
*/
|
|
14
11
|
export function pollingManagerSSFactory(
|
|
15
|
-
|
|
16
|
-
storage: IStorageSync,
|
|
17
|
-
readiness: IReadinessManager,
|
|
18
|
-
settings: ISettings
|
|
12
|
+
params: ISyncManagerFactoryParams
|
|
19
13
|
): IPollingManager {
|
|
20
14
|
|
|
15
|
+
const { splitApi, storage, readiness, settings } = params;
|
|
21
16
|
const log = settings.log;
|
|
22
17
|
|
|
23
18
|
const splitsSyncTask: ISplitsSyncTask = splitsSyncTaskFactory(splitApi.fetchSplitChanges, storage, readiness, settings);
|
|
@@ -21,12 +21,13 @@ export function mySegmentsSyncTaskFactory(
|
|
|
21
21
|
settings.log,
|
|
22
22
|
mySegmentsUpdaterFactory(
|
|
23
23
|
settings.log,
|
|
24
|
-
mySegmentsFetcherFactory(fetchMySegments
|
|
24
|
+
mySegmentsFetcherFactory(fetchMySegments),
|
|
25
25
|
storage.splits,
|
|
26
26
|
storage.segments,
|
|
27
27
|
readiness.segments,
|
|
28
28
|
settings.startup.requestTimeoutBeforeReady,
|
|
29
29
|
settings.startup.retriesOnFailureBeforeReady,
|
|
30
|
+
matchingKey
|
|
30
31
|
),
|
|
31
32
|
settings.scheduler.segmentsRefreshRate,
|
|
32
33
|
'mySegmentsUpdater',
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { IReadinessManager } from '../../readiness/types';
|
|
2
|
-
import { ISplitApi } from '../../services/types';
|
|
3
2
|
import { IStorageSync } from '../../storages/types';
|
|
4
|
-
import { ISettings } from '../../types';
|
|
5
3
|
import { SegmentsData } from '../streaming/SSEHandler/types';
|
|
6
4
|
import { ITask, ISyncTask } from '../types';
|
|
7
5
|
|
|
@@ -23,13 +21,3 @@ export interface IPollingManagerCS extends IPollingManager {
|
|
|
23
21
|
remove(matchingKey: string): void;
|
|
24
22
|
get(matchingKey: string): ISegmentsSyncTask | undefined
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Signature of polling manager factory/constructor
|
|
29
|
-
*/
|
|
30
|
-
export type IPollingManagerFactoryParams = [
|
|
31
|
-
splitApi: ISplitApi,
|
|
32
|
-
storage: IStorageSync,
|
|
33
|
-
readiness: IReadinessManager,
|
|
34
|
-
settings: ISettings,
|
|
35
|
-
]
|
|
@@ -23,6 +23,7 @@ export function mySegmentsUpdaterFactory(
|
|
|
23
23
|
segmentsEventEmitter: ISegmentsEventEmitter,
|
|
24
24
|
requestTimeoutBeforeReady: number,
|
|
25
25
|
retriesOnFailureBeforeReady: number,
|
|
26
|
+
matchingKey: string
|
|
26
27
|
): IMySegmentsUpdater {
|
|
27
28
|
|
|
28
29
|
let readyOnAlreadyExistentState = true;
|
|
@@ -69,7 +70,7 @@ export function mySegmentsUpdaterFactory(
|
|
|
69
70
|
// If segmentsData is provided, there is no need to fetch mySegments
|
|
70
71
|
new Promise((res) => { updateSegments(segmentsData); res(true); }) :
|
|
71
72
|
// If not provided, fetch mySegments
|
|
72
|
-
mySegmentsFetcher(noCache, _promiseDecorator).then(segments => {
|
|
73
|
+
mySegmentsFetcher(matchingKey, noCache, _promiseDecorator).then(segments => {
|
|
73
74
|
// Only when we have downloaded segments completely, we should not keep retrying anymore
|
|
74
75
|
startingUp = false;
|
|
75
76
|
|
|
@@ -17,8 +17,7 @@ export function authenticateFactory(fetchAuth: IFetchAuth): IAuthenticate {
|
|
|
17
17
|
* @param {string[] | undefined} userKeys set of user Keys to track MY_SEGMENTS_CHANGES. It is undefined for server-side API.
|
|
18
18
|
*/
|
|
19
19
|
return function authenticate(userKeys?: string[]): Promise<IAuthToken> {
|
|
20
|
-
|
|
21
|
-
return authPromise
|
|
20
|
+
return fetchAuth(userKeys)
|
|
22
21
|
.then(resp => resp.json())
|
|
23
22
|
.then(json => {
|
|
24
23
|
if (json.token) { // empty token when `"pushEnabled": false`
|
|
@@ -19,7 +19,7 @@ export class SegmentsUpdateWorker implements IUpdateWorker {
|
|
|
19
19
|
* @param {Object} segmentsCache segments data cache
|
|
20
20
|
* @param {Object} segmentsSyncTask task for syncing segments data
|
|
21
21
|
*/
|
|
22
|
-
constructor(
|
|
22
|
+
constructor(segmentsSyncTask: ISegmentsSyncTask, segmentsCache: ISegmentsCacheSync) {
|
|
23
23
|
this.segmentsCache = segmentsCache;
|
|
24
24
|
this.segmentsSyncTask = segmentsSyncTask;
|
|
25
25
|
this.maxChangeNumbers = {};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { IPushEventEmitter,
|
|
1
|
+
import { IPushEventEmitter, IPushManager } from './types';
|
|
2
2
|
import { ISSEClient } from './SSEClient/types';
|
|
3
|
-
import { IStorageSync } from '../../storages/types';
|
|
4
|
-
import { IReadinessManager } from '../../readiness/types';
|
|
5
3
|
import { ISegmentsSyncTask, IPollingManager } from '../polling/types';
|
|
6
4
|
import { objectAssign } from '../../utils/lang/objectAssign';
|
|
7
5
|
import { Backoff } from '../../utils/Backoff';
|
|
@@ -12,17 +10,15 @@ import { SplitsUpdateWorker } from './UpdateWorkers/SplitsUpdateWorker';
|
|
|
12
10
|
import { authenticateFactory, hashUserKey } from './AuthClient';
|
|
13
11
|
import { forOwn } from '../../utils/lang';
|
|
14
12
|
import { SSEClient } from './SSEClient';
|
|
15
|
-
import { IFetchAuth } from '../../services/types';
|
|
16
|
-
import { ISettings } from '../../types';
|
|
17
13
|
import { getMatching } from '../../utils/key';
|
|
18
14
|
import { MY_SEGMENTS_UPDATE, MY_SEGMENTS_UPDATE_V2, PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, PUSH_RETRYABLE_ERROR, PUSH_SUBSYSTEM_UP, ControlType } from './constants';
|
|
19
|
-
import { IPlatform } from '../../sdkFactory/types';
|
|
20
15
|
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT, STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 } from '../../logger/constants';
|
|
21
16
|
import { KeyList, UpdateStrategy } from './SSEHandler/types';
|
|
22
17
|
import { isInBitmap, parseBitmap, parseKeyList } from './mySegmentsV2utils';
|
|
23
18
|
import { ISet, _Set } from '../../utils/lang/sets';
|
|
24
19
|
import { Hash64, hash64 } from '../../utils/murmur3/murmur3_64';
|
|
25
20
|
import { IAuthTokenPushEnabled } from './AuthClient/types';
|
|
21
|
+
import { ISyncManagerFactoryParams } from '../types';
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
24
|
* PushManager factory:
|
|
@@ -30,17 +26,15 @@ import { IAuthTokenPushEnabled } from './AuthClient/types';
|
|
|
30
26
|
* - for client-side, with support for multiple clients, if key is provided in settings
|
|
31
27
|
*/
|
|
32
28
|
export function pushManagerFactory(
|
|
29
|
+
params: ISyncManagerFactoryParams,
|
|
33
30
|
pollingManager: IPollingManager,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
platform: IPlatform,
|
|
38
|
-
settings: ISettings,
|
|
39
|
-
): IPushManagerCS | undefined {
|
|
31
|
+
): IPushManager | undefined {
|
|
32
|
+
|
|
33
|
+
const { settings, storage, splitApi, readiness, platform } = params;
|
|
40
34
|
|
|
41
35
|
// `userKey` is the matching key of main client in client-side SDK.
|
|
42
36
|
// It can be used to check if running on client-side or server-side SDK.
|
|
43
|
-
const userKey = settings.core.key ? getMatching(settings.core.key) : undefined;
|
|
37
|
+
const userKey = settings.core.key ? getMatching(settings.core.key) : undefined;
|
|
44
38
|
const log = settings.log;
|
|
45
39
|
|
|
46
40
|
let sseClient: ISSEClient;
|
|
@@ -51,7 +45,7 @@ export function pushManagerFactory(
|
|
|
51
45
|
log.warn(STREAMING_FALLBACK, [e]);
|
|
52
46
|
return;
|
|
53
47
|
}
|
|
54
|
-
const authenticate = authenticateFactory(fetchAuth);
|
|
48
|
+
const authenticate = authenticateFactory(splitApi.fetchAuth);
|
|
55
49
|
|
|
56
50
|
// init feedback loop
|
|
57
51
|
const pushEmitter = new platform.EventEmitter() as IPushEventEmitter;
|
|
@@ -59,7 +53,8 @@ export function pushManagerFactory(
|
|
|
59
53
|
sseClient.setEventHandler(sseHandler);
|
|
60
54
|
|
|
61
55
|
// init workers
|
|
62
|
-
|
|
56
|
+
// MySegmentsUpdateWorker (client-side) are initiated in `add` method
|
|
57
|
+
const segmentsUpdateWorker = userKey ? undefined : new SegmentsUpdateWorker(pollingManager.segmentsSyncTask, storage.segments);
|
|
63
58
|
// For server-side we pass the segmentsSyncTask, used by SplitsUpdateWorker to fetch new segments
|
|
64
59
|
const splitsUpdateWorker = new SplitsUpdateWorker(storage.splits, pollingManager.splitsSyncTask, readiness.splits, userKey ? undefined : pollingManager.segmentsSyncTask);
|
|
65
60
|
|
|
@@ -68,11 +63,6 @@ export function pushManagerFactory(
|
|
|
68
63
|
// [Only for client-side] map of user keys to their corresponding hash64 and MySegmentsUpdateWorkers.
|
|
69
64
|
// Hash64 is used to process MY_SEGMENTS_UPDATE_V2 events and dispatch actions to the corresponding MySegmentsUpdateWorker.
|
|
70
65
|
const clients: Record<string, { hash64: Hash64, worker: MySegmentsUpdateWorker }> = {};
|
|
71
|
-
if (userKey) {
|
|
72
|
-
const hash = hashUserKey(userKey);
|
|
73
|
-
userKeyHashes[hash] = userKey;
|
|
74
|
-
clients[userKey] = { hash64: hash64(userKey), worker: segmentsUpdateWorker as MySegmentsUpdateWorker };
|
|
75
|
-
}
|
|
76
66
|
|
|
77
67
|
// [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
|
|
78
68
|
let connectForNewClient = false;
|
|
@@ -176,7 +166,7 @@ export function pushManagerFactory(
|
|
|
176
166
|
function stopWorkers() {
|
|
177
167
|
splitsUpdateWorker.backoff.reset();
|
|
178
168
|
if (userKey) forOwn(clients, ({ worker }) => worker.backoff.reset());
|
|
179
|
-
else segmentsUpdateWorker.backoff.reset();
|
|
169
|
+
else (segmentsUpdateWorker as SegmentsUpdateWorker).backoff.reset();
|
|
180
170
|
}
|
|
181
171
|
|
|
182
172
|
pushEmitter.on(PUSH_SUBSYSTEM_DOWN, stopWorkers);
|
|
@@ -306,37 +296,40 @@ export function pushManagerFactory(
|
|
|
306
296
|
// Expose Event Emitter functionality and Event constants
|
|
307
297
|
Object.create(pushEmitter),
|
|
308
298
|
{
|
|
309
|
-
//
|
|
310
|
-
stop
|
|
311
|
-
|
|
299
|
+
// Stop/pause push mode
|
|
300
|
+
stop() {
|
|
301
|
+
disconnectPush(); // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
|
|
302
|
+
if (userKey) this.remove(userKey); // Necessary to properly resume streaming in client-side (e.g., RN SDK transition to foreground).
|
|
303
|
+
},
|
|
304
|
+
// Start/resume push mode
|
|
312
305
|
start() {
|
|
313
306
|
// Guard condition to avoid calling `connectPush` again if the `start` method is called multiple times or if push has been disabled.
|
|
314
307
|
if (disabled || disconnected === false) return;
|
|
315
308
|
disconnected = false;
|
|
316
|
-
|
|
317
|
-
|
|
309
|
+
|
|
310
|
+
if (userKey) this.add(userKey, pollingManager.segmentsSyncTask); // client-side
|
|
311
|
+
else setTimeout(connectPush); // server-side runs in next cycle as in client-side, for consistency with client-side
|
|
318
312
|
},
|
|
319
313
|
|
|
320
314
|
// [Only for client-side]
|
|
321
315
|
add(userKey: string, mySegmentsSyncTask: ISegmentsSyncTask) {
|
|
322
|
-
clients[userKey] = { hash64: hash64(userKey), worker: new MySegmentsUpdateWorker(mySegmentsSyncTask) };
|
|
323
|
-
|
|
324
316
|
const hash = hashUserKey(userKey);
|
|
325
317
|
|
|
326
318
|
if (!userKeyHashes[hash]) {
|
|
327
319
|
userKeyHashes[hash] = userKey;
|
|
320
|
+
clients[userKey] = { hash64: hash64(userKey), worker: new MySegmentsUpdateWorker(mySegmentsSyncTask) };
|
|
328
321
|
connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
|
|
329
|
-
}
|
|
330
322
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
323
|
+
// Reconnects in case of a new client.
|
|
324
|
+
// Run in next event-loop cycle to save authentication calls
|
|
325
|
+
// in case multiple clients are created in the current cycle.
|
|
326
|
+
setTimeout(function checkForReconnect() {
|
|
327
|
+
if (connectForNewClient) {
|
|
328
|
+
connectForNewClient = false;
|
|
329
|
+
connectPush();
|
|
330
|
+
}
|
|
331
|
+
}, 0);
|
|
332
|
+
}
|
|
340
333
|
},
|
|
341
334
|
// [Only for client-side]
|
|
342
335
|
remove(userKey: string) {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { IMySegmentsUpdateData, IMySegmentsUpdateV2Data, ISegmentUpdateData, ISplitUpdateData, ISplitKillData } from './SSEHandler/types';
|
|
2
2
|
import { ITask } from '../types';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { IFetchAuth } from '../../services/types';
|
|
6
|
-
import { IStorageSync } from '../../storages/types';
|
|
7
|
-
import { IEventEmitter, ISettings } from '../../types';
|
|
8
|
-
import { IPlatform } from '../../sdkFactory/types';
|
|
3
|
+
import { ISegmentsSyncTask } from '../polling/types';
|
|
4
|
+
import { IEventEmitter } from '../../types';
|
|
9
5
|
import { ControlType } from './constants';
|
|
10
6
|
|
|
11
7
|
// Internal SDK events, subscribed by SyncManager and PushManager
|
|
@@ -45,26 +41,10 @@ export interface IPushEventEmitter extends IEventEmitter {
|
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
/**
|
|
48
|
-
* PushManager
|
|
44
|
+
* PushManager
|
|
49
45
|
*/
|
|
50
|
-
export interface IPushManager extends ITask, IPushEventEmitter {
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* PushManager for client-side with support for multiple clients
|
|
54
|
-
*/
|
|
55
|
-
export interface IPushManagerCS extends IPushManager {
|
|
46
|
+
export interface IPushManager extends ITask, IPushEventEmitter {
|
|
47
|
+
// Methods used in client-side, to support multiple clients
|
|
56
48
|
add(userKey: string, mySegmentsSyncTask: ISegmentsSyncTask): void,
|
|
57
49
|
remove(userKey: string): void
|
|
58
50
|
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Signature of push manager factory/constructor
|
|
62
|
-
*/
|
|
63
|
-
export type IPushManagerFactoryParams = [
|
|
64
|
-
pollingManager: IPollingManager,
|
|
65
|
-
storage: IStorageSync,
|
|
66
|
-
readiness: IReadinessManager,
|
|
67
|
-
fetchAuth: IFetchAuth,
|
|
68
|
-
platform: IPlatform,
|
|
69
|
-
settings: ISettings
|
|
70
|
-
]
|
|
@@ -2,15 +2,11 @@ import { syncTaskComposite } from '../syncTaskComposite';
|
|
|
2
2
|
import { eventsSyncTaskFactory } from './eventsSyncTask';
|
|
3
3
|
import { impressionsSyncTaskFactory } from './impressionsSyncTask';
|
|
4
4
|
import { impressionCountsSyncTaskFactory } from './impressionCountsSyncTask';
|
|
5
|
-
import {
|
|
6
|
-
import { IStorageSync } from '../../storages/types';
|
|
7
|
-
import { ISettings } from '../../types';
|
|
5
|
+
import { ISyncManagerFactoryParams } from '../types';
|
|
8
6
|
|
|
9
|
-
export function submitterManagerFactory(
|
|
10
|
-
|
|
11
|
-
storage
|
|
12
|
-
splitApi: ISplitApi,
|
|
13
|
-
) {
|
|
7
|
+
export function submitterManagerFactory(params: ISyncManagerFactoryParams) {
|
|
8
|
+
|
|
9
|
+
const { settings, storage, splitApi } = params;
|
|
14
10
|
const log = settings.log;
|
|
15
11
|
const submitters = [
|
|
16
12
|
impressionsSyncTaskFactory(log, splitApi.postTestImpressionsBulk, storage.impressions, settings.scheduler.impressionsRefreshRate, settings.core.labelsEnabled),
|