@newrelic/browser-agent 1.234.0 → 1.236.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.
Files changed (372) hide show
  1. package/README.md +42 -2
  2. package/dist/cjs/common/config/state/init.js +3 -0
  3. package/dist/cjs/common/config/state/runtime.js +4 -4
  4. package/dist/cjs/common/constants/env.cdn.js +2 -2
  5. package/dist/cjs/common/constants/env.npm.js +1 -1
  6. package/dist/cjs/common/constants/runtime.js +52 -0
  7. package/dist/cjs/common/constants/shared-channel.js +19 -0
  8. package/dist/cjs/common/event-listener/event-listener-opts.js +3 -3
  9. package/dist/cjs/common/harvest/harvest-scheduler.js +35 -16
  10. package/dist/cjs/common/harvest/harvest.js +163 -144
  11. package/dist/cjs/common/harvest/types.js +54 -0
  12. package/dist/cjs/common/ids/id.js +2 -2
  13. package/dist/cjs/common/ids/unique-id.js +3 -3
  14. package/dist/cjs/common/session/session-entity.js +21 -13
  15. package/dist/cjs/common/timer/interaction-timer.js +3 -3
  16. package/dist/cjs/common/unload/eol.js +10 -11
  17. package/dist/cjs/common/url/canonicalize-url.js +2 -2
  18. package/dist/cjs/common/url/parse-url.js +3 -3
  19. package/dist/cjs/common/url/protocol.js +2 -2
  20. package/dist/cjs/common/util/feature-flags.js +23 -12
  21. package/dist/cjs/common/util/obfuscate.js +2 -2
  22. package/dist/cjs/common/util/submit-data.js +61 -79
  23. package/dist/cjs/common/window/nreum.js +14 -14
  24. package/dist/cjs/common/wrap/wrap-events.js +3 -3
  25. package/dist/cjs/common/wrap/wrap-fetch.js +5 -5
  26. package/dist/cjs/common/wrap/wrap-history.js +2 -2
  27. package/dist/cjs/common/wrap/wrap-jsonp.js +2 -2
  28. package/dist/cjs/common/wrap/wrap-mutation.js +2 -2
  29. package/dist/cjs/common/wrap/wrap-promise.js +2 -2
  30. package/dist/cjs/common/wrap/wrap-raf.js +3 -3
  31. package/dist/cjs/common/wrap/wrap-timer.js +5 -5
  32. package/dist/cjs/common/wrap/wrap-xhr.js +3 -3
  33. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  34. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +2 -2
  35. package/dist/cjs/features/ajax/instrument/index.js +6 -7
  36. package/dist/cjs/features/jserrors/aggregate/index.js +11 -4
  37. package/dist/cjs/features/jserrors/instrument/index.js +6 -19
  38. package/dist/cjs/features/metrics/aggregate/framework-detection.js +2 -2
  39. package/dist/cjs/features/metrics/aggregate/index.js +3 -3
  40. package/dist/cjs/features/page_action/aggregate/index.js +3 -3
  41. package/dist/cjs/features/page_view_event/aggregate/index.js +10 -11
  42. package/dist/cjs/features/page_view_event/instrument/index.js +2 -2
  43. package/dist/cjs/features/page_view_timing/aggregate/index.js +3 -5
  44. package/dist/cjs/features/page_view_timing/instrument/index.js +2 -2
  45. package/dist/cjs/features/session_replay/aggregate/index.js +99 -82
  46. package/dist/cjs/features/session_replay/replay-mode.js +28 -0
  47. package/dist/cjs/features/session_trace/aggregate/index.js +222 -99
  48. package/dist/cjs/features/session_trace/constants.js +1 -3
  49. package/dist/cjs/features/session_trace/instrument/index.js +2 -18
  50. package/dist/cjs/features/spa/aggregate/index.js +1 -1
  51. package/dist/cjs/features/spa/constants.js +0 -1
  52. package/dist/cjs/features/spa/instrument/index.js +2 -2
  53. package/dist/cjs/features/utils/agent-session.js +20 -36
  54. package/dist/cjs/features/utils/aggregate-base.js +7 -12
  55. package/dist/cjs/features/utils/handler-cache.js +28 -23
  56. package/dist/cjs/features/utils/instrument-base.js +58 -40
  57. package/dist/cjs/index.js +7 -0
  58. package/dist/cjs/loaders/agent.js +7 -1
  59. package/dist/cjs/loaders/api/api.js +2 -2
  60. package/dist/cjs/loaders/api/apiAsync.js +6 -4
  61. package/dist/cjs/loaders/configure/configure.js +2 -2
  62. package/dist/cjs/loaders/features/featureDependencies.js +2 -0
  63. package/dist/cjs/loaders/micro-agent.js +29 -38
  64. package/dist/esm/common/config/state/init.js +3 -0
  65. package/dist/esm/common/config/state/runtime.js +1 -1
  66. package/dist/esm/common/constants/env.cdn.js +2 -2
  67. package/dist/esm/common/constants/env.npm.js +1 -1
  68. package/dist/esm/common/constants/runtime.js +38 -0
  69. package/dist/esm/common/constants/shared-channel.js +12 -0
  70. package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
  71. package/dist/esm/common/harvest/harvest-scheduler.js +34 -17
  72. package/dist/esm/common/harvest/harvest.js +160 -142
  73. package/dist/esm/common/harvest/types.js +47 -0
  74. package/dist/esm/common/ids/id.js +1 -1
  75. package/dist/esm/common/ids/unique-id.js +1 -1
  76. package/dist/esm/common/session/session-entity.js +18 -12
  77. package/dist/esm/common/timer/interaction-timer.js +2 -2
  78. package/dist/esm/common/unload/eol.js +1 -2
  79. package/dist/esm/common/url/canonicalize-url.js +1 -1
  80. package/dist/esm/common/url/parse-url.js +1 -1
  81. package/dist/esm/common/url/protocol.js +1 -1
  82. package/dist/esm/common/util/feature-flags.js +23 -12
  83. package/dist/esm/common/util/obfuscate.js +2 -2
  84. package/dist/esm/common/util/submit-data.js +58 -76
  85. package/dist/esm/common/window/nreum.js +1 -1
  86. package/dist/esm/common/wrap/wrap-events.js +1 -1
  87. package/dist/esm/common/wrap/wrap-fetch.js +1 -1
  88. package/dist/esm/common/wrap/wrap-history.js +1 -1
  89. package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
  90. package/dist/esm/common/wrap/wrap-mutation.js +1 -1
  91. package/dist/esm/common/wrap/wrap-promise.js +1 -1
  92. package/dist/esm/common/wrap/wrap-raf.js +2 -2
  93. package/dist/esm/common/wrap/wrap-timer.js +2 -2
  94. package/dist/esm/common/wrap/wrap-xhr.js +1 -1
  95. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  96. package/dist/esm/features/ajax/instrument/distributed-tracing.js +1 -1
  97. package/dist/esm/features/ajax/instrument/index.js +1 -2
  98. package/dist/esm/features/jserrors/aggregate/index.js +10 -3
  99. package/dist/esm/features/jserrors/instrument/index.js +3 -16
  100. package/dist/esm/features/metrics/aggregate/framework-detection.js +1 -1
  101. package/dist/esm/features/metrics/aggregate/index.js +1 -1
  102. package/dist/esm/features/page_action/aggregate/index.js +1 -1
  103. package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
  104. package/dist/esm/features/page_view_event/instrument/index.js +1 -1
  105. package/dist/esm/features/page_view_timing/aggregate/index.js +2 -4
  106. package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
  107. package/dist/esm/features/session_replay/aggregate/index.js +92 -78
  108. package/dist/esm/features/session_replay/replay-mode.js +23 -0
  109. package/dist/esm/features/session_trace/aggregate/index.js +223 -100
  110. package/dist/esm/features/session_trace/constants.js +0 -1
  111. package/dist/esm/features/session_trace/instrument/index.js +2 -18
  112. package/dist/esm/features/spa/aggregate/index.js +1 -1
  113. package/dist/esm/features/spa/constants.js +0 -1
  114. package/dist/esm/features/spa/instrument/index.js +1 -1
  115. package/dist/esm/features/utils/agent-session.js +21 -37
  116. package/dist/esm/features/utils/aggregate-base.js +7 -12
  117. package/dist/esm/features/utils/handler-cache.js +28 -23
  118. package/dist/esm/features/utils/instrument-base.js +57 -39
  119. package/dist/esm/index.js +1 -4
  120. package/dist/esm/loaders/agent.js +7 -1
  121. package/dist/esm/loaders/api/api.js +2 -2
  122. package/dist/esm/loaders/api/apiAsync.js +3 -3
  123. package/dist/esm/loaders/configure/configure.js +1 -1
  124. package/dist/esm/loaders/features/featureDependencies.js +2 -0
  125. package/dist/esm/loaders/micro-agent.js +29 -38
  126. package/dist/types/common/config/state/init.d.ts.map +1 -1
  127. package/dist/types/common/constants/runtime.d.ts +29 -0
  128. package/dist/types/common/constants/runtime.d.ts.map +1 -0
  129. package/dist/types/common/constants/shared-channel.d.ts +5 -0
  130. package/dist/types/common/constants/shared-channel.d.ts.map +1 -0
  131. package/dist/types/common/harvest/harvest-scheduler.d.ts +5 -1
  132. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  133. package/dist/types/common/harvest/harvest.d.ts +49 -38
  134. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  135. package/dist/types/common/harvest/types.d.ts +100 -0
  136. package/dist/types/common/harvest/types.d.ts.map +1 -0
  137. package/dist/types/common/session/session-entity.d.ts +9 -5
  138. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  139. package/dist/types/common/unload/eol.d.ts.map +1 -1
  140. package/dist/types/common/util/feature-flags.d.ts +1 -0
  141. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  142. package/dist/types/common/util/submit-data.d.ts +62 -64
  143. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  144. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  145. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -1
  146. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  147. package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
  148. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  149. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  150. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  151. package/dist/types/features/session_replay/aggregate/index.d.ts +14 -5
  152. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  153. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  154. package/dist/types/features/session_replay/replay-mode.d.ts +9 -0
  155. package/dist/types/features/session_replay/replay-mode.d.ts.map +1 -0
  156. package/dist/types/features/session_trace/aggregate/index.d.ts +21 -3
  157. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  158. package/dist/types/features/session_trace/constants.d.ts +0 -1
  159. package/dist/types/features/session_trace/constants.d.ts.map +1 -1
  160. package/dist/types/features/session_trace/instrument/index.d.ts +0 -2
  161. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  162. package/dist/types/features/spa/constants.d.ts.map +1 -1
  163. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  164. package/dist/types/features/utils/aggregate-base.d.ts +6 -1
  165. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  166. package/dist/types/features/utils/handler-cache.d.ts +12 -11
  167. package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
  168. package/dist/types/features/utils/instrument-base.d.ts +17 -1
  169. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  170. package/dist/types/index.d.ts +1 -0
  171. package/dist/types/loaders/agent.d.ts +4 -4
  172. package/dist/types/loaders/agent.d.ts.map +1 -1
  173. package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
  174. package/dist/types/loaders/micro-agent.d.ts +3 -4
  175. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  176. package/package.json +14 -7
  177. package/src/common/config/__mocks__/config.js +11 -0
  178. package/src/common/config/state/init.js +1 -0
  179. package/src/common/config/state/runtime.js +1 -1
  180. package/src/common/constants/__mocks__/env.js +3 -0
  181. package/src/common/constants/__mocks__/runtime.js +8 -0
  182. package/src/common/constants/env.cdn.test.js +7 -0
  183. package/src/common/constants/env.npm.test.js +7 -0
  184. package/src/common/constants/env.test.js +7 -0
  185. package/src/common/constants/runtime.js +71 -0
  186. package/src/common/constants/runtime.test.js +168 -0
  187. package/src/common/constants/shared-channel.js +13 -0
  188. package/src/common/context/__mocks__/shared-context.js +8 -0
  189. package/src/common/event-listener/__mocks__/event-listener-opts.js +7 -0
  190. package/src/common/event-listener/event-listener-opts.js +1 -1
  191. package/src/common/harvest/__mocks__/harvest.js +13 -0
  192. package/src/common/harvest/harvest-scheduler.js +31 -19
  193. package/src/common/harvest/harvest-scheduler.test.js +491 -20
  194. package/src/common/harvest/harvest.js +147 -130
  195. package/src/common/harvest/harvest.test.js +788 -139
  196. package/src/common/harvest/types.js +47 -0
  197. package/src/common/ids/id.js +1 -1
  198. package/src/common/ids/unique-id.js +1 -1
  199. package/src/common/session/__mocks__/session-entity.js +25 -0
  200. package/src/common/session/{session-entity.test.js → session-entity.component-test.js} +71 -48
  201. package/src/common/session/session-entity.js +16 -13
  202. package/src/common/timer/interaction-timer.js +2 -2
  203. package/src/common/timing/__mocks__/now.js +1 -0
  204. package/src/common/unload/__mocks__/eol.js +1 -0
  205. package/src/common/unload/eol.js +1 -2
  206. package/src/common/url/__mocks__/clean-url.js +1 -0
  207. package/src/common/url/__mocks__/encode.js +7 -0
  208. package/src/common/url/__mocks__/location.js +1 -0
  209. package/src/common/url/canonicalize-url.js +1 -1
  210. package/src/common/url/canonicalize-url.test.js +32 -21
  211. package/src/common/url/parse-url.js +1 -1
  212. package/src/common/url/parse-url.test.js +3 -3
  213. package/src/common/url/protocol.js +1 -1
  214. package/src/common/util/__mocks__/obfuscate.js +10 -0
  215. package/src/common/util/__mocks__/stringify.js +1 -0
  216. package/src/common/util/__mocks__/submit-data.js +6 -0
  217. package/src/common/util/__mocks__/traverse.js +1 -0
  218. package/src/common/util/data-size.test.js +27 -20
  219. package/src/common/util/feature-flags.js +24 -12
  220. package/src/common/util/feature-flags.test.js +98 -0
  221. package/src/common/util/obfuscate.component-test.js +173 -0
  222. package/src/common/util/obfuscate.js +2 -2
  223. package/src/common/util/submit-data.js +42 -56
  224. package/src/common/util/submit-data.test.js +158 -137
  225. package/src/common/window/nreum.js +1 -1
  226. package/src/common/wrap/wrap-events.js +1 -1
  227. package/src/common/wrap/wrap-fetch.js +1 -1
  228. package/src/common/wrap/wrap-history.js +1 -1
  229. package/src/common/wrap/wrap-jsonp.js +1 -1
  230. package/src/common/wrap/wrap-mutation.js +1 -1
  231. package/src/common/wrap/wrap-promise.js +1 -1
  232. package/src/common/wrap/wrap-promise.test.js +2 -2
  233. package/src/common/wrap/wrap-raf.js +2 -2
  234. package/src/common/wrap/wrap-timer.js +2 -2
  235. package/src/common/wrap/wrap-xhr.js +1 -1
  236. package/src/features/ajax/aggregate/index.js +1 -1
  237. package/src/features/ajax/instrument/distributed-tracing.js +1 -1
  238. package/src/features/ajax/instrument/index.js +1 -2
  239. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
  240. package/src/features/jserrors/aggregate/index.js +12 -3
  241. package/src/features/jserrors/instrument/index.js +3 -16
  242. package/src/features/metrics/aggregate/framework-detection.js +1 -1
  243. package/src/features/metrics/aggregate/framework-detection.test.js +2 -2
  244. package/src/features/metrics/aggregate/index.js +1 -1
  245. package/src/features/page_action/aggregate/index.js +1 -1
  246. package/src/features/page_view_event/aggregate/index.js +1 -2
  247. package/src/features/page_view_event/instrument/index.js +1 -1
  248. package/src/features/page_view_timing/aggregate/index.js +2 -4
  249. package/src/features/page_view_timing/instrument/index.js +1 -1
  250. package/src/features/session_replay/aggregate/index.component-test.js +368 -0
  251. package/src/features/session_replay/aggregate/index.js +96 -71
  252. package/src/features/session_replay/instrument/index.js +0 -1
  253. package/src/features/session_replay/replay-mode.js +23 -0
  254. package/src/features/session_trace/aggregate/index.js +198 -79
  255. package/src/features/session_trace/constants.js +0 -1
  256. package/src/features/session_trace/instrument/index.js +3 -20
  257. package/src/features/spa/aggregate/index.js +1 -1
  258. package/src/features/spa/constants.js +0 -1
  259. package/src/features/spa/instrument/index.js +1 -1
  260. package/src/features/utils/agent-session.js +22 -34
  261. package/src/features/utils/agent-session.test.js +194 -0
  262. package/src/features/utils/aggregate-base.js +12 -9
  263. package/src/features/utils/aggregate-base.test.js +122 -0
  264. package/src/features/utils/feature-base.test.js +45 -0
  265. package/src/features/utils/handler-cache.js +29 -23
  266. package/src/features/utils/handler-cache.test.js +72 -0
  267. package/src/features/utils/instrument-base.js +45 -29
  268. package/src/features/utils/instrument-base.test.js +209 -0
  269. package/src/features/utils/lazy-feature-loader.test.js +37 -0
  270. package/src/index.js +1 -3
  271. package/src/loaders/agent.js +8 -1
  272. package/src/loaders/api/api.js +2 -2
  273. package/src/loaders/api/apiAsync.js +3 -3
  274. package/src/loaders/configure/configure.js +1 -1
  275. package/src/loaders/features/featureDependencies.js +2 -0
  276. package/src/loaders/micro-agent.js +26 -30
  277. package/dist/cjs/common/browser-version/firefox-version.js +0 -17
  278. package/dist/cjs/common/browser-version/ios-version.js +0 -19
  279. package/dist/cjs/common/event-emitter/contextual-ee.test.js +0 -282
  280. package/dist/cjs/common/event-emitter/handle.test.js +0 -58
  281. package/dist/cjs/common/event-emitter/register-handler.test.js +0 -55
  282. package/dist/cjs/common/harvest/harvest-scheduler.test.js +0 -39
  283. package/dist/cjs/common/harvest/harvest.test.js +0 -224
  284. package/dist/cjs/common/ids/id.test.js +0 -85
  285. package/dist/cjs/common/ids/unique-id.test.js +0 -49
  286. package/dist/cjs/common/session/session-entity.test.js +0 -460
  287. package/dist/cjs/common/storage/local-memory.js +0 -35
  288. package/dist/cjs/common/storage/local-memory.test.js +0 -20
  289. package/dist/cjs/common/storage/local-storage.test.js +0 -14
  290. package/dist/cjs/common/timer/interaction-timer.test.js +0 -216
  291. package/dist/cjs/common/timer/timer.test.js +0 -105
  292. package/dist/cjs/common/timing/nav-timing.test.js +0 -192
  293. package/dist/cjs/common/url/canonicalize-url.test.js +0 -42
  294. package/dist/cjs/common/url/clean-url.test.js +0 -9
  295. package/dist/cjs/common/url/encode.test.js +0 -74
  296. package/dist/cjs/common/url/location.test.js +0 -13
  297. package/dist/cjs/common/url/parse-url.test.js +0 -111
  298. package/dist/cjs/common/url/protocol.test.js +0 -15
  299. package/dist/cjs/common/util/console.test.js +0 -30
  300. package/dist/cjs/common/util/data-size.test.js +0 -47
  301. package/dist/cjs/common/util/get-or-set.test.js +0 -47
  302. package/dist/cjs/common/util/global-scope.js +0 -58
  303. package/dist/cjs/common/util/invoke.test.js +0 -49
  304. package/dist/cjs/common/util/map-own.test.js +0 -49
  305. package/dist/cjs/common/util/stringify.test.js +0 -48
  306. package/dist/cjs/common/util/submit-data.test.js +0 -221
  307. package/dist/cjs/common/util/traverse.test.js +0 -44
  308. package/dist/cjs/common/wrap/wrap-promise.test.js +0 -119
  309. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +0 -31
  310. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +0 -383
  311. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +0 -40
  312. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +0 -27
  313. package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +0 -137
  314. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -17
  315. package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +0 -165
  316. package/dist/cjs/features/spa/aggregate/interaction-node.test.js +0 -16
  317. package/dist/esm/common/browser-version/firefox-version.js +0 -10
  318. package/dist/esm/common/browser-version/ios-version.js +0 -11
  319. package/dist/esm/common/event-emitter/contextual-ee.test.js +0 -278
  320. package/dist/esm/common/event-emitter/handle.test.js +0 -54
  321. package/dist/esm/common/event-emitter/register-handler.test.js +0 -51
  322. package/dist/esm/common/harvest/harvest-scheduler.test.js +0 -37
  323. package/dist/esm/common/harvest/harvest.test.js +0 -222
  324. package/dist/esm/common/ids/id.test.js +0 -81
  325. package/dist/esm/common/ids/unique-id.test.js +0 -44
  326. package/dist/esm/common/session/session-entity.test.js +0 -458
  327. package/dist/esm/common/storage/local-memory.js +0 -28
  328. package/dist/esm/common/storage/local-memory.test.js +0 -18
  329. package/dist/esm/common/storage/local-storage.test.js +0 -12
  330. package/dist/esm/common/timer/interaction-timer.test.js +0 -214
  331. package/dist/esm/common/timer/timer.test.js +0 -103
  332. package/dist/esm/common/timing/nav-timing.test.js +0 -190
  333. package/dist/esm/common/url/canonicalize-url.test.js +0 -38
  334. package/dist/esm/common/url/clean-url.test.js +0 -7
  335. package/dist/esm/common/url/encode.test.js +0 -70
  336. package/dist/esm/common/url/location.test.js +0 -11
  337. package/dist/esm/common/url/parse-url.test.js +0 -107
  338. package/dist/esm/common/url/protocol.test.js +0 -13
  339. package/dist/esm/common/util/console.test.js +0 -28
  340. package/dist/esm/common/util/data-size.test.js +0 -45
  341. package/dist/esm/common/util/get-or-set.test.js +0 -45
  342. package/dist/esm/common/util/global-scope.js +0 -45
  343. package/dist/esm/common/util/invoke.test.js +0 -47
  344. package/dist/esm/common/util/map-own.test.js +0 -47
  345. package/dist/esm/common/util/stringify.test.js +0 -46
  346. package/dist/esm/common/util/submit-data.test.js +0 -219
  347. package/dist/esm/common/util/traverse.test.js +0 -42
  348. package/dist/esm/common/wrap/wrap-promise.test.js +0 -115
  349. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +0 -29
  350. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +0 -379
  351. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +0 -38
  352. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +0 -25
  353. package/dist/esm/features/metrics/aggregate/framework-detection.test.js +0 -133
  354. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -15
  355. package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +0 -163
  356. package/dist/esm/features/spa/aggregate/interaction-node.test.js +0 -14
  357. package/dist/types/common/browser-version/firefox-version.d.ts +0 -2
  358. package/dist/types/common/browser-version/firefox-version.d.ts.map +0 -1
  359. package/dist/types/common/browser-version/ios-version.d.ts +0 -3
  360. package/dist/types/common/browser-version/ios-version.d.ts.map +0 -1
  361. package/dist/types/common/storage/local-memory.d.ts +0 -8
  362. package/dist/types/common/storage/local-memory.d.ts.map +0 -1
  363. package/dist/types/common/util/global-scope.d.ts +0 -14
  364. package/dist/types/common/util/global-scope.d.ts.map +0 -1
  365. package/src/common/browser-version/firefox-version.js +0 -10
  366. package/src/common/browser-version/ios-version.js +0 -11
  367. package/src/common/storage/local-memory.js +0 -30
  368. package/src/common/storage/local-memory.test.js +0 -19
  369. package/src/common/util/global-scope.js +0 -49
  370. /package/src/common/timer/{interaction-timer.test.js → interaction-timer.component-test.js} +0 -0
  371. /package/src/common/url/{encode.test.js → encode.component-test.js} +0 -0
  372. /package/src/common/url/{protocol.test.js → protocol.component-test.js} +0 -0
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Harvest = void 0;
7
- exports.getSubmitMethod = getSubmitMethod;
8
- var _mapOwn = require("../util/map-own");
9
7
  var _encode = require("../url/encode");
