@dwp/govuk-casa 8.2.6 → 8.3.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/CHANGELOG.md +11 -0
- package/dist/assets/css/casa-ie8.css +1 -1
- package/dist/assets/css/casa.css +1 -1
- package/dist/casa.d.ts +9 -0
- package/dist/casa.js +8 -0
- package/dist/lib/configure.js +16 -71
- package/dist/lib/field.d.ts +11 -2
- package/dist/lib/field.js +48 -14
- package/dist/lib/mount.d.ts +20 -0
- package/dist/lib/mount.js +98 -0
- package/dist/middleware/serve-first-waypoint.d.ts +4 -0
- package/dist/middleware/serve-first-waypoint.js +25 -0
- package/locales/cy/validation.json +11 -1
- package/locales/en/validation.json +11 -1
- package/package.json +19 -19
package/dist/lib/configure.js
CHANGED
|
@@ -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"));
|
|
@@ -125,73 +122,21 @@ function configure(config = {}) {
|
|
|
125
122
|
plan,
|
|
126
123
|
csrfMiddleware,
|
|
127
124
|
});
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
package/dist/lib/field.d.ts
CHANGED
|
@@ -39,20 +39,29 @@ export class PageField {
|
|
|
39
39
|
*
|
|
40
40
|
* @param {object} obj Object from which to extract the value
|
|
41
41
|
* @returns {any} Value extracted from object
|
|
42
|
-
* @throws {Error} When run on a complex field (not yet supported)
|
|
43
42
|
*/
|
|
44
43
|
getValue(obj?: object): any;
|
|
45
44
|
/**
|
|
46
45
|
* Store this field's value in the given object, using its name as the key.
|
|
47
46
|
*
|
|
47
|
+
* For complex fields, the field object will be created if it does not yet
|
|
48
|
+
* exist, before then storing the property within that object.
|
|
49
|
+
*
|
|
48
50
|
* @param {object} obj Object from which to extract the value
|
|
49
51
|
* @param {any} value Value to be stored
|
|
50
52
|
* @returns {any} Value extracted from object
|
|
51
|
-
* @throws {Error} When run on a complex field (not yet supported)
|
|
52
53
|
*/
|
|
53
54
|
putValue(obj?: object, value?: any): any;
|
|
54
55
|
get name(): string;
|
|
55
56
|
get meta(): object;
|
|
57
|
+
/**
|
|
58
|
+
* Rename this field.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} name New name to be applied
|
|
61
|
+
* @returns {PageField} Chain
|
|
62
|
+
* @throws {SyntaxError} When the name is invalid in some way
|
|
63
|
+
*/
|
|
64
|
+
rename(name: string): PageField;
|
|
56
65
|
/**
|
|
57
66
|
* Add/get value validators
|
|
58
67
|
* Some validators will include a `sanitise()` method which will be run at the
|
package/dist/lib/field.js
CHANGED
|
@@ -45,7 +45,7 @@ const { isFunction } = lodash_1.default;
|
|
|
45
45
|
*/
|
|
46
46
|
// Quick check to see if the field name corresponds to a non-primitive complex
|
|
47
47
|
// type. For example, `my_field[nested]`.
|
|
48
|
-
const reComplexType =
|
|
48
|
+
const reComplexType = /^([^[]+)\[([^\]]+)\]/;
|
|
49
49
|
const reInvalidName = /[^a-z0-9_.\-[\]]/i;
|
|
50
50
|
/**
|
|
51
51
|
* This class is not exposed via the public API. Instances should instead be
|
|
@@ -86,18 +86,19 @@ class PageField {
|
|
|
86
86
|
if (!name) {
|
|
87
87
|
throw new SyntaxError('A name for this field is required, i.e. "field(\'myField\')".');
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
throw new SyntaxError(`Field '${String(name)}' name contains invalid characters.`);
|
|
91
|
-
}
|
|
92
|
-
__classPrivateFieldSet(this, _PageField_name, String(name), "f");
|
|
89
|
+
__classPrivateFieldSet(this, _PageField_name, undefined, "f");
|
|
93
90
|
__classPrivateFieldSet(this, _PageField_validators, [], "f");
|
|
94
91
|
__classPrivateFieldSet(this, _PageField_processors, [], "f");
|
|
95
92
|
__classPrivateFieldSet(this, _PageField_conditions, [], "f");
|
|
96
93
|
__classPrivateFieldSet(this, _PageField_meta, {
|
|
97
94
|
optional,
|
|
98
95
|
persist,
|
|
99
|
-
complex:
|
|
96
|
+
complex: undefined,
|
|
97
|
+
complexFieldName: undefined,
|
|
98
|
+
complexFieldProperty: undefined,
|
|
100
99
|
}, "f");
|
|
100
|
+
// Apply name
|
|
101
|
+
this.rename(name);
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
103
104
|
* Extract this field's value from the given object.
|
|
@@ -107,29 +108,35 @@ class PageField {
|
|
|
107
108
|
*
|
|
108
109
|
* @param {object} obj Object from which to extract the value
|
|
109
110
|
* @returns {any} Value extracted from object
|
|
110
|
-
* @throws {Error} When run on a complex field (not yet supported)
|
|
111
111
|
*/
|
|
112
112
|
getValue(obj = Object.create(null)) {
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
var _a;
|
|
114
|
+
if (__classPrivateFieldGet(this, _PageField_meta, "f").complex) {
|
|
115
|
+
return (_a = obj[__classPrivateFieldGet(this, _PageField_meta, "f").complexFieldName]) === null || _a === void 0 ? void 0 : _a[__classPrivateFieldGet(this, _PageField_meta, "f").complexFieldProperty];
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
+
return obj[__classPrivateFieldGet(this, _PageField_name, "f")];
|
|
117
118
|
}
|
|
118
119
|
/**
|
|
119
120
|
* Store this field's value in the given object, using its name as the key.
|
|
120
121
|
*
|
|
122
|
+
* For complex fields, the field object will be created if it does not yet
|
|
123
|
+
* exist, before then storing the property within that object.
|
|
124
|
+
*
|
|
121
125
|
* @param {object} obj Object from which to extract the value
|
|
122
126
|
* @param {any} value Value to be stored
|
|
123
127
|
* @returns {any} Value extracted from object
|
|
124
|
-
* @throws {Error} When run on a complex field (not yet supported)
|
|
125
128
|
*/
|
|
126
129
|
putValue(obj = Object.create(null), value = undefined) {
|
|
127
|
-
|
|
130
|
+
var _a;
|
|
131
|
+
if (__classPrivateFieldGet(this, _PageField_meta, "f").complex) {
|
|
132
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
133
|
+
obj[__classPrivateFieldGet(this, _PageField_meta, "f").complexFieldName] = Object.assign(Object.assign({}, ((_a = obj[__classPrivateFieldGet(this, _PageField_meta, "f").complexFieldName]) !== null && _a !== void 0 ? _a : {})), { [__classPrivateFieldGet(this, _PageField_meta, "f").complexFieldProperty]: value });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
128
136
|
/* eslint-disable-next-line no-param-reassign */
|
|
129
137
|
obj[__classPrivateFieldGet(this, _PageField_name, "f")] = value;
|
|
130
|
-
return this;
|
|
131
138
|
}
|
|
132
|
-
|
|
139
|
+
return this;
|
|
133
140
|
}
|
|
134
141
|
/* -------------------------------------------------------------- configure */
|
|
135
142
|
get name() {
|
|
@@ -138,6 +145,33 @@ class PageField {
|
|
|
138
145
|
get meta() {
|
|
139
146
|
return __classPrivateFieldGet(this, _PageField_meta, "f");
|
|
140
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Rename this field.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} name New name to be applied
|
|
152
|
+
* @returns {PageField} Chain
|
|
153
|
+
* @throws {SyntaxError} When the name is invalid in some way
|
|
154
|
+
*/
|
|
155
|
+
rename(name) {
|
|
156
|
+
if (reInvalidName.test(String(name))) {
|
|
157
|
+
throw new SyntaxError(`Field '${String(name)}' name contains invalid characters.`);
|
|
158
|
+
}
|
|
159
|
+
// Complex names are only supported to one level deep. For example,
|
|
160
|
+
// `field[prop]` is supported, whilst `field[prop][subprop]` is not. Throw
|
|
161
|
+
// early to aid developer.
|
|
162
|
+
const isComplex = reComplexType.test(name);
|
|
163
|
+
if (isComplex && name.match(/\[/g).length > 1) {
|
|
164
|
+
throw new SyntaxError('Complex field names are only supported to 1 property depth. E.g. a[b] is ok, a[b][c] is not');
|
|
165
|
+
}
|
|
166
|
+
__classPrivateFieldSet(this, _PageField_name, String(name), "f");
|
|
167
|
+
__classPrivateFieldGet(this, _PageField_meta, "f").complex = isComplex;
|
|
168
|
+
// Extract the field name and property from a complex type for later use
|
|
169
|
+
if (isComplex) {
|
|
170
|
+
const parts = name.match(reComplexType);
|
|
171
|
+
[, __classPrivateFieldGet(this, _PageField_meta, "f").complexFieldName, __classPrivateFieldGet(this, _PageField_meta, "f").complexFieldProperty] = parts;
|
|
172
|
+
}
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
141
175
|
/**
|
|
142
176
|
* Add/get value validators
|
|
143
177
|
* Some validators will include a `sanitise()` method which will be run at the
|
|
@@ -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,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.
|
|
3
|
+
"version": "8.3.0",
|
|
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
|
|
51
|
+
"govuk-frontend": "4.2.0",
|
|
52
52
|
"graphlib": "2.1.8",
|
|
53
53
|
"helmet": "5.1.0",
|
|
54
|
-
"i18next": "21.8.
|
|
55
|
-
"i18next-http-middleware": "3.2.
|
|
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.
|
|
66
|
-
"@babel/eslint-parser": "7.
|
|
67
|
-
"@babel/preset-env": "7.18.
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
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": "
|
|
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.
|
|
81
|
-
"commitlint": "17.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
|
|
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.
|
|
97
|
+
"typescript": "4.7.4"
|
|
98
98
|
}
|
|
99
99
|
}
|