@dwp/govuk-casa 9.7.0 → 10.1.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 (278) hide show
  1. package/dist/assets/css/casa.css +1 -1
  2. package/dist/assets/css/casa.css.map +1 -1
  3. package/dist/casa.d.ts +90 -44
  4. package/dist/casa.d.ts.map +1 -0
  5. package/dist/casa.js +85 -101
  6. package/dist/core-plugins/edit-snapshot/src/configure.d.ts +1 -0
  7. package/dist/core-plugins/edit-snapshot/src/configure.d.ts.map +1 -0
  8. package/dist/core-plugins/edit-snapshot/src/configure.js +7 -14
  9. package/dist/core-plugins/edit-snapshot/src/index.d.ts +1 -0
  10. package/dist/core-plugins/edit-snapshot/src/index.d.ts.map +1 -0
  11. package/dist/core-plugins/edit-snapshot/src/index.js +3 -9
  12. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts +2 -1
  13. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.d.ts.map +1 -0
  14. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js +8 -13
  15. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts +2 -1
  16. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.d.ts.map +1 -0
  17. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js +13 -18
  18. package/dist/core-plugins/edit-snapshot/src/utils.d.ts +8 -5
  19. package/dist/core-plugins/edit-snapshot/src/utils.d.ts.map +1 -0
  20. package/dist/core-plugins/edit-snapshot/src/utils.js +37 -19
  21. package/dist/core-plugins/index.d.ts +1 -0
  22. package/dist/core-plugins/index.d.ts.map +1 -0
  23. package/dist/core-plugins/index.js +1 -9
  24. package/dist/lib/CasaTemplateLoader.d.ts +1 -0
  25. package/dist/lib/CasaTemplateLoader.d.ts.map +1 -0
  26. package/dist/lib/CasaTemplateLoader.js +2 -6
  27. package/dist/lib/JourneyContext.d.ts +22 -11
  28. package/dist/lib/JourneyContext.d.ts.map +1 -0
  29. package/dist/lib/JourneyContext.js +40 -45
  30. package/dist/lib/MutableRouter.d.ts +79 -55
  31. package/dist/lib/MutableRouter.d.ts.map +1 -0
  32. package/dist/lib/MutableRouter.js +53 -45
  33. package/dist/lib/NullObject.d.ts +3 -0
  34. package/dist/lib/NullObject.d.ts.map +1 -0
  35. package/dist/lib/NullObject.js +3 -0
  36. package/dist/lib/Plan.d.ts +2 -1
  37. package/dist/lib/Plan.d.ts.map +1 -0
  38. package/dist/lib/Plan.js +44 -62
  39. package/dist/lib/ValidationError.d.ts +2 -1
  40. package/dist/lib/ValidationError.d.ts.map +1 -0
  41. package/dist/lib/ValidationError.js +3 -11
  42. package/dist/lib/ValidatorFactory.d.ts +5 -6
  43. package/dist/lib/ValidatorFactory.d.ts.map +1 -0
  44. package/dist/lib/ValidatorFactory.js +4 -12
  45. package/dist/lib/configuration-ingestor.d.ts +10 -22
  46. package/dist/lib/configuration-ingestor.d.ts.map +1 -0
  47. package/dist/lib/configuration-ingestor.js +61 -143
  48. package/dist/lib/configure.d.ts +2 -1
  49. package/dist/lib/configure.d.ts.map +1 -0
  50. package/dist/lib/configure.js +40 -52
  51. package/dist/lib/constants.d.ts +1 -0
  52. package/dist/lib/constants.d.ts.map +1 -0
  53. package/dist/lib/constants.js +8 -12
  54. package/dist/lib/context-id-generators.d.ts +1 -0
  55. package/dist/lib/context-id-generators.d.ts.map +1 -0
  56. package/dist/lib/context-id-generators.js +4 -9
  57. package/dist/lib/end-session.d.ts +2 -1
  58. package/dist/lib/end-session.d.ts.map +1 -0
  59. package/dist/lib/end-session.js +4 -11
  60. package/dist/lib/field.d.ts +2 -1
  61. package/dist/lib/field.d.ts.map +1 -0
  62. package/dist/lib/field.js +11 -21
  63. package/dist/lib/index.d.ts +1 -0
  64. package/dist/lib/index.d.ts.map +1 -0
  65. package/dist/lib/index.js +13 -65
  66. package/dist/lib/logger.d.ts +25 -2
  67. package/dist/lib/logger.d.ts.map +1 -0
  68. package/dist/lib/logger.js +18 -9
  69. package/dist/lib/mount.d.ts +1 -0
  70. package/dist/lib/mount.d.ts.map +1 -0
  71. package/dist/lib/mount.js +10 -16
  72. package/dist/lib/nunjucks-filters.d.ts +7 -3
  73. package/dist/lib/nunjucks-filters.d.ts.map +1 -0
  74. package/dist/lib/nunjucks-filters.js +58 -71
  75. package/dist/lib/nunjucks.d.ts +4 -4
  76. package/dist/lib/nunjucks.d.ts.map +1 -0
  77. package/dist/lib/nunjucks.js +14 -26
  78. package/dist/lib/utils.d.ts +4 -2
  79. package/dist/lib/utils.d.ts.map +1 -0
  80. package/dist/lib/utils.js +14 -28
  81. package/dist/lib/validators/dateObject.d.ts +1 -0
  82. package/dist/lib/validators/dateObject.d.ts.map +1 -0
  83. package/dist/lib/validators/dateObject.js +14 -21
  84. package/dist/lib/validators/email.d.ts +1 -0
  85. package/dist/lib/validators/email.d.ts.map +1 -0
  86. package/dist/lib/validators/email.js +8 -15
  87. package/dist/lib/validators/inArray.d.ts +1 -0
  88. package/dist/lib/validators/inArray.d.ts.map +1 -0
  89. package/dist/lib/validators/inArray.js +8 -15
  90. package/dist/lib/validators/index.d.ts +1 -0
  91. package/dist/lib/validators/index.d.ts.map +1 -0
  92. package/dist/lib/validators/index.js +21 -27
  93. package/dist/lib/validators/nino.d.ts +1 -0
  94. package/dist/lib/validators/nino.d.ts.map +1 -0
  95. package/dist/lib/validators/nino.js +6 -13
  96. package/dist/lib/validators/postalAddressObject.d.ts +1 -0
  97. package/dist/lib/validators/postalAddressObject.d.ts.map +1 -0
  98. package/dist/lib/validators/postalAddressObject.js +12 -19
  99. package/dist/lib/validators/range.d.ts +1 -0
  100. package/dist/lib/validators/range.d.ts.map +1 -0
  101. package/dist/lib/validators/range.js +6 -13
  102. package/dist/lib/validators/regex.d.ts +1 -0
  103. package/dist/lib/validators/regex.d.ts.map +1 -0
  104. package/dist/lib/validators/regex.js +6 -13
  105. package/dist/lib/validators/required.d.ts +1 -0
  106. package/dist/lib/validators/required.d.ts.map +1 -0
  107. package/dist/lib/validators/required.js +9 -17
  108. package/dist/lib/validators/strlen.d.ts +1 -0
  109. package/dist/lib/validators/strlen.d.ts.map +1 -0
  110. package/dist/lib/validators/strlen.js +6 -13
  111. package/dist/lib/validators/wordCount.d.ts +1 -0
  112. package/dist/lib/validators/wordCount.d.ts.map +1 -0
  113. package/dist/lib/validators/wordCount.js +6 -13
  114. package/dist/lib/waypoint-url.d.ts +3 -2
  115. package/dist/lib/waypoint-url.d.ts.map +1 -0
  116. package/dist/lib/waypoint-url.js +12 -19
  117. package/dist/middleware/body-parser.d.ts +1 -0
  118. package/dist/middleware/body-parser.d.ts.map +1 -0
  119. package/dist/middleware/body-parser.js +4 -9
  120. package/dist/middleware/csrf.d.ts +1 -0
  121. package/dist/middleware/csrf.d.ts.map +1 -0
  122. package/dist/middleware/csrf.js +4 -8
  123. package/dist/middleware/data.d.ts +2 -3
  124. package/dist/middleware/data.d.ts.map +1 -0
  125. package/dist/middleware/data.js +23 -25
  126. package/dist/middleware/gather-fields.d.ts +3 -1
  127. package/dist/middleware/gather-fields.d.ts.map +1 -0
  128. package/dist/middleware/gather-fields.js +13 -14
  129. package/dist/middleware/i18n.d.ts +1 -0
  130. package/dist/middleware/i18n.d.ts.map +1 -0
  131. package/dist/middleware/i18n.js +26 -31
  132. package/dist/middleware/post.d.ts +4 -2
  133. package/dist/middleware/post.d.ts.map +1 -0
  134. package/dist/middleware/post.js +6 -11
  135. package/dist/middleware/pre.d.ts +2 -1
  136. package/dist/middleware/pre.d.ts.map +1 -0
  137. package/dist/middleware/pre.js +6 -12
  138. package/dist/middleware/progress-journey.d.ts +5 -3
  139. package/dist/middleware/progress-journey.d.ts.map +1 -0
  140. package/dist/middleware/progress-journey.js +20 -18
  141. package/dist/middleware/sanitise-fields.d.ts +5 -3
  142. package/dist/middleware/sanitise-fields.d.ts.map +1 -0
  143. package/dist/middleware/sanitise-fields.js +25 -17
  144. package/dist/middleware/serve-first-waypoint.d.ts +1 -0
  145. package/dist/middleware/serve-first-waypoint.d.ts.map +1 -0
  146. package/dist/middleware/serve-first-waypoint.js +3 -6
  147. package/dist/middleware/session.d.ts +15 -0
  148. package/dist/middleware/session.d.ts.map +1 -0
  149. package/dist/middleware/session.js +53 -57
  150. package/dist/middleware/skip-waypoint.d.ts +3 -2
  151. package/dist/middleware/skip-waypoint.d.ts.map +1 -0
  152. package/dist/middleware/skip-waypoint.js +15 -14
  153. package/dist/middleware/steer-journey.d.ts +2 -1
  154. package/dist/middleware/steer-journey.d.ts.map +1 -0
  155. package/dist/middleware/steer-journey.js +7 -13
  156. package/dist/middleware/strip-proxy-path.d.ts +3 -2
  157. package/dist/middleware/strip-proxy-path.d.ts.map +1 -0
  158. package/dist/middleware/strip-proxy-path.js +24 -24
  159. package/dist/middleware/validate-fields.d.ts +7 -4
  160. package/dist/middleware/validate-fields.d.ts.map +1 -0
  161. package/dist/middleware/validate-fields.js +22 -11
  162. package/dist/routes/ancillary.d.ts +1 -0
  163. package/dist/routes/ancillary.d.ts.map +1 -0
  164. package/dist/routes/ancillary.js +3 -10
  165. package/dist/routes/journey.d.ts +7 -2
  166. package/dist/routes/journey.d.ts.map +1 -0
  167. package/dist/routes/journey.js +56 -55
  168. package/dist/routes/static.d.ts +1 -0
  169. package/dist/routes/static.d.ts.map +1 -0
  170. package/dist/routes/static.js +15 -23
  171. package/package.json +30 -36
  172. package/src/casa.js +63 -31
  173. package/src/core-plugins/edit-snapshot/src/post-steer-hook.js +1 -0
  174. package/src/core-plugins/edit-snapshot/src/pre-steer-hook.js +2 -1
  175. package/src/core-plugins/edit-snapshot/src/utils.js +29 -1
  176. package/src/lib/JourneyContext.js +31 -28
  177. package/src/lib/MutableRouter.js +52 -38
  178. package/src/lib/NullObject.js +4 -0
  179. package/src/lib/Plan.js +41 -55
  180. package/src/lib/ValidationError.js +2 -4
  181. package/src/lib/ValidatorFactory.js +3 -5
  182. package/src/lib/configuration-ingestor.js +18 -38
  183. package/src/lib/configure.js +7 -10
  184. package/src/lib/end-session.js +1 -1
  185. package/src/lib/field.js +7 -12
  186. package/src/lib/logger.js +16 -0
  187. package/src/lib/mount.js +1 -1
  188. package/src/lib/nunjucks-filters.js +51 -61
  189. package/src/lib/nunjucks.js +5 -13
  190. package/src/lib/utils.js +2 -1
  191. package/src/lib/validators/dateObject.js +3 -4
  192. package/src/lib/validators/postalAddressObject.js +6 -7
  193. package/src/lib/validators/required.js +1 -3
  194. package/src/lib/waypoint-url.js +15 -19
  195. package/src/middleware/csrf.js +1 -1
  196. package/src/middleware/data.js +13 -13
  197. package/src/middleware/gather-fields.js +8 -2
  198. package/src/middleware/i18n.js +9 -6
  199. package/src/middleware/post.js +3 -1
  200. package/src/middleware/pre.js +1 -1
  201. package/src/middleware/progress-journey.js +8 -0
  202. package/src/middleware/sanitise-fields.js +17 -2
  203. package/src/middleware/session.js +53 -12
  204. package/src/middleware/skip-waypoint.js +8 -1
  205. package/src/middleware/steer-journey.js +1 -1
  206. package/src/middleware/strip-proxy-path.js +21 -16
  207. package/src/middleware/validate-fields.js +19 -0
  208. package/src/routes/journey.js +18 -8
  209. package/src/routes/static.js +5 -4
  210. package/views/casa/layouts/journey.njk +1 -1
  211. package/views/casa/layouts/main.njk +11 -21
  212. package/dist/casa.js.map +0 -1
  213. package/dist/core-plugins/edit-snapshot/src/configure.js.map +0 -1
  214. package/dist/core-plugins/edit-snapshot/src/index.js.map +0 -1
  215. package/dist/core-plugins/edit-snapshot/src/post-steer-hook.js.map +0 -1
  216. package/dist/core-plugins/edit-snapshot/src/pre-steer-hook.js.map +0 -1
  217. package/dist/core-plugins/edit-snapshot/src/utils.js.map +0 -1
  218. package/dist/core-plugins/index.js.map +0 -1
  219. package/dist/lib/CasaTemplateLoader.js.map +0 -1
  220. package/dist/lib/JourneyContext.js.map +0 -1
  221. package/dist/lib/MutableRouter.js.map +0 -1
  222. package/dist/lib/Plan.js.map +0 -1
  223. package/dist/lib/ValidationError.js.map +0 -1
  224. package/dist/lib/ValidatorFactory.js.map +0 -1
  225. package/dist/lib/configuration-ingestor.js.map +0 -1
  226. package/dist/lib/configure.js.map +0 -1
  227. package/dist/lib/constants.js.map +0 -1
  228. package/dist/lib/context-id-generators.js.map +0 -1
  229. package/dist/lib/dirname.cjs +0 -1
  230. package/dist/lib/dirname.d.cts +0 -2
  231. package/dist/lib/end-session.js.map +0 -1
  232. package/dist/lib/field.js.map +0 -1
  233. package/dist/lib/index.js.map +0 -1
  234. package/dist/lib/logger.js.map +0 -1
  235. package/dist/lib/mount.js.map +0 -1
  236. package/dist/lib/nunjucks-filters.js.map +0 -1
  237. package/dist/lib/nunjucks.js.map +0 -1
  238. package/dist/lib/utils.js.map +0 -1
  239. package/dist/lib/validators/dateObject.js.map +0 -1
  240. package/dist/lib/validators/email.js.map +0 -1
  241. package/dist/lib/validators/inArray.js.map +0 -1
  242. package/dist/lib/validators/index.js.map +0 -1
  243. package/dist/lib/validators/nino.js.map +0 -1
  244. package/dist/lib/validators/postalAddressObject.js.map +0 -1
  245. package/dist/lib/validators/range.js.map +0 -1
  246. package/dist/lib/validators/regex.js.map +0 -1
  247. package/dist/lib/validators/required.js.map +0 -1
  248. package/dist/lib/validators/strlen.js.map +0 -1
  249. package/dist/lib/validators/wordCount.js.map +0 -1
  250. package/dist/lib/waypoint-url.js.map +0 -1
  251. package/dist/middleware/body-parser.js.map +0 -1
  252. package/dist/middleware/csrf.js.map +0 -1
  253. package/dist/middleware/data.js.map +0 -1
  254. package/dist/middleware/dirname.cjs +0 -1
  255. package/dist/middleware/dirname.d.cts +0 -2
  256. package/dist/middleware/gather-fields.js.map +0 -1
  257. package/dist/middleware/i18n.js.map +0 -1
  258. package/dist/middleware/post.js.map +0 -1
  259. package/dist/middleware/pre.js.map +0 -1
  260. package/dist/middleware/progress-journey.js.map +0 -1
  261. package/dist/middleware/sanitise-fields.js.map +0 -1
  262. package/dist/middleware/serve-first-waypoint.js.map +0 -1
  263. package/dist/middleware/session.js.map +0 -1
  264. package/dist/middleware/skip-waypoint.js.map +0 -1
  265. package/dist/middleware/steer-journey.js.map +0 -1
  266. package/dist/middleware/strip-proxy-path.js.map +0 -1
  267. package/dist/middleware/validate-fields.js.map +0 -1
  268. package/dist/mjs/esm-wrapper.js +0 -20
  269. package/dist/mjs/package.json +0 -3
  270. package/dist/package.json +0 -3
  271. package/dist/routes/ancillary.js.map +0 -1
  272. package/dist/routes/dirname.cjs +0 -1
  273. package/dist/routes/dirname.d.cts +0 -2
  274. package/dist/routes/journey.js.map +0 -1
  275. package/dist/routes/static.js.map +0 -1
  276. package/src/lib/dirname.cjs +0 -1
  277. package/src/middleware/dirname.cjs +0 -1
  278. package/src/routes/dirname.cjs +0 -1
