@dwp/govuk-casa 8.2.3 → 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.
Files changed (65) hide show
  1. package/README.md +1 -0
  2. package/dist/casa.d.ts +198 -0
  3. package/dist/casa.js +129 -0
  4. package/dist/lib/CasaTemplateLoader.d.ts +4 -0
  5. package/dist/lib/CasaTemplateLoader.js +5 -0
  6. package/dist/lib/JourneyContext.d.ts +85 -13
  7. package/dist/lib/JourneyContext.js +78 -5
  8. package/dist/lib/Plan.d.ts +122 -49
  9. package/dist/lib/Plan.js +161 -37
  10. package/dist/lib/ValidationError.d.ts +38 -48
  11. package/dist/lib/ValidationError.js +30 -42
  12. package/dist/lib/ValidatorFactory.d.ts +42 -52
  13. package/dist/lib/ValidatorFactory.js +37 -48
  14. package/dist/lib/configuration-ingestor.d.ts +15 -0
  15. package/dist/lib/configuration-ingestor.js +17 -0
  16. package/dist/lib/configure.d.ts +4 -0
  17. package/dist/lib/configure.js +14 -1
  18. package/dist/lib/end-session.d.ts +3 -2
  19. package/dist/lib/end-session.js +2 -1
  20. package/dist/lib/field.d.ts +97 -35
  21. package/dist/lib/field.js +90 -41
  22. package/dist/lib/nunjucks-filters.d.ts +12 -2
  23. package/dist/lib/nunjucks-filters.js +11 -1
  24. package/dist/lib/nunjucks.d.ts +1 -0
  25. package/dist/lib/nunjucks.js +1 -0
  26. package/dist/lib/utils.d.ts +46 -14
  27. package/dist/lib/utils.js +43 -26
  28. package/dist/lib/validators/dateObject.d.ts +75 -1
  29. package/dist/lib/validators/dateObject.js +29 -18
  30. package/dist/lib/validators/email.d.ts +28 -1
  31. package/dist/lib/validators/email.js +20 -9
  32. package/dist/lib/validators/inArray.d.ts +34 -1
  33. package/dist/lib/validators/inArray.js +21 -0
  34. package/dist/lib/validators/index.js +3 -0
  35. package/dist/lib/validators/nino.d.ts +34 -1
  36. package/dist/lib/validators/nino.js +17 -7
  37. package/dist/lib/validators/postalAddressObject.d.ts +68 -1
  38. package/dist/lib/validators/postalAddressObject.js +27 -15
  39. package/dist/lib/validators/regex.d.ts +35 -1
  40. package/dist/lib/validators/regex.js +17 -7
  41. package/dist/lib/validators/required.d.ts +28 -1
  42. package/dist/lib/validators/required.js +19 -6
  43. package/dist/lib/validators/strlen.d.ts +40 -1
  44. package/dist/lib/validators/strlen.js +18 -8
  45. package/dist/lib/validators/wordCount.d.ts +40 -1
  46. package/dist/lib/validators/wordCount.js +18 -8
  47. package/dist/lib/waypoint-url.d.ts +1 -0
  48. package/dist/lib/waypoint-url.js +10 -0
  49. package/dist/middleware/data.js +21 -5
  50. package/dist/middleware/gather-fields.js +1 -0
  51. package/dist/middleware/pre.js +1 -0
  52. package/dist/middleware/steer-journey.js +2 -1
  53. package/dist/middleware/strip-proxy-path.js +6 -2
  54. package/dist/middleware/validate-fields.js +3 -0
  55. package/dist/routes/ancillary.d.ts +16 -5
  56. package/dist/routes/ancillary.js +7 -3
  57. package/dist/routes/journey.d.ts +30 -6
  58. package/dist/routes/journey.js +27 -0
  59. package/dist/routes/static.d.ts +1 -0
  60. package/dist/routes/static.js +2 -1
  61. package/package.json +16 -11
  62. package/views/casa/components/character-count/README.md +1 -1
  63. package/views/casa/components/input/README.md +1 -1
  64. package/views/casa/components/radios/README.md +2 -2
  65. package/views/casa/components/textarea/README.md +1 -1
@@ -33,6 +33,14 @@ function mergeObjects(...objects) {
33
33
  return deepmergeAll([Object.create(null), ...objects], { arrayMerge: combineMerge });
34
34
  }
35
35
  exports.mergeObjects = mergeObjects;
36
+ /**
37
+ * Determine whether a value exists in a list.
38
+ *
39
+ * @memberof NunjucksFilters
40
+ * @param {any[]} source List of items to search
41
+ * @param {any} search Item to search within the `source`
42
+ * @returns {boolean} True if the search item was found
43
+ */
36
44
  function includes(source = [], search = '') {
37
45
  return source.includes(search);
38
46
  }
@@ -45,6 +53,7 @@ exports.includes = includes;
45
53
  * `date` may be any of the following types:
46
54
  * object - {dd:'', mm:'', yyyy:''}
47
55
  *
56
+ * @memberof NunjucksFilters
48
57
  * @param {object} date Date (see supported formats above)
49
58
  * @param {object} config Holds locale
50
59
  * @returns {string} Formatted date
@@ -71,7 +80,8 @@ exports.formatDateObject = formatDateObject;
71
80
  * Given: {class: 'basic', 'data-ga': 3}
72
81
  * Output: class="basic" data-ga="3"
73
82
  *
74
- * @param {object} attrsObject Attributes object (in name:value pairs)
83
+ * @memberof NunjucksFilters
84
+ * @param {object} attrsObject Attributes object (in name:value pairs)
75
85
  * @returns {string} Formatted
