@defra/forms-engine-plugin 0.1.26 → 0.1.28

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 (95) hide show
  1. package/.public/assets/images/govuk-crest.svg +1 -1
  2. package/.public/assets/rebrand/images/favicon.ico +0 -0
  3. package/.public/assets/rebrand/images/favicon.svg +1 -0
  4. package/.public/assets/rebrand/images/govuk-crest.svg +1 -0
  5. package/.public/assets/rebrand/images/govuk-icon-180.png +0 -0
  6. package/.public/assets/rebrand/images/govuk-icon-192.png +0 -0
  7. package/.public/assets/rebrand/images/govuk-icon-512.png +0 -0
  8. package/.public/assets/rebrand/images/govuk-icon-mask.svg +1 -0
  9. package/.public/assets/rebrand/images/govuk-opengraph-image.png +0 -0
  10. package/.public/assets/rebrand/manifest.json +39 -0
  11. package/.public/assets-manifest.json +9 -0
  12. package/.public/javascripts/application.min.js +1 -1
  13. package/.public/javascripts/application.min.js.LICENSE.txt +5 -1
  14. package/.public/javascripts/application.min.js.map +1 -1
  15. package/.public/javascripts/shared.min.js +1 -1
  16. package/.public/javascripts/shared.min.js.LICENSE.txt +5 -1
  17. package/.public/javascripts/shared.min.js.map +1 -1
  18. package/.public/stylesheets/application.min.css +2 -2
  19. package/.public/stylesheets/application.min.css.map +1 -1
  20. package/.server/index.js +6 -2
  21. package/.server/index.js.map +1 -1
  22. package/.server/server/common/helpers/logging/request-tracing.js +1 -1
  23. package/.server/server/common/helpers/logging/request-tracing.js.map +1 -1
  24. package/.server/server/common/helpers/redis-client.js +5 -3
  25. package/.server/server/common/helpers/redis-client.js.map +1 -1
  26. package/.server/server/constants.d.ts +0 -1
  27. package/.server/server/constants.js +0 -1
  28. package/.server/server/constants.js.map +1 -1
  29. package/.server/server/index.js +3 -1
  30. package/.server/server/index.js.map +1 -1
  31. package/.server/server/plugins/engine/components/DatePartsField.d.ts +1 -6
  32. package/.server/server/plugins/engine/components/DatePartsField.js +2 -1
  33. package/.server/server/plugins/engine/components/DatePartsField.js.map +1 -1
  34. package/.server/server/plugins/engine/components/MonthYearField.d.ts +1 -5
  35. package/.server/server/plugins/engine/components/MonthYearField.js +3 -2
  36. package/.server/server/plugins/engine/components/MonthYearField.js.map +1 -1
  37. package/.server/server/plugins/engine/components/YesNoField.js +2 -1
  38. package/.server/server/plugins/engine/components/YesNoField.js.map +1 -1
  39. package/.server/server/plugins/engine/components/types.d.ts +9 -0
  40. package/.server/server/plugins/engine/components/types.js.map +1 -1
  41. package/.server/server/plugins/engine/date-helper.d.ts +12 -0
  42. package/.server/server/plugins/engine/date-helper.js +21 -0
  43. package/.server/server/plugins/engine/date-helper.js.map +1 -0
  44. package/.server/server/plugins/engine/helpers.js +4 -3
  45. package/.server/server/plugins/engine/helpers.js.map +1 -1
  46. package/.server/server/plugins/engine/index.js +3 -2
  47. package/.server/server/plugins/engine/index.js.map +1 -1
  48. package/.server/server/plugins/engine/models/FormModel.d.ts +13 -6
  49. package/.server/server/plugins/engine/models/FormModel.js +51 -18
  50. package/.server/server/plugins/engine/models/FormModel.js.map +1 -1
  51. package/.server/server/plugins/engine/outputFormatters/machine/v2.js.map +1 -1
  52. package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js +3 -2
  53. package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js.map +1 -1
  54. package/.server/server/plugins/engine/plugin.js +6 -5
  55. package/.server/server/plugins/engine/plugin.js.map +1 -1
  56. package/.server/server/plugins/engine/services/notifyService.js +3 -1
  57. package/.server/server/plugins/engine/services/notifyService.js.map +1 -1
  58. package/.server/server/plugins/engine/views/components/tag-env/template.njk +5 -24
  59. package/.server/server/plugins/engine/views/components/tag-env/template.test.js +19 -53
  60. package/.server/server/plugins/engine/views/components/tag-env/template.test.js.map +1 -1
  61. package/.server/server/plugins/errorPages.js +1 -1
  62. package/.server/server/plugins/errorPages.js.map +1 -1
  63. package/.server/server/plugins/nunjucks/context.js +1 -1
  64. package/.server/server/plugins/nunjucks/context.js.map +1 -1
  65. package/.server/server/plugins/nunjucks/environment.d.ts +1 -0
  66. package/.server/server/plugins/nunjucks/environment.js +4 -0
  67. package/.server/server/plugins/nunjucks/environment.js.map +1 -1
  68. package/package.json +18 -18
  69. package/src/index.ts +7 -2
  70. package/src/server/common/helpers/logging/request-tracing.js +1 -1
  71. package/src/server/common/helpers/redis-client.js +5 -3
  72. package/src/server/constants.js +0 -1
  73. package/src/server/index.ts +5 -2
  74. package/src/server/plugins/engine/components/DatePartsField.test.ts +17 -0
  75. package/src/server/plugins/engine/components/DatePartsField.ts +7 -8
  76. package/src/server/plugins/engine/components/MonthYearField.test.ts +15 -0
  77. package/src/server/plugins/engine/components/MonthYearField.ts +12 -8
  78. package/src/server/plugins/engine/components/YesNoField.ts +16 -2
  79. package/src/server/plugins/engine/components/types.ts +11 -0
  80. package/src/server/plugins/engine/date-helper.test.ts +47 -0
  81. package/src/server/plugins/engine/date-helper.ts +32 -0
  82. package/src/server/plugins/engine/helpers.ts +9 -2
  83. package/src/server/plugins/engine/index.ts +4 -2
  84. package/src/server/plugins/engine/models/FormModel.test.ts +163 -1
  85. package/src/server/plugins/engine/models/FormModel.ts +90 -23
  86. package/src/server/plugins/engine/outputFormatters/machine/v2.ts +4 -2
  87. package/src/server/plugins/engine/pageControllers/FileUploadPageController.test.ts +2 -1
  88. package/src/server/plugins/engine/pageControllers/FileUploadPageController.ts +6 -2
  89. package/src/server/plugins/engine/plugin.ts +11 -7
  90. package/src/server/plugins/engine/services/notifyService.ts +6 -2
  91. package/src/server/plugins/engine/views/components/tag-env/template.njk +5 -24
  92. package/src/server/plugins/engine/views/components/tag-env/template.test.js +18 -56
  93. package/src/server/plugins/errorPages.ts +5 -1
  94. package/src/server/plugins/nunjucks/context.js +3 -1
  95. package/src/server/plugins/nunjucks/environment.js +6 -0
package/.server/index.js CHANGED
@@ -1,10 +1,12 @@
1
+ import { getErrorMessage } from '@defra/forms-model';
1
2
  import { config } from "./config/index.js";
2
3
  import { createLogger } from "./server/common/helpers/logging/logger.js";
3
4
  import { createServer } from "./server/index.js";
4
5
  const logger = createLogger();
5
6
  process.on('unhandledRejection', error => {
7
+ const err = getErrorMessage(error);
6
8
  logger.info('Unhandled rejection');
7
- logger.error(error);
9
+ logger.error(err, `[unhandledRejection] Unhandled promise rejection: ${err}`);
8
10
  throw error;
9
11
  });
10
12
 
@@ -19,7 +21,9 @@ async function startServer() {
19
21
  server.logger.info(`Access your frontend on http://localhost:${config.get('port')}`);
20
22
  }
21
23
  startServer().catch(error => {
24
+ const err = getErrorMessage(error);
22
25
  logger.info('Server failed to start :(');
23
- logger.error(error);
26
+ logger.error(err, `[serverStartup] Server failed to start: ${err}`);
27
+ throw error;
24
28
  });
