@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
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import {
|
|
3
|
-
function
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { SDK_DEFINITIONS_ARRIVED, SDK_DEFINITIONS_CACHE_LOADED, SDK_SEGMENTS_ARRIVED, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE, SDK_READY } from './constants';
|
|
3
|
+
function definitionsEventEmitterFactory(EventEmitter) {
|
|
4
|
+
var definitionsEventEmitter = objectAssign(new EventEmitter(), {
|
|
5
|
+
definitionsArrived: false,
|
|
6
|
+
definitionsCacheLoaded: false,
|
|
7
7
|
hasInit: false,
|
|
8
8
|
initCallbacks: []
|
|
9
9
|
});
|
|
10
10
|
// `isSplitKill` condition avoids an edge-case of wrongly emitting SDK_READY if:
|
|
11
11
|
// - `/memberships` fetch and SPLIT_KILL occurs before `/splitChanges` fetch, and
|
|
12
12
|
// - storage has cached splits (for which case `splitsStorage.killLocally` can return true)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return
|
|
13
|
+
definitionsEventEmitter.on(SDK_DEFINITIONS_ARRIVED, function (metadata, isSplitKill) { if (!isSplitKill)
|
|
14
|
+
definitionsEventEmitter.definitionsArrived = true; });
|
|
15
|
+
definitionsEventEmitter.once(SDK_DEFINITIONS_CACHE_LOADED, function () { definitionsEventEmitter.definitionsCacheLoaded = true; });
|
|
16
|
+
return definitionsEventEmitter;
|
|
17
17
|
}
|
|
18
18
|
function segmentsEventEmitterFactory(EventEmitter) {
|
|
19
19
|
var segmentsEventEmitter = objectAssign(new EventEmitter(), {
|
|
@@ -25,8 +25,8 @@ function segmentsEventEmitterFactory(EventEmitter) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Factory of readiness manager, which handles the ready / update event propagation.
|
|
27
27
|
*/
|
|
28
|
-
export function readinessManagerFactory(EventEmitter, settings,
|
|
29
|
-
if (
|
|
28
|
+
export function readinessManagerFactory(EventEmitter, settings, definitions, isShared) {
|
|
29
|
+
if (definitions === void 0) { definitions = definitionsEventEmitterFactory(EventEmitter); }
|
|
30
30
|
var readyTimeout = settings.startup.readyTimeout;
|
|
31
31
|
var segments = segmentsEventEmitterFactory(EventEmitter);
|
|
32
32
|
var gate = new EventEmitter();
|
|
@@ -41,10 +41,10 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
41
41
|
};
|
|
42
42
|
// emit SDK_READY_FROM_CACHE
|
|
43
43
|
var isReadyFromCache = false;
|
|
44
|
-
if (
|
|
44
|
+
if (definitions.definitionsCacheLoaded)
|
|
45
45
|
isReadyFromCache = true; // ready from cache, but doesn't emit SDK_READY_FROM_CACHE
|
|
46
46
|
else
|
|
47
|
-
|
|
47
|
+
definitions.once(SDK_DEFINITIONS_CACHE_LOADED, checkIsReadyFromCache);
|
|
48
48
|
// emit SDK_READY_TIMED_OUT
|
|
49
49
|
var hasTimedout = false;
|
|
50
50
|
function timeout() {
|
|
@@ -56,7 +56,7 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
56
56
|
}
|
|
57
57
|
// emit SDK_READY and SDK_UPDATE
|
|
58
58
|
var isReady = false;
|
|
59
|
-
|
|
59
|
+
definitions.on(SDK_DEFINITIONS_ARRIVED, checkIsReadyOrUpdate);
|
|
60
60
|
segments.on(SDK_SEGMENTS_ARRIVED, checkIsReadyOrUpdate);
|
|
61
61
|
var isDestroyed = false;
|
|
62
62
|
var readyTimeoutId;
|
|
@@ -65,8 +65,8 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
65
65
|
if (readyTimeout > 0 && !isReady)
|
|
66
66
|
readyTimeoutId = setTimeout(timeout, readyTimeout);
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
68
|
+
definitions.initCallbacks.push(__init);
|
|
69
|
+
if (definitions.hasInit)
|
|
70
70
|
__init();
|
|
71
71
|
function checkIsReadyFromCache(cacheMetadata) {
|
|
72
72
|
metadataReady = cacheMetadata;
|
|
@@ -97,7 +97,7 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
|
-
if (
|
|
100
|
+
if (definitions.definitionsArrived && segments.segmentsArrived) {
|
|
101
101
|
clearTimeout(readyTimeoutId);
|
|
102
102
|
isReady = true;
|
|
103
103
|
try {
|
|
@@ -120,11 +120,11 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
return {
|
|
123
|
-
|
|
123
|
+
definitions: definitions,
|
|
124
124
|
segments: segments,
|
|
125
125
|
gate: gate,
|
|
126
126
|
shared: function () {
|
|
127
|
-
return readinessManagerFactory(EventEmitter, settings,
|
|
127
|
+
return readinessManagerFactory(EventEmitter, settings, definitions, true);
|
|
128
128
|
},
|
|
129
129
|
// @TODO review/remove next methods when non-recoverable errors are reworked
|
|
130
130
|
// Called on consumer mode, when storage fails to connect
|
|
@@ -133,17 +133,17 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
|
|
|
133
133
|
// tracking and evaluations, while keeping event listeners to emit SDK_READY_TIMED_OUT event
|
|
134
134
|
setDestroyed: function () { isDestroyed = true; },
|
|
135
135
|
init: function () {
|
|
136
|
-
if (
|
|
136
|
+
if (definitions.hasInit)
|
|
137
137
|
return;
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
definitions.hasInit = true;
|
|
139
|
+
definitions.initCallbacks.forEach(function (cb) { return cb(); });
|
|
140
140
|
},
|
|
141
141
|
destroy: function () {
|
|
142
142
|
isDestroyed = true;
|
|
143
143
|
syncLastUpdate();
|
|
144
144
|
clearTimeout(readyTimeoutId);
|
|
145
145
|
if (!isShared)
|
|
146
|
-
|
|
146
|
+
definitions.hasInit = false;
|
|
147
147
|
},
|
|
148
148
|
isReady: function () { return isReady; },
|
|
149
149
|
isReadyFromCache: function () { return isReadyFromCache; },
|
|
@@ -2,9 +2,8 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { promiseWrapper } from '../utils/promise/wrapper';
|
|
3
3
|
import { readinessManagerFactory } from './readinessManager';
|
|
4
4
|
import { SDK_READY, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE } from './constants';
|
|
5
|
-
import { ERROR_CLIENT_LISTENER, CLIENT_READY_FROM_CACHE, CLIENT_READY
|
|
5
|
+
import { ERROR_CLIENT_LISTENER, CLIENT_READY_FROM_CACHE, CLIENT_READY } from '../logger/constants';
|
|
6
6
|
var NEW_LISTENER_EVENT = 'newListener';
|
|
7
|
-
var REMOVE_LISTENER_EVENT = 'removeListener';
|
|
8
7
|
var TIMEOUT_ERROR = new Error(SDK_READY_TIMED_OUT);
|
|
9
8
|
/**
|
|
10
9
|
* SdkReadinessManager factory, which provides the public status API of SDK clients and manager: ready promise, readiness event emitter and constants (SDK_READY, etc).
|
|
@@ -16,21 +15,11 @@ var TIMEOUT_ERROR = new Error(SDK_READY_TIMED_OUT);
|
|
|
16
15
|
export function sdkReadinessManagerFactory(EventEmitter, settings, readinessManager) {
|
|
17
16
|
if (readinessManager === void 0) { readinessManager = readinessManagerFactory(EventEmitter, settings); }
|
|
18
17
|
var log = settings.log;
|
|
19
|
-
/** Ready callback warning */
|
|
20
|
-
var internalReadyCbCount = 0;
|
|
21
|
-
var readyCbCount = 0;
|
|
22
|
-
readinessManager.gate.on(REMOVE_LISTENER_EVENT, function (event) {
|
|
23
|
-
if (event === SDK_READY)
|
|
24
|
-
readyCbCount--;
|
|
25
|
-
});
|
|
26
18
|
readinessManager.gate.on(NEW_LISTENER_EVENT, function (event) {
|
|
27
19
|
if (event === SDK_READY || event === SDK_READY_TIMED_OUT) {
|
|
28
20
|
if (readinessManager.isReady()) {
|
|
29
21
|
log.error(ERROR_CLIENT_LISTENER, [event === SDK_READY ? 'SDK_READY' : 'SDK_READY_TIMED_OUT']);
|
|
30
22
|
}
|
|
31
|
-
else if (event === SDK_READY) {
|
|
32
|
-
readyCbCount++;
|
|
33
|
-
}
|
|
34
23
|
}
|
|
35
24
|
else if (event === SDK_READY_FROM_CACHE && readinessManager.isReadyFromCache()) {
|
|
36
25
|
log.error(ERROR_CLIENT_LISTENER, ['SDK_READY_FROM_CACHE']);
|
|
@@ -49,8 +38,6 @@ export function sdkReadinessManagerFactory(EventEmitter, settings, readinessMana
|
|
|
49
38
|
var promise = promiseWrapper(new Promise(function (resolve, reject) {
|
|
50
39
|
readinessManager.gate.once(SDK_READY, function () {
|
|
51
40
|
log.info(CLIENT_READY);
|
|
52
|
-
if (readyCbCount === internalReadyCbCount && !promise.hasOnFulfilled())
|
|
53
|
-
log.warn(CLIENT_NO_LISTENER);
|
|
54
41
|
resolve();
|
|
55
42
|
});
|
|
56
43
|
readinessManager.gate.once(SDK_READY_TIMED_OUT, function (message) {
|
|
@@ -75,9 +62,6 @@ export function sdkReadinessManagerFactory(EventEmitter, settings, readinessMana
|
|
|
75
62
|
shared: function () {
|
|
76
63
|
return sdkReadinessManagerFactory(EventEmitter, settings, readinessManager.shared());
|
|
77
64
|
},
|
|
78
|
-
incInternalReadyCbCount: function () {
|
|
79
|
-
internalReadyCbCount++;
|
|
80
|
-
},
|
|
81
65
|
sdkStatus: objectAssign(
|
|
82
66
|
// Expose Event Emitter functionality
|
|
83
67
|
Object.create(readinessManager.gate), {
|
package/esm/sdkClient/client.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { evaluateFeature, evaluateFeatures, evaluateFeaturesByFlagSets } from '../evaluator';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { getMatching, getBucketing } from '../utils/key';
|
|
4
|
-
import {
|
|
5
|
-
import { validateTrafficTypeExistence } from '../utils/inputValidation/trafficTypeExistence';
|
|
4
|
+
import { validateDefinitionExistence } from '../utils/inputValidation/definitionExistence';
|
|
6
5
|
import { SDK_NOT_READY } from '../utils/labels';
|
|
7
|
-
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG,
|
|
8
|
-
import {
|
|
6
|
+
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENT_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS } from '../utils/constants';
|
|
7
|
+
import { IMPRESSION_QUEUEING } from '../logger/constants';
|
|
9
8
|
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
9
|
+
import { trackMethodFactory } from './trackMethod';
|
|
10
10
|
var treatmentNotReady = { treatment: CONTROL, label: SDK_NOT_READY };
|
|
11
11
|
function treatmentsNotReady(featureFlagNames) {
|
|
12
12
|
var evaluations = {};
|
|
@@ -15,7 +15,7 @@ function treatmentsNotReady(featureFlagNames) {
|
|
|
15
15
|
});
|
|
16
16
|
return evaluations;
|
|
17
17
|
}
|
|
18
|
-
function stringify(options) {
|
|
18
|
+
export function stringify(options) {
|
|
19
19
|
if (options && options.properties) {
|
|
20
20
|
try {
|
|
21
21
|
return JSON.stringify(options.properties);
|
|
@@ -27,7 +27,7 @@ function stringify(options) {
|
|
|
27
27
|
* Creator of base client with getTreatments and track methods.
|
|
28
28
|
*/
|
|
29
29
|
export function clientFactory(params) {
|
|
30
|
-
var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker,
|
|
30
|
+
var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, telemetryTracker = params.telemetryTracker, fallbackCalculator = params.fallbackCalculator;
|
|
31
31
|
var log = settings.log, mode = settings.mode;
|
|
32
32
|
var isAsync = isConsumerMode(mode);
|
|
33
33
|
function getTreatment(key, featureFlagName, attributes, options, withConfig, methodName) {
|
|
@@ -115,14 +115,13 @@ export function clientFactory(params) {
|
|
|
115
115
|
var changeNumber = evaluation.changeNumber, impressionsDisabled = evaluation.impressionsDisabled;
|
|
116
116
|
var treatment = evaluation.treatment, label = evaluation.label, _a = evaluation.config, config = _a === void 0 ? null : _a;
|
|
117
117
|
if (treatment === CONTROL) {
|
|
118
|
-
var fallbackTreatment =
|
|
118
|
+
var fallbackTreatment = fallbackCalculator(featureFlagName, label);
|
|
119
119
|
treatment = fallbackTreatment.treatment;
|
|
120
120
|
label = fallbackTreatment.label;
|
|
121
121
|
config = fallbackTreatment.config;
|
|
122
122
|
}
|
|
123
|
-
log
|
|
124
|
-
|
|
125
|
-
log.info(IMPRESSION_QUEUEING);
|
|
123
|
+
if (validateDefinitionExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
|
|
124
|
+
log.info(IMPRESSION_QUEUEING, ['Feature flag', featureFlagName, matchingKey, treatment, label]);
|
|
126
125
|
queue.push({
|
|
127
126
|
imp: {
|
|
128
127
|
feature: featureFlagName,
|
|
@@ -145,33 +144,7 @@ export function clientFactory(params) {
|
|
|
145
144
|
}
|
|
146
145
|
return treatment;
|
|
147
146
|
}
|
|
148
|
-
|
|
149
|
-
if (size === void 0) { size = 1024; }
|
|
150
|
-
var stopTelemetryTracker = telemetryTracker.trackEval(TRACK);
|
|
151
|
-
var matchingKey = getMatching(key);
|
|
152
|
-
var timestamp = Date.now();
|
|
153
|
-
var eventData = {
|
|
154
|
-
eventTypeId: eventTypeId,
|
|
155
|
-
trafficTypeName: trafficTypeName,
|
|
156
|
-
value: value,
|
|
157
|
-
timestamp: timestamp,
|
|
158
|
-
key: matchingKey,
|
|
159
|
-
properties: properties
|
|
160
|
-
};
|
|
161
|
-
// This may be async but we only warn, we don't actually care if it is valid or not in terms of queueing the event.
|
|
162
|
-
validateTrafficTypeExistence(log, readinessManager, storage.splits, mode, trafficTypeName, TRACK_FN_LABEL);
|
|
163
|
-
var result = eventTracker.track(eventData, size);
|
|
164
|
-
if (thenable(result)) {
|
|
165
|
-
return result.then(function (result) {
|
|
166
|
-
stopTelemetryTracker();
|
|
167
|
-
return result;
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
stopTelemetryTracker();
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
147
|
+
var track = trackMethodFactory(params);
|
|
175
148
|
return {
|
|
176
149
|
getTreatment: getTreatment,
|
|
177
150
|
getTreatmentWithConfig: getTreatmentWithConfig,
|
|
@@ -66,7 +66,7 @@ export function clientAttributesDecoration(log, client) {
|
|
|
66
66
|
attribute[attributeName] = attributeValue;
|
|
67
67
|
if (!validateAttributesDeep(log, attribute, 'setAttribute'))
|
|
68
68
|
return false;
|
|
69
|
-
log.debug("stored "
|
|
69
|
+
log.debug("stored ".concat(attributeValue, " for attribute ").concat(attributeName));
|
|
70
70
|
return attributeStorage.setAttribute(attributeName, attributeValue);
|
|
71
71
|
},
|
|
72
72
|
/**
|
|
@@ -76,7 +76,7 @@ export function clientAttributesDecoration(log, client) {
|
|
|
76
76
|
* @returns Attribute with the given name
|
|
77
77
|
*/
|
|
78
78
|
getAttribute: function (attributeName) {
|
|
79
|
-
log.debug("retrieved attribute "
|
|
79
|
+
log.debug("retrieved attribute ".concat(attributeName));
|
|
80
80
|
return attributeStorage.getAttribute(attributeName + '');
|
|
81
81
|
},
|
|
82
82
|
/**
|
|
@@ -105,7 +105,7 @@ export function clientAttributesDecoration(log, client) {
|
|
|
105
105
|
* @returns true if attribute was removed and false otherways
|
|
106
106
|
*/
|
|
107
107
|
removeAttribute: function (attributeName) {
|
|
108
|
-
log.debug("removed attribute "
|
|
108
|
+
log.debug("removed attribute ".concat(attributeName));
|
|
109
109
|
return attributeStorage.removeAttribute(attributeName + '');
|
|
110
110
|
},
|
|
111
111
|
/**
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { validateAttributes,
|
|
1
|
+
import { validateAttributes, validateKey, validateDefinition, validateDefinitions, validateIfNotDestroyed, validateIfReadyFromCache, validateEvaluationOptions } from '../utils/inputValidation';
|
|
2
2
|
import { startsWith } from '../utils/lang';
|
|
3
|
-
import { GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG
|
|
3
|
+
import { GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG } from '../utils/constants';
|
|
4
4
|
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
5
5
|
import { validateFlagSets } from '../utils/settingsValidation/splitFilters';
|
|
6
6
|
/**
|
|
7
7
|
* Decorator that validates the input before actually executing the client methods.
|
|
8
8
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
9
9
|
*/
|
|
10
|
-
export function clientInputValidationDecorator(settings, client, readinessManager,
|
|
10
|
+
export function clientInputValidationDecorator(settings, client, readinessManager, fallbackCalculator) {
|
|
11
11
|
var log = settings.log, mode = settings.mode;
|
|
12
12
|
var isAsync = isConsumerMode(mode);
|
|
13
13
|
/**
|
|
@@ -18,12 +18,12 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
18
18
|
var nameOrNames = methodName.indexOf('ByFlagSet') > -1 ?
|
|
19
19
|
validateFlagSets(log, methodName, maybeNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet) :
|
|
20
20
|
startsWith(methodName, GET_TREATMENTS) ?
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
validateDefinitions(log, maybeNameOrNames, methodName) :
|
|
22
|
+
validateDefinition(log, maybeNameOrNames, methodName);
|
|
23
23
|
var attributes = validateAttributes(log, maybeAttributes, methodName);
|
|
24
24
|
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
|
|
25
25
|
var options = validateEvaluationOptions(log, maybeOptions, methodName);
|
|
26
|
-
validateIfReadyFromCache(log, readinessManager, methodName
|
|
26
|
+
validateIfReadyFromCache(log, readinessManager, methodName);
|
|
27
27
|
var valid = isNotDestroyed && key && nameOrNames && attributes !== false;
|
|
28
28
|
return {
|
|
29
29
|
valid: valid,
|
|
@@ -34,111 +34,68 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
function evaluateFallBackTreatment(featureFlagName, withConfig) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
37
|
+
if (Array.isArray(featureFlagName)) {
|
|
38
|
+
var res_1 = {};
|
|
39
|
+
featureFlagName.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, withConfig); });
|
|
40
|
+
return res_1;
|
|
41
|
+
}
|
|
42
|
+
var _a = fallbackCalculator(featureFlagName), treatment = _a.treatment, config = _a.config;
|
|
43
|
+
return withConfig ?
|
|
44
|
+
{
|
|
40
45
|
treatment: treatment,
|
|
41
46
|
config: config
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return treatment;
|
|
47
|
+
} : treatment;
|
|
45
48
|
}
|
|
46
49
|
function wrapResult(value) {
|
|
47
50
|
return isAsync ? Promise.resolve(value) : value;
|
|
48
51
|
}
|
|
49
52
|
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
50
53
|
var params = validateEvaluationParams(GET_TREATMENT, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
else {
|
|
55
|
-
var result = evaluateFallBackTreatment(params.nameOrNames, false);
|
|
56
|
-
return wrapResult(result);
|
|
57
|
-
}
|
|
54
|
+
return params.valid ?
|
|
55
|
+
client.getTreatment(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
56
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames, false));
|
|
58
57
|
}
|
|
59
58
|
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
60
59
|
var params = validateEvaluationParams(GET_TREATMENT_WITH_CONFIG, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
else {
|
|
65
|
-
var result = evaluateFallBackTreatment(params.nameOrNames, true);
|
|
66
|
-
return wrapResult(result);
|
|
67
|
-
}
|
|
60
|
+
return params.valid ?
|
|
61
|
+
client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
62
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames, true));
|
|
68
63
|
}
|
|
69
64
|
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
70
65
|
var params = validateEvaluationParams(GET_TREATMENTS, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else {
|
|
75
|
-
var res_1 = {};
|
|
76
|
-
if (params.nameOrNames)
|
|
77
|
-
params.nameOrNames.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, false); });
|
|
78
|
-
return wrapResult(res_1);
|
|
79
|
-
}
|
|
66
|
+
return params.valid ?
|
|
67
|
+
client.getTreatments(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
68
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], false));
|
|
80
69
|
}
|
|
81
70
|
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
82
71
|
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
else {
|
|
87
|
-
var res_2 = {};
|
|
88
|
-
if (params.nameOrNames)
|
|
89
|
-
params.nameOrNames.forEach(function (split) { return res_2[split] = evaluateFallBackTreatment(split, true); });
|
|
90
|
-
return wrapResult(res_2);
|
|
91
|
-
}
|
|
72
|
+
return params.valid ?
|
|
73
|
+
client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
74
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], true));
|
|
92
75
|
}
|
|
93
76
|
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
94
77
|
var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
else {
|
|
99
|
-
return wrapResult({});
|
|
100
|
-
}
|
|
78
|
+
return params.valid ?
|
|
79
|
+
client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
80
|
+
wrapResult({});
|
|
101
81
|
}
|
|
102
82
|
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
103
83
|
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
else {
|
|
108
|
-
return wrapResult({});
|
|
109
|
-
}
|
|
84
|
+
return params.valid ?
|
|
85
|
+
client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
86
|
+
wrapResult({});
|
|
110
87
|
}
|
|
111
88
|
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
112
89
|
var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
else {
|
|
117
|
-
return wrapResult({});
|
|
118
|
-
}
|
|
90
|
+
return params.valid ?
|
|
91
|
+
client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
|
|
92
|
+
wrapResult({});
|
|
119
93
|
}
|
|
120
94
|
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
121
95
|
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
else {
|
|
126
|
-
return wrapResult({});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
130
|
-
var key = validateKey(log, maybeKey, TRACK_FN_LABEL);
|
|
131
|
-
var tt = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
|
|
132
|
-
var event = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
|
|
133
|
-
var eventValue = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
|
|
134
|
-
var _a = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
135
|
-
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
|
|
136
|
-
if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
|
|
137
|
-
return client.track(key, tt, event, eventValue, properties, size);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return isAsync ? Promise.resolve(false) : false;
|
|
141
|
-
}
|
|
96
|
+
return params.valid ?
|
|
97
|
+
client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
|
|
98
|
+
wrapResult({});
|
|
142
99
|
}
|
|
143
100
|
return {
|
|
144
101
|
getTreatment: getTreatment,
|
|
@@ -149,6 +106,6 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
149
106
|
getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
|
|
150
107
|
getTreatmentsByFlagSet: getTreatmentsByFlagSet,
|
|
151
108
|
getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
|
|
152
|
-
track: track
|
|
109
|
+
track: client.track,
|
|
153
110
|
};
|
|
154
111
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export function buildInstanceId(key, trafficType) {
|
|
2
|
-
return (key.matchingKey ? key.matchingKey : key
|
|
2
|
+
return "".concat(key.matchingKey ? key.matchingKey : key, "-").concat(key.bucketingKey ? key.bucketingKey : key, "-").concat(trafficType ? trafficType : '');
|
|
3
3
|
}
|
|
@@ -1,60 +1,15 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import { releaseApiKey } from '../utils/inputValidation/apiKey';
|
|
3
2
|
import { clientFactory } from './client';
|
|
4
3
|
import { clientInputValidationDecorator } from './clientInputValidation';
|
|
5
|
-
|
|
4
|
+
import { sdkLifecycleFactory } from './sdkLifecycle';
|
|
6
5
|
/**
|
|
7
|
-
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
6
|
+
* Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
|
|
8
7
|
*/
|
|
9
8
|
export function sdkClientFactory(params, isSharedClient) {
|
|
10
|
-
var sdkReadinessManager = params.sdkReadinessManager,
|
|
11
|
-
var lastActionTime = 0;
|
|
12
|
-
function __cooldown(func, time) {
|
|
13
|
-
var now = Date.now();
|
|
14
|
-
//get the actual time elapsed in ms
|
|
15
|
-
var timeElapsed = now - lastActionTime;
|
|
16
|
-
//check if the time elapsed is less than desired cooldown
|
|
17
|
-
if (timeElapsed < time) {
|
|
18
|
-
//if yes, return message with remaining time in seconds
|
|
19
|
-
settings.log.warn("Flush cooldown, remaining time " + (time - timeElapsed) / 1000 + " seconds");
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
//Do the requested action and re-assign the lastActionTime
|
|
24
|
-
lastActionTime = now;
|
|
25
|
-
return func();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function __flush() {
|
|
29
|
-
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
30
|
-
}
|
|
9
|
+
var sdkReadinessManager = params.sdkReadinessManager, settings = params.settings;
|
|
31
10
|
return objectAssign(
|
|
32
11
|
// Proto-linkage of the readiness Event Emitter
|
|
33
12
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
34
13
|
// Client API (getTreatment* & track methods)
|
|
35
|
-
clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager, params.
|
|
36
|
-
// Sdk destroy
|
|
37
|
-
{
|
|
38
|
-
flush: function () {
|
|
39
|
-
// @TODO define cooldown time
|
|
40
|
-
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
41
|
-
},
|
|
42
|
-
destroy: function () {
|
|
43
|
-
// Mark the SDK as destroyed immediately
|
|
44
|
-
sdkReadinessManager.readinessManager.destroy();
|
|
45
|
-
// For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
|
|
46
|
-
if (!isSharedClient) {
|
|
47
|
-
releaseApiKey(settings.core.authorizationKey);
|
|
48
|
-
telemetryTracker.sessionLength();
|
|
49
|
-
signalListener && signalListener.stop();
|
|
50
|
-
uniqueKeysTracker.stop();
|
|
51
|
-
}
|
|
52
|
-
// Stop background jobs
|
|
53
|
-
syncManager && syncManager.stop();
|
|
54
|
-
return __flush().then(function () {
|
|
55
|
-
// Cleanup storage
|
|
56
|
-
return storage.destroy();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
});
|
|
14
|
+
clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager, params.fallbackCalculator), sdkLifecycleFactory(params, isSharedClient));
|
|
60
15
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { releaseApiKey, validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
|
|
2
|
+
var COOLDOWN_TIME_IN_MILLIS = 1000;
|
|
3
|
+
/**
|
|
4
|
+
* Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
|
|
5
|
+
*/
|
|
6
|
+
export function sdkLifecycleFactory(params, isSharedClient) {
|
|
7
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, settings = params.settings, telemetryTracker = params.telemetryTracker, impressionsTracker = params.impressionsTracker, platform = params.platform, splitApi = params.splitApi;
|
|
8
|
+
var hasInit = false;
|
|
9
|
+
var lastActionTime = 0;
|
|
10
|
+
var signalListener = platform.SignalListener && new platform.SignalListener(params);
|
|
11
|
+
function __cooldown(func, time) {
|
|
12
|
+
var now = Date.now();
|
|
13
|
+
//get the actual time elapsed in ms
|
|
14
|
+
var timeElapsed = now - lastActionTime;
|
|
15
|
+
//check if the time elapsed is less than desired cooldown
|
|
16
|
+
if (timeElapsed < time) {
|
|
17
|
+
//if yes, return message with remaining time in seconds
|
|
18
|
+
settings.log.warn("Flush cooldown, remaining time ".concat((time - timeElapsed) / 1000, " seconds"));
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
//Do the requested action and re-assign the lastActionTime
|
|
23
|
+
lastActionTime = now;
|
|
24
|
+
return func();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function __flush() {
|
|
28
|
+
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
init: function () {
|
|
32
|
+
if (hasInit)
|
|
33
|
+
return;
|
|
34
|
+
hasInit = true;
|
|
35
|
+
if (!isSharedClient) {
|
|
36
|
+
validateAndTrackApiKey(settings.log, settings.core.authorizationKey);
|
|
37
|
+
sdkReadinessManager.readinessManager.init();
|
|
38
|
+
impressionsTracker.start();
|
|
39
|
+
syncManager && syncManager.start();
|
|
40
|
+
signalListener && signalListener.start();
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
flush: function () {
|
|
44
|
+
// @TODO define cooldown time
|
|
45
|
+
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
46
|
+
},
|
|
47
|
+
destroy: function () {
|
|
48
|
+
hasInit = false;
|
|
49
|
+
// Mark the SDK as destroyed immediately
|
|
50
|
+
sdkReadinessManager.readinessManager.destroy();
|
|
51
|
+
// For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
|
|
52
|
+
if (!isSharedClient) {
|
|
53
|
+
releaseApiKey(settings.core.authorizationKey);
|
|
54
|
+
telemetryTracker.sessionLength();
|
|
55
|
+
signalListener && signalListener.stop();
|
|
56
|
+
impressionsTracker.stop();
|
|
57
|
+
}
|
|
58
|
+
// Stop background jobs
|
|
59
|
+
syncManager && syncManager.stop();
|
|
60
|
+
splitApi && splitApi.stop();
|
|
61
|
+
return __flush().then(function () {
|
|
62
|
+
// Cleanup storage
|
|
63
|
+
return storage.destroy();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|