@newrelic/browser-agent 0.1.230 → 1.232.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/README.md +27 -3
  2. package/dist/cjs/common/browser-version/ios-version.js +4 -3
  3. package/dist/cjs/common/config/state/configurable.js +27 -21
  4. package/dist/cjs/common/config/state/info.js +1 -1
  5. package/dist/cjs/common/config/state/init.js +9 -1
  6. package/dist/cjs/common/config/state/loader-config.js +1 -1
  7. package/dist/cjs/common/config/state/runtime.js +26 -28
  8. package/dist/cjs/common/constants/env.cdn.js +29 -0
  9. package/dist/cjs/common/constants/env.js +32 -0
  10. package/dist/cjs/common/constants/env.npm.js +30 -0
  11. package/dist/cjs/common/context/shared-context.js +2 -1
  12. package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
  13. package/dist/cjs/common/event-emitter/handle.test.js +58 -0
  14. package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
  15. package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
  16. package/dist/cjs/common/harvest/harvest-scheduler.js +14 -11
  17. package/dist/cjs/common/harvest/harvest.js +5 -3
  18. package/dist/cjs/common/ids/id.js +14 -6
  19. package/dist/cjs/common/ids/id.test.js +85 -0
  20. package/dist/cjs/common/ids/unique-id.js +75 -51
  21. package/dist/cjs/common/ids/unique-id.test.js +49 -0
  22. package/dist/cjs/common/session/constants.js +12 -0
  23. package/dist/cjs/common/session/session-entity.js +278 -0
  24. package/dist/cjs/common/session/session-entity.test.js +436 -0
  25. package/dist/cjs/common/storage/first-party-cookies.js +35 -0
  26. package/dist/cjs/common/storage/local-memory.js +35 -0
  27. package/dist/cjs/common/storage/local-memory.test.js +20 -0
  28. package/dist/cjs/common/storage/local-storage.js +33 -0
  29. package/dist/cjs/common/storage/local-storage.test.js +14 -0
  30. package/dist/cjs/common/timer/interaction-timer.js +78 -0
  31. package/dist/cjs/common/timer/interaction-timer.test.js +216 -0
  32. package/dist/cjs/common/timer/timer.js +32 -0
  33. package/dist/cjs/common/timer/timer.test.js +105 -0
  34. package/dist/cjs/common/timing/nav-timing.js +51 -30
  35. package/dist/cjs/common/timing/nav-timing.test.js +192 -0
  36. package/dist/cjs/common/unload/eol.js +2 -2
  37. package/dist/cjs/common/url/clean-url.test.js +9 -0
  38. package/dist/cjs/common/url/encode.test.js +74 -0
  39. package/dist/cjs/common/url/location.js +4 -0
  40. package/dist/cjs/common/url/location.test.js +13 -0
  41. package/dist/cjs/common/url/parse-url.test.js +111 -0
  42. package/dist/cjs/common/url/protocol.js +2 -12
  43. package/dist/cjs/common/url/protocol.test.js +16 -0
  44. package/dist/cjs/common/util/console.js +1 -1
  45. package/dist/cjs/common/util/data-size.js +6 -0
  46. package/dist/cjs/common/util/data-size.test.js +47 -0
  47. package/dist/cjs/common/util/invoke.js +73 -0
  48. package/dist/cjs/common/util/invoke.test.js +49 -0
  49. package/dist/cjs/common/util/map-own.test.js +3 -3
  50. package/dist/cjs/common/util/obfuscate.js +1 -5
  51. package/dist/cjs/common/window/page-visibility.js +5 -2
  52. package/dist/cjs/common/wrap/index.js +0 -7
  53. package/dist/cjs/common/wrap/wrap-events.js +6 -9
  54. package/dist/cjs/common/wrap/wrap-fetch.js +6 -6
  55. package/dist/cjs/common/wrap/wrap-history.js +7 -6
  56. package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
  57. package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
  58. package/dist/cjs/common/wrap/wrap-promise.js +7 -6
  59. package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
  60. package/dist/cjs/common/wrap/wrap-raf.js +6 -6
  61. package/dist/cjs/common/wrap/wrap-timer.js +7 -7
  62. package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
  63. package/dist/cjs/features/ajax/aggregate/index.js +3 -3
  64. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  65. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
  66. package/dist/cjs/features/jserrors/aggregate/index.js +6 -6
  67. package/dist/cjs/features/jserrors/instrument/index.js +2 -2
  68. package/dist/cjs/features/metrics/aggregate/index.js +19 -9
  69. package/dist/cjs/features/metrics/instrument/index.js +0 -25
  70. package/dist/cjs/features/metrics/instrument/workers-helper.js +5 -5
  71. package/dist/cjs/features/page_action/aggregate/index.js +3 -3
  72. package/dist/cjs/features/page_view_event/aggregate/index.js +23 -9
  73. package/dist/cjs/features/page_view_timing/aggregate/index.js +40 -30
  74. package/dist/cjs/features/session_trace/aggregate/index.js +18 -15
  75. package/dist/cjs/features/spa/aggregate/index.js +6 -5
  76. package/dist/cjs/features/utils/agent-session.js +73 -0
  77. package/dist/cjs/features/utils/feature-base.js +1 -1
  78. package/dist/cjs/features/utils/instrument-base.js +12 -3
  79. package/dist/cjs/features/utils/lazy-loader.js +2 -2
  80. package/dist/cjs/loaders/agent.js +2 -2
  81. package/dist/cjs/loaders/api/api.js +9 -9
  82. package/dist/cjs/loaders/api/apiAsync.js +3 -2
  83. package/dist/cjs/loaders/configure/configure.js +0 -6
  84. package/dist/cjs/loaders/features/enabled-features.js +1 -1
  85. package/dist/cjs/loaders/micro-agent.js +2 -1
  86. package/dist/esm/common/browser-version/ios-version.js +4 -3
  87. package/dist/esm/common/config/state/configurable.js +26 -20
  88. package/dist/esm/common/config/state/info.js +1 -1
  89. package/dist/esm/common/config/state/init.js +9 -1
  90. package/dist/esm/common/config/state/loader-config.js +1 -1
  91. package/dist/esm/common/config/state/runtime.js +26 -28
  92. package/dist/esm/common/constants/env.cdn.js +20 -0
  93. package/dist/esm/common/constants/env.js +23 -0
  94. package/dist/esm/common/constants/env.npm.js +21 -0
  95. package/dist/esm/common/context/shared-context.js +2 -1
  96. package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
  97. package/dist/esm/common/event-emitter/handle.test.js +54 -0
  98. package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
  99. package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
  100. package/dist/esm/common/harvest/harvest-scheduler.js +14 -11
  101. package/dist/esm/common/harvest/harvest.js +4 -2
  102. package/dist/esm/common/ids/id.js +16 -6
  103. package/dist/esm/common/ids/id.test.js +81 -0
  104. package/dist/esm/common/ids/unique-id.js +75 -51
  105. package/dist/esm/common/ids/unique-id.test.js +44 -0
  106. package/dist/esm/common/session/constants.js +3 -0
  107. package/dist/esm/common/session/session-entity.js +271 -0
  108. package/dist/esm/common/session/session-entity.test.js +434 -0
  109. package/dist/esm/common/storage/first-party-cookies.js +28 -0
  110. package/dist/esm/common/storage/local-memory.js +28 -0
  111. package/dist/esm/common/storage/local-memory.test.js +18 -0
  112. package/dist/esm/common/storage/local-storage.js +26 -0
  113. package/dist/esm/common/storage/local-storage.test.js +12 -0
  114. package/dist/esm/common/timer/interaction-timer.js +71 -0
  115. package/dist/esm/common/timer/interaction-timer.test.js +214 -0
  116. package/dist/esm/common/timer/timer.js +25 -0
  117. package/dist/esm/common/timer/timer.test.js +103 -0
  118. package/dist/esm/common/timing/nav-timing.js +51 -29
  119. package/dist/esm/common/timing/nav-timing.test.js +190 -0
  120. package/dist/esm/common/unload/eol.js +1 -1
  121. package/dist/esm/common/url/clean-url.test.js +7 -0
  122. package/dist/esm/common/url/encode.test.js +70 -0
  123. package/dist/esm/common/url/location.js +4 -0
  124. package/dist/esm/common/url/location.test.js +11 -0
  125. package/dist/esm/common/url/parse-url.test.js +107 -0
  126. package/dist/esm/common/url/protocol.js +3 -12
  127. package/dist/esm/common/url/protocol.test.js +14 -0
  128. package/dist/esm/common/util/console.js +1 -1
  129. package/dist/esm/common/util/data-size.js +7 -0
  130. package/dist/esm/common/util/data-size.test.js +45 -0
  131. package/dist/esm/common/util/invoke.js +66 -0
  132. package/dist/esm/common/util/invoke.test.js +47 -0
  133. package/dist/esm/common/util/map-own.test.js +3 -3
  134. package/dist/esm/common/util/obfuscate.js +2 -6
  135. package/dist/esm/common/window/page-visibility.js +5 -2
  136. package/dist/esm/common/wrap/index.js +1 -2
  137. package/dist/esm/common/wrap/wrap-events.js +6 -9
  138. package/dist/esm/common/wrap/wrap-fetch.js +6 -6
  139. package/dist/esm/common/wrap/wrap-history.js +7 -6
  140. package/dist/esm/common/wrap/wrap-jsonp.js +7 -6
  141. package/dist/esm/common/wrap/wrap-mutation.js +7 -6
  142. package/dist/esm/common/wrap/wrap-promise.js +7 -6
  143. package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
  144. package/dist/esm/common/wrap/wrap-raf.js +6 -6
  145. package/dist/esm/common/wrap/wrap-timer.js +7 -7
  146. package/dist/esm/common/wrap/wrap-xhr.js +5 -6
  147. package/dist/esm/features/ajax/aggregate/index.js +3 -3
  148. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  149. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
  150. package/dist/esm/features/jserrors/aggregate/index.js +6 -6
  151. package/dist/esm/features/jserrors/instrument/index.js +2 -2
  152. package/dist/esm/features/metrics/aggregate/index.js +21 -11
  153. package/dist/esm/features/metrics/instrument/index.js +0 -25
  154. package/dist/esm/features/metrics/instrument/workers-helper.js +5 -5
  155. package/dist/esm/features/page_action/aggregate/index.js +3 -3
  156. package/dist/esm/features/page_view_event/aggregate/index.js +23 -9
  157. package/dist/esm/features/page_view_timing/aggregate/index.js +40 -30
  158. package/dist/esm/features/session_trace/aggregate/index.js +18 -15
  159. package/dist/esm/features/spa/aggregate/index.js +6 -5
  160. package/dist/esm/features/utils/agent-session.js +67 -0
  161. package/dist/esm/features/utils/feature-base.js +1 -1
  162. package/dist/esm/features/utils/instrument-base.js +7 -2
  163. package/dist/esm/features/utils/lazy-loader.js +2 -2
  164. package/dist/esm/loaders/agent.js +2 -2
  165. package/dist/esm/loaders/api/api.js +6 -9
  166. package/dist/esm/loaders/api/apiAsync.js +2 -1
  167. package/dist/esm/loaders/configure/configure.js +2 -8
  168. package/dist/esm/loaders/features/enabled-features.js +1 -1
  169. package/dist/types/common/config/state/configurable.d.ts.map +1 -1
  170. package/dist/types/common/config/state/init.d.ts.map +1 -1
  171. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  172. package/dist/types/common/constants/env.cdn.d.ts +18 -0
  173. package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
  174. package/dist/types/common/constants/env.d.ts +13 -0
  175. package/dist/types/common/constants/env.d.ts.map +1 -0
  176. package/dist/types/common/constants/env.npm.d.ts +19 -0
  177. package/dist/types/common/constants/env.npm.d.ts.map +1 -0
  178. package/dist/types/common/context/shared-context.d.ts.map +1 -1
  179. package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
  180. package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
  181. package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -0
  182. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  183. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  184. package/dist/types/common/ids/id.d.ts +11 -1
  185. package/dist/types/common/ids/id.d.ts.map +1 -1
  186. package/dist/types/common/ids/unique-id.d.ts +24 -1
  187. package/dist/types/common/ids/unique-id.d.ts.map +1 -1
  188. package/dist/types/common/session/constants.d.ts +4 -0
  189. package/dist/types/common/session/constants.d.ts.map +1 -0
  190. package/dist/types/common/session/session-entity.d.ts +72 -0
  191. package/dist/types/common/session/session-entity.d.ts.map +1 -0
  192. package/dist/types/common/storage/first-party-cookies.d.ts +8 -0
  193. package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -0
  194. package/dist/types/common/storage/local-memory.d.ts +8 -0
  195. package/dist/types/common/storage/local-memory.d.ts.map +1 -0
  196. package/dist/types/common/storage/local-storage.d.ts +6 -0
  197. package/dist/types/common/storage/local-storage.d.ts.map +1 -0
  198. package/dist/types/common/timer/interaction-timer.d.ts +11 -0
  199. package/dist/types/common/timer/interaction-timer.d.ts.map +1 -0
  200. package/dist/types/common/timer/timer.d.ts +12 -0
  201. package/dist/types/common/timer/timer.d.ts.map +1 -0
  202. package/dist/types/common/timing/nav-timing.d.ts +1 -2
  203. package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
  204. package/dist/types/common/unload/eol.d.ts.map +1 -1
  205. package/dist/types/common/url/location.d.ts +4 -0
  206. package/dist/types/common/url/location.d.ts.map +1 -1
  207. package/dist/types/common/url/parse-url.d.ts.map +1 -1
  208. package/dist/types/common/url/protocol.d.ts +1 -6
  209. package/dist/types/common/url/protocol.d.ts.map +1 -1
  210. package/dist/types/common/util/data-size.d.ts +7 -1
  211. package/dist/types/common/util/data-size.d.ts.map +1 -1
  212. package/dist/types/common/util/global-scope.d.ts.map +1 -1
  213. package/dist/types/common/util/invoke.d.ts +35 -0
  214. package/dist/types/common/util/invoke.d.ts.map +1 -0
  215. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  216. package/dist/types/common/window/page-visibility.d.ts +1 -1
  217. package/dist/types/common/window/page-visibility.d.ts.map +1 -1
  218. package/dist/types/common/wrap/index.d.ts +1 -2
  219. package/dist/types/common/wrap/index.d.ts.map +1 -1
  220. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  221. package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
  222. package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
  223. package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
  224. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  225. package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -1
  226. package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -1
  227. package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
  228. package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
  229. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  230. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
  231. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  232. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  233. package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
  234. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  235. package/dist/types/features/metrics/instrument/index.d.ts +0 -1
  236. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  237. package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -1
  238. package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
  239. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  240. package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
  241. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  242. package/dist/types/features/page_view_timing/aggregate/index.d.ts +3 -4
  243. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  244. package/dist/types/features/session_trace/aggregate/index.d.ts +3 -3
  245. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  246. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  247. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  248. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  249. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  250. package/dist/types/features/utils/agent-session.d.ts +2 -0
  251. package/dist/types/features/utils/agent-session.d.ts.map +1 -0
  252. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  253. package/dist/types/features/utils/lazy-loader.d.ts +2 -2
  254. package/dist/types/features/utils/lazy-loader.d.ts.map +1 -1
  255. package/dist/types/loaders/api/api.d.ts.map +1 -1
  256. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
  257. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  258. package/package.json +12 -32
  259. package/src/common/browser-version/ios-version.js +4 -3
  260. package/src/common/config/state/configurable.js +26 -19
  261. package/src/common/config/state/init.js +7 -0
  262. package/src/common/config/state/runtime.js +7 -10
  263. package/src/common/constants/env.cdn.js +20 -0
  264. package/src/common/constants/env.js +23 -0
  265. package/src/common/constants/env.npm.js +21 -0
  266. package/src/common/context/shared-context.js +2 -1
  267. package/src/common/event-emitter/contextual-ee.test.js +310 -0
  268. package/src/common/event-emitter/handle.test.js +56 -0
  269. package/src/common/event-emitter/register-handler.test.js +61 -0
  270. package/src/common/event-listener/event-listener-opts.js +4 -4
  271. package/src/common/harvest/harvest-scheduler.js +12 -8
  272. package/src/common/harvest/harvest.js +5 -3
  273. package/src/common/ids/id.js +15 -6
  274. package/src/common/ids/id.test.js +92 -0
  275. package/src/common/ids/unique-id.js +77 -54
  276. package/src/common/ids/unique-id.test.js +58 -0
  277. package/src/common/session/constants.js +3 -0
  278. package/src/common/session/session-entity.js +271 -0
  279. package/src/common/session/session-entity.test.js +317 -0
  280. package/src/common/storage/first-party-cookies.js +31 -0
  281. package/src/common/storage/local-memory.js +30 -0
  282. package/src/common/storage/local-memory.test.js +19 -0
  283. package/src/common/storage/local-storage.js +28 -0
  284. package/src/common/storage/local-storage.test.js +17 -0
  285. package/src/common/timer/interaction-timer.js +75 -0
  286. package/src/common/timer/interaction-timer.test.js +167 -0
  287. package/src/common/timer/timer.js +31 -0
  288. package/src/common/timer/timer.test.js +100 -0
  289. package/src/common/timing/nav-timing.js +50 -30
  290. package/src/common/timing/nav-timing.test.js +161 -0
  291. package/src/common/unload/eol.js +2 -3
  292. package/src/common/url/clean-url.test.js +25 -0
  293. package/src/common/url/encode.test.js +80 -0
  294. package/src/common/url/location.js +4 -0
  295. package/src/common/url/location.test.js +15 -0
  296. package/src/common/url/parse-url.js +1 -2
  297. package/src/common/url/parse-url.test.js +110 -0
  298. package/src/common/url/protocol.js +3 -13
  299. package/src/common/url/protocol.test.js +18 -0
  300. package/src/common/util/data-size.js +6 -0
  301. package/src/common/util/data-size.test.js +50 -0
  302. package/src/common/util/global-scope.js +1 -2
  303. package/src/common/util/invoke.js +55 -0
  304. package/src/common/util/invoke.test.js +65 -0
  305. package/src/common/util/obfuscate.js +2 -6
  306. package/src/common/window/page-visibility.js +3 -3
  307. package/src/common/wrap/index.js +1 -2
  308. package/src/common/wrap/wrap-events.js +5 -5
  309. package/src/common/wrap/wrap-fetch.js +4 -3
  310. package/src/common/wrap/wrap-history.js +6 -3
  311. package/src/common/wrap/wrap-jsonp.js +5 -3
  312. package/src/common/wrap/wrap-mutation.js +6 -3
  313. package/src/common/wrap/wrap-promise.js +7 -6
  314. package/src/common/wrap/wrap-promise.test.js +140 -0
  315. package/src/common/wrap/wrap-raf.js +5 -3
  316. package/src/common/wrap/wrap-timer.js +6 -4
  317. package/src/common/wrap/wrap-xhr.js +4 -3
  318. package/src/features/ajax/aggregate/index.js +2 -2
  319. package/src/features/ajax/instrument/index.js +1 -1
  320. package/src/features/jserrors/aggregate/index.js +3 -3
  321. package/src/features/jserrors/instrument/index.js +4 -2
  322. package/src/features/metrics/aggregate/index.js +21 -7
  323. package/src/features/metrics/instrument/index.js +0 -30
  324. package/src/features/metrics/instrument/workers-helper.js +9 -6
  325. package/src/features/page_action/aggregate/index.js +2 -2
  326. package/src/features/page_view_event/aggregate/index.js +21 -9
  327. package/src/features/page_view_timing/aggregate/index.js +40 -29
  328. package/src/features/page_view_timing/long-tasks.js +10 -10
  329. package/src/features/session_trace/aggregate/index.js +17 -14
  330. package/src/features/session_trace/instrument/index.js +3 -2
  331. package/src/features/spa/aggregate/index.js +5 -5
  332. package/src/features/spa/instrument/index.js +4 -2
  333. package/src/features/utils/agent-session.js +68 -0
  334. package/src/features/utils/feature-base.js +1 -1
  335. package/src/features/utils/instrument-base.js +5 -2
  336. package/src/features/utils/lazy-loader.js +1 -1
  337. package/src/loaders/agent.js +1 -1
  338. package/src/loaders/api/api.js +3 -6
  339. package/src/loaders/api/apiAsync.js +2 -1
  340. package/src/loaders/configure/configure.js +2 -7
  341. package/dist/cjs/common/constants/environment-variables.js +0 -20
  342. package/dist/cjs/common/util/single.js +0 -23
  343. package/dist/cjs/common/window/session-storage.js +0 -87
  344. package/dist/cjs/common/wrap/wrap-console.js +0 -54
  345. package/dist/cjs/features/utils/aggregate-base.js +0 -13
  346. package/dist/esm/common/constants/environment-variables.js +0 -11
  347. package/dist/esm/common/util/single.js +0 -16
  348. package/dist/esm/common/window/session-storage.js +0 -77
  349. package/dist/esm/common/wrap/wrap-console.js +0 -46
  350. package/dist/esm/features/utils/aggregate-base.js +0 -6
  351. package/dist/types/common/constants/environment-variables.d.ts +0 -4
  352. package/dist/types/common/constants/environment-variables.d.ts.map +0 -1
  353. package/dist/types/common/util/single.d.ts +0 -2
  354. package/dist/types/common/util/single.d.ts.map +0 -1
  355. package/dist/types/common/window/session-storage.d.ts +0 -18
  356. package/dist/types/common/window/session-storage.d.ts.map +0 -1
  357. package/dist/types/common/wrap/wrap-console.d.ts +0 -16
  358. package/dist/types/common/wrap/wrap-console.d.ts.map +0 -1
  359. package/dist/types/features/utils/aggregate-base.d.ts +0 -4
  360. package/dist/types/features/utils/aggregate-base.d.ts.map +0 -1
  361. package/src/common/constants/environment-variables.js +0 -11
  362. package/src/common/util/single.js +0 -18
  363. package/src/common/window/session-storage.js +0 -75
  364. package/src/common/wrap/wrap-console.js +0 -47
  365. package/src/features/utils/aggregate-base.js +0 -7
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ var _navTiming = require("./nav-timing");
4
+ const offset = 123;
5
+ const testValues = {
6
+ unloadEventStart: 1,
7
+ redirectStart: 2,
8
+ unloadEventEnd: 3,
9
+ redirectEnd: 4,
10
+ fetchStart: 5,
11
+ domainLookupStart: 6,
12
+ domainLookupEnd: 7,
13
+ connectStart: 8,
14
+ secureConnectionStart: 9,
15
+ connectEnd: 10,
16
+ requestStart: 11,
17
+ responseStart: 12,
18
+ responseEnd: 13,
19
+ domLoading: 14,
20
+ domInteractive: 15,
21
+ domContentLoadedEventStart: 16,
22
+ domContentLoadedEventEnd: 17,
23
+ domComplete: 18,
24
+ loadEventStart: 19,
25
+ loadEventEnd: 20,
26
+ type: 'reload',
27
+ redirectCount: 22
28
+ };
29
+ const legacyTestValues = {
30
+ unloadEventStart: offset + 1,
31
+ redirectStart: offset + 2,
32
+ unloadEventEnd: offset + 3,
33
+ redirectEnd: offset + 4,
34
+ fetchStart: offset + 5,
35
+ domainLookupStart: offset + 6,
36
+ domainLookupEnd: offset + 7,
37
+ connectStart: offset + 8,
38
+ secureConnectionStart: offset + 9,
39
+ connectEnd: offset + 10,
40
+ requestStart: offset + 11,
41
+ responseStart: offset + 12,
42
+ responseEnd: offset + 13,
43
+ domLoading: offset + 14,
44
+ domInteractive: offset + 15,
45
+ domContentLoadedEventStart: offset + 16,
46
+ domContentLoadedEventEnd: offset + 17,
47
+ domComplete: offset + 18,
48
+ loadEventStart: offset + 19,
49
+ loadEventEnd: offset + 20,
50
+ type: 'reload',
51
+ redirectCount: offset + 22
52
+ };
53
+ const expectedPT = {
54
+ of: offset,
55
+ n: 0,
56
+ u: 1,
57
+ r: 2,
58
+ ue: 3,
59
+ re: 4,
60
+ f: 5,
61
+ dn: 6,
62
+ dne: 7,
63
+ c: 8,
64
+ s: 9,
65
+ ce: 10,
66
+ rq: 11,
67
+ rp: 12,
68
+ rpe: 13,
69
+ dl: 14,
70
+ di: 15,
71
+ ds: 16,
72
+ de: 17,
73
+ dc: 18,
74
+ l: 19,
75
+ le: 20
76
+ };
77
+ const expectedPN = {
78
+ ty: 1,
79
+ rc: 22
80
+ };
81
+ describe('addPT()', () => {
82
+ test('an output object is populated with valid values', () => {
83
+ const output = (0, _navTiming.addPT)(offset, testValues, {});
84
+ expect(output).toEqual(expectedPT);
85
+ });
86
+ test('an object with invalid values is handled', () => {
87
+ const output = (0, _navTiming.addPT)(offset, {
88
+ ...testValues,
89
+ invalidValue: 'test'
90
+ }, {});
91
+ expect(output).toEqual(expectedPT);
92
+ const output2 = (0, _navTiming.addPT)(offset, {
93
+ ...testValues,
94
+ loadEventEnd: -1
95
+ }, {});
96
+ let expected = {
97
+ ...expectedPT
98
+ };
99
+ delete expected.le;
100
+ expect(output2).toEqual(expected);
101
+ const output3 = (0, _navTiming.addPT)(offset, {
102
+ ...testValues,
103
+ loadEventEnd: 'test'
104
+ }, {});
105
+ expected = {
106
+ ...expectedPT
107
+ };
108
+ delete expected.le;
109
+ expect(output3).toEqual(expected);
110
+ const output4 = (0, _navTiming.addPT)(offset, {
111
+ ...testValues,
112
+ loadEventEnd: null
113
+ }, {});
114
+ expected = {
115
+ ...expectedPT
116
+ };
117
+ delete expected.le;
118
+ expect(output4).toEqual(expected);
119
+ const legacyoutput = (0, _navTiming.addPT)(offset, {
120
+ ...legacyTestValues,
121
+ invalidValue: 'test'
122
+ }, {}, true);
123
+ expect(legacyoutput).toEqual(expectedPT);
124
+ const legacyoutput2 = (0, _navTiming.addPT)(offset, {
125
+ ...legacyTestValues,
126
+ loadEventEnd: -1
127
+ }, {}, true);
128
+ let legacyexpected = {
129
+ ...expectedPT
130
+ };
131
+ delete legacyexpected.le;
132
+ expect(legacyoutput2).toEqual(expected);
133
+ const legacyoutput3 = (0, _navTiming.addPT)(offset, {
134
+ ...legacyTestValues,
135
+ loadEventEnd: 'test'
136
+ }, {}, true);
137
+ legacyexpected = {
138
+ ...expectedPT
139
+ };
140
+ delete legacyexpected.le;
141
+ expect(legacyoutput3).toEqual(legacyexpected);
142
+ const legacyoutput4 = (0, _navTiming.addPT)(offset, {
143
+ ...legacyTestValues,
144
+ loadEventEnd: null
145
+ }, {}, true);
146
+ legacyexpected = {
147
+ ...expectedPT
148
+ };
149
+ delete legacyexpected.le;
150
+ expect(legacyoutput4).toEqual(legacyexpected);
151
+ });
152
+ test('rounds values to integers', () => {
153
+ const output = (0, _navTiming.addPT)(offset, {
154
+ unloadEventStart: 3.14159
155
+ }, {});
156
+ expect(output.u).toEqual(3);
157
+ const legacyoutput = (0, _navTiming.addPT)(0, {
158
+ unloadEventStart: 3.14159
159
+ }, {}, true);
160
+ expect(legacyoutput.u).toEqual(3);
161
+ });
162
+ test('adds entries to navTimingValues', () => {
163
+ const beforeLength = _navTiming.navTimingValues.length;
164
+ (0, _navTiming.addPT)(offset, {
165
+ testValues
166
+ }, {});
167
+ const afterLength = _navTiming.navTimingValues.length;
168
+ expect(afterLength - beforeLength).toEqual(21); // 20 + value of n
169
+
170
+ const legacybeforeLength = _navTiming.navTimingValues.length;
171
+ (0, _navTiming.addPT)(offset, {
172
+ legacyTestValues
173
+ }, {}, true);
174
+ const legacyafterLength = _navTiming.navTimingValues.length;
175
+ expect(legacyafterLength - legacybeforeLength).toEqual(21); // 20 + value of n
176
+ });
177
+ });
178
+
179
+ describe('addPN()', () => {
180
+ test('an output object is populated with valid values', () => {
181
+ const output = (0, _navTiming.addPN)(testValues, {});
182
+ expect(output).toEqual(expectedPN);
183
+ });
184
+ test('adds entries to navTimingValues', () => {
185
+ const beforeLength = _navTiming.navTimingValues.length;
186
+ (0, _navTiming.addPN)(offset, {
187
+ testValues
188
+ }, {});
189
+ const afterLength = _navTiming.navTimingValues.length;
190
+ expect(afterLength - beforeLength).toEqual(2);
191
+ });
192
+ });
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.subscribeToEOL = subscribeToEOL;
7
7
  var _firefoxVersion = require("../browser-version/firefox-version");
