From 6536f38620a693795a7d73e79032105eebec963e Mon Sep 17 00:00:00 2001 From: Reilly Freret Date: Mon, 17 Nov 2025 17:43:29 -0500 Subject: [PATCH] adds template object to resend batch call --- src/client/index.ts | 6 +++++- src/component/lib.ts | 12 ++++++++++-- src/component/schema.ts | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/client/index.ts b/src/client/index.ts index 646b99f..2c9dfbd 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -147,6 +147,8 @@ export type SendEmailOptions = { subject: string; html?: string; text?: string; + template?: string; + variables?: Record; replyTo?: string[]; headers?: { name: string; value: string }[]; }; @@ -271,7 +273,7 @@ export class Resend { async sendEmailManually( ctx: RunMutationCtx, - options: Omit, + options: Omit, sendCallback: (emailId: EmailId) => Promise, ): Promise { const emailId = (await ctx.runMutation( @@ -367,6 +369,8 @@ export class Resend { createdAt: number; html?: string; text?: string; + template?: string; + variables?: Record; } | null> { return await ctx.runQuery(this.component.lib.get, { emailId, diff --git a/src/component/lib.ts b/src/component/lib.ts index d6c7c63..834a013 100644 --- a/src/component/lib.ts +++ b/src/component/lib.ts @@ -87,6 +87,8 @@ export const sendEmail = mutation({ html: v.optional(v.string()), text: v.optional(v.string()), replyTo: v.optional(v.array(v.string())), + template: v.optional(v.string()), + variables: v.optional(v.record(v.string(), v.string())), headers: v.optional( v.array( v.object({ @@ -106,8 +108,8 @@ export const sendEmail = mutation({ } // We require either html or text to be provided. No body = no bueno. - if (args.html === undefined && args.text === undefined) { - throw new Error("Either html or text must be provided"); + if (args.html === undefined && args.text === undefined && args.template === undefined) { + throw new Error("Either html, text, or template must be provided"); } // Store the text/html into separate records to keep things fast and memory low when we work with email batches. @@ -140,6 +142,8 @@ export const sendEmail = mutation({ html: htmlContentId, text: textContentId, headers: args.headers, + template: args.template, + variables: args.variables, segment, status: "waiting", complained: false, @@ -607,6 +611,10 @@ async function createResendBatchPayload( ]), ) : undefined, + template: email.template ? { + id: email.template, + variables: email.variables, + } : undefined, })); return [emails.map((e) => e._id), JSON.stringify(batchPayload)]; diff --git a/src/component/schema.ts b/src/component/schema.ts index 00f4f8a..8a3d968 100644 --- a/src/component/schema.ts +++ b/src/component/schema.ts @@ -22,6 +22,8 @@ export default defineSchema({ replyTo: v.array(v.string()), html: v.optional(v.id("content")), text: v.optional(v.id("content")), + template: v.optional(v.string()), + variables: v.optional(v.record(v.string(), v.string())), headers: v.optional( v.array( v.object({