@defra/fcp-sfd-frontend-engine 0.8.6 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -266,6 +266,24 @@ var businessVatSchema = Joi.object({
266
266
  })
267
267
  });
268
268
 
269
+ // src/schemas/business/business-vat-change-schema.js
270
+ var businessVatChangeSchema = Joi.object({
271
+ vatNumber: Joi.string().pattern(/^\d{9}$/).required().messages({
272
+ "string.pattern.base": "Enter a VAT registration number, like 123456789",
273
+ "string.empty": "Enter a VAT registration number",
274
+ "any.required": "Enter a VAT registration number",
275
+ "string.noControlChars": "VAT registration number must not contain invalid characters"
276
+ })
277
+ });
278
+
279
+ // src/schemas/business/business-vat-remove-schema.js
280
+ var businessVatRemoveSchema = Joi.object({
281
+ confirmRemove: Joi.string().valid("yes", "no").required().messages({
282
+ "any.required": "Select yes if you want to remove your VAT registration number",
283
+ "any.only": "Select yes if you want to remove your VAT registration number"
284
+ })
285
+ });
286
+
269
287
  // src/schemas/business/business-schemas.js
270
288
  var businessSchemas = {
271
289
  sbi: businessSbiSchema,
@@ -275,6 +293,10 @@ var businessSchemas = {
275
293
  phone: businessPhoneSchema,
276
294
  email: businessEmailSchema,
277
295
  vat: businessVatSchema
296
+ },
297
+ vat: {
298
+ change: businessVatChangeSchema,
299
+ remove: businessVatRemoveSchema
278
300
  }
279
301
  };
280
302
 
@@ -503,11 +525,60 @@ var personalSchemas = {
503
525
  email: personalEmailSchema
504
526
  };
505
527
 
528
+ // src/schemas/os-places/address-lookup-schema.js
529
+ var addressLookupSchema = Joi.object({
530
+ properties: Joi.object({
531
+ UPRN: Joi.string().required(),
532
+ ADDRESS: Joi.string().required(),
533
+ ORGANISATION_NAME: Joi.string().allow(null),
534
+ DEPARTMENT_NAME: Joi.string().allow(null),
535
+ SUB_BUILDING_NAME: Joi.string().allow(null),
536
+ BUILDING_NAME: Joi.string().allow(null),
537
+ BUILDING_NUMBER: Joi.string().allow(null),
538
+ DEPENDENT_THOROUGHFARE_NAME: Joi.string().allow(null),
539
+ THOROUGHFARE_NAME: Joi.string().allow(null),
540
+ DOUBLE_DEPENDENT_LOCALITY: Joi.string().allow(null),
541
+ DEPENDENT_LOCALITY: Joi.string().allow(null),
542
+ POST_TOWN: Joi.string().required(),
543
+ POSTCODE: Joi.string().required(),
544
+ LOCAL_CUSTODIAN_CODE_DESCRIPTION: Joi.string().allow(null),
545
+ COUNTRY_CODE: Joi.string().required()
546
+ }).unknown(true).required()
547
+ }).unknown(true);
548
+
549
+ // src/schemas/os-places/addresses-schema.js
550
+ var CHOOSE_ADDRESS_ERROR = "Choose an address";
551
+ var addressesSchema = Joi.object({
552
+ addresses: Joi.string().invalid("display").required().messages({
553
+ "any.required": CHOOSE_ADDRESS_ERROR,
554
+ "string.empty": CHOOSE_ADDRESS_ERROR,
555
+ "any.invalid": CHOOSE_ADDRESS_ERROR
556
+ })
557
+ });
558
+
559
+ // src/schemas/os-places/uk-postcode-schema.js
560
+ var ukPostcodeSchema = Joi.object({
561
+ postcode: Joi.string().trim().required().uppercase().max(POSTCODE_MAX).pattern(/^([A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}|GIR ?0A{2})$/).messages({
562
+ "any.required": "Enter a postcode",
563
+ "string.empty": "Enter a postcode",
564
+ "string.max": `Postal code must be ${POSTCODE_MAX} characters or less`,
565
+ "string.pattern.base": "Enter a full UK postcode, like AA3 1AB"
566
+ })
567
+ });
568
+
569
+ // src/schemas/os-places/os-places-schemas.js
570
+ var osPlacesSchemas = {
571
+ addressLookup: addressLookupSchema,
572
+ addresses: addressesSchema,
573
+ ukPostcode: ukPostcodeSchema
574
+ };
575
+
506
576
  // src/schemas/schemas.js