8
8
  var _eventListenerOpts = require("../event-listener/event-listener-opts");
9
- var _single = require("../util/single");
9
+ var _invoke = require("../util/invoke");
10
10
  var _globalScope = require("../util/global-scope");
11
11
  var _pageVisibility = require("../window/page-visibility");
12
12
  /*
@@ -40,7 +40,7 @@ function subscribeToEOL(cb, allowBFCache) {
40
40
  (0, _eventListenerOpts.windowAddEventListener)('pagehide', cb); // when user navigates away, and because safari iOS v14.4- doesn't fully support vis change
41
41
  // --this ought to be removed once support for version below 14.5 phases out
42
42
  } else {
43
- var oneCall = (0, _single.single)(cb);
43
+ var oneCall = (0, _invoke.single)(cb);
44
44
 
45
45
  // Firefox has a bug wherein a slow-loading resource loaded from the 'pagehide'
46
46
  // or 'unload' event will delay the 'load' event firing on the next page load.
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ var _cleanUrl = require("./clean-url");
4
+ test.each([['http://domain.com/path?query=5', 'http://domain.com/path'], ['http://domain.com/path#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path']])('cleanURL should remove hash', (input, expected) => {
5
+ expect((0, _cleanUrl.cleanURL)(input)).toEqual(expected);
6
+ });
7
+ test.each([['http://domain.com/path?query=5', 'http://domain.com/path'], ['http://domain.com/path#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path#fragment#dumb'], ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path#fragment#dumb'], ['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path#fragment/silly/dumber#dumbest']])('cleanURL should retain hash if second argument is true', (input, expected) => {
8
+ expect((0, _cleanUrl.cleanURL)(input, true)).toEqual(expected);
9
+ });
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ var encode = _interopRequireWildcard(require("./encode"));
4
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
5
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
6
+ describe('query string encoding', () => {
7
+ test('escapes string components except safe characters', () => {
8
+ const input = 'Asdf:, :, /@$;';
9
+ const expected = 'Asdf:,%20:,%20/@$;';
10
+ expect(encode.qs(input)).toEqual(expected);
11
+ });
12
+ test('null and undefined value returns \'null\'', () => {
13
+ expect(encode.qs(null)).toEqual('null');
14
+ expect(encode.qs(undefined)).toEqual('null');
15
+ });
16
+ });
17
+ describe('fromArray encoding', () => {
18
+ test('cuts cleanly at end of byte', () => {
19
+ const input = ['a', 'b', 'c'];
20
+ const expected = 'ab';
21
+ expect(encode.fromArray(input, 2)).toEqual(expected);
22
+ });
23
+ test('fall back to largest whole chunk', () => {
24
+ const input = ['aa', 'bb', 'cc'];
25
+ const expected = 'aabb';
26
+ expect(encode.fromArray(input, 5)).toEqual(expected);
27
+ });
28
+ });
29
+ describe('object encoding', () => {
30
+ test('cuts cleanly at end of byte', () => {
31
+ const input = {
32
+ foo: [1, 2, 3]
33
+ };
34
+ const expected = '&foo=%5B1,2%5D';
35
+ expect(encode.obj(input, 12)).toEqual(expected);
36
+ });
37
+ test('fall back to largest whole chunk', () => {
38
+ const input = {
39
+ bar: ['a', 'b', 'c']
40
+ };
41
+ const expected = '&bar=%5B%22a%22,%22b%22%5D';
42
+ expect(encode.obj(input, 30)).toEqual(expected);
43
+ });
44
+ test('handles circular objects', () => {
45
+ const circular = {};
46
+ circular.circular = circular;
47
+ const input = {
48
+ bar: ['a', circular, 'c']
49
+ };
50
+ const expected = '&bar=%5B%22a%22,%7B%7D,%22c%22%5D';
51
+ expect(encode.obj(input, 1000)).toEqual(expected);
52
+ });
53
+ test('handles circular arrays', () => {
54
+ const circular = [];
55
+ circular.push(circular);
56
+ const input = {
57
+ bar: ['a', circular, 'c']
58
+ };
59
+ const expected = '&bar=%5B%22a%22,%5Bnull%5D,%22c%22%5D';
60
+ expect(encode.obj(input, 1000)).toEqual(expected);
61
+ });
62
+ });
63
+ describe('encode key value pairs as query params', () => {
64
+ test('ignores input when value is null or undefined', () => {
65
+ expect(encode.param('foo', null)).toEqual('');
66
+ expect(encode.param('foo', undefined)).toEqual('');
67
+ });
68
+ test('encodes key value pair correctly', () => {
69
+ expect(encode.param('foo', 'bar')).toEqual('&foo=bar');
70
+ });
71
+ test('ignores input when value is not a string', () => {
72
+ expect(encode.param('foo', {})).toEqual('');
73
+ });
74
+ });
@@ -9,6 +9,10 @@ exports.getLocation = getLocation;
9
9
  * SPDX-License-Identifier: Apache-2.0
10
10
  */
