@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,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
jest.mock('./contextual-ee', () => ({
|
|
7
|
+
__esModule: true,
|
|
8
|
+
ee: {
|
|
9
|
+
buffer: jest.fn(),
|
|
10
|
+
emit: jest.fn(),
|
|
11
|
+
get: jest.fn(() => ({
|
|
12
|
+
buffer: jest.fn(),
|
|
13
|
+
emit: jest.fn()
|
|
14
|
+
}))
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.resetModules();
|
|
19
|
+
jest.resetAllMocks();
|
|
20
|
+
});
|
|
21
|
+
test('it should create and use a default event-emitter', async () => {
|
|
22
|
+
const {
|
|
23
|
+
ee
|
|
24
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
25
|
+
const {
|
|
26
|
+
handle
|
|
27
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
28
|
+
const handleEE = jest.mocked(ee.get).mock.results[0].value;
|
|
29
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
30
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
31
|
+
const eventContext = {};
|
|
32
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
33
|
+
handle(eventType, eventArgs, eventContext, eventGroup);
|
|
34
|
+
expect(handleEE.buffer).toHaveBeenCalledWith([eventType], eventGroup);
|
|
35
|
+
expect(handleEE.emit).toHaveBeenCalledWith(eventType, eventArgs, eventContext);
|
|
36
|
+
});
|
|
37
|
+
test('it should use the provided scoped event-emitter', async () => {
|
|
38
|
+
const {
|
|
39
|
+
ee
|
|
40
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
41
|
+
const {
|
|
42
|
+
handle
|
|
43
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
44
|
+
const scopedEE = {
|
|
45
|
+
buffer: jest.fn(),
|
|
46
|
+
emit: jest.fn()
|
|
47
|
+
};
|
|
48
|
+
const handleEE = jest.mocked(ee.get).mock.results[0].value;
|
|
49
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
50
|
+
const eventArgs = ['a', 'b', 'c'];
|
|
51
|
+
const eventContext = {};
|
|
52
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
53
|
+
handle(eventType, eventArgs, eventContext, eventGroup, scopedEE);
|
|
54
|
+
expect(handleEE.buffer).not.toHaveBeenCalled();
|
|
55
|
+
expect(handleEE.emit).not.toHaveBeenCalled();
|
|
56
|
+
expect(scopedEE.buffer).toHaveBeenCalledWith([eventType], eventGroup);
|
|
57
|
+
expect(scopedEE.emit).toHaveBeenCalledWith(eventType, eventArgs, eventContext);
|
|
58
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
5
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
6
|
+
jest.mock('./handle', () => ({
|
|
7
|
+
__esModule: true,
|
|
8
|
+
handleEE: {}
|
|
9
|
+
}));
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
jest.resetModules();
|
|
12
|
+
jest.resetAllMocks();
|
|
13
|
+
});
|
|
14
|
+
test('should default group to "feature"', async () => {
|
|
15
|
+
const {
|
|
16
|
+
handleEE
|
|
17
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
18
|
+
const {
|
|
19
|
+
registerHandler
|
|
20
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./register-handler')));
|
|
21
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
22
|
+
const eventHandler = jest.fn();
|
|
23
|
+
registerHandler(eventType, eventHandler);
|
|
24
|
+
expect(registerHandler.handlers.feature).toEqual(expect.objectContaining({
|
|
25
|
+
[eventType]: [expect.arrayContaining([handleEE, eventHandler])]
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
test('should use the provided group', async () => {
|
|
29
|
+
const {
|
|
30
|
+
handleEE
|
|
31
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./handle')));
|
|
32
|
+
const {
|
|
33
|
+
registerHandler
|
|
34
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./register-handler')));
|
|
35
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
36
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
37
|
+
const eventHandler = jest.fn();
|
|
38
|
+
registerHandler(eventType, eventHandler, eventGroup);
|
|
39
|
+
expect(registerHandler.handlers[eventGroup]).toEqual(expect.objectContaining({
|
|
40
|
+
[eventType]: [expect.arrayContaining([handleEE, eventHandler])]
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
43
|
+
test('should use the provided event-emitter', async () => {
|
|
44
|
+
const {
|
|
45
|
+
registerHandler
|
|
46
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./register-handler')));
|
|
47
|
+
const scopedEE = {};
|
|
48
|
+
const eventType = _faker.faker.datatype.uuid();
|
|
49
|
+
const eventGroup = _faker.faker.datatype.uuid();
|
|
50
|
+
const eventHandler = jest.fn();
|
|
51
|
+
registerHandler(eventType, eventHandler, eventGroup, scopedEE);
|
|
52
|
+
expect(registerHandler.handlers[eventGroup]).toEqual(expect.objectContaining({
|
|
53
|
+
[eventType]: [expect.arrayContaining([scopedEE, eventHandler])]
|
|
54
|
+
}));
|
|
55
|
+
});
|
|
@@ -39,10 +39,12 @@ function eventListenerOpts(useCapture, abortSignal) {
|
|
|
39
39
|
/** Do not use this within the worker context. */
|
|
40
40
|
function windowAddEventListener(event, listener) {
|
|
41
41
|
let capture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
42
|
-
|
|
42
|
+
let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
|
|
43
|
+
window.addEventListener(event, listener, eventListenerOpts(capture, abortSignal));
|
|
43
44
|
}
|
|
44
45
|
/** Do not use this within the worker context. */
|
|
45
46
|
function documentAddEventListener(event, listener) {
|
|
46
47
|
let capture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
47
|
-
|
|
48
|
+
let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
|
|
49
|
+
document.addEventListener(event, listener, eventListenerOpts(capture, abortSignal));
|
|
48
50
|
}
|
|
@@ -27,17 +27,21 @@ class HarvestScheduler extends _sharedContext.SharedContext {
|
|
|
27
27
|
this.aborted = false; // this controls the per-interval and final harvests for the scheduler (currently per feature specific!)
|
|
28
28
|
|
|
29
29
|
this.harvest = new _harvest.Harvest(this.sharedContext);
|
|
30
|
-
(0, _eol.subscribeToEOL)(() => {
|
|
31
|
-
if (this.aborted) return;
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.runHarvest({
|
|
36
|
-
unload: true
|
|
37
|
-
});
|
|
38
|
-
}, (0, _config.getConfigurationValue)(this.sharedContext.agentIdentifier, 'allow_bfcache')); // TO DO: remove feature flag after rls stable
|
|
39
|
-
}
|
|
31
|
+
// unload if EOL mechanism fires
|
|
32
|
+
(0, _eol.subscribeToEOL)(this.unload.bind(this), (0, _config.getConfigurationValue)(this.sharedContext.agentIdentifier, 'allow_bfcache')); // TO DO: remove feature flag after rls stable
|
|
40
33
|
|
|
34
|
+
// unload if session resets
|
|
35
|
+
this.sharedContext?.ee.on('session-reset', this.unload.bind(this));
|
|
36
|
+
}
|
|
37
|
+
unload() {
|
|
38
|
+
if (this.aborted) return;
|
|
39
|
+
// If opts.onUnload is defined, these are special actions to execute before attempting to send the final payload.
|
|
40
|
+
if (this.opts.onUnload) this.opts.onUnload();
|
|
41
|
+
this.runHarvest({
|
|
42
|
+
unload: true
|
|
43
|
+
});
|
|
44
|
+
}
|
|
41
45
|
startTimer(interval, initialDelay) {
|
|
42
46
|
this.interval = interval;
|
|
43
47
|
this.started = true;
|
|
@@ -80,8 +84,7 @@ class HarvestScheduler extends _sharedContext.SharedContext {
|
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
} else {
|
|
83
|
-
|
|
84
|
-
this.harvest.sendX(this.endpoint, opts, runAfterSending);
|
|
87
|
+
this.harvest.sendX(this.endpoint, opts, onHarvestFinished);
|
|
85
88
|
}
|
|
86
89
|
if (this.started) {
|
|
87
90
|
this.scheduleHarvest();
|
|
@@ -17,7 +17,7 @@ var _eventListenerOpts = require("../event-listener/event-listener-opts");
|
|
|
17
17
|
var _obfuscate = require("../util/obfuscate");
|
|
18
18
|
var _traverse = require("../util/traverse");
|
|
19
19
|
var _sharedContext = require("../context/shared-context");
|
|
20
|
-
var
|
|
20
|
+
var _env = require("../constants/env.npm");
|
|
21
21
|
var _globalScope = require("../util/global-scope");
|
|
22
22
|
/*
|
|
23
23
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
@@ -127,6 +127,8 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
127
127
|
|
|
128
128
|
// Get bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
|
|
129
129
|
agentRuntime.bytesSent[endpoint] = (agentRuntime.bytesSent[endpoint] || 0) + body?.length || 0;
|
|
130
|
+
// Get query bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
|
|
131
|
+
agentRuntime.queryBytesSent[endpoint] = (agentRuntime.queryBytesSent[endpoint] || 0) + fullUrl.split('?').slice(-1)[0]?.length || 0;
|
|
130
132
|
|
|
131
133
|
/* Since workers don't support sendBeacon right now, or Image(), they can only use XHR method.
|
|
132
134
|
Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
|
|
@@ -165,9 +167,9 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
165
167
|
var info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
|
|
166
168
|
var location = (0, _cleanUrl.cleanURL)((0, _location.getLocation)());
|
|
167
169
|
var ref = this.obfuscator.shouldObfuscate() ? this.obfuscator.obfuscateString(location) : location;
|
|
168
|
-
return ['?a=' + info.applicationID, (0, _encode.param)('sa', info.sa ? '' + info.sa : ''), (0, _encode.param)('v',
|
|
170
|
+
return ['?a=' + info.applicationID, (0, _encode.param)('sa', info.sa ? '' + info.sa : ''), (0, _encode.param)('v', _env.VERSION), transactionNameParam(info), (0, _encode.param)('ct', runtime.customTransaction), '&rst=' + (0, _now.now)(), '&ck=0',
|
|
169
171
|
// ck param DEPRECATED - still expected by backend
|
|
170
|
-
'&s=' + (runtime.
|
|
172
|
+
'&s=' + (runtime.session?.value || '0'),
|
|
171
173
|
// the 0 id encaps all untrackable and default traffic
|
|
172
174
|
(0, _encode.param)('ref', ref), (0, _encode.param)('ptid', runtime.ptid ? '' + runtime.ptid : '')].join('');
|
|
173
175
|
}
|
|
@@ -11,15 +11,23 @@ var _globalScope = require("../util/global-scope");
|
|
|
11
11
|
* SPDX-License-Identifier: Apache-2.0
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
// Start assigning ids at 1 so 0 can always be used for
|
|
14
|
+
// Start assigning ids at 1 so 0 can always be used for Window or WorkerGlobalScope, without
|
|
15
15
|
// actually setting it (which would create a global variable).
|
|
16
|
+
let index = 1;
|
|
17
|
+
const prop = 'nr@id';
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Tags a specified object with an identifier if it does not already
|
|
21
|
+
* have one. If the object is the global scope, zero will be returned
|
|
22
|
+
* and the object will not be modified. If the object already contains
|
|
23
|
+
* an identifier, it will be returned without modification. If the passed
|
|
24
|
+
* value is not an object, function, or array, -1 will be returned without
|
|
25
|
+
* modifying the passed value.
|
|
26
|
+
* @param {object|function|array} obj Object to be tagged with an identifier
|
|
27
|
+
* @returns {number} Identifier of the given object
|
|
28
|
+
*/
|
|
21
29
|
function id(obj) {
|
|
22
|
-
|
|
30
|
+
const type = typeof obj;
|
|
23
31
|
// We can only tag objects, functions, and arrays with ids.
|
|
24
32
|
// For all primitive values we instead return -1.
|
|
25
33
|
if (!obj || !(type === 'object' || type === 'function')) return -1;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
4
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
5
|
+
let idFn;
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
idFn = (await Promise.resolve().then(() => _interopRequireWildcard(require('./id')))).id;
|
|
8
|
+
});
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
jest.resetModules();
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
test.each([{
|
|
14
|
+
input: undefined,
|
|
15
|
+
expected: -1,
|
|
16
|
+
title: 'id of undefined is -1'
|
|
17
|
+
}, {
|
|
18
|
+
input: null,
|
|
19
|
+
expected: -1,
|
|
20
|
+
title: 'id of null is -1'
|
|
21
|
+
}, {
|
|
22
|
+
input: 2,
|
|
23
|
+
expected: -1,
|
|
24
|
+
title: 'id of number is -1'
|
|
25
|
+
}, {
|
|
26
|
+
input: 'foo',
|
|
27
|
+
expected: -1,
|
|
28
|
+
title: 'id of string is -1'
|
|
29
|
+
}])('$title', _ref => {
|
|
30
|
+
let {
|
|
31
|
+
input,
|
|
32
|
+
expected
|
|
33
|
+
} = _ref;
|
|
34
|
+
const result = idFn(input);
|
|
35
|
+
expect(typeof result).toEqual('number');
|
|
36
|
+
expect(result).toEqual(expected);
|
|
37
|
+
});
|
|
38
|
+
test('id values increment sequentially', () => {
|
|
39
|
+
const inputA = {};
|
|
40
|
+
const inputB = {};
|
|
41
|
+
const resultA = idFn(inputA);
|
|
42
|
+
const resultB = idFn(inputB);
|
|
43
|
+
expect(resultA - resultB).toEqual(-1);
|
|
44
|
+
});
|
|
45
|
+
test('id is correctly assigned to function type', () => {
|
|
46
|
+
const input = jest.fn();
|
|
47
|
+
const result = idFn(input);
|
|
48
|
+
expect(result).toEqual(1);
|
|
49
|
+
expect(input['nr@id']).toEqual(1);
|
|
50
|
+
});
|
|
51
|
+
test('id is correctly assigned to object type', () => {
|
|
52
|
+
const input = {};
|
|
53
|
+
const result = idFn(input);
|
|
54
|
+
expect(result).toEqual(1);
|
|
55
|
+
expect(input['nr@id']).toEqual(1);
|
|
56
|
+
});
|
|
57
|
+
test('id is the same when called twice on the same input', () => {
|
|
58
|
+
const input = {};
|
|
59
|
+
const result1 = idFn(input);
|
|
60
|
+
const result2 = idFn(input);
|
|
61
|
+
expect(result1).toEqual(1);
|
|
62
|
+
expect(result2).toEqual(1);
|
|
63
|
+
expect(input['nr@id']).toEqual(1);
|
|
64
|
+
});
|
|
65
|
+
test('id is zero on global scope', async () => {
|
|
66
|
+
const result = idFn(global);
|
|
67
|
+
expect(result).toEqual(0);
|
|
68
|
+
});
|
|
69
|
+
test('id on prototype is correctly inherited', () => {
|
|
70
|
+
const fn = jest.fn();
|
|
71
|
+
const a = {};
|
|
72
|
+
idFn(a);
|
|
73
|
+
fn.prototype = a;
|
|
74
|
+
const b = new fn();
|
|
75
|
+
expect(b['nr@id']).toEqual(a['nr@id']);
|
|
76
|
+
});
|
|
77
|
+
test('id on prototype is different from instance', () => {
|
|
78
|
+
const fn = jest.fn();
|
|
79
|
+
const a = {};
|
|
80
|
+
idFn(a);
|
|
81
|
+
fn.prototype = a;
|
|
82
|
+
const b = new fn();
|
|
83
|
+
const result = idFn(b);
|
|
84
|
+
expect(b['nr@id']).toEqual(result);
|
|
85
|
+
});
|
|
@@ -13,72 +13,96 @@ var _globalScope = require("../util/global-scope");
|
|
|
13
13
|
* SPDX-License-Identifier: Apache-2.0
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
const uuidv4Template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a random single hexadecimal value from a provided random value
|
|
20
|
+
* table and corresponding index. If a random value table is not provided,
|
|
21
|
+
* Math.random will be used to generate the value.
|
|
22
|
+
*
|
|
23
|
+
* @param {Uint8Array} valueTable Random value table typically generated using
|
|
24
|
+
* the built-in crypto engine.
|
|
25
|
+
* @param {int} tableIndex The index of the value table to use for generating
|
|
26
|
+
* the hexadecimal value.
|
|
27
|
+
* @returns {int} single hexadecimal value in decimal format
|
|
28
|
+
*/
|
|
29
|
+
function getRandomValue(valueTable, tableIndex) {
|
|
30
|
+
if (valueTable) {
|
|
31
|
+
/**
|
|
32
|
+
* The value table could have any number value in the given index. Use
|
|
33
|
+
* bitwise AND to ensure the value we generate is a valid hex value.
|
|
34
|
+
* x & 15 will ensure the value converted to hex using `toString(16)`
|
|
35
|
+
* falls within the range of 0 and 15 inclusively.
|
|
36
|
+
*/
|
|
37
|
+
return valueTable[tableIndex] & 15;
|
|
38
|
+
} else {
|
|
39
|
+
return Math.random() * 16 | 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generates a RFC compliant UUIDv4 using native browser crypto engine. If the browser
|
|
45
|
+
* does not support the crypto engine, the function will fallback to insecure Math.random()
|
|
46
|
+
* @returns {string} uuid version 4 string
|
|
47
|
+
*/
|
|
16
48
|
function generateUuid() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
49
|
+
const crypto = _globalScope.globalScope?.crypto || _globalScope.globalScope?.msCrypto;
|
|
50
|
+
let randomValueTable;
|
|
51
|
+
let randomValueIndex = 0;
|
|
20
52
|
if (crypto && crypto.getRandomValues) {
|
|
21
53
|
// eslint-disable-next-line
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
function getRandomValue() {
|
|
25
|
-
if (randomVals) {
|
|
26
|
-
// same as % 16
|
|
27
|
-
return randomVals[rvIndex++] & 15;
|
|
28
|
-
} else {
|
|
29
|
-
return Math.random() * 16 | 0;
|
|
30
|
-
}
|
|
54
|
+
randomValueTable = crypto.getRandomValues(new Uint8Array(31));
|
|
31
55
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var c;
|
|
37
|
-
for (var i = 0; i < template.length; i++) {
|
|
38
|
-
c = template[i];
|
|
39
|
-
if (c === 'x') {
|
|
40
|
-
id += getRandomValue().toString(16);
|
|
41
|
-
} else if (c === 'y') {
|
|
56
|
+
return uuidv4Template.split('').map(templateInput => {
|
|
57
|
+
if (templateInput === 'x') {
|
|
58
|
+
return getRandomValue(randomValueTable, ++randomValueIndex).toString(16);
|
|
59
|
+
} else if (templateInput === 'y') {
|
|
42
60
|
// this is the uuid variant per spec (8, 9, a, b)
|
|
43
61
|
// % 4, then shift to get values 8-11
|
|
44
|
-
|
|
45
|
-
id += c.toString(16);
|
|
62
|
+
return (getRandomValue() & 0x3 | 0x8).toString(16);
|
|
46
63
|
} else {
|
|
47
|
-
|
|
64
|
+
return templateInput;
|
|
48
65
|
}
|
|
66
|
+
}).join('');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Generates a string of the given length containing only hexadecimal
|
|
71
|
+
* value 0-9 and a-f.
|
|
72
|
+
* @param {int} length length of the string to generate
|
|
73
|
+
* @returns {string} generated hex string
|
|
74
|
+
*/
|
|
75
|
+
function generateRandomHexString(length) {
|
|
76
|
+
const crypto = _globalScope.globalScope?.crypto || _globalScope.globalScope?.msCrypto;
|
|
77
|
+
let randomValueTable;
|
|
78
|
+
let randomValueIndex = 0;
|
|
79
|
+
if (crypto && crypto.getRandomValues) {
|
|
80
|
+
// eslint-disable-next-line
|
|
81
|
+
randomValueTable = crypto.getRandomValues(new Uint8Array(31));
|
|
49
82
|
}
|
|
50
|
-
|
|
83
|
+
const chars = [];
|
|
84
|
+
for (var i = 0; i < length; i++) {
|
|
85
|
+
chars.push(getRandomValue(randomValueTable, ++randomValueIndex).toString(16));
|
|
86
|
+
}
|
|
87
|
+
return chars.join('');
|
|
51
88
|
}
|
|
52
89
|
|
|
53
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Generates a 16 character length hexadecimal string.
|
|
92
|
+
* per DT-spec.
|
|
93
|
+
* @see generateRandomHexString
|
|
94
|
+
* @returns {string} generated hex string
|
|
95
|
+
*/
|
|
54
96
|
function generateSpanId() {
|
|
55
97
|
return generateRandomHexString(16);
|
|
56
98
|
}
|
|
57
99
|
|
|
58
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Generates a 32 character length hexadecimal string.
|
|
102
|
+
* per DT-spec.
|
|
103
|
+
* @see generateRandomHexString
|
|
104
|
+
* @returns {string} generated hex string
|
|
105
|
+
*/
|
|
59
106
|
function generateTraceId() {
|
|
60
107
|
return generateRandomHexString(32);
|
|
61
|
-
}
|
|
62
|
-
function generateRandomHexString(length) {
|
|
63
|
-
var randomVals = null;
|
|
64
|
-
var rvIndex = 0;
|
|
65
|
-
var crypto = self.crypto || self.msCrypto;
|
|
66
|
-
// eslint-disable-next-line
|
|
67
|
-
if (crypto && crypto.getRandomValues && Uint8Array) {
|
|
68
|
-
// eslint-disable-next-line
|
|
69
|
-
randomVals = crypto.getRandomValues(new Uint8Array(31));
|
|
70
|
-
}
|
|
71
|
-
var chars = [];
|
|
72
|
-
for (var i = 0; i < length; i++) {
|
|
73
|
-
chars.push(getRandomValue().toString(16));
|
|
74
|
-
}
|
|
75
|
-
return chars.join('');
|
|
76
|
-
function getRandomValue() {
|
|
77
|
-
if (randomVals) {
|
|
78
|
-
// same as % 16
|
|
79
|
-
return randomVals[rvIndex++] & 15;
|
|
80
|
-
} else {
|
|
81
|
-
return Math.random() * 16 | 0;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
108
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
4
|
+
var uniqueId = _interopRequireWildcard(require("./unique-id"));
|
|
5
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
6
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
const getRandomValues = jest.fn(arr => _crypto.default.randomBytes(arr.length));
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
delete global.crypto;
|
|
11
|
+
});
|
|
12
|
+
describe('generateUuid', () => {
|
|
13
|
+
const uuidv4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
14
|
+
test('should generate a uuidv4 that matches the expected format', () => {
|
|
15
|
+
const id = uniqueId.generateUuid();
|
|
16
|
+
expect(uuidv4Regex.test(id)).toEqual(true);
|
|
17
|
+
});
|
|
18
|
+
test('should support using native crypto library', () => {
|
|
19
|
+
global.crypto = {
|
|
20
|
+
getRandomValues
|
|
21
|
+
};
|
|
22
|
+
const id = uniqueId.generateUuid();
|
|
23
|
+
expect(uuidv4Regex.test(id)).toEqual(true);
|
|
24
|
+
expect(getRandomValues).toHaveBeenCalledTimes(1);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('generateRandomHexString', () => {
|
|
28
|
+
const hexRegex = /^[0-9a-f]{8}$/;
|
|
29
|
+
test('should generate a valid hex string', () => {
|
|
30
|
+
const id = uniqueId.generateRandomHexString(8);
|
|
31
|
+
expect(hexRegex.test(id)).toEqual(true);
|
|
32
|
+
});
|
|
33
|
+
test('should support using native crypto library', () => {
|
|
34
|
+
global.crypto = {
|
|
35
|
+
getRandomValues
|
|
36
|
+
};
|
|
37
|
+
const id = uniqueId.generateRandomHexString(8);
|
|
38
|
+
expect(hexRegex.test(id)).toEqual(true);
|
|
39
|
+
expect(getRandomValues).toHaveBeenCalledTimes(1);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
test('generateSpanId should generate a 16 character hex string', () => {
|
|
43
|
+
const id = uniqueId.generateSpanId();
|
|
44
|
+
expect(/^[0-9a-f]{16}$/.test(id)).toEqual(true);
|
|
45
|
+
});
|
|
46
|
+
test('generateTraceId should generate a 32 character hex string', () => {
|
|
47
|
+
const id = uniqueId.generateTraceId();
|
|
48
|
+
expect(/^[0-9a-f]{32}$/.test(id)).toEqual(true);
|
|
49
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PREFIX = exports.DEFAULT_INACTIVE_MS = exports.DEFAULT_EXPIRES_MS = void 0;
|
|
7
|
+
const PREFIX = 'NRBA';
|
|
8
|
+
exports.PREFIX = PREFIX;
|
|
9
|
+
const DEFAULT_EXPIRES_MS = 14400000;
|
|
10
|
+
exports.DEFAULT_EXPIRES_MS = DEFAULT_EXPIRES_MS;
|
|
11
|
+
const DEFAULT_INACTIVE_MS = 1800000;
|
|
12
|
+
exports.DEFAULT_INACTIVE_MS = DEFAULT_INACTIVE_MS;
|