feat: add full-stack API persistence and RBAC

This commit is contained in:
2026-07-01 06:28:18 -07:00
parent aafd9caaac
commit 914f74c5cc
18 changed files with 1148 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { randomUUID } from "node:crypto";
import type { AuditLog, AuditResult, PublicAccount } from "@/modules/core/types";
import { updateData } from "@/modules/core/server/store";
type AuditInput = {
actor?: PublicAccount;
action: string;
targetType: string;
targetId?: string;
result: AuditResult;
reason: string;
};
export async function recordAuditLog(input: AuditInput): Promise<AuditLog> {
const timestamp = new Date().toISOString();
return await updateData((data) => {
const nextLog: AuditLog = {
id: randomUUID(),
timestamp,
actorAccountId: input.actor?.id,
actorEmail: input.actor?.email,
action: input.action,
targetType: input.targetType,
targetId: input.targetId,
result: input.result,
reason: input.reason,
};
data.auditLogs = [nextLog, ...data.auditLogs].slice(0, 500);
return nextLog;
});
}