-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const path = require('path');
const templateList = [
{
templateId: 'example',
templateSubject: 'example',
},
];
templateList.reduce((acc, templateInfo) => {
const { templateId } = templateInfo;
if (acc[templateId] === 1) {
throw new Error(`Error: Duplicate SES template id "${templateId}", they should be unique`);
}
acc[templateId] = 1;
return acc;
}, {});
/**
* @param {Object} serverless - Serverless instance
* @param {Object} _options - runtime options
* @returns {Promise<{name: string, subject: string, html: string, text}[]>}
*/
module.exports = async (serverless, _options) => {
// You can load template configuration from filesystem using serverless object + runtime options
// or from any other source like database or API
const sesEmailTemplates = templateList.map((templateInfo) => {
const { templateId, templateSubject } = templateInfo;
const templatePathHtml = path.join(__dirname, `templates/${templateId}.html`);
const templatePathTxt = path.join(__dirname, `templates/${templateId}.txt`);
return {
name: templateId,
subject: templateSubject,
html: serverless.utils.readFileSync(templatePathHtml),
text: serverless.utils.readFileSync(templatePathTxt),
};
});
return sesEmailTemplates;
};