initial commit
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic08e7c4b5b4f4072de9e2f9a701e977b6a6a6964
This commit is contained in:
commit
f8db097ba9
21 changed files with 4924 additions and 0 deletions
40
src/events.ts
Normal file
40
src/events.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue