From 20aa4251cf3a1ef0193f03afaccf66853432e580 Mon Sep 17 00:00:00 2001 From: Samir Gondzetovic Date: Tue, 14 Aug 2018 12:48:40 +0100 Subject: [PATCH 1/2] add transactional templates support; remove placeholders service;NOTE: all templates should be migrated to transactional (v3) templates before deployment --- connect/service.js | 3 +- package-lock.json | 159 ++++++++++++++++++-------- package.json | 4 +- src/bootstrap.js | 4 +- src/controllers/TemplateController.js | 20 ---- src/routes.js | 6 - src/services/TemplateService.js | 79 ------------- 7 files changed, 118 insertions(+), 157 deletions(-) delete mode 100644 src/controllers/TemplateController.js delete mode 100644 src/services/TemplateService.js diff --git a/connect/service.js b/connect/service.js index 4750b9b..fee178e 100644 --- a/connect/service.js +++ b/connect/service.js @@ -22,9 +22,8 @@ const sendEmail = (templateId, message) => { // send email return sgMail.send({ to, templateId, - substitutions, + dynamicTemplateData: substitutions, from, - substitutionWrappers: ['{{', '}}'], replyTo, categories, cc, diff --git a/package-lock.json b/package-lock.json index 0c46d21..c6915b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,58 +5,64 @@ "requires": true, "dependencies": { "@sendgrid/client": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-6.2.1.tgz", - "integrity": "sha512-FLqoh2UqmFs5R/92xzF1jYMLGU89rTgLK6XX+VA02YcfQW8rGjbMrj7zsSCQ7SLkeiWekmUU2+naeIO9L4dqxA==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-6.3.0.tgz", + "integrity": "sha512-fTy8vRpA9Whtf8ULQr/0vkSZaQvGQ97rY5N5PrevKRtugJMsJqFMKO0pwzEWeqITSg71aMMTj57QTgw3SjZvnQ==", "requires": { - "@sendgrid/helpers": "6.2.1", - "@types/request": "2.0.13", + "@sendgrid/helpers": "6.3.0", + "@types/request": "2.47.1", "request": "2.83.0" } }, "@sendgrid/helpers": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/@sendgrid/helpers/-/helpers-6.2.1.tgz", - "integrity": "sha512-WnQ4TV51Xln/X70lk6J1/3tfRHW3K4zagz19vlJrtQUtX1wwghOj926OqcMm5nOiBHEh+la3cvdzHENb09FsIA==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@sendgrid/helpers/-/helpers-6.3.0.tgz", + "integrity": "sha512-uTFcmhCDFg/2Uhz+z/cLwyLHH0UsblG49hKwdR7nKbWsGKWv4js7W32FlPdXqy2C/plTJ20vcPLgKM1m3F/MjQ==", "requires": { - "chalk": "2.3.0" + "chalk": "2.4.1", + "deepmerge": "2.1.1" }, "dependencies": { "ansi-styles": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", - "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "requires": { - "color-convert": "1.9.1" + "color-convert": "1.9.2" } }, "chalk": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", - "integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", "requires": { - "ansi-styles": "3.2.0", + "ansi-styles": "3.2.1", "escape-string-regexp": "1.0.5", - "supports-color": "4.5.0" + "supports-color": "5.4.0" } }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, "supports-color": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", - "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "requires": { - "has-flag": "2.0.0" + "has-flag": "3.0.0" } } } }, "@sendgrid/mail": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-6.2.1.tgz", - "integrity": "sha512-gTd8gMp4JVLGZhXb/DkyrjByTfIR1OvtpPpQLwO11Vz72x3JdPl4tJTtWA/svAFfN5UXnZtAomAvjJCdcd4lzw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-6.3.1.tgz", + "integrity": "sha512-5zIeAV9iU+0hQkrOQ/D4RB2MfpK+lNbOortIfQdCh95aMDF/TRc9WB8FGNhmQrx9YMuJTms5eiBklF0Fi/dbVg==", "requires": { - "@sendgrid/client": "6.2.1", - "@sendgrid/helpers": "6.2.1" + "@sendgrid/client": "6.3.0", + "@sendgrid/helpers": "6.3.0" } }, "@types/bluebird": { @@ -73,6 +79,11 @@ "@types/node": "9.4.0" } }, + "@types/caseless": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.1.tgz", + "integrity": "sha512-FhlMa34NHp9K5MY1Uz8yb+ZvuX0pnvn3jScRSNAb75KHGB8d3rEU6hqMs3Z2vjuytcMfRg6c5CHMc3wtYyD2/A==" + }, "@types/events": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-1.1.0.tgz", @@ -143,13 +154,14 @@ "integrity": "sha512-zkYho6/4wZyX6o9UQ8rd0ReEaiEYNNCqYFIAACe2Tf9DrYlgzWW27OigYHnnztnnZQwVRpwWmZKegFmDpinIsA==" }, "@types/request": { - "version": "2.0.13", - "resolved": "https://registry.npmjs.org/@types/request/-/request-2.0.13.tgz", - "integrity": "sha512-AHX0Qe6+C6AdEG1YII35eL88L6dqwUzsZowOuewxz71qOY4L7fJpy2BPHijdou2ZEC3DSALA65FL0k7dj1u+3g==", + "version": "2.47.1", + "resolved": "https://registry.npmjs.org/@types/request/-/request-2.47.1.tgz", + "integrity": "sha512-TV3XLvDjQbIeVxJ1Z3oCTDk/KuYwwcNKVwz2YaT0F5u86Prgc4syDAp6P96rkTQQ4bIdh+VswQIC9zS6NjY7/g==", "requires": { + "@types/caseless": "0.12.1", "@types/form-data": "2.2.1", "@types/node": "9.4.0", - "@types/tough-cookie": "2.3.2" + "@types/tough-cookie": "2.3.3" } }, "@types/serve-static": { @@ -162,9 +174,9 @@ } }, "@types/tough-cookie": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.2.tgz", - "integrity": "sha512-vOVmaruQG5EatOU/jM6yU2uCp3Lz6mK1P5Ztu4iJjfM4SVHU9XYktPUQtKlIXuahqXHdEyUarMrBEwg5Cwu+bA==" + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.3.tgz", + "integrity": "sha512-MDQLxNFRLasqS4UlkWMSACMKeSm1x4Q3TxzUC7KQUsh6RK1ZrQ0VEyE3yzXcBu+K8ejVj4wuX32eUG02yNp+YQ==" }, "accepts": { "version": "1.3.4", @@ -294,6 +306,20 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, + "auth0-js": { + "version": "9.7.3", + "resolved": "https://registry.npmjs.org/auth0-js/-/auth0-js-9.7.3.tgz", + "integrity": "sha512-iZAqoN4EbsNCS/3VkFPNb4glTyj8hq57T7gcUF+XH8Rua7hBTUzpb101K9zqcdUIBilIdF9XBLCTJ4JGgZ/oFA==", + "requires": { + "base64-js": "1.3.0", + "idtoken-verifier": "1.2.0", + "js-cookie": "2.2.0", + "qs": "6.5.1", + "superagent": "3.8.2", + "url-join": "1.1.0", + "winchan": "0.2.0" + } + }, "aws-sign2": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", @@ -333,6 +359,11 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, + "base64-js": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", + "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==" + }, "base64url": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", @@ -549,17 +580,17 @@ } }, "color-convert": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", - "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.2.tgz", + "integrity": "sha512-3NUJZdhMhcdPn8vJ9v2UQJoH0qqoGUkYTgFEPZaPjEtwmmKUfNV46zZmgB2M5M4DCEQHMaCfWHCxiBflLm04Tg==", "requires": { - "color-name": "1.1.3" + "color-name": "1.1.1" } }, "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha1-SxQVMEz1ACjqgWQ2Q72C6gWANok=" }, "colors": { "version": "1.0.3", @@ -697,6 +728,11 @@ } } }, + "crypto-js": { + "version": "3.1.9-1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.9-1.tgz", + "integrity": "sha1-/aGedh/Ad+Af+/3G6f38WeiAbNg=" + }, "cycle": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", @@ -742,6 +778,11 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "deepmerge": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-2.1.1.tgz", + "integrity": "sha512-urQxA1smbLZ2cBbXbaYObM1dJ82aJ2H57A1C/Kklfh/ZN1bgH4G/n5KWhdNfOK11W98gqZfyYj7W4frJJRwA2w==" + }, "define-properties": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz", @@ -1433,7 +1474,8 @@ "has-flag": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", - "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", + "dev": true }, "hashring": { "version": "3.2.0", @@ -1499,6 +1541,18 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" }, + "idtoken-verifier": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/idtoken-verifier/-/idtoken-verifier-1.2.0.tgz", + "integrity": "sha512-8jmmFHwdPz8L73zGNAXHHOV9yXNC+Z0TUBN5rafpoaFaLFltlIFr1JkQa3FYAETP23eSsulVw0sBiwrE8jqbUg==", + "requires": { + "base64-js": "1.3.0", + "crypto-js": "3.1.9-1", + "jsbn": "0.1.1", + "superagent": "3.8.2", + "url-join": "1.1.0" + } + }, "ignore": { "version": "3.3.7", "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.7.tgz", @@ -1663,6 +1717,11 @@ "topo": "2.0.2" } }, + "js-cookie": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.0.tgz", + "integrity": "sha1-Gywnmm7s44ChIWi5JIUmWzWx7/s=" + }, "js-string-escape": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/js-string-escape/-/js-string-escape-1.0.1.tgz", @@ -1681,8 +1740,7 @@ "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "optional": true + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, "json-schema": { "version": "0.2.3", @@ -2868,8 +2926,9 @@ } }, "tc-core-library-js": { - "version": "github:gondzo/tc-core-library-js#38bb886089822b96726180179c01cedc1291bef3", + "version": "github:appirio-tech/tc-core-library-js#df1f5c1a5578d3d1e475bfb4a7413d9dec25525a", "requires": { + "auth0-js": "9.7.3", "axios": "0.12.0", "bunyan": "1.8.12", "config": "1.29.2", @@ -2977,6 +3036,11 @@ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, + "url-join": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-1.1.0.tgz", + "integrity": "sha1-dBxsL0WWxIMNZxhGCSDQySIC3Hg=" + }, "user-home": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/user-home/-/user-home-2.0.0.tgz", @@ -3026,6 +3090,11 @@ "resolved": "https://registry.npmjs.org/very-fast-args/-/very-fast-args-1.1.0.tgz", "integrity": "sha1-4W0dH6+KbllqJGQh/ZCneWPQs5Y=" }, + "winchan": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/winchan/-/winchan-0.2.0.tgz", + "integrity": "sha1-OGMCjn+XSw2hQS8oQXukJJcqvZQ=" + }, "winston": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.0.tgz", diff --git a/package.json b/package.json index fb70227..17f83ab 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "mocha": "^5.0.0" }, "dependencies": { - "@sendgrid/client": "^6.2.1", - "@sendgrid/mail": "^6.2.1", + "@sendgrid/client": "^6.3.0", + "@sendgrid/mail": "^6.3.0", "bluebird": "^3.5.1", "body-parser": "^1.15.2", "co": "^4.6.0", diff --git a/src/bootstrap.js b/src/bootstrap.js index 38cc33d..2e19a05 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -5,6 +5,4 @@ 'use strict'; global.Promise = require('bluebird'); -const logger = require('./common/logger'); - -logger.buildService(require('./services/TemplateService')); +const logger = require('./common/logger'); \ No newline at end of file diff --git a/src/controllers/TemplateController.js b/src/controllers/TemplateController.js deleted file mode 100644 index ea8c18a..0000000 --- a/src/controllers/TemplateController.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Contains endpoints related to template controller - */ -'use strict'; - -const TemplateService = require('../services/TemplateService'); - -/** - * Get list with email template placeholder names. - * @param req the request - * @param res the response - */ -function* eventTypes(req, res) { - res.json(yield TemplateService.listPlaceholders(req.params.name)); -} - -// Exports -module.exports = { - eventTypes, -}; diff --git a/src/routes.js b/src/routes.js index 4fe56d5..a88189b 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,12 +1,6 @@ 'use strict'; module.exports = { - '/templates/:name': { - get: { - controller: 'TemplateController', - method: 'eventTypes', - }, - }, '/health': { get: { controller: 'HealthController', diff --git a/src/services/TemplateService.js b/src/services/TemplateService.js deleted file mode 100644 index 493e729..0000000 --- a/src/services/TemplateService.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Service for email template placeholders. - */ - -'use strict'; - -const _ = require('lodash'); -const client = require('@sendgrid/client'); -const config = require('config'); -const Joi = require('joi'); -const errors = require('../common/errors'); -const logger = require('../common/logger'); - -// set api key for SendGrid email client -client.setApiKey(config.SENDGRID_API_KEY); - -/** - * Find placeholders inside html template string. - * - * @param {String} html the html string with template - * @return {Array} the list of placeholders names - */ -function* _findPlaceholders(html) { - const pattern = /{{(.*?)}}/g; - const placeholders = []; - let match = pattern.exec(html); - while (match != null) { - // ignore duplicates and empty placeholder - if (match[1].length > 0 && !_.includes(placeholders, match[1])) { - placeholders.push(match[1]); - } - match = pattern.exec(html); - } - return placeholders; -} - -/** - * Get email template placeholder name. - * - * @param {String} name the Kafka topic name - * @return {Array} the list of email template placeholder names - */ -function* listPlaceholders(name) { - const templateId = config.TEMPLATE_MAP[name]; - if (templateId === undefined) { - throw new errors.BadRequestError(`Topic ${name} was not found`); - } - - try { - const response = yield client.request({ - method: 'GET', - url: '/v3/templates/' + templateId, - }); - - const template = response[0].body; - if (template.versions.length === 0) { - throw new errors.NotFoundError(`Template with id ${templateId} has no version in SendGrid`); - } - logger.debug(template.versions[0]); - - return yield _findPlaceholders(template.versions[0].html_content + template.versions[0].subject); - } catch (err) { - if (err.code === 404) { - throw new errors.NotFoundError(`Template with id ${templateId} for topic ${name} not found in SendGrid`); - } else if (err.code === 403) { - throw new errors.ForbiddenError('Sendgrid API key is invalid'); - } else { - throw err; - } - } -} - -listPlaceholders.schema = { - name: Joi.string().required(), -}; - -module.exports = { - listPlaceholders, -}; From 89cc9cb041e52882a9cfac3de618e70f49818be8 Mon Sep 17 00:00:00 2001 From: Samir Gondzetovic Date: Tue, 21 Aug 2018 00:28:13 +0100 Subject: [PATCH 2/2] update docs; add email retry max age config variable --- config/default.js | 2 + docs/swagger_api.yaml | 34 +-- ...c-email-server-api.postman_collection.json | 249 +----------------- src/app.js | 3 +- 4 files changed, 13 insertions(+), 275 deletions(-) diff --git a/config/default.js b/config/default.js index 97737d2..b0ce117 100644 --- a/config/default.js +++ b/config/default.js @@ -38,6 +38,8 @@ module.exports = { //in every 2 minutes will retry for failed status EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *', + //wont't retry failed emails older than this time (msec) + EMAIL_RETRY_MAX_AGE: process.env.EMAIL_RETRY_MAX_AGE || 1000*60*60*24, API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email', diff --git a/docs/swagger_api.yaml b/docs/swagger_api.yaml index 1a8c8a5..05f4421 100644 --- a/docs/swagger_api.yaml +++ b/docs/swagger_api.yaml @@ -15,46 +15,20 @@ securityDefinitions: description: JWT Authentication. Provide API Key in the form 'Bearer <token>'. paths: - /templates/{name}: + /health: get: description: - get email template placholders name + health check endpoint produces: - application/json - security: - - jwt: [] - parameters: - - name: name - in: path - description: The Kafka topic name - required: true - type: string responses: 200: description: OK schema: type: object properties: - items: - type: array - items: - type: string - 400: - description: "Bad request error." - schema: - $ref: "#/definitions/Error" - 404: - description: "Template is not found error." - schema: - $ref: "#/definitions/Error" - 401: - description: "Authentication failed." - schema: - $ref: "#/definitions/Error" - 500: - description: "Internal server error." - schema: - $ref: "#/definitions/Error" + health: + type: string definitions: Error: properties: diff --git a/docs/tc-email-server-api.postman_collection.json b/docs/tc-email-server-api.postman_collection.json index 2ac52a3..53b387e 100644 --- a/docs/tc-email-server-api.postman_collection.json +++ b/docs/tc-email-server-api.postman_collection.json @@ -1,239 +1,18 @@ { + "variables": [], "info": { "name": "tc-email-server-api", - "_postman_id": "f9d855bc-e0a5-3501-ab56-9a144830c431", + "_postman_id": "1b69bb54-1908-a951-8597-aa50db53b5ba", "description": "", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" }, "item": [ { - "name": "failure", - "description": "", - "item": [ - { - "name": "Email - invalid token", - "event": [ - { - "listen": "test", - "script": { - "id": "6bbbb6e1-3ef8-4e4e-802e-c6bfd892378c", - "type": "text/javascript", - "exec": [ - "pm.test(\"Invalid GET request\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([403]);", - "});" - ] - } - } - ], - "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "BAD_TOKEN", - "type": "string" - } - ] - }, - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "{{URL}}/email.project.created", - "host": [ - "{{URL}}" - ], - "path": [ - "email.project.created" - ] - }, - "description": "" - }, - "response": [] - }, - { - "name": "Email - invalid topic", - "event": [ - { - "listen": "test", - "script": { - "id": "5a75ca22-fb44-4a40-b6fa-d47f7421465b", - "type": "text/javascript", - "exec": [ - "pm.test(\"Bad request GET request\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});" - ] - } - } - ], - "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{TC_ADMIN_TOKEN}}", - "type": "string" - } - ] - }, - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "{{URL}}/email.invalid", - "host": [ - "{{URL}}" - ], - "path": [ - "email.invalid" - ] - }, - "description": "" - }, - "response": [] - }, - { - "name": "Email - invalid template", - "event": [ - { - "listen": "test", - "script": { - "id": "2e5a6ff8-bd38-457a-8c94-5cb745e11de5", - "type": "text/javascript", - "exec": [ - "pm.test(\"Not found GET request\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});" - ] - } - } - ], - "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{TC_ADMIN_TOKEN}}", - "type": "string" - } - ] - }, - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "{{URL}}/email.tempate.invalid", - "host": [ - "{{URL}}" - ], - "path": [ - "email.tempate.invalid" - ] - }, - "description": "" - }, - "response": [] - }, - { - "name": "Email - invalid template version", - "event": [ - { - "listen": "test", - "script": { - "id": "2e5a6ff8-bd38-457a-8c94-5cb745e11de5", - "type": "text/javascript", - "exec": [ - "pm.test(\"Not found GET request\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});" - ] - } - } - ], - "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{TC_ADMIN_TOKEN}}", - "type": "string" - } - ] - }, - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "{{URL}}/email.template.no.version", - "host": [ - "{{URL}}" - ], - "path": [ - "email.template.no.version" - ] - }, - "description": "" - }, - "response": [] - } - ] - }, - { - "name": "Email - project.created", - "event": [ - { - "listen": "test", - "script": { - "id": "db43bdd5-1b84-42c3-9033-59a8756ab3ba", - "type": "text/javascript", - "exec": [ - "pm.test(\"Successful GET request\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,204]);", - "});" - ] - } - } - ], - "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{TC_ADMIN_TOKEN}}", - "type": "string" - } - ] - }, - "method": "GET", - "header": [], - "body": {}, - "url": { - "raw": "{{URL}}/email.project.created", - "host": [ - "{{URL}}" - ], - "path": [ - "email.project.created" - ] - }, - "description": "" - }, - "response": [] - }, - { - "name": "Email - project.updated", + "name": "Health", "event": [ { "listen": "test", "script": { - "id": "9732b9ef-c3b0-4ea3-92e3-624f9e84c6e6", "type": "text/javascript", "exec": [ "pm.test(\"Successful GET request\", function () {", @@ -244,28 +23,10 @@ } ], "request": { - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{TC_ADMIN_TOKEN}}", - "type": "string" - } - ] - }, + "url": "{{URL}}/health", "method": "GET", "header": [], "body": {}, - "url": { - "raw": "{{URL}}/email.project.updated", - "host": [ - "{{URL}}" - ], - "path": [ - "email.project.updated" - ] - }, "description": "" }, "response": [] diff --git a/src/app.js b/src/app.js index c4d5565..cba5835 100644 --- a/src/app.js +++ b/src/app.js @@ -140,7 +140,8 @@ function startKafkaConsumer(consumer, handlers, dataHandler) { * @param {Object} handlers the handlers */ function retryEmail(handlers) { - return models.Email.findAll({ where: { status: 'FAILED' } }).then((models) => { + return models.Email.findAll({ where: { status: 'FAILED', createdAt: { $gt: new Date(new Date() - config.EMAIL_RETRY_MAX_AGE) }} }) + .then((models) => { if (models.length > 0) { logger.info(`Found ${models.length} e-mails to be resent`); return Promise.each(models, (m) => {