@@ -1,76 +1,11 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.validateI18nObject = validateI18nObject;
40
- exports.validateI18nDirs = validateI18nDirs;
41
- exports.validateI18nLocales = validateI18nLocales;
42
- exports.validateI18nFallbackLng = validateI18nFallbackLng;
43
- exports.validateMountUrl = validateMountUrl;
44
- exports.validateSessionObject = validateSessionObject;
45
- exports.validateViews = validateViews;
46
- exports.validateSessionSecret = validateSessionSecret;
47
- exports.validateSessionTtl = validateSessionTtl;
48
- exports.validateSessionName = validateSessionName;
49
- exports.validateSessionSecure = validateSessionSecure;
50
- exports.validateSessionStore = validateSessionStore;
51
- exports.validateSessionCookiePath = validateSessionCookiePath;
52
- exports.validateErrorVisibility = validateErrorVisibility;
53
- exports.validateSessionCookieSameSite = validateSessionCookieSameSite;
54
- exports.validatePageHooks = validatePageHooks;
55
- exports.validateFields = validateFields;
56
- exports.validatePages = validatePages;
57
- exports.validatePlan = validatePlan;
58
- exports.validateGlobalHooks = validateGlobalHooks;
59
- exports.validatePlugins = validatePlugins;
60
- exports.validateEvents = validateEvents;
61
- exports.validateHelmetConfigurator = validateHelmetConfigurator;
62
- exports.validateFormMaxParams = validateFormMaxParams;
63
- exports.validateFormMaxBytes = validateFormMaxBytes;
64
- exports.validateContextIdGenerator = validateContextIdGenerator;
65
- exports.validateGovukRebrand = validateGovukRebrand;
66
- exports.default = ingest;
67
- const bytes_1 = __importDefault(require("bytes"));
68
- const field_js_1 = require("./field.js");
69
- const Plan_js_1 = __importDefault(require("./Plan.js"));
70
- const logger_js_1 = __importDefault(require("./logger.js"));
71
- const utils_js_1 = require("./utils.js");
72
- const contextIdGenerators = __importStar(require("./context-id-generators.js"));
73
- const constants_js_1 = require("./constants.js");
1
+ import bytes from "bytes";
2
+ import { PageField } from "./field.js";
3
+ import NullObject from "./NullObject.js";
4
+ import Plan from "./Plan.js";
5
+ import logger from "./logger.js";
6
+ import { validateWaypoint, validateHookName, validateHookPath, validateView, } from "./utils.js";
7
+ import * as contextIdGenerators from "./context-id-generators.js";
8
+ import { CONFIG_ERROR_VISIBILITY_ALWAYS, CONFIG_ERROR_VISIBILITY_ONSUBMIT, } from "./constants.js";
74
9
  /**
75
10
  * @typedef {import("../casa").ConfigurationOptions} ConfigurationOptions
76
11
  * @access private
@@ -103,7 +38,11 @@ const constants_js_1 = require("./constants.js");
103
38
  * @typedef {import("../casa").ContextIdGenerator} ContextIdGenerator
104
39
  * @access private
105
40
  */
