import { sqlWrapper } from "./db.ts"; /** * SIDE EFFECT: Asynchronously logs an audit record to the database. * Does not block the main execution thread. Errors are logged but swallowed * to prevent failing the core request due to a logging issue. */ export let auditLog = function auditLog( userId: string | null, action: string, resource: string | null, details: Record | null, ipAddress: string, ): void { // Fire and forget sqlWrapper.sql` INSERT INTO audit_records (user_id, action, resource, details, ip_address) VALUES (${userId}, ${action}, ${resource}, ${ details ? JSON.stringify(details) : null }, ${ipAddress}) `.catch((error: any) => { console.error("[Audit Logger] Failed to insert audit record:", error); }); }; export const auditWrapper = { get auditLog() { return auditLog; }, set auditLog(val: any) { auditLog = val; }, };