From e1800f5a6eb5dea0f489f523934a8dc0a03bb264 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 21:03:21 +0200 Subject: [PATCH 1/3] Fix TypeScript compatibility with PayloadCMS generated types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: TS2344: Type Email does not satisfy the constraint BaseEmailData - Add null support to BaseEmailData interface for all optional fields - Update parseAndValidateEmails to handle null values - Update sendEmail validation to properly check for null values - Maintain compatibility with PayloadCMS generated types that include null Generated Email types like cc?: string[] | null | undefined now work correctly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/sendEmail.ts | 23 ++++++++++++----------- src/utils/helpers.ts | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/sendEmail.ts b/src/sendEmail.ts index 7f514de..a61783b 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -2,15 +2,16 @@ import { Payload } from 'payload' import { getMailing, renderTemplate, parseAndValidateEmails } from './utils/helpers.js' // Base type for email data that all emails must have +// Compatible with PayloadCMS generated types that include null export interface BaseEmailData { to: string | string[] - cc?: string | string[] - bcc?: string | string[] - subject?: string - html?: string - text?: string - scheduledAt?: string | Date - priority?: number + cc?: string | string[] | null + bcc?: string | string[] | null + subject?: string | null + html?: string | null + text?: string | null + scheduledAt?: string | Date | null + priority?: number | null [key: string]: any } @@ -78,18 +79,18 @@ export const sendEmail = async ( throw new Error('Field "to" is required for sending emails') } - if (!emailData.subject || !emailData.html) { + if (!emailData.subject || emailData.subject === null || !emailData.html || emailData.html === null) { throw new Error('Fields "subject" and "html" are required when not using a template') } - // Process email addresses using shared validation + // Process email addresses using shared validation (handle null values) if (emailData.to) { emailData.to = parseAndValidateEmails(emailData.to as string | string[]) } - if (emailData.cc) { + if (emailData.cc && emailData.cc !== null) { emailData.cc = parseAndValidateEmails(emailData.cc as string | string[]) } - if (emailData.bcc) { + if (emailData.bcc && emailData.bcc !== null) { emailData.bcc = parseAndValidateEmails(emailData.bcc as string | string[]) } diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index deec373..4c6b005 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -5,8 +5,8 @@ import { TemplateVariables } from '../types/index.js' * Parse and validate email addresses * @internal */ -export const parseAndValidateEmails = (emails: string | string[] | undefined): string[] | undefined => { - if (!emails) return undefined +export const parseAndValidateEmails = (emails: string | string[] | null | undefined): string[] | undefined => { + if (!emails || emails === null) return undefined let emailList: string[] if (Array.isArray(emails)) { From b342f32d97f30b9de2d9a325efaa4a3d7409f237 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 21:06:54 +0200 Subject: [PATCH 2/3] Simplify null checks in sendEmail validation logic --- src/sendEmail.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sendEmail.ts b/src/sendEmail.ts index a61783b..ce360a7 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -79,7 +79,7 @@ export const sendEmail = async ( throw new Error('Field "to" is required for sending emails') } - if (!emailData.subject || emailData.subject === null || !emailData.html || emailData.html === null) { + if (!emailData.subject || !emailData.html) { throw new Error('Fields "subject" and "html" are required when not using a template') } @@ -87,10 +87,10 @@ export const sendEmail = async ( if (emailData.to) { emailData.to = parseAndValidateEmails(emailData.to as string | string[]) } - if (emailData.cc && emailData.cc !== null) { + if (emailData.cc) { emailData.cc = parseAndValidateEmails(emailData.cc as string | string[]) } - if (emailData.bcc && emailData.bcc !== null) { + if (emailData.bcc) { emailData.bcc = parseAndValidateEmails(emailData.bcc as string | string[]) } @@ -108,4 +108,4 @@ export const sendEmail = async ( return email as unknown as T } -export default sendEmail \ No newline at end of file +export default sendEmail From a27481c818f826408403ed227359ce3cf83d3f3d Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 21:07:22 +0200 Subject: [PATCH 3/3] Bump package version to 0.1.7 in `package.json`. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 64734c0..0910a4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-mailing", - "version": "0.1.6", + "version": "0.1.7", "description": "Template-based email system with scheduling and job processing for PayloadCMS", "type": "module", "main": "dist/index.js",