/** * Harness remote telemetry emitter — a thin adapter that bridges the * harness-internal `AnalyticsEvent` shape into `@sapiom/analytics-core`'s * `track()` API, forwarding events to the hosted collector at * `POST /v1/analytics/collector`. * * Design contract: * - ONE analytics-core instance per harness server process. Multiple * concurrent harness sessions are multiplexed onto it via per-event * `session_id` overrides — no timer/listener multiplication. * - Consent is wired via the `disabled` flag on the analytics instance. * When the settings toggle changes, the current instance is shut down and * a new one is created with the updated flag. * - The local ndjson store (store.ts) is written ALWAYS, independent of * consent; this emitter gates only the remote collector path. * - `SAPIOM_TELEMETRY_DISABLED=1` and `DO_NOT_TRACK=1` are honored by * analytics-core's own consent resolution, at highest precedence. * - Event shape follows the harness convergence additions in the collector * contract: `data.seq`, `data.context`, `data.harness_session_id`, * `data.agent_session_id`, `data.harness_kind`, `source: "harness"`. */ import { type FetchLike } from "@sapiom/analytics-core"; import type { AnalyticsEvent, CollectorContext } from "../../shared/types.js"; export interface HarnessAnalyticsEmitterOptions { /** Whether remote telemetry is currently opted in. Mutable via setOptIn(). */ telemetryOptIn: boolean; /** Harness package version and runtime context stamped on every event. */ context: CollectorContext; /** Harness package name, e.g. "@sapiom/harness". */ sdkName: string; /** Harness package version string. */ sdkVersion: string; /** Optional API key for server-side org enrichment (x-sapiom-api-key header). */ apiKey?: string | null; /** * Collector endpoint. Defaults to SAPIOM_COLLECTOR_ENDPOINT (the hosted * collector). When SAPIOM_ANALYTICS_ENDPOINT is set in the environment, * analytics-core uses that instead (allows tests to redirect to a mock). */ endpoint?: string; /** Injectable fetch for tests. */ fetchImpl?: FetchLike; onDebug?: (message: string) => void; } /** * The interface the ingest pipeline sees — mirrors the old CollectorBatcher * surface so server/ingest.ts and server/index.ts need only minimal edits. */ export interface HarnessEmitter { enqueue(event: AnalyticsEvent): void; setTelemetryOptIn(optIn: boolean): void; setApiKey(apiKey: string | null): void; flush(): Promise; close(): Promise; } export declare function createHarnessEmitter(options: HarnessAnalyticsEmitterOptions): HarnessEmitter; //# sourceMappingURL=analytics-emitter.d.ts.map