/** * Observer entry point. * * startObserver wires the four pieces — allowlist filter + queue + * transport + PostHog subscription — into a single lifecycle controlled * via the returned handle. The handle is reference-counted: multiple * call sites (e.g. multiple chatbot widgets on the same page) share * one observer. * * Idempotent: calling startObserver twice with equivalent options * returns the same instance. Calling stop() decrements the ref count; * the observer tears down only when the count reaches zero. */ import { type ObservationEvent, type RawEvent } from './allowlist'; import { type ObserverStats } from './queue'; import { type Transport } from './transport'; export interface StartObserverOptions { url: string; token: () => string; getDistinctId: () => string | null; getSessionId: () => string | null; observableEvents?: readonly string[]; /** * Optional per-observation enrichment applied AFTER matchEvent, BEFORE the * observation is queued for POST. Given the matched observation plus the raw * event (element chain intact), returns a possibly-augmented observation — * e.g. attaching normalized product identity from the active platform * adapter. Kept as a generic transform so the observer stays platform-neutral. */ enrich?: (ev: ObservationEvent, raw: RawEvent) => ObservationEvent; /** Test seam: override fetch/timer behavior by injecting a custom transport. */ transport?: Transport; } export interface ObserverHandle { stop(): void; stats(): ObserverStats; /** Test seam: ingest a raw event directly without depending on PostHog being loaded. */ ingest(raw: RawEvent): void; flushNow(): Promise; } export declare function startObserver(opts: StartObserverOptions): ObserverHandle; /** Test-only: reset module singleton state. */ export declare function _resetObserverForTests(): void; //# sourceMappingURL=index.d.ts.map