@pdtf/schemas 0.6.10 → 0.6.13

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
@@ -119,6 +119,42 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
119
119
  }
120
120
  };
121
121
 
122
+ const validateVerifiedClaims = (verifiedClaimsArray) => {
123
+ const validatorVClaims = ajv.compile(verifiedClaimsSchema);
124
+
125
+ const validationErrorsArr = [];
126
+ const vClaimSchValidation = validatorVClaims({
127
+ verified_claims: verifiedClaimsArray,
128
+ });
129
+
130
+ if (!vClaimSchValidation) {
131
+ validationErrorsArr.push(validatorVClaims.errors);
132
+ }
133
+
134
+ verifiedClaimsArray.forEach((claim) => {
135
+ const paths = Object.keys(claim.claims);
136
+
137
+ for (const path of paths) {
138
+ const validPath = isPathValid(path);
139
+ if (validPath) {
140
+ const subValidator = getSubschemaValidator(path);
141
+ const isValid = subValidator(claim.claims[path]);
142
+ if (!isValid) {
143
+ validationErrorsArr.push(...subValidator.errors);
144
+ }
145
+ } else {
146
+ validationErrorsArr.push(
147
+ `Path ${path} is not a valid PDTF schema path`
148
+ );
149
+ }
150
+ }
151
+ });
152
+
153
+ return validationErrorsArr;
154
+ };
155
+
156
+
157
+
122
158
  module.exports = {
123
159
  transactionSchema,
124
160
  validator,
@@ -127,4 +163,5 @@ module.exports = {
127
163
  getSubschemaValidator,
128
164
  getTitleAtPath,
129
165
  verifiedClaimsSchema,
166
+ validateVerifiedClaims
130
167
  };
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
- "name": "@pdtf/schemas",
3
- "version": "0.6.10",
4
- "description": "Property Data Trust Framework Schemas and Utilities",
5
- "main": "index.js",
6
- "directories": {
7
- "doc": "docs"
8
- },
9
- "scripts": {
10
- "test": "jest",
11
- "test:watch": "jest --watch"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/Property-Data-Trust-Framework/schemas.git"
16
- },
17
- "keywords": [
18
- "PDTF",
19
- "Schemas"
20
- ],
21
- "author": "",
22
- "license": "MIT",
23
- "bugs": {
24
- "url": "https://github.com/Property-Data-Trust-Framework/schemas/issues"
25
- },
26
- "homepage": "https://github.com/Property-Data-Trust-Framework/schemas#readme",
27
- "dependencies": {
28
- "@jdw/jst": "^2.0.0-beta.15",
29
- "ajv": "^8.10.0",
30
- "ajv-formats": "^2.1.1",
31
- "jsonpointer": "^5.0.0"
32
- },
33
- "devDependencies": {
34
- "jest": "^27.5.1"
35
- }
36
- }
2
+ "name": "@pdtf/schemas",
3
+ "version": "0.6.13",
4
+ "description": "Property Data Trust Framework Schemas and Utilities",
5
+ "main": "index.js",
6
+ "directories": {
7
+ "doc": "docs"
8
+ },
9
+ "scripts": {
10
+ "test": "jest",
11
+ "test:watch": "jest --watch"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/Property-Data-Trust-Framework/schemas.git"
16
+ },
17
+ "keywords": [
18
+ "PDTF",
19
+ "Schemas"
20
+ ],
21
+ "author": "",
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/Property-Data-Trust-Framework/schemas/issues"
25
+ },
26
+ "homepage": "https://github.com/Property-Data-Trust-Framework/schemas#readme",
27
+ "dependencies": {
28
+ "@jdw/jst": "^2.0.0-beta.15",
29
+ "ajv": "^8.10.0",
30
+ "ajv-formats": "^2.1.1",
31
+ "jsonpointer": "^5.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "jest": "^27.5.1"
35
+ }
36
+ }
@@ -4,19 +4,7 @@
4
4
  "time": "2022-01-25T13:16:44.527Z",
