@dwp/govuk-casa 8.2.2 → 8.2.5

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +1 -0
  3. package/dist/casa.d.ts +212 -5
  4. package/dist/casa.js +144 -8
  5. package/dist/lib/CasaTemplateLoader.d.ts +4 -0
  6. package/dist/lib/CasaTemplateLoader.js +5 -0
  7. package/dist/lib/JourneyContext.d.ts +85 -13
  8. package/dist/lib/JourneyContext.js +103 -16
  9. package/dist/lib/Plan.d.ts +122 -49
  10. package/dist/lib/Plan.js +161 -37
  11. package/dist/lib/ValidationError.d.ts +38 -48
  12. package/dist/lib/ValidationError.js +30 -42
  13. package/dist/lib/ValidatorFactory.d.ts +42 -52
  14. package/dist/lib/ValidatorFactory.js +37 -48
  15. package/dist/lib/configuration-ingestor.d.ts +15 -0
  16. package/dist/lib/configuration-ingestor.js +17 -0
  17. package/dist/lib/configure.d.ts +4 -0
  18. package/dist/lib/configure.js +18 -2
  19. package/dist/lib/end-session.d.ts +3 -2
  20. package/dist/lib/end-session.js +2 -1
  21. package/dist/lib/field.d.ts +97 -35
  22. package/dist/lib/field.js +90 -41
  23. package/dist/lib/nunjucks-filters.d.ts +12 -2
  24. package/dist/lib/nunjucks-filters.js +11 -1
  25. package/dist/lib/nunjucks.d.ts +1 -0
  26. package/dist/lib/nunjucks.js +1 -0
  27. package/dist/lib/utils.d.ts +46 -14
  28. package/dist/lib/utils.js +44 -27
  29. package/dist/lib/validators/dateObject.d.ts +75 -1
  30. package/dist/lib/validators/dateObject.js +29 -18
  31. package/dist/lib/validators/email.d.ts +28 -1
  32. package/dist/lib/validators/email.js +20 -9
  33. package/dist/lib/validators/inArray.d.ts +34 -1
  34. package/dist/lib/validators/inArray.js +21 -0
  35. package/dist/lib/validators/index.js +3 -0
  36. package/dist/lib/validators/nino.d.ts +34 -1
  37. package/dist/lib/validators/nino.js +17 -7
  38. package/dist/lib/validators/postalAddressObject.d.ts +68 -1
  39. package/dist/lib/validators/postalAddressObject.js +27 -15
  40. package/dist/lib/validators/regex.d.ts +35 -1
  41. package/dist/lib/validators/regex.js +17 -7
  42. package/dist/lib/validators/required.d.ts +28 -1
  43. package/dist/lib/validators/required.js +19 -6
  44. package/dist/lib/validators/strlen.d.ts +40 -1
  45. package/dist/lib/validators/strlen.js +18 -8
  46. package/dist/lib/validators/wordCount.d.ts +40 -1
  47. package/dist/lib/validators/wordCount.js +18 -8
  48. package/dist/lib/waypoint-url.d.ts +1 -0
  49. package/dist/lib/waypoint-url.js +10 -0
  50. package/dist/middleware/data.js +21 -5
  51. package/dist/middleware/gather-fields.js +1 -0
  52. package/dist/middleware/pre.js +1 -0
  53. package/dist/middleware/steer-journey.js +2 -1
  54. package/dist/middleware/strip-proxy-path.js +6 -2
  55. package/dist/middleware/validate-fields.js +3 -0
  56. package/dist/routes/ancillary.d.ts +16 -5
  57. package/dist/routes/ancillary.js +7 -3
  58. package/dist/routes/journey.d.ts +30 -6
  59. package/dist/routes/journey.js +27 -0
  60. package/dist/routes/static.d.ts +1 -0
  61. package/dist/routes/static.js +2 -1
  62. package/package.json +16 -11
  63. package/views/casa/components/character-count/README.md +1 -1
  64. package/views/casa/components/input/README.md +1 -1
  65. package/views/casa/components/radios/README.md +2 -2
  66. package/views/casa/components/textarea/README.md +1 -1
@@ -1,83 +1,73 @@
1
1
  /**
2
- * @typedef {import('./index').ProcessorFunction} ProcessorFunction
2
+ * @access private
3
+ * @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
3
4
  */
