From 8809db6aff26ea0335cb5c633c9038d7eb9b8efc Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 23:27:53 +0200 Subject: [PATCH 1/3] Add null value support to BaseEmailDocument interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update BaseEmailDocument to support `| null` for optional fields (cc, bcc, from, replyTo, text, etc.) - Update BaseEmailTemplateDocument to support `| null` for optional fields - Add explicit null checks in sendEmail processing to handle null values properly - Update CUSTOM-TYPES.md documentation to reflect null value compatibility Fixes type constraint error where customer Email types had `cc?: string[] | null` but BaseEmailDocument only supported `cc?: string[]`. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CUSTOM-TYPES.md | 44 +++++++++++++++++++++++--------------------- src/sendEmail.ts | 4 ++-- src/types/index.ts | 38 +++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/CUSTOM-TYPES.md b/CUSTOM-TYPES.md index 7595440..5dafa06 100644 --- a/CUSTOM-TYPES.md +++ b/CUSTOM-TYPES.md @@ -38,13 +38,15 @@ const customEmail = await sendEmail(payload, { }) ``` -## ID Type Compatibility +## Compatibility -The plugin works with both: +The plugin works with: - **String IDs**: `id: string` - **Number IDs**: `id: number` +- **Nullable fields**: Fields can be `null`, `undefined`, or have values +- **Generated types**: Works with `payload generate:types` output -Your Payload configuration determines which type is used. The plugin automatically adapts to your setup. +Your Payload configuration determines which types are used. The plugin automatically adapts to your setup. ## Type Definitions @@ -55,33 +57,33 @@ interface BaseEmailDocument { id: string | number template?: any 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 - status?: 'pending' | 'processing' | 'sent' | 'failed' - attempts?: number - lastAttemptAt?: string - error?: string - priority?: number - createdAt?: string - updatedAt?: string + text?: string | null + variables?: Record | null + scheduledAt?: string | null + sentAt?: string | null + status?: 'pending' | 'processing' | 'sent' | 'failed' | null + attempts?: number | null + lastAttemptAt?: string | null + error?: string | null + priority?: number | null + createdAt?: string | null + updatedAt?: string | null } interface BaseEmailTemplateDocument { id: string | number name: string slug: string - subject?: string + subject?: string | null content?: any - createdAt?: string - updatedAt?: string + createdAt?: string | null + updatedAt?: string | null } ``` diff --git a/src/sendEmail.ts b/src/sendEmail.ts index 63452b4..9a8136c 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -83,10 +83,10 @@ export const sendEmail = async - scheduledAt?: string - sentAt?: string - status?: 'pending' | 'processing' | 'sent' | 'failed' - attempts?: number - lastAttemptAt?: string - error?: string - priority?: number - createdAt?: string - updatedAt?: string + text?: string | null + variables?: Record | null + scheduledAt?: string | null + sentAt?: string | null + status?: 'pending' | 'processing' | 'sent' | 'failed' | null + attempts?: number | null + lastAttemptAt?: string | null + error?: string | null + priority?: number | null + createdAt?: string | null + updatedAt?: string | null } export interface BaseEmailTemplateDocument { id: string | number name: string slug: string - subject?: string + subject?: string | null content?: any - createdAt?: string - updatedAt?: string + createdAt?: string | null + updatedAt?: string | null } export type BaseEmail = Omit & {template: Omit | TEmailTemplate['id'] | undefined | null} From a959673fc1f20d6625286ecbca74949ec8fa6a5a Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 23:31:23 +0200 Subject: [PATCH 2/3] Bump package version to 0.1.14 in `package.json`. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af14f2c..5c68b02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-mailing", - "version": "0.1.13", + "version": "0.1.14", "description": "Template-based email system with scheduling and job processing for PayloadCMS", "type": "module", "main": "dist/index.js", 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 3/3] 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 }