@dwp/govuk-casa 8.2.3 → 8.2.6
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 +212 -5
- package/dist/casa.js +144 -7
- 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 +103 -16
- 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 +6 -2
- package/dist/lib/configure.js +19 -3
- 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 +44 -27
- 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
package/dist/lib/field.d.ts
CHANGED
|
@@ -1,16 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating PageField instances.
|
|
3
|
+
*
|
|
4
|
+
* @memberof module:@dwp/govuk-casa
|
|
5
|
+
* @param {string} name Field name
|
|
6
|
+
* @param {object} opts Options
|
|
7
|
+
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
8
|
+
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
9
|
+
* @returns {PageField} A PageField
|
|
10
|
+
*/
|
|
11
|
+
export default function field(name: string, opts: {
|
|
12
|
+
optional?: boolean | undefined;
|
|
13
|
+
persist?: boolean | undefined;
|
|
14
|
+
}): PageField;
|
|
15
|
+
/**
|
|
16
|
+
* This class is not exposed via the public API. Instances should instead be
|
|
17
|
+
* instantiated through the `field()` factory function.
|
|
18
|
+
*
|
|
19
|
+
* @class
|
|
20
|
+
*/
|
|
2
21
|
export class PageField {
|
|
3
|
-
constructor(name: any, { optional, persist }?: any);
|
|
4
22
|
/**
|
|
5
|
-
*
|
|
23
|
+
* Create a field.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} name Field name
|
|
26
|
+
* @param {object} opts Options
|
|
27
|
+
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
28
|
+
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
29
|
+
*/
|
|
30
|
+
constructor(name: string, { optional, persist }?: {
|
|
31
|
+
optional?: boolean | undefined;
|
|
32
|
+
persist?: boolean | undefined;
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Extract this field's value from the given object.
|
|
36
|
+
*
|
|
37
|
+
* For complex fields, we may need to drill into an object to extract the
|
|
6
38
|
* value.
|
|
7
39
|
*
|
|
8
40
|
* @param {object} obj Object from which to extract the value
|
|
9
41
|
* @returns {any} Value extracted from object
|
|
10
|
-
* @throws {Error} When run on a complex field
|
|
42
|
+
* @throws {Error} When run on a complex field (not yet supported)
|
|
11
43
|
*/
|
|
12
44
|
getValue(obj?: object): any;
|
|
13
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Store this field's value in the given object, using its name as the key.
|
|
47
|
+
*
|
|
48
|
+
* @param {object} obj Object from which to extract the value
|
|
49
|
+
* @param {any} value Value to be stored
|
|
50
|
+
* @returns {any} Value extracted from object
|
|
51
|
+
* @throws {Error} When run on a complex field (not yet supported)
|
|
52
|
+
*/
|
|
53
|
+
putValue(obj?: object, value?: any): any;
|
|
14
54
|
get name(): string;
|
|
15
55
|
get meta(): object;
|
|
16
56
|
/**
|
|
@@ -18,60 +58,82 @@ export class PageField {
|
|
|
18
58
|
* Some validators will include a `sanitise()` method which will be run at the
|
|
19
59
|
* same time as other "processors".
|
|
20
60
|
*
|
|
21
|
-
* @param {
|
|
22
|
-
* @returns {PageField |
|
|
61
|
+
* @param {Validator[]} items Validation functions
|
|
62
|
+
* @returns {PageField | Validator[]} Chain or return all validators
|
|
23
63
|
*/
|
|
24
|
-
validators(items?:
|
|
64
|
+
validators(items?: Validator[]): PageField | Validator[];
|
|
25
65
|
/**
|
|
26
66
|
* Add/get value pre-processors
|
|
27
67
|
* This is most often used to sanitise values to a particular data type.
|
|
28
68
|
*
|
|
29
|
-
* @param {
|
|
30
|
-
* @returns {PageField |
|
|
69
|
+
* @param {FieldProcessorFunction[]} items Processor functions
|
|
70
|
+
* @returns {PageField | FieldProcessorFunction[]} Chain or return all processors
|
|
31
71
|
*/
|
|
32
|
-
processors(items?:
|
|
72
|
+
processors(items?: FieldProcessorFunction[]): PageField | FieldProcessorFunction[];
|
|
33
73
|
/**
|
|
34
74
|
* Add/get conditions
|
|
35
75
|
* All conditions must be met in order for this field to be considered
|
|
36
76
|
* "actionable".
|
|
37
77
|
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @returns {PageField |
|
|
78
|
+
* @param {ValidatorConditionFunction[]} items Condition functions
|
|
79
|
+
* @returns {PageField | ValidatorConditionFunction[]} Chain or return all conditions
|
|
40
80
|
*/
|
|
41
|
-
conditions(items?:
|
|
81
|
+
conditions(items?: ValidatorConditionFunction[]): PageField | ValidatorConditionFunction[];
|
|
42
82
|
/**
|
|
43
83
|
* Run all validators and return array of errors, if applicable.
|
|
44
84
|
*
|
|
45
85
|
* @param {any} value Value to validate
|
|
46
|
-
* @param {ValidateContext} context Contextual information
|
|
86
|
+
* @param {ValidateContext} context Contextual validation information
|
|
47
87
|
* @returns {ValidationError[]} Errors, or an empty array if all valid
|
|
48
88
|
*/
|
|
49
|
-
runValidators(value: any, context?:
|
|
89
|
+
runValidators(value: any, context?: ValidateContext): ValidationError[];
|
|
90
|
+
/**
|
|
91
|
+
* Apply all the processors to the given value.
|
|
92
|
+
*
|
|
93
|
+
* @param {any} value Value to process
|
|
94
|
+
* @returns {any} Processed value
|
|
95
|
+
*/
|
|
50
96
|
applyProcessors(value: any): any;
|
|
51
97
|
/**
|
|
52
|
-
*
|
|
98
|
+
* All conditions must return true to be considered a successful test.
|
|
53
99
|
*
|
|
54
|
-
* @param {
|
|
55
|
-
* @param {string} params.fieldValue Field value
|
|
56
|
-
* @param {string} params.waypoint Waypoint
|
|
57
|
-
* @param {object} params.journeyContext JourneyContext
|
|
100
|
+
* @param {ValidateContext} context Contextual validation information
|
|
58
101
|
* @returns {boolean} True if all conditions pass
|
|
59
102
|
*/
|
|
60
|
-
testConditions({ fieldValue, waypoint, journeyContext }:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
103
|
+
testConditions({ fieldValue, waypoint, journeyContext }: ValidateContext): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Add a single validator.
|
|
106
|
+
*
|
|
107
|
+
* @param {Validator} validator Validation function
|
|
108
|
+
* @returns {PageField} Chain
|
|
109
|
+
*/
|
|
110
|
+
validator(validator: Validator): PageField;
|
|
111
|
+
/**
|
|
112
|
+
* Add a single pre-processors
|
|
113
|
+
*
|
|
114
|
+
* @param {FieldProcessorFunction} processor Processor function
|
|
115
|
+
* @returns {PageField} Chain
|
|
116
|
+
*/
|
|
117
|
+
processor(processor: FieldProcessorFunction): PageField;
|
|
118
|
+
/**
|
|
119
|
+
* Add a single condition.
|
|
120
|
+
*
|
|
121
|
+
* @param {ValidatorConditionFunction} condition Condition function
|
|
122
|
+
* @returns {PageField} Chain
|
|
123
|
+
*/
|
|
124
|
+
condition(condition: ValidatorConditionFunction): PageField;
|
|
125
|
+
/**
|
|
126
|
+
* Alias for `conditions()`.
|
|
127
|
+
*
|
|
128
|
+
* @param {...ValidatorConditionFunction} args Condition functions
|
|
129
|
+
* @returns {PageField} Chain
|
|
130
|
+
*/
|
|
131
|
+
if(...args: ValidatorConditionFunction[]): PageField;
|
|
69
132
|
#private;
|
|
70
133
|
}
|
|
71
134
|
export type JourneyContext = import('./index').JourneyContext;
|
|
72
|
-
export type Validator = import('
|
|
73
|
-
export type
|
|
74
|
-
export type
|
|
135
|
+
export type Validator = import('../casa').Validator;
|
|
136
|
+
export type ValidateContext = import('../casa').ValidateContext;
|
|
137
|
+
export type ValidatorConditionFunction = import('../casa').ValidatorConditionFunction;
|
|
138
|
+
export type FieldProcessorFunction = import('../casa').FieldProcessorFunction;
|
|
75
139
|
export type ValidationError = import('./index').ValidationError;
|
|
76
|
-
export type ProcessorFunction = (value: any) => any;
|
|
77
|
-
export type ConditionFunction = (context: Object, fieldName: string, fieldValue: any, waypoint: string, waypointId: string, journeyContext: JourneyContext) => boolean;
|
package/dist/lib/field.js
CHANGED
|
@@ -20,57 +20,63 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
20
20
|
const utils_js_1 = require("./utils.js");
|
|
21
21
|
const { isFunction } = lodash_1.default;
|
|
22
22
|
/**
|
|
23
|
+
* @access private
|
|
23
24
|
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
24
25
|
*/
|
|
25
26
|
/**
|
|
26
|
-
* @
|
|
27
|
+
* @access private
|
|
28
|
+
* @typedef {import('../casa').Validator} Validator
|
|
27
29
|
*/
|
|
28
30
|
/**
|
|
29
|
-
* @
|
|
31
|
+
* @access private
|
|
32
|
+
* @typedef {import('../casa').ValidateContext} ValidateContext
|
|
30
33
|
*/
|
|
31
34
|
/**
|
|
32
|
-
* @
|
|
35
|
+
* @access private
|
|
36
|
+
* @typedef {import('../casa').ValidatorConditionFunction} ValidatorConditionFunction
|
|
33
37
|
*/
|
|
34
38
|
/**
|
|
35
|
-
* @
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @callback ProcessorFunction
|
|
39
|
-
* @param {any} value Value to be processed
|
|
40
|
-
* @returns {any}
|
|
39
|
+
* @access private
|
|
40
|
+
* @typedef {import('../casa').FieldProcessorFunction} FieldProcessorFunction
|
|
41
41
|
*/
|
|
42
42
|
/**
|
|
43
|
-
* @
|
|
44
|
-
* @
|
|
45
|
-
* @param {string} context.fieldName Field name
|
|
46
|
-
* @param {any} context.fieldValue Field value
|
|
47
|
-
* @param {string} context.waypoint Waypoint
|
|
48
|
-
* @param {string} context.waypointId [DEPRECATED] Waypoint (for backwards compatibility with v7)
|
|
49
|
-
* @param {JourneyContext} journeyContext Journey Context
|
|
50
|
-
* @returns {boolean} True if the validators should be run
|
|
43
|
+
* @access private
|
|
44
|
+
* @typedef {import('./index').ValidationError} ValidationError
|
|
51
45
|
*/
|
|
52
46
|
// Quick check to see if the field name corresponds to a non-primitive complex
|
|
53
47
|
// type. For example, `my_field[nested]`.
|
|
54
48
|
const reComplexType = /\[/;
|
|
55
49
|
const reInvalidName = /[^a-z0-9_.\-[\]]/i;
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
/**
|
|
51
|
+
* This class is not exposed via the public API. Instances should instead be
|
|
52
|
+
* instantiated through the `field()` factory function.
|
|
53
|
+
*
|
|
54
|
+
* @class
|
|
55
|
+
*/
|
|
58
56
|
class PageField {
|
|
57
|
+
/**
|
|
58
|
+
* Create a field.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} name Field name
|
|
61
|
+
* @param {object} opts Options
|
|
62
|
+
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
63
|
+
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
64
|
+
*/
|
|
59
65
|
constructor(name, { optional = false, persist = true } = Object.create(null)) {
|
|
60
|
-
|
|
66
|
+
/**
|
|
61
67
|
* @type {string}
|
|
62
68
|
*/
|
|
63
69
|
_PageField_name.set(this, void 0);
|
|
64
70
|
/**
|
|
65
|
-
* @type {
|
|
71
|
+
* @type {FieldProcessorFunction[]}
|
|
66
72
|
*/
|
|
67
73
|
_PageField_processors.set(this, void 0);
|
|
68
74
|
/**
|
|
69
|
-
* @type {
|
|
75
|
+
* @type {Validator[]}
|
|
70
76
|
*/
|
|
71
77
|
_PageField_validators.set(this, void 0);
|
|
72
78
|
/**
|
|
73
|
-
* @type {
|
|
79
|
+
* @type {ValidatorConditionFunction[]}
|
|
74
80
|
*/
|
|
75
81
|
_PageField_conditions.set(this, void 0);
|
|
76
82
|
/**
|
|
@@ -94,12 +100,14 @@ class PageField {
|
|
|
94
100
|
}, "f");
|
|
95
101
|
}
|
|
96
102
|
/**
|
|
97
|
-
*
|
|
103
|
+
* Extract this field's value from the given object.
|
|
104
|
+
*
|
|
105
|
+
* For complex fields, we may need to drill into an object to extract the
|
|
98
106
|
* value.
|
|
99
107
|
*
|
|
100
108
|
* @param {object} obj Object from which to extract the value
|
|
101
109
|
* @returns {any} Value extracted from object
|
|
102
|
-
* @throws {Error} When run on a complex field
|
|
110
|
+
* @throws {Error} When run on a complex field (not yet supported)
|
|
103
111
|
*/
|
|
104
112
|
getValue(obj = Object.create(null)) {
|
|
105
113
|
if (!__classPrivateFieldGet(this, _PageField_meta, "f").complex) {
|
|
@@ -107,6 +115,14 @@ class PageField {
|
|
|
107
115
|
}
|
|
108
116
|
throw new Error('Not yet supporting complex field types');
|
|
109
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Store this field's value in the given object, using its name as the key.
|
|
120
|
+
*
|
|
121
|
+
* @param {object} obj Object from which to extract the value
|
|
122
|
+
* @param {any} value Value to be stored
|
|
123
|
+
* @returns {any} Value extracted from object
|
|
124
|
+
* @throws {Error} When run on a complex field (not yet supported)
|
|
125
|
+
*/
|
|
110
126
|
putValue(obj = Object.create(null), value = undefined) {
|
|
111
127
|
if (!__classPrivateFieldGet(this, _PageField_meta, "f").complex) {
|
|
112
128
|
/* eslint-disable-next-line no-param-reassign */
|
|
@@ -127,8 +143,8 @@ class PageField {
|
|
|
127
143
|
* Some validators will include a `sanitise()` method which will be run at the
|
|
128
144
|
* same time as other "processors".
|
|
129
145
|
*
|
|
130
|
-
* @param {
|
|
131
|
-
* @returns {PageField |
|
|
146
|
+
* @param {Validator[]} items Validation functions
|
|
147
|
+
* @returns {PageField | Validator[]} Chain or return all validators
|
|
132
148
|
*/
|
|
133
149
|
validators(items = []) {
|
|
134
150
|
if (!items.length) {
|
|
@@ -141,8 +157,8 @@ class PageField {
|
|
|
141
157
|
* Add/get value pre-processors
|
|
142
158
|
* This is most often used to sanitise values to a particular data type.
|
|
143
159
|
*
|
|
144
|
-
* @param {
|
|
145
|
-
* @returns {PageField |
|
|
160
|
+
* @param {FieldProcessorFunction[]} items Processor functions
|
|
161
|
+
* @returns {PageField | FieldProcessorFunction[]} Chain or return all processors
|
|
146
162
|
*/
|
|
147
163
|
processors(items = []) {
|
|
148
164
|
if (!items.length) {
|
|
@@ -156,8 +172,8 @@ class PageField {
|
|
|
156
172
|
* All conditions must be met in order for this field to be considered
|
|
157
173
|
* "actionable".
|
|
158
174
|
*
|
|
159
|
-
* @param {
|
|
160
|
-
* @returns {PageField |
|
|
175
|
+
* @param {ValidatorConditionFunction[]} items Condition functions
|
|
176
|
+
* @returns {PageField | ValidatorConditionFunction[]} Chain or return all conditions
|
|
161
177
|
*/
|
|
162
178
|
conditions(items = []) {
|
|
163
179
|
if (!items.length) {
|
|
@@ -171,7 +187,7 @@ class PageField {
|
|
|
171
187
|
* Run all validators and return array of errors, if applicable.
|
|
172
188
|
*
|
|
173
189
|
* @param {any} value Value to validate
|
|
174
|
-
* @param {ValidateContext} context Contextual information
|
|
190
|
+
* @param {ValidateContext} context Contextual validation information
|
|
175
191
|
* @returns {ValidationError[]} Errors, or an empty array if all valid
|
|
176
192
|
*/
|
|
177
193
|
runValidators(value, context = Object.create(null)) {
|
|
@@ -182,6 +198,8 @@ class PageField {
|
|
|
182
198
|
}
|
|
183
199
|
// Skip validation if conditions are not met
|
|
184
200
|
// We duplicate value in context.fieldValue for historical reasons
|
|
201
|
+
// @todo explain these historical reasons! And deprecate the need for
|
|
202
|
+
// `value` altogether
|
|
185
203
|
context.fieldValue = (_a = context.fieldValue) !== null && _a !== void 0 ? _a : value;
|
|
186
204
|
if (!this.testConditions(context)) {
|
|
187
205
|
return [];
|
|
@@ -190,6 +208,7 @@ class PageField {
|
|
|
190
208
|
for (let i = 0, l = __classPrivateFieldGet(this, _PageField_validators, "f").length; i < l; i++) {
|
|
191
209
|
// ESLint disabled as `i` is an integer
|
|
192
210
|
/* eslint-disable security/detect-object-injection */
|
|
211
|
+
// TODO: Replace `value` with `context.fieldValue` here
|
|
193
212
|
const fieldErrors = __classPrivateFieldGet(this, _PageField_validators, "f")[i].validate(value, context).map((e) => e.withContext(Object.assign(Object.assign({}, context), { validator: __classPrivateFieldGet(this, _PageField_validators, "f")[i].name })));
|
|
194
213
|
/* eslint-enable security/detect-object-injection */
|
|
195
214
|
errors = [
|
|
@@ -199,7 +218,7 @@ class PageField {
|
|
|
199
218
|
}
|
|
200
219
|
return errors;
|
|
201
220
|
}
|
|
202
|
-
|
|
221
|
+
/**
|
|
203
222
|
* Apply all the processors to the given value.
|
|
204
223
|
*
|
|
205
224
|
* @param {any} value Value to process
|
|
@@ -225,12 +244,9 @@ class PageField {
|
|
|
225
244
|
return processedValue;
|
|
226
245
|
}
|
|
227
246
|
/**
|
|
228
|
-
*
|
|
247
|
+
* All conditions must return true to be considered a successful test.
|
|
229
248
|
*
|
|
230
|
-
* @param {
|
|
231
|
-
* @param {string} params.fieldValue Field value
|
|
232
|
-
* @param {string} params.waypoint Waypoint
|
|
233
|
-
* @param {object} params.journeyContext JourneyContext
|
|
249
|
+
* @param {ValidateContext} context Contextual validation information
|
|
234
250
|
* @returns {boolean} True if all conditions pass
|
|
235
251
|
*/
|
|
236
252
|
testConditions({ fieldValue, waypoint, journeyContext }) {
|
|
@@ -250,23 +266,56 @@ class PageField {
|
|
|
250
266
|
return result;
|
|
251
267
|
}
|
|
252
268
|
/* ---------------------------------------------------------------- aliases */
|
|
269
|
+
/**
|
|
270
|
+
* Add a single validator.
|
|
271
|
+
*
|
|
272
|
+
* @param {Validator} validator Validation function
|
|
273
|
+
* @returns {PageField} Chain
|
|
274
|
+
*/
|
|
253
275
|
validator(validator) {
|
|
254
276
|
return this.validators([validator]);
|
|
255
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Add a single pre-processors
|
|
280
|
+
*
|
|
281
|
+
* @param {FieldProcessorFunction} processor Processor function
|
|
282
|
+
* @returns {PageField} Chain
|
|
283
|
+
*/
|
|
256
284
|
processor(processor) {
|
|
257
285
|
return this.processors([processor]);
|
|
258
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Add a single condition.
|
|
289
|
+
*
|
|
290
|
+
* @param {ValidatorConditionFunction} condition Condition function
|
|
291
|
+
* @returns {PageField} Chain
|
|
292
|
+
*/
|
|
259
293
|
condition(condition) {
|
|
260
294
|
return this.conditions([condition]);
|
|
261
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Alias for `conditions()`.
|
|
298
|
+
*
|
|
299
|
+
* @param {...ValidatorConditionFunction} args Condition functions
|
|
300
|
+
* @returns {PageField} Chain
|
|
301
|
+
*/
|
|
262
302
|
if(...args) {
|
|
263
303
|
return this.conditions(...args);
|
|
264
304
|
}
|
|
265
305
|
}
|
|
266
306
|
exports.PageField = PageField;
|
|
267
307
|
_PageField_name = new WeakMap(), _PageField_processors = new WeakMap(), _PageField_validators = new WeakMap(), _PageField_conditions = new WeakMap(), _PageField_meta = new WeakMap();
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Factory for creating PageField instances.
|
|
310
|
+
*
|
|
311
|
+
* @memberof module:@dwp/govuk-casa
|
|
312
|
+
* @param {string} name Field name
|
|
313
|
+
* @param {object} opts Options
|
|
314
|
+
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
315
|
+
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
316
|
+
* @returns {PageField} A PageField
|
|
317
|
+
*/
|
|
318
|
+
function field(name, opts) {
|
|
319
|
+
return new PageField(name, opts);
|
|
271
320
|
}
|
|
272
321
|
exports.default = field;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export function mergeObjects(...objects: any[]): object;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Determine whether a value exists in a list.
|
|
4
|
+
*
|
|
5
|
+
* @memberof NunjucksFilters
|
|
6
|
+
* @param {any[]} source List of items to search
|
|
7
|
+
* @param {any} search Item to search within the `source`
|
|
8
|
+
* @returns {boolean} True if the search item was found
|
|
9
|
+
*/
|
|
10
|
+
export function includes(source?: any[], search?: any): boolean;
|
|
3
11
|
/**
|
|
4
12
|
* Format a given date.
|
|
5
13
|
*
|
|
@@ -8,6 +16,7 @@ export function includes(source?: any[], search?: string): boolean;
|
|
|
8
16
|
* `date` may be any of the following types:
|
|
9
17
|
* object - {dd:'', mm:'', yyyy:''}
|
|
10
18
|
*
|
|
19
|
+
* @memberof NunjucksFilters
|
|
11
20
|
* @param {object} date Date (see supported formats above)
|
|
12
21
|
* @param {object} config Holds locale
|
|
13
22
|
* @returns {string} Formatted date
|
|
@@ -20,7 +29,8 @@ export function formatDateObject(date: object, config?: object): string;
|
|
|
20
29
|
* Given: {class: 'basic', 'data-ga': 3}
|
|
21
30
|
* Output: class="basic" data-ga="3"
|
|
22
31
|
*
|
|
23
|
-
* @
|
|
32
|
+
* @memberof NunjucksFilters
|
|
33
|
+
* @param {object} attrsObject Attributes object (in name:value pairs)
|
|
24
34
|
* @returns {string} Formatted
|
|
25
35
|
*/
|
|
26
36
|
export function renderAsAttributes(attrsObject: object): string;
|
|
@@ -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
|
-
* @
|
|
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) {
|
package/dist/lib/nunjucks.d.ts
CHANGED
package/dist/lib/nunjucks.js
CHANGED
package/dist/lib/utils.d.ts
CHANGED
|
@@ -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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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;
|