From bf26ff45db51af2d29a9481ad9a33644007b7970 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 26 Nov 2021 06:04:08 +0000 Subject: [PATCH] chore(deps-dev): bump prettier from 2.4.1 to 2.5.0 (#3102) * chore(deps-dev): bump prettier from 2.4.1 to 2.5.0 Bumps [prettier](https://github.com/prettier/prettier) from 2.4.1 to 2.5.0. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.4.1...2.5.0) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: run lint Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kar Rui Lau --- package-lock.json | 16 +- package.json | 2 +- src/app/modules/bounce/bounce.controller.ts | 185 +++++++++--------- .../field-validation/validators/common.ts | 17 +- .../views/edit-contact-number-modal.view.html | 7 +- .../edit-logic.client.view.html | 5 +- .../form-emails-input.client.view.html | 5 +- .../admin/views/admin-form.client.view.html | 7 +- .../views/collaborator.client.modal.html | 10 +- .../views/edit-end-page.client.modal.html | 8 +- .../admin/views/edit-fields.client.modal.html | 8 +- .../admin/views/edit-logic.client.modal.html | 18 +- .../views/edit-myinfo-field.client.modal.html | 8 +- .../views/edit-start-page.client.modal.html | 8 +- .../admin/views/list-forms.client.view.html | 15 +- .../field-attachment.client.view.html | 7 +- 16 files changed, 130 insertions(+), 196 deletions(-) diff --git a/package-lock.json b/package-lock.json index c9c79ec03b..4779fc9195 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13481,7 +13481,8 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", - "dev": true + "dev": true, + "optional": true }, "handlebars": { "version": "4.7.7", @@ -14804,6 +14805,7 @@ "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", "dev": true, + "optional": true, "requires": { "is-docker": "^2.0.0" } @@ -18797,6 +18799,7 @@ "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.2.tgz", "integrity": "sha512-oJP/9NAdd9+x2Q+rfphB2RJCHjod70RcRLjosiPMMu5gjIfwVnOUGq2nbTjTUbmy0DJ/tFIVT30+Qe3nzl4TJg==", "dev": true, + "optional": true, "requires": { "growly": "^1.3.0", "is-wsl": "^2.2.0", @@ -18811,6 +18814,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", "dev": true, + "optional": true, "requires": { "lru-cache": "^6.0.0" } @@ -18820,6 +18824,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, + "optional": true, "requires": { "isexe": "^2.0.0" } @@ -20212,9 +20217,9 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" }, "prettier": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz", - "integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.0.tgz", + "integrity": "sha512-FM/zAKgWTxj40rH03VxzIPdXmj39SwSjwG0heUcNFwI+EMZJnY93yAiKXM3dObIKAM5TA88werc8T/EwhB45eg==", "dev": true }, "prettier-linter-helpers": { @@ -21727,7 +21732,8 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", - "dev": true + "dev": true, + "optional": true }, "side-channel": { "version": "1.0.4", diff --git a/package.json b/package.json index 3d093e403b..a064831234 100644 --- a/package.json +++ b/package.json @@ -232,7 +232,7 @@ "mongodb-memory-server-core": "^6.9.6", "ngrok": "^4.2.2", "optimize-css-assets-webpack-plugin": "^5.0.8", - "prettier": "^2.4.1", + "prettier": "^2.5.0", "proxyquire": "^2.1.3", "regenerator": "^0.14.4", "rimraf": "^3.0.2", diff --git a/src/app/modules/bounce/bounce.controller.ts b/src/app/modules/bounce/bounce.controller.ts index 7b0e065500..404cd59568 100644 --- a/src/app/modules/bounce/bounce.controller.ts +++ b/src/app/modules/bounce/bounce.controller.ts @@ -18,104 +18,105 @@ const logger = createLoggerWithLabel(module) * @param req Express request object * @param res - Express response object */ -export const handleSns: ControllerHandler = - async (req, res) => { - const notificationResult = await BounceService.validateSnsRequest( - req.body, - ).andThen(() => BounceService.safeParseNotification(req.body.Message)) - if (notificationResult.isErr()) { - logger.warn({ - message: 'Unable to parse email notification request', - meta: { - action: 'handleSns', - }, - error: notificationResult.error, - }) - return res.sendStatus(StatusCodes.UNAUTHORIZED) - } - const notification = notificationResult.value +export const handleSns: ControllerHandler< + unknown, + never, + ISnsNotification +> = async (req, res) => { + const notificationResult = await BounceService.validateSnsRequest( + req.body, + ).andThen(() => BounceService.safeParseNotification(req.body.Message)) + if (notificationResult.isErr()) { + logger.warn({ + message: 'Unable to parse email notification request', + meta: { + action: 'handleSns', + }, + error: notificationResult.error, + }) + return res.sendStatus(StatusCodes.UNAUTHORIZED) + } + const notification = notificationResult.value - BounceService.logEmailNotification(notification) - // If not admin response, no more action to be taken - if ( - BounceService.extractEmailType(notification) !== EmailType.AdminResponse - ) { - return res.sendStatus(StatusCodes.OK) - } + BounceService.logEmailNotification(notification) + // If not admin response, no more action to be taken + if ( + BounceService.extractEmailType(notification) !== EmailType.AdminResponse + ) { + return res.sendStatus(StatusCodes.OK) + } - const bounceDocResult = await BounceService.getUpdatedBounceDoc( - notification, - ) - if (bounceDocResult.isErr()) { - logger.warn({ - message: 'Error while retrieving or creating new bounce doc', - meta: { - action: 'handleSns', - }, - error: bounceDocResult.error, - }) - return res.sendStatus(StatusCodes.OK) - } - const bounceDoc = bounceDocResult.value + const bounceDocResult = await BounceService.getUpdatedBounceDoc(notification) + if (bounceDocResult.isErr()) { + logger.warn({ + message: 'Error while retrieving or creating new bounce doc', + meta: { + action: 'handleSns', + }, + error: bounceDocResult.error, + }) + return res.sendStatus(StatusCodes.OK) + } + const bounceDoc = bounceDocResult.value - const formResult = await FormService.retrieveFullFormById(bounceDoc.formId) - if (formResult.isErr()) { - // Either database error occurred or the formId saved in the bounce collection - // doesn't exist, so something went wrong. - logger.error({ - message: 'Failed to retrieve form corresponding to bounced formId', - meta: { - action: 'handleSns', - formId: bounceDoc.formId, - }, - }) - return res.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR) - } - const form = formResult.value + const formResult = await FormService.retrieveFullFormById(bounceDoc.formId) + if (formResult.isErr()) { + // Either database error occurred or the formId saved in the bounce collection + // doesn't exist, so something went wrong. + logger.error({ + message: 'Failed to retrieve form corresponding to bounced formId', + meta: { + action: 'handleSns', + formId: bounceDoc.formId, + }, + }) + return res.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR) + } + const form = formResult.value - if (bounceDoc.isCriticalBounce()) { - // Send notifications and deactivate form on best-effort basis, ignore errors - const possibleSmsRecipients = - await BounceService.getEditorsWithContactNumbers(form).unwrapOr([]) - const emailRecipients = await BounceService.sendEmailBounceNotification( - bounceDoc, - form, - ).unwrapOr([]) - const smsRecipients = await BounceService.sendSmsBounceNotification( - bounceDoc, + if (bounceDoc.isCriticalBounce()) { + // Send notifications and deactivate form on best-effort basis, ignore errors + const possibleSmsRecipients = + await BounceService.getEditorsWithContactNumbers(form).unwrapOr([]) + const emailRecipients = await BounceService.sendEmailBounceNotification( + bounceDoc, + form, + ).unwrapOr([]) + const smsRecipients = await BounceService.sendSmsBounceNotification( + bounceDoc, + form, + possibleSmsRecipients, + ).unwrapOr([]) + bounceDoc.setNotificationState(emailRecipients, smsRecipients) + + const shouldDeactivate = bounceDoc.areAllPermanentBounces() + if (shouldDeactivate) { + await FormService.deactivateForm(bounceDoc.formId) + await BounceService.notifyAdminsOfDeactivation( form, possibleSmsRecipients, - ).unwrapOr([]) - bounceDoc.setNotificationState(emailRecipients, smsRecipients) - - const shouldDeactivate = bounceDoc.areAllPermanentBounces() - if (shouldDeactivate) { - await FormService.deactivateForm(bounceDoc.formId) - await BounceService.notifyAdminsOfDeactivation( - form, - possibleSmsRecipients, - ) - } - - // Important log message for user follow-ups - BounceService.logCriticalBounce({ - bounceDoc, - notification, - autoEmailRecipients: emailRecipients, - autoSmsRecipients: smsRecipients, - hasDeactivated: shouldDeactivate, - }) + ) } - return BounceService.saveBounceDoc(bounceDoc) - .map(() => res.sendStatus(StatusCodes.OK)) - .mapErr((error) => { - // Accept the risk that there might be concurrency problems - // when multiple server instances try to access the same - // document, due to notifications arriving asynchronously. - if (error instanceof DatabaseConflictError) - return res.sendStatus(StatusCodes.OK) - // Otherwise internal database error - return res.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR) - }) + // Important log message for user follow-ups + BounceService.logCriticalBounce({ + bounceDoc, + notification, + autoEmailRecipients: emailRecipients, + autoSmsRecipients: smsRecipients, + hasDeactivated: shouldDeactivate, + }) } + + return BounceService.saveBounceDoc(bounceDoc) + .map(() => res.sendStatus(StatusCodes.OK)) + .mapErr((error) => { + // Accept the risk that there might be concurrency problems + // when multiple server instances try to access the same + // document, due to notifications arriving asynchronously. + if (error instanceof DatabaseConflictError) + return res.sendStatus(StatusCodes.OK) + // Otherwise internal database error + return res.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR) + }) +} diff --git a/src/app/utils/field-validation/validators/common.ts b/src/app/utils/field-validation/validators/common.ts index 73f4715510..f337bc4e1e 100644 --- a/src/app/utils/field-validation/validators/common.ts +++ b/src/app/utils/field-validation/validators/common.ts @@ -12,14 +12,15 @@ import { ProcessedSingleAnswerResponse } from '../../../modules/submission/submi /** * A function which returns a validator to check if single answer has a non-empty response */ -export const notEmptySingleAnswerResponse: ResponseValidator = - (response) => { - if (response.answer.trim().length === 0) - return left( - 'CommonValidator.notEmptySingleAnswerResponse:\tanswer is an empty string', - ) - return right(response) - } +export const notEmptySingleAnswerResponse: ResponseValidator< + ProcessedSingleAnswerResponse +> = (response) => { + if (response.answer.trim().length === 0) + return left( + 'CommonValidator.notEmptySingleAnswerResponse:\tanswer is an empty string', + ) + return right(response) +} /** * A function which returns a signature validator constructor for mobile and email verified field. diff --git a/src/public/modules/core/views/edit-contact-number-modal.view.html b/src/public/modules/core/views/edit-contact-number-modal.view.html index 3219b041e9..af7dd4795d 100644 --- a/src/public/modules/core/views/edit-contact-number-modal.view.html +++ b/src/public/modules/core/views/edit-contact-number-modal.view.html @@ -65,12 +65,7 @@ diff --git a/src/public/modules/forms/admin/views/collaborator.client.modal.html b/src/public/modules/forms/admin/views/collaborator.client.modal.html index 67d79ad002..a95f80fcec 100644 --- a/src/public/modules/forms/admin/views/collaborator.client.modal.html +++ b/src/public/modules/forms/admin/views/collaborator.client.modal.html @@ -231,10 +231,7 @@ {{ ROLES.ADMIN }}
@@ -316,10 +313,7 @@