11
11
 
12
+ /**
13
+ * This method only exists to support testing in JIL and can be removed once tests are migrated to WDIO.
14
+ * @returns global scope location
15
+ */
12
16
  function getLocation() {
13
17
  return '' + location;
14
18
  }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _faker = require("@faker-js/faker");
4
+ var _location = require("./location");
5
+ test('should always return a string', () => {
6
+ jest.spyOn(window, 'location', 'get').mockReturnValue({});
7
+ expect(typeof (0, _location.getLocation)()).toEqual('string');
8
+ });
9
+ test('should return window location', () => {
10
+ const expected = _faker.faker.internet.url();
11
+ jest.spyOn(window, 'location', 'get').mockReturnValue(expected);
12
+ expect((0, _location.getLocation)()).toEqual(expected);
13
+ });
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
4
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
5
+ afterEach(() => {
6
+ jest.resetModules();
7
+ jest.clearAllMocks();
8
+ });
9
+ const urlTests = [{
10
+ input: 'http://example.com/path/name?qs=5&a=b',
11
+ expected: {
12
+ hostname: 'example.com',
13
+ pathname: '/path/name',
14
+ protocol: 'http',
15
+ port: '80',
16
+ sameOrigin: false
17
+ }
18
+ }, {
19
+ input: 'http://foo:bar@example.com:8080/path/@name?qs=5&a=b',
20
+ expected: {
21
+ hostname: 'example.com',
22
+ pathname: '/path/@name',
23
+ protocol: 'http',
24
+ port: '8080',
25
+ sameOrigin: false
26
+ }
27
+ }, {
28
+ input: 'https://foo:bar@example.com/path/name?qs=5&a=b',
29
+ expected: {
30
+ hostname: 'example.com',
31
+ pathname: '/path/name',
32
+ protocol: 'https',
33
+ port: '443',
34
+ sameOrigin: false
35
+ }
36
+ }, {
37
+ input: '/path/name?qs=5&a=b',
38
+ expected: {
39
+ hostname: location.hostname,
40
+ pathname: '/path/name',
41
+ protocol: location.protocol.split(':')[0],
42
+ port: '80',
43
+ sameOrigin: true
44
+ }
45
+ }, {
46
+ input: location.protocol + '//' + location.hostname + ':' + location.port + '/path/name?qs=5&a=b',
47
+ expected: {
48
+ hostname: location.hostname,
49
+ pathname: '/path/name',
50
+ protocol: location.protocol.split(':')[0],
51
+ port: '80',
52
+ sameOrigin: true
53
+ }
54
+ }, {
55
+ input: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==',
56
+ expected: {
57
+ protocol: 'data'
58
+ }
59
+ }];
60
+ test.each(urlTests)('verify url parsing inside browser scope', async _ref => {
61
+ let {
62
+ input,
63
+ expected
64
+ } = _ref;
65
+ jest.doMock('../util/global-scope', () => ({
66
+ __esModule: true,
67
+ isBrowserScope: true,
68
+ globalScope: global
69
+ }));
70
+ const {
71
+ parseUrl
72
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require('./parse-url')));
73
+ expect(parseUrl(input)).toEqual(expected);
74
+ });
75
+ test.each(urlTests)('verify url parsing outside browser scope', async _ref2 => {
76
+ let {
77
+ input,
78
+ expected
79
+ } = _ref2;
80
+ jest.doMock('../util/global-scope', () => ({
81
+ __esModule: true,
82
+ isBrowserScope: false,
83
+ globalScope: global
84
+ }));
85
+ const {
86
+ parseUrl
87
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require('./parse-url')));
88
+ expect(parseUrl(input)).toEqual(expected);
89
+ });
90
+ test('should cache parsed urls', async () => {
91
+ jest.doMock('../util/global-scope', () => ({
92
+ __esModule: true,
93
+ isBrowserScope: true,
94
+ globalScope: global
95
+ }));
96
+ const input = 'http://example.com/';
97
+ const expected = {
98
+ hostname: 'example.com',
99
+ pathname: '/',
100
+ protocol: 'http',
101
+ port: '80',
102
+ sameOrigin: false
103
+ };
104
+ jest.spyOn(document, 'createElement');
105
+ const {
106
+ parseUrl
107
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require('./parse-url')));
108
+ parseUrl(input);
109
+ expect(parseUrl(input)).toEqual(expected);
110
+ expect(document.createElement).toHaveBeenCalledTimes(1);
111
+ });
@@ -3,23 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.protocol = void 0;
6
+ exports.isFileProtocol = isFileProtocol;
7
7
  var _globalScope = require("../util/global-scope");
