@utk09/ui-observability 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +119 -60
  3. package/dist/bus/bus.d.ts +10 -10
  4. package/dist/bus/links.d.ts +1 -1
  5. package/dist/bus-DeZzr2bx.cjs +2 -0
  6. package/dist/bus-DeZzr2bx.cjs.map +1 -0
  7. package/dist/{bus-D3OO0OcL.js → bus-DfAbg_pg.js} +19 -19
  8. package/dist/bus-DfAbg_pg.js.map +1 -0
  9. package/dist/capture/network.d.ts +2 -2
  10. package/dist/capture/types.d.ts +10 -10
  11. package/dist/capture/web-vitals.d.ts +3 -3
  12. package/dist/constants-C8nZQBmQ.js +86 -0
  13. package/dist/constants-C8nZQBmQ.js.map +1 -0
  14. package/dist/constants-IBL_jd5R.cjs +2 -0
  15. package/dist/constants-IBL_jd5R.cjs.map +1 -0
  16. package/dist/constants.d.ts +56 -43
  17. package/dist/core/breadcrumbs.d.ts +14 -14
  18. package/dist/core/config.d.ts +5 -4
  19. package/dist/core/context.d.ts +2 -2
  20. package/dist/core/diagnostics.d.ts +10 -9
  21. package/dist/core/journey.d.ts +23 -20
  22. package/dist/core/logger.d.ts +7 -7
  23. package/dist/core/pipeline.d.ts +34 -29
  24. package/dist/core/record.d.ts +6 -6
  25. package/dist/core/runtime.d.ts +20 -18
  26. package/dist/core/sampling.d.ts +15 -16
  27. package/dist/core/sender.d.ts +1 -1
  28. package/dist/{errors-Dme9tz-6.js → errors-4MQyjZVj.js} +4 -4
  29. package/dist/errors-4MQyjZVj.js.map +1 -0
  30. package/dist/{errors-DPju_xSI.cjs → errors-CUdShXe7.cjs} +2 -2
  31. package/dist/errors-CUdShXe7.cjs.map +1 -0
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.ts +7 -5
  35. package/dist/index.js +136 -115
  36. package/dist/index.js.map +1 -1
  37. package/dist/{indexeddb-storage-nxs_rxGx.js → indexeddb-storage-0LtUALBg.js} +16 -16
  38. package/dist/indexeddb-storage-0LtUALBg.js.map +1 -0
  39. package/dist/indexeddb-storage-CcEJlq2l.cjs +2 -0
  40. package/dist/indexeddb-storage-CcEJlq2l.cjs.map +1 -0
  41. package/dist/{interactions-DP0-rIPJ.cjs → interactions-BMNPQ3WH.cjs} +2 -2
  42. package/dist/interactions-BMNPQ3WH.cjs.map +1 -0
  43. package/dist/{interactions-C1romMpE.js → interactions-BaCmoGLB.js} +2 -2
  44. package/dist/interactions-BaCmoGLB.js.map +1 -0
  45. package/dist/models/batch.d.ts +12 -9
  46. package/dist/models/bus.d.ts +12 -13
  47. package/dist/models/config.d.ts +85 -44
  48. package/dist/models/log-record.d.ts +12 -10
  49. package/dist/models/serializer.d.ts +3 -2
  50. package/dist/models/storage.d.ts +2 -2
  51. package/dist/network-DBNvxCE3.cjs +2 -0
  52. package/dist/network-DBNvxCE3.cjs.map +1 -0
  53. package/dist/{network-au-Tqt1n.js → network-jQ2t8rU4.js} +4 -4
  54. package/dist/network-jQ2t8rU4.js.map +1 -0
  55. package/dist/platform-ByQllE_W.cjs +2 -0
  56. package/dist/platform-ByQllE_W.cjs.map +1 -0
  57. package/dist/{platform-DMYo3AX3.js → platform-YuByH8A5.js} +8 -8
  58. package/dist/platform-YuByH8A5.js.map +1 -0
  59. package/dist/{sampling-ByI5H44E.js → sampling-CbYySsZ1.js} +21 -18
  60. package/dist/sampling-CbYySsZ1.js.map +1 -0
  61. package/dist/sampling-Cs50xsZl.cjs +2 -0
  62. package/dist/sampling-Cs50xsZl.cjs.map +1 -0
  63. package/dist/{sender-R7lOpyNc.js → sender-BIob8eZz.js} +60 -60
  64. package/dist/sender-BIob8eZz.js.map +1 -0
  65. package/dist/sender-iOjzcueM.cjs +3 -0
  66. package/dist/sender-iOjzcueM.cjs.map +1 -0
  67. package/dist/storage/emergency-queue.d.ts +2 -2
  68. package/dist/storage/factory.d.ts +2 -1
  69. package/dist/storage/idb-driver.d.ts +19 -19
  70. package/dist/storage/indexeddb-storage.d.ts +18 -17
  71. package/dist/storage/keys.d.ts +1 -1
  72. package/dist/storage/local-storage.d.ts +19 -18
  73. package/dist/storage/memory-storage.d.ts +12 -11
  74. package/dist/transport/compression.d.ts +2 -2
  75. package/dist/transport/errors.d.ts +8 -7
  76. package/dist/transport/exit-flush.d.ts +27 -24
  77. package/dist/transport/http-transport.d.ts +18 -11
  78. package/dist/transport/retry-engine.d.ts +33 -28
  79. package/dist/transport/serializers/ecs.d.ts +1 -1
  80. package/dist/transport/serializers/otlp.d.ts +1 -1
  81. package/dist/unref-16maCyKA.js.map +1 -1
  82. package/dist/unref-CU9Nyz_9.cjs.map +1 -1
  83. package/dist/utils/console.d.ts +7 -6
  84. package/dist/utils/identity.d.ts +6 -5
  85. package/dist/utils/lock.d.ts +4 -4
  86. package/dist/utils/platform.d.ts +5 -3
  87. package/dist/utils/sanitize.d.ts +5 -2
  88. package/dist/utils/sequence.d.ts +2 -2
  89. package/dist/utils/tracing.d.ts +8 -7
  90. package/dist/web-vitals-B2FYsEAU.cjs +2 -0
  91. package/dist/web-vitals-B2FYsEAU.cjs.map +1 -0
  92. package/dist/{web-vitals-DwWdLBq6.js → web-vitals-DHZ0yA_H.js} +4 -4
  93. package/dist/web-vitals-DHZ0yA_H.js.map +1 -0
  94. package/package.json +4 -2
  95. package/dist/bus-D3OO0OcL.js.map +0 -1
  96. package/dist/bus-OdRJVUzr.cjs +0 -2
  97. package/dist/bus-OdRJVUzr.cjs.map +0 -1
  98. package/dist/constants-B6kdsCzF.js +0 -75
  99. package/dist/constants-B6kdsCzF.js.map +0 -1
  100. package/dist/constants-DZH04585.cjs +0 -2
  101. package/dist/constants-DZH04585.cjs.map +0 -1
  102. package/dist/errors-DPju_xSI.cjs.map +0 -1
  103. package/dist/errors-Dme9tz-6.js.map +0 -1
  104. package/dist/indexeddb-storage-lGdoHGHy.cjs +0 -2
  105. package/dist/indexeddb-storage-lGdoHGHy.cjs.map +0 -1
  106. package/dist/indexeddb-storage-nxs_rxGx.js.map +0 -1
  107. package/dist/interactions-C1romMpE.js.map +0 -1
  108. package/dist/interactions-DP0-rIPJ.cjs.map +0 -1
  109. package/dist/network-DDVIJSHd.cjs +0 -2
  110. package/dist/network-DDVIJSHd.cjs.map +0 -1
  111. package/dist/network-au-Tqt1n.js.map +0 -1
  112. package/dist/platform-DMYo3AX3.js.map +0 -1
  113. package/dist/platform-g99Kn755.cjs +0 -2
  114. package/dist/platform-g99Kn755.cjs.map +0 -1
  115. package/dist/sampling-ByI5H44E.js.map +0 -1
  116. package/dist/sampling-Dui-Fp3u.cjs +0 -2
  117. package/dist/sampling-Dui-Fp3u.cjs.map +0 -1
  118. package/dist/sender-R7lOpyNc.js.map +0 -1
  119. package/dist/sender-vLcbQhiB.cjs +0 -3
  120. package/dist/sender-vLcbQhiB.cjs.map +0 -1
  121. package/dist/web-vitals-DM2nvcMJ.cjs +0 -2
  122. package/dist/web-vitals-DM2nvcMJ.cjs.map +0 -1
  123. package/dist/web-vitals-DwWdLBq6.js.map +0 -1
@@ -1,14 +1,14 @@
1
1
  import type { Diagnostics } from "../core/diagnostics";
2
2
  /**
3
3
  * Executes an asynchronous function under a Web Locks API origin-wide lock.
4
- * Falls back to direct execution in environments without Web Locks support.
4
+ * It runs the task directly when the Web Locks API is not available.
5
5
  * @param name Origin-scoped lock identifier.
6
6
  * @param diagnostics Diagnostics reporter.
7
7
  * @param fn Asynchronous task to execute while holding the lock.
8
8
  * @param options Lock acquisition options.
9
- * @param options.skipIfBusy Skips execution if lock is currently held by another context.
10
- * @returns Promise resolving to the task result, or undefined if the lock was held
11
- * and nothing ran. A caller that conflates the two stops rescheduling.
9
+ * @param options.skipIfBusy When true, the task does not run if another context holds the lock.
10
+ * @returns Promise of the task result. It resolves to undefined when another context holds the
11
+ * lock. A caller that reads undefined as a task result stops rescheduling.
12
12
  */
