( event: IResendEventBase )
| 210 | * so route handlers can include it in the ACK response. |
| 211 | */ |
| 212 | export const applyResendEvent = async ( |
| 213 | event: IResendEventBase |
| 214 | ): Promise<number> => { |
| 215 | const reason = resendEventToReason(event); |
| 216 | |
| 217 | if (reason === null) { |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | const email = extractRecipient(event); |
| 222 | |
| 223 | if (email === null) { |
| 224 | logger.warn("Resend deliverability event without recipient address", { |
| 225 | event: "webhook.resend.recipient_missing", |
| 226 | type: event.type, |
| 227 | }); |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | const input: IRecordSuppressionInput = { |
| 233 | email, |
| 234 | reason, |
| 235 | provider: EMAIL_SUPPRESSION_PROVIDERS.RESEND, |
| 236 | providerMessageId: event.data?.email_id ?? undefined, |
| 237 | metadata: { |
| 238 | type: event.type, |
| 239 | bounceType: event.data?.bounce?.type ?? null, |
| 240 | bounceMessage: event.data?.bounce?.message ?? null, |
| 241 | }, |
| 242 | }; |
| 243 | const result = await emailSuppressionService.record(input); |
| 244 | |
| 245 | return result.recorded ? 1 : 0; |
| 246 | }; |
no test coverage detected