/** * Fire-and-forget delivery for telemetry/analytics. Tries (in order): * * 1. `fetchLater()` — WICG Pending Beacon API, Chromium 135+. Deferred * delivery; the browser sends the request even if the page unloads. * 2. `fetch(url, { keepalive: true })` — survives unload up to 64 KiB * total in-flight per origin. Errors visible if you await the promise. * 3. `navigator.sendBeacon(url, body)` — same 64 KiB cap, POST-only, * no response. * * Browser-only — no Node fallback. The first available primitive wins. * * @example * ```ts * import { beacon } from "misina/beacon" * * beacon("/telemetry", { event: "page_view", ts: Date.now() }) * ``` */ export interface BeaconOptions { /** HTTP method. Default: 'POST'. sendBeacon ignores this and always POSTs. */ method?: string; /** Headers. Note: sendBeacon ignores headers entirely. */ headers?: Record; /** * Earliest delivery time in ms relative to now. Honored by fetchLater * only; falls through to immediate dispatch on the other backends. */ activateAfter?: number; } export type BeaconResult = { ok: true; via: "fetchLater" | "fetch-keepalive" | "sendBeacon"; } | { ok: false; reason: "no-backend" | "send-rejected"; }; export declare function beacon(url: string, body: BodyInit | Record | undefined, options?: BeaconOptions): BeaconResult;