@splitsoftware/splitio-commons 1.2.0 → 1.2.1-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/evaluator/Engine.js +6 -6
- package/cjs/evaluator/combiners/and.js +1 -1
- package/cjs/evaluator/combiners/ifelseif.js +2 -2
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/condition/index.js +4 -4
- package/cjs/evaluator/index.js +5 -5
- package/cjs/evaluator/matchers/cont_all.js +1 -1
- package/cjs/evaluator/matchers/cont_any.js +1 -1
- package/cjs/evaluator/matchers/cont_str.js +1 -1
- package/cjs/evaluator/matchers/dependency.js +1 -1
- package/cjs/evaluator/matchers/eq_set.js +1 -1
- package/cjs/evaluator/matchers/ew.js +3 -3
- package/cjs/evaluator/matchers/part_of.js +1 -1
- package/cjs/evaluator/matchers/segment.js +1 -1
- package/cjs/evaluator/matchers/sw.js +1 -1
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/evaluator/matchersTransform/index.js +12 -12
- package/cjs/evaluator/parser/index.js +6 -6
- package/cjs/evaluator/treatments/index.js +1 -1
- package/cjs/evaluator/value/index.js +1 -1
- package/cjs/evaluator/value/sanitize.js +4 -4
- package/cjs/integrations/browser.js +3 -3
- package/cjs/integrations/ga/GaToSplit.js +14 -14
- package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +5 -3
- package/cjs/integrations/ga/SplitToGa.js +1 -1
- package/cjs/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/cjs/listeners/browser.js +15 -11
- package/cjs/listeners/node.js +1 -1
- package/cjs/logger/constants.js +8 -3
- package/cjs/logger/index.js +2 -2
- package/cjs/logger/messages/debug.js +4 -4
- package/cjs/logger/messages/error.js +5 -4
- package/cjs/logger/messages/info.js +10 -8
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/logger/sdkLogger.js +1 -1
- package/cjs/readiness/readinessManager.js +2 -2
- package/cjs/readiness/sdkReadinessManager.js +4 -4
- package/cjs/sdkClient/client.js +13 -11
- package/cjs/sdkClient/clientAttributesDecoration.js +4 -4
- package/cjs/sdkClient/clientCS.js +4 -3
- package/cjs/sdkClient/clientInputValidation.js +20 -22
- package/cjs/sdkClient/sdkClient.js +3 -6
- package/cjs/sdkClient/sdkClientMethod.js +1 -1
- package/cjs/sdkClient/sdkClientMethodCS.js +6 -10
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +7 -15
- package/cjs/sdkFactory/index.js +14 -12
- package/cjs/sdkFactory/userConsentProps.js +37 -0
- package/cjs/sdkManager/index.js +11 -11
- package/cjs/services/splitApi.js +3 -2
- package/cjs/services/splitHttpClient.js +3 -3
- package/cjs/storages/KeyBuilder.js +2 -6
- package/cjs/storages/KeyBuilderCS.js +13 -3
- package/cjs/storages/KeyBuilderSS.js +1 -1
- package/cjs/storages/findLatencyIndex.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +24 -4
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -12
- package/cjs/storages/inLocalStorage/index.js +4 -4
- package/cjs/storages/inMemory/AttributesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +1 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/cjs/storages/inMemory/LatenciesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +2 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/LatenciesCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +24 -11
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +3 -3
- package/cjs/storages/inRedis/index.js +1 -1
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +3 -3
- package/cjs/storages/pluggable/inMemoryWrapper.js +4 -4
- package/cjs/storages/pluggable/index.js +6 -6
- package/cjs/sync/offline/LocalhostFromFile.js +1 -1
- package/cjs/sync/offline/LocalhostFromObject.js +1 -1
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +13 -13
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +3 -3
- package/cjs/sync/offline/syncManagerOffline.js +1 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -2
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +8 -7
- package/cjs/sync/polling/pollingManagerSS.js +5 -4
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -2
- package/cjs/sync/streaming/AuthClient/index.js +4 -5
- package/cjs/sync/streaming/SSEClient/index.js +2 -1
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +3 -3
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +1 -1
- package/cjs/sync/streaming/pushManager.js +46 -35
- package/cjs/sync/submitters/eventsSyncTask.js +17 -5
- package/cjs/sync/submitters/impressionCountsSyncTask.js +1 -1
- package/cjs/sync/submitters/impressionsSyncTask.js +15 -3
- package/cjs/sync/submitters/metricsSyncTask.js +3 -3
- package/cjs/sync/submitters/submitterManager.js +6 -5
- package/cjs/sync/submitters/submitterSyncTask.js +1 -1
- package/cjs/sync/syncManagerOnline.js +21 -17
- package/cjs/trackers/eventTracker.js +11 -4
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +1 -1
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +1 -1
- package/cjs/trackers/impressionObserver/utils.js +8 -1
- package/cjs/trackers/impressionsTracker.js +9 -8
- package/cjs/utils/MinEvents.js +2 -1
- package/cjs/utils/consent.js +10 -0
- package/cjs/utils/constants/index.js +5 -1
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +4 -4
- package/cjs/utils/inputValidation/attributes.js +2 -2
- package/cjs/utils/inputValidation/event.js +1 -1
- package/cjs/utils/inputValidation/eventProperties.js +7 -5
- package/cjs/utils/inputValidation/eventValue.js +1 -1
- package/cjs/utils/inputValidation/key.js +6 -5
- package/cjs/utils/inputValidation/preloadedData.js +8 -8
- package/cjs/utils/inputValidation/split.js +1 -1
- package/cjs/utils/inputValidation/splits.js +2 -2
- package/cjs/utils/inputValidation/trafficType.js +1 -1
- package/cjs/utils/inputValidation/trafficTypeExistance.js +1 -1
- package/cjs/utils/jwt/index.js +1 -1
- package/cjs/utils/key/index.js +3 -3
- package/cjs/utils/lang/index.js +13 -16
- package/cjs/utils/lang/maps.js +16 -2
- package/cjs/utils/murmur3/common.js +1 -1
- package/cjs/utils/murmur3/legacy.js +44 -0
- package/cjs/utils/murmur3/murmur3.js +10 -10
- package/cjs/utils/murmur3/murmur3_128.js +1 -1
- package/cjs/utils/murmur3/murmur3_128_x86.js +37 -37
- package/cjs/utils/murmur3/murmur3_64.js +1 -1
- package/cjs/utils/promise/timeout.js +1 -1
- package/cjs/utils/settingsValidation/consent.js +16 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +6 -6
- package/cjs/utils/settingsValidation/index.js +32 -14
- package/cjs/utils/settingsValidation/integrations/configurable.js +1 -1
- package/cjs/utils/settingsValidation/integrations/pluggable.js +1 -1
- package/cjs/utils/settingsValidation/localhost/builtin.js +2 -2
- package/cjs/utils/settingsValidation/logger/builtinLogger.js +3 -3
- package/cjs/utils/settingsValidation/logger/commons.js +1 -1
- package/cjs/utils/settingsValidation/logger/pluggableLogger.js +1 -1
- package/cjs/utils/settingsValidation/runtime.js +11 -0
- package/cjs/utils/settingsValidation/splitFilters.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/cjs/utils/timeTracker/index.js +3 -3
- package/esm/evaluator/matchers/ew.js +4 -4
- package/esm/integrations/ga/GoogleAnalyticsToSplit.js +4 -2
- package/esm/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/esm/listeners/browser.js +14 -10
- package/esm/logger/constants.js +5 -2
- package/esm/logger/messages/debug.js +3 -3
- package/esm/logger/messages/error.js +4 -3
- package/esm/logger/messages/info.js +9 -7
- package/esm/sdkClient/client.js +4 -2
- package/esm/sdkClient/clientCS.js +2 -1
- package/esm/sdkClient/clientInputValidation.js +6 -8
- package/esm/sdkClient/sdkClient.js +1 -4
- package/esm/sdkClient/sdkClientMethodCS.js +1 -5
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +1 -9
- package/esm/sdkFactory/index.js +8 -6
- package/esm/sdkFactory/userConsentProps.js +33 -0
- package/esm/services/splitApi.js +2 -1
- package/esm/services/splitHttpClient.js +1 -1
- package/esm/storages/KeyBuilder.js +2 -6
- package/esm/storages/KeyBuilderCS.js +11 -1
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +23 -3
- package/esm/storages/inLocalStorage/index.js +1 -1
- package/esm/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/esm/storages/inMemory/InMemoryStorage.js +1 -1
- package/esm/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +15 -2
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +1 -1
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +2 -1
- package/esm/sync/polling/pollingManagerSS.js +2 -1
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/streaming/AuthClient/index.js +1 -2
- package/esm/sync/streaming/SSEClient/index.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/esm/sync/streaming/pushManager.js +34 -23
- package/esm/sync/submitters/eventsSyncTask.js +18 -6
- package/esm/sync/submitters/impressionsSyncTask.js +13 -1
- package/esm/sync/submitters/submitterManager.js +2 -1
- package/esm/sync/syncManagerOnline.js +21 -17
- package/esm/trackers/eventTracker.js +8 -1
- package/esm/trackers/impressionObserver/utils.js +7 -1
- package/esm/trackers/impressionsTracker.js +6 -5
- package/esm/utils/consent.js +6 -0
- package/esm/utils/constants/index.js +4 -0
- package/esm/utils/inputValidation/attributes.js +1 -1
- package/esm/utils/inputValidation/eventProperties.js +4 -2
- package/esm/utils/inputValidation/key.js +2 -1
- package/esm/utils/lang/index.js +12 -15
- package/esm/utils/lang/maps.js +14 -1
- package/esm/utils/murmur3/legacy.js +39 -0
- package/esm/utils/promise/timeout.js +1 -1
- package/esm/utils/settingsValidation/consent.js +12 -0
- package/esm/utils/settingsValidation/impressionsMode.js +7 -7
- package/esm/utils/settingsValidation/index.js +28 -10
- package/esm/utils/settingsValidation/runtime.js +7 -0
- package/package.json +7 -7
- package/src/evaluator/matchers/ew.ts +4 -4
- package/src/evaluator/parser/index.ts +1 -1
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +2 -2
- package/src/integrations/ga/GoogleAnalyticsToSplit.ts +7 -4
- package/src/integrations/ga/SplitToGoogleAnalytics.ts +7 -4
- package/src/integrations/pluggable.ts +2 -2
- package/src/integrations/types.ts +5 -0
- package/src/listeners/browser.ts +13 -9
- package/src/logger/.DS_Store +0 -0
- package/src/logger/constants.ts +5 -2
- package/src/logger/messages/debug.ts +3 -3
- package/src/logger/messages/error.ts +4 -3
- package/src/logger/messages/info.ts +9 -7
- package/src/logger/types.ts +4 -0
- package/src/sdkClient/client.ts +4 -2
- package/src/sdkClient/clientCS.ts +3 -1
- package/src/sdkClient/clientInputValidation.ts +8 -7
- package/src/sdkClient/sdkClient.ts +2 -5
- package/src/sdkClient/sdkClientMethodCS.ts +1 -6
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +2 -11
- package/src/sdkFactory/index.ts +9 -7
- package/src/sdkFactory/types.ts +2 -1
- package/src/sdkFactory/userConsentProps.ts +40 -0
- package/src/services/splitHttpClient.ts +1 -1
- package/src/storages/KeyBuilder.ts +2 -6
- package/src/storages/KeyBuilderCS.ts +13 -1
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +23 -3
- package/src/storages/inLocalStorage/index.ts +1 -1
- package/src/storages/inMemory/ImpressionsCacheInMemory.ts +22 -1
- package/src/storages/inMemory/InMemoryStorage.ts +1 -1
- package/src/storages/inMemory/InMemoryStorageCS.ts +1 -1
- package/src/storages/inRedis/RedisAdapter.ts +8 -2
- package/src/storages/pluggable/index.ts +2 -2
- package/src/storages/types.ts +6 -2
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +1 -1
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +2 -1
- package/src/sync/polling/fetchers/types.ts +1 -0
- package/src/sync/polling/pollingManagerCS.ts +3 -6
- package/src/sync/polling/pollingManagerSS.ts +3 -8
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +2 -1
- package/src/sync/polling/types.ts +0 -12
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -1
- package/src/sync/streaming/AuthClient/index.ts +1 -2
- package/src/sync/streaming/SSEClient/index.ts +2 -1
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
- package/src/sync/streaming/pushManager.ts +39 -37
- package/src/sync/streaming/types.ts +5 -25
- package/src/sync/submitters/eventsSyncTask.ts +19 -6
- package/src/sync/submitters/impressionsSyncTask.ts +16 -1
- package/src/sync/submitters/submitterManager.ts +4 -8
- package/src/sync/syncManagerOnline.ts +27 -27
- package/src/sync/types.ts +4 -1
- package/src/trackers/eventTracker.ts +11 -3
- package/src/trackers/impressionObserver/utils.ts +8 -1
- package/src/trackers/impressionsTracker.ts +7 -8
- package/src/types.ts +26 -1
- package/src/utils/consent.ts +8 -0
- package/src/utils/constants/index.ts +5 -0
- package/src/utils/inputValidation/attributes.ts +1 -2
- package/src/utils/inputValidation/eventProperties.ts +4 -2
- package/src/utils/lang/index.ts +15 -18
- package/src/utils/lang/maps.ts +15 -1
- package/src/utils/murmur3/legacy.ts +48 -0
- package/src/utils/promise/timeout.ts +1 -1
- package/src/utils/settingsValidation/consent.ts +16 -0
- package/src/utils/settingsValidation/impressionsMode.ts +8 -8
- package/src/utils/settingsValidation/index.ts +29 -10
- package/src/utils/settingsValidation/runtime.ts +9 -0
- package/src/utils/settingsValidation/types.ts +12 -6
- package/types/evaluator/types.d.ts +2 -2
- package/types/evaluator/value/index.d.ts +1 -1
- package/types/evaluator/value/sanitize.d.ts +1 -1
- package/types/integrations/ga/GaToSplitPlugin.d.ts +3 -0
- package/types/integrations/ga/GoogleAnalyticsToSplit.d.ts +2 -2
- package/types/integrations/ga/SplitToGaPlugin.d.ts +4 -0
- package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +2 -3
- package/types/integrations/types.d.ts +4 -0
- package/types/logger/browser/{DebugLogger.d.ts → debugLogger.d.ts} +0 -0
- package/types/logger/browser/{ErrorLogger.d.ts → errorLogger.d.ts} +0 -0
- package/types/logger/browser/{InfoLogger.d.ts → infoLogger.d.ts} +0 -0
- package/types/logger/browser/{WarnLogger.d.ts → warnLogger.d.ts} +0 -0
- package/types/logger/codes.d.ts +2 -0
- package/types/logger/codesConstants.d.ts +117 -0
- package/types/logger/codesConstantsBrowser.d.ts +2 -0
- package/types/logger/codesConstantsNode.d.ts +14 -0
- package/types/logger/codesDebug.d.ts +1 -0
- package/types/logger/codesDebugBrowser.d.ts +1 -0
- package/types/logger/codesDebugNode.d.ts +1 -0
- package/types/logger/codesError.d.ts +1 -0
- package/types/logger/codesErrorNode.d.ts +1 -0
- package/types/logger/codesInfo.d.ts +1 -0
- package/types/logger/codesWarn.d.ts +1 -0
- package/types/logger/codesWarnNode.d.ts +1 -0
- package/types/logger/constants.d.ts +5 -2
- package/types/logger/debugLogger.d.ts +2 -0
- package/types/logger/errorLogger.d.ts +2 -0
- package/types/logger/infoLogger.d.ts +2 -0
- package/types/logger/messages/debugBrowser.d.ts +1 -0
- package/types/logger/messages/debugNode.d.ts +1 -0
- package/types/logger/messages/errorNode.d.ts +1 -0
- package/types/logger/messages/warnNode.d.ts +1 -0
- package/types/logger/noopLogger.d.ts +2 -0
- package/types/logger/types.d.ts +4 -0
- package/types/logger/warnLogger.d.ts +2 -0
- package/types/sdkClient/clientAttributesDecoration.d.ts +1 -1
- package/types/sdkClient/clientInputValidation.d.ts +2 -3
- package/types/sdkFactory/types.d.ts +1 -1
- package/types/sdkFactory/userConsentProps.d.ts +6 -0
- package/types/sdkManager/sdkManagerMethod.d.ts +6 -0
- package/types/storages/KeyBuilderCS.d.ts +2 -0
- package/types/storages/getRegisteredSegments.d.ts +10 -0
- package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +9 -0
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +51 -0
- package/types/storages/inMemory/index.d.ts +10 -0
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +0 -0
- package/types/storages/parseSegments.d.ts +6 -0
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +2 -0
- package/types/storages/types.d.ts +3 -1
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +1 -1
- package/types/sync/polling/fetchers/types.d.ts +1 -1
- package/types/sync/polling/pollingManagerCS.d.ts +2 -5
- package/types/sync/polling/pollingManagerSS.d.ts +2 -5
- package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +35 -0
- package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +35 -0
- package/types/sync/polling/types.d.ts +0 -11
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +1 -1
- package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
- package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -1
- package/types/sync/streaming/pushManager.d.ts +3 -7
- package/types/sync/streaming/pushManagerCS.d.ts +1 -0
- package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
- package/types/sync/streaming/pushManagerSS.d.ts +1 -0
- package/types/sync/streaming/types.d.ts +3 -23
- package/types/sync/submitters/submitterManager.d.ts +2 -4
- package/types/sync/submitters/telemetrySyncTask.d.ts +17 -0
- package/types/sync/syncManagerFromFile.d.ts +2 -0
- package/types/sync/syncManagerFromObject.d.ts +2 -0
- package/types/sync/syncManagerOffline.d.ts +9 -0
- package/types/sync/syncManagerOnline.d.ts +3 -3
- package/types/sync/types.d.ts +3 -0
- package/types/trackers/eventTracker.d.ts +2 -2
- package/types/trackers/impressionObserver/utils.d.ts +4 -0
- package/types/trackers/impressionsTracker.d.ts +2 -3
- package/types/trackers/telemetryRecorder.d.ts +0 -0
- package/types/types.d.ts +22 -0
- package/types/utils/EventEmitter.d.ts +4 -0
- package/types/utils/consent.d.ts +2 -0
- package/types/utils/constants/index.d.ts +3 -0
- package/types/utils/lang/errors.d.ts +10 -0
- package/types/utils/lang/index.d.ts +6 -5
- package/types/utils/lang/maps.d.ts +7 -0
- package/types/utils/murmur3/commons.d.ts +12 -0
- package/types/utils/murmur3/legacy.d.ts +2 -0
- package/types/utils/settingsValidation/buildMetadata.d.ts +3 -0
- package/types/utils/settingsValidation/consent.d.ts +6 -0
- package/types/utils/settingsValidation/impressionsMode.d.ts +1 -1
- package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
- package/types/utils/settingsValidation/logger.d.ts +11 -0
- package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
- package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
- package/types/utils/settingsValidation/runtime.d.ts +2 -0
- package/types/utils/settingsValidation/types.d.ts +12 -6
- package/types/utils/settingsValidation/userConsent.d.ts +5 -0
|
@@ -19,10 +19,11 @@ import { hash64 } from '../../utils/murmur3/murmur3_64';
|
|
|
19
19
|
* - for server-side if key is not provided in settings.
|
|
20
20
|
* - for client-side, with support for multiple clients, if key is provided in settings
|
|
21
21
|
*/
|
|
22
|
-
export function pushManagerFactory(
|
|
22
|
+
export function pushManagerFactory(params, pollingManager) {
|
|
23
|
+
var settings = params.settings, storage = params.storage, splitApi = params.splitApi, readiness = params.readiness, platform = params.platform;
|
|
23
24
|
// `userKey` is the matching key of main client in client-side SDK.
|
|
24
25
|
// It can be used to check if running on client-side or server-side SDK.
|
|
25
|
-
var userKey = settings.core.key ? getMatching(settings.core.key) : undefined;
|
|
26
|
+
var userKey = settings.core.key ? getMatching(settings.core.key) : undefined;
|
|
26
27
|
var log = settings.log;
|
|
27
28
|
var sseClient;
|
|
28
29
|
try {
|
|
@@ -33,13 +34,14 @@ export function pushManagerFactory(pollingManager, storage, readiness, fetchAuth
|
|
|
33
34
|
log.warn(STREAMING_FALLBACK, [e]);
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
|
-
var authenticate = authenticateFactory(fetchAuth);
|
|
37
|
+
var authenticate = authenticateFactory(splitApi.fetchAuth);
|
|
37
38
|
// init feedback loop
|
|
38
39
|
var pushEmitter = new platform.EventEmitter();
|
|
39
40
|
var sseHandler = SSEHandlerFactory(log, pushEmitter);
|
|
40
41
|
sseClient.setEventHandler(sseHandler);
|
|
41
42
|
// init workers
|
|
42
|
-
|
|
43
|
+
// MySegmentsUpdateWorker (client-side) are initiated in `add` method
|
|
44
|
+
var segmentsUpdateWorker = userKey ? undefined : new SegmentsUpdateWorker(pollingManager.segmentsSyncTask, storage.segments);
|
|
43
45
|
// For server-side we pass the segmentsSyncTask, used by SplitsUpdateWorker to fetch new segments
|
|
44
46
|
var splitsUpdateWorker = new SplitsUpdateWorker(storage.splits, pollingManager.splitsSyncTask, readiness.splits, userKey ? undefined : pollingManager.segmentsSyncTask);
|
|
45
47
|
// [Only for client-side] map of hashes to user keys, to dispatch MY_SEGMENTS_UPDATE events to the corresponding MySegmentsUpdateWorker
|
|
@@ -47,17 +49,13 @@ export function pushManagerFactory(pollingManager, storage, readiness, fetchAuth
|
|
|
47
49
|
// [Only for client-side] map of user keys to their corresponding hash64 and MySegmentsUpdateWorkers.
|
|
48
50
|
// Hash64 is used to process MY_SEGMENTS_UPDATE_V2 events and dispatch actions to the corresponding MySegmentsUpdateWorker.
|
|
49
51
|
var clients = {};
|
|
50
|
-
if (userKey) {
|
|
51
|
-
var hash = hashUserKey(userKey);
|
|
52
|
-
userKeyHashes[hash] = userKey;
|
|
53
|
-
clients[userKey] = { hash64: hash64(userKey), worker: segmentsUpdateWorker };
|
|
54
|
-
}
|
|
55
52
|
// [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
|
|
56
53
|
var connectForNewClient = false;
|
|
57
54
|
// flag that indicates if `stop/disconnectPush` was called, either by the SyncManager, when the client is destroyed, or due to a PUSH_NONRETRYABLE_ERROR error.
|
|
58
55
|
// It is used to halt the `connectPush` process if it was in progress.
|
|
59
56
|
var disconnected;
|
|
60
57
|
// flag that indicates a PUSH_NONRETRYABLE_ERROR, condition with which starting pushManager again is ignored.
|
|
58
|
+
// true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
|
|
61
59
|
var disabled; // `disabled` implies `disconnected === true`
|
|
62
60
|
/** PushManager functions related to initialization */
|
|
63
61
|
var connectPushRetryBackoff = new Backoff(connectPush, settings.scheduler.pushRetryBackoffBase);
|
|
@@ -258,33 +256,46 @@ export function pushManagerFactory(pollingManager, storage, readiness, fetchAuth
|
|
|
258
256
|
return objectAssign(
|
|
259
257
|
// Expose Event Emitter functionality and Event constants
|
|
260
258
|
Object.create(pushEmitter), {
|
|
261
|
-
//
|
|
262
|
-
|
|
259
|
+
// Stop/pause push mode.
|
|
260
|
+
// It doesn't emit events. Neither PUSH_SUBSYSTEM_DOWN to start polling.
|
|
261
|
+
stop: function () {
|
|
262
|
+
disconnectPush(); // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
|
|
263
|
+
if (userKey)
|
|
264
|
+
this.remove(userKey); // Necessary to properly resume streaming in client-side (e.g., RN SDK transition to foreground).
|
|
265
|
+
},
|
|
266
|
+
// Start/resume push mode.
|
|
267
|
+
// It eventually emits PUSH_SUBSYSTEM_DOWN, that starts polling, or PUSH_SUBSYSTEM_UP, that executes a syncAll
|
|
263
268
|
start: function () {
|
|
264
269
|
// Guard condition to avoid calling `connectPush` again if the `start` method is called multiple times or if push has been disabled.
|
|
265
270
|
if (disabled || disconnected === false)
|
|
266
271
|
return;
|
|
267
272
|
disconnected = false;
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
if (userKey)
|
|
274
|
+
this.add(userKey, pollingManager.segmentsSyncTask); // client-side
|
|
275
|
+
else
|
|
276
|
+
setTimeout(connectPush); // server-side runs in next cycle as in client-side, for consistency with client-side
|
|
277
|
+
},
|
|
278
|
+
// true/false if start or stop was called last respectively
|
|
279
|
+
isRunning: function () {
|
|
280
|
+
return disconnected === false;
|
|
270
281
|
},
|
|
271
282
|
// [Only for client-side]
|
|
272
283
|
add: function (userKey, mySegmentsSyncTask) {
|
|
273
|
-
clients[userKey] = { hash64: hash64(userKey), worker: new MySegmentsUpdateWorker(mySegmentsSyncTask) };
|
|
274
284
|
var hash = hashUserKey(userKey);
|
|
275
285
|
if (!userKeyHashes[hash]) {
|
|
276
286
|
userKeyHashes[hash] = userKey;
|
|
287
|
+
clients[userKey] = { hash64: hash64(userKey), worker: new MySegmentsUpdateWorker(mySegmentsSyncTask) };
|
|
277
288
|
connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
|
|
289
|
+
// Reconnects in case of a new client.
|
|
290
|
+
// Run in next event-loop cycle to save authentication calls
|
|
291
|
+
// in case multiple clients are created in the current cycle.
|
|
292
|
+
setTimeout(function checkForReconnect() {
|
|
293
|
+
if (connectForNewClient) {
|
|
294
|
+
connectForNewClient = false;
|
|
295
|
+
connectPush();
|
|
296
|
+
}
|
|
297
|
+
}, 0);
|
|
278
298
|
}
|
|
279
|
-
// Reconnects in case of a new client.
|
|
280
|
-
// Run in next event-loop cycle to save authentication calls
|
|
281
|
-
// in case the user is creating several clients in the current cycle.
|
|
282
|
-
setTimeout(function checkForReconnect() {
|
|
283
|
-
if (connectForNewClient) {
|
|
284
|
-
connectForNewClient = false;
|
|
285
|
-
connectPush();
|
|
286
|
-
}
|
|
287
|
-
}, 0);
|
|
288
299
|
},
|
|
289
300
|
// [Only for client-side]
|
|
290
301
|
remove: function (userKey) {
|
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
2
|
-
import {
|
|
2
|
+
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
3
|
+
var DATA_NAME = 'events';
|
|
3
4
|
/**
|
|
4
5
|
* Sync task that periodically posts tracked events
|
|
5
6
|
*/
|
|
6
7
|
export function eventsSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, eventsFirstPushWindow, latencyTracker) {
|
|
7
8
|
// don't retry events.
|
|
8
|
-
var syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate,
|
|
9
|
-
// Set a timer for the first push of events
|
|
9
|
+
var syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
|
|
10
|
+
// Set a timer for the first push window of events.
|
|
11
|
+
// Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
|
|
10
12
|
if (eventsFirstPushWindow > 0) {
|
|
13
|
+
var running_1 = false;
|
|
11
14
|
var stopEventPublisherTimeout_1;
|
|
12
15
|
var originalStart_1 = syncTask.start;
|
|
13
16
|
syncTask.start = function () {
|
|
17
|
+
running_1 = true;
|
|
14
18
|
stopEventPublisherTimeout_1 = setTimeout(originalStart_1, eventsFirstPushWindow);
|
|
15
19
|
};
|
|
16
20
|
var originalStop_1 = syncTask.stop;
|
|
17
21
|
syncTask.stop = function () {
|
|
22
|
+
running_1 = false;
|
|
18
23
|
clearTimeout(stopEventPublisherTimeout_1);
|
|
19
24
|
originalStop_1();
|
|
20
25
|
};
|
|
26
|
+
syncTask.isRunning = function () {
|
|
27
|
+
return running_1;
|
|
28
|
+
};
|
|
21
29
|
}
|
|
22
|
-
// register
|
|
30
|
+
// register events submitter to be executed when events cache is full
|
|
23
31
|
eventsCache.setOnFullQueueCb(function () {
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
if (syncTask.isRunning()) {
|
|
33
|
+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
34
|
+
syncTask.execute();
|
|
35
|
+
}
|
|
36
|
+
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
37
|
+
// Data will be sent when submitter is resumed.
|
|
26
38
|
});
|
|
27
39
|
return syncTask;
|
|
28
40
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { groupBy, forOwn } from '../../utils/lang';
|
|
2
2
|
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
3
|
+
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
4
|
+
var DATA_NAME = 'impressions';
|
|
3
5
|
/**
|
|
4
6
|
* Converts `impressions` data from cache into request payload.
|
|
5
7
|
*/
|
|
@@ -32,5 +34,15 @@ export function fromImpressionsCollector(sendLabels, data) {
|
|
|
32
34
|
export function impressionsSyncTaskFactory(log, postTestImpressionsBulk, impressionsCache, impressionsRefreshRate, sendLabels, latencyTracker) {
|
|
33
35
|
if (sendLabels === void 0) { sendLabels = false; }
|
|
34
36
|
// retry impressions only once.
|
|
35
|
-
|
|
37
|
+
var syncTask = submitterSyncTaskFactory(log, postTestImpressionsBulk, impressionsCache, impressionsRefreshRate, DATA_NAME, latencyTracker, fromImpressionsCollector.bind(undefined, sendLabels), 1);
|
|
38
|
+
// register impressions submitter to be executed when impressions cache is full
|
|
39
|
+
impressionsCache.setOnFullQueueCb(function () {
|
|
40
|
+
if (syncTask.isRunning()) {
|
|
41
|
+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
42
|
+
syncTask.execute();
|
|
43
|
+
}
|
|
44
|
+
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
45
|
+
// Data will be sent when submitter is resumed.
|
|
46
|
+
});
|
|
47
|
+
return syncTask;
|
|
36
48
|
}
|
|
@@ -2,7 +2,8 @@ import { syncTaskComposite } from '../syncTaskComposite';
|
|
|
2
2
|
import { eventsSyncTaskFactory } from './eventsSyncTask';
|
|
3
3
|
import { impressionsSyncTaskFactory } from './impressionsSyncTask';
|
|
4
4
|
import { impressionCountsSyncTaskFactory } from './impressionCountsSyncTask';
|
|
5
|
-
export function submitterManagerFactory(
|
|
5
|
+
export function submitterManagerFactory(params) {
|
|
6
|
+
var settings = params.settings, storage = params.storage, splitApi = params.splitApi;
|
|
6
7
|
var log = settings.log;
|
|
7
8
|
var submitters = [
|
|
8
9
|
impressionsSyncTaskFactory(log, splitApi.postTestImpressionsBulk, storage.impressions, settings.scheduler.impressionsRefreshRate, settings.core.labelsEnabled),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { submitterManagerFactory } from './submitters/submitterManager';
|
|
2
2
|
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
|
+
import { isConsentGranted } from '../utils/consent';
|
|
4
5
|
/**
|
|
5
6
|
* Online SyncManager factory.
|
|
6
7
|
* Can be used for server-side API, and client-side API with or without multiple clients.
|
|
@@ -13,26 +14,25 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
13
14
|
/**
|
|
14
15
|
* SyncManager factory for modular SDK
|
|
15
16
|
*/
|
|
16
|
-
return function (
|
|
17
|
-
var settings =
|
|
18
|
-
var log = settings.log;
|
|
17
|
+
return function (params) {
|
|
18
|
+
var settings = params.settings, _a = params.settings, log = _a.log, streamingEnabled = _a.streamingEnabled;
|
|
19
19
|
/** Polling Manager */
|
|
20
|
-
var pollingManager = pollingManagerFactory && pollingManagerFactory(
|
|
20
|
+
var pollingManager = pollingManagerFactory && pollingManagerFactory(params);
|
|
21
21
|
/** Push Manager */
|
|
22
|
-
var pushManager =
|
|
23
|
-
pushManagerFactory(
|
|
22
|
+
var pushManager = streamingEnabled && pollingManager && pushManagerFactory ?
|
|
23
|
+
pushManagerFactory(params, pollingManager) :
|
|
24
24
|
undefined;
|
|
25
25
|
/** Submitter Manager */
|
|
26
26
|
// It is not inyected as push and polling managers, because at the moment it is required
|
|
27
|
-
var submitter = submitterManagerFactory(
|
|
27
|
+
var submitter = submitterManagerFactory(params);
|
|
28
28
|
/** Sync Manager logic */
|
|
29
29
|
function startPolling() {
|
|
30
|
-
if (
|
|
31
|
-
log.info(
|
|
32
|
-
pollingManager.start();
|
|
30
|
+
if (pollingManager.isRunning()) {
|
|
31
|
+
log.info(SYNC_CONTINUE_POLLING);
|
|
33
32
|
}
|
|
34
33
|
else {
|
|
35
|
-
log.info(
|
|
34
|
+
log.info(SYNC_START_POLLING);
|
|
35
|
+
pollingManager.start();
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
function stopPollingAndSyncAll() {
|
|
@@ -50,11 +50,16 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
50
50
|
var running = false; // flag that indicates whether the syncManager has been started (true) or stopped (false)
|
|
51
51
|
var startFirstTime = true; // flag to distinguish calling the `start` method for the first time, to support pausing and resuming the synchronization
|
|
52
52
|
return {
|
|
53
|
+
// Exposed for fine-grained control of synchronization.
|
|
54
|
+
// E.g.: user consent, app state changes (Page hide, Foreground/Background, Online/Offline).
|
|
55
|
+
pollingManager: pollingManager,
|
|
53
56
|
pushManager: pushManager,
|
|
57
|
+
submitter: submitter,
|
|
54
58
|
/**
|
|
55
59
|
* Method used to start the syncManager for the first time, or resume it after being stopped.
|
|
56
60
|
*/
|
|
57
61
|
start: function () {
|
|
62
|
+
running = true;
|
|
58
63
|
// start syncing splits and segments
|
|
59
64
|
if (pollingManager) {
|
|
60
65
|
if (pushManager) {
|
|
@@ -70,28 +75,27 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
// start periodic data recording (events, impressions, telemetry).
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
if (isConsentGranted(settings))
|
|
79
|
+
submitter.start();
|
|
75
80
|
},
|
|
76
81
|
/**
|
|
77
82
|
* Method used to stop/pause the syncManager.
|
|
78
83
|
*/
|
|
79
84
|
stop: function () {
|
|
85
|
+
running = false;
|
|
80
86
|
// stop syncing
|
|
81
87
|
if (pushManager)
|
|
82
88
|
pushManager.stop();
|
|
83
89
|
if (pollingManager && pollingManager.isRunning())
|
|
84
90
|
pollingManager.stop();
|
|
85
91
|
// stop periodic data recording (events, impressions, telemetry).
|
|
86
|
-
|
|
87
|
-
submitter.stop();
|
|
88
|
-
running = false;
|
|
92
|
+
submitter.stop();
|
|
89
93
|
},
|
|
90
94
|
isRunning: function () {
|
|
91
95
|
return running;
|
|
92
96
|
},
|
|
93
97
|
flush: function () {
|
|
94
|
-
if (
|
|
98
|
+
if (isConsentGranted(settings))
|
|
95
99
|
return submitter.execute();
|
|
96
100
|
else
|
|
97
101
|
return Promise.resolve();
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { EVENTS_TRACKER_SUCCESS, ERROR_EVENTS_TRACKER } from '../logger/constants';
|
|
4
|
+
import { CONSENT_DECLINED } from '../utils/constants';
|
|
5
|
+
import { isStorageSync } from './impressionObserver/utils';
|
|
4
6
|
/**
|
|
5
7
|
* Event tracker stores events in cache and pass them to the integrations manager if provided.
|
|
6
8
|
*
|
|
7
9
|
* @param eventsCache cache to save events
|
|
8
10
|
* @param integrationsManager optional event handler used for integrations
|
|
9
11
|
*/
|
|
10
|
-
export function eventTrackerFactory(
|
|
12
|
+
export function eventTrackerFactory(settings, eventsCache, integrationsManager) {
|
|
13
|
+
var log = settings.log;
|
|
14
|
+
var isSync = isStorageSync(settings);
|
|
11
15
|
function queueEventsCallback(eventData, tracked) {
|
|
12
16
|
var eventTypeId = eventData.eventTypeId, trafficTypeName = eventData.trafficTypeName, key = eventData.key, value = eventData.value, timestamp = eventData.timestamp, properties = eventData.properties;
|
|
13
17
|
// Logging every prop would be too much.
|
|
@@ -33,6 +37,9 @@ export function eventTrackerFactory(log, eventsCache, integrationsManager) {
|
|
|
33
37
|
}
|
|
34
38
|
return {
|
|
35
39
|
track: function (eventData, size) {
|
|
40
|
+
if (settings.userConsent === CONSENT_DECLINED) {
|
|
41
|
+
return isSync ? false : Promise.resolve(false);
|
|
42
|
+
}
|
|
36
43
|
var tracked = eventsCache.track(eventData, size);
|
|
37
44
|
if (thenable(tracked)) {
|
|
38
45
|
return tracked.then(queueEventsCallback.bind(null, eventData));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONSUMER_PARTIAL_MODE, OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '../../utils/constants';
|
|
1
|
+
import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE, OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '../../utils/constants';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if impressions previous time should be added or not.
|
|
4
4
|
*/
|
|
@@ -13,3 +13,9 @@ export function shouldBeOptimized(settings) {
|
|
|
13
13
|
return false;
|
|
14
14
|
return settings.sync.impressionsMode === OPTIMIZED ? true : false;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Storage is async if mode is consumer or partial consumer
|
|
18
|
+
*/
|
|
19
|
+
export function isStorageSync(settings) {
|
|
20
|
+
return [CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false;
|
|
21
|
+
}
|
|
@@ -2,6 +2,7 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { truncateTimeFrame } from '../utils/time';
|
|
4
4
|
import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
|
|
5
|
+
import { CONSENT_DECLINED } from '../utils/constants';
|
|
5
6
|
/**
|
|
6
7
|
* Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
|
|
7
8
|
*
|
|
@@ -12,16 +13,16 @@ import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIO
|
|
|
12
13
|
* @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
|
|
13
14
|
* @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
|
|
14
15
|
*/
|
|
15
|
-
export function impressionsTrackerFactory(
|
|
16
|
-
// @TODO consider passing only an optional integrationsManager to handle impressions
|
|
17
|
-
_a, impressionListener, integrationsManager,
|
|
16
|
+
export function impressionsTrackerFactory(settings, impressionsCache, integrationsManager,
|
|
18
17
|
// if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
|
|
19
18
|
observer,
|
|
20
19
|
// if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
|
|
21
20
|
countsCache) {
|
|
22
|
-
var
|
|
21
|
+
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
23
22
|
return {
|
|
24
23
|
track: function (impressions, attributes) {
|
|
24
|
+
if (settings.userConsent === CONSENT_DECLINED)
|
|
25
|
+
return;
|
|
25
26
|
var impressionsCount = impressions.length;
|
|
26
27
|
var impressionsToStore = []; // Track only the impressions that are going to be stored
|
|
27
28
|
// Wraps impressions to store and adds previousTime if it corresponds
|
|
@@ -65,7 +66,7 @@ countsCache) {
|
|
|
65
66
|
// integrationsManager.handleImpression does not throw errors
|
|
66
67
|
if (integrationsManager)
|
|
67
68
|
integrationsManager.handleImpression(impressionData);
|
|
68
|
-
try { // An exception on the listeners should not break the SDK.
|
|
69
|
+
try { // @ts-ignore. An exception on the listeners should not break the SDK.
|
|
69
70
|
if (impressionListener)
|
|
70
71
|
impressionListener.logImpression(impressionData);
|
|
71
72
|
}
|
|
@@ -24,3 +24,7 @@ export var STORAGE_MEMORY = 'MEMORY';
|
|
|
24
24
|
export var STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
|
|
25
25
|
export var STORAGE_REDIS = 'REDIS';
|
|
26
26
|
export var STORAGE_PLUGGABLE = 'PLUGGABLE';
|
|
27
|
+
// User consent
|
|
28
|
+
export var CONSENT_GRANTED = 'GRANTED'; // The user has granted consent for tracking events and impressions
|
|
29
|
+
export var CONSENT_DECLINED = 'DECLINED'; // The user has declined consent for tracking events and impressions
|
|
30
|
+
export var CONSENT_UNKNOWN = 'UNKNOWN'; // The user has neither granted nor declined consent for tracking events and impressions
|
|
@@ -3,7 +3,7 @@ import { validateAttribute } from './attribute';
|
|
|
3
3
|
import { ERROR_NOT_PLAIN_OBJECT } from '../../logger/constants';
|
|
4
4
|
export function validateAttributes(log, maybeAttrs, method) {
|
|
5
5
|
// Attributes are optional
|
|
6
|
-
if (
|
|
6
|
+
if (maybeAttrs == undefined || isObject(maybeAttrs)) // eslint-disable-line eqeqeq
|
|
7
7
|
return maybeAttrs;
|
|
8
8
|
log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'attributes']);
|
|
9
9
|
return false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { isObject,
|
|
1
|
+
import { isObject, isString, isFiniteNumber, isBoolean } from '../lang';
|
|
2
|
+
import { objectAssign } from '../lang/objectAssign';
|
|
2
3
|
import { ERROR_NOT_PLAIN_OBJECT, ERROR_SIZE_EXCEEDED, WARN_SETTING_NULL, WARN_TRIMMING_PROPERTIES } from '../../logger/constants';
|
|
3
4
|
var ECMA_SIZES = {
|
|
4
5
|
NULL: 0,
|
|
@@ -17,7 +18,8 @@ export function validateEventProperties(log, maybeProperties, method) {
|
|
|
17
18
|
return { properties: false, size: BASE_EVENT_SIZE };
|
|
18
19
|
}
|
|
19
20
|
var keys = Object.keys(maybeProperties);
|
|
20
|
-
|
|
21
|
+
// Shallow clone
|
|
22
|
+
var clone = objectAssign({}, maybeProperties);
|
|
21
23
|
// To avoid calculating the size twice we'll return it from here.
|
|
22
24
|
var output = {
|
|
23
25
|
properties: clone,
|
|
@@ -35,7 +35,8 @@ export function validateKey(log, maybeKey, method) {
|
|
|
35
35
|
var bucketingKey = validateKeyValue(log, maybeKey.bucketingKey, method, 'bucketingKey');
|
|
36
36
|
if (matchingKey && bucketingKey)
|
|
37
37
|
return {
|
|
38
|
-
matchingKey: matchingKey,
|
|
38
|
+
matchingKey: matchingKey,
|
|
39
|
+
bucketingKey: bucketingKey
|
|
39
40
|
};
|
|
40
41
|
log.error(ERROR_INVALID_KEY_OBJECT, [method]);
|
|
41
42
|
return false;
|
package/esm/utils/lang/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the target string ends with the sub string.
|
|
4
4
|
*/
|
|
@@ -141,10 +141,12 @@ export function isNaNNumber(val) {
|
|
|
141
141
|
return val !== val;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
|
-
* Validates if a value is an object
|
|
144
|
+
* Validates if a value is an object created by the Object constructor (plain object).
|
|
145
|
+
* It checks `constructor.name` to avoid false negatives when validating values on a separate VM context, which has its own global built-ins.
|
|
145
146
|
*/
|
|
146
147
|
export function isObject(obj) {
|
|
147
|
-
return obj !== null && typeof obj === 'object' && obj.constructor === Object
|
|
148
|
+
return obj !== null && typeof obj === 'object' && (obj.constructor === Object ||
|
|
149
|
+
(obj.constructor != null && obj.constructor.name === 'Object'));
|
|
148
150
|
}
|
|
149
151
|
/**
|
|
150
152
|
* Checks if a given value is a string.
|
|
@@ -152,6 +154,12 @@ export function isObject(obj) {
|
|
|
152
154
|
export function isString(val) {
|
|
153
155
|
return typeof val === 'string' || val instanceof String;
|
|
154
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* String sanitizer. Returns the provided value converted to uppercase if it is a string.
|
|
159
|
+
*/
|
|
160
|
+
export function stringToUpperCase(val) {
|
|
161
|
+
return isString(val) ? val.toUpperCase() : val;
|
|
162
|
+
}
|
|
155
163
|
/**
|
|
156
164
|
* Deep copy version of Object.assign using recursion.
|
|
157
165
|
* There are some assumptions here. It's for internal use and we don't need verbose errors
|
|
@@ -179,21 +187,10 @@ export function merge(target, source) {
|
|
|
179
187
|
});
|
|
180
188
|
if (rest && rest.length) {
|
|
181
189
|
var nextSource = rest.splice(0, 1)[0];
|
|
182
|
-
res = merge.apply(void 0,
|
|
190
|
+
res = merge.apply(void 0, __spreadArray([res, nextSource], rest, false));
|
|
183
191
|
}
|
|
184
192
|
return res;
|
|
185
193
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Shallow clone an object
|
|
188
|
-
*/
|
|
189
|
-
export function shallowClone(obj) {
|
|
190
|
-
var keys = Object.keys(obj);
|
|
191
|
-
var output = {};
|
|
192
|
-
for (var i = 0; i < keys.length; i++) {
|
|
193
|
-
output[keys[i]] = obj[keys[i]];
|
|
194
|
-
}
|
|
195
|
-
return output;
|
|
196
|
-
}
|
|
197
194
|
/**
|
|
198
195
|
* Checks if the target string starts with the sub string.
|
|
199
196
|
*/
|
package/esm/utils/lang/maps.js
CHANGED
|
@@ -68,4 +68,17 @@ var MapPoly = /** @class */ (function () {
|
|
|
68
68
|
return MapPoly;
|
|
69
69
|
}());
|
|
70
70
|
export { MapPoly };
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
|
|
73
|
+
* a ponyfill with minimal features is returned instead.
|
|
74
|
+
*
|
|
75
|
+
* Exported for testing purposes only.
|
|
76
|
+
*/
|
|
77
|
+
export function __getMapConstructor() {
|
|
78
|
+
// eslint-disable-next-line compat/compat
|
|
79
|
+
if (typeof Array.from === 'function' && typeof Map === 'function' && Map.prototype && Map.prototype.values) {
|
|
80
|
+
return Map;
|
|
81
|
+
}
|
|
82
|
+
return MapPoly;
|
|
83
|
+
}
|
|
84
|
+
export var _Map = __getMapConstructor();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Deprecated hashing function, used for split bucketing. Replaced by murmur3
|
|
2
|
+
//
|
|
3
|
+
// JAVA reference implementation for the hashing function.
|
|
4
|
+
//
|
|
5
|
+
// int h = 0;
|
|
6
|
+
// for (int i = 0; i < key.length(); i++) {
|
|
7
|
+
// h = 31 * h + key.charAt(i);
|
|
8
|
+
// }
|
|
9
|
+
// return h ^ seed; // XOR the hash and seed
|
|
10
|
+
//
|
|
11
|
+
function ToInteger(x) {
|
|
12
|
+
x = Number(x);
|
|
13
|
+
return x < 0 ? Math.ceil(x) : Math.floor(x);
|
|
14
|
+
}
|
|
15
|
+
function modulo(a, b) {
|
|
16
|
+
return a - Math.floor(a / b) * b;
|
|
17
|
+
}
|
|
18
|
+
function ToUint32(x) {
|
|
19
|
+
return modulo(ToInteger(x), Math.pow(2, 32));
|
|
20
|
+
}
|
|
21
|
+
function ToInt32(x) {
|
|
22
|
+
var uint32 = ToUint32(x);
|
|
23
|
+
if (uint32 >= Math.pow(2, 31)) {
|
|
24
|
+
return uint32 - Math.pow(2, 32);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return uint32;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function hash(str, seed) {
|
|
31
|
+
var h = 0;
|
|
32
|
+
for (var i = 0; i < str.length; i++) {
|
|
33
|
+
h = ToInt32(ToInt32(31 * h) + str.charCodeAt(i));
|
|
34
|
+
}
|
|
35
|
+
return ToInt32(h ^ seed);
|
|
36
|
+
}
|
|
37
|
+
export function bucket(str, seed) {
|
|
38
|
+
return Math.abs(hash(str, seed) % 100) + 1;
|
|
39
|
+
}
|
|
@@ -3,7 +3,7 @@ export function timeout(ms, promise) {
|
|
|
3
3
|
return promise;
|
|
4
4
|
return new Promise(function (resolve, reject) {
|
|
5
5
|
var tid = setTimeout(function () {
|
|
6
|
-
reject(new Error("Operation timed out because it exceeded the configured time limit of " + ms + "ms."));
|
|
6
|
+
reject(new Error("Operation timed out because it exceeded the configured time limit of " + ms + " ms."));
|
|
7
7
|
}, ms);
|
|
8
8
|
promise.then(function (res) {
|
|
9
9
|
clearTimeout(tid);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
|
|
2
|
+
import { CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN } from '../constants';
|
|
3
|
+
import { stringToUpperCase } from '../lang';
|
|
4
|
+
var userConsentValues = [CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN];
|
|
5
|
+
export function validateConsent(_a) {
|
|
6
|
+
var userConsent = _a.userConsent, log = _a.log;
|
|
7
|
+
userConsent = stringToUpperCase(userConsent);
|
|
8
|
+
if (userConsentValues.indexOf(userConsent) > -1)
|
|
9
|
+
return userConsent;
|
|
10
|
+
log.error(ERROR_INVALID_CONFIG_PARAM, ['userConsent', userConsentValues, CONSENT_GRANTED]);
|
|
11
|
+
return CONSENT_GRANTED;
|
|
12
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
|
|
2
2
|
import { DEBUG, OPTIMIZED } from '../constants';
|
|
3
|
+
import { stringToUpperCase } from '../lang';
|
|
3
4
|
export function validImpressionsMode(log, impressionsMode) {
|
|
4
|
-
impressionsMode = impressionsMode
|
|
5
|
-
if ([DEBUG, OPTIMIZED].indexOf(impressionsMode)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return impressionsMode;
|
|
5
|
+
impressionsMode = stringToUpperCase(impressionsMode);
|
|
6
|
+
if ([DEBUG, OPTIMIZED].indexOf(impressionsMode) > -1)
|
|
7
|
+
return impressionsMode;
|
|
8
|
+
log.error(ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [DEBUG, OPTIMIZED], OPTIMIZED]);
|
|
9
|
+
return OPTIMIZED;
|
|
10
10
|
}
|