@dwp/govuk-casa 6.8.4 → 6.9.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/casa.js +4 -3
  3. package/dist/casa/css/casa-ie8.css +1 -1
  4. package/dist/casa/css/casa.css +1 -1
  5. package/dist/casa/js/casa.js +1 -1
  6. package/lib/ConfigIngestor.js +119 -94
  7. package/lib/GatherModifier.js +1 -1
  8. package/lib/I18n.js +12 -11
  9. package/lib/JourneyContext.js +33 -30
  10. package/lib/JourneyMap.js +24 -16
  11. package/lib/JourneyRoad.js +25 -18
  12. package/lib/Logger.js +3 -3
  13. package/lib/PageDirectory.js +3 -3
  14. package/lib/Plan.js +31 -30
  15. package/lib/Util.js +20 -20
  16. package/lib/Validation.js +1 -1
  17. package/lib/bootstrap/end-session.js +2 -2
  18. package/lib/bootstrap/load-definitions.js +9 -9
  19. package/lib/gather-modifiers/trimPostalAddressObject.js +5 -5
  20. package/lib/gather-modifiers/trimWhitespace.js +4 -4
  21. package/lib/utils/makeEditLink.js +6 -3
  22. package/lib/utils/sanitise.js +1 -1
  23. package/lib/validation/ArrayObjectField.js +5 -4
  24. package/lib/validation/ObjectField.js +4 -3
  25. package/lib/validation/SimpleField.js +4 -3
  26. package/lib/validation/ValidationError.js +5 -2
  27. package/lib/validation/processor/flattenErrorArray.js +3 -2
  28. package/lib/validation/processor/queue.js +28 -28
  29. package/lib/validation/processor.js +9 -5
  30. package/lib/validation/rules/dateObject.js +2 -2
  31. package/lib/validation/rules/email.js +1 -1
  32. package/lib/validation/rules/inArray.js +3 -3
  33. package/lib/validation/rules/nino.js +2 -2
  34. package/lib/validation/rules/optional.js +2 -2
  35. package/lib/validation/rules/postalAddressObject.js +2 -2
  36. package/lib/validation/rules/regex.js +1 -1
  37. package/lib/validation/rules/required.js +3 -3
  38. package/lib/validation/rules/strlen.js +1 -1
  39. package/lib/view-filters/formatDateObject.js +6 -3
  40. package/lib/view-filters/includes.js +4 -4
  41. package/lib/view-filters/index.js +1 -1
  42. package/lib/view-filters/mergeObjectsDeep.js +3 -2
  43. package/lib/view-filters/renderAsAttributes.js +1 -1
  44. package/middleware/headers/config-defaults.js +2 -0
  45. package/middleware/i18n/i18n.js +15 -15
  46. package/middleware/nunjucks/environment.js +8 -9
  47. package/middleware/page/csrf.js +1 -1
  48. package/middleware/page/gather.js +1 -1
  49. package/middleware/page/index.js +5 -5
  50. package/middleware/page/journey-continue.js +15 -2
  51. package/middleware/page/journey-rails.js +1 -1
  52. package/middleware/page/prepare-request.js +2 -2
  53. package/middleware/page/skip.js +1 -1
  54. package/middleware/page/utils.js +37 -36
  55. package/middleware/page/validate.js +1 -1
  56. package/middleware/session/index.js +1 -1
  57. package/middleware/static/index.js +12 -7
  58. package/middleware/static/prepare-assets.js +4 -4
  59. package/middleware/static/serve-assets.js +4 -7
  60. package/package.json +51 -53
  61. package/src/js/casa.js +10 -6
  62. package/views/casa/layouts/main.njk +9 -0
  63. package/src/robots.txt +0 -2
@@ -8,9 +8,9 @@ const echo = (a) => (a);
8
8
  /**
9
9
  * Validate allow page edit flag.
10
10
  *
11
- * @param {boolean} allowPageEdit Flag
12
- * @throws {TypeError} for invalid argument type
13
- * @returns {boolean} flag
11
+ * @param {boolean} allowPageEdit Flag.
12
+ * @throws {TypeError} For invalid argument type.
13
+ * @returns {boolean} Flag.
14
14
  */
