@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.
- package/dist/assets/css/casa.css +1 -1
- package/dist/assets/css/casa.css.map +1 -1
- package/dist/casa.d.ts +90 -44
- package/dist/casa.d.ts.map +1 -0
- package/dist/casa.js +85 -101
- package/dist/core-plugins/edit-snapshot/src/configure.d.ts +1 -0
- package/dist/core-plugins/edit-snapshot/src/configure.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/configure.js +7 -14
- package/dist/core-plugins/edit-snapshot/src/index.d.ts +1 -0
- package/dist/core-plugins/edit-snapshot/src/index.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/index.js +3 -9
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts +2 -1
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js +8 -13
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts +2 -1
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js +13 -18
- package/dist/core-plugins/edit-snapshot/src/utils.d.ts +8 -5
- package/dist/core-plugins/edit-snapshot/src/utils.d.ts.map +1 -0
- package/dist/core-plugins/edit-snapshot/src/utils.js +37 -19
- package/dist/core-plugins/index.d.ts +1 -0
- package/dist/core-plugins/index.d.ts.map +1 -0
- package/dist/core-plugins/index.js +1 -9
- package/dist/lib/CasaTemplateLoader.d.ts +1 -0
- package/dist/lib/CasaTemplateLoader.d.ts.map +1 -0
- package/dist/lib/CasaTemplateLoader.js +2 -6
- package/dist/lib/JourneyContext.d.ts +22 -11
- package/dist/lib/JourneyContext.d.ts.map +1 -0
- package/dist/lib/JourneyContext.js +40 -45
- package/dist/lib/MutableRouter.d.ts +79 -55
- package/dist/lib/MutableRouter.d.ts.map +1 -0
- package/dist/lib/MutableRouter.js +53 -45
- package/dist/lib/NullObject.d.ts +3 -0
- package/dist/lib/NullObject.d.ts.map +1 -0
- package/dist/lib/NullObject.js +3 -0
- package/dist/lib/Plan.d.ts +2 -1
- package/dist/lib/Plan.d.ts.map +1 -0
- package/dist/lib/Plan.js +44 -62
- package/dist/lib/ValidationError.d.ts +2 -1
- package/dist/lib/ValidationError.d.ts.map +1 -0
- package/dist/lib/ValidationError.js +3 -11
- package/dist/lib/ValidatorFactory.d.ts +5 -6
- package/dist/lib/ValidatorFactory.d.ts.map +1 -0
- package/dist/lib/ValidatorFactory.js +4 -12
- package/dist/lib/configuration-ingestor.d.ts +10 -22
- package/dist/lib/configuration-ingestor.d.ts.map +1 -0
- package/dist/lib/configuration-ingestor.js +61 -143
- package/dist/lib/configure.d.ts +2 -1
- package/dist/lib/configure.d.ts.map +1 -0
- package/dist/lib/configure.js +40 -52
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +8 -12
- package/dist/lib/context-id-generators.d.ts +1 -0
- package/dist/lib/context-id-generators.d.ts.map +1 -0
- package/dist/lib/context-id-generators.js +4 -9
- package/dist/lib/end-session.d.ts +2 -1
- package/dist/lib/end-session.d.ts.map +1 -0
- package/dist/lib/end-session.js +4 -11
- package/dist/lib/field.d.ts +2 -1
- package/dist/lib/field.d.ts.map +1 -0
- package/dist/lib/field.js +11 -21
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +13 -65
- package/dist/lib/logger.d.ts +25 -2
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +18 -9
- package/dist/lib/mount.d.ts +1 -0
- package/dist/lib/mount.d.ts.map +1 -0
- package/dist/lib/mount.js +10 -16
- package/dist/lib/nunjucks-filters.d.ts +7 -3
- package/dist/lib/nunjucks-filters.d.ts.map +1 -0
- package/dist/lib/nunjucks-filters.js +58 -71
- package/dist/lib/nunjucks.d.ts +4 -4
- package/dist/lib/nunjucks.d.ts.map +1 -0
- package/dist/lib/nunjucks.js +14 -26
- package/dist/lib/utils.d.ts +4 -2
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +14 -28
- package/dist/lib/validators/dateObject.d.ts +1 -0
- package/dist/lib/validators/dateObject.d.ts.map +1 -0
- package/dist/lib/validators/dateObject.js +14 -21
- package/dist/lib/validators/email.d.ts +1 -0
- package/dist/lib/validators/email.d.ts.map +1 -0
- package/dist/lib/validators/email.js +8 -15
- package/dist/lib/validators/inArray.d.ts +1 -0
- package/dist/lib/validators/inArray.d.ts.map +1 -0
- package/dist/lib/validators/inArray.js +8 -15
- package/dist/lib/validators/index.d.ts +1 -0
- package/dist/lib/validators/index.d.ts.map +1 -0
- package/dist/lib/validators/index.js +21 -27
- package/dist/lib/validators/nino.d.ts +1 -0
- package/dist/lib/validators/nino.d.ts.map +1 -0
- package/dist/lib/validators/nino.js +6 -13
- package/dist/lib/validators/postalAddressObject.d.ts +1 -0
- package/dist/lib/validators/postalAddressObject.d.ts.map +1 -0
- package/dist/lib/validators/postalAddressObject.js +12 -19
- package/dist/lib/validators/range.d.ts +1 -0
- package/dist/lib/validators/range.d.ts.map +1 -0
- package/dist/lib/validators/range.js +6 -13
- package/dist/lib/validators/regex.d.ts +1 -0
- package/dist/lib/validators/regex.d.ts.map +1 -0
- package/dist/lib/validators/regex.js +6 -13
- package/dist/lib/validators/required.d.ts +1 -0
- package/dist/lib/validators/required.d.ts.map +1 -0
- package/dist/lib/validators/required.js +9 -17
- package/dist/lib/validators/strlen.d.ts +1 -0
- package/dist/lib/validators/strlen.d.ts.map +1 -0
- package/dist/lib/validators/strlen.js +6 -13
- package/dist/lib/validators/wordCount.d.ts +1 -0
- package/dist/lib/validators/wordCount.d.ts.map +1 -0
- package/dist/lib/validators/wordCount.js +6 -13
- package/dist/lib/waypoint-url.d.ts +3 -2
- package/dist/lib/waypoint-url.d.ts.map +1 -0
- package/dist/lib/waypoint-url.js +12 -19
- package/dist/middleware/body-parser.d.ts +1 -0
- package/dist/middleware/body-parser.d.ts.map +1 -0
- package/dist/middleware/body-parser.js +4 -9
- package/dist/middleware/csrf.d.ts +1 -0
- package/dist/middleware/csrf.d.ts.map +1 -0
- package/dist/middleware/csrf.js +4 -8
- package/dist/middleware/data.d.ts +2 -3
- package/dist/middleware/data.d.ts.map +1 -0
- package/dist/middleware/data.js +23 -25
- package/dist/middleware/gather-fields.d.ts +3 -1
- package/dist/middleware/gather-fields.d.ts.map +1 -0
- package/dist/middleware/gather-fields.js +13 -14
- package/dist/middleware/i18n.d.ts +1 -0
- package/dist/middleware/i18n.d.ts.map +1 -0
- package/dist/middleware/i18n.js +26 -31
- package/dist/middleware/post.d.ts +4 -2
- package/dist/middleware/post.d.ts.map +1 -0
- package/dist/middleware/post.js +6 -11
- package/dist/middleware/pre.d.ts +2 -1
- package/dist/middleware/pre.d.ts.map +1 -0
- package/dist/middleware/pre.js +6 -12
- package/dist/middleware/progress-journey.d.ts +5 -3
- package/dist/middleware/progress-journey.d.ts.map +1 -0
- package/dist/middleware/progress-journey.js +20 -18
- package/dist/middleware/sanitise-fields.d.ts +5 -3
- package/dist/middleware/sanitise-fields.d.ts.map +1 -0
- package/dist/middleware/sanitise-fields.js +25 -17
- package/dist/middleware/serve-first-waypoint.d.ts +1 -0
- package/dist/middleware/serve-first-waypoint.d.ts.map +1 -0
- package/dist/middleware/serve-first-waypoint.js +3 -6
- package/dist/middleware/session.d.ts +15 -0
- package/dist/middleware/session.d.ts.map +1 -0
- package/dist/middleware/session.js +53 -57
- package/dist/middleware/skip-waypoint.d.ts +3 -2
- package/dist/middleware/skip-waypoint.d.ts.map +1 -0
- package/dist/middleware/skip-waypoint.js +15 -14
- package/dist/middleware/steer-journey.d.ts +2 -1
- package/dist/middleware/steer-journey.d.ts.map +1 -0
- package/dist/middleware/steer-journey.js +7 -13
- package/dist/middleware/strip-proxy-path.d.ts +3 -2
- package/dist/middleware/strip-proxy-path.d.ts.map +1 -0
- package/dist/middleware/strip-proxy-path.js +24 -24
- package/dist/middleware/validate-fields.d.ts +7 -4
- package/dist/middleware/validate-fields.d.ts.map +1 -0
- package/dist/middleware/validate-fields.js +22 -11
- package/dist/routes/ancillary.d.ts +1 -0
- package/dist/routes/ancillary.d.ts.map +1 -0
- package/dist/routes/ancillary.js +3 -10
- package/dist/routes/journey.d.ts +7 -2
- package/dist/routes/journey.d.ts.map +1 -0
- package/dist/routes/journey.js +56 -55
- package/dist/routes/static.d.ts +1 -0
- package/dist/routes/static.d.ts.map +1 -0
- package/dist/routes/static.js +15 -23
- package/package.json +30 -36
- package/src/casa.js +63 -31
- package/src/core-plugins/edit-snapshot/src/post-steer-hook.js +1 -0
- package/src/core-plugins/edit-snapshot/src/pre-steer-hook.js +2 -1
- package/src/core-plugins/edit-snapshot/src/utils.js +29 -1
- package/src/lib/JourneyContext.js +31 -28
- package/src/lib/MutableRouter.js +52 -38
- package/src/lib/NullObject.js +4 -0
- package/src/lib/Plan.js +41 -55
- package/src/lib/ValidationError.js +2 -4
- package/src/lib/ValidatorFactory.js +3 -5
- package/src/lib/configuration-ingestor.js +18 -38
- package/src/lib/configure.js +7 -10
- package/src/lib/end-session.js +1 -1
- package/src/lib/field.js +7 -12
- package/src/lib/logger.js +16 -0
- package/src/lib/mount.js +1 -1
- package/src/lib/nunjucks-filters.js +51 -61
- package/src/lib/nunjucks.js +5 -13
- package/src/lib/utils.js +2 -1
- package/src/lib/validators/dateObject.js +3 -4
- package/src/lib/validators/postalAddressObject.js +6 -7
- package/src/lib/validators/required.js +1 -3
- package/src/lib/waypoint-url.js +15 -19
- package/src/middleware/csrf.js +1 -1
- package/src/middleware/data.js +13 -13
- package/src/middleware/gather-fields.js +8 -2
- package/src/middleware/i18n.js +9 -6
- package/src/middleware/post.js +3 -1
- package/src/middleware/pre.js +1 -1
- package/src/middleware/progress-journey.js +8 -0
- package/src/middleware/sanitise-fields.js +17 -2
- package/src/middleware/session.js +53 -12
- package/src/middleware/skip-waypoint.js +8 -1
- package/src/middleware/steer-journey.js +1 -1
- package/src/middleware/strip-proxy-path.js +21 -16
- package/src/middleware/validate-fields.js +19 -0
- package/src/routes/journey.js +18 -8
- package/src/routes/static.js +5 -4
- package/views/casa/layouts/journey.njk +1 -1
- package/views/casa/layouts/main.njk +11 -21
- package/dist/casa.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/configure.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/index.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js.map +0 -1
- package/dist/core-plugins/edit-snapshot/src/utils.js.map +0 -1
- package/dist/core-plugins/index.js.map +0 -1
- package/dist/lib/CasaTemplateLoader.js.map +0 -1
- package/dist/lib/JourneyContext.js.map +0 -1
- package/dist/lib/MutableRouter.js.map +0 -1
- package/dist/lib/Plan.js.map +0 -1
- package/dist/lib/ValidationError.js.map +0 -1
- package/dist/lib/ValidatorFactory.js.map +0 -1
- package/dist/lib/configuration-ingestor.js.map +0 -1
- package/dist/lib/configure.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/context-id-generators.js.map +0 -1
- package/dist/lib/dirname.cjs +0 -1
- package/dist/lib/dirname.d.cts +0 -2
- package/dist/lib/end-session.js.map +0 -1
- package/dist/lib/field.js.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/logger.js.map +0 -1
- package/dist/lib/mount.js.map +0 -1
- package/dist/lib/nunjucks-filters.js.map +0 -1
- package/dist/lib/nunjucks.js.map +0 -1
- package/dist/lib/utils.js.map +0 -1
- package/dist/lib/validators/dateObject.js.map +0 -1
- package/dist/lib/validators/email.js.map +0 -1
- package/dist/lib/validators/inArray.js.map +0 -1
- package/dist/lib/validators/index.js.map +0 -1
- package/dist/lib/validators/nino.js.map +0 -1
- package/dist/lib/validators/postalAddressObject.js.map +0 -1
- package/dist/lib/validators/range.js.map +0 -1
- package/dist/lib/validators/regex.js.map +0 -1
- package/dist/lib/validators/required.js.map +0 -1
- package/dist/lib/validators/strlen.js.map +0 -1
- package/dist/lib/validators/wordCount.js.map +0 -1
- package/dist/lib/waypoint-url.js.map +0 -1
- package/dist/middleware/body-parser.js.map +0 -1
- package/dist/middleware/csrf.js.map +0 -1
- package/dist/middleware/data.js.map +0 -1
- package/dist/middleware/dirname.cjs +0 -1
- package/dist/middleware/dirname.d.cts +0 -2
- package/dist/middleware/gather-fields.js.map +0 -1
- package/dist/middleware/i18n.js.map +0 -1
- package/dist/middleware/post.js.map +0 -1
- package/dist/middleware/pre.js.map +0 -1
- package/dist/middleware/progress-journey.js.map +0 -1
- package/dist/middleware/sanitise-fields.js.map +0 -1
- package/dist/middleware/serve-first-waypoint.js.map +0 -1
- package/dist/middleware/session.js.map +0 -1
- package/dist/middleware/skip-waypoint.js.map +0 -1
- package/dist/middleware/steer-journey.js.map +0 -1
- package/dist/middleware/strip-proxy-path.js.map +0 -1
- package/dist/middleware/validate-fields.js.map +0 -1
- package/dist/mjs/esm-wrapper.js +0 -20
- package/dist/mjs/package.json +0 -3
- package/dist/package.json +0 -3
- package/dist/routes/ancillary.js.map +0 -1
- package/dist/routes/dirname.cjs +0 -1
- package/dist/routes/dirname.d.cts +0 -2
- package/dist/routes/journey.js.map +0 -1
- package/dist/routes/static.js.map +0 -1
- package/src/lib/dirname.cjs +0 -1
- package/src/middleware/dirname.cjs +0 -1
- 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
|
|
92
|
-
* point
|
|
102
|
+
* Middleware function to insert at the
|
|
103
|
+
* hook point
|
|
93
104
|
*/
|
|
94
|
-
middleware:
|
|
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
|
|
111
|
-
* point
|
|
121
|
+
* Middleware function to insert at the
|
|
122
|
+
* hook point
|
|
112
123
|
*/
|
|
113
|
-
middleware:
|
|
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:
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
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
|
-
*
|
|
278
|
+
* Middleware mounted before
|
|
279
|
+
* everything
|
|
272
280
|
*/
|
|
273
|
-
preMiddleware:
|
|
281
|
+
preMiddleware: RequestHandler[];
|
|
274
282
|
/**
|
|
275
|
-
* Middleware
|
|
276
|
-
*
|
|
283
|
+
* Middleware mounted after
|
|
284
|
+
* everything
|
|
277
285
|
*/
|
|
278
|
-
postMiddleware:
|
|
286
|
+
postMiddleware: RequestHandler[];
|
|
279
287
|
/**
|
|
280
|
-
* CSRF get/set
|
|
281
|
-
* form middleware
|
|
288
|
+
* CSRF get/set form middleware
|
|
282
289
|
*/
|
|
283
|
-
csrfMiddleware:
|
|
290
|
+
csrfMiddleware: RequestHandler[];
|
|
284
291
|
/**
|
|
285
|
-
* Session
|
|
286
|
-
* middleware
|
|
292
|
+
* Session middleware
|
|
287
293
|
*/
|
|
288
|
-
sessionMiddleware:
|
|
294
|
+
sessionMiddleware: RequestHandler;
|
|
289
295
|
/**
|
|
290
|
-
*
|
|
296
|
+
* Cookie-parsing middleware
|
|
291
297
|
*/
|
|
292
|
-
cookieParserMiddleware:
|
|
298
|
+
cookieParserMiddleware: RequestHandler[];
|
|
293
299
|
/**
|
|
294
|
-
* I18n
|
|
295
|
-
* preparation middleware
|
|
300
|
+
* I18n preparation middleware
|
|
296
301
|
*/
|
|
297
|
-
i18nMiddleware:
|
|
302
|
+
i18nMiddleware: RequestHandler[];
|
|
298
303
|
/**
|
|
299
|
-
* Body
|
|
300
|
-
* parsing middleware
|
|
304
|
+
* Body parsing middleware
|
|
301
305
|
*/
|
|
302
|
-
bodyParserMiddleware:
|
|
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?:
|
|
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
|
|
544
|
+
* Validation
|
|
545
|
+
* state
|
|
519
546
|
*/
|
|
520
|
-
validation?:
|
|
547
|
+
validation?: Record<string, ValidationError[] | null> | undefined;
|
|
521
548
|
/**
|
|
522
549
|
* Navigation meta
|
|
523
550
|
*/
|
|
524
|
-
nav?:
|
|
551
|
+
nav?: object | undefined;
|
|
525
552
|
/**
|
|
526
553
|
* Identity meta
|
|
527
554
|
*/
|
|
528
|
-
identity?:
|
|
555
|
+
identity?: JourneyContextIdentity | undefined;
|
|
529
556
|
};
|
|
530
557
|
export type ContextIdGeneratorParams = {
|
|
531
558
|
/**
|
|
532
559
|
* Arguments
|
|
533
560
|
*/
|
|
534
561
|
args: {
|
|
535
|
-
req:
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 {
|
|
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 {
|
|
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 {
|
|
159
|
-
* @returns {
|
|
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 |
|
|
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 {
|
|
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 {
|
|
211
|
-
*
|
|
212
|
-
* @property {
|
|
213
|
-
*
|
|
214
|
-
* @property {
|
|
215
|
-
*
|
|
216
|
-
* @property {
|
|
217
|
-
*
|
|
218
|
-
* @property {
|
|
219
|
-
*
|
|
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 {
|
|
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 {
|
|
367
|
-
*
|
|
368
|
-
* @property {
|
|
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 {
|
|
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
|
-
|
|
375
|
+
/** @typedef {import("../src/globals.d.ts")} */
|
|
@@ -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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 = (
|
|
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
|
|
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:
|
|
18
|
+
middleware: preSteerHook,
|
|
25
19
|
}, {
|
|
26
20
|
hook: "journey.poststeer",
|
|
27
|
-
middleware:
|
|
21
|
+
middleware: postSteerHook,
|
|
28
22
|
});
|
|
29
23
|
}
|
|
30
|
-
//# sourceMappingURL=configure.js.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
|
-
|
|
2
|
-
|
|
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
|
|
4
|
+
configure,
|
|
10
5
|
};
|
|
11
6
|
};
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
declare
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
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[
|
|
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
|
-
|
|
12
|
+
deleteSnapshot(log, req);
|
|
17
13
|
// eslint-disable-next-line security/detect-object-injection
|
|
18
|
-
req.casa[
|
|
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
|