@dwp/govuk-casa 7.0.6 → 8.0.0-alpha1

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 (219) hide show
  1. package/README.md +22 -17
  2. package/dist/{casa → assets}/css/casa-ie8.css +1 -1
  3. package/dist/assets/css/casa.css +1 -0
  4. package/dist/casa.d.ts +10 -0
  5. package/dist/casa.js +44 -0
  6. package/dist/lib/CasaTemplateLoader.d.ts +19 -0
  7. package/dist/lib/CasaTemplateLoader.js +57 -0
  8. package/dist/lib/JourneyContext.d.ts +255 -0
  9. package/dist/lib/JourneyContext.js +681 -0
  10. package/dist/lib/MutableRouter.d.ts +155 -0
  11. package/dist/lib/MutableRouter.js +272 -0
  12. package/dist/lib/Plan.d.ts +119 -0
  13. package/dist/lib/Plan.js +382 -0
  14. package/dist/lib/ValidationError.d.ts +70 -0
  15. package/dist/lib/ValidationError.js +156 -0
  16. package/dist/lib/ValidatorFactory.d.ts +24 -0
  17. package/dist/lib/ValidatorFactory.js +87 -0
  18. package/dist/lib/configure.d.ts +205 -0
  19. package/dist/lib/configure.js +215 -0
  20. package/dist/lib/dirname.cjs +1 -0
  21. package/dist/lib/end-session.d.ts +12 -0
  22. package/dist/lib/end-session.js +24 -0
  23. package/dist/lib/field.d.ts +79 -0
  24. package/dist/lib/field.js +223 -0
  25. package/dist/lib/logger.d.ts +8 -0
  26. package/dist/lib/logger.js +19 -0
  27. package/dist/lib/nunjucks-filters.d.ts +26 -0
  28. package/dist/lib/nunjucks-filters.js +112 -0
  29. package/dist/lib/nunjucks.d.ts +22 -0
  30. package/dist/lib/nunjucks.js +49 -0
  31. package/dist/lib/utils.d.ts +22 -0
  32. package/dist/lib/utils.js +44 -0
  33. package/dist/lib/validators/dateObject.d.ts +4 -0
  34. package/dist/lib/validators/dateObject.js +135 -0
  35. package/dist/lib/validators/email.d.ts +4 -0
  36. package/dist/lib/validators/email.js +46 -0
  37. package/dist/lib/validators/inArray.d.ts +4 -0
  38. package/dist/lib/validators/inArray.js +60 -0
  39. package/dist/lib/validators/index.d.ts +21 -0
  40. package/dist/lib/validators/index.js +47 -0
  41. package/dist/lib/validators/nino.d.ts +4 -0
  42. package/dist/lib/validators/nino.js +46 -0
  43. package/dist/lib/validators/postalAddressObject.d.ts +4 -0
  44. package/dist/lib/validators/postalAddressObject.js +123 -0
  45. package/dist/lib/validators/regex.d.ts +4 -0
  46. package/dist/lib/validators/regex.js +40 -0
  47. package/dist/lib/validators/required.d.ts +4 -0
  48. package/dist/lib/validators/required.js +56 -0
  49. package/dist/lib/validators/strlen.d.ts +4 -0
  50. package/dist/lib/validators/strlen.js +51 -0
  51. package/dist/lib/validators/wordCount.d.ts +5 -0
  52. package/dist/lib/validators/wordCount.js +54 -0
  53. package/dist/lib/waypoint-url.d.ts +17 -0
  54. package/dist/lib/waypoint-url.js +46 -0
  55. package/dist/middleware/body-parser.d.ts +1 -0
  56. package/dist/middleware/body-parser.js +24 -0
  57. package/dist/middleware/csrf.d.ts +1 -0
  58. package/dist/middleware/csrf.js +31 -0
  59. package/dist/middleware/data.d.ts +6 -0
  60. package/dist/middleware/data.js +53 -0
  61. package/dist/middleware/dirname.cjs +1 -0
  62. package/dist/middleware/gather-fields.d.ts +5 -0
  63. package/dist/middleware/gather-fields.js +39 -0
  64. package/dist/middleware/i18n.d.ts +4 -0
  65. package/dist/middleware/i18n.js +87 -0
  66. package/dist/middleware/post.d.ts +1 -0
  67. package/dist/middleware/post.js +42 -0
  68. package/dist/middleware/pre.d.ts +3 -0
  69. package/dist/middleware/pre.js +38 -0
  70. package/dist/middleware/progress-journey.d.ts +6 -0
  71. package/dist/middleware/progress-journey.js +82 -0
  72. package/dist/middleware/sanitise-fields.d.ts +5 -0
  73. package/dist/middleware/sanitise-fields.js +48 -0
  74. package/dist/middleware/session.d.ts +10 -0
  75. package/dist/middleware/session.js +115 -0
  76. package/dist/middleware/skip-waypoint.d.ts +5 -0
  77. package/dist/middleware/skip-waypoint.js +40 -0
  78. package/dist/middleware/steer-journey.d.ts +6 -0
  79. package/dist/middleware/steer-journey.js +44 -0
  80. package/dist/middleware/validate-fields.d.ts +7 -0
  81. package/dist/middleware/validate-fields.js +76 -0
  82. package/dist/mjs/esm-wrapper.js +10 -0
  83. package/dist/mjs/package.json +3 -0
  84. package/dist/package.json +3 -0
  85. package/dist/routes/ancillary.d.ts +4 -0
  86. package/dist/routes/ancillary.js +19 -0
  87. package/dist/routes/dirname.cjs +1 -0
  88. package/dist/routes/journey.d.ts +8 -0
  89. package/dist/routes/journey.js +130 -0
  90. package/dist/routes/static.d.ts +26 -0
  91. package/dist/routes/static.js +67 -0
  92. package/package.json +45 -86
  93. package/views/casa/components/checkboxes/template.njk +4 -1
  94. package/views/casa/components/date-input/template.njk +3 -3
  95. package/views/casa/components/journey-form/README.md +3 -1
  96. package/views/casa/components/journey-form/template.njk +1 -1
  97. package/views/casa/components/postal-address-object/template.njk +5 -5
  98. package/views/casa/components/radios/template.njk +1 -1
  99. package/views/casa/layouts/journey.njk +26 -9
  100. package/views/casa/layouts/main.njk +6 -19
  101. package/views/casa/partials/scripts.njk +8 -3
  102. package/views/casa/partials/styles.njk +2 -2
  103. package/casa.js +0 -208
  104. package/definitions/review-page.js +0 -60
  105. package/dist/casa/css/casa.css +0 -1
  106. package/dist/casa/js/casa.js +0 -1
  107. package/index.d.ts +0 -121
  108. package/lib/ConfigIngestor.js +0 -588
  109. package/lib/GatherModifier.js +0 -14
  110. package/lib/I18n.js +0 -160
  111. package/lib/JourneyContext.d.ts +0 -97
  112. package/lib/JourneyContext.js +0 -552
  113. package/lib/JourneyMap.js +0 -233
  114. package/lib/JourneyRoad.js +0 -330
  115. package/lib/Logger.js +0 -59
  116. package/lib/PageDictionary.d.ts +0 -11
  117. package/lib/PageDirectory.js +0 -77
  118. package/lib/Plan.js +0 -423
  119. package/lib/RoadConverter.js +0 -153
  120. package/lib/UserJourney.js +0 -8
  121. package/lib/Util.js +0 -227
  122. package/lib/Validation.js +0 -20
  123. package/lib/bootstrap/end-session.js +0 -44
  124. package/lib/bootstrap/load-definitions.js +0 -64
  125. package/lib/commonBodyParser.js +0 -15
  126. package/lib/enums.js +0 -6
  127. package/lib/gather-modifiers/index.js +0 -7
  128. package/lib/gather-modifiers/trimPostalAddressObject.js +0 -75
  129. package/lib/gather-modifiers/trimWhitespace.js +0 -16
  130. package/lib/utils/createGetRequest.d.ts +0 -5
  131. package/lib/utils/createGetRequest.js +0 -59
  132. package/lib/utils/index.js +0 -11
  133. package/lib/utils/parseRequest.d.ts +0 -5
  134. package/lib/utils/parseRequest.js +0 -72
  135. package/lib/utils/sanitise.js +0 -74
  136. package/lib/utils/validate.js +0 -32
  137. package/lib/validation/ArrayObjectField.js +0 -49
  138. package/lib/validation/ObjectField.js +0 -53
  139. package/lib/validation/SimpleField.d.ts +0 -11
  140. package/lib/validation/SimpleField.js +0 -46
  141. package/lib/validation/ValidationError.d.ts +0 -14
  142. package/lib/validation/ValidationError.js +0 -170
  143. package/lib/validation/ValidatorFactory.d.ts +0 -32
  144. package/lib/validation/ValidatorFactory.js +0 -91
  145. package/lib/validation/index.js +0 -22
  146. package/lib/validation/processor/flattenErrorArray.js +0 -24
  147. package/lib/validation/processor/queue.js +0 -214
  148. package/lib/validation/processor.js +0 -84
  149. package/lib/validation/rules/README.md +0 -3
  150. package/lib/validation/rules/ValidationRules.d.ts +0 -22
  151. package/lib/validation/rules/dateObject.js +0 -156
  152. package/lib/validation/rules/email.js +0 -44
  153. package/lib/validation/rules/inArray.js +0 -61
  154. package/lib/validation/rules/index.js +0 -23
  155. package/lib/validation/rules/nino.js +0 -48
  156. package/lib/validation/rules/optional.js +0 -14
  157. package/lib/validation/rules/postalAddressObject.js +0 -142
  158. package/lib/validation/rules/regex.js +0 -39
  159. package/lib/validation/rules/required.js +0 -57
  160. package/lib/validation/rules/strlen.js +0 -57
  161. package/lib/validation/rules/wordCount.js +0 -61
  162. package/lib/view-filters/formatDateObject.js +0 -35
  163. package/lib/view-filters/includes.js +0 -10
  164. package/lib/view-filters/index.js +0 -23
  165. package/lib/view-filters/mergeObjectsDeep.js +0 -21
  166. package/lib/view-filters/renderAsAttributes.js +0 -33
  167. package/middleware/errors/404.js +0 -12
  168. package/middleware/errors/catch-all.js +0 -27
  169. package/middleware/errors/index.js +0 -9
  170. package/middleware/headers/config-defaults.js +0 -57
  171. package/middleware/headers/headers.js +0 -40
  172. package/middleware/headers/index.js +0 -9
  173. package/middleware/i18n/i18n.js +0 -56
  174. package/middleware/i18n/index.js +0 -16
  175. package/middleware/index.js +0 -55
  176. package/middleware/mount/index.js +0 -9
  177. package/middleware/mount/mount.js +0 -10
  178. package/middleware/nunjucks/environment.js +0 -57
  179. package/middleware/nunjucks/index.js +0 -8
  180. package/middleware/page/csrf.js +0 -37
  181. package/middleware/page/edit-mode.js +0 -52
  182. package/middleware/page/gather.js +0 -75
  183. package/middleware/page/index.js +0 -103
  184. package/middleware/page/journey-continue.js +0 -157
  185. package/middleware/page/journey-rails.js +0 -102
  186. package/middleware/page/prepare-request.js +0 -77
  187. package/middleware/page/render.js +0 -75
  188. package/middleware/page/skip.js +0 -72
  189. package/middleware/page/utils.js +0 -206
  190. package/middleware/page/validate.js +0 -67
  191. package/middleware/session/expiry.js +0 -95
  192. package/middleware/session/genid.js +0 -18
  193. package/middleware/session/index.js +0 -18
  194. package/middleware/session/init.js +0 -25
  195. package/middleware/session/seed.js +0 -50
  196. package/middleware/session/timeout.js +0 -5
  197. package/middleware/static/asset-versions.js +0 -23
  198. package/middleware/static/index.js +0 -104
  199. package/middleware/static/prepare-assets.js +0 -51
  200. package/middleware/static/serve-assets.js +0 -58
  201. package/middleware/variables/index.js +0 -12
  202. package/middleware/variables/variables.js +0 -35
  203. package/src/browserconfig.xml +0 -5
  204. package/src/js/casa.js +0 -132
  205. package/src/scss/_casaElements.scss +0 -11
  206. package/src/scss/_casaGovukTemplateJinjaPolyfill.scss +0 -39
  207. package/src/scss/_casaMountUrl.scss +0 -8
  208. package/src/scss/casa-ie8.scss +0 -3
  209. package/src/scss/casa.scss +0 -14
  210. package/test/unit/templates/README.md +0 -5
  211. package/test/utils/BaseTestWaypoint.js +0 -106
  212. package/test/utils/concatWaypoints.js +0 -26
  213. package/test/utils/index.js +0 -6
  214. package/test/utils/testTraversal.js +0 -90
  215. package/views/casa/partials/cookie_message.njk +0 -3
  216. package/views/casa/partials/phase_banner_alpha.njk +0 -8
  217. package/views/casa/partials/phase_banner_beta.njk +0 -8
  218. package/views/casa/review/page-block.njk +0 -8
  219. package/views/casa/review/review.njk +0 -47
