@utk09/ui-observability 0.9.3 → 0.9.5

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 (227) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +199 -96
  3. package/dist/batch-BQFtb3i5.cjs +2 -0
  4. package/dist/batch-BQFtb3i5.cjs.map +1 -0
  5. package/dist/{batch-DDgxg16_.js → batch-BUJh-1jZ.js} +6 -4
  6. package/dist/batch-BUJh-1jZ.js.map +1 -0
  7. package/dist/bus/bus.d.ts +76 -2
  8. package/dist/bus/links.d.ts +9 -2
  9. package/dist/bus/validation.d.ts +7 -0
  10. package/dist/bus-BW6N-pY8.cjs +2 -0
  11. package/dist/bus-BW6N-pY8.cjs.map +1 -0
  12. package/dist/bus-DeOPHWaD.js +647 -0
  13. package/dist/bus-DeOPHWaD.js.map +1 -0
  14. package/dist/capture/network.d.ts +1 -0
  15. package/dist/capture/storm.d.ts +2 -1
  16. package/dist/capture/types.d.ts +5 -0
  17. package/dist/capture/web-socket.d.ts +40 -0
  18. package/dist/{console-BSusX_M-.cjs → console-Ce6heqZZ.cjs} +2 -2
  19. package/dist/console-Ce6heqZZ.cjs.map +1 -0
  20. package/dist/{console-Dv5GfaNn.js → console-DbAZYJuy.js} +4 -4
  21. package/dist/console-DbAZYJuy.js.map +1 -0
  22. package/dist/constants-CN7GE1Lt.js +246 -0
  23. package/dist/constants-CN7GE1Lt.js.map +1 -0
  24. package/dist/constants-CW-MlHdY.cjs +2 -0
  25. package/dist/constants-CW-MlHdY.cjs.map +1 -0
  26. package/dist/constants.d.ts +63 -11
  27. package/dist/context-storage-BjzeBSxH.cjs +2 -0
  28. package/dist/context-storage-BjzeBSxH.cjs.map +1 -0
  29. package/dist/context-storage-DxZf4Gfh.js +52 -0
  30. package/dist/context-storage-DxZf4Gfh.js.map +1 -0
  31. package/dist/core/breadcrumbs.d.ts +10 -3
  32. package/dist/core/context.d.ts +2 -0
  33. package/dist/core/diagnostics.d.ts +11 -3
  34. package/dist/core/journey.d.ts +7 -0
  35. package/dist/core/meter.d.ts +25 -2
  36. package/dist/core/pipeline.d.ts +41 -6
  37. package/dist/core/record.d.ts +42 -9
  38. package/dist/core/remote-sampling.d.ts +7 -3
  39. package/dist/core/runtime.d.ts +153 -6
  40. package/dist/core/sampling.d.ts +35 -2
  41. package/dist/core/sender.d.ts +43 -1
  42. package/dist/core/spans.d.ts +34 -0
  43. package/dist/deadline-5_PecIl5.js +26 -0
  44. package/dist/deadline-5_PecIl5.js.map +1 -0
  45. package/dist/deadline-XSnm95pg.cjs +2 -0
  46. package/dist/deadline-XSnm95pg.cjs.map +1 -0
  47. package/dist/emergency-queue-BYUyDHGD.js +69 -0
  48. package/dist/emergency-queue-BYUyDHGD.js.map +1 -0
  49. package/dist/emergency-queue-Cs1hrjsC.cjs +2 -0
  50. package/dist/emergency-queue-Cs1hrjsC.cjs.map +1 -0
  51. package/dist/{errors-DCZWcHkd.js → errors-BhC7HTSt.js} +8 -9
  52. package/dist/errors-BhC7HTSt.js.map +1 -0
  53. package/dist/errors-CgY633cG.cjs +3 -0
  54. package/dist/errors-CgY633cG.cjs.map +1 -0
  55. package/dist/factory-C5TujXlU.js +280 -0
  56. package/dist/factory-C5TujXlU.js.map +1 -0
  57. package/dist/factory-CNj4DH3n.cjs +2 -0
  58. package/dist/factory-CNj4DH3n.cjs.map +1 -0
  59. package/dist/fixed-window-CtaFHanJ.js +12 -0
  60. package/dist/fixed-window-CtaFHanJ.js.map +1 -0
  61. package/dist/fixed-window-CvESpFYV.cjs +2 -0
  62. package/dist/fixed-window-CvESpFYV.cjs.map +1 -0
  63. package/dist/identity-8vKkyAWm.js +103 -0
  64. package/dist/identity-8vKkyAWm.js.map +1 -0
  65. package/dist/identity-Da9TkuKd.cjs +2 -0
  66. package/dist/identity-Da9TkuKd.cjs.map +1 -0
  67. package/dist/index.cjs +1 -1
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.d.ts +66 -6
  70. package/dist/index.js +1253 -595
  71. package/dist/index.js.map +1 -1
  72. package/dist/indexeddb-storage-BTfIFRHF.cjs +2 -0
  73. package/dist/indexeddb-storage-BTfIFRHF.cjs.map +1 -0
  74. package/dist/{indexeddb-storage-T9YIYVYC.js → indexeddb-storage-CCA1LvtO.js} +45 -30
  75. package/dist/indexeddb-storage-CCA1LvtO.js.map +1 -0
  76. package/dist/{interactions-BLH_tX87.js → interactions-BUDLxbv1.js} +16 -12
  77. package/dist/interactions-BUDLxbv1.js.map +1 -0
  78. package/dist/interactions-NHbLKrqe.cjs +2 -0
  79. package/dist/interactions-NHbLKrqe.cjs.map +1 -0
  80. package/dist/{journey-yALMEWF7.js → journey-BUJ4WJxP.js} +37 -34
  81. package/dist/journey-BUJ4WJxP.js.map +1 -0
  82. package/dist/journey-B_tTnvac.cjs +2 -0
  83. package/dist/journey-B_tTnvac.cjs.map +1 -0
  84. package/dist/keys-BHhw_0Wh.cjs +2 -0
  85. package/dist/keys-BHhw_0Wh.cjs.map +1 -0
  86. package/dist/keys-D5r_GH9q.js +17 -0
  87. package/dist/keys-D5r_GH9q.js.map +1 -0
  88. package/dist/{library-request-CQD4HUiP.js → library-request-BKOcaKtQ.js} +3 -3
  89. package/dist/{library-request-CQD4HUiP.js.map → library-request-BKOcaKtQ.js.map} +1 -1
  90. package/dist/{library-request-BcAxuwsf.cjs → library-request-BaZOi4eg.cjs} +2 -2
  91. package/dist/{library-request-BcAxuwsf.cjs.map → library-request-BaZOi4eg.cjs.map} +1 -1
  92. package/dist/{long-frames-D4Bm3Zkz.cjs → long-frames-CF3qiSAX.cjs} +2 -2
  93. package/dist/long-frames-CF3qiSAX.cjs.map +1 -0
  94. package/dist/{long-frames-DD_Um9_4.js → long-frames-DI5ypfAF.js} +5 -5
  95. package/dist/long-frames-DI5ypfAF.js.map +1 -0
  96. package/dist/models/batch.d.ts +4 -0
  97. package/dist/models/bus.d.ts +32 -9
  98. package/dist/models/config.d.ts +401 -12
  99. package/dist/models/drop.d.ts +1 -1
  100. package/dist/models/health.d.ts +27 -0
  101. package/dist/models/log-record.d.ts +1 -1
  102. package/dist/models/plugin.d.ts +47 -0
  103. package/dist/models/stats.d.ts +11 -0
  104. package/dist/models/storage.d.ts +13 -0
  105. package/dist/network-CF8UO5PK.cjs +2 -0
  106. package/dist/network-CF8UO5PK.cjs.map +1 -0
  107. package/dist/{network--GoE7_Or.js → network-DdzXDI3J.js} +47 -31
  108. package/dist/network-DdzXDI3J.js.map +1 -0
  109. package/dist/openfin-BwEN0uj4.js.map +1 -1
  110. package/dist/openfin-DtH2f7zX.cjs.map +1 -1
  111. package/dist/{platform-GaM6h7XM.js → platform-Bw1btWCT.js} +21 -10
  112. package/dist/platform-Bw1btWCT.js.map +1 -0
  113. package/dist/platform-DBSKTvFn.cjs +2 -0
  114. package/dist/platform-DBSKTvFn.cjs.map +1 -0
  115. package/dist/remote-rules-DIcC5vVC.js +91 -0
  116. package/dist/remote-rules-DIcC5vVC.js.map +1 -0
  117. package/dist/remote-rules-DpFmOef2.cjs +2 -0
  118. package/dist/remote-rules-DpFmOef2.cjs.map +1 -0
  119. package/dist/sampling-BVjspJWu.cjs +2 -0
  120. package/dist/sampling-BVjspJWu.cjs.map +1 -0
  121. package/dist/sampling-Cm3WhI0a.js +76 -0
  122. package/dist/sampling-Cm3WhI0a.js.map +1 -0
  123. package/dist/{sanitize-DP0xDPrt.js → sanitize-C-ahCFsG.js} +2 -2
  124. package/dist/{sanitize-DP0xDPrt.js.map → sanitize-C-ahCFsG.js.map} +1 -1
  125. package/dist/{sanitize--_e4oOPX.cjs → sanitize-DHucKGdi.cjs} +2 -2
  126. package/dist/{sanitize--_e4oOPX.cjs.map → sanitize-DHucKGdi.cjs.map} +1 -1
  127. package/dist/sender-D3fRCR8d.cjs +3 -0
  128. package/dist/sender-D3fRCR8d.cjs.map +1 -0
  129. package/dist/sender-DUUmSglb.js +1163 -0
  130. package/dist/sender-DUUmSglb.js.map +1 -0
  131. package/dist/storage/context-storage.d.ts +89 -0
  132. package/dist/storage/emergency-queue.d.ts +9 -1
  133. package/dist/storage/factory.d.ts +7 -1
  134. package/dist/storage/idb-driver.d.ts +13 -0
  135. package/dist/storage/indexeddb-storage.d.ts +13 -0
  136. package/dist/storage/local-storage.d.ts +21 -1
  137. package/dist/storage/memory-storage.d.ts +13 -0
  138. package/dist/storage-BA9RqRO-.cjs +2 -0
  139. package/dist/storage-BA9RqRO-.cjs.map +1 -0
  140. package/dist/storage-w7Tslvlq.js +17 -0
  141. package/dist/storage-w7Tslvlq.js.map +1 -0
  142. package/dist/storm-CNZjsw4T.cjs +2 -0
  143. package/dist/storm-CNZjsw4T.cjs.map +1 -0
  144. package/dist/storm-Daq2jGHU.js +10 -0
  145. package/dist/storm-Daq2jGHU.js.map +1 -0
  146. package/dist/transport/exit-flush.d.ts +6 -0
  147. package/dist/transport/http-transport.d.ts +2 -1
  148. package/dist/transport/retry-engine.d.ts +7 -2
  149. package/dist/transport/serializers/otlp-traces.d.ts +3 -0
  150. package/dist/transport/serializers/select.d.ts +8 -5
  151. package/dist/transport/status-transport.d.ts +24 -0
  152. package/dist/types-BR9t_w28.js +8 -0
  153. package/dist/types-BR9t_w28.js.map +1 -0
  154. package/dist/types-C7WNpnG1.cjs +2 -0
  155. package/dist/types-C7WNpnG1.cjs.map +1 -0
  156. package/dist/utils/fixed-window.d.ts +9 -0
  157. package/dist/utils/identity.d.ts +20 -2
  158. package/dist/utils/lock.d.ts +8 -0
  159. package/dist/utils/openfin.d.ts +1 -1
  160. package/dist/utils/platform.d.ts +10 -0
  161. package/dist/utils/tracing.d.ts +82 -4
  162. package/dist/web-socket-BacvKOvD.cjs +2 -0
  163. package/dist/web-socket-BacvKOvD.cjs.map +1 -0
  164. package/dist/web-socket-CpsD8WAa.js +105 -0
  165. package/dist/web-socket-CpsD8WAa.js.map +1 -0
  166. package/package.json +1 -1
  167. package/dist/batch-D5qvsMQ_.cjs +0 -2
  168. package/dist/batch-D5qvsMQ_.cjs.map +0 -1
  169. package/dist/batch-DDgxg16_.js.map +0 -1
  170. package/dist/bus-C6RwKzPW.js +0 -478
  171. package/dist/bus-C6RwKzPW.js.map +0 -1
  172. package/dist/bus-WPVDFw2y.cjs +0 -2
  173. package/dist/bus-WPVDFw2y.cjs.map +0 -1
  174. package/dist/console-BSusX_M-.cjs.map +0 -1
  175. package/dist/console-Dv5GfaNn.js.map +0 -1
  176. package/dist/constants-Cb92egPS.cjs +0 -2
  177. package/dist/constants-Cb92egPS.cjs.map +0 -1
  178. package/dist/constants-DhH6VI5a.js +0 -144
  179. package/dist/constants-DhH6VI5a.js.map +0 -1
  180. package/dist/deadline-CUrH0Hd8.cjs +0 -2
  181. package/dist/deadline-CUrH0Hd8.cjs.map +0 -1
  182. package/dist/deadline-DeqXEliN.js +0 -31
  183. package/dist/deadline-DeqXEliN.js.map +0 -1
  184. package/dist/errors-DCZWcHkd.js.map +0 -1
  185. package/dist/errors-ERu-su8m.cjs +0 -3
  186. package/dist/errors-ERu-su8m.cjs.map +0 -1
  187. package/dist/fixed-window-BR0bu32Y.cjs +0 -2
  188. package/dist/fixed-window-BR0bu32Y.cjs.map +0 -1
  189. package/dist/fixed-window-Re7jIRJH.js +0 -9
  190. package/dist/fixed-window-Re7jIRJH.js.map +0 -1
  191. package/dist/identity-C1WLItSl.cjs +0 -2
  192. package/dist/identity-C1WLItSl.cjs.map +0 -1
  193. package/dist/identity-Di-QXGCC.js +0 -88
  194. package/dist/identity-Di-QXGCC.js.map +0 -1
  195. package/dist/indexeddb-storage-DX18p39D.cjs +0 -2
  196. package/dist/indexeddb-storage-DX18p39D.cjs.map +0 -1
  197. package/dist/indexeddb-storage-T9YIYVYC.js.map +0 -1
  198. package/dist/interactions-BLH_tX87.js.map +0 -1
  199. package/dist/interactions-_hfOerfC.cjs +0 -2
  200. package/dist/interactions-_hfOerfC.cjs.map +0 -1
  201. package/dist/journey-BRUj0hqD.cjs +0 -2
  202. package/dist/journey-BRUj0hqD.cjs.map +0 -1
  203. package/dist/journey-yALMEWF7.js.map +0 -1
  204. package/dist/long-frames-D4Bm3Zkz.cjs.map +0 -1
  205. package/dist/long-frames-DD_Um9_4.js.map +0 -1
  206. package/dist/network--GoE7_Or.js.map +0 -1
  207. package/dist/network-DcuS2H1P.cjs +0 -2
  208. package/dist/network-DcuS2H1P.cjs.map +0 -1
  209. package/dist/platform-GaM6h7XM.js.map +0 -1
  210. package/dist/platform-kIL5AZB7.cjs +0 -2
  211. package/dist/platform-kIL5AZB7.cjs.map +0 -1
  212. package/dist/remote-rules-6ePq8CrI.js +0 -84
  213. package/dist/remote-rules-6ePq8CrI.js.map +0 -1
  214. package/dist/remote-rules-CI3gbRCL.cjs +0 -2
  215. package/dist/remote-rules-CI3gbRCL.cjs.map +0 -1
  216. package/dist/sampling-C-M8p3FK.cjs +0 -2
  217. package/dist/sampling-C-M8p3FK.cjs.map +0 -1
  218. package/dist/sampling-Ud_WiuU9.js +0 -65
  219. package/dist/sampling-Ud_WiuU9.js.map +0 -1
  220. package/dist/sender-BESHz6my.cjs +0 -3
  221. package/dist/sender-BESHz6my.cjs.map +0 -1
  222. package/dist/sender-BUBWLn5i.js +0 -1244
  223. package/dist/sender-BUBWLn5i.js.map +0 -1
  224. package/dist/storm-DhHGHhOc.cjs +0 -2
  225. package/dist/storm-DhHGHhOc.cjs.map +0 -1
  226. package/dist/storm-OD5J6Ylm.js +0 -10
  227. package/dist/storm-OD5J6Ylm.js.map +0 -1