25
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["config","createLogger","createServer","logger","process","on","error","info","startServer","server","start","send","get","catch"],"sources":["../src/index.ts"],"sourcesContent":["import { config } from '~/src/config/index.js'\nimport { createLogger } from '~/src/server/common/helpers/logging/logger.js'\nimport { createServer } from '~/src/server/index.js'\n\nconst logger = createLogger()\n\nprocess.on('unhandledRejection', (error) => {\n logger.info('Unhandled rejection')\n logger.error(error)\n throw error\n})\n\n/**\n * Main entrypoint to the application.\n */\nasync function startServer() {\n const server = await createServer()\n await server.start()\n\n process.send?.('online')\n\n server.logger.info('Server started successfully')\n server.logger.info(\n `Access your frontend on http://localhost:${config.get('port')}`\n )\n}\n\nstartServer().catch((error: unknown) => {\n logger.info('Server failed to start :(')\n logger.error(error)\n})\n"],"mappings":"AAAA,SAASA,MAAM;AACf,SAASC,YAAY;AACrB,SAASC,YAAY;AAErB,MAAMC,MAAM,GAAGF,YAAY,CAAC,CAAC;AAE7BG,OAAO,CAACC,EAAE,CAAC,oBAAoB,EAAGC,KAAK,IAAK;EAC1CH,MAAM,CAACI,IAAI,CAAC,qBAAqB,CAAC;EAClCJ,MAAM,CAACG,KAAK,CAACA,KAAK,CAAC;EACnB,MAAMA,KAAK;AACb,CAAC,CAAC;;AAEF;AACA;AACA;AACA,eAAeE,WAAWA,CAAA,EAAG;EAC3B,MAAMC,MAAM,GAAG,MAAMP,YAAY,CAAC,CAAC;EACnC,MAAMO,MAAM,CAACC,KAAK,CAAC,CAAC;EAEpBN,OAAO,CAACO,IAAI,GAAG,QAAQ,CAAC;EAExBF,MAAM,CAACN,MAAM,CAACI,IAAI,CAAC,6BAA6B,CAAC;EACjDE,MAAM,CAACN,MAAM,CAACI,IAAI,CAChB,4CAA4CP,MAAM,CAACY,GAAG,CAAC,MAAM,CAAC,EAChE,CAAC;AACH;AAEAJ,WAAW,CAAC,CAAC,CAACK,KAAK,CAAEP,KAAc,IAAK;EACtCH,MAAM,CAACI,IAAI,CAAC,2BAA2B,CAAC;EACxCJ,MAAM,CAACG,KAAK,CAACA,KAAK,CAAC;AACrB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["getErrorMessage","config","createLogger","createServer","logger","process","on","error","err","info","startServer","server","start","send","get","catch"],"sources":["../src/index.ts"],"sourcesContent":["import { getErrorMessage } from '@defra/forms-model'\n\nimport { config } from '~/src/config/index.js'\nimport { createLogger } from '~/src/server/common/helpers/logging/logger.js'\nimport { createServer } from '~/src/server/index.js'\n\nconst logger = createLogger()\n\nprocess.on('unhandledRejection', (error) => {\n const err = getErrorMessage(error)\n logger.info('Unhandled rejection')\n logger.error(err, `[unhandledRejection] Unhandled promise rejection: ${err}`)\n throw error\n})\n\n/**\n * Main entrypoint to the application.\n */\nasync function startServer() {\n const server = await createServer()\n await server.start()\n\n process.send?.('online')\n\n server.logger.info('Server started successfully')\n server.logger.info(\n `Access your frontend on http://localhost:${config.get('port')}`\n )\n}\n\nstartServer().catch((error: unknown) => {\n const err = getErrorMessage(error)\n logger.info('Server failed to start :(')\n logger.error(err, `[serverStartup] Server failed to start: ${err}`)\n throw error\n})\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AAEpD,SAASC,MAAM;AACf,SAASC,YAAY;AACrB,SAASC,YAAY;AAErB,MAAMC,MAAM,GAAGF,YAAY,CAAC,CAAC;AAE7BG,OAAO,CAACC,EAAE,CAAC,oBAAoB,EAAGC,KAAK,IAAK;EAC1C,MAAMC,GAAG,GAAGR,eAAe,CAACO,KAAK,CAAC;EAClCH,MAAM,CAACK,IAAI,CAAC,qBAAqB,CAAC;EAClCL,MAAM,CAACG,KAAK,CAACC,GAAG,EAAE,qDAAqDA,GAAG,EAAE,CAAC;EAC7E,MAAMD,KAAK;AACb,CAAC,CAAC;;AAEF;AACA;AACA;AACA,eAAeG,WAAWA,CAAA,EAAG;EAC3B,MAAMC,MAAM,GAAG,MAAMR,YAAY,CAAC,CAAC;EACnC,MAAMQ,MAAM,CAACC,KAAK,CAAC,CAAC;EAEpBP,OAAO,CAACQ,IAAI,GAAG,QAAQ,CAAC;EAExBF,MAAM,CAACP,MAAM,CAACK,IAAI,CAAC,6BAA6B,CAAC;EACjDE,MAAM,CAACP,MAAM,CAACK,IAAI,CAChB,4CAA4CR,MAAM,CAACa,GAAG,CAAC,MAAM,CAAC,EAChE,CAAC;AACH;AAEAJ,WAAW,CAAC,CAAC,CAACK,KAAK,CAAER,KAAc,IAAK;EACtC,MAAMC,GAAG,GAAGR,eAAe,CAACO,KAAK,CAAC;EAClCH,MAAM,CAACK,IAAI,CAAC,2BAA2B,CAAC;EACxCL,MAAM,CAACG,KAAK,CAACC,GAAG,EAAE,2CAA2CA,GAAG,EAAE,CAAC;EACnE,MAAMD,KAAK;AACb,CAAC,CAAC","ignoreList":[]}
@@ -6,7 +6,7 @@ import { config } from "../../../../config/index.js";
6
6
  export const requestTracing = {
7
7
  plugin: tracing,
8
8
  options: {
9
- tracingHeader: config.get('tracing').header
9
+ tracingHeader: config.get('tracing.header')
10
10
  }
11
11
  };
12
12
  //# sourceMappingURL=request-tracing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"request-tracing.js","names":["tracing","config","requestTracing","plugin","options","tracingHeader","get","header"],"sources":["../../../../../src/server/common/helpers/logging/request-tracing.js"],"sourcesContent":["import { tracing } from '@defra/hapi-tracing'\n\nimport { config } from '~/src/config/index.js'\n\n// Explicitly declare the expected type\n\nexport const requestTracing = {\n plugin: tracing,\n options: { tracingHeader: config.get('tracing').header }\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,qBAAqB;AAE7C,SAASC,MAAM;;AAEf;;AAEA,OAAO,MAAMC,cAAc,GAAG;EAC5BC,MAAM,EAAEH,OAAO;EACfI,OAAO,EAAE;IAAEC,aAAa,EAAEJ,MAAM,CAACK,GAAG,CAAC,SAAS,CAAC,CAACC;EAAO;AACzD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"request-tracing.js","names":["tracing","config","requestTracing","plugin","options","tracingHeader","get"],"sources":["../../../../../src/server/common/helpers/logging/request-tracing.js"],"sourcesContent":["import { tracing } from '@defra/hapi-tracing'\n\nimport { config } from '~/src/config/index.js'\n\n// Explicitly declare the expected type\n\nexport const requestTracing = {\n plugin: tracing,\n options: { tracingHeader: config.get('tracing.header') }\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,qBAAqB;AAE7C,SAASC,MAAM;;AAEf;;AAEA,OAAO,MAAMC,cAAc,GAAG;EAC5BC,MAAM,EAAEH,OAAO;EACfI,OAAO,EAAE;IAAEC,aAAa,EAAEJ,MAAM,CAACK,GAAG,CAAC,gBAAgB;EAAE;AACzD,CAAC","ignoreList":[]}
@@ -1,3 +1,4 @@
1
+ import { getErrorMessage } from '@defra/forms-model';
1
2
  import { Cluster, Redis } from 'ioredis';
2
3
  import { config } from "../../../config/index.js";
3
4
  import { createLogger } from "./logging/logger.js";
@@ -42,13 +43,14 @@ export function buildRedisClient() {
42
43
  });
43
44
  }
44
45
  redisClient.on('connect', () => {
45
- logger.info('Connected to Redis server');
46
+ logger.info('[redisConnected] Connected to Redis server');
46
47
  });
47
48
  redisClient.on('close', () => {
48
- logger.warn('Redis connection closed attempting reconnect with default behavior');
49
+ logger.warn('[redisDisconnected] Redis connection closed attempting reconnect with default behavior');
49
50
  });
50
51
  redisClient.on('error', error => {
51
- logger.error(error, `Redis connection error ${error}.`);
52
+ const err = getErrorMessage(error);
53
+ logger.error(err, `[redisConnectionError] Redis connection error - ${err}`);
52
54
  });
53
55
  return redisClient;
54
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"redis-client.js","names":["Cluster","Redis","config","createLogger","buildRedisClient","logger","port","db","redisConfig","get","keyPrefix","host","redisClient","info","slotsRefreshTimeout","dnsLookup","address","callback","redisOptions","username","password","tls","on","warn","error"],"sources":["../../../../src/server/common/helpers/redis-client.js"],"sourcesContent":["import { Cluster, Redis } from 'ioredis'\n\nimport { config } from '~/src/config/index.js'\nimport { createLogger } from '~/src/server/common/helpers/logging/logger.js'\n\n/**\n * Setup Redis and provide a redis client\n *\n * Local development - 1 Redis instance\n * Out in the wild - Elasticache / Redis Cluster with username and password\n */\nexport function buildRedisClient() {\n const logger = createLogger()\n\n const port = 6379\n const db = 0\n const redisConfig = config.get('redis')\n const keyPrefix = redisConfig.keyPrefix\n const host = redisConfig.host\n let redisClient\n\n if (!config.get('isProduction')) {\n logger.info('Connecting to Redis using single instance')\n\n redisClient = new Redis({\n port,\n host,\n db,\n keyPrefix\n })\n } else {\n logger.info('Connecting to Redis using cluster')\n\n redisClient = new Cluster(\n [\n {\n host,\n port\n }\n ],\n {\n keyPrefix,\n slotsRefreshTimeout: 2000,\n dnsLookup: (address, callback) => callback(null, address),\n redisOptions: {\n username: redisConfig.username,\n password: redisConfig.password,\n db,\n tls: {}\n }\n }\n )\n }\n\n redisClient.on('connect', () => {\n logger.info('Connected to Redis server')\n })\n\n redisClient.on('close', () => {\n logger.warn(\n 'Redis connection closed attempting reconnect with default behavior'\n )\n })\n\n redisClient.on('error', (error) => {\n logger.error(error, `Redis connection error ${error}.`)\n })\n\n return redisClient\n}\n"],"mappings":"AAAA,SAASA,OAAO,EAAEC,KAAK,QAAQ,SAAS;AAExC,SAASC,MAAM;AACf,SAASC,YAAY;;AA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AEFX,WAAW,CAACU,EAAE,CAAC,OAAO,EAAGE,KAAK,IAAK;IACjCnB,MAAM,CAACmB,KAAK,CAACA,KAAK,EAAE,0BAA0BA,KAAK,GAAG,CAAC;EACzD,CAAC,CAAC;EAEF,OAAOZ,WAAW;AACpB","ignoreList":[]}
1
+ {"version":3,"file":"redis-client.js","names":["getErrorMessage","Cluster","Redis","config","createLogger","buildRedisClient","logger","port","db","redisConfig","get","keyPrefix","host","redisClient","info","slotsRefreshTimeout","dnsLookup","address","callback","redisOptions","username","password","tls","on","warn","error","err"],"sources":["../../../../src/server/common/helpers/redis-client.js"],"sourcesContent":["import { getErrorMessage } from '@defra/forms-model'\nimport { Cluster, Redis } from 'ioredis'\n\nimport { config } from '~/src/config/index.js'\nimport { createLogger } from '~/src/server/common/helpers/logging/logger.js'\n\n/**\n * Setup Redis and provide a redis client\n *\n * Local development - 1 Redis instance\n * Out in the wild - Elasticache / Redis Cluster with username and password\n */\nexport function buildRedisClient() {\n const logger = createLogger()\n\n const port = 6379\n const db = 0\n const redisConfig = config.get('redis')\n const keyPrefix = redisConfig.keyPrefix\n const host = redisConfig.host\n let redisClient\n\n if (!config.get('isProduction')) {\n logger.info('Connecting to Redis using single instance')\n\n redisClient = new Redis({\n port,\n host,\n db,\n keyPrefix\n })\n } else {\n logger.info('Connecting to Redis using cluster')\n\n redisClient = new Cluster(\n [\n {\n host,\n port\n }\n ],\n {\n keyPrefix,\n slotsRefreshTimeout: 2000,\n dnsLookup: (address, callback) => callback(null, address),\n redisOptions: {\n username: redisConfig.username,\n password: redisConfig.password,\n db,\n tls: {}\n }\n }\n )\n }\n\n redisClient.on('connect', () => {\n logger.info('[redisConnected] Connected to Redis server')\n })\n\n redisClient.on('close', () => {\n logger.warn(\n '[redisDisconnected] Redis connection closed attempting reconnect with default behavior'\n )\n })\n\n redisClient.on('error', (error) => {\n const err = getErrorMessage(error)\n logger.error(err, `[redisConnectionError] Redis connection error - ${err}`)\n })\n\n return redisClient\n}\n"],"m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C,CAAC;EAEFD,WAAW,CAACU,EAAE,CAAC,OAAO,EAAE,MAAM;IAC5BjB,MAAM,CAACkB,IAAI,CACT,wFACF,CAAC;EACH,CAAC,CAAC;EAEFX,WAAW,CAACU,EAAE,CAAC,OAAO,EAAGE,KAAK,IAAK;IACjC,MAAMC,GAAG,GAAG1B,eAAe,CAACyB,KAAK,CAAC;IAClCnB,MAAM,CAACmB,KAAK,CAACC,GAAG,EAAE,mDAAmDA,GAAG,EAAE,CAAC;EAC7E,CAAC,CAAC;EAEF,OAAOb,WAAW;AACpB","ignoreList":[]}
@@ -1,3 +1,2 @@
1
1
  export const PREVIEW_PATH_PREFIX: "/preview";
