@utk09/ui-observability 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +90 -0
- package/README.md +199 -96
- package/dist/batch-BQFtb3i5.cjs +2 -0
- package/dist/batch-BQFtb3i5.cjs.map +1 -0
- package/dist/{batch-DDgxg16_.js → batch-BUJh-1jZ.js} +6 -4
- package/dist/batch-BUJh-1jZ.js.map +1 -0
- package/dist/bus/bus.d.ts +76 -2
- package/dist/bus/links.d.ts +9 -2
- package/dist/bus/validation.d.ts +7 -0
- package/dist/bus-BW6N-pY8.cjs +2 -0
- package/dist/bus-BW6N-pY8.cjs.map +1 -0
- package/dist/bus-DeOPHWaD.js +647 -0
- package/dist/bus-DeOPHWaD.js.map +1 -0
- package/dist/capture/network.d.ts +1 -0
- package/dist/capture/storm.d.ts +2 -1
- package/dist/capture/types.d.ts +5 -0
- package/dist/capture/web-socket.d.ts +40 -0
- package/dist/{console-BSusX_M-.cjs → console-Ce6heqZZ.cjs} +2 -2
- package/dist/console-Ce6heqZZ.cjs.map +1 -0
- package/dist/{console-Dv5GfaNn.js → console-DbAZYJuy.js} +4 -4
- package/dist/console-DbAZYJuy.js.map +1 -0
- package/dist/constants-CN7GE1Lt.js +246 -0
- package/dist/constants-CN7GE1Lt.js.map +1 -0
- package/dist/constants-CW-MlHdY.cjs +2 -0
- package/dist/constants-CW-MlHdY.cjs.map +1 -0
- package/dist/constants.d.ts +63 -11
- package/dist/context-storage-BjzeBSxH.cjs +2 -0
- package/dist/context-storage-BjzeBSxH.cjs.map +1 -0
- package/dist/context-storage-DxZf4Gfh.js +52 -0
- package/dist/context-storage-DxZf4Gfh.js.map +1 -0
- package/dist/core/breadcrumbs.d.ts +10 -3
- package/dist/core/context.d.ts +2 -0
- package/dist/core/diagnostics.d.ts +11 -3
- package/dist/core/journey.d.ts +7 -0
- package/dist/core/meter.d.ts +25 -2
- package/dist/core/pipeline.d.ts +41 -6
- package/dist/core/record.d.ts +42 -9
- package/dist/core/remote-sampling.d.ts +7 -3
- package/dist/core/runtime.d.ts +153 -6
- package/dist/core/sampling.d.ts +35 -2
- package/dist/core/sender.d.ts +43 -1
- package/dist/core/spans.d.ts +34 -0
- 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/emergency-queue-BYUyDHGD.js +69 -0
- package/dist/emergency-queue-BYUyDHGD.js.map +1 -0
- package/dist/emergency-queue-Cs1hrjsC.cjs +2 -0
- package/dist/emergency-queue-Cs1hrjsC.cjs.map +1 -0
- package/dist/{errors-DCZWcHkd.js → errors-BhC7HTSt.js} +8 -9
- package/dist/errors-BhC7HTSt.js.map +1 -0
- package/dist/errors-CgY633cG.cjs +3 -0
- package/dist/errors-CgY633cG.cjs.map +1 -0
- package/dist/factory-C5TujXlU.js +280 -0
- package/dist/factory-C5TujXlU.js.map +1 -0
- package/dist/factory-CNj4DH3n.cjs +2 -0
- package/dist/factory-CNj4DH3n.cjs.map +1 -0
- package/dist/fixed-window-CtaFHanJ.js +12 -0
- package/dist/fixed-window-CtaFHanJ.js.map +1 -0
- package/dist/fixed-window-CvESpFYV.cjs +2 -0
- package/dist/fixed-window-CvESpFYV.cjs.map +1 -0
- package/dist/identity-8vKkyAWm.js +103 -0
- package/dist/identity-8vKkyAWm.js.map +1 -0
- package/dist/identity-Da9TkuKd.cjs +2 -0
- package/dist/identity-Da9TkuKd.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +66 -6
- package/dist/index.js +1253 -595
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-BTfIFRHF.cjs +2 -0
- package/dist/indexeddb-storage-BTfIFRHF.cjs.map +1 -0
- package/dist/{indexeddb-storage-T9YIYVYC.js → indexeddb-storage-CCA1LvtO.js} +45 -30
- package/dist/indexeddb-storage-CCA1LvtO.js.map +1 -0
- package/dist/{interactions-BLH_tX87.js → interactions-BUDLxbv1.js} +16 -12
- package/dist/interactions-BUDLxbv1.js.map +1 -0
- package/dist/interactions-NHbLKrqe.cjs +2 -0
- package/dist/interactions-NHbLKrqe.cjs.map +1 -0
- package/dist/{journey-yALMEWF7.js → journey-BUJ4WJxP.js} +37 -34
- package/dist/journey-BUJ4WJxP.js.map +1 -0
- package/dist/journey-B_tTnvac.cjs +2 -0
- package/dist/journey-B_tTnvac.cjs.map +1 -0
- package/dist/keys-BHhw_0Wh.cjs +2 -0
- package/dist/keys-BHhw_0Wh.cjs.map +1 -0
- package/dist/keys-D5r_GH9q.js +17 -0
- package/dist/keys-D5r_GH9q.js.map +1 -0
- package/dist/{library-request-CQD4HUiP.js → library-request-BKOcaKtQ.js} +3 -3
- package/dist/{library-request-CQD4HUiP.js.map → library-request-BKOcaKtQ.js.map} +1 -1
- package/dist/{library-request-BcAxuwsf.cjs → library-request-BaZOi4eg.cjs} +2 -2
- package/dist/{library-request-BcAxuwsf.cjs.map → library-request-BaZOi4eg.cjs.map} +1 -1
- package/dist/{long-frames-D4Bm3Zkz.cjs → long-frames-CF3qiSAX.cjs} +2 -2
- package/dist/long-frames-CF3qiSAX.cjs.map +1 -0
- package/dist/{long-frames-DD_Um9_4.js → long-frames-DI5ypfAF.js} +5 -5
- package/dist/long-frames-DI5ypfAF.js.map +1 -0
- package/dist/models/batch.d.ts +4 -0
- package/dist/models/bus.d.ts +32 -9
- package/dist/models/config.d.ts +401 -12
- package/dist/models/drop.d.ts +1 -1
- package/dist/models/health.d.ts +27 -0
- package/dist/models/log-record.d.ts +1 -1
- package/dist/models/plugin.d.ts +47 -0
- package/dist/models/stats.d.ts +11 -0
- package/dist/models/storage.d.ts +13 -0
- package/dist/network-CF8UO5PK.cjs +2 -0
- package/dist/network-CF8UO5PK.cjs.map +1 -0
- package/dist/{network--GoE7_Or.js → network-DdzXDI3J.js} +47 -31
- package/dist/network-DdzXDI3J.js.map +1 -0
- package/dist/openfin-BwEN0uj4.js.map +1 -1
- package/dist/openfin-DtH2f7zX.cjs.map +1 -1
- package/dist/{platform-GaM6h7XM.js → platform-Bw1btWCT.js} +21 -10
- package/dist/platform-Bw1btWCT.js.map +1 -0
- package/dist/platform-DBSKTvFn.cjs +2 -0
- package/dist/platform-DBSKTvFn.cjs.map +1 -0
- package/dist/remote-rules-DIcC5vVC.js +91 -0
- package/dist/remote-rules-DIcC5vVC.js.map +1 -0
- package/dist/remote-rules-DpFmOef2.cjs +2 -0
- package/dist/remote-rules-DpFmOef2.cjs.map +1 -0
- package/dist/sampling-BVjspJWu.cjs +2 -0
- package/dist/sampling-BVjspJWu.cjs.map +1 -0
- package/dist/sampling-Cm3WhI0a.js +76 -0
- package/dist/sampling-Cm3WhI0a.js.map +1 -0
- package/dist/{sanitize-DP0xDPrt.js → sanitize-C-ahCFsG.js} +2 -2
- package/dist/{sanitize-DP0xDPrt.js.map → sanitize-C-ahCFsG.js.map} +1 -1
- package/dist/{sanitize--_e4oOPX.cjs → sanitize-DHucKGdi.cjs} +2 -2
- package/dist/{sanitize--_e4oOPX.cjs.map → sanitize-DHucKGdi.cjs.map} +1 -1
- package/dist/sender-D3fRCR8d.cjs +3 -0
- package/dist/sender-D3fRCR8d.cjs.map +1 -0
- package/dist/sender-DUUmSglb.js +1163 -0
- package/dist/sender-DUUmSglb.js.map +1 -0
- package/dist/storage/context-storage.d.ts +89 -0
- package/dist/storage/emergency-queue.d.ts +9 -1
- package/dist/storage/factory.d.ts +7 -1
- package/dist/storage/idb-driver.d.ts +13 -0
- package/dist/storage/indexeddb-storage.d.ts +13 -0
- package/dist/storage/local-storage.d.ts +21 -1
- package/dist/storage/memory-storage.d.ts +13 -0
- package/dist/storage-BA9RqRO-.cjs +2 -0
- package/dist/storage-BA9RqRO-.cjs.map +1 -0
- package/dist/storage-w7Tslvlq.js +17 -0
- package/dist/storage-w7Tslvlq.js.map +1 -0
- package/dist/storm-CNZjsw4T.cjs +2 -0
- package/dist/storm-CNZjsw4T.cjs.map +1 -0
- package/dist/storm-Daq2jGHU.js +10 -0
- package/dist/storm-Daq2jGHU.js.map +1 -0
- package/dist/transport/exit-flush.d.ts +6 -0
- package/dist/transport/http-transport.d.ts +2 -1
- package/dist/transport/retry-engine.d.ts +7 -2
- package/dist/transport/serializers/otlp-traces.d.ts +3 -0
- package/dist/transport/serializers/select.d.ts +8 -5
- package/dist/transport/status-transport.d.ts +24 -0
- package/dist/types-BR9t_w28.js +8 -0
- package/dist/types-BR9t_w28.js.map +1 -0
- package/dist/types-C7WNpnG1.cjs +2 -0
- package/dist/types-C7WNpnG1.cjs.map +1 -0
- package/dist/utils/fixed-window.d.ts +9 -0
- package/dist/utils/identity.d.ts +20 -2
- package/dist/utils/lock.d.ts +8 -0
- package/dist/utils/openfin.d.ts +1 -1
- package/dist/utils/platform.d.ts +10 -0
- package/dist/utils/tracing.d.ts +82 -4
- package/dist/web-socket-BacvKOvD.cjs +2 -0
- package/dist/web-socket-BacvKOvD.cjs.map +1 -0
- package/dist/web-socket-CpsD8WAa.js +105 -0
- package/dist/web-socket-CpsD8WAa.js.map +1 -0
- package/package.json +1 -1
- package/dist/batch-D5qvsMQ_.cjs +0 -2
- package/dist/batch-D5qvsMQ_.cjs.map +0 -1
- package/dist/batch-DDgxg16_.js.map +0 -1
- package/dist/bus-C6RwKzPW.js +0 -478
- package/dist/bus-C6RwKzPW.js.map +0 -1
- package/dist/bus-WPVDFw2y.cjs +0 -2
- package/dist/bus-WPVDFw2y.cjs.map +0 -1
- package/dist/console-BSusX_M-.cjs.map +0 -1
- package/dist/console-Dv5GfaNn.js.map +0 -1
- package/dist/constants-Cb92egPS.cjs +0 -2
- package/dist/constants-Cb92egPS.cjs.map +0 -1
- package/dist/constants-DhH6VI5a.js +0 -144
- package/dist/constants-DhH6VI5a.js.map +0 -1
- package/dist/deadline-CUrH0Hd8.cjs +0 -2
- package/dist/deadline-CUrH0Hd8.cjs.map +0 -1
- package/dist/deadline-DeqXEliN.js +0 -31
- package/dist/deadline-DeqXEliN.js.map +0 -1
- package/dist/errors-DCZWcHkd.js.map +0 -1
- package/dist/errors-ERu-su8m.cjs +0 -3
- package/dist/errors-ERu-su8m.cjs.map +0 -1
- package/dist/fixed-window-BR0bu32Y.cjs +0 -2
- package/dist/fixed-window-BR0bu32Y.cjs.map +0 -1
- package/dist/fixed-window-Re7jIRJH.js +0 -9
- package/dist/fixed-window-Re7jIRJH.js.map +0 -1
- package/dist/identity-C1WLItSl.cjs +0 -2
- package/dist/identity-C1WLItSl.cjs.map +0 -1
- package/dist/identity-Di-QXGCC.js +0 -88
- package/dist/identity-Di-QXGCC.js.map +0 -1
- package/dist/indexeddb-storage-DX18p39D.cjs +0 -2
- package/dist/indexeddb-storage-DX18p39D.cjs.map +0 -1
- package/dist/indexeddb-storage-T9YIYVYC.js.map +0 -1
- package/dist/interactions-BLH_tX87.js.map +0 -1
- package/dist/interactions-_hfOerfC.cjs +0 -2
- package/dist/interactions-_hfOerfC.cjs.map +0 -1
- package/dist/journey-BRUj0hqD.cjs +0 -2
- package/dist/journey-BRUj0hqD.cjs.map +0 -1
- package/dist/journey-yALMEWF7.js.map +0 -1
- package/dist/long-frames-D4Bm3Zkz.cjs.map +0 -1
- package/dist/long-frames-DD_Um9_4.js.map +0 -1
- package/dist/network--GoE7_Or.js.map +0 -1
- package/dist/network-DcuS2H1P.cjs +0 -2
- package/dist/network-DcuS2H1P.cjs.map +0 -1
- package/dist/platform-GaM6h7XM.js.map +0 -1
- package/dist/platform-kIL5AZB7.cjs +0 -2
- package/dist/platform-kIL5AZB7.cjs.map +0 -1
- package/dist/remote-rules-6ePq8CrI.js +0 -84
- package/dist/remote-rules-6ePq8CrI.js.map +0 -1
- package/dist/remote-rules-CI3gbRCL.cjs +0 -2
- package/dist/remote-rules-CI3gbRCL.cjs.map +0 -1
- package/dist/sampling-C-M8p3FK.cjs +0 -2
- package/dist/sampling-C-M8p3FK.cjs.map +0 -1
- package/dist/sampling-Ud_WiuU9.js +0 -65
- package/dist/sampling-Ud_WiuU9.js.map +0 -1
- package/dist/sender-BESHz6my.cjs +0 -3
- package/dist/sender-BESHz6my.cjs.map +0 -1
- package/dist/sender-BUBWLn5i.js +0 -1244
- package/dist/sender-BUBWLn5i.js.map +0 -1
- package/dist/storm-DhHGHhOc.cjs +0 -2
- package/dist/storm-DhHGHhOc.cjs.map +0 -1
- package/dist/storm-OD5J6Ylm.js +0 -10
- package/dist/storm-OD5J6Ylm.js.map +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { t as e } from "./library-request-BKOcaKtQ.js";
|
|
2
|
+
import { i as t } from "./platform-Bw1btWCT.js";
|
|
3
|
+
import { t as n } from "./patch-CCWfuEY7.js";
|
|
4
|
+
import { t as r } from "./storm-Daq2jGHU.js";
|
|
5
|
+
import { t as i } from "./types-BR9t_w28.js";
|
|
6
|
+
//#region src/capture/web-socket.ts
|
|
7
|
+
var a = "ui.websocket.messages";
|
|
8
|
+
function o(e, n, r) {
|
|
9
|
+
let i = new URL(e);
|
|
10
|
+
return {
|
|
11
|
+
target: t(e, !1, n.capture.urlTransform, r),
|
|
12
|
+
server: i.hostname
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function s(t, n, r) {
|
|
16
|
+
let i = t.servers.get(n), a = r === "transmit" && e();
|
|
17
|
+
if (!t.active || i === void 0 || a || t.config.securityContext.isolation && t.contexts.get(n) !== t.config.securityContext.id) return;
|
|
18
|
+
let o = {
|
|
19
|
+
"network.io.direction": r,
|
|
20
|
+
"server.address": i
|
|
21
|
+
};
|
|
22
|
+
t.messages.add(1, o);
|
|
23
|
+
}
|
|
24
|
+
var c = class {
|
|
25
|
+
diagnostics;
|
|
26
|
+
config;
|
|
27
|
+
name = "websocket";
|
|
28
|
+
restore;
|
|
29
|
+
state;
|
|
30
|
+
window = {
|
|
31
|
+
start: 0,
|
|
32
|
+
count: 0
|
|
33
|
+
};
|
|
34
|
+
constructor(e, t) {
|
|
35
|
+
this.diagnostics = e, this.config = t;
|
|
36
|
+
}
|
|
37
|
+
install(e) {
|
|
38
|
+
if (this.restore || typeof WebSocket > "u") return;
|
|
39
|
+
let t = {
|
|
40
|
+
active: !0,
|
|
41
|
+
ctx: e,
|
|
42
|
+
messages: e.counter(a),
|
|
43
|
+
servers: /* @__PURE__ */ new WeakMap(),
|
|
44
|
+
contexts: /* @__PURE__ */ new WeakMap(),
|
|
45
|
+
config: this.config
|
|
46
|
+
};
|
|
47
|
+
this.state = t;
|
|
48
|
+
let r = (e) => {
|
|
49
|
+
this.track(e, t);
|
|
50
|
+
};
|
|
51
|
+
this.restore = n(globalThis, "WebSocket", (e) => class extends e {
|
|
52
|
+
static [Symbol.hasInstance](t) {
|
|
53
|
+
return t instanceof e;
|
|
54
|
+
}
|
|
55
|
+
constructor(e, t) {
|
|
56
|
+
super(e, t), r(this);
|
|
57
|
+
}
|
|
58
|
+
send(e) {
|
|
59
|
+
super.send(e), s(t, this, "transmit");
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
uninstall() {
|
|
64
|
+
this.state && (this.state.active = !1), this.restore && !this.restore() && this.diagnostics.report("capture.install_failed", "Another script wrapped WebSocket after the library. The library keeps that wrapper."), this.restore = void 0, this.state = void 0;
|
|
65
|
+
}
|
|
66
|
+
track(e, t) {
|
|
67
|
+
t.active && this.diagnostics.guard("capture.record_failed", "The library could not track a WebSocket. The socket works without capture.", () => {
|
|
68
|
+
if (i(e.url, this.config.capture.ignoreUrls)) return;
|
|
69
|
+
let { target: n, server: r } = o(e.url, this.config, this.diagnostics), a = {
|
|
70
|
+
"url.full": n,
|
|
71
|
+
"server.address": r
|
|
72
|
+
}, { logger: c } = t.ctx;
|
|
73
|
+
t.servers.set(e, r), t.contexts.set(e, this.config.securityContext.id);
|
|
74
|
+
let l = (n) => {
|
|
75
|
+
(!this.config.securityContext.isolation || t.contexts.get(e) === this.config.securityContext.id) && this.allow(t) && n();
|
|
76
|
+
};
|
|
77
|
+
e.addEventListener("open", () => {
|
|
78
|
+
l(() => {
|
|
79
|
+
c.logEvent("websocket.open", a);
|
|
80
|
+
});
|
|
81
|
+
}), e.addEventListener("error", () => {
|
|
82
|
+
l(() => {
|
|
83
|
+
c.warn("websocket.error", a);
|
|
84
|
+
});
|
|
85
|
+
}), e.addEventListener("close", (e) => {
|
|
86
|
+
l(() => {
|
|
87
|
+
c.logEvent("websocket.close", {
|
|
88
|
+
...a,
|
|
89
|
+
"websocket.close.code": e.code,
|
|
90
|
+
"websocket.close.clean": e.wasClean
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}), e.addEventListener("message", () => {
|
|
94
|
+
s(t, e, "receive");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
allow(e) {
|
|
99
|
+
return e.active && r(this.window, this.config.capturePolicy.webSocketPerWindow, this.diagnostics, "WebSocket events", this.config.capturePolicy.windowMs);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
export { c as WebSocketCapture };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=web-socket-CpsD8WAa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-socket-CpsD8WAa.js","names":["isLibraryRequest","recordedUrl","patch","allowInWindow","matchesAny","MESSAGES_METRIC","socketTarget","parsed","url","config","diagnostics","count","server","state","socket","own","direction","attributes","WebSocketCapture","ctx","track","Original","value","protocols","data","target","lifecycle","write","event"],"sources":["../src/capture/web-socket.ts"],"sourcesContent":["// src/capture/web-socket.ts\n//\n// Records the open, close and error events of each WebSocket. It counts the messages by direction\n// and server. It never reads the content of a message. It is a capture plugin, and the runtime\n// loads it as a separate chunk.\n\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { Counter, MetricAttributes } from \"../models/metric\";\nimport type { CapturePlugin, PluginContext } from \"../models/plugin\";\nimport { isLibraryRequest } from \"../utils/library-request\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { patch } from \"../utils/patch\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { matchesAny } from \"./types\";\n\n/** Name of the message counter. */\nconst MESSAGES_METRIC = \"ui.websocket.messages\";\n\n/** Data of one WebSocket.send call. */\ntype SendData = Parameters<WebSocket[\"send\"]>[0];\n\n/** State of one install. A wrapper that stays after uninstall reads it and records nothing. */\ninterface InstallState {\n /** False after uninstall. */\n active: boolean;\n /** Tools of the plugin. */\n ctx: PluginContext;\n /** Counter of the messages. */\n messages: Counter;\n /** Server host name of each tracked socket. */\n servers: WeakMap<WebSocket, string>;\n /** Delivery context in force when each socket opened. */\n contexts: WeakMap<WebSocket, string>;\n /** Active capture settings and isolation rule. */\n config: ResolvedConfig;\n}\n\n/**\n * Removes the user info, the query and the fragment from a socket URL. They can hold a token.\n * @param url Absolute URL of the socket.\n * @param config Active capture settings.\n * @param diagnostics Diagnostics reporter for a URL transform that throws.\n * @returns The URL to record and the host name of the server.\n */\nfunction socketTarget(\n url: string,\n config: ResolvedConfig,\n diagnostics: Diagnostics,\n): { target: string; server: string } {\n const parsed = new URL(url);\n\n return {\n // Ignore fullUrls. A browser cannot set a header on a socket. Thus apps often put a token in\n // the query. Only urlTransform can record more of the URL.\n target: recordedUrl(url, false, config.capture.urlTransform, diagnostics),\n server: parsed.hostname,\n };\n}\n\n/**\n * Counts one message of a tracked socket.\n * @param state State of the install that made the socket.\n * @param socket Socket of the message.\n * @param direction Direction of the message.\n */\nfunction count(state: InstallState, socket: WebSocket, direction: \"transmit\" | \"receive\"): void {\n const server = state.servers.get(socket);\n\n // A send of the library, for example a custom transport, must not make the next send.\n const own = direction === \"transmit\" && isLibraryRequest();\n if (\n !state.active ||\n server === undefined ||\n own ||\n (state.config.securityContext.isolation &&\n state.contexts.get(socket) !== state.config.securityContext.id)\n ) {\n return;\n }\n\n const attributes: MetricAttributes = {\n \"network.io.direction\": direction,\n \"server.address\": server,\n };\n state.messages.add(1, attributes);\n}\n\n/** Records the lifecycle and the message counts of each WebSocket that the app opens. */\nexport class WebSocketCapture implements CapturePlugin {\n /** Capture module identifier. */\n readonly name = \"websocket\";\n\n /** Restores the WebSocket constructor. Undefined when the capture is not installed. */\n private restore: (() => boolean) | undefined;\n\n /** State of the active install. */\n private state: InstallState | undefined;\n\n /** Rate limit of the lifecycle records. A reconnect loop must not flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param diagnostics Diagnostics reporter.\n * @param config Active configuration. The capture reads `capture.ignoreUrls`.\n */\n constructor(\n private readonly diagnostics: Diagnostics,\n private readonly config: ResolvedConfig,\n ) {}\n\n /**\n * Replaces the WebSocket constructor with a subclass that tracks each socket.\n * @param ctx Tools of the plugin.\n */\n install(ctx: PluginContext): void {\n if (this.restore || typeof WebSocket === \"undefined\") {\n return;\n }\n\n const state: InstallState = {\n active: true,\n ctx,\n messages: ctx.counter(MESSAGES_METRIC),\n servers: new WeakMap(),\n contexts: new WeakMap(),\n config: this.config,\n };\n this.state = state;\n\n const track = (socket: WebSocket): void => {\n this.track(socket, state);\n };\n\n this.restore = patch(\n globalThis,\n \"WebSocket\",\n (Original) =>\n class TrackedWebSocket extends Original {\n /**\n * Keeps instanceof true for a socket that the app opened before the install.\n * @param value Value to test.\n * @returns True for each native socket.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Original;\n }\n\n /**\n * @param url URL of the server.\n * @param protocols Sub-protocols of the app.\n */\n constructor(url: string | URL, protocols?: string | string[]) {\n super(url, protocols);\n track(this);\n }\n\n /**\n * Sends the data, then counts one message. A send that throws counts nothing.\n * @param data Data of the app. The library does not read it.\n */\n override send(data: SendData): void {\n super.send(data);\n count(state, this, \"transmit\");\n }\n },\n );\n }\n\n /** Restores the WebSocket constructor and stops each tracked socket from recording. */\n uninstall(): void {\n if (this.state) {\n this.state.active = false;\n }\n\n // Another script can wrap the constructor after the library. Keep its wrapper.\n if (this.restore && !this.restore()) {\n this.diagnostics.report(\n \"capture.install_failed\",\n \"Another script wrapped WebSocket after the library. The library keeps that wrapper.\",\n );\n }\n\n this.restore = undefined;\n this.state = undefined;\n }\n\n /**\n * Adds the listeners that record the lifecycle and the received messages of one socket.\n * @param socket New socket of the app.\n * @param state State of the install that made the socket.\n */\n private track(socket: WebSocket, state: InstallState): void {\n if (!state.active) {\n return;\n }\n\n // A read here runs inside the constructor call of the app. A throw must not fail it.\n this.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not track a WebSocket. The socket works without capture.\",\n () => {\n // ignoreUrls matches the full URL. A custom transport can send over its own socket.\n if (matchesAny(socket.url, this.config.capture.ignoreUrls)) {\n return;\n }\n\n const { target, server } = socketTarget(socket.url, this.config, this.diagnostics);\n const attributes = { \"url.full\": target, \"server.address\": server };\n const { logger } = state.ctx;\n state.servers.set(socket, server);\n state.contexts.set(socket, this.config.securityContext.id);\n\n const lifecycle = (write: () => void): void => {\n if (\n (!this.config.securityContext.isolation ||\n state.contexts.get(socket) === this.config.securityContext.id) &&\n this.allow(state)\n ) {\n write();\n }\n };\n\n socket.addEventListener(\"open\", () => {\n lifecycle(() => {\n logger.logEvent(\"websocket.open\", attributes);\n });\n });\n socket.addEventListener(\"error\", () => {\n lifecycle(() => {\n logger.warn(\"websocket.error\", attributes);\n });\n });\n socket.addEventListener(\"close\", (event) => {\n lifecycle(() => {\n logger.logEvent(\"websocket.close\", {\n ...attributes,\n \"websocket.close.code\": event.code,\n \"websocket.close.clean\": event.wasClean,\n });\n });\n });\n socket.addEventListener(\"message\", () => {\n count(state, socket, \"receive\");\n });\n },\n );\n }\n\n /**\n * Tests if a lifecycle record can go out.\n * @param state State of the install that made the socket.\n * @returns False after uninstall, or when the window has no allowance left.\n */\n private allow(state: InstallState): boolean {\n return (\n state.active &&\n allowInWindow(\n this.window,\n this.config.capturePolicy.webSocketPerWindow,\n this.diagnostics,\n \"WebSocket events\",\n this.config.capturePolicy.windowMs,\n )\n );\n }\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
package/dist/batch-D5qvsMQ_.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./constants-Cb92egPS.cjs"),t=require("./identity-C1WLItSl.cjs");function n(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`createdAt`),r=Reflect.get(e,`attempts`),i=Reflect.get(e,`records`);return typeof t==`string`&&typeof n==`number`&&typeof r==`number`&&Array.isArray(i)}function r(e,n){if(e.records.length<2)return null;let r=Math.floor(e.records.length/2),i=r=>({id:t.i(n),records:r,createdAt:e.createdAt,attempts:e.attempts});return[i(e.records.slice(0,r)),i(e.records.slice(r))]}function i(e,t){let n=e;if(typeof n!=`object`||!n)return;let r=Reflect.get(n,`attributes`);if(typeof r==`object`&&r)return Reflect.get(r,t)}function a(t){return i(t,e.d)===e.mt}function o(e){return e.reduce((e,t)=>e+t.records.length,0)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
2
|
-
//# sourceMappingURL=batch-D5qvsMQ_.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-D5qvsMQ_.cjs","names":["newId","ATTR_LOG_TYPE","LOG_TYPE_ACTION","require_constants","require_identity","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":"iFAiCA,SAAgBK,EAAW,EAAmC,CAC5D,GAAI,OAAOC,GAAU,WAAYA,EAC/B,MAAO,GAGT,IAAMC,EAAc,QAAQ,IAAID,EAAO,IAAI,EACrCE,EAAqB,QAAQ,IAAIF,EAAO,WAAW,EACnDG,EAAoB,QAAQ,IAAIH,EAAO,UAAU,EACjDI,EAAmB,QAAQ,IAAIJ,EAAO,SAAS,EAErD,OACE,OAAOC,GAAO,UACd,OAAOC,GAAc,UACrB,OAAOC,GAAa,UACpB,MAAM,QAAQC,CAAO,CAEzB,CASA,SAAgBC,EAAW,EAAiB,EAAuD,CACjG,GAAIC,EAAM,QAAQ,OAAS,EACzB,OAAO,KAGT,IAAMC,EAAS,KAAK,MAAMD,EAAM,QAAQ,OAAS,CAAC,EAC5CE,EAAS,IAAoC,CACjD,GAAId,EAAAA,EAAMe,CAAW,EACrB,UACA,UAAWH,EAAM,UACjB,SAAUA,EAAM,QAClB,GAEA,MAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,EAAGC,CAAM,CAAC,EAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC,CACnF,CASA,SAAgBG,EAAY,EAAmB,EAAsB,CACnE,IAAMV,EAAiBW,EACvB,GAAI,OAAOX,GAAU,WAAYA,EAC/B,OAGF,IAAMY,EAAsB,QAAQ,IAAIZ,EAAO,YAAY,EAC3D,GAAI,OAAOY,GAAe,UAAYA,EAItC,OAAO,QAAQ,IAAIA,EAAYC,CAAG,CACpC,CAOA,SAAgBC,EAAe,EAA4B,CACzD,OAAOJ,EAAYC,EAAQhB,EAAAA,CAAa,IAAMC,EAAAA,EAChD,CAOA,SAAgBmB,EAAa,EAAsC,CACjE,OAAOC,EAAQ,QAAQ,EAAO,IAAUC,EAAQX,EAAM,QAAQ,OAAQ,CAAC,CACzE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-DDgxg16_.js","names":["ATTR_LOG_TYPE","LOG_TYPE_ACTION","newId","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord","countRecords","batches","total"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n\n/**\n * Returns the total record count of the batches.\n * @param batches Batches to measure.\n * @returns Total record count.\n */\nexport function countRecords(batches: readonly LogBatch[]): number {\n return batches.reduce((total, batch) => total + batch.records.length, 0);\n}\n"],"mappings":";;;AAiCA,SAAgBG,EAAW,GAAmC;CAC5D,IAAI,OAAOC,KAAU,aAAYA,GAC/B,OAAO;CAGT,IAAMC,IAAc,QAAQ,IAAID,GAAO,IAAI,GACrCE,IAAqB,QAAQ,IAAIF,GAAO,WAAW,GACnDG,IAAoB,QAAQ,IAAIH,GAAO,UAAU,GACjDI,IAAmB,QAAQ,IAAIJ,GAAO,SAAS;CAErD,OACE,OAAOC,KAAO,YACd,OAAOC,KAAc,YACrB,OAAOC,KAAa,YACpB,MAAM,QAAQC,CAAO;AAEzB;AASA,SAAgBC,EAAW,GAAiB,GAAuD;CACjG,IAAIC,EAAM,QAAQ,SAAS,GACzB,OAAO;CAGT,IAAMC,IAAS,KAAK,MAAMD,EAAM,QAAQ,SAAS,CAAC,GAC5CE,KAAS,OAAoC;EACjD,IAAIV,EAAMW,CAAW;EACrB;EACA,WAAWH,EAAM;EACjB,UAAUA,EAAM;CAClB;CAEA,OAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,GAAGC,CAAM,CAAC,GAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC;AACnF;AASA,SAAgBG,EAAY,GAAmB,GAAsB;CACnE,IAAMV,IAAiBW;CACvB,IAAI,OAAOX,KAAU,aAAYA,GAC/B;CAGF,IAAMY,IAAsB,QAAQ,IAAIZ,GAAO,YAAY;CAC3D,IAAI,OAAOY,KAAe,YAAYA,GAItC,OAAO,QAAQ,IAAIA,GAAYC,CAAG;AACpC;AAOA,SAAgBC,EAAe,GAA4B;CACzD,OAAOJ,EAAYC,GAAQf,CAAa,MAAMC;AAChD;AAOA,SAAgBkB,EAAa,GAAsC;CACjE,OAAOC,EAAQ,QAAQ,GAAO,MAAUC,IAAQX,EAAM,QAAQ,QAAQ,CAAC;AACzE"}
|
package/dist/bus-C6RwKzPW.js
DELETED
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
import { C as e, E as t, Nt as n, Zt as r, w as i } from "./constants-DhH6VI5a.js";
|
|
2
|
-
import { r as a } from "./deadline-DeqXEliN.js";
|
|
3
|
-
import { t as o } from "./openfin-BwEN0uj4.js";
|
|
4
|
-
import { r as s } from "./journey-yALMEWF7.js";
|
|
5
|
-
import { n as c, t as l } from "./remote-rules-6ePq8CrI.js";
|
|
6
|
-
//#region src/models/bus.ts
|
|
7
|
-
function u(e) {
|
|
8
|
-
return {
|
|
9
|
-
p: t,
|
|
10
|
-
m: e
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function d(e) {
|
|
14
|
-
if (typeof e != "object" || !e) return null;
|
|
15
|
-
let t = e;
|
|
16
|
-
if (t.p !== "ui-observability/1" || typeof t.m != "object" || t.m === null) return null;
|
|
17
|
-
let n = t.m;
|
|
18
|
-
return typeof n.t == "string" ? n : null;
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/bus/links.ts
|
|
22
|
-
var f = Symbol.for(r), p = "null";
|
|
23
|
-
function m(e, t) {
|
|
24
|
-
return e === p ? `The bus ignored ${t} from a sandboxed frame. The frame has an opaque origin. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.` : `The bus ignored ${t} from ${e}. If you own this origin, add it to bus.trustedOrigins.`;
|
|
25
|
-
}
|
|
26
|
-
function h() {
|
|
27
|
-
let e = location.ancestorOrigins;
|
|
28
|
-
if (e && e.length > 0) return e.item(0);
|
|
29
|
-
let t = document.referrer;
|
|
30
|
-
if (t === "") return null;
|
|
31
|
-
try {
|
|
32
|
-
return new URL(t).origin;
|
|
33
|
-
} catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function g(e, t) {
|
|
38
|
-
if (typeof window > "u" || window.parent === window) return null;
|
|
39
|
-
let n;
|
|
40
|
-
try {
|
|
41
|
-
n = window.parent[f];
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
if (typeof n?.busAccept != "function") return null;
|
|
46
|
-
let r = n, i = !0;
|
|
47
|
-
return {
|
|
48
|
-
kind: "direct",
|
|
49
|
-
post(n) {
|
|
50
|
-
i && t.guard("bus.send_failed", "The direct call into the parent runtime failed.", () => {
|
|
51
|
-
r.busAccept(n, e);
|
|
52
|
-
});
|
|
53
|
-
},
|
|
54
|
-
close() {
|
|
55
|
-
i = !1;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function _(e, t, n) {
|
|
60
|
-
if (typeof window > "u" || window.parent === window) return null;
|
|
61
|
-
let r = location.origin;
|
|
62
|
-
if (r === p) return n.report("bus.untrusted_origin", "This frame is sandboxed without allow-same-origin. It has an opaque origin. No parent can trust it. This context sends its own records. Set bus.mode: \"sender\" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.", {
|
|
63
|
-
origin: r,
|
|
64
|
-
type: "parent"
|
|
65
|
-
}), null;
|
|
66
|
-
let i = /* @__PURE__ */ new Set([r, ...t]), a = h();
|
|
67
|
-
if (a === null || !i.has(a)) return n.report("bus.untrusted_origin", a === null ? "The origin of the parent frame is unknown. This context sends its own records." : `The parent frame is on ${a}. This origin is not in bus.trustedOrigins. This context sends its own records.`, {
|
|
68
|
-
origin: a ?? "",
|
|
69
|
-
type: "parent"
|
|
70
|
-
}), null;
|
|
71
|
-
let o = /* @__PURE__ */ new Set(), s = (t) => {
|
|
72
|
-
let r = d(t.data);
|
|
73
|
-
r && t.source === window.parent && (i.has(t.origin) ? e(r, {
|
|
74
|
-
link: "parent",
|
|
75
|
-
origin: t.origin
|
|
76
|
-
}) : o.has(t.origin) || (o.add(t.origin), n.report("bus.untrusted_origin", m(t.origin, "a message"), {
|
|
77
|
-
origin: t.origin,
|
|
78
|
-
type: r.t.slice(0, 32)
|
|
79
|
-
})));
|
|
80
|
-
};
|
|
81
|
-
return addEventListener("message", s), {
|
|
82
|
-
kind: "parent",
|
|
83
|
-
post(e) {
|
|
84
|
-
n.guard("bus.send_failed", "The postMessage call to the parent failed.", () => {
|
|
85
|
-
window.parent.postMessage(u(e), a);
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
close() {
|
|
89
|
-
removeEventListener("message", s);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function v(e, t, n) {
|
|
94
|
-
if (typeof window > "u") return null;
|
|
95
|
-
let r = /* @__PURE__ */ new Set([location.origin, ...t]);
|
|
96
|
-
r.delete(p);
|
|
97
|
-
let i = /* @__PURE__ */ new Map(), a = (t) => {
|
|
98
|
-
let a = d(t.data);
|
|
99
|
-
a && (r.has(t.origin) ? (t.source && i.set(t.source, t.origin), e(a, {
|
|
100
|
-
link: "children",
|
|
101
|
-
origin: t.origin
|
|
102
|
-
})) : n.report("bus.untrusted_origin", m(t.origin, "a message"), {
|
|
103
|
-
origin: t.origin,
|
|
104
|
-
type: a.t.slice(0, 32)
|
|
105
|
-
}));
|
|
106
|
-
};
|
|
107
|
-
return addEventListener("message", a), {
|
|
108
|
-
kind: "children",
|
|
109
|
-
post(e) {
|
|
110
|
-
for (let [t, r] of i) {
|
|
111
|
-
let a = t;
|
|
112
|
-
a.closed ? i.delete(t) : n.guard("bus.send_failed", "The postMessage call to a child frame failed.", () => {
|
|
113
|
-
a.postMessage(u(e), r);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
close() {
|
|
118
|
-
removeEventListener("message", a), i.clear();
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
function y(e, t, n) {
|
|
123
|
-
let r = globalThis.BroadcastChannel;
|
|
124
|
-
if (r === void 0) return null;
|
|
125
|
-
let i = n.guard("bus.send_failed", "The library could not open the BroadcastChannel.", () => new r(e));
|
|
126
|
-
return i ? (i.onmessage = (e) => {
|
|
127
|
-
let n = d(e.data);
|
|
128
|
-
n && t(n, {
|
|
129
|
-
link: "broadcast",
|
|
130
|
-
origin: "same-origin"
|
|
131
|
-
});
|
|
132
|
-
}, {
|
|
133
|
-
kind: "broadcast",
|
|
134
|
-
post(e) {
|
|
135
|
-
n.guard("bus.send_failed", "The BroadcastChannel.postMessage call failed.", () => {
|
|
136
|
-
i.postMessage(u(e));
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
close() {
|
|
140
|
-
n.guard("bus.send_failed", "The library could not close the BroadcastChannel.", () => {
|
|
141
|
-
i.close();
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}) : null;
|
|
145
|
-
}
|
|
146
|
-
function b(e, t, n, r) {
|
|
147
|
-
let i = o()?.InterApplicationBus;
|
|
148
|
-
if (!i) return null;
|
|
149
|
-
if (!t) return r.report("openfin.unavailable", "OpenFin gives no application uuid. The InterApplicationBus link stays closed."), null;
|
|
150
|
-
let a = `${e}.${t}`;
|
|
151
|
-
return r.guardAsync("bus.send_failed", "The InterApplicationBus.subscribe call failed.", () => i.subscribe({ uuid: t }, a, (e) => {
|
|
152
|
-
let t = d(e);
|
|
153
|
-
t && n(t, {
|
|
154
|
-
link: "openfin",
|
|
155
|
-
origin: "openfin"
|
|
156
|
-
});
|
|
157
|
-
})), {
|
|
158
|
-
kind: "openfin",
|
|
159
|
-
post(e) {
|
|
160
|
-
r.guardAsync("bus.send_failed", "The InterApplicationBus.publish call failed.", () => i.publish(a, u(e)));
|
|
161
|
-
},
|
|
162
|
-
close() {}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function x(e, t) {
|
|
166
|
-
let n = globalThis, r = n.postMessage;
|
|
167
|
-
return n.WorkerGlobalScope === void 0 || !r ? null : (n.addEventListener?.("message", (t) => {
|
|
168
|
-
let n = d(t.data);
|
|
169
|
-
n && e(n, {
|
|
170
|
-
link: "owner",
|
|
171
|
-
origin: "same-origin"
|
|
172
|
-
});
|
|
173
|
-
}), {
|
|
174
|
-
kind: "owner",
|
|
175
|
-
post(e) {
|
|
176
|
-
t.guard("bus.send_failed", "The postMessage call of the worker failed.", () => {
|
|
177
|
-
r(u(e));
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
close() {}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
function S(e, t, n) {
|
|
184
|
-
let r = (e) => {
|
|
185
|
-
let n = d(e.data);
|
|
186
|
-
n && t(n, {
|
|
187
|
-
link: "worker",
|
|
188
|
-
origin: "same-origin"
|
|
189
|
-
});
|
|
190
|
-
};
|
|
191
|
-
return e.addEventListener("message", r), e.start?.(), {
|
|
192
|
-
kind: "worker",
|
|
193
|
-
post(t) {
|
|
194
|
-
n.guard("bus.send_failed", "The postMessage call to a worker failed.", () => {
|
|
195
|
-
e.postMessage(u(t));
|
|
196
|
-
});
|
|
197
|
-
},
|
|
198
|
-
close() {
|
|
199
|
-
e.removeEventListener("message", r);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
//#endregion
|
|
204
|
-
//#region src/bus/bus.ts
|
|
205
|
-
var C = {
|
|
206
|
-
timeoutMs: i,
|
|
207
|
-
maxAttempts: 3
|
|
208
|
-
}, w = [
|
|
209
|
-
"children",
|
|
210
|
-
"direct",
|
|
211
|
-
"worker"
|
|
212
|
-
], T = class {
|
|
213
|
-
config;
|
|
214
|
-
diagnostics;
|
|
215
|
-
platform;
|
|
216
|
-
contextId;
|
|
217
|
-
tabId;
|
|
218
|
-
handlers;
|
|
219
|
-
handshakeOptions;
|
|
220
|
-
role = "sender";
|
|
221
|
-
upstream = null;
|
|
222
|
-
links = [];
|
|
223
|
-
openFinLink = null;
|
|
224
|
-
isOpenFinProvider = !1;
|
|
225
|
-
rulesPoll;
|
|
226
|
-
destroyed = !1;
|
|
227
|
-
ownerId = null;
|
|
228
|
-
awaitingWelcome = null;
|
|
229
|
-
constructor(e, t, n, r, i, a, o = C) {
|
|
230
|
-
this.config = e, this.diagnostics = t, this.platform = n, this.contextId = r, this.tabId = i, this.handlers = a, this.handshakeOptions = o;
|
|
231
|
-
}
|
|
232
|
-
getRole() {
|
|
233
|
-
return this.role;
|
|
234
|
-
}
|
|
235
|
-
async start() {
|
|
236
|
-
let { bus: e } = this.config;
|
|
237
|
-
if (e.mode === "off") return this.role = "sender", this.role;
|
|
238
|
-
if (this.isOpenFinProvider = this.resolveOpenFinProvider(), e.mode === "sender" || e.mode === "forwarder") return this.role = e.mode, this.openControlLinks(), this.role === "forwarder" && (this.upstream = this.candidateUpstream(), this.upstream || this.diagnostics.report("bus.no_owner", "bus.mode is \"forwarder\". No owner exists. The library drops the records of this context.")), this.announce(), this.role;
|
|
239
|
-
this.openControlLinks();
|
|
240
|
-
let t = g(this.receive, this.diagnostics);
|
|
241
|
-
if (t) return this.role = "forwarder", this.upstream = t, this.diagnostics.report("bus.role_resolved", "This context attached directly to the runtime of its same-origin parent.", {
|
|
242
|
-
role: "forwarder",
|
|
243
|
-
via: "direct"
|
|
244
|
-
}), this.announce(), this.role;
|
|
245
|
-
let n = this.candidateUpstream();
|
|
246
|
-
if (!n) return this.role = "sender", this.diagnostics.report("bus.role_resolved", "No owner exists. This context sends its own records.", { role: "sender" }), this.announce(), this.role;
|
|
247
|
-
let r = this.orphanPolicy() === "retry" ? this.handshakeOptions.maxAttempts : 1, i = !1;
|
|
248
|
-
for (let e = 0; e < r && !i; e++) i = await this.handshake(n);
|
|
249
|
-
return this.role = i ? "forwarder" : "sender", this.upstream = i ? n : null, i || (n !== this.openFinLink && n.close(), this.diagnostics.report("bus.handshake_timeout", `No owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`, {
|
|
250
|
-
via: n.kind,
|
|
251
|
-
crossOrigin: this.isCrossOriginFrame()
|
|
252
|
-
})), this.diagnostics.report("bus.role_resolved", `The bus role is ${this.role}.`, {
|
|
253
|
-
role: this.role,
|
|
254
|
-
via: i ? n.kind : "none"
|
|
255
|
-
}), this.announce(), this.role;
|
|
256
|
-
}
|
|
257
|
-
sendRecords(e) {
|
|
258
|
-
this.upstream?.post({
|
|
259
|
-
t: "records",
|
|
260
|
-
from: this.contextId,
|
|
261
|
-
records: e
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
acceptDirect(e, t) {
|
|
265
|
-
if (e.from === this.contextId) return;
|
|
266
|
-
let n = {
|
|
267
|
-
link: "direct",
|
|
268
|
-
origin: "same-origin"
|
|
269
|
-
};
|
|
270
|
-
if (e.t === "hello") this.canOwn("direct") && t({
|
|
271
|
-
t: "welcome",
|
|
272
|
-
from: this.contextId,
|
|
273
|
-
to: e.from,
|
|
274
|
-
tabId: this.tabId
|
|
275
|
-
}, n);
|
|
276
|
-
else if (e.t === "journey?") {
|
|
277
|
-
let r = this.handlers.onJourneyRequest();
|
|
278
|
-
r && this.journeyLink("direct") && t({
|
|
279
|
-
t: "journey",
|
|
280
|
-
from: this.contextId,
|
|
281
|
-
to: e.from,
|
|
282
|
-
journey: r
|
|
283
|
-
}, n);
|
|
284
|
-
} else e.t === "sampling?" ? t(this.rulesAnswer(e.from), n) : this.receive(e, n);
|
|
285
|
-
}
|
|
286
|
-
attachWorker(e) {
|
|
287
|
-
this.links.push(S(e, this.receive, this.diagnostics));
|
|
288
|
-
}
|
|
289
|
-
broadcastJourney(e) {
|
|
290
|
-
this.postJourney({
|
|
291
|
-
t: "journey",
|
|
292
|
-
from: this.contextId,
|
|
293
|
-
journey: e
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
destroy() {
|
|
297
|
-
this.destroyed = !0, clearInterval(this.rulesPoll), this.rulesPoll = void 0;
|
|
298
|
-
for (let e of this.allLinks()) e.close();
|
|
299
|
-
this.links.length = 0, this.upstream = null, this.ownerId = null, this.openFinLink = null;
|
|
300
|
-
}
|
|
301
|
-
allLinks() {
|
|
302
|
-
return !this.upstream || this.links.includes(this.upstream) ? this.links : [...this.links, this.upstream];
|
|
303
|
-
}
|
|
304
|
-
postOver(e, t) {
|
|
305
|
-
for (let n of this.allLinks()) n.kind === e && n.post(t);
|
|
306
|
-
}
|
|
307
|
-
postJourney(e) {
|
|
308
|
-
for (let t of this.allLinks()) this.journeyLink(t.kind) && t.post(e);
|
|
309
|
-
}
|
|
310
|
-
receive = (e, t) => {
|
|
311
|
-
if (e.from !== this.contextId) switch (e.t) {
|
|
312
|
-
case "hello":
|
|
313
|
-
this.canOwn(t.link) && this.postOver(t.link, {
|
|
314
|
-
t: "welcome",
|
|
315
|
-
from: this.contextId,
|
|
316
|
-
to: e.from,
|
|
317
|
-
tabId: this.tabId
|
|
318
|
-
});
|
|
319
|
-
break;
|
|
320
|
-
case "welcome":
|
|
321
|
-
if (e.to !== this.contextId) break;
|
|
322
|
-
this.awaitingWelcome?.link === t.link && (this.ownerId = e.from, this.awaitingWelcome.settle(!0));
|
|
323
|
-
break;
|
|
324
|
-
case "records":
|
|
325
|
-
this.role === "sender" ? this.handlers.onRecords(e.records) : this.upstream && this.canRelay(t.link) && this.upstream.post(e);
|
|
326
|
-
break;
|
|
327
|
-
case "journey":
|
|
328
|
-
this.acceptsJourney(e, t) && this.applyJourney(e.journey);
|
|
329
|
-
break;
|
|
330
|
-
case "journey?": {
|
|
331
|
-
let n = this.handlers.onJourneyRequest();
|
|
332
|
-
n && this.journeyLink(t.link) && this.postOver(t.link, {
|
|
333
|
-
t: "journey",
|
|
334
|
-
from: this.contextId,
|
|
335
|
-
to: e.from,
|
|
336
|
-
journey: n
|
|
337
|
-
});
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
case "sampling?":
|
|
341
|
-
(this.role === "forwarder" ? t.link !== this.upstream?.kind : this.canOwn(t.link)) && this.postOver(t.link, this.rulesAnswer(e.from));
|
|
342
|
-
break;
|
|
343
|
-
case "sampling":
|
|
344
|
-
this.acceptsRules(e.to, t) && this.applyRules(e.rules);
|
|
345
|
-
break;
|
|
346
|
-
case "tab": t.link === "broadcast" && e.tabId === this.tabId && this.contextId > e.from && this.handlers.onTabConflict();
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
canRelay(e) {
|
|
350
|
-
return e === "direct" || e !== this.upstream?.kind;
|
|
351
|
-
}
|
|
352
|
-
canOwn(e) {
|
|
353
|
-
return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : w.includes(e) : !1;
|
|
354
|
-
}
|
|
355
|
-
resolveOpenFinProvider() {
|
|
356
|
-
let e = this.config.bus.openFinRole;
|
|
357
|
-
if (e !== "auto") return e === "provider";
|
|
358
|
-
if (this.platform.platform !== "openfin" && this.platform.platform !== "openfin_web") return !1;
|
|
359
|
-
let t = o()?.me;
|
|
360
|
-
return !t?.identity || t.isView ? !1 : !!(t.identity.name && t.identity.name === t.identity.uuid);
|
|
361
|
-
}
|
|
362
|
-
orphanPolicy() {
|
|
363
|
-
return this.isCrossOriginFrame() ? "retry" : "promote";
|
|
364
|
-
}
|
|
365
|
-
isCrossOriginFrame() {
|
|
366
|
-
if (typeof window > "u" || window.parent === window) return !1;
|
|
367
|
-
try {
|
|
368
|
-
return Reflect.get(window.parent, "location"), !1;
|
|
369
|
-
} catch {
|
|
370
|
-
return !0;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
candidateUpstream() {
|
|
374
|
-
return this.platform.isWorker ? x(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : _(this.receive, this.config.bus.trustedOrigins, this.diagnostics);
|
|
375
|
-
}
|
|
376
|
-
openControlLinks() {
|
|
377
|
-
let t = (e) => {
|
|
378
|
-
e && this.links.push(e);
|
|
379
|
-
};
|
|
380
|
-
this.platform.isTopLevelDocument && (t(v(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), t(y(e, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && t(this.ensureOpenFinLink());
|
|
381
|
-
}
|
|
382
|
-
ensureOpenFinLink() {
|
|
383
|
-
return this.openFinLink ??= b(e, this.platform.openfinUuid, this.receive, this.diagnostics), this.openFinLink;
|
|
384
|
-
}
|
|
385
|
-
handshake(e) {
|
|
386
|
-
return new Promise((t) => {
|
|
387
|
-
let n = !1, r = (e) => {
|
|
388
|
-
n || (n = !0, this.awaitingWelcome = null, clearTimeout(i), t(e));
|
|
389
|
-
};
|
|
390
|
-
this.awaitingWelcome = {
|
|
391
|
-
link: e.kind,
|
|
392
|
-
settle: r
|
|
393
|
-
};
|
|
394
|
-
let i = setTimeout(() => {
|
|
395
|
-
r(!1);
|
|
396
|
-
}, this.handshakeOptions.timeoutMs);
|
|
397
|
-
a(i), e.post({
|
|
398
|
-
t: "hello",
|
|
399
|
-
from: this.contextId,
|
|
400
|
-
tabId: this.tabId
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
announce() {
|
|
405
|
-
this.postOver("broadcast", {
|
|
406
|
-
t: "tab",
|
|
407
|
-
from: this.contextId,
|
|
408
|
-
tabId: this.tabId
|
|
409
|
-
}), this.postJourney({
|
|
410
|
-
t: "journey?",
|
|
411
|
-
from: this.contextId
|
|
412
|
-
}), this.pollRules();
|
|
413
|
-
}
|
|
414
|
-
journeyScope() {
|
|
415
|
-
let { scope: e } = this.config.journey;
|
|
416
|
-
if (e !== "auto") return e;
|
|
417
|
-
let { platform: t } = this.platform;
|
|
418
|
-
return t === "openfin" || t === "openfin_web" ? "origin" : "tab";
|
|
419
|
-
}
|
|
420
|
-
journeyLink(e) {
|
|
421
|
-
let t = this.journeyScope();
|
|
422
|
-
return t === "context" ? !1 : t === "origin" || e !== "broadcast";
|
|
423
|
-
}
|
|
424
|
-
acceptsJourney(e, t) {
|
|
425
|
-
return !this.journeyLink(t.link) || e.to !== void 0 && e.to !== this.contextId ? !1 : this.journeyScope() === "origin" || this.fromOwner(e.from, t.link);
|
|
426
|
-
}
|
|
427
|
-
fromOwner(e, t) {
|
|
428
|
-
return this.role !== "forwarder" || t !== this.upstream?.kind ? !1 : this.ownerId === null || e === this.ownerId;
|
|
429
|
-
}
|
|
430
|
-
applyJourney(e) {
|
|
431
|
-
if (e === null) {
|
|
432
|
-
this.handlers.onJourney(null);
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
let t = s(e);
|
|
436
|
-
t === null ? this.diagnostics.report("record.dropped_malformed", "The bus dropped a journey message. Its payload is not a journey.", { type: "journey" }) : this.handlers.onJourney(t);
|
|
437
|
-
}
|
|
438
|
-
rulesAnswer(e) {
|
|
439
|
-
let t = this.handlers.remote.sampling?.wire() ?? null;
|
|
440
|
-
return {
|
|
441
|
-
t: "sampling",
|
|
442
|
-
from: this.contextId,
|
|
443
|
-
to: e,
|
|
444
|
-
rules: t
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
acceptsRules(e, t) {
|
|
448
|
-
if (this.role !== "forwarder" || e !== this.contextId || t.link !== this.upstream?.kind) return !1;
|
|
449
|
-
let { origin: n } = t;
|
|
450
|
-
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.`, {
|
|
451
|
-
origin: n,
|
|
452
|
-
type: "sampling"
|
|
453
|
-
}), !1) : !0;
|
|
454
|
-
}
|
|
455
|
-
applyRules(e) {
|
|
456
|
-
if (e === null) {
|
|
457
|
-
l(this.handlers.remote, this.config, null);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
let t = c(e, this.diagnostics);
|
|
461
|
-
t && l(this.handlers.remote, this.config, t);
|
|
462
|
-
}
|
|
463
|
-
pollRules() {
|
|
464
|
-
let { upstream: e } = this;
|
|
465
|
-
if (this.destroyed || this.role !== "forwarder" || !e) return;
|
|
466
|
-
let t = () => {
|
|
467
|
-
this.config.sampling.remote && e.post({
|
|
468
|
-
t: "sampling?",
|
|
469
|
-
from: this.contextId
|
|
470
|
-
});
|
|
471
|
-
};
|
|
472
|
-
t(), this.rulesPoll = setInterval(t, n), a(this.rulesPoll);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
//#endregion
|
|
476
|
-
export { T as Bus };
|
|
477
|
-
|
|
478
|
-
//# sourceMappingURL=bus-C6RwKzPW.js.map
|