@dwp/govuk-casa 8.16.2 → 8.16.4

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 (189) hide show
  1. package/dist/assets/css/casa-ie8.css +1 -1
  2. package/dist/assets/css/casa.css +1 -1
  3. package/dist/casa.d.ts +13 -13
  4. package/dist/casa.js +17 -7
  5. package/dist/casa.js.map +1 -1
  6. package/dist/lib/CasaTemplateLoader.d.ts +1 -1
  7. package/dist/lib/CasaTemplateLoader.js +13 -14
  8. package/dist/lib/CasaTemplateLoader.js.map +1 -1
  9. package/dist/lib/JourneyContext.d.ts +10 -4
  10. package/dist/lib/JourneyContext.js +57 -47
  11. package/dist/lib/JourneyContext.js.map +1 -1
  12. package/dist/lib/MutableRouter.d.ts +1 -1
  13. package/dist/lib/MutableRouter.js +22 -23
  14. package/dist/lib/MutableRouter.js.map +1 -1
  15. package/dist/lib/Plan.d.ts +5 -5
  16. package/dist/lib/Plan.js +49 -36
  17. package/dist/lib/Plan.js.map +1 -1
  18. package/dist/lib/ValidationError.d.ts +1 -1
  19. package/dist/lib/ValidationError.js +9 -9
  20. package/dist/lib/ValidationError.js.map +1 -1
  21. package/dist/lib/ValidatorFactory.js +4 -7
  22. package/dist/lib/ValidatorFactory.js.map +1 -1
  23. package/dist/lib/configuration-ingestor.d.ts +75 -14
  24. package/dist/lib/configuration-ingestor.js +156 -64
  25. package/dist/lib/configuration-ingestor.js.map +1 -1
  26. package/dist/lib/configure.js +11 -10
  27. package/dist/lib/configure.js.map +1 -1
  28. package/dist/lib/constants.js +8 -8
  29. package/dist/lib/context-id-generators.d.ts +1 -1
  30. package/dist/lib/context-id-generators.js +7 -4
  31. package/dist/lib/context-id-generators.js.map +1 -1
  32. package/dist/lib/end-session.js +2 -2
  33. package/dist/lib/field.d.ts +6 -6
  34. package/dist/lib/field.js +15 -21
  35. package/dist/lib/field.js.map +1 -1
  36. package/dist/lib/index.d.ts +13 -13
  37. package/dist/lib/index.js +17 -7
  38. package/dist/lib/index.js.map +1 -1
  39. package/dist/lib/logger.js +7 -7
  40. package/dist/lib/logger.js.map +1 -1
  41. package/dist/lib/mount.js +3 -3
  42. package/dist/lib/mount.js.map +1 -1
  43. package/dist/lib/nunjucks-filters.d.ts +5 -1
  44. package/dist/lib/nunjucks-filters.js +37 -23
  45. package/dist/lib/nunjucks-filters.js.map +1 -1
  46. package/dist/lib/nunjucks.d.ts +2 -2
  47. package/dist/lib/nunjucks.js +6 -7
  48. package/dist/lib/nunjucks.js.map +1 -1
  49. package/dist/lib/utils.js +52 -42
  50. package/dist/lib/utils.js.map +1 -1
  51. package/dist/lib/validators/dateObject.d.ts +3 -3
  52. package/dist/lib/validators/dateObject.js +44 -37
  53. package/dist/lib/validators/dateObject.js.map +1 -1
  54. package/dist/lib/validators/email.d.ts +2 -2
  55. package/dist/lib/validators/email.js +4 -5
  56. package/dist/lib/validators/email.js.map +1 -1
  57. package/dist/lib/validators/inArray.d.ts +2 -2
  58. package/dist/lib/validators/inArray.js +5 -6
  59. package/dist/lib/validators/inArray.js.map +1 -1
  60. package/dist/lib/validators/index.d.ts +10 -10
  61. package/dist/lib/validators/index.js.map +1 -1
  62. package/dist/lib/validators/nino.d.ts +2 -2
  63. package/dist/lib/validators/nino.js +10 -7
  64. package/dist/lib/validators/nino.js.map +1 -1
  65. package/dist/lib/validators/postalAddressObject.d.ts +2 -2
  66. package/dist/lib/validators/postalAddressObject.js +52 -39
  67. package/dist/lib/validators/postalAddressObject.js.map +1 -1
  68. package/dist/lib/validators/range.d.ts +2 -2
  69. package/dist/lib/validators/range.js +6 -7
  70. package/dist/lib/validators/range.js.map +1 -1
  71. package/dist/lib/validators/regex.d.ts +2 -2
  72. package/dist/lib/validators/regex.js +4 -5
  73. package/dist/lib/validators/regex.js.map +1 -1
  74. package/dist/lib/validators/required.d.ts +2 -2
  75. package/dist/lib/validators/required.js +6 -9
  76. package/dist/lib/validators/required.js.map +1 -1
  77. package/dist/lib/validators/strlen.d.ts +2 -2
  78. package/dist/lib/validators/strlen.js +8 -9
  79. package/dist/lib/validators/strlen.js.map +1 -1
  80. package/dist/lib/validators/wordCount.d.ts +2 -2
  81. package/dist/lib/validators/wordCount.js +10 -9
  82. package/dist/lib/validators/wordCount.js.map +1 -1
  83. package/dist/lib/waypoint-url.d.ts +4 -4
  84. package/dist/lib/waypoint-url.js +23 -23
  85. package/dist/lib/waypoint-url.js.map +1 -1
  86. package/dist/middleware/body-parser.d.ts +27 -5
  87. package/dist/middleware/body-parser.js +37 -6
  88. package/dist/middleware/body-parser.js.map +1 -1
  89. package/dist/middleware/csrf.d.ts +3 -0
  90. package/dist/middleware/csrf.js +3 -0
  91. package/dist/middleware/csrf.js.map +1 -1
  92. package/dist/middleware/data.d.ts +22 -5
  93. package/dist/middleware/data.js +37 -7
  94. package/dist/middleware/data.js.map +1 -1
  95. package/dist/middleware/gather-fields.d.ts +1 -1
  96. package/dist/middleware/gather-fields.js +4 -3
  97. package/dist/middleware/gather-fields.js.map +1 -1
  98. package/dist/middleware/i18n.d.ts +11 -2
  99. package/dist/middleware/i18n.js +26 -17
  100. package/dist/middleware/i18n.js.map +1 -1
  101. package/dist/middleware/post.d.ts +3 -1
  102. package/dist/middleware/post.js +35 -18
  103. package/dist/middleware/post.js.map +1 -1
  104. package/dist/middleware/pre.d.ts +1 -1
  105. package/dist/middleware/pre.js +43 -21
  106. package/dist/middleware/pre.js.map +1 -1
  107. package/dist/middleware/progress-journey.d.ts +1 -1
  108. package/dist/middleware/progress-journey.js +5 -5
  109. package/dist/middleware/progress-journey.js.map +1 -1
  110. package/dist/middleware/sanitise-fields.d.ts +2 -2
  111. package/dist/middleware/sanitise-fields.js +13 -11
  112. package/dist/middleware/sanitise-fields.js.map +1 -1
  113. package/dist/middleware/serve-first-waypoint.d.ts +1 -1
  114. package/dist/middleware/serve-first-waypoint.js +6 -4
  115. package/dist/middleware/serve-first-waypoint.js.map +1 -1
  116. package/dist/middleware/session.d.ts +27 -8
  117. package/dist/middleware/session.js +53 -25
  118. package/dist/middleware/session.js.map +1 -1
  119. package/dist/middleware/skip-waypoint.d.ts +1 -1
  120. package/dist/middleware/skip-waypoint.js +3 -3
  121. package/dist/middleware/skip-waypoint.js.map +1 -1
  122. package/dist/middleware/steer-journey.d.ts +1 -1
  123. package/dist/middleware/steer-journey.js +15 -13
  124. package/dist/middleware/steer-journey.js.map +1 -1
  125. package/dist/middleware/strip-proxy-path.d.ts +1 -1
  126. package/dist/middleware/strip-proxy-path.js +3 -3
  127. package/dist/middleware/strip-proxy-path.js.map +1 -1
  128. package/dist/middleware/validate-fields.d.ts +2 -2
  129. package/dist/middleware/validate-fields.js +2 -5
  130. package/dist/middleware/validate-fields.js.map +1 -1
  131. package/dist/routes/ancillary.d.ts +2 -2
  132. package/dist/routes/ancillary.js +3 -3
  133. package/dist/routes/ancillary.js.map +1 -1
  134. package/dist/routes/journey.d.ts +1 -1
  135. package/dist/routes/journey.js +85 -31
  136. package/dist/routes/journey.js.map +1 -1
  137. package/dist/routes/static.d.ts +13 -4
  138. package/dist/routes/static.js +21 -19
  139. package/dist/routes/static.js.map +1 -1
  140. package/package.json +33 -36
  141. package/src/casa.js +13 -13
  142. package/src/lib/CasaTemplateLoader.js +21 -17
  143. package/src/lib/JourneyContext.js +118 -79
  144. package/src/lib/MutableRouter.js +30 -26
  145. package/src/lib/Plan.js +109 -62
  146. package/src/lib/ValidationError.js +13 -10
  147. package/src/lib/ValidatorFactory.js +7 -8
  148. package/src/lib/configuration-ingestor.js +200 -74
  149. package/src/lib/configure.js +31 -30
  150. package/src/lib/constants.js +8 -8
  151. package/src/lib/context-id-generators.js +39 -38
  152. package/src/lib/end-session.js +3 -3
  153. package/src/lib/field.js +48 -32
  154. package/src/lib/index.js +12 -12
  155. package/src/lib/logger.js +9 -9
  156. package/src/lib/mount.js +68 -73
  157. package/src/lib/nunjucks-filters.js +57 -44
  158. package/src/lib/nunjucks.js +20 -16
  159. package/src/lib/utils.js +69 -44
  160. package/src/lib/validators/dateObject.js +57 -48
  161. package/src/lib/validators/email.js +8 -9
  162. package/src/lib/validators/inArray.js +8 -9
  163. package/src/lib/validators/index.js +11 -11
  164. package/src/lib/validators/nino.js +25 -12
  165. package/src/lib/validators/postalAddressObject.js +73 -55
  166. package/src/lib/validators/range.js +9 -11
  167. package/src/lib/validators/regex.js +7 -8
  168. package/src/lib/validators/required.js +13 -14
  169. package/src/lib/validators/strlen.js +11 -12
  170. package/src/lib/validators/wordCount.js +17 -12
  171. package/src/lib/waypoint-url.js +48 -33
  172. package/src/middleware/body-parser.js +44 -10
  173. package/src/middleware/csrf.js +4 -1
  174. package/src/middleware/data.js +62 -25
  175. package/src/middleware/gather-fields.js +8 -8
  176. package/src/middleware/i18n.js +49 -39
  177. package/src/middleware/post.js +47 -21
  178. package/src/middleware/pre.js +59 -35
  179. package/src/middleware/progress-journey.js +32 -18
  180. package/src/middleware/sanitise-fields.js +43 -20
  181. package/src/middleware/serve-first-waypoint.js +12 -10
  182. package/src/middleware/session.js +97 -65
  183. package/src/middleware/skip-waypoint.js +7 -9
  184. package/src/middleware/steer-journey.js +39 -27
  185. package/src/middleware/strip-proxy-path.js +8 -7
  186. package/src/middleware/validate-fields.js +5 -12
  187. package/src/routes/ancillary.js +4 -6
  188. package/src/routes/journey.js +158 -78
  189. package/src/routes/static.js +64 -26
