import { auditLog, type DB, type NewAuditLogEntry } from "@cmbot/db"; export type AuditInput = { operatorId: string | null; source: "web" | "telegram" | "system"; action: string; targetType?: string | null; targetId?: string | null; payload?: Record; }; export async function writeAuditLog(db: DB, input: AuditInput): Promise { const row: NewAuditLogEntry = { operatorId: input.operatorId, source: input.source, action: input.action, targetType: input.targetType ?? null, targetId: input.targetId ?? null, payload: input.payload ?? {}, }; await db.insert(auditLog).values(row); }