(emails: EmailOptions[])
| 126 | } |
| 127 | |
| 128 | async function prepareBatch(emails: EmailOptions[]): Promise<PreparedBatchEntry[]> { |
| 129 | return Promise.all( |
| 130 | emails.map(async (email, index): Promise<PreparedBatchEntry> => { |
| 131 | try { |
| 132 | const allowed = await applyBanList(email) |
| 133 | if (!allowed) { |
| 134 | return { index, data: null, skippedResult: SKIPPED_BANNED_RESULT } |
| 135 | } |
| 136 | if (await shouldSkipForUnsubscribe(allowed)) { |
| 137 | return { index, data: null, skippedResult: SKIPPED_UNSUBSCRIBED_RESULT } |
| 138 | } |
| 139 | return { index, data: processEmailData(allowed), skippedResult: null } |
| 140 | } catch (error) { |
| 141 | return { |
| 142 | index, |
| 143 | data: null, |
| 144 | skippedResult: { |
| 145 | success: false, |
| 146 | message: getErrorMessage(error, 'Failed to prepare email'), |
| 147 | }, |
| 148 | } |
| 149 | } |
| 150 | }) |
| 151 | ) |
| 152 | } |
| 153 | |
| 154 | export async function sendBatchEmails(options: BatchEmailOptions): Promise<BatchSendEmailResult> { |
| 155 | try { |
no test coverage detected