8
8
  /*
9
9
  * Copyright 2020 New Relic Corporation. All rights reserved.
10
10
  * SPDX-License-Identifier: Apache-2.0
11
11
  */
12
12
 
13
- const protocol = {
14
- isFileProtocol: isFileProtocol,
15
- supportabilityMetricSent: false
16
- };
17
- exports.protocol = protocol;
18
13
  function isFileProtocol() {
19
- let isFile = Boolean((0, _globalScope.getGlobalScope)()?.location?.protocol === 'file:');
20
- if (isFile) {
21
- //metrics.recordSupportability('Generic/FileProtocol/Detected') -- may be implemented later? Probably make sure it's once per window
22
- protocol.supportabilityMetricSent = true;
23
- }
24
- return isFile;
14
+ return Boolean(_globalScope.globalScope?.location?.protocol === 'file:');
25
15
  }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _faker = require("@faker-js/faker");
4
+ var _protocol = require("./protocol");
5
+ test('should return true when location url contains file protocol', () => {
6
+ jest.spyOn(window, 'location', 'get').mockReturnValue({
7
+ protocol: 'file:'
8
+ });
9
+ expect((0, _protocol.isFileProtocol)()).toEqual(true);
10
+ });
11
+ test('should return false when location url does not contains file protocol', () => {
12
+ jest.spyOn(window, 'location', 'get').mockReturnValue({
13
+ protocol: 'http:'
14
+ });
15
+ expect((0, _protocol.isFileProtocol)()).toEqual(false);
16
+ });
@@ -12,6 +12,6 @@ exports.warn = warn;
12
12
  */
