@newrelic/browser-agent 1.264.0 → 1.265.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (406) hide show
  1. package/CHANGELOG.md +31 -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 +37 -18
  58. package/dist/cjs/features/metrics/aggregate/websocket-detection.js +34 -0
  59. package/dist/cjs/features/metrics/constants.js +5 -1
  60. package/dist/cjs/features/metrics/instrument/index.js +16 -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 +31 -12
  157. package/dist/esm/features/metrics/aggregate/websocket-detection.js +29 -0
  158. package/dist/esm/features/metrics/constants.js +4 -1
  159. package/dist/esm/features/metrics/instrument/index.js +15 -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.map +1 -1
  250. package/dist/types/features/metrics/instrument/index.d.ts +1 -0
  251. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  252. package/dist/types/features/page_action/instrument/index.d.ts +4 -0
  253. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  254. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  255. package/dist/types/features/page_view_event/instrument/index.d.ts +1 -0
  256. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  257. package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
  258. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  259. package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -0
  260. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  261. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  262. package/dist/types/features/session_replay/constants.d.ts +0 -4
  263. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  264. package/dist/types/features/session_replay/instrument/index.d.ts +1 -0
  265. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  266. package/dist/types/features/session_replay/shared/recorder-events.d.ts +6 -6
  267. package/dist/types/features/session_replay/shared/recorder-events.d.ts.map +1 -1
  268. package/dist/types/features/session_replay/shared/recorder.d.ts +2 -2
  269. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  270. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -1
  271. package/dist/types/features/session_trace/aggregate/index.d.ts +2 -2
  272. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  273. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts +1 -1
  274. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts.map +1 -1
  275. package/dist/types/features/session_trace/instrument/index.d.ts +1 -0
  276. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  277. package/dist/types/features/soft_navigations/aggregate/index.d.ts +3 -3
  278. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  279. package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -0
  280. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  281. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  282. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  283. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  284. package/dist/types/features/spa/constants.d.ts.map +1 -1
  285. package/dist/types/features/spa/instrument/index.d.ts +1 -0
  286. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  287. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  288. package/dist/types/features/utils/aggregate-base.d.ts +1 -0
  289. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  290. package/dist/types/features/utils/event-buffer.d.ts +72 -0
  291. package/dist/types/features/utils/event-buffer.d.ts.map +1 -0
  292. package/dist/types/features/utils/instrument-base.d.ts +1 -0
  293. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  294. package/dist/types/loaders/agent-base.d.ts +1 -1
  295. package/dist/types/loaders/agent.d.ts.map +1 -1
  296. package/dist/types/loaders/api/api.d.ts.map +1 -1
  297. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  298. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  299. package/package.json +55 -59
  300. package/src/common/config/__mocks__/info.js +3 -0
  301. package/src/common/config/__mocks__/init.js +3 -0
  302. package/src/common/config/__mocks__/loader-config.js +2 -0
  303. package/src/common/config/__mocks__/runtime.js +2 -0
  304. package/src/common/config/{state/configurable.js → configurable.js} +1 -1
  305. package/src/common/config/{state/info.js → info.js} +1 -1
  306. package/src/common/config/{state/init.js → init.js} +5 -5
  307. package/src/common/config/{state/loader-config.js → loader-config.js} +1 -1
  308. package/src/common/config/{state/runtime.js → runtime.js} +19 -5
  309. package/src/common/constants/agent-constants.js +2 -0
  310. package/src/common/drain/drain.js +5 -2
  311. package/src/common/event-emitter/contextual-ee.js +1 -1
  312. package/src/common/harvest/harvest.js +7 -21
  313. package/src/common/serialize/bel-serializer.js +5 -7
  314. package/src/common/session/session-entity.js +2 -2
  315. package/src/common/timing/__mocks__/time-keeper.js +6 -2
  316. package/src/common/timing/time-keeper.js +15 -5
  317. package/src/common/util/__mocks__/console.js +1 -0
  318. package/src/common/util/__mocks__/obfuscate.js +5 -8
  319. package/src/common/util/console.js +2 -0
  320. package/src/common/util/obfuscate.js +94 -50
  321. package/src/common/util/text.js +6 -0
  322. package/src/common/window/__mocks__/nreum.js +1 -1
  323. package/src/common/window/nreum.js +2 -1
  324. package/src/common/wrap/wrap-websocket.js +73 -0
  325. package/src/features/ajax/aggregate/chunk.js +3 -2
  326. package/src/features/ajax/aggregate/index.js +20 -19
  327. package/src/features/ajax/constants.js +0 -2
  328. package/src/features/ajax/instrument/distributed-tracing.js +2 -1
  329. package/src/features/ajax/instrument/index.js +9 -5
  330. package/src/features/generic_events/aggregate/index.js +43 -37
  331. package/src/features/generic_events/constants.js +2 -0
  332. package/src/features/generic_events/instrument/index.js +3 -1
  333. package/src/features/jserrors/aggregate/index.js +14 -4
  334. package/src/features/jserrors/instrument/index.js +2 -0
  335. package/src/features/logging/aggregate/index.js +39 -31
  336. package/src/features/logging/constants.js +0 -2
  337. package/src/features/logging/instrument/index.js +2 -0
  338. package/src/features/logging/shared/utils.js +1 -1
  339. package/src/features/metrics/aggregate/index.js +24 -9
  340. package/src/features/metrics/aggregate/websocket-detection.js +31 -0
  341. package/src/features/metrics/constants.js +3 -0
  342. package/src/features/metrics/instrument/index.js +13 -1
  343. package/src/features/page_action/instrument/index.js +5 -0
  344. package/src/features/page_view_event/aggregate/index.js +8 -23
  345. package/src/features/page_view_event/instrument/index.js +2 -0
  346. package/src/features/page_view_timing/aggregate/index.js +14 -16
  347. package/src/features/page_view_timing/instrument/index.js +2 -0
  348. package/src/features/session_replay/aggregate/index.js +13 -9
  349. package/src/features/session_replay/constants.js +0 -4
  350. package/src/features/session_replay/index.js +1 -7
  351. package/src/features/session_replay/instrument/index.js +3 -4
  352. package/src/features/session_replay/shared/recorder-events.js +27 -20
  353. package/src/features/session_replay/shared/recorder.js +13 -6
  354. package/src/features/session_replay/shared/stylesheet-evaluator.js +2 -2
  355. package/src/features/session_replay/shared/utils.js +3 -2
  356. package/src/features/session_trace/aggregate/index.js +16 -7
  357. package/src/features/session_trace/aggregate/trace/storage.js +6 -1
  358. package/src/features/session_trace/instrument/index.js +4 -1
  359. package/src/features/soft_navigations/aggregate/ajax-node.js +1 -1
  360. package/src/features/soft_navigations/aggregate/index.js +13 -15
  361. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  362. package/src/features/soft_navigations/aggregate/interaction.js +1 -1
  363. package/src/features/soft_navigations/instrument/index.js +9 -5
  364. package/src/features/spa/aggregate/index.js +11 -18
  365. package/src/features/spa/aggregate/interaction.js +5 -3
  366. package/src/features/spa/aggregate/serializer.js +1 -1
  367. package/src/features/spa/constants.js +2 -2
  368. package/src/features/spa/instrument/index.js +9 -3
  369. package/src/features/utils/agent-session.js +3 -1
  370. package/src/features/utils/aggregate-base.js +10 -2
  371. package/src/features/utils/event-buffer.js +126 -0
  372. package/src/features/utils/feature-gates.js +1 -1
  373. package/src/features/utils/instrument-base.js +2 -1
  374. package/src/loaders/agent-base.js +2 -2
  375. package/src/loaders/agent.js +7 -2
  376. package/src/loaders/api/api.js +2 -1
  377. package/src/loaders/api/apiAsync.js +1 -1
  378. package/src/loaders/configure/configure.js +4 -1
  379. package/src/loaders/features/enabled-features.js +1 -1
  380. package/src/loaders/micro-agent.js +4 -1
  381. package/dist/cjs/common/config/config.js +0 -76
  382. package/dist/cjs/common/config/state/originals.js +0 -8
  383. package/dist/cjs/common/wrap/index.js +0 -61
  384. package/dist/esm/common/config/config.js +0 -11
  385. package/dist/esm/common/config/state/originals.js +0 -2
  386. package/dist/esm/common/wrap/index.js +0 -13
  387. package/dist/types/common/config/config.d.ts +0 -13
  388. package/dist/types/common/config/config.d.ts.map +0 -1
  389. package/dist/types/common/config/state/configurable.d.ts.map +0 -1
  390. package/dist/types/common/config/state/info.d.ts.map +0 -1
  391. package/dist/types/common/config/state/init.d.ts.map +0 -1
  392. package/dist/types/common/config/state/loader-config.d.ts.map +0 -1
  393. package/dist/types/common/config/state/originals.d.ts +0 -2
  394. package/dist/types/common/config/state/originals.d.ts.map +0 -1
  395. package/dist/types/common/config/state/runtime.d.ts.map +0 -1
  396. package/dist/types/common/wrap/index.d.ts +0 -10
  397. package/dist/types/common/wrap/index.d.ts.map +0 -1
  398. package/src/common/config/__mocks__/config.js +0 -11
  399. package/src/common/config/config.js +0 -12
  400. package/src/common/config/state/originals.js +0 -3
  401. package/src/common/wrap/index.js +0 -16
  402. /package/dist/types/common/config/{state/configurable.d.ts → configurable.d.ts} +0 -0
  403. /package/dist/types/common/config/{state/info.d.ts → info.d.ts} +0 -0
  404. /package/dist/types/common/config/{state/init.d.ts → init.d.ts} +0 -0
  405. /package/dist/types/common/config/{state/loader-config.d.ts → loader-config.d.ts} +0 -0
  406. /package/dist/types/common/config/{state/runtime.d.ts → runtime.d.ts} +0 -0
