@dwp/govuk-casa 8.2.5 → 8.2.8

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.
@@ -3,20 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const express_1 = require("express");
7
6
  const express_session_1 = require("express-session");
8
7
  const path_1 = require("path");
9
8
  const module_1 = require("module");
10
9
  const cookie_parser_1 = __importDefault(require("cookie-parser"));
11
- const path_to_regexp_1 = require("path-to-regexp");
12
10
  const dirname_cjs_1 = __importDefault(require("./dirname.cjs"));
13
- const utils_js_1 = require("./utils.js");
14
11
  const configuration_ingestor_js_1 = __importDefault(require("./configuration-ingestor.js"));
15
12
  const nunjucks_js_1 = __importDefault(require("./nunjucks.js"));
13
+ const mount_js_1 = __importDefault(require("./mount.js"));
16
14
  const static_js_1 = __importDefault(require("../routes/static.js"));
17
15
  const ancillary_js_1 = __importDefault(require("../routes/ancillary.js"));
18
16
  const journey_js_1 = __importDefault(require("../routes/journey.js"));
19
- const strip_proxy_path_js_1 = __importDefault(require("../middleware/strip-proxy-path.js"));
20
17
  const pre_js_1 = __importDefault(require("../middleware/pre.js"));
21
18
  const post_js_1 = __importDefault(require("../middleware/post.js"));
22
19
  const session_js_1 = __importDefault(require("../middleware/session.js"));
@@ -30,7 +27,7 @@ const csrf_js_1 = __importDefault(require("../middleware/csrf.js"));
30
27
  */
31
28
  /**
32
29
  * @access private
33
- * @typedef {import('../casa').ConfigurationOptions} ConfigureResult
30
+ * @typedef {import('../casa').ConfigureResult} ConfigureResult
34
31
  */
35
32
  /**
36
33
  * @access private
@@ -125,73 +122,21 @@ function configure(config = {}) {
125
122
  plan,
126
123
  csrfMiddleware,
127
124
  });
128
- // Mount function
129
- // This will mount all of these routes and middleware in the correct order on
130
- // the given ExpressJS app.
131
- // Once this is called, you will not be able to modify any of the routers as
132
- // they will be "sealed".
133
- /**
134
- * Mounting function.
135
- *
136
- * @type {Mounter} mount
137
- */
138
- const mount = (app, { route = '/' } = {}) => {
139
- nunjucksEnv.express(app);
140
- app.set('view engine', 'njk');
141
- // If a `mountUrl` has been defined, then we're potentially in "proxy mode",
142
- // in which we strip the proxy path prefix from the incoming request URLs.
143
- if (mountUrl) {
144
- app.use((0, strip_proxy_path_js_1.default)({ mountUrl }));
145
- }
146
- // Attach a handler to redirect requests for `/` to the first waypoint in
147
- // the plan
148
- if (plan) {
149
- const re = (0, path_to_regexp_1.pathToRegexp)(`${route}`.replace(/\/+/g, '/'));
150
- app.use(re, (req, res) => {
151
- const reqUrl = new URL(req.url, 'https://placeholder.test/');
152
- const reqPath = (0, utils_js_1.validateUrlPath)(`${req.baseUrl}${reqUrl.pathname}${plan.getWaypoints()[0]}`);
153
- let reqParams = reqUrl.searchParams.toString();
154
- reqParams = reqParams ? `?${reqParams}` : '';
155
- res.redirect(302, `${reqPath}${reqParams}`);
156
- });
157
- }
158
- // Capture the mount path of this CASA app, before any parameterised path
159
- // segments exert influence over `req.baseUrl` in the `router` further below.
160
- // This can later be used by middleware that wants to use the
161
- // "unparameterised" version of the request's `baseUrl`, such as the static
162
- // router's middleware.
163
- app.use((req, res, next) => {
164
- req.unparameterisedBaseUrl = req.baseUrl;
165
- next();
166
- });
167
- // Serve static assets from the `app` rather than the `router`. The router
168
- // may contain paramaterised path segments which would mean serving static
169
- // assets over a dynamic URL each time, thus causing lots of cache misses on
170
- // the browser.
171
- const sealedStaticRouter = staticRouter.seal();
172
- app.use(preMiddleware);
173
- app.use(sealedStaticRouter);
174
- const router = (0, express_1.Router)({
175
- // Required so that any parameters in the URL are propagated to middleware
176
- mergeParams: true,
177
- });
178
- router.use(preMiddleware);
179
- // !!! DEPRECATE in v9 !!! For performance reasons, static assets will
180
- // always be handled via the `app` middleware rather than `router`.
181
- // Anywhere `mountUrl` is used in templates to service static assets must be
182
- // changed to use `staticMountUrl`.
183
- // TASK: remove this line below
184
- router.use(sealedStaticRouter);
185
- router.use(sessionMiddleware);
186
- router.use(i18nMiddleware);
187
- router.use(bodyParserMiddleware);
188
- router.use(dataMiddleware);
189
- router.use(ancillaryRouter.seal());
190
- router.use(journeyRouter.seal());
191
- router.use(postMiddleware);
192
- app.use(route, router);
193
- return app;
194
- };
125
+ // Create the mounting function
126
+ const mount = (0, mount_js_1.default)({
127
+ nunjucksEnv,
128
+ mountUrl,
129
+ plan,
130
+ staticRouter,
131
+ ancillaryRouter,
132
+ journeyRouter,
133
+ preMiddleware,
134
+ sessionMiddleware,
135
+ i18nMiddleware,
136
+ bodyParserMiddleware,
137
+ dataMiddleware,
138
+ postMiddleware,
139
+ });
195
140
  // Prepare configuration result
