From 06f9c2cb5bdc267dcae3ac5a21d7e8814284332e Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 13 Sep 2025 22:46:30 +0200 Subject: [PATCH] Align `sendEmail` and `sendEmailTask` with updated `BaseEmail` typing - Refactor `sendEmail` to return extended type with `id` for better type inference. - Update `sendEmailTask` to use `BaseEmail` instead of `Email`. - Add `outputSchema` in `sendEmailTask` for consistent output structure. --- src/jobs/sendEmailTask.ts | 19 ++++++++++--------- src/sendEmail.ts | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) 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