vet-data-utils-ts 0.5.24 → 0.5.25

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/README.md CHANGED
@@ -211,6 +211,9 @@ Federation 1.0 trust anchors and OpenID4VP 1.0 presentation definitions;
211
211
  catalogue exchange remains Dataspace Protocol 2025-1. X.509/TLS chain
212
212
  validation, federation trust resolution, VP verification and catalogue
213
213
  authorization are separate checks performed by their owning adapters.
214
+ `normalizeHealthDcatResource()` rejects unknown or nested index claims, while
215
+ `projectHealthDcatResourceToJsonLd()` is the explicit standards serialization
216
+ boundary used by host/dataspace adapters.
214
217
 
215
218
  `vet-data-utils-ts/organization-application` is the product-neutral application
216
219
  value used by UHC UNID, VetChain and SOSChain adapters. The host supplies the
@@ -38,6 +38,11 @@ export declare enum ClaimsHealthDcatCatalog {
38
38
  dataset = "dcat.dataset",
39
39
  userSelected = "Catalog.user-selected"
40
40
  }
41
+ /** Complete allowlist for product-persisted HealthDCAT flat claims. */
42
+ export declare const HealthDcatFlatClaimCatalog: Readonly<{
43
+ readonly Dataset: readonly ClaimsHealthDcatDataset[];
44
+ readonly Catalog: readonly ClaimsHealthDcatCatalog[];
45
+ }>;
41
46
  export type HealthDcatResource = Readonly<{
42
47
  resourceType: 'Dataset' | 'Catalog';
43
48
  id: string;
@@ -45,6 +50,10 @@ export type HealthDcatResource = Readonly<{
45
50
  claims: Readonly<Record<string, ClaimValue>>;
46
51
  }>;
47
52
  }>;
53
+ /** Validates an indexed HealthDCAT resource and rejects nested or unknown claims. */
54
+ export declare function normalizeHealthDcatResource(candidate: unknown): HealthDcatResource;
55
+ /** Explicitly projects internal flat claims to DCAT/HealthDCAT JSON-LD. */
56
+ export declare function projectHealthDcatResourceToJsonLd(resource: unknown): Readonly<Record<string, unknown>>;
48
57
  type ControllerAuthority = Readonly<{
49
58
  organizationIdentifier: string;
50
59
  controllerIdentifier: string;
@@ -41,6 +41,86 @@ export var ClaimsHealthDcatCatalog;
41
41
  ClaimsHealthDcatCatalog["dataset"] = "dcat.dataset";
42
42
  ClaimsHealthDcatCatalog["userSelected"] = "Catalog.user-selected";
43
43
  })(ClaimsHealthDcatCatalog || (ClaimsHealthDcatCatalog = {}));
