@dwp/govuk-casa 8.2.3 → 8.2.4

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 (65) hide show
  1. package/README.md +1 -0
  2. package/dist/casa.d.ts +198 -0
  3. package/dist/casa.js +129 -0
  4. package/dist/lib/CasaTemplateLoader.d.ts +4 -0
  5. package/dist/lib/CasaTemplateLoader.js +5 -0
  6. package/dist/lib/JourneyContext.d.ts +85 -13
  7. package/dist/lib/JourneyContext.js +78 -5
  8. package/dist/lib/Plan.d.ts +122 -49
  9. package/dist/lib/Plan.js +161 -37
  10. package/dist/lib/ValidationError.d.ts +38 -48
  11. package/dist/lib/ValidationError.js +30 -42
  12. package/dist/lib/ValidatorFactory.d.ts +42 -52
  13. package/dist/lib/ValidatorFactory.js +37 -48
  14. package/dist/lib/configuration-ingestor.d.ts +15 -0
  15. package/dist/lib/configuration-ingestor.js +17 -0
  16. package/dist/lib/configure.d.ts +4 -0
  17. package/dist/lib/configure.js +14 -1
  18. package/dist/lib/end-session.d.ts +3 -2
  19. package/dist/lib/end-session.js +2 -1
  20. package/dist/lib/field.d.ts +97 -35
  21. package/dist/lib/field.js +90 -41
  22. package/dist/lib/nunjucks-filters.d.ts +12 -2
  23. package/dist/lib/nunjucks-filters.js +11 -1
  24. package/dist/lib/nunjucks.d.ts +1 -0
  25. package/dist/lib/nunjucks.js +1 -0
  26. package/dist/lib/utils.d.ts +46 -14
  27. package/dist/lib/utils.js +43 -26
  28. package/dist/lib/validators/dateObject.d.ts +75 -1
  29. package/dist/lib/validators/dateObject.js +29 -18
  30. package/dist/lib/validators/email.d.ts +28 -1
  31. package/dist/lib/validators/email.js +20 -9
  32. package/dist/lib/validators/inArray.d.ts +34 -1
  33. package/dist/lib/validators/inArray.js +21 -0
  34. package/dist/lib/validators/index.js +3 -0
  35. package/dist/lib/validators/nino.d.ts +34 -1
  36. package/dist/lib/validators/nino.js +17 -7
  37. package/dist/lib/validators/postalAddressObject.d.ts +68 -1
  38. package/dist/lib/validators/postalAddressObject.js +27 -15
  39. package/dist/lib/validators/regex.d.ts +35 -1
  40. package/dist/lib/validators/regex.js +17 -7
  41. package/dist/lib/validators/required.d.ts +28 -1
  42. package/dist/lib/validators/required.js +19 -6
  43. package/dist/lib/validators/strlen.d.ts +40 -1
  44. package/dist/lib/validators/strlen.js +18 -8
  45. package/dist/lib/validators/wordCount.d.ts +40 -1
  46. package/dist/lib/validators/wordCount.js +18 -8
  47. package/dist/lib/waypoint-url.d.ts +1 -0
  48. package/dist/lib/waypoint-url.js +10 -0
  49. package/dist/middleware/data.js +21 -5
  50. package/dist/middleware/gather-fields.js +1 -0
  51. package/dist/middleware/pre.js +1 -0
  52. package/dist/middleware/steer-journey.js +2 -1
  53. package/dist/middleware/strip-proxy-path.js +6 -2
  54. package/dist/middleware/validate-fields.js +3 -0
  55. package/dist/routes/ancillary.d.ts +16 -5
  56. package/dist/routes/ancillary.js +7 -3
  57. package/dist/routes/journey.d.ts +30 -6
  58. package/dist/routes/journey.js +27 -0
  59. package/dist/routes/static.d.ts +1 -0
  60. package/dist/routes/static.js +2 -1
  61. package/package.json +16 -11
  62. package/views/casa/components/character-count/README.md +1 -1
  63. package/views/casa/components/input/README.md +1 -1
  64. package/views/casa/components/radios/README.md +2 -2
  65. package/views/casa/components/textarea/README.md +1 -1
