From 92eb184081825807d9755be90e539a40444b7c97 Mon Sep 17 00:00:00 2001 From: nickviola Date: Thu, 7 Dec 2023 12:07:05 -0600 Subject: [PATCH 01/17] Add base function to get email assets from s3 and update env var for bucket name in example env file --- backend/src/tasks/s3-client.ts | 21 +++++++++++++++++++++ dev.env.example | 2 ++ 2 files changed, 23 insertions(+) diff --git a/backend/src/tasks/s3-client.ts b/backend/src/tasks/s3-client.ts index fa4f03e28..d9f4afafb 100644 --- a/backend/src/tasks/s3-client.ts +++ b/backend/src/tasks/s3-client.ts @@ -1,5 +1,6 @@ import { S3 } from 'aws-sdk'; +S3.getObject({) /** * S3 Client. Normally, interacts with S3. * When the app is running locally, connects @@ -74,6 +75,7 @@ class S3Client { throw e; } } + async listReports(orgId: string) { try { const params = { @@ -93,6 +95,25 @@ class S3Client { throw e; } } + + async getEmailAsset(fileName: string) { + try { + const params = { + Bucket: process.env.EMAIL_BUCKET_NAME!, + Key: fileName + }; + + const data = await this.s3 + .getObject(params, function (err, data) { + if (err) throw err; + }) + .promise(); + return data.Contents; + } catch (e) { + console.error(e); + throw e; + } + } } export default S3Client; diff --git a/dev.env.example b/dev.env.example index 4443cf737..6e02b6096 100644 --- a/dev.env.example +++ b/dev.env.example @@ -77,4 +77,6 @@ EXPORT_BUCKET_NAME=crossfeed-local-exports REPORTS_BUCKET_NAME=crossfeed-local-reports +EMAIL_BUCKET_NAME=cisa-crossfeed-staging-html-email + IS_LOCAL=1 From 1ee9eec5d46b9a58d84a975a00643f8bd1a58fd8 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Thu, 7 Dec 2023 14:34:47 -0600 Subject: [PATCH 02/17] Integrate S3 getEmailAssets in the mail notification system. --- backend/src/api/helpers.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 16e7ca2ea..4c21b8090 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -12,6 +12,7 @@ import * as nodemailer from 'nodemailer'; import * as fs from 'fs'; import * as handlebars from 'handlebars'; import * as util from 'util'; +import { getEmailAsset } from '../tasks/s3-client'; export const validateBody = async ( obj: ClassType, @@ -111,8 +112,7 @@ export const sendUserNotificationEmail = async ( SES: new SES({ region: 'us-east-1' }) }); - const fs = require('fs').promises; - const html = await fs.readFile(template_file, 'utf8'); + const html = getEmailAsset(template_file); const template = handlebars.compile(html); const data = { first_name: p_firstName, @@ -129,37 +129,37 @@ export const sendUserNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: '/app/src/email_templates/banner.png', + path: getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: '/app/src/email_templates/banner.png', + path: getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: '/app/src/email_templates/email.png', + path: getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: '/app/src/email_templates/linkedin.png', + path: getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: '/app/src/email_templates/twitter.png', + path: getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: '/app/src/email_templates/facebooK.png', + path: getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: '/app/src/email_templates/instagram.png', + path: getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] @@ -181,7 +181,7 @@ export const sendRegionalAdminNotificationEmail = async ( const fs = require('fs').promises; const html = await fs.readFile( - '/app/src/email_templates/crossfeed_regional_admin_notification.html', + getEmailAsset('crossfeed_regional_admin_notification.html'), 'utf8' ); const template = handlebars.compile(html); @@ -200,37 +200,37 @@ export const sendRegionalAdminNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: '/app/src/email_templates/banner.png', + path: getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: '/app/src/email_templates/banner.png', + path: getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: '/app/src/email_templates/email.png', + path: getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: '/app/src/email_templates/linkedin.png', + path: getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: '/app/src/email_templates/twitter.png', + path: getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: '/app/src/email_templates/facebooK.png', + path: getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: '/app/src/email_templates/instagram.png', + path: getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] From 2056c1f12af905755bd63b9d2685e84f1d12f1cb Mon Sep 17 00:00:00 2001 From: nickviola Date: Thu, 7 Dec 2023 15:57:22 -0600 Subject: [PATCH 03/17] Fix typo in s3-client.ts --- backend/src/tasks/s3-client.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/tasks/s3-client.ts b/backend/src/tasks/s3-client.ts index d9f4afafb..756988d55 100644 --- a/backend/src/tasks/s3-client.ts +++ b/backend/src/tasks/s3-client.ts @@ -1,6 +1,5 @@ import { S3 } from 'aws-sdk'; -S3.getObject({) /** * S3 Client. Normally, interacts with S3. * When the app is running locally, connects From 5b474e622f289e89bf96bf810a4f34b7a9cbbbe1 Mon Sep 17 00:00:00 2001 From: nickviola Date: Thu, 7 Dec 2023 16:18:04 -0600 Subject: [PATCH 04/17] Fix imports in helpers file for S3Client --- backend/src/api/helpers.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 4c21b8090..e4dd35190 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -12,7 +12,8 @@ import * as nodemailer from 'nodemailer'; import * as fs from 'fs'; import * as handlebars from 'handlebars'; import * as util from 'util'; -import { getEmailAsset } from '../tasks/s3-client'; +import S3Client from '../tasks/s3-client'; + export const validateBody = async ( obj: ClassType, @@ -112,7 +113,7 @@ export const sendUserNotificationEmail = async ( SES: new SES({ region: 'us-east-1' }) }); - const html = getEmailAsset(template_file); + const html = S3Client.getEmailAsset(template_file); const template = handlebars.compile(html); const data = { first_name: p_firstName, @@ -129,37 +130,37 @@ export const sendUserNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: getEmailAsset('banner.png'), + path: S3Client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: getEmailAsset('banner.png'), + path: S3Client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: getEmailAsset('email.png'), + path: S3Client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: getEmailAsset('linkedin.png'), + path: S3Client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: getEmailAsset('twitter.png'), + path: S3Client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: getEmailAsset('facebooK.png'), + path: S3Client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: getEmailAsset('instagram.png'), + path: S3Client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] @@ -181,7 +182,7 @@ export const sendRegionalAdminNotificationEmail = async ( const fs = require('fs').promises; const html = await fs.readFile( - getEmailAsset('crossfeed_regional_admin_notification.html'), + S3Client.getEmailAsset('crossfeed_regional_admin_notification.html'), 'utf8' ); const template = handlebars.compile(html); @@ -200,37 +201,37 @@ export const sendRegionalAdminNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: getEmailAsset('banner.png'), + path: S3Client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: getEmailAsset('banner.png'), + path: S3Client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: getEmailAsset('email.png'), + path: S3Client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: getEmailAsset('linkedin.png'), + path: S3Client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: getEmailAsset('twitter.png'), + path: S3Client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: getEmailAsset('facebooK.png'), + path: S3Client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: getEmailAsset('instagram.png'), + path: S3Client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] From 90e998e259b05c7c03fb7feff3e9cb1a97f0260c Mon Sep 17 00:00:00 2001 From: nickviola Date: Thu, 7 Dec 2023 16:22:01 -0600 Subject: [PATCH 05/17] Fix linter errors in backend/src/api/helpers.ts --- backend/src/api/helpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index e4dd35190..47008e12a 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -14,7 +14,6 @@ import * as handlebars from 'handlebars'; import * as util from 'util'; import S3Client from '../tasks/s3-client'; - export const validateBody = async ( obj: ClassType, body: string | null, From b63e11b937ad9e827a1ee3a72c7906785d40d5e5 Mon Sep 17 00:00:00 2001 From: nickviola Date: Thu, 7 Dec 2023 16:36:10 -0600 Subject: [PATCH 06/17] Update usage of S3Client in backend/src/api/helpers.ts --- backend/src/api/helpers.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 47008e12a..2d3362c7d 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -112,7 +112,8 @@ export const sendUserNotificationEmail = async ( SES: new SES({ region: 'us-east-1' }) }); - const html = S3Client.getEmailAsset(template_file); + const client = new S3Client(); + const html = client.getEmailAsset(template_file); const template = handlebars.compile(html); const data = { first_name: p_firstName, @@ -129,37 +130,37 @@ export const sendUserNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: S3Client.getEmailAsset('banner.png'), + path: client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: S3Client.getEmailAsset('banner.png'), + path: client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: S3Client.getEmailAsset('email.png'), + path: client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: S3Client.getEmailAsset('linkedin.png'), + path: client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: S3Client.getEmailAsset('twitter.png'), + path: client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: S3Client.getEmailAsset('facebooK.png'), + path: client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: S3Client.getEmailAsset('instagram.png'), + path: client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] @@ -180,8 +181,9 @@ export const sendRegionalAdminNotificationEmail = async ( }); const fs = require('fs').promises; + const client = new S3Client(); const html = await fs.readFile( - S3Client.getEmailAsset('crossfeed_regional_admin_notification.html'), + client.getEmailAsset('crossfeed_regional_admin_notification.html'), 'utf8' ); const template = handlebars.compile(html); @@ -200,37 +202,37 @@ export const sendRegionalAdminNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: S3Client.getEmailAsset('banner.png'), + path: client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: S3Client.getEmailAsset('banner.png'), + path: client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: S3Client.getEmailAsset('email.png'), + path: client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: S3Client.getEmailAsset('linkedin.png'), + path: client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: S3Client.getEmailAsset('twitter.png'), + path: client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: S3Client.getEmailAsset('facebooK.png'), + path: client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: S3Client.getEmailAsset('instagram.png'), + path: client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] From e758fc93f041cb988a01cd697e4169a0ebb6db62 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 8 Dec 2023 11:27:48 -0600 Subject: [PATCH 07/17] WIP. Resolving issues between S3 buckets and nodemailer attachments. --- backend/src/api/helpers.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 2d3362c7d..6bc5384f6 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -130,37 +130,37 @@ export const sendUserNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: client.getEmailAsset('banner.png'), + content: client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: client.getEmailAsset('banner.png'), + content: client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: client.getEmailAsset('email.png'), + content: client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: client.getEmailAsset('linkedin.png'), + content: client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: client.getEmailAsset('twitter.png'), + content: client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: client.getEmailAsset('facebooK.png'), + content: client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: client.getEmailAsset('instagram.png'), + content: client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] @@ -202,37 +202,37 @@ export const sendRegionalAdminNotificationEmail = async ( attachments: [ { filename: 'banner.png', - path: client.getEmailAsset('banner.png'), + content: client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - path: client.getEmailAsset('banner.png'), + content: client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - path: client.getEmailAsset('email.png'), + content: client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - path: client.getEmailAsset('linkedin.png'), + content: client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - path: client.getEmailAsset('twitter.png'), + content: client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - path: client.getEmailAsset('facebooK.png'), + content: client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - path: client.getEmailAsset('instagram.png'), + content: client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] From aa710765878af1b5784622268c4e7d0a333c0560 Mon Sep 17 00:00:00 2001 From: nickviola Date: Fri, 8 Dec 2023 15:45:28 -0600 Subject: [PATCH 08/17] Modify output format of getEmailAsset to fit nodemailer requirements --- backend/src/tasks/s3-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/tasks/s3-client.ts b/backend/src/tasks/s3-client.ts index 756988d55..ae32b2ced 100644 --- a/backend/src/tasks/s3-client.ts +++ b/backend/src/tasks/s3-client.ts @@ -107,7 +107,7 @@ class S3Client { if (err) throw err; }) .promise(); - return data.Contents; + return data.Body.toString('utf-8'); } catch (e) { console.error(e); throw e; From 3a9394df245611063bb7b4e2f171bf49d4bbfb80 Mon Sep 17 00:00:00 2001 From: nickviola Date: Fri, 8 Dec 2023 15:51:12 -0600 Subject: [PATCH 09/17] Modify output format of getEmailAsset to fit nodemailer requirements --- backend/src/tasks/s3-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/tasks/s3-client.ts b/backend/src/tasks/s3-client.ts index ae32b2ced..e73f800f0 100644 --- a/backend/src/tasks/s3-client.ts +++ b/backend/src/tasks/s3-client.ts @@ -107,7 +107,7 @@ class S3Client { if (err) throw err; }) .promise(); - return data.Body.toString('utf-8'); + return data.Body; } catch (e) { console.error(e); throw e; From e7f8112b29525ab84d4c635b94f2cc601eb248e3 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Fri, 8 Dec 2023 15:52:32 -0600 Subject: [PATCH 10/17] Change content to await email asset. --- backend/src/api/helpers.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 6bc5384f6..31bdee052 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -130,37 +130,37 @@ export const sendUserNotificationEmail = async ( attachments: [ { filename: 'banner.png', - content: client.getEmailAsset('banner.png'), + content: await client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - content: client.getEmailAsset('banner.png'), + content: await client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - content: client.getEmailAsset('email.png'), + content: await client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - content: client.getEmailAsset('linkedin.png'), + content: await client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - content: client.getEmailAsset('twitter.png'), + content: await client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - content: client.getEmailAsset('facebooK.png'), + content: await client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - content: client.getEmailAsset('instagram.png'), + content: await client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] @@ -202,37 +202,37 @@ export const sendRegionalAdminNotificationEmail = async ( attachments: [ { filename: 'banner.png', - content: client.getEmailAsset('banner.png'), + content: await client.getEmailAsset('banner.png'), cid: 'CISA Banner' }, { filename: 'web.png', - content: client.getEmailAsset('banner.png'), + content: await client.getEmailAsset('banner.png'), cid: 'CISA Web' }, { filename: 'email.png', - content: client.getEmailAsset('email.png'), + content: await client.getEmailAsset('email.png'), cid: 'CISA Email' }, { filename: 'linkedin.png', - content: client.getEmailAsset('linkedin.png'), + content: await client.getEmailAsset('linkedin.png'), cid: 'CISA LinkedIn' }, { filename: 'twitter.png', - content: client.getEmailAsset('twitter.png'), + content: await client.getEmailAsset('twitter.png'), cid: 'CISA Twitter' }, { filename: 'facebook.png', - content: client.getEmailAsset('facebooK.png'), + content: await client.getEmailAsset('facebooK.png'), cid: 'CISA Facebook' }, { filename: 'instagram.png', - content: client.getEmailAsset('instagram.png'), + content: await client.getEmailAsset('instagram.png'), cid: 'CISA Instagram' } ] From 17c3e7c8dddfac17f01b9038ee79eeb975760700 Mon Sep 17 00:00:00 2001 From: nickviola Date: Fri, 8 Dec 2023 15:59:23 -0600 Subject: [PATCH 11/17] Modify output format of getEmailAsset to fit nodemailer requirements --- backend/src/tasks/s3-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/tasks/s3-client.ts b/backend/src/tasks/s3-client.ts index e73f800f0..ae32b2ced 100644 --- a/backend/src/tasks/s3-client.ts +++ b/backend/src/tasks/s3-client.ts @@ -107,7 +107,7 @@ class S3Client { if (err) throw err; }) .promise(); - return data.Body; + return data.Body.toString('utf-8'); } catch (e) { console.error(e); throw e; From 33274e15f860e26a360576b29e91e0045e92c6b5 Mon Sep 17 00:00:00 2001 From: nickviola Date: Fri, 8 Dec 2023 16:10:33 -0600 Subject: [PATCH 12/17] Modify output format of getEmailAsset to fit nodemailer requirements --- backend/src/tasks/s3-client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/tasks/s3-client.ts b/backend/src/tasks/s3-client.ts index ae32b2ced..f376f539a 100644 --- a/backend/src/tasks/s3-client.ts +++ b/backend/src/tasks/s3-client.ts @@ -107,7 +107,9 @@ class S3Client { if (err) throw err; }) .promise(); - return data.Body.toString('utf-8'); + if ( data && data.Body ) { + return data.Body.toString('utf-8'); + } } catch (e) { console.error(e); throw e; From e3e5e834f2aaafda403bab67ebe7f991b9844098 Mon Sep 17 00:00:00 2001 From: nickviola Date: Fri, 8 Dec 2023 16:13:05 -0600 Subject: [PATCH 13/17] Modify output format of getEmailAsset to fit nodemailer requirements --- backend/src/tasks/s3-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/tasks/s3-client.ts b/backend/src/tasks/s3-client.ts index f376f539a..923713c89 100644 --- a/backend/src/tasks/s3-client.ts +++ b/backend/src/tasks/s3-client.ts @@ -107,7 +107,7 @@ class S3Client { if (err) throw err; }) .promise(); - if ( data && data.Body ) { + if (data && data.Body) { return data.Body.toString('utf-8'); } } catch (e) { From 1549b67f68f50c647826b8de24d88efe4df8d3eb Mon Sep 17 00:00:00 2001 From: nickviola Date: Mon, 11 Dec 2023 10:48:47 -0600 Subject: [PATCH 14/17] Add await for s3 asset retrieval --- backend/src/api/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 31bdee052..4a5c15526 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -113,7 +113,7 @@ export const sendUserNotificationEmail = async ( }); const client = new S3Client(); - const html = client.getEmailAsset(template_file); + const html = await client.getEmailAsset(template_file); const template = handlebars.compile(html); const data = { first_name: p_firstName, @@ -183,7 +183,7 @@ export const sendRegionalAdminNotificationEmail = async ( const fs = require('fs').promises; const client = new S3Client(); const html = await fs.readFile( - client.getEmailAsset('crossfeed_regional_admin_notification.html'), + await client.getEmailAsset('crossfeed_regional_admin_notification.html'), 'utf8' ); const template = handlebars.compile(html); From a87c8ddc5201b977da7421a990fe70575dc41854 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Mon, 11 Dec 2023 15:01:12 -0600 Subject: [PATCH 15/17] Remove fs.readFile when grabbing from S3 bucket. --- backend/src/api/helpers.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 4a5c15526..8ff178e02 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -180,12 +180,9 @@ export const sendRegionalAdminNotificationEmail = async ( SES: new SES({ region: 'us-east-1' }) }); - const fs = require('fs').promises; const client = new S3Client(); - const html = await fs.readFile( - await client.getEmailAsset('crossfeed_regional_admin_notification.html'), - 'utf8' - ); + const html = await client.getEmailAsset('crossfeed_regional_admin_notification.html'); + const template = handlebars.compile(html); const data = { first_name: p_firstName, From 0717b6ac2c0d9569bb89350fbff54d5086f717a3 Mon Sep 17 00:00:00 2001 From: JCantu248 Date: Mon, 11 Dec 2023 15:21:37 -0600 Subject: [PATCH 16/17] Resolving linter issues. --- backend/src/api/helpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index 8ff178e02..c9219cc38 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -182,7 +182,6 @@ export const sendRegionalAdminNotificationEmail = async ( const client = new S3Client(); const html = await client.getEmailAsset('crossfeed_regional_admin_notification.html'); - const template = handlebars.compile(html); const data = { first_name: p_firstName, From 558b3498e7105ec7b25657fe142b8b5760458fd6 Mon Sep 17 00:00:00 2001 From: nickviola Date: Mon, 11 Dec 2023 15:30:05 -0600 Subject: [PATCH 17/17] Fix linter error in helpers.ts --- backend/src/api/helpers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/api/helpers.ts b/backend/src/api/helpers.ts index c9219cc38..c8cf3c0f1 100644 --- a/backend/src/api/helpers.ts +++ b/backend/src/api/helpers.ts @@ -181,7 +181,9 @@ export const sendRegionalAdminNotificationEmail = async ( }); const client = new S3Client(); - const html = await client.getEmailAsset('crossfeed_regional_admin_notification.html'); + const html = await client.getEmailAsset( + 'crossfeed_regional_admin_notification.html' + ); const template = handlebars.compile(html); const data = { first_name: p_firstName,