@utk09/ui-observability 0.12.0 → 1.1.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 (523) hide show
  1. package/CHANGELOG.md +280 -10
  2. package/README.md +70 -839
  3. package/dist/{batch-BjQUwjA6.js → batch-D3NHhF9L.js} +4 -4
  4. package/dist/{batch-BjQUwjA6.js.map → batch-D3NHhF9L.js.map} +1 -1
  5. package/dist/{batch-D5LlU4Q9.cjs → batch-DnYRJqhU.cjs} +2 -2
  6. package/dist/{batch-D5LlU4Q9.cjs.map → batch-DnYRJqhU.cjs.map} +1 -1
  7. package/dist/bus/bus.d.cts +355 -0
  8. package/dist/bus/bus.d.ts +86 -12
  9. package/dist/bus/links.d.cts +132 -0
  10. package/dist/bus/links.d.ts +18 -3
  11. package/dist/bus/validation.d.cts +16 -0
  12. package/dist/bus/validation.d.ts +10 -1
  13. package/dist/bus-B__467mL.cjs +2 -0
  14. package/dist/bus-B__467mL.cjs.map +1 -0
  15. package/dist/bus-dw7T92sO.js +788 -0
  16. package/dist/bus-dw7T92sO.js.map +1 -0
  17. package/dist/capture/console.d.cts +37 -0
  18. package/dist/capture/console.d.ts +1 -1
  19. package/dist/capture/errors.d.cts +32 -0
  20. package/dist/capture/errors.d.ts +1 -1
  21. package/dist/capture/interactions.d.cts +80 -0
  22. package/dist/capture/interactions.d.ts +36 -4
  23. package/dist/capture/lifecycle.d.cts +20 -0
  24. package/dist/capture/lifecycle.d.ts +1 -1
  25. package/dist/capture/long-frames.d.cts +31 -0
  26. package/dist/capture/long-frames.d.ts +1 -1
  27. package/dist/capture/network.d.cts +57 -0
  28. package/dist/capture/network.d.ts +1 -1
  29. package/dist/capture/observed-windows.d.cts +51 -0
  30. package/dist/capture/observed-windows.d.ts +51 -0
  31. package/dist/capture/profiler-frames.d.cts +44 -0
  32. package/dist/capture/profiler-frames.d.ts +1 -1
  33. package/dist/capture/replay-buffer.d.cts +45 -0
  34. package/dist/capture/replay-buffer.d.ts +9 -10
  35. package/dist/capture/replay-upload.d.cts +79 -0
  36. package/dist/capture/replay-upload.d.ts +7 -2
  37. package/dist/capture/replay.d.cts +114 -0
  38. package/dist/capture/replay.d.ts +1 -1
  39. package/dist/capture/reports.d.cts +17 -0
  40. package/dist/capture/reports.d.ts +1 -1
  41. package/dist/capture/resource-timing.d.cts +14 -0
  42. package/dist/capture/resource-timing.d.ts +1 -1
  43. package/dist/capture/server-timing.d.cts +19 -0
  44. package/dist/capture/storm.d.cts +13 -0
  45. package/dist/capture/storm.d.ts +5 -5
  46. package/dist/capture/types.d.cts +128 -0
  47. package/dist/capture/types.d.ts +10 -9
  48. package/dist/capture/unclean-exit.d.cts +31 -0
  49. package/dist/capture/unclean-exit.d.ts +1 -1
  50. package/dist/capture/user-timing.d.cts +22 -0
  51. package/dist/capture/user-timing.d.ts +2 -2
  52. package/dist/capture/web-socket.d.cts +40 -0
  53. package/dist/capture/web-socket.d.ts +3 -3
  54. package/dist/capture/web-vitals.d.cts +40 -0
  55. package/dist/capture/web-vitals.d.ts +1 -1
  56. package/dist/{compression-lD9abCcO.cjs → compression-C0hUHKR-.cjs} +2 -2
  57. package/dist/{compression-lD9abCcO.cjs.map → compression-C0hUHKR-.cjs.map} +1 -1
  58. package/dist/{compression-AJJCMBOa.js → compression-SHPAvS4U.js} +2 -2
  59. package/dist/{compression-AJJCMBOa.js.map → compression-SHPAvS4U.js.map} +1 -1
  60. package/dist/config-CSNcS7OZ.js +558 -0
  61. package/dist/config-CSNcS7OZ.js.map +1 -0
  62. package/dist/config-CybPP5VM.cjs +2 -0
  63. package/dist/config-CybPP5VM.cjs.map +1 -0
  64. package/dist/console-BsM-fSCQ.js +81 -0
  65. package/dist/console-BsM-fSCQ.js.map +1 -0
  66. package/dist/console-Dkxs6IVQ.cjs +2 -0
  67. package/dist/console-Dkxs6IVQ.cjs.map +1 -0
  68. package/dist/constants-BwJDXzj6.js +357 -0
  69. package/dist/constants-BwJDXzj6.js.map +1 -0
  70. package/dist/constants-CtF52hIV.cjs +2 -0
  71. package/dist/constants-CtF52hIV.cjs.map +1 -0
  72. package/dist/constants.d.cts +763 -0
  73. package/dist/constants.d.ts +100 -20
  74. package/dist/core/breadcrumbs.d.cts +54 -0
  75. package/dist/core/breadcrumbs.d.ts +5 -0
  76. package/dist/core/config.d.cts +45 -0
  77. package/dist/core/config.d.ts +30 -2
  78. package/dist/core/context.d.cts +24 -0
  79. package/dist/core/context.d.ts +3 -8
  80. package/dist/core/debug-buffer.d.cts +34 -0
  81. package/dist/core/debug-buffer.d.ts +3 -3
  82. package/dist/core/debug-bundle.d.cts +12 -0
  83. package/dist/core/debug-bundle.d.ts +3 -3
  84. package/dist/core/deferred.d.cts +7 -0
  85. package/dist/core/deferred.d.ts +2 -2
  86. package/dist/core/diagnostics.d.cts +86 -0
  87. package/dist/core/diagnostics.d.ts +1 -1
  88. package/dist/core/drops.d.cts +39 -0
  89. package/dist/core/drops.d.ts +16 -6
  90. package/dist/core/hold-buffer.d.cts +36 -0
  91. package/dist/core/hold-buffer.d.ts +16 -7
  92. package/dist/core/journey.d.cts +148 -0
  93. package/dist/core/journey.d.ts +7 -7
  94. package/dist/core/logger.d.cts +141 -0
  95. package/dist/core/logger.d.ts +23 -30
  96. package/dist/core/measure.d.cts +30 -0
  97. package/dist/core/measure.d.ts +14 -3
  98. package/dist/core/meter.d.cts +78 -0
  99. package/dist/core/meter.d.ts +14 -8
  100. package/dist/core/pipeline.d.cts +227 -0
  101. package/dist/core/pipeline.d.ts +73 -10
  102. package/dist/core/profile-buckets.d.cts +31 -0
  103. package/dist/core/profiler.d.cts +218 -0
  104. package/dist/core/profiler.d.ts +2 -2
  105. package/dist/core/record.d.cts +190 -0
  106. package/dist/core/record.d.ts +44 -12
  107. package/dist/core/remote-rules.d.cts +17 -0
  108. package/dist/core/remote-rules.d.ts +3 -3
  109. package/dist/core/remote-sampling.d.cts +74 -0
  110. package/dist/core/remote-sampling.d.ts +3 -3
  111. package/dist/core/rotation.d.cts +99 -0
  112. package/dist/core/rotation.d.ts +99 -0
  113. package/dist/core/runtime.d.cts +774 -0
  114. package/dist/core/runtime.d.ts +254 -70
  115. package/dist/core/sampling.d.cts +86 -0
  116. package/dist/core/sampling.d.ts +5 -5
  117. package/dist/core/sender.d.cts +161 -0
  118. package/dist/core/sender.d.ts +59 -15
  119. package/dist/core/spans.d.cts +39 -0
  120. package/dist/core/spans.d.ts +1 -1
  121. package/dist/debug-bundle-B2v6Cym-.cjs +2 -0
  122. package/dist/debug-bundle-B2v6Cym-.cjs.map +1 -0
  123. package/dist/debug-bundle-Cs_YWzTa.js +35 -0
  124. package/dist/debug-bundle-Cs_YWzTa.js.map +1 -0
  125. package/dist/defineProperty-X1c4tIPD.cjs +1 -0
  126. package/dist/defineProperty-s2S8BXUc.js +35 -0
  127. package/dist/doctor.cjs +1 -1
  128. package/dist/doctor.cjs.map +1 -1
  129. package/dist/doctor.d.cts +36 -0
  130. package/dist/doctor.d.ts +5 -2
  131. package/dist/doctor.js +119 -87
  132. package/dist/doctor.js.map +1 -1
  133. package/dist/errors-DP2RUm4V.cjs +3 -0
  134. package/dist/errors-DP2RUm4V.cjs.map +1 -0
  135. package/dist/errors-Q3Ng1ciC.js +86 -0
  136. package/dist/errors-Q3Ng1ciC.js.map +1 -0
  137. package/dist/factory-DV17sm2p.js +404 -0
  138. package/dist/factory-DV17sm2p.js.map +1 -0
  139. package/dist/factory-K8O6gpux.cjs +2 -0
  140. package/dist/factory-K8O6gpux.cjs.map +1 -0
  141. package/dist/guards-BlYGRK4l.js +10 -0
  142. package/dist/guards-BlYGRK4l.js.map +1 -0
  143. package/dist/guards-EjG3ahFp.cjs +2 -0
  144. package/dist/guards-EjG3ahFp.cjs.map +1 -0
  145. package/dist/{identity-BrQp_5J5.js → identity-BgtHyY4u.js} +33 -26
  146. package/dist/identity-BgtHyY4u.js.map +1 -0
  147. package/dist/identity-CvuyqZk7.cjs +2 -0
  148. package/dist/identity-CvuyqZk7.cjs.map +1 -0
  149. package/dist/index.cjs +1 -1
  150. package/dist/index.cjs.map +1 -1
  151. package/dist/index.d.cts +301 -0
  152. package/dist/index.d.ts +90 -98
  153. package/dist/index.js +1253 -1555
  154. package/dist/index.js.map +1 -1
  155. package/dist/indexeddb-storage-D4KVcqdD.cjs +2 -0
  156. package/dist/indexeddb-storage-D4KVcqdD.cjs.map +1 -0
  157. package/dist/{indexeddb-storage-DLXQzAGh.js → indexeddb-storage-e-13ZLWm.js} +61 -57
  158. package/dist/indexeddb-storage-e-13ZLWm.js.map +1 -0
  159. package/dist/interactions-Byxf1C82.js +207 -0
  160. package/dist/interactions-Byxf1C82.js.map +1 -0
  161. package/dist/interactions-OK85T-Dk.cjs +2 -0
  162. package/dist/interactions-OK85T-Dk.cjs.map +1 -0
  163. package/dist/{journey-35yCMNFo.js → journey-C93FTYcs.js} +46 -49
  164. package/dist/journey-C93FTYcs.js.map +1 -0
  165. package/dist/journey-nMbob3OB.cjs +2 -0
  166. package/dist/journey-nMbob3OB.cjs.map +1 -0
  167. package/dist/{library-console-BFWEuQsl.cjs → library-console-DJUQzcgM.cjs} +2 -2
  168. package/dist/{library-console-BFWEuQsl.cjs.map → library-console-DJUQzcgM.cjs.map} +1 -1
  169. package/dist/{library-console-Dl_Ly6DQ.js → library-console-DklSmucS.js} +2 -2
  170. package/dist/{library-console-Dl_Ly6DQ.js.map → library-console-DklSmucS.js.map} +1 -1
  171. package/dist/{library-request-nI6pvI6I.js → library-request-UGEwOHpf.js} +2 -2
  172. package/dist/{library-request-nI6pvI6I.js.map → library-request-UGEwOHpf.js.map} +1 -1
  173. package/dist/{library-request-Da-CHKzT.cjs → library-request-kY9iTpIF.cjs} +2 -2
  174. package/dist/{library-request-Da-CHKzT.cjs.map → library-request-kY9iTpIF.cjs.map} +1 -1
  175. package/dist/{lifecycle-CZ6RRXc6.js → lifecycle-B2PlIuQu.js} +21 -29
  176. package/dist/lifecycle-B2PlIuQu.js.map +1 -0
  177. package/dist/lifecycle-DaMdH_X7.cjs +2 -0
  178. package/dist/lifecycle-DaMdH_X7.cjs.map +1 -0
  179. package/dist/log-record-Bmx6etMh.cjs +2 -0
  180. package/dist/log-record-Bmx6etMh.cjs.map +1 -0
  181. package/dist/{log-record-DIA6McNr.js → log-record-DSt2P-Sr.js} +8 -7
  182. package/dist/log-record-DSt2P-Sr.js.map +1 -0
  183. package/dist/{long-frames-430_85Da.js → long-frames-Bamjs1WV.js} +18 -22
  184. package/dist/long-frames-Bamjs1WV.js.map +1 -0
  185. package/dist/long-frames-lhtONgGt.cjs +2 -0
  186. package/dist/long-frames-lhtONgGt.cjs.map +1 -0
  187. package/dist/models/batch.d.cts +57 -0
  188. package/dist/models/batch.d.ts +2 -2
  189. package/dist/models/bus.d.cts +163 -0
  190. package/dist/models/bus.d.ts +28 -3
  191. package/dist/models/config.d.cts +1555 -0
  192. package/dist/models/config.d.ts +377 -261
  193. package/dist/models/drop.d.cts +54 -0
  194. package/dist/models/drop.d.ts +16 -3
  195. package/dist/models/health.d.cts +148 -0
  196. package/dist/models/health.d.ts +108 -12
  197. package/dist/models/log-record.d.cts +61 -0
  198. package/dist/models/metric.d.cts +139 -0
  199. package/dist/models/metric.d.ts +13 -2
  200. package/dist/models/plugin.d.cts +47 -0
  201. package/dist/models/plugin.d.ts +3 -3
  202. package/dist/models/replay.d.cts +60 -0
  203. package/dist/models/serializer.d.cts +25 -0
  204. package/dist/models/serializer.d.ts +4 -2
  205. package/dist/models/storage.d.cts +95 -0
  206. package/dist/models/storage.d.ts +7 -5
  207. package/dist/network-BCn8Gn47.cjs +2 -0
  208. package/dist/network-BCn8Gn47.cjs.map +1 -0
  209. package/dist/{network-C7SkLf4v.js → network-Cg1L2w2r.js} +57 -57
  210. package/dist/network-Cg1L2w2r.js.map +1 -0
  211. package/dist/observed-windows-B3gJkdql.cjs +2 -0
  212. package/dist/observed-windows-B3gJkdql.cjs.map +1 -0
  213. package/dist/observed-windows-BrwaJNlj.js +64 -0
  214. package/dist/observed-windows-BrwaJNlj.js.map +1 -0
  215. package/dist/{otlp-2MCrC3kd.cjs → otlp-CrAWkQdO.cjs} +2 -2
  216. package/dist/{otlp-2MCrC3kd.cjs.map → otlp-CrAWkQdO.cjs.map} +1 -1
  217. package/dist/{otlp-COq033e3.js → otlp-D6dRZyB8.js} +9 -9
  218. package/dist/{otlp-COq033e3.js.map → otlp-D6dRZyB8.js.map} +1 -1
  219. package/dist/{platform-CVewe4wQ.js → platform-8DLhjddo.js} +9 -9
  220. package/dist/{platform-CVewe4wQ.js.map → platform-8DLhjddo.js.map} +1 -1
  221. package/dist/{platform-12uR7kBQ.cjs → platform-BqRc-7RO.cjs} +2 -2
  222. package/dist/{platform-12uR7kBQ.cjs.map → platform-BqRc-7RO.cjs.map} +1 -1
  223. package/dist/{profiler-BVWIOgnq.js → profiler-BaXSqCfz.js} +78 -96
  224. package/dist/profiler-BaXSqCfz.js.map +1 -0
  225. package/dist/profiler-BvWW2kNM.cjs +2 -0
  226. package/dist/profiler-BvWW2kNM.cjs.map +1 -0
  227. package/dist/{profiler-frames-CLXlT_xL.js → profiler-frames-C4ySHN0X.js} +21 -29
  228. package/dist/profiler-frames-C4ySHN0X.js.map +1 -0
  229. package/dist/profiler-frames-DeaBiB-5.cjs +2 -0
  230. package/dist/profiler-frames-DeaBiB-5.cjs.map +1 -0
  231. package/dist/remote-rules-D7L6D_D2.cjs +2 -0
  232. package/dist/remote-rules-D7L6D_D2.cjs.map +1 -0
  233. package/dist/remote-rules-Dq9xe7Qn.js +95 -0
  234. package/dist/remote-rules-Dq9xe7Qn.js.map +1 -0
  235. package/dist/replay-B0M8kWz_.js +310 -0
  236. package/dist/replay-B0M8kWz_.js.map +1 -0
  237. package/dist/replay-QOFBpAXh.cjs +2 -0
  238. package/dist/replay-QOFBpAXh.cjs.map +1 -0
  239. package/dist/{reports-BuXekPOS.js → reports--8APRLa-.js} +25 -30
  240. package/dist/reports--8APRLa-.js.map +1 -0
  241. package/dist/reports-ojuMKGO7.cjs +2 -0
  242. package/dist/reports-ojuMKGO7.cjs.map +1 -0
  243. package/dist/{resource-timing-CXGHwFRD.js → resource-timing-BzR05rE-.js} +20 -23
  244. package/dist/resource-timing-BzR05rE-.js.map +1 -0
  245. package/dist/resource-timing-pAG3ZhB5.cjs +2 -0
  246. package/dist/resource-timing-pAG3ZhB5.cjs.map +1 -0
  247. package/dist/response-body-BWvwKQ2p.js +331 -0
  248. package/dist/response-body-BWvwKQ2p.js.map +1 -0
  249. package/dist/response-body-CKEJ5itk.cjs +3 -0
  250. package/dist/response-body-CKEJ5itk.cjs.map +1 -0
  251. package/dist/rotation-BylN1B9e.js +93 -0
  252. package/dist/rotation-BylN1B9e.js.map +1 -0
  253. package/dist/rotation-E2eKClIs.cjs +2 -0
  254. package/dist/rotation-E2eKClIs.cjs.map +1 -0
  255. package/dist/sampling-B46LW0cy.cjs +2 -0
  256. package/dist/sampling-B46LW0cy.cjs.map +1 -0
  257. package/dist/sampling-zXA6r-Nw.js +63 -0
  258. package/dist/sampling-zXA6r-Nw.js.map +1 -0
  259. package/dist/{sanitize-CNmsD9r3.js → sanitize-DjnR6RXR.js} +2 -2
  260. package/dist/sanitize-DjnR6RXR.js.map +1 -0
  261. package/dist/{sanitize-ChLn97Ch.cjs → sanitize-Qj6LuZqp.cjs} +2 -2
  262. package/dist/sanitize-Qj6LuZqp.cjs.map +1 -0
  263. package/dist/sender-Bdp-TAS4.js +979 -0
  264. package/dist/sender-Bdp-TAS4.js.map +1 -0
  265. package/dist/sender-DR7ZycZY.cjs +2 -0
  266. package/dist/sender-DR7ZycZY.cjs.map +1 -0
  267. package/dist/storage/context-storage.d.cts +90 -0
  268. package/dist/storage/context-storage.d.ts +5 -5
  269. package/dist/storage/emergency-queue.d.cts +27 -0
  270. package/dist/storage/emergency-queue.d.ts +4 -4
  271. package/dist/storage/eviction.d.cts +40 -0
  272. package/dist/storage/eviction.d.ts +1 -1
  273. package/dist/storage/factory.d.cts +21 -0
  274. package/dist/storage/factory.d.ts +3 -3
  275. package/dist/storage/gap.d.cts +20 -0
  276. package/dist/storage/gap.d.ts +3 -3
  277. package/dist/storage/idb-driver.d.cts +93 -0
  278. package/dist/storage/idb-driver.d.ts +1 -1
  279. package/dist/storage/indexeddb-storage.d.cts +97 -0
  280. package/dist/storage/indexeddb-storage.d.ts +12 -4
  281. package/dist/storage/keys.d.cts +17 -0
  282. package/dist/storage/keys.d.ts +2 -2
  283. package/dist/storage/local-storage.d.cts +139 -0
  284. package/dist/storage/local-storage.d.ts +11 -4
  285. package/dist/storage/memory-storage.d.cts +73 -0
  286. package/dist/storage/memory-storage.d.ts +4 -3
  287. package/dist/storage/persistence.d.cts +8 -0
  288. package/dist/storage/persistence.d.ts +2 -2
  289. package/dist/storage/stored-context.d.cts +34 -0
  290. package/dist/storage/stored-context.d.ts +34 -0
  291. package/dist/stored-context-BOu54M8Y.cjs +2 -0
  292. package/dist/stored-context-BOu54M8Y.cjs.map +1 -0
  293. package/dist/stored-context-CSttrAsw.js +51 -0
  294. package/dist/stored-context-CSttrAsw.js.map +1 -0
  295. package/dist/storm-BHgI12iS.cjs +2 -0
  296. package/dist/storm-BHgI12iS.cjs.map +1 -0
  297. package/dist/storm-DKlpv0FL.js +9 -0
  298. package/dist/storm-DKlpv0FL.js.map +1 -0
  299. package/dist/transport/compression.d.cts +7 -0
  300. package/dist/transport/custom-transport.d.cts +22 -0
  301. package/dist/transport/custom-transport.d.ts +6 -5
  302. package/dist/transport/errors.d.cts +31 -0
  303. package/dist/transport/exit-flush.d.cts +135 -0
  304. package/dist/transport/exit-flush.d.ts +30 -13
  305. package/dist/transport/headers.d.cts +8 -0
  306. package/dist/transport/headers.d.ts +2 -2
  307. package/dist/transport/http-transport.d.cts +116 -0
  308. package/dist/transport/http-transport.d.ts +20 -8
  309. package/dist/transport/memory-transport.d.cts +30 -0
  310. package/dist/transport/memory-transport.d.ts +2 -2
  311. package/dist/transport/response-body.d.cts +49 -0
  312. package/dist/transport/response-body.d.ts +49 -0
  313. package/dist/transport/retry-engine.d.cts +129 -0
  314. package/dist/transport/retry-engine.d.ts +27 -9
  315. package/dist/transport/serializers/ecs.d.cts +3 -0
  316. package/dist/transport/serializers/ecs.d.ts +1 -1
  317. package/dist/transport/serializers/otlp-metrics.d.cts +3 -0
  318. package/dist/transport/serializers/otlp-metrics.d.ts +1 -1
  319. package/dist/transport/serializers/otlp-traces.d.cts +3 -0
  320. package/dist/transport/serializers/otlp-traces.d.ts +1 -1
  321. package/dist/transport/serializers/otlp.d.cts +47 -0
  322. package/dist/transport/serializers/otlp.d.ts +2 -2
  323. package/dist/transport/serializers/select.d.cts +38 -0
  324. package/dist/transport/serializers/select.d.ts +5 -5
  325. package/dist/transport/status-transport.d.cts +129 -0
  326. package/dist/transport/status-transport.d.ts +25 -8
  327. package/dist/transport/worker-client.d.cts +23 -0
  328. package/dist/transport/worker-client.d.ts +12 -3
  329. package/dist/transport/worker-entry.d.cts +5 -0
  330. package/dist/transport/worker-entry.d.ts +1 -1
  331. package/dist/transport/worker-protocol.d.cts +38 -0
  332. package/dist/transport/worker-protocol.d.ts +4 -2
  333. package/dist/transport/worker-server.d.cts +3 -0
  334. package/dist/transport/worker-server.d.ts +1 -1
  335. package/dist/transport/worker-transport.d.cts +10 -0
  336. package/dist/transport/worker-transport.d.ts +5 -4
  337. package/dist/types-BAerHgCq.js.map +1 -1
  338. package/dist/types-C7WNpnG1.cjs.map +1 -1
  339. package/dist/unclean-exit-BYPYYkQ5.cjs +2 -0
  340. package/dist/unclean-exit-BYPYYkQ5.cjs.map +1 -0
  341. package/dist/{unclean-exit-Cob_jyTv.js → unclean-exit-BcOB8A2e.js} +23 -30
  342. package/dist/unclean-exit-BcOB8A2e.js.map +1 -0
  343. package/dist/{user-timing-DgHubxCI.js → user-timing-4KIJ74Vi.js} +15 -17
  344. package/dist/user-timing-4KIJ74Vi.js.map +1 -0
  345. package/dist/user-timing-BsU2wQKE.cjs +2 -0
  346. package/dist/user-timing-BsU2wQKE.cjs.map +1 -0
  347. package/dist/utils/console.d.cts +36 -0
  348. package/dist/utils/console.d.ts +4 -4
  349. package/dist/utils/deadline.d.cts +14 -0
  350. package/dist/utils/error-like.d.cts +25 -0
  351. package/dist/utils/fixed-window.d.cts +25 -0
  352. package/dist/utils/global-scope.d.cts +20 -0
  353. package/dist/utils/guards.d.cts +14 -0
  354. package/dist/utils/guards.d.ts +8 -0
  355. package/dist/utils/identity.d.cts +114 -0
  356. package/dist/utils/identity.d.ts +8 -4
  357. package/dist/utils/library-console.d.cts +11 -0
  358. package/dist/utils/library-request.d.cts +24 -0
  359. package/dist/utils/lock.d.cts +24 -0
  360. package/dist/utils/lock.d.ts +1 -1
  361. package/dist/utils/openfin.d.cts +48 -0
  362. package/dist/utils/patch.d.cts +9 -0
  363. package/dist/utils/platform.d.cts +62 -0
  364. package/dist/utils/platform.d.ts +2 -2
  365. package/dist/utils/sanitize.d.cts +52 -0
  366. package/dist/utils/sanitize.d.ts +1 -1
  367. package/dist/utils/sequence.d.cts +10 -0
  368. package/dist/utils/tracing.d.cts +158 -0
  369. package/dist/utils/tracing.d.ts +11 -4
  370. package/dist/utils/unref.d.cts +9 -0
  371. package/dist/web-socket-Cs1ZbmmN.cjs +2 -0
  372. package/dist/{web-socket-DthJuSAg.js.map → web-socket-Cs1ZbmmN.cjs.map} +1 -1
  373. package/dist/{web-socket-DthJuSAg.js → web-socket-Zg0hj1LB.js} +23 -28
  374. package/dist/web-socket-Zg0hj1LB.js.map +1 -0
  375. package/dist/{web-vitals-CsGCWnUr.js → web-vitals-4pWACwaR.js} +15 -21
  376. package/dist/web-vitals-4pWACwaR.js.map +1 -0
  377. package/dist/web-vitals-__X7t4pj.cjs +2 -0
  378. package/dist/web-vitals-__X7t4pj.cjs.map +1 -0
  379. package/dist/{worker-protocol-B0_8rWy5.js → worker-protocol-CYpAbrVl.js} +14 -11
  380. package/dist/worker-protocol-CYpAbrVl.js.map +1 -0
  381. package/dist/worker-protocol-DFYXIFus.cjs +2 -0
  382. package/dist/worker-protocol-DFYXIFus.cjs.map +1 -0
  383. package/dist/worker-server--yGTadTA.cjs +2 -0
  384. package/dist/worker-server--yGTadTA.cjs.map +1 -0
  385. package/dist/worker-server-BokySIII.js +94 -0
  386. package/dist/worker-server-BokySIII.js.map +1 -0
  387. package/dist/worker-transport-BdEvh_-a.cjs +2 -0
  388. package/dist/worker-transport-BdEvh_-a.cjs.map +1 -0
  389. package/dist/worker-transport-JK-Fby9J.js +194 -0
  390. package/dist/worker-transport-JK-Fby9J.js.map +1 -0
  391. package/llms.txt +400 -0
  392. package/package.json +65 -49
  393. package/dist/bus-D_7pd7RN.cjs +0 -2
  394. package/dist/bus-D_7pd7RN.cjs.map +0 -1
  395. package/dist/bus-ecxUNTja.js +0 -660
  396. package/dist/bus-ecxUNTja.js.map +0 -1
  397. package/dist/console-CLz_PvFn.cjs +0 -2
  398. package/dist/console-CLz_PvFn.cjs.map +0 -1
  399. package/dist/console-cwgHKXvM.js +0 -82
  400. package/dist/console-cwgHKXvM.js.map +0 -1
  401. package/dist/constants-Bwl_YtQi.js +0 -349
  402. package/dist/constants-Bwl_YtQi.js.map +0 -1
  403. package/dist/constants-DakMxVB2.cjs +0 -2
  404. package/dist/constants-DakMxVB2.cjs.map +0 -1
  405. package/dist/context-storage-BjzeBSxH.cjs +0 -2
  406. package/dist/context-storage-BjzeBSxH.cjs.map +0 -1
  407. package/dist/context-storage-BzkoHzkQ.js +0 -51
  408. package/dist/context-storage-BzkoHzkQ.js.map +0 -1
  409. package/dist/debug-bundle-BOdYmCeV.js +0 -32
  410. package/dist/debug-bundle-BOdYmCeV.js.map +0 -1
  411. package/dist/debug-bundle-Ex4L_LSP.cjs +0 -2
  412. package/dist/debug-bundle-Ex4L_LSP.cjs.map +0 -1
  413. package/dist/emergency-queue-B9WZxanZ.js +0 -67
  414. package/dist/emergency-queue-B9WZxanZ.js.map +0 -1
  415. package/dist/emergency-queue-HBpL5r3V.cjs +0 -2
  416. package/dist/emergency-queue-HBpL5r3V.cjs.map +0 -1
  417. package/dist/errors-D6bwgJtO.js +0 -92
  418. package/dist/errors-D6bwgJtO.js.map +0 -1
  419. package/dist/errors-DCOCRdSi.cjs +0 -3
  420. package/dist/errors-DCOCRdSi.cjs.map +0 -1
  421. package/dist/factory-DLFDjdLv.cjs +0 -2
  422. package/dist/factory-DLFDjdLv.cjs.map +0 -1
  423. package/dist/factory-e9Qo3K0z.js +0 -276
  424. package/dist/factory-e9Qo3K0z.js.map +0 -1
  425. package/dist/guards-Cidk71ME.js +0 -7
  426. package/dist/guards-Cidk71ME.js.map +0 -1
  427. package/dist/guards-nJ70syPt.cjs +0 -2
  428. package/dist/guards-nJ70syPt.cjs.map +0 -1
  429. package/dist/identity-BlvlgjrU.cjs +0 -2
  430. package/dist/identity-BlvlgjrU.cjs.map +0 -1
  431. package/dist/identity-BrQp_5J5.js.map +0 -1
  432. package/dist/indexeddb-storage-CtLvZH1r.cjs +0 -2
  433. package/dist/indexeddb-storage-CtLvZH1r.cjs.map +0 -1
  434. package/dist/indexeddb-storage-DLXQzAGh.js.map +0 -1
  435. package/dist/interactions-B6z2I4tU.js +0 -119
  436. package/dist/interactions-B6z2I4tU.js.map +0 -1
  437. package/dist/interactions-P6pz08Jn.cjs +0 -2
  438. package/dist/interactions-P6pz08Jn.cjs.map +0 -1
  439. package/dist/journey-35yCMNFo.js.map +0 -1
  440. package/dist/journey-DAGh5h9k.cjs +0 -2
  441. package/dist/journey-DAGh5h9k.cjs.map +0 -1
  442. package/dist/keys-BHhw_0Wh.cjs +0 -2
  443. package/dist/keys-BHhw_0Wh.cjs.map +0 -1
  444. package/dist/keys-BU9j5YqW.js +0 -16
  445. package/dist/keys-BU9j5YqW.js.map +0 -1
  446. package/dist/lifecycle-BGGOcN4N.cjs +0 -2
  447. package/dist/lifecycle-BGGOcN4N.cjs.map +0 -1
  448. package/dist/lifecycle-CZ6RRXc6.js.map +0 -1
  449. package/dist/log-record-D7bA1RPb.cjs +0 -2
  450. package/dist/log-record-D7bA1RPb.cjs.map +0 -1
  451. package/dist/log-record-DIA6McNr.js.map +0 -1
  452. package/dist/long-frames-430_85Da.js.map +0 -1
  453. package/dist/long-frames-Dd8tsi2U.cjs +0 -2
  454. package/dist/long-frames-Dd8tsi2U.cjs.map +0 -1
  455. package/dist/models/stats.d.ts +0 -11
  456. package/dist/network-C7SkLf4v.js.map +0 -1
  457. package/dist/network-pEX3PAJv.cjs +0 -2
  458. package/dist/network-pEX3PAJv.cjs.map +0 -1
  459. package/dist/profiler-BVWIOgnq.js.map +0 -1
  460. package/dist/profiler-eVCknCzS.cjs +0 -2
  461. package/dist/profiler-eVCknCzS.cjs.map +0 -1
  462. package/dist/profiler-frames-CLXlT_xL.js.map +0 -1
  463. package/dist/profiler-frames-Dg2OebB2.cjs +0 -2
  464. package/dist/profiler-frames-Dg2OebB2.cjs.map +0 -1
  465. package/dist/remote-rules-BJGDJGwA.js +0 -98
  466. package/dist/remote-rules-BJGDJGwA.js.map +0 -1
  467. package/dist/remote-rules-CJD3ToVk.cjs +0 -2
  468. package/dist/remote-rules-CJD3ToVk.cjs.map +0 -1
  469. package/dist/replay-0zAJv9T3.js +0 -338
  470. package/dist/replay-0zAJv9T3.js.map +0 -1
  471. package/dist/replay-DomJpXqW.cjs +0 -2
  472. package/dist/replay-DomJpXqW.cjs.map +0 -1
  473. package/dist/reports-BsbqmP8h.cjs +0 -2
  474. package/dist/reports-BsbqmP8h.cjs.map +0 -1
  475. package/dist/reports-BuXekPOS.js.map +0 -1
  476. package/dist/resource-timing-CXGHwFRD.js.map +0 -1
  477. package/dist/resource-timing-DkycFGDa.cjs +0 -2
  478. package/dist/resource-timing-DkycFGDa.cjs.map +0 -1
  479. package/dist/sampling-Dd0wllyq.cjs +0 -2
  480. package/dist/sampling-Dd0wllyq.cjs.map +0 -1
  481. package/dist/sampling-UUDbi3K0.js +0 -60
  482. package/dist/sampling-UUDbi3K0.js.map +0 -1
  483. package/dist/sanitize-CNmsD9r3.js.map +0 -1
  484. package/dist/sanitize-ChLn97Ch.cjs.map +0 -1
  485. package/dist/select-CTk-K5mG.cjs +0 -3
  486. package/dist/select-CTk-K5mG.cjs.map +0 -1
  487. package/dist/select-DPv_j6wq.js +0 -270
  488. package/dist/select-DPv_j6wq.js.map +0 -1
  489. package/dist/sender-15zEsZpr.js +0 -857
  490. package/dist/sender-15zEsZpr.js.map +0 -1
  491. package/dist/sender-Bfpv9tad.cjs +0 -2
  492. package/dist/sender-Bfpv9tad.cjs.map +0 -1
  493. package/dist/storage-BA9RqRO-.cjs +0 -2
  494. package/dist/storage-BA9RqRO-.cjs.map +0 -1
  495. package/dist/storage-DZwed89z.js +0 -16
  496. package/dist/storage-DZwed89z.js.map +0 -1
  497. package/dist/storm-BTSNTIWI.js +0 -9
  498. package/dist/storm-BTSNTIWI.js.map +0 -1
  499. package/dist/storm-D0_qZOEg.cjs +0 -2
  500. package/dist/storm-D0_qZOEg.cjs.map +0 -1
  501. package/dist/unclean-exit-ClGzrc2A.cjs +0 -2
  502. package/dist/unclean-exit-ClGzrc2A.cjs.map +0 -1
  503. package/dist/unclean-exit-Cob_jyTv.js.map +0 -1
  504. package/dist/user-timing-CdYqx3PF.cjs +0 -2
  505. package/dist/user-timing-CdYqx3PF.cjs.map +0 -1
  506. package/dist/user-timing-DgHubxCI.js.map +0 -1
  507. package/dist/utils/timer.d.ts +0 -19
  508. package/dist/web-socket-BTuvYoJI.cjs +0 -2
  509. package/dist/web-socket-BTuvYoJI.cjs.map +0 -1
  510. package/dist/web-vitals-Ch5BpDmo.cjs +0 -2
  511. package/dist/web-vitals-Ch5BpDmo.cjs.map +0 -1
  512. package/dist/web-vitals-CsGCWnUr.js.map +0 -1
  513. package/dist/worker-protocol-B0_8rWy5.js.map +0 -1
  514. package/dist/worker-protocol-BjzFORfq.cjs +0 -2
  515. package/dist/worker-protocol-BjzFORfq.cjs.map +0 -1
  516. package/dist/worker-server-4en-Lt-3.cjs +0 -2
  517. package/dist/worker-server-4en-Lt-3.cjs.map +0 -1
  518. package/dist/worker-server-Cne9MX9I.js +0 -83
  519. package/dist/worker-server-Cne9MX9I.js.map +0 -1
  520. package/dist/worker-transport-B-GF4Aqn.cjs +0 -2
  521. package/dist/worker-transport-B-GF4Aqn.cjs.map +0 -1
  522. package/dist/worker-transport-C3SjJAEC.js +0 -200
  523. package/dist/worker-transport-C3SjJAEC.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactions-Byxf1C82.js","names":["NET_CHANGE_ATTRIBUTES","IGNORE_SELECTOR","patch","recordedUrl","forgetWindow","addWindowObserver","_defineProperty","LEAVING_LINKS","ELEMENT_NODE","isElement","value","INITIAL_DOCUMENT_URL","insideLive","live","target","writeAnswers","record","attributeNamespace","attributeName","oldValue","batchAnswers","changes","records","node","each","key","onInitialBlank","win","urlOf","unlisten","type","listener","capture","describeElement","tag","element","testId","label","classAttribute","historyMethods","InteractionCapture","event","from","to","full","fromUrl","urlTransform","toUrl","ctx","restore","settings","options","ignore","attribute","message","data","now","windowMs","count","times","t","reported","reached","action","pageUrl","viewUrl","view","responded","observer","onScroll","views","observedWindows","stop","timer","moved","test","onNavigate","active","restorePushState","args","original","restoreReplaceState"],"sources":["../src/capture/interactions.ts"],"sourcesContent":["// src/capture/interactions.ts\n//\n// Captures clicks and in-page navigations as breadcrumbs and trace boundaries. Also detects\n// rage clicks and dead clicks.\n\nimport {\n ACTION_ATTRIBUTE_DEFAULT,\n ARIA_LABEL_MAX_CHARS,\n CLICK_TEXT_MAX_CHARS,\n DEAD_CLICK_CONTROLS,\n DEAD_CLICK_IGNORE_SELECTOR,\n DEAD_CLICK_MS,\n IGNORE_SELECTOR,\n NET_CHANGE_ATTRIBUTES,\n RAGE_CLICK_COUNT,\n RAGE_CLICK_WINDOW_MS,\n SELECTOR_MAX_CLASSES,\n} from \"../constants\";\nimport type { InteractionOptions } from \"../models/config\";\nimport { patch } from \"../utils/patch\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { addWindowObserver, forgetWindow, observedWindows } from \"./observed-windows\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Links that open elsewhere. The page shows no response, but the click isn't dead. */\nconst LEAVING_LINKS = 'a[target=\"_blank\"], a[download]';\n\n/** An element's nodeType. Node.ELEMENT_NODE won't do, because another window has its own Node. */\nconst ELEMENT_NODE = 1;\n\n/**\n * Checks whether a value is an element of any window. instanceof fails for a popout's element,\n * because each window has its own Element class.\n * @param value An event or mutation target.\n * @returns True for an element.\n */\nfunction isElement(value: unknown): value is Element {\n return (value as Partial<Node> | null)?.nodeType === ELEMENT_NODE;\n}\n\n/** The page's initial document in a window that window.open() just made. */\nconst INITIAL_DOCUMENT_URL = \"about:blank\";\n\n/**\n * Checks whether a node or a scroll target sits inside a live region. A removed node is detached\n * by the time the observer runs, so for it closest() can only test the node itself.\n * @param target The node, or the scroll's target.\n * @param live Selector of the live regions. \"\" marks nothing.\n * @returns True if the target is inside a live region.\n * @throws SyntaxError for a selector the browser can't parse. Call it inside a diagnostics guard.\n */\nfunction insideLive(target: EventTarget | null, live: string): boolean {\n if (!live) {\n return false;\n }\n\n // A text change targets a Text node, and the document and the window have no closest().\n const element = isElement(target)\n ? target\n : ((target as Partial<Node> | null)?.parentElement ?? null);\n return Boolean(element?.closest(live));\n}\n\n/**\n * Checks whether an attribute or a text node now differs from a record's old value.\n * @param record An attributes or characterData change.\n * @returns True if the current value differs from the record's old value.\n */\nfunction writeAnswers(record: MutationRecord): boolean {\n if (record.type === \"characterData\") {\n return (record.target as CharacterData).data !== record.oldValue;\n }\n\n // An attributes record always names its attribute.\n const { attributeName, attributeNamespace, oldValue } = record as MutationRecord & {\n attributeName: string;\n };\n return (record.target as Element).getAttributeNS(attributeNamespace, attributeName) !== oldValue;\n}\n\n/** What one observer batch did to one node. */\ninterface NodeChanges {\n /** The net-change attributes and the text data whose first record the batch has checked. */\n checked: Set<string>;\n /** True if a live element was added under this node. */\n added: boolean;\n /** True if a live element was removed from under this node. */\n removed: boolean;\n}\n\n/**\n * Checks whether one observer batch answers a click. A change inside a live region doesn't, and\n * neither does a write that keeps the old value. A batch that sets `name` or `type`, or a text's\n * data, and then puts the old value back doesn't either, because React rewrites an input that\n * way. Any other attribute answers at each write with a new value, even if a later write puts\n * the old one back, because a class or style change around a forced layout restarts an\n * animation, which the user sees. A grid that swaps a live element for a new one under the same\n * parent doesn't answer. A live element that only appears or only goes away does, because a\n * click can show or hide it.\n * @param records The batch.\n * @param live Selector of the live regions.\n * @returns True if a change in the batch answers the click.\n * @throws SyntaxError for a selector the browser can't parse. Call it inside a diagnostics guard.\n */\nfunction batchAnswers(records: readonly MutationRecord[], live: string): boolean {\n const changes = new Map<Node, NodeChanges>();\n for (const record of records) {\n if (insideLive(record.target, live)) {\n continue;\n }\n\n let node = changes.get(record.target);\n if (!node) {\n node = { checked: new Set(), added: false, removed: false };\n changes.set(record.target, node);\n }\n\n if (record.type === \"childList\") {\n const nodes = [...record.addedNodes, ...record.removedNodes];\n if (!nodes.every((each) => isElement(each) && insideLive(each, live))) {\n return true;\n }\n // A browser can report one swap as one record or as two, so count the sides per parent.\n node.added ||= record.addedNodes.length > 0;\n node.removed ||= record.removedNodes.length > 0;\n continue;\n }\n\n if (record.type === \"attributes\") {\n // An attributes record always names its attribute.\n const { attributeName } = record as MutationRecord & { attributeName: string };\n if (!NET_CHANGE_ATTRIBUTES.includes(attributeName)) {\n if (writeAnswers(record)) {\n return true;\n }\n continue;\n }\n }\n\n // Only the first record's old value is the value before the batch. The namespace keeps an\n // SVG type apart from xlink:type, and a text's data has a null name, unlike any attribute.\n const key = JSON.stringify([record.attributeNamespace, record.attributeName]);\n if (node.checked.has(key)) {\n continue;\n }\n node.checked.add(key);\n if (writeAnswers(record)) {\n return true;\n }\n }\n\n return [...changes.values()].some((node) => node.added !== node.removed);\n}\n\n/**\n * Checks whether an open window still shows the about:blank that window.open() starts with. A\n * window that turned cross-origin throws, and that's the expected answer. The fallback is false,\n * so the caller forgets the window and no throw reaches the page from its pagehide.\n * @param win The window.\n * @returns True for an open window on its initial about:blank.\n */\nfunction onInitialBlank(win: Window): boolean {\n try {\n return win.document.URL === INITIAL_DOCUMENT_URL && !win.closed;\n } catch {\n return false;\n }\n}\n\n/**\n * Reads a window's URL. A window that turned cross-origin throws, and that's the expected answer.\n * The fallback is \"\", so the URL counts as changed.\n * @param win The window.\n * @returns The URL, or \"\" when the window can't be read.\n */\nfunction urlOf(win: Window): string {\n try {\n return win.location.href;\n } catch {\n return \"\";\n }\n}\n\n/**\n * Removes one listener from a window. A window that turned cross-origin throws, and that's the\n * expected answer. It holds no listener of ours, so the fallback is to remove nothing.\n * @param win The window.\n * @param type The event type.\n * @param listener The listener.\n * @param capture True for a capture-phase listener.\n */\nfunction unlisten(win: Window, type: string, listener: EventListener, capture = false): void {\n try {\n win.removeEventListener(type, listener, capture);\n } catch {\n // Nothing to remove. The listener went with the document the window left.\n }\n}\n\n/**\n * Builds a short CSS selector for an element. Prefers the test ID, then the ID, then the\n * aria-label, then the class names.\n * @param element Target DOM element.\n * @returns The selector.\n */\nfunction describeElement(element: Element): string {\n const tag = element.tagName.toLowerCase();\n\n const testId = element.getAttribute(\"data-testid\") ?? element.getAttribute(\"data-test-id\");\n if (testId !== null) {\n return `[data-testid=\"${testId}\"]`;\n }\n if (element.id !== \"\") {\n return `#${element.id}`;\n }\n\n const label = element.getAttribute(\"aria-label\");\n if (label !== null) {\n return `${tag}[aria-label=\"${label.slice(0, ARIA_LABEL_MAX_CHARS)}\"]`;\n }\n\n // Read the class through getAttribute. On an SVG element, `className` is an\n // SVGAnimatedString, and slicing it throws.\n const classAttribute = element.getAttribute(\"class\")?.trim() ?? \"\";\n if (classAttribute === \"\") {\n return tag;\n }\n\n const classes = classAttribute.split(/\\s+/).slice(0, SELECTOR_MAX_CLASSES).join(\".\");\n return `${tag}.${classes}`;\n}\n\n/**\n * The two History members this module replaces. They are declared as properties, not\n * methods, so the original functions stay unbound. With a bound copy, uninstall would\n * restore a different function from the one it replaced, and every install cycle would\n * stack one more bind on top of the last.\n */\ninterface HistoryMethods {\n pushState: (this: History, ...args: never[]) => void;\n replaceState: (this: History, ...args: never[]) => void;\n}\n\n/**\n * Returns the History object, typed so that its methods stay unbound.\n * @returns The global history.\n */\nfunction historyMethods(): HistoryMethods {\n return history;\n}\n\n/** Captures user clicks and single-page navigations. */\nexport class InteractionCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"interactions\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /** Restore functions for the history wrappers. */\n private readonly restores: (() => void)[] = [];\n\n /** The URL before the latest navigation. */\n private lastUrl = \"\";\n\n /** The element of the current click burst, and when each of its clicks happened. */\n private burst: { target: Element | null; times: number[]; reported: boolean } = {\n target: null,\n times: [],\n reported: false,\n };\n\n /** Stops the dead click check that is running now. */\n private stopDeadCheck: (() => void) | undefined;\n\n /** Detaches the observed windows. Set while clicks are captured. */\n private unobserve: (() => void) | undefined;\n\n /**\n * @param ctx Capture context: configuration, diagnostics, logger, breadcrumbs and tracing.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Registers click listeners and patches history navigation APIs. */\n install(): void {\n if (this.installed || typeof document === \"undefined\") {\n return;\n }\n this.installed = true;\n this.lastUrl = location.href;\n\n if (this.ctx.config.capture.interactions) {\n // In the capture phase we see the click before a page handler can stop propagation.\n addEventListener(\"click\", this.onClick, true);\n // The app's observed windows outlive this capture, so one observed before the install\n // gets attached here.\n this.unobserve = addWindowObserver({\n attach: (win) => this.attachView(win),\n detach: (win) => {\n this.detachView(win);\n },\n });\n }\n if (this.ctx.config.capture.navigation) {\n this.installHistory();\n addEventListener(\"popstate\", this.onNavigate);\n addEventListener(\"hashchange\", this.onNavigate);\n }\n }\n\n /**\n * Removes the interaction listeners and restores every history method that still holds our\n * wrapper. A wrapper that another script wrapped again stays in place and records nothing.\n */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n removeEventListener(\"click\", this.onClick, true);\n removeEventListener(\"popstate\", this.onNavigate);\n removeEventListener(\"hashchange\", this.onNavigate);\n // Restore history first. An observed window is another document, and a fault there mustn't\n // leave this page patched.\n for (const restore of this.restores.splice(0)) {\n restore();\n }\n this.unobserve?.();\n this.unobserve = undefined;\n\n this.stopDeadCheck?.();\n this.burst = { target: null, times: [], reported: false };\n }\n\n /** Records a click. The browser calls this directly, so a throw would be a page error. */\n private readonly onClick = (event: Event): void => {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a click. It skips that click.\",\n () => {\n this.recordClick(event);\n },\n );\n };\n\n /**\n * Rotates the trace context, records a click breadcrumb and runs the rage and dead click checks.\n * @param event The click.\n */\n private recordClick(event: Event): void {\n if (this.ctx.isActive?.() === false) {\n return;\n }\n const target = event.target;\n if (!isElement(target)) {\n return;\n }\n const settings = this.ctx.config.capture.interactions;\n const options = typeof settings === \"object\" ? settings : {};\n const ignore = options.ignoreSelector === undefined ? IGNORE_SELECTOR : options.ignoreSelector;\n if (ignore && target.closest(ignore)) {\n return;\n }\n // A missing or empty attribute gives \"\", and the message is then \"unknown-click\".\n const attribute = options.actionAttribute ?? ACTION_ATTRIBUTE_DEFAULT;\n const action = target.closest(`[${attribute}]`)?.getAttribute(attribute) ?? \"\";\n const message = (action || \"unknown-click\").slice(0, this.ctx.config.limits.maxBodyChars);\n const data: Record<string, unknown> = {};\n if (options.selector) {\n data.selector = describeElement(target);\n }\n if (options.text) {\n data.text = target.textContent.trim().slice(0, options.maxTextChars ?? CLICK_TEXT_MAX_CHARS);\n }\n this.ctx.tracing.rotate(\"interaction\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"click\",\n message,\n data: Object.keys(data).length > 0 ? data : undefined,\n });\n\n if (options.rageClicks) {\n this.countRage(target, message, options);\n }\n if (\n options.deadClicks &&\n target.closest(`${DEAD_CLICK_CONTROLS}, [${attribute}]`) &&\n !target.closest(LEAVING_LINKS)\n ) {\n // The listener sits on the window that got the click, the page's own or an observed one.\n this.watchDead(message, options, event.currentTarget as Window);\n }\n }\n\n /**\n * Counts the clicks on one element and records `ui.rage_click` once per burst.\n * @param target Clicked element.\n * @param action The click's action name.\n * @param options Interaction options.\n */\n private countRage(target: Element, action: string, options: InteractionOptions): void {\n const now = Date.now();\n const windowMs = options.rageClickWindowMs ?? RAGE_CLICK_WINDOW_MS;\n const count = options.rageClickCount ?? RAGE_CLICK_COUNT;\n const times =\n this.burst.target === target ? this.burst.times.filter((t) => now - t < windowMs) : [];\n // A burst only ends once no click is left in the window, so clicks that keep sliding\n // through it don't fire a second event.\n const reported = times.length > 0 && this.burst.reported;\n times.push(now);\n const reached = times.length >= count;\n this.burst = { target, times, reported: reported || reached };\n\n if (reached && !reported) {\n this.ctx.logger.logEvent(\"ui.rage_click\", { \"click.action\": action, \"click.count\": count });\n }\n }\n\n /**\n * Watches the page and each observed window after a click on a control. If there's no DOM\n * change, URL change or scroll within `deadClickMs`, it records `ui.dead_click`. Only one\n * check runs at a time.\n * @param action The click's action name.\n * @param options Interaction options.\n * @param view The window that got the click. Its URL change answers the click too.\n */\n private watchDead(action: string, options: InteractionOptions, view: Window): void {\n if (this.stopDeadCheck || typeof MutationObserver === \"undefined\") {\n return;\n }\n\n const pageUrl = location.href;\n const viewUrl = urlOf(view);\n const live = options.deadClickIgnoreSelector ?? DEAD_CLICK_IGNORE_SELECTOR;\n let responded = false;\n const observer = new MutationObserver((records) => {\n responded ||= this.answers(() => batchAnswers(records, live));\n });\n const onScroll = (event: Event): void => {\n responded ||= this.answers(() => !insideLive(event.target, live));\n };\n // A click in a popout can change this page, and a click here can change a popout.\n const views: Window[] = [];\n for (const each of [window, ...observedWindows()]) {\n try {\n // The old values let a same-value write count as no change.\n observer.observe(each.document, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeOldValue: true,\n characterData: true,\n characterDataOldValue: true,\n });\n each.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n views.push(each);\n } catch {\n // A window that turned cross-origin throws, and that's the expected answer. The fallback\n // skips it and forgets it, because the library can't watch it anymore.\n forgetWindow(each);\n }\n }\n\n const stop = (): void => {\n // timer is declared after stop, but stop can only run once that line has executed.\n clearTimeout(timer);\n observer.disconnect();\n for (const each of views) {\n unlisten(each, \"scroll\", onScroll, true);\n }\n this.stopDeadCheck = undefined;\n };\n const timer = setTimeout(() => {\n stop();\n const moved = location.href !== pageUrl || urlOf(view) !== viewUrl;\n if (!responded && !moved && this.ctx.isActive?.() !== false) {\n this.ctx.logger.logEvent(\"ui.dead_click\", { \"click.action\": action });\n }\n }, options.deadClickMs ?? DEAD_CLICK_MS);\n this.stopDeadCheck = stop;\n }\n\n /**\n * Runs one dead click test in a guard. A failed test counts as an answer, so a fault can't make\n * up a dead click. The browser calls the observer and the listener directly, so a throw would\n * be a page error.\n * @param test Returns true if a change answers the click.\n * @returns The test's result, or true if it threw.\n */\n private answers(test: () => boolean): boolean {\n return (\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not check a page change for a dead click. It counts the change as a response.\",\n test,\n ) ?? true\n );\n }\n\n /**\n * Starts listening for clicks in an observed window.\n * @param win The window.\n * @returns False for a window from another origin, after it reports the window.\n */\n private attachView(win: Window): boolean {\n try {\n // Only a window of this origin has a readable document. Reading it first means a window\n // from another origin throws before it gets a listener.\n const _sameOrigin = win.document;\n win.addEventListener(\"click\", this.onClick, true);\n win.addEventListener(\"pagehide\", this.onViewHide);\n return true;\n } catch {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The library cannot observe a window from another origin. It captures no clicks there.\",\n );\n return false;\n }\n }\n\n /**\n * Stops listening in an observed window. A running dead click check stops too, without a\n * record, because it holds a listener in this window. A window that leaves during the check\n * has most often answered the click, for example a popout that docks back into the page.\n * @param win The window.\n */\n private detachView(win: Window): void {\n this.stopDeadCheck?.();\n unlisten(win, \"click\", this.onClick, true);\n unlisten(win, \"pagehide\", this.onViewHide);\n }\n\n /** Forgets an observed window when its page goes away, so the library doesn't hold it. */\n private readonly onViewHide = (event: Event): void => {\n const win = event.currentTarget as Window;\n // window.open(url) starts on about:blank and fires pagehide there. Then it loads a page of\n // this origin into the same window, which keeps our listeners, so forgetting it would lose it.\n if (onInitialBlank(win)) {\n return;\n }\n\n forgetWindow(win);\n };\n\n /** On a URL change, rotates the trace context and records a breadcrumb and an event. */\n private readonly onNavigate = (): void => {\n const from = this.lastUrl;\n const to = location.href;\n if (from === to) {\n return;\n }\n this.lastUrl = to;\n if (this.ctx.isActive?.() === false) {\n return;\n }\n\n // The comparison above uses the full URL, so a query-only change still counts as a\n // navigation. The record doesn't keep the query unless you set fullUrls.\n const full = this.ctx.config.capture.fullUrls;\n const { urlTransform } = this.ctx.config.capture;\n const fromUrl = recordedUrl(from, full, urlTransform, this.ctx.diagnostics);\n const toUrl = recordedUrl(to, full, urlTransform, this.ctx.diagnostics);\n\n this.ctx.tracing.rotate(\"navigation\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"navigation\",\n message: `${fromUrl} -> ${toUrl}`,\n });\n\n // The event carries only the previous URL, and the record builder adds the current one as\n // `page.url`. Putting the new URL in `url.full` would make a navigation look like an HTTP\n // request.\n this.ctx.logger.logEvent(\"NAVIGATION\", { \"page.url.previous\": fromUrl });\n };\n\n /** Patches History.pushState and replaceState to observe programmatic navigations. */\n private installHistory(): void {\n if (typeof history === \"undefined\") {\n return;\n }\n\n // Wrap the instance, not History.prototype. Reading from the prototype would skip a patch\n // that a router installed on the instance. patch keeps the originals unbound.\n const target = historyMethods();\n const onNavigate = this.onNavigate;\n // Uninstall clears the flag, so a wrapper that stays in place only calls the original.\n let active = true;\n\n const restorePushState = patch(\n target,\n \"pushState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n // Queue the handler. The browser only updates location.href after the call returns,\n // so a synchronous read would report the previous URL as the new one.\n if (active) {\n queueMicrotask(onNavigate);\n }\n },\n );\n\n const restoreReplaceState = patch(\n target,\n \"replaceState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n if (active) {\n queueMicrotask(onNavigate);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I,YAAY,MACnB,yBACA,mGACAG,CACF,KAAK;CAET;CAOA,WAAmB,GAAsB;EACvC,IAAI;GAMF,OAHoBhD,EAAI,UACxBA,EAAI,iBAAiB,SAAS,KAAK,SAAS,EAAI,GAChDA,EAAI,iBAAiB,YAAY,KAAK,UAAU,GACzC;EACT,QAAQ;GAKN,OAJA,KAAK,IAAI,YAAY,OACnB,0BACA,uFACF,GACO;EACT;CACF;CAQA,WAAmB,GAAmB;EAGpC,AAFA,KAAK,gBAAgB,GACrBE,EAASF,GAAK,SAAS,KAAK,SAAS,EAAI,GACzCE,EAASF,GAAK,YAAY,KAAK,UAAU;CAC3C;CA+CA,iBAA+B;EAC7B,IAAI,OAAO,UAAY,KACrB;EAKF,IAAMb,IAASyB,EAAe,GACxBqC,IAAa,KAAK,YAEpBC,IAAS,IAEPC,IAAmB5E,EACvBY,GACA,cACC,MACC,SAAyB,GAAGiE,GAAqB;GAI/C,AAHAC,EAAS,MAAM,MAAMD,CAAI,GAGrBF,KACF,eAAeD,CAAU;EAE7B,CACJ,GAEMK,IAAsB/E,EAC1BY,GACA,iBACC,MACC,SAAyB,GAAGiE,GAAqB;GAE/C,AADAC,EAAS,MAAM,MAAMD,CAAI,GACrBF,KACF,eAAeD,CAAU;EAE7B,CACJ;EAEA,KAAK,SAAS,WAAW;GAGvB,AAFA,IAAS,IACTE,EAAiB,GACjBG,EAAoB;EACtB,CAAC;CACH;AACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("./constants-CtF52hIV.cjs"),t=require("./patch-BX8KrPCT.cjs"),n=require("./platform-BqRc-7RO.cjs"),r=require("./observed-windows-B3gJkdql.cjs"),i=require("./defineProperty-X1c4tIPD.cjs");var a=`a[target="_blank"], a[download]`,o=1;function s(e){return e?.nodeType===o}var c=`about:blank`;function l(e,t){return t?!!(s(e)?e:e?.parentElement??null)?.closest(t):!1}function u(e){if(e.type===`characterData`)return e.target.data!==e.oldValue;let{attributeName:t,attributeNamespace:n,oldValue:r}=e;return e.target.getAttributeNS(n,t)!==r}function d(t,n){let r=new Map;for(let i of t){if(l(i.target,n))continue;let t=r.get(i.target);if(t||(t={checked:new Set,added:!1,removed:!1},r.set(i.target,t)),i.type===`childList`){if(![...i.addedNodes,...i.removedNodes].every(e=>s(e)&&l(e,n)))return!0;t.added||=i.addedNodes.length>0,t.removed||=i.removedNodes.length>0;continue}if(i.type===`attributes`){let{attributeName:t}=i;if(!e.Kt.includes(t)){if(u(i))return!0;continue}}let a=JSON.stringify([i.attributeNamespace,i.attributeName]);if(!t.checked.has(a)&&(t.checked.add(a),u(i)))return!0}return[...r.values()].some(e=>e.added!==e.removed)}function f(e){try{return e.document.URL===c&&!e.closed}catch{return!1}}function p(e){try{return e.location.href}catch{return``}}function m(e,t,n,r=!1){try{e.removeEventListener(t,n,r)}catch{}}function h(e){let t=e.tagName.toLowerCase(),n=e.getAttribute(`data-testid`)??e.getAttribute(`data-test-id`);if(n!==null)return`[data-testid="${n}"]`;if(e.id!==``)return`#${e.id}`;let r=e.getAttribute(`aria-label`);if(r!==null)return`${t}[aria-label="${r.slice(0,40)}"]`;let i=e.getAttribute(`class`)?.trim()??``;return i===``?t:`${t}.${i.split(/\s+/).slice(0,2).join(`.`)}`}function g(){return history}var _=class{constructor(e){i.t(this,`ctx`,void 0),i.t(this,`name`,`interactions`),i.t(this,`installed`,!1),i.t(this,`restores`,[]),i.t(this,`lastUrl`,``),i.t(this,`burst`,{target:null,times:[],reported:!1}),i.t(this,`stopDeadCheck`,void 0),i.t(this,`unobserve`,void 0),i.t(this,`onClick`,e=>{this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record a click. It skips that click.`,()=>{this.recordClick(e)})}),i.t(this,`onViewHide`,e=>{let t=e.currentTarget;f(t)||r.n(t)}),i.t(this,`onNavigate`,()=>{let e=this.lastUrl,t=location.href;if(e===t||(this.lastUrl=t,this.ctx.isActive?.()===!1))return;let r=this.ctx.config.capture.fullUrls,{urlTransform:i}=this.ctx.config.capture,a=n.i(e,r,i,this.ctx.diagnostics),o=n.i(t,r,i,this.ctx.diagnostics);this.ctx.tracing.rotate(`navigation`),this.ctx.breadcrumbs.push({t:Date.now(),category:`navigation`,message:`${a} -> ${o}`}),this.ctx.logger.logEvent(`NAVIGATION`,{"page.url.previous":a})}),this.ctx=e}install(){this.installed||typeof document>`u`||(this.installed=!0,this.lastUrl=location.href,this.ctx.config.capture.interactions&&(addEventListener(`click`,this.onClick,!0),this.unobserve=r.t({attach:e=>this.attachView(e),detach:e=>{this.detachView(e)}})),this.ctx.config.capture.navigation&&(this.installHistory(),addEventListener(`popstate`,this.onNavigate),addEventListener(`hashchange`,this.onNavigate)))}uninstall(){if(this.installed){this.installed=!1,removeEventListener(`click`,this.onClick,!0),removeEventListener(`popstate`,this.onNavigate),removeEventListener(`hashchange`,this.onNavigate);for(let e of this.restores.splice(0))e();this.unobserve?.(),this.unobserve=void 0,this.stopDeadCheck?.(),this.burst={target:null,times:[],reported:!1}}}recordClick(t){if(this.ctx.isActive?.()===!1)return;let n=t.target;if(!s(n))return;let r=this.ctx.config.capture.interactions,i=typeof r==`object`?r:{},o=i.ignoreSelector===void 0?e.yt:i.ignoreSelector;if(o&&n.closest(o))return;let c=i.actionAttribute??`data-observability-action`,l=((n.closest(`[${c}]`)?.getAttribute(c)??``)||`unknown-click`).slice(0,this.ctx.config.limits.maxBodyChars),u={};i.selector&&(u.selector=h(n)),i.text&&(u.text=n.textContent.trim().slice(0,i.maxTextChars??50)),this.ctx.tracing.rotate(`interaction`),this.ctx.breadcrumbs.push({t:Date.now(),category:`click`,message:l,data:Object.keys(u).length>0?u:void 0}),i.rageClicks&&this.countRage(n,l,i),i.deadClicks&&n.closest(`a, button, summary, input[type="button"], input[type="submit"], input[type="reset"], [role="button"], [role="link"], [role="menuitem"], [role="tab"], [${c}]`)&&!n.closest(a)&&this.watchDead(l,i,t.currentTarget)}countRage(e,t,n){let r=Date.now(),i=n.rageClickWindowMs??1e3,a=n.rageClickCount??3,o=this.burst.target===e?this.burst.times.filter(e=>r-e<i):[],s=o.length>0&&this.burst.reported;o.push(r);let c=o.length>=a;this.burst={target:e,times:o,reported:s||c},c&&!s&&this.ctx.logger.logEvent(`ui.rage_click`,{"click.action":t,"click.count":a})}watchDead(e,t,n){if(this.stopDeadCheck||typeof MutationObserver>`u`)return;let i=location.href,a=p(n),o=t.deadClickIgnoreSelector??`[data-observability-live]`,s=!1,c=new MutationObserver(e=>{s||=this.answers(()=>d(e,o))}),u=e=>{s||=this.answers(()=>!l(e.target,o))},f=[];for(let e of[window,...r.i()])try{c.observe(e.document,{subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,characterData:!0,characterDataOldValue:!0}),e.addEventListener(`scroll`,u,{capture:!0,passive:!0}),f.push(e)}catch{r.n(e)}let h=()=>{clearTimeout(g),c.disconnect();for(let e of f)m(e,`scroll`,u,!0);this.stopDeadCheck=void 0},g=setTimeout(()=>{h();let t=location.href!==i||p(n)!==a;!s&&!t&&this.ctx.isActive?.()!==!1&&this.ctx.logger.logEvent(`ui.dead_click`,{"click.action":e})},t.deadClickMs??1e3);this.stopDeadCheck=h}answers(e){return this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not check a page change for a dead click. It counts the change as a response.`,e)??!0}attachView(e){try{return e.document,e.addEventListener(`click`,this.onClick,!0),e.addEventListener(`pagehide`,this.onViewHide),!0}catch{return this.ctx.diagnostics.report(`capture.install_failed`,`The library cannot observe a window from another origin. It captures no clicks there.`),!1}}detachView(e){this.stopDeadCheck?.(),m(e,`click`,this.onClick,!0),m(e,`pagehide`,this.onViewHide)}installHistory(){if(typeof history>`u`)return;let e=g(),n=this.onNavigate,r=!0,i=t.t(e,`pushState`,e=>function(...t){e.apply(this,t),r&&queueMicrotask(n)}),a=t.t(e,`replaceState`,e=>function(...t){e.apply(this,t),r&&queueMicrotask(n)});this.restores.push(()=>{r=!1,i(),a()})}};exports.InteractionCapture=_;