10
8
  var _stringify = require("../util/stringify");
11
- var _submitData = require("../util/submit-data");
9
+ var submitData = _interopRequireWildcard(require("../util/submit-data"));
12
10
  var _location = require("../url/location");
13
11
  var _config = require("../config/config");
14
12
  var _cleanUrl = require("../url/clean-url");
@@ -18,31 +16,22 @@ var _obfuscate = require("../util/obfuscate");
18
16
  var _traverse = require("../util/traverse");
19
17
  var _sharedContext = require("../context/shared-context");
20
18
  var _env = require("../constants/env.npm");
21
- var _globalScope = require("../util/global-scope");
19
+ var _runtime = require("../constants/runtime");
20
+ 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); }
21
+ 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; }
22
22
  /*
23
23
  * Copyright 2020 New Relic Corporation. All rights reserved.
24
24
  * SPDX-License-Identifier: Apache-2.0
25
25
  */
26
26
 
27
27
  /**
28
- * @typedef {object} NetworkSendSpec
29
- * @param {string} endpoint The endpoint to use (jserrors, events, resources etc.)
30
- * @param {object} payload Object representing payload.
31
- * @param {object} payload.qs Map of values that should be sent as part of the request query string.
32
- * @param {string} payload.body String that should be sent as the body of the request.
33
- * @param {string} payload.body.e Special case of body used for browser interactions.
34
- * @param {object} opts Additional options for sending data
35
- * @param {boolean} opts.needResponse Specify whether the caller expects a response data.
36
- * @param {boolean} opts.unload Specify whether the call is a final harvest during page unload.
37
- * @param {boolean} opts.sendEmptyBody Specify whether the call should be made even if the body is empty. Useful for rum calls.
38
- * @param {function} submitMethod The submit method to use {@link ../util/submit-data}
39
- * @param {string} customUrl Override the beacon url the data is sent to; must include protocol if defined
40
- * @param {boolean} gzip Enabled gzip compression on the body of the request before it is sent
41
- * @param {boolean} includeBaseParams Enables the use of base query parameters in the beacon url {@see Harvest.baseQueryString}
28
+ * @typedef {import('./types.js').NetworkSendSpec} NetworkSendSpec
29
+ * @typedef {import('./types.js').HarvestEndpointIdentifier} HarvestEndpointIdentifier
30
+ * @typedef {import('./types.js').HarvestPayload} HarvestPayload
31
+ * @typedef {import('./types.js').FeatureHarvestCallback} FeatureHarvestCallback
32
+ * @typedef {import('./types.js').FeatureHarvestCallbackOptions} FeatureHarvestCallbackOptions
42
33
  */
