@dwp/govuk-casa 8.7.12 → 8.8.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.
- package/dist/casa.js +2 -1
- package/dist/casa.js.map +1 -0
- package/dist/lib/CasaTemplateLoader.js +1 -0
- package/dist/lib/CasaTemplateLoader.js.map +1 -0
- package/dist/lib/JourneyContext.d.ts +1 -1
- package/dist/lib/JourneyContext.js +2 -1
- package/dist/lib/JourneyContext.js.map +1 -0
- package/dist/lib/MutableRouter.js +1 -0
- package/dist/lib/MutableRouter.js.map +1 -0
- package/dist/lib/Plan.d.ts +2 -1
- package/dist/lib/Plan.js +4 -3
- package/dist/lib/Plan.js.map +1 -0
- package/dist/lib/ValidationError.js +1 -0
- package/dist/lib/ValidationError.js.map +1 -0
- package/dist/lib/ValidatorFactory.d.ts +2 -2
- package/dist/lib/ValidatorFactory.js +3 -2
- package/dist/lib/ValidatorFactory.js.map +1 -0
- package/dist/lib/configuration-ingestor.js +1 -0
- package/dist/lib/configuration-ingestor.js.map +1 -0
- package/dist/lib/configure.js +2 -1
- package/dist/lib/configure.js.map +1 -0
- package/dist/lib/end-session.js +1 -0
- package/dist/lib/end-session.js.map +1 -0
- package/dist/lib/field.js +1 -0
- package/dist/lib/field.js.map +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/logger.js +1 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/mount.js +3 -2
- package/dist/lib/mount.js.map +1 -0
- package/dist/lib/nunjucks-filters.js +1 -0
- package/dist/lib/nunjucks-filters.js.map +1 -0
- package/dist/lib/nunjucks.js +1 -0
- package/dist/lib/nunjucks.js.map +1 -0
- package/dist/lib/utils.d.ts +45 -27
- package/dist/lib/utils.js +105 -67
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/validators/dateObject.js +4 -3
- package/dist/lib/validators/dateObject.js.map +1 -0
- package/dist/lib/validators/email.js +1 -0
- package/dist/lib/validators/email.js.map +1 -0
- package/dist/lib/validators/inArray.js +1 -0
- package/dist/lib/validators/inArray.js.map +1 -0
- package/dist/lib/validators/index.js +1 -0
- package/dist/lib/validators/index.js.map +1 -0
- package/dist/lib/validators/nino.js +1 -0
- package/dist/lib/validators/nino.js.map +1 -0
- package/dist/lib/validators/postalAddressObject.d.ts +2 -2
- package/dist/lib/validators/postalAddressObject.js +2 -1
- package/dist/lib/validators/postalAddressObject.js.map +1 -0
- package/dist/lib/validators/regex.js +1 -0
- package/dist/lib/validators/regex.js.map +1 -0
- package/dist/lib/validators/required.js +1 -0
- package/dist/lib/validators/required.js.map +1 -0
- package/dist/lib/validators/strlen.js +1 -0
- package/dist/lib/validators/strlen.js.map +1 -0
- package/dist/lib/validators/wordCount.js +1 -0
- package/dist/lib/validators/wordCount.js.map +1 -0
- package/dist/lib/waypoint-url.js +1 -0
- package/dist/lib/waypoint-url.js.map +1 -0
- package/dist/middleware/body-parser.js +1 -0
- package/dist/middleware/body-parser.js.map +1 -0
- package/dist/middleware/csrf.js +1 -0
- package/dist/middleware/csrf.js.map +1 -0
- package/dist/middleware/data.js +1 -0
- package/dist/middleware/data.js.map +1 -0
- package/dist/middleware/gather-fields.js +1 -0
- package/dist/middleware/gather-fields.js.map +1 -0
- package/dist/middleware/i18n.js +1 -0
- package/dist/middleware/i18n.js.map +1 -0
- package/dist/middleware/post.js +1 -0
- package/dist/middleware/post.js.map +1 -0
- package/dist/middleware/pre.js +1 -0
- package/dist/middleware/pre.js.map +1 -0
- package/dist/middleware/progress-journey.js +1 -0
- package/dist/middleware/progress-journey.js.map +1 -0
- package/dist/middleware/sanitise-fields.js +1 -0
- package/dist/middleware/sanitise-fields.js.map +1 -0
- package/dist/middleware/serve-first-waypoint.js +1 -0
- package/dist/middleware/serve-first-waypoint.js.map +1 -0
- package/dist/middleware/session.js +1 -0
- package/dist/middleware/session.js.map +1 -0
- package/dist/middleware/skip-waypoint.js +1 -0
- package/dist/middleware/skip-waypoint.js.map +1 -0
- package/dist/middleware/steer-journey.js +1 -0
- package/dist/middleware/steer-journey.js.map +1 -0
- package/dist/middleware/strip-proxy-path.js +1 -0
- package/dist/middleware/strip-proxy-path.js.map +1 -0
- package/dist/middleware/validate-fields.js +1 -0
- package/dist/middleware/validate-fields.js.map +1 -0
- package/dist/mjs/esm-wrapper.js +10 -15
- package/dist/routes/ancillary.js +1 -0
- package/dist/routes/ancillary.js.map +1 -0
- package/dist/routes/journey.js +1 -0
- package/dist/routes/journey.js.map +1 -0
- package/dist/routes/static.js +1 -0
- package/dist/routes/static.js.map +1 -0
- package/locales/cy/error.json +1 -1
- package/locales/en/error.json +1 -1
- package/package.json +16 -15
- package/src/casa.js +320 -0
- package/src/lib/CasaTemplateLoader.js +104 -0
- package/src/lib/JourneyContext.js +783 -0
- package/src/lib/MutableRouter.js +310 -0
- package/src/lib/Plan.js +624 -0
- package/src/lib/ValidationError.js +163 -0
- package/src/lib/ValidatorFactory.js +105 -0
- package/src/lib/configuration-ingestor.js +457 -0
- package/src/lib/configure.js +202 -0
- package/src/lib/dirname.cjs +1 -0
- package/src/lib/end-session.js +45 -0
- package/src/lib/field.js +456 -0
- package/src/lib/index.js +33 -0
- package/src/lib/logger.js +16 -0
- package/src/lib/mount.js +127 -0
- package/src/lib/nunjucks-filters.js +150 -0
- package/src/lib/nunjucks.js +53 -0
- package/src/lib/utils.js +232 -0
- package/src/lib/validators/dateObject.js +169 -0
- package/src/lib/validators/email.js +55 -0
- package/src/lib/validators/inArray.js +81 -0
- package/src/lib/validators/index.js +24 -0
- package/src/lib/validators/nino.js +57 -0
- package/src/lib/validators/postalAddressObject.js +162 -0
- package/src/lib/validators/regex.js +48 -0
- package/src/lib/validators/required.js +74 -0
- package/src/lib/validators/strlen.js +66 -0
- package/src/lib/validators/wordCount.js +70 -0
- package/src/lib/waypoint-url.js +93 -0
- package/src/middleware/body-parser.js +31 -0
- package/src/middleware/csrf.js +29 -0
- package/src/middleware/data.js +105 -0
- package/src/middleware/dirname.cjs +1 -0
- package/src/middleware/gather-fields.js +51 -0
- package/src/middleware/i18n.js +106 -0
- package/src/middleware/post.js +61 -0
- package/src/middleware/pre.js +91 -0
- package/src/middleware/progress-journey.js +92 -0
- package/src/middleware/sanitise-fields.js +58 -0
- package/src/middleware/serve-first-waypoint.js +28 -0
- package/src/middleware/session.js +129 -0
- package/src/middleware/skip-waypoint.js +46 -0
- package/src/middleware/steer-journey.js +78 -0
- package/src/middleware/strip-proxy-path.js +56 -0
- package/src/middleware/validate-fields.js +84 -0
- package/src/routes/ancillary.js +29 -0
- package/src/routes/dirname.cjs +1 -0
- package/src/routes/journey.js +212 -0
- package/src/routes/static.js +77 -0
- package/views/casa/components/character-count/README.md +10 -0
- package/views/casa/components/character-count/template.njk +6 -2
- package/views/casa/components/checkboxes/README.md +43 -34
- package/views/casa/components/checkboxes/template.njk +8 -7
- package/views/casa/components/date-input/README.md +11 -1
- package/views/casa/components/date-input/template.njk +6 -4
- package/views/casa/components/input/README.md +9 -0
- package/views/casa/components/input/template.njk +6 -2
- package/views/casa/components/postal-address-object/README.md +10 -0
- package/views/casa/components/postal-address-object/template.njk +20 -5
- package/views/casa/components/radios/README.md +49 -24
- package/views/casa/components/radios/template.njk +6 -3
- package/views/casa/components/select/README.md +65 -0
- package/views/casa/components/select/macro.njk +3 -0
- package/views/casa/components/select/template.njk +49 -0
- package/views/casa/components/textarea/README.md +9 -0
- package/views/casa/components/textarea/template.njk +6 -2
- package/views/casa/layouts/journey.njk +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-fields.js","sourceRoot":"","sources":["../../src/middleware/validate-fields.js"],"names":[],"mappings":";;;;;AAAA,oDAAoD;AACpD,iFAAsD;AAEtD,MAAM,aAAa,GAAG,CAAC,EACrB,QAAQ,EACR,MAAM,GAAG,IAAI,EACb,cAAc,EACd,OAAO,GACR,EAAE,EAAE;IACH,uBAAuB;IACvB,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,cAAc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AAE,GAAG,CAAC,OAAO;gBACpB,QAAQ;gBACR,IAAI;gBACJ,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,cAAc;aACxC,CAAC,CAAC;YACH,OAAO,IAAI,EAAE,CAAC;SACf;QAED,0EAA0E;QAC1E,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC;QAC3D,IAAI,WAAW,EAAE;YACf,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC;SAC1B;QAED,qDAAqD;QACrD,aAAa,CAAC;YACZ,MAAM;YACN,QAAQ;YACR,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,QAAQ;YACR,IAAI;YACJ,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,cAAc;SACxC,CAAC,CAAC;QAEH,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;CACF,CAAC"}
|
package/dist/mjs/esm-wrapper.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
// Basic wrapper to act as the package entrypoint for ESM applications
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
// `dist/` in the right location at build time, which will resolve that file
|
|
5
|
-
// path correctly.
|
|
1
|
+
// Basic wrapper to act as the package entrypoint for ESM applications;
|
|
2
|
+
// Reference: https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1;
|
|
3
|
+
|
|
6
4
|
import casa from '../casa.js';
|
|
7
5
|
|
|
8
|
-
export const { configure } = casa;
|
|
9
|
-
export const { validators } = casa;
|
|
10
|
-
export const { field } = casa;
|
|
11
|
-
export const { Plan } = casa;
|
|
12
6
|
export const { JourneyContext } = casa;
|
|
13
|
-
export const {
|
|
7
|
+
export const { MutableRouter } = casa;
|
|
8
|
+
export const { Plan } = casa;
|
|
14
9
|
export const { ValidationError } = casa;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const { waypointUrl } = casa;
|
|
10
|
+
export const { ValidatorFactory } = casa;
|
|
11
|
+
export const { configure } = casa;
|
|
18
12
|
export const { endSession } = casa;
|
|
19
|
-
|
|
20
|
-
// Nunjucks filters
|
|
13
|
+
export const { field } = casa;
|
|
21
14
|
export const { nunjucksFilters } = casa;
|
|
15
|
+
export const { validators } = casa;
|
|
16
|
+
export const { waypointUrl } = casa;
|
package/dist/routes/ancillary.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ancillary.js","sourceRoot":"","sources":["../../src/routes/ancillary.js"],"names":[],"mappings":";;;;;AAAA,+EAAoD;AAEpD;;;GAGG;AAEH;;;;;;GAMG;AACH,SAAwB,eAAe,CAAC,EACtC,UAAU,GACX;IACC,SAAS;IACT,MAAM,MAAM,GAAG,IAAI,0BAAa,EAAE,CAAC;IAEnC,kBAAkB;IAClB,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,GAAG,CAAC,MAAM,CAAC,0BAA0B,EAAE;YACrC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC;SACxC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAdD,kCAcC"}
|
package/dist/routes/journey.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journey.js","sourceRoot":"","sources":["../../src/routes/journey.js"],"names":[],"mappings":";;;;;AAAA,iDAAiD;AACjD,+EAAoD;AACpD,sFAA2E;AAC3E,sFAA2E;AAC3E,0FAA+E;AAC/E,sFAA2E;AAC3E,0FAA+E;AAC/E,4FAAiF;AACjF,6EAAiD;AACjD,iEAAsC;AACtC,8CAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,mBAAM,EAAC,gBAAgB,CAAC,CAAC;AAErC;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;GAMG;AAEH,M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GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1J,MAAM,CAAC,GAAG,CAAC,+BAA+B,EAAE,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,uBAAuB,EAAE,IAAA,0BAAe,EAAC,GAAG,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjK,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAE5C,OAAO,MAAM,CAAC;AAChB,CAAC;AAlDD,+BAkDC"}
|
package/locales/cy/error.json
CHANGED
package/locales/en/error.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dwp/govuk-casa",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.0",
|
|
4
4
|
"description": "A framework for building GOVUK Collect-And-Submit-Applications",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist/**/*",
|
|
18
18
|
"locales/**/*",
|
|
19
|
+
"src/**/*.{js,cjs,mjs}",
|
|
19
20
|
"views/**/*"
|
|
20
21
|
],
|
|
21
22
|
"engines": {
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"lint": "eslint .",
|
|
37
38
|
"build": "npm run build:prepare && npm run build:sources && npm run build:css-assets",
|
|
38
39
|
"build:prepare": "rm -rf dist/* && mkdir -p dist/assets/js/ && mkdir -p dist/assets/css/",
|
|
39
|
-
"build:sources": "tsc -p tsconfig-cjs.json && ./scripts/fixup.sh",
|
|
40
|
+
"build:sources": "tsc -p tsconfig-cjs.json && ./scripts/fixup.sh && node scripts/esm-wrapper",
|
|
40
41
|
"build:css-assets": "node scripts/compile-sass.js",
|
|
41
42
|
"build:api-docs": "npx jsdoc -c ./jsdoc.json -d ./docs/api/ --debug -P '' -r -R ./README.md --verbose -t ./node_modules/docdash ./src",
|
|
42
43
|
"prepare": "npm run build",
|
|
@@ -47,6 +48,7 @@
|
|
|
47
48
|
"license": "ISC",
|
|
48
49
|
"type": "module",
|
|
49
50
|
"dependencies": {
|
|
51
|
+
"@dagrejs/graphlib": "2.1.12",
|
|
50
52
|
"cookie-parser": "1.4.6",
|
|
51
53
|
"csurf": "1.11.0",
|
|
52
54
|
"debug": "4.3.4",
|
|
@@ -54,9 +56,8 @@
|
|
|
54
56
|
"express": "4.18.2",
|
|
55
57
|
"express-session": "1.17.3",
|
|
56
58
|
"govuk-frontend": "4.5.0",
|
|
57
|
-
"graphlib": "2.1.8",
|
|
58
59
|
"helmet": "6.0.1",
|
|
59
|
-
"i18next": "22.4.
|
|
60
|
+
"i18next": "22.4.13",
|
|
60
61
|
"i18next-http-middleware": "3.3.0",
|
|
61
62
|
"js-yaml": "4.1.0",
|
|
62
63
|
"lodash": "4.17.21",
|
|
@@ -67,33 +68,33 @@
|
|
|
67
68
|
"validator": "13.9.0"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@babel/core": "7.21.
|
|
71
|
+
"@babel/core": "7.21.4",
|
|
71
72
|
"@babel/eslint-parser": "7.21.3",
|
|
72
|
-
"@babel/preset-env": "7.
|
|
73
|
-
"@ckeditor/jsdoc-plugins": "
|
|
73
|
+
"@babel/preset-env": "7.21.4",
|
|
74
|
+
"@ckeditor/jsdoc-plugins": "36.0.0",
|
|
74
75
|
"@commitlint/config-conventional": "17.4.4",
|
|
75
76
|
"@dwp/casa-spiderplan": "2.5.4",
|
|
76
77
|
"@dwp/casa-spiderplan-a11y-plugin": "0.1.10",
|
|
77
78
|
"@dwp/casa-spiderplan-zap-plugin": "0.1.6",
|
|
78
|
-
"@dwp/eslint-config-base": "6.1.
|
|
79
|
+
"@dwp/eslint-config-base": "6.1.1",
|
|
79
80
|
"@types/express": "4.17.17",
|
|
80
|
-
"@types/node": "18.15.
|
|
81
|
+
"@types/node": "18.15.11",
|
|
81
82
|
"@types/nunjucks": "3.2.2",
|
|
82
83
|
"c8": "7.13.0",
|
|
83
84
|
"chai": "4.3.7",
|
|
84
85
|
"cheerio": "1.0.0-rc.12",
|
|
85
|
-
"commitlint": "17.
|
|
86
|
+
"commitlint": "17.5.1",
|
|
86
87
|
"docdash": "2.0.1",
|
|
87
|
-
"eslint": "8.
|
|
88
|
+
"eslint": "8.37.0",
|
|
88
89
|
"eslint-plugin-no-unsafe-regex": "1.0.0",
|
|
89
90
|
"eslint-plugin-security": "1.7.1",
|
|
90
|
-
"eslint-plugin-sonarjs": "0.
|
|
91
|
-
"fast-check": "3.
|
|
91
|
+
"eslint-plugin-sonarjs": "0.19.0",
|
|
92
|
+
"fast-check": "3.8.0",
|
|
92
93
|
"jsdoc": "4.0.2",
|
|
93
94
|
"jsdoc-tsimport-plugin": "1.0.5",
|
|
94
95
|
"mocha": "10.2.0",
|
|
95
|
-
"sass": "1.
|
|
96
|
-
"sinon": "15.0.
|
|
96
|
+
"sass": "1.60.0",
|
|
97
|
+
"sinon": "15.0.3",
|
|
97
98
|
"sinon-chai": "3.7.0",
|
|
98
99
|
"supertest": "6.3.3",
|
|
99
100
|
"typescript": "4.9.5"
|
package/src/casa.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// NOTE: Any changes made here must be reflected in `scripts/esm-wrapper.js`
|
|
2
|
+
import configure from './lib/configure.js';
|
|
3
|
+
import validators from './lib/validators/index.js';
|
|
4
|
+
import field from './lib/field.js';
|
|
5
|
+
import Plan from './lib/Plan.js';
|
|
6
|
+
import JourneyContext from './lib/JourneyContext.js';
|
|
7
|
+
import ValidatorFactory from './lib/ValidatorFactory.js';
|
|
8
|
+
import ValidationError from './lib/ValidationError.js';
|
|
9
|
+
import MutableRouter from './lib/MutableRouter.js';
|
|
10
|
+
import waypointUrl from './lib/waypoint-url.js';
|
|
11
|
+
import endSession from './lib/end-session.js';
|
|
12
|
+
import * as nunjucksFilters from './lib/nunjucks-filters.js';
|
|
13
|
+
|
|
14
|
+
/** @module @dwp/govuk-casa */
|
|
15
|
+
export {
|
|
16
|
+
configure,
|
|
17
|
+
validators,
|
|
18
|
+
field,
|
|
19
|
+
Plan,
|
|
20
|
+
JourneyContext,
|
|
21
|
+
ValidatorFactory,
|
|
22
|
+
ValidationError,
|
|
23
|
+
MutableRouter,
|
|
24
|
+
|
|
25
|
+
// Utilities
|
|
26
|
+
waypointUrl,
|
|
27
|
+
endSession,
|
|
28
|
+
|
|
29
|
+
// Nunjucks filters
|
|
30
|
+
nunjucksFilters,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/* ----------------------------------------------------------------- Typedefs */
|
|
34
|
+
// These exist here so that consumer can import CASA's internal types
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {import('./lib/field').PageField} PageField
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {object} ContextEventHandlerOptions
|
|
42
|
+
* @property {JourneyContext} journeyContext Context including changes
|
|
43
|
+
* @property {JourneyContext} previousContext Context prior to changes
|
|
44
|
+
* @property {object} session Request session object
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @callback ContextEventHandler
|
|
49
|
+
* @param {ContextEventHandlerOptions} opts Options
|
|
50
|
+
* @returns {void}
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @typedef {object} ContextEvent
|
|
55
|
+
* @property {string} waypoint Waypoint to watch for changes
|
|
56
|
+
* @property {string} [field] Field to watch for changes
|
|
57
|
+
* @property {ContextEventHandler} handler Handler to invoke when change happens
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {object} Page Page configuration. A Page is the interactive representation of a waypoint
|
|
62
|
+
* @property {string} waypoint The waypoint with which this page is associated
|
|
63
|
+
* @property {string} view Template path
|
|
64
|
+
* @property {PageHook[]} [hooks=[]] Page-specific hooks (optional, default [])
|
|
65
|
+
* @property {PageField[]} [fields=[]] Fields to be managed on this page (optional, default [])
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @typedef {object} I18nOptions
|
|
70
|
+
* @property {string[]} dirs Directories to search for locale dictionaries
|
|
71
|
+
* @property {string[]} [locales=['en', 'cy']] Supported locales
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {object} GlobalHook Hook configuration
|
|
76
|
+
* @property {string} hook Hook name in format `<router>.<hook>`
|
|
77
|
+
* @property {Function} middleware Middleware function to insert at the hook point
|
|
78
|
+
* @property {string|RegExp} [path=undefined] Only run if route path matches this string/regexp
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @typedef {object} PageHook (extends GlobalHook)
|
|
83
|
+
* @property {string} hook Hook name (without a scope prefix)
|
|
84
|
+
* @property {Function} middleware Middleware function to insert at the hook point
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {object} SessionOptions
|
|
89
|
+
* @property {string} [name=casasession] Session name
|
|
90
|
+
* @property {string} [secret=secret] Encryption secret
|
|
91
|
+
* @property {number} [ttl=3600] Session ttl (seconds)
|
|
92
|
+
* @property {boolean} [secure=false] Whether to use secure session cookies
|
|
93
|
+
* @property {boolean|string} [cookieSameSite=true] SameSite (true = Strict)
|
|
94
|
+
* @property {object} [store] Session store (default MemoryStore)
|
|
95
|
+
* @property {string} [cookiePath] the URL path on which the session cookie
|
|
96
|
+
* is valid (defaults to '/')
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @typedef {object} IPlugin Plugin interface
|
|
101
|
+
* @property {PluginConfigureFunction} [configure] Modify the app config
|
|
102
|
+
* @property {PluginBootstrapFunction} [bootstrap] Modify post-configuration artifacts
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @callback PluginConfigureFunction
|
|
107
|
+
* @param {ConfigurationOptions} config Options
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @callback PluginBootstrapFunction
|
|
112
|
+
* @param {ConfigureResult} config Options
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @callback HelmetConfigurator
|
|
117
|
+
* @param {object} config A default Helmet configuration provided by CASA
|
|
118
|
+
* @returns {object} The modified configuration object
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Mounting function.
|
|
123
|
+
*
|
|
124
|
+
* This will mount all of the routes and middleware in the correct order on
|
|
125
|
+
* the given ExpressJS app.
|
|
126
|
+
*
|
|
127
|
+
* Once this is called, you will not be able to modify any of the routers as
|
|
128
|
+
* they will be "sealed".
|
|
129
|
+
*
|
|
130
|
+
* @callback Mounter
|
|
131
|
+
* @param {import('express').Express} app Express application
|
|
132
|
+
* @param {object} opts Mounting options
|
|
133
|
+
* @param {string} [opts.route='/'] Optional route to attach all middleware/routers too
|
|
134
|
+
* @returns {import('express').Express} The prepared ExpressJS app instance
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Configure some middleware for use in creating a new CASA app.
|
|
139
|
+
*
|
|
140
|
+
* @typedef {object} ConfigurationOptions Configuration options
|
|
141
|
+
* @property {string} [mountUrl] Prefix for all URLS in browser address bar
|
|
142
|
+
* @property {string[]} [views=[]] Template directories
|
|
143
|
+
* @property {SessionOptions} [session] Session configuration
|
|
144
|
+
* @property {Page[]} [pages=[]] Pages the represent waypoints
|
|
145
|
+
* @property {GlobalHook[]} [hooks=[]] Hooks to apply
|
|
146
|
+
* @property {IPlugin[]} [plugins=[]] Plugins
|
|
147
|
+
* @property {I18nOptions} [i18n] I18n configuration
|
|
148
|
+
* @property {Plan} [plan] CASA Plan
|
|
149
|
+
* @property {ContextEvent[]} [events=[]] Handlers for JourneyContext events
|
|
150
|
+
* @property {HelmetConfigurator} [helmetConfigurator] Helmet configuration manipulator function
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @typedef {object} ConfigureResult Result of a call to configure() function
|
|
155
|
+
* @property {import('nunjucks').Environment} nunjucksEnv Nunjucks environment
|
|
156
|
+
* @property {MutableRouter} staticRouter Router handling all static assets
|
|
157
|
+
* @property {MutableRouter} ancillaryRouter Router handling ancillary routes
|
|
158
|
+
* @property {MutableRouter} journeyRouter Router handling all waypoint requests
|
|
159
|
+
* @property {import('express').RequestHandler[]} preMiddleware Middleware mounted before everything
|
|
160
|
+
* @property {import('express').RequestHandler[]} postMiddleware Middleware mounted after everything
|
|
161
|
+
* @property {import('express').RequestHandler[]} csrfMiddleware CSRF get/set form middleware
|
|
162
|
+
* @property {import('express').RequestHandler} sessionMiddleware Session middleware
|
|
163
|
+
* @property {import('express').RequestHandler[]} cookieParserMiddleware Cookie-parsing middleware
|
|
164
|
+
* @property {import('express').RequestHandler[]} i18nMiddleware I18n preparation middleware
|
|
165
|
+
* @property {import('express').RequestHandler} bodyParserMiddleware Body parsing middleware
|
|
166
|
+
* @property {Mounter} mount Function used to mount all CASA artifacts onto an ExpressJS app
|
|
167
|
+
* @property {ConfigurationOptions} config Ingested config supplied to `configure()`
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Configuration for generating a ValidationError.
|
|
172
|
+
* i.e. `new ValidationError(configObject)`
|
|
173
|
+
* <br/><br/>
|
|
174
|
+
*
|
|
175
|
+
* The `fieldKeySuffix` is used to differentiate errors attached to
|
|
176
|
+
* the same field name. For example, given these fields inputs ...
|
|
177
|
+
*
|
|
178
|
+
* <pre>
|
|
179
|
+
* <input name="dateOfBirth[dd]" />
|
|
180
|
+
* <input name="dateOfBirth[mm]" />
|
|
181
|
+
* <input name="dateOfBirth[yyyy]" />
|
|
182
|
+
* </pre>
|
|
183
|
+
*
|
|
184
|
+
* If we wanted to generate an error specifically for the `dd`
|
|
185
|
+
* element, then we'd include `{ fieldKeySuffix: '[dd]' }` in this
|
|
186
|
+
* config.
|
|
187
|
+
* <br/><br/>
|
|
188
|
+
*
|
|
189
|
+
* We can also use `focusSuffix` to control which properties of an
|
|
190
|
+
* object field should be highlighted with a red border when in error. Looking
|
|
191
|
+
* again at the `dateOfBirth` example above, if we did not specify
|
|
192
|
+
* any `focusSuffix`, then all three inputs would be highlighted.
|
|
193
|
+
* However, if we use `{ focusSuffix: ['[dd]', '[yyyy]'] }` then only
|
|
194
|
+
* the `[dd]` and `[yyyy]` inputs would be highlighted.
|
|
195
|
+
* <br/><br/>
|
|
196
|
+
*
|
|
197
|
+
* The `fieldHref` and `field` properties are strictly for
|
|
198
|
+
* internal use only and public access may be removed at any point.
|
|
199
|
+
*
|
|
200
|
+
* @typedef {object} ErrorMessageConfigObject
|
|
201
|
+
* @property {string} summary Summary message
|
|
202
|
+
* @property {string} [inline] Inline message (@deprecated now uses summary everywhere)
|
|
203
|
+
* @property {string|string[]} [focusSuffix] String(s) to append to URL hash for focusing inputs
|
|
204
|
+
* @property {string} [fieldKeySuffix] Object fields may use this to show errors per sub-property
|
|
205
|
+
* @property {object|ErrorMessageVariablesGenerator} [variables] Interpolation variables
|
|
206
|
+
* @property {string} [validator] Name of the validator
|
|
207
|
+
* @property {string} [fieldHref] (internal) URL hash to link to field in UI, i.e `#f-..`
|
|
208
|
+
* @property {string} [field] (internal) Field name, including any focus suffix
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Function to generate interpolation variables for injecting into the error
|
|
213
|
+
* message string.
|
|
214
|
+
*
|
|
215
|
+
* @callback ErrorMessageVariablesGenerator
|
|
216
|
+
* @param {ValidateContext} dataContext Data context
|
|
217
|
+
* @returns {object} Variables name:value hash
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @callback ErrorMessageConfigGenerator
|
|
222
|
+
* @param {ValidateContext} dataContext Data context
|
|
223
|
+
* @returns {string|ErrorMessageConfigObject} Compiled error message config
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @typedef {string|ErrorMessageConfigObject|ErrorMessageConfigGenerator|Error} ErrorMessageConfig
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @typedef {object} ValidateContext Context passed to validate function
|
|
232
|
+
* @property {JourneyContext} journeyContext Journey context
|
|
233
|
+
* @property {string} waypoint Waypoint
|
|
234
|
+
* @property {string} fieldName Name of field being processed
|
|
235
|
+
* @property {any} [fieldValue] Current value of the field being validated
|
|
236
|
+
* @property {string} [validator] Name of the validator
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @callback ValidateFunction
|
|
241
|
+
* @param {any} value
|
|
242
|
+
* @param {ValidateContext} context Vaildation context
|
|
243
|
+
* @returns {ValidationError[]}
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @callback FieldProcessorFunction
|
|
248
|
+
* @param {any} value Value to be processed
|
|
249
|
+
* @returns {any}
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @typedef {object} Validator
|
|
254
|
+
* @property {ValidateFunction} validate Validation function
|
|
255
|
+
* @property {FieldProcessorFunction} sanitise Sanitise a given value prior to validation
|
|
256
|
+
* @property {object} config Configuration
|
|
257
|
+
* @property {string} name Validator name
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @typedef {object} ValidatorConditionFunctionParams
|
|
262
|
+
* @property {string} fieldName Field name
|
|
263
|
+
* @property {any} fieldValue Field value
|
|
264
|
+
* @property {string} waypoint Waypoint
|
|
265
|
+
* @property {string} waypointId [DEPRECATED] Waypoint (for backwards compatibility with v7)
|
|
266
|
+
* @property {JourneyContext} journeyContext Journey Context
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Condition functions are executed unbound.
|
|
271
|
+
*
|
|
272
|
+
* @callback ValidatorConditionFunction
|
|
273
|
+
* @param {ValidatorConditionFunctionParams} context Value to be processed
|
|
274
|
+
* @returns {boolean} True if the validators should be run
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @typedef {object} PlanRoute
|
|
279
|
+
* @property {string} source Source waypoint
|
|
280
|
+
* @property {string} target Target waypoint
|
|
281
|
+
* @property {string} name Name
|
|
282
|
+
* @property {string} label Label
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @callback PlanRouteCondition
|
|
287
|
+
* @param {PlanRoute} route Route metadata
|
|
288
|
+
* @param {JourneyContext} context Journey Context
|
|
289
|
+
* @returns {boolean} Returns true is route should be followed
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @typedef PlanTraverseOptions
|
|
294
|
+
* @property {string} [startWaypoint] Waypoint from which to start (defaults to first in list)
|
|
295
|
+
* @property {string} routeName Follow routes matching this name (next | prev)
|
|
296
|
+
* @property {Map} history Used to detect loops in traversal (INTERNAL USE ONLY)
|
|
297
|
+
* @property {Function} [stopCondition] If true, traversal will be stopped (useful for performance)
|
|
298
|
+
* @property {string|PlanArbiter} [arbiter] Multiple target routes found, this decides which to use
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @typedef {object} PlanArbiterParams
|
|
303
|
+
* @property {PlanRoute[]} targets Potential target routes that need arbitration
|
|
304
|
+
* @property {JourneyContext} journeyContext Journey Context
|
|
305
|
+
* @property {PlanTraverseOptions} traverseOptions Original traverse options passed to `traverse()`
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @callback PlanArbiter
|
|
310
|
+
* @param {PlanArbiterParams} route Route metadata
|
|
311
|
+
* @returns {PlanRoute[]} Returns all routes, excluding those that the arbiter could eliminate
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @typedef {object} JourneyContextObject Journey Context Object
|
|
316
|
+
* @property {Record<string,any>} [data] Data
|
|
317
|
+
* @property {any} [validation] Validation state
|
|
318
|
+
* @property {any} [nav] Navigation meta
|
|
319
|
+
* @property {any} [identity] Identity meta
|
|
320
|
+
*/
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { FileSystemLoader } from 'nunjucks';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @access private
|
|
5
|
+
* @typedef {import('nunjucks').FileSystemLoaderOptions} FileSystemLoaderOptions
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @access private
|
|
10
|
+
* @typedef {import('nunjucks').LoaderSource} LoaderSource
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const VALID_BLOCKS = [
|
|
14
|
+
'beforeContent',
|
|
15
|
+
'bodyEnd',
|
|
16
|
+
'bodyStart',
|
|
17
|
+
'casaPageTitle',
|
|
18
|
+
'content',
|
|
19
|
+
'footer',
|
|
20
|
+
'head',
|
|
21
|
+
'header',
|
|
22
|
+
'headIcons',
|
|
23
|
+
'journey_form',
|
|
24
|
+
'main',
|
|
25
|
+
'pageTitle',
|
|
26
|
+
'skipLink',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @callback BlockModifier
|
|
31
|
+
* @param {string} templateName Path to the template being modified
|
|
32
|
+
* @returns {string} The modified template source
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @access private
|
|
37
|
+
* @augments FileSystemLoader
|
|
38
|
+
*/
|
|
39
|
+
export default class CasaTemplateLoader extends FileSystemLoader {
|
|
40
|
+
#blockModifiers;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Constructor.
|
|
44
|
+
*
|
|
45
|
+
* @param {string[]} searchPaths Template directories
|
|
46
|
+
* @param {FileSystemLoaderOptions} opts Loader options
|
|
47
|
+
*/
|
|
48
|
+
constructor(searchPaths, opts) {
|
|
49
|
+
super(searchPaths, opts);
|
|
50
|
+
|
|
51
|
+
this.#blockModifiers = [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Extract the source from the given template file.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} name Source file path
|
|
58
|
+
* @returns {LoaderSource} Source contents of template
|
|
59
|
+
*/
|
|
60
|
+
getSource(name) {
|
|
61
|
+
const source = super.getSource(name);
|
|
62
|
+
return source ? this.#applyBlockModifiers(name, source) : source;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Add a modification function to the loader.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} block Block name, e.g. `bodyStart`
|
|
69
|
+
* @param {BlockModifier} modifier Modifier function
|
|
70
|
+
* @returns {void}
|
|
71
|
+
* @throws {Error} If provided with an unrecognised block
|
|
72
|
+
*/
|
|
73
|
+
modifyBlock(block, modifier) {
|
|
74
|
+
// Limit to only known block so the user can't do general string replacements
|
|
75
|
+
if (!VALID_BLOCKS.includes(block)) {
|
|
76
|
+
throw new Error(`Block "${String(block)}" is not a recognised template block.`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.#blockModifiers.push({
|
|
80
|
+
block,
|
|
81
|
+
modifier,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Apply a block modifier to the given source content.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} name Block name
|
|
89
|
+
* @param {string} source Original source pulled from template file
|
|
90
|
+
* @returns {string} The modified source
|
|
91
|
+
*/
|
|
92
|
+
#applyBlockModifiers(name, source) {
|
|
93
|
+
for (let i = 0, l = this.#blockModifiers.length; i < l; i++) {
|
|
94
|
+
// ESLint disabled as `i` is an integer
|
|
95
|
+
/* eslint-disable-next-line security/detect-object-injection */
|
|
96
|
+
const { block, modifier } = this.#blockModifiers[i];
|
|
97
|
+
if (source.src.indexOf(`block ${block}`) > -1) {
|
|
98
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
99
|
+
source.src = source.src.replace(`block ${block} %}`, `block ${block} %}${modifier(name)}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return source;
|
|
103
|
+
}
|
|
104
|
+
}
|