@@ -1,5 +1,72 @@
1
+ /**
2
+ * @access private
3
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
4
+ */
5
+ /**
6
+ * @typedef {object} PostalAddressObjectConfigOptions
7
+ * @property {ErrorMessageConfig} [errorMsg] General error message for the entire address block
8
+ * @property {string|object} [errorMsgAddress1] Error message for address1 part
9
+ * @property {string|object} [errorMsgAddress2] Error message for address2 part
10
+ * @property {string|object} [errorMsgAddress3] Error message for address3 part
11
+ * @property {string|object} [errorMsgAddress4] Error message for address4 part
12
+ * @property {string|object} [errorMsgPostcode] Error message for postcode part
13
+ * @property {number} [strlenmax] Max. String length for each of the inputs appress[1-4]
14
+ * @property {string[]} [requiredFields] Field parts required (others become optional). One of
15
+ * 'address1'|'address2'|'address3'|'address4'|'postcode'
16
+ */
17
+ /**
18
+ * Works hand in hand with the core CASA `postalAddressObject` form
19
+ * macro.
20
+ *
21
+ * The errors sent back from this validator are specific to each subfield. For
22
+ * example, if the field name being tested is "address", any errors related to
23
+ * the "postcode" component would be associated with "address[postcode]".
24
+ *
25
+ * See {@link PostalAddressObjectConfigOptions} for `make()` options.
26
+ *
27
+ * @memberof Validators
28
+ * @augments ValidatorFactory
29
+ */
1
30
  export default class PostalAddressObject extends ValidatorFactory {
2
31
  name: string;
3
- validate(value: any, dataContext?: {}): object[];
32
+ validate(value: any, dataContext?: {}): ValidationError[];
33
+ sanitise(value: any): any;
4
34
  }
35
+ export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
36
+ export type PostalAddressObjectConfigOptions = {
37
+ /**
38
+ * General error message for the entire address block
39
+ */
40
+ errorMsg?: import("../../casa").ErrorMessageConfig | undefined;
41
+ /**
42
+ * Error message for address1 part
43
+ */
44
+ errorMsgAddress1?: string | object | undefined;
45
+ /**
46
+ * Error message for address2 part
47
+ */
48
+ errorMsgAddress2?: string | object | undefined;
49
+ /**
50
+ * Error message for address3 part
51
+ */
52
+ errorMsgAddress3?: string | object | undefined;
53
+ /**
54
+ * Error message for address4 part
55
+ */
56
+ errorMsgAddress4?: string | object | undefined;
57
+ /**
58
+ * Error message for postcode part
59
+ */
60
+ errorMsgPostcode?: string | object | undefined;
61
+ /**
62
+ * Max. String length for each of the inputs appress[1-4]
63
+ */
64
+ strlenmax?: number | undefined;
65
+ /**
66
+ * Field parts required (others become optional). One of
67
+ * 'address1'|'address2'|'address3'|'address4'|'postcode'
68
+ */
69
+ requiredFields?: string[] | undefined;
70
+ };
5
71
  import ValidatorFactory from "../ValidatorFactory.js";
72
+ import ValidationError from "../ValidationError.js";
@@ -4,28 +4,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable class-methods-use-this */
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
9
+ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
10
+ const utils_js_1 = require("../utils.js");
11
+ const { isPlainObject } = lodash_1.default; // CommonjS
12
+ /**
13
+ * @access private
14
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
15
+ */
7
16
  /**
8
- * Works hand in hand with the core CASA `postalAddressObject` form macro.
17
+ * @typedef {object} PostalAddressObjectConfigOptions
18
+ * @property {ErrorMessageConfig} [errorMsg] General error message for the entire address block
19
+ * @property {string|object} [errorMsgAddress1] Error message for address1 part
20
+ * @property {string|object} [errorMsgAddress2] Error message for address2 part
21
+ * @property {string|object} [errorMsgAddress3] Error message for address3 part
22
+ * @property {string|object} [errorMsgAddress4] Error message for address4 part
23
+ * @property {string|object} [errorMsgPostcode] Error message for postcode part
24
+ * @property {number} [strlenmax] Max. String length for each of the inputs appress[1-4]
25
+ * @property {string[]} [requiredFields] Field parts required (others become optional). One of
26
+ * 'address1'|'address2'|'address3'|'address4'|'postcode'
27
+ */
28
+ /**
29
+ * Works hand in hand with the core CASA `postalAddressObject` form
30
+ * macro.
9
31
  *
10
32
  * The errors sent back from this validator are specific to each subfield. For
11
33
  * example, if the field name being tested is "address", any errors related to
12
34
  * the "postcode" component would be associated with "address[postcode]".
13
35
  *
14
- * Config options:
15
- * string|object errorMsg = General error message for the entire address block
16
- * string|object errorMsgAddress1 = Error message for address1 part
17
- * string|object errorMsgAddress2 = Error message for address2 part
18
- * string|object errorMsgAddress3 = Error message for address3 part
19
- * string|object errorMsgAddress4 = Error message for address4 part
20
- * string|object errorMsgPostcode = Error message for postcode part
21
- * int strlenmax = Max. String length for each of the inputs appress[1-4]
22
- * array requiredFields = Field parts required (others become optional)
36
+ * See {@link PostalAddressObjectConfigOptions} for `make()` options.
37
+ *
38
+ * @memberof Validators
39
+ * @augments ValidatorFactory
23
40
  */