@@ -1,8 +1,7 @@
1
- /* eslint-disable class-methods-use-this */
2
- import validatorPkg from 'validator';
3
- import ValidationError from '../ValidationError.js';
4
- import ValidatorFactory from '../ValidatorFactory.js';
5
- import { stringifyInput } from '../utils.js';
1
+ import validatorPkg from "validator";
2
+ import ValidationError from "../ValidationError.js";
3
+ import ValidatorFactory from "../ValidatorFactory.js";
4
+ import { stringifyInput } from "../utils.js";
6
5
 
7
6
  const { isEmail } = validatorPkg; // CommonJS
8
7
 
@@ -28,19 +27,19 @@ const { isEmail } = validatorPkg; // CommonJS
28
27
  */
29
28
  export default class Email extends ValidatorFactory {
30
29
  /** @property {string} name Validator name ("email") */
31
- name = 'email';
30
+ name = "email";
32
31
 
33
32
  validate(value, dataContext = {}) {
34
33
  let isValid;
35
34
  try {
36
35
  isValid = isEmail(value);
37
- } catch (e) {
36
+ } catch {
38
37
  isValid = false;
39
38
  }
40
39
 
41
40
  const errorMsg = this.config.errorMsg || {
42
- summary: 'validation:rule.email.summary',
43
- inline: 'validation:rule.email.inline',
41
+ summary: "validation:rule.email.summary",
42
+ inline: "validation:rule.email.inline",
44
43
  };
45
44
 
46
45
  return isValid ? [] : [ValidationError.make({ errorMsg, dataContext })];
@@ -1,4 +1,3 @@
1
- /* eslint-disable class-methods-use-this */
2
1
  /**
3
2
  * Test if a value is present in an array.
4
3
  *
@@ -8,9 +7,9 @@
8
7
  * If the value itself is an array, all values within that array must be present
9
8
  * in the `source` array in order to pass validation.
10
9
  */
11
- import ValidationError from '../ValidationError.js';
12
- import ValidatorFactory from '../ValidatorFactory.js';
13
- import { stringifyInput, isStringable } from '../utils.js';
10
+ import ValidationError from "../ValidationError.js";
11
+ import ValidatorFactory from "../ValidatorFactory.js";
12
+ import { stringifyInput, isStringable } from "../utils.js";
14
13
 
15
14
  /**
16
15
  * @access private
@@ -36,17 +35,17 @@ import { stringifyInput, isStringable } from '../utils.js';
36
35
  */
37
36
  export default class InArray extends ValidatorFactory {
38
37
  /** @property {string} name Validator name ("inArray") */
39
- name = 'inArray';
38
+ name = "inArray";
40
39
 
41
40
  validate(value, dataContext = {}) {
42
41
  let valid = false;
43
42
  const source = this.config.source || [];
44
43
  const errorMsg = this.config.errorMsg || {
45
- inline: 'validation:rule.inArray.inline',
46
- summary: 'validation:rule.inArray.summary',
44
+ inline: "validation:rule.inArray.inline",
45
+ summary: "validation:rule.inArray.summary",
47
46
  };
48
47
 
49
- if (value !== null && typeof value !== 'undefined') {
48
+ if (value !== null && typeof value !== "undefined") {
50
49
  const search = Array.isArray(value) ? value : [value];
51
50
  for (let i = 0, l = search.length; i < l; i += 1) {
52
51
  if (source.indexOf(search[parseInt(i, 10)]) > -1) {
@@ -62,7 +61,7 @@ export default class InArray extends ValidatorFactory {
62
61
  }
63
62
 
64
63
  sanitise(value) {
65
- const coerce = (val) => (stringifyInput(val, undefined));
64
+ const coerce = (val) => stringifyInput(val, undefined);
66
65
 
67
66
  // Basic stringable
68
67
  if (isStringable(value)) {
@@ -1,13 +1,13 @@
1
- import dateObject from './dateObject.js';
2
- import email from './email.js';
3
- import inArray from './inArray.js';
4
- import nino from './nino.js';
5
- import postalAddressObject from './postalAddressObject.js';
6
- import regex from './regex.js';
7
- import required from './required.js';
8
- import strlen from './strlen.js';
9
- import range from './range.js';
10
- import wordCount from './wordCount.js';
1
+ import dateObject from "./dateObject.js";
2
+ import email from "./email.js";
3
+ import inArray from "./inArray.js";
4
+ import nino from "./nino.js";
5
+ import postalAddressObject from "./postalAddressObject.js";
6
+ import regex from "./regex.js";
7
+ import required from "./required.js";
8
+ import strlen from "./strlen.js";
9
+ import range from "./range.js";
10
+ import wordCount from "./wordCount.js";
11
11
 
12
12
  /**
13
13
  * @namespace Validators
@@ -23,4 +23,4 @@ export default {
23
23
  strlen,
24
24
  range,
25
25
  wordCount,
26
- }
26
+ };
@@ -1,7 +1,6 @@
1
- /* eslint-disable class-methods-use-this */
2
- import ValidationError from '../ValidationError.js';
3
- import ValidatorFactory from '../ValidatorFactory.js';
4
- import { stringifyInput } from '../utils.js';
1
+ import ValidationError from "../ValidationError.js";
2
+ import ValidatorFactory from "../ValidatorFactory.js";
3
+ import { stringifyInput } from "../utils.js";
5
4
 
6
5
  /**
7
6
  * @access private
@@ -27,23 +26,37 @@ import { stringifyInput } from '../utils.js';
27
26
  * @augments ValidatorFactory
28
27
  */
29
28
  export default class Nino extends ValidatorFactory {
30
- name = 'nino';
29
+ name = "nino";
31
30
 
32
31
  validate(value, dataContext = {}) {
33
32
  const {
34
33
  allowWhitespace,
35
34
  errorMsg = {
36
- inline: 'validation:rule.nino.inline',
37
- summary: 'validation:rule.nino.summary',
35
+ inline: "validation:rule.nino.inline",
36
+ summary: "validation:rule.nino.summary",
38
37
  },
39
38
  } = this.config;
40
39
 
41
- if (typeof allowWhitespace !== 'undefined' && typeof allowWhitespace !== 'boolean') {
42
- throw new TypeError(`NINO validation rule option "allowWhitespace" must been a boolean. received ${typeof allowWhitespace}`);
40
+ if (
41
+ typeof allowWhitespace !== "undefined" &&
42
+ typeof allowWhitespace !== "boolean"
43
+ ) {
44
+ throw new TypeError(
45
+ `NINO validation rule option "allowWhitespace" must been a boolean. received ${typeof allowWhitespace}`,
46
+ );
43
47
  }
44
- const valid = typeof value === 'string'
45
- && value.replace((typeof allowWhitespace !== 'undefined' && allowWhitespace) ? /\u0020/g : '', '')
46
- .match(/^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$/i);
48
+ const valid =
49
+ typeof value === "string" &&
50
+ value
51
+ .replace(
52
+ typeof allowWhitespace !== "undefined" && allowWhitespace
53
+ ? /\u0020/g
54
+ : "",
55
+ "",
56
+ )
57
+ .match(
58
+ /^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$/i,
59
+ );
47
60
 
48
61
  return valid ? [] : [ValidationError.make({ errorMsg, dataContext })];
49
62
  }
@@ -1,8 +1,7 @@
1
- /* eslint-disable class-methods-use-this */
2
- import lodash from 'lodash';
3
- import ValidationError from '../ValidationError.js';
4
- import ValidatorFactory from '../ValidatorFactory.js';
5
- import { stringifyInput } from '../utils.js';
1
+ import lodash from "lodash";
2
+ import ValidationError from "../ValidationError.js";
3
+ import ValidatorFactory from "../ValidatorFactory.js";
4
+ import { stringifyInput } from "../utils.js";
6
5
 
7
6
  const { isPlainObject } = lodash; // CommonjS
8
7
 
@@ -38,73 +37,85 @@ const { isPlainObject } = lodash; // CommonjS
38
37
  * @augments ValidatorFactory
39
38
  */
40
39
  export default class PostalAddressObject extends ValidatorFactory {
41
- name = 'postalAddressObject';
40
+ name = "postalAddressObject";
42
41
 
43
42
  validate(value, dataContext = {}) {
44
43
  const cfg = {
45
- requiredFields: ['address1', 'address3', 'postcode'],
44
+ requiredFields: ["address1", "address3", "postcode"],
46
45
  strlenmax: undefined,
47
46
  errorMsgAddress1: {
48
- inline: 'validation:rule.postalAddressObject.address1.inline',
49
- summary: 'validation:rule.postalAddressObject.address1.summary',
50
- focusSuffix: '[address1]',
47
+ inline: "validation:rule.postalAddressObject.address1.inline",
48
+ summary: "validation:rule.postalAddressObject.address1.summary",
49
+ focusSuffix: "[address1]",
51
50
  },
52
51
  errorMsgAddress2: {
53
- inline: 'validation:rule.postalAddressObject.address2.inline',
54
- summary: 'validation:rule.postalAddressObject.address2.summary',
55
- focusSuffix: '[address2]',
52
+ inline: "validation:rule.postalAddressObject.address2.inline",
53
+ summary: "validation:rule.postalAddressObject.address2.summary",
54
+ focusSuffix: "[address2]",
56
55
  },
57
56
  errorMsgAddress3: {
58
- inline: 'validation:rule.postalAddressObject.address3.inline',
59
- summary: 'validation:rule.postalAddressObject.address3.summary',
60
- focusSuffix: '[address3]',
57
+ inline: "validation:rule.postalAddressObject.address3.inline",
58
+ summary: "validation:rule.postalAddressObject.address3.summary",
59
+ focusSuffix: "[address3]",
61
60
  },
62
61
  errorMsgAddress4: {
63
- inline: 'validation:rule.postalAddressObject.address4.inline',
64
- summary: 'validation:rule.postalAddressObject.address4.summary',
65
- focusSuffix: '[address4]',
62
+ inline: "validation:rule.postalAddressObject.address4.inline",
63
+ summary: "validation:rule.postalAddressObject.address4.summary",
64
+ focusSuffix: "[address4]",
66
65
  },
67
66
  errorMsgPostcode: {
68
- inline: 'validation:rule.postalAddressObject.postcode.inline',
69
- summary: 'validation:rule.postalAddressObject.postcode.summary',
70
- focusSuffix: '[postcode]',
67
+ inline: "validation:rule.postalAddressObject.postcode.inline",
68
+ summary: "validation:rule.postalAddressObject.postcode.summary",
69
+ focusSuffix: "[postcode]",
71
70
  },
72
71
  errorMsg: {
73
- inline: 'validation:rule.postalAddressObject.group.inline',
74
- summary: 'validation:rule.postalAddressObject.group.summary',
75
- focusSuffix: '[address1]',
72
+ inline: "validation:rule.postalAddressObject.group.inline",
73
+ summary: "validation:rule.postalAddressObject.group.summary",
74
+ focusSuffix: "[address1]",
76
75
  },
77
76
  ...this.config,
78
77
  };
79
78
 
80
- /* eslint-disable-next-line require-jsdoc */
81
- const objectifyError = (err) => (typeof err === 'string' ? {
82
- inline: err,
83
- summary: err,
84
- } : err);
79
+ const objectifyError = (err) =>
80
+ typeof err === "string"
81
+ ? {
82
+ inline: err,
83
+ summary: err,
84
+ }
85
+ : err;
85
86
 
86
87
  // Work out required/optional parts based on config
87
88
  const reqF = Object.create(null);
88
89
  const reqC = cfg.requiredFields;
89
- ['address1', 'address2', 'address3', 'address4', 'postcode'].forEach((k) => {
90
- // ESLint disabled as `k` is a known value from a constant list
91
- /* eslint-disable-next-line security/detect-object-injection */
92
- reqF[k] = reqC.indexOf(k) > -1;
93
- });
90
+ ["address1", "address2", "address3", "address4", "postcode"].forEach(
91
+ (k) => {
92
+ // ESLint disabled as `k` is a known value from a constant list
93
+ /* eslint-disable-next-line security/detect-object-injection */
94
+ reqF[k] = reqC.indexOf(k) > -1;
95
+ },
96
+ );
94
97
 
95
98
  let valid = true;
96
99
  const errorMsgs = [];
97
100
 
98
- if (typeof value === 'object') {
99
- const reAddr = /^[^\s]+[a-z0-9\-,.&#()/\\:;'" ]+$/i;
100
- const reAddrLine1 = /^\d+|[^\s]+[a-z0-9\-,.&#()/\\:;'" ]+$/i;
101
+ if (typeof value === "object") {
102
+ const reAddr = /^[a-z0-9\-,.&#()/\\:;'" ]{2,}$/i;
103
+ const reAddrLine1 = /^(\d+|[a-z0-9\-,.&#()/\\:;'" ]{2,})$/i;
101
104
  // UK Postcode regex taken from the dwp java pc checker
102
105
  // https://github.com/dwp/postcode-format-validation
103
- const rePostcode = /^(?![QVX])[A-Z]((?![IJZ])[A-Z][0-9](([0-9]?)|([ABEHMNPRVWXY]?))|([0-9]([0-9]?|[ABCDEFGHJKPSTUW]?))) ?[0-9]((?![CIKMOV])[A-Z]){2}$|^(BFPO)[ ]?[0-9]{1,4}$/i;
106
+ /* eslint-disable sonarjs/regex-complexity */
107
+ const rePostcode =
108
+ /^(?![QVX])[A-Z]((?![IJZ])[A-Z]\d((\d?)|([ABEHMNPRVWXY]?))|(\d(\d?|[ABCDEFGHJKPSTUW]?))) ?\d((?![CIKMOV])[A-Z]){2}$|^(BFPO) ?\d{1,4}$/i;
109
+ /* eslint-enable sonarjs/regex-complexity */
104
110
 
105
111
  // [required, regex, strlenmax, error message]
106
112
  const attributes = {
107
- address1: [reqF.address1, reAddrLine1, cfg.strlenmax, cfg.errorMsgAddress1],
113
+ address1: [
114
+ reqF.address1,
115
+ reAddrLine1,
116
+ cfg.strlenmax,
117
+ cfg.errorMsgAddress1,
118
+ ],
108
119
  address2: [reqF.address2, reAddr, cfg.strlenmax, cfg.errorMsgAddress2],
109
120
  address3: [reqF.address3, reAddr, cfg.strlenmax, cfg.errorMsgAddress3],
110
121
  address4: [reqF.address4, reAddr, cfg.strlenmax, cfg.errorMsgAddress4],
@@ -117,16 +128,18 @@ export default class PostalAddressObject extends ValidatorFactory {
117
128
  const hasProperty = Object.prototype.hasOwnProperty.call(value, k);
118
129
  const hasContent = hasProperty && value[k].length > 0;
119
130
 
120
- const condMissingOrRegexMismatch = (attr[0] || hasContent)
121
- && (!hasProperty || !value[k].match(attr[1]));
122
- const condExceedStrlen = attr[2] > 0 && hasContent
123
- && String(value[k]).length > attr[2];
131
+ const condMissingOrRegexMismatch =
132
+ (attr[0] || hasContent) && (!hasProperty || !value[k].match(attr[1]));
133
+ const condExceedStrlen =
134
+ attr[2] > 0 && hasContent && String(value[k]).length > attr[2];
124
135
 
125
136
  if (condMissingOrRegexMismatch || condExceedStrlen) {
126
137
  valid = false;
127
- errorMsgs.push(Object.assign(Object.create(null), objectifyError(attr[3]), {
128
- fieldKeySuffix: `[${k}]`,
129
- }));
138
+ errorMsgs.push(
139
+ Object.assign(Object.create(null), objectifyError(attr[3]), {
140
+ fieldKeySuffix: `[${k}]`,
141
+ }),
142
+ );
130
143
  }
131
144
  });
132
145
  /* eslint-enable security/detect-object-injection */
@@ -136,8 +149,9 @@ export default class PostalAddressObject extends ValidatorFactory {
136
149
  }
137
150
 
138
151
  // Build ValidationErrorGroup
139
- const errorGroup = errorMsgs.map((err) => (
140
- ValidationError.make({ errorMsg: err, dataContext })));
152
+ const errorGroup = errorMsgs.map((err) =>
153
+ ValidationError.make({ errorMsg: err, dataContext }),
154
+ );
141
155
 
142
156
  return valid ? [] : [...errorGroup];
143
157
  }
@@ -149,13 +163,17 @@ export default class PostalAddressObject extends ValidatorFactory {
149
163
  }
150
164
 
151
165
  // Prune unrecognised attributes, and coerce to Strings
152
- const validKeys = ['address1', 'address2', 'address3', 'address4', 'postcode'];
166
+ const validKeys = [
167
+ "address1",
168
+ "address2",
169
+ "address3",
170
+ "address4",
171
+ "postcode",
172
+ ];
153
173
  const pruned = Object.fromEntries(
154
- Object.entries(value).filter(
155
- ([k]) => (validKeys.includes(k)),
156
- ).map(
157
- ([k, v]) => ([k, stringifyInput(v)]),
158
- ),
174
+ Object.entries(value)
175
+ .filter(([k]) => validKeys.includes(k))
176
+ .map(([k, v]) => [k, stringifyInput(v)]),
159
177
  );
160
178
  return Object.assign(Object.create(null), pruned);
161
179
  }
@@ -1,8 +1,6 @@
1
- /* eslint-disable class-methods-use-this */
2
-
3
- import ValidatorFactory from '../ValidatorFactory.js';
4
- import ValidationError from '../ValidationError.js';
5
- import { coerceInputToInteger } from '../utils.js';
1
+ import ValidatorFactory from "../ValidatorFactory.js";
2
+ import ValidationError from "../ValidationError.js";
3
+ import { coerceInputToInteger } from "../utils.js";
6
4
 
7
5
  /**
8
6
  * @access private
@@ -26,17 +24,17 @@ import { coerceInputToInteger } from '../utils.js';
26
24
  * @augments ValidatorFactory
27
25
  */
28
26
  export default class Range extends ValidatorFactory {
29
- name = 'range';
27
+ name = "range";
30
28
 
31
29
  validate(inputValue, dataContext = {}) {
32
30
  const {
33
31
  errorMsgMax = {
34
- inline: 'validation:rule.range.max.inline',
35
- summary: 'validation:rule.range.max.summary',
32
+ inline: "validation:rule.range.max.inline",
33
+ summary: "validation:rule.range.max.summary",
36
34
  },
37
35
  errorMsgMin = {
38
- inline: 'validation:rule.range.min.inline',
39
- summary: 'validation:rule.range.min.summary',
36
+ inline: "validation:rule.range.min.inline",
37
+ summary: "validation:rule.range.min.summary",
40
38
  },
41
39
  min = Number.MIN_VALUE,
42
40
  max = Number.MAX_VALUE,
@@ -61,7 +59,7 @@ export default class Range extends ValidatorFactory {
61
59
  sanitise(value) {
62
60
  // treat an empty string as undefined
63
61
  // when user submits empty form, it stores an empty string
64
- if (value !== '' && value !== undefined) {
62
+ if (value !== "" && value !== undefined) {
65
63
  // add to custom validator docs to ensure not to return a falsy value as
66
64
  // it doesn't show on screen
67
65
  return coerceInputToInteger(value)?.toString();
@@ -1,7 +1,6 @@
1
- /* eslint-disable class-methods-use-this */
2
- import ValidatorFactory from '../ValidatorFactory.js';
3
- import ValidationError from '../ValidationError.js';
4
- import { stringifyInput } from '../utils.js';
1
+ import ValidatorFactory from "../ValidatorFactory.js";
2
+ import ValidationError from "../ValidationError.js";
3
+ import { stringifyInput } from "../utils.js";
5
4
 
6
5
  /**
7
6
  * @access private
@@ -24,16 +23,16 @@ import { stringifyInput } from '../utils.js';
24
23
  * @augments ValidatorFactory
25
24
  */
26
25
  export default class Regex extends ValidatorFactory {
27
- name = 'regex';
26
+ name = "regex";
28
27
 
29
- validate(value = '', dataContext = {}) {
28
+ validate(value = "", dataContext = {}) {
30
29
  const invert = this.config.invert || false;
31
30
  const match = value.match(this.config.pattern || /.*/);
32
31
  const valid = invert ? !match : match;
33
32
 
34
33
  const errorMsg = this.config.errorMsg || {
35
- inline: 'validation:rule.regex.inline',
36
- summary: 'validation:rule.regex.summary',
34
+ inline: "validation:rule.regex.inline",
35
+ summary: "validation:rule.regex.summary",
37
36
  };
38
37
 
39
38
  return valid ? [] : [ValidationError.make({ errorMsg, dataContext })];
@@ -1,8 +1,7 @@
1
- /* eslint-disable class-methods-use-this */
2
- import lodash from 'lodash';
3
- import { isEmpty, isStringable, stringifyInput } from '../utils.js';
4
- import ValidatorFactory from '../ValidatorFactory.js';
5
- import ValidationError from '../ValidationError.js';
1
+ import lodash from "lodash";
2
+ import { isEmpty, isStringable, stringifyInput } from "../utils.js";
3
+ import ValidatorFactory from "../ValidatorFactory.js";
4
+ import ValidationError from "../ValidationError.js";
6
5
 
7
6
  const { isPlainObject } = lodash; // CommonJS
8
7
 
@@ -28,29 +27,27 @@ const { isPlainObject } = lodash; // CommonJS
28
27
  * @augments ValidatorFactory
29
28
  */
30
29
  export default class Required extends ValidatorFactory {
31
- name = 'required';
30
+ name = "required";
32
31
 
33
32
  validate(value, dataContext = {}) {
34
33
  const {
35
34
  errorMsg = {
36
- inline: 'validation:rule.required.inline',
37
- summary: 'validation:rule.required.summary',
35
+ inline: "validation:rule.required.inline",
36
+ summary: "validation:rule.required.summary",
38
37
  },
39
38
  } = this.config;
40
39
 
41
40
  if (!isEmpty(value)) {
42
- return []
41
+ return [];
43
42
  }
44
43
 
45
- return [
46
- ValidationError.make({ errorMsg, dataContext }),
47
- ];
44
+ return [ValidationError.make({ errorMsg, dataContext })];
48
45
  }
49
46
 
50
47
  sanitise(value) {
51
48
  const coerce = (val) => {
52
49
  const s = stringifyInput(val, undefined);
53
- return s === undefined ? undefined : s.replace(/^\s+$/, '');
50
+ return s === undefined ? undefined : s.replace(/^\s+$/, "");
54
51
  };
55
52
 
56
53
  if (isStringable(value)) {
@@ -66,7 +63,9 @@ export default class Required extends ValidatorFactory {
66
63
  // Coerce all elements to Strings.
67
64
  // This only supports a one dimensional object, with stringable elements.
68
65
  if (isPlainObject(value)) {
69
- return Object.fromEntries(Object.entries(value).map(([k, v]) => ([k, coerce(v)])));
66
+ return Object.fromEntries(
67
+ Object.entries(value).map(([k, v]) => [k, coerce(v)]),
68
+ );
70
69
  }
71
70
 
72
71
  return undefined;
@@ -1,7 +1,6 @@
1
- /* eslint-disable class-methods-use-this */
2
- import ValidatorFactory from '../ValidatorFactory.js';
3
- import ValidationError from '../ValidationError.js';
4
- import { stringifyInput } from '../utils.js';
1
+ import ValidatorFactory from "../ValidatorFactory.js";
2
+ import ValidationError from "../ValidationError.js";
3
+ import { stringifyInput } from "../utils.js";
5
4
 
6
5
  /**
7
6
  * @access private
@@ -25,17 +24,17 @@ import { stringifyInput } from '../utils.js';
25
24
  * @augments ValidatorFactory
26
25
  */
27
26
  export default class Strlen extends ValidatorFactory {
28
- name = 'strlen';
27
+ name = "strlen";
29
28
 
30
- validate(inputValue = '', dataContext = {}) {
29
+ validate(inputValue = "", dataContext = {}) {
31
30
  const {
32
31
  errorMsgMax = {
33
- inline: 'validation:rule.strlen.max.inline',
34
- summary: 'validation:rule.strlen.max.summary',
32
+ inline: "validation:rule.strlen.max.inline",
33
+ summary: "validation:rule.strlen.max.summary",
35
34
  },
36
35
  errorMsgMin = {
37
- inline: 'validation:rule.strlen.min.inline',
38
- summary: 'validation:rule.strlen.min.summary',
36
+ inline: "validation:rule.strlen.min.inline",
37
+ summary: "validation:rule.strlen.min.summary",
39
38
  },
40
39
  min,
41
40
  max,
@@ -44,12 +43,12 @@ export default class Strlen extends ValidatorFactory {
44
43
  let errorMsg;
45
44
  let valid = true;
46
45
 
47
- if (typeof max !== 'undefined' && inputValue.length > max) {
46
+ if (typeof max !== "undefined" && inputValue.length > max) {
48
47
  valid = false;
49
48
  errorMsg = errorMsgMax;
50
49
  }
51
50
 
52
- if (typeof min !== 'undefined' && inputValue.length < min) {
51
+ if (typeof min !== "undefined" && inputValue.length < min) {
53
52
  valid = false;
54
53
  errorMsg = errorMsgMin;
55
54
  }
@@ -1,7 +1,6 @@
1
- /* eslint-disable class-methods-use-this */
2
- import ValidatorFactory from '../ValidatorFactory.js';
3
- import ValidationError from '../ValidationError.js';
4
- import { stringifyInput } from '../utils.js';
1
+ import ValidatorFactory from "../ValidatorFactory.js";
2
+ import ValidationError from "../ValidationError.js";
3
+ import { stringifyInput } from "../utils.js";
5
4
 
6
5
  /**
7
6
  * @access private
@@ -25,21 +24,21 @@ import { stringifyInput } from '../utils.js';
25
24
  * @augments ValidatorFactory
26
25
  */
27
26
  export default class WordCount extends ValidatorFactory {
28
- name = 'wordCount';
27
+ name = "wordCount";
29
28
 
30
29
  count(input) {
31
30
  return (input.match(/\S+/g) || []).length;
32
31
  }
33
32
 
34
- validate(inputValue = '', dataContext = {}) {
33
+ validate(inputValue = "", dataContext = {}) {
35
34
  const {
36
35
  errorMsgMax = {
37
- inline: 'validation:rule.wordCount.max.inline',
38
- summary: 'validation:rule.wordCount.max.summary',
36
+ inline: "validation:rule.wordCount.max.inline",
37
+ summary: "validation:rule.wordCount.max.summary",
39
38
  },
40
39
  errorMsgMin = {
41
- inline: 'validation:rule.wordCount.min.inline',
42
- summary: 'validation:rule.wordCount.min.summary',
40
+ inline: "validation:rule.wordCount.min.inline",
41
+ summary: "validation:rule.wordCount.min.summary",
43
42
  },
44
43
  min,
45
44
  max,
@@ -48,12 +47,18 @@ export default class WordCount extends ValidatorFactory {
48
47
  let errorMsg;
49
48
  let valid = true;
50
49
 
51
- if (typeof max !== 'undefined' && (inputValue.match(/\S+/g) || []).length > max) {
50
+ if (
51
+ typeof max !== "undefined" &&
52
+ (inputValue.match(/\S+/g) || []).length > max
53
+ ) {
52
54
  valid = false;
53
55
  errorMsg = errorMsgMax;
54
56
  }
55
57
 
56
- if (typeof min !== 'undefined' && (inputValue.match(/\S+/g) || []).length < min) {
58
+ if (
59
+ typeof min !== "undefined" &&
60
+ (inputValue.match(/\S+/g) || []).length < min
61
+ ) {
57
62
  valid = false;
58
63
  errorMsg = errorMsgMin;
59
64
  }