196
141
  const configOutput = {
197
142
  // Nunjucks environment, so it can be attached to other ExpressJS instances
@@ -0,0 +1,20 @@
1
+ declare function _default({ nunjucksEnv, mountUrl, plan, staticRouter, ancillaryRouter, journeyRouter, preMiddleware, sessionMiddleware, i18nMiddleware, bodyParserMiddleware, dataMiddleware, postMiddleware, }: {
2
+ nunjucksEnv: NunjucksEnvironment;
3
+ mountUrl?: string | undefined;
4
+ plan?: import("./Plan.js").default | undefined;
5
+ staticRouter: MutableRouter;
6
+ ancillaryRouter: MutableRouter;
7
+ journeyRouter: MutableRouter;
8
+ preMiddleware: ExpressRequestHandler[];
9
+ sessionMiddleware: ExpressRequestHandler[];
10
+ i18nMiddleware: ExpressRequestHandler[];
11
+ bodyParserMiddleware: ExpressRequestHandler[];
12
+ dataMiddleware: ExpressRequestHandler[];
13
+ postMiddleware: ExpressRequestHandler[];
14
+ }): Mounter;
15
+ export default _default;
16
+ export type NunjucksEnvironment = import('nunjucks').Environment;
17
+ export type ExpressRequestHandler = import('express').RequestHandler;
18
+ export type Mounter = import('../casa').Mounter;
19
+ export type Plan = import('../casa').Plan;
20
+ export type MutableRouter = import('../casa').MutableRouter;
@@ -0,0 +1,98 @@
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 express_1 = require("express");
7
+ const path_to_regexp_1 = require("path-to-regexp");
8
+ const strip_proxy_path_js_1 = __importDefault(require("../middleware/strip-proxy-path.js"));
9
+ const serve_first_waypoint_js_1 = __importDefault(require("../middleware/serve-first-waypoint.js"));
10
+ /**
11
+ * @access private
12
+ * @typedef {import('nunjucks').Environment} NunjucksEnvironment
13
+ */
14
+ /**
15
+ * @access private
16
+ * @typedef {import('express').RequestHandler} ExpressRequestHandler
17
+ */
18
+ /**
19
+ * @access private
20
+ * @typedef {import('../casa').Mounter} Mounter
21
+ */
22
+ /**
23
+ * @access private
24
+ * @typedef {import('../casa').Plan} Plan
25
+ */
26
+ /**
27
+ * @access private
28
+ * @typedef {import('../casa').MutableRouter} MutableRouter
29
+ */
30
+ /**
31
+ * Mounting function factory.
32
+ *
33
+ * @param {Object} args Arguments
34
+ * @param {NunjucksEnvironment} args.nunjucksEnv Pre-configured Nunmjucks environment
35
+ * @param {string} [args.mountUrl] Mount URL
36
+ * @param {Plan} [args.plan] CASA Plan
37
+ * @param {MutableRouter} args.staticRouter Router for all static assets
38
+ * @param {MutableRouter} args.ancillaryRouter Router for all ancillary routes
39
+ * @param {MutableRouter} args.journeyRouter Router for all waypoints
40
+ * @param {ExpressRequestHandler[]} args.preMiddleware Middleware
41
+ * @param {ExpressRequestHandler[]} args.sessionMiddleware Middleware
42
+ * @param {ExpressRequestHandler[]} args.i18nMiddleware Middleware
43
+ * @param {ExpressRequestHandler[]} args.bodyParserMiddleware Middleware
44
+ * @param {ExpressRequestHandler[]} args.dataMiddleware Middleware
45
+ * @param {ExpressRequestHandler[]} args.postMiddleware Middleware
46
+ * @returns {Mounter} mount
47
+ */
48
+ exports.default = ({ nunjucksEnv, mountUrl, plan, staticRouter, ancillaryRouter, journeyRouter, preMiddleware, sessionMiddleware, i18nMiddleware, bodyParserMiddleware, dataMiddleware, postMiddleware, }) => (app, { route = '/', serveFirstWaypoint = false, } = {}) => {
49
+ nunjucksEnv.express(app);
50
+ app.set('view engine', 'njk');
51
+ // If a `mountUrl` has been defined, then we're potentially in "proxy mode",
52
+ // in which we strip the proxy path prefix from the incoming request URLs.
53
+ if (mountUrl) {
54
+ app.use((0, strip_proxy_path_js_1.default)({ mountUrl }));
55
+ }
56
+ // Attach a handler to redirect requests for `/` to the first waypoint in
57
+ // the plan
58
+ if (serveFirstWaypoint && plan) {
59
+ const re = (0, path_to_regexp_1.pathToRegexp)(`${route}`.replace(/\/+/g, '/'));
60
+ app.use(re, (0, serve_first_waypoint_js_1.default)({ plan }));
61
+ }
62
+ // Capture the mount path of this CASA app, before any parameterised path
63
+ // segments exert influence over `req.baseUrl` in the `router` further below.
64
+ // This can later be used by middleware that wants to use the
65
+ // "unparameterised" version of the request's `baseUrl`, such as the static
66
+ // router's middleware.
67
+ app.use((req, res, next) => {
68
+ req.unparameterisedBaseUrl = req.baseUrl;
69
+ next();
70
+ });
71
+ // Serve static assets from the `app` rather than the `router`. The router
72
+ // may contain paramaterised path segments which would mean serving static
73
+ // assets over a dynamic URL each time, thus causing lots of cache misses on
74
+ // the browser.
75
+ const sealedStaticRouter = staticRouter.seal();
76
+ app.use(preMiddleware);
77
+ app.use(sealedStaticRouter);
78
+ const router = (0, express_1.Router)({
79
+ // Required so that any parameters in the URL are propagated to middleware
80
+ mergeParams: true,
81
+ });
82
+ router.use(preMiddleware);
83
+ // !!! DEPRECATE in v9 !!! For performance reasons, static assets will
84
+ // always be handled via the `app` middleware rather than `router`.
85
+ // Anywhere `mountUrl` is used in templates to service static assets must be
86
+ // changed to use `staticMountUrl`.
87
+ // TASK: remove this line below
88
+ router.use(sealedStaticRouter);
89
+ router.use(sessionMiddleware);
90
+ router.use(i18nMiddleware);
91
+ router.use(bodyParserMiddleware);
92
+ router.use(dataMiddleware);
93
+ router.use(ancillaryRouter.seal());
94
+ router.use(journeyRouter.seal());
95
+ router.use(postMiddleware);
96
+ app.use(route, router);
97
+ return app;
98
+ };
@@ -0,0 +1,4 @@
1
+ declare function _default({ plan, }: Plan): ExpressRequestHandler[];
2
+ export default _default;
3
+ export type ExpressRequestHandler = import('express').RequestHandler;
4
+ export type Plan = import('../casa').Plan;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_js_1 = require("../lib/utils.js");
4
+ /**
5
+ * @access private
6
+ * @typedef {import('express').RequestHandler} ExpressRequestHandler
7
+ */
8
+ /**
9
+ * @access private
10
+ * @typedef {import('../casa').Plan} Plan
11
+ */
12
+ /**
13
+ * Redirect the user to the first Plan waypoint when they request the root /
14
+ * path.
15
+ *
16
+ * @param {Plan} plan CASA Plan
17
+ * @returns {ExpressRequestHandler[]} Array of middleware
18
+ */
19
+ exports.default = ({ plan, }) => [(req, res) => {
20
+ const reqUrl = new URL(req.url, 'https://placeholder.test/');
21
+ const reqPath = (0, utils_js_1.validateUrlPath)(`${req.baseUrl}${reqUrl.pathname}${plan.getWaypoints()[0]}`);
22
+ let reqParams = reqUrl.searchParams.toString();
23
+ reqParams = reqParams ? `?${reqParams}` : '';
24
+ res.redirect(302, `${reqPath}${reqParams}`);
25
+ }];
@@ -2,7 +2,17 @@
2
2
  "rule": {
3
3
  "dateObject": {
4
4
  "inline": "Rhowch ddyddiad dilys",
5
- "summary": "Rhowch ddyddiad dilys"
5
+ "summary": "Rhowch ddyddiad dilys",
6
+
7
+ "afterOffset": {
8
+ "inline": "Rhowch ddyddiad o fewn yr ystod benodol",
9
+ "summary": "Rhowch ddyddiad o fewn yr ystod benodol"
10
+ },
11
+
12
+ "beforeOffset": {
13
+ "inline": "Rhowch ddyddiad o fewn yr ystod benodol",
14
+ "summary": "Rhowch ddyddiad o fewn yr ystod benodol"
15
+ }
6
16
  },
7
17
 
8
18
  "email": {
@@ -2,7 +2,17 @@
2
2
  "rule": {
3
3
  "dateObject": {
4
4
  "inline": "Enter a valid date",
5
- "summary": "Enter a valid date"
5
+ "summary": "Enter a valid date",
6
+
7
+ "afterOffset": {
8
+ "inline": "Enter a date within the given range",
9
+ "summary": "Enter a date within the given range"
10
+ },
11
+
12
+ "beforeOffset": {
13
+ "inline": "Enter a date within the given range",
14
+ "summary": "Enter a date within the given range"
15
+ }
6
16
  },
7
17
 
8
18
  "email": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwp/govuk-casa",
3
- "version": "8.2.5",
3
+ "version": "8.2.8",
4
4
  "description": "A framework for building GOVUK Collect-And-Submit-Applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -48,11 +48,11 @@
48
48
  "deepmerge": "4.2.2",
49
49
  "express": "4.18.1",
50
50
  "express-session": "1.17.3",
51
- "govuk-frontend": "4.0.1",
51
+ "govuk-frontend": "4.2.0",
52
52
  "graphlib": "2.1.8",
53
53
  "helmet": "5.1.0",
54
- "i18next": "21.8.4",
55
- "i18next-http-middleware": "3.2.0",
54
+ "i18next": "21.8.11",
55
+ "i18next-http-middleware": "3.2.1",
56
56
  "js-yaml": "4.1.0",
57
57
  "lodash": "4.17.21",
58
58
  "luxon": "2.4.0",
@@ -62,38 +62,38 @@
62
62
  "validator": "13.7.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@babel/core": "7.18.0",
66
- "@babel/eslint-parser": "7.17.0",
67
- "@babel/preset-env": "7.18.0",
68
- "@commitlint/config-conventional": "17.0.0",
69
- "@ckeditor/jsdoc-plugins": "30.1.0",
65
+ "@babel/core": "7.18.6",
66
+ "@babel/eslint-parser": "7.18.2",
67
+ "@babel/preset-env": "7.18.6",
68
+ "@ckeditor/jsdoc-plugins": "30.3.1",
69
+ "@commitlint/config-conventional": "17.0.3",
70
70
  "@dwp/casa-spiderplan": "2.4.0",
71
71
  "@dwp/casa-spiderplan-a11y-plugin": "0.1.4",
72
72
  "@dwp/casa-spiderplan-zap-plugin": "0.1.1",
73
73
  "@dwp/eslint-config-base": "6.0.0",
74
74
  "@types/express": "4.17.13",
75
- "@types/node": "17.0.35",
75
+ "@types/node": "18.0.0",
76
76
  "@types/nunjucks": "3.2.1",
77
77
  "babel-eslint": "10.1.0",
78
78
  "c8": "7.11.3",
79
79
  "chai": "4.3.6",
80
- "cheerio": "1.0.0-rc.11",
81
- "commitlint": "17.0.0",
82
- "eslint": "8.16.0",
80
+ "cheerio": "1.0.0-rc.12",
81
+ "commitlint": "17.0.3",
83
82
  "docdash": "1.2.0",
84
- "eslint-plugin-security": "1.5.0",
85
- "fast-check": "2.25.0",
86
- "husky": "8.0.1",
87
- "mocha": "10.0.0",
88
- "sass": "1.52.1",
83
+ "eslint": "8.18.0",
89
84
  "eslint-plugin-no-unsafe-regex": "1.0.0",
85
+ "eslint-plugin-security": "1.5.0",
90
86
  "eslint-plugin-sonarjs": "0.13.0",
87
+ "fast-check": "3.0.1",
88
+ "husky": "8.0.1",
91
89
  "jsdoc": "3.6.10",
92
90
  "jsdoc-tsimport-plugin": "1.0.5",
91
+ "mocha": "10.0.0",
92
+ "sass": "1.53.0",
93
93
  "sinon": "14.0.0",
94
94
  "sinon-chai": "3.7.0",
95
95
  "standard-version": "9.5.0",
96
96
  "supertest": "6.2.3",
97
- "typescript": "4.6.4"
97
+ "typescript": "4.7.4"
98
98
  }
99
99
  }