datewise/app/lib/audit.server.ts
metatroncubeswdev c102594ca5 feat(security): log staff access to customers' personal data
DataAccessLog records bookings list/view/export and run-sheet views (actor, action,
target, time); pruned after 12 months by the worker; migration 0003.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 13:18:44 -04:00

18 lines
783 B
TypeScript

/**
* Access log for customers' personal data (protected customer data requirement: "log access to personal data").
* Never blocks the request: a failed write is reported and the page still loads.
*/
import prisma from "../db.server";
export function logAccess(shopId: string, actor: string, action: string, target?: string | null) {
prisma.dataAccessLog
.create({ data: { shopId, actor, action, target: target ?? null } })
.catch((e: unknown) => console.error("access log write failed", action, e));
}
/** Keep access logs for 12 months. Called by the worker. */
export async function pruneAccessLogs(now = new Date()) {
const cutoff = new Date(now.getTime() - 365 * 24 * 3600 * 1000);
return prisma.dataAccessLog.deleteMany({ where: { at: { lt: cutoff } } });
}