hof 22.8.4 → 22.9.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +30 -0
- package/config/hof-defaults.js +6 -1
- package/frontend/govuk-template/govuk_template_generated.html +102 -0
- package/frontend/template-partials/views/layout.html +2 -8
- package/frontend/themes/gov-uk/styles/_cookie-banner.scss +0 -3
- package/hof-22.9.0.tgz +0 -0
- package/lib/settings.js +1 -0
- package/package/.eslintignore +1 -0
- package/package/CHANGELOG.md +232 -0
- package/package/LICENSE +21 -0
- package/package/README.md +1887 -0
- package/package/bin/hof-build +10 -0
- package/package/bin/hof-transpiler +12 -0
- package/package/build/helpers/importer.js +29 -0
- package/package/build/helpers/local.js +35 -0
- package/package/build/helpers/resolver/import.js +32 -0
- package/package/build/helpers/resolver/nearest-package-root.js +33 -0
- package/package/build/helpers/resolver/package.js +29 -0
- package/package/build/helpers/resolver.js +16 -0
- package/package/build/index.js +49 -0
- package/package/build/lib/env.js +36 -0
- package/package/build/lib/mkdir.js +9 -0
- package/package/build/lib/run.js +17 -0
- package/package/build/lib/spawn.js +18 -0
- package/package/build/tasks/browserify/compress.js +15 -0
- package/package/build/tasks/browserify/index.js +48 -0
- package/package/build/tasks/build/index.js +6 -0
- package/package/build/tasks/images/index.js +27 -0
- package/package/build/tasks/index.js +8 -0
- package/package/build/tasks/sass/index.js +67 -0
- package/package/build/tasks/translate/index.js +20 -0
- package/package/build/tasks/watch/index.js +161 -0
- package/package/components/address-lookup/default-model.js +76 -0
- package/package/components/address-lookup/defaults.js +25 -0
- package/package/components/address-lookup/index.js +251 -0
- package/package/components/address-lookup/templates/address-lookup.html +14 -0
- package/package/components/address-lookup/templates/address.html +22 -0
- package/package/components/address-lookup/templates/postcode.html +9 -0
- package/package/components/clear-session/Readme.md +46 -0
- package/package/components/clear-session/index.js +26 -0
- package/package/components/combine-and-loop-fields/Readme.md +42 -0
- package/package/components/combine-and-loop-fields/index.js +156 -0
- package/package/components/date/fields.js +16 -0
- package/package/components/date/index.js +172 -0
- package/package/components/date/templates/date.html +20 -0
- package/package/components/emailer/assets/images/govuk_logotype_email.png +0 -0
- package/package/components/emailer/assets/images/ho_crest_27px.png +0 -0
- package/package/components/emailer/assets/images/spacer.gif +0 -0
- package/package/components/emailer/email-service.js +51 -0
- package/package/components/emailer/emailer.js +53 -0
- package/package/components/emailer/index.js +74 -0
- package/package/components/emailer/transports/debug.js +74 -0
- package/package/components/emailer/transports/index.js +8 -0
- package/package/components/emailer/transports/ses.js +36 -0
- package/package/components/emailer/transports/smtp.js +26 -0
- package/package/components/emailer/transports/stub.js +5 -0
- package/package/components/emailer/views/layout.html +63 -0
- package/package/components/homeoffice-countries/index.js +22 -0
- package/package/components/index.js +13 -0
- package/package/components/notify/index.js +62 -0
- package/package/components/notify/notify.js +51 -0
- package/package/components/session-timeout-warning/index.js +67 -0
- package/package/components/summary/index.js +237 -0
- package/package/config/builder-defaults.js +45 -0
- package/package/config/component-defaults.js +13 -0
- package/package/config/hof-defaults.js +65 -0
- package/package/config/rate-limits.js +20 -0
- package/package/config/sanitisation-rules.js +32 -0
- package/package/controller/base-controller.js +296 -0
- package/package/controller/behaviour-hooks.js +51 -0
- package/package/controller/behaviour-session.js +64 -0
- package/package/controller/controller.js +258 -0
- package/package/controller/deprecate-error.js +10 -0
- package/package/controller/formatting/formatters.js +70 -0
- package/package/controller/formatting/index.js +32 -0
- package/package/controller/index.js +17 -0
- package/package/controller/validation/email.js +30 -0
- package/package/controller/validation/index.js +101 -0
- package/package/controller/validation/validators.js +181 -0
- package/package/controller/validation-error.js +14 -0
- package/package/frontend/govuk-template/build/config.js +24 -0
- package/package/frontend/govuk-template/build/govuk_template.html +102 -0
- package/package/frontend/govuk-template/build/index.js +23 -0
- package/package/frontend/govuk-template/govuk_template_generated.html +102 -0
- package/package/frontend/govuk-template/index.js +29 -0
- package/package/frontend/index.js +9 -0
- package/package/frontend/template-mixins/mixins/helpers.js +103 -0
- package/package/frontend/template-mixins/mixins/index.js +37 -0
- package/package/frontend/template-mixins/mixins/render.js +12 -0
- package/package/frontend/template-mixins/mixins/template-mixins.js +520 -0
- package/package/frontend/template-mixins/partials/forms/checkbox-group.html +47 -0
- package/package/frontend/template-mixins/partials/forms/checkbox.html +16 -0
- package/package/frontend/template-mixins/partials/forms/input-submit.html +1 -0
- package/package/frontend/template-mixins/partials/forms/input-text-date.html +37 -0
- package/package/frontend/template-mixins/partials/forms/input-text-group.html +45 -0
- package/package/frontend/template-mixins/partials/forms/option-group.html +43 -0
- package/package/frontend/template-mixins/partials/forms/select.html +17 -0
- package/package/frontend/template-mixins/partials/forms/textarea-group.html +37 -0
- package/package/frontend/template-mixins/partials/mixins/panel.html +4 -0
- package/package/frontend/template-partials/index.js +9 -0
- package/package/frontend/template-partials/translations/index.js +26 -0
- package/package/frontend/template-partials/translations/src/cy/base.json +4 -0
- package/package/frontend/template-partials/translations/src/cy/buttons.json +6 -0
- package/package/frontend/template-partials/translations/src/cy/cookies.json +104 -0
- package/package/frontend/template-partials/translations/src/cy/errorlist.json +6 -0
- package/package/frontend/template-partials/translations/src/cy/errors.json +18 -0
- package/package/frontend/template-partials/translations/src/cy/terms.json +28 -0
- package/package/frontend/template-partials/translations/src/en/accessibility.json +43 -0
- package/package/frontend/template-partials/translations/src/en/base.json +5 -0
- package/package/frontend/template-partials/translations/src/en/buttons.json +10 -0
- package/package/frontend/template-partials/translations/src/en/cookies.json +116 -0
- package/package/frontend/template-partials/translations/src/en/errorlist.json +7 -0
- package/package/frontend/template-partials/translations/src/en/errors.json +35 -0
- package/package/frontend/template-partials/translations/src/en/exit.json +5 -0
- package/package/frontend/template-partials/translations/src/en/fields.json +5 -0
- package/package/frontend/template-partials/translations/src/en/journey.json +6 -0
- package/package/frontend/template-partials/translations/src/en/save-and-exit.json +4 -0
- package/package/frontend/template-partials/translations/src/en/terms.json +28 -0
- package/package/frontend/template-partials/views/404.html +9 -0
- package/package/frontend/template-partials/views/accessibility.html +55 -0
- package/package/frontend/template-partials/views/confirm.html +8 -0
- package/package/frontend/template-partials/views/confirmation.html +19 -0
- package/package/frontend/template-partials/views/content/en/what-happens-next.md +0 -0
- package/package/frontend/template-partials/views/cookie-error.html +1 -0
- package/package/frontend/template-partials/views/cookies.html +84 -0
- package/package/frontend/template-partials/views/email/data-row.html +4 -0
- package/package/frontend/template-partials/views/email/formatted.html +12 -0
- package/package/frontend/template-partials/views/email/layout.html +63 -0
- package/package/frontend/template-partials/views/email/raw.html +11 -0
- package/package/frontend/template-partials/views/email/section-row.html +3 -0
- package/package/frontend/template-partials/views/error.html +20 -0
- package/package/frontend/template-partials/views/exit.html +9 -0
- package/package/frontend/template-partials/views/feedback-submitted.html +11 -0
- package/package/frontend/template-partials/views/layout.html +55 -0
- package/package/frontend/template-partials/views/partials/analytics-table.html +25 -0
- package/package/frontend/template-partials/views/partials/back.html +5 -0
- package/package/frontend/template-partials/views/partials/bullet-list.html +7 -0
- package/package/frontend/template-partials/views/partials/confirmation-alert.html +6 -0
- package/package/frontend/template-partials/views/partials/continue.html +5 -0
- package/package/frontend/template-partials/views/partials/cookie-banner.html +29 -0
- package/package/frontend/template-partials/views/partials/cookie-notification.html +4 -0
- package/package/frontend/template-partials/views/partials/cookie-settings-button.html +1 -0
- package/package/frontend/template-partials/views/partials/cookie-settings-radio.html +8 -0
- package/package/frontend/template-partials/views/partials/details-summary.html +8 -0
- package/package/frontend/template-partials/views/partials/external-link.html +1 -0
- package/package/frontend/template-partials/views/partials/form.html +10 -0
- package/package/frontend/template-partials/views/partials/gatag.html +60 -0
- package/package/frontend/template-partials/views/partials/head.html +31 -0
- package/package/frontend/template-partials/views/partials/heading.html +11 -0
- package/package/frontend/template-partials/views/partials/items-table.html +32 -0
- package/package/frontend/template-partials/views/partials/maincontent-left.html +10 -0
- package/package/frontend/template-partials/views/partials/navigation.html +8 -0
- package/package/frontend/template-partials/views/partials/page.html +23 -0
- package/package/frontend/template-partials/views/partials/panel-indent.html +3 -0
- package/package/frontend/template-partials/views/partials/session-cookies-table.html +28 -0
- package/package/frontend/template-partials/views/partials/session-timeout-warning.html +38 -0
- package/package/frontend/template-partials/views/partials/summary-table-row.html +14 -0
- package/package/frontend/template-partials/views/partials/summary-table.html +8 -0
- package/package/frontend/template-partials/views/partials/table.html +18 -0
- package/package/frontend/template-partials/views/partials/validation-list.html +3 -0
- package/package/frontend/template-partials/views/partials/validation-summary.html +25 -0
- package/package/frontend/template-partials/views/partials/warn.html +7 -0
- package/package/frontend/template-partials/views/rate-limit-error.html +10 -0
- package/package/frontend/template-partials/views/save-and-exit.html +17 -0
- package/package/frontend/template-partials/views/service-unavailable.html +13 -0
- package/package/frontend/template-partials/views/session-timeout.html +7 -0
- package/package/frontend/template-partials/views/step.html +14 -0
- package/package/frontend/template-partials/views/terms.html +26 -0
- package/package/frontend/themes/gov-uk/client-js/cookieSettings.js +145 -0
- package/package/frontend/themes/gov-uk/client-js/govuk-cookies.js +121 -0
- package/package/frontend/themes/gov-uk/client-js/index.js +27 -0
- package/package/frontend/themes/gov-uk/client-js/session-timeout-dialog.js +348 -0
- package/package/frontend/themes/gov-uk/client-js/skip-to-main.js +19 -0
- package/package/frontend/themes/gov-uk/index.js +9 -0
- package/package/frontend/themes/gov-uk/styles/_base.scss +17 -0
- package/package/frontend/themes/gov-uk/styles/_check_your_answers.scss +155 -0
- package/package/frontend/themes/gov-uk/styles/_cookie-banner.scss +111 -0
- package/package/frontend/themes/gov-uk/styles/_cookie-settings.scss +33 -0
- package/package/frontend/themes/gov-uk/styles/_govuk_frontend_toolkit.scss +23 -0
- package/package/frontend/themes/gov-uk/styles/_helpers.scss +5 -0
- package/package/frontend/themes/gov-uk/styles/_layout.scss +125 -0
- package/package/frontend/themes/gov-uk/styles/_panel-indent.scss +27 -0
- package/package/frontend/themes/gov-uk/styles/_pdf.scss +42 -0
- package/package/frontend/themes/gov-uk/styles/_session-timeout-dialog.scss +121 -0
- package/package/frontend/themes/gov-uk/styles/_typography.scss +27 -0
- package/package/frontend/themes/gov-uk/styles/_variables.scss +11 -0
- package/package/frontend/themes/gov-uk/styles/govuk.scss +43 -0
- package/package/frontend/themes/gov-uk/styles/mixins.scss +16 -0
- package/package/frontend/themes/gov-uk/styles/modules/_alerts.scss +73 -0
- package/package/frontend/themes/gov-uk/styles/modules/_buttons.scss +5 -0
- package/package/frontend/themes/gov-uk/styles/modules/_character-count.scss +8 -0
- package/package/frontend/themes/gov-uk/styles/modules/_confirm-page.scss +20 -0
- package/package/frontend/themes/gov-uk/styles/modules/_lists.scss +5 -0
- package/package/frontend/themes/gov-uk/styles/modules/_progressive-reveal.scss +17 -0
- package/package/frontend/themes/gov-uk/styles/modules/_validation.scss +51 -0
- package/package/frontend/themes/index.js +5 -0
- package/package/frontend/toolkit/assets/images/passports/new-window-link-blue.png +0 -0
- package/package/frontend/toolkit/assets/images/passports/new-window-link.png +0 -0
- package/package/frontend/toolkit/assets/images/spinner.gif +0 -0
- package/package/frontend/toolkit/assets/javascript/character-count.js +99 -0
- package/package/frontend/toolkit/assets/javascript/form-focus.js +101 -0
- package/package/frontend/toolkit/assets/javascript/helpers.js +177 -0
- package/package/frontend/toolkit/assets/javascript/progressive-reveal.js +72 -0
- package/package/frontend/toolkit/assets/javascript/validation.js +71 -0
- package/package/frontend/toolkit/assets/javascript/vendor/details.polyfill.js +189 -0
- package/package/frontend/toolkit/assets/javascript/vendor/indexof.polyfill.js +39 -0
- package/package/frontend/toolkit/assets/javascript/vendor/safari-cachebuster.js +6 -0
- package/package/frontend/toolkit/assets/stylesheets/_base.scss +17 -0
- package/package/frontend/toolkit/assets/stylesheets/_helpers.scss +5 -0
- package/package/frontend/toolkit/assets/stylesheets/_layout.scss +118 -0
- package/package/frontend/toolkit/assets/stylesheets/_typography.scss +27 -0
- package/package/frontend/toolkit/assets/stylesheets/_variables.scss +11 -0
- package/package/frontend/toolkit/assets/stylesheets/app.scss +30 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_buttons.scss +47 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_details.scss +38 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_elements-typography.scss +175 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_forms.scss +167 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_helpers.scss +39 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_layout.scss +67 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_lists.scss +40 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_panels.scss +29 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_reset.scss +33 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_tables.scss +33 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-block-labels.scss +63 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-date.scss +39 -0
- package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-validation.scss +63 -0
- package/package/frontend/toolkit/assets/stylesheets/mixins.scss +16 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_alerts.scss +73 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_buttons.scss +5 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_confirm-page.scss +20 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_lists.scss +5 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_progressive-reveal.scss +17 -0
- package/package/frontend/toolkit/assets/stylesheets/modules/_validation.scss +51 -0
- package/package/frontend/toolkit/index.js +10 -0
- package/package/index.js +351 -0
- package/package/lib/deindex.js +18 -0
- package/package/lib/encryption.js +23 -0
- package/package/lib/ga-tag.js +89 -0
- package/package/lib/health.js +26 -0
- package/package/lib/helpers.js +66 -0
- package/package/lib/logger.js +65 -0
- package/package/lib/markdown.js +46 -0
- package/package/lib/router.js +111 -0
- package/package/lib/serve-static.js +12 -0
- package/package/lib/sessions.js +82 -0
- package/package/lib/settings.js +74 -0
- package/package/lib/which.js +28 -0
- package/package/middleware/cookies.js +43 -0
- package/package/middleware/deep-translate.js +32 -0
- package/package/middleware/errors.js +119 -0
- package/package/middleware/index.js +10 -0
- package/package/middleware/not-found.js +38 -0
- package/package/middleware/rate-limiter.js +98 -0
- package/package/middleware/service-unavailable.js +64 -0
- package/package/model/apis/axios-settings.js +21 -0
- package/package/model/apis/html-to-pdf-converter.js +35 -0
- package/package/model/apis/index.js +5 -0
- package/package/model/index.js +348 -0
- package/package/package.json +147 -0
- package/package/sandbox/README.md +66 -0
- package/package/sandbox/apps/sandbox/behaviours/clear-session.js +8 -0
- package/package/sandbox/apps/sandbox/behaviours/country-select.js +10 -0
- package/package/sandbox/apps/sandbox/behaviours/international-number.js +22 -0
- package/package/sandbox/apps/sandbox/fields.js +128 -0
- package/package/sandbox/apps/sandbox/index.js +99 -0
- package/package/sandbox/apps/sandbox/lib/staticAppealStages.js +189 -0
- package/package/sandbox/apps/sandbox/sections/summary-data-sections.js +43 -0
- package/package/sandbox/apps/sandbox/translations/src/en/errors.json +5 -0
- package/package/sandbox/apps/sandbox/translations/src/en/exit.json +4 -0
- package/package/sandbox/apps/sandbox/translations/src/en/fields.json +101 -0
- package/package/sandbox/apps/sandbox/translations/src/en/journey.json +7 -0
- package/package/sandbox/apps/sandbox/translations/src/en/pages.json +72 -0
- package/package/sandbox/apps/sandbox/translations/src/en/validation.json +54 -0
- package/package/sandbox/apps/sandbox/views/form-guidance-link.html +8 -0
- package/package/sandbox/apps/sandbox/views/save-and-exit.html +19 -0
- package/package/sandbox/assets/images/icons/icon-caret-left.png +0 -0
- package/package/sandbox/assets/images/icons/icon-complete.png +0 -0
- package/package/sandbox/assets/images/icons/icon-cross-remove-sign.png +0 -0
- package/package/sandbox/assets/js/index.js +70 -0
- package/package/sandbox/assets/scss/app.scss +27 -0
- package/package/sandbox/codecept.conf.js +15 -0
- package/package/sandbox/config.js +17 -0
- package/package/sandbox/package.json +26 -0
- package/package/sandbox/server.js +23 -0
- package/package/sandbox/yarn.lock +262 -0
- package/package/transpiler/index.js +2 -0
- package/package/transpiler/lib/aggregate.js +32 -0
- package/package/transpiler/lib/build.js +15 -0
- package/package/transpiler/lib/compile.js +12 -0
- package/package/transpiler/lib/expand-dirs.js +14 -0
- package/package/transpiler/lib/write-files.js +24 -0
- package/package/utilities/autofill/index.js +189 -0
- package/package/utilities/autofill/inputs.js +60 -0
- package/package/utilities/countries.js +12 -0
- package/package/utilities/helpers/index.js +189 -0
- package/package/utilities/index.js +9 -0
- package/package/utilities/reqres/index.js +18 -0
- package/package/utilities/test-data/data/domain.json +7 -0
- package/package/utilities/test-data/data/firstname.json +16 -0
- package/package/utilities/test-data/data/lastname.json +10 -0
- package/package/utilities/test-data/data/postcode.json +12 -0
- package/package/utilities/test-data/data/streetname.json +8 -0
- package/package/utilities/test-data/data/streetsuffix.json +7 -0
- package/package/utilities/test-data/data/town.json +9 -0
- package/package/utilities/test-data/index.js +67 -0
- package/package/wizard/behaviours/complete.js +20 -0
- package/package/wizard/behaviours/index.js +5 -0
- package/package/wizard/index.js +124 -0
- package/package/wizard/middleware/back-links.js +68 -0
- package/package/wizard/middleware/check-complete.js +13 -0
- package/package/wizard/middleware/check-progress.js +139 -0
- package/package/wizard/middleware/check-session.js +17 -0
- package/package/wizard/middleware/csrf.js +47 -0
- package/package/wizard/middleware/session-model.js +11 -0
- package/package/wizard/middleware/session.js +9 -0
- package/package/wizard/model.js +29 -0
- package/package/wizard/util/constants.js +5 -0
- package/package/wizard/util/helpers.js +19 -0
- package/package.json +5 -6
- package/.editorconfig +0 -10
- package/.github/workflows/automate-publish.yml +0 -38
- package/.github/workflows/automate-tag.yml +0 -78
- package/.istanbul.yml +0 -20
- package/codeReviewChecklist.md +0 -22
- package/pull_request_template.md +0 -16
@@ -0,0 +1,156 @@
|
|
1
|
+
|
2
|
+
const _ = require('lodash');
|
3
|
+
const uuid = require('uuid').v1;
|
4
|
+
const path = require('path');
|
5
|
+
const express = require('express');
|
6
|
+
|
7
|
+
module.exports = config => {
|
8
|
+
const { returnTo, groupName, fieldsToGroup, combineValuesToSingleField, removePrefix, groupOptional } = config;
|
9
|
+
|
10
|
+
if (removePrefix && typeof removePrefix !== 'string') {
|
11
|
+
throw new Error('removePrefix is a string and is optional for loops');
|
12
|
+
}
|
13
|
+
|
14
|
+
if (combineValuesToSingleField && typeof combineValuesToSingleField !== 'string') {
|
15
|
+
throw new Error('combineValuesToSingleField is a string and is optional for loops');
|
16
|
+
}
|
17
|
+
|
18
|
+
if (!returnTo || typeof returnTo !== 'string') {
|
19
|
+
throw new Error('returnTo is a string and is required for loops');
|
20
|
+
}
|
21
|
+
|
22
|
+
if (!groupName || typeof groupName !== 'string') {
|
23
|
+
throw new Error('groupName is a string and is required for loops');
|
24
|
+
}
|
25
|
+
|
26
|
+
if (!fieldsToGroup ||
|
27
|
+
!fieldsToGroup.length ||
|
28
|
+
!Array.isArray(fieldsToGroup) ||
|
29
|
+
_.some(fieldsToGroup, field => typeof field !== 'string')) {
|
30
|
+
throw new Error('fieldsToGroup is an array of strings and is required for loops');
|
31
|
+
}
|
32
|
+
|
33
|
+
return superclass => class extends superclass {
|
34
|
+
get(req, res, next) {
|
35
|
+
if (req.query.delete) {
|
36
|
+
const router = express.Router({ mergeParams: true });
|
37
|
+
router.use([
|
38
|
+
// eslint-disable-next-line no-underscore-dangle
|
39
|
+
this._configure.bind(this),
|
40
|
+
this.removeItem.bind(this),
|
41
|
+
this.reload.bind(this)
|
42
|
+
]);
|
43
|
+
return router.handle(req, res, next);
|
44
|
+
}
|
45
|
+
return super.get(req, res, next);
|
46
|
+
}
|
47
|
+
|
48
|
+
getLoopFields(req) {
|
49
|
+
let loopedFields = _.pick(req.sessionModel.toJSON(), fieldsToGroup);
|
50
|
+
|
51
|
+
if (removePrefix) {
|
52
|
+
loopedFields = _.mapKeys(loopedFields, (value, key) => key.replace(removePrefix, ''));
|
53
|
+
}
|
54
|
+
return loopedFields;
|
55
|
+
}
|
56
|
+
|
57
|
+
removeItem(req, res, next) {
|
58
|
+
const id = req.query.delete;
|
59
|
+
const items = req.sessionModel.get(groupName).filter(item => item.id !== id);
|
60
|
+
req.sessionModel.set(groupName, items);
|
61
|
+
next();
|
62
|
+
}
|
63
|
+
|
64
|
+
// eslint-disable-next-line no-unused-vars
|
65
|
+
reload(req, res, next) {
|
66
|
+
const items = req.sessionModel.get(groupName);
|
67
|
+
if (!items.length) {
|
68
|
+
req.sessionModel.set(`${groupName}-saved`, false);
|
69
|
+
fieldsToGroup.forEach(field => {
|
70
|
+
req.sessionModel.unset(field);
|
71
|
+
});
|
72
|
+
}
|
73
|
+
|
74
|
+
const target = (items.length || groupOptional) ? req.form.options.route : returnTo;
|
75
|
+
const action = req.params.action || '';
|
76
|
+
res.redirect(path.join(req.baseUrl, target, action));
|
77
|
+
}
|
78
|
+
|
79
|
+
configure(req, res, next) {
|
80
|
+
const field = `${groupName}-add-another`;
|
81
|
+
// add yes/no field
|
82
|
+
req.form.options.fields[field] = Object.assign({
|
83
|
+
mixin: 'radio-group',
|
84
|
+
validate: ['required'],
|
85
|
+
options: [
|
86
|
+
'yes', 'no'
|
87
|
+
],
|
88
|
+
legend: {
|
89
|
+
className: 'visuallyhidden'
|
90
|
+
}
|
91
|
+
}, req.form.options.fieldSettings);
|
92
|
+
|
93
|
+
// add conditonal fork
|
94
|
+
req.form.options.forks = req.form.options.forks || [];
|
95
|
+
req.form.options.forks.push({
|
96
|
+
target: returnTo,
|
97
|
+
continueOnEdit: true,
|
98
|
+
condition: {
|
99
|
+
field: field,
|
100
|
+
value: 'yes'
|
101
|
+
}
|
102
|
+
});
|
103
|
+
next();
|
104
|
+
}
|
105
|
+
|
106
|
+
getValues(req, res, next) {
|
107
|
+
const fieldsGroup = req.sessionModel.get(groupName) || [];
|
108
|
+
const added = req.sessionModel.get(`${groupName}-saved`);
|
109
|
+
return super.getValues(req, res, (err, values) => {
|
110
|
+
if (err) {
|
111
|
+
return next(err);
|
112
|
+
}
|
113
|
+
if (!added) {
|
114
|
+
const fields = this.getLoopFields(req);
|
115
|
+
if (!_.isEmpty(fields)) {
|
116
|
+
const newField = Object.assign({id: uuid()}, fields);
|
117
|
+
|
118
|
+
if (combineValuesToSingleField) {
|
119
|
+
const combinedValues = _.filter(fieldsToGroup.map(field => req.sessionModel.get(field))).join(', ');
|
120
|
+
newField[combineValuesToSingleField] = combinedValues;
|
121
|
+
}
|
122
|
+
|
123
|
+
fieldsGroup.push(newField);
|
124
|
+
values[groupName] = fieldsGroup;
|
125
|
+
fieldsToGroup.forEach(field => req.sessionModel.unset(field));
|
126
|
+
|
127
|
+
req.sessionModel.set(groupName, fieldsGroup);
|
128
|
+
req.sessionModel.set(`${groupName}-saved`, true);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
return next(null, values);
|
132
|
+
});
|
133
|
+
}
|
134
|
+
|
135
|
+
locals(req, res) {
|
136
|
+
const items = req.form.values[groupName] || [];
|
137
|
+
return Object.assign({}, super.locals(req, res), {
|
138
|
+
items,
|
139
|
+
hasItems: items.length > 0,
|
140
|
+
field: groupName
|
141
|
+
});
|
142
|
+
}
|
143
|
+
|
144
|
+
saveValues(req, res, next) {
|
145
|
+
// remove "yes" value from session so it is no pre-populated next time around
|
146
|
+
super.saveValues(req, res, err => {
|
147
|
+
const field = `${groupName}-add-another`;
|
148
|
+
if (req.form.values[field] === 'yes') {
|
149
|
+
req.sessionModel.unset(field);
|
150
|
+
req.sessionModel.set(`${groupName}-saved`, false);
|
151
|
+
}
|
152
|
+
next(err);
|
153
|
+
});
|
154
|
+
}
|
155
|
+
};
|
156
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
module.exports = key => ({
|
4
|
+
[`${key}-day`]: {
|
5
|
+
label: 'Day',
|
6
|
+
autocomplete: 'bday-day'
|
7
|
+
},
|
8
|
+
[`${key}-month`]: {
|
9
|
+
label: 'Month',
|
10
|
+
autocomplete: 'bday-month'
|
11
|
+
},
|
12
|
+
[`${key}-year`]: {
|
13
|
+
label: 'Year',
|
14
|
+
autocomplete: 'bday-year'
|
15
|
+
}
|
16
|
+
});
|
@@ -0,0 +1,172 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _ = require('lodash');
|
4
|
+
const path = require('path');
|
5
|
+
const getFields = require('./fields');
|
6
|
+
|
7
|
+
const TEMPLATE = path.resolve(__dirname, './templates/date.html');
|
8
|
+
|
9
|
+
// utility function taking the req.body, fields and key,
|
10
|
+
// returns a map of values in the format:
|
11
|
+
// {
|
12
|
+
// day: '01',
|
13
|
+
// month: '01',
|
14
|
+
// year: '2017'
|
15
|
+
// }
|
16
|
+
const getParts = (body, fields, key) =>
|
17
|
+
_.mapKeys(_.pick(body, Object.keys(fields)), (value, fieldKey) =>
|
18
|
+
fieldKey.replace(`${key}-`, '')
|
19
|
+
);
|
20
|
+
|
21
|
+
// accepts a date value in the format YYYY-MM-DD and fields config,
|
22
|
+
// returns a map of key: value pairs for the intermedate fields
|
23
|
+
const getPartsFromDate = (date, fields) =>
|
24
|
+
date.split('-')
|
25
|
+
.slice()
|
26
|
+
.reverse()
|
27
|
+
.reduce((obj, value, index) => Object.assign({}, obj, {
|
28
|
+
[fields[index]]: value
|
29
|
+
}), {});
|
30
|
+
|
31
|
+
// preprend '0' if number is only a single digit
|
32
|
+
const pad = num => num !== '' && num.length < 2 ? `0${num}` : num;
|
33
|
+
|
34
|
+
const conditionalTranslate = (key, translate) => {
|
35
|
+
let result = translate(key);
|
36
|
+
if (result === key) {
|
37
|
+
result = null;
|
38
|
+
}
|
39
|
+
return result;
|
40
|
+
};
|
41
|
+
|
42
|
+
const getLegendClassName = field => field && field.legend && field.legend.className || '';
|
43
|
+
const getIsPageHeading = field => field && field.isPageHeading || '';
|
44
|
+
|
45
|
+
module.exports = (key, opts) => {
|
46
|
+
if (!key) {
|
47
|
+
throw new Error('Key must be passed to date component');
|
48
|
+
}
|
49
|
+
const options = opts || {};
|
50
|
+
const template = options.template ?
|
51
|
+
path.resolve(__dirname, options.template) :
|
52
|
+
TEMPLATE;
|
53
|
+
const fields = getFields(key);
|
54
|
+
|
55
|
+
options.validate = _.uniq(options.validate ? ['date'].concat(options.validate) : ['date']);
|
56
|
+
|
57
|
+
let dayOptional = !!options.dayOptional;
|
58
|
+
const monthOptional = !!options.monthOptional;
|
59
|
+
|
60
|
+
if (monthOptional) {
|
61
|
+
dayOptional = true;
|
62
|
+
}
|
63
|
+
|
64
|
+
// take the 3 date parts, padding or defaulting
|
65
|
+
// to '01' if applic, then create a date value in the
|
66
|
+
// format YYYY-MM-DD. Save to req.body for processing
|
67
|
+
const preProcess = (req, res, next) => {
|
68
|
+
const parts = getParts(req.body, fields, key);
|
69
|
+
if (_.some(parts, part => part !== '')) {
|
70
|
+
if (dayOptional && parts.day === '') {
|
71
|
+
parts.day = '01';
|
72
|
+
} else {
|
73
|
+
parts.day = pad(parts.day);
|
74
|
+
}
|
75
|
+
if (monthOptional && parts.month === '') {
|
76
|
+
parts.month = '01';
|
77
|
+
} else {
|
78
|
+
parts.month = pad(parts.month);
|
79
|
+
}
|
80
|
+
req.body[key] = `${parts.year}-${parts.month}-${parts.day}`;
|
81
|
+
}
|
82
|
+
next();
|
83
|
+
};
|
84
|
+
|
85
|
+
// defaultFormatters on the base controller replace '--' with '-' on the process step.
|
86
|
+
// This ensures having the correct number of hyphens, so values do not jump from year to month.
|
87
|
+
// This should only be done on a partially completed date field otherwise the validation messages break.
|
88
|
+
const postProcess = (req, res, next) => {
|
89
|
+
const value = req.form.values[key];
|
90
|
+
if (value) {
|
91
|
+
req.form.values[key] = req.body[key];
|
92
|
+
}
|
93
|
+
next();
|
94
|
+
};
|
95
|
+
// if date field is included in errorValues, extend
|
96
|
+
// errorValues with the individual components
|
97
|
+
const preGetErrors = (req, res, next) => {
|
98
|
+
const errorValues = req.sessionModel.get('errorValues');
|
99
|
+
if (errorValues && errorValues[key]) {
|
100
|
+
req.sessionModel.set('errorValues',
|
101
|
+
Object.assign({}, errorValues, getPartsFromDate(errorValues[key], Object.keys(fields)))
|
102
|
+
);
|
103
|
+
}
|
104
|
+
next();
|
105
|
+
};
|
106
|
+
|
107
|
+
// if date field has any validation error, also add errors
|
108
|
+
// for the three child components. null type as we don't want to show
|
109
|
+
// duplicate messages
|
110
|
+
const postGetErrors = (req, res, next) => {
|
111
|
+
const errors = req.sessionModel.get('errors');
|
112
|
+
if (errors && errors[key]) {
|
113
|
+
Object.assign(req.form.errors, Object.keys(fields).reduce((obj, field) =>
|
114
|
+
Object.assign({}, obj, { [field]: { type: null } })
|
115
|
+
, {}));
|
116
|
+
}
|
117
|
+
next();
|
118
|
+
};
|
119
|
+
|
120
|
+
// if date value is set, split its parts and assign to req.form.values.
|
121
|
+
// This is extended with errorValues if they are present
|
122
|
+
const postGetValues = (req, res, next) => {
|
123
|
+
const date = req.form.values[key];
|
124
|
+
if (date) {
|
125
|
+
Object.assign(
|
126
|
+
req.form.values,
|
127
|
+
getPartsFromDate(date, Object.keys(fields)),
|
128
|
+
req.sessionModel.get('errorValues') || {}
|
129
|
+
);
|
130
|
+
}
|
131
|
+
next();
|
132
|
+
};
|
133
|
+
|
134
|
+
// render the template to a string, assign the html output
|
135
|
+
// to the date field in res.locals.fields
|
136
|
+
const preRender = (req, res, next) => {
|
137
|
+
Object.assign(req.form.options.fields, _.mapValues(fields, (v, k) => {
|
138
|
+
const rawKey = k.replace(`${key}-`, '');
|
139
|
+
const labelKey = `fields.${key}.parts.${rawKey}`;
|
140
|
+
const label = req.translate(labelKey);
|
141
|
+
return Object.assign({}, v, {
|
142
|
+
label: label === labelKey ? v.label : label
|
143
|
+
});
|
144
|
+
}));
|
145
|
+
const legend = conditionalTranslate(`fields.${key}.legend`, req.translate);
|
146
|
+
const hint = conditionalTranslate(`fields.${key}.hint`, req.translate);
|
147
|
+
const legendClassName = getLegendClassName(options);
|
148
|
+
const isPageHeading = getIsPageHeading(options);
|
149
|
+
const error = req.form.errors && req.form.errors[key];
|
150
|
+
res.render(template, { key, legend, legendClassName, isPageHeading, hint, error }, (err, html) => {
|
151
|
+
if (err) {
|
152
|
+
next(err);
|
153
|
+
} else {
|
154
|
+
const field = res.locals.fields.find(f => f.key === key);
|
155
|
+
Object.assign(field, { html });
|
156
|
+
next();
|
157
|
+
}
|
158
|
+
});
|
159
|
+
};
|
160
|
+
|
161
|
+
// return config extended with hooks
|
162
|
+
return Object.assign({}, options, {
|
163
|
+
hooks: {
|
164
|
+
'pre-process': preProcess,
|
165
|
+
'post-process': postProcess,
|
166
|
+
'pre-getErrors': preGetErrors,
|
167
|
+
'post-getErrors': postGetErrors,
|
168
|
+
'post-getValues': postGetValues,
|
169
|
+
'pre-render': preRender
|
170
|
+
}
|
171
|
+
});
|
172
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<div class="govuk-form-group {{#error}}govuk-form-group--error{{/error}}">
|
2
|
+
<fieldset id="{{key}}-group" class="govuk-fieldset{{#className}} {{className}}{{/className}}" role="group">
|
3
|
+
<legend class="govuk-fieldset__legend {{#isPageHeading}}govuk-fieldset__legend--l{{/isPageHeading}}{{#legendClassName}} {{legendClassName}}{{/legendClassName}}">
|
4
|
+
{{#isPageHeading}}<h1 class="govuk-fieldset__heading">{{/isPageHeading}}
|
5
|
+
{{legend}}
|
6
|
+
{{#isPageHeading}}</h1>{{/isPageHeading}}
|
7
|
+
</legend>
|
8
|
+
{{#hint}}
|
9
|
+
<span id="{{key}}-hint" class="govuk-hint">{{{hint}}}</span>
|
10
|
+
{{/hint}}
|
11
|
+
{{#error}}
|
12
|
+
<p id="{{key}}-error" class="govuk-error-message">
|
13
|
+
<span class="govuk-visually-hidden">Error:</span> {{error.message}}
|
14
|
+
</p>
|
15
|
+
{{/error}}
|
16
|
+
<div id="{{key}}" class="govuk-date-input">
|
17
|
+
{{#input-date}}{{key}}{{/input-date}}
|
18
|
+
</div>
|
19
|
+
</fieldset>
|
20
|
+
</div>
|
Binary file
|
Binary file
|
@@ -0,0 +1,51 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const fs = require('fs');
|
4
|
+
const path = require('path');
|
5
|
+
const Hogan = require('hogan.js');
|
6
|
+
const debug = require('debug')('hof:emailer');
|
7
|
+
|
8
|
+
const Emailer = require('./emailer');
|
9
|
+
|
10
|
+
module.exports = class EmailService {
|
11
|
+
constructor(opts) {
|
12
|
+
const options = opts || {};
|
13
|
+
this.layout = options.layout === undefined ? path.resolve(__dirname, './views/layout.html') : options.layout;
|
14
|
+
this.emailer = new Emailer(options);
|
15
|
+
}
|
16
|
+
|
17
|
+
send(r, b, s) {
|
18
|
+
let body = b;
|
19
|
+
let subject = s;
|
20
|
+
let recipient = r;
|
21
|
+
|
22
|
+
if (arguments.length === 1 && recipient.recipient) {
|
23
|
+
body = recipient.body;
|
24
|
+
subject = recipient.subject;
|
25
|
+
recipient = recipient.recipient;
|
26
|
+
}
|
27
|
+
return this.render(recipient, body, subject)
|
28
|
+
.then(content => this.emailer.send(recipient, subject, content));
|
29
|
+
}
|
30
|
+
|
31
|
+
render(recipient, body, subject) {
|
32
|
+
if (this.layout) {
|
33
|
+
return this.template()
|
34
|
+
.then(template => template.render({ recipient, body, subject }));
|
35
|
+
}
|
36
|
+
return Promise.resolve(body);
|
37
|
+
}
|
38
|
+
|
39
|
+
template() {
|
40
|
+
debug(`Reading template file: ${this.layout}`);
|
41
|
+
return new Promise((resolve, reject) => {
|
42
|
+
fs.readFile(this.layout, (err, content) => {
|
43
|
+
if (err) {
|
44
|
+
reject(err);
|
45
|
+
} else {
|
46
|
+
resolve(Hogan.compile(content.toString('utf8')));
|
47
|
+
}
|
48
|
+
});
|
49
|
+
});
|
50
|
+
}
|
51
|
+
};
|
@@ -0,0 +1,53 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const path = require('path');
|
4
|
+
const nodemailer = require('nodemailer');
|
5
|
+
const transports = require('./transports');
|
6
|
+
|
7
|
+
const debug = require('debug')('hof:emailer');
|
8
|
+
|
9
|
+
module.exports = class Emailer {
|
10
|
+
constructor(opts) {
|
11
|
+
const options = opts || {};
|
12
|
+
this.options = options;
|
13
|
+
|
14
|
+
options.transport = options.transport || 'smtp';
|
15
|
+
debug(`Using ${options.transport} transport`);
|
16
|
+
|
17
|
+
if (options.transport !== 'stub' && !options.from && !options.replyTo) {
|
18
|
+
throw new Error('At least one of `from` or `replyTo` options must be defined');
|
19
|
+
}
|
20
|
+
|
21
|
+
const transport = transports[options.transport](options.transportOptions || {});
|
22
|
+
|
23
|
+
this.emailer = nodemailer.createTransport(transport);
|
24
|
+
}
|
25
|
+
|
26
|
+
send(to, subject, body) {
|
27
|
+
debug(`Sending email to ${to} with subject ${subject}`);
|
28
|
+
return new Promise((resolve, reject) => {
|
29
|
+
this.emailer.sendMail({
|
30
|
+
to,
|
31
|
+
subject,
|
32
|
+
from: this.options.from || this.options.replyTo,
|
33
|
+
replyTo: this.options.replyTo || this.options.from,
|
34
|
+
html: body,
|
35
|
+
attachments: [{
|
36
|
+
filename: 'govuk_logotype_email.png',
|
37
|
+
path: path.resolve(__dirname, './assets/images/govuk_logotype_email.png'),
|
38
|
+
cid: 'govuk_logotype_email'
|
39
|
+
},
|
40
|
+
{
|
41
|
+
filename: 'ho_crest_27px.png',
|
42
|
+
path: path.resolve(__dirname, './assets/images/ho_crest_27px.png'),
|
43
|
+
cid: 'ho_crest_27px'
|
44
|
+
},
|
45
|
+
{
|
46
|
+
filename: 'spacer.gif',
|
47
|
+
path: path.resolve(__dirname, './assets/images/spacer.gif'),
|
48
|
+
cid: 'spacer_image'
|
49
|
+
}]
|
50
|
+
}, (err, result) => err ? reject(err) : resolve(result));
|
51
|
+
});
|
52
|
+
}
|
53
|
+
};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const EmailService = require('./email-service');
|
4
|
+
const Hogan = require('hogan.js');
|
5
|
+
const fs = require('fs');
|
6
|
+
const debug = require('debug')('hof:behaviour:emailer');
|
7
|
+
|
8
|
+
module.exports = config => {
|
9
|
+
const emailer = new EmailService(config);
|
10
|
+
config.parse = config.parse || (data => data);
|
11
|
+
|
12
|
+
if (!config.recipient) {
|
13
|
+
throw new Error('hof-behaviour-emailer: email recipient must be defined');
|
14
|
+
}
|
15
|
+
if (typeof config.template !== 'string') {
|
16
|
+
throw new Error('hof-behaviour-emailer: email template must be defined');
|
17
|
+
}
|
18
|
+
|
19
|
+
return superclass => class EmailBehaviour extends superclass {
|
20
|
+
async successHandler(req, res, next) {
|
21
|
+
req.sessionModel.unset('nodemailer-error');
|
22
|
+
|
23
|
+
try {
|
24
|
+
debug(`Loading email template from ${config.template}`);
|
25
|
+
|
26
|
+
const template = await new Promise((resolve, reject) => {
|
27
|
+
return fs.readFile(config.template, (err, resolvedTemplate) => {
|
28
|
+
return err ? reject(err) : resolve(resolvedTemplate.toString('utf8'));
|
29
|
+
});
|
30
|
+
});
|
31
|
+
|
32
|
+
debug('Rendering email content');
|
33
|
+
|
34
|
+
const data = config.parse(req.sessionModel.toJSON(), req.translate);
|
35
|
+
|
36
|
+
debug('Building email settings');
|
37
|
+
|
38
|
+
const settings = { body: Hogan.compile(template).render(data) };
|
39
|
+
|
40
|
+
if (typeof config.recipient === 'function') {
|
41
|
+
settings.recipient = config.recipient(req.sessionModel.toJSON());
|
42
|
+
} else {
|
43
|
+
settings.recipient = req.sessionModel.get(config.recipient) || config.recipient;
|
44
|
+
}
|
45
|
+
if (typeof settings.recipient !== 'string' || !settings.recipient.includes('@')) {
|
46
|
+
return next(new Error('hof-behaviour-emailer: invalid recipient'));
|
47
|
+
}
|
48
|
+
|
49
|
+
if (typeof config.subject === 'function') {
|
50
|
+
settings.subject = config.subject(req.sessionModel.toJSON(), req.translate);
|
51
|
+
} else {
|
52
|
+
settings.subject = config.subject;
|
53
|
+
}
|
54
|
+
|
55
|
+
debug('Sending email', settings);
|
56
|
+
|
57
|
+
await emailer.send(settings);
|
58
|
+
|
59
|
+
debug('Email sent successfully');
|
60
|
+
|
61
|
+
return super.successHandler(req, res, next);
|
62
|
+
} catch (e) {
|
63
|
+
if (config.emailerFallback) {
|
64
|
+
req.log('error', e.message || e);
|
65
|
+
req.sessionModel.set('nodemailer-error', true);
|
66
|
+
return super.successHandler(req, res, next);
|
67
|
+
}
|
68
|
+
return next(e);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
};
|
72
|
+
};
|
73
|
+
|
74
|
+
module.exports.EmailService = EmailService;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
/* eslint-disable max-len, no-console */
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
const fs = require('fs');
|
5
|
+
const path = require('path');
|
6
|
+
const cp = require('child_process');
|
7
|
+
|
8
|
+
const mimes = {
|
9
|
+
'.gif': 'image/gif',
|
10
|
+
'.png': 'image/png'
|
11
|
+
};
|
12
|
+
|
13
|
+
const mkdir = dir => new Promise((resolve, reject) => {
|
14
|
+
fs.mkdir(dir, {recursive: true}, err => err ? reject(err) : resolve());
|
15
|
+
});
|
16
|
+
|
17
|
+
const cidToBase64 = (h, attachments) => {
|
18
|
+
let html = h;
|
19
|
+
const list = attachments.reduce((p, attachment) => {
|
20
|
+
const mimeType = mimes[path.extname(attachment.path)];
|
21
|
+
return p
|
22
|
+
.then(map => new Promise((resolve, reject) => fs.readFile(attachment.path, (err, buffer) => err ? reject(err) : resolve(buffer.toString('base64'))))
|
23
|
+
.then(data => {
|
24
|
+
map[attachment.cid] = `"data:${mimeType};base64,${data}"`;
|
25
|
+
return map;
|
26
|
+
}));
|
27
|
+
}, Promise.resolve({}));
|
28
|
+
|
29
|
+
return list.then(files => {
|
30
|
+
Object.keys(files).forEach(cid => {
|
31
|
+
html = html.replace(`"cid:${cid}"`, files[cid]);
|
32
|
+
});
|
33
|
+
return html;
|
34
|
+
});
|
35
|
+
};
|
36
|
+
|
37
|
+
module.exports = options => {
|
38
|
+
options.log = options.log !== false;
|
39
|
+
return {
|
40
|
+
name: 'debug',
|
41
|
+
version: '1.0.0',
|
42
|
+
send: (mail, callback) => {
|
43
|
+
mail.resolveContent(mail.data, 'html', (err, html) => {
|
44
|
+
if (err) {
|
45
|
+
return callback(err);
|
46
|
+
}
|
47
|
+
const dir = options.dir || path.join(process.cwd(), '.emails');
|
48
|
+
const messageId = options.filename || mail.message.messageId().split('@')[0].slice(1);
|
49
|
+
const outfile = path.resolve(dir, `${messageId}.html`);
|
50
|
+
|
51
|
+
return mkdir(dir)
|
52
|
+
.then(() => cidToBase64(html, mail.data.attachments))
|
53
|
+
.then(inlined => new Promise((resolve, reject) => {
|
54
|
+
fs.writeFile(outfile, inlined, e => e ? reject(e) : resolve(inlined));
|
55
|
+
}))
|
56
|
+
.then(() => {
|
57
|
+
if (options.log) {
|
58
|
+
console.log('Email sent:');
|
59
|
+
console.log(` to: ${mail.data.to}`);
|
60
|
+
console.log(` subject: ${mail.data.subject}`);
|
61
|
+
console.log(` html: ${outfile}`);
|
62
|
+
}
|
63
|
+
})
|
64
|
+
.then(() => {
|
65
|
+
if (options.open) {
|
66
|
+
cp.execSync(`open ${outfile}`);
|
67
|
+
}
|
68
|
+
callback();
|
69
|
+
})
|
70
|
+
.catch(callback);
|
71
|
+
});
|
72
|
+
}
|
73
|
+
};
|
74
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const ses = require('nodemailer-ses-transport');
|
4
|
+
|
5
|
+
module.exports = options => {
|
6
|
+
if (!options.accessKeyId) {
|
7
|
+
throw new Error('Required option `accessKeyId` not found.');
|
8
|
+
}
|
9
|
+
if (!options.secretAccessKey) {
|
10
|
+
throw new Error('Required option `secretAccessKey` not found.');
|
11
|
+
}
|
12
|
+
|
13
|
+
const opts = {
|
14
|
+
accessKeyId: options.accessKeyId,
|
15
|
+
secretAccessKey: options.secretAccessKey
|
16
|
+
};
|
17
|
+
|
18
|
+
opts.region = options.region || 'eu-west-1';
|
19
|
+
|
20
|
+
if (options.sessionToken) {
|
21
|
+
opts.sessionToken = options.sessionToken;
|
22
|
+
}
|
23
|
+
|
24
|
+
if (options.httpOptions) {
|
25
|
+
opts.httpOptions = options.httpOptions;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (options.rateLimit !== undefined) {
|
29
|
+
opts.rateLimit = options.rateLimit;
|
30
|
+
}
|
31
|
+
|
32
|
+
if (options.maxConnections !== undefined) {
|
33
|
+
opts.maxConnections = options.maxConnections;
|
34
|
+
}
|
35
|
+
return ses(opts);
|
36
|
+
};
|