76
86
  */
77
87
  function renderAsAttributes(attrsObject) {
@@ -5,6 +5,7 @@
5
5
  /**
6
6
  * Create a Nunjucks environment.
7
7
  *
8
+ * @access private
8
9
  * @param {NunjucksOptions} options Nunjucks options
9
10
  * @returns {Environment} Nunjucks Environment instance
10
11
  */
@@ -16,6 +16,7 @@ const nunjucks_filters_js_1 = require("./nunjucks-filters.js");
16
16
  /**
17
17
  * Create a Nunjucks environment.
18
18
  *
19
+ * @access private
19
20
  * @param {NunjucksOptions} options Nunjucks options
20
21
  * @returns {Environment} Nunjucks Environment instance
21
22
  */
@@ -1,9 +1,11 @@
1
1
  /**
2
+ * @access private
2
3
  * @typedef {import('../casa').GlobalHook | import('../casa').PageHook} Hook
3
4
  */
4
5
  /**
5
6
  * Test is a value can be stringifed (numbers or strings)
6
7
  *
8
+ * @access private
7
9
  * @param {any} value Item to test
8
10
  * @returns {boolean} Whether the value is stringable or not
9
11
  */
@@ -11,6 +13,7 @@ export function isStringable(value: any): boolean;
11
13
  /**
12
14
  * Coerce an input to a string.
13
15
  *
16
+ * @access private
14
17
  * @param {any} input Input to be stringified
15
18
  * @param {string} fallback Fallback to use if input can't be stringified
16
19
  * @returns {string} The stringified input
@@ -19,6 +22,7 @@ export function stringifyInput(input: any, fallback: string, ...args: any[]): st
19
22
  /**
20
23
  * Determine if value is empty. Recurse over objects.
21
24
  *
25
+ * @access private
22
26
  * @param {any} val Value to check
23
27
  * @returns {boolean} True if the object is empty
24
28
  */
@@ -27,33 +31,61 @@ export function isEmpty(val: any): boolean;
27
31
  * Extract the middleware functions that are relevant for the given hook and
28
32
  * path.
29
33
  *
34
+ * @access private
30
35
  * @param {string} hookName Hook name (including scope prefix)
31
36
  * @param {string} path URL path to match (relative to mountUrl)
32
37
  * @param {Hook[]} hooks Hooks to be applied at the page level
33
38
  * @returns {Function[]} An array of middleware that should be applied
34
39
  */
35
40
  export function resolveMiddlewareHooks(hookName: string, path: string, hooks?: Hook[]): Function[];
36
- export function validateWaypoint(waypoint: any): void;
37
- export function validateUrlPath(path: any): string;
38
- export function validateView(view: any): void;
39
- export function validateHookName(hookName: any): void;
41
+ /**
42
+ * Validate a waypoint.
43
+ *
44
+ * @access private
45
+ * @param {string} waypoint Waypoint
46
+ * @returns {void}
47
+ * @throws {TypeError}
48
+ * @throws {SyntaxError}
49
+ */
50
+ export function validateWaypoint(waypoint: string): void;
51
+ /**
52
+ * Validate a URL path.
53
+ *
54
+ * @access private
55
+ * @param {string} path URL path
56
+ * @returns {string} Same string, if valid
57
+ * @throws {TypeError}
58
+ * @throws {SyntaxError}
59
+ */
60
+ export function validateUrlPath(path: string): string;
61
+ /**
62
+ * Validate a template name.
63
+ *
64
+ * @access private
65
+ * @param {string} view Template name
66
+ * @returns {void}
67
+ * @throws {TypeError}
68
+ * @throws {SyntaxError}
69
+ */
70
+ export function validateView(view: string): void;
71
+ /**
72
+ * Validate a hook name.
73
+ *
74
+ * @access private
75
+ * @param {string} hookName Hook name
76
+ * @returns {void}
77
+ * @throws {TypeError}
78
+ * @throws {SyntaxError}
79
+ */
80
+ export function validateHookName(hookName: string): void;
40
81
  export function validateHookPath(path: any): void;
41
82
  /**
42
83
  * Checks if the given string can be used as an object key.
43
84
  *
85
+ * @access private
44
86
  * @param {string} key Proposed Object key
45
87
  * @returns {string} Same key if it's valid
46
88
  * @throws {Error} if proposed key is an invalid keyword
47
89
  */
48
90
  export function notProto(key: string): string;
49
- /**
50
- * Remove any path segments from the URL that are present in the `mountpath`,
51
- * but not in the `baseUrl`. Those segments are considered to be part of an
52
- * internal proxying arrangement, and should not be used by CASA.
53
- *
54
- * @param {import('express').Request} req Express request
55
- * @throws {Error} When multiple mountpaths are present
56
- * @returns {string} URL path with any proxy prefixes removed
57
- */
58
- export function stripProxyFromUrlPath(req: import('express').Request): string;
59
91
  export type Hook = import('../casa').GlobalHook | import('../casa').PageHook;
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.stripProxyFromUrlPath = exports.notProto = exports.validateHookPath = exports.validateHookName = exports.validateView = exports.validateUrlPath = exports.validateWaypoint = exports.resolveMiddlewareHooks = exports.isEmpty = exports.stringifyInput = exports.isStringable = void 0;
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?: {}): object[];
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 of any injected "DateTime" objects will be zero'ed, as
16
- * we are only interested in the date component (minimum day resolution).
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
- * Config options:
19
- * string|object errorMsg = Error message to use on validation failure
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?: {}): object[];
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?: {}): object[];
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?: {}): object[];
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);