507
577
  var schemas = {
508
578
  business: businessSchemas,
509
579
  customer: customerSchemas,
510
- personal: personalSchemas
580
+ personal: personalSchemas,
581
+ osPlaces: osPlacesSchemas
511
582
  };
512
583
 
513
584
  // src/utils/format-validation-errors.js
package/dist/index.js CHANGED
@@ -227,6 +227,24 @@ var businessVatSchema = Joi.object({
227
227
  })
228
228
  });
229
229
 
230
+ // src/schemas/business/business-vat-change-schema.js
231
+ var businessVatChangeSchema = Joi.object({
232
+ vatNumber: Joi.string().pattern(/^\d{9}$/).required().messages({
233
+ "string.pattern.base": "Enter a VAT registration number, like 123456789",
234
+ "string.empty": "Enter a VAT registration number",
235
+ "any.required": "Enter a VAT registration number",
236
+ "string.noControlChars": "VAT registration number must not contain invalid characters"
237
+ })
238
+ });
239
+
240
+ // src/schemas/business/business-vat-remove-schema.js
241
+ var businessVatRemoveSchema = Joi.object({
242
+ confirmRemove: Joi.string().valid("yes", "no").required().messages({
243
+ "any.required": "Select yes if you want to remove your VAT registration number",
244
+ "any.only": "Select yes if you want to remove your VAT registration number"
245
+ })
246
+ });
247
+
230
248
  // src/schemas/business/business-schemas.js
231
249
  var businessSchemas = {
232
250
  sbi: businessSbiSchema,
@@ -236,6 +254,10 @@ var businessSchemas = {
236
254
  phone: businessPhoneSchema,
237
255
  email: businessEmailSchema,
238
256
  vat: businessVatSchema
257
+ },
258
+ vat: {
259
+ change: businessVatChangeSchema,
260
+ remove: businessVatRemoveSchema
239
261
  }
240
262
  };
241
263
 
@@ -464,11 +486,60 @@ var personalSchemas = {
464
486
  email: personalEmailSchema
465
487
  };
466
488
 
489
+ // src/schemas/os-places/address-lookup-schema.js
490
+ var addressLookupSchema = Joi.object({
491
+ properties: Joi.object({
492
+ UPRN: Joi.string().required(),
493
+ ADDRESS: Joi.string().required(),
494
+ ORGANISATION_NAME: Joi.string().allow(null),
495
+ DEPARTMENT_NAME: Joi.string().allow(null),
496
+ SUB_BUILDING_NAME: Joi.string().allow(null),
497
+ BUILDING_NAME: Joi.string().allow(null),
498
+ BUILDING_NUMBER: Joi.string().allow(null),
499
+ DEPENDENT_THOROUGHFARE_NAME: Joi.string().allow(null),
500
+ THOROUGHFARE_NAME: Joi.string().allow(null),
501
+ DOUBLE_DEPENDENT_LOCALITY: Joi.string().allow(null),
502
+ DEPENDENT_LOCALITY: Joi.string().allow(null),
503
+ POST_TOWN: Joi.string().required(),
504
+ POSTCODE: Joi.string().required(),
505
+ LOCAL_CUSTODIAN_CODE_DESCRIPTION: Joi.string().allow(null),
506
+ COUNTRY_CODE: Joi.string().required()
507
+ }).unknown(true).required()
508
+ }).unknown(true);
509
+
510
+ // src/schemas/os-places/addresses-schema.js
511
+ var CHOOSE_ADDRESS_ERROR = "Choose an address";
512
+ var addressesSchema = Joi.object({
513
+ addresses: Joi.string().invalid("display").required().messages({
514
+ "any.required": CHOOSE_ADDRESS_ERROR,
515
+ "string.empty": CHOOSE_ADDRESS_ERROR,
516
+ "any.invalid": CHOOSE_ADDRESS_ERROR
517
+ })
518
+ });
519
+
520
+ // src/schemas/os-places/uk-postcode-schema.js
521
+ var ukPostcodeSchema = Joi.object({
522
+ postcode: Joi.string().trim().required().uppercase().max(POSTCODE_MAX).pattern(/^([A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}|GIR ?0A{2})$/).messages({
523
+ "any.required": "Enter a postcode",
524
+ "string.empty": "Enter a postcode",
525
+ "string.max": `Postal code must be ${POSTCODE_MAX} characters or less`,
526
+ "string.pattern.base": "Enter a full UK postcode, like AA3 1AB"
527
+ })
528
+ });
529
+
530
+ // src/schemas/os-places/os-places-schemas.js
531
+ var osPlacesSchemas = {
532
+ addressLookup: addressLookupSchema,
533
+ addresses: addressesSchema,
534
+ ukPostcode: ukPostcodeSchema
535
+ };
536
+
467
537
  // src/schemas/schemas.js