4
5
  /**
6
+ * @access private
5
7
  * @typedef {import('./index').JourneyContext} JourneyContext
6
8
  */
7
9
  /**
10
+ * @access private
8
11
  * @typedef {import('./index').ValidationError} ValidationError
9
12
  */
10
13
  /**
11
- * @typedef {object} Validator
12
- * @property {ValidateFunction} validate Validation function
13
- * @property {ProcessorFunction} sanitise Sanitise a given value prior to validation
14
- * @property {object} config Configuration
15
- * @property {string} name Validator name
14
+ * @access private
15
+ * @typedef {import('../casa').ValidateContext} ValidateContext
16
16
  */
17
17
  /**
18
- * @callback ValidateFunction
19
- * @param {any} value
20
- * @param {ValidateContext} context
21
- * @returns {ValidationError[]}
18
+ * @access private
19
+ * @typedef {import('../casa').Validator} Validator
22
20
  */
23
21
  /**
24
- * @typedef {object} ValidateContext Context passed to validate function
25
- * @property {JourneyContext} journeyContext Journey context
26
- * @property {string} waypoint Waypoint
27
- * @property {string} fieldName Name of field being processed
22
+ * @typedef {object} ValidatorFactoryOptions
23
+ * @property {ErrorMessageConfig} errorMsg Error message
24
+ */
25
+ /**
26
+ * @class
27
+ * @memberof module:@dwp/govuk-casa
28
28
  */
29
29
  export default class ValidatorFactory {
30
30
  /**
31
31
  * This is a convenience method that will return a consistently object
32
32
  * structure containing validation and sanitisation methods.
33
33
  *
34
- * @param {object} config Validator config (custom to the validator being created)
34
+ * @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
35
35
  * @returns {Validator} Validator object
36
36
  * @throws {TypeError} When configurarion is invalid.
37
37
  */
38
- static make(config?: object): Validator;
39
- static coerceToValidatorObject(input: any): any;
40
- constructor(config?: {});
41
- config: {};
42
- validate(fieldValue: any, context: any): void;
43
- sanitise(fieldValue: any): any;
44
- }
45
- export type ProcessorFunction = import('./index').ProcessorFunction;
46
- export type JourneyContext = import('./index').JourneyContext;
47
- export type ValidationError = import('./index').ValidationError;
48
- export type Validator = {
49
- /**
50
- * Validation function
51
- */
52
- validate: ValidateFunction;
53
- /**
54
- * Sanitise a given value prior to validation
55
- */
56
- sanitise: any;
57
- /**
58
- * Configuration
59
- */
60
- config: object;
38
+ static make(config?: ValidatorFactoryOptions): Validator;
61
39
  /**
62
- * Validator name
40
+ * NEVER CALL THIS DIRECTLY. USE `make()`.
41
+ *
42
+ * @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
63
43
  */
64
- name: string;
65
- };
66
- export type ValidateFunction = (value: any, context: ValidateContext) => ValidationError[];
67
- /**
68
- * Context passed to validate function
69
- */
70
- export type ValidateContext = {
44
+ constructor(config?: ValidatorFactoryOptions);
45
+ config: ValidatorFactoryOptions;
71
46
  /**
72
- * Journey context
47
+ * Validate the given value.
48
+ *
49
+ * @param {any} fieldValue Value to validate
50
+ * @param {ValidateContext} context Contextual information
51
+ * @returns {ValidationError[]} A list of errors (empty if no errors found)
52
+ * @throws {Error}
73
53
  */
74
- journeyContext: JourneyContext;
54
+ validate(fieldValue: any, context: ValidateContext): ValidationError[];
75
55
  /**
76
- * Waypoint
56
+ * Sanitise the given value.
57
+ *
58
+ * @param {any} fieldValue Value to validate
59
+ * @returns {any} The sanitised value
77
60
  */
78
- waypoint: string;
61
+ sanitise(fieldValue: any): any;
62
+ }
63
+ export type ErrorMessageConfig = import('../casa').ErrorMessageConfig;
64
+ export type JourneyContext = import('./index').JourneyContext;
65
+ export type ValidationError = import('./index').ValidationError;
66
+ export type ValidateContext = import('../casa').ValidateContext;
67
+ export type Validator = import('../casa').Validator;
68
+ export type ValidatorFactoryOptions = {
79
69
  /**
80
- * Name of field being processed
70
+ * Error message
81
71
  */
82
- fieldName: string;
72
+ errorMsg: ErrorMessageConfig;
83
73
  };
