@splitsoftware/splitio-commons 1.6.2-rc.1 → 1.6.2-rc.11
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 +4 -0
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/evaluator/index.js +15 -16
- package/cjs/integrations/ga/GaToSplit.js +8 -5
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +15 -6
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/services/splitApi.js +6 -6
- package/cjs/storages/AbstractSplitsCacheAsync.js +8 -10
- package/cjs/storages/AbstractSplitsCacheSync.js +8 -10
- package/cjs/storages/KeyBuilderSS.js +54 -9
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/cjs/storages/inLocalStorage/index.js +5 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +6 -2
- package/cjs/storages/inMemory/InMemoryStorageCS.js +6 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +10 -5
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +72 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +76 -0
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +85 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +71 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +17 -2
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +81 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +61 -0
- package/cjs/storages/pluggable/index.js +46 -17
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +8 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +16 -59
- package/cjs/trackers/impressionsTracker.js +17 -15
- package/cjs/trackers/strategy/strategyNone.js +1 -1
- package/cjs/trackers/strategy/strategyOptimized.js +2 -1
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/trackers/uniqueKeysTracker.js +11 -42
- package/cjs/utils/constants/index.js +3 -2
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/index.js +0 -3
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +15 -16
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +16 -7
- package/esm/sdkManager/index.js +3 -11
- package/esm/services/splitApi.js +6 -6
- package/esm/storages/AbstractSplitsCacheAsync.js +8 -10
- package/esm/storages/AbstractSplitsCacheSync.js +8 -10
- package/esm/storages/KeyBuilderSS.js +50 -8
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/esm/storages/inLocalStorage/index.js +6 -2
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +8 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +7 -3
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +9 -5
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +68 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +73 -0
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +82 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +68 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +18 -3
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +78 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +58 -0
- package/esm/storages/pluggable/index.js +47 -18
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/esm/sync/submitters/telemetrySubmitter.js +9 -5
- package/esm/sync/submitters/uniqueKeysSubmitter.js +15 -56
- package/esm/trackers/impressionsTracker.js +17 -15
- package/esm/trackers/strategy/strategyNone.js +1 -1
- package/esm/trackers/strategy/strategyOptimized.js +2 -1
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/trackers/uniqueKeysTracker.js +11 -42
- package/esm/utils/constants/index.js +1 -0
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/index.js +0 -3
- package/package.json +1 -2
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/evaluator/index.ts +14 -15
- package/src/integrations/ga/GaToSplit.ts +9 -5
- package/src/integrations/types.ts +2 -1
- package/src/logger/.DS_Store +0 -0
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +17 -7
- package/src/sdkManager/index.ts +3 -12
- package/src/services/splitApi.ts +6 -6
- package/src/services/types.ts +2 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +13 -15
- package/src/storages/AbstractSplitsCacheSync.ts +15 -17
- package/src/storages/KeyBuilderSS.ts +61 -9
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -11
- package/src/storages/inLocalStorage/index.ts +5 -2
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +7 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -3
- package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +10 -6
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +80 -0
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +86 -0
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +95 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -2
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +77 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +15 -5
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +92 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -2
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +67 -0
- package/src/storages/pluggable/index.ts +51 -19
- package/src/storages/types.ts +38 -30
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
- package/src/sync/submitters/telemetrySubmitter.ts +15 -8
- package/src/sync/submitters/types.ts +26 -12
- package/src/sync/submitters/uniqueKeysSubmitter.ts +18 -61
- package/src/trackers/impressionsTracker.ts +16 -15
- package/src/trackers/strategy/strategyNone.ts +1 -1
- package/src/trackers/strategy/strategyOptimized.ts +1 -1
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +9 -7
- package/src/trackers/uniqueKeysTracker.ts +15 -47
- package/src/types.ts +0 -1
- package/src/utils/constants/index.ts +1 -0
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/index.ts +1 -4
- package/types/integrations/types.d.ts +2 -1
- package/types/services/types.d.ts +2 -2
- package/types/storages/AbstractSplitsCacheAsync.d.ts +7 -6
- package/types/storages/AbstractSplitsCacheSync.d.ts +6 -6
- package/types/storages/KeyBuilderSS.d.ts +9 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +3 -4
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -3
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +35 -0
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +16 -0
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +6 -5
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +21 -0
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +16 -0
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +6 -5
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +20 -0
- package/types/storages/types.d.ts +35 -35
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
- package/types/sync/submitters/telemetrySubmitter.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +19 -12
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +0 -14
- package/types/trackers/types.d.ts +9 -11
- package/types/trackers/uniqueKeysTracker.d.ts +3 -3
- package/types/types.d.ts +0 -1
- package/types/utils/constants/index.d.ts +1 -0
- package/types/utils/lang/maps.d.ts +6 -2
- package/types/utils/redis/RedisMock.d.ts +4 -0
- package/types/utils/settingsValidation/index.d.ts +0 -1
- 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/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- 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/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/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/utils/timeTracker/index.d.ts +0 -70
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
1.7.0 (September XXX, 2022)
|
|
2
|
+
- Updated SDK telemetry to support pluggable storage, partial consumer mode, and synchronizer.
|
|
3
|
+
- Updated storage implementations to improve the performance of split evaluations (i.e., `getTreatment(s)` method calls) when using the default storage in memory.
|
|
4
|
+
|
|
1
5
|
1.6.1 (July 22, 2022)
|
|
2
6
|
- Updated GoogleAnalyticsToSplit integration to validate `autoRequire` config parameter and avoid some wrong warning logs when mapping GA hit fields to Split event properties.
|
|
3
7
|
|
|
@@ -39,8 +39,8 @@ function createUserConsentAPI(params) {
|
|
|
39
39
|
if (events.clear)
|
|
40
40
|
events.clear(); // @ts-ignore
|
|
41
41
|
if (impressions.clear)
|
|
42
|
-
impressions.clear();
|
|
43
|
-
if (impressionCounts)
|
|
42
|
+
impressions.clear(); // @ts-ignore
|
|
43
|
+
if (impressionCounts && impressionCounts.clear)
|
|
44
44
|
impressionCounts.clear();
|
|
45
45
|
}
|
|
46
46
|
}
|
package/cjs/evaluator/index.js
CHANGED
|
@@ -19,63 +19,62 @@ function treatmentsException(splitNames) {
|
|
|
19
19
|
return evaluations;
|
|
20
20
|
}
|
|
21
21
|
function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
22
|
-
var
|
|
22
|
+
var parsedSplit;
|
|
23
23
|
try {
|
|
24
|
-
|
|
24
|
+
parsedSplit = storage.splits.getSplit(splitName);
|
|
25
25
|
}
|
|
26
26
|
catch (e) {
|
|
27
27
|
// Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
|
|
28
28
|
return treatmentException;
|
|
29
29
|
}
|
|
30
|
-
if ((0, thenable_1.thenable)(
|
|
31
|
-
return
|
|
30
|
+
if ((0, thenable_1.thenable)(parsedSplit)) {
|
|
31
|
+
return parsedSplit.then(function (split) { return getEvaluation(log, split, key, attributes, storage); }).catch(
|
|
32
32
|
// Exception on async `getSplit` storage. For example, when the storage is redis or
|
|
33
33
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
34
34
|
function () { return treatmentException; });
|
|
35
35
|
}
|
|
36
|
-
return getEvaluation(log,
|
|
36
|
+
return getEvaluation(log, parsedSplit, key, attributes, storage);
|
|
37
37
|
}
|
|
38
38
|
exports.evaluateFeature = evaluateFeature;
|
|
39
39
|
function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
40
|
-
var
|
|
40
|
+
var parsedSplits;
|
|
41
41
|
try {
|
|
42
|
-
|
|
42
|
+
parsedSplits = storage.splits.getSplits(splitNames);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
45
|
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
|
|
46
46
|
return treatmentsException(splitNames);
|
|
47
47
|
}
|
|
48
|
-
return (
|
|
49
|
-
|
|
48
|
+
return (0, thenable_1.thenable)(parsedSplits) ?
|
|
49
|
+
parsedSplits.then(function (splits) { return getEvaluations(log, splitNames, splits, key, attributes, storage); })
|
|
50
50
|
.catch(function () {
|
|
51
51
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
52
52
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
53
53
|
return treatmentsException(splitNames);
|
|
54
54
|
}) :
|
|
55
|
-
getEvaluations(log, splitNames,
|
|
55
|
+
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
56
56
|
}
|
|
57
57
|
exports.evaluateFeatures = evaluateFeatures;
|
|
58
|
-
function getEvaluation(log,
|
|
58
|
+
function getEvaluation(log, splitJSON, key, attributes, storage) {
|
|
59
59
|
var evaluation = {
|
|
60
60
|
treatment: constants_1.CONTROL,
|
|
61
61
|
label: LabelsConstants.SPLIT_NOT_FOUND,
|
|
62
62
|
config: null
|
|
63
63
|
};
|
|
64
|
-
if (
|
|
65
|
-
var
|
|
66
|
-
var split_1 = Engine_1.Engine.parse(log, splitJSON_1, storage);
|
|
64
|
+
if (splitJSON) {
|
|
65
|
+
var split_1 = Engine_1.Engine.parse(log, splitJSON, storage);
|
|
67
66
|
evaluation = split_1.getTreatment(key, attributes, evaluateFeature);
|
|
68
67
|
// If the storage is async and the evaluated split uses segment, evaluation is thenable
|
|
69
68
|
if ((0, thenable_1.thenable)(evaluation)) {
|
|
70
69
|
return evaluation.then(function (result) {
|
|
71
70
|
result.changeNumber = split_1.getChangeNumber();
|
|
72
|
-
result.config =
|
|
71
|
+
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
73
72
|
return result;
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
else {
|
|
77
76
|
evaluation.changeNumber = split_1.getChangeNumber(); // Always sync and optional
|
|
78
|
-
evaluation.config =
|
|
77
|
+
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
return evaluation;
|
|
@@ -16,7 +16,7 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
16
16
|
* @param log Logger instance.
|
|
17
17
|
* @param autoRequire If true, log error when auto-require script is not detected
|
|
18
18
|
*/
|
|
19
|
-
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire) {
|
|
19
|
+
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire, telemetryTracker) {
|
|
20
20
|
// get reference to global command queue. Init it if not defined yet.
|
|
21
21
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
22
22
|
window[gaAlias] = window[gaAlias] || function () {
|
|
@@ -24,10 +24,13 @@ function providePlugin(window, pluginName, pluginConstructor, log, autoRequire)
|
|
|
24
24
|
};
|
|
25
25
|
// provides the plugin for use with analytics.js.
|
|
26
26
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
var hasAutoRequire = window[gaAlias].q && window[gaAlias].q.push !== [].push;
|
|
28
|
+
if (autoRequire && !hasAutoRequire) { // Expecting spy on ga.q push method but not found
|
|
29
29
|
log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run. Please check the docs.');
|
|
30
30
|
}
|
|
31
|
+
if (telemetryTracker && hasAutoRequire) {
|
|
32
|
+
telemetryTracker.addTag('integration:ga-autorequire');
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
33
36
|
var defaultMapping = {
|
|
@@ -163,7 +166,7 @@ exports.fixEventTypeId = fixEventTypeId;
|
|
|
163
166
|
* @param {object} log factory logger
|
|
164
167
|
*/
|
|
165
168
|
function GaToSplit(sdkOptions, params) {
|
|
166
|
-
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log;
|
|
169
|
+
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log, telemetryTracker = params.telemetryTracker;
|
|
167
170
|
var defaultOptions = {
|
|
168
171
|
prefix: exports.defaultPrefix,
|
|
169
172
|
// We set default identities if key and TT are present in settings.core
|
|
@@ -249,6 +252,6 @@ function GaToSplit(sdkOptions, params) {
|
|
|
249
252
|
return SplitTracker;
|
|
250
253
|
}());
|
|
251
254
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
252
|
-
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true);
|
|
255
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
|
|
253
256
|
}
|
|
254
257
|
exports.GaToSplit = GaToSplit;
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -9,6 +9,15 @@ var trafficTypeExistance_1 = require("../utils/inputValidation/trafficTypeExista
|
|
|
9
9
|
var labels_1 = require("../utils/labels");
|
|
10
10
|
var constants_1 = require("../utils/constants");
|
|
11
11
|
var constants_2 = require("../logger/constants");
|
|
12
|
+
var utils_1 = require("../trackers/impressionObserver/utils");
|
|
13
|
+
var treatmentNotReady = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
|
|
14
|
+
function treatmentsNotReady(splitNames) {
|
|
15
|
+
var evaluations = {};
|
|
16
|
+
splitNames.forEach(function (splitName) {
|
|
17
|
+
evaluations[splitName] = treatmentNotReady;
|
|
18
|
+
});
|
|
19
|
+
return evaluations;
|
|
20
|
+
}
|
|
12
21
|
/**
|
|
13
22
|
* Creator of base client with getTreatments and track methods.
|
|
14
23
|
*/
|
|
@@ -25,7 +34,11 @@ function clientFactory(params) {
|
|
|
25
34
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
26
35
|
return treatment;
|
|
27
36
|
};
|
|
28
|
-
var evaluation = (
|
|
37
|
+
var evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
38
|
+
(0, evaluator_1.evaluateFeature)(log, key, splitName, attributes, storage) :
|
|
39
|
+
(0, utils_1.isStorageSync)(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
40
|
+
treatmentNotReady :
|
|
41
|
+
Promise.resolve(treatmentNotReady); // Promisify if async
|
|
29
42
|
return (0, thenable_1.thenable)(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
|
|
30
43
|
}
|
|
31
44
|
function getTreatmentWithConfig(key, splitName, attributes) {
|
|
@@ -44,7 +57,11 @@ function clientFactory(params) {
|
|
|
44
57
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
45
58
|
return treatments;
|
|
46
59
|
};
|
|
47
|
-
var evaluations = (
|
|
60
|
+
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
61
|
+
(0, evaluator_1.evaluateFeatures)(log, key, splitNames, attributes, storage) :
|
|
62
|
+
(0, utils_1.isStorageSync)(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
63
|
+
treatmentsNotReady(splitNames) :
|
|
64
|
+
Promise.resolve(treatmentsNotReady(splitNames)); // Promisify if async
|
|
48
65
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
49
66
|
}
|
|
50
67
|
function getTreatmentsWithConfig(key, splitNames, attributes) {
|
|
@@ -52,13 +69,8 @@ function clientFactory(params) {
|
|
|
52
69
|
}
|
|
53
70
|
// Internal function
|
|
54
71
|
function processEvaluation(evaluation, splitName, key, attributes, withConfig, invokingMethodName, queue) {
|
|
55
|
-
var isSdkReady = readinessManager.isReady() || readinessManager.isReadyFromCache();
|
|
56
72
|
var matchingKey = (0, key_1.getMatching)(key);
|
|
57
73
|
var bucketingKey = (0, key_1.getBucketing)(key);
|
|
58
|
-
// If the SDK was not ready, treatment may be incorrect due to having Splits but not segments data.
|
|
59
|
-
if (!isSdkReady) {
|
|
60
|
-
evaluation = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
|
|
61
|
-
}
|
|
62
74
|
var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a;
|
|
63
75
|
log.info(constants_2.IMPRESSION, [splitName, matchingKey, treatment, label]);
|
|
64
76
|
if ((0, splitExistance_1.validateSplitExistance)(log, readinessManager, splitName, label, invokingMethodName)) {
|
|
@@ -9,7 +9,7 @@ var clientInputValidation_1 = require("./clientInputValidation");
|
|
|
9
9
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
10
10
|
*/
|
|
11
11
|
function sdkClientFactory(params, isSharedClient) {
|
|
12
|
-
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker;
|
|
12
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker, uniqueKeysTracker = params.uniqueKeysTracker;
|
|
13
13
|
return (0, objectAssign_1.objectAssign)(
|
|
14
14
|
// Proto-linkage of the readiness Event Emitter
|
|
15
15
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
@@ -31,6 +31,8 @@ function sdkClientFactory(params, isSharedClient) {
|
|
|
31
31
|
// Release the API Key if it is the main client
|
|
32
32
|
if (!isSharedClient)
|
|
33
33
|
(0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
|
|
34
|
+
if (uniqueKeysTracker)
|
|
35
|
+
uniqueKeysTracker.stop();
|
|
34
36
|
// Cleanup storage
|
|
35
37
|
return storage.destroy();
|
|
36
38
|
});
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -24,7 +24,6 @@ var constants_3 = require("../utils/constants");
|
|
|
24
24
|
function sdkFactory(params) {
|
|
25
25
|
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory, filterAdapterFactory = params.filterAdapterFactory;
|
|
26
26
|
var log = settings.log;
|
|
27
|
-
var impressionsMode = settings.sync.impressionsMode;
|
|
28
27
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
29
28
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
30
29
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
@@ -41,6 +40,7 @@ function sdkFactory(params) {
|
|
|
41
40
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
42
41
|
// ATM, only used by PluggableStorage
|
|
43
42
|
mode: settings.mode,
|
|
43
|
+
impressionsMode: settings.sync.impressionsMode,
|
|
44
44
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
45
45
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
46
46
|
onReadyCb: function (error) {
|
|
@@ -54,14 +54,23 @@ function sdkFactory(params) {
|
|
|
54
54
|
};
|
|
55
55
|
var storage = storageFactory(storageFactoryParams);
|
|
56
56
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
57
|
-
var
|
|
57
|
+
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
58
|
+
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
58
59
|
var observer = impressionsObserverFactory();
|
|
59
|
-
var uniqueKeysTracker = impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
60
|
-
var strategy
|
|
61
|
-
|
|
60
|
+
var uniqueKeysTracker = storageFactoryParams.impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
61
|
+
var strategy;
|
|
62
|
+
switch (storageFactoryParams.impressionsMode) {
|
|
63
|
+
case constants_3.OPTIMIZED:
|
|
64
|
+
strategy = (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts);
|
|
65
|
+
break;
|
|
66
|
+
case constants_3.NONE:
|
|
67
|
+
strategy = (0, strategyNone_1.strategyNoneFactory)(storage.impressionCounts, uniqueKeysTracker);
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
strategy = (0, strategyDebug_1.strategyDebugFactory)(observer);
|
|
71
|
+
}
|
|
62
72
|
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
63
73
|
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager, storage.telemetry);
|
|
64
|
-
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
65
74
|
// splitApi is used by SyncManager and Browser signal listener
|
|
66
75
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
67
76
|
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
package/cjs/sdkManager/index.js
CHANGED
|
@@ -15,15 +15,7 @@ function collectTreatments(splitObject) {
|
|
|
15
15
|
// Then extract the treatments from the partitions
|
|
16
16
|
return allTreatmentsCondition ? allTreatmentsCondition.partitions.map(function (v) { return v.treatment; }) : [];
|
|
17
17
|
}
|
|
18
|
-
function objectToView(
|
|
19
|
-
var splitObject;
|
|
20
|
-
try {
|
|
21
|
-
// @ts-expect-error
|
|
22
|
-
splitObject = JSON.parse(json);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
18
|
+
function objectToView(splitObject) {
|
|
27
19
|
if (!splitObject)
|
|
28
20
|
return null;
|
|
29
21
|
return {
|
|
@@ -35,9 +27,9 @@ function objectToView(json) {
|
|
|
35
27
|
configs: splitObject.configurations || {}
|
|
36
28
|
};
|
|
37
29
|
}
|
|
38
|
-
function objectsToViews(
|
|
30
|
+
function objectsToViews(splitObjects) {
|
|
39
31
|
var views = [];
|
|
40
|
-
|
|
32
|
+
splitObjects.forEach(function (split) {
|
|
41
33
|
var view = objectToView(split);
|
|
42
34
|
if (view)
|
|
43
35
|
views.push(view);
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -97,7 +97,7 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
97
97
|
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
98
98
|
*/
|
|
99
99
|
postUniqueKeysBulkCs: function (body, headers) {
|
|
100
|
-
var url = urls.telemetry + "/
|
|
100
|
+
var url = urls.telemetry + "/v1/keys/cs";
|
|
101
101
|
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
|
|
102
102
|
},
|
|
103
103
|
/**
|
|
@@ -107,16 +107,16 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
107
107
|
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
108
108
|
*/
|
|
109
109
|
postUniqueKeysBulkSs: function (body, headers) {
|
|
110
|
-
var url = urls.telemetry + "/
|
|
110
|
+
var url = urls.telemetry + "/v1/keys/ss";
|
|
111
111
|
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
|
|
112
112
|
},
|
|
113
|
-
postMetricsConfig: function (body) {
|
|
113
|
+
postMetricsConfig: function (body, headers) {
|
|
114
114
|
var url = urls.telemetry + "/v1/metrics/config";
|
|
115
|
-
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
115
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
116
116
|
},
|
|
117
|
-
postMetricsUsage: function (body) {
|
|
117
|
+
postMetricsUsage: function (body, headers) {
|
|
118
118
|
var url = urls.telemetry + "/v1/metrics/usage";
|
|
119
|
-
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
119
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
122
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractSplitsCacheAsync = void 0;
|
|
4
|
+
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
4
5
|
/**
|
|
5
6
|
* This class provides a skeletal implementation of the ISplitsCacheAsync interface
|
|
6
7
|
* to minimize the effort required to implement this interface.
|
|
@@ -27,22 +28,19 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
27
28
|
* @param {string} name
|
|
28
29
|
* @param {string} defaultTreatment
|
|
29
30
|
* @param {number} changeNumber
|
|
30
|
-
* @returns {Promise} a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the
|
|
31
|
+
* @returns {Promise} a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the operation successed updating the split or `false` if no split is updated,
|
|
31
32
|
* for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
|
|
32
33
|
* The promise will never be rejected.
|
|
33
34
|
*/
|
|
34
35
|
AbstractSplitsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
35
36
|
var _this = this;
|
|
36
37
|
return this.getSplit(name).then(function (split) {
|
|
37
|
-
if (split) {
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
44
|
-
return _this.addSplit(name, newSplit);
|
|
45
|
-
}
|
|
38
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
39
|
+
var newSplit = (0, objectAssign_1.objectAssign)({}, split);
|
|
40
|
+
newSplit.killed = true;
|
|
41
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
42
|
+
newSplit.changeNumber = changeNumber;
|
|
43
|
+
return _this.addSplit(name, newSplit);
|
|
46
44
|
}
|
|
47
45
|
return false;
|
|
48
46
|
}).catch(function () { return false; });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usesSegments = exports.AbstractSplitsCacheSync = void 0;
|
|
4
|
+
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
4
5
|
/**
|
|
5
6
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
6
7
|
* to minimize the effort required to implement this interface.
|
|
@@ -42,20 +43,17 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
42
43
|
* @param {string} name
|
|
43
44
|
* @param {string} defaultTreatment
|
|
44
45
|
* @param {number} changeNumber
|
|
45
|
-
* @returns {
|
|
46
|
+
* @returns {boolean} `true` if the operation successed updating the split, or `false` if no split is updated,
|
|
46
47
|
* for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
|
|
47
48
|
*/
|
|
48
49
|
AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
49
50
|
var split = this.getSplit(name);
|
|
50
|
-
if (split) {
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
57
|
-
return this.addSplit(name, newSplit);
|
|
58
|
-
}
|
|
51
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
52
|
+
var newSplit = (0, objectAssign_1.objectAssign)({}, split);
|
|
53
|
+
newSplit.killed = true;
|
|
54
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
55
|
+
newSplit.changeNumber = changeNumber;
|
|
56
|
+
return this.addSplit(name, newSplit);
|
|
59
57
|
}
|
|
60
58
|
return false;
|
|
61
59
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyBuilderSS = void 0;
|
|
3
|
+
exports.parseLatencyField = exports.parseExceptionField = exports.parseMetadata = exports.KeyBuilderSS = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var KeyBuilder_1 = require("./KeyBuilder");
|
|
6
|
-
var
|
|
6
|
+
var TelemetryCacheInMemory_1 = require("./inMemory/TelemetryCacheInMemory");
|
|
7
|
+
var METHOD_NAMES = {
|
|
7
8
|
t: 'treatment',
|
|
8
9
|
ts: 'treatments',
|
|
9
10
|
tc: 'treatmentWithConfig',
|
|
@@ -14,7 +15,10 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
14
15
|
(0, tslib_1.__extends)(KeyBuilderSS, _super);
|
|
15
16
|
function KeyBuilderSS(prefix, metadata) {
|
|
16
17
|
var _this = _super.call(this, prefix) || this;
|
|
17
|
-
_this.
|
|
18
|
+
_this.latencyPrefix = _this.prefix + ".telemetry.latencies";
|
|
19
|
+
_this.exceptionPrefix = _this.prefix + ".telemetry.exceptions";
|
|
20
|
+
_this.initPrefix = _this.prefix + ".telemetry.init";
|
|
21
|
+
_this.versionablePrefix = metadata.s + "/" + metadata.n + "/" + metadata.i;
|
|
18
22
|
return _this;
|
|
19
23
|
}
|
|
20
24
|
KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
|
|
@@ -23,6 +27,12 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
23
27
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
24
28
|
return this.prefix + ".impressions";
|
|
25
29
|
};
|
|
30
|
+
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
31
|
+
return this.prefix + ".impressions.count";
|
|
32
|
+
};
|
|
33
|
+
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
34
|
+
return this.prefix + ".uniquekeys";
|
|
35
|
+
};
|
|
26
36
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
27
37
|
return this.prefix + ".events";
|
|
28
38
|
};
|
|
@@ -31,17 +41,52 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
31
41
|
};
|
|
32
42
|
/* Telemetry keys */
|
|
33
43
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
34
|
-
return this.
|
|
44
|
+
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
|
|
35
45
|
};
|
|
36
46
|
KeyBuilderSS.prototype.buildExceptionKey = function (method) {
|
|
37
|
-
return this.
|
|
47
|
+
return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method];
|
|
38
48
|
};
|
|
39
49
|
KeyBuilderSS.prototype.buildInitKey = function () {
|
|
40
|
-
return this.
|
|
41
|
-
};
|
|
42
|
-
KeyBuilderSS.prototype.buildVersionablePrefix = function () {
|
|
43
|
-
return this.metadata.s + "/" + this.metadata.n + "/" + this.metadata.i;
|
|
50
|
+
return this.initPrefix + "::" + this.versionablePrefix;
|
|
44
51
|
};
|
|
45
52
|
return KeyBuilderSS;
|
|
46
53
|
}(KeyBuilder_1.KeyBuilder));
|
|
47
54
|
exports.KeyBuilderSS = KeyBuilderSS;
|
|
55
|
+
// Used by consumer methods of TelemetryCacheInRedis and TelemetryCachePluggable
|
|
56
|
+
var REVERSE_METHOD_NAMES = Object.keys(METHOD_NAMES).reduce(function (acc, key) {
|
|
57
|
+
acc[METHOD_NAMES[key]] = key;
|
|
58
|
+
return acc;
|
|
59
|
+
}, {});
|
|
60
|
+
function parseMetadata(field) {
|
|
61
|
+
var parts = field.split('/');
|
|
62
|
+
if (parts.length !== 3)
|
|
63
|
+
return "invalid subsection count. Expected 3, got: " + parts.length;
|
|
64
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
|
|
65
|
+
return [JSON.stringify({ s: s, n: n, i: i })];
|
|
66
|
+
}
|
|
67
|
+
exports.parseMetadata = parseMetadata;
|
|
68
|
+
function parseExceptionField(field) {
|
|
69
|
+
var parts = field.split('/');
|
|
70
|
+
if (parts.length !== 4)
|
|
71
|
+
return "invalid subsection count. Expected 4, got: " + parts.length;
|
|
72
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
|
|
73
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
74
|
+
if (!method)
|
|
75
|
+
return "unknown method '" + m + "'";
|
|
76
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method];
|
|
77
|
+
}
|
|
78
|
+
exports.parseExceptionField = parseExceptionField;
|
|
79
|
+
function parseLatencyField(field) {
|
|
80
|
+
var parts = field.split('/');
|
|
81
|
+
if (parts.length !== 5)
|
|
82
|
+
return "invalid subsection count. Expected 5, got: " + parts.length;
|
|
83
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
|
|
84
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
85
|
+
if (!method)
|
|
86
|
+
return "unknown method '" + m + "'";
|
|
87
|
+
var bucket = parseInt(b);
|
|
88
|
+
if (isNaN(bucket) || bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT)
|
|
89
|
+
return "invalid bucket. Expected a number between 0 and " + (TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT - 1) + ", got: " + b;
|
|
90
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
|
|
91
|
+
}
|
|
92
|
+
exports.parseLatencyField = parseLatencyField;
|
|
@@ -35,7 +35,7 @@ function dataLoaderFactory(preloadedData) {
|
|
|
35
35
|
storage.splits.clear();
|
|
36
36
|
storage.splits.setChangeNumber(since);
|
|
37
37
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
38
|
-
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return
|
|
38
|
+
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
|
|
39
39
|
// add mySegments data
|
|
40
40
|
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
41
41
|
if (!mySegmentsData) {
|
|
@@ -96,9 +96,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
96
96
|
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
97
97
|
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
98
98
|
this._decrementCounts(previousSplit);
|
|
99
|
-
localStorage.setItem(splitKey, split);
|
|
100
|
-
|
|
101
|
-
this._incrementCounts(parsedSplit);
|
|
99
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
100
|
+
this._incrementCounts(split);
|
|
102
101
|
return true;
|
|
103
102
|
}
|
|
104
103
|
catch (e) {
|
|
@@ -110,8 +109,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
110
109
|
try {
|
|
111
110
|
var split = this.getSplit(name);
|
|
112
111
|
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
113
|
-
|
|
114
|
-
this._decrementCounts(parsedSplit);
|
|
112
|
+
this._decrementCounts(split);
|
|
115
113
|
return true;
|
|
116
114
|
}
|
|
117
115
|
catch (e) {
|
|
@@ -120,7 +118,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
120
118
|
}
|
|
121
119
|
};
|
|
122
120
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
123
|
-
|
|
121
|
+
var item = localStorage.getItem(this.keys.buildSplitKey(name));
|
|
122
|
+
return item && JSON.parse(item);
|
|
124
123
|
};
|
|
125
124
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
126
125
|
// when cache is ready but using a new split query, we must clear all split data
|
|
@@ -204,7 +203,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
204
203
|
};
|
|
205
204
|
/**
|
|
206
205
|
* Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
207
|
-
* Clean operation (clear) also updates `lastUpdated` timestamp with current time.
|
|
208
206
|
*
|
|
209
207
|
* @param {number | undefined} expirationTimestamp if the value is not a number, data will not be cleaned
|
|
210
208
|
*/
|
|
@@ -16,6 +16,7 @@ var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
|
|
|
16
16
|
var constants_1 = require("./constants");
|
|
17
17
|
var constants_2 = require("../../utils/constants");
|
|
18
18
|
var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
|
|
19
|
+
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
19
20
|
/**
|
|
20
21
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
21
22
|
*/
|
|
@@ -37,13 +38,16 @@ function InLocalStorage(options) {
|
|
|
37
38
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
38
39
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
39
40
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
40
|
-
telemetry:
|
|
41
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
42
|
+
uniqueKeys: params.impressionsMode === constants_2.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
41
43
|
destroy: function () {
|
|
44
|
+
var _a;
|
|
42
45
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
43
46
|
this.segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
44
47
|
this.impressions.clear();
|
|
45
48
|
this.impressionCounts && this.impressionCounts.clear();
|
|
46
49
|
this.events.clear();
|
|
50
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
47
51
|
},
|
|
48
52
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
49
53
|
shared: function (matchingKey) {
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImpressionCountsCacheInMemory = void 0;
|
|
4
4
|
var time_1 = require("../../utils/time");
|
|
5
|
+
var constants_1 = require("../inRedis/constants");
|
|
5
6
|
var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
6
|
-
function ImpressionCountsCacheInMemory() {
|
|
7
|
+
function ImpressionCountsCacheInMemory(impressionCountsCacheSize) {
|
|
8
|
+
if (impressionCountsCacheSize === void 0) { impressionCountsCacheSize = constants_1.DEFAULT_CACHE_SIZE; }
|
|
7
9
|
this.cache = {};
|
|
10
|
+
this.cacheSize = 0;
|
|
11
|
+
this.maxStorage = impressionCountsCacheSize;
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
@@ -19,6 +23,13 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
19
23
|
var key = this._makeKey(featureName, timeFrame);
|
|
20
24
|
var currentAmount = this.cache[key];
|
|
21
25
|
this.cache[key] = currentAmount ? currentAmount + amount : amount;
|
|
26
|
+
if (this.onFullQueue) {
|
|
27
|
+
this.cacheSize = this.cacheSize + amount;
|
|
28
|
+
if (this.cacheSize >= this.maxStorage) {
|
|
29
|
+
this.onFullQueue();
|
|
30
|
+
this.cacheSize = 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
};
|
|
23
34
|
/**
|
|
24
35
|
* Pop the collected data, used as payload for posting.
|
|
@@ -8,6 +8,7 @@ var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
|
|
|
8
8
|
var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
|
+
var UniqueKeysCacheInMemory_1 = require("./UniqueKeysCacheInMemory");
|
|
11
12
|
/**
|
|
12
13
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
13
14
|
*
|
|
@@ -18,16 +19,19 @@ function InMemoryStorageFactory(params) {
|
|
|
18
19
|
splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
|
|
19
20
|
segments: new SegmentsCacheInMemory_1.SegmentsCacheInMemory(),
|
|
20
21
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
21
|
-
impressionCounts: params.
|
|
22
|
+
impressionCounts: params.impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
22
23
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
23
|
-
telemetry:
|
|
24
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
|
|
25
|
+
uniqueKeys: params.impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : undefined,
|
|
24
26
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
25
27
|
destroy: function () {
|
|
28
|
+
var _a;
|
|
26
29
|
this.splits.clear();
|
|
27
30
|
this.segments.clear();
|
|
28
31
|
this.impressions.clear();
|
|
29
32
|
this.impressionCounts && this.impressionCounts.clear();
|
|
30
33
|
this.events.clear();
|
|
34
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
31
35
|
}
|
|
32
36
|
};
|
|
33
37
|
}
|