(options: EmailOptions)
| 65 | } |
| 66 | |
| 67 | export function processEmailData(options: EmailOptions): ProcessedEmailData { |
| 68 | const { senderEmail, subject, replyTo } = validateAndSanitize(options) |
| 69 | const { |
| 70 | to, |
| 71 | html, |
| 72 | text, |
| 73 | emailType = 'transactional', |
| 74 | includeUnsubscribe = true, |
| 75 | attachments, |
| 76 | } = options |
| 77 | |
| 78 | let finalHtml = html |
| 79 | let finalText = text |
| 80 | let headers: Record<string, string> = {} |
| 81 | |
| 82 | if (includeUnsubscribe && emailType !== 'transactional') { |
| 83 | const primaryEmail = Array.isArray(to) ? to[0] : to |
| 84 | const injection = buildUnsubscribeInjection(primaryEmail, emailType, html, text) |
| 85 | headers = injection.headers |
| 86 | finalHtml = injection.html |
| 87 | finalText = injection.text |
| 88 | } |
| 89 | |
| 90 | return { |
| 91 | to, |
| 92 | subject, |
| 93 | html: finalHtml, |
| 94 | text: finalText, |
| 95 | senderEmail, |
| 96 | headers, |
| 97 | attachments, |
| 98 | replyTo, |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | export async function shouldSkipForUnsubscribe(options: EmailOptions): Promise<boolean> { |
| 103 | const { emailType = 'transactional', to } = options |
no test coverage detected