(
params: OptionalFields<
{
transactionalId: string
email: string
dataVariables: Record<string, any>
logger: Logger
},
'dataVariables'
>,
)
| 22 | } |
| 23 | |
| 24 | async function sendTransactionalEmail( |
| 25 | params: OptionalFields< |
| 26 | { |
| 27 | transactionalId: string |
| 28 | email: string |
| 29 | dataVariables: Record<string, any> |
| 30 | logger: Logger |
| 31 | }, |
| 32 | 'dataVariables' |
| 33 | >, |
| 34 | ): Promise<SendEmailResult> { |
| 35 | const withDefaults = { |
| 36 | dataVariables: {}, |
| 37 | ...params, |
| 38 | } |
| 39 | const { transactionalId, email, dataVariables, logger } = withDefaults |
| 40 | |
| 41 | if (!loopsClient) { |
| 42 | return { |
| 43 | success: false, |
| 44 | error: |
| 45 | 'Loops SDK not initialized (LOOPS_API_KEY missing or SDK init failed).', |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | try { |
| 50 | const response = await loopsClient.sendTransactionalEmail({ |
| 51 | transactionalId, |
| 52 | email, |
| 53 | dataVariables, |
| 54 | }) |
| 55 | |
| 56 | logger.info( |
| 57 | { email, transactionalId, loopsId: (response as any)?.id }, |
| 58 | 'Loops transactional email sent successfully via SDK', |
| 59 | ) |
| 60 | return { success: true, loopsId: (response as any)?.id } |
| 61 | } catch (error) { |
| 62 | let errorMessage = 'Unknown SDK error during transactional email' |
| 63 | if (error instanceof APIError) { |
| 64 | logger.error( |
| 65 | { |
| 66 | ...error, |
| 67 | email, |
| 68 | transactionalId, |
| 69 | errorType: 'APIError', |
| 70 | }, |
| 71 | `Loops APIError sending transactional email: ${error.message}`, |
| 72 | ) |
| 73 | errorMessage = `Loops APIError: ${error.message} (Status: ${error.statusCode})` |
| 74 | } else { |
| 75 | logger.error( |
| 76 | { email, transactionalId, error }, |
| 77 | 'An unexpected error occurred sending transactional email via Loops SDK', |
| 78 | ) |
| 79 | } |
| 80 | return { success: false, error: errorMessage } |
| 81 | } |
no outgoing calls
no test coverage detected