@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
|
@@ -6,9 +6,9 @@ var constants_2 = require("../constants");
|
|
|
6
6
|
var lang_1 = require("../lang");
|
|
7
7
|
function validImpressionsMode(log, impressionsMode) {
|
|
8
8
|
impressionsMode = (0, lang_1.stringToUpperCase)(impressionsMode);
|
|
9
|
-
if ([constants_2.DEBUG, constants_2.OPTIMIZED].indexOf(impressionsMode) > -1)
|
|
9
|
+
if ([constants_2.DEBUG, constants_2.OPTIMIZED, constants_2.NONE].indexOf(impressionsMode) > -1)
|
|
10
10
|
return impressionsMode;
|
|
11
|
-
log.error(constants_1.ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [constants_2.DEBUG, constants_2.OPTIMIZED], constants_2.OPTIMIZED]);
|
|
11
|
+
log.error(constants_1.ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [constants_2.DEBUG, constants_2.OPTIMIZED, constants_2.NONE], constants_2.OPTIMIZED]);
|
|
12
12
|
return constants_2.OPTIMIZED;
|
|
13
13
|
}
|
|
14
14
|
exports.validImpressionsMode = validImpressionsMode;
|
|
@@ -34,6 +34,8 @@ exports.base = {
|
|
|
34
34
|
telemetryRefreshRate: 3600,
|
|
35
35
|
// publish evaluations each 300 sec (default value for OPTIMIZED impressions mode)
|
|
36
36
|
impressionsRefreshRate: 300,
|
|
37
|
+
// publish unique Keys each 900 sec (15 min)
|
|
38
|
+
uniqueKeysRefreshRate: 900,
|
|
37
39
|
// fetch offline changes each 15 sec
|
|
38
40
|
offlineRefreshRate: 15,
|
|
39
41
|
// publish events every 60 seconds after the first flush
|
|
@@ -112,6 +114,7 @@ function settingsValidation(config, validationParams) {
|
|
|
112
114
|
scheduler.segmentsRefreshRate = fromSecondsToMillis(scheduler.segmentsRefreshRate);
|
|
113
115
|
scheduler.offlineRefreshRate = fromSecondsToMillis(scheduler.offlineRefreshRate);
|
|
114
116
|
scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);
|
|
117
|
+
scheduler.uniqueKeysRefreshRate = fromSecondsToMillis(scheduler.uniqueKeysRefreshRate);
|
|
115
118
|
scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
|
|
116
119
|
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
117
120
|
if ((0, lang_1.get)(config, 'scheduler.impressionsRefreshRate') === undefined && withDefaults.sync.impressionsMode === constants_1.DEBUG)
|
package/esm/listeners/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromImpressionsCollector } from '../sync/submitters/impressionsSubmitter';
|
|
2
2
|
import { fromImpressionCountsCollector } from '../sync/submitters/impressionCountsSubmitter';
|
|
3
|
-
import { OPTIMIZED, DEBUG } from '../utils/constants';
|
|
3
|
+
import { OPTIMIZED, DEBUG, NONE } from '../utils/constants';
|
|
4
4
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
5
5
|
import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants';
|
|
6
6
|
import { isConsentGranted } from '../consent';
|
|
@@ -71,9 +71,10 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
71
71
|
// Flush impressions & events data if there is user consent
|
|
72
72
|
if (isConsentGranted(this.settings)) {
|
|
73
73
|
var eventsUrl = this.settings.urls.events;
|
|
74
|
+
var sim = this.settings.sync.impressionsMode;
|
|
74
75
|
var extraMetadata = {
|
|
75
76
|
// sim stands for Sync/Split Impressions Mode
|
|
76
|
-
sim:
|
|
77
|
+
sim: sim === OPTIMIZED ? OPTIMIZED : sim === DEBUG ? DEBUG : NONE
|
|
77
78
|
};
|
|
78
79
|
this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
79
80
|
this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
package/esm/logger/constants.js
CHANGED
|
@@ -139,4 +139,5 @@ export var LOG_PREFIX_SYNC_POLLING = LOG_PREFIX_SYNC + ':polling-manager: ';
|
|
|
139
139
|
export var LOG_PREFIX_SYNC_SUBMITTERS = LOG_PREFIX_SYNC + ':submitter: ';
|
|
140
140
|
export var LOG_PREFIX_IMPRESSIONS_TRACKER = 'impressions-tracker: ';
|
|
141
141
|
export var LOG_PREFIX_EVENTS_TRACKER = 'events-tracker: ';
|
|
142
|
+
export var LOG_PREFIX_UNIQUE_KEYS_TRACKER = 'unique-keys-tracker: ';
|
|
142
143
|
export var LOG_PREFIX_CLEANUP = 'cleanup: ';
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -10,11 +10,16 @@ import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
|
|
|
10
10
|
import { metadataBuilder } from '../storages/metadataBuilder';
|
|
11
11
|
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
12
12
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
13
|
+
import { strategyDebugFactory } from '../trackers/strategy/strategyDebug';
|
|
14
|
+
import { strategyOptimizedFactory } from '../trackers/strategy/strategyOptimized';
|
|
15
|
+
import { strategyNoneFactory } from '../trackers/strategy/strategyNone';
|
|
16
|
+
import { uniqueKeysTrackerFactory } from '../trackers/uniqueKeysTracker';
|
|
17
|
+
import { NONE } from '../utils/constants';
|
|
13
18
|
/**
|
|
14
19
|
* Modular SDK factory
|
|
15
20
|
*/
|
|
16
21
|
export function sdkFactory(params) {
|
|
17
|
-
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;
|
|
22
|
+
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;
|
|
18
23
|
var log = settings.log;
|
|
19
24
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
20
25
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
@@ -26,12 +31,14 @@ export function sdkFactory(params) {
|
|
|
26
31
|
var storageFactoryParams = {
|
|
27
32
|
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
28
33
|
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
34
|
+
uniqueKeysCacheSize: settings.scheduler.uniqueKeysCacheSize,
|
|
29
35
|
optimize: shouldBeOptimized(settings),
|
|
30
36
|
// ATM, only used by InLocalStorage
|
|
31
37
|
matchingKey: getMatching(settings.core.key),
|
|
32
38
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
33
39
|
// ATM, only used by PluggableStorage
|
|
34
40
|
mode: settings.mode,
|
|
41
|
+
impressionsMode: settings.sync.impressionsMode,
|
|
35
42
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
36
43
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
37
44
|
onReadyCb: function (error) {
|
|
@@ -46,14 +53,16 @@ export function sdkFactory(params) {
|
|
|
46
53
|
var storage = storageFactory(storageFactoryParams);
|
|
47
54
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
48
55
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
|
|
49
|
-
|
|
50
|
-
var
|
|
51
|
-
var
|
|
56
|
+
var observer = impressionsObserverFactory();
|
|
57
|
+
var uniqueKeysTracker = storageFactoryParams.impressionsMode === NONE ? uniqueKeysTrackerFactory(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
58
|
+
var strategy = (storageFactoryParams.optimize) ? strategyOptimizedFactory(observer, storage.impressionCounts) :
|
|
59
|
+
(storageFactoryParams.impressionsMode === NONE) ? strategyNoneFactory(storage.impressionCounts, uniqueKeysTracker) : strategyDebugFactory(observer);
|
|
60
|
+
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
52
61
|
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
53
62
|
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
54
63
|
// splitApi is used by SyncManager and Browser signal listener
|
|
55
64
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
56
|
-
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
65
|
+
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
57
66
|
var syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
58
67
|
ctx.syncManager = syncManager;
|
|
59
68
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
package/esm/services/splitApi.js
CHANGED
|
@@ -87,6 +87,26 @@ export function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
87
87
|
var url = urls.events + "/testImpressions/count";
|
|
88
88
|
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(IMPRESSIONS_COUNT));
|
|
89
89
|
},
|
|
90
|
+
/**
|
|
91
|
+
* Post unique keys for client side.
|
|
92
|
+
*
|
|
93
|
+
* @param body unique keys payload
|
|
94
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
95
|
+
*/
|
|
96
|
+
postUniqueKeysBulkCs: function (body, headers) {
|
|
97
|
+
var url = urls.telemetry + "/v1/keys/cs";
|
|
98
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY));
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Post unique keys for server side.
|
|
102
|
+
*
|
|
103
|
+
* @param body unique keys payload
|
|
104
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
105
|
+
*/
|
|
106
|
+
postUniqueKeysBulkSs: function (body, headers) {
|
|
107
|
+
var url = urls.telemetry + "/v1/keys/ss";
|
|
108
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY));
|
|
109
|
+
},
|
|
90
110
|
postMetricsConfig: function (body) {
|
|
91
111
|
var url = urls.telemetry + "/v1/metrics/config";
|
|
92
112
|
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
@@ -11,8 +11,9 @@ import { SplitsCacheInMemory } from '../inMemory/SplitsCacheInMemory';
|
|
|
11
11
|
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
|
|
12
12
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
13
13
|
import { LOG_PREFIX } from './constants';
|
|
14
|
-
import { LOCALHOST_MODE, STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
14
|
+
import { LOCALHOST_MODE, NONE, STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
15
15
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
16
|
+
import { UniqueKeysCacheInMemoryCS } from '../inMemory/uniqueKeysCacheInMemoryCS';
|
|
16
17
|
/**
|
|
17
18
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
18
19
|
*/
|
|
@@ -35,12 +36,15 @@ export function InLocalStorage(options) {
|
|
|
35
36
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
36
37
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
37
38
|
telemetry: params.mode !== LOCALHOST_MODE && shouldRecordTelemetry() ? new TelemetryCacheInMemory() : undefined,
|
|
39
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined,
|
|
38
40
|
destroy: function () {
|
|
41
|
+
var _a;
|
|
39
42
|
this.splits = new SplitsCacheInMemory();
|
|
40
43
|
this.segments = new MySegmentsCacheInMemory();
|
|
41
44
|
this.impressions.clear();
|
|
42
45
|
this.impressionCounts && this.impressionCounts.clear();
|
|
43
46
|
this.events.clear();
|
|
47
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
44
48
|
},
|
|
45
49
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
46
50
|
shared: function (matchingKey) {
|
|
@@ -3,8 +3,9 @@ import { SegmentsCacheInMemory } from './SegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
6
|
+
import { DEBUG, LOCALHOST_MODE, NONE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
+
import { UniqueKeysCacheInMemory } from './uniqueKeysCacheInMemory';
|
|
8
9
|
/**
|
|
9
10
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
10
11
|
*
|
|
@@ -15,16 +16,19 @@ export function InMemoryStorageFactory(params) {
|
|
|
15
16
|
splits: new SplitsCacheInMemory(),
|
|
16
17
|
segments: new SegmentsCacheInMemory(),
|
|
17
18
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
18
|
-
impressionCounts: params.
|
|
19
|
+
impressionCounts: params.impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
19
20
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
20
21
|
telemetry: params.mode !== LOCALHOST_MODE ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemory(params.uniqueKeysCacheSize) : undefined,
|
|
21
23
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
22
24
|
destroy: function () {
|
|
25
|
+
var _a;
|
|
23
26
|
this.splits.clear();
|
|
24
27
|
this.segments.clear();
|
|
25
28
|
this.impressions.clear();
|
|
26
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
27
30
|
this.events.clear();
|
|
31
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
28
32
|
}
|
|
29
33
|
};
|
|
30
34
|
}
|
|
@@ -3,8 +3,9 @@ import { MySegmentsCacheInMemory } from './MySegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
6
|
+
import { DEBUG, LOCALHOST_MODE, NONE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
+
import { UniqueKeysCacheInMemoryCS } from './uniqueKeysCacheInMemoryCS';
|
|
8
9
|
/**
|
|
9
10
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
10
11
|
*
|
|
@@ -15,16 +16,19 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
15
16
|
splits: new SplitsCacheInMemory(),
|
|
16
17
|
segments: new MySegmentsCacheInMemory(),
|
|
17
18
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
18
|
-
impressionCounts: params.
|
|
19
|
+
impressionCounts: params.impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
19
20
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
20
21
|
telemetry: params.mode !== LOCALHOST_MODE && shouldRecordTelemetry() ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS(params.uniqueKeysCacheSize) : undefined,
|
|
21
23
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
22
24
|
destroy: function () {
|
|
25
|
+
var _a;
|
|
23
26
|
this.splits.clear();
|
|
24
27
|
this.segments.clear();
|
|
25
28
|
this.impressions.clear();
|
|
26
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
27
30
|
this.events.clear();
|
|
31
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
28
32
|
},
|
|
29
33
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
|
|
30
34
|
shared: function () {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { setToArray, _Set } from '../../utils/lang/sets';
|
|
2
|
+
var DEFAULT_CACHE_SIZE = 30000;
|
|
3
|
+
var UniqueKeysCacheInMemory = /** @class */ (function () {
|
|
4
|
+
function UniqueKeysCacheInMemory(uniqueKeysQueueSize) {
|
|
5
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
6
|
+
this.uniqueTrackerSize = 0;
|
|
7
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
8
|
+
this.uniqueKeysTracker = {};
|
|
9
|
+
}
|
|
10
|
+
UniqueKeysCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
|
|
11
|
+
this.onFullQueue = cb;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Store unique keys in sequential order
|
|
15
|
+
* key: string = feature name.
|
|
16
|
+
* value: Set<string> = set of unique keys.
|
|
17
|
+
*/
|
|
18
|
+
UniqueKeysCacheInMemory.prototype.track = function (key, featureName) {
|
|
19
|
+
if (!this.uniqueKeysTracker[featureName])
|
|
20
|
+
this.uniqueKeysTracker[featureName] = new _Set();
|
|
21
|
+
var tracker = this.uniqueKeysTracker[featureName];
|
|
22
|
+
if (!tracker.has(key)) {
|
|
23
|
+
tracker.add(key);
|
|
24
|
+
this.uniqueTrackerSize++;
|
|
25
|
+
}
|
|
26
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
27
|
+
this.uniqueTrackerSize = 0;
|
|
28
|
+
this.onFullQueue();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Clear the data stored on the cache.
|
|
33
|
+
*/
|
|
34
|
+
UniqueKeysCacheInMemory.prototype.clear = function () {
|
|
35
|
+
this.uniqueKeysTracker = {};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Pop the collected data, used as payload for posting.
|
|
39
|
+
*/
|
|
40
|
+
UniqueKeysCacheInMemory.prototype.pop = function () {
|
|
41
|
+
var data = this.uniqueKeysTracker;
|
|
42
|
+
this.uniqueKeysTracker = {};
|
|
43
|
+
return this.fromUniqueKeysCollector(data);
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Check if the cache is empty.
|
|
47
|
+
*/
|
|
48
|
+
UniqueKeysCacheInMemory.prototype.isEmpty = function () {
|
|
49
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Converts `uniqueKeys` data from cache into request payload for SS.
|
|
53
|
+
*/
|
|
54
|
+
UniqueKeysCacheInMemory.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
55
|
+
var payload = [];
|
|
56
|
+
var featureNames = Object.keys(uniqueKeys);
|
|
57
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
58
|
+
var featureName = featureNames[i];
|
|
59
|
+
var featureKeys = setToArray(uniqueKeys[featureName]);
|
|
60
|
+
var uniqueKeysPayload = {
|
|
61
|
+
f: featureName,
|
|
62
|
+
ks: featureKeys
|
|
63
|
+
};
|
|
64
|
+
payload.push(uniqueKeysPayload);
|
|
65
|
+
}
|
|
66
|
+
return { keys: payload };
|
|
67
|
+
};
|
|
68
|
+
return UniqueKeysCacheInMemory;
|
|
69
|
+
}());
|
|
70
|
+
export { UniqueKeysCacheInMemory };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { setToArray, _Set } from '../../utils/lang/sets';
|
|
2
|
+
var DEFAULT_CACHE_SIZE = 30000;
|
|
3
|
+
var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
|
|
7
|
+
* Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
|
|
8
|
+
*/
|
|
9
|
+
function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
|
|
10
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
11
|
+
this.uniqueTrackerSize = 0;
|
|
12
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
13
|
+
this.uniqueKeysTracker = {};
|
|
14
|
+
}
|
|
15
|
+
UniqueKeysCacheInMemoryCS.prototype.setOnFullQueueCb = function (cb) {
|
|
16
|
+
this.onFullQueue = cb;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Store unique keys in sequential order
|
|
20
|
+
* key: string = key.
|
|
21
|
+
* value: HashSet<string> = set of split names.
|
|
22
|
+
*/
|
|
23
|
+
UniqueKeysCacheInMemoryCS.prototype.track = function (key, featureName) {
|
|
24
|
+
if (!this.uniqueKeysTracker[key])
|
|
25
|
+
this.uniqueKeysTracker[key] = new _Set();
|
|
26
|
+
var tracker = this.uniqueKeysTracker[key];
|
|
27
|
+
if (!tracker.has(featureName)) {
|
|
28
|
+
tracker.add(featureName);
|
|
29
|
+
this.uniqueTrackerSize++;
|
|
30
|
+
}
|
|
31
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
32
|
+
this.uniqueTrackerSize = 0;
|
|
33
|
+
this.onFullQueue();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Clear the data stored on the cache.
|
|
38
|
+
*/
|
|
39
|
+
UniqueKeysCacheInMemoryCS.prototype.clear = function () {
|
|
40
|
+
this.uniqueKeysTracker = {};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Pop the collected data, used as payload for posting.
|
|
44
|
+
*/
|
|
45
|
+
UniqueKeysCacheInMemoryCS.prototype.pop = function () {
|
|
46
|
+
var data = this.uniqueKeysTracker;
|
|
47
|
+
this.uniqueKeysTracker = {};
|
|
48
|
+
return this.fromUniqueKeysCollector(data);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Check if the cache is empty.
|
|
52
|
+
*/
|
|
53
|
+
UniqueKeysCacheInMemoryCS.prototype.isEmpty = function () {
|
|
54
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Converts `uniqueKeys` data from cache into request payload.
|
|
58
|
+
*/
|
|
59
|
+
UniqueKeysCacheInMemoryCS.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
60
|
+
var payload = [];
|
|
61
|
+
var featureKeys = Object.keys(uniqueKeys);
|
|
62
|
+
for (var k = 0; k < featureKeys.length; k++) {
|
|
63
|
+
var featureKey = featureKeys[k];
|
|
64
|
+
var featureNames = setToArray(uniqueKeys[featureKey]);
|
|
65
|
+
var uniqueKeysPayload = {
|
|
66
|
+
k: featureKey,
|
|
67
|
+
fs: featureNames
|
|
68
|
+
};
|
|
69
|
+
payload.push(uniqueKeysPayload);
|
|
70
|
+
}
|
|
71
|
+
return { keys: payload };
|
|
72
|
+
};
|
|
73
|
+
return UniqueKeysCacheInMemoryCS;
|
|
74
|
+
}());
|
|
75
|
+
export { UniqueKeysCacheInMemoryCS };
|
|
@@ -2,6 +2,7 @@ import { eventsSubmitterFactory } from './eventsSubmitter';
|
|
|
2
2
|
import { impressionsSubmitterFactory } from './impressionsSubmitter';
|
|
3
3
|
import { impressionCountsSubmitterFactory } from './impressionCountsSubmitter';
|
|
4
4
|
import { telemetrySubmitterFactory } from './telemetrySubmitter';
|
|
5
|
+
import { uniqueKeysSubmitterFactory } from './uniqueKeysSubmitter';
|
|
5
6
|
export function submitterManagerFactory(params) {
|
|
6
7
|
var submitters = [
|
|
7
8
|
impressionsSubmitterFactory(params),
|
|
@@ -11,6 +12,8 @@ export function submitterManagerFactory(params) {
|
|
|
11
12
|
if (impressionCountsSubmitter)
|
|
12
13
|
submitters.push(impressionCountsSubmitter);
|
|
13
14
|
var telemetrySubmitter = telemetrySubmitterFactory(params);
|
|
15
|
+
if (params.uniqueKeysTracker)
|
|
16
|
+
submitters.push(uniqueKeysSubmitterFactory(params));
|
|
14
17
|
return {
|
|
15
18
|
// `onlyTelemetry` true if SDK is created with userConsent not GRANTED
|
|
16
19
|
start: function (onlyTelemetry) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a, _b, _c;
|
|
2
2
|
import { submitterFactory, firstPushWindowDecorator } from './submitter';
|
|
3
|
-
import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG, DEBUG_ENUM, OPTIMIZED_ENUM, CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../../utils/constants';
|
|
3
|
+
import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG, NONE, DEBUG_ENUM, OPTIMIZED_ENUM, NONE_ENUM, CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../../utils/constants';
|
|
4
4
|
import { SDK_READY, SDK_READY_FROM_CACHE } from '../../readiness/constants';
|
|
5
5
|
import { base } from '../../utils/settingsValidation';
|
|
6
6
|
import { usedKeysMap } from '../../utils/inputValidation/apiKey';
|
|
@@ -46,6 +46,7 @@ var OPERATION_MODE_MAP = (_a = {},
|
|
|
46
46
|
var IMPRESSIONS_MODE_MAP = (_b = {},
|
|
47
47
|
_b[OPTIMIZED] = OPTIMIZED_ENUM,
|
|
48
48
|
_b[DEBUG] = DEBUG_ENUM,
|
|
49
|
+
_b[NONE] = NONE_ENUM,
|
|
49
50
|
_b);
|
|
50
51
|
var USER_CONSENT_MAP = (_c = {},
|
|
51
52
|
_c[CONSENT_UNKNOWN] = 1,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
2
|
+
import { submitterFactory } from './submitter';
|
|
3
|
+
var DATA_NAME = 'uniqueKeys';
|
|
4
|
+
/**
|
|
5
|
+
* Submitter that periodically posts impression counts
|
|
6
|
+
*/
|
|
7
|
+
export function uniqueKeysSubmitterFactory(params) {
|
|
8
|
+
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;
|
|
9
|
+
var isClientSide = key !== undefined;
|
|
10
|
+
var postUniqueKeysBulk = isClientSide ? postUniqueKeysBulkCs : postUniqueKeysBulkSs;
|
|
11
|
+
var syncTask = submitterFactory(log, postUniqueKeysBulk, uniqueKeys, uniqueKeysRefreshRate, 'unique keys');
|
|
12
|
+
// register unique keys submitter to be executed when uniqueKeys cache is full
|
|
13
|
+
uniqueKeys.setOnFullQueueCb(function () {
|
|
14
|
+
if (syncTask.isRunning()) {
|
|
15
|
+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
16
|
+
syncTask.execute();
|
|
17
|
+
}
|
|
18
|
+
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
19
|
+
// Data will be sent when submitter is resumed.
|
|
20
|
+
});
|
|
21
|
+
return syncTask;
|
|
22
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
|
-
import { truncateTimeFrame } from '../utils/time';
|
|
4
3
|
import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
|
|
5
4
|
import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
|
|
6
5
|
/**
|
|
@@ -10,37 +9,17 @@ import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
|
|
|
10
9
|
* @param metadata runtime metadata (ip, hostname and version)
|
|
11
10
|
* @param impressionListener optional impression listener
|
|
12
11
|
* @param integrationsManager optional integrations manager
|
|
13
|
-
* @param
|
|
14
|
-
* @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
|
|
12
|
+
* @param strategy strategy for impressions tracking.
|
|
15
13
|
*/
|
|
16
|
-
export function impressionsTrackerFactory(settings, impressionsCache, integrationsManager,
|
|
17
|
-
// if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
|
|
18
|
-
observer,
|
|
19
|
-
// if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
|
|
20
|
-
countsCache, telemetryCache) {
|
|
14
|
+
export function impressionsTrackerFactory(settings, impressionsCache, strategy, integrationsManager, telemetryCache) {
|
|
21
15
|
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
22
16
|
return {
|
|
23
17
|
track: function (impressions, attributes) {
|
|
24
18
|
if (settings.userConsent === CONSENT_DECLINED)
|
|
25
19
|
return;
|
|
26
20
|
var impressionsCount = impressions.length;
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
impressions.forEach(function (impression) {
|
|
30
|
-
if (observer) {
|
|
31
|
-
// Adds previous time if it is enabled
|
|
32
|
-
impression.pt = observer.testAndSet(impression);
|
|
33
|
-
}
|
|
34
|
-
var now = Date.now();
|
|
35
|
-
if (countsCache) {
|
|
36
|
-
// Increments impression counter per featureName
|
|
37
|
-
countsCache.track(impression.feature, now, 1);
|
|
38
|
-
}
|
|
39
|
-
// Checks if the impression should be added in queue to be sent
|
|
40
|
-
if (!countsCache || !impression.pt || impression.pt < truncateTimeFrame(now)) {
|
|
41
|
-
impressionsToStore.push(impression);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
21
|
+
var _a = strategy.process(impressions), impressionsToStore = _a.impressionsToStore, impressionsToListener = _a.impressionsToListener, deduped = _a.deduped;
|
|
22
|
+
var impressionsToListenerCount = impressionsToListener.length;
|
|
44
23
|
var res = impressionsCache.track(impressionsToStore);
|
|
45
24
|
// If we're on an async storage, handle error and log it.
|
|
46
25
|
if (thenable(res)) {
|
|
@@ -55,7 +34,7 @@ countsCache, telemetryCache) {
|
|
|
55
34
|
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
56
35
|
if (telemetryCache) {
|
|
57
36
|
telemetryCache.recordImpressionStats(QUEUED, impressionsToStore.length);
|
|
58
|
-
telemetryCache.recordImpressionStats(DEDUPED,
|
|
37
|
+
telemetryCache.recordImpressionStats(DEDUPED, deduped);
|
|
59
38
|
}
|
|
60
39
|
}
|
|
61
40
|
// @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
|
|
@@ -63,7 +42,7 @@ countsCache, telemetryCache) {
|
|
|
63
42
|
var _loop_1 = function (i) {
|
|
64
43
|
var impressionData = {
|
|
65
44
|
// copy of impression, to avoid unexpected behaviour if modified by integrations or impressionListener
|
|
66
|
-
impression: objectAssign({},
|
|
45
|
+
impression: objectAssign({}, impressionsToListener[i]),
|
|
67
46
|
attributes: attributes,
|
|
68
47
|
ip: ip,
|
|
69
48
|
hostname: hostname,
|
|
@@ -83,7 +62,7 @@ countsCache, telemetryCache) {
|
|
|
83
62
|
}
|
|
84
63
|
}, 0);
|
|
85
64
|
};
|
|
86
|
-
for (var i = 0; i <
|
|
65
|
+
for (var i = 0; i < impressionsToListenerCount; i++) {
|
|
87
66
|
_loop_1(i);
|
|
88
67
|
}
|
|
89
68
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
|
|
3
|
+
*
|
|
4
|
+
* @param impressionsObserver impression observer. Previous time (pt property) is included in impression instances
|
|
5
|
+
* @returns IStrategyResult
|
|
6
|
+
*/
|
|
7
|
+
export function strategyDebugFactory(impressionsObserver) {
|
|
8
|
+
return {
|
|
9
|
+
process: function (impressions) {
|
|
10
|
+
impressions.forEach(function (impression) {
|
|
11
|
+
// Adds previous time if it is enabled
|
|
12
|
+
impression.pt = impressionsObserver.testAndSet(impression);
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
impressionsToStore: impressions,
|
|
16
|
+
impressionsToListener: impressions,
|
|
17
|
+
deduped: 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* None strategy for impressions tracker.
|
|
3
|
+
*
|
|
4
|
+
* @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
|
|
5
|
+
* @param uniqueKeysTracker unique keys tracker in charge of tracking the unique keys per split.
|
|
6
|
+
* @returns IStrategyResult
|
|
7
|
+
*/
|
|
8
|
+
export function strategyNoneFactory(impressionsCounter, uniqueKeysTracker) {
|
|
9
|
+
return {
|
|
10
|
+
process: function (impressions) {
|
|
11
|
+
impressions.forEach(function (impression) {
|
|
12
|
+
var now = Date.now();
|
|
13
|
+
// Increments impression counter per featureName
|
|
14
|
+
impressionsCounter.track(impression.feature, now, 1);
|
|
15
|
+
// Keep track by unique key
|
|
16
|
+
uniqueKeysTracker.track(impression.keyName, impression.feature);
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
impressionsToStore: [],
|
|
20
|
+
impressionsToListener: impressions,
|
|
21
|
+
deduped: 0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { truncateTimeFrame } from '../../utils/time';
|
|
2
|
+
/**
|
|
3
|
+
* Optimized strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
|
|
4
|
+
*
|
|
5
|
+
* @param impressionsObserver impression observer. previous time (pt property) is included in impression instances
|
|
6
|
+
* @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
|
|
7
|
+
* @returns IStrategyResult
|
|
8
|
+
*/
|
|
9
|
+
export function strategyOptimizedFactory(impressionsObserver, impressionsCounter) {
|
|
10
|
+
return {
|
|
11
|
+
process: function (impressions) {
|
|
12
|
+
var impressionsToStore = [];
|
|
13
|
+
impressions.forEach(function (impression) {
|
|
14
|
+
impression.pt = impressionsObserver.testAndSet(impression);
|
|
15
|
+
var now = Date.now();
|
|
16
|
+
// Increments impression counter per featureName
|
|
17
|
+
impressionsCounter.track(impression.feature, now, 1);
|
|
18
|
+
// Checks if the impression should be added in queue to be sent
|
|
19
|
+
if (!impression.pt || impression.pt < truncateTimeFrame(now)) {
|
|
20
|
+
impressionsToStore.push(impression);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
impressionsToStore: impressionsToStore,
|
|
25
|
+
impressionsToListener: impressions,
|
|
26
|
+
deduped: impressions.length - impressionsToStore.length
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LOG_PREFIX_UNIQUE_KEYS_TRACKER } from '../logger/constants';
|
|
2
|
+
var noopFilterAdapter = {
|
|
3
|
+
add: function () { return true; },
|
|
4
|
+
contains: function () { return true; },
|
|
5
|
+
clear: function () { }
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Trackes uniques keys
|
|
9
|
+
* Unique Keys Tracker will be in charge of checking if the MTK was already sent to the BE in the last period
|
|
10
|
+
* or schedule to be sent; if not it will be added in an internal cache and sent in the next post.
|
|
11
|
+
*
|
|
12
|
+
* @param log Logger instance
|
|
13
|
+
* @param filterAdapter filter adapter
|
|
14
|
+
* @param uniqueKeysCache cache to save unique keys
|
|
15
|
+
*/
|
|
16
|
+
export function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
17
|
+
if (filterAdapter === void 0) { filterAdapter = noopFilterAdapter; }
|
|
18
|
+
return {
|
|
19
|
+
track: function (key, featureName) {
|
|
20
|
+
if (!filterAdapter.add(key, featureName)) {
|
|
21
|
+
log.debug(LOG_PREFIX_UNIQUE_KEYS_TRACKER + "The feature " + featureName + " and key " + key + " exist in the filter");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
uniqueKeysCache.track(key, featureName);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -13,6 +13,7 @@ export var SPLIT_EVENT = 'EVENT';
|
|
|
13
13
|
// Impression collection modes
|
|
14
14
|
export var DEBUG = 'DEBUG';
|
|
15
15
|
export var OPTIMIZED = 'OPTIMIZED';
|
|
16
|
+
export var NONE = 'NONE';
|
|
16
17
|
// SDK Modes
|
|
17
18
|
export var LOCALHOST_MODE = 'localhost';
|
|
18
19
|
export var STANDALONE_MODE = 'standalone';
|
|
@@ -37,6 +38,7 @@ export var CONSUMER_ENUM = 1;
|
|
|
37
38
|
export var CONSUMER_PARTIAL_ENUM = 2;
|
|
38
39
|
export var OPTIMIZED_ENUM = 0;
|
|
39
40
|
export var DEBUG_ENUM = 1;
|
|
41
|
+
export var NONE_ENUM = 2;
|
|
40
42
|
export var SPLITS = 'sp';
|
|
41
43
|
export var IMPRESSIONS = 'im';
|
|
42
44
|
export var IMPRESSIONS_COUNT = 'ic';
|