@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/routes/journey.js
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const progress_journey_js_1 = __importDefault(require("../middleware/progress-journey.js"));
|
|
15
|
-
const waypoint_url_js_1 = __importDefault(require("../lib/waypoint-url.js"));
|
|
16
|
-
const logger_js_1 = __importDefault(require("../lib/logger.js"));
|
|
17
|
-
const utils_js_1 = require("../lib/utils.js");
|
|
18
|
-
const constants_js_1 = require("../lib/constants.js");
|
|
19
|
-
const log = (0, logger_js_1.default)("routes:journey");
|
|
1
|
+
import MutableRouter from "../lib/MutableRouter.js";
|
|
2
|
+
import NullObject from "../lib/NullObject.js";
|
|
3
|
+
import skipWaypointMiddlewareFactory from "../middleware/skip-waypoint.js";
|
|
4
|
+
import steerJourneyMiddlewareFactory from "../middleware/steer-journey.js";
|
|
5
|
+
import sanitiseFieldsMiddlewareFactory from "../middleware/sanitise-fields.js";
|
|
6
|
+
import gatherFieldsMiddlewareFactory from "../middleware/gather-fields.js";
|
|
7
|
+
import validateFieldsMiddlewareFactory from "../middleware/validate-fields.js";
|
|
8
|
+
import progressJourneyMiddlewareFactory from "../middleware/progress-journey.js";
|
|
9
|
+
import waypointUrl from "../lib/waypoint-url.js";
|
|
10
|
+
import logger from "../lib/logger.js";
|
|
11
|
+
import { resolveMiddlewareHooks } from "../lib/utils.js";
|
|
12
|
+
import { CONFIG_ERROR_VISIBILITY_ALWAYS } from "../lib/constants.js";
|
|
13
|
+
const log = logger("routes:journey");
|
|
20
14
|
/**
|
|
21
|
-
* @
|
|
15
|
+
* @typedef {import("../casa.js").GlobalHook} GlobalHook
|
|
22
16
|
* @access private
|
|
23
17
|
*/
|
|
24
18
|
/**
|
|
25
|
-
* @
|
|
19
|
+
* @typedef {import("../casa.js").Page} Page
|
|
26
20
|
* @access private
|
|
27
21
|
*/
|
|
28
22
|
/**
|
|
29
|
-
* @
|
|
23
|
+
* @typedef {import("../casa.js").Plan} Plan
|
|
30
24
|
* @access private
|
|
31
25
|
*/
|
|
32
26
|
/** @typedef {import("../casa.js").ValidationError} ValidationError */
|
|
@@ -40,7 +34,8 @@ const log = (0, logger_js_1.default)("routes:journey");
|
|
|
40
34
|
* @property {GlobalHook[]} globalHooks Global hooks
|
|
41
35
|
* @property {Page[]} pages Page definitions
|
|
42
36
|
* @property {Plan} plan Plan
|
|
43
|
-
* @property {
|
|
37
|
+
* @property {import("express").RequestHandler[]} csrfMiddleware Middleware for
|
|
38
|
+
* providing CSRF controls
|
|
44
39
|
*/
|
|
45
40
|
const renderMiddlewareFactory = (view, contextFactory) => [
|
|
46
41
|
(req, res, next) => {
|
|
@@ -69,11 +64,17 @@ const renderMiddlewareFactory = (view, contextFactory) => [
|
|
|
69
64
|
* @param {import("express").Request} req Casa request object
|
|
70
65
|
* @returns {GovUkErrorObject[]} Array of error objects
|
|
71
66
|
*/
|
|
72
|
-
const generateGovukErrors = (errors, req) => Object.values(errors || {}).map(([error]) => ({
|
|
67
|
+
export const generateGovukErrors = (errors, req) => Object.values(errors || {}).map(([error]) => ({
|
|
73
68
|
text: req.t(error.summary, error.variables),
|
|
74
69
|
href: error.fieldHref,
|
|
75
70
|
}));
|
|
76
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Generate edit cancel URL
|
|
73
|
+
*
|
|
74
|
+
* @param {string} editOrigin Edit mode origin waypoint
|
|
75
|
+
* @param {string} waypoint Current waypoint
|
|
76
|
+
* @returns {string} Edit cancel URL
|
|
77
|
+
*/
|
|
77
78
|
const generateEditCancelUrl = (editOrigin, waypoint) => {
|
|
78
79
|
const url = new URL(editOrigin, "https://placeholder.test/");
|
|
79
80
|
url.searchParams.set("editcancel", waypoint);
|
|
@@ -82,14 +83,15 @@ const generateEditCancelUrl = (editOrigin, waypoint) => {
|
|
|
82
83
|
/**
|
|
83
84
|
* Handle errorVisibility flag and function and return boolean
|
|
84
85
|
*
|
|
85
|
-
* @param {
|
|
86
|
-
* @param {
|
|
86
|
+
* @param {import("express").Request} req Casa request object
|
|
87
|
+
* @param {Page["errorVisibility"]} errorVisibility ErrorVisibility config
|
|
88
|
+
* option
|
|
87
89
|
* @returns {boolean} True if errorVisibility is "always" or function condition
|
|
88
90
|
* true
|
|
89
91
|
*/
|
|
90
92
|
const resolveErrorVisibility = (req, errorVisibility) => typeof errorVisibility === "function"
|
|
91
93
|
? errorVisibility({ req })
|
|
92
|
-
: errorVisibility ===
|
|
94
|
+
: errorVisibility === CONFIG_ERROR_VISIBILITY_ALWAYS;
|
|
93
95
|
/**
|
|
94
96
|
* Create an instance of the router for all waypoints visited during a Journey
|
|
95
97
|
* through the Plan.
|
|
@@ -98,9 +100,9 @@ const resolveErrorVisibility = (req, errorVisibility) => typeof errorVisibility
|
|
|
98
100
|
* @returns {MutableRouter} Router
|
|
99
101
|
* @access private
|
|
100
102
|
*/
|
|
101
|
-
function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVisibility, }) {
|
|
103
|
+
export default function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVisibility, }) {
|
|
102
104
|
// Router
|
|
103
|
-
const router = new
|
|
105
|
+
const router = new MutableRouter({ mergeParams: true });
|
|
104
106
|
// Special "_" route which handles redirecting the user between sub-apps
|
|
105
107
|
// /app1/_/?refmount=app2&route=prev
|
|
106
108
|
router.all("/_", (req, res) => {
|
|
@@ -109,7 +111,7 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
109
111
|
const route = req.query?.route;
|
|
110
112
|
log.trace(`App root ${mountUrl}: refmount = ${refmount}, route = ${route}`);
|
|
111
113
|
let redirectTo;
|
|
112
|
-
const fallback = (
|
|
114
|
+
const fallback = waypointUrl({
|
|
113
115
|
mountUrl,
|
|
114
116
|
waypoint: plan.traverse(req.casa.journeyContext, {
|
|
115
117
|
stopCondition: () => true, // we only need one; stop at the first
|
|
@@ -127,7 +129,7 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
127
129
|
startWaypoint: refmount,
|
|
128
130
|
});
|
|
129
131
|
redirectTo = routes.length
|
|
130
|
-
? (
|
|
132
|
+
? waypointUrl({
|
|
131
133
|
mountUrl,
|
|
132
134
|
waypoint: routes[0].target,
|
|
133
135
|
journeyContext: req.casa.journeyContext,
|
|
@@ -140,7 +142,7 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
140
142
|
});
|
|
141
143
|
if (routes[0].target !== null) {
|
|
142
144
|
redirectTo = routes.length
|
|
143
|
-
? (
|
|
145
|
+
? waypointUrl({
|
|
144
146
|
mountUrl,
|
|
145
147
|
waypoint: routes[0].target,
|
|
146
148
|
journeyContext: req.casa.journeyContext,
|
|
@@ -178,16 +180,16 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
178
180
|
log.info(`Configuring "${waypoint}" as a skippable waypoint`);
|
|
179
181
|
commonWaypointMiddleware = [
|
|
180
182
|
...commonWaypointMiddleware,
|
|
181
|
-
...(
|
|
183
|
+
...skipWaypointMiddlewareFactory({ waypoint }),
|
|
182
184
|
];
|
|
183
185
|
}
|
|
184
|
-
router.get(waypointPath, ...commonMiddleware, ...commonWaypointMiddleware, ...
|
|
186
|
+
router.get(waypointPath, ...commonMiddleware, ...commonWaypointMiddleware, ...resolveMiddlewareHooks("journey.presteer", waypointPath, [
|
|
185
187
|
...globalHooks,
|
|
186
188
|
...pageHooks,
|
|
187
|
-
]), ...(
|
|
189
|
+
]), ...steerJourneyMiddlewareFactory({ waypoint, plan }), ...resolveMiddlewareHooks("journey.poststeer", waypointPath, [
|
|
188
190
|
...globalHooks,
|
|
189
191
|
...pageHooks,
|
|
190
|
-
]), ...
|
|
192
|
+
]), ...resolveMiddlewareHooks("journey.prerender", waypointPath, [
|
|
191
193
|
...globalHooks,
|
|
192
194
|
...pageHooks,
|
|
193
195
|
]), renderMiddlewareFactory(view, (req) => {
|
|
@@ -195,10 +197,10 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
195
197
|
resolveErrorVisibility(req, errorVisibility);
|
|
196
198
|
const errors = displayErrors &&
|
|
197
199
|
(req.casa.journeyContext.getValidationErrorsForPageByField(waypoint) ??
|
|
198
|
-
|
|
199
|
-
const govukErrors = displayErrors &&
|
|
200
|
+
new NullObject());
|
|
201
|
+
const govukErrors = displayErrors && generateGovukErrors(errors, req);
|
|
200
202
|
return {
|
|
201
|
-
formUrl: (
|
|
203
|
+
formUrl: waypointUrl({
|
|
202
204
|
mountUrl: `${req.baseUrl}/`,
|
|
203
205
|
waypoint,
|
|
204
206
|
journeyContext: req.casa.journeyContext,
|
|
@@ -208,28 +210,28 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
208
210
|
formErrorsGovukArray: govukErrors.length && displayErrors ? govukErrors : null,
|
|
209
211
|
};
|
|
210
212
|
}));
|
|
211
|
-
router.post(waypointPath, ...commonMiddleware, ...commonWaypointMiddleware, ...
|
|
213
|
+
router.post(waypointPath, ...commonMiddleware, ...commonWaypointMiddleware, ...resolveMiddlewareHooks("journey.presteer", waypointPath, [
|
|
212
214
|
...globalHooks,
|
|
213
215
|
...pageHooks,
|
|
214
|
-
]), ...(
|
|
216
|
+
]), ...steerJourneyMiddlewareFactory({ waypoint, plan }), ...resolveMiddlewareHooks("journey.poststeer", waypointPath, [
|
|
215
217
|
...globalHooks,
|
|
216
218
|
...pageHooks,
|
|
217
|
-
]), ...
|
|
219
|
+
]), ...resolveMiddlewareHooks("journey.presanitise", waypointPath, [
|
|
218
220
|
...globalHooks,
|
|
219
221
|
...pageHooks,
|
|
220
|
-
]), ...(
|
|
222
|
+
]), ...sanitiseFieldsMiddlewareFactory({ waypoint, fields }), ...resolveMiddlewareHooks("journey.postsanitise", waypointPath, [
|
|
221
223
|
...globalHooks,
|
|
222
224
|
...pageHooks,
|
|
223
|
-
]), ...
|
|
225
|
+
]), ...resolveMiddlewareHooks("journey.pregather", waypointPath, [
|
|
224
226
|
...globalHooks,
|
|
225
227
|
...pageHooks,
|
|
226
|
-
]), ...(
|
|
228
|
+
]), ...gatherFieldsMiddlewareFactory({ waypoint, fields }), ...resolveMiddlewareHooks("journey.postgather", waypointPath, [
|
|
227
229
|
...globalHooks,
|
|
228
230
|
...pageHooks,
|
|
229
|
-
]), ...
|
|
231
|
+
]), ...resolveMiddlewareHooks("journey.prevalidate", waypointPath, [
|
|
230
232
|
...globalHooks,
|
|
231
233
|
...pageHooks,
|
|
232
|
-
]), ...(
|
|
234
|
+
]), ...validateFieldsMiddlewareFactory({ waypoint, fields, plan }), ...resolveMiddlewareHooks("journey.postvalidate", waypointPath, [
|
|
233
235
|
...globalHooks,
|
|
234
236
|
...pageHooks,
|
|
235
237
|
]),
|
|
@@ -237,16 +239,16 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
237
239
|
// next, where the errors will be rendered
|
|
238
240
|
(req, res, next) => req.casa.journeyContext.hasValidationErrorsForPage(waypoint)
|
|
239
241
|
? next("route")
|
|
240
|
-
: next(), ...
|
|
242
|
+
: next(), ...resolveMiddlewareHooks("journey.preredirect", waypointPath, [
|
|
241
243
|
...globalHooks,
|
|
242
244
|
...pageHooks,
|
|
243
|
-
]), ...(
|
|
244
|
-
router.post(waypointPath, ...
|
|
245
|
+
]), ...progressJourneyMiddlewareFactory({ waypoint, plan }));
|
|
246
|
+
router.post(waypointPath, ...resolveMiddlewareHooks("journey.prerender", waypointPath, [
|
|
245
247
|
...globalHooks,
|
|
246
248
|
...pageHooks,
|
|
247
249
|
]), renderMiddlewareFactory(view, (req) => {
|
|
248
250
|
const errors = req.casa.journeyContext.getValidationErrorsForPageByField(waypoint) ??
|
|
249
|
-
|
|
251
|
+
new NullObject();
|
|
250
252
|
// This is a convenience for the template. The `govukErrorSummary` macro
|
|
251
253
|
// requires the errors be in a particular format, so here we provide our
|
|
252
254
|
// errors in that format.
|
|
@@ -254,9 +256,9 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
254
256
|
// first one is shown.
|
|
255
257
|
// Disabling security/detect-object-injection rule because both `errors`
|
|
256
258
|
// and the `k` property are known entities
|
|
257
|
-
const govukErrors =
|
|
259
|
+
const govukErrors = generateGovukErrors(errors, req);
|
|
258
260
|
return {
|
|
259
|
-
formUrl: (
|
|
261
|
+
formUrl: waypointUrl({
|
|
260
262
|
mountUrl: `${req.baseUrl}/`,
|
|
261
263
|
waypoint,
|
|
262
264
|
journeyContext: req.casa.journeyContext,
|
|
@@ -269,4 +271,3 @@ function journeyRouter({ globalHooks, pages, plan, csrfMiddleware, globalErrorVi
|
|
|
269
271
|
}
|
|
270
272
|
return router;
|
|
271
273
|
}
|
|
272
|
-
//# sourceMappingURL=journey.js.map
|
package/dist/routes/static.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/routes/static.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,iEAJW,aAAa,GACX,aAAa,CA2FzB;;;;;;;;;;;;;;;;0BA5GyB,yBAAyB"}
|
package/dist/routes/static.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const node_url_1 = require("node:url");
|
|
10
|
-
const node_path_1 = require("node:path");
|
|
11
|
-
const node_module_1 = require("node:module");
|
|
12
|
-
const dirname_cjs_1 = __importDefault(require("./dirname.cjs"));
|
|
13
|
-
const MutableRouter_js_1 = __importDefault(require("../lib/MutableRouter.js"));
|
|
14
|
-
const utils_js_1 = require("../lib/utils.js");
|
|
15
|
-
const { static: ExpressStatic } = express_1.default; // CommonJS
|
|
1
|
+
import ExpressJS from "express";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { URL } from "node:url";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import MutableRouter from "../lib/MutableRouter.js";
|
|
7
|
+
import { validateUrlPath } from "../lib/utils.js";
|
|
8
|
+
const { static: ExpressStatic } = ExpressJS; // CommonJS
|
|
16
9
|
/**
|
|
17
10
|
* @typedef {object} StaticOptions Options to configure static router
|
|
18
11
|
* @property {number} [maxAge=3600000] Cache TTL for all assets. Default is
|
|
@@ -27,8 +20,8 @@ const { static: ExpressStatic } = express_1.default; // CommonJS
|
|
|
27
20
|
* @returns {MutableRouter} ExpressJS Router instance
|
|
28
21
|
* @access private
|
|
29
22
|
*/
|
|
30
|
-
function staticRouter({ maxAge = 3600000, cacheControl = "no-cache, private", } = {}) {
|
|
31
|
-
const router = new
|
|
23
|
+
export default function staticRouter({ maxAge = 3600000, cacheControl = "no-cache, private", } = {}) {
|
|
24
|
+
const router = new MutableRouter();
|
|
32
25
|
const notFoundHandler = (req, res, next) => {
|
|
33
26
|
// Fall through to a general purpose error handler
|
|
34
27
|
next(new Error("404"));
|
|
@@ -36,7 +29,7 @@ function staticRouter({ maxAge = 3600000, cacheControl = "no-cache, private", }
|
|
|
36
29
|
const setHeaders = (req, res, next) => {
|
|
37
30
|
res.set("cache-control", cacheControl);
|
|
38
31
|
res.set("expires", new Date(Date.now() + maxAge).toUTCString());
|
|
39
|
-
const { pathname } = new
|
|
32
|
+
const { pathname } = new URL(req?.originalUrl ?? "", "https://placeholder.test/");
|
|
40
33
|
if (pathname.substr(-4) === ".css") {
|
|
41
34
|
// Just needed for our in-memory CSS assets
|
|
42
35
|
res.set("content-type", "text/css");
|
|
@@ -55,18 +48,17 @@ function staticRouter({ maxAge = 3600000, cacheControl = "no-cache, private", }
|
|
|
55
48
|
// must be replaced with the dynamic `mountUrl` to ensure govuk-frontend
|
|
56
49
|
// assets are served from the correct location.
|
|
57
50
|
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
58
|
-
const casaCss =
|
|
51
|
+
const casaCss = readFileSync(resolve(import.meta.dirname, "../../dist/assets/css/casa.css"), { encoding: "utf8" });
|
|
59
52
|
/* eslint-enable security/detect-non-literal-fs-filename */
|
|
60
53
|
// The static middleware will only server GET/HEAD requests, so we can mount
|
|
61
54
|
// the middleware using `use()` rather than resorting to `get()`
|
|
62
|
-
const govukFrontendDirectory =
|
|
55
|
+
const govukFrontendDirectory = resolve(createRequire(import.meta.dirname).resolve("govuk-frontend"), "../../");
|
|
63
56
|
router.use("/govuk/govuk-frontend.min.js", ExpressStatic(`${govukFrontendDirectory}/govuk/govuk-frontend.min.js`, staticConfig));
|
|
64
57
|
router.use("/govuk/govuk-frontend.min.js.map", ExpressStatic(`${govukFrontendDirectory}/govuk/govuk-frontend.min.js.map`, staticConfig));
|
|
65
58
|
router.use("/govuk/assets", ExpressStatic(`${govukFrontendDirectory}/govuk/assets`, staticConfig));
|
|
66
59
|
router.use("/govuk/assets", notFoundHandler);
|
|
67
|
-
router.get("/casa/assets/css/casa.css", setHeaders, (req, res) => res.send(casaCss.replace(/~~~CASA_MOUNT_URL~~~/g,
|
|
68
|
-
router.use("/casa/assets/css/casa.css.map", ExpressStatic(
|
|
60
|
+
router.get("/casa/assets/css/casa.css", setHeaders, (req, res) => res.send(casaCss.replace(/~~~CASA_MOUNT_URL~~~/g, validateUrlPath(`${req.baseUrl}/`))));
|
|
61
|
+
router.use("/casa/assets/css/casa.css.map", ExpressStatic(resolve(import.meta.dirname, "../../dist/assets/css/casa.css.map")));
|
|
69
62
|
router.use("/casa/assets", notFoundHandler);
|
|
70
63
|
return router;
|
|
71
64
|
}
|
|
72
|
-
//# sourceMappingURL=static.js.map
|
package/package.json
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dwp/govuk-casa",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "A framework for building GOVUK Collect-And-Submit-Applications",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git@github.com:dwp/govuk-casa.git"
|
|
8
8
|
},
|
|
9
|
+
"type": "module",
|
|
9
10
|
"main": "dist/casa.js",
|
|
10
|
-
"
|
|
11
|
-
"exports": {
|
|
12
|
-
"types": "./dist/casa.d.ts",
|
|
13
|
-
"import": "./dist/mjs/esm-wrapper.js",
|
|
14
|
-
"require": "./dist/casa.js"
|
|
15
|
-
},
|
|
11
|
+
"types": "dist/casa.d.ts",
|
|
16
12
|
"files": [
|
|
17
13
|
"dist/**/*",
|
|
18
14
|
"locales/**/*",
|
|
@@ -22,14 +18,15 @@
|
|
|
22
18
|
"!src/core-plugins/**/tests/"
|
|
23
19
|
],
|
|
24
20
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
26
|
-
"npm": ">=
|
|
21
|
+
"node": ">=22",
|
|
22
|
+
"npm": ">=10"
|
|
27
23
|
},
|
|
28
24
|
"scripts": {
|
|
29
25
|
"pipeline": "npm run coverage && npm run lint",
|
|
30
26
|
"coverage": "c8 npm test",
|
|
31
|
-
"test": "npm run test:unit && npm run test:e2e && npm run core-plugin:edit-snapshot:test:e2e",
|
|
32
|
-
"test:
|
|
27
|
+
"test": "npm run test:mkdir && npm run test:unit && npm run test:e2e && npm run core-plugin:edit-snapshot:test:e2e",
|
|
28
|
+
"test:mkdir": "node -e 'require(`node:fs/promises`).mkdir(`./.junit`).catch((err) => err.code !== `EEXIST` && console.error(err))'",
|
|
29
|
+
"test:unit": "node --test --test-reporter=junit --test-reporter-destination=.junit/unit.xml --test-reporter=spec --test-reporter-destination=stdout",
|
|
33
30
|
"test:e2e": "spiderplan --worker-init ./tests/e2e/worker-init.js --language en ./tests/e2e/personas/**/*.yaml",
|
|
34
31
|
"test:dast": "spiderplan --worker-init ./tests/e2e/worker-init.js --language en ./tests/e2e/personas/**/traversal.yaml --workers 1 --zap --zap-proxy 'http://localhost:8080/' --zap-target-hostname 'host.docker.internal'",
|
|
35
32
|
"test:dast:report": "curl -s --header 'X-ZAP-Api-Key: secret' http://localhost:8080/OTHER/core/other/htmlreport > gl-dast-report.html",
|
|
@@ -39,7 +36,7 @@
|
|
|
39
36
|
"lint": "eslint .",
|
|
40
37
|
"build": "npm run build:prepare && npm run build:sources && npm run build:css-assets",
|
|
41
38
|
"build:prepare": "rm -rf dist/* && mkdir -p dist/assets/js/ && mkdir -p dist/assets/css/",
|
|
42
|
-
"build:sources": "tsc -p tsconfig
|
|
39
|
+
"build:sources": "tsc -p tsconfig.json && sed 1d ./src/globals.d.ts >> dist/casa.d.ts",
|
|
43
40
|
"build:css-assets": "node scripts/compile-sass.js",
|
|
44
41
|
"build:api-docs": "npx jsdoc -c ./jsdoc.json -d ./docs/api/ --debug -P '' -r -R ./README.md --verbose -t ./node_modules/docdash ./src",
|
|
45
42
|
"prepare": "npm run build",
|
|
@@ -50,22 +47,22 @@
|
|
|
50
47
|
"keywords": [],
|
|
51
48
|
"author": "DWP Digital",
|
|
52
49
|
"license": "ISC",
|
|
53
|
-
"type": "module",
|
|
54
50
|
"dependencies": {
|
|
55
|
-
"@dagrejs/graphlib": "
|
|
51
|
+
"@dagrejs/graphlib": "4.0.1",
|
|
52
|
+
"@fastify/deepmerge": "3.2.1",
|
|
56
53
|
"bytes": "3.1.2",
|
|
57
54
|
"cookie-parser": "1.4.7",
|
|
58
55
|
"csrf-sync": "4.2.1",
|
|
59
56
|
"debug": "4.4.3",
|
|
60
|
-
"
|
|
61
|
-
"express": "4.22.1",
|
|
57
|
+
"express": "5.2.1",
|
|
62
58
|
"express-session": "1.19.0",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"i18next
|
|
59
|
+
"fast-equals": "6.0.0",
|
|
60
|
+
"govuk-frontend": "6.1.0",
|
|
61
|
+
"helmet": "8.2.0",
|
|
62
|
+
"i18next": "26.3.0",
|
|
63
|
+
"i18next-http-middleware": "3.9.7",
|
|
64
|
+
"is-plain-obj": "4.1.0",
|
|
67
65
|
"js-yaml": "4.1.1",
|
|
68
|
-
"lodash": "4.18.1",
|
|
69
66
|
"luxon": "3.7.2",
|
|
70
67
|
"nunjucks": "3.2.4",
|
|
71
68
|
"path-to-regexp": "8.4.2",
|
|
@@ -73,35 +70,32 @@
|
|
|
73
70
|
"validator": "13.15.35"
|
|
74
71
|
},
|
|
75
72
|
"devDependencies": {
|
|
76
|
-
"@dwp/casa-spiderplan": "
|
|
77
|
-
"@dwp/casa-spiderplan-a11y-plugin": "
|
|
78
|
-
"@dwp/casa-spiderplan-zap-plugin": "
|
|
73
|
+
"@dwp/casa-spiderplan": "5.0.0",
|
|
74
|
+
"@dwp/casa-spiderplan-a11y-plugin": "2.0.0",
|
|
75
|
+
"@dwp/casa-spiderplan-zap-plugin": "2.0.0",
|
|
79
76
|
"@dwp/commitlint-config-base": "5.0.0",
|
|
80
77
|
"@dwp/eslint-config-base": "9.0.2",
|
|
81
78
|
"@types/express": "5.0.6",
|
|
82
79
|
"@types/luxon": "3.7.1",
|
|
83
|
-
"@types/node": "25.
|
|
80
|
+
"@types/node": "25.9.1",
|
|
84
81
|
"@types/nunjucks": "3.2.6",
|
|
85
82
|
"c8": "11.0.0",
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"commitlint": "20.5.3",
|
|
83
|
+
"cheerio": "1.2.0",
|
|
84
|
+
"commitlint": "21.0.1",
|
|
89
85
|
"docdash": "2.0.2",
|
|
90
86
|
"eslint": "9.39.4",
|
|
91
87
|
"eslint-plugin-import": "2.32.0",
|
|
92
|
-
"eslint-plugin-jsdoc": "
|
|
93
|
-
"eslint-plugin-security": "
|
|
94
|
-
"eslint-plugin-sonarjs": "
|
|
95
|
-
"fast-check": "4.
|
|
88
|
+
"eslint-plugin-jsdoc": "63.0.0",
|
|
89
|
+
"eslint-plugin-security": "4.0.0",
|
|
90
|
+
"eslint-plugin-sonarjs": "4.0.3",
|
|
91
|
+
"fast-check": "4.8.0",
|
|
96
92
|
"jsdoc": "4.0.5",
|
|
97
93
|
"jsdoc-tsimport-plugin": "1.0.5",
|
|
98
|
-
"mocha": "11.7.5",
|
|
99
94
|
"prettier": "3.8.3",
|
|
100
95
|
"prettier-plugin-jsdoc": "1.8.0",
|
|
101
|
-
"sass": "1.
|
|
102
|
-
"sinon": "22.0.0",
|
|
96
|
+
"sass": "1.100.0",
|
|
103
97
|
"supertest": "7.2.2",
|
|
104
98
|
"ts-api-utils": "2.5.0",
|
|
105
|
-
"typescript": "
|
|
99
|
+
"typescript": "6.0.3"
|
|
106
100
|
}
|
|
107
101
|
}
|
package/src/casa.js
CHANGED
|
@@ -48,6 +48,9 @@ export {
|
|
|
48
48
|
// These exist here so that consumer can import CASA's internal types
|
|
49
49
|
|
|
50
50
|
/** @typedef {import("./lib/field").PageField} PageField */
|
|
51
|
+
/** @typedef {import("express").Request} ExpressRequest */
|
|
52
|
+
/** @typedef {import("express").RequestHandler} RequestHandler */
|
|
53
|
+
/** @typedef {import("helmet").HelmetOptions} HelmetOptions */
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
56
|
* @typedef {object} ContextEventHandlerOptions
|
|
@@ -76,11 +79,19 @@ export {
|
|
|
76
79
|
* @property {ContextEventHandler} handler Handler to invoke when change happens
|
|
77
80
|
*/
|
|
78
81
|
|
|
82
|
+
/**
|
|
83
|
+
* @callback ErrorVisibiltyFunction
|
|
84
|
+
* @param {object} opts Options
|
|
85
|
+
* @param {ExpressRequest} opts.req Request
|
|
86
|
+
*/
|
|
87
|
+
|
|
79
88
|
/**
|
|
80
89
|
* @typedef {object} Page Page configuration. A Page is the interactive
|
|
81
90
|
* representation of a waypoint
|
|
82
91
|
* @property {string} waypoint The waypoint with which this page is associated
|
|
83
92
|
* @property {string} view Template path
|
|
93
|
+
* @property {ErrorVisibiltyFunction | symbol} [errorVisibility] Should page
|
|
94
|
+
* validation errors be visible on GET requests
|
|
84
95
|
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default []).
|
|
85
96
|
* Default is `[]`
|
|
86
97
|
* @property {PageField[]} [fields=[]] Fields to be managed on this page
|
|
@@ -99,8 +110,8 @@ export {
|
|
|
99
110
|
/**
|
|
100
111
|
* @typedef {object} GlobalHook Hook configuration
|
|
101
112
|
* @property {string} hook Hook name in format `<router>.<hook>`
|
|
102
|
-
* @property {
|
|
103
|
-
* point
|
|
113
|
+
* @property {RequestHandler} middleware Middleware function to insert at the
|
|
114
|
+
* hook point
|
|
104
115
|
* @property {string | RegExp} [path=undefined] Only run if route path matches
|
|
105
116
|
* this string/regexp. Default is `undefined`
|
|
106
117
|
*/
|
|
@@ -108,8 +119,8 @@ export {
|
|
|
108
119
|
/**
|
|
109
120
|
* @typedef {object} PageHook (extends GlobalHook)
|
|
110
121
|
* @property {string} hook Hook name (without a scope prefix)
|
|
111
|
-
* @property {
|
|
112
|
-
* point
|
|
122
|
+
* @property {RequestHandler} middleware Middleware function to insert at the
|
|
123
|
+
* hook point
|
|
113
124
|
*/
|
|
114
125
|
|
|
115
126
|
/**
|
|
@@ -145,8 +156,16 @@ export {
|
|
|
145
156
|
|
|
146
157
|
/**
|
|
147
158
|
* @callback HelmetConfigurator
|
|
148
|
-
* @param {
|
|
149
|
-
* @returns {
|
|
159
|
+
* @param {HelmetOptions} config A default Helmet configuration provided by CASA
|
|
160
|
+
* @returns {HelmetOptions} The modified configuration object
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @typedef {Omit<
|
|
165
|
+
* import("nunjucks").Environment &
|
|
166
|
+
* import("./lib/CasaTemplateLoader.js").default,
|
|
167
|
+
* "getSource"
|
|
168
|
+
* >} CasaNunjucksEnvironment
|
|
150
169
|
*/
|
|
151
170
|
|
|
152
171
|
/**
|
|
@@ -160,9 +179,12 @@ export {
|
|
|
160
179
|
*
|
|
161
180
|
* @callback Mounter
|
|
162
181
|
* @param {import("express").Express} app Express application
|
|
163
|
-
* @param {object} opts Mounting options
|
|
182
|
+
* @param {object} [opts] Mounting options
|
|
164
183
|
* @param {string} [opts.route='/'] Optional route to attach all
|
|
165
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`
|
|
166
188
|
* @returns {import("express").Express} The prepared ExpressJS app instance
|
|
167
189
|
*/
|
|
168
190
|
|
|
@@ -188,32 +210,26 @@ export {
|
|
|
188
210
|
* to ingest. Default is `"50KB"`
|
|
189
211
|
* @property {ContextIdGenerator} [contextIdGenerator] Custom context ID
|
|
190
212
|
* generator
|
|
191
|
-
* @property {symbol |
|
|
192
|
-
* active on GET request
|
|
193
|
-
* @property {boolean} [govukRebrand=false] Sets whether you wish to use the
|
|
194
|
-
* govuk rebrand. Default is `false`
|
|
213
|
+
* @property {symbol | ErrorVisibiltyFunction} [errorVisibility] Option to keep
|
|
214
|
+
* page errors active on GET request
|
|
195
215
|
*/
|
|
196
216
|
|
|
197
217
|
/**
|
|
198
218
|
* @typedef {object} ConfigureResult Result of a call to configure() function
|
|
199
|
-
* @property {
|
|
219
|
+
* @property {CasaNunjucksEnvironment} nunjucksEnv Nunjucks environment
|
|
200
220
|
* @property {MutableRouter} staticRouter Router handling all static assets
|
|
201
221
|
* @property {MutableRouter} ancillaryRouter Router handling ancillary routes
|
|
202
222
|
* @property {MutableRouter} journeyRouter Router handling all waypoint requests
|
|
203
|
-
* @property {
|
|
204
|
-
*
|
|
205
|
-
* @property {
|
|
206
|
-
*
|
|
207
|
-
* @property {
|
|
208
|
-
*
|
|
209
|
-
* @property {
|
|
210
|
-
*
|
|
211
|
-
* @property {
|
|
212
|
-
*
|
|
213
|
-
* @property {import("express").RequestHandler[]} i18nMiddleware I18n
|
|
214
|
-
* preparation middleware
|
|
215
|
-
* @property {import("express").RequestHandler} bodyParserMiddleware Body
|
|
216
|
-
* parsing middleware
|
|
223
|
+
* @property {RequestHandler[]} preMiddleware Middleware mounted before
|
|
224
|
+
* everything
|
|
225
|
+
* @property {RequestHandler[]} postMiddleware Middleware mounted after
|
|
226
|
+
* everything
|
|
227
|
+
* @property {RequestHandler[]} csrfMiddleware CSRF get/set form middleware
|
|
228
|
+
* @property {RequestHandler} sessionMiddleware Session middleware
|
|
229
|
+
* @property {RequestHandler[]} cookieParserMiddleware Cookie-parsing middleware
|
|
230
|
+
* @property {RequestHandler[]} i18nMiddleware I18n preparation middleware
|
|
231
|
+
* @property {RequestHandler} bodyParserMiddleware Body parsing middleware
|
|
232
|
+
* @property {RequestHandler[]} dataMiddleware Data decoration middleware
|
|
217
233
|
* @property {Mounter} mount Function used to mount all CASA artifacts onto an
|
|
218
234
|
* ExpressJS app
|
|
219
235
|
* @property {ConfigurationOptions} config Ingested config supplied to
|
|
@@ -342,13 +358,19 @@ export {
|
|
|
342
358
|
* @returns {boolean} Returns true is route should be followed
|
|
343
359
|
*/
|
|
344
360
|
|
|
361
|
+
/**
|
|
362
|
+
* @callback StopCondition
|
|
363
|
+
* @param {PlanRoute} route Route metadata
|
|
364
|
+
* @returns {boolean} Returns true is traversal should be stopped
|
|
365
|
+
*/
|
|
366
|
+
|
|
345
367
|
/**
|
|
346
368
|
* @typedef PlanTraverseOptions
|
|
347
369
|
* @property {string} [startWaypoint] Waypoint from which to start (defaults to
|
|
348
370
|
* first in list)
|
|
349
371
|
* @property {string} routeName Follow routes matching this name (next | prev)
|
|
350
372
|
* @property {Map} history Used to detect loops in traversal (INTERNAL USE ONLY)
|
|
351
|
-
* @property {
|
|
373
|
+
* @property {StopCondition} [stopCondition] If true, traversal will be stopped
|
|
352
374
|
* (useful for performance)
|
|
353
375
|
* @property {string | PlanArbiter} [arbiter] Multiple target routes found, this
|
|
354
376
|
* decides which to use
|
|
@@ -369,18 +391,26 @@ export {
|
|
|
369
391
|
* could eliminate
|
|
370
392
|
*/
|
|
371
393
|
|
|
394
|
+
/**
|
|
395
|
+
* @typedef {object} JourneyContextIdentity Journey Context Identity Object
|
|
396
|
+
* @property {string} [id] The context ID
|
|
397
|
+
* @property {string} [name] Context name
|
|
398
|
+
* @property {string[]} [tags] JouneyContext tags
|
|
399
|
+
*/
|
|
400
|
+
|
|
372
401
|
/**
|
|
373
402
|
* @typedef {object} JourneyContextObject Journey Context Object
|
|
374
403
|
* @property {Record<string, any>} [data] Data
|
|
375
|
-
* @property {
|
|
376
|
-
*
|
|
377
|
-
* @property {
|
|
404
|
+
* @property {Record<string, ValidationError[] | null>} [validation] Validation
|
|
405
|
+
* state
|
|
406
|
+
* @property {object} [nav] Navigation meta
|
|
407
|
+
* @property {JourneyContextIdentity} [identity] Identity meta
|
|
378
408
|
*/
|
|
379
409
|
|
|
380
410
|
/**
|
|
381
411
|
* @typedef ContextIdGeneratorParams
|
|
382
412
|
* @property {object} args Arguments
|
|
383
|
-
* @property {
|
|
413
|
+
* @property {ExpressRequest} args.req Request
|
|
384
414
|
* @property {[string]} args.reservedIds List of IDs already in use in session
|
|
385
415
|
* or request
|
|
386
416
|
*/
|
|
@@ -399,3 +429,5 @@ export {
|
|
|
399
429
|
* @param {ContextIdGeneratorParams} params Parameters
|
|
400
430
|
* @returns {string} A newly generated GUID
|
|
401
431
|
*/
|
|
432
|
+
|
|
433
|
+
/** @typedef {import("../src/globals.d.ts")} */
|