@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
|
@@ -7,10 +7,16 @@ import { EventsCachePluggable } from './EventsCachePluggable';
|
|
|
7
7
|
import { wrapperAdapter, METHODS_TO_PROMISE_WRAP } from './wrapperAdapter';
|
|
8
8
|
import { isObject } from '../../utils/lang';
|
|
9
9
|
import { validatePrefix } from '../KeyBuilder';
|
|
10
|
-
import { CONSUMER_PARTIAL_MODE, STORAGE_PLUGGABLE } from '../../utils/constants';
|
|
10
|
+
import { CONSUMER_PARTIAL_MODE, DEBUG, NONE, STORAGE_PLUGGABLE } from '../../utils/constants';
|
|
11
11
|
import { ImpressionsCacheInMemory } from '../inMemory/ImpressionsCacheInMemory';
|
|
12
12
|
import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory';
|
|
13
13
|
import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
|
|
14
|
+
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
15
|
+
import { TelemetryCachePluggable } from './TelemetryCachePluggable';
|
|
16
|
+
import { ImpressionCountsCachePluggable } from './ImpressionCountsCachePluggable';
|
|
17
|
+
import { UniqueKeysCachePluggable } from './UniqueKeysCachePluggable';
|
|
18
|
+
import { UniqueKeysCacheInMemory } from '../inMemory/UniqueKeysCacheInMemory';
|
|
19
|
+
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
14
20
|
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
15
21
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
16
22
|
/**
|
|
@@ -27,15 +33,6 @@ function validatePluggableStorageOptions(options) {
|
|
|
27
33
|
if (missingMethods.length)
|
|
28
34
|
throw new Error(NO_VALID_WRAPPER_INTERFACE + " The following methods are missing or invalid: " + missingMethods);
|
|
29
35
|
}
|
|
30
|
-
// subscription to wrapper connect event in order to emit SDK_READY event
|
|
31
|
-
function wrapperConnect(wrapper, onReadyCb) {
|
|
32
|
-
wrapper.connect().then(function () {
|
|
33
|
-
onReadyCb();
|
|
34
|
-
// At the moment, we don't synchronize config with pluggable storage
|
|
35
|
-
}).catch(function (e) {
|
|
36
|
-
onReadyCb(e || new Error('Error connecting wrapper'));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
36
|
// Async return type in `client.track` method on consumer partial mode
|
|
40
37
|
// No need to promisify impressions cache
|
|
41
38
|
function promisifyEventsTrack(events) {
|
|
@@ -51,28 +48,60 @@ function promisifyEventsTrack(events) {
|
|
|
51
48
|
export function PluggableStorage(options) {
|
|
52
49
|
validatePluggableStorageOptions(options);
|
|
53
50
|
var prefix = validatePrefix(options.prefix);
|
|
54
|
-
function PluggableStorageFactory(
|
|
55
|
-
var log =
|
|
51
|
+
function PluggableStorageFactory(params) {
|
|
52
|
+
var log = params.log, metadata = params.metadata, onReadyCb = params.onReadyCb, mode = params.mode, eventsQueueSize = params.eventsQueueSize, impressionsQueueSize = params.impressionsQueueSize, impressionsMode = params.impressionsMode, matchingKey = params.matchingKey;
|
|
56
53
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
57
54
|
var wrapper = wrapperAdapter(log, options.wrapper);
|
|
55
|
+
var isSyncronizer = mode === undefined; // If mode is not defined, the synchronizer is running
|
|
58
56
|
var isPartialConsumer = mode === CONSUMER_PARTIAL_MODE;
|
|
57
|
+
var telemetry = shouldRecordTelemetry(params) || isSyncronizer ?
|
|
58
|
+
isPartialConsumer ?
|
|
59
|
+
new TelemetryCacheInMemory() :
|
|
60
|
+
new TelemetryCachePluggable(log, keys, wrapper) :
|
|
61
|
+
undefined;
|
|
62
|
+
var impressionCountsCache = impressionsMode !== DEBUG || isSyncronizer ?
|
|
63
|
+
isPartialConsumer ?
|
|
64
|
+
new ImpressionCountsCacheInMemory() :
|
|
65
|
+
new ImpressionCountsCachePluggable(log, keys.buildImpressionsCountKey(), wrapper) :
|
|
66
|
+
undefined;
|
|
67
|
+
var uniqueKeysCache = impressionsMode === NONE || isSyncronizer ?
|
|
68
|
+
isPartialConsumer ?
|
|
69
|
+
matchingKey === undefined ? new UniqueKeysCacheInMemory() : new UniqueKeysCacheInMemoryCS() :
|
|
70
|
+
new UniqueKeysCachePluggable(log, keys.buildUniqueKeysKey(), wrapper) :
|
|
71
|
+
undefined;
|
|
59
72
|
// Connects to wrapper and emits SDK_READY event on main client
|
|
60
|
-
|
|
73
|
+
var connectPromise = wrapper.connect().then(function () {
|
|
74
|
+
onReadyCb();
|
|
75
|
+
// Start periodic flush of async storages
|
|
76
|
+
if (impressionCountsCache && impressionCountsCache.start)
|
|
77
|
+
impressionCountsCache.start();
|
|
78
|
+
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
79
|
+
uniqueKeysCache.start();
|
|
80
|
+
if (telemetry && telemetry.recordConfig && !isSyncronizer)
|
|
81
|
+
telemetry.recordConfig();
|
|
82
|
+
}).catch(function (e) {
|
|
83
|
+
e = e || new Error('Error connecting wrapper');
|
|
84
|
+
onReadyCb(e);
|
|
85
|
+
return e;
|
|
86
|
+
});
|
|
61
87
|
return {
|
|
62
88
|
splits: new SplitsCachePluggable(log, keys, wrapper),
|
|
63
89
|
segments: new SegmentsCachePluggable(log, keys, wrapper),
|
|
64
90
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
65
|
-
impressionCounts:
|
|
91
|
+
impressionCounts: impressionCountsCache,
|
|
66
92
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
telemetry: telemetry,
|
|
94
|
+
uniqueKeys: uniqueKeysCache,
|
|
69
95
|
// Disconnect the underlying storage
|
|
70
96
|
destroy: function () {
|
|
71
|
-
return
|
|
97
|
+
return Promise.all([
|
|
98
|
+
impressionCountsCache && impressionCountsCache.stop && impressionCountsCache.stop(),
|
|
99
|
+
uniqueKeysCache && uniqueKeysCache.stop && uniqueKeysCache.stop(),
|
|
100
|
+
]).then(function () { return wrapper.disconnect(); });
|
|
72
101
|
},
|
|
73
102
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
74
103
|
shared: function (_, onReadyCb) {
|
|
75
|
-
|
|
104
|
+
connectPromise.then(onReadyCb);
|
|
76
105
|
return __assign(__assign({}, this), {
|
|
77
106
|
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
78
107
|
destroy: function () { } });
|
|
@@ -24,8 +24,7 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
24
24
|
log.debug(SYNC_OFFLINE_DATA, [JSON.stringify(splitsMock)]);
|
|
25
25
|
forOwn(splitsMock, function (val, name) {
|
|
26
26
|
splits.push([
|
|
27
|
-
name,
|
|
28
|
-
JSON.stringify({
|
|
27
|
+
name, {
|
|
29
28
|
name: name,
|
|
30
29
|
status: 'ACTIVE',
|
|
31
30
|
killed: false,
|
|
@@ -34,7 +33,7 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
34
33
|
conditions: val.conditions || [],
|
|
35
34
|
configurations: val.configurations,
|
|
36
35
|
trafficTypeName: val.trafficTypeName
|
|
37
|
-
}
|
|
36
|
+
}
|
|
38
37
|
]);
|
|
39
38
|
});
|
|
40
39
|
return Promise.all([
|
|
@@ -37,7 +37,7 @@ export function computeSplitsMutation(entries) {
|
|
|
37
37
|
var segments = new _Set();
|
|
38
38
|
var computed = entries.reduce(function (accum, split) {
|
|
39
39
|
if (split.status === 'ACTIVE') {
|
|
40
|
-
accum.added.push([split.name,
|
|
40
|
+
accum.added.push([split.name, split]);
|
|
41
41
|
parseSegments(split).forEach(function (segmentName) {
|
|
42
42
|
segments.add(segmentName);
|
|
43
43
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
var _a, _b, _c;
|
|
2
2
|
import { submitterFactory, firstPushWindowDecorator } from './submitter';
|
|
3
|
-
import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG, DEBUG_ENUM, OPTIMIZED_ENUM, CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../../utils/constants';
|
|
3
|
+
import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG, NONE, DEBUG_ENUM, OPTIMIZED_ENUM, NONE_ENUM, CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../../utils/constants';
|
|
4
4
|
import { SDK_READY, SDK_READY_FROM_CACHE } from '../../readiness/constants';
|
|
5
5
|
import { base } from '../../utils/settingsValidation';
|
|
6
6
|
import { usedKeysMap } from '../../utils/inputValidation/apiKey';
|
|
7
7
|
import { timer } from '../../utils/timeTracker/timer';
|
|
8
8
|
import { objectAssign } from '../../utils/lang/objectAssign';
|
|
9
|
+
import { isStorageSync } from '../../trackers/impressionObserver/utils';
|
|
9
10
|
/**
|
|
10
11
|
* Converts data from telemetry cache into /metrics/usage request payload.
|
|
11
12
|
*/
|
|
@@ -26,9 +27,9 @@ export function telemetryCacheStatsAdapter(telemetry, splits, segments) {
|
|
|
26
27
|
iQ: telemetry.getImpressionStats(QUEUED),
|
|
27
28
|
iDe: telemetry.getImpressionStats(DEDUPED),
|
|
28
29
|
iDr: telemetry.getImpressionStats(DROPPED),
|
|
29
|
-
spC: splits.getSplitNames().length,
|
|
30
|
-
seC: segments.getRegisteredSegments().length,
|
|
31
|
-
skC: segments.getKeysCount(),
|
|
30
|
+
spC: splits && splits.getSplitNames().length,
|
|
31
|
+
seC: segments && segments.getRegisteredSegments().length,
|
|
32
|
+
skC: segments && segments.getKeysCount(),
|
|
32
33
|
sL: telemetry.getSessionLength(),
|
|
33
34
|
eQ: telemetry.getEventStats(QUEUED),
|
|
34
35
|
eD: telemetry.getEventStats(DROPPED),
|
|
@@ -46,6 +47,7 @@ var OPERATION_MODE_MAP = (_a = {},
|
|
|
46
47
|
var IMPRESSIONS_MODE_MAP = (_b = {},
|
|
47
48
|
_b[OPTIMIZED] = OPTIMIZED_ENUM,
|
|
48
49
|
_b[DEBUG] = DEBUG_ENUM,
|
|
50
|
+
_b[NONE] = NONE_ENUM,
|
|
49
51
|
_b);
|
|
50
52
|
var USER_CONSENT_MAP = (_c = {},
|
|
51
53
|
_c[CONSENT_UNKNOWN] = 1,
|
|
@@ -119,7 +121,9 @@ export function telemetrySubmitterFactory(params) {
|
|
|
119
121
|
return; // No submitter created if telemetry cache is not defined
|
|
120
122
|
var settings = params.settings, _b = params.settings, log = _b.log, telemetryRefreshRate = _b.scheduler.telemetryRefreshRate, splitApi = params.splitApi, readiness = params.readiness, sdkReadinessManager = params.sdkReadinessManager;
|
|
121
123
|
var startTime = timer(now);
|
|
122
|
-
var submitter = firstPushWindowDecorator(submitterFactory(log, splitApi.postMetricsUsage,
|
|
124
|
+
var submitter = firstPushWindowDecorator(submitterFactory(log, splitApi.postMetricsUsage,
|
|
125
|
+
// @TODO cannot provide splits and segments cache if they are async, because `submitterFactory` expects a sync storage source
|
|
126
|
+
isStorageSync(params.settings) ? telemetryCacheStatsAdapter(telemetry, splits, segments) : telemetryCacheStatsAdapter(telemetry), telemetryRefreshRate, 'telemetry stats', undefined, 0, true), telemetryRefreshRate);
|
|
123
127
|
readiness.gate.once(SDK_READY_FROM_CACHE, function () {
|
|
124
128
|
telemetry.recordTimeUntilReadyFromCache(startTime());
|
|
125
129
|
});
|
|
@@ -1,64 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
2
2
|
import { submitterFactory } from './submitter';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
function invertUniqueKeys(uniqueKeys) {
|
|
7
|
-
var featureNames = Object.keys(uniqueKeys);
|
|
8
|
-
var inverted = {};
|
|
9
|
-
for (var i = 0; i < featureNames.length; i++) {
|
|
10
|
-
var featureName = featureNames[i];
|
|
11
|
-
var featureKeys = setToArray(uniqueKeys[featureName]);
|
|
12
|
-
for (var j = 0; j < featureKeys.length; j++) {
|
|
13
|
-
var featureKey = featureKeys[j];
|
|
14
|
-
if (!inverted[featureKey])
|
|
15
|
-
inverted[featureKey] = [];
|
|
16
|
-
inverted[featureKey].push(featureName);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return inverted;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Converts `uniqueKeys` data from cache into request payload for CS.
|
|
23
|
-
*/
|
|
24
|
-
export function fromUniqueKeysCollectorCs(uniqueKeys) {
|
|
25
|
-
var payload = [];
|
|
26
|
-
var featuresPerKey = invertUniqueKeys(uniqueKeys);
|
|
27
|
-
var keys = Object.keys(featuresPerKey);
|
|
28
|
-
for (var k = 0; k < keys.length; k++) {
|
|
29
|
-
var key = keys[k];
|
|
30
|
-
var uniqueKeysPayload = {
|
|
31
|
-
k: key,
|
|
32
|
-
fs: featuresPerKey[key]
|
|
33
|
-
};
|
|
34
|
-
payload.push(uniqueKeysPayload);
|
|
35
|
-
}
|
|
36
|
-
return { keys: payload };
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Converts `uniqueKeys` data from cache into request payload for SS.
|
|
40
|
-
*/
|
|
41
|
-
export function fromUniqueKeysCollectorSs(uniqueKeys) {
|
|
42
|
-
var payload = [];
|
|
43
|
-
var featureNames = Object.keys(uniqueKeys);
|
|
44
|
-
for (var i = 0; i < featureNames.length; i++) {
|
|
45
|
-
var featureName = featureNames[i];
|
|
46
|
-
var featureKeys = setToArray(uniqueKeys[featureName]);
|
|
47
|
-
var uniqueKeysPayload = {
|
|
48
|
-
f: featureName,
|
|
49
|
-
ks: featureKeys
|
|
50
|
-
};
|
|
51
|
-
payload.push(uniqueKeysPayload);
|
|
52
|
-
}
|
|
53
|
-
return { keys: payload };
|
|
54
|
-
}
|
|
3
|
+
var DATA_NAME = 'unique keys';
|
|
4
|
+
var UNIQUE_KEYS_RATE = 900000; // 15 minutes
|
|
55
5
|
/**
|
|
56
6
|
* Submitter that periodically posts impression counts
|
|
57
7
|
*/
|
|
58
8
|
export function uniqueKeysSubmitterFactory(params) {
|
|
59
|
-
var _a = params.settings, log = _a.log,
|
|
9
|
+
var _a = params.settings, log = _a.log, key = _a.core.key, _b = params.splitApi, postUniqueKeysBulkCs = _b.postUniqueKeysBulkCs, postUniqueKeysBulkSs = _b.postUniqueKeysBulkSs, uniqueKeys = params.storage.uniqueKeys;
|
|
60
10
|
var isClientSide = key !== undefined;
|
|
61
11
|
var postUniqueKeysBulk = isClientSide ? postUniqueKeysBulkCs : postUniqueKeysBulkSs;
|
|
62
|
-
var
|
|
63
|
-
|
|
12
|
+
var syncTask = submitterFactory(log, postUniqueKeysBulk, uniqueKeys, UNIQUE_KEYS_RATE, DATA_NAME);
|
|
13
|
+
// register unique keys submitter to be executed when uniqueKeys cache is full
|
|
14
|
+
uniqueKeys.setOnFullQueueCb(function () {
|
|
15
|
+
if (syncTask.isRunning()) {
|
|
16
|
+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
17
|
+
syncTask.execute();
|
|
18
|
+
}
|
|
19
|
+
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
20
|
+
// Data will be sent when submitter is resumed.
|
|
21
|
+
});
|
|
22
|
+
return syncTask;
|
|
64
23
|
}
|
|
@@ -20,21 +20,23 @@ export function impressionsTrackerFactory(settings, impressionsCache, strategy,
|
|
|
20
20
|
var impressionsCount = impressions.length;
|
|
21
21
|
var _a = strategy.process(impressions), impressionsToStore = _a.impressionsToStore, impressionsToListener = _a.impressionsToListener, deduped = _a.deduped;
|
|
22
22
|
var impressionsToListenerCount = impressionsToListener.length;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
telemetryCache
|
|
37
|
-
|
|
23
|
+
if (impressionsToStore.length > 0) {
|
|
24
|
+
var res = impressionsCache.track(impressionsToStore);
|
|
25
|
+
// If we're on an async storage, handle error and log it.
|
|
26
|
+
if (thenable(res)) {
|
|
27
|
+
res.then(function () {
|
|
28
|
+
log.info(IMPRESSIONS_TRACKER_SUCCESS, [impressionsCount]);
|
|
29
|
+
}).catch(function (err) {
|
|
30
|
+
log.error(ERROR_IMPRESSIONS_TRACKER, [impressionsCount, err]);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// Record when impressionsCache is sync only (standalone mode)
|
|
35
|
+
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
36
|
+
if (telemetryCache) {
|
|
37
|
+
telemetryCache.recordImpressionStats(QUEUED, impressionsToStore.length);
|
|
38
|
+
telemetryCache.recordImpressionStats(DEDUPED, deduped);
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
// @TODO next block might be handled by the integration manager. In that case, the metadata object doesn't need to be passed in the constructor
|
|
@@ -13,7 +13,7 @@ export function strategyNoneFactory(impressionsCounter, uniqueKeysTracker) {
|
|
|
13
13
|
// Increments impression counter per featureName
|
|
14
14
|
impressionsCounter.track(impression.feature, now, 1);
|
|
15
15
|
// Keep track by unique key
|
|
16
|
-
uniqueKeysTracker.track(impression.
|
|
16
|
+
uniqueKeysTracker.track(impression.keyName, impression.feature);
|
|
17
17
|
});
|
|
18
18
|
return {
|
|
19
19
|
impressionsToStore: [],
|
|
@@ -14,7 +14,8 @@ export function strategyOptimizedFactory(impressionsObserver, impressionsCounter
|
|
|
14
14
|
impression.pt = impressionsObserver.testAndSet(impression);
|
|
15
15
|
var now = Date.now();
|
|
16
16
|
// Increments impression counter per featureName
|
|
17
|
-
|
|
17
|
+
if (impression.pt)
|
|
18
|
+
impressionsCounter.track(impression.feature, now, 1);
|
|
18
19
|
// Checks if the impression should be added in queue to be sent
|
|
19
20
|
if (!impression.pt || impression.pt < truncateTimeFrame(now)) {
|
|
20
21
|
impressionsToStore.push(impression);
|
|
@@ -46,6 +46,11 @@ export function telemetryTrackerFactory(telemetryCache, now) {
|
|
|
46
46
|
if (e === TOKEN_REFRESH)
|
|
47
47
|
telemetryCache.recordTokenRefreshes();
|
|
48
48
|
}
|
|
49
|
+
},
|
|
50
|
+
addTag: function (tag) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
if (telemetryCache.addTag)
|
|
53
|
+
telemetryCache.addTag(tag);
|
|
49
54
|
}
|
|
50
55
|
};
|
|
51
56
|
}
|
|
@@ -56,6 +61,7 @@ export function telemetryTrackerFactory(telemetryCache, now) {
|
|
|
56
61
|
trackHttp: noopTrack,
|
|
57
62
|
sessionLength: function () { },
|
|
58
63
|
streamingEvent: function () { },
|
|
64
|
+
addTag: function () { }
|
|
59
65
|
};
|
|
60
66
|
}
|
|
61
67
|
}
|
|
@@ -1,65 +1,34 @@
|
|
|
1
1
|
import { LOG_PREFIX_UNIQUE_KEYS_TRACKER } from '../logger/constants';
|
|
2
|
-
import { _Set } from '../utils/lang/sets';
|
|
3
2
|
var noopFilterAdapter = {
|
|
4
3
|
add: function () { return true; },
|
|
5
4
|
contains: function () { return true; },
|
|
6
5
|
clear: function () { }
|
|
7
6
|
};
|
|
8
|
-
var DEFAULT_CACHE_SIZE = 30000;
|
|
9
7
|
/**
|
|
10
8
|
* Trackes uniques keys
|
|
11
9
|
* Unique Keys Tracker will be in charge of checking if the MTK was already sent to the BE in the last period
|
|
12
10
|
* or schedule to be sent; if not it will be added in an internal cache and sent in the next post.
|
|
13
11
|
*
|
|
14
12
|
* @param log Logger instance
|
|
13
|
+
* @param uniqueKeysCache cache to save unique keys
|
|
15
14
|
* @param filterAdapter filter adapter
|
|
16
|
-
* @param cacheSize optional internal cache size
|
|
17
|
-
* @param maxBulkSize optional max MTKs bulk size
|
|
18
15
|
*/
|
|
19
|
-
export function uniqueKeysTrackerFactory(log,
|
|
16
|
+
export function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
20
17
|
if (filterAdapter === void 0) { filterAdapter = noopFilterAdapter; }
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
var intervalId;
|
|
19
|
+
if (filterAdapter.refreshRate) {
|
|
20
|
+
intervalId = setInterval(filterAdapter.clear, filterAdapter.refreshRate);
|
|
21
|
+
}
|
|
24
22
|
return {
|
|
25
|
-
track: function (
|
|
26
|
-
if (!filterAdapter.add(
|
|
23
|
+
track: function (key, featureName) {
|
|
24
|
+
if (!filterAdapter.add(key, featureName)) {
|
|
27
25
|
log.debug(LOG_PREFIX_UNIQUE_KEYS_TRACKER + "The feature " + featureName + " and key " + key + " exist in the filter");
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
uniqueKeysTracker[featureName] = new _Set();
|
|
32
|
-
var tracker = uniqueKeysTracker[featureName];
|
|
33
|
-
if (!tracker.has(key)) {
|
|
34
|
-
tracker.add(key);
|
|
35
|
-
log.debug(LOG_PREFIX_UNIQUE_KEYS_TRACKER + "Key " + key + " added to feature " + featureName);
|
|
36
|
-
uniqueTrackerSize++;
|
|
37
|
-
}
|
|
38
|
-
if (uniqueTrackerSize >= cacheSize) {
|
|
39
|
-
log.warn(LOG_PREFIX_UNIQUE_KEYS_TRACKER + "The UniqueKeysTracker size reached the maximum limit");
|
|
40
|
-
// @TODO trigger event to submitter to send mtk
|
|
41
|
-
uniqueTrackerSize = 0;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
/**
|
|
45
|
-
* Pop the collected data, used as payload for posting.
|
|
46
|
-
*/
|
|
47
|
-
pop: function () {
|
|
48
|
-
var data = uniqueKeysTracker;
|
|
49
|
-
uniqueKeysTracker = {};
|
|
50
|
-
return data;
|
|
51
|
-
},
|
|
52
|
-
/**
|
|
53
|
-
* Clear the data stored on the cache.
|
|
54
|
-
*/
|
|
55
|
-
clear: function () {
|
|
56
|
-
uniqueKeysTracker = {};
|
|
28
|
+
uniqueKeysCache.track(key, featureName);
|
|
57
29
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
isEmpty: function () {
|
|
62
|
-
return Object.keys(uniqueKeysTracker).length === 0;
|
|
30
|
+
stop: function () {
|
|
31
|
+
clearInterval(intervalId);
|
|
63
32
|
}
|
|
64
33
|
};
|
|
65
34
|
}
|
|
@@ -38,6 +38,7 @@ export var CONSUMER_ENUM = 1;
|
|
|
38
38
|
export var CONSUMER_PARTIAL_ENUM = 2;
|
|
39
39
|
export var OPTIMIZED_ENUM = 0;
|
|
40
40
|
export var DEBUG_ENUM = 1;
|
|
41
|
+
export var NONE_ENUM = 2;
|
|
41
42
|
export var SPLITS = 'sp';
|
|
42
43
|
export var IMPRESSIONS = 'im';
|
|
43
44
|
export var IMPRESSIONS_COUNT = 'ic';
|
package/esm/utils/lang/maps.js
CHANGED
|
@@ -37,13 +37,6 @@ var MapPoly = /** @class */ (function () {
|
|
|
37
37
|
this.__mapKeysData__.length = 0;
|
|
38
38
|
this.__mapValuesData__.length = 0;
|
|
39
39
|
};
|
|
40
|
-
MapPoly.prototype.set = function (key, value) {
|
|
41
|
-
var index = this.__mapKeysData__.indexOf(key);
|
|
42
|
-
if (index === -1)
|
|
43
|
-
index = this.__mapKeysData__.push(key) - 1;
|
|
44
|
-
this.__mapValuesData__[index] = value;
|
|
45
|
-
return this;
|
|
46
|
-
};
|
|
47
40
|
MapPoly.prototype.delete = function (key) {
|
|
48
41
|
var index = this.__mapKeysData__.indexOf(key);
|
|
49
42
|
if (index === -1)
|
|
@@ -52,12 +45,27 @@ var MapPoly = /** @class */ (function () {
|
|
|
52
45
|
this.__mapValuesData__.splice(index, 1);
|
|
53
46
|
return true;
|
|
54
47
|
};
|
|
48
|
+
MapPoly.prototype.forEach = function (callbackfn, thisArg) {
|
|
49
|
+
for (var i = 0; i < this.__mapKeysData__.length; i++) {
|
|
50
|
+
callbackfn.call(thisArg, this.__mapValuesData__[i], this.__mapKeysData__[i], this);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
55
53
|
MapPoly.prototype.get = function (key) {
|
|
56
54
|
var index = this.__mapKeysData__.indexOf(key);
|
|
57
55
|
if (index === -1)
|
|
58
56
|
return;
|
|
59
57
|
return this.__mapValuesData__[index];
|
|
60
58
|
};
|
|
59
|
+
MapPoly.prototype.has = function (key) {
|
|
60
|
+
return this.__mapKeysData__.indexOf(key) !== -1;
|
|
61
|
+
};
|
|
62
|
+
MapPoly.prototype.set = function (key, value) {
|
|
63
|
+
var index = this.__mapKeysData__.indexOf(key);
|
|
64
|
+
if (index === -1)
|
|
65
|
+
index = this.__mapKeysData__.push(key) - 1;
|
|
66
|
+
this.__mapValuesData__[index] = value;
|
|
67
|
+
return this;
|
|
68
|
+
};
|
|
61
69
|
Object.defineProperty(MapPoly.prototype, "size", {
|
|
62
70
|
get: function () {
|
|
63
71
|
return this.__mapKeysData__.length;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
function identityFunction(data) {
|
|
3
|
+
return data;
|
|
4
|
+
}
|
|
5
|
+
function asyncFunction(data) {
|
|
6
|
+
return Promise.resolve(data);
|
|
7
|
+
}
|
|
8
|
+
var IDENTITY_METHODS = [];
|
|
9
|
+
var ASYNC_METHODS = ['rpush', 'hincrby'];
|
|
10
|
+
var PIPELINE_METHODS = ['rpush', 'hincrby'];
|
|
11
|
+
var RedisMock = /** @class */ (function () {
|
|
12
|
+
function RedisMock() {
|
|
13
|
+
var _this = this;
|
|
14
|
+
this.pipelineMethods = { exec: jest.fn(asyncFunction) };
|
|
15
|
+
IDENTITY_METHODS.forEach(function (method) {
|
|
16
|
+
_this[method] = jest.fn(identityFunction);
|
|
17
|
+
});
|
|
18
|
+
ASYNC_METHODS.forEach(function (method) {
|
|
19
|
+
_this[method] = jest.fn(asyncFunction);
|
|
20
|
+
});
|
|
21
|
+
PIPELINE_METHODS.forEach(function (method) {
|
|
22
|
+
_this.pipelineMethods[method] = _this[method];
|
|
23
|
+
});
|
|
24
|
+
this.pipeline = jest.fn(function () { return _this.pipelineMethods; });
|
|
25
|
+
}
|
|
26
|
+
return RedisMock;
|
|
27
|
+
}());
|
|
28
|
+
export { RedisMock };
|
|
@@ -31,8 +31,6 @@ export var base = {
|
|
|
31
31
|
telemetryRefreshRate: 3600,
|
|
32
32
|
// publish evaluations each 300 sec (default value for OPTIMIZED impressions mode)
|
|
33
33
|
impressionsRefreshRate: 300,
|
|
34
|
-
// publish unique Keys each 900 sec (15 min)
|
|
35
|
-
uniqueKeysRefreshRate: 900,
|
|
36
34
|
// fetch offline changes each 15 sec
|
|
37
35
|
offlineRefreshRate: 15,
|
|
38
36
|
// publish events every 60 seconds after the first flush
|
|
@@ -111,7 +109,6 @@ export function settingsValidation(config, validationParams) {
|
|
|
111
109
|
scheduler.segmentsRefreshRate = fromSecondsToMillis(scheduler.segmentsRefreshRate);
|
|
112
110
|
scheduler.offlineRefreshRate = fromSecondsToMillis(scheduler.offlineRefreshRate);
|
|
113
111
|
scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);
|
|
114
|
-
scheduler.uniqueKeysRefreshRate = fromSecondsToMillis(scheduler.uniqueKeysRefreshRate);
|
|
115
112
|
scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
|
|
116
113
|
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
117
114
|
if (get(config, 'scheduler.impressionsRefreshRate') === undefined && withDefaults.sync.impressionsMode === DEBUG)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splitsoftware/splitio-commons",
|
|
3
|
-
"version": "1.6.2-rc.
|
|
3
|
+
"version": "1.6.2-rc.11",
|
|
4
4
|
"description": "Split Javascript SDK common components",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"ioredis": "^4.28.0",
|
|
71
71
|
"jest": "^27.2.3",
|
|
72
72
|
"jest-localstorage-mock": "^2.4.3",
|
|
73
|
-
"js-yaml": "^3.13.1",
|
|
74
73
|
"lodash": "^4.17.21",
|
|
75
74
|
"node-fetch": "^2.6.7",
|
|
76
75
|
"redis-server": "1.2.2",
|
|
@@ -40,8 +40,8 @@ export function createUserConsentAPI(params: ISdkFactoryContext) {
|
|
|
40
40
|
|
|
41
41
|
// @ts-ignore, clear method is present in storage for standalone and partial consumer mode
|
|
42
42
|
if (events.clear) events.clear(); // @ts-ignore
|
|
43
|
-
if (impressions.clear) impressions.clear()
|
|
44
|
-
if (impressionCounts) impressionCounts.clear();
|
|
43
|
+
if (impressions.clear) impressions.clear();// @ts-ignore
|
|
44
|
+
if (impressionCounts && impressionCounts.clear) impressionCounts.clear();
|
|
45
45
|
}
|
|
46
46
|
} else {
|
|
47
47
|
log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|
package/src/evaluator/index.ts
CHANGED
|
@@ -29,19 +29,19 @@ export function evaluateFeature(
|
|
|
29
29
|
attributes: SplitIO.Attributes | undefined,
|
|
30
30
|
storage: IStorageSync | IStorageAsync,
|
|
31
31
|
): MaybeThenable<IEvaluationResult> {
|
|
32
|
-
let
|
|
32
|
+
let parsedSplit;
|
|
33
33
|
|
|
34
34
|
try {
|
|
35
|
-
|
|
35
|
+
parsedSplit = storage.splits.getSplit(splitName);
|
|
36
36
|
} catch (e) {
|
|
37
37
|
// Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
|
|
38
38
|
return treatmentException;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
if (thenable(
|
|
42
|
-
return
|
|
41
|
+
if (thenable(parsedSplit)) {
|
|
42
|
+
return parsedSplit.then((split) => getEvaluation(
|
|
43
43
|
log,
|
|
44
|
-
|
|
44
|
+
split,
|
|
45
45
|
key,
|
|
46
46
|
attributes,
|
|
47
47
|
storage,
|
|
@@ -54,7 +54,7 @@ export function evaluateFeature(
|
|
|
54
54
|
|
|
55
55
|
return getEvaluation(
|
|
56
56
|
log,
|
|
57
|
-
|
|
57
|
+
parsedSplit,
|
|
58
58
|
key,
|
|
59
59
|
attributes,
|
|
60
60
|
storage,
|
|
@@ -68,28 +68,28 @@ export function evaluateFeatures(
|
|
|
68
68
|
attributes: SplitIO.Attributes | undefined,
|
|
69
69
|
storage: IStorageSync | IStorageAsync,
|
|
70
70
|
): MaybeThenable<Record<string, IEvaluationResult>> {
|
|
71
|
-
let
|
|
71
|
+
let parsedSplits;
|
|
72
72
|
|
|
73
73
|
try {
|
|
74
|
-
|
|
74
|
+
parsedSplits = storage.splits.getSplits(splitNames);
|
|
75
75
|
} catch (e) {
|
|
76
76
|
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
|
|
77
77
|
return treatmentsException(splitNames);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
return
|
|
81
|
-
|
|
80
|
+
return thenable(parsedSplits) ?
|
|
81
|
+
parsedSplits.then(splits => getEvaluations(log, splitNames, splits, key, attributes, storage))
|
|
82
82
|
.catch(() => {
|
|
83
83
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
84
84
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
85
85
|
return treatmentsException(splitNames);
|
|
86
86
|
}) :
|
|
87
|
-
getEvaluations(log, splitNames,
|
|
87
|
+
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
function getEvaluation(
|
|
91
91
|
log: ILogger,
|
|
92
|
-
|
|
92
|
+
splitJSON: ISplit | null,
|
|
93
93
|
key: SplitIO.SplitKey,
|
|
94
94
|
attributes: SplitIO.Attributes | undefined,
|
|
95
95
|
storage: IStorageSync | IStorageAsync,
|
|
@@ -100,8 +100,7 @@ function getEvaluation(
|
|
|
100
100
|
config: null
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
if (
|
|
104
|
-
const splitJSON: ISplit = JSON.parse(stringifiedSplit);
|
|
103
|
+
if (splitJSON) {
|
|
105
104
|
const split = Engine.parse(log, splitJSON, storage);
|
|
106
105
|
evaluation = split.getTreatment(key, attributes, evaluateFeature);
|
|
107
106
|
|
|
@@ -125,7 +124,7 @@ function getEvaluation(
|
|
|
125
124
|
function getEvaluations(
|
|
126
125
|
log: ILogger,
|
|
127
126
|
splitNames: string[],
|
|
128
|
-
splits: Record<string,
|
|
127
|
+
splits: Record<string, ISplit | null>,
|
|
129
128
|
key: SplitIO.SplitKey,
|
|
130
129
|
attributes: SplitIO.Attributes | undefined,
|
|
131
130
|
storage: IStorageSync | IStorageAsync,
|