Skip to content
Open
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
21 changes: 16 additions & 5 deletions packages/email-resend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,28 @@ function mapAttachments(
attachments: SendEmailOptions['attachments'],
): ResendSendEmailOptions['attachments'] {
if (!attachments) {
return []
return [] as Attachment[]
}

return attachments.map((attachment) => {
if (!attachment.filename || !attachment.content) {
throw new APIError('Attachment is missing filename or content', 400)
return attachments.map((attachment): Attachment => {
if (!attachment.filename) {
throw new APIError('Attachment is missing filename', 400)
}

if (!attachment.content && !attachment.path) {
throw new APIError('Attachment is missing both content and path', 400)
}

if (attachment.path && !attachment.content) {
return {
filename: attachment.filename,
path: attachment.path,
}
}

if (typeof attachment.content === 'string') {
return {
content: Buffer.from(attachment.content),
content: attachment.content,
filename: attachment.filename,
}
}
Expand Down