@utk09/ui-observability 0.9.2 → 0.9.3

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 (142) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/batch-D5qvsMQ_.cjs +2 -0
  3. package/dist/batch-D5qvsMQ_.cjs.map +1 -0
  4. package/dist/{batch-4xKzzSCj.js → batch-DDgxg16_.js} +7 -4
  5. package/dist/batch-DDgxg16_.js.map +1 -0
  6. package/dist/bus/bus.d.ts +0 -4
  7. package/dist/{bus-DrixwdiX.js → bus-C6RwKzPW.js} +59 -62
  8. package/dist/bus-C6RwKzPW.js.map +1 -0
  9. package/dist/bus-WPVDFw2y.cjs +2 -0
  10. package/dist/bus-WPVDFw2y.cjs.map +1 -0
  11. package/dist/capture/storm.d.ts +2 -7
  12. package/dist/{console-ChfuJlf9.cjs → console-BSusX_M-.cjs} +2 -2
  13. package/dist/{console-ChfuJlf9.cjs.map → console-BSusX_M-.cjs.map} +1 -1
  14. package/dist/{console-B3vGRW5p.js → console-Dv5GfaNn.js} +3 -3
  15. package/dist/{console-B3vGRW5p.js.map → console-Dv5GfaNn.js.map} +1 -1
  16. package/dist/{constants-Be83LICb.cjs → constants-Cb92egPS.cjs} +2 -2
  17. package/dist/constants-Cb92egPS.cjs.map +1 -0
  18. package/dist/{constants-CQ_D7jIW.js → constants-DhH6VI5a.js} +2 -2
  19. package/dist/constants-DhH6VI5a.js.map +1 -0
  20. package/dist/constants.d.ts +2 -3
  21. package/dist/core/breadcrumbs.d.ts +1 -3
  22. package/dist/core/context.d.ts +0 -8
  23. package/dist/core/diagnostics.d.ts +0 -2
  24. package/dist/core/sampling.d.ts +1 -3
  25. package/dist/deadline-CUrH0Hd8.cjs +2 -0
  26. package/dist/deadline-CUrH0Hd8.cjs.map +1 -0
  27. package/dist/deadline-DeqXEliN.js +31 -0
  28. package/dist/deadline-DeqXEliN.js.map +1 -0
  29. package/dist/{errors-BGs5NOrw.js → errors-DCZWcHkd.js} +4 -4
  30. package/dist/{errors-BGs5NOrw.js.map → errors-DCZWcHkd.js.map} +1 -1
  31. package/dist/{errors-BMJm7KZZ.cjs → errors-ERu-su8m.cjs} +3 -3
  32. package/dist/{errors-BMJm7KZZ.cjs.map → errors-ERu-su8m.cjs.map} +1 -1
  33. package/dist/fixed-window-BR0bu32Y.cjs +2 -0
  34. package/dist/fixed-window-BR0bu32Y.cjs.map +1 -0
  35. package/dist/fixed-window-Re7jIRJH.js +9 -0
  36. package/dist/fixed-window-Re7jIRJH.js.map +1 -0
  37. package/dist/{identity-DXyV86o-.cjs → identity-C1WLItSl.cjs} +2 -2
  38. package/dist/{identity-DXyV86o-.cjs.map → identity-C1WLItSl.cjs.map} +1 -1
  39. package/dist/{identity-rpEyjvVg.js → identity-Di-QXGCC.js} +2 -2
  40. package/dist/{identity-rpEyjvVg.js.map → identity-Di-QXGCC.js.map} +1 -1
  41. package/dist/index.cjs +1 -1
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.js +224 -236
  44. package/dist/index.js.map +1 -1
  45. package/dist/indexeddb-storage-DX18p39D.cjs +2 -0
  46. package/dist/indexeddb-storage-DX18p39D.cjs.map +1 -0
  47. package/dist/{indexeddb-storage-Q9fDYlyn.js → indexeddb-storage-T9YIYVYC.js} +39 -50
  48. package/dist/indexeddb-storage-T9YIYVYC.js.map +1 -0
  49. package/dist/{interactions-B8zjCjga.js → interactions-BLH_tX87.js} +2 -2
  50. package/dist/{interactions-B8zjCjga.js.map → interactions-BLH_tX87.js.map} +1 -1
  51. package/dist/{interactions-BAGRmtrv.cjs → interactions-_hfOerfC.cjs} +2 -2
  52. package/dist/{interactions-BAGRmtrv.cjs.map → interactions-_hfOerfC.cjs.map} +1 -1
  53. package/dist/journey-BRUj0hqD.cjs +2 -0
  54. package/dist/journey-BRUj0hqD.cjs.map +1 -0
  55. package/dist/{journey-_dQQ1eMP.js → journey-yALMEWF7.js} +26 -25
  56. package/dist/journey-yALMEWF7.js.map +1 -0
  57. package/dist/{library-request-BIG3Xpx3.cjs → library-request-BcAxuwsf.cjs} +2 -2
  58. package/dist/{library-request-BIG3Xpx3.cjs.map → library-request-BcAxuwsf.cjs.map} +1 -1
  59. package/dist/{library-request-DX6ev9oG.js → library-request-CQD4HUiP.js} +2 -2
  60. package/dist/{library-request-DX6ev9oG.js.map → library-request-CQD4HUiP.js.map} +1 -1
  61. package/dist/{long-frames-Cq2LgNnp.cjs → long-frames-D4Bm3Zkz.cjs} +2 -2
  62. package/dist/{long-frames-Cq2LgNnp.cjs.map → long-frames-D4Bm3Zkz.cjs.map} +1 -1
  63. package/dist/{long-frames-B0tKuChx.js → long-frames-DD_Um9_4.js} +3 -3
  64. package/dist/{long-frames-B0tKuChx.js.map → long-frames-DD_Um9_4.js.map} +1 -1
  65. package/dist/models/batch.d.ts +6 -0
  66. package/dist/{network-CMnEvGJB.js → network--GoE7_Or.js} +3 -3
  67. package/dist/{network-CMnEvGJB.js.map → network--GoE7_Or.js.map} +1 -1
  68. package/dist/{network-C6kJbW6K.cjs → network-DcuS2H1P.cjs} +2 -2
  69. package/dist/{network-C6kJbW6K.cjs.map → network-DcuS2H1P.cjs.map} +1 -1
  70. package/dist/openfin-BwEN0uj4.js +8 -0
  71. package/dist/openfin-BwEN0uj4.js.map +1 -0
  72. package/dist/openfin-DtH2f7zX.cjs +2 -0
  73. package/dist/openfin-DtH2f7zX.cjs.map +1 -0
  74. package/dist/{platform-j0uMPwHi.js → platform-GaM6h7XM.js} +25 -21
  75. package/dist/platform-GaM6h7XM.js.map +1 -0
  76. package/dist/platform-kIL5AZB7.cjs +2 -0
  77. package/dist/platform-kIL5AZB7.cjs.map +1 -0
  78. package/dist/{remote-rules-UggoZqfP.js → remote-rules-6ePq8CrI.js} +19 -21
  79. package/dist/remote-rules-6ePq8CrI.js.map +1 -0
  80. package/dist/remote-rules-CI3gbRCL.cjs +2 -0
  81. package/dist/remote-rules-CI3gbRCL.cjs.map +1 -0
  82. package/dist/sampling-C-M8p3FK.cjs +2 -0
  83. package/dist/sampling-C-M8p3FK.cjs.map +1 -0
  84. package/dist/sampling-Ud_WiuU9.js +65 -0
  85. package/dist/sampling-Ud_WiuU9.js.map +1 -0
  86. package/dist/{sanitize-BqzPc4Jg.cjs → sanitize--_e4oOPX.cjs} +2 -2
  87. package/dist/{sanitize-BqzPc4Jg.cjs.map → sanitize--_e4oOPX.cjs.map} +1 -1
  88. package/dist/{sanitize-BNwgPj_B.js → sanitize-DP0xDPrt.js} +2 -2
  89. package/dist/{sanitize-BNwgPj_B.js.map → sanitize-DP0xDPrt.js.map} +1 -1
  90. package/dist/sender-BESHz6my.cjs +3 -0
  91. package/dist/sender-BESHz6my.cjs.map +1 -0
  92. package/dist/{sender--0_VzPbN.js → sender-BUBWLn5i.js} +202 -207
  93. package/dist/sender-BUBWLn5i.js.map +1 -0
  94. package/dist/storage/gap.d.ts +20 -0
  95. package/dist/storage/indexeddb-storage.d.ts +1 -7
  96. package/dist/storage/keys.d.ts +9 -0
  97. package/dist/storage/local-storage.d.ts +0 -6
  98. package/dist/storage/memory-storage.d.ts +1 -1
  99. package/dist/storm-DhHGHhOc.cjs +2 -0
  100. package/dist/storm-DhHGHhOc.cjs.map +1 -0
  101. package/dist/storm-OD5J6Ylm.js +10 -0
  102. package/dist/storm-OD5J6Ylm.js.map +1 -0
  103. package/dist/utils/fixed-window.d.ts +15 -0
  104. package/dist/utils/guards.d.ts +6 -0
  105. package/dist/utils/openfin.d.ts +48 -0
  106. package/dist/utils/platform.d.ts +5 -0
  107. package/package.json +2 -3
  108. package/dist/batch-4xKzzSCj.js.map +0 -1
  109. package/dist/batch-cys7e53Q.cjs +0 -2
  110. package/dist/batch-cys7e53Q.cjs.map +0 -1
  111. package/dist/bus-B6vzPmQM.cjs +0 -2
  112. package/dist/bus-B6vzPmQM.cjs.map +0 -1
  113. package/dist/bus-DrixwdiX.js.map +0 -1
  114. package/dist/constants-Be83LICb.cjs.map +0 -1
  115. package/dist/constants-CQ_D7jIW.js.map +0 -1
  116. package/dist/deadline-5_PecIl5.js +0 -26
  117. package/dist/deadline-5_PecIl5.js.map +0 -1
  118. package/dist/deadline-XSnm95pg.cjs +0 -2
  119. package/dist/deadline-XSnm95pg.cjs.map +0 -1
  120. package/dist/indexeddb-storage-BXaPVPyG.cjs +0 -2
  121. package/dist/indexeddb-storage-BXaPVPyG.cjs.map +0 -1
  122. package/dist/indexeddb-storage-Q9fDYlyn.js.map +0 -1
  123. package/dist/journey-BGSyy8Es.cjs +0 -2
  124. package/dist/journey-BGSyy8Es.cjs.map +0 -1
  125. package/dist/journey-_dQQ1eMP.js.map +0 -1
  126. package/dist/platform-DNOJjpOm.cjs +0 -2
  127. package/dist/platform-DNOJjpOm.cjs.map +0 -1
  128. package/dist/platform-j0uMPwHi.js.map +0 -1
  129. package/dist/remote-rules-DgoBJxZL.cjs +0 -2
  130. package/dist/remote-rules-DgoBJxZL.cjs.map +0 -1
  131. package/dist/remote-rules-UggoZqfP.js.map +0 -1
  132. package/dist/sampling-BLMD8EGM.js +0 -64
  133. package/dist/sampling-BLMD8EGM.js.map +0 -1
  134. package/dist/sampling-MthcVXXU.cjs +0 -2
  135. package/dist/sampling-MthcVXXU.cjs.map +0 -1
  136. package/dist/sender--0_VzPbN.js.map +0 -1
  137. package/dist/sender-SPGMqZjD.cjs +0 -3
  138. package/dist/sender-SPGMqZjD.cjs.map +0 -1
  139. package/dist/storm-CTy1dfvs.cjs +0 -2
  140. package/dist/storm-CTy1dfvs.cjs.map +0 -1
  141. package/dist/storm-knaj4GUH.js +0 -10
  142. package/dist/storm-knaj4GUH.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
 
