/** * 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 } } }); }