@absolutejs/beacon 0.7.0-beta.14 → 0.7.0-beta.16
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 +12 -0
- package/README.md +52 -0
- package/changelog.json +30 -0
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.js +2 -1
- package/dist/contracts.js.map +3 -3
- package/dist/index.d.ts +5 -1
- package/dist/index.js +86 -2
- package/dist/index.js.map +4 -4
- package/dist/outbox.d.ts +42 -0
- package/dist/policy.js +2 -1
- package/dist/policy.js.map +3 -3
- package/package.json +1 -1
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/policy.js
CHANGED
|
@@ -10,6 +10,7 @@ var BEACON_SIGNAL = {
|
|
|
10
10
|
CONTROL_COLLISION: "control_collision",
|
|
11
11
|
CSP_VIOLATION: "csp_violation",
|
|
12
12
|
CLIPBOARD_FAILURE: "clipboard_failure",
|
|
13
|
+
COLLAPSED_MODAL: "collapsed_modal",
|
|
13
14
|
DEAD_CLICK: "dead_click",
|
|
14
15
|
DISRUPTIVE_LAYOUT_SHIFT: "disruptive_layout_shift",
|
|
15
16
|
DOCUMENT_DISCARDED: "document_discarded",
|
|
@@ -217,5 +218,5 @@ export {
|
|
|
217
218
|
reliabilitySignalPreset
|
|
218
219
|
};
|
|
219
220
|
|
|
220
|
-
//# debugId=
|
|
221
|
+
//# debugId=508EFF44D0F80FED64756E2164756E21
|
|
221
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",
|
|
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
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": ";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,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C1D,IAAI,QAAQ,QAAQ;AAAA,MAAW,OAAO;AAAA,IAGtC,MAAM,SAAS,gBAAgB,QAAQ,GAAG;AAAA,IAC1C,IAAI,WAAW;AAAA,MAAW,OAAO;AAAA,IACjC,IACE,QAAQ,SAAS,YACjB,gBAAgB,KAAK,CAAC,SAAS,YAAY,OAAO,UAAU,IAAI,CAAC;AAAA,MAEjE,OAAO;AAAA,IACT,IAAI,QAAQ,SAAS;AAAA,MAAO,OAAO;AAAA,IACnC,IAAI,6BAA6B,QAAQ;AAAA,MAAa,OAAO;AAAA,IAE7D,OAAO,qBAAqB,KAAK,CAAC,WAChC,OAAO,SAAS,WAAW,MAAM,CACnC,IACI,QACA;AAAA;AAAA;AAqCD,IAAM,0BAA0B,CACrC,UAAoC,CAAC,MACnB;AAAA,EAClB;AAAA,IACE,cAAc;AAAA,IACd,uBAAuB;AAAA,IACvB;AAAA,IACA,uBAAuB;AAAA,IACvB,qBAAqB;AAAA,IACrB;AAAA,IACA,0BAA0B;AAAA,MACxB;AAAA,EAEJ,OAAO;AAAA,IACL,yBAAyB,CAAC;AAAA,IAC1B,YAAY;AAAA,IACZ,kBAAkB,CAAC;AAAA,IACnB,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,iBAAiB;AAAA,OACb,wBAAwB,EAAE,sBAAsB,IAAI,CAAC;AAAA,IACzD,YAAY;AAAA,OACR,qBAAqB,EAAE,mBAAmB,IAAI,CAAC;AAAA,IACnD,YAAY;AAAA,IACZ,kBAAkB,CAAC;AAAA,IACnB,eAAe,CAAC;AAAA,IAChB,eAAe,CAAC;AAAA,IAChB,iBAAiB;AAAA,EACnB;AAAA;",
|
|
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.16",
|
|
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",
|