15
15
  function validateAllowPageEdit(allowPageEdit = false) {
16
16
  if (typeof allowPageEdit !== 'boolean') {
@@ -22,9 +22,9 @@ function validateAllowPageEdit(allowPageEdit = false) {
22
22
  /**
23
23
  * Validate use sticky edit flag.
24
24
  *
25
- * @param {boolean} useStickyEdit Flag
26
- * @throws {TypeError} for invalid argument type
27
- * @returns {boolean} flag
25
+ * @param {boolean} useStickyEdit Flag.
26
+ * @throws {TypeError} For invalid argument type.
27
+ * @returns {boolean} Flag.
28
28
  */
29
29
  function validateUseStickyEdit(useStickyEdit = false) {
30
30
  if (typeof useStickyEdit !== 'boolean') {
@@ -36,12 +36,13 @@ function validateUseStickyEdit(useStickyEdit = false) {
36
36
  /**
37
37
  * Validates directory and checks that it is writeable.
38
38
  *
39
- * @param {string} compiledAssetsDir Directory
40
- * @throws {ReferenceError} for missing directory value
41
- * @throws {Error} for missing directory
42
- * @returns {string} directory
39
+ * @param {string} compiledAssetsDir Directory.
40
+ * @param {boolean} skipAssetsGeneration skip static assets generation
41
+ * @throws {ReferenceError} For missing directory value.
42
+ * @throws {Error} For missing directory.
43
+ * @returns {string} Directory.
43
44
  */
44
- function validateCompiledAssetsDir(compiledAssetsDir) {
45
+ function validateCompiledAssetsDir(compiledAssetsDir, skipAssetsGeneration = false) {
45
46
  if (typeof compiledAssetsDir === 'undefined') {
46
47
  throw new ReferenceError('Compiled assets directory required (compiledAssetsDir)');
47
48
  }
@@ -50,7 +51,10 @@ function validateCompiledAssetsDir(compiledAssetsDir) {
50
51
  try {
51
52
  /* eslint-disable no-bitwise */
52
53
  const constants = fs.constants || fs;
53
- fs.accessSync(cad, constants.F_OK | constants.R_OK | constants.W_OK);
54
+ const permissions = skipAssetsGeneration
55
+ ? (constants.F_OK | constants.R_OK)
56
+ : (constants.F_OK | constants.R_OK | constants.W_OK);
57
+ fs.accessSync(cad, permissions);
54
58
  } catch (err) {
55
59
  if (err.code === 'ENOENT') {
56
60
  err.message = 'Compiled assets directory missing (compiledAssetsDir)';
@@ -64,10 +68,10 @@ function validateCompiledAssetsDir(compiledAssetsDir) {
64
68
  /**
65
69
  * Validate and sanitise CSP directives.
66
70
  *
67
- * @param {object} csp CSP directive and values pairs
68
- * @throws {TypeError} for invalid argument type
69
- * @throws {Error} for scriptSources warning
70
- * @returns {object} validated CSPs
71
+ * @param {object} csp CSP directive and values pairs.
72
+ * @throws {TypeError} For invalid argument type.
73
+ * @throws {Error} For scriptSources warning.
74
+ * @returns {object} Validated CSPs.
71
75
  */
72
76
  function validateContentSecurityPolicies(csp) {
73
77
  const validCspDirectives = [
@@ -130,10 +134,10 @@ function validateContentSecurityPolicies(csp) {
130
134
  /**
131
135
  * Validates and sanitises headers object.
132
136
  *
133
- * @param {object} headers Object to validate
134
- * @param {function} cb Callback function that receives the validated value
135
- * @throws {TypeError} for invalid object
136
- * @returns {object} sanitised headers object
137
+ * @param {object} headers Object to validate.
138
+ * @param {Function} cb Callback function that receives the validated value.
139
+ * @throws {TypeError} For invalid object.
140
+ * @returns {object} Sanitised headers object.
137
141
  */
138
142
  function validateHeadersObject(headers = {}, cb = echo) {
139
143
  if (Object.prototype.toString.call(headers) !== '[object Object]') {
@@ -143,13 +147,13 @@ function validateHeadersObject(headers = {}, cb = echo) {
143
147
  }
144
148
 
145
149
  /**
146
- * Validates and sanitises disabled headers.
147
- *
148
- * @param {array} disabled Array of disabled headers
149
- * @throws {SyntaxError} for invalid headers
150
- * @throws {TypeError} for invalid type
151
- * @returns {array} array of disabled headers
152
- */
150
+ * Validates and sanitises disabled headers.
151
+ *
152
+ * @param {Array} disabled Array of disabled headers.
153
+ * @throws {SyntaxError} For invalid headers.
154
+ * @throws {TypeError} For invalid type.
155
+ * @returns {Array} Array of disabled headers.
156
+ */
153
157
  function validateHeadersDisabled(disabled = []) {
154
158
  if (!Array.isArray(disabled)) {
155
159
  throw new TypeError('Disabled headers must be an array (headers.disabled)');
@@ -165,10 +169,10 @@ function validateHeadersDisabled(disabled = []) {
165
169
  /**
166
170
  * Validates and sanitises i18n obejct.
167
171
  *
168
- * @param {object} i18n Object to validate
169
- * @param {function} cb Callback function that receives the validated value
170
- * @throws {TypeError} for invalid object
171
- * @returns {object} sanitised i18n object
172
+ * @param {object} i18n Object to validate.
173
+ * @param {Function} cb Callback function that receives the validated value.
174
+ * @throws {TypeError} For invalid object.
175
+ * @returns {object} Sanitised i18n object.
172
176
  */
173
177
  function validateI18nObject(i18n, cb = echo) {
174
178
  if (Object.prototype.toString.call(i18n) !== '[object Object]') {
@@ -180,10 +184,10 @@ function validateI18nObject(i18n, cb = echo) {
180
184
  /**
181
185
  * Validates and sanitises i18n directory.
182
186
  *
183
- * @param {array} dirs Array of directories
184
- * @throws {SyntaxError} for invalid directories
185
- * @throws {TypeError} for invalid type
186
- * @returns {array} array of directories
187
+ * @param {Array} dirs Array of directories.
188
+ * @throws {SyntaxError} For invalid directories.
189
+ * @throws {TypeError} For invalid type.
190
+ * @returns {Array} Array of directories.
187
191
  */
188
192
  function validateI18nDirs(dirs) {
189
193
  if (typeof dirs === 'undefined') {
@@ -202,10 +206,10 @@ function validateI18nDirs(dirs) {
202
206
  /**
203
207
  * Validates and sanitises i18n locales.
204
208
  *
205
- * @param {array} locales Array of locales
206
- * @throws {SyntaxError} for invalid locales
207
- * @throws {TypeError} for invalid type
208
- * @returns {array} array of locales
209
+ * @param {Array} locales Array of locales.
210
+ * @throws {SyntaxError} For invalid locales.
211
+ * @throws {TypeError} For invalid type.
212
+ * @returns {Array} Array of locales.
209
213
  */
210
214
  function validateI18nLocales(locales) {
211
215
  if (typeof locales === 'undefined') {
@@ -224,9 +228,9 @@ function validateI18nLocales(locales) {
224
228
  /**
225
229
  * Validates and returns the custom mount controller function.
226
230
  *
227
- * @param {function} controller Function for mounting middlware onto Express app
228
- * @throws {TypeError} for incorrect type
229
- * @returns {function} controller
231
+ * @param {Function} controller Function for mounting middlware onto Express app.
232
+ * @throws {TypeError} For incorrect type.
233
+ * @returns {Function} Controller.
230
234
  */
231
235
  function validateMountController(controller) {
232
236
  if (!['undefined', 'function'].includes(typeof controller)) {
@@ -240,10 +244,10 @@ function validateMountController(controller) {
240
244
  /**
241
245
  * Validates and sanitises mount url.
242
246
  *
243
- * @param {string} mountUrl URL from which Express app will be served
244
- * @param {string} name Name of the URL type (Mount URL, or Proxy Mount URL)
245
- * @throws {SyntaxError} for invalid URL
246
- * @returns {string} sanitised URL
247
+ * @param {string} mountUrl URL from which Express app will be served.
248
+ * @param {string} name Name of the URL type (Mount URL, or Proxy Mount URL).
249
+ * @throws {SyntaxError} For invalid URL.
250
+ * @returns {string} Sanitised URL.
247
251
  */
248
252
  function validateMountUrl(mountUrl, name = 'Mount URL') {
249
253
  if (typeof mountUrl === 'undefined') {
@@ -258,9 +262,9 @@ function validateMountUrl(mountUrl, name = 'Mount URL') {
258
262
  /**
259
263
  * Validate phase.
260
264
  *
261
- * @param {string} phase Service phase (alpha | beta | live)
262
- * @throws {SyntaxError} for invalid phase value
263
- * @returns {string} Phase
265
+ * @param {string} phase Service phase (alpha | beta | live).
266
+ * @throws {SyntaxError} For invalid phase value.
267
+ * @returns {string} Phase.
264
268
  */
265
269
  function validatePhase(phase) {
266
270
  if (typeof phase === 'undefined') {
@@ -275,9 +279,9 @@ function validatePhase(phase) {
275
279
  /**
276
280
  * Validate service name.
277
281
  *
278
- * @param {string} serviceName Service name
279
- * @throws {SyntaxError} for invalid phase value
280
- * @returns {string} Phase
282
+ * @param {string} serviceName Service name.
283
+ * @throws {SyntaxError} For invalid phase value.
284
+ * @returns {string} Phase.
281
285
  */
282
286
  function validateServiceName(serviceName) {
283
287
  if (typeof serviceName === 'undefined') {
@@ -292,9 +296,9 @@ function validateServiceName(serviceName) {
292
296
  /**
293
297
  * Validates and returns the custom session expiry controller function.
294
298
  *
295
- * @param {function} controller Function to handle custom session expiry
296
- * @throws {TypeError} for incorrect type
297
- * @returns {function} controller
299
+ * @param {Function} controller Function to handle custom session expiry.
300
+ * @throws {TypeError} For incorrect type.
301
+ * @returns {Function} Controller.
298
302
  */
299
303
  function validateSessionExpiryController(controller) {
300
304
  if (!['undefined', 'function'].includes(typeof controller)) {
@@ -308,10 +312,10 @@ function validateSessionExpiryController(controller) {
308
312
  /**
309
313
  * Validates and sanitises sessions obejct.
310
314
  *
311
- * @param {string} sessions Object to validate
312
- * @param {function} cb Callback function that receives the validated value
313
- * @throws {TypeError} for invalid object
314
- * @returns {object} sanitised sessions object
315
+ * @param {string} sessions Object to validate.
316
+ * @param {Function} cb Callback function that receives the validated value.
317
+ * @throws {TypeError} For invalid object.
318
+ * @returns {object} Sanitised sessions object.
315
319
  */
316
320
  function validateSessionsObject(sessions, cb = echo) {
317
321
  if (typeof sessions !== 'object') {
@@ -323,10 +327,10 @@ function validateSessionsObject(sessions, cb = echo) {
323
327
  /**
324
328
  * Validates and sanitises views obejct.
325
329
  *
326
- * @param {object} views Object to validate
327
- * @param {function} cb Callback function that receives the validated value
328
- * @throws {TypeError} for invalid object
329
- * @returns {object} sanitised views object
330
+ * @param {object} views Object to validate.
331
+ * @param {Function} cb Callback function that receives the validated value.
332
+ * @throws {TypeError} For invalid object.
333
+ * @returns {object} Sanitised views object.
330
334
  */
331
335
  function validateViewsObject(views, cb = echo) {
332
336
  if (typeof views !== 'object') {
@@ -338,10 +342,10 @@ function validateViewsObject(views, cb = echo) {
338
342
  /**
339
343
  * Validates and sanitises view directory.
340
344
  *
341
- * @param {array} dirs Array of directories
342
- * @throws {SyntaxError} for invalid directories
343
- * @throws {TypeError} for invalid type
344
- * @returns {array} array of directories
345
+ * @param {Array} dirs Array of directories.
346
+ * @throws {SyntaxError} For invalid directories.
347
+ * @throws {TypeError} For invalid type.
348
+ * @returns {Array} Array of directories.
345
349
  */
346
350
  function validateViewsDirs(dirs) {
347
351
  if (typeof dirs === 'undefined') {
@@ -360,10 +364,10 @@ function validateViewsDirs(dirs) {
360
364
  /**
361
365
  * Validates and sanitises sessions secret.
362
366
  *
363
- * @param {string} secret Session secret
364
- * @throws {ReferenceError} for missing value type
365
- * @throws {TypeError} for invalid value
366
- * @returns {string} secret
367
+ * @param {string} secret Session secret.
368
+ * @throws {ReferenceError} For missing value type.
369
+ * @throws {TypeError} For invalid value.
370
+ * @returns {string} Secret.
367
371
  */
368
372
  function validateSessionsSecret(secret) {
369
373
  if (typeof secret === 'undefined') {
@@ -377,10 +381,10 @@ function validateSessionsSecret(secret) {
377
381
  /**
378
382
  * Validates and sanitises sessions ttl.
379
383
  *
380
- * @param {int} ttl Session ttl (seconds)
381
- * @throws {ReferenceError} for missing value type
382
- * @throws {TypeError} for invalid value
383
- * @returns {int} ttl
384
+ * @param {number} ttl Session ttl (seconds).
385
+ * @throws {ReferenceError} For missing value type.
386
+ * @throws {TypeError} For invalid value.
387
+ * @returns {number} Ttl.
384
388
  */
385
389
  function validateSessionsTtl(ttl) {
386
390
  if (typeof ttl === 'undefined') {
@@ -394,10 +398,10 @@ function validateSessionsTtl(ttl) {
394
398
  /**
395
399
  * Validates and sanitises sessions name.
396
400
  *
397
- * @param {string} name Session name
398
- * @throws {ReferenceError} for missing value type
399
- * @throws {TypeError} for invalid value
400
- * @returns {string} name
401
+ * @param {string} name Session name.
402
+ * @throws {ReferenceError} For missing value type.
403
+ * @throws {TypeError} For invalid value.
404
+ * @returns {string} Name.
401
405
  */
402
406
  function validateSessionsName(name) {
403
407
  if (typeof name === 'undefined') {
@@ -411,10 +415,10 @@ function validateSessionsName(name) {
411
415
  /**
412
416
  * Validates and sanitises sessions secure flag.
413
417
  *
414
- * @param {bool} secure Session secure flag
415
- * @throws {ReferenceError} for missing value type
416
- * @throws {TypeError} for invalid value
417
- * @returns {string} name
418
+ * @param {boolean} secure Session secure flag.
419
+ * @throws {ReferenceError} For missing value type.
420
+ * @throws {TypeError} For invalid value.
421
+ * @returns {string} Name.
418
422
  */
419
423
  function validateSessionsSecure(secure) {
420
424
  if (typeof secure === 'undefined') {
@@ -428,8 +432,8 @@ function validateSessionsSecure(secure) {
428
432
  /**
429
433
  * Validates and sanitises sessions store.
430
434
  *
431
- * @param {function} store Session store
432
- * @returns {function} store
435
+ * @param {Function} store Session store.
436
+ * @returns {Function} Store.
433
437
  */
434
438
  function validateSessionsStore(store) {
435
439
  if (typeof store === 'undefined') {
@@ -442,9 +446,9 @@ function validateSessionsStore(store) {
442
446
  /**
443
447
  * Validates and sanitises sessions cookie url path.
444
448
  *
445
- * @param {string} cookiePath Session cookie url path
446
- * @param {string} defaultPath Default path if none specified
447
- * @returns {string} cookie path
449
+ * @param {string} cookiePath Session cookie url path.
450
+ * @param {string} defaultPath Default path if none specified.
451
+ * @returns {string} Cookie path.
448
452
  */
449
453
  function validateSessionsCookiePath(cookiePath, defaultPath = '/') {
450
454
  if (typeof cookiePath === 'undefined') {
@@ -461,9 +465,10 @@ function validateSessionsCookiePath(cookiePath, defaultPath = '/') {
461
465
  * Lax
462
466
  * None
463
467
  *
464
- * @param {mixed} cookieSameSite Session cookie "sameSite" flag
465
- * @param {mixed} defaultFlag Default path if none specified
468
+ * @param {any} cookieSameSite Session cookie "sameSite" flag
469
+ * @param {any} defaultFlag Default path if none specified
466
470
  * @returns {boolean} cookie path
471
+ * @throws {TypeError} When invalid arguments are provided
467
472
  */
468
473
  function validateSessionsCookieSameSite(cookieSameSite, defaultFlag) {
469
474
  const validValues = [true, false, 'Strict', 'Lax', 'None'];
@@ -482,12 +487,26 @@ function validateSessionsCookieSameSite(cookieSameSite, defaultFlag) {
482
487
  return value;
483
488
  }
484
489
 
490
+ /**
491
+ * Validate skip assets generation flag.
492
+ *
493
+ * @param {boolean} skipAssetsGeneration Flag.
494
+ * @throws {TypeError} For invalid argument type.
495
+ * @returns {boolean} Flag.
496
+ */
497
+ function validateSkipAssetsGeneration(skipAssetsGeneration = false) {
498
+ if (typeof skipAssetsGeneration !== 'boolean') {
499
+ throw new TypeError('Skip assets generation flag must be a boolean (skipAssetsGeneration)');
500
+ }
501
+ return skipAssetsGeneration;
502
+ }
503
+
485
504
  /**
486
505
  * Ingest, validate, sanitise and manipulate configuration parameters.
487
506
  *
488
- * @param {object} config Config to ingest
489
- * @throws {Error|SyntaxError|TypeError} for invalid config values
490
- * @returns {object} Immutable config object
507
+ * @param {object} config Config to ingest.
508
+ * @throws {Error|SyntaxError|TypeError} For invalid config values.
509
+ * @returns {object} Immutable config object.
491
510
  */
492
511
  function ingest(config = {}) {
493
512
  const validatedMountUrl = validateMountUrl(config.mountUrl);
@@ -499,8 +518,13 @@ function ingest(config = {}) {
499
518
  // Use "sticky" edit mode
500
519
  useStickyEdit: validateUseStickyEdit(config.useStickyEdit),
501
520
 
521
+ // Skip assets Generation
522
+ skipAssetsGeneration: validateSkipAssetsGeneration(config.skipAssetsGeneration),
523
+
502
524
  // Directory to store compiled assets
503
- compiledAssetsDir: validateCompiledAssetsDir(config.compiledAssetsDir),
525
+ compiledAssetsDir: validateCompiledAssetsDir(
526
+ config.compiledAssetsDir, config.skipAssetsGeneration,
527
+ ),
504
528
 
505
529
  // Content security policies
506
530
  csp: validateContentSecurityPolicies(config.csp),
@@ -584,4 +608,5 @@ module.exports = {
584
608
  validateSessionsTtl,
585
609
  validateViewsObject,
586
610
  validateViewsDirs,
611
+ validateSkipAssetsGeneration,
587
612
  };
@@ -2,7 +2,7 @@
2
2
  * @deprecated Do not use this file in new applications.
3
3
  *
4
4
  * Use this instead:
5
- * const { gatherModifiers } = require('@dwp/govuk-casa');
5
+ * const { gatherModifiers } = require('@dwp/govuk-casa');.
6
6
  */
7
7
 
8
8
  const util = require('util');
package/lib/I18n.js CHANGED
@@ -6,7 +6,6 @@
6
6
  * const I18n = require('govuk-casa/lib/I18n')(localeDirs, supportedLocales);
7
7
  *
8
8
  * This essentially iniialises the I18n singleton object.
9
-
10
9
  */
11
10
 
12
11
  const npath = require('path');
@@ -22,7 +21,7 @@ class Translator {
22
21
  /**
23
22
  * Constructor.
24
23
  *
25
- * @param {string} lang Language to use for all translations
24
+ * @param {string} lang Language to use for all translations.
26
25
  */
27
26
  constructor(lang) {
28
27
  if (typeof lang !== 'string') {
@@ -34,7 +33,7 @@ class Translator {
34
33
  /**
35
34
  * Retrieve the language.
36
35
  *
37
- * @return {string} Language code
36
+ * @returns {string} Language code.
38
37
  */
39
38
  getLanguage() {
40
39
  return this.language;
@@ -49,8 +48,9 @@ class Translator {
49
48
  * t('Pay £${fee}', {fee:100}) = Pay £100
50
49
  *
51
50
  * @param {string} key String to translate
52
- * @param {...mixed} subs Replacements
53
- * @return {string} Translated string
51
+ * @param {...any} subs Replacements
52
+ * @returns {string} Translated string
53
+ * @throws {Error} When a function substitution is used
54
54
  */
55
55
  t(key, ...subs) {
56
56
  const k = (key || '').split(':');
@@ -85,11 +85,11 @@ module.exports = function TranslaterInit(localeDirs, supportedLocales) {
85
85
  * "person": {
86
86
  * "title": {
87
87
  * "label": "Miss"
88
- * }
89
- * }
90
- * }
88
+ * }.
89
+ * }.
90
+ * }.
91
91
  *
92
- * ... results in the new object, written to `tgt`:
92
+ * ... Results in the new object, written to `tgt`:
93
93
  * {
94
94
  * "person.title.label": "Miss"
95
95
  * }
@@ -113,8 +113,9 @@ module.exports = function TranslaterInit(localeDirs, supportedLocales) {
113
113
  /**
114
114
  * Load the locale into the `LOCALE_DATA` object.
115
115
  *
116
- * @param {string} locale Locale to load (e.g. "en")
117
- * @return {void}
116
+ * @param {string} locale Locale to load (e.g. "en").
117
+ * @returns {void}
118
+ * @throws {Error} When locale is missing
118
119
  */
119
120
  function loadLocale(locale) {
120
121
  try {
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * - Data gathered during the journey
6
6
  * - Validation errors on that data
7
- * - Navigation information about how the user got where they are
7
+ * - Navigation information about how the user got where they are.
8
8
  */
9
9
  const clonedeep = require('fast-copy');
10
10
  const { isObjectType } = require('./Util.js');
@@ -13,7 +13,7 @@ const privates = new WeakMap();
13
13
 
14
14
  class JourneyContext {
15
15
  /**
16
- * Constructor
16
+ * Constructor.
17
17
  *
18
18
  * `data` is the "single source of truth" for all data gathered during the
19
19
  * user's journey. This is referred to as the "canonical data model".
@@ -27,9 +27,9 @@ class JourneyContext {
27
27
  * `nav` holds information about the current navigation state. Currently this
28
28
  * comprises of the language in which the user is navigating the service.
29
29
  *
30
- * @param {object} data Entire journey data
31
- * @param {object} validation Page errors (indexed by waypoint id)
32
- * @param {object} nav Navigation context
30
+ * @param {object} data Entire journey data.
31
+ * @param {object} validation Page errors (indexed by waypoint id).
32
+ * @param {object} nav Navigation context.
33
33
  */
34
34
  constructor(data = {}, validation = {}, nav = {}) {
35
35
  privates.set(this, { data, validation, nav });
@@ -38,7 +38,7 @@ class JourneyContext {
38
38
  /**
39
39
  * Turn this instance into an object that can be stringified.
40
40
  *
41
- * @returns {object} Plain object
41
+ * @returns {object} Plain object.
42
42
  */
43
43
  toObject() {
44
44
  return Object.assign(Object.create(null), {
@@ -51,8 +51,8 @@ class JourneyContext {
51
51
  /**
52
52
  * Create a new JourneyContext using the plain object.
53
53
  *
54
- * @param {object} obj Object
55
- * @returns {JourneyContext} Instance
54
+ * @param {object} obj Object.
55
+ * @returns {JourneyContext} Instance.
56
56
  */
57
57
  static fromObject(obj = {}) {
58
58
  return new JourneyContext(
@@ -86,7 +86,7 @@ class JourneyContext {
86
86
  * ...
87
87
  * }
88
88
  *
89
- * @return {object} Data context
89
+ * @returns {object} Data context
90
90
  */
91
91
  getData() {
92
92
  return privates.get(this).data;
@@ -100,8 +100,9 @@ class JourneyContext {
100
100
  * instance, its `fieldReader()` method will be called to transform the
101
101
  * internal context data into a format suitable for populating an HTML form.
102
102
  *
103
- * @param {string | PageMeta} page Page waypoint ID, or PageMeta object
104
- * @return {object} Page data
103
+ * @param {string | PageMeta} page Page waypoint ID, or PageMeta object.
104
+ * @returns {object} Page data.
105
+ * @throws {TypeError} When page is invalid.
105
106
  */
106
107
  getDataForPage(page) {
107
108
  const priv = privates.get(this);
@@ -129,8 +130,8 @@ class JourneyContext {
129
130
  /**
130
131
  * Overwrite the data context with a new object.
131
132
  *
132
- * @param {object} data Data that will overwrite all existing data
133
- * @return {JourneyContext} Chain
133
+ * @param {object} data Data that will overwrite all existing data.
134
+ * @returns {JourneyContext} Chain.
134
135
  */
135
136
  setData(data) {
136
137
  const priv = privates.get(this);
@@ -149,7 +150,8 @@ class JourneyContext {
149
150
  *
150
151
  * @param {string | PageMeta} page Page waypoint ID, or PageMeta object
151
152
  * @param {object} webFormData Data to overwrite with
152
- * @return {JourneyContext} Chain
153
+ * @returns {JourneyContext} Chain
154
+ * @throws {TypeError} When page is invalid.
153
155
  */
154
156
  setDataForPage(page, webFormData) {
155
157
  const priv = privates.get(this);
@@ -180,7 +182,7 @@ class JourneyContext {
180
182
  /**
181
183
  * Return validation errors for all pages.
182
184
  *
183
- * @return {object} All page validation errors
185
+ * @returns {object} All page validation errors.
184
186
  */
185
187
  getValidationErrors() {
186
188
  return privates.get(this).validation;
@@ -191,8 +193,8 @@ class JourneyContext {
191
193
  * completely will, by default, prevent onward traversal from this page. See
192
194
  * the traversal logic in Plan class.
193
195
  *
194
- * @param {string} pageId Page ID
195
- * @return {JourneyContext} Chain
196
+ * @param {string} pageId Page ID.
197
+ * @returns {JourneyContext} Chain.
196
198
  */
197
199
  removeValidationStateForPage(pageId) {
198
200
  const priv = privates.get(this);
@@ -207,8 +209,8 @@ class JourneyContext {
207
209
  * you want to remove any knowledge of validation success/failure, use
208
210
  * `removeValidationStateForPage()` instead.
209
211
  *
210
- * @param {string} pageId Page ID
211
- * @return {JourneyContext} Chain
212
+ * @param {string} pageId Page ID.
213
+ * @returns {JourneyContext} Chain.
212
214
  */
213
215
  clearValidationErrorsForPage(pageId) {
214
216
  const priv = privates.get(this);
@@ -220,9 +222,10 @@ class JourneyContext {
220
222
  /**
221
223
  * Set validation errors for a page.
222
224
  *
223
- * @param {string} pageId Page ID
224
- * @param {object} errors Errors index by field name (as generated by Validation.processor)
225
- * @return {JourneyContext} Chain
225
+ * @param {string} pageId Page ID.
226
+ * @param {object} errors Errors index by field name (as generated by Validation.processor).
227
+ * @returns {JourneyContext} Chain.
228
+ * @throws {SyntaxError} When errors are invalid.
226
229
  */
227
230
  setValidationErrorsForPage(pageId, errors = {}) {
228
231
  const priv = privates.get(this);
@@ -247,8 +250,8 @@ class JourneyContext {
247
250
  * Return the validation errors associated with the page's currently held data
248
251
  * context (if any).
249
252
  *
250
- * @param {string} pageId Page ID
251
- * @return {object} An object of errors, indexed by field name
253
+ * @param {string} pageId Page ID.
254
+ * @returns {object} An object of errors, indexed by field name.
252
255
  */
253
256
  getValidationErrorsForPage(pageId) {
254
257
  return privates.get(this).validation[pageId] || Object.create(null);
@@ -258,8 +261,8 @@ class JourneyContext {
258
261
  * Determine whether the specified page has any errors in its validation
259
262
  * context.
260
263
  *
261
- * @param {string} pageId Page ID
262
- * @returns {boolean} Result
264
+ * @param {string} pageId Page ID.
265
+ * @returns {boolean} Result.
263
266
  */
264
267
  hasValidationErrorsForPage(pageId) {
265
268
  return Object.keys(this.getValidationErrorsForPage(pageId)).length > 0;
@@ -280,8 +283,8 @@ class JourneyContext {
280
283
  /**
281
284
  * Set language of the context.
282
285
  *
283
- * @param {string} language Language to set (ISO 639-1 2-letter code)
284
- * @returns {JourneyContext} Chain
286
+ * @param {string} language Language to set (ISO 639-1 2-letter code).
287
+ * @returns {JourneyContext} Chain.
285
288
  */
286
289
  setNavigationLanguage(language = 'en') {
287
290
  const priv = privates.get(this);
@@ -293,8 +296,8 @@ class JourneyContext {
293
296
  /**
294
297
  * Convenience function to test if page is valid.
295
298
  *
296
- * @param {string} pageId Page ID
297
- * @return {boolean} True if the page is valid
299
+ * @param {string} pageId Page ID.
300
+ * @returns {boolean} True if the page is valid.
298
301
  */
299
302
  isPageValid(pageId) {
300
303
  return privates.get(this).validation[pageId] === null;