Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resend",
"version": "4.7.0",
"version": "4.8.0",
"description": "Node.js library for the Resend API",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
11 changes: 9 additions & 2 deletions src/common/interfaces/email-api-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { Attachment } from '../../emails/interfaces/create-email-options.interface';
import type { Tag } from '../../interfaces';

export interface EmailApiAttachment {
content?: string | Buffer;
filename?: string | false | undefined;
path?: string;
content_type?: string;
inline_content_id?: string;
}

export interface EmailApiOptions {
from: string;
to: string | string[];
Expand All @@ -14,5 +21,5 @@ export interface EmailApiOptions {
reply_to?: string | string[];
scheduled_at?: string;
tags?: Tag[];
attachments?: Attachment[];
attachments?: EmailApiAttachment[];
}
19 changes: 17 additions & 2 deletions src/common/utils/parse-email-to-api-options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import type { CreateEmailOptions } from '../../emails/interfaces/create-email-options.interface';
import type { EmailApiOptions } from '../interfaces/email-api-options.interface';
import type {
EmailApiAttachment,
EmailApiOptions,
} from '../interfaces/email-api-options.interface';

function parseAttachments(
attachments: CreateEmailOptions['attachments'],
): EmailApiAttachment[] | undefined {
return attachments?.map((attachment) => ({
content: attachment.content,
filename: attachment.filename,
path: attachment.path,
content_type: attachment.contentType,
inline_content_id: attachment.inlineContentId,
}));
}

export function parseEmailToApiOptions(
email: CreateEmailOptions,
): EmailApiOptions {
return {
attachments: email.attachments,
attachments: parseAttachments(email.attachments),
bcc: email.bcc,
cc: email.cc,
from: email.from,
Expand Down
5 changes: 5 additions & 0 deletions src/emails/interfaces/create-email-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export interface Attachment {
path?: string;
/** Optional content type for the attachment, if not set will be derived from the filename property */
contentType?: string;
/**
* Optional content ID for the attachment, to be used as a reference in the HTML content.
* If set, this attachment will be sent as an inline attachment and you can reference it in the HTML content using the `cid:` prefix.
*/
inlineContentId?: string;
}

export type Tag = {
Expand Down
Loading