@dwp/govuk-casa 8.7.8 → 8.7.12

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.
@@ -15,13 +15,6 @@ export default class CasaTemplateLoader extends FileSystemLoader {
15
15
  * @param {FileSystemLoaderOptions} opts Loader options
16
16
  */
17
17
  constructor(searchPaths: string[], opts: FileSystemLoaderOptions);
18
- /**
19
- * Extract the source from the given template file.
20
- *
21
- * @param {string} name Source file path
22
- * @returns {string} Source contents of template
23
- */
24
- getSource(name: string): string;
25
18
  /**
26
19
  * Add a modification function to the loader.
27
20
  *
@@ -34,5 +27,6 @@ export default class CasaTemplateLoader extends FileSystemLoader {
34
27
  #private;
35
28
  }
36
29
  export type FileSystemLoaderOptions = import('nunjucks').FileSystemLoaderOptions;
30
+ export type LoaderSource = import('nunjucks').LoaderSource;
37
31
  export type BlockModifier = (templateName: string) => string;
38
32
  import { FileSystemLoader } from "nunjucks";
@@ -17,6 +17,10 @@ const nunjucks_1 = require("nunjucks");
17
17
  * @access private
18
18
  * @typedef {import('nunjucks').FileSystemLoaderOptions} FileSystemLoaderOptions
19
19
  */
20
+ /**
21
+ * @access private
22
+ * @typedef {import('nunjucks').LoaderSource} LoaderSource
23
+ */
20
24
  const VALID_BLOCKS = [
21
25
  'beforeContent',
22
26
  'bodyEnd',
@@ -58,7 +62,7 @@ class CasaTemplateLoader extends nunjucks_1.FileSystemLoader {
58
62
  * Extract the source from the given template file.
59
63
  *
60
64
  * @param {string} name Source file path
61
- * @returns {string} Source contents of template
65
+ * @returns {LoaderSource} Source contents of template
62
66
  */
63
67
  getSource(name) {
64
68
  const source = super.getSource(name);
@@ -214,6 +214,7 @@ export type PlanRoute = import('../casa').PlanRoute;
214
214
  export type PlanRouteCondition = import('../casa').PlanRouteCondition;
215
215
  export type PlanTraverseOptions = import('../casa').PlanTraverseOptions;
216
216
  export type PlanArbiter = import('../casa').PlanArbiter;
217
+ export type Graph = any;
217
218
  export type PlanConstructorOptions = {
218
219
  /**
219
220
  * Check page validity before conditions
package/dist/lib/Plan.js CHANGED
@@ -35,6 +35,10 @@ const log = (0, logger_js_1.default)('lib:plan');
35
35
  * @access private
36
36
  * @typedef {import('../casa').PlanArbiter} PlanArbiter
37
37
  */
38
+ /**
39
+ * @access private
40
+ * @typedef {import('graphlib').Graph} Graph
41
+ */
38
42
  /**
39
43
  * @typedef {object} PlanConstructorOptions
40
44
  * @property {boolean} [validateBeforeRouteCondition=true] Check page validity before conditions
@@ -502,8 +506,8 @@ class Plan {
502
506
  });
503
507
  // When there's more than one candidate route to take, we need help to choose
504
508
  if (target.length > 1) {
505
- const satisifed = target.map((t) => `${t.v} -> ${t.w}`);
506
- log.debug(`Multiple routes were satisfied for "${routeName}" from "${startWP}" (${satisifed.join(' / ')}). Deciding how to resolve ...`);
509
+ const satisfied = target.map((t) => `${t.v} -> ${t.w}`);
510
+ log.debug(`Multiple routes were satisfied for "${routeName}" from "${startWP}" (${satisfied.join(' / ')}). Deciding how to resolve ...`);
507
511
  if (arbiter === 'auto') {
508
512
  log.debug('Using automatic arbitration process');
509
513
  const targetNames = target.map(({ w }) => w);
@@ -53,7 +53,7 @@ class ValidationError {
53
53
  focusSuffix: [],
54
54
  });
55
55
  }
56
- // No contextual changes applicable; return ValidationErorr made from the
56
+ // No contextual changes applicable; return ValidationError made from the
57
57
  // original object
58
58
  if (isPlainObject(errorMsg)) {
59
59
  return new ValidationError(errorMsg);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Validates and sanitises i18n obejct.
2
+ * Validates and sanitises i18n object.
3
3
  *
4
4
  * @access private
5
5
  * @param {object} i18n Object to validate.
@@ -20,7 +20,7 @@ const utils_js_1 = require("./utils.js");
20
20
  const log = (0, logger_js_1.default)('lib:configuration-ingestor');
21
21
  const echo = (a) => (a);
22
22
  /**
23
- * Validates and sanitises i18n obejct.
23
+ * Validates and sanitises i18n object.
24
24
  *
25
25
  * @access private
26
26
  * @param {object} i18n Object to validate.
@@ -29,8 +29,34 @@ const combineMerge = (target, source, options) => {
29
29
  });
30
30
  return destination;
31
31
  };
32
+ // Allows objects to be deepmerged and retain their type, without becoming [object Object]
33
+ // ref: https://github.com/jonschlinkert/is-plain-object/blob/master/is-plain-object.js
34
+ function isObject(o) {
35
+ return Object.prototype.toString.call(o) === '[object Object]';
36
+ }
37
+ function isPlainObjectOrArray(o) {
38
+ if (Array.isArray(o)) {
39
+ return true;
40
+ }
41
+ if (isObject(o) === false) {
42
+ return false;
43
+ }
44
+ const ctor = o.constructor;
45
+ if (ctor === undefined) {
46
+ return true;
47
+ }
48
+ const prot = ctor.prototype;
49
+ if (isObject(prot) === false) {
50
+ return false;
51
+ }
52
+ // eslint-disable-next-line no-prototype-builtins
53
+ if (prot.hasOwnProperty('isPrototypeOf') === false) {
54
+ return false;
55
+ }
56
+ return true;
57
+ }
32
58
  function mergeObjects(...objects) {
33
- return deepmergeAll([Object.create(null), ...objects], { arrayMerge: combineMerge });
59
+ return deepmergeAll([Object.create(null), ...objects], { arrayMerge: combineMerge, isMergeableObject: isPlainObjectOrArray });
34
60
  }
35
61
  exports.mergeObjects = mergeObjects;
36
62
  /**
@@ -3,7 +3,7 @@
3
3
  * @typedef {import('../casa').GlobalHook | import('../casa').PageHook} Hook
4
4
  */
5
5
  /**
6
- * Test is a value can be stringifed (numbers or strings)
6
+ * Test is a value can be stringified (numbers or strings)
7
7
  *
8
8
  * @access private
9
9
  * @param {any} value Item to test
package/dist/lib/utils.js CHANGED
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.notProto = exports.validateHookPath = exports.validateHookName = exports.validateView = exports.validateUrlPath = exports.validateWaypoint = exports.resolveMiddlewareHooks = exports.isEmpty = exports.stringifyInput = exports.isStringable = void 0;
8
8
  /**
9
- * Test is a value can be stringifed (numbers or strings)
9
+ * Test is a value can be stringified (numbers or strings)
10
10
  *
11
11
  * @access private
12
12
  * @param {any} value Item to test
@@ -124,7 +124,7 @@ class DateObject extends ValidatorFactory_js_1.default {
124
124
  if (!Object.prototype.hasOwnProperty.call(value, 'yyyy') || !value.yyyy) {
125
125
  errorMsg.focusSuffix.push('[yyyy]');
126
126
  }
127
- // If the date is invalid, but not specific parts have been highighted in
127
+ // If the date is invalid, but not specific parts have been highlighted in
128
128
  // error, then highlight all inputs, focusing on the [dd] first
129
129
  if (!valid && !errorMsg.focusSuffix.length) {
130
130
  errorMsg.focusSuffix = ['[dd]', '[mm]', '[yyyy]'];
@@ -10,7 +10,7 @@
10
10
  * Test if value is present.
11
11
  *
12
12
  * Value is required. The following values will fail this rule:
13
- * (all values that satisify `isEmpty()`) plus '\s'
13
+ * (all values that satisfy `isEmpty()`) plus '\s'
14
14
  *
15
15
  * See {@link RequiredConfigOptions} for `make()` options.
16
16
  *
@@ -21,7 +21,7 @@ const { isPlainObject } = lodash_1.default; // CommonJS
21
21
  * Test if value is present.
22
22
  *
23
23
  * Value is required. The following values will fail this rule:
24
- * (all values that satisify `isEmpty()`) plus '\s'
24
+ * (all values that satisfy `isEmpty()`) plus '\s'
25
25
  *
26
26
  * See {@link RequiredConfigOptions} for `make()` options.
27
27
  *
@@ -26,7 +26,7 @@ const JourneyContext_js_1 = __importDefault(require("../lib/JourneyContext.js"))
26
26
  exports.default = ({ waypoint, fields = [], }) => [
27
27
  (req, res, next) => {
28
28
  // Store a copy of the journey context before modifying it. This is useful
29
- // for any comparison work that may be done in subseqent middleware.
29
+ // for any comparison work that may be done in subsequent middleware.
30
30
  req.casa.archivedJourneyContext = JourneyContext_js_1.default.fromContext(req.casa.journeyContext);
31
31
  // Ignore data for any non-persistent fields
32
32
  // ESLint disabled as `fields`, `i` and `name` are dev-controlled
@@ -40,7 +40,7 @@ exports.default = ({ mountUrl = '/', }) => [
40
40
  }
41
41
  else {
42
42
  // Strip the proxy path prefix from the original URL so that
43
- // subsequnt middleware sees the URL path as though proxy wasn't there.
43
+ // subsequent middleware sees the URL path as though proxy wasn't there.
44
44
  // req.url will already have the proxy prefix and mountUrl removed.
45
45
  /* eslint-disable security/detect-non-literal-regexp */
46
46
  log.trace(`req.originalUrl before proxy stripping: ${req.originalUrl}`);
@@ -20,7 +20,7 @@ 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
23
+ // Run validators for every field to build up a complete list of errors
24
24
  // currently associated with this waypoint.
25
25
  let errors = [];
26
26
  for (let i = 0, l = fields.length; i < l; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwp/govuk-casa",
3
- "version": "8.7.8",
3
+ "version": "8.7.12",
4
4
  "description": "A framework for building GOVUK Collect-And-Submit-Applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -50,52 +50,52 @@
50
50
  "cookie-parser": "1.4.6",
51
51
  "csurf": "1.11.0",
52
52
  "debug": "4.3.4",
53
- "deepmerge": "4.2.2",
53
+ "deepmerge": "4.3.1",
54
54
  "express": "4.18.2",
55
55
  "express-session": "1.17.3",
56
- "govuk-frontend": "4.4.1",
56
+ "govuk-frontend": "4.5.0",
57
57
  "graphlib": "2.1.8",
58
58
  "helmet": "6.0.1",
59
- "i18next": "22.4.9",
60
- "i18next-http-middleware": "3.2.2",
59
+ "i18next": "22.4.12",
60
+ "i18next-http-middleware": "3.3.0",
61
61
  "js-yaml": "4.1.0",
62
62
  "lodash": "4.17.21",
63
- "luxon": "3.2.1",
63
+ "luxon": "3.3.0",
64
64
  "nunjucks": "3.2.3",
65
65
  "path-to-regexp": "6.2.1",
66
66
  "uuid": "9.0.0",
67
- "validator": "13.7.0"
67
+ "validator": "13.9.0"
68
68
  },
69
69
  "devDependencies": {
70
- "@babel/core": "7.20.12",
71
- "@babel/eslint-parser": "7.19.1",
70
+ "@babel/core": "7.21.3",
71
+ "@babel/eslint-parser": "7.21.3",
72
72
  "@babel/preset-env": "7.20.2",
73
- "@ckeditor/jsdoc-plugins": "32.1.0",
74
- "@commitlint/config-conventional": "17.4.2",
75
- "@dwp/casa-spiderplan": "2.5.3",
76
- "@dwp/casa-spiderplan-a11y-plugin": "0.1.9",
77
- "@dwp/casa-spiderplan-zap-plugin": "0.1.5",
78
- "@dwp/eslint-config-base": "6.0.0",
79
- "@types/express": "4.17.15",
80
- "@types/node": "18.11.18",
81
- "@types/nunjucks": "3.2.1",
82
- "c8": "7.12.0",
73
+ "@ckeditor/jsdoc-plugins": "35.0.3",
74
+ "@commitlint/config-conventional": "17.4.4",
75
+ "@dwp/casa-spiderplan": "2.5.4",
76
+ "@dwp/casa-spiderplan-a11y-plugin": "0.1.10",
77
+ "@dwp/casa-spiderplan-zap-plugin": "0.1.6",
78
+ "@dwp/eslint-config-base": "6.1.0",
79
+ "@types/express": "4.17.17",
80
+ "@types/node": "18.15.3",
81
+ "@types/nunjucks": "3.2.2",
82
+ "c8": "7.13.0",
83
83
  "chai": "4.3.7",
84
84
  "cheerio": "1.0.0-rc.12",
85
- "commitlint": "17.4.2",
85
+ "commitlint": "17.4.4",
86
86
  "docdash": "2.0.1",
87
- "eslint": "8.32.0",
87
+ "eslint": "8.36.0",
88
88
  "eslint-plugin-no-unsafe-regex": "1.0.0",
89
- "eslint-plugin-security": "1.6.0",
89
+ "eslint-plugin-security": "1.7.1",
90
90
  "eslint-plugin-sonarjs": "0.18.0",
91
- "fast-check": "3.6.2",
92
- "jsdoc": "4.0.0",
91
+ "fast-check": "3.7.1",
92
+ "jsdoc": "4.0.2",
93
93
  "jsdoc-tsimport-plugin": "1.0.5",
94
94
  "mocha": "10.2.0",
95
- "sass": "1.57.1",
96
- "sinon": "15.0.1",
95
+ "sass": "1.59.3",
96
+ "sinon": "15.0.2",
97
97
  "sinon-chai": "3.7.0",
98
98
  "supertest": "6.3.3",
99
- "typescript": "4.9.4"
99
+ "typescript": "4.9.5"
100
100
  }
101
101
  }
@@ -10,7 +10,6 @@ Custom parameters:
10
10
  * `casaErrors` - form errors (just pass `formErrors`)
11
11
  * `casaWithAnalytics` - enable DWP's conventional Google Analytics attributes (`data-ga-question` and `data-ga-answer`) - `false` by default; **IMPORTANT: DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google**
12
12
 
13
-
14
13
  ## Example usage
15
14
 
16
15
  Basic example:
@@ -76,7 +75,7 @@ casaGovukCheckboxes({
76
75
 
77
76
  ## Displaying errors
78
77
 
79
- ref: https://design-system.service.gov.uk/components/error-summary/
78
+ ref: <https://design-system.service.gov.uk/components/error-summary/>
80
79
 
81
80
  The error summary link must set focus on the first checkbox in the group. Unless you have specified an explicit `id` for the first item in the list, this macro will explicitly set that `id` to `f-<name>`, e.g. `f-preferences` in order for links from the error summary to work as expected.
82
81
 
@@ -89,4 +88,4 @@ The following attributes will be attached to each `<input>` option if `casaWithA
89
88
 
90
89
  These are the conventions used by DWP.
91
90
 
92
- **IMPORTANT: DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google**
91
+ > **IMPORTANT:** DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google
@@ -88,7 +88,8 @@ The `formatDateObject()` Nunjucks filter will take a date object captured with t
88
88
  ```nunjucks
89
89
  {{ myDate | formatDateObject }}
90
90
  ```
91
- ```
91
+
92
+ ```nunjucks
92
93
  1 January 1980
93
94
  ```
94
95
 
@@ -97,6 +98,7 @@ You can also pass a locale:
97
98
  ```nunjucks
98
99
  {{ myDate | formatDateObject({ locale: 'cy' }) }}
99
100
  ```
100
- ```
101
+
102
+ ```nunjucks
101
103
  1 Ionawr 1980
102
104
  ```
@@ -5,7 +5,8 @@ Component to wrap your form inputs in a `<form>` that contains all the required
5
5
  A "Continue" button (and "Cancel" link if in edit mode) will also be added.
6
6
 
7
7
  - [1.3.5: Identify Input Purpose](https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html)
8
- - [<form>: The Form element - autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-autocomplete)
8
+ - [`<form>`: The Form element - autocomplete](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-autocomplete)
9
+
9
10
  ## Example usage
10
11
 
11
12
  ```nunjucks
@@ -51,7 +52,7 @@ Note that the submit button is configured to prevent double-clicks and avoid dup
51
52
  | Name | Type | Required | Description |
52
53
  |------|------|----------|-------------|
53
54
  | `formUrl` | string | Yes | The form's "action", available in a `formUrl` template variable |
54
- | `autoComplete` | string | No | Allows you to override the autocomplete paramater - the default value is 'off'
55
+ | `autoComplete` | string | No | Allows you to override the autocomplete parameter - the default value is 'off'
55
56
  | `csrfToken` | string | Yes | Token used to protect form from CSRF (available to user's templates via the global `casa.csrfToken` variable) |
56
57
  | `inEditMode` | boolean | No | Toggle edit-mode of the form (available to page templates using default GET/POST handlers via the local `inEditMode` variable) |
57
58
  | `editOriginUrl` | string | No | Absolute URL to the page from which the edit request came (defaults to `review`) (available to user's templates using default GET/POST handlers via the local `editOriginUrl` variable) |
@@ -57,7 +57,7 @@ If you want one of the radio items to toggle the display of an element:
57
57
 
58
58
  ## Displaying errors
59
59
 
60
- ref: https://design-system.service.gov.uk/components/error-summary/
60
+ ref: <https://design-system.service.gov.uk/components/error-summary/>
61
61
 
62
62
  The error summary link must set focus on the first radio in the group. Unless you have specified an explicit `id` for the first item in the list, this macro will explicitly set that `id` to `f-<name>`, e.g. `f-preferences` in order for links from the error summary to work as expected.
63
63
 
@@ -70,4 +70,4 @@ The following attributes will be attached to each `<input>` option if `casaWithA
70
70
 
71
71
  These are the conventions used by DWP.
72
72
 
73
- **IMPORTANT: DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google**
73
+ > **IMPORTANT:** DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
  {% block skipLink %}
10
- {# Harcoding content for the skip link as t() may not be availble on some error pages #}
10
+ {# Hardcoding content for the skip link as t() may not be available on some error pages #}
11
11
  {{ govukSkipLink({
12
12
  href: '#main-content',
13
13
  text: "Neidio i'r prif gynnwys" if locale === 'cy' else 'Skip to main content'