2
- export const ERROR_PREVIEW_PATH_PREFIX: "/error-preview";
3
2
  export const FORM_PREFIX: "";
@@ -1,4 +1,3 @@
1
1
  export const PREVIEW_PATH_PREFIX = '/preview';
2
- export const ERROR_PREVIEW_PATH_PREFIX = '/error-preview';
3
2
  export const FORM_PREFIX = '';
4
3
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":["PREVIEW_PATH_PREFIX","ERROR_PREVIEW_PATH_PREFIX","FORM_PREFIX"],"sources":["../../src/server/constants.js"],"sourcesContent":["export const PREVIEW_PATH_PREFIX = '/preview'\nexport const ERROR_PREVIEW_PATH_PREFIX = '/error-preview'\nexport const FORM_PREFIX = ''\n"],"mappings":"AAAA,OAAO,MAAMA,mBAAmB,GAAG,UAAU;AAC7C,OAAO,MAAMC,yBAAyB,GAAG,gBAAgB;AACzD,OAAO,MAAMC,WAAW,GAAG,EAAE","ignoreList":[]}
1
+ {"version":3,"file":"constants.js","names":["PREVIEW_PATH_PREFIX","FORM_PREFIX"],"sources":["../../src/server/constants.js"],"sourcesContent":["export const PREVIEW_PATH_PREFIX = '/preview'\nexport const FORM_PREFIX = ''\n"],"mappings":"AAAA,OAAO,MAAMA,mBAAmB,GAAG,UAAU;AAC7C,OAAO,MAAMC,WAAW,GAAG,EAAE","ignoreList":[]}
@@ -100,7 +100,9 @@ export async function createServer(routeConfig) {
100
100
  }
101
101
  });
102
102
  await server.register(pluginErrorPages);
103
- await server.register(blipp);
103
+ if (config.get('cdpEnvironment') === 'local') {
104
+ await server.register(blipp);
105
+ }
104
106
  await server.register(requestTracing);
105
107
  return server;
