import type { ConsentConfigSnapshot, ConsentLoggerOptions, ConsentRecord } from './types.js'; /** * Reliable, fire-and-forget transport for consent records. * * - Prefers `navigator.sendBeacon` so a record survives the page navigation * that often follows "Accept all". The body uses a CORS-safelisted * content-type (`text/plain` by default), so the beacon reaches cross-origin * endpoints with no preflight and regardless of server CORS. * - If `contentType` is set to a non-safelisted type (e.g. `application/json`), * a cross-origin beacon would need a preflight beacons cannot perform and be * silently dropped, so `auto` falls back to `fetch(..., { keepalive: true })` * for cross-origin endpoints. keepalive fetch survives navigation too. * - Always uses `fetch` when custom headers are configured (beacons cannot set * headers). The `transport` option can force `'beacon'` or `'fetch'`. * - Buffers failed sends in `localStorage` and retries them on construction * (i.e. the next page load) and after the next successful send. * * The class is environment-tolerant: it reads `navigator`, `fetch` and * `localStorage` lazily and degrades gracefully when any are unavailable. */ export declare class ConsentLogger { private readonly endpoint; private readonly snapshotEndpoint; private readonly transport; private readonly contentType; private readonly headers; private readonly includeUserAgent; private readonly queueKey; private readonly maxQueueSize; private readonly snapshotSentKeyPrefix; /** Revisions whose snapshot upload is in-flight or already acknowledged. */ private readonly snapshotInFlight; constructor(options: ConsentLoggerOptions); /** Send one consent record. Falls back to the offline queue on failure. */ log(record: ConsentRecord): void; /** * Upload a banner-config snapshot. Idempotent per revision: the first * successful upload for a given revision sets a localStorage flag, and later * calls for the same revision become no-ops until the flag is cleared. The * server should additionally dedupe on content hash (DSK-OH Rn. 85). * * Uses fetch only (not sendBeacon) because beacon's boolean return reflects * queueing, not delivery — we cannot set the per-revision dedup flag on a * value that doesn't represent an actual HTTP acknowledgement. */ logSnapshot(snapshot: ConsentConfigSnapshot): void; /** Attempt to resend any queued records (via fetch, so success is confirmed). */ flush(): Promise; private enrich; private dispatch; private dispatchTo; /** * True when `url` resolves to a different origin than the current page. * Relative URLs and environments without a `location` are treated as * same-origin (the conservative default that preserves beacon usage). */ private isCrossOrigin; /** * True when `contentType`'s essence is CORS-safelisted, so a cross-origin * beacon is a "simple request" that needs no preflight. Parameters (e.g. * `;charset=UTF-8`) are ignored — only the type/subtype matters. */ private isSafelistedContentType; private sendBeacon; private dispatchFetch; private dispatchFetchTo; /** * Merge custom headers but always set the configured `content-type` * (case-insensitively), so a raw `Content-Type` header in `headers` can't * accidentally break ingestion or diverge from the beacon's content-type. */ private buildFetchHeaders; private enqueue; private readQueue; private writeQueue; private isOffline; } /** Convenience factory mirroring the `create()` style used elsewhere. */ export declare function createConsentLogger(options: ConsentLoggerOptions): ConsentLogger;