@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.
- package/README.md +1 -0
- package/dist/casa.d.ts +198 -0
- package/dist/casa.js +129 -0
- 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 +15 -0
- package/dist/lib/configuration-ingestor.js +17 -0
- package/dist/lib/configure.d.ts +4 -0
- package/dist/lib/configure.js +14 -1
- 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.js +6 -2
- 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
|
@@ -1,65 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../casa').ValidateContext} ValidateContext
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @access private
|
|
7
|
+
* @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @access private
|
|
11
|
+
* @typedef {import('../casa').ErrorMessageConfigObject} ErrorMessageConfigObject
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @class
|
|
15
|
+
* @memberof module:@dwp/govuk-casa
|
|
3
16
|
*/
|
|
4
17
|
export default class ValidationError {
|
|
5
18
|
/**
|
|
6
19
|
* Make a ValidationError instance from a primitive object (or a function that
|
|
7
20
|
* returns a primitive object) that is specific to the given journey context.
|
|
21
|
+
* <br/><br/>
|
|
8
22
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* String => 'common:errors.my-error-message'
|
|
14
|
-
* Object => (see constructor argument for structure of this object)
|
|
15
|
-
* Function => Function returns object suitable for constructor (see example below)
|
|
16
|
-
* Error => A JavaScript error. It's `message` will be used as the error.
|
|
17
|
-
*
|
|
18
|
-
* `dataContext` is an object containing the same data passed to all validator
|
|
19
|
-
* functions, and contains:
|
|
20
|
-
* waypointId => The current waypoint being requested
|
|
21
|
-
* fieldName => Name of the field being validated
|
|
22
|
-
* journeyContext => The full JourneyContext of the current request.
|
|
23
|
+
* In the case of `errorMsg` being a function, this will be called at runtime,
|
|
24
|
+
* at the point that errors are generated within the `validate()`,
|
|
25
|
+
* methods, and will be passed the `dataContext`.
|
|
26
|
+
* <br/><br/>
|
|
23
27
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* name: journeyContext.getDataForPage(waypointId).name,
|
|
29
|
-
* }
|
|
30
|
-
* });
|
|
28
|
+
* `dataContext` is an object containing the same data passed to all
|
|
29
|
+
* validators' `validate()` methods. In the case of `errorMsg` being
|
|
30
|
+
* a function, this data is passed to that function in order to help resolve to
|
|
31
|
+
* an error message config object.
|
|
31
32
|
*
|
|
32
|
-
* @param {object} args
|
|
33
|
-
* @param {
|
|
34
|
-
* @param {
|
|
35
|
-
* @returns {
|
|
33
|
+
* @param {object} args Arguments
|
|
34
|
+
* @param {ErrorMessageConfig} args.errorMsg Error message config to seed ValidationError
|
|
35
|
+
* @param {ValidateContext} [args.dataContext={}] Data for error msg function
|
|
36
|
+
* @returns {ValidationError} Error instance
|
|
36
37
|
* @throws {TypeError} If errorMsg is not in a valid type
|
|
37
38
|
*/
|
|
38
39
|
static make({ errorMsg, dataContext }: {
|
|
39
|
-
errorMsg:
|
|
40
|
-
dataContext
|
|
41
|
-
}):
|
|
40
|
+
errorMsg: ErrorMessageConfig;
|
|
41
|
+
dataContext?: import("../casa").ValidateContext | undefined;
|
|
42
|
+
}): ValidationError;
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
-
* error mesaage (equivalent to `error.summary` in the structure below).
|
|
45
|
-
*
|
|
46
|
-
* `error`, when passed as an object, must match this structure:
|
|
47
|
-
*
|
|
48
|
-
* {
|
|
49
|
-
* summary: "", // required
|
|
50
|
-
* inline: "", // optional, may be deprecated in future
|
|
51
|
-
* focusSuffix: "", // optional
|
|
52
|
-
* fieldKeySuffix: "", // optional
|
|
53
|
-
* variables: { // optional
|
|
54
|
-
* myVariable: 'a value'
|
|
55
|
-
* }
|
|
56
|
-
* }
|
|
44
|
+
* Create a ValidationError.
|
|
57
45
|
*
|
|
58
|
-
* @param {
|
|
46
|
+
* @param {string|ErrorMessageConfigObject} errorParam Error configuration
|
|
59
47
|
*/
|
|
60
|
-
constructor(errorParam?:
|
|
48
|
+
constructor(errorParam?: string | ErrorMessageConfigObject);
|
|
61
49
|
/**
|
|
62
|
-
* Modifies
|
|
50
|
+
* Modifies this instance to reflect the given validation context.
|
|
63
51
|
*
|
|
64
52
|
* @param {ValidateContext} context See structure above
|
|
65
53
|
* @returns {ValidationError} Chain
|
|
@@ -69,6 +57,8 @@ export default class ValidationError {
|
|
|
69
57
|
field: string | undefined;
|
|
70
58
|
fieldHref: string | undefined;
|
|
71
59
|
focusSuffix: any;
|
|
72
|
-
validator:
|
|
60
|
+
validator: string | undefined;
|
|
73
61
|
}
|
|
74
|
-
export type ValidateContext = import('
|
|
62
|
+
export type ValidateContext = import('../casa').ValidateContext;
|
|
63
|
+
export type ErrorMessageConfig = import('../casa').ErrorMessageConfig;
|
|
64
|
+
export type ErrorMessageConfigObject = import('../casa').ErrorMessageConfigObject;
|
|
@@ -7,40 +7,41 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
7
7
|
const { isPlainObject } = lodash_1.default; // CommonJS
|
|
8
8
|
const params = new WeakMap();
|
|
9
9
|
/**
|
|
10
|
-
* @
|
|
10
|
+
* @access private
|
|
11
|
+
* @typedef {import('../casa').ValidateContext} ValidateContext
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @access private
|
|
15
|
+
* @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @access private
|
|
19
|
+
* @typedef {import('../casa').ErrorMessageConfigObject} ErrorMessageConfigObject
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @class
|
|
23
|
+
* @memberof module:@dwp/govuk-casa
|
|
11
24
|
*/
|
|
12
25
|
class ValidationError {
|
|
13
26
|
/**
|
|
14
27
|
* Make a ValidationError instance from a primitive object (or a function that
|
|
15
28
|
* returns a primitive object) that is specific to the given journey context.
|
|
29
|
+
* <br/><br/>
|
|
16
30
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* String => 'common:errors.my-error-message'
|
|
22
|
-
* Object => (see constructor argument for structure of this object)
|
|
23
|
-
* Function => Function returns object suitable for constructor (see example below)
|
|
24
|
-
* Error => A JavaScript error. It's `message` will be used as the error.
|
|
25
|
-
*
|
|
26
|
-
* `dataContext` is an object containing the same data passed to all validator
|
|
27
|
-
* functions, and contains:
|
|
28
|
-
* waypointId => The current waypoint being requested
|
|
29
|
-
* fieldName => Name of the field being validated
|
|
30
|
-
* journeyContext => The full JourneyContext of the current request.
|
|
31
|
+
* In the case of `errorMsg` being a function, this will be called at runtime,
|
|
32
|
+
* at the point that errors are generated within the `validate()`,
|
|
33
|
+
* methods, and will be passed the `dataContext`.
|
|
34
|
+
* <br/><br/>
|
|
31
35
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* name: journeyContext.getDataForPage(waypointId).name,
|
|
37
|
-
* }
|
|
38
|
-
* });
|
|
36
|
+
* `dataContext` is an object containing the same data passed to all
|
|
37
|
+
* validators' `validate()` methods. In the case of `errorMsg` being
|
|
38
|
+
* a function, this data is passed to that function in order to help resolve to
|
|
39
|
+
* an error message config object.
|
|
39
40
|
*
|
|
40
|
-
* @param {object} args
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {
|
|
43
|
-
* @returns {
|
|
41
|
+
* @param {object} args Arguments
|
|
42
|
+
* @param {ErrorMessageConfig} args.errorMsg Error message config to seed ValidationError
|
|
43
|
+
* @param {ValidateContext} [args.dataContext={}] Data for error msg function
|
|
44
|
+
* @returns {ValidationError} Error instance
|
|
44
45
|
* @throws {TypeError} If errorMsg is not in a valid type
|
|
45
46
|
*/
|
|
46
47
|
static make({ errorMsg, dataContext = {} }) {
|
|
@@ -74,22 +75,9 @@ class ValidationError {
|
|
|
74
75
|
throw new TypeError('errorMsg must be a string, Error, primitive object or function that generates a primitive object');
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
|
-
*
|
|
78
|
-
* error mesaage (equivalent to `error.summary` in the structure below).
|
|
79
|
-
*
|
|
80
|
-
* `error`, when passed as an object, must match this structure:
|
|
81
|
-
*
|
|
82
|
-
* {
|
|
83
|
-
* summary: "", // required
|
|
84
|
-
* inline: "", // optional, may be deprecated in future
|
|
85
|
-
* focusSuffix: "", // optional
|
|
86
|
-
* fieldKeySuffix: "", // optional
|
|
87
|
-
* variables: { // optional
|
|
88
|
-
* myVariable: 'a value'
|
|
89
|
-
* }
|
|
90
|
-
* }
|
|
78
|
+
* Create a ValidationError.
|
|
91
79
|
*
|
|
92
|
-
* @param {
|
|
80
|
+
* @param {string|ErrorMessageConfigObject} errorParam Error configuration
|
|
93
81
|
*/
|
|
94
82
|
constructor(errorParam = {}) {
|
|
95
83
|
if (!isPlainObject(errorParam) && typeof errorParam !== 'string') {
|
|
@@ -126,7 +114,7 @@ class ValidationError {
|
|
|
126
114
|
});
|
|
127
115
|
}
|
|
128
116
|
/**
|
|
129
|
-
* Modifies
|
|
117
|
+
* Modifies this instance to reflect the given validation context.
|
|
130
118
|
*
|
|
131
119
|
* @param {ValidateContext} context See structure above
|
|
132
120
|
* @returns {ValidationError} Chain
|
|
@@ -1,83 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @access private
|
|
3
|
+
* @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
3
4
|
*/
|
|
4
5
|
/**
|
|
6
|
+
* @access private
|
|
5
7
|
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
6
8
|
*/
|
|
7
9
|
/**
|
|
10
|
+
* @access private
|
|
8
11
|
* @typedef {import('./index').ValidationError} ValidationError
|
|
9
12
|
*/
|
|
10
13
|
/**
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
13
|
-
* @property {ProcessorFunction} sanitise Sanitise a given value prior to validation
|
|
14
|
-
* @property {object} config Configuration
|
|
15
|
-
* @property {string} name Validator name
|
|
14
|
+
* @access private
|
|
15
|
+
* @typedef {import('../casa').ValidateContext} ValidateContext
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* @param {ValidateContext} context
|
|
21
|
-
* @returns {ValidationError[]}
|
|
18
|
+
* @access private
|
|
19
|
+
* @typedef {import('../casa').Validator} Validator
|
|
22
20
|
*/
|
|
23
21
|
/**
|
|
24
|
-
* @typedef {object}
|
|
25
|
-
* @property {
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
* @typedef {object} ValidatorFactoryOptions
|
|
23
|
+
* @property {ErrorMessageConfig} errorMsg Error message
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @class
|
|
27
|
+
* @memberof module:@dwp/govuk-casa
|
|
28
28
|
*/
|
|
29
29
|
export default class ValidatorFactory {
|
|
30
30
|
/**
|
|
31
31
|
* This is a convenience method that will return a consistently object
|
|
32
32
|
* structure containing validation and sanitisation methods.
|
|
33
33
|
*
|
|
34
|
-
* @param {
|
|
34
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
|
|
35
35
|
* @returns {Validator} Validator object
|
|
36
36
|
* @throws {TypeError} When configurarion is invalid.
|
|
37
37
|
*/
|
|
38
|
-
static make(config?:
|
|
39
|
-
static coerceToValidatorObject(input: any): any;
|
|
40
|
-
constructor(config?: {});
|
|
41
|
-
config: {};
|
|
42
|
-
validate(fieldValue: any, context: any): void;
|
|
43
|
-
sanitise(fieldValue: any): any;
|
|
44
|
-
}
|
|
45
|
-
export type ProcessorFunction = import('./index').ProcessorFunction;
|
|
46
|
-
export type JourneyContext = import('./index').JourneyContext;
|
|
47
|
-
export type ValidationError = import('./index').ValidationError;
|
|
48
|
-
export type Validator = {
|
|
49
|
-
/**
|
|
50
|
-
* Validation function
|
|
51
|
-
*/
|
|
52
|
-
validate: ValidateFunction;
|
|
53
|
-
/**
|
|
54
|
-
* Sanitise a given value prior to validation
|
|
55
|
-
*/
|
|
56
|
-
sanitise: any;
|
|
57
|
-
/**
|
|
58
|
-
* Configuration
|
|
59
|
-
*/
|
|
60
|
-
config: object;
|
|
38
|
+
static make(config?: ValidatorFactoryOptions): Validator;
|
|
61
39
|
/**
|
|
62
|
-
*
|
|
40
|
+
* NEVER CALL THIS DIRECTLY. USE `make()`.
|
|
41
|
+
*
|
|
42
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
|
|
63
43
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export type ValidateFunction = (value: any, context: ValidateContext) => ValidationError[];
|
|
67
|
-
/**
|
|
68
|
-
* Context passed to validate function
|
|
69
|
-
*/
|
|
70
|
-
export type ValidateContext = {
|
|
44
|
+
constructor(config?: ValidatorFactoryOptions);
|
|
45
|
+
config: ValidatorFactoryOptions;
|
|
71
46
|
/**
|
|
72
|
-
*
|
|
47
|
+
* Validate the given value.
|
|
48
|
+
*
|
|
49
|
+
* @param {any} fieldValue Value to validate
|
|
50
|
+
* @param {ValidateContext} context Contextual information
|
|
51
|
+
* @returns {ValidationError[]} A list of errors (empty if no errors found)
|
|
52
|
+
* @throws {Error}
|
|
73
53
|
*/
|
|
74
|
-
|
|
54
|
+
validate(fieldValue: any, context: ValidateContext): ValidationError[];
|
|
75
55
|
/**
|
|
76
|
-
*
|
|
56
|
+
* Sanitise the given value.
|
|
57
|
+
*
|
|
58
|
+
* @param {any} fieldValue Value to validate
|
|
59
|
+
* @returns {any} The sanitised value
|
|
77
60
|
*/
|
|
78
|
-
|
|
61
|
+
sanitise(fieldValue: any): any;
|
|
62
|
+
}
|
|
63
|
+
export type ErrorMessageConfig = import('../casa').ErrorMessageConfig;
|
|
64
|
+
export type JourneyContext = import('./index').JourneyContext;
|
|
65
|
+
export type ValidationError = import('./index').ValidationError;
|
|
66
|
+
export type ValidateContext = import('../casa').ValidateContext;
|
|
67
|
+
export type Validator = import('../casa').Validator;
|
|
68
|
+
export type ValidatorFactoryOptions = {
|
|
79
69
|
/**
|
|
80
|
-
*
|
|
70
|
+
* Error message
|
|
81
71
|
*/
|
|
82
|
-
|
|
72
|
+
errorMsg: ErrorMessageConfig;
|
|
83
73
|
};
|
|
@@ -7,39 +7,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const { isPlainObject } = lodash_1.default; // CommonJS
|
|
9
9
|
/**
|
|
10
|
-
* @
|
|
10
|
+
* @access private
|
|
11
|
+
* @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
|
|
11
12
|
*/
|
|
12
13
|
/**
|
|
14
|
+
* @access private
|
|
13
15
|
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
14
16
|
*/
|
|
15
17
|
/**
|
|
18
|
+
* @access private
|
|
16
19
|
* @typedef {import('./index').ValidationError} ValidationError
|
|
17
20
|
*/
|
|
18
21
|
/**
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
21
|
-
* @property {ProcessorFunction} sanitise Sanitise a given value prior to validation
|
|
22
|
-
* @property {object} config Configuration
|
|
23
|
-
* @property {string} name Validator name
|
|
22
|
+
* @access private
|
|
23
|
+
* @typedef {import('../casa').ValidateContext} ValidateContext
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
26
|
-
* @
|
|
27
|
-
* @
|
|
28
|
-
* @param {ValidateContext} context
|
|
29
|
-
* @returns {ValidationError[]}
|
|
26
|
+
* @access private
|
|
27
|
+
* @typedef {import('../casa').Validator} Validator
|
|
30
28
|
*/
|
|
31
29
|
/**
|
|
32
|
-
* @typedef {object}
|
|
33
|
-
* @property {
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
* @typedef {object} ValidatorFactoryOptions
|
|
31
|
+
* @property {ErrorMessageConfig} errorMsg Error message
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* @class
|
|
35
|
+
* @memberof module:@dwp/govuk-casa
|
|
36
36
|
*/
|
|
37
37
|
class ValidatorFactory {
|
|
38
38
|
/**
|
|
39
39
|
* This is a convenience method that will return a consistently object
|
|
40
40
|
* structure containing validation and sanitisation methods.
|
|
41
41
|
*
|
|
42
|
-
* @param {
|
|
42
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
|
|
43
43
|
* @returns {Validator} Validator object
|
|
44
44
|
* @throws {TypeError} When configurarion is invalid.
|
|
45
45
|
*/
|
|
@@ -57,48 +57,37 @@ class ValidatorFactory {
|
|
|
57
57
|
Object.freeze(instance);
|
|
58
58
|
return instance;
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// An uninstantied Validator subclass
|
|
66
|
-
if (typeof input === 'function' && Reflect.getPrototypeOf(input) === ValidatorFactory) {
|
|
67
|
-
validator = input.make();
|
|
68
|
-
}
|
|
69
|
-
else if (typeof input === 'function') {
|
|
70
|
-
// A plain function is assumed to be just the validation logic. We do not
|
|
71
|
-
// bind the function to `validator` here because it may already be bound to
|
|
72
|
-
// another context in userland.
|
|
73
|
-
validator.name = input.name || input.constructor.name || 'unknown';
|
|
74
|
-
validator.validate = input;
|
|
75
|
-
}
|
|
76
|
-
else if (isPlainObject(input)) {
|
|
77
|
-
// A plain object
|
|
78
|
-
validator = {
|
|
79
|
-
validate: input.validate || validator.validate,
|
|
80
|
-
sanitise: input.sanitise || validator.sanitise,
|
|
81
|
-
config: input.config || validator.config,
|
|
82
|
-
name: input.name || validator.name,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
// An unsupported scenario
|
|
87
|
-
throw new TypeError(`Cannot coerce input to a validator object (typeof = ${typeof input})`);
|
|
88
|
-
}
|
|
89
|
-
return validator;
|
|
90
|
-
}
|
|
60
|
+
/**
|
|
61
|
+
* NEVER CALL THIS DIRECTLY. USE `make()`.
|
|
62
|
+
*
|
|
63
|
+
* @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
|
|
64
|
+
*/
|
|
91
65
|
constructor(config = {}) {
|
|
92
66
|
if (new.target === ValidatorFactory) {
|
|
93
67
|
throw new TypeError('Cannot instantiate the abstract class, ValidatorFactory');
|
|
94
68
|
}
|
|
95
69
|
this.config = config;
|
|
96
70
|
}
|
|
97
|
-
/* eslint-disable
|
|
71
|
+
/* eslint-disable no-unused-vars */
|
|
72
|
+
/* eslint-disable-next-line jsdoc/require-returns-check */
|
|
73
|
+
/**
|
|
74
|
+
* Validate the given value.
|
|
75
|
+
*
|
|
76
|
+
* @param {any} fieldValue Value to validate
|
|
77
|
+
* @param {ValidateContext} context Contextual information
|
|
78
|
+
* @returns {ValidationError[]} A list of errors (empty if no errors found)
|
|
79
|
+
* @throws {Error}
|
|
80
|
+
*/
|
|
98
81
|
validate(fieldValue, context) {
|
|
99
82
|
throw new Error('validate() method has not been implemented');
|
|
100
83
|
}
|
|
101
|
-
/* eslint-disable-next-line
|
|
84
|
+
/* eslint-disable-next-line jsdoc/require-returns-check */
|
|
85
|
+
/**
|
|
86
|
+
* Sanitise the given value.
|
|
87
|
+
*
|
|
88
|
+
* @param {any} fieldValue Value to validate
|
|
89
|
+
* @returns {any} The sanitised value
|
|
90
|
+
*/
|
|
102
91
|
sanitise(fieldValue) {
|
|
103
92
|
return fieldValue;
|
|
104
93
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Validates and sanitises i18n obejct.
|
|
3
3
|
*
|
|
4
|
+
* @access private
|
|
4
5
|
* @param {object} i18n Object to validate.
|
|
5
6
|
* @param {Function} cb Callback function that receives the validated value.
|
|
6
7
|
* @throws {TypeError} For invalid object.
|
|
@@ -10,6 +11,7 @@ export function validateI18nObject(i18n?: object, cb?: Function): object;
|
|
|
10
11
|
/**
|
|
11
12
|
* Validates and sanitises i18n directory.
|
|
12
13
|
*
|
|
14
|
+
* @access private
|
|
13
15
|
* @param {Array} dirs Array of directories.
|
|
14
16
|
* @throws {SyntaxError} For invalid directories.
|
|
15
17
|
* @throws {TypeError} For invalid type.
|
|
@@ -19,6 +21,7 @@ export function validateI18nDirs(dirs?: any[]): any[];
|
|
|
19
21
|
/**
|
|
20
22
|
* Validates and sanitises i18n locales.
|
|
21
23
|
*
|
|
24
|
+
* @access private
|
|
22
25
|
* @param {Array} locales Array of locales.
|
|
23
26
|
* @throws {SyntaxError} For invalid locales.
|
|
24
27
|
* @throws {TypeError} For invalid type.
|
|
@@ -28,6 +31,7 @@ export function validateI18nLocales(locales?: any[]): any[];
|
|
|
28
31
|
/**
|
|
29
32
|
* Validates and sanitises mount url.
|
|
30
33
|
*
|
|
34
|
+
* @access private
|
|
31
35
|
* @param {string} mountUrl Prefix for all URLs in the browser address bar
|
|
32
36
|
* @throws {SyntaxError} For invalid URL.
|
|
33
37
|
* @returns {string|undefined} Sanitised URL.
|
|
@@ -36,6 +40,7 @@ export function validateMountUrl(mountUrl: string): string | undefined;
|
|
|
36
40
|
/**
|
|
37
41
|
* Validates and sanitises sessions object.
|
|
38
42
|
*
|
|
43
|
+
* @access private
|
|
39
44
|
* @param {object} session Object to validate.
|
|
40
45
|
* @param {Function} cb Callback function that receives the validated value.
|
|
41
46
|
* @throws {TypeError} For invalid object.
|
|
@@ -45,6 +50,7 @@ export function validateSessionObject(session?: object, cb?: Function): object;
|
|
|
45
50
|
/**
|
|
46
51
|
* Validates and sanitises view directory.
|
|
47
52
|
*
|
|
53
|
+
* @access private
|
|
48
54
|
* @param {Array} dirs Array of directories.
|
|
49
55
|
* @throws {SyntaxError} For invalid directories.
|
|
50
56
|
* @throws {TypeError} For invalid type.
|
|
@@ -54,6 +60,7 @@ export function validateViews(dirs?: any[]): any[];
|
|
|
54
60
|
/**
|
|
55
61
|
* Validates and sanitises sessions secret.
|
|
56
62
|
*
|
|
63
|
+
* @access private
|
|
57
64
|
* @param {string} secret Session secret.
|
|
58
65
|
* @throws {ReferenceError} For missing value type.
|
|
59
66
|
* @throws {TypeError} For invalid value.
|
|
@@ -63,6 +70,7 @@ export function validateSessionSecret(secret: string): string;
|
|
|
63
70
|
/**
|
|
64
71
|
* Validates and sanitises sessions ttl.
|
|
65
72
|
*
|
|
73
|
+
* @access private
|
|
66
74
|
* @param {number} ttl Session ttl (seconds).
|
|
67
75
|
* @throws {ReferenceError} For missing value type.
|
|
68
76
|
* @throws {TypeError} For invalid value.
|
|
@@ -72,6 +80,7 @@ export function validateSessionTtl(ttl?: number): number;
|
|
|
72
80
|
/**
|
|
73
81
|
* Validates and sanitises sessions name.
|
|
74
82
|
*
|
|
83
|
+
* @access private
|
|
75
84
|
* @param {string} [name=casa-session] Session name.
|
|
76
85
|
* @throws {ReferenceError} For missing value type.
|
|
77
86
|
* @throws {TypeError} For invalid value.
|
|
@@ -81,6 +90,7 @@ export function validateSessionName(name?: string | undefined): string;
|
|
|
81
90
|
/**
|
|
82
91
|
* Validates and sanitises sessions secure flag.
|
|
83
92
|
*
|
|
93
|
+
* @access private
|
|
84
94
|
* @param {boolean} [secure=false] Session secure flag.
|
|
85
95
|
* @throws {ReferenceError} For missing value type.
|
|
86
96
|
* @throws {TypeError} For invalid value.
|
|
@@ -90,6 +100,7 @@ export function validateSessionSecure(secure?: boolean | undefined): string;
|
|
|
90
100
|
/**
|
|
91
101
|
* Validates and sanitises sessions store.
|
|
92
102
|
*
|
|
103
|
+
* @access private
|
|
93
104
|
* @param {Function} store Session store.
|
|
94
105
|
* @returns {Function} Store.
|
|
95
106
|
*/
|
|
@@ -97,6 +108,7 @@ export function validateSessionStore(store: Function): Function;
|
|
|
97
108
|
/**
|
|
98
109
|
* Validates and sanitises sessions cookie url path.
|
|
99
110
|
*
|
|
111
|
+
* @access private
|
|
100
112
|
* @param {string} cookiePath Session cookie url path.
|
|
101
113
|
* @param {string} defaultPath Default path if none specified.
|
|
102
114
|
* @returns {string} Cookie path.
|
|
@@ -110,6 +122,7 @@ export function validateSessionCookiePath(cookiePath: string, defaultPath?: stri
|
|
|
110
122
|
* Lax
|
|
111
123
|
* None
|
|
112
124
|
*
|
|
125
|
+
* @access private
|
|
113
126
|
* @param {any} cookieSameSite Session cookie "sameSite" flag
|
|
114
127
|
* @param {any} defaultFlag Default path if none specified
|
|
115
128
|
* @returns {boolean} cookie path
|
|
@@ -126,6 +139,7 @@ export function validateEvents(events: any): any;
|
|
|
126
139
|
/**
|
|
127
140
|
* Validates helmet configuration function.
|
|
128
141
|
*
|
|
142
|
+
* @access private
|
|
129
143
|
* @param {HelmetConfigurator} helmetConfigurator Configuration function
|
|
130
144
|
* @returns {HelmetConfigurator} Validated configuration function
|
|
131
145
|
* @throws {TypeError} when passed a non-function
|
|
@@ -134,6 +148,7 @@ export function validateHelmetConfigurator(helmetConfigurator: HelmetConfigurato
|
|
|
134
148
|
/**
|
|
135
149
|
* Ingest, validate, sanitise and manipulate configuration parameters.
|
|
136
150
|
*
|
|
151
|
+
* @access private
|
|
137
152
|
* @param {ConfigurationOptions} config Config to ingest.
|
|
138
153
|
* @throws {Error|SyntaxError|TypeError} For invalid config values.
|
|
139
154
|
* @returns {object} Immutable config object.
|