@newrelic/browser-agent 0.1.230 → 1.232.0
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/README.md +27 -3
- package/dist/cjs/common/browser-version/ios-version.js +4 -3
- package/dist/cjs/common/config/state/configurable.js +27 -21
- package/dist/cjs/common/config/state/info.js +1 -1
- package/dist/cjs/common/config/state/init.js +9 -1
- package/dist/cjs/common/config/state/loader-config.js +1 -1
- package/dist/cjs/common/config/state/runtime.js +26 -28
- package/dist/cjs/common/constants/env.cdn.js +29 -0
- package/dist/cjs/common/constants/env.js +32 -0
- package/dist/cjs/common/constants/env.npm.js +30 -0
- package/dist/cjs/common/context/shared-context.js +2 -1
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
- package/dist/cjs/common/event-emitter/handle.test.js +58 -0
- package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
- package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
- package/dist/cjs/common/harvest/harvest-scheduler.js +14 -11
- package/dist/cjs/common/harvest/harvest.js +5 -3
- package/dist/cjs/common/ids/id.js +14 -6
- package/dist/cjs/common/ids/id.test.js +85 -0
- package/dist/cjs/common/ids/unique-id.js +75 -51
- package/dist/cjs/common/ids/unique-id.test.js +49 -0
- package/dist/cjs/common/session/constants.js +12 -0
- package/dist/cjs/common/session/session-entity.js +278 -0
- package/dist/cjs/common/session/session-entity.test.js +436 -0
- package/dist/cjs/common/storage/first-party-cookies.js +35 -0
- package/dist/cjs/common/storage/local-memory.js +35 -0
- package/dist/cjs/common/storage/local-memory.test.js +20 -0
- package/dist/cjs/common/storage/local-storage.js +33 -0
- package/dist/cjs/common/storage/local-storage.test.js +14 -0
- package/dist/cjs/common/timer/interaction-timer.js +78 -0
- package/dist/cjs/common/timer/interaction-timer.test.js +216 -0
- package/dist/cjs/common/timer/timer.js +32 -0
- package/dist/cjs/common/timer/timer.test.js +105 -0
- package/dist/cjs/common/timing/nav-timing.js +51 -30
- package/dist/cjs/common/timing/nav-timing.test.js +192 -0
- package/dist/cjs/common/unload/eol.js +2 -2
- package/dist/cjs/common/url/clean-url.test.js +9 -0
- package/dist/cjs/common/url/encode.test.js +74 -0
- package/dist/cjs/common/url/location.js +4 -0
- package/dist/cjs/common/url/location.test.js +13 -0
- package/dist/cjs/common/url/parse-url.test.js +111 -0
- package/dist/cjs/common/url/protocol.js +2 -12
- package/dist/cjs/common/url/protocol.test.js +16 -0
- package/dist/cjs/common/util/console.js +1 -1
- package/dist/cjs/common/util/data-size.js +6 -0
- package/dist/cjs/common/util/data-size.test.js +47 -0
- package/dist/cjs/common/util/invoke.js +73 -0
- package/dist/cjs/common/util/invoke.test.js +49 -0
- package/dist/cjs/common/util/map-own.test.js +3 -3
- package/dist/cjs/common/util/obfuscate.js +1 -5
- package/dist/cjs/common/window/page-visibility.js +5 -2
- package/dist/cjs/common/wrap/index.js +0 -7
- package/dist/cjs/common/wrap/wrap-events.js +6 -9
- package/dist/cjs/common/wrap/wrap-fetch.js +6 -6
- package/dist/cjs/common/wrap/wrap-history.js +7 -6
- package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
- package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
- package/dist/cjs/common/wrap/wrap-raf.js +6 -6
- package/dist/cjs/common/wrap/wrap-timer.js +7 -7
- package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
- package/dist/cjs/features/ajax/aggregate/index.js +3 -3
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/index.js +6 -6
- package/dist/cjs/features/jserrors/instrument/index.js +2 -2
- package/dist/cjs/features/metrics/aggregate/index.js +19 -9
- package/dist/cjs/features/metrics/instrument/index.js +0 -25
- package/dist/cjs/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/cjs/features/page_action/aggregate/index.js +3 -3
- package/dist/cjs/features/page_view_event/aggregate/index.js +23 -9
- package/dist/cjs/features/page_view_timing/aggregate/index.js +40 -30
- package/dist/cjs/features/session_trace/aggregate/index.js +18 -15
- package/dist/cjs/features/spa/aggregate/index.js +6 -5
- package/dist/cjs/features/utils/agent-session.js +73 -0
- package/dist/cjs/features/utils/feature-base.js +1 -1
- package/dist/cjs/features/utils/instrument-base.js +12 -3
- package/dist/cjs/features/utils/lazy-loader.js +2 -2
- package/dist/cjs/loaders/agent.js +2 -2
- package/dist/cjs/loaders/api/api.js +9 -9
- package/dist/cjs/loaders/api/apiAsync.js +3 -2
- package/dist/cjs/loaders/configure/configure.js +0 -6
- package/dist/cjs/loaders/features/enabled-features.js +1 -1
- package/dist/cjs/loaders/micro-agent.js +2 -1
- package/dist/esm/common/browser-version/ios-version.js +4 -3
- package/dist/esm/common/config/state/configurable.js +26 -20
- package/dist/esm/common/config/state/info.js +1 -1
- package/dist/esm/common/config/state/init.js +9 -1
- package/dist/esm/common/config/state/loader-config.js +1 -1
- package/dist/esm/common/config/state/runtime.js +26 -28
- package/dist/esm/common/constants/env.cdn.js +20 -0
- package/dist/esm/common/constants/env.js +23 -0
- package/dist/esm/common/constants/env.npm.js +21 -0
- package/dist/esm/common/context/shared-context.js +2 -1
- package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
- package/dist/esm/common/event-emitter/handle.test.js +54 -0
- package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
- package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
- package/dist/esm/common/harvest/harvest-scheduler.js +14 -11
- package/dist/esm/common/harvest/harvest.js +4 -2
- package/dist/esm/common/ids/id.js +16 -6
- package/dist/esm/common/ids/id.test.js +81 -0
- package/dist/esm/common/ids/unique-id.js +75 -51
- package/dist/esm/common/ids/unique-id.test.js +44 -0
- package/dist/esm/common/session/constants.js +3 -0
- package/dist/esm/common/session/session-entity.js +271 -0
- package/dist/esm/common/session/session-entity.test.js +434 -0
- package/dist/esm/common/storage/first-party-cookies.js +28 -0
- package/dist/esm/common/storage/local-memory.js +28 -0
- package/dist/esm/common/storage/local-memory.test.js +18 -0
- package/dist/esm/common/storage/local-storage.js +26 -0
- package/dist/esm/common/storage/local-storage.test.js +12 -0
- package/dist/esm/common/timer/interaction-timer.js +71 -0
- package/dist/esm/common/timer/interaction-timer.test.js +214 -0
- package/dist/esm/common/timer/timer.js +25 -0
- package/dist/esm/common/timer/timer.test.js +103 -0
- package/dist/esm/common/timing/nav-timing.js +51 -29
- package/dist/esm/common/timing/nav-timing.test.js +190 -0
- package/dist/esm/common/unload/eol.js +1 -1
- package/dist/esm/common/url/clean-url.test.js +7 -0
- package/dist/esm/common/url/encode.test.js +70 -0
- package/dist/esm/common/url/location.js +4 -0
- package/dist/esm/common/url/location.test.js +11 -0
- package/dist/esm/common/url/parse-url.test.js +107 -0
- package/dist/esm/common/url/protocol.js +3 -12
- package/dist/esm/common/url/protocol.test.js +14 -0
- package/dist/esm/common/util/console.js +1 -1
- package/dist/esm/common/util/data-size.js +7 -0
- package/dist/esm/common/util/data-size.test.js +45 -0
- package/dist/esm/common/util/invoke.js +66 -0
- package/dist/esm/common/util/invoke.test.js +47 -0
- package/dist/esm/common/util/map-own.test.js +3 -3
- package/dist/esm/common/util/obfuscate.js +2 -6
- package/dist/esm/common/window/page-visibility.js +5 -2
- package/dist/esm/common/wrap/index.js +1 -2
- package/dist/esm/common/wrap/wrap-events.js +6 -9
- package/dist/esm/common/wrap/wrap-fetch.js +6 -6
- package/dist/esm/common/wrap/wrap-history.js +7 -6
- package/dist/esm/common/wrap/wrap-jsonp.js +7 -6
- package/dist/esm/common/wrap/wrap-mutation.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
- package/dist/esm/common/wrap/wrap-raf.js +6 -6
- package/dist/esm/common/wrap/wrap-timer.js +7 -7
- package/dist/esm/common/wrap/wrap-xhr.js +5 -6
- package/dist/esm/features/ajax/aggregate/index.js +3 -3
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/esm/features/jserrors/aggregate/index.js +6 -6
- package/dist/esm/features/jserrors/instrument/index.js +2 -2
- package/dist/esm/features/metrics/aggregate/index.js +21 -11
- package/dist/esm/features/metrics/instrument/index.js +0 -25
- package/dist/esm/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/esm/features/page_action/aggregate/index.js +3 -3
- package/dist/esm/features/page_view_event/aggregate/index.js +23 -9
- package/dist/esm/features/page_view_timing/aggregate/index.js +40 -30
- package/dist/esm/features/session_trace/aggregate/index.js +18 -15
- package/dist/esm/features/spa/aggregate/index.js +6 -5
- package/dist/esm/features/utils/agent-session.js +67 -0
- package/dist/esm/features/utils/feature-base.js +1 -1
- package/dist/esm/features/utils/instrument-base.js +7 -2
- package/dist/esm/features/utils/lazy-loader.js +2 -2
- package/dist/esm/loaders/agent.js +2 -2
- package/dist/esm/loaders/api/api.js +6 -9
- package/dist/esm/loaders/api/apiAsync.js +2 -1
- package/dist/esm/loaders/configure/configure.js +2 -8
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/types/common/config/state/configurable.d.ts.map +1 -1
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/config/state/runtime.d.ts.map +1 -1
- package/dist/types/common/constants/env.cdn.d.ts +18 -0
- package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
- package/dist/types/common/constants/env.d.ts +13 -0
- package/dist/types/common/constants/env.d.ts.map +1 -0
- package/dist/types/common/constants/env.npm.d.ts +19 -0
- package/dist/types/common/constants/env.npm.d.ts.map +1 -0
- package/dist/types/common/context/shared-context.d.ts.map +1 -1
- package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
- package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/ids/id.d.ts +11 -1
- package/dist/types/common/ids/id.d.ts.map +1 -1
- package/dist/types/common/ids/unique-id.d.ts +24 -1
- package/dist/types/common/ids/unique-id.d.ts.map +1 -1
- package/dist/types/common/session/constants.d.ts +4 -0
- package/dist/types/common/session/constants.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +72 -0
- package/dist/types/common/session/session-entity.d.ts.map +1 -0
- package/dist/types/common/storage/first-party-cookies.d.ts +8 -0
- package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -0
- package/dist/types/common/storage/local-memory.d.ts +8 -0
- package/dist/types/common/storage/local-memory.d.ts.map +1 -0
- package/dist/types/common/storage/local-storage.d.ts +6 -0
- package/dist/types/common/storage/local-storage.d.ts.map +1 -0
- package/dist/types/common/timer/interaction-timer.d.ts +11 -0
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -0
- package/dist/types/common/timer/timer.d.ts +12 -0
- package/dist/types/common/timer/timer.d.ts.map +1 -0
- package/dist/types/common/timing/nav-timing.d.ts +1 -2
- package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/url/location.d.ts +4 -0
- package/dist/types/common/url/location.d.ts.map +1 -1
- package/dist/types/common/url/parse-url.d.ts.map +1 -1
- package/dist/types/common/url/protocol.d.ts +1 -6
- package/dist/types/common/url/protocol.d.ts.map +1 -1
- package/dist/types/common/util/data-size.d.ts +7 -1
- package/dist/types/common/util/data-size.d.ts.map +1 -1
- package/dist/types/common/util/global-scope.d.ts.map +1 -1
- package/dist/types/common/util/invoke.d.ts +35 -0
- package/dist/types/common/util/invoke.d.ts.map +1 -0
- package/dist/types/common/util/obfuscate.d.ts.map +1 -1
- package/dist/types/common/window/page-visibility.d.ts +1 -1
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/common/wrap/index.d.ts +1 -2
- package/dist/types/common/wrap/index.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts +0 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts +3 -4
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +3 -3
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts +2 -2
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts +2 -0
- package/dist/types/features/utils/agent-session.d.ts.map +1 -0
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/features/utils/lazy-loader.d.ts +2 -2
- package/dist/types/features/utils/lazy-loader.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts.map +1 -1
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/package.json +12 -32
- package/src/common/browser-version/ios-version.js +4 -3
- package/src/common/config/state/configurable.js +26 -19
- package/src/common/config/state/init.js +7 -0
- package/src/common/config/state/runtime.js +7 -10
- package/src/common/constants/env.cdn.js +20 -0
- package/src/common/constants/env.js +23 -0
- package/src/common/constants/env.npm.js +21 -0
- package/src/common/context/shared-context.js +2 -1
- package/src/common/event-emitter/contextual-ee.test.js +310 -0
- package/src/common/event-emitter/handle.test.js +56 -0
- package/src/common/event-emitter/register-handler.test.js +61 -0
- package/src/common/event-listener/event-listener-opts.js +4 -4
- package/src/common/harvest/harvest-scheduler.js +12 -8
- package/src/common/harvest/harvest.js +5 -3
- package/src/common/ids/id.js +15 -6
- package/src/common/ids/id.test.js +92 -0
- package/src/common/ids/unique-id.js +77 -54
- package/src/common/ids/unique-id.test.js +58 -0
- package/src/common/session/constants.js +3 -0
- package/src/common/session/session-entity.js +271 -0
- package/src/common/session/session-entity.test.js +317 -0
- package/src/common/storage/first-party-cookies.js +31 -0
- package/src/common/storage/local-memory.js +30 -0
- package/src/common/storage/local-memory.test.js +19 -0
- package/src/common/storage/local-storage.js +28 -0
- package/src/common/storage/local-storage.test.js +17 -0
- package/src/common/timer/interaction-timer.js +75 -0
- package/src/common/timer/interaction-timer.test.js +167 -0
- package/src/common/timer/timer.js +31 -0
- package/src/common/timer/timer.test.js +100 -0
- package/src/common/timing/nav-timing.js +50 -30
- package/src/common/timing/nav-timing.test.js +161 -0
- package/src/common/unload/eol.js +2 -3
- package/src/common/url/clean-url.test.js +25 -0
- package/src/common/url/encode.test.js +80 -0
- package/src/common/url/location.js +4 -0
- package/src/common/url/location.test.js +15 -0
- package/src/common/url/parse-url.js +1 -2
- package/src/common/url/parse-url.test.js +110 -0
- package/src/common/url/protocol.js +3 -13
- package/src/common/url/protocol.test.js +18 -0
- package/src/common/util/data-size.js +6 -0
- package/src/common/util/data-size.test.js +50 -0
- package/src/common/util/global-scope.js +1 -2
- package/src/common/util/invoke.js +55 -0
- package/src/common/util/invoke.test.js +65 -0
- package/src/common/util/obfuscate.js +2 -6
- package/src/common/window/page-visibility.js +3 -3
- package/src/common/wrap/index.js +1 -2
- package/src/common/wrap/wrap-events.js +5 -5
- package/src/common/wrap/wrap-fetch.js +4 -3
- package/src/common/wrap/wrap-history.js +6 -3
- package/src/common/wrap/wrap-jsonp.js +5 -3
- package/src/common/wrap/wrap-mutation.js +6 -3
- package/src/common/wrap/wrap-promise.js +7 -6
- package/src/common/wrap/wrap-promise.test.js +140 -0
- package/src/common/wrap/wrap-raf.js +5 -3
- package/src/common/wrap/wrap-timer.js +6 -4
- package/src/common/wrap/wrap-xhr.js +4 -3
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/ajax/instrument/index.js +1 -1
- package/src/features/jserrors/aggregate/index.js +3 -3
- package/src/features/jserrors/instrument/index.js +4 -2
- package/src/features/metrics/aggregate/index.js +21 -7
- package/src/features/metrics/instrument/index.js +0 -30
- package/src/features/metrics/instrument/workers-helper.js +9 -6
- package/src/features/page_action/aggregate/index.js +2 -2
- package/src/features/page_view_event/aggregate/index.js +21 -9
- package/src/features/page_view_timing/aggregate/index.js +40 -29
- package/src/features/page_view_timing/long-tasks.js +10 -10
- package/src/features/session_trace/aggregate/index.js +17 -14
- package/src/features/session_trace/instrument/index.js +3 -2
- package/src/features/spa/aggregate/index.js +5 -5
- package/src/features/spa/instrument/index.js +4 -2
- package/src/features/utils/agent-session.js +68 -0
- package/src/features/utils/feature-base.js +1 -1
- package/src/features/utils/instrument-base.js +5 -2
- package/src/features/utils/lazy-loader.js +1 -1
- package/src/loaders/agent.js +1 -1
- package/src/loaders/api/api.js +3 -6
- package/src/loaders/api/apiAsync.js +2 -1
- package/src/loaders/configure/configure.js +2 -7
- package/dist/cjs/common/constants/environment-variables.js +0 -20
- package/dist/cjs/common/util/single.js +0 -23
- package/dist/cjs/common/window/session-storage.js +0 -87
- package/dist/cjs/common/wrap/wrap-console.js +0 -54
- package/dist/cjs/features/utils/aggregate-base.js +0 -13
- package/dist/esm/common/constants/environment-variables.js +0 -11
- package/dist/esm/common/util/single.js +0 -16
- package/dist/esm/common/window/session-storage.js +0 -77
- package/dist/esm/common/wrap/wrap-console.js +0 -46
- package/dist/esm/features/utils/aggregate-base.js +0 -6
- package/dist/types/common/constants/environment-variables.d.ts +0 -4
- package/dist/types/common/constants/environment-variables.d.ts.map +0 -1
- package/dist/types/common/util/single.d.ts +0 -2
- package/dist/types/common/util/single.d.ts.map +0 -1
- package/dist/types/common/window/session-storage.d.ts +0 -18
- package/dist/types/common/window/session-storage.d.ts.map +0 -1
- package/dist/types/common/wrap/wrap-console.d.ts +0 -16
- package/dist/types/common/wrap/wrap-console.d.ts.map +0 -1
- package/dist/types/features/utils/aggregate-base.d.ts +0 -4
- package/dist/types/features/utils/aggregate-base.d.ts.map +0 -1
- package/src/common/constants/environment-variables.js +0 -11
- package/src/common/util/single.js +0 -18
- package/src/common/window/session-storage.js +0 -75
- package/src/common/wrap/wrap-console.js +0 -47
- package/src/features/utils/aggregate-base.js +0 -7
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FirstPartyCookies = void 0;
|
|
7
|
+
class FirstPartyCookies {
|
|
8
|
+
constructor(domain) {
|
|
9
|
+
this.domain = domain;
|
|
10
|
+
}
|
|
11
|
+
get(name) {
|
|
12
|
+
try {
|
|
13
|
+
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
|
|
14
|
+
if (match) return match[2];
|
|
15
|
+
} catch (err) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
set(key, value) {
|
|
20
|
+
try {
|
|
21
|
+
const cookie = "".concat(key, "=").concat(value, "; Domain=").concat(domain, "; Path=/");
|
|
22
|
+
document.cookie = cookie;
|
|
23
|
+
} catch (err) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
remove(key) {
|
|
28
|
+
try {
|
|
29
|
+
return document.cookie = "".concat(key, "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; Domain=").concat(domain, "; Path=/");
|
|
30
|
+
} catch (err) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.FirstPartyCookies = FirstPartyCookies;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LocalMemory = void 0;
|
|
7
|
+
class LocalMemory {
|
|
8
|
+
constructor() {
|
|
9
|
+
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10
|
+
this.state = initialState;
|
|
11
|
+
}
|
|
12
|
+
get(key) {
|
|
13
|
+
try {
|
|
14
|
+
return this.state[key];
|
|
15
|
+
} catch (err) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
set(key, value) {
|
|
20
|
+
try {
|
|
21
|
+
if (value === undefined || value === null) return this.remove(key);
|
|
22
|
+
this.state[key] = value;
|
|
23
|
+
} catch (err) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
remove(key) {
|
|
28
|
+
try {
|
|
29
|
+
delete this.state[key];
|
|
30
|
+
} catch (err) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.LocalMemory = LocalMemory;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _localMemory = require("./local-memory");
|
|
4
|
+
test('Local-memory', () => {
|
|
5
|
+
const LM = new _localMemory.LocalMemory({
|
|
6
|
+
test: 1
|
|
7
|
+
});
|
|
8
|
+
expect(LM.state).toEqual({
|
|
9
|
+
test: 1
|
|
10
|
+
});
|
|
11
|
+
expect(LM.get('test')).toEqual(1);
|
|
12
|
+
LM.set('test', 2);
|
|
13
|
+
expect(LM.get('test')).toEqual(2);
|
|
14
|
+
LM.set('test');
|
|
15
|
+
expect(LM.get('test')).toEqual(undefined);
|
|
16
|
+
LM.set('test', 2);
|
|
17
|
+
expect(LM.get('test')).toEqual(2);
|
|
18
|
+
LM.remove('test');
|
|
19
|
+
expect(LM.get('test')).toEqual(undefined);
|
|
20
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LocalStorage = void 0;
|
|
7
|
+
class LocalStorage {
|
|
8
|
+
get(key) {
|
|
9
|
+
try {
|
|
10
|
+
// localStorage strangely type-casts non-existing data to "null"...
|
|
11
|
+
// Cast it back to undefined if it doesnt exist
|
|
12
|
+
return localStorage.getItem(key) || undefined;
|
|
13
|
+
} catch (err) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
set(key, value) {
|
|
18
|
+
try {
|
|
19
|
+
if (value === undefined || value === null) return this.remove(key);
|
|
20
|
+
return localStorage.setItem(key, value);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
remove(key) {
|
|
26
|
+
try {
|
|
27
|
+
localStorage.removeItem(key);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.LocalStorage = LocalStorage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _localStorage = require("./local-storage");
|
|
4
|
+
test('Local-memory', () => {
|
|
5
|
+
const LS = new _localStorage.LocalStorage();
|
|
6
|
+
LS.set('test', 1);
|
|
7
|
+
expect(LS.get('test')).toEqual('1');
|
|
8
|
+
LS.set('test');
|
|
9
|
+
expect(LS.get('test')).toEqual(undefined);
|
|
10
|
+
LS.set('test', 2);
|
|
11
|
+
expect(LS.get('test')).toEqual('2');
|
|
12
|
+
LS.remove('test');
|
|
13
|
+
expect(LS.get('test')).toEqual(undefined);
|
|
14
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InteractionTimer = void 0;
|
|
7
|
+
var _timer = require("./timer");
|
|
8
|
+
var _pageVisibility = require("../window/page-visibility");
|
|
9
|
+
var _invoke = require("../util/invoke");
|
|
10
|
+
var _globalScope = require("../util/global-scope");
|
|
11
|
+
class InteractionTimer extends _timer.Timer {
|
|
12
|
+
constructor(opts, ms) {
|
|
13
|
+
super(opts, ms);
|
|
14
|
+
this.onRefresh = opts.onRefresh;
|
|
15
|
+
this.onPause = opts.onPause;
|
|
16
|
+
|
|
17
|
+
// used by pause/resume
|
|
18
|
+
this.remainingMs = undefined;
|
|
19
|
+
if (!opts.refreshEvents) opts.refreshEvents = ['click', 'keydown', 'scroll'];
|
|
20
|
+
|
|
21
|
+
// the abort controller is used to "reset" the event listeners and prevent them from duplicating when new sessions are created
|
|
22
|
+
try {
|
|
23
|
+
this.abortController = new AbortController();
|
|
24
|
+
} catch (e) {
|
|
25
|
+
// this try-catch can be removed when IE11 is completely unsupported & gone
|
|
26
|
+
}
|
|
27
|
+
if (_globalScope.isBrowserScope && opts.ee) {
|
|
28
|
+
if (opts.ee) {
|
|
29
|
+
const debouncedRefresh = (0, _invoke.debounce)(this.refresh.bind(this), 500, {
|
|
30
|
+
leading: true
|
|
31
|
+
});
|
|
32
|
+
opts.ee.on('fn-end', evts => {
|
|
33
|
+
if (opts.refreshEvents.includes(evts?.[0]?.type)) {
|
|
34
|
+
debouncedRefresh();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// watch for the vis state changing. If the page is hidden, the local inactivity timer should be paused
|
|
40
|
+
// if the page is brought BACK to visibility and the timer hasnt "naturally" expired, refresh the timer...
|
|
41
|
+
// this is to support the concept that other tabs could be experiencing activity. The thought would be that
|
|
42
|
+
// "backgrounded" tabs would pause, while "closed" tabs that "reopen" will just instantiate a new SessionEntity class if restored
|
|
43
|
+
// which will do a "hard" check of the timestamps.
|
|
44
|
+
|
|
45
|
+
// NOTE -- this does not account for 2 browser windows open side by side, blurring/focusing between them
|
|
46
|
+
// IF DEEMED necessary, more event handling would be needed to account for this.
|
|
47
|
+
(0, _pageVisibility.subscribeToVisibilityChange)(state => {
|
|
48
|
+
if (state === 'hidden') this.pause();
|
|
49
|
+
// vis change --> visible is treated like a new interaction with the page
|
|
50
|
+
else this.refresh();
|
|
51
|
+
}, false, false, this.abortController?.signal);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
abort() {
|
|
55
|
+
this.clear();
|
|
56
|
+
this.abortController?.abort();
|
|
57
|
+
}
|
|
58
|
+
pause() {
|
|
59
|
+
this.onPause?.();
|
|
60
|
+
clearTimeout(this.timer);
|
|
61
|
+
this.remainingMs = this.initialMs - (Date.now() - this.startTimestamp);
|
|
62
|
+
}
|
|
63
|
+
refresh(cb, ms) {
|
|
64
|
+
this.clear();
|
|
65
|
+
this.timer = this.create(cb, ms);
|
|
66
|
+
this.startTimestamp = Date.now();
|
|
67
|
+
this.remainingMs = undefined;
|
|
68
|
+
this.onRefresh?.();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// NOT CURRENTLY UTILIZED BY ANYTHING
|
|
72
|
+
// resume () {
|
|
73
|
+
// if (!this.remainingMs || !this.isValid()) return
|
|
74
|
+
// this.timer = this.create(this.cb, this.remainingMs)
|
|
75
|
+
// this.remainingMs = undefined
|
|
76
|
+
// }
|
|
77
|
+
}
|
|
78
|
+
exports.InteractionTimer = InteractionTimer;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interactionTimer = require("./interaction-timer");
|
|
4
|
+
jest.useFakeTimers();
|
|
5
|
+
let now;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
now = Date.now();
|
|
8
|
+
jest.setSystemTime(now);
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
describe('constructor', () => {
|
|
14
|
+
test('appropriate properties are set with valid values -- no refresh', () => {
|
|
15
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
16
|
+
onEnd: jest.fn()
|
|
17
|
+
}, 100);
|
|
18
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
|
|
19
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
test('appropriate properties are set with valid values -- with refresh', () => {
|
|
22
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
23
|
+
onEnd: jest.fn()
|
|
24
|
+
}, 100);
|
|
25
|
+
const requiredKeys = ['onEnd', 'refresh', 'initialMs', 'startTimestamp', 'timer'];
|
|
26
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
test('required keys are enforced', () => {
|
|
29
|
+
try {
|
|
30
|
+
new _interactionTimer.InteractionTimer({}, 100);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
expect(e).toEqual(new Error('onEnd handler is required'));
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
new _interactionTimer.InteractionTimer({
|
|
36
|
+
onEnd: jest.fn()
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
expect(e).toEqual(new Error('ms duration is required'));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
test('refresh type timers set event listeners', () => {
|
|
43
|
+
// eslint-disable-next-line
|
|
44
|
+
let ee = {
|
|
45
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
46
|
+
cb([{
|
|
47
|
+
type: 'click'
|
|
48
|
+
}]);
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
let it = new _interactionTimer.InteractionTimer({
|
|
52
|
+
onEnd: jest.fn(),
|
|
53
|
+
onRefresh: jest.fn(),
|
|
54
|
+
ee
|
|
55
|
+
}, 100);
|
|
56
|
+
// scroll, keypress, click
|
|
57
|
+
expect(ee.on).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(it.onRefresh).toHaveBeenCalledTimes(1);
|
|
59
|
+
|
|
60
|
+
// eslint-disable-next-line
|
|
61
|
+
ee = {
|
|
62
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
63
|
+
cb([{
|
|
64
|
+
type: 'scroll'
|
|
65
|
+
}]);
|
|
66
|
+
})
|
|
67
|
+
};
|
|
68
|
+
it = new _interactionTimer.InteractionTimer({
|
|
69
|
+
onEnd: jest.fn(),
|
|
70
|
+
onRefresh: jest.fn(),
|
|
71
|
+
ee
|
|
72
|
+
}, 100);
|
|
73
|
+
// scroll, keypress, click
|
|
74
|
+
expect(ee.on).toHaveBeenCalledTimes(1);
|
|
75
|
+
expect(it.onRefresh).toHaveBeenCalledTimes(1);
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line
|
|
78
|
+
ee = {
|
|
79
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
80
|
+
cb([{
|
|
81
|
+
type: 'keydown'
|
|
82
|
+
}]);
|
|
83
|
+
})
|
|
84
|
+
};
|
|
85
|
+
it = new _interactionTimer.InteractionTimer({
|
|
86
|
+
onEnd: jest.fn(),
|
|
87
|
+
onRefresh: jest.fn(),
|
|
88
|
+
ee
|
|
89
|
+
}, 100);
|
|
90
|
+
// scroll, keypress, click
|
|
91
|
+
expect(ee.on).toHaveBeenCalledTimes(1);
|
|
92
|
+
expect(it.onRefresh).toHaveBeenCalledTimes(1);
|
|
93
|
+
const aelSpy = jest.spyOn(document, 'addEventListener');
|
|
94
|
+
// eslint-disable-next-line
|
|
95
|
+
ee = {
|
|
96
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
97
|
+
cb([{
|
|
98
|
+
type: 'keydown'
|
|
99
|
+
}]);
|
|
100
|
+
})
|
|
101
|
+
};
|
|
102
|
+
it = new _interactionTimer.InteractionTimer({
|
|
103
|
+
onEnd: jest.fn(),
|
|
104
|
+
onRefresh: jest.fn(),
|
|
105
|
+
ee
|
|
106
|
+
}, 100);
|
|
107
|
+
// visibility change
|
|
108
|
+
expect(aelSpy).toHaveBeenCalledTimes(1);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe('create()', () => {
|
|
112
|
+
test('Create sets a timeout that can execute a cb', () => {
|
|
113
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
114
|
+
onEnd: jest.fn()
|
|
115
|
+
}, 100);
|
|
116
|
+
expect(timer.timer).toBeTruthy();
|
|
117
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
118
|
+
jest.runOnlyPendingTimers();
|
|
119
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
120
|
+
});
|
|
121
|
+
test('Create can fallback to use defaults', () => {
|
|
122
|
+
let called = 0;
|
|
123
|
+
const timer1 = new _interactionTimer.InteractionTimer({
|
|
124
|
+
onEnd: jest.fn()
|
|
125
|
+
}, 100);
|
|
126
|
+
timer1.create();
|
|
127
|
+
const timer2 = new _interactionTimer.InteractionTimer({
|
|
128
|
+
onEnd: jest.fn()
|
|
129
|
+
}, 100);
|
|
130
|
+
timer2.create(timer2.onEnd);
|
|
131
|
+
const timer3 = new _interactionTimer.InteractionTimer({
|
|
132
|
+
onEnd: jest.fn()
|
|
133
|
+
}, 100);
|
|
134
|
+
timer3.create(undefined, 100);
|
|
135
|
+
jest.runAllTimers(200);
|
|
136
|
+
expect(timer1.onEnd).toHaveBeenCalledTimes(1);
|
|
137
|
+
expect(timer2.onEnd).toHaveBeenCalledTimes(1);
|
|
138
|
+
expect(timer3.onEnd).toHaveBeenCalledTimes(1);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe('refresh()', () => {
|
|
142
|
+
test('refresh prevents the callback from firing', () => {
|
|
143
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
144
|
+
onEnd: jest.fn(),
|
|
145
|
+
onRefresh: jest.fn()
|
|
146
|
+
}, 100);
|
|
147
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
148
|
+
jest.advanceTimersByTime(75);
|
|
149
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
150
|
+
timer.refresh();
|
|
151
|
+
jest.advanceTimersByTime(75);
|
|
152
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
153
|
+
jest.advanceTimersByTime(100);
|
|
154
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
155
|
+
});
|
|
156
|
+
test('refresh executes a callback for consumers', () => {
|
|
157
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
158
|
+
onEnd: jest.fn(),
|
|
159
|
+
onRefresh: jest.fn()
|
|
160
|
+
}, 100);
|
|
161
|
+
timer.refresh();
|
|
162
|
+
expect(timer.onRefresh).toHaveBeenCalledTimes(1);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('pause()', () => {
|
|
166
|
+
test('pause prevents the callback from firing', () => {
|
|
167
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
168
|
+
onEnd: jest.fn()
|
|
169
|
+
}, 100);
|
|
170
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
171
|
+
timer.pause();
|
|
172
|
+
jest.advanceTimersByTime(150);
|
|
173
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
174
|
+
});
|
|
175
|
+
test('pause sets remainingMs timestamp', () => {
|
|
176
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
177
|
+
onEnd: jest.fn()
|
|
178
|
+
}, 100);
|
|
179
|
+
expect(timer.remainingMs).toEqual(undefined);
|
|
180
|
+
timer.pause();
|
|
181
|
+
expect(timer.remainingMs).toEqual(timer.initialMs - (now - timer.startTimestamp));
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
describe('clear()', () => {
|
|
185
|
+
test('clear prevents the callback from firing and deletes the pointer', () => {
|
|
186
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
187
|
+
onEnd: jest.fn()
|
|
188
|
+
}, 100);
|
|
189
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
190
|
+
timer.clear();
|
|
191
|
+
jest.advanceTimersByTime(150);
|
|
192
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
193
|
+
expect(timer.timer).toEqual(null);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
describe('end()', () => {
|
|
197
|
+
test('end clears the callback and calls the onEnd callback', () => {
|
|
198
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
199
|
+
onEnd: jest.fn()
|
|
200
|
+
}, 100);
|
|
201
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
202
|
+
timer.end();
|
|
203
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
204
|
+
expect(timer.timer).toEqual(null);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe('isValid', () => {
|
|
208
|
+
test('isValid validates timeStamps', () => {
|
|
209
|
+
const timer = new _interactionTimer.InteractionTimer({
|
|
210
|
+
onEnd: jest.fn()
|
|
211
|
+
}, 100);
|
|
212
|
+
expect(timer.isValid()).toEqual(true);
|
|
213
|
+
timer.startTimestamp -= 100;
|
|
214
|
+
expect(timer.isValid()).toEqual(false);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Timer = void 0;
|
|
7
|
+
class Timer {
|
|
8
|
+
constructor(opts, ms) {
|
|
9
|
+
if (!opts.onEnd) throw new Error('onEnd handler is required');
|
|
10
|
+
if (!ms) throw new Error('ms duration is required');
|
|
11
|
+
this.onEnd = opts.onEnd;
|
|
12
|
+
this.initialMs = ms;
|
|
13
|
+
this.startTimestamp = Date.now();
|
|
14
|
+
this.timer = this.create(this.onEnd, ms);
|
|
15
|
+
}
|
|
16
|
+
create(cb, ms) {
|
|
17
|
+
if (this.timer) this.clear();
|
|
18
|
+
return setTimeout(() => cb ? cb() : this.onEnd(), ms || this.initialMs);
|
|
19
|
+
}
|
|
20
|
+
clear() {
|
|
21
|
+
clearTimeout(this.timer);
|
|
22
|
+
this.timer = null;
|
|
23
|
+
}
|
|
24
|
+
end() {
|
|
25
|
+
this.clear();
|
|
26
|
+
this.onEnd();
|
|
27
|
+
}
|
|
28
|
+
isValid() {
|
|
29
|
+
return this.initialMs - (Date.now() - this.startTimestamp) > 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Timer = Timer;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _timer = require("./timer");
|
|
4
|
+
jest.useFakeTimers();
|
|
5
|
+
let now;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
now = Date.now();
|
|
8
|
+
jest.setSystemTime(now);
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
describe('constructor', () => {
|
|
14
|
+
test('appropriate properties are set with valid values -- no refresh', () => {
|
|
15
|
+
const timer = new _timer.Timer({
|
|
16
|
+
onEnd: jest.fn()
|
|
17
|
+
}, 100);
|
|
18
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
|
|
19
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
test('appropriate properties are set with valid values -- with refresh', () => {
|
|
22
|
+
const timer = new _timer.Timer({
|
|
23
|
+
onEnd: jest.fn()
|
|
24
|
+
}, 100);
|
|
25
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
|
|
26
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
test('required keys are enforced', () => {
|
|
29
|
+
try {
|
|
30
|
+
new _timer.Timer({}, 100);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
expect(e).toEqual(new Error('onEnd handler is required'));
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
new _timer.Timer({
|
|
36
|
+
onEnd: jest.fn()
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
expect(e).toEqual(new Error('ms duration is required'));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('create()', () => {
|
|
44
|
+
test('Create sets a timeout that can execute a cb', () => {
|
|
45
|
+
const timer = new _timer.Timer({
|
|
46
|
+
onEnd: jest.fn()
|
|
47
|
+
}, 100);
|
|
48
|
+
expect(timer.timer).toBeTruthy();
|
|
49
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
50
|
+
jest.runOnlyPendingTimers();
|
|
51
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
test('Create can fallback to use defaults', () => {
|
|
54
|
+
let called = 0;
|
|
55
|
+
const timer1 = new _timer.Timer({
|
|
56
|
+
onEnd: jest.fn()
|
|
57
|
+
}, 100);
|
|
58
|
+
timer1.create();
|
|
59
|
+
const timer2 = new _timer.Timer({
|
|
60
|
+
onEnd: jest.fn()
|
|
61
|
+
}, 100);
|
|
62
|
+
timer2.create(timer2.onEnd);
|
|
63
|
+
const timer3 = new _timer.Timer({
|
|
64
|
+
onEnd: jest.fn()
|
|
65
|
+
}, 100);
|
|
66
|
+
timer3.create(undefined, 100);
|
|
67
|
+
jest.runAllTimers(200);
|
|
68
|
+
expect(timer1.onEnd).toHaveBeenCalledTimes(1);
|
|
69
|
+
expect(timer2.onEnd).toHaveBeenCalledTimes(1);
|
|
70
|
+
expect(timer3.onEnd).toHaveBeenCalledTimes(1);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('clear()', () => {
|
|
74
|
+
test('clear prevents the callback from firing and deletes the pointer', () => {
|
|
75
|
+
const timer = new _timer.Timer({
|
|
76
|
+
onEnd: jest.fn()
|
|
77
|
+
}, 100);
|
|
78
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
79
|
+
timer.clear();
|
|
80
|
+
jest.advanceTimersByTime(150);
|
|
81
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
82
|
+
expect(timer.timer).toEqual(null);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('end()', () => {
|
|
86
|
+
test('end clears the callback and calls the onEnd callback', () => {
|
|
87
|
+
const timer = new _timer.Timer({
|
|
88
|
+
onEnd: jest.fn()
|
|
89
|
+
}, 100);
|
|
90
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
91
|
+
timer.end();
|
|
92
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(timer.timer).toEqual(null);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('isValid', () => {
|
|
97
|
+
test('isValid validates timeStamps', () => {
|
|
98
|
+
const timer = new _timer.Timer({
|
|
99
|
+
onEnd: jest.fn()
|
|
100
|
+
}, 100);
|
|
101
|
+
expect(timer.isValid()).toEqual(true);
|
|
102
|
+
timer.startTimestamp -= 100;
|
|
103
|
+
expect(timer.isValid()).toEqual(false);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.addPN = addPN;
|
|
7
7
|
exports.addPT = addPT;
|
|
8
|
-
exports.addRel = addRel;
|
|
9
8
|
exports.navTimingValues = void 0;
|
|
10
9
|
/*
|
|
11
10
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
@@ -35,43 +34,65 @@ var LOAD_EVENT = 'loadEvent';
|
|
|
35
34
|
var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent';
|
|
36
35
|
var navTimingValues = [];
|
|
37
36
|
exports.navTimingValues = navTimingValues;
|
|
38
|
-
function
|
|
37
|
+
function getPntType(type) {
|
|
38
|
+
if (typeof type == 'number') return type;
|
|
39
|
+
const types = {
|
|
40
|
+
navigate: undefined,
|
|
41
|
+
reload: 1,
|
|
42
|
+
back_forward: 2,
|
|
43
|
+
prerender: 3
|
|
44
|
+
};
|
|
45
|
+
return types[type];
|
|
46
|
+
}
|
|
47
|
+
function addPT(offset, pt) {
|
|
48
|
+
let v = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
49
|
+
let isL1Api = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
50
|
+
if (!pt) return;
|
|
39
51
|
v.of = offset;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
handleValue(v.of, v, 'n', true);
|
|
53
|
+
handleValue(pt[UNLOAD_EVENT + START], v, 'u', isL1Api);
|
|
54
|
+
handleValue(pt[REDIRECT + START], v, 'r', isL1Api);
|
|
55
|
+
handleValue(pt[UNLOAD_EVENT + END], v, 'ue', isL1Api);
|
|
56
|
+
handleValue(pt[REDIRECT + END], v, 're', isL1Api);
|
|
57
|
+
handleValue(pt['fetch' + START], v, 'f', isL1Api);
|
|
58
|
+
handleValue(pt[DOMAIN_LOOKUP + START], v, 'dn', isL1Api);
|
|
59
|
+
handleValue(pt[DOMAIN_LOOKUP + END], v, 'dne', isL1Api);
|
|
60
|
+
handleValue(pt['c' + ONNECT + START], v, 'c', isL1Api);
|
|
61
|
+
handleValue(pt['secureC' + ONNECT + 'ion' + START], v, 's', isL1Api);
|
|
62
|
+
handleValue(pt['c' + ONNECT + END], v, 'ce', isL1Api);
|
|
63
|
+
handleValue(pt[REQUEST + START], v, 'rq', isL1Api);
|
|
64
|
+
handleValue(pt[RESPONSE + START], v, 'rp', isL1Api);
|
|
65
|
+
handleValue(pt[RESPONSE + END], v, 'rpe', isL1Api);
|
|
66
|
+
handleValue(pt.domLoading, v, 'dl', isL1Api);
|
|
67
|
+
handleValue(pt.domInteractive, v, 'di', isL1Api);
|
|
68
|
+
handleValue(pt[DOM_CONTENT_LOAD_EVENT + START], v, 'ds', isL1Api);
|
|
69
|
+
handleValue(pt[DOM_CONTENT_LOAD_EVENT + END], v, 'de', isL1Api);
|
|
70
|
+
handleValue(pt.domComplete, v, 'dc', isL1Api);
|
|
71
|
+
handleValue(pt[LOAD_EVENT + START], v, 'l', isL1Api);
|
|
72
|
+
handleValue(pt[LOAD_EVENT + END], v, 'le', isL1Api);
|
|
61
73
|
return v;
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
// Add Performance Navigation values to the given object
|
|
65
77
|
function addPN(pn, v) {
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
handleValue(getPntType(pn.type), v, 'ty');
|
|
79
|
+
handleValue(pn.redirectCount, v, 'rc');
|
|
68
80
|
return v;
|
|
69
81
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
82
|
+
function handleValue(value, obj, prop, isOldApi) {
|
|
83
|
+
/*
|
|
84
|
+
For L2 Timing API, the value will already be a relative-to-previous-document DOMHighResTimeStamp.
|
|
85
|
+
For L1 (deprecated) Timing, the value is an UNIX epoch timestamp, which we will convert to a relative time using our offset.
|
|
86
|
+
PNT.type is reported as undefined, 1, 2, etc -- note that zero-value properties will be recorded as 'undefined', however DEM interprets undefined "types" as "navigate"
|
|
87
|
+
*/
|
|
72
88
|
if (typeof value === 'number' && value > 0) {
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
// note that zero-value properties will be recorded as 'undefined'
|
|
90
|
+
if (isOldApi) {
|
|
91
|
+
const offset = obj?.of > 0 ? obj.of : 0; // expect an epoch timestamp, if called by addPT
|
|
92
|
+
value = Math.max(value - offset, 0);
|
|
93
|
+
}
|
|
94
|
+
value = Math.round(value);
|
|
95
|
+
obj[prop] = value;
|
|
75
96
|
}
|
|
76
|
-
navTimingValues.push(
|
|
97
|
+
navTimingValues.push(value);
|
|
77
98
|
}
|