diff --git a/package.json b/package.json index 1c4829a..7dce23a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-mailing", - "version": "0.1.10", + "version": "0.1.11", "description": "Template-based email system with scheduling and job processing for PayloadCMS", "type": "module", "main": "dist/index.js", diff --git a/src/jobs/sendEmailTask.ts b/src/jobs/sendEmailTask.ts index 55cd15c..0c808af 100644 --- a/src/jobs/sendEmailTask.ts +++ b/src/jobs/sendEmailTask.ts @@ -1,5 +1,6 @@ import { sendEmail } from '../sendEmail.js' import { Email } from '../payload-types.js' +import {BaseEmail} from "../types/index.js" export interface SendEmailTaskInput { // Template mode fields @@ -116,6 +117,12 @@ export const sendEmailJob = { } } ], + outputSchema: [ + { + name: 'id', + type: 'text' as const + } + ], handler: async ({ input, payload }: any) => { // Cast input to our expected type const taskInput = input as SendEmailTaskInput @@ -154,18 +161,12 @@ export const sendEmailJob = { }) // Use the sendEmail helper to create the email - const email = await sendEmail(payload, sendEmailOptions) + const email = await sendEmail(payload, sendEmailOptions) return { output: { success: true, - emailId: email.id, - message: `Email queued successfully with ID: ${email.id}`, - mode: taskInput.templateSlug ? 'template' : 'direct', - templateSlug: taskInput.templateSlug || null, - subject: email.subject, - recipients: Array.isArray(email.to) ? email.to.length : 1, - scheduledAt: email.scheduledAt || null + id: email.id, } } @@ -176,4 +177,4 @@ export const sendEmailJob = { } } -export default sendEmailJob \ No newline at end of file +export default sendEmailJob diff --git a/src/sendEmail.ts b/src/sendEmail.ts index 0d76ade..e83052f 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -36,10 +36,10 @@ export interface SendEmailOptions { * }) * ``` */ -export const sendEmail = async ( +export const sendEmail = async ( payload: Payload, options: SendEmailOptions -): Promise => { +): Promise => { const mailing = getMailing(payload) const collectionSlug = options.collectionSlug || mailing.collections.emails || 'emails' @@ -97,7 +97,7 @@ export const sendEmail = async ( data: emailData }) - return email as T + return email as T & {id: ID} } export default sendEmail