@newrelic/browser-agent 1.264.0 → 1.265.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 (407) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/common/aggregate/aggregator.js +1 -2
  3. package/dist/cjs/common/config/{state/configurable.js → configurable.js} +1 -1
  4. package/dist/cjs/common/config/{state/info.js → info.js} +1 -1
  5. package/dist/cjs/common/config/{state/init.js → init.js} +5 -5
  6. package/dist/cjs/common/config/{state/loader-config.js → loader-config.js} +1 -1
  7. package/dist/cjs/common/config/{state/runtime.js → runtime.js} +16 -5
  8. package/dist/cjs/common/constants/agent-constants.js +8 -0
  9. package/dist/cjs/common/constants/env.cdn.js +1 -1
  10. package/dist/cjs/common/constants/env.npm.js +1 -1
  11. package/dist/cjs/common/context/shared-context.js +1 -2
  12. package/dist/cjs/common/dispatch/global-event.js +1 -2
  13. package/dist/cjs/common/drain/drain.js +10 -16
  14. package/dist/cjs/common/event-emitter/contextual-ee.js +3 -4
  15. package/dist/cjs/common/event-listener/event-listener-opts.js +2 -6
  16. package/dist/cjs/common/harvest/harvest-scheduler.js +1 -2
  17. package/dist/cjs/common/harvest/harvest.js +29 -56
  18. package/dist/cjs/common/serialize/bel-serializer.js +6 -11
  19. package/dist/cjs/common/session/session-entity.js +9 -12
  20. package/dist/cjs/common/timing/nav-timing.js +1 -3
  21. package/dist/cjs/common/timing/time-keeper.js +16 -6
  22. package/dist/cjs/common/url/encode.js +2 -4
  23. package/dist/cjs/common/util/console.js +2 -0
  24. package/dist/cjs/common/util/invoke.js +6 -16
  25. package/dist/cjs/common/util/obfuscate.js +97 -53
  26. package/dist/cjs/common/util/submit-data.js +17 -20
  27. package/dist/cjs/common/util/text.js +9 -0
  28. package/dist/cjs/common/util/traverse.js +1 -3
  29. package/dist/cjs/common/vitals/cumulative-layout-shift.js +5 -6
  30. package/dist/cjs/common/vitals/first-contentful-paint.js +4 -5
  31. package/dist/cjs/common/vitals/first-input-delay.js +4 -5
  32. package/dist/cjs/common/vitals/interaction-to-next-paint.js +5 -6
  33. package/dist/cjs/common/vitals/largest-contentful-paint.js +4 -5
  34. package/dist/cjs/common/vitals/time-to-first-byte.js +4 -5
  35. package/dist/cjs/common/vitals/vital-metric.js +6 -8
  36. package/dist/cjs/common/window/nreum.js +2 -1
  37. package/dist/cjs/common/window/page-visibility.js +1 -4
  38. package/dist/cjs/common/wrap/wrap-events.js +1 -4
  39. package/dist/cjs/common/wrap/wrap-promise.js +1 -4
  40. package/dist/cjs/common/wrap/wrap-websocket.js +74 -0
  41. package/dist/cjs/features/ajax/aggregate/chunk.js +4 -3
  42. package/dist/cjs/features/ajax/aggregate/gql.js +4 -5
  43. package/dist/cjs/features/ajax/aggregate/index.js +20 -23
  44. package/dist/cjs/features/ajax/constants.js +2 -3
  45. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +9 -8
  46. package/dist/cjs/features/ajax/instrument/index.js +15 -13
  47. package/dist/cjs/features/generic_events/aggregate/index.js +49 -58
  48. package/dist/cjs/features/generic_events/constants.js +4 -2
  49. package/dist/cjs/features/generic_events/instrument/index.js +7 -7
  50. package/dist/cjs/features/jserrors/aggregate/index.js +24 -44
  51. package/dist/cjs/features/jserrors/instrument/index.js +5 -5
  52. package/dist/cjs/features/logging/aggregate/index.js +34 -37
  53. package/dist/cjs/features/logging/constants.js +2 -3
  54. package/dist/cjs/features/logging/instrument/index.js +6 -7
  55. package/dist/cjs/features/logging/shared/log.js +1 -3
  56. package/dist/cjs/features/logging/shared/utils.js +2 -4
  57. package/dist/cjs/features/metrics/aggregate/index.js +35 -18
  58. package/dist/cjs/features/metrics/aggregate/websocket-detection.js +34 -0
  59. package/dist/cjs/features/metrics/constants.js +4 -2
  60. package/dist/cjs/features/metrics/instrument/index.js +13 -5
  61. package/dist/cjs/features/page_action/instrument/index.js +8 -4
  62. package/dist/cjs/features/page_view_event/aggregate/index.js +20 -40
  63. package/dist/cjs/features/page_view_event/instrument/index.js +5 -5
  64. package/dist/cjs/features/page_view_timing/aggregate/index.js +24 -40
  65. package/dist/cjs/features/page_view_timing/instrument/index.js +5 -5
  66. package/dist/cjs/features/session_replay/aggregate/index.js +37 -44
  67. package/dist/cjs/features/session_replay/constants.js +1 -5
  68. package/dist/cjs/features/session_replay/instrument/index.js +6 -10
  69. package/dist/cjs/features/session_replay/shared/recorder-events.js +25 -20
  70. package/dist/cjs/features/session_replay/shared/recorder.js +17 -13
  71. package/dist/cjs/features/session_replay/shared/stylesheet-evaluator.js +3 -3
  72. package/dist/cjs/features/session_replay/shared/utils.js +5 -4
  73. package/dist/cjs/features/session_trace/aggregate/index.js +26 -43
  74. package/dist/cjs/features/session_trace/aggregate/trace/storage.js +7 -5
  75. package/dist/cjs/features/session_trace/instrument/index.js +9 -8
  76. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +1 -1
  77. package/dist/cjs/features/soft_navigations/aggregate/bel-node.js +1 -1
  78. package/dist/cjs/features/soft_navigations/aggregate/index.js +23 -31
  79. package/dist/cjs/features/soft_navigations/aggregate/initial-page-load-interaction.js +2 -2
  80. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +9 -10
  81. package/dist/cjs/features/soft_navigations/instrument/index.js +15 -14
  82. package/dist/cjs/features/spa/aggregate/index.js +17 -27
  83. package/dist/cjs/features/spa/aggregate/interaction.js +7 -6
  84. package/dist/cjs/features/spa/aggregate/serializer.js +3 -3
  85. package/dist/cjs/features/spa/constants.js +2 -2
  86. package/dist/cjs/features/spa/instrument/index.js +21 -20
  87. package/dist/cjs/features/utils/agent-session.js +6 -4
  88. package/dist/cjs/features/utils/aggregate-base.js +15 -10
  89. package/dist/cjs/features/utils/event-buffer.js +132 -0
  90. package/dist/cjs/features/utils/feature-gates.js +2 -2
  91. package/dist/cjs/features/utils/instrument-base.js +7 -8
  92. package/dist/cjs/features/utils/lazy-feature-loader.js +11 -11
  93. package/dist/cjs/features/utils/nr1-debugger.js +1 -3
  94. package/dist/cjs/loaders/agent-base.js +4 -8
  95. package/dist/cjs/loaders/agent.js +7 -2
  96. package/dist/cjs/loaders/api/api.js +22 -34
  97. package/dist/cjs/loaders/api/apiAsync.js +9 -12
  98. package/dist/cjs/loaders/configure/configure.js +12 -12
  99. package/dist/cjs/loaders/features/enabled-features.js +2 -2
  100. package/dist/cjs/loaders/micro-agent.js +15 -14
  101. package/dist/esm/common/aggregate/aggregator.js +1 -2
  102. package/dist/esm/common/config/{state/configurable.js → configurable.js} +1 -1
  103. package/dist/esm/common/config/{state/info.js → info.js} +1 -1
  104. package/dist/esm/common/config/{state/init.js → init.js} +5 -5
  105. package/dist/esm/common/config/{state/loader-config.js → loader-config.js} +1 -1
  106. package/dist/esm/common/config/{state/runtime.js → runtime.js} +17 -5
  107. package/dist/esm/common/constants/agent-constants.js +2 -0
  108. package/dist/esm/common/constants/env.cdn.js +1 -1
  109. package/dist/esm/common/constants/env.npm.js +1 -1
  110. package/dist/esm/common/context/shared-context.js +1 -2
  111. package/dist/esm/common/dispatch/global-event.js +1 -2
  112. package/dist/esm/common/drain/drain.js +10 -16
  113. package/dist/esm/common/event-emitter/contextual-ee.js +2 -3
  114. package/dist/esm/common/event-listener/event-listener-opts.js +2 -6
  115. package/dist/esm/common/harvest/harvest-scheduler.js +1 -2
  116. package/dist/esm/common/harvest/harvest.js +21 -48
  117. package/dist/esm/common/serialize/bel-serializer.js +6 -11
  118. package/dist/esm/common/session/session-entity.js +8 -11
  119. package/dist/esm/common/timing/nav-timing.js +1 -3
  120. package/dist/esm/common/timing/time-keeper.js +15 -5
  121. package/dist/esm/common/url/encode.js +2 -4
  122. package/dist/esm/common/util/console.js +2 -0
  123. package/dist/esm/common/util/invoke.js +6 -16
  124. package/dist/esm/common/util/obfuscate.js +96 -49
  125. package/dist/esm/common/util/submit-data.js +17 -20
  126. package/dist/esm/common/util/text.js +3 -0
  127. package/dist/esm/common/util/traverse.js +1 -3
  128. package/dist/esm/common/vitals/cumulative-layout-shift.js +5 -6
  129. package/dist/esm/common/vitals/first-contentful-paint.js +4 -5
  130. package/dist/esm/common/vitals/first-input-delay.js +4 -5
  131. package/dist/esm/common/vitals/interaction-to-next-paint.js +5 -6
  132. package/dist/esm/common/vitals/largest-contentful-paint.js +4 -5
  133. package/dist/esm/common/vitals/time-to-first-byte.js +4 -5
  134. package/dist/esm/common/vitals/vital-metric.js +6 -8
  135. package/dist/esm/common/window/nreum.js +2 -1
  136. package/dist/esm/common/window/page-visibility.js +1 -4
  137. package/dist/esm/common/wrap/wrap-events.js +1 -4
  138. package/dist/esm/common/wrap/wrap-promise.js +1 -4
  139. package/dist/esm/common/wrap/wrap-websocket.js +67 -0
  140. package/dist/esm/features/ajax/aggregate/chunk.js +3 -2
  141. package/dist/esm/features/ajax/aggregate/gql.js +4 -5
  142. package/dist/esm/features/ajax/aggregate/index.js +17 -20
  143. package/dist/esm/features/ajax/constants.js +1 -2
  144. package/dist/esm/features/ajax/instrument/distributed-tracing.js +2 -1
  145. package/dist/esm/features/ajax/instrument/index.js +11 -9
  146. package/dist/esm/features/generic_events/aggregate/index.js +41 -50
  147. package/dist/esm/features/generic_events/constants.js +3 -1
  148. package/dist/esm/features/generic_events/instrument/index.js +5 -5
  149. package/dist/esm/features/jserrors/aggregate/index.js +19 -39
  150. package/dist/esm/features/jserrors/instrument/index.js +4 -4
  151. package/dist/esm/features/logging/aggregate/index.js +32 -35
  152. package/dist/esm/features/logging/constants.js +1 -2
  153. package/dist/esm/features/logging/instrument/index.js +5 -6
  154. package/dist/esm/features/logging/shared/log.js +1 -3
  155. package/dist/esm/features/logging/shared/utils.js +2 -4
  156. package/dist/esm/features/metrics/aggregate/index.js +29 -12
  157. package/dist/esm/features/metrics/aggregate/websocket-detection.js +29 -0
  158. package/dist/esm/features/metrics/constants.js +3 -1
  159. package/dist/esm/features/metrics/instrument/index.js +13 -5
  160. package/dist/esm/features/page_action/instrument/index.js +7 -3
  161. package/dist/esm/features/page_view_event/aggregate/index.js +18 -38
  162. package/dist/esm/features/page_view_event/instrument/index.js +4 -4
  163. package/dist/esm/features/page_view_timing/aggregate/index.js +21 -37
  164. package/dist/esm/features/page_view_timing/instrument/index.js +4 -4
  165. package/dist/esm/features/session_replay/aggregate/index.js +27 -34
  166. package/dist/esm/features/session_replay/constants.js +0 -4
  167. package/dist/esm/features/session_replay/index.js +1 -7
  168. package/dist/esm/features/session_replay/instrument/index.js +6 -9
  169. package/dist/esm/features/session_replay/shared/recorder-events.js +25 -20
  170. package/dist/esm/features/session_replay/shared/recorder.js +14 -10
  171. package/dist/esm/features/session_replay/shared/stylesheet-evaluator.js +3 -3
  172. package/dist/esm/features/session_replay/shared/utils.js +3 -2
  173. package/dist/esm/features/session_trace/aggregate/index.js +21 -38
  174. package/dist/esm/features/session_trace/aggregate/trace/storage.js +7 -5
  175. package/dist/esm/features/session_trace/instrument/index.js +6 -5
  176. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +1 -1
  177. package/dist/esm/features/soft_navigations/aggregate/bel-node.js +1 -1
  178. package/dist/esm/features/soft_navigations/aggregate/index.js +22 -30
  179. package/dist/esm/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  180. package/dist/esm/features/soft_navigations/aggregate/interaction.js +7 -8
  181. package/dist/esm/features/soft_navigations/instrument/index.js +12 -11
  182. package/dist/esm/features/spa/aggregate/index.js +11 -21
  183. package/dist/esm/features/spa/aggregate/interaction.js +6 -5
  184. package/dist/esm/features/spa/aggregate/serializer.js +1 -1
  185. package/dist/esm/features/spa/constants.js +2 -2
  186. package/dist/esm/features/spa/instrument/index.js +13 -12
  187. package/dist/esm/features/utils/agent-session.js +3 -1
  188. package/dist/esm/features/utils/aggregate-base.js +13 -8
  189. package/dist/esm/features/utils/event-buffer.js +126 -0
  190. package/dist/esm/features/utils/feature-gates.js +1 -1
  191. package/dist/esm/features/utils/instrument-base.js +6 -7
  192. package/dist/esm/features/utils/lazy-feature-loader.js +11 -11
  193. package/dist/esm/features/utils/nr1-debugger.js +1 -3
  194. package/dist/esm/loaders/agent-base.js +4 -8
  195. package/dist/esm/loaders/agent.js +7 -2
  196. package/dist/esm/loaders/api/api.js +17 -29
  197. package/dist/esm/loaders/api/apiAsync.js +2 -5
  198. package/dist/esm/loaders/configure/configure.js +5 -5
  199. package/dist/esm/loaders/features/enabled-features.js +1 -1
  200. package/dist/esm/loaders/micro-agent.js +10 -9
  201. package/dist/types/common/config/configurable.d.ts.map +1 -0
  202. package/dist/types/common/config/info.d.ts.map +1 -0
  203. package/dist/types/common/config/init.d.ts.map +1 -0
  204. package/dist/types/common/config/loader-config.d.ts.map +1 -0
  205. package/dist/types/common/config/runtime.d.ts.map +1 -0
  206. package/dist/types/common/constants/agent-constants.d.ts +3 -0
  207. package/dist/types/common/constants/agent-constants.d.ts.map +1 -0
  208. package/dist/types/common/drain/drain.d.ts.map +1 -1
  209. package/dist/types/common/harvest/harvest.d.ts +1 -7
  210. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  211. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -1
  212. package/dist/types/common/timing/time-keeper.d.ts +9 -2
  213. package/dist/types/common/timing/time-keeper.d.ts.map +1 -1
  214. package/dist/types/common/util/console.d.ts.map +1 -1
  215. package/dist/types/common/util/obfuscate.d.ts +78 -6
  216. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  217. package/dist/types/common/util/text.d.ts +2 -0
  218. package/dist/types/common/util/text.d.ts.map +1 -0
  219. package/dist/types/common/window/nreum.d.ts.map +1 -1
  220. package/dist/types/common/wrap/wrap-websocket.d.ts +4 -0
  221. package/dist/types/common/wrap/wrap-websocket.d.ts.map +1 -0
  222. package/dist/types/features/ajax/aggregate/chunk.d.ts.map +1 -1
  223. package/dist/types/features/ajax/aggregate/index.d.ts +2 -3
  224. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  225. package/dist/types/features/ajax/constants.d.ts +0 -1
  226. package/dist/types/features/ajax/constants.d.ts.map +1 -1
  227. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -1
  228. package/dist/types/features/ajax/instrument/index.d.ts +1 -0
  229. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  230. package/dist/types/features/generic_events/aggregate/index.d.ts +6 -8
  231. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  232. package/dist/types/features/generic_events/constants.d.ts +2 -0
  233. package/dist/types/features/generic_events/constants.d.ts.map +1 -1
  234. package/dist/types/features/generic_events/instrument/index.d.ts +1 -0
  235. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  236. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
  237. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  238. package/dist/types/features/jserrors/instrument/index.d.ts +1 -0
  239. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  240. package/dist/types/features/logging/aggregate/index.d.ts +4 -7
  241. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  242. package/dist/types/features/logging/constants.d.ts +0 -1
  243. package/dist/types/features/logging/constants.d.ts.map +1 -1
  244. package/dist/types/features/logging/instrument/index.d.ts +1 -0
  245. package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
  246. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  247. package/dist/types/features/metrics/aggregate/websocket-detection.d.ts +12 -0
  248. package/dist/types/features/metrics/aggregate/websocket-detection.d.ts.map +1 -0
  249. package/dist/types/features/metrics/constants.d.ts +1 -0
  250. package/dist/types/features/metrics/constants.d.ts.map +1 -1
  251. package/dist/types/features/metrics/instrument/index.d.ts +1 -0
  252. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  253. package/dist/types/features/page_action/instrument/index.d.ts +4 -0
  254. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  255. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  256. package/dist/types/features/page_view_event/instrument/index.d.ts +1 -0
  257. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  258. package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
  259. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  260. package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -0
  261. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  262. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  263. package/dist/types/features/session_replay/constants.d.ts +0 -4
  264. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  265. package/dist/types/features/session_replay/instrument/index.d.ts +1 -0
  266. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  267. package/dist/types/features/session_replay/shared/recorder-events.d.ts +6 -6
  268. package/dist/types/features/session_replay/shared/recorder-events.d.ts.map +1 -1
  269. package/dist/types/features/session_replay/shared/recorder.d.ts +2 -2
  270. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  271. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -1
  272. package/dist/types/features/session_trace/aggregate/index.d.ts +2 -2
  273. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  274. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts +1 -1
  275. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts.map +1 -1
  276. package/dist/types/features/session_trace/instrument/index.d.ts +1 -0
  277. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  278. package/dist/types/features/soft_navigations/aggregate/index.d.ts +3 -3
  279. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  280. package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -0
  281. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  282. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  283. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  284. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  285. package/dist/types/features/spa/constants.d.ts.map +1 -1
  286. package/dist/types/features/spa/instrument/index.d.ts +1 -0
  287. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  288. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  289. package/dist/types/features/utils/aggregate-base.d.ts +1 -0
  290. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  291. package/dist/types/features/utils/event-buffer.d.ts +72 -0
  292. package/dist/types/features/utils/event-buffer.d.ts.map +1 -0
  293. package/dist/types/features/utils/instrument-base.d.ts +1 -0
  294. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  295. package/dist/types/loaders/agent-base.d.ts +1 -1
  296. package/dist/types/loaders/agent.d.ts.map +1 -1
  297. package/dist/types/loaders/api/api.d.ts.map +1 -1
  298. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  299. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  300. package/package.json +55 -59
  301. package/src/common/config/__mocks__/info.js +3 -0
  302. package/src/common/config/__mocks__/init.js +3 -0
  303. package/src/common/config/__mocks__/loader-config.js +2 -0
  304. package/src/common/config/__mocks__/runtime.js +2 -0
  305. package/src/common/config/{state/configurable.js → configurable.js} +1 -1
  306. package/src/common/config/{state/info.js → info.js} +1 -1
  307. package/src/common/config/{state/init.js → init.js} +5 -5
  308. package/src/common/config/{state/loader-config.js → loader-config.js} +1 -1
  309. package/src/common/config/{state/runtime.js → runtime.js} +19 -5
  310. package/src/common/constants/agent-constants.js +2 -0
  311. package/src/common/drain/drain.js +5 -2
  312. package/src/common/event-emitter/contextual-ee.js +1 -1
  313. package/src/common/harvest/harvest.js +7 -21
  314. package/src/common/serialize/bel-serializer.js +5 -7
  315. package/src/common/session/session-entity.js +2 -2
  316. package/src/common/timing/__mocks__/time-keeper.js +6 -2
  317. package/src/common/timing/time-keeper.js +15 -5
  318. package/src/common/util/__mocks__/console.js +1 -0
  319. package/src/common/util/__mocks__/obfuscate.js +5 -8
  320. package/src/common/util/console.js +2 -0
  321. package/src/common/util/obfuscate.js +94 -50
  322. package/src/common/util/text.js +6 -0
  323. package/src/common/window/__mocks__/nreum.js +1 -1
  324. package/src/common/window/nreum.js +2 -1
  325. package/src/common/wrap/wrap-websocket.js +73 -0
  326. package/src/features/ajax/aggregate/chunk.js +3 -2
  327. package/src/features/ajax/aggregate/index.js +20 -19
  328. package/src/features/ajax/constants.js +0 -2
  329. package/src/features/ajax/instrument/distributed-tracing.js +2 -1
  330. package/src/features/ajax/instrument/index.js +9 -5
  331. package/src/features/generic_events/aggregate/index.js +43 -37
  332. package/src/features/generic_events/constants.js +2 -0
  333. package/src/features/generic_events/instrument/index.js +3 -1
  334. package/src/features/jserrors/aggregate/index.js +14 -4
  335. package/src/features/jserrors/instrument/index.js +2 -0
  336. package/src/features/logging/aggregate/index.js +39 -31
  337. package/src/features/logging/constants.js +0 -2
  338. package/src/features/logging/instrument/index.js +2 -0
  339. package/src/features/logging/shared/utils.js +1 -1
  340. package/src/features/metrics/aggregate/index.js +24 -9
  341. package/src/features/metrics/aggregate/websocket-detection.js +31 -0
  342. package/src/features/metrics/constants.js +3 -0
  343. package/src/features/metrics/instrument/index.js +13 -1
  344. package/src/features/page_action/instrument/index.js +5 -0
  345. package/src/features/page_view_event/aggregate/index.js +8 -23
  346. package/src/features/page_view_event/instrument/index.js +2 -0
  347. package/src/features/page_view_timing/aggregate/index.js +14 -16
  348. package/src/features/page_view_timing/instrument/index.js +2 -0
  349. package/src/features/session_replay/aggregate/index.js +13 -9
  350. package/src/features/session_replay/constants.js +0 -4
  351. package/src/features/session_replay/index.js +1 -7
  352. package/src/features/session_replay/instrument/index.js +3 -4
  353. package/src/features/session_replay/shared/recorder-events.js +27 -20
  354. package/src/features/session_replay/shared/recorder.js +13 -6
  355. package/src/features/session_replay/shared/stylesheet-evaluator.js +2 -2
  356. package/src/features/session_replay/shared/utils.js +3 -2
  357. package/src/features/session_trace/aggregate/index.js +16 -7
  358. package/src/features/session_trace/aggregate/trace/storage.js +6 -1
  359. package/src/features/session_trace/instrument/index.js +4 -1
  360. package/src/features/soft_navigations/aggregate/ajax-node.js +1 -1
  361. package/src/features/soft_navigations/aggregate/index.js +13 -15
  362. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  363. package/src/features/soft_navigations/aggregate/interaction.js +1 -1
  364. package/src/features/soft_navigations/instrument/index.js +9 -5
  365. package/src/features/spa/aggregate/index.js +11 -18
  366. package/src/features/spa/aggregate/interaction.js +5 -3
  367. package/src/features/spa/aggregate/serializer.js +1 -1
  368. package/src/features/spa/constants.js +2 -2
  369. package/src/features/spa/instrument/index.js +9 -3
  370. package/src/features/utils/agent-session.js +3 -1
  371. package/src/features/utils/aggregate-base.js +10 -2
  372. package/src/features/utils/event-buffer.js +126 -0
  373. package/src/features/utils/feature-gates.js +1 -1
  374. package/src/features/utils/instrument-base.js +2 -1
  375. package/src/loaders/agent-base.js +2 -2
  376. package/src/loaders/agent.js +7 -2
  377. package/src/loaders/api/api.js +2 -1
  378. package/src/loaders/api/apiAsync.js +1 -1
  379. package/src/loaders/configure/configure.js +4 -1
  380. package/src/loaders/features/enabled-features.js +1 -1
  381. package/src/loaders/micro-agent.js +4 -1
  382. package/dist/cjs/common/config/config.js +0 -76
  383. package/dist/cjs/common/config/state/originals.js +0 -8
  384. package/dist/cjs/common/wrap/index.js +0 -61
  385. package/dist/esm/common/config/config.js +0 -11
  386. package/dist/esm/common/config/state/originals.js +0 -2
  387. package/dist/esm/common/wrap/index.js +0 -13
  388. package/dist/types/common/config/config.d.ts +0 -13
  389. package/dist/types/common/config/config.d.ts.map +0 -1
  390. package/dist/types/common/config/state/configurable.d.ts.map +0 -1
  391. package/dist/types/common/config/state/info.d.ts.map +0 -1
  392. package/dist/types/common/config/state/init.d.ts.map +0 -1
  393. package/dist/types/common/config/state/loader-config.d.ts.map +0 -1
  394. package/dist/types/common/config/state/originals.d.ts +0 -2
  395. package/dist/types/common/config/state/originals.d.ts.map +0 -1
  396. package/dist/types/common/config/state/runtime.d.ts.map +0 -1
  397. package/dist/types/common/wrap/index.d.ts +0 -10
  398. package/dist/types/common/wrap/index.d.ts.map +0 -1
  399. package/src/common/config/__mocks__/config.js +0 -11
  400. package/src/common/config/config.js +0 -12
  401. package/src/common/config/state/originals.js +0 -3
  402. package/src/common/wrap/index.js +0 -16
  403. /package/dist/types/common/config/{state/configurable.d.ts → configurable.d.ts} +0 -0
  404. /package/dist/types/common/config/{state/info.d.ts → info.d.ts} +0 -0
  405. /package/dist/types/common/config/{state/init.d.ts → init.d.ts} +0 -0
  406. /package/dist/types/common/config/{state/loader-config.d.ts → loader-config.d.ts} +0 -0
  407. /package/dist/types/common/config/{state/runtime.d.ts → runtime.d.ts} +0 -0