@@ -45,8 +45,7 @@ function fromArray(qs, maxBytes) {
45
45
  function obj(payload, maxBytes) {
46
46
  var total = 0;
47
47
  var result = '';
48
- Object.entries(payload || {}).forEach(_ref => {
49
- let [feature, dataArray] = _ref;
48
+ Object.entries(payload || {}).forEach(([feature, dataArray]) => {
50
49
  var intermediate = [];
51
50
  var next;
52
51
  var i;
@@ -69,8 +68,7 @@ function obj(payload, maxBytes) {
69
68
  }
70
69
 
71
70
  // Constructs an HTTP parameter to add to the BAM router URL
72
- function param(name, value) {
73
- let base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
71
+ function param(name, value, base = {}) {
74
72
  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
75
73
  if (value && typeof value === 'string') {
76
74
  return '&' + name + '=' + qs(value);
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.warn = warn;
7
+ /* eslint no-console: ["error", { allow: ["debug"] }] */
8
+
7
9
  /**
8
10
  * A helper method to warn to the console with New Relic: decoration
9
11
  * @param {string} message The primary message to warn
@@ -27,18 +27,12 @@ exports.single = single;
27
27
  * @returns {function} A wrapping function that will ensure the provided function
28
28
  * is invoked only once within the given timeout.
29
29
  */
30
- function debounce(func) {
31
- var _this = this;
32
- let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
33
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
30
+ function debounce(func, timeout = 500, options = {}) {
34
31
  const leading = options?.leading || false;
35
32
  let timer;
36
- return function () {
37
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
38
- args[_key] = arguments[_key];
39
- }
33
+ return (...args) => {
40
34
  if (leading && timer === undefined) {
41
- func.apply(_this, args);
35
+ func.apply(this, args);
42
36
  timer = setTimeout(() => {
43
37
  timer = clearTimeout(timer);
44
38
  }, timeout);
@@ -46,7 +40,7 @@ function debounce(func) {
46
40
  if (!leading) {
47
41
  clearTimeout(timer);
48
42
  timer = setTimeout(() => {
49
- func.apply(_this, args);
43
+ func.apply(this, args);
50
44
  }, timeout);
51
45
  }
52
46
  };
@@ -61,15 +55,11 @@ function debounce(func) {
61
55
  * is invoked only once.
62
56
  */
63
57
  function single(func) {
64
- var _this2 = this;
65
58
  let called = false;
66
- return function () {
59
+ return (...args) => {
67
60
  if (!called) {
68
61
  called = true;
69
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
70
- args[_key2] = arguments[_key2];
71
- }
72
- func.apply(_this2, args);
62
+ func.apply(this, args);
73
63
  }
74
64
  };
75
65
  }
@@ -4,67 +4,111 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Obfuscator = void 0;
7
- exports.getRules = getRules;
8
- exports.validateRules = validateRules;
9
- var _config = require("../config/config");
10
- var _sharedContext = require("../context/shared-context");
7
+ var _init = require("../config/init");
11
8
  var _protocol = require("../url/protocol");
12
9
  var _console = require("./console");
13
- var fileProtocolRule = {
14
- regex: /^file:\/\/(.*)/,
15
- replacement: atob('ZmlsZTovL09CRlVTQ0FURUQ=')
16
- };
17
- class Obfuscator extends _sharedContext.SharedContext {
18
- shouldObfuscate() {
19
- return getRules(this.sharedContext.agentIdentifier).length > 0;
10
+ /**
11
+ * Represents an obfuscation rule that can be applied to harvested payloads
12
+ * @typedef {object} ObfuscationRule
13
+ * @property {string|RegExp} regex The regular expression to match against in the payload
14
+ * @property {string} [replacement] The string to replace the matched regex with
15
+ */
16
+
17
+ /**
18
+ * Represents an obfuscation rule validation state
19
+ * @typedef {object} ObfuscationRuleValidation
20
+ * @property {ObfuscationRule} rule The original rule validated
21
+ * @property {boolean} isValid Whether the rule is valid
22
+ * @property {object} errors Validation errors
23
+ * @property {boolean} errors.regexMissingDetected Whether the regex is missing
24
+ * @property {boolean} errors.invalidRegexDetected Whether the regex is invalid
25
+ * @property {boolean} errors.invalidReplacementDetected Whether the replacement is invalid
26
+ */
27
+
28
+ class Obfuscator {
29
+ /**
30
+ * @type {ObfuscationRuleValidation[]}
31
+ */
32
+ #ruleValidationCache;
33
+ constructor(agentIdentifier) {
34
+ this.#ruleValidationCache = Obfuscator.getRuleValidationCache(agentIdentifier);
35
+ Obfuscator.logObfuscationRuleErrors(this.#ruleValidationCache);
36
+ }
37
+ get ruleValidationCache() {
38
+ return this.#ruleValidationCache;
20
39
  }
21
40
 
22
- // applies all regex obfuscation rules to provided URL string and returns the result
23
- obfuscateString(string) {
24
- // if string is empty string, null or not a string, return unmodified
25
- if (!string || typeof string !== 'string') return string;
26
- var rules = getRules(this.sharedContext.agentIdentifier);
27
- var obfuscated = string;
41
+ /**
42
+ * Applies all valid obfuscation rules to the provided input string
43
+ * @param {string} input String to obfuscate
44
+ * @returns {string}
45
+ */
46
+ obfuscateString(input) {
47
+ // if input is not of type string or is an empty string, short-circuit
48
+ if (typeof input !== 'string' || input.trim().length === 0) return input;
49
+ return this.#ruleValidationCache.filter(ruleValidation => ruleValidation.isValid).reduce((input, ruleValidation) => {
50
+ const {
51
+ rule
52
+ } = ruleValidation;
53
+ return input.replace(rule.regex, rule.replacement || '*');
54
+ }, input);
55
+ }
28
56
 
29
- // apply every rule to URL string
30
- for (var i = 0; i < rules.length; i++) {
31
- var regex = rules[i].regex;
32
- var replacement = rules[i].replacement || '*';
33
- obfuscated = obfuscated.replace(regex, replacement);
57
+ /**
58
+ * Returns an array of obfuscation rules to be applied to harvested payloads
59
+ * @param {string} agentIdentifier The agent identifier to get rules for
60
+ * @returns {ObfuscationRuleValidation[]} The array of rules or validation states
61
+ */
62
+ static getRuleValidationCache(agentIdentifier) {
63
+ /**
64
+ * @type {ObfuscationRule[]}
65
+ */
66
+ let rules = (0, _init.getConfigurationValue)(agentIdentifier, 'obfuscate') || [];
67
+ if ((0, _protocol.isFileProtocol)()) {
68
+ rules.push({
69
+ regex: /^file:\/\/(.*)/,
70
+ replacement: atob('ZmlsZTovL09CRlVTQ0FURUQ=')
71
+ });
34
72
  }
35
- return obfuscated;
73
+ return rules.map(rule => Obfuscator.validateObfuscationRule(rule));
36
74
  }
37
- }
38
75
 
39
- // TO DO: this function should be inside the Obfuscator class since its context relates to agentID
40
- exports.Obfuscator = Obfuscator;
41
- function getRules(agentIdentifier) {
42
- var rules = [];
43
- var configRules = (0, _config.getConfigurationValue)(agentIdentifier, 'obfuscate') || [];
44
- rules = rules.concat(configRules);
45
- if ((0, _protocol.isFileProtocol)()) rules.push(fileProtocolRule);
46
- // could add additional runtime/environment-specific rules here
47
-
48
- return rules;
49
- }
76
+ /**
77
+ * Validates an obfuscation rule and provides errors if any are found.
78
+ * @param {ObfuscationRule} rule The rule to validate
79
+ * @returns {ObfuscationRuleValidation} The validation state of the rule
80
+ */
81
+ static validateObfuscationRule(rule) {
82
+ const regexMissingDetected = Boolean(rule.regex === undefined);
83
+ const invalidRegexDetected = Boolean(rule.regex !== undefined && typeof rule.regex !== 'string' && !(rule.regex instanceof RegExp));
84
+ const invalidReplacementDetected = Boolean(rule.replacement && typeof rule.replacement !== 'string');
85
+ return {
86
+ rule,
87
+ isValid: !regexMissingDetected && !invalidRegexDetected && !invalidReplacementDetected,
88
+ errors: {
89
+ regexMissingDetected,
90
+ invalidRegexDetected,
91
+ invalidReplacementDetected
92
+ }
93
+ };
94
+ }
50
95
 
51
- // takes array of rule objects, logs warning and returns false if any portion of rule is invalid
52
- function validateRules(rules) {
53
- var invalidReplacementDetected = false;
54
- var invalidRegexDetected = false;
55
- for (var i = 0; i < rules.length; i++) {
56
- if (!('regex' in rules[i])) {
57
- (0, _console.warn)(12);
58
- invalidRegexDetected = true;
59
- } else if (typeof rules[i].regex !== 'string' && !(rules[i].regex instanceof RegExp)) {
60
- (0, _console.warn)(13);
61
- invalidRegexDetected = true;
62
- }
63
- var replacement = rules[i].replacement;
64
- if (replacement && typeof replacement !== 'string') {
65
- (0, _console.warn)(14);
66
- invalidReplacementDetected = true;
96
+ /**
97
+ * Logs any obfuscation rule errors to the console. This is called when an obfuscator
98
+ * instance is created.
99
+ * @param {ObfuscationRuleValidation[]} ruleValidationCache The cache of rule validation states
100
+ */
101
+ static logObfuscationRuleErrors(ruleValidationCache) {
102
+ for (const ruleValidation of ruleValidationCache) {
103
+ const {
104
+ rule,
105
+ isValid,
106
+ errors
107
+ } = ruleValidation;
108
+ if (isValid) continue;
109
+ if (errors.regexMissingDetected) (0, _console.warn)(12, rule);else if (errors.invalidRegexDetected) (0, _console.warn)(13, rule);
110
+ if (errors.invalidReplacementDetected) (0, _console.warn)(14, rule);
67
111
  }
68
112
  }
69
- return !invalidReplacementDetected && !invalidRegexDetected;
70
- }
113
+ }
114
+ exports.Obfuscator = Obfuscator;
@@ -23,10 +23,9 @@ var _runtime = require("../constants/runtime");
23
23
  * @param {boolean} opts.isFinalHarvest Indicates if the data submission is due to
24
24
  * a final harvest within the agent.
25
25
  */
26
- function getSubmitMethod() {
27
- let {
28
- isFinalHarvest = false
29
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26
+ function getSubmitMethod({
27
+ isFinalHarvest = false
28
+ } = {}) {
30
29
  return isFinalHarvest && _runtime.isBrowserScope && _runtime.supportsSendBeacon
31
30
  // Use sendBeacon for final harvest
32
31
  ? beacon
@@ -44,17 +43,16 @@ function getSubmitMethod() {
44
43
  * @param {{key: string, value: string}[]} [args.headers] - The headers to attach.
45
44
  * @returns {XMLHttpRequest}
46
45
  */
47
- function xhr(_ref) {
48
- let {
49
- url,
50
- body = null,
51
- sync,
52
- method = 'POST',
53
- headers = [{
54
- key: 'content-type',
55
- value: 'text/plain'
56
- }]
57
- } = _ref;
46
+ function xhr({
47
+ url,
48
+ body = null,
49
+ sync,
50
+ method = 'POST',
51
+ headers = [{
52
+ key: 'content-type',
53
+ value: 'text/plain'
54
+ }]
55
+ }) {
58
56
  const request = new XMLHttpRequest();
59
57
  request.open(method, url, !sync);
60
58
  try {
@@ -77,11 +75,10 @@ function xhr(_ref) {
77
75
  * @param {string=} args.body - The Stringified body
78
76
  * @returns {boolean}
79
77
  */
80
- function beacon(_ref2) {
81
- let {
82
- url,
83
- body
84
- } = _ref2;
78
+ function beacon({
79
+ url,
80
+ body
81
+ }) {
85
82
  try {
86
83
  // Navigator has to be bound to ensure it does not error in some browsers
87
84
  // https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toTitleCase = toTitleCase;
7
+ function toTitleCase(str, regex = /\w*/g) {
8
+ return str.replace(regex, text => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase());
9
+ }
@@ -18,9 +18,7 @@ exports.applyFnToProps = applyFnToProps;
18
18
  * @param {Array<string>} [ignoreKeys=[]] - The keys of properties to ignore and not modify.
19
19
  * @returns {Object} - The object with function recursively applied.
20
20
  */
21
- function applyFnToProps(obj, fn) {
22
- let type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'string';
23
- let ignoreKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
21
+ function applyFnToProps(obj, fn, type = 'string', ignoreKeys = []) {
24
22
  if (!obj || typeof obj !== 'object') return obj;
25
23
  Object.keys(obj).forEach(property => {
26
24
  if (typeof obj[property] === 'object') {
@@ -10,12 +10,11 @@ var _vitalMetric = require("./vital-metric");
10
10
  var _runtime = require("../constants/runtime");
11
11
  const cumulativeLayoutShift = exports.cumulativeLayoutShift = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.CUMULATIVE_LAYOUT_SHIFT, x => x);
12
12
  if (_runtime.isBrowserScope) {
13
- (0, _attribution.onCLS)(_ref => {
14
- let {
15
- value,
16
- attribution,
17
- id
18
- } = _ref;
13
+ (0, _attribution.onCLS)(({
14
+ value,
15
+ attribution,
16
+ id
17
+ }) => {
19
18
  const attrs = {
20
19
  metricId: id,
21
20
  largestShiftTarget: attribution.largestShiftTarget,
@@ -32,11 +32,10 @@ if (_runtime.isBrowserScope) {
32
32
  // ignore
33
33
  }
34
34
  } else {
35
- (0, _attribution.onFCP)(_ref => {
36
- let {
37
- value,
38
- attribution
39
- } = _ref;
35
+ (0, _attribution.onFCP)(({
36
+ value,
37
+ attribution
38
+ }) => {
40
39
  if (_runtime.initiallyHidden || firstContentfulPaint.isValid) return;
41
40
  const attrs = {
42
41
  timeToFirstByte: attribution.timeToFirstByte,
@@ -10,11 +10,10 @@ var _constants = require("./constants");
10
10
  var _runtime = require("../constants/runtime");
11
11
  const firstInputDelay = exports.firstInputDelay = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.FIRST_INPUT_DELAY);
12
12
  if (_runtime.isBrowserScope) {
13
- (0, _attribution.onFID)(_ref => {
14
- let {
15
- value,
16
- attribution
17
- } = _ref;
13
+ (0, _attribution.onFID)(({
14
+ value,
15
+ attribution
16
+ }) => {
18
17
  if (_runtime.initiallyHidden || firstInputDelay.isValid) return;
19
18
  const attrs = {
20
19
  type: attribution.eventType,
@@ -11,12 +11,11 @@ var _runtime = require("../constants/runtime");
11
11
  const interactionToNextPaint = exports.interactionToNextPaint = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.INTERACTION_TO_NEXT_PAINT);
12
12
  if (_runtime.isBrowserScope) {
13
13
  /* Interaction-to-Next-Paint */
14
- (0, _attribution.onINP)(_ref => {
15
- let {
16
- value,
17
- attribution,
18
- id
19
- } = _ref;
14
+ (0, _attribution.onINP)(({
15
+ value,
16
+ attribution,
17
+ id
18
+ }) => {
20
19
  const attrs = {
21
20
  metricId: id,
22
21
  eventTarget: attribution.eventTarget,
@@ -11,11 +11,10 @@ var _runtime = require("../constants/runtime");
11
11
  var _cleanUrl = require("../url/clean-url");
12
12
  const largestContentfulPaint = exports.largestContentfulPaint = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.LARGEST_CONTENTFUL_PAINT);
13
13
  if (_runtime.isBrowserScope) {
14
- (0, _attribution.onLCP)(_ref => {
15
- let {
16
- value,
17
- attribution
18
- } = _ref;
14
+ (0, _attribution.onLCP)(({
15
+ value,
16
+ attribution
17
+ }) => {
19
18
  /* Largest Contentful Paint - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
20
19
  if (_runtime.initiallyHidden || largestContentfulPaint.isValid) return;
21
20
  let attrs;
@@ -18,11 +18,10 @@ const timeToFirstByte = exports.timeToFirstByte = new _vitalMetric.VitalMetric(_
18
18
  * - cross-origin iframes specifically in firefox and safari
19
19
  */
20
20
  if (_runtime.isBrowserScope && typeof PerformanceNavigationTiming !== 'undefined' && !_runtime.isiOS && window === window.parent) {
21
- (0, _attribution.onTTFB)(_ref => {
22
- let {
23
- value,
24
- attribution
25
- } = _ref;
21
+ (0, _attribution.onTTFB)(({
22
+ value,
23
+ attribution
24
+ }) => {
26
25
  if (timeToFirstByte.isValid) return;
27
26
  timeToFirstByte.update({
28
27
  value,
@@ -5,18 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.VitalMetric = void 0;
7
7
  class VitalMetric {
8
- #subscribers = (() => new Set())();
8
+ #subscribers = new Set();
9
9
  history = [];
10
10
  constructor(name, roundingMethod) {
11
11
  this.name = name;
12
12
  this.attrs = {};
13
13
  this.roundingMethod = typeof roundingMethod === 'function' ? roundingMethod : Math.floor;
14
14
  }
15
- update(_ref) {
16
- let {
17
- value,
18
- attrs = {}
19
- } = _ref;
15
+ update({
16
+ value,
17
+ attrs = {}
18
+ }) {
20
19
  if (value === undefined || value === null || value < 0) return;
21
20
  const state = {
22
21
  value: this.roundingMethod(value),
@@ -42,8 +41,7 @@ class VitalMetric {
42
41
  get isValid() {
43
42
  return this.current.value >= 0;
44
43
  }
45
- subscribe(callback) {
46
- let buffered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
44
+ subscribe(callback, buffered = true) {
47
45
  if (typeof callback !== 'function') return;
48
46
  this.#subscribers.add(callback);
49
47
  // emit full history on subscription ("buffered" behavior)
@@ -66,7 +66,8 @@ function gosNREUMOriginals() {
66
66
  PR: _runtime.globalScope.Promise,
67
67
  MO: _runtime.globalScope.MutationObserver,
68
68
  // this'll be undefined if not in a web window
69
- FETCH: _runtime.globalScope.fetch
69
+ FETCH: _runtime.globalScope.fetch,
70
+ WS: _runtime.globalScope.WebSocket
70
71
  };
71
72
  }
72
73
  return nr;
@@ -15,10 +15,7 @@ var _eventListenerOpts = require("../event-listener/event-listener-opts");
15
15
  * @param {boolean} [toHiddenOnly=false] - only execute the 'cb' when the vis is changing to the hidden state; no arg is passed to 'cb' if used
16
16
  * @returns void
17
17
  */
18
- function subscribeToVisibilityChange(cb) {
19
- let toHiddenOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
20
- let capture = arguments.length > 2 ? arguments[2] : undefined;
21
- let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
18
+ function subscribeToVisibilityChange(cb, toHiddenOnly = false, capture, abortSignal) {
22
19
  (0, _eventListenerOpts.documentAddEventListener)('visibilitychange', handleVisibilityChange, capture, abortSignal);
23
20
  function handleVisibilityChange() {
24
21
  if (toHiddenOnly) {
@@ -83,14 +83,11 @@ function wrapEvents(sharedEE) {
83
83
  * @param {Function} cb - the function to run on the ancestral object once found, accepts an object as a arg
84
84
  * @param {Array} rest - [optional] any additional arguments to pass to the cb
85
85
  */
86
- function findEventListenerProtoAndCb(object, cb) {
86
+ function findEventListenerProtoAndCb(object, cb, ...rest) {
87
87
  let step = object;
88
88
  while (typeof step === 'object' && !Object.prototype.hasOwnProperty.call(step, ADD_EVENT_LISTENER)) {
89
89
  step = Object.getPrototypeOf(step);
90
90
  }
91
- for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
92
- rest[_key - 2] = arguments[_key];
93
- }
94
91
  if (step) cb(step, ...rest);
95
92
  }
96
93
 
@@ -111,13 +111,10 @@ function wrapPromise(sharedEE) {
111
111
 
112
112
  // Note that this wrapping affects the same originals.PR (prototype) object.
113
113
  const prevPromiseOrigThen = prevPromiseObj.prototype.then;
114
- prevPromiseObj.prototype.then = function wrappedThen() {
114
+ prevPromiseObj.prototype.then = function wrappedThen(...args) {
115
115
  var originalThis = this;
116
116
  var ctx = getContext(originalThis);
117
117
  ctx.promise = originalThis;
118
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
119
- args[_key] = arguments[_key];
120
- }
121
118
  args[0] = promiseWrapper(args[0], 'cb-', ctx, null, false);
122
119
  args[1] = promiseWrapper(args[1], 'cb-', ctx, null, false);
123
120
  const origFnCallWithThis = prevPromiseOrigThen.apply(this, args);
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WEBSOCKET_TAG = exports.ADD_EVENT_LISTENER_TAG = void 0;
7
+ exports.wrapWebSocket = wrapWebSocket;
8
+ var _runtime = require("../constants/runtime");
9
+ var _now = require("../timing/now");
10
+ var _load = require("../window/load");
11
+ var _uniqueId = require("../ids/unique-id");
12
+ var _nreum = require("../window/nreum");
13
+ const WEBSOCKET_TAG = exports.WEBSOCKET_TAG = 'websocket-';
14
+ const ADD_EVENT_LISTENER_TAG = exports.ADD_EVENT_LISTENER_TAG = 'addEventListener';
15
+ const wrapped = {};
16
+ function wrapWebSocket(sharedEE) {
17
+ if (wrapped[sharedEE.debugId]++) return sharedEE;
18
+ const originals = (0, _nreum.gosNREUMOriginals)().o;
19
+ if (!originals.WS) return sharedEE;
20
+ function reporter(socketId) {
21
+ const createdAt = (0, _now.now)();
22
+ return function (message, ...data) {
23
+ const timestamp = data[0]?.timeStamp || (0, _now.now)();
24
+ const isLoaded = (0, _load.checkState)();
25
+ sharedEE.emit(WEBSOCKET_TAG + message, [timestamp, timestamp - createdAt, isLoaded, socketId, ...data]);
26
+ };
27
+ }
28
+ Object.defineProperty(WrappedWebSocket, 'name', {
29
+ value: 'WebSocket'
30
+ });
31
+ function WrappedWebSocket() {
32
+ const ws = new originals.WS(...arguments);
33
+ const socketId = (0, _uniqueId.generateRandomHexString)(6);
34
+ const report = reporter(socketId);
35
+ report('new');
36
+ const events = ['message', 'error', 'open', 'close'];
37
+ /** add event listeners */
38
+ events.forEach(evt => {
39
+ ws.addEventListener(evt, function (e) {
40
+ report(ADD_EVENT_LISTENER_TAG, {
41
+ eventType: evt,
42
+ event: e
43
+ });
44
+ });
45
+ })
46
+
47
+ /** could also observe the on-events for runtime processing, but not implemented yet */
48
+
49
+ /** observe the static method send, but noteably not close, as that is currently observed with the event listener */;
50
+ ['send'].forEach(wrapStaticProperty);
51
+ function wrapStaticProperty(prop) {
52
+ const originalProp = ws[prop];
53
+ if (originalProp) {
54
+ Object.defineProperty(proxiedProp, 'name', {
55
+ value: prop
56
+ });
57
+ function proxiedProp() {
58
+ report(prop, ...arguments);
59
+ try {
60
+ return originalProp.apply(this, arguments);
61
+ } catch (err) {
62
+ report(prop + '-err', ...arguments);
63
+ // rethrow error so we don't effect execution by observing.
64
+ throw err;
65
+ }
66
+ }
67
+ ws[prop] = proxiedProp;
68
+ }
69
+ }
70
+ return ws;
71
+ }
72
+ _runtime.globalScope.WebSocket = WrappedWebSocket;
73
+ return sharedEE;
74
+ }
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _belSerializer = require("../../../common/serialize/bel-serializer");
8
- var _config = require("../../../common/config/config");
8
+ var _info = require("../../../common/config/info");
9
+ var _agentConstants = require("../../../common/constants/agent-constants");
9
10
  class Chunk {
10
11
  constructor(events, aggregateInstance) {
11
12
  this.addString = (0, _belSerializer.getAddStringContext)(aggregateInstance.agentIdentifier); // pass agentIdentifier here
@@ -28,7 +29,7 @@ class Chunk {
28
29
  let insert = '2,';
29
30
 
30
31
  // Since configuration objects (like info) are created new each time they are set, we have to grab the current pointer to the attr object here.
31
- const jsAttributes = (0, _config.getInfo)(aggregateInstance.agentIdentifier).jsAttributes;
32
+ const jsAttributes = (0, _info.getInfo)(aggregateInstance.agentIdentifier).jsAttributes;
32
33
 
33
34
  // add custom attributes
34
35
  // gql decorators are added as custom attributes to alleviate need for new BEL schema
@@ -44,7 +45,7 @@ class Chunk {
44
45
  if (i + 1 < events.length) insert += ';';
45
46
  this.payload += insert;
46
47
  }
47
- this.tooBig = this.payload.length * 2 > aggregateInstance.MAX_PAYLOAD_SIZE;
48
+ this.tooBig = this.payload.length * 2 > _agentConstants.MAX_PAYLOAD_SIZE;
48
49
  }
49
50
  }
50
51
  exports.default = Chunk;
@@ -19,11 +19,10 @@ var _typeCheck = require("../../../common/util/type-check");
19
19
  * @param {string} query Ajax request query param string
20
20
  * @returns {GQLMetadata | undefined}
21
21
  */
22
- function parseGQL() {
23
- let {
24
- body,
25
- query
26
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
22
+ function parseGQL({
23
+ body,
24
+ query
25
+ } = {}) {
27
26
  if (!body && !query) return;
28
27
  try {
29
28
  const gqlBody = parseBatchGQL(parseGQLContents(body));