@dwp/govuk-casa 9.7.0 → 10.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 (278) hide show
  1. package/dist/assets/css/casa.css +1 -1
  2. package/dist/assets/css/casa.css.map +1 -1
  3. package/dist/casa.d.ts +90 -44
  4. package/dist/casa.d.ts.map +1 -0
  5. package/dist/casa.js +85 -101
  6. package/dist/core-plugins/edit-snapshot/src/configure.d.ts +1 -0
  7. package/dist/core-plugins/edit-snapshot/src/configure.d.ts.map +1 -0
  8. package/dist/core-plugins/edit-snapshot/src/configure.js +7 -14
  9. package/dist/core-plugins/edit-snapshot/src/index.d.ts +1 -0
  10. package/dist/core-plugins/edit-snapshot/src/index.d.ts.map +1 -0
  11. package/dist/core-plugins/edit-snapshot/src/index.js +3 -9
  12. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts +2 -1
  13. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts.map +1 -0
  14. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js +8 -13
  15. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts +2 -1
  16. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts.map +1 -0
  17. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js +13 -18
  18. package/dist/core-plugins/edit-snapshot/src/utils.d.ts +8 -5
  19. package/dist/core-plugins/edit-snapshot/src/utils.d.ts.map +1 -0
  20. package/dist/core-plugins/edit-snapshot/src/utils.js +37 -19
  21. package/dist/core-plugins/index.d.ts +1 -0
  22. package/dist/core-plugins/index.d.ts.map +1 -0
  23. package/dist/core-plugins/index.js +1 -9
  24. package/dist/lib/CasaTemplateLoader.d.ts +1 -0
  25. package/dist/lib/CasaTemplateLoader.d.ts.map +1 -0
  26. package/dist/lib/CasaTemplateLoader.js +2 -6
  27. package/dist/lib/JourneyContext.d.ts +22 -11
  28. package/dist/lib/JourneyContext.d.ts.map +1 -0
  29. package/dist/lib/JourneyContext.js +40 -45
  30. package/dist/lib/MutableRouter.d.ts +79 -55
  31. package/dist/lib/MutableRouter.d.ts.map +1 -0
  32. package/dist/lib/MutableRouter.js +53 -45
  33. package/dist/lib/NullObject.d.ts +3 -0
  34. package/dist/lib/NullObject.d.ts.map +1 -0
  35. package/dist/lib/NullObject.js +3 -0
  36. package/dist/lib/Plan.d.ts +2 -1
  37. package/dist/lib/Plan.d.ts.map +1 -0
  38. package/dist/lib/Plan.js +44 -62
  39. package/dist/lib/ValidationError.d.ts +2 -1
  40. package/dist/lib/ValidationError.d.ts.map +1 -0
  41. package/dist/lib/ValidationError.js +3 -11
  42. package/dist/lib/ValidatorFactory.d.ts +5 -6
  43. package/dist/lib/ValidatorFactory.d.ts.map +1 -0
  44. package/dist/lib/ValidatorFactory.js +4 -12
  45. package/dist/lib/configuration-ingestor.d.ts +10 -22
  46. package/dist/lib/configuration-ingestor.d.ts.map +1 -0
  47. package/dist/lib/configuration-ingestor.js +61 -143
  48. package/dist/lib/configure.d.ts +2 -1
  49. package/dist/lib/configure.d.ts.map +1 -0
  50. package/dist/lib/configure.js +40 -52
  51. package/dist/lib/constants.d.ts +1 -0
  52. package/dist/lib/constants.d.ts.map +1 -0
  53. package/dist/lib/constants.js +8 -12
  54. package/dist/lib/context-id-generators.d.ts +1 -0
  55. package/dist/lib/context-id-generators.d.ts.map +1 -0
  56. package/dist/lib/context-id-generators.js +4 -9
  57. package/dist/lib/end-session.d.ts +2 -1
  58. package/dist/lib/end-session.d.ts.map +1 -0
  59. package/dist/lib/end-session.js +4 -11
  60. package/dist/lib/field.d.ts +2 -1
  61. package/dist/lib/field.d.ts.map +1 -0
  62. package/dist/lib/field.js +11 -21
  63. package/dist/lib/index.d.ts +1 -0
  64. package/dist/lib/index.d.ts.map +1 -0
  65. package/dist/lib/index.js +13 -65
  66. package/dist/lib/logger.d.ts +25 -2
  67. package/dist/lib/logger.d.ts.map +1 -0
  68. package/dist/lib/logger.js +18 -9
  69. package/dist/lib/mount.d.ts +1 -0
  70. package/dist/lib/mount.d.ts.map +1 -0
  71. package/dist/lib/mount.js +10 -16
  72. package/dist/lib/nunjucks-filters.d.ts +7 -3
  73. package/dist/lib/nunjucks-filters.d.ts.map +1 -0
  74. package/dist/lib/nunjucks-filters.js +58 -71
  75. package/dist/lib/nunjucks.d.ts +4 -4
  76. package/dist/lib/nunjucks.d.ts.map +1 -0
  77. package/dist/lib/nunjucks.js +14 -26
  78. package/dist/lib/utils.d.ts +4 -2
  79. package/dist/lib/utils.d.ts.map +1 -0
  80. package/dist/lib/utils.js +14 -28
  81. package/dist/lib/validators/dateObject.d.ts +1 -0
  82. package/dist/lib/validators/dateObject.d.ts.map +1 -0
  83. package/dist/lib/validators/dateObject.js +14 -21
  84. package/dist/lib/validators/email.d.ts +1 -0
  85. package/dist/lib/validators/email.d.ts.map +1 -0
  86. package/dist/lib/validators/email.js +8 -15
  87. package/dist/lib/validators/inArray.d.ts +1 -0
  88. package/dist/lib/validators/inArray.d.ts.map +1 -0
  89. package/dist/lib/validators/inArray.js +8 -15
  90. package/dist/lib/validators/index.d.ts +1 -0
  91. package/dist/lib/validators/index.d.ts.map +1 -0
  92. package/dist/lib/validators/index.js +21 -27
  93. package/dist/lib/validators/nino.d.ts +1 -0
  94. package/dist/lib/validators/nino.d.ts.map +1 -0
  95. package/dist/lib/validators/nino.js +6 -13
  96. package/dist/lib/validators/postalAddressObject.d.ts +1 -0
  97. package/dist/lib/validators/postalAddressObject.d.ts.map +1 -0
  98. package/dist/lib/validators/postalAddressObject.js +12 -19
  99. package/dist/lib/validators/range.d.ts +1 -0
  100. package/dist/lib/validators/range.d.ts.map +1 -0
  101. package/dist/lib/validators/range.js +6 -13
  102. package/dist/lib/validators/regex.d.ts +1 -0
  103. package/dist/lib/validators/regex.d.ts.map +1 -0
  104. package/dist/lib/validators/regex.js +6 -13
  105. package/dist/lib/validators/required.d.ts +1 -0
  106. package/dist/lib/validators/required.d.ts.map +1 -0
  107. package/dist/lib/validators/required.js +9 -17
  108. package/dist/lib/validators/strlen.d.ts +1 -0
  109. package/dist/lib/validators/strlen.d.ts.map +1 -0
  110. package/dist/lib/validators/strlen.js +6 -13
  111. package/dist/lib/validators/wordCount.d.ts +1 -0
  112. package/dist/lib/validators/wordCount.d.ts.map +1 -0
  113. package/dist/lib/validators/wordCount.js +6 -13
  114. package/dist/lib/waypoint-url.d.ts +3 -2
  115. package/dist/lib/waypoint-url.d.ts.map +1 -0
  116. package/dist/lib/waypoint-url.js +12 -19
  117. package/dist/middleware/body-parser.d.ts +1 -0
  118. package/dist/middleware/body-parser.d.ts.map +1 -0
  119. package/dist/middleware/body-parser.js +4 -9
  120. package/dist/middleware/csrf.d.ts +1 -0
  121. package/dist/middleware/csrf.d.ts.map +1 -0
  122. package/dist/middleware/csrf.js +4 -8
  123. package/dist/middleware/data.d.ts +2 -3
  124. package/dist/middleware/data.d.ts.map +1 -0
  125. package/dist/middleware/data.js +23 -25
  126. package/dist/middleware/gather-fields.d.ts +3 -1
  127. package/dist/middleware/gather-fields.d.ts.map +1 -0
  128. package/dist/middleware/gather-fields.js +13 -14
  129. package/dist/middleware/i18n.d.ts +1 -0
  130. package/dist/middleware/i18n.d.ts.map +1 -0
  131. package/dist/middleware/i18n.js +26 -31
  132. package/dist/middleware/post.d.ts +4 -2
  133. package/dist/middleware/post.d.ts.map +1 -0
  134. package/dist/middleware/post.js +6 -11
  135. package/dist/middleware/pre.d.ts +2 -1
  136. package/dist/middleware/pre.d.ts.map +1 -0
  137. package/dist/middleware/pre.js +6 -12
  138. package/dist/middleware/progress-journey.d.ts +5 -3
  139. package/dist/middleware/progress-journey.d.ts.map +1 -0
  140. package/dist/middleware/progress-journey.js +20 -18
  141. package/dist/middleware/sanitise-fields.d.ts +5 -3
  142. package/dist/middleware/sanitise-fields.d.ts.map +1 -0
  143. package/dist/middleware/sanitise-fields.js +25 -17
  144. package/dist/middleware/serve-first-waypoint.d.ts +1 -0
  145. package/dist/middleware/serve-first-waypoint.d.ts.map +1 -0
  146. package/dist/middleware/serve-first-waypoint.js +3 -6
  147. package/dist/middleware/session.d.ts +15 -0
  148. package/dist/middleware/session.d.ts.map +1 -0
  149. package/dist/middleware/session.js +53 -57
  150. package/dist/middleware/skip-waypoint.d.ts +3 -2
  151. package/dist/middleware/skip-waypoint.d.ts.map +1 -0
  152. package/dist/middleware/skip-waypoint.js +15 -14
  153. package/dist/middleware/steer-journey.d.ts +2 -1
  154. package/dist/middleware/steer-journey.d.ts.map +1 -0
  155. package/dist/middleware/steer-journey.js +7 -13
  156. package/dist/middleware/strip-proxy-path.d.ts +3 -2
  157. package/dist/middleware/strip-proxy-path.d.ts.map +1 -0
  158. package/dist/middleware/strip-proxy-path.js +24 -24
  159. package/dist/middleware/validate-fields.d.ts +7 -4
  160. package/dist/middleware/validate-fields.d.ts.map +1 -0
  161. package/dist/middleware/validate-fields.js +22 -11
  162. package/dist/routes/ancillary.d.ts +1 -0
  163. package/dist/routes/ancillary.d.ts.map +1 -0
  164. package/dist/routes/ancillary.js +3 -10
  165. package/dist/routes/journey.d.ts +7 -2
  166. package/dist/routes/journey.d.ts.map +1 -0
  167. package/dist/routes/journey.js +56 -55
  168. package/dist/routes/static.d.ts +1 -0
  169. package/dist/routes/static.d.ts.map +1 -0
  170. package/dist/routes/static.js +15 -23
  171. package/package.json +30 -36
  172. package/src/casa.js +63 -31
  173. package/src/core-plugins/edit-snapshot/src/post-steer-hook.js +1 -0
  174. package/src/core-plugins/edit-snapshot/src/pre-steer-hook.js +2 -1
  175. package/src/core-plugins/edit-snapshot/src/utils.js +29 -1
  176. package/src/lib/JourneyContext.js +31 -28
  177. package/src/lib/MutableRouter.js +52 -38
  178. package/src/lib/NullObject.js +4 -0
  179. package/src/lib/Plan.js +41 -55
  180. package/src/lib/ValidationError.js +2 -4
  181. package/src/lib/ValidatorFactory.js +3 -5
  182. package/src/lib/configuration-ingestor.js +18 -38
  183. package/src/lib/configure.js +7 -10
  184. package/src/lib/end-session.js +1 -1
  185. package/src/lib/field.js +7 -12
  186. package/src/lib/logger.js +16 -0
  187. package/src/lib/mount.js +1 -1
  188. package/src/lib/nunjucks-filters.js +51 -61
  189. package/src/lib/nunjucks.js +5 -13
  190. package/src/lib/utils.js +2 -1
  191. package/src/lib/validators/dateObject.js +3 -4
  192. package/src/lib/validators/postalAddressObject.js +6 -7
  193. package/src/lib/validators/required.js +1 -3
  194. package/src/lib/waypoint-url.js +15 -19
  195. package/src/middleware/csrf.js +1 -1
  196. package/src/middleware/data.js +13 -13
  197. package/src/middleware/gather-fields.js +8 -2
  198. package/src/middleware/i18n.js +9 -6
  199. package/src/middleware/post.js +3 -1
  200. package/src/middleware/pre.js +1 -1
  201. package/src/middleware/progress-journey.js +8 -0
  202. package/src/middleware/sanitise-fields.js +17 -2
  203. package/src/middleware/session.js +53 -12
  204. package/src/middleware/skip-waypoint.js +8 -1
  205. package/src/middleware/steer-journey.js +1 -1
  206. package/src/middleware/strip-proxy-path.js +21 -16
  207. package/src/middleware/validate-fields.js +19 -0
  208. package/src/routes/journey.js +18 -8
  209. package/src/routes/static.js +5 -4
  210. package/views/casa/layouts/journey.njk +1 -1
  211. package/views/casa/layouts/main.njk +11 -21
  212. package/dist/casa.js.map +0 -1
  213. package/dist/core-plugins/edit-snapshot/src/configure.js.map +0 -1
  214. package/dist/core-plugins/edit-snapshot/src/index.js.map +0 -1
  215. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js.map +0 -1
  216. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js.map +0 -1
  217. package/dist/core-plugins/edit-snapshot/src/utils.js.map +0 -1
  218. package/dist/core-plugins/index.js.map +0 -1
  219. package/dist/lib/CasaTemplateLoader.js.map +0 -1
  220. package/dist/lib/JourneyContext.js.map +0 -1
  221. package/dist/lib/MutableRouter.js.map +0 -1
  222. package/dist/lib/Plan.js.map +0 -1
  223. package/dist/lib/ValidationError.js.map +0 -1
  224. package/dist/lib/ValidatorFactory.js.map +0 -1
  225. package/dist/lib/configuration-ingestor.js.map +0 -1
  226. package/dist/lib/configure.js.map +0 -1
  227. package/dist/lib/constants.js.map +0 -1
  228. package/dist/lib/context-id-generators.js.map +0 -1
  229. package/dist/lib/dirname.cjs +0 -1
  230. package/dist/lib/dirname.d.cts +0 -2
  231. package/dist/lib/end-session.js.map +0 -1
  232. package/dist/lib/field.js.map +0 -1
  233. package/dist/lib/index.js.map +0 -1
  234. package/dist/lib/logger.js.map +0 -1
  235. package/dist/lib/mount.js.map +0 -1
  236. package/dist/lib/nunjucks-filters.js.map +0 -1
  237. package/dist/lib/nunjucks.js.map +0 -1
  238. package/dist/lib/utils.js.map +0 -1
  239. package/dist/lib/validators/dateObject.js.map +0 -1
  240. package/dist/lib/validators/email.js.map +0 -1
  241. package/dist/lib/validators/inArray.js.map +0 -1
  242. package/dist/lib/validators/index.js.map +0 -1
  243. package/dist/lib/validators/nino.js.map +0 -1
  244. package/dist/lib/validators/postalAddressObject.js.map +0 -1
  245. package/dist/lib/validators/range.js.map +0 -1
  246. package/dist/lib/validators/regex.js.map +0 -1
  247. package/dist/lib/validators/required.js.map +0 -1
  248. package/dist/lib/validators/strlen.js.map +0 -1
  249. package/dist/lib/validators/wordCount.js.map +0 -1
  250. package/dist/lib/waypoint-url.js.map +0 -1
  251. package/dist/middleware/body-parser.js.map +0 -1
  252. package/dist/middleware/csrf.js.map +0 -1
  253. package/dist/middleware/data.js.map +0 -1
  254. package/dist/middleware/dirname.cjs +0 -1
  255. package/dist/middleware/dirname.d.cts +0 -2
  256. package/dist/middleware/gather-fields.js.map +0 -1
  257. package/dist/middleware/i18n.js.map +0 -1
  258. package/dist/middleware/post.js.map +0 -1
  259. package/dist/middleware/pre.js.map +0 -1
  260. package/dist/middleware/progress-journey.js.map +0 -1
  261. package/dist/middleware/sanitise-fields.js.map +0 -1
  262. package/dist/middleware/serve-first-waypoint.js.map +0 -1
  263. package/dist/middleware/session.js.map +0 -1
  264. package/dist/middleware/skip-waypoint.js.map +0 -1
  265. package/dist/middleware/steer-journey.js.map +0 -1
  266. package/dist/middleware/strip-proxy-path.js.map +0 -1
  267. package/dist/middleware/validate-fields.js.map +0 -1
  268. package/dist/mjs/esm-wrapper.js +0 -20
  269. package/dist/mjs/package.json +0 -3
  270. package/dist/package.json +0 -3
  271. package/dist/routes/ancillary.js.map +0 -1
  272. package/dist/routes/dirname.cjs +0 -1
  273. package/dist/routes/dirname.d.cts +0 -2
  274. package/dist/routes/journey.js.map +0 -1
  275. package/dist/routes/static.js.map +0 -1
  276. package/src/lib/dirname.cjs +0 -1
  277. package/src/middleware/dirname.cjs +0 -1
  278. package/src/routes/dirname.cjs +0 -1
