import { _ as SubscriptionEvent, g as EventsAdapter } from "../index-gRqfQZ6n.js"; //#region src/audit/index.d.ts /** * A single audit trail entry. * * Audit records are append-only: they describe an action performed on an * entity at a point in time, optionally with before/after snapshots. */ interface AuditRecord { /** Unique identifier for this audit entry */ id: string; /** Identifier of the actor who triggered the action (user, admin, API key, system, ...) */ actorId?: string; /** The action performed, e.g. 'subscription.created' */ action: string; /** Kind of entity the action targeted, e.g. 'subscription', 'plan', 'invoice' */ entityType: string; /** Identifier of the entity the action targeted */ entityId: string; /** Snapshot of the entity before the action (if available) */ before?: unknown; /** Snapshot of the entity after the action (if available) */ after?: unknown; /** When the action occurred */ occurredAt: Date; /** Free-form extra context (request id, tenant id, ip, ...) */ metadata?: Record; } /** * Filter for listing audit records. */ interface AuditFilter { /** Only records for this entity type */ entityType?: string; /** Only records for this entity id */ entityId?: string; /** Maximum number of records to return */ limit?: number; /** Number of records to skip (for pagination) */ offset?: number; } /** * Audit log adapter interface. * * Implement this interface to persist audit records to your own storage * (database table, log service, data warehouse, ...). Append-only by design. */ interface AuditLogAdapter { /** * Append a record to the audit log. Implementations must not mutate * the passed record and should treat the log as append-only. */ append(record: AuditRecord): Promise; /** * List audit records matching a filter (most recent first). * Optional — omit if the backing store does not support querying. */ list?(filter: AuditFilter): Promise; } /** * In-memory audit log adapter, for tests and development. * * Keeps records in a plain array (newest first in `list()` results). * Not suitable for production: records are lost on restart and grow * unbounded in memory. */ declare function memoryAuditLogAdapter(): AuditLogAdapter; /** * Options for {@link createAuditLogger}. */ interface AuditLoggerOptions { /** * Actor attribution for generated audit records: * - a static string applied to every record, or * - a function deriving the actor id from each event (e.g. from * `event.data.actorId` or a header captured in the event payload). * * Omit to leave `actorId` unset. */ actorId?: string | ((event: SubscriptionEvent) => string | undefined); } /** * Create an {@link EventsAdapter} that writes every subscription event to an * {@link AuditLogAdapter}. Plug it into the events bus alongside (or instead * of) your other listeners. * * Event → audit record mapping: * * | AuditRecord field | Source | * |-------------------|---------------------------------------------------------------| * | `id` | `event.id` | * | `actorId` | `options.actorId` (static value or derived from the event) | * | `action` | `event.type` (e.g. 'subscription.created') | * | `entityType` | prefix of `event.type` before the first '.' (e.g. 'subscription'); falls back to 'unknown' | * | `entityId` | `event.data.id` (stringified) ?? `event.subscriberId` ?? 'unknown' | * | `before` | (unset — events carry no prior snapshot) | * | `after` | `event.data` | * | `occurredAt` | `event.occurredAt` | * | `metadata` | (unset) | * * Append failures are swallowed and logged to `console.error` so a broken * audit sink never breaks the subscription flow itself. */ declare function createAuditLogger(adapter: AuditLogAdapter, options?: AuditLoggerOptions): EventsAdapter; //#endregion export { AuditFilter, AuditLogAdapter, AuditLoggerOptions, AuditRecord, type EventsAdapter, type SubscriptionEvent, createAuditLogger, memoryAuditLogAdapter }; //# sourceMappingURL=index.d.ts.map