@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
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { __extends, __spreadArray } from "tslib";
|
|
2
|
+
import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
|
|
3
|
+
import { LOG_PREFIX } from './constants';
|
|
4
|
+
import { AbstractDefinitionsCacheAsync } from '../AbstractDefinitionsCacheAsync';
|
|
5
|
+
import { returnDifference } from '../../utils/lang/sets';
|
|
6
|
+
/**
|
|
7
|
+
* IDefinitionsCacheAsync implementation for pluggable storages.
|
|
8
|
+
*/
|
|
9
|
+
var DefinitionsCachePluggable = /** @class */ (function (_super) {
|
|
10
|
+
__extends(DefinitionsCachePluggable, _super);
|
|
11
|
+
/**
|
|
12
|
+
* Create a DefinitionsCache that uses a storage wrapper.
|
|
13
|
+
* @param log - Logger instance.
|
|
14
|
+
* @param keys - Key builder.
|
|
15
|
+
* @param wrapper - Adapted wrapper storage.
|
|
16
|
+
*/
|
|
17
|
+
function DefinitionsCachePluggable(log, keys, wrapper, splitFiltersValidation) {
|
|
18
|
+
var _this = _super.call(this) || this;
|
|
19
|
+
_this.log = log;
|
|
20
|
+
_this.keys = keys;
|
|
21
|
+
_this.wrapper = wrapper;
|
|
22
|
+
_this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
DefinitionsCachePluggable.prototype._decrementCounts = function (definition) {
|
|
26
|
+
var _this = this;
|
|
27
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
28
|
+
return this.wrapper.decr(ttKey).then(function (count) {
|
|
29
|
+
if (count === 0)
|
|
30
|
+
return _this.wrapper.del(ttKey);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
DefinitionsCachePluggable.prototype._incrementCounts = function (definition) {
|
|
34
|
+
var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
|
|
35
|
+
return this.wrapper.incr(ttKey);
|
|
36
|
+
};
|
|
37
|
+
DefinitionsCachePluggable.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
|
|
38
|
+
var _this = this;
|
|
39
|
+
var removeFromSets = returnDifference(setsOfRemovedDefinition, setsOfAddedDefinition);
|
|
40
|
+
var addToSets = returnDifference(setsOfAddedDefinition, setsOfRemovedDefinition);
|
|
41
|
+
if (this.setsFilter.length > 0) {
|
|
42
|
+
addToSets = addToSets.filter(function (set) {
|
|
43
|
+
return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
var items = [definitionName];
|
|
47
|
+
return Promise.all(__spreadArray(__spreadArray([], removeFromSets.map(function (setName) { return _this.wrapper.removeItems(_this.keys.buildSetKey(setName), items); }), true), addToSets.map(function (setName) { return _this.wrapper.addItems(_this.keys.buildSetKey(setName), items); }), true));
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Add a given definition.
|
|
51
|
+
* The returned promise is resolved when the operation success
|
|
52
|
+
* or rejected if it fails (e.g., wrapper operation fails)
|
|
53
|
+
*/
|
|
54
|
+
DefinitionsCachePluggable.prototype.add = function (definition) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
var name = definition.name;
|
|
57
|
+
var definitionKey = this.keys.buildDefinitionKey(name);
|
|
58
|
+
return this.wrapper.get(definitionKey).then(function (definitionFromStorage) {
|
|
59
|
+
// handling parsing error
|
|
60
|
+
var parsedPreviousDefinition, stringifiedNewDefinition;
|
|
61
|
+
try {
|
|
62
|
+
parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
|
|
63
|
+
stringifiedNewDefinition = JSON.stringify(definition);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
throw new Error('Error parsing feature flag definition: ' + e);
|
|
67
|
+
}
|
|
68
|
+
return _this.wrapper.set(definitionKey, stringifiedNewDefinition).then(function () {
|
|
69
|
+
// avoid unnecessary increment/decrement operations
|
|
70
|
+
if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
|
|
71
|
+
return;
|
|
72
|
+
// update traffic type counts
|
|
73
|
+
return _this._incrementCounts(definition).then(function () {
|
|
74
|
+
if (parsedPreviousDefinition)
|
|
75
|
+
return _this._decrementCounts(parsedPreviousDefinition);
|
|
76
|
+
});
|
|
77
|
+
}).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
|
|
78
|
+
}).then(function () { return true; });
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Remove a given definition.
|
|
82
|
+
* The returned promise is resolved when the operation success, with a boolean indicating if the definition existed or not.
|
|
83
|
+
* or rejected if it fails (e.g., wrapper operation fails).
|
|
84
|
+
*/
|
|
85
|
+
DefinitionsCachePluggable.prototype.remove = function (name) {
|
|
86
|
+
var _this = this;
|
|
87
|
+
return this.get(name).then(function (definition) {
|
|
88
|
+
if (definition) {
|
|
89
|
+
return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
|
|
90
|
+
}
|
|
91
|
+
}).then(function () {
|
|
92
|
+
return _this.wrapper.del(_this.keys.buildDefinitionKey(name));
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Get definition.
|
|
97
|
+
* The returned promise is resolved with the definition or null if it's not defined,
|
|
98
|
+
* or rejected if wrapper operation fails.
|
|
99
|
+
*/
|
|
100
|
+
DefinitionsCachePluggable.prototype.get = function (name) {
|
|
101
|
+
return this.wrapper.get(this.keys.buildDefinitionKey(name))
|
|
102
|
+
.then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Get list of definitions.
|
|
106
|
+
* The returned promise is resolved with a map of names to their definition or null if it's not defined,
|
|
107
|
+
* or rejected if wrapper operation fails.
|
|
108
|
+
*/
|
|
109
|
+
DefinitionsCachePluggable.prototype.getMany = function (names) {
|
|
110
|
+
var _this = this;
|
|
111
|
+
var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
|
|
112
|
+
return this.wrapper.getMany(keys).then(function (stringifiedDefinitions) {
|
|
113
|
+
var definitions = {};
|
|
114
|
+
names.forEach(function (name, idx) {
|
|
115
|
+
var definition = stringifiedDefinitions[idx];
|
|
116
|
+
definitions[name] = definition && JSON.parse(definition);
|
|
117
|
+
});
|
|
118
|
+
return Promise.resolve(definitions);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Get list of all definitions.
|
|
123
|
+
* The returned promise is resolved with the list of definitions,
|
|
124
|
+
* or rejected if wrapper operation fails.
|
|
125
|
+
*/
|
|
126
|
+
DefinitionsCachePluggable.prototype.getAll = function () {
|
|
127
|
+
var _this = this;
|
|
128
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix())
|
|
129
|
+
.then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
|
|
130
|
+
.then(function (definitions) { return definitions.map(function (definition) {
|
|
131
|
+
return JSON.parse(definition);
|
|
132
|
+
}); });
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Get list of definition names.
|
|
136
|
+
* The returned promise is resolved with the list of names,
|
|
137
|
+
* or rejected if wrapper operation fails.
|
|
138
|
+
*/
|
|
139
|
+
DefinitionsCachePluggable.prototype.getNames = function () {
|
|
140
|
+
var _this = this;
|
|
141
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Get list of definition names related to a given list of set names.
|
|
145
|
+
* The returned promise is resolved with the list of names per set.
|
|
146
|
+
* It never rejects (If there is a wrapper error for some set, an empty set is returned for it).
|
|
147
|
+
*/
|
|
148
|
+
DefinitionsCachePluggable.prototype.getNamesBySets = function (sets) {
|
|
149
|
+
var _this = this;
|
|
150
|
+
return Promise.all(sets.map(function (set) {
|
|
151
|
+
var setKey = _this.keys.buildSetKey(set);
|
|
152
|
+
return _this.wrapper.getItems(setKey).catch(function () { return []; });
|
|
153
|
+
})).then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Check traffic type existence.
|
|
157
|
+
* The returned promise is resolved with a boolean indicating whether the TT exist or not.
|
|
158
|
+
* In case of wrapper operation failures, the promise resolves with a true value, assuming that the TT might exist.
|
|
159
|
+
* It will never be rejected.
|
|
160
|
+
*/
|
|
161
|
+
DefinitionsCachePluggable.prototype.trafficTypeExists = function (trafficType) {
|
|
162
|
+
var _this = this;
|
|
163
|
+
// If there is a number there should be > 0, otherwise the TT is considered as not existent.
|
|
164
|
+
return this.wrapper.get(this.keys.buildTrafficTypeKey(trafficType))
|
|
165
|
+
.then(function (ttCount) {
|
|
166
|
+
if (ttCount === null)
|
|
167
|
+
return false; // if entry doesn't exist, means that TT doesn't exist
|
|
168
|
+
ttCount = parseInt(ttCount, 10);
|
|
169
|
+
if (!isFiniteNumber(ttCount) || ttCount < 0) {
|
|
170
|
+
_this.log.info(LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to data corruption of some sorts."));
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return ttCount > 0;
|
|
174
|
+
}).catch(function (e) {
|
|
175
|
+
_this.log.error(LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to an error: ").concat(e, "."));
|
|
176
|
+
// If there is an error, bypass the validation so the event can get tracked.
|
|
177
|
+
return true;
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Set till number.
|
|
182
|
+
* The returned promise is resolved when the operation success,
|
|
183
|
+
* or rejected if it fails (e.g., wrapper operation fails).
|
|
184
|
+
*/
|
|
185
|
+
DefinitionsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
|
|
186
|
+
return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Get till number or -1 if it's not defined.
|
|
190
|
+
* The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
|
|
191
|
+
* The promise will never be rejected.
|
|
192
|
+
*/
|
|
193
|
+
DefinitionsCachePluggable.prototype.getChangeNumber = function () {
|
|
194
|
+
var _this = this;
|
|
195
|
+
return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
|
|
196
|
+
var i = parseInt(value, 10);
|
|
197
|
+
return isNaNNumber(i) ? -1 : i;
|
|
198
|
+
}).catch(function (e) {
|
|
199
|
+
_this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
|
|
200
|
+
return -1;
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
// @TODO implement if required by DataLoader or producer mode
|
|
204
|
+
DefinitionsCachePluggable.prototype.clear = function () {
|
|
205
|
+
return Promise.resolve(true);
|
|
206
|
+
};
|
|
207
|
+
return DefinitionsCachePluggable;
|
|
208
|
+
}(AbstractDefinitionsCacheAsync));
|
|
209
|
+
export { DefinitionsCachePluggable };
|
|
@@ -18,7 +18,7 @@ var EventsCachePluggable = /** @class */ (function () {
|
|
|
18
18
|
// We use boolean values to signal successful queueing
|
|
19
19
|
.then(function () { return true; })
|
|
20
20
|
.catch(function (e) {
|
|
21
|
-
_this.log.error(LOG_PREFIX
|
|
21
|
+
_this.log.error("".concat(LOG_PREFIX, "Error adding event to queue: ").concat(e, "."));
|
|
22
22
|
return false;
|
|
23
23
|
});
|
|
24
24
|
};
|
|
@@ -21,10 +21,10 @@ var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
|
|
|
21
21
|
if (!keys.length)
|
|
22
22
|
return Promise.resolve(false);
|
|
23
23
|
var pipeline = keys.reduce(function (pipeline, key) {
|
|
24
|
-
return pipeline.then(function () { return _this.wrapper.incr(_this.key
|
|
24
|
+
return pipeline.then(function () { return _this.wrapper.incr("".concat(_this.key, "::").concat(key), counts[key]); });
|
|
25
25
|
}, Promise.resolve());
|
|
26
26
|
return pipeline.catch(function (err) {
|
|
27
|
-
_this.log.error(LOG_PREFIX
|
|
27
|
+
_this.log.error("".concat(LOG_PREFIX, "Error in impression counts pipeline: ").concat(err, "."));
|
|
28
28
|
return false;
|
|
29
29
|
});
|
|
30
30
|
};
|
|
@@ -49,18 +49,18 @@ var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
|
|
|
49
49
|
var count = counts[i];
|
|
50
50
|
var keyFeatureNameAndTime = key.split('::');
|
|
51
51
|
if (keyFeatureNameAndTime.length !== 3) {
|
|
52
|
-
_this.log.error(LOG_PREFIX
|
|
52
|
+
_this.log.error("".concat(LOG_PREFIX, "Error spliting key ").concat(key));
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
55
|
var timeFrame = parseInt(keyFeatureNameAndTime[2]);
|
|
56
56
|
if (isNaN(timeFrame)) {
|
|
57
|
-
_this.log.error(LOG_PREFIX
|
|
57
|
+
_this.log.error("".concat(LOG_PREFIX, "Error parsing time frame ").concat(keyFeatureNameAndTime[2]));
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
60
|
// @ts-ignore
|
|
61
61
|
var rawCount = parseInt(count);
|
|
62
62
|
if (isNaN(rawCount)) {
|
|
63
|
-
_this.log.error(LOG_PREFIX
|
|
63
|
+
_this.log.error("".concat(LOG_PREFIX, "Error parsing raw count ").concat(count));
|
|
64
64
|
continue;
|
|
65
65
|
}
|
|
66
66
|
pf.push({
|
|
@@ -31,7 +31,7 @@ var RBSegmentsCachePluggable = /** @class */ (function () {
|
|
|
31
31
|
return _this.wrapper.set(key, stringifiedNewRBSegment).then(function () { return true; });
|
|
32
32
|
})),
|
|
33
33
|
Promise.all(toRemove.map(function (toRemove) {
|
|
34
|
-
var key = _this.keys.buildRBSegmentKey(toRemove
|
|
34
|
+
var key = _this.keys.buildRBSegmentKey(toRemove);
|
|
35
35
|
return _this.wrapper.del(key);
|
|
36
36
|
}))
|
|
37
37
|
]).then(function (_a) {
|
|
@@ -42,18 +42,18 @@ var TelemetryCachePluggable = /** @class */ (function () {
|
|
|
42
42
|
var field = latencyKeys[i].split('::')[1];
|
|
43
43
|
var parsedField = parseLatencyField(field);
|
|
44
44
|
if (isString(parsedField)) {
|
|
45
|
-
_this.log.error("Ignoring invalid latency field: "
|
|
45
|
+
_this.log.error("Ignoring invalid latency field: ".concat(field, ": ").concat(parsedField));
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
48
|
// @ts-ignore
|
|
49
49
|
var count = parseInt(latencies[i]);
|
|
50
50
|
if (isNaNNumber(count)) {
|
|
51
|
-
_this.log.error("Ignoring latency with invalid count: "
|
|
51
|
+
_this.log.error("Ignoring latency with invalid count: ".concat(latencies[i]));
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
54
|
var metadata = parsedField[0], method = parsedField[1], bucket = parsedField[2];
|
|
55
55
|
if (bucket >= MAX_LATENCY_BUCKET_COUNT) {
|
|
56
|
-
_this.log.error("Ignoring latency with invalid bucket: "
|
|
56
|
+
_this.log.error("Ignoring latency with invalid bucket: ".concat(bucket));
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
var methodLatencies = result.get(metadata) || {};
|
|
@@ -81,13 +81,13 @@ var TelemetryCachePluggable = /** @class */ (function () {
|
|
|
81
81
|
var field = exceptionKeys[i].split('::')[1];
|
|
82
82
|
var parsedField = parseExceptionField(field);
|
|
83
83
|
if (isString(parsedField)) {
|
|
84
|
-
_this.log.error("Ignoring invalid exception field: "
|
|
84
|
+
_this.log.error("Ignoring invalid exception field: ".concat(field, ": ").concat(parsedField));
|
|
85
85
|
continue;
|
|
86
86
|
}
|
|
87
87
|
// @ts-ignore
|
|
88
88
|
var count = parseInt(exceptions[i]);
|
|
89
89
|
if (isNaNNumber(count)) {
|
|
90
|
-
_this.log.error("Ignoring exception with invalid count: "
|
|
90
|
+
_this.log.error("Ignoring exception with invalid count: ".concat(exceptions[i]));
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
93
|
var metadata = parsedField[0], method = parsedField[1];
|
|
@@ -115,7 +115,7 @@ var TelemetryCachePluggable = /** @class */ (function () {
|
|
|
115
115
|
var field = configKeys[i].split('::')[1];
|
|
116
116
|
var parsedField = parseMetadata(field);
|
|
117
117
|
if (isString(parsedField)) {
|
|
118
|
-
_this.log.error("Ignoring invalid config field: "
|
|
118
|
+
_this.log.error("Ignoring invalid config field: ".concat(field, ": ").concat(parsedField));
|
|
119
119
|
continue;
|
|
120
120
|
}
|
|
121
121
|
var metadata = parsedField[0];
|
|
@@ -124,7 +124,7 @@ var TelemetryCachePluggable = /** @class */ (function () {
|
|
|
124
124
|
result.set(metadata, config);
|
|
125
125
|
}
|
|
126
126
|
catch (e) {
|
|
127
|
-
_this.log.error("Ignoring invalid config: "
|
|
127
|
+
_this.log.error("Ignoring invalid config: ".concat(configs[i]));
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
return Promise.all(configKeys.map(function (configKey) { return _this.wrapper.del(configKey); })).then(function () { return result; });
|
|
@@ -32,7 +32,7 @@ var UniqueKeysCachePluggable = /** @class */ (function (_super) {
|
|
|
32
32
|
this.clear();
|
|
33
33
|
return this.wrapper.pushItems(this.key, uniqueKeysArray)
|
|
34
34
|
.catch(function (err) {
|
|
35
|
-
_this.log.error(LOG_PREFIX
|
|
35
|
+
_this.log.error("".concat(LOG_PREFIX, "Error in uniqueKeys pipeline: ").concat(err, "."));
|
|
36
36
|
return false;
|
|
37
37
|
});
|
|
38
38
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
3
|
-
import {
|
|
3
|
+
import { DefinitionsCachePluggable } from './DefinitionsCachePluggable';
|
|
4
4
|
import { SegmentsCachePluggable } from './SegmentsCachePluggable';
|
|
5
5
|
import { ImpressionsCachePluggable } from './ImpressionsCachePluggable';
|
|
6
6
|
import { EventsCachePluggable } from './EventsCachePluggable';
|
|
@@ -35,7 +35,7 @@ function validatePluggableStorageOptions(options) {
|
|
|
35
35
|
var wrapper = options.wrapper;
|
|
36
36
|
var missingMethods = METHODS_TO_PROMISE_WRAP.filter(function (method) { return typeof wrapper[method] !== 'function'; });
|
|
37
37
|
if (missingMethods.length)
|
|
38
|
-
throw new Error(NO_VALID_WRAPPER_INTERFACE
|
|
38
|
+
throw new Error("".concat(NO_VALID_WRAPPER_INTERFACE, " The following methods are missing or invalid: ").concat(missingMethods));
|
|
39
39
|
}
|
|
40
40
|
// Async return type in `client.track` method on consumer partial mode
|
|
41
41
|
// No need to promisify impressions cache
|
|
@@ -79,7 +79,7 @@ export function PluggableStorage(options) {
|
|
|
79
79
|
var currentHash = getStorageHash(settings);
|
|
80
80
|
if (hash !== currentHash) {
|
|
81
81
|
log.info(LOG_PREFIX + 'Storage HASH has changed (SDK key, flags filter criteria or flags spec version was modified). Clearing cache');
|
|
82
|
-
return wrapper.getKeysByPrefix(keys.prefix
|
|
82
|
+
return wrapper.getKeysByPrefix("".concat(keys.prefix, ".")).then(function (storageKeys) {
|
|
83
83
|
return Promise.all(storageKeys.map(function (storageKey) { return wrapper.del(storageKey); }));
|
|
84
84
|
}).then(function () { return wrapper.set(keys.buildHashKey(), currentHash); });
|
|
85
85
|
}
|
|
@@ -103,7 +103,7 @@ export function PluggableStorage(options) {
|
|
|
103
103
|
return e; // Propagate error for shared clients
|
|
104
104
|
});
|
|
105
105
|
return {
|
|
106
|
-
|
|
106
|
+
definitions: new DefinitionsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
107
107
|
rbSegments: new RBSegmentsCachePluggable(log, keys, wrapper),
|
|
108
108
|
segments: new SegmentsCachePluggable(log, keys, wrapper),
|
|
109
109
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
@@ -31,7 +31,7 @@ export function wrapperAdapter(log, wrapper) {
|
|
|
31
31
|
METHODS_TO_PROMISE_WRAP.forEach(function (method) {
|
|
32
32
|
// Logs error and wraps it into a rejected promise.
|
|
33
33
|
function handleError(e) {
|
|
34
|
-
log.error(LOG_PREFIX
|
|
34
|
+
log.error("".concat(LOG_PREFIX, " Wrapper '").concat(method, "' operation threw an error. Message: ").concat(e));
|
|
35
35
|
return Promise.reject(e);
|
|
36
36
|
}
|
|
37
37
|
wrapperAdapter[method] = function () {
|
|
@@ -20,16 +20,16 @@ export function validateRolloutPlan(log, settings) {
|
|
|
20
20
|
* Otherwise, the storage is handled as a server-side storage (segments is an instance of SegmentsCache).
|
|
21
21
|
*/
|
|
22
22
|
export function setRolloutPlan(log, rolloutPlan, storage, matchingKey) {
|
|
23
|
-
var
|
|
23
|
+
var definitions = storage.definitions, rbSegments = storage.rbSegments, segments = storage.segments, largeSegments = storage.largeSegments;
|
|
24
24
|
var _a = rolloutPlan.splitChanges, ff = _a.ff, rbs = _a.rbs;
|
|
25
|
-
log.debug("storage: set feature flags and segments"
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
log.debug("storage: set feature flags and segments".concat(matchingKey ? " for key ".concat(matchingKey) : ''));
|
|
26
|
+
if (definitions && ff) {
|
|
27
|
+
definitions.clear();
|
|
28
|
+
definitions.update(ff.d || [], [], ff.t);
|
|
29
29
|
}
|
|
30
30
|
if (rbSegments && rbs) {
|
|
31
31
|
rbSegments.clear();
|
|
32
|
-
rbSegments.update(rbs.d, [], rbs.t);
|
|
32
|
+
rbSegments.update(rbs.d || [], [], rbs.t);
|
|
33
33
|
}
|
|
34
34
|
var segmentChanges = rolloutPlan.segmentChanges;
|
|
35
35
|
if (matchingKey) { // add memberships data (client-side)
|
package/esm/storages/utils.js
CHANGED
|
@@ -37,30 +37,30 @@ var REVERSE_METHOD_NAMES = Object.keys(METHOD_NAMES).reduce(function (acc, key)
|
|
|
37
37
|
export function parseMetadata(field) {
|
|
38
38
|
var parts = field.split('/');
|
|
39
39
|
if (parts.length !== 3)
|
|
40
|
-
return "invalid subsection count. Expected 3, got: "
|
|
40
|
+
return "invalid subsection count. Expected 3, got: ".concat(parts.length);
|
|
41
41
|
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
|
|
42
42
|
return [JSON.stringify({ s: s, n: n, i: i })];
|
|
43
43
|
}
|
|
44
44
|
export function parseExceptionField(field) {
|
|
45
45
|
var parts = field.split('/');
|
|
46
46
|
if (parts.length !== 4)
|
|
47
|
-
return "invalid subsection count. Expected 4, got: "
|
|
47
|
+
return "invalid subsection count. Expected 4, got: ".concat(parts.length);
|
|
48
48
|
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
|
|
49
49
|
var method = REVERSE_METHOD_NAMES[m];
|
|
50
50
|
if (!method)
|
|
51
|
-
return "unknown method '"
|
|
51
|
+
return "unknown method '".concat(m, "'");
|
|
52
52
|
return [JSON.stringify({ s: s, n: n, i: i }), method];
|
|
53
53
|
}
|
|
54
54
|
export function parseLatencyField(field) {
|
|
55
55
|
var parts = field.split('/');
|
|
56
56
|
if (parts.length !== 5)
|
|
57
|
-
return "invalid subsection count. Expected 5, got: "
|
|
57
|
+
return "invalid subsection count. Expected 5, got: ".concat(parts.length);
|
|
58
58
|
var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
|
|
59
59
|
var method = REVERSE_METHOD_NAMES[m];
|
|
60
60
|
if (!method)
|
|
61
|
-
return "unknown method '"
|
|
61
|
+
return "unknown method '".concat(m, "'");
|
|
62
62
|
var bucket = parseInt(b);
|
|
63
63
|
if (isNaN(bucket) || bucket >= MAX_LATENCY_BUCKET_COUNT)
|
|
64
|
-
return "invalid bucket. Expected a number between 0 and "
|
|
64
|
+
return "invalid bucket. Expected a number between 0 and ".concat(MAX_LATENCY_BUCKET_COUNT - 1, ", got: ").concat(b);
|
|
65
65
|
return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
|
|
66
66
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { forOwn } from '../../../utils/lang';
|
|
2
2
|
import { syncTaskFactory } from '../../syncTask';
|
|
3
3
|
import { CONTROL } from '../../../utils/constants';
|
|
4
|
-
import {
|
|
4
|
+
import { SDK_DEFINITIONS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_DEFINITIONS_CACHE_LOADED, FLAGS_UPDATE, SEGMENTS_UPDATE } from '../../../readiness/constants';
|
|
5
5
|
import { SYNC_OFFLINE_DATA, ERROR_SYNC_OFFLINE_LOADING } from '../../../logger/constants';
|
|
6
6
|
/**
|
|
7
7
|
* Offline equivalent of `splitChangesUpdaterFactory`
|
|
8
8
|
*/
|
|
9
9
|
export function fromObjectUpdaterFactory(splitsParser, storage, readiness, settings) {
|
|
10
|
-
var log = settings.log,
|
|
10
|
+
var log = settings.log, definitions = storage.definitions;
|
|
11
11
|
var startingUp = true;
|
|
12
12
|
return function objectUpdater() {
|
|
13
13
|
var splits = [];
|
|
@@ -36,16 +36,16 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
return Promise.all([
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
definitions.clear(),
|
|
40
|
+
definitions.update(splits, [], Date.now())
|
|
41
41
|
]).then(function () {
|
|
42
|
-
readiness.
|
|
42
|
+
readiness.definitions.emit(SDK_DEFINITIONS_ARRIVED, { type: FLAGS_UPDATE, names: [] });
|
|
43
43
|
if (startingUp) {
|
|
44
44
|
startingUp = false;
|
|
45
45
|
Promise.resolve(storage.validateCache ? storage.validateCache() : { initialCacheLoad: true /* Fallback: assume initial load when validateCache doesn't exist */ }).then(function (cacheMetadata) {
|
|
46
46
|
// Emits SDK_READY_FROM_CACHE
|
|
47
47
|
if (!cacheMetadata.initialCacheLoad) {
|
|
48
|
-
readiness.
|
|
48
|
+
readiness.definitions.emit(SDK_DEFINITIONS_CACHE_LOADED, cacheMetadata);
|
|
49
49
|
}
|
|
50
50
|
// Emits SDK_READY
|
|
51
51
|
readiness.segments.emit(SDK_SEGMENTS_ARRIVED, { type: SEGMENTS_UPDATE, names: [] });
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import { FLAG_SPEC_VERSION } from '../../../utils/constants';
|
|
2
2
|
import { base } from '../../../utils/settingsValidation';
|
|
3
|
-
import {
|
|
3
|
+
import { LOG_PREFIX_SYNC } from '../../../logger/constants';
|
|
4
4
|
import { checkIfServerSide } from '../../../utils/key';
|
|
5
5
|
var PROXY_CHECK_INTERVAL_MILLIS_CS = 60 * 60 * 1000; // 1 hour in Client Side
|
|
6
6
|
var PROXY_CHECK_INTERVAL_MILLIS_SS = 24 * PROXY_CHECK_INTERVAL_MILLIS_CS; // 24 hours in Server Side
|
|
7
7
|
function sdkEndpointOverridden(settings) {
|
|
8
8
|
return settings.urls.sdk !== base.urls.sdk;
|
|
9
9
|
}
|
|
10
|
+
function isSplitChangesLegacyResponse(data) {
|
|
11
|
+
return data.splits != null;
|
|
12
|
+
}
|
|
13
|
+
function partitionByStatus(items, till, since) {
|
|
14
|
+
var updated = [], removed = [];
|
|
15
|
+
items.forEach(function (item) { return item.status === 'ARCHIVED' ? removed.push(item.name) : updated.push(item); });
|
|
16
|
+
return { updated: updated, removed: removed, till: till, since: since };
|
|
17
|
+
}
|
|
10
18
|
/**
|
|
11
19
|
* Factory of SplitChanges fetcher.
|
|
12
20
|
* SplitChanges fetcher is a wrapper around `splitChanges` API service that parses the response and handle errors.
|
|
13
21
|
*/
|
|
14
22
|
// @TODO breaking: drop support for Split Proxy below v5.10.0 and simplify the implementation
|
|
15
|
-
export function splitChangesFetcherFactory(
|
|
23
|
+
export function splitChangesFetcherFactory(params) {
|
|
24
|
+
var fetchSplitChanges = params.splitApi.fetchSplitChanges, settings = params.settings, storage = params.storage;
|
|
16
25
|
var log = settings.log;
|
|
17
26
|
var PROXY_CHECK_INTERVAL_MILLIS = checkIfServerSide(settings) ? PROXY_CHECK_INTERVAL_MILLIS_SS : PROXY_CHECK_INTERVAL_MILLIS_CS;
|
|
18
27
|
var lastProxyCheckTimestamp;
|
|
19
|
-
|
|
28
|
+
function splitChangesFetcher(since, noCache, till, rbSince,
|
|
20
29
|
// Optional decorator for `fetchSplitChanges` promise, such as timeout or time tracker
|
|
21
30
|
decorator) {
|
|
22
31
|
// Recheck proxy
|
|
@@ -27,7 +36,7 @@ export function splitChangesFetcherFactory(fetchSplitChanges, settings, storage)
|
|
|
27
36
|
.catch(function (err) {
|
|
28
37
|
// Handle proxy error with spec 1.3
|
|
29
38
|
if ((!err.statusCode || err.statusCode === 400) && sdkEndpointOverridden(settings) && settings.sync.flagSpecVersion === FLAG_SPEC_VERSION) {
|
|
30
|
-
log.error(
|
|
39
|
+
log.error(LOG_PREFIX_SYNC + 'Proxy error detected. Retrying with spec 1.2. If you are using Split Proxy, please upgrade to latest version');
|
|
31
40
|
lastProxyCheckTimestamp = Date.now();
|
|
32
41
|
settings.sync.flagSpecVersion = '1.2'; // fallback to 1.2 spec
|
|
33
42
|
return fetchSplitChanges(since, noCache, till); // retry request without rbSince
|
|
@@ -40,26 +49,26 @@ export function splitChangesFetcherFactory(fetchSplitChanges, settings, storage)
|
|
|
40
49
|
.then(function (resp) { return resp.json(); })
|
|
41
50
|
.then(function (data) {
|
|
42
51
|
// Using flag spec version 1.2 or below
|
|
43
|
-
if (data
|
|
44
|
-
return {
|
|
45
|
-
ff: {
|
|
46
|
-
d: data.splits,
|
|
47
|
-
s: data.since,
|
|
48
|
-
t: data.till
|
|
49
|
-
}
|
|
50
|
-
};
|
|
52
|
+
if (isSplitChangesLegacyResponse(data)) {
|
|
53
|
+
return { d: partitionByStatus(data.splits || [], data.till, data.since) };
|
|
51
54
|
}
|
|
52
55
|
// Proxy recovery
|
|
53
56
|
if (lastProxyCheckTimestamp) {
|
|
54
|
-
log.info(
|
|
57
|
+
log.info(LOG_PREFIX_SYNC + 'Proxy error recovered');
|
|
55
58
|
lastProxyCheckTimestamp = undefined;
|
|
56
59
|
return splitChangesFetcher(-1, undefined, undefined, -1)
|
|
57
60
|
.then(function (splitChangesResponse) {
|
|
58
|
-
return Promise.all([storage.
|
|
61
|
+
return Promise.all([storage.definitions.clear(), storage.rbSegments.clear()])
|
|
59
62
|
.then(function () { return splitChangesResponse; });
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
|
-
|
|
65
|
+
var ff = data.ff, rbs = data.rbs;
|
|
66
|
+
return {
|
|
67
|
+
d: (ff === null || ff === void 0 ? void 0 : ff.d) ? partitionByStatus(ff.d, ff.t, ff.s) : undefined,
|
|
68
|
+
rbs: (rbs === null || rbs === void 0 ? void 0 : rbs.d) ? partitionByStatus(rbs.d, rbs.t, rbs.s) : undefined,
|
|
69
|
+
};
|
|
63
70
|
});
|
|
64
|
-
}
|
|
71
|
+
}
|
|
72
|
+
splitChangesFetcher.type = 'feature flags';
|
|
73
|
+
return splitChangesFetcher;
|
|
65
74
|
}
|