@splitsoftware/splitio-commons 2.12.0 → 3.0.0-rc.1
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 +19 -1
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +70 -0
- package/cjs/evaluator/fallbackConfigsCalculator/index.js +25 -0
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/cjs/evaluator/fallbackTreatmentsCalculator/index.js +21 -32
- package/cjs/evaluator/index.js +73 -48
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/integrations/pluggable.js +1 -1
- package/cjs/listeners/browser.js +4 -3
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +15 -21
- package/cjs/logger/index.js +1 -1
- package/cjs/logger/messages/debug.js +6 -7
- package/cjs/logger/messages/error.js +4 -4
- package/cjs/logger/messages/info.js +2 -4
- package/cjs/logger/messages/warn.js +9 -10
- package/cjs/platform/browser.js +15 -0
- package/cjs/platform/getEventSource/browser.js +8 -0
- package/cjs/platform/getEventSource/eventsource.js +480 -0
- package/cjs/platform/getEventSource/node.js +26 -0
- package/cjs/platform/getFetch/browser.js +9 -0
- package/cjs/platform/getFetch/node.js +27 -0
- package/cjs/platform/getOptions/node.js +25 -0
- package/cjs/platform/node.js +17 -0
- package/cjs/readiness/constants.js +5 -4
- package/cjs/readiness/readinessManager.js +22 -22
- package/cjs/readiness/sdkReadinessManager.js +0 -16
- package/cjs/sdkClient/client.js +9 -35
- package/cjs/sdkClient/clientAttributesDecoration.js +3 -3
- package/cjs/sdkClient/clientInputValidation.js +38 -81
- package/cjs/sdkClient/identity.js +1 -1
- package/cjs/sdkClient/sdkClient.js +4 -49
- package/cjs/sdkClient/sdkLifecycle.js +71 -0
- package/cjs/sdkClient/trackMethod.js +56 -0
- package/cjs/sdkFactory/index.js +13 -50
- package/cjs/sdkManager/index.js +5 -5
- package/cjs/services/authProvider.js +67 -0
- package/cjs/services/secureSplitHttpClient.js +39 -0
- package/cjs/services/splitApi.js +24 -14
- package/cjs/services/splitHttpClient.js +1 -1
- package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
- package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
- package/cjs/storages/KeyBuilder.js +16 -16
- package/cjs/storages/KeyBuilderCS.js +17 -17
- package/cjs/storages/KeyBuilderSS.js +16 -16
- package/cjs/storages/getRolloutPlan.js +4 -4
- package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -1
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
- package/cjs/storages/inLocalStorage/index.js +6 -6
- package/cjs/storages/inLocalStorage/validateCache.js +3 -3
- package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/DefinitionsCacheInRedis.js +243 -0
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -5
- package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +8 -8
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +7 -7
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +3 -3
- package/cjs/storages/inRedis/index.js +2 -2
- package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
- package/cjs/storages/pluggable/EventsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +6 -6
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +7 -7
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -2
- package/cjs/storages/pluggable/index.js +5 -5
- package/cjs/storages/pluggable/wrapperAdapter.js +1 -1
- package/cjs/storages/setRolloutPlan.js +6 -6
- package/cjs/storages/utils.js +6 -6
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
- package/cjs/sync/polling/pollingManagerCS.js +18 -18
- package/cjs/sync/polling/pollingManagerSS.js +13 -13
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +12 -0
- package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +72 -64
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/streaming/SSEClient/index.js +2 -2
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +1 -1
- package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +18 -18
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/parseUtils.js +12 -12
- package/cjs/sync/streaming/pushManager.js +14 -14
- package/cjs/sync/submitters/impressionsSubmitter.js +6 -6
- package/cjs/sync/submitters/submitter.js +1 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +1 -2
- package/cjs/sync/syncManagerOnline.js +9 -6
- package/cjs/trackers/eventTracker.js +10 -12
- package/cjs/trackers/impressionObserver/buildKey.js +1 -1
- package/cjs/trackers/impressionsTracker.js +37 -20
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/Backoff.js +20 -0
- package/cjs/utils/EventEmitter.js +391 -0
- package/cjs/utils/filter/bloomFilter.js +37 -0
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +2 -2
- package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
- package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
- package/cjs/utils/inputValidation/definitions.js +25 -0
- package/cjs/utils/inputValidation/eventProperties.js +1 -1
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/target.js +22 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/lang/index.js +1 -1
- package/cjs/utils/lang/sets.js +4 -4
- package/cjs/utils/promise/timeout.js +1 -1
- package/cjs/utils/settingsValidation/splitFilters.js +4 -4
- package/cjs/utils/settingsValidation/url.js +6 -6
- package/esm/evaluator/condition/engineUtils.js +2 -2
- package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +64 -0
- package/esm/evaluator/fallbackConfigsCalculator/index.js +21 -0
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/esm/evaluator/fallbackTreatmentsCalculator/index.js +21 -33
- package/esm/evaluator/index.js +72 -48
- package/esm/evaluator/matchers/whitelist.js +1 -1
- package/esm/integrations/pluggable.js +1 -1
- package/esm/listeners/browser.js +4 -3
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +12 -18
- package/esm/logger/index.js +1 -1
- package/esm/logger/messages/debug.js +5 -6
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +1 -3
- package/esm/logger/messages/warn.js +8 -9
- package/esm/platform/browser.js +12 -0
- package/esm/platform/getEventSource/browser.js +4 -0
- package/esm/platform/getEventSource/eventsource.js +480 -0
- package/esm/platform/getEventSource/node.js +20 -0
- package/esm/platform/getFetch/browser.js +5 -0
- package/esm/platform/getFetch/node.js +22 -0
- package/esm/platform/getOptions/node.js +20 -0
- package/esm/platform/node.js +14 -0
- package/esm/readiness/constants.js +4 -3
- package/esm/readiness/readinessManager.js +23 -23
- package/esm/readiness/sdkReadinessManager.js +1 -17
- package/esm/sdkClient/client.js +10 -37
- package/esm/sdkClient/clientAttributesDecoration.js +3 -3
- package/esm/sdkClient/clientInputValidation.js +40 -83
- package/esm/sdkClient/identity.js +1 -1
- package/esm/sdkClient/sdkClient.js +4 -49
- package/esm/sdkClient/sdkLifecycle.js +67 -0
- package/esm/sdkClient/trackMethod.js +52 -0
- package/esm/sdkFactory/index.js +14 -51
- package/esm/sdkManager/index.js +6 -6
- package/esm/services/authProvider.js +63 -0
- package/esm/services/secureSplitHttpClient.js +35 -0
- package/esm/services/splitApi.js +24 -14
- package/esm/services/splitHttpClient.js +1 -1
- package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
- package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
- package/esm/storages/KeyBuilder.js +16 -16
- package/esm/storages/KeyBuilderCS.js +16 -16
- package/esm/storages/KeyBuilderSS.js +15 -15
- package/esm/storages/getRolloutPlan.js +4 -4
- package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
- package/esm/storages/inLocalStorage/index.js +6 -6
- package/esm/storages/inLocalStorage/validateCache.js +3 -3
- package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/InMemoryStorage.js +4 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
- package/esm/storages/inRedis/DefinitionsCacheInRedis.js +240 -0
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +4 -4
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +7 -7
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +7 -7
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -1
- package/esm/storages/inRedis/index.js +2 -2
- package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
- package/esm/storages/pluggable/EventsCachePluggable.js +1 -1
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +5 -5
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/esm/storages/pluggable/TelemetryCachePluggable.js +7 -7
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -1
- package/esm/storages/pluggable/index.js +4 -4
- package/esm/storages/pluggable/wrapperAdapter.js +1 -1
- package/esm/storages/setRolloutPlan.js +6 -6
- package/esm/storages/utils.js +6 -6
- package/esm/sync/offline/splitsParser/parseCondition.js +1 -1
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
- package/esm/sync/polling/pollingManagerCS.js +15 -15
- package/esm/sync/polling/pollingManagerSS.js +13 -13
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +8 -0
- package/esm/sync/polling/updaters/definitionChangesUpdater.js +200 -0
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/streaming/SSEClient/index.js +2 -2
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
- package/esm/sync/streaming/SSEHandler/index.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +17 -17
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/parseUtils.js +10 -10
- package/esm/sync/streaming/pushManager.js +16 -16
- package/esm/sync/submitters/impressionsSubmitter.js +6 -6
- package/esm/sync/submitters/submitter.js +1 -1
- package/esm/sync/submitters/telemetrySubmitter.js +1 -2
- package/esm/sync/syncManagerOnline.js +8 -5
- package/esm/trackers/eventTracker.js +10 -12
- package/esm/trackers/impressionObserver/buildKey.js +1 -1
- package/esm/trackers/impressionsTracker.js +38 -21
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/Backoff.js +20 -0
- package/esm/utils/EventEmitter.js +387 -0
- package/esm/utils/filter/bloomFilter.js +33 -0
- package/esm/utils/inputValidation/apiKey.js +1 -1
- package/esm/utils/inputValidation/attribute.js +2 -2
- package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
- package/esm/utils/inputValidation/definitionExistence.js +15 -0
- package/esm/utils/inputValidation/definitions.js +21 -0
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/target.js +18 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/lang/sets.js +4 -4
- package/esm/utils/promise/timeout.js +1 -1
- package/esm/utils/settingsValidation/splitFilters.js +4 -4
- package/esm/utils/settingsValidation/url.js +6 -6
- package/package.json +15 -6
- package/src/dtos/types.ts +65 -70
- package/src/evaluator/Engine.ts +4 -4
- package/src/evaluator/combiners/and.ts +3 -3
- package/src/evaluator/combiners/ifelseif.ts +2 -2
- package/src/evaluator/condition/engineUtils.ts +2 -2
- package/src/evaluator/condition/index.ts +3 -3
- package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +76 -0
- package/src/evaluator/fallbackConfigsCalculator/index.ts +24 -0
- package/src/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.ts +5 -7
- package/src/evaluator/fallbackTreatmentsCalculator/index.ts +27 -41
- package/src/evaluator/index.ts +86 -51
- package/src/evaluator/matchers/dependency.ts +2 -2
- package/src/evaluator/matchers/matcherTypes.ts +2 -2
- package/src/evaluator/matchers/prerequisites.ts +4 -4
- package/src/evaluator/matchers/rbsegment.ts +2 -2
- package/src/evaluator/matchers/whitelist.ts +2 -2
- package/src/evaluator/matchersTransform/index.ts +2 -2
- package/src/evaluator/matchersTransform/whitelist.ts +2 -2
- package/src/evaluator/parser/index.ts +4 -4
- package/src/evaluator/treatments/index.ts +2 -2
- package/src/evaluator/types.ts +6 -6
- package/src/evaluator/value/index.ts +1 -1
- package/src/integrations/pluggable.ts +1 -1
- package/src/listeners/browser.ts +11 -8
- package/src/listeners/node.ts +2 -5
- package/src/logger/constants.ts +12 -18
- package/src/logger/messages/debug.ts +5 -6
- package/src/logger/messages/error.ts +3 -3
- package/src/logger/messages/info.ts +1 -3
- package/src/logger/messages/warn.ts +8 -9
- package/src/platform/browser.ts +14 -0
- package/src/platform/getEventSource/browser.ts +4 -0
- package/src/platform/getEventSource/eventsource.js +519 -0
- package/src/platform/getEventSource/node.ts +23 -0
- package/src/platform/getFetch/browser.ts +5 -0
- package/src/platform/getFetch/node.ts +27 -0
- package/src/platform/getOptions/node.ts +24 -0
- package/src/platform/node.ts +16 -0
- package/src/readiness/constants.ts +4 -3
- package/src/readiness/readinessManager.ts +22 -22
- package/src/readiness/sdkReadinessManager.ts +1 -16
- package/src/readiness/types.ts +10 -16
- package/src/sdkClient/client.ts +11 -41
- package/src/sdkClient/clientInputValidation.ts +44 -84
- package/src/sdkClient/sdkClient.ts +5 -54
- package/src/sdkClient/sdkLifecycle.ts +79 -0
- package/src/sdkClient/trackMethod.ts +59 -0
- package/src/sdkFactory/index.ts +15 -59
- package/src/sdkFactory/types.ts +19 -16
- package/src/sdkManager/index.ts +15 -15
- package/src/services/authProvider.ts +86 -0
- package/src/services/secureSplitHttpClient.ts +44 -0
- package/src/services/splitApi.ts +14 -2
- package/src/services/types.ts +7 -2
- package/src/storages/AbstractDefinitionsCacheAsync.ts +63 -0
- package/src/storages/AbstractDefinitionsCacheSync.ts +95 -0
- package/src/storages/KeyBuilder.ts +6 -6
- package/src/storages/KeyBuilderCS.ts +6 -6
- package/src/storages/KeyBuilderSS.ts +2 -2
- package/src/storages/getRolloutPlan.ts +3 -3
- package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +234 -0
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +8 -8
- package/src/storages/inLocalStorage/index.ts +6 -6
- package/src/storages/inLocalStorage/validateCache.ts +4 -4
- package/src/storages/inMemory/DefinitionsCacheInMemory.ts +130 -0
- package/src/storages/inMemory/InMemoryStorage.ts +4 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +5 -5
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +3 -3
- package/src/storages/inMemory/SegmentsCacheInMemory.ts +1 -1
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +5 -5
- package/src/storages/inRedis/{SplitsCacheInRedis.ts → DefinitionsCacheInRedis.ts} +69 -69
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +2 -2
- package/src/storages/inRedis/index.ts +2 -2
- package/src/storages/pluggable/DefinitionsCachePluggable.ts +230 -0
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +2 -2
- package/src/storages/pluggable/index.ts +2 -2
- package/src/storages/setRolloutPlan.ts +7 -7
- package/src/storages/types.ts +34 -29
- package/src/sync/offline/splitsParser/parseCondition.ts +2 -2
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +3 -3
- package/src/sync/offline/splitsParser/types.ts +6 -3
- package/src/sync/offline/syncManagerOffline.ts +2 -2
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +14 -14
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +58 -23
- package/src/sync/polling/fetchers/types.ts +5 -3
- package/src/sync/polling/pollingManagerCS.ts +16 -14
- package/src/sync/polling/pollingManagerSS.ts +15 -13
- package/src/sync/polling/syncTasks/{splitsSyncTask.ts → definitionsSyncTask.ts} +11 -12
- package/src/sync/polling/types.ts +3 -3
- package/src/sync/polling/updaters/definitionChangesUpdater.ts +239 -0
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +3 -3
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +7 -7
- package/src/sync/streaming/AuthClient/index.ts +2 -2
- package/src/sync/streaming/AuthClient/types.ts +14 -11
- package/src/sync/streaming/SSEClient/index.ts +2 -2
- package/src/sync/streaming/SSEClient/types.ts +2 -2
- package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +2 -2
- package/src/sync/streaming/SSEHandler/index.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.ts → DefinitionsUpdateWorker.ts} +21 -21
- package/src/sync/streaming/constants.ts +2 -2
- package/src/sync/streaming/parseUtils.ts +12 -12
- package/src/sync/streaming/pushManager.ts +18 -18
- package/src/sync/streaming/types.ts +2 -2
- package/src/sync/submitters/impressionsSubmitter.ts +9 -9
- package/src/sync/submitters/telemetrySubmitter.ts +1 -2
- package/src/sync/submitters/types.ts +3 -0
- package/src/sync/syncManagerOnline.ts +9 -5
- package/src/trackers/eventTracker.ts +7 -10
- package/src/trackers/impressionsTracker.ts +42 -26
- package/src/trackers/types.ts +3 -1
- package/src/utils/Backoff.ts +21 -0
- package/src/utils/EventEmitter.js +444 -0
- package/src/utils/filter/bloomFilter.ts +38 -0
- package/src/utils/inputValidation/definition.ts +27 -0
- package/src/utils/inputValidation/definitionExistence.ts +19 -0
- package/src/utils/inputValidation/definitions.ts +21 -0
- package/src/utils/inputValidation/index.ts +3 -3
- package/src/utils/inputValidation/isOperational.ts +4 -4
- package/src/utils/inputValidation/target.ts +21 -0
- package/src/utils/inputValidation/trafficTypeExistence.ts +2 -2
- package/src/utils/jwt/types.ts +1 -1
- package/src/utils/labels/index.ts +2 -2
- package/src/utils/lang/sets.ts +4 -2
- package/src/utils/settingsValidation/splitFilters.ts +3 -3
- package/src/utils/settingsValidation/url.ts +1 -1
- package/types/splitio.d.ts +222 -11
- package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
- package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +0 -243
- package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
- package/cjs/utils/inputValidation/splits.js +0 -25
- package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
- package/esm/storages/AbstractSplitsCacheSync.js +0 -71
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
- package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
- package/esm/storages/inRedis/SplitsCacheInRedis.js +0 -240
- package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
- package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -192
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
- package/src/storages/AbstractSplitsCacheAsync.ts +0 -63
- package/src/storages/AbstractSplitsCacheSync.ts +0 -95
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -234
- package/src/storages/inMemory/SplitsCacheInMemory.ts +0 -130
- package/src/storages/pluggable/SplitsCachePluggable.ts +0 -230
- package/src/sync/polling/updaters/splitChangesUpdater.ts +0 -230
- package/src/utils/inputValidation/split.ts +0 -27
- package/src/utils/inputValidation/splitExistence.ts +0 -19
- package/src/utils/inputValidation/splits.ts +0 -21
|
@@ -14,34 +14,34 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
14
14
|
this.prefix = prefix;
|
|
15
15
|
}
|
|
16
16
|
KeyBuilder.prototype.buildTrafficTypeKey = function (trafficType) {
|
|
17
|
-
return this.prefix
|
|
17
|
+
return "".concat(this.prefix, ".trafficType.").concat(trafficType);
|
|
18
18
|
};
|
|
19
|
-
KeyBuilder.prototype.
|
|
20
|
-
return this.prefix
|
|
19
|
+
KeyBuilder.prototype.buildSetKey = function (set) {
|
|
20
|
+
return "".concat(this.prefix, ".flagSet.").concat(set);
|
|
21
21
|
};
|
|
22
|
-
KeyBuilder.prototype.
|
|
23
|
-
return this.prefix
|
|
22
|
+
KeyBuilder.prototype.buildDefinitionKey = function (definitionName) {
|
|
23
|
+
return "".concat(this.prefix, ".split.").concat(definitionName);
|
|
24
24
|
};
|
|
25
|
-
KeyBuilder.prototype.
|
|
26
|
-
return this.prefix
|
|
25
|
+
KeyBuilder.prototype.buildDefinitionsTillKey = function () {
|
|
26
|
+
return "".concat(this.prefix, ".splits.till");
|
|
27
27
|
};
|
|
28
|
-
KeyBuilder.prototype.
|
|
29
|
-
return this.prefix
|
|
28
|
+
KeyBuilder.prototype.buildDefinitionKeyPrefix = function () {
|
|
29
|
+
return "".concat(this.prefix, ".split.");
|
|
30
30
|
};
|
|
31
31
|
KeyBuilder.prototype.buildRBSegmentKey = function (rbsegmentName) {
|
|
32
|
-
return this.prefix
|
|
32
|
+
return "".concat(this.prefix, ".rbsegment.").concat(rbsegmentName);
|
|
33
33
|
};
|
|
34
34
|
KeyBuilder.prototype.buildRBSegmentsTillKey = function () {
|
|
35
|
-
return this.prefix
|
|
35
|
+
return "".concat(this.prefix, ".rbsegments.till");
|
|
36
36
|
};
|
|
37
37
|
KeyBuilder.prototype.buildRBSegmentKeyPrefix = function () {
|
|
38
|
-
return this.prefix
|
|
38
|
+
return "".concat(this.prefix, ".rbsegment.");
|
|
39
39
|
};
|
|
40
40
|
KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) {
|
|
41
|
-
return this.prefix
|
|
41
|
+
return "".concat(this.prefix, ".segment.").concat(segmentName);
|
|
42
42
|
};
|
|
43
43
|
KeyBuilder.prototype.buildSegmentTillKey = function (segmentName) {
|
|
44
|
-
return this.prefix
|
|
44
|
+
return "".concat(this.prefix, ".segment.").concat(segmentName, ".till");
|
|
45
45
|
};
|
|
46
46
|
KeyBuilder.prototype.extractKey = function (builtKey) {
|
|
47
47
|
var s = builtKey.match(everythingAtTheEnd);
|
|
@@ -53,7 +53,7 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
KeyBuilder.prototype.buildHashKey = function () {
|
|
56
|
-
return this.prefix
|
|
56
|
+
return "".concat(this.prefix, ".hash");
|
|
57
57
|
};
|
|
58
58
|
return KeyBuilder;
|
|
59
59
|
}());
|
|
@@ -63,6 +63,6 @@ exports.KeyBuilder = KeyBuilder;
|
|
|
63
63
|
* The hash is in hexadecimal format (8 characters max, 32 bits).
|
|
64
64
|
*/
|
|
65
65
|
function getStorageHash(settings) {
|
|
66
|
-
return (0, murmur3_1.hash)(settings.core.authorizationKey
|
|
66
|
+
return (0, murmur3_1.hash)("".concat(settings.core.authorizationKey, "::").concat(settings.sync.__splitFiltersValidation.queryString, "::").concat(settings.sync.flagSpecVersion)).toString(16);
|
|
67
67
|
}
|
|
68
68
|
exports.getStorageHash = getStorageHash;
|
|
@@ -5,44 +5,44 @@ 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
|
-
|
|
8
|
+
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;
|
|
12
|
-
_this.
|
|
12
|
+
_this.regexDefinitionsCacheKey = new RegExp("^".concat(prefix, "\\.(splits?|trafficType|flagSet)\\."));
|
|
13
13
|
return _this;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* @override
|
|
17
17
|
*/
|
|
18
18
|
KeyBuilderCS.prototype.buildSegmentNameKey = function (segmentName) {
|
|
19
|
-
return this.prefix
|
|
19
|
+
return "".concat(this.prefix, ".").concat(this.matchingKey, ".segment.").concat(segmentName);
|
|
20
20
|
};
|
|
21
21
|
KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) {
|
|
22
|
-
var prefix = this.prefix
|
|
22
|
+
var prefix = "".concat(this.prefix, ".").concat(this.matchingKey, ".segment.");
|
|
23
23
|
if ((0, lang_1.startsWith)(builtSegmentKeyName, prefix))
|
|
24
24
|
return builtSegmentKeyName.slice(prefix.length);
|
|
25
25
|
};
|
|
26
26
|
KeyBuilderCS.prototype.buildLastUpdatedKey = function () {
|
|
27
|
-
return this.prefix
|
|
27
|
+
return "".concat(this.prefix, ".splits.lastUpdated");
|
|
28
28
|
};
|
|
29
|
-
KeyBuilderCS.prototype.
|
|
30
|
-
return this.
|
|
29
|
+
KeyBuilderCS.prototype.isDefinitionsCacheKey = function (key) {
|
|
30
|
+
return this.regexDefinitionsCacheKey.test(key);
|
|
31
31
|
};
|
|
32
32
|
KeyBuilderCS.prototype.buildTillKey = function () {
|
|
33
|
-
return this.prefix
|
|
33
|
+
return "".concat(this.prefix, ".").concat(this.matchingKey, ".segments.till");
|
|
34
34
|
};
|
|
35
|
-
KeyBuilderCS.prototype.
|
|
36
|
-
return (0, lang_1.startsWith)(key, this.prefix
|
|
35
|
+
KeyBuilderCS.prototype.isDefinitionKey = function (key) {
|
|
36
|
+
return (0, lang_1.startsWith)(key, "".concat(this.prefix, ".split."));
|
|
37
37
|
};
|
|
38
38
|
KeyBuilderCS.prototype.isRBSegmentKey = function (key) {
|
|
39
|
-
return (0, lang_1.startsWith)(key, this.prefix
|
|
39
|
+
return (0, lang_1.startsWith)(key, "".concat(this.prefix, ".rbsegment."));
|
|
40
40
|
};
|
|
41
|
-
KeyBuilderCS.prototype.
|
|
42
|
-
return this.prefix
|
|
41
|
+
KeyBuilderCS.prototype.buildDefinitionsWithSegmentCountKey = function () {
|
|
42
|
+
return "".concat(this.prefix, ".splits.usingSegments");
|
|
43
43
|
};
|
|
44
44
|
KeyBuilderCS.prototype.buildLastClear = function () {
|
|
45
|
-
return this.prefix
|
|
45
|
+
return "".concat(this.prefix, ".lastClear");
|
|
46
46
|
};
|
|
47
47
|
return KeyBuilderCS;
|
|
48
48
|
}(KeyBuilder_1.KeyBuilder));
|
|
@@ -50,15 +50,15 @@ exports.KeyBuilderCS = KeyBuilderCS;
|
|
|
50
50
|
function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
|
|
51
51
|
return {
|
|
52
52
|
buildSegmentNameKey: function (segmentName) {
|
|
53
|
-
return prefix
|
|
53
|
+
return "".concat(prefix, ".").concat(matchingKey, ".largeSegment.").concat(segmentName);
|
|
54
54
|
},
|
|
55
55
|
extractSegmentName: function (builtSegmentKeyName) {
|
|
56
|
-
var p = prefix
|
|
56
|
+
var p = "".concat(prefix, ".").concat(matchingKey, ".largeSegment.");
|
|
57
57
|
if ((0, lang_1.startsWith)(builtSegmentKeyName, p))
|
|
58
58
|
return builtSegmentKeyName.slice(p.length);
|
|
59
59
|
},
|
|
60
60
|
buildTillKey: function () {
|
|
61
|
-
return prefix
|
|
61
|
+
return "".concat(prefix, ".").concat(matchingKey, ".largeSegments.till");
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
|
@@ -15,45 +15,45 @@ exports.METHOD_NAMES = {
|
|
|
15
15
|
tr: 'track'
|
|
16
16
|
};
|
|
17
17
|
var KeyBuilderSS = /** @class */ (function (_super) {
|
|
18
|
-
|
|
18
|
+
tslib_1.__extends(KeyBuilderSS, _super);
|
|
19
19
|
function KeyBuilderSS(prefix, metadata) {
|
|
20
20
|
var _this = _super.call(this, prefix) || this;
|
|
21
|
-
_this.latencyPrefix = _this.prefix
|
|
22
|
-
_this.exceptionPrefix = _this.prefix
|
|
23
|
-
_this.initPrefix = _this.prefix
|
|
24
|
-
_this.versionablePrefix = metadata.s
|
|
21
|
+
_this.latencyPrefix = "".concat(_this.prefix, ".telemetry.latencies");
|
|
22
|
+
_this.exceptionPrefix = "".concat(_this.prefix, ".telemetry.exceptions");
|
|
23
|
+
_this.initPrefix = "".concat(_this.prefix, ".telemetry.init");
|
|
24
|
+
_this.versionablePrefix = "".concat(metadata.s, "/").concat(metadata.n, "/").concat(metadata.i);
|
|
25
25
|
return _this;
|
|
26
26
|
}
|
|
27
27
|
KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
|
|
28
|
-
return this.prefix
|
|
28
|
+
return "".concat(this.prefix, ".segments.registered");
|
|
29
29
|
};
|
|
30
30
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
31
|
-
return this.prefix
|
|
31
|
+
return "".concat(this.prefix, ".impressions");
|
|
32
32
|
};
|
|
33
33
|
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
34
|
-
return this.prefix
|
|
34
|
+
return "".concat(this.prefix, ".impressions.count");
|
|
35
35
|
};
|
|
36
36
|
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
37
|
-
return this.prefix
|
|
37
|
+
return "".concat(this.prefix, ".uniquekeys");
|
|
38
38
|
};
|
|
39
39
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
40
|
-
return this.prefix
|
|
40
|
+
return "".concat(this.prefix, ".events");
|
|
41
41
|
};
|
|
42
|
-
KeyBuilderSS.prototype.
|
|
43
|
-
return this.
|
|
42
|
+
KeyBuilderSS.prototype.searchPatternForDefinitionKeys = function () {
|
|
43
|
+
return "".concat(this.buildDefinitionKeyPrefix(), "*");
|
|
44
44
|
};
|
|
45
45
|
KeyBuilderSS.prototype.searchPatternForRBSegmentKeys = function () {
|
|
46
|
-
return this.buildRBSegmentKeyPrefix()
|
|
46
|
+
return "".concat(this.buildRBSegmentKeyPrefix(), "*");
|
|
47
47
|
};
|
|
48
48
|
/* Telemetry keys */
|
|
49
49
|
KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
|
|
50
|
-
return this.latencyPrefix
|
|
50
|
+
return "".concat(this.latencyPrefix, "::").concat(this.versionablePrefix, "/").concat(exports.METHOD_NAMES[method], "/").concat(bucket);
|
|
51
51
|
};
|
|
52
52
|
KeyBuilderSS.prototype.buildExceptionKey = function (method) {
|
|
53
|
-
return this.exceptionPrefix
|
|
53
|
+
return "".concat(this.exceptionPrefix, "::").concat(this.versionablePrefix, "/").concat(exports.METHOD_NAMES[method]);
|
|
54
54
|
};
|
|
55
55
|
KeyBuilderSS.prototype.buildInitKey = function () {
|
|
56
|
-
return this.initPrefix
|
|
56
|
+
return "".concat(this.initPrefix, "::").concat(this.versionablePrefix);
|
|
57
57
|
};
|
|
58
58
|
return KeyBuilderSS;
|
|
59
59
|
}(KeyBuilder_1.KeyBuilder));
|
|
@@ -9,14 +9,14 @@ var key_1 = require("../utils/key");
|
|
|
9
9
|
function getRolloutPlan(log, storage, options) {
|
|
10
10
|
if (options === void 0) { options = {}; }
|
|
11
11
|
var keys = options.keys, exposeSegments = options.exposeSegments;
|
|
12
|
-
var
|
|
13
|
-
log.debug("storage: get feature flags"
|
|
12
|
+
var definitions = storage.definitions, segments = storage.segments, rbSegments = storage.rbSegments;
|
|
13
|
+
log.debug("storage: get feature flags".concat(keys ? ", and memberships for keys: ".concat(keys) : '').concat(exposeSegments ? ', and segments' : ''));
|
|
14
14
|
return {
|
|
15
15
|
splitChanges: {
|
|
16
16
|
ff: {
|
|
17
|
-
t:
|
|
17
|
+
t: definitions.getChangeNumber(),
|
|
18
18
|
s: -1,
|
|
19
|
-
d:
|
|
19
|
+
d: definitions.getAll(),
|
|
20
20
|
},
|
|
21
21
|
rbs: {
|
|
22
22
|
t: rbSegments.getChangeNumber(),
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefinitionsCacheInLocal = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
|
|
6
|
+
var lang_1 = require("../../utils/lang");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
var sets_1 = require("../../utils/lang/sets");
|
|
9
|
+
var DefinitionsCacheInLocal = /** @class */ (function (_super) {
|
|
10
|
+
tslib_1.__extends(DefinitionsCacheInLocal, _super);
|
|
11
|
+
function DefinitionsCacheInLocal(settings, keys, storage) {
|
|
12
|
+
var _this = _super.call(this) || this;
|
|
13
|
+
_this.keys = keys;
|
|
14
|
+
_this.log = settings.log;
|
|
15
|
+
_this.setsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
16
|
+
_this.storage = storage;
|
|
17
|
+
return _this;
|
|
18
|
+
}
|
|
19
|
+
DefinitionsCacheInLocal.prototype._decrementCount = function (key) {
|
|
20
|
+
var count = (0, lang_1.toNumber)(this.storage.getItem(key)) - 1;
|
|
21
|
+
if (count > 0)
|
|
22
|
+
this.storage.setItem(key, count + '');
|
|
23
|
+
else
|
|
24
|
+
this.storage.removeItem(key);
|
|
25
|
+
};
|
|
26
|
+
DefinitionsCacheInLocal.prototype._decrementCounts = function (definition) {
|
|
27
|
+
try {
|
|
28
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
29
|
+
this._decrementCount(ttKey);
|
|
30
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition)) {
|
|
31
|
+
var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
|
|
32
|
+
this._decrementCount(segmentsCountKey);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
this.log.error(constants_1.LOG_PREFIX + e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
DefinitionsCacheInLocal.prototype._incrementCounts = function (definition) {
|
|
40
|
+
try {
|
|
41
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
42
|
+
this.storage.setItem(ttKey, ((0, lang_1.toNumber)(this.storage.getItem(ttKey)) + 1) + '');
|
|
43
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition)) {
|
|
44
|
+
var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
|
|
45
|
+
this.storage.setItem(segmentsCountKey, ((0, lang_1.toNumber)(this.storage.getItem(segmentsCountKey)) + 1) + '');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
this.log.error(constants_1.LOG_PREFIX + e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Removes all definitions related data from localStorage (splits, counters, changeNumber and lastUpdated).
|
|
54
|
+
* We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
|
|
55
|
+
*/
|
|
56
|
+
DefinitionsCacheInLocal.prototype.clear = function () {
|
|
57
|
+
var _this = this;
|
|
58
|
+
// collect item keys
|
|
59
|
+
var len = this.storage.length;
|
|
60
|
+
var accum = [];
|
|
61
|
+
for (var cur = 0; cur < len; cur++) {
|
|
62
|
+
var key = this.storage.key(cur);
|
|
63
|
+
if (key != null && this.keys.isDefinitionsCacheKey(key))
|
|
64
|
+
accum.push(key);
|
|
65
|
+
}
|
|
66
|
+
// remove items
|
|
67
|
+
accum.forEach(function (key) {
|
|
68
|
+
_this.storage.removeItem(key);
|
|
69
|
+
});
|
|
70
|
+
this.hasSync = false;
|
|
71
|
+
};
|
|
72
|
+
DefinitionsCacheInLocal.prototype.add = function (definition) {
|
|
73
|
+
var name = definition.name;
|
|
74
|
+
var definitionKey = this.keys.buildDefinitionKey(name);
|
|
75
|
+
var definitionFromStorage = this.storage.getItem(definitionKey);
|
|
76
|
+
var previousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : null;
|
|
77
|
+
if (previousDefinition) {
|
|
78
|
+
this._decrementCounts(previousDefinition);
|
|
79
|
+
this.removeFromSets(previousDefinition.name, previousDefinition.sets);
|
|
80
|
+
}
|
|
81
|
+
this.storage.setItem(definitionKey, JSON.stringify(definition));
|
|
82
|
+
this._incrementCounts(definition);
|
|
83
|
+
this.addToSets(definition);
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
DefinitionsCacheInLocal.prototype.remove = function (name) {
|
|
87
|
+
var definition = this.get(name);
|
|
88
|
+
if (!definition)
|
|
89
|
+
return false;
|
|
90
|
+
this.storage.removeItem(this.keys.buildDefinitionKey(name));
|
|
91
|
+
this._decrementCounts(definition);
|
|
92
|
+
this.removeFromSets(definition.name, definition.sets);
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
95
|
+
DefinitionsCacheInLocal.prototype.get = function (name) {
|
|
96
|
+
var item = this.storage.getItem(this.keys.buildDefinitionKey(name));
|
|
97
|
+
return item && JSON.parse(item);
|
|
98
|
+
};
|
|
99
|
+
DefinitionsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
100
|
+
try {
|
|
101
|
+
this.storage.setItem(this.keys.buildDefinitionsTillKey(), changeNumber + '');
|
|
102
|
+
// update "last updated" timestamp with current time
|
|
103
|
+
this.storage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
|
|
104
|
+
this.hasSync = true;
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
this.log.error(constants_1.LOG_PREFIX + e);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
DefinitionsCacheInLocal.prototype.getChangeNumber = function () {
|
|
113
|
+
var n = -1;
|
|
114
|
+
var value = this.storage.getItem(this.keys.buildDefinitionsTillKey());
|
|
115
|
+
if (value !== null) {
|
|
116
|
+
value = parseInt(value, 10);
|
|
117
|
+
return (0, lang_1.isNaNNumber)(value) ? n : value;
|
|
118
|
+
}
|
|
119
|
+
return n;
|
|
120
|
+
};
|
|
121
|
+
DefinitionsCacheInLocal.prototype.getNames = function () {
|
|
122
|
+
var len = this.storage.length;
|
|
123
|
+
var accum = [];
|
|
124
|
+
var cur = 0;
|
|
125
|
+
while (cur < len) {
|
|
126
|
+
var key = this.storage.key(cur);
|
|
127
|
+
if (key != null && this.keys.isDefinitionKey(key))
|
|
128
|
+
accum.push(this.keys.extractKey(key));
|
|
129
|
+
cur++;
|
|
130
|
+
}
|
|
131
|
+
return accum;
|
|
132
|
+
};
|
|
133
|
+
DefinitionsCacheInLocal.prototype.trafficTypeExists = function (trafficType) {
|
|
134
|
+
var ttCount = (0, lang_1.toNumber)(this.storage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
|
|
135
|
+
return (0, lang_1.isFiniteNumber)(ttCount) && ttCount > 0;
|
|
136
|
+
};
|
|
137
|
+
DefinitionsCacheInLocal.prototype.usesSegments = function () {
|
|
138
|
+
// If cache hasn't been synchronized with the cloud, assume we need them.
|
|
139
|
+
if (!this.hasSync)
|
|
140
|
+
return true;
|
|
141
|
+
var storedCount = this.storage.getItem(this.keys.buildDefinitionsWithSegmentCountKey());
|
|
142
|
+
var definitionsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
|
|
143
|
+
return (0, lang_1.isFiniteNumber)(definitionsWithSegmentsCount) ?
|
|
144
|
+
definitionsWithSegmentsCount > 0 :
|
|
145
|
+
true;
|
|
146
|
+
};
|
|
147
|
+
DefinitionsCacheInLocal.prototype.getNamesBySets = function (sets) {
|
|
148
|
+
var _this = this;
|
|
149
|
+
return sets.map(function (set) {
|
|
150
|
+
var setKey = _this.keys.buildSetKey(set);
|
|
151
|
+
var setFromStorage = _this.storage.getItem(setKey);
|
|
152
|
+
return new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
DefinitionsCacheInLocal.prototype.addToSets = function (definition) {
|
|
156
|
+
var _this = this;
|
|
157
|
+
if (!definition.sets)
|
|
158
|
+
return;
|
|
159
|
+
definition.sets.forEach(function (set) {
|
|
160
|
+
if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterSet) { return filterSet === set; }))
|
|
161
|
+
return;
|
|
162
|
+
var setKey = _this.keys.buildSetKey(set);
|
|
163
|
+
var setFromStorage = _this.storage.getItem(setKey);
|
|
164
|
+
var setCache = new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
|
|
165
|
+
if (setCache.has(definition.name))
|
|
166
|
+
return;
|
|
167
|
+
setCache.add(definition.name);
|
|
168
|
+
_this.storage.setItem(setKey, JSON.stringify((0, sets_1.setToArray)(setCache)));
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
DefinitionsCacheInLocal.prototype.removeFromSets = function (definitionName, sets) {
|
|
172
|
+
var _this = this;
|
|
173
|
+
if (!sets)
|
|
174
|
+
return;
|
|
175
|
+
sets.forEach(function (set) {
|
|
176
|
+
_this.removeNames(set, definitionName);
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
DefinitionsCacheInLocal.prototype.removeNames = function (setName, definitionName) {
|
|
180
|
+
var setKey = this.keys.buildSetKey(setName);
|
|
181
|
+
var setFromStorage = this.storage.getItem(setKey);
|
|
182
|
+
if (!setFromStorage)
|
|
183
|
+
return;
|
|
184
|
+
var setCache = new Set(JSON.parse(setFromStorage));
|
|
185
|
+
setCache.delete(definitionName);
|
|
186
|
+
if (setCache.size === 0) {
|
|
187
|
+
this.storage.removeItem(setKey);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.storage.setItem(setKey, JSON.stringify((0, sets_1.setToArray)(setCache)));
|
|
191
|
+
};
|
|
192
|
+
return DefinitionsCacheInLocal;
|
|
193
|
+
}(AbstractDefinitionsCacheSync_1.AbstractDefinitionsCacheSync));
|
|
194
|
+
exports.DefinitionsCacheInLocal = DefinitionsCacheInLocal;
|
|
@@ -6,7 +6,7 @@ var lang_1 = require("../../utils/lang");
|
|
|
6
6
|
var AbstractMySegmentsCacheSync_1 = require("../AbstractMySegmentsCacheSync");
|
|
7
7
|
var constants_1 = require("./constants");
|
|
8
8
|
var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
9
|
-
|
|
9
|
+
tslib_1.__extends(MySegmentsCacheInLocal, _super);
|
|
10
10
|
function MySegmentsCacheInLocal(log, keys, storage) {
|
|
11
11
|
var _this = _super.call(this) || this;
|
|
12
12
|
_this.log = log;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RBSegmentsCacheInLocal = void 0;
|
|
4
4
|
var lang_1 = require("../../utils/lang");
|
|
5
5
|
var sets_1 = require("../../utils/lang/sets");
|
|
6
|
-
var
|
|
6
|
+
var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
|
|
7
7
|
var constants_1 = require("./constants");
|
|
8
8
|
var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
9
9
|
function RBSegmentsCacheInLocal(settings, keys, storage) {
|
|
@@ -19,7 +19,7 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
19
19
|
RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
20
20
|
var _this = this;
|
|
21
21
|
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
22
|
-
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove
|
|
22
|
+
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove); }).some(function (result) { return result; }) || updated;
|
|
23
23
|
this.setChangeNumber(changeNumber);
|
|
24
24
|
return updated;
|
|
25
25
|
};
|
|
@@ -33,7 +33,7 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
RBSegmentsCacheInLocal.prototype.updateSegmentCount = function (diff) {
|
|
36
|
-
var segmentsCountKey = this.keys.
|
|
36
|
+
var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
|
|
37
37
|
var count = (0, lang_1.toNumber)(this.storage.getItem(segmentsCountKey)) + diff;
|
|
38
38
|
if (count > 0)
|
|
39
39
|
this.storage.setItem(segmentsCountKey, count + '');
|
|
@@ -47,9 +47,9 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
47
47
|
var previous = rbSegmentFromStorage ? JSON.parse(rbSegmentFromStorage) : null;
|
|
48
48
|
this.storage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
|
|
49
49
|
var usesSegmentsDiff = 0;
|
|
50
|
-
if (previous && (0,
|
|
50
|
+
if (previous && (0, AbstractDefinitionsCacheSync_1.usesSegments)(previous))
|
|
51
51
|
usesSegmentsDiff--;
|
|
52
|
-
if ((0,
|
|
52
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(rbSegment))
|
|
53
53
|
usesSegmentsDiff++;
|
|
54
54
|
if (usesSegmentsDiff !== 0)
|
|
55
55
|
this.updateSegmentCount(usesSegmentsDiff);
|
|
@@ -60,7 +60,7 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
60
60
|
if (!rbSegment)
|
|
61
61
|
return false;
|
|
62
62
|
this.storage.removeItem(this.keys.buildRBSegmentKey(name));
|
|
63
|
-
if ((0,
|
|
63
|
+
if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(rbSegment))
|
|
64
64
|
this.updateSegmentCount(-1);
|
|
65
65
|
return true;
|
|
66
66
|
};
|
|
@@ -99,10 +99,10 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
99
99
|
return n;
|
|
100
100
|
};
|
|
101
101
|
RBSegmentsCacheInLocal.prototype.usesSegments = function () {
|
|
102
|
-
var storedCount = this.storage.getItem(this.keys.
|
|
103
|
-
var
|
|
104
|
-
return (0, lang_1.isFiniteNumber)(
|
|
105
|
-
|
|
102
|
+
var storedCount = this.storage.getItem(this.keys.buildDefinitionsWithSegmentCountKey());
|
|
103
|
+
var definitionsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
|
|
104
|
+
return (0, lang_1.isFiniteNumber)(definitionsWithSegmentsCount) ?
|
|
105
|
+
definitionsWithSegmentsCount > 0 :
|
|
106
106
|
true;
|
|
107
107
|
};
|
|
108
108
|
return RBSegmentsCacheInLocal;
|
|
@@ -7,7 +7,7 @@ var EventsCacheInMemory_1 = require("../inMemory/EventsCacheInMemory");
|
|
|
7
7
|
var KeyBuilder_1 = require("../KeyBuilder");
|
|
8
8
|
var KeyBuilderCS_1 = require("../KeyBuilderCS");
|
|
9
9
|
var isLocalStorageAvailable_1 = require("../../utils/env/isLocalStorageAvailable");
|
|
10
|
-
var
|
|
10
|
+
var DefinitionsCacheInLocal_1 = require("./DefinitionsCacheInLocal");
|
|
11
11
|
var RBSegmentsCacheInLocal_1 = require("./RBSegmentsCacheInLocal");
|
|
12
12
|
var MySegmentsCacheInLocal_1 = require("./MySegmentsCacheInLocal");
|
|
13
13
|
var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
|
|
@@ -44,24 +44,24 @@ function InLocalStorage(options) {
|
|
|
44
44
|
return (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
|
|
45
45
|
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
46
46
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
47
|
-
var
|
|
47
|
+
var definitions = new DefinitionsCacheInLocal_1.DefinitionsCacheInLocal(settings, keys, storage);
|
|
48
48
|
var rbSegments = new RBSegmentsCacheInLocal_1.RBSegmentsCacheInLocal(settings, keys, storage);
|
|
49
49
|
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys, storage);
|
|
50
50
|
var largeSegments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey), storage);
|
|
51
51
|
var validateCachePromise;
|
|
52
52
|
return {
|
|
53
|
-
|
|
53
|
+
definitions: definitions,
|
|
54
54
|
rbSegments: rbSegments,
|
|
55
55
|
segments: segments,
|
|
56
56
|
largeSegments: largeSegments,
|
|
57
57
|
impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
|
|
58
58
|
impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
|
|
59
59
|
events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
|
|
60
|
-
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(
|
|
60
|
+
telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(definitions, segments) : undefined,
|
|
61
61
|
uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
|
|
62
62
|
validateCache: function () {
|
|
63
63
|
if (!validateCachePromise) {
|
|
64
|
-
validateCachePromise = (0, validateCache_1.validateCache)(options, storage, settings, keys,
|
|
64
|
+
validateCachePromise = (0, validateCache_1.validateCache)(options, storage, settings, keys, definitions, rbSegments, segments, largeSegments);
|
|
65
65
|
}
|
|
66
66
|
return validateCachePromise;
|
|
67
67
|
},
|
|
@@ -74,7 +74,7 @@ function InLocalStorage(options) {
|
|
|
74
74
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
|
|
75
75
|
shared: function (matchingKey) {
|
|
76
76
|
return {
|
|
77
|
-
|
|
77
|
+
definitions: this.definitions,
|
|
78
78
|
rbSegments: this.rbSegments,
|
|
79
79
|
segments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey), storage),
|
|
80
80
|
largeSegments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, (0, KeyBuilderCS_1.myLargeSegmentsKeyBuilder)(prefix, matchingKey), storage),
|
|
@@ -57,16 +57,16 @@ function validateExpiration(options, storage, settings, keys, currentTimestamp,
|
|
|
57
57
|
*
|
|
58
58
|
* @returns Metadata object with `initialCacheLoad` (true if is fresh install, false if is ready from cache) and `lastUpdateTimestamp` (timestamp of last cache update or undefined)
|
|
59
59
|
*/
|
|
60
|
-
function validateCache(options, storage, settings, keys,
|
|
60
|
+
function validateCache(options, storage, settings, keys, definitions, rbSegments, segments, largeSegments) {
|
|
61
61
|
return Promise.resolve(storage.load && storage.load()).then(function () {
|
|
62
62
|
var currentTimestamp = Date.now();
|
|
63
|
-
var isThereCache =
|
|
63
|
+
var isThereCache = definitions.getChangeNumber() > -1;
|
|
64
64
|
// Get lastUpdateTimestamp from storage
|
|
65
65
|
var lastUpdatedTimestampStr = storage.getItem(keys.buildLastUpdatedKey());
|
|
66
66
|
var lastUpdatedTimestamp = lastUpdatedTimestampStr ? parseInt(lastUpdatedTimestampStr, 10) : undefined;
|
|
67
67
|
var lastUpdateTimestamp = (!(0, lang_1.isNaNNumber)(lastUpdatedTimestamp) && lastUpdatedTimestamp !== undefined) ? lastUpdatedTimestamp : undefined;
|
|
68
68
|
if (validateExpiration(options, storage, settings, keys, currentTimestamp, isThereCache)) {
|
|
69
|
-
|
|
69
|
+
definitions.clear();
|
|
70
70
|
rbSegments.clear();
|
|
71
71
|
segments.clear();
|
|
72
72
|
largeSegments.clear();
|