@@ -7,39 +7,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const { isPlainObject } = lodash_1.default; // CommonJS
9
9
  /**
10
- * @typedef {import('./index').ProcessorFunction} ProcessorFunction
10
+ * @access private
11
+ * @typedef {import('../casa').ErrorMessageConfig} ErrorMessageConfig
11
12
  */
12
13
  /**
14
+ * @access private
13
15
  * @typedef {import('./index').JourneyContext} JourneyContext
14
16
  */
15
17
  /**
18
+ * @access private
16
19
  * @typedef {import('./index').ValidationError} ValidationError
17
20
  */
18
21
  /**
19
- * @typedef {object} Validator
20
- * @property {ValidateFunction} validate Validation function
21
- * @property {ProcessorFunction} sanitise Sanitise a given value prior to validation
22
- * @property {object} config Configuration
23
- * @property {string} name Validator name
22
+ * @access private
23
+ * @typedef {import('../casa').ValidateContext} ValidateContext
24
24
  */
25
25
  /**
26
- * @callback ValidateFunction
27
- * @param {any} value
28
- * @param {ValidateContext} context
29
- * @returns {ValidationError[]}
26
+ * @access private
27
+ * @typedef {import('../casa').Validator} Validator
30
28
  */
31
29
  /**
32
- * @typedef {object} ValidateContext Context passed to validate function
33
- * @property {JourneyContext} journeyContext Journey context
34
- * @property {string} waypoint Waypoint
35
- * @property {string} fieldName Name of field being processed
30
+ * @typedef {object} ValidatorFactoryOptions
31
+ * @property {ErrorMessageConfig} errorMsg Error message
32
+ */
33
+ /**
34
+ * @class
35
+ * @memberof module:@dwp/govuk-casa
36
36
  */
