@dwp/govuk-casa 9.3.2 → 9.3.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 (93) hide show
  1. package/dist/assets/css/casa.css +1 -1
  2. package/dist/assets/css/casa.css.map +1 -1
  3. package/dist/lib/CasaTemplateLoader.js +22 -28
  4. package/dist/lib/CasaTemplateLoader.js.map +1 -1
  5. package/dist/lib/JourneyContext.js +86 -112
  6. package/dist/lib/JourneyContext.js.map +1 -1
  7. package/dist/lib/MutableRouter.d.ts +9 -0
  8. package/dist/lib/MutableRouter.js +73 -81
  9. package/dist/lib/MutableRouter.js.map +1 -1
  10. package/dist/lib/Plan.js +15 -26
  11. package/dist/lib/Plan.js.map +1 -1
  12. package/dist/lib/ValidationError.js +3 -3
  13. package/dist/lib/ValidationError.js.map +1 -1
  14. package/dist/lib/configuration-ingestor.js +21 -10
  15. package/dist/lib/configuration-ingestor.js.map +1 -1
  16. package/dist/lib/configure.js +18 -17
  17. package/dist/lib/configure.js.map +1 -1
  18. package/dist/lib/end-session.js +5 -5
  19. package/dist/lib/end-session.js.map +1 -1
  20. package/dist/lib/field.js +56 -65
  21. package/dist/lib/field.js.map +1 -1
  22. package/dist/lib/nunjucks-filters.js +6 -6
  23. package/dist/lib/nunjucks-filters.js.map +1 -1
  24. package/dist/lib/nunjucks.js +3 -3
  25. package/dist/lib/nunjucks.js.map +1 -1
  26. package/dist/lib/utils.js +6 -1
  27. package/dist/lib/utils.js.map +1 -1
  28. package/dist/lib/validators/dateObject.js +23 -14
  29. package/dist/lib/validators/dateObject.js.map +1 -1
  30. package/dist/lib/validators/email.js +2 -5
  31. package/dist/lib/validators/email.js.map +1 -1
  32. package/dist/lib/validators/inArray.js +2 -5
  33. package/dist/lib/validators/inArray.js.map +1 -1
  34. package/dist/lib/validators/nino.js +1 -4
  35. package/dist/lib/validators/nino.js.map +1 -1
  36. package/dist/lib/validators/postalAddressObject.js +26 -19
  37. package/dist/lib/validators/postalAddressObject.js.map +1 -1
  38. package/dist/lib/validators/range.js +2 -6
  39. package/dist/lib/validators/range.js.map +1 -1
  40. package/dist/lib/validators/regex.js +1 -4
  41. package/dist/lib/validators/regex.js.map +1 -1
  42. package/dist/lib/validators/required.js +1 -4
  43. package/dist/lib/validators/required.js.map +1 -1
  44. package/dist/lib/validators/strlen.js +1 -4
  45. package/dist/lib/validators/strlen.js.map +1 -1
  46. package/dist/lib/validators/wordCount.js +1 -4
  47. package/dist/lib/validators/wordCount.js.map +1 -1
  48. package/dist/middleware/csrf.js +4 -2
  49. package/dist/middleware/csrf.js.map +1 -1
  50. package/dist/middleware/data.js +17 -10
  51. package/dist/middleware/data.js.map +1 -1
  52. package/dist/middleware/i18n.d.ts +1 -1
  53. package/dist/middleware/i18n.js +16 -16
  54. package/dist/middleware/i18n.js.map +1 -1
  55. package/dist/middleware/post.js +9 -7
  56. package/dist/middleware/post.js.map +1 -1
  57. package/dist/middleware/pre.js +2 -2
  58. package/dist/middleware/pre.js.map +1 -1
  59. package/dist/middleware/sanitise-fields.d.ts +1 -1
  60. package/dist/middleware/sanitise-fields.js +1 -2
  61. package/dist/middleware/sanitise-fields.js.map +1 -1
  62. package/dist/middleware/session.js +11 -6
  63. package/dist/middleware/session.js.map +1 -1
  64. package/dist/middleware/strip-proxy-path.js +1 -2
  65. package/dist/middleware/strip-proxy-path.js.map +1 -1
  66. package/dist/middleware/validate-fields.d.ts +1 -1
  67. package/dist/middleware/validate-fields.js +1 -2
  68. package/dist/middleware/validate-fields.js.map +1 -1
  69. package/dist/routes/ancillary.js +1 -1
  70. package/dist/routes/ancillary.js.map +1 -1
  71. package/dist/routes/journey.js +16 -12
  72. package/dist/routes/journey.js.map +1 -1
  73. package/dist/routes/static.js +8 -9
  74. package/dist/routes/static.js.map +1 -1
  75. package/package.json +23 -22
  76. package/src/lib/JourneyContext.js +22 -19
  77. package/src/lib/MutableRouter.js +5 -4
  78. package/src/lib/Plan.js +2 -8
  79. package/src/lib/ValidationError.js +2 -2
  80. package/src/lib/configuration-ingestor.js +21 -12
  81. package/src/lib/configure.js +14 -11
  82. package/src/lib/end-session.js +5 -5
  83. package/src/lib/nunjucks-filters.js +6 -6
  84. package/src/lib/nunjucks.js +2 -2
  85. package/src/lib/validators/dateObject.js +5 -5
  86. package/src/lib/validators/postalAddressObject.js +8 -10
  87. package/src/middleware/data.js +4 -7
  88. package/src/middleware/i18n.js +9 -9
  89. package/src/middleware/pre.js +1 -1
  90. package/src/middleware/sanitise-fields.js +1 -2
  91. package/src/routes/ancillary.js +1 -1
  92. package/src/routes/journey.js +3 -3
  93. package/src/routes/static.js +4 -4
