From 6fccf2bd7a7e99afb0a301a67f7dda1250e52092 Mon Sep 17 00:00:00 2001 From: Marco Comi <9998393+kin0992@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:29:24 +0100 Subject: [PATCH] Parse config and extrac fromEmailAddress from there --- apps/cognito-functions/src/main.ts | 18 +++++++++++++++++- .../src/send-email-handler.ts | 16 ++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/cognito-functions/src/main.ts b/apps/cognito-functions/src/main.ts index 3100ed1919..5df2ce098a 100644 --- a/apps/cognito-functions/src/main.ts +++ b/apps/cognito-functions/src/main.ts @@ -16,4 +16,20 @@ export const customMessageHandler = pipe( }, customMessage.makeHandler) ); -export const sensEmailHandler = pipe(new SES(), sendEmail.makeHandler); +export const sensEmailHandler = pipe( + { fromEmailAddress: process.env.FROM_EMAIL_ADDRESS }, + sendEmail.SendEmailConfig.decode, + E.fold( + (errors) => { + // eslint-disable-next-line functional/no-expression-statements + console.log(PR.failure(errors).join('\n')); + // eslint-disable-next-line functional/no-throw-statements + throw new Error(); + }, + (config) => + sendEmail.makeHandler({ + ses: new SES(), + config, + }) + ) +); diff --git a/apps/cognito-functions/src/send-email-handler.ts b/apps/cognito-functions/src/send-email-handler.ts index 7e90d64643..7f126df53b 100644 --- a/apps/cognito-functions/src/send-email-handler.ts +++ b/apps/cognito-functions/src/send-email-handler.ts @@ -4,6 +4,7 @@ import { SendEmailCommand, SendEmailCommandInput, } from '@aws-sdk/client-ses'; +import * as t from 'io-ts'; const emailBody = (firstName: string) => `