2
+ //# sourceMappingURL=interactions-OK85T-Dk.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactions-OK85T-Dk.cjs","names":["NET_CHANGE_ATTRIBUTES","recordedUrl","addWindowObserver","IGNORE_SELECTOR","observedWindows","patch","require_constants","require_patch","require_platform","require_observed_windows","require_defineProperty","LEAVING_LINKS","ELEMENT_NODE","isElement","value","INITIAL_DOCUMENT_URL","insideLive","live","target","writeAnswers","record","attributeNamespace","attributeName","oldValue","batchAnswers","changes","records","node","each","key","onInitialBlank","win","urlOf","unlisten","type","listener","capture","describeElement","tag","element","testId","label","classAttribute","historyMethods","InteractionCapture","event","from","to","full","fromUrl","urlTransform","toUrl","ctx","restore","settings","options","ignore","attribute","message","data","now","windowMs","count","times","t","reported","reached","action","pageUrl","viewUrl","view","responded","observer","onScroll","views","stop","timer","moved","test","onNavigate","active","restorePushState","args","original","restoreReplaceState"],"sources":["../src/capture/interactions.ts"],"sourcesContent":["// src/capture/interactions.ts\n//\n// Captures clicks and in-page navigations as breadcrumbs and trace boundaries. Also detects\n// rage clicks and dead clicks.\n\nimport {\n ACTION_ATTRIBUTE_DEFAULT,\n ARIA_LABEL_MAX_CHARS,\n CLICK_TEXT_MAX_CHARS,\n DEAD_CLICK_CONTROLS,\n DEAD_CLICK_IGNORE_SELECTOR,\n DEAD_CLICK_MS,\n IGNORE_SELECTOR,\n NET_CHANGE_ATTRIBUTES,\n RAGE_CLICK_COUNT,\n RAGE_CLICK_WINDOW_MS,\n SELECTOR_MAX_CLASSES,\n} from \"../constants\";\nimport type { InteractionOptions } from \"../models/config\";\nimport { patch } from \"../utils/patch\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { addWindowObserver, forgetWindow, observedWindows } from \"./observed-windows\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Links that open elsewhere. The page shows no response, but the click isn't dead. */\nconst LEAVING_LINKS = 'a[target=\"_blank\"], a[download]';\n\n/** An element's nodeType. Node.ELEMENT_NODE won't do, because another window has its own Node. */\nconst ELEMENT_NODE = 1;\n\n/**\n * Checks whether a value is an element of any window. instanceof fails for a popout's element,\n * because each window has its own Element class.\n * @param value An event or mutation target.\n * @returns True for an element.\n */\nfunction isElement(value: unknown): value is Element {\n return (value as Partial<Node> | null)?.nodeType === ELEMENT_NODE;\n}\n\n/** The page's initial document in a window that window.open() just made. */\nconst INITIAL_DOCUMENT_URL = \"about:blank\";\n\n/**\n * Checks whether a node or a scroll target sits inside a live region. A removed node is detached\n * by the time the observer runs, so for it closest() can only test the node itself.\n * @param target The node, or the scroll's target.\n * @param live Selector of the live regions. \"\" marks nothing.\n * @returns True if the target is inside a live region.\n * @throws SyntaxError for a selector the browser can't parse. Call it inside a diagnostics guard.\n */\nfunction insideLive(target: EventTarget | null, live: string): boolean {\n if (!live) {\n return false;\n }\n\n // A text change targets a Text node, and the document and the window have no closest().\n const element = isElement(target)\n ? target\n : ((target as Partial<Node> | null)?.parentElement ?? null);\n return Boolean(element?.closest(live));\n}\n\n/**\n * Checks whether an attribute or a text node now differs from a record's old value.\n * @param record An attributes or characterData change.\n * @returns True if the current value differs from the record's old value.\n */\nfunction writeAnswers(record: MutationRecord): boolean {\n if (record.type === \"characterData\") {\n return (record.target as CharacterData).data !== record.oldValue;\n }\n\n // An attributes record always names its attribute.\n const { attributeName, attributeNamespace, oldValue } = record as MutationRecord & {\n attributeName: string;\n };\n return (record.target as Element).getAttributeNS(attributeNamespace, attributeName) !== oldValue;\n}\n\n/** What one observer batch did to one node. */\ninterface NodeChanges {\n /** The net-change attributes and the text data whose first record the batch has checked. */\n checked: Set<string>;\n /** True if a live element was added under this node. */\n added: boolean;\n /** True if a live element was removed from under this node. */\n removed: boolean;\n}\n\n/**\n * Checks whether one observer batch answers a click. A change inside a live region doesn't, and\n * neither does a write that keeps the old value. A batch that sets `name` or `type`, or a text's\n * data, and then puts the old value back doesn't either, because React rewrites an input that\n * way. Any other attribute answers at each write with a new value, even if a later write puts\n * the old one back, because a class or style change around a forced layout restarts an\n * animation, which the user sees. A grid that swaps a live element for a new one under the same\n * parent doesn't answer. A live element that only appears or only goes away does, because a\n * click can show or hide it.\n * @param records The batch.\n * @param live Selector of the live regions.\n * @returns True if a change in the batch answers the click.\n * @throws SyntaxError for a selector the browser can't parse. Call it inside a diagnostics guard.\n */\nfunction batchAnswers(records: readonly MutationRecord[], live: string): boolean {\n const changes = new Map<Node, NodeChanges>();\n for (const record of records) {\n if (insideLive(record.target, live)) {\n continue;\n }\n\n let node = changes.get(record.target);\n if (!node) {\n node = { checked: new Set(), added: false, removed: false };\n changes.set(record.target, node);\n }\n\n if (record.type === \"childList\") {\n const nodes = [...record.addedNodes, ...record.removedNodes];\n if (!nodes.every((each) => isElement(each) && insideLive(each, live))) {\n return true;\n }\n // A browser can report one swap as one record or as two, so count the sides per parent.\n node.added ||= record.addedNodes.length > 0;\n node.removed ||= record.removedNodes.length > 0;\n continue;\n }\n\n if (record.type === \"attributes\") {\n // An attributes record always names its attribute.\n const { attributeName } = record as MutationRecord & { attributeName: string };\n if (!NET_CHANGE_ATTRIBUTES.includes(attributeName)) {\n if (writeAnswers(record)) {\n return true;\n }\n continue;\n }\n }\n\n // Only the first record's old value is the value before the batch. The namespace keeps an\n // SVG type apart from xlink:type, and a text's data has a null name, unlike any attribute.\n const key = JSON.stringify([record.attributeNamespace, record.attributeName]);\n if (node.checked.has(key)) {\n continue;\n }\n node.checked.add(key);\n if (writeAnswers(record)) {\n return true;\n }\n }\n\n return [...changes.values()].some((node) => node.added !== node.removed);\n}\n\n/**\n * Checks whether an open window still shows the about:blank that window.open() starts with. A\n * window that turned cross-origin throws, and that's the expected answer. The fallback is false,\n * so the caller forgets the window and no throw reaches the page from its pagehide.\n * @param win The window.\n * @returns True for an open window on its initial about:blank.\n */\nfunction onInitialBlank(win: Window): boolean {\n try {\n return win.document.URL === INITIAL_DOCUMENT_URL && !win.closed;\n } catch {\n return false;\n }\n}\n\n/**\n * Reads a window's URL. A window that turned cross-origin throws, and that's the expected answer.\n * The fallback is \"\", so the URL counts as changed.\n * @param win The window.\n * @returns The URL, or \"\" when the window can't be read.\n */\nfunction urlOf(win: Window): string {\n try {\n return win.location.href;\n } catch {\n return \"\";\n }\n}\n\n/**\n * Removes one listener from a window. A window that turned cross-origin throws, and that's the\n * expected answer. It holds no listener of ours, so the fallback is to remove nothing.\n * @param win The window.\n * @param type The event type.\n * @param listener The listener.\n * @param capture True for a capture-phase listener.\n */\nfunction unlisten(win: Window, type: string, listener: EventListener, capture = false): void {\n try {\n win.removeEventListener(type, listener, capture);\n } catch {\n // Nothing to remove. The listener went with the document the window left.\n }\n}\n\n/**\n * Builds a short CSS selector for an element. Prefers the test ID, then the ID, then the\n * aria-label, then the class names.\n * @param element Target DOM element.\n * @returns The selector.\n */\nfunction describeElement(element: Element): string {\n const tag = element.tagName.toLowerCase();\n\n const testId = element.getAttribute(\"data-testid\") ?? element.getAttribute(\"data-test-id\");\n if (testId !== null) {\n return `[data-testid=\"${testId}\"]`;\n }\n if (element.id !== \"\") {\n return `#${element.id}`;\n }\n\n const label = element.getAttribute(\"aria-label\");\n if (label !== null) {\n return `${tag}[aria-label=\"${label.slice(0, ARIA_LABEL_MAX_CHARS)}\"]`;\n }\n\n // Read the class through getAttribute. On an SVG element, `className` is an\n // SVGAnimatedString, and slicing it throws.\n const classAttribute = element.getAttribute(\"class\")?.trim() ?? \"\";\n if (classAttribute === \"\") {\n return tag;\n }\n\n const classes = classAttribute.split(/\\s+/).slice(0, SELECTOR_MAX_CLASSES).join(\".\");\n return `${tag}.${classes}`;\n}\n\n/**\n * The two History members this module replaces. They are declared as properties, not\n * methods, so the original functions stay unbound. With a bound copy, uninstall would\n * restore a different function from the one it replaced, and every install cycle would\n * stack one more bind on top of the last.\n */\ninterface HistoryMethods {\n pushState: (this: History, ...args: never[]) => void;\n replaceState: (this: History, ...args: never[]) => void;\n}\n\n/**\n * Returns the History object, typed so that its methods stay unbound.\n * @returns The global history.\n */\nfunction historyMethods(): HistoryMethods {\n return history;\n}\n\n/** Captures user clicks and single-page navigations. */\nexport class InteractionCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"interactions\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /** Restore functions for the history wrappers. */\n private readonly restores: (() => void)[] = [];\n\n /** The URL before the latest navigation. */\n private lastUrl = \"\";\n\n /** The element of the current click burst, and when each of its clicks happened. */\n private burst: { target: Element | null; times: number[]; reported: boolean } = {\n target: null,\n times: [],\n reported: false,\n };\n\n /** Stops the dead click check that is running now. */\n private stopDeadCheck: (() => void) | undefined;\n\n /** Detaches the observed windows. Set while clicks are captured. */\n private unobserve: (() => void) | undefined;\n\n /**\n * @param ctx Capture context: configuration, diagnostics, logger, breadcrumbs and tracing.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Registers click listeners and patches history navigation APIs. */\n install(): void {\n if (this.installed || typeof document === \"undefined\") {\n return;\n }\n this.installed = true;\n this.lastUrl = location.href;\n\n if (this.ctx.config.capture.interactions) {\n // In the capture phase we see the click before a page handler can stop propagation.\n addEventListener(\"click\", this.onClick, true);\n // The app's observed windows outlive this capture, so one observed before the install\n // gets attached here.\n this.unobserve = addWindowObserver({\n attach: (win) => this.attachView(win),\n detach: (win) => {\n this.detachView(win);\n },\n });\n }\n if (this.ctx.config.capture.navigation) {\n this.installHistory();\n addEventListener(\"popstate\", this.onNavigate);\n addEventListener(\"hashchange\", this.onNavigate);\n }\n }\n\n /**\n * Removes the interaction listeners and restores every history method that still holds our\n * wrapper. A wrapper that another script wrapped again stays in place and records nothing.\n */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n removeEventListener(\"click\", this.onClick, true);\n removeEventListener(\"popstate\", this.onNavigate);\n removeEventListener(\"hashchange\", this.onNavigate);\n // Restore history first. An observed window is another document, and a fault there mustn't\n // leave this page patched.\n for (const restore of this.restores.splice(0)) {\n restore();\n }\n this.unobserve?.();\n this.unobserve = undefined;\n\n this.stopDeadCheck?.();\n this.burst = { target: null, times: [], reported: false };\n }\n\n /** Records a click. The browser calls this directly, so a throw would be a page error. */\n private readonly onClick = (event: Event): void => {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a click. It skips that click.\",\n () => {\n this.recordClick(event);\n },\n );\n };\n\n /**\n * Rotates the trace context, records a click breadcrumb and runs the rage and dead click checks.\n * @param event The click.\n */\n private recordClick(event: Event): void {\n if (this.ctx.isActive?.() === false) {\n return;\n }\n const target = event.target;\n if (!isElement(target)) {\n return;\n }\n const settings = this.ctx.config.capture.interactions;\n const options = typeof settings === \"object\" ? settings : {};\n const ignore = options.ignoreSelector === undefined ? IGNORE_SELECTOR : options.ignoreSelector;\n if (ignore && target.closest(ignore)) {\n return;\n }\n // A missing or empty attribute gives \"\", and the message is then \"unknown-click\".\n const attribute = options.actionAttribute ?? ACTION_ATTRIBUTE_DEFAULT;\n const action = target.closest(`[${attribute}]`)?.getAttribute(attribute) ?? \"\";\n const message = (action || \"unknown-click\").slice(0, this.ctx.config.limits.maxBodyChars);\n const data: Record<string, unknown> = {};\n if (options.selector) {\n data.selector = describeElement(target);\n }\n if (options.text) {\n data.text = target.textContent.trim().slice(0, options.maxTextChars ?? CLICK_TEXT_MAX_CHARS);\n }\n this.ctx.tracing.rotate(\"interaction\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"click\",\n message,\n data: Object.keys(data).length > 0 ? data : undefined,\n });\n\n if (options.rageClicks) {\n this.countRage(target, message, options);\n }\n if (\n options.deadClicks &&\n target.closest(`${DEAD_CLICK_CONTROLS}, [${attribute}]`) &&\n !target.closest(LEAVING_LINKS)\n ) {\n // The listener sits on the window that got the click, the page's own or an observed one.\n this.watchDead(message, options, event.currentTarget as Window);\n }\n }\n\n /**\n * Counts the clicks on one element and records `ui.rage_click` once per burst.\n * @param target Clicked element.\n * @param action The click's action name.\n * @param options Interaction options.\n */\n private countRage(target: Element, action: string, options: InteractionOptions): void {\n const now = Date.now();\n const windowMs = options.rageClickWindowMs ?? RAGE_CLICK_WINDOW_MS;\n const count = options.rageClickCount ?? RAGE_CLICK_COUNT;\n const times =\n this.burst.target === target ? this.burst.times.filter((t) => now - t < windowMs) : [];\n // A burst only ends once no click is left in the window, so clicks that keep sliding\n // through it don't fire a second event.\n const reported = times.length > 0 && this.burst.reported;\n times.push(now);\n const reached = times.length >= count;\n this.burst = { target, times, reported: reported || reached };\n\n if (reached && !reported) {\n this.ctx.logger.logEvent(\"ui.rage_click\", { \"click.action\": action, \"click.count\": count });\n }\n }\n\n /**\n * Watches the page and each observed window after a click on a control. If there's no DOM\n * change, URL change or scroll within `deadClickMs`, it records `ui.dead_click`. Only one\n * check runs at a time.\n * @param action The click's action name.\n * @param options Interaction options.\n * @param view The window that got the click. Its URL change answers the click too.\n */\n private watchDead(action: string, options: InteractionOptions, view: Window): void {\n if (this.stopDeadCheck || typeof MutationObserver === \"undefined\") {\n return;\n }\n\n const pageUrl = location.href;\n const viewUrl = urlOf(view);\n const live = options.deadClickIgnoreSelector ?? DEAD_CLICK_IGNORE_SELECTOR;\n let responded = false;\n const observer = new MutationObserver((records) => {\n responded ||= this.answers(() => batchAnswers(records, live));\n });\n const onScroll = (event: Event): void => {\n responded ||= this.answers(() => !insideLive(event.target, live));\n };\n // A click in a popout can change this page, and a click here can change a popout.\n const views: Window[] = [];\n for (const each of [window, ...observedWindows()]) {\n try {\n // The old values let a same-value write count as no change.\n observer.observe(each.document, {\n subtree: true,\n childList: true,\n attributes: true,\n attributeOldValue: true,\n characterData: true,\n characterDataOldValue: true,\n });\n each.addEventListener(\"scroll\", onScroll, { capture: true, passive: true });\n views.push(each);\n } catch {\n // A window that turned cross-origin throws, and that's the expected answer. The fallback\n // skips it and forgets it, because the library can't watch it anymore.\n forgetWindow(each);\n }\n }\n\n const stop = (): void => {\n // timer is declared after stop, but stop can only run once that line has executed.\n clearTimeout(timer);\n observer.disconnect();\n for (const each of views) {\n unlisten(each, \"scroll\", onScroll, true);\n }\n this.stopDeadCheck = undefined;\n };\n const timer = setTimeout(() => {\n stop();\n const moved = location.href !== pageUrl || urlOf(view) !== viewUrl;\n if (!responded && !moved && this.ctx.isActive?.() !== false) {\n this.ctx.logger.logEvent(\"ui.dead_click\", { \"click.action\": action });\n }\n }, options.deadClickMs ?? DEAD_CLICK_MS);\n this.stopDeadCheck = stop;\n }\n\n /**\n * Runs one dead click test in a guard. A failed test counts as an answer, so a fault can't make\n * up a dead click. The browser calls the observer and the listener directly, so a throw would\n * be a page error.\n * @param test Returns true if a change answers the click.\n * @returns The test's result, or true if it threw.\n */\n private answers(test: () => boolean): boolean {\n return (\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not check a page change for a dead click. It counts the change as a response.\",\n test,\n ) ?? true\n );\n }\n\n /**\n * Starts listening for clicks in an observed window.\n * @param win The window.\n * @returns False for a window from another origin, after it reports the window.\n */\n private attachView(win: Window): boolean {\n try {\n // Only a window of this origin has a readable document. Reading it first means a window\n // from another origin throws before it gets a listener.\n const _sameOrigin = win.document;\n win.addEventListener(\"click\", this.onClick, true);\n win.addEventListener(\"pagehide\", this.onViewHide);\n return true;\n } catch {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The library cannot observe a window from another origin. It captures no clicks there.\",\n );\n return false;\n }\n }\n\n /**\n * Stops listening in an observed window. A running dead click check stops too, without a\n * record, because it holds a listener in this window. A window that leaves during the check\n * has most often answered the click, for example a popout that docks back into the page.\n * @param win The window.\n */\n private detachView(win: Window): void {\n this.stopDeadCheck?.();\n unlisten(win, \"click\", this.onClick, true);\n unlisten(win, \"pagehide\", this.onViewHide);\n }\n\n /** Forgets an observed window when its page goes away, so the library doesn't hold it. */\n private readonly onViewHide = (event: Event): void => {\n const win = event.currentTarget as Window;\n // window.open(url) starts on about:blank and fires pagehide there. Then it loads a page of\n // this origin into the same window, which keeps our listeners, so forgetting it would lose it.\n if (onInitialBlank(win)) {\n return;\n }\n\n forgetWindow(win);\n };\n\n /** On a URL change, rotates the trace context and records a breadcrumb and an event. */\n private readonly onNavigate = (): void => {\n const from = this.lastUrl;\n const to = location.href;\n if (from === to) {\n return;\n }\n this.lastUrl = to;\n if (this.ctx.isActive?.() === false) {\n return;\n }\n\n // The comparison above uses the full URL, so a query-only change still counts as a\n // navigation. The record doesn't keep the query unless you set fullUrls.\n const full = this.ctx.config.capture.fullUrls;\n const { urlTransform } = this.ctx.config.capture;\n const fromUrl = recordedUrl(from, full, urlTransform, this.ctx.diagnostics);\n const toUrl = recordedUrl(to, full, urlTransform, this.ctx.diagnostics);\n\n this.ctx.tracing.rotate(\"navigation\");\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"navigation\",\n message: `${fromUrl} -> ${toUrl}`,\n });\n\n // The event carries only the previous URL, and the record builder adds the current one as\n // `page.url`. Putting the new URL in `url.full` would make a navigation look like an HTTP\n // request.\n this.ctx.logger.logEvent(\"NAVIGATION\", { \"page.url.previous\": fromUrl });\n };\n\n /** Patches History.pushState and replaceState to observe programmatic navigations. */\n private installHistory(): void {\n if (typeof history === \"undefined\") {\n return;\n }\n\n // Wrap the instance, not History.prototype. Reading from the prototype would skip a patch\n // that a router installed on the instance. patch keeps the originals unbound.\n const target = historyMethods();\n const onNavigate = this.onNavigate;\n // Uninstall clears the flag, so a wrapper that stays in place only calls the original.\n let active = true;\n\n const restorePushState = patch(\n target,\n \"pushState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n // Queue the handler. The browser only updates location.href after the call returns,\n // so a synchronous read would report the previous URL as the new one.\n if (active) {\n queueMicrotask(onNavigate);\n }\n },\n );\n\n const restoreReplaceState = patch(\n target,\n \"replaceState\",\n (original) =>\n function (this: History, ...args: never[]): void {\n original.apply(this, args);\n if (active) {\n queueMicrotask(onNavigate);\n }\n },\n );\n\n this.restores.push(() => {\n active = false;\n restorePushState();\n restoreReplaceState();\n });\n }\n}\n"],"mappings":"A,2MAyBA,IAAMW,EAAgB,kCAGhBC,EAAe,EAQrB,SAASC,EAAU,EAAkC,CACnD,OAAQC,GAAgC,WAAaF,CACvD,CAGA,IAAMG,EAAuB,cAU7B,SAASC,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,CAKN,OAJA,KAAK,IAAI,YAAY,OACnB,yBACA,uFACF,EACO,EACT,CACF,CAQA,WAAmB,EAAmB,CACpC,KAAK,gBAAgB,EACrBE,EAASF,EAAK,QAAS,KAAK,QAAS,EAAI,EACzCE,EAASF,EAAK,WAAY,KAAK,UAAU,CAC3C,CA+CA,gBAA+B,CAC7B,GAAI,OAAO,QAAY,IACrB,OAKF,IAAMb,EAASyB,EAAe,EACxBoC,EAAa,KAAK,WAEpBC,EAAS,GAEPC,EAAmB5E,EAAAA,EACvBa,EACA,YACC,GACC,SAAyB,GAAGgE,EAAqB,CAC/CC,EAAS,MAAM,KAAMD,CAAI,EAGrBF,GACF,eAAeD,CAAU,CAE7B,CACJ,EAEMK,EAAsB/E,EAAAA,EAC1Ba,EACA,eACC,GACC,SAAyB,GAAGgE,EAAqB,CAC/CC,EAAS,MAAM,KAAMD,CAAI,EACrBF,GACF,eAAeD,CAAU,CAE7B,CACJ,EAEA,KAAK,SAAS,SAAW,CACvB,EAAS,GACTE,EAAiB,EACjBG,EAAoB,CACtB,CAAC,CACH,CACF,E"}
@@ -1,36 +1,37 @@
1
- import { Bt as e, C as t, Ct as n, S as r, St as i, T as a, Vt as o, bt as s, w as c, x as l, xt as u } from "./constants-Bwl_YtQi.js";
1
+ import { C as e, Dt as t, Et as n, Jt as r, Ot as i, S as a, T as o, Tt as s, Yt as c, w as l, x as u } from "./constants-BwJDXzj6.js";
2
2
  import { n as d } from "./deadline-C4ccAuk5.js";
