2024-09-30 17:11:01 +00:00
|
|
|
import {AuditEvent, AuditEventContext, AuditEventDetails, AuditEventName, AuditEventUser} from 'app/common/AuditEvent';
|
2024-09-23 15:04:22 +00:00
|
|
|
import {RequestOrSession} from 'app/server/lib/sessionUtils';
|
2024-09-09 20:04:21 +00:00
|
|
|
|
|
|
|
export interface IAuditLogger {
|
|
|
|
/**
|
|
|
|
* Logs an audit event.
|
|
|
|
*/
|
|
|
|
logEvent<Name extends AuditEventName>(
|
|
|
|
requestOrSession: RequestOrSession,
|
2024-09-23 15:04:22 +00:00
|
|
|
properties: AuditEventProperties<Name>
|
2024-09-09 20:04:21 +00:00
|
|
|
): void;
|
|
|
|
/**
|
2024-09-23 15:04:22 +00:00
|
|
|
* Logs an audit event.
|
2024-09-09 20:04:21 +00:00
|
|
|
*
|
2024-09-23 15:04:22 +00:00
|
|
|
* Throws a `LogAuditEventError` on failure.
|
2024-09-09 20:04:21 +00:00
|
|
|
*/
|
|
|
|
logEventAsync<Name extends AuditEventName>(
|
|
|
|
requestOrSession: RequestOrSession,
|
2024-09-23 15:04:22 +00:00
|
|
|
properties: AuditEventProperties<Name>
|
2024-09-09 20:04:21 +00:00
|
|
|
): Promise<void>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AuditEventProperties<Name extends AuditEventName> {
|
|
|
|
event: {
|
|
|
|
/**
|
2024-09-30 17:11:01 +00:00
|
|
|
* The name of the event.
|
2024-09-09 20:04:21 +00:00
|
|
|
*/
|
|
|
|
name: Name;
|
|
|
|
/**
|
2024-09-30 17:11:01 +00:00
|
|
|
* Event-specific details (e.g. properties of affected resources).
|
2024-09-09 20:04:21 +00:00
|
|
|
*/
|
|
|
|
details?: AuditEventDetails[Name];
|
2024-09-23 15:04:22 +00:00
|
|
|
/**
|
2024-09-30 17:11:01 +00:00
|
|
|
* The context that the event occurred in (e.g. workspace, document).
|
2024-09-23 15:04:22 +00:00
|
|
|
*/
|
|
|
|
context?: AuditEventContext;
|
2024-09-30 17:11:01 +00:00
|
|
|
/**
|
|
|
|
* The user that triggered the event.
|
|
|
|
*/
|
|
|
|
user?: AuditEventUser;
|
2024-09-09 20:04:21 +00:00
|
|
|
};
|
|
|
|
/**
|
2024-09-30 17:11:01 +00:00
|
|
|
* ISO 8601 timestamp (e.g. `2024-09-04T14:54:50Z`) of when the event occurred.
|
2024-09-09 20:04:21 +00:00
|
|
|
*
|
|
|
|
* Defaults to now.
|
|
|
|
*/
|
|
|
|
timestamp?: string;
|
|
|
|
}
|
2024-09-23 15:04:22 +00:00
|
|
|
|
|
|
|
export class LogAuditEventError<Name extends AuditEventName> extends Error {
|
|
|
|
public name = 'LogAuditEventError';
|
|
|
|
|
|
|
|
constructor(public auditEvent: AuditEvent<Name>, ...params: any[]) {
|
|
|
|
super(...params);
|
|
|
|
|
|
|
|
if (Error.captureStackTrace) {
|
|
|
|
Error.captureStackTrace(this, LogAuditEventError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|