/** * Drengr Analytics for JavaScript runtimes — Web, React Native, Electron. * One call captures every fetch/XHR exchange (secret/PII redaction applied * in-process before anything leaves the runtime) and ships it to your org's * ingest endpoint under a publishable key. * * import { Drengr } from 'drengr-js'; * Drengr.start({ * ingestUrl: 'https://.supabase.co/functions/v1/ingest', * publishableKey: 'drengr_pk_…', * appPackage: 'com.example.app', * }); */ import { type CaptureOptions, type NetworkEvent } from './capture.js'; import { IngestSink, type StorageAdapter } from './sink.js'; import { SessionManager, SESSION_IDLE_MS, SESSION_MAX_MS } from './session.js'; import { SDK_VERSION } from './version.js'; export type { NetworkEvent, StorageAdapter }; export { IngestSink, SessionManager, SESSION_IDLE_MS, SESSION_MAX_MS, SDK_VERSION }; export * as redact from './redact.js'; export interface DrengrOptions { ingestUrl: string; publishableKey: string; /** Stable app identifier shown in the dashboard (reverse-DNS or domain). */ appPackage: string; /** Extra envelope context merged over the defaults. */ context?: Record; /** Storage for the offline queue + install id. Default: localStorage or memory. */ storage?: StorageAdapter; maxBodyBytes?: number; captureWhen?: CaptureOptions['captureWhen']; ignoreHosts?: string[]; redactHeaders?: string[]; /** Start paused (e.g. behind a consent gate); call setEnabled(true) later. */ enabled?: boolean; /** Screen/route name for screen_view + tap + crash events (router hook). * Default: location.pathname + location.hash. */ screenName?: () => string; /** Called after each capture, before delivery — for debugging. */ onEvent?: (e: NetworkEvent) => void; /** Turn on the E2EE PII vault. Until the org's signed config is fetched AND * verifies against the PINNED signer, sealing stays off (placeholders only). */ vault?: { /** base64 Ed25519 public key from `drengr-vault keygen` — the pin. */ signPubKey: string; /** The org id (tenant) this SDK reports under; the config is bound to it. */ tenantId: string; /** Override the config endpoint (defaults to the ingest host's /vault-pubkey). */ pubkeyUrl?: string; }; } export declare const Drengr: { /** Install capture + delivery. Subsequent calls are ignored (stop() first). */ start(options: DrengrOptions): void; /** Pause/resume capture (consent gate). Delivery of already-captured events continues. */ setEnabled(v: boolean): void; /** Persistently opt this install OUT of capture (GDPR). Unlike setEnabled(false), * this survives restart: it writes the opt-out flag to storage AND pauses now, so * start() reads it and stays paused on the next launch. */ optOut(): void; /** Reverse optOut(): clear the persisted flag and resume capture. */ optIn(): void; /** Flush the queue now (e.g. before navigation). Best-effort. */ flush(): Promise; /** Sets external_id (your own stable, non-PII user id — not an email) on the * session and all events hereafter; emits one identify event. traits are * redacted before delivery. Fail-open: no-op if start() hasn't run or * externalId is empty. */ identify(externalId: string, traits?: Record): void; /** Tags the session with an experiment variant, attached to all events * hereafter as `experiments`. Pass a null/empty variant to clear the key. */ setExperiment(key: string, variant: string | null): void; /** Uninstall capture, restoring the runtime's own fetch/XHR + History API. */ stop(): void; };