@@ -6,6 +6,7 @@ import { getNotificationUrl, getProviderConfig } from '@/lib/webhooks/providers/
66import type {
77 AuthContext ,
88 DeleteSubscriptionContext ,
9+ EventMatchContext ,
910 FormatInputContext ,
1011 FormatInputResult ,
1112 SubscriptionContext ,
@@ -100,6 +101,35 @@ export const resendHandler: WebhookProviderHandler = {
100101 return null
101102 } ,
102103
104+ matchEvent ( { body, providerConfig, requestId } : EventMatchContext ) : boolean {
105+ const triggerId = providerConfig . triggerId as string | undefined
106+ if ( ! triggerId || triggerId === 'resend_webhook' ) {
107+ return true
108+ }
109+
110+ const EVENT_TYPE_MAP : Record < string , string > = {
111+ resend_email_sent : 'email.sent' ,
112+ resend_email_delivered : 'email.delivered' ,
113+ resend_email_bounced : 'email.bounced' ,
114+ resend_email_complained : 'email.complained' ,
115+ resend_email_opened : 'email.opened' ,
116+ resend_email_clicked : 'email.clicked' ,
117+ resend_email_failed : 'email.failed' ,
118+ }
119+
120+ const expectedType = EVENT_TYPE_MAP [ triggerId ]
121+ const actualType = ( body as Record < string , unknown > ) ?. type as string | undefined
122+
123+ if ( expectedType && actualType !== expectedType ) {
124+ logger . debug (
125+ `[${ requestId } ] Resend event type mismatch: expected ${ expectedType } , got ${ actualType } . Skipping.`
126+ )
127+ return false
128+ }
129+
130+ return true
131+ } ,
132+
103133 async formatInput ( { body } : FormatInputContext ) : Promise < FormatInputResult > {
104134 const payload = body as Record < string , unknown >
105135 const data = payload . data as Record < string , unknown > | undefined
0 commit comments