@absolutejs/beacon 0.7.0-beta.2 → 0.7.0-beta.21
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 +89 -0
- package/README.md +56 -1
- package/changelog.json +201 -0
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.js +2 -9
- package/dist/contracts.js.map +3 -3
- package/dist/early.js +2 -10
- package/dist/early.js.map +3 -3
- package/dist/index.d.ts +13 -1
- package/dist/index.js +447 -195
- package/dist/index.js.map +5 -5
- package/dist/manifest.js +1 -9
- package/dist/manifest.js.map +2 -2
- package/dist/outbox.d.ts +42 -0
- package/dist/outbox.js +170 -0
- package/dist/outbox.js.map +10 -0
- package/dist/policy.d.ts +9 -0
- package/dist/policy.js +8 -10
- package/dist/policy.js.map +4 -4
- package/package.json +17 -7
package/dist/manifest.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
1
|
// src/manifest.ts
|
|
10
2
|
import { defineManifest } from "@absolutejs/manifest";
|
|
11
3
|
import { Type } from "@sinclair/typebox";
|
|
@@ -109,5 +101,5 @@ export {
|
|
|
109
101
|
manifest
|
|
110
102
|
};
|
|
111
103
|
|
|
112
|
-
//# debugId=
|
|
104
|
+
//# debugId=CA2283C496CB01DC64756E2164756E21
|
|
113
105
|
//# sourceMappingURL=manifest.js.map
|
package/dist/manifest.js.map
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { defineManifest } from \"@absolutejs/manifest\";\nimport { Type } from \"@sinclair/typebox\";\nimport type { BeaconOptions } from \"./index\";\n\nconst MAX_BATCH = 100;\nconst MAX_BREADCRUMBS = 200;\nconst MIN_FLUSH_INTERVAL_MS = 250;\n\n/* Serializable, browser-safe subset of BeaconOptions. `key`, `transport`,\n * `beforeSend`, and `getReplayId` are host capabilities and must never be\n * generated from settings. In particular, a browser manifest must not invite\n * an agent to embed an ingest credential. */\nexport const manifest = defineManifest<BeaconOptions>()({\n contract: 2,\n identity: {\n accent: \"#f97316\",\n category: \"observability\",\n description:\n \"Tiny browser observability SDK for uncaught errors, rejected promises, breadcrumbs, actionable UX/network signals, Core Web Vitals, trace correlation, and an optional session-replay id. Envelopes are validated by @absolutejs/errors/ingest; no credential belongs in browser settings.\",\n docsUrl: \"https://github.com/absolutejs/beacon\",\n name: \"@absolutejs/beacon\",\n tagline: \"Learn what visitors experience when a site goes wrong.\",\n },\n settings: Type.Object({\n endpoint: Type.Optional(\n Type.String({\n default: \"/api/errors/ingest\",\n description:\n \"Same-origin or explicitly allowed error-ingest endpoint. Never put credentials in this URL.\",\n title: \"Error ingest endpoint\",\n }),\n ),\n environment: Type.Optional(\n Type.String({\n description: \"Deployment environment attached to each event.\",\n examples: [\"production\"],\n title: \"Environment\",\n }),\n ),\n filterKnownNoise: Type.Optional(\n Type.Boolean({\n default: true,\n description:\n \"Drop signatures known to originate in browser hosts and scanners rather than application code.\",\n title: \"Filter known browser noise\",\n \"x-group\": \"advanced\",\n }),\n ),\n flushIntervalMs: Type.Optional(\n Type.Integer({\n description:\n \"How often buffered errors are flushed, in milliseconds. Default is 5000.\",\n minimum: MIN_FLUSH_INTERVAL_MS,\n title: \"Flush interval\",\n \"x-group\": \"advanced\",\n }),\n ),\n maxBatch: Type.Optional(\n Type.Integer({\n description: \"Flush once this many events are buffered. Default is 30.\",\n maximum: MAX_BATCH,\n minimum: 1,\n title: \"Events per batch\",\n \"x-group\": \"advanced\",\n }),\n ),\n maxBreadcrumbs: Type.Optional(\n Type.Integer({\n description:\n \"Recent browser actions retained with an event. Default is 30.\",\n maximum: MAX_BREADCRUMBS,\n minimum: 0,\n title: \"Breadcrumb limit\",\n \"x-group\": \"advanced\",\n }),\n ),\n project: Type.String({\n default: \"web\",\n description:\n \"Project identifier accepted by the host ingest boundary. Managed hosts replace this with their tenant id.\",\n title: \"Project\",\n }),\n release: Type.Optional(\n Type.String({\n description: \"Immutable application release identifier.\",\n title: \"Release\",\n }),\n ),\n sampleRate: Type.Optional(\n Type.Number({\n default: 1,\n description: \"Fraction of captured events retained, from 0 to 1.\",\n maximum: 1,\n minimum: 0,\n title: \"Event sample rate\",\n }),\n ),\n signals: Type.Optional(\n Type.Boolean({\n default: true,\n description:\n \"Capture actionable browser reliability, accessibility, network, policy, worker, and realtime-transport failures.\",\n title: \"Actionable browser signals\",\n }),\n ),\n redact: Type.Optional(\n Type.Boolean({\n default: true,\n description:\n \"Remove credential-bearing fields and URL query/hash values before events are buffered. Keep this on unless an equivalent trusted boundary owns redaction.\",\n title: \"Redact sensitive data\",\n }),\n ),\n vitals: Type.Optional(\n Type.Boolean({\n description:\n \"Capture Core Web Vitals through the optional web-vitals peer.\",\n title: \"Core Web Vitals\",\n }),\n ),\n }),\n wiring: [\n {\n description:\n \"Initialize privacy-conscious browser error and experience capture. A host can add replay correlation through getReplayId without exposing it as configuration.\",\n id: \"default\",\n client: {\n client: {\n code: \"const beacon = initBeacon(${settings});\",\n imports: [{ from: \"@absolutejs/beacon\", names: [\"initBeacon\"] }],\n placement: \"client-entry\",\n },\n },\n title: \"Capture browser errors and experience signals\",\n },\n ],\n});\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AACA;AAGA,IAAM,YAAY;AAClB,IAAM,kBAAkB;AACxB,IAAM,wBAAwB;AAMvB,IAAM,WAAW,eAA8B,EAAE;AAAA,EACtD,UAAU;AAAA,EACV,UAAU;AAAA,IACR,QAAQ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T,OAAO;AAAA,IACT,CAAC,CACH;AAAA,IACA,SAAS,KAAK,SACZ,KAAK,QAAQ;AAAA,MACX,SAAS;AAAA,MACT,aACE;AAAA,MACF,OAAO;AAAA,IACT,CAAC,CACH;AAAA,IACA,QAAQ,KAAK,SACX,KAAK,QAAQ;AAAA,MACX,SAAS;AAAA,MACT,aACE;AAAA,MACF,OAAO;AAAA,IACT,CAAC,CACH;AAAA,IACA,QAAQ,KAAK,SACX,KAAK,QAAQ;AAAA,MACX,aACE;AAAA,MACF,OAAO;AAAA,IACT,CAAC,CACH;AAAA,EACF,CAAC;AAAA,EACD,QAAQ;AAAA,IACN;AAAA,MACE,aACE;AAAA,MACF,IAAI;AAAA,MACJ,QAAQ;AAAA,QACN,QAAQ;AAAA,UACN,MAAM;AAAA,UACN,SAAS,CAAC,EAAE,MAAM,sBAAsB,OAAO,CAAC,YAAY,EAAE,CAAC;AAAA,UAC/D,WAAW;AAAA,QACb;AAAA,MACF;AAAA,MACA,OAAO;AAAA,IACT;AAAA,EACF;AACF,CAAC;",
|
|
8
|
+
"debugId": "CA2283C496CB01DC64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/outbox.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Durable, bounded delivery for JSON telemetry. Call enqueue only with redacted data.
|
|
2
|
+
* Server must deduplicate by id and acknowledge that id after committing storage.
|
|
3
|
+
* Browser persistence is best effort: unavailable/quota-exhausted storage is reported.
|
|
4
|
+
*/
|
|
5
|
+
export type OutboxRecord = {
|
|
6
|
+
id: string;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
body: string;
|
|
9
|
+
bytes: number;
|
|
10
|
+
};
|
|
11
|
+
export interface OutboxStore {
|
|
12
|
+
list(): Promise<OutboxRecord[]>;
|
|
13
|
+
put(record: OutboxRecord): Promise<void>;
|
|
14
|
+
remove(id: string): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare function createIndexedDBOutboxStore(name?: string): OutboxStore;
|
|
17
|
+
export declare function createMemoryOutboxStore(): OutboxStore;
|
|
18
|
+
export declare function createOutbox(options: {
|
|
19
|
+
store: OutboxStore;
|
|
20
|
+
send: (record: OutboxRecord, signal: AbortSignal) => Promise<string>;
|
|
21
|
+
now?: () => number;
|
|
22
|
+
random?: () => number;
|
|
23
|
+
maxItems?: number;
|
|
24
|
+
maxBytes?: number;
|
|
25
|
+
maxRecordBytes?: number;
|
|
26
|
+
maxAgeMs?: number;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
}): {
|
|
29
|
+
stats: () => {
|
|
30
|
+
nextAttempt: number;
|
|
31
|
+
pending: number;
|
|
32
|
+
bytes: number;
|
|
33
|
+
dropped: number;
|
|
34
|
+
expired: number;
|
|
35
|
+
storageErrors: number;
|
|
36
|
+
failedAttempts: number;
|
|
37
|
+
acknowledged: number;
|
|
38
|
+
persistMs: number;
|
|
39
|
+
};
|
|
40
|
+
enqueue(value: unknown, id?: string): Promise<string>;
|
|
41
|
+
flush(): Promise<void>;
|
|
42
|
+
};
|
package/dist/outbox.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// src/outbox.ts
|
|
2
|
+
function createIndexedDBOutboxStore(name = "absolute-beacon-outbox") {
|
|
3
|
+
let opening;
|
|
4
|
+
const open = () => opening ??= new Promise((resolve, reject) => {
|
|
5
|
+
const request = indexedDB.open(name, 1);
|
|
6
|
+
request.onupgradeneeded = () => request.result.createObjectStore("pending", { keyPath: "id" });
|
|
7
|
+
request.onerror = () => {
|
|
8
|
+
opening = undefined;
|
|
9
|
+
reject(request.error);
|
|
10
|
+
};
|
|
11
|
+
request.onblocked = () => {
|
|
12
|
+
opening = undefined;
|
|
13
|
+
reject(Error("Outbox database blocked"));
|
|
14
|
+
};
|
|
15
|
+
request.onsuccess = () => {
|
|
16
|
+
request.result.onversionchange = () => {
|
|
17
|
+
request.result.close();
|
|
18
|
+
opening = undefined;
|
|
19
|
+
};
|
|
20
|
+
resolve(request.result);
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
const transact = async (mode, action) => {
|
|
24
|
+
const db = await open();
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const tx = db.transaction("pending", mode), request = action(tx.objectStore("pending"));
|
|
27
|
+
tx.oncomplete = () => resolve(request.result);
|
|
28
|
+
tx.onabort = tx.onerror = () => reject(tx.error ?? request.error ?? Error("Outbox storage failed"));
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
list: () => transact("readonly", (s) => s.getAll()),
|
|
33
|
+
put: async (r) => {
|
|
34
|
+
await transact("readwrite", (s) => s.put(r));
|
|
35
|
+
},
|
|
36
|
+
remove: async (id) => {
|
|
37
|
+
await transact("readwrite", (s) => s.delete(id));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createMemoryOutboxStore() {
|
|
42
|
+
const records = new Map;
|
|
43
|
+
return {
|
|
44
|
+
list: async () => [...records.values()],
|
|
45
|
+
put: async (r) => {
|
|
46
|
+
records.set(r.id, r);
|
|
47
|
+
},
|
|
48
|
+
remove: async (id) => {
|
|
49
|
+
records.delete(id);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function createOutbox(options) {
|
|
54
|
+
const now = options.now ?? Date.now, random = options.random ?? Math.random;
|
|
55
|
+
const maxItems = options.maxItems ?? 128, maxBytes = options.maxBytes ?? 4000000, maxRecordBytes = options.maxRecordBytes ?? 1e6, maxAge = options.maxAgeMs ?? 172800000;
|
|
56
|
+
let sequence = Promise.resolve(), flushing = null, nextAttempt = 0, failures = 0;
|
|
57
|
+
const stats = {
|
|
58
|
+
pending: 0,
|
|
59
|
+
bytes: 0,
|
|
60
|
+
dropped: 0,
|
|
61
|
+
expired: 0,
|
|
62
|
+
storageErrors: 0,
|
|
63
|
+
failedAttempts: 0,
|
|
64
|
+
acknowledged: 0,
|
|
65
|
+
persistMs: 0
|
|
66
|
+
};
|
|
67
|
+
const lock = (fn) => {
|
|
68
|
+
const result = sequence.then(fn);
|
|
69
|
+
sequence = result.then(() => {}, () => {});
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
const prune = async () => {
|
|
73
|
+
let rows = (await options.store.list()).sort((a, b) => a.createdAt - b.createdAt || a.id.localeCompare(b.id));
|
|
74
|
+
for (const row of rows)
|
|
75
|
+
if (now() - row.createdAt > maxAge) {
|
|
76
|
+
await options.store.remove(row.id);
|
|
77
|
+
stats.expired++;
|
|
78
|
+
}
|
|
79
|
+
rows = rows.filter((r) => now() - r.createdAt <= maxAge);
|
|
80
|
+
let bytes = rows.reduce((n, r) => n + r.bytes, 0);
|
|
81
|
+
while (rows.length > maxItems || bytes > maxBytes) {
|
|
82
|
+
const row = rows.shift();
|
|
83
|
+
await options.store.remove(row.id);
|
|
84
|
+
bytes -= row.bytes;
|
|
85
|
+
stats.dropped++;
|
|
86
|
+
}
|
|
87
|
+
stats.pending = rows.length;
|
|
88
|
+
stats.bytes = bytes;
|
|
89
|
+
return rows;
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
stats: () => ({ ...stats, nextAttempt }),
|
|
93
|
+
enqueue(value, id = crypto.randomUUID()) {
|
|
94
|
+
const body = JSON.stringify(value), bytes = new TextEncoder().encode(body).byteLength;
|
|
95
|
+
if (bytes > maxRecordBytes || bytes > maxBytes)
|
|
96
|
+
return Promise.reject(Error("Telemetry record exceeds outbox limit"));
|
|
97
|
+
return lock(async () => {
|
|
98
|
+
const started = performance.now();
|
|
99
|
+
try {
|
|
100
|
+
await options.store.put({ id, createdAt: now(), body, bytes });
|
|
101
|
+
await prune();
|
|
102
|
+
return id;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
stats.storageErrors++;
|
|
105
|
+
throw error;
|
|
106
|
+
} finally {
|
|
107
|
+
stats.persistMs += performance.now() - started;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
flush() {
|
|
112
|
+
if (flushing)
|
|
113
|
+
return flushing;
|
|
114
|
+
if (now() < nextAttempt)
|
|
115
|
+
return Promise.resolve();
|
|
116
|
+
flushing = (async () => {
|
|
117
|
+
let rows;
|
|
118
|
+
try {
|
|
119
|
+
rows = await lock(prune);
|
|
120
|
+
} catch {
|
|
121
|
+
stats.storageErrors++;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
for (const row of rows) {
|
|
125
|
+
const controller = new AbortController;
|
|
126
|
+
let timer;
|
|
127
|
+
try {
|
|
128
|
+
const ack = await Promise.race([
|
|
129
|
+
options.send(row, controller.signal),
|
|
130
|
+
new Promise((_, reject) => {
|
|
131
|
+
timer = setTimeout(() => {
|
|
132
|
+
controller.abort();
|
|
133
|
+
reject(Error("Outbox delivery timed out"));
|
|
134
|
+
}, options.timeoutMs ?? 5000);
|
|
135
|
+
})
|
|
136
|
+
]);
|
|
137
|
+
if (ack !== row.id)
|
|
138
|
+
throw Error("Unacknowledged telemetry");
|
|
139
|
+
await lock(async () => {
|
|
140
|
+
await options.store.remove(row.id);
|
|
141
|
+
await prune();
|
|
142
|
+
});
|
|
143
|
+
stats.acknowledged++;
|
|
144
|
+
failures = 0;
|
|
145
|
+
nextAttempt = 0;
|
|
146
|
+
} catch {
|
|
147
|
+
stats.failedAttempts++;
|
|
148
|
+
failures++;
|
|
149
|
+
nextAttempt = now() + Math.min(60000, 1000 * 2 ** Math.min(failures - 1, 6)) * (0.75 + random() * 0.5);
|
|
150
|
+
break;
|
|
151
|
+
} finally {
|
|
152
|
+
if (timer)
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
})().finally(() => {
|
|
157
|
+
flushing = null;
|
|
158
|
+
});
|
|
159
|
+
return flushing;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
createIndexedDBOutboxStore,
|
|
165
|
+
createMemoryOutboxStore,
|
|
166
|
+
createOutbox
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
//# debugId=D474205395F6C58E64756E2164756E21
|
|
170
|
+
//# sourceMappingURL=outbox.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/outbox.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/** Durable, bounded delivery for JSON telemetry. Call enqueue only with redacted data.\n * Server must deduplicate by id and acknowledge that id after committing storage.\n * Browser persistence is best effort: unavailable/quota-exhausted storage is reported.\n */\nexport type OutboxRecord = {\n id: string;\n createdAt: number;\n body: string;\n bytes: number;\n};\nexport interface OutboxStore {\n list(): Promise<OutboxRecord[]>;\n put(record: OutboxRecord): Promise<void>;\n remove(id: string): Promise<void>;\n}\nexport function createIndexedDBOutboxStore(\n name = \"absolute-beacon-outbox\",\n): OutboxStore {\n let opening: Promise<IDBDatabase> | undefined;\n const open = () =>\n (opening ??= new Promise((resolve, reject) => {\n const request = indexedDB.open(name, 1);\n request.onupgradeneeded = () =>\n request.result.createObjectStore(\"pending\", { keyPath: \"id\" });\n request.onerror = () => {\n opening = undefined;\n reject(request.error);\n };\n request.onblocked = () => {\n opening = undefined;\n reject(Error(\"Outbox database blocked\"));\n };\n request.onsuccess = () => {\n request.result.onversionchange = () => {\n request.result.close();\n opening = undefined;\n };\n resolve(request.result);\n };\n }));\n const transact = async <T>(\n mode: IDBTransactionMode,\n action: (s: IDBObjectStore) => IDBRequest<T>,\n ): Promise<T> => {\n const db = await open();\n return new Promise((resolve, reject) => {\n const tx = db.transaction(\"pending\", mode),\n request = action(tx.objectStore(\"pending\"));\n tx.oncomplete = () => resolve(request.result);\n tx.onabort = tx.onerror = () =>\n reject(tx.error ?? request.error ?? Error(\"Outbox storage failed\"));\n });\n };\n return {\n list: () => transact(\"readonly\", (s) => s.getAll()),\n put: async (r) => {\n await transact(\"readwrite\", (s) => s.put(r));\n },\n remove: async (id) => {\n await transact(\"readwrite\", (s) => s.delete(id));\n },\n };\n}\nexport function createMemoryOutboxStore(): OutboxStore {\n const records = new Map<string, OutboxRecord>();\n return {\n list: async () => [...records.values()],\n put: async (r) => {\n records.set(r.id, r);\n },\n remove: async (id) => {\n records.delete(id);\n },\n };\n}\nexport function createOutbox(options: {\n store: OutboxStore;\n send: (record: OutboxRecord, signal: AbortSignal) => Promise<string>;\n now?: () => number;\n random?: () => number;\n maxItems?: number;\n maxBytes?: number;\n maxRecordBytes?: number;\n maxAgeMs?: number;\n timeoutMs?: number;\n}) {\n const now = options.now ?? Date.now,\n random = options.random ?? Math.random;\n const maxItems = options.maxItems ?? 128,\n maxBytes = options.maxBytes ?? 4_000_000,\n maxRecordBytes = options.maxRecordBytes ?? 1_000_000,\n maxAge = options.maxAgeMs ?? 172800000;\n let sequence = Promise.resolve(),\n flushing: Promise<void> | null = null,\n nextAttempt = 0,\n failures = 0;\n const stats = {\n pending: 0,\n bytes: 0,\n dropped: 0,\n expired: 0,\n storageErrors: 0,\n failedAttempts: 0,\n acknowledged: 0,\n persistMs: 0,\n };\n const lock = <T>(fn: () => Promise<T>): Promise<T> => {\n const result = sequence.then(fn);\n sequence = result.then(\n () => {},\n () => {},\n );\n return result;\n };\n const prune = async () => {\n let rows = (await options.store.list()).sort(\n (a, b) => a.createdAt - b.createdAt || a.id.localeCompare(b.id),\n );\n for (const row of rows)\n if (now() - row.createdAt > maxAge) {\n await options.store.remove(row.id);\n stats.expired++;\n }\n rows = rows.filter((r) => now() - r.createdAt <= maxAge);\n let bytes = rows.reduce((n, r) => n + r.bytes, 0);\n while (rows.length > maxItems || bytes > maxBytes) {\n const row = rows.shift()!;\n await options.store.remove(row.id);\n bytes -= row.bytes;\n stats.dropped++;\n }\n stats.pending = rows.length;\n stats.bytes = bytes;\n return rows;\n };\n return {\n stats: () => ({ ...stats, nextAttempt }),\n enqueue(value: unknown, id: string = crypto.randomUUID()): Promise<string> {\n const body = JSON.stringify(value),\n bytes = new TextEncoder().encode(body).byteLength;\n if (bytes > maxRecordBytes || bytes > maxBytes)\n return Promise.reject(Error(\"Telemetry record exceeds outbox limit\"));\n return lock(async () => {\n const started = performance.now();\n try {\n await options.store.put({ id, createdAt: now(), body, bytes });\n await prune();\n return id;\n } catch (error) {\n stats.storageErrors++;\n throw error;\n } finally {\n stats.persistMs += performance.now() - started;\n }\n });\n },\n flush(): Promise<void> {\n if (flushing) return flushing;\n if (now() < nextAttempt) return Promise.resolve();\n flushing = (async () => {\n let rows: OutboxRecord[];\n try {\n rows = await lock(prune);\n } catch {\n stats.storageErrors++;\n return;\n }\n // Bounded snapshot: newly enqueued records wait until the next flush.\n for (const row of rows) {\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n const ack = await Promise.race([\n options.send(row, controller.signal),\n new Promise<never>((_, reject) => {\n timer = setTimeout(() => {\n controller.abort();\n reject(Error(\"Outbox delivery timed out\"));\n }, options.timeoutMs ?? 5000);\n }),\n ]);\n if (ack !== row.id) throw Error(\"Unacknowledged telemetry\");\n await lock(async () => {\n await options.store.remove(row.id);\n await prune();\n });\n stats.acknowledged++;\n failures = 0;\n nextAttempt = 0;\n } catch {\n stats.failedAttempts++;\n failures++;\n nextAttempt =\n now() +\n Math.min(60000, 1000 * 2 ** Math.min(failures - 1, 6)) *\n (0.75 + random() * 0.5);\n break;\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n })().finally(() => {\n flushing = null;\n });\n return flushing;\n },\n };\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAeO,SAAS,0BAA0B,CACxC,OAAO,0BACM;AAAA,EACb,IAAI;AAAA,EACJ,MAAM,OAAO,MACV,YAAY,IAAI,QAAQ,CAAC,SAAS,WAAW;AAAA,IAC5C,MAAM,UAAU,UAAU,KAAK,MAAM,CAAC;AAAA,IACtC,QAAQ,kBAAkB,MACxB,QAAQ,OAAO,kBAAkB,WAAW,EAAE,SAAS,KAAK,CAAC;AAAA,IAC/D,QAAQ,UAA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I;AAAA,YACF,MAAM,MAAM,MAAM,QAAQ,KAAK;AAAA,cAC7B,QAAQ,KAAK,KAAK,WAAW,MAAM;AAAA,cACnC,IAAI,QAAe,CAAC,GAAG,WAAW;AAAA,gBAChC,QAAQ,WAAW,MAAM;AAAA,kBACvB,WAAW,MAAM;AAAA,kBACjB,OAAO,MAAM,2BAA2B,CAAC;AAAA,mBACxC,QAAQ,aAAa,IAAI;AAAA,eAC7B;AAAA,YACH,CAAC;AAAA,YACD,IAAI,QAAQ,IAAI;AAAA,cAAI,MAAM,MAAM,0BAA0B;AAAA,YAC1D,MAAM,KAAK,YAAY;AAAA,cACrB,MAAM,QAAQ,MAAM,OAAO,IAAI,EAAE;AAAA,cACjC,MAAM,MAAM;AAAA,aACb;AAAA,YACD,MAAM;AAAA,YACN,WAAW;AAAA,YACX,cAAc;AAAA,YACd,MAAM;AAAA,YACN,MAAM;AAAA,YACN;AAAA,YACA,cACE,IAAI,IACJ,KAAK,IAAI,OAAO,OAAO,KAAK,KAAK,IAAI,WAAW,GAAG,CAAC,CAAC,KAClD,OAAO,OAAO,IAAI;AAAA,YACvB;AAAA,oBACA;AAAA,YACA,IAAI;AAAA,cAAO,aAAa,KAAK;AAAA;AAAA,QAEjC;AAAA,SACC,EAAE,QAAQ,MAAM;AAAA,QACjB,WAAW;AAAA,OACZ;AAAA,MACD,OAAO;AAAA;AAAA,EAEX;AAAA;",
|
|
8
|
+
"debugId": "D474205395F6C58E64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/policy.d.ts
CHANGED
|
@@ -95,6 +95,13 @@ export declare const isStaleReleaseSignal: (event: Pick<BeaconEvent, "tags">) =>
|
|
|
95
95
|
* error that would churn the board on every deploy, once per open tab.
|
|
96
96
|
*/
|
|
97
97
|
export declare const isStaleChunkImport: (event: Pick<BeaconEvent, "message">) => boolean;
|
|
98
|
+
/**
|
|
99
|
+
* A browser hides an error thrown by a script from another origin (an
|
|
100
|
+
* extension, an ad or analytics tag, a CDN script without CORS) behind a bare
|
|
101
|
+
* "Script error." with no message, file or stack. Nothing in it can be acted
|
|
102
|
+
* on or even attributed to the application.
|
|
103
|
+
*/
|
|
104
|
+
export declare const isOpaqueScriptError: (event: Pick<BeaconEvent, "message" | "stack">) => boolean;
|
|
98
105
|
/**
|
|
99
106
|
* A hydration mismatch caused by a page-recolouring extension.
|
|
100
107
|
*
|
|
@@ -141,6 +148,8 @@ export type NoisePolicyOptions = {
|
|
|
141
148
|
ignoreStaleChunkImports?: boolean;
|
|
142
149
|
/** Suppress hydration mismatches written by theme extensions. Default true. */
|
|
143
150
|
ignoreThemeExtensionHydration?: boolean;
|
|
151
|
+
/** Suppress cross-origin "Script error." with no stack. Default true. */
|
|
152
|
+
ignoreOpaqueScriptErrors?: boolean;
|
|
144
153
|
/** Application-specific rules, run after the built-in ones. */
|
|
145
154
|
rules?: readonly ((event: BeaconEvent) => boolean)[];
|
|
146
155
|
};
|
package/dist/policy.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
1
|
// src/contracts.ts
|
|
10
2
|
var BEACON_SIGNAL = {
|
|
11
3
|
AUTH_FAILURE_STORM: "auth_failure_storm",
|
|
@@ -18,6 +10,7 @@ var BEACON_SIGNAL = {
|
|
|
18
10
|
CONTROL_COLLISION: "control_collision",
|
|
19
11
|
CSP_VIOLATION: "csp_violation",
|
|
20
12
|
CLIPBOARD_FAILURE: "clipboard_failure",
|
|
13
|
+
COLLAPSED_MODAL: "collapsed_modal",
|
|
21
14
|
DEAD_CLICK: "dead_click",
|
|
22
15
|
DISRUPTIVE_LAYOUT_SHIFT: "disruptive_layout_shift",
|
|
23
16
|
DOCUMENT_DISCARDED: "document_discarded",
|
|
@@ -114,6 +107,9 @@ var isServerCapturedHttpFailure = (event, probeEndpoints = []) => {
|
|
|
114
107
|
var isStaleReleaseSignal = (event) => event.tags?.signal === BEACON_SIGNAL.STALE_RELEASE;
|
|
115
108
|
var STALE_CHUNK_IMPORT = /failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed/iu;
|
|
116
109
|
var isStaleChunkImport = (event) => STALE_CHUNK_IMPORT.test(event.message);
|
|
110
|
+
var OPAQUE_SCRIPT_ERROR = /^script error\.?$/iu;
|
|
111
|
+
var isOpaqueScriptError = (event) => OPAQUE_SCRIPT_ERROR.test(event.message.trim()) && !(event.stack ?? "").split(`
|
|
112
|
+
`).slice(1).some((line) => line.trim() !== "");
|
|
117
113
|
var THEME_EXTENSION_INLINE_STYLE = /--(?:darkreader|noir)-inline-/u;
|
|
118
114
|
var breadcrumbMessage = (breadcrumb) => {
|
|
119
115
|
if (breadcrumb === null || typeof breadcrumb !== "object")
|
|
@@ -134,6 +130,7 @@ var createNoisePolicy = (options = {}) => {
|
|
|
134
130
|
exemptions = [],
|
|
135
131
|
externalDeprecations = [ATTRIBUTION_REPORTING_DEPRECATION],
|
|
136
132
|
ignoreHiddenReadFailures = true,
|
|
133
|
+
ignoreOpaqueScriptErrors = true,
|
|
137
134
|
ignoreServerCapturedFailures = true,
|
|
138
135
|
ignoreStaleChunkImports = true,
|
|
139
136
|
ignoreThemeExtensionHydration = true,
|
|
@@ -141,7 +138,7 @@ var createNoisePolicy = (options = {}) => {
|
|
|
141
138
|
probeEndpoints = [],
|
|
142
139
|
rules = []
|
|
143
140
|
} = options;
|
|
144
|
-
return (event) => ownsReleaseUpdates && isStaleReleaseSignal(event) || ignoreStaleChunkImports && isStaleChunkImport(event) || ignoreThemeExtensionHydration && isThemeExtensionHydrationNoise(event) || ignoreHiddenReadFailures && isHiddenReadFailure(event) || ignoreServerCapturedFailures && isServerCapturedHttpFailure(event, probeEndpoints) || externalDeprecations.length > 0 && isExternalBrowserDeprecation(event, externalDeprecations) || exemptions.some((exemption) => matchesEndpointExemption(event, exemption)) || rules.some((rule) => rule(event));
|
|
141
|
+
return (event) => ownsReleaseUpdates && isStaleReleaseSignal(event) || ignoreStaleChunkImports && isStaleChunkImport(event) || ignoreThemeExtensionHydration && isThemeExtensionHydrationNoise(event) || ignoreOpaqueScriptErrors && isOpaqueScriptError(event) || ignoreHiddenReadFailures && isHiddenReadFailure(event) || ignoreServerCapturedFailures && isServerCapturedHttpFailure(event, probeEndpoints) || externalDeprecations.length > 0 && isExternalBrowserDeprecation(event, externalDeprecations) || exemptions.some((exemption) => matchesEndpointExemption(event, exemption)) || rules.some((rule) => rule(event));
|
|
145
142
|
};
|
|
146
143
|
var hostMatches = (hostname, pattern) => hostname === pattern || hostname.endsWith(`.${pattern}`);
|
|
147
144
|
var parseFailureUrl = (url) => {
|
|
@@ -212,6 +209,7 @@ export {
|
|
|
212
209
|
eventEndpoints,
|
|
213
210
|
isExternalBrowserDeprecation,
|
|
214
211
|
isHiddenReadFailure,
|
|
212
|
+
isOpaqueScriptError,
|
|
215
213
|
isServerCapturedHttpFailure,
|
|
216
214
|
isStaleChunkImport,
|
|
217
215
|
isStaleReleaseSignal,
|
|
@@ -220,5 +218,5 @@ export {
|
|
|
220
218
|
reliabilitySignalPreset
|
|
221
219
|
};
|
|
222
220
|
|
|
223
|
-
//# debugId=
|
|
221
|
+
//# debugId=508EFF44D0F80FED64756E2164756E21
|
|
224
222
|
//# sourceMappingURL=policy.js.map
|
package/dist/policy.js.map
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/contracts.ts", "../src/policy.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/** Stable names for Beacon's built-in UX and health signals. */\nexport const BEACON_SIGNAL = {\n AUTH_FAILURE_STORM: \"auth_failure_storm\",\n BROWSER_INTERVENTION: \"browser_intervention\",\n BROWSER_POLICY_VIOLATION: \"browser_policy_violation\",\n BFCACHE_BLOCKED: \"bfcache_blocked\",\n CAPABILITY_FAILURE: \"capability_failure\",\n BLANK_APP_ROOT: \"blank_app_root\",\n CONSOLE_ERROR: \"console_error\",\n CONTROL_COLLISION: \"control_collision\",\n CSP_VIOLATION: \"csp_violation\",\n CLIPBOARD_FAILURE: \"clipboard_failure\",\n DEAD_CLICK: \"dead_click\",\n DISRUPTIVE_LAYOUT_SHIFT: \"disruptive_layout_shift\",\n DOCUMENT_DISCARDED: \"document_discarded\",\n ERROR_CLICK: \"error_click\",\n FETCH_FAILED: \"fetch_failed\",\n FOCUS_LOST: \"focus_lost\",\n FONT_FAILURE: \"font_failure\",\n FORM_FRUSTRATION: \"form_frustration\",\n FORM_ABANDONMENT: \"form_abandonment\",\n FOCUSED_CONTROL_OFFSCREEN: \"focused_control_offscreen\",\n HTTP_5XX: \"http_5xx\",\n HTTP_RESPONSE_FAILURE: \"http_response_failure\",\n INVISIBLE_TEXT: \"invisible_text\",\n EMBEDDED_CONTENT_STALLED: \"embedded_content_stalled\",\n LAYOUT_OVERFLOW: \"layout_overflow\",\n MAIN_THREAD_STALL: \"main_thread_stall\",\n MEDIA_PLAYBACK_FAILED: \"media_playback_failed\",\n MEDIA_PLAYBACK_STALLED: \"media_playback_stalled\",\n MODAL_FOCUS_ESCAPE: \"modal_focus_escape\",\n OCCLUDED_CONTROL: \"occluded_control\",\n RAGE_CLICK: \"rage_click\",\n RATE_LIMITED: \"rate_limited\",\n NAVIGATION_STALLED: \"navigation_stalled\",\n RELOAD_LOOP: \"reload_loop\",\n REQUEST_STORM: \"request_storm\",\n SEMANTIC_RESPONSE_FAILURE: \"semantic_response_failure\",\n SCROLL_JAIL: \"scroll_jail\",\n SLOW_RESPONSE: \"slow_response\",\n SLOW_RESOURCE: \"slow_resource\",\n SLOW_INTERACTION: \"slow_interaction\",\n SOCKET_ABNORMAL_CLOSE: \"socket_abnormal_close\",\n SOCKET_FLAPPING: \"socket_flapping\",\n SSE_FLAPPING: \"sse_flapping\",\n STALE_RELEASE: \"stale_release\",\n STALLED_STREAM: \"stalled_stream\",\n STUCK_LOADING: \"stuck_loading\",\n THEME_MISMATCH: \"theme_mismatch\",\n THRASHED_CURSOR: \"thrashed_cursor\",\n STORAGE_FAILURE: \"storage_failure\",\n WEBGL_CONTEXT_LOST: \"webgl_context_lost\",\n SERVICE_WORKER_FAILURE: \"service_worker_failure\",\n WORKER_FAILURE: \"worker_failure\",\n} as const;\n\nexport type BeaconSignal = (typeof BEACON_SIGNAL)[keyof typeof BEACON_SIGNAL];\n\n/** Stable DOM attributes understood by Beacon's instrumentation. */\nexport const BEACON_ATTRIBUTE = {\n APP_ROOT: \"data-beacon-app-root\",\n CONTROL_GROUP: \"data-beacon-control-group\",\n DEAD_CLICK: \"data-beacon-dead-click\",\n NAME: \"data-beacon-name\",\n EMBED: \"data-beacon-embed\",\n LOADING: \"data-beacon-loading\",\n LOADING_TIMEOUT: \"data-beacon-loading-timeout\",\n FORM: \"data-beacon-form\",\n /** `=\"allow\"` exempts an intentional dynamic subtree from layout-shift issues. */\n LAYOUT_SHIFT: \"data-beacon-layout-shift\",\n MEDIA: \"data-beacon-media\",\n OVERFLOW: \"data-beacon-overflow\",\n SCAN: \"data-beacon-scan\",\n THEME: \"data-beacon-theme\",\n} as const;\n",
|
|
6
|
-
"/**\n * Noise policy — which captured signals are real, and which are known-fine.\n *\n * An issue board is only worth opening if everything on it is real. A board\n * that files an application's own SSE stream as a stalled request every shift\n * gets ignored, and the actual breakage gets ignored along with it. So every\n * application that ships Beacon ends up writing the same `beforeSend` filter:\n * a list of named, explained exclusions. In practice most of that list is not\n * application-specific at all — a stale chunk import after a deploy, a theme\n * extension rewriting inline styles before hydration, a read that failed while\n * the tab was hidden, a 5xx the server already captured with a stack. What\n * differs between applications is a handful of endpoints and hostnames.\n *\n * This module is that list, with the endpoints as configuration.\n *\n * It is a separate entry point on purpose, and it imports nothing from the SDK\n * at runtime. Boot-time policy is read by the synchronous page graph; pulling\n * Beacon's runtime constants into that graph makes the bundler merge the whole\n * monitoring SDK back into it, defeating lazy startup. Everything here is\n * plain data and pure functions, and the only imports are types, which erase.\n */\nimport { BEACON_ATTRIBUTE, BEACON_SIGNAL } from \"./contracts\";\nimport type {\n BeaconEvent,\n BeaconResourceFailure,\n BeaconSignals,\n} from \"./index\";\n\n/** Re-exported so a page can read boot-time policy from one import. Both live\n * in `./contracts`, which pulls in nothing else. */\nexport { BEACON_ATTRIBUTE, BEACON_SIGNAL };\n\n/** A batched request event covers several endpoints at once, and Beacon marks\n * the method `multiple` when they did not share one. */\nconst BATCHED_METHOD = \"multiple\";\n\n/**\n * One endpoint exemption: a signal raised against a set of endpoints that are\n * known to produce it in normal operation.\n *\n * This is the shape nearly every application-specific rule turns out to have —\n * a stream that stays open for hours, an upload that is megabytes by design, a\n * marketing pixel that fails when a blocker is installed, a request whose\n * client already owns its retry. Naming it once means those rules become four\n * lines of configuration instead of four hand-written predicates.\n */\nexport type EndpointExemption = {\n /** Signals this exemption applies to. */\n signals: readonly string[];\n /** Endpoints it covers. A string matches as a substring unless `match` says\n * otherwise; a RegExp is tested against the endpoint. */\n endpoints: readonly (RegExp | string)[];\n /** Restrict to specific request methods. Omit to cover every method. A\n * batched event (method `multiple`) matches whenever its endpoints do. */\n methods?: readonly string[];\n /** How string patterns are compared. Default `includes`. */\n match?: \"exact\" | \"includes\" | \"prefix\";\n};\n\n/**\n * Read the endpoints off an event.\n *\n * Beacon reports a single request on `endpoint` and a batch on `endpoints` as a\n * comma-separated list. Every application that writes one of these rules writes\n * this parser first, usually more than once.\n */\nexport const eventEndpoints = (tags: BeaconEvent[\"tags\"]): string[] => {\n const batched = tags?.endpoints\n ?.split(\",\")\n .map((endpoint) => endpoint.trim())\n .filter(Boolean);\n if (batched !== undefined && batched.length > 0) return batched;\n\n return tags?.endpoint ? [tags.endpoint] : [];\n};\n\nconst endpointMatches = (\n endpoint: string,\n pattern: RegExp | string,\n match: EndpointExemption[\"match\"],\n): boolean => {\n if (typeof pattern !== \"string\") return pattern.test(endpoint);\n if (match === \"exact\") return endpoint === pattern;\n if (match === \"prefix\") return endpoint.startsWith(pattern);\n\n return endpoint.includes(pattern);\n};\n\n/**\n * Whether an event is fully covered by an exemption.\n *\n * Every endpoint has to match, not just one: a batch that mixes the exempt\n * stream with a real request is a real request, and suppressing it would hide\n * the failure behind the stream that happened to travel with it.\n */\nexport const matchesEndpointExemption = (\n event: Pick<BeaconEvent, \"tags\">,\n exemption: EndpointExemption,\n): boolean => {\n const signal = event.tags?.signal;\n if (signal === undefined || !exemption.signals.includes(signal)) return false;\n const method = event.tags?.method;\n if (\n exemption.methods !== undefined &&\n method !== undefined &&\n method !== BATCHED_METHOD &&\n !exemption.methods.includes(method)\n )\n return false;\n const endpoints = eventEndpoints(event.tags);\n\n return (\n endpoints.length > 0 &&\n endpoints.every((endpoint) =>\n exemption.endpoints.some((pattern) =>\n endpointMatches(endpoint, pattern, exemption.match),\n ),\n )\n );\n};\n\n/**\n * A read that failed while the tab was hidden.\n *\n * A backgrounded tab losing a request is browser lifecycle, not breakage —\n * suspension, a dropped connection, a VPN moving. Applications refetch on\n * focus. Visible failures, writes and timeouts all stay actionable.\n */\nexport const isHiddenReadFailure = (\n event: Pick<BeaconEvent, \"tags\">,\n): boolean =>\n event.tags?.signal === BEACON_SIGNAL.FETCH_FAILED &&\n event.tags.method === \"GET\" &&\n event.tags.visibilityState === \"hidden\" &&\n (event.tags.failureKind === \"offline\" ||\n event.tags.failureKind === \"transport\");\n\n/**\n * A 5xx the server already captured.\n *\n * The trace id means a server-side capture exists with the stack, the request\n * and the context. The browser's view of the same failure would open a second\n * issue for one fault, with less in it.\n */\nexport const isServerCapturedHttpFailure = (\n event: Pick<BeaconEvent, \"tags\" | \"traceId\">,\n probeEndpoints: readonly string[] = [],\n): boolean => {\n if (\n event.tags?.signal !== BEACON_SIGNAL.HTTP_5XX ||\n event.traceId === undefined\n )\n return false;\n const endpoint = event.tags.endpoint;\n\n // Cross-origin endpoints have no server-side capture to defer to, and a\n // failing health probe is the one 5xx worth hearing from the browser: it is\n // how an application finds out its own server stopped answering.\n return (\n endpoint?.startsWith(\"/\") === true && !probeEndpoints.includes(endpoint)\n );\n};\n\n/**\n * The page is running an older release than this browser has already seen.\n *\n * Applications that prompt for their own updates — a service worker with an\n * update path, a release probe with an `onStale` reload — already tell the\n * person what to do. Reporting it as an issue too is a second voice saying the\n * same thing to someone who cannot act on it.\n */\nexport const isStaleReleaseSignal = (\n event: Pick<BeaconEvent, \"tags\">,\n): boolean => event.tags?.signal === BEACON_SIGNAL.STALE_RELEASE;\n\nconst STALE_CHUNK_IMPORT =\n /failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed/iu;\n\n/**\n * A dynamic import for a chunk the deploy replaced.\n *\n * The document was served before the release and asks for a file the release\n * renamed. The update path already recovers it, so what is left is a console\n * error that would churn the board on every deploy, once per open tab.\n */\nexport const isStaleChunkImport = (\n event: Pick<BeaconEvent, \"message\">,\n): boolean => STALE_CHUNK_IMPORT.test(event.message);\n\nconst THEME_EXTENSION_INLINE_STYLE = /--(?:darkreader|noir)-inline-/u;\n\nconst breadcrumbMessage = (breadcrumb: unknown): string | undefined => {\n if (breadcrumb === null || typeof breadcrumb !== \"object\") return undefined;\n const message = Reflect.get(breadcrumb, \"message\");\n\n return typeof message === \"string\" ? message : undefined;\n};\n\n/**\n * A hydration mismatch caused by a page-recolouring extension.\n *\n * Dark Reader and its kind rewrite inline styles before the framework hydrates,\n * and the framework correctly reports that the markup it found is not the\n * markup it rendered. The edit is the extension's, made in a browser the\n * application will never see, and no change to the application removes it.\n */\nexport const isThemeExtensionHydrationNoise = (\n event: Pick<BeaconEvent, \"extra\" | \"message\">,\n): boolean => {\n if (event.message !== \"Hydration completed but contains mismatches.\")\n return false;\n const breadcrumbs = event.extra?.breadcrumbs;\n\n return (\n Array.isArray(breadcrumbs) &&\n breadcrumbs.some((breadcrumb) =>\n THEME_EXTENSION_INLINE_STYLE.test(breadcrumbMessage(breadcrumb) ?? \"\"),\n )\n );\n};\n\n/**\n * A browser deprecation report for something the page does not control.\n *\n * A third-party tag's own deprecation is attributed to the document that hosts\n * it. Naming the report identities that are known to come from outside keeps\n * the ones from application code actionable.\n */\nexport const isExternalBrowserDeprecation = (\n event: Pick<BeaconEvent, \"tags\">,\n reportIdentities: readonly string[],\n): boolean =>\n event.tags?.signal === BEACON_SIGNAL.BROWSER_POLICY_VIOLATION &&\n event.tags.reportType === \"deprecation\" &&\n reportIdentities.includes(event.tags.policyId ?? \"\");\n\n/** Google's Attribution Reporting deprecation, emitted by the ads and\n * analytics tags rather than by the page that embeds them. */\nexport const ATTRIBUTION_REPORTING_DEPRECATION = \"AttributionReporting\";\n\nexport type NoisePolicyOptions = {\n /**\n * Endpoints that are known to raise a signal in normal operation: streams\n * that stay open, uploads that are large by design, pixels that a blocker\n * refuses, requests whose client owns its own retry.\n */\n exemptions?: readonly EndpointExemption[];\n /**\n * Health/readiness endpoints. A 5xx from one of these still reports even\n * when a trace id says the server captured it, because a server that has\n * stopped answering cannot be relied on to file its own issue.\n */\n probeEndpoints?: readonly string[];\n /** Browser report identities known to originate outside the page. Defaults\n * to Attribution Reporting; pass `[]` to keep every deprecation. */\n externalDeprecations?: readonly string[];\n /** The application prompts for its own updates. Default true. */\n ownsReleaseUpdates?: boolean;\n /** Suppress hidden-tab read failures. Default true. */\n ignoreHiddenReadFailures?: boolean;\n /** Suppress 5xx the server already captured. Default true. */\n ignoreServerCapturedFailures?: boolean;\n /** Suppress dynamic imports for chunks a deploy replaced. Default true. */\n ignoreStaleChunkImports?: boolean;\n /** Suppress hydration mismatches written by theme extensions. Default true. */\n ignoreThemeExtensionHydration?: boolean;\n /** Application-specific rules, run after the built-in ones. */\n rules?: readonly ((event: BeaconEvent) => boolean)[];\n};\n\n/**\n * Build the `beforeSend` predicate.\n *\n * Returns true for an event that should be dropped, so a caller reads as\n * `beforeSend: (event) => (isNoise(event) ? null : event)`.\n */\nexport const createNoisePolicy = (options: NoisePolicyOptions = {}) => {\n const {\n exemptions = [],\n externalDeprecations = [ATTRIBUTION_REPORTING_DEPRECATION],\n ignoreHiddenReadFailures = true,\n ignoreServerCapturedFailures = true,\n ignoreStaleChunkImports = true,\n ignoreThemeExtensionHydration = true,\n ownsReleaseUpdates = true,\n probeEndpoints = [],\n rules = [],\n } = options;\n\n return (event: BeaconEvent): boolean =>\n (ownsReleaseUpdates && isStaleReleaseSignal(event)) ||\n (ignoreStaleChunkImports && isStaleChunkImport(event)) ||\n (ignoreThemeExtensionHydration && isThemeExtensionHydrationNoise(event)) ||\n (ignoreHiddenReadFailures && isHiddenReadFailure(event)) ||\n (ignoreServerCapturedFailures &&\n isServerCapturedHttpFailure(event, probeEndpoints)) ||\n (externalDeprecations.length > 0 &&\n isExternalBrowserDeprecation(event, externalDeprecations)) ||\n exemptions.some((exemption) =>\n matchesEndpointExemption(event, exemption),\n ) ||\n rules.some((rule) => rule(event));\n};\n\nexport type ResourceFailurePolicyOptions = {\n /** Hostnames whose scripts are not the application's to fix. A pattern\n * matches the hostname itself or any subdomain of it. */\n thirdPartyHosts?: readonly string[];\n /** Cross-origin images are optional by default: the elements that show them\n * render a placeholder, and the remote host is not the application's to\n * fix. Set false to treat a missing remote image as an error. */\n optionalCrossOriginImages?: boolean;\n /** Same-origin path prefixes serving optional imagery — an avatar, a logo\n * proxy, an uploaded thumbnail — where a placeholder already stands in. */\n optionalPathPrefixes?: readonly string[];\n};\n\nconst hostMatches = (hostname: string, pattern: string): boolean =>\n hostname === pattern || hostname.endsWith(`.${pattern}`);\n\n/**\n * Split a failed resource's URL into the two parts these rules ask about.\n *\n * An absolute URL carries its own host and needs no base. A relative one is\n * same-origin by construction, and its path is the characters before any query\n * — which is worth extracting directly, because the contexts this runs in do\n * not all have a resolvable `location`: a worker, a server render, or a test\n * DOM parked on `about:blank`. Falling back to \"unparseable\" there would\n * quietly disable the path rules in exactly the places hardest to notice.\n */\nconst parseFailureUrl = (\n url: string,\n): { hostname: string; pathname: string } | undefined => {\n try {\n return new URL(url);\n } catch {\n // Relative; fall through.\n }\n const base = typeof location === \"undefined\" ? undefined : location.href;\n if (base !== undefined)\n try {\n return new URL(url, base);\n } catch {\n // Unusable base; fall through to the path-only reading.\n }\n\n return url.startsWith(\"/\")\n ? { hostname: \"\", pathname: url.split(/[?#]/u)[0] ?? url }\n : undefined;\n};\n\n/**\n * Which failed resources are errors.\n *\n * A third-party analytics script blocked by an extension and a customer's\n * uploaded thumbnail 404ing are not the application being broken — the first is\n * not the application's code to fix, and the second already renders a\n * placeholder. Its own scripts, styles and images still are.\n *\n * Returns Beacon's `resourceErrors` classifier: a level to report at, or false\n * to ignore.\n */\nexport const createResourceFailurePolicy = (\n options: ResourceFailurePolicyOptions = {},\n) => {\n const {\n optionalCrossOriginImages = true,\n optionalPathPrefixes = [],\n thirdPartyHosts = [],\n } = options;\n\n return (failure: BeaconResourceFailure): \"error\" | false => {\n if (failure.url === undefined) return \"error\";\n // An unreadable URL is not evidence that the resource was optional, so it\n // reports rather than disappearing.\n const parsed = parseFailureUrl(failure.url);\n if (parsed === undefined) return \"error\";\n if (\n failure.type === \"script\" &&\n thirdPartyHosts.some((host) => hostMatches(parsed.hostname, host))\n )\n return false;\n if (failure.type !== \"img\") return \"error\";\n if (optionalCrossOriginImages && failure.crossOrigin) return false;\n\n return optionalPathPrefixes.some((prefix) =>\n parsed.pathname.startsWith(prefix),\n )\n ? false\n : \"error\";\n };\n};\n\nexport type ReliabilityPresetOptions = {\n /**\n * Behavioural detectors watch a person rather than a page — what they\n * clicked, where they got stuck — so they belong on the same consent\n * boundary as session replay. Structural health stays on for everyone.\n */\n behavioural?: boolean;\n /** A `report-to` endpoint already delivers browser policy reports, so the\n * parallel observer would file each deprecation twice. Default true. */\n hasReportingEndpoint?: boolean;\n /** A Performance console owns ordinary latency, so error triage keeps only\n * failures. Default true. */\n ownsLatencyElsewhere?: boolean;\n /** The application prompts for its own updates. Default true. */\n ownsReleaseUpdates?: boolean;\n /** Documents are restored from server state on boot, so a browser evicting\n * a tab to reclaim memory is not a fault. Default true. */\n restoresFromServerState?: boolean;\n /** Endpoints whose client owns reconnect and resume. */\n recoverableSockets?: Array<RegExp | string>;\n /** bfcache blockers inherent to a capability the application requires. */\n ignoredBfcacheReasons?: string[];\n};\n\n/**\n * The signal set an application with its own error triage usually wants.\n *\n * Beacon enables every detector by default, which is right for an application\n * that has nothing else. One that also runs a Performance console, a release\n * probe and a Reporting API endpoint has to turn the same four off, for the\n * same reasons, every time — otherwise each of those systems files the issue\n * its neighbour already filed. Everything not named here keeps its default.\n */\nexport const reliabilitySignalPreset = (\n options: ReliabilityPresetOptions = {},\n): BeaconSignals => {\n const {\n behavioural = false,\n hasReportingEndpoint = true,\n ignoredBfcacheReasons,\n ownsLatencyElsewhere = true,\n ownsReleaseUpdates = true,\n recoverableSockets,\n restoresFromServerState = true,\n } = options;\n\n return {\n browserPolicyViolations: !hasReportingEndpoint,\n deadClicks: behavioural,\n documentDiscards: !restoresFromServerState,\n errorClicks: behavioural,\n formAbandonment: behavioural,\n formFrustration: behavioural,\n ...(ignoredBfcacheReasons ? { ignoredBfcacheReasons } : {}),\n rageClicks: behavioural,\n ...(recoverableSockets ? { recoverableSockets } : {}),\n scrollJail: behavioural,\n slowInteractions: !ownsLatencyElsewhere,\n slowResponses: !ownsLatencyElsewhere,\n staleReleases: !ownsReleaseUpdates,\n thrashedCursors: behavioural,\n };\n};\n"
|
|
5
|
+
"/** Stable names for Beacon's built-in UX and health signals. */\nexport const BEACON_SIGNAL = {\n AUTH_FAILURE_STORM: \"auth_failure_storm\",\n BROWSER_INTERVENTION: \"browser_intervention\",\n BROWSER_POLICY_VIOLATION: \"browser_policy_violation\",\n BFCACHE_BLOCKED: \"bfcache_blocked\",\n CAPABILITY_FAILURE: \"capability_failure\",\n BLANK_APP_ROOT: \"blank_app_root\",\n CONSOLE_ERROR: \"console_error\",\n CONTROL_COLLISION: \"control_collision\",\n CSP_VIOLATION: \"csp_violation\",\n CLIPBOARD_FAILURE: \"clipboard_failure\",\n COLLAPSED_MODAL: \"collapsed_modal\",\n DEAD_CLICK: \"dead_click\",\n DISRUPTIVE_LAYOUT_SHIFT: \"disruptive_layout_shift\",\n DOCUMENT_DISCARDED: \"document_discarded\",\n ERROR_CLICK: \"error_click\",\n FETCH_FAILED: \"fetch_failed\",\n FOCUS_LOST: \"focus_lost\",\n FONT_FAILURE: \"font_failure\",\n FORM_FRUSTRATION: \"form_frustration\",\n FORM_ABANDONMENT: \"form_abandonment\",\n FOCUSED_CONTROL_OFFSCREEN: \"focused_control_offscreen\",\n HTTP_5XX: \"http_5xx\",\n HTTP_RESPONSE_FAILURE: \"http_response_failure\",\n INVISIBLE_TEXT: \"invisible_text\",\n EMBEDDED_CONTENT_STALLED: \"embedded_content_stalled\",\n LAYOUT_OVERFLOW: \"layout_overflow\",\n MAIN_THREAD_STALL: \"main_thread_stall\",\n MEDIA_PLAYBACK_FAILED: \"media_playback_failed\",\n MEDIA_PLAYBACK_STALLED: \"media_playback_stalled\",\n MODAL_FOCUS_ESCAPE: \"modal_focus_escape\",\n OCCLUDED_CONTROL: \"occluded_control\",\n RAGE_CLICK: \"rage_click\",\n RATE_LIMITED: \"rate_limited\",\n NAVIGATION_STALLED: \"navigation_stalled\",\n RELOAD_LOOP: \"reload_loop\",\n REQUEST_STORM: \"request_storm\",\n SEMANTIC_RESPONSE_FAILURE: \"semantic_response_failure\",\n SCROLL_JAIL: \"scroll_jail\",\n SLOW_RESPONSE: \"slow_response\",\n SLOW_RESOURCE: \"slow_resource\",\n SLOW_INTERACTION: \"slow_interaction\",\n SOCKET_ABNORMAL_CLOSE: \"socket_abnormal_close\",\n SOCKET_FLAPPING: \"socket_flapping\",\n SSE_FLAPPING: \"sse_flapping\",\n STALE_RELEASE: \"stale_release\",\n STALLED_STREAM: \"stalled_stream\",\n STUCK_LOADING: \"stuck_loading\",\n THEME_MISMATCH: \"theme_mismatch\",\n THRASHED_CURSOR: \"thrashed_cursor\",\n STORAGE_FAILURE: \"storage_failure\",\n WEBGL_CONTEXT_LOST: \"webgl_context_lost\",\n SERVICE_WORKER_FAILURE: \"service_worker_failure\",\n WORKER_FAILURE: \"worker_failure\",\n} as const;\n\nexport type BeaconSignal = (typeof BEACON_SIGNAL)[keyof typeof BEACON_SIGNAL];\n\n/** Stable DOM attributes understood by Beacon's instrumentation. */\nexport const BEACON_ATTRIBUTE = {\n APP_ROOT: \"data-beacon-app-root\",\n CONTROL_GROUP: \"data-beacon-control-group\",\n DEAD_CLICK: \"data-beacon-dead-click\",\n NAME: \"data-beacon-name\",\n EMBED: \"data-beacon-embed\",\n LOADING: \"data-beacon-loading\",\n LOADING_TIMEOUT: \"data-beacon-loading-timeout\",\n FORM: \"data-beacon-form\",\n /** `=\"allow\"` exempts an intentional dynamic subtree from layout-shift issues. */\n LAYOUT_SHIFT: \"data-beacon-layout-shift\",\n MEDIA: \"data-beacon-media\",\n OVERFLOW: \"data-beacon-overflow\",\n SCAN: \"data-beacon-scan\",\n THEME: \"data-beacon-theme\",\n} as const;\n",
|
|
6
|
+
"/**\n * Noise policy — which captured signals are real, and which are known-fine.\n *\n * An issue board is only worth opening if everything on it is real. A board\n * that files an application's own SSE stream as a stalled request every shift\n * gets ignored, and the actual breakage gets ignored along with it. So every\n * application that ships Beacon ends up writing the same `beforeSend` filter:\n * a list of named, explained exclusions. In practice most of that list is not\n * application-specific at all — a stale chunk import after a deploy, a theme\n * extension rewriting inline styles before hydration, a read that failed while\n * the tab was hidden, a 5xx the server already captured with a stack. What\n * differs between applications is a handful of endpoints and hostnames.\n *\n * This module is that list, with the endpoints as configuration.\n *\n * It is a separate entry point on purpose, and it imports nothing from the SDK\n * at runtime. Boot-time policy is read by the synchronous page graph; pulling\n * Beacon's runtime constants into that graph makes the bundler merge the whole\n * monitoring SDK back into it, defeating lazy startup. Everything here is\n * plain data and pure functions, and the only imports are types, which erase.\n */\nimport { BEACON_ATTRIBUTE, BEACON_SIGNAL } from \"./contracts\";\nimport type {\n BeaconEvent,\n BeaconResourceFailure,\n BeaconSignals,\n} from \"./index\";\n\n/** Re-exported so a page can read boot-time policy from one import. Both live\n * in `./contracts`, which pulls in nothing else. */\nexport { BEACON_ATTRIBUTE, BEACON_SIGNAL };\n\n/** A batched request event covers several endpoints at once, and Beacon marks\n * the method `multiple` when they did not share one. */\nconst BATCHED_METHOD = \"multiple\";\n\n/**\n * One endpoint exemption: a signal raised against a set of endpoints that are\n * known to produce it in normal operation.\n *\n * This is the shape nearly every application-specific rule turns out to have —\n * a stream that stays open for hours, an upload that is megabytes by design, a\n * marketing pixel that fails when a blocker is installed, a request whose\n * client already owns its retry. Naming it once means those rules become four\n * lines of configuration instead of four hand-written predicates.\n */\nexport type EndpointExemption = {\n /** Signals this exemption applies to. */\n signals: readonly string[];\n /** Endpoints it covers. A string matches as a substring unless `match` says\n * otherwise; a RegExp is tested against the endpoint. */\n endpoints: readonly (RegExp | string)[];\n /** Restrict to specific request methods. Omit to cover every method. A\n * batched event (method `multiple`) matches whenever its endpoints do. */\n methods?: readonly string[];\n /** How string patterns are compared. Default `includes`. */\n match?: \"exact\" | \"includes\" | \"prefix\";\n};\n\n/**\n * Read the endpoints off an event.\n *\n * Beacon reports a single request on `endpoint` and a batch on `endpoints` as a\n * comma-separated list. Every application that writes one of these rules writes\n * this parser first, usually more than once.\n */\nexport const eventEndpoints = (tags: BeaconEvent[\"tags\"]): string[] => {\n const batched = tags?.endpoints\n ?.split(\",\")\n .map((endpoint) => endpoint.trim())\n .filter(Boolean);\n if (batched !== undefined && batched.length > 0) return batched;\n\n return tags?.endpoint ? [tags.endpoint] : [];\n};\n\nconst endpointMatches = (\n endpoint: string,\n pattern: RegExp | string,\n match: EndpointExemption[\"match\"],\n): boolean => {\n if (typeof pattern !== \"string\") return pattern.test(endpoint);\n if (match === \"exact\") return endpoint === pattern;\n if (match === \"prefix\") return endpoint.startsWith(pattern);\n\n return endpoint.includes(pattern);\n};\n\n/**\n * Whether an event is fully covered by an exemption.\n *\n * Every endpoint has to match, not just one: a batch that mixes the exempt\n * stream with a real request is a real request, and suppressing it would hide\n * the failure behind the stream that happened to travel with it.\n */\nexport const matchesEndpointExemption = (\n event: Pick<BeaconEvent, \"tags\">,\n exemption: EndpointExemption,\n): boolean => {\n const signal = event.tags?.signal;\n if (signal === undefined || !exemption.signals.includes(signal)) return false;\n const method = event.tags?.method;\n if (\n exemption.methods !== undefined &&\n method !== undefined &&\n method !== BATCHED_METHOD &&\n !exemption.methods.includes(method)\n )\n return false;\n const endpoints = eventEndpoints(event.tags);\n\n return (\n endpoints.length > 0 &&\n endpoints.every((endpoint) =>\n exemption.endpoints.some((pattern) =>\n endpointMatches(endpoint, pattern, exemption.match),\n ),\n )\n );\n};\n\n/**\n * A read that failed while the tab was hidden.\n *\n * A backgrounded tab losing a request is browser lifecycle, not breakage —\n * suspension, a dropped connection, a VPN moving. Applications refetch on\n * focus. Visible failures, writes and timeouts all stay actionable.\n */\nexport const isHiddenReadFailure = (\n event: Pick<BeaconEvent, \"tags\">,\n): boolean =>\n event.tags?.signal === BEACON_SIGNAL.FETCH_FAILED &&\n event.tags.method === \"GET\" &&\n event.tags.visibilityState === \"hidden\" &&\n (event.tags.failureKind === \"offline\" ||\n event.tags.failureKind === \"transport\");\n\n/**\n * A 5xx the server already captured.\n *\n * The trace id means a server-side capture exists with the stack, the request\n * and the context. The browser's view of the same failure would open a second\n * issue for one fault, with less in it.\n */\nexport const isServerCapturedHttpFailure = (\n event: Pick<BeaconEvent, \"tags\" | \"traceId\">,\n probeEndpoints: readonly string[] = [],\n): boolean => {\n if (\n event.tags?.signal !== BEACON_SIGNAL.HTTP_5XX ||\n event.traceId === undefined\n )\n return false;\n const endpoint = event.tags.endpoint;\n\n // Cross-origin endpoints have no server-side capture to defer to, and a\n // failing health probe is the one 5xx worth hearing from the browser: it is\n // how an application finds out its own server stopped answering.\n return (\n endpoint?.startsWith(\"/\") === true && !probeEndpoints.includes(endpoint)\n );\n};\n\n/**\n * The page is running an older release than this browser has already seen.\n *\n * Applications that prompt for their own updates — a service worker with an\n * update path, a release probe with an `onStale` reload — already tell the\n * person what to do. Reporting it as an issue too is a second voice saying the\n * same thing to someone who cannot act on it.\n */\nexport const isStaleReleaseSignal = (\n event: Pick<BeaconEvent, \"tags\">,\n): boolean => event.tags?.signal === BEACON_SIGNAL.STALE_RELEASE;\n\nconst STALE_CHUNK_IMPORT =\n /failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed/iu;\n\n/**\n * A dynamic import for a chunk the deploy replaced.\n *\n * The document was served before the release and asks for a file the release\n * renamed. The update path already recovers it, so what is left is a console\n * error that would churn the board on every deploy, once per open tab.\n */\nexport const isStaleChunkImport = (\n event: Pick<BeaconEvent, \"message\">,\n): boolean => STALE_CHUNK_IMPORT.test(event.message);\n\nconst OPAQUE_SCRIPT_ERROR = /^script error\\.?$/iu;\n\n/**\n * A browser hides an error thrown by a script from another origin (an\n * extension, an ad or analytics tag, a CDN script without CORS) behind a bare\n * \"Script error.\" with no message, file or stack. Nothing in it can be acted\n * on or even attributed to the application.\n */\nexport const isOpaqueScriptError = (\n event: Pick<BeaconEvent, \"message\" | \"stack\">,\n): boolean =>\n OPAQUE_SCRIPT_ERROR.test(event.message.trim()) &&\n !(event.stack ?? \"\")\n .split(\"\\n\")\n .slice(1)\n .some((line) => line.trim() !== \"\");\n\nconst THEME_EXTENSION_INLINE_STYLE = /--(?:darkreader|noir)-inline-/u;\n\nconst breadcrumbMessage = (breadcrumb: unknown): string | undefined => {\n if (breadcrumb === null || typeof breadcrumb !== \"object\") return undefined;\n const message = Reflect.get(breadcrumb, \"message\");\n\n return typeof message === \"string\" ? message : undefined;\n};\n\n/**\n * A hydration mismatch caused by a page-recolouring extension.\n *\n * Dark Reader and its kind rewrite inline styles before the framework hydrates,\n * and the framework correctly reports that the markup it found is not the\n * markup it rendered. The edit is the extension's, made in a browser the\n * application will never see, and no change to the application removes it.\n */\nexport const isThemeExtensionHydrationNoise = (\n event: Pick<BeaconEvent, \"extra\" | \"message\">,\n): boolean => {\n if (event.message !== \"Hydration completed but contains mismatches.\")\n return false;\n const breadcrumbs = event.extra?.breadcrumbs;\n\n return (\n Array.isArray(breadcrumbs) &&\n breadcrumbs.some((breadcrumb) =>\n THEME_EXTENSION_INLINE_STYLE.test(breadcrumbMessage(breadcrumb) ?? \"\"),\n )\n );\n};\n\n/**\n * A browser deprecation report for something the page does not control.\n *\n * A third-party tag's own deprecation is attributed to the document that hosts\n * it. Naming the report identities that are known to come from outside keeps\n * the ones from application code actionable.\n */\nexport const isExternalBrowserDeprecation = (\n event: Pick<BeaconEvent, \"tags\">,\n reportIdentities: readonly string[],\n): boolean =>\n event.tags?.signal === BEACON_SIGNAL.BROWSER_POLICY_VIOLATION &&\n event.tags.reportType === \"deprecation\" &&\n reportIdentities.includes(event.tags.policyId ?? \"\");\n\n/** Google's Attribution Reporting deprecation, emitted by the ads and\n * analytics tags rather than by the page that embeds them. */\nexport const ATTRIBUTION_REPORTING_DEPRECATION = \"AttributionReporting\";\n\nexport type NoisePolicyOptions = {\n /**\n * Endpoints that are known to raise a signal in normal operation: streams\n * that stay open, uploads that are large by design, pixels that a blocker\n * refuses, requests whose client owns its own retry.\n */\n exemptions?: readonly EndpointExemption[];\n /**\n * Health/readiness endpoints. A 5xx from one of these still reports even\n * when a trace id says the server captured it, because a server that has\n * stopped answering cannot be relied on to file its own issue.\n */\n probeEndpoints?: readonly string[];\n /** Browser report identities known to originate outside the page. Defaults\n * to Attribution Reporting; pass `[]` to keep every deprecation. */\n externalDeprecations?: readonly string[];\n /** The application prompts for its own updates. Default true. */\n ownsReleaseUpdates?: boolean;\n /** Suppress hidden-tab read failures. Default true. */\n ignoreHiddenReadFailures?: boolean;\n /** Suppress 5xx the server already captured. Default true. */\n ignoreServerCapturedFailures?: boolean;\n /** Suppress dynamic imports for chunks a deploy replaced. Default true. */\n ignoreStaleChunkImports?: boolean;\n /** Suppress hydration mismatches written by theme extensions. Default true. */\n ignoreThemeExtensionHydration?: boolean;\n /** Suppress cross-origin \"Script error.\" with no stack. Default true. */\n ignoreOpaqueScriptErrors?: boolean;\n /** Application-specific rules, run after the built-in ones. */\n rules?: readonly ((event: BeaconEvent) => boolean)[];\n};\n\n/**\n * Build the `beforeSend` predicate.\n *\n * Returns true for an event that should be dropped, so a caller reads as\n * `beforeSend: (event) => (isNoise(event) ? null : event)`.\n */\nexport const createNoisePolicy = (options: NoisePolicyOptions = {}) => {\n const {\n exemptions = [],\n externalDeprecations = [ATTRIBUTION_REPORTING_DEPRECATION],\n ignoreHiddenReadFailures = true,\n ignoreOpaqueScriptErrors = true,\n ignoreServerCapturedFailures = true,\n ignoreStaleChunkImports = true,\n ignoreThemeExtensionHydration = true,\n ownsReleaseUpdates = true,\n probeEndpoints = [],\n rules = [],\n } = options;\n\n return (event: BeaconEvent): boolean =>\n (ownsReleaseUpdates && isStaleReleaseSignal(event)) ||\n (ignoreStaleChunkImports && isStaleChunkImport(event)) ||\n (ignoreThemeExtensionHydration && isThemeExtensionHydrationNoise(event)) ||\n (ignoreOpaqueScriptErrors && isOpaqueScriptError(event)) ||\n (ignoreHiddenReadFailures && isHiddenReadFailure(event)) ||\n (ignoreServerCapturedFailures &&\n isServerCapturedHttpFailure(event, probeEndpoints)) ||\n (externalDeprecations.length > 0 &&\n isExternalBrowserDeprecation(event, externalDeprecations)) ||\n exemptions.some((exemption) =>\n matchesEndpointExemption(event, exemption),\n ) ||\n rules.some((rule) => rule(event));\n};\n\nexport type ResourceFailurePolicyOptions = {\n /** Hostnames whose scripts are not the application's to fix. A pattern\n * matches the hostname itself or any subdomain of it. */\n thirdPartyHosts?: readonly string[];\n /** Cross-origin images are optional by default: the elements that show them\n * render a placeholder, and the remote host is not the application's to\n * fix. Set false to treat a missing remote image as an error. */\n optionalCrossOriginImages?: boolean;\n /** Same-origin path prefixes serving optional imagery — an avatar, a logo\n * proxy, an uploaded thumbnail — where a placeholder already stands in. */\n optionalPathPrefixes?: readonly string[];\n};\n\nconst hostMatches = (hostname: string, pattern: string): boolean =>\n hostname === pattern || hostname.endsWith(`.${pattern}`);\n\n/**\n * Split a failed resource's URL into the two parts these rules ask about.\n *\n * An absolute URL carries its own host and needs no base. A relative one is\n * same-origin by construction, and its path is the characters before any query\n * — which is worth extracting directly, because the contexts this runs in do\n * not all have a resolvable `location`: a worker, a server render, or a test\n * DOM parked on `about:blank`. Falling back to \"unparseable\" there would\n * quietly disable the path rules in exactly the places hardest to notice.\n */\nconst parseFailureUrl = (\n url: string,\n): { hostname: string; pathname: string } | undefined => {\n try {\n return new URL(url);\n } catch {\n // Relative; fall through.\n }\n const base = typeof location === \"undefined\" ? undefined : location.href;\n if (base !== undefined)\n try {\n return new URL(url, base);\n } catch {\n // Unusable base; fall through to the path-only reading.\n }\n\n return url.startsWith(\"/\")\n ? { hostname: \"\", pathname: url.split(/[?#]/u)[0] ?? url }\n : undefined;\n};\n\n/**\n * Which failed resources are errors.\n *\n * A third-party analytics script blocked by an extension and a customer's\n * uploaded thumbnail 404ing are not the application being broken — the first is\n * not the application's code to fix, and the second already renders a\n * placeholder. Its own scripts, styles and images still are.\n *\n * Returns Beacon's `resourceErrors` classifier: a level to report at, or false\n * to ignore.\n */\nexport const createResourceFailurePolicy = (\n options: ResourceFailurePolicyOptions = {},\n) => {\n const {\n optionalCrossOriginImages = true,\n optionalPathPrefixes = [],\n thirdPartyHosts = [],\n } = options;\n\n return (failure: BeaconResourceFailure): \"error\" | false => {\n if (failure.url === undefined) return \"error\";\n // An unreadable URL is not evidence that the resource was optional, so it\n // reports rather than disappearing.\n const parsed = parseFailureUrl(failure.url);\n if (parsed === undefined) return \"error\";\n if (\n failure.type === \"script\" &&\n thirdPartyHosts.some((host) => hostMatches(parsed.hostname, host))\n )\n return false;\n if (failure.type !== \"img\") return \"error\";\n if (optionalCrossOriginImages && failure.crossOrigin) return false;\n\n return optionalPathPrefixes.some((prefix) =>\n parsed.pathname.startsWith(prefix),\n )\n ? false\n : \"error\";\n };\n};\n\nexport type ReliabilityPresetOptions = {\n /**\n * Behavioural detectors watch a person rather than a page — what they\n * clicked, where they got stuck — so they belong on the same consent\n * boundary as session replay. Structural health stays on for everyone.\n */\n behavioural?: boolean;\n /** A `report-to` endpoint already delivers browser policy reports, so the\n * parallel observer would file each deprecation twice. Default true. */\n hasReportingEndpoint?: boolean;\n /** A Performance console owns ordinary latency, so error triage keeps only\n * failures. Default true. */\n ownsLatencyElsewhere?: boolean;\n /** The application prompts for its own updates. Default true. */\n ownsReleaseUpdates?: boolean;\n /** Documents are restored from server state on boot, so a browser evicting\n * a tab to reclaim memory is not a fault. Default true. */\n restoresFromServerState?: boolean;\n /** Endpoints whose client owns reconnect and resume. */\n recoverableSockets?: Array<RegExp | string>;\n /** bfcache blockers inherent to a capability the application requires. */\n ignoredBfcacheReasons?: string[];\n};\n\n/**\n * The signal set an application with its own error triage usually wants.\n *\n * Beacon enables every detector by default, which is right for an application\n * that has nothing else. One that also runs a Performance console, a release\n * probe and a Reporting API endpoint has to turn the same four off, for the\n * same reasons, every time — otherwise each of those systems files the issue\n * its neighbour already filed. Everything not named here keeps its default.\n */\nexport const reliabilitySignalPreset = (\n options: ReliabilityPresetOptions = {},\n): BeaconSignals => {\n const {\n behavioural = false,\n hasReportingEndpoint = true,\n ignoredBfcacheReasons,\n ownsLatencyElsewhere = true,\n ownsReleaseUpdates = true,\n recoverableSockets,\n restoresFromServerState = true,\n } = options;\n\n return {\n browserPolicyViolations: !hasReportingEndpoint,\n deadClicks: behavioural,\n documentDiscards: !restoresFromServerState,\n errorClicks: behavioural,\n formAbandonment: behavioural,\n formFrustration: behavioural,\n ...(ignoredBfcacheReasons ? { ignoredBfcacheReasons } : {}),\n rageClicks: behavioural,\n ...(recoverableSockets ? { recoverableSockets } : {}),\n scrollJail: behavioural,\n slowInteractions: !ownsLatencyElsewhere,\n slowResponses: !ownsLatencyElsewhere,\n staleReleases: !ownsReleaseUpdates,\n thrashedCursors: behavioural,\n };\n};\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": ";AACO,IAAM,gBAAgB;AAAA,EAC3B,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,0BAA0B;AAAA,EAC1B,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,YAAY;AAAA,EACZ,yBAAyB;AAAA,EACzB,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,2BAA2B;AAAA,EAC3B,UAAU;AAAA,EACV,uBAAuB;AAAA,EACvB,gBAAgB;AAAA,EAChB,0BAA0B;AAAA,EAC1B,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,uBAAuB;AAAA,EACvB,wBAAwB;AAAA,EACxB,oBAAoB;AAAA,EACpB,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,eAAe;AAAA,EACf,2BAA2B;AAAA,EAC3B,aAAa;AAAA,EACb,eAAe;AAAA,EACf,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,wBAAwB;AAAA,EACxB,gBAAgB;AAClB;AAKO,IAAM,mBAAmB;AAAA,EAC9B,UAAU;AAAA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9
|
+
"debugId": "508EFF44D0F80FED64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/beacon",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.21",
|
|
4
4
|
"description": "Tiny, zero-dependency browser SDK for the AbsoluteJS observability stack. Captures uncaught errors + unhandled rejections, breadcrumbs (console/click/fetch/history), batches, and POSTs an envelope to @absolutejs/errors/ingest via sendBeacon/keepalive. ~2-5KB gz, no Effect in the browser; end-to-end type-safe via the shared erased envelope contract.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,23 +42,32 @@
|
|
|
42
42
|
"import": "./dist/manifest.js",
|
|
43
43
|
"default": "./dist/manifest.js"
|
|
44
44
|
},
|
|
45
|
-
"./manifest.json": "./dist/manifest.json"
|
|
45
|
+
"./manifest.json": "./dist/manifest.json",
|
|
46
|
+
"./outbox": {
|
|
47
|
+
"types": "./dist/outbox.d.ts",
|
|
48
|
+
"import": "./dist/outbox.js",
|
|
49
|
+
"default": "./dist/outbox.js"
|
|
50
|
+
}
|
|
46
51
|
},
|
|
47
52
|
"publishConfig": {
|
|
48
53
|
"access": "public"
|
|
49
54
|
},
|
|
50
55
|
"files": [
|
|
51
|
-
"
|
|
52
|
-
"README.md"
|
|
56
|
+
"CHANGELOG.md",
|
|
57
|
+
"README.md",
|
|
58
|
+
"changelog.json",
|
|
59
|
+
"dist"
|
|
53
60
|
],
|
|
54
61
|
"scripts": {
|
|
55
|
-
"build": "rm -rf dist && bun build src/index.ts src/contracts.ts src/early.ts src/policy.ts src/manifest.ts --outdir dist --root ./src --sourcemap --target=browser --external @absolutejs/manifest --external '@absolutejs/manifest/*' --external @sinclair/typebox --external '@sinclair/typebox/*' --external web-vitals --external 'web-vitals/*' && tsc --project tsconfig.build.json && absolute-manifest emit",
|
|
62
|
+
"build": "rm -rf dist && bun build src/index.ts src/contracts.ts src/early.ts src/policy.ts src/outbox.ts src/manifest.ts --outdir dist --root ./src --sourcemap --target=browser --external @absolutejs/manifest --external '@absolutejs/manifest/*' --external @sinclair/typebox --external '@sinclair/typebox/*' --external web-vitals --external 'web-vitals/*' && tsc --project tsconfig.build.json && absolute-manifest emit",
|
|
56
63
|
"test": "bun test",
|
|
57
64
|
"typecheck": "tsc --noEmit",
|
|
58
65
|
"format": "prettier --write \"./**/*.{ts,json,md}\"",
|
|
59
66
|
"verify-package": "absolute-manifest verify-package",
|
|
60
|
-
"check:package": "bun run format && bun run typecheck && bun run test && bun run verify-package && bun run build",
|
|
61
|
-
"release": "bun run check:package && npm publish --access public"
|
|
67
|
+
"check:package": "bun run format && bun run typecheck && bun run test && bun run verify-package && bun run build && bun run test:package && absolute-changelog check",
|
|
68
|
+
"release": "bun run check:package && npm publish --access public",
|
|
69
|
+
"prepublishOnly": "bun run check:package",
|
|
70
|
+
"test:package": "bun scripts/verify-outbox-package.ts"
|
|
62
71
|
},
|
|
63
72
|
"keywords": [
|
|
64
73
|
"absolutejs",
|
|
@@ -93,6 +102,7 @@
|
|
|
93
102
|
"@sinclair/typebox": "0.34.52"
|
|
94
103
|
},
|
|
95
104
|
"devDependencies": {
|
|
105
|
+
"@absolutejs/changelog": "^0.6.0",
|
|
96
106
|
"@absolutejs/errors": "0.9.0",
|
|
97
107
|
"@happy-dom/global-registrator": "20.11.1",
|
|
98
108
|
"@types/bun": "1.3.14",
|