From ecc0b0a73e97aebf8edd1849610168b8bda02f18 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 23:32:44 +0200 Subject: [PATCH] Fix type inconsistencies and missing null checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update QueuedEmail interface to include `| null` for optional fields to match BaseEmailDocument - Add missing null checks for replyTo and from fields in sendEmail processing - Add proper email validation for replyTo and from fields (single email addresses) - Ensure type consistency across all email-related interfaces Fixes potential type conflicts between QueuedEmail and BaseEmailDocument, and ensures all nullable email fields are properly validated. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/sendEmail.ts | 10 ++++++++++ src/types/index.ts | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/sendEmail.ts b/src/sendEmail.ts index 9a8136c..6ca74f5 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -89,6 +89,16 @@ export const sendEmail = async 0 ? validated[0] : undefined + } + if (emailData.from && emailData.from !== null) { + const validated = parseAndValidateEmails(emailData.from as string | string[]) + // from should be a single email, so take the first one if array + emailData.from = validated && validated.length > 0 ? validated[0] : undefined + } // Create the email in the collection with proper typing const email = await payload.create({ diff --git a/src/types/index.ts b/src/types/index.ts index 2e295ca..1e42760 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -75,23 +75,23 @@ export interface MailingTransportConfig { export interface QueuedEmail { id: string - template?: string + template?: string | null to: string[] - cc?: string[] - bcc?: string[] - from?: string - replyTo?: string + cc?: string[] | null + bcc?: string[] | null + from?: string | null + replyTo?: string | null subject: string html: string - text?: string - variables?: Record - scheduledAt?: string - sentAt?: string + text?: string | null + variables?: Record | null + scheduledAt?: string | null + sentAt?: string | null status: 'pending' | 'processing' | 'sent' | 'failed' attempts: number - lastAttemptAt?: string - error?: string - priority?: number + lastAttemptAt?: string | null + error?: string | null + priority?: number | null createdAt: string updatedAt: string }