mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 08:13:23 +00:00
Merge pull request #23 from xtr-dev/dev
Fix TypeScript compatibility with PayloadCMS generated types
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/payload-mailing",
|
"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",
|
"description": "Template-based email system with scheduling and job processing for PayloadCMS",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@@ -2,15 +2,16 @@ import { Payload } from 'payload'
|
|||||||
import { getMailing, renderTemplate, parseAndValidateEmails } from './utils/helpers.js'
|
import { getMailing, renderTemplate, parseAndValidateEmails } from './utils/helpers.js'
|
||||||
|
|
||||||
// Base type for email data that all emails must have
|
// Base type for email data that all emails must have
|
||||||
|
// Compatible with PayloadCMS generated types that include null
|
||||||
export interface BaseEmailData {
|
export interface BaseEmailData {
|
||||||
to: string | string[]
|
to: string | string[]
|
||||||
cc?: string | string[]
|
cc?: string | string[] | null
|
||||||
bcc?: string | string[]
|
bcc?: string | string[] | null
|
||||||
subject?: string
|
subject?: string | null
|
||||||
html?: string
|
html?: string | null
|
||||||
text?: string
|
text?: string | null
|
||||||
scheduledAt?: string | Date
|
scheduledAt?: string | Date | null
|
||||||
priority?: number
|
priority?: number | null
|
||||||
[key: string]: any
|
[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')
|
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) {
|
if (emailData.to) {
|
||||||
emailData.to = parseAndValidateEmails(emailData.to as string | string[])
|
emailData.to = parseAndValidateEmails(emailData.to as string | string[])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { TemplateVariables } from '../types/index.js'
|
|||||||
* Parse and validate email addresses
|
* Parse and validate email addresses
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export const parseAndValidateEmails = (emails: string | string[] | undefined): string[] | undefined => {
|
export const parseAndValidateEmails = (emails: string | string[] | null | undefined): string[] | undefined => {
|
||||||
if (!emails) return undefined
|
if (!emails || emails === null) return undefined
|
||||||
|
|
||||||
let emailList: string[]
|
let emailList: string[]
|
||||||
if (Array.isArray(emails)) {
|
if (Array.isArray(emails)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user