diff --git a/config/service.report.json.example b/config/service.report.json.example index 4f497869..7ba6c3ba 100644 --- a/config/service.report.json.example +++ b/config/service.report.json.example @@ -3,10 +3,6 @@ "rest:report:api" ], "restUrl": "https://api-pub.bitfinex.com", - "emailConf": { - "from": "Bitfinex ", - "subject": "Your report is ready" - }, "s3Conf": { "bucket": "", "acl": "", diff --git a/locales/en/email.json b/locales/en/email.json deleted file mode 100644 index b86690a3..00000000 --- a/locales/en/email.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "template": { - "subject": "Your report is ready", - "btnText": "Download Report", - "fileName": "File name", - "unauth": "Your file could not be completed, please try again", - "readyForDownload": "The report you request is ready for download", - "ifDidNotInitAction": "If you did not initiate this action and you suspect that your account may be compromised, please", - "freezeAccount": "freeze your account", - "contactSupport": "and contact support", - "youCan": "You can", - "download": "download", - "pgpSignature": "a PGP digital signature file" - } -} diff --git a/locales/es-EM/email.json b/locales/es-EM/email.json deleted file mode 100644 index 01e10af2..00000000 --- a/locales/es-EM/email.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "template": { - "subject": "Tu reporte esta listo", - "btnText": "Descargar el Informe", - "fileName": "Nombre del archivo", - "unauth": "Tu archivo no se pudo completar, intente de nuevo por favor.", - "readyForDownload": "Tu reporte esta listo para ser descargado", - "ifDidNotInitAction": "Si no realizaste esta acción y sospechas que tu cuenta puede estar comprometida, por favor", - "freezeAccount": "congela tu cuenta", - "contactSupport": "y contacta soporte", - "youCan": "Puedes", - "download": "descargar", - "pgpSignature": "un archivo con firma digital PGP" - } -} diff --git a/locales/pt-BR/email.json b/locales/pt-BR/email.json deleted file mode 100644 index 383c132f..00000000 --- a/locales/pt-BR/email.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "template": { - "subject": "Seu relatório está pronto", - "btnText": "Baixar Relatório", - "fileName": "Nome do arquivo", - "unauth": "Não foi possível concluir seu arquivo, tente novamente", - "readyForDownload": "O relatório solicitado está pronto para download", - "ifDidNotInitAction": "Se você não iniciou esta ação e suspeita que sua conta pode estar comprometida", - "freezeAccount": "por favor, congele sua conta", - "contactSupport": "e entre em contato com o suporte", - "youCan": "Você pode", - "download": "baixar", - "pgpSignature": "um arquivo de assinatura digital PGP" - } -} diff --git a/locales/ru/email.json b/locales/ru/email.json deleted file mode 100644 index e53c1326..00000000 --- a/locales/ru/email.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "template": { - "subject": "Ваш отчет готов", - "btnText": "Скачать Отчет", - "fileName": "Имя файла", - "unauth": "Ваш файл не может быть завершен, пожалуйста, попробуйте еще раз", - "readyForDownload": "Запрашиваемый вами отчет готов к загрузке", - "ifDidNotInitAction": "Если вы не инициировали это действие и подозреваете, что ваша учетная запись может быть взломана, пожалуйста,", - "freezeAccount": "заблокируйте ее", - "contactSupport": "и обратитесь в службу поддержки", - "youCan": "Вы можете", - "download": "скачать", - "pgpSignature": "файл цифровой подписи PGP" - } -} diff --git a/locales/tr/email.json b/locales/tr/email.json deleted file mode 100644 index d9237f34..00000000 --- a/locales/tr/email.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "template": { - "subject": "Raporunuz hazır", - "btnText": "Raporu İndir", - "fileName": "Dosya adı", - "unauth": "Dosyanız tamamlanamadı, lütfen tekrar deneyin", - "readyForDownload": "İstediğiniz rapor indirilmeye hazır", - "ifDidNotInitAction": "Bu işlemi siz başlatmadıysanız ve hesabınızın güvenliğinin ihlal edilmiş olabileceğinden şüpheleniyorsanız, lütfen", - "freezeAccount": "hesabınızı dondurun", - "contactSupport": "ve destek ekibiyle iletişime geçin", - "youCan": "Yapabilirsiniz", - "download": "indir", - "pgpSignature": "bir PGP dijital imza dosyası" - } -} diff --git a/locales/zh-CN/email.json b/locales/zh-CN/email.json deleted file mode 100644 index 2b18df1b..00000000 --- a/locales/zh-CN/email.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "template": { - "subject": "您的报告已备妥", - "btnText": "下载报告档案", - "fileName": "档案名称", - "unauth": "档案未下载成功,请重试一次", - "readyForDownload": "您请求的报告已可下载", - "ifDidNotInitAction": "如果您未进行此操作并且怀疑您的帐户已遭盗用,请", - "freezeAccount": "冻结您的帐户", - "contactSupport": "以及联络客服人员", - "youCan": "您可以", - "download": "下载", - "pgpSignature": "PGP数位签名档" - } -} diff --git a/locales/zh-TW/email.json b/locales/zh-TW/email.json deleted file mode 100644 index 25956fd4..00000000 --- a/locales/zh-TW/email.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "template": { - "subject": "您的報告已備妥", - "btnText": "下載报告檔案", - "fileName": "檔案名稱", - "unauth": "檔案未下載成功,請重試一次", - "readyForDownload": "您請求的報告已可下載", - "ifDidNotInitAction": "如果您未進行此操作並且懷疑您的帳戶已遭盜用,請", - "freezeAccount": "凍結您的帳戶", - "contactSupport": "以及聯絡客服人員", - "youCan": "您可以", - "download": "下載", - "pgpSignature": "PGP數位簽名檔案" - } -} diff --git a/package-lock.json b/package-lock.json index b3bf8f4e..29cf4a24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bfx-report", - "version": "4.13.1", + "version": "4.13.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bfx-report", - "version": "4.13.1", + "version": "4.13.2", "license": "Apache-2.0", "dependencies": { "ajv": "8.17.1", diff --git a/package.json b/package.json index 3fe3fc54..ab865ff9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bfx-report", - "version": "4.13.1", + "version": "4.13.2", "description": "Reporting tool", "main": "worker.js", "license": "Apache-2.0", @@ -70,8 +70,7 @@ ".idea/", ".vscode/", "csv/", - "workers/loc.api/queue/temp/", - "workers/loc.api/queue/views/" + "workers/loc.api/queue/temp/" ] }, "betterScripts": { diff --git a/test/helpers/helpers.worker.js b/test/helpers/helpers.worker.js index 398d853a..d3ad4fe1 100644 --- a/test/helpers/helpers.worker.js +++ b/test/helpers/helpers.worker.js @@ -20,7 +20,7 @@ const startHelpers = ( logs, workers = [ { name: 's3', port: 13371 }, - { name: 'sendgrid', port: 1310 }, + { name: 'mail', port: 1310 }, { name: 'gpg', port: 1320 }, { name: 'pdf', port: 1330 }, { name: 'testcalls', port: 1300 } diff --git a/test/simulate/mocks-spies/mail.js b/test/simulate/mocks-spies/mail.js new file mode 100644 index 00000000..b7f1c77f --- /dev/null +++ b/test/simulate/mocks-spies/mail.js @@ -0,0 +1,43 @@ +'use strict' + +const workerArgs = ['rest:core:mail'] + +function addFunctions (ExtApi) { + ExtApi.prototype.enqueueEmail = function (space, msg, cb) { + const { + lang, + to, + reportUrl, + fileName + } = msg?.payload + + if (!msg?.type) return cb(new Error('ERR_API_NO_TYPE')) + if (!lang) return cb(new Error('ERR_API_NO_LANGUAGE')) + if (!to) return cb(new Error('ERR_API_NO_TO')) + if (!reportUrl) return cb(new Error('ERR_API_NO_REPORT_URL')) + if (!fileName) return cb(new Error('ERR_API_NO_FILE_NAME')) + + try { + const res = ['send'] + const grcBfx = this.ctx.grc_bfx + const call = { + worker: 'core.mail', + on: 'enqueueEmail', + params: { msg }, + res: res[0], + timestamp: Date.now() + } + grcBfx.req('rest:ext:testcalls', 'addCall', [call], { timeout: 10000 }, (err, data) => { + if (err) cb(new Error('core.mail:enqueueEmail:testcalls')) + else return cb(null, res && res.length && res[0]) + }) + } catch (e) { + cb(new Error(`ERR_API_MAIL: ${e.toString()}`)) + } + } +} + +module.exports = { + addFunctions, + workerArgs +} diff --git a/test/simulate/mocks-spies/s3.js b/test/simulate/mocks-spies/s3.js index b96feeff..f7e1e75c 100644 --- a/test/simulate/mocks-spies/s3.js +++ b/test/simulate/mocks-spies/s3.js @@ -4,17 +4,15 @@ const workerArgs = ['rest:ext:s3'] function addFunctions (ExtApi) { ExtApi.prototype.uploadPresigned = function (space, data, opts, cb) { - const upload = { - public_url: 'https://fakeUrl.com', - key: 'fakeKey', - s3bucket: 'fakeBucket' + const mockedRes = { + presigned_url: 'https://fakePresignedUrl.com' } const grcBfx = this.ctx.grc_bfx const call = { worker: 'ext.s3', on: 'uploadPresigned', - params: { opts }, - res: { upload }, + params: { data, opts }, + res: mockedRes, timestamp: Date.now() } @@ -25,7 +23,7 @@ function addFunctions (ExtApi) { { timeout: 10000 }, (err, data) => { if (err) cb(new Error('ext.s3:uploadPresigned:testcalls')) - else return cb(null, upload) + else return cb(null, mockedRes) } ) } diff --git a/test/simulate/mocks-spies/sendgrid.js b/test/simulate/mocks-spies/sendgrid.js deleted file mode 100644 index b437180e..00000000 --- a/test/simulate/mocks-spies/sendgrid.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict' - -const workerArgs = ['rest:ext:sendgrid'] - -function addFunctions (ExtApi) { - ExtApi.prototype.sendEmail = function (space, msg, cb) { - const { - to, - from, - subject, - text - } = msg - - if (!to) return cb(new Error('ERR_API_NO_TO')) - if (!from) return cb(new Error('ERR_API_NO_FROM')) - if (!subject) return cb(new Error('ERR_API_NO_SUBJECT')) - if (!text) return cb(new Error('ERR_API_NO_TEXT')) - - try { - const res = ['send'] - const grcBfx = this.ctx.grc_bfx - const call = { - worker: 'ext.sendgrid', - on: 'sendEmail', - params: { msg }, - res: res[0], - timestamp: Date.now() - } - grcBfx.req('rest:ext:testcalls', 'addCall', [call], { timeout: 10000 }, (err, data) => { - if (err) cb(new Error('ext.sendgrid:sendEmail:testcalls')) - else return cb(null, res && res.length && res[0]) - }) - } catch (e) { - cb(new Error(`ERR_API_SENDGRID: ${e.toString()}`)) - } - } -} - -module.exports = { - addFunctions, - workerArgs -} diff --git a/workers/loc.api/di/app.deps.js b/workers/loc.api/di/app.deps.js index 91c69ec6..8a076fea 100644 --- a/workers/loc.api/di/app.deps.js +++ b/workers/loc.api/di/app.deps.js @@ -173,8 +173,7 @@ module.exports = ({ bindDepsToFn( sendMail, [ - TYPES.GrcBfxReq, - TYPES.I18next + TYPES.GrcBfxReq ] ) ) diff --git a/workers/loc.api/generate-report-file/index.js b/workers/loc.api/generate-report-file/index.js index 3952cc55..1625ef8e 100644 --- a/workers/loc.api/generate-report-file/index.js +++ b/workers/loc.api/generate-report-file/index.js @@ -50,7 +50,7 @@ const _getReportFileStoreStatus = async ({ } } - if (!await hasGrcService.hasS3AndSendgrid()) { + if (!await hasGrcService.hasS3AndMailServices()) { throw new EmailSendingError() } if ( diff --git a/workers/loc.api/has.grc.service/index.js b/workers/loc.api/has.grc.service/index.js index 65459346..1f3dad77 100644 --- a/workers/loc.api/has.grc.service/index.js +++ b/workers/loc.api/has.grc.service/index.js @@ -29,15 +29,15 @@ class HasGrcService { } } - async hasS3AndSendgrid () { + async hasS3AndMailServices () { const countS3Services = await this.lookUpFunction( 'rest:ext:s3' ) - const countSendgridServices = await this.lookUpFunction( - 'rest:ext:sendgrid' + const countMailServices = await this.lookUpFunction( + 'rest:core:mail' ) - return !!(countS3Services && countSendgridServices) + return !!(countS3Services && countMailServices) } async hasGPGService () { diff --git a/workers/loc.api/i18next/index.js b/workers/loc.api/i18next/index.js index a344d24a..646c4565 100644 --- a/workers/loc.api/i18next/index.js +++ b/workers/loc.api/i18next/index.js @@ -29,7 +29,7 @@ module.exports = (params) => { default: ['en'] }, ns: Object.values(TRANSLATION_NAMESPACES), - defaultNS: 'email', + defaultNS: TRANSLATION_NAMESPACES.PDF, preload: [...transPaths.reduce((accum, transPath) => { const allFileNames = fs.readdirSync(transPath) diff --git a/workers/loc.api/i18next/translation.namespaces.js b/workers/loc.api/i18next/translation.namespaces.js index 9932066f..00e63753 100644 --- a/workers/loc.api/i18next/translation.namespaces.js +++ b/workers/loc.api/i18next/translation.namespaces.js @@ -1,7 +1,6 @@ 'use strict' const TRANSLATION_NAMESPACES = { - EMAIL: 'email', PDF: 'pdf' } diff --git a/workers/loc.api/queue/aggregator.js b/workers/loc.api/queue/aggregator.js index 46a893f5..ce3829b2 100644 --- a/workers/loc.api/queue/aggregator.js +++ b/workers/loc.api/queue/aggregator.js @@ -29,13 +29,12 @@ module.exports = ( email, isUnauth, s3Conf, - emailConf, language } = job.data const isEnableToSendEmail = ( typeof email === 'string' && - await hasGrcService.hasS3AndSendgrid() + await hasGrcService.hasS3AndMailServices() ) const newFilePaths = [] @@ -55,9 +54,7 @@ module.exports = ( ) await sendMail( - emailConf, email, - 'email.pug', s3Data.map((item, i) => ({ ...item, isUnauth, diff --git a/workers/loc.api/queue/processor.js b/workers/loc.api/queue/processor.js index d739bc49..1ac7bda2 100644 --- a/workers/loc.api/queue/processor.js +++ b/workers/loc.api/queue/processor.js @@ -88,7 +88,6 @@ module.exports = ( processorQueue.on('completed', (result) => { aggregatorQueue.addJob({ ...result, - emailConf: conf.emailConf, s3Conf: conf.s3Conf }) }) diff --git a/workers/loc.api/queue/send-mail/index.js b/workers/loc.api/queue/send-mail/index.js index 1dfadd91..aded590d 100644 --- a/workers/loc.api/queue/send-mail/index.js +++ b/workers/loc.api/queue/send-mail/index.js @@ -1,84 +1,32 @@ 'use strict' -const path = require('path') -const pug = require('pug') - -const getTranslator = require('../../helpers/get-translator') -const TRANSLATION_NAMESPACES = require( - '../../i18next/translation.namespaces' -) - -const basePathToViews = path.join(__dirname, 'views') - -const SENDGRID_WORKER_SUPPORTED_LNGS = { - en: 'en', - 'en-US': 'en', - ru: 'ru', - 'ru-RU': 'ru', - zh: 'zh-CN', - 'zh-CN': 'zh-CN', - 'zh-TW': 'zh-TW', - pt: 'pt-BR', - 'pt-PT': 'pt-BR', - 'pt-BR': 'pt-BR' -} - -const _getSendgridLng = (lng) => { - return SENDGRID_WORKER_SUPPORTED_LNGS[lng] ?? lng -} - -module.exports = (grcBfxReq, i18next) => { +module.exports = (grcBfxReq) => { return async ( - configs, to, - viewName, dataArr ) => { - const pathToView = path.join(basePathToViews, viewName) - const promises = dataArr.map(data => { const { - presigned_url: url, - language = 'en' + presigned_url: reportUrl, + language, + fileName, + isUnauth, + signatureS3 } = data ?? {} - const translate = getTranslator( - { i18next }, - { - lng: language, - ns: TRANSLATION_NAMESPACES.EMAIL - } - ) - const subject = translate( - configs.subject, - 'template.subject' - ) - const text = pug.renderFile( - pathToView, - { - ...data, - filters: { translate } - } - ) - const button = { - url, - text: translate( - 'Download Report', - 'template.btnText' - ) - } - const mailOptions = { - ...configs, + + const payload = { + lang: language ?? 'en', to, - text, - subject, - button, - language: _getSendgridLng(language) + reportUrl, + fileName, + signatureS3, + isUnauth } return grcBfxReq({ - service: 'rest:ext:sendgrid', - action: 'sendEmail', - args: [mailOptions] + service: 'rest:core:mail', + action: 'enqueueEmail', + args: [{ type: 'reportDownloadReady', payload }] }) }) diff --git a/workers/loc.api/queue/send-mail/views/email.pug b/workers/loc.api/queue/send-mail/views/email.pug deleted file mode 100644 index 3d1387d0..00000000 --- a/workers/loc.api/queue/send-mail/views/email.pug +++ /dev/null @@ -1,46 +0,0 @@ -if isUnauth - p - :translate(prop='template.unauth') - Your file could not be completed, please try again -else - p(style='color: #606060;font-size: 15px;line-height: 150%;') - :translate(prop='template.readyForDownload') - The report you request is ready for download - p(style='color: #606060;font-size: 15px;line-height: 150%;') - :translate(prop='template.fileName') - File name - | : - b(style='margin-left: 5px;') - | #{fileName} - if signatureS3 - p(style='color: #606060;font-size: 15px;line-height: 150%;') - :translate(prop='template.youCan') - You can - a( - style=` - margin:0 5px;letter-spacing:.7;line-height:100%; - text-decoration:none;color:#4995c4;word-wrap:break-word; - ` - target='_blank' - href=signatureS3.presigned_url - ) - :translate(prop='template.download') - download - :translate(prop='template.pgpSignature') - PGP digital signature file - - p(style='color: #606060;font-size: 15px;line-height: 150%;') - :translate(prop='template.ifDidNotInitAction') - If you did not initiate this action and you suspect that your account may be compromised, please - - a( - href='https://www.bitfinex.com/freeze', - target='_blank', - style='text-decoration: none; color: #4995c4' - ) - |  - :translate(prop='template.freezeAccount') - freeze your account - |  - :translate(prop='template.contactSupport') - and contact support diff --git a/workers/loc.api/responder/index.js b/workers/loc.api/responder/index.js index 84c07eab..6ec75658 100644 --- a/workers/loc.api/responder/index.js +++ b/workers/loc.api/responder/index.js @@ -173,7 +173,9 @@ const _getErrorMetadata = (args, err, name) => { 'subAccountApiKeys', 'subAccountPassword', 'addingSubUsers', - 'removingSubUsersByEmails' + 'removingSubUsersByEmails', + 'login', + 'password' ]) : args?.params ?? null const extendedData = {