37
37
  class ValidatorFactory {
38
38
  /**
39
39
  * This is a convenience method that will return a consistently object
40
40
  * structure containing validation and sanitisation methods.
41
41
  *
42
- * @param {object} config Validator config (custom to the validator being created)
42
+ * @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
43
43
  * @returns {Validator} Validator object
44
44
  * @throws {TypeError} When configurarion is invalid.
45
45
  */
@@ -57,48 +57,37 @@ class ValidatorFactory {
57
57
  Object.freeze(instance);
58
58
  return instance;
59
59
  }
60
- static coerceToValidatorObject(input) {
61
- let validator = Object.create(null);
62
- validator.validate = () => (Promise.reject(new Error('validate() method has not been defined')));
63
- validator.sanitise = (val) => (val);
64
- validator.config = Object.create(null);
65
- // An uninstantied Validator subclass
66
- if (typeof input === 'function' && Reflect.getPrototypeOf(input) === ValidatorFactory) {
67
- validator = input.make();
68
- }
69
- else if (typeof input === 'function') {
70
- // A plain function is assumed to be just the validation logic. We do not
71
- // bind the function to `validator` here because it may already be bound to
72
- // another context in userland.
73
- validator.name = input.name || input.constructor.name || 'unknown';
74
- validator.validate = input;
75
- }
76
- else if (isPlainObject(input)) {
77
- // A plain object
78
- validator = {
79
- validate: input.validate || validator.validate,
80
- sanitise: input.sanitise || validator.sanitise,
81
- config: input.config || validator.config,
82
- name: input.name || validator.name,
83
- };
84
- }
85
- else {
86
- // An unsupported scenario
87
- throw new TypeError(`Cannot coerce input to a validator object (typeof = ${typeof input})`);
88
- }
89
- return validator;
90
- }
60
+ /**
61
+ * NEVER CALL THIS DIRECTLY. USE `make()`.
62
+ *
63
+ * @param {ValidatorFactoryOptions} config Validator config (custom to each validator)
64
+ */
91
65
  constructor(config = {}) {
92
66
  if (new.target === ValidatorFactory) {
93
67
  throw new TypeError('Cannot instantiate the abstract class, ValidatorFactory');
94
68
  }
95
69
  this.config = config;
96
70
  }
97
- /* eslint-disable-next-line no-unused-vars */
71
+ /* eslint-disable no-unused-vars */
72
+ /* eslint-disable-next-line jsdoc/require-returns-check */
73
+ /**
74
+ * Validate the given value.
75
+ *
76
+ * @param {any} fieldValue Value to validate
77
+ * @param {ValidateContext} context Contextual information
78
+ * @returns {ValidationError[]} A list of errors (empty if no errors found)
79
+ * @throws {Error}
80
+ */
98
81
  validate(fieldValue, context) {
99
82
  throw new Error('validate() method has not been implemented');
100
83
  }
101
- /* eslint-disable-next-line no-unused-vars */
84
+ /* eslint-disable-next-line jsdoc/require-returns-check */
85
+ /**
86
+ * Sanitise the given value.
87
+ *
88
+ * @param {any} fieldValue Value to validate
89
+ * @returns {any} The sanitised value
90
+ */
102
91
  sanitise(fieldValue) {
103
92
  return fieldValue;
104
93
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Validates and sanitises i18n obejct.
3
3
  *
4
+ * @access private
4
5
  * @param {object} i18n Object to validate.
5
6
  * @param {Function} cb Callback function that receives the validated value.
6
7
  * @throws {TypeError} For invalid object.
@@ -10,6 +11,7 @@ export function validateI18nObject(i18n?: object, cb?: Function): object;
10
11
  /**
11
12
  * Validates and sanitises i18n directory.
12
13
  *
14
+ * @access private
13
15
  * @param {Array} dirs Array of directories.
14
16
  * @throws {SyntaxError} For invalid directories.
15
17
  * @throws {TypeError} For invalid type.
@@ -19,6 +21,7 @@ export function validateI18nDirs(dirs?: any[]): any[];
19
21
  /**
20
22
  * Validates and sanitises i18n locales.
21
23
  *
24
+ * @access private
22
25
  * @param {Array} locales Array of locales.
23
26
  * @throws {SyntaxError} For invalid locales.
24
27
  * @throws {TypeError} For invalid type.
@@ -28,6 +31,7 @@ export function validateI18nLocales(locales?: any[]): any[];
28
31
  /**
29
32
  * Validates and sanitises mount url.
30
33
  *
34
+ * @access private
31
35
  * @param {string} mountUrl Prefix for all URLs in the browser address bar
32
36
  * @throws {SyntaxError} For invalid URL.
33
37
  * @returns {string|undefined} Sanitised URL.
@@ -36,6 +40,7 @@ export function validateMountUrl(mountUrl: string): string | undefined;
36
40
  /**
37
41
  * Validates and sanitises sessions object.
38
42
  *
43
+ * @access private
39
44
  * @param {object} session Object to validate.
40
45
  * @param {Function} cb Callback function that receives the validated value.
41
46
  * @throws {TypeError} For invalid object.
@@ -45,6 +50,7 @@ export function validateSessionObject(session?: object, cb?: Function): object;
45
50
  /**
46
51
  * Validates and sanitises view directory.
47
52
  *
53
+ * @access private
48
54
  * @param {Array} dirs Array of directories.
49
55
  * @throws {SyntaxError} For invalid directories.
50
56
  * @throws {TypeError} For invalid type.
@@ -54,6 +60,7 @@ export function validateViews(dirs?: any[]): any[];
54
60
  /**
55
61
  * Validates and sanitises sessions secret.
56
62
  *
63
+ * @access private
57
64
  * @param {string} secret Session secret.
58
65
  * @throws {ReferenceError} For missing value type.
59
66
  * @throws {TypeError} For invalid value.
@@ -63,6 +70,7 @@ export function validateSessionSecret(secret: string): string;
63
70
  /**
64
71
  * Validates and sanitises sessions ttl.
65
72
  *
73
+ * @access private
66
74
  * @param {number} ttl Session ttl (seconds).
67
75
  * @throws {ReferenceError} For missing value type.
68
76
  * @throws {TypeError} For invalid value.
@@ -72,6 +80,7 @@ export function validateSessionTtl(ttl?: number): number;
72
80
  /**
73
81
  * Validates and sanitises sessions name.
74
82
  *
83
+ * @access private
75
84
  * @param {string} [name=casa-session] Session name.
76
85
  * @throws {ReferenceError} For missing value type.
77
86
  * @throws {TypeError} For invalid value.
@@ -81,6 +90,7 @@ export function validateSessionName(name?: string | undefined): string;
81
90
  /**
82
91
  * Validates and sanitises sessions secure flag.
83
92
  *
93
+ * @access private
84
94
  * @param {boolean} [secure=false] Session secure flag.
85
95
  * @throws {ReferenceError} For missing value type.
86
96
  * @throws {TypeError} For invalid value.
@@ -90,6 +100,7 @@ export function validateSessionSecure(secure?: boolean | undefined): string;
90
100
  /**
91
101
  * Validates and sanitises sessions store.
92
102
  *
103
+ * @access private
93
104
  * @param {Function} store Session store.
94
105
  * @returns {Function} Store.
95
106
  */
@@ -97,6 +108,7 @@ export function validateSessionStore(store: Function): Function;
97
108
  /**
98
109
  * Validates and sanitises sessions cookie url path.
99
110
  *
111
+ * @access private
100
112
  * @param {string} cookiePath Session cookie url path.
101
113
  * @param {string} defaultPath Default path if none specified.
102
114
  * @returns {string} Cookie path.
@@ -110,6 +122,7 @@ export function validateSessionCookiePath(cookiePath: string, defaultPath?: stri
110
122
  * Lax
111
123
  * None
112
124
  *
125
+ * @access private
113
126
  * @param {any} cookieSameSite Session cookie "sameSite" flag
114
127
  * @param {any} defaultFlag Default path if none specified
115
128
  * @returns {boolean} cookie path
@@ -126,6 +139,7 @@ export function validateEvents(events: any): any;
126
139
  /**
127
140
  * Validates helmet configuration function.
128
141
  *
142
+ * @access private
129
143
  * @param {HelmetConfigurator} helmetConfigurator Configuration function
130
144
  * @returns {HelmetConfigurator} Validated configuration function
131
145
  * @throws {TypeError} when passed a non-function
@@ -134,6 +148,7 @@ export function validateHelmetConfigurator(helmetConfigurator: HelmetConfigurato
134
148
  /**
135
149
  * Ingest, validate, sanitise and manipulate configuration parameters.
136
150
  *
151
+ * @access private
137
152
  * @param {ConfigurationOptions} config Config to ingest.
138
153
  * @throws {Error|SyntaxError|TypeError} For invalid config values.
139
154
  * @returns {object} Immutable config object.
@@ -10,9 +10,11 @@ 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
+ * @access private
13
14
  * @typedef {import('../casa').ConfigurationOptions} ConfigurationOptions
14
15
  */
15
16
  /**
17
+ * @access private
16
18
  * @typedef {import('../casa').HelmetConfigurator} HelmetConfigurator
17
19
  */
18
20
  const log = (0, logger_js_1.default)('lib:configuration-ingestor');
@@ -20,6 +22,7 @@ const echo = (a) => (a);
20
22
  /**
21
23
  * Validates and sanitises i18n obejct.
22
24
  *
25
+ * @access private
23
26
  * @param {object} i18n Object to validate.
24
27
  * @param {Function} cb Callback function that receives the validated value.
25
28
  * @throws {TypeError} For invalid object.
@@ -35,6 +38,7 @@ exports.validateI18nObject = validateI18nObject;
35
38
  /**
36
39
  * Validates and sanitises i18n directory.
37
40
  *
41
+ * @access private
38
42
  * @param {Array} dirs Array of directories.
39
43
  * @throws {SyntaxError} For invalid directories.
40
44
  * @throws {TypeError} For invalid type.
@@ -55,6 +59,7 @@ exports.validateI18nDirs = validateI18nDirs;
55
59
  /**
56
60
  * Validates and sanitises i18n locales.
57
61
  *
62
+ * @access private
58
63
  * @param {Array} locales Array of locales.
59
64
  * @throws {SyntaxError} For invalid locales.
60
65
  * @throws {TypeError} For invalid type.
@@ -75,6 +80,7 @@ exports.validateI18nLocales = validateI18nLocales;
75
80
  /**
76
81
  * Validates and sanitises mount url.
77
82
  *
83
+ * @access private
78
84
  * @param {string} mountUrl Prefix for all URLs in the browser address bar
79
85
  * @throws {SyntaxError} For invalid URL.
80
86
  * @returns {string|undefined} Sanitised URL.
@@ -92,6 +98,7 @@ exports.validateMountUrl = validateMountUrl;
92
98
  /**
93
99
  * Validates and sanitises sessions object.
94
100
  *
101
+ * @access private
95
102
  * @param {object} session Object to validate.
96
103
  * @param {Function} cb Callback function that receives the validated value.
97
104
  * @throws {TypeError} For invalid object.
@@ -110,6 +117,7 @@ exports.validateSessionObject = validateSessionObject;
110
117
  /**
111
118
  * Validates and sanitises view directory.
112
119
  *
120
+ * @access private
113
121
  * @param {Array} dirs Array of directories.
114
122
  * @throws {SyntaxError} For invalid directories.
115
123
  * @throws {TypeError} For invalid type.
@@ -130,6 +138,7 @@ exports.validateViews = validateViews;
130
138
  /**
131
139
  * Validates and sanitises sessions secret.
132
140
  *
141
+ * @access private
133
142
  * @param {string} secret Session secret.
134
143
  * @throws {ReferenceError} For missing value type.
135
144
  * @throws {TypeError} For invalid value.
@@ -148,6 +157,7 @@ exports.validateSessionSecret = validateSessionSecret;
148
157
  /**
149
158
  * Validates and sanitises sessions ttl.
150
159
  *
160
+ * @access private
151
161
  * @param {number} ttl Session ttl (seconds).
152
162
  * @throws {ReferenceError} For missing value type.
153
163
  * @throws {TypeError} For invalid value.
@@ -163,6 +173,7 @@ exports.validateSessionTtl = validateSessionTtl;
163
173
  /**
164
174
  * Validates and sanitises sessions name.
165
175
  *
176
+ * @access private
166
177
  * @param {string} [name=casa-session] Session name.
167
178
  * @throws {ReferenceError} For missing value type.
168
179
  * @throws {TypeError} For invalid value.
@@ -178,6 +189,7 @@ exports.validateSessionName = validateSessionName;
178
189
  /**
179
190
  * Validates and sanitises sessions secure flag.
180
191
  *
192
+ * @access private
181
193
  * @param {boolean} [secure=false] Session secure flag.
182
194
  * @throws {ReferenceError} For missing value type.
183
195
  * @throws {TypeError} For invalid value.
@@ -193,6 +205,7 @@ exports.validateSessionSecure = validateSessionSecure;
193
205
  /**
194
206
  * Validates and sanitises sessions store.
195
207
  *
208
+ * @access private
196
209
  * @param {Function} store Session store.
197
210
  * @returns {Function} Store.
198
211
  */
@@ -207,6 +220,7 @@ exports.validateSessionStore = validateSessionStore;
207
220
  /**
208
221
  * Validates and sanitises sessions cookie url path.
209
222
  *
223
+ * @access private
210
224
  * @param {string} cookiePath Session cookie url path.
211
225
  * @param {string} defaultPath Default path if none specified.
212
226
  * @returns {string} Cookie path.
@@ -226,6 +240,7 @@ exports.validateSessionCookiePath = validateSessionCookiePath;
226
240
  * Lax
227
241
  * None
228
242
  *
243
+ * @access private
229
244
  * @param {any} cookieSameSite Session cookie "sameSite" flag
230
245
  * @param {any} defaultFlag Default path if none specified
231
246
  * @returns {boolean} cookie path
@@ -356,6 +371,7 @@ exports.validateEvents = validateEvents;
356
371
  /**
357
372
  * Validates helmet configuration function.
358
373
  *
374
+ * @access private
359
375
  * @param {HelmetConfigurator} helmetConfigurator Configuration function
360
376
  * @returns {HelmetConfigurator} Validated configuration function
361
377
  * @throws {TypeError} when passed a non-function
@@ -370,6 +386,7 @@ exports.validateHelmetConfigurator = validateHelmetConfigurator;
370
386
  /**
371
387
  * Ingest, validate, sanitise and manipulate configuration parameters.
372
388
  *
389
+ * @access private
373
390
  * @param {ConfigurationOptions} config Config to ingest.
374
391
  * @throws {Error|SyntaxError|TypeError} For invalid config values.
375
392
  * @returns {object} Immutable config object.
@@ -1,15 +1,19 @@
1
1
  /**
2
+ * @access private
2
3
  * @typedef {import('../casa').ConfigurationOptions} ConfigurationOptions
3
4
  */
4
5
  /**
6
+ * @access private
5
7
  * @typedef {import('../casa').ConfigurationOptions} ConfigureResult
6
8
  */
7
9
  /**
10
+ * @access private
8
11
  * @typedef {import('../casa').Mounter} Mounter
9
12
  */
10
13
  /**
11
14
  * Configure some middleware for use in creating a new CASA app.
12
15
  *
16
+ * @memberof module:@dwp/govuk-casa
13
17
  * @param {ConfigurationOptions} config Configuration options
14
18
  * @returns {ConfigureResult} Result
15
19
  */
@@ -25,17 +25,21 @@ const data_js_1 = __importDefault(require("../middleware/data.js"));
25
25
  const body_parser_js_1 = __importDefault(require("../middleware/body-parser.js"));
26
26
  const csrf_js_1 = __importDefault(require("../middleware/csrf.js"));
27
27
  /**
28
+ * @access private
28
29
  * @typedef {import('../casa').ConfigurationOptions} ConfigurationOptions
29
30
  */
30
31
  /**
32
+ * @access private
31
33
  * @typedef {import('../casa').ConfigurationOptions} ConfigureResult
32
34
  */
33
35
  /**
36
+ * @access private
34
37
  * @typedef {import('../casa').Mounter} Mounter
35
38
  */
36
39
  /**
37
40
  * Configure some middleware for use in creating a new CASA app.
38
41
  *
42
+ * @memberof module:@dwp/govuk-casa
39
43
  * @param {ConfigurationOptions} config Configuration options
40
44
  * @returns {ConfigureResult} Result
41
45
  */
@@ -47,6 +51,7 @@ function configure(config = {}) {
47
51
  plugin.configure(config);
48
52
  });
49
53
  // Extract config
54
+ const ingestedConfig = (0, configuration_ingestor_js_1.default)(config);
50
55
  const { mountUrl, views = [], session = {
51
56
  secret: 'secret',
52
57
  name: 'casasession',
@@ -58,7 +63,7 @@ function configure(config = {}) {
58
63
  }, pages = [], plan = null, hooks = [], plugins = [], events = [], i18n = {
59
64
  dirs: [],
60
65
  locales: ['en', 'cy'],
61
- }, helmetConfigurator = undefined, } = (0, configuration_ingestor_js_1.default)(config);
66
+ }, helmetConfigurator = undefined, } = ingestedConfig;
62
67
  // Prepare all page hooks so they are prefixed with the `journey.` scope.
