@utk09/ui-observability 0.8.0 → 0.9.1
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 +95 -0
- package/README.md +75 -48
- package/dist/batch-DEK4bv9N.js +31 -0
- package/dist/batch-DEK4bv9N.js.map +1 -0
- package/dist/batch-DEVFs28i.cjs +2 -0
- package/dist/batch-DEVFs28i.cjs.map +1 -0
- package/dist/bus/bus.d.ts +46 -12
- package/dist/bus/links.d.ts +6 -3
- package/dist/bus-DNFvTkif.cjs +2 -0
- package/dist/bus-DNFvTkif.cjs.map +1 -0
- package/dist/{bus-DPDrlUBY.js → bus-HVQ8E72V.js} +128 -71
- package/dist/bus-HVQ8E72V.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-C9Y639mn.js +82 -0
- package/dist/console-C9Y639mn.js.map +1 -0
- package/dist/console-DssDxq1B.cjs +2 -0
- package/dist/console-DssDxq1B.cjs.map +1 -0
- package/dist/constants-N99w84xy.js +117 -0
- package/dist/constants-N99w84xy.js.map +1 -0
- package/dist/constants-X86IDwkC.cjs +2 -0
- package/dist/constants-X86IDwkC.cjs.map +1 -0
- package/dist/constants.d.ts +36 -18
- package/dist/core/diagnostics.d.ts +2 -2
- package/dist/core/drops.d.ts +29 -0
- package/dist/core/hold-buffer.d.ts +27 -0
- package/dist/core/journey.d.ts +16 -4
- package/dist/core/logger.d.ts +6 -2
- package/dist/core/pipeline.d.ts +20 -16
- package/dist/core/record.d.ts +11 -6
- package/dist/core/remote-sampling.d.ts +1 -1
- package/dist/core/runtime.d.ts +87 -23
- package/dist/core/sender.d.ts +19 -11
- package/dist/deadline-5_PecIl5.js +26 -0
- package/dist/deadline-5_PecIl5.js.map +1 -0
- package/dist/deadline-XSnm95pg.cjs +2 -0
- package/dist/deadline-XSnm95pg.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-BTWuVnHZ.cjs +3 -0
- package/dist/errors-BTWuVnHZ.cjs.map +1 -0
- package/dist/{errors-Dnc-X4Ec.js → errors-CQusIGWJ.js} +39 -20
- package/dist/errors-CQusIGWJ.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/identity-B1GDS1Tb.cjs +2 -0
- package/dist/identity-B1GDS1Tb.cjs.map +1 -0
- package/dist/identity-D4DPjTM9.js +88 -0
- package/dist/identity-D4DPjTM9.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.js +720 -446
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-uD4oaRMc.js → indexeddb-storage-B8SGUzSV.js} +88 -59
- package/dist/indexeddb-storage-B8SGUzSV.js.map +1 -0
- package/dist/indexeddb-storage-ukzC82dm.cjs +2 -0
- package/dist/indexeddb-storage-ukzC82dm.cjs.map +1 -0
- package/dist/interactions-CcxrVzpg.cjs +2 -0
- package/dist/interactions-CcxrVzpg.cjs.map +1 -0
- package/dist/{interactions-igKTAJvj.js → interactions-CnjfQgw3.js} +22 -19
- package/dist/interactions-CnjfQgw3.js.map +1 -0
- package/dist/journey-DjvDzHyp.js +163 -0
- package/dist/journey-DjvDzHyp.js.map +1 -0
- package/dist/journey-DxlfdFJV.cjs +2 -0
- package/dist/journey-DxlfdFJV.cjs.map +1 -0
- package/dist/{library-request-Br_T09Bn.cjs → library-request-BZ1ekVtl.cjs} +2 -2
- package/dist/{library-request-Br_T09Bn.cjs.map → library-request-BZ1ekVtl.cjs.map} +1 -1
- package/dist/{library-request-Dt0fXhcn.js → library-request-C8kc5YWv.js} +2 -2
- package/dist/{library-request-Dt0fXhcn.js.map → library-request-C8kc5YWv.js.map} +1 -1
- package/dist/{long-frames-DahhqM6u.cjs → long-frames-BGik_Yhy.cjs} +2 -2
- package/dist/{long-frames-DahhqM6u.cjs.map → long-frames-BGik_Yhy.cjs.map} +1 -1
- package/dist/{long-frames-6pnjWSSR.js → long-frames-CZk3XOkH.js} +3 -3
- package/dist/{long-frames-6pnjWSSR.js.map → long-frames-CZk3XOkH.js.map} +1 -1
- package/dist/models/batch.d.ts +15 -1
- package/dist/models/bus.d.ts +7 -4
- package/dist/models/config.d.ts +189 -12
- package/dist/models/drop.d.ts +39 -0
- package/dist/models/log-record.d.ts +12 -6
- package/dist/models/storage.d.ts +15 -3
- package/dist/network-51iicpLl.js +174 -0
- package/dist/network-51iicpLl.js.map +1 -0
- package/dist/network-jBbjyAJP.cjs +2 -0
- package/dist/network-jBbjyAJP.cjs.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-Cjts-8k8.js +48 -0
- package/dist/platform-Cjts-8k8.js.map +1 -0
- package/dist/{platform-D_XkVIF6.cjs → platform-DW3GFIUE.cjs} +2 -2
- package/dist/platform-DW3GFIUE.cjs.map +1 -0
- package/dist/{remote-rules-rJJZKVG8.cjs → remote-rules-ByS34k4e.cjs} +2 -2
- package/dist/remote-rules-ByS34k4e.cjs.map +1 -0
- package/dist/{remote-rules-5UA23alm.js → remote-rules-M-XZ1xbe.js} +14 -14
- package/dist/remote-rules-M-XZ1xbe.js.map +1 -0
- package/dist/sampling-BN3Oi6SV.js +63 -0
- package/dist/sampling-BN3Oi6SV.js.map +1 -0
- package/dist/sampling-b2ck5X98.cjs +2 -0
- package/dist/sampling-b2ck5X98.cjs.map +1 -0
- package/dist/sanitize-DKp5MRsa.cjs +2 -0
- package/dist/sanitize-DKp5MRsa.cjs.map +1 -0
- package/dist/sanitize-Dwj9JCkI.js +123 -0
- package/dist/sanitize-Dwj9JCkI.js.map +1 -0
- package/dist/{sender-G6v4Uqi4.js → sender-BBY0IcUo.js} +439 -322
- package/dist/sender-BBY0IcUo.js.map +1 -0
- package/dist/sender-BXoAZKum.cjs +3 -0
- package/dist/sender-BXoAZKum.cjs.map +1 -0
- package/dist/storage/emergency-queue.d.ts +5 -2
- package/dist/storage/eviction.d.ts +40 -0
- package/dist/storage/factory.d.ts +1 -1
- package/dist/storage/idb-driver.d.ts +7 -1
- package/dist/storage/indexeddb-storage.d.ts +13 -5
- package/dist/storage/local-storage.d.ts +27 -4
- package/dist/storage/memory-storage.d.ts +10 -3
- package/dist/{storm-BtzgLOCX.cjs → storm-CKuaBp7i.cjs} +2 -2
- package/dist/{storm-BtzgLOCX.cjs.map → storm-CKuaBp7i.cjs.map} +1 -1
- package/dist/{storm-DJkEZP_8.js → storm-DhtL2eVr.js} +2 -2
- package/dist/{storm-DJkEZP_8.js.map → storm-DhtL2eVr.js.map} +1 -1
- package/dist/transport/compression.d.ts +1 -1
- package/dist/transport/exit-flush.d.ts +27 -17
- package/dist/transport/http-transport.d.ts +61 -7
- package/dist/transport/retry-engine.d.ts +12 -8
- package/dist/transport/status-transport.d.ts +8 -3
- package/dist/utils/console.d.ts +5 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,101 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
+
## [0.9.1] - 2026-10-29
|
|
6
|
+
|
|
7
|
+
### Added - v0.9.1
|
|
8
|
+
|
|
9
|
+
- `batching` sets the batch size and the flush interval of the log stream and of the metric stream. The keys are `logFlushIntervalMs`, `logBatchSize`, `metricFlushIntervalMs` and `metricBatchSize`.
|
|
10
|
+
- `retention` sets `maxBatches`, `maxAgeMs` and `maxAttempts` for undelivered batches.
|
|
11
|
+
- With `retention.mode: "until-delivered"`, a stored batch has no age limit and no attempt limit. `maxBatches` still applies. A permanent error still drops the batch.
|
|
12
|
+
- With `retention.mode: "until-delivered"`, a batch that always gets a temporary error stays first in the queue. The batches behind it wait.
|
|
13
|
+
- `limits` sets the 8 size limits of each record: `maxBodyChars`, `maxAttributeChars`, `maxAttributeCount`, `maxStackChars`, `maxDepth`, `maxArrayLength`, `maxNodes` and `maxRecordBytes`. The console uses the same limits.
|
|
14
|
+
- `journey.maxAgeMs` sets the maximum open time of a journey.
|
|
15
|
+
- Each new key has a range. A value outside its range reports `config.invalid`. The value in force stays.
|
|
16
|
+
- `onDrop(summary)` receives a summary when the library loses records that it built. The summary has `reason`, `records`, `batchIds`, `journeyIds` and `actions`. Sampling, `minLevel` and `redact` do not cause a loss.
|
|
17
|
+
- The library joins the losses of one reason in one task into one summary. Each list holds at most 20 different values.
|
|
18
|
+
- The `onDrop` reasons are `buffer_full`, `expired`, `over_capacity`, `quota`, `max_attempts`, `rejected`, `unserializable`, `exit_queue_full`, `load_failed` and `not_stored`.
|
|
19
|
+
- `load_failed` covers the records that wait for the delivery stack when its load fails. It also covers these records when `shutdown()` comes before the load ends. After a failed load, each new record also reports `load_failed`.
|
|
20
|
+
- `not_stored` covers a failed send that storage did not keep. The cause is an IndexedDB write error or `storage: "none"`.
|
|
21
|
+
- The `onDrop` hook runs inside the library request scope and the library console scope. Network capture and console capture skip its requests and its console lines.
|
|
22
|
+
- Do not log through the library in the `onDrop` hook. A record from the hook can evict a stored batch.
|
|
23
|
+
- `onDrop` can report a batch that storage evicts during its send. The server can still receive that batch.
|
|
24
|
+
- The package exports the types `DropSummary` and `LossReason`.
|
|
25
|
+
|
|
26
|
+
### Changed - v0.9.1
|
|
27
|
+
|
|
28
|
+
- A later `configure()` cannot change `batching` or `retention` after the delivery stack loads. It cannot change `limits` or `journey.maxAgeMs` after the first `configure()`. It reports `config.invalid`. The values in force stay.
|
|
29
|
+
- A log call before `configure()` starts a runtime with defaults. The first `configure()` then sets `batching`, `retention`, `limits` and `journey.maxAgeMs` of that runtime.
|
|
30
|
+
- An action is an audit fact. When storage is over `retention.maxBatches` or over the quota of the browser, it removes the batches without an action first. `retention.maxAgeMs` still removes each old batch.
|
|
31
|
+
- The hold buffers keep up to 2000 actions before startup and while the delivery stack loads. The 500-record limit applies only to the other records.
|
|
32
|
+
- A prune that removes expired batches and batches over `retention.maxBatches` reports each group with its own reason. `storage.evicted` and the gap warning record come one time for each group.
|
|
33
|
+
- With `storage: "none"`, a failed send gives the gap warning record. A throttle limits that record.
|
|
34
|
+
- The gzip size budget of the main graph is 24,400 B. It was 23,700 B.
|
|
35
|
+
|
|
36
|
+
### Fixed - v0.9.1
|
|
37
|
+
|
|
38
|
+
- When a keepalive exit fetch fails or throws, the library puts the batch in the emergency queue. The next page load sends it. Before, the library lost the batch.
|
|
39
|
+
- `shutdown()` gives the forward buffer to the bus before the bus stops. Before, a forwarder lost the records that it logged in the same task as `shutdown()`.
|
|
40
|
+
|
|
41
|
+
## [0.9.0] - 2026-10-28
|
|
42
|
+
|
|
43
|
+
### Breaking changes - v0.9.0
|
|
44
|
+
|
|
45
|
+
- The level methods (`trace`, `debug`, `info`, `warn`, `error`, `fatal`) give records with `log.type: "log"`. It was `"system"`. `"system"` is now for the records of the library itself.
|
|
46
|
+
- A cross-origin child frame forwards its records only to a parent on an origin in its `bus.trustedOrigins`, or on its own origin. It posts to that origin, not to `"*"`. With no trusted parent, the frame sends its own records at once.
|
|
47
|
+
- A sandboxed frame without `allow-same-origin` sends its own records. `bus.untrusted_origin` tells you to set `bus.mode: "sender"` in the frame. Add `allow-same-origin` only for content that you trust.
|
|
48
|
+
- `bus.trustedOrigins` does not accept `"null"`. One `"null"` entry trusts each sandboxed and `data:` document, for example a frame in an ad. Set `bus.mode: "sender"` in your sandboxed frame.
|
|
49
|
+
- `journey.scope` sets which contexts adopt a journey. The default `"auto"` is `"tab"` in a browser. A journey no longer goes to other tabs through the broadcast link. Set `"origin"` for the previous behavior. OpenFin and OpenFin Core Web keep `"origin"`.
|
|
50
|
+
- `minLevel` no longer drops action and metric records. It applies to log, event and system records.
|
|
51
|
+
- A string in `capture.propagateTraceHeaderTo` is an origin. It matches a request to that origin only. Before, it matched a substring of the URL. A string that is not a URL, for example `"/api/"`, reports `config.invalid`. To match a path, use a RegExp that starts with `^`.
|
|
52
|
+
- If the `redact` hook throws or returns a value that is not a record, the library drops the record. It counts the drop as `record.dropped_by_redact`. Before, it sent the record without redaction.
|
|
53
|
+
- This release removes `Sequence.reset()`.
|
|
54
|
+
|
|
55
|
+
### Added - v0.9.0
|
|
56
|
+
|
|
57
|
+
- `fatal(message, error?, payload?)` is a top-level function.
|
|
58
|
+
- `configure()` checks each key: `enabled`, `minLevel`, `console`, `compression`, `credentials`, `headers`, `storage`, `identity`, each `bus`, `journey`, `capture` and `sampling` key. A value of the wrong type reports `config.invalid`. The value in force stays. Level names can have any case. Each `bus.trustedOrigins` entry becomes its origin.
|
|
59
|
+
- `error.data` holds the own string, number and boolean fields of the reason, for example `code`. An object field, for example the `config` of an `AxiosError`, stays out. It holds credentials and request bodies.
|
|
60
|
+
- `timeSync` and `timeAsync` also emit the duration histogram when the function throws or the promise rejects, with `status: "FAILURE"`. The error record and the histogram give the same duration.
|
|
61
|
+
- If a copy of another version owns the page runtime, this copy runs console-only. It installs no capture. It reports `runtime.version_mismatch`. A later `configure()` keeps it console-only. Its log calls and its `shutdown()` do not touch the runtime of the other version.
|
|
62
|
+
- New diagnostic codes: `runtime.version_mismatch` and `record.dropped_no_destination`. The library now also reports `transport.timeout`. It counts `record.dropped_malformed` and `record.sanitize_failed` in more places.
|
|
63
|
+
|
|
64
|
+
### Changed - v0.9.0
|
|
65
|
+
|
|
66
|
+
- When the document becomes hidden, the library runs a normal flush with the headers, gzip and retry. On `pagehide`, `freeze` and OpenFin close, it uses a keepalive fetch with the last headers when `headers` is set. It uses `sendBeacon` only with no custom headers.
|
|
67
|
+
- While the document is hidden, a send of 60 KB or less uses `keepalive`. A mobile OS can stop a hidden page with no `pagehide`. The exit flush does not send that batch again.
|
|
68
|
+
- Until a `headers` function gives its first result, the exit flush puts the batch in the emergency queue. The next page load sends it with the headers.
|
|
69
|
+
- The exit flush sends the cached result of a `headers` function only while that function and the endpoint are in force.
|
|
70
|
+
- With a `redact` hook, a record that `redact` drops prints no console line. Before, the console printed its message.
|
|
71
|
+
- `shutdown()` runs a normal flush before the exit flush.
|
|
72
|
+
- After a 401 or 403, the library calls a `headers` function one more time. It then sends the batch one more time. A second 401 or 403 drops the batch.
|
|
73
|
+
- `flush()` waits for the batches in the queue and in flight. A flush while the server throttles stores the batch for the retry engine. It does not send around the throttle and the concurrency limit.
|
|
74
|
+
- A later `configure()` reinstalls the capture modules only when the `capture` section changes.
|
|
75
|
+
- A capture module restores a host function, for example `fetch` or `history.pushState`, only if the function still holds the wrapper of the library. A wrapper that another script added later stays in place.
|
|
76
|
+
- The library waits 60 s at most after a `Retry-After` answer.
|
|
77
|
+
- The library removes the journey token from the URL after it adopts the token.
|
|
78
|
+
|
|
79
|
+
### Fixed - v0.9.0
|
|
80
|
+
|
|
81
|
+
- The build works on Windows. `npm run verify` runs lint after the build.
|
|
82
|
+
- `headers()` and the gzip encoding run under the 15 s request deadline. A `headers()` that never settles no longer holds a send slot.
|
|
83
|
+
- The emergency queue import runs after the sender starts. It no longer delays startup. It no longer drops records from the boot buffer.
|
|
84
|
+
- OTLP sends an integer above `Number.MAX_SAFE_INTEGER` as `doubleValue`, not as a broken `intValue`.
|
|
85
|
+
- The fetch capture no longer throws on an input with a text form only, on a Request from another realm, or on an input it cannot read. The XHR capture no longer throws on a method that is not a string. The capture never changes the result of the call.
|
|
86
|
+
- The XHR capture sends `traceparent` to the targets in `propagateTraceHeaderTo`.
|
|
87
|
+
- An allowlisted Request from another realm keeps its own headers. The library sends it without `traceparent`.
|
|
88
|
+
- An Error from another realm keeps its name, message and stack in the error capture, the console capture, `log.error()`, `console.args` and `cause`.
|
|
89
|
+
- A failed web-vitals import gets a new attempt when a later `configure()` changes the `capture` section.
|
|
90
|
+
- An oversized error record drops the caller attributes first. It keeps each `error.*` field, then the breadcrumbs if they fit.
|
|
91
|
+
- A breadcrumb holds the body after `redact`.
|
|
92
|
+
- The library drops a record that `redact` breaks in place, or a `redact` result with an unknown `severityText`. It counts the drop as `record.dropped_malformed`. The library sets `severityNumber` from the `severityText` that `redact` returns.
|
|
93
|
+
- A payload or a reason with a throwing getter or Proxy trap no longer throws out of a log call. The record gets `uiobs.sanitize_failed: true`.
|
|
94
|
+
- `logMetric` drops `NaN` and `Infinity`. It counts the drop as `record.dropped_malformed`.
|
|
95
|
+
- The bus checks the shape of each journey message. A journey answer holds the address of the context that asked. Only that context adopts it.
|
|
96
|
+
- A sandboxed page without `allow-same-origin` drops each message from a child frame with the origin `"null"`. Before, it trusted those frames as its own origin.
|
|
97
|
+
- The `bus.untrusted_origin` detail keeps only the first 32 characters of the message type.
|
|
98
|
+
- An oversized record keeps `page.url`, `journey.id` and `journey.name` as `redact` left them. Before, the size limit wrote the values from before `redact` back.
|
|
99
|
+
|
|
5
100
|
## [0.8.0] - 2026-10-14
|
|
6
101
|
|
|
7
102
|
### Added - v0.8.0
|
package/README.md
CHANGED
|
@@ -64,10 +64,10 @@ log.logAction("ORDER_SUBMIT", { orderId: "ORD-1001", qty: 100 });
|
|
|
64
64
|
log.error("pricing call failed", caughtError);
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
- `configure()` is idempotent. A later call updates the runtime singleton in place. You cannot change `storage` or `
|
|
67
|
+
- `configure()` is idempotent. A later call updates the runtime singleton in place. You cannot change `storage`, `identity`, `batching`, `retention`, `limits` or `journey.maxAgeMs` after startup. The library reports that change and ignores it.
|
|
68
68
|
- Call `configure()` from one context in each document. A second call changes `service.name` on the records of every other context. In a composed page, the shell calls `configure()`. Each microfrontend uses its own namespace.
|
|
69
69
|
- You can call `getLogger()` at module top level, before `configure()`. The logger finds the runtime on its first write.
|
|
70
|
-
- A write before the first `configure()` starts a runtime with default settings. It does not throw.
|
|
70
|
+
- A write before the first `configure()` starts a runtime with default settings. It does not throw. The first `configure()` then sets `limits` and `journey.maxAgeMs` of that runtime.
|
|
71
71
|
- After `shutdown()`, every call does nothing until the next `configure()`.
|
|
72
72
|
|
|
73
73
|
### Console Only (No Network)
|
|
@@ -89,7 +89,7 @@ configure({
|
|
|
89
89
|
- `identity: "memory"` writes no key to `localStorage` or `sessionStorage`.
|
|
90
90
|
- `console` and `minLevel` are independent. `console` sets what the library prints. `minLevel` sets what the library sends.
|
|
91
91
|
- The console output does not depend on the bus or the endpoint.
|
|
92
|
-
- With a `redact` hook, the console shows only what `redact` returns. A record below `minLevel` shows its message and error only, because the library does not build it.
|
|
92
|
+
- With a `redact` hook, the console shows only what `redact` returns. A record that `redact` drops prints no line. A record below `minLevel` shows its message and error only, because the library does not build it.
|
|
93
93
|
|
|
94
94
|
### Console Output
|
|
95
95
|
|
|
@@ -249,11 +249,14 @@ X-UiObs-Sampling: {"v":1,"ttlMs":600000,"defaultRate":0.1,"rates":{"blotter.grid
|
|
|
249
249
|
| `info(msg, payload?)` | Logs an INFO record. |
|
|
250
250
|
| `warn(msg, payload?)` | Logs a WARN record. |
|
|
251
251
|
| `error(msg, err?, payload?)` | Logs an ERROR record with the error and the breadcrumb trail. |
|
|
252
|
+
| `fatal(msg, err?, payload?)` | Logs a FATAL record with the error and the breadcrumb trail. |
|
|
252
253
|
| `logAction(name, payload?)` | Logs one user action. |
|
|
253
254
|
| `logEvent(name, payload?)` | Logs one domain or lifecycle event. |
|
|
254
255
|
| `logMetric(name, value, unit?, type?, attrs?)` | Logs a measurement (`gauge`, `counter`, `histogram`). |
|
|
255
|
-
| `timeSync(label, fn, attrs?)` | Times a function and emits a duration histogram
|
|
256
|
-
| `timeAsync(label, fn, attrs?)` | Times a promise and emits a duration histogram
|
|
256
|
+
| `timeSync(label, fn, attrs?)` | Times a function and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
|
|
257
|
+
| `timeAsync(label, fn, attrs?)` | Times a promise and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
|
|
258
|
+
|
|
259
|
+
The level methods give records with `log.type: "log"`. Records of the library itself have `log.type: "system"`. `logMetric` drops a value that is not finite and counts `record.dropped_malformed`.
|
|
257
260
|
|
|
258
261
|
### Context & Correlation
|
|
259
262
|
|
|
@@ -273,47 +276,66 @@ X-UiObs-Sampling: {"v":1,"ttlMs":600000,"defaultRate":0.1,"rates":{"blotter.grid
|
|
|
273
276
|
|
|
274
277
|
### Delivery & Diagnostics
|
|
275
278
|
|
|
276
|
-
| Function | Description
|
|
277
|
-
| ------------------------- |
|
|
278
|
-
| `flush()` | Sends the records held in the pipeline or the forward buffer. |
|
|
279
|
-
| `getQueueDepth()` | Returns the number of batches in storage.
|
|
280
|
-
| `getDiagnosticCounters()` | Returns the count of each diagnostic code.
|
|
279
|
+
| Function | Description |
|
|
280
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
281
|
+
| `flush()` | Sends the records held in the pipeline or the forward buffer, and waits for the batches in flight. |
|
|
282
|
+
| `getQueueDepth()` | Returns the number of batches in storage. |
|
|
283
|
+
| `getDiagnosticCounters()` | Returns the count of each diagnostic code. |
|
|
281
284
|
|
|
282
285
|
---
|
|
283
286
|
|
|
284
287
|
## Configuration Options
|
|
285
288
|
|
|
286
|
-
No key is required. Set `endpoint` to send records.
|
|
287
|
-
|
|
288
|
-
| Key
|
|
289
|
-
|
|
|
290
|
-
| `endpoint`
|
|
291
|
-
| `serviceName`
|
|
292
|
-
| `serviceVersion`
|
|
293
|
-
| `environment`
|
|
294
|
-
| `enabled`
|
|
295
|
-
| `minLevel`
|
|
296
|
-
| `compression`
|
|
297
|
-
| `serializer`
|
|
298
|
-
| `credentials`
|
|
299
|
-
| `headers`
|
|
300
|
-
| `storage`
|
|
301
|
-
| `identity`
|
|
302
|
-
| `sampling.defaultRate`
|
|
303
|
-
| `sampling.rates`
|
|
304
|
-
| `sampling.alwaysSampleTypes`
|
|
305
|
-
| `sampling.remote`
|
|
306
|
-
| `sampling.remoteMaxRate`
|
|
307
|
-
| `bus.mode`
|
|
308
|
-
| `bus.trustedOrigins`
|
|
309
|
-
| `bus.openFinRole`
|
|
310
|
-
| `
|
|
311
|
-
| `
|
|
312
|
-
| `
|
|
313
|
-
| `
|
|
314
|
-
| `
|
|
315
|
-
| `
|
|
316
|
-
| `
|
|
289
|
+
No key is required. Set `endpoint` to send records. A value of the wrong type or outside its range reports `config.invalid`. The value in force stays. Level names can have any case. You cannot change `batching` and `retention` after the delivery stack loads. You cannot change `limits` and `journey.maxAgeMs` after the first `configure()`.
|
|
290
|
+
|
|
291
|
+
| Key | Default | Description |
|
|
292
|
+
| -------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
293
|
+
| `endpoint` | `""` | HTTP endpoint that receives the batches. `null` selects console-only mode. `""` reports `config.invalid`. |
|
|
294
|
+
| `serviceName` | `""` | `service.name` on every record. |
|
|
295
|
+
| `serviceVersion` | `""` | `service.version` on every record. |
|
|
296
|
+
| `environment` | `""` | `deployment.environment` on every record. |
|
|
297
|
+
| `enabled` | `true` | Set `false` to stop all logging. Every log call then does nothing. |
|
|
298
|
+
| `minLevel` | `"INFO"` | Lowest level that the library sends (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). It does not drop actions and metrics. |
|
|
299
|
+
| `compression` | `"gzip"` | `gzip` or `none`. The library compresses a payload above 1 KB only. |
|
|
300
|
+
| `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. |
|
|
301
|
+
| `credentials` | `"omit"` | Fetch credentials mode. Set `"include"` for cookie auth. |
|
|
302
|
+
| `headers` | `{}` | Static headers, or a function that returns them. After a 401 or 403, a function gets one more call and the batch one more send. The exit flush sends the last headers. Before a function gives its first result, the exit flush puts the batch in the emergency queue. `headers: undefined` removes the headers. |
|
|
303
|
+
| `storage` | `"auto"` | Store for undelivered batches: `auto`, `indexeddb`, `localstorage`, `memory` or `none`. Fixed at startup. |
|
|
304
|
+
| `identity` | `"storage"` | Store for session, tab and journey ids. `memory` writes no key. Fixed at startup. |
|
|
305
|
+
| `sampling.defaultRate` | `1` | Keep rate for a namespace with no rule. |
|
|
306
|
+
| `sampling.rates` | `{}` | Keep rate per namespace. The longest matching prefix wins. |
|
|
307
|
+
| `sampling.alwaysSampleTypes` | `["action"]` | Record types that ignore the rate. |
|
|
308
|
+
| `sampling.remote` | `false` | Reads sampling rules from the `X-UiObs-Sampling` header of each accepted batch (see Remote Sampling). |
|
|
309
|
+
| `sampling.remoteMaxRate` | `1` | Highest rate that a remote rule can set. It applies to the remote `defaultRate` and to each remote namespace rate. |
|
|
310
|
+
| `bus.mode` | `"auto"` | `auto`, `sender`, `forwarder` or `off`. With `off`, this context sends its own records and opens no link. A same-origin child frame can still forward to it. |
|
|
311
|
+
| `bus.trustedOrigins` | `[]` | Origins of other documents that this document trusts. A parent accepts records from a child frame on these origins. A cross-origin child frame forwards its records only to a parent on these origins. The library keeps the origin of each URL. For a sandboxed frame, set `bus.mode: "sender"` in the frame. |
|
|
312
|
+
| `bus.openFinRole` | `"auto"` | `auto`, `provider` or `client`. |
|
|
313
|
+
| `journey.scope` | `"auto"` | Which contexts adopt a journey. `context`: each context keeps its own. `tab`: a frame or a worker adopts the journey of its owner. `origin`: each context of the origin, also in other tabs. `auto` is `origin` in OpenFin and `tab` in a browser. |
|
|
314
|
+
| `journey.maxAgeMs` | `1800000` | Maximum open time of a journey, in milliseconds. Then the library ends it. The range is 60000 to 86400000. |
|
|
315
|
+
| `batching.logFlushIntervalMs` | `2000` | Maximum wait of a partial log batch, in milliseconds. The range is 100 to 60000. |
|
|
316
|
+
| `batching.logBatchSize` | `100` | Maximum records in one log batch. The range is 1 to 1000. |
|
|
317
|
+
| `batching.metricFlushIntervalMs` | `10000` | Maximum wait of a partial metric batch, in milliseconds. The range is 100 to 60000. |
|
|
318
|
+
| `batching.metricBatchSize` | `500` | Maximum records in one metric batch. The range is 1 to 1000. |
|
|
319
|
+
| `retention.mode` | `"limited"` | `limited` or `until-delivered`. With `until-delivered`, a stored batch has no age limit and no attempt limit. `retention.maxBatches` still applies. A permanent error still drops the batch. A batch that always gets a temporary error stays first. The batches behind it wait. |
|
|
320
|
+
| `retention.maxBatches` | `500` | Maximum stored batches. A new batch evicts the oldest batch without an action first. The range is 1 to 5000. |
|
|
321
|
+
| `retention.maxAgeMs` | `86400000` | Maximum age of a stored batch, in milliseconds. The range is 60000 to 604800000. |
|
|
322
|
+
| `retention.maxAttempts` | `5` | Maximum send attempts of a stored batch. The range is 1 to 20. |
|
|
323
|
+
| `limits.maxBodyChars` | `4096` | Maximum body length, in characters. The range is 256 to 65536. |
|
|
324
|
+
| `limits.maxAttributeChars` | `8192` | Maximum length of a string attribute, in characters. The range is 256 to 65536. |
|
|
325
|
+
| `limits.maxAttributeCount` | `128` | Maximum keys in one object. The range is 1 to 1024. |
|
|
326
|
+
| `limits.maxStackChars` | `8192` | Maximum length of an error stack, in characters. The range is 256 to 65536. |
|
|
327
|
+
| `limits.maxDepth` | `6` | Maximum depth of a nested value. The range is 1 to 16. |
|
|
328
|
+
| `limits.maxArrayLength` | `100` | Maximum items in one array, set or map. The range is 1 to 10000. |
|
|
329
|
+
| `limits.maxNodes` | `10000` | Maximum values in one sanitize pass. The range is 100 to 100000. |
|
|
330
|
+
| `limits.maxRecordBytes` | `32768` | Maximum attribute bytes of one record. Above it, the library drops the caller attributes. The range is 1024 to 60000. |
|
|
331
|
+
| `capture` | See below | Auto-capture settings. |
|
|
332
|
+
| `console` | `false` | Prints records to devtools. `true` prints from `DEBUG` up. A level name prints from that level up. An object sets `level` and `styles` (see Console Output). It does not depend on `minLevel`. |
|
|
333
|
+
| `transport(request)` | `undefined` | Sends batches through a channel of your app in place of HTTP (see Custom Transport). |
|
|
334
|
+
| `transportOnExit(request)` | `undefined` | Sends the last batch while the page closes. It must return a boolean and must not wait. |
|
|
335
|
+
| `otelLoader()` | `undefined` | Loads `@opentelemetry/api`. Without it, OTel is off. |
|
|
336
|
+
| `redact(record)` | `undefined` | Changes a record before the library sends or prints it. Return `null` to drop the record. If the hook throws or returns a value that is not a record, the library drops the record. It counts `record.dropped_by_redact`. |
|
|
337
|
+
| `onDiagnostic(event)` | `undefined` | Receives the faults of the library itself. |
|
|
338
|
+
| `onDrop(summary)` | `undefined` | Receives a summary when the library loses records that it built. The summary has `reason`, `records`, `batchIds`, `journeyIds` and `actions`. Sampling, `minLevel` and `redact` do not cause a loss. Do not log through the library in the hook. A record from the hook can evict a stored batch. A batch that storage evicts during its send can still reach the server. |
|
|
317
339
|
|
|
318
340
|
### Auto-Capture Options
|
|
319
341
|
|
|
@@ -332,7 +354,7 @@ capture: {
|
|
|
332
354
|
console: false, // App console calls: true, or a list such as ["error", "warn", "info"]
|
|
333
355
|
fullUrls: false, // Keep query strings and fragments on recorded URLs
|
|
334
356
|
ignoreUrls: [], // URL patterns excluded from network capture
|
|
335
|
-
propagateTraceHeaderTo: [], //
|
|
357
|
+
propagateTraceHeaderTo: [], // Origins, or RegExp patterns, that receive traceparent
|
|
336
358
|
}
|
|
337
359
|
```
|
|
338
360
|
|
|
@@ -355,7 +377,9 @@ capture: {
|
|
|
355
377
|
- To record an argument, the library reads each property, also a getter. A getter with a side effect then runs during the console call.
|
|
356
378
|
- On `shutdown()`, the library restores each method. If another script wrapped the method later, the library leaves it and reports `capture.install_failed`.
|
|
357
379
|
|
|
358
|
-
`fullUrls` is off by default. The library then cuts each recorded URL at the first `?` or `#`. This applies to the page URL, the request target and the URL of a failed resource. `ignoreUrls` and `propagateTraceHeaderTo` match the full URL.
|
|
380
|
+
`fullUrls` is off by default. The library then cuts each recorded URL at the first `?` or `#`. This applies to the page URL, the request target and the URL of a failed resource. `ignoreUrls` and a RegExp in `propagateTraceHeaderTo` match the full URL.
|
|
381
|
+
|
|
382
|
+
A string in `propagateTraceHeaderTo` is an origin, for example `"https://api.example"`. It matches a request to that origin only. A URL with a path gives its origin. A relative request URL resolves against the page. To match a path, use a RegExp. A RegExp tests the request URL in the form that the caller gives. Start each RegExp with `^`. Without it, `/\/api\//` also matches `https://vendor.example/api/`. For example, `/^https:\/\/api\.example\/v2\//` matches one path on one origin. `/^\/api\//` matches a relative request URL only.
|
|
359
383
|
|
|
360
384
|
### Browser Storage Keys
|
|
361
385
|
|
|
@@ -378,11 +402,14 @@ IndexedDB holds undelivered batches with `storage: "auto"` or `"indexeddb"`.
|
|
|
378
402
|
- **Document singleton:** The library keeps the runtime at `globalThis[Symbol.for("ui-observability.runtime")]`. Federated microfrontends and separate bundles share one buffer, one sequence and one transport.
|
|
379
403
|
- **One sender:** Iframes, workers and OpenFin views find the nearest long-lived context. They forward their records to it over the bus. That context batches, stores and sends for all of them.
|
|
380
404
|
- **Five correlation ids:** Each record carries `session.id`, `tab.id`, `context.id`, `journey.id` and `trace_id`.
|
|
381
|
-
- **Durability and exit flush:** The library stores a batch that fails to send, in IndexedDB or localStorage. It sends the batch again with exponential backoff and jitter. On `pagehide` or
|
|
405
|
+
- **Durability and exit flush:** The library stores a batch that fails to send, in IndexedDB or localStorage. It sends the batch again with exponential backoff and jitter. When the document becomes hidden, the library runs a normal flush with the headers, gzip and retry. While the document is hidden, a send of 60 KB or less uses `keepalive`. A mobile OS can stop a hidden page with no `pagehide`. On `pagehide`, `freeze` or OpenFin close, it sends pending records with `navigator.sendBeacon` if they are below 60 KB. With `headers`, it uses a keepalive fetch with the last headers, because a beacon cannot set a header. A larger payload goes to the emergency queue. `shutdown()` runs a normal flush before the exit flush. An action is an audit fact. When storage is over `retention.maxBatches` or over the quota of the browser, it removes the batches without an action first. Before startup, the hold buffers keep up to 2000 actions. The 500-record limit applies only to other records. `onDrop` tells the app about each loss.
|
|
406
|
+
- **One library version on a page:** If a copy of another version owns the page runtime, this copy runs console-only. It installs no capture and reports `runtime.version_mismatch`. Load one version of the library on the page.
|
|
382
407
|
- **Emergency queue:** The emergency queue is best effort. It writes to `localStorage` synchronously, because no other storage works while the page unloads. If the browser refuses the write, the library reports `storage.quota_exceeded`. The library then loses the batch.
|
|
383
|
-
- **Configuration after startup:** A second `configure()` call merges the new options into the live runtime. The runtime refuses
|
|
408
|
+
- **Configuration after startup:** A second `configure()` call merges the new options into the live runtime. The runtime refuses 5 changes and reports `config.invalid` for each:
|
|
384
409
|
- A change to `storage`. The stored batches stay in the adapter that the runtime built at startup.
|
|
385
410
|
- A change to `identity`. The ids exist from startup.
|
|
411
|
+
- A change to `batching` or `retention` after the delivery stack loads. The stack reads them one time.
|
|
412
|
+
- A change to `limits` or `journey.maxAgeMs` after the first `configure()`. The record builder and the journey engine read them one time.
|
|
386
413
|
- An `endpoint` change to `null` or `""` after the delivery stack loads. Without an endpoint, the stored batches would be lost. A change to another endpoint URL is accepted.
|
|
387
414
|
- **Deterministic sampling:** FNV-1a hashing applies one keep rate to a whole journey. An error and an explicit action are always kept.
|
|
388
415
|
|
|
@@ -403,11 +430,11 @@ The ingest server must meet these requirements:
|
|
|
403
430
|
- Above 1 KiB, it also sends `Content-Encoding: gzip`.
|
|
404
431
|
- Each of these headers causes a CORS preflight. If the server does not allow them, each preflight fails.
|
|
405
432
|
- After a failed preflight, the library tries the batch 5 more times. It then drops the batch.
|
|
406
|
-
- Only the exit flush
|
|
433
|
+
- Only the beacon records of the exit flush arrive, because a beacon sends no custom header.
|
|
407
434
|
|
|
408
435
|
3. **Deduplication:** Deduplicate on the `X-UiObs-Batch-Id` header and the `uiobs_batch_id` query parameter. Keep the ids for at least 24 hours.
|
|
409
|
-
4. **Throttling:** Return `429` or `503` with `Retry-After`. Expose the header with `Access-Control-Expose-Headers: retry-after`.
|
|
410
|
-
5. **Status codes:** `200`, `202` and `204` accept the batch. `413` makes the library split the batch. The library drops a batch that gets any other `4xx`.
|
|
436
|
+
4. **Throttling:** Return `429` or `503` with `Retry-After`. Expose the header with `Access-Control-Expose-Headers: retry-after`. The library waits 60 s at most.
|
|
437
|
+
5. **Status codes:** `200`, `202` and `204` accept the batch. `413` makes the library split the batch. With a `headers` function, a `401` or `403` gets one more send with new headers. The library drops a batch that gets any other `4xx`.
|
|
411
438
|
6. **Remote sampling (optional):** To send sampling rules, add `X-UiObs-Sampling` to a `2xx` answer. Expose the header with `Access-Control-Expose-Headers: x-uiobs-sampling`.
|
|
412
439
|
|
|
413
440
|
---
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { d as e, pt as t } from "./constants-N99w84xy.js";
|
|
2
|
+
import { i as n } from "./identity-D4DPjTM9.js";
|
|
3
|
+
//#region src/models/batch.ts
|
|
4
|
+
function r(e) {
|
|
5
|
+
if (typeof e != "object" || !e) return !1;
|
|
6
|
+
let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
|
|
7
|
+
return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
|
|
8
|
+
}
|
|
9
|
+
function i(e, t) {
|
|
10
|
+
if (e.records.length < 2) return null;
|
|
11
|
+
let r = Math.floor(e.records.length / 2), i = (r) => ({
|
|
12
|
+
id: n(t),
|
|
13
|
+
records: r,
|
|
14
|
+
createdAt: e.createdAt,
|
|
15
|
+
attempts: e.attempts
|
|
16
|
+
});
|
|
17
|
+
return [i(e.records.slice(0, r)), i(e.records.slice(r))];
|
|
18
|
+
}
|
|
19
|
+
function a(e, t) {
|
|
20
|
+
let n = e;
|
|
21
|
+
if (typeof n != "object" || !n) return;
|
|
22
|
+
let r = Reflect.get(n, "attributes");
|
|
23
|
+
if (typeof r == "object" && r) return Reflect.get(r, t);
|
|
24
|
+
}
|
|
25
|
+
function o(n) {
|
|
26
|
+
return a(n, e) === t;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { i, o as n, r, a as t };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=batch-DEK4bv9N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-DEK4bv9N.js","names":["ATTR_LOG_TYPE","LOG_TYPE_ACTION","newId","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n"],"mappings":";;;AAiCA,SAAgBG,EAAW,GAAmC;CAC5D,IAAI,OAAOC,KAAU,aAAYA,GAC/B,OAAO;CAGT,IAAMC,IAAc,QAAQ,IAAID,GAAO,IAAI,GACrCE,IAAqB,QAAQ,IAAIF,GAAO,WAAW,GACnDG,IAAoB,QAAQ,IAAIH,GAAO,UAAU,GACjDI,IAAmB,QAAQ,IAAIJ,GAAO,SAAS;CAErD,OACE,OAAOC,KAAO,YACd,OAAOC,KAAc,YACrB,OAAOC,KAAa,YACpB,MAAM,QAAQC,CAAO;AAEzB;AASA,SAAgBC,EAAW,GAAiB,GAAuD;CACjG,IAAIC,EAAM,QAAQ,SAAS,GACzB,OAAO;CAGT,IAAMC,IAAS,KAAK,MAAMD,EAAM,QAAQ,SAAS,CAAC,GAC5CE,KAAS,OAAoC;EACjD,IAAIV,EAAMW,CAAW;EACrB;EACA,WAAWH,EAAM;EACjB,UAAUA,EAAM;CAClB;CAEA,OAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,GAAGC,CAAM,CAAC,GAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC;AACnF;AASA,SAAgBG,EAAY,GAAmB,GAAsB;CACnE,IAAMV,IAAiBW;CACvB,IAAI,OAAOX,KAAU,aAAYA,GAC/B;CAGF,IAAMY,IAAsB,QAAQ,IAAIZ,GAAO,YAAY;CAC3D,IAAI,OAAOY,KAAe,YAAYA,GAItC,OAAO,QAAQ,IAAIA,GAAYC,CAAG;AACpC;AAOA,SAAgBC,EAAe,GAA4B;CACzD,OAAOJ,EAAYC,GAAQf,CAAa,MAAMC;AAChD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-X86IDwkC.cjs"),t=require("./identity-B1GDS1Tb.cjs");function n(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`createdAt`),r=Reflect.get(e,`attempts`),i=Reflect.get(e,`records`);return typeof t==`string`&&typeof n==`number`&&typeof r==`number`&&Array.isArray(i)}function r(e,n){if(e.records.length<2)return null;let r=Math.floor(e.records.length/2),i=r=>({id:t.i(n),records:r,createdAt:e.createdAt,attempts:e.attempts});return[i(e.records.slice(0,r)),i(e.records.slice(r))]}function i(e,t){let n=e;if(typeof n!=`object`||!n)return;let r=Reflect.get(n,`attributes`);if(typeof r==`object`&&r)return Reflect.get(r,t)}function a(t){return i(t,e.d)===e.pt}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
2
|
+
//# sourceMappingURL=batch-DEVFs28i.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-DEVFs28i.cjs","names":["newId","ATTR_LOG_TYPE","LOG_TYPE_ACTION","require_constants","require_identity","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n"],"mappings":"iFAiCA,SAAgBK,EAAW,EAAmC,CAC5D,GAAI,OAAOC,GAAU,WAAYA,EAC/B,MAAO,GAGT,IAAMC,EAAc,QAAQ,IAAID,EAAO,IAAI,EACrCE,EAAqB,QAAQ,IAAIF,EAAO,WAAW,EACnDG,EAAoB,QAAQ,IAAIH,EAAO,UAAU,EACjDI,EAAmB,QAAQ,IAAIJ,EAAO,SAAS,EAErD,OACE,OAAOC,GAAO,UACd,OAAOC,GAAc,UACrB,OAAOC,GAAa,UACpB,MAAM,QAAQC,CAAO,CAEzB,CASA,SAAgBC,EAAW,EAAiB,EAAuD,CACjG,GAAIC,EAAM,QAAQ,OAAS,EACzB,OAAO,KAGT,IAAMC,EAAS,KAAK,MAAMD,EAAM,QAAQ,OAAS,CAAC,EAC5CE,EAAS,IAAoC,CACjD,GAAId,EAAAA,EAAMe,CAAW,EACrB,UACA,UAAWH,EAAM,UACjB,SAAUA,EAAM,QAClB,GAEA,MAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,EAAGC,CAAM,CAAC,EAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC,CACnF,CASA,SAAgBG,EAAY,EAAmB,EAAsB,CACnE,IAAMV,EAAiBW,EACvB,GAAI,OAAOX,GAAU,WAAYA,EAC/B,OAGF,IAAMY,EAAsB,QAAQ,IAAIZ,EAAO,YAAY,EAC3D,GAAI,OAAOY,GAAe,UAAYA,EAItC,OAAO,QAAQ,IAAIA,EAAYC,CAAG,CACpC,CAOA,SAAgBC,EAAe,EAA4B,CACzD,OAAOJ,EAAYC,EAAQhB,EAAAA,CAAa,IAAMC,EAAAA,EAChD"}
|
package/dist/bus/bus.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
-
import type
|
|
2
|
+
import { type Journey } from "../core/journey";
|
|
3
3
|
import type { RemoteSlot } from "../core/remote-sampling";
|
|
4
4
|
import type { BusMessage, BusRole } from "../models/bus";
|
|
5
5
|
import type { ResolvedConfig } from "../models/config";
|
|
@@ -45,14 +45,16 @@ export declare class Bus {
|
|
|
45
45
|
private readonly links;
|
|
46
46
|
/** Shared OpenFin InterApplicationBus link instance. */
|
|
47
47
|
private openFinLink;
|
|
48
|
-
/**
|
|
48
|
+
/** True if this context is the OpenFin platform provider. */
|
|
49
49
|
private isOpenFinProvider;
|
|
50
|
-
/**
|
|
50
|
+
/** True if role resolution is complete. */
|
|
51
51
|
private resolved;
|
|
52
52
|
/** Timer that asks the upstream owner for the remote sampling rules. */
|
|
53
53
|
private rulesPoll;
|
|
54
54
|
/** True after destroy(). A handshake that ends later must not start a timer. */
|
|
55
55
|
private destroyed;
|
|
56
|
+
/** Context id of the owner that answered the handshake. Null with no handshake. */
|
|
57
|
+
private ownerId;
|
|
56
58
|
/** Active handshake state awaiting welcome response. */
|
|
57
59
|
private awaitingWelcome;
|
|
58
60
|
/**
|
|
@@ -66,7 +68,7 @@ export declare class Bus {
|
|
|
66
68
|
constructor(config: ResolvedConfig, diagnostics: Diagnostics, platform: PlatformMetadata, contextId: string, tabId: string, handlers: BusHandlers, handshakeOptions?: HandshakeOptions);
|
|
67
69
|
/** Returns the resolved bus role. */
|
|
68
70
|
getRole(): BusRole;
|
|
69
|
-
/** Returns
|
|
71
|
+
/** Returns true if role resolution is complete. */
|
|
70
72
|
isResolved(): boolean;
|
|
71
73
|
/**
|
|
72
74
|
* Resolves bus role and establishes control links.
|
|
@@ -90,7 +92,7 @@ export declare class Bus {
|
|
|
90
92
|
*/
|
|
91
93
|
attachWorker(worker: WorkerLike): void;
|
|
92
94
|
/**
|
|
93
|
-
*
|
|
95
|
+
* Sends journey state changes over each link of the journey scope.
|
|
94
96
|
* @param journey Active journey or null if ended.
|
|
95
97
|
*/
|
|
96
98
|
broadcastJourney(journey: Journey | null): void;
|
|
@@ -98,14 +100,14 @@ export declare class Bus {
|
|
|
98
100
|
destroy(): void;
|
|
99
101
|
/** Returns all unique active links including upstream. */
|
|
100
102
|
private allLinks;
|
|
101
|
-
/** Broadcasts a message across all open links. */
|
|
102
|
-
private post;
|
|
103
103
|
/** Sends a message only over links of the given kind. */
|
|
104
104
|
private postOver;
|
|
105
|
+
/** Sends a journey message over each link of the journey scope. */
|
|
106
|
+
private postJourney;
|
|
105
107
|
/** Routes incoming messages to registered handlers or upstream targets. */
|
|
106
108
|
private readonly receive;
|
|
107
109
|
/**
|
|
108
|
-
* Tells
|
|
110
|
+
* Tells if records from a link can go upstream. Records that go back on
|
|
109
111
|
* their arrival link return to their sender. A direct link is an exception.
|
|
110
112
|
* Each direct link is one call into one parent. Thus two direct links in a
|
|
111
113
|
* chain are different links.
|
|
@@ -113,13 +115,13 @@ export declare class Bus {
|
|
|
113
115
|
* @returns True if the relay is safe.
|
|
114
116
|
*/
|
|
115
117
|
private canRelay;
|
|
116
|
-
/** Returns
|
|
118
|
+
/** Returns true if this context can be the owner of the given link type. */
|
|
117
119
|
private canOwn;
|
|
118
|
-
/**
|
|
120
|
+
/** Finds if this context is the OpenFin platform provider. */
|
|
119
121
|
private resolveOpenFinProvider;
|
|
120
122
|
/** Resolves the handshake orphan policy for the current platform context. */
|
|
121
123
|
private orphanPolicy;
|
|
122
|
-
/** Tests
|
|
124
|
+
/** Tests if a cross-origin boundary blocks access to the parent window. */
|
|
123
125
|
private isCrossOriginFrame;
|
|
124
126
|
/** Identifies the candidate upstream link based on platform hierarchy. */
|
|
125
127
|
private candidateUpstream;
|
|
@@ -135,6 +137,38 @@ export declare class Bus {
|
|
|
135
137
|
private handshake;
|
|
136
138
|
/** Broadcasts tab claim and queries existing journey state. */
|
|
137
139
|
private announce;
|
|
140
|
+
/**
|
|
141
|
+
* Resolves the journey scope. "auto" gives "origin" in OpenFin and "tab" in a browser.
|
|
142
|
+
* @returns The scope in force.
|
|
143
|
+
*/
|
|
144
|
+
private journeyScope;
|
|
145
|
+
/**
|
|
146
|
+
* Tests if a link carries journey messages in the scope in force.
|
|
147
|
+
* Only "origin" uses the broadcast link. That link reaches each tab of the origin.
|
|
148
|
+
* @param link Link kind.
|
|
149
|
+
* @returns True if the link carries journey messages.
|
|
150
|
+
*/
|
|
151
|
+
private journeyLink;
|
|
152
|
+
/**
|
|
153
|
+
* Tests if this context adopts a journey message.
|
|
154
|
+
* @param message Journey message.
|
|
155
|
+
* @param source Link and origin of the message.
|
|
156
|
+
* @returns True for a message on a journey link, to this context, from an accepted sender.
|
|
157
|
+
* In "tab" scope, only the owner of a forwarder is an accepted sender.
|
|
158
|
+
*/
|
|
159
|
+
private acceptsJourney;
|
|
160
|
+
/**
|
|
161
|
+
* Tests if a message comes from the upstream owner of this forwarder.
|
|
162
|
+
* @param from Context id of the sender.
|
|
163
|
+
* @param link Link kind of the message.
|
|
164
|
+
* @returns True for the upstream link and, after a handshake, the owner that answered it.
|
|
165
|
+
*/
|
|
166
|
+
private fromOwner;
|
|
167
|
+
/**
|
|
168
|
+
* Parses a journey payload from another realm and gives it to the runtime.
|
|
169
|
+
* @param payload Journey, or null when the journey ended.
|
|
170
|
+
*/
|
|
171
|
+
private applyJourney;
|
|
138
172
|
/**
|
|
139
173
|
* Builds the answer to a sampling question. Null rules end the copy of the forwarder.
|
|
140
174
|
* @param to Context id of the forwarder that asked.
|
|
@@ -142,7 +176,7 @@ export declare class Bus {
|
|
|
142
176
|
*/
|
|
143
177
|
private rulesAnswer;
|
|
144
178
|
/**
|
|
145
|
-
* Tests
|
|
179
|
+
* Tests if this context accepts sampling rules from a source.
|
|
146
180
|
* @param to Context id that the answer names.
|
|
147
181
|
* @param source Link and origin of the answer.
|
|
148
182
|
* @returns True only for an answer from the upstream owner to this context.
|
package/dist/bus/links.d.ts
CHANGED
|
@@ -57,12 +57,15 @@ export interface WorkerLike {
|
|
|
57
57
|
*/
|
|
58
58
|
export declare function createDirectLink(receive: Receive, diagnostics: Diagnostics): Link | null;
|
|
59
59
|
/**
|
|
60
|
-
* Creates a postMessage link to
|
|
60
|
+
* Creates a postMessage link to a parent window on a trusted origin. Records hold user data.
|
|
61
|
+
* A page on another origin that frames this app must not get them.
|
|
61
62
|
* @param receive Callback for incoming parent messages.
|
|
63
|
+
* @param trustedOrigins Origins of a parent that can get the records, in addition to this origin.
|
|
62
64
|
* @param diagnostics Diagnostics reporter.
|
|
63
|
-
* @returns Link to parent window, or null
|
|
65
|
+
* @returns Link to the parent window, or null at the top level or with an untrusted parent.
|
|
66
|
+
* With null, this context sends its own records.
|
|
64
67
|
*/
|
|
65
|
-
export declare function createParentLink(receive: Receive, diagnostics: Diagnostics): Link | null;
|
|
68
|
+
export declare function createParentLink(receive: Receive, trustedOrigins: string[], diagnostics: Diagnostics): Link | null;
|
|
66
69
|
/**
|
|
67
70
|
* Creates a link listening to child frames with origin allowlist filtering.
|
|
68
71
|
* @param receive Callback for messages from authorized child frames.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./constants-X86IDwkC.cjs"),t=require("./deadline-XSnm95pg.cjs"),n=require("./journey-DxlfdFJV.cjs"),r=require("./remote-rules-ByS34k4e.cjs");function i(t){return{p:e.T,m:t}}function a(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 o=Symbol.for(e.qt),s=`null`;function c(e,t){return e===s?`The bus ignored ${t} from a sandboxed frame. The frame has an opaque origin. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`:`The bus ignored ${t} from ${e}. If you own this origin, add it to bus.trustedOrigins.`}function l(){let e=location.ancestorOrigins;if(e&&e.length>0)return e.item(0);let t=document.referrer;if(t===``)return null;try{return new URL(t).origin}catch{return null}}function u(e,t){if(typeof window>`u`||window.parent===window)return null;let n;try{n=window.parent[o]}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 d(e,t,n){if(typeof window>`u`||window.parent===window)return null;let r=location.origin;if(r===s)return n.report(`bus.untrusted_origin`,`This frame is sandboxed without allow-same-origin. It has an opaque origin. No parent can trust it. This context sends its own records. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`,{origin:r,type:`parent`}),null;let o=new Set([r,...t]),u=l();if(u===null||!o.has(u))return n.report(`bus.untrusted_origin`,u===null?`The origin of the parent frame is unknown. This context sends its own records.`:`The parent frame is on ${u}. This origin is not in bus.trustedOrigins. This context sends its own records.`,{origin:u??``,type:`parent`}),null;let d=new Set,f=t=>{let r=a(t.data);r&&t.source===window.parent&&(o.has(t.origin)?e(r,{link:`parent`,origin:t.origin}):d.has(t.origin)||(d.add(t.origin),n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:r.t.slice(0,32)})))};return addEventListener(`message`,f),{kind:`parent`,post(e){n.guard(`bus.send_failed`,`The postMessage call to the parent failed.`,()=>{window.parent.postMessage(i(e),u)})},close(){removeEventListener(`message`,f)}}}function f(e,t,n){if(typeof window>`u`)return null;let r=new Set([location.origin,...t]);r.delete(s);let o=new Map,l=t=>{let i=a(t.data);i&&(r.has(t.origin)?(t.source&&o.set(t.source,t.origin),e(i,{link:`children`,origin:t.origin})):n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:i.t.slice(0,32)}))};return addEventListener(`message`,l),{kind:`children`,post(e){for(let[t,r]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(i(e),r)})}},close(){removeEventListener(`message`,l),o.clear()}}}function p(e,t,n){let r=globalThis.BroadcastChannel;if(r===void 0)return null;let o=n.guard(`bus.send_failed`,`The library could not open the BroadcastChannel.`,()=>new r(e));return o?(o.onmessage=e=>{let n=a(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(i(e))})},close(){n.guard(`bus.send_failed`,`The library could not close the BroadcastChannel.`,()=>{o.close()})}}):null}function m(e,t,n,r){let o=globalThis.fin?.InterApplicationBus;if(!o)return null;if(!t)return r.report(`openfin.unavailable`,`OpenFin gives no application uuid. The InterApplicationBus link stays closed.`),null;let s=`${e}.${t}`;return r.guardAsync(`bus.send_failed`,`The InterApplicationBus.subscribe call failed.`,()=>o.subscribe({uuid:t},s,e=>{let t=a(e);t&&n(t,{link:`openfin`,origin:`openfin`})})),{kind:`openfin`,post(e){r.guardAsync(`bus.send_failed`,`The InterApplicationBus.publish call failed.`,()=>o.publish(s,i(e)))},close(){}}}function h(e,t){let n=globalThis,r=n.postMessage;return n.WorkerGlobalScope===void 0||!r?null:(n.addEventListener?.(`message`,t=>{let n=a(t.data);n&&e(n,{link:`owner`,origin:`same-origin`})}),{kind:`owner`,post(e){t.guard(`bus.send_failed`,`The postMessage call of the worker failed.`,()=>{r(i(e))})},close(){}})}function g(e,t,n){let r=e=>{let n=a(e.data);n&&t(n,{link:`worker`,origin:`same-origin`})};return e.addEventListener(`message`,r),e.start?.(),{kind:`worker`,post(t){n.guard(`bus.send_failed`,`The postMessage call to a worker failed.`,()=>{e.postMessage(i(t))})},close(){e.removeEventListener(`message`,r)}}}var _={timeoutMs:e.C,maxAttempts:3},v=[`children`,`direct`,`worker`],y=class{config;diagnostics;platform;contextId;tabId;handlers;handshakeOptions;role=`sender`;upstream=null;links=[];openFinLink=null;isOpenFinProvider=!1;resolved=!1;rulesPoll;destroyed=!1;ownerId=null;awaitingWelcome=null;constructor(e,t,n,r,i,a,o=_){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=u(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 r=this.handlers.onJourneyRequest();r&&this.journeyLink(`direct`)&&t({t:`journey`,from:this.contextId,to:e.from,journey:r},n)}else e.t===`sampling?`?t(this.rulesAnswer(e.from),n):this.receive(e,n)}attachWorker(e){this.links.push(g(e,this.receive,this.diagnostics))}broadcastJourney(e){this.postJourney({t:`journey`,from:this.contextId,journey:e})}destroy(){this.destroyed=!0,clearInterval(this.rulesPoll),this.rulesPoll=void 0;for(let e of this.allLinks())e.close();this.links.length=0,this.upstream=null,this.ownerId=null,this.openFinLink=null}allLinks(){return!this.upstream||this.links.includes(this.upstream)?this.links:[...this.links,this.upstream]}postOver(e,t){for(let n of this.allLinks())n.kind===e&&n.post(t)}postJourney(e){for(let t of this.allLinks())this.journeyLink(t.kind)&&t.post(e)}receive=(e,t)=>{if(e.from!==this.contextId)switch(e.t){case`hello`:this.canOwn(t.link)&&this.postOver(t.link,{t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId});break;case`welcome`:if(e.to!==this.contextId)break;this.awaitingWelcome?.link===t.link&&(this.ownerId=e.from,this.awaitingWelcome.settle(!0));break;case`records`:this.role===`sender`?this.handlers.onRecords(e.records):this.upstream&&this.canRelay(t.link)&&this.upstream.post(e);break;case`journey`:this.acceptsJourney(e,t)&&this.applyJourney(e.journey);break;case`journey?`:{let n=this.handlers.onJourneyRequest();n&&this.journeyLink(t.link)&&this.postOver(t.link,{t:`journey`,from:this.contextId,to:e.from,journey:n});break}case`sampling?`:(this.role===`forwarder`?t.link!==this.upstream?.kind:this.canOwn(t.link))&&this.postOver(t.link,this.rulesAnswer(e.from));break;case`sampling`:this.acceptsRules(e.to,t)&&this.applyRules(e.rules);break;case`tab`:t.link===`broadcast`&&e.tabId===this.tabId&&this.contextId>e.from&&this.handlers.onTabConflict()}};canRelay(e){return e===`direct`||e!==this.upstream?.kind}canOwn(e){return this.role===`sender`?e===`openfin`?this.isOpenFinProvider:v.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?h(this.receive,this.diagnostics):this.platform.isTopLevelDocument?this.platform.platform===`openfin`&&!this.isOpenFinProvider?this.ensureOpenFinLink():null:d(this.receive,this.config.bus.trustedOrigins,this.diagnostics)}openControlLinks(){let t=e=>{e&&this.links.push(e)};this.platform.isTopLevelDocument&&(t(f(this.receive,this.config.bus.trustedOrigins,this.diagnostics)),t(p(e.S,this.receive,this.diagnostics))),(this.platform.platform===`openfin`||this.platform.platform===`openfin_web`)&&t(this.ensureOpenFinLink())}ensureOpenFinLink(){return this.openFinLink??=m(e.S,this.platform.openfinUuid,this.receive,this.diagnostics),this.openFinLink}handshake(e){return new Promise(n=>{let r=!1,i=e=>{r||(r=!0,this.awaitingWelcome=null,clearTimeout(a),n(e))};this.awaitingWelcome={link:e.kind,settle:i};let a=setTimeout(()=>{i(!1)},this.handshakeOptions.timeoutMs);t.r(a),e.post({t:`hello`,from:this.contextId,tabId:this.tabId})})}announce(){this.postOver(`broadcast`,{t:`tab`,from:this.contextId,tabId:this.tabId}),this.postJourney({t:`journey?`,from:this.contextId}),this.pollRules()}journeyScope(){let{scope:e}=this.config.journey;if(e!==`auto`)return e;let{platform:t}=this.platform;return t===`openfin`||t===`openfin_web`?`origin`:`tab`}journeyLink(e){let t=this.journeyScope();return t===`context`?!1:t===`origin`||e!==`broadcast`}acceptsJourney(e,t){return!this.journeyLink(t.link)||e.to!==void 0&&e.to!==this.contextId?!1:this.journeyScope()===`origin`||this.fromOwner(e.from,t.link)}fromOwner(e,t){return this.role!==`forwarder`||t!==this.upstream?.kind?!1:this.ownerId===null||e===this.ownerId}applyJourney(e){if(e===null){this.handlers.onJourney(null);return}let t=n.r(e);t===null?this.diagnostics.report(`record.dropped_malformed`,`The bus dropped a journey message. Its payload is not a journey.`,{type:`journey`}):this.handlers.onJourney(t)}rulesAnswer(e){let t=this.handlers.remote.sampling?.wire()??null;return{t:`sampling`,from:this.contextId,to:e,rules:t}}acceptsRules(e,t){if(this.role!==`forwarder`||e!==this.contextId||t.link!==this.upstream?.kind)return!1;let{origin:n}=t;return t.link===`parent`&&n!==location.origin&&!this.config.bus.trustedOrigins.includes(n)?(this.diagnostics.report(`bus.untrusted_origin`,`The bus ignored sampling rules from ${n}. If you own this origin, add it to bus.trustedOrigins.`,{origin:n,type:`sampling`}),!1):!0}applyRules(e){if(e===null){r.t(this.handlers.remote,this.config,null);return}let t=r.n(e,this.diagnostics);t&&r.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.kt),t.r(this.rulesPoll)}};exports.Bus=y;
|
|
2
|
+
//# sourceMappingURL=bus-DNFvTkif.cjs.map
|