@dwp/govuk-casa 7.0.7 → 7.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/dist/assets/css/casa-ie8.css +1 -0
  3. package/dist/assets/css/casa.css +1 -0
  4. package/dist/casa/css/casa-ie8.css +1 -1
  5. package/dist/casa/css/casa.css +1 -1
  6. package/dist/casa.d.ts +11 -0
  7. package/dist/casa.js +46 -0
  8. package/dist/lib/CasaTemplateLoader.d.ts +29 -0
  9. package/dist/lib/CasaTemplateLoader.js +74 -0
  10. package/dist/lib/JourneyContext.d.ts +297 -0
  11. package/dist/lib/JourneyContext.js +581 -0
  12. package/dist/lib/MutableRouter.d.ts +155 -0
  13. package/dist/lib/MutableRouter.js +277 -0
  14. package/dist/lib/Plan.d.ts +154 -0
  15. package/dist/lib/Plan.js +442 -0
  16. package/dist/lib/ValidationError.d.ts +74 -0
  17. package/dist/lib/ValidationError.js +159 -0
  18. package/dist/lib/ValidatorFactory.d.ts +83 -0
  19. package/dist/lib/ValidatorFactory.js +106 -0
  20. package/dist/lib/configuration-ingestor.d.ts +262 -0
  21. package/dist/lib/configuration-ingestor.js +490 -0
  22. package/dist/lib/configure.d.ts +90 -0
  23. package/dist/lib/configure.js +192 -0
  24. package/dist/lib/dirname.cjs +1 -0
  25. package/dist/lib/dirname.d.cts +2 -0
  26. package/dist/lib/end-session.d.ts +13 -0
  27. package/dist/lib/end-session.js +43 -0
  28. package/dist/lib/field.d.ts +77 -0
  29. package/dist/lib/field.js +255 -0
  30. package/dist/lib/index.d.ts +14 -0
  31. package/dist/lib/index.js +54 -0
  32. package/dist/lib/logger.d.ts +9 -0
  33. package/dist/lib/logger.js +18 -0
  34. package/dist/lib/nunjucks-filters.d.ts +26 -0
  35. package/dist/lib/nunjucks-filters.js +90 -0
  36. package/dist/lib/nunjucks.d.ts +23 -0
  37. package/dist/lib/nunjucks.js +49 -0
  38. package/dist/lib/utils.d.ts +48 -0
  39. package/dist/lib/utils.js +111 -0
  40. package/dist/lib/validators/dateObject.d.ts +4 -0
  41. package/dist/lib/validators/dateObject.js +135 -0
  42. package/dist/lib/validators/email.d.ts +4 -0
  43. package/dist/lib/validators/email.js +46 -0
  44. package/dist/lib/validators/inArray.d.ts +4 -0
  45. package/dist/lib/validators/inArray.js +60 -0
  46. package/dist/lib/validators/index.d.ts +21 -0
  47. package/dist/lib/validators/index.js +47 -0
  48. package/dist/lib/validators/nino.d.ts +4 -0
  49. package/dist/lib/validators/nino.js +46 -0
  50. package/dist/lib/validators/postalAddressObject.d.ts +4 -0
  51. package/dist/lib/validators/postalAddressObject.js +123 -0
  52. package/dist/lib/validators/regex.d.ts +4 -0
  53. package/dist/lib/validators/regex.js +40 -0
  54. package/dist/lib/validators/required.d.ts +4 -0
  55. package/dist/lib/validators/required.js +56 -0
  56. package/dist/lib/validators/strlen.d.ts +4 -0
  57. package/dist/lib/validators/strlen.js +51 -0
  58. package/dist/lib/validators/wordCount.d.ts +5 -0
  59. package/dist/lib/validators/wordCount.js +54 -0
  60. package/dist/lib/waypoint-url.d.ts +23 -0
  61. package/dist/lib/waypoint-url.js +52 -0
  62. package/dist/middleware/body-parser.d.ts +1 -0
  63. package/dist/middleware/body-parser.js +24 -0
  64. package/dist/middleware/csrf.d.ts +1 -0
  65. package/dist/middleware/csrf.js +31 -0
  66. package/dist/middleware/data.d.ts +5 -0
  67. package/dist/middleware/data.js +53 -0
  68. package/dist/middleware/dirname.cjs +1 -0
  69. package/dist/middleware/dirname.d.cts +2 -0
  70. package/dist/middleware/gather-fields.d.ts +6 -0
  71. package/dist/middleware/gather-fields.js +48 -0
  72. package/dist/middleware/i18n.d.ts +4 -0
  73. package/dist/middleware/i18n.js +88 -0
  74. package/dist/middleware/post.d.ts +3 -0
  75. package/dist/middleware/post.js +57 -0
  76. package/dist/middleware/pre.d.ts +3 -0
  77. package/dist/middleware/pre.js +51 -0
  78. package/dist/middleware/progress-journey.d.ts +6 -0
  79. package/dist/middleware/progress-journey.js +80 -0
  80. package/dist/middleware/sanitise-fields.d.ts +5 -0
  81. package/dist/middleware/sanitise-fields.js +53 -0
  82. package/dist/middleware/session.d.ts +11 -0
  83. package/dist/middleware/session.js +121 -0
  84. package/dist/middleware/skip-waypoint.d.ts +5 -0
  85. package/dist/middleware/skip-waypoint.js +43 -0
  86. package/dist/middleware/steer-journey.d.ts +7 -0
  87. package/dist/middleware/steer-journey.js +62 -0
  88. package/dist/middleware/validate-fields.d.ts +7 -0
  89. package/dist/middleware/validate-fields.js +67 -0
  90. package/dist/mjs/esm-wrapper.js +11 -0
  91. package/dist/mjs/package.json +3 -0
  92. package/dist/package.json +3 -0
  93. package/dist/routes/ancillary.d.ts +11 -0
  94. package/dist/routes/ancillary.js +27 -0
  95. package/dist/routes/dirname.cjs +1 -0
  96. package/dist/routes/dirname.d.cts +2 -0
  97. package/dist/routes/journey.d.ts +8 -0
  98. package/dist/routes/journey.js +127 -0
  99. package/dist/routes/static.d.ts +26 -0
  100. package/dist/routes/static.js +68 -0
  101. package/package.json +19 -19
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @typedef {import('./index').ProcessorFunction} ProcessorFunction
3
+ */
4
+ /**
5
+ * @typedef {import('./index').JourneyContext} JourneyContext
6
+ */
7
+ /**
8
+ * @typedef {import('./index').ValidationError} ValidationError
9
+ */
10
+ /**
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
16
+ */
17
+ /**
18
+ * @callback ValidateFunction
19
+ * @param {any} value
20
+ * @param {ValidateContext} context
21
+ * @returns {ValidationError[]}
22
+ */
23
+ /**
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
28
+ */
29
+ export default class ValidatorFactory {
30
+ /**
31
+ * This is a convenience method that will return a consistently object
32
+ * structure containing validation and sanitisation methods.
33
+ *
34
+ * @param {object} config Validator config (custom to the validator being created)
35
+ * @returns {Validator} Validator object
36
+ * @throws {TypeError} When configurarion is invalid.
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;
61
+ /**
62
+ * Validator name
63
+ */
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 = {
71
+ /**
72
+ * Journey context
73
+ */
74
+ journeyContext: JourneyContext;
75
+ /**
76
+ * Waypoint
77
+ */
78
+ waypoint: string;
79
+ /**
80
+ * Name of field being processed
81
+ */
82
+ fieldName: string;
83
+ };
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* eslint-disable class-methods-use-this */
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const { isPlainObject } = lodash_1.default; // CommonJS
9
+ /**
10
+ * @typedef {import('./index').ProcessorFunction} ProcessorFunction
11
+ */
12
+ /**
13
+ * @typedef {import('./index').JourneyContext} JourneyContext
14
+ */
15
+ /**
16
+ * @typedef {import('./index').ValidationError} ValidationError
17
+ */
18
+ /**
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
24
+ */
25
+ /**
26
+ * @callback ValidateFunction
27
+ * @param {any} value
28
+ * @param {ValidateContext} context
29
+ * @returns {ValidationError[]}
30
+ */
31
+ /**
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
36
+ */
37
+ class ValidatorFactory {
38
+ /**
39
+ * This is a convenience method that will return a consistently object
40
+ * structure containing validation and sanitisation methods.
41
+ *
42
+ * @param {object} config Validator config (custom to the validator being created)
43
+ * @returns {Validator} Validator object
44
+ * @throws {TypeError} When configurarion is invalid.
45
+ */
46
+ static make(config = {}) {
47
+ if (!isPlainObject(config)) {
48
+ throw new TypeError('Configuration must be an object');
49
+ }
50
+ const validator = Reflect.construct(this, [config]);
51
+ /* eslint-disable-next-line sonarjs/prefer-object-literal */
52
+ const instance = {};
53
+ instance.name = validator.name || 'unknown';
54
+ instance.config = config;
55
+ instance.validate = validator.validate.bind(instance);
56
+ instance.sanitise = validator.sanitise.bind(instance);
57
+ Object.freeze(instance);
58
+ return instance;
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
+ }
91
+ constructor(config = {}) {
92
+ if (new.target === ValidatorFactory) {
93
+ throw new TypeError('Cannot instantiate the abstract class, ValidatorFactory');
94
+ }
95
+ this.config = config;
96
+ }
97
+ /* eslint-disable-next-line no-unused-vars */
98
+ validate(fieldValue, context) {
99
+ throw new Error('validate() method has not been implemented');
100
+ }
101
+ /* eslint-disable-next-line no-unused-vars */
102
+ sanitise(fieldValue) {
103
+ return fieldValue;
104
+ }
105
+ }
106
+ exports.default = ValidatorFactory;
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Validates and sanitises i18n obejct.
3
+ *
4
+ * @param {object} i18n Object to validate.
5
+ * @param {Function} cb Callback function that receives the validated value.
6
+ * @throws {TypeError} For invalid object.
7
+ * @returns {object} Sanitised i18n object.
8
+ */
9
+ export function validateI18nObject(i18n: object, cb?: Function): object;
10
+ /**
11
+ * Validates and sanitises i18n directory.
12
+ *
13
+ * @param {Array} dirs Array of directories.
14
+ * @throws {SyntaxError} For invalid directories.
15
+ * @throws {TypeError} For invalid type.
16
+ * @returns {Array} Array of directories.
17
+ */
18
+ export function validateI18nDirs(dirs: any[]): any[];
19
+ /**
20
+ * Validates and sanitises i18n locales.
21
+ *
22
+ * @param {Array} locales Array of locales.
23
+ * @throws {SyntaxError} For invalid locales.
24
+ * @throws {TypeError} For invalid type.
25
+ * @returns {Array} Array of locales.
26
+ */
27
+ export function validateI18nLocales(locales: any[]): any[];
28
+ /**
29
+ * Validates and sanitises mount url.
30
+ *
31
+ * @param {string} mountUrl URL from which Express app will be served.
32
+ * @param {string} name Name of the URL type (Mount URL, or Proxy Mount URL).
33
+ * @throws {SyntaxError} For invalid URL.
34
+ * @returns {string} Sanitised URL.
35
+ */
36
+ export function validateMountUrl(mountUrl: string, name?: string): string;
37
+ /**
38
+ * Validates and sanitises sessions object.
39
+ *
40
+ * @param {object} session Object to validate.
41
+ * @param {Function} cb Callback function that receives the validated value.
42
+ * @throws {TypeError} For invalid object.
43
+ * @returns {object} Sanitised sessions object.
44
+ */
45
+ export function validateSessionObject(session: object, cb?: Function): object;
46
+ /**
47
+ * Validates and sanitises view directory.
48
+ *
49
+ * @param {Array} dirs Array of directories.
50
+ * @throws {SyntaxError} For invalid directories.
51
+ * @throws {TypeError} For invalid type.
52
+ * @returns {Array} Array of directories.
53
+ */
54
+ export function validateViews(dirs: any[]): any[];
55
+ /**
56
+ * Validates and sanitises sessions secret.
57
+ *
58
+ * @param {string} secret Session secret.
59
+ * @throws {ReferenceError} For missing value type.
60
+ * @throws {TypeError} For invalid value.
61
+ * @returns {string} Secret.
62
+ */
63
+ export function validateSessionSecret(secret: string): string;
64
+ /**
65
+ * Validates and sanitises sessions ttl.
66
+ *
67
+ * @param {number} ttl Session ttl (seconds).
68
+ * @throws {ReferenceError} For missing value type.
69
+ * @throws {TypeError} For invalid value.
70
+ * @returns {number} Ttl.
71
+ */
72
+ export function validateSessionTtl(ttl: number): number;
73
+ /**
74
+ * Validates and sanitises sessions name.
75
+ *
76
+ * @param {string} name Session name.
77
+ * @throws {ReferenceError} For missing value type.
78
+ * @throws {TypeError} For invalid value.
79
+ * @returns {string} Name.
80
+ */
81
+ export function validateSessionName(name: string): string;
82
+ /**
83
+ * Validates and sanitises sessions secure flag.
84
+ *
85
+ * @param {boolean} secure Session secure flag.
86
+ * @throws {ReferenceError} For missing value type.
87
+ * @throws {TypeError} For invalid value.
88
+ * @returns {string} Name.
89
+ */
90
+ export function validateSessionSecure(secure: boolean): string;
91
+ /**
92
+ * Validates and sanitises sessions store.
93
+ *
94
+ * @param {Function} store Session store.
95
+ * @returns {Function} Store.
96
+ */
97
+ export function validateSessionStore(store: Function): Function;
98
+ /**
99
+ * Validates and sanitises sessions cookie url path.
100
+ *
101
+ * @param {string} cookiePath Session cookie url path.
102
+ * @param {string} defaultPath Default path if none specified.
103
+ * @returns {string} Cookie path.
104
+ */
105
+ export function validateSessionCookiePath(cookiePath: string, defaultPath?: string): string;
106
+ /**
107
+ * Validates and sanitises sessions cookie "sameSite" flag. One of:
108
+ * true (Strict)
109
+ * false (will not set the flag at all)
110
+ * Strict
111
+ * Lax
112
+ * None
113
+ *
114
+ * @param {any} cookieSameSite Session cookie "sameSite" flag
115
+ * @param {any} defaultFlag Default path if none specified
116
+ * @returns {boolean} cookie path
117
+ * @throws {TypeError} When invalid arguments are provided
118
+ */
119
+ export function validateSessionCookieSameSite(cookieSameSite: any, defaultFlag: any): boolean;
120
+ export function validatePageHooks(hooks: any): any[];
121
+ export function validateFields(fields: any): any[];
122
+ export function validatePages(pages: any): any[];
123
+ export function validatePlan(plan: any): any;
124
+ export function validateGlobalHooks(hooks: any): any[];
125
+ export function validatePlugins(plugins: any): any;
126
+ export function validateEvents(events: any): any;
127
+ /**
128
+ * Ingest, validate, sanitise and manipulate configuration parameters.
129
+ *
130
+ * @param {ConfigurationOptions} config Config to ingest.
131
+ * @throws {Error|SyntaxError|TypeError} For invalid config values.
132
+ * @returns {object} Immutable config object.
133
+ */
134
+ export default function ingest(config?: ConfigurationOptions): object;
135
+ export type ContextEvent = import('./index').ContextEvent;
136
+ export type SessionOptions = {
137
+ /**
138
+ * Session name
139
+ */
140
+ name?: string | undefined;
141
+ /**
142
+ * Encryption secret
143
+ */
144
+ secret?: string | undefined;
145
+ /**
146
+ * Session ttl (seconds)
147
+ */
148
+ ttl?: number | undefined;
149
+ /**
150
+ * Whether to use secure session cookies
151
+ */
152
+ secure?: boolean | undefined;
153
+ /**
154
+ * SameSite (true = Strict)
155
+ */
156
+ cookieSameSite?: string | boolean | undefined;
157
+ /**
158
+ * Session store (default MemoryStore)
159
+ */
160
+ store?: object | undefined;
161
+ };
162
+ export type I18nOptions = {
163
+ /**
164
+ * Directories to search for locale dictionaries
165
+ */
166
+ dirs: string[];
167
+ /**
168
+ * Supported locales
169
+ */
170
+ locales?: string[] | undefined;
171
+ };
172
+ /**
173
+ * Hook configuration
174
+ */
175
+ export type GlobalHook = {
176
+ /**
177
+ * Hook name in format `<router>.<hook>`
178
+ */
179
+ hook: string;
180
+ /**
181
+ * Middleware function to insert at the hook point
182
+ */
183
+ middleware: Function;
184
+ /**
185
+ * Only run if route path matches this string/regexp
186
+ */
187
+ path?: string | RegExp | undefined;
188
+ };
189
+ /**
190
+ * (extends GlobalHook)
191
+ */
192
+ export type PageHook = {
193
+ /**
194
+ * Hook name (without a scope prefix)
195
+ */
196
+ hook: string;
197
+ /**
198
+ * Middleware function to insert at the hook point
199
+ */
200
+ middleware: Function;
201
+ };
202
+ /**
203
+ * Page configuration. A Page is the interactive representation of a waypoint
204
+ */
205
+ export type Page = {
206
+ /**
207
+ * The waypoint with which this page is associated
208
+ */
209
+ waypoint: string;
210
+ /**
211
+ * Template path
212
+ */
213
+ view: string;
214
+ /**
215
+ * Page-specific hooks (optional, default [])
216
+ */
217
+ hooks?: PageHook[] | undefined;
218
+ /**
219
+ * Fields to be managed on this page (optional, default [])
220
+ */
221
+ fields?: PageField[] | undefined;
222
+ };
223
+ /**
224
+ * Configuration options
225
+ */
226
+ export type ConfigurationOptions = {
227
+ mountUrl?: string | undefined;
228
+ /**
229
+ * Template directories
230
+ */
231
+ views?: string[] | undefined;
232
+ /**
233
+ * Session configuration
234
+ */
235
+ session?: SessionOptions | undefined;
236
+ /**
237
+ * Pages the represent waypoints
238
+ */
239
+ pages?: Page[] | undefined;
240
+ /**
241
+ * Hooks to apply
242
+ */
243
+ hooks?: GlobalHook[] | undefined;
244
+ /**
245
+ * Plugins
246
+ */
247
+ plugins?: object[] | undefined;
248
+ /**
249
+ * I18n configuration
250
+ */
251
+ i18n?: I18nOptions[] | undefined;
252
+ /**
253
+ * CASA Plan
254
+ */
255
+ plan: Plan;
256
+ /**
257
+ * Handlers for JourneyContext events
258
+ */
259
+ events?: any[] | undefined;
260
+ };
261
+ import { PageField } from "./field.js";
262
+ import Plan from "./Plan.js";