-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (35 loc) · 1.15 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
// Each type of email has a provider assigned.
const channels = {}
const providers = {}
module.exports = {
init: (providerOptions = {}, settings = {}) => {
// Init all providers.
Object.keys(providerOptions.providers).forEach(key => {
providers[key] = providerOptions.init[key](
providerOptions.providers[key],
settings
)
})
// Nominate the default provider
providers.default = providers[providerOptions.default]
// Set up channels.
Object.keys(providerOptions.channels).forEach(channelKey => {
const providerKey = providerOptions.channels[channelKey]
const provider = providers[providerKey]
if (!provider) {
strapi.log.error(`Unknown email provider: ${providerKey}. Using default.`)
}
channels[channelKey] = provider || providers.default
})
return {
send: (options) => {
const { channel } = options
const provider = channels[channel]
if (!provider) {
strapi.log.error(`No provider for email channel: ${channel}. Using default.`)
}
return (provider || providers.default).send(options)
}
}
},
}