From c6f32eb4b21a47b12e4c0907f1dfad6b1e588a6f Mon Sep 17 00:00:00 2001 From: Parker Date: Wed, 6 Dec 2023 14:18:24 -0700 Subject: [PATCH] Remove ability to email multiple people --- app/utils/email.server.ts | 34 +++++++++++++++++++--------------- tests/mocks/utils.ts | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/utils/email.server.ts b/app/utils/email.server.ts index 007071e..6df9156 100644 --- a/app/utils/email.server.ts +++ b/app/utils/email.server.ts @@ -1,17 +1,21 @@ import { type ReactElement } from 'react' import { renderAsync } from '@react-email/components' import { siteEmailAddressWithName } from '~/data.ts' -import { Resend } from 'resend'; +import { Resend } from 'resend' -const resend = new Resend(process.env.RESEND_API_KEY); +const resend = new Resend(process.env.RESEND_API_KEY) export async function sendEmail({ react, ...options }: { - to: string | string[] + to: string subject: string - attachments?: { filename?: string, path?: string, content?: string | Buffer }[] + attachments?: { + filename?: string + path?: string + content?: string | Buffer + }[] } & ( | { html: string; text: string; react?: never } | { react: ReactElement; html?: never; text?: never } @@ -20,7 +24,7 @@ export async function sendEmail({ const from = siteEmailAddressWithName const email = { - from, + from, ...options, ...(react ? await renderReactEmail(react) : null), } @@ -57,7 +61,7 @@ export async function sendEmail({ html: email.html, text: email.text, attachments: email.attachments, - }); + }) return { status: 'success', @@ -65,16 +69,16 @@ export async function sendEmail({ } as const // Catch full exception - } catch (e : any) { - console.error('🔴 error sending email:', JSON.stringify(email)) + } catch (e: any) { + console.error('🔴 error sending email:', JSON.stringify(email)) return { - status: 'error', - error: { - message: e.message || 'Unknown error', - code: e.code || 'Unknown code', - response: e.response || 'Unknown response', - } - } + status: 'error', + error: { + message: e.message || 'Unknown error', + code: e.code || 'Unknown code', + response: e.response || 'Unknown response', + }, + } } } diff --git a/tests/mocks/utils.ts b/tests/mocks/utils.ts index d749800..113ef1c 100644 --- a/tests/mocks/utils.ts +++ b/tests/mocks/utils.ts @@ -21,7 +21,7 @@ export async function createFixture( } export const emailSchema = z.object({ - to: z.union([z.string(), z.array(z.string())]), + to: z.string(), from: z.string(), subject: z.string(), text: z.string(),