@@ -0,0 +1,647 @@
1
+ import { D as e, O as t, Qt as n, Rt as r, T as i, an as a, w as o } from "./constants-CN7GE1Lt.js";
2
+ import { c as s, s as c } from "./sampling-Cm3WhI0a.js";
3
+ import { r as l } from "./deadline-5_PecIl5.js";
4
+ import { t as u } from "./openfin-BwEN0uj4.js";
5
+ import { r as d } from "./journey-BUJ4WJxP.js";
6
+ import { n as f, t as p } from "./fixed-window-CtaFHanJ.js";
7
+ import { n as m, t as h } from "./remote-rules-DIcC5vVC.js";
8
+ //#region src/bus/validation.ts
9
+ function g(e) {
10
+ if (typeof e != "object" || !e) return !1;
11
+ let n = e;
12
+ if (typeof n.from != "string" || !n.from || typeof n.t != "string") return !1;
13
+ let r = (e) => typeof n[e] == "string";
14
+ switch (n.t) {
15
+ case t.hello:
16
+ case t.tab: return r("tabId");
17
+ case t.welcome: return r("to") && r("tabId") && (n.routingContextId === void 0 || r("routingContextId"));
18
+ case t.journeyRequest:
19
+ case t.samplingRequest: return !0;
20
+ case t.securityContext: return r("id") && n.id !== "";
21
+ case t.journey: return (n.to === void 0 || r("to")) && "journey" in n;
22
+ case t.sampling: return r("to") && "rules" in n;
23
+ case t.records: return Array.isArray(n.records) && (n.routingContextId === void 0 || r("routingContextId")) && n.records.every((e) => !s(e) || !c(e.severityText) ? !1 : !Array.isArray(e.attributes) && !Array.isArray(e.resource) && /^\d+$/.test(e.timeUnixNano) && (e.observedTimeUnixNano === void 0 || /^\d+$/.test(e.observedTimeUnixNano)) && typeof e.traceId == "string" && /^(?:[a-f\d]{32})?$/.test(e.traceId) && typeof e.spanId == "string" && /^(?:[a-f\d]{16})?$/.test(e.spanId) && Number.isInteger(e.traceFlags) && e.traceFlags >= 0 && e.traceFlags <= 255 && e.severityNumber === a[e.severityText]);
24
+ default: return !1;
25
+ }
26
+ }
27
+ //#endregion
28
+ //#region src/models/bus.ts
29
+ function _(t) {
30
+ return {
31
+ p: e,
32
+ m: t
33
+ };
34
+ }
35
+ function v(e) {
36
+ if (typeof e != "object" || !e) return null;
37
+ let t = e;
38
+ if (t.p !== "ui-observability/2" || typeof t.m != "object" || t.m === null) return null;
39
+ let n = t.m;
40
+ return typeof n.t == "string" ? n : null;
41
+ }
42
+ //#endregion
43
+ //#region src/bus/links.ts
44
+ var y = Symbol.for(n), b = "null";
45
+ function x(e, t) {
46
+ return e === b ? `The bus ignored ${t} 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.` : `The bus ignored ${t} from ${e}. If you own this origin, add it to bus.trustedOrigins.`;
47
+ }
48
+ function S() {
49
+ let e = location.ancestorOrigins;
50
+ if (e && e.length > 0) return e.item(0);
51
+ let t = document.referrer;
52
+ if (t === "") return null;
53
+ try {
54
+ return new URL(t).origin;
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+ function C(e, t) {
60
+ if (typeof window > "u" || window.parent === window) return null;
61
+ let n;
62
+ try {
63
+ n = window.parent[y];
64
+ } catch {
65
+ return null;
66
+ }
67
+ if (typeof n?.busAccept != "function" || n.busCanAccept && !n.busCanAccept(window, location.origin)) return null;
68
+ let r = n, i = !0;
69
+ return {
70
+ kind: "direct",
71
+ post(n) {
72
+ i && t.guard("bus.send_failed", "The direct call into the parent runtime failed.", () => {
73
+ r.busAccept(n, e, window);
74
+ });
75
+ },
76
+ close() {
77
+ i = !1;
78
+ }
79
+ };
80
+ }
81
+ function w(e, t, n) {
82
+ if (typeof window > "u" || window.parent === window) return null;
83
+ let r = location.origin;
84
+ if (r === b) return n.report("bus.untrusted_origin", "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.", {
85
+ origin: r,
86
+ type: "parent"
87
+ }), null;
88
+ let i = /* @__PURE__ */ new Set([r, ...t]), a = S();
89
+ if (a === null || !i.has(a)) return n.report("bus.untrusted_origin", a === null ? "The origin of the parent frame is unknown. This context sends its own records." : `The parent frame is on ${a}. This origin is not in bus.trustedOrigins. This context sends its own records.`, {
90
+ origin: a ?? "",
91
+ type: "parent"
92
+ }), null;
93
+ let o = /* @__PURE__ */ new Set(), s = (t) => {
94
+ let r = v(t.data);
95
+ r && t.source === window.parent && (i.has(t.origin) ? e(r, {
96
+ link: "parent",
97
+ origin: t.origin,
98
+ peer: t.source
99
+ }) : o.has(t.origin) || (o.add(t.origin), n.report("bus.untrusted_origin", x(t.origin, "a message"), {
100
+ origin: t.origin,
101
+ type: r.t.slice(0, 48)
102
+ })));
103
+ };
104
+ return addEventListener("message", s), {
105
+ kind: "parent",
106
+ post(e) {
107
+ n.guard("bus.send_failed", "The postMessage call to the parent failed.", () => {
108
+ window.parent.postMessage(_(e), a);
109
+ });
110
+ },
111
+ close() {
112
+ removeEventListener("message", s);
113
+ }
114
+ };
115
+ }
116
+ function T(e, t, n, r, i) {
117
+ if (typeof window > "u") return null;
118
+ let a = /* @__PURE__ */ new Set([location.origin, ...t]);
119
+ a.delete(b);
120
+ let o = /* @__PURE__ */ new Map(), s = (e, t, a) => {
121
+ if (r && !r(e, t)) {
122
+ o.delete(e);
123
+ return;
124
+ }
125
+ if (i && !i(a, e)) return;
126
+ let s = e;
127
+ s.closed ? o.delete(e) : n.guard("bus.send_failed", "The postMessage call to a child frame failed.", () => {
128
+ s.postMessage(_(a), t);
129
+ });
130
+ }, c = (t) => {
131
+ let i = v(t.data);
132
+ if (!i || window.parent !== window && t.source === window.parent) return;
133
+ if (!r && !a.has(t.origin)) {
134
+ n.report("bus.untrusted_origin", x(t.origin, "a message"), {
135
+ origin: t.origin,
136
+ type: i.t.slice(0, 48)
137
+ });
138
+ return;
139
+ }
140
+ if (r && !r(t.source, t.origin)) return;
141
+ let { source: c, origin: l } = t;
142
+ c && o.set(c, l), e(i, {
143
+ link: "children",
144
+ origin: l,
145
+ peer: c ?? void 0,
146
+ reply: c ? (e) => {
147
+ s(c, l, e);
148
+ } : void 0
149
+ });
150
+ };
151
+ return addEventListener("message", c), {
152
+ kind: "children",
153
+ post(e) {
154
+ for (let [t, n] of o) s(t, n, e);
155
+ },
156
+ close() {
157
+ removeEventListener("message", c), o.clear();
158
+ }
159
+ };
160
+ }
161
+ function E(e, t, n) {
162
+ let r = globalThis.BroadcastChannel;
163
+ if (r === void 0) return null;
164
+ let i = n.guard("bus.send_failed", "The library could not open the BroadcastChannel.", () => new r(e));
165
+ return i ? (i.onmessage = (e) => {
166
+ let n = v(e.data);
167
+ n && t(n, {
168
+ link: "broadcast",
169
+ origin: "same-origin"
170
+ });
171
+ }, {
172
+ kind: "broadcast",
173
+ post(e) {
174
+ n.guard("bus.send_failed", "The BroadcastChannel.postMessage call failed.", () => {
175
+ i.postMessage(_(e));
176
+ });
177
+ },
178
+ close() {
179
+ n.guard("bus.send_failed", "The library could not close the BroadcastChannel.", () => {
180
+ i.close();
181
+ });
182
+ }
183
+ }) : null;
184
+ }
185
+ function D(e, t, n, r) {
186
+ let i = u()?.InterApplicationBus;
187
+ if (!i) return null;
188
+ if (!t) return r.report("openfin.unavailable", "OpenFin gives no application uuid. The InterApplicationBus link stays closed."), null;
189
+ let a = `${e}.${t}`;
190
+ return r.guardAsync("bus.send_failed", "The InterApplicationBus.subscribe call failed.", () => i.subscribe({ uuid: t }, a, (e, t, r) => {
191
+ let i = v(e);
192
+ i && n(i, {
193
+ link: "openfin",
194
+ origin: "openfin",
195
+ peer: t && r ? `${t}:${r}` : void 0
196
+ });
197
+ })), {
198
+ kind: "openfin",
199
+ post(e) {
200
+ r.guardAsync("bus.send_failed", "The InterApplicationBus.publish call failed.", () => i.publish(a, _(e)));
201
+ },
202
+ close() {}
203
+ };
204
+ }
205
+ function O(e, t) {
206
+ let n = globalThis, r = n.postMessage;
207
+ return n.WorkerGlobalScope === void 0 || !r ? null : (n.addEventListener?.("message", (t) => {
208
+ let n = v(t.data);
209
+ n && e(n, {
210
+ link: "owner",
211
+ origin: "same-origin"
212
+ });
213
+ }), {
214
+ kind: "owner",
215
+ post(e) {
216
+ t.guard("bus.send_failed", "The postMessage call of the worker failed.", () => {
217
+ r(_(e));
218
+ });
219
+ },
220
+ close() {}
221
+ });
222
+ }
223
+ function k(e, t, n) {
224
+ let r = (n) => {
225
+ let r = v(n.data);
226
+ r && t(r, {
227
+ link: "worker",
228
+ origin: "same-origin",
229
+ peer: e
230
+ });
231
+ };
232
+ return e.addEventListener("message", r), e.start?.(), {
233
+ kind: "worker",
234
+ post(t) {
235
+ n.guard("bus.send_failed", "The postMessage call to a worker failed.", () => {
236
+ e.postMessage(_(t));
237
+ });
238
+ },
239
+ close() {
240
+ e.removeEventListener("message", r);
241
+ }
242
+ };
243
+ }
244
+ //#endregion
245
+ //#region src/bus/bus.ts
246
+ var A = {
247
+ timeoutMs: i,
248
+ maxAttempts: 3
249
+ }, j = [
250
+ "children",
251
+ "direct",
252
+ "worker"
253
+ ], M = class {
254
+ config;
255
+ diagnostics;
256
+ platform;
257
+ contextId;
258
+ tabId;
259
+ handlers;
260
+ handshakeOptions;
261
+ sources = /* @__PURE__ */ new Map();
262
+ rates = /* @__PURE__ */ new WeakMap();
263
+ channelRates = /* @__PURE__ */ new Map();
264
+ mayPost(e, n) {
265
+ let r = this.sources.get(n)?.permissions;
266
+ return r ? e.t === t.journey ? r.includes("journey:read") : e.t === t.journeyRequest ? r.includes("journey:write") : e.t !== t.sampling || r.includes("sampling:read") : this.config.bus.sourcePolicy === "trusted-origin";
267
+ }
268
+ registerFrame(e, t) {
269
+ let n = typeof HTMLIFrameElement > "u" ? void 0 : HTMLIFrameElement, r = n && e instanceof n ? e.contentWindow : e;
270
+ if (!r || new URL(t.origin).origin !== t.origin || t.origin === "null") throw Error("A frame registration requires a window and an exact origin.");
271
+ let i = {
272
+ ...t,
273
+ permissions: [...t.permissions ?? ["records"]]
274
+ };
275
+ return this.sources.set(r, i), this.ensureChildrenLink(), () => {
276
+ this.sources.get(r) === i && this.sources.delete(r);
277
+ };
278
+ }
279
+ isRegistered(e, t) {
280
+ if (!e) return !1;
281
+ let n = this.sources.get(e);
282
+ return n ? n.origin === t : this.config.bus.sourcePolicy !== "registered" && t !== "null" && (t === location.origin || this.config.bus.trustedOrigins.includes(t));
283
+ }
284
+ rotateContext() {
285
+ this.passContext(this.role === "sender");
286
+ }
287
+ passContext(e) {
288
+ let n = {
289
+ t: t.securityContext,
290
+ from: this.contextId,
291
+ id: this.config.securityContext.id
292
+ };
293
+ this.postOver("children", n), this.postOver("worker", n), e && this.postOver("openfin", n);
294
+ }
295
+ role = "sender";
296
+ upstream = null;
297
+ links = [];
298
+ openFinLink = null;
299
+ isOpenFinProvider = !1;
300
+ rulesPoll;
301
+ destroyed = !1;
302
+ ownerId = null;
303
+ ownerPeer;
304
+ awaitingWelcome = null;
305
+ constructor(e, t, n, r, i, a, o = A) {
306
+ this.config = e, this.diagnostics = t, this.platform = n, this.contextId = r, this.tabId = i, this.handlers = a, this.handshakeOptions = o;
307
+ }
308
+ getRole() {
309
+ return this.role;
310
+ }
311
+ async start() {
312
+ let { bus: e } = this.config;
313
+ if (e.mode === "off") return this.role = "sender", this.role;
314
+ if (this.isOpenFinProvider = this.resolveOpenFinProvider(), e.mode === "sender" || e.mode === "forwarder") return this.role = e.mode, this.openControlLinks(), this.role === "forwarder" && (this.upstream = this.candidateUpstream(), this.upstream || this.diagnostics.report("bus.no_owner", "bus.mode is \"forwarder\". No owner exists. The library drops the records of this context.")), this.announce(), this.role;
315
+ this.openControlLinks();
316
+ let t = C(this.receive, this.diagnostics);
317
+ if (t) return this.role = "forwarder", this.upstream = t, await this.handshake(t), this.diagnostics.report("bus.role_resolved", "This context attached directly to the runtime of its same-origin parent.", {
318
+ role: "forwarder",
319
+ via: "direct"
320
+ }), this.announce(), this.role;
321
+ let n = this.candidateUpstream();
322
+ if (!n) return this.role = "sender", this.diagnostics.report("bus.role_resolved", "No owner exists. This context sends its own records.", { role: "sender" }), this.announce(), this.role;
323
+ let r = this.orphanPolicy() === "retry" ? this.handshakeOptions.maxAttempts : 1, i = !1;
324
+ for (let e = 0; e < r && !i; e++) i = await this.handshake(n);
325
+ return this.role = i ? "forwarder" : "sender", this.upstream = i ? n : null, i || (n !== this.openFinLink && n.close(), this.diagnostics.report("bus.handshake_timeout", `No owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`, {
326
+ via: n.kind,
327
+ crossOrigin: this.isCrossOriginFrame()
328
+ })), this.diagnostics.report("bus.role_resolved", `The bus role is ${this.role}.`, {
329
+ role: this.role,
330
+ via: i ? n.kind : "none"
331
+ }), this.announce(), this.role;
332
+ }
333
+ sendRecords(e) {
334
+ let { maxRecordsPerMessage: n, maxMessageBytes: r } = this.config.bus, i = new TextEncoder(), a = (e) => r ? i.encode(JSON.stringify(e)).length : 0, o = (e) => ({
335
+ t: t.records,
336
+ from: this.contextId,
337
+ records: e,
338
+ routingContextId: this.config.securityContext.id || void 0
339
+ }), s = a(o([])), c = [], l = s;
340
+ for (let t of e) {
341
+ let e = a(t);
342
+ if (r && s + e > r) {
343
+ this.diagnostics.count("bus.rejected_message");
344
+ continue;
345
+ }
346
+ let i = +(c.length > 0);
347
+ (n && c.length >= n || r && l + i + e > r) && (this.upstream?.post(o(c)), c = [], l = s), l += +(c.length > 0) + e, c.push(t);
348
+ }
349
+ c.length > 0 && this.upstream?.post(o(c));
350
+ }
351
+ acceptDirect(e, n, r) {
352
+ let i = {
353
+ link: "direct",
354
+ origin: "same-origin",
355
+ peer: r
356
+ }, a = {
357
+ ...i,
358
+ reply: (e) => {
359
+ n(e, i);
360
+ }
361
+ };
362
+ this.acceptsMessage(e, a, !0) && e.from !== this.contextId && (e.t === t.samplingRequest ? n(this.rulesAnswer(e.from), i) : (e.t === t.records && !this.awaitingWelcome && e.routingContextId !== this.config.securityContext.id && n({
363
+ t: t.securityContext,
364
+ from: this.contextId,
365
+ id: this.config.securityContext.id
366
+ }, i), this.routeMessage(e, a)));
367
+ }
368
+ attachWorker(e, t = {}) {
369
+ let n = {
370
+ ...t,
371
+ permissions: [...t.permissions ?? ["records"]]
372
+ };
373
+ this.sources.set(e, n);
374
+ let r = k(e, this.receive, this.diagnostics), i = {
375
+ ...r,
376
+ post: (t) => {
377
+ this.mayPost(t, e) && r.post(t);
378
+ }
379
+ };
380
+ return this.links.push(i), () => {
381
+ i.close();
382
+ let t = this.links.indexOf(i);
383
+ t >= 0 && this.links.splice(t, 1), this.sources.get(e) === n && this.sources.delete(e);
384
+ };
385
+ }
386
+ broadcastJourney(e) {
387
+ this.postJourney({
388
+ t: t.journey,
389
+ from: this.contextId,
390
+ journey: e
391
+ });
392
+ }
393
+ destroy() {
394
+ this.sources.clear(), this.destroyed = !0, clearInterval(this.rulesPoll), this.rulesPoll = void 0;
395
+ for (let e of this.allLinks()) e.close();
396
+ this.links.length = 0, this.upstream = null, this.ownerId = null, this.openFinLink = null;
397
+ }
398
+ allLinks() {
399
+ return !this.upstream || this.links.includes(this.upstream) ? this.links : [...this.links, this.upstream];
400
+ }
401
+ postOver(e, t) {
402
+ for (let n of this.allLinks()) n.kind === e && n.post(t);
403
+ }
404
+ postJourney(e) {
405
+ for (let t of this.allLinks()) this.journeyLink(t.kind) && t.post(e);
406
+ }
407
+ receive = (e, t) => {
408
+ let n = t.link === "children" || t.link === "worker";
409
+ this.acceptsMessage(e, t, n) && this.routeMessage(e, t);
410
+ };
411
+ acceptsMessage(e, t, n) {
412
+ if (this.destroyed) return !1;
413
+ let r;
414
+ try {
415
+ r = this.passesChecks(e, t, n);
416
+ } catch {
417
+ r = !1;
418
+ }
419
+ return r || this.diagnostics.count("bus.rejected_message"), r;
420
+ }
421
+ passesChecks(e, n, r) {
422
+ let { bus: i } = this.config, a = typeof n.peer == "object" ? this.sources.get(n.peer) : void 0;
423
+ if (r && i.sourcePolicy === "registered" && !a) return !1;
424
+ let o = typeof n.peer == "object" ? n.peer : void 0, s = typeof n.peer == "string" ? n.peer : n.link, c = Date.now(), l = (o ? this.rates.get(o) : this.channelRates.get(s)) ?? {
425
+ start: c,
426
+ count: 0
427
+ };
428
+ if (o) this.rates.set(o, l);
429
+ else {
430
+ for (let [e, t] of this.channelRates) f(t, 1e3, c) && this.channelRates.delete(e);
431
+ if (i.maxTrackedSources && this.channelRates.size >= i.maxTrackedSources && !this.channelRates.has(s)) return !1;
432
+ this.channelRates.set(s, l);
433
+ }
434
+ if (!p(l, i.maxMessagesPerSecond || Infinity, 1e3)) return !1;
435
+ let u = JSON.stringify(e, (e, t) => {
436
+ if (i.validation === "strict" && typeof t == "number" && !Number.isFinite(t)) throw Error("Non-finite value");
437
+ return t;
438
+ });
439
+ if (i.maxMessageBytes && new TextEncoder().encode(u).length > i.maxMessageBytes || i.validation === "strict" && !g(e) || e.t === t.records && i.maxRecordsPerMessage && e.records.length > i.maxRecordsPerMessage) return !1;
440
+ if (a) {
441
+ let n = e.t === t.records ? "records" : e.t === t.journey ? "journey:write" : e.t === t.journeyRequest ? "journey:read" : e.t === t.samplingRequest ? "sampling:read" : void 0;
442
+ if (n && !a.permissions?.includes(n)) return !1;
443
+ }
444
+ return r && (e.t === t.sampling || e.t === t.securityContext) ? !1 : i.sourcePolicy !== "registered" || n.link !== "broadcast" || e.t !== t.records;
445
+ }
446
+ routeMessage(e, n) {
447
+ if (e.from !== this.contextId) switch (e.t) {
448
+ case t.hello:
449
+ this.canOwn(n.link) && this.answer(n, {
450
+ t: t.welcome,
451
+ from: this.contextId,
452
+ to: e.from,
453
+ tabId: this.tabId,
454
+ routingContextId: this.awaitingWelcome ? void 0 : this.config.securityContext.id || void 0
455
+ });
456
+ break;
457
+ case t.welcome:
458
+ if (e.to !== this.contextId) break;
459
+ if (this.awaitingWelcome?.link === n.link || this.upstream?.kind === n.link && this.ownerId === null) {
460
+ this.ownerId = e.from, this.ownerPeer = n.peer;
461
+ let t = this.config.securityContext.id;
462
+ if (e.routingContextId && this.handlers.onSecurityContext?.(e.routingContextId) === !1) break;
463
+ this.config.securityContext.id !== t && this.passContext(!1), this.awaitingWelcome?.settle(!0);
464
+ }
465
+ break;
466
+ case t.records:
467
+ if (this.config.securityContext.isolation && this.config.securityContext.id && e.routingContextId !== this.config.securityContext.id) {
468
+ this.diagnostics.count("security.context_mismatch");
469
+ break;
470
+ }
471
+ this.role === "sender" ? this.handlers.onRecords(e.records) : this.upstream && this.canRelay(n.link) && this.upstream.post(e);
472
+ break;
473
+ case t.securityContext:
474
+ n.link === this.upstream?.kind && this.ownerId === e.from && this.ownerPeer === n.peer && this.handlers.onSecurityContext?.(e.id) !== !1 && this.rotateContext();
475
+ break;
476
+ case t.journey:
477
+ this.acceptsJourney(e, n) && this.applyJourney(e.journey);
478
+ break;
479
+ case t.journeyRequest: {
480
+ let r = this.handlers.onJourneyRequest();
481
+ r && this.journeyLink(n.link) && this.answer(n, {
482
+ t: t.journey,
483
+ from: this.contextId,
484
+ to: e.from,
485
+ journey: r
486
+ });
487
+ break;
488
+ }
489
+ case t.samplingRequest:
490
+ (this.role === "forwarder" ? n.link !== this.upstream?.kind : this.canOwn(n.link)) && this.answer(n, this.rulesAnswer(e.from));
491
+ break;
492
+ case t.sampling:
493
+ this.acceptsRules(e.to, n) && this.applyRules(e.rules);
494
+ break;
495
+ case t.tab: n.link === "broadcast" && e.tabId === this.tabId && this.contextId > e.from && this.handlers.onTabConflict();
496
+ }
497
+ }
498
+ answer(e, t) {
499
+ e.reply ? e.reply(t) : this.postOver(e.link, t);
500
+ }
501
+ canRelay(e) {
502
+ return e === "direct" || e !== this.upstream?.kind;
503
+ }
504
+ canOwn(e) {
505
+ return this.role !== "sender" && this.ownerId === null ? !1 : e === "openfin" ? this.role === "sender" && this.isOpenFinProvider : j.includes(e);
506
+ }
507
+ resolveOpenFinProvider() {
508
+ let e = this.config.bus.openFinRole;
509
+ if (e !== "auto") return e === "provider";
510
+ if (this.platform.platform !== "openfin" && this.platform.platform !== "openfin_web") return !1;
511
+ let t = u()?.me;
512
+ return !t?.identity || t.isView ? !1 : !!(t.identity.name && t.identity.name === t.identity.uuid);
513
+ }
514
+ orphanPolicy() {
515
+ return this.isCrossOriginFrame() ? "retry" : "promote";
516
+ }
517
+ isCrossOriginFrame() {
518
+ if (typeof window > "u" || window.parent === window) return !1;
519
+ try {
520
+ return Reflect.get(window.parent, "location"), !1;
521
+ } catch {
522
+ return !0;
523
+ }
524
+ }
525
+ candidateUpstream() {
526
+ return this.platform.isWorker ? O(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : w(this.receive, this.config.bus.trustedOrigins, this.diagnostics);
527
+ }
528
+ openControlLinks() {
529
+ let e = (e) => {
530
+ e && this.links.push(e);
531
+ };
532
+ this.platform.isWorker || this.ensureChildrenLink(), this.platform.isTopLevelDocument && e(E(o, this.receive, this.diagnostics)), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && e(this.ensureOpenFinLink());
533
+ }
534
+ ensureChildrenLink() {
535
+ if (this.links.some((e) => e.kind === "children")) return;
536
+ let e = T(this.receive, this.config.bus.trustedOrigins, this.diagnostics, (e, t) => {
537
+ let n = this.isRegistered(e, t);
538
+ if (!n) {
539
+ this.diagnostics.count("bus.rejected_message");
540
+ let n = e !== null && this.sources.has(e), r = t === location.origin || this.config.bus.trustedOrigins.includes(t);
541
+ (n || !r) && this.diagnostics.report("bus.untrusted_origin", "The bus rejected a message from an untrusted origin.");
542
+ }
543
+ return n;
544
+ }, (e, t) => this.mayPost(e, t));
545
+ e && this.links.push(e);
546
+ }
547
+ ensureOpenFinLink() {
548
+ return this.openFinLink ??= D(o, this.platform.openfinUuid, this.receive, this.diagnostics), this.openFinLink;
549
+ }
550
+ handshake(e) {
551
+ return new Promise((n) => {
552
+ let r = !1, i = (e) => {
553
+ r || (r = !0, this.awaitingWelcome = null, clearTimeout(a), n(e));
554
+ };
555
+ this.awaitingWelcome = {
556
+ link: e.kind,
557
+ settle: i
558
+ };
559
+ let a = setTimeout(() => {
560
+ i(!1);
561
+ }, this.handshakeOptions.timeoutMs);
562
+ l(a), e.post({
563
+ t: t.hello,
564
+ from: this.contextId,
565
+ tabId: this.tabId
566
+ });
567
+ });
568
+ }
569
+ announce() {
570
+ this.postOver("broadcast", {
571
+ t: t.tab,
572
+ from: this.contextId,
573
+ tabId: this.tabId
574
+ }), this.upstream && this.ownerId === null && this.upstream.post({
575
+ t: t.hello,
576
+ from: this.contextId,
577
+ tabId: this.tabId
578
+ }), this.postJourney({
579
+ t: t.journeyRequest,
580
+ from: this.contextId
581
+ }), this.pollRules(), this.passContext(!1);
582
+ }
583
+ journeyScope() {
584
+ let { scope: e } = this.config.journey;
585
+ if (e !== "auto") return e;
586
+ let { platform: t } = this.platform;
587
+ return t === "openfin" || t === "openfin_web" ? "origin" : "tab";
588
+ }
589
+ journeyLink(e) {
590
+ let t = this.journeyScope();
591
+ return t === "context" ? !1 : t === "origin" || e !== "broadcast";
592
+ }
593
+ acceptsJourney(e, t) {
594
+ return !this.journeyLink(t.link) || e.to !== void 0 && e.to !== this.contextId ? !1 : this.journeyScope() === "origin" || this.fromOwner(e.from, t.link) && (this.ownerPeer === void 0 || this.ownerPeer === t.peer);
595
+ }
596
+ fromOwner(e, t) {
597
+ return this.role !== "forwarder" || t !== this.upstream?.kind ? !1 : this.ownerId === null || e === this.ownerId;
598
+ }
599
+ applyJourney(e) {
600
+ if (e === null) {
601
+ this.handlers.onJourney(null);
602
+ return;
603
+ }
604
+ let t = d(e);
605
+ t === null ? this.diagnostics.report("record.dropped_malformed", "The bus dropped a journey message. Its payload is not a journey.", { type: "journey" }) : this.handlers.onJourney(t);
606
+ }
607
+ rulesAnswer(e) {
608
+ let n = this.handlers.remote.sampling?.wire() ?? null;
609
+ return {
610
+ t: t.sampling,
611
+ from: this.contextId,
612
+ to: e,
613
+ rules: n
614
+ };
615
+ }
616
+ acceptsRules(e, t) {
617
+ if (this.role !== "forwarder" || e !== this.contextId || t.link !== this.upstream?.kind) return !1;
618
+ let { origin: n } = t;
619
+ return t.link === "parent" && n !== location.origin && !this.config.bus.trustedOrigins.includes(n) ? (this.diagnostics.report("bus.untrusted_origin", `The bus ignored sampling rules from ${n}. If you own this origin, add it to bus.trustedOrigins.`, {
620
+ origin: n,
621
+ type: "sampling"
622
+ }), !1) : this.ownerPeer === void 0 || this.ownerPeer === t.peer;
623
+ }
624
+ applyRules(e) {
625
+ if (e === null) {
626
+ h(this.handlers.remote, this.config, null);
627
+ return;
628
+ }
629
+ let t = m(e, this.diagnostics);
630
+ t && h(this.handlers.remote, this.config, t);
631
+ }
632
+ pollRules() {
633
+ let { upstream: e } = this;
634
+ if (this.destroyed || this.role !== "forwarder" || !e) return;
635
+ let n = () => {
636
+ this.config.sampling.remote && e.post({
637
+ t: t.samplingRequest,
638
+ from: this.contextId
639
+ });
640
+ };
641
+ n(), this.rulesPoll = setInterval(n, r), l(this.rulesPoll);
642
+ }
643
+ };
644
+ //#endregion
645
+ export { M as Bus };
646
+
647
+ //# sourceMappingURL=bus-DeOPHWaD.js.map