5
5
  "evidence": [
6
6
  {
7
- "verification_method": {
8
- "type": "auth"
9
- },
10
7
  "type": "vouch",
11
- "attestation": {
12
- "voucher": {
13
- "name": "Maria Harris"
14
- },
15
- "type": "digital_attestation"
16
- }
17
- },
18
- {
19
- "type": "document",
20
8
  "attachments": [
21
9
  {
22
10
  "digest": {
@@ -26,7 +14,16 @@
26
14
  "url": "https://fakeFileStore.com/some/kind/of/file",
27
15
  "desc": "proofOfAddress.pdf"
28
16
  }
29
- ]
17
+ ],
18
+ "verification_method": {
19
+ "type": "auth"
20
+ },
21
+ "attestation": {
22
+ "voucher": {
23
+ "name": "Maria Harris"
24
+ },
25
+ "type": "digital_attestation"
26
+ }
30
27
  }
31
28
  ]
32
29
  },
@@ -282,7 +282,8 @@
282
282
  }
283
283
  },
284
284
  "centralHeating": {
285
- "hasCentralHeating": {
285
+ "hasCentralHeating": "Yes",
286
+ "centralHeatingDetails": {
286
287
  "boilerInstallationCertificate": {
287
288
  "yesNo": "Yes",
288
289
  "details": "Certified installation"
@@ -290,10 +291,8 @@
290
291
  "heatingInGoodWorkingOrder": {
291
292
  "yesNo": "Yes"
292
293
  },
293
- "yesNo": "Yes",
294
294
  "centralHeatingFuel": "Gas boiler",
295
295
  "centralHeatingInstalled": "2016-04-20",
296
- "heatingServiceReport": "Full service history available from Whickham Plumbing & Heating ",
297
296
  "heatingLastServiced": "2021-03-26"
298
297
  }
299
298
  },
@@ -1005,90 +1005,89 @@
1005
1005
  "baspiRef": "A7.4",
1006
1006
  "RDSRef": "Buildings|BuildingSections/isUnheated=no|yes|true|false",
1007
1007
  "lawSocietyRef": "TA6/12.3",
1008
+ "title": "Central Heating",
1008
1009
  "type": "object",
1009
1010
  "required": ["hasCentralHeating"],
1010
1011
  "properties": {
1011
1012
  "hasCentralHeating": {
1012
1013
  "title": "Is there full/partial central heating in your property?",
1013
- "yesNoCentralHeatingDetailIfYes": {
1014
- "type": "object",
1015
- "properties": {
1016
- "yesNo": {
1017
- "type": "string",
1018
- "title": "",
1019
- "enum": ["Yes", "No"]
1020
- }
1014
+ "type": "string",
1015
+ "enum": ["Yes", "No"]
1016
+ }
1017
+ },
1018
+ "dependencies": {
1019
+ "hasCentralHeating": {
1020
+ "oneOf": [
1021
+ {
1022
+ "properties": {
1023
+ "hasCentralHeating": {
1024
+ "enum": ["No"]
1025
+ }
1026
+ },
1027
+ "additionalProperties": false
1021
1028
  },
1022
- "required": ["yesNo"],
1023
- "dependencies": {
1024
- "yesNo": {
1025
- "oneOf": [
1026
- {
1027
- "properties": {
1028
- "yesNo": {
1029
- "enum": ["No"]
1030
- }
1029
+ {
1030
+ "properties": {
1031
+ "hasCentralHeating": {
1032
+ "enum": ["Yes"]
1033
+ },
1034
+ "centralHeatingDetails": {
1035
+ "type": "object",
1036
+ "title": "Central Heating Details",
1037
+ "properties": {
1038
+ "centralHeatingFuel": {
1039
+ "baspiRef": "A7.5.1",
1040
+ "RDSRef": "Buildings|BuildingSections/Heating/isGas=no|yes|true|false",
1041
+ "lawSocietyRef": "TA6/12.3a",
1042
+ "title": "Please provide details of the type of fuel which the system and boiler runs on",
1043
+ "type": "string",
1044
+ "minLength": 1
1031
1045
  },
1032
- "additionalProperties": false
1033
- },
1034
- {
1035
- "properties": {
1036
- "yesNo": {
1037
- "enum": ["Yes"]
1038
- },
1039
- "centralHeatingFuel": {
1040
- "baspiRef": "A7.5.1",
1041
- "RDSRef": "Buildings|BuildingSections/Heating/isGas=no|yes|true|false",
1042
- "lawSocietyRef": "TA6/12.3a",
1043
- "title": "Please provide details of the type of fuel which the system and boiler runs on",
1044
- "type": "string",
1045
- "minLength": 1
1046
- },
1047
- "centralHeatingInstalled": {
1048
- "baspiRef": "A7.5.2",
1049
- "RDSRef": "Objects/Installed",
1050
- "lawSocietyRef": "TA6/12.3b",
1051
- "title": "When was the heating system and boiler installed?",
1052
- "type": "string",
1053
- "format": "date"
1054
- },
1055
- "boilerInstallationCertificate": {
1056
- "baspiRef": "A7.5.3",
1057
- "RDSRef": "Objects/Installation,Objects/Certificates",
1058
- "lawSocietyRef": "TA6/12.3b",
1059
- "title": "Was a gas boiler installed after 1st April 2005, or a solid fuel or oil boiler installed after 1 October 2010?",
1060
- "$ref": "#/$defs/yesNoDetailIfYes",
1061
- "description": "If yes, please supply a copy of the installation completion certificate from a competent person qualified under the relevant self-certification scheme e.g. HETAS etc"
1062
- },
1063
- "heatingLastServiced": {
1064
- "baspiRef": "A7.5.4",
1065
- "RDSRef": "Objects/Maintenance",
1066
- "lawSocietyRef": "TA6/12.3d",
1067
- "title": "When was the heating system and boiler last serviced or maintained?",
1068
- "type": "string",
1069
- "format": "date"
1070
- },
1071
- "heatingServiceReport": {
1072
- "baspiRef": "A7.5.5",
1073
- "RDSRef": "Objects/Servicing",
1074
- "lawSocietyRef": "TA6/12.3d",
1075
- "title": "Please provide a copy of the service or maintenance works report",
1076
- "type": "string"
1077
- },
1078
- "heatingInGoodWorkingOrder": {
1079
- "baspiRef": "A7.5.6",
1080
- "RDSRef": "Objects/Condition=?",
1081
- "lawSocietyRef": "TA6/12.3c",
1082
- "title": "Is the heating system in good working order to your satisfaction?",
1083
- "$ref": "#/$defs/yesNoDetailIfNo",
1084
- "description": "If 'No' please provide details"
1085
- }
1046
+ "centralHeatingInstalled": {
1047
+ "baspiRef": "A7.5.2",
1048
+ "RDSRef": "Objects/Installed",
1049
+ "lawSocietyRef": "TA6/12.3b",
1050
+ "title": "When was the heating system and boiler installed?",
1051
+ "type": "string",
1052
+ "format": "date"
1053
+ },
1054
+ "boilerInstallationCertificate": {
1055
+ "baspiRef": "A7.5.3",
1056
+ "RDSRef": "Objects/Installation,Objects/Certificates",
1057
+ "lawSocietyRef": "TA6/12.3b",
1058
+ "title": "Was a gas boiler installed after 1st April 2005, or a solid fuel or oil boiler installed after 1 October 2010?",
1059
+ "$ref": "#/$defs/yesNoDetailIfYes",
1060
+ "description": "If yes, please supply a copy of the installation completion certificate from a competent person qualified under the relevant self-certification scheme e.g. HETAS etc"
1061
+ },
1062
+ "heatingLastServiced": {
1063
+ "baspiRef": "A7.5.4",
1064
+ "RDSRef": "Objects/Maintenance",
1065
+ "lawSocietyRef": "TA6/12.3d",
1066
+ "title": "When was the heating system and boiler last serviced or maintained? Please provide a copy of the service or maintenance works report ",
1067
+ "type": "string",
1068
+ "format": "date"
1069
+ },
1070
+ "heatingInGoodWorkingOrder": {
1071
+ "baspiRef": "A7.5.6",
1072
+ "RDSRef": "Objects/Condition=?",
1073
+ "lawSocietyRef": "TA6/12.3c",
1074
+ "title": "Is the heating system in good working order to your satisfaction?",
1075
+ "$ref": "#/$defs/yesNoDetailIfNo",
1076
+ "description": "If 'No' please provide details"
1086
1077
  }
1087
- }
1088
- ]
1089
- }
1078
+ },
1079
+ "required": [
1080
+ "centralHeatingFuel",
1081
+ "centralHeatingInstalled",
1082
+ "boilerInstallationCertificate",
1083
+ "heatingLastServiced",
1084
+ "heatingInGoodWorkingOrder"
1085
+ ]
1086
+ }
1087
+ },
1088
+ "required": ["centralHeatingDetails"]
1090
1089
  }
1091
- }
1090
+ ]
1092
1091
  }
1093
1092
  }
1094
1093
  },
@@ -7,6 +7,7 @@ const {
7
7
  isPathValid,
8
8
  getSubschemaValidator,
9
9
  getTitleAtPath,
10
+ validateVerifiedClaims
10
11
  } = require("../../index.js");
11
12
  const exampleTransaction = require("../examples/exampleTransaction.json");
12
13
 
@@ -182,3 +183,274 @@ test("correctly gets titles across schemas, arrays and non-existient title prope
182
183
  )
183
184
  ).toBe("Current energy rating");
184
185
  });
186
+
187
+ test("returns an array with an error stating if path is incorrect", () => {
188
+ const vClaims = [
189
+ {
190
+ verification: {
191
+ trust_framework: "uk_pdtf",
192
+ time: "2022-01-25T13:16:44.527Z",
193
+ evidence: [
194
+ {
195
+ verification_method: {
196
+ type: "auth",
197
+ },
198
+ type: "vouch",
199
+ attestation: {
200
+ voucher: {
201
+ name: "Maria Harris",
202
+ },
203
+ type: "digital_attestation",
204
+ },
205
+ },
206
+ {
207
+ type: "document",
208
+ attachments: [
209
+ {
210
+ digest: {
211
+ alg: "md5",
212
+ value: "randomHashValue",
213
+ },
214
+ url: "https://fakeFileStore.com/some/kind/of/file",
215
+ desc: "proofOfAddress.pdf",
216
+ },
217
+ ],
218
+ },
219
+ ],
220
+ },
221
+ claims: {
222
+ "/propertyPack/INVALID/materialFacts/councilTax": {
223
+ councilTaxBand: "D",
224
+ councilTaxAffectingAlterations: {
225
+ yesNo: "Yes",
226
+ details:
227
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
228
+ },
229
+ },
230
+ },
231
+ },
232
+ ];
233
+ expect(validateVerifiedClaims(vClaims)).toEqual([
234
+ "Path /propertyPack/INVALID/materialFacts/councilTax is not a valid PDTF schema path",
235
+ ]);
236
+ });
237
+
238
+ test("returns an empty array if path is correct", () => {
239
+ const vClaims = [
240
+ {
241
+ verification: {
242
+ trust_framework: "uk_pdtf",
243
+ time: "2022-01-25T13:16:44.527Z",
244
+ evidence: [
245
+ {
246
+ verification_method: {
247
+ type: "auth",
248
+ },
249
+ type: "vouch",
250
+ attestation: {
251
+ voucher: {
252
+ name: "Maria Harris",
253
+ },
254
+ type: "digital_attestation",
255
+ },
256
+ },
257
+ {
258
+ type: "document",
259
+ attachments: [
260
+ {
261
+ digest: {
262
+ alg: "md5",
263
+ value: "randomHashValue",
264
+ },
265
+ url: "https://fakeFileStore.com/some/kind/of/file",
266
+ desc: "proofOfAddress.pdf",
267
+ },
268
+ ],
269
+ },
270
+ ],
271
+ },
272
+ claims: {
273
+ "/propertyPack/materialFacts/councilTax": {
274
+ councilTaxBand: "D",
275
+ councilTaxAffectingAlterations: {
276
+ yesNo: "Yes",
277
+ details:
278
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
279
+ },
280
+ },
281
+ },
282
+ },
283
+ ];
284
+ expect(validateVerifiedClaims(vClaims)).toEqual([]);
285
+ });
286
+
287
+ test("returns an array of errors if data in the path is in invalid format", () => {
288
+ const vClaims = [
289
+ {
290
+ verification: {
291
+ trust_framework: "uk_pdtf",
292
+ time: "2022-01-25T13:16:44.527Z",
293
+ evidence: [
294
+ {
295
+ verification_method: {
296
+ type: "auth",
297
+ },
298
+ type: "vouch",
299
+ attestation: {
300
+ voucher: {
301
+ name: "Maria Harris",
302
+ },
303
+ type: "digital_attestation",
304
+ },
305
+ },
306
+ {
307
+ type: "document",
308
+ attachments: [
309
+ {
310
+ digest: {
311
+ alg: "md5",
312
+ value: "randomHashValue",
313
+ },
314
+ url: "https://fakeFileStore.com/some/kind/of/file",
315
+ desc: "proofOfAddress.pdf",
316
+ },
317
+ ],
318
+ },
319
+ ],
320
+ },
321
+ claims: {
322
+ "/propertyPack/materialFacts/councilTax": {
323
+ councilTaxBand: "D",
324
+ councilTaxAffectingAlterationsINVALID: {
325
+ yesNo: "Yes",
326
+ details:
327
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
328
+ },
329
+ },
330
+ },
331
+ },
332
+ ];
333
+ expect(validateVerifiedClaims(vClaims)).toEqual([
334
+ {
335
+ instancePath: "",
336
+ schemaPath: "#/required",
337
+ keyword: "required",
338
+ params: { missingProperty: "councilTaxAffectingAlterations" },
339
+ message: "must have required property 'councilTaxAffectingAlterations'",
340
+ },
341
+ ]);
342
+ });
343
+
344
+ test("returns an array of errors for verified claim with multiple paths", () => {
345
+ const vClaims = [
346
+ {
347
+ verification: {
348
+ trust_framework: "uk_pdtf",
349
+ time: "2022-01-25T13:16:44.527Z",
350
+ evidence: [
351
+ {
352
+ verification_method: {
353
+ type: "auth",
354
+ },
355
+ type: "vouch",
356
+ attestation: {
357
+ voucher: {
358
+ name: "Maria Harris",
359
+ },
360
+ type: "digital_attestation",
361
+ },
362
+ },
363
+ {
364
+ type: "document",
365
+ attachments: [
366
+ {
367
+ digest: {
368
+ alg: "md5",
369
+ value: "randomHashValue",
370
+ },
371
+ url: "https://fakeFileStore.com/some/kind/of/file",
372
+ desc: "proofOfAddress.pdf",
373
+ },
374
+ ],
375
+ },
376
+ ],
377
+ },
378
+ claims: {
379
+ "/propertyPack/materialFacts/cousncilTaxBad": {
380
+ councilTaxBand: "D",
381
+ councilTaxAffectingAlterations: {
382
+ yesNo: "Yes",
383
+ details:
384
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
385
+ },
386
+ },
387
+ "/propertyPack/materialFacts/councilTaxBadTwo": {
388
+ councilTaxBand: "D",
389
+ councilTaxAffectingAlterations: {
390
+ yesNo: "Yes",
391
+ details:
392
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
393
+ },
394
+ },
395
+ },
396
+ },
397
+ ];
398
+ expect(validateVerifiedClaims(vClaims)).toEqual(["Path /propertyPack/materialFacts/cousncilTaxBad is not a valid PDTF schema path",
399
+ "Path /propertyPack/materialFacts/councilTaxBadTwo is not a valid PDTF schema path"]);
400
+ });
401
+
402
+ test("returns an empty array of errors for verified claim with multiple paths", () => {
403
+ const vClaims = [
404
+ {
405
+ verification: {
406
+ trust_framework: "uk_pdtf",
407
+ time: "2022-01-25T13:16:44.527Z",
408
+ evidence: [
409
+ {
410
+ verification_method: {
411
+ type: "auth",
412
+ },
413
+ type: "vouch",
414
+ attestation: {
415
+ voucher: {
416
+ name: "Maria Harris",
417
+ },
418
+ type: "digital_attestation",
419
+ },
420
+ },
421
+ {
422
+ type: "document",
423
+ attachments: [
424
+ {
425
+ digest: {
426
+ alg: "md5",
427
+ value: "randomHashValue",
428
+ },
429
+ url: "https://fakeFileStore.com/some/kind/of/file",
430
+ desc: "proofOfAddress.pdf",
431
+ },
432
+ ],
433
+ },
434
+ ],
435
+ },
436
+ claims: {
437
+ "/propertyPack/materialFacts/councilTax": {
438
+ councilTaxBand: "D",
439
+ councilTaxAffectingAlterations: {
440
+ yesNo: "Yes",
441
+ details:
442
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
443
+ },
444
+ },
445
+ "/propertyPack/materialFacts/address": {
446
+ line1: "property.line1",
447
+ line2: "property.line2",
448
+ town: "property.city",
449
+ county: "property.province",
450
+ postcode: "property.postcode",
451
+ },
452
+ },
453
+ },
454
+ ];
455
+ expect(validateVerifiedClaims(vClaims)).toEqual([]);
456
+ });