63
68
  pages.forEach((page) => {
64
69
  var _a;
@@ -150,7 +155,16 @@ function configure(config = {}) {
150
155
  res.redirect(302, `${reqPath}${reqParams}`);
151
156
  });
152
157
  }
153
- // Service static assets from the `app` rather than the `router`. The router
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
154
168
  // may contain paramaterised path segments which would mean serving static
155
169
  // assets over a dynamic URL each time, thus causing lots of cache misses on
156
170
  // the browser.
@@ -201,6 +215,8 @@ function configure(config = {}) {
201
215
  dataMiddleware,
202
216
  // Mount function
203
217
  mount,
218
+ // Ingested config
219
+ config: ingestedConfig,
204
220
  };
205
221
  // Bootstrap all plugins
206
222
  plugins.filter((p) => p.bootstrap).forEach((plugin) => plugin === null || plugin === void 0 ? void 0 : plugin.bootstrap(configOutput));
@@ -6,8 +6,9 @@
6
6
  * Note: this will not remove the session from server-side storage, which will
7
7
  * instead be left up to the storage mechanism to clean up.
8
8
  *
9
- * @param {object} req HTTP request
9
+ * @memberof module:@dwp/govuk-casa
10
+ * @param {import('express').Request} req HTTP request
10
11
  * @param {Function} next Chain
11
12
  * @returns {void}
12
13
  */
13
- export default function endSession(req: object, next: Function): void;
14
+ export default function endSession(req: import('express').Request, next: Function): void;
@@ -13,7 +13,8 @@ const log = (0, logger_js_1.default)('lib:end-session');
13
13
  * Note: this will not remove the session from server-side storage, which will
14
14
  * instead be left up to the storage mechanism to clean up.
15
15
  *
16
- * @param {object} req HTTP request
16
+ * @memberof module:@dwp/govuk-casa
17
+ * @param {import('express').Request} req HTTP request
17
18
  * @param {Function} next Chain
18
19
  * @returns {void}
19
20
  */