@dwp/govuk-casa 8.2.2 → 8.2.5
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 -8
- 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 +4 -0
- package/dist/lib/configure.js +18 -2
- 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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [8.2.5](https://github.com/dwp/govuk-casa/compare/8.2.3...8.2.5) (2022-06-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* serve statics correctly from deeply nested apps ([0fd00a5](https://github.com/dwp/govuk-casa/commit/0fd00a5f10de28706afe87a993072d3184e3c7aa))
|
|
11
|
+
|
|
12
|
+
### [8.2.3](https://github.com/dwp/govuk-casa/compare/8.2.2...8.2.3) (2022-05-23)
|
|
13
|
+
|
|
5
14
|
### [8.2.2](https://github.com/dwp/govuk-casa/compare/8.2.1...8.2.2) (2022-05-23)
|
|
6
15
|
|
|
7
16
|
|
package/README.md
CHANGED
package/dist/casa.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type PageField = import('./lib/field').PageField;
|
|
2
|
-
export type ContextEventHandler = (journeyContext: JourneyContext, previousContext: JourneyContext) => void;
|
|
2
|
+
export type ContextEventHandler = (opts: object, journeyContext: JourneyContext, previousContext: JourneyContext, session: object) => void;
|
|
3
3
|
export type ContextEvent = {
|
|
4
4
|
/**
|
|
5
5
|
* Waypoint to watch for changes
|
|
@@ -108,13 +108,14 @@ export type IPlugin = {
|
|
|
108
108
|
/**
|
|
109
109
|
* Modify the app config
|
|
110
110
|
*/
|
|
111
|
-
configure?:
|
|
111
|
+
configure?: PluginConfigureFunction | undefined;
|
|
112
112
|
/**
|
|
113
113
|
* Modify post-configuration artifacts
|
|
114
114
|
*/
|
|
115
|
-
bootstrap?:
|
|
115
|
+
bootstrap?: PluginBootstrapFunction | undefined;
|
|
116
116
|
};
|
|
117
|
-
export type PluginConfigureFunction = (
|
|
117
|
+
export type PluginConfigureFunction = (config: ConfigurationOptions) => any;
|
|
118
|
+
export type PluginBootstrapFunction = (config: ConfigureResult) => any;
|
|
118
119
|
export type HelmetConfigurator = (config: object) => object;
|
|
119
120
|
export type Mounter = (app: import('express').Express, opts: object, route?: string | undefined) => import('express').Express;
|
|
120
121
|
export type MutableRouter = import('./lib/index').MutableRouter;
|
|
@@ -153,11 +154,15 @@ export type ConfigurationOptions = {
|
|
|
153
154
|
/**
|
|
154
155
|
* CASA Plan
|
|
155
156
|
*/
|
|
156
|
-
plan
|
|
157
|
+
plan?: Plan | undefined;
|
|
157
158
|
/**
|
|
158
159
|
* Handlers for JourneyContext events
|
|
159
160
|
*/
|
|
160
161
|
events?: ContextEvent[] | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Helmet configuration manipulator function
|
|
164
|
+
*/
|
|
165
|
+
helmetConfigurator?: HelmetConfigurator | undefined;
|
|
161
166
|
};
|
|
162
167
|
/**
|
|
163
168
|
* Result of a call to configure() function
|
|
@@ -211,7 +216,209 @@ export type ConfigureResult = {
|
|
|
211
216
|
* Function used to mount all CASA artifacts onto an ExpressJS app
|
|
212
217
|
*/
|
|
213
218
|
mount: Mounter;
|
|
219
|
+
/**
|
|
220
|
+
* Ingested config supplied to `configure()`
|
|
221
|
+
*/
|
|
222
|
+
config: ConfigurationOptions;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Configuration for generating a ValidationError.
|
|
226
|
+
* i.e. `new ValidationError(configObject)`
|
|
227
|
+
* <br/><br/>
|
|
228
|
+
*
|
|
229
|
+
* The `fieldKeySuffix` is used to differentiate errors attached to
|
|
230
|
+
* the same field name. For example, given these fields inputs ...
|
|
231
|
+
*
|
|
232
|
+
* <pre>
|
|
233
|
+
* <input name="dateOfBirth[dd]" />
|
|
234
|
+
* <input name="dateOfBirth[mm]" />
|
|
235
|
+
* <input name="dateOfBirth[yyyy]" />
|
|
236
|
+
* </pre>
|
|
237
|
+
*
|
|
238
|
+
* If we wanted to generate an error specifically for the `dd`
|
|
239
|
+
* element, then we'd include `{ fieldKeySuffix: '[dd]' }` in this
|
|
240
|
+
* config.
|
|
241
|
+
* <br/><br/>
|
|
242
|
+
*
|
|
243
|
+
* We can also use `focusSuffix` to control which properties of an
|
|
244
|
+
* object field should be highlighted with a red border when in error. Looking
|
|
245
|
+
* again at the `dateOfBirth` example above, if we did not specify
|
|
246
|
+
* any `focusSuffix`, then all three inputs would be highlighted.
|
|
247
|
+
* However, if we use `{ focusSuffix: ['[dd]', '[yyyy]'] }` then only
|
|
248
|
+
* the `[dd]` and `[yyyy]` inputs would be highlighted.
|
|
249
|
+
* <br/><br/>
|
|
250
|
+
*
|
|
251
|
+
* The `fieldHref` and `field` properties are strictly for
|
|
252
|
+
* internal use only and public access may be removed at any point.
|
|
253
|
+
*/
|
|
254
|
+
export type ErrorMessageConfigObject = {
|
|
255
|
+
/**
|
|
256
|
+
* Summary message
|
|
257
|
+
*/
|
|
258
|
+
summary: string;
|
|
259
|
+
/**
|
|
260
|
+
* Inline message (@deprecated now uses summary everywhere)
|
|
261
|
+
*/
|
|
262
|
+
inline?: string | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* String(s) to append to URL hash for focusing inputs
|
|
265
|
+
*/
|
|
266
|
+
focusSuffix?: string | string[] | undefined;
|
|
267
|
+
/**
|
|
268
|
+
* Object fields may use this to show errors per sub-property
|
|
269
|
+
*/
|
|
270
|
+
fieldKeySuffix?: string | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* Interpolation variables
|
|
273
|
+
*/
|
|
274
|
+
variables?: object | ErrorMessageVariablesGenerator | undefined;
|
|
275
|
+
/**
|
|
276
|
+
* Name of the validator
|
|
277
|
+
*/
|
|
278
|
+
validator?: string | undefined;
|
|
279
|
+
/**
|
|
280
|
+
* (internal) URL hash to link to field in UI, i.e `#f-..`
|
|
281
|
+
*/
|
|
282
|
+
fieldHref?: string | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* (internal) Field name, including any focus suffix
|
|
285
|
+
*/
|
|
286
|
+
field?: string | undefined;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Function to generate interpolation variables for injecting into the error
|
|
290
|
+
* message string.
|
|
291
|
+
*/
|
|
292
|
+
export type ErrorMessageVariablesGenerator = (dataContext: ValidateContext) => object;
|
|
293
|
+
export type ErrorMessageConfigGenerator = (dataContext: ValidateContext) => string | ErrorMessageConfigObject;
|
|
294
|
+
export type ErrorMessageConfig = string | ErrorMessageConfigObject | ErrorMessageConfigGenerator | Error;
|
|
295
|
+
/**
|
|
296
|
+
* Context passed to validate function
|
|
297
|
+
*/
|
|
298
|
+
export type ValidateContext = {
|
|
299
|
+
/**
|
|
300
|
+
* Journey context
|
|
301
|
+
*/
|
|
302
|
+
journeyContext: JourneyContext;
|
|
303
|
+
/**
|
|
304
|
+
* Waypoint
|
|
305
|
+
*/
|
|
306
|
+
waypoint: string;
|
|
307
|
+
/**
|
|
308
|
+
* Name of field being processed
|
|
309
|
+
*/
|
|
310
|
+
fieldName: string;
|
|
311
|
+
/**
|
|
312
|
+
* Current value of the field being validated
|
|
313
|
+
*/
|
|
314
|
+
fieldValue?: any;
|
|
315
|
+
/**
|
|
316
|
+
* Name of the validator
|
|
317
|
+
*/
|
|
318
|
+
validator?: string | undefined;
|
|
319
|
+
};
|
|
320
|
+
export type ValidateFunction = (value: any, context: ValidateContext) => ValidationError[];
|
|
321
|
+
export type FieldProcessorFunction = (value: any) => any;
|
|
322
|
+
export type Validator = {
|
|
323
|
+
/**
|
|
324
|
+
* Validation function
|
|
325
|
+
*/
|
|
326
|
+
validate: ValidateFunction;
|
|
327
|
+
/**
|
|
328
|
+
* Sanitise a given value prior to validation
|
|
329
|
+
*/
|
|
330
|
+
sanitise: FieldProcessorFunction;
|
|
331
|
+
/**
|
|
332
|
+
* Configuration
|
|
333
|
+
*/
|
|
334
|
+
config: object;
|
|
335
|
+
/**
|
|
336
|
+
* Validator name
|
|
337
|
+
*/
|
|
338
|
+
name: string;
|
|
339
|
+
};
|
|
340
|
+
export type ValidatorConditionFunctionParams = {
|
|
341
|
+
/**
|
|
342
|
+
* Field name
|
|
343
|
+
*/
|
|
344
|
+
fieldName: string;
|
|
345
|
+
/**
|
|
346
|
+
* Field value
|
|
347
|
+
*/
|
|
348
|
+
fieldValue: any;
|
|
349
|
+
/**
|
|
350
|
+
* Waypoint
|
|
351
|
+
*/
|
|
352
|
+
waypoint: string;
|
|
353
|
+
/**
|
|
354
|
+
* [DEPRECATED] Waypoint (for backwards compatibility with v7)
|
|
355
|
+
*/
|
|
356
|
+
waypointId: string;
|
|
357
|
+
/**
|
|
358
|
+
* Journey Context
|
|
359
|
+
*/
|
|
360
|
+
journeyContext: JourneyContext;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* Condition functions are executed unbound.
|
|
364
|
+
*/
|
|
365
|
+
export type ValidatorConditionFunction = (context: ValidatorConditionFunctionParams) => boolean;
|
|
366
|
+
export type PlanRoute = {
|
|
367
|
+
/**
|
|
368
|
+
* Source waypoint
|
|
369
|
+
*/
|
|
370
|
+
source: string;
|
|
371
|
+
/**
|
|
372
|
+
* Target waypoint
|
|
373
|
+
*/
|
|
374
|
+
target: string;
|
|
375
|
+
/**
|
|
376
|
+
* Name
|
|
377
|
+
*/
|
|
378
|
+
name: string;
|
|
379
|
+
/**
|
|
380
|
+
* Label
|
|
381
|
+
*/
|
|
382
|
+
label: string;
|
|
383
|
+
};
|
|
384
|
+
export type PlanRouteCondition = (route: PlanRoute, context: JourneyContext) => boolean;
|
|
385
|
+
export type PlanTraverseOptions = {
|
|
386
|
+
/**
|
|
387
|
+
* Waypoint from which to start (defaults to first in list)
|
|
388
|
+
*/
|
|
389
|
+
startWaypoint?: string | undefined;
|
|
390
|
+
/**
|
|
391
|
+
* Follow routes matching this name (next | prev)
|
|
392
|
+
*/
|
|
393
|
+
routeName: string;
|
|
394
|
+
/**
|
|
395
|
+
* Used to detect loops in traversal (INTERNAL USE ONLY)
|
|
396
|
+
*/
|
|
397
|
+
history: Map<any, any>;
|
|
398
|
+
/**
|
|
399
|
+
* If true, traversal will be stopped (useful for performance)
|
|
400
|
+
*/
|
|
401
|
+
stopCondition?: Function | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* Mutliple target routes found, this decides which to use
|
|
404
|
+
*/
|
|
405
|
+
arbiter?: string | PlanArbiter | undefined;
|
|
406
|
+
};
|
|
407
|
+
export type PlanArbiterParams = {
|
|
408
|
+
/**
|
|
409
|
+
* Potential target routes that need arbitration
|
|
410
|
+
*/
|
|
411
|
+
targets: PlanRoute[];
|
|
412
|
+
/**
|
|
413
|
+
* Journey Context
|
|
414
|
+
*/
|
|
415
|
+
journeyContext: JourneyContext;
|
|
416
|
+
/**
|
|
417
|
+
* Original traverse options passed to `traverse()`
|
|
418
|
+
*/
|
|
419
|
+
traverseOptions: PlanTraverseOptions;
|
|
214
420
|
};
|
|
421
|
+
export type PlanArbiter = (route: PlanArbiterParams) => PlanRoute[];
|
|
215
422
|
import configure from "./lib/configure.js";
|
|
216
423
|
import validators from "./lib/validators/index.js";
|
|
217
424
|
import field from "./lib/field.js";
|
package/dist/casa.js
CHANGED
|
@@ -55,8 +55,10 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
55
55
|
*/
|
|
56
56
|
/**
|
|
57
57
|
* @callback ContextEventHandler
|
|
58
|
-
* @param {
|
|
59
|
-
* @param {JourneyContext}
|
|
58
|
+
* @param {object} opts Options
|
|
59
|
+
* @param {JourneyContext} opts.journeyContext Context including changes
|
|
60
|
+
* @param {JourneyContext} opts.previousContext Context prior to changes
|
|
61
|
+
* @param {object} opts.session Request session object
|
|
60
62
|
* @returns {void}
|
|
61
63
|
*/
|
|
62
64
|
/**
|
|
@@ -99,13 +101,16 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
99
101
|
*/
|
|
100
102
|
/**
|
|
101
103
|
* @typedef {object} IPlugin Plugin interface
|
|
102
|
-
* @property {
|
|
103
|
-
* @property {
|
|
104
|
+
* @property {PluginConfigureFunction} [configure] Modify the app config
|
|
105
|
+
* @property {PluginBootstrapFunction} [bootstrap] Modify post-configuration artifacts
|
|
104
106
|
*/
|
|
105
107
|
/**
|
|
106
108
|
* @callback PluginConfigureFunction
|
|
107
|
-
* @param {
|
|
108
|
-
|
|
109
|
+
* @param {ConfigurationOptions} config Options
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* @callback PluginBootstrapFunction
|
|
113
|
+
* @param {ConfigureResult} config Options
|
|
109
114
|
*/
|
|
110
115
|
/**
|
|
111
116
|
* @callback HelmetConfigurator
|
|
@@ -116,7 +121,7 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
116
121
|
* @callback Mounter
|
|
117
122
|
* @param {import('express').Express} app Express application
|
|
118
123
|
* @param {object} opts Mounting options
|
|
119
|
-
* @param {string} [opts.route
|
|
124
|
+
* @param {string} [opts.route='/'] Optional route to attach all middleware/routers too
|
|
120
125
|
* @returns {import('express').Express} The prepared ExpressJS app instance
|
|
121
126
|
*/
|
|
122
127
|
/**
|
|
@@ -133,8 +138,9 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
133
138
|
* @property {GlobalHook[]} [hooks=[]] Hooks to apply
|
|
134
139
|
* @property {IPlugin[]} [plugins=[]] Plugins
|
|
135
140
|
* @property {I18nOptions[]} [i18n] I18n configuration
|
|
136
|
-
* @property {Plan} plan CASA Plan
|
|
141
|
+
* @property {Plan} [plan] CASA Plan
|
|
137
142
|
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events
|
|
143
|
+
* @property {HelmetConfigurator} [helmetConfigurator] Helmet configuration manipulator function
|
|
138
144
|
*/
|
|
139
145
|
/**
|
|
140
146
|
* @typedef {object} ConfigureResult Result of a call to configure() function
|
|
@@ -150,4 +156,134 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
150
156
|
* @property {import('express').RequestHandler[]} i18nMiddleware I18n preparation middleware
|
|
151
157
|
* @property {import('express').RequestHandler} bodyParserMiddleware Body parsing middleware
|
|
152
158
|
* @property {Mounter} mount Function used to mount all CASA artifacts onto an ExpressJS app
|
|
159
|
+
* @property {ConfigurationOptions} config Ingested config supplied to `configure()`
|
|
160
|
+
*/
|
|
161
|
+
/**
|
|
162
|
+
* Configuration for generating a ValidationError.
|
|
163
|
+
* i.e. `new ValidationError(configObject)`
|
|
164
|
+
* <br/><br/>
|
|
165
|
+
*
|
|
166
|
+
* The `fieldKeySuffix` is used to differentiate errors attached to
|
|
167
|
+
* the same field name. For example, given these fields inputs ...
|
|
168
|
+
*
|
|
169
|
+
* <pre>
|
|
170
|
+
* <input name="dateOfBirth[dd]" />
|
|
171
|
+
* <input name="dateOfBirth[mm]" />
|
|
172
|
+
* <input name="dateOfBirth[yyyy]" />
|
|
173
|
+
* </pre>
|
|
174
|
+
*
|
|
175
|
+
* If we wanted to generate an error specifically for the `dd`
|
|
176
|
+
* element, then we'd include `{ fieldKeySuffix: '[dd]' }` in this
|
|
177
|
+
* config.
|
|
178
|
+
* <br/><br/>
|
|
179
|
+
*
|
|
180
|
+
* We can also use `focusSuffix` to control which properties of an
|
|
181
|
+
* object field should be highlighted with a red border when in error. Looking
|
|
182
|
+
* again at the `dateOfBirth` example above, if we did not specify
|
|
183
|
+
* any `focusSuffix`, then all three inputs would be highlighted.
|
|
184
|
+
* However, if we use `{ focusSuffix: ['[dd]', '[yyyy]'] }` then only
|
|
185
|
+
* the `[dd]` and `[yyyy]` inputs would be highlighted.
|
|
186
|
+
* <br/><br/>
|
|
187
|
+
*
|
|
188
|
+
* The `fieldHref` and `field` properties are strictly for
|
|
189
|
+
* internal use only and public access may be removed at any point.
|
|
190
|
+
*
|
|
191
|
+
* @typedef {object} ErrorMessageConfigObject
|
|
192
|
+
* @property {string} summary Summary message
|
|
193
|
+
* @property {string} [inline] Inline message (@deprecated now uses summary everywhere)
|
|
194
|
+
* @property {string|string[]} [focusSuffix] String(s) to append to URL hash for focusing inputs
|
|
195
|
+
* @property {string} [fieldKeySuffix] Object fields may use this to show errors per sub-property
|
|
196
|
+
* @property {object|ErrorMessageVariablesGenerator} [variables] Interpolation variables
|
|
197
|
+
* @property {string} [validator] Name of the validator
|
|
198
|
+
* @property {string} [fieldHref] (internal) URL hash to link to field in UI, i.e `#f-..`
|
|
199
|
+
* @property {string} [field] (internal) Field name, including any focus suffix
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Function to generate interpolation variables for injecting into the error
|
|
203
|
+
* message string.
|
|
204
|
+
*
|
|
205
|
+
* @callback ErrorMessageVariablesGenerator
|
|
206
|
+
* @param {ValidateContext} dataContext Data context
|
|
207
|
+
* @returns {object} Variables name:value hash
|
|
208
|
+
*/
|
|
209
|
+
/**
|
|
210
|
+
* @callback ErrorMessageConfigGenerator
|
|
211
|
+
* @param {ValidateContext} dataContext Data context
|
|
212
|
+
* @returns {string|ErrorMessageConfigObject} Compiled error mesasge config
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* @typedef {string|ErrorMessageConfigObject|ErrorMessageConfigGenerator|Error} ErrorMessageConfig
|
|
216
|
+
*/
|
|
217
|
+
/**
|
|
218
|
+
* @typedef {object} ValidateContext Context passed to validate function
|
|
219
|
+
* @property {JourneyContext} journeyContext Journey context
|
|
220
|
+
* @property {string} waypoint Waypoint
|
|
221
|
+
* @property {string} fieldName Name of field being processed
|
|
222
|
+
* @property {any} [fieldValue] Current value of the field being validated
|
|
223
|
+
* @property {string} [validator] Name of the validator
|
|
224
|
+
*/
|
|
225
|
+
/**
|
|
226
|
+
* @callback ValidateFunction
|
|
227
|
+
* @param {any} value
|
|
228
|
+
* @param {ValidateContext} context Vaildation context
|
|
229
|
+
* @returns {ValidationError[]}
|
|
230
|
+
*/
|
|
231
|
+
/**
|
|
232
|
+
* @callback FieldProcessorFunction
|
|
233
|
+
* @param {any} value Value to be processed
|
|
234
|
+
* @returns {any}
|
|
235
|
+
*/
|
|
236
|
+
/**
|
|
237
|
+
* @typedef {object} Validator
|
|
238
|
+
* @property {ValidateFunction} validate Validation function
|
|
239
|
+
* @property {FieldProcessorFunction} sanitise Sanitise a given value prior to validation
|
|
240
|
+
* @property {object} config Configuration
|
|
241
|
+
* @property {string} name Validator name
|
|
242
|
+
*/
|
|
243
|
+
/**
|
|
244
|
+
* @typedef {object} ValidatorConditionFunctionParams
|
|
245
|
+
* @property {string} fieldName Field name
|
|
246
|
+
* @property {any} fieldValue Field value
|
|
247
|
+
* @property {string} waypoint Waypoint
|
|
248
|
+
* @property {string} waypointId [DEPRECATED] Waypoint (for backwards compatibility with v7)
|
|
249
|
+
* @property {JourneyContext} journeyContext Journey Context
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* Condition functions are executed unbound.
|
|
253
|
+
*
|
|
254
|
+
* @callback ValidatorConditionFunction
|
|
255
|
+
* @param {ValidatorConditionFunctionParams} context Value to be processed
|
|
256
|
+
* @returns {boolean} True if the validators should be run
|
|
257
|
+
*/
|
|
258
|
+
/**
|
|
259
|
+
* @typedef {object} PlanRoute
|
|
260
|
+
* @property {string} source Source waypoint
|
|
261
|
+
* @property {string} target Target waypoint
|
|
262
|
+
* @property {string} name Name
|
|
263
|
+
* @property {string} label Label
|
|
264
|
+
*/
|
|
265
|
+
/**
|
|
266
|
+
* @callback PlanRouteCondition
|
|
267
|
+
* @param {PlanRoute} route Route metadata
|
|
268
|
+
* @param {JourneyContext} context Journey Context
|
|
269
|
+
* @returns {boolean} Returns true is route should be followed
|
|
270
|
+
*/
|
|
271
|
+
/**
|
|
272
|
+
* @typedef PlanTraverseOptions
|
|
273
|
+
* @property {string} [startWaypoint] Waypoint from which to start (defaults to first in list)
|
|
274
|
+
* @property {string} routeName Follow routes matching this name (next | prev)
|
|
275
|
+
* @property {Map} history Used to detect loops in traversal (INTERNAL USE ONLY)
|
|
276
|
+
* @property {Function} [stopCondition] If true, traversal will be stopped (useful for performance)
|
|
277
|
+
* @property {string|PlanArbiter} [arbiter] Mutliple target routes found, this decides which to use
|
|
278
|
+
*/
|
|
279
|
+
/**
|
|
280
|
+
* @typedef {object} PlanArbiterParams
|
|
281
|
+
* @property {PlanRoute[]} targets Potential target routes that need arbitration
|
|
282
|
+
* @property {JourneyContext} journeyContext Journey Context
|
|
283
|
+
* @property {PlanTraverseOptions} traverseOptions Original traverse options passed to `traverse()`
|
|
284
|
+
*/
|
|
285
|
+
/**
|
|
286
|
+
* @callback PlanArbiter
|
|
287
|
+
* @param {PlanArbiterParams} route Route metadata
|
|
288
|
+
* @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter could eliminate
|
|
153
289
|
*/
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* @param {string} templateName Path to the template being modified
|
|
4
4
|
* @returns {string} The modified template source
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* @access private
|
|
8
|
+
* @augments FileSystemLoader
|
|
9
|
+
*/
|
|
6
10
|
export default class CasaTemplateLoader extends FileSystemLoader {
|
|
7
11
|
/**
|
|
8
12
|
* Constructor.
|
|
@@ -14,6 +14,7 @@ var _CasaTemplateLoader_instances, _CasaTemplateLoader_blockModifiers, _CasaTemp
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const nunjucks_1 = require("nunjucks");
|
|
16
16
|
/**
|
|
17
|
+
* @access private
|
|
17
18
|
* @typedef {import('nunjucks').FileSystemLoaderOptions} FileSystemLoaderOptions
|
|
18
19
|
*/
|
|
19
20
|
const VALID_BLOCKS = [
|
|
@@ -36,6 +37,10 @@ const VALID_BLOCKS = [
|
|
|
36
37
|
* @param {string} templateName Path to the template being modified
|
|
37
38
|
* @returns {string} The modified template source
|
|
38
39
|
*/
|
|
40
|
+
/**
|
|
41
|
+
* @access private
|
|
42
|
+
* @augments FileSystemLoader
|
|
43
|
+
*/
|
|
39
44
|
class CasaTemplateLoader extends nunjucks_1.FileSystemLoader {
|
|
40
45
|
/**
|
|
41
46
|
* Constructor.
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @access private
|
|
2
3
|
* @typedef {import('../casa').Page} Page
|
|
3
4
|
*/
|
|
4
5
|
/**
|
|
6
|
+
* @access private
|
|
5
7
|
* @typedef {import('../casa').ContextEventHandler} ContextEventHandler
|
|
6
8
|
*/
|
|
7
9
|
/**
|
|
10
|
+
* @access private
|
|
8
11
|
* @typedef {import('../casa').ContextEvent} ContextEvent
|
|
9
12
|
*/
|
|
13
|
+
/**
|
|
14
|
+
* @access private
|
|
15
|
+
* @typedef {import('express').Request} ExpressRequest
|
|
16
|
+
*/
|
|
10
17
|
export function validateObjectKey(key?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* @memberof module:@dwp/govuk-casa
|
|
20
|
+
*/
|
|
11
21
|
export default class JourneyContext {
|
|
12
22
|
static DEFAULT_CONTEXT_ID: string;
|
|
13
23
|
/**
|
|
@@ -58,6 +68,14 @@ export default class JourneyContext {
|
|
|
58
68
|
* @throws {SyntaxError} When id is not a valid uuid format
|
|
59
69
|
*/
|
|
60
70
|
static validateContextId(id: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieve the default Journey Context. This is just a convenient wrapper
|
|
73
|
+
* around `getContextById()`.
|
|
74
|
+
*
|
|
75
|
+
* @param {object} session Request session
|
|
76
|
+
* @returns {JourneyContext} The default Journey Context
|
|
77
|
+
*/
|
|
78
|
+
static getDefaultContext(session: object): JourneyContext;
|
|
61
79
|
/**
|
|
62
80
|
* Lookup context from session using the ID.
|
|
63
81
|
*
|
|
@@ -106,11 +124,48 @@ export default class JourneyContext {
|
|
|
106
124
|
* @returns {void}
|
|
107
125
|
*/
|
|
108
126
|
static removeContext(session: object, context: JourneyContext): void;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Remove context from session using the ID.
|
|
129
|
+
*
|
|
130
|
+
* @param {object} session Request session
|
|
131
|
+
* @param {string} id Context ID
|
|
132
|
+
* @returns {void}
|
|
133
|
+
*/
|
|
134
|
+
static removeContextById(session: object, id: string): void;
|
|
135
|
+
/**
|
|
136
|
+
* Remove context from session using the name.
|
|
137
|
+
*
|
|
138
|
+
* @param {object} session Request session
|
|
139
|
+
* @param {string} name Context name
|
|
140
|
+
* @returns {void}
|
|
141
|
+
*/
|
|
142
|
+
static removeContextByName(session: object, name: string): void;
|
|
143
|
+
/**
|
|
144
|
+
* Remove context from session using the tag.
|
|
145
|
+
*
|
|
146
|
+
* @param {object} session Request session
|
|
147
|
+
* @param {string} tag Context tag
|
|
148
|
+
* @returns {void}
|
|
149
|
+
*/
|
|
150
|
+
static removeContextsByTag(session: object, tag: string): void;
|
|
151
|
+
/**
|
|
152
|
+
* Remove call contexts.
|
|
153
|
+
*
|
|
154
|
+
* @param {object} session Request session
|
|
155
|
+
* @returns {void}
|
|
156
|
+
*/
|
|
157
|
+
static removeContexts(session: object): void;
|
|
158
|
+
/**
|
|
159
|
+
* Extract the Journey Context referred to in the incoming request.
|
|
160
|
+
*
|
|
161
|
+
* This will look in `req.params`, `req.query` and
|
|
162
|
+
* `req.body` for a `contextid` parameter, and use that
|
|
163
|
+
* to load the correct Journey Context from the session.
|
|
164
|
+
*
|
|
165
|
+
* @param {ExpressRequest} req ExpressJS incoming request
|
|
166
|
+
* @returns {JourneyContext} The Journey Context
|
|
167
|
+
*/
|
|
168
|
+
static extractContextFromRequest(req: ExpressRequest): JourneyContext;
|
|
114
169
|
/**
|
|
115
170
|
* Constructor.
|
|
116
171
|
*
|
|
@@ -154,6 +209,11 @@ export default class JourneyContext {
|
|
|
154
209
|
* @throws {TypeError} When page is invalid.
|
|
155
210
|
*/
|
|
156
211
|
getDataForPage(page: string | Page): object;
|
|
212
|
+
/**
|
|
213
|
+
* Get all data.
|
|
214
|
+
*
|
|
215
|
+
* @returns {object} Page data
|
|
216
|
+
*/
|
|
157
217
|
getData(): object;
|
|
158
218
|
/**
|
|
159
219
|
* Overwrite the data context with a new object.
|
|
@@ -165,11 +225,6 @@ export default class JourneyContext {
|
|
|
165
225
|
/**
|
|
166
226
|
* Write field form data from a page HTML form, into the `data` model.
|
|
167
227
|
*
|
|
168
|
-
* By default this will store the data as-is, keyed against the page's
|
|
169
|
-
* waypoint ID. However, when passing a `Page` instance, its
|
|
170
|
-
* `fieldWriter()` method will be called to transform the provided formData
|
|
171
|
-
* before storing in `data`
|
|
172
|
-
*
|
|
173
228
|
* @param {string | Page} page Page waypoint ID, or Page object
|
|
174
229
|
* @param {object} webFormData Data to overwrite with
|
|
175
230
|
* @returns {JourneyContext} Chain
|
|
@@ -218,7 +273,15 @@ export default class JourneyContext {
|
|
|
218
273
|
* @returns {ValidationError[]} An array of errors
|
|
219
274
|
*/
|
|
220
275
|
getValidationErrorsForPage(pageId: string): ValidationError[];
|
|
221
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Same as `getValidationErrorsForPage()`, but the return value is
|
|
278
|
+
* an object whose keys are the field names, and values are the list of errors
|
|
279
|
+
* associated with that particular field.
|
|
280
|
+
*
|
|
281
|
+
* @param {string} pageId Page ID.
|
|
282
|
+
* @returns {object} Object indexed by field names; values containing list of errors
|
|
283
|
+
*/
|
|
284
|
+
getValidationErrorsForPageByField(pageId: string): object;
|
|
222
285
|
/**
|
|
223
286
|
* Determine whether the specified page has any errors in its validation
|
|
224
287
|
* context.
|
|
@@ -268,9 +331,17 @@ export default class JourneyContext {
|
|
|
268
331
|
* @returns {JourneyContext} Chain
|
|
269
332
|
*/
|
|
270
333
|
addEventListeners(events: ContextEvent[]): JourneyContext;
|
|
334
|
+
/**
|
|
335
|
+
* Execute all listeners for the given event.
|
|
336
|
+
*
|
|
337
|
+
* @param {object} params Params
|
|
338
|
+
* @param {string} params.event Event (waypoint-change | context-change)
|
|
339
|
+
* @param {object} params.session Session
|
|
340
|
+
* @returns {JourneyContext} Chain
|
|
341
|
+
*/
|
|
271
342
|
applyEventListeners({ event, session }: {
|
|
272
|
-
event:
|
|
273
|
-
session:
|
|
343
|
+
event: string;
|
|
344
|
+
session: object;
|
|
274
345
|
}): JourneyContext;
|
|
275
346
|
/**
|
|
276
347
|
* Convenience method to determine if this is the default context.
|
|
@@ -283,4 +354,5 @@ export default class JourneyContext {
|
|
|
283
354
|
export type Page = import('../casa').Page;
|
|
284
355
|
export type ContextEventHandler = import('../casa').ContextEventHandler;
|
|
285
356
|
export type ContextEvent = import('../casa').ContextEvent;
|
|
357
|
+
export type ExpressRequest = import('express').Request;
|
|
286
358
|
import ValidationError from "./ValidationError.js";
|