diff --git a/src/emails/interfaces/create-email-options.interface.ts b/src/emails/interfaces/create-email-options.interface.ts
index 64726ddc..5599bc34 100644
--- a/src/emails/interfaces/create-email-options.interface.ts
+++ b/src/emails/interfaces/create-email-options.interface.ts
@@ -1,20 +1,32 @@
import { ReactElement } from 'react';
import { PostOptions } from '../../common/interfaces';
-export interface CreateEmailOptions {
+interface CreateEmailBaseOptions {
attachments?: Attachment[];
bcc?: string | string[];
cc?: string | string[];
from: string;
- html?: string;
react?: ReactElement | null;
reply_to?: string | string[];
subject: string;
tags?: Tag[];
- text?: string;
to: string | string[];
}
+interface CreateEmailWithHtmlOptions extends CreateEmailBaseOptions {
+ html: string;
+ text?: string;
+}
+
+interface CreateEmailWithTextOptions extends CreateEmailBaseOptions {
+ html?: string;
+ text: string;
+}
+
+export type CreateEmailOptions =
+ | CreateEmailWithHtmlOptions
+ | CreateEmailWithTextOptions;
+
export interface CreateEmailRequestOptions extends PostOptions {}
export interface CreateEmailResponse {
diff --git a/src/resend.spec.ts b/src/resend.spec.ts
index 1405fab5..f7b07d27 100644
--- a/src/resend.spec.ts
+++ b/src/resend.spec.ts
@@ -1,6 +1,7 @@
import { Resend } from './resend';
import MockAdapater from 'axios-mock-adapter';
import axios from 'axios';
+import { CreateEmailOptions } from './emails/interfaces';
const mock = new MockAdapater(axios);
const resend = new Resend('re_924b3rjh2387fbewf823');
@@ -13,10 +14,11 @@ describe('Resend', () => {
});
it('sends email', async () => {
- const payload = {
+ const payload: CreateEmailOptions = {
from: 'bu@resend.com',
to: 'zeno@resend.com',
subject: 'Hello World',
+ html: '
Hello world
',
};
mock.onPost('/emails', payload).replyOnce(200, {
id: '1234',
@@ -37,10 +39,11 @@ describe('Resend', () => {
});
it('sends email with multiple recipients', async () => {
- const payload = {
+ const payload: CreateEmailOptions = {
from: 'admin@resend.com',
to: ['bu@resend.com', 'zeno@resend.com'],
subject: 'Hello World',
+ text: 'Hello world',
};
mock.onPost('/emails', payload).replyOnce(200, {
id: '1234',
@@ -64,11 +67,12 @@ describe('Resend', () => {
});
it('sends email with multiple bcc recipients', async () => {
- const payload = {
+ const payload: CreateEmailOptions = {
from: 'admin@resend.com',
to: 'bu@resend.com',
bcc: ['foo@resend.com', 'bar@resend.com'],
subject: 'Hello World',
+ text: 'Hello world',
};
mock.onPost('/emails', payload).replyOnce(200, {
id: '1234',
@@ -94,11 +98,12 @@ describe('Resend', () => {
});
it('sends email with multiple cc recipients', async () => {
- const payload = {
+ const payload: CreateEmailOptions = {
from: 'admin@resend.com',
to: 'bu@resend.com',
cc: ['foo@resend.com', 'bar@resend.com'],
subject: 'Hello World',
+ text: 'Hello world',
};
mock.onPost('/emails', payload).replyOnce(200, {
id: '1234',
@@ -124,11 +129,12 @@ describe('Resend', () => {
});
it('sends email with multiple replyTo emails', async () => {
- const apiPayload = {
+ const apiPayload: CreateEmailOptions = {
from: 'admin@resend.com',
to: 'bu@resend.com',
reply_to: ['foo@resend.com', 'bar@resend.com'],
subject: 'Hello World',
+ text: 'Hello world',
};
mock.onPost('/emails', apiPayload).replyOnce(200, {
@@ -139,11 +145,12 @@ describe('Resend', () => {
created_at: '123',
});
- const payload = {
+ const payload: CreateEmailOptions = {
from: 'admin@resend.com',
to: 'bu@resend.com',
reply_to: ['foo@resend.com', 'bar@resend.com'],
subject: 'Hello World',
+ text: 'Hello world',
};
const data = await resend.emails.send(payload);