@dwp/govuk-casa 9.0.0 → 9.1.0
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/README.md +9 -9
- package/dist/assets/css/casa.css +1 -1
- package/dist/assets/css/casa.css.map +1 -1
- package/dist/casa.d.ts +122 -95
- package/dist/casa.js +119 -86
- package/dist/casa.js.map +1 -1
- package/dist/lib/CasaTemplateLoader.d.ts +4 -4
- package/dist/lib/CasaTemplateLoader.js +16 -16
- package/dist/lib/CasaTemplateLoader.js.map +1 -1
- package/dist/lib/JourneyContext.d.ts +38 -40
- package/dist/lib/JourneyContext.js +81 -75
- package/dist/lib/JourneyContext.js.map +1 -1
- package/dist/lib/MutableRouter.d.ts +40 -41
- package/dist/lib/MutableRouter.js +64 -71
- package/dist/lib/MutableRouter.js.map +1 -1
- package/dist/lib/Plan.d.ts +29 -26
- package/dist/lib/Plan.js +85 -71
- package/dist/lib/Plan.js.map +1 -1
- package/dist/lib/ValidationError.d.ts +16 -15
- package/dist/lib/ValidationError.js +21 -20
- package/dist/lib/ValidationError.js.map +1 -1
- package/dist/lib/ValidatorFactory.d.ts +15 -13
- package/dist/lib/ValidatorFactory.js +14 -12
- package/dist/lib/ValidatorFactory.js.map +1 -1
- package/dist/lib/configuration-ingestor.d.ts +37 -40
- package/dist/lib/configuration-ingestor.js +93 -93
- package/dist/lib/configuration-ingestor.js.map +1 -1
- package/dist/lib/configure.d.ts +6 -6
- package/dist/lib/configure.js +14 -12
- package/dist/lib/configure.js.map +1 -1
- package/dist/lib/constants.d.ts +1 -3
- package/dist/lib/constants.js +9 -11
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/context-id-generators.d.ts +3 -5
- package/dist/lib/context-id-generators.js +7 -6
- package/dist/lib/context-id-generators.js.map +1 -1
- package/dist/lib/end-session.d.ts +4 -4
- package/dist/lib/end-session.js +5 -5
- package/dist/lib/field.d.ts +20 -18
- package/dist/lib/field.js +35 -48
- package/dist/lib/field.js.map +1 -1
- package/dist/lib/index.d.ts +13 -13
- package/dist/lib/logger.d.ts +7 -6
- package/dist/lib/logger.js +7 -7
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/mount.d.ts +5 -5
- package/dist/lib/mount.js +11 -10
- package/dist/lib/mount.js.map +1 -1
- package/dist/lib/nunjucks-filters.d.ts +10 -12
- package/dist/lib/nunjucks-filters.js +35 -35
- package/dist/lib/nunjucks-filters.js.map +1 -1
- package/dist/lib/nunjucks.d.ts +7 -5
- package/dist/lib/nunjucks.js +10 -8
- package/dist/lib/nunjucks.js.map +1 -1
- package/dist/lib/utils.d.ts +19 -19
- package/dist/lib/utils.js +62 -55
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/validators/dateObject.d.ts +29 -22
- package/dist/lib/validators/dateObject.js +58 -49
- package/dist/lib/validators/dateObject.js.map +1 -1
- package/dist/lib/validators/email.d.ts +4 -4
- package/dist/lib/validators/email.js +4 -4
- package/dist/lib/validators/inArray.d.ts +4 -4
- package/dist/lib/validators/inArray.js +7 -8
- package/dist/lib/validators/inArray.js.map +1 -1
- package/dist/lib/validators/index.d.ts +10 -10
- package/dist/lib/validators/index.js +1 -3
- package/dist/lib/validators/index.js.map +1 -1
- package/dist/lib/validators/nino.d.ts +9 -8
- package/dist/lib/validators/nino.js +14 -10
- package/dist/lib/validators/nino.js.map +1 -1
- package/dist/lib/validators/postalAddressObject.d.ts +37 -24
- package/dist/lib/validators/postalAddressObject.js +65 -46
- package/dist/lib/validators/postalAddressObject.js.map +1 -1
- package/dist/lib/validators/range.d.ts +12 -8
- package/dist/lib/validators/range.js +11 -9
- package/dist/lib/validators/range.js.map +1 -1
- package/dist/lib/validators/regex.d.ts +4 -4
- package/dist/lib/validators/regex.js +5 -5
- package/dist/lib/validators/required.d.ts +6 -6
- package/dist/lib/validators/required.js +9 -11
- package/dist/lib/validators/required.js.map +1 -1
- package/dist/lib/validators/strlen.d.ts +12 -8
- package/dist/lib/validators/strlen.js +13 -11
- package/dist/lib/validators/strlen.js.map +1 -1
- package/dist/lib/validators/wordCount.d.ts +12 -8
- package/dist/lib/validators/wordCount.js +15 -11
- package/dist/lib/validators/wordCount.js.map +1 -1
- package/dist/lib/waypoint-url.d.ts +16 -13
- package/dist/lib/waypoint-url.js +39 -36
- package/dist/lib/waypoint-url.js.map +1 -1
- package/dist/middleware/body-parser.d.ts +1 -1
- package/dist/middleware/body-parser.js +6 -6
- package/dist/middleware/body-parser.js.map +1 -1
- package/dist/middleware/data.d.ts +1 -1
- package/dist/middleware/data.js +8 -7
- package/dist/middleware/data.js.map +1 -1
- package/dist/middleware/gather-fields.d.ts +2 -2
- package/dist/middleware/gather-fields.js +6 -4
- package/dist/middleware/gather-fields.js.map +1 -1
- package/dist/middleware/i18n.js +13 -15
- package/dist/middleware/i18n.js.map +1 -1
- package/dist/middleware/post.js +30 -18
- package/dist/middleware/post.js.map +1 -1
- package/dist/middleware/pre.d.ts +2 -2
- package/dist/middleware/pre.js +46 -27
- package/dist/middleware/pre.js.map +1 -1
- package/dist/middleware/progress-journey.d.ts +1 -1
- package/dist/middleware/progress-journey.js +5 -5
- package/dist/middleware/progress-journey.js.map +1 -1
- package/dist/middleware/sanitise-fields.d.ts +1 -1
- package/dist/middleware/sanitise-fields.js +13 -11
- package/dist/middleware/sanitise-fields.js.map +1 -1
- package/dist/middleware/serve-first-waypoint.d.ts +3 -3
- package/dist/middleware/serve-first-waypoint.js +8 -6
- package/dist/middleware/serve-first-waypoint.js.map +1 -1
- package/dist/middleware/session.js +14 -11
- package/dist/middleware/session.js.map +1 -1
- package/dist/middleware/skip-waypoint.d.ts +1 -1
- package/dist/middleware/skip-waypoint.js +3 -3
- package/dist/middleware/skip-waypoint.js.map +1 -1
- package/dist/middleware/steer-journey.d.ts +1 -1
- package/dist/middleware/steer-journey.js +16 -14
- package/dist/middleware/steer-journey.js.map +1 -1
- package/dist/middleware/strip-proxy-path.d.ts +1 -1
- package/dist/middleware/strip-proxy-path.js +3 -3
- package/dist/middleware/strip-proxy-path.js.map +1 -1
- package/dist/middleware/validate-fields.d.ts +1 -1
- package/dist/middleware/validate-fields.js +2 -5
- package/dist/middleware/validate-fields.js.map +1 -1
- package/dist/routes/ancillary.d.ts +3 -3
- package/dist/routes/ancillary.js +4 -4
- package/dist/routes/ancillary.js.map +1 -1
- package/dist/routes/journey.d.ts +2 -2
- package/dist/routes/journey.js +91 -39
- package/dist/routes/journey.js.map +1 -1
- package/dist/routes/static.d.ts +7 -5
- package/dist/routes/static.js +20 -19
- package/dist/routes/static.js.map +1 -1
- package/package.json +19 -18
- package/src/casa.js +133 -100
- package/src/lib/CasaTemplateLoader.js +24 -19
- package/src/lib/JourneyContext.js +138 -107
- package/src/lib/MutableRouter.js +72 -74
- package/src/lib/Plan.js +145 -97
- package/src/lib/ValidationError.js +25 -21
- package/src/lib/ValidatorFactory.js +17 -13
- package/src/lib/configuration-ingestor.js +147 -110
- package/src/lib/configure.js +34 -32
- package/src/lib/constants.js +9 -11
- package/src/lib/context-id-generators.js +40 -43
- package/src/lib/end-session.js +6 -6
- package/src/lib/field.js +69 -58
- package/src/lib/index.js +12 -12
- package/src/lib/logger.js +9 -9
- package/src/lib/mount.js +70 -74
- package/src/lib/nunjucks-filters.js +56 -59
- package/src/lib/nunjucks.js +23 -18
- package/src/lib/utils.js +78 -57
- package/src/lib/validators/dateObject.js +71 -60
- package/src/lib/validators/email.js +8 -8
- package/src/lib/validators/inArray.js +10 -11
- package/src/lib/validators/index.js +12 -14
- package/src/lib/validators/nino.js +29 -15
- package/src/lib/validators/postalAddressObject.js +87 -63
- package/src/lib/validators/range.js +14 -12
- package/src/lib/validators/regex.js +8 -8
- package/src/lib/validators/required.js +16 -16
- package/src/lib/validators/strlen.js +16 -14
- package/src/lib/validators/wordCount.js +22 -14
- package/src/lib/waypoint-url.js +64 -46
- package/src/middleware/body-parser.js +10 -10
- package/src/middleware/csrf.js +1 -1
- package/src/middleware/data.js +28 -24
- package/src/middleware/gather-fields.js +10 -9
- package/src/middleware/i18n.js +35 -37
- package/src/middleware/post.js +41 -21
- package/src/middleware/pre.js +62 -41
- package/src/middleware/progress-journey.js +32 -18
- package/src/middleware/sanitise-fields.js +43 -20
- package/src/middleware/serve-first-waypoint.js +14 -12
- package/src/middleware/session.js +74 -61
- package/src/middleware/skip-waypoint.js +7 -9
- package/src/middleware/steer-journey.js +40 -28
- package/src/middleware/strip-proxy-path.js +8 -7
- package/src/middleware/validate-fields.js +5 -12
- package/src/routes/ancillary.js +5 -7
- package/src/routes/journey.js +159 -85
- package/src/routes/static.js +62 -29
- package/views/casa/components/character-count/README.md +2 -2
- package/views/casa/components/checkboxes/README.md +6 -6
- package/views/casa/components/date-input/README.md +7 -7
- package/views/casa/components/input/README.md +2 -2
- package/views/casa/components/journey-form/README.md +33 -14
- package/views/casa/components/postal-address-object/README.md +4 -4
- package/views/casa/components/radios/README.md +6 -6
- package/views/casa/components/select/README.md +6 -6
- package/views/casa/components/textarea/README.md +2 -2
- package/views/casa/layouts/main.njk +2 -1
|
@@ -10,8 +10,8 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
11
|
const { isEmail } = validator_1.default; // CommonJS
|
|
12
12
|
/**
|
|
13
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
13
14
|
* @access private
|
|
14
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {object} EmailConfigOptions
|
|
@@ -31,7 +31,7 @@ class Email extends ValidatorFactory_js_1.default {
|
|
|
31
31
|
constructor() {
|
|
32
32
|
super(...arguments);
|
|
33
33
|
/** @property {string} name Validator name ("email") */
|
|
34
|
-
this.name =
|
|
34
|
+
this.name = "email";
|
|
35
35
|
}
|
|
36
36
|
validate(value, dataContext = {}) {
|
|
37
37
|
let isValid;
|
|
@@ -42,8 +42,8 @@ class Email extends ValidatorFactory_js_1.default {
|
|
|
42
42
|
isValid = false;
|
|
43
43
|
}
|
|
44
44
|
const errorMsg = this.config.errorMsg || {
|
|
45
|
-
summary:
|
|
46
|
-
inline:
|
|
45
|
+
summary: "validation:rule.email.summary",
|
|
46
|
+
inline: "validation:rule.email.inline",
|
|
47
47
|
};
|
|
48
48
|
return isValid ? [] : [ValidationError_js_1.default.make({ errorMsg, dataContext })];
|
|
49
49
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
2
3
|
* @access private
|
|
3
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {object} ArrayConfigOptions
|
|
@@ -24,7 +24,7 @@ export default class InArray extends ValidatorFactory {
|
|
|
24
24
|
validate(value: any, dataContext?: {}): ValidationError[];
|
|
25
25
|
sanitise(value: any): string | string[] | undefined;
|
|
26
26
|
}
|
|
27
|
-
export type ErrorMessageConfig = import(
|
|
27
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
28
28
|
export type ArrayConfigOptions = {
|
|
29
29
|
/**
|
|
30
30
|
* Error message config
|
|
@@ -35,5 +35,5 @@ export type ArrayConfigOptions = {
|
|
|
35
35
|
*/
|
|
36
36
|
source: string[];
|
|
37
37
|
};
|
|
38
|
-
import ValidatorFactory from
|
|
39
|
-
import ValidationError from
|
|
38
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
39
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
/**
|
|
8
8
|
* Test if a value is present in an array.
|
|
9
9
|
*
|
|
10
|
-
* Config options:
|
|
11
|
-
* Array source = Array of values to test against
|
|
10
|
+
* Config options: Array source = Array of values to test against
|
|
12
11
|
*
|
|
13
12
|
* If the value itself is an array, all values within that array must be present
|
|
14
13
|
* in the `source` array in order to pass validation.
|
|
@@ -17,8 +16,8 @@ const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
|
17
16
|
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
18
17
|
const utils_js_1 = require("../utils.js");
|
|
19
18
|
/**
|
|
19
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
20
20
|
* @access private
|
|
21
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
22
21
|
*/
|
|
23
22
|
/**
|
|
24
23
|
* @typedef {object} ArrayConfigOptions
|
|
@@ -40,16 +39,16 @@ class InArray extends ValidatorFactory_js_1.default {
|
|
|
40
39
|
constructor() {
|
|
41
40
|
super(...arguments);
|
|
42
41
|
/** @property {string} name Validator name ("inArray") */
|
|
43
|
-
this.name =
|
|
42
|
+
this.name = "inArray";
|
|
44
43
|
}
|
|
45
44
|
validate(value, dataContext = {}) {
|
|
46
45
|
let valid = false;
|
|
47
46
|
const source = this.config.source || [];
|
|
48
47
|
const errorMsg = this.config.errorMsg || {
|
|
49
|
-
inline:
|
|
50
|
-
summary:
|
|
48
|
+
inline: "validation:rule.inArray.inline",
|
|
49
|
+
summary: "validation:rule.inArray.summary",
|
|
51
50
|
};
|
|
52
|
-
if (value !== null && typeof value !==
|
|
51
|
+
if (value !== null && typeof value !== "undefined") {
|
|
53
52
|
const search = Array.isArray(value) ? value : [value];
|
|
54
53
|
for (let i = 0, l = search.length; i < l; i += 1) {
|
|
55
54
|
if (source.indexOf(search[parseInt(i, 10)]) > -1) {
|
|
@@ -64,7 +63,7 @@ class InArray extends ValidatorFactory_js_1.default {
|
|
|
64
63
|
return valid ? [] : [ValidationError_js_1.default.make({ errorMsg, dataContext })];
|
|
65
64
|
}
|
|
66
65
|
sanitise(value) {
|
|
67
|
-
const coerce = (val) => (
|
|
66
|
+
const coerce = (val) => (0, utils_js_1.stringifyInput)(val, undefined);
|
|
68
67
|
// Basic stringable
|
|
69
68
|
if ((0, utils_js_1.isStringable)(value)) {
|
|
70
69
|
return (0, utils_js_1.stringifyInput)(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inArray.js","sourceRoot":"","sources":["../../../src/lib/validators/inArray.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C
|
|
1
|
+
{"version":3,"file":"inArray.js","sourceRoot":"","sources":["../../../src/lib/validators/inArray.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C;;;;;;;GAOG;AACH,+EAAoD;AACpD,iFAAsD;AACtD,0CAA2D;AAE3D;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,MAAqB,OAAQ,SAAQ,6BAAgB;IAArD;;QACE,yDAAyD;QACzD,SAAI,GAAG,SAAS,CAAC;IA0CnB,CAAC;IAxCC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,EAAE;QAC9B,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI;YACvC,MAAM,EAAE,gCAAgC;YACxC,OAAO,EAAE,iCAAiC;SAC3C,CAAC;QAEF,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;YACnD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;oBACjD,KAAK,GAAG,IAAI,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACN,KAAK,GAAG,KAAK,CAAC;oBACd,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,4BAAe,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,QAAQ,CAAC,KAAK;QACZ,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,yBAAc,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAEvD,mBAAmB;QACnB,IAAI,IAAA,uBAAY,EAAC,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QAED,kCAAkC;QAClC,qEAAqE;QACrE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;QAED,oBAAoB;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5CD,0BA4CC"}
|
|
@@ -11,13 +11,13 @@ declare namespace _default {
|
|
|
11
11
|
export { wordCount };
|
|
12
12
|
}
|
|
13
13
|
export default _default;
|
|
14
|
-
import dateObject from
|
|
15
|
-
import email from
|
|
16
|
-
import inArray from
|
|
17
|
-
import nino from
|
|
18
|
-
import postalAddressObject from
|
|
19
|
-
import regex from
|
|
20
|
-
import required from
|
|
21
|
-
import strlen from
|
|
22
|
-
import range from
|
|
23
|
-
import wordCount from
|
|
14
|
+
import dateObject from "./dateObject.js";
|
|
15
|
+
import email from "./email.js";
|
|
16
|
+
import inArray from "./inArray.js";
|
|
17
|
+
import nino from "./nino.js";
|
|
18
|
+
import postalAddressObject from "./postalAddressObject.js";
|
|
19
|
+
import regex from "./regex.js";
|
|
20
|
+
import required from "./required.js";
|
|
21
|
+
import strlen from "./strlen.js";
|
|
22
|
+
import range from "./range.js";
|
|
23
|
+
import wordCount from "./wordCount.js";
|
|
@@ -13,9 +13,7 @@ const required_js_1 = __importDefault(require("./required.js"));
|
|
|
13
13
|
const strlen_js_1 = __importDefault(require("./strlen.js"));
|
|
14
14
|
const range_js_1 = __importDefault(require("./range.js"));
|
|
15
15
|
const wordCount_js_1 = __importDefault(require("./wordCount.js"));
|
|
16
|
-
/**
|
|
17
|
-
* @namespace Validators
|
|
18
|
-
*/
|
|
16
|
+
/** @namespace Validators */
|
|
19
17
|
exports.default = {
|
|
20
18
|
dateObject: dateObject_js_1.default,
|
|
21
19
|
email: email_js_1.default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/validators/index.js"],"names":[],"mappings":";;;;;AAAA,oEAAyC;AACzC,0DAA+B;AAC/B,8DAAmC;AACnC,wDAA6B;AAC7B,sFAA2D;AAC3D,0DAA+B;AAC/B,gEAAqC;AACrC,4DAAiC;AACjC,0DAA+B;AAC/B,kEAAuC;AAEvC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/validators/index.js"],"names":[],"mappings":";;;;;AAAA,oEAAyC;AACzC,0DAA+B;AAC/B,8DAAmC;AACnC,wDAA6B;AAC7B,sFAA2D;AAC3D,0DAA+B;AAC/B,gEAAqC;AACrC,4DAAiC;AACjC,0DAA+B;AAC/B,kEAAuC;AAEvC,4BAA4B;AAC5B,kBAAe;IACb,UAAU,EAAV,uBAAU;IACV,KAAK,EAAL,kBAAK;IACL,OAAO,EAAP,oBAAO;IACP,IAAI,EAAJ,iBAAI;IACJ,mBAAmB,EAAnB,gCAAmB;IACnB,KAAK,EAAL,kBAAK;IACL,QAAQ,EAAR,qBAAQ;IACR,MAAM,EAAN,mBAAM;IACN,KAAK,EAAL,kBAAK;IACL,SAAS,EAAT,sBAAS;CACV,CAAC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
2
3
|
* @access private
|
|
3
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {object} NinoConfigOptions
|
|
7
7
|
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
|
-
* @property {boolean} allowWhitespace Will permit input values that contain
|
|
8
|
+
* @property {boolean} allowWhitespace Will permit input values that contain
|
|
9
|
+
* spaces.
|
|
9
10
|
*/
|
|
10
11
|
/**
|
|
11
12
|
* UK National Insurance number.
|
|
12
13
|
*
|
|
13
|
-
* Ref:
|
|
14
|
-
* https://en.wikipedia.org/wiki/National_Insurance_number#Format
|
|
14
|
+
* Ref: https://en.wikipedia.org/wiki/National_Insurance_number#Format
|
|
15
15
|
* https://design-system.service.gov.uk/patterns/national-insurance-numbers/
|
|
16
16
|
*
|
|
17
17
|
* See {@link NinoConfigOptions} for `make()` options.
|
|
@@ -24,16 +24,17 @@ export default class Nino extends ValidatorFactory {
|
|
|
24
24
|
validate(value: any, dataContext?: {}): ValidationError[];
|
|
25
25
|
sanitise(value: any): string | undefined;
|
|
26
26
|
}
|
|
27
|
-
export type ErrorMessageConfig = import(
|
|
27
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
28
28
|
export type NinoConfigOptions = {
|
|
29
29
|
/**
|
|
30
30
|
* Error message config
|
|
31
31
|
*/
|
|
32
32
|
errorMsg: ErrorMessageConfig;
|
|
33
33
|
/**
|
|
34
|
-
* Will permit input values that contain
|
|
34
|
+
* Will permit input values that contain
|
|
35
|
+
* spaces.
|
|
35
36
|
*/
|
|
36
37
|
allowWhitespace: boolean;
|
|
37
38
|
};
|
|
38
|
-
import ValidatorFactory from
|
|
39
|
-
import ValidationError from
|
|
39
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
40
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -8,19 +8,19 @@ const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
|
8
8
|
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
10
|
/**
|
|
11
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
11
12
|
* @access private
|
|
12
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {object} NinoConfigOptions
|
|
16
16
|
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
17
|
-
* @property {boolean} allowWhitespace Will permit input values that contain
|
|
17
|
+
* @property {boolean} allowWhitespace Will permit input values that contain
|
|
18
|
+
* spaces.
|
|
18
19
|
*/
|
|
19
20
|
/**
|
|
20
21
|
* UK National Insurance number.
|
|
21
22
|
*
|
|
22
|
-
* Ref:
|
|
23
|
-
* https://en.wikipedia.org/wiki/National_Insurance_number#Format
|
|
23
|
+
* Ref: https://en.wikipedia.org/wiki/National_Insurance_number#Format
|
|
24
24
|
* https://design-system.service.gov.uk/patterns/national-insurance-numbers/
|
|
25
25
|
*
|
|
26
26
|
* See {@link NinoConfigOptions} for `make()` options.
|
|
@@ -31,18 +31,22 @@ const utils_js_1 = require("../utils.js");
|
|
|
31
31
|
class Nino extends ValidatorFactory_js_1.default {
|
|
32
32
|
constructor() {
|
|
33
33
|
super(...arguments);
|
|
34
|
-
this.name =
|
|
34
|
+
this.name = "nino";
|
|
35
35
|
}
|
|
36
36
|
validate(value, dataContext = {}) {
|
|
37
37
|
const { allowWhitespace, errorMsg = {
|
|
38
|
-
inline:
|
|
39
|
-
summary:
|
|
38
|
+
inline: "validation:rule.nino.inline",
|
|
39
|
+
summary: "validation:rule.nino.summary",
|
|
40
40
|
}, } = this.config;
|
|
41
|
-
if (typeof allowWhitespace !==
|
|
41
|
+
if (typeof allowWhitespace !== "undefined" &&
|
|
42
|
+
typeof allowWhitespace !== "boolean") {
|
|
42
43
|
throw new TypeError(`NINO validation rule option "allowWhitespace" must been a boolean. received ${typeof allowWhitespace}`);
|
|
43
44
|
}
|
|
44
|
-
const valid = typeof value ===
|
|
45
|
-
|
|
45
|
+
const valid = typeof value === "string" &&
|
|
46
|
+
value
|
|
47
|
+
.replace(typeof allowWhitespace !== "undefined" && allowWhitespace
|
|
48
|
+
? /\u0020/g
|
|
49
|
+
: "", "")
|
|
46
50
|
.match(/^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$/i);
|
|
47
51
|
return valid ? [] : [ValidationError_js_1.default.make({ errorMsg, dataContext })];
|
|
48
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nino.js","sourceRoot":"","sources":["../../../src/lib/validators/nino.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,+EAAoD;AACpD,iFAAsD;AACtD,0CAA6C;AAE7C;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"nino.js","sourceRoot":"","sources":["../../../src/lib/validators/nino.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,+EAAoD;AACpD,iFAAsD;AACtD,0CAA6C;AAE7C;;;GAGG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,MAAqB,IAAK,SAAQ,6BAAgB;IAAlD;;QACE,SAAI,GAAG,MAAM,CAAC;IAyChB,CAAC;IAvCC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,EAAE;QAC9B,MAAM,EACJ,eAAe,EACf,QAAQ,GAAG;YACT,MAAM,EAAE,6BAA6B;YACrC,OAAO,EAAE,8BAA8B;SACxC,GACF,GAAG,IAAI,CAAC,MAAM,CAAC;QAEhB,IACE,OAAO,eAAe,KAAK,WAAW;YACtC,OAAO,eAAe,KAAK,SAAS,EACpC,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,+EAA+E,OAAO,eAAe,EAAE,CACxG,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,GACT,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK;iBACF,OAAO,CACN,OAAO,eAAe,KAAK,WAAW,IAAI,eAAe;gBACvD,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,EAAE,EACN,EAAE,CACH;iBACA,KAAK,CACJ,0EAA0E,CAC3E,CAAC;QAEN,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,4BAAe,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,QAAQ,CAAC,KAAK;QACZ,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA1CD,uBA0CC"}
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
2
3
|
* @access private
|
|
3
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {object} PostalAddressObjectConfigOptions
|
|
7
|
-
* @property {ErrorMessageConfig} [errorMsg] General error message for the
|
|
8
|
-
*
|
|
9
|
-
* @property {string|object} [
|
|
10
|
-
*
|
|
11
|
-
* @property {string|object} [
|
|
12
|
-
*
|
|
13
|
-
* @property {
|
|
14
|
-
*
|
|
15
|
-
*
|
|
7
|
+
* @property {ErrorMessageConfig} [errorMsg] General error message for the
|
|
8
|
+
* entire address block
|
|
9
|
+
* @property {string | object} [errorMsgAddress1] Error message for address1
|
|
10
|
+
* part
|
|
11
|
+
* @property {string | object} [errorMsgAddress2] Error message for address2
|
|
12
|
+
* part
|
|
13
|
+
* @property {string | object} [errorMsgAddress3] Error message for address3
|
|
14
|
+
* part
|
|
15
|
+
* @property {string | object} [errorMsgAddress4] Error message for address4
|
|
16
|
+
* part
|
|
17
|
+
* @property {string | object} [errorMsgPostcode] Error message for postcode
|
|
18
|
+
* part
|
|
19
|
+
* @property {number} [strlenmax] Max. String length for each of the inputs
|
|
20
|
+
* address[1-4]
|
|
21
|
+
* @property {string[]} [requiredFields] Field parts required (others become
|
|
22
|
+
* optional). One of 'address1'|'address2'|'address3'|'address4'|'postcode'
|
|
16
23
|
*/
|
|
17
24
|
/**
|
|
18
|
-
* Works hand in hand with the core CASA `postalAddressObject` form
|
|
19
|
-
* macro.
|
|
25
|
+
* Works hand in hand with the core CASA `postalAddressObject` form macro.
|
|
20
26
|
*
|
|
21
27
|
* The errors sent back from this validator are specific to each subfield. For
|
|
22
28
|
* example, if the field name being tested is "address", any errors related to
|
|
@@ -32,41 +38,48 @@ export default class PostalAddressObject extends ValidatorFactory {
|
|
|
32
38
|
validate(value: any, dataContext?: {}): ValidationError[];
|
|
33
39
|
sanitise(value: any): any;
|
|
34
40
|
}
|
|
35
|
-
export type ErrorMessageConfig = import(
|
|
41
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
36
42
|
export type PostalAddressObjectConfigOptions = {
|
|
37
43
|
/**
|
|
38
|
-
* General error message for the
|
|
44
|
+
* General error message for the
|
|
45
|
+
* entire address block
|
|
39
46
|
*/
|
|
40
47
|
errorMsg?: import("../../casa").ErrorMessageConfig | undefined;
|
|
41
48
|
/**
|
|
42
|
-
* Error message for address1
|
|
49
|
+
* Error message for address1
|
|
50
|
+
* part
|
|
43
51
|
*/
|
|
44
52
|
errorMsgAddress1?: string | object | undefined;
|
|
45
53
|
/**
|
|
46
|
-
* Error message for address2
|
|
54
|
+
* Error message for address2
|
|
55
|
+
* part
|
|
47
56
|
*/
|
|
48
57
|
errorMsgAddress2?: string | object | undefined;
|
|
49
58
|
/**
|
|
50
|
-
* Error message for address3
|
|
59
|
+
* Error message for address3
|
|
60
|
+
* part
|
|
51
61
|
*/
|
|
52
62
|
errorMsgAddress3?: string | object | undefined;
|
|
53
63
|
/**
|
|
54
|
-
* Error message for address4
|
|
64
|
+
* Error message for address4
|
|
65
|
+
* part
|
|
55
66
|
*/
|
|
56
67
|
errorMsgAddress4?: string | object | undefined;
|
|
57
68
|
/**
|
|
58
|
-
* Error message for postcode
|
|
69
|
+
* Error message for postcode
|
|
70
|
+
* part
|
|
59
71
|
*/
|
|
60
72
|
errorMsgPostcode?: string | object | undefined;
|
|
61
73
|
/**
|
|
62
|
-
* Max. String length for each of the inputs
|
|
74
|
+
* Max. String length for each of the inputs
|
|
75
|
+
* address[1-4]
|
|
63
76
|
*/
|
|
64
77
|
strlenmax?: number | undefined;
|
|
65
78
|
/**
|
|
66
|
-
* Field parts required (others become
|
|
67
|
-
* 'address1'|'address2'|'address3'|'address4'|'postcode'
|
|
79
|
+
* Field parts required (others become
|
|
80
|
+
* optional). One of 'address1'|'address2'|'address3'|'address4'|'postcode'
|
|
68
81
|
*/
|
|
69
82
|
requiredFields?: string[] | undefined;
|
|
70
83
|
};
|
|
71
|
-
import ValidatorFactory from
|
|
72
|
-
import ValidationError from
|
|
84
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
85
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -10,24 +10,30 @@ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"))
|
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
11
|
const { isPlainObject } = lodash_1.default; // CommonjS
|
|
12
12
|
/**
|
|
13
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
13
14
|
* @access private
|
|
14
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {object} PostalAddressObjectConfigOptions
|
|
18
|
-
* @property {ErrorMessageConfig} [errorMsg] General error message for the
|
|
19
|
-
*
|
|
20
|
-
* @property {string|object} [
|
|
21
|
-
*
|
|
22
|
-
* @property {string|object} [
|
|
23
|
-
*
|
|
24
|
-
* @property {
|
|
25
|
-
*
|
|
26
|
-
*
|
|
18
|
+
* @property {ErrorMessageConfig} [errorMsg] General error message for the
|
|
19
|
+
* entire address block
|
|
20
|
+
* @property {string | object} [errorMsgAddress1] Error message for address1
|
|
21
|
+
* part
|
|
22
|
+
* @property {string | object} [errorMsgAddress2] Error message for address2
|
|
23
|
+
* part
|
|
24
|
+
* @property {string | object} [errorMsgAddress3] Error message for address3
|
|
25
|
+
* part
|
|
26
|
+
* @property {string | object} [errorMsgAddress4] Error message for address4
|
|
27
|
+
* part
|
|
28
|
+
* @property {string | object} [errorMsgPostcode] Error message for postcode
|
|
29
|
+
* part
|
|
30
|
+
* @property {number} [strlenmax] Max. String length for each of the inputs
|
|
31
|
+
* address[1-4]
|
|
32
|
+
* @property {string[]} [requiredFields] Field parts required (others become
|
|
33
|
+
* optional). One of 'address1'|'address2'|'address3'|'address4'|'postcode'
|
|
27
34
|
*/
|
|
28
35
|
/**
|
|
29
|
-
* Works hand in hand with the core CASA `postalAddressObject` form
|
|
30
|
-
* macro.
|
|
36
|
+
* Works hand in hand with the core CASA `postalAddressObject` form macro.
|
|
31
37
|
*
|
|
32
38
|
* The errors sent back from this validator are specific to each subfield. For
|
|
33
39
|
* example, if the field name being tested is "address", any errors related to
|
|
@@ -41,50 +47,52 @@ const { isPlainObject } = lodash_1.default; // CommonjS
|
|
|
41
47
|
class PostalAddressObject extends ValidatorFactory_js_1.default {
|
|
42
48
|
constructor() {
|
|
43
49
|
super(...arguments);
|
|
44
|
-
this.name =
|
|
50
|
+
this.name = "postalAddressObject";
|
|
45
51
|
}
|
|
46
52
|
validate(value, dataContext = {}) {
|
|
47
|
-
const cfg = Object.assign({ requiredFields: [
|
|
48
|
-
inline:
|
|
49
|
-
summary:
|
|
50
|
-
focusSuffix:
|
|
53
|
+
const cfg = Object.assign({ requiredFields: ["address1", "address3", "postcode"], strlenmax: undefined, errorMsgAddress1: {
|
|
54
|
+
inline: "validation:rule.postalAddressObject.address1.inline",
|
|
55
|
+
summary: "validation:rule.postalAddressObject.address1.summary",
|
|
56
|
+
focusSuffix: "[address1]",
|
|
51
57
|
}, errorMsgAddress2: {
|
|
52
|
-
inline:
|
|
53
|
-
summary:
|
|
54
|
-
focusSuffix:
|
|
58
|
+
inline: "validation:rule.postalAddressObject.address2.inline",
|
|
59
|
+
summary: "validation:rule.postalAddressObject.address2.summary",
|
|
60
|
+
focusSuffix: "[address2]",
|
|
55
61
|
}, errorMsgAddress3: {
|
|
56
|
-
inline:
|
|
57
|
-
summary:
|
|
58
|
-
focusSuffix:
|
|
62
|
+
inline: "validation:rule.postalAddressObject.address3.inline",
|
|
63
|
+
summary: "validation:rule.postalAddressObject.address3.summary",
|
|
64
|
+
focusSuffix: "[address3]",
|
|
59
65
|
}, errorMsgAddress4: {
|
|
60
|
-
inline:
|
|
61
|
-
summary:
|
|
62
|
-
focusSuffix:
|
|
66
|
+
inline: "validation:rule.postalAddressObject.address4.inline",
|
|
67
|
+
summary: "validation:rule.postalAddressObject.address4.summary",
|
|
68
|
+
focusSuffix: "[address4]",
|
|
63
69
|
}, errorMsgPostcode: {
|
|
64
|
-
inline:
|
|
65
|
-
summary:
|
|
66
|
-
focusSuffix:
|
|
70
|
+
inline: "validation:rule.postalAddressObject.postcode.inline",
|
|
71
|
+
summary: "validation:rule.postalAddressObject.postcode.summary",
|
|
72
|
+
focusSuffix: "[postcode]",
|
|
67
73
|
}, errorMsg: {
|
|
68
|
-
inline:
|
|
69
|
-
summary:
|
|
70
|
-
focusSuffix:
|
|
74
|
+
inline: "validation:rule.postalAddressObject.group.inline",
|
|
75
|
+
summary: "validation:rule.postalAddressObject.group.summary",
|
|
76
|
+
focusSuffix: "[address1]",
|
|
71
77
|
} }, this.config);
|
|
72
78
|
/* eslint-disable-next-line require-jsdoc */
|
|
73
|
-
const objectifyError = (err) =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
const objectifyError = (err) => typeof err === "string"
|
|
80
|
+
? {
|
|
81
|
+
inline: err,
|
|
82
|
+
summary: err,
|
|
83
|
+
}
|
|
84
|
+
: err;
|
|
77
85
|
// Work out required/optional parts based on config
|
|
78
86
|
const reqF = Object.create(null);
|
|
79
87
|
const reqC = cfg.requiredFields;
|
|
80
|
-
[
|
|
88
|
+
["address1", "address2", "address3", "address4", "postcode"].forEach((k) => {
|
|
81
89
|
// ESLint disabled as `k` is a known value from a constant list
|
|
82
90
|
/* eslint-disable-next-line security/detect-object-injection */
|
|
83
91
|
reqF[k] = reqC.indexOf(k) > -1;
|
|
84
92
|
});
|
|
85
93
|
let valid = true;
|
|
86
94
|
const errorMsgs = [];
|
|
87
|
-
if (typeof value ===
|
|
95
|
+
if (typeof value === "object") {
|
|
88
96
|
const reAddr = /^[^\s]+[a-z0-9\-,.&#()/\\:;'" ]+$/i;
|
|
89
97
|
const reAddrLine1 = /^\d+|[^\s]+[a-z0-9\-,.&#()/\\:;'" ]+$/i;
|
|
90
98
|
// UK Postcode regex taken from the dwp java pc checker
|
|
@@ -92,7 +100,12 @@ class PostalAddressObject extends ValidatorFactory_js_1.default {
|
|
|
92
100
|
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;
|
|
93
101
|
// [required, regex, strlenmax, error message]
|
|
94
102
|
const attributes = {
|
|
95
|
-
address1: [
|
|
103
|
+
address1: [
|
|
104
|
+
reqF.address1,
|
|
105
|
+
reAddrLine1,
|
|
106
|
+
cfg.strlenmax,
|
|
107
|
+
cfg.errorMsgAddress1,
|
|
108
|
+
],
|
|
96
109
|
address2: [reqF.address2, reAddr, cfg.strlenmax, cfg.errorMsgAddress2],
|
|
97
110
|
address3: [reqF.address3, reAddr, cfg.strlenmax, cfg.errorMsgAddress3],
|
|
98
111
|
address4: [reqF.address4, reAddr, cfg.strlenmax, cfg.errorMsgAddress4],
|
|
@@ -104,10 +117,8 @@ class PostalAddressObject extends ValidatorFactory_js_1.default {
|
|
|
104
117
|
const attr = attributes[k];
|
|
105
118
|
const hasProperty = Object.prototype.hasOwnProperty.call(value, k);
|
|
106
119
|
const hasContent = hasProperty && value[k].length > 0;
|
|
107
|
-
const condMissingOrRegexMismatch = (attr[0] || hasContent)
|
|
108
|
-
|
|
109
|
-
const condExceedStrlen = attr[2] > 0 && hasContent
|
|
110
|
-
&& String(value[k]).length > attr[2];
|
|
120
|
+
const condMissingOrRegexMismatch = (attr[0] || hasContent) && (!hasProperty || !value[k].match(attr[1]));
|
|
121
|
+
const condExceedStrlen = attr[2] > 0 && hasContent && String(value[k]).length > attr[2];
|
|
111
122
|
if (condMissingOrRegexMismatch || condExceedStrlen) {
|
|
112
123
|
valid = false;
|
|
113
124
|
errorMsgs.push(Object.assign(Object.create(null), objectifyError(attr[3]), {
|
|
@@ -122,7 +133,7 @@ class PostalAddressObject extends ValidatorFactory_js_1.default {
|
|
|
122
133
|
errorMsgs.push(cfg.errorMsg);
|
|
123
134
|
}
|
|
124
135
|
// Build ValidationErrorGroup
|
|
125
|
-
const errorGroup = errorMsgs.map((err) =>
|
|
136
|
+
const errorGroup = errorMsgs.map((err) => ValidationError_js_1.default.make({ errorMsg: err, dataContext }));
|
|
126
137
|
return valid ? [] : [...errorGroup];
|
|
127
138
|
}
|
|
128
139
|
sanitise(value) {
|
|
@@ -131,8 +142,16 @@ class PostalAddressObject extends ValidatorFactory_js_1.default {
|
|
|
131
142
|
return Object.create(null);
|
|
132
143
|
}
|
|
133
144
|
// Prune unrecognised attributes, and coerce to Strings
|
|
134
|
-
const validKeys = [
|
|
135
|
-
|
|
145
|
+
const validKeys = [
|
|
146
|
+
"address1",
|
|
147
|
+
"address2",
|
|
148
|
+
"address3",
|
|
149
|
+
"address4",
|
|
150
|
+
"postcode",
|
|
151
|
+
];
|
|
152
|
+
const pruned = Object.fromEntries(Object.entries(value)
|
|
153
|
+
.filter(([k]) => validKeys.includes(k))
|
|
154
|
+
.map(([k, v]) => [k, (0, utils_js_1.stringifyInput)(v)]));
|
|
136
155
|
return Object.assign(Object.create(null), pruned);
|
|
137
156
|
}
|
|
138
157
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postalAddressObject.js","sourceRoot":"","sources":["../../../src/lib/validators/postalAddressObject.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,oDAA4B;AAC5B,+EAAoD;AACpD,iFAAsD;AACtD,0CAA6C;AAE7C,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAM,CAAC,CAAC,WAAW;AAE7C;;;GAGG;AAEH;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"postalAddressObject.js","sourceRoot":"","sources":["../../../src/lib/validators/postalAddressObject.js"],"names":[],"mappings":";;;;;AAAA,2CAA2C;AAC3C,oDAA4B;AAC5B,+EAAoD;AACpD,iFAAsD;AACtD,0CAA6C;AAE7C,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAM,CAAC,CAAC,WAAW;AAE7C;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;;;;;GAWG;AACH,MAAqB,mBAAoB,SAAQ,6BAAgB;IAAjE;;QACE,SAAI,GAAG,qBAAqB,CAAC;IA2I/B,CAAC;IAzIC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,EAAE;QAC9B,MAAM,GAAG,mBACP,cAAc,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,EACpD,SAAS,EAAE,SAAS,EACp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,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QAED,uDAAuD;QACvD,MAAM,SAAS,GAAG;YAChB,UAAU;YACV,UAAU;YACV,UAAU;YACV,UAAU;YACV,UAAU;SACX,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAC/B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;aAClB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAA,yBAAc,EAAC,CAAC,CAAC,CAAC,CAAC,CAC3C,CAAC;QACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;CACF;AA5ID,sCA4IC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import("../../casa").ErrorMessageConfig} ErrorMessageConfig
|
|
2
3
|
* @access private
|
|
3
|
-
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {object} RangeConfigOptions
|
|
7
|
-
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max
|
|
8
|
-
*
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsgMax Error message to use on max
|
|
8
|
+
* failure
|
|
9
|
+
* @property {ErrorMessageConfig} errorMsgMin Error message to use on min
|
|
10
|
+
* failure
|
|
9
11
|
* @property {number} max Maximum integer value
|
|
10
12
|
* @property {number} min Minimum integer value
|
|
11
13
|
*/
|
|
@@ -22,14 +24,16 @@ export default class Range extends ValidatorFactory {
|
|
|
22
24
|
validate(inputValue: any, dataContext?: {}): ValidationError[];
|
|
23
25
|
sanitise(value: any): string | undefined;
|
|
24
26
|
}
|
|
25
|
-
export type ErrorMessageConfig = import(
|
|
27
|
+
export type ErrorMessageConfig = import("../../casa").ErrorMessageConfig;
|
|
26
28
|
export type RangeConfigOptions = {
|
|
27
29
|
/**
|
|
28
|
-
* Error message to use on max
|
|
30
|
+
* Error message to use on max
|
|
31
|
+
* failure
|
|
29
32
|
*/
|
|
30
33
|
errorMsgMax: ErrorMessageConfig;
|
|
31
34
|
/**
|
|
32
|
-
* Error message to use on min
|
|
35
|
+
* Error message to use on min
|
|
36
|
+
* failure
|
|
33
37
|
*/
|
|
34
38
|
errorMsgMin: ErrorMessageConfig;
|
|
35
39
|
/**
|
|
@@ -41,5 +45,5 @@ export type RangeConfigOptions = {
|
|
|
41
45
|
*/
|
|
42
46
|
min: number;
|
|
43
47
|
};
|
|
44
|
-
import ValidatorFactory from
|
|
45
|
-
import ValidationError from
|
|
48
|
+
import ValidatorFactory from "../ValidatorFactory.js";
|
|
49
|
+
import ValidationError from "../ValidationError.js";
|