hof 22.9.0-beta.v1 → 22.9.0-beta.v3

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.
Files changed (316) hide show
  1. package/config/hof-defaults.js +1 -0
  2. package/frontend/template-partials/views/cookies.html +6 -6
  3. package/frontend/template-partials/views/partials/cookie-banner.html +11 -6
  4. package/lib/settings.js +1 -0
  5. package/package.json +1 -1
  6. package/package/.eslintignore +0 -1
  7. package/package/CHANGELOG.md +0 -232
  8. package/package/LICENSE +0 -21
  9. package/package/README.md +0 -1887
  10. package/package/bin/hof-build +0 -10
  11. package/package/bin/hof-transpiler +0 -12
  12. package/package/build/helpers/importer.js +0 -29
  13. package/package/build/helpers/local.js +0 -35
  14. package/package/build/helpers/resolver/import.js +0 -32
  15. package/package/build/helpers/resolver/nearest-package-root.js +0 -33
  16. package/package/build/helpers/resolver/package.js +0 -29
  17. package/package/build/helpers/resolver.js +0 -16
  18. package/package/build/index.js +0 -49
  19. package/package/build/lib/env.js +0 -36
  20. package/package/build/lib/mkdir.js +0 -9
  21. package/package/build/lib/run.js +0 -17
  22. package/package/build/lib/spawn.js +0 -18
  23. package/package/build/tasks/browserify/compress.js +0 -15
  24. package/package/build/tasks/browserify/index.js +0 -48
  25. package/package/build/tasks/build/index.js +0 -6
  26. package/package/build/tasks/images/index.js +0 -27
  27. package/package/build/tasks/index.js +0 -8
  28. package/package/build/tasks/sass/index.js +0 -67
  29. package/package/build/tasks/translate/index.js +0 -20
  30. package/package/build/tasks/watch/index.js +0 -161
  31. package/package/components/address-lookup/default-model.js +0 -76
  32. package/package/components/address-lookup/defaults.js +0 -25
  33. package/package/components/address-lookup/index.js +0 -251
  34. package/package/components/address-lookup/templates/address-lookup.html +0 -14
  35. package/package/components/address-lookup/templates/address.html +0 -22
  36. package/package/components/address-lookup/templates/postcode.html +0 -9
  37. package/package/components/clear-session/Readme.md +0 -46
  38. package/package/components/clear-session/index.js +0 -26
  39. package/package/components/combine-and-loop-fields/Readme.md +0 -42
  40. package/package/components/combine-and-loop-fields/index.js +0 -156
  41. package/package/components/date/fields.js +0 -16
  42. package/package/components/date/index.js +0 -172
  43. package/package/components/date/templates/date.html +0 -20
  44. package/package/components/emailer/assets/images/govuk_logotype_email.png +0 -0
  45. package/package/components/emailer/assets/images/ho_crest_27px.png +0 -0
  46. package/package/components/emailer/assets/images/spacer.gif +0 -0
  47. package/package/components/emailer/email-service.js +0 -51
  48. package/package/components/emailer/emailer.js +0 -53
  49. package/package/components/emailer/index.js +0 -74
  50. package/package/components/emailer/transports/debug.js +0 -74
  51. package/package/components/emailer/transports/index.js +0 -8
  52. package/package/components/emailer/transports/ses.js +0 -36
  53. package/package/components/emailer/transports/smtp.js +0 -26
  54. package/package/components/emailer/transports/stub.js +0 -5
  55. package/package/components/emailer/views/layout.html +0 -63
  56. package/package/components/homeoffice-countries/index.js +0 -22
  57. package/package/components/index.js +0 -13
  58. package/package/components/notify/index.js +0 -62
  59. package/package/components/notify/notify.js +0 -51
  60. package/package/components/session-timeout-warning/index.js +0 -67
  61. package/package/components/summary/index.js +0 -237
  62. package/package/config/builder-defaults.js +0 -45
  63. package/package/config/component-defaults.js +0 -13
  64. package/package/config/hof-defaults.js +0 -65
  65. package/package/config/rate-limits.js +0 -20
  66. package/package/config/sanitisation-rules.js +0 -32
  67. package/package/controller/base-controller.js +0 -296
  68. package/package/controller/behaviour-hooks.js +0 -51
  69. package/package/controller/behaviour-session.js +0 -64
  70. package/package/controller/controller.js +0 -258
  71. package/package/controller/deprecate-error.js +0 -10
  72. package/package/controller/formatting/formatters.js +0 -70
  73. package/package/controller/formatting/index.js +0 -32
  74. package/package/controller/index.js +0 -17
  75. package/package/controller/validation/email.js +0 -30
  76. package/package/controller/validation/index.js +0 -101
  77. package/package/controller/validation/validators.js +0 -181
  78. package/package/controller/validation-error.js +0 -14
  79. package/package/frontend/govuk-template/build/config.js +0 -24
  80. package/package/frontend/govuk-template/build/govuk_template.html +0 -102
  81. package/package/frontend/govuk-template/build/index.js +0 -23
  82. package/package/frontend/govuk-template/govuk_template_generated.html +0 -102
  83. package/package/frontend/govuk-template/index.js +0 -29
  84. package/package/frontend/index.js +0 -9
  85. package/package/frontend/template-mixins/mixins/helpers.js +0 -103
  86. package/package/frontend/template-mixins/mixins/index.js +0 -37
  87. package/package/frontend/template-mixins/mixins/render.js +0 -12
  88. package/package/frontend/template-mixins/mixins/template-mixins.js +0 -520
  89. package/package/frontend/template-mixins/partials/forms/checkbox-group.html +0 -47
  90. package/package/frontend/template-mixins/partials/forms/checkbox.html +0 -16
  91. package/package/frontend/template-mixins/partials/forms/input-submit.html +0 -1
  92. package/package/frontend/template-mixins/partials/forms/input-text-date.html +0 -37
  93. package/package/frontend/template-mixins/partials/forms/input-text-group.html +0 -45
  94. package/package/frontend/template-mixins/partials/forms/option-group.html +0 -43
  95. package/package/frontend/template-mixins/partials/forms/select.html +0 -17
  96. package/package/frontend/template-mixins/partials/forms/textarea-group.html +0 -37
  97. package/package/frontend/template-mixins/partials/mixins/panel.html +0 -4
  98. package/package/frontend/template-partials/index.js +0 -9
  99. package/package/frontend/template-partials/translations/index.js +0 -26
  100. package/package/frontend/template-partials/translations/src/cy/base.json +0 -4
  101. package/package/frontend/template-partials/translations/src/cy/buttons.json +0 -6
  102. package/package/frontend/template-partials/translations/src/cy/cookies.json +0 -104
  103. package/package/frontend/template-partials/translations/src/cy/errorlist.json +0 -6
  104. package/package/frontend/template-partials/translations/src/cy/errors.json +0 -18
  105. package/package/frontend/template-partials/translations/src/cy/terms.json +0 -28
  106. package/package/frontend/template-partials/translations/src/en/accessibility.json +0 -43
  107. package/package/frontend/template-partials/translations/src/en/base.json +0 -5
  108. package/package/frontend/template-partials/translations/src/en/buttons.json +0 -10
  109. package/package/frontend/template-partials/translations/src/en/cookies.json +0 -116
  110. package/package/frontend/template-partials/translations/src/en/errorlist.json +0 -7
  111. package/package/frontend/template-partials/translations/src/en/errors.json +0 -35
  112. package/package/frontend/template-partials/translations/src/en/exit.json +0 -5
  113. package/package/frontend/template-partials/translations/src/en/fields.json +0 -5
  114. package/package/frontend/template-partials/translations/src/en/journey.json +0 -6
  115. package/package/frontend/template-partials/translations/src/en/save-and-exit.json +0 -4
  116. package/package/frontend/template-partials/translations/src/en/terms.json +0 -28
  117. package/package/frontend/template-partials/views/404.html +0 -9
  118. package/package/frontend/template-partials/views/accessibility.html +0 -55
  119. package/package/frontend/template-partials/views/confirm.html +0 -8
  120. package/package/frontend/template-partials/views/confirmation.html +0 -19
  121. package/package/frontend/template-partials/views/content/en/what-happens-next.md +0 -0
  122. package/package/frontend/template-partials/views/cookie-error.html +0 -1
  123. package/package/frontend/template-partials/views/cookies.html +0 -84
  124. package/package/frontend/template-partials/views/email/data-row.html +0 -4
  125. package/package/frontend/template-partials/views/email/formatted.html +0 -12
  126. package/package/frontend/template-partials/views/email/layout.html +0 -63
  127. package/package/frontend/template-partials/views/email/raw.html +0 -11
  128. package/package/frontend/template-partials/views/email/section-row.html +0 -3
  129. package/package/frontend/template-partials/views/error.html +0 -20
  130. package/package/frontend/template-partials/views/exit.html +0 -9
  131. package/package/frontend/template-partials/views/feedback-submitted.html +0 -11
  132. package/package/frontend/template-partials/views/layout.html +0 -55
  133. package/package/frontend/template-partials/views/partials/analytics-table.html +0 -25
  134. package/package/frontend/template-partials/views/partials/back.html +0 -5
  135. package/package/frontend/template-partials/views/partials/bullet-list.html +0 -7
  136. package/package/frontend/template-partials/views/partials/confirmation-alert.html +0 -6
  137. package/package/frontend/template-partials/views/partials/continue.html +0 -5
  138. package/package/frontend/template-partials/views/partials/cookie-banner.html +0 -29
  139. package/package/frontend/template-partials/views/partials/cookie-notification.html +0 -4
  140. package/package/frontend/template-partials/views/partials/cookie-settings-button.html +0 -1
  141. package/package/frontend/template-partials/views/partials/cookie-settings-radio.html +0 -8
  142. package/package/frontend/template-partials/views/partials/details-summary.html +0 -8
  143. package/package/frontend/template-partials/views/partials/external-link.html +0 -1
  144. package/package/frontend/template-partials/views/partials/form.html +0 -10
  145. package/package/frontend/template-partials/views/partials/gatag.html +0 -60
  146. package/package/frontend/template-partials/views/partials/head.html +0 -31
  147. package/package/frontend/template-partials/views/partials/heading.html +0 -11
  148. package/package/frontend/template-partials/views/partials/items-table.html +0 -32
  149. package/package/frontend/template-partials/views/partials/maincontent-left.html +0 -10
  150. package/package/frontend/template-partials/views/partials/navigation.html +0 -8
  151. package/package/frontend/template-partials/views/partials/page.html +0 -23
  152. package/package/frontend/template-partials/views/partials/panel-indent.html +0 -3
  153. package/package/frontend/template-partials/views/partials/session-cookies-table.html +0 -28
  154. package/package/frontend/template-partials/views/partials/session-timeout-warning.html +0 -38
  155. package/package/frontend/template-partials/views/partials/summary-table-row.html +0 -14
  156. package/package/frontend/template-partials/views/partials/summary-table.html +0 -8
  157. package/package/frontend/template-partials/views/partials/table.html +0 -18
  158. package/package/frontend/template-partials/views/partials/validation-list.html +0 -3
  159. package/package/frontend/template-partials/views/partials/validation-summary.html +0 -25
  160. package/package/frontend/template-partials/views/partials/warn.html +0 -7
  161. package/package/frontend/template-partials/views/rate-limit-error.html +0 -10
  162. package/package/frontend/template-partials/views/save-and-exit.html +0 -17
  163. package/package/frontend/template-partials/views/service-unavailable.html +0 -13
  164. package/package/frontend/template-partials/views/session-timeout.html +0 -7
  165. package/package/frontend/template-partials/views/step.html +0 -14
  166. package/package/frontend/template-partials/views/terms.html +0 -26
  167. package/package/frontend/themes/gov-uk/client-js/cookieSettings.js +0 -145
  168. package/package/frontend/themes/gov-uk/client-js/govuk-cookies.js +0 -121
  169. package/package/frontend/themes/gov-uk/client-js/index.js +0 -27
  170. package/package/frontend/themes/gov-uk/client-js/session-timeout-dialog.js +0 -348
  171. package/package/frontend/themes/gov-uk/client-js/skip-to-main.js +0 -19
  172. package/package/frontend/themes/gov-uk/index.js +0 -9
  173. package/package/frontend/themes/gov-uk/styles/_base.scss +0 -17
  174. package/package/frontend/themes/gov-uk/styles/_check_your_answers.scss +0 -155
  175. package/package/frontend/themes/gov-uk/styles/_cookie-banner.scss +0 -111
  176. package/package/frontend/themes/gov-uk/styles/_cookie-settings.scss +0 -33
  177. package/package/frontend/themes/gov-uk/styles/_govuk_frontend_toolkit.scss +0 -23
  178. package/package/frontend/themes/gov-uk/styles/_helpers.scss +0 -5
  179. package/package/frontend/themes/gov-uk/styles/_layout.scss +0 -125
  180. package/package/frontend/themes/gov-uk/styles/_panel-indent.scss +0 -27
  181. package/package/frontend/themes/gov-uk/styles/_pdf.scss +0 -42
  182. package/package/frontend/themes/gov-uk/styles/_session-timeout-dialog.scss +0 -121
  183. package/package/frontend/themes/gov-uk/styles/_typography.scss +0 -27
  184. package/package/frontend/themes/gov-uk/styles/_variables.scss +0 -11
  185. package/package/frontend/themes/gov-uk/styles/govuk.scss +0 -43
  186. package/package/frontend/themes/gov-uk/styles/mixins.scss +0 -16
  187. package/package/frontend/themes/gov-uk/styles/modules/_alerts.scss +0 -73
  188. package/package/frontend/themes/gov-uk/styles/modules/_buttons.scss +0 -5
  189. package/package/frontend/themes/gov-uk/styles/modules/_character-count.scss +0 -8
  190. package/package/frontend/themes/gov-uk/styles/modules/_confirm-page.scss +0 -20
  191. package/package/frontend/themes/gov-uk/styles/modules/_lists.scss +0 -5
  192. package/package/frontend/themes/gov-uk/styles/modules/_progressive-reveal.scss +0 -17
  193. package/package/frontend/themes/gov-uk/styles/modules/_validation.scss +0 -51
  194. package/package/frontend/themes/index.js +0 -5
  195. package/package/frontend/toolkit/assets/images/passports/new-window-link-blue.png +0 -0
  196. package/package/frontend/toolkit/assets/images/passports/new-window-link.png +0 -0
  197. package/package/frontend/toolkit/assets/images/spinner.gif +0 -0
  198. package/package/frontend/toolkit/assets/javascript/character-count.js +0 -99
  199. package/package/frontend/toolkit/assets/javascript/form-focus.js +0 -101
  200. package/package/frontend/toolkit/assets/javascript/helpers.js +0 -177
  201. package/package/frontend/toolkit/assets/javascript/progressive-reveal.js +0 -72
  202. package/package/frontend/toolkit/assets/javascript/validation.js +0 -71
  203. package/package/frontend/toolkit/assets/javascript/vendor/details.polyfill.js +0 -189
  204. package/package/frontend/toolkit/assets/javascript/vendor/indexof.polyfill.js +0 -39
  205. package/package/frontend/toolkit/assets/javascript/vendor/safari-cachebuster.js +0 -6
  206. package/package/frontend/toolkit/assets/stylesheets/_base.scss +0 -17
  207. package/package/frontend/toolkit/assets/stylesheets/_helpers.scss +0 -5
  208. package/package/frontend/toolkit/assets/stylesheets/_layout.scss +0 -118
  209. package/package/frontend/toolkit/assets/stylesheets/_typography.scss +0 -27
  210. package/package/frontend/toolkit/assets/stylesheets/_variables.scss +0 -11
  211. package/package/frontend/toolkit/assets/stylesheets/app.scss +0 -30
  212. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_buttons.scss +0 -47
  213. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_details.scss +0 -38
  214. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_elements-typography.scss +0 -175
  215. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_forms.scss +0 -167
  216. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_helpers.scss +0 -39
  217. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_layout.scss +0 -67
  218. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_lists.scss +0 -40
  219. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_panels.scss +0 -29
  220. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_reset.scss +0 -33
  221. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/_tables.scss +0 -33
  222. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-block-labels.scss +0 -63
  223. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-date.scss +0 -39
  224. package/package/frontend/toolkit/assets/stylesheets/govuk-elements/forms/_form-validation.scss +0 -63
  225. package/package/frontend/toolkit/assets/stylesheets/mixins.scss +0 -16
  226. package/package/frontend/toolkit/assets/stylesheets/modules/_alerts.scss +0 -73
  227. package/package/frontend/toolkit/assets/stylesheets/modules/_buttons.scss +0 -5
  228. package/package/frontend/toolkit/assets/stylesheets/modules/_confirm-page.scss +0 -20
  229. package/package/frontend/toolkit/assets/stylesheets/modules/_lists.scss +0 -5
  230. package/package/frontend/toolkit/assets/stylesheets/modules/_progressive-reveal.scss +0 -17
  231. package/package/frontend/toolkit/assets/stylesheets/modules/_validation.scss +0 -51
  232. package/package/frontend/toolkit/index.js +0 -10
  233. package/package/index.js +0 -351
  234. package/package/lib/deindex.js +0 -18
  235. package/package/lib/encryption.js +0 -23
  236. package/package/lib/ga-tag.js +0 -89
  237. package/package/lib/health.js +0 -26
  238. package/package/lib/helpers.js +0 -66
  239. package/package/lib/logger.js +0 -65
  240. package/package/lib/markdown.js +0 -46
  241. package/package/lib/router.js +0 -111
  242. package/package/lib/serve-static.js +0 -12
  243. package/package/lib/sessions.js +0 -82
  244. package/package/lib/settings.js +0 -74
  245. package/package/lib/which.js +0 -28
  246. package/package/middleware/cookies.js +0 -43
  247. package/package/middleware/deep-translate.js +0 -32
  248. package/package/middleware/errors.js +0 -119
  249. package/package/middleware/index.js +0 -10
  250. package/package/middleware/not-found.js +0 -38
  251. package/package/middleware/rate-limiter.js +0 -98
  252. package/package/middleware/service-unavailable.js +0 -64
  253. package/package/model/apis/axios-settings.js +0 -21
  254. package/package/model/apis/html-to-pdf-converter.js +0 -35
  255. package/package/model/apis/index.js +0 -5
  256. package/package/model/index.js +0 -348
  257. package/package/package.json +0 -147
  258. package/package/sandbox/README.md +0 -66
  259. package/package/sandbox/apps/sandbox/behaviours/clear-session.js +0 -8
  260. package/package/sandbox/apps/sandbox/behaviours/country-select.js +0 -10
  261. package/package/sandbox/apps/sandbox/behaviours/international-number.js +0 -22
  262. package/package/sandbox/apps/sandbox/fields.js +0 -128
  263. package/package/sandbox/apps/sandbox/index.js +0 -99
  264. package/package/sandbox/apps/sandbox/lib/staticAppealStages.js +0 -189
  265. package/package/sandbox/apps/sandbox/sections/summary-data-sections.js +0 -43
  266. package/package/sandbox/apps/sandbox/translations/src/en/errors.json +0 -5
  267. package/package/sandbox/apps/sandbox/translations/src/en/exit.json +0 -4
  268. package/package/sandbox/apps/sandbox/translations/src/en/fields.json +0 -101
  269. package/package/sandbox/apps/sandbox/translations/src/en/journey.json +0 -7
  270. package/package/sandbox/apps/sandbox/translations/src/en/pages.json +0 -72
  271. package/package/sandbox/apps/sandbox/translations/src/en/validation.json +0 -54
  272. package/package/sandbox/apps/sandbox/views/form-guidance-link.html +0 -8
  273. package/package/sandbox/apps/sandbox/views/save-and-exit.html +0 -19
  274. package/package/sandbox/assets/images/icons/icon-caret-left.png +0 -0
  275. package/package/sandbox/assets/images/icons/icon-complete.png +0 -0
  276. package/package/sandbox/assets/images/icons/icon-cross-remove-sign.png +0 -0
  277. package/package/sandbox/assets/js/index.js +0 -70
  278. package/package/sandbox/assets/scss/app.scss +0 -27
  279. package/package/sandbox/codecept.conf.js +0 -15
  280. package/package/sandbox/config.js +0 -17
  281. package/package/sandbox/package.json +0 -26
  282. package/package/sandbox/server.js +0 -23
  283. package/package/sandbox/yarn.lock +0 -262
  284. package/package/transpiler/index.js +0 -2
  285. package/package/transpiler/lib/aggregate.js +0 -32
  286. package/package/transpiler/lib/build.js +0 -15
  287. package/package/transpiler/lib/compile.js +0 -12
  288. package/package/transpiler/lib/expand-dirs.js +0 -14
  289. package/package/transpiler/lib/write-files.js +0 -24
  290. package/package/utilities/autofill/index.js +0 -189
  291. package/package/utilities/autofill/inputs.js +0 -60
  292. package/package/utilities/countries.js +0 -12
  293. package/package/utilities/helpers/index.js +0 -189
  294. package/package/utilities/index.js +0 -9
  295. package/package/utilities/reqres/index.js +0 -18
  296. package/package/utilities/test-data/data/domain.json +0 -7
  297. package/package/utilities/test-data/data/firstname.json +0 -16
  298. package/package/utilities/test-data/data/lastname.json +0 -10
  299. package/package/utilities/test-data/data/postcode.json +0 -12
  300. package/package/utilities/test-data/data/streetname.json +0 -8
  301. package/package/utilities/test-data/data/streetsuffix.json +0 -7
  302. package/package/utilities/test-data/data/town.json +0 -9
  303. package/package/utilities/test-data/index.js +0 -67
  304. package/package/wizard/behaviours/complete.js +0 -20
  305. package/package/wizard/behaviours/index.js +0 -5
  306. package/package/wizard/index.js +0 -124
  307. package/package/wizard/middleware/back-links.js +0 -68
  308. package/package/wizard/middleware/check-complete.js +0 -13
  309. package/package/wizard/middleware/check-progress.js +0 -139
  310. package/package/wizard/middleware/check-session.js +0 -17
  311. package/package/wizard/middleware/csrf.js +0 -47
  312. package/package/wizard/middleware/session-model.js +0 -11
  313. package/package/wizard/middleware/session.js +0 -9
  314. package/package/wizard/model.js +0 -29
  315. package/package/wizard/util/constants.js +0 -5
  316. package/package/wizard/util/helpers.js +0 -19