package/lib/I18n.js DELETED
@@ -1,160 +0,0 @@
1
- /**
2
- * I18n utilities.
3
- *
4
- * When this module is first required, be sure to invoke with the directories
5
- * and list of supported locales, e.g:
6
- * const I18n = require('govuk-casa/lib/I18n')(localeDirs, supportedLocales);
7
- *
8
- * This essentially iniialises the I18n singleton object.
9
- */
10
-
11
- const npath = require('path');
12
- const fs = require('fs');
13
- const logger = require('./Logger')('i18n');
14
-
15
- const LOCALE_DATA = Object.create(null);
16
-
17
- /**
18
- * Translator class.
19
- */
20
- class Translator {
21
- /**
22
- * Constructor.
23
- *
24
- * @param {string} lang Language to use for all translations.
25
- */
26
- constructor(lang) {
27
- if (typeof lang !== 'string') {
28
- throw new TypeError('Translator must be instantiated with a language');
29
- }
30
- this.language = lang;
31
- }
32
-
33
- /**
34
- * Retrieve the language.
35
- *
36
- * @returns {string} Language code.
37
- */
38
- getLanguage() {
39
- return this.language;
40
- }
41
-
42
- /**
43
- * Translate string.
44
- *
45
- * The replacements can be primitives, a function or a object containing such
46
- * values. For example, the following are all valid:
47
- * t('Hello, %s', 'World') = Hello, World
48
- * t('Pay £${fee}', {fee:100}) = Pay £100
49
- *
50
- * @param {string} key String to translate
51
- * @param {...any} subs Replacements
52
- * @returns {string} Translated string
53
- * @throws {Error} When a function substitution is used
54
- */
55
- t(key, ...subs) {
56
- const k = (key || '').split(':');
57
- let str = key;
58
- if (typeof LOCALE_DATA[this.language][k[0]] !== 'undefined') {
59
- str = typeof LOCALE_DATA[this.language][k[0]][k[1]] === 'undefined'
60
- ? key
61
- : LOCALE_DATA[this.language][k[0]][k[1]];
62
- }
63
-
64
- subs.forEach((sub) => {
65
- if (typeof sub === 'object') {
66
- Object.keys(sub).forEach((subkey) => {
67
- str = str.replace(new RegExp(`\\$\\{${subkey}\\}`), sub[subkey]);
68
- });
69
- } else if (typeof sub === 'function') {
70
- throw new Error('Function substitions are not yet supported');
71
- } else {
72
- str = str.replace(/%s/, sub);
73
- }
74
- });
75
-
76
- return str;
77
- }
78
- }
79
-
80
- module.exports = function TranslaterInit(localeDirs, supportedLocales) {
81
- /**
82
- * Flattens a JSON object structure into a "flat" object indexed by paths in a
83
- * dot-notation. For example, calling `flatten()` on the structure ...
84
- * {
85
- * "person": {
86
- * "title": {
87
- * "label": "Miss"
88
- * }.
89
- * }.
90
- * }.
91
- *
92
- * ... Results in the new object, written to `tgt`:
93
- * {
94
- * "person.title.label": "Miss"
95
- * }
96
- *
97
- * @param {string} path Current path (used by recursive element)
98
- * @param {object} src Source object to flatten
99
- * @param {object} tgt Object into which the resulting data is written
100
- * @returns {void}
101
- */
102
- function flatten(path, src, tgt) {
103
- Object.keys(src).forEach((key) => {
104
- const nodepath = path ? [path, key].join('.') : key;
105
- if (typeof src[key] === 'object') {
106
- flatten(nodepath, src[key], tgt);
107
- } else {
108
- tgt[nodepath] = src[key]; /* eslint-disable-line no-param-reassign */
109
- }
110
- });
111
- }
112
-
113
- /**
114
- * Load the locale into the `LOCALE_DATA` object.
115
- *
116
- * @param {string} locale Locale to load (e.g. "en").
117
- * @returns {void}
118
- * @throws {Error} When locale is missing
119
- */
120
- function loadLocale(locale) {
121
- try {
122
- LOCALE_DATA[locale] = Object.create(null);
123
- localeDirs.forEach((localeDir) => {
124
- const langDir = npath.resolve(localeDir, locale);
125
- if (fs.existsSync(langDir)) {
126
- logger.info('Loading %s locale from %s ...', locale, langDir);
127
- fs.readdirSync(langDir).forEach((file) => {
128
- const ns = npath.basename(file, '.json');
129
- if (typeof LOCALE_DATA[locale][ns] === 'undefined') {
130
- LOCALE_DATA[locale][ns] = Object.create(null);
131
- }
132
-
133
- // Load file and strip newlines out, otherwise JSON.parse will fail.
134
- // Newlines may be in the file to make them more readable during
135
- // content creation, but they are invalid in JSON.
136
- let json = fs.readFileSync(npath.resolve(langDir, file), 'utf8');
137
- json = json.replace(/[\r\n]/g, '');
138
- json = JSON.parse(json);
139
- flatten(null, json, LOCALE_DATA[locale][ns]);
140
- });
141
- }
142
- });
143
- } catch (e) {
144
- logger.error('Error loading locale: %s', e);
145
- throw e;
146
- }
147
- }
148
-
149
- // Load data for all supported locales
150
- if (!Array.isArray(supportedLocales) || !supportedLocales.length) {
151
- throw new Error('You must define at least one supported locale');
152
- }
153
- supportedLocales.forEach((l) => {
154
- loadLocale(l);
155
- });
156
-
157
- return {
158
- Translator,
159
- };
160
- };
@@ -1,97 +0,0 @@
1
- import ValidationError = require("./validation/ValidationError");
2
- import PageMeta from '../index';
3
-
4
- export = JourneyContext;
5
-
6
- declare class JourneyContext {
7
- constructor(data?: object, validation?: { [key: string]: JourneyContextPageValidation }, nav?: object, identity?: object);
8
-
9
- toObject(): JourneyContextObject;
10
-
11
- static fromObject(obj: JourneyContextObject): JourneyContext;
12
-
13
- static fromContext(context: JourneyContext): JourneyContext;
14
-
15
- public data: object;
16
-
17
- public validation: JourneyContextPageValidation;
18
-
19
- public nav: JourneyContextNavObject;
20
-
21
- public identity: JourneyContextIdentityObject;
22
-
23
- getData(): object;
24
-
25
- getDataForPage(pageId: string | typeof PageMeta): object;
26
-
27
- setData(data: object): JourneyContext;
28
-
29
- setDataForPage(page: string | typeof PageMeta, data: object): JourneyContext;
30
-
31
- getValidationErrors(): { [key: string]: JourneyContextPageValidation };
32
-
33
- removeValidationStateForPage(pageId: string): JourneyContext;
34
-
35
- clearValidationErrorsForPage(pageId: string): JourneyContext;
36
-
37
- setValidationErrorsForPage(pageId: string, errors: JourneyContextPageValidation): JourneyContext;
38
-
39
- getValidationErrorsForPage(pageId: string): JourneyContextPageValidation;
40
-
41
- hasValidationErrorsForPage(pageId: string): boolean;
42
-
43
- getNavigation(): JourneyContextNavObject;
44
-
45
- setNavigationLanguage(language: string): JourneyContext;
46
-
47
- isPageValid(pageId: string): boolean;
48
-
49
- getIdentity(): JourneyContextIdentityObject;
50
-
51
- isDefault(): boolean;
52
-
53
- static initContextStore(session: object): void;
54
-
55
- static validateContextId(id: string): string;
56
-
57
- static getContextById(session: object, id: string): JourneyContext;
58
-
59
- static getContextByName(session: object, name: string): JourneyContext;
60
-
61
- static getContextsByTag(session: object, tag: string): JourneyContext;
62
-
63
- static getContexts(session: object): Array<JourneyContext>;
64
-
65
- static putContext(session: object, context:JourneyContext): void;
66
-
67
- static removeContext(session: object, context:JourneyContext): void;
68
-
69
- static removeContextById(session: object, id:string): void;
70
-
71
- static removeContextByName(session: object, name:string): void;
72
-
73
- static removeContextsByTag(session: object, tag:string): void;
74
-
75
- static removeContexts(session: object): void;
76
- }
77
-
78
- interface JourneyContextObject {
79
- data?: object;
80
- validation?: JourneyContextPageValidation;
81
- nav?: JourneyContextNavObject;
82
- identity?: JourneyContextIdentityObject;
83
- }
84
-
85
- interface JourneyContextPageValidation {
86
- [key: string]: Array<ValidationError>
87
- }
88
-
89
- interface JourneyContextNavObject {
90
- language?: string;
91
- }
92
-
93
- interface JourneyContextIdentityObject {
94
- id: String,
95
- name?: String,
96
- tags?: Array<String>,
97
- }