@dwp/govuk-casa 8.5.1 → 8.6.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 +9 -0
- package/dist/casa.d.ts +23 -4
- package/dist/casa.js +13 -9
- package/dist/lib/JourneyContext.d.ts +4 -4
- package/dist/lib/JourneyContext.js +1 -1
- package/dist/lib/MutableRouter.d.ts +57 -54
- package/dist/lib/MutableRouter.js +43 -38
- package/dist/lib/ValidatorFactory.d.ts +5 -6
- package/dist/lib/ValidatorFactory.js +1 -1
- package/dist/lib/field.d.ts +36 -11
- package/dist/lib/field.js +51 -16
- package/dist/lib/waypoint-url.d.ts +0 -1
- package/dist/lib/waypoint-url.js +0 -1
- package/dist/middleware/pre.js +19 -4
- package/locales/cy/common.json +1 -1
- package/locales/cy/macros.json +1 -1
- package/locales/cy/review.json +1 -1
- package/locales/cy/validation.json +1 -1
- package/locales/en/common.json +1 -1
- package/locales/en/review.json +1 -1
- package/package.json +18 -19
- package/views/casa/components/date-input/README.md +1 -1
- package/views/casa/layouts/journey.njk +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [8.6.0](https://github.com/dwp/govuk-casa/compare/8.5.2...8.6.0) (2022-11-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **better-typescript-support:** fixes and additions to types ([8dda905](https://github.com/dwp/govuk-casa/commit/8dda9050b53ee8a5f53c8f7c1cb4afa91df2e674))
|
|
11
|
+
|
|
12
|
+
### [8.5.2](https://github.com/dwp/govuk-casa/compare/8.5.1...8.5.2) (2022-10-31)
|
|
13
|
+
|
|
5
14
|
### [8.5.1](https://github.com/dwp/govuk-casa/compare/8.5.0...8.5.1) (2022-10-13)
|
|
6
15
|
|
|
7
16
|
## [8.5.0](https://github.com/dwp/govuk-casa/compare/8.4.0...8.5.0) (2022-09-22)
|
package/dist/casa.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
export type PageField = import('./lib/field').PageField;
|
|
2
|
-
export type
|
|
2
|
+
export type ContextEventHandlerOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Context including changes
|
|
5
|
+
*/
|
|
6
|
+
journeyContext: JourneyContext;
|
|
7
|
+
/**
|
|
8
|
+
* Context prior to changes
|
|
9
|
+
*/
|
|
10
|
+
previousContext: JourneyContext;
|
|
11
|
+
/**
|
|
12
|
+
* Request session object
|
|
13
|
+
*/
|
|
14
|
+
session: object;
|
|
15
|
+
};
|
|
16
|
+
export type ContextEventHandler = (opts: ContextEventHandlerOptions) => void;
|
|
3
17
|
export type ContextEvent = {
|
|
4
18
|
/**
|
|
5
19
|
* Waypoint to watch for changes
|
|
@@ -100,6 +114,11 @@ export type SessionOptions = {
|
|
|
100
114
|
* Session store (default MemoryStore)
|
|
101
115
|
*/
|
|
102
116
|
store?: object | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* the URL path on which the session cookie
|
|
119
|
+
* is valid (defaults to '/')
|
|
120
|
+
*/
|
|
121
|
+
cookiePath?: string | undefined;
|
|
103
122
|
};
|
|
104
123
|
/**
|
|
105
124
|
* Plugin interface
|
|
@@ -127,7 +146,6 @@ export type HelmetConfigurator = (config: object) => object;
|
|
|
127
146
|
* they will be "sealed".
|
|
128
147
|
*/
|
|
129
148
|
export type Mounter = (app: import('express').Express, opts: object, route?: string | undefined) => import('express').Express;
|
|
130
|
-
export type MutableRouter = import('./lib/index').MutableRouter;
|
|
131
149
|
/**
|
|
132
150
|
* Configuration options
|
|
133
151
|
*/
|
|
@@ -159,7 +177,7 @@ export type ConfigurationOptions = {
|
|
|
159
177
|
/**
|
|
160
178
|
* I18n configuration
|
|
161
179
|
*/
|
|
162
|
-
i18n?: I18nOptions
|
|
180
|
+
i18n?: I18nOptions | undefined;
|
|
163
181
|
/**
|
|
164
182
|
* CASA Plan
|
|
165
183
|
*/
|
|
@@ -435,7 +453,8 @@ import Plan from "./lib/Plan.js";
|
|
|
435
453
|
import JourneyContext from "./lib/JourneyContext.js";
|
|
436
454
|
import ValidatorFactory from "./lib/ValidatorFactory.js";
|
|
437
455
|
import ValidationError from "./lib/ValidationError.js";
|
|
456
|
+
import MutableRouter from "./lib/MutableRouter.js";
|
|
438
457
|
import waypointUrl from "./lib/waypoint-url.js";
|
|
439
458
|
import endSession from "./lib/end-session.js";
|
|
440
459
|
import * as nunjucksFilters from "./lib/nunjucks-filters.js";
|
|
441
|
-
export { configure, validators, field, Plan, JourneyContext, ValidatorFactory, ValidationError, waypointUrl, endSession, nunjucksFilters };
|
|
460
|
+
export { configure, validators, field, Plan, JourneyContext, ValidatorFactory, ValidationError, MutableRouter, waypointUrl, endSession, nunjucksFilters };
|
package/dist/casa.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.nunjucksFilters = exports.endSession = exports.waypointUrl = exports.ValidationError = exports.ValidatorFactory = exports.JourneyContext = exports.Plan = exports.field = exports.validators = exports.configure = void 0;
|
|
29
|
+
exports.nunjucksFilters = exports.endSession = exports.waypointUrl = exports.MutableRouter = exports.ValidationError = exports.ValidatorFactory = exports.JourneyContext = exports.Plan = exports.field = exports.validators = exports.configure = void 0;
|
|
30
30
|
// NOTE: Any changes made here must be reflected in `scripts/esm-wrapper.js`
|
|
31
31
|
const configure_js_1 = __importDefault(require("./lib/configure.js"));
|
|
32
32
|
exports.configure = configure_js_1.default;
|
|
@@ -42,6 +42,8 @@ const ValidatorFactory_js_1 = __importDefault(require("./lib/ValidatorFactory.js
|
|
|
42
42
|
exports.ValidatorFactory = ValidatorFactory_js_1.default;
|
|
43
43
|
const ValidationError_js_1 = __importDefault(require("./lib/ValidationError.js"));
|
|
44
44
|
exports.ValidationError = ValidationError_js_1.default;
|
|
45
|
+
const MutableRouter_js_1 = __importDefault(require("./lib/MutableRouter.js"));
|
|
46
|
+
exports.MutableRouter = MutableRouter_js_1.default;
|
|
45
47
|
const waypoint_url_js_1 = __importDefault(require("./lib/waypoint-url.js"));
|
|
46
48
|
exports.waypointUrl = waypoint_url_js_1.default;
|
|
47
49
|
const end_session_js_1 = __importDefault(require("./lib/end-session.js"));
|
|
@@ -53,12 +55,15 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
53
55
|
/**
|
|
54
56
|
* @typedef {import('./lib/field').PageField} PageField
|
|
55
57
|
*/
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {object} ContextEventHandlerOptions
|
|
60
|
+
* @property {JourneyContext} journeyContext Context including changes
|
|
61
|
+
* @property {JourneyContext} previousContext Context prior to changes
|
|
62
|
+
* @property {object} session Request session object
|
|
63
|
+
*/
|
|
56
64
|
/**
|
|
57
65
|
* @callback ContextEventHandler
|
|
58
|
-
* @param {
|
|
59
|
-
* @param {JourneyContext} opts.journeyContext Context including changes
|
|
60
|
-
* @param {JourneyContext} opts.previousContext Context prior to changes
|
|
61
|
-
* @param {object} opts.session Request session object
|
|
66
|
+
* @param {ContextEventHandlerOptions} opts Options
|
|
62
67
|
* @returns {void}
|
|
63
68
|
*/
|
|
64
69
|
/**
|
|
@@ -98,6 +103,8 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
98
103
|
* @property {boolean} [secure=false] Whether to use secure session cookies
|
|
99
104
|
* @property {boolean|string} [cookieSameSite=true] SameSite (true = Strict)
|
|
100
105
|
* @property {object} [store] Session store (default MemoryStore)
|
|
106
|
+
* @property {string} [cookiePath] the URL path on which the session cookie
|
|
107
|
+
* is valid (defaults to '/')
|
|
101
108
|
*/
|
|
102
109
|
/**
|
|
103
110
|
* @typedef {object} IPlugin Plugin interface
|
|
@@ -132,9 +139,6 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
132
139
|
* @param {string} [opts.route='/'] Optional route to attach all middleware/routers too
|
|
133
140
|
* @returns {import('express').Express} The prepared ExpressJS app instance
|
|
134
141
|
*/
|
|
135
|
-
/**
|
|
136
|
-
* @typedef {import('./lib/index').MutableRouter} MutableRouter
|
|
137
|
-
*/
|
|
138
142
|
/**
|
|
139
143
|
* Configure some middleware for use in creating a new CASA app.
|
|
140
144
|
*
|
|
@@ -145,7 +149,7 @@ exports.nunjucksFilters = nunjucksFilters;
|
|
|
145
149
|
* @property {Page[]} [pages=[]] Pages the represent waypoints
|
|
146
150
|
* @property {GlobalHook[]} [hooks=[]] Hooks to apply
|
|
147
151
|
* @property {IPlugin[]} [plugins=[]] Plugins
|
|
148
|
-
* @property {I18nOptions
|
|
152
|
+
* @property {I18nOptions} [i18n] I18n configuration
|
|
149
153
|
* @property {Plan} [plan] CASA Plan
|
|
150
154
|
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events
|
|
151
155
|
* @property {HelmetConfigurator} [helmetConfigurator] Helmet configuration manipulator function
|
|
@@ -184,20 +184,20 @@ export default class JourneyContext {
|
|
|
184
184
|
* `identity` holds information that helps uniquely identify this context
|
|
185
185
|
* among a group of contexts stored in the session.
|
|
186
186
|
*
|
|
187
|
-
* @param {
|
|
187
|
+
* @param {Record<string,unknown>} data Entire journey data.
|
|
188
188
|
* @param {object} validation Page errors (indexed by waypoint id).
|
|
189
189
|
* @param {object} nav Navigation context.
|
|
190
190
|
* @param {object} identity Some metadata for identifying this context among others.
|
|
191
191
|
*/
|
|
192
|
-
constructor(data?:
|
|
192
|
+
constructor(data?: Record<string, unknown>, validation?: object, nav?: object, identity?: object);
|
|
193
193
|
/**
|
|
194
194
|
* Clone into an object that can be stringified.
|
|
195
195
|
*
|
|
196
196
|
* @returns {object} Plain object.
|
|
197
197
|
*/
|
|
198
198
|
toObject(): object;
|
|
199
|
-
set data(arg:
|
|
200
|
-
get data():
|
|
199
|
+
set data(arg: Record<string, unknown>);
|
|
200
|
+
get data(): Record<string, unknown>;
|
|
201
201
|
get validation(): object;
|
|
202
202
|
get nav(): object;
|
|
203
203
|
get identity(): object;
|
|
@@ -88,7 +88,7 @@ class JourneyContext {
|
|
|
88
88
|
* `identity` holds information that helps uniquely identify this context
|
|
89
89
|
* among a group of contexts stored in the session.
|
|
90
90
|
*
|
|
91
|
-
* @param {
|
|
91
|
+
* @param {Record<string,unknown>} data Entire journey data.
|
|
92
92
|
* @param {object} validation Page errors (indexed by waypoint id).
|
|
93
93
|
* @param {object} nav Navigation context.
|
|
94
94
|
* @param {object} identity Some metadata for identifying this context among others.
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @memberof module:@dwp/govuk-casa
|
|
3
|
+
*/
|
|
1
4
|
export default class MutableRouter {
|
|
2
5
|
/**
|
|
3
6
|
* Seals this router to make it immutable. Returns the ExpressJS router.
|
|
@@ -8,147 +11,147 @@ export default class MutableRouter {
|
|
|
8
11
|
/**
|
|
9
12
|
* Prepend middleware function(s) using the `all()` method.
|
|
10
13
|
*
|
|
11
|
-
* @param {string} path route path
|
|
12
|
-
* @param {...Function} callbacks
|
|
14
|
+
* @param {string | Function} path route path or middleware function
|
|
15
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
13
16
|
* @returns {void}
|
|
14
17
|
*/
|
|
15
|
-
prependAll(path: string, ...callbacks: Function[]): void;
|
|
18
|
+
prependAll(path: string | Function, ...callbacks: Function[]): void;
|
|
16
19
|
/**
|
|
17
20
|
* Prepend middleware function(s) using the `get()` method.
|
|
18
21
|
*
|
|
19
|
-
* @param {string} path route path
|
|
20
|
-
* @param {...Function} callbacks
|
|
22
|
+
* @param {string | Function} path route path or middleware function
|
|
23
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
21
24
|
* @returns {void}
|
|
22
25
|
*/
|
|
23
|
-
prependGet(path: string, ...callbacks: Function[]): void;
|
|
26
|
+
prependGet(path: string | Function, ...callbacks: Function[]): void;
|
|
24
27
|
/**
|
|
25
28
|
* Prepend middleware function(s) using the `post()` method.
|
|
26
29
|
*
|
|
27
|
-
* @param {string} path route path
|
|
28
|
-
* @param {...Function} callbacks
|
|
30
|
+
* @param {string | Function} path route path or middleware function
|
|
31
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
29
32
|
* @returns {void}
|
|
30
33
|
*/
|
|
31
|
-
prependPost(path: string, ...callbacks: Function[]): void;
|
|
34
|
+
prependPost(path: string | Function, ...callbacks: Function[]): void;
|
|
32
35
|
/**
|
|
33
36
|
* Prepend middleware function(s) using the `delete()` method.
|
|
34
37
|
*
|
|
35
|
-
* @param {string} path route path
|
|
36
|
-
* @param {...Function} callbacks
|
|
38
|
+
* @param {string | Function} path route path or middleware function
|
|
39
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
37
40
|
* @returns {void}
|
|
38
41
|
*/
|
|
39
|
-
prependDelete(path: string, ...callbacks: Function[]): void;
|
|
42
|
+
prependDelete(path: string | Function, ...callbacks: Function[]): void;
|
|
40
43
|
/**
|
|
41
44
|
* Prepend middleware function(s) using the `put()` method.
|
|
42
45
|
*
|
|
43
|
-
* @param {string} path route path
|
|
44
|
-
* @param {...Function} callbacks
|
|
46
|
+
* @param {string | Function} path route path or middleware function
|
|
47
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
45
48
|
* @returns {void}
|
|
46
49
|
*/
|
|
47
|
-
prependPut(path: string, ...callbacks: Function[]): void;
|
|
50
|
+
prependPut(path: string | Function, ...callbacks: Function[]): void;
|
|
48
51
|
/**
|
|
49
52
|
* Prepend middleware function(s) using the `use()` method.
|
|
50
53
|
*
|
|
51
|
-
* @param {string} path route path
|
|
52
|
-
* @param {...Function} callbacks
|
|
54
|
+
* @param {string | Function} path route path or middleware function
|
|
55
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
53
56
|
* @returns {void}
|
|
54
57
|
*/
|
|
55
|
-
prependUse(path: string, ...callbacks: Function[]): void;
|
|
58
|
+
prependUse(path: string | Function, ...callbacks: Function[]): void;
|
|
56
59
|
/**
|
|
57
60
|
* Replace middleware function(s) that were mounted using the `all()` method.
|
|
58
61
|
*
|
|
59
|
-
* @param {string} path route path
|
|
60
|
-
* @param {...Function} callbacks
|
|
62
|
+
* @param {string | Function} path route path or middleware function
|
|
63
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
61
64
|
* @returns {void}
|
|
62
65
|
*/
|
|
63
|
-
replaceAll(path: string, ...callbacks: Function[]): void;
|
|
66
|
+
replaceAll(path: string | Function, ...callbacks: Function[]): void;
|
|
64
67
|
/**
|
|
65
68
|
* Replace middleware function(s) that were mounted using the `get()` method.
|
|
66
69
|
*
|
|
67
|
-
* @param {string} path route path
|
|
68
|
-
* @param {...Function} callbacks
|
|
70
|
+
* @param {string | Function} path route path or middleware function
|
|
71
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
69
72
|
* @returns {void}
|
|
70
73
|
*/
|
|
71
|
-
replaceGet(path: string, ...callbacks: Function[]): void;
|
|
74
|
+
replaceGet(path: string | Function, ...callbacks: Function[]): void;
|
|
72
75
|
/**
|
|
73
76
|
* Replace middleware function(s) that were mounted using the `post()` method.
|
|
74
77
|
*
|
|
75
|
-
* @param {string} path route path
|
|
76
|
-
* @param {...Function} callbacks
|
|
78
|
+
* @param {string | Function} path route path or middleware function
|
|
79
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
77
80
|
* @returns {void}
|
|
78
81
|
*/
|
|
79
|
-
replacePost(path: string, ...callbacks: Function[]): void;
|
|
82
|
+
replacePost(path: string | Function, ...callbacks: Function[]): void;
|
|
80
83
|
/**
|
|
81
84
|
* Replace middleware function(s) that were mounted using the `delete()` method.
|
|
82
85
|
*
|
|
83
|
-
* @param {string} path route path
|
|
84
|
-
* @param {...Function} callbacks
|
|
86
|
+
* @param {string | Function} path route path or middleware function
|
|
87
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
85
88
|
* @returns {void}
|
|
86
89
|
*/
|
|
87
|
-
replaceDelete(path: string, ...callbacks: Function[]): void;
|
|
90
|
+
replaceDelete(path: string | Function, ...callbacks: Function[]): void;
|
|
88
91
|
/**
|
|
89
92
|
* Replace middleware function(s) that were mounted using the `put()` method.
|
|
90
93
|
*
|
|
91
|
-
* @param {string} path route path
|
|
92
|
-
* @param {...Function} callbacks
|
|
94
|
+
* @param {string | Function} path route path or middleware function
|
|
95
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
93
96
|
* @returns {void}
|
|
94
97
|
*/
|
|
95
|
-
replacePut(path: string, ...callbacks: Function[]): void;
|
|
98
|
+
replacePut(path: string | Function, ...callbacks: Function[]): void;
|
|
96
99
|
/**
|
|
97
100
|
* Replace middleware function(s) that were mounted using the `use()` method.
|
|
98
101
|
*
|
|
99
|
-
* @param {string} path route path
|
|
100
|
-
* @param {...Function} callbacks
|
|
102
|
+
* @param {string | Function} path route path or middleware function
|
|
103
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
101
104
|
* @returns {void}
|
|
102
105
|
*/
|
|
103
|
-
replaceUse(path: string, ...callbacks: Function[]): void;
|
|
106
|
+
replaceUse(path: string | Function, ...callbacks: Function[]): void;
|
|
104
107
|
/**
|
|
105
108
|
* Append middleware function(s) using the `all()` method.
|
|
106
109
|
*
|
|
107
|
-
* @param {string} path route path
|
|
108
|
-
* @param {...Function} callbacks
|
|
110
|
+
* @param {string | Function} path route path or middleware function
|
|
111
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
109
112
|
* @returns {void}
|
|
110
113
|
*/
|
|
111
|
-
all(path: string, ...callbacks: Function[]): void;
|
|
114
|
+
all(path: string | Function, ...callbacks: Function[]): void;
|
|
112
115
|
/**
|
|
113
116
|
* Append middleware function(s) using the `get()` method.
|
|
114
117
|
*
|
|
115
|
-
* @param {string} path route path
|
|
116
|
-
* @param {...Function} callbacks
|
|
118
|
+
* @param {string | Function} path route path or middleware function
|
|
119
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
117
120
|
* @returns {void}
|
|
118
121
|
*/
|
|
119
|
-
get(path: string, ...callbacks: Function[]): void;
|
|
122
|
+
get(path: string | Function, ...callbacks: Function[]): void;
|
|
120
123
|
/**
|
|
121
124
|
* Append middleware function(s) using the `post()` method.
|
|
122
125
|
*
|
|
123
|
-
* @param {string} path route path
|
|
124
|
-
* @param {...Function} callbacks
|
|
126
|
+
* @param {string | Function} path route path or middleware function
|
|
127
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
125
128
|
* @returns {void}
|
|
126
129
|
*/
|
|
127
|
-
post(path: string, ...callbacks: Function[]): void;
|
|
130
|
+
post(path: string | Function, ...callbacks: Function[]): void;
|
|
128
131
|
/**
|
|
129
132
|
* Append middleware function(s) using the `delete()` method.
|
|
130
133
|
*
|
|
131
|
-
* @param {string} path route path
|
|
132
|
-
* @param {...Function} callbacks
|
|
134
|
+
* @param {string | Function} path route path or middleware function
|
|
135
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
133
136
|
* @returns {void}
|
|
134
137
|
*/
|
|
135
|
-
delete(path: string, ...callbacks: Function[]): void;
|
|
138
|
+
delete(path: string | Function, ...callbacks: Function[]): void;
|
|
136
139
|
/**
|
|
137
140
|
* Append middleware function(s) using the `put()` method.
|
|
138
141
|
*
|
|
139
|
-
* @param {string} path route path
|
|
140
|
-
* @param {...Function} callbacks
|
|
142
|
+
* @param {string | Function} path route path or middleware function
|
|
143
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
141
144
|
* @returns {void}
|
|
142
145
|
*/
|
|
143
|
-
put(path: string, ...callbacks: Function[]): void;
|
|
146
|
+
put(path: string | Function, ...callbacks: Function[]): void;
|
|
144
147
|
/**
|
|
145
148
|
* Append middleware function(s) using the `use()` method.
|
|
146
149
|
*
|
|
147
|
-
* @param {string} path route path
|
|
148
|
-
* @param {...Function} callbacks
|
|
150
|
+
* @param {string | Function} path route path or middleware function
|
|
151
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
149
152
|
* @returns {void}
|
|
150
153
|
*/
|
|
151
|
-
use(path: string, ...callbacks: Function[]): void;
|
|
154
|
+
use(path: string | Function, ...callbacks: Function[]): void;
|
|
152
155
|
route(): void;
|
|
153
156
|
#private;
|
|
154
157
|
}
|
|
@@ -14,9 +14,14 @@ var _MutableRouter_instances, _MutableRouter_stack, _MutableRouter_router, _Muta
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
/* eslint-disable sonarjs/no-duplicate-string,class-methods-use-this */
|
|
16
16
|
const express_1 = require("express");
|
|
17
|
+
/**
|
|
18
|
+
* @memberof module:@dwp/govuk-casa
|
|
19
|
+
*/
|
|
17
20
|
class MutableRouter {
|
|
18
21
|
/**
|
|
19
|
-
*
|
|
22
|
+
* A wrapping class to make Express routers mutable. You can append, prepend
|
|
23
|
+
* and remove routes from a MutableRouter before finally "sealing" it and
|
|
24
|
+
* mounting it on your Express app.
|
|
20
25
|
*
|
|
21
26
|
* @class
|
|
22
27
|
*/
|
|
@@ -34,7 +39,7 @@ class MutableRouter {
|
|
|
34
39
|
* @type {boolean}
|
|
35
40
|
*/
|
|
36
41
|
_MutableRouter_sealed.set(this, void 0);
|
|
37
|
-
__classPrivateFieldSet(this, _MutableRouter_router,
|
|
42
|
+
__classPrivateFieldSet(this, _MutableRouter_router, (0, express_1.Router)(), "f");
|
|
38
43
|
__classPrivateFieldSet(this, _MutableRouter_stack, [], "f");
|
|
39
44
|
__classPrivateFieldSet(this, _MutableRouter_sealed, false, "f");
|
|
40
45
|
}
|
|
@@ -60,8 +65,8 @@ class MutableRouter {
|
|
|
60
65
|
/**
|
|
61
66
|
* Prepend middleware function(s) using the `all()` method.
|
|
62
67
|
*
|
|
63
|
-
* @param {string} path route path
|
|
64
|
-
* @param {...Function} callbacks
|
|
68
|
+
* @param {string | Function} path route path or middleware function
|
|
69
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
65
70
|
* @returns {void}
|
|
66
71
|
*/
|
|
67
72
|
prependAll(path, ...callbacks) {
|
|
@@ -70,8 +75,8 @@ class MutableRouter {
|
|
|
70
75
|
/**
|
|
71
76
|
* Prepend middleware function(s) using the `get()` method.
|
|
72
77
|
*
|
|
73
|
-
* @param {string} path route path
|
|
74
|
-
* @param {...Function} callbacks
|
|
78
|
+
* @param {string | Function} path route path or middleware function
|
|
79
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
75
80
|
* @returns {void}
|
|
76
81
|
*/
|
|
77
82
|
prependGet(path, ...callbacks) {
|
|
@@ -80,8 +85,8 @@ class MutableRouter {
|
|
|
80
85
|
/**
|
|
81
86
|
* Prepend middleware function(s) using the `post()` method.
|
|
82
87
|
*
|
|
83
|
-
* @param {string} path route path
|
|
84
|
-
* @param {...Function} callbacks
|
|
88
|
+
* @param {string | Function} path route path or middleware function
|
|
89
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
85
90
|
* @returns {void}
|
|
86
91
|
*/
|
|
87
92
|
prependPost(path, ...callbacks) {
|
|
@@ -90,8 +95,8 @@ class MutableRouter {
|
|
|
90
95
|
/**
|
|
91
96
|
* Prepend middleware function(s) using the `delete()` method.
|
|
92
97
|
*
|
|
93
|
-
* @param {string} path route path
|
|
94
|
-
* @param {...Function} callbacks
|
|
98
|
+
* @param {string | Function} path route path or middleware function
|
|
99
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
95
100
|
* @returns {void}
|
|
96
101
|
*/
|
|
97
102
|
prependDelete(path, ...callbacks) {
|
|
@@ -100,8 +105,8 @@ class MutableRouter {
|
|
|
100
105
|
/**
|
|
101
106
|
* Prepend middleware function(s) using the `put()` method.
|
|
102
107
|
*
|
|
103
|
-
* @param {string} path route path
|
|
104
|
-
* @param {...Function} callbacks
|
|
108
|
+
* @param {string | Function} path route path or middleware function
|
|
109
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
105
110
|
* @returns {void}
|
|
106
111
|
*/
|
|
107
112
|
prependPut(path, ...callbacks) {
|
|
@@ -110,8 +115,8 @@ class MutableRouter {
|
|
|
110
115
|
/**
|
|
111
116
|
* Prepend middleware function(s) using the `use()` method.
|
|
112
117
|
*
|
|
113
|
-
* @param {string} path route path
|
|
114
|
-
* @param {...Function} callbacks
|
|
118
|
+
* @param {string | Function} path route path or middleware function
|
|
119
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
115
120
|
* @returns {void}
|
|
116
121
|
*/
|
|
117
122
|
prependUse(path, ...callbacks) {
|
|
@@ -121,8 +126,8 @@ class MutableRouter {
|
|
|
121
126
|
/**
|
|
122
127
|
* Replace middleware function(s) that were mounted using the `all()` method.
|
|
123
128
|
*
|
|
124
|
-
* @param {string} path route path
|
|
125
|
-
* @param {...Function} callbacks
|
|
129
|
+
* @param {string | Function} path route path or middleware function
|
|
130
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
126
131
|
* @returns {void}
|
|
127
132
|
*/
|
|
128
133
|
replaceAll(path, ...callbacks) {
|
|
@@ -131,8 +136,8 @@ class MutableRouter {
|
|
|
131
136
|
/**
|
|
132
137
|
* Replace middleware function(s) that were mounted using the `get()` method.
|
|
133
138
|
*
|
|
134
|
-
* @param {string} path route path
|
|
135
|
-
* @param {...Function} callbacks
|
|
139
|
+
* @param {string | Function} path route path or middleware function
|
|
140
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
136
141
|
* @returns {void}
|
|
137
142
|
*/
|
|
138
143
|
replaceGet(path, ...callbacks) {
|
|
@@ -141,8 +146,8 @@ class MutableRouter {
|
|
|
141
146
|
/**
|
|
142
147
|
* Replace middleware function(s) that were mounted using the `post()` method.
|
|
143
148
|
*
|
|
144
|
-
* @param {string} path route path
|
|
145
|
-
* @param {...Function} callbacks
|
|
149
|
+
* @param {string | Function} path route path or middleware function
|
|
150
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
146
151
|
* @returns {void}
|
|
147
152
|
*/
|
|
148
153
|
replacePost(path, ...callbacks) {
|
|
@@ -151,8 +156,8 @@ class MutableRouter {
|
|
|
151
156
|
/**
|
|
152
157
|
* Replace middleware function(s) that were mounted using the `delete()` method.
|
|
153
158
|
*
|
|
154
|
-
* @param {string} path route path
|
|
155
|
-
* @param {...Function} callbacks
|
|
159
|
+
* @param {string | Function} path route path or middleware function
|
|
160
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
156
161
|
* @returns {void}
|
|
157
162
|
*/
|
|
158
163
|
replaceDelete(path, ...callbacks) {
|
|
@@ -161,8 +166,8 @@ class MutableRouter {
|
|
|
161
166
|
/**
|
|
162
167
|
* Replace middleware function(s) that were mounted using the `put()` method.
|
|
163
168
|
*
|
|
164
|
-
* @param {string} path route path
|
|
165
|
-
* @param {...Function} callbacks
|
|
169
|
+
* @param {string | Function} path route path or middleware function
|
|
170
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
166
171
|
* @returns {void}
|
|
167
172
|
*/
|
|
168
173
|
replacePut(path, ...callbacks) {
|
|
@@ -171,8 +176,8 @@ class MutableRouter {
|
|
|
171
176
|
/**
|
|
172
177
|
* Replace middleware function(s) that were mounted using the `use()` method.
|
|
173
178
|
*
|
|
174
|
-
* @param {string} path route path
|
|
175
|
-
* @param {...Function} callbacks
|
|
179
|
+
* @param {string | Function} path route path or middleware function
|
|
180
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
176
181
|
* @returns {void}
|
|
177
182
|
*/
|
|
178
183
|
replaceUse(path, ...callbacks) {
|
|
@@ -182,8 +187,8 @@ class MutableRouter {
|
|
|
182
187
|
/**
|
|
183
188
|
* Append middleware function(s) using the `all()` method.
|
|
184
189
|
*
|
|
185
|
-
* @param {string} path route path
|
|
186
|
-
* @param {...Function} callbacks
|
|
190
|
+
* @param {string | Function} path route path or middleware function
|
|
191
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
187
192
|
* @returns {void}
|
|
188
193
|
*/
|
|
189
194
|
all(path, ...callbacks) {
|
|
@@ -192,8 +197,8 @@ class MutableRouter {
|
|
|
192
197
|
/**
|
|
193
198
|
* Append middleware function(s) using the `get()` method.
|
|
194
199
|
*
|
|
195
|
-
* @param {string} path route path
|
|
196
|
-
* @param {...Function} callbacks
|
|
200
|
+
* @param {string | Function} path route path or middleware function
|
|
201
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
197
202
|
* @returns {void}
|
|
198
203
|
*/
|
|
199
204
|
get(path, ...callbacks) {
|
|
@@ -202,8 +207,8 @@ class MutableRouter {
|
|
|
202
207
|
/**
|
|
203
208
|
* Append middleware function(s) using the `post()` method.
|
|
204
209
|
*
|
|
205
|
-
* @param {string} path route path
|
|
206
|
-
* @param {...Function} callbacks
|
|
210
|
+
* @param {string | Function} path route path or middleware function
|
|
211
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
207
212
|
* @returns {void}
|
|
208
213
|
*/
|
|
209
214
|
post(path, ...callbacks) {
|
|
@@ -212,8 +217,8 @@ class MutableRouter {
|
|
|
212
217
|
/**
|
|
213
218
|
* Append middleware function(s) using the `delete()` method.
|
|
214
219
|
*
|
|
215
|
-
* @param {string} path route path
|
|
216
|
-
* @param {...Function} callbacks
|
|
220
|
+
* @param {string | Function} path route path or middleware function
|
|
221
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
217
222
|
* @returns {void}
|
|
218
223
|
*/
|
|
219
224
|
delete(path, ...callbacks) {
|
|
@@ -222,8 +227,8 @@ class MutableRouter {
|
|
|
222
227
|
/**
|
|
223
228
|
* Append middleware function(s) using the `put()` method.
|
|
224
229
|
*
|
|
225
|
-
* @param {string} path route path
|
|
226
|
-
* @param {...Function} callbacks
|
|
230
|
+
* @param {string | Function} path route path or middleware function
|
|
231
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
227
232
|
* @returns {void}
|
|
228
233
|
*/
|
|
229
234
|
put(path, ...callbacks) {
|
|
@@ -232,8 +237,8 @@ class MutableRouter {
|
|
|
232
237
|
/**
|
|
233
238
|
* Append middleware function(s) using the `use()` method.
|
|
234
239
|
*
|
|
235
|
-
* @param {string} path route path
|
|
236
|
-
* @param {...Function} callbacks
|
|
240
|
+
* @param {string | Function} path route path or middleware function
|
|
241
|
+
* @param {...Function} callbacks Additional middleware functions
|
|
237
242
|
* @returns {void}
|
|
238
243
|
*/
|
|
239
244
|
use(path, ...callbacks) {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* @typedef {import('../casa').Validator} Validator
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
|
-
* @typedef {
|
|
22
|
+
* @typedef {Object.<string, unknown>} ValidatorFactoryOptions
|
|
23
23
|
* @property {ErrorMessageConfig} errorMsg Error message
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
@@ -42,7 +42,9 @@ export default class ValidatorFactory {
|
|
|
42
42
|
* @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
|
|
43
43
|
*/
|
|
44
44
|
constructor(config?: ValidatorFactoryOptions);
|
|
45
|
-
config:
|
|
45
|
+
config: {
|
|
46
|
+
[x: string]: unknown;
|
|
47
|
+
};
|
|
46
48
|
/**
|
|
47
49
|
* Validate the given value.
|
|
48
50
|
*
|
|
@@ -66,8 +68,5 @@ export type ValidationError = import('./index').ValidationError;
|
|
|
66
68
|
export type ValidateContext = import('../casa').ValidateContext;
|
|
67
69
|
export type Validator = import('../casa').Validator;
|
|
68
70
|
export type ValidatorFactoryOptions = {
|
|
69
|
-
|
|
70
|
-
* Error message
|
|
71
|
-
*/
|
|
72
|
-
errorMsg: ErrorMessageConfig;
|
|
71
|
+
[x: string]: unknown;
|
|
73
72
|
};
|
|
@@ -27,7 +27,7 @@ const { isPlainObject } = lodash_1.default; // CommonJS
|
|
|
27
27
|
* @typedef {import('../casa').Validator} Validator
|
|
28
28
|
*/
|
|
29
29
|
/**
|
|
30
|
-
* @typedef {
|
|
30
|
+
* @typedef {Object.<string, unknown>} ValidatorFactoryOptions
|
|
31
31
|
* @property {ErrorMessageConfig} errorMsg Error message
|
|
32
32
|
*/
|
|
33
33
|
/**
|
package/dist/lib/field.d.ts
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @memberof module:@dwp/govuk-casa
|
|
5
5
|
* @param {string} name Field name
|
|
6
|
-
* @param {object} opts Options
|
|
6
|
+
* @param {object} [opts] Options
|
|
7
7
|
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
8
8
|
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
9
9
|
* @returns {PageField} A PageField
|
|
10
10
|
*/
|
|
11
|
-
export default function field(name: string, opts
|
|
11
|
+
export default function field(name: string, opts?: {
|
|
12
12
|
optional?: boolean | undefined;
|
|
13
13
|
persist?: boolean | undefined;
|
|
14
|
-
}): PageField;
|
|
14
|
+
} | undefined): PageField;
|
|
15
15
|
/**
|
|
16
16
|
* This class is not exposed via the public API. Instances should instead be
|
|
17
17
|
* instantiated through the `field()` factory function.
|
|
@@ -23,14 +23,14 @@ export class PageField {
|
|
|
23
23
|
* Create a field.
|
|
24
24
|
*
|
|
25
25
|
* @param {string} name Field name
|
|
26
|
-
* @param {object} opts Options
|
|
26
|
+
* @param {object} [opts] Options
|
|
27
27
|
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
28
28
|
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
29
29
|
*/
|
|
30
30
|
constructor(name: string, { optional, persist }?: {
|
|
31
31
|
optional?: boolean | undefined;
|
|
32
32
|
persist?: boolean | undefined;
|
|
33
|
-
});
|
|
33
|
+
} | undefined);
|
|
34
34
|
/**
|
|
35
35
|
* Clone this field.
|
|
36
36
|
*
|
|
@@ -68,38 +68,63 @@ export class PageField {
|
|
|
68
68
|
* @throws {SyntaxError} When the name is invalid in some way
|
|
69
69
|
*/
|
|
70
70
|
rename(name: string): PageField;
|
|
71
|
+
/**
|
|
72
|
+
* Get validators
|
|
73
|
+
*
|
|
74
|
+
* @returns {Validator[]} A list containing all validators.
|
|
75
|
+
*/
|
|
76
|
+
getValidators(): Validator[];
|
|
71
77
|
/**
|
|
72
78
|
* Add/get value validators
|
|
73
79
|
* Some validators will include a `sanitise()` method which will be run at the
|
|
74
80
|
* same time as other "processors".
|
|
75
81
|
*
|
|
76
82
|
* @param {Validator[]} items Validation functions
|
|
77
|
-
* @returns {PageField
|
|
83
|
+
* @returns {PageField} Chain - Deprecated: this currently gets all validators if
|
|
84
|
+
* empty or missing, in v9 this functionality will removed in favour of the
|
|
85
|
+
* function getValidators().
|
|
78
86
|
*/
|
|
79
|
-
validators(items?: Validator[]): PageField
|
|
87
|
+
validators(items?: Validator[]): PageField;
|
|
88
|
+
/**
|
|
89
|
+
* Get processors
|
|
90
|
+
*
|
|
91
|
+
* @returns {FieldProcessorFunction[]} A list containing all processors.
|
|
92
|
+
*/
|
|
93
|
+
getProcessors(): FieldProcessorFunction[];
|
|
80
94
|
/**
|
|
81
95
|
* Add/get value pre-processors
|
|
82
96
|
* This is most often used to sanitise values to a particular data type.
|
|
83
97
|
*
|
|
84
98
|
* @param {FieldProcessorFunction[]} items Processor functions
|
|
85
|
-
* @returns {PageField
|
|
99
|
+
* @returns {PageField} Chain - Deprecated: this currently gets all processors if
|
|
100
|
+
* empty or missing, in v9 this functionality will removed in favour of the
|
|
101
|
+
* function getProcessors().
|
|
102
|
+
*/
|
|
103
|
+
processors(items?: FieldProcessorFunction[]): PageField;
|
|
104
|
+
/**
|
|
105
|
+
* Get conditions
|
|
106
|
+
*
|
|
107
|
+
* @returns {ValidatorConditionFunction[]} A list containing all conditions.
|
|
86
108
|
*/
|
|
87
|
-
|
|
109
|
+
getConditions(): ValidatorConditionFunction[];
|
|
88
110
|
/**
|
|
89
111
|
* Add/get conditions
|
|
90
112
|
* All conditions must be met in order for this field to be considered
|
|
91
113
|
* "actionable".
|
|
92
114
|
*
|
|
93
115
|
* @param {ValidatorConditionFunction[]} items Condition functions
|
|
94
|
-
* @returns {PageField
|
|
116
|
+
* @returns {PageField} Chain - Deprecated: this currently gets all conditions if
|
|
117
|
+
* empty or missing, in v9 this functionality will removed in favour of the
|
|
118
|
+
* function getConditions().
|
|
95
119
|
*/
|
|
96
|
-
conditions(items?: ValidatorConditionFunction[]): PageField
|
|
120
|
+
conditions(items?: ValidatorConditionFunction[]): PageField;
|
|
97
121
|
/**
|
|
98
122
|
* Run all validators and return array of errors, if applicable.
|
|
99
123
|
*
|
|
100
124
|
* @param {any} value Value to validate
|
|
101
125
|
* @param {ValidateContext} context Contextual validation information
|
|
102
126
|
* @returns {ValidationError[]} Errors, or an empty array if all valid
|
|
127
|
+
* @throws {TypeError} If validator does not return an array
|
|
103
128
|
*/
|
|
104
129
|
runValidators(value: any, context?: ValidateContext): ValidationError[];
|
|
105
130
|
/**
|
package/dist/lib/field.js
CHANGED
|
@@ -19,8 +19,8 @@ exports.PageField = void 0;
|
|
|
19
19
|
const lodash_1 = __importDefault(require("lodash"));
|
|
20
20
|
const utils_js_1 = require("./utils.js");
|
|
21
21
|
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
22
|
-
const { isFunction } = lodash_1.default;
|
|
23
22
|
const log = (0, logger_js_1.default)('lib:field');
|
|
23
|
+
const { isFunction } = lodash_1.default;
|
|
24
24
|
/**
|
|
25
25
|
* @access private
|
|
26
26
|
* @typedef {import('./index').JourneyContext} JourneyContext
|
|
@@ -60,7 +60,7 @@ class PageField {
|
|
|
60
60
|
* Create a field.
|
|
61
61
|
*
|
|
62
62
|
* @param {string} name Field name
|
|
63
|
-
* @param {object} opts Options
|
|
63
|
+
* @param {object} [opts] Options
|
|
64
64
|
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
65
65
|
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
66
66
|
*/
|
|
@@ -100,6 +100,7 @@ class PageField {
|
|
|
100
100
|
complexFieldProperty: undefined,
|
|
101
101
|
}, "f");
|
|
102
102
|
// Apply name
|
|
103
|
+
/* eslint-disable-next-line security/detect-non-literal-fs-filename */
|
|
103
104
|
this.rename(name);
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
@@ -112,14 +113,14 @@ class PageField {
|
|
|
112
113
|
optional: __classPrivateFieldGet(this, _PageField_meta, "f").optional,
|
|
113
114
|
persist: __classPrivateFieldGet(this, _PageField_meta, "f").persist,
|
|
114
115
|
});
|
|
115
|
-
if (this.
|
|
116
|
-
clone.validators(this.
|
|
116
|
+
if (this.getValidators()) {
|
|
117
|
+
clone.validators(this.getValidators());
|
|
117
118
|
}
|
|
118
|
-
if (this.
|
|
119
|
-
clone.conditions(this.
|
|
119
|
+
if (this.getConditions()) {
|
|
120
|
+
clone.conditions(this.getConditions());
|
|
120
121
|
}
|
|
121
|
-
if (this.
|
|
122
|
-
clone.processors(this.
|
|
122
|
+
if (this.getProcessors()) {
|
|
123
|
+
clone.processors(this.getProcessors());
|
|
123
124
|
}
|
|
124
125
|
return clone;
|
|
125
126
|
}
|
|
@@ -195,46 +196,79 @@ class PageField {
|
|
|
195
196
|
}
|
|
196
197
|
return this;
|
|
197
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Get validators
|
|
201
|
+
*
|
|
202
|
+
* @returns {Validator[]} A list containing all validators.
|
|
203
|
+
*/
|
|
204
|
+
getValidators() {
|
|
205
|
+
return __classPrivateFieldGet(this, _PageField_validators, "f");
|
|
206
|
+
}
|
|
198
207
|
/**
|
|
199
208
|
* Add/get value validators
|
|
200
209
|
* Some validators will include a `sanitise()` method which will be run at the
|
|
201
210
|
* same time as other "processors".
|
|
202
211
|
*
|
|
203
212
|
* @param {Validator[]} items Validation functions
|
|
204
|
-
* @returns {PageField
|
|
213
|
+
* @returns {PageField} Chain - Deprecated: this currently gets all validators if
|
|
214
|
+
* empty or missing, in v9 this functionality will removed in favour of the
|
|
215
|
+
* function getValidators().
|
|
205
216
|
*/
|
|
206
217
|
validators(items = []) {
|
|
207
218
|
if (!items.length) {
|
|
208
|
-
|
|
219
|
+
log.warn('Calling validators() to get all validators is deprecated, please use getValidators()');
|
|
220
|
+
return this.getValidators();
|
|
209
221
|
}
|
|
210
222
|
__classPrivateFieldSet(this, _PageField_validators, [...__classPrivateFieldGet(this, _PageField_validators, "f"), ...(items.flat())], "f");
|
|
211
223
|
return this;
|
|
212
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Get processors
|
|
227
|
+
*
|
|
228
|
+
* @returns {FieldProcessorFunction[]} A list containing all processors.
|
|
229
|
+
*/
|
|
230
|
+
getProcessors() {
|
|
231
|
+
return __classPrivateFieldGet(this, _PageField_processors, "f");
|
|
232
|
+
}
|
|
213
233
|
/**
|
|
214
234
|
* Add/get value pre-processors
|
|
215
235
|
* This is most often used to sanitise values to a particular data type.
|
|
216
236
|
*
|
|
217
237
|
* @param {FieldProcessorFunction[]} items Processor functions
|
|
218
|
-
* @returns {PageField
|
|
238
|
+
* @returns {PageField} Chain - Deprecated: this currently gets all processors if
|
|
239
|
+
* empty or missing, in v9 this functionality will removed in favour of the
|
|
240
|
+
* function getProcessors().
|
|
219
241
|
*/
|
|
220
242
|
processors(items = []) {
|
|
221
243
|
if (!items.length) {
|
|
222
|
-
|
|
244
|
+
log.warn('Calling processors() to get all processors is deprecated, please use getProcessors()');
|
|
245
|
+
return this.getProcessors();
|
|
223
246
|
}
|
|
224
247
|
__classPrivateFieldSet(this, _PageField_processors, [...__classPrivateFieldGet(this, _PageField_processors, "f"), ...(items.flat())], "f");
|
|
225
248
|
return this;
|
|
226
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Get conditions
|
|
252
|
+
*
|
|
253
|
+
* @returns {ValidatorConditionFunction[]} A list containing all conditions.
|
|
254
|
+
*/
|
|
255
|
+
getConditions() {
|
|
256
|
+
return __classPrivateFieldGet(this, _PageField_conditions, "f");
|
|
257
|
+
}
|
|
227
258
|
/**
|
|
228
259
|
* Add/get conditions
|
|
229
260
|
* All conditions must be met in order for this field to be considered
|
|
230
261
|
* "actionable".
|
|
231
262
|
*
|
|
232
263
|
* @param {ValidatorConditionFunction[]} items Condition functions
|
|
233
|
-
* @returns {PageField
|
|
264
|
+
* @returns {PageField} Chain - Deprecated: this currently gets all conditions if
|
|
265
|
+
* empty or missing, in v9 this functionality will removed in favour of the
|
|
266
|
+
* function getConditions().
|
|
234
267
|
*/
|
|
235
268
|
conditions(items = []) {
|
|
236
269
|
if (!items.length) {
|
|
237
|
-
|
|
270
|
+
log.warn('Calling conditions() to get all conditions is deprecated, please use getConditions()');
|
|
271
|
+
return this.getConditions();
|
|
238
272
|
}
|
|
239
273
|
__classPrivateFieldSet(this, _PageField_conditions, [...__classPrivateFieldGet(this, _PageField_conditions, "f"), ...(items.flat())], "f");
|
|
240
274
|
return this;
|
|
@@ -246,6 +280,7 @@ class PageField {
|
|
|
246
280
|
* @param {any} value Value to validate
|
|
247
281
|
* @param {ValidateContext} context Contextual validation information
|
|
248
282
|
* @returns {ValidationError[]} Errors, or an empty array if all valid
|
|
283
|
+
* @throws {TypeError} If validator does not return an array
|
|
249
284
|
*/
|
|
250
285
|
runValidators(value, context = Object.create(null)) {
|
|
251
286
|
var _a;
|
|
@@ -362,7 +397,7 @@ class PageField {
|
|
|
362
397
|
* @returns {PageField} Chain
|
|
363
398
|
*/
|
|
364
399
|
if(...args) {
|
|
365
|
-
return this.conditions(
|
|
400
|
+
return this.conditions(args);
|
|
366
401
|
}
|
|
367
402
|
}
|
|
368
403
|
exports.PageField = PageField;
|
|
@@ -372,7 +407,7 @@ _PageField_name = new WeakMap(), _PageField_processors = new WeakMap(), _PageFie
|
|
|
372
407
|
*
|
|
373
408
|
* @memberof module:@dwp/govuk-casa
|
|
374
409
|
* @param {string} name Field name
|
|
375
|
-
* @param {object} opts Options
|
|
410
|
+
* @param {object} [opts] Options
|
|
376
411
|
* @param {boolean} [opts.optional=false] Whether this field is optional
|
|
377
412
|
* @param {boolean} [opts.persist=true] Whether this field will persist in `req.body`
|
|
378
413
|
* @returns {PageField} A PageField
|
package/dist/lib/waypoint-url.js
CHANGED
package/dist/middleware/pre.js
CHANGED
|
@@ -5,14 +5,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
const helmet_1 = __importDefault(require("helmet"));
|
|
8
|
+
/**
|
|
9
|
+
* @access private
|
|
10
|
+
* @typedef {import('../casa').HelmetConfigurator} HelmetConfigurator
|
|
11
|
+
*/
|
|
8
12
|
const GA_DOMAIN = '*.google-analytics.com';
|
|
9
13
|
const GA_ANALYTICS_DOMAIN = '*.analytics.google.com';
|
|
10
14
|
const GTM_DOMAIN = '*.googletagmanager.com';
|
|
11
15
|
const GTM_PREVIEW_DOMAIN = 'https://tagmanager.google.com';
|
|
12
16
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
17
|
+
* Extracts the CSP nonce used in every template, and makes it available as a
|
|
18
|
+
* nonce value in the CSP header.
|
|
19
|
+
*
|
|
20
|
+
* IMPORTANT: Do not rename this function as it _might_ be used in consumer code
|
|
21
|
+
* to identify this function specifically, most likely to remove it from CSP
|
|
22
|
+
* headers for custom purposes.
|
|
23
|
+
*
|
|
24
|
+
* @param {import('express').Request} req Request
|
|
25
|
+
* @param {import('express').Response} res Response
|
|
26
|
+
* @returns {string} nonce value suitable for use in CSP header
|
|
15
27
|
*/
|
|
28
|
+
function casaCspNonce(req, res) {
|
|
29
|
+
return `'nonce-${res.locals.cspNonce}'`;
|
|
30
|
+
}
|
|
16
31
|
/**
|
|
17
32
|
* Pre middleware.
|
|
18
33
|
*
|
|
@@ -56,13 +71,13 @@ exports.default = ({ helmetConfigurator = (config) => (config), } = {}) => [
|
|
|
56
71
|
useDefaults: true,
|
|
57
72
|
directives: {
|
|
58
73
|
'default-src': ["'none'"],
|
|
59
|
-
'script-src': ["'self'", GA_DOMAIN, GTM_DOMAIN, GTM_PREVIEW_DOMAIN,
|
|
74
|
+
'script-src': ["'self'", GA_DOMAIN, GTM_DOMAIN, GTM_PREVIEW_DOMAIN, casaCspNonce],
|
|
60
75
|
'img-src': ["'self'", GA_DOMAIN, GA_ANALYTICS_DOMAIN, GTM_DOMAIN, 'https://ssl.gstatic.com', 'https://www.gstatic.com'],
|
|
61
76
|
'connect-src': ["'self'", GA_DOMAIN, GA_ANALYTICS_DOMAIN, GTM_DOMAIN],
|
|
62
77
|
'frame-src': ["'self'", GTM_DOMAIN],
|
|
63
78
|
'frame-ancestors': ["'self'"],
|
|
64
79
|
'form-action': ["'self'"],
|
|
65
|
-
'style-src': ["'self'", 'https://fonts.googleapis.com', GTM_PREVIEW_DOMAIN,
|
|
80
|
+
'style-src': ["'self'", 'https://fonts.googleapis.com', GTM_PREVIEW_DOMAIN, casaCspNonce],
|
|
66
81
|
'font-src': ["'self'", 'data:', 'https://fonts.gstatic.com'],
|
|
67
82
|
},
|
|
68
83
|
},
|
package/locales/cy/common.json
CHANGED
package/locales/cy/macros.json
CHANGED
package/locales/cy/review.json
CHANGED
package/locales/en/common.json
CHANGED
package/locales/en/review.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dwp/govuk-casa",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"description": "A framework for building GOVUK Collect-And-Submit-Applications",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"build:css-assets": "node scripts/compile-sass.js",
|
|
35
35
|
"build:api-docs": "npx jsdoc -c ./jsdoc.json -d ./docs/api/ --debug -P '' -r -R ./README.md --verbose -t ./node_modules/docdash ./src",
|
|
36
36
|
"prepare": "npm run build",
|
|
37
|
-
"upgrade-deps": "OD=$(npm outdated --long --parseable); echo \"$OD\" | grep ':devDependencies:' | awk -F: '{ print $4 }' | xargs npm i -DE; echo \"$OD\" | grep ':dependencies:' | awk -F: '{ print $4 }' | xargs npm i -E"
|
|
38
|
-
"standard-version": "node scripts/standard-version.js"
|
|
37
|
+
"upgrade-deps": "OD=$(npm outdated --long --parseable); echo \"$OD\" | grep ':devDependencies:' | awk -F: '{ print $4 }' | xargs npm i -DE; echo \"$OD\" | grep ':dependencies:' | awk -F: '{ print $4 }' | xargs npm i -E"
|
|
39
38
|
},
|
|
40
39
|
"keywords": [],
|
|
41
40
|
"author": "DWP Digital",
|
|
@@ -50,50 +49,50 @@
|
|
|
50
49
|
"express-session": "1.17.3",
|
|
51
50
|
"govuk-frontend": "4.3.1",
|
|
52
51
|
"graphlib": "2.1.8",
|
|
53
|
-
"helmet": "
|
|
54
|
-
"i18next": "
|
|
52
|
+
"helmet": "6.0.0",
|
|
53
|
+
"i18next": "22.0.4",
|
|
55
54
|
"i18next-http-middleware": "3.2.1",
|
|
56
55
|
"js-yaml": "4.1.0",
|
|
57
56
|
"lodash": "4.17.21",
|
|
58
|
-
"luxon": "
|
|
57
|
+
"luxon": "3.1.0",
|
|
59
58
|
"nunjucks": "3.2.3",
|
|
60
59
|
"path-to-regexp": "6.2.1",
|
|
61
|
-
"uuid": "
|
|
60
|
+
"uuid": "9.0.0",
|
|
62
61
|
"validator": "13.7.0"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"@babel/core": "7.
|
|
64
|
+
"@babel/core": "7.20.2",
|
|
66
65
|
"@babel/eslint-parser": "7.19.1",
|
|
67
|
-
"@babel/preset-env": "7.
|
|
68
|
-
"@ckeditor/jsdoc-plugins": "
|
|
69
|
-
"@commitlint/config-conventional": "17.
|
|
66
|
+
"@babel/preset-env": "7.20.2",
|
|
67
|
+
"@ckeditor/jsdoc-plugins": "31.1.8",
|
|
68
|
+
"@commitlint/config-conventional": "17.2.0",
|
|
70
69
|
"@dwp/casa-spiderplan": "2.4.1",
|
|
71
70
|
"@dwp/casa-spiderplan-a11y-plugin": "0.1.4",
|
|
72
71
|
"@dwp/casa-spiderplan-zap-plugin": "0.1.1",
|
|
73
72
|
"@dwp/eslint-config-base": "6.0.0",
|
|
74
73
|
"@types/express": "4.17.14",
|
|
75
|
-
"@types/node": "18.
|
|
74
|
+
"@types/node": "18.11.9",
|
|
76
75
|
"@types/nunjucks": "3.2.1",
|
|
77
76
|
"babel-eslint": "10.1.0",
|
|
78
77
|
"c8": "7.12.0",
|
|
79
78
|
"chai": "4.3.6",
|
|
80
79
|
"cheerio": "1.0.0-rc.12",
|
|
81
|
-
"commitlint": "17.
|
|
80
|
+
"commitlint": "17.2.0",
|
|
82
81
|
"docdash": "1.2.0",
|
|
83
|
-
"eslint": "8.
|
|
82
|
+
"eslint": "8.26.0",
|
|
84
83
|
"eslint-plugin-no-unsafe-regex": "1.0.0",
|
|
85
84
|
"eslint-plugin-security": "1.5.0",
|
|
86
85
|
"eslint-plugin-sonarjs": "0.16.0",
|
|
87
|
-
"fast-check": "3.
|
|
86
|
+
"fast-check": "3.3.0",
|
|
88
87
|
"husky": "8.0.1",
|
|
89
|
-
"jsdoc": "
|
|
88
|
+
"jsdoc": "4.0.0",
|
|
90
89
|
"jsdoc-tsimport-plugin": "1.0.5",
|
|
91
|
-
"mocha": "10.
|
|
92
|
-
"sass": "1.
|
|
90
|
+
"mocha": "10.1.0",
|
|
91
|
+
"sass": "1.56.0",
|
|
93
92
|
"sinon": "14.0.1",
|
|
94
93
|
"sinon-chai": "3.7.0",
|
|
95
94
|
"standard-version": "9.5.0",
|
|
96
|
-
"supertest": "6.3.
|
|
95
|
+
"supertest": "6.3.1",
|
|
97
96
|
"typescript": "4.8.4"
|
|
98
97
|
}
|
|
99
98
|
}
|