@utk09/ui-observability 0.10.0 → 0.12.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 (406) hide show
  1. package/CHANGELOG.md +77 -1
  2. package/README.md +323 -113
  3. package/bin/uiobs.mjs +1 -1
  4. package/dist/{batch-BMdT9mKm.js → batch-BjQUwjA6.js} +5 -6
  5. package/dist/batch-BjQUwjA6.js.map +1 -0
  6. package/dist/{batch-BHXypM1j.cjs → batch-D5LlU4Q9.cjs} +2 -2
  7. package/dist/batch-D5LlU4Q9.cjs.map +1 -0
  8. package/dist/bus/bus.d.ts +48 -47
  9. package/dist/bus/links.d.ts +4 -4
  10. package/dist/bus/validation.d.ts +1 -1
  11. package/dist/bus-D_7pd7RN.cjs +2 -0
  12. package/dist/bus-D_7pd7RN.cjs.map +1 -0
  13. package/dist/{bus-DKfBaica.js → bus-ecxUNTja.js} +105 -109
  14. package/dist/bus-ecxUNTja.js.map +1 -0
  15. package/dist/capture/console.d.ts +10 -10
  16. package/dist/capture/errors.d.ts +6 -6
  17. package/dist/capture/interactions.d.ts +14 -14
  18. package/dist/capture/lifecycle.d.ts +3 -3
  19. package/dist/capture/long-frames.d.ts +6 -6
  20. package/dist/capture/network.d.ts +17 -17
  21. package/dist/capture/profiler-frames.d.ts +44 -0
  22. package/dist/capture/replay-buffer.d.ts +46 -0
  23. package/dist/capture/replay-upload.d.ts +74 -0
  24. package/dist/capture/replay.d.ts +114 -0
  25. package/dist/capture/reports.d.ts +2 -2
  26. package/dist/capture/resource-timing.d.ts +1 -1
  27. package/dist/capture/server-timing.d.ts +3 -3
  28. package/dist/capture/storm.d.ts +3 -3
  29. package/dist/capture/types.d.ts +45 -33
  30. package/dist/capture/unclean-exit.d.ts +8 -8
  31. package/dist/capture/user-timing.d.ts +3 -3
  32. package/dist/capture/web-socket.d.ts +11 -11
  33. package/dist/capture/web-vitals.d.ts +20 -7
  34. package/dist/compression-AJJCMBOa.js +11 -0
  35. package/dist/compression-AJJCMBOa.js.map +1 -0
  36. package/dist/compression-lD9abCcO.cjs +2 -0
  37. package/dist/compression-lD9abCcO.cjs.map +1 -0
  38. package/dist/console-CLz_PvFn.cjs +2 -0
  39. package/dist/console-CLz_PvFn.cjs.map +1 -0
  40. package/dist/{console-BX_0UCV7.js → console-cwgHKXvM.js} +14 -15
  41. package/dist/console-cwgHKXvM.js.map +1 -0
  42. package/dist/constants-Bwl_YtQi.js +349 -0
  43. package/dist/constants-Bwl_YtQi.js.map +1 -0
  44. package/dist/constants-DakMxVB2.cjs +2 -0
  45. package/dist/constants-DakMxVB2.cjs.map +1 -0
  46. package/dist/constants.d.ts +150 -103
  47. package/dist/context-storage-BjzeBSxH.cjs.map +1 -1
  48. package/dist/{context-storage-DxZf4Gfh.js → context-storage-BzkoHzkQ.js} +2 -3
  49. package/dist/context-storage-BzkoHzkQ.js.map +1 -0
  50. package/dist/core/breadcrumbs.d.ts +16 -15
  51. package/dist/core/config.d.ts +3 -3
  52. package/dist/core/context.d.ts +7 -7
  53. package/dist/core/debug-buffer.d.ts +10 -10
  54. package/dist/core/debug-bundle.d.ts +3 -3
  55. package/dist/core/deferred.d.ts +2 -2
  56. package/dist/core/diagnostics.d.ts +24 -21
  57. package/dist/core/drops.d.ts +7 -7
  58. package/dist/core/hold-buffer.d.ts +1 -1
  59. package/dist/core/journey.d.ts +22 -23
  60. package/dist/core/logger.d.ts +22 -21
  61. package/dist/core/measure.d.ts +7 -7
  62. package/dist/core/meter.d.ts +25 -21
  63. package/dist/core/pipeline.d.ts +42 -41
  64. package/dist/core/profile-buckets.d.ts +31 -0
  65. package/dist/core/profiler.d.ts +218 -0
  66. package/dist/core/record.d.ts +23 -23
  67. package/dist/core/remote-rules.d.ts +4 -4
  68. package/dist/core/remote-sampling.d.ts +21 -20
  69. package/dist/core/runtime.d.ts +206 -137
  70. package/dist/core/sampling.d.ts +18 -18
  71. package/dist/core/sender.d.ts +22 -20
  72. package/dist/core/spans.d.ts +5 -5
  73. package/dist/{deadline-5_PecIl5.js → deadline-C4ccAuk5.js} +4 -9
  74. package/dist/deadline-C4ccAuk5.js.map +1 -0
  75. package/dist/deadline-CUGbto-y.cjs +2 -0
  76. package/dist/deadline-CUGbto-y.cjs.map +1 -0
  77. package/dist/{debug-bundle-CZZ6SQQh.js → debug-bundle-BOdYmCeV.js} +12 -6
  78. package/dist/debug-bundle-BOdYmCeV.js.map +1 -0
  79. package/dist/debug-bundle-Ex4L_LSP.cjs +2 -0
  80. package/dist/debug-bundle-Ex4L_LSP.cjs.map +1 -0
  81. package/dist/doctor.cjs +1 -1
  82. package/dist/doctor.cjs.map +1 -1
  83. package/dist/doctor.d.ts +16 -6
  84. package/dist/doctor.js +148 -54
  85. package/dist/doctor.js.map +1 -1
  86. package/dist/{emergency-queue-Cs8-i2xw.js → emergency-queue-B9WZxanZ.js} +15 -17
  87. package/dist/emergency-queue-B9WZxanZ.js.map +1 -0
  88. package/dist/{emergency-queue-CQ-9acZf.cjs → emergency-queue-HBpL5r3V.cjs} +2 -2
  89. package/dist/emergency-queue-HBpL5r3V.cjs.map +1 -0
  90. package/dist/{error-like-Ywo5uRHo.js → error-like-B11pB4aL.js} +2 -3
  91. package/dist/error-like-B11pB4aL.js.map +1 -0
  92. package/dist/error-like-gGRx2s36.cjs.map +1 -1
  93. package/dist/{errors-oyxrpHjY.js → errors-D6bwgJtO.js} +5 -6
  94. package/dist/errors-D6bwgJtO.js.map +1 -0
  95. package/dist/{errors-CigX45pL.cjs → errors-DCOCRdSi.cjs} +2 -2
  96. package/dist/errors-DCOCRdSi.cjs.map +1 -0
  97. package/dist/{factory-BkjNzPYL.cjs → factory-DLFDjdLv.cjs} +2 -2
  98. package/dist/factory-DLFDjdLv.cjs.map +1 -0
  99. package/dist/{factory-Bgsky_e0.js → factory-e9Qo3K0z.js} +18 -22
  100. package/dist/factory-e9Qo3K0z.js.map +1 -0
  101. package/dist/fixed-window-CvESpFYV.cjs.map +1 -1
  102. package/dist/{fixed-window-CtaFHanJ.js → fixed-window-Dq3MLUUv.js} +2 -3
  103. package/dist/fixed-window-Dq3MLUUv.js.map +1 -0
  104. package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
  105. package/dist/{global-scope-dp2jADRl.js → global-scope-D9I8s-oN.js} +2 -3
  106. package/dist/global-scope-D9I8s-oN.js.map +1 -0
  107. package/dist/{guards-CpvOpJL6.js → guards-Cidk71ME.js} +2 -3
  108. package/dist/guards-Cidk71ME.js.map +1 -0
  109. package/dist/guards-nJ70syPt.cjs.map +1 -1
  110. package/dist/{identity-BMlKGHUM.cjs → identity-BlvlgjrU.cjs} +2 -2
  111. package/dist/identity-BlvlgjrU.cjs.map +1 -0
  112. package/dist/{identity-DOaHdfhT.js → identity-BrQp_5J5.js} +20 -21
  113. package/dist/identity-BrQp_5J5.js.map +1 -0
  114. package/dist/index.cjs +1 -1
  115. package/dist/index.cjs.map +1 -1
  116. package/dist/index.d.ts +112 -79
  117. package/dist/index.js +797 -659
  118. package/dist/index.js.map +1 -1
  119. package/dist/{indexeddb-storage-CaXGJqDD.cjs → indexeddb-storage-CtLvZH1r.cjs} +2 -2
  120. package/dist/indexeddb-storage-CtLvZH1r.cjs.map +1 -0
  121. package/dist/{indexeddb-storage-D-lUW_5P.js → indexeddb-storage-DLXQzAGh.js} +5 -6
  122. package/dist/indexeddb-storage-DLXQzAGh.js.map +1 -0
  123. package/dist/{interactions-CqDNrtIR.js → interactions-B6z2I4tU.js} +10 -11
  124. package/dist/interactions-B6z2I4tU.js.map +1 -0
  125. package/dist/{interactions-8DgxtmgO.cjs → interactions-P6pz08Jn.cjs} +2 -2
  126. package/dist/interactions-P6pz08Jn.cjs.map +1 -0
  127. package/dist/{journey-DgIjhrIc.js → journey-35yCMNFo.js} +21 -21
  128. package/dist/journey-35yCMNFo.js.map +1 -0
  129. package/dist/journey-DAGh5h9k.cjs +2 -0
  130. package/dist/journey-DAGh5h9k.cjs.map +1 -0
  131. package/dist/keys-BHhw_0Wh.cjs.map +1 -1
  132. package/dist/{keys-D5r_GH9q.js → keys-BU9j5YqW.js} +2 -3
  133. package/dist/keys-BU9j5YqW.js.map +1 -0
  134. package/dist/{library-console-g_VU-wzP.cjs → library-console-BFWEuQsl.cjs} +2 -2
  135. package/dist/library-console-BFWEuQsl.cjs.map +1 -0
  136. package/dist/library-console-Dl_Ly6DQ.js +13 -0
  137. package/dist/library-console-Dl_Ly6DQ.js.map +1 -0
  138. package/dist/{library-request-FQaiWjCP.cjs → library-request-Da-CHKzT.cjs} +2 -2
  139. package/dist/library-request-Da-CHKzT.cjs.map +1 -0
  140. package/dist/{library-request-CyC-9IOk.js → library-request-nI6pvI6I.js} +4 -5
  141. package/dist/library-request-nI6pvI6I.js.map +1 -0
  142. package/dist/{lifecycle-C2z_d8OX.cjs → lifecycle-BGGOcN4N.cjs} +2 -2
  143. package/dist/lifecycle-BGGOcN4N.cjs.map +1 -0
  144. package/dist/{lifecycle-BLC4VU7c.js → lifecycle-CZ6RRXc6.js} +3 -4
  145. package/dist/lifecycle-CZ6RRXc6.js.map +1 -0
  146. package/dist/{log-record-DKvo-B-d.cjs → log-record-D7bA1RPb.cjs} +2 -2
  147. package/dist/log-record-D7bA1RPb.cjs.map +1 -0
  148. package/dist/{log-record-CndanC-p.js → log-record-DIA6McNr.js} +3 -4
  149. package/dist/log-record-DIA6McNr.js.map +1 -0
  150. package/dist/{long-frames-BQef9rXR.js → long-frames-430_85Da.js} +9 -8
  151. package/dist/long-frames-430_85Da.js.map +1 -0
  152. package/dist/long-frames-Dd8tsi2U.cjs +2 -0
  153. package/dist/long-frames-Dd8tsi2U.cjs.map +1 -0
  154. package/dist/models/batch.d.ts +14 -15
  155. package/dist/models/bus.d.ts +24 -24
  156. package/dist/models/config.d.ts +402 -216
  157. package/dist/models/drop.d.ts +13 -11
  158. package/dist/models/health.d.ts +13 -13
  159. package/dist/models/log-record.d.ts +13 -14
  160. package/dist/models/metric.d.ts +82 -17
  161. package/dist/models/plugin.d.ts +13 -13
  162. package/dist/models/replay.d.ts +60 -0
  163. package/dist/models/serializer.d.ts +2 -3
  164. package/dist/models/stats.d.ts +2 -2
  165. package/dist/models/storage.d.ts +12 -11
  166. package/dist/{network-CvkvYzRU.js → network-C7SkLf4v.js} +30 -32
  167. package/dist/network-C7SkLf4v.js.map +1 -0
  168. package/dist/{network-CqnQOqon.cjs → network-pEX3PAJv.cjs} +2 -2
  169. package/dist/network-pEX3PAJv.cjs.map +1 -0
  170. package/dist/openfin-Bxelt0yg.js +7 -0
  171. package/dist/openfin-Bxelt0yg.js.map +1 -0
  172. package/dist/openfin-DtH2f7zX.cjs.map +1 -1
  173. package/dist/otlp-2MCrC3kd.cjs +2 -0
  174. package/dist/otlp-2MCrC3kd.cjs.map +1 -0
  175. package/dist/{otlp-CYIL7MOE.js → otlp-COq033e3.js} +26 -35
  176. package/dist/otlp-COq033e3.js.map +1 -0
  177. package/dist/patch-BX8KrPCT.cjs.map +1 -1
  178. package/dist/{patch-CCWfuEY7.js → patch-UdPz1ea8.js} +2 -3
  179. package/dist/patch-UdPz1ea8.js.map +1 -0
  180. package/dist/{platform-KMWkoI-v.cjs → platform-12uR7kBQ.cjs} +2 -2
  181. package/dist/platform-12uR7kBQ.cjs.map +1 -0
  182. package/dist/{platform-wcAkkv9F.js → platform-CVewe4wQ.js} +9 -10
  183. package/dist/platform-CVewe4wQ.js.map +1 -0
  184. package/dist/profiler-BVWIOgnq.js +310 -0
  185. package/dist/profiler-BVWIOgnq.js.map +1 -0
  186. package/dist/profiler-eVCknCzS.cjs +2 -0
  187. package/dist/profiler-eVCknCzS.cjs.map +1 -0
  188. package/dist/profiler-frames-CLXlT_xL.js +86 -0
  189. package/dist/profiler-frames-CLXlT_xL.js.map +1 -0
  190. package/dist/profiler-frames-Dg2OebB2.cjs +2 -0
  191. package/dist/profiler-frames-Dg2OebB2.cjs.map +1 -0
  192. package/dist/{remote-rules-CH_7PphT.js → remote-rules-BJGDJGwA.js} +29 -30
  193. package/dist/remote-rules-BJGDJGwA.js.map +1 -0
  194. package/dist/{remote-rules-BL8km4xk.cjs → remote-rules-CJD3ToVk.cjs} +2 -2
  195. package/dist/remote-rules-CJD3ToVk.cjs.map +1 -0
  196. package/dist/replay-0zAJv9T3.js +338 -0
  197. package/dist/replay-0zAJv9T3.js.map +1 -0
  198. package/dist/replay-DomJpXqW.cjs +2 -0
  199. package/dist/replay-DomJpXqW.cjs.map +1 -0
  200. package/dist/{reports-Bh_-KpZ2.cjs → reports-BsbqmP8h.cjs} +2 -2
  201. package/dist/reports-BsbqmP8h.cjs.map +1 -0
  202. package/dist/{reports-BOKyY3_A.js → reports-BuXekPOS.js} +4 -5
  203. package/dist/reports-BuXekPOS.js.map +1 -0
  204. package/dist/{resource-timing-BROnEJ0E.js → resource-timing-CXGHwFRD.js} +6 -7
  205. package/dist/resource-timing-CXGHwFRD.js.map +1 -0
  206. package/dist/{resource-timing-CbgwNpog.cjs → resource-timing-DkycFGDa.cjs} +2 -2
  207. package/dist/resource-timing-DkycFGDa.cjs.map +1 -0
  208. package/dist/{sampling-ECGVYiDD.cjs → sampling-Dd0wllyq.cjs} +2 -2
  209. package/dist/sampling-Dd0wllyq.cjs.map +1 -0
  210. package/dist/{sampling-BLO_pcV4.js → sampling-UUDbi3K0.js} +11 -12
  211. package/dist/sampling-UUDbi3K0.js.map +1 -0
  212. package/dist/{sanitize-DS0G4_ea.js → sanitize-CNmsD9r3.js} +4 -5
  213. package/dist/sanitize-CNmsD9r3.js.map +1 -0
  214. package/dist/{sanitize-Bsn8HQWC.cjs → sanitize-ChLn97Ch.cjs} +2 -2
  215. package/dist/sanitize-ChLn97Ch.cjs.map +1 -0
  216. package/dist/{select-DWO0-w8_.cjs → select-CTk-K5mG.cjs} +3 -3
  217. package/dist/select-CTk-K5mG.cjs.map +1 -0
  218. package/dist/{select-wqt9Wxio.js → select-DPv_j6wq.js} +64 -67
  219. package/dist/select-DPv_j6wq.js.map +1 -0
  220. package/dist/{sender-BkAVt-Rq.js → sender-15zEsZpr.js} +98 -101
  221. package/dist/sender-15zEsZpr.js.map +1 -0
  222. package/dist/sender-Bfpv9tad.cjs +2 -0
  223. package/dist/sender-Bfpv9tad.cjs.map +1 -0
  224. package/dist/storage/context-storage.d.ts +34 -33
  225. package/dist/storage/emergency-queue.d.ts +9 -9
  226. package/dist/storage/eviction.d.ts +12 -12
  227. package/dist/storage/factory.d.ts +8 -7
  228. package/dist/storage/gap.d.ts +6 -6
  229. package/dist/storage/idb-driver.d.ts +31 -32
  230. package/dist/storage/indexeddb-storage.d.ts +26 -27
  231. package/dist/storage/keys.d.ts +7 -7
  232. package/dist/storage/local-storage.d.ts +38 -38
  233. package/dist/storage/memory-storage.d.ts +21 -22
  234. package/dist/storage/persistence.d.ts +1 -1
  235. package/dist/storage-BA9RqRO-.cjs.map +1 -1
  236. package/dist/{storage-w7Tslvlq.js → storage-DZwed89z.js} +2 -3
  237. package/dist/storage-DZwed89z.js.map +1 -0
  238. package/dist/{storm-DD4cUkoL.js → storm-BTSNTIWI.js} +4 -5
  239. package/dist/storm-BTSNTIWI.js.map +1 -0
  240. package/dist/{storm-DCEsqViG.cjs → storm-D0_qZOEg.cjs} +2 -2
  241. package/dist/storm-D0_qZOEg.cjs.map +1 -0
  242. package/dist/transport/compression.d.ts +2 -2
  243. package/dist/transport/errors.d.ts +7 -7
  244. package/dist/transport/exit-flush.d.ts +39 -39
  245. package/dist/transport/headers.d.ts +2 -2
  246. package/dist/transport/http-transport.d.ts +28 -27
  247. package/dist/transport/memory-transport.d.ts +6 -6
  248. package/dist/transport/retry-engine.d.ts +35 -34
  249. package/dist/transport/serializers/ecs.d.ts +1 -1
  250. package/dist/transport/serializers/otlp-metrics.d.ts +1 -1
  251. package/dist/transport/serializers/otlp-traces.d.ts +1 -1
  252. package/dist/transport/serializers/otlp.d.ts +16 -16
  253. package/dist/transport/serializers/select.d.ts +7 -7
  254. package/dist/transport/status-transport.d.ts +20 -20
  255. package/dist/transport/worker-protocol.d.ts +3 -3
  256. package/dist/{types-BR9t_w28.js → types-BAerHgCq.js} +2 -3
  257. package/dist/types-BAerHgCq.js.map +1 -0
  258. package/dist/types-C7WNpnG1.cjs.map +1 -1
  259. package/dist/{unclean-exit-CwdpbUDg.cjs → unclean-exit-ClGzrc2A.cjs} +2 -2
  260. package/dist/unclean-exit-ClGzrc2A.cjs.map +1 -0
  261. package/dist/{unclean-exit-BYZ5yaSI.js → unclean-exit-Cob_jyTv.js} +3 -4
  262. package/dist/unclean-exit-Cob_jyTv.js.map +1 -0
  263. package/dist/unref-CU9Nyz_9.cjs +2 -0
  264. package/dist/unref-CU9Nyz_9.cjs.map +1 -0
  265. package/dist/unref-DgHPQeWv.js +7 -0
  266. package/dist/unref-DgHPQeWv.js.map +1 -0
  267. package/dist/user-timing-CdYqx3PF.cjs +2 -0
  268. package/dist/user-timing-CdYqx3PF.cjs.map +1 -0
  269. package/dist/{user-timing-Di2ra5DB.js → user-timing-DgHubxCI.js} +7 -6
  270. package/dist/user-timing-DgHubxCI.js.map +1 -0
  271. package/dist/utils/console.d.ts +2 -2
  272. package/dist/utils/deadline.d.ts +4 -4
  273. package/dist/utils/error-like.d.ts +7 -7
  274. package/dist/utils/fixed-window.d.ts +9 -8
  275. package/dist/utils/global-scope.d.ts +8 -8
  276. package/dist/utils/guards.d.ts +2 -2
  277. package/dist/utils/identity.d.ts +17 -17
  278. package/dist/utils/library-console.d.ts +4 -4
  279. package/dist/utils/library-request.d.ts +10 -10
  280. package/dist/utils/lock.d.ts +10 -9
  281. package/dist/utils/openfin.d.ts +5 -5
  282. package/dist/utils/patch.d.ts +6 -6
  283. package/dist/utils/platform.d.ts +13 -11
  284. package/dist/utils/sanitize.d.ts +4 -4
  285. package/dist/utils/timer.d.ts +1 -1
  286. package/dist/utils/tracing.d.ts +38 -38
  287. package/dist/utils/unref.d.ts +3 -3
  288. package/dist/{web-socket-DwBNhgre.cjs → web-socket-BTuvYoJI.cjs} +2 -2
  289. package/dist/web-socket-BTuvYoJI.cjs.map +1 -0
  290. package/dist/{web-socket-B-5qqPy7.js → web-socket-DthJuSAg.js} +14 -15
  291. package/dist/web-socket-DthJuSAg.js.map +1 -0
  292. package/dist/web-vitals-Ch5BpDmo.cjs +2 -0
  293. package/dist/web-vitals-Ch5BpDmo.cjs.map +1 -0
  294. package/dist/web-vitals-CsGCWnUr.js +77 -0
  295. package/dist/web-vitals-CsGCWnUr.js.map +1 -0
  296. package/dist/{worker-protocol-0HMf4-kY.js → worker-protocol-B0_8rWy5.js} +6 -7
  297. package/dist/worker-protocol-B0_8rWy5.js.map +1 -0
  298. package/dist/{worker-protocol-DXekoADQ.cjs → worker-protocol-BjzFORfq.cjs} +2 -2
  299. package/dist/worker-protocol-BjzFORfq.cjs.map +1 -0
  300. package/dist/worker-server-4en-Lt-3.cjs +2 -0
  301. package/dist/worker-server-4en-Lt-3.cjs.map +1 -0
  302. package/dist/{worker-server-CKcmX5m5.js → worker-server-Cne9MX9I.js} +25 -26
  303. package/dist/{worker-server-CKcmX5m5.js.map → worker-server-Cne9MX9I.js.map} +1 -1
  304. package/dist/worker-transport-B-GF4Aqn.cjs +2 -0
  305. package/dist/worker-transport-B-GF4Aqn.cjs.map +1 -0
  306. package/dist/{worker-transport-2220ghFZ.js → worker-transport-C3SjJAEC.js} +64 -65
  307. package/dist/worker-transport-C3SjJAEC.js.map +1 -0
  308. package/package.json +33 -41
  309. package/dist/batch-BHXypM1j.cjs.map +0 -1
  310. package/dist/batch-BMdT9mKm.js.map +0 -1
  311. package/dist/bus-DKfBaica.js.map +0 -1
  312. package/dist/bus-Dea9rVhy.cjs +0 -2
  313. package/dist/bus-Dea9rVhy.cjs.map +0 -1
  314. package/dist/console-BX_0UCV7.js.map +0 -1
  315. package/dist/console-DZEcs7FL.cjs +0 -2
  316. package/dist/console-DZEcs7FL.cjs.map +0 -1
  317. package/dist/constants-CL0ZdI2f.cjs +0 -2
  318. package/dist/constants-CL0ZdI2f.cjs.map +0 -1
  319. package/dist/constants-CU60FG4w.js +0 -305
  320. package/dist/constants-CU60FG4w.js.map +0 -1
  321. package/dist/context-storage-DxZf4Gfh.js.map +0 -1
  322. package/dist/deadline-5_PecIl5.js.map +0 -1
  323. package/dist/deadline-XSnm95pg.cjs +0 -2
  324. package/dist/deadline-XSnm95pg.cjs.map +0 -1
  325. package/dist/debug-bundle-CZZ6SQQh.js.map +0 -1
  326. package/dist/debug-bundle-yRkrU1ny.cjs +0 -2
  327. package/dist/debug-bundle-yRkrU1ny.cjs.map +0 -1
  328. package/dist/emergency-queue-CQ-9acZf.cjs.map +0 -1
  329. package/dist/emergency-queue-Cs8-i2xw.js.map +0 -1
  330. package/dist/error-like-Ywo5uRHo.js.map +0 -1
  331. package/dist/errors-CigX45pL.cjs.map +0 -1
  332. package/dist/errors-oyxrpHjY.js.map +0 -1
  333. package/dist/factory-Bgsky_e0.js.map +0 -1
  334. package/dist/factory-BkjNzPYL.cjs.map +0 -1
  335. package/dist/fixed-window-CtaFHanJ.js.map +0 -1
  336. package/dist/global-scope-dp2jADRl.js.map +0 -1
  337. package/dist/guards-CpvOpJL6.js.map +0 -1
  338. package/dist/identity-BMlKGHUM.cjs.map +0 -1
  339. package/dist/identity-DOaHdfhT.js.map +0 -1
  340. package/dist/indexeddb-storage-CaXGJqDD.cjs.map +0 -1
  341. package/dist/indexeddb-storage-D-lUW_5P.js.map +0 -1
  342. package/dist/interactions-8DgxtmgO.cjs.map +0 -1
  343. package/dist/interactions-CqDNrtIR.js.map +0 -1
  344. package/dist/journey-5tcxEbnG.cjs +0 -2
  345. package/dist/journey-5tcxEbnG.cjs.map +0 -1
  346. package/dist/journey-DgIjhrIc.js.map +0 -1
  347. package/dist/keys-D5r_GH9q.js.map +0 -1
  348. package/dist/library-console-CabK2j2-.js +0 -14
  349. package/dist/library-console-CabK2j2-.js.map +0 -1
  350. package/dist/library-console-g_VU-wzP.cjs.map +0 -1
  351. package/dist/library-request-CyC-9IOk.js.map +0 -1
  352. package/dist/library-request-FQaiWjCP.cjs.map +0 -1
  353. package/dist/lifecycle-BLC4VU7c.js.map +0 -1
  354. package/dist/lifecycle-C2z_d8OX.cjs.map +0 -1
  355. package/dist/log-record-CndanC-p.js.map +0 -1
  356. package/dist/log-record-DKvo-B-d.cjs.map +0 -1
  357. package/dist/long-frames-BQef9rXR.js.map +0 -1
  358. package/dist/long-frames-CV5ZG2cx.cjs +0 -2
  359. package/dist/long-frames-CV5ZG2cx.cjs.map +0 -1
  360. package/dist/network-CqnQOqon.cjs.map +0 -1
  361. package/dist/network-CvkvYzRU.js.map +0 -1
  362. package/dist/openfin-BwEN0uj4.js +0 -8
  363. package/dist/openfin-BwEN0uj4.js.map +0 -1
  364. package/dist/otlp-CYIL7MOE.js.map +0 -1
  365. package/dist/otlp-RVbkNQRh.cjs +0 -2
  366. package/dist/otlp-RVbkNQRh.cjs.map +0 -1
  367. package/dist/patch-CCWfuEY7.js.map +0 -1
  368. package/dist/platform-KMWkoI-v.cjs.map +0 -1
  369. package/dist/platform-wcAkkv9F.js.map +0 -1
  370. package/dist/remote-rules-BL8km4xk.cjs.map +0 -1
  371. package/dist/remote-rules-CH_7PphT.js.map +0 -1
  372. package/dist/reports-BOKyY3_A.js.map +0 -1
  373. package/dist/reports-Bh_-KpZ2.cjs.map +0 -1
  374. package/dist/resource-timing-BROnEJ0E.js.map +0 -1
  375. package/dist/resource-timing-CbgwNpog.cjs.map +0 -1
  376. package/dist/sampling-BLO_pcV4.js.map +0 -1
  377. package/dist/sampling-ECGVYiDD.cjs.map +0 -1
  378. package/dist/sanitize-Bsn8HQWC.cjs.map +0 -1
  379. package/dist/sanitize-DS0G4_ea.js.map +0 -1
  380. package/dist/select-DWO0-w8_.cjs.map +0 -1
  381. package/dist/select-wqt9Wxio.js.map +0 -1
  382. package/dist/sender-BkAVt-Rq.js.map +0 -1
  383. package/dist/sender-D82PxlCY.cjs +0 -2
  384. package/dist/sender-D82PxlCY.cjs.map +0 -1
  385. package/dist/storage-w7Tslvlq.js.map +0 -1
  386. package/dist/storm-DCEsqViG.cjs.map +0 -1
  387. package/dist/storm-DD4cUkoL.js.map +0 -1
  388. package/dist/types-BR9t_w28.js.map +0 -1
  389. package/dist/unclean-exit-BYZ5yaSI.js.map +0 -1
  390. package/dist/unclean-exit-CwdpbUDg.cjs.map +0 -1
  391. package/dist/user-timing-C1kB3JEg.cjs +0 -2
  392. package/dist/user-timing-C1kB3JEg.cjs.map +0 -1
  393. package/dist/user-timing-Di2ra5DB.js.map +0 -1
  394. package/dist/web-socket-B-5qqPy7.js.map +0 -1
  395. package/dist/web-socket-DwBNhgre.cjs.map +0 -1
  396. package/dist/web-vitals-Bflr5jSA.js +0 -53
  397. package/dist/web-vitals-Bflr5jSA.js.map +0 -1
  398. package/dist/web-vitals-DFuoTQbZ.cjs +0 -2
  399. package/dist/web-vitals-DFuoTQbZ.cjs.map +0 -1
  400. package/dist/worker-protocol-0HMf4-kY.js.map +0 -1
  401. package/dist/worker-protocol-DXekoADQ.cjs.map +0 -1
  402. package/dist/worker-server-BQK5z2yl.cjs +0 -2
  403. package/dist/worker-server-BQK5z2yl.cjs.map +0 -1
  404. package/dist/worker-transport-2220ghFZ.js.map +0 -1
  405. package/dist/worker-transport-Dj2yCQN5.cjs +0 -2
  406. package/dist/worker-transport-Dj2yCQN5.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bus-D_7pd7RN.cjs","names":["BUS_TYPE","isLogRecord","isLogLevel","SEVERITY_NUMBER","BUS_PROTOCOL","RUNTIME_GLOBAL_KEY","getFin","BUS_HANDSHAKE_TIMEOUT_MS","BUS_TYPE","windowEnded","countInWindow","getFin","BUS_CHANNEL_NAME","parseJourney","parseRemoteRules","REMOTE_SAMPLING_POLL_MS","require_constants","require_journey","require_remote_rules","require_log_record","require_openfin","require_fixed_window","require_unref","validMessage","value","m","text","key","r","envelope","message","unwrap","data","wrapper","RUNTIME_KEY","OPAQUE_ORIGIN","untrustedText","origin","what","parentOrigin","ancestors","referrer","createDirectLink","host","target","open","diagnostics","receive","createParentLink","self","trusted","trustedOrigins","reported","onMessage","event","createChildrenLink","sources","send","authorize","source","mayPost","answer","createBroadcastLink","BC","channel","channelName","createOpenFinLink","iab","appUuid","scoped","topic","raw","uuid","name","createOwnerLink","scope","createWorkerLink","worker","HANDSHAKE_OPTIONS","OWNED","Bus","permissions","peer","element","frame","options","registration","openFin","ref","reply","known","config","platform","contextId","tabId","handlers","handshakeOptions","bus","direct","candidate","attempts","welcomed","attempt","encoder","size","maxMessageBytes","chunk","bytes","record","records","recordBytes","comma","maxRecordsPerMessage","plain","link","index","child","accepted","object","now","rate","entry","encoded","permission","before","current","configured","me","push","registered","settled","finish","timer","resolve","result","from","payload","journey","rules","to","update","upstream","ask"],"sources":["../src/bus/validation.ts","../src/models/bus.ts","../src/bus/links.ts","../src/bus/bus.ts"],"sourcesContent":["// src/bus/validation.ts\n//\n// Checks the required fields and values of messages from another context.\n\nimport type { BusMessage } from \"../models/bus\";\nimport { isLogLevel, isLogRecord } from \"../models/log-record\";\nimport { BUS_TYPE, SEVERITY_NUMBER } from \"../constants\";\n\n/**\n * Checks the fields that each bus message type requires. unwrap() only checks the envelope.\n * @param value Message to check.\n * @returns True if the message has the required fields and values.\n */\nexport function validMessage(value: unknown): value is BusMessage {\n if (typeof value !== \"object\" || value === null) return false;\n const m = value as Record<string, unknown>;\n if (typeof m.from !== \"string\" || !m.from || typeof m.t !== \"string\") return false;\n const text = (key: string): boolean => typeof m[key] === \"string\";\n switch (m.t) {\n case BUS_TYPE.hello:\n case BUS_TYPE.tab:\n return text(\"tabId\");\n case BUS_TYPE.welcome:\n return (\n text(\"to\") &&\n text(\"tabId\") &&\n (m.routingContextId === undefined || text(\"routingContextId\"))\n );\n case BUS_TYPE.journeyRequest:\n case BUS_TYPE.samplingRequest:\n return true;\n case BUS_TYPE.securityContext:\n return text(\"id\") && m.id !== \"\";\n case BUS_TYPE.journey:\n return (m.to === undefined || text(\"to\")) && \"journey\" in m;\n case BUS_TYPE.sampling:\n return text(\"to\") && \"rules\" in m;\n case BUS_TYPE.records:\n return (\n Array.isArray(m.records) &&\n (m.routingContextId === undefined || text(\"routingContextId\")) &&\n m.records.every((r: unknown) => {\n if (!isLogRecord(r) || !isLogLevel(r.severityText)) return false;\n return (\n !Array.isArray(r.attributes) &&\n !Array.isArray(r.resource) &&\n /^\\d+$/.test(r.timeUnixNano) &&\n (r.observedTimeUnixNano === undefined || /^\\d+$/.test(r.observedTimeUnixNano)) &&\n typeof r.traceId === \"string\" &&\n /^(?:[a-f\\d]{32})?$/.test(r.traceId) &&\n typeof r.spanId === \"string\" &&\n /^(?:[a-f\\d]{16})?$/.test(r.spanId) &&\n Number.isInteger(r.traceFlags) &&\n r.traceFlags >= 0 &&\n r.traceFlags <= 255 &&\n r.severityNumber === SEVERITY_NUMBER[r.severityText]\n );\n })\n );\n default:\n return false;\n }\n}\n","// src/models/bus.ts\n//\n// Protocol types, message definitions, and envelope encoding for bus messages between realms.\n\nimport { BUS_PROTOCOL, type BUS_TYPE } from \"../constants\";\nimport type { LogRecord } from \"./log-record\";\n\n/** What one child window or worker may do. The handshake needs no permission of its own. */\nexport type BusPermission = \"records\" | \"journey:read\" | \"journey:write\" | \"sampling:read\";\nexport interface SourceOptions {\n /** This source's permissions. Without the list, the source can only send records. */\n permissions?: BusPermission[];\n}\n\n/** Origin and permissions for one child frame registration. */\nexport interface FrameOptions extends SourceOptions {\n /** Expected window origin, including its scheme and port. Must match exactly. */\n origin: string;\n}\n\n/** Delivery role: whether this context sends its own records or forwards them upstream. */\nexport type BusRole = \"sender\" | \"forwarder\";\n\n/**\n * Kind of transport channel, which the bus uses to route incoming and outgoing messages.\n * Without it, `receive` can't tell the channels apart and a same-origin iframe looks like a\n * duplicated tab.\n */\nexport type LinkKind =\n /** Synchronous call into a same-origin parent runtime. */\n | \"direct\"\n /** postMessage to a parent window. */\n | \"parent\"\n /** postMessage to child frames. */\n | \"children\"\n /** BroadcastChannel across same-origin tabs and windows. */\n | \"broadcast\"\n /** OpenFin InterApplicationBus across desktop views and applications. */\n | \"openfin\"\n /** Dedicated worker communication to its owning document. */\n | \"owner\"\n /** Document-side communication to a dedicated worker. */\n | \"worker\";\n\n/** Origin and transport metadata for an incoming bus message. */\nexport interface MessageSource {\n /** Source identity as the transport reports it. The source can't supply it in message.from. */\n peer?: object | string;\n /** Inbound transport channel kind. */\n link: LinkKind;\n /** `event.origin` for `parent` and `children`. Other links use `\"same-origin\"` or `\"openfin\"`. */\n origin: string;\n /** Replies to this source only. A link that can't address a single source omits it. */\n reply?: (message: BusMessage) => void;\n}\n\n/** Discriminated union of control and telemetry payload messages. */\nexport type BusMessage =\n /** Handshake discovery announcement from a starting forwarder. */\n | { t: typeof BUS_TYPE.hello; from: string; tabId: string }\n /**\n * Handshake response from an upstream owner, addressed through the `to` field. A welcome on\n * InterApplicationBus reaches every subscriber, so without an address every waiting view\n * would accept the welcome as its own.\n */\n | {\n t: typeof BUS_TYPE.welcome;\n from: string;\n to: string;\n tabId: string;\n routingContextId?: string;\n }\n /** Telemetry log records forwarded to an upstream sender. */\n | { t: typeof BUS_TYPE.records; from: string; records: LogRecord[]; routingContextId?: string }\n /** Delivery context update. Only the owner from the handshake may send it to its children. */\n | { t: typeof BUS_TYPE.securityContext; from: string; id: string }\n /**\n * Journey update, or the answer to a journey question. An answer carries the asking\n * context's address in `to`. The payload comes from another realm, so the receiver parses it.\n */\n | { t: typeof BUS_TYPE.journey; from: string; to?: string; journey: unknown }\n /** Query requesting active journey state from connected peers. */\n | { t: typeof BUS_TYPE.journeyRequest; from: string }\n /** Tab identifier claim broadcast to detect collisions across windows. */\n | { t: typeof BUS_TYPE.tab; from: string; tabId: string }\n /** A forwarder's request for the current remote sampling rules. */\n | { t: typeof BUS_TYPE.samplingRequest; from: string }\n /**\n * Remote sampling rules in the header's shape, with the remaining TTL. `to` holds the address\n * of the forwarder that asked. The receiver validates `rules` again. Null rules end the\n * forwarder's copy.\n */\n | { t: typeof BUS_TYPE.sampling; from: string; to: string; rules: unknown };\n\n/** Transport envelope wrapping bus messages with a protocol version tag. */\nexport interface BusEnvelope {\n /** Protocol version identifier. */\n p: typeof BUS_PROTOCOL;\n /** Encapsulated bus payload. */\n m: BusMessage;\n}\n\n/**\n * Wraps a bus message in a versioned protocol envelope.\n * @param message Message to encapsulate.\n * @returns Envelope ready for transport.\n */\nexport function envelope(message: BusMessage): BusEnvelope {\n return { p: BUS_PROTOCOL, m: message };\n}\n\n/**\n * Validates the protocol tag and unpacks a raw payload into a bus message. A document gets\n * `message` events from all embedded content on the page, including analytics tags, video\n * players and extensions. Without the tag check, the bus would parse a video player's message\n * as a log record.\n * @param data Raw payload received over a transport link.\n * @returns The validated message, or null if the payload is invalid or unrecognized.\n */\nexport function unwrap(data: unknown): BusMessage | null {\n if (typeof data !== \"object\" || data === null) {\n return null;\n }\n\n // Validates payload structure at runtime without assuming envelope fields exist.\n const wrapper = data as Record<string, unknown>;\n if (wrapper.p !== BUS_PROTOCOL || typeof wrapper.m !== \"object\" || wrapper.m === null) {\n return null;\n }\n\n const message = wrapper.m as Record<string, unknown>;\n if (typeof message.t !== \"string\") {\n return null;\n }\n\n return message as unknown as BusMessage;\n}\n","// src/bus/links.ts\n//\n// Communication link implementations for direct, frame, broadcast, OpenFin, and worker channels.\n\nimport { BUS_TYPE_DETAIL_MAX_CHARS, RUNTIME_GLOBAL_KEY } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport {\n type BusMessage,\n envelope,\n type LinkKind,\n type MessageSource,\n unwrap,\n} from \"../models/bus\";\nimport { getFin } from \"../utils/openfin\";\n\n/** Bidirectional communication channel for bus message transport. */\nexport interface Link {\n /** Channel transport kind. */\n readonly kind: LinkKind;\n\n /**\n * Sends a message over the channel without throwing.\n * @param message Bus message to transmit.\n */\n post(message: BusMessage): void;\n\n /** Releases listeners, subscriptions, or channels held open by the link. */\n close(): void;\n}\n\n/**\n * Callback invoked when a bus message arrives on a link.\n * @param message Received bus message.\n * @param source Origin and link metadata.\n */\nexport type Receive = (message: BusMessage, source: MessageSource) => void;\n\n/** Interface that a same-origin parent runtime exposes on a global symbol. */\nexport interface DirectHost {\n /**\n * Accepts a message directly from a child frame and replies synchronously.\n * @param message Child bus message.\n * @param reply Callback for synchronous response.\n */\n busAccept(message: BusMessage, reply: Receive, source?: Window): void;\n /**\n * Checks if the parent permits a direct link from the child window.\n * @param source Child window.\n * @param origin Origin of the child window.\n * @returns True if the parent permits this source.\n */\n busCanAccept?: (source: Window, origin: string) => boolean;\n}\n\n/** Message port or dedicated/shared worker interface. */\nexport interface WorkerLike {\n /**\n * Sends a message to the worker or port.\n * @param message Payload to send.\n */\n postMessage(message: unknown): void;\n\n /**\n * Subscribes to incoming message events.\n * @param type Event name (\"message\").\n * @param listener Event handler callback.\n */\n addEventListener(type: \"message\", listener: (event: MessageEvent) => void): void;\n\n /**\n * Unsubscribes from message events.\n * @param type Event name (\"message\").\n * @param listener Event handler to remove.\n */\n removeEventListener(type: \"message\", listener: (event: MessageEvent) => void): void;\n\n /** Starts message delivery on MessagePort instances. */\n start?: () => void;\n}\n\n/** Global symbol used to look up same-origin parent runtime instances. */\nconst RUNTIME_KEY = Symbol.for(RUNTIME_GLOBAL_KEY);\n\n/** Origin of a sandboxed frame without allow-same-origin. */\nconst OPAQUE_ORIGIN = \"null\";\n\n/** Location with the ancestor list that Chromium and WebKit give. */\ninterface LocationWithAncestors {\n origin: string;\n ancestorOrigins?: { length: number; item: (index: number) => string | null };\n}\n\n/**\n * Builds the diagnostic text for something we ignored from an untrusted origin.\n * @param origin Origin of the sender.\n * @param what What the bus ignored, for example \"a message\".\n * @returns The text. For a sandboxed sender it includes the fix for its frame.\n */\nfunction untrustedText(origin: string, what: string): string {\n if (origin === OPAQUE_ORIGIN) {\n return `The bus ignored ${what} from a sandboxed frame. The frame has an opaque origin. Set bus.mode: \"sender\" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`;\n }\n\n return `The bus ignored ${what} from ${origin}. If you own this origin, add it to bus.trustedOrigins.`;\n}\n\n/**\n * Reads the parent frame's origin. A cross-origin parent doesn't expose its location.\n * @returns The origin, or null when the browser doesn't reveal it.\n */\nfunction parentOrigin(): string | null {\n const ancestors = (location as LocationWithAncestors).ancestorOrigins;\n if (ancestors && ancestors.length > 0) {\n return ancestors.item(0);\n }\n\n // Firefox has no ancestorOrigins, so use the referrer, which for a frame is the page that\n // loaded it. A Referrer-Policy of no-referrer gives \"\", and the caller then reports an\n // unknown origin.\n const referrer = document.referrer;\n if (referrer === \"\") {\n return null;\n }\n\n try {\n return new URL(referrer).origin;\n } catch {\n return null;\n }\n}\n\n/**\n * Establishes direct synchronous communication with a same-origin parent runtime.\n * @param receive Callback for parent replies.\n * @param diagnostics Diagnostics reporter.\n * @returns Direct link, or null if parent is inaccessible or lacks a runtime.\n */\nexport function createDirectLink(receive: Receive, diagnostics: Diagnostics): Link | null {\n if (typeof window === \"undefined\" || window.parent === window) {\n return null;\n }\n\n let host: DirectHost | undefined;\n try {\n const parentGlobal = window.parent as unknown as Record<symbol, DirectHost | undefined>;\n host = parentGlobal[RUNTIME_KEY];\n } catch {\n // Cross-origin access throws on read.\n return null;\n }\n if (typeof host?.busAccept !== \"function\") {\n return null;\n }\n\n if (host.busCanAccept && !host.busCanAccept(window, location.origin)) return null;\n const target = host;\n let open = true;\n\n return {\n kind: \"direct\",\n post(message) {\n if (!open) {\n return;\n }\n\n // Stops an error in the parent runtime from breaking a logging call in the child.\n diagnostics.guard(\n \"bus.send_failed\",\n \"The direct call into the parent runtime failed.\",\n () => {\n target.busAccept(message, receive, window);\n },\n );\n },\n close() {\n open = false;\n },\n };\n}\n\n/**\n * Creates a postMessage link to a parent window on a trusted origin. Records hold user data,\n * so a page on another origin that frames this app must not get them.\n * @param receive Callback for incoming parent messages.\n * @param trustedOrigins Parent origins that may receive the records, in addition to this origin.\n * @param diagnostics Diagnostics reporter.\n * @returns Link to the parent window, or null at the top level or with an untrusted parent.\n * When it is null, this context sends its own records.\n */\nexport function createParentLink(\n receive: Receive,\n trustedOrigins: string[],\n diagnostics: Diagnostics,\n): Link | null {\n if (typeof window === \"undefined\" || window.parent === window) {\n return null;\n }\n\n // A sandboxed frame has an opaque origin, which no parent can put in its trust list.\n const self = location.origin;\n if (self === OPAQUE_ORIGIN) {\n diagnostics.report(\n \"bus.untrusted_origin\",\n 'This frame is sandboxed without allow-same-origin. It has an opaque origin. No parent can trust it. This context sends its own records. Set bus.mode: \"sender\" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.',\n { origin: self, type: \"parent\" },\n );\n return null;\n }\n\n const trusted = new Set([self, ...trustedOrigins]);\n const target = parentOrigin();\n if (target === null || !trusted.has(target)) {\n diagnostics.report(\n \"bus.untrusted_origin\",\n target === null\n ? \"The origin of the parent frame is unknown. This context sends its own records.\"\n : `The parent frame is on ${target}. This origin is not in bus.trustedOrigins. This context sends its own records.`,\n { origin: target ?? \"\", type: \"parent\" },\n );\n return null;\n }\n\n // Report every untrusted origin only once, because a hostile parent can send many messages.\n const reported = new Set<string>();\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (!message || event.source !== window.parent) {\n return;\n }\n\n // The parent can navigate to another origin after this frame loads.\n if (!trusted.has(event.origin)) {\n if (!reported.has(event.origin)) {\n reported.add(event.origin);\n // The parent controls message.t, so keep it out of the message text and truncate it\n // in the detail.\n diagnostics.report(\"bus.untrusted_origin\", untrustedText(event.origin, \"a message\"), {\n origin: event.origin,\n type: message.t.slice(0, BUS_TYPE_DETAIL_MAX_CHARS),\n });\n }\n return;\n }\n\n receive(message, { link: \"parent\", origin: event.origin, peer: event.source });\n };\n addEventListener(\"message\", onMessage);\n\n return {\n kind: \"parent\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"The postMessage call to the parent failed.\", () => {\n // Target the trusted origin, not \"*\". The browser drops the message if the parent\n // navigated to another origin.\n window.parent.postMessage(envelope(message), target);\n });\n },\n close() {\n removeEventListener(\"message\", onMessage);\n },\n };\n}\n\n/**\n * Creates a link listening to child frames with origin allowlist filtering.\n * @param receive Callback for messages from authorized child frames.\n * @param trustedOrigins Additional origins allowed to communicate.\n * @param diagnostics Diagnostics reporter.\n * @returns Children link, or null in non-window environments.\n */\nexport function createChildrenLink(\n receive: Receive,\n trustedOrigins: string[],\n diagnostics: Diagnostics,\n authorize?: (source: MessageEventSource | null, origin: string) => boolean,\n mayPost?: (message: BusMessage, source: MessageEventSource) => boolean,\n): Link | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n // A sandboxed page has the opaque origin \"null\", and so does every sandboxed child.\n const trusted = new Set([location.origin, ...trustedOrigins]);\n trusted.delete(OPAQUE_ORIGIN);\n\n // Remembers every source's origin, so a child that navigates doesn't get the ids of its\n // previous origin.\n const sources = new Map<MessageEventSource, string>();\n\n /**\n * Posts one message to one child, and forgets a child that is closed or no longer permitted.\n * @param source Child window.\n * @param origin Last known origin of the child.\n * @param message Message to send.\n */\n const send = (source: MessageEventSource, origin: string, message: BusMessage): void => {\n if (authorize && !authorize(source, origin)) {\n sources.delete(source);\n return;\n }\n if (mayPost && !mayPost(message, source)) {\n return;\n }\n const target = source as Window;\n // Evicts closed child windows to prevent memory leaks.\n if (target.closed) {\n sources.delete(source);\n return;\n }\n diagnostics.guard(\"bus.send_failed\", \"The postMessage call to a child frame failed.\", () => {\n // Targets the last known origin of the child. The browser drops the\n // message if the child navigated to a different origin.\n target.postMessage(envelope(message), origin);\n });\n };\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (!message) {\n return;\n }\n // A nested frame also receives its parent's messages here. Those belong to the parent link.\n if (window.parent !== window && event.source === window.parent) {\n return;\n }\n if (!authorize && !trusted.has(event.origin)) {\n diagnostics.report(\"bus.untrusted_origin\", untrustedText(event.origin, \"a message\"), {\n origin: event.origin,\n type: message.t.slice(0, BUS_TYPE_DETAIL_MAX_CHARS),\n });\n return;\n }\n\n if (authorize && !authorize(event.source, event.origin)) return;\n const { source, origin } = event;\n if (source) {\n sources.set(source, origin);\n }\n // Answer only the child that asked. A broadcast would let one child use up every\n // sibling's budget.\n receive(message, {\n link: \"children\",\n origin,\n peer: source ?? undefined,\n reply: source\n ? (answer) => {\n send(source, origin, answer);\n }\n : undefined,\n });\n };\n addEventListener(\"message\", onMessage);\n\n return {\n kind: \"children\",\n post(message) {\n for (const [source, origin] of sources) {\n send(source, origin, message);\n }\n },\n close() {\n removeEventListener(\"message\", onMessage);\n sources.clear();\n },\n };\n}\n\n/**\n * Creates a same-origin BroadcastChannel link for cross-tab control messages.\n * @param channelName BroadcastChannel identifier.\n * @param receive Callback for incoming cross-tab messages.\n * @param diagnostics Diagnostics reporter.\n * @returns Broadcast link, or null if unsupported.\n */\nexport function createBroadcastLink(\n channelName: string,\n receive: Receive,\n diagnostics: Diagnostics,\n): Link | null {\n const BC = (globalThis as { BroadcastChannel?: typeof BroadcastChannel }).BroadcastChannel;\n if (typeof BC === \"undefined\") {\n return null;\n }\n\n const channel = diagnostics.guard(\n \"bus.send_failed\",\n \"The library could not open the BroadcastChannel.\",\n () => new BC(channelName),\n );\n if (!channel) {\n return null;\n }\n\n channel.onmessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (message) {\n receive(message, { link: \"broadcast\", origin: \"same-origin\" });\n }\n };\n\n return {\n kind: \"broadcast\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"The BroadcastChannel.postMessage call failed.\", () => {\n channel.postMessage(envelope(message));\n });\n },\n close() {\n diagnostics.guard(\n \"bus.send_failed\",\n \"The library could not close the BroadcastChannel.\",\n () => {\n channel.close();\n },\n );\n },\n };\n}\n\n/**\n * Creates an OpenFin InterApplicationBus link scoped to one application.\n * @param topic InterApplicationBus topic prefix.\n * @param appUuid OpenFin application uuid owning this context.\n * @param receive Callback for received topic messages.\n * @param diagnostics Diagnostics reporter.\n * @returns OpenFin link, or null if InterApplicationBus or the identity is unavailable.\n */\nexport function createOpenFinLink(\n topic: string,\n appUuid: string | undefined,\n receive: Receive,\n diagnostics: Diagnostics,\n): Link | null {\n const iab = getFin()?.InterApplicationBus;\n if (!iab) {\n return null;\n }\n if (!appUuid) {\n // publish() sends to every subscriber on the runtime. Without a uuid scope,\n // this link would share this app's bus with every other app.\n diagnostics.report(\n \"openfin.unavailable\",\n \"OpenFin gives no application uuid. The InterApplicationBus link stays closed.\",\n );\n return null;\n }\n\n // The uuid goes into both the topic and the subscriber identity. The topic keeps this app's\n // messages away from other apps, and the identity rejects messages that come from them.\n const scoped = `${topic}.${appUuid}`;\n\n void diagnostics.guardAsync(\n \"bus.send_failed\",\n \"The InterApplicationBus.subscribe call failed.\",\n () =>\n iab.subscribe({ uuid: appUuid }, scoped, (raw, uuid, name) => {\n const message = unwrap(raw);\n if (message) {\n receive(message, {\n link: \"openfin\",\n origin: \"openfin\",\n peer: uuid && name ? `${uuid}:${name}` : undefined,\n });\n }\n }),\n );\n\n return {\n kind: \"openfin\",\n post(message) {\n void diagnostics.guardAsync(\n \"bus.send_failed\",\n \"The InterApplicationBus.publish call failed.\",\n () => iab.publish(scoped, envelope(message)),\n );\n },\n close() {\n // OpenFin removes the subscriptions when the context closes.\n },\n };\n}\n\n/**\n * Creates the worker-side link pointing at the document that created this\n * worker. Emits `kind: \"owner\"`.\n * @param receive Callback for incoming messages from the owning document.\n * @param diagnostics Diagnostics reporter.\n * @returns Owner link, or null outside a DedicatedWorkerGlobalScope.\n */\nexport function createOwnerLink(receive: Receive, diagnostics: Diagnostics): Link | null {\n const scope = globalThis as unknown as {\n postMessage?: (message: unknown) => void;\n addEventListener?: (type: string, listener: (event: MessageEvent) => void) => void;\n WorkerGlobalScope?: unknown;\n };\n const send = scope.postMessage;\n if (typeof scope.WorkerGlobalScope === \"undefined\" || !send) {\n return null;\n }\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (message) {\n receive(message, { link: \"owner\", origin: \"same-origin\" });\n }\n };\n scope.addEventListener?.(\"message\", onMessage);\n\n return {\n kind: \"owner\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"The postMessage call of the worker failed.\", () => {\n send(envelope(message));\n });\n },\n close() {\n // Worker scope listeners stop when the worker stops.\n },\n };\n}\n\n/**\n * Creates the document-side link pointing at one attached worker or port.\n * Emits `kind: \"worker\"`.\n * @param worker Target worker instance or MessagePort.\n * @param receive Callback for messages from the worker.\n * @param diagnostics Diagnostics reporter.\n * @returns Document-to-worker link.\n */\nexport function createWorkerLink(\n worker: WorkerLike,\n receive: Receive,\n diagnostics: Diagnostics,\n): Link {\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (message) {\n receive(message, { link: \"worker\", origin: \"same-origin\", peer: worker });\n }\n };\n worker.addEventListener(\"message\", onMessage);\n\n // Starts delivery on a MessagePort. A Worker has no start method.\n worker.start?.();\n\n return {\n kind: \"worker\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"The postMessage call to a worker failed.\", () => {\n worker.postMessage(envelope(message));\n });\n },\n close() {\n worker.removeEventListener(\"message\", onMessage);\n },\n };\n}\n","// src/bus/bus.ts\n//\n// Resolves the bus role and routes messages between realms.\n\nimport {\n BUS_CHANNEL_NAME,\n BUS_HANDSHAKE_TIMEOUT_MS,\n BUS_MAX_HANDSHAKE_ATTEMPTS,\n BUS_TYPE,\n REMOTE_SAMPLING_POLL_MS,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { type Journey, parseJourney } from \"../core/journey\";\nimport { applyRemote, parseRemoteRules } from \"../core/remote-rules\";\nimport type { RemoteSlot } from \"../core/remote-sampling\";\nimport type { BusMessage, BusRole, LinkKind, MessageSource } from \"../models/bus\";\nimport type { SourceOptions, FrameOptions } from \"../models/bus\";\nimport { validMessage } from \"./validation\";\nimport type { JourneyScope, ResolvedConfig } from \"../models/config\";\nimport type { LogRecord } from \"../models/log-record\";\nimport { getFin } from \"../utils/openfin\";\nimport type { PlatformMetadata } from \"../utils/platform\";\nimport { countInWindow, windowEnded } from \"../utils/fixed-window\";\nimport { unrefTimer } from \"../utils/unref\";\nimport {\n createBroadcastLink,\n createChildrenLink,\n createDirectLink,\n createOpenFinLink,\n createOwnerLink,\n createParentLink,\n createWorkerLink,\n type Link,\n type Receive,\n type WorkerLike,\n} from \"./links\";\n\n/** Handshake timing for a forwarder waiting on an owner. */\nexport interface HandshakeOptions {\n /** How long a forwarder waits for an owner to answer, in milliseconds. */\n timeoutMs: number;\n /** Attempts allowed before a cross-origin forwarder promotes itself to sender. */\n maxAttempts: number;\n}\n\n/** Default handshake timing. Tests build a bus with shorter values. */\nexport const HANDSHAKE_OPTIONS: HandshakeOptions = {\n timeoutMs: BUS_HANDSHAKE_TIMEOUT_MS,\n maxAttempts: BUS_MAX_HANDSHAKE_ATTEMPTS,\n};\n\n/** Callbacks for handling records and journey events from connected realms. */\nexport interface BusHandlers {\n /** Adopts the owner's delivery context. Returning false refuses a different identity. */\n onSecurityContext?: (id: string) => boolean;\n /** Processes records forwarded from child contexts. */\n onRecords: (records: LogRecord[]) => void;\n /** Applies journey updates received from the control bus. */\n onJourney: (journey: Journey | null) => void;\n /** Returns the active journey to a child context that requests it. */\n onJourneyRequest: () => Journey | null;\n /** Runs when two windows use the same tab identifier. */\n onTabConflict: () => void;\n /** The runtime's slot for the remote sampling rules. The bus both reads and fills it. */\n remote: RemoteSlot;\n}\n\n/** Link types that a sender context may claim ownership over during handshakes. */\nconst OWNED: readonly LinkKind[] = [\"children\", \"direct\", \"worker\"];\n\n/** Journey scope after the bus resolves \"auto\". */\ntype ResolvedScope = Exclude<JourneyScope, \"auto\">;\n\n/** Coordinates cross-realm communication, role resolution, and message dispatch. */\nexport class Bus {\n /** Window and worker registrations with their permissions. */\n private readonly sources = new Map<object, SourceOptions & { origin?: string }>();\n /** Message counts for each window and worker in the current rate window. */\n private readonly rates = new WeakMap<object, { start: number; count: number }>();\n /** Message counts for each named source or link in the current rate window. */\n private readonly channelRates = new Map<string, { start: number; count: number }>();\n /** Each same-origin direct child's reply. Held weakly so a navigated frame can be freed. */\n private readonly directReplies = new Map<Window, WeakRef<Receive>>();\n\n /**\n * Checks whether this source may receive a control message. A window can read a message\n * even when it is addressed to another window.\n * @param message Control message to send.\n * @param peer Window or worker that receives the message.\n * @returns True if the source has the required permission.\n */\n private mayPost(message: BusMessage, peer: object): boolean {\n const permissions = this.sources.get(peer)?.permissions;\n if (!permissions) return this.config.bus.sourcePolicy === \"trusted-origin\";\n if (message.t === BUS_TYPE.journey) return permissions.includes(\"journey:read\");\n if (message.t === BUS_TYPE.journeyRequest) return permissions.includes(\"journey:write\");\n if (message.t === BUS_TYPE.sampling) return permissions.includes(\"sampling:read\");\n return true;\n }\n\n /**\n * Registers one child window and its permissions.\n * @param frame Frame element or window to register.\n * @param options Expected origin and source permissions.\n * @returns Function that removes this registration.\n */\n registerFrame(frame: HTMLIFrameElement | Window, options: FrameOptions): () => void {\n // Use instanceof here, because the \"in\" operator throws on a cross-origin window.\n const element = typeof HTMLIFrameElement === \"undefined\" ? undefined : HTMLIFrameElement;\n const source = element && frame instanceof element ? frame.contentWindow : frame;\n if (!source || new URL(options.origin).origin !== options.origin || options.origin === \"null\")\n throw new Error(\"A frame registration requires a window and an exact origin.\");\n const registration = { ...options, permissions: [...(options.permissions ?? [\"records\"])] };\n this.sources.set(source, registration);\n this.ensureChildrenLink();\n return () => {\n if (this.sources.get(source) === registration) this.sources.delete(source);\n };\n }\n\n /**\n * Checks if a source is permitted at the given origin.\n * @param source Window or port that sent the message.\n * @param origin Origin supplied by the transport.\n * @returns True if the current source policy permits this source.\n */\n isRegistered(source: object | null, origin: string): boolean {\n if (!source) return false;\n const registration = this.sources.get(source);\n // A registration is bound to its exact origin under every policy, so it needs no\n // trustedOrigins entry.\n if (registration) {\n return registration.origin === origin;\n }\n if (this.config.bus.sourcePolicy === \"registered\") {\n return false;\n }\n return (\n origin !== \"null\" &&\n (origin === location.origin || this.config.bus.trustedOrigins.includes(origin))\n );\n }\n\n /**\n * Sends the new context id to child frames, workers and OpenFin views. Other tabs keep their\n * own context.\n */\n rotateContext(): void {\n // Only the owner sends on the OpenFin link. Without this message every view keeps the old id.\n this.passContext(this.role === \"sender\");\n }\n\n /**\n * Sends the context id to child frames and workers.\n * @param openFin True to send it to OpenFin views too.\n */\n private passContext(openFin: boolean): void {\n const message: BusMessage = {\n t: BUS_TYPE.securityContext,\n from: this.contextId,\n id: this.config.securityContext.id,\n };\n this.postOver(\"children\", message);\n this.postOver(\"worker\", message);\n this.postToDirectChildren(message);\n if (openFin) {\n this.postOver(\"openfin\", message);\n }\n }\n\n /**\n * Sends a security context message to every same-origin child on the direct link, dropping\n * any child that is closed, freed or no longer permitted.\n * @param message Security context message.\n */\n private postToDirectChildren(message: BusMessage): void {\n for (const [peer, ref] of this.directReplies) {\n const reply = ref.deref();\n if (!reply || peer.closed || !this.isRegistered(peer, location.origin)) {\n this.directReplies.delete(peer);\n continue;\n }\n\n this.diagnostics.guard(\"bus.send_failed\", \"The reply to a direct child failed.\", () => {\n reply(message, { link: \"direct\", origin: \"same-origin\", peer });\n });\n }\n }\n\n /**\n * Keeps a direct child's reply callback for the next context id. Closed children are dropped\n * along the way, so a removed frame doesn't keep its document in memory.\n * @param peer The child's window.\n * @param reply The child's reply callback.\n */\n private keepDirectReply(peer: Window, reply: Receive): void {\n for (const known of this.directReplies.keys()) {\n if (known.closed) {\n this.directReplies.delete(known);\n }\n }\n\n this.directReplies.set(peer, new WeakRef(reply));\n }\n\n /** Current bus role. Defaults to \"sender\". */\n private role: BusRole = \"sender\";\n /** Upstream forwarding link, or null when acting as sender. */\n private upstream: Link | null = null;\n /** Open control plane links. */\n private readonly links: Link[] = [];\n /** Shared OpenFin InterApplicationBus link instance. */\n private openFinLink: Link | null = null;\n /** True if this context is the OpenFin platform provider. */\n private isOpenFinProvider = false;\n /** Timer that asks the upstream owner for the remote sampling rules. */\n private rulesPoll: ReturnType<typeof setInterval> | undefined;\n /** True after destroy(), so a handshake that finishes later doesn't start a timer. */\n private destroyed = false;\n /** Context id of the owner that answered the handshake. Null if there was no handshake. */\n private ownerId: string | null = null;\n /** The owner's transport identity, taken from the handshake. */\n private ownerPeer?: object | string;\n /** Active handshake state awaiting welcome response. */\n private awaitingWelcome: {\n link: LinkKind;\n settle: (ok: boolean) => void;\n } | null = null;\n\n /**\n * @param config Active configuration instance.\n * @param diagnostics Diagnostics reporter.\n * @param platform Platform runtime metadata.\n * @param contextId Unique context identifier for loop prevention.\n * @param tabId Tab identifier announced on broadcast channels.\n * @param handlers Callbacks for routed bus events.\n */\n constructor(\n private readonly config: ResolvedConfig,\n private readonly diagnostics: Diagnostics,\n private readonly platform: PlatformMetadata,\n private readonly contextId: string,\n private readonly tabId: string,\n private readonly handlers: BusHandlers,\n private readonly handshakeOptions: HandshakeOptions = HANDSHAKE_OPTIONS,\n ) {}\n\n /** Returns the resolved bus role. */\n getRole(): BusRole {\n return this.role;\n }\n\n /**\n * Resolves bus role and establishes control links.\n * @returns Resolved role.\n */\n async start(): Promise<BusRole> {\n const { bus } = this.config;\n\n if (bus.mode === \"off\") {\n this.role = \"sender\";\n return this.role;\n }\n\n this.isOpenFinProvider = this.resolveOpenFinProvider();\n\n if (bus.mode === \"sender\" || bus.mode === \"forwarder\") {\n this.role = bus.mode;\n this.openControlLinks();\n if (this.role === \"forwarder\") {\n this.upstream = this.candidateUpstream();\n if (!this.upstream) {\n this.diagnostics.report(\n \"bus.no_owner\",\n 'bus.mode is \"forwarder\". No owner exists. The library drops the records of this context.',\n );\n }\n }\n this.announce();\n return this.role;\n }\n\n this.openControlLinks();\n\n // A same-origin parent runtime accepts a direct synchronous link.\n const direct = createDirectLink(this.receive, this.diagnostics);\n if (direct) {\n this.role = \"forwarder\";\n this.upstream = direct;\n await this.handshake(direct);\n this.diagnostics.report(\n \"bus.role_resolved\",\n \"This context attached directly to the runtime of its same-origin parent.\",\n {\n role: \"forwarder\",\n via: \"direct\",\n },\n );\n this.announce();\n return this.role;\n }\n\n const candidate = this.candidateUpstream();\n\n if (!candidate) {\n this.role = \"sender\";\n this.diagnostics.report(\n \"bus.role_resolved\",\n \"No owner exists. This context sends its own records.\",\n {\n role: \"sender\",\n },\n );\n this.announce();\n return this.role;\n }\n\n const attempts = this.orphanPolicy() === \"retry\" ? this.handshakeOptions.maxAttempts : 1;\n\n let welcomed = false;\n for (let attempt = 0; attempt < attempts && !welcomed; attempt++) {\n welcomed = await this.handshake(candidate);\n }\n\n this.role = welcomed ? \"forwarder\" : \"sender\";\n this.upstream = welcomed ? candidate : null;\n if (!welcomed) {\n // The OpenFin link stays open for control messages.\n if (candidate !== this.openFinLink) {\n candidate.close();\n }\n this.diagnostics.report(\n \"bus.handshake_timeout\",\n `No owner answered after ${String(attempts)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`,\n { via: candidate.kind, crossOrigin: this.isCrossOriginFrame() },\n );\n }\n this.diagnostics.report(\"bus.role_resolved\", `The bus role is ${this.role}.`, {\n role: this.role,\n via: welcomed ? candidate.kind : \"none\",\n });\n\n this.announce();\n return this.role;\n }\n\n /**\n * Forwards records to the upstream owner if configured.\n * @param records Batch of log records to send.\n */\n sendRecords(records: LogRecord[]): void {\n const { maxRecordsPerMessage, maxMessageBytes } = this.config.bus;\n const encoder = new TextEncoder();\n const size = (value: unknown): number =>\n maxMessageBytes ? encoder.encode(JSON.stringify(value)).length : 0;\n const message = (chunk: LogRecord[]): BusMessage => ({\n t: BUS_TYPE.records,\n from: this.contextId,\n records: chunk,\n routingContextId: this.config.securityContext.id || undefined,\n });\n\n // Measure every record once. A message is the empty envelope plus its records and the\n // commas between them.\n const envelope = size(message([]));\n let chunk: LogRecord[] = [];\n let bytes = envelope;\n\n for (const record of records) {\n const recordBytes = size(record);\n if (maxMessageBytes && envelope + recordBytes > maxMessageBytes) {\n this.diagnostics.count(\"bus.rejected_message\");\n continue;\n }\n\n const comma = chunk.length > 0 ? 1 : 0;\n if (\n (maxRecordsPerMessage && chunk.length >= maxRecordsPerMessage) ||\n (maxMessageBytes && bytes + comma + recordBytes > maxMessageBytes)\n ) {\n this.upstream?.post(message(chunk));\n chunk = [];\n bytes = envelope;\n }\n\n bytes += (chunk.length > 0 ? 1 : 0) + recordBytes;\n chunk.push(record);\n }\n\n if (chunk.length > 0) {\n this.upstream?.post(message(chunk));\n }\n }\n\n /**\n * Synchronously processes direct messages from same-origin child contexts.\n * @param message Received bus message.\n * @param reply Direct response callback.\n */\n acceptDirect(message: BusMessage, reply: Receive, peer?: Window): void {\n // The child gets the plain source. The reply field stays on this side.\n const plain: MessageSource = { link: \"direct\", origin: \"same-origin\", peer };\n const source: MessageSource = {\n ...plain,\n reply: (answer) => {\n reply(answer, plain);\n },\n };\n if (!this.acceptsMessage(message, source, true)) return;\n if (message.from === this.contextId) {\n return;\n }\n\n // A rotation sends the new id through this reply, so the child doesn't send a stale batch.\n if (peer) {\n this.keepDirectReply(peer, reply);\n }\n\n // A direct link has no channel from parent to child, so the parent answers here. The\n // forwarder rule in routeMessage() would refuse a sampling question on a direct link.\n if (message.t === BUS_TYPE.samplingRequest) {\n reply(this.rulesAnswer(message.from), plain);\n return;\n }\n // While this context still waits for its own owner it has no final id, so it sends none.\n if (\n message.t === BUS_TYPE.records &&\n !this.awaitingWelcome &&\n message.routingContextId !== this.config.securityContext.id\n ) {\n reply(\n { t: BUS_TYPE.securityContext, from: this.contextId, id: this.config.securityContext.id },\n plain,\n );\n }\n this.routeMessage(message, source);\n }\n\n /**\n * Connects a worker instance to the bus control plane.\n * @param worker Worker instance.\n */\n attachWorker(worker: WorkerLike, options: SourceOptions = {}): () => void {\n const registration = { ...options, permissions: [...(options.permissions ?? [\"records\"])] };\n this.sources.set(worker, registration);\n const raw = createWorkerLink(worker, this.receive, this.diagnostics);\n const link: Link = {\n ...raw,\n post: (message) => {\n if (this.mayPost(message, worker)) raw.post(message);\n },\n };\n this.links.push(link);\n return () => {\n link.close();\n const index = this.links.indexOf(link);\n if (index >= 0) this.links.splice(index, 1);\n if (this.sources.get(worker) === registration) this.sources.delete(worker);\n };\n }\n\n /**\n * Sends journey state changes over every link in the journey scope.\n * @param journey Active journey or null if ended.\n */\n broadcastJourney(journey: Journey | null): void {\n this.postJourney({ t: BUS_TYPE.journey, from: this.contextId, journey });\n }\n\n /** Closes all open links and clears internal state. */\n destroy(): void {\n this.sources.clear();\n this.directReplies.clear();\n this.destroyed = true;\n clearInterval(this.rulesPoll);\n this.rulesPoll = undefined;\n for (const link of this.allLinks()) {\n link.close();\n }\n this.links.length = 0;\n this.upstream = null;\n this.ownerId = null;\n this.openFinLink = null;\n }\n\n /** Returns all unique active links including upstream. */\n private allLinks(): Link[] {\n if (!this.upstream || this.links.includes(this.upstream)) {\n return this.links;\n }\n return [...this.links, this.upstream];\n }\n\n /** Sends a message only over links of the given kind. */\n private postOver(link: LinkKind, message: BusMessage): void {\n for (const candidate of this.allLinks()) {\n if (candidate.kind === link) {\n candidate.post(message);\n }\n }\n }\n\n /** Sends a journey message over every link in the journey scope. */\n private postJourney(message: BusMessage): void {\n for (const link of this.allLinks()) {\n if (this.journeyLink(link.kind)) {\n link.post(message);\n }\n }\n }\n\n /** Routes incoming messages to registered handlers or upstream targets. */\n private readonly receive = (message: BusMessage, source: MessageSource): void => {\n // Anything arriving here on the direct link is an answer from the parent, because\n // acceptDirect() handles a direct child's messages. That leaves only the children and worker\n // links carrying child traffic.\n const child = source.link === \"children\" || source.link === \"worker\";\n if (this.acceptsMessage(message, source, child)) {\n this.routeMessage(message, source);\n }\n };\n\n /**\n * Checks the source, the message limits and the message shape before delivery.\n * @param message Message from the source.\n * @param source Link and identity of the source.\n * @param child True if the source is a child of this context.\n * @returns True if the bus can accept the message.\n */\n private acceptsMessage(message: BusMessage, source: MessageSource, child: boolean): boolean {\n if (this.destroyed) {\n return false;\n }\n\n let accepted: boolean;\n try {\n accepted = this.passesChecks(message, source, child);\n } catch {\n // Either a value JSON can't encode or a non-finite number under strict validation.\n // The count below reports the rejection.\n accepted = false;\n }\n\n if (!accepted) {\n this.diagnostics.count(\"bus.rejected_message\");\n }\n return accepted;\n }\n\n /**\n * Runs the source, budget, shape and permission checks. A failed check returns false instead\n * of throwing, so a flood of rejected messages builds no stack traces. Only the JSON encoding\n * can throw, and acceptsMessage catches that.\n * @param message Message from the source.\n * @param source Link and identity of the source.\n * @param child True if the source is a child of this context.\n * @returns True if the message passes every check.\n */\n private passesChecks(message: BusMessage, source: MessageSource, child: boolean): boolean {\n const { bus } = this.config;\n const registration =\n typeof source.peer === \"object\" ? this.sources.get(source.peer) : undefined;\n if (child && bus.sourcePolicy === \"registered\" && !registration) {\n return false;\n }\n\n const object = typeof source.peer === \"object\" ? source.peer : undefined;\n const key = typeof source.peer === \"string\" ? source.peer : source.link;\n const now = Date.now();\n const rate = (object ? this.rates.get(object) : this.channelRates.get(key)) ?? {\n start: now,\n count: 0,\n };\n if (object) {\n this.rates.set(object, rate);\n } else {\n for (const [peer, entry] of this.channelRates) {\n if (windowEnded(entry, 1000, now)) {\n this.channelRates.delete(peer);\n }\n }\n if (\n bus.maxTrackedSources &&\n this.channelRates.size >= bus.maxTrackedSources &&\n !this.channelRates.has(key)\n ) {\n return false;\n }\n this.channelRates.set(key, rate);\n }\n\n // A limit of 0 still counts, just without a cap, so a named source's window stays current.\n if (!countInWindow(rate, bus.maxMessagesPerSecond || Infinity, 1000)) {\n return false;\n }\n\n const encoded = JSON.stringify(message, (_key, value: unknown) => {\n if (bus.validation === \"strict\" && typeof value === \"number\" && !Number.isFinite(value)) {\n throw new Error(\"Non-finite value\");\n }\n return value;\n });\n if (bus.maxMessageBytes && new TextEncoder().encode(encoded).length > bus.maxMessageBytes) {\n return false;\n }\n if (bus.validation === \"strict\" && !validMessage(message)) {\n return false;\n }\n if (\n message.t === BUS_TYPE.records &&\n bus.maxRecordsPerMessage &&\n message.records.length > bus.maxRecordsPerMessage\n ) {\n return false;\n }\n\n if (registration) {\n const permission =\n message.t === BUS_TYPE.records\n ? \"records\"\n : message.t === BUS_TYPE.journey\n ? \"journey:write\"\n : message.t === BUS_TYPE.journeyRequest\n ? \"journey:read\"\n : message.t === BUS_TYPE.samplingRequest\n ? \"sampling:read\"\n : undefined;\n if (permission && !registration.permissions?.includes(permission)) {\n return false;\n }\n }\n\n // Only an upstream owner can publish these control messages.\n if (child && (message.t === BUS_TYPE.sampling || message.t === BUS_TYPE.securityContext)) {\n return false;\n }\n\n // Under the registered policy, broadcast is a control channel only and carries no records.\n return !(\n bus.sourcePolicy === \"registered\" &&\n source.link === \"broadcast\" &&\n message.t === BUS_TYPE.records\n );\n }\n\n /**\n * Hands an accepted message to its handler or to the upstream link.\n * @param message Message that passed the source and shape checks.\n * @param source Link and identity of the source.\n */\n private routeMessage(message: BusMessage, source: MessageSource): void {\n if (message.from === this.contextId) {\n return;\n }\n\n switch (message.t) {\n case BUS_TYPE.hello:\n if (this.canOwn(source.link)) {\n // While this context still waits for its own owner, its id is only temporary, so send\n // none. announce() sends the final id once the role is known.\n this.answer(source, {\n t: BUS_TYPE.welcome,\n from: this.contextId,\n to: message.from,\n tabId: this.tabId,\n routingContextId: this.awaitingWelcome\n ? undefined\n : this.config.securityContext.id || undefined,\n });\n }\n break;\n\n case BUS_TYPE.welcome:\n if (message.to !== this.contextId) {\n break;\n }\n if (\n this.awaitingWelcome?.link === source.link ||\n (this.upstream?.kind === source.link && this.ownerId === null)\n ) {\n // Remember the owner. On a shared link, only the owner may set this context's journey.\n this.ownerId = message.from;\n this.ownerPeer = source.peer;\n const before = this.config.securityContext.id;\n if (\n message.routingContextId &&\n this.handlers.onSecurityContext?.(message.routingContextId) === false\n )\n break;\n // Our children may still hold the old id, so pass the owner's id on to them. During a\n // handshake the role can still be \"sender\", so don't send on the OpenFin link here.\n if (this.config.securityContext.id !== before) {\n this.passContext(false);\n }\n this.awaitingWelcome?.settle(true);\n }\n break;\n\n case BUS_TYPE.records:\n if (\n this.config.securityContext.isolation &&\n this.config.securityContext.id &&\n message.routingContextId !== this.config.securityContext.id\n ) {\n this.diagnostics.count(\"security.context_mismatch\");\n break;\n }\n if (this.role === \"sender\") {\n this.handlers.onRecords(message.records);\n } else if (this.upstream && this.canRelay(source.link)) {\n // Relays records upstream in nested frame chains.\n this.upstream.post(message);\n }\n break;\n\n case BUS_TYPE.securityContext:\n if (\n source.link === this.upstream?.kind &&\n this.ownerId === message.from &&\n this.ownerPeer === source.peer\n ) {\n if (this.handlers.onSecurityContext?.(message.id) !== false) this.rotateContext();\n }\n break;\n\n case BUS_TYPE.journey:\n if (this.acceptsJourney(message, source)) {\n this.applyJourney(message.journey);\n }\n break;\n\n case BUS_TYPE.journeyRequest: {\n const current = this.handlers.onJourneyRequest();\n // Address the answer, so that every other context on a shared link ignores it.\n if (current && this.journeyLink(source.link)) {\n this.answer(source, {\n t: BUS_TYPE.journey,\n from: this.contextId,\n to: message.from,\n journey: current,\n });\n }\n break;\n }\n\n case BUS_TYPE.samplingRequest:\n // A forwarder answers only its own children, although siblings on its upstream link ask\n // too. Siblings answering each other on OpenFin would mean N squared messages, and a\n // stale copy could win.\n if (\n this.role === \"forwarder\" ? source.link !== this.upstream?.kind : this.canOwn(source.link)\n ) {\n this.answer(source, this.rulesAnswer(message.from));\n }\n break;\n\n case BUS_TYPE.sampling:\n if (this.acceptsRules(message.to, source)) {\n this.applyRules(message.rules);\n }\n break;\n\n case BUS_TYPE.tab:\n // Only two different contexts on the broadcast channel can collide. The id comparison\n // picks one of the pair, otherwise both would report the conflict and rename.\n if (\n source.link === \"broadcast\" &&\n message.tabId === this.tabId &&\n this.contextId > message.from\n ) {\n this.handlers.onTabConflict();\n }\n break;\n }\n }\n\n /**\n * Answers whoever sent a message. A link that can address a single source sends to it only.\n * @param source Link and identity of the source.\n * @param message Answer to send.\n */\n private answer(source: MessageSource, message: BusMessage): void {\n if (source.reply) {\n source.reply(message);\n return;\n }\n this.postOver(source.link, message);\n }\n\n /**\n * Checks whether records from a link can go upstream. Records sent back out on the link\n * they arrived on would return to their sender. A direct link is the exception, because\n * each one is a single call into one parent, so two direct links in a chain are\n * different links.\n * @param link Kind of the link the records arrived on.\n * @returns True if the relay is safe.\n */\n private canRelay(link: LinkKind): boolean {\n return link === \"direct\" || link !== this.upstream?.kind;\n }\n\n /** Checks whether this context can own the given link type. */\n private canOwn(link: LinkKind): boolean {\n // A forwarder that knows its owner also owns its own children and relays their records\n // upstream.\n const owner = this.role === \"sender\" || this.ownerId !== null;\n if (!owner) {\n return false;\n }\n if (link === \"openfin\") {\n return this.role === \"sender\" && this.isOpenFinProvider;\n }\n return OWNED.includes(link);\n }\n\n /** Works out whether this context is the OpenFin platform provider. */\n private resolveOpenFinProvider(): boolean {\n const configured = this.config.bus.openFinRole;\n if (configured !== \"auto\") {\n return configured === \"provider\";\n }\n if (this.platform.platform !== \"openfin\" && this.platform.platform !== \"openfin_web\") {\n return false;\n }\n\n const me = getFin()?.me;\n if (!me?.identity || me.isView) {\n return false;\n }\n return Boolean(me.identity.name && me.identity.name === me.identity.uuid);\n }\n\n /** Resolves the handshake orphan policy for the current platform context. */\n private orphanPolicy(): \"promote\" | \"retry\" {\n return this.isCrossOriginFrame() ? \"retry\" : \"promote\";\n }\n\n /** Checks whether a cross-origin boundary blocks access to the parent window. */\n private isCrossOriginFrame(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) {\n return false;\n }\n try {\n // A cross-origin parent throws on this read. It goes through Reflect.get because lint\n // rejects a bare property read.\n Reflect.get(window.parent, \"location\");\n return false;\n } catch {\n return true;\n }\n }\n\n /** Identifies the candidate upstream link based on platform hierarchy. */\n private candidateUpstream(): Link | null {\n if (this.platform.isWorker) {\n return createOwnerLink(this.receive, this.diagnostics);\n }\n if (!this.platform.isTopLevelDocument) {\n return createParentLink(this.receive, this.config.bus.trustedOrigins, this.diagnostics);\n }\n if (this.platform.platform === \"openfin\" && !this.isOpenFinProvider) {\n return this.ensureOpenFinLink();\n }\n return null;\n }\n\n /** Opens control links supported by the current runtime environment. */\n private openControlLinks(): void {\n const push = (link: Link | null): void => {\n if (link) {\n this.links.push(link);\n }\n };\n\n if (!this.platform.isWorker) this.ensureChildrenLink();\n if (this.platform.isTopLevelDocument) {\n push(createBroadcastLink(BUS_CHANNEL_NAME, this.receive, this.diagnostics));\n }\n if (this.platform.platform === \"openfin\" || this.platform.platform === \"openfin_web\") {\n push(this.ensureOpenFinLink());\n }\n }\n\n /** Opens the link to child frames if it is not already open. */\n private ensureChildrenLink(): void {\n if (this.links.some((link) => link.kind === \"children\")) return;\n const link = createChildrenLink(\n this.receive,\n this.config.bus.trustedOrigins,\n this.diagnostics,\n (source, origin) => {\n const accepted = this.isRegistered(source, origin);\n if (!accepted) {\n this.diagnostics.count(\"bus.rejected_message\");\n // A registered window speaking from another origin is untrusted too. Without this\n // report, a registration with the wrong origin silences the frame with no named cause.\n const registered = source !== null && this.sources.has(source);\n const trusted =\n origin === location.origin || this.config.bus.trustedOrigins.includes(origin);\n if (registered || !trusted) {\n this.diagnostics.report(\n \"bus.untrusted_origin\",\n \"The bus rejected a message from an untrusted origin.\",\n );\n }\n }\n return accepted;\n },\n (message, source) => this.mayPost(message, source),\n );\n if (link) this.links.push(link);\n }\n\n /** Returns the singleton OpenFin InterApplicationBus link. */\n private ensureOpenFinLink(): Link | null {\n this.openFinLink ??= createOpenFinLink(\n BUS_CHANNEL_NAME,\n this.platform.openfinUuid,\n this.receive,\n this.diagnostics,\n );\n return this.openFinLink;\n }\n\n /**\n * Runs a hello/welcome handshake over the candidate link.\n * @param candidate Upstream link candidate.\n * @returns True if the welcome arrived before the timeout.\n */\n private handshake(candidate: Link): Promise<boolean> {\n return new Promise((resolve) => {\n let settled = false;\n\n const finish = (result: boolean): void => {\n if (settled) {\n return;\n }\n settled = true;\n this.awaitingWelcome = null;\n clearTimeout(timer);\n resolve(result);\n };\n\n this.awaitingWelcome = { link: candidate.kind, settle: finish };\n // finish reads timer, which is declared after it. That's safe, because finish can only\n // run after the post below, and by then the timer exists.\n const timer = setTimeout(() => {\n finish(false);\n }, this.handshakeOptions.timeoutMs);\n unrefTimer(timer);\n candidate.post({ t: BUS_TYPE.hello, from: this.contextId, tabId: this.tabId });\n });\n }\n\n /** Broadcasts tab claim and queries existing journey state. */\n private announce(): void {\n this.postOver(\"broadcast\", {\n t: BUS_TYPE.tab,\n from: this.contextId,\n tabId: this.tabId,\n });\n if (this.upstream && this.ownerId === null)\n this.upstream.post({ t: BUS_TYPE.hello, from: this.contextId, tabId: this.tabId });\n this.postJourney({ t: BUS_TYPE.journeyRequest, from: this.contextId });\n this.pollRules();\n // The role is final now. Children welcomed during the handshake got no id, so send it now.\n this.passContext(false);\n }\n\n /**\n * Resolves the journey scope. \"auto\" becomes \"origin\" in OpenFin and \"tab\" in a browser.\n * @returns The scope in effect.\n */\n private journeyScope(): ResolvedScope {\n const { scope } = this.config.journey;\n if (scope !== \"auto\") {\n return scope;\n }\n\n const { platform } = this.platform;\n return platform === \"openfin\" || platform === \"openfin_web\" ? \"origin\" : \"tab\";\n }\n\n /**\n * Checks whether a link carries journey messages in the current scope.\n * Only \"origin\" uses the broadcast link, which reaches every tab on the origin.\n * @param link Link kind.\n * @returns True if the link carries journey messages.\n */\n private journeyLink(link: LinkKind): boolean {\n const scope = this.journeyScope();\n if (scope === \"context\") {\n return false;\n }\n\n return scope === \"origin\" || link !== \"broadcast\";\n }\n\n /**\n * Checks whether this context adopts a journey message.\n * @param message Journey message.\n * @param source Link and origin of the message.\n * @returns True for a message on a journey link, addressed to this context, from an accepted\n * sender. In \"tab\" scope, the only accepted sender is a forwarder's owner.\n */\n private acceptsJourney(\n message: Extract<BusMessage, { t: typeof BUS_TYPE.journey }>,\n source: MessageSource,\n ): boolean {\n if (!this.journeyLink(source.link)) {\n return false;\n }\n\n if (message.to !== undefined && message.to !== this.contextId) {\n return false;\n }\n\n return (\n this.journeyScope() === \"origin\" ||\n (this.fromOwner(message.from, source.link) &&\n (this.ownerPeer === undefined || this.ownerPeer === source.peer))\n );\n }\n\n /**\n * Checks whether a message comes from this forwarder's upstream owner.\n * @param from Context id of the sender.\n * @param link Link kind of the message.\n * @returns True for the upstream link and, after a handshake, the owner that answered it.\n */\n private fromOwner(from: string, link: LinkKind): boolean {\n if (this.role !== \"forwarder\" || link !== this.upstream?.kind) {\n return false;\n }\n\n return this.ownerId === null || from === this.ownerId;\n }\n\n /**\n * Parses a journey payload from another realm and hands it to the runtime.\n * @param payload Journey, or null when the journey ended.\n */\n private applyJourney(payload: unknown): void {\n if (payload === null) {\n this.handlers.onJourney(null);\n return;\n }\n\n const journey = parseJourney(payload);\n if (journey === null) {\n this.diagnostics.report(\n \"record.dropped_malformed\",\n \"The bus dropped a journey message. Its payload is not a journey.\",\n { type: \"journey\" },\n );\n return;\n }\n\n this.handlers.onJourney(journey);\n }\n\n /**\n * Builds the answer to a sampling question. Null rules clear the forwarder's copy.\n * @param to Context id of the forwarder that asked.\n * @returns The answer.\n */\n private rulesAnswer(to: string): BusMessage {\n const rules = this.handlers.remote.sampling?.wire() ?? null;\n\n return { t: BUS_TYPE.sampling, from: this.contextId, to, rules };\n }\n\n /**\n * Checks whether this context accepts sampling rules from a source.\n * @param to Context id that the answer names.\n * @param source Link and origin of the answer.\n * @returns True only for an answer from the upstream owner to this context.\n */\n private acceptsRules(to: string, source: MessageSource): boolean {\n // Accept rules only from the upstream owner. A sibling on a shared link isn't trusted.\n if (this.role !== \"forwarder\" || to !== this.contextId || source.link !== this.upstream?.kind) {\n return false;\n }\n\n // A page on another origin can embed this app. Don't let it lower minLevel and read the\n // records.\n const { origin } = source;\n\n if (\n source.link === \"parent\" &&\n origin !== location.origin &&\n !this.config.bus.trustedOrigins.includes(origin)\n ) {\n this.diagnostics.report(\n \"bus.untrusted_origin\",\n `The bus ignored sampling rules from ${origin}. If you own this origin, add it to bus.trustedOrigins.`,\n { origin, type: \"sampling\" },\n );\n return false;\n }\n\n return this.ownerPeer === undefined || this.ownerPeer === source.peer;\n }\n\n /**\n * Applies the rules from an answer, ignoring any that are invalid.\n * @param raw The answer's rules, or null when the upstream has none.\n */\n private applyRules(raw: unknown): void {\n if (raw === null) {\n applyRemote(this.handlers.remote, this.config, null);\n return;\n }\n\n const update = parseRemoteRules(raw, this.diagnostics);\n\n if (update) {\n applyRemote(this.handlers.remote, this.config, update);\n }\n }\n\n /**\n * Asks the upstream owner for the remote sampling rules now, then on every poll interval.\n * A direct link can't push the rules to a child, but a poll works on every link kind.\n */\n private pollRules(): void {\n const { upstream } = this;\n\n if (this.destroyed || this.role !== \"forwarder\" || !upstream) {\n return;\n }\n\n // Read the config on every poll, because a later configure() can turn remote sampling on\n // or off.\n const ask = (): void => {\n if (this.config.sampling.remote) {\n upstream.post({ t: BUS_TYPE.samplingRequest, from: this.contextId });\n }\n };\n\n ask();\n this.rulesPoll = setInterval(ask, REMOTE_SAMPLING_POLL_MS);\n unrefTimer(this.rulesPoll);\n }\n}\n"],"mappings":"A,+QAaA,SAAgBuB,EAAa,EAAqC,CAChE,GAAI,OAAOC,GAAU,WAAYA,EAAgB,MAAO,GACxD,IAAMC,EAAID,EACV,GAAI,OAAOC,EAAE,MAAS,UAAY,CAACA,EAAE,MAAQ,OAAOA,EAAE,GAAM,SAAU,MAAO,GAC7E,IAAMC,EAAQ,GAAyB,OAAOD,EAAEE,IAAS,SACzD,OAAQF,EAAE,EAAV,CACE,KAAKzB,EAAAA,EAAS,MACd,KAAKA,EAAAA,EAAS,IACZ,OAAO0B,EAAK,OAAO,EACrB,KAAK1B,EAAAA,EAAS,QACZ,OACE0B,EAAK,IAAI,GACTA,EAAK,OAAO,IACXD,EAAE,mBAAqB,IAAA,IAAaC,EAAK,kBAAkB,GAEhE,KAAK1B,EAAAA,EAAS,eACd,KAAKA,EAAAA,EAAS,gBACZ,MAAO,GACT,KAAKA,EAAAA,EAAS,gBACZ,OAAO0B,EAAK,IAAI,GAAKD,EAAE,KAAO,GAChC,KAAKzB,EAAAA,EAAS,QACZ,OAAQyB,EAAE,KAAO,IAAA,IAAaC,EAAK,IAAI,IAAM,YAAaD,EAC5D,KAAKzB,EAAAA,EAAS,SACZ,OAAO0B,EAAK,IAAI,GAAK,UAAWD,EAClC,KAAKzB,EAAAA,EAAS,QAC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