hof 22.8.4 → 22.9.0-beta.v1
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/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,20 @@
|
|
1
|
+
|
2
|
+
module.exports = {
|
3
|
+
rateLimits: {
|
4
|
+
env: process.env.NODE_ENV,
|
5
|
+
requests: {
|
6
|
+
active: false,
|
7
|
+
windowSizeInMinutes: 5,
|
8
|
+
maxWindowRequestCount: 100,
|
9
|
+
windowLogIntervalInMinutes: 1,
|
10
|
+
errCode: 'DDOS_RATE_LIMIT'
|
11
|
+
},
|
12
|
+
submissions: {
|
13
|
+
active: false,
|
14
|
+
windowSizeInMinutes: 10,
|
15
|
+
maxWindowRequestCount: 1,
|
16
|
+
windowLogIntervalInMinutes: 1,
|
17
|
+
errCode: 'SUBMISSION_RATE_LIMIT'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
'use strict';
|
2
|
+
/* eslint no-process-env: "off" */
|
3
|
+
|
4
|
+
const sanitisationBlacklistArray = {
|
5
|
+
// Input will be sanitised using the below rules
|
6
|
+
// Each one is an array which will run sequentially
|
7
|
+
// Some have multiple steps which allow us to remove dups then append the suffix
|
8
|
+
// Useful for ensuring we're not re-sanitising the same input multiple times (and appending extra hypens each time)
|
9
|
+
// The key is what we're sanitising out
|
10
|
+
// The regex is the rule we used to find them (note some dictate repeating characters)
|
11
|
+
// And the replace is what we're replacing that pattern with. Usually nothing sometimes a
|
12
|
+
// single character or sometimes a single character followed by a "-"
|
13
|
+
'/*': [{ regex: '\/\\*', replace: '-' }],
|
14
|
+
'*/': [{ regex: '\\*\\/', replace: '-' }],
|
15
|
+
'|': [{ regex: '\\|', replace: '-' }],
|
16
|
+
'&&': [{ regex: '&&+', replace: '&' }],
|
17
|
+
'@@': [{ regex: '@@+', replace: '@' }],
|
18
|
+
'/..;/': [{ regex: '/\\.\\.;/', replace: '-' }], // Purposely input before ".." as they conflict
|
19
|
+
// '..': [{ regex: '\\.\\.+', replace: '.' }], // Agreed to disable this rule for now unless its specifically required
|
20
|
+
'/etc/passwd': [{ regex: '\/etc\/passwd', replace: '-' }],
|
21
|
+
'c:\\': [{ regex: 'c:\\\\', replace: '-' }],
|
22
|
+
'cmd.exe': [{ regex: 'cmd\\.exe', replace: '-' }],
|
23
|
+
'<': [{ regex: '<+', replace: '<' }, { regex: '<(?!-)', replace: '<-' }],
|
24
|
+
'>': [{ regex: '>+', replace: '>' }, { regex: '>(?!-)', replace: '>-' }],
|
25
|
+
'[': [{ regex: '\\[+', replace: '[' }, { regex: '\\[(?!-)', replace: '[-' }],
|
26
|
+
']': [{ regex: '\\]+', replace: ']-' }, { regex: '\\](?!-)', replace: ']-' }],
|
27
|
+
'~': [{ regex: '~+', replace: '~' }, { regex: '~(?!-)', replace: '~-' }],
|
28
|
+
'&#': [{ regex: '&#', replace: '-' }],
|
29
|
+
'%U': [{ regex: '%U', replace: '-' }]
|
30
|
+
};
|
31
|
+
|
32
|
+
module.exports = sanitisationBlacklistArray;
|
@@ -0,0 +1,296 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/* eslint no-unused-vars: [2, {"vars": "all", "args": "none"}] */
|
4
|
+
const _ = require('lodash');
|
5
|
+
const express = require('express');
|
6
|
+
const EventEmitter = require('events').EventEmitter;
|
7
|
+
const debug = require('debug')('hmpo:form');
|
8
|
+
const dataFormatter = require('./formatting');
|
9
|
+
const dataValidator = require('./validation');
|
10
|
+
const ErrorClass = require('./validation-error');
|
11
|
+
const Helpers = require('../utilities').helpers;
|
12
|
+
const sanitisationBlacklistArray = require('../config/sanitisation-rules');
|
13
|
+
|
14
|
+
module.exports = class BaseController extends EventEmitter {
|
15
|
+
constructor(options) {
|
16
|
+
if (!options) {
|
17
|
+
throw new Error('Options must be provided');
|
18
|
+
}
|
19
|
+
if (!options.template) {
|
20
|
+
debug('No template provided');
|
21
|
+
}
|
22
|
+
super(options);
|
23
|
+
options.defaultFormatters = options.defaultFormatters || ['trim', 'singlespaces', 'hyphens'];
|
24
|
+
options.fields = options.fields || {};
|
25
|
+
this.options = options;
|
26
|
+
this.ValidationError = ErrorClass;
|
27
|
+
|
28
|
+
this.router = express.Router({ mergeParams: true });
|
29
|
+
}
|
30
|
+
|
31
|
+
requestHandler() {
|
32
|
+
['get', 'post', 'put', 'delete'].forEach(method => {
|
33
|
+
if (typeof this[method] === 'function') {
|
34
|
+
this.router[method]('*', this[method].bind(this));
|
35
|
+
} else {
|
36
|
+
this.router[method]('*', (req, res, next) => {
|
37
|
+
const err = new Error('Method not supported');
|
38
|
+
err.statusCode = 405;
|
39
|
+
next(err);
|
40
|
+
});
|
41
|
+
}
|
42
|
+
});
|
43
|
+
this.router.use(this.errorHandler.bind(this));
|
44
|
+
return this.router;
|
45
|
+
}
|
46
|
+
|
47
|
+
use() {
|
48
|
+
this.router.use.apply(this.router, arguments);
|
49
|
+
}
|
50
|
+
|
51
|
+
get(req, res, callback) {
|
52
|
+
express.Router({ mergeParams: true })
|
53
|
+
.use([
|
54
|
+
this._configure.bind(this),
|
55
|
+
this._getErrors.bind(this),
|
56
|
+
this._getValues.bind(this),
|
57
|
+
this._locals.bind(this),
|
58
|
+
this.render.bind(this),
|
59
|
+
// eslint-disable-next-line no-shadow
|
60
|
+
(err, req, res, next) => {
|
61
|
+
callback(err);
|
62
|
+
}
|
63
|
+
])
|
64
|
+
.handle(req, res, callback);
|
65
|
+
}
|
66
|
+
|
67
|
+
post(req, res, callback) {
|
68
|
+
this.setErrors(null, req, res);
|
69
|
+
express.Router({ mergeParams: true })
|
70
|
+
.use([
|
71
|
+
this._configure.bind(this),
|
72
|
+
this._process.bind(this),
|
73
|
+
this._validate.bind(this),
|
74
|
+
this._sanitize.bind(this),
|
75
|
+
this._getHistoricalValues.bind(this),
|
76
|
+
this.saveValues.bind(this),
|
77
|
+
this.successHandler.bind(this),
|
78
|
+
// eslint-disable-next-line no-shadow
|
79
|
+
(err, req, res, next) => {
|
80
|
+
callback(err);
|
81
|
+
}
|
82
|
+
])
|
83
|
+
.handle(req, res, callback);
|
84
|
+
}
|
85
|
+
|
86
|
+
_locals(req, res, callback) {
|
87
|
+
Object.assign(res.locals, {
|
88
|
+
errors: req.form.errors,
|
89
|
+
errorlist: _.map(req.form.errors, _.identity),
|
90
|
+
values: req.form.values,
|
91
|
+
options: req.form.options,
|
92
|
+
action: req.baseUrl !== '/' ? req.baseUrl + req.path : req.path
|
93
|
+
});
|
94
|
+
Object.assign(res.locals, this.locals(req, res));
|
95
|
+
callback();
|
96
|
+
}
|
97
|
+
|
98
|
+
// eslint-disable-next-line no-inline-comments, spaced-comment
|
99
|
+
locals(/*req, res*/) {
|
100
|
+
return {};
|
101
|
+
}
|
102
|
+
|
103
|
+
render(req, res, callback) {
|
104
|
+
if (!req.form.options.template) {
|
105
|
+
callback(new Error('A template must be provided'));
|
106
|
+
} else {
|
107
|
+
res.render(req.form.options.template);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
_getErrors(req, res, callback) {
|
112
|
+
req.form.errors = this.getErrors(req, res);
|
113
|
+
callback();
|
114
|
+
}
|
115
|
+
|
116
|
+
// placeholder methods for persisting error messages between POST and GET
|
117
|
+
// eslint-disable-next-line no-inline-comments, spaced-comment
|
118
|
+
getErrors(/*req, res*/) {
|
119
|
+
return {};
|
120
|
+
}
|
121
|
+
|
122
|
+
// eslint-disable-next-line no-inline-comments, spaced-comment
|
123
|
+
setErrors(/*err, req, res*/) {}
|
124
|
+
|
125
|
+
_validate(req, res, callback) {
|
126
|
+
debug('Validating...');
|
127
|
+
|
128
|
+
const formatter = dataFormatter(
|
129
|
+
req.form.options.fields,
|
130
|
+
req.form.options.defaultFormatters,
|
131
|
+
req.form.options.formatters
|
132
|
+
);
|
133
|
+
const validator = dataValidator(req.form.options.fields);
|
134
|
+
|
135
|
+
const errors = _.reduce(req.form.values, (errs, value, key) => {
|
136
|
+
const error = this.validateField(key, req, validator, formatter);
|
137
|
+
if (error) {
|
138
|
+
const errorKey = error.group || error.key;
|
139
|
+
return Object.assign({}, errs, {
|
140
|
+
[errorKey]: new this.ValidationError(errorKey, error)
|
141
|
+
});
|
142
|
+
}
|
143
|
+
return errs;
|
144
|
+
}, {});
|
145
|
+
|
146
|
+
if (!_.isEmpty(errors)) {
|
147
|
+
callback(errors);
|
148
|
+
} else {
|
149
|
+
this.validate(req, res, callback);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
validate(req, res, callback) {
|
154
|
+
callback();
|
155
|
+
}
|
156
|
+
|
157
|
+
validateField(key, req, vld, fmtr) {
|
158
|
+
const formatter = fmtr || dataFormatter(
|
159
|
+
req.form.options.fields,
|
160
|
+
req.form.options.defaultFormatters,
|
161
|
+
req.form.options.formatters
|
162
|
+
);
|
163
|
+
const validator = vld || dataValidator(req.form.options.fields);
|
164
|
+
const emptyValue = formatter(key, '');
|
165
|
+
return validator(key, req.form.values[key], req.form.values, emptyValue);
|
166
|
+
}
|
167
|
+
|
168
|
+
_sanitize(req, res, callback) {
|
169
|
+
// Sanitisation could be disabled in the config
|
170
|
+
if(!this.options.sanitiseInputs) return callback();
|
171
|
+
|
172
|
+
// If we don't have any data, no need to progress
|
173
|
+
if(!_.isEmpty(req.form.values)) {
|
174
|
+
Object.keys(req.form.values).forEach(function (property, propertyIndex) {
|
175
|
+
// If it's not a string, don't sanitise it
|
176
|
+
if(_.isString(req.form.values[property])) {
|
177
|
+
// For each property in our form data
|
178
|
+
Object.keys(sanitisationBlacklistArray).forEach(function (blacklisted, blacklistedIndex) {
|
179
|
+
const blacklistedDetail = sanitisationBlacklistArray[blacklisted];
|
180
|
+
blacklistedDetail.forEach(step => {
|
181
|
+
const regexQuery = new RegExp(step.regex, 'gi');
|
182
|
+
// Will perform the required replace based on our passed in regex and the replace string
|
183
|
+
req.form.values[property] = req.form.values[property].replace(regexQuery, step.replace);
|
184
|
+
});
|
185
|
+
});
|
186
|
+
}
|
187
|
+
});
|
188
|
+
}
|
189
|
+
return callback();
|
190
|
+
}
|
191
|
+
|
192
|
+
_process(req, res, callback) {
|
193
|
+
req.form.values = req.form.values || {};
|
194
|
+
const formatter = dataFormatter(
|
195
|
+
req.form.options.fields,
|
196
|
+
req.form.options.defaultFormatters,
|
197
|
+
req.form.options.formatters
|
198
|
+
);
|
199
|
+
Object.assign(req.form.values, _.reduce(req.form.options.fields, (fields, field, key) =>
|
200
|
+
Object.assign({}, fields, { [key]: formatter(key, req.body[key] || '') })
|
201
|
+
, {}));
|
202
|
+
this.process(req, res, callback);
|
203
|
+
}
|
204
|
+
|
205
|
+
process(req, res, callback) {
|
206
|
+
callback();
|
207
|
+
}
|
208
|
+
|
209
|
+
_configure(req, res, callback) {
|
210
|
+
req.form = req.form || {};
|
211
|
+
req.form.options = _.cloneDeep(this.options);
|
212
|
+
this.configure(req, res, callback);
|
213
|
+
}
|
214
|
+
|
215
|
+
configure(req, res, callback) {
|
216
|
+
callback();
|
217
|
+
}
|
218
|
+
|
219
|
+
_getValues(req, res, callback) {
|
220
|
+
this.getValues(req, res, (err, values) => {
|
221
|
+
req.form.values = values || {};
|
222
|
+
callback(err);
|
223
|
+
});
|
224
|
+
}
|
225
|
+
|
226
|
+
// populate the historical values into the request to allow fork evaluation against those.
|
227
|
+
_getHistoricalValues(req, res, callback) {
|
228
|
+
this.getValues(req, res, (err, values) => {
|
229
|
+
req.form.historicalValues = values || {};
|
230
|
+
callback(err);
|
231
|
+
});
|
232
|
+
}
|
233
|
+
|
234
|
+
getValues(req, res, callback) {
|
235
|
+
callback();
|
236
|
+
}
|
237
|
+
|
238
|
+
saveValues(req, res, callback) {
|
239
|
+
callback();
|
240
|
+
}
|
241
|
+
|
242
|
+
_getForkTarget(req, res) {
|
243
|
+
// If a fork condition is met, its target supercedes the next property
|
244
|
+
return req.form.options.forks.reduce((result, value) =>
|
245
|
+
Helpers.isFieldValueInPageOrSessionValid(req, res, value.condition) ?
|
246
|
+
value.target :
|
247
|
+
result
|
248
|
+
, req.form.options.next);
|
249
|
+
}
|
250
|
+
|
251
|
+
getForkTarget(req, res) {
|
252
|
+
return this._getForkTarget(req, res);
|
253
|
+
}
|
254
|
+
|
255
|
+
getNextStep(req, res) {
|
256
|
+
let next = req.form.options.next || req.path;
|
257
|
+
if (req.form.options.forks && Array.isArray(req.form.options.forks)) {
|
258
|
+
next = this._getForkTarget(req, res);
|
259
|
+
}
|
260
|
+
if (req.baseUrl !== '/') {
|
261
|
+
next = req.baseUrl + next;
|
262
|
+
}
|
263
|
+
return next;
|
264
|
+
}
|
265
|
+
|
266
|
+
getErrorStep(err, req) {
|
267
|
+
const redirectError = _.every(err, error => error.redirect);
|
268
|
+
let redirect = req.originalUrl;
|
269
|
+
|
270
|
+
if (redirectError) {
|
271
|
+
redirect = _.find(err, error => error.redirect).redirect;
|
272
|
+
}
|
273
|
+
|
274
|
+
return redirect;
|
275
|
+
}
|
276
|
+
|
277
|
+
isValidationError(err) {
|
278
|
+
return !_.isEmpty(err) && _.every(err, e => e instanceof this.ValidationError);
|
279
|
+
}
|
280
|
+
|
281
|
+
// eslint-disable-next-line consistent-return
|
282
|
+
errorHandler(err, req, res, callback) {
|
283
|
+
if (this.isValidationError(err)) {
|
284
|
+
this.setErrors(err, req, res);
|
285
|
+
res.redirect(this.getErrorStep(err, req));
|
286
|
+
} else {
|
287
|
+
// if the error is not a validation error then throw and let the error handler pick it up
|
288
|
+
return callback(err);
|
289
|
+
}
|
290
|
+
}
|
291
|
+
|
292
|
+
successHandler(req, res) {
|
293
|
+
this.emit('complete', req, res);
|
294
|
+
res.redirect(this.getNextStep(req, res));
|
295
|
+
}
|
296
|
+
};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _ = require('lodash');
|
4
|
+
const Router = require('express').Router;
|
5
|
+
|
6
|
+
module.exports = SuperClass => {
|
7
|
+
class Behaviour extends SuperClass {
|
8
|
+
runHooks(hook) {
|
9
|
+
return (req, res, next) => {
|
10
|
+
// find the fields which have the current hook defined
|
11
|
+
const hooks = _(req.form.options.fields)
|
12
|
+
.filter(field => field.hooks)
|
13
|
+
.map('hooks')
|
14
|
+
.filter(h => h[hook])
|
15
|
+
.map(hook)
|
16
|
+
.value();
|
17
|
+
if (hooks.length) {
|
18
|
+
Router({ mergeParams: true }).use(hooks).handle(req, res, next);
|
19
|
+
} else {
|
20
|
+
next();
|
21
|
+
}
|
22
|
+
};
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
[
|
27
|
+
// GET pipeline
|
28
|
+
'_getErrors',
|
29
|
+
'_getValues',
|
30
|
+
'_locals',
|
31
|
+
'render',
|
32
|
+
// POST pipeline
|
33
|
+
'_process',
|
34
|
+
'_validate',
|
35
|
+
'saveValues',
|
36
|
+
'successHandler'
|
37
|
+
].forEach(method => {
|
38
|
+
/* eslint-disable func-names */
|
39
|
+
Behaviour.prototype[method] = function (req, res, next) {
|
40
|
+
/* eslint-enable func-names */
|
41
|
+
const methodName = method.replace(/^_/, '');
|
42
|
+
Router({ mergeParams: true }).use([
|
43
|
+
this.runHooks(`pre-${methodName}`),
|
44
|
+
SuperClass.prototype[method].bind(this),
|
45
|
+
this.runHooks(`post-${methodName}`)
|
46
|
+
]).handle(req, res, next);
|
47
|
+
};
|
48
|
+
});
|
49
|
+
|
50
|
+
return Behaviour;
|
51
|
+
};
|
@@ -0,0 +1,64 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const _ = require('lodash');
|
4
|
+
const path = require('path');
|
5
|
+
|
6
|
+
module.exports = SuperClass => class extends SuperClass {
|
7
|
+
configure(req, res, callback) {
|
8
|
+
if (!req.sessionModel) {
|
9
|
+
throw new Error('req.sessionModel must be defined in order to use this behaviour');
|
10
|
+
}
|
11
|
+
super.configure(req, res, callback);
|
12
|
+
}
|
13
|
+
|
14
|
+
getValues(req, res, callback) {
|
15
|
+
const json = req.sessionModel.toJSON();
|
16
|
+
delete json.errorValues;
|
17
|
+
callback(null, Object.assign({}, json, req.sessionModel.get('errorValues')));
|
18
|
+
}
|
19
|
+
|
20
|
+
saveValues(req, res, callback) {
|
21
|
+
req.sessionModel.set(req.form.values);
|
22
|
+
req.sessionModel.unset('errorValues');
|
23
|
+
callback();
|
24
|
+
}
|
25
|
+
|
26
|
+
getErrors(req) {
|
27
|
+
let errs = req.sessionModel.get('errors');
|
28
|
+
errs = _.pick(errs, Object.keys(req.form.options.fields));
|
29
|
+
errs = _.pickBy(errs, err => !err.redirect);
|
30
|
+
return errs;
|
31
|
+
}
|
32
|
+
|
33
|
+
setErrors(err, req) {
|
34
|
+
if (req.form) {
|
35
|
+
req.sessionModel.set('errorValues', req.form.values);
|
36
|
+
}
|
37
|
+
req.sessionModel.set('errors', err);
|
38
|
+
}
|
39
|
+
|
40
|
+
locals(req, res) {
|
41
|
+
return Object.assign({}, super.locals(req, res), {
|
42
|
+
baseUrl: req.baseUrl,
|
43
|
+
nextPage: this.getNextStep(req, res)
|
44
|
+
});
|
45
|
+
}
|
46
|
+
|
47
|
+
missingPrereqHandler(req, res) {
|
48
|
+
const last = _.last(req.sessionModel.get('steps'));
|
49
|
+
let redirect = _.first(Object.keys(this.options.steps));
|
50
|
+
|
51
|
+
if (last && this.options.steps[last]) {
|
52
|
+
redirect = this.options.steps[last].next || last;
|
53
|
+
}
|
54
|
+
res.redirect(path.join(req.baseUrl, redirect));
|
55
|
+
}
|
56
|
+
|
57
|
+
errorHandler(err, req, res, next) {
|
58
|
+
if (err.code === 'MISSING_PREREQ') {
|
59
|
+
this.missingPrereqHandler(req, res, next);
|
60
|
+
} else {
|
61
|
+
super.errorHandler(err, req, res, next);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
};
|