@dwp/govuk-casa 8.2.1 → 8.2.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.
- package/CHANGELOG.md +9 -0
- package/README.md +1 -0
- package/dist/casa.d.ts +203 -1
- package/dist/casa.js +131 -2
- package/dist/lib/CasaTemplateLoader.d.ts +4 -0
- package/dist/lib/CasaTemplateLoader.js +5 -0
- package/dist/lib/JourneyContext.d.ts +85 -13
- package/dist/lib/JourneyContext.js +78 -5
- package/dist/lib/Plan.d.ts +122 -49
- package/dist/lib/Plan.js +161 -37
- package/dist/lib/ValidationError.d.ts +38 -48
- package/dist/lib/ValidationError.js +30 -42
- package/dist/lib/ValidatorFactory.d.ts +42 -52
- package/dist/lib/ValidatorFactory.js +37 -48
- package/dist/lib/configuration-ingestor.d.ts +18 -4
- package/dist/lib/configuration-ingestor.js +23 -10
- package/dist/lib/configure.d.ts +4 -0
- package/dist/lib/configure.js +20 -52
- package/dist/lib/end-session.d.ts +3 -2
- package/dist/lib/end-session.js +2 -1
- package/dist/lib/field.d.ts +97 -35
- package/dist/lib/field.js +90 -41
- package/dist/lib/nunjucks-filters.d.ts +12 -2
- package/dist/lib/nunjucks-filters.js +11 -1
- package/dist/lib/nunjucks.d.ts +1 -0
- package/dist/lib/nunjucks.js +1 -0
- package/dist/lib/utils.d.ts +46 -14
- package/dist/lib/utils.js +43 -26
- package/dist/lib/validators/dateObject.d.ts +75 -1
- package/dist/lib/validators/dateObject.js +29 -18
- package/dist/lib/validators/email.d.ts +28 -1
- package/dist/lib/validators/email.js +20 -9
- package/dist/lib/validators/inArray.d.ts +34 -1
- package/dist/lib/validators/inArray.js +21 -0
- package/dist/lib/validators/index.js +3 -0
- package/dist/lib/validators/nino.d.ts +34 -1
- package/dist/lib/validators/nino.js +17 -7
- package/dist/lib/validators/postalAddressObject.d.ts +68 -1
- package/dist/lib/validators/postalAddressObject.js +27 -15
- package/dist/lib/validators/regex.d.ts +35 -1
- package/dist/lib/validators/regex.js +17 -7
- package/dist/lib/validators/required.d.ts +28 -1
- package/dist/lib/validators/required.js +19 -6
- package/dist/lib/validators/strlen.d.ts +40 -1
- package/dist/lib/validators/strlen.js +18 -8
- package/dist/lib/validators/wordCount.d.ts +40 -1
- package/dist/lib/validators/wordCount.js +18 -8
- package/dist/lib/waypoint-url.d.ts +1 -0
- package/dist/lib/waypoint-url.js +10 -0
- package/dist/middleware/data.js +21 -5
- package/dist/middleware/gather-fields.js +1 -0
- package/dist/middleware/pre.js +1 -0
- package/dist/middleware/steer-journey.js +2 -1
- package/dist/middleware/strip-proxy-path.d.ts +4 -0
- package/dist/middleware/strip-proxy-path.js +56 -0
- package/dist/middleware/validate-fields.js +3 -0
- package/dist/routes/ancillary.d.ts +16 -5
- package/dist/routes/ancillary.js +7 -3
- package/dist/routes/journey.d.ts +30 -6
- package/dist/routes/journey.js +27 -0
- package/dist/routes/static.d.ts +1 -0
- package/dist/routes/static.js +2 -1
- package/package.json +16 -11
- package/views/casa/components/character-count/README.md +1 -1
- package/views/casa/components/input/README.md +1 -1
- package/views/casa/components/radios/README.md +2 -2
- package/views/casa/components/textarea/README.md +1 -1
package/dist/lib/utils.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* @access private
|
|
3
4
|
* @typedef {import('../casa').GlobalHook | import('../casa').PageHook} Hook
|
|
4
5
|
*/
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
+
exports.notProto = exports.validateHookPath = exports.validateHookName = exports.validateView = exports.validateUrlPath = exports.validateWaypoint = exports.resolveMiddlewareHooks = exports.isEmpty = exports.stringifyInput = exports.isStringable = void 0;
|
|
7
8
|
/**
|
|
8
9
|
* Test is a value can be stringifed (numbers or strings)
|
|
9
10
|
*
|
|
11
|
+
* @access private
|
|
10
12
|
* @param {any} value Item to test
|
|
11
13
|
* @returns {boolean} Whether the value is stringable or not
|
|
12
14
|
*/
|
|
@@ -17,6 +19,7 @@ exports.isStringable = isStringable;
|
|
|
17
19
|
/**
|
|
18
20
|
* Coerce an input to a string.
|
|
19
21
|
*
|
|
22
|
+
* @access private
|
|
20
23
|
* @param {any} input Input to be stringified
|
|
21
24
|
* @param {string} fallback Fallback to use if input can't be stringified
|
|
22
25
|
* @returns {string} The stringified input
|
|
@@ -30,6 +33,7 @@ exports.stringifyInput = stringifyInput;
|
|
|
30
33
|
/**
|
|
31
34
|
* Determine if value is empty. Recurse over objects.
|
|
32
35
|
*
|
|
36
|
+
* @access private
|
|
33
37
|
* @param {any} val Value to check
|
|
34
38
|
* @returns {boolean} True if the object is empty
|
|
35
39
|
*/
|
|
@@ -51,6 +55,7 @@ exports.isEmpty = isEmpty;
|
|
|
51
55
|
* Extract the middleware functions that are relevant for the given hook and
|
|
52
56
|
* path.
|
|
53
57
|
*
|
|
58
|
+
* @access private
|
|
54
59
|
* @param {string} hookName Hook name (including scope prefix)
|
|
55
60
|
* @param {string} path URL path to match (relative to mountUrl)
|
|
56
61
|
* @param {Hook[]} hooks Hooks to be applied at the page level
|
|
@@ -63,6 +68,15 @@ function resolveMiddlewareHooks(hookName, path, hooks = []) {
|
|
|
63
68
|
}
|
|
64
69
|
exports.resolveMiddlewareHooks = resolveMiddlewareHooks;
|
|
65
70
|
/* ------------------------------------------------ validation / sanitisation */
|
|
71
|
+
/**
|
|
72
|
+
* Validate a waypoint.
|
|
73
|
+
*
|
|
74
|
+
* @access private
|
|
75
|
+
* @param {string} waypoint Waypoint
|
|
76
|
+
* @returns {void}
|
|
77
|
+
* @throws {TypeError}
|
|
78
|
+
* @throws {SyntaxError}
|
|
79
|
+
*/
|
|
66
80
|
function validateWaypoint(waypoint) {
|
|
67
81
|
if (typeof waypoint !== 'string') {
|
|
68
82
|
throw new TypeError('Waypoint must be a string');
|
|
@@ -75,6 +89,15 @@ function validateWaypoint(waypoint) {
|
|
|
75
89
|
}
|
|
76
90
|
}
|
|
77
91
|
exports.validateWaypoint = validateWaypoint;
|
|
92
|
+
/**
|
|
93
|
+
* Validate a URL path.
|
|
94
|
+
*
|
|
95
|
+
* @access private
|
|
96
|
+
* @param {string} path URL path
|
|
97
|
+
* @returns {string} Same string, if valid
|
|
98
|
+
* @throws {TypeError}
|
|
99
|
+
* @throws {SyntaxError}
|
|
100
|
+
*/
|
|
78
101
|
function validateUrlPath(path) {
|
|
79
102
|
if (typeof path !== 'string') {
|
|
80
103
|
throw new TypeError('URL path must be a string');
|
|
@@ -88,6 +111,15 @@ function validateUrlPath(path) {
|
|
|
88
111
|
return path;
|
|
89
112
|
}
|
|
90
113
|
exports.validateUrlPath = validateUrlPath;
|
|
114
|
+
/**
|
|
115
|
+
* Validate a template name.
|
|
116
|
+
*
|
|
117
|
+
* @access private
|
|
118
|
+
* @param {string} view Template name
|
|
119
|
+
* @returns {void}
|
|
120
|
+
* @throws {TypeError}
|
|
121
|
+
* @throws {SyntaxError}
|
|
122
|
+
*/
|
|
91
123
|
function validateView(view) {
|
|
92
124
|
if (typeof view !== 'string') {
|
|
93
125
|
throw new TypeError('View must be a string');
|
|
@@ -100,6 +132,15 @@ function validateView(view) {
|
|
|
100
132
|
}
|
|
101
133
|
}
|
|
102
134
|
exports.validateView = validateView;
|
|
135
|
+
/**
|
|
136
|
+
* Validate a hook name.
|
|
137
|
+
*
|
|
138
|
+
* @access private
|
|
139
|
+
* @param {string} hookName Hook name
|
|
140
|
+
* @returns {void}
|
|
141
|
+
* @throws {TypeError}
|
|
142
|
+
* @throws {SyntaxError}
|
|
143
|
+
*/
|
|
103
144
|
function validateHookName(hookName) {
|
|
104
145
|
if (typeof hookName !== 'string') {
|
|
105
146
|
throw new TypeError('Hook name must be a string');
|
|
@@ -121,6 +162,7 @@ exports.validateHookPath = validateHookPath;
|
|
|
121
162
|
/**
|
|
122
163
|
* Checks if the given string can be used as an object key.
|
|
123
164
|
*
|
|
165
|
+
* @access private
|
|
124
166
|
* @param {string} key Proposed Object key
|
|
125
167
|
* @returns {string} Same key if it's valid
|
|
126
168
|
* @throws {Error} if proposed key is an invalid keyword
|
|
@@ -132,28 +174,3 @@ function notProto(key) {
|
|
|
132
174
|
return key;
|
|
133
175
|
}
|
|
134
176
|
exports.notProto = notProto;
|
|
135
|
-
/**
|
|
136
|
-
* Remove any path segments from the URL that are present in the `mountpath`,
|
|
137
|
-
* but not in the `baseUrl`. Those segments are considered to be part of an
|
|
138
|
-
* internal proxying arrangement, and should not be used by CASA.
|
|
139
|
-
*
|
|
140
|
-
* @param {import('express').Request} req Express request
|
|
141
|
-
* @throws {Error} When multiple mountpaths are present
|
|
142
|
-
* @returns {string} URL path with any proxy prefixes removed
|
|
143
|
-
*/
|
|
144
|
-
function stripProxyFromUrlPath(req) {
|
|
145
|
-
if (typeof req.app.mountpath !== 'string') {
|
|
146
|
-
throw new Error('CASA does not currently support multiple mountpaths');
|
|
147
|
-
}
|
|
148
|
-
let stripped = '/';
|
|
149
|
-
const mountPathParts = req.app.mountpath.replace(/^\/+/, '').replace(/\/+$/, '').split('/');
|
|
150
|
-
const baseUrlParts = req.baseUrl.replace(/^\/+/, '').replace(/\/+$/, '').split('/');
|
|
151
|
-
for (let i = 0, l = mountPathParts.length; i < l; i++) {
|
|
152
|
-
/* eslint-disable-next-line security/detect-object-injection */
|
|
153
|
-
if (baseUrlParts.length && mountPathParts[i] === baseUrlParts[0]) {
|
|
154
|
-
stripped = `${stripped}${baseUrlParts.shift()}/`;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return stripped;
|
|
158
|
-
}
|
|
159
|
-
exports.stripProxyFromUrlPath = stripProxyFromUrlPath;
|
|
@@ -1,5 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} DateObjectConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
|
+
* @property {object} [afterOffsetFromNow] Offset from now
|
|
9
|
+
* @property {ErrorMessageConfig} [errorMsgAfterOffset] Error if date is after this offset
|
|
10
|
+
* @property {object} [beforeOffsetFromNow] Offset from now
|
|
11
|
+
* @property {ErrorMessageConfig} [errorMsgBeforeOffset] Error if date is before this offset
|
|
12
|
+
* @property {boolean} [allowMonthNames=false] Allow "Jan", "January", etc
|
|
13
|
+
* @property {boolean} [allowSingleDigitDay=false] Allow "1" rather than "01"
|
|
14
|
+
* @property {boolean} [allowSingleDigitMonth=false] Allow "1" rather than "01"
|
|
15
|
+
* @property {DateTime} [now=false] Override the notion of "now" (useful for testing)
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Date object format:
|
|
19
|
+
* {
|
|
20
|
+
* dd: <string>,
|
|
21
|
+
* mm: <string>,
|
|
22
|
+
* yyyy: <string>
|
|
23
|
+
* }.
|
|
24
|
+
*
|
|
25
|
+
* Note that the time part will be zero'ed, as we are only interested in the
|
|
26
|
+
* date component (minimum day resolution).
|
|
27
|
+
*
|
|
28
|
+
* See {@link DateObjectConfigOptions} for `make()` options.
|
|
29
|
+
*
|
|
30
|
+
* @memberof Validators
|
|
31
|
+
* @augments ValidatorFactory
|
|
32
|
+
*/
|
|
1
33
|
export default class DateObject extends ValidatorFactory {
|
|
34
|
+
/** @property {string} name Validator name ("dateObject") */
|
|
2
35
|
name: string;
|
|
3
|
-
validate(value: any, dataContext?: {}):
|
|
36
|
+
validate(value: any, dataContext?: {}): ValidationError[];
|
|
37
|
+
sanitise(value: any): any;
|
|
4
38
|
}
|
|
39
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
40
|
+
export type DateObjectConfigOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Error message config
|
|
43
|
+
*/
|
|
44
|
+
errorMsg: ErrorMessageConfig;
|
|
45
|
+
/**
|
|
46
|
+
* Offset from now
|
|
47
|
+
*/
|
|
48
|
+
afterOffsetFromNow?: object | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Error if date is after this offset
|
|
51
|
+
*/
|
|
52
|
+
errorMsgAfterOffset?: import("../../casa").ErrorMessageConfig | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Offset from now
|
|
55
|
+
*/
|
|
56
|
+
beforeOffsetFromNow?: object | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Error if date is before this offset
|
|
59
|
+
*/
|
|
60
|
+
errorMsgBeforeOffset?: import("../../casa").ErrorMessageConfig | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Allow "Jan", "January", etc
|
|
63
|
+
*/
|
|
64
|
+
allowMonthNames?: boolean | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Allow "1" rather than "01"
|
|
67
|
+
*/
|
|
68
|
+
allowSingleDigitDay?: boolean | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Allow "1" rather than "01"
|
|
71
|
+
*/
|
|
72
|
+
allowSingleDigitMonth?: boolean | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Override the notion of "now" (useful for testing)
|
|
75
|
+
*/
|
|
76
|
+
now?: any;
|
|
77
|
+
};
|
|
5
78
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
79
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -4,6 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable class-methods-use-this */
|
|
7
|
+
const luxon_1 = require("luxon");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
10
|
+
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
11
|
+
const utils_js_1 = require("../utils.js");
|
|
12
|
+
const { isPlainObject } = lodash_1.default;
|
|
13
|
+
/**
|
|
14
|
+
* @access private
|
|
15
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {object} DateObjectConfigOptions
|
|
19
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
20
|
+
* @property {object} [afterOffsetFromNow] Offset from now
|
|
21
|
+
* @property {ErrorMessageConfig} [errorMsgAfterOffset] Error if date is after this offset
|
|
22
|
+
* @property {object} [beforeOffsetFromNow] Offset from now
|
|
23
|
+
* @property {ErrorMessageConfig} [errorMsgBeforeOffset] Error if date is before this offset
|
|
24
|
+
* @property {boolean} [allowMonthNames=false] Allow "Jan", "January", etc
|
|
25
|
+
* @property {boolean} [allowSingleDigitDay=false] Allow "1" rather than "01"
|
|
26
|
+
* @property {boolean} [allowSingleDigitMonth=false] Allow "1" rather than "01"
|
|
27
|
+
* @property {DateTime} [now=false] Override the notion of "now" (useful for testing)
|
|
28
|
+
*/
|
|
7
29
|
/**
|
|
8
30
|
* Date object format:
|
|
9
31
|
* {
|
|
@@ -12,29 +34,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
34
|
* yyyy: <string>
|
|
13
35
|
* }.
|
|
14
36
|
*
|
|
15
|
-
* Note that the time part
|
|
16
|
-
*
|
|
37
|
+
* Note that the time part will be zero'ed, as we are only interested in the
|
|
38
|
+
* date component (minimum day resolution).
|
|
39
|
+
*
|
|
40
|
+
* See {@link DateObjectConfigOptions} for `make()` options.
|
|
17
41
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* object|luxon.Duration afterOffsetFromNow = Date must be after offset from now
|
|
21
|
-
* string|object errorMsgAfterOffset = Error for afterOffsetFromNow failure
|
|
22
|
-
* object|luxon.Duration beforeOffsetFromNow = Date must be before offset from now
|
|
23
|
-
* string|object errorMsgBeforeOffset = Error for beforeOffsetFromNow failure
|
|
24
|
-
* bool allowMonthNames = Allow "Jan", "January", etc (default = false)
|
|
25
|
-
* bool allowSingleDigitDay = Allow "1" rather than "01" (default = false)
|
|
26
|
-
* bool allowSingleDigitMonth = Allow "1" rather than "01" (default = false)
|
|
27
|
-
* luxon.DateTime now = Override the notion of "now" (useful for testing)
|
|
42
|
+
* @memberof Validators
|
|
43
|
+
* @augments ValidatorFactory
|
|
28
44
|
*/
|
|
29
|
-
const luxon_1 = require("luxon");
|
|
30
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
31
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
32
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
33
|
-
const utils_js_1 = require("../utils.js");
|
|
34
|
-
const { isPlainObject } = lodash_1.default;
|
|
35
45
|
class DateObject extends ValidatorFactory_js_1.default {
|
|
36
46
|
constructor() {
|
|
37
47
|
super(...arguments);
|
|
48
|
+
/** @property {string} name Validator name ("dateObject") */
|
|
38
49
|
this.name = 'dateObject';
|
|
39
50
|
}
|
|
40
51
|
validate(value, dataContext = {}) {
|
|
@@ -1,6 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} EmailConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Email address.
|
|
11
|
+
*
|
|
12
|
+
* This is not an exhaustive validation, and is permissive.
|
|
13
|
+
*
|
|
14
|
+
* See {@link EmailConfigOptions} for `make()` options.
|
|
15
|
+
*
|
|
16
|
+
* @memberof Validators
|
|
17
|
+
* @augments ValidatorFactory
|
|
18
|
+
*/
|
|
1
19
|
export default class Email extends ValidatorFactory {
|
|
20
|
+
/** @property {string} name Validator name ("email") */
|
|
2
21
|
name: string;
|
|
3
|
-
validate(value: any, dataContext?: {}):
|
|
22
|
+
validate(value: any, dataContext?: {}): ValidationError[];
|
|
4
23
|
sanitise(value: any): string | undefined;
|
|
5
24
|
}
|
|
25
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
26
|
+
export type EmailConfigOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* Error message config
|
|
29
|
+
*/
|
|
30
|
+
errorMsg: ErrorMessageConfig;
|
|
31
|
+
};
|
|
6
32
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
33
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable class-methods-use-this */
|
|
3
|
-
/**
|
|
4
|
-
* Email address.
|
|
5
|
-
*
|
|
6
|
-
* This is not an exhaustive validation, and is permissive.
|
|
7
|
-
*
|
|
8
|
-
* Config options:
|
|
9
|
-
* string|object errorMsg = Error message to use on validation failure
|
|
10
|
-
*/
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/* eslint-disable class-methods-use-this */
|
|
15
7
|
const validator_1 = __importDefault(require("validator"));
|
|
16
8
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
17
9
|
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
18
10
|
const utils_js_1 = require("../utils.js");
|
|
19
11
|
const { isEmail } = validator_1.default; // CommonJS
|
|
12
|
+
/**
|
|
13
|
+
* @access private
|
|
14
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} EmailConfigOptions
|
|
18
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Email address.
|
|
22
|
+
*
|
|
23
|
+
* This is not an exhaustive validation, and is permissive.
|
|
24
|
+
*
|
|
25
|
+
* See {@link EmailConfigOptions} for `make()` options.
|
|
26
|
+
*
|
|
27
|
+
* @memberof Validators
|
|
28
|
+
* @augments ValidatorFactory
|
|
29
|
+
*/
|
|
20
30
|
class Email extends ValidatorFactory_js_1.default {
|
|
21
31
|
constructor() {
|
|
22
32
|
super(...arguments);
|
|
33
|
+
/** @property {string} name Validator name ("email") */
|
|
23
34
|
this.name = 'email';
|
|
24
35
|
}
|
|
25
36
|
validate(value, dataContext = {}) {
|
|
@@ -1,6 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} ArrayConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
|
+
* @property {string[]} source Array of values to test against
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Test if a value is present in an array.
|
|
12
|
+
*
|
|
13
|
+
* If the value itself is an array, all values within that array must be present
|
|
14
|
+
* in the `source` array in order to pass validation.
|
|
15
|
+
*
|
|
16
|
+
* See {@link ArrayConfigOptions} for `make()` options.
|
|
17
|
+
*
|
|
18
|
+
* @memberof Validators
|
|
19
|
+
* @augments ValidatorFactory
|
|
20
|
+
*/
|
|
1
21
|
export default class InArray extends ValidatorFactory {
|
|
22
|
+
/** @property {string} name Validator name ("inArray") */
|
|
2
23
|
name: string;
|
|
3
|
-
validate(value: any, dataContext?: {}):
|
|
24
|
+
validate(value: any, dataContext?: {}): ValidationError[];
|
|
4
25
|
sanitise(value: any): string | string[] | undefined;
|
|
5
26
|
}
|
|
27
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
28
|
+
export type ArrayConfigOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Error message config
|
|
31
|
+
*/
|
|
32
|
+
errorMsg: ErrorMessageConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Array of values to test against
|
|
35
|
+
*/
|
|
36
|
+
source: string[];
|
|
37
|
+
};
|
|
6
38
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
39
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -16,9 +16,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
17
17
|
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
18
18
|
const utils_js_1 = require("../utils.js");
|
|
19
|
+
/**
|
|
20
|
+
* @access private
|
|
21
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {object} ArrayConfigOptions
|
|
25
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
26
|
+
* @property {string[]} source Array of values to test against
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Test if a value is present in an array.
|
|
30
|
+
*
|
|
31
|
+
* If the value itself is an array, all values within that array must be present
|
|
32
|
+
* in the `source` array in order to pass validation.
|
|
33
|
+
*
|
|
34
|
+
* See {@link ArrayConfigOptions} for `make()` options.
|
|
35
|
+
*
|
|
36
|
+
* @memberof Validators
|
|
37
|
+
* @augments ValidatorFactory
|
|
38
|
+
*/
|
|
19
39
|
class InArray extends ValidatorFactory_js_1.default {
|
|
20
40
|
constructor() {
|
|
21
41
|
super(...arguments);
|
|
42
|
+
/** @property {string} name Validator name ("inArray") */
|
|
22
43
|
this.name = 'inArray';
|
|
23
44
|
}
|
|
24
45
|
validate(value, dataContext = {}) {
|
|
@@ -12,6 +12,9 @@ const regex_js_1 = __importDefault(require("./regex.js"));
|
|
|
12
12
|
const required_js_1 = __importDefault(require("./required.js"));
|
|
13
13
|
const strlen_js_1 = __importDefault(require("./strlen.js"));
|
|
14
14
|
const wordCount_js_1 = __importDefault(require("./wordCount.js"));
|
|
15
|
+
/**
|
|
16
|
+
* @namespace Validators
|
|
17
|
+
*/
|
|
15
18
|
exports.default = {
|
|
16
19
|
dateObject: dateObject_js_1.default,
|
|
17
20
|
email: email_js_1.default,
|
|
@@ -1,6 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} NinoConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
8
|
+
* @property {boolean} allowWhitespace Will permit input values that contain spaces.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* UK National Insurance number.
|
|
12
|
+
*
|
|
13
|
+
* Ref:
|
|
14
|
+
* https://en.wikipedia.org/wiki/National_Insurance_number#Format
|
|
15
|
+
* https://design-system.service.gov.uk/patterns/national-insurance-numbers/
|
|
16
|
+
*
|
|
17
|
+
* See {@link NinoConfigOptions} for `make()` options.
|
|
18
|
+
*
|
|
19
|
+
* @memberof Validators
|
|
20
|
+
* @augments ValidatorFactory
|
|
21
|
+
*/
|
|
1
22
|
export default class Nino extends ValidatorFactory {
|
|
2
23
|
name: string;
|
|
3
|
-
validate(value: any, dataContext?: {}):
|
|
24
|
+
validate(value: any, dataContext?: {}): ValidationError[];
|
|
4
25
|
sanitise(value: any): string | undefined;
|
|
5
26
|
}
|
|
27
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
28
|
+
export type NinoConfigOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Error message config
|
|
31
|
+
*/
|
|
32
|
+
errorMsg: ErrorMessageConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Will permit input values that contain spaces.
|
|
35
|
+
*/
|
|
36
|
+
allowWhitespace: boolean;
|
|
37
|
+
};
|
|
6
38
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
39
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -4,20 +4,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable class-methods-use-this */
|
|
7
|
+
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
8
|
+
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
9
|
+
const utils_js_1 = require("../utils.js");
|
|
10
|
+
/**
|
|
11
|
+
* @access private
|
|
12
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} NinoConfigOptions
|
|
16
|
+
* @property {ErrorMessageConfig} errorMsg Error message config
|
|
17
|
+
* @property {boolean} allowWhitespace Will permit input values that contain spaces.
|
|
18
|
+
*/
|
|
7
19
|
/**
|
|
8
20
|
* UK National Insurance number.
|
|
9
21
|
*
|
|
10
|
-
* Config options:
|
|
11
|
-
* string|object errorMsg = Error message to use on validation failure
|
|
12
|
-
* boolean allowWhitespace = will permit input values that contain spaces.
|
|
13
|
-
*
|
|
14
22
|
* Ref:
|
|
15
23
|
* https://en.wikipedia.org/wiki/National_Insurance_number#Format
|
|
16
24
|
* https://design-system.service.gov.uk/patterns/national-insurance-numbers/
|
|
25
|
+
*
|
|
26
|
+
* See {@link NinoConfigOptions} for `make()` options.
|
|
27
|
+
*
|
|
28
|
+
* @memberof Validators
|
|
29
|
+
* @augments ValidatorFactory
|
|
17
30
|
*/
|
|
18
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
19
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
20
|
-
const utils_js_1 = require("../utils.js");
|
|
21
31
|
class Nino extends ValidatorFactory_js_1.default {
|
|
22
32
|
constructor() {
|
|
23
33
|
super(...arguments);
|
|
@@ -1,5 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} PostalAddressObjectConfigOptions
|
|
7
|
+
* @property {ErrorMessageConfig} [errorMsg] General error message for the entire address block
|
|
8
|
+
* @property {string|object} [errorMsgAddress1] Error message for address1 part
|
|
9
|
+
* @property {string|object} [errorMsgAddress2] Error message for address2 part
|
|
10
|
+
* @property {string|object} [errorMsgAddress3] Error message for address3 part
|
|
11
|
+
* @property {string|object} [errorMsgAddress4] Error message for address4 part
|
|
12
|
+
* @property {string|object} [errorMsgPostcode] Error message for postcode part
|
|
13
|
+
* @property {number} [strlenmax] Max. String length for each of the inputs appress[1-4]
|
|
14
|
+
* @property {string[]} [requiredFields] Field parts required (others become optional). One of
|
|
15
|
+
* 'address1'|'address2'|'address3'|'address4'|'postcode'
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Works hand in hand with the core CASA `postalAddressObject` form
|
|
19
|
+
* macro.
|
|
20
|
+
*
|
|
21
|
+
* The errors sent back from this validator are specific to each subfield. For
|
|
22
|
+
* example, if the field name being tested is "address", any errors related to
|
|
23
|
+
* the "postcode" component would be associated with "address[postcode]".
|
|
24
|
+
*
|
|
25
|
+
* See {@link PostalAddressObjectConfigOptions} for `make()` options.
|
|
26
|
+
*
|
|
27
|
+
* @memberof Validators
|
|
28
|
+
* @augments ValidatorFactory
|
|
29
|
+
*/
|
|
1
30
|
export default class PostalAddressObject extends ValidatorFactory {
|
|
2
31
|
name: string;
|
|
3
|
-
validate(value: any, dataContext?: {}):
|
|
32
|
+
validate(value: any, dataContext?: {}): ValidationError[];
|
|
33
|
+
sanitise(value: any): any;
|
|
4
34
|
}
|
|
35
|
+
export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
|
|
36
|
+
export type PostalAddressObjectConfigOptions = {
|
|
37
|
+
/**
|
|
38
|
+
* General error message for the entire address block
|
|
39
|
+
*/
|
|
40
|
+
errorMsg?: import("../../casa").ErrorMessageConfig | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Error message for address1 part
|
|
43
|
+
*/
|
|
44
|
+
errorMsgAddress1?: string | object | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Error message for address2 part
|
|
47
|
+
*/
|
|
48
|
+
errorMsgAddress2?: string | object | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Error message for address3 part
|
|
51
|
+
*/
|
|
52
|
+
errorMsgAddress3?: string | object | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Error message for address4 part
|
|
55
|
+
*/
|
|
56
|
+
errorMsgAddress4?: string | object | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Error message for postcode part
|
|
59
|
+
*/
|
|
60
|
+
errorMsgPostcode?: string | object | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Max. String length for each of the inputs appress[1-4]
|
|
63
|
+
*/
|
|
64
|
+
strlenmax?: number | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Field parts required (others become optional). One of
|
|
67
|
+
* 'address1'|'address2'|'address3'|'address4'|'postcode'
|
|
68
|
+
*/
|
|
69
|
+
requiredFields?: string[] | undefined;
|
|
70
|
+
};
|
|
5
71
|
import ValidatorFactory from "../ValidatorFactory.js";
|
|
72
|
+
import ValidationError from "../ValidationError.js";
|
|
@@ -4,28 +4,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
/* eslint-disable class-methods-use-this */
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
9
|
+
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
10
|
+
const utils_js_1 = require("../utils.js");
|
|
11
|
+
const { isPlainObject } = lodash_1.default; // CommonjS
|
|
12
|
+
/**
|
|
13
|
+
* @access private
|
|
14
|
+
* @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
15
|
+
*/
|
|
7
16
|
/**
|
|
8
|
-
*
|
|
17
|
+
* @typedef {object} PostalAddressObjectConfigOptions
|
|
18
|
+
* @property {ErrorMessageConfig} [errorMsg] General error message for the entire address block
|
|
19
|
+
* @property {string|object} [errorMsgAddress1] Error message for address1 part
|
|
20
|
+
* @property {string|object} [errorMsgAddress2] Error message for address2 part
|
|
21
|
+
* @property {string|object} [errorMsgAddress3] Error message for address3 part
|
|
22
|
+
* @property {string|object} [errorMsgAddress4] Error message for address4 part
|
|
23
|
+
* @property {string|object} [errorMsgPostcode] Error message for postcode part
|
|
24
|
+
* @property {number} [strlenmax] Max. String length for each of the inputs appress[1-4]
|
|
25
|
+
* @property {string[]} [requiredFields] Field parts required (others become optional). One of
|
|
26
|
+
* 'address1'|'address2'|'address3'|'address4'|'postcode'
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Works hand in hand with the core CASA `postalAddressObject` form
|
|
30
|
+
* macro.
|
|
9
31
|
*
|
|
10
32
|
* The errors sent back from this validator are specific to each subfield. For
|
|
11
33
|
* example, if the field name being tested is "address", any errors related to
|
|
12
34
|
* the "postcode" component would be associated with "address[postcode]".
|
|
13
35
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* string|object errorMsgAddress3 = Error message for address3 part
|
|
19
|
-
* string|object errorMsgAddress4 = Error message for address4 part
|
|
20
|
-
* string|object errorMsgPostcode = Error message for postcode part
|
|
21
|
-
* int strlenmax = Max. String length for each of the inputs appress[1-4]
|
|
22
|
-
* array requiredFields = Field parts required (others become optional)
|
|
36
|
+
* See {@link PostalAddressObjectConfigOptions} for `make()` options.
|
|
37
|
+
*
|
|
38
|
+
* @memberof Validators
|
|
39
|
+
* @augments ValidatorFactory
|
|
23
40
|
*/
|
|
24
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
25
|
-
const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
|
|
26
|
-
const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
|
|
27
|
-
const utils_js_1 = require("../utils.js");
|
|
28
|
-
const { isPlainObject } = lodash_1.default; // CommonjS
|
|
29
41
|
class PostalAddressObject extends ValidatorFactory_js_1.default {
|
|
30
42
|
constructor() {
|
|
31
43
|
super(...arguments);
|