/** * Zero-code network capture for JS runtimes (Web, React Native, Electron * renderer/main): patches `fetch` and `XMLHttpRequest`, emits one redacted * NetworkEvent per completed exchange. Fail-open by design — capture errors * never propagate into the app, and the app's response objects are never * consumed (fetch bodies are read from a clone; XHR is observed post-loadend). * * The pre-patch `fetch` is preserved and exported for the sink, so delivery * traffic is STRUCTURALLY invisible to capture (lesson from the Flutter SDK's * self-capture loop — no ignoreHosts wiring, no recursion possible). */ import { projectBody } from './redact.js'; export interface NetworkEvent { method: string; /** Already redacted. */ url: string; statusCode: number | null; durationMs: number; /** Accurate byte size, or undefined when unknowable (streams) — never a fake 0. */ requestBodyBytes: number | undefined; responseBodyBytes: number | undefined; requestHeaders: Record; responseHeaders: Record; /** Redacted request body text (textual bodies only, capped). */ requestBody: string | null; /** Redacted response body text (textual bodies only, capped). */ responseBody: string | null; errorText: string | null; timestampMs: number; } export interface CaptureOptions { maxBodyBytes?: number; /** Return false to skip a request entirely (sampling / allow-listing). */ captureWhen?: (url: string) => boolean; /** Hosts to skip (exact or subdomain match). */ ignoreHosts?: Set; /** Extra header names (lowercase) to mask on top of the built-in set. */ redactHeaderNames?: Set; onEvent: (e: NetworkEvent) => void; } type FetchFn = typeof globalThis.fetch; /** The runtime's fetch as it was BEFORE capture installed. Sink delivery uses * this so its own requests can never be captured. */ export declare function nativeFetch(): FetchFn; export declare function setEnabled(v: boolean): void; export declare function isInstalled(): boolean; export declare function install(options: CaptureOptions): void; export declare function uninstall(): void; /** Exported for the projection step in the sink. */ export { projectBody };