gdc-sdk-client-ts 1.1.0 → 1.2.0

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
@@ -264,6 +264,31 @@ const sdk = useMemo(() => {
264
264
  }, []);
265
265
  ```
266
266
 
267
+ ### API Config Discovery For Frontend Forms
268
+
269
+ When a provider API publishes `/.well-known/api-config.json`, the SDK can fetch it and return the form fields in a UI-friendly shape.
270
+
271
+ ```typescript
272
+ const apiConfig = await sdk.fetchWellKnownApiConfig('http://34.8.62.21');
273
+ // or: await sdk.fetchWellKnownApiConfig('did:web:api.example.com');
274
+
275
+ console.log(apiConfig.language); // "es"
276
+ console.log(apiConfig.fields);
277
+ // [
278
+ // { code: 'section', display: 'Departamento o sección: ...' },
279
+ // { code: 'coverage_insurer', display: 'Identificador o nombre de la aseguradora' },
280
+ // ]
281
+
282
+ const supportedFields = await sdk.fetchSupportedFields('http://34.8.62.21');
283
+ ```
284
+
285
+ The resolved object includes:
286
+
287
+ - `language`
288
+ - `supportedFields` as the raw `code -> display` map
289
+ - `fields` as `{ code, display }[]` ready for selects/tables
290
+ - `endpoints` with backend route templates such as `create`, `createResponse`, `upload`, and `uploadResponse`
291
+
267
292
  ### Constructing the Provider DID
268
293
 
269
294
  Before initializing a session, your application must determine the canonical DID of the provider (the organization or host) the user wants to connect to. The SDK supports two scenarios:
@@ -1,7 +1,7 @@
1
1
  import { IWallet } from 'gdc-common-utils-ts/interfaces/IWallet';
2
2
  import { IVaultRepository } from './interfaces/IVaultRepository';
3
3
  import { ProfileManager } from './ProfileManager';
4
- import { SdkConfig } from './interfaces/others';
4
+ import { SdkConfig, WellKnownApiConfigResolved, WellKnownApiSupportedField } from './interfaces/others';
5
5
  import { DidDocument } from 'gdc-common-utils-ts/models/did';
6
6
  import { IVerifier } from './interfaces/ITrustRegistry';
7
7
  import { AppInfo } from './interfaces/others';
@@ -31,6 +31,10 @@ export declare class ClientSDK {
31
31
  currentSession: ProfileManager | null;
32
32
  profileRegistry: ProfileRegistry | null;
33
33
  get operationMode(): string;
34
+ private resolveApiConfigBaseUrl;
35
+ private normalizeWellKnownApiConfig;
36
+ fetchWellKnownApiConfig(source: string): Promise<WellKnownApiConfigResolved>;
37
+ fetchSupportedFields(source: string): Promise<WellKnownApiSupportedField[]>;
34
38
  /**
35
39
  * Dynamically adds a mock DID Document to the SDK's configuration for DEMO mode.
36
40
  * This allows the UI to inject mock data at runtime to bypass network failures.
package/dist/ClientSDK.js CHANGED
@@ -11,6 +11,55 @@ export class ClientSDK {
11
11
  get operationMode() {
12
12
  return this.sdkConfig.api.operationMode;
13
13
  }
14
+ resolveApiConfigBaseUrl(source) {
15
+ const normalized = String(source || '').trim();
16
+ if (!normalized) {
17
+ throw new Error('fetchWellKnownApiConfig requires a provider did:web or a base URL.');
18
+ }
19
+ if (normalized.startsWith('did:web:')) {
20
+ return getBaseUrlFromDidWeb(normalizeDidWeb(normalized));
21
+ }
22
+ return normalized.endsWith('/') ? normalized : `${normalized}/`;
23
+ }
24
+ normalizeWellKnownApiConfig(payload) {
25
+ const raw = (payload && typeof payload === 'object') ? payload : {};
26
+ const supportedFieldsSource = raw.supportedFields && typeof raw.supportedFields === 'object'
27
+ ? raw.supportedFields
28
+ : {};
29
+ const endpointsSource = raw.endpoints && typeof raw.endpoints === 'object'
30
+ ? raw.endpoints
31
+ : {};
32
+ const supportedFields = Object.fromEntries(Object.entries(supportedFieldsSource)
33
+ .filter(([key, value]) => String(key || '').trim() && String(value || '').trim())
34
+ .map(([key, value]) => [String(key).trim(), String(value).trim()]));
35
+ const endpoints = Object.fromEntries(Object.entries(endpointsSource)
36
+ .filter(([key, value]) => String(key || '').trim() && String(value || '').trim())
37
+ .map(([key, value]) => [String(key).trim(), String(value).trim()]));
38
+ const fields = Object.entries(supportedFields).map(([code, display]) => ({
39
+ code,
40
+ display,
41
+ }));
42
+ return {
43
+ language: String(raw.language || '').trim(),
44
+ supportedFields,
45
+ endpoints,
46
+ fields,
47
+ };
48
+ }
49
+ async fetchWellKnownApiConfig(source) {
50
+ const baseUrl = this.resolveApiConfigBaseUrl(source);
51
+ const url = new URL('.well-known/api-config.json', baseUrl).href;
52
+ const response = await this._fetch(url);
53
+ if (!response.ok) {
54
+ throw new Error(`Failed to fetch API config from ${url}`);
55
+ }
56
+ const payload = await response.json();
57
+ return this.normalizeWellKnownApiConfig(payload);
58
+ }
59
+ async fetchSupportedFields(source) {
60
+ const config = await this.fetchWellKnownApiConfig(source);
61
+ return config.fields;
62
+ }
14
63
  /**
15
64
  * Dynamically adds a mock DID Document to the SDK's configuration for DEMO mode.
16
65
  * This allows the UI to inject mock data at runtime to bypass network failures.
@@ -44,6 +44,18 @@ export interface IApiConfig {
44
44
  delayMs: number;
45
45
  } | undefined;
46
46
  }
47
+ export interface WellKnownApiSupportedField {
48
+ code: string;
49
+ display: string;
50
+ }
51
+ export interface WellKnownApiConfigDocument {
52
+ language: string;
53
+ supportedFields: Record<string, string>;
54
+ endpoints: Record<string, string>;
55
+ }
56
+ export interface WellKnownApiConfigResolved extends WellKnownApiConfigDocument {
57
+ fields: WellKnownApiSupportedField[];
58
+ }
47
59
  /**
48
60
  * Defines the set of optional parameters for enabling the SDK's mock mode.
49
61
  * This allows for testing the SDK's logic without a live backend.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdc-sdk-client-ts",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "dependencies": {