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", diff --git a/src/sendEmail.ts b/src/sendEmail.ts index 7f514de..ce360a7 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 } @@ -82,7 +83,7 @@ export const sendEmail = async ( 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[]) } @@ -107,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 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)) {