@splitsoftware/splitio-commons 1.6.2-rc.6 → 1.6.2-rc.7
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/consent/sdkUserConsent.js +2 -2
- package/cjs/listeners/browser.js +2 -1
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +26 -5
- package/cjs/services/splitApi.js +20 -0
- package/cjs/storages/KeyBuilderSS.js +6 -0
- package/cjs/storages/inLocalStorage/index.js +4 -0
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +5 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -1
- package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +73 -0
- package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +78 -0
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +49 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +15 -1
- package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +56 -0
- package/cjs/sync/submitters/submitterManager.js +3 -0
- package/cjs/sync/submitters/telemetrySubmitter.js +1 -0
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +26 -0
- package/cjs/trackers/impressionsTracker.js +22 -41
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +35 -0
- package/cjs/trackers/uniqueKeysTracker.js +38 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +4 -0
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +26 -5
- package/esm/services/splitApi.js +20 -0
- package/esm/storages/KeyBuilderSS.js +6 -0
- package/esm/storages/inLocalStorage/index.js +5 -1
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +6 -2
- package/esm/storages/inMemory/InMemoryStorageCS.js +6 -2
- package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +70 -0
- package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +75 -0
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +46 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +16 -2
- package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +53 -0
- package/esm/sync/submitters/submitterManager.js +3 -0
- package/esm/sync/submitters/telemetrySubmitter.js +2 -1
- package/esm/sync/submitters/uniqueKeysSubmitter.js +22 -0
- package/esm/trackers/impressionsTracker.js +22 -41
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +31 -0
- package/esm/trackers/uniqueKeysTracker.js +34 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +4 -0
- package/package.json +1 -1
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +29 -5
- package/src/sdkFactory/types.ts +7 -4
- package/src/services/splitApi.ts +22 -0
- package/src/services/types.ts +6 -0
- package/src/storages/AbstractSplitsCacheAsync.ts +0 -1
- package/src/storages/KeyBuilderSS.ts +8 -0
- package/src/storages/inLocalStorage/index.ts +4 -1
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +5 -2
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -2
- package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +82 -0
- package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +88 -0
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +51 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +12 -3
- package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +63 -0
- package/src/storages/types.ts +30 -8
- package/src/sync/submitters/submitterManager.ts +2 -0
- package/src/sync/submitters/telemetrySubmitter.ts +4 -3
- package/src/sync/submitters/types.ts +20 -1
- package/src/sync/submitters/uniqueKeysSubmitter.ts +35 -0
- package/src/trackers/impressionsTracker.ts +27 -48
- package/src/trackers/strategy/strategyDebug.ts +28 -0
- package/src/trackers/strategy/strategyNone.ts +34 -0
- package/src/trackers/strategy/strategyOptimized.ts +42 -0
- package/src/trackers/types.ts +28 -0
- package/src/trackers/uniqueKeysTracker.ts +48 -0
- package/src/types.ts +5 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +5 -0
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkClient/types.d.ts +18 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +4 -0
- package/types/storages/KeyBuilderSS.d.ts +2 -0
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -0
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +15 -0
- package/types/storages/types.d.ts +18 -5
- package/types/sync/offline/LocalhostFromFile.d.ts +2 -0
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -0
- package/types/sync/submitters/eventsSyncTask.d.ts +8 -0
- package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +5 -0
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +13 -0
- package/types/sync/submitters/impressionsSyncTask.d.ts +14 -0
- package/types/sync/submitters/metricsSyncTask.d.ts +12 -0
- package/types/sync/submitters/submitterSyncTask.d.ts +10 -0
- package/types/sync/submitters/types.d.ts +18 -1
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +5 -0
- package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +5 -0
- package/types/sync/syncTaskComposite.d.ts +5 -0
- package/types/trackers/filter/bloomFilter.d.ts +10 -0
- package/types/trackers/filter/dictionaryFilter.d.ts +8 -0
- package/types/trackers/filter/types.d.ts +5 -0
- package/types/trackers/impressionsTracker.d.ts +4 -6
- package/types/trackers/strategy/strategyDebug.d.ts +9 -0
- package/types/trackers/strategy/strategyNone.d.ts +10 -0
- package/types/trackers/strategy/strategyOptimized.d.ts +11 -0
- package/types/trackers/types.d.ts +23 -0
- package/types/trackers/uniqueKeysTracker.d.ts +13 -0
- package/types/types.d.ts +5 -1
- package/types/utils/constants/index.d.ts +2 -0
- package/types/utils/settingsValidation/index.d.ts +1 -0
- package/types/utils/timeTracker/index.d.ts +70 -0
- package/src/logger/.DS_Store +0 -0
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
1.6.2 (September XXX, 2022)
|
|
2
|
+
- Updated storage implementations to improve the performance of split evaluations (i.e., `getTreatment(s)` method calls) when using the default storage in memory.
|
|
3
|
+
|
|
1
4
|
1.6.1 (July 22, 2022)
|
|
2
5
|
- Updated GoogleAnalyticsToSplit integration to validate `autoRequire` config parameter and avoid some wrong warning logs when mapping GA hit fields to Split event properties.
|
|
3
6
|
|
|
@@ -39,8 +39,8 @@ function createUserConsentAPI(params) {
|
|
|
39
39
|
if (events.clear)
|
|
40
40
|
events.clear(); // @ts-ignore
|
|
41
41
|
if (impressions.clear)
|
|
42
|
-
impressions.clear();
|
|
43
|
-
if (impressionCounts)
|
|
42
|
+
impressions.clear(); // @ts-ignore
|
|
43
|
+
if (impressionCounts && impressionCounts.clear)
|
|
44
44
|
impressionCounts.clear();
|
|
45
45
|
}
|
|
46
46
|
}
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -74,9 +74,10 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
74
74
|
// Flush impressions & events data if there is user consent
|
|
75
75
|
if ((0, consent_1.isConsentGranted)(this.settings)) {
|
|
76
76
|
var eventsUrl = this.settings.urls.events;
|
|
77
|
+
var sim = this.settings.sync.impressionsMode;
|
|
77
78
|
var extraMetadata = {
|
|
78
79
|
// sim stands for Sync/Split Impressions Mode
|
|
79
|
-
sim:
|
|
80
|
+
sim: sim === constants_1.OPTIMIZED ? constants_1.OPTIMIZED : sim === constants_1.DEBUG ? constants_1.DEBUG : constants_1.NONE
|
|
80
81
|
};
|
|
81
82
|
this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
82
83
|
this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
package/cjs/logger/constants.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_SEGMENTS = exports.SYNC_SPLITS_REMOVED = exports.SYNC_SPLITS_NEW = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_WHITELIST = exports.ENGINE_MATCHER_STARTS_WITH = exports.ENGINE_MATCHER_STRING_INVALID = exports.ENGINE_MATCHER_STRING = exports.ENGINE_MATCHER_SEGMENT = exports.ENGINE_MATCHER_PART_OF = exports.ENGINE_MATCHER_LESS = exports.ENGINE_MATCHER_GREATER = exports.ENGINE_MATCHER_ENDS_WITH = exports.ENGINE_MATCHER_EQUAL_TO_SET = exports.ENGINE_MATCHER_EQUAL = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_MATCHER_CONTAINS_STRING = exports.ENGINE_MATCHER_CONTAINS_ANY = exports.ENGINE_MATCHER_CONTAINS_ALL = exports.ENGINE_MATCHER_BOOLEAN = exports.ENGINE_MATCHER_BETWEEN = exports.ENGINE_MATCHER_ALL = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
4
|
exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_API_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = void 0;
|
|
5
|
-
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = void 0;
|
|
5
|
+
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
8
8
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -144,4 +144,5 @@ exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC + ':polling-manager: '
|
|
|
144
144
|
exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC + ':submitter: ';
|
|
145
145
|
exports.LOG_PREFIX_IMPRESSIONS_TRACKER = 'impressions-tracker: ';
|
|
146
146
|
exports.LOG_PREFIX_EVENTS_TRACKER = 'events-tracker: ';
|
|
147
|
+
exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = 'unique-keys-tracker: ';
|
|
147
148
|
exports.LOG_PREFIX_CLEANUP = 'cleanup: ';
|
|
@@ -9,7 +9,7 @@ var clientInputValidation_1 = require("./clientInputValidation");
|
|
|
9
9
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
10
10
|
*/
|
|
11
11
|
function sdkClientFactory(params, isSharedClient) {
|
|
12
|
-
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker;
|
|
12
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker, uniqueKeysTracker = params.uniqueKeysTracker;
|
|
13
13
|
return (0, objectAssign_1.objectAssign)(
|
|
14
14
|
// Proto-linkage of the readiness Event Emitter
|
|
15
15
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
@@ -31,6 +31,8 @@ function sdkClientFactory(params, isSharedClient) {
|
|
|
31
31
|
// Release the API Key if it is the main client
|
|
32
32
|
if (!isSharedClient)
|
|
33
33
|
(0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
|
|
34
|
+
if (uniqueKeysTracker)
|
|
35
|
+
uniqueKeysTracker.stop();
|
|
34
36
|
// Cleanup storage
|
|
35
37
|
return storage.destroy();
|
|
36
38
|
});
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -13,11 +13,16 @@ var constants_1 = require("../logger/constants");
|
|
|
13
13
|
var metadataBuilder_1 = require("../storages/metadataBuilder");
|
|
14
14
|
var constants_2 = require("../readiness/constants");
|
|
15
15
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
16
|
+
var strategyDebug_1 = require("../trackers/strategy/strategyDebug");
|
|
17
|
+
var strategyOptimized_1 = require("../trackers/strategy/strategyOptimized");
|
|
18
|
+
var strategyNone_1 = require("../trackers/strategy/strategyNone");
|
|
19
|
+
var uniqueKeysTracker_1 = require("../trackers/uniqueKeysTracker");
|
|
20
|
+
var constants_3 = require("../utils/constants");
|
|
16
21
|
/**
|
|
17
22
|
* Modular SDK factory
|
|
18
23
|
*/
|
|
19
24
|
function sdkFactory(params) {
|
|
20
|
-
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory;
|
|
25
|
+
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory, filterAdapterFactory = params.filterAdapterFactory;
|
|
21
26
|
var log = settings.log;
|
|
22
27
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
23
28
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
@@ -29,12 +34,17 @@ function sdkFactory(params) {
|
|
|
29
34
|
var storageFactoryParams = {
|
|
30
35
|
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
31
36
|
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
37
|
+
uniqueKeysCacheSize: settings.scheduler.uniqueKeysCacheSize,
|
|
38
|
+
impressionCountsQueueSize: settings.scheduler.impressionCountsQueueSize,
|
|
39
|
+
impressionCountsRefreshRate: settings.scheduler.impressionCountsRefreshRate,
|
|
40
|
+
uniqueKeysRefreshRate: settings.scheduler.uniqueKeysRefreshRate,
|
|
32
41
|
optimize: (0, utils_1.shouldBeOptimized)(settings),
|
|
33
42
|
// ATM, only used by InLocalStorage
|
|
34
43
|
matchingKey: (0, key_1.getMatching)(settings.core.key),
|
|
35
44
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
36
45
|
// ATM, only used by PluggableStorage
|
|
37
46
|
mode: settings.mode,
|
|
47
|
+
impressionsMode: settings.sync.impressionsMode,
|
|
38
48
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
39
49
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
40
50
|
onReadyCb: function (error) {
|
|
@@ -50,13 +60,24 @@ function sdkFactory(params) {
|
|
|
50
60
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
51
61
|
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
52
62
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
var
|
|
63
|
+
var observer = impressionsObserverFactory();
|
|
64
|
+
var uniqueKeysTracker = storageFactoryParams.impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
65
|
+
var strategy;
|
|
66
|
+
switch (storageFactoryParams.impressionsMode) {
|
|
67
|
+
case constants_3.OPTIMIZED:
|
|
68
|
+
strategy = (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts);
|
|
69
|
+
break;
|
|
70
|
+
case constants_3.NONE:
|
|
71
|
+
strategy = (0, strategyNone_1.strategyNoneFactory)(storage.impressionCounts, uniqueKeysTracker);
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
strategy = (0, strategyDebug_1.strategyDebugFactory)(observer);
|
|
75
|
+
}
|
|
76
|
+
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
56
77
|
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager, storage.telemetry);
|
|
57
78
|
// splitApi is used by SyncManager and Browser signal listener
|
|
58
79
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
59
|
-
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
80
|
+
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
60
81
|
var syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
61
82
|
ctx.syncManager = syncManager;
|
|
62
83
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -90,6 +90,26 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
90
90
|
var url = urls.events + "/testImpressions/count";
|
|
91
91
|
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS_COUNT));
|
|
92
92
|
},
|
|
93
|
+
/**
|
|
94
|
+
* Post unique keys for client side.
|
|
95
|
+
*
|
|
96
|
+
* @param body unique keys payload
|
|
97
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
98
|
+
*/
|
|
99
|
+
postUniqueKeysBulkCs: function (body, headers) {
|
|
100
|
+
var url = urls.telemetry + "/v1/keys/cs";
|
|
101
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Post unique keys for server side.
|
|
105
|
+
*
|
|
106
|
+
* @param body unique keys payload
|
|
107
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
108
|
+
*/
|
|
109
|
+
postUniqueKeysBulkSs: function (body, headers) {
|
|
110
|
+
var url = urls.telemetry + "/v1/keys/ss";
|
|
111
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
|
|
112
|
+
},
|
|
93
113
|
postMetricsConfig: function (body) {
|
|
94
114
|
var url = urls.telemetry + "/v1/metrics/config";
|
|
95
115
|
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
@@ -23,6 +23,12 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
23
23
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
24
24
|
return this.prefix + ".impressions";
|
|
25
25
|
};
|
|
26
|
+
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
27
|
+
return this.prefix + ".impressions.count";
|
|
28
|
+
};
|
|
29
|
+
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
30
|
+
return this.prefix + ".uniquekeys";
|
|
31
|
+
};
|
|
26
32
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
27
33
|
return this.prefix + ".events";
|
|
28
34
|
};
|
|
@@ -16,6 +16,7 @@ var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
|
|
|
16
16
|
var constants_1 = require("./constants");
|
|
17
17
|
var constants_2 = require("../../utils/constants");
|
|
18
18
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
19
|
+
var uniqueKeysCacheInMemoryCS_1 = require("../inMemory/uniqueKeysCacheInMemoryCS");
|
|
19
20
|
/**
|
|
20
21
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
21
22
|
*/
|
|
@@ -38,12 +39,15 @@ function InLocalStorage(options) {
|
|
|
38
39
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
39
40
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
40
41
|
telemetry: params.mode !== constants_2.LOCALHOST_MODE && (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)() ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
42
|
+
uniqueKeys: params.impressionsMode === constants_2.NONE ? new uniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
41
43
|
destroy: function () {
|
|
44
|
+
var _a;
|
|
42
45
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
43
46
|
this.segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
44
47
|
this.impressions.clear();
|
|
45
48
|
this.impressionCounts && this.impressionCounts.clear();
|
|
46
49
|
this.events.clear();
|
|
50
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
47
51
|
},
|
|
48
52
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
49
53
|
shared: function (matchingKey) {
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImpressionCountsCacheInMemory = void 0;
|
|
4
4
|
var time_1 = require("../../utils/time");
|
|
5
|
+
var constants_1 = require("../inRedis/constants");
|
|
5
6
|
var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
6
|
-
function ImpressionCountsCacheInMemory() {
|
|
7
|
+
function ImpressionCountsCacheInMemory(impressionCountsCacheSize) {
|
|
8
|
+
if (impressionCountsCacheSize === void 0) { impressionCountsCacheSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
7
9
|
this.cache = {};
|
|
10
|
+
this.cacheSize = 0;
|
|
11
|
+
this.maxStorage = impressionCountsCacheSize;
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
@@ -19,6 +23,13 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
19
23
|
var key = this._makeKey(featureName, timeFrame);
|
|
20
24
|
var currentAmount = this.cache[key];
|
|
21
25
|
this.cache[key] = currentAmount ? currentAmount + amount : amount;
|
|
26
|
+
if (this.onFullQueue) {
|
|
27
|
+
this.cacheSize = this.cacheSize + amount;
|
|
28
|
+
if (this.cacheSize >= this.maxStorage) {
|
|
29
|
+
this.onFullQueue();
|
|
30
|
+
this.cacheSize = 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
};
|
|
23
34
|
/**
|
|
24
35
|
* Pop the collected data, used as payload for posting.
|
|
@@ -8,6 +8,7 @@ var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
|
|
|
8
8
|
var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
|
+
var uniqueKeysCacheInMemory_1 = require("./uniqueKeysCacheInMemory");
|
|
11
12
|
/**
|
|
12
13
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
13
14
|
*
|
|
@@ -18,16 +19,19 @@ function InMemoryStorageFactory(params) {
|
|
|
18
19
|
splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
|
|
19
20
|
segments: new SegmentsCacheInMemory_1.SegmentsCacheInMemory(),
|
|
20
21
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
21
|
-
impressionCounts: params.
|
|
22
|
+
impressionCounts: params.impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
22
23
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
23
24
|
telemetry: params.mode !== constants_1.LOCALHOST_MODE ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
25
|
+
uniqueKeys: params.impressionsMode === constants_1.NONE ? new uniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory(params.uniqueKeysCacheSize) : undefined,
|
|
24
26
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
25
27
|
destroy: function () {
|
|
28
|
+
var _a;
|
|
26
29
|
this.splits.clear();
|
|
27
30
|
this.segments.clear();
|
|
28
31
|
this.impressions.clear();
|
|
29
32
|
this.impressionCounts && this.impressionCounts.clear();
|
|
30
33
|
this.events.clear();
|
|
34
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
31
35
|
}
|
|
32
36
|
};
|
|
33
37
|
}
|
|
@@ -8,6 +8,7 @@ var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
|
|
|
8
8
|
var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
|
+
var uniqueKeysCacheInMemoryCS_1 = require("./uniqueKeysCacheInMemoryCS");
|
|
11
12
|
/**
|
|
12
13
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
13
14
|
*
|
|
@@ -18,16 +19,19 @@ function InMemoryStorageCSFactory(params) {
|
|
|
18
19
|
splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
|
|
19
20
|
segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
20
21
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
21
|
-
impressionCounts: params.
|
|
22
|
+
impressionCounts: params.impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
22
23
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
23
24
|
telemetry: params.mode !== constants_1.LOCALHOST_MODE && (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)() ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
25
|
+
uniqueKeys: params.impressionsMode === constants_1.NONE ? new uniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(params.uniqueKeysCacheSize) : undefined,
|
|
24
26
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
25
27
|
destroy: function () {
|
|
28
|
+
var _a;
|
|
26
29
|
this.splits.clear();
|
|
27
30
|
this.segments.clear();
|
|
28
31
|
this.impressions.clear();
|
|
29
32
|
this.impressionCounts && this.impressionCounts.clear();
|
|
30
33
|
this.events.clear();
|
|
34
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
31
35
|
},
|
|
32
36
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
|
|
33
37
|
shared: function () {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueKeysCacheInMemory = void 0;
|
|
4
|
+
var sets_1 = require("../../utils/lang/sets");
|
|
5
|
+
var constants_1 = require("../inRedis/constants");
|
|
6
|
+
var UniqueKeysCacheInMemory = /** @class */ (function () {
|
|
7
|
+
function UniqueKeysCacheInMemory(uniqueKeysQueueSize) {
|
|
8
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
9
|
+
this.uniqueTrackerSize = 0;
|
|
10
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
11
|
+
this.uniqueKeysTracker = {};
|
|
12
|
+
}
|
|
13
|
+
UniqueKeysCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
|
|
14
|
+
this.onFullQueue = cb;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Store unique keys in sequential order
|
|
18
|
+
* key: string = feature name.
|
|
19
|
+
* value: Set<string> = set of unique keys.
|
|
20
|
+
*/
|
|
21
|
+
UniqueKeysCacheInMemory.prototype.track = function (key, featureName) {
|
|
22
|
+
if (!this.uniqueKeysTracker[featureName])
|
|
23
|
+
this.uniqueKeysTracker[featureName] = new sets_1._Set();
|
|
24
|
+
var tracker = this.uniqueKeysTracker[featureName];
|
|
25
|
+
if (!tracker.has(key)) {
|
|
26
|
+
tracker.add(key);
|
|
27
|
+
this.uniqueTrackerSize++;
|
|
28
|
+
}
|
|
29
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
30
|
+
this.uniqueTrackerSize = 0;
|
|
31
|
+
this.onFullQueue();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Clear the data stored on the cache.
|
|
36
|
+
*/
|
|
37
|
+
UniqueKeysCacheInMemory.prototype.clear = function () {
|
|
38
|
+
this.uniqueKeysTracker = {};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Pop the collected data, used as payload for posting.
|
|
42
|
+
*/
|
|
43
|
+
UniqueKeysCacheInMemory.prototype.pop = function () {
|
|
44
|
+
var data = this.uniqueKeysTracker;
|
|
45
|
+
this.uniqueKeysTracker = {};
|
|
46
|
+
return this.fromUniqueKeysCollector(data);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Check if the cache is empty.
|
|
50
|
+
*/
|
|
51
|
+
UniqueKeysCacheInMemory.prototype.isEmpty = function () {
|
|
52
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Converts `uniqueKeys` data from cache into request payload for SS.
|
|
56
|
+
*/
|
|
57
|
+
UniqueKeysCacheInMemory.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
58
|
+
var payload = [];
|
|
59
|
+
var featureNames = Object.keys(uniqueKeys);
|
|
60
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
61
|
+
var featureName = featureNames[i];
|
|
62
|
+
var featureKeys = (0, sets_1.setToArray)(uniqueKeys[featureName]);
|
|
63
|
+
var uniqueKeysPayload = {
|
|
64
|
+
f: featureName,
|
|
65
|
+
ks: featureKeys
|
|
66
|
+
};
|
|
67
|
+
payload.push(uniqueKeysPayload);
|
|
68
|
+
}
|
|
69
|
+
return { keys: payload };
|
|
70
|
+
};
|
|
71
|
+
return UniqueKeysCacheInMemory;
|
|
72
|
+
}());
|
|
73
|
+
exports.UniqueKeysCacheInMemory = UniqueKeysCacheInMemory;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueKeysCacheInMemoryCS = void 0;
|
|
4
|
+
var sets_1 = require("../../utils/lang/sets");
|
|
5
|
+
var constants_1 = require("../inRedis/constants");
|
|
6
|
+
var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
|
|
10
|
+
* Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
|
|
11
|
+
*/
|
|
12
|
+
function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
|
|
13
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
14
|
+
this.uniqueTrackerSize = 0;
|
|
15
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
16
|
+
this.uniqueKeysTracker = {};
|
|
17
|
+
}
|
|
18
|
+
UniqueKeysCacheInMemoryCS.prototype.setOnFullQueueCb = function (cb) {
|
|
19
|
+
this.onFullQueue = cb;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Store unique keys in sequential order
|
|
23
|
+
* key: string = key.
|
|
24
|
+
* value: HashSet<string> = set of split names.
|
|
25
|
+
*/
|
|
26
|
+
UniqueKeysCacheInMemoryCS.prototype.track = function (key, featureName) {
|
|
27
|
+
if (!this.uniqueKeysTracker[key])
|
|
28
|
+
this.uniqueKeysTracker[key] = new sets_1._Set();
|
|
29
|
+
var tracker = this.uniqueKeysTracker[key];
|
|
30
|
+
if (!tracker.has(featureName)) {
|
|
31
|
+
tracker.add(featureName);
|
|
32
|
+
this.uniqueTrackerSize++;
|
|
33
|
+
}
|
|
34
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
35
|
+
this.uniqueTrackerSize = 0;
|
|
36
|
+
this.onFullQueue();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Clear the data stored on the cache.
|
|
41
|
+
*/
|
|
42
|
+
UniqueKeysCacheInMemoryCS.prototype.clear = function () {
|
|
43
|
+
this.uniqueKeysTracker = {};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Pop the collected data, used as payload for posting.
|
|
47
|
+
*/
|
|
48
|
+
UniqueKeysCacheInMemoryCS.prototype.pop = function () {
|
|
49
|
+
var data = this.uniqueKeysTracker;
|
|
50
|
+
this.uniqueKeysTracker = {};
|
|
51
|
+
return this.fromUniqueKeysCollector(data);
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Check if the cache is empty.
|
|
55
|
+
*/
|
|
56
|
+
UniqueKeysCacheInMemoryCS.prototype.isEmpty = function () {
|
|
57
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Converts `uniqueKeys` data from cache into request payload.
|
|
61
|
+
*/
|
|
62
|
+
UniqueKeysCacheInMemoryCS.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
63
|
+
var payload = [];
|
|
64
|
+
var featureKeys = Object.keys(uniqueKeys);
|
|
65
|
+
for (var k = 0; k < featureKeys.length; k++) {
|
|
66
|
+
var featureKey = featureKeys[k];
|
|
67
|
+
var featureNames = (0, sets_1.setToArray)(uniqueKeys[featureKey]);
|
|
68
|
+
var uniqueKeysPayload = {
|
|
69
|
+
k: featureKey,
|
|
70
|
+
fs: featureNames
|
|
71
|
+
};
|
|
72
|
+
payload.push(uniqueKeysPayload);
|
|
73
|
+
}
|
|
74
|
+
return { keys: payload };
|
|
75
|
+
};
|
|
76
|
+
return UniqueKeysCacheInMemoryCS;
|
|
77
|
+
}());
|
|
78
|
+
exports.UniqueKeysCacheInMemoryCS = UniqueKeysCacheInMemoryCS;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImpressionCountsCacheInRedis = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var ImpressionCountsCacheInMemory_1 = require("../inMemory/ImpressionCountsCacheInMemory");
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
8
|
+
(0, tslib_1.__extends)(ImpressionCountsCacheInRedis, _super);
|
|
9
|
+
function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize, refreshRate) {
|
|
10
|
+
if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
|
|
11
|
+
var _this = _super.call(this, impressionCountsCacheSize) || this;
|
|
12
|
+
_this.log = log;
|
|
13
|
+
_this.key = key;
|
|
14
|
+
_this.redis = redis;
|
|
15
|
+
_this.refreshRate = refreshRate;
|
|
16
|
+
_this.onFullQueue = function () { _this.postImpressionCountsInRedis(); };
|
|
17
|
+
return _this;
|
|
18
|
+
}
|
|
19
|
+
ImpressionCountsCacheInRedis.prototype.postImpressionCountsInRedis = function () {
|
|
20
|
+
var _this = this;
|
|
21
|
+
var counts = this.pop();
|
|
22
|
+
if (!counts)
|
|
23
|
+
return false;
|
|
24
|
+
var keys = Object.keys(counts);
|
|
25
|
+
var pipeline = this.redis.pipeline();
|
|
26
|
+
keys.forEach(function (key) {
|
|
27
|
+
pipeline.hincrby(_this.key, key, counts[key]);
|
|
28
|
+
});
|
|
29
|
+
return pipeline.exec()
|
|
30
|
+
.then(function (data) {
|
|
31
|
+
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
32
|
+
if (data.length && data.length === keys.length) {
|
|
33
|
+
return _this.redis.expire(_this.key, constants_1.TTL_REFRESH);
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.catch(function (err) {
|
|
37
|
+
_this.log.error(constants_1.LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
ImpressionCountsCacheInRedis.prototype.start = function () {
|
|
42
|
+
this.intervalId = setInterval(this.postImpressionCountsInRedis.bind(this), this.refreshRate);
|
|
43
|
+
};
|
|
44
|
+
ImpressionCountsCacheInRedis.prototype.stop = function () {
|
|
45
|
+
clearInterval(this.intervalId);
|
|
46
|
+
};
|
|
47
|
+
return ImpressionCountsCacheInRedis;
|
|
48
|
+
}(ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory));
|
|
49
|
+
exports.ImpressionCountsCacheInRedis = ImpressionCountsCacheInRedis;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LOG_PREFIX = void 0;
|
|
3
|
+
exports.TTL_REFRESH = exports.REFRESH_RATE = exports.DEFAULT_CACHE_SIZE = exports.LOG_PREFIX = void 0;
|
|
4
4
|
exports.LOG_PREFIX = 'storage:redis: ';
|
|
5
|
+
exports.DEFAULT_CACHE_SIZE = 30000;
|
|
6
|
+
exports.REFRESH_RATE = 300000; // 300.000 ms = start after 5 mins
|
|
7
|
+
exports.TTL_REFRESH = 3600; // 1hr
|
|
@@ -10,6 +10,8 @@ var ImpressionsCacheInRedis_1 = require("./ImpressionsCacheInRedis");
|
|
|
10
10
|
var EventsCacheInRedis_1 = require("./EventsCacheInRedis");
|
|
11
11
|
var constants_1 = require("../../utils/constants");
|
|
12
12
|
var TelemetryCacheInRedis_1 = require("./TelemetryCacheInRedis");
|
|
13
|
+
var uniqueKeysCacheInRedis_1 = require("./uniqueKeysCacheInRedis");
|
|
14
|
+
var ImpressionCountsCacheInRedis_1 = require("./ImpressionCountsCacheInRedis");
|
|
13
15
|
/**
|
|
14
16
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
15
17
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -18,13 +20,19 @@ function InRedisStorage(options) {
|
|
|
18
20
|
if (options === void 0) { options = {}; }
|
|
19
21
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
20
22
|
function InRedisStorageFactory(_a) {
|
|
21
|
-
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
23
|
+
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb, impressionsMode = _a.impressionsMode, impressionCountsQueueSize = _a.impressionCountsQueueSize, impressionCountsRefreshRate = _a.impressionCountsRefreshRate, uniqueKeysCacheSize = _a.uniqueKeysCacheSize, uniqueKeysRefreshRate = _a.uniqueKeysRefreshRate;
|
|
22
24
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
23
25
|
var redisClient = new RedisAdapter_1.RedisAdapter(log, options.options || {});
|
|
24
26
|
var telemetry = new TelemetryCacheInRedis_1.TelemetryCacheInRedis(log, keys, redisClient);
|
|
27
|
+
var impressionCountsCache = impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient, impressionCountsQueueSize, impressionCountsRefreshRate) : undefined;
|
|
28
|
+
var uniqueKeysCache = impressionsMode === constants_1.NONE ? new uniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient, uniqueKeysCacheSize, uniqueKeysRefreshRate) : undefined;
|
|
25
29
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
26
30
|
redisClient.on('connect', function () {
|
|
27
31
|
onReadyCb();
|
|
32
|
+
if (impressionCountsCache)
|
|
33
|
+
impressionCountsCache.start();
|
|
34
|
+
if (uniqueKeysCache)
|
|
35
|
+
uniqueKeysCache.start();
|
|
28
36
|
// Synchronize config
|
|
29
37
|
telemetry.recordConfig();
|
|
30
38
|
});
|
|
@@ -32,12 +40,18 @@ function InRedisStorage(options) {
|
|
|
32
40
|
splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient),
|
|
33
41
|
segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
|
|
34
42
|
impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
43
|
+
impressionCounts: impressionCountsCache,
|
|
35
44
|
events: new EventsCacheInRedis_1.EventsCacheInRedis(log, keys.buildEventsKey(), redisClient, metadata),
|
|
36
45
|
telemetry: telemetry,
|
|
46
|
+
uniqueKeys: uniqueKeysCache,
|
|
37
47
|
// When using REDIS we should:
|
|
38
48
|
// 1- Disconnect from the storage
|
|
39
49
|
destroy: function () {
|
|
40
50
|
redisClient.disconnect();
|
|
51
|
+
if (impressionCountsCache)
|
|
52
|
+
impressionCountsCache.stop();
|
|
53
|
+
if (uniqueKeysCache)
|
|
54
|
+
uniqueKeysCache.stop();
|
|
41
55
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
42
56
|
}
|
|
43
57
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueKeysCacheInRedis = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var uniqueKeysCacheInMemory_1 = require("../inMemory/uniqueKeysCacheInMemory");
|
|
6
|
+
var sets_1 = require("../../utils/lang/sets");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
var constants_2 = require("./constants");
|
|
9
|
+
var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
|
|
10
|
+
(0, tslib_1.__extends)(UniqueKeysCacheInRedis, _super);
|
|
11
|
+
function UniqueKeysCacheInRedis(log, key, redis, uniqueKeysQueueSize, refreshRate) {
|
|
12
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
13
|
+
if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
|
|
14
|
+
var _this = _super.call(this, uniqueKeysQueueSize) || this;
|
|
15
|
+
_this.log = log;
|
|
16
|
+
_this.key = key;
|
|
17
|
+
_this.redis = redis;
|
|
18
|
+
_this.refreshRate = refreshRate;
|
|
19
|
+
_this.onFullQueue = function () { _this.postUniqueKeysInRedis(); };
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
UniqueKeysCacheInRedis.prototype.postUniqueKeysInRedis = function () {
|
|
23
|
+
var _this = this;
|
|
24
|
+
var pipeline = this.redis.pipeline();
|
|
25
|
+
var featureNames = Object.keys(this.uniqueKeysTracker);
|
|
26
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
27
|
+
var featureName = featureNames[i];
|
|
28
|
+
var featureKeys = (0, sets_1.setToArray)(this.uniqueKeysTracker[featureName]);
|
|
29
|
+
var uniqueKeysPayload = {
|
|
30
|
+
f: featureName,
|
|
31
|
+
ks: featureKeys
|
|
32
|
+
};
|
|
33
|
+
pipeline.rpush(this.key, JSON.stringify(uniqueKeysPayload));
|
|
34
|
+
}
|
|
35
|
+
this.clear();
|
|
36
|
+
return pipeline.exec()
|
|
37
|
+
.then(function (data) {
|
|
38
|
+
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
39
|
+
if (data.length && data.length === featureNames.length) {
|
|
40
|
+
return _this.redis.expire(_this.key, constants_1.TTL_REFRESH);
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
.catch(function (err) {
|
|
44
|
+
_this.log.error(constants_2.LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
|
|
45
|
+
return false;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
UniqueKeysCacheInRedis.prototype.start = function () {
|
|
49
|
+
this.intervalId = setInterval(this.postUniqueKeysInRedis.bind(this), this.refreshRate);
|
|
50
|
+
};
|
|
51
|
+
UniqueKeysCacheInRedis.prototype.stop = function () {
|
|
52
|
+
clearInterval(this.intervalId);
|
|
53
|
+
};
|
|
54
|
+
return UniqueKeysCacheInRedis;
|
|
55
|
+
}(uniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory));
|
|
56
|
+
exports.UniqueKeysCacheInRedis = UniqueKeysCacheInRedis;
|
|
@@ -5,6 +5,7 @@ var eventsSubmitter_1 = require("./eventsSubmitter");
|
|
|
5
5
|
var impressionsSubmitter_1 = require("./impressionsSubmitter");
|
|
6
6
|
var impressionCountsSubmitter_1 = require("./impressionCountsSubmitter");
|
|
7
7
|
var telemetrySubmitter_1 = require("./telemetrySubmitter");
|
|
8
|
+
var uniqueKeysSubmitter_1 = require("./uniqueKeysSubmitter");
|
|
8
9
|
function submitterManagerFactory(params) {
|
|
9
10
|
var submitters = [
|
|
10
11
|
(0, impressionsSubmitter_1.impressionsSubmitterFactory)(params),
|
|
@@ -14,6 +15,8 @@ function submitterManagerFactory(params) {
|
|
|
14
15
|
if (impressionCountsSubmitter)
|
|
15
16
|
submitters.push(impressionCountsSubmitter);
|
|
16
17
|
var telemetrySubmitter = (0, telemetrySubmitter_1.telemetrySubmitterFactory)(params);
|
|
18
|
+
if (params.uniqueKeysTracker)
|
|
19
|
+
submitters.push((0, uniqueKeysSubmitter_1.uniqueKeysSubmitterFactory)(params));
|
|
17
20
|
return {
|
|
18
21
|
// `onlyTelemetry` true if SDK is created with userConsent not GRANTED
|
|
19
22
|
start: function (onlyTelemetry) {
|
|
@@ -50,6 +50,7 @@ var OPERATION_MODE_MAP = (_a = {},
|
|
|
50
50
|
var IMPRESSIONS_MODE_MAP = (_b = {},
|
|
51
51
|
_b[constants_1.OPTIMIZED] = constants_1.OPTIMIZED_ENUM,
|
|
52
52
|
_b[constants_1.DEBUG] = constants_1.DEBUG_ENUM,
|
|
53
|
+
_b[constants_1.NONE] = constants_1.NONE_ENUM,
|
|
53
54
|
_b);
|
|
54
55
|
var USER_CONSENT_MAP = (_c = {},
|
|
55
56
|
_c[constants_1.CONSENT_UNKNOWN] = 1,
|