-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
52 lines (45 loc) · 1.47 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
42
43
44
45
46
47
48
49
50
51
52
import path from "node:path"
import { fileURLToPath } from "node:url"
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
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: string}[]>}
*/
const templateConfiguration = 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
}
export default templateConfiguration