5
+ ## [0.9.3] - 2026-10-31
6
+
7
+ ### Fixed - v0.9.3
8
+
9
+ - The limit on ERROR and FATAL records starts a new window when the clock moves back. Before, the library dropped each ERROR and FATAL record above the limit until the clock passed the old window start.
10
+
5
11
  ## [0.9.2] - 2026-10-30
6
12
 
7
13
  ### Added - v0.9.2
@@ -0,0 +1,2 @@
1
+ const e=require("./constants-Cb92egPS.cjs"),t=require("./identity-C1WLItSl.cjs");function n(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`createdAt`),r=Reflect.get(e,`attempts`),i=Reflect.get(e,`records`);return typeof t==`string`&&typeof n==`number`&&typeof r==`number`&&Array.isArray(i)}function r(e,n){if(e.records.length<2)return null;let r=Math.floor(e.records.length/2),i=r=>({id:t.i(n),records:r,createdAt:e.createdAt,attempts:e.attempts});return[i(e.records.slice(0,r)),i(e.records.slice(r))]}function i(e,t){let n=e;if(typeof n!=`object`||!n)return;let r=Reflect.get(n,`attributes`);if(typeof r==`object`&&r)return Reflect.get(r,t)}function a(t){return i(t,e.d)===e.mt}function o(e){return e.reduce((e,t)=>e+t.records.length,0)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
2
+ //# sourceMappingURL=batch-D5qvsMQ_.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-D5qvsMQ_.cjs","names":["newId","ATTR_LOG_TYPE","LOG_TYPE_ACTION","require_constants","require_identity","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":"iFAiCA,SAAgBK,EAAW,EAAmC,CAC5D,GAAI,OAAOC,GAAU,WAAYA,EAC/B,MAAO,GAGT,IAAMC,EAAc,QAAQ,IAAID,EAAO,IAAI,EACrCE,EAAqB,QAAQ,IAAIF,EAAO,WAAW,EACnDG,EAAoB,QAAQ,IAAIH,EAAO,UAAU,EACjDI,EAAmB,QAAQ,IAAIJ,EAAO,SAAS,EAErD,OACE,OAAOC,GAAO,UACd,OAAOC,GAAc,UACrB,OAAOC,GAAa,UACpB,MAAM,QAAQC,CAAO,CAEzB,CASA,SAAgBC,EAAW,EAAiB,EAAuD,CACjG,GAAIC,EAAM,QAAQ,OAAS,EACzB,OAAO,KAGT,IAAMC,EAAS,KAAK,MAAMD,EAAM,QAAQ,OAAS,CAAC,EAC5CE,EAAS,IAAoC,CACjD,GAAId,EAAAA,EAAMe,CAAW,EACrB,UACA,UAAWH,EAAM,UACjB,SAAUA,EAAM,QAClB,GAEA,MAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,EAAGC,CAAM,CAAC,EAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC,CACnF,CASA,SAAgBG,EAAY,EAAmB,EAAsB,CACnE,IAAMV,EAAiBW,EACvB,GAAI,OAAOX,GAAU,WAAYA,EAC/B,OAGF,IAAMY,EAAsB,QAAQ,IAAIZ,EAAO,YAAY,EAC3D,GAAI,OAAOY,GAAe,UAAYA,EAItC,OAAO,QAAQ,IAAIA,EAAYC,CAAG,CACpC,CAOA,SAAgBC,EAAe,EAA4B,CACzD,OAAOJ,EAAYC,EAAQhB,EAAAA,CAAa,IAAMC,EAAAA,EAChD,CAOA,SAAgBmB,EAAa,EAAsC,CACjE,OAAOC,EAAQ,QAAQ,EAAO,IAAUC,EAAQX,EAAM,QAAQ,OAAQ,CAAC,CACzE"}
@@ -1,5 +1,5 @@
1
- import { d as e, mt as t } from "./constants-CQ_D7jIW.js";
2
- import { i as n } from "./identity-rpEyjvVg.js";
1
+ import { d as e, mt as t } from "./constants-DhH6VI5a.js";
2
+ import { i as n } from "./identity-Di-QXGCC.js";
3
3
  //#region src/models/batch.ts
4
4
  function r(e) {
5
5
  if (typeof e != "object" || !e) return !1;
@@ -25,7 +25,10 @@ function a(e, t) {
25
25
  function o(n) {
26
26
  return a(n, e) === t;
27
27
  }
28
+ function s(e) {
29
+ return e.reduce((e, t) => e + t.records.length, 0);
30
+ }
28
31
  //#endregion
29
- export { i, o as n, r, a as t };
32
+ export { i as a, r as i, s as n, o as r, a as t };
30
33
 
31
- //# sourceMappingURL=batch-4xKzzSCj.js.map
34
+ //# sourceMappingURL=batch-DDgxg16_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-DDgxg16_.js","names":["ATTR_LOG_TYPE","LOG_TYPE_ACTION","newId","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":";;;AAiCA,SAAgBG,EAAW,GAAmC;CAC5D,IAAI,OAAOC,KAAU,aAAYA,GAC/B,OAAO;CAGT,IAAMC,IAAc,QAAQ,IAAID,GAAO,IAAI,GACrCE,IAAqB,QAAQ,IAAIF,GAAO,WAAW,GACnDG,IAAoB,QAAQ,IAAIH,GAAO,UAAU,GACjDI,IAAmB,QAAQ,IAAIJ,GAAO,SAAS;CAErD,OACE,OAAOC,KAAO,YACd,OAAOC,KAAc,YACrB,OAAOC,KAAa,YACpB,MAAM,QAAQC,CAAO;AAEzB;AASA,SAAgBC,EAAW,GAAiB,GAAuD;CACjG,IAAIC,EAAM,QAAQ,SAAS,GACzB,OAAO;CAGT,IAAMC,IAAS,KAAK,MAAMD,EAAM,QAAQ,SAAS,CAAC,GAC5CE,KAAS,OAAoC;EACjD,IAAIV,EAAMW,CAAW;EACrB;EACA,WAAWH,EAAM;EACjB,UAAUA,EAAM;CAClB;CAEA,OAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,GAAGC,CAAM,CAAC,GAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC;AACnF;AASA,SAAgBG,EAAY,GAAmB,GAAsB;CACnE,IAAMV,IAAiBW;CACvB,IAAI,OAAOX,KAAU,aAAYA,GAC/B;CAGF,IAAMY,IAAsB,QAAQ,IAAIZ,GAAO,YAAY;CAC3D,IAAI,OAAOY,KAAe,YAAYA,GAItC,OAAO,QAAQ,IAAIA,GAAYC,CAAG;AACpC;AAOA,SAAgBC,EAAe,GAA4B;CACzD,OAAOJ,EAAYC,GAAQf,CAAa,MAAMC;AAChD;AAOA,SAAgBkB,EAAa,GAAsC;CACjE,OAAOC,EAAQ,QAAQ,GAAO,MAAUC,IAAQX,EAAM,QAAQ,QAAQ,CAAC;AACzE"}
package/dist/bus/bus.d.ts CHANGED
@@ -47,8 +47,6 @@ export declare class Bus {
47
47
  private openFinLink;
48
48
  /** True if this context is the OpenFin platform provider. */
49
49
  private isOpenFinProvider;
50
- /** True if role resolution is complete. */
51
- private resolved;
52
50
  /** Timer that asks the upstream owner for the remote sampling rules. */
53
51
  private rulesPoll;
54
52
  /** True after destroy(). A handshake that ends later must not start a timer. */
@@ -68,8 +66,6 @@ export declare class Bus {
68
66
  constructor(config: ResolvedConfig, diagnostics: Diagnostics, platform: PlatformMetadata, contextId: string, tabId: string, handlers: BusHandlers, handshakeOptions?: HandshakeOptions);
69
67
  /** Returns the resolved bus role. */
70
68
  getRole(): BusRole;
71
- /** Returns true if role resolution is complete. */
72
- isResolved(): boolean;
73
69
  /**
74
70
  * Resolves bus role and establishes control links.
75
71
  * @returns Resolved role.
@@ -1,15 +1,16 @@
1
- import { C as e, E as t, Nt as n, Zt as r, w as i } from "./constants-CQ_D7jIW.js";
2
- import { r as a } from "./deadline-5_PecIl5.js";
3
- import { r as o } from "./journey-_dQQ1eMP.js";
4
- import { n as s, t as c } from "./remote-rules-UggoZqfP.js";
1
+ import { C as e, E as t, Nt as n, Zt as r, w as i } from "./constants-DhH6VI5a.js";
2
+ import { r as a } from "./deadline-DeqXEliN.js";
3
+ import { t as o } from "./openfin-BwEN0uj4.js";
4
+ import { r as s } from "./journey-yALMEWF7.js";
5
+ import { n as c, t as l } from "./remote-rules-6ePq8CrI.js";
5
6
  //#region src/models/bus.ts
6
- function l(e) {
7
+ function u(e) {
7
8
  return {
8
9
  p: t,
9
10
  m: e
10
11
  };
11
12
  }
12
- function u(e) {
13
+ function d(e) {
13
14
  if (typeof e != "object" || !e) return null;
14
15
  let t = e;
15
16
  if (t.p !== "ui-observability/1" || typeof t.m != "object" || t.m === null) return null;
@@ -18,11 +19,11 @@ function u(e) {
18
19
  }
19
20
  //#endregion
20
21
  //#region src/bus/links.ts
21
- var d = Symbol.for(r), f = "null";
22
- function p(e, t) {
23
- return e === f ? `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.`;
22
+ var f = Symbol.for(r), p = "null";
23
+ function m(e, t) {
24
+ return e === p ? `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.`;
24
25
  }
25
- function m() {
26
+ function h() {
26
27
  let e = location.ancestorOrigins;
27
28
  if (e && e.length > 0) return e.item(0);
28
29
  let t = document.referrer;
@@ -33,11 +34,11 @@ function m() {
33
34
  return null;
34
35
  }
35
36
  }
36
- function h(e, t) {
37
+ function g(e, t) {
37
38
  if (typeof window > "u" || window.parent === window) return null;
38
39
  let n;
39
40
  try {
40
- n = window.parent[d];
41
+ n = window.parent[f];
41
42
  } catch {
42
43
  return null;
43
44
  }
@@ -55,24 +56,24 @@ function h(e, t) {
55
56
  }
56
57
  };
57
58
  }
58
- function g(e, t, n) {
59
+ function _(e, t, n) {
59
60
  if (typeof window > "u" || window.parent === window) return null;
60
61
  let r = location.origin;
61
- if (r === f) 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.", {
62
+ if (r === p) 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.", {
62
63
  origin: r,
63
64
  type: "parent"
64
65
  }), null;
65
- let i = /* @__PURE__ */ new Set([r, ...t]), a = m();
66
+ let i = /* @__PURE__ */ new Set([r, ...t]), a = h();
66
67
  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.`, {
67
68
  origin: a ?? "",
68
69
  type: "parent"
69
70
  }), null;
70
71
  let o = /* @__PURE__ */ new Set(), s = (t) => {
71
- let r = u(t.data);
72
+ let r = d(t.data);
72
73
  r && t.source === window.parent && (i.has(t.origin) ? e(r, {
73
74
  link: "parent",
74
75
  origin: t.origin
75
- }) : o.has(t.origin) || (o.add(t.origin), n.report("bus.untrusted_origin", p(t.origin, "a message"), {
76
+ }) : o.has(t.origin) || (o.add(t.origin), n.report("bus.untrusted_origin", m(t.origin, "a message"), {
76
77
  origin: t.origin,
77
78
  type: r.t.slice(0, 32)
78
79
  })));
@@ -81,7 +82,7 @@ function g(e, t, n) {
81
82
  kind: "parent",
82
83
  post(e) {
83
84
  n.guard("bus.send_failed", "The postMessage call to the parent failed.", () => {
84
- window.parent.postMessage(l(e), a);
85
+ window.parent.postMessage(u(e), a);
85
86
  });
86
87
  },
87
88
  close() {
@@ -89,16 +90,16 @@ function g(e, t, n) {
89
90
  }
90
91
  };
91
92
  }
92
- function _(e, t, n) {
93
+ function v(e, t, n) {
93
94
  if (typeof window > "u") return null;
94
95
  let r = /* @__PURE__ */ new Set([location.origin, ...t]);
95
- r.delete(f);
96
+ r.delete(p);
96
97
  let i = /* @__PURE__ */ new Map(), a = (t) => {
97
- let a = u(t.data);
98
+ let a = d(t.data);
98
99
  a && (r.has(t.origin) ? (t.source && i.set(t.source, t.origin), e(a, {
99
100
  link: "children",
100
101
  origin: t.origin
101
- })) : n.report("bus.untrusted_origin", p(t.origin, "a message"), {
102
+ })) : n.report("bus.untrusted_origin", m(t.origin, "a message"), {
102
103
  origin: t.origin,
103
104
  type: a.t.slice(0, 32)
104
105
  }));
@@ -109,7 +110,7 @@ function _(e, t, n) {
109
110
  for (let [t, r] of i) {
110
111
  let a = t;
111
112
  a.closed ? i.delete(t) : n.guard("bus.send_failed", "The postMessage call to a child frame failed.", () => {
112
- a.postMessage(l(e), r);
113
+ a.postMessage(u(e), r);
113
114
  });
114
115
  }
115
116
  },
@@ -118,12 +119,12 @@ function _(e, t, n) {
118
119
  }
119
120
  };
120
121
  }
121
- function v(e, t, n) {
122
+ function y(e, t, n) {
122
123
  let r = globalThis.BroadcastChannel;
123
124
  if (r === void 0) return null;
124
125
  let i = n.guard("bus.send_failed", "The library could not open the BroadcastChannel.", () => new r(e));
125
126
  return i ? (i.onmessage = (e) => {
126
- let n = u(e.data);
127
+ let n = d(e.data);
127
128
  n && t(n, {
128
129
  link: "broadcast",
129
130
  origin: "same-origin"
@@ -132,7 +133,7 @@ function v(e, t, n) {
132
133
  kind: "broadcast",
133
134
  post(e) {
134
135
  n.guard("bus.send_failed", "The BroadcastChannel.postMessage call failed.", () => {
135
- i.postMessage(l(e));
136
+ i.postMessage(u(e));
136
137
  });
137
138
  },
138
139
  close() {
@@ -142,13 +143,13 @@ function v(e, t, n) {
142
143
  }
143
144
  }) : null;
144
145
  }
145
- function y(e, t, n, r) {
146
- let i = globalThis.fin?.InterApplicationBus;
146
+ function b(e, t, n, r) {
147
+ let i = o()?.InterApplicationBus;
147
148
  if (!i) return null;
148
149
  if (!t) return r.report("openfin.unavailable", "OpenFin gives no application uuid. The InterApplicationBus link stays closed."), null;
149
150
  let a = `${e}.${t}`;
150
151
  return r.guardAsync("bus.send_failed", "The InterApplicationBus.subscribe call failed.", () => i.subscribe({ uuid: t }, a, (e) => {
151
- let t = u(e);
152
+ let t = d(e);
152
153
  t && n(t, {
153
154
  link: "openfin",
154
155
  origin: "openfin"
@@ -156,15 +157,15 @@ function y(e, t, n, r) {
156
157
  })), {
157
158
  kind: "openfin",
158
159
  post(e) {
159
- r.guardAsync("bus.send_failed", "The InterApplicationBus.publish call failed.", () => i.publish(a, l(e)));
160
+ r.guardAsync("bus.send_failed", "The InterApplicationBus.publish call failed.", () => i.publish(a, u(e)));
160
161
  },
161
162
  close() {}
162
163
  };
163
164
  }
164
- function b(e, t) {
165
+ function x(e, t) {
165
166
  let n = globalThis, r = n.postMessage;
166
167
  return n.WorkerGlobalScope === void 0 || !r ? null : (n.addEventListener?.("message", (t) => {
167
- let n = u(t.data);
168
+ let n = d(t.data);
168
169
  n && e(n, {
169
170
  link: "owner",
170
171
  origin: "same-origin"
@@ -173,15 +174,15 @@ function b(e, t) {
173
174
  kind: "owner",
174
175
  post(e) {
175
176
  t.guard("bus.send_failed", "The postMessage call of the worker failed.", () => {
176
- r(l(e));
177
+ r(u(e));
177
178
  });
178
179
  },
179
180
  close() {}
180
181
  });
181
182
  }
182
- function x(e, t, n) {
183
+ function S(e, t, n) {
183
184
  let r = (e) => {
184
- let n = u(e.data);
185
+ let n = d(e.data);
185
186
  n && t(n, {
186
187
  link: "worker",
187
188
  origin: "same-origin"
@@ -191,7 +192,7 @@ function x(e, t, n) {
191
192
  kind: "worker",
192
193
  post(t) {
193
194
  n.guard("bus.send_failed", "The postMessage call to a worker failed.", () => {
194
- e.postMessage(l(t));
195
+ e.postMessage(u(t));
195
196
  });
196
197
  },
197
198
  close() {
@@ -201,14 +202,14 @@ function x(e, t, n) {
201
202
  }
202
203
  //#endregion
203
204
  //#region src/bus/bus.ts
204
- var S = {
205
+ var C = {
205
206
  timeoutMs: i,
206
207
  maxAttempts: 3
207
- }, C = [
208
+ }, w = [
208
209
  "children",
209
210
  "direct",
210
211
  "worker"
211
- ], w = class {
212
+ ], T = class {
212
213
  config;
213
214
  diagnostics;
214
215
  platform;
@@ -221,32 +222,28 @@ var S = {
221
222
  links = [];
222
223
  openFinLink = null;
223
224
  isOpenFinProvider = !1;
224
- resolved = !1;
225
225
  rulesPoll;
226
226
  destroyed = !1;
227
227
  ownerId = null;
228
228
  awaitingWelcome = null;
229
- constructor(e, t, n, r, i, a, o = S) {
229
+ constructor(e, t, n, r, i, a, o = C) {
230
230
  this.config = e, this.diagnostics = t, this.platform = n, this.contextId = r, this.tabId = i, this.handlers = a, this.handshakeOptions = o;
231
231
  }
232
232
  getRole() {
233
233
  return this.role;
234
234
  }
235
- isResolved() {
236
- return this.resolved;
237
- }
238
235
  async start() {
239
236
  let { bus: e } = this.config;
240
- if (e.mode === "off") return this.role = "sender", this.resolved = !0, this.role;
241
- 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.resolved = !0, this.announce(), this.role;
237
+ if (e.mode === "off") return this.role = "sender", this.role;
238
+ 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;
242
239
  this.openControlLinks();
243
- let t = h(this.receive, this.diagnostics);
244
- if (t) return this.role = "forwarder", this.upstream = t, this.resolved = !0, this.diagnostics.report("bus.role_resolved", "This context attached directly to the runtime of its same-origin parent.", {
240
+ let t = g(this.receive, this.diagnostics);
241
+ if (t) return this.role = "forwarder", this.upstream = t, this.diagnostics.report("bus.role_resolved", "This context attached directly to the runtime of its same-origin parent.", {
245
242
  role: "forwarder",
246
243
  via: "direct"
247
244
  }), this.announce(), this.role;
248
245
  let n = this.candidateUpstream();
249
- if (!n) return this.role = "sender", this.resolved = !0, this.diagnostics.report("bus.role_resolved", "No owner exists. This context sends its own records.", { role: "sender" }), this.announce(), this.role;
246
+ 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;
250
247
  let r = this.orphanPolicy() === "retry" ? this.handshakeOptions.maxAttempts : 1, i = !1;
251
248
  for (let e = 0; e < r && !i; e++) i = await this.handshake(n);
252
249
  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.`, {
@@ -255,7 +252,7 @@ var S = {
255
252
  })), this.diagnostics.report("bus.role_resolved", `The bus role is ${this.role}.`, {
256
253
  role: this.role,
257
254
  via: i ? n.kind : "none"
258
- }), this.resolved = !0, this.announce(), this.role;
255
+ }), this.announce(), this.role;
259
256
  }
260
257
  sendRecords(e) {
261
258
  this.upstream?.post({
@@ -287,7 +284,7 @@ var S = {
287
284
  } else e.t === "sampling?" ? t(this.rulesAnswer(e.from), n) : this.receive(e, n);
288
285
  }
289
286
  attachWorker(e) {
290
- this.links.push(x(e, this.receive, this.diagnostics));
287
+ this.links.push(S(e, this.receive, this.diagnostics));
291
288
  }
292
289
  broadcastJourney(e) {
293
290
  this.postJourney({
@@ -353,13 +350,13 @@ var S = {
353
350
  return e === "direct" || e !== this.upstream?.kind;
354
351
  }
355
352
  canOwn(e) {
356
- return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : C.includes(e) : !1;
353
+ return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : w.includes(e) : !1;
357
354
  }
358
355
  resolveOpenFinProvider() {
359
356
  let e = this.config.bus.openFinRole;
360
357
  if (e !== "auto") return e === "provider";
361
358
  if (this.platform.platform !== "openfin" && this.platform.platform !== "openfin_web") return !1;
362
- let t = globalThis.fin?.me;
359
+ let t = o()?.me;
363
360
  return !t?.identity || t.isView ? !1 : !!(t.identity.name && t.identity.name === t.identity.uuid);
364
361
  }
365
362
  orphanPolicy() {
@@ -374,16 +371,16 @@ var S = {
374
371
  }
375
372
  }
376
373
  candidateUpstream() {
377
- return this.platform.isWorker ? b(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : g(this.receive, this.config.bus.trustedOrigins, this.diagnostics);
374
+ return this.platform.isWorker ? x(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : _(this.receive, this.config.bus.trustedOrigins, this.diagnostics);
378
375
  }
379
376
  openControlLinks() {
380
377
  let t = (e) => {
381
378
  e && this.links.push(e);
382
379
  };
383
- this.platform.isTopLevelDocument && (t(_(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), t(v(e, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && t(this.ensureOpenFinLink());
380
+ this.platform.isTopLevelDocument && (t(v(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), t(y(e, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && t(this.ensureOpenFinLink());
384
381
  }
385
382
  ensureOpenFinLink() {
386
- return this.openFinLink ??= y(e, this.platform.openfinUuid, this.receive, this.diagnostics), this.openFinLink;
383
+ return this.openFinLink ??= b(e, this.platform.openfinUuid, this.receive, this.diagnostics), this.openFinLink;
387
384
  }
388
385
  handshake(e) {
389
386
  return new Promise((t) => {
@@ -435,7 +432,7 @@ var S = {
435
432
  this.handlers.onJourney(null);
436
433
  return;
437
434
  }
438
- let t = o(e);
435
+ let t = s(e);
439
436
  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);
440
437
  }
441
438
  rulesAnswer(e) {
@@ -457,11 +454,11 @@ var S = {
457
454
  }
458
455
  applyRules(e) {
459
456
  if (e === null) {
460
- c(this.handlers.remote, this.config, null);
457
+ l(this.handlers.remote, this.config, null);
461
458
  return;
462
459
  }
463
- let t = s(e, this.diagnostics);
464
- t && c(this.handlers.remote, this.config, t);
460
+ let t = c(e, this.diagnostics);
461
+ t && l(this.handlers.remote, this.config, t);
465
462
  }
466
463
  pollRules() {
467
464
  let { upstream: e } = this;
@@ -476,6 +473,6 @@ var S = {
476
473
  }
477
474
  };
478
475
  //#endregion
479
- export { w as Bus };
476
+ export { T as Bus };
480
477
 
481
- //# sourceMappingURL=bus-DrixwdiX.js.map
478
+ //# sourceMappingURL=bus-C6RwKzPW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bus-C6RwKzPW.js","names":["BUS_CHANNEL_NAME","BUS_PROTOCOL","REMOTE_SAMPLING_POLL_MS","RUNTIME_GLOBAL_KEY","BUS_HANDSHAKE_TIMEOUT_MS","unrefTimer","getFin","parseJourney","parseRemoteRules","applyRemote","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","source","createBroadcastLink","BC","channel","channelName","createOpenFinLink","iab","appUuid","scoped","topic","raw","createOwnerLink","scope","send","createWorkerLink","worker","HANDSHAKE_OPTIONS","OWNED","Bus","config","platform","contextId","tabId","handlers","handshakeOptions","bus","direct","candidate","attempts","welcomed","attempt","reply","current","link","configured","me","push","settled","finish","timer","resolve","result","from","payload","journey","rules","to","update","upstream","ask"],"sources":["../src/models/bus.ts","../src/bus/links.ts","../src/bus/bus.ts"],"sourcesContent":["// src/models/bus.ts\n//\n// Protocol types, message definitions, and envelope encoding for bus messages between realms.\n\nimport { BUS_PROTOCOL } from \"../constants\";\nimport type { LogRecord } from \"./log-record\";\n\n/** Delivery role. It tells if this context sends its records or forwards them upstream. */\nexport type BusRole = \"sender\" | \"forwarder\";\n\n/**\n * Kind of transport channel. The bus uses it to route incoming and outgoing messages.\n * Without it, `receive` cannot tell the channels apart. Then a same-origin iframe\n * looks like a 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 /** 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}\n\n/** Discriminated union of control and telemetry payload messages. */\nexport type BusMessage =\n /** Handshake discovery announcement from a starting forwarder. */\n | { t: \"hello\"; from: string; tabId: string }\n /**\n * Handshake response from an upstream owner. The `to` field holds the address.\n * A welcome on InterApplicationBus goes to every subscriber. Without an address,\n * each waiting view accepts the welcome as its own.\n */\n | { t: \"welcome\"; from: string; to: string; tabId: string }\n /** Telemetry log records forwarded to an upstream sender. */\n | { t: \"records\"; from: string; records: LogRecord[] }\n /**\n * Journey update, or the answer to a journey question. An answer holds the address of the\n * context that asked in `to`. The payload comes from another realm. The receiver parses it.\n */\n | { t: \"journey\"; from: string; to?: string; journey: unknown }\n /** Query requesting active journey state from connected peers. */\n | { t: \"journey?\"; from: string }\n /** Tab identifier claim broadcast to detect collisions across windows. */\n | { t: \"tab\"; from: string; tabId: string }\n /** Request of a forwarder for the remote sampling rules in force. */\n | { t: \"sampling?\"; from: string }\n /**\n * Remote sampling rules in the shape of the header, with the remaining TTL. The `to` field\n * holds the address of the forwarder that asked. The receiver validates `rules` again.\n * Null rules end the copy of the forwarder.\n */\n | { t: \"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\n * document gets `message` events from all embedded content on the page. This\n * includes analytics tags, video players and extensions. Without the tag check,\n * the bus parses a message from a video player as a log record.\n * @param data Raw payload received over a transport link.\n * @returns Validated message, or null if 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): void;\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 message for an ignored message 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 message. A sandboxed sender gets 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 origin of the parent frame. A cross-origin parent does not give its location.\n * @returns The origin, or null when the browser does not give 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. The referrer of a frame is the page that loaded it.\n // A Referrer-Policy of no-referrer gives \"\". The caller reports an 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 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);\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 * A page on another origin that frames this app must not get them.\n * @param receive Callback for incoming parent messages.\n * @param trustedOrigins Origins of a parent that can get 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 * With 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. No parent can list it in its own 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 each untrusted origin one time. 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 sets message.t. Keep it out of the message text. Cut it 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 });\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): Link | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n // A sandboxed page has the opaque origin \"null\". Each sandboxed child also has it.\n const trusted = new Set([location.origin, ...trustedOrigins]);\n trusted.delete(OPAQUE_ORIGIN);\n\n // The map keeps the origin of each source.\n // A child that navigates must not get the ids of its previous origin.\n const sources = new Map<MessageEventSource, string>();\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (!message) {\n return;\n }\n if (!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 (event.source) {\n sources.set(event.source, event.origin);\n }\n receive(message, { link: \"children\", origin: event.origin });\n };\n addEventListener(\"message\", onMessage);\n\n return {\n kind: \"children\",\n post(message) {\n for (const [source, origin] of sources) {\n const target = source as Window;\n // Evicts closed child windows to prevent memory leaks.\n if (target.closed) {\n sources.delete(source);\n continue;\n }\n diagnostics.guard(\n \"bus.send_failed\",\n \"The postMessage call to a child frame failed.\",\n () => {\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 },\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 shares the bus of this app with all other apps.\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 topic and the subscriber identity both contain the uuid. The topic keeps\n // messages of this app from other apps. The identity rejects messages from other apps.\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) => {\n const message = unwrap(raw);\n if (message) {\n receive(message, { link: \"openfin\", origin: \"openfin\" });\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\" });\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 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 { JourneyScope, ResolvedConfig } from \"../models/config\";\nimport type { LogRecord } from \"../models/log-record\";\nimport { getFin } from \"../utils/openfin\";\nimport type { PlatformMetadata } from \"../utils/platform\";\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 /** Maximum time that 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 /** 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 /** Slot of the runtime for the remote sampling rules. The bus reads it 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 /** Current bus role. The default is \"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(). A handshake that ends later must not start a timer. */\n private destroyed = false;\n /** Context id of the owner that answered the handshake. Null with no handshake. */\n private ownerId: string | null = null;\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 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 // OpenFin link remains 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 this.upstream?.post({ t: \"records\", from: this.contextId, records });\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): void {\n if (message.from === this.contextId) {\n return;\n }\n const source: MessageSource = { link: \"direct\", origin: \"same-origin\" };\n\n if (message.t === \"hello\") {\n if (this.canOwn(\"direct\")) {\n reply(\n {\n t: \"welcome\",\n from: this.contextId,\n to: message.from,\n tabId: this.tabId,\n },\n source,\n );\n }\n return;\n }\n if (message.t === \"journey?\") {\n const current = this.handlers.onJourneyRequest();\n if (current && this.journeyLink(\"direct\")) {\n reply({ t: \"journey\", from: this.contextId, to: message.from, journey: current }, source);\n }\n return;\n }\n // A direct link has no channel from the parent to the child. The parent answers here.\n if (message.t === \"sampling?\") {\n reply(this.rulesAnswer(message.from), source);\n return;\n }\n this.receive(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): void {\n this.links.push(createWorkerLink(worker, this.receive, this.diagnostics));\n }\n\n /**\n * Sends journey state changes over each link of the journey scope.\n * @param journey Active journey or null if ended.\n */\n broadcastJourney(journey: Journey | null): void {\n this.postJourney({ t: \"journey\", from: this.contextId, journey });\n }\n\n /** Closes all open links and clears internal state. */\n destroy(): void {\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 each link of 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 if (message.from === this.contextId) {\n return;\n }\n\n switch (message.t) {\n case \"hello\":\n if (this.canOwn(source.link)) {\n this.postOver(source.link, {\n t: \"welcome\",\n from: this.contextId,\n to: message.from,\n tabId: this.tabId,\n });\n }\n break;\n\n case \"welcome\":\n if (message.to !== this.contextId) {\n break;\n }\n if (this.awaitingWelcome?.link === source.link) {\n // Keep the owner. Only it can set the journey of this context on a shared link.\n this.ownerId = message.from;\n this.awaitingWelcome.settle(true);\n }\n break;\n\n case \"records\":\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 \"journey\":\n if (this.acceptsJourney(message, source)) {\n this.applyJourney(message.journey);\n }\n break;\n\n case \"journey?\": {\n const current = this.handlers.onJourneyRequest();\n // Address the answer. On a shared link, each other context ignores it.\n if (current && this.journeyLink(source.link)) {\n this.postOver(source.link, {\n t: \"journey\",\n from: this.contextId,\n to: message.from,\n journey: current,\n });\n }\n break;\n }\n\n case \"sampling?\":\n // A forwarder answers only its own children. A sibling on its upstream link asks too.\n // A sibling answer on OpenFin gives N squared messages, and a stale copy can win.\n if (\n this.role === \"forwarder\" ? source.link !== this.upstream?.kind : this.canOwn(source.link)\n ) {\n this.postOver(source.link, this.rulesAnswer(message.from));\n }\n break;\n\n case \"sampling\":\n if (this.acceptsRules(message.to, source)) {\n this.applyRules(message.rules);\n }\n break;\n\n case \"tab\":\n // A collision applies only to two different contexts on the broadcast channel.\n // The id comparison selects one context of the pair.\n // Without it, both contexts 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 * Tells if records from a link can go upstream. Records that go back on\n * their arrival link return to their sender. A direct link is an exception.\n * Each direct link is one call into one parent. Thus two direct links in a\n * chain are 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 /** Returns true if this context can be the owner of the given link type. */\n private canOwn(link: LinkKind): boolean {\n if (this.role !== \"sender\") {\n return false;\n }\n if (link === \"openfin\") {\n return this.isOpenFinProvider;\n }\n return OWNED.includes(link);\n }\n\n /** Finds if 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 /** Tests if 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. Lint 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.isTopLevelDocument) {\n push(createChildrenLink(this.receive, this.config.bus.trustedOrigins, this.diagnostics));\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 /** 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 * Executes a hello/welcome handshake over candidate link.\n * @param candidate Upstream link candidate.\n * @returns True if welcome response arrived before 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 the code declares after finish. This order is safe.\n // finish can run only after the post below. The timer exists at that time.\n const timer = setTimeout(() => {\n finish(false);\n }, this.handshakeOptions.timeoutMs);\n unrefTimer(timer);\n candidate.post({ t: \"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: \"tab\",\n from: this.contextId,\n tabId: this.tabId,\n });\n this.postJourney({ t: \"journey?\", from: this.contextId });\n this.pollRules();\n }\n\n /**\n * Resolves the journey scope. \"auto\" gives \"origin\" in OpenFin and \"tab\" in a browser.\n * @returns The scope in force.\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 * Tests if a link carries journey messages in the scope in force.\n * Only \"origin\" uses the broadcast link. That link reaches each tab of 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 * Tests if 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, to this context, from an accepted sender.\n * In \"tab\" scope, only the owner of a forwarder is an accepted sender.\n */\n private acceptsJourney(\n message: Extract<BusMessage, { t: \"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 this.journeyScope() === \"origin\" || this.fromOwner(message.from, source.link);\n }\n\n /**\n * Tests if a message comes from the upstream owner of this forwarder.\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 gives 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 end the copy of the forwarder.\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: \"sampling\", from: this.contextId, to, rules };\n }\n\n /**\n * Tests if 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 is not 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. It must not lower minLevel and read the 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 true;\n }\n\n /**\n * Applies the rules of an answer. It ignores rules that are not valid.\n * @param raw Rules of the answer, 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 at each poll interval.\n * A direct link cannot push the rules to a child. A poll works on each 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 at each poll. A later configure() can turn remote sampling on or off.\n const ask = (): void => {\n if (this.config.sampling.remote) {\n upstream.post({ t: \"sampling?\", 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":";;;;;;AAkFA,SAAgBU,EAAS,GAAkC;CACzD,OAAO;EAAE,GAAGT;EAAc,GAAGU;CAAQ;AACvC;AAUA,SAAgBC,EAAO,GAAkC;CACvD,IAAI,OAAOC,KAAS,aAAYA,GAC9B,OAAO;CAIT,IAAMC,IAAUD;CAChB,IAAIC,EAAQ,MAAA,wBAAsB,OAAOA,EAAQ,KAAM,YAAYA,EAAQ,MAAM,MAC/E,OAAO;CAGT,IAAMH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AIA,AAFAC,EAAI,GACJ,KAAK,YAAY,YAAYA,GAAKrF,CAAuB,GACzDG,EAAW,KAAK,SAAS;CAC3B;AACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("./constants-Cb92egPS.cjs"),t=require("./deadline-CUrH0Hd8.cjs"),n=require("./openfin-DtH2f7zX.cjs"),r=require("./journey-BRUj0hqD.cjs"),i=require("./remote-rules-CI3gbRCL.cjs");function a(t){return{p:e.E,m:t}}function o(e){if(typeof e!=`object`||!e)return null;let t=e;if(t.p!==`ui-observability/1`||typeof t.m!=`object`||t.m===null)return null;let n=t.m;return typeof n.t==`string`?n:null}var s=Symbol.for(e.Zt),c=`null`;function l(e,t){return e===c?`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.`}function u(){let e=location.ancestorOrigins;if(e&&e.length>0)return e.item(0);let t=document.referrer;if(t===``)return null;try{return new URL(t).origin}catch{return null}}function d(e,t){if(typeof window>`u`||window.parent===window)return null;let n;try{n=window.parent[s]}catch{return null}if(typeof n?.busAccept!=`function`)return null;let r=n,i=!0;return{kind:`direct`,post(n){i&&t.guard(`bus.send_failed`,`The direct call into the parent runtime failed.`,()=>{r.busAccept(n,e)})},close(){i=!1}}}function f(e,t,n){if(typeof window>`u`||window.parent===window)return null;let r=location.origin;if(r===c)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.`,{origin:r,type:`parent`}),null;let i=new Set([r,...t]),s=u();if(s===null||!i.has(s))return n.report(`bus.untrusted_origin`,s===null?`The origin of the parent frame is unknown. This context sends its own records.`:`The parent frame is on ${s}. This origin is not in bus.trustedOrigins. This context sends its own records.`,{origin:s??``,type:`parent`}),null;let d=new Set,f=t=>{let r=o(t.data);r&&t.source===window.parent&&(i.has(t.origin)?e(r,{link:`parent`,origin:t.origin}):d.has(t.origin)||(d.add(t.origin),n.report(`bus.untrusted_origin`,l(t.origin,`a message`),{origin:t.origin,type:r.t.slice(0,32)})))};return addEventListener(`message`,f),{kind:`parent`,post(e){n.guard(`bus.send_failed`,`The postMessage call to the parent failed.`,()=>{window.parent.postMessage(a(e),s)})},close(){removeEventListener(`message`,f)}}}function p(e,t,n){if(typeof window>`u`)return null;let r=new Set([location.origin,...t]);r.delete(c);let i=new Map,s=t=>{let a=o(t.data);a&&(r.has(t.origin)?(t.source&&i.set(t.source,t.origin),e(a,{link:`children`,origin:t.origin})):n.report(`bus.untrusted_origin`,l(t.origin,`a message`),{origin:t.origin,type:a.t.slice(0,32)}))};return addEventListener(`message`,s),{kind:`children`,post(e){for(let[t,r]of i){let o=t;o.closed?i.delete(t):n.guard(`bus.send_failed`,`The postMessage call to a child frame failed.`,()=>{o.postMessage(a(e),r)})}},close(){removeEventListener(`message`,s),i.clear()}}}function m(e,t,n){let r=globalThis.BroadcastChannel;if(r===void 0)return null;let i=n.guard(`bus.send_failed`,`The library could not open the BroadcastChannel.`,()=>new r(e));return i?(i.onmessage=e=>{let n=o(e.data);n&&t(n,{link:`broadcast`,origin:`same-origin`})},{kind:`broadcast`,post(e){n.guard(`bus.send_failed`,`The BroadcastChannel.postMessage call failed.`,()=>{i.postMessage(a(e))})},close(){n.guard(`bus.send_failed`,`The library could not close the BroadcastChannel.`,()=>{i.close()})}}):null}function h(e,t,r,i){let s=n.t()?.InterApplicationBus;if(!s)return null;if(!t)return i.report(`openfin.unavailable`,`OpenFin gives no application uuid. The InterApplicationBus link stays closed.`),null;let c=`${e}.${t}`;return i.guardAsync(`bus.send_failed`,`The InterApplicationBus.subscribe call failed.`,()=>s.subscribe({uuid:t},c,e=>{let t=o(e);t&&r(t,{link:`openfin`,origin:`openfin`})})),{kind:`openfin`,post(e){i.guardAsync(`bus.send_failed`,`The InterApplicationBus.publish call failed.`,()=>s.publish(c,a(e)))},close(){}}}function g(e,t){let n=globalThis,r=n.postMessage;return n.WorkerGlobalScope===void 0||!r?null:(n.addEventListener?.(`message`,t=>{let n=o(t.data);n&&e(n,{link:`owner`,origin:`same-origin`})}),{kind:`owner`,post(e){t.guard(`bus.send_failed`,`The postMessage call of the worker failed.`,()=>{r(a(e))})},close(){}})}function _(e,t,n){let r=e=>{let n=o(e.data);n&&t(n,{link:`worker`,origin:`same-origin`})};return e.addEventListener(`message`,r),e.start?.(),{kind:`worker`,post(t){n.guard(`bus.send_failed`,`The postMessage call to a worker failed.`,()=>{e.postMessage(a(t))})},close(){e.removeEventListener(`message`,r)}}}var v={timeoutMs:e.w,maxAttempts:3},y=[`children`,`direct`,`worker`],b=class{config;diagnostics;platform;contextId;tabId;handlers;handshakeOptions;role=`sender`;upstream=null;links=[];openFinLink=null;isOpenFinProvider=!1;rulesPoll;destroyed=!1;ownerId=null;awaitingWelcome=null;constructor(e,t,n,r,i,a,o=v){this.config=e,this.diagnostics=t,this.platform=n,this.contextId=r,this.tabId=i,this.handlers=a,this.handshakeOptions=o}getRole(){return this.role}async start(){let{bus:e}=this.config;if(e.mode===`off`)return this.role=`sender`,this.role;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;this.openControlLinks();let t=d(this.receive,this.diagnostics);if(t)return this.role=`forwarder`,this.upstream=t,this.diagnostics.report(`bus.role_resolved`,`This context attached directly to the runtime of its same-origin parent.`,{role:`forwarder`,via:`direct`}),this.announce(),this.role;let n=this.candidateUpstream();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;let r=this.orphanPolicy()===`retry`?this.handshakeOptions.maxAttempts:1,i=!1;for(let e=0;e<r&&!i;e++)i=await this.handshake(n);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.`,{via:n.kind,crossOrigin:this.isCrossOriginFrame()})),this.diagnostics.report(`bus.role_resolved`,`The bus role is ${this.role}.`,{role:this.role,via:i?n.kind:`none`}),this.announce(),this.role}sendRecords(e){this.upstream?.post({t:`records`,from:this.contextId,records:e})}acceptDirect(e,t){if(e.from===this.contextId)return;let n={link:`direct`,origin:`same-origin`};if(e.t===`hello`)this.canOwn(`direct`)&&t({t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId},n);else if(e.t===`journey?`){let r=this.handlers.onJourneyRequest();r&&this.journeyLink(`direct`)&&t({t:`journey`,from:this.contextId,to:e.from,journey:r},n)}else e.t===`sampling?`?t(this.rulesAnswer(e.from),n):this.receive(e,n)}attachWorker(e){this.links.push(_(e,this.receive,this.diagnostics))}broadcastJourney(e){this.postJourney({t:`journey`,from:this.contextId,journey:e})}destroy(){this.destroyed=!0,clearInterval(this.rulesPoll),this.rulesPoll=void 0;for(let e of this.allLinks())e.close();this.links.length=0,this.upstream=null,this.ownerId=null,this.openFinLink=null}allLinks(){return!this.upstream||this.links.includes(this.upstream)?this.links:[...this.links,this.upstream]}postOver(e,t){for(let n of this.allLinks())n.kind===e&&n.post(t)}postJourney(e){for(let t of this.allLinks())this.journeyLink(t.kind)&&t.post(e)}receive=(e,t)=>{if(e.from!==this.contextId)switch(e.t){case`hello`:this.canOwn(t.link)&&this.postOver(t.link,{t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId});break;case`welcome`:if(e.to!==this.contextId)break;this.awaitingWelcome?.link===t.link&&(this.ownerId=e.from,this.awaitingWelcome.settle(!0));break;case`records`:this.role===`sender`?this.handlers.onRecords(e.records):this.upstream&&this.canRelay(t.link)&&this.upstream.post(e);break;case`journey`:this.acceptsJourney(e,t)&&this.applyJourney(e.journey);break;case`journey?`:{let n=this.handlers.onJourneyRequest();n&&this.journeyLink(t.link)&&this.postOver(t.link,{t:`journey`,from:this.contextId,to:e.from,journey:n});break}case`sampling?`:(this.role===`forwarder`?t.link!==this.upstream?.kind:this.canOwn(t.link))&&this.postOver(t.link,this.rulesAnswer(e.from));break;case`sampling`:this.acceptsRules(e.to,t)&&this.applyRules(e.rules);break;case`tab`:t.link===`broadcast`&&e.tabId===this.tabId&&this.contextId>e.from&&this.handlers.onTabConflict()}};canRelay(e){return e===`direct`||e!==this.upstream?.kind}canOwn(e){return this.role===`sender`?e===`openfin`?this.isOpenFinProvider:y.includes(e):!1}resolveOpenFinProvider(){let e=this.config.bus.openFinRole;if(e!==`auto`)return e===`provider`;if(this.platform.platform!==`openfin`&&this.platform.platform!==`openfin_web`)return!1;let t=n.t()?.me;return!t?.identity||t.isView?!1:!!(t.identity.name&&t.identity.name===t.identity.uuid)}orphanPolicy(){return this.isCrossOriginFrame()?`retry`:`promote`}isCrossOriginFrame(){if(typeof window>`u`||window.parent===window)return!1;try{return Reflect.get(window.parent,`location`),!1}catch{return!0}}candidateUpstream(){return this.platform.isWorker?g(this.receive,this.diagnostics):this.platform.isTopLevelDocument?this.platform.platform===`openfin`&&!this.isOpenFinProvider?this.ensureOpenFinLink():null:f(this.receive,this.config.bus.trustedOrigins,this.diagnostics)}openControlLinks(){let t=e=>{e&&this.links.push(e)};this.platform.isTopLevelDocument&&(t(p(this.receive,this.config.bus.trustedOrigins,this.diagnostics)),t(m(e.C,this.receive,this.diagnostics))),(this.platform.platform===`openfin`||this.platform.platform===`openfin_web`)&&t(this.ensureOpenFinLink())}ensureOpenFinLink(){return this.openFinLink??=h(e.C,this.platform.openfinUuid,this.receive,this.diagnostics),this.openFinLink}handshake(e){return new Promise(n=>{let r=!1,i=e=>{r||(r=!0,this.awaitingWelcome=null,clearTimeout(a),n(e))};this.awaitingWelcome={link:e.kind,settle:i};let a=setTimeout(()=>{i(!1)},this.handshakeOptions.timeoutMs);t.r(a),e.post({t:`hello`,from:this.contextId,tabId:this.tabId})})}announce(){this.postOver(`broadcast`,{t:`tab`,from:this.contextId,tabId:this.tabId}),this.postJourney({t:`journey?`,from:this.contextId}),this.pollRules()}journeyScope(){let{scope:e}=this.config.journey;if(e!==`auto`)return e;let{platform:t}=this.platform;return t===`openfin`||t===`openfin_web`?`origin`:`tab`}journeyLink(e){let t=this.journeyScope();return t===`context`?!1:t===`origin`||e!==`broadcast`}acceptsJourney(e,t){return!this.journeyLink(t.link)||e.to!==void 0&&e.to!==this.contextId?!1:this.journeyScope()===`origin`||this.fromOwner(e.from,t.link)}fromOwner(e,t){return this.role!==`forwarder`||t!==this.upstream?.kind?!1:this.ownerId===null||e===this.ownerId}applyJourney(e){if(e===null){this.handlers.onJourney(null);return}let t=r.r(e);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)}rulesAnswer(e){let t=this.handlers.remote.sampling?.wire()??null;return{t:`sampling`,from:this.contextId,to:e,rules:t}}acceptsRules(e,t){if(this.role!==`forwarder`||e!==this.contextId||t.link!==this.upstream?.kind)return!1;let{origin:n}=t;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.`,{origin:n,type:`sampling`}),!1):!0}applyRules(e){if(e===null){i.t(this.handlers.remote,this.config,null);return}let t=i.n(e,this.diagnostics);t&&i.t(this.handlers.remote,this.config,t)}pollRules(){let{upstream:n}=this;if(this.destroyed||this.role!==`forwarder`||!n)return;let r=()=>{this.config.sampling.remote&&n.post({t:`sampling?`,from:this.contextId})};r(),this.rulesPoll=setInterval(r,e.Nt),t.r(this.rulesPoll)}};exports.Bus=b;
2
+ //# sourceMappingURL=bus-WPVDFw2y.cjs.map