import { AsyncLocalStorage } from 'node:async_hooks'; /** * The actor for the current request, used by the Prisma audit extension to * attribute database mutations. Populated in `hooks.server.ts`. */ export type AuditContext = { userId: string | null; email: string | null; roleId: number | null; page: string; ip: string | null; }; const storage = new AsyncLocalStorage(); export function runWithAuditContext(context: AuditContext, fn: () => T): T { return storage.run(context, fn); } export function getAuditContext(): AuditContext | undefined { return storage.getStore(); }