@splitsoftware/splitio-commons 1.6.2-rc.0 → 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/listeners/browser.js +2 -1
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +24 -7
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/services/splitApi.js +24 -4
- 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/submitterManager.js +3 -0
- package/cjs/sync/submitters/telemetrySubmitter.js +8 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +27 -0
- package/cjs/trackers/impressionsTracker.js +22 -41
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +35 -0
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/trackers/uniqueKeysTracker.js +38 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +15 -16
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +24 -7
- package/esm/sdkManager/index.js +3 -11
- package/esm/services/splitApi.js +24 -4
- 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/submitterManager.js +3 -0
- package/esm/sync/submitters/telemetrySubmitter.js +9 -5
- package/esm/sync/submitters/uniqueKeysSubmitter.js +23 -0
- package/esm/trackers/impressionsTracker.js +22 -41
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +31 -0
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/trackers/uniqueKeysTracker.js +34 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -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/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +28 -8
- package/src/sdkFactory/types.ts +7 -4
- package/src/sdkManager/index.ts +3 -12
- package/src/services/splitApi.ts +26 -4
- package/src/services/types.ts +8 -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 +50 -29
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
- package/src/sync/submitters/submitterManager.ts +2 -0
- package/src/sync/submitters/telemetrySubmitter.ts +15 -8
- package/src/sync/submitters/types.ts +38 -7
- package/src/sync/submitters/uniqueKeysSubmitter.ts +36 -0
- package/src/trackers/impressionsTracker.ts +27 -48
- package/src/trackers/strategy/strategyDebug.ts +28 -0
- package/src/trackers/strategy/strategyNone.ts +34 -0
- package/src/trackers/strategy/strategyOptimized.ts +42 -0
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +32 -0
- package/src/trackers/uniqueKeysTracker.ts +48 -0
- package/src/types.ts +1 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +1 -0
- package/types/integrations/types.d.ts +2 -1
- package/types/logger/browser/{debugLogger.d.ts → DebugLogger.d.ts} +0 -0
- package/types/logger/browser/{errorLogger.d.ts → ErrorLogger.d.ts} +0 -0
- package/types/logger/browser/{infoLogger.d.ts → InfoLogger.d.ts} +0 -0
- package/types/logger/browser/{warnLogger.d.ts → WarnLogger.d.ts} +0 -0
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +6 -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 +38 -25
- 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 +30 -7
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +0 -8
- package/types/trackers/impressionsTracker.d.ts +4 -6
- package/types/trackers/types.d.ts +27 -0
- package/types/trackers/uniqueKeysTracker.d.ts +3 -3
- package/types/types.d.ts +1 -1
- package/types/utils/constants/index.d.ts +2 -0
- package/types/utils/lang/maps.d.ts +6 -2
- package/types/utils/redis/RedisMock.d.ts +4 -0
- package/src/splitio.d.ts +0 -1602
- package/types/integrations/ga/GaToSplitPlugin.d.ts +0 -3
- package/types/integrations/ga/SplitToGaPlugin.d.ts +0 -4
- package/types/integrations/ga/autoRequire.d.ts +0 -4
- package/types/logger/codes.d.ts +0 -2
- package/types/logger/codesConstants.d.ts +0 -117
- package/types/logger/codesConstantsBrowser.d.ts +0 -2
- package/types/logger/codesConstantsNode.d.ts +0 -14
- package/types/logger/codesDebug.d.ts +0 -1
- package/types/logger/codesDebugBrowser.d.ts +0 -1
- package/types/logger/codesDebugNode.d.ts +0 -1
- package/types/logger/codesError.d.ts +0 -1
- package/types/logger/codesErrorNode.d.ts +0 -1
- package/types/logger/codesInfo.d.ts +0 -1
- package/types/logger/codesWarn.d.ts +0 -1
- package/types/logger/codesWarnNode.d.ts +0 -1
- package/types/logger/debugLogger.d.ts +0 -2
- package/types/logger/errorLogger.d.ts +0 -2
- package/types/logger/infoLogger.d.ts +0 -2
- package/types/logger/messages/debugBrowser.d.ts +0 -1
- package/types/logger/messages/debugNode.d.ts +0 -1
- package/types/logger/messages/errorNode.d.ts +0 -1
- package/types/logger/messages/warnNode.d.ts +0 -1
- package/types/logger/noopLogger.d.ts +0 -2
- package/types/logger/warnLogger.d.ts +0 -2
- package/types/sdkClient/types.d.ts +0 -18
- package/types/sdkFactory/userConsentProps.d.ts +0 -6
- package/types/sdkManager/sdkManagerMethod.d.ts +0 -6
- package/types/storages/getRegisteredSegments.d.ts +0 -10
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/index.d.ts +0 -10
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/storages/parseSegments.d.ts +0 -6
- package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
- package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +0 -35
- package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +0 -35
- package/types/sync/streaming/AuthClient/indexV1.d.ts +0 -12
- package/types/sync/streaming/AuthClient/indexV2.d.ts +0 -8
- package/types/sync/streaming/pushManagerCS.d.ts +0 -1
- package/types/sync/streaming/pushManagerNoUsers.d.ts +0 -13
- package/types/sync/streaming/pushManagerSS.d.ts +0 -1
- 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/submitters/telemetrySyncTask.d.ts +0 -0
- package/types/sync/syncManagerFromFile.d.ts +0 -2
- package/types/sync/syncManagerFromObject.d.ts +0 -2
- package/types/sync/syncManagerOffline.d.ts +0 -9
- package/types/sync/syncTaskComposite.d.ts +0 -5
- package/types/trackers/telemetryRecorder.d.ts +0 -0
- package/types/utils/EventEmitter.d.ts +0 -4
- package/types/utils/consent.d.ts +0 -2
- package/types/utils/lang/errors.d.ts +0 -10
- package/types/utils/murmur3/commons.d.ts +0 -12
- package/types/utils/settingsValidation/buildMetadata.d.ts +0 -3
- package/types/utils/settingsValidation/localhost/index.d.ts +0 -9
- package/types/utils/settingsValidation/logger.d.ts +0 -11
- package/types/utils/settingsValidation/runtime/browser.d.ts +0 -2
- package/types/utils/settingsValidation/runtime/node.d.ts +0 -2
- package/types/utils/settingsValidation/userConsent.d.ts +0 -5
- package/types/utils/timeTracker/index.d.ts +0 -1
package/esm/sdkFactory/index.js
CHANGED
|
@@ -10,11 +10,16 @@ import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
|
|
|
10
10
|
import { metadataBuilder } from '../storages/metadataBuilder';
|
|
11
11
|
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
12
12
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
13
|
+
import { strategyDebugFactory } from '../trackers/strategy/strategyDebug';
|
|
14
|
+
import { strategyOptimizedFactory } from '../trackers/strategy/strategyOptimized';
|
|
15
|
+
import { strategyNoneFactory } from '../trackers/strategy/strategyNone';
|
|
16
|
+
import { uniqueKeysTrackerFactory } from '../trackers/uniqueKeysTracker';
|
|
17
|
+
import { NONE, OPTIMIZED } from '../utils/constants';
|
|
13
18
|
/**
|
|
14
19
|
* Modular SDK factory
|
|
15
20
|
*/
|
|
16
21
|
export function sdkFactory(params) {
|
|
17
|
-
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;
|
|
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;
|
|
18
23
|
var log = settings.log;
|
|
19
24
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
20
25
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
@@ -32,6 +37,7 @@ export function sdkFactory(params) {
|
|
|
32
37
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
33
38
|
// ATM, only used by PluggableStorage
|
|
34
39
|
mode: settings.mode,
|
|
40
|
+
impressionsMode: settings.sync.impressionsMode,
|
|
35
41
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
36
42
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
37
43
|
onReadyCb: function (error) {
|
|
@@ -45,15 +51,26 @@ export function sdkFactory(params) {
|
|
|
45
51
|
};
|
|
46
52
|
var storage = storageFactory(storageFactoryParams);
|
|
47
53
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
48
|
-
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
|
|
49
|
-
// trackers
|
|
50
|
-
var observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
51
|
-
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts, storage.telemetry);
|
|
52
|
-
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
53
54
|
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
55
|
+
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
56
|
+
var observer = impressionsObserverFactory();
|
|
57
|
+
var uniqueKeysTracker = storageFactoryParams.impressionsMode === NONE ? uniqueKeysTrackerFactory(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
58
|
+
var strategy;
|
|
59
|
+
switch (storageFactoryParams.impressionsMode) {
|
|
60
|
+
case OPTIMIZED:
|
|
61
|
+
strategy = strategyOptimizedFactory(observer, storage.impressionCounts);
|
|
62
|
+
break;
|
|
63
|
+
case NONE:
|
|
64
|
+
strategy = strategyNoneFactory(storage.impressionCounts, uniqueKeysTracker);
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
strategy = strategyDebugFactory(observer);
|
|
68
|
+
}
|
|
69
|
+
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
70
|
+
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
54
71
|
// splitApi is used by SyncManager and Browser signal listener
|
|
55
72
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
56
|
-
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
73
|
+
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
|
57
74
|
var syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
58
75
|
ctx.syncManager = syncManager;
|
|
59
76
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
package/esm/sdkManager/index.js
CHANGED
|
@@ -12,15 +12,7 @@ function collectTreatments(splitObject) {
|
|
|
12
12
|
// Then extract the treatments from the partitions
|
|
13
13
|
return allTreatmentsCondition ? allTreatmentsCondition.partitions.map(function (v) { return v.treatment; }) : [];
|
|
14
14
|
}
|
|
15
|
-
function objectToView(
|
|
16
|
-
var splitObject;
|
|
17
|
-
try {
|
|
18
|
-
// @ts-expect-error
|
|
19
|
-
splitObject = JSON.parse(json);
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
15
|
+
function objectToView(splitObject) {
|
|
24
16
|
if (!splitObject)
|
|
25
17
|
return null;
|
|
26
18
|
return {
|
|
@@ -32,9 +24,9 @@ function objectToView(json) {
|
|
|
32
24
|
configs: splitObject.configurations || {}
|
|
33
25
|
};
|
|
34
26
|
}
|
|
35
|
-
function objectsToViews(
|
|
27
|
+
function objectsToViews(splitObjects) {
|
|
36
28
|
var views = [];
|
|
37
|
-
|
|
29
|
+
splitObjects.forEach(function (split) {
|
|
38
30
|
var view = objectToView(split);
|
|
39
31
|
if (view)
|
|
40
32
|
views.push(view);
|
package/esm/services/splitApi.js
CHANGED
|
@@ -87,13 +87,33 @@ export function splitApiFactory(settings, platform, telemetryTracker) {
|
|
|
87
87
|
var url = urls.events + "/testImpressions/count";
|
|
88
88
|
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(IMPRESSIONS_COUNT));
|
|
89
89
|
},
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Post unique keys for client side.
|
|
92
|
+
*
|
|
93
|
+
* @param body unique keys payload
|
|
94
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
95
|
+
*/
|
|
96
|
+
postUniqueKeysBulkCs: function (body, headers) {
|
|
97
|
+
var url = urls.telemetry + "/v1/keys/cs";
|
|
98
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY));
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Post unique keys for server side.
|
|
102
|
+
*
|
|
103
|
+
* @param body unique keys payload
|
|
104
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
105
|
+
*/
|
|
106
|
+
postUniqueKeysBulkSs: function (body, headers) {
|
|
107
|
+
var url = urls.telemetry + "/v1/keys/ss";
|
|
108
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY));
|
|
109
|
+
},
|
|
110
|
+
postMetricsConfig: function (body, headers) {
|
|
91
111
|
var url = urls.telemetry + "/v1/metrics/config";
|
|
92
|
-
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
112
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
93
113
|
},
|
|
94
|
-
postMetricsUsage: function (body) {
|
|
114
|
+
postMetricsUsage: function (body, headers) {
|
|
95
115
|
var url = urls.telemetry + "/v1/metrics/usage";
|
|
96
|
-
return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
116
|
+
return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
97
117
|
}
|
|
98
118
|
};
|
|
99
119
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
1
2
|
/**
|
|
2
3
|
* This class provides a skeletal implementation of the ISplitsCacheAsync interface
|
|
3
4
|
* to minimize the effort required to implement this interface.
|
|
@@ -24,22 +25,19 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
24
25
|
* @param {string} name
|
|
25
26
|
* @param {string} defaultTreatment
|
|
26
27
|
* @param {number} changeNumber
|
|
27
|
-
* @returns {Promise} a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the
|
|
28
|
+
* @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,
|
|
28
29
|
* 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.
|
|
29
30
|
* The promise will never be rejected.
|
|
30
31
|
*/
|
|
31
32
|
AbstractSplitsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
32
33
|
var _this = this;
|
|
33
34
|
return this.getSplit(name).then(function (split) {
|
|
34
|
-
if (split) {
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
41
|
-
return _this.addSplit(name, newSplit);
|
|
42
|
-
}
|
|
35
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
36
|
+
var newSplit = objectAssign({}, split);
|
|
37
|
+
newSplit.killed = true;
|
|
38
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
39
|
+
newSplit.changeNumber = changeNumber;
|
|
40
|
+
return _this.addSplit(name, newSplit);
|
|
43
41
|
}
|
|
44
42
|
return false;
|
|
45
43
|
}).catch(function () { return false; });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
1
2
|
/**
|
|
2
3
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
3
4
|
* to minimize the effort required to implement this interface.
|
|
@@ -39,20 +40,17 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
39
40
|
* @param {string} name
|
|
40
41
|
* @param {string} defaultTreatment
|
|
41
42
|
* @param {number} changeNumber
|
|
42
|
-
* @returns {
|
|
43
|
+
* @returns {boolean} `true` if the operation successed updating the split, or `false` if no split is updated,
|
|
43
44
|
* 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.
|
|
44
45
|
*/
|
|
45
46
|
AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
46
47
|
var split = this.getSplit(name);
|
|
47
|
-
if (split) {
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
54
|
-
return this.addSplit(name, newSplit);
|
|
55
|
-
}
|
|
48
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
49
|
+
var newSplit = objectAssign({}, split);
|
|
50
|
+
newSplit.killed = true;
|
|
51
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
52
|
+
newSplit.changeNumber = changeNumber;
|
|
53
|
+
return this.addSplit(name, newSplit);
|
|
56
54
|
}
|
|
57
55
|
return false;
|
|
58
56
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __extends } from "tslib";
|
|
2
2
|
import { KeyBuilder } from './KeyBuilder';
|
|
3
|
-
|
|
3
|
+
import { MAX_LATENCY_BUCKET_COUNT } from './inMemory/TelemetryCacheInMemory';
|
|
4
|
+
var METHOD_NAMES = {
|
|
4
5
|
t: 'treatment',
|
|
5
6
|
ts: 'treatments',
|
|
6
7
|
tc: 'treatmentWithConfig',
|
|
@@ -11,7 +12,10 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
11
12
|
__extends(KeyBuilderSS, _super);
|
|
12
13
|
function KeyBuilderSS(prefix, metadata) {
|
|
13
14
|
var _this = _super.call(this, prefix) || this;
|
|
14
|
-
_this.
|
|
15
|
+
_this.latencyPrefix = _this.prefix + ".telemetry.latencies";
|
|
16
|
+
_this.exceptionPrefix = _this.prefix + ".telemetry.exceptions";
|
|
17
|
+
_this.initPrefix = _this.prefix + ".telemetry.init";
|
|
18
|
+
_this.versionablePrefix = metadata.s + "/" + metadata.n + "/" + metadata.i;
|
|
15
19
|
return _this;
|
|
16
20
|
}
|
|
17
21
|
KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
|
|
@@ -20,6 +24,12 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
20
24
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
21
25
|
return this.prefix + ".impressions";
|
|
22
26
|
};
|
|
27
|
+
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
28
|
+
return this.prefix + ".impressions.count";
|
|
29
|
+
};
|
|
30
|
+
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
31
|
+
return this.prefix + ".uniquekeys";
|
|
32
|
+
};
|
|
23
33
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
24
34
|
return this.prefix + ".events";
|
|
25
35
|
};
|
|
@@ -28,17 +38,49 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
28
38
|
};
|
|
29
39
|
/* Telemetry keys */
|
|
30
40
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
31
|
-
return this.
|
|
41
|
+
return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
|
|
32
42
|
};
|
|
33
43
|
KeyBuilderSS.prototype.buildExceptionKey = function (method) {
|
|
34
|
-
return this.
|
|
44
|
+
return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method];
|
|
35
45
|
};
|
|
36
46
|
KeyBuilderSS.prototype.buildInitKey = function () {
|
|
37
|
-
return this.
|
|
38
|
-
};
|
|
39
|
-
KeyBuilderSS.prototype.buildVersionablePrefix = function () {
|
|
40
|
-
return this.metadata.s + "/" + this.metadata.n + "/" + this.metadata.i;
|
|
47
|
+
return this.initPrefix + "::" + this.versionablePrefix;
|
|
41
48
|
};
|
|
42
49
|
return KeyBuilderSS;
|
|
43
50
|
}(KeyBuilder));
|
|
44
51
|
export { KeyBuilderSS };
|
|
52
|
+
// Used by consumer methods of TelemetryCacheInRedis and TelemetryCachePluggable
|
|
53
|
+
var REVERSE_METHOD_NAMES = Object.keys(METHOD_NAMES).reduce(function (acc, key) {
|
|
54
|
+
acc[METHOD_NAMES[key]] = key;
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
export function parseMetadata(field) {
|
|
58
|
+
var parts = field.split('/');
|
|
59
|
+
if (parts.length !== 3)
|
|
60
|
+
return "invalid subsection count. Expected 3, got: " + parts.length;
|
|
61
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
|
|
62
|
+
return [JSON.stringify({ s: s, n: n, i: i })];
|
|
63
|
+
}
|
|
64
|
+
export function parseExceptionField(field) {
|
|
65
|
+
var parts = field.split('/');
|
|
66
|
+
if (parts.length !== 4)
|
|
67
|
+
return "invalid subsection count. Expected 4, got: " + parts.length;
|
|
68
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
|
|
69
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
70
|
+
if (!method)
|
|
71
|
+
return "unknown method '" + m + "'";
|
|
72
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method];
|
|
73
|
+
}
|
|
74
|
+
export function parseLatencyField(field) {
|
|
75
|
+
var parts = field.split('/');
|
|
76
|
+
if (parts.length !== 5)
|
|
77
|
+
return "invalid subsection count. Expected 5, got: " + parts.length;
|
|
78
|
+
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
|
|
79
|
+
var method = REVERSE_METHOD_NAMES[m];
|
|
80
|
+
if (!method)
|
|
81
|
+
return "unknown method '" + m + "'";
|
|
82
|
+
var bucket = parseInt(b);
|
|
83
|
+
if (isNaN(bucket) || bucket >= MAX_LATENCY_BUCKET_COUNT)
|
|
84
|
+
return "invalid bucket. Expected a number between 0 and " + (MAX_LATENCY_BUCKET_COUNT - 1) + ", got: " + b;
|
|
85
|
+
return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
|
|
86
|
+
}
|
|
@@ -32,7 +32,7 @@ export function dataLoaderFactory(preloadedData) {
|
|
|
32
32
|
storage.splits.clear();
|
|
33
33
|
storage.splits.setChangeNumber(since);
|
|
34
34
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
35
|
-
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return
|
|
35
|
+
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
|
|
36
36
|
// add mySegments data
|
|
37
37
|
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
38
38
|
if (!mySegmentsData) {
|
|
@@ -93,9 +93,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
93
93
|
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
94
94
|
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
95
95
|
this._decrementCounts(previousSplit);
|
|
96
|
-
localStorage.setItem(splitKey, split);
|
|
97
|
-
|
|
98
|
-
this._incrementCounts(parsedSplit);
|
|
96
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
97
|
+
this._incrementCounts(split);
|
|
99
98
|
return true;
|
|
100
99
|
}
|
|
101
100
|
catch (e) {
|
|
@@ -107,8 +106,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
107
106
|
try {
|
|
108
107
|
var split = this.getSplit(name);
|
|
109
108
|
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
110
|
-
|
|
111
|
-
this._decrementCounts(parsedSplit);
|
|
109
|
+
this._decrementCounts(split);
|
|
112
110
|
return true;
|
|
113
111
|
}
|
|
114
112
|
catch (e) {
|
|
@@ -117,7 +115,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
117
115
|
}
|
|
118
116
|
};
|
|
119
117
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
120
|
-
|
|
118
|
+
var item = localStorage.getItem(this.keys.buildSplitKey(name));
|
|
119
|
+
return item && JSON.parse(item);
|
|
121
120
|
};
|
|
122
121
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
123
122
|
// when cache is ready but using a new split query, we must clear all split data
|
|
@@ -201,7 +200,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
201
200
|
};
|
|
202
201
|
/**
|
|
203
202
|
* Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
204
|
-
* Clean operation (clear) also updates `lastUpdated` timestamp with current time.
|
|
205
203
|
*
|
|
206
204
|
* @param {number | undefined} expirationTimestamp if the value is not a number, data will not be cleaned
|
|
207
205
|
*/
|
|
@@ -11,8 +11,9 @@ import { SplitsCacheInMemory } from '../inMemory/SplitsCacheInMemory';
|
|
|
11
11
|
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
|
|
12
12
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
13
13
|
import { LOG_PREFIX } from './constants';
|
|
14
|
-
import {
|
|
14
|
+
import { NONE, STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
15
15
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
16
|
+
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
16
17
|
/**
|
|
17
18
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
18
19
|
*/
|
|
@@ -34,13 +35,16 @@ export function InLocalStorage(options) {
|
|
|
34
35
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
35
36
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
36
37
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
37
|
-
telemetry:
|
|
38
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory() : undefined,
|
|
39
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined,
|
|
38
40
|
destroy: function () {
|
|
41
|
+
var _a;
|
|
39
42
|
this.splits = new SplitsCacheInMemory();
|
|
40
43
|
this.segments = new MySegmentsCacheInMemory();
|
|
41
44
|
this.impressions.clear();
|
|
42
45
|
this.impressionCounts && this.impressionCounts.clear();
|
|
43
46
|
this.events.clear();
|
|
47
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
44
48
|
},
|
|
45
49
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
46
50
|
shared: function (matchingKey) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { truncateTimeFrame } from '../../utils/time';
|
|
2
|
+
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
2
3
|
var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
3
|
-
function ImpressionCountsCacheInMemory() {
|
|
4
|
+
function ImpressionCountsCacheInMemory(impressionCountsCacheSize) {
|
|
5
|
+
if (impressionCountsCacheSize === void 0) { impressionCountsCacheSize = DEFAULT_CACHE_SIZE; }
|
|
4
6
|
this.cache = {};
|
|
7
|
+
this.cacheSize = 0;
|
|
8
|
+
this.maxStorage = impressionCountsCacheSize;
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
11
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
@@ -16,6 +20,13 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
16
20
|
var key = this._makeKey(featureName, timeFrame);
|
|
17
21
|
var currentAmount = this.cache[key];
|
|
18
22
|
this.cache[key] = currentAmount ? currentAmount + amount : amount;
|
|
23
|
+
if (this.onFullQueue) {
|
|
24
|
+
this.cacheSize = this.cacheSize + amount;
|
|
25
|
+
if (this.cacheSize >= this.maxStorage) {
|
|
26
|
+
this.onFullQueue();
|
|
27
|
+
this.cacheSize = 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
19
30
|
};
|
|
20
31
|
/**
|
|
21
32
|
* Pop the collected data, used as payload for posting.
|
|
@@ -3,8 +3,9 @@ import { SegmentsCacheInMemory } from './SegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import {
|
|
7
|
-
import { TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
6
|
+
import { DEBUG, NONE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
|
+
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
+
import { UniqueKeysCacheInMemory } from './UniqueKeysCacheInMemory';
|
|
8
9
|
/**
|
|
9
10
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
10
11
|
*
|
|
@@ -15,16 +16,19 @@ export function InMemoryStorageFactory(params) {
|
|
|
15
16
|
splits: new SplitsCacheInMemory(),
|
|
16
17
|
segments: new SegmentsCacheInMemory(),
|
|
17
18
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
18
|
-
impressionCounts: params.
|
|
19
|
+
impressionCounts: params.impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
19
20
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
20
|
-
telemetry: params
|
|
21
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemory() : undefined,
|
|
21
23
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
22
24
|
destroy: function () {
|
|
25
|
+
var _a;
|
|
23
26
|
this.splits.clear();
|
|
24
27
|
this.segments.clear();
|
|
25
28
|
this.impressions.clear();
|
|
26
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
27
30
|
this.events.clear();
|
|
31
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
28
32
|
}
|
|
29
33
|
};
|
|
30
34
|
}
|
|
@@ -3,8 +3,9 @@ import { MySegmentsCacheInMemory } from './MySegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import {
|
|
6
|
+
import { DEBUG, NONE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
+
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
|
|
8
9
|
/**
|
|
9
10
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
10
11
|
*
|
|
@@ -15,16 +16,19 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
15
16
|
splits: new SplitsCacheInMemory(),
|
|
16
17
|
segments: new MySegmentsCacheInMemory(),
|
|
17
18
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
18
|
-
impressionCounts: params.
|
|
19
|
+
impressionCounts: params.impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
|
|
19
20
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
20
|
-
telemetry:
|
|
21
|
+
telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
+
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined,
|
|
21
23
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
22
24
|
destroy: function () {
|
|
25
|
+
var _a;
|
|
23
26
|
this.splits.clear();
|
|
24
27
|
this.segments.clear();
|
|
25
28
|
this.impressions.clear();
|
|
26
29
|
this.impressionCounts && this.impressionCounts.clear();
|
|
27
30
|
this.events.clear();
|
|
31
|
+
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
28
32
|
},
|
|
29
33
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
|
|
30
34
|
shared: function () {
|
|
@@ -22,9 +22,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
22
22
|
this.splitsWithSegmentsCount = 0;
|
|
23
23
|
};
|
|
24
24
|
SplitsCacheInMemory.prototype.addSplit = function (name, split) {
|
|
25
|
-
var
|
|
26
|
-
if (
|
|
27
|
-
var previousSplit = JSON.parse(splitFromMemory);
|
|
25
|
+
var previousSplit = this.getSplit(name);
|
|
26
|
+
if (previousSplit) { // We had this Split already
|
|
28
27
|
if (previousSplit.trafficTypeName) {
|
|
29
28
|
var previousTtName = previousSplit.trafficTypeName;
|
|
30
29
|
this.ttCache[previousTtName]--;
|
|
@@ -35,19 +34,18 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
35
34
|
this.splitsWithSegmentsCount--;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
if (parsedSplit) {
|
|
37
|
+
if (split) {
|
|
40
38
|
// Store the Split.
|
|
41
39
|
this.splitsCache[name] = split;
|
|
42
40
|
// Update TT cache
|
|
43
|
-
var ttName =
|
|
41
|
+
var ttName = split.trafficTypeName;
|
|
44
42
|
if (ttName) { // safeguard
|
|
45
43
|
if (!this.ttCache[ttName])
|
|
46
44
|
this.ttCache[ttName] = 0;
|
|
47
45
|
this.ttCache[ttName]++;
|
|
48
46
|
}
|
|
49
47
|
// Add to segments count for the new version of the Split
|
|
50
|
-
if (usesSegments(
|
|
48
|
+
if (usesSegments(split))
|
|
51
49
|
this.splitsWithSegmentsCount++;
|
|
52
50
|
return true;
|
|
53
51
|
}
|
|
@@ -60,15 +58,14 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
60
58
|
if (split) {
|
|
61
59
|
// Delete the Split
|
|
62
60
|
delete this.splitsCache[name];
|
|
63
|
-
var
|
|
64
|
-
var ttName = parsedSplit.trafficTypeName;
|
|
61
|
+
var ttName = split.trafficTypeName;
|
|
65
62
|
if (ttName) { // safeguard
|
|
66
63
|
this.ttCache[ttName]--; // Update tt cache
|
|
67
64
|
if (!this.ttCache[ttName])
|
|
68
65
|
delete this.ttCache[ttName];
|
|
69
66
|
}
|
|
70
67
|
// Update the segments count.
|
|
71
|
-
if (usesSegments(
|
|
68
|
+
if (usesSegments(split))
|
|
72
69
|
this.splitsWithSegmentsCount--;
|
|
73
70
|
return true;
|
|
74
71
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { LOCALHOST_MODE } from '../../utils/constants';
|
|
1
2
|
import { findLatencyIndex } from '../findLatencyIndex';
|
|
2
3
|
var MAX_STREAMING_EVENTS = 20;
|
|
3
4
|
var MAX_TAGS = 10;
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
export var MAX_LATENCY_BUCKET_COUNT = 23;
|
|
6
|
+
export function newBuckets() {
|
|
7
|
+
// MAX_LATENCY_BUCKET_COUNT (length) is 23
|
|
8
|
+
// Not using Array.fill for old browsers compatibility
|
|
6
9
|
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
7
10
|
}
|
|
8
11
|
var ACCEPTANCE_RANGE = 0.001;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* Record telemetry if mode is not localhost.
|
|
14
|
+
* All factory instances track telemetry on server-side, and 0.1% on client-side.
|
|
11
15
|
*/
|
|
12
|
-
export function shouldRecordTelemetry() {
|
|
13
|
-
return Math.random() <= ACCEPTANCE_RANGE;
|
|
16
|
+
export function shouldRecordTelemetry(params) {
|
|
17
|
+
return params.mode !== LOCALHOST_MODE && (params.matchingKey === undefined || Math.random() <= ACCEPTANCE_RANGE);
|
|
14
18
|
}
|
|
15
19
|
var TelemetryCacheInMemory = /** @class */ (function () {
|
|
16
20
|
function TelemetryCacheInMemory() {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { setToArray, _Set } from '../../utils/lang/sets';
|
|
2
|
+
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
3
|
+
var UniqueKeysCacheInMemory = /** @class */ (function () {
|
|
4
|
+
function UniqueKeysCacheInMemory(uniqueKeysQueueSize) {
|
|
5
|
+
if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
|
|
6
|
+
this.uniqueTrackerSize = 0;
|
|
7
|
+
this.maxStorage = uniqueKeysQueueSize;
|
|
8
|
+
this.uniqueKeysTracker = {};
|
|
9
|
+
}
|
|
10
|
+
UniqueKeysCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
|
|
11
|
+
this.onFullQueue = cb;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Store unique keys in sequential order
|
|
15
|
+
* key: string = feature name.
|
|
16
|
+
* value: Set<string> = set of unique keys.
|
|
17
|
+
*/
|
|
18
|
+
UniqueKeysCacheInMemory.prototype.track = function (key, featureName) {
|
|
19
|
+
if (!this.uniqueKeysTracker[featureName])
|
|
20
|
+
this.uniqueKeysTracker[featureName] = new _Set();
|
|
21
|
+
var tracker = this.uniqueKeysTracker[featureName];
|
|
22
|
+
if (!tracker.has(key)) {
|
|
23
|
+
tracker.add(key);
|
|
24
|
+
this.uniqueTrackerSize++;
|
|
25
|
+
}
|
|
26
|
+
if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
|
|
27
|
+
this.uniqueTrackerSize = 0;
|
|
28
|
+
this.onFullQueue();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Clear the data stored on the cache.
|
|
33
|
+
*/
|
|
34
|
+
UniqueKeysCacheInMemory.prototype.clear = function () {
|
|
35
|
+
this.uniqueKeysTracker = {};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Pop the collected data, used as payload for posting.
|
|
39
|
+
*/
|
|
40
|
+
UniqueKeysCacheInMemory.prototype.pop = function () {
|
|
41
|
+
var data = this.uniqueKeysTracker;
|
|
42
|
+
this.uniqueKeysTracker = {};
|
|
43
|
+
return this.fromUniqueKeysCollector(data);
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Check if the cache is empty.
|
|
47
|
+
*/
|
|
48
|
+
UniqueKeysCacheInMemory.prototype.isEmpty = function () {
|
|
49
|
+
return Object.keys(this.uniqueKeysTracker).length === 0;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Converts `uniqueKeys` data from cache into request payload for SS.
|
|
53
|
+
*/
|
|
54
|
+
UniqueKeysCacheInMemory.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
|
|
55
|
+
var payload = [];
|
|
56
|
+
var featureNames = Object.keys(uniqueKeys);
|
|
57
|
+
for (var i = 0; i < featureNames.length; i++) {
|
|
58
|
+
var featureName = featureNames[i];
|
|
59
|
+
var featureKeys = setToArray(uniqueKeys[featureName]);
|
|
60
|
+
var uniqueKeysPayload = {
|
|
61
|
+
f: featureName,
|
|
62
|
+
ks: featureKeys
|
|
63
|
+
};
|
|
64
|
+
payload.push(uniqueKeysPayload);
|
|
65
|
+
}
|
|
66
|
+
return { keys: payload };
|
|
67
|
+
};
|
|
68
|
+
return UniqueKeysCacheInMemory;
|
|
69
|
+
}());
|
|
70
|
+
export { UniqueKeysCacheInMemory };
|