18 lines
556 B
TypeScript
18 lines
556 B
TypeScript
import { storage } from '../../lib/storage.js';
|
|
import { AuditEvent } from '../../core/types.js';
|
|
|
|
const AUDIT_FILE = 'audit-events.json';
|
|
|
|
export class AuditService {
|
|
async record(event: Omit<AuditEvent, 'id' | 'createdAt'>): Promise<AuditEvent> {
|
|
const events = await storage.readCollection<AuditEvent>(AUDIT_FILE);
|
|
const entry: AuditEvent = {
|
|
id: crypto.randomUUID(),
|
|
createdAt: new Date().toISOString(),
|
|
...event,
|
|
};
|
|
events.push(entry);
|
|
await storage.writeCollection(AUDIT_FILE, events);
|
|
return entry;
|
|
}
|
|
}
|