24
- const lodash_1 = __importDefault(require("lodash"));
25
- const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
26
- const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
27
- const utils_js_1 = require("../utils.js");
28
- const { isPlainObject } = lodash_1.default; // CommonjS
29
41
  class PostalAddressObject extends ValidatorFactory_js_1.default {
30
42
  constructor() {
31
43
  super(...arguments);
@@ -1,6 +1,40 @@
1
+ /**
2
+ * @access private
3
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
4
+ */
5
+ /**
6
+ * @typedef {object} RegexConfigOptions
7
+ * @property {ErrorMessageConfig} errorMsg Error message config
8
+ * @property {RegExp} pattern Regular expression to test against
9
+ * @property {boolean} invert Return error on positive regex match
10
+ */
11
+ /**
12
+ * Match a string pattern.
13
+ *
14
+ * See {@link RegexConfigOptions} for `make()` options.
15
+ *
16
+ * @memberof Validators
17
+ * @augments ValidatorFactory
18
+ */
1
19
  export default class Regex extends ValidatorFactory {
2
20
  name: string;
3
- validate(value?: string, dataContext?: {}): object[];
21
+ validate(value?: string, dataContext?: {}): ValidationError[];
4
22
  sanitise(value: any): string | undefined;
5
23
  }
24
+ export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
25
+ export type RegexConfigOptions = {
26
+ /**
27
+ * Error message config
28
+ */
29
+ errorMsg: ErrorMessageConfig;
30
+ /**
31
+ * Regular expression to test against
32
+ */
33
+ pattern: RegExp;
34
+ /**
35
+ * Return error on positive regex match
36
+ */
37
+ invert: boolean;
38
+ };
6
39
  import ValidatorFactory from "../ValidatorFactory.js";
40
+ import ValidationError from "../ValidationError.js";
@@ -4,17 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable class-methods-use-this */
7
+ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
8
+ const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
9
+ const utils_js_1 = require("../utils.js");
10
+ /**
11
+ * @access private
12
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
13
+ */
14
+ /**
15
+ * @typedef {object} RegexConfigOptions
16
+ * @property {ErrorMessageConfig} errorMsg Error message config
17
+ * @property {RegExp} pattern Regular expression to test against
18
+ * @property {boolean} invert Return error on positive regex match
19
+ */
7
20
  /**
8
21
  * Match a string pattern.
9
22
  *
10
- * Config options:
11
- * string|object errorMsg = Error message to use on validation failure
12
- * RegExp pattern = Regular expression to test against
13
- * boolean invert = return reject on positive regex match
23
+ * See {@link RegexConfigOptions} for `make()` options.
24
+ *
25
+ * @memberof Validators
26
+ * @augments ValidatorFactory
14
27
  */
15
- const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
16
- const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
17
- const utils_js_1 = require("../utils.js");
18
28
  class Regex extends ValidatorFactory_js_1.default {
19
29
  constructor() {
20
30
  super(...arguments);
@@ -1,8 +1,35 @@
1
+ /**
2
+ * @access private
3
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
4
+ */
5
+ /**
6
+ * @typedef {object} RequiredConfigOptions
7
+ * @property {ErrorMessageConfig} errorMsg Error message config
8
+ */
9
+ /**
10
+ * Test if value is present.
11
+ *
12
+ * Value is required. The following values will fail this rule:
13
+ * (all values that satisify `isEmpty()`) plus '\s'
14
+ *
15
+ * See {@link RequiredConfigOptions} for `make()` options.
16
+ *
17
+ * @memberof Validators
18
+ * @augments ValidatorFactory
19
+ */
1
20
  export default class Required extends ValidatorFactory {
2
21
  name: string;
3
- validate(value: any, dataContext?: {}): object[];
22
+ validate(value: any, dataContext?: {}): ValidationError[];
4
23
  sanitise(value: any): string | (string | undefined)[] | {
5
24
  [k: string]: string | undefined;
6
25
  } | undefined;
7
26
  }
27
+ export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
28
+ export type RequiredConfigOptions = {
29
+ /**
30
+ * Error message config
31
+ */
32
+ errorMsg: ErrorMessageConfig;
33
+ };
8
34
  import ValidatorFactory from "../ValidatorFactory.js";
35
+ import ValidationError from "../ValidationError.js";
@@ -4,17 +4,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable class-methods-use-this */
7
- /**
8
- * Test is value is present.
9
- *
10
- * Value is required. The following values will fail this rule:
11
- * (all values that satisify `isEmpty()`) plus '\s'
12
- */
13
7
  const lodash_1 = __importDefault(require("lodash"));
14
8
  const utils_js_1 = require("../utils.js");
15
9
  const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
16
10
  const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
17
11
  const { isPlainObject } = lodash_1.default; // CommonJS
12
+ /**
13
+ * @access private
14
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
15
+ */
16
+ /**
17
+ * @typedef {object} RequiredConfigOptions
18
+ * @property {ErrorMessageConfig} errorMsg Error message config
19
+ */
20
+ /**
21
+ * Test if value is present.
22
+ *
23
+ * Value is required. The following values will fail this rule:
24
+ * (all values that satisify `isEmpty()`) plus '\s'
25
+ *
26
+ * See {@link RequiredConfigOptions} for `make()` options.
27
+ *
28
+ * @memberof Validators
29
+ * @augments ValidatorFactory
30
+ */
18
31
  class Required extends ValidatorFactory_js_1.default {
19
32
  constructor() {
20
33
  super(...arguments);
@@ -1,6 +1,45 @@
1
+ /**
2
+ * @access private
3
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
4
+ */
5
+ /**
6
+ * @typedef {object} StrlenConfigOptions
7
+ * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
8
+ * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
9
+ * @property {number} max Maximum string length allowed
10
+ * @property {number} min Minimum string length required
11
+ */
12
+ /**
13
+ * Test the length of a string.
14
+ *
15
+ * See {@link StrlenConfigOptions} for `make()` options.
16
+ *
17
+ * @memberof Validators
18
+ * @augments ValidatorFactory
19
+ */
1
20
  export default class Strlen extends ValidatorFactory {
2
21
  name: string;
3
- validate(inputValue?: string, dataContext?: {}): object[];
22
+ validate(inputValue?: string, dataContext?: {}): ValidationError[];
4
23
  sanitise(value: any): string | undefined;
5
24
  }
25
+ export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
26
+ export type StrlenConfigOptions = {
27
+ /**
28
+ * Error message to use on max length failure
29
+ */
30
+ errorMsgMax: ErrorMessageConfig;
31
+ /**
32
+ * Error message to use on min length failure
33
+ */
34
+ errorMsgMin: ErrorMessageConfig;
35
+ /**
36
+ * Maximum string length allowed
37
+ */
38
+ max: number;
39
+ /**
40
+ * Minimum string length required
41
+ */
42
+ min: number;
43
+ };
6
44
  import ValidatorFactory from "../ValidatorFactory.js";
45
+ import ValidationError from "../ValidationError.js";
@@ -4,18 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable class-methods-use-this */
7
+ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
8
+ const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
9
+ const utils_js_1 = require("../utils.js");
10
+ /**
11
+ * @access private
12
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
13
+ */
14
+ /**
15
+ * @typedef {object} StrlenConfigOptions
16
+ * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
17
+ * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
18
+ * @property {number} max Maximum string length allowed
19
+ * @property {number} min Minimum string length required
20
+ */
7
21
  /**
8
22
  * Test the length of a string.
9
23
  *
10
- * Config options:
11
- * string|object errorMsgMax = Error message to use on max length failure
12
- * string|object errorMsgMin = Error message to use on min length failure
13
- * int max = Maximum string length allowed
14
- * int min = Minimum string length required
24
+ * See {@link StrlenConfigOptions} for `make()` options.
25
+ *
26
+ * @memberof Validators
27
+ * @augments ValidatorFactory
15
28
  */
16
- const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
17
- const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
18
- const utils_js_1 = require("../utils.js");
19
29
  class Strlen extends ValidatorFactory_js_1.default {
20
30
  constructor() {
21
31
  super(...arguments);
@@ -1,7 +1,46 @@
1
+ /**
2
+ * @access private
3
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
4
+ */
5
+ /**
6
+ * @typedef {object} WordcountConfigOptions
7
+ * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
8
+ * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
9
+ * @property {number} max Maximum string length allowed
10
+ * @property {number} min Minimum string length required
11
+ */
12
+ /**
13
+ * Test the number of words in a string.
14
+ *
15
+ * See {@link WordcountConfigOptions} for `make()` options.
16
+ *
17
+ * @memberof Validators
18
+ * @augments ValidatorFactory
19
+ */
1
20
  export default class WordCount extends ValidatorFactory {
2
21
  name: string;
3
22
  count(input: any): any;
4
- validate(inputValue?: string, dataContext?: {}): object[];
23
+ validate(inputValue?: string, dataContext?: {}): ValidationError[];
5
24
  sanitise(value: any): string | undefined;
6
25
  }
26
+ export type ErrorMessageConfig = import('../../casa').ErrorMessageConfig;
27
+ export type WordcountConfigOptions = {
28
+ /**
29
+ * Error message to use on max length failure
30
+ */
31
+ errorMsgMax: ErrorMessageConfig;
32
+ /**
33
+ * Error message to use on min length failure
34
+ */
35
+ errorMsgMin: ErrorMessageConfig;
36
+ /**
37
+ * Maximum string length allowed
38
+ */
39
+ max: number;
40
+ /**
41
+ * Minimum string length required
42
+ */
43
+ min: number;
44
+ };
7
45
  import ValidatorFactory from "../ValidatorFactory.js";
46
+ import ValidationError from "../ValidationError.js";
@@ -4,18 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable class-methods-use-this */
7
+ const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
8
+ const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
9
+ const utils_js_1 = require("../utils.js");
10
+ /**
11
+ * @access private
12
+ * @typedef {import('../../casa').ErrorMessageConfig} ErrorMessageConfig
13
+ */
14
+ /**
15
+ * @typedef {object} WordcountConfigOptions
16
+ * @property {ErrorMessageConfig} errorMsgMax Error message to use on max length failure
17
+ * @property {ErrorMessageConfig} errorMsgMin Error message to use on min length failure
18
+ * @property {number} max Maximum string length allowed
19
+ * @property {number} min Minimum string length required
20
+ */
7
21
  /**
8
22
  * Test the number of words in a string.
9
23
  *
10
- * Config options:
11
- * string|object errorMsgMax = Error message to use on max length failure
12
- * string|object errorMsgMin = Error message to use on min length failure
13
- * int max = Maximum word count allowed
14
- * int min = Minimum word count required
24
+ * See {@link WordcountConfigOptions} for `make()` options.
25
+ *
26
+ * @memberof Validators
27
+ * @augments ValidatorFactory
15
28
  */
16
- const ValidatorFactory_js_1 = __importDefault(require("../ValidatorFactory.js"));
17
- const ValidationError_js_1 = __importDefault(require("../ValidationError.js"));
18
- const utils_js_1 = require("../utils.js");
19
29
  class WordCount extends ValidatorFactory_js_1.default {
20
30
  constructor() {
21
31
  super(...arguments);
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Generate a URL pointing at a particular waypoint.
3
3
  *
4
+ * @memberof module:@dwp/govuk-casa
4
5
  * @param {object} obj Options
5
6
  * @param {string} obj.waypoint Waypoint
6
7
  * @param {string} obj.mountUrl Mount URL
@@ -1,13 +1,23 @@
1
1
  "use strict";
2
2
  /**
3
+ * @access private
3
4
  * @typedef {import('./index').JourneyContext} JourneyContext
4
5
  */
5
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ /** @access private */
6
8
  const reUrlProtocolExtract = /^url:\/\/(.+)$/i;
9
+ /**
10
+ * Sanitise a waypoint string.
11
+ *
12
+ * @access private
13
+ * @param {string} w Waypoint
14
+ * @returns {string} Sanitised waypoint
15
+ */
7
16
  const sanitiseWaypoint = (w) => w.replace(/[^/a-z0-9_-]/ig, '').replace(/\/+/g, '/');
8
17
  /**
9
18
  * Generate a URL pointing at a particular waypoint.
10
19
  *
20
+ * @memberof module:@dwp/govuk-casa
11
21
  * @param {object} obj Options
12
22
  * @param {string} obj.waypoint Waypoint
13
23
  * @param {string} obj.mountUrl Mount URL
@@ -35,12 +35,28 @@ function dataMiddleware({ plan, events, }) {
35
35
  // Grab chosen language from session
36
36
  req.casa.journeyContext.nav.language = req.session.language;
37
37
  /* ------------------------------------------------- Template variables */
38
- // Figure out the mount URL of the current request
38
+ // Capture mount URL that will be used in generating all browser URLs
39
39
  const mountUrl = (0, utils_js_1.validateUrlPath)(`${req.baseUrl}/`.replace(/\/+/g, '/'));
40
- // For browser performance reasons, CASA's static assets are potentially
41
- // delivered over a different route to the `mountUrl` if this CASA app has
42
- // been mounted on a parameterised route.
43
- const staticMountUrl = (0, utils_js_1.validateUrlPath)(`${(0, utils_js_1.stripProxyFromUrlPath)(req)}`.replace(/\/+/g, '/'));
40
+ // If this CASA app is mounted on a parameterised route, then all of its
41
+ // static assets (served by `staticRouter`) will, by default, be served
42
+ // from that dynamic path, for example:
43
+ // markup: <link href="{{ mountUrl }}css/static.css" />
44
+ // resolved URL: /mount/<some-id-here>/css/static.css
45
+ // baseUrl: /mount/<some-id>
46
+ //
47
+ // From a performance point of view, this is very inefficient as we can't
48
+ // take advantage of any intermediate caches. So we instead provide am
49
+ // alternative URL path in the `staticMountUrl` property that excludes the
50
+ // parameterised element, eg:
51
+ // markup: <link href="{{ staticMountUrl }}css/static.css" />
52
+ // resolved URL: /mount/css/static.css
53
+ // baseUrl: /mount
54
+ //
55
+ // As the staticRouter is mounted on both the CASA app, and its internal
56
+ // Router, the `baseUrl` is different in each case, so we cannot rely
57
+ // on it to be consistent. Hence the need for this property, which will
58
+ // always be the non-parameterised version of the baseUrl.
59
+ const staticMountUrl = (0, utils_js_1.validateUrlPath)(`${req.unparameterisedBaseUrl}/`.replace(/\/+/g, '/'));
44
60
  // CASA and userland templates
45
61
  res.locals.casa = {
46
62
  mountUrl,
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  const JourneyContext_js_1 = __importDefault(require("../lib/JourneyContext.js"));
11
11
  /**
12
+ * @access private
12
13
  * @typedef {import('../lib/field').PageField} PageField
13
14
  */
14
15
  /**
@@ -9,6 +9,7 @@ const GA_DOMAIN = '*.google-analytics.com';
9
9
  const GA_ANALYTICS_DOMAIN = '*.analytics.google.com';
10
10
  const GTM_DOMAIN = 'www.googletagmanager.com';
11
11
  /**
12
+ * @access private
12
13
  * @typedef {import('../casa').HelmetConfigurator} HelmetConfigurator
13
14
  */
14
15
  /**
@@ -9,6 +9,7 @@ const waypoint_url_js_1 = __importDefault(require("../lib/waypoint-url.js"));
9
9
  const logger_js_1 = __importDefault(require("../lib/logger.js"));
10
10
  const log = (0, logger_js_1.default)('middleware:steer-journey');
11
11
  /**
12
+ * @access private
12
13
  * @typedef {import('../lib/Plan')} Plan
13
14
  */
14
15
  /**
@@ -40,7 +41,7 @@ exports.default = ({ waypoint, plan, }) => [
40
41
  // Edit mode
41
42
  // Cannot be in edit mode if we're already on the `editorigin` URL
42
43
  if (req.casa.editMode) {
43
- const { pathname: currentPathname } = new URL(req.originalUrl, 'http://placeholder.test/');
44
+ const { pathname: currentPathname } = new URL(req.originalUrl, 'https://placeholder.test/');
44
45
  if (req.casa.editOrigin === currentPathname) {
45
46
  log.debug(`Disabling edit mode as we are on the edit origin (${req.casa.editOrigin})`);
46
47
  req.casa.editMode = false;
@@ -22,12 +22,16 @@ const logger_js_1 = __importDefault(require("../lib/logger.js"));
22
22
  const log = (0, logger_js_1.default)('casa:middleware:strip-proxy-path');
23
23
  exports.default = ({ mountUrl = '/', }) => [
24
24
  (req, res, next) => {
25
+ // TODO:
26
+ // We _may_ have to start tracking the various prefix in order to differentiate
27
+ // between a proxy prefix, and a parent app's path.
28
+ var _a;
25
29
  // Assume everything before `mountUrl` is the proxy path prefix and remove it
26
- const originalBaseUrl = req.baseUrl;
30
+ req.originalBaseUrl = (_a = req.originalBaseUrl) !== null && _a !== void 0 ? _a : req.baseUrl;
27
31
  req.baseUrl = mountUrl.replace(/\/$/, '');
28
32
  // If the app has been mounted directly on the specific `mountUrl`, then
29
33
  // there's nothing we need to do and can let this request pass-through.
30
- if (req.baseUrl === originalBaseUrl) {
34
+ if (req.baseUrl === req.originalBaseUrl) {
31
35
  next();
32
36
  }
33
37
  else if (req.__CASA_BASE_URL_REWRITTEN__) {
@@ -20,6 +20,8 @@ exports.default = ({ waypoint, fields = [], plan, }) => [
20
20
  (req, res, next) => {
21
21
  var _a, _b;
22
22
  const mountUrl = `${req.baseUrl}/`;
23
+ // Run validators for every field to build up a compelte list of errors
24
+ // currently associated with this waypoint.
23
25
  let errors = [];
24
26
  for (let i = 0, l = fields.length; i < l; i++) {
25
27
  /* eslint-disable security/detect-object-injection */
@@ -27,6 +29,7 @@ exports.default = ({ waypoint, fields = [], plan, }) => [
27
29
  const field = fields[i];
28
30
  const fieldName = field.name;
29
31
  const fieldValue = (_b = (_a = req.casa.journeyContext.data) === null || _a === void 0 ? void 0 : _a[waypoint]) === null || _b === void 0 ? void 0 : _b[fieldName];
32
+ // (type = ValidateContext)
30
33
  const context = {
31
34
  fieldName,
32
35
  fieldValue,
@@ -1,11 +1,22 @@
1
+ /**
2
+ * @typedef {object} AncillaryRouterOptions Options to configure static router
3
+ * @property {number} sessionTtl Session timeout (seconds)
4
+ */
1
5
  /**
2
6
  * Create an instance of the ancillary router.
3
7
  *
4
- * @param {Object} options = Optiona
5
- * @param {number} options.sessionTtl Session timeout (seconds)
6
- * @returns {MutableRouter} Mutable router
8
+ * @access private
9
+ * @param {AncillaryRouterOptions} options Options
10
+ * @returns {MutableRouter} ExpressJS Router instance
11
+ */
12
+ export default function ancillaryRouter({ sessionTtl, }: AncillaryRouterOptions): MutableRouter;
13
+ /**
14
+ * Options to configure static router
7
15
  */
8
- export default function ancillaryRouter({ sessionTtl, }: {
16
+ export type AncillaryRouterOptions = {
17
+ /**
18
+ * Session timeout (seconds)
19
+ */
9
20
  sessionTtl: number;
10
- }): MutableRouter;
21
+ };
11
22
  import MutableRouter from "../lib/MutableRouter.js";
@@ -4,12 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const MutableRouter_js_1 = __importDefault(require("../lib/MutableRouter.js"));
7
+ /**
8
+ * @typedef {object} AncillaryRouterOptions Options to configure static router
9
+ * @property {number} sessionTtl Session timeout (seconds)
10
+ */
7
11
  /**
8
12
  * Create an instance of the ancillary router.
9
13
  *
10
- * @param {Object} options = Optiona
11
- * @param {number} options.sessionTtl Session timeout (seconds)
12
- * @returns {MutableRouter} Mutable router
14
+ * @access private
15
+ * @param {AncillaryRouterOptions} options Options
16
+ * @returns {MutableRouter} ExpressJS Router instance
13
17
  */
14
18
  function ancillaryRouter({ sessionTtl, }) {
15
19
  // Router