@splitsoftware/splitio-commons 1.6.1 → 1.6.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/listeners/browser.js +2 -1
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkFactory/index.js +14 -5
- package/cjs/services/splitApi.js +20 -0
- package/cjs/storages/inLocalStorage/index.js +4 -0
- 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/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 +7 -28
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +34 -0
- package/cjs/trackers/uniqueKeysTracker.js +31 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +3 -0
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/sdkFactory/index.js +14 -5
- package/esm/services/splitApi.js +20 -0
- package/esm/storages/inLocalStorage/index.js +5 -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/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 +7 -28
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +30 -0
- package/esm/trackers/uniqueKeysTracker.js +27 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +3 -0
- package/package.json +1 -1
- package/src/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/sdkFactory/index.ts +16 -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/inLocalStorage/index.ts +4 -1
- package/src/storages/inMemory/InMemoryStorage.ts +5 -2
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -2
- package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +83 -0
- package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +89 -0
- package/src/storages/types.ts +22 -6
- 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 +12 -35
- 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 +26 -0
- package/src/trackers/uniqueKeysTracker.ts +37 -0
- package/src/types.ts +3 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +4 -0
- package/types/logger/browser/{debugLogger.d.ts → DebugLogger.d.ts} +0 -0
- package/types/logger/browser/{errorLogger.d.ts → ErrorLogger.d.ts} +0 -0
- package/types/logger/browser/{infoLogger.d.ts → InfoLogger.d.ts} +0 -0
- package/types/logger/browser/{warnLogger.d.ts → WarnLogger.d.ts} +0 -0
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +4 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +32 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
- package/types/storages/types.d.ts +14 -4
- package/types/sync/submitters/types.d.ts +18 -1
- package/types/sync/submitters/uniqueKeysSubmitter.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 +21 -0
- package/types/trackers/uniqueKeysTracker.d.ts +13 -0
- package/types/types.d.ts +3 -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 -1
- package/src/logger/.DS_Store +0 -0
- package/types/integrations/ga/GaToSplitPlugin.d.ts +0 -3
- package/types/integrations/ga/SplitToGaPlugin.d.ts +0 -4
- package/types/integrations/ga/autoRequire.d.ts +0 -4
- package/types/logger/codes.d.ts +0 -2
- package/types/logger/codesConstants.d.ts +0 -117
- package/types/logger/codesConstantsBrowser.d.ts +0 -2
- package/types/logger/codesConstantsNode.d.ts +0 -14
- package/types/logger/codesDebug.d.ts +0 -1
- package/types/logger/codesDebugBrowser.d.ts +0 -1
- package/types/logger/codesDebugNode.d.ts +0 -1
- package/types/logger/codesError.d.ts +0 -1
- package/types/logger/codesErrorNode.d.ts +0 -1
- package/types/logger/codesInfo.d.ts +0 -1
- package/types/logger/codesWarn.d.ts +0 -1
- package/types/logger/codesWarnNode.d.ts +0 -1
- package/types/logger/debugLogger.d.ts +0 -2
- package/types/logger/errorLogger.d.ts +0 -2
- package/types/logger/infoLogger.d.ts +0 -2
- package/types/logger/messages/debugBrowser.d.ts +0 -1
- package/types/logger/messages/debugNode.d.ts +0 -1
- package/types/logger/messages/errorNode.d.ts +0 -1
- package/types/logger/messages/warnNode.d.ts +0 -1
- package/types/logger/noopLogger.d.ts +0 -2
- package/types/logger/warnLogger.d.ts +0 -2
- package/types/sdkFactory/userConsentProps.d.ts +0 -6
- package/types/sdkManager/sdkManagerMethod.d.ts +0 -6
- package/types/storages/getRegisteredSegments.d.ts +0 -10
- package/types/storages/inMemory/index.d.ts +0 -10
- package/types/storages/parseSegments.d.ts +0 -6
- package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +0 -35
- package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +0 -35
- package/types/sync/streaming/AuthClient/indexV1.d.ts +0 -12
- package/types/sync/streaming/AuthClient/indexV2.d.ts +0 -8
- package/types/sync/streaming/pushManagerCS.d.ts +0 -1
- package/types/sync/streaming/pushManagerNoUsers.d.ts +0 -13
- package/types/sync/streaming/pushManagerSS.d.ts +0 -1
- package/types/sync/submitters/telemetrySyncTask.d.ts +0 -0
- package/types/sync/syncManagerFromFile.d.ts +0 -2
- package/types/sync/syncManagerFromObject.d.ts +0 -2
- package/types/sync/syncManagerOffline.d.ts +0 -9
- package/types/trackers/telemetryRecorder.d.ts +0 -0
- package/types/utils/EventEmitter.d.ts +0 -4
- package/types/utils/consent.d.ts +0 -2
- package/types/utils/lang/errors.d.ts +0 -10
- package/types/utils/murmur3/commons.d.ts +0 -12
- package/types/utils/settingsValidation/buildMetadata.d.ts +0 -3
- package/types/utils/settingsValidation/localhost/index.d.ts +0 -9
- package/types/utils/settingsValidation/logger.d.ts +0 -11
- package/types/utils/settingsValidation/runtime/browser.d.ts +0 -2
- package/types/utils/settingsValidation/runtime/node.d.ts +0 -2
- package/types/utils/settingsValidation/userConsent.d.ts +0 -5
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: ';
|
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,14 @@ function sdkFactory(params) {
|
|
|
29
34
|
var storageFactoryParams = {
|
|
30
35
|
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
31
36
|
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
37
|
+
uniqueKeysCacheSize: settings.scheduler.uniqueKeysCacheSize,
|
|
32
38
|
optimize: (0, utils_1.shouldBeOptimized)(settings),
|
|
33
39
|
// ATM, only used by InLocalStorage
|
|
34
40
|
matchingKey: (0, key_1.getMatching)(settings.core.key),
|
|
35
41
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
36
42
|
// ATM, only used by PluggableStorage
|
|
37
43
|
mode: settings.mode,
|
|
44
|
+
impressionsMode: settings.sync.impressionsMode,
|
|
38
45
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
39
46
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
40
47
|
onReadyCb: function (error) {
|
|
@@ -49,14 +56,16 @@ function sdkFactory(params) {
|
|
|
49
56
|
var storage = storageFactory(storageFactoryParams);
|
|
50
57
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
51
58
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
var
|
|
59
|
+
var observer = impressionsObserverFactory();
|
|
60
|
+
var uniqueKeysTracker = storageFactoryParams.impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
61
|
+
var strategy = (storageFactoryParams.optimize) ? (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts) :
|
|
62
|
+
(storageFactoryParams.impressionsMode === constants_3.NONE) ? (0, strategyNone_1.strategyNoneFactory)(storage.impressionCounts, uniqueKeysTracker) : (0, strategyDebug_1.strategyDebugFactory)(observer);
|
|
63
|
+
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
55
64
|
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager, storage.telemetry);
|
|
56
65
|
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
57
66
|
// splitApi is used by SyncManager and Browser signal listener
|
|
58
67
|
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 };
|
|
68
|
+
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
60
69
|
var syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
61
70
|
ctx.syncManager = syncManager;
|
|
62
71
|
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);
|
|
@@ -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) {
|
|
@@ -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 DEFAULT_CACHE_SIZE = 30000;
|
|
6
|
+
var UniqueKeysCacheInMemory = /** @class */ (function () {
|
|
7
|
+
function UniqueKeysCacheInMemory(uniqueKeysQueueSize) {
|
|
8
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = 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 DEFAULT_CACHE_SIZE = 30000;
|
|
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 = 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;
|
|
@@ -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,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uniqueKeysSubmitterFactory = void 0;
|
|
4
|
+
var constants_1 = require("../../logger/constants");
|
|
5
|
+
var submitter_1 = require("./submitter");
|
|
6
|
+
var DATA_NAME = 'uniqueKeys';
|
|
7
|
+
/**
|
|
8
|
+
* Submitter that periodically posts impression counts
|
|
9
|
+
*/
|
|
10
|
+
function uniqueKeysSubmitterFactory(params) {
|
|
11
|
+
var _a = params.settings, log = _a.log, uniqueKeysRefreshRate = _a.scheduler.uniqueKeysRefreshRate, key = _a.core.key, _b = params.splitApi, postUniqueKeysBulkCs = _b.postUniqueKeysBulkCs, postUniqueKeysBulkSs = _b.postUniqueKeysBulkSs, uniqueKeys = params.storage.uniqueKeys;
|
|
12
|
+
var isClientSide = key !== undefined;
|
|
13
|
+
var postUniqueKeysBulk = isClientSide ? postUniqueKeysBulkCs : postUniqueKeysBulkSs;
|
|
14
|
+
var syncTask = (0, submitter_1.submitterFactory)(log, postUniqueKeysBulk, uniqueKeys, uniqueKeysRefreshRate, 'unique keys');
|
|
15
|
+
// register unique keys submitter to be executed when uniqueKeys cache is full
|
|
16
|
+
uniqueKeys.setOnFullQueueCb(function () {
|
|
17
|
+
if (syncTask.isRunning()) {
|
|
18
|
+
log.info(constants_1.SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
19
|
+
syncTask.execute();
|
|
20
|
+
}
|
|
21
|
+
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
22
|
+
// Data will be sent when submitter is resumed.
|
|
23
|
+
});
|
|
24
|
+
return syncTask;
|
|
25
|
+
}
|
|
26
|
+
exports.uniqueKeysSubmitterFactory = uniqueKeysSubmitterFactory;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.impressionsTrackerFactory = void 0;
|
|
4
4
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
5
5
|
var thenable_1 = require("../utils/promise/thenable");
|
|
6
|
-
var time_1 = require("../utils/time");
|
|
7
6
|
var constants_1 = require("../logger/constants");
|
|
8
7
|
var constants_2 = require("../utils/constants");
|
|
9
8
|
/**
|
|
@@ -13,37 +12,17 @@ var constants_2 = require("../utils/constants");
|
|
|
13
12
|
* @param metadata runtime metadata (ip, hostname and version)
|
|
14
13
|
* @param impressionListener optional impression listener
|
|
15
14
|
* @param integrationsManager optional integrations manager
|
|
16
|
-
* @param
|
|
17
|
-
* @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
|
|
15
|
+
* @param strategy strategy for impressions tracking.
|
|
18
16
|
*/
|
|
19
|
-
function impressionsTrackerFactory(settings, impressionsCache, integrationsManager,
|
|
20
|
-
// if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
|
|
21
|
-
observer,
|
|
22
|
-
// if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
|
|
23
|
-
countsCache, telemetryCache) {
|
|
17
|
+
function impressionsTrackerFactory(settings, impressionsCache, strategy, integrationsManager, telemetryCache) {
|
|
24
18
|
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
25
19
|
return {
|
|
26
20
|
track: function (impressions, attributes) {
|
|
27
21
|
if (settings.userConsent === constants_2.CONSENT_DECLINED)
|
|
28
22
|
return;
|
|
29
23
|
var impressionsCount = impressions.length;
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
impressions.forEach(function (impression) {
|
|
33
|
-
if (observer) {
|
|
34
|
-
// Adds previous time if it is enabled
|
|
35
|
-
impression.pt = observer.testAndSet(impression);
|
|
36
|
-
}
|
|
37
|
-
var now = Date.now();
|
|
38
|
-
if (countsCache) {
|
|
39
|
-
// Increments impression counter per featureName
|
|
40
|
-
countsCache.track(impression.feature, now, 1);
|
|
41
|
-
}
|
|
42
|
-
// Checks if the impression should be added in queue to be sent
|
|
43
|
-
if (!countsCache || !impression.pt || impression.pt < (0, time_1.truncateTimeFrame)(now)) {
|
|
44
|
-
impressionsToStore.push(impression);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
24
|
+
var _a = strategy.process(impressions), impressionsToStore = _a.impressionsToStore, impressionsToListener = _a.impressionsToListener, deduped = _a.deduped;
|
|
25
|
+
var impressionsToListenerCount = impressionsToListener.length;
|
|
47
26
|
var res = impressionsCache.track(impressionsToStore);
|
|
48
27
|
// If we're on an async storage, handle error and log it.
|
|
49
28
|
if ((0, thenable_1.thenable)(res)) {
|
|
@@ -58,7 +37,7 @@ countsCache, telemetryCache) {
|
|
|
58
37
|
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
59
38
|
if (telemetryCache) {
|
|
60
39
|
telemetryCache.recordImpressionStats(constants_2.QUEUED, impressionsToStore.length);
|
|
61
|
-
telemetryCache.recordImpressionStats(constants_2.DEDUPED,
|
|
40
|
+
telemetryCache.recordImpressionStats(constants_2.DEDUPED, deduped);
|
|
62
41
|
}
|
|
63
42
|
}
|
|
64
43
|
// @TODO next block might be handled by the integration manager. In that case, the metadata object doesn't need to be passed in the constructor
|
|
@@ -66,7 +45,7 @@ countsCache, telemetryCache) {
|
|
|
66
45
|
var _loop_1 = function (i) {
|
|
67
46
|
var impressionData = {
|
|
68
47
|
// copy of impression, to avoid unexpected behaviour if modified by integrations or impressionListener
|
|
69
|
-
impression: (0, objectAssign_1.objectAssign)({},
|
|
48
|
+
impression: (0, objectAssign_1.objectAssign)({}, impressionsToListener[i]),
|
|
70
49
|
attributes: attributes,
|
|
71
50
|
ip: ip,
|
|
72
51
|
hostname: hostname,
|
|
@@ -86,7 +65,7 @@ countsCache, telemetryCache) {
|
|
|
86
65
|
}
|
|
87
66
|
}, 0);
|
|
88
67
|
};
|
|
89
|
-
for (var i = 0; i <
|
|
68
|
+
for (var i = 0; i < impressionsToListenerCount; i++) {
|
|
90
69
|
_loop_1(i);
|
|
91
70
|
}
|
|
92
71
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strategyDebugFactory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Debug strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
|
|
6
|
+
*
|
|
7
|
+
* @param impressionsObserver impression observer. Previous time (pt property) is included in impression instances
|
|
8
|
+
* @returns IStrategyResult
|
|
9
|
+
*/
|
|
10
|
+
function strategyDebugFactory(impressionsObserver) {
|
|
11
|
+
return {
|
|
12
|
+
process: function (impressions) {
|
|
13
|
+
impressions.forEach(function (impression) {
|
|
14
|
+
// Adds previous time if it is enabled
|
|
15
|
+
impression.pt = impressionsObserver.testAndSet(impression);
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
impressionsToStore: impressions,
|
|
19
|
+
impressionsToListener: impressions,
|
|
20
|
+
deduped: 0
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.strategyDebugFactory = strategyDebugFactory;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strategyNoneFactory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* None strategy for impressions tracker.
|
|
6
|
+
*
|
|
7
|
+
* @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
|
|
8
|
+
* @param uniqueKeysTracker unique keys tracker in charge of tracking the unique keys per split.
|
|
9
|
+
* @returns IStrategyResult
|
|
10
|
+
*/
|
|
11
|
+
function strategyNoneFactory(impressionsCounter, uniqueKeysTracker) {
|
|
12
|
+
return {
|
|
13
|
+
process: function (impressions) {
|
|
14
|
+
impressions.forEach(function (impression) {
|
|
15
|
+
var now = Date.now();
|
|
16
|
+
// Increments impression counter per featureName
|
|
17
|
+
impressionsCounter.track(impression.feature, now, 1);
|
|
18
|
+
// Keep track by unique key
|
|
19
|
+
uniqueKeysTracker.track(impression.keyName, impression.feature);
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
impressionsToStore: [],
|
|
23
|
+
impressionsToListener: impressions,
|
|
24
|
+
deduped: 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.strategyNoneFactory = strategyNoneFactory;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strategyOptimizedFactory = void 0;
|
|
4
|
+
var time_1 = require("../../utils/time");
|
|
5
|
+
/**
|
|
6
|
+
* Optimized strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
|
|
7
|
+
*
|
|
8
|
+
* @param impressionsObserver impression observer. previous time (pt property) is included in impression instances
|
|
9
|
+
* @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
|
|
10
|
+
* @returns IStrategyResult
|
|
11
|
+
*/
|
|
12
|
+
function strategyOptimizedFactory(impressionsObserver, impressionsCounter) {
|
|
13
|
+
return {
|
|
14
|
+
process: function (impressions) {
|
|
15
|
+
var impressionsToStore = [];
|
|
16
|
+
impressions.forEach(function (impression) {
|
|
17
|
+
impression.pt = impressionsObserver.testAndSet(impression);
|
|
18
|
+
var now = Date.now();
|
|
19
|
+
// Increments impression counter per featureName
|
|
20
|
+
impressionsCounter.track(impression.feature, now, 1);
|
|
21
|
+
// Checks if the impression should be added in queue to be sent
|
|
22
|
+
if (!impression.pt || impression.pt < (0, time_1.truncateTimeFrame)(now)) {
|
|
23
|
+
impressionsToStore.push(impression);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
impressionsToStore: impressionsToStore,
|
|
28
|
+
impressionsToListener: impressions,
|
|
29
|
+
deduped: impressions.length - impressionsToStore.length
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.strategyOptimizedFactory = strategyOptimizedFactory;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uniqueKeysTrackerFactory = void 0;
|
|
4
|
+
var constants_1 = require("../logger/constants");
|
|
5
|
+
var noopFilterAdapter = {
|
|
6
|
+
add: function () { return true; },
|
|
7
|
+
contains: function () { return true; },
|
|
8
|
+
clear: function () { }
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Trackes uniques keys
|
|
12
|
+
* Unique Keys Tracker will be in charge of checking if the MTK was already sent to the BE in the last period
|
|
13
|
+
* or schedule to be sent; if not it will be added in an internal cache and sent in the next post.
|
|
14
|
+
*
|
|
15
|
+
* @param log Logger instance
|
|
16
|
+
* @param filterAdapter filter adapter
|
|
17
|
+
* @param uniqueKeysCache cache to save unique keys
|
|
18
|
+
*/
|
|
19
|
+
function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
20
|
+
if (filterAdapter === void 0) { filterAdapter = noopFilterAdapter; }
|
|
21
|
+
return {
|
|
22
|
+
track: function (key, featureName) {
|
|
23
|
+
if (!filterAdapter.add(key, featureName)) {
|
|
24
|
+
log.debug(constants_1.LOG_PREFIX_UNIQUE_KEYS_TRACKER + "The feature " + featureName + " and key " + key + " exist in the filter");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
uniqueKeysCache.track(key, featureName);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.uniqueKeysTrackerFactory = uniqueKeysTrackerFactory;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.PAUSED = exports.ENABLED = exports.DISABLED = exports.NON_REQUESTED = exports.REQUESTED = exports.POLLING = exports.STREAMING = void 0;
|
|
3
|
+
exports.ABLY_ERROR = exports.TOKEN_REFRESH = exports.SSE_CONNECTION_ERROR = exports.STREAMING_STATUS = exports.OCCUPANCY_SEC = exports.OCCUPANCY_PRI = exports.CONNECTION_ESTABLISHED = exports.TRACK = exports.TREATMENTS_WITH_CONFIG = exports.TREATMENT_WITH_CONFIG = exports.TREATMENTS = exports.TREATMENT = exports.MY_SEGMENT = exports.SEGMENT = exports.TOKEN = exports.TELEMETRY = exports.EVENTS = exports.IMPRESSIONS_COUNT = exports.IMPRESSIONS = exports.SPLITS = exports.NONE_ENUM = exports.DEBUG_ENUM = exports.OPTIMIZED_ENUM = exports.CONSUMER_PARTIAL_ENUM = exports.CONSUMER_ENUM = exports.STANDALONE_ENUM = exports.DEDUPED = exports.DROPPED = exports.QUEUED = exports.CONSENT_UNKNOWN = exports.CONSENT_DECLINED = exports.CONSENT_GRANTED = exports.STORAGE_PLUGGABLE = exports.STORAGE_REDIS = exports.STORAGE_LOCALSTORAGE = exports.STORAGE_MEMORY = exports.CONSUMER_PARTIAL_MODE = exports.CONSUMER_MODE = exports.PRODUCER_MODE = exports.STANDALONE_MODE = exports.LOCALHOST_MODE = exports.NONE = exports.OPTIMIZED = exports.DEBUG = exports.SPLIT_EVENT = exports.SPLIT_IMPRESSION = exports.NA = exports.UNKNOWN = exports.CONTROL_WITH_CONFIG = exports.CONTROL = void 0;
|
|
4
|
+
exports.PAUSED = exports.ENABLED = exports.DISABLED = exports.NON_REQUESTED = exports.REQUESTED = exports.POLLING = exports.STREAMING = exports.AUTH_REJECTION = exports.SYNC_MODE_UPDATE = void 0;
|
|
5
5
|
// Special treatments
|
|
6
6
|
exports.CONTROL = 'control';
|
|
7
7
|
exports.CONTROL_WITH_CONFIG = {
|
|
@@ -17,6 +17,7 @@ exports.SPLIT_EVENT = 'EVENT';
|
|
|
17
17
|
// Impression collection modes
|
|
18
18
|
exports.DEBUG = 'DEBUG';
|
|
19
19
|
exports.OPTIMIZED = 'OPTIMIZED';
|
|
20
|
+
exports.NONE = 'NONE';
|
|
20
21
|
// SDK Modes
|
|
21
22
|
exports.LOCALHOST_MODE = 'localhost';
|
|
22
23
|
exports.STANDALONE_MODE = 'standalone';
|
|
@@ -41,6 +42,7 @@ exports.CONSUMER_ENUM = 1;
|
|
|
41
42
|
exports.CONSUMER_PARTIAL_ENUM = 2;
|
|
42
43
|
exports.OPTIMIZED_ENUM = 0;
|
|
43
44
|
exports.DEBUG_ENUM = 1;
|
|
45
|
+
exports.NONE_ENUM = 2;
|
|
44
46
|
exports.SPLITS = 'sp';
|
|
45
47
|
exports.IMPRESSIONS = 'im';
|
|
46
48
|
exports.IMPRESSIONS_COUNT = 'ic';
|