@@ -1,18 +1,15 @@
1
1
  // Decorates the request with some contextual data about the user's journey
2
2
  // through the application. This is used by downstream middleware and templates.
3
3
 
4
- import lodash from "lodash";
5
4
  import JourneyContext from "../lib/JourneyContext.js";
6
5
  import { validateUrlPath } from "../lib/utils.js";
7
6
  import waypointUrl from "../lib/waypoint-url.js";
8
7
 
9
- const { has } = lodash;
10
-
11
8
  const editOrigin = (req) => {
12
- if (has(req.query, "editorigin")) {
9
+ if (Object.hasOwn(req.query, "editorigin")) {
13
10
  return waypointUrl({ waypoint: req.query.editorigin });
14
11
  }
15
- if (has(req?.body, "editorigin")) {
12
+ if (req.body && Object.hasOwn(req.body, "editorigin")) {
16
13
  return waypointUrl({ waypoint: req.body.editorigin });
17
14
  }
18
15
  return "";
@@ -39,8 +36,8 @@ export default function dataMiddleware({ plan, events, contextIdGenerator }) {
39
36
 
40
37
  // Edit mode
41
38
  editMode:
42
- (has(req?.query, "edit") && has(req?.query, "editorigin")) ||
43
- (has(req?.body, "edit") && has(req?.body, "editorigin")),
39
+ (Object.hasOwn(req.query, "edit") && Object.hasOwn(req.query, "editorigin")) ||
40
+ (Object.hasOwn(req.body, "edit") && Object.hasOwn(req.body, "editorigin")),
44
41
  editOrigin: editOrigin(req),
45
42
  };
46
43
 
@@ -1,7 +1,7 @@
1
1
  import { createInstance } from "i18next";
2
2
  import { LanguageDetector, handle } from "i18next-http-middleware";
3
- import { resolve, basename } from "path";
4
- import { existsSync, readFileSync, readdirSync } from "fs";
3
+ import { resolve, basename } from "node:path";
4
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
5
5
  import deepmerge from "deepmerge";
6
6
  import yaml from "js-yaml";
7
7
  import logger from "../lib/logger.js";
@@ -32,22 +32,22 @@ const extract = (file) => {
32
32
  const loadResources = (languages, directories) => {
33
33
  const store = Object.create(null);
34
34
 
35
- languages.forEach((language) => {
35
+ for (const language of languages) {
36
36
  // ESLint disabled as `store`, `language` and `ns` are all dev-controlled,
37
37
  // and this function is only called once, at boot-time.
38
38
  /* eslint-disable security/detect-object-injection */
39
39
  store[language] = Object.create(null);
40
40
 
41
- directories.forEach((basedir) => {
41
+ for (const basedir of directories) {
42
42
  const dir = resolve(basedir, language);
43
43
  /* eslint-disable-next-line security/detect-non-literal-fs-filename */
44
44
  if (!existsSync(dir)) {
45
- return;
45
+ continue;
46
46
  }
47
47
 
48
48
  log.info("Loading %s language from %s ...", language, dir);
49
49
  /* eslint-disable-next-line security/detect-non-literal-fs-filename */
50
- readdirSync(dir).forEach((file) => {
50
+ for (const file of readdirSync(dir)) {
51
51
  const { ns, data } = extract(resolve(dir, file));
52
52
 
53
53
  if (store[language][ns] === undefined) {
@@ -55,10 +55,10 @@ const loadResources = (languages, directories) => {
55
55
  }
56
56
 
57
57
  store[language][ns] = deepmerge(store[language][ns], data);
58
- });
59
- });
58
+ }
59
+ }
60
60
  /* eslint-enable security/detect-object-injection */
61
- });
61
+ }
62
62
 
63
63
  return store;
64
64
  };
@@ -1,4 +1,4 @@
1
- import { randomBytes } from "crypto";
1
+ import { randomBytes } from "node:crypto";
2
2
  import helmet from "helmet";
3
3
 
4
4
  /**
@@ -2,7 +2,6 @@
2
2
  // - Coerce each field to its correct type
3
3
  // - Remove an extraneous fields that are not know to the application
4
4
 
5
- import _ from "lodash";
6
5
  import fieldFactory from "../lib/field.js";
7
6
  import JourneyContext from "../lib/JourneyContext.js";
8
7
 
@@ -39,7 +38,7 @@ export default ({ waypoint, fields = [] }) => {
39
38
  const prunedBody = Object.create(null);
40
39
  for (let i = 0, l = fields.length; i < l; i++) {
41
40
  if (
42
- _.has(req.body, fields[i].name) &&
41
+ Object.hasOwn(req.body, fields[i].name) &&
43
42
  req.body[fields[i].name] !== undefined
44
43
  ) {
45
44
  prunedBody[fields[i].name] = req.body[fields[i].name];
@@ -14,7 +14,7 @@ import MutableRouter from "../lib/MutableRouter.js";
14
14
  */
15
15
  export default function ancillaryRouter({ sessionTtl }) {
16
16
  // Router
17
- const router = new MutableRouter();
17
+ const router = new MutableRouter({ mergeParams: true });
18
18
 
19
19
  // Session timeout
20
20
  router.all("/session-timeout", (req, res) => {
@@ -107,7 +107,7 @@ export default function journeyRouter({
107
107
  globalErrorVisibility,
108
108
  }) {
109
109
  // Router
110
- const router = new MutableRouter();
110
+ const router = new MutableRouter({ mergeParams: true });
111
111
 
112
112
  // Special "_" route which handles redirecting the user between sub-apps
113
113
  // /app1/_/?refmount=app2&route=prev
@@ -165,7 +165,7 @@ export default function journeyRouter({
165
165
  // Create GET / POST routes for each page
166
166
  const commonMiddleware = [...csrfMiddleware];
167
167
 
168
- pages.forEach((page) => {
168
+ for (const page of pages) {
169
169
  const {
170
170
  waypoint,
171
171
  view,
@@ -320,7 +320,7 @@ export default function journeyRouter({
320
320
  };
321
321
  }),
322
322
  );
323
- });
323
+ }
324
324
 
325
325
  return router;
326
326
  }
@@ -1,8 +1,8 @@
1
1
  import ExpressJS from "express";
2
- import { readFileSync } from "fs";
3
- import { URL } from "url";
4
- import { resolve } from "path";
5
- import { createRequire } from "module";
2
+ import { readFileSync } from "node:fs";
3
+ import { URL } from "node:url";
4
+ import { resolve } from "node:path";
5
+ import { createRequire } from "node:module";
6
6
 
7
7
  import dirname from "./dirname.cjs";
8
8
  import MutableRouter from "../lib/MutableRouter.js";