13
13
  export declare function withDrainLock<T>(name: string, diagnostics: Diagnostics, fn: () => Promise<T>, { skipIfBusy }?: {
14
14
  skipIfBusy?: boolean;
@@ -24,17 +24,19 @@ export interface PlatformMetadata {
24
24
  export declare function detectPlatform(diagnostics: Diagnostics): PlatformMetadata;
25
25
  /**
26
26
  * Determines whether the current window is the top-level browsing context.
27
+ * @param diagnostics Diagnostics reporter. It counts a blocked read of window.top.
27
28
  * @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.
28
29
  */
29
- export declare function isTopLevel(): boolean;
30
+ export declare function isTopLevel(diagnostics: Diagnostics): boolean;
30
31
  /**
31
32
  * Retrieves the current document URL without caching.
33
+ * @param diagnostics Diagnostics reporter. It counts a blocked read of location.href.
32
34
  * @returns Current location.href or empty string.
33
35
  */
34
- export declare function currentUrl(): string;
36
+ export declare function currentUrl(diagnostics: Diagnostics): string;
35
37
  /**
36
38
  * Drops the query string and fragment from a URL.
37
- * A string cut, not a URL parse: a relative request target has no base to parse against.
39
+ * It cuts the string and does not parse a URL. A relative request target has no base URL.
38
40
  * @param url Absolute or relative URL.
39
41
  * @returns The URL up to the first "?" or "#".
40
42
  */
@@ -1,3 +1,4 @@
1
+ import type { Diagnostics } from "../core/diagnostics";
1
2
  /** Structural depth and size limits enforced during object sanitization. */
2
3
  export interface SanitizeLimits {
3
4
  /** Maximum recursion depth before truncating nested objects. */
@@ -31,16 +32,18 @@ export interface SanitizeResult {
31
32
  * Sanitizes arbitrary values into JSON-safe structures without throwing.
32
33
  * @param value Raw value to sanitize.
33
34
  * @param limits Configuration limits for depth, count, and character lengths.
35
+ * @param diagnostics Diagnostics reporter. It counts a value that throws during the walk.
34
36
  * @returns JSON-safe sanitized value.
35
37
  */
36
- export declare function sanitize(value: unknown, limits: SanitizeLimits): unknown;
38
+ export declare function sanitize(value: unknown, limits: SanitizeLimits, diagnostics: Diagnostics): unknown;
37
39
  /**
38
40
  * Sanitizes arbitrary values and calculates approximate serialized byte sizes.
39
41
  * @param value Raw value to sanitize.
40
42
  * @param limits Configuration limits.
43
+ * @param diagnostics Diagnostics reporter. It counts a value that throws during the walk.
41
44
  * @returns SanitizeResult containing sanitized value and byte count.
42
45
  */
43
- export declare function sanitizeWithSize(value: unknown, limits: SanitizeLimits): SanitizeResult;
46
+ export declare function sanitizeWithSize(value: unknown, limits: SanitizeLimits, diagnostics: Diagnostics): SanitizeResult;
44
47
  /**
45
48
  * Estimates UTF-8 encoded byte length for a string.
46
49
  * @param value Target string.
@@ -8,8 +8,8 @@ export declare class Sequence {
8
8
  */
9
9
  next(): number;
10
10
  /**
11
- * Resets the sequence counter to zero, for a runtime configured afresh.
12
- * Continuing the count implies continuity with the previous run.
11
+ * Resets the sequence counter to zero when the runtime gets a new configuration.
12
+ * A continued count shows a false link to the previous run.
13
13
  */
14
14
  reset(): void;
15
15
  }
@@ -12,9 +12,9 @@ export interface TraceContext {
12
12
  /** Trigger classification for rotating the ambient trace context. */
13
13
  export type RotateReason = "start" | "interaction" | "navigation" | "explicit" | "maxAge";
14
14
  /**
15
- * Generates a random 32-character hex string conforming to W3C trace ID format.
16
- * Exported for callers starting their own trace. A wrong-width id is dropped by
17
- * the backend without a word.
15
+ * Generates a random 32-character hex string in the W3C trace ID format.
16
+ * Use it to start your own trace. The backend drops an id with the wrong width
17
+ * and reports no error.
18
18
  * @returns 32-character hexadecimal trace ID.
19
19
  */
20
20
  export declare function newTraceId(): string;
@@ -29,11 +29,11 @@ export declare class TraceEngine {
29
29
  private readonly maxAgeMs;
30
30
  private readonly load?;
31
31
  /**
32
- * Active ambient trace context. Instance state, never module state. Two runtimes
33
- * in one document must not share a trace id.
32
+ * Active ambient trace context. The instance keeps this state, not the module. Two
33
+ * runtimes in one document must not share a trace id.
34
34
  */
35
35
  private ambient;
36
- /** The optional peer once loaded. Undefined while it loads, and forever if it is absent. */
36
+ /** The optional peer after it loads. It is undefined while it loads or when it is absent. */
37
37
  private otel;
38
38
  /**
39
39
  * @param diagnostics Diagnostics reporter.
@@ -65,7 +65,8 @@ export declare class TraceEngine {
65
65
  */
66
66
  rotate(_reason: RotateReason): TraceContext;
67
67
  /**
68
- * Generates W3C traceparent headers using registered OpenTelemetry propagators or ambient fallback.
68
+ * Generates W3C traceparent headers with the registered OpenTelemetry propagators.
69
+ * Without a traceparent from OpenTelemetry, it uses the ambient trace.
69
70
  * @returns Header map containing traceparent.
70
71
  */
71
72
  headers(): Record<string, string>;
@@ -0,0 +1,2 @@
1
+ var e=class{ctx;name=`web-vitals`;installed=!1;constructor(e){this.ctx=e}install(){if(this.installed||(this.installed=!0,this.reportNavigationTiming(),this.ctx.once.webVitals))return;let e=this.ctx.config.capture.webVitalsLoader;e?(this.ctx.once.webVitals=!0,this.loadWebVitals(e)):this.ctx.diagnostics.report(`config.invalid`,`capture.webVitals needs capture.webVitalsLoader. LCP, CLS and INP are off. Navigation timing continues.`)}uninstall(){this.installed=!1}async loadWebVitals(e){let t=await this.ctx.diagnostics.guardAsync(`capture.install_failed`,`The library could not load web-vitals.`,e);if(!t){this.ctx.diagnostics.report(`capture.install_failed`,`The web-vitals module is not available. LCP, CLS and INP are off. Navigation timing continues.`);return}let n=(e,t)=>n=>{this.ctx.logger.logMetric(`web_vitals.${e}`,Math.round(n.value*1e3)/1e3,t,`gauge`,{"metric.rating":n.rating,"metric.id":n.id})};t.onLCP(n(`lcp`,`ms`)),t.onCLS(n(`cls`,`1`)),t.onINP(n(`inp`,`ms`)),t.onFCP(n(`fcp`,`ms`)),t.onTTFB(n(`ttfb`,`ms`))}reportNavigationTiming(){this.ctx.once.navigationTiming||(this.ctx.once.navigationTiming=!0,this.ctx.diagnostics.guard(`capture.install_failed`,`The library could not read the navigation timing.`,()=>{let e=performance.getEntriesByType(`navigation`)[0];if(!e)return;let t={"navigation.dns_ms":e.domainLookupEnd-e.domainLookupStart,"navigation.tcp_ms":e.connectEnd-e.connectStart,"navigation.ttfb_ms":e.responseStart-e.requestStart,"navigation.response_ms":e.responseEnd-e.responseStart,"navigation.dom_interactive_ms":e.domInteractive,"navigation.dom_complete_ms":e.domComplete,"navigation.load_ms":e.loadEventEnd};for(let[n,r]of Object.entries(t))Number.isFinite(r)&&r>=0&&this.ctx.logger.logMetric(n,Math.round(r),`ms`,`gauge`,{"navigation.type":e.type})}))}};exports.WebVitalsCapture=e;
2
+ //# sourceMappingURL=web-vitals-B2FYsEAU.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-vitals-B2FYsEAU.cjs","names":["WebVitalsCapture","ctx","loader","module","send","name","metric","unit","nav","metrics","value"],"sources":["../src/capture/web-vitals.ts"],"sourcesContent":["// src/capture/web-vitals.ts\n//\n// Captures browser navigation timing and Core Web Vitals metrics through an optional peer.\n\nimport type { WebVitalsMetric, WebVitalsModule, WebVitalsReporter } from \"../models/config\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Captures browser navigation timing benchmarks and Core Web Vitals. */\nexport class WebVitalsCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"web-vitals\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /**\n * @param ctx Capture context containing configuration, diagnostics, and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Reports navigation timing and starts to load web-vitals. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n\n this.reportNavigationTiming();\n\n if (this.ctx.once.webVitals) {\n return;\n }\n\n // Do not import the peer by name. The Vite dev server fails if the peer is not installed.\n // Do not set once here. A later configure() call with a loader must subscribe.\n const loader = this.ctx.config.capture.webVitalsLoader;\n if (!loader) {\n this.ctx.diagnostics.report(\n \"config.invalid\",\n \"capture.webVitals needs capture.webVitalsLoader. LCP, CLS and INP are off. Navigation timing continues.\",\n );\n return;\n }\n\n // Set the flag before the load, not after. Without this order, two configure() calls\n // in one turn both pass this check and subscribe two times.\n this.ctx.once.webVitals = true;\n\n void this.loadWebVitals(loader);\n }\n\n /**\n * Marks the module as uninstalled. The web-vitals reporters stay subscribed\n * because the package has no unsubscribe. `ctx.once` prevents a second set.\n */\n uninstall(): void {\n this.installed = false;\n }\n\n /**\n * Loads the web-vitals module and registers metric reporters.\n * @param loader Loader that the consumer supplies.\n */\n private async loadWebVitals(loader: () => Promise<WebVitalsModule>): Promise<void> {\n const module = await this.ctx.diagnostics.guardAsync(\n \"capture.install_failed\",\n \"The library could not load web-vitals.\",\n loader,\n );\n\n if (!module) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The web-vitals module is not available. LCP, CLS and INP are off. Navigation timing continues.\",\n );\n return;\n }\n\n const send =\n (name: string, unit: string): WebVitalsReporter =>\n (metric: WebVitalsMetric): void => {\n this.ctx.logger.logMetric(\n `web_vitals.${name}`,\n // Keep three decimals. CLS is a small fraction. An integer value\n // reports each layout shift as zero.\n Math.round(metric.value * 1000) / 1000,\n unit,\n \"gauge\",\n { \"metric.rating\": metric.rating, \"metric.id\": metric.id },\n );\n };\n\n module.onLCP(send(\"lcp\", \"ms\"));\n module.onCLS(send(\"cls\", \"1\"));\n module.onINP(send(\"inp\", \"ms\"));\n module.onFCP(send(\"fcp\", \"ms\"));\n module.onTTFB(send(\"ttfb\", \"ms\"));\n }\n\n /** Extracts and logs PerformanceNavigationTiming benchmarks one time for each document. */\n private reportNavigationTiming(): void {\n // The entry describes the one navigation of this document. A second report after a\n // reconfigure duplicates the seven metrics.\n if (this.ctx.once.navigationTiming) {\n return;\n }\n this.ctx.once.navigationTiming = true;\n\n this.ctx.diagnostics.guard(\n \"capture.install_failed\",\n \"The library could not read the navigation timing.\",\n () => {\n const nav = performance.getEntriesByType(\"navigation\")[0] as\n PerformanceNavigationTiming | undefined;\n if (!nav) {\n return;\n }\n\n const metrics: Record<string, number> = {\n \"navigation.dns_ms\": nav.domainLookupEnd - nav.domainLookupStart,\n \"navigation.tcp_ms\": nav.connectEnd - nav.connectStart,\n \"navigation.ttfb_ms\": nav.responseStart - nav.requestStart,\n \"navigation.response_ms\": nav.responseEnd - nav.responseStart,\n \"navigation.dom_interactive_ms\": nav.domInteractive,\n \"navigation.dom_complete_ms\": nav.domComplete,\n \"navigation.load_ms\": nav.loadEventEnd,\n };\n\n for (const [name, value] of Object.entries(metrics)) {\n // Filters unrecorded or negative timings to avoid false zero readings.\n if (Number.isFinite(value) && value >= 0) {\n this.ctx.logger.logMetric(name, Math.round(value), \"ms\", \"gauge\", {\n \"navigation.type\": nav.type,\n });\n }\n }\n },\n );\n }\n}\n"],"mappings":"AAQA,IAAaA,EAAb,KAAiD,CAUlB,IAR7B,KAAgB,aAGhB,UAAoB,GAKpB,YAAY,EAAsC,CAArB,KAAA,IAAAC,CAAsB,CAGnD,SAAgB,CAQd,GAPI,KAAK,YAGT,KAAK,UAAY,GAEjB,KAAK,uBAAuB,EAExB,KAAK,IAAI,KAAK,WAChB,OAKF,IAAMC,EAAS,KAAK,IAAI,OAAO,QAAQ,gBAClCA,GAUL,KAAK,IAAI,KAAK,UAAY,GAE1B,KAAU,cAAcA,CAAM,GAX5B,KAAK,IAAI,YAAY,OACnB,iBACA,yGACF,CASJ,CAMA,WAAkB,CAChB,KAAK,UAAY,EACnB,CAMA,MAAc,cAAc,EAAuD,CACjF,IAAMC,EAAS,MAAM,KAAK,IAAI,YAAY,WACxC,yBACA,yCACAD,CACF,EAEA,GAAI,CAACC,EAAQ,CACX,KAAK,IAAI,YAAY,OACnB,yBACA,gGACF,EACA,MACF,CAEA,IAAMC,GACH,EAAc,IACd,GAAkC,CACjC,KAAK,IAAI,OAAO,UACd,cAAcC,IAGd,KAAK,MAAMC,EAAO,MAAQ,GAAI,EAAI,IAClCC,EACA,QACA,CAAE,gBAAiBD,EAAO,OAAQ,YAAaA,EAAO,EAAG,CAC3D,CACF,EAEFH,EAAO,MAAMC,EAAK,MAAO,IAAI,CAAC,EAC9BD,EAAO,MAAMC,EAAK,MAAO,GAAG,CAAC,EAC7BD,EAAO,MAAMC,EAAK,MAAO,IAAI,CAAC,EAC9BD,EAAO,MAAMC,EAAK,MAAO,IAAI,CAAC,EAC9BD,EAAO,OAAOC,EAAK,OAAQ,IAAI,CAAC,CAClC,CAGA,wBAAuC,CAGjC,KAAK,IAAI,KAAK,mBAGlB,KAAK,IAAI,KAAK,iBAAmB,GAEjC,KAAK,IAAI,YAAY,MACnB,yBACA,wDACM,CACJ,IAAMI,EAAM,YAAY,iBAAiB,YAAY,CAAC,CAAC,GAEvD,GAAI,CAACA,EACH,OAGF,IAAMC,EAAkC,CACtC,oBAAqBD,EAAI,gBAAkBA,EAAI,kBAC/C,oBAAqBA,EAAI,WAAaA,EAAI,aAC1C,qBAAsBA,EAAI,cAAgBA,EAAI,aAC9C,yBAA0BA,EAAI,YAAcA,EAAI,cAChD,gCAAiCA,EAAI,eACrC,6BAA8BA,EAAI,YAClC,qBAAsBA,EAAI,YAC5B,EAEA,IAAK,GAAM,CAACH,EAAMK,KAAU,OAAO,QAAQD,CAAO,EAE5C,OAAO,SAASC,CAAK,GAAKA,GAAS,GACrC,KAAK,IAAI,OAAO,UAAUL,EAAM,KAAK,MAAMK,CAAK,EAAG,KAAM,QAAS,CAChE,kBAAmBF,EAAI,IACzB,CAAC,CAGP,CACF,EACF,CACF"}
@@ -15,9 +15,9 @@ var e = class {
15
15
  this.installed = !1;
16
16
  }
17
17
  async loadWebVitals(e) {
18
- let t = await this.ctx.diagnostics.guardAsync("capture.install_failed", "loading web-vitals", e);
18
+ let t = await this.ctx.diagnostics.guardAsync("capture.install_failed", "The library could not load web-vitals.", e);
19
19
  if (!t) {
20
- this.ctx.diagnostics.report("capture.install_failed", "web-vitals is not available, so LCP, CLS and INP are unavailable. Navigation timing still works.");
20
+ this.ctx.diagnostics.report("capture.install_failed", "The web-vitals module is not available. LCP, CLS and INP are off. Navigation timing continues.");
21
21
  return;
22
22
  }
23
23
  let n = (e, t) => (n) => {
@@ -29,7 +29,7 @@ var e = class {
29
29
  t.onLCP(n("lcp", "ms")), t.onCLS(n("cls", "1")), t.onINP(n("inp", "ms")), t.onFCP(n("fcp", "ms")), t.onTTFB(n("ttfb", "ms"));
30
30
  }
31
31
  reportNavigationTiming() {
32
- this.ctx.once.navigationTiming || (this.ctx.once.navigationTiming = !0, this.ctx.diagnostics.guard("capture.install_failed", "reading navigation timing", () => {
32
+ this.ctx.once.navigationTiming || (this.ctx.once.navigationTiming = !0, this.ctx.diagnostics.guard("capture.install_failed", "The library could not read the navigation timing.", () => {
33
33
  let e = performance.getEntriesByType("navigation")[0];
34
34
  if (!e) return;
35
35
  let t = {
@@ -48,4 +48,4 @@ var e = class {
48
48
  //#endregion
49
49
  export { e as WebVitalsCapture };
50
50
 
51
- //# sourceMappingURL=web-vitals-DwWdLBq6.js.map
51
+ //# sourceMappingURL=web-vitals-DHZ0yA_H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-vitals-DHZ0yA_H.js","names":["WebVitalsCapture","ctx","loader","module","send","name","metric","unit","nav","metrics","value"],"sources":["../src/capture/web-vitals.ts"],"sourcesContent":["// src/capture/web-vitals.ts\n//\n// Captures browser navigation timing and Core Web Vitals metrics through an optional peer.\n\nimport type { WebVitalsMetric, WebVitalsModule, WebVitalsReporter } from \"../models/config\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Captures browser navigation timing benchmarks and Core Web Vitals. */\nexport class WebVitalsCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"web-vitals\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /**\n * @param ctx Capture context containing configuration, diagnostics, and logger.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Reports navigation timing and starts to load web-vitals. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n\n this.reportNavigationTiming();\n\n if (this.ctx.once.webVitals) {\n return;\n }\n\n // Do not import the peer by name. The Vite dev server fails if the peer is not installed.\n // Do not set once here. A later configure() call with a loader must subscribe.\n const loader = this.ctx.config.capture.webVitalsLoader;\n if (!loader) {\n this.ctx.diagnostics.report(\n \"config.invalid\",\n \"capture.webVitals needs capture.webVitalsLoader. LCP, CLS and INP are off. Navigation timing continues.\",\n );\n return;\n }\n\n // Set the flag before the load, not after. Without this order, two configure() calls\n // in one turn both pass this check and subscribe two times.\n this.ctx.once.webVitals = true;\n\n void this.loadWebVitals(loader);\n }\n\n /**\n * Marks the module as uninstalled. The web-vitals reporters stay subscribed\n * because the package has no unsubscribe. `ctx.once` prevents a second set.\n */\n uninstall(): void {\n this.installed = false;\n }\n\n /**\n * Loads the web-vitals module and registers metric reporters.\n * @param loader Loader that the consumer supplies.\n */\n private async loadWebVitals(loader: () => Promise<WebVitalsModule>): Promise<void> {\n const module = await this.ctx.diagnostics.guardAsync(\n \"capture.install_failed\",\n \"The library could not load web-vitals.\",\n loader,\n );\n\n if (!module) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The web-vitals module is not available. LCP, CLS and INP are off. Navigation timing continues.\",\n );\n return;\n }\n\n const send =\n (name: string, unit: string): WebVitalsReporter =>\n (metric: WebVitalsMetric): void => {\n this.ctx.logger.logMetric(\n `web_vitals.${name}`,\n // Keep three decimals. CLS is a small fraction. An integer value\n // reports each layout shift as zero.\n Math.round(metric.value * 1000) / 1000,\n unit,\n \"gauge\",\n { \"metric.rating\": metric.rating, \"metric.id\": metric.id },\n );\n };\n\n module.onLCP(send(\"lcp\", \"ms\"));\n module.onCLS(send(\"cls\", \"1\"));\n module.onINP(send(\"inp\", \"ms\"));\n module.onFCP(send(\"fcp\", \"ms\"));\n module.onTTFB(send(\"ttfb\", \"ms\"));\n }\n\n /** Extracts and logs PerformanceNavigationTiming benchmarks one time for each document. */\n private reportNavigationTiming(): void {\n // The entry describes the one navigation of this document. A second report after a\n // reconfigure duplicates the seven metrics.\n if (this.ctx.once.navigationTiming) {\n return;\n }\n this.ctx.once.navigationTiming = true;\n\n this.ctx.diagnostics.guard(\n \"capture.install_failed\",\n \"The library could not read the navigation timing.\",\n () => {\n const nav = performance.getEntriesByType(\"navigation\")[0] as\n PerformanceNavigationTiming | undefined;\n if (!nav) {\n return;\n }\n\n const metrics: Record<string, number> = {\n \"navigation.dns_ms\": nav.domainLookupEnd - nav.domainLookupStart,\n \"navigation.tcp_ms\": nav.connectEnd - nav.connectStart,\n \"navigation.ttfb_ms\": nav.responseStart - nav.requestStart,\n \"navigation.response_ms\": nav.responseEnd - nav.responseStart,\n \"navigation.dom_interactive_ms\": nav.domInteractive,\n \"navigation.dom_complete_ms\": nav.domComplete,\n \"navigation.load_ms\": nav.loadEventEnd,\n };\n\n for (const [name, value] of Object.entries(metrics)) {\n // Filters unrecorded or negative timings to avoid false zero readings.\n if (Number.isFinite(value) && value >= 0) {\n this.ctx.logger.logMetric(name, Math.round(value), \"ms\", \"gauge\", {\n \"navigation.type\": nav.type,\n });\n }\n }\n },\n );\n }\n}\n"],"mappings":";AAQA,IAAaA,IAAb,MAAiD;CAUlB;CAR7B,OAAgB;CAGhB,YAAoB;CAKpB,YAAY,GAAsC;EAArB,KAAA,MAAAC;CAAsB;CAGnD,UAAgB;EAQd,IAPI,KAAK,cAGT,KAAK,YAAY,IAEjB,KAAK,uBAAuB,GAExB,KAAK,IAAI,KAAK,YAChB;EAKF,IAAMC,IAAS,KAAK,IAAI,OAAO,QAAQ;EACvC,AAAKA,KAUL,KAAK,IAAI,KAAK,YAAY,IAE1B,KAAU,cAAcA,CAAM,KAX5B,KAAK,IAAI,YAAY,OACnB,kBACA,yGACF;CASJ;CAMA,YAAkB;EAChB,KAAK,YAAY;CACnB;CAMA,MAAc,cAAc,GAAuD;EACjF,IAAMC,IAAS,MAAM,KAAK,IAAI,YAAY,WACxC,0BACA,0CACAD,CACF;EAEA,IAAI,CAACC,GAAQ;GACX,KAAK,IAAI,YAAY,OACnB,0BACA,gGACF;GACA;EACF;EAEA,IAAMC,KACH,GAAc,OACd,MAAkC;GACjC,KAAK,IAAI,OAAO,UACd,cAAcC,KAGd,KAAK,MAAMC,EAAO,QAAQ,GAAI,IAAI,KAClCC,GACA,SACA;IAAE,iBAAiBD,EAAO;IAAQ,aAAaA,EAAO;GAAG,CAC3D;EACF;EAMF,AAJAH,EAAO,MAAMC,EAAK,OAAO,IAAI,CAAC,GAC9BD,EAAO,MAAMC,EAAK,OAAO,GAAG,CAAC,GAC7BD,EAAO,MAAMC,EAAK,OAAO,IAAI,CAAC,GAC9BD,EAAO,MAAMC,EAAK,OAAO,IAAI,CAAC,GAC9BD,EAAO,OAAOC,EAAK,QAAQ,IAAI,CAAC;CAClC;CAGA,yBAAuC;EAGrC,AAAI,KAAK,IAAI,KAAK,qBAGlB,KAAK,IAAI,KAAK,mBAAmB,IAEjC,KAAK,IAAI,YAAY,MACnB,0BACA,2DACM;GACJ,IAAMI,IAAM,YAAY,iBAAiB,YAAY,CAAC,CAAC;GAEvD,IAAI,CAACA,GACH;GAGF,IAAMC,IAAkC;IACtC,qBAAqBD,EAAI,kBAAkBA,EAAI;IAC/C,qBAAqBA,EAAI,aAAaA,EAAI;IAC1C,sBAAsBA,EAAI,gBAAgBA,EAAI;IAC9C,0BAA0BA,EAAI,cAAcA,EAAI;IAChD,iCAAiCA,EAAI;IACrC,8BAA8BA,EAAI;IAClC,sBAAsBA,EAAI;GAC5B;GAEA,KAAK,IAAM,CAACH,GAAMK,MAAU,OAAO,QAAQD,CAAO,GAEhD,AAAI,OAAO,SAASC,CAAK,KAAKA,KAAS,KACrC,KAAK,IAAI,OAAO,UAAUL,GAAM,KAAK,MAAMK,CAAK,GAAG,MAAM,SAAS,EAChE,mBAAmBF,EAAI,KACzB,CAAC;EAGP,CACF;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utk09/ui-observability",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "UI observability and logging for browser, OpenFin and webview applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -75,7 +75,9 @@
75
75
  "typecheck": "tsc --noEmit",
76
76
  "check:version": "node tools/check-version-sync.mjs",
77
77
  "check:peers": "node tools/check-peer-imports.mjs",
78
- "verify": "npm run format:check && npm run check:version && npm run typecheck && npm run lint && npm run build && npm run check:peers && npm run test:coverage",
78
+ "check:size": "node tools/check-size.mjs",
79
+ "check:dev": "node tools/check-dev-server.mjs",
80
+ "verify": "npm run format:check && npm run check:version && npm run typecheck && npm run lint && npm run build && npm run check:peers && npm run check:size && npm run check:dev && npm run test:coverage",
79
81
  "prepublishOnly": "npm run verify"
80
82
  },
81
83
  "peerDependencies": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"bus-D3OO0OcL.js","names":["RUNTIME_GLOBAL_KEY","BUS_PROTOCOL","BUS_CHANNEL_NAME","BUS_HANDSHAKE_TIMEOUT_MS","unrefTimer","envelope","message","unwrap","data","wrapper","RUNTIME_KEY","createDirectLink","host","target","open","diagnostics","receive","createParentLink","onMessage","event","createChildrenLink","trusted","trustedOrigins","sources","source","origin","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"],"sources":["../src/models/bus.ts","../src/bus/links.ts","../src/bus/bus.ts"],"sourcesContent":["// src/models/bus.ts\n//\n// Wire protocol types, message definitions, and envelope encoding for cross-realm bus communication.\n\nimport { BUS_PROTOCOL } from \"../constants\";\nimport type { Journey } from \"../core/journey\";\nimport type { LogRecord } from \"./log-record\";\n\n/** Delivery role indicating whether this context sends records directly or forwards upstream. */\nexport type BusRole = \"sender\" | \"forwarder\";\n\n/**\n * Transport channel classification used to route incoming and outgoing bus\n * messages. If `receive` switches on the message alone and cannot tell the\n * channels apart, a same-origin iframe 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`; otherwise `\"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 booting forwarder. */\n | { t: \"hello\"; from: string; tabId: string }\n /**\n * Handshake response acknowledging an upstream owner relationship. Addressed\n * through `to`: a welcome published over InterApplicationBus reaches every\n * subscriber, so an unaddressed one lets three waiting views each conclude\n * it has found an owner of 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 /** Broadcast update announcing a new or ended journey state. */\n | { t: \"journey\"; from: string; journey: Journey | null }\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\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 protocol tags and unpacks raw payloads into bus messages. A\n * document receives `message` events from every embedded thing on the page,\n * including analytics tags, video players and extensions. Without the tag\n * check a video player's message is parsed 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 { 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\";\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 exposed on global symbol by same-origin parent runtimes. */\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/**\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 // Catches errors thrown by parent runtime to protect child logging calls.\n diagnostics.guard(\"bus.send_failed\", \"direct call into the parent runtime\", () => {\n target.busAccept(message, receive);\n });\n },\n close() {\n open = false;\n },\n };\n}\n\n/**\n * Creates a postMessage link to the parent window.\n * @param receive Callback for incoming parent messages.\n * @param diagnostics Diagnostics reporter.\n * @returns Link to parent window, or null if running in top-level window.\n */\nexport function createParentLink(receive: Receive, diagnostics: Diagnostics): Link | null {\n if (typeof window === \"undefined\" || window.parent === window) {\n return null;\n }\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n // The parent is trusted by construction: this context chose to talk to it.\n if (message && event.source === window.parent) {\n receive(message, { link: \"parent\", origin: event.origin });\n }\n };\n addEventListener(\"message\", onMessage);\n\n return {\n kind: \"parent\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"postMessage to parent\", () => {\n // \"*\" is fine outbound: the payload is this context's own records,\n // and the parent already receives them another way. Inbound trust\n // works differently; see createChildrenLink.\n window.parent.postMessage(envelope(message), \"*\");\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 const trusted = new Set([window.location.origin, ...trustedOrigins]);\n // Origin per source: a child that navigates must not receive the previous origin's ids.\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(\n \"bus.untrusted_origin\",\n `ignored a bus message from ${event.origin}. Add it to bus.trustedOrigins if it is yours.`,\n { origin: event.origin, type: message.t },\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(\"bus.send_failed\", \"postMessage to child\", () => {\n // Targets the origin the child last spoke from. The browser drops the\n // message if the child has since navigated elsewhere.\n target.postMessage(envelope(message), origin);\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 \"opening 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\", \"BroadcastChannel.postMessage\", () => {\n channel.postMessage(envelope(message));\n });\n },\n close() {\n diagnostics.guard(\"bus.send_failed\", \"closing BroadcastChannel\", () => {\n channel.close();\n });\n },\n };\n}\n\n/** Structural interface for OpenFin InterApplicationBus operations. */\ninterface FinIab {\n /**\n * Publishes a message to all topic subscribers.\n * @param topic Topic name.\n * @param message Message payload.\n */\n publish(topic: string, message: unknown): Promise<void>;\n\n /**\n * Subscribes a listener to a topic for matching application identities.\n * @param identity Target application identity.\n * @param topic Topic name.\n * @param listener Message callback.\n */\n subscribe(\n identity: { uuid: string },\n topic: string,\n listener: (message: unknown) => void,\n ): Promise<void>;\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 fin = (globalThis as { fin?: { InterApplicationBus?: FinIab } }).fin;\n const iab = fin?.InterApplicationBus;\n if (!iab) {\n return null;\n }\n if (!appUuid) {\n // publish() reaches every subscriber on the runtime. Without an identity to\n // scope it, opening the link would share this app's bus with every other.\n diagnostics.report(\n \"openfin.unavailable\",\n \"no OpenFin application uuid, so the InterApplicationBus link stays closed\",\n );\n return null;\n }\n\n // Both halves carry the uuid: the topic keeps this app's messages away from\n // other applications, the subscriber identity rejects theirs.\n const scoped = `${topic}.${appUuid}`;\n\n void diagnostics.guardAsync(\"bus.send_failed\", \"InterApplicationBus.subscribe\", () =>\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(\"bus.send_failed\", \"InterApplicationBus.publish\", () =>\n iab.publish(scoped, envelope(message)),\n );\n },\n close() {\n // OpenFin automatically cleans up subscriptions on context teardown.\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\", \"worker postMessage\", () => {\n send(envelope(message));\n });\n },\n close() {\n // Worker scope listeners terminate with the worker lifecycle.\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 // Activates MessagePort message delivery if supported.\n worker.start?.();\n\n return {\n kind: \"worker\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"postMessage to a worker\", () => {\n worker.postMessage(envelope(message));\n });\n },\n close() {\n worker.removeEventListener(\"message\", onMessage);\n },\n };\n}\n","// src/bus/bus.ts\n//\n// Manages cross-realm bus role resolution and message routing.\n\nimport {\n BUS_CHANNEL_NAME,\n BUS_HANDSHAKE_TIMEOUT_MS,\n BUS_MAX_HANDSHAKE_ATTEMPTS,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { Journey } from \"../core/journey\";\nimport type { BusMessage, BusRole, LinkKind, MessageSource } from \"../models/bus\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogRecord } from \"../models/log-record\";\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 /** Max time to wait 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/** Handshake timing in force. 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 for inquiring child contexts. */\n onJourneyRequest: () => Journey | null;\n /** Invoked when a tab identifier collision is detected across windows. */\n onTabConflict: () => void;\n}\n\n/** Link types that a sender context may claim ownership over during handshakes. */\nconst OWNED: readonly LinkKind[] = [\"children\", \"direct\", \"worker\"];\n\n/** Structural shape of fin.me identity metadata. */\ninterface OpenFinMe {\n isView?: boolean;\n identity?: { uuid?: string; name?: string };\n}\n\n/** Coordinates cross-realm communication, role resolution, and message dispatch. */\nexport class Bus {\n /** Current bus role. Defaults to \"sender\". */\n private role: BusRole = \"sender\";\n /** Upstream forwarding link, or null when acting as sender. */\n private upstream: Link | null = null;\n /** Open control plane links. */\n private readonly links: Link[] = [];\n /** Shared OpenFin InterApplicationBus link instance. */\n private openFinLink: Link | null = null;\n /** Indicates whether this context is the OpenFin platform provider. */\n private isOpenFinProvider = false;\n /** Indicates whether role resolution has completed. */\n private resolved = false;\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 /** Returns whether role resolution has completed. */\n isResolved(): boolean {\n return this.resolved;\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 this.resolved = true;\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\" but there is no owner to forward to. Records will be dropped.',\n );\n }\n }\n this.resolved = true;\n this.announce();\n return this.role;\n }\n\n this.openControlLinks();\n\n // Direct synchronous attachment for same-origin parents.\n const direct = createDirectLink(this.receive, this.diagnostics);\n if (direct) {\n this.role = \"forwarder\";\n this.upstream = direct;\n this.resolved = true;\n this.diagnostics.report(\n \"bus.role_resolved\",\n \"attached directly to the same-origin parent runtime\",\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.resolved = true;\n this.diagnostics.report(\"bus.role_resolved\", \"no owner to forward to, sending directly\", {\n role: \"sender\",\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, promoting to sender`,\n { via: candidate.kind, crossOrigin: this.isCrossOriginFrame() },\n );\n }\n this.diagnostics.report(\"bus.role_resolved\", `role is ${this.role}`, {\n role: this.role,\n via: welcomed ? candidate.kind : \"none\",\n });\n\n this.resolved = true;\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) {\n reply({ t: \"journey\", from: this.contextId, journey: current }, source);\n }\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 * Broadcasts journey state changes to all connected links.\n * @param journey Active journey or null if ended.\n */\n broadcastJourney(journey: Journey | null): void {\n this.post({ t: \"journey\", from: this.contextId, journey });\n }\n\n /** Closes all open links and clears internal state. */\n destroy(): void {\n for (const link of this.allLinks()) {\n link.close();\n }\n this.links.length = 0;\n this.upstream = 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 /** Broadcasts a message across all open links. */\n private post(message: BusMessage): void {\n for (const link of this.allLinks()) {\n link.post(message);\n }\n }\n\n /** Sends a message exclusively over links matching the specified 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 /** 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 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 this.handlers.onJourney(message.journey);\n break;\n\n case \"journey?\": {\n const current = this.handlers.onJourneyRequest();\n if (current) {\n this.postOver(source.link, {\n t: \"journey\",\n from: this.contextId,\n journey: current,\n });\n }\n break;\n }\n\n case \"tab\":\n // Collisions only apply to distinct contexts sharing the broadcast\n // channel. The id comparison picks one side of the pair: without it\n // both colliding contexts report the conflict and both 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 whether records from a link can go upstream. Posted back on the link\n * they arrived on, the records echo to their sender. A direct link is an\n * exception: it is one call into one parent, so two direct links in a chain are\n * different links.\n * @param link Kind of the link the records arrived on.\n * @returns True if the relay is safe.\n */\n private canRelay(link: LinkKind): boolean {\n return link === \"direct\" || link !== this.upstream?.kind;\n }\n\n /** Returns whether this context can accept ownership over 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 /** Resolves whether this context represents 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 = (globalThis as { fin?: { me?: OpenFinMe } }).fin?.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 whether the parent window is inaccessible due to cross-origin boundaries. */\n private isCrossOriginFrame(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) {\n return false;\n }\n try {\n // The probe: a cross-origin parent throws on this read. A bare read fails lint.\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.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 // Declared below finish, which reads it: nothing can call finish until\n // the timer exists, because the welcome arrives through the post below.\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.post({ t: \"journey?\", from: this.contextId });\n }\n}\n"],"mappings":";;;AAyEA,SAAgBK,EAAS,GAAkC;CACzD,OAAO;EAAE,GAAGJ;EAAc,GAAGK;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,IAAUG,EAAQ;CAKxB,OAJI,OAAOH,EAAQ,KAAM,WAIlBA,IAHE;AAIX;;;AC7BA,IAAMI,IAAc,OAAO,IAAIV,CAAkB;AAQjD,SAAgBW,EAAiB,GAAkB,GAAuC;CACxF,IAAI,OAAO,SAAW,OAAe,OAAO,WAAW,QACrD,OAAO;CAGT,IAAIC;CACJ,IAAI;EAEF,IADqB,OAAO,OACRF;CACtB,QAAQ;EAEN,OAAO;CACT;CACA,IAAI,OAAOE,GAAM,aAAc,YAC7B,OAAO;CAGT,IAAMC,IAASD,GACXE,IAAO;CAEX,OAAO;EACL,MAAM;EACN,KAAK,GAAS;GACZ,AAAKA,KAKLC,EAAY,MAAM,mBAAmB,6CAA6C;IAChF,EAAO,UAAUT,GAASU,CAAO;GACnC,CAAC;EACH;EACA,QAAQ;GACN,IAAO;EACT;CACF;AACF;AAQA,SAAgBC,EAAiB,GAAkB,GAAuC;CACxF,IAAI,OAAO,SAAW,OAAe,OAAO,WAAW,QACrD,OAAO;CAGT,IAAMC,KAAa,MAA8B;EAC/C,IAAMZ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E2D,EAAK,KAAK,kBAAkB,CAAC;CAEjC;CAGA,oBAAyC;EAOvC,OANA,KAAK,gBAAgB/B,EACnB5B,GACA,KAAK,SAAS,aACd,KAAK,SACL,KAAK,WACP,GACO,KAAK;CACd;CAOA,UAAkB,GAAmC;EACnD,OAAO,IAAI,SAAS,MAAY;GAC9B,IAAI4D,IAAU,IAERC,KAAU,MAA0B;IACxC,AAAID,MAGJ,IAAU,IACV,KAAK,kBAAkB,MACvB,aAAaE,CAAK,GAClBC,EAAQC,CAAM;GAChB;GAEA,KAAK,kBAAkB;IAAE,MAAMd,EAAU;IAAM,QAAQW;GAAO;GAG9D,IAAMC,IAAQ,iBAAiB;IAC7B,EAAO,EAAK;GACd,GAAG,KAAK,iBAAiB,SAAS;GAElC,AADA5D,EAAW4D,CAAK,GAChBZ,EAAU,KAAK;IAAE,GAAG;IAAS,MAAM,KAAK;IAAW,OAAO,KAAK;GAAM,CAAC;EACxE,CAAC;CACH;CAGA,WAAyB;EAMvB,AALA,KAAK,SAAS,aAAa;GACzB,GAAG;GACH,MAAM,KAAK;GACX,OAAO,KAAK;EACd,CAAC,GACD,KAAK,KAAK;GAAE,GAAG;GAAY,MAAM,KAAK;EAAU,CAAC;CACnD;AACF"}
@@ -1,2 +0,0 @@
1
- const e=require("./constants-DZH04585.cjs"),t=require("./unref-CU9Nyz_9.cjs");function n(t){return{p:e.S,m:t}}function r(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 i=Symbol.for(e.Rt);function a(e,t){if(typeof window>`u`||window.parent===window)return null;let n;try{n=window.parent[i]}catch{return null}if(typeof n?.busAccept!=`function`)return null;let r=n,a=!0;return{kind:`direct`,post(n){a&&t.guard(`bus.send_failed`,`direct call into the parent runtime`,()=>{r.busAccept(n,e)})},close(){a=!1}}}function o(e,t){if(typeof window>`u`||window.parent===window)return null;let i=t=>{let n=r(t.data);n&&t.source===window.parent&&e(n,{link:`parent`,origin:t.origin})};return addEventListener(`message`,i),{kind:`parent`,post(e){t.guard(`bus.send_failed`,`postMessage to parent`,()=>{window.parent.postMessage(n(e),`*`)})},close(){removeEventListener(`message`,i)}}}function s(e,t,i){if(typeof window>`u`)return null;let a=new Set([window.location.origin,...t]),o=new Map,s=t=>{let n=r(t.data);n&&(a.has(t.origin)?(t.source&&o.set(t.source,t.origin),e(n,{link:`children`,origin:t.origin})):i.report(`bus.untrusted_origin`,`ignored a bus message from ${t.origin}. Add it to bus.trustedOrigins if it is yours.`,{origin:t.origin,type:n.t}))};return addEventListener(`message`,s),{kind:`children`,post(e){for(let[t,r]of o){let a=t;a.closed?o.delete(t):i.guard(`bus.send_failed`,`postMessage to child`,()=>{a.postMessage(n(e),r)})}},close(){removeEventListener(`message`,s),o.clear()}}}function c(e,t,i){let a=globalThis.BroadcastChannel;if(a===void 0)return null;let o=i.guard(`bus.send_failed`,`opening BroadcastChannel`,()=>new a(e));return o?(o.onmessage=e=>{let n=r(e.data);n&&t(n,{link:`broadcast`,origin:`same-origin`})},{kind:`broadcast`,post(e){i.guard(`bus.send_failed`,`BroadcastChannel.postMessage`,()=>{o.postMessage(n(e))})},close(){i.guard(`bus.send_failed`,`closing BroadcastChannel`,()=>{o.close()})}}):null}function l(e,t,i,a){let o=globalThis.fin?.InterApplicationBus;if(!o)return null;if(!t)return a.report(`openfin.unavailable`,`no OpenFin application uuid, so the InterApplicationBus link stays closed`),null;let s=`${e}.${t}`;return a.guardAsync(`bus.send_failed`,`InterApplicationBus.subscribe`,()=>o.subscribe({uuid:t},s,e=>{let t=r(e);t&&i(t,{link:`openfin`,origin:`openfin`})})),{kind:`openfin`,post(e){a.guardAsync(`bus.send_failed`,`InterApplicationBus.publish`,()=>o.publish(s,n(e)))},close(){}}}function u(e,t){let i=globalThis,a=i.postMessage;return i.WorkerGlobalScope===void 0||!a?null:(i.addEventListener?.(`message`,t=>{let n=r(t.data);n&&e(n,{link:`owner`,origin:`same-origin`})}),{kind:`owner`,post(e){t.guard(`bus.send_failed`,`worker postMessage`,()=>{a(n(e))})},close(){}})}function d(e,t,i){let a=e=>{let n=r(e.data);n&&t(n,{link:`worker`,origin:`same-origin`})};return e.addEventListener(`message`,a),e.start?.(),{kind:`worker`,post(t){i.guard(`bus.send_failed`,`postMessage to a worker`,()=>{e.postMessage(n(t))})},close(){e.removeEventListener(`message`,a)}}}var f={timeoutMs:e.x,maxAttempts:3},p=[`children`,`direct`,`worker`],m=class{config;diagnostics;platform;contextId;tabId;handlers;handshakeOptions;role=`sender`;upstream=null;links=[];openFinLink=null;isOpenFinProvider=!1;resolved=!1;awaitingWelcome=null;constructor(e,t,n,r,i,a,o=f){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}isResolved(){return this.resolved}async start(){let{bus:e}=this.config;if(e.mode===`off`)return this.role=`sender`,this.resolved=!0,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" but there is no owner to forward to. Records will be dropped.`)),this.resolved=!0,this.announce(),this.role;this.openControlLinks();let t=a(this.receive,this.diagnostics);if(t)return this.role=`forwarder`,this.upstream=t,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`attached directly to the same-origin parent runtime`,{role:`forwarder`,via:`direct`}),this.announce(),this.role;let n=this.candidateUpstream();if(!n)return this.role=`sender`,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`no owner to forward to, sending directly`,{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, promoting to sender`,{via:n.kind,crossOrigin:this.isCrossOriginFrame()})),this.diagnostics.report(`bus.role_resolved`,`role is ${this.role}`,{role:this.role,via:i?n.kind:`none`}),this.resolved=!0,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 e=this.handlers.onJourneyRequest();e&&t({t:`journey`,from:this.contextId,journey:e},n)}else this.receive(e,n)}attachWorker(e){this.links.push(d(e,this.receive,this.diagnostics))}broadcastJourney(e){this.post({t:`journey`,from:this.contextId,journey:e})}destroy(){for(let e of this.allLinks())e.close();this.links.length=0,this.upstream=null,this.openFinLink=null}allLinks(){return!this.upstream||this.links.includes(this.upstream)?this.links:[...this.links,this.upstream]}post(e){for(let t of this.allLinks())t.post(e)}postOver(e,t){for(let n of this.allLinks())n.kind===e&&n.post(t)}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.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.handlers.onJourney(e.journey);break;case`journey?`:{let e=this.handlers.onJourneyRequest();e&&this.postOver(t.link,{t:`journey`,from:this.contextId,journey:e});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:p.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=globalThis.fin?.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?u(this.receive,this.diagnostics):this.platform.isTopLevelDocument?this.platform.platform===`openfin`&&!this.isOpenFinProvider?this.ensureOpenFinLink():null:o(this.receive,this.diagnostics)}openControlLinks(){let t=e=>{e&&this.links.push(e)};this.platform.isTopLevelDocument&&(t(s(this.receive,this.config.bus.trustedOrigins,this.diagnostics)),t(c(e.b,this.receive,this.diagnostics))),(this.platform.platform===`openfin`||this.platform.platform===`openfin_web`)&&t(this.ensureOpenFinLink())}ensureOpenFinLink(){return this.openFinLink??=l(e.b,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.t(a),e.post({t:`hello`,from:this.contextId,tabId:this.tabId})})}announce(){this.postOver(`broadcast`,{t:`tab`,from:this.contextId,tabId:this.tabId}),this.post({t:`journey?`,from:this.contextId})}};exports.Bus=m;
2
- //# sourceMappingURL=bus-OdRJVUzr.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bus-OdRJVUzr.cjs","names":["BUS_PROTOCOL","RUNTIME_GLOBAL_KEY","BUS_HANDSHAKE_TIMEOUT_MS","BUS_CHANNEL_NAME","require_constants","require_unref","envelope","message","unwrap","data","wrapper","RUNTIME_KEY","createDirectLink","host","target","open","diagnostics","receive","createParentLink","onMessage","event","createChildrenLink","trusted","trustedOrigins","sources","source","origin","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"],"sources":["../src/models/bus.ts","../src/bus/links.ts","../src/bus/bus.ts"],"sourcesContent":["// src/models/bus.ts\n//\n// Wire protocol types, message definitions, and envelope encoding for cross-realm bus communication.\n\nimport { BUS_PROTOCOL } from \"../constants\";\nimport type { Journey } from \"../core/journey\";\nimport type { LogRecord } from \"./log-record\";\n\n/** Delivery role indicating whether this context sends records directly or forwards upstream. */\nexport type BusRole = \"sender\" | \"forwarder\";\n\n/**\n * Transport channel classification used to route incoming and outgoing bus\n * messages. If `receive` switches on the message alone and cannot tell the\n * channels apart, a same-origin iframe 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`; otherwise `\"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 booting forwarder. */\n | { t: \"hello\"; from: string; tabId: string }\n /**\n * Handshake response acknowledging an upstream owner relationship. Addressed\n * through `to`: a welcome published over InterApplicationBus reaches every\n * subscriber, so an unaddressed one lets three waiting views each conclude\n * it has found an owner of 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 /** Broadcast update announcing a new or ended journey state. */\n | { t: \"journey\"; from: string; journey: Journey | null }\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\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 protocol tags and unpacks raw payloads into bus messages. A\n * document receives `message` events from every embedded thing on the page,\n * including analytics tags, video players and extensions. Without the tag\n * check a video player's message is parsed 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 { 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\";\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 exposed on global symbol by same-origin parent runtimes. */\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/**\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 // Catches errors thrown by parent runtime to protect child logging calls.\n diagnostics.guard(\"bus.send_failed\", \"direct call into the parent runtime\", () => {\n target.busAccept(message, receive);\n });\n },\n close() {\n open = false;\n },\n };\n}\n\n/**\n * Creates a postMessage link to the parent window.\n * @param receive Callback for incoming parent messages.\n * @param diagnostics Diagnostics reporter.\n * @returns Link to parent window, or null if running in top-level window.\n */\nexport function createParentLink(receive: Receive, diagnostics: Diagnostics): Link | null {\n if (typeof window === \"undefined\" || window.parent === window) {\n return null;\n }\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n // The parent is trusted by construction: this context chose to talk to it.\n if (message && event.source === window.parent) {\n receive(message, { link: \"parent\", origin: event.origin });\n }\n };\n addEventListener(\"message\", onMessage);\n\n return {\n kind: \"parent\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"postMessage to parent\", () => {\n // \"*\" is fine outbound: the payload is this context's own records,\n // and the parent already receives them another way. Inbound trust\n // works differently; see createChildrenLink.\n window.parent.postMessage(envelope(message), \"*\");\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 const trusted = new Set([window.location.origin, ...trustedOrigins]);\n // Origin per source: a child that navigates must not receive the previous origin's ids.\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(\n \"bus.untrusted_origin\",\n `ignored a bus message from ${event.origin}. Add it to bus.trustedOrigins if it is yours.`,\n { origin: event.origin, type: message.t },\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(\"bus.send_failed\", \"postMessage to child\", () => {\n // Targets the origin the child last spoke from. The browser drops the\n // message if the child has since navigated elsewhere.\n target.postMessage(envelope(message), origin);\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 \"opening 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\", \"BroadcastChannel.postMessage\", () => {\n channel.postMessage(envelope(message));\n });\n },\n close() {\n diagnostics.guard(\"bus.send_failed\", \"closing BroadcastChannel\", () => {\n channel.close();\n });\n },\n };\n}\n\n/** Structural interface for OpenFin InterApplicationBus operations. */\ninterface FinIab {\n /**\n * Publishes a message to all topic subscribers.\n * @param topic Topic name.\n * @param message Message payload.\n */\n publish(topic: string, message: unknown): Promise<void>;\n\n /**\n * Subscribes a listener to a topic for matching application identities.\n * @param identity Target application identity.\n * @param topic Topic name.\n * @param listener Message callback.\n */\n subscribe(\n identity: { uuid: string },\n topic: string,\n listener: (message: unknown) => void,\n ): Promise<void>;\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 fin = (globalThis as { fin?: { InterApplicationBus?: FinIab } }).fin;\n const iab = fin?.InterApplicationBus;\n if (!iab) {\n return null;\n }\n if (!appUuid) {\n // publish() reaches every subscriber on the runtime. Without an identity to\n // scope it, opening the link would share this app's bus with every other.\n diagnostics.report(\n \"openfin.unavailable\",\n \"no OpenFin application uuid, so the InterApplicationBus link stays closed\",\n );\n return null;\n }\n\n // Both halves carry the uuid: the topic keeps this app's messages away from\n // other applications, the subscriber identity rejects theirs.\n const scoped = `${topic}.${appUuid}`;\n\n void diagnostics.guardAsync(\"bus.send_failed\", \"InterApplicationBus.subscribe\", () =>\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(\"bus.send_failed\", \"InterApplicationBus.publish\", () =>\n iab.publish(scoped, envelope(message)),\n );\n },\n close() {\n // OpenFin automatically cleans up subscriptions on context teardown.\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\", \"worker postMessage\", () => {\n send(envelope(message));\n });\n },\n close() {\n // Worker scope listeners terminate with the worker lifecycle.\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 // Activates MessagePort message delivery if supported.\n worker.start?.();\n\n return {\n kind: \"worker\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"postMessage to a worker\", () => {\n worker.postMessage(envelope(message));\n });\n },\n close() {\n worker.removeEventListener(\"message\", onMessage);\n },\n };\n}\n","// src/bus/bus.ts\n//\n// Manages cross-realm bus role resolution and message routing.\n\nimport {\n BUS_CHANNEL_NAME,\n BUS_HANDSHAKE_TIMEOUT_MS,\n BUS_MAX_HANDSHAKE_ATTEMPTS,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { Journey } from \"../core/journey\";\nimport type { BusMessage, BusRole, LinkKind, MessageSource } from \"../models/bus\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogRecord } from \"../models/log-record\";\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 /** Max time to wait 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/** Handshake timing in force. 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 for inquiring child contexts. */\n onJourneyRequest: () => Journey | null;\n /** Invoked when a tab identifier collision is detected across windows. */\n onTabConflict: () => void;\n}\n\n/** Link types that a sender context may claim ownership over during handshakes. */\nconst OWNED: readonly LinkKind[] = [\"children\", \"direct\", \"worker\"];\n\n/** Structural shape of fin.me identity metadata. */\ninterface OpenFinMe {\n isView?: boolean;\n identity?: { uuid?: string; name?: string };\n}\n\n/** Coordinates cross-realm communication, role resolution, and message dispatch. */\nexport class Bus {\n /** Current bus role. Defaults to \"sender\". */\n private role: BusRole = \"sender\";\n /** Upstream forwarding link, or null when acting as sender. */\n private upstream: Link | null = null;\n /** Open control plane links. */\n private readonly links: Link[] = [];\n /** Shared OpenFin InterApplicationBus link instance. */\n private openFinLink: Link | null = null;\n /** Indicates whether this context is the OpenFin platform provider. */\n private isOpenFinProvider = false;\n /** Indicates whether role resolution has completed. */\n private resolved = false;\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 /** Returns whether role resolution has completed. */\n isResolved(): boolean {\n return this.resolved;\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 this.resolved = true;\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\" but there is no owner to forward to. Records will be dropped.',\n );\n }\n }\n this.resolved = true;\n this.announce();\n return this.role;\n }\n\n this.openControlLinks();\n\n // Direct synchronous attachment for same-origin parents.\n const direct = createDirectLink(this.receive, this.diagnostics);\n if (direct) {\n this.role = \"forwarder\";\n this.upstream = direct;\n this.resolved = true;\n this.diagnostics.report(\n \"bus.role_resolved\",\n \"attached directly to the same-origin parent runtime\",\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.resolved = true;\n this.diagnostics.report(\"bus.role_resolved\", \"no owner to forward to, sending directly\", {\n role: \"sender\",\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, promoting to sender`,\n { via: candidate.kind, crossOrigin: this.isCrossOriginFrame() },\n );\n }\n this.diagnostics.report(\"bus.role_resolved\", `role is ${this.role}`, {\n role: this.role,\n via: welcomed ? candidate.kind : \"none\",\n });\n\n this.resolved = true;\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) {\n reply({ t: \"journey\", from: this.contextId, journey: current }, source);\n }\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 * Broadcasts journey state changes to all connected links.\n * @param journey Active journey or null if ended.\n */\n broadcastJourney(journey: Journey | null): void {\n this.post({ t: \"journey\", from: this.contextId, journey });\n }\n\n /** Closes all open links and clears internal state. */\n destroy(): void {\n for (const link of this.allLinks()) {\n link.close();\n }\n this.links.length = 0;\n this.upstream = 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 /** Broadcasts a message across all open links. */\n private post(message: BusMessage): void {\n for (const link of this.allLinks()) {\n link.post(message);\n }\n }\n\n /** Sends a message exclusively over links matching the specified 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 /** 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 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 this.handlers.onJourney(message.journey);\n break;\n\n case \"journey?\": {\n const current = this.handlers.onJourneyRequest();\n if (current) {\n this.postOver(source.link, {\n t: \"journey\",\n from: this.contextId,\n journey: current,\n });\n }\n break;\n }\n\n case \"tab\":\n // Collisions only apply to distinct contexts sharing the broadcast\n // channel. The id comparison picks one side of the pair: without it\n // both colliding contexts report the conflict and both 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 whether records from a link can go upstream. Posted back on the link\n * they arrived on, the records echo to their sender. A direct link is an\n * exception: it is one call into one parent, so two direct links in a chain are\n * different links.\n * @param link Kind of the link the records arrived on.\n * @returns True if the relay is safe.\n */\n private canRelay(link: LinkKind): boolean {\n return link === \"direct\" || link !== this.upstream?.kind;\n }\n\n /** Returns whether this context can accept ownership over 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 /** Resolves whether this context represents 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 = (globalThis as { fin?: { me?: OpenFinMe } }).fin?.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 whether the parent window is inaccessible due to cross-origin boundaries. */\n private isCrossOriginFrame(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) {\n return false;\n }\n try {\n // The probe: a cross-origin parent throws on this read. A bare read fails lint.\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.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 // Declared below finish, which reads it: nothing can call finish until\n // the timer exists, because the welcome arrives through the post below.\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.post({ t: \"journey?\", from: this.contextId });\n }\n}\n"],"mappings":"8EAyEA,SAAgBM,EAAS,EAAkC,CACzD,MAAO,CAAE,EAAGN,EAAAA,EAAc,EAAGO,CAAQ,CACvC,CAUA,SAAgBC,EAAO,EAAkC,CACvD,GAAI,OAAOC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,EAAU,KAAK,CAAE,EAAG,QAAS,KAAM,KAAK,UAAW,MAAO,KAAK,KAAM,CAAC,CACxE,CAAC,CACH,CAGA,UAAyB,CACvB,KAAK,SAAS,YAAa,CACzB,EAAG,MACH,KAAM,KAAK,UACX,MAAO,KAAK,KACd,CAAC,EACD,KAAK,KAAK,CAAE,EAAG,WAAY,KAAM,KAAK,SAAU,CAAC,CACnD,CACF"}
@@ -1,75 +0,0 @@
1
- //#region src/constants.ts
2
- var ee = "[ui-observability]", te = 1e3, e = "ui-observability.session", t = "ui-observability.tab", n = 18e5, r = 6e4, i = /OpenFin/i, a = /\bwv\b/, o = /\b(iPhone|iPad|iPod)\b/, s = /\bMacintosh\b/, c = /\bMobile\b/, l = "AppleWebKit", u = "Safari/", d = 55296, f = 56319, p = 2048, m = {
3
- TRACE: 1,
4
- DEBUG: 5,
5
- INFO: 9,
6
- WARN: 13,
7
- ERROR: 17,
8
- FATAL: 21
9
- }, h = m, g = "log.type", _ = "log.seq", v = "app.namespace", y = "page.url", b = "url.full", x = "journey.id", S = "journey.name", C = "journey.parent_id", w = "uiobs.sanitize_failed", T = "uiobs.attributes_dropped", E = "uiobs.attributes_bytes", D = "service.name", O = "service.version", k = "deployment.environment", A = "telemetry.sdk.name", j = "telemetry.sdk.version", M = "telemetry.sdk.language", N = "host.platform", P = "session.id", F = "tab.id", I = "context.id", L = "browser.user_agent", R = "openfin.uuid", z = "openfin.name", B = "@utk09/ui-observability", V = "0.5.0", H = "webjs", U = "otlp", W = { WARN: "warning" }, G = "application/json", K = "application/x-ndjson", q = 1000000n, J = /^\d+$/, Y = "Content-Type", X = "Content-Encoding", Z = "Retry-After", Q = "X-UiObs-Batch-Id", ne = "X-UiObs-Attempt", re = "gzip", ie = 1e3, ae = 6e4, oe = "text/plain;charset=UTF-8", se = "uiobs_batch_id", ce = "uiobs_exit", le = "ui-observability.batch.", ue = "ui-observability.emergency.", $ = "ui-observability.probe", de = "QuotaExceededError", fe = "batches", pe = "createdAt", me = "indexeddb", he = "localstorage", ge = "memory", _e = "none", ve = "ui-observability.drain", ye = "ui-observability.emergency", be = "ui-observability.journey", xe = 2e3, Se = "uiObsJourney", Ce = /\+/g, we = /\//g, Te = /=+$/, Ee = /-/g, De = /_/g, Oe = 3e5, ke = "traceparent", Ae = 2166136261, je = 16777619, Me = 4294967295, Ne = "metric", Pe = "ui-observability/1", Fe = "ui-observability.runtime", Ie = "ui-observability.stopped", Le = 1e4, Re = "color:#888", ze = 1e3, Be = 6e4, Ve = "uiobs.capture", He = "uiobs.storage", Ue = "count", We = "unknown-service", Ge = [
10
- "redact",
11
- "onDiagnostic",
12
- "headers",
13
- "serializer",
14
- "otelLoader"
15
- ], Ke = [
16
- "sampling",
17
- "bus",
18
- "capture"
19
- ], qe = {
20
- sampling: [],
21
- bus: [],
22
- capture: ["webVitalsLoader"]
23
- }, Je = {
24
- endpoint: "",
25
- serviceName: "",
26
- serviceVersion: "",
27
- environment: "",
28
- enabled: !0,
29
- minLevel: "INFO",
30
- compression: "gzip",
31
- credentials: "omit",
32
- storage: "auto",
33
- identity: "storage",
34
- sampling: {
35
- defaultRate: 1,
36
- rates: {},
37
- alwaysSampleTypes: ["action"]
38
- },
39
- bus: {
40
- mode: "auto",
41
- trustedOrigins: [],
42
- openFinRole: "auto"
43
- },
44
- capture: {
45
- errors: !0,
46
- rejections: !0,
47
- resourceErrors: !1,
48
- fetch: !1,
49
- xhr: !1,
50
- interactions: !1,
51
- navigation: !1,
52
- webVitals: !1,
53
- fullUrls: !1,
54
- ignoreUrls: [],
55
- propagateTraceHeaderTo: []
56
- },
57
- console: null
58
- }, Ye = "DEBUG", Xe = 2e3, Ze = 1e4, Qe = 15e3, $e = 1024, et = "UiObservability", tt = {
59
- maxBatches: 500,
60
- maxAgeMs: 864e5,
61
- maxAttempts: 5
62
- }, nt = 1e4, rt = 2e3, it = 6e4, at = 3e4, ot = 18e5, st = "__uiobs_journey", ct = "ui_observability_control", lt = 1500, ut = 5e3, dt = {
63
- maxBodyChars: 4096,
64
- maxAttributeChars: 8192,
65
- maxAttributeCount: 128,
66
- maxStackChars: 8192,
67
- maxDepth: 6,
68
- maxArrayLength: 100,
69
- maxNodes: 1e4,
70
- maxRecordBytes: 32768
71
- };
72
- //#endregion
73
- export { fe as $, _e as $t, oe as A, P as At, ut as B, u as Bt, Ve as C, I as Ct, Re as D, R as Dt, Ye as E, z as Et, ze as F, rt as Ft, ne as G, m as Gt, Ae as H, n as Ht, W as I, at as It, Y as J, tt as Jt, Q as K, et as Kt, ye as L, it as Lt, Ue as M, M as Mt, te as N, A as Nt, G as O, D as Ot, ve as P, j as Pt, pe as Q, ge as Qt, ue as R, Fe as Rt, Pe as S, L as St, Ke as T, N as Tt, je as U, e as Ut, Le as V, U as Vt, Be as W, r as Wt, f as X, me as Xt, Z as Y, He as Yt, d as Z, he as Zt, we as _, se as _t, x as a, ke as an, ee as at, ct as b, dt as bt, _ as c, Ge as cn, s as ct, w as d, p as dn, c as dt, $ as en, o as et, b as f, l as fn, J as ft, Ce as g, i as gt, Te as h, xe as ht, T as i, V as in, h as it, Je as j, F as jt, K as k, O as kt, g as l, qe as ln, Ze as lt, De as m, Se as mt, v as n, H as nn, be as nt, S as o, Oe as on, Xe as ot, Ee as p, q as pt, X as q, nt as qt, E as r, B as rn, st as rt, C as s, Me as sn, Ne as st, a as t, t as tn, ot as tt, y as u, We as un, ie as ut, le as v, ce as vt, $e as w, k as wt, lt as x, Qe as xt, ae as y, de as yt, re as z, Ie as zt };
74
-
75
- //# sourceMappingURL=constants-B6kdsCzF.js.map