mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 16:23:23 +00:00
Support custom ID types (string/number) for improved compatibility
- Replace hardcoded payload-types imports with generic BaseEmailDocument interface - Update sendEmail and sendEmailTask to work with both string and number IDs - Refactor MailingService to use generic document types instead of specific ones - Add BaseEmailDocument and BaseEmailTemplateDocument interfaces supporting id: string | number - Export BaseEmailDocument for users to extend with their custom fields - Fix TypeScript compilation error in template subject handling - Add CUSTOM-TYPES.md documentation for users with different ID types Fixes compatibility issue where plugin required number IDs but user projects used string IDs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,32 @@
|
||||
import { Payload } from 'payload'
|
||||
import { getMailing, renderTemplate, parseAndValidateEmails } from './utils/helpers.js'
|
||||
import {Email, EmailTemplate} from "./payload-types.js"
|
||||
|
||||
// Generic email interface that can work with any ID type
|
||||
export interface BaseEmailDocument {
|
||||
id: string | number
|
||||
template?: any
|
||||
to: string[]
|
||||
cc?: string[]
|
||||
bcc?: string[]
|
||||
from?: string
|
||||
replyTo?: string
|
||||
subject: string
|
||||
html: string
|
||||
text?: string
|
||||
variables?: Record<string, any>
|
||||
scheduledAt?: string
|
||||
sentAt?: string
|
||||
status?: 'pending' | 'processing' | 'sent' | 'failed'
|
||||
attempts?: number
|
||||
lastAttemptAt?: string
|
||||
error?: string
|
||||
priority?: number
|
||||
createdAt?: string
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
// Options for sending emails
|
||||
export interface SendEmailOptions<T extends Email = Email> {
|
||||
export interface SendEmailOptions<T extends BaseEmailDocument = BaseEmailDocument> {
|
||||
// Template-based email
|
||||
template?: {
|
||||
slug: string
|
||||
@@ -35,7 +58,7 @@ export interface SendEmailOptions<T extends Email = Email> {
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export const sendEmail = async <TEmail extends Email = Email>(
|
||||
export const sendEmail = async <TEmail extends BaseEmailDocument = BaseEmailDocument>(
|
||||
payload: Payload,
|
||||
options: SendEmailOptions<TEmail>
|
||||
): Promise<TEmail> => {
|
||||
|
||||
Reference in New Issue
Block a user