import {AuditEvent, AuditEventContext, AuditEventDetails, AuditEventName} from 'app/common/AuditEvent'; import {RequestOrSession} from 'app/server/lib/sessionUtils'; export interface IAuditLogger { /** * Logs an audit event. */ logEvent( requestOrSession: RequestOrSession, properties: AuditEventProperties ): void; /** * Logs an audit event. * * Throws a `LogAuditEventError` on failure. */ logEventAsync( requestOrSession: RequestOrSession, properties: AuditEventProperties ): Promise; } export interface AuditEventProperties { event: { /** * The event name. */ name: Name; /** * Additional event details. */ details?: AuditEventDetails[Name]; /** * The context of the event. */ context?: AuditEventContext; }; /** * ISO 8601 timestamp (e.g. `2024-09-04T14:54:50Z`) of when the event occured. * * Defaults to now. */ timestamp?: string; } export class LogAuditEventError extends Error { public name = 'LogAuditEventError'; constructor(public auditEvent: AuditEvent, ...params: any[]) { super(...params); if (Error.captureStackTrace) { Error.captureStackTrace(this, LogAuditEventError); } } }