43
34
 
44
- const haveSendBeacon = !!navigator.sendBeacon; // only the web window obj has sendBeacon at this time, so 'false' for other envs
45
-
46
35
  class Harvest extends _sharedContext.SharedContext {
47
36
  constructor(parent) {
48
37
  super(parent); // gets any allowed properties from the parent and stores them in `sharedContext`
@@ -56,20 +45,19 @@ class Harvest extends _sharedContext.SharedContext {
56
45
  /**
57
46
  * Initiate a harvest from multiple sources. An event that corresponds to the endpoint
58
47
  * name is emitted, which gives any listeners the opportunity to provide payload data.
48
+ * Note: Used by page_action
59
49
  * @param {NetworkSendSpec} spec Specification for sending data
60
50
  */
61
- sendX(spec) {
62
- const {
63
- endpoint,
64
- opts
65
- } = spec;
66
- var submitMethod = getSubmitMethod(endpoint, opts);
67
- if (!submitMethod) return false;
68
- var options = {
69
- retry: submitMethod.method === _submitData.submitData.xhr
51
+ sendX() {
52
+ let spec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
53
+ const submitMethod = submitData.getSubmitMethod({
54
+ isFinalHarvest: spec.opts?.unload
55
+ });
56
+ const options = {
57
+ retry: !spec.opts?.unload && submitMethod === submitData.xhr
70
58
  };
71
- const payload = this.createPayload(endpoint, options);
72
- var caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
59
+ const payload = this.createPayload(spec.endpoint, options);
60
+ const caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
73
61
  return caller({
74
62
  ...spec,
75
63
  payload,
@@ -81,31 +69,19 @@ class Harvest extends _sharedContext.SharedContext {
81
69
  * Initiate a harvest call.
82
70
  * @param {NetworkSendSpec} spec Specification for sending data
83
71
  */
84
- send(spec) {
85
- const {
86
- payload = {}
87
- } = spec;
88
- var makeBody = createAccumulator();
89
- var makeQueryString = createAccumulator();
90
- if (payload.body) (0, _mapOwn.mapOwn)(payload.body, makeBody);
91
- if (payload.qs) (0, _mapOwn.mapOwn)(payload.qs, makeQueryString);
92
- var newPayload = {
93
- body: makeBody(),
94
- qs: makeQueryString()
95
- };
96
- var caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
97
- return caller({
98
- ...spec,
99
- payload: newPayload
100
- });
72
+ send() {
73
+ let spec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
74
+ const caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
75
+ return caller(spec);
101
76
  }
102
77
 
103
78
  /**
104
79
  * Apply obfuscation rules to the payload and then initial the harvest network call.
105
80
  * @param {NetworkSendSpec} spec Specification for sending data
106
81
  */
107
- obfuscateAndSend(spec) {
82
+ obfuscateAndSend() {
108
83
  var _this = this;
84
+ let spec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
109
85
  const {
110
86
  payload = {}
111
87
  } = spec;
@@ -117,6 +93,14 @@ class Harvest extends _sharedContext.SharedContext {
117
93
  payload
118
94
  });
119
95
  }
96
+
97
+ /**
98
+ * Initiate a harvest call. Typically used by `sendX` and `send` methods or called directly
99
+ * for raw network calls.
100
+ * @param {NetworkSendSpec} param0 Specification for sending data
101
+ * @returns {boolean} True if the network call succeeded. For final harvest calls, the return
102
+ * value should not be relied upon because network calls will be made asynchronously.
103
+ */
120
104
  _send(_ref) {
121
105
  let {
122
106
  endpoint,
@@ -128,10 +112,14 @@ class Harvest extends _sharedContext.SharedContext {
128
112
  raw,
129
113
  includeBaseParams = true
130
114
  } = _ref;
131
- var info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
115
+ const info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
132
116
  if (!info.errorBeacon) return false;
133
- var agentRuntime = (0, _config.getRuntime)(this.sharedContext.agentIdentifier);
134
- if (!payload.body && !opts?.sendEmptyBody) {
117
+ const agentRuntime = (0, _config.getRuntime)(this.sharedContext.agentIdentifier);
118
+ let {
119
+ body,
120
+ qs
121
+ } = this.cleanPayload(payload);
122
+ if (Object.keys(body).length === 0 && !opts?.sendEmptyBody) {
135
123
  // no payload body? nothing to send, just run onfinish stuff and return
136
124
  if (cbFinished) {
137
125
  cbFinished({
@@ -140,27 +128,32 @@ class Harvest extends _sharedContext.SharedContext {
140
128
  }
141
129
  return false;
142
130
  }
143
- let url = '';
144
- if (customUrl) url = customUrl;else if (raw) url = "".concat(this.getScheme(), "://").concat(info.errorBeacon, "/").concat(endpoint);else url = "".concat(this.getScheme(), "://").concat(info.errorBeacon).concat(endpoint !== 'rum' ? "/".concat(endpoint) : '', "/1/").concat(info.licenseKey);
145
- var baseParams = !raw && includeBaseParams ? this.baseQueryString() : '';
146
- var payloadParams = payload.qs ? (0, _encode.obj)(payload.qs, agentRuntime.maxBytes) : '';
131
+ let url = "".concat(this.getScheme(), "://").concat(info.errorBeacon).concat(endpoint !== 'rum' ? "/".concat(endpoint) : '', "/1/").concat(info.licenseKey);
132
+ if (customUrl) url = customUrl;
133
+ if (raw) url = "".concat(this.getScheme(), "://").concat(info.errorBeacon, "/").concat(endpoint);
134
+ const baseParams = !raw && includeBaseParams ? this.baseQueryString() : '';
135
+ let payloadParams = (0, _encode.obj)(qs, agentRuntime.maxBytes);
147
136
  if (!submitMethod) {
148
- submitMethod = getSubmitMethod(endpoint, opts);
137
+ submitMethod = submitData.getSubmitMethod({
138
+ isFinalHarvest: opts.unload
139
+ });
140
+ }
141
+ if (baseParams === '' && payloadParams.startsWith('&')) {
142
+ payloadParams = payloadParams.substring(1);
149
143
  }
150
- var method = submitMethod.method;
151
- var useBody = submitMethod.useBody;
152
- var body;
153
- var fullUrl = "".concat(url, "?").concat(baseParams).concat(payloadParams);
154
- const gzip = payload?.qs?.content_encoding === 'gzip';
144
+ const fullUrl = "".concat(url, "?").concat(baseParams).concat(payloadParams);
145
+ const gzip = qs.content_encoding === 'gzip';
155
146
  if (!gzip) {
156
- if (useBody && endpoint === 'events') {
157
- body = payload.body.e;
158
- } else if (useBody) {
159
- body = (0, _stringify.stringify)(payload.body);
147
+ if (endpoint === 'events') {
148
+ body = body.e;
160
149
  } else {
161
- fullUrl = fullUrl + (0, _encode.obj)(payload.body, agentRuntime.maxBytes);
150
+ body = (0, _stringify.stringify)(body);
162
151
  }
163
- } else body = payload.body;
152
+ }
153
+ if (!body || body.length === 0 || body === '{}' || body === '[]') {
154
+ // If body is null, undefined, or an empty object or array, send an empty string instead
155
+ body = '';
156
+ }
164
157
 
165
158
  // Get bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
166
159
  agentRuntime.bytesSent[endpoint] = (agentRuntime.bytesSent[endpoint] || 0) + body?.length || 0;
@@ -172,122 +165,148 @@ class Harvest extends _sharedContext.SharedContext {
172
165
  value: 'text/plain'
173
166
  });
174
167
 
175
- /* Since workers don't support sendBeacon right now, or Image(), they can only use XHR method.
168
+ /* Since workers don't support sendBeacon right now, they can only use XHR method.
176
169
  Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
177
- we just make a BLOCKING request--trivial impact--with the remaining data as a temp fill-in for sendBeacon. */
178
-
179
- var result = method({
170
+ we just make a BLOCKING request--trivial impact--with the remaining data as a temp fill-in for sendBeacon.
171
+ Following the removal of img-element method, IE will also use sync XHR on page dismissal to ensure final analytics are sent. */
172
+ let result = submitMethod({
180
173
  url: fullUrl,
181
174
  body,
182
- sync: opts.unload && _globalScope.isWorkerScope,
175
+ sync: opts.unload && (_runtime.isWorkerScope || _runtime.isIE),
183
176
  headers
184
177
  });
185
- if (cbFinished && method === _submitData.submitData.xhr) {
186
- var xhr = result;
187
- xhr.addEventListener('load', function () {
188
- var result = {
178
+ if (!opts.unload && cbFinished && submitMethod === submitData.xhr) {
179
+ const harvestScope = this;
180
+ result.addEventListener('load', function () {
181
+ // `this` refers to the XHR object in this scope, do not change this to a fat arrow
182
+ const cbResult = {
189
183
  sent: true,
190
184
  status: this.status
191
185
  };
192
186
  if (this.status === 429) {
193
- result.retry = true;
194
- result.delay = this.tooManyRequestsDelay;
187
+ cbResult.retry = true;
188
+ cbResult.delay = harvestScope.tooManyRequestsDelay;
195
189
  } else if (this.status === 408 || this.status === 500 || this.status === 503) {
196
- result.retry = true;
190
+ cbResult.retry = true;
197
191
  }
198
192
  if (opts.needResponse) {
199
- result.responseText = this.responseText;
193
+ cbResult.responseText = this.responseText;
200
194
  }
201
- cbFinished(result);
195
+ cbFinished(cbResult);
202
196
  }, (0, _eventListenerOpts.eventListenerOpts)(false));
203
197
  }
204
198
 
205
199
  // if beacon request failed, retry with an alternative method -- will not happen for workers
206
- if (!result && method === _submitData.submitData.beacon) {
207
- method = _submitData.submitData.img;
208
- result = method({
209
- url: fullUrl + (0, _encode.obj)(payload.body, agentRuntime.maxBytes)
210
- });
200
+ if (!result && submitMethod === submitData.beacon) {
201
+ // browsers that support sendBeacon also support fetch with keepalive - IE will not retry unload calls
202
+ submitMethod = submitData.fetchKeepAlive;
203
+ try {
204
+ submitMethod({
205
+ url: fullUrl,
206
+ body,
207
+ headers
208
+ });
209
+ } catch (e) {
210
+ // Ignore error in final harvest
211
+ } finally {
212
+ result = true;
213
+ }
211
214
  }
212
215
  return result;
213
216
  }
214
217
 
215
218
  // The stuff that gets sent every time.
216
219
  baseQueryString() {
217
- var runtime = (0, _config.getRuntime)(this.sharedContext.agentIdentifier);
218
- var info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
219
- var location = (0, _cleanUrl.cleanURL)((0, _location.getLocation)());
220
- var ref = this.obfuscator.shouldObfuscate() ? this.obfuscator.obfuscateString(location) : location;
220
+ const runtime = (0, _config.getRuntime)(this.sharedContext.agentIdentifier);
221
+ const info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
222
+ const location = (0, _cleanUrl.cleanURL)((0, _location.getLocation)());
223
+ const ref = this.obfuscator.shouldObfuscate() ? this.obfuscator.obfuscateString(location) : location;
221
224
  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',
222
225
  // ck param DEPRECATED - still expected by backend
223
226
  '&s=' + (runtime.session?.state.value || '0'),
224
227
  // the 0 id encaps all untrackable and default traffic
225
228
  (0, _encode.param)('ref', ref), (0, _encode.param)('ptid', runtime.ptid ? '' + runtime.ptid : '')].join('');
226
229
  }
227
- createPayload(type, options) {
228
- var makeBody = createAccumulator();
229
- var makeQueryString = createAccumulator();
230
- var listeners = this._events[type] && this._events[type] || [];
231
- for (var i = 0; i < listeners.length; i++) {
232
- var singlePayload = listeners[i](options);
233
- if (!singlePayload) continue;
234
- if (singlePayload.body) (0, _mapOwn.mapOwn)(singlePayload.body, makeBody);
235
- if (singlePayload.qs) (0, _mapOwn.mapOwn)(singlePayload.qs, makeQueryString);
230
+
231
+ /**
232
+ * Calls and accumulates data from registered harvesting functions based on
233
+ * the endpoint being harvested.
234
+ * @param {HarvestEndpointIdentifier} endpoint BAM endpoint identifier.
235
+ * @param {FeatureHarvestCallbackOptions} options Options to be passed to the
236
+ * feature harvest listener callback.
237
+ * @returns {HarvestPayload} Payload object to transmit to the bam endpoint.
238
+ */
239
+ createPayload(endpoint, options) {
240
+ const listeners = this._events[endpoint];
241
+ const payload = {
242
+ body: {},
243
+ qs: {}
244
+ };
245
+ if (Array.isArray(listeners) && listeners.length > 0) {
246
+ for (let i = 0; i < listeners.length; i++) {
247
+ const singlePayload = listeners[i](options);
248
+ if (singlePayload) {
249
+ payload.body = {
250
+ ...payload.body,
251
+ ...(singlePayload.body || {})
252
+ };
253
+ payload.qs = {
254
+ ...payload.qs,
255
+ ...(singlePayload.qs || {})
256
+ };
257
+ }
258
+ }
236
259
  }
260
+ return payload;
261
+ }
262
+
263
+ /**
264
+ * Cleans and returns a payload object containing a body and qs
265
+ * object with key/value pairs. KV pairs where the value is null,
266
+ * undefined, or an empty string are removed to save on transmission
267
+ * size.
268
+ * @param {HarvestPayload} payload Payload to be sent to the endpoint.
269
+ * @returns {HarvestPayload} Cleaned payload payload to be sent to the endpoint.
270
+ */
271
+ cleanPayload() {
272
+ let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
273
+ const clean = input => {
274
+ if (typeof Uint8Array !== 'undefined' && input instanceof Uint8Array) {
275
+ return input.length > 0 ? input : null;
276
+ }
277
+ return Object.entries(input || {}).reduce((accumulator, _ref2) => {
278
+ let [key, value] = _ref2;
279
+ if (typeof value === 'number' || typeof value === 'string' && value.length > 0 || typeof value === 'object' && Object.keys(value || {}).length > 0) {
280
+ accumulator[key] = value;
281
+ }
282
+ return accumulator;
283
+ }, {});
284
+ };
237
285
  return {
238
- body: makeBody(),
239
- qs: makeQueryString()
286
+ body: clean(payload.body),
287
+ qs: clean(payload.qs)
240
288
  };
241
289
  }
242
- on(type, listener) {
243
- var listeners = this._events[type] || (this._events[type] = []);
244
- listeners.push(listener);
245
- }
246
- resetListeners() {
247
- (0, _mapOwn.mapOwn)(this._events, key => {
248
- this._events[key] = [];
249
- });
250
- }
251
- }
252
- exports.Harvest = Harvest;
253
- function getSubmitMethod(endpoint, opts) {
254
- opts = opts || {};
255
- var method;
256
- var useBody;
257
- if (opts.unload && _globalScope.isBrowserScope) {
258
- // all the features' final harvest; neither methods work outside window context
259
- useBody = haveSendBeacon;
260
- method = haveSendBeacon ? _submitData.submitData.beacon : _submitData.submitData.img; // really only IE doesn't have Beacon API for web browsers
261
- } else {
262
- // `submitData.beacon` was removed, there is an upper limit to the
263
- // number of data allowed before it starts failing, so we save it only for page unloading
264
- useBody = true;
265
- method = _submitData.submitData.xhr;
290
+
291
+ /**
292
+ * Registers a function to be called when harvesting is triggered for a specific
293
+ * endpoint.
294
+ * @param {HarvestEndpointIdentifier} endpoint
295
+ * @param {FeatureHarvestCallback} listener
296
+ */
297
+ on(endpoint, listener) {
298
+ if (!Array.isArray(this._events[endpoint])) {
299
+ this._events[endpoint] = [];
300
+ }
301
+ this._events[endpoint].push(listener);
266
302
  }
267
- return {
268
- method: method,
269
- useBody: useBody
270
- };
271
303
  }
272
304
 
273
305
  // Constructs the transaction name param for the beacon URL.
274
306
  // Prefers the obfuscated transaction name over the plain text.
275
307
  // Falls back to making up a name.
308
+ exports.Harvest = Harvest;
276
309
  function transactionNameParam(info) {
277
310
  if (info.transactionName) return (0, _encode.param)('to', info.transactionName);
278
311
  return (0, _encode.param)('t', info.tNamePlain || 'Unnamed Transaction');
279
- }
280
-
281
- // returns a function that can be called to accumulate values to a single object
282
- // when the function is called without parameters, then the accumulator is returned
283
- function createAccumulator() {
284
- var accumulator = {};
285
- var hasData = false;
286
- return function (key, val) {
287
- if (val !== null && val !== undefined && val.toString()?.length) {
288
- accumulator[key] = val;
289
- hasData = true;
290
- }
291
- if (hasData) return accumulator;
292
- };
293
312
  }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.unused = void 0;
7
+ /**
8
+ * @file Contains types related to harvesting data.
9
+ * @copyright 2023 New Relic Corporation. All rights reserved.
10
+ * @license Apache-2.0
11
+ */
12
+
13
+ /**
14
+ * @typedef {'rum'|'jserrors'|'events'|'ins'|'resources'|'blob'} HarvestEndpointIdentifier
15
+ */
16
+
17
+ /**
18
+ * @typedef {object} HarvestPayload
19
+ * @property {object} qs Map of values that should be sent as part of the request query string.
20
+ * @property {object} body Map of values that should be sent as the body of the request.
21
+ * @property {string} body.e Special case of body used for browser interactions.
22
+ */
23
+
24
+ /**
25
+ * @typedef {object} FeatureHarvestCallbackOptions Options for aggregating data for harvesting.
26
+ * @property {boolean} options.retry Indicates if the feature should store the aggregated
27
+ * data in anticipation of a possible need to retry the transmission.
28
+ */
29
+
30
+ /**
31
+ * @callback FeatureHarvestCallback
32
+ * @param {FeatureHarvestCallbackOptions} options Options for aggregating data for harvesting.
33
+ * @returns {HarvestPayload} Payload of data to transmit to bam endpoint.
34
+ */
35
+
36
+ /**
37
+ * @typedef {object} NetworkSendSpec
38
+ * @property {HarvestEndpointIdentifier} endpoint The endpoint to use (jserrors, events, resources etc.)
39
+ * @property {HarvestPayload} payload Object representing payload.
40
+ * @property {object} opts Additional options for sending data
41
+ * @property {boolean} opts.needResponse Specify whether the caller expects a response data.
42
+ * @property {boolean} opts.unload Specify whether the call is a final harvest during page unload.
43
+ * @property {boolean} opts.sendEmptyBody Specify whether the call should be made even if the body is empty. Useful for rum calls.
44
+ * @property {boolean} opts.retry Indicates if the feature should store the aggregated data in anticipation of a possible need to
45
+ * retry the transmission.
46
+ * @property {import('../util/submit-data.js').NetworkMethods} submitMethod The network method to use {@link ../util/submit-data.js}
47
+ * @property {string} customUrl Override the beacon url the data is sent to; must include protocol if defined
48
+ * @property {boolean} raw If true, disables adding the license key to the url
49
+ * @property {boolean} includeBaseParams Enables the use of base query parameters in the beacon url
50
+ */
51
+
52
+ /* istanbul ignore next */
53
+ const unused = {};
54
+ exports.unused = unused;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.id = id;
7
7
  var _getOrSet = require("../util/get-or-set");
8
- var _globalScope = require("../util/global-scope");
8
+ var _runtime = require("../constants/runtime");
9
9
  /*
10
10
  * Copyright 2020 New Relic Corporation. All rights reserved.
11
11
  * SPDX-License-Identifier: Apache-2.0
@@ -31,7 +31,7 @@ function id(obj) {
31
31
  // We can only tag objects, functions, and arrays with ids.
32
32
  // For all primitive values we instead return -1.
33
33
  if (!obj || !(type === 'object' || type === 'function')) return -1;
34
- if (obj === _globalScope.globalScope) return 0;
34
+ if (obj === _runtime.globalScope) return 0;
35
35
  return (0, _getOrSet.getOrSet)(obj, prop, function () {
36
36
  return index++;
37
37
  });
@@ -7,7 +7,7 @@ exports.generateRandomHexString = generateRandomHexString;
7
7
  exports.generateSpanId = generateSpanId;
8
8
  exports.generateTraceId = generateTraceId;
9
9
  exports.generateUuid = generateUuid;
10
- var _globalScope = require("../util/global-scope");
10
+ var _runtime = require("../constants/runtime");
11
11
  /*
12
12
  * Copyright 2020 New Relic Corporation. All rights reserved.
13
13
  * SPDX-License-Identifier: Apache-2.0
@@ -46,7 +46,7 @@ function getRandomValue(valueTable, tableIndex) {
46
46
  * @returns {string} uuid version 4 string
47
47
  */
48
48
  function generateUuid() {
49
- const crypto = _globalScope.globalScope?.crypto || _globalScope.globalScope?.msCrypto;
49
+ const crypto = _runtime.globalScope?.crypto || _runtime.globalScope?.msCrypto;
50
50
  let randomValueTable;
51
51
  let randomValueIndex = 0;
52
52
  if (crypto && crypto.getRandomValues) {
@@ -73,7 +73,7 @@ function generateUuid() {
73
73
  * @returns {string} generated hex string
74
74
  */
75
75
  function generateRandomHexString(length) {
76
- const crypto = _globalScope.globalScope?.crypto || _globalScope.globalScope?.msCrypto;
76
+ const crypto = _runtime.globalScope?.crypto || _runtime.globalScope?.msCrypto;
77
77
  let randomValueTable;
78
78
  let randomValueIndex = 0;
79
79
  if (crypto && crypto.getRandomValues) {
@@ -3,30 +3,35 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SessionEntity = exports.SESSION_EVENTS = void 0;
6
+ exports.SessionEntity = exports.SESSION_EVENTS = exports.MODE = void 0;
7
7
  var _uniqueId = require("../ids/unique-id");
8
8
  var _console = require("../util/console");
9
9
  var _stringify = require("../util/stringify");
10
10
  var _contextualEe = require("../event-emitter/contextual-ee");
11
11
  var _timer = require("../timer/timer");
12
- var _globalScope = require("../util/global-scope");
12
+ var _runtime = require("../constants/runtime");
13
13
  var _constants = require("./constants");
14
- var _localMemory = require("../storage/local-memory");
15
14
  var _interactionTimer = require("../timer/interaction-timer");
16
15
  var _wrap = require("../wrap");
17
16
  var _configurable = require("../config/state/configurable");
18
17
  var _handle = require("../event-emitter/handle");
19
18
  var _constants2 = require("../../features/metrics/constants");
20
19
  var _features = require("../../loaders/features/features");
20
+ const MODE = {
21
+ OFF: 0,
22
+ FULL: 1,
23
+ ERROR: 2
24
+ };
21
25
  // this is what can be stored in local storage (not enforced but probably should be)
22
26
  // these values should sync between local storage and the parent class props
27
+ exports.MODE = MODE;
23
28
  const model = {
24
29
  value: '',
25
30
  inactiveAt: 0,
26
31
  expiresAt: 0,
27
32
  updatedAt: Date.now(),
28
- sessionReplay: 0,
29
- sessionTraceActive: false,
33
+ sessionReplay: MODE.OFF,
34
+ sessionTraceMode: MODE.OFF,
30
35
  custom: {}
31
36
  };
32
37
  const SESSION_EVENTS = {
@@ -49,16 +54,19 @@ class SessionEntity {
49
54
  let {
50
55
  agentIdentifier,
51
56
  key,
57
+ storage,
52
58
  value = (0, _uniqueId.generateRandomHexString)(16),
53
59
  expiresMs = _constants.DEFAULT_EXPIRES_MS,
54
- inactiveMs = _constants.DEFAULT_INACTIVE_MS,
55
- storageAPI = new _localMemory.LocalMemory()
60
+ inactiveMs = _constants.DEFAULT_INACTIVE_MS
56
61
  } = _ref;
57
- if (!agentIdentifier || !key) throw new Error('Missing Required Fields');
58
- if (!_globalScope.isBrowserScope) this.storage = new _localMemory.LocalMemory();else this.storage = storageAPI;
62
+ if (!agentIdentifier || !key || !storage) {
63
+ throw new Error("Missing required field(s):".concat(!agentIdentifier ? ' agentID' : '').concat(!key ? ' key' : '').concat(!storage ? ' storage' : ''));
64
+ }
65
+ this.agentIdentifier = agentIdentifier;
66
+ this.storage = storage;
59
67
  this.state = {};
60
68
  this.sync(model);
61
- this.agentIdentifier = agentIdentifier;
69
+
62
70
  // key is intended to act as the k=v pair
63
71
  this.key = key;
64
72
  // value is intended to act as the primary value of the k=v pair
@@ -185,7 +193,7 @@ class SessionEntity {
185
193
  this.sync(data); // update the parent class "state" properties with the local storage values
186
194
  //
187
195
  // TODO - compression would need happen here if we decide to do it
188
- this.storage.set(this.lookupKey, (0, _stringify.stringify)(data));
196
+ this.storage.set(this.lookupKey, (0, _stringify.stringify)(this.state));
189
197
  return data;
190
198
  } catch (e) {
191
199
  // storage is inaccessible
@@ -207,7 +215,7 @@ class SessionEntity {
207
215
  this.setup({
208
216
  agentIdentifier: this.agentIdentifier,
209
217
  key: this.key,
210
- storageAPI: this.storage,
218
+ storage: this.storage,
211
219
  expiresMs: this.expiresMs,
212
220
  inactiveMs: this.inactiveMs
213
221
  });
@@ -266,7 +274,7 @@ class SessionEntity {
266
274
  return Date.now() + futureMs;
267
275
  }
268
276
  syncCustomAttribute(key, value) {
269
- if (!_globalScope.isBrowserScope) return;
277
+ if (!_runtime.isBrowserScope) return;
270
278
  if (value === null) {
271
279
  const curr = this.read();
272
280
  if (curr.custom) {
@@ -7,7 +7,7 @@ exports.InteractionTimer = void 0;
7
7
  var _timer = require("./timer");
8
8
  var _pageVisibility = require("../window/page-visibility");
9
9
  var _invoke = require("../util/invoke");
10
- var _globalScope = require("../util/global-scope");
10
+ var _runtime = require("../constants/runtime");
11
11
  class InteractionTimer extends _timer.Timer {
12
12
  constructor(opts, ms) {
13
13
  super(opts, ms);
@@ -25,7 +25,7 @@ class InteractionTimer extends _timer.Timer {
25
25
  } catch (e) {
26
26
  // this try-catch can be removed when IE11 is completely unsupported & gone
27
27
  }
28
- if (_globalScope.isBrowserScope && opts.ee) {
28
+ if (_runtime.isBrowserScope && opts.ee) {
29
29
  if (opts.ee) {
30
30
  const debouncedRefresh = (0, _invoke.debounce)(this.refresh.bind(this), 500, {
31
31
  leading: true
@@ -49,8 +49,8 @@ class InteractionTimer extends _timer.Timer {
49
49
  if (state === 'hidden') this.pause();
50
50
  // vis change --> visible is treated like a new interaction with the page
51
51
  else {
52
- this.onResume();
53
52
  this.refresh();
53
+ this.onResume(); // emit resume event after state updated
54
54
  }
55
55
  }, false, false, this.abortController?.signal);
56
56
  }