@dwp/govuk-casa 10.0.0 → 10.1.1

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/src/casa.js CHANGED
@@ -90,7 +90,7 @@ export {
90
90
  * representation of a waypoint
91
91
  * @property {string} waypoint The waypoint with which this page is associated
92
92
  * @property {string} view Template path
93
- * @property {ErrorVisibiltyFunction | symbol} errorVisibility Should page
93
+ * @property {ErrorVisibiltyFunction | symbol} [errorVisibility] Should page
94
94
  * validation errors be visible on GET requests
95
95
  * @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default []).
96
96
  * Default is `[]`
@@ -160,6 +160,14 @@ export {
160
160
  * @returns {HelmetOptions} The modified configuration object
161
161
  */
162
162
 
163
+ /**
164
+ * @typedef {Omit<
165
+ * import("nunjucks").Environment &
166
+ * import("./lib/CasaTemplateLoader.js").default,
167
+ * "getSource"
168
+ * >} CasaNunjucksEnvironment
169
+ */
170
+
163
171
  /**
164
172
  * Mounting function.
165
173
  *
@@ -171,9 +179,12 @@ export {
171
179
  *
172
180
  * @callback Mounter
173
181
  * @param {import("express").Express} app Express application
174
- * @param {object} opts Mounting options
182
+ * @param {object} [opts] Mounting options
175
183
  * @param {string} [opts.route='/'] Optional route to attach all
176
184
  * middleware/routers too. Default is `'/'`
185
+ * @param {boolean} [opts.serveFirstWaypoint=false] Automatically redirect
186
+ * requests to the mount route to the first waypoint in the plan. Default is
187
+ * `false`
177
188
  * @returns {import("express").Express} The prepared ExpressJS app instance
178
189
  */
179
190
 
@@ -205,7 +216,7 @@ export {
205
216
 
206
217
  /**
207
218
  * @typedef {object} ConfigureResult Result of a call to configure() function
208
- * @property {import("nunjucks").Environment} nunjucksEnv Nunjucks environment
219
+ * @property {CasaNunjucksEnvironment} nunjucksEnv Nunjucks environment
209
220
  * @property {MutableRouter} staticRouter Router handling all static assets
210
221
  * @property {MutableRouter} ancillaryRouter Router handling ancillary routes
211
222
  * @property {MutableRouter} journeyRouter Router handling all waypoint requests
@@ -218,6 +229,7 @@ export {
218
229
  * @property {RequestHandler[]} cookieParserMiddleware Cookie-parsing middleware
219
230
  * @property {RequestHandler[]} i18nMiddleware I18n preparation middleware
220
231
  * @property {RequestHandler} bodyParserMiddleware Body parsing middleware
232
+ * @property {RequestHandler[]} dataMiddleware Data decoration middleware
221
233
  * @property {Mounter} mount Function used to mount all CASA artifacts onto an
222
234
  * ExpressJS app
223
235
  * @property {ConfigurationOptions} config Ingested config supplied to
@@ -100,7 +100,7 @@ export default class MutableRouter {
100
100
  /**
101
101
  * Prepend middleware function(s) using the `all()` method.
102
102
  *
103
- * @param {string | RequestHandler} path Route path or middleware function
103
+ * @param {PathParams | RequestHandler} path Route path or middleware function
104
104
  * @param {...RequestHandler} callbacks Additional middleware functions
105
105
  * @returns {void}
106
106
  */
@@ -111,7 +111,7 @@ export default class MutableRouter {
111
111
  /**
112
112
  * Prepend middleware function(s) using the `get()` method.
113
113
  *
114
- * @param {string | RequestHandler} path Route path or middleware function
114
+ * @param {PathParams | RequestHandler} path Route path or middleware function
115
115
  * @param {...RequestHandler} callbacks Additional middleware functions
116
116
  * @returns {void}
117
117
  */
@@ -122,7 +122,7 @@ export default class MutableRouter {
122
122
  /**
123
123
  * Prepend middleware function(s) using the `post()` method.
124
124
  *
125
- * @param {string | RequestHandler} path Route path or middleware function
125
+ * @param {PathParams | RequestHandler} path Route path or middleware function
126
126
  * @param {...RequestHandler} callbacks Additional middleware functions
127
127
  * @returns {void}
128
128
  */
@@ -133,7 +133,7 @@ export default class MutableRouter {
133
133
  /**
134
134
  * Prepend middleware function(s) using the `delete()` method.
135
135
  *
136
- * @param {string | RequestHandler} path Route path or middleware function
136
+ * @param {PathParams | RequestHandler} path Route path or middleware function
137
137
  * @param {...RequestHandler} callbacks Additional middleware functions
138
138
  * @returns {void}
139
139
  */
@@ -144,7 +144,7 @@ export default class MutableRouter {
144
144
  /**
145
145
  * Prepend middleware function(s) using the `put()` method.
146
146
  *
147
- * @param {string | RequestHandler} path Route path or middleware function
147
+ * @param {PathParams | RequestHandler} path Route path or middleware function
148
148
  * @param {...RequestHandler} callbacks Additional middleware functions
149
149
  * @returns {void}
150
150
  */
@@ -155,8 +155,9 @@ export default class MutableRouter {
155
155
  /**
156
156
  * Prepend middleware function(s) using the `use()` method.
157
157
  *
158
- * @param {string | RequestHandler} path Route path or middleware function
159
- * @param {...RequestHandler} callbacks Additional middleware functions
158
+ * @param {PathParams | RequestHandlerParams} path Route path or middleware
159
+ * function
160
+ * @param {...RequestHandlerParams} callbacks Additional middleware functions
160
161
  * @returns {void}
161
162
  */
162
163
  prependUse(path, ...callbacks) {
@@ -168,7 +169,7 @@ export default class MutableRouter {
168
169
  /**
169
170
  * Replace middleware function(s) that were mounted using the `all()` method.
170
171
  *
171
- * @param {string | RequestHandler} path Route path or middleware function
172
+ * @param {PathParams | RequestHandler} path Route path or middleware function
172
173
  * @param {...RequestHandler} callbacks Additional middleware functions
173
174
  * @returns {void}
174
175
  */
@@ -179,7 +180,7 @@ export default class MutableRouter {
179
180
  /**
180
181
  * Replace middleware function(s) that were mounted using the `get()` method.
181
182
  *
182
- * @param {string | RequestHandler} path Route path or middleware function
183
+ * @param {PathParams | RequestHandler} path Route path or middleware function
183
184
  * @param {...RequestHandler} callbacks Additional middleware functions
184
185
  * @returns {void}
185
186
  */
@@ -190,7 +191,7 @@ export default class MutableRouter {
190
191
  /**
191
192
  * Replace middleware function(s) that were mounted using the `post()` method.
192
193
  *
193
- * @param {string | RequestHandler} path Route path or middleware function
194
+ * @param {PathParams | RequestHandler} path Route path or middleware function
194
195
  * @param {...RequestHandler} callbacks Additional middleware functions
195
196
  * @returns {void}
196
197
  */
@@ -202,7 +203,7 @@ export default class MutableRouter {
202
203
  * Replace middleware function(s) that were mounted using the `delete()`
203
204
  * method.
204
205
  *
205
- * @param {string | RequestHandler} path Route path or middleware function
206
+ * @param {PathParams | RequestHandler} path Route path or middleware function
206
207
  * @param {...RequestHandler} callbacks Additional middleware functions
207
208
  * @returns {void}
208
209
  */
@@ -213,7 +214,7 @@ export default class MutableRouter {
213
214
  /**
214
215
  * Replace middleware function(s) that were mounted using the `put()` method.
215
216
  *
216
- * @param {string | RequestHandler} path Route path or middleware function
217
+ * @param {PathParams | RequestHandler} path Route path or middleware function
217
218
  * @param {...RequestHandler} callbacks Additional middleware functions
218
219
  * @returns {void}
219
220
  */
@@ -224,8 +225,9 @@ export default class MutableRouter {
224
225
  /**
225
226
  * Replace middleware function(s) that were mounted using the `use()` method.
226
227
  *
227
- * @param {string | RequestHandler} path Route path or middleware function
228
- * @param {...RequestHandler} callbacks Additional middleware functions
228
+ * @param {PathParams | RequestHandlerParams} path Route path or middleware
229
+ * function
230
+ * @param {...RequestHandlerParams} callbacks Additional middleware functions
229
231
  * @returns {void}
230
232
  */
231
233
  replaceUse(path, ...callbacks) {
@@ -237,7 +239,7 @@ export default class MutableRouter {
237
239
  /**
238
240
  * Append middleware function(s) using the `all()` method.
239
241
  *
240
- * @param {string | RequestHandler} path Route path or middleware function
242
+ * @param {PathParams | RequestHandler} path Route path or middleware function
241
243
  * @param {...RequestHandler} callbacks Additional middleware functions
242
244
  * @returns {void}
243
245
  */
@@ -248,7 +250,7 @@ export default class MutableRouter {
248
250
  /**
249
251
  * Append middleware function(s) using the `get()` method.
250
252
  *
251
- * @param {string | RequestHandler} path Route path or middleware function
253
+ * @param {PathParams | RequestHandler} path Route path or middleware function
252
254
  * @param {...RequestHandler} callbacks Additional middleware functions
253
255
  * @returns {void}
254
256
  */
@@ -259,7 +261,7 @@ export default class MutableRouter {
259
261
  /**
260
262
  * Append middleware function(s) using the `post()` method.
261
263
  *
262
- * @param {string | RequestHandler} path Route path or middleware function
264
+ * @param {PathParams | RequestHandler} path Route path or middleware function
263
265
  * @param {...RequestHandler} callbacks Additional middleware functions
264
266
  * @returns {void}
265
267
  */
@@ -270,7 +272,7 @@ export default class MutableRouter {
270
272
  /**
271
273
  * Append middleware function(s) using the `delete()` method.
272
274
  *
273
- * @param {string | RequestHandler} path Route path or middleware function
275
+ * @param {PathParams | RequestHandler} path Route path or middleware function
274
276
  * @param {...RequestHandler} callbacks Additional middleware functions
275
277
  * @returns {void}
276
278
  */
@@ -281,7 +283,7 @@ export default class MutableRouter {
281
283
  /**
282
284
  * Append middleware function(s) using the `put()` method.
283
285
  *
284
- * @param {string | RequestHandler} path Route path or middleware function
286
+ * @param {PathParams | RequestHandler} path Route path or middleware function
285
287
  * @param {...RequestHandler} callbacks Additional middleware functions
286
288
  * @returns {void}
287
289
  */
@@ -292,8 +294,9 @@ export default class MutableRouter {
292
294
  /**
293
295
  * Append middleware function(s) using the `use()` method.
294
296
  *
295
- * @param {string | RequestHandler} path Route path or middleware function
296
- * @param {...RequestHandler} callbacks Additional middleware functions
297
+ * @param {PathParams | RequestHandlerParams} path Route path or middleware
298
+ * function
299
+ * @param {...RequestHandlerParams} callbacks Additional middleware functions
297
300
  * @returns {void}
298
301
  */
299
302
  use(path, ...callbacks) {
@@ -308,10 +311,12 @@ export default class MutableRouter {
308
311
  }
309
312
 
310
313
  /** @typedef {import("express").RequestHandler} RequestHandler */
314
+ /** @typedef {import("express-serve-static-core").PathParams} PathParams */
315
+ /** @typedef {import("express-serve-static-core").RequestHandlerParams} RequestHandlerParams */
311
316
 
312
317
  /**
313
318
  * @typedef {object} StackRoute Stack route
314
319
  * @property {string} method HTTP request method
315
- * @property {string} path Route path
316
- * @property {[string, ...RequestHandler[]]} args Router arguments
320
+ * @property {PathParams} path Route path
321
+ * @property {[PathParams, ...RequestHandler[]]} args Router arguments
317
322
  */
@@ -18,7 +18,8 @@ import {
18
18
  * Create a Nunjucks environment.
19
19
  *
20
20
  * @param {NunjucksOptions} options Nunjucks options
21
- * @returns {Environment} Nunjucks Environment instance
21
+ * @returns {import("../casa.js").CasaNunjucksEnvironment} Nunjucks Environment
22
+ * instance
22
23
  * @access private
23
24
  */
24
25
  export default function nunjucksConfig({ views = [] }) {
@@ -3,12 +3,14 @@ import logger from "../lib/logger.js";
3
3
 
4
4
  /**
5
5
  * @typedef {import("express").RequestHandler} RequestHandler
6
+ *
7
+ * @typedef {import("express").ErrorRequestHandler} ErrorRequestHandler
6
8
  * @access private
7
9
  */
8
10
 
9
11
  const log = logger("middleware:post");
10
12
 
11
- /** @returns {RequestHandler[]} Middleware functions */
13
+ /** @returns {[RequestHandler, ErrorRequestHandler]} Middleware functions */
12
14
  export default function postMiddleware() {
13
15
  return [
14
16
  (req, res) => {