@dwp/govuk-casa 9.0.0 → 9.2.0
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 +9 -9
- package/dist/assets/css/casa.css +1 -1
- package/dist/assets/css/casa.css.map +1 -1
- package/dist/casa.d.ts +122 -95
- package/dist/casa.js +119 -86
- package/dist/casa.js.map +1 -1
- package/dist/lib/CasaTemplateLoader.d.ts +4 -4
- package/dist/lib/CasaTemplateLoader.js +16 -16
- package/dist/lib/CasaTemplateLoader.js.map +1 -1
- package/dist/lib/JourneyContext.d.ts +58 -40
- package/dist/lib/JourneyContext.js +132 -75
- package/dist/lib/JourneyContext.js.map +1 -1
- package/dist/lib/MutableRouter.d.ts +40 -41
- package/dist/lib/MutableRouter.js +64 -71
- package/dist/lib/MutableRouter.js.map +1 -1
- package/dist/lib/Plan.d.ts +29 -26
- package/dist/lib/Plan.js +85 -71
- package/dist/lib/Plan.js.map +1 -1
- package/dist/lib/ValidationError.d.ts +16 -15
- package/dist/lib/ValidationError.js +21 -20
- package/dist/lib/ValidationError.js.map +1 -1
- package/dist/lib/ValidatorFactory.d.ts +15 -13
- package/dist/lib/ValidatorFactory.js +14 -12
- package/dist/lib/ValidatorFactory.js.map +1 -1
- package/dist/lib/configuration-ingestor.d.ts +37 -40
- package/dist/lib/configuration-ingestor.js +93 -93
- package/dist/lib/configuration-ingestor.js.map +1 -1
- package/dist/lib/configure.d.ts +6 -6
- package/dist/lib/configure.js +14 -12
- package/dist/lib/configure.js.map +1 -1
- package/dist/lib/constants.d.ts +1 -3
- package/dist/lib/constants.js +9 -11
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/context-id-generators.d.ts +3 -5
- package/dist/lib/context-id-generators.js +7 -6
- package/dist/lib/context-id-generators.js.map +1 -1
- package/dist/lib/end-session.d.ts +4 -4
- package/dist/lib/end-session.js +5 -5
- package/dist/lib/field.d.ts +20 -18
- package/dist/lib/field.js +35 -48
- package/dist/lib/field.js.map +1 -1
- package/dist/lib/index.d.ts +13 -13
- package/dist/lib/logger.d.ts +7 -6
- package/dist/lib/logger.js +7 -7
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/mount.d.ts +5 -5
- package/dist/lib/mount.js +11 -10
- package/dist/lib/mount.js.map +1 -1
- package/dist/lib/nunjucks-filters.d.ts +10 -12
- package/dist/lib/nunjucks-filters.js +35 -35
- package/dist/lib/nunjucks-filters.js.map +1 -1
- package/dist/lib/nunjucks.d.ts +7 -5
- package/dist/lib/nunjucks.js +10 -8
- package/dist/lib/nunjucks.js.map +1 -1
- package/dist/lib/utils.d.ts +19 -19
- package/dist/lib/utils.js +62 -55
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/validators/dateObject.d.ts +29 -22
- package/dist/lib/validators/dateObject.js +58 -49
- package/dist/lib/validators/dateObject.js.map +1 -1
- package/dist/lib/validators/email.d.ts +4 -4
- package/dist/lib/validators/email.js +4 -4
- package/dist/lib/validators/inArray.d.ts +4 -4
- package/dist/lib/validators/inArray.js +7 -8
- package/dist/lib/validators/inArray.js.map +1 -1
- package/dist/lib/validators/index.d.ts +10 -10
- package/dist/lib/validators/index.js +1 -3
- package/dist/lib/validators/index.js.map +1 -1
- package/dist/lib/validators/nino.d.ts +9 -8
- package/dist/lib/validators/nino.js +14 -10
- package/dist/lib/validators/nino.js.map +1 -1
- package/dist/lib/validators/postalAddressObject.d.ts +37 -24
- package/dist/lib/validators/postalAddressObject.js +65 -46
- package/dist/lib/validators/postalAddressObject.js.map +1 -1
- package/dist/lib/validators/range.d.ts +12 -8
- package/dist/lib/validators/range.js +11 -9
- package/dist/lib/validators/range.js.map +1 -1
- package/dist/lib/validators/regex.d.ts +4 -4
- package/dist/lib/validators/regex.js +5 -5
- package/dist/lib/validators/required.d.ts +6 -6
- package/dist/lib/validators/required.js +9 -11
- package/dist/lib/validators/required.js.map +1 -1
- package/dist/lib/validators/strlen.d.ts +12 -8
- package/dist/lib/validators/strlen.js +13 -11
- package/dist/lib/validators/strlen.js.map +1 -1
- package/dist/lib/validators/wordCount.d.ts +12 -8
- package/dist/lib/validators/wordCount.js +15 -11
- package/dist/lib/validators/wordCount.js.map +1 -1
- package/dist/lib/waypoint-url.d.ts +16 -13
- package/dist/lib/waypoint-url.js +39 -36
- package/dist/lib/waypoint-url.js.map +1 -1
- package/dist/middleware/body-parser.d.ts +1 -1
- package/dist/middleware/body-parser.js +6 -6
- package/dist/middleware/body-parser.js.map +1 -1
- package/dist/middleware/data.d.ts +1 -1
- package/dist/middleware/data.js +8 -7
- package/dist/middleware/data.js.map +1 -1
- package/dist/middleware/gather-fields.d.ts +2 -2
- package/dist/middleware/gather-fields.js +6 -4
- package/dist/middleware/gather-fields.js.map +1 -1
- package/dist/middleware/i18n.js +13 -15
- package/dist/middleware/i18n.js.map +1 -1
- package/dist/middleware/post.js +30 -18
- package/dist/middleware/post.js.map +1 -1
- package/dist/middleware/pre.d.ts +2 -2
- package/dist/middleware/pre.js +46 -27
- package/dist/middleware/pre.js.map +1 -1
- package/dist/middleware/progress-journey.d.ts +1 -1
- package/dist/middleware/progress-journey.js +5 -5
- package/dist/middleware/progress-journey.js.map +1 -1
- package/dist/middleware/sanitise-fields.d.ts +1 -1
- package/dist/middleware/sanitise-fields.js +13 -11
- package/dist/middleware/sanitise-fields.js.map +1 -1
- package/dist/middleware/serve-first-waypoint.d.ts +3 -3
- package/dist/middleware/serve-first-waypoint.js +8 -6
- package/dist/middleware/serve-first-waypoint.js.map +1 -1
- package/dist/middleware/session.js +14 -11
- package/dist/middleware/session.js.map +1 -1
- package/dist/middleware/skip-waypoint.d.ts +1 -1
- package/dist/middleware/skip-waypoint.js +5 -9
- package/dist/middleware/skip-waypoint.js.map +1 -1
- package/dist/middleware/steer-journey.d.ts +1 -1
- package/dist/middleware/steer-journey.js +16 -14
- package/dist/middleware/steer-journey.js.map +1 -1
- package/dist/middleware/strip-proxy-path.d.ts +1 -1
- package/dist/middleware/strip-proxy-path.js +3 -3
- package/dist/middleware/strip-proxy-path.js.map +1 -1
- package/dist/middleware/validate-fields.d.ts +1 -1
- package/dist/middleware/validate-fields.js +2 -5
- package/dist/middleware/validate-fields.js.map +1 -1
- package/dist/routes/ancillary.d.ts +3 -3
- package/dist/routes/ancillary.js +4 -4
- package/dist/routes/ancillary.js.map +1 -1
- package/dist/routes/journey.d.ts +2 -2
- package/dist/routes/journey.js +91 -39
- package/dist/routes/journey.js.map +1 -1
- package/dist/routes/static.d.ts +7 -5
- package/dist/routes/static.js +20 -19
- package/dist/routes/static.js.map +1 -1
- package/package.json +20 -19
- package/src/casa.js +133 -100
- package/src/lib/CasaTemplateLoader.js +24 -19
- package/src/lib/JourneyContext.js +190 -107
- package/src/lib/MutableRouter.js +72 -74
- package/src/lib/Plan.js +145 -97
- package/src/lib/ValidationError.js +25 -21
- package/src/lib/ValidatorFactory.js +17 -13
- package/src/lib/configuration-ingestor.js +147 -110
- package/src/lib/configure.js +34 -32
- package/src/lib/constants.js +9 -11
- package/src/lib/context-id-generators.js +40 -43
- package/src/lib/end-session.js +6 -6
- package/src/lib/field.js +69 -58
- package/src/lib/index.js +12 -12
- package/src/lib/logger.js +9 -9
- package/src/lib/mount.js +70 -74
- package/src/lib/nunjucks-filters.js +56 -59
- package/src/lib/nunjucks.js +23 -18
- package/src/lib/utils.js +78 -57
- package/src/lib/validators/dateObject.js +71 -60
- package/src/lib/validators/email.js +8 -8
- package/src/lib/validators/inArray.js +10 -11
- package/src/lib/validators/index.js +12 -14
- package/src/lib/validators/nino.js +29 -15
- package/src/lib/validators/postalAddressObject.js +87 -63
- package/src/lib/validators/range.js +14 -12
- package/src/lib/validators/regex.js +8 -8
- package/src/lib/validators/required.js +16 -16
- package/src/lib/validators/strlen.js +16 -14
- package/src/lib/validators/wordCount.js +22 -14
- package/src/lib/waypoint-url.js +64 -46
- package/src/middleware/body-parser.js +10 -10
- package/src/middleware/csrf.js +1 -1
- package/src/middleware/data.js +28 -24
- package/src/middleware/gather-fields.js +10 -9
- package/src/middleware/i18n.js +35 -37
- package/src/middleware/post.js +41 -21
- package/src/middleware/pre.js +62 -41
- package/src/middleware/progress-journey.js +32 -18
- package/src/middleware/sanitise-fields.js +43 -20
- package/src/middleware/serve-first-waypoint.js +14 -12
- package/src/middleware/session.js +74 -61
- package/src/middleware/skip-waypoint.js +8 -15
- package/src/middleware/steer-journey.js +40 -28
- package/src/middleware/strip-proxy-path.js +8 -7
- package/src/middleware/validate-fields.js +5 -12
- package/src/routes/ancillary.js +5 -7
- package/src/routes/journey.js +159 -85
- package/src/routes/static.js +62 -29
- package/views/casa/components/character-count/README.md +2 -2
- package/views/casa/components/checkboxes/README.md +6 -6
- package/views/casa/components/date-input/README.md +7 -7
- package/views/casa/components/input/README.md +2 -2
- package/views/casa/components/journey-form/README.md +33 -14
- package/views/casa/components/postal-address-object/README.md +4 -4
- package/views/casa/components/radios/README.md +6 -6
- package/views/casa/components/select/README.md +6 -6
- package/views/casa/components/textarea/README.md +2 -2
- package/views/casa/layouts/main.njk +2 -1
package/src/casa.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// NOTE: Any changes made here must be reflected in `scripts/esm-wrapper.js`
|
|
2
|
-
import configure from
|
|
3
|
-
import validators from
|
|
4
|
-
import field from
|
|
5
|
-
import Plan from
|
|
6
|
-
import JourneyContext from
|
|
7
|
-
import ValidatorFactory from
|
|
8
|
-
import ValidationError from
|
|
9
|
-
import MutableRouter from
|
|
10
|
-
import waypointUrl from
|
|
11
|
-
import endSession from
|
|
12
|
-
import * as nunjucksFilters from
|
|
13
|
-
import * as constants from
|
|
14
|
-
import * as contextIdGenerators from
|
|
2
|
+
import configure from "./lib/configure.js";
|
|
3
|
+
import validators from "./lib/validators/index.js";
|
|
4
|
+
import field from "./lib/field.js";
|
|
5
|
+
import Plan from "./lib/Plan.js";
|
|
6
|
+
import JourneyContext from "./lib/JourneyContext.js";
|
|
7
|
+
import ValidatorFactory from "./lib/ValidatorFactory.js";
|
|
8
|
+
import ValidationError from "./lib/ValidationError.js";
|
|
9
|
+
import MutableRouter from "./lib/MutableRouter.js";
|
|
10
|
+
import waypointUrl from "./lib/waypoint-url.js";
|
|
11
|
+
import endSession from "./lib/end-session.js";
|
|
12
|
+
import * as nunjucksFilters from "./lib/nunjucks-filters.js";
|
|
13
|
+
import * as constants from "./lib/constants.js";
|
|
14
|
+
import * as contextIdGenerators from "./lib/context-id-generators.js";
|
|
15
15
|
|
|
16
16
|
/** @module @dwp/govuk-casa */
|
|
17
17
|
export {
|
|
@@ -41,9 +41,7 @@ export {
|
|
|
41
41
|
/* ----------------------------------------------------------------- Typedefs */
|
|
42
42
|
// These exist here so that consumer can import CASA's internal types
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {import('./lib/field').PageField} PageField
|
|
46
|
-
*/
|
|
44
|
+
/** @typedef {import("./lib/field").PageField} PageField */
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
47
|
* @typedef {object} ContextEventHandlerOptions
|
|
@@ -61,7 +59,8 @@ export {
|
|
|
61
59
|
|
|
62
60
|
/**
|
|
63
61
|
* @typedef {object} ContextEventUserInfo
|
|
64
|
-
* @property {symbol} [casaRequestPhase] Request phase at which event is
|
|
62
|
+
* @property {symbol} [casaRequestPhase] Request phase at which event is
|
|
63
|
+
* triggered
|
|
65
64
|
*/
|
|
66
65
|
|
|
67
66
|
/**
|
|
@@ -72,48 +71,58 @@ export {
|
|
|
72
71
|
*/
|
|
73
72
|
|
|
74
73
|
/**
|
|
75
|
-
* @typedef {object} Page Page configuration. A Page is the interactive
|
|
74
|
+
* @typedef {object} Page Page configuration. A Page is the interactive
|
|
75
|
+
* representation of a waypoint
|
|
76
76
|
* @property {string} waypoint The waypoint with which this page is associated
|
|
77
77
|
* @property {string} view Template path
|
|
78
|
-
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default [])
|
|
79
|
-
*
|
|
78
|
+
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default []).
|
|
79
|
+
* Default is `[]`
|
|
80
|
+
* @property {PageField[]} [fields=[]] Fields to be managed on this page
|
|
81
|
+
* (optional, default []). Default is `[]`
|
|
80
82
|
*/
|
|
81
83
|
|
|
82
84
|
/**
|
|
83
85
|
* @typedef {object} I18nOptions
|
|
84
86
|
* @property {string[]} dirs Directories to search for locale dictionaries
|
|
85
|
-
* @property {string[]} [locales=['en', 'cy']] Supported locales
|
|
87
|
+
* @property {string[]} [locales=['en', 'cy']] Supported locales. Default is
|
|
88
|
+
* `['en', 'cy']`
|
|
86
89
|
*/
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
92
|
* @typedef {object} GlobalHook Hook configuration
|
|
90
93
|
* @property {string} hook Hook name in format `<router>.<hook>`
|
|
91
|
-
* @property {Function} middleware Middleware function to insert at the hook
|
|
92
|
-
*
|
|
94
|
+
* @property {Function} middleware Middleware function to insert at the hook
|
|
95
|
+
* point
|
|
96
|
+
* @property {string | RegExp} [path=undefined] Only run if route path matches
|
|
97
|
+
* this string/regexp. Default is `undefined`
|
|
93
98
|
*/
|
|
94
99
|
|
|
95
100
|
/**
|
|
96
101
|
* @typedef {object} PageHook (extends GlobalHook)
|
|
97
102
|
* @property {string} hook Hook name (without a scope prefix)
|
|
98
|
-
* @property {Function} middleware Middleware function to insert at the hook
|
|
103
|
+
* @property {Function} middleware Middleware function to insert at the hook
|
|
104
|
+
* point
|
|
99
105
|
*/
|
|
100
106
|
|
|
101
107
|
/**
|
|
102
108
|
* @typedef {object} SessionOptions
|
|
103
|
-
* @property {string} [name=casasession] Session name
|
|
104
|
-
* @property {string} [secret=secret] Encryption secret
|
|
105
|
-
* @property {number} [ttl=3600] Session ttl (seconds)
|
|
106
|
-
* @property {boolean} [secure=false] Whether to use secure session cookies
|
|
107
|
-
*
|
|
109
|
+
* @property {string} [name=casasession] Session name. Default is `casasession`
|
|
110
|
+
* @property {string} [secret=secret] Encryption secret. Default is `secret`
|
|
111
|
+
* @property {number} [ttl=3600] Session ttl (seconds). Default is `3600`
|
|
112
|
+
* @property {boolean} [secure=false] Whether to use secure session cookies.
|
|
113
|
+
* Default is `false`
|
|
114
|
+
* @property {boolean | string} [cookieSameSite=true] SameSite (true = Strict).
|
|
115
|
+
* Default is `true`
|
|
108
116
|
* @property {object} [store] Session store (default MemoryStore)
|
|
109
|
-
* @property {string} [cookiePath]
|
|
110
|
-
*
|
|
117
|
+
* @property {string} [cookiePath] The URL path on which the session cookie is
|
|
118
|
+
* valid (defaults to '/')
|
|
111
119
|
*/
|
|
112
120
|
|
|
113
121
|
/**
|
|
114
122
|
* @typedef {object} IPlugin Plugin interface
|
|
115
123
|
* @property {PluginConfigureFunction} [configure] Modify the app config
|
|
116
|
-
* @property {PluginBootstrapFunction} [bootstrap] Modify post-configuration
|
|
124
|
+
* @property {PluginBootstrapFunction} [bootstrap] Modify post-configuration
|
|
125
|
+
* artifacts
|
|
117
126
|
*/
|
|
118
127
|
|
|
119
128
|
/**
|
|
@@ -135,17 +144,18 @@ export {
|
|
|
135
144
|
/**
|
|
136
145
|
* Mounting function.
|
|
137
146
|
*
|
|
138
|
-
* This will mount all of the routes and middleware in the correct order on
|
|
139
|
-
*
|
|
147
|
+
* This will mount all of the routes and middleware in the correct order on the
|
|
148
|
+
* given ExpressJS app.
|
|
140
149
|
*
|
|
141
150
|
* Once this is called, you will not be able to modify any of the routers as
|
|
142
151
|
* they will be "sealed".
|
|
143
152
|
*
|
|
144
153
|
* @callback Mounter
|
|
145
|
-
* @param {import(
|
|
154
|
+
* @param {import("express").Express} app Express application
|
|
146
155
|
* @param {object} opts Mounting options
|
|
147
|
-
* @param {string} [opts.route='/'] Optional route to attach all
|
|
148
|
-
*
|
|
156
|
+
* @param {string} [opts.route='/'] Optional route to attach all
|
|
157
|
+
* middleware/routers too. Default is `'/'`
|
|
158
|
+
* @returns {import("express").Express} The prepared ExpressJS app instance
|
|
149
159
|
*/
|
|
150
160
|
|
|
151
161
|
/**
|
|
@@ -153,76 +163,88 @@ export {
|
|
|
153
163
|
*
|
|
154
164
|
* @typedef {object} ConfigurationOptions Configuration options
|
|
155
165
|
* @property {string} [mountUrl] Prefix for all URLS in browser address bar
|
|
156
|
-
* @property {string[]} [views=[]] Template directories
|
|
166
|
+
* @property {string[]} [views=[]] Template directories. Default is `[]`
|
|
157
167
|
* @property {SessionOptions} [session] Session configuration
|
|
158
|
-
* @property {Page[]} [pages=[]] Pages the represent waypoints
|
|
159
|
-
* @property {GlobalHook[]} [hooks=[]] Hooks to apply
|
|
160
|
-
* @property {IPlugin[]} [plugins=[]] Plugins
|
|
168
|
+
* @property {Page[]} [pages=[]] Pages the represent waypoints. Default is `[]`
|
|
169
|
+
* @property {GlobalHook[]} [hooks=[]] Hooks to apply. Default is `[]`
|
|
170
|
+
* @property {IPlugin[]} [plugins=[]] Plugins. Default is `[]`
|
|
161
171
|
* @property {I18nOptions} [i18n] I18n configuration
|
|
162
172
|
* @property {Plan} [plan] CASA Plan
|
|
163
|
-
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events
|
|
164
|
-
*
|
|
165
|
-
* @property {
|
|
166
|
-
*
|
|
167
|
-
* @property {
|
|
168
|
-
*
|
|
173
|
+
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events.
|
|
174
|
+
* Default is `[]`
|
|
175
|
+
* @property {HelmetConfigurator} [helmetConfigurator] Helmet configuration
|
|
176
|
+
* manipulator function
|
|
177
|
+
* @property {number} [formMaxParams=25] Max number of form parameters to
|
|
178
|
+
* ingest. Default is `25`
|
|
179
|
+
* @property {number | string} [formMaxBytes="50KB"] Max total form payload size
|
|
180
|
+
* to ingest. Default is `"50KB"`
|
|
181
|
+
* @property {ContextIdGenerator} [contextIdGenerator] Custom context ID
|
|
182
|
+
* generator
|
|
183
|
+
* @property {symbol | Function} [errorVisibility] Option to keep page errors
|
|
184
|
+
* active on GET request
|
|
169
185
|
*/
|
|
170
186
|
|
|
171
187
|
/**
|
|
172
188
|
* @typedef {object} ConfigureResult Result of a call to configure() function
|
|
173
|
-
* @property {import(
|
|
189
|
+
* @property {import("nunjucks").Environment} nunjucksEnv Nunjucks environment
|
|
174
190
|
* @property {MutableRouter} staticRouter Router handling all static assets
|
|
175
191
|
* @property {MutableRouter} ancillaryRouter Router handling ancillary routes
|
|
176
192
|
* @property {MutableRouter} journeyRouter Router handling all waypoint requests
|
|
177
|
-
* @property {import(
|
|
178
|
-
*
|
|
179
|
-
* @property {import(
|
|
180
|
-
*
|
|
181
|
-
* @property {import(
|
|
182
|
-
*
|
|
183
|
-
* @property {import(
|
|
184
|
-
*
|
|
185
|
-
* @property {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
193
|
+
* @property {import("express").RequestHandler[]} preMiddleware Middleware
|
|
194
|
+
* mounted before everything
|
|
195
|
+
* @property {import("express").RequestHandler[]} postMiddleware Middleware
|
|
196
|
+
* mounted after everything
|
|
197
|
+
* @property {import("express").RequestHandler[]} csrfMiddleware CSRF get/set
|
|
198
|
+
* form middleware
|
|
199
|
+
* @property {import("express").RequestHandler} sessionMiddleware Session
|
|
200
|
+
* middleware
|
|
201
|
+
* @property {import("express").RequestHandler[]} cookieParserMiddleware
|
|
202
|
+
* Cookie-parsing middleware
|
|
203
|
+
* @property {import("express").RequestHandler[]} i18nMiddleware I18n
|
|
204
|
+
* preparation middleware
|
|
205
|
+
* @property {import("express").RequestHandler} bodyParserMiddleware Body
|
|
206
|
+
* parsing middleware
|
|
207
|
+
* @property {Mounter} mount Function used to mount all CASA artifacts onto an
|
|
208
|
+
* ExpressJS app
|
|
209
|
+
* @property {ConfigurationOptions} config Ingested config supplied to
|
|
210
|
+
* `configure()`
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Configuration for generating a ValidationError. i.e. `new
|
|
215
|
+
* ValidationError(configObject)` <br/><br/>
|
|
195
216
|
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* </pre>
|
|
217
|
+
* The `fieldKeySuffix` is used to differentiate errors attached to the same
|
|
218
|
+
* field name. For example, given these fields inputs ...<pre> <input
|
|
219
|
+
* name="dateOfBirth[dd]" /> <input name="dateOfBirth[mm]" /> <input
|
|
220
|
+
* name="dateOfBirth[yyyy]" /> </pre>
|
|
201
221
|
*
|
|
202
|
-
* If we wanted to generate an error specifically for the `dd`
|
|
203
|
-
*
|
|
204
|
-
* config.
|
|
205
|
-
* <br/><br/>
|
|
222
|
+
* If we wanted to generate an error specifically for the `dd` element, then
|
|
223
|
+
* we'd include `{ fieldKeySuffix: '[dd]' }` in this config. <br/><br/>
|
|
206
224
|
*
|
|
207
|
-
* We can also use `focusSuffix` to control which properties of an
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* <br/><br/>
|
|
225
|
+
* We can also use `focusSuffix` to control which properties of an object field
|
|
226
|
+
* should be highlighted with a red border when in error. Looking again at the
|
|
227
|
+
* `dateOfBirth` example above, if we did not specify any `focusSuffix`, then
|
|
228
|
+
* all three inputs would be highlighted. However, if we use `{ focusSuffix:
|
|
229
|
+
* ['[dd]', '[yyyy]'] }` then only the `[dd]` and `[yyyy]` inputs would be
|
|
230
|
+
* highlighted. <br/><br/>
|
|
214
231
|
*
|
|
215
|
-
* The `fieldHref` and `field` properties are strictly for
|
|
216
|
-
*
|
|
232
|
+
* The `fieldHref` and `field` properties are strictly for internal use only and
|
|
233
|
+
* public access may be removed at any point.
|
|
217
234
|
*
|
|
218
235
|
* @typedef {object} ErrorMessageConfigObject
|
|
219
236
|
* @property {string} summary Summary message
|
|
220
|
-
* @property {string} [inline] Inline message (@deprecated now uses summary
|
|
221
|
-
*
|
|
222
|
-
* @property {string} [
|
|
223
|
-
*
|
|
237
|
+
* @property {string} [inline] Inline message (@deprecated now uses summary
|
|
238
|
+
* everywhere)
|
|
239
|
+
* @property {string | string[]} [focusSuffix] String(s) to append to URL hash
|
|
240
|
+
* for focusing inputs
|
|
241
|
+
* @property {string} [fieldKeySuffix] Object fields may use this to show errors
|
|
242
|
+
* per sub-property
|
|
243
|
+
* @property {object | ErrorMessageVariablesGenerator} [variables]
|
|
244
|
+
* Interpolation variables
|
|
224
245
|
* @property {string} [validator] Name of the validator
|
|
225
|
-
* @property {string} [fieldHref] (internal) URL hash to link to field in UI,
|
|
246
|
+
* @property {string} [fieldHref] (internal) URL hash to link to field in UI,
|
|
247
|
+
* i.e `#f-..`
|
|
226
248
|
* @property {string} [field] (internal) Field name, including any focus suffix
|
|
227
249
|
*/
|
|
228
250
|
|
|
@@ -238,11 +260,14 @@ export {
|
|
|
238
260
|
/**
|
|
239
261
|
* @callback ErrorMessageConfigGenerator
|
|
240
262
|
* @param {ValidateContext} dataContext Data context
|
|
241
|
-
* @returns {string|ErrorMessageConfigObject} Compiled error message config
|
|
263
|
+
* @returns {string | ErrorMessageConfigObject} Compiled error message config
|
|
242
264
|
*/
|
|
243
265
|
|
|
244
266
|
/**
|
|
245
|
-
* @typedef {string
|
|
267
|
+
* @typedef {string
|
|
268
|
+
* | ErrorMessageConfigObject
|
|
269
|
+
* | ErrorMessageConfigGenerator
|
|
270
|
+
* | Error} ErrorMessageConfig
|
|
246
271
|
*/
|
|
247
272
|
|
|
248
273
|
/**
|
|
@@ -270,7 +295,8 @@ export {
|
|
|
270
295
|
/**
|
|
271
296
|
* @typedef {object} Validator
|
|
272
297
|
* @property {ValidateFunction} validate Validation function
|
|
273
|
-
* @property {FieldProcessorFunction} sanitise Sanitise a given value prior to
|
|
298
|
+
* @property {FieldProcessorFunction} sanitise Sanitise a given value prior to
|
|
299
|
+
* validation
|
|
274
300
|
* @property {object} config Configuration
|
|
275
301
|
* @property {string} name Validator name
|
|
276
302
|
*/
|
|
@@ -308,29 +334,34 @@ export {
|
|
|
308
334
|
|
|
309
335
|
/**
|
|
310
336
|
* @typedef PlanTraverseOptions
|
|
311
|
-
* @property {string} [startWaypoint] Waypoint from which to start (defaults to
|
|
337
|
+
* @property {string} [startWaypoint] Waypoint from which to start (defaults to
|
|
338
|
+
* first in list)
|
|
312
339
|
* @property {string} routeName Follow routes matching this name (next | prev)
|
|
313
340
|
* @property {Map} history Used to detect loops in traversal (INTERNAL USE ONLY)
|
|
314
|
-
* @property {Function} [stopCondition] If true, traversal will be stopped
|
|
315
|
-
*
|
|
341
|
+
* @property {Function} [stopCondition] If true, traversal will be stopped
|
|
342
|
+
* (useful for performance)
|
|
343
|
+
* @property {string | PlanArbiter} [arbiter] Multiple target routes found, this
|
|
344
|
+
* decides which to use
|
|
316
345
|
*/
|
|
317
346
|
|
|
318
347
|
/**
|
|
319
348
|
* @typedef {object} PlanArbiterParams
|
|
320
349
|
* @property {PlanRoute[]} targets Potential target routes that need arbitration
|
|
321
350
|
* @property {JourneyContext} journeyContext Journey Context
|
|
322
|
-
* @property {PlanTraverseOptions} traverseOptions Original traverse options
|
|
351
|
+
* @property {PlanTraverseOptions} traverseOptions Original traverse options
|
|
352
|
+
* passed to `traverse()`
|
|
323
353
|
*/
|
|
324
354
|
|
|
325
355
|
/**
|
|
326
356
|
* @callback PlanArbiter
|
|
327
357
|
* @param {PlanArbiterParams} route Route metadata
|
|
328
|
-
* @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter
|
|
358
|
+
* @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter
|
|
359
|
+
* could eliminate
|
|
329
360
|
*/
|
|
330
361
|
|
|
331
362
|
/**
|
|
332
363
|
* @typedef {object} JourneyContextObject Journey Context Object
|
|
333
|
-
* @property {Record<string,any>} [data] Data
|
|
364
|
+
* @property {Record<string, any>} [data] Data
|
|
334
365
|
* @property {any} [validation] Validation state
|
|
335
366
|
* @property {any} [nav] Navigation meta
|
|
336
367
|
* @property {any} [identity] Identity meta
|
|
@@ -339,8 +370,9 @@ export {
|
|
|
339
370
|
/**
|
|
340
371
|
* @typedef ContextIdGeneratorParams
|
|
341
372
|
* @property {object} args Arguments
|
|
342
|
-
* @property {import(
|
|
343
|
-
* @property {[string]} args.reservedIds List of IDs already in use in session
|
|
373
|
+
* @property {import("express").Request} args.req Request
|
|
374
|
+
* @property {[string]} args.reservedIds List of IDs already in use in session
|
|
375
|
+
* or request
|
|
344
376
|
*/
|
|
345
377
|
|
|
346
378
|
/**
|
|
@@ -348,6 +380,7 @@ export {
|
|
|
348
380
|
* any other context IDs in the given session.
|
|
349
381
|
*
|
|
350
382
|
* The resulting ID must match these criteria:
|
|
383
|
+
*
|
|
351
384
|
* - A string
|
|
352
385
|
* - Between 1 and 64 characters
|
|
353
386
|
* - Contain only the characters a-z, 0-9, -
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { FileSystemLoader } from
|
|
1
|
+
import { FileSystemLoader } from "nunjucks";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
+
* @typedef {import("nunjucks").FileSystemLoaderOptions} FileSystemLoaderOptions
|
|
4
5
|
* @access private
|
|
5
|
-
* @typedef {import('nunjucks').FileSystemLoaderOptions} FileSystemLoaderOptions
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
+
* @typedef {import("nunjucks").LoaderSource} LoaderSource
|
|
9
10
|
* @access private
|
|
10
|
-
* @typedef {import('nunjucks').LoaderSource} LoaderSource
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const VALID_BLOCKS = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
"beforeContent",
|
|
15
|
+
"bodyEnd",
|
|
16
|
+
"bodyStart",
|
|
17
|
+
"casaPageTitle",
|
|
18
|
+
"content",
|
|
19
|
+
"footer",
|
|
20
|
+
"head",
|
|
21
|
+
"header",
|
|
22
|
+
"headIcons",
|
|
23
|
+
"journey_form",
|
|
24
|
+
"main",
|
|
25
|
+
"pageTitle",
|
|
26
|
+
"skipLink",
|
|
27
27
|
];
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -33,8 +33,8 @@ const VALID_BLOCKS = [
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* @access private
|
|
37
36
|
* @augments FileSystemLoader
|
|
37
|
+
* @access private
|
|
38
38
|
*/
|
|
39
39
|
export default class CasaTemplateLoader extends FileSystemLoader {
|
|
40
40
|
#blockModifiers;
|
|
@@ -73,7 +73,9 @@ export default class CasaTemplateLoader extends FileSystemLoader {
|
|
|
73
73
|
modifyBlock(block, modifier) {
|
|
74
74
|
// Limit to only known block so the user can't do general string replacements
|
|
75
75
|
if (!VALID_BLOCKS.includes(block)) {
|
|
76
|
-
throw new Error(
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Block "${String(block)}" is not a recognised template block.`,
|
|
78
|
+
);
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
this.#blockModifiers.push({
|
|
@@ -96,7 +98,10 @@ export default class CasaTemplateLoader extends FileSystemLoader {
|
|
|
96
98
|
const { block, modifier } = this.#blockModifiers[i];
|
|
97
99
|
if (source.src.indexOf(`block ${block}`) > -1) {
|
|
98
100
|
/* eslint-disable-next-line no-param-reassign */
|
|
99
|
-
source.src = source.src.replace(
|
|
101
|
+
source.src = source.src.replace(
|
|
102
|
+
`block ${block} %}`,
|
|
103
|
+
`block ${block} %}${modifier(name)}`,
|
|
104
|
+
);
|
|
100
105
|
}
|
|
101
106
|
}
|
|
102
107
|
return source;
|