dataspace-client-sdk-node 0.1.2 → 0.2.1

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.
@@ -0,0 +1,67 @@
1
+ {
2
+ "iss": "did:web:controller.example.org",
3
+ "sub": "did:web:controller.example.org",
4
+ "aud": "did:web:host.example.com",
5
+ "vp": {
6
+ "@context": [
7
+ "https://www.w3.org/ns/credentials/v2"
8
+ ],
9
+ "type": [
10
+ "VerifiablePresentation"
11
+ ],
12
+ "holder": "did:web:controller.example.org",
13
+ "verifiableCredential": [
14
+ {
15
+ "@context": [
16
+ "https://www.w3.org/ns/credentials/v2",
17
+ "https://schema.org"
18
+ ],
19
+ "type": [
20
+ "VerifiableCredential",
21
+ "OrganizationCredential"
22
+ ],
23
+ "issuer": "did:web:localhost%3A3310",
24
+ "credentialSubject": {
25
+ "id": "did:web:globaldatacare.es:onehealth:organization:taxid:VATES-B00000000",
26
+ "@type": "Organization",
27
+ "legalName": "Example Data Provider SL",
28
+ "taxID": "VATES-B00000000",
29
+ "sameAs": "did:web:provider.example.org",
30
+ "url": "provider.example.org",
31
+ "alternateName": "example-provider",
32
+ "identifier": "did:web:globaldatacare.es:onehealth:organization:taxid:VATES-B00000000",
33
+ "identifierType": "TAX",
34
+ "identifierValue": "VATES-B00000000",
35
+ "address": {
36
+ "@type": "PostalAddress",
37
+ "addressCountry": "ES"
38
+ }
39
+ }
40
+ },
41
+ {
42
+ "@context": [
43
+ "https://www.w3.org/ns/credentials/v2",
44
+ "https://schema.org"
45
+ ],
46
+ "type": [
47
+ "VerifiableCredential",
48
+ "PersonCredential",
49
+ "LegalRepresentativeCredential"
50
+ ],
51
+ "issuer": "did:web:localhost%3A3310",
52
+ "credentialSubject": {
53
+ "id": "urn:person:identifier:IDCES-99999999R",
54
+ "@type": "Person",
55
+ "name": "Alex Example",
56
+ "identifier": "IDCES-99999999R",
57
+ "sameAs": "did:web:controller.example.org",
58
+ "memberOf": {
59
+ "@type": "Organization",
60
+ "taxID": "VATES-B00000000"
61
+ }
62
+ }
63
+ }
64
+ ]
65
+ }
66
+ }
67
+
@@ -0,0 +1,23 @@
1
+ import fs from 'node:fs';
2
+
3
+ function b64url(input) {
4
+ return Buffer.from(input).toString('base64url');
5
+ }
6
+
7
+ export function buildUnsignedVpJwt(payload) {
8
+ const now = Math.floor(Date.now() / 1000);
9
+ const header = { alg: 'none', typ: 'JWT' };
10
+ const claims = {
11
+ iat: now,
12
+ exp: now + 600,
13
+ nonce: `nonce-${now}`,
14
+ ...payload,
15
+ };
16
+ return `${b64url(JSON.stringify(header))}.${b64url(JSON.stringify(claims))}.`;
17
+ }
18
+
19
+ export function loadVpPayloadFixture(path) {
20
+ const raw = fs.readFileSync(path, 'utf8');
21
+ return JSON.parse(raw);
22
+ }
23
+
@@ -0,0 +1,108 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { DataspaceNodeClient } from '../dist/index.js';
6
+ import { buildUnsignedVpJwt, loadVpPayloadFixture } from './helpers/vp-token-fixture.mjs';
7
+
8
+ function env(name, fallback = '') {
9
+ const value = String(process.env[name] ?? fallback).trim();
10
+ return value;
11
+ }
12
+
13
+ const RUN = env('RUN_LIVE_GW_E2E', '0') === '1';
14
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
+
16
+ test('LIVE UC5 chain on local GW (legal -> individual -> consent -> professional token)', { skip: !RUN }, async () => {
17
+ const baseUrl = env('BASE_URL', 'http://127.0.0.1:3000');
18
+ const vpTokenEnv = env('VP_TOKEN');
19
+ const vpTokenFile = env('VP_TOKEN_FILE', path.join(__dirname, 'fixtures', 'ica-vp-minimal.json'));
20
+ const tenantId = env('TENANT_ID', 'VATES-B00000000');
21
+ const jurisdiction = env('JURISDICTION', 'ES');
22
+ const sector = env('SECTOR', 'health-care');
23
+ const hostSector = env('HOST_REGISTRY_SECTOR', 'test');
24
+ const professionalIdToken = env(
25
+ 'PROFESSIONAL_ID_TOKEN',
26
+ 'eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiJwcm9mZXNzaW9uYWwifQ.demo',
27
+ );
28
+
29
+ const vpToken = vpTokenEnv || buildUnsignedVpJwt(loadVpPayloadFixture(vpTokenFile));
30
+ assert.ok(vpToken, 'VP_TOKEN or VP_TOKEN_FILE fixture is required for live activation test.');
31
+
32
+ const hostCtx = { jurisdiction, sector: hostSector };
33
+ const ctx = { tenantId, jurisdiction, sector };
34
+ const pollOptions = { timeoutMs: 120000, intervalMs: 1500 };
35
+
36
+ const ping = await fetch(`${baseUrl}/host/.well-known/ping`);
37
+ assert.equal(ping.status, 200, 'GW ping must be healthy before running live UC5 chain.');
38
+
39
+ const legalClient = new DataspaceNodeClient({ baseUrl, ctx });
40
+
41
+ const activation = await legalClient.activateOrganizationInGatewayFromIcaProof(
42
+ hostCtx,
43
+ { vpToken },
44
+ pollOptions,
45
+ );
46
+ assert.equal(activation.poll.status, 200, 'Legal organization activation must complete (200).');
47
+
48
+ const individual = await legalClient.bootstrapSubjectOrganizationIndex(ctx, {
49
+ registrationPayload: {
50
+ body: {
51
+ data: [
52
+ {
53
+ type: 'Family-registration-form-v1.0',
54
+ meta: {
55
+ claims: {
56
+ '@context': 'org.schema',
57
+ 'org.schema.Organization.alternateName': env('INDIVIDUAL_ALTERNATE_NAME', `family-${Date.now()}`),
58
+ 'org.schema.Person.telephone': env('INDIVIDUAL_CONTROLLER_PHONE', 'tel:+34600111222'),
59
+ },
60
+ },
61
+ },
62
+ ],
63
+ },
64
+ },
65
+ pollOptions,
66
+ });
67
+ assert.equal(
68
+ individual.registration.poll.status,
69
+ 200,
70
+ `Individual organization registration must complete (tenantId='${tenantId}' must exist and be resolvable in GW).`,
71
+ );
72
+
73
+ const consent = await legalClient.grantProfessionalAccessSimple(ctx, {
74
+ subjectPhone: env('SUBJECT_PHONE', '+34600111222'),
75
+ subjectGivenName: env('SUBJECT_GIVEN_NAME', 'Ana'),
76
+ actor: { identifier: env('PROFESSIONAL_DID', 'did:web:professional.example.com') },
77
+ actorRole: env('PROFESSIONAL_ROLE', 'Practitioner'),
78
+ purpose: env('CONSENT_PURPOSE', 'TREAT'),
79
+ actions: ['organization/Composition.rs'],
80
+ pollOptions,
81
+ });
82
+ assert.equal(consent.poll.status, 200, 'Consent grant must complete.');
83
+
84
+ const smart = await legalClient.requestSmartTokenSimple({
85
+ tenantId,
86
+ jurisdiction,
87
+ sector,
88
+ idToken: professionalIdToken,
89
+ targetEndpoint: legalClient.getEndpointId(
90
+ {
91
+ section: 'organization',
92
+ format: 'org.hl7.fhir.r4',
93
+ resourceType: 'Composition',
94
+ action: '_search',
95
+ },
96
+ env('PROFESSIONAL_DID', 'did:web:professional.example.com'),
97
+ ),
98
+ scopes: ['organization/Composition.rs'],
99
+ timeoutSeconds: 60,
100
+ intervalSeconds: 2,
101
+ });
102
+
103
+ assert.ok(smart.accessToken, 'Professional SMART token must be issued.');
104
+ assert.ok(
105
+ Array.isArray(smart.scopes) && smart.scopes.includes('organization/Composition.rs'),
106
+ 'SMART token must include organization/Composition.rs scope.',
107
+ );
108
+ });