feat: mock-email and some fixes for email auth

This commit is contained in:
Rafael Taranto 2023-11-28 19:01:35 +00:00
parent ab304093f3
commit c173f241eb
10 changed files with 97 additions and 26 deletions

View file

@ -3,7 +3,7 @@ const ph = require('./plugin-helper')
function sendMessage (settings, rec) {
return Promise.resolve()
.then(() => {
const pluginCode = 'mailgun'
const pluginCode = settings.config.notifications_thirdParty_email
const plugin = ph.load(ph.EMAIL, pluginCode)
const account = settings.accounts[pluginCode]
@ -11,4 +11,15 @@ function sendMessage (settings, rec) {
})
}
module.exports = {sendMessage}
function sendCustomerMessage (settings, rec) {
return Promise.resolve()
.then(() => {
const pluginCode = settings.config.notifications_thirdParty_email
const plugin = ph.load(ph.EMAIL, pluginCode)
const account = settings.accounts[pluginCode]
return plugin.sendMessage(account, rec)
})
}
module.exports = {sendMessage, sendCustomerMessage}

View file

@ -53,6 +53,7 @@ const ALL_ACCOUNTS = [
{ code: 'telnyx', display: 'Telnyx', class: SMS },
{ code: 'vonage', display: 'Vonage', class: SMS },
{ code: 'mailgun', display: 'Mailgun', class: EMAIL },
{ code: 'mock-email', display: 'Mock Email', class: EMAIL, dev: true },
{ code: 'none', display: 'None', class: ZERO_CONF, cryptos: ALL_CRYPTOS },
{ code: 'blockcypher', display: 'Blockcypher', class: ZERO_CONF, cryptos: [BTC] },
{ code: 'mock-zero-conf', display: 'Mock 0-conf', class: ZERO_CONF, cryptos: ALL_CRYPTOS, dev: true },

View file

@ -763,7 +763,7 @@ function plugins (settings, deviceId) {
function getPhoneCode (phone) {
const notifications = configManager.getNotifications(settings.config)
const code = notifications.thirdParty_sms === 'mock-sms'
const code = settings.config.notifications_thirdParty_sms === 'mock-sms'
? '123'
: randomCode()
@ -780,13 +780,11 @@ function plugins (settings, deviceId) {
}
function getEmailCode (toEmail) {
const notifications = configManager.getNotifications(settings.config)
const code = notifications.thirdParty_email === 'mock-email'
const code = settings.config.notifications_thirdParty_email === 'mock-email'
? '123'
: randomCode()
const req = {
const rec = {
email: {
toEmail,
subject: 'Your cryptomat code',
@ -794,10 +792,8 @@ function plugins (settings, deviceId) {
}
}
console.log(code)
return Promise.resolve(code)
// return sms.sendMessage(settings, rec)
// .then(() => code)
return email.sendCustomerMessage(settings, rec)
.then(() => code)
}
function sweepHdRow (row) {

View file

@ -16,7 +16,22 @@ function sendMessage ({apiKey, domain, fromEmail, toEmail}, rec) {
return mailgun.messages().send(emailData)
}
function sendCustomerMessage ({apiKey, domain, fromEmail}, rec) {
const mailgun = Mailgun({apiKey, domain})
const to = req.email.toEmail
const emailData = {
from: fromEmail,
to,
subject: rec.email.subject,
text: rec.email.body
}
return mailgun.messages().send(emailData)
}
module.exports = {
NAME,
sendMessage
sendMessage,
sendCustomerMessage
}

View file

@ -0,0 +1,15 @@
const NAME = 'mock-email'
function sendMessage (settings, rec) {
console.log('sending email', rec)
}
function sendCustomerMessage(settings, rec) {
console.log('sending email', rec)
}
module.exports = {
NAME,
sendMessage,
sendCustomerMessage
}