@splitsoftware/splitio-commons 1.2.1-rc.0 → 1.2.1-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/cjs/evaluator/Engine.js +6 -6
- package/cjs/evaluator/combiners/and.js +1 -1
- package/cjs/evaluator/combiners/ifelseif.js +2 -2
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/condition/index.js +4 -4
- package/cjs/evaluator/index.js +5 -5
- package/cjs/evaluator/matchers/cont_all.js +1 -1
- package/cjs/evaluator/matchers/cont_any.js +1 -1
- package/cjs/evaluator/matchers/cont_str.js +1 -1
- package/cjs/evaluator/matchers/dependency.js +1 -1
- package/cjs/evaluator/matchers/eq_set.js +1 -1
- package/cjs/evaluator/matchers/ew.js +3 -3
- package/cjs/evaluator/matchers/part_of.js +1 -1
- package/cjs/evaluator/matchers/segment.js +1 -1
- package/cjs/evaluator/matchers/sw.js +1 -1
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/evaluator/matchersTransform/index.js +12 -12
- package/cjs/evaluator/parser/index.js +6 -6
- package/cjs/evaluator/treatments/index.js +1 -1
- package/cjs/evaluator/value/index.js +1 -1
- package/cjs/evaluator/value/sanitize.js +4 -4
- package/cjs/integrations/browser.js +3 -3
- package/cjs/integrations/ga/GaToSplit.js +14 -14
- package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +5 -3
- package/cjs/integrations/ga/SplitToGa.js +1 -1
- package/cjs/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/cjs/listeners/browser.js +15 -11
- package/cjs/listeners/node.js +1 -1
- package/cjs/logger/constants.js +9 -3
- package/cjs/logger/index.js +2 -2
- package/cjs/logger/messages/debug.js +4 -4
- package/cjs/logger/messages/error.js +5 -4
- package/cjs/logger/messages/info.js +8 -5
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/logger/sdkLogger.js +1 -1
- package/cjs/readiness/readinessManager.js +2 -2
- package/cjs/readiness/sdkReadinessManager.js +4 -4
- package/cjs/sdkClient/client.js +12 -11
- package/cjs/sdkClient/clientAttributesDecoration.js +4 -4
- package/cjs/sdkClient/clientCS.js +3 -3
- package/cjs/sdkClient/clientInputValidation.js +20 -22
- package/cjs/sdkClient/sdkClient.js +3 -6
- package/cjs/sdkClient/sdkClientMethod.js +1 -1
- package/cjs/sdkClient/sdkClientMethodCS.js +6 -10
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +7 -15
- package/cjs/sdkFactory/index.js +14 -12
- package/cjs/sdkFactory/userConsentProps.js +40 -0
- package/cjs/sdkManager/index.js +11 -11
- package/cjs/services/splitApi.js +3 -2
- package/cjs/services/splitHttpClient.js +2 -2
- package/cjs/storages/KeyBuilder.js +2 -6
- package/cjs/storages/KeyBuilderCS.js +13 -3
- package/cjs/storages/KeyBuilderSS.js +1 -1
- package/cjs/storages/findLatencyIndex.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +24 -4
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -12
- package/cjs/storages/inLocalStorage/index.js +4 -4
- package/cjs/storages/inMemory/AttributesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +1 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/cjs/storages/inMemory/LatenciesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +2 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/LatenciesCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +24 -11
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +3 -3
- package/cjs/storages/inRedis/index.js +1 -1
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +3 -3
- package/cjs/storages/pluggable/inMemoryWrapper.js +4 -4
- package/cjs/storages/pluggable/index.js +6 -6
- package/cjs/sync/offline/LocalhostFromFile.js +1 -1
- package/cjs/sync/offline/LocalhostFromObject.js +1 -1
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +13 -13
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +3 -3
- package/cjs/sync/offline/syncManagerOffline.js +1 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -2
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +8 -7
- package/cjs/sync/polling/pollingManagerSS.js +5 -4
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -2
- package/cjs/sync/streaming/AuthClient/index.js +3 -3
- package/cjs/sync/streaming/SSEClient/index.js +2 -1
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +3 -3
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +1 -1
- package/cjs/sync/streaming/pushManager.js +27 -19
- package/cjs/sync/submitters/eventsSyncTask.js +17 -5
- package/cjs/sync/submitters/impressionCountsSyncTask.js +1 -1
- package/cjs/sync/submitters/impressionsSyncTask.js +15 -3
- package/cjs/sync/submitters/metricsSyncTask.js +3 -3
- package/cjs/sync/submitters/submitterManager.js +6 -5
- package/cjs/sync/submitters/submitterSyncTask.js +1 -1
- package/cjs/sync/syncManagerOnline.js +14 -15
- package/cjs/trackers/eventTracker.js +11 -4
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +1 -1
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +1 -1
- package/cjs/trackers/impressionObserver/utils.js +8 -1
- package/cjs/trackers/impressionsTracker.js +9 -8
- package/cjs/utils/MinEvents.js +2 -1
- package/cjs/utils/consent.js +10 -0
- package/cjs/utils/constants/index.js +5 -1
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +4 -4
- package/cjs/utils/inputValidation/attributes.js +2 -2
- package/cjs/utils/inputValidation/event.js +1 -1
- package/cjs/utils/inputValidation/eventProperties.js +7 -5
- package/cjs/utils/inputValidation/eventValue.js +1 -1
- package/cjs/utils/inputValidation/key.js +6 -5
- package/cjs/utils/inputValidation/preloadedData.js +8 -8
- package/cjs/utils/inputValidation/split.js +1 -1
- package/cjs/utils/inputValidation/splits.js +2 -2
- package/cjs/utils/inputValidation/trafficType.js +1 -1
- package/cjs/utils/inputValidation/trafficTypeExistance.js +1 -1
- package/cjs/utils/jwt/index.js +1 -1
- package/cjs/utils/key/index.js +3 -3
- package/cjs/utils/lang/index.js +13 -16
- package/cjs/utils/lang/maps.js +16 -2
- package/cjs/utils/murmur3/common.js +1 -1
- package/cjs/utils/murmur3/murmur3.js +10 -10
- package/cjs/utils/murmur3/murmur3_128.js +1 -1
- package/cjs/utils/murmur3/murmur3_128_x86.js +37 -37
- package/cjs/utils/murmur3/murmur3_64.js +1 -1
- package/cjs/utils/settingsValidation/consent.js +16 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +6 -6
- package/cjs/utils/settingsValidation/index.js +32 -14
- package/cjs/utils/settingsValidation/integrations/configurable.js +1 -1
- package/cjs/utils/settingsValidation/integrations/pluggable.js +1 -1
- package/cjs/utils/settingsValidation/localhost/builtin.js +2 -2
- package/cjs/utils/settingsValidation/logger/builtinLogger.js +3 -3
- package/cjs/utils/settingsValidation/logger/commons.js +1 -1
- package/cjs/utils/settingsValidation/logger/pluggableLogger.js +1 -1
- package/cjs/utils/settingsValidation/runtime.js +11 -0
- package/cjs/utils/settingsValidation/splitFilters.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/cjs/utils/timeTracker/index.js +3 -3
- package/esm/evaluator/matchers/ew.js +4 -4
- package/esm/integrations/ga/GoogleAnalyticsToSplit.js +4 -2
- package/esm/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/esm/listeners/browser.js +14 -10
- package/esm/logger/constants.js +6 -2
- package/esm/logger/messages/debug.js +3 -3
- package/esm/logger/messages/error.js +4 -3
- package/esm/logger/messages/info.js +7 -4
- package/esm/sdkClient/client.js +3 -2
- package/esm/sdkClient/clientCS.js +1 -1
- package/esm/sdkClient/clientInputValidation.js +6 -8
- package/esm/sdkClient/sdkClient.js +1 -4
- package/esm/sdkClient/sdkClientMethodCS.js +1 -5
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +1 -9
- package/esm/sdkFactory/index.js +8 -6
- package/esm/sdkFactory/userConsentProps.js +36 -0
- package/esm/services/splitApi.js +2 -1
- package/esm/storages/KeyBuilder.js +2 -6
- package/esm/storages/KeyBuilderCS.js +11 -1
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +23 -3
- package/esm/storages/inLocalStorage/index.js +1 -1
- package/esm/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/esm/storages/inMemory/InMemoryStorage.js +1 -1
- package/esm/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +15 -2
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +1 -1
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +2 -1
- package/esm/sync/polling/pollingManagerSS.js +2 -1
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/streaming/SSEClient/index.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/esm/sync/streaming/pushManager.js +13 -5
- package/esm/sync/submitters/eventsSyncTask.js +18 -6
- package/esm/sync/submitters/impressionsSyncTask.js +13 -1
- package/esm/sync/submitters/submitterManager.js +2 -1
- package/esm/sync/syncManagerOnline.js +14 -15
- package/esm/trackers/eventTracker.js +8 -1
- package/esm/trackers/impressionObserver/utils.js +7 -1
- package/esm/trackers/impressionsTracker.js +6 -5
- package/esm/utils/consent.js +6 -0
- package/esm/utils/constants/index.js +4 -0
- package/esm/utils/inputValidation/attributes.js +1 -1
- package/esm/utils/inputValidation/eventProperties.js +4 -2
- package/esm/utils/inputValidation/key.js +2 -1
- package/esm/utils/lang/index.js +12 -15
- package/esm/utils/lang/maps.js +14 -1
- package/esm/utils/settingsValidation/consent.js +12 -0
- package/esm/utils/settingsValidation/impressionsMode.js +7 -7
- package/esm/utils/settingsValidation/index.js +28 -10
- package/esm/utils/settingsValidation/runtime.js +7 -0
- package/package.json +6 -6
- package/src/evaluator/matchers/ew.ts +4 -4
- package/src/evaluator/parser/index.ts +1 -1
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +2 -2
- package/src/integrations/ga/GoogleAnalyticsToSplit.ts +7 -4
- package/src/integrations/ga/SplitToGoogleAnalytics.ts +7 -4
- package/src/integrations/pluggable.ts +2 -2
- package/src/integrations/types.ts +5 -0
- package/src/listeners/browser.ts +13 -9
- package/src/logger/constants.ts +6 -2
- package/src/logger/messages/debug.ts +3 -3
- package/src/logger/messages/error.ts +4 -3
- package/src/logger/messages/info.ts +7 -4
- package/src/logger/types.ts +4 -0
- package/src/sdkClient/client.ts +3 -2
- package/src/sdkClient/clientCS.ts +1 -1
- package/src/sdkClient/clientInputValidation.ts +8 -7
- package/src/sdkClient/sdkClient.ts +2 -5
- package/src/sdkClient/sdkClientMethodCS.ts +1 -6
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +2 -11
- package/src/sdkFactory/index.ts +9 -7
- package/src/sdkFactory/types.ts +2 -1
- package/src/sdkFactory/userConsentProps.ts +42 -0
- package/src/storages/KeyBuilder.ts +2 -6
- package/src/storages/KeyBuilderCS.ts +13 -1
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +23 -3
- package/src/storages/inLocalStorage/index.ts +1 -1
- package/src/storages/inMemory/ImpressionsCacheInMemory.ts +22 -1
- package/src/storages/inMemory/InMemoryStorage.ts +1 -1
- package/src/storages/inMemory/InMemoryStorageCS.ts +1 -1
- package/src/storages/inRedis/RedisAdapter.ts +8 -2
- package/src/storages/pluggable/index.ts +2 -2
- package/src/storages/types.ts +6 -2
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +1 -1
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +2 -1
- package/src/sync/polling/fetchers/types.ts +1 -0
- package/src/sync/polling/pollingManagerCS.ts +3 -6
- package/src/sync/polling/pollingManagerSS.ts +3 -8
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +2 -1
- package/src/sync/polling/types.ts +0 -12
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -1
- package/src/sync/streaming/SSEClient/index.ts +2 -1
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
- package/src/sync/streaming/pushManager.ts +19 -16
- package/src/sync/streaming/types.ts +5 -25
- package/src/sync/submitters/eventsSyncTask.ts +19 -6
- package/src/sync/submitters/impressionsSyncTask.ts +16 -1
- package/src/sync/submitters/submitterManager.ts +4 -8
- package/src/sync/syncManagerOnline.ts +20 -24
- package/src/sync/types.ts +4 -1
- package/src/trackers/eventTracker.ts +11 -3
- package/src/trackers/impressionObserver/utils.ts +8 -1
- package/src/trackers/impressionsTracker.ts +7 -8
- package/src/types.ts +22 -1
- package/src/utils/consent.ts +8 -0
- package/src/utils/constants/index.ts +5 -0
- package/src/utils/inputValidation/attributes.ts +1 -2
- package/src/utils/inputValidation/eventProperties.ts +4 -2
- package/src/utils/lang/index.ts +15 -18
- package/src/utils/lang/maps.ts +15 -1
- package/src/utils/settingsValidation/consent.ts +16 -0
- package/src/utils/settingsValidation/impressionsMode.ts +8 -8
- package/src/utils/settingsValidation/index.ts +29 -10
- package/src/utils/settingsValidation/runtime.ts +9 -0
- package/src/utils/settingsValidation/types.ts +12 -6
- package/types/evaluator/types.d.ts +2 -2
- package/types/evaluator/value/index.d.ts +1 -1
- package/types/evaluator/value/sanitize.d.ts +1 -1
- package/types/integrations/ga/GoogleAnalyticsToSplit.d.ts +2 -2
- package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +2 -3
- package/types/integrations/types.d.ts +4 -0
- package/types/logger/constants.d.ts +6 -2
- package/types/logger/types.d.ts +4 -0
- package/types/sdkClient/clientAttributesDecoration.d.ts +1 -1
- package/types/sdkClient/clientInputValidation.d.ts +2 -3
- package/types/sdkFactory/types.d.ts +1 -1
- package/types/sdkFactory/userConsentProps.d.ts +6 -0
- package/types/storages/KeyBuilderCS.d.ts +2 -0
- package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +9 -0
- package/types/storages/inMemory/index.d.ts +10 -0
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
- package/types/storages/parseSegments.d.ts +6 -0
- package/types/storages/types.d.ts +3 -1
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +1 -1
- package/types/sync/polling/fetchers/types.d.ts +1 -1
- package/types/sync/polling/pollingManagerCS.d.ts +2 -5
- package/types/sync/polling/pollingManagerSS.d.ts +2 -5
- package/types/sync/polling/types.d.ts +0 -11
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +1 -1
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -1
- package/types/sync/streaming/pushManager.d.ts +3 -7
- package/types/sync/streaming/pushManagerCS.d.ts +1 -12
- package/types/sync/streaming/pushManagerSS.d.ts +1 -11
- package/types/sync/streaming/types.d.ts +3 -23
- package/types/sync/submitters/submitterManager.d.ts +2 -4
- package/types/sync/syncManagerOnline.d.ts +3 -3
- package/types/sync/types.d.ts +3 -0
- package/types/trackers/eventTracker.d.ts +2 -2
- package/types/trackers/impressionObserver/utils.d.ts +4 -0
- package/types/trackers/impressionsTracker.d.ts +2 -3
- package/types/types.d.ts +22 -1
- package/types/utils/consent.d.ts +2 -0
- package/types/utils/constants/index.d.ts +3 -0
- package/types/utils/lang/index.d.ts +6 -5
- package/types/utils/lang/maps.d.ts +7 -0
- package/types/utils/settingsValidation/consent.d.ts +6 -0
- package/types/utils/settingsValidation/impressionsMode.d.ts +1 -1
- package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
- package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
- package/types/utils/settingsValidation/runtime.d.ts +2 -0
- package/types/utils/settingsValidation/types.d.ts +12 -6
- package/types/utils/settingsValidation/userConsent.d.ts +5 -0
|
@@ -21,17 +21,9 @@ var method = 'Client instantiation';
|
|
|
21
21
|
*/
|
|
22
22
|
function sdkClientMethodCSFactory(params) {
|
|
23
23
|
var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var validKey = key_1.validateKey(log, key, method);
|
|
28
|
-
var validTrafficType;
|
|
29
|
-
if (trafficType !== undefined) {
|
|
30
|
-
validTrafficType = trafficType_1.validateTrafficType(log, trafficType, method);
|
|
31
|
-
}
|
|
32
|
-
var mainClientInstance = clientCS_1.clientCSDecorator(log, sdkClient_1.sdkClientFactory(params), // @ts-ignore
|
|
33
|
-
validKey, validTrafficType);
|
|
34
|
-
var parsedDefaultKey = key_2.keyParser(key);
|
|
24
|
+
var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), // @ts-ignore
|
|
25
|
+
key, trafficType);
|
|
26
|
+
var parsedDefaultKey = (0, key_2.keyParser)(key);
|
|
35
27
|
var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
|
|
36
28
|
// Cache instances created per factory.
|
|
37
29
|
var clientInstances = {};
|
|
@@ -42,20 +34,20 @@ function sdkClientMethodCSFactory(params) {
|
|
|
42
34
|
return mainClientInstance;
|
|
43
35
|
}
|
|
44
36
|
// Validate the key value
|
|
45
|
-
var validKey = key_1.validateKey(log, key, "Shared " + method);
|
|
37
|
+
var validKey = (0, key_1.validateKey)(log, key, "Shared " + method);
|
|
46
38
|
if (validKey === false) {
|
|
47
39
|
throw new Error('Shared Client needs a valid key.');
|
|
48
40
|
}
|
|
49
41
|
var validTrafficType;
|
|
50
42
|
if (trafficType !== undefined) {
|
|
51
|
-
validTrafficType = trafficType_1.validateTrafficType(log, trafficType, "Shared " + method);
|
|
43
|
+
validTrafficType = (0, trafficType_1.validateTrafficType)(log, trafficType, "Shared " + method);
|
|
52
44
|
if (validTrafficType === false) {
|
|
53
45
|
throw new Error('Shared Client needs a valid traffic type or no traffic type at all.');
|
|
54
46
|
}
|
|
55
47
|
}
|
|
56
48
|
var instanceId = buildInstanceId(validKey, validTrafficType);
|
|
57
49
|
if (!clientInstances[instanceId]) {
|
|
58
|
-
var matchingKey = key_2.getMatching(validKey);
|
|
50
|
+
var matchingKey = (0, key_2.getMatching)(validKey);
|
|
59
51
|
var sharedSdkReadiness_1 = sdkReadinessManager.shared(readyTimeout);
|
|
60
52
|
var sharedStorage = storage.shared && storage.shared(matchingKey, function (err) {
|
|
61
53
|
if (err)
|
|
@@ -71,7 +63,7 @@ function sdkClientMethodCSFactory(params) {
|
|
|
71
63
|
var sharedSyncManager = syncManager && sharedStorage && syncManager.shared(matchingKey, sharedSdkReadiness_1.readinessManager, sharedStorage);
|
|
72
64
|
// As shared clients reuse all the storage information, we don't need to check here if we
|
|
73
65
|
// will use offline or online mode. We should stick with the original decision.
|
|
74
|
-
clientInstances[instanceId] = clientCS_1.clientCSDecorator(log, sdkClient_1.sdkClientFactory(objectAssign_1.objectAssign({}, params, {
|
|
66
|
+
clientInstances[instanceId] = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)((0, objectAssign_1.objectAssign)({}, params, {
|
|
75
67
|
sdkReadinessManager: sharedSdkReadiness_1,
|
|
76
68
|
storage: sharedStorage || storage,
|
|
77
69
|
syncManager: sharedSyncManager,
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -11,24 +11,26 @@ var sdkLogger_1 = require("../logger/sdkLogger");
|
|
|
11
11
|
var constants_1 = require("../logger/constants");
|
|
12
12
|
var metadataBuilder_1 = require("../storages/metadataBuilder");
|
|
13
13
|
var constants_2 = require("../readiness/constants");
|
|
14
|
+
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
14
15
|
/**
|
|
15
16
|
* Modular SDK factory
|
|
16
17
|
*/
|
|
17
18
|
function sdkFactory(params) {
|
|
18
|
-
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory,
|
|
19
|
+
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;
|
|
19
20
|
var log = settings.log;
|
|
20
21
|
// @TODO handle non-recoverable errors: not start sync, mark the SDK as destroyed, etc.
|
|
21
22
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
22
|
-
apiKey_1.validateAndTrackApiKey(log, settings.core.authorizationKey);
|
|
23
|
+
(0, apiKey_1.validateAndTrackApiKey)(log, settings.core.authorizationKey);
|
|
23
24
|
// @TODO handle non-recoverable error, such as, `fetch` api not available, invalid API Key, etc.
|
|
24
|
-
var sdkReadinessManager = sdkReadinessManager_1.sdkReadinessManagerFactory(log, platform.EventEmitter, settings.startup.readyTimeout);
|
|
25
|
+
var sdkReadinessManager = (0, sdkReadinessManager_1.sdkReadinessManagerFactory)(log, platform.EventEmitter, settings.startup.readyTimeout);
|
|
25
26
|
var readinessManager = sdkReadinessManager.readinessManager;
|
|
26
27
|
// @TODO consider passing the settings object, so that each storage access only what it needs
|
|
27
28
|
var storageFactoryParams = {
|
|
29
|
+
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
28
30
|
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
29
|
-
optimize: utils_1.shouldBeOptimized(settings),
|
|
31
|
+
optimize: (0, utils_1.shouldBeOptimized)(settings),
|
|
30
32
|
// ATM, only used by InLocalStorage
|
|
31
|
-
matchingKey: key_1.getMatching(settings.core.key),
|
|
33
|
+
matchingKey: (0, key_1.getMatching)(settings.core.key),
|
|
32
34
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
33
35
|
// ATM, only used by PluggableStorage
|
|
34
36
|
mode: settings.mode,
|
|
@@ -40,7 +42,7 @@ function sdkFactory(params) {
|
|
|
40
42
|
readinessManager.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
|
|
41
43
|
readinessManager.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
42
44
|
},
|
|
43
|
-
metadata: metadataBuilder_1.metadataBuilder(settings),
|
|
45
|
+
metadata: (0, metadataBuilder_1.metadataBuilder)(settings),
|
|
44
46
|
log: log
|
|
45
47
|
};
|
|
46
48
|
var storage = storageFactory(storageFactoryParams);
|
|
@@ -57,8 +59,8 @@ function sdkFactory(params) {
|
|
|
57
59
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
|
|
58
60
|
// trackers
|
|
59
61
|
var observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
60
|
-
var impressionsTracker = impressionsTracker_1.impressionsTrackerFactory(
|
|
61
|
-
var eventTracker = eventTracker_1.eventTrackerFactory(
|
|
62
|
+
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts);
|
|
63
|
+
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager);
|
|
62
64
|
// signal listener
|
|
63
65
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
|
64
66
|
// Sdk client and manager
|
|
@@ -67,18 +69,18 @@ function sdkFactory(params) {
|
|
|
67
69
|
syncManager && syncManager.start();
|
|
68
70
|
signalListener && signalListener.start();
|
|
69
71
|
log.info(constants_1.NEW_FACTORY);
|
|
70
|
-
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
return (0, objectAssign_1.objectAssign)({
|
|
71
74
|
// Split evaluation and event tracking engine
|
|
72
75
|
client: clientMethod,
|
|
73
76
|
// Manager API to explore available information
|
|
74
|
-
// @ts-ignore
|
|
75
77
|
manager: function () {
|
|
76
78
|
log.debug(constants_1.RETRIEVE_MANAGER);
|
|
77
79
|
return managerInstance;
|
|
78
80
|
},
|
|
79
81
|
// Logger wrapper API
|
|
80
|
-
Logger: sdkLogger_1.createLoggerAPI(settings.log),
|
|
82
|
+
Logger: (0, sdkLogger_1.createLoggerAPI)(settings.log),
|
|
81
83
|
settings: settings,
|
|
82
|
-
};
|
|
84
|
+
}, extraProps && extraProps(settings, syncManager));
|
|
83
85
|
}
|
|
84
86
|
exports.sdkFactory = sdkFactory;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.userConsentProps = void 0;
|
|
4
|
+
var constants_1 = require("../logger/constants");
|
|
5
|
+
var consent_1 = require("../utils/consent");
|
|
6
|
+
var constants_2 = require("../utils/constants");
|
|
7
|
+
var lang_1 = require("../utils/lang");
|
|
8
|
+
// Extend client-side factory instances with user consent getter/setter
|
|
9
|
+
function userConsentProps(settings, syncManager) {
|
|
10
|
+
var log = settings.log;
|
|
11
|
+
if (!(0, consent_1.isConsentGranted)(settings))
|
|
12
|
+
log.info(constants_1.USER_CONSENT_INITIAL, [settings.userConsent]);
|
|
13
|
+
return {
|
|
14
|
+
setUserConsent: function (consent) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
// validate input param
|
|
17
|
+
if (!(0, lang_1.isBoolean)(consent)) {
|
|
18
|
+
log.warn(constants_1.ERROR_NOT_BOOLEAN, ['setUserConsent']);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
var newConsentStatus = consent ? constants_2.CONSENT_GRANTED : constants_2.CONSENT_DECLINED;
|
|
22
|
+
if (settings.userConsent !== newConsentStatus) {
|
|
23
|
+
log.info(constants_1.USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
|
|
24
|
+
settings.userConsent = newConsentStatus;
|
|
25
|
+
if (consent)
|
|
26
|
+
(_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
|
|
27
|
+
else
|
|
28
|
+
(_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
log.info(constants_1.USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
getUserConsent: function () {
|
|
36
|
+
return settings.userConsent;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.userConsentProps = userConsentProps;
|
package/cjs/sdkManager/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var inputValidation_1 = require("../utils/inputValidation");
|
|
|
8
8
|
function collectTreatments(splitObject) {
|
|
9
9
|
var conditions = splitObject.conditions;
|
|
10
10
|
// Rollout conditions are supposed to have the entire partitions list, so we find the first one.
|
|
11
|
-
var allTreatmentsCondition = lang_1.find(conditions, function (cond) { return cond.conditionType === 'ROLLOUT'; });
|
|
11
|
+
var allTreatmentsCondition = (0, lang_1.find)(conditions, function (cond) { return cond.conditionType === 'ROLLOUT'; });
|
|
12
12
|
// Localstorage mode could fall into a no rollout conditions state. Take the first condition in that case.
|
|
13
13
|
if (!allTreatmentsCondition)
|
|
14
14
|
allTreatmentsCondition = conditions[0];
|
|
@@ -47,36 +47,36 @@ function objectsToViews(jsons) {
|
|
|
47
47
|
function sdkManagerFactory(log, splits, _a) {
|
|
48
48
|
var readinessManager = _a.readinessManager, sdkStatus = _a.sdkStatus;
|
|
49
49
|
var SPLIT_FN_LABEL = 'split';
|
|
50
|
-
return objectAssign_1.objectAssign(
|
|
50
|
+
return (0, objectAssign_1.objectAssign)(
|
|
51
51
|
// Proto-linkage of the readiness Event Emitter
|
|
52
52
|
Object.create(sdkStatus), {
|
|
53
53
|
/**
|
|
54
54
|
* Get the Split object corresponding to the given split name if valid
|
|
55
55
|
*/
|
|
56
56
|
split: function (maybeSplitName) {
|
|
57
|
-
var splitName = inputValidation_1.validateSplit(log, maybeSplitName, SPLIT_FN_LABEL);
|
|
58
|
-
if (!inputValidation_1.validateIfNotDestroyed(log, readinessManager, SPLIT_FN_LABEL) || !inputValidation_1.validateIfOperational(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
|
|
57
|
+
var splitName = (0, inputValidation_1.validateSplit)(log, maybeSplitName, SPLIT_FN_LABEL);
|
|
58
|
+
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, SPLIT_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
|
|
59
59
|
return null;
|
|
60
60
|
}
|
|
61
61
|
var split = splits.getSplit(splitName);
|
|
62
|
-
if (thenable_1.thenable(split)) {
|
|
62
|
+
if ((0, thenable_1.thenable)(split)) {
|
|
63
63
|
return split.catch(function () { return null; }).then(function (result) {
|
|
64
|
-
inputValidation_1.validateSplitExistance(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
|
|
64
|
+
(0, inputValidation_1.validateSplitExistance)(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
|
|
65
65
|
return objectToView(result);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
inputValidation_1.validateSplitExistance(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
|
|
68
|
+
(0, inputValidation_1.validateSplitExistance)(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
|
|
69
69
|
return objectToView(split);
|
|
70
70
|
},
|
|
71
71
|
/**
|
|
72
72
|
* Get the Split objects present on the factory storage
|
|
73
73
|
*/
|
|
74
74
|
splits: function () {
|
|
75
|
-
if (!inputValidation_1.validateIfNotDestroyed(log, readinessManager, 'splits') || !inputValidation_1.validateIfOperational(log, readinessManager, 'splits')) {
|
|
75
|
+
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, 'splits') || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, 'splits')) {
|
|
76
76
|
return [];
|
|
77
77
|
}
|
|
78
78
|
var currentSplits = splits.getAll();
|
|
79
|
-
return thenable_1.thenable(currentSplits) ?
|
|
79
|
+
return (0, thenable_1.thenable)(currentSplits) ?
|
|
80
80
|
currentSplits.catch(function () { return []; }).then(objectsToViews) : // handle possible rejections when using pluggable storage
|
|
81
81
|
objectsToViews(currentSplits);
|
|
82
82
|
},
|
|
@@ -84,11 +84,11 @@ function sdkManagerFactory(log, splits, _a) {
|
|
|
84
84
|
* Get the Split names present on the factory storage
|
|
85
85
|
*/
|
|
86
86
|
names: function () {
|
|
87
|
-
if (!inputValidation_1.validateIfNotDestroyed(log, readinessManager, 'names') || !inputValidation_1.validateIfOperational(log, readinessManager, 'names')) {
|
|
87
|
+
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, 'names') || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, 'names')) {
|
|
88
88
|
return [];
|
|
89
89
|
}
|
|
90
90
|
var splitNames = splits.getSplitNames();
|
|
91
|
-
return thenable_1.thenable(splitNames) ?
|
|
91
|
+
return (0, thenable_1.thenable)(splitNames) ?
|
|
92
92
|
splitNames.catch(function () { return []; }) : // handle possible rejections when using pluggable storage
|
|
93
93
|
splitNames;
|
|
94
94
|
}
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -17,7 +17,7 @@ function splitApiFactory(settings, platform) {
|
|
|
17
17
|
var urls = settings.urls;
|
|
18
18
|
var filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
|
|
19
19
|
var SplitSDKImpressionsMode = settings.sync.impressionsMode;
|
|
20
|
-
var splitHttpClient = splitHttpClient_1.splitHttpClientFactory(settings, platform.getFetch, platform.getOptions);
|
|
20
|
+
var splitHttpClient = (0, splitHttpClient_1.splitHttpClientFactory)(settings, platform.getFetch, platform.getOptions);
|
|
21
21
|
return {
|
|
22
22
|
getSdkAPIHealthCheck: function () {
|
|
23
23
|
var url = urls.sdk + "/version";
|
|
@@ -75,7 +75,8 @@ function splitApiFactory(settings, platform) {
|
|
|
75
75
|
return splitHttpClient(url, {
|
|
76
76
|
// Adding extra headers to send impressions in OPTIMIZED or DEBUG modes.
|
|
77
77
|
method: 'POST',
|
|
78
|
-
body: body,
|
|
78
|
+
body: body,
|
|
79
|
+
headers: (0, objectAssign_1.objectAssign)({ SplitSDKImpressionsMode: SplitSDKImpressionsMode }, headers)
|
|
79
80
|
});
|
|
80
81
|
},
|
|
81
82
|
/**
|
|
@@ -31,8 +31,8 @@ function splitHttpClientFactory(settings, getFetch, getOptions) {
|
|
|
31
31
|
return function httpClient(url, reqOpts, logErrorsAsInfo) {
|
|
32
32
|
if (reqOpts === void 0) { reqOpts = {}; }
|
|
33
33
|
if (logErrorsAsInfo === void 0) { logErrorsAsInfo = false; }
|
|
34
|
-
var request = objectAssign_1.objectAssign({
|
|
35
|
-
headers: reqOpts.headers ? objectAssign_1.objectAssign({}, headers, reqOpts.headers) : headers,
|
|
34
|
+
var request = (0, objectAssign_1.objectAssign)({
|
|
35
|
+
headers: reqOpts.headers ? (0, objectAssign_1.objectAssign)({}, headers, reqOpts.headers) : headers,
|
|
36
36
|
method: reqOpts.method || 'GET',
|
|
37
37
|
body: reqOpts.body
|
|
38
38
|
}, options);
|
|
@@ -5,11 +5,7 @@ var lang_1 = require("../utils/lang");
|
|
|
5
5
|
var everythingAtTheEnd = /[^.]+$/;
|
|
6
6
|
var DEFAULT_PREFIX = 'SPLITIO';
|
|
7
7
|
function validatePrefix(prefix) {
|
|
8
|
-
return prefix
|
|
9
|
-
lang_1.endsWith(prefix, '.' + DEFAULT_PREFIX) ?
|
|
10
|
-
prefix : // suffix already appended
|
|
11
|
-
prefix + '.' + DEFAULT_PREFIX : // append suffix
|
|
12
|
-
DEFAULT_PREFIX; // use default prefix if none is provided
|
|
8
|
+
return prefix ? prefix + '.SPLITIO' : 'SPLITIO';
|
|
13
9
|
}
|
|
14
10
|
exports.validatePrefix = validatePrefix;
|
|
15
11
|
var KeyBuilder = /** @class */ (function () {
|
|
@@ -31,7 +27,7 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
31
27
|
// return `${this.prefix}.splits.ready`;
|
|
32
28
|
// }
|
|
33
29
|
KeyBuilder.prototype.isSplitKey = function (key) {
|
|
34
|
-
return lang_1.startsWith(key, this.prefix + ".split.");
|
|
30
|
+
return (0, lang_1.startsWith)(key, this.prefix + ".split.");
|
|
35
31
|
};
|
|
36
32
|
KeyBuilder.prototype.buildSplitKeyPrefix = function () {
|
|
37
33
|
return this.prefix + ".split.";
|
|
@@ -5,7 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var lang_1 = require("../utils/lang");
|
|
6
6
|
var KeyBuilder_1 = require("./KeyBuilder");
|
|
7
7
|
var KeyBuilderCS = /** @class */ (function (_super) {
|
|
8
|
-
tslib_1.__extends(KeyBuilderCS, _super);
|
|
8
|
+
(0, tslib_1.__extends)(KeyBuilderCS, _super);
|
|
9
9
|
function KeyBuilderCS(prefix, matchingKey) {
|
|
10
10
|
var _this = _super.call(this, prefix) || this;
|
|
11
11
|
_this.matchingKey = matchingKey;
|
|
@@ -16,11 +16,21 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
16
16
|
* @override
|
|
17
17
|
*/
|
|
18
18
|
KeyBuilderCS.prototype.buildSegmentNameKey = function (segmentName) {
|
|
19
|
-
return this.
|
|
19
|
+
return this.prefix + "." + this.matchingKey + ".segment." + segmentName;
|
|
20
20
|
};
|
|
21
21
|
KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) {
|
|
22
|
+
var prefix = this.prefix + "." + this.matchingKey + ".segment.";
|
|
23
|
+
if ((0, lang_1.startsWith)(builtSegmentKeyName, prefix))
|
|
24
|
+
return builtSegmentKeyName.substr(prefix.length);
|
|
25
|
+
};
|
|
26
|
+
// @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
|
|
27
|
+
KeyBuilderCS.prototype.buildOldSegmentNameKey = function (segmentName) {
|
|
28
|
+
return this.matchingKey + "." + this.prefix + ".segment." + segmentName;
|
|
29
|
+
};
|
|
30
|
+
// @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
|
|
31
|
+
KeyBuilderCS.prototype.extractOldSegmentKey = function (builtSegmentKeyName) {
|
|
22
32
|
var prefix = this.matchingKey + "." + this.prefix + ".segment.";
|
|
23
|
-
if (lang_1.startsWith(builtSegmentKeyName, prefix))
|
|
33
|
+
if ((0, lang_1.startsWith)(builtSegmentKeyName, prefix))
|
|
24
34
|
return builtSegmentKeyName.substr(prefix.length);
|
|
25
35
|
};
|
|
26
36
|
KeyBuilderCS.prototype.buildLastUpdatedKey = function () {
|
|
@@ -7,7 +7,7 @@ var KeyBuilder_1 = require("./KeyBuilder");
|
|
|
7
7
|
// const everythingAfterCount = /count\.([^/]+)$/;
|
|
8
8
|
// const latencyMetricNameAndBucket = /latency\.([^/]+)\.bucket\.([0-9]+)$/;
|
|
9
9
|
var KeyBuilderSS = /** @class */ (function (_super) {
|
|
10
|
-
tslib_1.__extends(KeyBuilderSS, _super);
|
|
10
|
+
(0, tslib_1.__extends)(KeyBuilderSS, _super);
|
|
11
11
|
function KeyBuilderSS(prefix, metadata) {
|
|
12
12
|
var _this = _super.call(this, prefix) || this;
|
|
13
13
|
_this.metadata = metadata;
|
|
@@ -8,6 +8,6 @@ function findLatencyIndex(latency, min, max, base) {
|
|
|
8
8
|
if (max === void 0) { max = 23; }
|
|
9
9
|
if (base === void 0) { base = 1.5; }
|
|
10
10
|
var index = Math.min(max, Math.max(min, Math.floor(Math.log(latency) / Math.log(base))));
|
|
11
|
-
return lang_1.isNaNNumber(index) ? 0 : index; // index is NaN if latency is not a positive number
|
|
11
|
+
return (0, lang_1.isNaNNumber)(index) ? 0 : index; // index is NaN if latency is not a positive number
|
|
12
12
|
}
|
|
13
13
|
exports.findLatencyIndex = findLatencyIndex;
|
|
@@ -5,7 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var AbstractSegmentsCacheSync_1 = require("../AbstractSegmentsCacheSync");
|
|
6
6
|
var constants_1 = require("./constants");
|
|
7
7
|
var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
8
|
-
tslib_1.__extends(MySegmentsCacheInLocal, _super);
|
|
8
|
+
(0, tslib_1.__extends)(MySegmentsCacheInLocal, _super);
|
|
9
9
|
function MySegmentsCacheInLocal(log, keys) {
|
|
10
10
|
var _this = _super.call(this) || this;
|
|
11
11
|
_this.log = log;
|
|
@@ -60,9 +60,29 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
60
60
|
var index;
|
|
61
61
|
// Scan current values from localStorage
|
|
62
62
|
var storedSegmentNames = Object.keys(localStorage).reduce(function (accum, key) {
|
|
63
|
-
var
|
|
64
|
-
if (
|
|
65
|
-
accum.push(
|
|
63
|
+
var segmentName = _this.keys.extractSegmentName(key);
|
|
64
|
+
if (segmentName) {
|
|
65
|
+
accum.push(segmentName);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// @BREAKING: This is only to clean up "old" keys. Remove this whole else code block.
|
|
69
|
+
segmentName = _this.keys.extractOldSegmentKey(key);
|
|
70
|
+
if (segmentName) { // this was an old segment key, let's clean up.
|
|
71
|
+
var newSegmentKey = _this.keys.buildSegmentNameKey(segmentName);
|
|
72
|
+
try {
|
|
73
|
+
// If the new format key is not there, create it.
|
|
74
|
+
if (!localStorage.getItem(newSegmentKey) && names.indexOf(segmentName) > -1) {
|
|
75
|
+
localStorage.setItem(newSegmentKey, constants_1.DEFINED);
|
|
76
|
+
// we are migrating a segment, let's track it.
|
|
77
|
+
accum.push(segmentName);
|
|
78
|
+
}
|
|
79
|
+
localStorage.removeItem(key); // we migrated the current key, let's delete it.
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
_this.log.error(e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
66
86
|
return accum;
|
|
67
87
|
}, []);
|
|
68
88
|
// Extreme fast => everything is empty
|
|
@@ -9,7 +9,7 @@ var constants_1 = require("./constants");
|
|
|
9
9
|
* ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
|
|
10
10
|
*/
|
|
11
11
|
var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
12
|
-
tslib_1.__extends(SplitsCacheInLocal, _super);
|
|
12
|
+
(0, tslib_1.__extends)(SplitsCacheInLocal, _super);
|
|
13
13
|
/**
|
|
14
14
|
* @param {KeyBuilderCS} keys
|
|
15
15
|
* @param {number | undefined} expirationTimestamp
|
|
@@ -27,7 +27,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
27
27
|
return _this;
|
|
28
28
|
}
|
|
29
29
|
SplitsCacheInLocal.prototype._decrementCount = function (key) {
|
|
30
|
-
var count = lang_1.toNumber(localStorage.getItem(key)) - 1;
|
|
30
|
+
var count = (0, lang_1.toNumber)(localStorage.getItem(key)) - 1;
|
|
31
31
|
// @ts-expect-error
|
|
32
32
|
if (count > 0)
|
|
33
33
|
localStorage.setItem(key, count);
|
|
@@ -41,7 +41,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
41
41
|
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
42
42
|
this._decrementCount(ttKey);
|
|
43
43
|
}
|
|
44
|
-
if (AbstractSplitsCacheSync_1.usesSegments(split)) {
|
|
44
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
45
45
|
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
46
46
|
this._decrementCount(segmentsCountKey);
|
|
47
47
|
}
|
|
@@ -57,12 +57,12 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
57
57
|
if (split.trafficTypeName) {
|
|
58
58
|
var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
59
59
|
// @ts-expect-error
|
|
60
|
-
localStorage.setItem(ttKey, lang_1.toNumber(localStorage.getItem(ttKey)) + 1);
|
|
60
|
+
localStorage.setItem(ttKey, (0, lang_1.toNumber)(localStorage.getItem(ttKey)) + 1);
|
|
61
61
|
}
|
|
62
|
-
if (AbstractSplitsCacheSync_1.usesSegments(split)) {
|
|
62
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split)) {
|
|
63
63
|
var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
64
64
|
// @ts-expect-error
|
|
65
|
-
localStorage.setItem(segmentsCountKey, lang_1.toNumber(localStorage.getItem(segmentsCountKey)) + 1);
|
|
65
|
+
localStorage.setItem(segmentsCountKey, (0, lang_1.toNumber)(localStorage.getItem(segmentsCountKey)) + 1);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -161,7 +161,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
161
161
|
var value = localStorage.getItem(this.keys.buildSplitsTillKey());
|
|
162
162
|
if (value !== null) {
|
|
163
163
|
value = parseInt(value, 10);
|
|
164
|
-
return lang_1.isNaNNumber(value) ? n : value;
|
|
164
|
+
return (0, lang_1.isNaNNumber)(value) ? n : value;
|
|
165
165
|
}
|
|
166
166
|
return n;
|
|
167
167
|
};
|
|
@@ -178,16 +178,16 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
178
178
|
return accum;
|
|
179
179
|
};
|
|
180
180
|
SplitsCacheInLocal.prototype.trafficTypeExists = function (trafficType) {
|
|
181
|
-
var ttCount = lang_1.toNumber(localStorage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
|
|
182
|
-
return lang_1.isFiniteNumber(ttCount) && ttCount > 0;
|
|
181
|
+
var ttCount = (0, lang_1.toNumber)(localStorage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
|
|
182
|
+
return (0, lang_1.isFiniteNumber)(ttCount) && ttCount > 0;
|
|
183
183
|
};
|
|
184
184
|
SplitsCacheInLocal.prototype.usesSegments = function () {
|
|
185
185
|
// If cache hasn't been synchronized with the cloud, assume we need them.
|
|
186
186
|
if (!this.hasSync)
|
|
187
187
|
return true;
|
|
188
188
|
var storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
189
|
-
var splitsWithSegmentsCount = storedCount === null ? 0 : lang_1.toNumber(storedCount);
|
|
190
|
-
if (lang_1.isFiniteNumber(splitsWithSegmentsCount)) {
|
|
189
|
+
var splitsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
|
|
190
|
+
if ((0, lang_1.isFiniteNumber)(splitsWithSegmentsCount)) {
|
|
191
191
|
return splitsWithSegmentsCount > 0;
|
|
192
192
|
}
|
|
193
193
|
else {
|
|
@@ -212,7 +212,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
212
212
|
var value = localStorage.getItem(this.keys.buildLastUpdatedKey());
|
|
213
213
|
if (value !== null) {
|
|
214
214
|
value = parseInt(value, 10);
|
|
215
|
-
if (!lang_1.isNaNNumber(value) && expirationTimestamp && value < expirationTimestamp)
|
|
215
|
+
if (!(0, lang_1.isNaNNumber)(value) && expirationTimestamp && value < expirationTimestamp)
|
|
216
216
|
this.clear();
|
|
217
217
|
}
|
|
218
218
|
};
|
|
@@ -20,12 +20,12 @@ var constants_2 = require("../../utils/constants");
|
|
|
20
20
|
*/
|
|
21
21
|
function InLocalStorage(options) {
|
|
22
22
|
if (options === void 0) { options = {}; }
|
|
23
|
-
var prefix = KeyBuilder_1.validatePrefix(options.prefix);
|
|
23
|
+
var prefix = (0, KeyBuilder_1.validatePrefix)(options.prefix);
|
|
24
24
|
function InLocalStorageCSFactory(params) {
|
|
25
25
|
// Fallback to InMemoryStorage if LocalStorage API is not available
|
|
26
|
-
if (!isLocalStorageAvailable_1.isLocalStorageAvailable()) {
|
|
26
|
+
if (!(0, isLocalStorageAvailable_1.isLocalStorageAvailable)()) {
|
|
27
27
|
params.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Fallbacking into default MEMORY storage');
|
|
28
|
-
return InMemoryStorageCS_1.InMemoryStorageCSFactory(params);
|
|
28
|
+
return (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
|
|
29
29
|
}
|
|
30
30
|
var log = params.log;
|
|
31
31
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, params.matchingKey);
|
|
@@ -33,7 +33,7 @@ function InLocalStorage(options) {
|
|
|
33
33
|
return {
|
|
34
34
|
splits: new SplitsCacheInLocal_1.SplitsCacheInLocal(log, keys, expirationTimestamp, params.splitFiltersValidation),
|
|
35
35
|
segments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys),
|
|
36
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(),
|
|
36
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
37
37
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
38
38
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
39
39
|
destroy: function () {
|
|
@@ -33,7 +33,7 @@ var AttributesCacheInMemory = /** @class */ (function () {
|
|
|
33
33
|
* @returns {boolean} attributes were stored
|
|
34
34
|
*/
|
|
35
35
|
AttributesCacheInMemory.prototype.setAttributes = function (attributes) {
|
|
36
|
-
this.attributesCache = objectAssign_1.objectAssign(this.attributesCache, attributes);
|
|
36
|
+
this.attributesCache = (0, objectAssign_1.objectAssign)(this.attributesCache, attributes);
|
|
37
37
|
return true;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
@@ -10,7 +10,7 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
10
10
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
11
11
|
*/
|
|
12
12
|
ImpressionCountsCacheInMemory.prototype._makeKey = function (featureName, timeFrame) {
|
|
13
|
-
return featureName + "::" + time_1.truncateTimeFrame(timeFrame);
|
|
13
|
+
return featureName + "::" + (0, time_1.truncateTimeFrame)(timeFrame);
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Increments the quantity of impressions with the passed featureName and timeFrame.
|
|
@@ -2,15 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImpressionsCacheInMemory = void 0;
|
|
4
4
|
var ImpressionsCacheInMemory = /** @class */ (function () {
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
|
|
8
|
+
* Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
|
|
9
|
+
*/
|
|
10
|
+
function ImpressionsCacheInMemory(impressionsQueueSize) {
|
|
11
|
+
if (impressionsQueueSize === void 0) { impressionsQueueSize = 0; }
|
|
12
|
+
this.maxQueue = impressionsQueueSize;
|
|
6
13
|
this.queue = [];
|
|
7
14
|
}
|
|
15
|
+
ImpressionsCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
|
|
16
|
+
this.onFullQueue = cb;
|
|
17
|
+
};
|
|
8
18
|
/**
|
|
9
19
|
* Store impressions in sequential order
|
|
10
20
|
*/
|
|
11
21
|
ImpressionsCacheInMemory.prototype.track = function (data) {
|
|
12
22
|
var _a;
|
|
13
23
|
(_a = this.queue).push.apply(_a, data);
|
|
24
|
+
// Check if the cache queue is full and we need to flush it.
|
|
25
|
+
if (this.maxQueue > 0 && this.queue.length >= this.maxQueue && this.onFullQueue) {
|
|
26
|
+
this.onFullQueue();
|
|
27
|
+
}
|
|
14
28
|
};
|
|
15
29
|
/**
|
|
16
30
|
* Clear the data stored on the cache.
|
|
@@ -16,7 +16,7 @@ function InMemoryStorageFactory(params) {
|
|
|
16
16
|
return {
|
|
17
17
|
splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
|
|
18
18
|
segments: new SegmentsCacheInMemory_1.SegmentsCacheInMemory(),
|
|
19
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(),
|
|
19
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
20
20
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
21
21
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
22
22
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
@@ -16,7 +16,7 @@ function InMemoryStorageCSFactory(params) {
|
|
|
16
16
|
return {
|
|
17
17
|
splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
|
|
18
18
|
segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
19
|
-
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(),
|
|
19
|
+
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
20
20
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
|
|
21
21
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
|
|
22
22
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
@@ -17,7 +17,7 @@ var LatenciesCacheInMemory = /** @class */ (function () {
|
|
|
17
17
|
];
|
|
18
18
|
}
|
|
19
19
|
// +1 based on the latency number
|
|
20
|
-
this.counters[metricName][findLatencyIndex_1.findLatencyIndex(latency)]++;
|
|
20
|
+
this.counters[metricName][(0, findLatencyIndex_1.findLatencyIndex)(latency)]++;
|
|
21
21
|
return true;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
@@ -8,7 +8,7 @@ var AbstractSegmentsCacheSync_1 = require("../AbstractSegmentsCacheSync");
|
|
|
8
8
|
* Supported by all JS runtimes.
|
|
9
9
|
*/
|
|
10
10
|
var MySegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
11
|
-
tslib_1.__extends(MySegmentsCacheInMemory, _super);
|
|
11
|
+
(0, tslib_1.__extends)(MySegmentsCacheInMemory, _super);
|
|
12
12
|
function MySegmentsCacheInMemory() {
|
|
13
13
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
14
14
|
_this.segmentCache = {};
|
|
@@ -10,7 +10,7 @@ var lang_1 = require("../../utils/lang");
|
|
|
10
10
|
* Supported by all JS runtimes.
|
|
11
11
|
*/
|
|
12
12
|
var SegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
13
|
-
tslib_1.__extends(SegmentsCacheInMemory, _super);
|
|
13
|
+
(0, tslib_1.__extends)(SegmentsCacheInMemory, _super);
|
|
14
14
|
function SegmentsCacheInMemory() {
|
|
15
15
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
16
16
|
_this.segmentCache = {};
|
|
@@ -63,7 +63,7 @@ var SegmentsCacheInMemory = /** @class */ (function (_super) {
|
|
|
63
63
|
};
|
|
64
64
|
SegmentsCacheInMemory.prototype.getChangeNumber = function (name) {
|
|
65
65
|
var value = this.segmentChangeNumber[name];
|
|
66
|
-
return lang_1.isIntegerNumber(value) ? value : -1;
|
|
66
|
+
return (0, lang_1.isIntegerNumber)(value) ? value : -1;
|
|
67
67
|
};
|
|
68
68
|
return SegmentsCacheInMemory;
|
|
69
69
|
}(AbstractSegmentsCacheSync_1.AbstractSegmentsCacheSync));
|