@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
@@ -2,27 +2,28 @@ const { isObjectWithKeys, isObjectType, normalizeHtmlObjectPath } = require('../
2
2
  const JourneyContext = require('../../lib/JourneyContext.js');
3
3
 
4
4
  /**
5
- * Converts an array of functions to a nested callback, eg:
6
- * [ | function nested(req, res, next) {-
7
- * function a(req, res, next) {- | a(req, res, () => {-
8
- * ... | ...
9
- * next(); | b(req, res, () => {-
10
- * }, | ...
11
- * function b(req, res, next) {- | c(req, res, () => {-
12
- * ... | ...
13
- * next(); | next();
14
- * }, | });
15
- * function c(req, res, next) {- | })
16
- * ... | });
17
- * next(); | }
18
- * }, |
19
- * ] |
20
- * @param {Logger} logger Request-specific Logger instance
21
- * @param {string} hookName Name of the hook being called
22
- * @param {string} waypointId id of waypoint
23
- * @param {array} hooks array of middleware like functions
24
- * @return {function} nested function
25
- */
5
+ * Converts an array of functions to a nested callback, eg:
6
+ * [ | function nested(req, res, next) {-
7
+ * function a(req, res, next) {- | a(req, res, () => {-
8
+ * ... | ...
9
+ * next(); | b(req, res, () => {-
10
+ * }, | ...
11
+ * function b(req, res, next) {- | c(req, res, () => {-
12
+ * ... | ...
13
+ * next(); | next();
14
+ * }, | });
15
+ * function c(req, res, next) {- | })
16
+ * ... | });
17
+ * next(); | }
18
+ * }, |
19
+ * ] |.
20
+ *
21
+ * @param {object} logger Request-specific Logger instance.
22
+ * @param {string} hookName Name of the hook being called.
23
+ * @param {string} waypointId ID of waypoint.
24
+ * @param {Array} hooks Array of middleware like functions.
25
+ * @returns {Function} Nested function.
26
+ */
26
27
  function nestHooks(logger, hookName, waypointId, hooks) {
27
28
  return hooks.reduce((inital, hook, hookNumber) => {
28
29
  if (typeof hook === 'function') {
@@ -43,12 +44,12 @@ function nestHooks(logger, hookName, waypointId, hooks) {
43
44
  * The returned Promise will always resolve unless the hook function ends the
44
45
  * response with something like `res.send()`.
45
46
  *
46
- * @param {Logger} logger Request-specific Logger instance
47
- * @param {request} req Express request
48
- * @param {response} res Express response
49
- * @param {object} pageMeta Metadata of page being processed
50
- * @param {string} hookName Name of hook to execute
51
- * @return {Promise} Promise
47
+ * @param {object} logger Request-specific Logger instance.
48
+ * @param {object} req Express request.
49
+ * @param {object} res Express response.
50
+ * @param {object} pageMeta Metadata of page being processed.
51
+ * @param {string} hookName Name of hook to execute.
52
+ * @returns {Promise} Promise.
52
53
  */
53
54
  function executeHook(logger, req = {}, res = {}, pageMeta = {}, hookName = '') {
54
55
  return new Promise((resolve, reject) => {
@@ -83,12 +84,12 @@ function executeHook(logger, req = {}, res = {}, pageMeta = {}, hookName = '') {
83
84
  * Where no validators are defined for the requested waypoint, we will store
84
85
  * nothing in the session.
85
86
  *
86
- * @param {Logger} logger Request-specific logger instance
87
- * @param {object} pageMeta Page meta object
88
- * @param {object} data Data to be pruned
89
- * @param {JourneyContext} journeyContext Request's journey context
90
- * @returns {object} The pruned data
91
- * @throws {TypeError} When given invalid argument types
87
+ * @param {object} logger Request-specific logger instance.
88
+ * @param {object} pageMeta Page meta object.
89
+ * @param {object} data Data to be pruned.
90
+ * @param {JourneyContext} journeyContext Request's journey context.
91
+ * @returns {object} The pruned data.
92
+ * @throws {TypeError} When given invalid argument types.
92
93
  */
93
94
  function extractSessionableData(
94
95
  logger,
@@ -149,9 +150,9 @@ function extractSessionableData(
149
150
  /**
150
151
  * Run modifying functions against the specified field.
151
152
  *
152
- * @param {object} fieldValue Value to modify
153
- * @param {array|function} gatherModifiers Either an array of functions or a single function
154
- * @return {mixed} Modified value
153
+ * @param {object} fieldValue Value to modify.
154
+ * @param {Array | Function} gatherModifiers Either an array of functions or a single function.
155
+ * @returns {any} Modified value.
155
156
  */
156
157
  function runGatherModifiers(fieldValue, gatherModifiers = []) {
157
158
  const modifiers = Array.isArray(gatherModifiers) ? gatherModifiers : [gatherModifiers];
@@ -12,7 +12,7 @@ module.exports = (pageMeta = {}) => (req, res, next) => {
12
12
  /**
13
13
  * Run validation process.
14
14
  *
15
- * @return {Promise} Promise
15
+ * @returns {Promise} Promise.
16
16
  */
17
17
  function runValidation() {
18
18
  let result;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Enhances `req` with:
5
5
  * object session = Current session
6
- * model/claim claim = Current Claim state
6
+ * model/claim claim = Current Claim state.
7
7
  */
8
8
 
9
9
  const logger = require('../../lib/Logger.js')('session');
@@ -39,9 +39,11 @@ const onehour = 3600000;
39
39
  * govukFrontend: govuk-frontend npm package path <string>,
40
40
  * govukTemplateJinja: govuk_template_jinja npm package path <string>
41
41
  * govukCasa: @dwp/govuk-casa npm package path <string>
42
+ * skipAssetsGeneration: boolean value to determine whether to skip the preparation of assets
42
43
  *
43
44
  * @param {object} args See above
44
45
  * @returns {void}
46
+ * @throws {ReferenceError}
45
47
  */
46
48
  module.exports = (args) => {
47
49
  const {
@@ -54,6 +56,7 @@ module.exports = (args) => {
54
56
  govukTemplateJinja = '',
55
57
  govukCasa = '',
56
58
  } = Object.create(null),
59
+ skipAssetsGeneration,
57
60
  } = args;
58
61
 
59
62
  const compiledAssetsDir = path.resolve(cAssetsDir);
@@ -73,13 +76,15 @@ module.exports = (args) => {
73
76
 
74
77
  const prefixCasa = `${proxyMountUrl}/govuk/casa`.replace(/\/+/g, '/');
75
78
 
76
- logger.trace('Calling prepare-assets');
77
- mwPrepareAssets({
78
- logger,
79
- npmGovukCasa: govukCasa,
80
- compiledAssetsDir,
81
- mountUrl,
82
- });
79
+ if (!skipAssetsGeneration) {
80
+ logger.trace('Calling prepare-assets');
81
+ mwPrepareAssets({
82
+ logger,
83
+ npmGovukCasa: govukCasa,
84
+ compiledAssetsDir,
85
+ mountUrl,
86
+ });
87
+ }
83
88
 
84
89
  logger.trace('Calling serve-assets');
85
90
  mwServeAssets({
@@ -2,11 +2,11 @@
2
2
  * Inject the configured `mountUrl` into the pre-compiled CSS sources, and copy
3
3
  * all CSS and JS to the `compiledAssetsDir` directory.
4
4
  *
5
- * @param {string} npmGovukCasa Path to root of `govuk-casa` module
6
- * @param {string} compiledAssetsDir Directory where compiled assets are saved
7
- * @param {string} mountUrl Mount point
5
+ * @param {string} npmGovukCasa Path to root of `govuk-casa` module.
6
+ * @param {string} compiledAssetsDir Directory where compiled assets are saved.
7
+ * @param {string} mountUrl Mount point.
8
8
  * @returns {void}
9
- * @throws {Exception} For any IO errors
9
+ * @throws {Error} For any IO errors.
10
10
  */
11
11
 
12
12
  const path = require('path');
@@ -2,10 +2,10 @@
2
2
  * Serve up all CASA assets from the `compiledAssetsDir` directory, and all
3
3
  * third party assets from their respective npm package directories.
4
4
  *
5
- * @param {express} app Express app
6
- * @param {Express.Static} static Static module from ExpressJS
7
- * @param {string} compiledAssetsDir Directory where static assets are saved
8
- * @param {string} prefixCasa Virtual URL prefix
5
+ * @param {Function} app Express app.
6
+ * @param {Function} static Static module from ExpressJS.
7
+ * @param {string} compiledAssetsDir Directory where static assets are saved.
8
+ * @param {string} prefixCasa Virtual URL prefix.
9
9
  * @returns {void}
10
10
  */
11
11
 
@@ -40,9 +40,6 @@ module.exports = (args) => {
40
40
  }, {
41
41
  url: `${proxyMountUrl}browserconfig.xml`,
42
42
  path: path.resolve(__dirname, '../../src/browserconfig.xml'),
43
- }, {
44
- url: `${proxyMountUrl}robots.txt`,
45
- path: path.resolve(__dirname, '../../src/robots.txt'),
46
43
  }];
47
44
 
48
45
  mounts.forEach((m) => {
package/package.json CHANGED
@@ -1,88 +1,86 @@
1
1
  {
2
2
  "name": "@dwp/govuk-casa",
3
- "version": "6.8.4",
3
+ "version": "6.9.0",
4
4
  "description": "Framework for creating basic GOVUK Collect-And-Submit-Applications",
5
5
  "main": "casa.js",
6
6
  "files": [
7
- "definitions/**/*",
8
- "dist/**/*",
9
- "lib/**/*",
10
- "locales/**/*",
11
- "middleware/**/*",
12
- "test/utils/**/*",
13
- "src/scss/*",
14
- "src/browserconfig.xml",
15
- "src/robots.txt",
16
- "views/**/*",
17
- "index.js",
18
- "casa.js",
19
- "**/*.d.ts",
20
- "!**/*/.DS_Store",
21
- "!**/*/.gitkeep",
22
- "!examples/**/*",
23
- "!test/unit/testdata/**/*"
7
+ "/definitions/**/*",
8
+ "/dist/**/*",
9
+ "/lib/**/*",
10
+ "/locales/**/*",
11
+ "/middleware/**/*",
12
+ "/test/utils/**/*",
13
+ "/src/scss/*",
14
+ "/src/browserconfig.xml",
15
+ "/views/**/*",
16
+ "/index.js",
17
+ "/casa.js",
18
+ "/**/*.d.ts",
19
+ "!/**/*/.DS_Store",
20
+ "!/**/*/.gitkeep",
21
+ "!/examples/**/*",
22
+ "!/test/unit/testdata/**/*"
24
23
  ],
25
24
  "engines": {
26
- "node": ">=12.0.0 <14.0.0"
25
+ "node": ">=12.0.0 <15.0.0"
27
26
  },
28
27
  "repository": {
29
28
  "type": "git",
30
29
  "url": "git@github.com:dwp/govuk-casa.git"
31
30
  },
32
31
  "dependencies": {
33
- "body-parser": "1.19.0",
32
+ "body-parser": "1.20.0",
34
33
  "colors": "1.4.0",
35
34
  "csurf": "1.11.0",
36
- "debug": "4.3.1",
37
- "fast-copy": "2.1.1",
38
- "fs-extra": "9.1.0",
39
- "govuk-frontend": "3.11.0",
35
+ "debug": "4.3.4",
36
+ "fast-copy": "2.1.2",
37
+ "fs-extra": "10.0.1",
38
+ "govuk-frontend": "3.14.0",
40
39
  "govuk_template_jinja": "0.26.0",
41
40
  "graphlib": "2.1.8",
42
41
  "klaw-sync": "6.0.0",
43
42
  "lodash.merge": "4.6.2",
44
- "moment": "2.29.1",
43
+ "moment": "2.29.2",
45
44
  "nunjucks": "3.2.3",
46
45
  "object-resolve-path": "1.1.1",
47
46
  "serve-favicon": "2.5.0",
48
47
  "uid-safe": "2.1.5",
49
- "validator": "13.5.2"
48
+ "validator": "13.7.0"
50
49
  },
51
50
  "devDependencies": {
52
- "@commitlint/cli": "12.0.0",
53
- "@commitlint/config-conventional": "12.0.0",
54
- "@commitlint/travis-cli": "12.0.0",
55
- "@dwp/commitlint-config-base": "1.1.0",
56
- "@dwp/eslint-config-base": "4.1.0",
57
- "@stryker-mutator/core": "4.4.1",
51
+ "@commitlint/cli": "16.2.3",
52
+ "@commitlint/config-conventional": "16.2.1",
53
+ "@commitlint/travis-cli": "16.2.3",
54
+ "@dwp/commitlint-config-base": "1.2.0",
55
+ "@dwp/eslint-config-base": "5.0.1",
56
+ "@stryker-mutator/core": "5.6.1",
58
57
  "@stryker-mutator/html-reporter": "3.1.0",
59
58
  "@stryker-mutator/javascript-mutator": "4.0.0",
60
59
  "@stryker-mutator/mocha-framework": "4.0.0",
61
- "@stryker-mutator/mocha-runner": "4.4.1",
62
- "autocannon": "7.0.4",
63
- "chai": "4.3.0",
60
+ "@stryker-mutator/mocha-runner": "5.6.1",
61
+ "autocannon": "7.8.1",
62
+ "chai": "4.3.6",
64
63
  "chai-as-promised": "7.1.1",
65
64
  "chai-http": "4.3.0",
66
- "cheerio": "1.0.0-rc.5",
67
- "conventional-changelog-cli": "2.1.1",
68
- "eslint": "7.20.0",
69
- "eslint-plugin-sonarjs": "0.6.0",
70
- "express": "4.17.1",
71
- "express-session": "1.17.1",
72
- "husky": "5.1.1",
73
- "jsdom": "16.4.0",
74
- "minimatch": "3.0.4",
75
- "mocha": "8.3.0",
76
- "npm-audit-resolver": "2.2.1",
65
+ "cheerio": "1.0.0-rc.10",
66
+ "conventional-changelog-cli": "2.2.2",
67
+ "eslint": "7.32.0",
68
+ "eslint-plugin-sonarjs": "0.13.0",
69
+ "express": "4.17.3",
70
+ "express-session": "1.17.2",
71
+ "husky": "7.0.4",
72
+ "jsdom": "19.0.0",
73
+ "minimatch": "5.0.1",
74
+ "mocha": "9.2.2",
77
75
  "nyc": "15.1.0",
78
76
  "proxyquire": "2.1.3",
79
- "sass": "1.32.8",
80
- "sinon": "9.2.4",
81
- "sinon-chai": "3.5.0",
82
- "supertest": "6.1.3",
83
- "uglify-js": "3.12.8",
77
+ "sass": "1.50.0",
78
+ "sinon": "13.0.1",
79
+ "sinon-chai": "3.7.0",
80
+ "supertest": "6.2.2",
81
+ "uglify-js": "3.15.3",
84
82
  "uuid": "8.3.2",
85
- "yargs": "16.2.0"
83
+ "yargs": "17.4.0"
86
84
  },
87
85
  "peerDependencies": {
88
86
  "express": "4.x",
@@ -100,7 +98,7 @@
100
98
  "quality:coverage": "nyc npm test",
101
99
  "quality:mutation": "stryker run",
102
100
  "security": "npm run security:vulnerable-packages",
103
- "security:vulnerable-packages": "check-audit --registry=https://registry.npmjs.org --json | node -e 'a=JSON.parse(fs.readFileSync(\"/dev/stdin\",\"utf-8\")).metadata.vulnerabilities;process.exit(a.high+a.critical);'",
101
+ "security:vulnerable-packages": "npm audit --production --registry=https://registry.npmjs.org --json | node -e 'a=JSON.parse(fs.readFileSync(\"/dev/stdin\",\"utf-8\")).metadata.vulnerabilities;process.exit(a.high+a.critical);'",
104
102
  "package:changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
105
103
  "start-pen-test-service": "PORT=4000 node ./test/penetration/server.js",
106
104
  "compile-static-assets": "node ./scripts/compile-sass.js && node ./scripts/compile-js.js",
package/src/js/casa.js CHANGED
@@ -7,10 +7,11 @@
7
7
  /**
8
8
  * Polyfill for attaching event listeners to elements.
9
9
  *
10
- * @param {HTMLElement} obj Element to which event is attached
11
- * @param {string} ev Event name
12
- * @param {Function} func Listener
10
+ * @param {HTMLElement} obj Element to which event is attached.
11
+ * @param {string} ev Event name.
12
+ * @param {Function} func Listener.
13
13
  * @returns {void}
14
+ * @throws {Error}
14
15
  */
15
16
  function attachEventPolyfill(obj, ev, func) {
16
17
  if (obj.addEventListener) {
@@ -60,7 +61,7 @@
60
61
  /**
61
62
  * Attach show/hide functionalty.
62
63
  *
63
- * @param {HTMLElement} node Element to init
64
+ * @param {HTMLElement} node Element to init.
64
65
  * @returns {void}
65
66
  */
66
67
  function casaV1InitShowHide(node) {
@@ -70,7 +71,8 @@
70
71
 
71
72
  /**
72
73
  * Show target.
73
- * @param {HTMLElement} targetEl Target
74
+ *
75
+ * @param {HTMLElement} targetEl Target.
74
76
  * @returns {void}
75
77
  */
76
78
  function showTarget(targetEl) {
@@ -80,7 +82,8 @@
80
82
 
81
83
  /**
82
84
  * Hide target.
83
- * @param {HTMLElement} targetEl Target
85
+ *
86
+ * @param {HTMLElement} targetEl Target.
84
87
  * @returns {void}
85
88
  */
86
89
  function hideTarget(targetEl) {
@@ -90,6 +93,7 @@
90
93
 
91
94
  /**
92
95
  * Click node.
96
+ *
93
97
  * @returns {void}
94
98
  */
95
99
  function clickNode() {
@@ -8,6 +8,15 @@
8
8
  {% endblock %}
9
9
 
10
10
 
11
+ {% block skipLink %}
12
+ {# Harcoding content for the skip link as t() may not be availble on some error pages #}
13
+ {{ govukSkipLink({
14
+ href: '#main-content',
15
+ text: 'Neidio i\'r prif gynnwys' if locale === 'cy' else 'Skip to main content'
16
+ }) }}
17
+ {% endblock %}
18
+
19
+
11
20
  {% block bodyStart %}
12
21
  <div id="global-cookie-message" class="js-hidden">
13
22
  {% include "casa/partials/cookie_message.njk" %}
package/src/robots.txt DELETED
@@ -1,2 +0,0 @@
1
- User-agent: *
2
- Disallow: /