@dwp/govuk-casa 8.15.0 → 9.1.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.
Files changed (201) hide show
  1. package/README.md +9 -9
  2. package/dist/assets/css/casa.css +2 -1
  3. package/dist/assets/css/casa.css.map +1 -0
  4. package/dist/casa.d.ts +122 -99
  5. package/dist/casa.js +120 -88
  6. package/dist/casa.js.map +1 -1
  7. package/dist/lib/CasaTemplateLoader.d.ts +4 -4
  8. package/dist/lib/CasaTemplateLoader.js +16 -16
  9. package/dist/lib/CasaTemplateLoader.js.map +1 -1
  10. package/dist/lib/JourneyContext.d.ts +38 -40
  11. package/dist/lib/JourneyContext.js +89 -75
  12. package/dist/lib/JourneyContext.js.map +1 -1
  13. package/dist/lib/MutableRouter.d.ts +40 -41
  14. package/dist/lib/MutableRouter.js +64 -71
  15. package/dist/lib/MutableRouter.js.map +1 -1
  16. package/dist/lib/Plan.d.ts +29 -26
  17. package/dist/lib/Plan.js +85 -71
  18. package/dist/lib/Plan.js.map +1 -1
  19. package/dist/lib/ValidationError.d.ts +16 -15
  20. package/dist/lib/ValidationError.js +21 -20
  21. package/dist/lib/ValidationError.js.map +1 -1
  22. package/dist/lib/ValidatorFactory.d.ts +15 -13
  23. package/dist/lib/ValidatorFactory.js +14 -12
  24. package/dist/lib/ValidatorFactory.js.map +1 -1
  25. package/dist/lib/configuration-ingestor.d.ts +37 -40
  26. package/dist/lib/configuration-ingestor.js +93 -93
  27. package/dist/lib/configuration-ingestor.js.map +1 -1
  28. package/dist/lib/configure.d.ts +6 -6
  29. package/dist/lib/configure.js +14 -12
  30. package/dist/lib/configure.js.map +1 -1
  31. package/dist/lib/constants.d.ts +1 -3
  32. package/dist/lib/constants.js +9 -11
  33. package/dist/lib/constants.js.map +1 -1
  34. package/dist/lib/context-id-generators.d.ts +3 -5
  35. package/dist/lib/context-id-generators.js +7 -6
  36. package/dist/lib/context-id-generators.js.map +1 -1
  37. package/dist/lib/end-session.d.ts +4 -4
  38. package/dist/lib/end-session.js +5 -5
  39. package/dist/lib/field.d.ts +24 -29
  40. package/dist/lib/field.js +41 -70
  41. package/dist/lib/field.js.map +1 -1
  42. package/dist/lib/index.d.ts +13 -13
  43. package/dist/lib/logger.d.ts +7 -6
  44. package/dist/lib/logger.js +7 -7
  45. package/dist/lib/logger.js.map +1 -1
  46. package/dist/lib/mount.d.ts +5 -5
  47. package/dist/lib/mount.js +12 -17
  48. package/dist/lib/mount.js.map +1 -1
  49. package/dist/lib/nunjucks-filters.d.ts +10 -12
  50. package/dist/lib/nunjucks-filters.js +35 -35
  51. package/dist/lib/nunjucks-filters.js.map +1 -1
  52. package/dist/lib/nunjucks.d.ts +7 -5
  53. package/dist/lib/nunjucks.js +10 -8
  54. package/dist/lib/nunjucks.js.map +1 -1
  55. package/dist/lib/utils.d.ts +19 -19
  56. package/dist/lib/utils.js +62 -55
  57. package/dist/lib/utils.js.map +1 -1
  58. package/dist/lib/validators/dateObject.d.ts +29 -22
  59. package/dist/lib/validators/dateObject.js +58 -49
  60. package/dist/lib/validators/dateObject.js.map +1 -1
  61. package/dist/lib/validators/email.d.ts +4 -4
  62. package/dist/lib/validators/email.js +4 -4
  63. package/dist/lib/validators/inArray.d.ts +4 -4
  64. package/dist/lib/validators/inArray.js +7 -8
  65. package/dist/lib/validators/inArray.js.map +1 -1
  66. package/dist/lib/validators/index.d.ts +10 -10
  67. package/dist/lib/validators/index.js +1 -3
  68. package/dist/lib/validators/index.js.map +1 -1
  69. package/dist/lib/validators/nino.d.ts +9 -8
  70. package/dist/lib/validators/nino.js +14 -10
  71. package/dist/lib/validators/nino.js.map +1 -1
  72. package/dist/lib/validators/postalAddressObject.d.ts +37 -24
  73. package/dist/lib/validators/postalAddressObject.js +65 -46
  74. package/dist/lib/validators/postalAddressObject.js.map +1 -1
  75. package/dist/lib/validators/range.d.ts +12 -8
  76. package/dist/lib/validators/range.js +11 -9
  77. package/dist/lib/validators/range.js.map +1 -1
  78. package/dist/lib/validators/regex.d.ts +4 -4
  79. package/dist/lib/validators/regex.js +5 -5
  80. package/dist/lib/validators/required.d.ts +6 -6
  81. package/dist/lib/validators/required.js +9 -11
  82. package/dist/lib/validators/required.js.map +1 -1
  83. package/dist/lib/validators/strlen.d.ts +12 -8
  84. package/dist/lib/validators/strlen.js +13 -11
  85. package/dist/lib/validators/strlen.js.map +1 -1
  86. package/dist/lib/validators/wordCount.d.ts +12 -8
  87. package/dist/lib/validators/wordCount.js +15 -11
  88. package/dist/lib/validators/wordCount.js.map +1 -1
  89. package/dist/lib/waypoint-url.d.ts +16 -13
  90. package/dist/lib/waypoint-url.js +39 -36
  91. package/dist/lib/waypoint-url.js.map +1 -1
  92. package/dist/middleware/body-parser.d.ts +1 -1
  93. package/dist/middleware/body-parser.js +6 -6
  94. package/dist/middleware/body-parser.js.map +1 -1
  95. package/dist/middleware/data.d.ts +1 -1
  96. package/dist/middleware/data.js +8 -7
  97. package/dist/middleware/data.js.map +1 -1
  98. package/dist/middleware/gather-fields.d.ts +2 -2
  99. package/dist/middleware/gather-fields.js +6 -4
  100. package/dist/middleware/gather-fields.js.map +1 -1
  101. package/dist/middleware/i18n.js +13 -15
  102. package/dist/middleware/i18n.js.map +1 -1
  103. package/dist/middleware/post.js +30 -18
  104. package/dist/middleware/post.js.map +1 -1
  105. package/dist/middleware/pre.d.ts +2 -2
  106. package/dist/middleware/pre.js +46 -26
  107. package/dist/middleware/pre.js.map +1 -1
  108. package/dist/middleware/progress-journey.d.ts +1 -1
  109. package/dist/middleware/progress-journey.js +5 -5
  110. package/dist/middleware/progress-journey.js.map +1 -1
  111. package/dist/middleware/sanitise-fields.d.ts +1 -1
  112. package/dist/middleware/sanitise-fields.js +13 -11
  113. package/dist/middleware/sanitise-fields.js.map +1 -1
  114. package/dist/middleware/serve-first-waypoint.d.ts +3 -3
  115. package/dist/middleware/serve-first-waypoint.js +8 -6
  116. package/dist/middleware/serve-first-waypoint.js.map +1 -1
  117. package/dist/middleware/session.js +14 -11
  118. package/dist/middleware/session.js.map +1 -1
  119. package/dist/middleware/skip-waypoint.d.ts +1 -1
  120. package/dist/middleware/skip-waypoint.js +3 -3
  121. package/dist/middleware/skip-waypoint.js.map +1 -1
  122. package/dist/middleware/steer-journey.d.ts +1 -1
  123. package/dist/middleware/steer-journey.js +16 -14
  124. package/dist/middleware/steer-journey.js.map +1 -1
  125. package/dist/middleware/strip-proxy-path.d.ts +1 -1
  126. package/dist/middleware/strip-proxy-path.js +3 -3
  127. package/dist/middleware/strip-proxy-path.js.map +1 -1
  128. package/dist/middleware/validate-fields.d.ts +1 -1
  129. package/dist/middleware/validate-fields.js +2 -5
  130. package/dist/middleware/validate-fields.js.map +1 -1
  131. package/dist/routes/ancillary.d.ts +3 -3
  132. package/dist/routes/ancillary.js +4 -4
  133. package/dist/routes/ancillary.js.map +1 -1
  134. package/dist/routes/journey.d.ts +2 -2
  135. package/dist/routes/journey.js +91 -39
  136. package/dist/routes/journey.js.map +1 -1
  137. package/dist/routes/static.d.ts +7 -5
  138. package/dist/routes/static.js +20 -20
  139. package/dist/routes/static.js.map +1 -1
  140. package/package.json +17 -16
  141. package/src/casa.js +134 -102
  142. package/src/lib/CasaTemplateLoader.js +24 -19
  143. package/src/lib/JourneyContext.js +147 -107
  144. package/src/lib/MutableRouter.js +72 -74
  145. package/src/lib/Plan.js +145 -97
  146. package/src/lib/ValidationError.js +25 -21
  147. package/src/lib/ValidatorFactory.js +17 -13
  148. package/src/lib/configuration-ingestor.js +147 -110
  149. package/src/lib/configure.js +34 -32
  150. package/src/lib/constants.js +9 -11
  151. package/src/lib/context-id-generators.js +40 -43
  152. package/src/lib/end-session.js +6 -6
  153. package/src/lib/field.js +74 -78
  154. package/src/lib/index.js +12 -12
  155. package/src/lib/logger.js +9 -9
  156. package/src/lib/mount.js +70 -80
  157. package/src/lib/nunjucks-filters.js +56 -59
  158. package/src/lib/nunjucks.js +23 -18
  159. package/src/lib/utils.js +78 -57
  160. package/src/lib/validators/dateObject.js +71 -60
  161. package/src/lib/validators/email.js +8 -8
  162. package/src/lib/validators/inArray.js +10 -11
  163. package/src/lib/validators/index.js +12 -14
  164. package/src/lib/validators/nino.js +29 -15
  165. package/src/lib/validators/postalAddressObject.js +87 -63
  166. package/src/lib/validators/range.js +14 -12
  167. package/src/lib/validators/regex.js +8 -8
  168. package/src/lib/validators/required.js +16 -16
  169. package/src/lib/validators/strlen.js +16 -14
  170. package/src/lib/validators/wordCount.js +22 -14
  171. package/src/lib/waypoint-url.js +64 -46
  172. package/src/middleware/body-parser.js +10 -10
  173. package/src/middleware/csrf.js +1 -1
  174. package/src/middleware/data.js +28 -24
  175. package/src/middleware/gather-fields.js +10 -9
  176. package/src/middleware/i18n.js +35 -37
  177. package/src/middleware/post.js +41 -21
  178. package/src/middleware/pre.js +62 -40
  179. package/src/middleware/progress-journey.js +32 -18
  180. package/src/middleware/sanitise-fields.js +43 -20
  181. package/src/middleware/serve-first-waypoint.js +14 -12
  182. package/src/middleware/session.js +74 -61
  183. package/src/middleware/skip-waypoint.js +7 -9
  184. package/src/middleware/steer-journey.js +40 -28
  185. package/src/middleware/strip-proxy-path.js +8 -7
  186. package/src/middleware/validate-fields.js +5 -12
  187. package/src/routes/ancillary.js +5 -7
  188. package/src/routes/journey.js +159 -85
  189. package/src/routes/static.js +62 -30
  190. package/views/casa/components/character-count/README.md +2 -2
  191. package/views/casa/components/checkboxes/README.md +6 -6
  192. package/views/casa/components/date-input/README.md +7 -7
  193. package/views/casa/components/input/README.md +2 -2
  194. package/views/casa/components/journey-form/README.md +33 -14
  195. package/views/casa/components/postal-address-object/README.md +4 -4
  196. package/views/casa/components/radios/README.md +6 -6
  197. package/views/casa/components/select/README.md +6 -6
  198. package/views/casa/components/textarea/README.md +2 -2
  199. package/views/casa/partials/scripts.njk +5 -3
  200. package/views/casa/partials/styles.njk +1 -4
  201. package/dist/assets/css/casa-ie8.css +0 -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 './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';
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 triggered
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 representation of a waypoint
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
- * @property {PageField[]} [fields=[]] Fields to be managed on this page (optional, default [])
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 point
92
- * @property {string|RegExp} [path=undefined] Only run if route path matches this string/regexp
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 point
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
- * @property {boolean|string} [cookieSameSite=true] SameSite (true = Strict)
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] the URL path on which the session cookie
110
- * is valid (defaults to '/')
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 artifacts
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
- * the given ExpressJS app.
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('express').Express} app Express application
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 middleware/routers too
148
- * @returns {import('express').Express} The prepared ExpressJS app instance
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
- * @property {HelmetConfigurator} [helmetConfigurator] Helmet configuration manipulator function
165
- * @property {number} [formMaxParams=25] Max number of form parameters to ingest
166
- * @property {number|string} [formMaxBytes="50KB"] Max total form payload size to ingest
167
- * @property {ContextIdGenerator} [contextIdGenerator] Custom context ID generator
168
- * @property {symbol|Function} [errorVisibility] option to keep page errors active on GET request
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('nunjucks').Environment} nunjucksEnv Nunjucks environment
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('express').RequestHandler[]} preMiddleware Middleware mounted before everything
178
- * @property {import('express').RequestHandler[]} postMiddleware Middleware mounted after everything
179
- * @property {import('express').RequestHandler[]} csrfMiddleware CSRF get/set form middleware
180
- * @property {import('express').RequestHandler} sessionMiddleware Session middleware
181
- * @property {import('express').RequestHandler[]} cookieParserMiddleware Cookie-parsing middleware
182
- * @property {import('express').RequestHandler[]} i18nMiddleware I18n preparation middleware
183
- * @property {import('express').RequestHandler} bodyParserMiddleware Body parsing middleware
184
- * @property {Mounter} mount Function used to mount all CASA artifacts onto an ExpressJS app
185
- * @property {ConfigurationOptions} config Ingested config supplied to `configure()`
186
- */
187
-
188
- /**
189
- * Configuration for generating a ValidationError.
190
- * i.e. `new ValidationError(configObject)`
191
- * <br/><br/>
192
- *
193
- * The `fieldKeySuffix` is used to differentiate errors attached to
194
- * the same field name. For example, given these fields inputs ...
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
- * <pre>
197
- * &lt;input name="dateOfBirth[dd]" /&gt;
198
- * &lt;input name="dateOfBirth[mm]" /&gt;
199
- * &lt;input name="dateOfBirth[yyyy]" /&gt;
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
- * element, then we'd include `{ fieldKeySuffix: '[dd]' }` in this
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
- * object field should be highlighted with a red border when in error. Looking
209
- * again at the `dateOfBirth` example above, if we did not specify
210
- * any `focusSuffix`, then all three inputs would be highlighted.
211
- * However, if we use `{ focusSuffix: ['[dd]', '[yyyy]'] }` then only
212
- * the `[dd]` and `[yyyy]` inputs would be highlighted.
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
- * internal use only and public access may be removed at any point.
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 everywhere)
221
- * @property {string|string[]} [focusSuffix] String(s) to append to URL hash for focusing inputs
222
- * @property {string} [fieldKeySuffix] Object fields may use this to show errors per sub-property
223
- * @property {object|ErrorMessageVariablesGenerator} [variables] Interpolation variables
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, i.e `#f-..`
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|ErrorMessageConfigObject|ErrorMessageConfigGenerator|Error} ErrorMessageConfig
267
+ * @typedef {string
268
+ * | ErrorMessageConfigObject
269
+ * | ErrorMessageConfigGenerator
270
+ * | Error} ErrorMessageConfig
246
271
  */
