From f87fd9f48d71a2104901fe241ae1fff6be7ef2b3 Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Thu, 25 Dec 2025 22:40:44 +0000 Subject: [PATCH] code: store,nextjs,log (1 files) --- .../lib/security/secure-db/audit-log-store.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 frontends/nextjs/src/lib/security/secure-db/audit-log-store.ts diff --git a/frontends/nextjs/src/lib/security/secure-db/audit-log-store.ts b/frontends/nextjs/src/lib/security/secure-db/audit-log-store.ts new file mode 100644 index 000000000..a33739e34 --- /dev/null +++ b/frontends/nextjs/src/lib/security/secure-db/audit-log-store.ts @@ -0,0 +1,32 @@ +import type { AuditLog } from './types' + +const DEFAULT_AUDIT_LOG_LIMIT = 100 +const MAX_AUDIT_LOGS = 1000 +const auditLogs: AuditLog[] = [] + +const normalizeLimit = (limit: number): number => { + if (!Number.isFinite(limit)) return DEFAULT_AUDIT_LOG_LIMIT + return Math.max(0, Math.floor(limit)) +} + +export const addAuditLog = (log: AuditLog): void => { + auditLogs.push(log) + + if (auditLogs.length > MAX_AUDIT_LOGS) { + auditLogs.splice(0, auditLogs.length - MAX_AUDIT_LOGS) + } +} + +export const listAuditLogs = (limit: number = DEFAULT_AUDIT_LOG_LIMIT): AuditLog[] => { + const normalizedLimit = normalizeLimit(limit) + if (normalizedLimit === 0) return [] + + const slice = auditLogs.slice(-normalizedLimit) + return slice.reverse() +} + +export const clearAuditLogs = (): void => { + auditLogs.length = 0 +} + +export { DEFAULT_AUDIT_LOG_LIMIT, MAX_AUDIT_LOGS }