@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
|
@@ -27,25 +27,25 @@ function decompress(data, compression) {
|
|
|
27
27
|
return algorithms.gunzipSync(binData);
|
|
28
28
|
if (compression === ZLIB)
|
|
29
29
|
return algorithms.unzlibSync(binData);
|
|
30
|
-
throw new Error("Invalid compression algorithm #"
|
|
30
|
+
throw new Error("Invalid compression algorithm #".concat(compression));
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Decode, decompress and parse the provided 'data' into
|
|
33
|
+
* Decode, decompress and parse the provided 'data' into an object of type T
|
|
34
34
|
*
|
|
35
35
|
* @param data - base64 encoded string
|
|
36
36
|
* @param compression - 1 GZIP, 2 ZLIB
|
|
37
37
|
* @param avoidPrecisionLoss - true as default, set it as false if dont need to avoid precission loss
|
|
38
|
-
* @returns
|
|
38
|
+
* @returns parsed object
|
|
39
39
|
* @throws if data string cannot be decoded, decompressed or parsed
|
|
40
40
|
*/
|
|
41
|
-
export function
|
|
41
|
+
export function parseCompressedData(data, compression, avoidPrecisionLoss) {
|
|
42
42
|
if (avoidPrecisionLoss === void 0) { avoidPrecisionLoss = true; }
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
// replace numbers to strings, to avoid losing precision
|
|
43
|
+
var binData = decompress(data, compression);
|
|
44
|
+
var str = Uint8ArrayToString(binData);
|
|
45
|
+
// replace numbers to strings, to avoid losing precision (e.g., 64-bit IDs in KeyList)
|
|
46
46
|
if (avoidPrecisionLoss)
|
|
47
|
-
|
|
48
|
-
return JSON.parse(
|
|
47
|
+
str = str.replace(/\d+/g, '"$&"');
|
|
48
|
+
return JSON.parse(str);
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Decode, decompress and parse the provided 'data' into a Bitmap object
|
|
@@ -77,7 +77,7 @@ export function isInBitmap(bitmap, hash64hex) {
|
|
|
77
77
|
*/
|
|
78
78
|
export function parseFFUpdatePayload(compression, data) {
|
|
79
79
|
return compression > 0 ?
|
|
80
|
-
|
|
80
|
+
parseCompressedData(data, compression, false) :
|
|
81
81
|
JSON.parse(decodeFromBase64(data));
|
|
82
82
|
}
|
|
83
83
|
var DEFAULT_MAX_INTERVAL = 60000;
|
|
@@ -3,15 +3,15 @@ import { Backoff } from '../../utils/Backoff';
|
|
|
3
3
|
import { SSEHandlerFactory } from './SSEHandler';
|
|
4
4
|
import { MySegmentsUpdateWorker } from './UpdateWorkers/MySegmentsUpdateWorker';
|
|
5
5
|
import { SegmentsUpdateWorker } from './UpdateWorkers/SegmentsUpdateWorker';
|
|
6
|
-
import {
|
|
6
|
+
import { DefinitionsUpdateWorker } from './UpdateWorkers/DefinitionsUpdateWorker';
|
|
7
7
|
import { authenticateFactory, hashUserKey } from './AuthClient';
|
|
8
8
|
import { forOwn } from '../../utils/lang';
|
|
9
9
|
import { SSEClient } from './SSEClient';
|
|
10
10
|
import { checkIfServerSide, getMatching } from '../../utils/key';
|
|
11
|
-
import { MEMBERSHIPS_MS_UPDATE, MEMBERSHIPS_LS_UPDATE,
|
|
11
|
+
import { MEMBERSHIPS_MS_UPDATE, MEMBERSHIPS_LS_UPDATE, PUSH_NON_RETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, RB_SEGMENT_UPDATE, PUSH_RETRYABLE_ERROR, PUSH_SUBSYSTEM_UP, ControlType } from './constants';
|
|
12
12
|
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT, STREAMING_PARSING_MEMBERSHIPS_UPDATE } from '../../logger/constants';
|
|
13
13
|
import { UpdateStrategy } from './SSEHandler/types';
|
|
14
|
-
import { getDelay, isInBitmap, parseBitmap,
|
|
14
|
+
import { getDelay, isInBitmap, parseBitmap, parseCompressedData } from './parseUtils';
|
|
15
15
|
import { hash64 } from '../../utils/murmur3/murmur3_64';
|
|
16
16
|
import { TOKEN_REFRESH, AUTH_REJECTION } from '../../utils/constants';
|
|
17
17
|
/**
|
|
@@ -42,8 +42,8 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
42
42
|
// init workers
|
|
43
43
|
// MySegmentsUpdateWorker (client-side) are initiated in `add` method
|
|
44
44
|
var segmentsUpdateWorker = userKey ? undefined : SegmentsUpdateWorker(log, pollingManager.segmentsSyncTask, storage.segments);
|
|
45
|
-
// For server-side we pass the segmentsSyncTask, used by
|
|
46
|
-
var
|
|
45
|
+
// For server-side we pass the segmentsSyncTask, used by DefinitionsUpdateWorker to fetch new segments
|
|
46
|
+
var definitionsUpdateWorker = DefinitionsUpdateWorker(log, storage, pollingManager.definitionsSyncTask, readiness.definitions, telemetryTracker, userKey ? undefined : pollingManager.segmentsSyncTask);
|
|
47
47
|
// [Only for client-side] map of hashes to user keys, to dispatch membership update events to the corresponding MySegmentsUpdateWorker
|
|
48
48
|
var userKeyHashes = {};
|
|
49
49
|
// [Only for client-side] map of user keys to their corresponding hash64 and MySegmentsUpdateWorkers.
|
|
@@ -51,10 +51,10 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
51
51
|
var clients = {};
|
|
52
52
|
// [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
|
|
53
53
|
var connectForNewClient = false;
|
|
54
|
-
// flag that indicates if `stop/disconnectPush` was called, either by the SyncManager, when the client is destroyed, or due to a
|
|
54
|
+
// flag that indicates if `stop/disconnectPush` was called, either by the SyncManager, when the client is destroyed, or due to a PUSH_NON_RETRYABLE_ERROR error.
|
|
55
55
|
// It is used to halt the `connectPush` process if it was in progress.
|
|
56
56
|
var disconnected;
|
|
57
|
-
// flag that indicates a
|
|
57
|
+
// flag that indicates a PUSH_NON_RETRYABLE_ERROR, condition with which starting pushManager again is ignored.
|
|
58
58
|
// true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
|
|
59
59
|
var disabled; // `disabled` implies `disconnected === true`
|
|
60
60
|
/** PushManager functions related to initialization */
|
|
@@ -93,11 +93,11 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
93
93
|
authenticate(userKeys).then(function (authData) {
|
|
94
94
|
if (disconnected)
|
|
95
95
|
return;
|
|
96
|
-
// 'pushEnabled: false' is handled as a
|
|
96
|
+
// 'pushEnabled: false' is handled as a PUSH_NON_RETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
|
|
97
97
|
// close the sseClient in case the org has been bloqued while the instance was connected to streaming
|
|
98
98
|
if (!authData.pushEnabled) {
|
|
99
99
|
log.info(STREAMING_DISABLED);
|
|
100
|
-
pushEmitter.emit(
|
|
100
|
+
pushEmitter.emit(PUSH_NON_RETRYABLE_ERROR);
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
// [Only for client-side] don't open SSE connection if a new shared client was added, since it means that a new authentication is taking place
|
|
@@ -112,7 +112,7 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
112
112
|
// Handle 4XX HTTP errors: 401 (invalid SDK Key) or 400 (using incorrect SDK Key, i.e., client-side SDK Key on server-side)
|
|
113
113
|
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
114
114
|
telemetryTracker.streamingEvent(AUTH_REJECTION);
|
|
115
|
-
pushEmitter.emit(
|
|
115
|
+
pushEmitter.emit(PUSH_NON_RETRYABLE_ERROR);
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
// Handle other HTTP and network errors as recoverable errors
|
|
@@ -136,7 +136,7 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
136
136
|
}
|
|
137
137
|
// cancel scheduled fetch retries of Splits, Segments, and MySegments Update Workers
|
|
138
138
|
function stopWorkers() {
|
|
139
|
-
|
|
139
|
+
definitionsUpdateWorker.stop();
|
|
140
140
|
if (userKey)
|
|
141
141
|
forOwn(clients, function (_a) {
|
|
142
142
|
var worker = _a.worker;
|
|
@@ -152,7 +152,7 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
152
152
|
connectPushRetryBackoff.reset();
|
|
153
153
|
});
|
|
154
154
|
/** Fallback to polling without retry due to: STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE and Authentication errors */
|
|
155
|
-
pushEmitter.on(
|
|
155
|
+
pushEmitter.on(PUSH_NON_RETRYABLE_ERROR, function handleNonRetryableError() {
|
|
156
156
|
disabled = true;
|
|
157
157
|
// Note: `stopWorkers` is been called twice, but it is not harmful
|
|
158
158
|
disconnectPush();
|
|
@@ -178,9 +178,9 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
178
178
|
connectPush();
|
|
179
179
|
});
|
|
180
180
|
/** Functions related to synchronization (Queues and Workers in the spec) */
|
|
181
|
-
pushEmitter.on(SPLIT_KILL,
|
|
182
|
-
pushEmitter.on(SPLIT_UPDATE,
|
|
183
|
-
pushEmitter.on(RB_SEGMENT_UPDATE,
|
|
181
|
+
pushEmitter.on(SPLIT_KILL, definitionsUpdateWorker.killDefinition);
|
|
182
|
+
pushEmitter.on(SPLIT_UPDATE, definitionsUpdateWorker.put);
|
|
183
|
+
pushEmitter.on(RB_SEGMENT_UPDATE, definitionsUpdateWorker.put);
|
|
184
184
|
function handleMySegmentsUpdate(parsedData) {
|
|
185
185
|
switch (parsedData.u) {
|
|
186
186
|
case UpdateStrategy.BoundedFetchRequest: {
|
|
@@ -203,7 +203,7 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
203
203
|
case UpdateStrategy.KeyList: {
|
|
204
204
|
var keyList = void 0, added_1, removed_1;
|
|
205
205
|
try {
|
|
206
|
-
keyList =
|
|
206
|
+
keyList = parseCompressedData(parsedData.d, parsedData.c);
|
|
207
207
|
added_1 = new Set(keyList.a);
|
|
208
208
|
removed_1 = new Set(keyList.r);
|
|
209
209
|
}
|
|
@@ -4,14 +4,14 @@ import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
|
4
4
|
/**
|
|
5
5
|
* Converts `impressions` data from cache into request payload.
|
|
6
6
|
*/
|
|
7
|
-
export function fromImpressionsCollector(sendLabels, data) {
|
|
7
|
+
export function fromImpressionsCollector(sendLabels, entityType, data) {
|
|
8
8
|
var groupedByFeature = groupBy(data, 'feature');
|
|
9
9
|
var dto = [];
|
|
10
10
|
forOwn(groupedByFeature, function (value, name) {
|
|
11
11
|
dto.push({
|
|
12
12
|
f: name,
|
|
13
13
|
i: value.map(function (entry) {
|
|
14
|
-
|
|
14
|
+
return {
|
|
15
15
|
k: entry.keyName,
|
|
16
16
|
t: entry.treatment,
|
|
17
17
|
m: entry.time,
|
|
@@ -19,9 +19,9 @@ export function fromImpressionsCollector(sendLabels, data) {
|
|
|
19
19
|
r: sendLabels ? entry.label : undefined,
|
|
20
20
|
b: entry.bucketingKey,
|
|
21
21
|
pt: entry.pt,
|
|
22
|
-
properties: entry.properties
|
|
22
|
+
properties: entry.properties,
|
|
23
|
+
et: entityType, // Definition type
|
|
23
24
|
};
|
|
24
|
-
return keyImpression;
|
|
25
25
|
})
|
|
26
26
|
});
|
|
27
27
|
});
|
|
@@ -31,9 +31,9 @@ export function fromImpressionsCollector(sendLabels, data) {
|
|
|
31
31
|
* Submitter that periodically posts impressions data
|
|
32
32
|
*/
|
|
33
33
|
export function impressionsSubmitterFactory(params) {
|
|
34
|
-
var _a = params.settings, log = _a.log, impressionsRefreshRate = _a.scheduler.impressionsRefreshRate, labelsEnabled = _a.core.labelsEnabled, postTestImpressionsBulk = params.splitApi.postTestImpressionsBulk, impressions = params.storage.impressions;
|
|
34
|
+
var _a = params.settings, log = _a.log, impressionsRefreshRate = _a.scheduler.impressionsRefreshRate, labelsEnabled = _a.core.labelsEnabled, postTestImpressionsBulk = params.splitApi.postTestImpressionsBulk, impressions = params.storage.impressions, entityType = params.entityType;
|
|
35
35
|
// retry impressions only once.
|
|
36
|
-
var syncTask = submitterFactory(log, postTestImpressionsBulk, impressions, impressionsRefreshRate, fromImpressionsCollector.bind(undefined, labelsEnabled), 1);
|
|
36
|
+
var syncTask = submitterFactory(log, postTestImpressionsBulk, impressions, impressionsRefreshRate, fromImpressionsCollector.bind(undefined, labelsEnabled, entityType), 1);
|
|
37
37
|
// register impressions submitter to be executed when impressions cache is full
|
|
38
38
|
impressions.setOnFullQueueCb(function () {
|
|
39
39
|
if (syncTask.isRunning()) {
|
|
@@ -13,7 +13,7 @@ export function submitterFactory(log, postClient, sourceCache, postRate, fromCac
|
|
|
13
13
|
if (sourceCache.isEmpty() && !data)
|
|
14
14
|
return Promise.resolve();
|
|
15
15
|
data = sourceCache.pop(data);
|
|
16
|
-
var dataCountMessage = typeof data.length === 'number' ? data.length
|
|
16
|
+
var dataCountMessage = typeof data.length === 'number' ? "".concat(data.length, " ").concat(dataName) : dataName;
|
|
17
17
|
log[debugLogs ? 'debug' : 'info'](SUBMITTERS_PUSH, [dataCountMessage]);
|
|
18
18
|
var jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
|
|
19
19
|
if (!maxRetries)
|
|
@@ -102,13 +102,12 @@ export function telemetrySubmitterFactory(params) {
|
|
|
102
102
|
var telemetry = params.storage.telemetry, now = params.platform.now;
|
|
103
103
|
if (!telemetry || !now)
|
|
104
104
|
return; // No submitter created if telemetry cache is not defined
|
|
105
|
-
var settings = params.settings, _a = params.settings, log = _a.log, telemetryRefreshRate = _a.scheduler.telemetryRefreshRate, splitApi = params.splitApi, readiness = params.readiness
|
|
105
|
+
var settings = params.settings, _a = params.settings, log = _a.log, telemetryRefreshRate = _a.scheduler.telemetryRefreshRate, splitApi = params.splitApi, readiness = params.readiness;
|
|
106
106
|
var stopTimer = timer(now);
|
|
107
107
|
var submitter = firstPushWindowDecorator(submitterFactory(log, splitApi.postMetricsUsage, telemetry, telemetryRefreshRate, undefined, 0, true), telemetryRefreshRate);
|
|
108
108
|
readiness.gate.once(SDK_READY_FROM_CACHE, function () {
|
|
109
109
|
telemetry.recordTimeUntilReadyFromCache(stopTimer());
|
|
110
110
|
});
|
|
111
|
-
sdkReadinessManager.incInternalReadyCbCount();
|
|
112
111
|
readiness.gate.once(SDK_READY, function () {
|
|
113
112
|
telemetry.recordTimeUntilReady(stopTimer());
|
|
114
113
|
// Post config data when the SDK is ready and if the telemetry submitter was started
|
|
@@ -3,8 +3,9 @@ import { PUSH_SUBSYSTEM_UP, PUSH_SUBSYSTEM_DOWN } from './streaming/constants';
|
|
|
3
3
|
import { SYNC_START_POLLING, SYNC_CONTINUE_POLLING, SYNC_STOP_POLLING } from '../logger/constants';
|
|
4
4
|
import { isConsentGranted } from '../consent';
|
|
5
5
|
import { POLLING, STREAMING, SYNC_MODE_UPDATE } from '../utils/constants';
|
|
6
|
-
import {
|
|
7
|
-
import { usesSegmentsSync } from '../storages/
|
|
6
|
+
import { SDK_DEFINITIONS_CACHE_LOADED } from '../readiness/constants';
|
|
7
|
+
import { usesSegmentsSync } from '../storages/AbstractDefinitionsCacheSync';
|
|
8
|
+
import { splitChangesFetcherFactory } from './polling/fetchers/splitChangesFetcher';
|
|
8
9
|
/**
|
|
9
10
|
* Online SyncManager factory.
|
|
10
11
|
* Can be used for server-side API, and client-side API with or without multiple clients.
|
|
@@ -12,15 +13,17 @@ import { usesSegmentsSync } from '../storages/AbstractSplitsCacheSync';
|
|
|
12
13
|
* @param pollingManagerFactory - allows to specialize the SyncManager for server-side or client-side API by passing
|
|
13
14
|
* `pollingManagerSSFactory` or `pollingManagerCSFactory` respectively.
|
|
14
15
|
* @param pushManagerFactory - optional to build a SyncManager with or without streaming support
|
|
16
|
+
* @param definitionChangesFetcherFactory - optional to replace the default split changes fetcher
|
|
15
17
|
*/
|
|
16
|
-
export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
18
|
+
export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory, definitionChangesFetcherFactory) {
|
|
19
|
+
if (definitionChangesFetcherFactory === void 0) { definitionChangesFetcherFactory = splitChangesFetcherFactory; }
|
|
17
20
|
/**
|
|
18
21
|
* SyncManager factory for modular SDK
|
|
19
22
|
*/
|
|
20
23
|
return function (params) {
|
|
21
24
|
var settings = params.settings, _a = params.settings, log = _a.log, streamingEnabled = _a.streamingEnabled, syncEnabled = _a.sync.enabled, telemetryTracker = params.telemetryTracker, storage = params.storage, readiness = params.readiness;
|
|
22
25
|
/** Polling Manager */
|
|
23
|
-
var pollingManager = pollingManagerFactory && pollingManagerFactory(params);
|
|
26
|
+
var pollingManager = pollingManagerFactory && pollingManagerFactory(params, definitionChangesFetcherFactory(params));
|
|
24
27
|
/** Push Manager */
|
|
25
28
|
var pushManager = syncEnabled && streamingEnabled && pollingManager && pushManagerFactory ?
|
|
26
29
|
pushManagerFactory(params, pollingManager) :
|
|
@@ -74,7 +77,7 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
74
77
|
if (startFirstTime) {
|
|
75
78
|
// Emits SDK_READY_FROM_CACHE
|
|
76
79
|
if (!cacheMetadata.initialCacheLoad) {
|
|
77
|
-
readiness.
|
|
80
|
+
readiness.definitions.emit(SDK_DEFINITIONS_CACHE_LOADED, cacheMetadata);
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
// start syncing splits and segments
|
|
@@ -9,26 +9,24 @@ import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
|
9
9
|
* @param eventsCache - cache to save events
|
|
10
10
|
* @param integrationsManager - optional event handler used for integrations
|
|
11
11
|
*/
|
|
12
|
-
export function eventTrackerFactory(settings, eventsCache,
|
|
12
|
+
export function eventTrackerFactory(settings, eventsCache, integrationsManager, telemetryCache) {
|
|
13
13
|
var log = settings.log, mode = settings.mode;
|
|
14
14
|
var isAsync = isConsumerMode(mode);
|
|
15
15
|
function queueEventsCallback(eventData, tracked) {
|
|
16
16
|
var eventTypeId = eventData.eventTypeId, trafficTypeName = eventData.trafficTypeName, key = eventData.key, value = eventData.value, timestamp = eventData.timestamp, properties = eventData.properties;
|
|
17
17
|
// Logging every prop would be too much.
|
|
18
|
-
var msg = "event of type \""
|
|
18
|
+
var msg = "event of type \"".concat(eventTypeId, "\" for traffic type \"").concat(trafficTypeName, "\". Key: ").concat(key, ". Value: ").concat(value, ". Timestamp: ").concat(timestamp, ". ").concat(properties ? 'With properties.' : 'With no properties.');
|
|
19
19
|
if (tracked) {
|
|
20
20
|
log.info(EVENTS_TRACKER_SUCCESS, [msg]);
|
|
21
21
|
if (integrationsManager) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
integrationsManager.handleEvent(eventDataCopy);
|
|
31
|
-
});
|
|
22
|
+
// Wrap in a timeout because we don't want it to be blocking.
|
|
23
|
+
setTimeout(function () {
|
|
24
|
+
// copy of event, to avoid unexpected behavior if modified by integrations
|
|
25
|
+
var eventDataCopy = objectAssign({}, eventData);
|
|
26
|
+
if (properties)
|
|
27
|
+
eventDataCopy.properties = objectAssign({}, properties);
|
|
28
|
+
// integrationsManager does not throw errors (they are internally handled by each integration module)
|
|
29
|
+
integrationsManager.handleEvent(eventDataCopy);
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export function buildKey(impression) {
|
|
2
|
-
return impression.keyName
|
|
2
|
+
return "".concat(impression.keyName, ":").concat(impression.feature, ":").concat(impression.treatment, ":").concat(impression.label, ":").concat(impression.changeNumber);
|
|
3
3
|
}
|
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
|
|
4
|
-
import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
|
|
4
|
+
import { CONSENT_DECLINED, DEBUG, DEDUPED, OPTIMIZED, QUEUED } from '../utils/constants';
|
|
5
|
+
import { strategyDebugFactory } from './strategy/strategyDebug';
|
|
6
|
+
import { strategyNoneFactory } from './strategy/strategyNone';
|
|
7
|
+
import { strategyOptimizedFactory } from './strategy/strategyOptimized';
|
|
8
|
+
import { uniqueKeysTrackerFactory } from './uniqueKeysTracker';
|
|
5
9
|
/**
|
|
6
10
|
* Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
|
|
7
11
|
*/
|
|
8
|
-
export function impressionsTrackerFactory(
|
|
9
|
-
var
|
|
12
|
+
export function impressionsTrackerFactory(params, storage, integrationsManager) {
|
|
13
|
+
var settings = params.settings, impressionsObserverFactory = params.impressionsObserverFactory, filterAdapterFactory = params.filterAdapterFactory;
|
|
14
|
+
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version, impressionsMode = settings.sync.impressionsMode;
|
|
15
|
+
var observer = impressionsObserverFactory();
|
|
16
|
+
var uniqueKeysTracker = uniqueKeysTrackerFactory(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory());
|
|
17
|
+
var noneStrategy = strategyNoneFactory(storage.impressionCounts, uniqueKeysTracker);
|
|
18
|
+
var strategy = impressionsMode === OPTIMIZED ?
|
|
19
|
+
strategyOptimizedFactory(observer, storage.impressionCounts) :
|
|
20
|
+
impressionsMode === DEBUG ?
|
|
21
|
+
strategyDebugFactory(observer) :
|
|
22
|
+
noneStrategy;
|
|
10
23
|
return {
|
|
24
|
+
start: function () {
|
|
25
|
+
uniqueKeysTracker.start();
|
|
26
|
+
},
|
|
27
|
+
stop: function () {
|
|
28
|
+
uniqueKeysTracker.stop();
|
|
29
|
+
},
|
|
11
30
|
track: function (impressions, attributes) {
|
|
12
31
|
if (settings.userConsent === CONSENT_DECLINED)
|
|
13
32
|
return;
|
|
@@ -20,7 +39,7 @@ export function impressionsTrackerFactory(settings, impressionsCache, noneStrate
|
|
|
20
39
|
var impressionsLength = impressions.length;
|
|
21
40
|
var impressionsToStoreLength = impressionsToStore.length;
|
|
22
41
|
if (impressionsToStoreLength) {
|
|
23
|
-
var res =
|
|
42
|
+
var res = storage.impressions.track(impressionsToStore.map(function (item) { return item.imp; }));
|
|
24
43
|
// If we're on an async storage, handle error and log it.
|
|
25
44
|
if (thenable(res)) {
|
|
26
45
|
res.then(function () {
|
|
@@ -32,9 +51,9 @@ export function impressionsTrackerFactory(settings, impressionsCache, noneStrate
|
|
|
32
51
|
else {
|
|
33
52
|
// Record when impressionsCache is sync only (standalone mode)
|
|
34
53
|
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
if (storage.telemetry) {
|
|
55
|
+
storage.telemetry.recordImpressionStats(QUEUED, impressionsToStoreLength);
|
|
56
|
+
storage.telemetry.recordImpressionStats(DEDUPED, impressionsLength - impressionsToStoreLength);
|
|
38
57
|
}
|
|
39
58
|
}
|
|
40
59
|
}
|
|
@@ -49,20 +68,18 @@ export function impressionsTrackerFactory(settings, impressionsCache, noneStrate
|
|
|
49
68
|
hostname: hostname,
|
|
50
69
|
sdkLanguageVersion: version
|
|
51
70
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
});
|
|
71
|
+
// Wrap in a timeout because we don't want it to be blocking.
|
|
72
|
+
setTimeout(function () {
|
|
73
|
+
// integrationsManager.handleImpression does not throw errors
|
|
74
|
+
if (integrationsManager)
|
|
75
|
+
integrationsManager.handleImpression(impressionData);
|
|
76
|
+
try { // @ts-ignore. An exception on the listeners should not break the SDK.
|
|
77
|
+
if (impressionListener)
|
|
78
|
+
impressionListener.logImpression(impressionData);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
log.error(ERROR_IMPRESSIONS_LISTENER, [err]);
|
|
82
|
+
}
|
|
66
83
|
});
|
|
67
84
|
};
|
|
68
85
|
for (var i = 0; i < impressionsLength; i++) {
|
|
@@ -19,7 +19,7 @@ export function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
|
19
19
|
return {
|
|
20
20
|
track: function (key, featureName) {
|
|
21
21
|
if (!filterAdapter.add(key, featureName)) {
|
|
22
|
-
log.debug(LOG_PREFIX_UNIQUE_KEYS_TRACKER
|
|
22
|
+
log.debug("".concat(LOG_PREFIX_UNIQUE_KEYS_TRACKER, "The feature ").concat(featureName, " and key ").concat(key, " exist in the filter"));
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
uniqueKeysCache.track(key, featureName);
|
package/esm/utils/Backoff.js
CHANGED
|
@@ -24,6 +24,26 @@ var Backoff = /** @class */ (function () {
|
|
|
24
24
|
this.attempts++;
|
|
25
25
|
return delayInMillis;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Schedule a delayed call to `cb`
|
|
29
|
+
* @returns a promise that resolves/rejects with the result of the `cb` function, which must return a promise.
|
|
30
|
+
*/
|
|
31
|
+
Backoff.prototype.scheduleCallAsync = function () {
|
|
32
|
+
var _this = this;
|
|
33
|
+
var delayInMillis = Math.min(this.baseMillis * Math.pow(2, this.attempts), this.maxMillis);
|
|
34
|
+
if (this.timeoutID)
|
|
35
|
+
clearTimeout(this.timeoutID);
|
|
36
|
+
this.attempts++;
|
|
37
|
+
return new Promise(function (resolve, reject) {
|
|
38
|
+
_this.timeoutID = setTimeout(function () {
|
|
39
|
+
_this.timeoutID = undefined;
|
|
40
|
+
_this.cb().then(resolve, reject);
|
|
41
|
+
}, delayInMillis);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Reset the backoff attempts
|
|
46
|
+
*/
|
|
27
47
|
Backoff.prototype.reset = function () {
|
|
28
48
|
this.attempts = 0;
|
|
29
49
|
if (this.timeoutID) {
|