TypeScript 97.5%
SQL 1.4%
Python 0.8%
1import "server-only";2import { getDb, auditLogs } from "@fetcha/db";3import { newId } from "@fetcha/core";45export type AuditAction =6 | "account.created"7 | "login"8 | "logout"9 | "email.verified"10 | "password.changed"11 | "password.reset"12 | "email.changed"13 | "account.deleted"14 | "api_key.created"15 | "api_key.revoked"16 | "api_key.rotated"17 | "project.created"18 | "project.updated"19 | "project.archived"20 | "billing.changed"21 | "webhook.modified"22 | "limits.updated"23 | "session.revoked"24 | "admin.action";2526export async function writeAudit(input: {27 userId?: string | null;28 organizationId?: string | null;29 action: AuditAction;30 target?: string | null;31 metadata?: Record<string, unknown>;32 ipAddress?: string | null;33 userAgent?: string | null;34}): Promise<void> {35 try {36 await getDb().insert(auditLogs).values({37 id: newId("aud"),38 userId: input.userId ?? null,39 organizationId: input.organizationId ?? null,40 action: input.action,41 target: input.target ?? null,42 metadata: input.metadata ?? null,43 ipAddress: input.ipAddress ?? null,44 userAgent: input.userAgent ?? null,45 });46 } catch (e) {47 console.error("[audit] failed", (e as Error).message);48 }49}50