247
272
 
248
273
  /**
@@ -257,7 +282,7 @@ export {
257
282
  /**
258
283
  * @callback ValidateFunction
259
284
  * @param {any} value
260
- * @param {ValidateContext} context Vaildation context
285
+ * @param {ValidateContext} context Validation context
261
286
  * @returns {ValidationError[]}
262
287
  */
263
288
 
@@ -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 validation
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
  */
@@ -280,7 +306,6 @@ export {
280
306
  * @property {string} fieldName Field name
281
307
  * @property {any} fieldValue Field value
282
308
  * @property {string} waypoint Waypoint
283
- * @property {string} waypointId [DEPRECATED] Waypoint (for backwards compatibility with v7)
284
309
  * @property {JourneyContext} journeyContext Journey Context
285
310
  */
286
311
 
@@ -309,29 +334,34 @@ export {
309
334
 
310
335
  /**
311
336
  * @typedef PlanTraverseOptions
312
- * @property {string} [startWaypoint] Waypoint from which to start (defaults to first in list)
337
+ * @property {string} [startWaypoint] Waypoint from which to start (defaults to
338
+ * first in list)
313
339
  * @property {string} routeName Follow routes matching this name (next | prev)
314
340
  * @property {Map} history Used to detect loops in traversal (INTERNAL USE ONLY)
315
- * @property {Function} [stopCondition] If true, traversal will be stopped (useful for performance)
316
- * @property {string|PlanArbiter} [arbiter] Multiple target routes found, this decides which to use
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
317
345
  */
318
346
 
319
347
  /**
320
348
  * @typedef {object} PlanArbiterParams
321
349
  * @property {PlanRoute[]} targets Potential target routes that need arbitration
322
350
  * @property {JourneyContext} journeyContext Journey Context
323
- * @property {PlanTraverseOptions} traverseOptions Original traverse options passed to `traverse()`
351
+ * @property {PlanTraverseOptions} traverseOptions Original traverse options
352
+ * passed to `traverse()`
324
353
  */
325
354
 
326
355
  /**
327
356
  * @callback PlanArbiter
328
357
  * @param {PlanArbiterParams} route Route metadata
329
- * @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter could eliminate
358
+ * @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter
359
+ * could eliminate
330
360
  */
331
361
 
332
362
  /**
333
363
  * @typedef {object} JourneyContextObject Journey Context Object
334
- * @property {Record<string,any>} [data] Data
364
+ * @property {Record<string, any>} [data] Data
335
365
  * @property {any} [validation] Validation state
336
366
  * @property {any} [nav] Navigation meta
337
367
  * @property {any} [identity] Identity meta
@@ -340,8 +370,9 @@ export {
340
370
  /**
341
371
  * @typedef ContextIdGeneratorParams
342
372
  * @property {object} args Arguments
343
- * @property {import('express').Request} args.req Request
344
- * @property {[string]} args.reservedIds List of IDs already in use in session or request
373
+ * @property {import("express").Request} args.req Request
374
+ * @property {[string]} args.reservedIds List of IDs already in use in session
375
+ * or request
345
376
  */
346
377
 
347
378
  /**
@@ -349,6 +380,7 @@ export {
349
380
  * any other context IDs in the given session.
350
381
  *
351
382
  * The resulting ID must match these criteria:
383
+ *
352
384
  * - A string
353
385
  * - Between 1 and 64 characters
354
386
  * - Contain only the characters a-z, 0-9, -
@@ -1,29 +1,29 @@
1
- import { FileSystemLoader } from 'nunjucks';
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
- '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',
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(`Block "${String(block)}" is not a recognised template block.`);
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(`block ${block} %}`, `block ${block} %}${modifier(name)}`);
101
+ source.src = source.src.replace(
102
+ `block ${block} %}`,
103
+ `block ${block} %}${modifier(name)}`,
104
+ );
100
105
  }
101
106
  }
102
107
  return source;