UNPKG

@unchainedshop/events

Version:

Event emitter abstraction layer for the Unchained Engine

96 lines (95 loc) 2.81 kB
import { type OCSFEvent, OCSF_AUTH_ACTIVITY, OCSF_ACCOUNT_ACTIVITY, OCSF_API_ACTIVITY } from './ocsf-types.ts'; export * from './ocsf-types.ts'; export interface AuditLogConfig { directory?: string; collectorUrl?: string; collectorHeaders?: Record<string, string>; batchSize?: number; flushIntervalMs?: number; } export interface AuthenticationInput { activity: (typeof OCSF_AUTH_ACTIVITY)[keyof typeof OCSF_AUTH_ACTIVITY]; userId?: string; userName?: string; success?: boolean; remoteAddress?: string; sessionId?: string; message?: string; isMfa?: boolean; authProtocol?: string; } export interface AccountChangeInput { activity: (typeof OCSF_ACCOUNT_ACTIVITY)[keyof typeof OCSF_ACCOUNT_ACTIVITY]; userId?: string; userName?: string; success?: boolean; remoteAddress?: string; sessionId?: string; message?: string; actorUserId?: string; actorUserName?: string; } export interface ApiActivityInput { activity: (typeof OCSF_API_ACTIVITY)[keyof typeof OCSF_API_ACTIVITY]; userId?: string; userName?: string; success?: boolean; remoteAddress?: string; sessionId?: string; message?: string; operation?: string; httpMethod?: string; path?: string; responseCode?: number; } export interface AuditLogQuery { classUids?: number[]; activityIds?: number[]; userId?: string; success?: boolean; startTime?: Date; endTime?: Date; limit?: number; offset?: number; } export interface VerifyResult { valid: boolean; entries: number; verified: number; error?: string; } export declare class AuditLog { private readonly dir; private readonly collectorUrl?; private readonly collectorHeaders; private readonly batchSize; private readonly flushIntervalMs; private lastEvent; private writeLock; private initialized; private pendingEvents; private flushTimer?; constructor(config?: AuditLogConfig); private getFilePath; private init; private computeHash; private createMetadata; private createUser; private createEndpoint; private writeEvent; private flushToCollector; private matches; logAuthentication(input: AuthenticationInput): Promise<string>; logAccountChange(input: AccountChangeInput): Promise<string>; logApiActivity(input: ApiActivityInput): Promise<string>; find(query?: AuditLogQuery): Promise<OCSFEvent[]>; count(query?: AuditLogQuery): Promise<number>; getFailedLogins(params: { userId?: string; remoteAddress?: string; since?: Date; }): Promise<number>; verify(): Promise<VerifyResult>; close(): Promise<void>; } export declare function createAuditLog(config?: AuditLogConfig | string): AuditLog;