/** * Persistent audit sink implementations. * * An AuditSink is any object that durably records an AuditLogEntry outside * the current process. The SDK calls `write()` after every policy decision; * failures are caught so they never block runtime traffic. * * Built-in implementations: * - NoopAuditSink — discards all entries (default / test) * - FileAuditSink — appends NDJSON lines to a local file * - CompositeAuditSink — fans out to multiple sinks in parallel * * Custom sinks (database, cloud logging, SIEM, …) must implement AuditSink. */ import type { AuditLogEntry } from "./types"; export interface AuditSink { /** * Durably write one audit log entry. * Implementations MUST be idempotent (entries may be replayed on retry). * Implementations MUST NOT throw; catch and handle all errors internally. */ write(entry: AuditLogEntry): Promise; /** * Optional: flush any buffered entries before process exit. * Called by AIGuardSDK.shutdown(). */ flush?(): Promise; } /** * Discards all entries. Used in development and tests when no persistence * is required. */ export declare class NoopAuditSink implements AuditSink { write(_entry: AuditLogEntry): Promise; } export type FileAuditSinkOptions = { /** Absolute path to the NDJSON log file. */ filePath: string; /** * If true, a failed write is retried once after a short delay. * Default: true */ retryOnError?: boolean; /** * Callback invoked when a write permanently fails (after any retry). * Default: writes to stderr. */ onError?: (error: unknown, entry: AuditLogEntry) => void; }; /** * Appends one NDJSON line per audit entry to a local file. * Survives process restarts: entries are flushed to disk on every `write()`. * * Usage: * const sdk = new AIGuardSDK({ * auditSink: new FileAuditSink({ filePath: "/var/log/ai-guard-audit.ndjson" }), * }); */ export declare class FileAuditSink implements AuditSink { private readonly filePath; private readonly retryOnError; private readonly onError; constructor(options: FileAuditSinkOptions); write(entry: AuditLogEntry): Promise; } /** * Fans out writes to multiple sinks in parallel. * Failures in one sink do not prevent writes to others. * * Usage: * const sdk = new AIGuardSDK({ * auditSink: new CompositeAuditSink([ * new FileAuditSink({ filePath: "/var/log/ai-guard-audit.ndjson" }), * new MySiemSink(), * ]), * }); */ export declare class CompositeAuditSink implements AuditSink { private readonly sinks; constructor(sinks: AuditSink[]); write(entry: AuditLogEntry): Promise; flush(): Promise; } export type WebhookAuditSinkOptions = { url: string; headers?: Record; timeoutMs?: number; onError?: (error: unknown, entry: AuditLogEntry) => void; }; /** * Sends each audit entry to an external HTTP webhook endpoint. */ export declare class WebhookAuditSink implements AuditSink { private readonly url; private readonly headers; private readonly timeoutMs; private readonly onError; constructor(options: WebhookAuditSinkOptions); write(entry: AuditLogEntry): Promise; } export type DatadogAuditSinkOptions = { apiKey: string; site?: string; service?: string; source?: string; tags?: readonly string[]; timeoutMs?: number; onError?: (error: unknown, entry: AuditLogEntry) => void; }; /** * Sends audit entries to Datadog Logs HTTP intake. */ export declare class DatadogAuditSink implements AuditSink { private readonly intakeUrl; private readonly apiKey; private readonly service; private readonly source; private readonly tags; private readonly timeoutMs; private readonly onError; constructor(options: DatadogAuditSinkOptions); write(entry: AuditLogEntry): Promise; }