Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic08e7c4b5b4f4072de9e2f9a701e977b6a6a6964
40 lines
784 B
TypeScript
40 lines
784 B
TypeScript
import type { WebhookEvent, AnalysisResult } from './types.js';
|
|
|
|
export interface EventEntry {
|
|
id: number;
|
|
timestamp: string;
|
|
event: WebhookEvent;
|
|
result: Record<string, unknown>;
|
|
analysis?: AnalysisResult;
|
|
}
|
|
|
|
const MAX_ENTRIES = 100;
|
|
const buffer: EventEntry[] = [];
|
|
let nextId = 1;
|
|
|
|
export function recordEvent(
|
|
event: WebhookEvent,
|
|
result: Record<string, unknown>,
|
|
analysis?: AnalysisResult
|
|
): void {
|
|
const entry: EventEntry = {
|
|
id: nextId++,
|
|
timestamp: new Date().toISOString(),
|
|
event,
|
|
result,
|
|
analysis,
|
|
};
|
|
|
|
buffer.push(entry);
|
|
if (buffer.length > MAX_ENTRIES) {
|
|
buffer.shift();
|
|
}
|
|
}
|
|
|
|
export function getRecentEvents(): EventEntry[] {
|
|
return [...buffer].reverse();
|
|
}
|
|
|
|
export function clearEvents(): void {
|
|
buffer.length = 0;
|
|
}
|