package/dist/casa.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export type PageField = import("./lib/field").PageField;
2
+ export type ExpressRequest = import("express").Request;
3
+ export type RequestHandler = import("express").RequestHandler;
4
+ export type HelmetOptions = import("helmet").HelmetOptions;
2
5
  export type ContextEventHandlerOptions = {
3
6
  /**
4
7
  * Context including changes
@@ -39,6 +42,9 @@ export type ContextEvent = {
39
42
  */
40
43
  handler: ContextEventHandler;
41
44
  };
45
+ export type ErrorVisibiltyFunction = (opts: {
46
+ req: ExpressRequest;
47
+ }) => any;
42
48
  /**
43
49
  * Page configuration. A Page is the interactive
44
50
  * representation of a waypoint
@@ -52,6 +58,11 @@ export type Page = {
52
58
  * Template path
53
59
  */
54
60
  view: string;
61
+ /**
62
+ * Should page
63
+ * validation errors be visible on GET requests
64
+ */
65
+ errorVisibility?: symbol | ErrorVisibiltyFunction | undefined;
55
66
  /**
56
67
  * Page-specific hooks (optional, default []).
57
68
  * Default is `[]`
@@ -88,10 +99,10 @@ export type GlobalHook = {
88
99
  */
89
100
  hook: string;
