feat: add full-stack API persistence and RBAC
This commit is contained in:
35
modules/core/server/audit.ts
Normal file
35
modules/core/server/audit.ts
Normal 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;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user