@pdtf/schemas 0.5.14 → 0.6.2

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
@@ -2,7 +2,7 @@ const { dereference } = require("@jdw/jst");
2
2
  const Ajv = require("ajv");
3
3
  const addFormats = require("ajv-formats");
4
4
 
5
- const propertyPack = require("./src/schemas/property-pack.json");
5
+ const pdtfTransaction = require("./src/schemas/pdtf-transaction.json");
6
6
  const baspiMaterialFacts = require("./src/schemas/baspi-a-material-facts.json");
7
7
  const baspiLegalInformation = require("./src/schemas/baspi-b-legal-information.json");
8
8
  const energyPerformanceCertificate = require("./src/schemas/energy-performance-certificate.json");
@@ -21,7 +21,7 @@ const subSchemas = {
21
21
  "https://homebuyingandsellinggroup.co.uk/schemas/title-deed.json": titleDeed,
22
22
  };
23
23
 
24
- const propertyPackSchema = dereference(propertyPack, (id) => subSchemas[id]);
24
+ const transactionSchema = dereference(pdtfTransaction, (id) => subSchemas[id]);
25
25
 
26
26
  const ajv = new Ajv({
27
27
  allErrors: true,
@@ -31,18 +31,26 @@ const ajv = new Ajv({
31
31
  // Adds date formats among other types to the validator.
32
32
  addFormats(ajv);
33
33
 
34
- const validator = ajv.compile(propertyPackSchema);
34
+ const validator = ajv.compile(transactionSchema);
35
35
 
36
36
  const getSubschema = (path) => {
37
37
  const pathArray = path.split("/").slice(1);
38
38
  if (pathArray.length < 1) {
39
- return propertyPackSchema;
39
+ return transactionSchema;
40
40
  }
41
- return pathArray.reduce((propertyPackSchema, pathElement) => {
42
- return propertyPackSchema.properties[pathElement];
43
- }, propertyPackSchema);
41
+ return pathArray.reduce((schema, pathElement) => {
42
+ if (schema.type === "array") return schema.items;
43
+ return schema.properties[pathElement];
44
+ }, transactionSchema);
44
45
  };
45
46
 
47
+ const isPathValid = (path) => {
48
+ try {
49
+ return getSubschema(path) !== undefined;
50
+ } catch (err) {
51
+ return false;
52
+ }
53
+ };
46
54
  const getSubschemaValidator = (path) => {
47
55
  const subSchema = getSubschema(path);
48
56
  let validator = ajv.getSchema(path);
@@ -99,9 +107,10 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
99
107
  };
100
108
 
101
109
  module.exports = {
102
- propertyPackSchema,
110
+ transactionSchema,
103
111
  validator,
104
112
  getSubschema,
113
+ isPathValid,
105
114
  getSubschemaValidator,
106
115
  getTitleAtPath,
107
116
  verifiedClaimsSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdtf/schemas",
3
- "version": "0.5.14",
3
+ "version": "0.6.2",
4
4
  "description": "Property Data Trust Framework Schemas and Utilities",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -31,7 +31,7 @@
31
31
  ]
32
32
  },
33
33
  "claims": {
34
- "/propertyPack/materialFacts/propertyToBeSold/councilTax": {
34
+ "/propertyPack/materialFacts/councilTax": {
35
35
  "councilTaxBand": "D",
36
36
  "councilTaxAffectingAlterations": {
37
37
  "yesNo": "Yes",
@@ -5,9 +5,13 @@
5
5
  "evidence": [
6
6
  {
7
7
  "type": "electronic_record",
8
+ "verifier": {
9
+ "organization": "Property Pack Assembly Software Ltd"
10
+ },
8
11
  "record": {
9
12
  "source": {
10
- "name": "Royal Mail Postcode Address File record via ideal-postcodes.co.uk"
13
+ "name": "Royal Mail Postcode Address File",
14
+ "rights": "(c) Royal Mail"
11
15
  },
12
16
  "type": "postcode_address_file"
13
17
  }