dataconv-client-sdk-ts 0.2.0 → 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.
@@ -1,127 +0,0 @@
1
- import type { CreateTenantConfigOptions, DataConvClientConfig, DataConvCrypto, SourceFormat } from '../types.js';
2
- import { DEFAULT_SECTOR } from './constants.js';
3
-
4
- export function normalizeSourceFormat(sourceFormat: SourceFormat | undefined, config: DataConvClientConfig): 'excel' | 'csv' {
5
- const raw = String(sourceFormat || config.defaultSourceFormat || 'excel').trim().toLowerCase();
6
- if (raw === 'xlsx') {
7
- return 'excel';
8
- }
9
- if (raw !== 'excel' && raw !== 'csv') {
10
- throw new Error(`Unsupported sourceFormat '${raw}'`);
11
- }
12
- return raw;
13
- }
14
-
15
- export function requireText(value: string | undefined, fieldName: string): string {
16
- const text = String(value || '').trim();
17
- if (!text) {
18
- throw new Error(`${fieldName} is required`);
19
- }
20
- return text;
21
- }
22
-
23
- export function resolveIssuerDid(config: DataConvClientConfig, override?: string): string {
24
- return requireText(override || config.issuerDid, 'issuerDid');
25
- }
26
-
27
- export function resolveSector(config: DataConvClientConfig, override?: string): string {
28
- return requireText(override || config.sector || DEFAULT_SECTOR, 'sector');
29
- }
30
-
31
- export function resolveResourceType(config: DataConvClientConfig, override?: string): string {
32
- return requireText(override || config.defaultResourceType || 'Composition', 'resourceType');
33
- }
34
-
35
- export function resolveConfigTenantId(config: DataConvClientConfig, override?: string): string {
36
- return requireText(override || config.tenantId || config.alternateName, 'tenantId');
37
- }
38
-
39
- export function resolveConfigSoftwareId(options: CreateTenantConfigOptions): string {
40
- const direct = String(options.softwareId || '').trim();
41
- if (direct) {
42
- return direct;
43
- }
44
- const fromFirstEntry = String(options.entries[0]?.softwareId || '').trim();
45
- return requireText(fromFirstEntry, 'softwareId');
46
- }
47
-
48
- export function resolveTenantId(config: DataConvClientConfig, override?: string): string {
49
- return requireText(override || config.tenantId || config.alternateName, 'tenantId');
50
- }
51
-
52
- export function resolveJurisdiction(config: DataConvClientConfig, override?: string): string {
53
- return requireText(override || config.jurisdiction || 'ES', 'jurisdiction');
54
- }
55
-
56
- export function createUuid(cryptoApi: DataConvCrypto | undefined): string {
57
- const uuidFactory = cryptoApi?.randomUUID;
58
- if (typeof uuidFactory === 'function') {
59
- return uuidFactory.call(cryptoApi);
60
- }
61
-
62
- const getRandomValues = cryptoApi?.getRandomValues?.bind(cryptoApi);
63
- if (typeof getRandomValues === 'function') {
64
- const bytes = new Uint8Array(16);
65
- getRandomValues(bytes);
66
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
67
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
68
- const hex = Array.from(bytes, (value) => value.toString(16).padStart(2, '0')).join('');
69
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
70
- }
71
-
72
- throw new Error(
73
- 'Secure random UUID generation is not available in this runtime. ' +
74
- 'Provide DataConvClientConfig.crypto or ensure globalThis.crypto is available.'
75
- );
76
- }
77
-
78
- export function sleep(ms: number): Promise<void> {
79
- return new Promise((resolve) => setTimeout(resolve, ms));
80
- }
81
-
82
- export function buildUrl(baseUrl: string, url: string): string {
83
- if (url.startsWith('http://') || url.startsWith('https://')) {
84
- return url;
85
- }
86
- const base = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
87
- const path = url.startsWith('/') ? url : `/${url}`;
88
- return `${base}${path}`;
89
- }
90
-
91
- export function headerValue(headers: Record<string, string> | undefined, key: string): string | undefined {
92
- if (!headers) {
93
- return undefined;
94
- }
95
- const expectedKey = key.toLowerCase();
96
- const match = Object.entries(headers).find(([headerKey]) => headerKey.toLowerCase() === expectedKey);
97
- return match?.[1];
98
- }
99
-
100
- export function headersToObject(headers: Headers): Record<string, string> {
101
- const result: Record<string, string> = {};
102
- headers.forEach((value, key) => {
103
- result[key.toLowerCase()] = value;
104
- });
105
- return result;
106
- }
107
-
108
- export function isFormData(body: unknown): body is FormData {
109
- return typeof FormData !== 'undefined' && body instanceof FormData;
110
- }
111
-
112
- export function normalizeSearchParams(searchParams: Record<string, unknown> | undefined): Record<string, unknown> {
113
- const normalized: Record<string, unknown> = {};
114
- if (!searchParams || typeof searchParams !== 'object') {
115
- return normalized;
116
- }
117
-
118
- for (const [key, value] of Object.entries(searchParams)) {
119
- const normalizedKey = String(key || '').trim().toLowerCase();
120
- if (!normalizedKey) {
121
- continue;
122
- }
123
- normalized[normalizedKey] = value;
124
- }
125
-
126
- return normalized;
127
- }
@@ -1,139 +0,0 @@
1
- import type {
2
- DataConvClientConfig,
3
- DataConvCrypto,
4
- DataConvDidCommAttachment,
5
- DataConvUploadDidCommOptions,
6
- SourceFormat
7
- } from '../types.js';
8
- import { DEFAULT_DIDCOMM_TYPE } from './constants.js';
9
- import { createUuid, normalizeSourceFormat, resolveIssuerDid } from './helpers.js';
10
-
11
- export function buildAttachment(
12
- source: string | Uint8Array,
13
- options: DataConvUploadDidCommOptions,
14
- cryptoApi: DataConvCrypto | undefined
15
- ): DataConvDidCommAttachment {
16
- const attachmentId = options.attachmentId || createUuid(cryptoApi);
17
- const mediaType = options.mediaType || 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
18
- const attachment: DataConvDidCommAttachment = {
19
- id: attachmentId,
20
- media_type: mediaType
21
- };
22
-
23
- if (options.fileName) {
24
- attachment.filename = options.fileName;
25
- }
26
-
27
- if (typeof source === 'string') {
28
- attachment.data = { links: [source] };
29
- } else {
30
- attachment.data = { base64: Buffer.from(source).toString('base64') };
31
- }
32
-
33
- return attachment;
34
- }
35
-
36
- export function buildUploadExtra(
37
- options: Pick<DataConvUploadDidCommOptions, 'mode' | 'send' | 'inlineConfig' | 'softwareVersion' | 'sourceFormat'>,
38
- config: DataConvClientConfig
39
- ): Record<string, unknown> {
40
- const extra: Record<string, unknown> = {};
41
- if (typeof options.mode === 'string' && options.mode.trim()) {
42
- extra.mode = options.mode.trim();
43
- }
44
- if (typeof options.send === 'boolean') {
45
- extra.send = options.send;
46
- }
47
- if (typeof options.softwareVersion === 'string' && options.softwareVersion.trim()) {
48
- extra.softwareVersion = options.softwareVersion.trim();
49
- }
50
- const sourceFormat = normalizeSourceFormat(options.sourceFormat as SourceFormat | undefined, config);
51
- if (sourceFormat) {
52
- extra.sourceFormat = sourceFormat;
53
- }
54
- if (options.inlineConfig && typeof options.inlineConfig === 'object') {
55
- extra.inlineConfig = options.inlineConfig;
56
- }
57
- return extra;
58
- }
59
-
60
- export function buildEnvelope(
61
- input: {
62
- iss?: string;
63
- thid?: string;
64
- type?: string;
65
- iat?: number;
66
- exp?: number;
67
- idToken?: string;
68
- vpToken?: string;
69
- data?: unknown[];
70
- body?: Record<string, unknown>;
71
- attachments?: DataConvDidCommAttachment[];
72
- extra?: Record<string, unknown>;
73
- },
74
- deps: {
75
- config: DataConvClientConfig;
76
- cryptoApi?: DataConvCrypto;
77
- defaultExpSeconds: number;
78
- currentIdToken?: string;
79
- currentVpToken?: string;
80
- }
81
- ): Record<string, unknown> & { thid: string; jti: string } {
82
- const thid = input.thid?.trim() || createUuid(deps.cryptoApi);
83
- const iat = input.iat ?? Math.floor(Date.now() / 1000);
84
- const exp = input.exp ?? (iat + deps.defaultExpSeconds);
85
- const envelope: Record<string, unknown> & { thid: string; jti: string } = {
86
- iss: resolveIssuerDid(deps.config, input.iss),
87
- thid,
88
- jti: thid,
89
- type: input.type || deps.config.defaultDidCommType || DEFAULT_DIDCOMM_TYPE,
90
- iat,
91
- exp
92
- };
93
-
94
- const idToken = input.idToken || deps.currentIdToken;
95
- const vpToken = input.vpToken || deps.currentVpToken;
96
- if (idToken) {
97
- envelope.id_token = idToken;
98
- }
99
- if (vpToken) {
100
- envelope.vp_token = vpToken;
101
- }
102
- if (Array.isArray(input.data)) {
103
- envelope.data = input.data;
104
- }
105
- if (input.body) {
106
- envelope.body = input.body;
107
- }
108
- if (Array.isArray(input.attachments) && input.attachments.length > 0) {
109
- envelope.attachments = input.attachments;
110
- }
111
- if (input.extra) {
112
- Object.entries(input.extra).forEach(([key, value]) => {
113
- if (value !== undefined) {
114
- envelope[key] = value;
115
- }
116
- });
117
- }
118
-
119
- return envelope;
120
- }
121
-
122
- export function buildMultipartFormData(
123
- fileBytes: Uint8Array,
124
- fileName: string,
125
- mediaType: string,
126
- envelope: Record<string, unknown>
127
- ): FormData {
128
- if (typeof FormData === 'undefined') {
129
- throw new Error('FormData is not available in this runtime');
130
- }
131
-
132
- const formData = new FormData();
133
- const payload = typeof Blob === 'undefined'
134
- ? Buffer.from(fileBytes)
135
- : new Blob([fileBytes], { type: mediaType });
136
- formData.append('file', payload as Blob, fileName);
137
- formData.append('payload', JSON.stringify(envelope));
138
- return formData;
139
- }
package/src/index.ts DELETED
@@ -1,39 +0,0 @@
1
- export { DataConvClient } from './DataConvClient.js';
2
- export { DidCommMessage, DidCommAttachment } from 'gdc-common-utils-ts/utils/didcomm';
3
- export type {
4
- ConversionResultEntry,
5
- ConvertedBundleResource,
6
- CreateTenantConfigEntry,
7
- CreateTenantConfigOptions,
8
- DataConvClientConfig,
9
- DataConvConversionPollOptions,
10
- DataConvCreateResult,
11
- DataConvCrypto,
12
- DataConvDidCommAttachment,
13
- DataConvDidCommAttachmentData,
14
- DataConvDidCommAttachmentPayload,
15
- DataConvDidCommRequest,
16
- DataConvDidCommResponse,
17
- DataConvMultipartUploadOptions,
18
- DataConvOperationOutcome,
19
- DataConvOperationOutcomeIssue,
20
- DataConvPatchOptions,
21
- DataConvPatchResponse,
22
- DataConvSearchBundle,
23
- DataConvSearchBundleEntry,
24
- DataConvSearchOptions,
25
- DataConvTenantConfigPollOptions,
26
- DataConvUploadDidCommOptions,
27
- DataConvUploadResult,
28
- SourceFormat,
29
- TenantAdapterConfigContent,
30
- TenantAdapterConfigEntry,
31
- TenantAdapterConfigResource
32
- } from './types.js';
33
- export {
34
- prepareDidCommRequest,
35
- includeVpTokenInMessage,
36
- includeFileInMessage,
37
- getThidFromMessage,
38
- getDataResults
39
- } from 'gdc-common-utils-ts/utils/didcomm';
package/src/types.ts DELETED
@@ -1,302 +0,0 @@
1
- import type { AxiosInstance } from 'axios';
2
-
3
- export type SourceFormat = 'excel' | 'xlsx' | 'csv';
4
-
5
- export interface DataConvOperationOutcomeIssue {
6
- severity?: string;
7
- code?: string;
8
- diagnostics?: string;
9
- [key: string]: unknown;
10
- }
11
-
12
- export interface DataConvOperationOutcome {
13
- resourceType?: string;
14
- issue?: DataConvOperationOutcomeIssue[];
15
- [key: string]: unknown;
16
- }
17
-
18
- export interface DataConvDidCommAttachmentPayload {
19
- format?: string;
20
- jwt?: string;
21
- [key: string]: unknown;
22
- }
23
-
24
- export interface DataConvDidCommAttachmentData {
25
- json?: DataConvDidCommAttachmentPayload;
26
- links?: string[];
27
- base64?: string;
28
- [key: string]: unknown;
29
- }
30
-
31
- export interface DataConvDidCommAttachment {
32
- id?: string;
33
- format?: string;
34
- media_type?: string;
35
- filename?: string;
36
- data?: DataConvDidCommAttachmentData;
37
- [key: string]: unknown;
38
- }
39
-
40
- export interface DataConvDidCommRequest {
41
- jti: string;
42
- thid: string;
43
- iss: string;
44
- type: string;
45
- iat: number;
46
- exp: number;
47
- body?: Record<string, unknown>;
48
- data?: unknown[];
49
- attachments?: DataConvDidCommAttachment[];
50
- id_token?: string;
51
- vp_token?: string;
52
- [key: string]: unknown;
53
- }
54
-
55
- export interface DataConvCrypto {
56
- randomUUID?: () => string;
57
- getRandomValues?: (array: Uint8Array) => Uint8Array;
58
- }
59
-
60
- export interface TenantAdapterConfigContent {
61
- mappingConfig?: Record<string, unknown>;
62
- speciesFhir?: Record<string, unknown>;
63
- speciesLocalToFhirCode?: Record<string, string>;
64
- runtimeDefaults?: Record<string, unknown>;
65
- [key: string]: unknown;
66
- }
67
-
68
- export interface CreateTenantConfigEntry {
69
- softwareId: string;
70
- softwareVersion?: string;
71
- updatedBy?: string;
72
- config?: TenantAdapterConfigContent;
73
- [key: string]: unknown;
74
- }
75
-
76
- export interface TenantAdapterConfigResource {
77
- id?: string;
78
- type?: string;
79
- tenantId?: string;
80
- alternateName?: string;
81
- softwareId?: string;
82
- country?: string;
83
- facilityId?: string;
84
- revision?: string;
85
- createdAt?: string;
86
- updatedAt?: string;
87
- audit?: Record<string, unknown>;
88
- content?: TenantAdapterConfigContent;
89
- [key: string]: unknown;
90
- }
91
-
92
- export interface TenantAdapterConfigEntry<TResource = unknown> {
93
- type?: string;
94
- response?: {
95
- status?: string;
96
- outcome?: DataConvOperationOutcome;
97
- [key: string]: unknown;
98
- };
99
- resource?: TResource;
100
- [key: string]: unknown;
101
- }
102
-
103
- export interface DataConvBundleResponseBody<TResource = unknown> {
104
- resourceType?: string;
105
- type?: string;
106
- total?: number;
107
- issues?: DataConvOperationOutcome;
108
- data?: Array<TenantAdapterConfigEntry<TResource>>;
109
- [key: string]: unknown;
110
- }
111
-
112
- export interface DataConvDidCommResponse<TResource = unknown> {
113
- jti?: string;
114
- iss?: string;
115
- aud?: string;
116
- thid?: string;
117
- type?: string;
118
- iat?: number;
119
- exp?: number;
120
- attachments?: DataConvDidCommAttachment[];
121
- body?: DataConvBundleResponseBody<TResource>;
122
- [key: string]: unknown;
123
- }
124
-
125
- export interface ConvertedBundleResource {
126
- resourceType?: string;
127
- type?: string;
128
- total?: number;
129
- data?: Array<Record<string, unknown>>;
130
- [key: string]: unknown;
131
- }
132
-
133
- export type ConversionResultEntry = TenantAdapterConfigEntry<ConvertedBundleResource>;
134
-
135
- export interface DataConvClientConfig {
136
- issuerDid: string;
137
- alternateName?: string;
138
- tenantId?: string;
139
- jurisdiction?: string;
140
- sector?: string;
141
- baseUrl?: string;
142
- retryTimes?: number;
143
- retryDelayMs?: number;
144
- defaultExpSeconds?: number;
145
- defaultDidCommType?: string;
146
- defaultSourceFormat?: SourceFormat;
147
- defaultResourceType?: string;
148
- idToken?: string;
149
- vpToken?: string;
150
- httpClient?: AxiosInstance;
151
- fetch?: typeof fetch;
152
- crypto?: DataConvCrypto;
153
- }
154
-
155
- export interface CreateTenantConfigOptions {
156
- alternateName?: string;
157
- tenantId?: string;
158
- jurisdiction?: string;
159
- sector?: string;
160
- softwareId?: string;
161
- thid?: string;
162
- iss?: string;
163
- type?: string;
164
- iat?: number;
165
- exp?: number;
166
- idToken?: string;
167
- vpToken?: string;
168
- entries: CreateTenantConfigEntry[];
169
- }
170
-
171
- export interface DataConvTenantConfigPollOptions {
172
- alternateName?: string;
173
- tenantId?: string;
174
- jurisdiction?: string;
175
- sector?: string;
176
- softwareId: string;
177
- thid: string;
178
- iss?: string;
179
- type?: string;
180
- iat?: number;
181
- exp?: number;
182
- idToken?: string;
183
- vpToken?: string;
184
- }
185
-
186
- export interface DataConvUploadBaseOptions {
187
- alternateName?: string;
188
- tenantId?: string;
189
- jurisdiction?: string;
190
- sector?: string;
191
- softwareId: string;
192
- resourceType?: string;
193
- softwareVersion?: string;
194
- sourceFormat?: SourceFormat;
195
- thid?: string;
196
- iss?: string;
197
- type?: string;
198
- iat?: number;
199
- exp?: number;
200
- idToken?: string;
201
- vpToken?: string;
202
- mode?: string;
203
- send?: boolean;
204
- inlineConfig?: Record<string, unknown>;
205
- }
206
-
207
- export interface DataConvUploadDidCommOptions extends DataConvUploadBaseOptions {
208
- attachmentId?: string;
209
- fileName?: string;
210
- mediaType?: string;
211
- body?: Record<string, unknown>;
212
- }
213
-
214
- export interface DataConvMultipartUploadOptions extends DataConvUploadBaseOptions {
215
- fileBytes: Uint8Array;
216
- fileName?: string;
217
- mediaType?: string;
218
- }
219
-
220
- export interface DataConvConversionPollOptions {
221
- alternateName?: string;
222
- tenantId?: string;
223
- jurisdiction?: string;
224
- sector?: string;
225
- softwareId: string;
226
- resourceType?: string;
227
- thid: string;
228
- iss?: string;
229
- type?: string;
230
- iat?: number;
231
- exp?: number;
232
- idToken?: string;
233
- vpToken?: string;
234
- }
235
-
236
- export interface DataConvPatchOptions {
237
- alternateName?: string;
238
- tenantId?: string;
239
- jurisdiction?: string;
240
- sector?: string;
241
- softwareId: string;
242
- resourceType?: string;
243
- thid: string;
244
- iss?: string;
245
- type?: string;
246
- iat?: number;
247
- exp?: number;
248
- idToken?: string;
249
- vpToken?: string;
250
- }
251
-
252
- export interface DataConvPatchResponseBody {
253
- status?: string;
254
- promotedCount?: number;
255
- message?: string;
256
- [key: string]: unknown;
257
- }
258
-
259
- export interface DataConvPatchResponse {
260
- type?: string;
261
- thid?: string;
262
- body?: DataConvPatchResponseBody;
263
- [key: string]: unknown;
264
- }
265
-
266
- export interface DataConvSearchBundleEntry<TResource = Record<string, unknown>> {
267
- fullUrl?: string;
268
- resource?: TResource;
269
- [key: string]: unknown;
270
- }
271
-
272
- export interface DataConvSearchBundle<TResource = Record<string, unknown>> {
273
- resourceType?: string;
274
- type?: string;
275
- total?: number;
276
- entry?: Array<DataConvSearchBundleEntry<TResource>>;
277
- [key: string]: unknown;
278
- }
279
-
280
- export interface DataConvSearchOptions {
281
- alternateName?: string;
282
- tenantId?: string;
283
- jurisdiction?: string;
284
- sector?: string;
285
- softwareId?: string;
286
- resourceType: string;
287
- searchParams?: Record<string, unknown>;
288
- authorizationToken?: string;
289
- idToken?: string;
290
- }
291
-
292
- export interface DataConvBatchOptions extends DataConvPatchOptions {}
293
-
294
- export interface DataConvCreateResult {
295
- thid: string;
296
- location?: string;
297
- }
298
-
299
- export interface DataConvUploadResult {
300
- thid: string;
301
- location?: string;
302
- }
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ES2020",
5
- "lib": ["ES2020"],
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "declaration": true,
13
- "declarationMap": true,
14
- "sourceMap": true,
15
- "resolveJsonModule": true,
16
- "allowSyntheticDefaultImports": true,
17
- "moduleResolution": "bundler",
18
- },
19
- "include": ["src/**/*"],
20
- "exclude": ["node_modules", "dist", "**/*.test.ts"]
21
- }