106
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Engine","CatboxMemory","CatboxRedis","hapi","inert","Scooter","Wreck","blipp","ProxyAgent","config","requestLogger","requestTracing","buildRedisClient","configureCrumbPlugin","configureEnginePlugin","pluginErrorPages","plugin","pluginViews","pluginPulse","pluginSession","publicRoutes","prepareSecureContext","proxyAgent","agents","https","http","httpsAllowUnauthorized","serverOptions","debug","request","get","port","router","stripTrailingSlash","routes","validate","options","abortEarly","security","hsts","maxAge","includeSubDomains","preload","xss","noSniff","xframe","cache","name","engine","client","createServer","routeConfig","server","register","pluginCrumb","pluginEngine","ext","h","response","continue","header","path","startsWith","route"],"sources":["../../src/server/index.ts"],"sourcesContent":["import { Engine as CatboxMemory } from '@hapi/catbox-memory'\nimport { Engine as CatboxRedis } from '@hapi/catbox-redis'\nimport hapi, {\n type Request,\n type ResponseToolkit,\n type ServerOptions\n} from '@hapi/hapi'\nimport inert from '@hapi/inert'\nimport Scooter from '@hapi/scooter'\nimport Wreck from '@hapi/wreck'\nimport blipp from 'blipp'\nimport { ProxyAgent } from 'proxy-agent'\n\nimport { config } from '~/src/config/index.js'\nimport { requestLogger } from '~/src/server/common/helpers/logging/request-logger.js'\nimport { requestTracing } from '~/src/server/common/helpers/logging/request-tracing.js'\nimport { buildRedisClient } from '~/src/server/common/helpers/redis-client.js'\nimport { configureCrumbPlugin } from '~/src/server/plugins/crumb.js'\nimport { configureEnginePlugin } from '~/src/server/plugins/engine/configureEnginePlugin.js'\nimport pluginErrorPages from '~/src/server/plugins/errorPages.js'\nimport { plugin as pluginViews } from '~/src/server/plugins/nunjucks/index.js'\nimport pluginPulse from '~/src/server/plugins/pulse.js'\nimport pluginSession from '~/src/server/plugins/session.js'\nimport { publicRoutes } from '~/src/server/routes/index.js'\nimport { prepareSecureContext } from '~/src/server/secure-context.js'\nimport { type RouteConfig } from '~/src/server/types.js'\n\nconst proxyAgent = new ProxyAgent()\n\nWreck.agents = {\n https: proxyAgent,\n http: proxyAgent,\n httpsAllowUnauthorized: proxyAgent\n}\n\nconst serverOptions = (): ServerOptions => {\n const serverOptions: ServerOptions = {\n debug: { request: [`${config.get('isDevelopment')}`] },\n port: config.get('port'),\n router: {\n stripTrailingSlash: true\n },\n routes: {\n validate: {\n options: {\n abortEarly: false\n }\n },\n security: {\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n preload: false\n },\n xss: 'enabled',\n noSniff: true,\n xframe: true\n }\n },\n cache: [\n {\n name: 'session',\n engine: config.get('isTest')\n ? new CatboxMemory()\n : new CatboxRedis({\n client: buildRedisClient()\n })\n }\n ]\n }\n\n return serverOptions\n}\n\nexport async function createServer(routeConfig?: RouteConfig) {\n const server = hapi.server(serverOptions())\n\n await server.register(requestLogger)\n\n if (config.get('isProduction')) {\n prepareSecureContext(server)\n }\n\n const pluginCrumb = configureCrumbPlugin(routeConfig)\n const pluginEngine = await configureEnginePlugin(routeConfig)\n\n await server.register(pluginSession)\n await server.register(pluginPulse)\n await server.register(inert)\n await server.register(Scooter)\n await server.register(pluginCrumb)\n\n await server.register(pluginEngine)\n\n server.ext('onPreResponse', (request: Request, h: ResponseToolkit) => {\n const { response } = request\n\n if ('isBoom' in response) {\n return h.continue\n }\n\n // Prevent search engine indexing\n response.header('x-robots-tag', 'noindex, nofollow')\n\n // Disable cache to ensure back/foward navigation updates progress\n if (\n !request.path.startsWith('/javascripts/') &&\n !request.path.startsWith('/stylesheets/') &&\n !request.path.startsWith('/assets/')\n ) {\n response.header('cache-control', 'no-store')\n }\n\n return h.continue\n })\n\n await server.register(pluginViews)\n\n await server.register({\n plugin: {\n name: 'router',\n register: (server) => {\n server.route(publicRoutes)\n }\n }\n })\n\n await server.register(pluginErrorPages)\n await server.register(blipp)\n await server.register(requestTracing)\n\n return server\n}\n"],"mappings":"AAAA,SAASA,MAAM,IAAIC,YAAY,QAAQ,qBAAqB;AAC5D,SAASD,MAAM,IAAIE,WAAW,QAAQ,oBAAoB;AAC1D,OAAOC,IAAI,MAIJ,YAAY;AACnB,OAAOC,KAAK,MAAM,aAAa;AAC/B,OAAOC,OAAO,MAAM,eAAe;AACnC,OAAOC,KAAK,MAAM,aAAa;AAC/B,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,aAAa;AAExC,SAASC,MAAM;AACf,SAASC,aAAa;AACtB,SAASC,cAAc;AACvB,SAASC,gBAAgB;AACzB,SAASC,oBAAoB;AAC7B,SAASC,qBAAqB;AAC9B,OAAOC,gBAAgB;AACvB,SAASC,MAAM,IAAIC,WAAW;AAC9B,OAAOC,WAAW;AAClB,OAAOC,aAAa;AACpB,SAASC,YAAY;AACrB,SAASC,oBAAoB;AAG7B,MAAMC,UAAU,GAAG,IAAId,UAAU,CAAC,CAAC;AAEnCF,KAAK,CAACiB,MAAM,GAAG;EACbC,KAAK,EAAEF,UAAU;EACjBG,IAAI,EAAEH,UAAU;EAChBI,sBAAsB,EAAEJ;AAC1B,CAAC;AAED,MAAMK,aAAa,GAAGA,CAAA,KAAqB;EACzC,MAAMA,aAA4B,GAAG;IACnCC,KAAK,EAAE;MAAEC,OAAO,EAAE,CAAC,GAAGpB,MAAM,CAACqB,GAAG,CAAC,eAAe,CAAC,EAAE;IAAE,CAAC;IACtDC,IAAI,EAAEtB,MAAM,CAACqB,GAAG,CAAC,MAAM,CAAC;IACxBE,MAAM,EAAE;MACNC,kBAAkB,EAAE;IACtB,CAAC;IACDC,MAAM,EAAE;MACNC,QAAQ,EAAE;QACRC,OAAO,EAAE;UACPC,UAAU,EAAE;QACd;MACF,CAAC;MACDC,QAAQ,EAAE;QACRC,IAAI,EAAE;UACJC,MAAM,EAAE,QAAQ;UAChBC,iBAAiB,EAA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,IAAI,QAAQ,IAAI6B,QAAQ,EAAE;MACxB,OAAOD,CAAC,CAACE,QAAQ;IACnB;;IAEA;IACAD,QAAQ,CAACE,MAAM,CAAC,cAAc,EAAE,mBAAmB,CAAC;;IAEpD;IACA,IACE,CAAC/B,OAAO,CAACgC,IAAI,CAACC,UAAU,CAAC,eAAe,CAAC,IACzC,CAACjC,OAAO,CAACgC,IAAI,CAACC,UAAU,CAAC,eAAe,CAAC,IACzC,CAACjC,OAAO,CAACgC,IAAI,CAACC,UAAU,CAAC,UAAU,CAAC,EACpC;MACAJ,QAAQ,CAACE,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC;IAC9C;IAEA,OAAOH,CAAC,CAACE,QAAQ;EACnB,CAAC,CAAC;EAEF,MAAMP,MAAM,CAACC,QAAQ,CAACpC,WAAW,CAAC;EAElC,MAAMmC,MAAM,CAACC,QAAQ,CAAC;IACpBrC,MAAM,EAAE;MACN+B,IAAI,EAAE,QAAQ;MACdM,QAAQ,EAAGD,MAAM,IAAK;QACpBA,MAAM,CAACW,KAAK,CAAC3C,YAAY,CAAC;MAC5B;IACF;EACF,CAAC,CAAC;EAEF,MAAMgC,MAAM,CAACC,QAAQ,CAACtC,gBAAgB,CAAC;EACvC,MAAMqC,MAAM,CAACC,QAAQ,CAAC9C,KAAK,CAAC;EAC5B,MAAM6C,MAAM,CAACC,QAAQ,CAAC1C,cAAc,CAAC;EAErC,OAAOyC,MAAM;AACf","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Engine","CatboxMemory","CatboxRedis","hapi","inert","Scooter","Wreck","blipp","ProxyAgent","config","requestLogger","requestTracing","buildRedisClient","configureCrumbPlugin","configureEnginePlugin","pluginErrorPages","plugin","pluginViews","pluginPulse","pluginSession","publicRoutes","prepareSecureContext","proxyAgent","agents","https","http","httpsAllowUnauthorized","serverOptions","debug","request","get","port","router","stripTrailingSlash","routes","validate","options","abortEarly","security","hsts","maxAge","includeSubDomains","preload","xss","noSniff","xframe","cache","name","engine","client","createServer","routeConfig","server","register","pluginCrumb","pluginEngine","ext","h","response","continue","header","path","startsWith","route"],"sources":["../../src/server/index.ts"],"sourcesContent":["import { Engine as CatboxMemory } from '@hapi/catbox-memory'\nimport { Engine as CatboxRedis } from '@hapi/catbox-redis'\nimport hapi, {\n type Request,\n type ResponseToolkit,\n type ServerOptions\n} from '@hapi/hapi'\nimport inert from '@hapi/inert'\nimport Scooter from '@hapi/scooter'\nimport Wreck from '@hapi/wreck'\nimport blipp from 'blipp'\nimport { ProxyAgent } from 'proxy-agent'\n\nimport { config } from '~/src/config/index.js'\nimport { requestLogger } from '~/src/server/common/helpers/logging/request-logger.js'\nimport { requestTracing } from '~/src/server/common/helpers/logging/request-tracing.js'\nimport { buildRedisClient } from '~/src/server/common/helpers/redis-client.js'\nimport { configureCrumbPlugin } from '~/src/server/plugins/crumb.js'\nimport { configureEnginePlugin } from '~/src/server/plugins/engine/configureEnginePlugin.js'\nimport pluginErrorPages from '~/src/server/plugins/errorPages.js'\nimport { plugin as pluginViews } from '~/src/server/plugins/nunjucks/index.js'\nimport pluginPulse from '~/src/server/plugins/pulse.js'\nimport pluginSession from '~/src/server/plugins/session.js'\nimport { publicRoutes } from '~/src/server/routes/index.js'\nimport { prepareSecureContext } from '~/src/server/secure-context.js'\nimport { type RouteConfig } from '~/src/server/types.js'\n\nconst proxyAgent = new ProxyAgent()\n\nWreck.agents = {\n https: proxyAgent,\n http: proxyAgent,\n httpsAllowUnauthorized: proxyAgent\n}\n\nconst serverOptions = (): ServerOptions => {\n const serverOptions: ServerOptions = {\n debug: { request: [`${config.get('isDevelopment')}`] },\n port: config.get('port'),\n router: {\n stripTrailingSlash: true\n },\n routes: {\n validate: {\n options: {\n abortEarly: false\n }\n },\n security: {\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n preload: false\n },\n xss: 'enabled',\n noSniff: true,\n xframe: true\n }\n },\n cache: [\n {\n name: 'session',\n engine: config.get('isTest')\n ? new CatboxMemory()\n : new CatboxRedis({\n client: buildRedisClient()\n })\n }\n ]\n }\n\n return serverOptions\n}\n\nexport async function createServer(routeConfig?: RouteConfig) {\n const server = hapi.server(serverOptions())\n\n await server.register(requestLogger)\n\n if (config.get('isProduction')) {\n prepareSecureContext(server)\n }\n\n const pluginCrumb = configureCrumbPlugin(routeConfig)\n const pluginEngine = await configureEnginePlugin(routeConfig)\n\n await server.register(pluginSession)\n await server.register(pluginPulse)\n await server.register(inert)\n await server.register(Scooter)\n await server.register(pluginCrumb)\n await server.register(pluginEngine)\n\n server.ext('onPreResponse', (request: Request, h: ResponseToolkit) => {\n const { response } = request\n\n if ('isBoom' in response) {\n return h.continue\n }\n\n // Prevent search engine indexing\n response.header('x-robots-tag', 'noindex, nofollow')\n\n // Disable cache to ensure back/foward navigation updates progress\n if (\n !request.path.startsWith('/javascripts/') &&\n !request.path.startsWith('/stylesheets/') &&\n !request.path.startsWith('/assets/')\n ) {\n response.header('cache-control', 'no-store')\n }\n\n return h.continue\n })\n\n await server.register(pluginViews)\n\n await server.register({\n plugin: {\n name: 'router',\n register: (server) => {\n server.route(publicRoutes)\n }\n }\n })\n\n await server.register(pluginErrorPages)\n\n if (config.get('cdpEnvironment') === 'local') {\n await server.register(blipp)\n }\n\n await server.register(requestTracing)\n\n return server\n}\n"],"mappings":"AAAA,SAASA,MAAM,IAAIC,YAAY,QAAQ,qBAAqB;AAC5D,SAASD,MAAM,IAAIE,WAAW,QAAQ,oBAAoB;AAC1D,OAAOC,IAAI,MAIJ,YAAY;AACnB,OAAOC,KAAK,MAAM,aAAa;AAC/B,OAAOC,OAAO,MAAM,eAAe;AACnC,OAAOC,KAAK,MAAM,aAAa;AAC/B,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,aAAa;AAExC,SAASC,MAAM;AACf,SAASC,aAAa;AACtB,SAASC,cAAc;AACvB,SAASC,gBAAgB;AACzB,SAASC,oBAAoB;AAC7B,SAASC,qBAAqB;AAC9B,OAAOC,gBAAgB;AACvB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,WAAW,CAAC;EAElC,MAAMmC,MAAM,CAACC,QAAQ,CAAC;IACpBrC,MAAM,EAAE;MACN+B,IAAI,EAAE,QAAQ;MACdM,QAAQ,EAAGD,MAAM,IAAK;QACpBA,MAAM,CAACW,KAAK,CAAC3C,YAAY,CAAC;MAC5B;IACF;EACF,CAAC,CAAC;EAEF,MAAMgC,MAAM,CAACC,QAAQ,CAACtC,gBAAgB,CAAC;EAEvC,IAAIN,MAAM,CAACqB,GAAG,CAAC,gBAAgB,CAAC,KAAK,OAAO,EAAE;IAC5C,MAAMsB,MAAM,CAACC,QAAQ,CAAC9C,KAAK,CAAC;EAC9B;EAEA,MAAM6C,MAAM,CAACC,QAAQ,CAAC1C,cAAc,CAAC;EAErC,OAAOyC,MAAM;AACf","ignoreList":[]}
@@ -2,7 +2,7 @@ import { type DatePartsFieldComponent } from '@defra/forms-model';
2
2
  import { type CustomValidator, type ObjectSchema } from 'joi';
3
3
  import { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js';
4
4
  import { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js';
5
- import { type DateInputItem } from '~/src/server/plugins/engine/components/types.js';
5
+ import { type DateInputItem, type DatePartsState } from '~/src/server/plugins/engine/components/types.js';
6
6
  import { type ErrorMessageTemplateList, type FormPayload, type FormState, type FormStateValue, type FormSubmissionError, type FormSubmissionState } from '~/src/server/plugins/engine/types.js';
7
7
  export declare class DatePartsField extends FormComponent {
8
8
  options: DatePartsFieldComponent['options'];
@@ -72,9 +72,4 @@ export declare class DatePartsField extends FormComponent {
72
72
  static getAllPossibleErrors(): ErrorMessageTemplateList;
73
73
  static isDateParts(value?: FormStateValue | FormState): value is DatePartsState;
74
74
  }
75
- export interface DatePartsState extends Record<string, number> {
76
- day: number;
77
- month: number;
78
- year: number;
79
- }
80
75
  export declare function getValidatorDate(component: DatePartsField): CustomValidator;
@@ -3,6 +3,7 @@ import { add, format, isValid, parse, startOfToday, sub } from 'date-fns';
3
3
  import { ComponentCollection } from "./ComponentCollection.js";
4
4
  import { FormComponent, isFormState, isFormValue } from "./FormComponent.js";
5
5
  import { NumberField } from "./NumberField.js";
6
+ import { parseStrictDate } from "../date-helper.js";
6
7
  import { messageTemplate } from "../pageControllers/validationOptions.js";
7
8
  import { convertToLanguageMessages } from "../../../utils/type-utils.js";
8
9
  export class DatePartsField extends FormComponent {
@@ -93,7 +94,7 @@ export class DatePartsField extends FormComponent {
93
94
  }
94
95
  getContextValueFromState(state) {
95
96
  const value = this.getFormValueFromState(state);
96
- if (!value || !isValid(parse(`${value.year}-${value.month}-${value.day}`, 'yyyy-MM-dd', new Date()))) {
97
+ if (!value || !isValid(parseStrictDate(value, `${value.year}-${value.month}-${value.day}`, 'yyyy-MM-dd', new Date()))) {
97
98
  return null;
98
99
  }
99
100
  return format(`${value.year}-${value.month}-${value.day}`, 'yyyy-MM-dd');
@@ -1 +1 @@
1
- {"version":3,"file":"DatePartsField.js","names":["ComponentType","add","format","isValid","parse","startOfToday","sub","ComponentCollection","FormComponent","isFormState","isFormValue","NumberField","messageTemplate","convertToLanguageMessages","DatePartsField","constructor","def","props","name","options","isRequired","required","customValidationMessages","objectMissing","dateFormat","collection","type","title","schema","min","max","precision","optionalText","classes","parent","custom","getValidatorDate","peers","formSchema","stateSchema","getFormValueFromState","state","value","isState","undefined","getDisplayStringFromState","year","month","day","getContextValueFromState","Date","getViewModel","payload","errors","viewModel","fieldset","label","hasError","some","error","items","map","model","errorMessage","toString","text","trim","id","legend","isDateParts","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","dateMin","dateMax","isNumber","component","validator","helpers","values","getStateFromValidForm","context","missing","keys","key","date","maxDaysInPast","days","maxDaysInFuture","limit"],"sources":["../../../../../src/server/plugins/engine/components/DatePartsField.ts"],"sourcesContent":["import { ComponentType, type DatePartsFieldComponent } from '@defra/forms-model'\nimport { add, format, isValid, parse, startOfToday, sub } from 'date-fns'\nimport { type Context, type CustomValidator, type ObjectSchema } from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { type DateInputItem } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\nexport class DatePartsField extends FormComponent {\n declare options: DatePartsFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: DatePartsFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options } = def\n\n const isRequired = options.required !== false\n\n const customValidationMessages = convertToLanguageMessages({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'any.required': messageTemplate.objectMissing,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'number.base': messageTemplate.objectMissing,\n 'number.precision': messageTemplate.dateFormat,\n 'number.integer': messageTemplate.dateFormat,\n 'number.unsafe': messageTemplate.dateFormat,\n 'number.min': messageTemplate.dateFormat,\n 'number.max': messageTemplate.dateFormat\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__day`,\n title: 'Day',\n schema: { min: 1, max: 31, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__month`,\n title: 'Month',\n schema: { min: 1, max: 12, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__year`,\n title: 'Year',\n schema: { min: 1000, max: 3000, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-4',\n customValidationMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorDate(this),\n peers: [`${name}__day`, `${name}__month`, `${name}__year`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return this.isState(value) ? value : undefined\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (!value) {\n return ''\n }\n\n return format(`${value.year}-${value.month}-${value.day}`, 'd MMMM yyyy')\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (\n !value ||\n !isValid(\n parse(\n `${value.year}-${value.month}-${value.day}`,\n 'yyyy-MM-dd',\n new Date()\n )\n )\n ) {\n return null\n }\n\n return format(`${value.year}-${value.month}-${value.day}`, 'yyyy-MM-dd')\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { collection, name } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n // Check for component errors only\n const hasError = errors?.some((error) => error.name === name)\n\n // Use the component collection to generate the subitems\n const items: DateInputItem[] = collection\n .getViewModel(payload, errors)\n .map(({ model }) => {\n let { label, type, value, classes, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text // Date component uses string labels\n }\n\n if (hasError || errorMessage) {\n classes = `${classes} govuk-input--error`.trim()\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes\n }\n })\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n\n isState(value?: FormStateValue | FormState) {\n return DatePartsField.isDateParts(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DatePartsField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n { type: 'dateFormat', template: messageTemplate.dateFormat },\n { type: 'dateFormatDay', template: '{{#label}} must include a day' },\n {\n type: 'dateFormatMonth',\n template: '{{#label}} must include a month'\n },\n { type: 'dateFormatYear', template: '{{#label}} must include a year' }\n ],\n advancedSettingsErrors: [\n { type: 'dateMin', template: messageTemplate.dateMin },\n { type: 'dateMax', template: messageTemplate.dateMax }\n ]\n }\n }\n\n static isDateParts(\n value?: FormStateValue | FormState\n ): value is DatePartsState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.day) &&\n NumberField.isNumber(value.month) &&\n NumberField.isNumber(value.year)\n )\n }\n}\n\nexport interface DatePartsState extends Record<string, number> {\n day: number\n month: number\n year: number\n}\n\nexport function getValidatorDate(component: DatePartsField) {\n const validator: CustomValidator = (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n const date = parse(\n `${values.year}-${values.month}-${values.day}`,\n 'yyyy-MM-dd',\n new Date()\n )\n\n if (!isValid(date)) {\n return helpers.error('date.format', context)\n }\n\n // Minimum date from today\n const dateMin = options.maxDaysInPast\n ? sub(startOfToday(), { days: options.maxDaysInPast })\n : undefined\n\n // Maximum date from today\n const dateMax = options.maxDaysInFuture\n ? add(startOfToday(), { days: options.maxDaysInFuture })\n : undefined\n\n if (dateMin && date < dateMin) {\n return helpers.error('date.min', { ...context, limit: dateMin })\n }\n\n if (dateMax && date > dateMax) {\n return helpers.error('date.max', { ...context, limit: dateMax })\n }\n\n return payload\n }\n\n return validator\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsC,oBAAoB;AAChF,SAASC,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,YAAY,EAAEC,GAAG,QAAQ,UAAU;AAGzE,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW,EACXC,WAAW;AAEb,SAASC,WAAW;AAEpB,SAASC,eAAe;AASxB,SAASC,yBAAyB;AAElC,OAAO,MAAMC,cAAc,SAASN,aAAa,CAAC;EAMhDO,WAAWA,CACTC,GAA4B,EAC5BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAE7B,MAAMI,UAAU,GAAGD,OAAO,CAACE,QAAQ,KAAK,KAAK;IAE7C,MAAMC,wBAAwB,GAAGT,yBAAyB,CAAC;MACzD;MACA,cAAc,EAAED,eAAe,CAACW,aAAa;MAC7C;MACA,aAAa,EAAEX,eAAe,CAACW,aAAa;MAC5C,kBAAkB,EAAEX,eAAe,CAACY,UAAU;MAC9C,gBAAgB,EAAEZ,eAAe,CAACY,UAAU;MAC5C,eAAe,EAAEZ,eAAe,CAACY,UAAU;MAC3C,YAAY,EAAEZ,eAAe,CAACY,UAAU;MACxC,YAAY,EAAEZ,eAAe,CAACY;IAChC,CAAC,CAAC;IAEF,IAAI,CAACC,UAAU,GAAG,IAAIlB,mBAAmB,CACvC,CACE;MACEmB,IAAI,EAAE1B,aAAa,CAACW,WAAW;MAC/BO,IAAI,EAAE,GAAGA,IAAI,OAAO;MACpBS,KAAK,EAAE,KAAK;MACZC,MAAM,EAAE;QAAEC,GAAG,EAAE,CAAC;QAAEC,GAAG,EAAE,EAAE;QAAEC,SAAS,EAAE;MAAE,CAAC;MACzCZ,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Valid","parse","startOfToday","sub","ComponentCollection","FormComponent","isFormState","isFormValue","NumberField","parseStrictDate","messageTemplate","convertToLanguageMessages","DatePartsField","constructor","def","props","name","options","isRequired","required","customValidationMessages","objectMissing","dateFormat","collection","type","title","schema","min","max","precision","optionalText","classes","parent","custom","getValidatorDate","peers","formSchema","stateSchema","getFormValueFromState","state","value","isState","undefined","getDisplayStringFromState","year","month","day","getContextValueFromState","Date","getViewModel","payload","errors","viewModel","fieldset","label","hasError","some","error","items","map","model","errorMessage","toString","text","trim","id","legend","isDateParts","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","dateMin","dateMax","isNumber","component","validator","helpers","values","getStateFromValidForm","context","missing","keys","key","date","maxDaysInPast","days","maxDaysInFuture","limit"],"sources":["../../../../../src/server/plugins/engine/components/DatePartsField.ts"],"sourcesContent":["import { ComponentType, type DatePartsFieldComponent } from '@defra/forms-model'\nimport { add, format, isValid, parse, startOfToday, sub } from 'date-fns'\nimport { type Context, type CustomValidator, type ObjectSchema } from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport {\n type DateInputItem,\n type DatePartsState\n} from '~/src/server/plugins/engine/components/types.js'\nimport { parseStrictDate } from '~/src/server/plugins/engine/date-helper.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\nexport class DatePartsField extends FormComponent {\n declare options: DatePartsFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: DatePartsFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options } = def\n\n const isRequired = options.required !== false\n\n const customValidationMessages = convertToLanguageMessages({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'any.required': messageTemplate.objectMissing,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'number.base': messageTemplate.objectMissing,\n 'number.precision': messageTemplate.dateFormat,\n 'number.integer': messageTemplate.dateFormat,\n 'number.unsafe': messageTemplate.dateFormat,\n 'number.min': messageTemplate.dateFormat,\n 'number.max': messageTemplate.dateFormat\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__day`,\n title: 'Day',\n schema: { min: 1, max: 31, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__month`,\n title: 'Month',\n schema: { min: 1, max: 12, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__year`,\n title: 'Year',\n schema: { min: 1000, max: 3000, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-4',\n customValidationMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorDate(this),\n peers: [`${name}__day`, `${name}__month`, `${name}__year`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return this.isState(value) ? value : undefined\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (!value) {\n return ''\n }\n\n return format(`${value.year}-${value.month}-${value.day}`, 'd MMMM yyyy')\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (\n !value ||\n !isValid(\n parseStrictDate(\n value,\n `${value.year}-${value.month}-${value.day}`,\n 'yyyy-MM-dd',\n new Date()\n )\n )\n ) {\n return null\n }\n\n return format(`${value.year}-${value.month}-${value.day}`, 'yyyy-MM-dd')\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { collection, name } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n // Check for component errors only\n const hasError = errors?.some((error) => error.name === name)\n\n // Use the component collection to generate the subitems\n const items: DateInputItem[] = collection\n .getViewModel(payload, errors)\n .map(({ model }) => {\n let { label, type, value, classes, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text // Date component uses string labels\n }\n\n if (hasError || errorMessage) {\n classes = `${classes} govuk-input--error`.trim()\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes\n }\n })\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n\n isState(value?: FormStateValue | FormState) {\n return DatePartsField.isDateParts(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DatePartsField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n { type: 'dateFormat', template: messageTemplate.dateFormat },\n { type: 'dateFormatDay', template: '{{#label}} must include a day' },\n {\n type: 'dateFormatMonth',\n template: '{{#label}} must include a month'\n },\n { type: 'dateFormatYear', template: '{{#label}} must include a year' }\n ],\n advancedSettingsErrors: [\n { type: 'dateMin', template: messageTemplate.dateMin },\n { type: 'dateMax', template: messageTemplate.dateMax }\n ]\n }\n }\n\n static isDateParts(\n value?: FormStateValue | FormState\n ): value is DatePartsState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.day) &&\n NumberField.isNumber(value.month) &&\n NumberField.isNumber(value.year)\n )\n }\n}\n\nexport function getValidatorDate(component: DatePartsField) {\n const validator: CustomValidator = (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n const date = parse(\n `${values.year}-${values.month}-${values.day}`,\n 'yyyy-MM-dd',\n new Date()\n )\n\n if (!isValid(date)) {\n return helpers.error('date.format', context)\n }\n\n // Minimum date from today\n const dateMin = options.maxDaysInPast\n ? sub(startOfToday(), { days: options.maxDaysInPast })\n : undefined\n\n // Maximum date from today\n const dateMax = options.maxDaysInFuture\n ? add(startOfToday(), { days: options.maxDaysInFuture })\n : undefined\n\n if (dateMin && date < dateMin) {\n return helpers.error('date.min', { ...context, limit: dateMin })\n }\n\n if (dateMax && date > dateMax) {\n return helpers.error('date.max', { ...context, limit: dateMax })\n }\n\n return payload\n }\n\n return validator\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsC,oBAAoB;AAChF,SAASC,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,YAAY,EAAEC,GAAG,QAAQ,UAAU;AAGzE,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW,EACXC,WAAW;AAEb,SAASC,WAAW;AAKpB,SAASC,eAAe;AACxB,SAASC,eAAe;AASxB,SAASC,yBAAyB;AAElC,OAAO,MAAMC,cAAc,SAASP,aAAa,CAAC;EAMhDQ,WAAWA,CACTC,GAA4B,EAC5BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GA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AAEoF,IAAI,EAAErE,OAAO,CAACoE;IAAc,CAAC,CAAC,GACpD3C,SAAS;;IAEb;IACA,MAAM+B,OAAO,GAAGxD,OAAO,CAACsE,eAAe,GACnCzF,GAAG,CAACI,YAAY,CAAC,CAAC,EAAE;MAAEoF,IAAI,EAAErE,OAAO,CAACsE;IAAgB,CAAC,CAAC,GACtD7C,SAAS;IAEb,IAAI8B,OAAO,IAAIY,IAAI,GAAGZ,OAAO,EAAE;MAC7B,OAAOK,OAAO,CAACpB,KAAK,CAAC,UAAU,EAAE;QAAE,GAAGuB,OAAO;QAAEQ,KAAK,EAAEhB;MAAQ,CAAC,CAAC;IAClE;IAEA,IAAIC,OAAO,IAAIW,IAAI,GAAGX,OAAO,EAAE;MAC7B,OAAOI,OAAO,CAACpB,KAAK,CAAC,UAAU,EAAE;QAAE,GAAGuB,OAAO;QAAEQ,KAAK,EAAEf;MAAQ,CAAC,CAAC;IAClE;IAEA,OAAOvB,OAAO;EAChB,CAAC;EAED,OAAO0B,SAAS;AAClB","ignoreList":[]}
@@ -2,7 +2,7 @@ import { type MonthYearFieldComponent } from '@defra/forms-model';
2
2
  import { type CustomValidator, type ObjectSchema } from 'joi';
3
3
  import { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js';
4
4
  import { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js';
5
- import { type DateInputItem } from '~/src/server/plugins/engine/components/types.js';
5
+ import { type DateInputItem, type MonthYearState } from '~/src/server/plugins/engine/components/types.js';
6
6
  import { type ErrorMessageTemplateList, type FormPayload, type FormState, type FormStateValue, type FormSubmissionError, type FormSubmissionState } from '~/src/server/plugins/engine/types.js';
7
7
  export declare class MonthYearField extends FormComponent {
8
8
  options: MonthYearFieldComponent['options'];
@@ -72,8 +72,4 @@ export declare class MonthYearField extends FormComponent {
72
72
  static getAllPossibleErrors(): ErrorMessageTemplateList;
73
73
  static isMonthYear(value?: FormStateValue | FormState): value is MonthYearState;
74
74
  }
75
- export interface MonthYearState extends Record<string, number> {
76
- month: number;
77
- year: number;
78
- }
79
75
  export declare function getValidatorMonthYear(component: MonthYearField): CustomValidator;
@@ -1,8 +1,9 @@
1
1
  import { ComponentType } from '@defra/forms-model';
2
- import { format, isValid, parse } from 'date-fns';
2
+ import { format, isValid } from 'date-fns';
3
3
  import { ComponentCollection } from "./ComponentCollection.js";
4
4
  import { FormComponent, isFormState, isFormValue } from "./FormComponent.js";
5
5
  import { NumberField } from "./NumberField.js";
6
+ import { parseStrictDate } from "../date-helper.js";
6
7
  import { messageTemplate } from "../pageControllers/validationOptions.js";
7
8
  import { convertToLanguageMessages } from "../../../utils/type-utils.js";
8
9
  export class MonthYearField extends FormComponent {
@@ -83,7 +84,7 @@ export class MonthYearField extends FormComponent {
83
84
  }
84
85
  getContextValueFromState(state) {
85
86
  const value = this.getFormValueFromState(state);
86
- if (!value || !isValid(parse(`${value.year}-${value.month}-01`, 'yyyy-MM-dd', new Date()))) {
87
+ if (!value || !isValid(parseStrictDate(value, `${value.year}-${value.month}-01`, 'yyyy-MM-dd', new Date()))) {
87
88
  return null;
88
89
  }
89
90
  return format(`${value.year}-${value.month}-01`, 'yyyy-MM');
@@ -1 +1 @@
1
- {"version":3,"file":"MonthYearField.js","names":["ComponentType","format","isValid","parse","ComponentCollection","FormComponent","isFormState","isFormValue","NumberField","messageTemplate","convertToLanguageMessages","MonthYearField","constructor","def","props","name","options","isRequired","required","customValidationMessages","objectMissing","dateFormat","collection","type","title","schema","min","max","precision","optionalText","classes","parent","custom","getValidatorMonthYear","peers","formSchema","stateSchema","getFormValueFromState","state","value","isMonthYear","undefined","getDisplayStringFromState","date","Date","setMonth","month","monthString","toLocaleString","year","getContextValueFromState","getViewModel","payload","errors","viewModel","fieldset","label","hasError","some","error","items","map","model","errorMessage","toString","text","trim","id","legend","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","dateMin","dateMax","isNumber","component","validator","helpers","values","getStateFromValidForm","context","missing","keys","key"],"sources":["../../../../../src/server/plugins/engine/components/MonthYearField.ts"],"sourcesContent":["import { ComponentType, type MonthYearFieldComponent } from '@defra/forms-model'\nimport { format, isValid, parse } from 'date-fns'\nimport {\n type Context,\n type CustomValidator,\n type LanguageMessages,\n type ObjectSchema\n} from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { type DateInputItem } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\nexport class MonthYearField extends FormComponent {\n declare options: MonthYearFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: MonthYearFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options } = def\n\n const isRequired = options.required !== false\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'any.required': messageTemplate.objectMissing,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'number.base': messageTemplate.objectMissing,\n 'number.precision': messageTemplate.dateFormat,\n 'number.integer': messageTemplate.dateFormat,\n 'number.unsafe': messageTemplate.dateFormat,\n 'number.min': messageTemplate.dateFormat,\n 'number.max': messageTemplate.dateFormat\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__month`,\n title: 'Month',\n schema: { min: 1, max: 12, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__year`,\n title: 'Year',\n schema: { min: 1000, max: 3000, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-4',\n customValidationMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorMonthYear(this),\n peers: [`${name}__month`, `${name}__year`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return MonthYearField.isMonthYear(value) ? value : undefined\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (!value) {\n return ''\n }\n\n const date = new Date()\n date.setMonth(value.month - 1)\n\n const monthString = date.toLocaleString('default', { month: 'long' })\n return `${monthString} ${value.year}`\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (\n !value ||\n !isValid(\n parse(`${value.year}-${value.month}-01`, 'yyyy-MM-dd', new Date())\n )\n ) {\n return null\n }\n\n return format(`${value.year}-${value.month}-01`, 'yyyy-MM')\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { collection, name } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n // Check for component errors only\n const hasError = errors?.some((error) => error.name === name)\n\n // Use the component collection to generate the subitems\n const items: DateInputItem[] = collection\n .getViewModel(payload, errors)\n .map(({ model }) => {\n let { label, type, value, classes, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text // Date component uses string labels\n }\n\n if (hasError || errorMessage) {\n classes = `${classes} govuk-input--error`.trim()\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes\n }\n })\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n\n isState(value?: FormStateValue | FormState) {\n return MonthYearField.isMonthYear(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return MonthYearField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n {\n type: 'dateFormatMonth',\n template: '{{#label}} must include a month'\n },\n { type: 'dateFormatYear', template: '{{#label}} must include a year' }\n ],\n advancedSettingsErrors: [\n { type: 'dateMin', template: messageTemplate.dateMin },\n { type: 'dateMax', template: messageTemplate.dateMax }\n ]\n }\n }\n\n static isMonthYear(\n value?: FormStateValue | FormState\n ): value is MonthYearState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.month) &&\n NumberField.isNumber(value.year)\n )\n }\n}\n\nexport interface MonthYearState extends Record<string, number> {\n month: number\n year: number\n}\n\nexport function getValidatorMonthYear(component: MonthYearField) {\n const validator: CustomValidator = (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n return payload\n }\n\n return validator\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsC,oBAAoB;AAChF,SAASC,MAAM,EAAEC,OAAO,EAAEC,KAAK,QAAQ,UAAU;AAQjD,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW,EACXC,WAAW;AAEb,SAASC,WAAW;AAEpB,SAASC,eAAe;AASxB,SAASC,yBAAyB;AAElC,OAAO,MAAMC,cAAc,SAASN,aAAa,CAAC;EAMhDO,WAAWA,CACTC,GAA4B,EAC5BC,K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,MAAM;MAAEzD,UAAU;MAAEP,IAAI;MAAEC;IAAQ,CAAC,GAAG6D,SAAS;IAE/C,MAAMG,MAAM,GAAGH,SAAS,CAACxC,qBAAqB,CAC5CwC,SAAS,CAACI,qBAAqB,CAAC7B,OAAO,CACzC,CAAC;IAED,MAAM8B,OAAgB,GAAG;MACvBC,OAAO,EAAE7D,UAAU,CAAC8D,IAAI;MACxBC,GAAG,EAAEtE;IACP,CAAC;IAED,IAAI,CAAC8D,SAAS,CAACR,OAAO,CAACW,MAAM,CAAC,EAAE;MAC9B,OAAOhE,OAAO,CAACE,QAAQ,KAAK,KAAK,GAC7B6D,OAAO,CAACpB,KAAK,CAAC,iBAAiB,EAAEuB,OAAO,CAAC,GACzC9B,OAAO;IACb;IAEA,OAAOA,OAAO;EAChB,CAAC;EAED,OAAO0B,SAAS;AAClB","ignoreList":[]}
1
+ {"version":3,"file":"MonthYearField.js","names":["ComponentType","format","isValid","ComponentCollection","FormComponent","isFormState","isFormValue","NumberField","parseStrictDate","messageTemplate","convertToLanguageMessages","MonthYearField","constructor","def","props","name","options","isRequired","required","customValidationMessages","objectMissing","dateFormat","collection","type","title","schema","min","max","precision","optionalText","classes","parent","custom","getValidatorMonthYear","peers","formSchema","stateSchema","getFormValueFromState","state","value","isMonthYear","undefined","getDisplayStringFromState","date","Date","setMonth","month","monthString","toLocaleString","year","getContextValueFromState","getViewModel","payload","errors","viewModel","fieldset","label","hasError","some","error","items","map","model","errorMessage","toString","text","trim","id","legend","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","dateMin","dateMax","isNumber","component","validator","helpers","values","getStateFromValidForm","context","missing","keys","key"],"sources":["../../../../../src/server/plugins/engine/components/MonthYearField.ts"],"sourcesContent":["import { ComponentType, type MonthYearFieldComponent } from '@defra/forms-model'\nimport { format, isValid } from 'date-fns'\nimport {\n type Context,\n type CustomValidator,\n type LanguageMessages,\n type ObjectSchema\n} from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport {\n type DateInputItem,\n type MonthYearState\n} from '~/src/server/plugins/engine/components/types.js'\nimport { parseStrictDate } from '~/src/server/plugins/engine/date-helper.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\nexport class MonthYearField extends FormComponent {\n declare options: MonthYearFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: MonthYearFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options } = def\n\n const isRequired = options.required !== false\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'any.required': messageTemplate.objectMissing,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n 'number.base': messageTemplate.objectMissing,\n 'number.precision': messageTemplate.dateFormat,\n 'number.integer': messageTemplate.dateFormat,\n 'number.unsafe': messageTemplate.dateFormat,\n 'number.min': messageTemplate.dateFormat,\n 'number.max': messageTemplate.dateFormat\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__month`,\n title: 'Month',\n schema: { min: 1, max: 12, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-2',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__year`,\n title: 'Year',\n schema: { min: 1000, max: 3000, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-4',\n customValidationMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorMonthYear(this),\n peers: [`${name}__month`, `${name}__year`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return MonthYearField.isMonthYear(value) ? value : undefined\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (!value) {\n return ''\n }\n\n const date = new Date()\n date.setMonth(value.month - 1)\n\n const monthString = date.toLocaleString('default', { month: 'long' })\n return `${monthString} ${value.year}`\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n if (\n !value ||\n !isValid(\n parseStrictDate(\n value,\n `${value.year}-${value.month}-01`,\n 'yyyy-MM-dd',\n new Date()\n )\n )\n ) {\n return null\n }\n\n return format(`${value.year}-${value.month}-01`, 'yyyy-MM')\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const { collection, name } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n // Check for component errors only\n const hasError = errors?.some((error) => error.name === name)\n\n // Use the component collection to generate the subitems\n const items: DateInputItem[] = collection\n .getViewModel(payload, errors)\n .map(({ model }) => {\n let { label, type, value, classes, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text // Date component uses string labels\n }\n\n if (hasError || errorMessage) {\n classes = `${classes} govuk-input--error`.trim()\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes\n }\n })\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n return {\n ...viewModel,\n fieldset,\n items\n }\n }\n\n isState(value?: FormStateValue | FormState) {\n return MonthYearField.isMonthYear(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return MonthYearField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n {\n type: 'dateFormatMonth',\n template: '{{#label}} must include a month'\n },\n { type: 'dateFormatYear', template: '{{#label}} must include a year' }\n ],\n advancedSettingsErrors: [\n { type: 'dateMin', template: messageTemplate.dateMin },\n { type: 'dateMax', template: messageTemplate.dateMax }\n ]\n }\n }\n\n static isMonthYear(\n value?: FormStateValue | FormState\n ): value is MonthYearState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.month) &&\n NumberField.isNumber(value.year)\n )\n }\n}\n\nexport function getValidatorMonthYear(component: MonthYearField) {\n const validator: CustomValidator = (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n return payload\n }\n\n return validator\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAsC,oBAAoB;AAChF,SAASC,MAAM,EAAEC,OAAO,QAAQ,UAAU;AAQ1C,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW,EACXC,WAAW;AAEb,SAASC,WAAW;AAKpB,SAASC,eAAe;AACxB,SAASC,eAAe;AASxB,SAASC,yBAAyB;AAElC,OAAO,MAAMC,cAAc,SAASP,aAAa,CAAC;EAMhDQ,WAAWA,CACTC,GAA4B,EAC5BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAE7B,MAAMI,UAAU,GAAGD,OAAO,CAACE,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,CAAC7B,OAAO,CACzC,CAAC;IAED,MAAM8B,OAAgB,GAAG;MACvBC,OAAO,EAAE7D,UAAU,CAAC8D,IAAI;MACxBC,GAAG,EAAEtE;IACP,CAAC;IAED,IAAI,CAAC8D,SAAS,CAACR,OAAO,CAACW,MAAM,CAAC,EAAE;MAC9B,OAAOhE,OAAO,CAACE,QAAQ,KAAK,KAAK,GAC7B6D,OAAO,CAACpB,KAAK,CAAC,iBAAiB,EAAEuB,OAAO,CAAC,GACzC9B,OAAO;IACb;IAEA,OAAOA,OAAO;EAChB,CAAC;EAED,OAAO0B,SAAS;AAClB","ignoreList":[]}
@@ -1,3 +1,4 @@
1
+ import { SchemaVersion, yesNoListId, yesNoListName } from '@defra/forms-model';
1
2
  import { SelectionControlField } from "./SelectionControlField.js";
2
3
  import { addClassOptionIfNone } from "./helpers.js";
3
4
  import { messageTemplate } from "../pageControllers/validationOptions.js";
@@ -11,7 +12,7 @@ export class YesNoField extends SelectionControlField {
11
12
  constructor(def, props) {
12
13
  super({
13
14
  ...def,
14
- list: '__yesNo'
15
+ list: props.model.schemaVersion === SchemaVersion.V1 ? yesNoListName : yesNoListId
15
16
  }, props);
16
17
  const {
17
18
  options
@@ -1 +1 @@
1
- {"version":3,"file":"YesNoField.js","names":["SelectionControlField","addClassOptionIfNone","messageTemplate","convertToLanguageMessages","YesNoField","constructor","def","props","list","options","formSchema","required","optional","messages","selectYesNoRequired","getAllPossibleErrors","baseErrors","type","template","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/YesNoField.ts"],"sourcesContent":["import { type YesNoFieldComponent } from '@defra/forms-model'\n\nimport { SelectionControlField } from '~/src/server/plugins/engine/components/SelectionControlField.js'\nimport { addClassOptionIfNone } from '~/src/server/plugins/engine/components/helpers.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport { type ErrorMessageTemplateList } from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\n/**\n * @description\n * YesNoField is a radiosField with predefined values.\n */\nexport class YesNoField extends SelectionControlField {\n declare options: YesNoFieldComponent['options']\n\n constructor(\n def: YesNoFieldComponent,\n props: ConstructorParameters<typeof SelectionControlField>[1]\n ) {\n super({ ...def, list: '__yesNo' }, props)\n\n const { options } = def\n let { formSchema } = this\n\n addClassOptionIfNone(options, 'govuk-radios--inline')\n\n if (options.required === false) {\n formSchema = formSchema.optional()\n }\n\n formSchema = formSchema.messages(\n convertToLanguageMessages({\n 'any.required': messageTemplate.selectYesNoRequired\n })\n )\n\n this.formSchema = formSchema\n this.options = options\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return YesNoField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n {\n type: 'selectYesNoRequired',\n template: messageTemplate.selectYesNoRequired\n }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAEA,SAASA,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AAExB,SAASC,yBAAyB;;AAElC;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,SAASJ,qBAAqB,CAAC;EAGpDK,WAAWA,CACTC,GAAwB,EACxBC,KAA6D,EAC7D;IACA,KAAK,CAAC;MAAE,GAAGD,GAAG;MAAEE,IAAI,EAAE;IAAU,CAAC,EAAED,KAAK,CAAC;IAEzC,MAAM;MAAEE;IAAQ,CAAC,GAAGH,GAAG;IACvB,IAAI;MAAEI;IAAW,CAAC,GAAG,IAAI;IAEzBT,oBAAoB,CAACQ,OAAO,EAAE,sBAAsB,CAAC;IAErD,IAAIA,OAAO,CAACE,QAAQ,KAAK,KAAK,EAAE;MAC9BD,UAAU,GAAGA,UAAU,CAACE,QAAQ,CAAC,CAAC;IACpC;IAEAF,UAAU,GAAGA,UAAU,CAACG,QAAQ,CAC9BV,yBAAyB,CAAC;MACxB,cAAc,EAAED,eAAe,CAACY;IAClC,CAAC,CACH,CAAC;IAED,IAAI,CAACJ,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACD,OAAO,GAAGA,OAAO;EACxB;;EAEA;AACF;AACA;EACEM,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOX,UAAU,CAACW,oBAAoB,CAAC,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QACEC,IAAI,EAAE,qBAAqB;QAC3BC,QAAQ,EAAEhB,eAAe,CAACY;MAC5B,CAAC,CACF;MACDK,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
1
+ {"version":3,"file":"YesNoField.js","names":["SchemaVersion","yesNoListId","yesNoListName","SelectionControlField","addClassOptionIfNone","messageTemplate","convertToLanguageMessages","YesNoField","constructor","def","props","list","model","schemaVersion","V1","options","formSchema","required","optional","messages","selectYesNoRequired","getAllPossibleErrors","baseErrors","type","template","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/YesNoField.ts"],"sourcesContent":["import {\n SchemaVersion,\n yesNoListId,\n yesNoListName,\n type YesNoFieldComponent\n} from '@defra/forms-model'\n\nimport { SelectionControlField } from '~/src/server/plugins/engine/components/SelectionControlField.js'\nimport { addClassOptionIfNone } from '~/src/server/plugins/engine/components/helpers.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport { type ErrorMessageTemplateList } from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\n/**\n * @description\n * YesNoField is a radiosField with predefined values.\n */\nexport class YesNoField extends SelectionControlField {\n declare options: YesNoFieldComponent['options']\n\n constructor(\n def: YesNoFieldComponent,\n props: ConstructorParameters<typeof SelectionControlField>[1]\n ) {\n super(\n {\n ...def,\n list:\n props.model.schemaVersion === SchemaVersion.V1\n ? yesNoListName\n : yesNoListId\n },\n props\n )\n\n const { options } = def\n let { formSchema } = this\n\n addClassOptionIfNone(options, 'govuk-radios--inline')\n\n if (options.required === false) {\n formSchema = formSchema.optional()\n }\n\n formSchema = formSchema.messages(\n convertToLanguageMessages({\n 'any.required': messageTemplate.selectYesNoRequired\n })\n )\n\n this.formSchema = formSchema\n this.options = options\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return YesNoField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n {\n type: 'selectYesNoRequired',\n template: messageTemplate.selectYesNoRequired\n }\n ],\n advancedSettingsErrors: []\n }\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,WAAW,EACXC,aAAa,QAER,oBAAoB;AAE3B,SAASC,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AAExB,SAASC,yBAAyB;;AAElC;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,SAASJ,qBAAqB,CAAC;EAGpDK,WAAWA,CACTC,GAAwB,EACxBC,KAA6D,EAC7D;IACA,KAAK,CACH;MACE,GAAGD,GAAG;MACNE,IAAI,EACFD,KAAK,CAACE,KAAK,CAACC,aAAa,KAAKb,aAAa,CAACc,EAAE,GAC1CZ,aAAa,GACbD;IACR,CAAC,EACDS,KACF,CAAC;IAED,MAAM;MAAEK;IAAQ,CAAC,GAAGN,GAAG;IACvB,IAAI;MAAEO;IAAW,CAAC,GAAG,IAAI;IAEzBZ,oBAAoB,CAACW,OAAO,EAAE,sBAAsB,CAAC;IAErD,IAAIA,OAAO,CAACE,QAAQ,KAAK,KAAK,EAAE;MAC9BD,UAAU,GAAGA,UAAU,CAACE,QAAQ,CAAC,CAAC;IACpC;IAEAF,UAAU,GAAGA,UAAU,CAACG,QAAQ,CAC9Bb,yBAAyB,CAAC;MACxB,cAAc,EAAED,eAAe,CAACe;IAClC,CAAC,CACH,CAAC;IAED,IAAI,CAACJ,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACD,OAAO,GAAGA,OAAO;EACxB;;EAEA;AACF;AACA;EACEM,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOd,UAAU,CAACc,oBAAoB,CAAC,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QACEC,IAAI,EAAE,qBAAqB;QAC3BC,QAAQ,EAAEnB,eAAe,CAACe;MAC5B,CAAC,CACF;MACDK,sBAAsB,EAAE;IAC1B,CAAC;EACH;AACF","ignoreList":[]}
@@ -98,3 +98,12 @@ export interface ComponentViewModel {
98
98
  isFormComponent: boolean;
99
99
  model: ViewModel;
100
100
  }
101
+ export interface DatePartsState extends Record<string, number> {
102
+ day: number;
103
+ month: number;
104
+ year: number;
105
+ }
106
+ export interface MonthYearState extends Record<string, number> {
107
+ month: number;
108
+ year: number;
109
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/server/plugins/engine/components/types.ts"],"sourcesContent":["import { type ComponentType, type Item } from '@defra/forms-model'\n\nimport {\n type FormSubmissionError,\n type FormValue,\n type SummaryList\n} from '~/src/server/plugins/engine/types.js'\n\nexport type ComponentText = {\n classes?: string\n attributes?: string | Record<string, string>\n} & (\n | {\n text: string\n html?: string\n }\n | {\n text?: string\n html: string\n }\n)\n\nexport interface Label {\n text: string\n classes?: string\n html?: string\n isPageHeading?: boolean\n}\n\nexport interface Content {\n title?: string\n text: string\n condition?: string\n}\n\nexport interface BackLink {\n text: string\n href: string\n}\n\nexport type ListItemLabel = Omit<Label, 'text' | 'isPageHeading'>\n\nexport interface ListItem {\n text?: string\n value?: Item['value']\n hint?: {\n id?: string\n text: string\n }\n checked?: boolean\n selected?: boolean\n label?: ListItemLabel\n condition?: string\n}\n\nexport interface DateInputItem {\n label?: Label\n type?: string\n id?: string\n name?: string\n value?: Item['value']\n classes?: string\n condition?: undefined\n}\n\nexport interface ViewModel extends Record<string, unknown> {\n label?: Label\n type?: string\n id?: string\n name?: string\n value?: FormValue\n hint?: {\n id?: string\n text: string\n }\n prefix?: ComponentText\n suffix?: ComponentText\n classes?: string\n condition?: string\n errors?: FormSubmissionError[]\n errorMessage?: {\n text: string\n }\n summaryHtml?: string\n html?: string\n attributes: {\n autocomplete?: string\n maxlength?: number\n multiple?: string\n accept?: string\n inputmode?: string\n }\n content?: Content | Content[] | string\n maxlength?: number\n maxwords?: number\n rows?: number\n items?: ListItem[] | DateInputItem[]\n fieldset?: {\n attributes?: string | Record<string, string>\n legend?: Label\n }\n formGroup?: {\n classes?: string\n attributes?: string | Record<string, string>\n }\n components?: ComponentViewModel[]\n upload?: {\n count: number\n summaryList: SummaryList\n }\n}\n\nexport interface ComponentViewModel {\n type: ComponentType\n isFormComponent: boolean\n model: ViewModel\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../../src/server/plugins/engine/components/types.ts"],"sourcesContent":["import { type ComponentType, type Item } from '@defra/forms-model'\n\nimport {\n type FormSubmissionError,\n type FormValue,\n type SummaryList\n} from '~/src/server/plugins/engine/types.js'\n\nexport type ComponentText = {\n classes?: string\n attributes?: string | Record<string, string>\n} & (\n | {\n text: string\n html?: string\n }\n | {\n text?: string\n html: string\n }\n)\n\nexport interface Label {\n text: string\n classes?: string\n html?: string\n isPageHeading?: boolean\n}\n\nexport interface Content {\n title?: string\n text: string\n condition?: string\n}\n\nexport interface BackLink {\n text: string\n href: string\n}\n\nexport type ListItemLabel = Omit<Label, 'text' | 'isPageHeading'>\n\nexport interface ListItem {\n text?: string\n value?: Item['value']\n hint?: {\n id?: string\n text: string\n }\n checked?: boolean\n selected?: boolean\n label?: ListItemLabel\n condition?: string\n}\n\nexport interface DateInputItem {\n label?: Label\n type?: string\n id?: string\n name?: string\n value?: Item['value']\n classes?: string\n condition?: undefined\n}\n\nexport interface ViewModel extends Record<string, unknown> {\n label?: Label\n type?: string\n id?: string\n name?: string\n value?: FormValue\n hint?: {\n id?: string\n text: string\n }\n prefix?: ComponentText\n suffix?: ComponentText\n classes?: string\n condition?: string\n errors?: FormSubmissionError[]\n errorMessage?: {\n text: string\n }\n summaryHtml?: string\n html?: string\n attributes: {\n autocomplete?: string\n maxlength?: number\n multiple?: string\n accept?: string\n inputmode?: string\n }\n content?: Content | Content[] | string\n maxlength?: number\n maxwords?: number\n rows?: number\n items?: ListItem[] | DateInputItem[]\n fieldset?: {\n attributes?: string | Record<string, string>\n legend?: Label\n }\n formGroup?: {\n classes?: string\n attributes?: string | Record<string, string>\n }\n components?: ComponentViewModel[]\n upload?: {\n count: number\n summaryList: SummaryList\n }\n}\n\nexport interface ComponentViewModel {\n type: ComponentType\n isFormComponent: boolean\n model: ViewModel\n}\n\nexport interface DatePartsState extends Record<string, number> {\n day: number\n month: number\n year: number\n}\n\nexport interface MonthYearState extends Record<string, number> {\n month: number\n year: number\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import { type DatePartsState, type MonthYearState } from '~/src/server/plugins/engine/components/types.js';
2
+ /**
3
+ * This function is just a wrapper for startOfToday() but, since it's in a separate file, allows
4
+ * the function to be easily mocked for unit testing.
5
+ * @returns {Date}
6
+ */
7
+ export declare function todayAsDateOnly(): Date;
8
+ /**
9
+ * Wrapper for date-fns parse() method to ensure the year is 4-digits. It seems parse() allows a non-4-digit year
10
+ * despite the format mask enforcing it.
11
+ */
12
+ export declare function parseStrictDate(dateObj: DatePartsState | MonthYearState, dateStr: string, formatStr: string, referenceDate: Date): number | Date;
@@ -0,0 +1,21 @@
1
+ import { parse, startOfToday } from 'date-fns';
2
+ /**
3
+ * This function is just a wrapper for startOfToday() but, since it's in a separate file, allows
4
+ * the function to be easily mocked for unit testing.
5
+ * @returns {Date}
6
+ */
7
+ export function todayAsDateOnly() {
8
+ return startOfToday();
9
+ }
10
+
11
+ /**
12
+ * Wrapper for date-fns parse() method to ensure the year is 4-digits. It seems parse() allows a non-4-digit year
13
+ * despite the format mask enforcing it.
14
+ */
15
+ export function parseStrictDate(dateObj, dateStr, formatStr, referenceDate) {
16
+ if (!dateObj.year || dateObj.year < 1000 || dateObj.year > 9999) {
17
+ return NaN;
18
+ }
19
+ return parse(dateStr, formatStr, referenceDate);
20
+ }
21
+ //# sourceMappingURL=date-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-helper.js","names":["parse","startOfToday","todayAsDateOnly","parseStrictDate","dateObj","dateStr","formatStr","referenceDate","year","NaN"],"sources":["../../../../src/server/plugins/engine/date-helper.ts"],"sourcesContent":["import { parse, startOfToday } from 'date-fns'\n\nimport {\n type DatePartsState,\n type MonthYearState\n} from '~/src/server/plugins/engine/components/types.js'\n\n/**\n * This function is just a wrapper for startOfToday() but, since it's in a separate file, allows\n * the function to be easily mocked for unit testing.\n * @returns {Date}\n */\nexport function todayAsDateOnly() {\n return startOfToday()\n}\n\n/**\n * Wrapper for date-fns parse() method to ensure the year is 4-digits. It seems parse() allows a non-4-digit year\n * despite the format mask enforcing it.\n */\nexport function parseStrictDate(\n dateObj: DatePartsState | MonthYearState,\n dateStr: string,\n formatStr: string,\n referenceDate: Date\n) {\n if (!dateObj.year || dateObj.year < 1000 || dateObj.year > 9999) {\n return NaN\n }\n\n return parse(dateStr, formatStr, referenceDate)\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,YAAY,QAAQ,UAAU;AAO9C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAAA,EAAG;EAChC,OAAOD,YAAY,CAAC,CAAC;AACvB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASE,eAAeA,CAC7BC,OAAwC,EACxCC,OAAe,EACfC,SAAiB,EACjBC,aAAmB,EACnB;EACA,IAAI,CAACH,OAAO,CAACI,IAAI,IAAIJ,OAAO,CAACI,IAAI,GAAG,IAAI,IAAIJ,OAAO,CAACI,IAAI,GAAG,IAAI,EAAE;IAC/D,OAAOC,GAAG;EACZ;EAEA,OAAOT,KAAK,CAACK,OAAO,EAAEC,SAAS,EAAEC,aAAa,CAAC;AACjD","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { ControllerPath, Engine, hasComponents, isFormType } from '@defra/forms-model';
1
+ import { ControllerPath, Engine, getErrorMessage, hasComponents, isFormType } from '@defra/forms-model';
2
2
  import Boom from '@hapi/boom';
3
3
  import { format, parseISO } from 'date-fns';
4
4
  import { StatusCodes } from 'http-status-codes';
@@ -85,7 +85,8 @@ export function encodeUrl(link) {
85
85
  try {
86
86
  return new URL(link).toString(); // escape the search params without breaking the ? and & reserved characters in rfc2368
87
87
  } catch (err) {
88
- logger.error(err, `Failed to encode ${link}`);
88
+ const errMsg = getErrorMessage(err);
89
+ logger.error(errMsg, `[urlEncodingFailed] Failed to encode URL: ${link} - ${errMsg}`);
89
90
  throw err;
90
91
  }
91
92
  }
@@ -283,7 +284,7 @@ export function setPageTitles(def) {
283
284
  }
284
285
  if (!page.title) {
285
286
  const formNameMsg = def.name ? ` in form '${def.name}'` : '';
286
- logger.warn(`Page '${page.path}' has no title${formNameMsg}`);
287
+ logger.info(`[pageTitleMissing] Page '${page.path}' has no title${formNameMsg}`);
287
288
  }
288
289
  }
289
290
  });