Merge pull request #23 from xtr-dev/dev

Fix TypeScript compatibility with PayloadCMS generated types
This commit is contained in:
Bas
2025-09-13 21:10:09 +02:00
committed by GitHub
3 changed files with 13 additions and 12 deletions

View File

@@ -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",

View File

@@ -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 <T extends BaseEmailData = BaseEmailData>(
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 <T extends BaseEmailData = BaseEmailData>(
return email as unknown as T
}
export default sendEmail
export default sendEmail

View File

@@ -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)) {