import type { Db } from "../db.js"; import { nowIso } from "../db.js"; import { newId, ID_PREFIX } from "./ids.js"; /** Zapis istotnego działania do audit_log — wywoływać wewnątrz transakcji domenowej. */ export function audit( db: Db, input: { actor: string; action: string; entity: string; entityId: string; detail?: Record; } ): void { db.prepare( `INSERT INTO audit_log (id, actor, action, entity, entity_id, detail_json, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)` ).run( newId(ID_PREFIX.audit), input.actor, input.action, input.entity, input.entityId, JSON.stringify(input.detail ?? {}), nowIso() ); }