@splitsoftware/splitio-commons 1.6.2-rc.1 → 1.6.2-rc.10
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 +73 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +78 -0
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +50 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +59 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +17 -2
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +43 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +50 -0
- package/cjs/storages/pluggable/index.js +42 -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 +70 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +75 -0
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +47 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +56 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +18 -3
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +40 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +47 -0
- package/esm/storages/pluggable/index.js +43 -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 +82 -0
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +88 -0
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +53 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -2
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +65 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +15 -5
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +47 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -2
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +56 -0
- package/src/storages/pluggable/index.ts +44 -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 +18 -6
- 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 +37 -0
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -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 +15 -0
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +14 -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 +14 -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 +12 -6
- 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
|
@@ -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.10",
|
|
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,
|
|
@@ -12,6 +12,7 @@ import { SplitIO } from '../../types';
|
|
|
12
12
|
import { Identity, GoogleAnalyticsToSplitOptions } from './types';
|
|
13
13
|
import { ILogger } from '../../logger/types';
|
|
14
14
|
import { IIntegrationFactoryParams } from '../types';
|
|
15
|
+
import { ITelemetryTracker } from '../../trackers/types';
|
|
15
16
|
|
|
16
17
|
const logPrefix = 'ga-to-split: ';
|
|
17
18
|
const logNameMapper = 'ga-to-split:mapper';
|
|
@@ -25,7 +26,7 @@ const logNameMapper = 'ga-to-split:mapper';
|
|
|
25
26
|
* @param log Logger instance.
|
|
26
27
|
* @param autoRequire If true, log error when auto-require script is not detected
|
|
27
28
|
*/
|
|
28
|
-
function providePlugin(window: any, pluginName: string, pluginConstructor: Function, log: ILogger, autoRequire?:
|
|
29
|
+
function providePlugin(window: any, pluginName: string, pluginConstructor: Function, log: ILogger, autoRequire: boolean, telemetryTracker?: ITelemetryTracker) {
|
|
29
30
|
// get reference to global command queue. Init it if not defined yet.
|
|
30
31
|
const gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
31
32
|
window[gaAlias] = window[gaAlias] || function () {
|
|
@@ -35,10 +36,13 @@ function providePlugin(window: any, pluginName: string, pluginConstructor: Funct
|
|
|
35
36
|
// provides the plugin for use with analytics.js.
|
|
36
37
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const hasAutoRequire = window[gaAlias].q && window[gaAlias].q.push !== [].push;
|
|
40
|
+
if (autoRequire && !hasAutoRequire) { // Expecting spy on ga.q push method but not found
|
|
40
41
|
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.');
|
|
41
42
|
}
|
|
43
|
+
if (telemetryTracker && hasAutoRequire) {
|
|
44
|
+
telemetryTracker.addTag('integration:ga-autorequire');
|
|
45
|
+
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
@@ -191,7 +195,7 @@ export function fixEventTypeId(log: ILogger, eventTypeId: any) {
|
|
|
191
195
|
*/
|
|
192
196
|
export function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIntegrationFactoryParams) {
|
|
193
197
|
|
|
194
|
-
const { storage, settings: { core: coreSettings, log } } = params;
|
|
198
|
+
const { storage, settings: { core: coreSettings, log }, telemetryTracker } = params;
|
|
195
199
|
|
|
196
200
|
const defaultOptions = {
|
|
197
201
|
prefix: defaultPrefix,
|
|
@@ -291,5 +295,5 @@ export function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIn
|
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
294
|
-
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true);
|
|
298
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
|
|
295
299
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IEventsCacheBase } from '../storages/types';
|
|
2
|
-
import { IEventsHandler, IImpressionsHandler } from '../trackers/types';
|
|
2
|
+
import { IEventsHandler, IImpressionsHandler, ITelemetryTracker } from '../trackers/types';
|
|
3
3
|
import { ISettings, SplitIO } from '../types';
|
|
4
4
|
|
|
5
5
|
export interface IIntegration {
|
|
@@ -11,6 +11,7 @@ export type IIntegrationManager = IEventsHandler & IImpressionsHandler;
|
|
|
11
11
|
export interface IIntegrationFactoryParams {
|
|
12
12
|
storage: { events: IEventsCacheBase }
|
|
13
13
|
settings: ISettings
|
|
14
|
+
telemetryTracker: ITelemetryTracker
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export type IntegrationFactory = {
|
|
Binary file
|
package/src/sdkClient/client.ts
CHANGED
|
@@ -9,6 +9,17 @@ import { IEvaluationResult } from '../evaluator/types';
|
|
|
9
9
|
import { SplitIO, ImpressionDTO } from '../types';
|
|
10
10
|
import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
|
|
11
11
|
import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
12
|
+
import { isStorageSync } from '../trackers/impressionObserver/utils';
|
|
13
|
+
|
|
14
|
+
const treatmentNotReady = { treatment: CONTROL, label: SDK_NOT_READY };
|
|
15
|
+
|
|
16
|
+
function treatmentsNotReady(splitNames: string[]) {
|
|
17
|
+
const evaluations: Record<string, IEvaluationResult> = {};
|
|
18
|
+
splitNames.forEach(splitName => {
|
|
19
|
+
evaluations[splitName] = treatmentNotReady;
|
|
20
|
+
});
|
|
21
|
+
return evaluations;
|
|
22
|
+
}
|
|
12
23
|
|
|
13
24
|
/**
|
|
14
25
|
* Creator of base client with getTreatments and track methods.
|
|
@@ -29,7 +40,11 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
29
40
|
return treatment;
|
|
30
41
|
};
|
|
31
42
|
|
|
32
|
-
const evaluation =
|
|
43
|
+
const evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
44
|
+
evaluateFeature(log, key, splitName, attributes, storage) :
|
|
45
|
+
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
|
|
46
|
+
treatmentNotReady :
|
|
47
|
+
Promise.resolve(treatmentNotReady); // Promisify if async
|
|
33
48
|
|
|
34
49
|
return thenable(evaluation) ? evaluation.then((res) => wrapUp(res)) : wrapUp(evaluation);
|
|
35
50
|
}
|
|
@@ -53,7 +68,11 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
53
68
|
return treatments;
|
|
54
69
|
};
|
|
55
70
|
|
|
56
|
-
const evaluations =
|
|
71
|
+
const evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
72
|
+
evaluateFeatures(log, key, splitNames, attributes, storage) :
|
|
73
|
+
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
|
|
74
|
+
treatmentsNotReady(splitNames) :
|
|
75
|
+
Promise.resolve(treatmentsNotReady(splitNames)); // Promisify if async
|
|
57
76
|
|
|
58
77
|
return thenable(evaluations) ? evaluations.then((res) => wrapUp(res)) : wrapUp(evaluations);
|
|
59
78
|
}
|
|
@@ -72,15 +91,9 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
72
91
|
invokingMethodName: string,
|
|
73
92
|
queue: ImpressionDTO[]
|
|
74
93
|
): SplitIO.Treatment | SplitIO.TreatmentWithConfig {
|
|
75
|
-
const isSdkReady = readinessManager.isReady() || readinessManager.isReadyFromCache();
|
|
76
94
|
const matchingKey = getMatching(key);
|
|
77
95
|
const bucketingKey = getBucketing(key);
|
|
78
96
|
|
|
79
|
-
// If the SDK was not ready, treatment may be incorrect due to having Splits but not segments data.
|
|
80
|
-
if (!isSdkReady) {
|
|
81
|
-
evaluation = { treatment: CONTROL, label: SDK_NOT_READY };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
97
|
const { treatment, label, changeNumber, config = null } = evaluation;
|
|
85
98
|
log.info(IMPRESSION, [splitName, matchingKey, treatment, label]);
|
|
86
99
|
|
|
@@ -9,7 +9,7 @@ import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
|
9
9
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
10
10
|
*/
|
|
11
11
|
export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: boolean): SplitIO.IClient | SplitIO.IAsyncClient {
|
|
12
|
-
const { sdkReadinessManager, syncManager, storage, signalListener, settings, telemetryTracker } = params;
|
|
12
|
+
const { sdkReadinessManager, syncManager, storage, signalListener, settings, telemetryTracker, uniqueKeysTracker } = params;
|
|
13
13
|
|
|
14
14
|
return objectAssign(
|
|
15
15
|
// Proto-linkage of the readiness Event Emitter
|
|
@@ -39,6 +39,8 @@ export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: bo
|
|
|
39
39
|
|
|
40
40
|
// Release the API Key if it is the main client
|
|
41
41
|
if (!isSharedClient) releaseApiKey(settings.core.authorizationKey);
|
|
42
|
+
|
|
43
|
+
if (uniqueKeysTracker) uniqueKeysTracker.stop();
|
|
42
44
|
|
|
43
45
|
// Cleanup storage
|
|
44
46
|
return storage.destroy();
|