/** * In-memory batching queue for ObservationEvents. * * Holds events until either a size threshold or a time interval triggers * a flush. The flush function is injected so transport choice (fetch vs. * sendBeacon) and auth wiring stay out of this module. * * Backoff strategy: pure exponential, starting at 1s and capping at 30s * (1s → 2s → 4s → 8s → 16s → 30s). Reset on first successful flush. * Jitter is intentionally omitted — the observer queue is per-client, so * thundering-herd at recovery is not a meaningful risk, and deterministic * timing keeps unit tests fast and stable. A "permanent" failure (4xx * marked by the caller) disables the queue entirely — no further flushes * are attempted; lastError is exposed via stats(). */ import type { ObservationEvent } from './allowlist'; export interface FlushError extends Error { /** When true, the queue stops trying forever. Set by transport for 4xx. */ permanent?: boolean; } export interface ObserverQueueOptions { batchSize: number; flushIntervalMs: number; queueCap: number; flush: (batch: ObservationEvent[]) => Promise; backoffStartMs?: number; backoffCapMs?: number; } export interface ObserverStats { queued: number; sent: number; dropped: number; lastError: string | null; disabled: boolean; } export declare class ObserverQueue { private readonly _opts; private readonly _buffer; private _sent; private _dropped; private _lastError; private _disabled; private _intervalTimer; private _backoffTimer; private _currentBackoffMs; private _inFlight; constructor(opts: ObserverQueueOptions); push(event: ObservationEvent): void; flushNow(): Promise; /** * Synchronously hand the newest backend-sized batch to an unload-safe sender. * Returns false when the sender rejected delivery and restores the batch so * the caller can fall back to fetch({ keepalive: true }). */ flushOnPageHide(send: (batch: ObservationEvent[]) => boolean): boolean; stats(): ObserverStats; private _scheduleImmediate; private _scheduleInterval; private _clearInterval; private _flush; private _scheduleBackoff; } //# sourceMappingURL=queue.d.ts.map