90
101
  /**
91
- * Middleware function to insert at the hook
92
- * point
102
+ * Middleware function to insert at the
103
+ * hook point
93
104
  */
94
- middleware: Function;
105
+ middleware: RequestHandler;
95
106
  /**
96
107
  * Only run if route path matches
97
108
  * this string/regexp. Default is `undefined`
@@ -107,10 +118,10 @@ export type PageHook = {
107
118
  */
108
119
  hook: string;
109
120
  /**
110
- * Middleware function to insert at the hook
111
- * point
121
+ * Middleware function to insert at the
122
+ * hook point
112
123
  */
113
- middleware: Function;
124
+ middleware: RequestHandler;
114
125
  };
115
126
  export type SessionOptions = {
116
127
  /**
@@ -161,7 +172,8 @@ export type IPlugin = {
161
172
  };
162
173
  export type PluginConfigureFunction = (config: ConfigurationOptions) => any;
163
174
  export type PluginBootstrapFunction = (config: ConfigureResult) => any;
164
- export type HelmetConfigurator = (config: object) => object;
175
+ export type HelmetConfigurator = (config: HelmetOptions) => HelmetOptions;
176
+ export type CasaNunjucksEnvironment = Omit<import("nunjucks").Environment & import("./lib/CasaTemplateLoader.js").default, "getSource">;
165
177
  /**
166
178
  * Mounting function.
167
179
  *
@@ -171,9 +183,10 @@ export type HelmetConfigurator = (config: object) => object;
171
183
  * Once this is called, you will not be able to modify any of the routers as
172
184
  * they will be "sealed".
173
185
  */
174
- export type Mounter = (app: import("express").Express, opts: {
186
+ export type Mounter = (app: import("express").Express, opts?: {
175
187
  route?: string | undefined;
176
- }) => import("express").Express;
188
+ serveFirstWaypoint?: boolean | undefined;
189
+ } | undefined) => import("express").Express;
177
190
  /**
178
191
  * Configuration options
179
192
  */
@@ -236,15 +249,10 @@ export type ConfigurationOptions = {
236
249
  */
237
250
  contextIdGenerator?: ContextIdGenerator | undefined;
238
251
  /**
239
- * Option to keep page errors
240
- * active on GET request
241
- */
242
- errorVisibility?: symbol | Function | undefined;
243
- /**
244
- * Sets whether you wish to use the
245
- * govuk rebrand. Default is `false`
252
+ * Option to keep
253
+ * page errors active on GET request
246
254
  */
247
- govukRebrand?: boolean | undefined;
255
+ errorVisibility?: symbol | ErrorVisibiltyFunction | undefined;
248
256
  };
249
257
  /**
250
258
  * Result of a call to configure() function
@@ -253,7 +261,7 @@ export type ConfigureResult = {
253
261
  /**
254
262
  * Nunjucks environment
255
263
  */
256
- nunjucksEnv: import("nunjucks").Environment;
264
+ nunjucksEnv: CasaNunjucksEnvironment;
257
265
  /**
258
266
  * Router handling all static assets
259
267
  */
@@ -267,39 +275,39 @@ export type ConfigureResult = {
267
275
  */
268
276
  journeyRouter: MutableRouter;
269
277
  /**
270
- * Middleware
271
- * mounted before everything
278
+ * Middleware mounted before
279
+ * everything
272
280
  */
273
- preMiddleware: import("express").RequestHandler[];
281
+ preMiddleware: RequestHandler[];
274
282
  /**
275
- * Middleware
276
- * mounted after everything
283
+ * Middleware mounted after
284
+ * everything
277
285
  */
278
- postMiddleware: import("express").RequestHandler[];
286
+ postMiddleware: RequestHandler[];
279
287
  /**
280
- * CSRF get/set
281
- * form middleware
288
+ * CSRF get/set form middleware
282
289
  */
283
- csrfMiddleware: import("express").RequestHandler[];
290
+ csrfMiddleware: RequestHandler[];
284
291
  /**
285
- * Session
286
- * middleware
292
+ * Session middleware
287
293
  */
288
- sessionMiddleware: import("express").RequestHandler;
294
+ sessionMiddleware: RequestHandler;
289
295
  /**
290
- * Cookie-parsing middleware
296
+ * Cookie-parsing middleware
291
297
  */
292
- cookieParserMiddleware: import("express").RequestHandler[];
298
+ cookieParserMiddleware: RequestHandler[];
293
299
  /**
294
- * I18n
295
- * preparation middleware
300
+ * I18n preparation middleware
296
301
  */
297
- i18nMiddleware: import("express").RequestHandler[];
302
+ i18nMiddleware: RequestHandler[];
298
303
  /**
299
- * Body
300
- * parsing middleware
304
+ * Body parsing middleware
301
305
  */
302
- bodyParserMiddleware: import("express").RequestHandler;
306
+ bodyParserMiddleware: RequestHandler;
307
+ /**
308
+ * Data decoration middleware
309
+ */
310
+ dataMiddleware: RequestHandler[];
303
311
  /**
304
312
  * Function used to mount all CASA artifacts onto an
305
313
  * ExpressJS app
@@ -465,6 +473,7 @@ export type PlanRoute = {
465
473
  label: string;
466
474
  };
467
475
  export type PlanRouteCondition = (route: PlanRoute, context: JourneyContext) => boolean;
476
+ export type StopCondition = (route: PlanRoute) => boolean;
468
477
  export type PlanTraverseOptions = {
469
478
  /**
470
479
  * Waypoint from which to start (defaults to
@@ -483,7 +492,7 @@ export type PlanTraverseOptions = {
483
492
  * If true, traversal will be stopped
484
493
  * (useful for performance)
485
494
  */
486
- stopCondition?: Function | undefined;
495
+ stopCondition?: StopCondition | undefined;
487
496
  /**
488
497
  * Multiple target routes found, this
489
498
  * decides which to use
@@ -506,6 +515,23 @@ export type PlanArbiterParams = {
506
515
  traverseOptions: PlanTraverseOptions;
507
516
  };
508
517
  export type PlanArbiter = (route: PlanArbiterParams) => PlanRoute[];
518
+ /**
519
+ * Journey Context Identity Object
520
+ */
521
+ export type JourneyContextIdentity = {
522
+ /**
523
+ * The context ID
524
+ */
525
+ id?: string | undefined;
526
+ /**
527
+ * Context name
528
+ */
529
+ name?: string | undefined;
530
+ /**
531
+ * JouneyContext tags
532
+ */
533
+ tags?: string[] | undefined;
534
+ };
509
535
  /**
510
536
  * Journey Context Object
511
537
  */
@@ -515,24 +541,25 @@ export type JourneyContextObject = {
515
541
  */
516
542
  data?: Record<string, any> | undefined;
517
543
  /**
518
- * Validation state
544
+ * Validation
545
+ * state
519
546
  */
520
- validation?: any;
547
+ validation?: Record<string, ValidationError[] | null> | undefined;
521
548
  /**
522
549
  * Navigation meta
523
550
  */
524
- nav?: any;
551
+ nav?: object | undefined;
525
552
  /**
526
553
  * Identity meta
527
554
  */
528
- identity?: any;
555
+ identity?: JourneyContextIdentity | undefined;
529
556
  };
530
557
  export type ContextIdGeneratorParams = {
531
558
  /**
532
559
  * Arguments
533
560
  */
534
561
  args: {
535
- req: import("express").Request;
562
+ req: ExpressRequest;
536
563
  reservedIds: [string];
537
564
  };
538
565
  };
@@ -563,3 +590,22 @@ import * as constants from "./lib/constants.js";
563
590
  import * as contextIdGenerators from "./lib/context-id-generators.js";
564
591
  import * as corePlugins from "./core-plugins/index.js";
565
592
  export { configure, validators, field, Plan, JourneyContext, ValidatorFactory, ValidationError, MutableRouter, waypointUrl, endSession, generateGovukErrors, nunjucksFilters, constants, contextIdGenerators, corePlugins };
593
+ //# sourceMappingURL=casa.d.ts.map
594
+ declare global {
595
+ namespace Express {
596
+ type CasaRequestContext = {
597
+ plan: Plan,
598
+ journeyContext: JourneyContext,
599
+ editMode: boolean,
600
+ editOrigin: string,
601
+ }
602
+
603
+ // Inject additional properties on express.Request
604
+ interface Request {
605
+ /**
606
+ * CASA request context
607
+ */
608
+ casa: CasaRequestContext;
609
+ }
610
+ }
611
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"casa.d.ts","sourceRoot":"","sources":["../src/casa.js"],"names":[],"mappings":"wBAiDc,OAAO,aAAa,EAAE,SAAS;6BAC/B,OAAO,SAAS,EAAE,OAAO;6BACzB,OAAO,SAAS,EAAE,cAAc;4BAChC,OAAO,QAAQ,EAAE,aAAa;;;;;oBAI9B,cAAc;;;;qBACd,cAAc;;;;aACd,MAAM;;;;cACN,oBAAoB;;yCAKvB,0BAA0B,KACxB,IAAI;;;;;;;;;;;;cAWH,MAAM;;;;;;;;aAEN,mBAAmB;;4CAM9B;IAA6B,GAAG,EAAxB,cAAc;CACxB;;;;;;;;;cAKa,MAAM;;;;UACN,MAAM;;;;;;;;;;;;;;;;;;;;;UAWN,MAAM,EAAE;;;;;;;;;;;;;;;;;;;UASR,MAAM;;;;;gBACN,cAAc;;;;;;;;;;;;;;UAQd,MAAM;;;;;gBACN,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+CA2BjB,oBAAoB;+CAKpB,eAAe;0CAKf,aAAa,KACX,aAAa;sCAIb,IAAI,CAChB,OAAW,UAAU,EAAE,WAAW,GAClC,OAAa,6BAA6B,EAAE,OAAO,EACnD,WAAe,CACZ;;;;;;;;;;4BAaO,OAAO,SAAS,EAAE,OAAO;;;kBAOvB,OAAO,SAAS,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+BxB,uBAAuB;;;;kBACvB,aAAa;;;;qBACb,aAAa;;;;mBACb,aAAa;;;;;mBACb,cAAc,EAAE;;;;;oBAEhB,cAAc,EAAE;;;;oBAEhB,cAAc,EAAE;;;;uBAChB,cAAc;;;;4BACd,cAAc,EAAE;;;;oBAChB,cAAc,EAAE;;;;0BAChB,cAAc;;;;oBACd,cAAc,EAAE;;;;;WAChB,OAAO;;;;;YAEP,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA2BpB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2DAoBT,eAAe,KACb,MAAM;wDAKR,eAAe,KACb,MAAM,GAAG,wBAAwB;iCAIjC,MAAM,GACZ,wBAAwB,GACxB,2BAA2B,GAC3B,KAAK;;;;;;;;oBAKE,cAAc;;;;cACd,MAAM;;;;eACN,MAAM;;;;iBACN,GAAG;;;;;;uCAMN,GAAG,WACH,eAAe,KACb,eAAe,EAAE;6CAKnB,GAAG,KACD,GAAG;;;;;cAKF,gBAAgB;;;;;cAChB,sBAAsB;;;;YAEtB,MAAM;;;;UACN,MAAM;;;;;;eAKN,MAAM;;;;gBACN,GAAG;;;;cACH,MAAM;;;;oBACN,cAAc;;;;;mDAOjB,gCAAgC,KAC9B,OAAO;;;;;YAKN,MAAM;;;;YACN,MAAM;;;;UACN,MAAM;;;;WACN,MAAM;;yCAKT,SAAS,WACT,cAAc,KACZ,OAAO;oCAKT,SAAS,KACP,OAAO;;;;;;;;;;eAON,MAAM;;;;;;;;;;;;;;;;;;;;aAUN,SAAS,EAAE;;;;oBACX,cAAc;;;;;qBACd,mBAAmB;;kCAMtB,iBAAiB,KACf,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAuBrB;QAAgC,GAAG,EAAxB,cAAc;QACC,WAAW,EAA1B,CAAC,MAAM,CAAC;KAErB;;;;;;;;;;;;0CAaU,wBAAwB,KACtB,MAAM;sBA5aG,oBAAoB;uBACnB,2BAA2B;kBAChC,gBAAgB;iBACjB,eAAe;2BACL,yBAAyB;6BACvB,2BAA2B;4BAC5B,0BAA0B;0BAC5B,wBAAwB;wBAC1B,uBAAuB;uBACxB,sBAAsB;oCACT,qBAAqB;iCACxB,2BAA2B;2BACjC,oBAAoB;qCACV,gCAAgC;6BACxC,yBAAyB"}
package/dist/casa.js CHANGED
@@ -1,76 +1,37 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.corePlugins = exports.contextIdGenerators = exports.constants = exports.nunjucksFilters = exports.generateGovukErrors = exports.endSession = exports.waypointUrl = exports.MutableRouter = exports.ValidationError = exports.ValidatorFactory = exports.JourneyContext = exports.Plan = exports.field = exports.validators = exports.configure = void 0;
40
1
  // NOTE: Any changes made here must be reflected in `scripts/esm-wrapper.js`
41
- const configure_js_1 = __importDefault(require("./lib/configure.js"));
42
- exports.configure = configure_js_1.default;
43
- const index_js_1 = __importDefault(require("./lib/validators/index.js"));
44
- exports.validators = index_js_1.default;
45
- const field_js_1 = __importDefault(require("./lib/field.js"));
46
- exports.field = field_js_1.default;
47
- const Plan_js_1 = __importDefault(require("./lib/Plan.js"));
48
- exports.Plan = Plan_js_1.default;
49
- const JourneyContext_js_1 = __importDefault(require("./lib/JourneyContext.js"));
50
- exports.JourneyContext = JourneyContext_js_1.default;
51
- const ValidatorFactory_js_1 = __importDefault(require("./lib/ValidatorFactory.js"));
52
- exports.ValidatorFactory = ValidatorFactory_js_1.default;
53
- const ValidationError_js_1 = __importDefault(require("./lib/ValidationError.js"));
54
- exports.ValidationError = ValidationError_js_1.default;
55
- const MutableRouter_js_1 = __importDefault(require("./lib/MutableRouter.js"));
56
- exports.MutableRouter = MutableRouter_js_1.default;
57
- const waypoint_url_js_1 = __importDefault(require("./lib/waypoint-url.js"));
58
- exports.waypointUrl = waypoint_url_js_1.default;
59
- const end_session_js_1 = __importDefault(require("./lib/end-session.js"));
60
- exports.endSession = end_session_js_1.default;
61
- const journey_js_1 = require("./routes/journey.js");
62
- Object.defineProperty(exports, "generateGovukErrors", { enumerable: true, get: function () { return journey_js_1.generateGovukErrors; } });
63
- const nunjucksFilters = __importStar(require("./lib/nunjucks-filters.js"));
64
- exports.nunjucksFilters = nunjucksFilters;
65
- const constants = __importStar(require("./lib/constants.js"));
66
- exports.constants = constants;
67
- const contextIdGenerators = __importStar(require("./lib/context-id-generators.js"));
68
- exports.contextIdGenerators = contextIdGenerators;
69
- const corePlugins = __importStar(require("./core-plugins/index.js"));
70
- exports.corePlugins = corePlugins;
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 { generateGovukErrors } from "./routes/journey.js";
13
+ import * as nunjucksFilters from "./lib/nunjucks-filters.js";
14
+ import * as constants from "./lib/constants.js";
15
+ import * as contextIdGenerators from "./lib/context-id-generators.js";
16
+ import * as corePlugins from "./core-plugins/index.js";
17
+ /** @module @dwp/govuk-casa */
18
+ export { configure, validators, field, Plan, JourneyContext, ValidatorFactory, ValidationError, MutableRouter,
19
+ // Utilities
20
+ waypointUrl, endSession, generateGovukErrors,
21
+ // Nunjucks filters
22
+ nunjucksFilters,
23
+ // Constants
24
+ constants,
25
+ // Context ID generators
26
+ contextIdGenerators,
27
+ // Core plugins
28
+ corePlugins, };
71
29
  /* ----------------------------------------------------------------- Typedefs */
72
30
  // These exist here so that consumer can import CASA's internal types
73
31
  /** @typedef {import("./lib/field").PageField} PageField */
32
+ /** @typedef {import("express").Request} ExpressRequest */
33
+ /** @typedef {import("express").RequestHandler} RequestHandler */
34
+ /** @typedef {import("helmet").HelmetOptions} HelmetOptions */
74
35
  /**
75
36
  * @typedef {object} ContextEventHandlerOptions
76
37
  * @property {JourneyContext} journeyContext Context including changes
@@ -94,11 +55,18 @@ exports.corePlugins = corePlugins;
94
55
  * @property {string} [field] Field to watch for changes
95
56
  * @property {ContextEventHandler} handler Handler to invoke when change happens
96
57
  */
58
+ /**
59
+ * @callback ErrorVisibiltyFunction
60
+ * @param {object} opts Options
61
+ * @param {ExpressRequest} opts.req Request
62
+ */
97
63
  /**
98
64
  * @typedef {object} Page Page configuration. A Page is the interactive
99
65
  * representation of a waypoint
100
66
  * @property {string} waypoint The waypoint with which this page is associated
101
67
  * @property {string} view Template path
68
+ * @property {ErrorVisibiltyFunction | symbol} [errorVisibility] Should page
69
+ * validation errors be visible on GET requests
102
70
  * @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default []).
103
71
  * Default is `[]`
104
72
  * @property {PageField[]} [fields=[]] Fields to be managed on this page
@@ -115,16 +83,16 @@ exports.corePlugins = corePlugins;
115
83
  /**
116
84
  * @typedef {object} GlobalHook Hook configuration
117
85
  * @property {string} hook Hook name in format `<router>.<hook>`
118
- * @property {Function} middleware Middleware function to insert at the hook
119
- * point
86
+ * @property {RequestHandler} middleware Middleware function to insert at the
87
+ * hook point
120
88
  * @property {string | RegExp} [path=undefined] Only run if route path matches
121
89
  * this string/regexp. Default is `undefined`
122
90
  */
123
91
  /**
124
92
  * @typedef {object} PageHook (extends GlobalHook)
125
93
  * @property {string} hook Hook name (without a scope prefix)
126
- * @property {Function} middleware Middleware function to insert at the hook
127
- * point
94
+ * @property {RequestHandler} middleware Middleware function to insert at the
95
+ * hook point
128
96
  */
129
97
  /**
130
98
  * @typedef {object} SessionOptions
@@ -155,8 +123,15 @@ exports.corePlugins = corePlugins;
155
123
  */
156
124
  /**
157
125
  * @callback HelmetConfigurator
158
- * @param {object} config A default Helmet configuration provided by CASA
159
- * @returns {object} The modified configuration object
126
+ * @param {HelmetOptions} config A default Helmet configuration provided by CASA
127
+ * @returns {HelmetOptions} The modified configuration object
128
+ */
129
+ /**
130
+ * @typedef {Omit<
131
+ * import("nunjucks").Environment &
132
+ * import("./lib/CasaTemplateLoader.js").default,
133
+ * "getSource"
134
+ * >} CasaNunjucksEnvironment
160
135
  */
161
136
  /**
162
137
  * Mounting function.
@@ -169,9 +144,12 @@ exports.corePlugins = corePlugins;
169
144
  *
170
145
  * @callback Mounter
171
146
  * @param {import("express").Express} app Express application
172
- * @param {object} opts Mounting options
147
+ * @param {object} [opts] Mounting options
173
148
  * @param {string} [opts.route='/'] Optional route to attach all
174
149
  * middleware/routers too. Default is `'/'`
150
+ * @param {boolean} [opts.serveFirstWaypoint=false] Automatically redirect
151
+ * requests to the mount route to the first waypoint in the plan. Default is
152
+ * `false`
175
153
  * @returns {import("express").Express} The prepared ExpressJS app instance
176
154
  */
177
155
  /**
@@ -196,31 +174,25 @@ exports.corePlugins = corePlugins;
196
174
  * to ingest. Default is `"50KB"`
197
175
  * @property {ContextIdGenerator} [contextIdGenerator] Custom context ID
198
176
  * generator
199
- * @property {symbol | Function} [errorVisibility] Option to keep page errors
200
- * active on GET request
201
- * @property {boolean} [govukRebrand=false] Sets whether you wish to use the
202
- * govuk rebrand. Default is `false`
177
+ * @property {symbol | ErrorVisibiltyFunction} [errorVisibility] Option to keep
178
+ * page errors active on GET request
203
179
  */
204
180
  /**
205
181
  * @typedef {object} ConfigureResult Result of a call to configure() function
206
- * @property {import("nunjucks").Environment} nunjucksEnv Nunjucks environment
182
+ * @property {CasaNunjucksEnvironment} nunjucksEnv Nunjucks environment
207
183
  * @property {MutableRouter} staticRouter Router handling all static assets
208
184
  * @property {MutableRouter} ancillaryRouter Router handling ancillary routes
209
185
  * @property {MutableRouter} journeyRouter Router handling all waypoint requests
210
- * @property {import("express").RequestHandler[]} preMiddleware Middleware
211
- * mounted before everything
212
- * @property {import("express").RequestHandler[]} postMiddleware Middleware
213
- * mounted after everything
214
- * @property {import("express").RequestHandler[]} csrfMiddleware CSRF get/set
215
- * form middleware
216
- * @property {import("express").RequestHandler} sessionMiddleware Session
217
- * middleware
218
- * @property {import("express").RequestHandler[]} cookieParserMiddleware
219
- * Cookie-parsing middleware
220
- * @property {import("express").RequestHandler[]} i18nMiddleware I18n
221
- * preparation middleware
222
- * @property {import("express").RequestHandler} bodyParserMiddleware Body
223
- * parsing middleware
186
+ * @property {RequestHandler[]} preMiddleware Middleware mounted before
187
+ * everything
188
+ * @property {RequestHandler[]} postMiddleware Middleware mounted after
189
+ * everything
190
+ * @property {RequestHandler[]} csrfMiddleware CSRF get/set form middleware
191
+ * @property {RequestHandler} sessionMiddleware Session middleware
192
+ * @property {RequestHandler[]} cookieParserMiddleware Cookie-parsing middleware
193
+ * @property {RequestHandler[]} i18nMiddleware I18n preparation middleware
194
+ * @property {RequestHandler} bodyParserMiddleware Body parsing middleware
195
+ * @property {RequestHandler[]} dataMiddleware Data decoration middleware
224
196
  * @property {Mounter} mount Function used to mount all CASA artifacts onto an
225
197
  * ExpressJS app
226
198
  * @property {ConfigurationOptions} config Ingested config supplied to
@@ -336,13 +308,18 @@ exports.corePlugins = corePlugins;
336
308
  * @param {JourneyContext} context Journey Context
337
309
  * @returns {boolean} Returns true is route should be followed
338
310
  */
311
+ /**
312
+ * @callback StopCondition
313
+ * @param {PlanRoute} route Route metadata
314
+ * @returns {boolean} Returns true is traversal should be stopped
315
+ */
339
316
  /**
340
317
  * @typedef PlanTraverseOptions
341
318
  * @property {string} [startWaypoint] Waypoint from which to start (defaults to
342
319
  * first in list)
343
320
  * @property {string} routeName Follow routes matching this name (next | prev)
344
321
  * @property {Map} history Used to detect loops in traversal (INTERNAL USE ONLY)
345
- * @property {Function} [stopCondition] If true, traversal will be stopped
322
+ * @property {StopCondition} [stopCondition] If true, traversal will be stopped
346
323
  * (useful for performance)
347
324
  * @property {string | PlanArbiter} [arbiter] Multiple target routes found, this
348
325
  * decides which to use
@@ -360,17 +337,24 @@ exports.corePlugins = corePlugins;
360
337
  * @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter
361
338
  * could eliminate
362
339
  */
340
+ /**
341
+ * @typedef {object} JourneyContextIdentity Journey Context Identity Object
342
+ * @property {string} [id] The context ID
343
+ * @property {string} [name] Context name
344
+ * @property {string[]} [tags] JouneyContext tags
345
+ */
363
346
  /**
364
347
  * @typedef {object} JourneyContextObject Journey Context Object
365
348
  * @property {Record<string, any>} [data] Data
366
- * @property {any} [validation] Validation state
367
- * @property {any} [nav] Navigation meta
368
- * @property {any} [identity] Identity meta
349
+ * @property {Record<string, ValidationError[] | null>} [validation] Validation
350
+ * state
351
+ * @property {object} [nav] Navigation meta
352
+ * @property {JourneyContextIdentity} [identity] Identity meta
369
353
  */
370
354
  /**
371
355
  * @typedef ContextIdGeneratorParams
372
356
  * @property {object} args Arguments
373
- * @property {import("express").Request} args.req Request
357
+ * @property {ExpressRequest} args.req Request
374
358
  * @property {[string]} args.reservedIds List of IDs already in use in session
375
359
  * or request
376
360
  */
@@ -388,4 +372,4 @@ exports.corePlugins = corePlugins;
388
372
  * @param {ContextIdGeneratorParams} params Parameters
389
373
  * @returns {string} A newly generated GUID
390
374
  */
391
- //# sourceMappingURL=casa.js.map
375
+ /** @typedef {import("../src/globals.d.ts")} */
@@ -4,3 +4,4 @@
4
4
  */
5
5
  export default function _default(config: ConfigurationOptions): void;
6
6
  export type ConfigurationOptions = import("../../../casa.js").ConfigurationOptions;
7
+ //# sourceMappingURL=configure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../../../src/core-plugins/edit-snapshot/src/configure.js"],"names":[],"mappings":"AAWA;;;GAGG;AACH,yCAHW,oBAAoB,GAClB,IAAI,CAgBhB;mCAxBY,OAAO,kBAAkB,EAAE,oBAAoB"}
@@ -1,30 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = default_1;
7
- const logger_js_1 = __importDefault(require("../../../lib/logger.js"));
8
- const pre_steer_hook_js_1 = __importDefault(require("./pre-steer-hook.js"));
9
- const post_steer_hook_js_1 = __importDefault(require("./post-steer-hook.js"));
1
+ import logger from "../../../lib/logger.js";
2
+ import preSteerHook from "./pre-steer-hook.js";
3
+ import postSteerHook from "./post-steer-hook.js";
10
4
  /**
11
5
  * @typedef {import("../../../casa.js").ConfigurationOptions} ConfigurationOptions
12
6
  * @access private
13
7
  */
14
- const log = (0, logger_js_1.default)("lib:internal-plugin:edit-snapshot");
8
+ const log = logger("lib:internal-plugin:edit-snapshot");
15
9
  /**
16
10
  * @param {ConfigurationOptions} config Configuration object
17
11
  * @returns {void}
18
12
  */
19
- function default_1(config) {
13
+ export default function (config) {
20
14
  log.info("Configuring 'edit-snapshot' plugin");
21
15
  config.hooks ??= [];
22
16
  config.hooks.push({
23
17
  hook: "journey.presteer",
24
- middleware: pre_steer_hook_js_1.default,
18
+ middleware: preSteerHook,
25
19
  }, {
26
20
  hook: "journey.poststeer",
27
- middleware: post_steer_hook_js_1.default,
21
+ middleware: postSteerHook,
28
22
  });
29
23
  }
30
- //# sourceMappingURL=configure.js.map
@@ -3,3 +3,4 @@ declare function _default(): {
3
3
  };
4
4
  export default _default;
5
5
  import configure from "./configure.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core-plugins/edit-snapshot/src/index.js"],"names":[],"mappings":"AAEe;;EAId;;sBANqB,gBAAgB"}
@@ -1,12 +1,6 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const configure_js_1 = __importDefault(require("./configure.js"));
7
- exports.default = () => {
1
+ import configure from "./configure.js";
2
+ export default () => {
8
3
  return {
9
- configure: configure_js_1.default,
4
+ configure,
10
5
  };
11
6
  };
12
- //# sourceMappingURL=index.js.map
@@ -1,2 +1,3 @@
1
- declare function _default(req: any, res: any, next: any): any;
1
+ declare const _default: (req: import("express-serve-static-core").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: import("express-serve-static-core").Response<any, Record<string, any>, number>, next: import("express-serve-static-core").NextFunction) => unknown;
2
2
  export default _default;
3
+ //# sourceMappingURL=post-steer-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-steer-hook.d.ts","sourceRoot":"","sources":["../../../../src/core-plugins/edit-snapshot/src/post-steer-hook.js"],"names":[],"mappings":"yBAMgB,4JAAG,EAAE,mFAAG,EAAE,sDAAI"}
@@ -1,23 +1,18 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const logger_js_1 = __importDefault(require("../../../lib/logger.js"));
7
- const utils_js_1 = require("./utils.js");
8
- const log = (0, logger_js_1.default)("lib:internal-plugin:edit-snapshot:post-steer-hook");
9
- exports.default = (req, res, next) => {
1
+ import logger from "../../../lib/logger.js";
2
+ import { FLAG_FOR_PURGING, deleteSnapshot } from "./utils.js";
3
+ const log = logger("lib:internal-plugin:edit-snapshot:post-steer-hook");
4
+ /** @type {import("express").RequestHandler} */
5
+ export default (req, res, next) => {
10
6
  // Snapshot purging is carried out here rather than in the presteer hook,
11
7
  // because the `middleware/steer-journey.js` middleware first needs the opportunity
12
8
  // to redirect if the journey cannot be traversed to the edit origin.
13
9
  // eslint-disable-next-line security/detect-object-injection
14
- if (req.casa[utils_js_1.FLAG_FOR_PURGING] === true) {
10
+ if (req.casa[FLAG_FOR_PURGING] === true) {
15
11
  log.debug(`Snapshot purging flag has been set for context '${req.casa.journeyContext.identity.id}'. Snapshot will be deleted.`);
16
- (0, utils_js_1.deleteSnapshot)(log, req);
12
+ deleteSnapshot(log, req);
17
13
  // eslint-disable-next-line security/detect-object-injection
18
- req.casa[utils_js_1.FLAG_FOR_PURGING] = false;
14
+ req.casa[FLAG_FOR_PURGING] = false;
19
15
  return req.session.save(next);
20
16
  }
21
17
  next();
22
18
  };
23
- //# sourceMappingURL=post-steer-hook.js.map