@splitsoftware/splitio-commons 1.6.2-rc.8 → 1.7.0
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 -1
- package/cjs/evaluator/index.js +5 -5
- package/cjs/listeners/browser.js +9 -11
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkFactory/index.js +7 -25
- package/cjs/services/splitApi.js +4 -4
- package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/KeyBuilderSS.js +9 -9
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
- package/cjs/storages/inLocalStorage/index.js +15 -11
- package/cjs/storages/inMemory/InMemoryStorage.js +11 -8
- package/cjs/storages/inMemory/InMemoryStorageCS.js +11 -8
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +65 -37
- package/cjs/storages/inMemory/{uniqueKeysCacheInMemory.js → UniqueKeysCacheInMemory.js} +24 -25
- package/cjs/storages/inMemory/{uniqueKeysCacheInMemoryCS.js → UniqueKeysCacheInMemoryCS.js} +10 -12
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +37 -2
- package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/{uniqueKeysCacheInRedis.js → UniqueKeysCacheInRedis.js} +16 -4
- package/cjs/storages/inRedis/index.js +6 -4
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +81 -0
- package/cjs/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +61 -0
- package/cjs/storages/pluggable/inMemoryWrapper.js +8 -6
- package/cjs/storages/pluggable/index.js +51 -18
- package/cjs/storages/utils.js +73 -0
- package/cjs/sync/submitters/submitterManager.js +1 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +4 -37
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +4 -3
- package/cjs/trackers/impressionObserver/utils.js +1 -17
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/index.js +7 -4
- package/esm/evaluator/index.js +5 -5
- package/esm/listeners/browser.js +9 -11
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkFactory/index.js +7 -25
- package/esm/services/splitApi.js +4 -4
- package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/KeyBuilderSS.js +8 -8
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
- package/esm/storages/inLocalStorage/index.js +16 -12
- package/esm/storages/inMemory/InMemoryStorage.js +13 -10
- package/esm/storages/inMemory/InMemoryStorageCS.js +12 -9
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +64 -37
- package/esm/storages/inMemory/{uniqueKeysCacheInMemory.js → UniqueKeysCacheInMemory.js} +22 -24
- package/esm/storages/inMemory/{uniqueKeysCacheInMemoryCS.js → UniqueKeysCacheInMemoryCS.js} +10 -12
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +37 -2
- package/esm/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/{uniqueKeysCacheInRedis.js → UniqueKeysCacheInRedis.js} +15 -3
- package/esm/storages/inRedis/index.js +5 -3
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +78 -0
- package/esm/storages/pluggable/ImpressionsCachePluggable.js +2 -19
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +58 -0
- package/esm/storages/pluggable/inMemoryWrapper.js +8 -6
- package/esm/storages/pluggable/index.js +52 -19
- package/esm/storages/utils.js +65 -0
- package/esm/sync/submitters/submitterManager.js +1 -1
- package/esm/sync/submitters/telemetrySubmitter.js +4 -36
- package/esm/sync/submitters/uniqueKeysSubmitter.js +4 -3
- package/esm/trackers/impressionObserver/utils.js +1 -15
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/index.js +7 -4
- package/package.json +2 -2
- package/src/consent/sdkUserConsent.ts +1 -1
- package/src/evaluator/index.ts +6 -6
- package/src/listeners/browser.ts +9 -13
- package/src/logger/.DS_Store +0 -0
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +1 -1
- package/src/sdkFactory/index.ts +10 -33
- package/src/sdkFactory/types.ts +2 -2
- package/src/services/splitApi.ts +6 -6
- package/src/services/types.ts +2 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/KeyBuilderSS.ts +13 -11
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -1
- package/src/storages/inLocalStorage/index.ts +17 -12
- package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -7
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/InMemoryStorage.ts +14 -10
- package/src/storages/inMemory/InMemoryStorageCS.ts +13 -10
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +72 -35
- package/src/storages/inMemory/{uniqueKeysCacheInMemory.ts → UniqueKeysCacheInMemory.ts} +26 -28
- package/src/storages/inMemory/{uniqueKeysCacheInMemoryCS.ts → UniqueKeysCacheInMemoryCS.ts} +15 -17
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +51 -8
- package/src/storages/inRedis/ImpressionsCacheInRedis.ts +2 -22
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -1
- package/src/storages/inRedis/{uniqueKeysCacheInRedis.ts → UniqueKeysCacheInRedis.ts} +25 -12
- package/src/storages/inRedis/index.ts +6 -3
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +92 -0
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -23
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -1
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +67 -0
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -6
- package/src/storages/pluggable/index.ts +56 -20
- package/src/storages/types.ts +53 -70
- package/src/storages/utils.ts +78 -0
- package/src/sync/submitters/submitter.ts +2 -2
- package/src/sync/submitters/submitterManager.ts +1 -1
- package/src/sync/submitters/telemetrySubmitter.ts +9 -39
- package/src/sync/submitters/types.ts +33 -17
- package/src/sync/submitters/uniqueKeysSubmitter.ts +6 -5
- package/src/trackers/impressionObserver/utils.ts +1 -16
- package/src/trackers/impressionsTracker.ts +2 -2
- package/src/trackers/strategy/strategyDebug.ts +4 -4
- package/src/trackers/strategy/strategyNone.ts +9 -9
- package/src/trackers/strategy/strategyOptimized.ts +9 -9
- package/src/trackers/uniqueKeysTracker.ts +6 -6
- package/src/types.ts +0 -2
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/index.ts +5 -5
- package/types/services/types.d.ts +2 -2
- package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
- package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
- package/types/storages/KeyBuilderSS.d.ts +5 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +0 -1
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +23 -9
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +9 -9
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +2 -4
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +3 -1
- package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +0 -1
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +8 -2
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +16 -0
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +1 -2
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +20 -0
- package/types/storages/types.d.ts +42 -49
- package/types/storages/utils.d.ts +8 -0
- package/types/sync/submitters/submitter.d.ts +2 -2
- package/types/sync/submitters/telemetrySubmitter.d.ts +2 -10
- package/types/sync/submitters/types.d.ts +27 -18
- package/types/trackers/impressionObserver/utils.d.ts +0 -8
- package/types/trackers/strategy/strategyNone.d.ts +2 -2
- package/types/trackers/strategy/strategyOptimized.d.ts +2 -2
- package/types/trackers/uniqueKeysTracker.d.ts +1 -1
- package/types/types.d.ts +0 -2
- 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/cjs/storages/metadataBuilder.js +0 -12
- package/esm/storages/metadataBuilder.js +0 -8
- package/src/storages/metadataBuilder.ts +0 -11
- 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/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/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/utils/timeTracker/index.d.ts +0 -70
package/CHANGES.txt
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.7.0 (October 4, 2022)
|
|
2
|
+
- Added a new impressions mode for the SDK called NONE, to be used in factory when there is no desire to capture impressions on an SDK factory to feed Split's analytics engine. Running NONE mode, the SDK will only capture unique keys evaluated for a particular feature flag instead of full blown impressions.
|
|
3
|
+
- Updated SDK telemetry to support pluggable storage, partial consumer mode, and synchronizer.
|
|
2
4
|
- Updated storage implementations to improve the performance of split evaluations (i.e., `getTreatment(s)` method calls) when using the default storage in memory.
|
|
5
|
+
- Updated evaluation flow to avoid unnecessarily storage calls when the SDK is not ready.
|
|
3
6
|
|
|
4
7
|
1.6.1 (July 22, 2022)
|
|
5
8
|
- Updated GoogleAnalyticsToSplit integration to validate `autoRequire` config parameter and avoid some wrong warning logs when mapping GA hit fields to Split event properties.
|
package/cjs/evaluator/index.js
CHANGED
|
@@ -19,21 +19,21 @@ 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) {
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -7,7 +7,6 @@ var constants_1 = require("../utils/constants");
|
|
|
7
7
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
8
8
|
var constants_2 = require("../logger/constants");
|
|
9
9
|
var consent_1 = require("../consent");
|
|
10
|
-
var telemetrySubmitter_1 = require("../sync/submitters/telemetrySubmitter");
|
|
11
10
|
var VISIBILITYCHANGE_EVENT = 'visibilitychange';
|
|
12
11
|
var PAGEHIDE_EVENT = 'pagehide';
|
|
13
12
|
var UNLOAD_EVENT = 'unload';
|
|
@@ -71,25 +70,25 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
71
70
|
BrowserSignalListener.prototype.flushData = function () {
|
|
72
71
|
if (!this.syncManager)
|
|
73
72
|
return; // In consumer mode there is not sync manager and data to flush
|
|
73
|
+
var _a = this.settings.urls, events = _a.events, telemetry = _a.telemetry;
|
|
74
74
|
// Flush impressions & events data if there is user consent
|
|
75
75
|
if ((0, consent_1.isConsentGranted)(this.settings)) {
|
|
76
|
-
var eventsUrl = this.settings.urls.events;
|
|
77
76
|
var sim = this.settings.sync.impressionsMode;
|
|
78
77
|
var extraMetadata = {
|
|
79
78
|
// sim stands for Sync/Split Impressions Mode
|
|
80
79
|
sim: sim === constants_1.OPTIMIZED ? constants_1.OPTIMIZED : sim === constants_1.DEBUG ? constants_1.DEBUG : constants_1.NONE
|
|
81
80
|
};
|
|
82
|
-
this._flushData(
|
|
83
|
-
this._flushData(
|
|
81
|
+
this._flushData(events + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
82
|
+
this._flushData(events + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
|
84
83
|
if (this.storage.impressionCounts)
|
|
85
|
-
this._flushData(
|
|
84
|
+
this._flushData(events + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, impressionCountsSubmitter_1.fromImpressionCountsCollector);
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
if (this.storage.uniqueKeys)
|
|
87
|
+
this._flushData(telemetry + '/v1/keys/cs/beacon', this.storage.uniqueKeys, this.serviceApi.postUniqueKeysBulkCs);
|
|
86
88
|
}
|
|
87
89
|
// Flush telemetry data
|
|
88
|
-
if (this.storage.telemetry)
|
|
89
|
-
|
|
90
|
-
var telemetryCacheAdapter = (0, telemetrySubmitter_1.telemetryCacheStatsAdapter)(this.storage.telemetry, this.storage.splits, this.storage.segments);
|
|
91
|
-
this._flushData(telemetryUrl + '/v1/metrics/usage/beacon', telemetryCacheAdapter, this.serviceApi.postMetricsUsage);
|
|
92
|
-
}
|
|
90
|
+
if (this.storage.telemetry)
|
|
91
|
+
this._flushData(telemetry + '/v1/metrics/usage/beacon', this.storage.telemetry, this.serviceApi.postMetricsUsage);
|
|
93
92
|
};
|
|
94
93
|
BrowserSignalListener.prototype.flushDataIfHidden = function () {
|
|
95
94
|
// Precondition: document defined
|
|
@@ -103,7 +102,6 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
103
102
|
if (!this._sendBeacon(url, dataPayload, extraMetadata)) {
|
|
104
103
|
postService(JSON.stringify(dataPayload)).catch(function () { }); // no-op just to catch a possible exception
|
|
105
104
|
}
|
|
106
|
-
cache.clear();
|
|
107
105
|
}
|
|
108
106
|
};
|
|
109
107
|
/**
|
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)) {
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -5,12 +5,9 @@ var sdkReadinessManager_1 = require("../readiness/sdkReadinessManager");
|
|
|
5
5
|
var impressionsTracker_1 = require("../trackers/impressionsTracker");
|
|
6
6
|
var eventTracker_1 = require("../trackers/eventTracker");
|
|
7
7
|
var telemetryTracker_1 = require("../trackers/telemetryTracker");
|
|
8
|
-
var key_1 = require("../utils/key");
|
|
9
|
-
var utils_1 = require("../trackers/impressionObserver/utils");
|
|
10
8
|
var apiKey_1 = require("../utils/inputValidation/apiKey");
|
|
11
9
|
var sdkLogger_1 = require("../logger/sdkLogger");
|
|
12
10
|
var constants_1 = require("../logger/constants");
|
|
13
|
-
var metadataBuilder_1 = require("../storages/metadataBuilder");
|
|
14
11
|
var constants_2 = require("../readiness/constants");
|
|
15
12
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
16
13
|
var strategyDebug_1 = require("../trackers/strategy/strategyDebug");
|
|
@@ -23,44 +20,29 @@ var constants_3 = require("../utils/constants");
|
|
|
23
20
|
*/
|
|
24
21
|
function sdkFactory(params) {
|
|
25
22
|
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory, filterAdapterFactory = params.filterAdapterFactory;
|
|
26
|
-
var log = settings.log;
|
|
23
|
+
var log = settings.log, impressionsMode = settings.sync.impressionsMode;
|
|
27
24
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
28
25
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
29
26
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
30
27
|
(0, apiKey_1.validateAndTrackApiKey)(log, settings.core.authorizationKey);
|
|
31
28
|
var sdkReadinessManager = (0, sdkReadinessManager_1.sdkReadinessManagerFactory)(log, platform.EventEmitter, settings.startup.readyTimeout);
|
|
32
29
|
var readiness = sdkReadinessManager.readinessManager;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
36
|
-
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
37
|
-
uniqueKeysCacheSize: settings.scheduler.uniqueKeysCacheSize,
|
|
38
|
-
optimize: (0, utils_1.shouldBeOptimized)(settings),
|
|
39
|
-
// ATM, only used by InLocalStorage
|
|
40
|
-
matchingKey: (0, key_1.getMatching)(settings.core.key),
|
|
41
|
-
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
42
|
-
// ATM, only used by PluggableStorage
|
|
43
|
-
mode: settings.mode,
|
|
44
|
-
impressionsMode: settings.sync.impressionsMode,
|
|
45
|
-
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
46
|
-
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
30
|
+
var storage = storageFactory({
|
|
31
|
+
settings: settings,
|
|
47
32
|
onReadyCb: function (error) {
|
|
48
33
|
if (error)
|
|
49
34
|
return; // Don't emit SDK_READY if storage failed to connect. Error message is logged by wrapperAdapter
|
|
50
35
|
readiness.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
|
|
51
36
|
readiness.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
52
37
|
},
|
|
53
|
-
|
|
54
|
-
log: log
|
|
55
|
-
};
|
|
56
|
-
var storage = storageFactory(storageFactoryParams);
|
|
38
|
+
});
|
|
57
39
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
58
40
|
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
59
41
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
60
42
|
var observer = impressionsObserverFactory();
|
|
61
|
-
var uniqueKeysTracker =
|
|
43
|
+
var uniqueKeysTracker = impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
62
44
|
var strategy;
|
|
63
|
-
switch (
|
|
45
|
+
switch (impressionsMode) {
|
|
64
46
|
case constants_3.OPTIMIZED:
|
|
65
47
|
strategy = (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts);
|
|
66
48
|
break;
|
|
@@ -95,7 +77,7 @@ function sdkFactory(params) {
|
|
|
95
77
|
return managerInstance;
|
|
96
78
|
},
|
|
97
79
|
// Logger wrapper API
|
|
98
|
-
Logger: (0, sdkLogger_1.createLoggerAPI)(
|
|
80
|
+
Logger: (0, sdkLogger_1.createLoggerAPI)(log),
|
|
99
81
|
settings: settings,
|
|
100
82
|
}, extraProps && extraProps(ctx));
|
|
101
83
|
}
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -110,13 +110,13 @@ function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
110
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
|
}
|
|
@@ -28,7 +28,7 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
28
28
|
* @param {string} name
|
|
29
29
|
* @param {string} defaultTreatment
|
|
30
30
|
* @param {number} changeNumber
|
|
31
|
-
* @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,
|
|
32
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.
|
|
33
33
|
* The promise will never be rejected.
|
|
34
34
|
*/
|
|
@@ -43,7 +43,7 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
43
43
|
* @param {string} name
|
|
44
44
|
* @param {string} defaultTreatment
|
|
45
45
|
* @param {number} changeNumber
|
|
46
|
-
* @returns {
|
|
46
|
+
* @returns {boolean} `true` if the operation successed updating the split, or `false` if no split is updated,
|
|
47
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.
|
|
48
48
|
*/
|
|
49
49
|
AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyBuilderSS = void 0;
|
|
3
|
+
exports.KeyBuilderSS = exports.METHOD_NAMES = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var KeyBuilder_1 = require("./KeyBuilder");
|
|
6
|
-
|
|
6
|
+
exports.METHOD_NAMES = {
|
|
7
7
|
t: 'treatment',
|
|
8
8
|
ts: 'treatments',
|
|
9
9
|
tc: 'treatmentWithConfig',
|
|
@@ -14,7 +14,10 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
14
14
|
(0, tslib_1.__extends)(KeyBuilderSS, _super);
|
|
15
15
|
function KeyBuilderSS(prefix, metadata) {
|
|
16
16
|
var _this = _super.call(this, prefix) || this;
|
|
17
|
-
_this.
|
|
17
|
+
_this.latencyPrefix = _this.prefix + ".telemetry.latencies";
|
|
18
|
+
_this.exceptionPrefix = _this.prefix + ".telemetry.exceptions";
|
|
19
|
+
_this.initPrefix = _this.prefix + ".telemetry.init";
|
|
20
|
+
_this.versionablePrefix = metadata.s + "/" + metadata.n + "/" + metadata.i;
|
|
18
21
|
return _this;
|
|
19
22
|
}
|
|
20
23
|
KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
|
|
@@ -37,16 +40,13 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
37
40
|
};
|
|
38
41
|
/* Telemetry keys */
|
|
39
42
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
40
|
-
return this.
|
|
43
|
+
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + exports.METHOD_NAMES[method] + "/" + bucket;
|
|
41
44
|
};
|
|
42
45
|
KeyBuilderSS.prototype.buildExceptionKey = function (method) {
|
|
43
|
-
return this.
|
|
46
|
+
return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + exports.METHOD_NAMES[method];
|
|
44
47
|
};
|
|
45
48
|
KeyBuilderSS.prototype.buildInitKey = function () {
|
|
46
|
-
return this.
|
|
47
|
-
};
|
|
48
|
-
KeyBuilderSS.prototype.buildVersionablePrefix = function () {
|
|
49
|
-
return this.metadata.s + "/" + this.metadata.n + "/" + this.metadata.i;
|
|
49
|
+
return this.initPrefix + "::" + this.versionablePrefix;
|
|
50
50
|
};
|
|
51
51
|
return KeyBuilderSS;
|
|
52
52
|
}(KeyBuilder_1.KeyBuilder));
|
|
@@ -203,7 +203,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
203
203
|
};
|
|
204
204
|
/**
|
|
205
205
|
* Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
206
|
-
* Clean operation (clear) also updates `lastUpdated` timestamp with current time.
|
|
207
206
|
*
|
|
208
207
|
* @param {number | undefined} expirationTimestamp if the value is not a number, data will not be cleaned
|
|
209
208
|
*/
|
|
@@ -16,7 +16,8 @@ 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
|
|
19
|
+
var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
|
|
20
|
+
var key_1 = require("../../utils/key");
|
|
20
21
|
/**
|
|
21
22
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
22
23
|
*/
|
|
@@ -26,20 +27,23 @@ function InLocalStorage(options) {
|
|
|
26
27
|
function InLocalStorageCSFactory(params) {
|
|
27
28
|
// Fallback to InMemoryStorage if LocalStorage API is not available
|
|
28
29
|
if (!(0, isLocalStorageAvailable_1.isLocalStorageAvailable)()) {
|
|
29
|
-
params.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
|
|
30
|
+
params.settings.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
|
|
30
31
|
return (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
|
|
31
32
|
}
|
|
32
|
-
var
|
|
33
|
-
var
|
|
33
|
+
var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
|
|
34
|
+
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
35
|
+
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
34
36
|
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
37
|
+
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(log, keys, expirationTimestamp, __splitFiltersValidation);
|
|
38
|
+
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
35
39
|
return {
|
|
36
|
-
splits:
|
|
37
|
-
segments:
|
|
38
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(
|
|
39
|
-
impressionCounts:
|
|
40
|
-
events: new EventsCacheInMemory_1.EventsCacheInMemory(
|
|
41
|
-
telemetry:
|
|
42
|
-
uniqueKeys:
|
|
40
|
+
splits: splits,
|
|
41
|
+
segments: segments,
|
|
42
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
43
|
+
impressionCounts: impressionsMode !== constants_2.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
44
|
+
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
45
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
46
|
+
uniqueKeys: impressionsMode === constants_2.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
43
47
|
destroy: function () {
|
|
44
48
|
var _a;
|
|
45
49
|
this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
@@ -8,21 +8,24 @@ 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
|
|
11
|
+
var UniqueKeysCacheInMemory_1 = require("./UniqueKeysCacheInMemory");
|
|
12
12
|
/**
|
|
13
13
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
14
14
|
*
|
|
15
15
|
* @param params parameters required by EventsCacheSync
|
|
16
16
|
*/
|
|
17
17
|
function InMemoryStorageFactory(params) {
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, impressionsMode = _a.sync.impressionsMode;
|
|
19
|
+
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
20
|
+
var segments = new SegmentsCacheInMemory_1.SegmentsCacheInMemory();
|
|
18
21
|
return {
|
|
19
|
-
splits:
|
|
20
|
-
segments:
|
|
21
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(
|
|
22
|
-
impressionCounts:
|
|
23
|
-
events: new EventsCacheInMemory_1.EventsCacheInMemory(
|
|
24
|
-
telemetry:
|
|
25
|
-
uniqueKeys:
|
|
22
|
+
splits: splits,
|
|
23
|
+
segments: segments,
|
|
24
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
25
|
+
impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
26
|
+
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
27
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
28
|
+
uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : undefined,
|
|
26
29
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
27
30
|
destroy: function () {
|
|
28
31
|
var _a;
|
|
@@ -8,21 +8,24 @@ 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
|
|
11
|
+
var UniqueKeysCacheInMemoryCS_1 = require("./UniqueKeysCacheInMemoryCS");
|
|
12
12
|
/**
|
|
13
13
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
14
14
|
*
|
|
15
15
|
* @param params parameters required by EventsCacheSync
|
|
16
16
|
*/
|
|
17
17
|
function InMemoryStorageCSFactory(params) {
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, impressionsMode = _a.sync.impressionsMode;
|
|
19
|
+
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
|
|
20
|
+
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
18
21
|
return {
|
|
19
|
-
splits:
|
|
20
|
-
segments:
|
|
21
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(
|
|
22
|
-
impressionCounts:
|
|
23
|
-
events: new EventsCacheInMemory_1.EventsCacheInMemory(
|
|
24
|
-
telemetry:
|
|
25
|
-
uniqueKeys:
|
|
22
|
+
splits: splits,
|
|
23
|
+
segments: segments,
|
|
24
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
25
|
+
impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
26
|
+
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
27
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
|
|
28
|
+
uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
|
|
26
29
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
27
30
|
destroy: function () {
|
|
28
31
|
var _a;
|
|
@@ -1,41 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TelemetryCacheInMemory = exports.shouldRecordTelemetry = void 0;
|
|
3
|
+
exports.TelemetryCacheInMemory = exports.shouldRecordTelemetry = exports.newBuckets = exports.MAX_LATENCY_BUCKET_COUNT = void 0;
|
|
4
|
+
var constants_1 = require("../../utils/constants");
|
|
4
5
|
var findLatencyIndex_1 = require("../findLatencyIndex");
|
|
5
6
|
var MAX_STREAMING_EVENTS = 20;
|
|
6
7
|
var MAX_TAGS = 10;
|
|
8
|
+
exports.MAX_LATENCY_BUCKET_COUNT = 23;
|
|
7
9
|
function newBuckets() {
|
|
8
|
-
// MAX_LATENCY_BUCKET_COUNT (length) is 23
|
|
10
|
+
// MAX_LATENCY_BUCKET_COUNT (length) is 23
|
|
11
|
+
// Not using Array.fill for old browsers compatibility
|
|
9
12
|
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
10
13
|
}
|
|
14
|
+
exports.newBuckets = newBuckets;
|
|
11
15
|
var ACCEPTANCE_RANGE = 0.001;
|
|
12
16
|
/**
|
|
13
|
-
*
|
|
17
|
+
* Record telemetry if mode is not localhost.
|
|
18
|
+
* All factory instances track telemetry on server-side, and 0.1% on client-side.
|
|
14
19
|
*/
|
|
15
|
-
function shouldRecordTelemetry() {
|
|
16
|
-
|
|
20
|
+
function shouldRecordTelemetry(_a) {
|
|
21
|
+
var settings = _a.settings;
|
|
22
|
+
return settings.mode !== constants_1.LOCALHOST_MODE && (settings.core.key === undefined || Math.random() <= ACCEPTANCE_RANGE);
|
|
17
23
|
}
|
|
18
24
|
exports.shouldRecordTelemetry = shouldRecordTelemetry;
|
|
19
25
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
20
|
-
function TelemetryCacheInMemory() {
|
|
26
|
+
function TelemetryCacheInMemory(splits, segments) {
|
|
27
|
+
this.splits = splits;
|
|
28
|
+
this.segments = segments;
|
|
29
|
+
// isEmpty flag
|
|
30
|
+
this.e = true;
|
|
21
31
|
this.notReadyUsage = 0;
|
|
32
|
+
/** Usage stats */
|
|
22
33
|
this.impressionStats = [0, 0, 0];
|
|
23
34
|
this.eventStats = [0, 0];
|
|
24
|
-
// @ts-expect-error
|
|
25
35
|
this.lastSync = {};
|
|
26
|
-
// @ts-expect-error
|
|
27
36
|
this.httpErrors = {};
|
|
28
|
-
// @ts-expect-error
|
|
29
37
|
this.httpLatencies = {};
|
|
30
38
|
this.authRejections = 0;
|
|
31
39
|
this.tokenRefreshes = 0;
|
|
32
40
|
this.streamingEvents = [];
|
|
33
41
|
this.tags = [];
|
|
34
|
-
// @ts-expect-error
|
|
35
42
|
this.exceptions = {};
|
|
36
|
-
// @ts-expect-error
|
|
37
43
|
this.latencies = {};
|
|
38
44
|
}
|
|
45
|
+
TelemetryCacheInMemory.prototype.isEmpty = function () { return this.e; };
|
|
46
|
+
TelemetryCacheInMemory.prototype.clear = function () { };
|
|
47
|
+
TelemetryCacheInMemory.prototype.pop = function () {
|
|
48
|
+
this.e = true;
|
|
49
|
+
return {
|
|
50
|
+
lS: this.getLastSynchronization(),
|
|
51
|
+
mL: this.popLatencies(),
|
|
52
|
+
mE: this.popExceptions(),
|
|
53
|
+
hE: this.popHttpErrors(),
|
|
54
|
+
hL: this.popHttpLatencies(),
|
|
55
|
+
tR: this.popTokenRefreshes(),
|
|
56
|
+
aR: this.popAuthRejections(),
|
|
57
|
+
iQ: this.getImpressionStats(constants_1.QUEUED),
|
|
58
|
+
iDe: this.getImpressionStats(constants_1.DEDUPED),
|
|
59
|
+
iDr: this.getImpressionStats(constants_1.DROPPED),
|
|
60
|
+
spC: this.splits && this.splits.getSplitNames().length,
|
|
61
|
+
seC: this.segments && this.segments.getRegisteredSegments().length,
|
|
62
|
+
skC: this.segments && this.segments.getKeysCount(),
|
|
63
|
+
sL: this.getSessionLength(),
|
|
64
|
+
eQ: this.getEventStats(constants_1.QUEUED),
|
|
65
|
+
eD: this.getEventStats(constants_1.DROPPED),
|
|
66
|
+
sE: this.popStreamingEvents(),
|
|
67
|
+
t: this.popTags(),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
39
70
|
TelemetryCacheInMemory.prototype.getTimeUntilReady = function () {
|
|
40
71
|
return this.timeUntilReady;
|
|
41
72
|
};
|
|
@@ -59,44 +90,41 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
59
90
|
};
|
|
60
91
|
TelemetryCacheInMemory.prototype.recordImpressionStats = function (type, count) {
|
|
61
92
|
this.impressionStats[type] += count;
|
|
93
|
+
this.e = false;
|
|
62
94
|
};
|
|
63
95
|
TelemetryCacheInMemory.prototype.getEventStats = function (type) {
|
|
64
96
|
return this.eventStats[type];
|
|
65
97
|
};
|
|
66
98
|
TelemetryCacheInMemory.prototype.recordEventStats = function (type, count) {
|
|
67
99
|
this.eventStats[type] += count;
|
|
100
|
+
this.e = false;
|
|
68
101
|
};
|
|
69
102
|
TelemetryCacheInMemory.prototype.getLastSynchronization = function () {
|
|
70
103
|
return this.lastSync;
|
|
71
104
|
};
|
|
72
105
|
TelemetryCacheInMemory.prototype.recordSuccessfulSync = function (resource, timeMs) {
|
|
73
106
|
this.lastSync[resource] = timeMs;
|
|
107
|
+
this.e = false;
|
|
74
108
|
};
|
|
75
109
|
TelemetryCacheInMemory.prototype.popHttpErrors = function () {
|
|
76
|
-
var result = this.httpErrors;
|
|
110
|
+
var result = this.httpErrors;
|
|
77
111
|
this.httpErrors = {};
|
|
78
112
|
return result;
|
|
79
113
|
};
|
|
80
114
|
TelemetryCacheInMemory.prototype.recordHttpError = function (resource, status) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.httpErrors[resource][status] = 1;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.httpErrors[resource][status]++;
|
|
88
|
-
}
|
|
115
|
+
var statusErrors = (this.httpErrors[resource] = this.httpErrors[resource] || {});
|
|
116
|
+
statusErrors[status] = (statusErrors[status] || 0) + 1;
|
|
117
|
+
this.e = false;
|
|
89
118
|
};
|
|
90
119
|
TelemetryCacheInMemory.prototype.popHttpLatencies = function () {
|
|
91
|
-
var result = this.httpLatencies;
|
|
120
|
+
var result = this.httpLatencies;
|
|
92
121
|
this.httpLatencies = {};
|
|
93
122
|
return result;
|
|
94
123
|
};
|
|
95
124
|
TelemetryCacheInMemory.prototype.recordHttpLatency = function (resource, latencyMs) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.httpLatencies[resource][(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
125
|
+
var latencyBuckets = (this.httpLatencies[resource] = this.httpLatencies[resource] || newBuckets());
|
|
126
|
+
latencyBuckets[(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
127
|
+
this.e = false;
|
|
100
128
|
};
|
|
101
129
|
TelemetryCacheInMemory.prototype.popAuthRejections = function () {
|
|
102
130
|
var result = this.authRejections;
|
|
@@ -105,6 +133,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
105
133
|
};
|
|
106
134
|
TelemetryCacheInMemory.prototype.recordAuthRejections = function () {
|
|
107
135
|
this.authRejections++;
|
|
136
|
+
this.e = false;
|
|
108
137
|
};
|
|
109
138
|
TelemetryCacheInMemory.prototype.popTokenRefreshes = function () {
|
|
110
139
|
var result = this.tokenRefreshes;
|
|
@@ -113,6 +142,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
113
142
|
};
|
|
114
143
|
TelemetryCacheInMemory.prototype.recordTokenRefreshes = function () {
|
|
115
144
|
this.tokenRefreshes++;
|
|
145
|
+
this.e = false;
|
|
116
146
|
};
|
|
117
147
|
TelemetryCacheInMemory.prototype.popStreamingEvents = function () {
|
|
118
148
|
return this.streamingEvents.splice(0);
|
|
@@ -121,6 +151,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
121
151
|
if (this.streamingEvents.length < MAX_STREAMING_EVENTS) {
|
|
122
152
|
this.streamingEvents.push(streamingEvent);
|
|
123
153
|
}
|
|
154
|
+
this.e = false;
|
|
124
155
|
};
|
|
125
156
|
TelemetryCacheInMemory.prototype.popTags = function () {
|
|
126
157
|
return this.tags.splice(0);
|
|
@@ -129,36 +160,33 @@ var TelemetryCacheInMemory = /** @class */ (function () {
|
|
|
129
160
|
if (this.tags.length < MAX_TAGS) {
|
|
130
161
|
this.tags.push(tag);
|
|
131
162
|
}
|
|
163
|
+
this.e = false;
|
|
132
164
|
};
|
|
133
165
|
TelemetryCacheInMemory.prototype.getSessionLength = function () {
|
|
134
166
|
return this.sessionLength;
|
|
135
167
|
};
|
|
136
168
|
TelemetryCacheInMemory.prototype.recordSessionLength = function (ms) {
|
|
137
169
|
this.sessionLength = ms;
|
|
170
|
+
this.e = false;
|
|
138
171
|
};
|
|
139
172
|
TelemetryCacheInMemory.prototype.popExceptions = function () {
|
|
140
|
-
var result = this.exceptions;
|
|
173
|
+
var result = this.exceptions;
|
|
141
174
|
this.exceptions = {};
|
|
142
175
|
return result;
|
|
143
176
|
};
|
|
144
177
|
TelemetryCacheInMemory.prototype.recordException = function (method) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
this.exceptions[method]++;
|
|
150
|
-
}
|
|
178
|
+
this.exceptions[method] = (this.exceptions[method] || 0) + 1;
|
|
179
|
+
this.e = false;
|
|
151
180
|
};
|
|
152
181
|
TelemetryCacheInMemory.prototype.popLatencies = function () {
|
|
153
|
-
var result = this.latencies;
|
|
182
|
+
var result = this.latencies;
|
|
154
183
|
this.latencies = {};
|
|
155
184
|
return result;
|
|
156
185
|
};
|
|
157
186
|
TelemetryCacheInMemory.prototype.recordLatency = function (method, latencyMs) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.latencies[method][(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
187
|
+
var latencyBuckets = (this.latencies[method] = this.latencies[method] || newBuckets());
|
|
188
|
+
latencyBuckets[(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
|
|
189
|
+
this.e = false;
|
|
162
190
|
};
|
|
163
191
|
return TelemetryCacheInMemory;
|
|
164
192
|
}());
|