@splitsoftware/splitio-commons 1.6.2-rc.6 → 1.6.2-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +3 -0
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/listeners/browser.js +2 -1
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +26 -5
- package/cjs/services/splitApi.js +20 -0
- package/cjs/storages/KeyBuilderSS.js +6 -0
- package/cjs/storages/inLocalStorage/index.js +4 -0
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +5 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -1
- package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +73 -0
- package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +78 -0
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +49 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +15 -1
- package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +56 -0
- package/cjs/sync/submitters/submitterManager.js +3 -0
- package/cjs/sync/submitters/telemetrySubmitter.js +1 -0
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +26 -0
- package/cjs/trackers/impressionsTracker.js +22 -41
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +35 -0
- package/cjs/trackers/uniqueKeysTracker.js +38 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +4 -0
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +26 -5
- package/esm/services/splitApi.js +20 -0
- package/esm/storages/KeyBuilderSS.js +6 -0
- package/esm/storages/inLocalStorage/index.js +5 -1
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +6 -2
- package/esm/storages/inMemory/InMemoryStorageCS.js +6 -2
- package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +70 -0
- package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +75 -0
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +46 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +16 -2
- package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +53 -0
- package/esm/sync/submitters/submitterManager.js +3 -0
- package/esm/sync/submitters/telemetrySubmitter.js +2 -1
- package/esm/sync/submitters/uniqueKeysSubmitter.js +22 -0
- package/esm/trackers/impressionsTracker.js +22 -41
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +31 -0
- package/esm/trackers/uniqueKeysTracker.js +34 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +4 -0
- package/package.json +1 -1
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +29 -5
- package/src/sdkFactory/types.ts +7 -4
- package/src/services/splitApi.ts +22 -0
- package/src/services/types.ts +6 -0
- package/src/storages/AbstractSplitsCacheAsync.ts +0 -1
- package/src/storages/KeyBuilderSS.ts +8 -0
- package/src/storages/inLocalStorage/index.ts +4 -1
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +5 -2
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -2
- package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +82 -0
- package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +88 -0
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +51 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +12 -3
- package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +63 -0
- package/src/storages/types.ts +30 -8
- package/src/sync/submitters/submitterManager.ts +2 -0
- package/src/sync/submitters/telemetrySubmitter.ts +4 -3
- package/src/sync/submitters/types.ts +20 -1
- package/src/sync/submitters/uniqueKeysSubmitter.ts +35 -0
- package/src/trackers/impressionsTracker.ts +27 -48
- package/src/trackers/strategy/strategyDebug.ts +28 -0
- package/src/trackers/strategy/strategyNone.ts +34 -0
- package/src/trackers/strategy/strategyOptimized.ts +42 -0
- package/src/trackers/types.ts +28 -0
- package/src/trackers/uniqueKeysTracker.ts +48 -0
- package/src/types.ts +5 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +5 -0
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkClient/types.d.ts +18 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +4 -0
- package/types/storages/KeyBuilderSS.d.ts +2 -0
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -0
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +15 -0
- package/types/storages/types.d.ts +18 -5
- package/types/sync/offline/LocalhostFromFile.d.ts +2 -0
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -0
- package/types/sync/submitters/eventsSyncTask.d.ts +8 -0
- package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +5 -0
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +13 -0
- package/types/sync/submitters/impressionsSyncTask.d.ts +14 -0
- package/types/sync/submitters/metricsSyncTask.d.ts +12 -0
- package/types/sync/submitters/submitterSyncTask.d.ts +10 -0
- package/types/sync/submitters/types.d.ts +18 -1
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +5 -0
- package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +5 -0
- package/types/sync/syncTaskComposite.d.ts +5 -0
- package/types/trackers/filter/bloomFilter.d.ts +10 -0
- package/types/trackers/filter/dictionaryFilter.d.ts +8 -0
- package/types/trackers/filter/types.d.ts +5 -0
- package/types/trackers/impressionsTracker.d.ts +4 -6
- package/types/trackers/strategy/strategyDebug.d.ts +9 -0
- package/types/trackers/strategy/strategyNone.d.ts +10 -0
- package/types/trackers/strategy/strategyOptimized.d.ts +11 -0
- package/types/trackers/types.d.ts +23 -0
- package/types/trackers/uniqueKeysTracker.d.ts +13 -0
- package/types/types.d.ts +5 -1
- package/types/utils/constants/index.d.ts +2 -0
- package/types/utils/settingsValidation/index.d.ts +1 -0
- package/types/utils/timeTracker/index.d.ts +70 -0
- package/src/logger/.DS_Store +0 -0
|
@@ -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,52 +12,34 @@ 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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
var _a = strategy.process(impressions), impressionsToStore = _a.impressionsToStore, impressionsToListener = _a.impressionsToListener, deduped = _a.deduped;
|
|
25
|
+
var impressionsToListenerCount = impressionsToListener.length;
|
|
26
|
+
if (impressionsToStore.length > 0) {
|
|
27
|
+
var res = impressionsCache.track(impressionsToStore);
|
|
28
|
+
// If we're on an async storage, handle error and log it.
|
|
29
|
+
if ((0, thenable_1.thenable)(res)) {
|
|
30
|
+
res.then(function () {
|
|
31
|
+
log.info(constants_1.IMPRESSIONS_TRACKER_SUCCESS, [impressionsCount]);
|
|
32
|
+
}).catch(function (err) {
|
|
33
|
+
log.error(constants_1.ERROR_IMPRESSIONS_TRACKER, [impressionsCount, err]);
|
|
34
|
+
});
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
impressionsToStore.push(impression);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
var res = impressionsCache.track(impressionsToStore);
|
|
48
|
-
// If we're on an async storage, handle error and log it.
|
|
49
|
-
if ((0, thenable_1.thenable)(res)) {
|
|
50
|
-
res.then(function () {
|
|
51
|
-
log.info(constants_1.IMPRESSIONS_TRACKER_SUCCESS, [impressionsCount]);
|
|
52
|
-
}).catch(function (err) {
|
|
53
|
-
log.error(constants_1.ERROR_IMPRESSIONS_TRACKER, [impressionsCount, err]);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// Record when impressionsCache is sync only (standalone mode)
|
|
58
|
-
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
59
|
-
if (telemetryCache) {
|
|
60
|
-
telemetryCache.recordImpressionStats(constants_2.QUEUED, impressionsToStore.length);
|
|
61
|
-
telemetryCache.recordImpressionStats(constants_2.DEDUPED, impressions.length - impressionsToStore.length);
|
|
36
|
+
else {
|
|
37
|
+
// Record when impressionsCache is sync only (standalone mode)
|
|
38
|
+
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
39
|
+
if (telemetryCache) {
|
|
40
|
+
telemetryCache.recordImpressionStats(constants_2.QUEUED, impressionsToStore.length);
|
|
41
|
+
telemetryCache.recordImpressionStats(constants_2.DEDUPED, deduped);
|
|
42
|
+
}
|
|
62
43
|
}
|
|
63
44
|
}
|
|
64
45
|
// @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 +47,7 @@ countsCache, telemetryCache) {
|
|
|
66
47
|
var _loop_1 = function (i) {
|
|
67
48
|
var impressionData = {
|
|
68
49
|
// copy of impression, to avoid unexpected behaviour if modified by integrations or impressionListener
|
|
69
|
-
impression: (0, objectAssign_1.objectAssign)({},
|
|
50
|
+
impression: (0, objectAssign_1.objectAssign)({}, impressionsToListener[i]),
|
|
70
51
|
attributes: attributes,
|
|
71
52
|
ip: ip,
|
|
72
53
|
hostname: hostname,
|
|
@@ -86,7 +67,7 @@ countsCache, telemetryCache) {
|
|
|
86
67
|
}
|
|
87
68
|
}, 0);
|
|
88
69
|
};
|
|
89
|
-
for (var i = 0; i <
|
|
70
|
+
for (var i = 0; i < impressionsToListenerCount; i++) {
|
|
90
71
|
_loop_1(i);
|
|
91
72
|
}
|
|
92
73
|
}
|
|
@@ -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,35 @@
|
|
|
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
|
+
if (impression.pt)
|
|
21
|
+
impressionsCounter.track(impression.feature, now, 1);
|
|
22
|
+
// Checks if the impression should be added in queue to be sent
|
|
23
|
+
if (!impression.pt || impression.pt < (0, time_1.truncateTimeFrame)(now)) {
|
|
24
|
+
impressionsToStore.push(impression);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
impressionsToStore: impressionsToStore,
|
|
29
|
+
impressionsToListener: impressions,
|
|
30
|
+
deduped: impressions.length - impressionsToStore.length
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.strategyOptimizedFactory = strategyOptimizedFactory;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 uniqueKeysCache cache to save unique keys
|
|
17
|
+
* @param filterAdapter filter adapter
|
|
18
|
+
*/
|
|
19
|
+
function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
20
|
+
if (filterAdapter === void 0) { filterAdapter = noopFilterAdapter; }
|
|
21
|
+
var intervalId;
|
|
22
|
+
if (filterAdapter.refreshRate) {
|
|
23
|
+
intervalId = setInterval(filterAdapter.clear, filterAdapter.refreshRate);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
track: function (key, featureName) {
|
|
27
|
+
if (!filterAdapter.add(key, featureName)) {
|
|
28
|
+
log.debug(constants_1.LOG_PREFIX_UNIQUE_KEYS_TRACKER + "The feature " + featureName + " and key " + key + " exist in the filter");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
uniqueKeysCache.track(key, featureName);
|
|
32
|
+
},
|
|
33
|
+
stop: function () {
|
|
34
|
+
clearInterval(intervalId);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
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';
|
|
@@ -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,8 @@ 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);
|
|
118
|
+
scheduler.impressionCountsRefreshRate = fromSecondsToMillis(scheduler.impressionCountsRefreshRate);
|
|
115
119
|
scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
|
|
116
120
|
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
117
121
|
if ((0, lang_1.get)(config, 'scheduler.impressionsRefreshRate') === undefined && withDefaults.sync.impressionsMode === constants_1.DEBUG)
|
|
@@ -36,8 +36,8 @@ export function createUserConsentAPI(params) {
|
|
|
36
36
|
if (events.clear)
|
|
37
37
|
events.clear(); // @ts-ignore
|
|
38
38
|
if (impressions.clear)
|
|
39
|
-
impressions.clear();
|
|
40
|
-
if (impressionCounts)
|
|
39
|
+
impressions.clear(); // @ts-ignore
|
|
40
|
+
if (impressionCounts && impressionCounts.clear)
|
|
41
41
|
impressionCounts.clear();
|
|
42
42
|
}
|
|
43
43
|
}
|
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: ';
|
|
@@ -6,7 +6,7 @@ import { clientInputValidationDecorator } from './clientInputValidation';
|
|
|
6
6
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
7
7
|
*/
|
|
8
8
|
export function sdkClientFactory(params, isSharedClient) {
|
|
9
|
-
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker;
|
|
9
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker, uniqueKeysTracker = params.uniqueKeysTracker;
|
|
10
10
|
return objectAssign(
|
|
11
11
|
// Proto-linkage of the readiness Event Emitter
|
|
12
12
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
@@ -28,6 +28,8 @@ export function sdkClientFactory(params, isSharedClient) {
|
|
|
28
28
|
// Release the API Key if it is the main client
|
|
29
29
|
if (!isSharedClient)
|
|
30
30
|
releaseApiKey(settings.core.authorizationKey);
|
|
31
|
+
if (uniqueKeysTracker)
|
|
32
|
+
uniqueKeysTracker.stop();
|
|
31
33
|
// Cleanup storage
|
|
32
34
|
return storage.destroy();
|
|
33
35
|
});
|
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, OPTIMIZED } 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,17 @@ 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,
|
|
35
|
+
impressionCountsQueueSize: settings.scheduler.impressionCountsQueueSize,
|
|
36
|
+
impressionCountsRefreshRate: settings.scheduler.impressionCountsRefreshRate,
|
|
37
|
+
uniqueKeysRefreshRate: settings.scheduler.uniqueKeysRefreshRate,
|
|
29
38
|
optimize: shouldBeOptimized(settings),
|
|
30
39
|
// ATM, only used by InLocalStorage
|
|
31
40
|
matchingKey: getMatching(settings.core.key),
|
|
32
41
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
33
42
|
// ATM, only used by PluggableStorage
|
|
34
43
|
mode: settings.mode,
|
|
44
|
+
impressionsMode: settings.sync.impressionsMode,
|
|
35
45
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
36
46
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
37
47
|
onReadyCb: function (error) {
|
|
@@ -47,13 +57,24 @@ export function sdkFactory(params) {
|
|
|
47
57
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
48
58
|
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
49
59
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
50
|
-
|
|
51
|
-
var
|
|
52
|
-
var
|
|
60
|
+
var observer = impressionsObserverFactory();
|
|
61
|
+
var uniqueKeysTracker = storageFactoryParams.impressionsMode === NONE ? uniqueKeysTrackerFactory(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
62
|
+
var strategy;
|
|
63
|
+
switch (storageFactoryParams.impressionsMode) {
|
|
64
|
+
case OPTIMIZED:
|
|
65
|
+
strategy = strategyOptimizedFactory(observer, storage.impressionCounts);
|
|
66
|
+
break;
|
|
67
|
+
case NONE:
|
|
68
|
+
strategy = strategyNoneFactory(storage.impressionCounts, uniqueKeysTracker);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
strategy = strategyDebugFactory(observer);
|
|
72
|
+
}
|
|
73
|
+
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
53
74
|
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
54
75
|
// splitApi is used by SyncManager and Browser signal listener
|
|
55
76
|
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 };
|
|
77
|
+
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
57
78
|
var syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
58
79
|
ctx.syncManager = syncManager;
|
|
59
80
|
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);
|
|
@@ -20,6 +20,12 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
20
20
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
21
21
|
return this.prefix + ".impressions";
|
|
22
22
|
};
|
|
23
|
+
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
24
|
+
return this.prefix + ".impressions.count";
|
|
25
|
+
};
|
|
26
|
+
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
27
|
+
return this.prefix + ".uniquekeys";
|
|
28
|
+
};
|
|
23
29
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
24
30
|
return this.prefix + ".events";
|
|
25
31
|
};
|
|
@@ -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) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { truncateTimeFrame } from '../../utils/time';
|
|
2
|
+
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
2
3
|
var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
3
|
-
function ImpressionCountsCacheInMemory() {
|
|
4
|
+
function ImpressionCountsCacheInMemory(impressionCountsCacheSize) {
|
|
5
|
+
if (impressionCountsCacheSize === void 0) { impressionCountsCacheSize = DEFAULT_CACHE_SIZE; }
|
|
4
6
|
this.cache = {};
|
|
7
|
+
this.cacheSize = 0;
|
|
8
|
+
this.maxStorage = impressionCountsCacheSize;
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
11
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
@@ -16,6 +20,13 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
16
20
|
var key = this._makeKey(featureName, timeFrame);
|
|
17
21
|
var currentAmount = this.cache[key];
|
|
18
22
|
this.cache[key] = currentAmount ? currentAmount + amount : amount;
|
|
23
|
+
if (this.onFullQueue) {
|
|
24
|
+
this.cacheSize = this.cacheSize + amount;
|
|
25
|
+
if (this.cacheSize >= this.maxStorage) {
|
|
26
|
+
this.onFullQueue();
|
|
27
|
+
this.cacheSize = 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
19
30
|
};
|
|
20
31
|
/**
|
|
21
32
|
* Pop the collected data, used as payload for posting.
|
|
@@ -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 () {
|