@utk09/ui-observability 0.8.0 → 0.9.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.
- package/CHANGELOG.md +59 -0
- package/README.md +52 -45
- package/dist/bus/bus.d.ts +46 -12
- package/dist/bus/links.d.ts +6 -3
- package/dist/bus-CtJWf9QN.cjs +2 -0
- package/dist/bus-CtJWf9QN.cjs.map +1 -0
- package/dist/{bus-DPDrlUBY.js → bus-D8kH58tb.js} +128 -71
- package/dist/bus-D8kH58tb.js.map +1 -0
- package/dist/capture/interactions.d.ts +7 -6
- package/dist/capture/network.d.ts +23 -9
- package/dist/capture/types.d.ts +3 -3
- package/dist/console-BpHfWstv.cjs +2 -0
- package/dist/console-BpHfWstv.cjs.map +1 -0
- package/dist/console-DjLbryED.js +82 -0
- package/dist/console-DjLbryED.js.map +1 -0
- package/dist/constants-Br3b89Wg.cjs +2 -0
- package/dist/constants-Br3b89Wg.cjs.map +1 -0
- package/dist/constants-DM94FjVX.js +96 -0
- package/dist/constants-DM94FjVX.js.map +1 -0
- package/dist/constants.d.ts +20 -9
- package/dist/core/diagnostics.d.ts +2 -2
- package/dist/core/journey.d.ts +16 -4
- package/dist/core/logger.d.ts +6 -2
- package/dist/core/pipeline.d.ts +18 -9
- package/dist/core/record.d.ts +11 -6
- package/dist/core/remote-sampling.d.ts +1 -1
- package/dist/core/runtime.d.ts +43 -15
- package/dist/core/sender.d.ts +15 -10
- package/dist/deadline-B5DINjD5.js +111 -0
- package/dist/deadline-B5DINjD5.js.map +1 -0
- package/dist/deadline-Cbg2cbUw.cjs +2 -0
- package/dist/deadline-Cbg2cbUw.cjs.map +1 -0
- package/dist/error-like-Ywo5uRHo.js +19 -0
- package/dist/error-like-Ywo5uRHo.js.map +1 -0
- package/dist/error-like-gGRx2s36.cjs +2 -0
- package/dist/error-like-gGRx2s36.cjs.map +1 -0
- package/dist/errors-CpGRhhIf.cjs +3 -0
- package/dist/errors-CpGRhhIf.cjs.map +1 -0
- package/dist/{errors-Dnc-X4Ec.js → errors-DH4QJS0u.js} +39 -20
- package/dist/errors-DH4QJS0u.js.map +1 -0
- package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
- package/dist/global-scope-dp2jADRl.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +561 -436
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-DNdf1fmL.cjs +2 -0
- package/dist/indexeddb-storage-DNdf1fmL.cjs.map +1 -0
- package/dist/{indexeddb-storage-uD4oaRMc.js → indexeddb-storage-n1qkFBGA.js} +17 -17
- package/dist/indexeddb-storage-n1qkFBGA.js.map +1 -0
- package/dist/interactions-31eHGwEQ.cjs +2 -0
- package/dist/interactions-31eHGwEQ.cjs.map +1 -0
- package/dist/{interactions-igKTAJvj.js → interactions-OU94MPXs.js} +22 -19
- package/dist/interactions-OU94MPXs.js.map +1 -0
- package/dist/journey-CE2EcwHW.cjs +2 -0
- package/dist/journey-CE2EcwHW.cjs.map +1 -0
- package/dist/journey-CeJ1QoT2.js +162 -0
- package/dist/journey-CeJ1QoT2.js.map +1 -0
- package/dist/{library-request-Br_T09Bn.cjs → library-request-C9uJFlbq.cjs} +2 -2
- package/dist/{library-request-Br_T09Bn.cjs.map → library-request-C9uJFlbq.cjs.map} +1 -1
- package/dist/{library-request-Dt0fXhcn.js → library-request-DvhuplAB.js} +2 -2
- package/dist/{library-request-Dt0fXhcn.js.map → library-request-DvhuplAB.js.map} +1 -1
- package/dist/{long-frames-DahhqM6u.cjs → long-frames-B8VdA_ny.cjs} +2 -2
- package/dist/{long-frames-DahhqM6u.cjs.map → long-frames-B8VdA_ny.cjs.map} +1 -1
- package/dist/{long-frames-6pnjWSSR.js → long-frames-C_7OutLs.js} +3 -3
- package/dist/{long-frames-6pnjWSSR.js.map → long-frames-C_7OutLs.js.map} +1 -1
- package/dist/models/batch.d.ts +1 -1
- package/dist/models/bus.d.ts +7 -4
- package/dist/models/config.d.ts +43 -12
- package/dist/models/log-record.d.ts +12 -6
- package/dist/network-BAV7ipyn.cjs +2 -0
- package/dist/network-BAV7ipyn.cjs.map +1 -0
- package/dist/network-D_lloS5t.js +174 -0
- package/dist/network-D_lloS5t.js.map +1 -0
- package/dist/patch-BX8KrPCT.cjs +2 -0
- package/dist/patch-BX8KrPCT.cjs.map +1 -0
- package/dist/patch-CCWfuEY7.js +9 -0
- package/dist/patch-CCWfuEY7.js.map +1 -0
- package/dist/{platform-D_XkVIF6.cjs → platform-D4wu1eIF.cjs} +2 -2
- package/dist/platform-D4wu1eIF.cjs.map +1 -0
- package/dist/platform-IHBZGqUe.js +48 -0
- package/dist/platform-IHBZGqUe.js.map +1 -0
- package/dist/{remote-rules-5UA23alm.js → remote-rules-Bt1XsdEQ.js} +14 -14
- package/dist/remote-rules-Bt1XsdEQ.js.map +1 -0
- package/dist/{remote-rules-rJJZKVG8.cjs → remote-rules-kuDf5gbe.cjs} +2 -2
- package/dist/remote-rules-kuDf5gbe.cjs.map +1 -0
- package/dist/sampling-BI15ds9D.cjs +2 -0
- package/dist/sampling-BI15ds9D.cjs.map +1 -0
- package/dist/sampling-o0VY1mqQ.js +63 -0
- package/dist/sampling-o0VY1mqQ.js.map +1 -0
- package/dist/sanitize-B9UheVKc.js +123 -0
- package/dist/sanitize-B9UheVKc.js.map +1 -0
- package/dist/sanitize-DSIP7amZ.cjs +2 -0
- package/dist/sanitize-DSIP7amZ.cjs.map +1 -0
- package/dist/{sender-G6v4Uqi4.js → sender-BnNj9bOX.js} +234 -176
- package/dist/sender-BnNj9bOX.js.map +1 -0
- package/dist/sender-D0OsyB1c.cjs +3 -0
- package/dist/sender-D0OsyB1c.cjs.map +1 -0
- package/dist/storage/emergency-queue.d.ts +1 -1
- package/dist/storage/factory.d.ts +1 -1
- package/dist/storage/idb-driver.d.ts +1 -1
- package/dist/storage/local-storage.d.ts +3 -3
- package/dist/storage/memory-storage.d.ts +3 -3
- package/dist/{storm-DJkEZP_8.js → storm-BTw0J6eE.js} +2 -2
- package/dist/{storm-DJkEZP_8.js.map → storm-BTw0J6eE.js.map} +1 -1
- package/dist/{storm-BtzgLOCX.cjs → storm-Y-yuBhvv.cjs} +2 -2
- package/dist/{storm-BtzgLOCX.cjs.map → storm-Y-yuBhvv.cjs.map} +1 -1
- package/dist/transport/compression.d.ts +1 -1
- package/dist/transport/exit-flush.d.ts +21 -17
- package/dist/transport/http-transport.d.ts +61 -7
- package/dist/transport/retry-engine.d.ts +5 -5
- package/dist/transport/status-transport.d.ts +4 -2
- package/dist/utils/console.d.ts +1 -1
- package/dist/utils/error-like.d.ts +25 -0
- package/dist/utils/global-scope.d.ts +1 -1
- package/dist/utils/identity.d.ts +1 -1
- package/dist/utils/library-console.d.ts +1 -1
- package/dist/utils/library-request.d.ts +1 -1
- package/dist/utils/patch.d.ts +9 -0
- package/dist/utils/platform.d.ts +3 -3
- package/dist/utils/sequence.d.ts +0 -5
- package/dist/utils/timer.d.ts +1 -1
- package/dist/utils/tracing.d.ts +3 -3
- package/dist/utils/unref.d.ts +2 -2
- package/dist/{web-vitals-DHZ0yA_H.js → web-vitals-Bflr5jSA.js} +4 -2
- package/dist/web-vitals-Bflr5jSA.js.map +1 -0
- package/dist/web-vitals-DFuoTQbZ.cjs +2 -0
- package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -0
- package/package.json +2 -2
- package/dist/bus-CUXRY0JR.cjs +0 -2
- package/dist/bus-CUXRY0JR.cjs.map +0 -1
- package/dist/bus-DPDrlUBY.js.map +0 -1
- package/dist/console-CNljJict.js +0 -81
- package/dist/console-CNljJict.js.map +0 -1
- package/dist/console-PKzc-FmR.cjs +0 -2
- package/dist/console-PKzc-FmR.cjs.map +0 -1
- package/dist/constants-B28fDv2F.cjs +0 -2
- package/dist/constants-B28fDv2F.cjs.map +0 -1
- package/dist/constants-Bu49bm39.js +0 -93
- package/dist/constants-Bu49bm39.js.map +0 -1
- package/dist/errors-C78ZTjet.cjs +0 -3
- package/dist/errors-C78ZTjet.cjs.map +0 -1
- package/dist/errors-Dnc-X4Ec.js.map +0 -1
- package/dist/indexeddb-storage-D0p3iMD0.cjs +0 -2
- package/dist/indexeddb-storage-D0p3iMD0.cjs.map +0 -1
- package/dist/indexeddb-storage-uD4oaRMc.js.map +0 -1
- package/dist/interactions-CsE2y_fQ.cjs +0 -2
- package/dist/interactions-CsE2y_fQ.cjs.map +0 -1
- package/dist/interactions-igKTAJvj.js.map +0 -1
- package/dist/network-CZ0aFUsy.cjs +0 -2
- package/dist/network-CZ0aFUsy.cjs.map +0 -1
- package/dist/network-aSNbwpue.js +0 -112
- package/dist/network-aSNbwpue.js.map +0 -1
- package/dist/platform-BwbMRwHm.js +0 -48
- package/dist/platform-BwbMRwHm.js.map +0 -1
- package/dist/platform-D_XkVIF6.cjs.map +0 -1
- package/dist/remote-rules-5UA23alm.js.map +0 -1
- package/dist/remote-rules-rJJZKVG8.cjs.map +0 -1
- package/dist/sampling-E4x92Nn2.cjs +0 -2
- package/dist/sampling-E4x92Nn2.cjs.map +0 -1
- package/dist/sampling-J1eahbfT.js +0 -160
- package/dist/sampling-J1eahbfT.js.map +0 -1
- package/dist/sanitize-BMhh8ghJ.cjs +0 -2
- package/dist/sanitize-BMhh8ghJ.cjs.map +0 -1
- package/dist/sanitize-UJ-4Lb0n.js +0 -114
- package/dist/sanitize-UJ-4Lb0n.js.map +0 -1
- package/dist/sender-B6ufz26f.cjs +0 -3
- package/dist/sender-B6ufz26f.cjs.map +0 -1
- package/dist/sender-G6v4Uqi4.js.map +0 -1
- package/dist/unref-16maCyKA.js +0 -8
- package/dist/unref-16maCyKA.js.map +0 -1
- package/dist/unref-CU9Nyz_9.cjs +0 -2
- package/dist/unref-CU9Nyz_9.cjs.map +0 -1
- package/dist/web-vitals-B2FYsEAU.cjs +0 -2
- package/dist/web-vitals-B2FYsEAU.cjs.map +0 -1
- package/dist/web-vitals-DHZ0yA_H.js.map +0 -1
|
@@ -5,25 +5,68 @@ import { StatusTransport } from "./status-transport";
|
|
|
5
5
|
* compression and classifies errors.
|
|
6
6
|
*/
|
|
7
7
|
export declare class HttpTransport extends StatusTransport {
|
|
8
|
+
/**
|
|
9
|
+
* Headers that the headers() function gave last. The exit flush sends them only while that
|
|
10
|
+
* function and the endpoint are in force. A tenant switch must not send the old token to the
|
|
11
|
+
* new endpoint.
|
|
12
|
+
*/
|
|
13
|
+
private cachedHeaders;
|
|
8
14
|
/**
|
|
9
15
|
* Sends one log batch over HTTP.
|
|
10
16
|
* @param batch Batch to send.
|
|
17
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
11
18
|
* @throws TransportError on transient, throttled, 413, or permanent network failures.
|
|
12
19
|
*/
|
|
13
|
-
send(batch: LogBatch): Promise<void>;
|
|
20
|
+
send(batch: LogBatch, onKeepalive?: () => void): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Gives the headers for the exit flush. A closing document cannot await headers().
|
|
23
|
+
* @returns The static headers, the headers that the function in force gave last, or undefined.
|
|
24
|
+
*/
|
|
25
|
+
lastHeaders(): Record<string, string> | undefined;
|
|
14
26
|
/**
|
|
15
27
|
* Serializes, encodes and sends a batch. It throws a classified TransportError
|
|
16
28
|
* on failure.
|
|
17
29
|
* @param batch Batch to deliver.
|
|
18
30
|
* @param endpoint Ingest URL. The caller reads it one time. A reconfigure during the send
|
|
19
31
|
* cannot change it.
|
|
32
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
20
33
|
*/
|
|
21
34
|
private post;
|
|
22
35
|
/**
|
|
23
|
-
*
|
|
36
|
+
* Tests if a status rejects the credentials.
|
|
37
|
+
* @param status HTTP status code.
|
|
38
|
+
* @returns True for 401 and 403.
|
|
39
|
+
*/
|
|
40
|
+
private rejectsCredentials;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the headers, encodes the body and sends one request. One deadline covers the
|
|
43
|
+
* three steps. Without it, a headers() that never settles holds a dispatch slot forever.
|
|
44
|
+
* @param batch Batch to deliver.
|
|
45
|
+
* @param endpoint Ingest URL.
|
|
46
|
+
* @param serialized Serialized batch.
|
|
47
|
+
* @param onKeepalive Runs when the request starts with keepalive.
|
|
48
|
+
* @returns Promise that resolves to the HTTP Response.
|
|
49
|
+
* @throws TransportError on timeout or network failure.
|
|
50
|
+
*/
|
|
51
|
+
private attempt;
|
|
52
|
+
/**
|
|
53
|
+
* Waits for a step until the deadline.
|
|
54
|
+
* @param work Step to wait for. It does not reject. Only the deadline rejects here.
|
|
55
|
+
* @param deadline Epoch time in milliseconds at which the request times out.
|
|
56
|
+
* @returns Promise that resolves to the value of the step.
|
|
57
|
+
* @throws TransportError of kind "timeout" at the deadline.
|
|
58
|
+
*/
|
|
59
|
+
private before;
|
|
60
|
+
/**
|
|
61
|
+
* Reports a timeout and builds its error.
|
|
62
|
+
* @returns TransportError of kind "timeout".
|
|
63
|
+
*/
|
|
64
|
+
private timeout;
|
|
65
|
+
/**
|
|
66
|
+
* Compresses the serialized payload when the config sets gzip. The payload size must
|
|
24
67
|
* be at or above the threshold.
|
|
25
68
|
* @param text Serialized payload string.
|
|
26
|
-
* @returns Promise
|
|
69
|
+
* @returns Promise that resolves to original string or compressed byte array.
|
|
27
70
|
*/
|
|
28
71
|
private encodeBody;
|
|
29
72
|
/**
|
|
@@ -32,19 +75,30 @@ export declare class HttpTransport extends StatusTransport {
|
|
|
32
75
|
* @param endpoint Ingest URL.
|
|
33
76
|
* @param headers HTTP request headers.
|
|
34
77
|
* @param body Request body string or byte array.
|
|
35
|
-
* @
|
|
78
|
+
* @param deadline Epoch time in milliseconds at which the request times out.
|
|
79
|
+
* @param keepalive True if the request continues after unload.
|
|
80
|
+
* @returns Promise that resolves to the HTTP Response.
|
|
36
81
|
* @throws TransportError on network failure, timeout, or offline status.
|
|
37
82
|
*/
|
|
38
83
|
private dispatch;
|
|
84
|
+
/**
|
|
85
|
+
* Tests if a send uses keepalive. A mobile OS can stop a hidden page with no pagehide.
|
|
86
|
+
* A keepalive request continues after that. The browser limits the keepalive bodies in flight.
|
|
87
|
+
* @param body Request body string or byte array.
|
|
88
|
+
* @returns True for a hidden document and a body of BEACON_LIMIT_BYTES or less.
|
|
89
|
+
*/
|
|
90
|
+
private keepalive;
|
|
39
91
|
/**
|
|
40
92
|
* Reads the optional maxBytes limit from a 413 response body.
|
|
41
93
|
* @param response HTTP 413 Response instance.
|
|
42
|
-
* @returns Promise
|
|
94
|
+
* @returns Promise that resolves to maximum byte limit or undefined.
|
|
43
95
|
*/
|
|
44
96
|
private readMaxBytes;
|
|
45
97
|
/**
|
|
46
|
-
* Resolves the configured static or dynamic request headers.
|
|
47
|
-
*
|
|
98
|
+
* Resolves the configured static or dynamic request headers. It keeps the headers that
|
|
99
|
+
* headers() gave, for the exit flush.
|
|
100
|
+
* @param endpoint Ingest URL of the send.
|
|
101
|
+
* @returns Promise that resolves to resolved header map.
|
|
48
102
|
*/
|
|
49
103
|
private resolveHeaders;
|
|
50
104
|
}
|
|
@@ -13,13 +13,13 @@ export declare class RetryEngine {
|
|
|
13
13
|
private readonly diagnostics;
|
|
14
14
|
private readonly config;
|
|
15
15
|
private readonly batchesPerDrain;
|
|
16
|
-
/** This field holds the active retry timer handle. It is null when no timer
|
|
16
|
+
/** This field holds the active retry timer handle. It is null when no timer runs. */
|
|
17
17
|
private timer;
|
|
18
18
|
/** This field counts consecutive failed deliveries. The backoff calculation uses it. */
|
|
19
19
|
private attempt;
|
|
20
20
|
/** This flag is true while a storage drain runs. */
|
|
21
21
|
private draining;
|
|
22
|
-
/** This flag is true
|
|
22
|
+
/** This flag is true after stop(). */
|
|
23
23
|
private stopped;
|
|
24
24
|
/** This listener runs on the online event. It resets the attempt count and starts a drain. */
|
|
25
25
|
private readonly onOnline;
|
|
@@ -71,12 +71,12 @@ export declare class RetryEngine {
|
|
|
71
71
|
/**
|
|
72
72
|
* Processes batches while it holds the Web Lock. It schedules the next tick.
|
|
73
73
|
* It always resolves. A throw leaves the engine idle with no armed timer.
|
|
74
|
-
* @returns Promise
|
|
74
|
+
* @returns Promise that resolves to true on completion.
|
|
75
75
|
*/
|
|
76
76
|
private drainLocked;
|
|
77
77
|
/**
|
|
78
|
-
* Tries to deliver one batch. It removes the batch on success.
|
|
79
|
-
*
|
|
78
|
+
* Tries to deliver one batch. It removes the batch on success. On failure, it applies the
|
|
79
|
+
* rule for the failure kind.
|
|
80
80
|
* @param batch Log batch to deliver.
|
|
81
81
|
* @returns True to continue with the next batch. False to stop the current drain.
|
|
82
82
|
*/
|
|
@@ -8,9 +8,10 @@ export interface BatchTransport {
|
|
|
8
8
|
/**
|
|
9
9
|
* Sends one batch.
|
|
10
10
|
* @param batch Batch to send.
|
|
11
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
11
12
|
* @throws TransportError when the batch is not accepted.
|
|
12
13
|
*/
|
|
13
|
-
send(batch: LogBatch): Promise<void>;
|
|
14
|
+
send(batch: LogBatch, onKeepalive?: () => void): Promise<void>;
|
|
14
15
|
/**
|
|
15
16
|
* Returns the remaining throttle delay.
|
|
16
17
|
* @returns Milliseconds until the throttle ends, or 0.
|
|
@@ -42,9 +43,10 @@ export declare abstract class StatusTransport implements BatchTransport {
|
|
|
42
43
|
/**
|
|
43
44
|
* Sends one batch.
|
|
44
45
|
* @param batch Batch to send.
|
|
46
|
+
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
45
47
|
* @throws TransportError when the batch is not accepted.
|
|
46
48
|
*/
|
|
47
|
-
abstract send(batch: LogBatch): Promise<void>;
|
|
49
|
+
abstract send(batch: LogBatch, onKeepalive?: () => void): Promise<void>;
|
|
48
50
|
/**
|
|
49
51
|
* Returns the remaining throttle delay in milliseconds.
|
|
50
52
|
* @returns Milliseconds remaining in throttle window, or 0 if unthrottled.
|
package/dist/utils/console.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class ConsoleSink {
|
|
|
16
16
|
*/
|
|
17
17
|
update(settings: ResolvedConsole): void;
|
|
18
18
|
/**
|
|
19
|
-
* Tests
|
|
19
|
+
* Tests if a level clears the console threshold.
|
|
20
20
|
* @param level Severity level of the record.
|
|
21
21
|
* @returns True if the sink prints this level.
|
|
22
22
|
*/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Standard fields of an error. The library writes the other own fields as error data. */
|
|
2
|
+
export declare const ERROR_OWN_KEYS: ReadonlySet<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Tests if a value is a field that error data keeps. An object field, for example the
|
|
5
|
+
* config of an AxiosError, holds credentials and request bodies.
|
|
6
|
+
* @param value Field value.
|
|
7
|
+
* @returns True for a string, a number or a boolean.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isDataField(value: unknown): boolean;
|
|
10
|
+
/** The fields of an error that the library reads. */
|
|
11
|
+
export interface ErrorLike {
|
|
12
|
+
/** Error class name, for example "TypeError". */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Error message. */
|
|
15
|
+
message: string;
|
|
16
|
+
/** Stack trace text. */
|
|
17
|
+
stack?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Tests if a value has the shape of an error.
|
|
21
|
+
* A getter on a hostile value can throw. Call this function inside a diagnostics guard.
|
|
22
|
+
* @param value Value to test.
|
|
23
|
+
* @returns True for an object with a string name, a string message and a string or no stack.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isErrorLike(value: unknown): value is ErrorLike;
|
package/dist/utils/identity.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare const BROWSER_STORES: IdentityStores;
|
|
|
44
44
|
export declare function memoryStores(): IdentityStores;
|
|
45
45
|
/**
|
|
46
46
|
* Generates a random lowercase hexadecimal string of the specified byte length.
|
|
47
|
-
* It uses crypto.getRandomValues when it is available.
|
|
47
|
+
* It uses crypto.getRandomValues when it is available. If not, it uses Math.random.
|
|
48
48
|
* @param byteLength Number of random bytes to generate.
|
|
49
49
|
* @returns Hexadecimal string of length byteLength * 2.
|
|
50
50
|
*/
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function runAsLibraryConsole<T>(fn: () => T): T;
|
|
7
7
|
/**
|
|
8
|
-
* Tests
|
|
8
|
+
* Tests if a library console scope is open.
|
|
9
9
|
* @returns True while the library writes to the console.
|
|
10
10
|
*/
|
|
11
11
|
export declare function isLibraryConsole(): boolean;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function runAsLibraryRequest<T>(fn: () => T): T;
|
|
8
8
|
/**
|
|
9
|
-
* Tests
|
|
9
|
+
* Tests if a library request scope is open.
|
|
10
10
|
* @returns True while the library starts a request.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isLibraryRequest(): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces `target[key]` with a wrapper of the current value.
|
|
3
|
+
* @param target Object that holds the function, for example `console` or `globalThis`.
|
|
4
|
+
* @param key Property to replace.
|
|
5
|
+
* @param wrap Makes the wrapper from the original value.
|
|
6
|
+
* @returns Restore function. It writes the original back only if the property still holds
|
|
7
|
+
* the wrapper. It then returns true. If not, it changes nothing. It returns false.
|
|
8
|
+
*/
|
|
9
|
+
export declare function patch<T extends object, K extends keyof T>(target: T, key: K, wrap: (original: T[K]) => T[K]): () => boolean;
|
package/dist/utils/platform.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ export interface PlatformMetadata {
|
|
|
11
11
|
openfinName?: string;
|
|
12
12
|
/** Raw navigator user agent string or empty string if unavailable. */
|
|
13
13
|
userAgent: string;
|
|
14
|
-
/**
|
|
14
|
+
/** True if the code runs in a worker realm. */
|
|
15
15
|
isWorker: boolean;
|
|
16
|
-
/**
|
|
16
|
+
/** True if this context is the top-level document rather than an iframe. */
|
|
17
17
|
isTopLevelDocument: boolean;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -23,7 +23,7 @@ export interface PlatformMetadata {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function detectPlatform(diagnostics: Diagnostics): PlatformMetadata;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Tests if the current window is the top-level browsing context.
|
|
27
27
|
* @param diagnostics Diagnostics reporter. It counts a blocked read of window.top.
|
|
28
28
|
* @returns True if top-level, false if framed or inaccessible due to cross-origin boundaries.
|
|
29
29
|
*/
|
package/dist/utils/sequence.d.ts
CHANGED
|
@@ -7,9 +7,4 @@ export declare class Sequence {
|
|
|
7
7
|
* @returns Next sequence number.
|
|
8
8
|
*/
|
|
9
9
|
next(): number;
|
|
10
|
-
/**
|
|
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
|
-
*/
|
|
14
|
-
reset(): void;
|
|
15
10
|
}
|
package/dist/utils/timer.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export declare function timeSync<T>(logger: CaptureLogger, label: string, fn: ()
|
|
|
14
14
|
* @param label Metric name prefix.
|
|
15
15
|
* @param fn Asynchronous function to execute.
|
|
16
16
|
* @param attributes Optional contextual attributes.
|
|
17
|
-
* @returns Promise
|
|
17
|
+
* @returns Promise that resolves to the result of the wrapped function.
|
|
18
18
|
*/
|
|
19
19
|
export declare function timeAsync<T>(logger: CaptureLogger, label: string, fn: () => Promise<T>, attributes?: Record<string, unknown>): Promise<T>;
|
package/dist/utils/tracing.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface TraceContext {
|
|
|
9
9
|
/** Bitfield byte containing W3C trace flags. */
|
|
10
10
|
traceFlags: number;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/** Cause of a rotation of the ambient trace context. */
|
|
13
13
|
export type RotateReason = "start" | "interaction" | "navigation" | "explicit" | "maxAge";
|
|
14
14
|
/**
|
|
15
15
|
* Generates a random 32-character hex string in the W3C trace ID format.
|
|
@@ -45,7 +45,7 @@ export declare class TraceEngine {
|
|
|
45
45
|
/**
|
|
46
46
|
* Loads the OpenTelemetry API. Until the load completes, records use the ambient trace.
|
|
47
47
|
* If there is no loader or the load fails, all records use the ambient trace.
|
|
48
|
-
* @returns Promise
|
|
48
|
+
* @returns Promise that resolves when the attempt settles.
|
|
49
49
|
*/
|
|
50
50
|
loadOtel(): Promise<void>;
|
|
51
51
|
/**
|
|
@@ -54,7 +54,7 @@ export declare class TraceEngine {
|
|
|
54
54
|
*/
|
|
55
55
|
resolve(): TraceContext;
|
|
56
56
|
/**
|
|
57
|
-
* Reads the
|
|
57
|
+
* Reads the active span of the host if the peer module loaded and a span runs.
|
|
58
58
|
* @returns Trace context of the active span, or undefined.
|
|
59
59
|
*/
|
|
60
60
|
private activeSpanContext;
|
package/dist/utils/unref.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Timer handle. It is a number in a browser and a Timeout object in Node. */
|
|
2
2
|
export type TimerHandle = number | {
|
|
3
3
|
unref?: () => void;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
|
-
* Unreferences a timer handle
|
|
6
|
+
* Unreferences a timer handle. A pending timer then does not keep a Node.js process alive.
|
|
7
7
|
* @param timer Timer handle returned by setTimeout.
|
|
8
8
|
*/
|
|
9
9
|
export declare function unrefTimer(timer: TimerHandle): void;
|
|
@@ -9,7 +9,7 @@ var e = class {
|
|
|
9
9
|
install() {
|
|
10
10
|
if (this.installed || (this.installed = !0, this.reportNavigationTiming(), this.ctx.once.webVitals)) return;
|
|
11
11
|
let e = this.ctx.config.capture.webVitalsLoader;
|
|
12
|
-
e ?
|
|
12
|
+
e ? this.loadWebVitals(e) : this.ctx.diagnostics.report("config.invalid", "capture.webVitals needs capture.webVitalsLoader. LCP, CLS and INP are off. Navigation timing continues.");
|
|
13
13
|
}
|
|
14
14
|
uninstall() {
|
|
15
15
|
this.installed = !1;
|
|
@@ -20,6 +20,8 @@ var e = class {
|
|
|
20
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
|
+
if (this.ctx.once.webVitals) return;
|
|
24
|
+
this.ctx.once.webVitals = !0;
|
|
23
25
|
let n = (e, t) => (n) => {
|
|
24
26
|
this.ctx.logger.logMetric(`web_vitals.${e}`, Math.round(n.value * 1e3) / 1e3, t, "gauge", {
|
|
25
27
|
"metric.rating": n.rating,
|
|
@@ -48,4 +50,4 @@ var e = class {
|
|
|
48
50
|
//#endregion
|
|
49
51
|
export { e as WebVitalsCapture };
|
|
50
52
|
|
|
51
|
-
//# sourceMappingURL=web-vitals-
|
|
53
|
+
//# sourceMappingURL=web-vitals-Bflr5jSA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-vitals-Bflr5jSA.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 after a successful load, not before. A failed load then gets a new\n // attempt on a later install.\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 // Two installs in one turn both load the module. Only the first subscribes.\n // web-vitals has no unsubscribe, and a second set reports each metric two times.\n if (this.ctx.once.webVitals) {\n return;\n }\n this.ctx.once.webVitals = true;\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,IAUL,KAAU,cAAcA,CAAM,IAT5B,KAAK,IAAI,YAAY,OACnB,kBACA,yGACF;CAOJ;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;EAIA,IAAI,KAAK,IAAI,KAAK,WAChB;EAEF,KAAK,IAAI,KAAK,YAAY;EAE1B,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"}
|
|
@@ -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.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}if(this.ctx.once.webVitals)return;this.ctx.once.webVitals=!0;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-DFuoTQbZ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-vitals-DFuoTQbZ.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 after a successful load, not before. A failed load then gets a new\n // attempt on a later install.\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 // Two installs in one turn both load the module. Only the first subscribes.\n // web-vitals has no unsubscribe, and a second set reports each metric two times.\n if (this.ctx.once.webVitals) {\n return;\n }\n this.ctx.once.webVitals = true;\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,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AAkBA,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utk09/ui-observability",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "UI observability and logging for browser, OpenFin and webview applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"check:peers": "node tools/check-peer-imports.mjs",
|
|
78
78
|
"check:size": "node tools/check-size.mjs",
|
|
79
79
|
"check:dev": "node tools/check-dev-server.mjs",
|
|
80
|
-
"verify": "npm run format:check && npm run check:version && npm run typecheck && npm run
|
|
80
|
+
"verify": "npm run format:check && npm run check:version && npm run typecheck && npm run build && npm run lint && npm run check:peers && npm run check:size && npm run check:dev && npm run test:coverage",
|
|
81
81
|
"prepublishOnly": "npm run verify"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
package/dist/bus-CUXRY0JR.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./constants-B28fDv2F.cjs"),t=require("./unref-CU9Nyz_9.cjs"),n=require("./remote-rules-rJJZKVG8.cjs");function r(t){return{p:e.S,m:t}}function i(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 a=Symbol.for(e.Wt);function o(e,t){if(typeof window>`u`||window.parent===window)return null;let n;try{n=window.parent[a]}catch{return null}if(typeof n?.busAccept!=`function`)return null;let r=n,i=!0;return{kind:`direct`,post(n){i&&t.guard(`bus.send_failed`,`The direct call into the parent runtime failed.`,()=>{r.busAccept(n,e)})},close(){i=!1}}}function s(e,t){if(typeof window>`u`||window.parent===window)return null;let n=t=>{let n=i(t.data);n&&t.source===window.parent&&e(n,{link:`parent`,origin:t.origin})};return addEventListener(`message`,n),{kind:`parent`,post(e){t.guard(`bus.send_failed`,`The postMessage call to the parent failed.`,()=>{window.parent.postMessage(r(e),`*`)})},close(){removeEventListener(`message`,n)}}}function c(e,t,n){if(typeof window>`u`)return null;let a=new Set([window.location.origin,...t]),o=new Map,s=t=>{let r=i(t.data);r&&(a.has(t.origin)?(t.source&&o.set(t.source,t.origin),e(r,{link:`children`,origin:t.origin})):n.report(`bus.untrusted_origin`,`The bus ignored a message from ${t.origin}. If you own this origin, add it to bus.trustedOrigins.`,{origin:t.origin,type:r.t}))};return addEventListener(`message`,s),{kind:`children`,post(e){for(let[t,i]of o){let a=t;a.closed?o.delete(t):n.guard(`bus.send_failed`,`The postMessage call to a child frame failed.`,()=>{a.postMessage(r(e),i)})}},close(){removeEventListener(`message`,s),o.clear()}}}function l(e,t,n){let a=globalThis.BroadcastChannel;if(a===void 0)return null;let o=n.guard(`bus.send_failed`,`The library could not open the BroadcastChannel.`,()=>new a(e));return o?(o.onmessage=e=>{let n=i(e.data);n&&t(n,{link:`broadcast`,origin:`same-origin`})},{kind:`broadcast`,post(e){n.guard(`bus.send_failed`,`The BroadcastChannel.postMessage call failed.`,()=>{o.postMessage(r(e))})},close(){n.guard(`bus.send_failed`,`The library could not close the BroadcastChannel.`,()=>{o.close()})}}):null}function u(e,t,n,a){let o=globalThis.fin?.InterApplicationBus;if(!o)return null;if(!t)return a.report(`openfin.unavailable`,`OpenFin gives no application uuid. The InterApplicationBus link stays closed.`),null;let s=`${e}.${t}`;return a.guardAsync(`bus.send_failed`,`The InterApplicationBus.subscribe call failed.`,()=>o.subscribe({uuid:t},s,e=>{let t=i(e);t&&n(t,{link:`openfin`,origin:`openfin`})})),{kind:`openfin`,post(e){a.guardAsync(`bus.send_failed`,`The InterApplicationBus.publish call failed.`,()=>o.publish(s,r(e)))},close(){}}}function d(e,t){let n=globalThis,a=n.postMessage;return n.WorkerGlobalScope===void 0||!a?null:(n.addEventListener?.(`message`,t=>{let n=i(t.data);n&&e(n,{link:`owner`,origin:`same-origin`})}),{kind:`owner`,post(e){t.guard(`bus.send_failed`,`The postMessage call of the worker failed.`,()=>{a(r(e))})},close(){}})}function f(e,t,n){let a=e=>{let n=i(e.data);n&&t(n,{link:`worker`,origin:`same-origin`})};return e.addEventListener(`message`,a),e.start?.(),{kind:`worker`,post(t){n.guard(`bus.send_failed`,`The postMessage call to a worker failed.`,()=>{e.postMessage(r(t))})},close(){e.removeEventListener(`message`,a)}}}var p={timeoutMs:e.x,maxAttempts:3},m=[`children`,`direct`,`worker`],h=class{config;diagnostics;platform;contextId;tabId;handlers;handshakeOptions;role=`sender`;upstream=null;links=[];openFinLink=null;isOpenFinProvider=!1;resolved=!1;rulesPoll;destroyed=!1;awaitingWelcome=null;constructor(e,t,n,r,i,a,o=p){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". No owner exists. The library drops the records of this context.`)),this.resolved=!0,this.announce(),this.role;this.openControlLinks();let t=o(this.receive,this.diagnostics);if(t)return this.role=`forwarder`,this.upstream=t,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`This context attached directly to the runtime of its same-origin parent.`,{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 exists. This context sends its own records.`,{role:`sender`}),this.announce(),this.role;let r=this.orphanPolicy()===`retry`?this.handshakeOptions.maxAttempts:1,i=!1;for(let e=0;e<r&&!i;e++)i=await this.handshake(n);return this.role=i?`forwarder`:`sender`,this.upstream=i?n:null,i||(n!==this.openFinLink&&n.close(),this.diagnostics.report(`bus.handshake_timeout`,`No owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`,{via:n.kind,crossOrigin:this.isCrossOriginFrame()})),this.diagnostics.report(`bus.role_resolved`,`The bus role is ${this.role}.`,{role:this.role,via:i?n.kind:`none`}),this.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 e.t===`sampling?`?t(this.rulesAnswer(e.from),n):this.receive(e,n)}attachWorker(e){this.links.push(f(e,this.receive,this.diagnostics))}broadcastJourney(e){this.post({t:`journey`,from:this.contextId,journey:e})}destroy(){this.destroyed=!0,clearInterval(this.rulesPoll),this.rulesPoll=void 0;for(let e of this.allLinks())e.close();this.links.length=0,this.upstream=null,this.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`sampling?`:(this.role===`forwarder`?t.link!==this.upstream?.kind:this.canOwn(t.link))&&this.postOver(t.link,this.rulesAnswer(e.from));break;case`sampling`:this.acceptsRules(e.to,t)&&this.applyRules(e.rules);break;case`tab`:t.link===`broadcast`&&e.tabId===this.tabId&&this.contextId>e.from&&this.handlers.onTabConflict()}};canRelay(e){return e===`direct`||e!==this.upstream?.kind}canOwn(e){return this.role===`sender`?e===`openfin`?this.isOpenFinProvider:m.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?d(this.receive,this.diagnostics):this.platform.isTopLevelDocument?this.platform.platform===`openfin`&&!this.isOpenFinProvider?this.ensureOpenFinLink():null:s(this.receive,this.diagnostics)}openControlLinks(){let t=e=>{e&&this.links.push(e)};this.platform.isTopLevelDocument&&(t(c(this.receive,this.config.bus.trustedOrigins,this.diagnostics)),t(l(e.b,this.receive,this.diagnostics))),(this.platform.platform===`openfin`||this.platform.platform===`openfin_web`)&&t(this.ensureOpenFinLink())}ensureOpenFinLink(){return this.openFinLink??=u(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}),this.pollRules()}rulesAnswer(e){let t=this.handlers.remote.sampling?.wire()??null;return{t:`sampling`,from:this.contextId,to:e,rules:t}}acceptsRules(e,t){if(this.role!==`forwarder`||e!==this.contextId||t.link!==this.upstream?.kind)return!1;let{origin:n}=t;return t.link===`parent`&&n!==location.origin&&!this.config.bus.trustedOrigins.includes(n)?(this.diagnostics.report(`bus.untrusted_origin`,`The bus ignored sampling rules from ${n}. If you own this origin, add it to bus.trustedOrigins.`,{origin:n,type:`sampling`}),!1):!0}applyRules(e){if(e===null){n.t(this.handlers.remote,this.config,null);return}let t=n.n(e,this.diagnostics);t&&n.t(this.handlers.remote,this.config,t)}pollRules(){let{upstream:n}=this;if(this.destroyed||this.role!==`forwarder`||!n)return;let r=()=>{this.config.sampling.remote&&n.post({t:`sampling?`,from:this.contextId})};r(),this.rulesPoll=setInterval(r,e.Et),t.t(this.rulesPoll)}};exports.Bus=h;
|
|
2
|
-
//# sourceMappingURL=bus-CUXRY0JR.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bus-CUXRY0JR.cjs","names":["BUS_PROTOCOL","RUNTIME_GLOBAL_KEY","BUS_HANDSHAKE_TIMEOUT_MS","BUS_CHANNEL_NAME","parseRemoteRules","REMOTE_SAMPLING_POLL_MS","require_constants","require_unref","require_remote_rules","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","rules","to","update","upstream","ask"],"sources":["../src/models/bus.ts","../src/bus/links.ts","../src/bus/bus.ts"],"sourcesContent":["// src/models/bus.ts\n//\n// Protocol types, message definitions, and envelope encoding for bus messages between realms.\n\nimport { BUS_PROTOCOL } from \"../constants\";\nimport type { 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 * Kind of transport channel. The bus uses it to route incoming and outgoing messages.\n * Without it, `receive` cannot tell the channels apart. Then a same-origin iframe\n * looks like a duplicated tab.\n */\nexport type LinkKind =\n /** Synchronous call into a same-origin parent runtime. */\n | \"direct\"\n /** postMessage to a parent window. */\n | \"parent\"\n /** postMessage to child frames. */\n | \"children\"\n /** BroadcastChannel across same-origin tabs and windows. */\n | \"broadcast\"\n /** OpenFin InterApplicationBus across desktop views and applications. */\n | \"openfin\"\n /** Dedicated worker communication to its owning document. */\n | \"owner\"\n /** Document-side communication to a dedicated worker. */\n | \"worker\";\n\n/** Origin and transport metadata for an incoming bus message. */\nexport interface MessageSource {\n /** Inbound transport channel kind. */\n link: LinkKind;\n /** `event.origin` for `parent` and `children`. Other links use `\"same-origin\"` or `\"openfin\"`. */\n origin: string;\n}\n\n/** Discriminated union of control and telemetry payload messages. */\nexport type BusMessage =\n /** Handshake discovery announcement from a starting forwarder. */\n | { t: \"hello\"; from: string; tabId: string }\n /**\n * Handshake response from an upstream owner. The `to` field holds the address.\n * A welcome on InterApplicationBus goes to every subscriber. Without an address,\n * each waiting view accepts the welcome as its own.\n */\n | { t: \"welcome\"; from: string; to: string; tabId: string }\n /** Telemetry log records forwarded to an upstream sender. */\n | { t: \"records\"; from: string; records: LogRecord[] }\n /** 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 /** Request of a forwarder for the remote sampling rules in force. */\n | { t: \"sampling?\"; from: string }\n /**\n * Remote sampling rules in the shape of the header, with the remaining TTL. The `to` field\n * holds the address of the forwarder that asked. The receiver validates `rules` again.\n * Null rules end the copy of the forwarder.\n */\n | { t: \"sampling\"; from: string; to: string; rules: unknown };\n\n/** Transport envelope wrapping bus messages with a protocol version tag. */\nexport interface BusEnvelope {\n /** Protocol version identifier. */\n p: typeof BUS_PROTOCOL;\n /** Encapsulated bus payload. */\n m: BusMessage;\n}\n\n/**\n * Wraps a bus message in a versioned protocol envelope.\n * @param message Message to encapsulate.\n * @returns Envelope ready for transport.\n */\nexport function envelope(message: BusMessage): BusEnvelope {\n return { p: BUS_PROTOCOL, m: message };\n}\n\n/**\n * Validates the protocol tag and unpacks a raw payload into a bus message. A\n * document gets `message` events from all embedded content on the page. This\n * includes analytics tags, video players and extensions. Without the tag check,\n * the bus parses a message from a video player as a log record.\n * @param data Raw payload received over a transport link.\n * @returns Validated message, or null if payload is invalid or unrecognized.\n */\nexport function unwrap(data: unknown): BusMessage | null {\n if (typeof data !== \"object\" || data === null) {\n return null;\n }\n\n // Validates payload structure at runtime without assuming envelope fields exist.\n const wrapper = data as Record<string, unknown>;\n if (wrapper.p !== BUS_PROTOCOL || typeof wrapper.m !== \"object\" || wrapper.m === null) {\n return null;\n }\n\n const message = wrapper.m as Record<string, unknown>;\n if (typeof message.t !== \"string\") {\n return null;\n }\n\n return message as unknown as BusMessage;\n}\n","// src/bus/links.ts\n//\n// Communication link implementations for direct, frame, broadcast, OpenFin, and worker channels.\n\nimport { 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 that a same-origin parent runtime exposes on a global symbol. */\nexport interface DirectHost {\n /**\n * Accepts a message directly from a child frame and replies synchronously.\n * @param message Child bus message.\n * @param reply Callback for synchronous response.\n */\n busAccept(message: BusMessage, reply: Receive): void;\n}\n\n/** Message port or dedicated/shared worker interface. */\nexport interface WorkerLike {\n /**\n * Sends a message to the worker or port.\n * @param message Payload to send.\n */\n postMessage(message: unknown): void;\n\n /**\n * Subscribes to incoming message events.\n * @param type Event name (\"message\").\n * @param listener Event handler callback.\n */\n addEventListener(type: \"message\", listener: (event: MessageEvent) => void): void;\n\n /**\n * Unsubscribes from message events.\n * @param type Event name (\"message\").\n * @param listener Event handler to remove.\n */\n removeEventListener(type: \"message\", listener: (event: MessageEvent) => void): void;\n\n /** Starts message delivery on MessagePort instances. */\n start?: () => void;\n}\n\n/** Global symbol used to look up same-origin parent runtime instances. */\nconst RUNTIME_KEY = Symbol.for(RUNTIME_GLOBAL_KEY);\n\n/**\n * Establishes direct synchronous communication with a same-origin parent runtime.\n * @param receive Callback for parent replies.\n * @param diagnostics Diagnostics reporter.\n * @returns Direct link, or null if parent is inaccessible or lacks a runtime.\n */\nexport function createDirectLink(receive: Receive, diagnostics: Diagnostics): Link | null {\n if (typeof window === \"undefined\" || window.parent === window) {\n return null;\n }\n\n let host: DirectHost | undefined;\n try {\n const parentGlobal = window.parent as unknown as Record<symbol, DirectHost | undefined>;\n host = parentGlobal[RUNTIME_KEY];\n } catch {\n // Cross-origin access throws on read.\n return null;\n }\n if (typeof host?.busAccept !== \"function\") {\n return null;\n }\n\n const target = host;\n let open = true;\n\n return {\n kind: \"direct\",\n post(message) {\n if (!open) {\n return;\n }\n\n // Stops an error in the parent runtime from breaking a logging call in the child.\n diagnostics.guard(\n \"bus.send_failed\",\n \"The direct call into the parent runtime failed.\",\n () => {\n target.busAccept(message, receive);\n },\n );\n },\n close() {\n open = false;\n },\n };\n}\n\n/**\n * Creates a postMessage link to 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 // This context trusts the parent because it selected the parent as its upstream.\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\", \"The postMessage call to the parent failed.\", () => {\n // An outbound \"*\" target is safe. The payload holds only this context's records.\n // The parent already gets these records by another path.\n // For inbound trust, 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 // The map keeps the origin of each source.\n // A child that navigates must not get the ids of its previous origin.\n const sources = new Map<MessageEventSource, string>();\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (!message) {\n return;\n }\n if (!trusted.has(event.origin)) {\n diagnostics.report(\n \"bus.untrusted_origin\",\n `The bus ignored a message from ${event.origin}. If you own this origin, add it to bus.trustedOrigins.`,\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(\n \"bus.send_failed\",\n \"The postMessage call to a child frame failed.\",\n () => {\n // Targets the last known origin of the child. The browser drops the\n // message if the child navigated to a different origin.\n target.postMessage(envelope(message), origin);\n },\n );\n }\n },\n close() {\n removeEventListener(\"message\", onMessage);\n sources.clear();\n },\n };\n}\n\n/**\n * Creates a same-origin BroadcastChannel link for cross-tab control messages.\n * @param channelName BroadcastChannel identifier.\n * @param receive Callback for incoming cross-tab messages.\n * @param diagnostics Diagnostics reporter.\n * @returns Broadcast link, or null if unsupported.\n */\nexport function createBroadcastLink(\n channelName: string,\n receive: Receive,\n diagnostics: Diagnostics,\n): Link | null {\n const BC = (globalThis as { BroadcastChannel?: typeof BroadcastChannel }).BroadcastChannel;\n if (typeof BC === \"undefined\") {\n return null;\n }\n\n const channel = diagnostics.guard(\n \"bus.send_failed\",\n \"The library could not open the BroadcastChannel.\",\n () => new BC(channelName),\n );\n if (!channel) {\n return null;\n }\n\n channel.onmessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (message) {\n receive(message, { link: \"broadcast\", origin: \"same-origin\" });\n }\n };\n\n return {\n kind: \"broadcast\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"The BroadcastChannel.postMessage call failed.\", () => {\n channel.postMessage(envelope(message));\n });\n },\n close() {\n diagnostics.guard(\n \"bus.send_failed\",\n \"The library could not close the BroadcastChannel.\",\n () => {\n channel.close();\n },\n );\n },\n };\n}\n\n/** 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() sends to every subscriber on the runtime. Without a uuid scope,\n // this link shares the bus of this app with all other apps.\n diagnostics.report(\n \"openfin.unavailable\",\n \"OpenFin gives no application uuid. The InterApplicationBus link stays closed.\",\n );\n return null;\n }\n\n // The topic and the subscriber identity both contain the uuid. The topic keeps\n // messages of this app from other apps. The identity rejects messages from other apps.\n const scoped = `${topic}.${appUuid}`;\n\n void diagnostics.guardAsync(\n \"bus.send_failed\",\n \"The InterApplicationBus.subscribe call failed.\",\n () =>\n iab.subscribe({ uuid: appUuid }, scoped, (raw) => {\n const message = unwrap(raw);\n if (message) {\n receive(message, { link: \"openfin\", origin: \"openfin\" });\n }\n }),\n );\n\n return {\n kind: \"openfin\",\n post(message) {\n void diagnostics.guardAsync(\n \"bus.send_failed\",\n \"The InterApplicationBus.publish call failed.\",\n () => iab.publish(scoped, envelope(message)),\n );\n },\n close() {\n // OpenFin removes the subscriptions when the context closes.\n },\n };\n}\n\n/**\n * Creates the worker-side link pointing at the document that created this\n * worker. Emits `kind: \"owner\"`.\n * @param receive Callback for incoming messages from the owning document.\n * @param diagnostics Diagnostics reporter.\n * @returns Owner link, or null outside a DedicatedWorkerGlobalScope.\n */\nexport function createOwnerLink(receive: Receive, diagnostics: Diagnostics): Link | null {\n const scope = globalThis as unknown as {\n postMessage?: (message: unknown) => void;\n addEventListener?: (type: string, listener: (event: MessageEvent) => void) => void;\n WorkerGlobalScope?: unknown;\n };\n const send = scope.postMessage;\n if (typeof scope.WorkerGlobalScope === \"undefined\" || !send) {\n return null;\n }\n\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (message) {\n receive(message, { link: \"owner\", origin: \"same-origin\" });\n }\n };\n scope.addEventListener?.(\"message\", onMessage);\n\n return {\n kind: \"owner\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"The postMessage call of the worker failed.\", () => {\n send(envelope(message));\n });\n },\n close() {\n // Worker scope listeners stop when the worker stops.\n },\n };\n}\n\n/**\n * Creates the document-side link pointing at one attached worker or port.\n * Emits `kind: \"worker\"`.\n * @param worker Target worker instance or MessagePort.\n * @param receive Callback for messages from the worker.\n * @param diagnostics Diagnostics reporter.\n * @returns Document-to-worker link.\n */\nexport function createWorkerLink(\n worker: WorkerLike,\n receive: Receive,\n diagnostics: Diagnostics,\n): Link {\n const onMessage = (event: MessageEvent): void => {\n const message = unwrap(event.data);\n if (message) {\n receive(message, { link: \"worker\", origin: \"same-origin\" });\n }\n };\n worker.addEventListener(\"message\", onMessage);\n\n // Starts delivery on a MessagePort. A Worker has no start method.\n worker.start?.();\n\n return {\n kind: \"worker\",\n post(message) {\n diagnostics.guard(\"bus.send_failed\", \"The postMessage call to a worker failed.\", () => {\n worker.postMessage(envelope(message));\n });\n },\n close() {\n worker.removeEventListener(\"message\", onMessage);\n },\n };\n}\n","// src/bus/bus.ts\n//\n// Resolves the bus role and routes messages between realms.\n\nimport {\n BUS_CHANNEL_NAME,\n BUS_HANDSHAKE_TIMEOUT_MS,\n BUS_MAX_HANDSHAKE_ATTEMPTS,\n REMOTE_SAMPLING_POLL_MS,\n} from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { Journey } from \"../core/journey\";\nimport { applyRemote, parseRemoteRules } from \"../core/remote-rules\";\nimport type { RemoteSlot } from \"../core/remote-sampling\";\nimport type { BusMessage, BusRole, LinkKind, MessageSource } from \"../models/bus\";\nimport type { 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 /** Maximum time that a forwarder waits for an owner to answer, in milliseconds. */\n timeoutMs: number;\n /** Attempts allowed before a cross-origin forwarder promotes itself to sender. */\n maxAttempts: number;\n}\n\n/** Default handshake timing. Tests build a bus with shorter values. */\nexport const HANDSHAKE_OPTIONS: HandshakeOptions = {\n timeoutMs: BUS_HANDSHAKE_TIMEOUT_MS,\n maxAttempts: BUS_MAX_HANDSHAKE_ATTEMPTS,\n};\n\n/** Callbacks for handling records and journey events from connected realms. */\nexport interface BusHandlers {\n /** Processes records forwarded from child contexts. */\n onRecords: (records: LogRecord[]) => void;\n /** Applies journey updates received from the control bus. */\n onJourney: (journey: Journey | null) => void;\n /** Returns the active journey to a child context that requests it. */\n onJourneyRequest: () => Journey | null;\n /** Runs when two windows use the same tab identifier. */\n onTabConflict: () => void;\n /** Slot of the runtime for the remote sampling rules. The bus reads it and fills it. */\n remote: RemoteSlot;\n}\n\n/** Link types that a sender context may claim ownership over during handshakes. */\nconst OWNED: readonly LinkKind[] = [\"children\", \"direct\", \"worker\"];\n\n/** 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. The default is \"sender\". */\n private role: BusRole = \"sender\";\n /** Upstream forwarding link, or null when acting as sender. */\n private upstream: Link | null = null;\n /** Open control plane links. */\n private readonly links: Link[] = [];\n /** Shared OpenFin InterApplicationBus link instance. */\n private openFinLink: Link | null = null;\n /** 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 /** Timer that asks the upstream owner for the remote sampling rules. */\n private rulesPoll: ReturnType<typeof setInterval> | undefined;\n /** True after destroy(). A handshake that ends later must not start a timer. */\n private destroyed = false;\n /** 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\". No owner exists. The library drops the records of this context.',\n );\n }\n }\n this.resolved = true;\n this.announce();\n return this.role;\n }\n\n this.openControlLinks();\n\n // A same-origin parent runtime accepts a direct synchronous link.\n const direct = createDirectLink(this.receive, this.diagnostics);\n if (direct) {\n this.role = \"forwarder\";\n this.upstream = direct;\n this.resolved = true;\n this.diagnostics.report(\n \"bus.role_resolved\",\n \"This context attached directly to the runtime of its same-origin parent.\",\n {\n role: \"forwarder\",\n via: \"direct\",\n },\n );\n this.announce();\n return this.role;\n }\n\n const candidate = this.candidateUpstream();\n\n if (!candidate) {\n this.role = \"sender\";\n this.resolved = true;\n this.diagnostics.report(\n \"bus.role_resolved\",\n \"No owner exists. This context sends its own records.\",\n {\n role: \"sender\",\n },\n );\n this.announce();\n return this.role;\n }\n\n const attempts = this.orphanPolicy() === \"retry\" ? this.handshakeOptions.maxAttempts : 1;\n\n let welcomed = false;\n for (let attempt = 0; attempt < attempts && !welcomed; attempt++) {\n welcomed = await this.handshake(candidate);\n }\n\n this.role = welcomed ? \"forwarder\" : \"sender\";\n this.upstream = welcomed ? candidate : null;\n if (!welcomed) {\n // OpenFin link remains open for control messages.\n if (candidate !== this.openFinLink) {\n candidate.close();\n }\n this.diagnostics.report(\n \"bus.handshake_timeout\",\n `No owner answered after ${String(attempts)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`,\n { via: candidate.kind, crossOrigin: this.isCrossOriginFrame() },\n );\n }\n this.diagnostics.report(\"bus.role_resolved\", `The bus role is ${this.role}.`, {\n role: this.role,\n via: welcomed ? candidate.kind : \"none\",\n });\n\n this.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 // A direct link has no channel from the parent to the child. The parent answers here.\n if (message.t === \"sampling?\") {\n reply(this.rulesAnswer(message.from), source);\n return;\n }\n this.receive(message, source);\n }\n\n /**\n * Connects a worker instance to the bus control plane.\n * @param worker Worker instance.\n */\n attachWorker(worker: WorkerLike): void {\n this.links.push(createWorkerLink(worker, this.receive, this.diagnostics));\n }\n\n /**\n * 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 this.destroyed = true;\n clearInterval(this.rulesPoll);\n this.rulesPoll = undefined;\n for (const link of this.allLinks()) {\n link.close();\n }\n this.links.length = 0;\n this.upstream = null;\n this.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 only over links of the given kind. */\n private postOver(link: LinkKind, message: BusMessage): void {\n for (const candidate of this.allLinks()) {\n if (candidate.kind === link) {\n candidate.post(message);\n }\n }\n }\n\n /** 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 \"sampling?\":\n // A forwarder answers only its own children. A sibling on its upstream link asks too.\n // A sibling answer on OpenFin gives N squared messages, and a stale copy can win.\n if (\n this.role === \"forwarder\" ? source.link !== this.upstream?.kind : this.canOwn(source.link)\n ) {\n this.postOver(source.link, this.rulesAnswer(message.from));\n }\n break;\n\n case \"sampling\":\n if (this.acceptsRules(message.to, source)) {\n this.applyRules(message.rules);\n }\n break;\n\n case \"tab\":\n // A collision applies only to two different contexts on the broadcast channel.\n // The id comparison selects one context of the pair.\n // Without it, both contexts report the conflict and rename.\n if (\n source.link === \"broadcast\" &&\n message.tabId === this.tabId &&\n this.contextId > message.from\n ) {\n this.handlers.onTabConflict();\n }\n break;\n }\n };\n\n /**\n * Tells whether records from a link can go upstream. Records that go back on\n * their arrival link return to their sender. A direct link is an exception.\n * Each direct link is one call into one parent. Thus two direct links in a\n * chain are different links.\n * @param link Kind of the link the records arrived on.\n * @returns True if the relay is safe.\n */\n private canRelay(link: LinkKind): boolean {\n return link === \"direct\" || link !== this.upstream?.kind;\n }\n\n /** Returns 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 // A cross-origin parent throws on this read. Lint rejects a bare property read.\n Reflect.get(window.parent, \"location\");\n return false;\n } catch {\n return true;\n }\n }\n\n /** Identifies the candidate upstream link based on platform hierarchy. */\n private candidateUpstream(): Link | null {\n if (this.platform.isWorker) {\n return createOwnerLink(this.receive, this.diagnostics);\n }\n if (!this.platform.isTopLevelDocument) {\n return createParentLink(this.receive, this.diagnostics);\n }\n if (this.platform.platform === \"openfin\" && !this.isOpenFinProvider) {\n return this.ensureOpenFinLink();\n }\n return null;\n }\n\n /** Opens control links supported by the current runtime environment. */\n private openControlLinks(): void {\n const push = (link: Link | null): void => {\n if (link) {\n this.links.push(link);\n }\n };\n\n if (this.platform.isTopLevelDocument) {\n push(createChildrenLink(this.receive, this.config.bus.trustedOrigins, this.diagnostics));\n push(createBroadcastLink(BUS_CHANNEL_NAME, this.receive, this.diagnostics));\n }\n if (this.platform.platform === \"openfin\" || this.platform.platform === \"openfin_web\") {\n push(this.ensureOpenFinLink());\n }\n }\n\n /** Returns the singleton OpenFin InterApplicationBus link. */\n private ensureOpenFinLink(): Link | null {\n this.openFinLink ??= createOpenFinLink(\n BUS_CHANNEL_NAME,\n this.platform.openfinUuid,\n this.receive,\n this.diagnostics,\n );\n return this.openFinLink;\n }\n\n /**\n * Executes a hello/welcome handshake over candidate link.\n * @param candidate Upstream link candidate.\n * @returns True if welcome response arrived before timeout.\n */\n private handshake(candidate: Link): Promise<boolean> {\n return new Promise((resolve) => {\n let settled = false;\n\n const finish = (result: boolean): void => {\n if (settled) {\n return;\n }\n settled = true;\n this.awaitingWelcome = null;\n clearTimeout(timer);\n resolve(result);\n };\n\n this.awaitingWelcome = { link: candidate.kind, settle: finish };\n // finish reads timer, which the code declares after finish. This order is safe.\n // finish can run only after the post below. The timer exists at that time.\n const timer = setTimeout(() => {\n finish(false);\n }, this.handshakeOptions.timeoutMs);\n unrefTimer(timer);\n candidate.post({ t: \"hello\", from: this.contextId, tabId: this.tabId });\n });\n }\n\n /** Broadcasts tab claim and queries existing journey state. */\n private announce(): void {\n this.postOver(\"broadcast\", {\n t: \"tab\",\n from: this.contextId,\n tabId: this.tabId,\n });\n this.post({ t: \"journey?\", from: this.contextId });\n this.pollRules();\n }\n\n /**\n * Builds the answer to a sampling question. Null rules end the copy of the forwarder.\n * @param to Context id of the forwarder that asked.\n * @returns The answer.\n */\n private rulesAnswer(to: string): BusMessage {\n const rules = this.handlers.remote.sampling?.wire() ?? null;\n\n return { t: \"sampling\", from: this.contextId, to, rules };\n }\n\n /**\n * Tests whether this context accepts sampling rules from a source.\n * @param to Context id that the answer names.\n * @param source Link and origin of the answer.\n * @returns True only for an answer from the upstream owner to this context.\n */\n private acceptsRules(to: string, source: MessageSource): boolean {\n // Accept rules only from the upstream owner. A sibling on a shared link is not trusted.\n if (this.role !== \"forwarder\" || to !== this.contextId || source.link !== this.upstream?.kind) {\n return false;\n }\n\n // A page on another origin can embed this app. It must not lower minLevel and read the records.\n const { origin } = source;\n\n if (\n source.link === \"parent\" &&\n origin !== location.origin &&\n !this.config.bus.trustedOrigins.includes(origin)\n ) {\n this.diagnostics.report(\n \"bus.untrusted_origin\",\n `The bus ignored sampling rules from ${origin}. If you own this origin, add it to bus.trustedOrigins.`,\n { origin, type: \"sampling\" },\n );\n return false;\n }\n\n return true;\n }\n\n /**\n * Applies the rules of an answer. It ignores rules that are not valid.\n * @param raw Rules of the answer, or null when the upstream has none.\n */\n private applyRules(raw: unknown): void {\n if (raw === null) {\n applyRemote(this.handlers.remote, this.config, null);\n return;\n }\n\n const update = parseRemoteRules(raw, this.diagnostics);\n\n if (update) {\n applyRemote(this.handlers.remote, this.config, update);\n }\n }\n\n /**\n * Asks the upstream owner for the remote sampling rules now, then at each poll interval.\n * A direct link cannot push the rules to a child. A poll works on each link kind.\n */\n private pollRules(): void {\n const { upstream } = this;\n\n if (this.destroyed || this.role !== \"forwarder\" || !upstream) {\n return;\n }\n\n // Read the config at each poll. A later configure() can turn remote sampling on or off.\n const ask = (): void => {\n if (this.config.sampling.remote) {\n upstream.post({ t: \"sampling?\", from: this.contextId });\n }\n };\n\n ask();\n this.rulesPoll = setInterval(ask, REMOTE_SAMPLING_POLL_MS);\n unrefTimer(this.rulesPoll);\n }\n}\n"],"mappings":"uHAgFA,SAAgBS,EAAS,EAAkC,CACzD,MAAO,CAAE,EAAGT,EAAAA,EAAc,EAAGU,CAAQ,CACvC,CAUA,SAAgBC,EAAO,EAAkC,CACvD,GAAI,OAAOC,GAAS,WAAYA,EAC9B,OAAO,KAIT,IAAMC,EAAUD,EAChB,GAAIC,EAAQ,IAAA,sBAAsB,OAAOA,EAAQ,GAAM,UAAYA,EAAQ,IAAM,KAC/E,OAAO,KAGT,IAAMH,EAAUG,EAAQ,EAKxB,OAJI,OAAOH,EAAQ,GAAM,SAIl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