@@ -1,258 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
- const i18nLookup = require('i18n-lookup');
5
- const Mustache = require('mustache');
6
- const BaseController = require('./base-controller');
7
- const Helpers = require('../utilities').helpers;
8
-
9
- const omitField = (field, req) => field.useWhen && (typeof field.useWhen === 'string'
10
- ? req.sessionModel.get(field.useWhen) !== 'true'
11
- : req.sessionModel.get(field.useWhen.field) !== field.useWhen.value);
12
-
13
- module.exports = class Controller extends BaseController {
14
- constructor(options) {
15
- super(options);
16
- this.confirmStep = options.confirmStep || '/confirm';
17
- }
18
-
19
- configure(req, res, callback) {
20
- const removeFields = Object.keys(_.pickBy(req.form.options.fields, field => omitField(field, req)));
21
- if (removeFields.length) {
22
- req.form.options.fields = _.omit(req.form.options.fields, removeFields);
23
- req.sessionModel.unset(removeFields);
24
- }
25
- callback();
26
- }
27
-
28
- get(req, res, callback) {
29
- const template = this.options.template || '';
30
- res.render(template, err => {
31
- if (err && err.message.match(/^Failed to lookup view/)) {
32
- this.options.template = res.locals.partials.step;
33
- }
34
- });
35
- super.get(req, res, callback);
36
- }
37
-
38
- getNextStep(req, res) {
39
- let next = super.getNextStep(req, res);
40
- const forks = req.form.options.forks || [];
41
-
42
- const normaliseUrl = url => req.baseUrl === '/' ? url : req.baseUrl + url;
43
-
44
- const confirmStep = normaliseUrl(this.confirmStep);
45
-
46
- const completed = s => {
47
- let step = s;
48
- if (req.baseUrl !== '/') {
49
- const re = new RegExp('^' + req.baseUrl);
50
- step = step.replace(re, '');
51
- }
52
- // Has the user already completed the step?
53
- return _.includes(req.sessionModel.get('steps'), step);
54
- };
55
-
56
- // If a form condition is met, its target supercedes the next property
57
- next = _.reduce(forks, (result, value) => {
58
- if (Helpers.isFieldValueInPageOrSessionValid(req, res, value.condition)) {
59
- if (value.continueOnEdit) {
60
- req.form.options.continueOnEdit = true;
61
- }
62
- return normaliseUrl(value.target);
63
- }
64
- return result;
65
- }, next);
66
-
67
-
68
- if (req.params.action === 'edit') {
69
- if (!req.form.options.continueOnEdit && completed(next)) {
70
- next = confirmStep;
71
- }
72
- if (next !== confirmStep) {
73
- next += '/edit';
74
- }
75
- }
76
-
77
- return next;
78
- }
79
-
80
- getBackLink(req, res) {
81
- const backLink = res.locals.backLink;
82
- const trailingEdit = req.params.action === 'edit' ? '/edit' : '';
83
- const leadingSlash = /^\/?\w+/.test(req.baseUrl) ? '' : '/';
84
-
85
- if (!backLink) {
86
- return backLink;
87
- }
88
-
89
- return `${leadingSlash}${backLink}${trailingEdit}`;
90
- }
91
-
92
- getErrorStep(err, req) {
93
- let redirect = super.getErrorStep(err, req);
94
- if (req.params.action === 'edit' && !redirect.match(/\/edit$|\/edit\//)) {
95
- redirect += '/edit';
96
- }
97
- return redirect;
98
- }
99
-
100
- locals(req, res) {
101
- const lookup = i18nLookup(req.translate, Mustache.render);
102
- const route = req.form.options.route.replace(/^\//, '');
103
- const locals = super.locals(req, res);
104
- const stepLocals = req.form.options.locals || {};
105
-
106
- let fields = _.map(req.form.options.fields, (field, key) =>
107
- Object.assign({}, field, { key })
108
- );
109
- // only include fields that aren't dependents to mitigate duplicate fields on the page
110
- fields = fields.filter(field => !req.form.options.fields[field.key].dependent);
111
-
112
- const exitStep = req.form.options.exitStep || '/exit';
113
- const saveAndExitStep = req.form.options.saveAndExitStep || '/save-and-exit';
114
- return _.extend({}, locals, {
115
- fields,
116
- route,
117
- baseUrl: req.baseUrl,
118
- exitStep,
119
- saveAndExitStep,
120
- skipToMain: this.getFirstFormItem(req.form.options.fields),
121
- title: this.getTitle(route, lookup, req.form.options.fields, res.locals),
122
- journeyHeaderURL: this.getJourneyHeaderURL(req.baseUrl),
123
- header: this.getHeader(route, lookup, res.locals),
124
- serviceName: this.getServiceName(lookup, res.locals),
125
- captionHeading: this.getCaptionHeading(route, lookup, res.locals),
126
- warning: this.getWarning(route, lookup, res.locals),
127
- subHeading: this.getSubHeading(route, lookup, res.locals),
128
- intro: this.getIntro(route, lookup, res.locals),
129
- backLink: this.getBackLink(req, res),
130
- nextPage: this.getNextStep(req, res),
131
- errorLength: this.getErrorLength(req, res)
132
- }, stepLocals);
133
- }
134
-
135
- getJourneyHeaderURL(url) {
136
- return url === '' ? '/' : url;
137
- }
138
-
139
- getFirstFormItem(fields) {
140
- let firstFieldKey;
141
- if (_.size(fields)) {
142
- firstFieldKey = Object.keys(fields)[0];
143
- }
144
- return firstFieldKey | 'main-content';
145
- }
146
-
147
- getHeader(route, lookup, locals) {
148
- return lookup(`pages.${route}.header`, locals);
149
- }
150
-
151
- getServiceName(lookup, locals) {
152
- return lookup([
153
- 'journey.serviceName',
154
- 'journey.header'
155
- ], locals);
156
- }
157
-
158
- getCaptionHeading(route, lookup, locals) {
159
- return lookup(`pages.${route}.captionHeading`, locals);
160
- }
161
-
162
- getSubHeading(route, lookup, locals) {
163
- return lookup(`pages.${route}.subHeading`, locals);
164
- }
165
-
166
- getWarning(route, lookup, locals) {
167
- return lookup(`pages.${route}.warning`, locals);
168
- }
169
-
170
- getTitle(route, lookup, fields, locals) {
171
- let fieldName = '';
172
- if (_.size(fields)) {
173
- fieldName = Object.keys(fields)[0];
174
- }
175
- return lookup([
176
- `pages.${route}.title`,
177
- `pages.${route}.header`,
178
- `fields.${fieldName}.label`,
179
- `fields.${fieldName}.legend`
180
- ], locals);
181
- }
182
-
183
- getIntro(route, lookup, locals) {
184
- return lookup([
185
- `pages.${route}.intro`
186
- ], locals);
187
- }
188
-
189
- _getErrors(req, res, callback) {
190
- super._getErrors(req, res, () => {
191
- Object.keys(req.form.errors).forEach(key => {
192
- if (req.form && req.form.options && req.form.options.fields) {
193
- const field = req.form.options.fields[key];
194
- // get first option for radios and checkbox
195
- if (field.mixin === 'radio-group' || field.mixin === 'checkbox-group') {
196
- // get first option for radios and checkbox where there is a toggle
197
- if (typeof field.options[0] === 'object') {
198
- req.form.errors[key].errorLinkId = key + '-' + field.options[0].value;
199
- } else {
200
- req.form.errors[key].errorLinkId = key + '-' + field.options[0];
201
- }
202
- // eslint-disable-next-line brace-style
203
- }
204
- // get first field for date input control
205
- else if (field && field.mixin === 'input-date') {
206
- req.form.errors[key].errorLinkId = key + '-day';
207
- } else {
208
- req.form.errors[key].errorLinkId = key;
209
- }
210
- }
211
-
212
- req.form.errors[key].message = this.getErrorMessage(req.form.errors[key], req, res);
213
- });
214
- callback();
215
- });
216
- }
217
-
218
- getErrorMessage(error, req, res) {
219
- error.type = error.type || 'default';
220
- error.options = error.options || {};
221
- const keys = [
222
- `fields.${error.key}.validation.${error.type}`,
223
- `validation.${error.key}.${error.type}`,
224
- `validation.${error.key}.default`,
225
- `validation.${error.type}`,
226
- 'validation.default'
227
- ];
228
- const getArgs = () => {
229
- if (error.type === 'before' || error.type === 'after') {
230
- return { diff: error.arguments.join(' ') };
231
- } else if (error.arguments && Array.isArray(error.arguments)) {
232
- return { [error.type]: error.arguments[0] };
233
- }
234
- return {};
235
- };
236
- const context = Object.assign({
237
- label: req.translate(`fields.${error.key}.label`).toLowerCase(),
238
- legend: req.translate(`fields.${error.key}.legend`).toLowerCase()
239
- }, res.locals, getArgs(error));
240
-
241
- return i18nLookup(req.translate, Mustache.render)(keys, context);
242
- }
243
-
244
- // eslint-disable-next-line no-unused-vars
245
- getErrorLength(req, res) {
246
- if (!req.form.errors) {
247
- return undefined;
248
- }
249
-
250
- const errorLength = Object.keys(req.form.errors).length;
251
-
252
- const propName = errorLength === 1 ? 'single' : 'multiple';
253
-
254
- return errorLength ? {
255
- [propName]: true
256
- } : undefined;
257
- }
258
- };
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- const deprecate = require('deprecate');
4
-
5
- module.exports = superclass => class DeprecatedError extends superclass {
6
- constructor(options) {
7
- deprecate('this.Error is deprecated in favour of this.ValidationError');
8
- super(options);
9
- }
10
- };
@@ -1,70 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
-
5
- trim(value) {
6
- return typeof value === 'string' ? value.trim() : value;
7
- },
8
-
9
- boolean(value) {
10
- if (value === true || value === 'true') {
11
- return true;
12
- } else if (value === false || value === 'false') {
13
- return false;
14
- }
15
- return undefined;
16
- },
17
-
18
- uppercase(value) {
19
- return typeof value === 'string' ? value.toUpperCase() : value;
20
- },
21
-
22
- lowercase(value) {
23
- return typeof value === 'string' ? value.toLowerCase() : value;
24
- },
25
-
26
- removespaces(value) {
27
- return typeof value === 'string' ? value.replace(/\s+/g, '') : value;
28
- },
29
-
30
- singlespaces(value) {
31
- return typeof value === 'string' ? value.replace(/\s+/g, ' ') : value;
32
- },
33
-
34
- hyphens(value) {
35
- return typeof value === 'string' ? value.replace(/[–—-]+/g, '-') : value;
36
- },
37
-
38
- removeroundbrackets(value) {
39
- return typeof value === 'string' ? value.replace(/[\(\)]/g, '') : value;
40
- },
41
-
42
- removehyphens(value) {
43
- return typeof value === 'string' ? value.replace(/[–—-]+/g, '') : value;
44
- },
45
-
46
- removeslashes(value) {
47
- return typeof value === 'string' ? value.replace(/[\/\\]/g, '') : value;
48
- },
49
-
50
- ukphoneprefix(value) {
51
- return typeof value === 'string' ? value.replace(/^\+44\(?0?\)?/, '0') : value;
52
- },
53
-
54
- base64decode(value) {
55
- return Buffer.from(value, 'base64').toString();
56
- },
57
-
58
- ukPostcode(value) {
59
- if (typeof value !== 'string' || value === '') {
60
- return value;
61
- }
62
-
63
- const postcode = this.uppercase(this.removespaces(value));
64
- const firstPart = postcode.slice(0, -3);
65
- const secondPart = postcode.slice(-3);
66
-
67
- return `${firstPart} ${secondPart}`;
68
- }
69
-
70
- };
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
-
5
- function format(f, val, formatters) {
6
- let value = val;
7
- if (typeof f === 'string' && formatters[f]) {
8
- return formatters[f](value);
9
- } else if (typeof f === 'function') {
10
- return f(value);
11
- } else if (Array.isArray(f)) {
12
- f.forEach(v => {
13
- value = format(v, value, formatters);
14
- });
15
- }
16
- return value;
17
- }
18
-
19
- module.exports = (fields, _default, f) => (key, v) => {
20
- const formatters = f || require('./formatters');
21
- let value = _.castArray(v);
22
- if (_default && !(fields[key] && fields[key]['ignore-defaults'])) {
23
- value = value.map(item => format(_default, item, formatters));
24
- }
25
- if (fields[key] && fields[key].formatter) {
26
- value = value.map(item => format(fields[key].formatter, item, formatters));
27
- }
28
- if (value.length === 1) {
29
- value = value[0];
30
- }
31
- return value;
32
- };
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- const Session = require('./behaviour-session');
4
- const Hooks = require('./behaviour-hooks');
5
- const Controller = require('./controller');
6
- const mix = require('mixwith').mix;
7
-
8
- class FormController extends mix(Controller).with(Session, Hooks) {}
9
-
10
- FormController.validators = require('./validation/validators');
11
- FormController.formatters = require('./formatting/formatters');
12
-
13
- FormController.ValidationError = require('./validation-error');
14
-
15
- module.exports = FormController;
16
- module.exports.Controller = Controller;
17
- module.exports.BaseController = require('./base-controller');
@@ -1,30 +0,0 @@
1
- /* eslint-disable vars-on-top */
2
- 'use strict';
3
-
4
- // eslint-disable-next-line max-len
5
- const tester = /^[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
6
-
7
- module.exports = function (email) {
8
- if (!email || !(typeof email === 'string')) return false;
9
-
10
- const emailParts = email.split('@');
11
-
12
- if (emailParts.length !== 2) return false;
13
-
14
- const account = emailParts[0];
15
- const address = emailParts[1];
16
-
17
- if (account.length > 64) return false;
18
-
19
- else if (address.length > 255) return false;
20
-
21
- const domainParts = address.split('.');
22
- if (domainParts.some(function (part) {
23
- return part.length > 63;
24
- })) return false;
25
-
26
-
27
- if (!tester.test(email)) return false;
28
-
29
- return true;
30
- };
@@ -1,101 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
- const debug = require('debug')('hmpo:validation');
5
-
6
- const validators = require('./validators');
7
-
8
- function applyValidator(vlt, value, key) {
9
- const validator = typeof vlt === 'string' ? { type: vlt } : vlt;
10
-
11
- function doValidate() {
12
- debug('Applying %s validator with value "%s"', validator.type, value);
13
- let args = [value];
14
- if (!Array.isArray(validator.arguments)) {
15
- validator.arguments = [validator.arguments];
16
- }
17
- args = args.concat(validator.arguments);
18
- if (!validators[validator.type].apply(null, args)) {
19
- return Object.assign({ key }, validator, { arguments: validator.arguments });
20
- }
21
- return undefined;
22
- }
23
-
24
- function customValidate() {
25
- debug('Applying custom %s validator with value %s', validator.name, value);
26
- if (!validator(value)) {
27
- return Object.assign({ key }, { type: validator.name });
28
- }
29
- return undefined;
30
- }
31
-
32
- if (validators[validator.type]) {
33
- return doValidate();
34
- } else if (typeof validator === 'function') {
35
- if (validator.name) {
36
- return customValidate();
37
- }
38
- throw new Error('Custom validator needs to be a named function');
39
- } else {
40
- throw new Error(`Undefined validator:${validator.type}`);
41
- }
42
- }
43
-
44
- function validate(fields) {
45
- _.each(fields, (field, key) => {
46
- if (typeof fields[key].validate === 'string') {
47
- fields[key].validate = [fields[key].validate];
48
- }
49
-
50
- if (fields[key].options) {
51
- fields[key].validate = fields[key].validate || [];
52
- fields[key].validate.push({
53
- type: 'equal',
54
- arguments: _.map(fields[key].options, option =>
55
- typeof option === 'string' ? option : option.value
56
- )
57
- });
58
- }
59
- });
60
-
61
- // eslint-disable-next-line consistent-return
62
- return (key, value, values, emptyValue) => {
63
- debug(`Validating field: "${key}" with value: "${value}"`);
64
-
65
- function shouldValidate() {
66
- // validationLink used to validates multiple dependent fields in checkbox-group
67
- let dependent = fields[key].dependent || fields[key].validationLink;
68
-
69
- if (typeof dependent === 'string') {
70
- dependent = {
71
- field: dependent,
72
- value: true
73
- };
74
- }
75
- if (!dependent
76
- || (dependent && !fields[dependent.field])
77
- || (dependent && (Array.isArray(values[dependent.field])
78
- ? values[dependent.field].indexOf(dependent.value) > -1
79
- : values[dependent.field] === dependent.value))
80
- ) {
81
- return true;
82
- }
83
- return false;
84
- }
85
-
86
- if (fields[key]) {
87
- if (shouldValidate()) {
88
- debug(`Applying validation on field ${key} with ${value}`);
89
- return _.reduce(fields[key].validate, (err, validator) =>
90
- err || applyValidator(validator, value, key)
91
- , null);
92
- }
93
- values[key] = emptyValue === undefined ? '' : emptyValue;
94
- debug('Skipping validation for field %s', key);
95
- }
96
- };
97
- }
98
-
99
- validate.validators = validators;
100
-
101
- module.exports = validate;
@@ -1,181 +0,0 @@
1
- 'use strict';
2
-
3
- const moment = require('moment');
4
- const _ = require('lodash');
5
- const libPhoneNumber = require('libphonenumber-js/max');
6
- const deprecate = require('deprecate');
7
- const emailValidator = require('./email');
8
-
9
- // validator methods should return false (or falsy value) for *invalid* input
10
- // and true (or truthy value) for *valid* input.
11
- const dateFormat = 'YYYY-MM-DD';
12
- let Validators;
13
-
14
- module.exports = Validators = {
15
-
16
- string(value) {
17
- return typeof value === 'string';
18
- },
19
-
20
- decimal(value) {
21
- return value === '' || Validators.regex(value, /^-?[\d]*\.?\d{0,2}$/);
22
- },
23
-
24
- regex(value, match) {
25
- return Validators.string(value) && !!value.match(match);
26
- },
27
-
28
- required(value) {
29
- return value !== undefined && value !== '';
30
- },
31
-
32
- url(value) {
33
- return value === '' ||
34
- Validators.regex(value, /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/);
35
- },
36
-
37
- notUrl(value) {
38
- return value === '' || !(Validators.url(value));
39
- },
40
-
41
- email(value) {
42
- return value === '' || emailValidator(value);
43
- },
44
-
45
- between(value, min, max) {
46
- return value === '' || (value <= max && value >= min);
47
- },
48
-
49
- min(value, min) {
50
- return value === '' || value >= min;
51
- },
52
-
53
- max(value, max) {
54
- return value === '' || value <= max;
55
- },
56
-
57
- minlength(value, length) {
58
- return Validators.string(value) && (value === '' || value.length >= (length || 0));
59
- },
60
-
61
- maxlength(value, length) {
62
- return Validators.string(value) && (value === '' || value.length <= length);
63
- },
64
-
65
- maxword(value, length) {
66
- return Validators.string(value) && (value === '' || value.split(/\s+/).length <= length);
67
- },
68
-
69
- exactlength(value, length) {
70
- return Validators.string(value) && (value === '' || value.length === length);
71
- },
72
-
73
- alphanum(value) {
74
- return Validators.regex(value, /^[a-zA-Z0-9]*$/);
75
- },
76
-
77
- numeric(value) {
78
- return Validators.regex(value, /^\d*$/);
79
- },
80
-
81
- equal(v) {
82
- const values = [].slice.call(arguments, 1);
83
- const value = _.castArray(v);
84
- return values.length && _.every(value, item =>
85
- item === '' || values.indexOf(item) > -1
86
- );
87
- },
88
-
89
- phonenumber(value) {
90
- deprecate('phonenumber validator', 'Recommend using internationalPhoneNumber for validating ' +
91
- 'international numbers or a different phone validator for more specific requirements.');
92
- return value === '' || Validators.regex(value, /^\(?\+?[\d()-]{0,15}$/);
93
- },
94
-
95
- /**
96
- * Validates international phone numbers (fixed and mobile) including UK.
97
- * Non-GB phone numbers will require country code to validate.
98
- */
99
- internationalPhoneNumber(value, code) {
100
- const countryCode = code || 'GB';
101
- const phoneNumber = libPhoneNumber.parsePhoneNumberFromString(value, countryCode) || '';
102
- const isValidComparedToGivenCountry = code ? phoneNumber.country === countryCode : true;
103
- return value === '' || (phoneNumber && phoneNumber.isValid() && isValidComparedToGivenCountry);
104
- },
105
-
106
- ukPhoneNumber(value) {
107
- const phoneNumber = libPhoneNumber.parsePhoneNumberFromString(value, 'GB') || '';
108
- return value === '' || (phoneNumber && phoneNumber.isValid() && phoneNumber.country === 'GB');
109
- },
110
-
111
- ukmobilephone(value) {
112
- return value === '' || Validators.regex(value, /^(?:\+447|07)\d{9}$/);
113
- },
114
-
115
- date(value) {
116
- return value === '' || Validators.regex(value, /\d{4}\-\d{2}\-\d{2}/) && moment(value, dateFormat).isValid();
117
- },
118
-
119
- 'date-year'(value) {
120
- return Validators.regex(value, /^\d{4}$/);
121
- },
122
-
123
- 'date-month'(value) {
124
- return Validators.regex(value, /^\d{2}$/) && parseInt(value, 10) > 0 && parseInt(value, 10) < 13;
125
- },
126
-
127
- 'date-day'(value) {
128
- return Validators.regex(value, /^\d{2}$/) && parseInt(value, 10) > 0 && parseInt(value, 10) < 32;
129
- },
130
-
131
- // eslint-disable-next-line no-inline-comments, spaced-comment
132
- before(value, date) {
133
- // validator can also do before(value, [diff, unit][, diff, unit])
134
- let valueDate = moment(value, dateFormat);
135
- let comparator;
136
- if (arguments.length === 2) {
137
- comparator = date;
138
- } else {
139
- comparator = moment();
140
- const args = [].slice.call(arguments, 1);
141
- let diff;
142
- let unit;
143
- while (args.length) {
144
- diff = args.shift();
145
- unit = args.shift() || 'years';
146
- valueDate = valueDate.add(diff, unit);
147
- }
148
- }
149
- return value === '' || Validators.date(value) && valueDate.isBefore(comparator);
150
- },
151
-
152
- after(value, date) {
153
- // validator can also do after(value, [diff, unit][, diff, unit])
154
- let valueDate = moment(value, dateFormat);
155
- let comparator;
156
- if (arguments.length === 2) {
157
- comparator = date;
158
- } else {
159
- comparator = moment();
160
- const args = [].slice.call(arguments, 1);
161
- let diff;
162
- let unit;
163
- while (args.length) {
164
- diff = args.shift();
165
- unit = args.shift() || 'years';
166
- valueDate = valueDate.add(diff, unit);
167
- }
168
- }
169
- return value === '' || Validators.date(value) && valueDate.isAfter(comparator);
170
- },
171
-
172
- over18(value) {
173
- return Validators.before(value, '18', 'years');
174
- },
175
-
176
- postcode(value) {
177
- // eslint-disable-next-line max-len
178
- return value === '' || Validators.regex(value, /^(([GIR] ?0[A]{2})|((([A-Z][0-9]{1,2})|(([A-Z][A-HJ-Y][0-9]{1,2})|(([A-Z][0-9][A-Z])|([A-Z][A-HJ-Y][0-9]?[A-Z])))) ?[0-9][A-Z]{2}))$/i);
179
- }
180
-
181
- };