@@ -7,11 +7,11 @@ import { obj as encodeObj, param as encodeParam } from '../url/encode';
7
7
  import { stringify } from '../util/stringify';
8
8
  import * as submitData from '../util/submit-data';
9
9
  import { getLocation } from '../url/location';
10
- import { getInfo, getConfigurationValue, getRuntime, getConfiguration } from '../config/config';
10
+ import { getInfo } from '../config/info';
11
+ import { getConfigurationValue, getConfiguration } from '../config/init';
12
+ import { getRuntime } from '../config/runtime';
11
13
  import { cleanURL } from '../url/clean-url';
12
14
  import { eventListenerOpts } from '../event-listener/event-listener-opts';
13
- import { Obfuscator } from '../util/obfuscate';
14
- import { applyFnToProps } from '../util/traverse';
15
15
  import { SharedContext } from '../context/shared-context';
16
16
  import { VERSION } from "../constants/env.npm";
17
17
  import { isWorkerScope } from '../constants/runtime';
@@ -31,7 +31,7 @@ export class Harvest extends SharedContext {
31
31
  super(parent); // gets any allowed properties from the parent and stores them in `sharedContext`
32
32
 
33
33
  this.tooManyRequestsDelay = getConfigurationValue(this.sharedContext.agentIdentifier, 'harvest.tooManyRequestsDelay') || 60;
34
- this.obfuscator = new Obfuscator(this.sharedContext);
34
+ this.obfuscator = getRuntime(this.sharedContext.agentIdentifier).obfuscator;
35
35
  this._events = {};
36
36
  }