3
- import { i as f, t as p } from "./identity-BrQp_5J5.js";
3
+ import { i as f, t as p } from "./identity-BgtHyY4u.js";
4
4
  import { t as m } from "./openfin-Bxelt0yg.js";
5
5
  import { t as h } from "./unref-DgHPQeWv.js";
6
+ import { t as g } from "./defineProperty-s2S8BXUc.js";
6
7
  // src/core/journey.ts
7
- var g = {
8
- maxAgeMs: u,
8
+ var _ = {
9
+ maxAgeMs: n,
9
10
  endOnOwnerClose: !1,
10
- urlParam: n
11
+ urlParam: i
11
12
  };
12
- function _(e, t) {
13
+ function v(e, t) {
13
14
  let n = Reflect.get(e, t);
14
15
  return typeof n == "string" && n !== "" ? n : void 0;
15
16
  }
16
- function v(e, t) {
17
+ function y(e, t) {
17
18
  let n = Reflect.get(e, t);
18
19
  return typeof n == "number" && Number.isFinite(n) ? n : void 0;
19
20
  }
20
- function y(e) {
21
+ function b(e) {
21
22
  if (typeof e != "object" || !e) return null;
22
- let t = _(e, "id"), n = _(e, "name"), r = v(e, "startedAt");
23
+ let t = v(e, "id"), n = v(e, "name"), r = y(e, "startedAt");
23
24
  return t === void 0 || n === void 0 || r === void 0 ? null : {
24
25
  id: t,
25
26
  name: n,
26
27
  startedAt: r,
27
- parentId: _(e, "parentId"),
28
- ownerContextId: _(e, "ownerContextId") ?? ""
28
+ parentId: v(e, "parentId"),
29
+ ownerContextId: v(e, "ownerContextId") ?? ""
29
30
  };
30
31
  }
31
- function b(e) {
32
+ function x(e) {
32
33
  if (typeof e != "object" || !e) return null;
33
- let t = _(e, "i"), n = _(e, "n"), r = v(e, "s"), i = r !== void 0 && r > Date.now() + 3e5;
34
+ let t = v(e, "i"), n = v(e, "n"), r = y(e, "s"), i = r !== void 0 && r > Date.now() + 3e5;
34
35
  return t === void 0 || n === void 0 || r === void 0 || i ? null : {
35
36
  id: t,
36
37
  name: n,
@@ -39,39 +40,36 @@ function b(e) {
39
40
  ownerContextId: ""
40
41
  };
41
42
  }
42
- function x(e) {
43
+ function S(t) {
43
44
  let n = JSON.stringify({
44
- i: e.id,
45
- n: e.name.slice(0, 64),
46
- s: e.startedAt
45
+ i: t.id,
46
+ n: t.name.slice(0, 64),
47
+ s: t.startedAt
47
48
  }), r = new TextEncoder().encode(n), i = "";
48
49
  for (let e of r) i += String.fromCharCode(e);
49
- return btoa(i).replace(c, "-").replace(a, "_").replace(t, "");
50
+ return btoa(i).replace(l, "-").replace(o, "_").replace(e, "");
50
51
  }
51
- var S = class {
52
- options;
53
- diagnostics;
54
- contextId;
55
- onLocalChange;
56
- stores;
57
- journey = null;
58
- expiryTimer = null;
52
+ var C = class {
59
53
  constructor(e, t, n, r, i = p) {
60
- this.options = e, this.diagnostics = t, this.contextId = n, this.onLocalChange = r, this.stores = i;
54
+ g(this, "options", void 0), g(this, "diagnostics", void 0), g(this, "contextId", void 0), g(this, "onLocalChange", void 0), g(this, "stores", void 0), g(this, "journey", null), g(this, "expiryTimer", null), this.options = e, this.diagnostics = t, this.contextId = n, this.onLocalChange = r, this.stores = i;
61
55
  }
62
56
  current() {
63
57
  return this.journey;
64
58
  }
65
59
  async bootstrap() {
66
60
  let e = this.readUrlToken();
61
+ if (this.journey) {
62
+ e && this.removeUrlToken(), this.setJourney(this.journey);
63
+ return;
64
+ }
67
65
  if (e && this.adopt(e, "url")) {
68
66
  this.removeUrlToken();
69
67
  return;
70
68
  }
71
- let t = this.diagnostics.guard("storage.unavailable", "The library could not read the persisted journey.", () => this.stores.session().getItem(i));
72
- if (t && this.restore(t)) return;
73
- let n = await this.readOpenFinToken();
74
- n !== null && this.adopt(n, "openfin.customData");
69
+ let n = this.diagnostics.guard("storage.unavailable", "The library could not read the persisted journey.", () => this.stores.session().getItem(t));
70
+ if (n && this.restore(n)) return;
71
+ let r = await this.readOpenFinToken();
72
+ r !== null && this.adopt(r, "openfin.customData");
75
73
  }
76
74
  start(e, t = {}) {
77
75
  let n = {
@@ -95,10 +93,9 @@ var S = class {
95
93
  }
96
94
  getToken() {
97
95
  let e = this.journey;
98
- if (e === null) return;
99
- let t = x(e);
100
- if (t.length > 256) this.diagnostics.report("journey.token_too_large", "The journey token is larger than the size limit. The library does not issue it.", { length: t.length });
101
- else return t;
96
+ if (e === null) return null;
97
+ let t = S(e);
98
+ return t.length > 256 ? (this.diagnostics.report("journey.token_too_large", "The journey token is larger than the size limit. The library does not issue it.", { length: t.length }), null) : t;
102
99
  }
103
100
  adopt(e, t, n = !1) {
104
101
  let r = this.decodeToken(e);
@@ -117,7 +114,7 @@ var S = class {
117
114
  this.clearTimer();
118
115
  }
119
116
  restore(e) {
120
- let t = y(this.diagnostics.guard("storage.degraded", "The library could not parse the persisted journey.", () => JSON.parse(e)));
117
+ let t = b(this.diagnostics.guard("storage.degraded", "The library could not parse the persisted journey.", () => JSON.parse(e)));
121
118
  return t === null ? !1 : Date.now() - t.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "The library discarded a persisted journey older than maxAgeMs.", { name: t.name }), this.clearStored(), !1) : (this.setJourney(t), this.diagnostics.report("journey.adopted", `The library resumed the journey "${t.name}".`, {
122
119
  source: "sessionStorage",
123
120
  journeyId: t.id
@@ -125,22 +122,22 @@ var S = class {
125
122
  }
126
123
  decodeToken(e) {
127
124
  return this.diagnostics.guard("config.invalid", "The library could not decode a seeded journey token.", () => {
128
- let t = e.replace(l, "+").replace(r, "/"), n = (4 - t.length % 4) % 4, i = "=".repeat(n), a = Uint8Array.from(atob(t + i), (e) => e.charCodeAt(0));
129
- return b(JSON.parse(new TextDecoder().decode(a)));
125
+ let t = e.replace(u, "+").replace(a, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
126
+ return x(JSON.parse(new TextDecoder().decode(i)));
130
127
  }) ?? null;
131
128
  }
132
129
  setJourney(e) {
133
130
  if (this.journey = e, this.clearTimer(), this.diagnostics.guard("storage.unavailable", "The library could not save the journey.", () => {
134
- e === null ? this.stores.session().removeItem(i) : this.stores.session().setItem(i, JSON.stringify(e));
131
+ e === null ? this.stores.session().removeItem(t) : this.stores.session().setItem(t, JSON.stringify(e));
135
132
  }), e === null) return;
136
- let t = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), n = setTimeout(() => {
133
+ let n = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), r = setTimeout(() => {
137
134
  this.diagnostics.report("journey.expired", `The journey "${e.name}" reached maxAgeMs. The library ended it.`, { journeyId: e.id }), this.journey = null, this.expiryTimer = null, this.clearStored();
138
- }, t);
139
- this.expiryTimer = n, h(n);
135
+ }, n);
136
+ this.expiryTimer = r, h(r);
140
137
  }
141
138
  clearStored() {
142
139
  this.diagnostics.guard("storage.unavailable", "The library could not clear the persisted journey.", () => {
143
- this.stores.session().removeItem(i);
140
+ this.stores.session().removeItem(t);
144
141
  });
145
142
  }
146
143
  clearTimer() {
@@ -156,12 +153,12 @@ var S = class {
156
153
  });
157
154
  }
158
155
  async readOpenFinToken() {
159
- let t = m()?.me, n = t?.getOptions;
160
- if (n === void 0) return null;
161
- let r = (await this.diagnostics.guardAsync("openfin.unavailable", "The library could not read fin.me.getOptions().", () => d(n.call(t), o)))?.customData?.[e];
162
- return typeof r == "string" ? r : null;
156
+ let e = m()?.me, t = e?.getOptions;
157
+ if (t === void 0) return null;
158
+ let n = (await this.diagnostics.guardAsync("openfin.unavailable", "The library could not read fin.me.getOptions().", () => d(t.call(e), c)))?.customData?.[r];
159
+ return typeof n == "string" ? n : null;
163
160
  }
164
161
  };
165
- export { S as n, y as r, g as t };
162
+ export { C as n, b as r, _ as t };
166
163
 
167
- //# sourceMappingURL=journey-35yCMNFo.js.map
164
+ //# sourceMappingURL=journey-C93FTYcs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journey-C93FTYcs.js","names":["BASE64_PADDING_PATTERN","JOURNEY_STORAGE_KEY","JOURNEY_MAX_AGE_MS","OPENFIN_JOURNEY_CUSTOM_DATA_KEY","JOURNEY_URL_PARAM","BASE64URL_UNDERSCORE_PATTERN","BASE64_SLASH_PATTERN","JOURNEY_ID_PATTERN","OPENFIN_OPTIONS_TIMEOUT_MS","BASE64_PLUS_PATTERN","BASE64URL_DASH_PATTERN","withDeadline","newId","BROWSER_STORES","getFin","unrefTimer","_defineProperty","JOURNEY_OPTIONS","readString","value","source","key","readNumber","parseJourney","id","name","startedAt","journeyFromTokenPayload","future","encodeToken","json","journey","bytes","binary","byte","JourneyEngine","options","diagnostics","contextId","onLocalChange","stores","fromUrl","fromStorage","fromOpenFin","opts","requested","current","token","decoded","broadcast","ownerContextId","raw","standard","missing","padding","c","remaining","timer","url","me","getOptions"],"sources":["../src/core/journey.ts"],"sourcesContent":["// src/core/journey.ts\n//\n// Manages a user journey's lifecycle across windows: encodes tokens, stores the journey and\n// ends it at expiry. Never trust a value from storage or a token, because any code on the\n// origin can write to both.\n\nimport {\n BASE64_GROUP_CHARS,\n BASE64_PADDING_PATTERN,\n BASE64_PLUS_PATTERN,\n BASE64_SLASH_PATTERN,\n BASE64URL_DASH_PATTERN,\n BASE64URL_UNDERSCORE_PATTERN,\n JOURNEY_END_ON_OWNER_CLOSE,\n JOURNEY_CLOCK_SKEW_MS,\n JOURNEY_ID_MAX_CHARS,\n JOURNEY_ID_PATTERN,\n JOURNEY_MAX_AGE_MS,\n JOURNEY_STORAGE_KEY,\n JOURNEY_TOKEN_MAX_CHARS,\n JOURNEY_TOKEN_NAME_MAX_CHARS,\n OPENFIN_JOURNEY_CUSTOM_DATA_KEY,\n JOURNEY_URL_PARAM,\n OPENFIN_OPTIONS_TIMEOUT_MS,\n} from \"../constants\";\nimport { withDeadline } from \"../utils/deadline\";\nimport { BROWSER_STORES, type IdentityStores, newId } from \"../utils/identity\";\nimport { getFin } from \"../utils/openfin\";\nimport { unrefTimer } from \"../utils/unref\";\nimport type { Diagnostics } from \"./diagnostics\";\n\n/** Lifetime rules for a journey, which is one user task spanning several contexts. */\nexport interface JourneyOptions {\n /** Maximum time a journey stays open, in milliseconds. After that the engine ends it. */\n maxAgeMs: number;\n /** True if the journey ends for all contexts when the owning context closes. */\n endOnOwnerClose: boolean;\n /** Query parameter checked at boot for a seeded journey token. */\n urlParam: string;\n}\n\n/** The journey lifetime policy in effect. Tests build an engine with shorter values. */\nexport const JOURNEY_OPTIONS: JourneyOptions = {\n maxAgeMs: JOURNEY_MAX_AGE_MS,\n endOnOwnerClose: JOURNEY_END_ON_OWNER_CLOSE,\n urlParam: JOURNEY_URL_PARAM,\n};\n\n/** User journey workflow context shared across windows and applications. */\nexport interface Journey {\n /** Unique journey correlation identifier. */\n id: string;\n /** Human-readable name of the journey's workflow. */\n name: string;\n /** Journey start timestamp in epoch milliseconds. */\n startedAt: number;\n /** Parent journey ID, set when the journey branches from an earlier one. */\n parentId?: string;\n /** Context identifier of the document that started the journey. */\n ownerContextId: string;\n}\n\n/**\n * Reads a non-empty string property from an unverified object.\n * @param source Object to read from.\n * @param key Property name.\n * @returns Non-empty string value or undefined.\n */\nfunction readString(source: object, key: string): string | undefined {\n const value: unknown = Reflect.get(source, key);\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\n/**\n * Reads a finite number property from an unverified object.\n * @param source Object to read from.\n * @param key Property name.\n * @returns Finite number value or undefined.\n */\nfunction readNumber(source: object, key: string): number | undefined {\n const value: unknown = Reflect.get(source, key);\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\n/**\n * Parses and validates an unknown value into a Journey object. The value comes from\n * sessionStorage or from another realm's bus message.\n * @param value Unverified parsed JSON value.\n * @returns Validated Journey instance or null.\n */\nexport function parseJourney(value: unknown): Journey | null {\n if (typeof value !== \"object\" || value === null) {\n return null;\n }\n const id = readString(value, \"id\");\n const name = readString(value, \"name\");\n const startedAt = readNumber(value, \"startedAt\");\n if (id === undefined || name === undefined || startedAt === undefined) {\n return null;\n }\n return {\n id,\n name,\n startedAt,\n parentId: readString(value, \"parentId\"),\n ownerContextId: readString(value, \"ownerContextId\") ?? \"\",\n };\n}\n\n/**\n * Parses and validates a decoded token payload into a Journey object.\n * @param value Unverified parsed token payload.\n * @returns Validated Journey instance or null.\n */\nfunction journeyFromTokenPayload(value: unknown): Journey | null {\n if (typeof value !== \"object\" || value === null) {\n return null;\n }\n const id = readString(value, \"i\");\n const name = readString(value, \"n\");\n const startedAt = readNumber(value, \"s\");\n // We always write a start time. A token without one, or with one from the future, would\n // never expire.\n const future = startedAt !== undefined && startedAt > Date.now() + JOURNEY_CLOCK_SKEW_MS;\n if (id === undefined || name === undefined || startedAt === undefined || future) {\n return null;\n }\n return {\n id,\n name,\n startedAt,\n parentId: undefined,\n ownerContextId: \"\",\n };\n}\n\n/**\n * Encodes journey metadata into a compact, URL-safe base64 string.\n * @param journey Journey instance to serialize.\n * @returns Unpadded base64url encoded token string.\n */\nfunction encodeToken(journey: Journey): string {\n const json = JSON.stringify({\n i: journey.id,\n n: journey.name.slice(0, JOURNEY_TOKEN_NAME_MAX_CHARS),\n s: journey.startedAt,\n });\n // Convert the UTF-8 bytes to a binary string before btoa, which throws above U+00FF.\n // Without this step, a name in a non-Latin script would fail.\n const bytes = new TextEncoder().encode(json);\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary)\n .replace(BASE64_PLUS_PATTERN, \"-\")\n .replace(BASE64_SLASH_PATTERN, \"_\")\n .replace(BASE64_PADDING_PATTERN, \"\");\n}\n\n/** Manages journey lifecycle, cross-window adoption, storage synchronization, and expiration. */\nexport class JourneyEngine {\n /** Active journey context, or null if none is in progress. */\n private journey: Journey | null = null;\n\n /** Active expiration timer handle. */\n private expiryTimer: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * @param options Journey configuration thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param contextId Unique context identifier for this document.\n * @param onLocalChange Callback invoked when journey state changes locally.\n * @param stores Identity stores that hold the journey.\n */\n constructor(\n private readonly options: JourneyOptions,\n private readonly diagnostics: Diagnostics,\n private readonly contextId: string,\n private readonly onLocalChange: (journey: Journey | null) => void,\n private readonly stores: IdentityStores = BROWSER_STORES,\n ) {}\n\n /** Returns the active journey instance or null. */\n current(): Journey | null {\n return this.journey;\n }\n\n /**\n * Finds and adopts the initial journey. Keeps an active journey. Otherwise checks the URL\n * query first, then sessionStorage, then OpenFin customData.\n * @returns Promise that resolves when journey initialization completes.\n */\n async bootstrap(): Promise<void> {\n const fromUrl = this.readUrlToken();\n // A journey that the app started before configure() wins, and it moves to the stores that\n // configure() chose. Otherwise a stored journey from an earlier page would replace it. The\n // token still leaves the address bar, or a copied link would carry it to another session.\n if (this.journey) {\n if (fromUrl) {\n this.removeUrlToken();\n }\n this.setJourney(this.journey);\n return;\n }\n\n if (fromUrl && this.adopt(fromUrl, \"url\")) {\n this.removeUrlToken();\n return;\n }\n\n const fromStorage = this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read the persisted journey.\",\n () => this.stores.session().getItem(JOURNEY_STORAGE_KEY),\n );\n if (fromStorage && this.restore(fromStorage)) {\n return;\n }\n\n const fromOpenFin = await this.readOpenFinToken();\n if (fromOpenFin !== null) {\n this.adopt(fromOpenFin, \"openfin.customData\");\n }\n }\n\n /**\n * Starts a new journey, replacing the active one and telling connected peers.\n * @param name Human-readable workflow name.\n * @param opts Optional parent linkage and pre-assigned identifier.\n * @returns Started Journey instance.\n */\n start(name: string, opts: { parent?: boolean; id?: string } = {}): Journey {\n const journey: Journey = {\n id: this.journeyId(opts.id),\n name,\n startedAt: Date.now(),\n parentId: opts.parent ? this.journey?.id : undefined,\n ownerContextId: this.contextId,\n };\n this.setJourney(journey);\n this.onLocalChange(journey);\n return journey;\n }\n\n /**\n * Picks the id for a new journey. A longer id, or one with multibyte characters, would make\n * the journey token too long for adoptJourney().\n * @param requested Id from the app, or undefined.\n * @returns The requested id when it matches JOURNEY_ID_PATTERN, otherwise a new id.\n */\n private journeyId(requested: unknown): string {\n if (requested === undefined) {\n return newId(this.diagnostics);\n }\n\n if (typeof requested === \"string\" && JOURNEY_ID_PATTERN.test(requested)) {\n return requested;\n }\n\n this.diagnostics.report(\n \"config.invalid\",\n `startJourney() needs an id of 1 to ${String(JOURNEY_ID_MAX_CHARS)} letters, digits, \"_\", \".\", \":\" or \"-\". The library uses a new id.`,\n );\n return newId(this.diagnostics);\n }\n\n /** Ends the active journey and broadcasts the change. */\n end(): void {\n if (this.journey === null) {\n return;\n }\n this.setJourney(null);\n this.onLocalChange(null);\n }\n\n /**\n * Applies a journey update from a bus peer without broadcasting it again. An echo would\n * make two windows send the change back and forth forever. A journey with the same ID as\n * the active one is ignored, so an echo can't restart the timer.\n * @param journey Updated Journey instance or null.\n */\n applyRemote(journey: Journey | null): void {\n const current = this.journey;\n if (journey !== null && current !== null && journey.id === current.id) {\n return;\n }\n this.setJourney(journey);\n }\n\n /**\n * Serializes the active journey into a compact token for URL or intent transfer.\n * @returns Base64url token, or null when no journey is active or the token exceeds the size\n * limit.\n */\n getToken(): string | null {\n const journey = this.journey;\n if (journey === null) {\n return null;\n }\n const token = encodeToken(journey);\n if (token.length > JOURNEY_TOKEN_MAX_CHARS) {\n this.diagnostics.report(\n \"journey.token_too_large\",\n \"The journey token is larger than the size limit. The library does not issue it.\",\n { length: token.length },\n );\n return null;\n }\n return token;\n }\n\n /**\n * Validates and adopts a serialized journey token.\n * @param token Base64url journey token.\n * @param source Originating source description for diagnostics.\n * @param broadcast True to send the adoption to the connected bus peers.\n * @returns True if the token was valid, unexpired, and adopted.\n */\n adopt(token: string, source: string, broadcast = false): boolean {\n const decoded = this.decodeToken(token);\n if (decoded === null) {\n return false;\n }\n if (Date.now() - decoded.startedAt > this.options.maxAgeMs) {\n this.diagnostics.report(\n \"journey.expired\",\n \"The library discarded a seeded journey older than maxAgeMs.\",\n {\n source,\n name: decoded.name,\n },\n );\n return false;\n }\n\n this.setJourney(decoded);\n this.diagnostics.report(\n \"journey.adopted\",\n `The library adopted the journey \"${decoded.name}\".`,\n {\n source,\n journeyId: decoded.id,\n },\n );\n if (broadcast) {\n this.onLocalChange(decoded);\n }\n return true;\n }\n\n /**\n * Ends the journey when endOnOwnerClose is on and the closed context owns the journey.\n * @param ownerContextId Context identifier of the closed window.\n */\n ownerClosed(ownerContextId: string): void {\n if (!this.options.endOnOwnerClose) {\n return;\n }\n if (this.journey?.ownerContextId === ownerContextId) {\n this.end();\n }\n }\n\n /** Clears pending expiration timers and releases resources on shutdown. */\n destroy(): void {\n this.clearTimer();\n }\n\n /**\n * Resumes a persisted journey from raw sessionStorage data.\n * @param raw Serialized JSON string from storage.\n * @returns True if the engine restored the journey.\n */\n private restore(raw: string): boolean {\n const parsed = this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not parse the persisted journey.\",\n () => JSON.parse(raw) as unknown,\n );\n const journey = parseJourney(parsed);\n if (journey === null) {\n return false;\n }\n\n if (Date.now() - journey.startedAt > this.options.maxAgeMs) {\n this.diagnostics.report(\n \"journey.expired\",\n \"The library discarded a persisted journey older than maxAgeMs.\",\n { name: journey.name },\n );\n this.clearStored();\n return false;\n }\n\n this.setJourney(journey);\n this.diagnostics.report(\n \"journey.adopted\",\n `The library resumed the journey \"${journey.name}\".`,\n {\n source: \"sessionStorage\",\n journeyId: journey.id,\n },\n );\n return true;\n }\n\n /**\n * Decodes a base64url token into a validated Journey object. Anyone can edit the URL\n * that holds a token, and every step throws on bad input. The guard reports the failure\n * instead of letting it throw.\n * @param token Encoded token string.\n * @returns Decoded Journey instance or null on decode error.\n */\n private decodeToken(token: string): Journey | null {\n const decoded = this.diagnostics.guard(\n \"config.invalid\",\n \"The library could not decode a seeded journey token.\",\n () => {\n const standard = token\n .replace(BASE64URL_DASH_PATTERN, \"+\")\n .replace(BASE64URL_UNDERSCORE_PATTERN, \"/\");\n const missing =\n (BASE64_GROUP_CHARS - (standard.length % BASE64_GROUP_CHARS)) % BASE64_GROUP_CHARS;\n const padding = \"=\".repeat(missing);\n const bytes = Uint8Array.from(atob(standard + padding), (c) => c.charCodeAt(0));\n return journeyFromTokenPayload(JSON.parse(new TextDecoder().decode(bytes)) as unknown);\n },\n );\n return decoded ?? null;\n }\n\n /**\n * Sets the active journey, updates sessionStorage, and schedules expiration.\n * @param journey Target Journey instance or null.\n */\n private setJourney(journey: Journey | null): void {\n this.journey = journey;\n this.clearTimer();\n\n this.diagnostics.guard(\"storage.unavailable\", \"The library could not save the journey.\", () => {\n if (journey !== null) {\n this.stores.session().setItem(JOURNEY_STORAGE_KEY, JSON.stringify(journey));\n } else {\n this.stores.session().removeItem(JOURNEY_STORAGE_KEY);\n }\n });\n\n if (journey === null) {\n return;\n }\n\n const remaining = Math.max(this.options.maxAgeMs - (Date.now() - journey.startedAt), 0);\n const timer = setTimeout(() => {\n this.diagnostics.report(\n \"journey.expired\",\n `The journey \"${journey.name}\" reached maxAgeMs. The library ended it.`,\n { journeyId: journey.id },\n );\n this.journey = null;\n this.expiryTimer = null;\n this.clearStored();\n }, remaining);\n this.expiryTimer = timer;\n unrefTimer(timer);\n }\n\n /** Removes journey data from the session store. */\n private clearStored(): void {\n this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not clear the persisted journey.\",\n () => {\n this.stores.session().removeItem(JOURNEY_STORAGE_KEY);\n },\n );\n }\n\n /** Cancels any active expiration timer. */\n private clearTimer(): void {\n if (this.expiryTimer !== null) {\n clearTimeout(this.expiryTimer);\n this.expiryTimer = null;\n }\n }\n\n /**\n * Extracts the journey token from the current window location search parameters.\n * @returns Token string or null.\n */\n private readUrlToken(): string | null {\n const token = this.diagnostics.guard(\n \"config.invalid\",\n \"The library could not read the journey token from the URL.\",\n () => {\n if (typeof location === \"undefined\") {\n return null;\n }\n return new URL(location.href).searchParams.get(this.options.urlParam);\n },\n );\n return token ?? null;\n }\n\n /**\n * Removes the journey token from the address bar once the engine has adopted it.\n * Otherwise a copied or bookmarked link would start the same journey in another session.\n */\n private removeUrlToken(): void {\n this.diagnostics.guard(\n \"platform.api_blocked\",\n \"The library could not remove the journey token from the URL.\",\n () => {\n const url = new URL(location.href);\n url.searchParams.delete(this.options.urlParam);\n // Keep history.state, because a router stores its own state there.\n history.replaceState(history.state, \"\", url.href);\n },\n );\n }\n\n /**\n * Reads the journey token from customData in the OpenFin window options. The wait is\n * capped by OPENFIN_OPTIONS_TIMEOUT_MS. At the deadline we report openfin.unavailable and\n * return no token. A window with no token gives the same result.\n * @returns Promise that resolves to the token string or null.\n */\n private async readOpenFinToken(): Promise<string | null> {\n const me = getFin()?.me;\n const getOptions = me?.getOptions;\n if (getOptions === undefined) {\n return null;\n }\n\n // Use call so the native OpenFin method keeps its receiver. A detached copy throws when\n // called.\n const options = await this.diagnostics.guardAsync(\n \"openfin.unavailable\",\n \"The library could not read fin.me.getOptions().\",\n () => withDeadline(getOptions.call(me), OPENFIN_OPTIONS_TIMEOUT_MS),\n );\n const token = options?.customData?.[OPENFIN_JOURNEY_CUSTOM_DATA_KEY];\n return typeof token === \"string\" ? token : null;\n }\n}\n"],"mappings":";;;;;;;AA0CA,IAAaiB,IAAkC;CAC7C,UAAUf;CACV,iBAAA;CACA,UAAUE;AACZ;AAsBA,SAASc,EAAW,GAAgB,GAAiC;CACnE,IAAMC,IAAiB,QAAQ,IAAIC,GAAQC,CAAG;CAC9C,OAAO,OAAOF,KAAU,YAAYA,MAAU,KAAKA,IAAQ,KAAA;AAC7D;AAQA,SAASG,EAAW,GAAgB,GAAiC;CACnE,IAAMH,IAAiB,QAAQ,IAAIC,GAAQC,CAAG;CAC9C,OAAO,OAAOF,KAAU,YAAY,OAAO,SAASA,CAAK,IAAIA,IAAQ,KAAA;AACvE;AAQA,SAAgBI,EAAa,GAAgC;CAC3D,IAAI,OAAOJ,KAAU,aAAYA,GAC/B,OAAO;CAET,IAAMK,IAAKN,EAAWC,GAAO,IAAI,GAC3BM,IAAOP,EAAWC,GAAO,MAAM,GAC/BO,IAAYJ,EAAWH,GAAO,WAAW;CAI/C,OAHIK,MAAO,KAAA,KAAaC,MAAS,KAAA,KAAaC,MAAc,KAAA,IACnD,OAEF;EACL;EACA;EACA;EACA,UAAUR,EAAWC,GAAO,UAAU;EACtC,gBAAgBD,EAAWC,GAAO,gBAAgB,KAAK;CACzD;AACF;AAOA,SAASQ,EAAwB,GAAgC;CAC/D,IAAI,OAAOR,KAAU,aAAYA,GAC/B,OAAO;CAET,IAAMK,IAAKN,EAAWC,GAAO,GAAG,GAC1BM,IAAOP,EAAWC,GAAO,GAAG,GAC5BO,IAAYJ,EAAWH,GAAO,GAAG,GAGjCS,IAASF,MAAc,KAAA,KAAaA,IAAY,KAAK,IAAI,IAAA;CAI/D,OAHIF,MAAO,KAAA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,IAAIA,EAAI,IAAI;EAClD,CACF;CACF;CAQA,MAAc,mBAA2C;EACvD,IAAMC,IAAK7C,EAAO,CAAC,EAAE,IACf8C,IAAaD,GAAI;EACvB,IAAIC,MAAe,KAAA,GACjB,OAAO;EAUT,IAAMb,KAAQ,MALQ,KAAK,YAAY,WACrC,uBACA,yDACMpC,EAAaiD,EAAW,KAAKD,CAAE,GAAGnD,CAA0B,CACpE,EAAA,EACuB,aAAaL;EACpC,OAAO,OAAO4C,KAAU,WAAWA,IAAQ;CAC7C;AACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("./constants-CtF52hIV.cjs"),t=require("./deadline-CUGbto-y.cjs"),n=require("./identity-CvuyqZk7.cjs"),r=require("./openfin-DtH2f7zX.cjs"),i=require("./unref-CU9Nyz_9.cjs"),a=require("./defineProperty-X1c4tIPD.cjs");var o={maxAgeMs:e.Et,endOnOwnerClose:!1,urlParam:e.Ot};function s(e,t){let n=Reflect.get(e,t);return typeof n==`string`&&n!==``?n:void 0}function c(e,t){let n=Reflect.get(e,t);return typeof n==`number`&&Number.isFinite(n)?n:void 0}function l(e){if(typeof e!=`object`||!e)return null;let t=s(e,`id`),n=s(e,`name`),r=c(e,`startedAt`);return t===void 0||n===void 0||r===void 0?null:{id:t,name:n,startedAt:r,parentId:s(e,`parentId`),ownerContextId:s(e,`ownerContextId`)??``}}function u(e){if(typeof e!=`object`||!e)return null;let t=s(e,`i`),n=s(e,`n`),r=c(e,`s`),i=r!==void 0&&r>Date.now()+3e5;return t===void 0||n===void 0||r===void 0||i?null:{id:t,name:n,startedAt:r,parentId:void 0,ownerContextId:``}}function d(t){let n=JSON.stringify({i:t.id,n:t.name.slice(0,64),s:t.startedAt}),r=new TextEncoder().encode(n),i=``;for(let e of r)i+=String.fromCharCode(e);return btoa(i).replace(e.w,`-`).replace(e.T,`_`).replace(e.C,``)}var f=class{constructor(e,t,r,i,o=n.t){a.t(this,`options`,void 0),a.t(this,`diagnostics`,void 0),a.t(this,`contextId`,void 0),a.t(this,`onLocalChange`,void 0),a.t(this,`stores`,void 0),a.t(this,`journey`,null),a.t(this,`expiryTimer`,null),this.options=e,this.diagnostics=t,this.contextId=r,this.onLocalChange=i,this.stores=o}current(){return this.journey}async bootstrap(){let t=this.readUrlToken();if(this.journey){t&&this.removeUrlToken(),this.setJourney(this.journey);return}if(t&&this.adopt(t,`url`)){this.removeUrlToken();return}let n=this.diagnostics.guard(`storage.unavailable`,`The library could not read the persisted journey.`,()=>this.stores.session().getItem(e.Dt));if(n&&this.restore(n))return;let r=await this.readOpenFinToken();r!==null&&this.adopt(r,`openfin.customData`)}start(e,t={}){let n={id:this.journeyId(t.id),name:e,startedAt:Date.now(),parentId:t.parent?this.journey?.id:void 0,ownerContextId:this.contextId};return this.setJourney(n),this.onLocalChange(n),n}journeyId(t){return t===void 0?n.i(this.diagnostics):typeof t==`string`&&e.Tt.test(t)?t:(this.diagnostics.report(`config.invalid`,`startJourney() needs an id of 1 to 64 letters, digits, "_", ".", ":" or "-". The library uses a new id.`),n.i(this.diagnostics))}end(){this.journey!==null&&(this.setJourney(null),this.onLocalChange(null))}applyRemote(e){let t=this.journey;(e===null||t===null||e.id!==t.id)&&this.setJourney(e)}getToken(){let e=this.journey;if(e===null)return null;let t=d(e);return t.length>256?(this.diagnostics.report(`journey.token_too_large`,`The journey token is larger than the size limit. The library does not issue it.`,{length:t.length}),null):t}adopt(e,t,n=!1){let r=this.decodeToken(e);return r===null?!1:Date.now()-r.startedAt>this.options.maxAgeMs?(this.diagnostics.report(`journey.expired`,`The library discarded a seeded journey older than maxAgeMs.`,{source:t,name:r.name}),!1):(this.setJourney(r),this.diagnostics.report(`journey.adopted`,`The library adopted the journey "${r.name}".`,{source:t,journeyId:r.id}),n&&this.onLocalChange(r),!0)}ownerClosed(e){this.options.endOnOwnerClose&&this.journey?.ownerContextId===e&&this.end()}destroy(){this.clearTimer()}restore(e){let t=l(this.diagnostics.guard(`storage.degraded`,`The library could not parse the persisted journey.`,()=>JSON.parse(e)));return t===null?!1:Date.now()-t.startedAt>this.options.maxAgeMs?(this.diagnostics.report(`journey.expired`,`The library discarded a persisted journey older than maxAgeMs.`,{name:t.name}),this.clearStored(),!1):(this.setJourney(t),this.diagnostics.report(`journey.adopted`,`The library resumed the journey "${t.name}".`,{source:`sessionStorage`,journeyId:t.id}),!0)}decodeToken(t){return this.diagnostics.guard(`config.invalid`,`The library could not decode a seeded journey token.`,()=>{let n=t.replace(e.x,`+`).replace(e.S,`/`),r=(4-n.length%4)%4,i=`=`.repeat(r),a=Uint8Array.from(atob(n+i),e=>e.charCodeAt(0));return u(JSON.parse(new TextDecoder().decode(a)))})??null}setJourney(t){if(this.journey=t,this.clearTimer(),this.diagnostics.guard(`storage.unavailable`,`The library could not save the journey.`,()=>{t===null?this.stores.session().removeItem(e.Dt):this.stores.session().setItem(e.Dt,JSON.stringify(t))}),t===null)return;let n=Math.max(this.options.maxAgeMs-(Date.now()-t.startedAt),0),r=setTimeout(()=>{this.diagnostics.report(`journey.expired`,`The journey "${t.name}" reached maxAgeMs. The library ended it.`,{journeyId:t.id}),this.journey=null,this.expiryTimer=null,this.clearStored()},n);this.expiryTimer=r,i.t(r)}clearStored(){this.diagnostics.guard(`storage.unavailable`,`The library could not clear the persisted journey.`,()=>{this.stores.session().removeItem(e.Dt)})}clearTimer(){this.expiryTimer!==null&&(clearTimeout(this.expiryTimer),this.expiryTimer=null)}readUrlToken(){return this.diagnostics.guard(`config.invalid`,`The library could not read the journey token from the URL.`,()=>typeof location>`u`?null:new URL(location.href).searchParams.get(this.options.urlParam))??null}removeUrlToken(){this.diagnostics.guard(`platform.api_blocked`,`The library could not remove the journey token from the URL.`,()=>{let e=new URL(location.href);e.searchParams.delete(this.options.urlParam),history.replaceState(history.state,``,e.href)})}async readOpenFinToken(){let n=r.t()?.me,i=n?.getOptions;if(i===void 0)return null;let a=(await this.diagnostics.guardAsync(`openfin.unavailable`,`The library could not read fin.me.getOptions().`,()=>t.n(i.call(n),e.Yt)))?.customData?.[e.Jt];return typeof a==`string`?a:null}};Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
2
+ //# sourceMappingURL=journey-nMbob3OB.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journey-nMbob3OB.cjs","names":["JOURNEY_MAX_AGE_MS","JOURNEY_URL_PARAM","BASE64_PLUS_PATTERN","BASE64_SLASH_PATTERN","BASE64_PADDING_PATTERN","BROWSER_STORES","JOURNEY_STORAGE_KEY","newId","JOURNEY_ID_PATTERN","BASE64URL_DASH_PATTERN","BASE64URL_UNDERSCORE_PATTERN","getFin","withDeadline","OPENFIN_OPTIONS_TIMEOUT_MS","OPENFIN_JOURNEY_CUSTOM_DATA_KEY","require_constants","require_deadline","require_identity","require_openfin","require_unref","require_defineProperty","JOURNEY_OPTIONS","readString","value","source","key","readNumber","parseJourney","id","name","startedAt","journeyFromTokenPayload","future","encodeToken","json","journey","bytes","binary","byte","JourneyEngine","options","diagnostics","contextId","onLocalChange","stores","fromUrl","fromStorage","fromOpenFin","opts","requested","current","token","decoded","broadcast","ownerContextId","raw","standard","missing","padding","c","remaining","timer","url","me","getOptions"],"sources":["../src/core/journey.ts"],"sourcesContent":["// src/core/journey.ts\n//\n// Manages a user journey's lifecycle across windows: encodes tokens, stores the journey and\n// ends it at expiry. Never trust a value from storage or a token, because any code on the\n// origin can write to both.\n\nimport {\n BASE64_GROUP_CHARS,\n BASE64_PADDING_PATTERN,\n BASE64_PLUS_PATTERN,\n BASE64_SLASH_PATTERN,\n BASE64URL_DASH_PATTERN,\n BASE64URL_UNDERSCORE_PATTERN,\n JOURNEY_END_ON_OWNER_CLOSE,\n JOURNEY_CLOCK_SKEW_MS,\n JOURNEY_ID_MAX_CHARS,\n JOURNEY_ID_PATTERN,\n JOURNEY_MAX_AGE_MS,\n JOURNEY_STORAGE_KEY,\n JOURNEY_TOKEN_MAX_CHARS,\n JOURNEY_TOKEN_NAME_MAX_CHARS,\n OPENFIN_JOURNEY_CUSTOM_DATA_KEY,\n JOURNEY_URL_PARAM,\n OPENFIN_OPTIONS_TIMEOUT_MS,\n} from \"../constants\";\nimport { withDeadline } from \"../utils/deadline\";\nimport { BROWSER_STORES, type IdentityStores, newId } from \"../utils/identity\";\nimport { getFin } from \"../utils/openfin\";\nimport { unrefTimer } from \"../utils/unref\";\nimport type { Diagnostics } from \"./diagnostics\";\n\n/** Lifetime rules for a journey, which is one user task spanning several contexts. */\nexport interface JourneyOptions {\n /** Maximum time a journey stays open, in milliseconds. After that the engine ends it. */\n maxAgeMs: number;\n /** True if the journey ends for all contexts when the owning context closes. */\n endOnOwnerClose: boolean;\n /** Query parameter checked at boot for a seeded journey token. */\n urlParam: string;\n}\n\n/** The journey lifetime policy in effect. Tests build an engine with shorter values. */\nexport const JOURNEY_OPTIONS: JourneyOptions = {\n maxAgeMs: JOURNEY_MAX_AGE_MS,\n endOnOwnerClose: JOURNEY_END_ON_OWNER_CLOSE,\n urlParam: JOURNEY_URL_PARAM,\n};\n\n/** User journey workflow context shared across windows and applications. */\nexport interface Journey {\n /** Unique journey correlation identifier. */\n id: string;\n /** Human-readable name of the journey's workflow. */\n name: string;\n /** Journey start timestamp in epoch milliseconds. */\n startedAt: number;\n /** Parent journey ID, set when the journey branches from an earlier one. */\n parentId?: string;\n /** Context identifier of the document that started the journey. */\n ownerContextId: string;\n}\n\n/**\n * Reads a non-empty string property from an unverified object.\n * @param source Object to read from.\n * @param key Property name.\n * @returns Non-empty string value or undefined.\n */\nfunction readString(source: object, key: string): string | undefined {\n const value: unknown = Reflect.get(source, key);\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\n/**\n * Reads a finite number property from an unverified object.\n * @param source Object to read from.\n * @param key Property name.\n * @returns Finite number value or undefined.\n */\nfunction readNumber(source: object, key: string): number | undefined {\n const value: unknown = Reflect.get(source, key);\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\n/**\n * Parses and validates an unknown value into a Journey object. The value comes from\n * sessionStorage or from another realm's bus message.\n * @param value Unverified parsed JSON value.\n * @returns Validated Journey instance or null.\n */\nexport function parseJourney(value: unknown): Journey | null {\n if (typeof value !== \"object\" || value === null) {\n return null;\n }\n const id = readString(value, \"id\");\n const name = readString(value, \"name\");\n const startedAt = readNumber(value, \"startedAt\");\n if (id === undefined || name === undefined || startedAt === undefined) {\n return null;\n }\n return {\n id,\n name,\n startedAt,\n parentId: readString(value, \"parentId\"),\n ownerContextId: readString(value, \"ownerContextId\") ?? \"\",\n };\n}\n\n/**\n * Parses and validates a decoded token payload into a Journey object.\n * @param value Unverified parsed token payload.\n * @returns Validated Journey instance or null.\n */\nfunction journeyFromTokenPayload(value: unknown): Journey | null {\n if (typeof value !== \"object\" || value === null) {\n return null;\n }\n const id = readString(value, \"i\");\n const name = readString(value, \"n\");\n const startedAt = readNumber(value, \"s\");\n // We always write a start time. A token without one, or with one from the future, would\n // never expire.\n const future = startedAt !== undefined && startedAt > Date.now() + JOURNEY_CLOCK_SKEW_MS;\n if (id === undefined || name === undefined || startedAt === undefined || future) {\n return null;\n }\n return {\n id,\n name,\n startedAt,\n parentId: undefined,\n ownerContextId: \"\",\n };\n}\n\n/**\n * Encodes journey metadata into a compact, URL-safe base64 string.\n * @param journey Journey instance to serialize.\n * @returns Unpadded base64url encoded token string.\n */\nfunction encodeToken(journey: Journey): string {\n const json = JSON.stringify({\n i: journey.id,\n n: journey.name.slice(0, JOURNEY_TOKEN_NAME_MAX_CHARS),\n s: journey.startedAt,\n });\n // Convert the UTF-8 bytes to a binary string before btoa, which throws above U+00FF.\n // Without this step, a name in a non-Latin script would fail.\n const bytes = new TextEncoder().encode(json);\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary)\n .replace(BASE64_PLUS_PATTERN, \"-\")\n .replace(BASE64_SLASH_PATTERN, \"_\")\n .replace(BASE64_PADDING_PATTERN, \"\");\n}\n\n/** Manages journey lifecycle, cross-window adoption, storage synchronization, and expiration. */\nexport class JourneyEngine {\n /** Active journey context, or null if none is in progress. */\n private journey: Journey | null = null;\n\n /** Active expiration timer handle. */\n private expiryTimer: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * @param options Journey configuration thresholds.\n * @param diagnostics Diagnostics reporter.\n * @param contextId Unique context identifier for this document.\n * @param onLocalChange Callback invoked when journey state changes locally.\n * @param stores Identity stores that hold the journey.\n */\n constructor(\n private readonly options: JourneyOptions,\n private readonly diagnostics: Diagnostics,\n private readonly contextId: string,\n private readonly onLocalChange: (journey: Journey | null) => void,\n private readonly stores: IdentityStores = BROWSER_STORES,\n ) {}\n\n /** Returns the active journey instance or null. */\n current(): Journey | null {\n return this.journey;\n }\n\n /**\n * Finds and adopts the initial journey. Keeps an active journey. Otherwise checks the URL\n * query first, then sessionStorage, then OpenFin customData.\n * @returns Promise that resolves when journey initialization completes.\n */\n async bootstrap(): Promise<void> {\n const fromUrl = this.readUrlToken();\n // A journey that the app started before configure() wins, and it moves to the stores that\n // configure() chose. Otherwise a stored journey from an earlier page would replace it. The\n // token still leaves the address bar, or a copied link would carry it to another session.\n if (this.journey) {\n if (fromUrl) {\n this.removeUrlToken();\n }\n this.setJourney(this.journey);\n return;\n }\n\n if (fromUrl && this.adopt(fromUrl, \"url\")) {\n this.removeUrlToken();\n return;\n }\n\n const fromStorage = this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not read the persisted journey.\",\n () => this.stores.session().getItem(JOURNEY_STORAGE_KEY),\n );\n if (fromStorage && this.restore(fromStorage)) {\n return;\n }\n\n const fromOpenFin = await this.readOpenFinToken();\n if (fromOpenFin !== null) {\n this.adopt(fromOpenFin, \"openfin.customData\");\n }\n }\n\n /**\n * Starts a new journey, replacing the active one and telling connected peers.\n * @param name Human-readable workflow name.\n * @param opts Optional parent linkage and pre-assigned identifier.\n * @returns Started Journey instance.\n */\n start(name: string, opts: { parent?: boolean; id?: string } = {}): Journey {\n const journey: Journey = {\n id: this.journeyId(opts.id),\n name,\n startedAt: Date.now(),\n parentId: opts.parent ? this.journey?.id : undefined,\n ownerContextId: this.contextId,\n };\n this.setJourney(journey);\n this.onLocalChange(journey);\n return journey;\n }\n\n /**\n * Picks the id for a new journey. A longer id, or one with multibyte characters, would make\n * the journey token too long for adoptJourney().\n * @param requested Id from the app, or undefined.\n * @returns The requested id when it matches JOURNEY_ID_PATTERN, otherwise a new id.\n */\n private journeyId(requested: unknown): string {\n if (requested === undefined) {\n return newId(this.diagnostics);\n }\n\n if (typeof requested === \"string\" && JOURNEY_ID_PATTERN.test(requested)) {\n return requested;\n }\n\n this.diagnostics.report(\n \"config.invalid\",\n `startJourney() needs an id of 1 to ${String(JOURNEY_ID_MAX_CHARS)} letters, digits, \"_\", \".\", \":\" or \"-\". The library uses a new id.`,\n );\n return newId(this.diagnostics);\n }\n\n /** Ends the active journey and broadcasts the change. */\n end(): void {\n if (this.journey === null) {\n return;\n }\n this.setJourney(null);\n this.onLocalChange(null);\n }\n\n /**\n * Applies a journey update from a bus peer without broadcasting it again. An echo would\n * make two windows send the change back and forth forever. A journey with the same ID as\n * the active one is ignored, so an echo can't restart the timer.\n * @param journey Updated Journey instance or null.\n */\n applyRemote(journey: Journey | null): void {\n const current = this.journey;\n if (journey !== null && current !== null && journey.id === current.id) {\n return;\n }\n this.setJourney(journey);\n }\n\n /**\n * Serializes the active journey into a compact token for URL or intent transfer.\n * @returns Base64url token, or null when no journey is active or the token exceeds the size\n * limit.\n */\n getToken(): string | null {\n const journey = this.journey;\n if (journey === null) {\n return null;\n }\n const token = encodeToken(journey);\n if (token.length > JOURNEY_TOKEN_MAX_CHARS) {\n this.diagnostics.report(\n \"journey.token_too_large\",\n \"The journey token is larger than the size limit. The library does not issue it.\",\n { length: token.length },\n );\n return null;\n }\n return token;\n }\n\n /**\n * Validates and adopts a serialized journey token.\n * @param token Base64url journey token.\n * @param source Originating source description for diagnostics.\n * @param broadcast True to send the adoption to the connected bus peers.\n * @returns True if the token was valid, unexpired, and adopted.\n */\n adopt(token: string, source: string, broadcast = false): boolean {\n const decoded = this.decodeToken(token);\n if (decoded === null) {\n return false;\n }\n if (Date.now() - decoded.startedAt > this.options.maxAgeMs) {\n this.diagnostics.report(\n \"journey.expired\",\n \"The library discarded a seeded journey older than maxAgeMs.\",\n {\n source,\n name: decoded.name,\n },\n );\n return false;\n }\n\n this.setJourney(decoded);\n this.diagnostics.report(\n \"journey.adopted\",\n `The library adopted the journey \"${decoded.name}\".`,\n {\n source,\n journeyId: decoded.id,\n },\n );\n if (broadcast) {\n this.onLocalChange(decoded);\n }\n return true;\n }\n\n /**\n * Ends the journey when endOnOwnerClose is on and the closed context owns the journey.\n * @param ownerContextId Context identifier of the closed window.\n */\n ownerClosed(ownerContextId: string): void {\n if (!this.options.endOnOwnerClose) {\n return;\n }\n if (this.journey?.ownerContextId === ownerContextId) {\n this.end();\n }\n }\n\n /** Clears pending expiration timers and releases resources on shutdown. */\n destroy(): void {\n this.clearTimer();\n }\n\n /**\n * Resumes a persisted journey from raw sessionStorage data.\n * @param raw Serialized JSON string from storage.\n * @returns True if the engine restored the journey.\n */\n private restore(raw: string): boolean {\n const parsed = this.diagnostics.guard(\n \"storage.degraded\",\n \"The library could not parse the persisted journey.\",\n () => JSON.parse(raw) as unknown,\n );\n const journey = parseJourney(parsed);\n if (journey === null) {\n return false;\n }\n\n if (Date.now() - journey.startedAt > this.options.maxAgeMs) {\n this.diagnostics.report(\n \"journey.expired\",\n \"The library discarded a persisted journey older than maxAgeMs.\",\n { name: journey.name },\n );\n this.clearStored();\n return false;\n }\n\n this.setJourney(journey);\n this.diagnostics.report(\n \"journey.adopted\",\n `The library resumed the journey \"${journey.name}\".`,\n {\n source: \"sessionStorage\",\n journeyId: journey.id,\n },\n );\n return true;\n }\n\n /**\n * Decodes a base64url token into a validated Journey object. Anyone can edit the URL\n * that holds a token, and every step throws on bad input. The guard reports the failure\n * instead of letting it throw.\n * @param token Encoded token string.\n * @returns Decoded Journey instance or null on decode error.\n */\n private decodeToken(token: string): Journey | null {\n const decoded = this.diagnostics.guard(\n \"config.invalid\",\n \"The library could not decode a seeded journey token.\",\n () => {\n const standard = token\n .replace(BASE64URL_DASH_PATTERN, \"+\")\n .replace(BASE64URL_UNDERSCORE_PATTERN, \"/\");\n const missing =\n (BASE64_GROUP_CHARS - (standard.length % BASE64_GROUP_CHARS)) % BASE64_GROUP_CHARS;\n const padding = \"=\".repeat(missing);\n const bytes = Uint8Array.from(atob(standard + padding), (c) => c.charCodeAt(0));\n return journeyFromTokenPayload(JSON.parse(new TextDecoder().decode(bytes)) as unknown);\n },\n );\n return decoded ?? null;\n }\n\n /**\n * Sets the active journey, updates sessionStorage, and schedules expiration.\n * @param journey Target Journey instance or null.\n */\n private setJourney(journey: Journey | null): void {\n this.journey = journey;\n this.clearTimer();\n\n this.diagnostics.guard(\"storage.unavailable\", \"The library could not save the journey.\", () => {\n if (journey !== null) {\n this.stores.session().setItem(JOURNEY_STORAGE_KEY, JSON.stringify(journey));\n } else {\n this.stores.session().removeItem(JOURNEY_STORAGE_KEY);\n }\n });\n\n if (journey === null) {\n return;\n }\n\n const remaining = Math.max(this.options.maxAgeMs - (Date.now() - journey.startedAt), 0);\n const timer = setTimeout(() => {\n this.diagnostics.report(\n \"journey.expired\",\n `The journey \"${journey.name}\" reached maxAgeMs. The library ended it.`,\n { journeyId: journey.id },\n );\n this.journey = null;\n this.expiryTimer = null;\n this.clearStored();\n }, remaining);\n this.expiryTimer = timer;\n unrefTimer(timer);\n }\n\n /** Removes journey data from the session store. */\n private clearStored(): void {\n this.diagnostics.guard(\n \"storage.unavailable\",\n \"The library could not clear the persisted journey.\",\n () => {\n this.stores.session().removeItem(JOURNEY_STORAGE_KEY);\n },\n );\n }\n\n /** Cancels any active expiration timer. */\n private clearTimer(): void {\n if (this.expiryTimer !== null) {\n clearTimeout(this.expiryTimer);\n this.expiryTimer = null;\n }\n }\n\n /**\n * Extracts the journey token from the current window location search parameters.\n * @returns Token string or null.\n */\n private readUrlToken(): string | null {\n const token = this.diagnostics.guard(\n \"config.invalid\",\n \"The library could not read the journey token from the URL.\",\n () => {\n if (typeof location === \"undefined\") {\n return null;\n }\n return new URL(location.href).searchParams.get(this.options.urlParam);\n },\n );\n return token ?? null;\n }\n\n /**\n * Removes the journey token from the address bar once the engine has adopted it.\n * Otherwise a copied or bookmarked link would start the same journey in another session.\n */\n private removeUrlToken(): void {\n this.diagnostics.guard(\n \"platform.api_blocked\",\n \"The library could not remove the journey token from the URL.\",\n () => {\n const url = new URL(location.href);\n url.searchParams.delete(this.options.urlParam);\n // Keep history.state, because a router stores its own state there.\n history.replaceState(history.state, \"\", url.href);\n },\n );\n }\n\n /**\n * Reads the journey token from customData in the OpenFin window options. The wait is\n * capped by OPENFIN_OPTIONS_TIMEOUT_MS. At the deadline we report openfin.unavailable and\n * return no token. A window with no token gives the same result.\n * @returns Promise that resolves to the token string or null.\n */\n private async readOpenFinToken(): Promise<string | null> {\n const me = getFin()?.me;\n const getOptions = me?.getOptions;\n if (getOptions === undefined) {\n return null;\n }\n\n // Use call so the native OpenFin method keeps its receiver. A detached copy throws when\n // called.\n const options = await this.diagnostics.guardAsync(\n \"openfin.unavailable\",\n \"The library could not read fin.me.getOptions().\",\n () => withDeadline(getOptions.call(me), OPENFIN_OPTIONS_TIMEOUT_MS),\n );\n const token = options?.customData?.[OPENFIN_JOURNEY_CUSTOM_DATA_KEY];\n return typeof token === \"string\" ? token : null;\n }\n}\n"],"mappings":"A,uOA0CA,IAAaqB,EAAkC,CAC7C,SAAUrB,EAAAA,GACV,gBAAA,GACA,SAAUC,EAAAA,EACZ,EAsBA,SAASqB,EAAW,EAAgB,EAAiC,CACnE,IAAMC,EAAiB,QAAQ,IAAIC,EAAQC,CAAG,EAC9C,OAAO,OAAOF,GAAU,UAAYA,IAAU,GAAKA,EAAQ,IAAA,EAC7D,CAQA,SAASG,EAAW,EAAgB,EAAiC,CACnE,IAAM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./global-scope-BN-Io_yv.cjs").t(e.Et);function n(e){return t.run(e)}function r(){return t.open()}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
2
- //# sourceMappingURL=library-console-BFWEuQsl.cjs.map
1
+ const e=require("./constants-CtF52hIV.cjs");var t=require("./global-scope-BN-Io_yv.cjs").t(e.jt);function n(e){return t.run(e)}function r(){return t.open()}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}});
2
+ //# sourceMappingURL=library-console-DJUQzcgM.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"library-console-BFWEuQsl.cjs","names":["globalScope","LIBRARY_CONSOLE_KEY","require_constants","scope","runAsLibraryConsole","fn","isLibraryConsole"],"sources":["../src/utils/library-console.ts"],"sourcesContent":["// src/utils/library-console.ts\n//\n// Marks the console calls that the library makes itself, so the console capture can skip them.\n// Without the scope, the capture would record every mirrored line again in an endless loop.\n\nimport { LIBRARY_CONSOLE_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own console calls. */\nconst scope = globalScope(LIBRARY_CONSOLE_KEY);\n\n/**\n * Runs a function inside the library console scope.\n * @param fn The function that writes to the console.\n * @returns The function's return value.\n */\nexport function runAsLibraryConsole<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library console scope is open.\n * @returns True while the library is writing to the console.\n */\nexport function isLibraryConsole(): boolean {\n return scope.open();\n}\n"],"mappings":"A,4CASA,IAAMG,E,qCAAQH,CAAAA,CAAAA,EAAYC,EAAAA,EAAmB,EAO7C,SAAgBG,EAAuB,EAAgB,CACrD,OAAOD,EAAM,IAAIE,CAAE,CACrB,CAMA,SAAgBC,GAA4B,CAC1C,OAAOH,EAAM,KAAK,CACpB,C"}
1
+ {"version":3,"file":"library-console-DJUQzcgM.cjs","names":["globalScope","LIBRARY_CONSOLE_KEY","require_constants","scope","runAsLibraryConsole","fn","isLibraryConsole"],"sources":["../src/utils/library-console.ts"],"sourcesContent":["// src/utils/library-console.ts\n//\n// Marks the console calls that the library makes itself, so the console capture can skip them.\n// Without the scope, the capture would record every mirrored line again in an endless loop.\n\nimport { LIBRARY_CONSOLE_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own console calls. */\nconst scope = globalScope(LIBRARY_CONSOLE_KEY);\n\n/**\n * Runs a function inside the library console scope.\n * @param fn The function that writes to the console.\n * @returns The function's return value.\n */\nexport function runAsLibraryConsole<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library console scope is open.\n * @returns True while the library is writing to the console.\n */\nexport function isLibraryConsole(): boolean {\n return scope.open();\n}\n"],"mappings":"A,4CASA,IAAMG,E,qCAAQH,CAAAA,CAAAA,EAAYC,EAAAA,EAAmB,EAO7C,SAAgBG,EAAuB,EAAgB,CACrD,OAAOD,EAAM,IAAIE,CAAE,CACrB,CAMA,SAAgBC,GAA4B,CAC1C,OAAOH,EAAM,KAAK,CACpB,C"}
@@ -1,4 +1,4 @@
1
- import { Et as e } from "./constants-Bwl_YtQi.js";
1
+ import { jt as e } from "./constants-BwJDXzj6.js";
2
2
  import { t } from "./global-scope-D9I8s-oN.js";
3
3
  // src/utils/library-console.ts
4
4
  var n = t(e);
@@ -10,4 +10,4 @@ function i() {
10
10
  }
11
11
  export { r as n, i as t };
12
12
 
13
- //# sourceMappingURL=library-console-Dl_Ly6DQ.js.map
13
+ //# sourceMappingURL=library-console-DklSmucS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"library-console-Dl_Ly6DQ.js","names":["LIBRARY_CONSOLE_KEY","scope","globalScope","runAsLibraryConsole","fn","isLibraryConsole"],"sources":["../src/utils/library-console.ts"],"sourcesContent":["// src/utils/library-console.ts\n//\n// Marks the console calls that the library makes itself, so the console capture can skip them.\n// Without the scope, the capture would record every mirrored line again in an endless loop.\n\nimport { LIBRARY_CONSOLE_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own console calls. */\nconst scope = globalScope(LIBRARY_CONSOLE_KEY);\n\n/**\n * Runs a function inside the library console scope.\n * @param fn The function that writes to the console.\n * @returns The function's return value.\n */\nexport function runAsLibraryConsole<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library console scope is open.\n * @returns True while the library is writing to the console.\n */\nexport function isLibraryConsole(): boolean {\n return scope.open();\n}\n"],"mappings":";;;AASA,IAAMC,IAAQC,EAAYF,CAAmB;AAO7C,SAAgBG,EAAuB,GAAgB;CACrD,OAAOF,EAAM,IAAIG,CAAE;AACrB;AAMA,SAAgBC,IAA4B;CAC1C,OAAOJ,EAAM,KAAK;AACpB"}
1
+ {"version":3,"file":"library-console-DklSmucS.js","names":["LIBRARY_CONSOLE_KEY","scope","globalScope","runAsLibraryConsole","fn","isLibraryConsole"],"sources":["../src/utils/library-console.ts"],"sourcesContent":["// src/utils/library-console.ts\n//\n// Marks the console calls that the library makes itself, so the console capture can skip them.\n// Without the scope, the capture would record every mirrored line again in an endless loop.\n\nimport { LIBRARY_CONSOLE_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own console calls. */\nconst scope = globalScope(LIBRARY_CONSOLE_KEY);\n\n/**\n * Runs a function inside the library console scope.\n * @param fn The function that writes to the console.\n * @returns The function's return value.\n */\nexport function runAsLibraryConsole<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library console scope is open.\n * @returns True while the library is writing to the console.\n */\nexport function isLibraryConsole(): boolean {\n return scope.open();\n}\n"],"mappings":";;;AASA,IAAMC,IAAQC,EAAYF,CAAmB;AAO7C,SAAgBG,EAAuB,GAAgB;CACrD,OAAOF,EAAM,IAAIG,CAAE;AACrB;AAMA,SAAgBC,IAA4B;CAC1C,OAAOJ,EAAM,KAAK;AACpB"}
@@ -1,4 +1,4 @@
1
- import { Ot as e, Yn as t } from "./constants-Bwl_YtQi.js";
1
+ import { Nt as e, sr as t } from "./constants-BwJDXzj6.js";
2
2
  import { t as n } from "./global-scope-D9I8s-oN.js";
3
3
  // src/utils/library-request.ts
4
4
  var r = n(e), i = Symbol.for(t), a = globalThis, o = () => a[i] ?? 0;
@@ -21,4 +21,4 @@ function u() {
21
21
  }
22
22
  export { l as i, u as n, s as r, c as t };
23
23
 
24
- //# sourceMappingURL=library-request-nI6pvI6I.js.map
24
+ //# sourceMappingURL=library-request-UGEwOHpf.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"library-request-nI6pvI6I.js","names":["LIBRARY_REQUEST_KEY","TRANSPORT_CALL_KEY","globalScope","scope","calls","store","pending","runAsLibraryRequest","fn","isLibraryRequest","trackTransportCall","isTransportPending"],"sources":["../src/utils/library-request.ts"],"sourcesContent":["// src/utils/library-request.ts\n//\n// Marks the requests that the library starts itself, so network capture can skip them. A\n// captured library request would log a record, the library would send that record with\n// another request, and the loop would never stop.\n\nimport { LIBRARY_REQUEST_KEY, TRANSPORT_CALL_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own requests. */\nconst scope = globalScope(LIBRARY_REQUEST_KEY);\n\n/** Global count of custom transport calls that are still waiting for an answer. */\nconst calls = Symbol.for(TRANSPORT_CALL_KEY);\nconst store = globalThis as unknown as Record<symbol, number | undefined>;\nconst pending = (): number => store[calls] ?? 0;\n\n/**\n * Runs a function inside the library request scope. Only the synchronous part of the function\n * is covered, so a request that starts after an await is outside the scope.\n * @param fn The function that starts the request.\n * @returns The function's return value.\n */\nexport function runAsLibraryRequest<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library request scope is open.\n * @returns True while the library is starting a request.\n */\nexport function isLibraryRequest(): boolean {\n return scope.open();\n}\n\n/**\n * Runs a custom transport call and counts it until it settles. The count includes the time after\n * each await, which the library request scope does not cover.\n * @param fn The function that calls the custom transport.\n * @returns A promise that settles with the call's result.\n */\nexport async function trackTransportCall<T>(fn: () => T | PromiseLike<T>): Promise<T> {\n store[calls] = pending() + 1;\n\n try {\n return await fn();\n } finally {\n store[calls] = pending() - 1;\n }\n}\n\n/**\n * Checks whether a custom transport call is still waiting for an answer.\n * @returns True while a call hasn't settled.\n */\nexport function isTransportPending(): boolean {\n return pending() > 0;\n}\n"],"mappings":";;;AAUA,IAAMG,IAAQD,EAAYF,CAAmB,GAGvCI,IAAQ,OAAO,IAAIH,CAAkB,GACrCI,IAAQ,YACRC,UAAwBD,EAAMD,MAAU;AAQ9C,SAAgBG,EAAuB,GAAgB;CACrD,OAAOJ,EAAM,IAAIK,CAAE;AACrB;AAMA,SAAgBC,IAA4B;CAC1C,OAAON,EAAM,KAAK;AACpB;AAQA,eAAsBO,EAAsB,GAA0C;CACpF,EAAMN,KAASE,EAAQ,IAAI;CAE3B,IAAI;EACF,OAAO,MAAME,EAAG;CAClB,UAAU;EACR,EAAMJ,KAASE,EAAQ,IAAI;CAC7B;AACF;AAMA,SAAgBK,IAA8B;CAC5C,OAAOL,EAAQ,IAAI;AACrB"}
1
+ {"version":3,"file":"library-request-UGEwOHpf.js","names":["LIBRARY_REQUEST_KEY","TRANSPORT_CALL_KEY","globalScope","scope","calls","store","pending","runAsLibraryRequest","fn","isLibraryRequest","trackTransportCall","isTransportPending"],"sources":["../src/utils/library-request.ts"],"sourcesContent":["// src/utils/library-request.ts\n//\n// Marks the requests that the library starts itself, so network capture can skip them. A\n// captured library request would log a record, the library would send that record with\n// another request, and the loop would never stop.\n\nimport { LIBRARY_REQUEST_KEY, TRANSPORT_CALL_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own requests. */\nconst scope = globalScope(LIBRARY_REQUEST_KEY);\n\n/** Global count of custom transport calls that are still waiting for an answer. */\nconst calls = Symbol.for(TRANSPORT_CALL_KEY);\nconst store = globalThis as unknown as Record<symbol, number | undefined>;\nconst pending = (): number => store[calls] ?? 0;\n\n/**\n * Runs a function inside the library request scope. Only the synchronous part of the function\n * is covered, so a request that starts after an await is outside the scope.\n * @param fn The function that starts the request.\n * @returns The function's return value.\n */\nexport function runAsLibraryRequest<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library request scope is open.\n * @returns True while the library is starting a request.\n */\nexport function isLibraryRequest(): boolean {\n return scope.open();\n}\n\n/**\n * Runs a custom transport call and counts it until it settles. The count includes the time after\n * each await, which the library request scope does not cover.\n * @param fn The function that calls the custom transport.\n * @returns A promise that settles with the call's result.\n */\nexport async function trackTransportCall<T>(fn: () => T | PromiseLike<T>): Promise<T> {\n store[calls] = pending() + 1;\n\n try {\n return await fn();\n } finally {\n store[calls] = pending() - 1;\n }\n}\n\n/**\n * Checks whether a custom transport call is still waiting for an answer.\n * @returns True while a call hasn't settled.\n */\nexport function isTransportPending(): boolean {\n return pending() > 0;\n}\n"],"mappings":";;;AAUA,IAAMG,IAAQD,EAAYF,CAAmB,GAGvCI,IAAQ,OAAO,IAAIH,CAAkB,GACrCI,IAAQ,YACRC,UAAwBD,EAAMD,MAAU;AAQ9C,SAAgBG,EAAuB,GAAgB;CACrD,OAAOJ,EAAM,IAAIK,CAAE;AACrB;AAMA,SAAgBC,IAA4B;CAC1C,OAAON,EAAM,KAAK;AACpB;AAQA,eAAsBO,EAAsB,GAA0C;CACpF,EAAMN,KAASE,EAAQ,IAAI;CAE3B,IAAI;EACF,OAAO,MAAME,EAAG;CAClB,UAAU;EACR,EAAMJ,KAASE,EAAQ,IAAI;CAC7B;AACF;AAMA,SAAgBK,IAA8B;CAC5C,OAAOL,EAAQ,IAAI;AACrB"}
@@ -1,2 +1,2 @@
1
- const e=require("./constants-DakMxVB2.cjs");var t=require("./global-scope-BN-Io_yv.cjs").t(e.Ot),n=Symbol.for(e.Yn),r=globalThis,i=()=>r[n]??0;function a(e){return t.run(e)}function o(){return t.open()}async function s(e){r[n]=i()+1;try{return await e()}finally{r[n]=i()-1}}function c(){return i()>0}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
2
- //# sourceMappingURL=library-request-Da-CHKzT.cjs.map
1
+ const e=require("./constants-CtF52hIV.cjs");var t=require("./global-scope-BN-Io_yv.cjs").t(e.Nt),n=Symbol.for(e.sr),r=globalThis,i=()=>r[n]??0;function a(e){return t.run(e)}function o(){return t.open()}async function s(e){r[n]=i()+1;try{return await e()}finally{r[n]=i()-1}}function c(){return i()>0}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
2
+ //# sourceMappingURL=library-request-kY9iTpIF.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"library-request-Da-CHKzT.cjs","names":["globalScope","LIBRARY_REQUEST_KEY","TRANSPORT_CALL_KEY","require_constants","scope","calls","store","pending","runAsLibraryRequest","fn","isLibraryRequest","trackTransportCall","isTransportPending"],"sources":["../src/utils/library-request.ts"],"sourcesContent":["// src/utils/library-request.ts\n//\n// Marks the requests that the library starts itself, so network capture can skip them. A\n// captured library request would log a record, the library would send that record with\n// another request, and the loop would never stop.\n\nimport { LIBRARY_REQUEST_KEY, TRANSPORT_CALL_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own requests. */\nconst scope = globalScope(LIBRARY_REQUEST_KEY);\n\n/** Global count of custom transport calls that are still waiting for an answer. */\nconst calls = Symbol.for(TRANSPORT_CALL_KEY);\nconst store = globalThis as unknown as Record<symbol, number | undefined>;\nconst pending = (): number => store[calls] ?? 0;\n\n/**\n * Runs a function inside the library request scope. Only the synchronous part of the function\n * is covered, so a request that starts after an await is outside the scope.\n * @param fn The function that starts the request.\n * @returns The function's return value.\n */\nexport function runAsLibraryRequest<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library request scope is open.\n * @returns True while the library is starting a request.\n */\nexport function isLibraryRequest(): boolean {\n return scope.open();\n}\n\n/**\n * Runs a custom transport call and counts it until it settles. The count includes the time after\n * each await, which the library request scope does not cover.\n * @param fn The function that calls the custom transport.\n * @returns A promise that settles with the call's result.\n */\nexport async function trackTransportCall<T>(fn: () => T | PromiseLike<T>): Promise<T> {\n store[calls] = pending() + 1;\n\n try {\n return await fn();\n } finally {\n store[calls] = pending() - 1;\n }\n}\n\n/**\n * Checks whether a custom transport call is still waiting for an answer.\n * @returns True while a call hasn't settled.\n */\nexport function isTransportPending(): boolean {\n return pending() > 0;\n}\n"],"mappings":"A,4CAUA,IAAMI,E,qCAAQJ,CAAAA,CAAAA,EAAYC,EAAAA,EAAmB,EAGvCI,EAAQ,OAAO,IAAIH,EAAAA,EAAkB,EACrCI,EAAQ,WACRC,MAAwBD,EAAMD,IAAU,EAQ9C,SAAgBG,EAAuB,EAAgB,CACrD,OAAOJ,EAAM,IAAIK,CAAE,CACrB,CAMA,SAAgBC,GAA4B,CAC1C,OAAON,EAAM,KAAK,CACpB,CAQA,eAAsBO,EAAsB,EAA0C,CACpF,EAAMN,GAASE,EAAQ,EAAI,EAE3B,GAAI,CACF,OAAO,MAAME,EAAG,CAClB,QAAU,CACR,EAAMJ,GAASE,EAAQ,EAAI,CAC7B,CACF,CAMA,SAAgBK,GAA8B,CAC5C,OAAOL,EAAQ,EAAI,CACrB,C"}
1
+ {"version":3,"file":"library-request-kY9iTpIF.cjs","names":["globalScope","LIBRARY_REQUEST_KEY","TRANSPORT_CALL_KEY","require_constants","scope","calls","store","pending","runAsLibraryRequest","fn","isLibraryRequest","trackTransportCall","isTransportPending"],"sources":["../src/utils/library-request.ts"],"sourcesContent":["// src/utils/library-request.ts\n//\n// Marks the requests that the library starts itself, so network capture can skip them. A\n// captured library request would log a record, the library would send that record with\n// another request, and the loop would never stop.\n\nimport { LIBRARY_REQUEST_KEY, TRANSPORT_CALL_KEY } from \"../constants\";\nimport { globalScope } from \"./global-scope\";\n\n/** The scope for the library's own requests. */\nconst scope = globalScope(LIBRARY_REQUEST_KEY);\n\n/** Global count of custom transport calls that are still waiting for an answer. */\nconst calls = Symbol.for(TRANSPORT_CALL_KEY);\nconst store = globalThis as unknown as Record<symbol, number | undefined>;\nconst pending = (): number => store[calls] ?? 0;\n\n/**\n * Runs a function inside the library request scope. Only the synchronous part of the function\n * is covered, so a request that starts after an await is outside the scope.\n * @param fn The function that starts the request.\n * @returns The function's return value.\n */\nexport function runAsLibraryRequest<T>(fn: () => T): T {\n return scope.run(fn);\n}\n\n/**\n * Checks whether a library request scope is open.\n * @returns True while the library is starting a request.\n */\nexport function isLibraryRequest(): boolean {\n return scope.open();\n}\n\n/**\n * Runs a custom transport call and counts it until it settles. The count includes the time after\n * each await, which the library request scope does not cover.\n * @param fn The function that calls the custom transport.\n * @returns A promise that settles with the call's result.\n */\nexport async function trackTransportCall<T>(fn: () => T | PromiseLike<T>): Promise<T> {\n store[calls] = pending() + 1;\n\n try {\n return await fn();\n } finally {\n store[calls] = pending() - 1;\n }\n}\n\n/**\n * Checks whether a custom transport call is still waiting for an answer.\n * @returns True while a call hasn't settled.\n */\nexport function isTransportPending(): boolean {\n return pending() > 0;\n}\n"],"mappings":"A,4CAUA,IAAMI,E,qCAAQJ,CAAAA,CAAAA,EAAYC,EAAAA,EAAmB,EAGvCI,EAAQ,OAAO,IAAIH,EAAAA,EAAkB,EACrCI,EAAQ,WACRC,MAAwBD,EAAMD,IAAU,EAQ9C,SAAgBG,EAAuB,EAAgB,CACrD,OAAOJ,EAAM,IAAIK,CAAE,CACrB,CAMA,SAAgBC,GAA4B,CAC1C,OAAON,EAAM,KAAK,CACpB,CAQA,eAAsBO,EAAsB,EAA0C,CACpF,EAAMN,GAASE,EAAQ,EAAI,EAE3B,GAAI,CACF,OAAO,MAAME,EAAG,CAClB,QAAU,CACR,EAAMJ,GAASE,EAAQ,EAAI,CAC7B,CACF,CAMA,SAAgBK,GAA8B,CAC5C,OAAOL,EAAQ,EAAI,CACrB,C"}