@splitsoftware/splitio-commons 1.6.2-rc.8 → 1.6.2-rc.9
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 +2 -1
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/evaluator/index.js +5 -5
- package/cjs/listeners/browser.js +1 -2
- package/cjs/logger/constants.js +1 -2
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkClient/sdkClient.js +1 -3
- package/cjs/sdkFactory/index.js +5 -23
- package/cjs/services/splitApi.js +4 -24
- package/cjs/storages/KeyBuilderSS.js +48 -15
- package/cjs/storages/inLocalStorage/index.js +1 -5
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -6
- package/cjs/storages/inMemory/InMemoryStorageCS.js +2 -6
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +9 -6
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/constants.js +1 -4
- package/cjs/storages/inRedis/index.js +2 -17
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/index.js +19 -15
- package/cjs/sync/submitters/submitterManager.js +0 -3
- package/cjs/sync/submitters/telemetrySubmitter.js +7 -5
- package/cjs/trackers/impressionsTracker.js +41 -22
- package/cjs/utils/constants/index.js +2 -4
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +0 -3
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +5 -5
- package/esm/listeners/browser.js +2 -3
- package/esm/logger/constants.js +0 -1
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkClient/sdkClient.js +1 -3
- package/esm/sdkFactory/index.js +5 -23
- package/esm/services/splitApi.js +4 -24
- package/esm/storages/KeyBuilderSS.js +44 -14
- package/esm/storages/inLocalStorage/index.js +2 -6
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
- package/esm/storages/inMemory/InMemoryStorage.js +4 -8
- package/esm/storages/inMemory/InMemoryStorageCS.js +3 -7
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +8 -6
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/constants.js +0 -3
- package/esm/storages/inRedis/index.js +3 -18
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/index.js +19 -15
- package/esm/sync/submitters/submitterManager.js +0 -3
- package/esm/sync/submitters/telemetrySubmitter.js +8 -6
- package/esm/trackers/impressionsTracker.js +41 -22
- package/esm/utils/constants/index.js +0 -2
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +0 -3
- package/package.json +2 -1
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/evaluator/index.ts +6 -6
- package/src/listeners/browser.ts +2 -3
- package/src/logger/.DS_Store +0 -0
- package/src/logger/constants.ts +0 -1
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +1 -3
- package/src/sdkFactory/index.ts +5 -26
- package/src/sdkFactory/types.ts +4 -7
- package/src/services/splitApi.ts +4 -26
- package/src/services/types.ts +2 -8
- package/src/storages/KeyBuilderSS.ts +53 -17
- package/src/storages/inLocalStorage/index.ts +2 -5
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +1 -16
- package/src/storages/inMemory/InMemoryStorage.ts +4 -7
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -7
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +9 -7
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -2
- package/src/storages/inRedis/constants.ts +0 -3
- package/src/storages/inRedis/index.ts +5 -15
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -2
- package/src/storages/pluggable/index.ts +20 -16
- package/src/storages/types.ts +13 -31
- package/src/sync/submitters/submitterManager.ts +0 -2
- package/src/sync/submitters/telemetrySubmitter.ts +14 -9
- package/src/sync/submitters/types.ts +40 -26
- package/src/trackers/impressionsTracker.ts +48 -27
- package/src/trackers/types.ts +0 -28
- package/src/types.ts +1 -3
- package/src/utils/constants/index.ts +0 -2
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +0 -4
- package/types/logger/constants.d.ts +0 -1
- package/types/sdkFactory/types.d.ts +2 -4
- package/types/services/types.d.ts +2 -6
- package/types/storages/KeyBuilderSS.d.ts +7 -4
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +1 -5
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -3
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/constants.d.ts +0 -3
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/types.d.ts +10 -18
- package/types/sync/submitters/telemetrySubmitter.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +13 -24
- package/types/trackers/impressionsTracker.d.ts +6 -4
- package/types/trackers/types.d.ts +0 -23
- package/types/types.d.ts +1 -3
- package/types/utils/constants/index.d.ts +0 -2
- package/types/utils/lang/maps.d.ts +6 -2
- package/types/utils/settingsValidation/index.d.ts +0 -1
- package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +0 -73
- package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -78
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -50
- package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +0 -59
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +0 -26
- package/cjs/trackers/strategy/strategyDebug.js +0 -25
- package/cjs/trackers/strategy/strategyNone.js +0 -29
- package/cjs/trackers/strategy/strategyOptimized.js +0 -35
- package/cjs/trackers/uniqueKeysTracker.js +0 -38
- package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +0 -70
- package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -75
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -47
- package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +0 -56
- package/esm/sync/submitters/uniqueKeysSubmitter.js +0 -22
- package/esm/trackers/strategy/strategyDebug.js +0 -21
- package/esm/trackers/strategy/strategyNone.js +0 -25
- package/esm/trackers/strategy/strategyOptimized.js +0 -31
- package/esm/trackers/uniqueKeysTracker.js +0 -34
- package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +0 -82
- package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +0 -88
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +0 -52
- package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +0 -64
- package/src/sync/submitters/uniqueKeysSubmitter.ts +0 -35
- package/src/trackers/strategy/strategyDebug.ts +0 -28
- package/src/trackers/strategy/strategyNone.ts +0 -34
- package/src/trackers/strategy/strategyOptimized.ts +0 -42
- package/src/trackers/uniqueKeysTracker.ts +0 -48
- package/types/sdkClient/types.d.ts +0 -18
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +0 -35
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +0 -37
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +0 -14
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +0 -15
- package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
- package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
- package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +0 -5
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
- package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
- package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
- package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +0 -5
- package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +0 -5
- package/types/sync/syncTaskComposite.d.ts +0 -5
- package/types/trackers/filter/bloomFilter.d.ts +0 -10
- package/types/trackers/filter/dictionaryFilter.d.ts +0 -8
- package/types/trackers/filter/types.d.ts +0 -5
- package/types/trackers/strategy/strategyDebug.d.ts +0 -9
- package/types/trackers/strategy/strategyNone.d.ts +0 -10
- package/types/trackers/strategy/strategyOptimized.d.ts +0 -11
- package/types/trackers/uniqueKeysTracker.d.ts +0 -13
- package/types/utils/timeTracker/index.d.ts +0 -70
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.LOG_PREFIX = void 0;
|
|
4
4
|
exports.LOG_PREFIX = 'storage:redis: ';
|
|
5
|
-
exports.DEFAULT_CACHE_SIZE = 30000;
|
|
6
|
-
exports.REFRESH_RATE = 300000; // 300.000 ms = start after 5 mins
|
|
7
|
-
exports.TTL_REFRESH = 3600; // 1hr
|
|
@@ -10,8 +10,6 @@ var ImpressionsCacheInRedis_1 = require("./ImpressionsCacheInRedis");
|
|
|
10
10
|
var EventsCacheInRedis_1 = require("./EventsCacheInRedis");
|
|
11
11
|
var constants_1 = require("../../utils/constants");
|
|
12
12
|
var TelemetryCacheInRedis_1 = require("./TelemetryCacheInRedis");
|
|
13
|
-
var uniqueKeysCacheInRedis_1 = require("./uniqueKeysCacheInRedis");
|
|
14
|
-
var ImpressionCountsCacheInRedis_1 = require("./ImpressionCountsCacheInRedis");
|
|
15
13
|
/**
|
|
16
14
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
17
15
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -20,19 +18,13 @@ function InRedisStorage(options) {
|
|
|
20
18
|
if (options === void 0) { options = {}; }
|
|
21
19
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
22
20
|
function InRedisStorageFactory(_a) {
|
|
23
|
-
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb
|
|
21
|
+
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
24
22
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
25
23
|
var redisClient = new RedisAdapter_1.RedisAdapter(log, options.options || {});
|
|
26
24
|
var telemetry = new TelemetryCacheInRedis_1.TelemetryCacheInRedis(log, keys, redisClient);
|
|
27
|
-
var impressionCountsCache = impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInRedis_1.ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
|
|
28
|
-
var uniqueKeysCache = impressionsMode === constants_1.NONE ? new uniqueKeysCacheInRedis_1.UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;
|
|
29
25
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
30
26
|
redisClient.on('connect', function () {
|
|
31
27
|
onReadyCb();
|
|
32
|
-
if (impressionCountsCache)
|
|
33
|
-
impressionCountsCache.start();
|
|
34
|
-
if (uniqueKeysCache)
|
|
35
|
-
uniqueKeysCache.start();
|
|
36
28
|
// Synchronize config
|
|
37
29
|
telemetry.recordConfig();
|
|
38
30
|
});
|
|
@@ -40,19 +32,12 @@ function InRedisStorage(options) {
|
|
|
40
32
|
splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient),
|
|
41
33
|
segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
|
|
42
34
|
impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
43
|
-
impressionCounts: impressionCountsCache,
|
|
44
35
|
events: new EventsCacheInRedis_1.EventsCacheInRedis(log, keys.buildEventsKey(), redisClient, metadata),
|
|
45
36
|
telemetry: telemetry,
|
|
46
|
-
uniqueKeys: uniqueKeysCache,
|
|
47
37
|
// When using REDIS we should:
|
|
48
38
|
// 1- Disconnect from the storage
|
|
49
39
|
destroy: function () {
|
|
50
|
-
|
|
51
|
-
if (impressionCountsCache)
|
|
52
|
-
promises.push(impressionCountsCache.stop());
|
|
53
|
-
if (uniqueKeysCache)
|
|
54
|
-
promises.push(uniqueKeysCache.stop());
|
|
55
|
-
return Promise.all(promises).then(function () { redisClient.disconnect(); });
|
|
40
|
+
redisClient.disconnect();
|
|
56
41
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
57
42
|
}
|
|
58
43
|
};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TelemetryCachePluggable = void 0;
|
|
4
|
+
var KeyBuilderSS_1 = require("../KeyBuilderSS");
|
|
4
5
|
var findLatencyIndex_1 = require("../findLatencyIndex");
|
|
6
|
+
var telemetrySubmitter_1 = require("../../sync/submitters/telemetrySubmitter");
|
|
7
|
+
var constants_1 = require("../../utils/constants");
|
|
8
|
+
var lang_1 = require("../../utils/lang");
|
|
9
|
+
var maps_1 = require("../../utils/lang/maps");
|
|
10
|
+
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
5
11
|
var TelemetryCachePluggable = /** @class */ (function () {
|
|
6
12
|
/**
|
|
7
13
|
* Create a Telemetry cache that uses a storage wrapper.
|
|
@@ -22,6 +28,126 @@ var TelemetryCachePluggable = /** @class */ (function () {
|
|
|
22
28
|
return this.wrapper.incr(this.keys.buildExceptionKey(method))
|
|
23
29
|
.catch(function () { });
|
|
24
30
|
};
|
|
31
|
+
TelemetryCachePluggable.prototype.recordConfig = function () {
|
|
32
|
+
var value = JSON.stringify((0, telemetrySubmitter_1.getTelemetryConfigStats)(constants_1.CONSUMER_MODE, constants_1.STORAGE_PLUGGABLE));
|
|
33
|
+
return this.wrapper.set(this.keys.buildInitKey(), value).catch(function () { });
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Pop telemetry latencies.
|
|
37
|
+
* The returned promise rejects if wrapper operations fail.
|
|
38
|
+
*/
|
|
39
|
+
TelemetryCachePluggable.prototype.popLatencies = function () {
|
|
40
|
+
var _this = this;
|
|
41
|
+
return this.wrapper.getKeysByPrefix(this.keys.latencyPrefix).then(function (latencyKeys) {
|
|
42
|
+
return latencyKeys.length ?
|
|
43
|
+
_this.wrapper.getMany(latencyKeys).then(function (latencies) {
|
|
44
|
+
var result = new maps_1._Map();
|
|
45
|
+
for (var i = 0; i < latencyKeys.length; i++) {
|
|
46
|
+
var field = latencyKeys[i].split('::')[1];
|
|
47
|
+
var parsedField = (0, KeyBuilderSS_1.parseLatencyField)(field);
|
|
48
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
49
|
+
_this.log.error("Ignoring invalid latency field: " + field + ": " + parsedField);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
var count = parseInt(latencies[i]);
|
|
54
|
+
if ((0, lang_1.isNaNNumber)(count)) {
|
|
55
|
+
_this.log.error("Ignoring latency with invalid count: " + latencies[i]);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
var metadata = parsedField[0], method = parsedField[1], bucket = parsedField[2];
|
|
59
|
+
if (bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT) {
|
|
60
|
+
_this.log.error("Ignoring latency with invalid bucket: " + bucket);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!result.has(metadata))
|
|
64
|
+
result.set(metadata, {
|
|
65
|
+
t: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
66
|
+
ts: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
67
|
+
tc: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
68
|
+
tcs: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
69
|
+
tr: (0, TelemetryCacheInMemory_1.newBuckets)(),
|
|
70
|
+
});
|
|
71
|
+
result.get(metadata)[method][bucket] = count;
|
|
72
|
+
}
|
|
73
|
+
return Promise.all(latencyKeys.map(function (latencyKey) { return _this.wrapper.del(latencyKey); })).then(function () { return result; });
|
|
74
|
+
}) :
|
|
75
|
+
// If latencyKeys is empty, return an empty map.
|
|
76
|
+
new maps_1._Map();
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Pop telemetry exceptions.
|
|
81
|
+
* The returned promise rejects if wrapper operations fail.
|
|
82
|
+
*/
|
|
83
|
+
TelemetryCachePluggable.prototype.popExceptions = function () {
|
|
84
|
+
var _this = this;
|
|
85
|
+
return this.wrapper.getKeysByPrefix(this.keys.exceptionPrefix).then(function (exceptionKeys) {
|
|
86
|
+
return exceptionKeys.length ?
|
|
87
|
+
_this.wrapper.getMany(exceptionKeys).then(function (exceptions) {
|
|
88
|
+
var result = new maps_1._Map();
|
|
89
|
+
for (var i = 0; i < exceptionKeys.length; i++) {
|
|
90
|
+
var field = exceptionKeys[i].split('::')[1];
|
|
91
|
+
var parsedField = (0, KeyBuilderSS_1.parseExceptionField)(field);
|
|
92
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
93
|
+
_this.log.error("Ignoring invalid exception field: " + field + ": " + parsedField);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
var count = parseInt(exceptions[i]);
|
|
98
|
+
if ((0, lang_1.isNaNNumber)(count)) {
|
|
99
|
+
_this.log.error("Ignoring exception with invalid count: " + exceptions[i]);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
var metadata = parsedField[0], method = parsedField[1];
|
|
103
|
+
if (!result.has(metadata))
|
|
104
|
+
result.set(metadata, {
|
|
105
|
+
t: 0,
|
|
106
|
+
ts: 0,
|
|
107
|
+
tc: 0,
|
|
108
|
+
tcs: 0,
|
|
109
|
+
tr: 0,
|
|
110
|
+
});
|
|
111
|
+
result.get(metadata)[method] = count;
|
|
112
|
+
}
|
|
113
|
+
return Promise.all(exceptionKeys.map(function (exceptionKey) { return _this.wrapper.del(exceptionKey); })).then(function () { return result; });
|
|
114
|
+
}) :
|
|
115
|
+
// If exceptionKeys is empty, return an empty map.
|
|
116
|
+
new maps_1._Map();
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Pop telemetry configs.
|
|
121
|
+
* The returned promise rejects if wrapper operations fail.
|
|
122
|
+
*/
|
|
123
|
+
TelemetryCachePluggable.prototype.popConfigs = function () {
|
|
124
|
+
var _this = this;
|
|
125
|
+
return this.wrapper.getKeysByPrefix(this.keys.initPrefix).then(function (configKeys) {
|
|
126
|
+
return configKeys.length ?
|
|
127
|
+
_this.wrapper.getMany(configKeys).then(function (configs) {
|
|
128
|
+
var result = new maps_1._Map();
|
|
129
|
+
for (var i = 0; i < configKeys.length; i++) {
|
|
130
|
+
var field = configKeys[i].split('::')[1];
|
|
131
|
+
var parsedField = (0, KeyBuilderSS_1.parseMetadata)(field);
|
|
132
|
+
if ((0, lang_1.isString)(parsedField)) {
|
|
133
|
+
_this.log.error("Ignoring invalid config field: " + field + ": " + parsedField);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
var metadata = parsedField[0];
|
|
137
|
+
try { // @ts-ignore
|
|
138
|
+
var config = JSON.parse(configs[i]);
|
|
139
|
+
result.set(metadata, config);
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
_this.log.error("Ignoring invalid config: " + configs[i]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return Promise.all(configKeys.map(function (configKey) { return _this.wrapper.del(configKey); })).then(function () { return result; });
|
|
146
|
+
}) :
|
|
147
|
+
// If configKeys is empty, return an empty map.
|
|
148
|
+
new maps_1._Map();
|
|
149
|
+
});
|
|
150
|
+
};
|
|
25
151
|
return TelemetryCachePluggable;
|
|
26
152
|
}());
|
|
27
153
|
exports.TelemetryCachePluggable = TelemetryCachePluggable;
|
|
@@ -14,6 +14,8 @@ var constants_1 = require("../../utils/constants");
|
|
|
14
14
|
var ImpressionsCacheInMemory_1 = require("../inMemory/ImpressionsCacheInMemory");
|
|
15
15
|
var EventsCacheInMemory_1 = require("../inMemory/EventsCacheInMemory");
|
|
16
16
|
var ImpressionCountsCacheInMemory_1 = require("../inMemory/ImpressionCountsCacheInMemory");
|
|
17
|
+
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
18
|
+
var TelemetryCachePluggable_1 = require("./TelemetryCachePluggable");
|
|
17
19
|
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
18
20
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
19
21
|
/**
|
|
@@ -30,15 +32,6 @@ function validatePluggableStorageOptions(options) {
|
|
|
30
32
|
if (missingMethods.length)
|
|
31
33
|
throw new Error(NO_VALID_WRAPPER_INTERFACE + " The following methods are missing or invalid: " + missingMethods);
|
|
32
34
|
}
|
|
33
|
-
// subscription to wrapper connect event in order to emit SDK_READY event
|
|
34
|
-
function wrapperConnect(wrapper, onReadyCb) {
|
|
35
|
-
wrapper.connect().then(function () {
|
|
36
|
-
onReadyCb();
|
|
37
|
-
// At the moment, we don't synchronize config with pluggable storage
|
|
38
|
-
}).catch(function (e) {
|
|
39
|
-
onReadyCb(e || new Error('Error connecting wrapper'));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
35
|
// Async return type in `client.track` method on consumer partial mode
|
|
43
36
|
// No need to promisify impressions cache
|
|
44
37
|
function promisifyEventsTrack(events) {
|
|
@@ -54,28 +47,39 @@ function promisifyEventsTrack(events) {
|
|
|
54
47
|
function PluggableStorage(options) {
|
|
55
48
|
validatePluggableStorageOptions(options);
|
|
56
49
|
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
57
|
-
function PluggableStorageFactory(
|
|
58
|
-
var log =
|
|
50
|
+
function PluggableStorageFactory(params) {
|
|
51
|
+
var log = params.log, metadata = params.metadata, onReadyCb = params.onReadyCb, mode = params.mode, eventsQueueSize = params.eventsQueueSize, impressionsQueueSize = params.impressionsQueueSize, optimize = params.optimize;
|
|
59
52
|
var keys = new KeyBuilderSS_1.KeyBuilderSS(prefix, metadata);
|
|
60
53
|
var wrapper = (0, wrapperAdapter_1.wrapperAdapter)(log, options.wrapper);
|
|
61
54
|
var isPartialConsumer = mode === constants_1.CONSUMER_PARTIAL_MODE;
|
|
55
|
+
var telemetry = (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ?
|
|
56
|
+
isPartialConsumer ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : new TelemetryCachePluggable_1.TelemetryCachePluggable(log, keys, wrapper) :
|
|
57
|
+
undefined;
|
|
62
58
|
// Connects to wrapper and emits SDK_READY event on main client
|
|
63
|
-
|
|
59
|
+
var connectPromise = wrapper.connect().then(function () {
|
|
60
|
+
onReadyCb();
|
|
61
|
+
// If mode is not defined, it means that the synchronizer is running and so we don't have to record telemetry
|
|
62
|
+
if (telemetry && telemetry.recordConfig && mode)
|
|
63
|
+
telemetry.recordConfig();
|
|
64
|
+
}).catch(function (e) {
|
|
65
|
+
e = e || new Error('Error connecting wrapper');
|
|
66
|
+
onReadyCb(e);
|
|
67
|
+
return e;
|
|
68
|
+
});
|
|
64
69
|
return {
|
|
65
70
|
splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper),
|
|
66
71
|
segments: new SegmentsCachePluggable_1.SegmentsCachePluggable(log, keys, wrapper),
|
|
67
72
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable_1.ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
68
73
|
impressionCounts: optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
69
74
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable_1.EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
70
|
-
|
|
71
|
-
// telemetry: isPartialConsumer ? new TelemetryCacheInMemory() : new TelemetryCachePluggable(log, keys, wrapper),
|
|
75
|
+
telemetry: telemetry,
|
|
72
76
|
// Disconnect the underlying storage
|
|
73
77
|
destroy: function () {
|
|
74
78
|
return wrapper.disconnect();
|
|
75
79
|
},
|
|
76
80
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
77
81
|
shared: function (_, onReadyCb) {
|
|
78
|
-
|
|
82
|
+
connectPromise.then(onReadyCb);
|
|
79
83
|
return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, this), {
|
|
80
84
|
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
81
85
|
destroy: function () { } });
|
|
@@ -5,7 +5,6 @@ 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");
|
|
9
8
|
function submitterManagerFactory(params) {
|
|
10
9
|
var submitters = [
|
|
11
10
|
(0, impressionsSubmitter_1.impressionsSubmitterFactory)(params),
|
|
@@ -15,8 +14,6 @@ function submitterManagerFactory(params) {
|
|
|
15
14
|
if (impressionCountsSubmitter)
|
|
16
15
|
submitters.push(impressionCountsSubmitter);
|
|
17
16
|
var telemetrySubmitter = (0, telemetrySubmitter_1.telemetrySubmitterFactory)(params);
|
|
18
|
-
if (params.uniqueKeysTracker)
|
|
19
|
-
submitters.push((0, uniqueKeysSubmitter_1.uniqueKeysSubmitterFactory)(params));
|
|
20
17
|
return {
|
|
21
18
|
// `onlyTelemetry` true if SDK is created with userConsent not GRANTED
|
|
22
19
|
start: function (onlyTelemetry) {
|
|
@@ -9,6 +9,7 @@ var settingsValidation_1 = require("../../utils/settingsValidation");
|
|
|
9
9
|
var apiKey_1 = require("../../utils/inputValidation/apiKey");
|
|
10
10
|
var timer_1 = require("../../utils/timeTracker/timer");
|
|
11
11
|
var objectAssign_1 = require("../../utils/lang/objectAssign");
|
|
12
|
+
var utils_1 = require("../../trackers/impressionObserver/utils");
|
|
12
13
|
/**
|
|
13
14
|
* Converts data from telemetry cache into /metrics/usage request payload.
|
|
14
15
|
*/
|
|
@@ -29,9 +30,9 @@ function telemetryCacheStatsAdapter(telemetry, splits, segments) {
|
|
|
29
30
|
iQ: telemetry.getImpressionStats(constants_1.QUEUED),
|
|
30
31
|
iDe: telemetry.getImpressionStats(constants_1.DEDUPED),
|
|
31
32
|
iDr: telemetry.getImpressionStats(constants_1.DROPPED),
|
|
32
|
-
spC: splits.getSplitNames().length,
|
|
33
|
-
seC: segments.getRegisteredSegments().length,
|
|
34
|
-
skC: segments.getKeysCount(),
|
|
33
|
+
spC: splits && splits.getSplitNames().length,
|
|
34
|
+
seC: segments && segments.getRegisteredSegments().length,
|
|
35
|
+
skC: segments && segments.getKeysCount(),
|
|
35
36
|
sL: telemetry.getSessionLength(),
|
|
36
37
|
eQ: telemetry.getEventStats(constants_1.QUEUED),
|
|
37
38
|
eD: telemetry.getEventStats(constants_1.DROPPED),
|
|
@@ -50,7 +51,6 @@ var OPERATION_MODE_MAP = (_a = {},
|
|
|
50
51
|
var IMPRESSIONS_MODE_MAP = (_b = {},
|
|
51
52
|
_b[constants_1.OPTIMIZED] = constants_1.OPTIMIZED_ENUM,
|
|
52
53
|
_b[constants_1.DEBUG] = constants_1.DEBUG_ENUM,
|
|
53
|
-
_b[constants_1.NONE] = constants_1.NONE_ENUM,
|
|
54
54
|
_b);
|
|
55
55
|
var USER_CONSENT_MAP = (_c = {},
|
|
56
56
|
_c[constants_1.CONSENT_UNKNOWN] = 1,
|
|
@@ -126,7 +126,9 @@ function telemetrySubmitterFactory(params) {
|
|
|
126
126
|
return; // No submitter created if telemetry cache is not defined
|
|
127
127
|
var settings = params.settings, _b = params.settings, log = _b.log, telemetryRefreshRate = _b.scheduler.telemetryRefreshRate, splitApi = params.splitApi, readiness = params.readiness, sdkReadinessManager = params.sdkReadinessManager;
|
|
128
128
|
var startTime = (0, timer_1.timer)(now);
|
|
129
|
-
var submitter = (0, submitter_1.firstPushWindowDecorator)((0, submitter_1.submitterFactory)(log, splitApi.postMetricsUsage,
|
|
129
|
+
var submitter = (0, submitter_1.firstPushWindowDecorator)((0, submitter_1.submitterFactory)(log, splitApi.postMetricsUsage,
|
|
130
|
+
// @TODO cannot provide splits and segments cache if they are async, because `submitterFactory` expects a sync storage source
|
|
131
|
+
(0, utils_1.isStorageSync)(params.settings) ? telemetryCacheStatsAdapter(telemetry, splits, segments) : telemetryCacheStatsAdapter(telemetry), telemetryRefreshRate, 'telemetry stats', undefined, 0, true), telemetryRefreshRate);
|
|
130
132
|
readiness.gate.once(constants_2.SDK_READY_FROM_CACHE, function () {
|
|
131
133
|
telemetry.recordTimeUntilReadyFromCache(startTime());
|
|
132
134
|
});
|
|
@@ -3,6 +3,7 @@ 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");
|
|
6
7
|
var constants_1 = require("../logger/constants");
|
|
7
8
|
var constants_2 = require("../utils/constants");
|
|
8
9
|
/**
|
|
@@ -12,34 +13,52 @@ var constants_2 = require("../utils/constants");
|
|
|
12
13
|
* @param metadata runtime metadata (ip, hostname and version)
|
|
13
14
|
* @param impressionListener optional impression listener
|
|
14
15
|
* @param integrationsManager optional integrations manager
|
|
15
|
-
* @param
|
|
16
|
+
* @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
|
|
17
|
+
* @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
|
|
16
18
|
*/
|
|
17
|
-
function impressionsTrackerFactory(settings, impressionsCache,
|
|
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) {
|
|
18
24
|
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
19
25
|
return {
|
|
20
26
|
track: function (impressions, attributes) {
|
|
21
27
|
if (settings.userConsent === constants_2.CONSENT_DECLINED)
|
|
22
28
|
return;
|
|
23
29
|
var impressionsCount = impressions.length;
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
});
|
|
30
|
+
var impressionsToStore = []; // Track only the impressions that are going to be stored
|
|
31
|
+
// Wraps impressions to store and adds previousTime if it corresponds
|
|
32
|
+
impressions.forEach(function (impression) {
|
|
33
|
+
if (observer) {
|
|
34
|
+
// Adds previous time if it is enabled
|
|
35
|
+
impression.pt = observer.testAndSet(impression);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
});
|
|
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);
|
|
43
62
|
}
|
|
44
63
|
}
|
|
45
64
|
// @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
|
|
@@ -47,7 +66,7 @@ function impressionsTrackerFactory(settings, impressionsCache, strategy, integra
|
|
|
47
66
|
var _loop_1 = function (i) {
|
|
48
67
|
var impressionData = {
|
|
49
68
|
// copy of impression, to avoid unexpected behaviour if modified by integrations or impressionListener
|
|
50
|
-
impression: (0, objectAssign_1.objectAssign)({},
|
|
69
|
+
impression: (0, objectAssign_1.objectAssign)({}, impressions[i]),
|
|
51
70
|
attributes: attributes,
|
|
52
71
|
ip: ip,
|
|
53
72
|
hostname: hostname,
|
|
@@ -67,7 +86,7 @@ function impressionsTrackerFactory(settings, impressionsCache, strategy, integra
|
|
|
67
86
|
}
|
|
68
87
|
}, 0);
|
|
69
88
|
};
|
|
70
|
-
for (var i = 0; i <
|
|
89
|
+
for (var i = 0; i < impressionsCount; i++) {
|
|
71
90
|
_loop_1(i);
|
|
72
91
|
}
|
|
73
92
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.
|
|
4
|
-
exports.PAUSED = exports.ENABLED = exports.DISABLED = exports.NON_REQUESTED = exports.REQUESTED = exports.POLLING = exports.STREAMING =
|
|
3
|
+
exports.AUTH_REJECTION = exports.SYNC_MODE_UPDATE = 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.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.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 = void 0;
|
|
5
5
|
// Special treatments
|
|
6
6
|
exports.CONTROL = 'control';
|
|
7
7
|
exports.CONTROL_WITH_CONFIG = {
|
|
@@ -17,7 +17,6 @@ exports.SPLIT_EVENT = 'EVENT';
|
|
|
17
17
|
// Impression collection modes
|
|
18
18
|
exports.DEBUG = 'DEBUG';
|
|
19
19
|
exports.OPTIMIZED = 'OPTIMIZED';
|
|
20
|
-
exports.NONE = 'NONE';
|
|
21
20
|
// SDK Modes
|
|
22
21
|
exports.LOCALHOST_MODE = 'localhost';
|
|
23
22
|
exports.STANDALONE_MODE = 'standalone';
|
|
@@ -42,7 +41,6 @@ exports.CONSUMER_ENUM = 1;
|
|
|
42
41
|
exports.CONSUMER_PARTIAL_ENUM = 2;
|
|
43
42
|
exports.OPTIMIZED_ENUM = 0;
|
|
44
43
|
exports.DEBUG_ENUM = 1;
|
|
45
|
-
exports.NONE_ENUM = 2;
|
|
46
44
|
exports.SPLITS = 'sp';
|
|
47
45
|
exports.IMPRESSIONS = 'im';
|
|
48
46
|
exports.IMPRESSIONS_COUNT = 'ic';
|
package/cjs/utils/lang/maps.js
CHANGED
|
@@ -40,13 +40,6 @@ var MapPoly = /** @class */ (function () {
|
|
|
40
40
|
this.__mapKeysData__.length = 0;
|
|
41
41
|
this.__mapValuesData__.length = 0;
|
|
42
42
|
};
|
|
43
|
-
MapPoly.prototype.set = function (key, value) {
|
|
44
|
-
var index = this.__mapKeysData__.indexOf(key);
|
|
45
|
-
if (index === -1)
|
|
46
|
-
index = this.__mapKeysData__.push(key) - 1;
|
|
47
|
-
this.__mapValuesData__[index] = value;
|
|
48
|
-
return this;
|
|
49
|
-
};
|
|
50
43
|
MapPoly.prototype.delete = function (key) {
|
|
51
44
|
var index = this.__mapKeysData__.indexOf(key);
|
|
52
45
|
if (index === -1)
|
|
@@ -55,12 +48,27 @@ var MapPoly = /** @class */ (function () {
|
|
|
55
48
|
this.__mapValuesData__.splice(index, 1);
|
|
56
49
|
return true;
|
|
57
50
|
};
|
|
51
|
+
MapPoly.prototype.forEach = function (callbackfn, thisArg) {
|
|
52
|
+
for (var i = 0; i < this.__mapKeysData__.length; i++) {
|
|
53
|
+
callbackfn.call(thisArg, this.__mapValuesData__[i], this.__mapKeysData__[i], this);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
58
56
|
MapPoly.prototype.get = function (key) {
|
|
59
57
|
var index = this.__mapKeysData__.indexOf(key);
|
|
60
58
|
if (index === -1)
|
|
61
59
|
return;
|
|
62
60
|
return this.__mapValuesData__[index];
|
|
63
61
|
};
|
|
62
|
+
MapPoly.prototype.has = function (key) {
|
|
63
|
+
return this.__mapKeysData__.indexOf(key) !== -1;
|
|
64
|
+
};
|
|
65
|
+
MapPoly.prototype.set = function (key, value) {
|
|
66
|
+
var index = this.__mapKeysData__.indexOf(key);
|
|
67
|
+
if (index === -1)
|
|
68
|
+
index = this.__mapKeysData__.push(key) - 1;
|
|
69
|
+
this.__mapValuesData__[index] = value;
|
|
70
|
+
return this;
|
|
71
|
+
};
|
|
64
72
|
Object.defineProperty(MapPoly.prototype, "size", {
|
|
65
73
|
get: function () {
|
|
66
74
|
return this.__mapKeysData__.length;
|
|
@@ -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
|
|
9
|
+
if ([constants_2.DEBUG, constants_2.OPTIMIZED].indexOf(impressionsMode) > -1)
|
|
10
10
|
return impressionsMode;
|
|
11
|
-
log.error(constants_1.ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [constants_2.DEBUG, constants_2.OPTIMIZED
|
|
11
|
+
log.error(constants_1.ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [constants_2.DEBUG, constants_2.OPTIMIZED], constants_2.OPTIMIZED]);
|
|
12
12
|
return constants_2.OPTIMIZED;
|
|
13
13
|
}
|
|
14
14
|
exports.validImpressionsMode = validImpressionsMode;
|
|
@@ -34,8 +34,6 @@ 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,
|
|
39
37
|
// fetch offline changes each 15 sec
|
|
40
38
|
offlineRefreshRate: 15,
|
|
41
39
|
// publish events every 60 seconds after the first flush
|
|
@@ -114,7 +112,6 @@ function settingsValidation(config, validationParams) {
|
|
|
114
112
|
scheduler.segmentsRefreshRate = fromSecondsToMillis(scheduler.segmentsRefreshRate);
|
|
115
113
|
scheduler.offlineRefreshRate = fromSecondsToMillis(scheduler.offlineRefreshRate);
|
|
116
114
|
scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);
|
|
117
|
-
scheduler.uniqueKeysRefreshRate = fromSecondsToMillis(scheduler.uniqueKeysRefreshRate);
|
|
118
115
|
scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
|
|
119
116
|
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
120
117
|
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();
|
|
40
|
+
if (impressionCounts)
|
|
41
41
|
impressionCounts.clear();
|
|
42
42
|
}
|
|
43
43
|
}
|
package/esm/evaluator/index.js
CHANGED
|
@@ -15,21 +15,21 @@ function treatmentsException(splitNames) {
|
|
|
15
15
|
return evaluations;
|
|
16
16
|
}
|
|
17
17
|
export function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
18
|
-
var
|
|
18
|
+
var parsedSplit;
|
|
19
19
|
try {
|
|
20
|
-
|
|
20
|
+
parsedSplit = storage.splits.getSplit(splitName);
|
|
21
21
|
}
|
|
22
22
|
catch (e) {
|
|
23
23
|
// Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
|
|
24
24
|
return treatmentException;
|
|
25
25
|
}
|
|
26
|
-
if (thenable(
|
|
27
|
-
return
|
|
26
|
+
if (thenable(parsedSplit)) {
|
|
27
|
+
return parsedSplit.then(function (split) { return getEvaluation(log, split, key, attributes, storage); }).catch(
|
|
28
28
|
// Exception on async `getSplit` storage. For example, when the storage is redis or
|
|
29
29
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
30
30
|
function () { return treatmentException; });
|
|
31
31
|
}
|
|
32
|
-
return getEvaluation(log,
|
|
32
|
+
return getEvaluation(log, parsedSplit, key, attributes, storage);
|
|
33
33
|
}
|
|
34
34
|
export function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
35
35
|
var parsedSplits;
|
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
|
|
3
|
+
import { OPTIMIZED, DEBUG } 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,10 +71,9 @@ 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;
|
|
75
74
|
var extraMetadata = {
|
|
76
75
|
// sim stands for Sync/Split Impressions Mode
|
|
77
|
-
sim:
|
|
76
|
+
sim: this.settings.sync.impressionsMode === OPTIMIZED ? OPTIMIZED : DEBUG
|
|
78
77
|
};
|
|
79
78
|
this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
80
79
|
this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
package/esm/logger/constants.js
CHANGED
|
@@ -139,5 +139,4 @@ 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: ';
|
|
143
142
|
export var LOG_PREFIX_CLEANUP = 'cleanup: ';
|