37
37
 
@@ -41,8 +41,7 @@ export class Harvest extends SharedContext {
41
41
  * Note: Used by page_action
42
42
  * @param {NetworkSendSpec} spec Specification for sending data
43
43
  */
44
- sendX() {
45
- let spec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
44
+ sendX(spec = {}) {
46
45
  const submitMethod = submitData.getSubmitMethod({
47
46
  isFinalHarvest: spec.opts?.unload
48
47
  });
@@ -51,7 +50,7 @@ export class Harvest extends SharedContext {
51
50
  isFinalHarvest: spec.opts?.unload === true
52
51
  };
53
52
  const payload = this.createPayload(spec.endpoint, options);
54
- const caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
53
+ const caller = this._send.bind(this);
55
54
  return caller({
56
55
  ...spec,
57
56
  payload,
@@ -63,31 +62,11 @@ export class Harvest extends SharedContext {
63
62
  * Initiate a harvest call.
64
63
  * @param {NetworkSendSpec} spec Specification for sending data
65
64
  */
66
- send() {
67
- let spec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
68
- const caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
65
+ send(spec = {}) {
66
+ const caller = this._send.bind(this);
69
67
  return caller(spec);
70
68
  }
71
69
 
72
- /**
73
- * Apply obfuscation rules to the payload and then initial the harvest network call.
74
- * @param {NetworkSendSpec} spec Specification for sending data
75
- */
76
- obfuscateAndSend() {
77
- var _this = this;
78
- let spec = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
79
- const {
80
- payload = {}
81
- } = spec;
82
- applyFnToProps(payload, function () {
83
- return _this.obfuscator.obfuscateString(...arguments);
84
- }, 'string', ['e']);
85
- return this._send({
86
- ...spec,
87
- payload
88
- });
89
- }
90
-
91
70
  /**
92
71
  * Initiate a harvest call. Typically used by `sendX` and `send` methods or called directly
93
72
  * for raw network calls.
@@ -95,17 +74,16 @@ export class Harvest extends SharedContext {
95
74
  * @returns {boolean} True if the network call succeeded. For final harvest calls, the return
96
75
  * value should not be relied upon because network calls will be made asynchronously.
97
76
  */
98
- _send(_ref) {
99
- let {
100
- endpoint,
101
- payload = {},
102
- opts = {},
103
- submitMethod,
104
- cbFinished,
105
- customUrl,
106
- raw,
107
- includeBaseParams = true
108
- } = _ref;
77
+ _send({
78
+ endpoint,
79
+ payload = {},
80
+ opts = {},
81
+ submitMethod,
82
+ cbFinished,
83
+ customUrl,
84
+ raw,
85
+ includeBaseParams = true
86
+ }) {
109
87
  const info = getInfo(this.sharedContext.agentIdentifier);
110
88
  if (!info.errorBeacon) return false;
111
89
  const agentRuntime = getRuntime(this.sharedContext.agentIdentifier);
@@ -193,8 +171,6 @@ export class Harvest extends SharedContext {
193
171
  cbFinished(cbResult);
194
172
  }, eventListenerOpts(false));
195
173
  }
196
- const runtime = getRuntime(this.sharedContext.agentIdentifier);
197
- runtime.harvestCount++;
198
174
  return result;
199
175
  }
200
176
 
@@ -202,8 +178,7 @@ export class Harvest extends SharedContext {
202
178
  baseQueryString(qs, endpoint) {
203
179
  const runtime = getRuntime(this.sharedContext.agentIdentifier);
204
180
  const info = getInfo(this.sharedContext.agentIdentifier);
205
- const location = cleanURL(getLocation());
206
- const ref = this.obfuscator.shouldObfuscate() ? this.obfuscator.obfuscateString(location) : location;
181
+ const ref = this.obfuscator.obfuscateString(cleanURL(getLocation()));
207
182
  const hr = runtime?.session?.state.sessionReplayMode === 1 && endpoint !== 'jserrors';
208
183
  const qps = ['a=' + info.applicationID, encodeParam('sa', info.sa ? '' + info.sa : ''), encodeParam('v', VERSION), transactionNameParam(info), encodeParam('ct', runtime.customTransaction), '&rst=' + now(), '&ck=0',
209
184
  // ck param DEPRECATED - still expected by backend
@@ -254,13 +229,11 @@ export class Harvest extends SharedContext {
254
229
  * @param {HarvestPayload} payload Payload to be sent to the endpoint.
255
230
  * @returns {HarvestPayload} Cleaned payload payload to be sent to the endpoint.
256
231
  */
257
- cleanPayload() {
258
- let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
232
+ cleanPayload(payload = {}) {
259
233
  const clean = input => {
260
234
  if (typeof Uint8Array !== 'undefined' && input instanceof Uint8Array || Array.isArray(input)) return input;
261
235
  if (typeof input === 'string') return input.length > 0 ? input : null;
262
- return Object.entries(input || {}).reduce((accumulator, _ref2) => {
263
- let [key, value] = _ref2;
236
+ return Object.entries(input || {}).reduce((accumulator, [key, value]) => {
264
237
  if (typeof value === 'number' || typeof value === 'string' && value.length > 0 || typeof value === 'object' && Object.keys(value || {}).length > 0) {
265
238
  accumulator[key] = value;
266
239
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { stringify } from '../util/stringify';
7
- import { Obfuscator } from '../util/obfuscate';
7
+ import { getRuntime } from '../config/runtime';
8
8
  var hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var MAX_ATTRIBUTES = 64;
10
10
  export function nullable(val, fn, comma) {
@@ -17,17 +17,13 @@ export function numeric(n, noDefault) {
17
17
  return n === undefined || n === 0 ? '' : Math.floor(n).toString(36);
18
18
  }
19
19
  export function getAddStringContext(agentIdentifier) {
20
- // eslint-disable-next-line
21
- var stringTable = Object.hasOwnProperty('create') ? Object.create(null) : {};
22
- var stringTableIdx = 0;
20
+ let stringTableIdx = 0;
21
+ const stringTable = Object.prototype.hasOwnProperty.call(Object, 'create') ? Object.create(null) : {};
22
+ const obfuscator = getRuntime(agentIdentifier).obfuscator;
23
23
  return addString;
24
24
  function addString(str) {
25
25
  if (typeof str === 'undefined' || str === '') return '';
26
- var obfuscator = new Obfuscator({
27
- agentIdentifier
28
- });
29
- str = String(str);
30
- if (obfuscator.shouldObfuscate()) str = obfuscator.obfuscateString(str);
26
+ str = obfuscator.obfuscateString(String(str));
31
27
  if (hasOwnProp.call(stringTable, str)) {
32
28
  return numeric(stringTable[str], true);
33
29
  } else {
@@ -38,8 +34,7 @@ export function getAddStringContext(agentIdentifier) {
38
34
  }
39
35
  export function addCustomAttributes(attrs, addString) {
40
36
  var attrParts = [];
41
- Object.entries(attrs || {}).forEach(_ref => {
42
- let [key, val] = _ref;
37
+ Object.entries(attrs || {}).forEach(([key, val]) => {
43
38
  if (attrParts.length >= MAX_ATTRIBUTES) return;
44
39
  var type = 5;
45
40
  var serializedValue;
@@ -6,8 +6,8 @@ import { Timer } from '../timer/timer';
6
6
  import { isBrowserScope } from '../constants/runtime';
7
7
  import { DEFAULT_EXPIRES_MS, DEFAULT_INACTIVE_MS, MODE, PREFIX, SESSION_EVENTS, SESSION_EVENT_TYPES } from './constants';
8
8
  import { InteractionTimer } from '../timer/interaction-timer';
9
- import { wrapEvents } from '../wrap';
10
- import { getModeledObject } from '../config/state/configurable';
9
+ import { wrapEvents } from '../wrap/wrap-events';
10
+ import { getModeledObject } from '../config/configurable';
11
11
  import { handle } from '../event-emitter/handle';
12
12
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants';
13
13
  import { FEATURE_NAMES } from '../../loaders/features/features';
@@ -69,12 +69,11 @@ export class SessionEntity {
69
69
  });
70
70
  }
71
71
  }
72
- setup(_ref) {
73
- let {
74
- value = generateRandomHexString(16),
75
- expiresMs = DEFAULT_EXPIRES_MS,
76
- inactiveMs = DEFAULT_INACTIVE_MS
77
- } = _ref;
72
+ setup({
73
+ value = generateRandomHexString(16),
74
+ expiresMs = DEFAULT_EXPIRES_MS,
75
+ inactiveMs = DEFAULT_INACTIVE_MS
76
+ }) {
78
77
  /** Ensure that certain properties are preserved across a reset if already set */
79
78
  const persistentAttributes = {
80
79
  serverTimeDiff: this.state.serverTimeDiff || model.serverTimeDiff
@@ -282,9 +281,7 @@ export class SessionEntity {
282
281
  if (type === 'inactive') tag = 'Session/Inactive/Seen';
283
282
  if (tag) handle(SUPPORTABILITY_METRIC_CHANNEL, [tag, value], undefined, FEATURE_NAMES.metrics, this.ee);
284
283
  }
285
- getDuration() {
286
- let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state;
287
- let useUpdatedAt = arguments.length > 1 ? arguments[1] : undefined;
284
+ getDuration(data = this.state, useUpdatedAt) {
288
285
  const startingTimestamp = data.expiresAt - this.expiresMs;
289
286
  const endingTimestamp = !useUpdatedAt ? data.updatedAt : Date.now();
290
287
  return endingTimestamp - startingTimestamp;
@@ -35,9 +35,7 @@ function getPntType(type) {
35
35
  };
36
36
  return types[type];
37
37
  }
38
- export function addPT(offset, pt) {
39
- let v = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
40
- let isL1Api = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
38
+ export function addPT(offset, pt, v = {}, isL1Api = false) {
41
39
  if (!pt) return;
42
40
  v.of = offset;
43
41
  handleValue(v.of, v, 'n', true);
@@ -1,5 +1,5 @@
1
1
  import { originTime } from '../constants/runtime';
2
- import { getRuntime } from '../config/config';
2
+ import { getRuntime } from '../config/runtime';
3
3
  const rfc2616Regex = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-3][0-9]) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([0-9]{4}) ([01][0-9]|2[0-3])(:[0-5][0-9]){2} GMT$/;
4
4
 
5
5
  /**
@@ -81,21 +81,31 @@ export class TimeKeeper {
81
81
 
82
82
  /**
83
83
  * Converts a page origin relative time to an absolute timestamp
84
- * corrected to NR server time.
84
+ * using the user's local clock.
85
85
  * @param relativeTime {number} The relative time of the event in milliseconds
86
86
  * @returns {number} Corrected unix/epoch timestamp
87
87
  */
88
88
  convertRelativeTimestamp(relativeTime) {
89
- return Math.floor(this.#correctedOriginTime + relativeTime);
89
+ return originTime + relativeTime;
90
90
  }
91
91
 
92
92
  /**
93
- * Corrects an event timestamp to NR server time.
93
+ * Converts an absolute timestamp to a relative timestamp using the
94
+ * user's local clock.
95
+ * @param timestamp
96
+ * @returns {number}
97
+ */
98
+ convertAbsoluteTimestamp(timestamp) {
99
+ return timestamp - originTime;
100
+ }
101
+
102
+ /**
103
+ * Corrects an absolute timestamp to NR server time.
94
104
  * @param timestamp {number} The unix/epoch timestamp of the event with milliseconds
95
105
  * @return {number} Corrected unix/epoch timestamp
96
106
  */
97
107
  correctAbsoluteTimestamp(timestamp) {
98
- return Math.floor(timestamp - this.#localTimeDiff);
108
+ return timestamp - this.#localTimeDiff;
99
109
  }
100
110
 
101
111
  /** Process the session entity and use the info to set the main time calculations if present */
@@ -37,8 +37,7 @@ export function fromArray(qs, maxBytes) {
37
37
  export function obj(payload, maxBytes) {
38
38
  var total = 0;
39
39
  var result = '';
40
- Object.entries(payload || {}).forEach(_ref => {
41
- let [feature, dataArray] = _ref;
40
+ Object.entries(payload || {}).forEach(([feature, dataArray]) => {
42
41
  var intermediate = [];
43
42
  var next;
44
43
  var i;
@@ -61,8 +60,7 @@ export function obj(payload, maxBytes) {
61
60
  }
62
61
 
63
62
  // Constructs an HTTP parameter to add to the BAM router URL
64
- export function param(name, value) {
65
- let base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
63
+ export function param(name, value, base = {}) {
66
64
  if (Object.keys(base).includes(name)) return ''; // we assume if feature supplied a matching qp to the base, we should honor what the feature sent over the default
67
65
  if (value && typeof value === 'string') {
68
66
  return '&' + name + '=' + qs(value);
@@ -1,3 +1,5 @@
1
+ /* eslint no-console: ["error", { allow: ["debug"] }] */
2
+
1
3
  /**
2
4
  * A helper method to warn to the console with New Relic: decoration
3
5
  * @param {string} message The primary message to warn
@@ -20,18 +20,12 @@
20
20
  * @returns {function} A wrapping function that will ensure the provided function
21
21
  * is invoked only once within the given timeout.
22
22
  */
23
- export function debounce(func) {
24
- var _this = this;
25
- let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
26
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
23
+ export function debounce(func, timeout = 500, options = {}) {
27
24
  const leading = options?.leading || false;
28
25
  let timer;
29
- return function () {
30
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
31
- args[_key] = arguments[_key];
32
- }
26
+ return (...args) => {
33
27
  if (leading && timer === undefined) {
34
- func.apply(_this, args);
28
+ func.apply(this, args);
35
29
  timer = setTimeout(() => {
36
30
  timer = clearTimeout(timer);
37
31
  }, timeout);
@@ -39,7 +33,7 @@ export function debounce(func) {
39
33
  if (!leading) {
40
34
  clearTimeout(timer);
41
35
  timer = setTimeout(() => {
42
- func.apply(_this, args);
36
+ func.apply(this, args);
43
37
  }, timeout);
44
38
  }
45
39
  };
@@ -54,15 +48,11 @@ export function debounce(func) {
54
48
  * is invoked only once.
55
49
  */
56
50
  export function single(func) {
57
- var _this2 = this;
58
51
  let called = false;
59
- return function () {
52
+ return (...args) => {
60
53
  if (!called) {
61
54
  called = true;
62
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
63
- args[_key2] = arguments[_key2];
64
- }
65
- func.apply(_this2, args);
55
+ func.apply(this, args);
66
56
  }
67
57
  };
68
58
  }
@@ -1,61 +1,108 @@
1
- import { getConfigurationValue } from '../config/config';
2
- import { SharedContext } from '../context/shared-context';
1
+ import { getConfigurationValue } from '../config/init';
3
2
  import { isFileProtocol } from '../url/protocol';
4
3
  import { warn } from './console';
5
- var fileProtocolRule = {
6
- regex: /^file:\/\/(.*)/,
7
- replacement: atob('ZmlsZTovL09CRlVTQ0FURUQ=')
8
- };
9
- export class Obfuscator extends SharedContext {
10
- shouldObfuscate() {
11
- return getRules(this.sharedContext.agentIdentifier).length > 0;
4
+
5
+ /**
6
+ * Represents an obfuscation rule that can be applied to harvested payloads
7
+ * @typedef {object} ObfuscationRule
8
+ * @property {string|RegExp} regex The regular expression to match against in the payload
9
+ * @property {string} [replacement] The string to replace the matched regex with
10
+ */
11
+
12
+ /**
13
+ * Represents an obfuscation rule validation state
14
+ * @typedef {object} ObfuscationRuleValidation
15
+ * @property {ObfuscationRule} rule The original rule validated
16
+ * @property {boolean} isValid Whether the rule is valid
17
+ * @property {object} errors Validation errors
18
+ * @property {boolean} errors.regexMissingDetected Whether the regex is missing
19
+ * @property {boolean} errors.invalidRegexDetected Whether the regex is invalid
20
+ * @property {boolean} errors.invalidReplacementDetected Whether the replacement is invalid
21
+ */
22
+
23
+ export class Obfuscator {
24
+ /**
25
+ * @type {ObfuscationRuleValidation[]}
26
+ */
27
+ #ruleValidationCache;
28
+ constructor(agentIdentifier) {
29
+ this.#ruleValidationCache = Obfuscator.getRuleValidationCache(agentIdentifier);
30
+ Obfuscator.logObfuscationRuleErrors(this.#ruleValidationCache);
31
+ }
32
+ get ruleValidationCache() {
33
+ return this.#ruleValidationCache;
12
34
  }
13
35
 
14
- // applies all regex obfuscation rules to provided URL string and returns the result
15
- obfuscateString(string) {
16
- // if string is empty string, null or not a string, return unmodified
17
- if (!string || typeof string !== 'string') return string;
18
- var rules = getRules(this.sharedContext.agentIdentifier);
19
- var obfuscated = string;
36
+ /**
37
+ * Applies all valid obfuscation rules to the provided input string
38
+ * @param {string} input String to obfuscate
39
+ * @returns {string}
40
+ */
41
+ obfuscateString(input) {
42
+ // if input is not of type string or is an empty string, short-circuit
43
+ if (typeof input !== 'string' || input.trim().length === 0) return input;
44
+ return this.#ruleValidationCache.filter(ruleValidation => ruleValidation.isValid).reduce((input, ruleValidation) => {
45
+ const {
46
+ rule
47
+ } = ruleValidation;
48
+ return input.replace(rule.regex, rule.replacement || '*');
49
+ }, input);
50
+ }
20
51
 
21
- // apply every rule to URL string
22
- for (var i = 0; i < rules.length; i++) {
23
- var regex = rules[i].regex;
24
- var replacement = rules[i].replacement || '*';
25
- obfuscated = obfuscated.replace(regex, replacement);
52
+ /**
53
+ * Returns an array of obfuscation rules to be applied to harvested payloads
54
+ * @param {string} agentIdentifier The agent identifier to get rules for
55
+ * @returns {ObfuscationRuleValidation[]} The array of rules or validation states
56
+ */
57
+ static getRuleValidationCache(agentIdentifier) {
58
+ /**
59
+ * @type {ObfuscationRule[]}
60
+ */
61
+ let rules = getConfigurationValue(agentIdentifier, 'obfuscate') || [];
62
+ if (isFileProtocol()) {
63
+ rules.push({
64
+ regex: /^file:\/\/(.*)/,
65
+ replacement: atob('ZmlsZTovL09CRlVTQ0FURUQ=')
66
+ });
26
67
  }
27
- return obfuscated;
68
+ return rules.map(rule => Obfuscator.validateObfuscationRule(rule));
28
69
  }
29
- }
30
-
31
- // TO DO: this function should be inside the Obfuscator class since its context relates to agentID
32
- export function getRules(agentIdentifier) {
33
- var rules = [];
34
- var configRules = getConfigurationValue(agentIdentifier, 'obfuscate') || [];
35
- rules = rules.concat(configRules);
36
- if (isFileProtocol()) rules.push(fileProtocolRule);
37
- // could add additional runtime/environment-specific rules here
38
70
 
39
- return rules;
40
- }
71
+ /**
72
+ * Validates an obfuscation rule and provides errors if any are found.
73
+ * @param {ObfuscationRule} rule The rule to validate
74
+ * @returns {ObfuscationRuleValidation} The validation state of the rule
75
+ */
76
+ static validateObfuscationRule(rule) {
77
+ const regexMissingDetected = Boolean(rule.regex === undefined);
78
+ const invalidRegexDetected = Boolean(rule.regex !== undefined && typeof rule.regex !== 'string' && !(rule.regex instanceof RegExp));
79
+ const invalidReplacementDetected = Boolean(rule.replacement && typeof rule.replacement !== 'string');
80
+ return {
81
+ rule,
82
+ isValid: !regexMissingDetected && !invalidRegexDetected && !invalidReplacementDetected,
83
+ errors: {
84
+ regexMissingDetected,
85
+ invalidRegexDetected,
86
+ invalidReplacementDetected
87
+ }
88
+ };
89
+ }
41
90
 
42
- // takes array of rule objects, logs warning and returns false if any portion of rule is invalid
43
- export function validateRules(rules) {
44
- var invalidReplacementDetected = false;
45
- var invalidRegexDetected = false;
46
- for (var i = 0; i < rules.length; i++) {
47
- if (!('regex' in rules[i])) {
48
- warn(12);
49
- invalidRegexDetected = true;
50
- } else if (typeof rules[i].regex !== 'string' && !(rules[i].regex instanceof RegExp)) {
51
- warn(13);
52
- invalidRegexDetected = true;
53
- }
54
- var replacement = rules[i].replacement;
55
- if (replacement && typeof replacement !== 'string') {
56
- warn(14);
57
- invalidReplacementDetected = true;
91
+ /**
92
+ * Logs any obfuscation rule errors to the console. This is called when an obfuscator
93
+ * instance is created.
94
+ * @param {ObfuscationRuleValidation[]} ruleValidationCache The cache of rule validation states
95
+ */
96
+ static logObfuscationRuleErrors(ruleValidationCache) {
97
+ for (const ruleValidation of ruleValidationCache) {
98
+ const {
99
+ rule,
100
+ isValid,
101
+ errors
102
+ } = ruleValidation;
103
+ if (isValid) continue;
104
+ if (errors.regexMissingDetected) warn(12, rule);else if (errors.invalidRegexDetected) warn(13, rule);
105
+ if (errors.invalidReplacementDetected) warn(14, rule);
58
106
  }
59
107
  }
60
- return !invalidReplacementDetected && !invalidRegexDetected;
61
108
  }
@@ -16,10 +16,9 @@ import { isBrowserScope, supportsSendBeacon } from '../constants/runtime';
16
16
  * @param {boolean} opts.isFinalHarvest Indicates if the data submission is due to
17
17
  * a final harvest within the agent.
18
18
  */
19
- export function getSubmitMethod() {
20
- let {
21
- isFinalHarvest = false
22
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ export function getSubmitMethod({
20
+ isFinalHarvest = false
21
+ } = {}) {
23
22
  return isFinalHarvest && isBrowserScope && supportsSendBeacon
24
23
  // Use sendBeacon for final harvest
25
24
  ? beacon
@@ -37,17 +36,16 @@ export function getSubmitMethod() {
37
36
  * @param {{key: string, value: string}[]} [args.headers] - The headers to attach.
38
37
  * @returns {XMLHttpRequest}
39
38
  */
40
- export function xhr(_ref) {
41
- let {
42
- url,
43
- body = null,
44
- sync,
45
- method = 'POST',
46
- headers = [{
47
- key: 'content-type',
48
- value: 'text/plain'
49
- }]
50
- } = _ref;
39
+ export function xhr({
40
+ url,
41
+ body = null,
42
+ sync,
43
+ method = 'POST',
44
+ headers = [{
45
+ key: 'content-type',
46
+ value: 'text/plain'
47
+ }]
48
+ }) {
51
49
  const request = new XMLHttpRequest();
52
50
  request.open(method, url, !sync);
53
51
  try {
@@ -70,11 +68,10 @@ export function xhr(_ref) {
70
68
  * @param {string=} args.body - The Stringified body
71
69
  * @returns {boolean}
72
70
  */
73
- export function beacon(_ref2) {
74
- let {
75
- url,
76
- body
77
- } = _ref2;
71
+ export function beacon({
72
+ url,
73
+ body
74
+ }) {
78
75
  try {
79
76
  // Navigator has to be bound to ensure it does not error in some browsers
80
77
  // https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
@@ -0,0 +1,3 @@
1
+ export function toTitleCase(str, regex = /\w*/g) {
2
+ return str.replace(regex, text => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase());
3
+ }
@@ -12,9 +12,7 @@
12
12
  * @param {Array<string>} [ignoreKeys=[]] - The keys of properties to ignore and not modify.
13
13
  * @returns {Object} - The object with function recursively applied.
14
14
  */
15
- export function applyFnToProps(obj, fn) {
16
- let type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'string';
17
- let ignoreKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
15
+ export function applyFnToProps(obj, fn, type = 'string', ignoreKeys = []) {
18
16
  if (!obj || typeof obj !== 'object') return obj;
19
17
  Object.keys(obj).forEach(property => {
20
18
  if (typeof obj[property] === 'object') {
@@ -4,12 +4,11 @@ import { VitalMetric } from './vital-metric';
4
4
  import { isBrowserScope } from '../constants/runtime';
5
5
  export const cumulativeLayoutShift = new VitalMetric(VITAL_NAMES.CUMULATIVE_LAYOUT_SHIFT, x => x);
6
6
  if (isBrowserScope) {
7
- onCLS(_ref => {
8
- let {
9
- value,
10
- attribution,
11
- id
12
- } = _ref;
7
+ onCLS(({
8
+ value,
9
+ attribution,
10
+ id
11
+ }) => {
13
12
  const attrs = {
14
13
  metricId: id,
15
14
  largestShiftTarget: attribution.largestShiftTarget,
@@ -25,11 +25,10 @@ if (isBrowserScope) {
25
25
  // ignore
26
26
  }
27
27
  } else {
28
- onFCP(_ref => {
29
- let {
30
- value,
31
- attribution
32
- } = _ref;
28
+ onFCP(({
29
+ value,
30
+ attribution
31
+ }) => {
33
32
  if (initiallyHidden || firstContentfulPaint.isValid) return;
34
33
  const attrs = {
35
34
  timeToFirstByte: attribution.timeToFirstByte,
@@ -4,11 +4,10 @@ import { VITAL_NAMES } from './constants';
4
4
  import { initiallyHidden, isBrowserScope } from '../constants/runtime';
5
5
  export const firstInputDelay = new VitalMetric(VITAL_NAMES.FIRST_INPUT_DELAY);
6
6
  if (isBrowserScope) {
7
- onFID(_ref => {
8
- let {
9
- value,
10
- attribution
11
- } = _ref;
7
+ onFID(({
8
+ value,
9
+ attribution
10
+ }) => {
12
11
  if (initiallyHidden || firstInputDelay.isValid) return;
13
12
  const attrs = {
14
13
  type: attribution.eventType,
@@ -5,12 +5,11 @@ import { isBrowserScope } from '../constants/runtime';
5
5
  export const interactionToNextPaint = new VitalMetric(VITAL_NAMES.INTERACTION_TO_NEXT_PAINT);
6
6
  if (isBrowserScope) {
7
7
  /* Interaction-to-Next-Paint */
8
- onINP(_ref => {
9
- let {
10
- value,
11
- attribution,
12
- id
13
- } = _ref;
8
+ onINP(({
9
+ value,
10
+ attribution,
11
+ id
12
+ }) => {
14
13
  const attrs = {
15
14
  metricId: id,
16
15
  eventTarget: attribution.eventTarget,