@dwp/govuk-casa 8.1.0 → 8.2.2
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 +25 -0
- package/README.md +2 -0
- package/dist/assets/css/casa-ie8.css +1 -1
- package/dist/assets/css/casa.css +1 -1
- package/dist/casa.d.ts +214 -0
- package/dist/casa.js +103 -0
- package/dist/lib/JourneyContext.d.ts +15 -27
- package/dist/lib/JourneyContext.js +25 -15
- package/dist/lib/configuration-ingestor.d.ts +16 -144
- package/dist/lib/configuration-ingestor.js +25 -95
- package/dist/lib/configure.d.ts +6 -77
- package/dist/lib/configure.js +58 -39
- package/dist/lib/nunjucks.d.ts +1 -6
- package/dist/lib/nunjucks.js +1 -3
- package/dist/lib/utils.d.ts +13 -10
- package/dist/lib/utils.js +40 -8
- package/dist/lib/waypoint-url.js +8 -2
- package/dist/middleware/body-parser.js +1 -1
- package/dist/middleware/data.d.ts +1 -2
- package/dist/middleware/data.js +12 -2
- package/dist/middleware/post.d.ts +1 -3
- package/dist/middleware/post.js +2 -2
- package/dist/middleware/pre.d.ts +1 -1
- package/dist/middleware/pre.js +5 -4
- package/dist/middleware/progress-journey.d.ts +1 -2
- package/dist/middleware/progress-journey.js +2 -2
- package/dist/middleware/session.d.ts +1 -2
- package/dist/middleware/session.js +7 -5
- package/dist/middleware/skip-waypoint.d.ts +1 -2
- package/dist/middleware/skip-waypoint.js +2 -2
- package/dist/middleware/steer-journey.d.ts +1 -2
- package/dist/middleware/steer-journey.js +2 -2
- package/dist/middleware/strip-proxy-path.d.ts +4 -0
- package/dist/middleware/strip-proxy-path.js +52 -0
- package/dist/middleware/validate-fields.d.ts +1 -2
- package/dist/middleware/validate-fields.js +2 -1
- package/dist/routes/journey.d.ts +1 -2
- package/dist/routes/journey.js +8 -8
- package/dist/routes/static.d.ts +1 -6
- package/dist/routes/static.js +6 -6
- package/package.json +25 -23
- package/views/casa/components/journey-form/README.md +3 -0
- package/views/casa/components/journey-form/template.njk +1 -1
- package/views/casa/partials/scripts.njk +1 -1
- package/views/casa/partials/styles.njk +2 -2
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @throws {TypeError} For invalid object.
|
|
7
7
|
* @returns {object} Sanitised i18n object.
|
|
8
8
|
*/
|
|
9
|
-
export function validateI18nObject(i18n
|
|
9
|
+
export function validateI18nObject(i18n?: object, cb?: Function): object;
|
|
10
10
|
/**
|
|
11
11
|
* Validates and sanitises i18n directory.
|
|
12
12
|
*
|
|
@@ -15,7 +15,7 @@ export function validateI18nObject(i18n: object, cb?: Function): object;
|
|
|
15
15
|
* @throws {TypeError} For invalid type.
|
|
16
16
|
* @returns {Array} Array of directories.
|
|
17
17
|
*/
|
|
18
|
-
export function validateI18nDirs(dirs
|
|
18
|
+
export function validateI18nDirs(dirs?: any[]): any[];
|
|
19
19
|
/**
|
|
20
20
|
* Validates and sanitises i18n locales.
|
|
21
21
|
*
|
|
@@ -24,16 +24,15 @@ export function validateI18nDirs(dirs: any[]): any[];
|
|
|
24
24
|
* @throws {TypeError} For invalid type.
|
|
25
25
|
* @returns {Array} Array of locales.
|
|
26
26
|
*/
|
|
27
|
-
export function validateI18nLocales(locales
|
|
27
|
+
export function validateI18nLocales(locales?: any[]): any[];
|
|
28
28
|
/**
|
|
29
29
|
* Validates and sanitises mount url.
|
|
30
30
|
*
|
|
31
|
-
* @param {string} mountUrl
|
|
32
|
-
* @param {string} name Name of the URL type (Mount URL, or Proxy Mount URL).
|
|
31
|
+
* @param {string} mountUrl Prefix for all URLs in the browser address bar
|
|
33
32
|
* @throws {SyntaxError} For invalid URL.
|
|
34
|
-
* @returns {string} Sanitised URL.
|
|
33
|
+
* @returns {string|undefined} Sanitised URL.
|
|
35
34
|
*/
|
|
36
|
-
export function validateMountUrl(mountUrl: string
|
|
35
|
+
export function validateMountUrl(mountUrl: string): string | undefined;
|
|
37
36
|
/**
|
|
38
37
|
* Validates and sanitises sessions object.
|
|
39
38
|
*
|
|
@@ -42,7 +41,7 @@ export function validateMountUrl(mountUrl: string, name?: string): string;
|
|
|
42
41
|
* @throws {TypeError} For invalid object.
|
|
43
42
|
* @returns {object} Sanitised sessions object.
|
|
44
43
|
*/
|
|
45
|
-
export function validateSessionObject(session
|
|
44
|
+
export function validateSessionObject(session?: object, cb?: Function): object;
|
|
46
45
|
/**
|
|
47
46
|
* Validates and sanitises view directory.
|
|
48
47
|
*
|
|
@@ -51,7 +50,7 @@ export function validateSessionObject(session: object, cb?: Function): object;
|
|
|
51
50
|
* @throws {TypeError} For invalid type.
|
|
52
51
|
* @returns {Array} Array of directories.
|
|
53
52
|
*/
|
|
54
|
-
export function validateViews(dirs
|
|
53
|
+
export function validateViews(dirs?: any[]): any[];
|
|
55
54
|
/**
|
|
56
55
|
* Validates and sanitises sessions secret.
|
|
57
56
|
*
|
|
@@ -69,25 +68,25 @@ export function validateSessionSecret(secret: string): string;
|
|
|
69
68
|
* @throws {TypeError} For invalid value.
|
|
70
69
|
* @returns {number} Ttl.
|
|
71
70
|
*/
|
|
72
|
-
export function validateSessionTtl(ttl
|
|
71
|
+
export function validateSessionTtl(ttl?: number): number;
|
|
73
72
|
/**
|
|
74
73
|
* Validates and sanitises sessions name.
|
|
75
74
|
*
|
|
76
|
-
* @param {string} name Session name.
|
|
75
|
+
* @param {string} [name=casa-session] Session name.
|
|
77
76
|
* @throws {ReferenceError} For missing value type.
|
|
78
77
|
* @throws {TypeError} For invalid value.
|
|
79
78
|
* @returns {string} Name.
|
|
80
79
|
*/
|
|
81
|
-
export function validateSessionName(name
|
|
80
|
+
export function validateSessionName(name?: string | undefined): string;
|
|
82
81
|
/**
|
|
83
82
|
* Validates and sanitises sessions secure flag.
|
|
84
83
|
*
|
|
85
|
-
* @param {boolean} secure Session secure flag.
|
|
84
|
+
* @param {boolean} [secure=false] Session secure flag.
|
|
86
85
|
* @throws {ReferenceError} For missing value type.
|
|
87
86
|
* @throws {TypeError} For invalid value.
|
|
88
87
|
* @returns {string} Name.
|
|
89
88
|
*/
|
|
90
|
-
export function validateSessionSecure(secure
|
|
89
|
+
export function validateSessionSecure(secure?: boolean | undefined): string;
|
|
91
90
|
/**
|
|
92
91
|
* Validates and sanitises sessions store.
|
|
93
92
|
*
|
|
@@ -119,7 +118,7 @@ export function validateSessionCookiePath(cookiePath: string, defaultPath?: stri
|
|
|
119
118
|
export function validateSessionCookieSameSite(cookieSameSite: any, defaultFlag: any): boolean;
|
|
120
119
|
export function validatePageHooks(hooks: any): any[];
|
|
121
120
|
export function validateFields(fields: any): any[];
|
|
122
|
-
export function validatePages(pages
|
|
121
|
+
export function validatePages(pages?: any[]): any[];
|
|
123
122
|
export function validatePlan(plan: any): any;
|
|
124
123
|
export function validateGlobalHooks(hooks: any): any[];
|
|
125
124
|
export function validatePlugins(plugins: any): any;
|
|
@@ -140,132 +139,5 @@ export function validateHelmetConfigurator(helmetConfigurator: HelmetConfigurato
|
|
|
140
139
|
* @returns {object} Immutable config object.
|
|
141
140
|
*/
|
|
142
141
|
export default function ingest(config?: ConfigurationOptions): object;
|
|
143
|
-
export type
|
|
144
|
-
export type
|
|
145
|
-
/**
|
|
146
|
-
* Session name
|
|
147
|
-
*/
|
|
148
|
-
name?: string | undefined;
|
|
149
|
-
/**
|
|
150
|
-
* Encryption secret
|
|
151
|
-
*/
|
|
152
|
-
secret?: string | undefined;
|
|
153
|
-
/**
|
|
154
|
-
* Session ttl (seconds)
|
|
155
|
-
*/
|
|
156
|
-
ttl?: number | undefined;
|
|
157
|
-
/**
|
|
158
|
-
* Whether to use secure session cookies
|
|
159
|
-
*/
|
|
160
|
-
secure?: boolean | undefined;
|
|
161
|
-
/**
|
|
162
|
-
* SameSite (true = Strict)
|
|
163
|
-
*/
|
|
164
|
-
cookieSameSite?: string | boolean | undefined;
|
|
165
|
-
/**
|
|
166
|
-
* Session store (default MemoryStore)
|
|
167
|
-
*/
|
|
168
|
-
store?: object | undefined;
|
|
169
|
-
};
|
|
170
|
-
export type I18nOptions = {
|
|
171
|
-
/**
|
|
172
|
-
* Directories to search for locale dictionaries
|
|
173
|
-
*/
|
|
174
|
-
dirs: string[];
|
|
175
|
-
/**
|
|
176
|
-
* Supported locales
|
|
177
|
-
*/
|
|
178
|
-
locales?: string[] | undefined;
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* Hook configuration
|
|
182
|
-
*/
|
|
183
|
-
export type GlobalHook = {
|
|
184
|
-
/**
|
|
185
|
-
* Hook name in format `<router>.<hook>`
|
|
186
|
-
*/
|
|
187
|
-
hook: string;
|
|
188
|
-
/**
|
|
189
|
-
* Middleware function to insert at the hook point
|
|
190
|
-
*/
|
|
191
|
-
middleware: Function;
|
|
192
|
-
/**
|
|
193
|
-
* Only run if route path matches this string/regexp
|
|
194
|
-
*/
|
|
195
|
-
path?: string | RegExp | undefined;
|
|
196
|
-
};
|
|
197
|
-
/**
|
|
198
|
-
* (extends GlobalHook)
|
|
199
|
-
*/
|
|
200
|
-
export type PageHook = {
|
|
201
|
-
/**
|
|
202
|
-
* Hook name (without a scope prefix)
|
|
203
|
-
*/
|
|
204
|
-
hook: string;
|
|
205
|
-
/**
|
|
206
|
-
* Middleware function to insert at the hook point
|
|
207
|
-
*/
|
|
208
|
-
middleware: Function;
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
211
|
-
* Page configuration. A Page is the interactive representation of a waypoint
|
|
212
|
-
*/
|
|
213
|
-
export type Page = {
|
|
214
|
-
/**
|
|
215
|
-
* The waypoint with which this page is associated
|
|
216
|
-
*/
|
|
217
|
-
waypoint: string;
|
|
218
|
-
/**
|
|
219
|
-
* Template path
|
|
220
|
-
*/
|
|
221
|
-
view: string;
|
|
222
|
-
/**
|
|
223
|
-
* Page-specific hooks (optional, default [])
|
|
224
|
-
*/
|
|
225
|
-
hooks?: PageHook[] | undefined;
|
|
226
|
-
/**
|
|
227
|
-
* Fields to be managed on this page (optional, default [])
|
|
228
|
-
*/
|
|
229
|
-
fields?: PageField[] | undefined;
|
|
230
|
-
};
|
|
231
|
-
export type HelmetConfigurator = (config: object) => object;
|
|
232
|
-
/**
|
|
233
|
-
* Configuration options
|
|
234
|
-
*/
|
|
235
|
-
export type ConfigurationOptions = {
|
|
236
|
-
mountUrl?: string | undefined;
|
|
237
|
-
/**
|
|
238
|
-
* Template directories
|
|
239
|
-
*/
|
|
240
|
-
views?: string[] | undefined;
|
|
241
|
-
/**
|
|
242
|
-
* Session configuration
|
|
243
|
-
*/
|
|
244
|
-
session?: SessionOptions | undefined;
|
|
245
|
-
/**
|
|
246
|
-
* Pages the represent waypoints
|
|
247
|
-
*/
|
|
248
|
-
pages?: Page[] | undefined;
|
|
249
|
-
/**
|
|
250
|
-
* Hooks to apply
|
|
251
|
-
*/
|
|
252
|
-
hooks?: GlobalHook[] | undefined;
|
|
253
|
-
/**
|
|
254
|
-
* Plugins
|
|
255
|
-
*/
|
|
256
|
-
plugins?: object[] | undefined;
|
|
257
|
-
/**
|
|
258
|
-
* I18n configuration
|
|
259
|
-
*/
|
|
260
|
-
i18n?: I18nOptions[] | undefined;
|
|
261
|
-
/**
|
|
262
|
-
* CASA Plan
|
|
263
|
-
*/
|
|
264
|
-
plan: Plan;
|
|
265
|
-
/**
|
|
266
|
-
* Handlers for JourneyContext events
|
|
267
|
-
*/
|
|
268
|
-
events?: any[] | undefined;
|
|
269
|
-
};
|
|
270
|
-
import { PageField } from "./field.js";
|
|
271
|
-
import Plan from "./Plan.js";
|
|
142
|
+
export type ConfigurationOptions = import('../casa').ConfigurationOptions;
|
|
143
|
+
export type HelmetConfigurator = import('../casa').HelmetConfigurator;
|
|
@@ -10,61 +10,10 @@ const Plan_js_1 = __importDefault(require("./Plan.js"));
|
|
|
10
10
|
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
11
11
|
const utils_js_1 = require("./utils.js");
|
|
12
12
|
/**
|
|
13
|
-
* @typedef {import('
|
|
13
|
+
* @typedef {import('../casa').ConfigurationOptions} ConfigurationOptions
|
|
14
14
|
*/
|
|
15
15
|
/**
|
|
16
|
-
* @typedef {
|
|
17
|
-
* @property {string} [name=casasession] Session name
|
|
18
|
-
* @property {string} [secret=secret] Encryption secret
|
|
19
|
-
* @property {number} [ttl=3600] Session ttl (seconds)
|
|
20
|
-
* @property {boolean} [secure=false] Whether to use secure session cookies
|
|
21
|
-
* @property {boolean|string} [cookieSameSite=true] SameSite (true = Strict)
|
|
22
|
-
* @property {object} [store] Session store (default MemoryStore)
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* @typedef {object} I18nOptions
|
|
26
|
-
* @property {string[]} dirs Directories to search for locale dictionaries
|
|
27
|
-
* @property {string[]} [locales=['en', 'cy']] Supported locales
|
|
28
|
-
*/
|
|
29
|
-
/**
|
|
30
|
-
* @typedef {object} GlobalHook Hook configuration
|
|
31
|
-
* @property {string} hook Hook name in format `<router>.<hook>`
|
|
32
|
-
* @property {Function} middleware Middleware function to insert at the hook point
|
|
33
|
-
* @property {string|RegExp} [path=undefined] Only run if route path matches this string/regexp
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {object} PageHook (extends GlobalHook)
|
|
37
|
-
* @property {string} hook Hook name (without a scope prefix)
|
|
38
|
-
* @property {Function} middleware Middleware function to insert at the hook point
|
|
39
|
-
*/
|
|
40
|
-
/**
|
|
41
|
-
* @typedef {object} Page Page configuration. A Page is the interactive representation of a waypoint
|
|
42
|
-
* @property {string} waypoint The waypoint with which this page is associated
|
|
43
|
-
* @property {string} view Template path
|
|
44
|
-
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default [])
|
|
45
|
-
* @property {PageField[]} [fields=[]] Fields to be managed on this page (optional, default [])
|
|
46
|
-
*/
|
|
47
|
-
/**
|
|
48
|
-
* @callback HelmetConfigurator
|
|
49
|
-
* @param {object} config A default Helmet configuration provided by CASA
|
|
50
|
-
* @returns {object} The modified configuration object
|
|
51
|
-
*/
|
|
52
|
-
/**
|
|
53
|
-
* Configure some middleware for use in creating a new CASA app.
|
|
54
|
-
*
|
|
55
|
-
* `mountUrl` is used to ensure the CSS content uses the correct reference to
|
|
56
|
-
* static assets in the `govuk-frontend` module.
|
|
57
|
-
*
|
|
58
|
-
* @typedef {object} ConfigurationOptions Configuration options
|
|
59
|
-
* @property {string} [mountUrl=/] URL path to root of CASA app
|
|
60
|
-
* @property {string[]} [views=[]] Template directories
|
|
61
|
-
* @property {SessionOptions} [session] Session configuration
|
|
62
|
-
* @property {Page[]} [pages=[]] Pages the represent waypoints
|
|
63
|
-
* @property {GlobalHook[]} [hooks=[]] Hooks to apply
|
|
64
|
-
* @property {object[]} [plugins=[]] Plugins
|
|
65
|
-
* @property {I18nOptions[]} [i18n] I18n configuration
|
|
66
|
-
* @property {Plan} plan CASA Plan
|
|
67
|
-
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events
|
|
16
|
+
* @typedef {import('../casa').HelmetConfigurator} HelmetConfigurator
|
|
68
17
|
*/
|
|
69
18
|
const log = (0, logger_js_1.default)('lib:configuration-ingestor');
|
|
70
19
|
const echo = (a) => (a);
|
|
@@ -76,7 +25,7 @@ const echo = (a) => (a);
|
|
|
76
25
|
* @throws {TypeError} For invalid object.
|
|
77
26
|
* @returns {object} Sanitised i18n object.
|
|
78
27
|
*/
|
|
79
|
-
function validateI18nObject(i18n, cb = echo) {
|
|
28
|
+
function validateI18nObject(i18n = Object.create(null), cb = echo) {
|
|
80
29
|
if (Object.prototype.toString.call(i18n) !== '[object Object]') {
|
|
81
30
|
throw new TypeError('I18n must be an object');
|
|
82
31
|
}
|
|
@@ -91,11 +40,8 @@ exports.validateI18nObject = validateI18nObject;
|
|
|
91
40
|
* @throws {TypeError} For invalid type.
|
|
92
41
|
* @returns {Array} Array of directories.
|
|
93
42
|
*/
|
|
94
|
-
function validateI18nDirs(dirs) {
|
|
95
|
-
if (
|
|
96
|
-
throw ReferenceError('I18n directories are missing (i18n.dirs)');
|
|
97
|
-
}
|
|
98
|
-
else if (!Array.isArray(dirs)) {
|
|
43
|
+
function validateI18nDirs(dirs = []) {
|
|
44
|
+
if (!Array.isArray(dirs)) {
|
|
99
45
|
throw new TypeError('I18n directories must be an array (i18n.dirs)');
|
|
100
46
|
}
|
|
101
47
|
dirs.forEach((dir, i) => {
|
|
@@ -114,11 +60,8 @@ exports.validateI18nDirs = validateI18nDirs;
|
|
|
114
60
|
* @throws {TypeError} For invalid type.
|
|
115
61
|
* @returns {Array} Array of locales.
|
|
116
62
|
*/
|
|
117
|
-
function validateI18nLocales(locales) {
|
|
118
|
-
if (
|
|
119
|
-
throw ReferenceError('I18n locales are missing (i18n.locales)');
|
|
120
|
-
}
|
|
121
|
-
else if (!Array.isArray(locales)) {
|
|
63
|
+
function validateI18nLocales(locales = ['en', 'cy']) {
|
|
64
|
+
if (!Array.isArray(locales)) {
|
|
122
65
|
throw new TypeError('I18n locales must be an array (i18n.locales)');
|
|
123
66
|
}
|
|
124
67
|
locales.forEach((locale, i) => {
|
|
@@ -132,17 +75,16 @@ exports.validateI18nLocales = validateI18nLocales;
|
|
|
132
75
|
/**
|
|
133
76
|
* Validates and sanitises mount url.
|
|
134
77
|
*
|
|
135
|
-
* @param {string} mountUrl
|
|
136
|
-
* @param {string} name Name of the URL type (Mount URL, or Proxy Mount URL).
|
|
78
|
+
* @param {string} mountUrl Prefix for all URLs in the browser address bar
|
|
137
79
|
* @throws {SyntaxError} For invalid URL.
|
|
138
|
-
* @returns {string} Sanitised URL.
|
|
80
|
+
* @returns {string|undefined} Sanitised URL.
|
|
139
81
|
*/
|
|
140
|
-
function validateMountUrl(mountUrl
|
|
82
|
+
function validateMountUrl(mountUrl) {
|
|
141
83
|
if (typeof mountUrl === 'undefined') {
|
|
142
|
-
return
|
|
84
|
+
return undefined;
|
|
143
85
|
}
|
|
144
86
|
if (!mountUrl.match(/\/$/)) {
|
|
145
|
-
throw new SyntaxError(
|
|
87
|
+
throw new SyntaxError('mountUrl must include a trailing slash (/)');
|
|
146
88
|
}
|
|
147
89
|
return mountUrl;
|
|
148
90
|
}
|
|
@@ -155,7 +97,7 @@ exports.validateMountUrl = validateMountUrl;
|
|
|
155
97
|
* @throws {TypeError} For invalid object.
|
|
156
98
|
* @returns {object} Sanitised sessions object.
|
|
157
99
|
*/
|
|
158
|
-
function validateSessionObject(session, cb = echo) {
|
|
100
|
+
function validateSessionObject(session = Object.create(null), cb = echo) {
|
|
159
101
|
if (session === undefined) {
|
|
160
102
|
return cb(session);
|
|
161
103
|
}
|
|
@@ -173,11 +115,8 @@ exports.validateSessionObject = validateSessionObject;
|
|
|
173
115
|
* @throws {TypeError} For invalid type.
|
|
174
116
|
* @returns {Array} Array of directories.
|
|
175
117
|
*/
|
|
176
|
-
function validateViews(dirs) {
|
|
177
|
-
if (
|
|
178
|
-
throw ReferenceError('View directories are missing (views)');
|
|
179
|
-
}
|
|
180
|
-
else if (!Array.isArray(dirs)) {
|
|
118
|
+
function validateViews(dirs = []) {
|
|
119
|
+
if (!Array.isArray(dirs)) {
|
|
181
120
|
throw new TypeError('View directories must be an array (views)');
|
|
182
121
|
}
|
|
183
122
|
dirs.forEach((dir, i) => {
|
|
@@ -214,11 +153,8 @@ exports.validateSessionSecret = validateSessionSecret;
|
|
|
214
153
|
* @throws {TypeError} For invalid value.
|
|
215
154
|
* @returns {number} Ttl.
|
|
216
155
|
*/
|
|
217
|
-
function validateSessionTtl(ttl) {
|
|
218
|
-
if (typeof ttl
|
|
219
|
-
throw ReferenceError('Session ttl is missing (session.ttl)');
|
|
220
|
-
}
|
|
221
|
-
else if (typeof ttl !== 'number') {
|
|
156
|
+
function validateSessionTtl(ttl = 3600) {
|
|
157
|
+
if (typeof ttl !== 'number') {
|
|
222
158
|
throw new TypeError('Session ttl must be an integer (session.ttl)');
|
|
223
159
|
}
|
|
224
160
|
return ttl;
|
|
@@ -227,16 +163,13 @@ exports.validateSessionTtl = validateSessionTtl;
|
|
|
227
163
|
/**
|
|
228
164
|
* Validates and sanitises sessions name.
|
|
229
165
|
*
|
|
230
|
-
* @param {string} name Session name.
|
|
166
|
+
* @param {string} [name=casa-session] Session name.
|
|
231
167
|
* @throws {ReferenceError} For missing value type.
|
|
232
168
|
* @throws {TypeError} For invalid value.
|
|
233
169
|
* @returns {string} Name.
|
|
234
170
|
*/
|
|
235
|
-
function validateSessionName(name) {
|
|
236
|
-
if (typeof name
|
|
237
|
-
throw ReferenceError('Session name is missing (session.name)');
|
|
238
|
-
}
|
|
239
|
-
else if (typeof name !== 'string') {
|
|
171
|
+
function validateSessionName(name = 'casa-session') {
|
|
172
|
+
if (typeof name !== 'string') {
|
|
240
173
|
throw new TypeError('Session name must be a string (session.name)');
|
|
241
174
|
}
|
|
242
175
|
return name;
|
|
@@ -245,16 +178,13 @@ exports.validateSessionName = validateSessionName;
|
|
|
245
178
|
/**
|
|
246
179
|
* Validates and sanitises sessions secure flag.
|
|
247
180
|
*
|
|
248
|
-
* @param {boolean} secure Session secure flag.
|
|
181
|
+
* @param {boolean} [secure=false] Session secure flag.
|
|
249
182
|
* @throws {ReferenceError} For missing value type.
|
|
250
183
|
* @throws {TypeError} For invalid value.
|
|
251
184
|
* @returns {string} Name.
|
|
252
185
|
*/
|
|
253
|
-
function validateSessionSecure(secure) {
|
|
254
|
-
if (typeof secure
|
|
255
|
-
throw ReferenceError('Session secure flag is missing (session.secure)');
|
|
256
|
-
}
|
|
257
|
-
else if (typeof secure !== 'boolean') {
|
|
186
|
+
function validateSessionSecure(secure = false) {
|
|
187
|
+
if (typeof secure !== 'boolean') {
|
|
258
188
|
throw new TypeError('Session secure flag must be boolean (session.secure)');
|
|
259
189
|
}
|
|
260
190
|
return secure;
|
|
@@ -371,7 +301,7 @@ const validatePage = (page, index) => {
|
|
|
371
301
|
throw err;
|
|
372
302
|
}
|
|
373
303
|
};
|
|
374
|
-
function validatePages(pages) {
|
|
304
|
+
function validatePages(pages = []) {
|
|
375
305
|
if (!Array.isArray(pages)) {
|
|
376
306
|
throw new TypeError('Pages must be an array (pages)');
|
|
377
307
|
}
|
|
@@ -451,7 +381,7 @@ function ingest(config = {}) {
|
|
|
451
381
|
dirs: validateI18nDirs(i18n.dirs),
|
|
452
382
|
locales: validateI18nLocales(i18n.locales),
|
|
453
383
|
})),
|
|
454
|
-
//
|
|
384
|
+
// URL that will prefix all URLs in the browser address bar
|
|
455
385
|
mountUrl: validateMountUrl(config.mountUrl),
|
|
456
386
|
// Session
|
|
457
387
|
session: validateSessionObject(config.session, (session) => ({
|
package/dist/lib/configure.d.ts
CHANGED
|
@@ -1,90 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {import('
|
|
2
|
+
* @typedef {import('../casa').ConfigurationOptions} ConfigurationOptions
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @typedef {import('
|
|
5
|
+
* @typedef {import('../casa').ConfigurationOptions} ConfigureResult
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
* @typedef {import('
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {object} ConfigureResult Result of a call to configure() function
|
|
12
|
-
* @property {nunjucks.Environment} nunjucksEnv Nunjucks environment
|
|
13
|
-
* @property {MutableRouter} staticRouter Router handling all static assets
|
|
14
|
-
* @property {MutableRouter} ancillaryRouter Router handling ancillary routes
|
|
15
|
-
* @property {MutableRouter} journeyRouter Router handling all waypoint requests
|
|
16
|
-
* @property {ExpressRequestHandler[]} preMiddleware Middleware mounted before anything else
|
|
17
|
-
* @property {ExpressRequestHandler[]} postMiddleware Middleware mounted after everything else
|
|
18
|
-
* @property {ExpressRequestHandler[]} csrfMiddleware CSRF get/set middleware (useful for forms)
|
|
19
|
-
* @property {ExpressRequestHandler} sessionMiddleware Session middleware
|
|
20
|
-
* @property {ExpressRequestHandler[]} cookieParserMiddleware Cookie-parsing middleware
|
|
21
|
-
* @property {ExpressRequestHandler[]} i18nMiddleware I18n preparation middleware
|
|
22
|
-
* @property {ExpressRequestHandler} bodyParserMiddleware Body parsing middleware
|
|
23
|
-
* @property {Function} mount Function used to mount all CASA artifacts onto an ExpressJS app
|
|
8
|
+
* @typedef {import('../casa').Mounter} Mounter
|
|
24
9
|
*/
|
|
25
10
|
/**
|
|
26
11
|
* Configure some middleware for use in creating a new CASA app.
|
|
27
12
|
*
|
|
28
|
-
* `mountUrl` is used to ensure the CSS content uses the correct reference to
|
|
29
|
-
* static assets in the `govuk-frontend` module.
|
|
30
|
-
*
|
|
31
13
|
* @param {ConfigurationOptions} config Configuration options
|
|
32
14
|
* @returns {ConfigureResult} Result
|
|
33
15
|
*/
|
|
34
16
|
export default function configure(config?: ConfigurationOptions): ConfigureResult;
|
|
35
|
-
export type
|
|
36
|
-
export type
|
|
37
|
-
export type
|
|
38
|
-
/**
|
|
39
|
-
* Result of a call to configure() function
|
|
40
|
-
*/
|
|
41
|
-
export type ConfigureResult = {
|
|
42
|
-
/**
|
|
43
|
-
* Nunjucks environment
|
|
44
|
-
*/
|
|
45
|
-
nunjucksEnv: nunjucks.Environment;
|
|
46
|
-
/**
|
|
47
|
-
* Router handling all static assets
|
|
48
|
-
*/
|
|
49
|
-
staticRouter: MutableRouter;
|
|
50
|
-
/**
|
|
51
|
-
* Router handling ancillary routes
|
|
52
|
-
*/
|
|
53
|
-
ancillaryRouter: MutableRouter;
|
|
54
|
-
/**
|
|
55
|
-
* Router handling all waypoint requests
|
|
56
|
-
*/
|
|
57
|
-
journeyRouter: MutableRouter;
|
|
58
|
-
/**
|
|
59
|
-
* Middleware mounted before anything else
|
|
60
|
-
*/
|
|
61
|
-
preMiddleware: ExpressRequestHandler[];
|
|
62
|
-
/**
|
|
63
|
-
* Middleware mounted after everything else
|
|
64
|
-
*/
|
|
65
|
-
postMiddleware: ExpressRequestHandler[];
|
|
66
|
-
/**
|
|
67
|
-
* CSRF get/set middleware (useful for forms)
|
|
68
|
-
*/
|
|
69
|
-
csrfMiddleware: ExpressRequestHandler[];
|
|
70
|
-
/**
|
|
71
|
-
* Session middleware
|
|
72
|
-
*/
|
|
73
|
-
sessionMiddleware: ExpressRequestHandler;
|
|
74
|
-
/**
|
|
75
|
-
* Cookie-parsing middleware
|
|
76
|
-
*/
|
|
77
|
-
cookieParserMiddleware: ExpressRequestHandler[];
|
|
78
|
-
/**
|
|
79
|
-
* I18n preparation middleware
|
|
80
|
-
*/
|
|
81
|
-
i18nMiddleware: ExpressRequestHandler[];
|
|
82
|
-
/**
|
|
83
|
-
* Body parsing middleware
|
|
84
|
-
*/
|
|
85
|
-
bodyParserMiddleware: ExpressRequestHandler;
|
|
86
|
-
/**
|
|
87
|
-
* Function used to mount all CASA artifacts onto an ExpressJS app
|
|
88
|
-
*/
|
|
89
|
-
mount: Function;
|
|
90
|
-
};
|
|
17
|
+
export type ConfigurationOptions = import('../casa').ConfigurationOptions;
|
|
18
|
+
export type ConfigureResult = import('../casa').ConfigurationOptions;
|
|
19
|
+
export type Mounter = import('../casa').Mounter;
|