@pdtf/schemas 0.6.13 → 0.6.14

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,18 +119,22 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
119
119
  }
120
120
  };
121
121
 
122
- const validateVerifiedClaims = (verifiedClaimsArray) => {
122
+ const validateVerifiedClaims = (verifiedClaims) => {
123
123
  const validatorVClaims = ajv.compile(verifiedClaimsSchema);
124
124
 
125
125
  const validationErrorsArr = [];
126
126
  const vClaimSchValidation = validatorVClaims({
127
- verified_claims: verifiedClaimsArray,
127
+ verified_claims: verifiedClaims,
128
128
  });
129
129
 
130
130
  if (!vClaimSchValidation) {
131
131
  validationErrorsArr.push(validatorVClaims.errors);
132
132
  }
133
133
 
134
+ const verifiedClaimsArray = Array.isArray(verifiedClaims)
135
+ ? verifiedClaims
136
+ : [verifiedClaims];
137
+
134
138
  verifiedClaimsArray.forEach((claim) => {
135
139
  const paths = Object.keys(claim.claims);
136
140
 
@@ -153,8 +157,6 @@ const validateVerifiedClaims = (verifiedClaimsArray) => {
153
157
  return validationErrorsArr;
154
158
  };
155
159
 
156
-
157
-
158
160
  module.exports = {
159
161
  transactionSchema,
160
162
  validator,
@@ -163,5 +165,5 @@ module.exports = {
163
165
  getSubschemaValidator,
164
166
  getTitleAtPath,
165
167
  verifiedClaimsSchema,
166
- validateVerifiedClaims
168
+ validateVerifiedClaims,
167
169
  };
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
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
- }
2
+ "name": "@pdtf/schemas",
3
+ "version": "0.6.14",
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
+ }
@@ -7,7 +7,6 @@ const {
7
7
  isPathValid,
8
8
  getSubschemaValidator,
9
9
  getTitleAtPath,
10
- validateVerifiedClaims
11
10
  } = require("../../index.js");
12
11
  const exampleTransaction = require("../examples/exampleTransaction.json");
13
12
 
@@ -183,274 +182,3 @@ test("correctly gets titles across schemas, arrays and non-existient title prope
183
182
  )
184
183
  ).toBe("Current energy rating");
185
184
  });
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
- });
@@ -0,0 +1,96 @@
1
+ const { validateVerifiedClaims } = require("../../index.js");
2
+
3
+ const exampleVouch = require("../examples/exampleVouch.json");
4
+ const exampleDocumentedVouch = require("../examples/exampleDocumentedVouch.json");
5
+
6
+ test("returns an empty array for a valid claim", () => {
7
+ expect(validateVerifiedClaims(exampleVouch)).toEqual([]);
8
+ });
9
+
10
+ test("returns an empty array for a valid array of claims", () => {
11
+ const claimsArray = [exampleVouch, exampleDocumentedVouch];
12
+ expect(validateVerifiedClaims(claimsArray)).toEqual([]);
13
+ });
14
+
15
+ test("returns an array with an error stating if path is incorrect", () => {
16
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
17
+ const originalPath = Object.keys(clonedVouch.claims)[0];
18
+ const data = clonedVouch.claims[originalPath];
19
+ clonedVouch.claims = {
20
+ "/propertyPack/INVALID/materialFacts/councilTax": data,
21
+ };
22
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([
23
+ "Path /propertyPack/INVALID/materialFacts/councilTax is not a valid PDTF schema path",
24
+ ]);
25
+ });
26
+
27
+ test("returns an array of errors if data in the path is in invalid format", () => {
28
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
29
+ clonedVouch.claims = {
30
+ "/propertyPack/materialFacts/councilTax": {
31
+ councilTaxBand: "D",
32
+ councilTaxAffectingAlterationsINVALID: {
33
+ yesNo: "Yes",
34
+ details:
35
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
36
+ },
37
+ },
38
+ };
39
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([
40
+ {
41
+ instancePath: "",
42
+ schemaPath: "#/required",
43
+ keyword: "required",
44
+ params: { missingProperty: "councilTaxAffectingAlterations" },
45
+ message: "must have required property 'councilTaxAffectingAlterations'",
46
+ },
47
+ ]);
48
+ });
49
+
50
+ test("returns an array of errors for verified claim with multiple paths", () => {
51
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
52
+ clonedVouch.claims = {
53
+ "/propertyPack/materialFacts/cousncilTaxBad": {
54
+ councilTaxBand: "D",
55
+ councilTaxAffectingAlterations: {
56
+ yesNo: "Yes",
57
+ details:
58
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
59
+ },
60
+ },
61
+ "/propertyPack/materialFacts/councilTaxBadTwo": {
62
+ councilTaxBand: "D",
63
+ councilTaxAffectingAlterations: {
64
+ yesNo: "Yes",
65
+ details:
66
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
67
+ },
68
+ },
69
+ };
70
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([
71
+ "Path /propertyPack/materialFacts/cousncilTaxBad is not a valid PDTF schema path",
72
+ "Path /propertyPack/materialFacts/councilTaxBadTwo is not a valid PDTF schema path",
73
+ ]);
74
+ });
75
+
76
+ test("returns an empty array of errors for verified claim with multiple valid paths", () => {
77
+ const clonedVouch = JSON.parse(JSON.stringify(exampleVouch));
78
+ clonedVouch.claims = {
79
+ "/propertyPack/materialFacts/councilTax": {
80
+ councilTaxBand: "D",
81
+ councilTaxAffectingAlterations: {
82
+ yesNo: "Yes",
83
+ details:
84
+ "Extension added in 2005 to add bedroom with ensuite shower room. Certificate of Compliance issued 17th Feb 2006 and council tax updated",
85
+ },
86
+ },
87
+ "/propertyPack/materialFacts/address": {
88
+ line1: "property.line1",
89
+ line2: "property.line2",
90
+ town: "property.city",
91
+ county: "property.province",
92
+ postcode: "property.postcode",
93
+ },
94
+ };
95
+ expect(validateVerifiedClaims(clonedVouch)).toEqual([]);
96
+ });