@pdtf/schemas 2.0.0-22 → 2.0.0-24

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/index.js CHANGED
@@ -60,7 +60,7 @@ const con29DWOverlay = require("./src/schemas/v2/overlays/con29DW.json");
60
60
  const rdsOverlay = require("./src/schemas/v2/overlays/rds.json");
61
61
  const oc1Overlay = require("./src/schemas/v2/overlays/oc1.json");
62
62
 
63
- const overlays = { baspiV4: baspiOverlay, null: {} };
63
+ const overlaysMap = { baspiV4: baspiOverlay, ta6ed4: ta6Overlay, null: {} };
64
64
 
65
65
  const transactionSchemas = {
66
66
  "https://trust.propdata.org.uk/schemas/v1/pdtf-transaction.json":
@@ -85,22 +85,25 @@ const combineMerge = (target, source, options) => {
85
85
 
86
86
  const getTransactionSchema = (
87
87
  schemaId = "https://trust.propdata.org.uk/schemas/v2/pdtf-transaction.json",
88
- overlay = "baspiV4"
88
+ overlays = ["baspiV4"]
89
89
  ) => {
90
90
  const sourceSchema = transactionSchemas[schemaId];
91
- const overlaySchema = overlays[overlay];
92
- if (!overlaySchema) return sourceSchema;
93
- const mergedSchema = merge(overlaySchema, sourceSchema, {
94
- arrayMerge: combineMerge,
91
+ if (!overlays || overlays.length < 1) return sourceSchema;
92
+ let mergedSchema = sourceSchema;
93
+ overlays.forEach((overlay) => {
94
+ const overlaySchema = overlaysMap[overlay] || {};
95
+ mergedSchema = merge(overlaySchema, mergedSchema, {
96
+ arrayMerge: combineMerge,
97
+ });
95
98
  });
96
99
  // console.log("mergedSchema", mergedSchema);
97
100
  return mergedSchema;
98
101
  };
99
102
 
100
- const getValidator = (schemaId, overlay = "baspiV4") => {
103
+ const getValidator = (schemaId, overlays) => {
101
104
  let validator = ajv.getSchema(schemaId);
102
105
  if (!validator) {
103
- const schema = getTransactionSchema(schemaId, overlay);
106
+ const schema = getTransactionSchema(schemaId, overlays);
104
107
  ajv.addSchema(schema, schemaId);
105
108
  validator = ajv.getSchema(schemaId);
106
109
  }
@@ -108,8 +111,8 @@ const getValidator = (schemaId, overlay = "baspiV4") => {
108
111
  };
109
112
 
110
113
  // common functions for v1 and v2
111
- const getSubschema = (path, schemaId, overlay) => {
112
- const sourceSchema = getTransactionSchema(schemaId, overlay);
114
+ const getSubschema = (path, schemaId, overlays) => {
115
+ const sourceSchema = getTransactionSchema(schemaId, overlays);
113
116
  const pathArray = path.split("/").slice(1);
114
117
  if (pathArray.length < 1) return sourceSchema;
115
118
  return pathArray.reduce((schema, pathElement) => {
@@ -131,19 +134,19 @@ const getSubschema = (path, schemaId, overlay) => {
131
134
  }, sourceSchema);
132
135
  };
133
136
 
134
- const isPathValid = (path, schemaId, overlay) => {
135
- const schema = getTransactionSchema(schemaId, overlay);
137
+ const isPathValid = (path, schemaId, overlays) => {
136
138
  try {
137
- return getSubschema(path, schemaId, overlay) !== undefined;
139
+ return getSubschema(path, schemaId, overlays) !== undefined;
138
140
  } catch (err) {
139
141
  return false;
140
142
  }
141
143
  };
142
144
 
143
- const getSubschemaValidator = (path, schemaId, overlay) => {
144
- const subSchema = getSubschema(path, schemaId, overlay);
145
- // see if we can retrieve the schema by path, schemaId and overlay
146
- const cacheKey = `${path}-${schemaId}-${overlay}`;
145
+ const getSubschemaValidator = (path, schemaId, overlays = ["baspiV4"]) => {
146
+ const subSchema = getSubschema(path, schemaId, overlays);
147
+ const overlayKey = (overlays || []).join(".");
148
+ // see if we can retrieve the schema by path, schemaId and overlays
149
+ const cacheKey = `${path}-${schemaId}-${overlayKey}`;
147
150
  let validator = ajv.getSchema(cacheKey);
148
151
  // retrieve whole schema by $id if available
149
152
  if (!validator && subSchema.$id) validator = ajv.getSchema(cacheKey);
@@ -198,7 +201,7 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
198
201
  }
199
202
  };
200
203
 
201
- const validateVerifiedClaims = (verifiedClaims, schemaId, overlay) => {
204
+ const validateVerifiedClaims = (verifiedClaims, schemaId, overlays) => {
202
205
  const validatorVClaims = ajv.compile(verifiedClaimsSchema);
203
206
 
204
207
  const validationErrorsArr = [];
@@ -217,9 +220,9 @@ const validateVerifiedClaims = (verifiedClaims, schemaId, overlay) => {
217
220
  verifiedClaimsArray.forEach((claim) => {
218
221
  const paths = Object.keys(claim.claims);
219
222
  for (const path of paths) {
220
- const validPath = isPathValid(path, schemaId, overlay);
223
+ const validPath = isPathValid(path, schemaId, overlays);
221
224
  if (validPath) {
222
- const subValidator = getSubschemaValidator(path, schemaId, overlay);
225
+ const subValidator = getSubschemaValidator(path, schemaId, overlays);
223
226
  const isValid = subValidator(claim.claims[path]);
224
227
  if (!isValid) {
225
228
  validationErrorsArr.push(...subValidator.errors);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "2.0.0-22",
3
+ "version": "2.0.0-24",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -164,9 +164,6 @@
164
164
  "yesNo": "Not required",
165
165
  "details": "No restriction"
166
166
  },
167
- "unfinished": {
168
- "yesNo": "No"
169
- },
170
167
  "yesNo": "Yes",
171
168
  "details": "Bedroom and ensuite shower room extension 2005"
172
169
  },
@@ -190,9 +187,6 @@
190
187
  "yesNo": "Not required",
191
188
  "details": "No restriction"
192
189
  },
193
- "unfinished": {
194
- "yesNo": "No"
195
- },
196
190
  "yesNo": "Yes",
197
191
  "details": "New front door added 2016",
198
192
  "yearCompleted": 2016
@@ -214,13 +208,13 @@
214
208
  "yesNo": "No",
215
209
  "details": "Added as part of initial build and deeds"
216
210
  },
217
- "unfinished": {
218
- "yesNo": "No"
219
- },
220
211
  "yesNo": "Yes",
221
212
  "details": "Conservatory added during house build in 1990 and exterior quality door separates the conservatory from the kitchen/dining room",
222
213
  "yearCompleted": 1990
223
214
  },
215
+ "worksUnfinished": {
216
+ "yesNo": "No"
217
+ },
224
218
  "planningPermissionBreaches": {
225
219
  "yesNo": "No"
226
220
  },
@@ -382,7 +376,10 @@
382
376
  "insurance": {
383
377
  "isInsured": "Yes",
384
378
  "difficultiesObtainingInsurance": {
385
- "yesNo": "No"
379
+ "abnormalRiseInPremiums": { "yesNo": "No" },
380
+ "subjectToHighExcesses": { "yesNo": "No" },
381
+ "subjectToUnusualConditions": { "yesNo": "No" },
382
+ "refused": { "yesNo": "No" }
386
383
  },
387
384
  "insuranceClaims": {
388
385
  "yesNo": "No"
@@ -477,6 +474,9 @@
477
474
  },
478
475
  "otherMaterialIssue": {
479
476
  "yesNo": "No"
477
+ },
478
+ "otherCharges": {
479
+ "yesNo": "No"
480
480
  }
481
481
  },
482
482
  "consumerProtectionRegulationsDeclaration": {
@@ -551,7 +551,10 @@
551
551
  "completionAndMoving": {
552
552
  "willRemoveAllRubbish": true,
553
553
  "otherPropertyInChain": { "yesNo": "No" },
554
- "moveRestrictionDates": { "yesNo": "No" },
554
+ "moveRestrictionDates": {
555
+ "yesNo": "Yes",
556
+ "details": "On holiday 1-15 Aug 23"
557
+ },
555
558
  "digitalPropertyLogbook": {
556
559
  "yesNo": "Yes",
557
560
  "logbookProvider": "someone",