44
+ /** Complete allowlist for product-persisted HealthDCAT flat claims. */
45
+ export const HealthDcatFlatClaimCatalog = Object.freeze({
46
+ Dataset: Object.freeze(Object.values(ClaimsHealthDcatDataset)),
47
+ Catalog: Object.freeze(Object.values(ClaimsHealthDcatCatalog)),
48
+ });
49
+ /** Validates an indexed HealthDCAT resource and rejects nested or unknown claims. */
50
+ export function normalizeHealthDcatResource(candidate) {
51
+ if (!candidate || typeof candidate !== 'object')
52
+ throw new TypeError('health_dcat_resource_invalid');
53
+ const value = candidate;
54
+ if (value.resourceType !== 'Dataset' && value.resourceType !== 'Catalog')
55
+ throw new TypeError('health_dcat_resource_invalid');
56
+ if (typeof value.id !== 'string' || !value.id.trim())
57
+ throw new TypeError('health_dcat_resource_invalid');
58
+ if (!value.meta || typeof value.meta !== 'object' || Array.isArray(value.meta))
59
+ throw new TypeError('health_dcat_resource_invalid');
60
+ const claims = value.meta.claims;
61
+ if (!claims || typeof claims !== 'object' || Array.isArray(claims))
62
+ throw new TypeError('health_dcat_resource_invalid');
63
+ const allowed = HealthDcatFlatClaimCatalog[value.resourceType];
64
+ const normalized = {};
65
+ for (const [claim, raw] of Object.entries(claims)) {
66
+ if (!allowed.includes(claim))
67
+ throw new TypeError(`health_dcat_claim_not_governed:${claim}`);
68
+ if (typeof raw === 'string' || typeof raw === 'boolean' || typeof raw === 'number')
69
+ normalized[claim] = raw;
70
+ else if (Array.isArray(raw) && raw.every(item => typeof item === 'string'))
71
+ normalized[claim] = Object.freeze([...raw]);
72
+ else
73
+ throw new TypeError(`health_dcat_claim_value_invalid:${claim}`);
74
+ }
75
+ return Object.freeze({
76
+ resourceType: value.resourceType,
77
+ id: value.id,
78
+ meta: Object.freeze({ claims: Object.freeze(normalized) }),
79
+ });
80
+ }
81
+ const JsonLdClaimNames = Object.freeze({
82
+ [ClaimsHealthDcatDataset.identifier]: 'dct:identifier',
83
+ [ClaimsHealthDcatDataset.title]: 'dct:title',
84
+ [ClaimsHealthDcatDataset.description]: 'dct:description',
85
+ [ClaimsHealthDcatDataset.creator]: 'dct:creator',
86
+ [ClaimsHealthDcatDataset.publisher]: 'dct:publisher',
87
+ [ClaimsHealthDcatDataset.custodian]: 'geodcatap:custodian',
88
+ [ClaimsHealthDcatDataset.accessRights]: 'dct:accessRights',
89
+ [ClaimsHealthDcatDataset.applicableLegislation]: 'dcatap:applicableLegislation',
90
+ [ClaimsHealthDcatDataset.distribution]: 'dcat:distribution',
91
+ [ClaimsHealthDcatDataset.source]: 'dct:source',
92
+ [ClaimsHealthDcatDataset.provenance]: 'dct:provenance',
93
+ [ClaimsHealthDcatDataset.personalData]: 'dpv:hasPersonalData',
94
+ [ClaimsHealthDcatDataset.healthCategory]: 'healthdcatap:healthCategory',
95
+ [ClaimsHealthDcatDataset.healthDataAccessBody]: 'healthdcatap:hdab',
96
+ [ClaimsHealthDcatDataset.structuredData]: 'healthdcatap:hasStructuredData',
97
+ [ClaimsHealthDcatDataset.variables]: 'healthdcatap:hasVariables',
98
+ [ClaimsHealthDcatDataset.authorizationReference]: 'prov:qualifiedAttribution',
99
+ [ClaimsHealthDcatCatalog.dataset]: 'dcat:dataset',
100
+ });
101
+ /** Explicitly projects internal flat claims to DCAT/HealthDCAT JSON-LD. */
102
+ export function projectHealthDcatResourceToJsonLd(resource) {
103
+ const normalized = normalizeHealthDcatResource(resource);
104
+ const output = {
105
+ '@context': Object.freeze({
106
+ dcat: 'http://www.w3.org/ns/dcat#',
107
+ dct: 'http://purl.org/dc/terms/',
108
+ dcatap: 'http://data.europa.eu/r5r/',
109
+ geodcatap: 'http://data.europa.eu/930/',
110
+ healthdcatap: 'http://healthdataportal.eu/ns/health#',
111
+ dpv: 'https://w3id.org/dpv#',
112
+ prov: 'http://www.w3.org/ns/prov#',
113
+ }),
114
+ '@id': normalized.id,
115
+ '@type': normalized.resourceType === 'Catalog' ? 'dcat:Catalog' : 'dcat:Dataset',
116
+ };
117
+ for (const [claim, value] of Object.entries(normalized.meta.claims)) {
118
+ const jsonLdName = JsonLdClaimNames[claim];
119
+ if (jsonLdName)
120
+ output[jsonLdName] = value;
121
+ }
122
+ return Object.freeze(output);
123
+ }
44
124
  function required(value, field) {
45
125
  const normalized = value.trim();
46
126
  if (!normalized)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vet-data-utils-ts",
3
- "version": "0.5.24",
3
+ "version": "0.5.25",
4
4
  "description": "Browser-safe governed VetChain data contracts",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Connecting Solution & Applications Ltd",