@defra/land-grants-contract-schemas 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ import Joi from 'joi'
2
+
3
+ const applicationValidationResponseSchemaV2 = Joi.object({
4
+ message: Joi.string().required(),
5
+ id: Joi.number().integer().required(),
6
+ actions: Joi.array().items(
7
+ Joi.object({
8
+ actionCode: Joi.string().required(),
9
+ description: Joi.string(),
10
+ sheetId: Joi.string().required(),
11
+ parcelId: Joi.string().required(),
12
+ hasPassed: Joi.boolean().required(),
13
+ version: Joi.string().required(),
14
+ rules: Joi.array().items(
15
+ Joi.object({
16
+ name: Joi.string().required(),
17
+ passed: Joi.boolean().required(),
18
+ reason: Joi.string(),
19
+ description: Joi.string(),
20
+ explanations: Joi.array().items(
21
+ Joi.object({
22
+ title: Joi.string().required(),
23
+ lines: Joi.array().items(Joi.string())
24
+ })
25
+ ),
26
+ caveat: Joi.object({
27
+ code: Joi.string().required(),
28
+ description: Joi.string().required(),
29
+ metadata: Joi.object({
30
+ actionCode: Joi.string().required(),
31
+ parcelId: Joi.string().required(),
32
+ sheetId: Joi.string().required(),
33
+ percentageOverlap: Joi.number().optional(),
34
+ overlapAreaHectares: Joi.number().optional(),
35
+ overlapLengthMeters: Joi.number().integer().optional(),
36
+ boundaryLengthMeters: Joi.number().integer().optional()
37
+ })
38
+ })
39
+ })
40
+ )
41
+ })
42
+ ),
43
+ valid: Joi.boolean().required()
44
+ })
45
+
46
+ export { applicationValidationResponseSchemaV2 }
@@ -0,0 +1,75 @@
1
+ import Joi from 'joi'
2
+
3
+ const applicationValidationSchema = Joi.object({
4
+ applicationId: Joi.string().required(),
5
+ requester: Joi.string().required(),
6
+ applicantCrn: Joi.string().required(),
7
+ sbi: Joi.string().required(),
8
+ landActions: Joi.array()
9
+ .items(
10
+ Joi.object({
11
+ sheetId: Joi.string().required(),
12
+ parcelId: Joi.string().required(),
13
+ actions: Joi.array()
14
+ .items(
15
+ Joi.object({
16
+ code: Joi.string().required(),
17
+ quantity: Joi.number().positive().required(),
18
+ version: Joi.string().optional()
19
+ })
20
+ )
21
+ .required()
22
+ })
23
+ )
24
+ .min(1)
25
+ .required()
26
+ })
27
+
28
+ const applicationValidationRunSchema = Joi.object({
29
+ id: Joi.number().integer().required(),
30
+ application_id: Joi.string().required(),
31
+ sbi: Joi.string().required(),
32
+ crn: Joi.string().required(),
33
+ data: Joi.object().required(),
34
+ created_at: Joi.date().required()
35
+ })
36
+
37
+ const applicationValidationRunResponseSchema = Joi.object({
38
+ message: Joi.string().required(),
39
+ applicationValidationRun: applicationValidationRunSchema
40
+ })
41
+
42
+ const applicationValidationRunRequestSchema = Joi.object({
43
+ id: Joi.number().integer().required()
44
+ })
45
+
46
+ const applicationValidationRunsRequestSchema = Joi.object({
47
+ applicationId: Joi.string().required()
48
+ })
49
+
50
+ const applicationValidationRunsBodyRequestSchema = Joi.object({
51
+ fields: Joi.array().items(Joi.string().valid('details')).required()
52
+ })
53
+
54
+ const applicationValidationRunsResponseSchema = Joi.alternatives(
55
+ Joi.object({
56
+ message: Joi.string().required(),
57
+ applicationValidationRuns: Joi.array().items(applicationValidationRunSchema)
58
+ }),
59
+ Joi.object({
60
+ message: Joi.string().required(),
61
+ applicationValidationRuns: Joi.array().items({
62
+ id: Joi.number().integer().required(),
63
+ created_at: Joi.date().required()
64
+ })
65
+ })
66
+ )
67
+
68
+ export {
69
+ applicationValidationSchema,
70
+ applicationValidationRunRequestSchema,
71
+ applicationValidationRunResponseSchema,
72
+ applicationValidationRunsRequestSchema,
73
+ applicationValidationRunsResponseSchema,
74
+ applicationValidationRunsBodyRequestSchema
75
+ }
@@ -0,0 +1,83 @@
1
+ import Joi from 'joi'
2
+
3
+ const caseManagementApplicationValidationRunRequestSchema = Joi.object({
4
+ id: Joi.number().integer().required()
5
+ })
6
+
7
+ const MIN_LEVEL = 1
8
+ const MAX_LEVEL = 6
9
+
10
+ // Schema for paragraph component
11
+ const paragraphComponentSchema = Joi.object({
12
+ component: Joi.string().valid('paragraph').required(),
13
+ text: Joi.string().allow('').required()
14
+ })
15
+
16
+ // Schema for status component
17
+ const statusComponentSchema = Joi.object({
18
+ component: Joi.string().valid('status').required(),
19
+ text: Joi.string().required(),
20
+ colour: Joi.string()
21
+ .valid('red', 'green', 'yellow', 'blue', 'grey')
22
+ .required(),
23
+ classes: Joi.string().optional()
24
+ })
25
+
26
+ // Schema for heading component
27
+ const headingComponentSchema = Joi.object({
28
+ component: Joi.string().valid('heading').required(),
29
+ text: Joi.string().required(),
30
+ level: Joi.number().integer().min(MIN_LEVEL).max(MAX_LEVEL).required(),
31
+ id: Joi.string().optional()
32
+ })
33
+
34
+ // Schema for summary items (can be text items or status components)
35
+ const summaryItemSchema = Joi.alternatives().try(
36
+ Joi.object({
37
+ text: Joi.string().required(),
38
+ classes: Joi.string().required()
39
+ }),
40
+ statusComponentSchema
41
+ )
42
+
43
+ // Forward reference for details component (for recursive structure)
44
+ const detailsComponentSchema = Joi.object({
45
+ component: Joi.string().valid('details').required(),
46
+ summaryItems: Joi.array().items(summaryItemSchema).min(MIN_LEVEL).required(),
47
+ items: Joi.array().items(Joi.link('#component')).required()
48
+ }).id('details')
49
+
50
+ // Combined component schema (for use in details items)
51
+ const componentSchema = Joi.alternatives()
52
+ .try(
53
+ paragraphComponentSchema,
54
+ headingComponentSchema,
55
+ detailsComponentSchema,
56
+ statusComponentSchema
57
+ )
58
+ .id('component')
59
+
60
+ // Response schema for application validation run
61
+ const caseManagementApplicationValidationRunResponseSchema = Joi.object({
62
+ message: Joi.string().required(),
63
+ response: Joi.array().items(componentSchema).required()
64
+ })
65
+
66
+ const caseManagementApplicationValidationRerunRequestSchema = Joi.object({
67
+ requesterUsername: Joi.string().required(),
68
+ id: Joi.number().integer().required()
69
+ })
70
+
71
+ const caseManagementApplicationValidationReRunResponseSchema = Joi.object({
72
+ message: Joi.string().required(),
73
+ valid: Joi.boolean().required(),
74
+ id: Joi.number().integer().required(),
75
+ date: Joi.date().required()
76
+ })
77
+
78
+ export {
79
+ caseManagementApplicationValidationRunRequestSchema,
80
+ caseManagementApplicationValidationRunResponseSchema,
81
+ caseManagementApplicationValidationRerunRequestSchema,
82
+ caseManagementApplicationValidationReRunResponseSchema
83
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @typedef {Record<string, number>} StatusCodes
3
+ */
4
+ export const statusCodes = {
5
+ ok: 200,
6
+ noContent: 204,
7
+ badRequest: 400,
8
+ unauthorized: 401,
9
+ forbidden: 403,
10
+ notFound: 404,
11
+ imATeapot: 418,
12
+ unprocessableEntity: 422,
13
+ internalServerError: 500
14
+ }
@@ -0,0 +1,26 @@
1
+ export const HECTARES = 'ha'
2
+ export const COUNT = 'count'
3
+ export const METERS = 'm'
4
+ export const SQM = 'sqm'
5
+
6
+ export const UNIT_TYPES = [HECTARES, SQM, METERS, COUNT]
7
+
8
+ // Unit which must be integers
9
+ export const INTEGER_UNITS = [SQM, METERS, COUNT]
10
+
11
+ // Land area reaches us as sqm on agreements and as ha on planned actions
12
+ const AREA_UNITS = new Set([HECTARES, SQM])
13
+
14
+ /**
15
+ * Whether a quantity in this unit competes for a parcel's land area
16
+ * @param {string|undefined} unit
17
+ * @returns {boolean}
18
+ */
19
+ export const isAreaUnit = (unit) => AREA_UNITS.has(unit ?? '')
20
+
21
+ /**
22
+ * Whether a quantity in this unit competes for a parcel's boundary
23
+ * @param {string|undefined} unit
24
+ * @returns {boolean}
25
+ */
26
+ export const isLengthUnit = (unit) => unit === METERS
@@ -0,0 +1,52 @@
1
+ import Joi from 'joi'
2
+ import { statusCodes } from '../constants/status-codes.js'
3
+
4
+ /**
5
+ * @typedef {object} ErrorResponseSchema
6
+ * @property {number} statusCode
7
+ * @property {string} error
8
+ * @property {string} message
9
+ */
10
+ const errorResponseSchema = Joi.object({
11
+ statusCode: Joi.number().valid(statusCodes.notFound).required(),
12
+ error: Joi.string().required(),
13
+ message: Joi.string().required()
14
+ }).label('errorResponse')
15
+
16
+ /**
17
+ * @typedef {object} InternalServerErrorResponseSchema
18
+ * @property {number} statusCode
19
+ * @property {string} error
20
+ * @property {string} message
21
+ */
22
+ /**
23
+ * @typedef {object} UnprocessableEntityResponseSchema
24
+ * @property {number} statusCode
25
+ * @property {string} error
26
+ * @property {string} message
27
+ */
28
+ const badRequestResponseSchema = Joi.object({
29
+ statusCode: Joi.number().valid(statusCodes.badRequest).required(),
30
+ error: Joi.string().required(),
31
+ message: Joi.string().required(),
32
+ validation: Joi.object().optional()
33
+ }).label('badRequestResponse')
34
+
35
+ const unprocessableEntityResponseSchema = Joi.object({
36
+ statusCode: Joi.number().valid(statusCodes.unprocessableEntity).required(),
37
+ error: Joi.string().required(),
38
+ message: Joi.string().required()
39
+ }).label('unprocessableEntityResponse')
40
+
41
+ const internalServerErrorResponseSchema = Joi.object({
42
+ statusCode: Joi.number().valid(statusCodes.internalServerError).required(),
43
+ error: Joi.string().required(),
44
+ message: Joi.string().required()
45
+ }).label('internalServerErrorResponse')
46
+
47
+ export {
48
+ badRequestResponseSchema,
49
+ errorResponseSchema,
50
+ unprocessableEntityResponseSchema,
51
+ internalServerErrorResponseSchema
52
+ }
@@ -0,0 +1,30 @@
1
+ import Joi from 'joi'
2
+
3
+ export const statusIngestQuery = Joi.object({
4
+ ingestId: Joi.number().optional(),
5
+ filename: Joi.string().optional()
6
+ }).with('filename', 'ingestId')
7
+
8
+ const statusFileResponseSchema = Joi.object({
9
+ id: Joi.number().required(),
10
+ ingest_id: Joi.number().required(),
11
+ filename: Joi.string().required(),
12
+ total_rows: Joi.number().required(),
13
+ status: Joi.string().required()
14
+ })
15
+
16
+ const statusIngestResponseSchema = Joi.object({
17
+ id: Joi.number().required(),
18
+ entity: Joi.string().required(),
19
+ status: Joi.string().required(),
20
+ start_date: Joi.date().required(),
21
+ staged_date: Joi.date().allow(null).optional(),
22
+ completed_date: Joi.date().allow(null).optional(),
23
+ files: Joi.array().items(statusFileResponseSchema).optional()
24
+ })
25
+
26
+ export const statusResponseSchema = Joi.alternatives().try(
27
+ statusIngestResponseSchema,
28
+ statusFileResponseSchema,
29
+ Joi.array().items(statusIngestResponseSchema)
30
+ )
@@ -0,0 +1,21 @@
1
+ // Why an action cannot be applied for on a parcel at all, as opposed to a
2
+ // validation failure or a caveat, both of which presume the applicant has
3
+ // already chosen it. The code is the contract; grants-ui may key its own copy
4
+ // off it rather than show the reason text.
5
+ export const EXISTING_ACTIONS_DO_NOT_FIT = 'existing-actions-do-not-fit'
6
+ export const RULE_FAILED = 'rule-failed'
7
+ export const NO_AVAILABILITY = 'no-availability'
8
+
9
+ export const UNAVAILABLE_REASON_CODES = [
10
+ EXISTING_ACTIONS_DO_NOT_FIT,
11
+ RULE_FAILED,
12
+ NO_AVAILABILITY
13
+ ]
14
+
15
+ export const EXISTING_ACTIONS_DO_NOT_FIT_REASON =
16
+ 'Your existing actions do not fit on this land parcel. Please contact the RPA to resolve this.'
17
+ export const EXISTING_ACTIONS_DO_NOT_FIT_ON_LENGTH_REASON =
18
+ 'Your existing actions do not fit on the available length for this land parcel. Please contact the RPA to resolve this.'
19
+
20
+ export const NO_AVAILABILITY_REASON =
21
+ 'There is no remaining availability for this action'
@@ -0,0 +1,85 @@
1
+ import Joi from 'joi'
2
+ import { isAreaUnit } from '../../../common/constants/unit_type.js'
3
+ import {
4
+ actionSchema,
5
+ parcelIdSchema,
6
+ plannedActionsSchema
7
+ } from './parcel.schema.js'
8
+
9
+ /**
10
+ * The base action must be in the planned actions, which give its area, as an
11
+ * area greater than zero, and so must the base action each planned supplement
12
+ * sits on.
13
+ * @param {{baseActionCode: string, plannedActions: PlannedAction[]}} payload - The request payload
14
+ * @param {Joi.CustomHelpers} helpers - Joi's helpers
15
+ * @returns {object | Joi.ErrorReport} The payload, or why it is invalid
16
+ */
17
+ const validateBaseAction = (payload, helpers) => {
18
+ const { baseActionCode, plannedActions } = payload
19
+ const planned = plannedActions.find((p) => p.actionCode === baseActionCode)
20
+
21
+ if (!planned) {
22
+ return helpers.message({
23
+ custom: `Base action missing from plannedActions: ${baseActionCode}`
24
+ })
25
+ }
26
+
27
+ if (!isAreaUnit(planned.unit) || planned.quantity <= 0) {
28
+ return helpers.message({
29
+ custom: `Base action must be given as an area greater than zero, in ha or sqm: ${baseActionCode}`
30
+ })
31
+ }
32
+
33
+ const unplannedBase = plannedActions.find(
34
+ (p) =>
35
+ p.baseActionCode !== undefined &&
36
+ !plannedActions.some((other) => other.actionCode === p.baseActionCode)
37
+ )
38
+
39
+ if (unplannedBase) {
40
+ return helpers.message({
41
+ custom: `${unplannedBase.actionCode}'s baseActionCode ${unplannedBase.baseActionCode} is not in plannedActions`
42
+ })
43
+ }
44
+
45
+ return payload
46
+ }
47
+
48
+ const parcelSupplementsSchema = Joi.object({
49
+ sbi: Joi.string()
50
+ .required()
51
+ .description(
52
+ 'The business, whose existing agreements on the parcel use up land'
53
+ ),
54
+ parcelId: parcelIdSchema.required(),
55
+ baseActionCode: Joi.string()
56
+ .required()
57
+ .description(
58
+ 'The selected base action to list the supplements of. It must be in plannedActions, which gives its area.'
59
+ ),
60
+ plannedActions: plannedActionsSchema
61
+ .required()
62
+ .description(
63
+ 'Every action selected on the parcel so far: the base actions, the other actions and the supplements selected, each supplement with the base action it sits on (baseActionCode)'
64
+ )
65
+ }).custom(validateBaseAction)
66
+
67
+ // Supplements are reported as the parcels endpoint reports actions, without
68
+ // the flag for their own supplements
69
+ const supplementSchema = actionSchema.keys({
70
+ hasSupplements: Joi.any().forbidden()
71
+ })
72
+
73
+ const parcelSupplementsSuccessResponseSchema = Joi.object({
74
+ message: Joi.string().valid('success').required(),
75
+ parcelId: Joi.string().required(),
76
+ sheetId: Joi.string().required(),
77
+ baseActionCode: Joi.string().required(),
78
+ supplements: Joi.array().items(supplementSchema).required()
79
+ })
80
+
81
+ export { parcelSupplementsSchema, parcelSupplementsSuccessResponseSchema }
82
+
83
+ /**
84
+ * @typedef {{actionCode: string, quantity: number, unit: string, baseActionCode?: string}} PlannedAction
85
+ */
@@ -0,0 +1,108 @@
1
+ import Joi from 'joi'
2
+ import { COUNT, UNIT_TYPES } from '../../../common/constants/unit_type.js'
3
+ import { UNAVAILABLE_REASON_CODES } from '../../constants/unavailable-reasons.js'
4
+
5
+ export const parcelIdSchema = Joi.string().pattern(/^[A-Za-z0-9]{6}-[0-9]{4}$/)
6
+
7
+ export const actionAvailabilitySchema = Joi.object({
8
+ unit: Joi.string().required(),
9
+ value: Joi.number()
10
+ .allow(null)
11
+ .required()
12
+ .when(Joi.ref('unit'), {
13
+ is: Joi.allow(COUNT).only(),
14
+ then: Joi.number().integer()
15
+ })
16
+ })
17
+
18
+ const unavailableReasonSchema = Joi.object({
19
+ code: Joi.string()
20
+ .valid(...UNAVAILABLE_REASON_CODES)
21
+ .required(),
22
+ reason: Joi.string().required(),
23
+ metadata: Joi.object().optional()
24
+ })
25
+
26
+ export const actionSchema = Joi.object({
27
+ code: Joi.string().required(),
28
+ description: Joi.string().required(),
29
+ results: Joi.object({
30
+ totalValidLandCoverSqm: Joi.number().optional(),
31
+ stacks: Joi.array().optional(),
32
+ explanations: Joi.array().optional()
33
+ }),
34
+ ratePerUnitGbp: Joi.number().required(),
35
+ ratePerAgreementPerYearGbp: Joi.number().optional(),
36
+ sssiConsentRequired: Joi.boolean().optional(),
37
+ heferRequired: Joi.boolean().optional(),
38
+ version: Joi.string().optional(),
39
+ guidanceUrl: Joi.string().uri().optional(),
40
+ availability: actionAvailabilitySchema.optional(),
41
+ isAvailable: Joi.boolean().required(),
42
+ hasSupplements: Joi.boolean()
43
+ .required()
44
+ .description(
45
+ 'Whether the action has supplementary actions, so the parcels-supplements endpoint can be called for it'
46
+ ),
47
+ unavailableReason: unavailableReasonSchema.optional(),
48
+ quantityRequired: Joi.boolean().required(),
49
+ displayUnit: Joi.string().allow(null).optional(),
50
+ displayUnitPlural: Joi.string().allow(null).optional()
51
+ })
52
+
53
+ const parcelSchema = Joi.object({
54
+ parcelId: Joi.string().required(),
55
+ sheetId: Joi.string().required(),
56
+ size: Joi.object({
57
+ unit: Joi.string().required(),
58
+ value: Joi.number().required()
59
+ }).optional(),
60
+ actions: Joi.array().items(actionSchema).optional()
61
+ })
62
+
63
+ // The actions the applicant has already selected on the parcel
64
+ export const plannedActionsSchema = Joi.array()
65
+ .items(
66
+ Joi.object({
67
+ actionCode: Joi.string().required(),
68
+ quantity: Joi.number().required(),
69
+ unit: Joi.string()
70
+ .valid(...UNIT_TYPES)
71
+ .required(),
72
+ baseActionCode: Joi.string()
73
+ .optional()
74
+ .description('For a supplement, the base action it sits on')
75
+ })
76
+ )
77
+ .optional()
78
+
79
+ const parcelsSchema = Joi.object({
80
+ sbi: Joi.string().required(),
81
+ parcelIds: Joi.array().items(parcelIdSchema).required(),
82
+ fields: Joi.array()
83
+ .items(
84
+ Joi.string().valid(
85
+ 'size',
86
+ 'actions',
87
+ 'actions.results',
88
+ 'actions.sssiConsentRequired',
89
+ 'actions.heferRequired',
90
+ 'groups'
91
+ )
92
+ )
93
+ .required(),
94
+ plannedActions: plannedActionsSchema
95
+ })
96
+
97
+ const groupSchema = Joi.object({
98
+ name: Joi.string().required(),
99
+ actions: Joi.array().items(Joi.string()).required()
100
+ })
101
+
102
+ const parcelsSuccessResponseSchema = Joi.object({
103
+ message: Joi.string().valid('success').required(),
104
+ parcels: Joi.array().items(parcelSchema).required(),
105
+ groups: Joi.array().items(groupSchema).optional()
106
+ })
107
+
108
+ export { parcelsSchema, parcelsSuccessResponseSchema }
@@ -0,0 +1,98 @@
1
+ import Joi from 'joi'
2
+
3
+ const PaymentsSchema = Joi.array()
4
+ .items(
5
+ Joi.object({
6
+ totalPaymentPence: Joi.number().integer().min(0),
7
+ paymentDate: Joi.string(),
8
+ lineItems: Joi.array().items(
9
+ Joi.object({
10
+ parcelItemId: Joi.number().integer().optional(),
11
+ agreementLevelItemId: Joi.number().integer().optional(),
12
+ paymentPence: Joi.number().integer()
13
+ })
14
+ )
15
+ })
16
+ )
17
+ .min(1)
18
+ .required()
19
+
20
+ const ExplanationsSchema = Joi.array().items(
21
+ Joi.object({
22
+ title: Joi.string().required(),
23
+ content: Joi.array().items(Joi.string()).required()
24
+ })
25
+ )
26
+
27
+ const PaymentCalculateSchema = Joi.object({
28
+ startDate: Joi.date().optional(),
29
+ sbi: Joi.string().optional(),
30
+ applicationId: Joi.string().optional(),
31
+ parcel: Joi.array()
32
+ .items(
33
+ Joi.object({
34
+ sheetId: Joi.string().required(),
35
+ parcelId: Joi.string().required(),
36
+ actions: Joi.array()
37
+ .items(
38
+ Joi.object({
39
+ code: Joi.string().required(),
40
+ quantity: Joi.number().positive().required(),
41
+ version: Joi.string().optional()
42
+ })
43
+ )
44
+ .required()
45
+ })
46
+ )
47
+ .required()
48
+ })
49
+
50
+ const parcelItemsSchemaV2 = Joi.object()
51
+ .pattern(
52
+ Joi.number().integer(),
53
+ Joi.object({
54
+ code: Joi.string(),
55
+ description: Joi.string(),
56
+ version: Joi.string(),
57
+ unit: Joi.string(),
58
+ quantity: Joi.number(),
59
+ rateInPence: Joi.number().integer(),
60
+ annualPaymentPence: Joi.number().integer(),
61
+ durationYears: Joi.number().integer(),
62
+ sheetId: Joi.string(),
63
+ parcelId: Joi.string()
64
+ })
65
+ )
66
+ .optional()
67
+
68
+ const agreementLevelItemsSchemaV2 = Joi.object()
69
+ .pattern(
70
+ Joi.number().integer(),
71
+ Joi.object({
72
+ code: Joi.string(),
73
+ description: Joi.string(),
74
+ durationYears: Joi.number().integer(),
75
+ version: Joi.string(),
76
+ annualPaymentPence: Joi.number().integer()
77
+ })
78
+ )
79
+ .optional()
80
+
81
+ const PaymentCalculateResponseSchemaV2 = Joi.object({
82
+ message: Joi.string().required(),
83
+ payment: Joi.object({
84
+ explanations: ExplanationsSchema,
85
+ agreementStartDate: Joi.string().isoDate().required(),
86
+ agreementEndDate: Joi.string().isoDate().required(),
87
+ frequency: Joi.string()
88
+ .valid('Monthly', 'Quarterly', 'Annually')
89
+ .required(),
90
+ agreementTotalPence: Joi.number().integer().required(),
91
+ annualTotalPence: Joi.number().integer().required(),
92
+ parcelItems: parcelItemsSchemaV2,
93
+ agreementLevelItems: agreementLevelItemsSchemaV2,
94
+ payments: PaymentsSchema
95
+ }).required()
96
+ })
97
+
98
+ export { PaymentCalculateSchema, PaymentCalculateResponseSchemaV2 }
@@ -0,0 +1,31 @@
1
+ import Joi from 'joi'
2
+ import { parcelIdsSchema } from './parcel-tiles.schema.js'
3
+
4
+ const parcelTilesLocatePayloadSchema = Joi.object({
5
+ parcelIds: parcelIdsSchema
6
+ })
7
+
8
+ const boundsSchema = Joi.object({
9
+ minLng: Joi.number().required(),
10
+ minLat: Joi.number().required(),
11
+ maxLng: Joi.number().required(),
12
+ maxLat: Joi.number().required()
13
+ }).required()
14
+
15
+ const parcelTilesLocateSuccessResponseSchema = Joi.object({
16
+ message: Joi.string().valid('success').required(),
17
+ bbox: boundsSchema,
18
+ parcels: Joi.array()
19
+ .items(
20
+ Joi.object({
21
+ id: Joi.string().required(),
22
+ bounds: boundsSchema
23
+ })
24
+ )
25
+ .required()
26
+ })
27
+
28
+ export {
29
+ parcelTilesLocatePayloadSchema,
30
+ parcelTilesLocateSuccessResponseSchema
31
+ }
@@ -0,0 +1,28 @@
1
+ import Joi from 'joi'
2
+
3
+ const MAX_ZOOM = 22
4
+ const MAX_PARCEL_IDS = 1000
5
+
6
+ const parcelTilesParamsSchema = Joi.object({
7
+ z: Joi.number().integer().min(0).max(MAX_ZOOM).required(),
8
+ x: Joi.number().integer().min(0).required(),
9
+ y: Joi.number().integer().min(0).required()
10
+ }).custom((value, helpers) => {
11
+ const max = 2 ** value.z
12
+ if (value.x >= max || value.y >= max) {
13
+ return helpers.error('any.invalid')
14
+ }
15
+ return value
16
+ })
17
+
18
+ const parcelIdsSchema = Joi.array()
19
+ .items(Joi.string().pattern(/^[A-Za-z\d]+-\d+$/))
20
+ .min(1)
21
+ .max(MAX_PARCEL_IDS)
22
+ .required()
23
+
24
+ const parcelTilesPayloadSchema = Joi.object({
25
+ parcelIds: parcelIdsSchema
26
+ })
27
+
28
+ export { parcelIdsSchema, parcelTilesParamsSchema, parcelTilesPayloadSchema }
@@ -0,0 +1,13 @@
1
+ import Joi from 'joi'
2
+
3
+ export const paymentCalculateTotalWMPSchema = Joi.object({
4
+ // The total area of the WMP application
5
+ totalAreaHa: Joi.number().min(0).required(),
6
+ // The total area on the original WMP application, before adjustments which may be later made
7
+ // by the forestry commission
8
+ originalTotalAreaHa: Joi.number().min(0).required(),
9
+ applicationId: Joi.string().required(),
10
+ sbi: Joi.string().required(),
11
+ crn: Joi.string().optional(),
12
+ startDate: Joi.date().optional()
13
+ })
@@ -0,0 +1,51 @@
1
+ import Joi from 'joi'
2
+
3
+ const agreementLevelItemSchema = Joi.object({
4
+ code: Joi.string().required(),
5
+ description: Joi.string().required(),
6
+ version: Joi.string().required(),
7
+ parcelIds: Joi.array().items(Joi.string()).required(),
8
+ activePaymentTier: Joi.number().integer().required(),
9
+ quantityInActiveTier: Joi.number().required(),
10
+ activeTierRatePence: Joi.number().required(),
11
+ activeTierFlatRatePence: Joi.number().required(),
12
+ agreementTotalPence: Joi.number().required(),
13
+ unit: Joi.string().required(),
14
+ quantity: Joi.number().required()
15
+ })
16
+
17
+ const lineItemSchema = Joi.object({
18
+ agreementLevelItemId: Joi.number().integer().required(),
19
+ paymentPence: Joi.number().required()
20
+ })
21
+
22
+ const paymentSchema = Joi.object({
23
+ totalPaymentPence: Joi.number().required(),
24
+ paymentDate: Joi.string().allow(null).required(),
25
+ lineItems: Joi.array().items(lineItemSchema).required()
26
+ })
27
+
28
+ export const paymentCalculateWMPResponseSchema = Joi.object({
29
+ message: Joi.string().required(),
30
+ payment: Joi.object({
31
+ explanations: Joi.array().required(),
32
+ agreementStartDate: Joi.string().required(),
33
+ agreementEndDate: Joi.string().required(),
34
+ frequency: Joi.string().required(),
35
+ agreementTotalPence: Joi.number().required(),
36
+ parcelItems: Joi.object().required(),
37
+ agreementLevelItems: Joi.object().pattern(
38
+ Joi.number().integer(),
39
+ agreementLevelItemSchema
40
+ ),
41
+ payments: Joi.array().items(paymentSchema).required()
42
+ }),
43
+ result: Joi.object()
44
+ })
45
+
46
+ export const paymentCalculateWMPSchemaV2 = Joi.object({
47
+ parcelIds: Joi.array().items(Joi.string()).min(1).required(),
48
+ oldWoodlandAreaHa: Joi.number().min(0).precision(4).required(),
49
+ newWoodlandAreaHa: Joi.number().min(0).precision(4).required(),
50
+ startDate: Joi.date().optional()
51
+ })
@@ -0,0 +1,19 @@
1
+ import Joi from 'joi'
2
+
3
+ const ruleResultsSchema = Joi.object({
4
+ hasPassed: Joi.boolean().required(),
5
+ code: Joi.string().required(),
6
+ actionConfigVersion: Joi.string().required(),
7
+ rules: Joi.array().items(Joi.object()).required()
8
+ })
9
+
10
+ export const validateWMPResponseSchemaV2 = Joi.object({
11
+ message: Joi.string().required(),
12
+ result: ruleResultsSchema
13
+ })
14
+
15
+ export const validateWMPSchemaV2 = Joi.object({
16
+ parcelIds: Joi.array().items(Joi.string()).required(),
17
+ oldWoodlandAreaHa: Joi.number().min(0).precision(4).required(),
18
+ newWoodlandAreaHa: Joi.number().min(0).precision(4)
19
+ })
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { parcelsSchema, parcelsSuccessResponseSchema } from './features/parcel/schema/2.0.0/parcel.schema.js'
2
+ import { parcelSupplementsSchema, parcelSupplementsSuccessResponseSchema } from './features/parcel/schema/2.0.0/parcel-supplements.schema.js'
3
+ import { PaymentCalculateSchema, PaymentCalculateResponseSchemaV2 } from './features/payment/schema/2.0.0/payment-calculate.schema.js'
4
+ import { applicationValidationSchema, applicationValidationRunRequestSchema, applicationValidationRunResponseSchema, applicationValidationRunsRequestSchema, applicationValidationRunsBodyRequestSchema, applicationValidationRunsResponseSchema } from './features/application/schema/application-validation.schema.js'
5
+ import { applicationValidationResponseSchemaV2 } from './features/application/schema/2.0.0/application-validation.schema.js'
6
+ import { caseManagementApplicationValidationRunRequestSchema, caseManagementApplicationValidationRunResponseSchema, caseManagementApplicationValidationRerunRequestSchema, caseManagementApplicationValidationReRunResponseSchema } from './features/case-management-adapter/schema/application-validation.schema.js'
7
+ import { parcelTilesParamsSchema, parcelTilesPayloadSchema } from './features/vector-tiles/schema/parcel-tiles.schema.js'
8
+ import { parcelTilesLocatePayloadSchema, parcelTilesLocateSuccessResponseSchema } from './features/vector-tiles/schema/parcel-tiles-locate.schema.js'
9
+ import { validateWMPSchemaV2, validateWMPResponseSchemaV2 } from './features/woodland-management/schema/validate-wmp.schema.js'
10
+ import { paymentCalculateWMPSchemaV2, paymentCalculateWMPResponseSchema } from './features/woodland-management/schema/payment-calculate-wmp.schema.js'
11
+ import { paymentCalculateTotalWMPSchema } from './features/woodland-management/schema/payment-calculate-total-wmp.schema.js'
12
+ import { statusIngestQuery, statusResponseSchema } from './features/land-data-ingest/schema/status.schema.js'
13
+ import { badRequestResponseSchema, errorResponseSchema, unprocessableEntityResponseSchema, internalServerErrorResponseSchema } from './features/common/schema/index.js'
14
+
15
+ export const paths = { "/api/v2/parcels": { "post": { "payload": parcelsSchema, "responses": { "200": parcelsSuccessResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/api/v2/parcels/supplements": { "post": { "payload": parcelSupplementsSchema, "responses": { "200": parcelSupplementsSuccessResponseSchema, "400": badRequestResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/api/v2/payments/calculate": { "post": { "payload": PaymentCalculateSchema, "responses": { "200": PaymentCalculateResponseSchemaV2, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/api/v2/application/validate": { "post": { "payload": applicationValidationSchema, "responses": { "200": applicationValidationResponseSchemaV2, "404": errorResponseSchema, "422": unprocessableEntityResponseSchema, "500": internalServerErrorResponseSchema } } }, "/application/validation-run/{id}": { "post": { "params": applicationValidationRunRequestSchema, "responses": { "200": applicationValidationRunResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/application/{applicationId}/validation-run": { "post": { "params": applicationValidationRunsRequestSchema, "payload": applicationValidationRunsBodyRequestSchema, "responses": { "200": applicationValidationRunsResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/case-management-adapter/application/validation-run/{id}": { "get": { "params": caseManagementApplicationValidationRunRequestSchema, "responses": { "200": caseManagementApplicationValidationRunResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/case-management-adapter/application/validation-run/rerun": { "post": { "payload": caseManagementApplicationValidationRerunRequestSchema, "responses": { "200": caseManagementApplicationValidationReRunResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/api/v1/parcel-tiles/{z}/{x}/{y}": { "post": { "params": parcelTilesParamsSchema, "payload": parcelTilesPayloadSchema, "responses": { } } }, "/api/v1/parcel-tiles/locate": { "post": { "payload": parcelTilesLocatePayloadSchema, "responses": { "200": parcelTilesLocateSuccessResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/api/v1/wmp/validate": { "post": { "payload": validateWMPSchemaV2, "responses": { "200": validateWMPResponseSchemaV2, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/api/v1/wmp/payments/calculate": { "post": { "payload": paymentCalculateWMPSchemaV2, "responses": { "200": paymentCalculateWMPResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/api/v1/wmp/payments/calculate-by-total-area": { "post": { "payload": paymentCalculateTotalWMPSchema, "responses": { "200": paymentCalculateWMPResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } }, "/ingest/status": { "get": { "query": statusIngestQuery, "responses": { "200": statusResponseSchema, "404": errorResponseSchema, "500": internalServerErrorResponseSchema } } } }
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@defra/land-grants-contract-schemas",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Joi schemas for the land-grants-api request and response contracts",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/DEFRA/land-grants-api.git",
9
+ "directory": "packages/contract-schemas"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "main": "dist/index.js",
15
+ "exports": "./dist/index.js",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "prepack": "node scripts/build.js"
21
+ },
22
+ "dependencies": {
23
+ "joi": "^17.13.9"
24
+ },
25
+ "license": "OGL-UK-3.0"
26
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.