import { db, schema } from "@/db"; /** Append-only audit entry (DB trigger forbids UPDATE/DELETE). */ export async function audit(actor: { id?: string | null; name: string }, action: string, entity?: { type: string; id: string }, details: Record = {}, ip?: string | null) { await db.insert(schema.auditLog).values({ actorId: actor.id ?? null, actor: actor.name, action, entityType: entity?.type ?? null, entityId: entity?.id ?? null, details, ip: ip ?? null }); }