@openobserve/browser-core 0.2.11 → 0.2.12-beta.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/package.json +6 -5
- package/src/boot/displayAlreadyInitializedError.ts +8 -0
- package/src/boot/init.ts +29 -15
- package/src/browser/addEventListener.ts +44 -35
- package/src/browser/{types.ts → browser.types.ts} +42 -0
- package/src/browser/cookie.ts +69 -15
- package/src/browser/fetchObservable.ts +97 -42
- package/src/browser/{pageExitObservable.ts → pageMayExitObservable.ts} +11 -24
- package/src/browser/runOnReadyState.ts +14 -4
- package/src/browser/xhrObservable.ts +45 -38
- package/src/domain/allowedTrackingOrigins.ts +30 -0
- package/src/domain/bufferedData.ts +32 -0
- package/src/domain/configuration/configuration.ts +366 -95
- package/src/domain/configuration/endpointBuilder.ts +48 -64
- package/src/domain/configuration/index.ts +6 -4
- package/src/domain/configuration/transportConfiguration.ts +42 -35
- package/src/domain/connectivity/connectivity.ts +31 -0
- package/src/domain/connectivity/index.ts +1 -0
- package/src/domain/console/consoleObservable.ts +59 -27
- package/src/domain/context/contextConstants.ts +27 -0
- package/src/domain/context/contextManager.ts +85 -0
- package/src/domain/context/contextUtils.ts +14 -0
- package/src/domain/context/defineContextMethod.ts +31 -0
- package/src/domain/context/storeContextManager.ts +55 -0
- package/src/domain/contexts/accountContext.ts +47 -0
- package/src/domain/contexts/globalContext.ts +30 -0
- package/src/domain/contexts/rumInternalContext.type.ts +15 -0
- package/src/domain/contexts/userContext.ts +64 -0
- package/src/domain/deflate/{types.ts → deflate.types.ts} +18 -2
- package/src/domain/deflate/index.ts +1 -1
- package/src/domain/error/error.ts +28 -84
- package/src/domain/error/error.types.ts +21 -4
- package/src/domain/error/trackRuntimeError.ts +37 -8
- package/src/domain/eventRateLimiter/createEventRateLimiter.ts +5 -2
- package/src/domain/extension/extensionUtils.ts +28 -0
- package/src/domain/intakeSites.ts +18 -0
- package/src/domain/report/browser.types.ts +12 -0
- package/src/domain/report/reportObservable.ts +37 -30
- package/src/domain/resourceUtils.ts +20 -16
- package/src/domain/session/README.md +193 -0
- package/src/domain/session/oldCookiesMigration.ts +7 -7
- package/src/domain/session/sessionConstants.ts +16 -1
- package/src/domain/session/sessionManager.ts +179 -15
- package/src/domain/session/sessionState.ts +49 -17
- package/src/domain/session/sessionStateValidation.ts +9 -0
- package/src/domain/session/sessionStore.ts +118 -55
- package/src/domain/session/sessionStoreOperations.ts +51 -32
- package/src/domain/session/storeStrategies/sessionInCookie.ts +113 -23
- package/src/domain/session/storeStrategies/sessionInLocalStorage.ts +11 -8
- package/src/domain/session/storeStrategies/sessionStoreStrategy.ts +6 -2
- package/src/domain/synthetics/syntheticsWorkerValues.ts +15 -4
- package/src/domain/tags.ts +76 -0
- package/src/domain/telemetry/index.ts +12 -4
- package/src/domain/telemetry/rawTelemetryEvent.types.ts +11 -3
- package/src/domain/telemetry/telemetry.ts +242 -98
- package/src/domain/telemetry/telemetryEvent.types.ts +530 -5
- package/src/domain/trackingConsent.ts +34 -0
- package/src/index.ts +92 -55
- package/src/tools/abstractHooks.ts +72 -0
- package/src/tools/abstractLifeCycle.ts +1 -0
- package/src/tools/boundedBuffer.ts +36 -8
- package/src/tools/display.ts +18 -13
- package/src/tools/encoder.ts +103 -0
- package/src/tools/experimentalFeatures.ts +18 -9
- package/src/tools/getZoneJsOriginalValue.ts +1 -1
- package/src/tools/{getGlobalObject.ts → globalObject.ts} +20 -0
- package/src/tools/instrumentMethod.ts +127 -66
- package/src/tools/matchOption.ts +1 -2
- package/src/tools/mergeInto.ts +16 -16
- package/src/tools/monitor.ts +14 -10
- package/src/tools/observable.ts +79 -15
- package/src/tools/queueMicrotask.ts +13 -0
- package/src/tools/readBytesFromStream.ts +24 -64
- package/src/tools/requestIdleCallback.ts +40 -0
- package/src/tools/sendToExtension.ts +3 -1
- package/src/tools/serialisation/context.ts +4 -1
- package/src/tools/serialisation/sanitize.ts +32 -14
- package/src/tools/stackTrace/computeStackTrace.ts +250 -0
- package/src/tools/stackTrace/handlingStack.ts +48 -0
- package/src/tools/taskQueue.ts +63 -0
- package/src/tools/timer.ts +1 -1
- package/src/tools/utils/arrayUtils.ts +11 -3
- package/src/tools/utils/browserDetection.ts +35 -3
- package/src/tools/utils/byteUtils.ts +13 -2
- package/src/tools/utils/functionUtils.ts +0 -2
- package/src/tools/utils/numberUtils.ts +2 -1
- package/src/tools/utils/objectUtils.ts +1 -3
- package/src/tools/utils/polyfills.ts +6 -110
- package/src/tools/utils/responseUtils.ts +1 -1
- package/src/tools/utils/stringUtils.ts +62 -4
- package/src/tools/utils/timeUtils.ts +18 -13
- package/src/tools/utils/timezone.ts +9 -0
- package/src/tools/utils/urlPolyfill.ts +29 -59
- package/src/tools/valueHistory.ts +66 -35
- package/src/transport/batch.ts +113 -61
- package/src/transport/eventBridge.ts +24 -5
- package/src/transport/flushController.ts +44 -23
- package/src/transport/httpRequest.ts +99 -71
- package/src/transport/index.ts +7 -4
- package/src/transport/sendWithRetryStrategy.ts +60 -41
- package/cjs/boot/init.d.ts +0 -5
- package/cjs/boot/init.js +0 -36
- package/cjs/boot/init.js.map +0 -1
- package/cjs/browser/addEventListener.d.ts +0 -76
- package/cjs/browser/addEventListener.js +0 -52
- package/cjs/browser/addEventListener.js.map +0 -1
- package/cjs/browser/cookie.d.ts +0 -10
- package/cjs/browser/cookie.js +0 -69
- package/cjs/browser/cookie.js.map +0 -1
- package/cjs/browser/fetchObservable.d.ts +0 -23
- package/cjs/browser/fetchObservable.js +0 -74
- package/cjs/browser/fetchObservable.js.map +0 -1
- package/cjs/browser/pageExitObservable.d.ts +0 -14
- package/cjs/browser/pageExitObservable.js +0 -58
- package/cjs/browser/pageExitObservable.js.map +0 -1
- package/cjs/browser/runOnReadyState.d.ts +0 -2
- package/cjs/browser/runOnReadyState.js +0 -15
- package/cjs/browser/runOnReadyState.js.map +0 -1
- package/cjs/browser/types.d.ts +0 -19
- package/cjs/browser/types.js +0 -6
- package/cjs/browser/types.js.map +0 -1
- package/cjs/browser/xhrObservable.d.ts +0 -22
- package/cjs/browser/xhrObservable.js +0 -93
- package/cjs/browser/xhrObservable.js.map +0 -1
- package/cjs/domain/configuration/configuration.d.ts +0 -67
- package/cjs/domain/configuration/configuration.js +0 -95
- package/cjs/domain/configuration/configuration.js.map +0 -1
- package/cjs/domain/configuration/endpointBuilder.d.ts +0 -14
- package/cjs/domain/configuration/endpointBuilder.js +0 -94
- package/cjs/domain/configuration/endpointBuilder.js.map +0 -1
- package/cjs/domain/configuration/index.d.ts +0 -3
- package/cjs/domain/configuration/index.js +0 -25
- package/cjs/domain/configuration/index.js.map +0 -1
- package/cjs/domain/configuration/intakeSites.d.ts +0 -5
- package/cjs/domain/configuration/intakeSites.js +0 -9
- package/cjs/domain/configuration/intakeSites.js.map +0 -1
- package/cjs/domain/configuration/tags.d.ts +0 -4
- package/cjs/domain/configuration/tags.js +0 -39
- package/cjs/domain/configuration/tags.js.map +0 -1
- package/cjs/domain/configuration/transportConfiguration.d.ts +0 -16
- package/cjs/domain/configuration/transportConfiguration.js +0 -42
- package/cjs/domain/configuration/transportConfiguration.js.map +0 -1
- package/cjs/domain/console/consoleObservable.d.ts +0 -11
- package/cjs/domain/console/consoleObservable.js +0 -75
- package/cjs/domain/console/consoleObservable.js.map +0 -1
- package/cjs/domain/deflate/index.d.ts +0 -1
- package/cjs/domain/deflate/index.js +0 -18
- package/cjs/domain/deflate/index.js.map +0 -1
- package/cjs/domain/deflate/types.d.ts +0 -26
- package/cjs/domain/deflate/types.js +0 -3
- package/cjs/domain/deflate/types.js.map +0 -1
- package/cjs/domain/error/error.d.ts +0 -28
- package/cjs/domain/error/error.js +0 -131
- package/cjs/domain/error/error.js.map +0 -1
- package/cjs/domain/error/error.types.d.ts +0 -40
- package/cjs/domain/error/error.types.js +0 -13
- package/cjs/domain/error/error.types.js.map +0 -1
- package/cjs/domain/error/trackRuntimeError.d.ts +0 -5
- package/cjs/domain/error/trackRuntimeError.js +0 -21
- package/cjs/domain/error/trackRuntimeError.js.map +0 -1
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.d.ts +0 -5
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.js +0 -40
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.js.map +0 -1
- package/cjs/domain/report/browser.types.d.ts +0 -24
- package/cjs/domain/report/browser.types.js +0 -3
- package/cjs/domain/report/browser.types.js.map +0 -1
- package/cjs/domain/report/reportObservable.d.ts +0 -15
- package/cjs/domain/report/reportObservable.js +0 -94
- package/cjs/domain/report/reportObservable.js.map +0 -1
- package/cjs/domain/resourceUtils.d.ts +0 -16
- package/cjs/domain/resourceUtils.js +0 -3
- package/cjs/domain/resourceUtils.js.map +0 -1
- package/cjs/domain/session/oldCookiesMigration.d.ts +0 -11
- package/cjs/domain/session/oldCookiesMigration.js +0 -40
- package/cjs/domain/session/oldCookiesMigration.js.map +0 -1
- package/cjs/domain/session/sessionConstants.d.ts +0 -2
- package/cjs/domain/session/sessionConstants.js +0 -7
- package/cjs/domain/session/sessionConstants.js.map +0 -1
- package/cjs/domain/session/sessionManager.d.ts +0 -20
- package/cjs/domain/session/sessionManager.js +0 -65
- package/cjs/domain/session/sessionManager.js.map +0 -1
- package/cjs/domain/session/sessionState.d.ts +0 -11
- package/cjs/domain/session/sessionState.js +0 -45
- package/cjs/domain/session/sessionState.js.map +0 -1
- package/cjs/domain/session/sessionStore.d.ts +0 -34
- package/cjs/domain/session/sessionStore.js +0 -144
- package/cjs/domain/session/sessionStore.js.map +0 -1
- package/cjs/domain/session/sessionStoreOperations.d.ts +0 -15
- package/cjs/domain/session/sessionStoreOperations.js +0 -104
- package/cjs/domain/session/sessionStoreOperations.js.map +0 -1
- package/cjs/domain/session/storeStrategies/sessionInCookie.d.ts +0 -6
- package/cjs/domain/session/storeStrategies/sessionInCookie.js +0 -48
- package/cjs/domain/session/storeStrategies/sessionInCookie.js.map +0 -1
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.d.ts +0 -3
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js +0 -40
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js.map +0 -1
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.d.ts +0 -14
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.js +0 -5
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.js.map +0 -1
- package/cjs/domain/synthetics/syntheticsWorkerValues.d.ts +0 -11
- package/cjs/domain/synthetics/syntheticsWorkerValues.js +0 -22
- package/cjs/domain/synthetics/syntheticsWorkerValues.js.map +0 -1
- package/cjs/domain/telemetry/index.d.ts +0 -3
- package/cjs/domain/telemetry/index.js +0 -28
- package/cjs/domain/telemetry/index.js.map +0 -1
- package/cjs/domain/telemetry/rawTelemetryEvent.types.d.ts +0 -11
- package/cjs/domain/telemetry/rawTelemetryEvent.types.js +0 -8
- package/cjs/domain/telemetry/rawTelemetryEvent.types.js.map +0 -1
- package/cjs/domain/telemetry/telemetry.d.ts +0 -112
- package/cjs/domain/telemetry/telemetry.js +0 -146
- package/cjs/domain/telemetry/telemetry.js.map +0 -1
- package/cjs/domain/telemetry/telemetryEvent.types.d.ts +0 -375
- package/cjs/domain/telemetry/telemetryEvent.types.js +0 -7
- package/cjs/domain/telemetry/telemetryEvent.types.js.map +0 -1
- package/cjs/domain/tracekit/computeStackTrace.d.ts +0 -5
- package/cjs/domain/tracekit/computeStackTrace.js +0 -118
- package/cjs/domain/tracekit/computeStackTrace.js.map +0 -1
- package/cjs/domain/tracekit/index.d.ts +0 -3
- package/cjs/domain/tracekit/index.js +0 -8
- package/cjs/domain/tracekit/index.js.map +0 -1
- package/cjs/domain/tracekit/tracekit.d.ts +0 -35
- package/cjs/domain/tracekit/tracekit.js +0 -95
- package/cjs/domain/tracekit/tracekit.js.map +0 -1
- package/cjs/domain/tracekit/types.d.ts +0 -44
- package/cjs/domain/tracekit/types.js +0 -3
- package/cjs/domain/tracekit/types.js.map +0 -1
- package/cjs/domain/user/index.d.ts +0 -2
- package/cjs/domain/user/index.js +0 -19
- package/cjs/domain/user/index.js.map +0 -1
- package/cjs/domain/user/user.d.ts +0 -12
- package/cjs/domain/user/user.js +0 -35
- package/cjs/domain/user/user.js.map +0 -1
- package/cjs/domain/user/user.types.d.ts +0 -6
- package/cjs/domain/user/user.types.js +0 -3
- package/cjs/domain/user/user.types.js.map +0 -1
- package/cjs/index.d.ts +0 -63
- package/cjs/index.js +0 -155
- package/cjs/index.js.map +0 -1
- package/cjs/tools/abstractLifeCycle.d.ts +0 -23
- package/cjs/tools/abstractLifeCycle.js +0 -29
- package/cjs/tools/abstractLifeCycle.js.map +0 -1
- package/cjs/tools/boundedBuffer.d.ts +0 -5
- package/cjs/tools/boundedBuffer.js +0 -22
- package/cjs/tools/boundedBuffer.js.map +0 -1
- package/cjs/tools/catchUserErrors.d.ts +0 -1
- package/cjs/tools/catchUserErrors.js +0 -20
- package/cjs/tools/catchUserErrors.js.map +0 -1
- package/cjs/tools/display.d.ts +0 -35
- package/cjs/tools/display.js +0 -45
- package/cjs/tools/display.js.map +0 -1
- package/cjs/tools/experimentalFeatures.d.ts +0 -24
- package/cjs/tools/experimentalFeatures.js +0 -47
- package/cjs/tools/experimentalFeatures.js.map +0 -1
- package/cjs/tools/getGlobalObject.d.ts +0 -4
- package/cjs/tools/getGlobalObject.js +0 -37
- package/cjs/tools/getGlobalObject.js.map +0 -1
- package/cjs/tools/getZoneJsOriginalValue.d.ts +0 -19
- package/cjs/tools/getZoneJsOriginalValue.js +0 -30
- package/cjs/tools/getZoneJsOriginalValue.js.map +0 -1
- package/cjs/tools/instrumentMethod.d.ts +0 -19
- package/cjs/tools/instrumentMethod.js +0 -83
- package/cjs/tools/instrumentMethod.js.map +0 -1
- package/cjs/tools/matchOption.d.ts +0 -8
- package/cjs/tools/matchOption.js +0 -38
- package/cjs/tools/matchOption.js.map +0 -1
- package/cjs/tools/mergeInto.d.ts +0 -25
- package/cjs/tools/mergeInto.js +0 -105
- package/cjs/tools/mergeInto.js.map +0 -1
- package/cjs/tools/monitor.d.ts +0 -9
- package/cjs/tools/monitor.js +0 -76
- package/cjs/tools/monitor.js.map +0 -1
- package/cjs/tools/observable.d.ts +0 -12
- package/cjs/tools/observable.js +0 -44
- package/cjs/tools/observable.js.map +0 -1
- package/cjs/tools/readBytesFromStream.d.ts +0 -11
- package/cjs/tools/readBytesFromStream.js +0 -64
- package/cjs/tools/readBytesFromStream.js.map +0 -1
- package/cjs/tools/sendToExtension.d.ts +0 -3
- package/cjs/tools/sendToExtension.js +0 -11
- package/cjs/tools/sendToExtension.js.map +0 -1
- package/cjs/tools/serialisation/context.d.ts +0 -6
- package/cjs/tools/serialisation/context.js +0 -3
- package/cjs/tools/serialisation/context.js.map +0 -1
- package/cjs/tools/serialisation/contextManager.d.ts +0 -21
- package/cjs/tools/serialisation/contextManager.js +0 -70
- package/cjs/tools/serialisation/contextManager.js.map +0 -1
- package/cjs/tools/serialisation/heavyCustomerDataWarning.d.ts +0 -8
- package/cjs/tools/serialisation/heavyCustomerDataWarning.js +0 -18
- package/cjs/tools/serialisation/heavyCustomerDataWarning.js.map +0 -1
- package/cjs/tools/serialisation/jsonStringify.d.ts +0 -14
- package/cjs/tools/serialisation/jsonStringify.js +0 -49
- package/cjs/tools/serialisation/jsonStringify.js.map +0 -1
- package/cjs/tools/serialisation/sanitize.d.ts +0 -18
- package/cjs/tools/serialisation/sanitize.js +0 -185
- package/cjs/tools/serialisation/sanitize.js.map +0 -1
- package/cjs/tools/timer.d.ts +0 -5
- package/cjs/tools/timer.js +0 -23
- package/cjs/tools/timer.js.map +0 -1
- package/cjs/tools/utils/arrayUtils.d.ts +0 -1
- package/cjs/tools/utils/arrayUtils.js +0 -11
- package/cjs/tools/utils/arrayUtils.js.map +0 -1
- package/cjs/tools/utils/browserDetection.d.ts +0 -2
- package/cjs/tools/utils/browserDetection.js +0 -12
- package/cjs/tools/utils/browserDetection.js.map +0 -1
- package/cjs/tools/utils/byteUtils.d.ts +0 -4
- package/cjs/tools/utils/byteUtils.js +0 -31
- package/cjs/tools/utils/byteUtils.js.map +0 -1
- package/cjs/tools/utils/functionUtils.d.ts +0 -9
- package/cjs/tools/utils/functionUtils.js +0 -48
- package/cjs/tools/utils/functionUtils.js.map +0 -1
- package/cjs/tools/utils/numberUtils.d.ts +0 -8
- package/cjs/tools/utils/numberUtils.js +0 -24
- package/cjs/tools/utils/numberUtils.js.map +0 -1
- package/cjs/tools/utils/objectUtils.d.ts +0 -10
- package/cjs/tools/utils/objectUtils.js +0 -26
- package/cjs/tools/utils/objectUtils.js.map +0 -1
- package/cjs/tools/utils/polyfills.d.ts +0 -24
- package/cjs/tools/utils/polyfills.js +0 -110
- package/cjs/tools/utils/polyfills.js.map +0 -1
- package/cjs/tools/utils/responseUtils.d.ts +0 -2
- package/cjs/tools/utils/responseUtils.js +0 -18
- package/cjs/tools/utils/responseUtils.js.map +0 -1
- package/cjs/tools/utils/stringUtils.d.ts +0 -7
- package/cjs/tools/utils/stringUtils.js +0 -32
- package/cjs/tools/utils/stringUtils.js.map +0 -1
- package/cjs/tools/utils/timeUtils.d.ts +0 -57
- package/cjs/tools/utils/timeUtils.js +0 -99
- package/cjs/tools/utils/timeUtils.js.map +0 -1
- package/cjs/tools/utils/typeUtils.d.ts +0 -4
- package/cjs/tools/utils/typeUtils.js +0 -17
- package/cjs/tools/utils/typeUtils.js.map +0 -1
- package/cjs/tools/utils/urlPolyfill.d.ts +0 -14
- package/cjs/tools/utils/urlPolyfill.js +0 -92
- package/cjs/tools/utils/urlPolyfill.js.map +0 -1
- package/cjs/tools/valueHistory.d.ts +0 -50
- package/cjs/tools/valueHistory.js +0 -106
- package/cjs/tools/valueHistory.js.map +0 -1
- package/cjs/transport/batch.d.ts +0 -19
- package/cjs/transport/batch.js +0 -79
- package/cjs/transport/batch.js.map +0 -1
- package/cjs/transport/eventBridge.d.ts +0 -12
- package/cjs/transport/eventBridge.js +0 -34
- package/cjs/transport/eventBridge.js.map +0 -1
- package/cjs/transport/flushController.d.ts +0 -48
- package/cjs/transport/flushController.js +0 -97
- package/cjs/transport/flushController.js.map +0 -1
- package/cjs/transport/httpRequest.d.ts +0 -37
- package/cjs/transport/httpRequest.js +0 -91
- package/cjs/transport/httpRequest.js.map +0 -1
- package/cjs/transport/index.d.ts +0 -4
- package/cjs/transport/index.js +0 -13
- package/cjs/transport/index.js.map +0 -1
- package/cjs/transport/sendWithRetryStrategy.d.ts +0 -39
- package/cjs/transport/sendWithRetryStrategy.js +0 -151
- package/cjs/transport/sendWithRetryStrategy.js.map +0 -1
- package/cjs/transport/startBatchWithReplica.d.ts +0 -15
- package/cjs/transport/startBatchWithReplica.js +0 -37
- package/cjs/transport/startBatchWithReplica.js.map +0 -1
- package/esm/boot/init.d.ts +0 -5
- package/esm/boot/init.js +0 -31
- package/esm/boot/init.js.map +0 -1
- package/esm/browser/addEventListener.d.ts +0 -76
- package/esm/browser/addEventListener.js +0 -47
- package/esm/browser/addEventListener.js.map +0 -1
- package/esm/browser/cookie.d.ts +0 -10
- package/esm/browser/cookie.js +0 -61
- package/esm/browser/cookie.js.map +0 -1
- package/esm/browser/fetchObservable.d.ts +0 -23
- package/esm/browser/fetchObservable.js +0 -70
- package/esm/browser/fetchObservable.js.map +0 -1
- package/esm/browser/pageExitObservable.d.ts +0 -14
- package/esm/browser/pageExitObservable.js +0 -53
- package/esm/browser/pageExitObservable.js.map +0 -1
- package/esm/browser/runOnReadyState.d.ts +0 -2
- package/esm/browser/runOnReadyState.js +0 -11
- package/esm/browser/runOnReadyState.js.map +0 -1
- package/esm/browser/types.d.ts +0 -19
- package/esm/browser/types.js +0 -5
- package/esm/browser/types.js.map +0 -1
- package/esm/browser/xhrObservable.d.ts +0 -22
- package/esm/browser/xhrObservable.js +0 -89
- package/esm/browser/xhrObservable.js.map +0 -1
- package/esm/domain/configuration/configuration.d.ts +0 -67
- package/esm/domain/configuration/configuration.js +0 -90
- package/esm/domain/configuration/configuration.js.map +0 -1
- package/esm/domain/configuration/endpointBuilder.d.ts +0 -14
- package/esm/domain/configuration/endpointBuilder.js +0 -90
- package/esm/domain/configuration/endpointBuilder.js.map +0 -1
- package/esm/domain/configuration/index.d.ts +0 -3
- package/esm/domain/configuration/index.js +0 -4
- package/esm/domain/configuration/index.js.map +0 -1
- package/esm/domain/configuration/intakeSites.d.ts +0 -5
- package/esm/domain/configuration/intakeSites.js +0 -6
- package/esm/domain/configuration/intakeSites.js.map +0 -1
- package/esm/domain/configuration/tags.d.ts +0 -4
- package/esm/domain/configuration/tags.js +0 -34
- package/esm/domain/configuration/tags.js.map +0 -1
- package/esm/domain/configuration/transportConfiguration.d.ts +0 -16
- package/esm/domain/configuration/transportConfiguration.js +0 -38
- package/esm/domain/configuration/transportConfiguration.js.map +0 -1
- package/esm/domain/console/consoleObservable.d.ts +0 -11
- package/esm/domain/console/consoleObservable.js +0 -70
- package/esm/domain/console/consoleObservable.js.map +0 -1
- package/esm/domain/deflate/index.d.ts +0 -1
- package/esm/domain/deflate/index.js +0 -2
- package/esm/domain/deflate/index.js.map +0 -1
- package/esm/domain/deflate/types.d.ts +0 -26
- package/esm/domain/deflate/types.js +0 -2
- package/esm/domain/deflate/types.js.map +0 -1
- package/esm/domain/error/error.d.ts +0 -28
- package/esm/domain/error/error.js +0 -121
- package/esm/domain/error/error.js.map +0 -1
- package/esm/domain/error/error.types.d.ts +0 -40
- package/esm/domain/error/error.types.js +0 -10
- package/esm/domain/error/error.types.js.map +0 -1
- package/esm/domain/error/trackRuntimeError.d.ts +0 -5
- package/esm/domain/error/trackRuntimeError.js +0 -17
- package/esm/domain/error/trackRuntimeError.js.map +0 -1
- package/esm/domain/eventRateLimiter/createEventRateLimiter.d.ts +0 -5
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js +0 -36
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js.map +0 -1
- package/esm/domain/report/browser.types.d.ts +0 -24
- package/esm/domain/report/browser.types.js +0 -2
- package/esm/domain/report/browser.types.js.map +0 -1
- package/esm/domain/report/reportObservable.d.ts +0 -15
- package/esm/domain/report/reportObservable.js +0 -90
- package/esm/domain/report/reportObservable.js.map +0 -1
- package/esm/domain/resourceUtils.d.ts +0 -16
- package/esm/domain/resourceUtils.js +0 -2
- package/esm/domain/resourceUtils.js.map +0 -1
- package/esm/domain/session/oldCookiesMigration.d.ts +0 -11
- package/esm/domain/session/oldCookiesMigration.js +0 -36
- package/esm/domain/session/oldCookiesMigration.js.map +0 -1
- package/esm/domain/session/sessionConstants.d.ts +0 -2
- package/esm/domain/session/sessionConstants.js +0 -4
- package/esm/domain/session/sessionConstants.js.map +0 -1
- package/esm/domain/session/sessionManager.d.ts +0 -20
- package/esm/domain/session/sessionManager.js +0 -60
- package/esm/domain/session/sessionManager.js.map +0 -1
- package/esm/domain/session/sessionState.d.ts +0 -11
- package/esm/domain/session/sessionState.js +0 -38
- package/esm/domain/session/sessionState.js.map +0 -1
- package/esm/domain/session/sessionStore.d.ts +0 -34
- package/esm/domain/session/sessionStore.js +0 -139
- package/esm/domain/session/sessionStore.js.map +0 -1
- package/esm/domain/session/sessionStoreOperations.d.ts +0 -15
- package/esm/domain/session/sessionStoreOperations.js +0 -99
- package/esm/domain/session/sessionStoreOperations.js.map +0 -1
- package/esm/domain/session/storeStrategies/sessionInCookie.d.ts +0 -6
- package/esm/domain/session/storeStrategies/sessionInCookie.js +0 -42
- package/esm/domain/session/storeStrategies/sessionInCookie.js.map +0 -1
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.d.ts +0 -3
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js +0 -35
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js.map +0 -1
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.d.ts +0 -14
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js +0 -2
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js.map +0 -1
- package/esm/domain/synthetics/syntheticsWorkerValues.d.ts +0 -11
- package/esm/domain/synthetics/syntheticsWorkerValues.js +0 -16
- package/esm/domain/synthetics/syntheticsWorkerValues.js.map +0 -1
- package/esm/domain/telemetry/index.d.ts +0 -3
- package/esm/domain/telemetry/index.js +0 -4
- package/esm/domain/telemetry/index.js.map +0 -1
- package/esm/domain/telemetry/rawTelemetryEvent.types.d.ts +0 -11
- package/esm/domain/telemetry/rawTelemetryEvent.types.js +0 -5
- package/esm/domain/telemetry/rawTelemetryEvent.types.js.map +0 -1
- package/esm/domain/telemetry/telemetry.d.ts +0 -112
- package/esm/domain/telemetry/telemetry.js +0 -134
- package/esm/domain/telemetry/telemetry.js.map +0 -1
- package/esm/domain/telemetry/telemetryEvent.types.d.ts +0 -375
- package/esm/domain/telemetry/telemetryEvent.types.js +0 -6
- package/esm/domain/telemetry/telemetryEvent.types.js.map +0 -1
- package/esm/domain/tracekit/computeStackTrace.d.ts +0 -5
- package/esm/domain/tracekit/computeStackTrace.js +0 -114
- package/esm/domain/tracekit/computeStackTrace.js.map +0 -1
- package/esm/domain/tracekit/index.d.ts +0 -3
- package/esm/domain/tracekit/index.js +0 -3
- package/esm/domain/tracekit/index.js.map +0 -1
- package/esm/domain/tracekit/tracekit.d.ts +0 -35
- package/esm/domain/tracekit/tracekit.js +0 -91
- package/esm/domain/tracekit/tracekit.js.map +0 -1
- package/esm/domain/tracekit/types.d.ts +0 -44
- package/esm/domain/tracekit/types.js +0 -2
- package/esm/domain/tracekit/types.js.map +0 -1
- package/esm/domain/user/index.d.ts +0 -2
- package/esm/domain/user/index.js +0 -3
- package/esm/domain/user/index.js.map +0 -1
- package/esm/domain/user/user.d.ts +0 -12
- package/esm/domain/user/user.js +0 -30
- package/esm/domain/user/user.js.map +0 -1
- package/esm/domain/user/user.types.d.ts +0 -6
- package/esm/domain/user/user.types.js +0 -2
- package/esm/domain/user/user.types.js.map +0 -1
- package/esm/index.d.ts +0 -63
- package/esm/index.js +0 -61
- package/esm/index.js.map +0 -1
- package/esm/tools/abstractLifeCycle.d.ts +0 -23
- package/esm/tools/abstractLifeCycle.js +0 -26
- package/esm/tools/abstractLifeCycle.js.map +0 -1
- package/esm/tools/boundedBuffer.d.ts +0 -5
- package/esm/tools/boundedBuffer.js +0 -19
- package/esm/tools/boundedBuffer.js.map +0 -1
- package/esm/tools/catchUserErrors.d.ts +0 -1
- package/esm/tools/catchUserErrors.js +0 -16
- package/esm/tools/catchUserErrors.js.map +0 -1
- package/esm/tools/display.d.ts +0 -35
- package/esm/tools/display.js +0 -41
- package/esm/tools/display.js.map +0 -1
- package/esm/tools/experimentalFeatures.d.ts +0 -24
- package/esm/tools/experimentalFeatures.js +0 -40
- package/esm/tools/experimentalFeatures.js.map +0 -1
- package/esm/tools/getGlobalObject.d.ts +0 -4
- package/esm/tools/getGlobalObject.js +0 -33
- package/esm/tools/getGlobalObject.js.map +0 -1
- package/esm/tools/getZoneJsOriginalValue.d.ts +0 -19
- package/esm/tools/getZoneJsOriginalValue.js +0 -26
- package/esm/tools/getZoneJsOriginalValue.js.map +0 -1
- package/esm/tools/instrumentMethod.d.ts +0 -19
- package/esm/tools/instrumentMethod.js +0 -77
- package/esm/tools/instrumentMethod.js.map +0 -1
- package/esm/tools/matchOption.d.ts +0 -8
- package/esm/tools/matchOption.js +0 -33
- package/esm/tools/matchOption.js.map +0 -1
- package/esm/tools/mergeInto.d.ts +0 -25
- package/esm/tools/mergeInto.js +0 -99
- package/esm/tools/mergeInto.js.map +0 -1
- package/esm/tools/monitor.d.ts +0 -9
- package/esm/tools/monitor.js +0 -66
- package/esm/tools/monitor.js.map +0 -1
- package/esm/tools/observable.d.ts +0 -12
- package/esm/tools/observable.js +0 -40
- package/esm/tools/observable.js.map +0 -1
- package/esm/tools/readBytesFromStream.d.ts +0 -11
- package/esm/tools/readBytesFromStream.js +0 -60
- package/esm/tools/readBytesFromStream.js.map +0 -1
- package/esm/tools/sendToExtension.d.ts +0 -3
- package/esm/tools/sendToExtension.js +0 -7
- package/esm/tools/sendToExtension.js.map +0 -1
- package/esm/tools/serialisation/context.d.ts +0 -6
- package/esm/tools/serialisation/context.js +0 -2
- package/esm/tools/serialisation/context.js.map +0 -1
- package/esm/tools/serialisation/contextManager.d.ts +0 -21
- package/esm/tools/serialisation/contextManager.js +0 -66
- package/esm/tools/serialisation/contextManager.js.map +0 -1
- package/esm/tools/serialisation/heavyCustomerDataWarning.d.ts +0 -8
- package/esm/tools/serialisation/heavyCustomerDataWarning.js +0 -14
- package/esm/tools/serialisation/heavyCustomerDataWarning.js.map +0 -1
- package/esm/tools/serialisation/jsonStringify.d.ts +0 -14
- package/esm/tools/serialisation/jsonStringify.js +0 -44
- package/esm/tools/serialisation/jsonStringify.js.map +0 -1
- package/esm/tools/serialisation/sanitize.d.ts +0 -18
- package/esm/tools/serialisation/sanitize.js +0 -181
- package/esm/tools/serialisation/sanitize.js.map +0 -1
- package/esm/tools/timer.d.ts +0 -5
- package/esm/tools/timer.js +0 -16
- package/esm/tools/timer.js.map +0 -1
- package/esm/tools/utils/arrayUtils.d.ts +0 -1
- package/esm/tools/utils/arrayUtils.js +0 -7
- package/esm/tools/utils/arrayUtils.js.map +0 -1
- package/esm/tools/utils/browserDetection.d.ts +0 -2
- package/esm/tools/utils/browserDetection.js +0 -7
- package/esm/tools/utils/browserDetection.js.map +0 -1
- package/esm/tools/utils/byteUtils.d.ts +0 -4
- package/esm/tools/utils/byteUtils.js +0 -26
- package/esm/tools/utils/byteUtils.js.map +0 -1
- package/esm/tools/utils/functionUtils.d.ts +0 -9
- package/esm/tools/utils/functionUtils.js +0 -43
- package/esm/tools/utils/functionUtils.js.map +0 -1
- package/esm/tools/utils/numberUtils.d.ts +0 -8
- package/esm/tools/utils/numberUtils.js +0 -17
- package/esm/tools/utils/numberUtils.js.map +0 -1
- package/esm/tools/utils/objectUtils.d.ts +0 -10
- package/esm/tools/utils/objectUtils.js +0 -19
- package/esm/tools/utils/objectUtils.js.map +0 -1
- package/esm/tools/utils/polyfills.d.ts +0 -24
- package/esm/tools/utils/polyfills.js +0 -95
- package/esm/tools/utils/polyfills.js.map +0 -1
- package/esm/tools/utils/responseUtils.d.ts +0 -2
- package/esm/tools/utils/responseUtils.js +0 -13
- package/esm/tools/utils/responseUtils.js.map +0 -1
- package/esm/tools/utils/stringUtils.d.ts +0 -7
- package/esm/tools/utils/stringUtils.js +0 -26
- package/esm/tools/utils/stringUtils.js.map +0 -1
- package/esm/tools/utils/timeUtils.d.ts +0 -57
- package/esm/tools/utils/timeUtils.js +0 -82
- package/esm/tools/utils/timeUtils.js.map +0 -1
- package/esm/tools/utils/typeUtils.d.ts +0 -4
- package/esm/tools/utils/typeUtils.js +0 -13
- package/esm/tools/utils/typeUtils.js.map +0 -1
- package/esm/tools/utils/urlPolyfill.d.ts +0 -14
- package/esm/tools/utils/urlPolyfill.js +0 -80
- package/esm/tools/utils/urlPolyfill.js.map +0 -1
- package/esm/tools/valueHistory.d.ts +0 -50
- package/esm/tools/valueHistory.js +0 -103
- package/esm/tools/valueHistory.js.map +0 -1
- package/esm/transport/batch.d.ts +0 -19
- package/esm/transport/batch.js +0 -76
- package/esm/transport/batch.js.map +0 -1
- package/esm/transport/eventBridge.d.ts +0 -12
- package/esm/transport/eventBridge.js +0 -29
- package/esm/transport/eventBridge.js.map +0 -1
- package/esm/transport/flushController.d.ts +0 -48
- package/esm/transport/flushController.js +0 -93
- package/esm/transport/flushController.js.map +0 -1
- package/esm/transport/httpRequest.d.ts +0 -37
- package/esm/transport/httpRequest.js +0 -85
- package/esm/transport/httpRequest.js.map +0 -1
- package/esm/transport/index.d.ts +0 -4
- package/esm/transport/index.js +0 -5
- package/esm/transport/index.js.map +0 -1
- package/esm/transport/sendWithRetryStrategy.d.ts +0 -39
- package/esm/transport/sendWithRetryStrategy.js +0 -146
- package/esm/transport/sendWithRetryStrategy.js.map +0 -1
- package/esm/transport/startBatchWithReplica.d.ts +0 -15
- package/esm/transport/startBatchWithReplica.js +0 -33
- package/esm/transport/startBatchWithReplica.js.map +0 -1
- package/src/domain/configuration/intakeSites.ts +0 -5
- package/src/domain/configuration/tags.ts +0 -43
- package/src/domain/tracekit/computeStackTrace.ts +0 -141
- package/src/domain/tracekit/index.ts +0 -3
- package/src/domain/tracekit/tracekit.ts +0 -96
- package/src/domain/tracekit/types.ts +0 -47
- package/src/domain/user/index.ts +0 -2
- package/src/domain/user/user.ts +0 -33
- package/src/domain/user/user.types.ts +0 -6
- package/src/tools/serialisation/contextManager.ts +0 -79
- package/src/tools/serialisation/heavyCustomerDataWarning.ts +0 -26
- package/src/transport/startBatchWithReplica.ts +0 -52
|
@@ -1,32 +1,66 @@
|
|
|
1
1
|
import { isEmptyObject } from '../../tools/utils/objectUtils'
|
|
2
2
|
import { objectEntries } from '../../tools/utils/polyfills'
|
|
3
3
|
import { dateNow } from '../../tools/utils/timeUtils'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
4
|
+
import type { Configuration } from '../configuration'
|
|
5
|
+
import { SESSION_EXPIRATION_DELAY, SESSION_TIME_OUT_DELAY } from './sessionConstants'
|
|
6
|
+
import { isValidSessionString, SESSION_ENTRY_REGEXP, SESSION_ENTRY_SEPARATOR } from './sessionStateValidation'
|
|
7
|
+
export const EXPIRED = '1'
|
|
8
8
|
|
|
9
9
|
export interface SessionState {
|
|
10
10
|
id?: string
|
|
11
11
|
created?: string
|
|
12
12
|
expire?: string
|
|
13
|
-
|
|
13
|
+
isExpired?: typeof EXPIRED
|
|
14
14
|
|
|
15
15
|
[key: string]: string | undefined
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function
|
|
18
|
+
export function getExpiredSessionState(
|
|
19
|
+
previousSessionState: SessionState | undefined,
|
|
20
|
+
configuration: Configuration
|
|
21
|
+
): SessionState {
|
|
22
|
+
const expiredSessionState: SessionState = {
|
|
23
|
+
isExpired: EXPIRED,
|
|
24
|
+
}
|
|
25
|
+
if (configuration.trackAnonymousUser && previousSessionState?.anonymousId) {
|
|
26
|
+
expiredSessionState.anonymousId = previousSessionState?.anonymousId
|
|
27
|
+
}
|
|
28
|
+
return expiredSessionState
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isSessionInNotStartedState(session: SessionState) {
|
|
19
32
|
return isEmptyObject(session)
|
|
20
33
|
}
|
|
21
34
|
|
|
35
|
+
export function isSessionStarted(session: SessionState) {
|
|
36
|
+
return !isSessionInNotStartedState(session)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isSessionInExpiredState(session: SessionState) {
|
|
40
|
+
return session.isExpired !== undefined || !isActiveSession(session)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// An active session is a session in either `Tracked` or `NotTracked` state
|
|
44
|
+
function isActiveSession(sessionState: SessionState) {
|
|
45
|
+
// created and expire can be undefined for versions which was not storing them
|
|
46
|
+
// these checks could be removed when older versions will not be available/live anymore
|
|
47
|
+
return (
|
|
48
|
+
(sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) &&
|
|
49
|
+
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire))
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
22
53
|
export function expandSessionState(session: SessionState) {
|
|
23
54
|
session.expire = String(dateNow() + SESSION_EXPIRATION_DELAY)
|
|
24
55
|
}
|
|
25
56
|
|
|
26
57
|
export function toSessionString(session: SessionState) {
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
return (
|
|
59
|
+
objectEntries(session)
|
|
60
|
+
// we use `aid` as a key for anonymousId
|
|
61
|
+
.map(([key, value]) => (key === 'anonymousId' ? `aid=${value}` : `${key}=${value}`))
|
|
62
|
+
.join(SESSION_ENTRY_SEPARATOR)
|
|
63
|
+
)
|
|
30
64
|
}
|
|
31
65
|
|
|
32
66
|
export function toSessionState(sessionString: string | undefined | null) {
|
|
@@ -36,16 +70,14 @@ export function toSessionState(sessionString: string | undefined | null) {
|
|
|
36
70
|
const matches = SESSION_ENTRY_REGEXP.exec(entry)
|
|
37
71
|
if (matches !== null) {
|
|
38
72
|
const [, key, value] = matches
|
|
39
|
-
|
|
73
|
+
if (key === 'aid') {
|
|
74
|
+
// we use `aid` as a key for anonymousId
|
|
75
|
+
session.anonymousId = value
|
|
76
|
+
} else {
|
|
77
|
+
session[key] = value
|
|
78
|
+
}
|
|
40
79
|
}
|
|
41
80
|
})
|
|
42
81
|
}
|
|
43
82
|
return session
|
|
44
83
|
}
|
|
45
|
-
|
|
46
|
-
function isValidSessionString(sessionString: string | undefined | null): sessionString is string {
|
|
47
|
-
return (
|
|
48
|
-
!!sessionString &&
|
|
49
|
-
(sessionString.indexOf(SESSION_ENTRY_SEPARATOR) !== -1 || SESSION_ENTRY_REGEXP.test(sessionString))
|
|
50
|
-
)
|
|
51
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const SESSION_ENTRY_REGEXP = /^([a-zA-Z]+)=([a-z0-9-]+)$/
|
|
2
|
+
export const SESSION_ENTRY_SEPARATOR = '&'
|
|
3
|
+
|
|
4
|
+
export function isValidSessionString(sessionString: string | undefined | null): sessionString is string {
|
|
5
|
+
return (
|
|
6
|
+
!!sessionString &&
|
|
7
|
+
(sessionString.indexOf(SESSION_ENTRY_SEPARATOR) !== -1 || SESSION_ENTRY_REGEXP.test(sessionString))
|
|
8
|
+
)
|
|
9
|
+
}
|
|
@@ -3,22 +3,32 @@ import { Observable } from '../../tools/observable'
|
|
|
3
3
|
import { ONE_SECOND, dateNow } from '../../tools/utils/timeUtils'
|
|
4
4
|
import { throttle } from '../../tools/utils/functionUtils'
|
|
5
5
|
import { generateUUID } from '../../tools/utils/stringUtils'
|
|
6
|
-
import type { InitConfiguration } from '../configuration'
|
|
7
|
-
import {
|
|
6
|
+
import type { InitConfiguration, Configuration } from '../configuration'
|
|
7
|
+
import { display } from '../../tools/display'
|
|
8
8
|
import { selectCookieStrategy, initCookieStrategy } from './storeStrategies/sessionInCookie'
|
|
9
|
-
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy'
|
|
9
|
+
import type { SessionStoreStrategy, SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy'
|
|
10
10
|
import type { SessionState } from './sessionState'
|
|
11
|
+
import {
|
|
12
|
+
getExpiredSessionState,
|
|
13
|
+
isSessionInExpiredState,
|
|
14
|
+
isSessionInNotStartedState,
|
|
15
|
+
isSessionStarted,
|
|
16
|
+
} from './sessionState'
|
|
11
17
|
import { initLocalStorageStrategy, selectLocalStorageStrategy } from './storeStrategies/sessionInLocalStorage'
|
|
12
18
|
import { processSessionStoreOperations } from './sessionStoreOperations'
|
|
19
|
+
import { SESSION_NOT_TRACKED, SessionPersistence } from './sessionConstants'
|
|
13
20
|
|
|
14
21
|
export interface SessionStore {
|
|
15
22
|
expandOrRenewSession: () => void
|
|
16
23
|
expandSession: () => void
|
|
17
24
|
getSession: () => SessionState
|
|
25
|
+
restartSession: () => void
|
|
18
26
|
renewObservable: Observable<void>
|
|
19
27
|
expireObservable: Observable<void>
|
|
20
|
-
|
|
28
|
+
sessionStateUpdateObservable: Observable<{ previousState: SessionState; newState: SessionState }>
|
|
29
|
+
expire: (hasConsent?: boolean) => void
|
|
21
30
|
stop: () => void
|
|
31
|
+
updateSessionState: (state: Partial<SessionState>) => void
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
/**
|
|
@@ -29,17 +39,39 @@ export interface SessionStore {
|
|
|
29
39
|
export const STORAGE_POLL_DELAY = ONE_SECOND
|
|
30
40
|
|
|
31
41
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
42
|
+
* Selects the correct session store strategy type based on the configuration and storage
|
|
43
|
+
* availability.
|
|
34
44
|
*/
|
|
35
45
|
export function selectSessionStoreStrategyType(
|
|
36
46
|
initConfiguration: InitConfiguration
|
|
37
47
|
): SessionStoreStrategyType | undefined {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
switch (initConfiguration.sessionPersistence) {
|
|
49
|
+
case SessionPersistence.COOKIE:
|
|
50
|
+
return selectCookieStrategy(initConfiguration)
|
|
51
|
+
|
|
52
|
+
case SessionPersistence.LOCAL_STORAGE:
|
|
53
|
+
return selectLocalStorageStrategy()
|
|
54
|
+
|
|
55
|
+
case undefined: {
|
|
56
|
+
let sessionStoreStrategyType = selectCookieStrategy(initConfiguration)
|
|
57
|
+
if (!sessionStoreStrategyType && initConfiguration.allowFallbackToLocalStorage) {
|
|
58
|
+
sessionStoreStrategyType = selectLocalStorageStrategy()
|
|
59
|
+
}
|
|
60
|
+
return sessionStoreStrategyType
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
default:
|
|
64
|
+
display.error(`Invalid session persistence '${String(initConfiguration.sessionPersistence)}'`)
|
|
41
65
|
}
|
|
42
|
-
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getSessionStoreStrategy(
|
|
69
|
+
sessionStoreStrategyType: SessionStoreStrategyType,
|
|
70
|
+
configuration: Configuration
|
|
71
|
+
) {
|
|
72
|
+
return sessionStoreStrategyType.type === SessionPersistence.COOKIE
|
|
73
|
+
? initCookieStrategy(configuration, sessionStoreStrategyType.cookieOptions)
|
|
74
|
+
: initLocalStorageStrategy(configuration)
|
|
43
75
|
}
|
|
44
76
|
|
|
45
77
|
/**
|
|
@@ -50,32 +82,34 @@ export function selectSessionStoreStrategyType(
|
|
|
50
82
|
*/
|
|
51
83
|
export function startSessionStore<TrackingType extends string>(
|
|
52
84
|
sessionStoreStrategyType: SessionStoreStrategyType,
|
|
85
|
+
configuration: Configuration,
|
|
53
86
|
productKey: string,
|
|
54
|
-
|
|
87
|
+
computeTrackingType: (rawTrackingType?: string) => TrackingType,
|
|
88
|
+
sessionStoreStrategy: SessionStoreStrategy = getSessionStoreStrategy(sessionStoreStrategyType, configuration)
|
|
55
89
|
): SessionStore {
|
|
56
90
|
const renewObservable = new Observable<void>()
|
|
57
91
|
const expireObservable = new Observable<void>()
|
|
58
|
-
|
|
59
|
-
const sessionStoreStrategy =
|
|
60
|
-
sessionStoreStrategyType.type === 'Cookie'
|
|
61
|
-
? initCookieStrategy(sessionStoreStrategyType.cookieOptions)
|
|
62
|
-
: initLocalStorageStrategy()
|
|
63
|
-
const { clearSession, retrieveSession } = sessionStoreStrategy
|
|
92
|
+
const sessionStateUpdateObservable = new Observable<{ previousState: SessionState; newState: SessionState }>()
|
|
64
93
|
|
|
65
94
|
const watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY)
|
|
66
|
-
let sessionCache: SessionState
|
|
95
|
+
let sessionCache: SessionState
|
|
67
96
|
|
|
68
|
-
|
|
69
|
-
|
|
97
|
+
startSession()
|
|
98
|
+
|
|
99
|
+
const { throttled: throttledExpandOrRenewSession, cancel: cancelExpandOrRenewSession } = throttle(() => {
|
|
70
100
|
processSessionStoreOperations(
|
|
71
101
|
{
|
|
72
102
|
process: (sessionState) => {
|
|
103
|
+
if (isSessionInNotStartedState(sessionState)) {
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
73
107
|
const synchronizedSession = synchronizeSession(sessionState)
|
|
74
|
-
|
|
108
|
+
expandOrRenewSessionState(synchronizedSession)
|
|
75
109
|
return synchronizedSession
|
|
76
110
|
},
|
|
77
111
|
after: (sessionState) => {
|
|
78
|
-
if (
|
|
112
|
+
if (isSessionStarted(sessionState) && !hasSessionInCache()) {
|
|
79
113
|
renewSessionInCache(sessionState)
|
|
80
114
|
}
|
|
81
115
|
sessionCache = sessionState
|
|
@@ -83,7 +117,7 @@ export function startSessionStore<TrackingType extends string>(
|
|
|
83
117
|
},
|
|
84
118
|
sessionStoreStrategy
|
|
85
119
|
)
|
|
86
|
-
}
|
|
120
|
+
}, STORAGE_POLL_DELAY)
|
|
87
121
|
|
|
88
122
|
function expandSession() {
|
|
89
123
|
processSessionStoreOperations(
|
|
@@ -100,41 +134,70 @@ export function startSessionStore<TrackingType extends string>(
|
|
|
100
134
|
* - if the session is not active, clear the session store and expire the session cache
|
|
101
135
|
*/
|
|
102
136
|
function watchSession() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
137
|
+
const sessionState = sessionStoreStrategy.retrieveSession()
|
|
138
|
+
|
|
139
|
+
if (isSessionInExpiredState(sessionState)) {
|
|
140
|
+
processSessionStoreOperations(
|
|
141
|
+
{
|
|
142
|
+
process: (sessionState: SessionState) =>
|
|
143
|
+
isSessionInExpiredState(sessionState) ? getExpiredSessionState(sessionState, configuration) : undefined,
|
|
144
|
+
after: synchronizeSession,
|
|
145
|
+
},
|
|
146
|
+
sessionStoreStrategy
|
|
147
|
+
)
|
|
148
|
+
} else {
|
|
149
|
+
synchronizeSession(sessionState)
|
|
150
|
+
}
|
|
110
151
|
}
|
|
111
152
|
|
|
112
153
|
function synchronizeSession(sessionState: SessionState) {
|
|
113
|
-
if (
|
|
114
|
-
sessionState =
|
|
154
|
+
if (isSessionInExpiredState(sessionState)) {
|
|
155
|
+
sessionState = getExpiredSessionState(sessionState, configuration)
|
|
115
156
|
}
|
|
116
157
|
if (hasSessionInCache()) {
|
|
117
158
|
if (isSessionInCacheOutdated(sessionState)) {
|
|
118
159
|
expireSessionInCache()
|
|
119
160
|
} else {
|
|
161
|
+
sessionStateUpdateObservable.notify({ previousState: sessionCache, newState: sessionState })
|
|
120
162
|
sessionCache = sessionState
|
|
121
163
|
}
|
|
122
164
|
}
|
|
123
165
|
return sessionState
|
|
124
166
|
}
|
|
125
167
|
|
|
168
|
+
function startSession() {
|
|
169
|
+
processSessionStoreOperations(
|
|
170
|
+
{
|
|
171
|
+
process: (sessionState) => {
|
|
172
|
+
if (isSessionInNotStartedState(sessionState)) {
|
|
173
|
+
sessionState.anonymousId = generateUUID()
|
|
174
|
+
return getExpiredSessionState(sessionState, configuration)
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
after: (sessionState) => {
|
|
178
|
+
sessionCache = sessionState
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
sessionStoreStrategy
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
126
185
|
function expandOrRenewSessionState(sessionState: SessionState) {
|
|
127
|
-
|
|
186
|
+
if (isSessionInNotStartedState(sessionState)) {
|
|
187
|
+
return false
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const trackingType = computeTrackingType(sessionState[productKey])
|
|
128
191
|
sessionState[productKey] = trackingType
|
|
129
|
-
|
|
192
|
+
delete sessionState.isExpired
|
|
193
|
+
if (trackingType !== SESSION_NOT_TRACKED && !sessionState.id) {
|
|
130
194
|
sessionState.id = generateUUID()
|
|
131
195
|
sessionState.created = String(dateNow())
|
|
132
196
|
}
|
|
133
|
-
return isTracked
|
|
134
197
|
}
|
|
135
198
|
|
|
136
199
|
function hasSessionInCache() {
|
|
137
|
-
return sessionCache[productKey] !== undefined
|
|
200
|
+
return sessionCache?.[productKey] !== undefined
|
|
138
201
|
}
|
|
139
202
|
|
|
140
203
|
function isSessionInCacheOutdated(sessionState: SessionState) {
|
|
@@ -142,7 +205,7 @@ export function startSessionStore<TrackingType extends string>(
|
|
|
142
205
|
}
|
|
143
206
|
|
|
144
207
|
function expireSessionInCache() {
|
|
145
|
-
sessionCache =
|
|
208
|
+
sessionCache = getExpiredSessionState(sessionCache, configuration)
|
|
146
209
|
expireObservable.notify()
|
|
147
210
|
}
|
|
148
211
|
|
|
@@ -151,35 +214,35 @@ export function startSessionStore<TrackingType extends string>(
|
|
|
151
214
|
renewObservable.notify()
|
|
152
215
|
}
|
|
153
216
|
|
|
154
|
-
function
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
function isActiveSession(sessionState: SessionState) {
|
|
163
|
-
// created and expire can be undefined for versions which was not storing them
|
|
164
|
-
// these checks could be removed when older versions will not be available/live anymore
|
|
165
|
-
return (
|
|
166
|
-
(sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) &&
|
|
167
|
-
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire))
|
|
217
|
+
function updateSessionState(partialSessionState: Partial<SessionState>) {
|
|
218
|
+
processSessionStoreOperations(
|
|
219
|
+
{
|
|
220
|
+
process: (sessionState) => ({ ...sessionState, ...partialSessionState }),
|
|
221
|
+
after: synchronizeSession,
|
|
222
|
+
},
|
|
223
|
+
sessionStoreStrategy
|
|
168
224
|
)
|
|
169
225
|
}
|
|
170
226
|
|
|
171
227
|
return {
|
|
172
|
-
expandOrRenewSession:
|
|
228
|
+
expandOrRenewSession: throttledExpandOrRenewSession,
|
|
173
229
|
expandSession,
|
|
174
230
|
getSession: () => sessionCache,
|
|
175
231
|
renewObservable,
|
|
176
232
|
expireObservable,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
233
|
+
sessionStateUpdateObservable,
|
|
234
|
+
restartSession: startSession,
|
|
235
|
+
expire: (hasConsent?: boolean) => {
|
|
236
|
+
cancelExpandOrRenewSession()
|
|
237
|
+
if (hasConsent === false && sessionCache) {
|
|
238
|
+
delete sessionCache.anonymousId
|
|
239
|
+
}
|
|
240
|
+
sessionStoreStrategy.expireSession(sessionCache)
|
|
241
|
+
synchronizeSession(getExpiredSessionState(sessionCache, configuration))
|
|
180
242
|
},
|
|
181
243
|
stop: () => {
|
|
182
244
|
clearInterval(watchSessionTimeoutId)
|
|
183
245
|
},
|
|
246
|
+
updateSessionState,
|
|
184
247
|
}
|
|
185
248
|
}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { setTimeout } from '../../tools/timer'
|
|
2
2
|
import { generateUUID } from '../../tools/utils/stringUtils'
|
|
3
|
-
import {
|
|
3
|
+
import type { TimeStamp } from '../../tools/utils/timeUtils'
|
|
4
|
+
import { elapsed, ONE_SECOND, timeStampNow } from '../../tools/utils/timeUtils'
|
|
4
5
|
import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy'
|
|
5
6
|
import type { SessionState } from './sessionState'
|
|
6
7
|
import { expandSessionState, isSessionInExpiredState } from './sessionState'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
interface Operations {
|
|
9
10
|
process: (sessionState: SessionState) => SessionState | undefined
|
|
10
11
|
after?: (sessionState: SessionState) => void
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const LOCK_RETRY_DELAY = 10
|
|
14
15
|
export const LOCK_MAX_TRIES = 100
|
|
16
|
+
|
|
17
|
+
// Locks should be hold for a few milliseconds top, just the time it takes to read and write a
|
|
18
|
+
// cookie. Using one second should be enough in most situations.
|
|
19
|
+
export const LOCK_EXPIRATION_DELAY = ONE_SECOND
|
|
20
|
+
const LOCK_SEPARATOR = '--'
|
|
21
|
+
|
|
15
22
|
const bufferedOperations: Operations[] = []
|
|
16
23
|
let ongoingOperations: Operations | undefined
|
|
17
24
|
|
|
@@ -20,8 +27,15 @@ export function processSessionStoreOperations(
|
|
|
20
27
|
sessionStoreStrategy: SessionStoreStrategy,
|
|
21
28
|
numberOfRetries = 0
|
|
22
29
|
) {
|
|
23
|
-
const {
|
|
24
|
-
const
|
|
30
|
+
const { isLockEnabled, persistSession, expireSession } = sessionStoreStrategy
|
|
31
|
+
const persistWithLock = (session: SessionState) => persistSession({ ...session, lock: currentLock })
|
|
32
|
+
const retrieveStore = () => {
|
|
33
|
+
const { lock, ...session } = sessionStoreStrategy.retrieveSession()
|
|
34
|
+
return {
|
|
35
|
+
session,
|
|
36
|
+
lock: lock && !isLockExpired(lock) ? lock : undefined,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
25
39
|
|
|
26
40
|
if (!ongoingOperations) {
|
|
27
41
|
ongoingOperations = operations
|
|
@@ -30,73 +44,69 @@ export function processSessionStoreOperations(
|
|
|
30
44
|
bufferedOperations.push(operations)
|
|
31
45
|
return
|
|
32
46
|
}
|
|
33
|
-
if (
|
|
47
|
+
if (isLockEnabled && numberOfRetries >= LOCK_MAX_TRIES) {
|
|
34
48
|
next(sessionStoreStrategy)
|
|
35
49
|
return
|
|
36
50
|
}
|
|
37
51
|
let currentLock: string
|
|
38
|
-
let
|
|
39
|
-
if (
|
|
52
|
+
let currentStore = retrieveStore()
|
|
53
|
+
if (isLockEnabled) {
|
|
40
54
|
// if someone has lock, retry later
|
|
41
|
-
if (
|
|
55
|
+
if (currentStore.lock) {
|
|
42
56
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
43
57
|
return
|
|
44
58
|
}
|
|
45
59
|
// acquire lock
|
|
46
|
-
currentLock =
|
|
47
|
-
|
|
48
|
-
persistSession(currentSession)
|
|
60
|
+
currentLock = createLock()
|
|
61
|
+
persistWithLock(currentStore.session)
|
|
49
62
|
// if lock is not acquired, retry later
|
|
50
|
-
|
|
51
|
-
if (
|
|
63
|
+
currentStore = retrieveStore()
|
|
64
|
+
if (currentStore.lock !== currentLock) {
|
|
52
65
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
53
66
|
return
|
|
54
67
|
}
|
|
55
68
|
}
|
|
56
|
-
let processedSession = operations.process(
|
|
57
|
-
if (
|
|
69
|
+
let processedSession = operations.process(currentStore.session)
|
|
70
|
+
if (isLockEnabled) {
|
|
58
71
|
// if lock corrupted after process, retry later
|
|
59
|
-
|
|
60
|
-
if (
|
|
72
|
+
currentStore = retrieveStore()
|
|
73
|
+
if (currentStore.lock !== currentLock!) {
|
|
61
74
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
62
75
|
return
|
|
63
76
|
}
|
|
64
77
|
}
|
|
65
78
|
if (processedSession) {
|
|
66
79
|
if (isSessionInExpiredState(processedSession)) {
|
|
67
|
-
|
|
80
|
+
expireSession(processedSession)
|
|
68
81
|
} else {
|
|
69
82
|
expandSessionState(processedSession)
|
|
70
|
-
|
|
83
|
+
if (isLockEnabled) {
|
|
84
|
+
persistWithLock(processedSession)
|
|
85
|
+
} else {
|
|
86
|
+
persistSession(processedSession)
|
|
87
|
+
}
|
|
71
88
|
}
|
|
72
89
|
}
|
|
73
|
-
if (
|
|
90
|
+
if (isLockEnabled) {
|
|
74
91
|
// correctly handle lock around expiration would require to handle this case properly at several levels
|
|
75
92
|
// since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it
|
|
76
93
|
if (!(processedSession && isSessionInExpiredState(processedSession))) {
|
|
77
94
|
// if lock corrupted after persist, retry later
|
|
78
|
-
|
|
79
|
-
if (
|
|
95
|
+
currentStore = retrieveStore()
|
|
96
|
+
if (currentStore.lock !== currentLock!) {
|
|
80
97
|
retryLater(operations, sessionStoreStrategy, numberOfRetries)
|
|
81
98
|
return
|
|
82
99
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
processedSession = currentSession
|
|
100
|
+
persistSession(currentStore.session)
|
|
101
|
+
processedSession = currentStore.session
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
// call after even if session is not persisted in order to perform operations on
|
|
89
105
|
// up-to-date session state value => the value could have been modified by another tab
|
|
90
|
-
operations.after?.(processedSession ||
|
|
106
|
+
operations.after?.(processedSession || currentStore.session)
|
|
91
107
|
next(sessionStoreStrategy)
|
|
92
108
|
}
|
|
93
109
|
|
|
94
|
-
/**
|
|
95
|
-
* Lock strategy allows mitigating issues due to concurrent access to cookie.
|
|
96
|
-
* This issue concerns only chromium browsers and enabling this on firefox increases cookie write failures.
|
|
97
|
-
*/
|
|
98
|
-
export const isLockEnabled = () => isChromium()
|
|
99
|
-
|
|
100
110
|
function retryLater(operations: Operations, sessionStore: SessionStoreStrategy, currentNumberOfRetries: number) {
|
|
101
111
|
setTimeout(() => {
|
|
102
112
|
processSessionStoreOperations(operations, sessionStore, currentNumberOfRetries + 1)
|
|
@@ -110,3 +120,12 @@ function next(sessionStore: SessionStoreStrategy) {
|
|
|
110
120
|
processSessionStoreOperations(nextOperations, sessionStore)
|
|
111
121
|
}
|
|
112
122
|
}
|
|
123
|
+
|
|
124
|
+
export function createLock(): string {
|
|
125
|
+
return generateUUID() + LOCK_SEPARATOR + timeStampNow()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function isLockExpired(lock: string) {
|
|
129
|
+
const [, timeStamp] = lock.split(LOCK_SEPARATOR)
|
|
130
|
+
return !timeStamp || elapsed(Number(timeStamp) as TimeStamp, timeStampNow()) > LOCK_EXPIRATION_DELAY
|
|
131
|
+
}
|