SPB Git

Repository Public

audit.ts 665 B 10 lines typescript

1import { j, sql, type Tx } from "./db";23export interface AuditInput { userId?: string | null; actor: "admin" | "visitor" | "system"; action: string; entity?: string; entityId?: string; meta?: Record<string, unknown>; ip?: string | null }45/** Audit trail. `meta` must never contain reasons, answers or other free text typed by a visitor. */6export async function audit(a: AuditInput, tx: Tx | typeof sql = sql): Promise<void> {7  await tx`INSERT INTO audit_events (user_id, actor, action, entity, entity_id, meta, ip)8           VALUES (${a.userId ?? null}, ${a.actor}, ${a.action}, ${a.entity ?? ""}, ${a.entityId ?? ""}, ${j(a.meta ?? {})}, ${a.ip ?? null})`;9}10
Files main
Menu

Theme