@splitsoftware/splitio-commons 0.1.1-canary.6 → 0.1.1-rc.18
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/cjs/evaluator/matchers/matcherTypes.js +4 -4
- package/cjs/evaluator/matchersTransform/index.js +11 -11
- package/cjs/evaluator/value/sanitize.js +6 -6
- package/cjs/listeners/browser.js +5 -2
- package/cjs/listeners/node.js +9 -2
- package/cjs/logger/constants.js +3 -1
- package/cjs/logger/messages/error.js +3 -2
- package/cjs/logger/messages/info.js +2 -2
- package/cjs/logger/messages/warn.js +2 -1
- package/cjs/readiness/readinessManager.js +10 -7
- package/cjs/sdkFactory/index.js +1 -1
- package/cjs/services/splitApi.js +9 -1
- package/cjs/services/splitHttpClient.js +5 -4
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/inLocalStorage/index.js +5 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/cjs/storages/inRedis/index.js +5 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/cjs/storages/pluggable/inMemoryWrapper.js +6 -7
- package/cjs/storages/pluggable/index.js +5 -2
- package/cjs/storages/pluggable/wrapperAdapter.js +0 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +92 -89
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +45 -42
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +14 -4
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +0 -8
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -4
- package/cjs/sync/streaming/SSEClient/index.js +38 -20
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/cjs/sync/streaming/SSEHandler/index.js +8 -9
- package/cjs/sync/streaming/SSEHandler/types.js +14 -0
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/cjs/sync/streaming/constants.js +3 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +75 -0
- package/cjs/sync/streaming/pushManager.js +148 -40
- package/cjs/sync/submitters/metricsSyncTask.js +1 -1
- package/cjs/sync/submitters/submitterSyncTask.js +2 -2
- package/cjs/sync/syncManagerFromFile.js +15 -0
- package/cjs/sync/syncManagerFromObject.js +14 -0
- package/cjs/sync/syncManagerOffline.js +3 -3
- package/cjs/sync/syncManagerOnline.js +18 -5
- package/cjs/sync/syncTask.js +1 -1
- package/cjs/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/cjs/trackers/impressionObserver/buildKey.js +3 -9
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/cjs/utils/constants/index.js +4 -1
- package/cjs/utils/decompress/index.js +427 -0
- package/cjs/utils/murmur3/{commons.js → common.js} +2 -6
- package/cjs/utils/murmur3/murmur3.js +11 -12
- package/cjs/utils/murmur3/murmur3_128.js +7 -142
- package/cjs/utils/murmur3/murmur3_128_x86.js +154 -0
- package/cjs/utils/murmur3/murmur3_64.js +36 -0
- package/cjs/utils/murmur3/utfx.js +100 -106
- package/cjs/utils/promise/wrapper.js +14 -11
- package/cjs/utils/settingsValidation/index.js +5 -2
- package/cjs/utils/settingsValidation/localhost/index.js +20 -0
- package/cjs/utils/settingsValidation/splitFilters.js +0 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +18 -8
- package/cjs/utils/settingsValidation/url.js +1 -1
- package/esm/evaluator/matchers/matcherTypes.js +2 -2
- package/esm/evaluator/matchersTransform/index.js +12 -12
- package/esm/evaluator/value/sanitize.js +7 -7
- package/esm/listeners/browser.js +5 -2
- package/esm/listeners/node.js +9 -2
- package/esm/logger/constants.js +2 -0
- package/esm/logger/messages/error.js +3 -2
- package/esm/logger/messages/info.js +2 -2
- package/esm/logger/messages/warn.js +2 -1
- package/esm/readiness/readinessManager.js +10 -7
- package/esm/sdkFactory/index.js +1 -1
- package/esm/services/splitApi.js +9 -1
- package/esm/services/splitHttpClient.js +5 -4
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/inLocalStorage/index.js +5 -2
- package/esm/storages/inMemory/InMemoryStorage.js +2 -0
- package/esm/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/esm/storages/inRedis/index.js +5 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/esm/storages/pluggable/inMemoryWrapper.js +6 -7
- package/esm/storages/pluggable/index.js +5 -2
- package/esm/storages/pluggable/wrapperAdapter.js +0 -1
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +90 -88
- package/esm/sync/offline/splitsParser/splitsParserFromSettings.js +43 -41
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +15 -5
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +0 -8
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +2 -4
- package/esm/sync/streaming/SSEClient/index.js +38 -20
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/esm/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/esm/sync/streaming/SSEHandler/index.js +9 -10
- package/esm/sync/streaming/SSEHandler/types.js +13 -1
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/esm/sync/streaming/constants.js +2 -0
- package/esm/sync/streaming/mySegmentsV2utils.js +69 -0
- package/esm/sync/streaming/pushManager.js +150 -42
- package/esm/sync/submitters/metricsSyncTask.js +1 -1
- package/esm/sync/submitters/submitterSyncTask.js +2 -2
- package/esm/sync/syncManagerFromFile.js +11 -0
- package/esm/sync/syncManagerFromObject.js +10 -0
- package/esm/sync/syncManagerOffline.js +3 -3
- package/esm/sync/syncManagerOnline.js +18 -5
- package/esm/sync/syncTask.js +1 -1
- package/esm/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/esm/trackers/impressionObserver/buildKey.js +2 -9
- package/esm/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/esm/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/esm/utils/constants/index.js +3 -0
- package/esm/utils/decompress/index.js +424 -0
- package/esm/utils/murmur3/{commons.js → common.js} +1 -4
- package/esm/utils/murmur3/murmur3.js +1 -2
- package/esm/utils/murmur3/murmur3_128.js +7 -142
- package/esm/utils/murmur3/murmur3_128_x86.js +150 -0
- package/esm/utils/murmur3/murmur3_64.js +32 -0
- package/esm/utils/murmur3/utfx.js +96 -106
- package/esm/utils/promise/wrapper.js +14 -11
- package/esm/utils/settingsValidation/index.js +5 -2
- package/esm/utils/settingsValidation/localhost/index.js +16 -0
- package/esm/utils/settingsValidation/splitFilters.js +0 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +16 -7
- package/esm/utils/settingsValidation/url.js +1 -1
- package/package.json +5 -5
- package/src/evaluator/matchers/matcherTypes.ts +2 -2
- package/src/evaluator/matchersTransform/index.ts +12 -12
- package/src/evaluator/value/sanitize.ts +7 -7
- package/src/listeners/browser.ts +5 -2
- package/src/listeners/node.ts +14 -2
- package/src/logger/constants.ts +2 -0
- package/src/logger/messages/error.ts +3 -2
- package/src/logger/messages/info.ts +2 -2
- package/src/logger/messages/warn.ts +3 -1
- package/src/readiness/readinessManager.ts +9 -7
- package/src/sdkFactory/index.ts +1 -1
- package/src/sdkFactory/types.ts +4 -5
- package/src/services/splitApi.ts +12 -3
- package/src/services/splitHttpClient.ts +6 -5
- package/src/services/types.ts +7 -3
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/inLocalStorage/index.ts +8 -4
- package/src/storages/inMemory/InMemoryStorage.ts +3 -0
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -1
- package/src/storages/inRedis/index.ts +8 -4
- package/src/storages/pluggable/SegmentsCachePluggable.ts +1 -1
- package/src/storages/pluggable/SplitsCachePluggable.ts +3 -1
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -7
- package/src/storages/pluggable/index.ts +8 -4
- package/src/storages/pluggable/wrapperAdapter.ts +0 -1
- package/src/storages/types.ts +18 -15
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +110 -105
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +45 -41
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +15 -5
- package/src/sync/polling/fetchers/segmentChangesFetcher.ts +0 -7
- package/src/sync/polling/types.ts +2 -1
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +28 -10
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -3
- package/src/sync/streaming/AuthClient/types.ts +3 -0
- package/src/sync/streaming/SSEClient/index.ts +43 -23
- package/src/sync/streaming/SSEClient/types.ts +0 -1
- package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +8 -0
- package/src/sync/streaming/SSEHandler/NotificationParser.ts +4 -2
- package/src/sync/streaming/SSEHandler/index.ts +11 -20
- package/src/sync/streaming/SSEHandler/types.ts +37 -3
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +7 -6
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +2 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +4 -3
- package/src/sync/streaming/UpdateWorkers/types.ts +1 -1
- package/src/sync/streaming/constants.ts +2 -0
- package/src/sync/streaming/mySegmentsV2utils.ts +77 -0
- package/src/sync/streaming/pushManager.ts +145 -42
- package/src/sync/streaming/types.ts +14 -22
- package/src/sync/submitters/metricsSyncTask.ts +1 -1
- package/src/sync/submitters/submitterSyncTask.ts +2 -1
- package/src/sync/syncManagerFromFile.ts +13 -0
- package/src/sync/syncManagerFromObject.ts +12 -0
- package/src/sync/syncManagerOffline.ts +3 -3
- package/src/sync/syncManagerOnline.ts +19 -5
- package/src/sync/syncTask.ts +1 -1
- package/src/sync/types.ts +3 -1
- package/src/trackers/impressionObserver/ImpressionObserver.ts +4 -6
- package/src/trackers/impressionObserver/buildKey.ts +2 -16
- package/src/trackers/impressionObserver/impressionObserverCS.ts +2 -2
- package/src/trackers/impressionObserver/impressionObserverSS.ts +3 -3
- package/src/types.ts +16 -2
- package/src/utils/constants/index.ts +6 -1
- package/src/utils/decompress/index.ts +429 -0
- package/src/utils/lang/index.ts +1 -1
- package/src/utils/murmur3/{commons.ts → common.ts} +1 -5
- package/src/utils/murmur3/murmur3.ts +5 -5
- package/src/utils/murmur3/murmur3_128.ts +7 -180
- package/src/utils/murmur3/murmur3_128_x86.ts +188 -0
- package/src/utils/murmur3/murmur3_64.ts +36 -0
- package/src/utils/murmur3/utfx.ts +92 -110
- package/src/utils/promise/wrapper.ts +12 -9
- package/src/utils/settingsValidation/index.ts +8 -4
- package/src/utils/settingsValidation/localhost/index.ts +19 -0
- package/src/utils/settingsValidation/splitFilters.ts +0 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +21 -8
- package/src/utils/settingsValidation/types.ts +2 -11
- package/src/utils/settingsValidation/url.ts +1 -1
- package/types/evaluator/matchers/matcherTypes.d.ts +2 -2
- package/types/listeners/browser.d.ts +3 -3
- package/types/listeners/node.d.ts +3 -2
- package/types/logger/constants.d.ts +2 -0
- package/types/sdkFactory/types.d.ts +4 -5
- package/types/services/types.d.ts +4 -0
- package/types/storages/inLocalStorage/index.d.ts +2 -2
- package/types/storages/inMemory/InMemoryStorage.d.ts +3 -0
- package/types/storages/inMemory/InMemoryStorageCS.d.ts +3 -0
- package/types/storages/inRedis/index.d.ts +2 -2
- package/types/storages/pluggable/index.d.ts +2 -2
- package/types/storages/types.d.ts +15 -15
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -7
- package/types/sync/offline/splitsParser/splitsParserFromSettings.d.ts +1 -5
- package/types/sync/polling/types.d.ts +2 -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/AuthClient/types.d.ts +2 -0
- package/types/sync/streaming/SSEClient/index.d.ts +9 -12
- package/types/sync/streaming/SSEClient/types.d.ts +0 -1
- package/types/sync/streaming/SSEHandler/NotificationParser.d.ts +3 -2
- package/types/sync/streaming/SSEHandler/types.d.ts +30 -2
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +4 -3
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +2 -1
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +3 -2
- package/types/sync/streaming/UpdateWorkers/types.d.ts +1 -1
- package/types/sync/streaming/constants.d.ts +3 -1
- package/types/sync/streaming/mySegmentsV2utils.d.ts +27 -0
- package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
- package/types/sync/streaming/types.d.ts +9 -5
- package/types/sync/submitters/submitterSyncTask.d.ts +1 -1
- package/types/sync/syncManagerFromFile.d.ts +2 -0
- package/types/sync/syncManagerFromObject.d.ts +2 -0
- package/types/sync/syncManagerOffline.d.ts +1 -1
- package/types/sync/syncTask.d.ts +1 -1
- package/types/sync/types.d.ts +2 -0
- package/types/trackers/impressionObserver/ImpressionObserver.d.ts +2 -2
- package/types/trackers/impressionObserver/buildKey.d.ts +1 -1
- package/types/trackers/impressionObserver/impressionObserverCS.d.ts +2 -2
- package/types/trackers/impressionObserver/impressionObserverSS.d.ts +2 -2
- package/types/types.d.ts +16 -2
- package/types/utils/constants/index.d.ts +5 -1
- package/types/utils/decompress/index.d.ts +16 -0
- package/types/utils/lang/index.d.ts +1 -1
- package/types/utils/murmur3/common.d.ts +12 -0
- package/types/utils/murmur3/murmur3.d.ts +2 -2
- package/types/utils/murmur3/murmur3_128.d.ts +5 -0
- package/types/utils/murmur3/murmur3_128_x86.d.ts +7 -0
- package/types/utils/murmur3/murmur3_64.d.ts +10 -0
- package/types/utils/murmur3/utfx.d.ts +24 -6
- package/types/utils/settingsValidation/index.d.ts +3 -2
- package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
- package/types/utils/settingsValidation/storage/storageCS.d.ts +7 -1
- package/types/utils/settingsValidation/types.d.ts +2 -10
- package/cjs/sync/streaming/pushManagerCS.js +0 -178
- package/cjs/sync/streaming/pushManagerSS.js +0 -128
- package/esm/sync/streaming/pushManagerCS.js +0 -174
- package/esm/sync/streaming/pushManagerSS.js +0 -124
- package/src/sync/streaming/pushManagerCS.ts +0 -237
- package/src/sync/streaming/pushManagerSS.ts +0 -177
|
@@ -102,7 +102,6 @@ function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
102
102
|
return res;
|
|
103
103
|
}
|
|
104
104
|
// Validate filters and group their values by filter type inside `groupedFilters` object
|
|
105
|
-
// Assign the valid filters to the output of the validator by using filter function
|
|
106
105
|
res.validFilters = maybeSplitFilters.filter(function (filter, index) {
|
|
107
106
|
if (filter && validateFilterType(filter.type) && Array.isArray(filter.values)) {
|
|
108
107
|
res.groupedFilters[filter.type] = res.groupedFilters[filter.type].concat(filter.values);
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateStorageCS = void 0;
|
|
3
|
+
exports.validateStorageCS = exports.__InLocalStorageMockFactory = void 0;
|
|
4
4
|
var InMemoryStorageCS_1 = require("../../../storages/inMemory/InMemoryStorageCS");
|
|
5
5
|
var constants_1 = require("../../../logger/constants");
|
|
6
|
+
var constants_2 = require("../../../utils/constants");
|
|
7
|
+
function __InLocalStorageMockFactory(params) {
|
|
8
|
+
var result = InMemoryStorageCS_1.InMemoryStorageCSFactory(params);
|
|
9
|
+
result.splits.checkCache = function () { return true; }; // to emit SDK_READY_FROM_CACHE
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
exports.__InLocalStorageMockFactory = __InLocalStorageMockFactory;
|
|
13
|
+
__InLocalStorageMockFactory.type = constants_2.STORAGE_MEMORY;
|
|
6
14
|
/**
|
|
7
15
|
* This function validates `settings.storage` object
|
|
8
16
|
*
|
|
@@ -11,15 +19,17 @@ var constants_1 = require("../../../logger/constants");
|
|
|
11
19
|
* @returns {Object} valid storage factory. It might be the default `InMemoryStorageCSFactory` if the provided storage is invalid.
|
|
12
20
|
*/
|
|
13
21
|
function validateStorageCS(settings) {
|
|
14
|
-
var
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (typeof storage === 'function')
|
|
19
|
-
return storage;
|
|
22
|
+
var _a = settings.storage, storage = _a === void 0 ? InMemoryStorageCS_1.InMemoryStorageCSFactory : _a, log = settings.log, mode = settings.mode;
|
|
23
|
+
// If an invalid storage is provided, fallback into MEMORY
|
|
24
|
+
if (typeof storage !== 'function' || storage.type !== constants_2.STORAGE_MEMORY && storage.type !== constants_2.STORAGE_LOCALSTORAGE) {
|
|
25
|
+
storage = InMemoryStorageCS_1.InMemoryStorageCSFactory;
|
|
20
26
|
log.warn(constants_1.WARN_STORAGE_INVALID);
|
|
21
27
|
}
|
|
28
|
+
// In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
|
|
29
|
+
if (mode === constants_2.LOCALHOST_MODE && storage.type === constants_2.STORAGE_LOCALSTORAGE) {
|
|
30
|
+
return __InLocalStorageMockFactory;
|
|
31
|
+
}
|
|
22
32
|
// return default InMemory storage if provided one is not valid
|
|
23
|
-
return
|
|
33
|
+
return storage;
|
|
24
34
|
}
|
|
25
35
|
exports.validateStorageCS = validateStorageCS;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.url = void 0;
|
|
4
4
|
var eventsEndpointMatcher = /^\/(testImpressions|metrics|events)/;
|
|
5
|
-
var authEndpointMatcher = /^\/auth/;
|
|
5
|
+
var authEndpointMatcher = /^\/v2\/auth/;
|
|
6
6
|
var streamingEndpointMatcher = /^\/(sse|event-stream)/;
|
|
7
7
|
/**
|
|
8
8
|
* Get URL based on a given target (path).
|
|
@@ -18,7 +18,7 @@ export var matcherTypes = {
|
|
|
18
18
|
EQUAL_TO_BOOLEAN: 16,
|
|
19
19
|
MATCHES_STRING: 17
|
|
20
20
|
};
|
|
21
|
-
export var
|
|
21
|
+
export var matcherDataTypes = {
|
|
22
22
|
BOOLEAN: 'BOOLEAN',
|
|
23
23
|
STRING: 'STRING',
|
|
24
24
|
NUMBER: 'NUMBER',
|
|
@@ -26,7 +26,7 @@ export var dataTypes = {
|
|
|
26
26
|
DATETIME: 'DATETIME',
|
|
27
27
|
NOT_SPECIFIED: 'NOT_SPECIFIED'
|
|
28
28
|
};
|
|
29
|
-
export function
|
|
29
|
+
export function matcherTypesMapper(matcherType) {
|
|
30
30
|
var type = matcherTypes[matcherType];
|
|
31
31
|
if (type)
|
|
32
32
|
return type;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { findIndex } from '../../utils/lang';
|
|
2
|
-
import { matcherTypes,
|
|
2
|
+
import { matcherTypes, matcherTypesMapper, matcherDataTypes } from '../matchers/matcherTypes';
|
|
3
3
|
import segmentTransform from './segment';
|
|
4
4
|
import whitelistTransform from './whitelist';
|
|
5
5
|
import setTransform from './set';
|
|
@@ -12,9 +12,9 @@ export default function matchersTransform(matchers) {
|
|
|
12
12
|
var parsedMatchers = matchers.map(function (matcher) {
|
|
13
13
|
var matcherType = matcher.matcherType /* string */, negate = matcher.negate /* boolean */, keySelector = matcher.keySelector /* keySelectorObject */, segmentObject = matcher.userDefinedSegmentMatcherData /* segmentObject */, whitelistObject = matcher.whitelistMatcherData /* whiteListObject, provided by 'WHITELIST', set and string matchers */, unaryNumericObject = matcher.unaryNumericMatcherData /* unaryNumericObject */, betweenObject = matcher.betweenMatcherData /* betweenObject */, dependencyObject = matcher.dependencyMatcherData /* dependencyObject */, booleanMatcherData = matcher.booleanMatcherData, stringMatcherData = matcher.stringMatcherData;
|
|
14
14
|
var attribute = keySelector && keySelector.attribute;
|
|
15
|
-
var type =
|
|
15
|
+
var type = matcherTypesMapper(matcherType);
|
|
16
16
|
// As default input data type we use string (even for ALL_KEYS)
|
|
17
|
-
var dataType =
|
|
17
|
+
var dataType = matcherDataTypes.STRING;
|
|
18
18
|
var value = undefined;
|
|
19
19
|
if (type === matcherTypes.IN_SEGMENT) {
|
|
20
20
|
value = segmentTransform(segmentObject);
|
|
@@ -24,28 +24,28 @@ export default function matchersTransform(matchers) {
|
|
|
24
24
|
}
|
|
25
25
|
else if (type === matcherTypes.EQUAL_TO) {
|
|
26
26
|
value = numericTransform(unaryNumericObject);
|
|
27
|
-
dataType =
|
|
27
|
+
dataType = matcherDataTypes.NUMBER;
|
|
28
28
|
if (unaryNumericObject.dataType === 'DATETIME') {
|
|
29
29
|
value = zeroSinceHH(value);
|
|
30
|
-
dataType =
|
|
30
|
+
dataType = matcherDataTypes.DATETIME;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
else if (type === matcherTypes.GREATER_THAN_OR_EQUAL_TO ||
|
|
34
34
|
type === matcherTypes.LESS_THAN_OR_EQUAL_TO) {
|
|
35
35
|
value = numericTransform(unaryNumericObject);
|
|
36
|
-
dataType =
|
|
36
|
+
dataType = matcherDataTypes.NUMBER;
|
|
37
37
|
if (unaryNumericObject.dataType === 'DATETIME') {
|
|
38
38
|
value = zeroSinceSS(value);
|
|
39
|
-
dataType =
|
|
39
|
+
dataType = matcherDataTypes.DATETIME;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
else if (type === matcherTypes.BETWEEN) {
|
|
43
43
|
value = betweenObject;
|
|
44
|
-
dataType =
|
|
44
|
+
dataType = matcherDataTypes.NUMBER;
|
|
45
45
|
if (value.dataType === 'DATETIME') {
|
|
46
46
|
value.start = zeroSinceSS(value.start);
|
|
47
47
|
value.end = zeroSinceSS(value.end);
|
|
48
|
-
dataType =
|
|
48
|
+
dataType = matcherDataTypes.DATETIME;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
else if (type === matcherTypes.EQUAL_TO_SET ||
|
|
@@ -53,7 +53,7 @@ export default function matchersTransform(matchers) {
|
|
|
53
53
|
type === matcherTypes.CONTAINS_ALL_OF_SET ||
|
|
54
54
|
type === matcherTypes.PART_OF_SET) {
|
|
55
55
|
value = setTransform(whitelistObject);
|
|
56
|
-
dataType =
|
|
56
|
+
dataType = matcherDataTypes.SET;
|
|
57
57
|
}
|
|
58
58
|
else if (type === matcherTypes.STARTS_WITH ||
|
|
59
59
|
type === matcherTypes.ENDS_WITH ||
|
|
@@ -62,10 +62,10 @@ export default function matchersTransform(matchers) {
|
|
|
62
62
|
}
|
|
63
63
|
else if (type === matcherTypes.IN_SPLIT_TREATMENT) {
|
|
64
64
|
value = dependencyObject;
|
|
65
|
-
dataType =
|
|
65
|
+
dataType = matcherDataTypes.NOT_SPECIFIED;
|
|
66
66
|
}
|
|
67
67
|
else if (type === matcherTypes.EQUAL_TO_BOOLEAN) {
|
|
68
|
-
dataType =
|
|
68
|
+
dataType = matcherDataTypes.BOOLEAN;
|
|
69
69
|
value = booleanMatcherData;
|
|
70
70
|
}
|
|
71
71
|
else if (type === matcherTypes.MATCHES_STRING) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isObject, uniq, toString, toNumber } from '../../utils/lang';
|
|
2
2
|
import { zeroSinceHH, zeroSinceSS } from '../convertions';
|
|
3
|
-
import { matcherTypes,
|
|
3
|
+
import { matcherTypes, matcherDataTypes } from '../matchers/matcherTypes';
|
|
4
4
|
import { ENGINE_SANITIZE } from '../../logger/constants';
|
|
5
5
|
function sanitizeNumber(val) {
|
|
6
6
|
var num = toNumber(val);
|
|
@@ -61,20 +61,20 @@ export default function sanitize(log, matcherTypeID, value, dataType, attributes
|
|
|
61
61
|
var processor = getProcessingFunction(matcherTypeID, dataType);
|
|
62
62
|
var sanitizedValue;
|
|
63
63
|
switch (dataType) {
|
|
64
|
-
case
|
|
65
|
-
case
|
|
64
|
+
case matcherDataTypes.NUMBER:
|
|
65
|
+
case matcherDataTypes.DATETIME:
|
|
66
66
|
sanitizedValue = sanitizeNumber(value);
|
|
67
67
|
break;
|
|
68
|
-
case
|
|
68
|
+
case matcherDataTypes.STRING:
|
|
69
69
|
sanitizedValue = sanitizeString(value);
|
|
70
70
|
break;
|
|
71
|
-
case
|
|
71
|
+
case matcherDataTypes.SET:
|
|
72
72
|
sanitizedValue = sanitizeArray(value);
|
|
73
73
|
break;
|
|
74
|
-
case
|
|
74
|
+
case matcherDataTypes.BOOLEAN:
|
|
75
75
|
sanitizedValue = sanitizeBoolean(value);
|
|
76
76
|
break;
|
|
77
|
-
case
|
|
77
|
+
case matcherDataTypes.NOT_SPECIFIED:
|
|
78
78
|
sanitizedValue = value;
|
|
79
79
|
break;
|
|
80
80
|
default:
|
package/esm/listeners/browser.js
CHANGED
|
@@ -10,8 +10,8 @@ var EVENT_NAME = 'for unload page event.';
|
|
|
10
10
|
* We'll listen for 'unload' event over the window object, since it's the standard way to listen page reload and close.
|
|
11
11
|
*/
|
|
12
12
|
var BrowserSignalListener = /** @class */ (function () {
|
|
13
|
-
function BrowserSignalListener(
|
|
14
|
-
|
|
13
|
+
function BrowserSignalListener(syncManager, settings, storage, serviceApi) {
|
|
14
|
+
this.syncManager = syncManager;
|
|
15
15
|
this.settings = settings;
|
|
16
16
|
this.storage = storage;
|
|
17
17
|
this.serviceApi = serviceApi;
|
|
@@ -55,6 +55,9 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
55
55
|
this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
|
56
56
|
if (this.storage.impressionCounts)
|
|
57
57
|
this._flushData(eventsUrl + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, fromImpressionCountsCollector);
|
|
58
|
+
// Close streaming connection
|
|
59
|
+
if (this.syncManager && this.syncManager.pushManager)
|
|
60
|
+
this.syncManager.pushManager.stop();
|
|
58
61
|
};
|
|
59
62
|
BrowserSignalListener.prototype._flushData = function (url, cache, postService, fromCacheToPayload, extraMetadata) {
|
|
60
63
|
// if there is data in cache, send it to backend
|
package/esm/listeners/node.js
CHANGED
|
@@ -10,8 +10,15 @@ var EVENT_NAME = 'for SIGTERM signal.';
|
|
|
10
10
|
* the process is already exiting.
|
|
11
11
|
*/
|
|
12
12
|
var NodeSignalListener = /** @class */ (function () {
|
|
13
|
-
function NodeSignalListener(
|
|
14
|
-
|
|
13
|
+
function NodeSignalListener(syncManager, // private handler: () => MaybeThenable<void>,
|
|
14
|
+
settings) {
|
|
15
|
+
// @TODO review handler logic when implementing Node SDK
|
|
16
|
+
this.handler = function () {
|
|
17
|
+
if (syncManager) {
|
|
18
|
+
// syncManager.stop();
|
|
19
|
+
return syncManager.flush();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
15
22
|
this.settings = settings;
|
|
16
23
|
this._sigtermHandler = this._sigtermHandler.bind(this);
|
|
17
24
|
}
|
package/esm/logger/constants.js
CHANGED
|
@@ -91,6 +91,7 @@ export var WARN_SPLITS_FILTER_INVALID = 220;
|
|
|
91
91
|
export var WARN_SPLITS_FILTER_EMPTY = 221;
|
|
92
92
|
export var WARN_STORAGE_INVALID = 222;
|
|
93
93
|
export var WARN_API_KEY = 223;
|
|
94
|
+
export var STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
94
95
|
export var ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
95
96
|
export var ERROR_LOGLEVEL_INVALID = 301;
|
|
96
97
|
export var ERROR_CLIENT_LISTENER = 302;
|
|
@@ -114,6 +115,7 @@ export var ERROR_EMPTY = 319;
|
|
|
114
115
|
export var ERROR_EMPTY_ARRAY = 320;
|
|
115
116
|
export var ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
116
117
|
export var ERROR_HTTP = 322;
|
|
118
|
+
export var ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
117
119
|
// Log prefixes (a.k.a. tags or categories)
|
|
118
120
|
export var LOG_PREFIX_SETTINGS = 'settings';
|
|
119
121
|
export var LOG_PREFIX_INSTANTIATION = 'Factory instantiation';
|
|
@@ -10,8 +10,8 @@ export var codesError = [
|
|
|
10
10
|
[c.ERROR_EVENTS_TRACKER, c.LOG_PREFIX_EVENTS_TRACKER + 'Failed to queue %s'],
|
|
11
11
|
// synchronizer
|
|
12
12
|
[c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
|
|
13
|
-
[c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + '
|
|
14
|
-
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error:
|
|
13
|
+
[c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
|
|
14
|
+
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
|
|
15
15
|
[c.ERROR_HTTP, ' Response status is not OK. Status: %s. URL: %s. Message: %s'],
|
|
16
16
|
// client status
|
|
17
17
|
[c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
|
|
@@ -29,4 +29,5 @@ export var codesError = [
|
|
|
29
29
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
30
30
|
// initialization / settings validation
|
|
31
31
|
[c.ERROR_INVALID_IMPRESSIONS_MODE, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "impressionsMode". It should be one of the following values: %s. Defaulting to "%s" mode.'],
|
|
32
|
+
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': you didn\'t pass a valid "sync.localhostMode". It should be defined for using the SDK in localhost mode']
|
|
32
33
|
];
|
|
@@ -19,9 +19,9 @@ export var codesInfo = codesWarn.concat([
|
|
|
19
19
|
[c.SYNC_SPLITS_FETCH_RETRY, c.LOG_PREFIX_SYNC_SPLITS + 'Retrying download of splits #%s. Reason: %s'],
|
|
20
20
|
[c.SUBMITTERS_PUSH_FULL_EVENTS_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full events queue and reseting timer.'],
|
|
21
21
|
[c.SUBMITTERS_PUSH, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Pushing %s %s.'],
|
|
22
|
-
[c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds.'],
|
|
22
|
+
[c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds, and connecting streaming in %s seconds.'],
|
|
23
23
|
[c.STREAMING_RECONNECT, c.LOG_PREFIX_SYNC_STREAMING + 'Attempting to reconnect in %s seconds.'],
|
|
24
|
-
[c.STREAMING_CONNECTING, c.LOG_PREFIX_SYNC_STREAMING + '
|
|
24
|
+
[c.STREAMING_CONNECTING, c.LOG_PREFIX_SYNC_STREAMING + '%sConnecting to streaming.'],
|
|
25
25
|
[c.STREAMING_DISABLED, c.LOG_PREFIX_SYNC_STREAMING + 'Streaming is disabled for given Api key. Switching to polling mode.'],
|
|
26
26
|
[c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting from streaming.'],
|
|
27
27
|
[c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
|
|
@@ -29,5 +29,6 @@ export var codesWarn = codesError.concat([
|
|
|
29
29
|
[c.WARN_SPLITS_FILTER_INVALID, c.LOG_PREFIX_SETTINGS + ': split filter at position %s is invalid. It must be an object with a valid filter type ("byName" or "byPrefix") and a list of "values".'],
|
|
30
30
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': splitFilters configuration must be a non-empty array of filter objects.'],
|
|
31
31
|
[c.WARN_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid. Fallbacking into default MEMORY storage'],
|
|
32
|
-
[c.WARN_API_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application']
|
|
32
|
+
[c.WARN_API_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
33
|
+
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
33
34
|
]);
|
|
@@ -31,7 +31,7 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
|
|
|
31
31
|
// emit SDK_READY_FROM_CACHE
|
|
32
32
|
var isReadyFromCache = false;
|
|
33
33
|
if (splits.splitsCacheLoaded)
|
|
34
|
-
|
|
34
|
+
isReadyFromCache = true; // ready from cache, but doesn't emit SDK_READY_FROM_CACHE
|
|
35
35
|
else
|
|
36
36
|
splits.once(SDK_SPLITS_CACHE_LOADED, checkIsReadyFromCache);
|
|
37
37
|
// emit SDK_READY_TIMED_OUT
|
|
@@ -49,13 +49,16 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
|
|
|
49
49
|
segments.on(SDK_SEGMENTS_ARRIVED, checkIsReadyOrUpdate);
|
|
50
50
|
var isDestroyed = false;
|
|
51
51
|
function checkIsReadyFromCache() {
|
|
52
|
-
|
|
53
|
-
if
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
isReadyFromCache = true;
|
|
52
|
+
isReadyFromCache = true;
|
|
53
|
+
// Don't emit SDK_READY_FROM_CACHE if SDK_READY has been emitted
|
|
54
|
+
if (!isReady) {
|
|
55
|
+
try {
|
|
57
56
|
gate.emit(SDK_READY_FROM_CACHE);
|
|
58
|
-
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
// throws user callback exceptions in next tick
|
|
60
|
+
setTimeout(function () { throw e; }, 0);
|
|
61
|
+
}
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
function checkIsReadyOrUpdate(diff) {
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -54,7 +54,7 @@ export function sdkFactory(params) {
|
|
|
54
54
|
var impressionsTracker = impressionsTrackerFactory(log, storage.impressions, settings, impressionListener, integrationsManager, observer, storage.impressionCounts);
|
|
55
55
|
var eventTracker = eventTrackerFactory(log, storage.events, integrationsManager);
|
|
56
56
|
// signal listener
|
|
57
|
-
var signalListener = SignalListener && new SignalListener(syncManager
|
|
57
|
+
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
|
58
58
|
// Sdk client and manager
|
|
59
59
|
var clientMethod = sdkClientMethodFactory({ eventTracker: eventTracker, impressionsTracker: impressionsTracker, sdkReadinessManager: sdkReadinessManager, settings: settings, storage: storage, syncManager: syncManager, signalListener: signalListener });
|
|
60
60
|
var managerInstance = sdkManagerFactory(log, storage.splits, sdkReadinessManager);
|
package/esm/services/splitApi.js
CHANGED
|
@@ -16,8 +16,16 @@ export function splitApiFactory(settings, platform) {
|
|
|
16
16
|
var SplitSDKImpressionsMode = settings.sync.impressionsMode;
|
|
17
17
|
var splitHttpClient = splitHttpClientFactory(settings, platform.getFetch, platform.getOptions);
|
|
18
18
|
return {
|
|
19
|
+
getSdkAPIHealthCheck: function () {
|
|
20
|
+
var url = urls.sdk + "/version";
|
|
21
|
+
return splitHttpClient(url).then(function () { return true; }).catch(function () { return false; });
|
|
22
|
+
},
|
|
23
|
+
getEventsAPIHealthCheck: function () {
|
|
24
|
+
var url = urls.events + "/version";
|
|
25
|
+
return splitHttpClient(url).then(function () { return true; }).catch(function () { return false; });
|
|
26
|
+
},
|
|
19
27
|
fetchAuth: function (userMatchingKeys) {
|
|
20
|
-
var url = urls.auth + "/auth";
|
|
28
|
+
var url = urls.auth + "/v2/auth";
|
|
21
29
|
if (userMatchingKeys) { // accounting the possibility that `userMatchingKeys` is undefined (server-side API)
|
|
22
30
|
var queryParams = userMatchingKeys.map(userKeyToQueryParam).join('&');
|
|
23
31
|
if (queryParams) // accounting the possibility that `userKeys` and thus `queryParams` are empty
|
|
@@ -37,8 +37,8 @@ export function splitHttpClientFactory(settings, getFetch, getOptions) {
|
|
|
37
37
|
return fetch ? fetch(url, request)
|
|
38
38
|
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
|
|
39
39
|
.then(function (response) {
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
return response.text().then(function (message) { return Promise.reject({ response: response, message: message }); });
|
|
42
42
|
}
|
|
43
43
|
return response;
|
|
44
44
|
})
|
|
@@ -50,13 +50,14 @@ export function splitHttpClientFactory(settings, getFetch, getOptions) {
|
|
|
50
50
|
case 404:
|
|
51
51
|
msg = 'Invalid API key or resource not found.';
|
|
52
52
|
break;
|
|
53
|
+
// Don't use resp.statusText since reason phrase is removed in HTTP/2
|
|
53
54
|
default:
|
|
54
|
-
msg =
|
|
55
|
+
msg = error.message;
|
|
55
56
|
break;
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
else { // Something else, either an error making the request or a Network error.
|
|
59
|
-
msg = error.message;
|
|
60
|
+
msg = error.message || 'Network Error';
|
|
60
61
|
}
|
|
61
62
|
if (!resp || resp.status !== 403) { // 403's log we'll be handled somewhere else.
|
|
62
63
|
log[logErrorsAsInfo ? 'info' : 'error'](ERROR_HTTP, [resp ? resp.status : 'NO_STATUS', url, msg]);
|
|
@@ -30,7 +30,7 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
30
30
|
* It is used as condition to emit SDK_SPLITS_CACHE_LOADED, and then SDK_READY_FROM_CACHE.
|
|
31
31
|
*/
|
|
32
32
|
AbstractSplitsCacheSync.prototype.checkCache = function () {
|
|
33
|
-
return
|
|
33
|
+
return false;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
@@ -11,13 +11,14 @@ import SplitsCacheInMemory from '../inMemory/SplitsCacheInMemory';
|
|
|
11
11
|
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
|
|
12
12
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
13
13
|
import { LOG_PREFIX } from './constants';
|
|
14
|
+
import { STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
14
15
|
/**
|
|
15
16
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
16
17
|
*/
|
|
17
18
|
export function InLocalStorage(options) {
|
|
18
19
|
if (options === void 0) { options = {}; }
|
|
19
20
|
var prefix = validatePrefix(options.prefix);
|
|
20
|
-
|
|
21
|
+
function InLocalStorageCSFactory(params) {
|
|
21
22
|
// Fallback to InMemoryStorage if LocalStorage API is not available
|
|
22
23
|
if (!isLocalStorageAvailable()) {
|
|
23
24
|
params.log.warn(LOG_PREFIX + 'LocalStorage API is unavailable. Fallbacking into default MEMORY storage');
|
|
@@ -55,5 +56,7 @@ export function InLocalStorage(options) {
|
|
|
55
56
|
};
|
|
56
57
|
},
|
|
57
58
|
};
|
|
58
|
-
}
|
|
59
|
+
}
|
|
60
|
+
InLocalStorageCSFactory.type = STORAGE_LOCALSTORAGE;
|
|
61
|
+
return InLocalStorageCSFactory;
|
|
59
62
|
}
|
|
@@ -3,6 +3,7 @@ import SegmentsCacheInMemory from './SegmentsCacheInMemory';
|
|
|
3
3
|
import ImpressionsCacheInMemory from './ImpressionsCacheInMemory';
|
|
4
4
|
import EventsCacheInMemory from './EventsCacheInMemory';
|
|
5
5
|
import ImpressionCountsCacheInMemory from './ImpressionCountsCacheInMemory';
|
|
6
|
+
import { STORAGE_MEMORY } from '../../utils/constants';
|
|
6
7
|
/**
|
|
7
8
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
8
9
|
*
|
|
@@ -28,3 +29,4 @@ export function InMemoryStorageFactory(params) {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
InMemoryStorageFactory.type = STORAGE_MEMORY;
|
|
@@ -3,6 +3,7 @@ import MySegmentsCacheInMemory from './MySegmentsCacheInMemory';
|
|
|
3
3
|
import ImpressionsCacheInMemory from './ImpressionsCacheInMemory';
|
|
4
4
|
import EventsCacheInMemory from './EventsCacheInMemory';
|
|
5
5
|
import ImpressionCountsCacheInMemory from './ImpressionCountsCacheInMemory';
|
|
6
|
+
import { STORAGE_MEMORY } from '../../utils/constants';
|
|
6
7
|
/**
|
|
7
8
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
8
9
|
*
|
|
@@ -40,3 +41,4 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
40
41
|
},
|
|
41
42
|
};
|
|
42
43
|
}
|
|
44
|
+
InMemoryStorageCSFactory.type = STORAGE_MEMORY;
|
|
@@ -34,9 +34,13 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
34
34
|
return _this;
|
|
35
35
|
}
|
|
36
36
|
SplitsCacheInRedis.prototype._decrementCounts = function (split) {
|
|
37
|
+
var _this = this;
|
|
37
38
|
if (split.trafficTypeName) {
|
|
38
|
-
var
|
|
39
|
-
return this.redis.decr(
|
|
39
|
+
var ttKey_1 = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
40
|
+
return this.redis.decr(ttKey_1).then(function (count) {
|
|
41
|
+
if (count === 0)
|
|
42
|
+
return _this.redis.del(ttKey_1);
|
|
43
|
+
});
|
|
40
44
|
}
|
|
41
45
|
};
|
|
42
46
|
SplitsCacheInRedis.prototype._incrementCounts = function (split) {
|
|
@@ -7,6 +7,7 @@ import ImpressionsCacheInRedis from './ImpressionsCacheInRedis';
|
|
|
7
7
|
import EventsCacheInRedis from './EventsCacheInRedis';
|
|
8
8
|
import LatenciesCacheInRedis from './LatenciesCacheInRedis';
|
|
9
9
|
import CountsCacheInRedis from './CountsCacheInRedis';
|
|
10
|
+
import { STORAGE_REDIS } from '../../utils/constants';
|
|
10
11
|
/**
|
|
11
12
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
12
13
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -14,7 +15,7 @@ import CountsCacheInRedis from './CountsCacheInRedis';
|
|
|
14
15
|
export function InRedisStorage(options) {
|
|
15
16
|
if (options === void 0) { options = {}; }
|
|
16
17
|
var prefix = validatePrefix(options.prefix);
|
|
17
|
-
|
|
18
|
+
function InRedisStorageFactory(_a) {
|
|
18
19
|
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
19
20
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
20
21
|
var redisClient = new RedisAdapter(log, options.options || {});
|
|
@@ -37,5 +38,7 @@ export function InRedisStorage(options) {
|
|
|
37
38
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
38
39
|
}
|
|
39
40
|
};
|
|
40
|
-
}
|
|
41
|
+
}
|
|
42
|
+
InRedisStorageFactory.type = STORAGE_REDIS;
|
|
43
|
+
return InRedisStorageFactory;
|
|
41
44
|
}
|
|
@@ -21,9 +21,13 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
21
21
|
return _this;
|
|
22
22
|
}
|
|
23
23
|
SplitsCachePluggable.prototype._decrementCounts = function (split) {
|
|
24
|
+
var _this = this;
|
|
24
25
|
if (split.trafficTypeName) {
|
|
25
|
-
var
|
|
26
|
-
return this.wrapper.decr(
|
|
26
|
+
var ttKey_1 = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
27
|
+
return this.wrapper.decr(ttKey_1).then(function (count) {
|
|
28
|
+
if (count === 0)
|
|
29
|
+
return _this.wrapper.del(ttKey_1);
|
|
30
|
+
});
|
|
27
31
|
}
|
|
28
32
|
};
|
|
29
33
|
SplitsCachePluggable.prototype._incrementCounts = function (split) {
|
|
@@ -31,32 +31,31 @@ export function inMemoryWrapperFactory() {
|
|
|
31
31
|
getKeysByPrefix: function (prefix) {
|
|
32
32
|
return Promise.resolve(Object.keys(_cache).filter(function (key) { return startsWith(key, prefix); }));
|
|
33
33
|
},
|
|
34
|
-
getByPrefix: function (prefix) {
|
|
35
|
-
return Promise.resolve(Object.keys(_cache).filter(function (key) { return startsWith(key, prefix); }).map(function (key) { return _cache[key]; }));
|
|
36
|
-
},
|
|
37
34
|
incr: function (key) {
|
|
38
35
|
if (key in _cache) {
|
|
39
36
|
var count = toNumber(_cache[key]) + 1;
|
|
40
37
|
if (isNaN(count))
|
|
41
|
-
return Promise.
|
|
38
|
+
return Promise.reject('Given key is not a number');
|
|
42
39
|
_cache[key] = count + '';
|
|
40
|
+
return Promise.resolve(count);
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
43
|
_cache[key] = '1';
|
|
44
|
+
return Promise.resolve(1);
|
|
46
45
|
}
|
|
47
|
-
return Promise.resolve(true);
|
|
48
46
|
},
|
|
49
47
|
decr: function (key) {
|
|
50
48
|
if (key in _cache) {
|
|
51
49
|
var count = toNumber(_cache[key]) - 1;
|
|
52
50
|
if (isNaN(count))
|
|
53
|
-
return Promise.
|
|
51
|
+
return Promise.reject('Given key is not a number');
|
|
54
52
|
_cache[key] = count + '';
|
|
53
|
+
return Promise.resolve(count);
|
|
55
54
|
}
|
|
56
55
|
else {
|
|
57
56
|
_cache[key] = '-1';
|
|
57
|
+
return Promise.resolve(-1);
|
|
58
58
|
}
|
|
59
|
-
return Promise.resolve(true);
|
|
60
59
|
},
|
|
61
60
|
getMany: function (keys) {
|
|
62
61
|
return Promise.resolve(keys.map(function (key) { return _cache[key] ? _cache[key] : null; }));
|
|
@@ -6,6 +6,7 @@ import { EventsCachePluggable } from './EventsCachePluggable';
|
|
|
6
6
|
import { wrapperAdapter, METHODS_TO_PROMISE_WRAP } from './wrapperAdapter';
|
|
7
7
|
import { isObject } from '../../utils/lang';
|
|
8
8
|
import { validatePrefix } from '../KeyBuilder';
|
|
9
|
+
import { STORAGE_CUSTOM } from '../../utils/constants';
|
|
9
10
|
var NO_VALID_WRAPPER = 'Expecting custom storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
10
11
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
11
12
|
/**
|
|
@@ -28,7 +29,7 @@ function validatePluggableStorageOptions(options) {
|
|
|
28
29
|
export function PluggableStorage(options) {
|
|
29
30
|
validatePluggableStorageOptions(options);
|
|
30
31
|
var prefix = validatePrefix(options.prefix);
|
|
31
|
-
|
|
32
|
+
function PluggableStorageFactory(_a) {
|
|
32
33
|
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
33
34
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
34
35
|
var wrapper = wrapperAdapter(log, options.wrapper);
|
|
@@ -51,5 +52,7 @@ export function PluggableStorage(options) {
|
|
|
51
52
|
return wrapper.close();
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
|
-
}
|
|
55
|
+
}
|
|
56
|
+
PluggableStorageFactory.type = STORAGE_CUSTOM;
|
|
57
|
+
return PluggableStorageFactory;
|
|
55
58
|
}
|