106
- const log = (0, logger_js_1.default)("lib:configuration-ingestor");
41
+ /**
42
+ * @typedef {true | false | "Lax" | "None" | "Strict" | "auto"} CookieSameSite
43
+ * @access private
44
+ */
45
+ const log = logger("lib:configuration-ingestor");
107
46
  const echo = (a) => a;
108
47
  /**
109
48
  * Validates and sanitises i18n object.
@@ -114,7 +53,7 @@ const echo = (a) => a;
114
53
  * @throws {TypeError} For invalid object.
115
54
  * @access private
116
55
  */
117
- function validateI18nObject(i18n = Object.create(null), cb = echo) {
56
+ export function validateI18nObject(i18n = new NullObject(), cb = echo) {
118
57
  if (Object.prototype.toString.call(i18n) !== "[object Object]") {
119
58
  throw new TypeError("I18n must be an object");
120
59
  }
@@ -129,7 +68,7 @@ function validateI18nObject(i18n = Object.create(null), cb = echo) {
129
68
  * @throws {TypeError} For invalid type.
130
69
  * @access private
131
70
  */
132
- function validateI18nDirs(dirs = []) {
71
+ export function validateI18nDirs(dirs = []) {
133
72
  if (!Array.isArray(dirs)) {
134
73
  throw new TypeError("I18n directories must be an array (i18n.dirs)");
135
74
  }
@@ -138,6 +77,7 @@ function validateI18nDirs(dirs = []) {
138
77
  if (typeof dir !== "string") {
139
78
  throw new TypeError(`I18n directory must be a string, got ${typeof dir} (i18n.dirs[${i++}])`);
140
79
  }
80
+ i++;
141
81
  }
142
82
  return dirs;
143
83
  }
@@ -150,7 +90,7 @@ function validateI18nDirs(dirs = []) {
150
90
  * @throws {TypeError} For invalid type.
151
91
  * @access private
152
92
  */
153
- function validateI18nLocales(locales = ["en", "cy"]) {
93
+ export function validateI18nLocales(locales = ["en", "cy"]) {
154
94
  if (!Array.isArray(locales)) {
155
95
  throw new TypeError("I18n locales must be an array (i18n.locales)");
156
96
  }
@@ -159,6 +99,7 @@ function validateI18nLocales(locales = ["en", "cy"]) {
159
99
  if (typeof locale !== "string") {
160
100
  throw new TypeError(`I18n locale must be a string, got ${typeof locale} (i18n.locales[${i++}])`);
161
101
  }
102
+ i++;
162
103
  }
163
104
  return locales;
164
105
  }
@@ -172,7 +113,7 @@ function validateI18nLocales(locales = ["en", "cy"]) {
172
113
  * @throws {TypeError} For invalid type.
173
114
  * @access private
174
115
  */
175
- function validateI18nFallbackLng(fallback, locales = ["en", "cy"]) {
116
+ export function validateI18nFallbackLng(fallback, locales = ["en", "cy"]) {
176
117
  if (fallback === undefined) {
177
118
  return false;
178
119
  }
@@ -192,7 +133,7 @@ function validateI18nFallbackLng(fallback, locales = ["en", "cy"]) {
192
133
  * @throws {SyntaxError} For invalid URL.
193
134
  * @access private
194
135
  */
195
- function validateMountUrl(mountUrl) {
136
+ export function validateMountUrl(mountUrl) {
196
137
  if (typeof mountUrl === "undefined") {
197
138
  return undefined;
198
139
  }
@@ -210,7 +151,7 @@ function validateMountUrl(mountUrl) {
210
151
  * @throws {TypeError} For invalid object.
211
152
  * @access private
212
153
  */
213
- function validateSessionObject(session = Object.create(null), cb = echo) {
154
+ export function validateSessionObject(session = new NullObject(), cb = echo) {
214
155
  if (session === undefined) {
215
156
  return cb(session);
216
157
  }
@@ -228,7 +169,7 @@ function validateSessionObject(session = Object.create(null), cb = echo) {
228
169
  * @throws {TypeError} For invalid type.
229
170
  * @access private
230
171
  */
231
- function validateViews(dirs = []) {
172
+ export function validateViews(dirs = []) {
232
173
  if (!Array.isArray(dirs)) {
233
174
  throw new TypeError("View directories must be an array (views)");
234
175
  }
@@ -237,6 +178,7 @@ function validateViews(dirs = []) {
237
178
  if (typeof dir !== "string") {
238
179
  throw new TypeError(`View directory must be a string, got ${typeof dir} (views[${i++}])`);
239
180
  }
181
+ i++;
240
182
  }
241
183
  return dirs;
242
184
  }
@@ -249,7 +191,7 @@ function validateViews(dirs = []) {
249
191
  * @throws {TypeError} For invalid value.
250
192
  * @access private
251
193
  */
252
- function validateSessionSecret(secret) {
194
+ export function validateSessionSecret(secret) {
253
195
  if (typeof secret === "undefined") {
254
196
  throw ReferenceError("Session secret is missing (session.secret)");
255
197
  }
@@ -267,7 +209,7 @@ function validateSessionSecret(secret) {
267
209
  * @throws {TypeError} For invalid value.
268
210
  * @access private
269
211
  */
270
- function validateSessionTtl(ttl = 3600) {
212
+ export function validateSessionTtl(ttl = 3600) {
271
213
  if (typeof ttl !== "number") {
272
214
  throw new TypeError("Session ttl must be an integer (session.ttl)");
273
215
  }
@@ -282,7 +224,7 @@ function validateSessionTtl(ttl = 3600) {
282
224
  * @throws {TypeError} For invalid value.
283
225
  * @access private
284
226
  */
285
- function validateSessionName(name = "casa-session") {
227
+ export function validateSessionName(name = "casa-session") {
286
228
  if (typeof name !== "string") {
287
229
  throw new TypeError("Session name must be a string (session.name)");
288
230
  }
@@ -297,7 +239,7 @@ function validateSessionName(name = "casa-session") {
297
239
  * @throws {TypeError} For invalid or missing value.
298
240
  * @access private
299
241
  */
300
- function validateSessionSecure(secure) {
242
+ export function validateSessionSecure(secure) {
301
243
  if (secure === undefined) {
302
244
  throw new Error("Session secure flag must be explicitly defined (session.secure)");
303
245
  }
@@ -313,7 +255,7 @@ function validateSessionSecure(secure) {
313
255
  * @returns {Function} Store.
314
256
  * @access private
315
257
  */
316
- function validateSessionStore(store) {
258
+ export function validateSessionStore(store) {
317
259
  if (typeof store === "undefined") {
318
260
  log.warn("Using MemoryStore session storage, which is not suitable for production");
319
261
  return null;
@@ -328,22 +270,12 @@ function validateSessionStore(store) {
328
270
  * @returns {string} Cookie path.
329
271
  * @access private
330
272
  */
331
- function validateSessionCookiePath(cookiePath, defaultPath = "/") {
273
+ export function validateSessionCookiePath(cookiePath, defaultPath = "/") {
332
274
  if (typeof cookiePath === "undefined") {
333
275
  return defaultPath;
334
276
  }
335
277
  return cookiePath;
336
278
  }
337
- /**
338
- * Validates and sanitises sessions cookie "sameSite" flag. One of: true
339
- * (Strict) false (will not set the flag at all) Strict Lax None
340
- *
341
- * @param {any} cookieSameSite Session cookie "sameSite" flag
342
- * @param {any} defaultFlag Default path if none specified
343
- * @returns {boolean} Cookie path
344
- * @throws {TypeError} When invalid arguments are provided
345
- * @access private
346
- */
347
279
  /**
348
280
  * Validates errorVisibility.
349
281
  *
@@ -353,23 +285,28 @@ function validateSessionCookiePath(cookiePath, defaultPath = "/") {
353
285
  * @throws {SyntaxError} For invalid errorVisibility flag.
354
286
  * @access private
355
287
  */
356
- function validateErrorVisibility(errorVisibility = constants_js_1.CONFIG_ERROR_VISIBILITY_ONSUBMIT) {
288
+ export function validateErrorVisibility(errorVisibility = CONFIG_ERROR_VISIBILITY_ONSUBMIT) {
357
289
  if (errorVisibility === undefined) {
358
290
  return undefined;
359
291
  }
360
- if (errorVisibility === constants_js_1.CONFIG_ERROR_VISIBILITY_ALWAYS ||
361
- errorVisibility === constants_js_1.CONFIG_ERROR_VISIBILITY_ONSUBMIT ||
292
+ if (errorVisibility === CONFIG_ERROR_VISIBILITY_ALWAYS ||
293
+ errorVisibility === CONFIG_ERROR_VISIBILITY_ONSUBMIT ||
362
294
  typeof errorVisibility === "function") {
363
295
  return errorVisibility;
364
296
  }
365
297
  throw new TypeError("errorVisibility must be casa constant CONFIG_ERROR_VISIBILITY_ALWAYS | CONFIG_ERROR_VISIBILITY_ONSUBMIT or function");
366
298
  }
367
299
  /**
368
- * @param {boolean | string} cookieSameSite Cookie SameSite value
369
- * @param {boolean | string} defaultFlag Default value
300
+ * Validates and sanitises sessions cookie "sameSite" flag. One of: true
301
+ * (Strict) false (will not set the flag at all) Strict Lax None
302
+ *
303
+ * @param {CookieSameSite} cookieSameSite Session cookie "sameSite" flag
304
+ * @param {CookieSameSite} defaultFlag Default value
370
305
  * @returns {boolean | string} Validated value
306
+ * @throws {TypeError} When invalid arguments are provided
307
+ * @access private
371
308
  */
372
- function validateSessionCookieSameSite(cookieSameSite, defaultFlag) {
309
+ export function validateSessionCookieSameSite(cookieSameSite, defaultFlag) {
373
310
  const validValues = [true, false, "Strict", "Lax", "None"];
374
311
  if (defaultFlag === undefined) {
375
312
  throw new TypeError("validateSessionCookieSameSite() requires an explicit default flag");
@@ -385,7 +322,7 @@ function validateSessionCookieSameSite(cookieSameSite, defaultFlag) {
385
322
  }
386
323
  const validatePageHook = (hook, index) => {
387
324
  try {
388
- (0, utils_js_1.validateHookName)(hook.hook);
325
+ validateHookName(hook.hook);
389
326
  if (typeof hook.middleware !== "function") {
390
327
  throw new TypeError("Hook middleware must be a function");
391
328
  }
@@ -399,7 +336,7 @@ const validatePageHook = (hook, index) => {
399
336
  * @param {PageHook[]} hooks Page hook functions
400
337
  * @returns {PageHook[]} Validated page hooks
401
338
  */
402
- function validatePageHooks(hooks) {
339
+ export function validatePageHooks(hooks) {
403
340
  if (!Array.isArray(hooks)) {
404
341
  throw new TypeError("Hooks must be an array");
405
342
  }
@@ -411,7 +348,7 @@ function validatePageHooks(hooks) {
411
348
  }
412
349
  const validateField = (field, index) => {
413
350
  try {
414
- if (!(field instanceof field_js_1.PageField)) {
351
+ if (!(field instanceof PageField)) {
415
352
  throw new TypeError('Page field must be an instance of PageField (created via the "field()" function)');
416
353
  }
417
354
  }
@@ -424,7 +361,7 @@ const validateField = (field, index) => {
424
361
  * @param {PageField[]} fields Page fields
425
362
  * @returns {PageField[]} Validated fields
426
363
  */
427
- function validateFields(fields) {
364
+ export function validateFields(fields) {
428
365
  if (!Array.isArray(fields)) {
429
366
  throw new TypeError("Page fields must be an array (page[].fields)");
430
367
  }
@@ -436,8 +373,8 @@ function validateFields(fields) {
436
373
  }
437
374
  const validatePage = (page, index) => {
438
375
  try {
439
- (0, utils_js_1.validateWaypoint)(page.waypoint);
440
- (0, utils_js_1.validateView)(page.view);
376
+ validateWaypoint(page.waypoint);
377
+ validateView(page.view);
441
378
  if (page.fields !== undefined) {
442
379
  validateFields(page.fields);
443
380
  }
@@ -457,7 +394,7 @@ const validatePage = (page, index) => {
457
394
  * @param {Page[]} [pages] Pages
458
395
  * @returns {Page[]} Validated pages
459
396
  */
460
- function validatePages(pages = []) {
397
+ export function validatePages(pages = []) {
461
398
  if (!Array.isArray(pages)) {
462
399
  throw new TypeError("Pages must be an array (pages)");
463
400
  }
@@ -471,23 +408,23 @@ function validatePages(pages = []) {
471
408
  * @param {Plan} plan Plan
472
409
  * @returns {Plan} Validated plan
473
410
  */
474
- function validatePlan(plan) {
411
+ export function validatePlan(plan) {
475
412
  if (plan === undefined) {
476
413
  return plan;
477
414
  }
478
- if (!(plan instanceof Plan_js_1.default)) {
415
+ if (!(plan instanceof Plan)) {
479
416
  throw new TypeError("Plan must be an instance the Plan class (plan)");
480
417
  }
481
418
  return plan;
482
419
  }
483
420
  const validateGlobalHook = (hook, index) => {
484
421
  try {
485
- (0, utils_js_1.validateHookName)(hook.hook);
422
+ validateHookName(hook.hook);
486
423
  if (typeof hook.middleware !== "function") {
487
424
  throw new TypeError("Hook middleware must be a function");
488
425
  }
489
426
  if (hook.path !== undefined) {
490
- (0, utils_js_1.validateHookPath)(hook.path);
427
+ validateHookPath(hook.path);
491
428
  }
492
429
  }
493
430
  catch (err) {
@@ -499,7 +436,7 @@ const validateGlobalHook = (hook, index) => {
499
436
  * @param {GlobalHook[]} hooks Global hook functions
500
437
  * @returns {GlobalHook[]} Validated global hooks
501
438
  */
502
- function validateGlobalHooks(hooks) {
439
+ export function validateGlobalHooks(hooks) {
503
440
  if (hooks === undefined) {
504
441
  return [];
505
442
  }
@@ -516,14 +453,14 @@ function validateGlobalHooks(hooks) {
516
453
  * @param {IPlugin[]} plugins Plugins
517
454
  * @returns {IPlugin[]} Validated plugins
518
455
  */
519
- function validatePlugins(plugins) {
456
+ export function validatePlugins(plugins) {
520
457
  return plugins;
521
458
  }
522
459
  /**
523
460
  * @param {ContextEventHandler[]} events Event handlers
524
461
  * @returns {ContextEventHandler[]} Validated event handlers
525
462
  */
526
- function validateEvents(events) {
463
+ export function validateEvents(events) {
527
464
  return events;
528
465
  }
529
466
  /**
@@ -534,7 +471,7 @@ function validateEvents(events) {
534
471
  * @throws {TypeError} When passed a non-function
535
472
  * @access private
536
473
  */
537
- function validateHelmetConfigurator(helmetConfigurator) {
474
+ export function validateHelmetConfigurator(helmetConfigurator) {
538
475
  if (helmetConfigurator !== undefined &&
539
476
  !(helmetConfigurator instanceof Function)) {
540
477
  throw new TypeError("Helmet configurator must be a function");
@@ -548,7 +485,7 @@ function validateHelmetConfigurator(helmetConfigurator) {
548
485
  * @throws {TypeError} If not an integer
549
486
  * @throws {RangeError} If out of bounds
550
487
  */
551
- function validateFormMaxParams(value, defaultValue = 25) {
488
+ export function validateFormMaxParams(value, defaultValue = 25) {
552
489
  // CASA needs to send certain hidden form fields (see `sanitise-fields`
553
490
  // middleware), plus some padding here.
554
491
  const MIN_PARAMS = 10;
@@ -570,17 +507,17 @@ function validateFormMaxParams(value, defaultValue = 25) {
570
507
  * @throws {TypeError} If not an integer
571
508
  * @throws {RangeError} If out of bounds
572
509
  */
573
- function validateFormMaxBytes(value, defaultValue = 1024 * 50) {
510
+ export function validateFormMaxBytes(value, defaultValue = 1024 * 50) {
574
511
  const MIN_BYTES = 1024;
575
512
  if (value === undefined) {
576
513
  return defaultValue;
577
514
  }
578
- const parsedValue = bytes_1.default.parse(value);
515
+ const parsedValue = bytes.parse(value);
579
516
  if (!Number.isInteger(parsedValue)) {
580
517
  throw new TypeError("formMaxParams must be a string or an integer");
581
518
  }
582
519
  if (parsedValue < MIN_BYTES) {
583
- throw new RangeError(`formMaxBytes must be at least ${MIN_BYTES} bytes (${bytes_1.default.format(MIN_BYTES)})`);
520
+ throw new RangeError(`formMaxBytes must be at least ${MIN_BYTES} bytes (${bytes.format(MIN_BYTES)})`);
584
521
  }
585
522
  return parsedValue;
586
523
  }
@@ -589,7 +526,7 @@ function validateFormMaxBytes(value, defaultValue = 1024 * 50) {
589
526
  * @returns {ContextIdGenerator} Validated generator
590
527
  * @throws {TypeError} If not a function
591
528
  */
592
- function validateContextIdGenerator(generator) {
529
+ export function validateContextIdGenerator(generator) {
593
530
  if (generator === undefined) {
594
531
  return contextIdGenerators.uuid();
595
532
  }
@@ -598,23 +535,6 @@ function validateContextIdGenerator(generator) {
598
535
  }
599
536
  return generator;
600
537
  }
601
- /**
602
- * Validates the govuk rebrand feature flag.
603
- *
604
- * @param {boolean} [govukRebrand] Govuk rebrand feature flag
605
- * @returns {boolean | true} Boolean.
606
- * @throws {TypeError} For invalid feagure flag is set.
607
- * @access private
608
- */
609
- function validateGovukRebrand(govukRebrand) {
610
- if (govukRebrand === undefined) {
611
- return false;
612
- }
613
- if (typeof govukRebrand !== "boolean") {
614
- throw new TypeError("govukRebrand must be a boolean");
615
- }
616
- return govukRebrand;
617
- }
618
538
  /**
619
539
  * Ingest, validate, sanitise and manipulate configuration parameters.
620
540
  *
@@ -623,7 +543,7 @@ function validateGovukRebrand(govukRebrand) {
623
543
  * @throws {Error | SyntaxError | TypeError} For invalid config values.
624
544
  * @access private
625
545
  */
626
- function ingest(config = {}) {
546
+ export default function ingest(config = {}) {
627
547
  const parsed = {
628
548
  // I18n configuration
629
549
  i18n: validateI18nObject(config.i18n, (i18n) => ({
@@ -664,10 +584,8 @@ function ingest(config = {}) {
664
584
  formMaxBytes: validateFormMaxBytes(config.formMaxBytes, 1024 * 50),
665
585
  // Context ID generator
666
586
  contextIdGenerator: validateContextIdGenerator(config.contextIdGenerator),
667
- govukRebrand: validateGovukRebrand(config.govukRebrand),
668
587
  };
669
588
  // Freeze to modifications
670
589
  Object.freeze(parsed);
671
590
  return parsed;
672
591
  }
673
- //# sourceMappingURL=configuration-ingestor.js.map
@@ -13,7 +13,7 @@
13
13
  /**
14
14
  * Configure some middleware for use in creating a new CASA app.
15
15
  *
16
- * @memberof module:@dwp/govuk-casa
16
+ * @memberof module:"@dwp/govuk-casa"
17
17
  * @param {ConfigurationOptions} config Configuration options
18
18
  * @returns {ConfigureResult} Result
19
19
  */
@@ -21,3 +21,4 @@ export default function configure(config?: ConfigurationOptions): ConfigureResul
21
21
  export type ConfigurationOptions = import("../casa").ConfigurationOptions;
22
22
  export type ConfigureResult = import("../casa").ConfigureResult;
23
23
  export type Mounter = import("../casa").Mounter;
24
+ //# sourceMappingURL=configure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/lib/configure.js"],"names":[],"mappings":"AAyBA;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;GAMG;AACH,2CAHW,oBAAoB,GAClB,eAAe,CAgL3B;mCAnMY,OAAO,SAAS,EAAE,oBAAoB;8BAKtC,OAAO,SAAS,EAAE,eAAe;sBAKjC,OAAO,SAAS,EAAE,OAAO"}