13
13
  function warn(message, secondary) {
14
14
  if (typeof console.warn !== 'function') return;
15
- console.warn(`New Relic: ${message}`);
15
+ console.warn("New Relic: ".concat(message));
16
16
  if (secondary) console.warn(secondary);
17
17
  }
@@ -10,6 +10,12 @@ var _stringify = require("./stringify");
10
10
  * SPDX-License-Identifier: Apache-2.0
11
11
  */
12
12
 
13
+ /**
14
+ * Returns the size of the provided data. Designed for measuring XHR responses.
15
+ *
16
+ * @param {*} data - The data to be measured.
17
+ * @returns {(number|undefined)} - The size of the data or undefined if size cannot be determined.
18
+ */
13
19
  function dataSize(data) {
14
20
  if (typeof data === 'string' && data.length) return data.length;
15
21
  if (typeof data !== 'object') return undefined;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _dataSize = require("./data-size");
4
+ describe('dataSize', () => {
5
+ test('returns length of string', () => {
6
+ const str = 'Hello, world!';
7
+ expect((0, _dataSize.dataSize)(str)).toBe(str.length);
8
+ });
9
+ test('returns undefined for non-object, number, or empty string', () => {
10
+ expect((0, _dataSize.dataSize)(Infinity)).toBeUndefined();
11
+ expect((0, _dataSize.dataSize)(12345)).toBeUndefined(); // might not actually be by design, but this is how it works today
12
+ expect((0, _dataSize.dataSize)('')).toBeUndefined();
13
+ });
14
+ test('returns byte length of ArrayBuffer object', () => {
15
+ const buffer = new ArrayBuffer(8);
16
+ expect((0, _dataSize.dataSize)(buffer)).toBe(8);
17
+ });
18
+ test('returns size of Blob object', () => {
19
+ const blob = new Blob(['Hello, world!'], {
20
+ type: 'text/plain'
21
+ });
22
+ expect((0, _dataSize.dataSize)(blob)).toBe(blob.size);
23
+ });
24
+ test('returns undefined for FormData object', () => {
25
+ const formData = new FormData();
26
+ expect((0, _dataSize.dataSize)(formData)).toBeUndefined();
27
+ });
28
+ test('returns length of JSON string representation of object', () => {
29
+ const obj = {
30
+ str: 'Hello, world!',
31
+ num: 12345,
32
+ nestedObj: {
33
+ arr: [1, 2, 3]
34
+ }
35
+ };
36
+ const expectedSize = JSON.stringify(obj).length;
37
+ expect((0, _dataSize.dataSize)(obj)).toBe(expectedSize);
38
+ });
39
+ test('returns undefined for object with toJSON method that throws an error', () => {
40
+ const obj = {
41
+ toJSON: () => {
42
+ throw new Error('Error in toJSON');
43
+ }
44
+ };
45
+ expect((0, _dataSize.dataSize)(obj)).toBeUndefined();
46
+ });
47
+ });
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.debounce = debounce;
7
+ exports.single = single;
8
+ /**
9
+ * Reduce the invocation of the supplied function so that it is only invoked
10
+ * once within a given timeout.
11
+ *
12
+ * If `wait` is `0`, the function will be invoked during the next tick.
13
+ * If `options.leading` is false or not provided, the function will be invoked
14
+ * N milliseconds after the last invocation of the returned function where
15
+ * N is the `timeout` value.
16
+ * If `options.leading` is true, the function will be invoked immediately upon
17
+ * the first invocation of the returned function and not again for N milliseconds
18
+ * where N is the `timeout` value.
19
+ * @param {function} func Function whose invocation should be limited so it is only invoked
20
+ * once within a given timeout period.
21
+ * @param {number} timeout Time in milliseconds that the function should only be invoked
22
+ * once within.
23
+ * @param {object} options Debounce options
24
+ * @param {boolean} options.leading Forces the function to be invoked on the first
25
+ * invocation of the returned function instead of N milliseconds after the last
26
+ * invocation.
27
+ * @returns {function} A wrapping function that will ensure the provided function
28
+ * is invoked only once within the given timeout.
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] : {};
34
+ const leading = options?.leading || false;
35
+ 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
+ }
40
+ if (leading && timer === undefined) {
41
+ func.apply(_this, args);
42
+ timer = setTimeout(() => timer = clearTimeout(timer), timeout);
43
+ }
44
+ if (!leading) {
45
+ clearTimeout(timer);
46
+ timer = setTimeout(() => {
47
+ func.apply(_this, args);
48
+ }, timeout);
49
+ }
50
+ };
51
+ }
52
+
53
+ /**
54
+ * Reduce the invocation of the supplied function so that it is only invoked
55
+ * once.
56
+ * @param {function} func Function whose invocation should be limited so it is only invoked
57
+ * once.
58
+ * @returns {function} A wrapping function that will ensure the provided function
59
+ * is invoked only once.
60
+ */
61
+ function single(func) {
62
+ var _this2 = this;
63
+ let called = false;
64
+ return function () {
65
+ if (!called) {
66
+ called = true;
67
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
68
+ args[_key2] = arguments[_key2];
69
+ }
70
+ func.apply(_this2, args);
71
+ }
72
+ };
73
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _invoke = require("./invoke");
4
+ jest.useFakeTimers();
5
+ describe('debounce', () => {
6
+ test('should run the supplied function after 100ms', () => {
7
+ let mockCallback = jest.fn();
8
+ let debouncedMethod = (0, _invoke.debounce)(mockCallback, 100);
9
+ execFnTimes(debouncedMethod, 100);
10
+ expect(mockCallback).not.toHaveBeenCalled();
11
+ jest.advanceTimersByTime(1000);
12
+ expect(mockCallback).toHaveBeenCalledTimes(1);
13
+ });
14
+ test('should rerun the supplied function when called again after 100ms', () => {
15
+ let mockCallback = jest.fn();
16
+ let debouncedMethod = (0, _invoke.debounce)(mockCallback, 100);
17
+ execFnTimes(debouncedMethod, 100);
18
+ jest.advanceTimersByTime(200);
19
+ execFnTimes(debouncedMethod, 100);
20
+ jest.advanceTimersByTime(2000);
21
+ expect(mockCallback).toHaveBeenCalledTimes(2);
22
+ });
23
+ test('should run the supplied function on the first event and debounce subsequent events', () => {
24
+ let mockCallback = jest.fn();
25
+ let debouncedMethod = (0, _invoke.debounce)(mockCallback, 100, {
26
+ leading: true
27
+ });
28
+ execFnTimes(debouncedMethod, 100);
29
+ expect(mockCallback).toHaveBeenCalledTimes(1);
30
+ jest.advanceTimersByTime(200);
31
+ expect(mockCallback).toHaveBeenCalledTimes(1);
32
+ execFnTimes(debouncedMethod, 100);
33
+ jest.advanceTimersByTime(200);
34
+ expect(mockCallback).toHaveBeenCalledTimes(2);
35
+ });
36
+ });
37
+ describe('single', () => {
38
+ test('should run the supplied function only once', () => {
39
+ let mockCallback = jest.fn();
40
+ let singleMethod = (0, _invoke.single)(mockCallback, 100);
41
+ execFnTimes(singleMethod, 100);
42
+ expect(mockCallback).toHaveBeenCalledTimes(1);
43
+ });
44
+ });
45
+ function execFnTimes(fn, count) {
46
+ for (let i = 0; i < count; i++) {
47
+ fn();
48
+ }
49
+ }