468
538
  var schemas = {
469
539
  business: businessSchemas,
470
540
  customer: customerSchemas,
471
- personal: personalSchemas
541
+ personal: personalSchemas,
542
+ osPlaces: osPlacesSchemas
472
543
  };
473
544
 
474
545
  // src/utils/format-validation-errors.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.8.6",
3
+ "version": "0.9.1",
4
4
  "description": "Shared frontend engine used by both the internal and external frontend applications.",
5
5
  "main": "./dist/index.cjs",
6
6
  "exports": {
@@ -4,12 +4,23 @@ import { businessNameSchema } from './business-name-schema.js'
4
4
  import { businessEmailSchema } from './business-email-schema.js'
5
5
  import { businessPhoneSchema } from './business-phone-schema.js'
6
6
  import { businessVatSchema } from './business-vat-schema.js'
7
+ import { businessVatChangeSchema } from './business-vat-change-schema.js'
8
+ import { businessVatRemoveSchema } from './business-vat-remove-schema.js'
7
9
 
8
10
  /**
9
11
  * The businessSchema object has a nested property of `details`.
10
12
  * This is due to the interrupter journey. The journey required the business details to be validated in a single step,
11
13
  * these include name, address, phone, email and vat. The `details` property is used to group these schemas together.
12
14
  * The `sbi` property is separate as it is validated in a different step of the journey.
15
+ *
16
+ * The `vat` property groups the schemas for the standalone VAT action pages:
17
+ * - `vat.change` validates the dedicated VAT change page where a VAT registration number is mandatory
18
+ * (9 digits, `.required()`), so it is deliberately separate from `details.vat`.
19
+ * - `vat.remove` validates the VAT removal confirmation page (yes/no).
20
+ *
21
+ * Note `details.vat` and `vat.change` are two distinct validation contexts for the same field: within the
22
+ * interrupter `details` set VAT is optional and an empty string is allowed, whereas on the dedicated change
23
+ * page a valid VAT number must be entered (removal is handled by its own journey).
13
24
  */
14
25
  export const businessSchemas = {
15
26
  sbi: businessSbiSchema,
@@ -19,5 +30,9 @@ export const businessSchemas = {
19
30
  phone: businessPhoneSchema,
20
31
  email: businessEmailSchema,
21
32
  vat: businessVatSchema
33
+ },
34
+ vat: {
35
+ change: businessVatChangeSchema,
36
+ remove: businessVatRemoveSchema
22
37
  }
23
38
  }
@@ -0,0 +1,13 @@
1
+ import { Joi } from '../../utils/joi.js'
2
+
3
+ export const businessVatChangeSchema = Joi.object({
4
+ vatNumber: Joi.string()
5
+ .pattern(/^\d{9}$/)
6
+ .required()
7
+ .messages({
8
+ 'string.pattern.base': 'Enter a VAT registration number, like 123456789',
9
+ 'string.empty': 'Enter a VAT registration number',
10
+ 'any.required': 'Enter a VAT registration number',
11
+ 'string.noControlChars': 'VAT registration number must not contain invalid characters'
12
+ })
13
+ })
@@ -0,0 +1,11 @@
1
+ import { Joi } from '../../utils/joi.js'
2
+
3
+ export const businessVatRemoveSchema = Joi.object({
4
+ confirmRemove: Joi.string()
5
+ .valid('yes', 'no')
6
+ .required()
7
+ .messages({
8
+ 'any.required': 'Select yes if you want to remove your VAT registration number',
9
+ 'any.only': 'Select yes if you want to remove your VAT registration number'
10
+ })
11
+ })
@@ -0,0 +1,21 @@
1
+ import { Joi } from '../../utils/joi.js'
2
+
3
+ export const addressLookupSchema = Joi.object({
4
+ properties: Joi.object({
5
+ UPRN: Joi.string().required(),
6
+ ADDRESS: Joi.string().required(),
7
+ ORGANISATION_NAME: Joi.string().allow(null),
8
+ DEPARTMENT_NAME: Joi.string().allow(null),
9
+ SUB_BUILDING_NAME: Joi.string().allow(null),
10
+ BUILDING_NAME: Joi.string().allow(null),
11
+ BUILDING_NUMBER: Joi.string().allow(null),
12
+ DEPENDENT_THOROUGHFARE_NAME: Joi.string().allow(null),
13
+ THOROUGHFARE_NAME: Joi.string().allow(null),
14
+ DOUBLE_DEPENDENT_LOCALITY: Joi.string().allow(null),
15
+ DEPENDENT_LOCALITY: Joi.string().allow(null),
16
+ POST_TOWN: Joi.string().required(),
17
+ POSTCODE: Joi.string().required(),
18
+ LOCAL_CUSTODIAN_CODE_DESCRIPTION: Joi.string().allow(null),
19
+ COUNTRY_CODE: Joi.string().required()
20
+ }).unknown(true).required()
21
+ }).unknown(true)
@@ -0,0 +1,14 @@
1
+ import { Joi } from '../../utils/joi.js'
2
+
3
+ const CHOOSE_ADDRESS_ERROR = 'Choose an address'
4
+
5
+ export const addressesSchema = Joi.object({
6
+ addresses: Joi.string()
7
+ .invalid('display')
8
+ .required()
9
+ .messages({
10
+ 'any.required': CHOOSE_ADDRESS_ERROR,
11
+ 'string.empty': CHOOSE_ADDRESS_ERROR,
12
+ 'any.invalid': CHOOSE_ADDRESS_ERROR
13
+ })
14
+ })
@@ -0,0 +1,9 @@
1
+ import { addressLookupSchema } from './address-lookup-schema.js'
2
+ import { addressesSchema } from './addresses-schema.js'
3
+ import { ukPostcodeSchema } from './uk-postcode-schema.js'
4
+
5
+ export const osPlacesSchemas = {
6
+ addressLookup: addressLookupSchema,
7
+ addresses: addressesSchema,
8
+ ukPostcode: ukPostcodeSchema
9
+ }
@@ -0,0 +1,17 @@
1
+ import { Joi } from '../../utils/joi.js'
2
+ import { POSTCODE_MAX } from '../../constants/validation-fields.js'
3
+
4
+ export const ukPostcodeSchema = Joi.object({
5
+ postcode: Joi.string()
6
+ .trim()
7
+ .required()
8
+ .uppercase()
9
+ .max(POSTCODE_MAX)
10
+ .pattern(/^([A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}|GIR ?0A{2})$/)
11
+ .messages({
12
+ 'any.required': 'Enter a postcode',
13
+ 'string.empty': 'Enter a postcode',
14
+ 'string.max': `Postal code must be ${POSTCODE_MAX} characters or less`,
15
+ 'string.pattern.base': 'Enter a full UK postcode, like AA3 1AB'
16
+ })
17
+ })
@@ -1,9 +1,11 @@
1
1
  import { businessSchemas } from './business/business-schemas.js'
2
2
  import { customerSchemas } from './customer/customer-schemas.js'
3
3
  import { personalSchemas } from './personal/personal-schemas.js'
4
+ import { osPlacesSchemas } from './os-places/os-places-schemas.js'
4
5
 
5
6
  export const schemas = {
6
7
  business: businessSchemas,
7
8
  customer: customerSchemas,
8
- personal: personalSchemas
9
+ personal: personalSchemas,
10
+ osPlaces: osPlacesSchemas
9
11
  }