@dwp/govuk-casa 8.0.0-alpha2 → 8.0.0-beta1

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 (49) hide show
  1. package/dist/casa.d.ts +2 -1
  2. package/dist/casa.js +3 -1
  3. package/dist/lib/CasaTemplateLoader.d.ts +6 -2
  4. package/dist/lib/CasaTemplateLoader.js +4 -1
  5. package/dist/lib/JourneyContext.d.ts +37 -6
  6. package/dist/lib/JourneyContext.js +21 -6
  7. package/dist/lib/MutableRouter.js +3 -1
  8. package/dist/lib/Plan.d.ts +37 -4
  9. package/dist/lib/Plan.js +63 -6
  10. package/dist/lib/ValidationError.d.ts +6 -2
  11. package/dist/lib/ValidationError.js +3 -0
  12. package/dist/lib/ValidatorFactory.d.ts +72 -19
  13. package/dist/lib/ValidatorFactory.js +33 -20
  14. package/dist/lib/configuration-ingestor.d.ts +262 -0
  15. package/dist/lib/configuration-ingestor.js +490 -0
  16. package/dist/lib/configure.d.ts +26 -140
  17. package/dist/lib/configure.js +16 -43
  18. package/dist/lib/dirname.d.cts +2 -0
  19. package/dist/lib/end-session.d.ts +2 -1
  20. package/dist/lib/end-session.js +24 -7
  21. package/dist/lib/field.d.ts +38 -45
  22. package/dist/lib/field.js +56 -34
  23. package/dist/lib/index.d.ts +14 -0
  24. package/dist/lib/index.js +54 -0
  25. package/dist/lib/logger.d.ts +2 -1
  26. package/dist/lib/logger.js +2 -3
  27. package/dist/lib/utils.d.ts +18 -2
  28. package/dist/lib/utils.js +54 -2
  29. package/dist/lib/waypoint-url.d.ts +2 -1
  30. package/dist/lib/waypoint-url.js +3 -0
  31. package/dist/middleware/body-parser.js +2 -2
  32. package/dist/middleware/data.d.ts +1 -2
  33. package/dist/middleware/data.js +4 -8
  34. package/dist/middleware/dirname.d.cts +2 -0
  35. package/dist/middleware/gather-fields.d.ts +2 -1
  36. package/dist/middleware/gather-fields.js +3 -0
  37. package/dist/middleware/post.js +6 -6
  38. package/dist/middleware/sanitise-fields.js +4 -4
  39. package/dist/middleware/session.d.ts +2 -1
  40. package/dist/middleware/session.js +2 -2
  41. package/dist/middleware/steer-journey.d.ts +2 -1
  42. package/dist/middleware/steer-journey.js +3 -0
  43. package/dist/routes/ancillary.d.ts +8 -1
  44. package/dist/routes/ancillary.js +7 -0
  45. package/dist/routes/dirname.d.cts +2 -0
  46. package/dist/routes/journey.js +9 -2
  47. package/dist/routes/static.js +4 -3
  48. package/package.json +27 -17
  49. package/views/casa/layouts/main.njk +2 -2
@@ -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";