@eudiplo/sdk-core 1.14.0-main.0f12c71

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/dist/index.mjs ADDED
@@ -0,0 +1,1575 @@
1
+ // src/api/core/bodySerializer.gen.ts
2
+ var serializeFormDataPair = (data, key, value) => {
3
+ if (typeof value === "string" || value instanceof Blob) {
4
+ data.append(key, value);
5
+ } else if (value instanceof Date) {
6
+ data.append(key, value.toISOString());
7
+ } else {
8
+ data.append(key, JSON.stringify(value));
9
+ }
10
+ };
11
+ var formDataBodySerializer = {
12
+ bodySerializer: (body) => {
13
+ const data = new FormData();
14
+ Object.entries(body).forEach(([key, value]) => {
15
+ if (value === void 0 || value === null) {
16
+ return;
17
+ }
18
+ if (Array.isArray(value)) {
19
+ value.forEach((v) => serializeFormDataPair(data, key, v));
20
+ } else {
21
+ serializeFormDataPair(data, key, value);
22
+ }
23
+ });
24
+ return data;
25
+ }
26
+ };
27
+ var jsonBodySerializer = {
28
+ bodySerializer: (body) => JSON.stringify(
29
+ body,
30
+ (_key, value) => typeof value === "bigint" ? value.toString() : value
31
+ )
32
+ };
33
+
34
+ // src/api/core/serverSentEvents.gen.ts
35
+ var createSseClient = ({
36
+ onRequest,
37
+ onSseError,
38
+ onSseEvent,
39
+ responseTransformer,
40
+ responseValidator,
41
+ sseDefaultRetryDelay,
42
+ sseMaxRetryAttempts,
43
+ sseMaxRetryDelay,
44
+ sseSleepFn,
45
+ url,
46
+ ...options
47
+ }) => {
48
+ let lastEventId;
49
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
50
+ const createStream = async function* () {
51
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
52
+ let attempt = 0;
53
+ const signal = options.signal ?? new AbortController().signal;
54
+ while (true) {
55
+ if (signal.aborted) break;
56
+ attempt++;
57
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
58
+ if (lastEventId !== void 0) {
59
+ headers.set("Last-Event-ID", lastEventId);
60
+ }
61
+ try {
62
+ const requestInit = {
63
+ redirect: "follow",
64
+ ...options,
65
+ body: options.serializedBody,
66
+ headers,
67
+ signal
68
+ };
69
+ let request = new Request(url, requestInit);
70
+ if (onRequest) {
71
+ request = await onRequest(url, requestInit);
72
+ }
73
+ const _fetch = options.fetch ?? globalThis.fetch;
74
+ const response = await _fetch(request);
75
+ if (!response.ok)
76
+ throw new Error(
77
+ `SSE failed: ${response.status} ${response.statusText}`
78
+ );
79
+ if (!response.body) throw new Error("No body in SSE response");
80
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
81
+ let buffer = "";
82
+ const abortHandler = () => {
83
+ try {
84
+ reader.cancel();
85
+ } catch {
86
+ }
87
+ };
88
+ signal.addEventListener("abort", abortHandler);
89
+ try {
90
+ while (true) {
91
+ const { done, value } = await reader.read();
92
+ if (done) break;
93
+ buffer += value;
94
+ buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
95
+ const chunks = buffer.split("\n\n");
96
+ buffer = chunks.pop() ?? "";
97
+ for (const chunk of chunks) {
98
+ const lines = chunk.split("\n");
99
+ const dataLines = [];
100
+ let eventName;
101
+ for (const line of lines) {
102
+ if (line.startsWith("data:")) {
103
+ dataLines.push(line.replace(/^data:\s*/, ""));
104
+ } else if (line.startsWith("event:")) {
105
+ eventName = line.replace(/^event:\s*/, "");
106
+ } else if (line.startsWith("id:")) {
107
+ lastEventId = line.replace(/^id:\s*/, "");
108
+ } else if (line.startsWith("retry:")) {
109
+ const parsed = Number.parseInt(
110
+ line.replace(/^retry:\s*/, ""),
111
+ 10
112
+ );
113
+ if (!Number.isNaN(parsed)) {
114
+ retryDelay = parsed;
115
+ }
116
+ }
117
+ }
118
+ let data;
119
+ let parsedJson = false;
120
+ if (dataLines.length) {
121
+ const rawData = dataLines.join("\n");
122
+ try {
123
+ data = JSON.parse(rawData);
124
+ parsedJson = true;
125
+ } catch {
126
+ data = rawData;
127
+ }
128
+ }
129
+ if (parsedJson) {
130
+ if (responseValidator) {
131
+ await responseValidator(data);
132
+ }
133
+ if (responseTransformer) {
134
+ data = await responseTransformer(data);
135
+ }
136
+ }
137
+ onSseEvent?.({
138
+ data,
139
+ event: eventName,
140
+ id: lastEventId,
141
+ retry: retryDelay
142
+ });
143
+ if (dataLines.length) {
144
+ yield data;
145
+ }
146
+ }
147
+ }
148
+ } finally {
149
+ signal.removeEventListener("abort", abortHandler);
150
+ reader.releaseLock();
151
+ }
152
+ break;
153
+ } catch (error) {
154
+ onSseError?.(error);
155
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
156
+ break;
157
+ }
158
+ const backoff = Math.min(
159
+ retryDelay * 2 ** (attempt - 1),
160
+ sseMaxRetryDelay ?? 3e4
161
+ );
162
+ await sleep(backoff);
163
+ }
164
+ }
165
+ };
166
+ const stream = createStream();
167
+ return { stream };
168
+ };
169
+
170
+ // src/api/core/pathSerializer.gen.ts
171
+ var separatorArrayExplode = (style) => {
172
+ switch (style) {
173
+ case "label":
174
+ return ".";
175
+ case "matrix":
176
+ return ";";
177
+ case "simple":
178
+ return ",";
179
+ default:
180
+ return "&";
181
+ }
182
+ };
183
+ var separatorArrayNoExplode = (style) => {
184
+ switch (style) {
185
+ case "form":
186
+ return ",";
187
+ case "pipeDelimited":
188
+ return "|";
189
+ case "spaceDelimited":
190
+ return "%20";
191
+ default:
192
+ return ",";
193
+ }
194
+ };
195
+ var separatorObjectExplode = (style) => {
196
+ switch (style) {
197
+ case "label":
198
+ return ".";
199
+ case "matrix":
200
+ return ";";
201
+ case "simple":
202
+ return ",";
203
+ default:
204
+ return "&";
205
+ }
206
+ };
207
+ var serializeArrayParam = ({
208
+ allowReserved,
209
+ explode,
210
+ name,
211
+ style,
212
+ value
213
+ }) => {
214
+ if (!explode) {
215
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
216
+ switch (style) {
217
+ case "label":
218
+ return `.${joinedValues2}`;
219
+ case "matrix":
220
+ return `;${name}=${joinedValues2}`;
221
+ case "simple":
222
+ return joinedValues2;
223
+ default:
224
+ return `${name}=${joinedValues2}`;
225
+ }
226
+ }
227
+ const separator = separatorArrayExplode(style);
228
+ const joinedValues = value.map((v) => {
229
+ if (style === "label" || style === "simple") {
230
+ return allowReserved ? v : encodeURIComponent(v);
231
+ }
232
+ return serializePrimitiveParam({
233
+ allowReserved,
234
+ name,
235
+ value: v
236
+ });
237
+ }).join(separator);
238
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
239
+ };
240
+ var serializePrimitiveParam = ({
241
+ allowReserved,
242
+ name,
243
+ value
244
+ }) => {
245
+ if (value === void 0 || value === null) {
246
+ return "";
247
+ }
248
+ if (typeof value === "object") {
249
+ throw new Error(
250
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
251
+ );
252
+ }
253
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
254
+ };
255
+ var serializeObjectParam = ({
256
+ allowReserved,
257
+ explode,
258
+ name,
259
+ style,
260
+ value,
261
+ valueOnly
262
+ }) => {
263
+ if (value instanceof Date) {
264
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
265
+ }
266
+ if (style !== "deepObject" && !explode) {
267
+ let values = [];
268
+ Object.entries(value).forEach(([key, v]) => {
269
+ values = [
270
+ ...values,
271
+ key,
272
+ allowReserved ? v : encodeURIComponent(v)
273
+ ];
274
+ });
275
+ const joinedValues2 = values.join(",");
276
+ switch (style) {
277
+ case "form":
278
+ return `${name}=${joinedValues2}`;
279
+ case "label":
280
+ return `.${joinedValues2}`;
281
+ case "matrix":
282
+ return `;${name}=${joinedValues2}`;
283
+ default:
284
+ return joinedValues2;
285
+ }
286
+ }
287
+ const separator = separatorObjectExplode(style);
288
+ const joinedValues = Object.entries(value).map(
289
+ ([key, v]) => serializePrimitiveParam({
290
+ allowReserved,
291
+ name: style === "deepObject" ? `${name}[${key}]` : key,
292
+ value: v
293
+ })
294
+ ).join(separator);
295
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
296
+ };
297
+
298
+ // src/api/core/utils.gen.ts
299
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
300
+ var defaultPathSerializer = ({ path, url: _url }) => {
301
+ let url = _url;
302
+ const matches = _url.match(PATH_PARAM_RE);
303
+ if (matches) {
304
+ for (const match of matches) {
305
+ let explode = false;
306
+ let name = match.substring(1, match.length - 1);
307
+ let style = "simple";
308
+ if (name.endsWith("*")) {
309
+ explode = true;
310
+ name = name.substring(0, name.length - 1);
311
+ }
312
+ if (name.startsWith(".")) {
313
+ name = name.substring(1);
314
+ style = "label";
315
+ } else if (name.startsWith(";")) {
316
+ name = name.substring(1);
317
+ style = "matrix";
318
+ }
319
+ const value = path[name];
320
+ if (value === void 0 || value === null) {
321
+ continue;
322
+ }
323
+ if (Array.isArray(value)) {
324
+ url = url.replace(
325
+ match,
326
+ serializeArrayParam({ explode, name, style, value })
327
+ );
328
+ continue;
329
+ }
330
+ if (typeof value === "object") {
331
+ url = url.replace(
332
+ match,
333
+ serializeObjectParam({
334
+ explode,
335
+ name,
336
+ style,
337
+ value,
338
+ valueOnly: true
339
+ })
340
+ );
341
+ continue;
342
+ }
343
+ if (style === "matrix") {
344
+ url = url.replace(
345
+ match,
346
+ `;${serializePrimitiveParam({
347
+ name,
348
+ value
349
+ })}`
350
+ );
351
+ continue;
352
+ }
353
+ const replaceValue = encodeURIComponent(
354
+ style === "label" ? `.${value}` : value
355
+ );
356
+ url = url.replace(match, replaceValue);
357
+ }
358
+ }
359
+ return url;
360
+ };
361
+ var getUrl = ({
362
+ baseUrl,
363
+ path,
364
+ query,
365
+ querySerializer,
366
+ url: _url
367
+ }) => {
368
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
369
+ let url = (baseUrl ?? "") + pathUrl;
370
+ if (path) {
371
+ url = defaultPathSerializer({ path, url });
372
+ }
373
+ let search = query ? querySerializer(query) : "";
374
+ if (search.startsWith("?")) {
375
+ search = search.substring(1);
376
+ }
377
+ if (search) {
378
+ url += `?${search}`;
379
+ }
380
+ return url;
381
+ };
382
+ function getValidRequestBody(options) {
383
+ const hasBody = options.body !== void 0;
384
+ const isSerializedBody = hasBody && options.bodySerializer;
385
+ if (isSerializedBody) {
386
+ if ("serializedBody" in options) {
387
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
388
+ return hasSerializedBody ? options.serializedBody : null;
389
+ }
390
+ return options.body !== "" ? options.body : null;
391
+ }
392
+ if (hasBody) {
393
+ return options.body;
394
+ }
395
+ return void 0;
396
+ }
397
+
398
+ // src/api/core/auth.gen.ts
399
+ var getAuthToken = async (auth, callback) => {
400
+ const token = typeof callback === "function" ? await callback(auth) : callback;
401
+ if (!token) {
402
+ return;
403
+ }
404
+ if (auth.scheme === "bearer") {
405
+ return `Bearer ${token}`;
406
+ }
407
+ if (auth.scheme === "basic") {
408
+ return `Basic ${btoa(token)}`;
409
+ }
410
+ return token;
411
+ };
412
+
413
+ // src/api/client/utils.gen.ts
414
+ var createQuerySerializer = ({
415
+ parameters = {},
416
+ ...args
417
+ } = {}) => {
418
+ const querySerializer = (queryParams) => {
419
+ const search = [];
420
+ if (queryParams && typeof queryParams === "object") {
421
+ for (const name in queryParams) {
422
+ const value = queryParams[name];
423
+ if (value === void 0 || value === null) {
424
+ continue;
425
+ }
426
+ const options = parameters[name] || args;
427
+ if (Array.isArray(value)) {
428
+ const serializedArray = serializeArrayParam({
429
+ allowReserved: options.allowReserved,
430
+ explode: true,
431
+ name,
432
+ style: "form",
433
+ value,
434
+ ...options.array
435
+ });
436
+ if (serializedArray) search.push(serializedArray);
437
+ } else if (typeof value === "object") {
438
+ const serializedObject = serializeObjectParam({
439
+ allowReserved: options.allowReserved,
440
+ explode: true,
441
+ name,
442
+ style: "deepObject",
443
+ value,
444
+ ...options.object
445
+ });
446
+ if (serializedObject) search.push(serializedObject);
447
+ } else {
448
+ const serializedPrimitive = serializePrimitiveParam({
449
+ allowReserved: options.allowReserved,
450
+ name,
451
+ value
452
+ });
453
+ if (serializedPrimitive) search.push(serializedPrimitive);
454
+ }
455
+ }
456
+ }
457
+ return search.join("&");
458
+ };
459
+ return querySerializer;
460
+ };
461
+ var getParseAs = (contentType) => {
462
+ if (!contentType) {
463
+ return "stream";
464
+ }
465
+ const cleanContent = contentType.split(";")[0]?.trim();
466
+ if (!cleanContent) {
467
+ return;
468
+ }
469
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
470
+ return "json";
471
+ }
472
+ if (cleanContent === "multipart/form-data") {
473
+ return "formData";
474
+ }
475
+ if (["application/", "audio/", "image/", "video/"].some(
476
+ (type) => cleanContent.startsWith(type)
477
+ )) {
478
+ return "blob";
479
+ }
480
+ if (cleanContent.startsWith("text/")) {
481
+ return "text";
482
+ }
483
+ return;
484
+ };
485
+ var checkForExistence = (options, name) => {
486
+ if (!name) {
487
+ return false;
488
+ }
489
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
490
+ return true;
491
+ }
492
+ return false;
493
+ };
494
+ var setAuthParams = async ({
495
+ security,
496
+ ...options
497
+ }) => {
498
+ for (const auth of security) {
499
+ if (checkForExistence(options, auth.name)) {
500
+ continue;
501
+ }
502
+ const token = await getAuthToken(auth, options.auth);
503
+ if (!token) {
504
+ continue;
505
+ }
506
+ const name = auth.name ?? "Authorization";
507
+ switch (auth.in) {
508
+ case "query":
509
+ if (!options.query) {
510
+ options.query = {};
511
+ }
512
+ options.query[name] = token;
513
+ break;
514
+ case "cookie":
515
+ options.headers.append("Cookie", `${name}=${token}`);
516
+ break;
517
+ case "header":
518
+ default:
519
+ options.headers.set(name, token);
520
+ break;
521
+ }
522
+ }
523
+ };
524
+ var buildUrl = (options) => getUrl({
525
+ baseUrl: options.baseUrl,
526
+ path: options.path,
527
+ query: options.query,
528
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
529
+ url: options.url
530
+ });
531
+ var mergeConfigs = (a, b) => {
532
+ const config = { ...a, ...b };
533
+ if (config.baseUrl?.endsWith("/")) {
534
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
535
+ }
536
+ config.headers = mergeHeaders(a.headers, b.headers);
537
+ return config;
538
+ };
539
+ var headersEntries = (headers) => {
540
+ const entries = [];
541
+ headers.forEach((value, key) => {
542
+ entries.push([key, value]);
543
+ });
544
+ return entries;
545
+ };
546
+ var mergeHeaders = (...headers) => {
547
+ const mergedHeaders = new Headers();
548
+ for (const header of headers) {
549
+ if (!header) {
550
+ continue;
551
+ }
552
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
553
+ for (const [key, value] of iterator) {
554
+ if (value === null) {
555
+ mergedHeaders.delete(key);
556
+ } else if (Array.isArray(value)) {
557
+ for (const v of value) {
558
+ mergedHeaders.append(key, v);
559
+ }
560
+ } else if (value !== void 0) {
561
+ mergedHeaders.set(
562
+ key,
563
+ typeof value === "object" ? JSON.stringify(value) : value
564
+ );
565
+ }
566
+ }
567
+ }
568
+ return mergedHeaders;
569
+ };
570
+ var Interceptors = class {
571
+ fns = [];
572
+ clear() {
573
+ this.fns = [];
574
+ }
575
+ eject(id) {
576
+ const index = this.getInterceptorIndex(id);
577
+ if (this.fns[index]) {
578
+ this.fns[index] = null;
579
+ }
580
+ }
581
+ exists(id) {
582
+ const index = this.getInterceptorIndex(id);
583
+ return Boolean(this.fns[index]);
584
+ }
585
+ getInterceptorIndex(id) {
586
+ if (typeof id === "number") {
587
+ return this.fns[id] ? id : -1;
588
+ }
589
+ return this.fns.indexOf(id);
590
+ }
591
+ update(id, fn) {
592
+ const index = this.getInterceptorIndex(id);
593
+ if (this.fns[index]) {
594
+ this.fns[index] = fn;
595
+ return id;
596
+ }
597
+ return false;
598
+ }
599
+ use(fn) {
600
+ this.fns.push(fn);
601
+ return this.fns.length - 1;
602
+ }
603
+ };
604
+ var createInterceptors = () => ({
605
+ error: new Interceptors(),
606
+ request: new Interceptors(),
607
+ response: new Interceptors()
608
+ });
609
+ var defaultQuerySerializer = createQuerySerializer({
610
+ allowReserved: false,
611
+ array: {
612
+ explode: true,
613
+ style: "form"
614
+ },
615
+ object: {
616
+ explode: true,
617
+ style: "deepObject"
618
+ }
619
+ });
620
+ var defaultHeaders = {
621
+ "Content-Type": "application/json"
622
+ };
623
+ var createConfig = (override = {}) => ({
624
+ ...jsonBodySerializer,
625
+ headers: defaultHeaders,
626
+ parseAs: "auto",
627
+ querySerializer: defaultQuerySerializer,
628
+ ...override
629
+ });
630
+
631
+ // src/api/client/client.gen.ts
632
+ var createClient = (config = {}) => {
633
+ let _config = mergeConfigs(createConfig(), config);
634
+ const getConfig = () => ({ ..._config });
635
+ const setConfig = (config2) => {
636
+ _config = mergeConfigs(_config, config2);
637
+ return getConfig();
638
+ };
639
+ const interceptors = createInterceptors();
640
+ const beforeRequest = async (options) => {
641
+ const opts = {
642
+ ..._config,
643
+ ...options,
644
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
645
+ headers: mergeHeaders(_config.headers, options.headers),
646
+ serializedBody: void 0
647
+ };
648
+ if (opts.security) {
649
+ await setAuthParams({
650
+ ...opts,
651
+ security: opts.security
652
+ });
653
+ }
654
+ if (opts.requestValidator) {
655
+ await opts.requestValidator(opts);
656
+ }
657
+ if (opts.body !== void 0 && opts.bodySerializer) {
658
+ opts.serializedBody = opts.bodySerializer(opts.body);
659
+ }
660
+ if (opts.body === void 0 || opts.serializedBody === "") {
661
+ opts.headers.delete("Content-Type");
662
+ }
663
+ const url = buildUrl(opts);
664
+ return { opts, url };
665
+ };
666
+ const request = async (options) => {
667
+ const { opts, url } = await beforeRequest(options);
668
+ const requestInit = {
669
+ redirect: "follow",
670
+ ...opts,
671
+ body: getValidRequestBody(opts)
672
+ };
673
+ let request2 = new Request(url, requestInit);
674
+ for (const fn of interceptors.request.fns) {
675
+ if (fn) {
676
+ request2 = await fn(request2, opts);
677
+ }
678
+ }
679
+ const _fetch = opts.fetch;
680
+ let response;
681
+ try {
682
+ response = await _fetch(request2);
683
+ } catch (error2) {
684
+ let finalError2 = error2;
685
+ for (const fn of interceptors.error.fns) {
686
+ if (fn) {
687
+ finalError2 = await fn(
688
+ error2,
689
+ void 0,
690
+ request2,
691
+ opts
692
+ );
693
+ }
694
+ }
695
+ finalError2 = finalError2 || {};
696
+ if (opts.throwOnError) {
697
+ throw finalError2;
698
+ }
699
+ return opts.responseStyle === "data" ? void 0 : {
700
+ error: finalError2,
701
+ request: request2,
702
+ response: void 0
703
+ };
704
+ }
705
+ for (const fn of interceptors.response.fns) {
706
+ if (fn) {
707
+ response = await fn(response, request2, opts);
708
+ }
709
+ }
710
+ const result = {
711
+ request: request2,
712
+ response
713
+ };
714
+ if (response.ok) {
715
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
716
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
717
+ let emptyData;
718
+ switch (parseAs) {
719
+ case "arrayBuffer":
720
+ case "blob":
721
+ case "text":
722
+ emptyData = await response[parseAs]();
723
+ break;
724
+ case "formData":
725
+ emptyData = new FormData();
726
+ break;
727
+ case "stream":
728
+ emptyData = response.body;
729
+ break;
730
+ case "json":
731
+ default:
732
+ emptyData = {};
733
+ break;
734
+ }
735
+ return opts.responseStyle === "data" ? emptyData : {
736
+ data: emptyData,
737
+ ...result
738
+ };
739
+ }
740
+ let data;
741
+ switch (parseAs) {
742
+ case "arrayBuffer":
743
+ case "blob":
744
+ case "formData":
745
+ case "json":
746
+ case "text":
747
+ data = await response[parseAs]();
748
+ break;
749
+ case "stream":
750
+ return opts.responseStyle === "data" ? response.body : {
751
+ data: response.body,
752
+ ...result
753
+ };
754
+ }
755
+ if (parseAs === "json") {
756
+ if (opts.responseValidator) {
757
+ await opts.responseValidator(data);
758
+ }
759
+ if (opts.responseTransformer) {
760
+ data = await opts.responseTransformer(data);
761
+ }
762
+ }
763
+ return opts.responseStyle === "data" ? data : {
764
+ data,
765
+ ...result
766
+ };
767
+ }
768
+ const textError = await response.text();
769
+ let jsonError;
770
+ try {
771
+ jsonError = JSON.parse(textError);
772
+ } catch {
773
+ }
774
+ const error = jsonError ?? textError;
775
+ let finalError = error;
776
+ for (const fn of interceptors.error.fns) {
777
+ if (fn) {
778
+ finalError = await fn(error, response, request2, opts);
779
+ }
780
+ }
781
+ finalError = finalError || {};
782
+ if (opts.throwOnError) {
783
+ throw finalError;
784
+ }
785
+ return opts.responseStyle === "data" ? void 0 : {
786
+ error: finalError,
787
+ ...result
788
+ };
789
+ };
790
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
791
+ const makeSseFn = (method) => async (options) => {
792
+ const { opts, url } = await beforeRequest(options);
793
+ return createSseClient({
794
+ ...opts,
795
+ body: opts.body,
796
+ headers: opts.headers,
797
+ method,
798
+ onRequest: async (url2, init) => {
799
+ let request2 = new Request(url2, init);
800
+ for (const fn of interceptors.request.fns) {
801
+ if (fn) {
802
+ request2 = await fn(request2, opts);
803
+ }
804
+ }
805
+ return request2;
806
+ },
807
+ serializedBody: getValidRequestBody(opts),
808
+ url
809
+ });
810
+ };
811
+ return {
812
+ buildUrl,
813
+ connect: makeMethodFn("CONNECT"),
814
+ delete: makeMethodFn("DELETE"),
815
+ get: makeMethodFn("GET"),
816
+ getConfig,
817
+ head: makeMethodFn("HEAD"),
818
+ interceptors,
819
+ options: makeMethodFn("OPTIONS"),
820
+ patch: makeMethodFn("PATCH"),
821
+ post: makeMethodFn("POST"),
822
+ put: makeMethodFn("PUT"),
823
+ request,
824
+ setConfig,
825
+ sse: {
826
+ connect: makeSseFn("CONNECT"),
827
+ delete: makeSseFn("DELETE"),
828
+ get: makeSseFn("GET"),
829
+ head: makeSseFn("HEAD"),
830
+ options: makeSseFn("OPTIONS"),
831
+ patch: makeSseFn("PATCH"),
832
+ post: makeSseFn("POST"),
833
+ put: makeSseFn("PUT"),
834
+ trace: makeSseFn("TRACE")
835
+ },
836
+ trace: makeMethodFn("TRACE")
837
+ };
838
+ };
839
+
840
+ // src/api/client.gen.ts
841
+ var client = createClient(
842
+ createConfig({ throwOnError: true })
843
+ );
844
+
845
+ // src/api/sdk.gen.ts
846
+ var appControllerMain = (options) => (options?.client ?? client).get({ url: "/", ...options });
847
+ var healthControllerCheck = (options) => (options?.client ?? client).get({ url: "/health", ...options });
848
+ var prometheusControllerIndex = (options) => (options?.client ?? client).get({ url: "/metrics", ...options });
849
+ var authControllerGetOAuth2Token = (options) => (options.client ?? client).post({
850
+ url: "/oauth2/token",
851
+ ...options,
852
+ headers: {
853
+ "Content-Type": "application/json",
854
+ ...options.headers
855
+ }
856
+ });
857
+ var authControllerGetOidcDiscovery = (options) => (options?.client ?? client).get({ url: "/.well-known/oauth-authorization-server", ...options });
858
+ var authControllerGetGlobalJwks = (options) => (options?.client ?? client).get({ url: "/.well-known/jwks.json", ...options });
859
+ var tenantControllerGetTenants = (options) => (options?.client ?? client).get({
860
+ security: [{ scheme: "bearer", type: "http" }],
861
+ url: "/tenant",
862
+ ...options
863
+ });
864
+ var tenantControllerInitTenant = (options) => (options.client ?? client).post({
865
+ security: [{ scheme: "bearer", type: "http" }],
866
+ url: "/tenant",
867
+ ...options,
868
+ headers: {
869
+ "Content-Type": "application/json",
870
+ ...options.headers
871
+ }
872
+ });
873
+ var tenantControllerDeleteTenant = (options) => (options.client ?? client).delete({
874
+ security: [{ scheme: "bearer", type: "http" }],
875
+ url: "/tenant/{id}",
876
+ ...options
877
+ });
878
+ var tenantControllerGetTenant = (options) => (options.client ?? client).get({
879
+ security: [{ scheme: "bearer", type: "http" }],
880
+ url: "/tenant/{id}",
881
+ ...options
882
+ });
883
+ var tenantControllerUpdateTenant = (options) => (options.client ?? client).patch({
884
+ security: [{ scheme: "bearer", type: "http" }],
885
+ url: "/tenant/{id}",
886
+ ...options,
887
+ headers: {
888
+ "Content-Type": "application/json",
889
+ ...options.headers
890
+ }
891
+ });
892
+ var clientControllerGetClients = (options) => (options?.client ?? client).get({
893
+ security: [{ scheme: "bearer", type: "http" }],
894
+ url: "/client",
895
+ ...options
896
+ });
897
+ var clientControllerCreateClient = (options) => (options.client ?? client).post({
898
+ security: [{ scheme: "bearer", type: "http" }],
899
+ url: "/client",
900
+ ...options,
901
+ headers: {
902
+ "Content-Type": "application/json",
903
+ ...options.headers
904
+ }
905
+ });
906
+ var clientControllerDeleteClient = (options) => (options.client ?? client).delete({
907
+ security: [{ scheme: "bearer", type: "http" }],
908
+ url: "/client/{id}",
909
+ ...options
910
+ });
911
+ var clientControllerGetClient = (options) => (options.client ?? client).get({
912
+ security: [{ scheme: "bearer", type: "http" }],
913
+ url: "/client/{id}",
914
+ ...options
915
+ });
916
+ var clientControllerUpdateClient = (options) => (options.client ?? client).patch({
917
+ security: [{ scheme: "bearer", type: "http" }],
918
+ url: "/client/{id}",
919
+ ...options,
920
+ headers: {
921
+ "Content-Type": "application/json",
922
+ ...options.headers
923
+ }
924
+ });
925
+ var clientControllerGetClientSecret = (options) => (options.client ?? client).get({
926
+ security: [{ scheme: "bearer", type: "http" }],
927
+ url: "/client/{id}/secret",
928
+ ...options
929
+ });
930
+ var keyControllerGetKeys = (options) => (options?.client ?? client).get({
931
+ security: [{ scheme: "bearer", type: "http" }],
932
+ url: "/key",
933
+ ...options
934
+ });
935
+ var keyControllerAddKey = (options) => (options.client ?? client).post({
936
+ security: [{ scheme: "bearer", type: "http" }],
937
+ url: "/key",
938
+ ...options,
939
+ headers: {
940
+ "Content-Type": "application/json",
941
+ ...options.headers
942
+ }
943
+ });
944
+ var keyControllerDeleteKey = (options) => (options.client ?? client).delete({
945
+ security: [{ scheme: "bearer", type: "http" }],
946
+ url: "/key/{id}",
947
+ ...options
948
+ });
949
+ var keyControllerGetKey = (options) => (options.client ?? client).get({
950
+ security: [{ scheme: "bearer", type: "http" }],
951
+ url: "/key/{id}",
952
+ ...options
953
+ });
954
+ var keyControllerUpdateKey = (options) => (options.client ?? client).put({
955
+ security: [{ scheme: "bearer", type: "http" }],
956
+ url: "/key/{id}",
957
+ ...options,
958
+ headers: {
959
+ "Content-Type": "application/json",
960
+ ...options.headers
961
+ }
962
+ });
963
+ var certControllerGetCertificates = (options) => (options?.client ?? client).get({
964
+ security: [{ scheme: "bearer", type: "http" }],
965
+ url: "/certs",
966
+ ...options
967
+ });
968
+ var certControllerAddCertificate = (options) => (options.client ?? client).post({
969
+ security: [{ scheme: "bearer", type: "http" }],
970
+ url: "/certs",
971
+ ...options,
972
+ headers: {
973
+ "Content-Type": "application/json",
974
+ ...options.headers
975
+ }
976
+ });
977
+ var certControllerDeleteCertificate = (options) => (options.client ?? client).delete({
978
+ security: [{ scheme: "bearer", type: "http" }],
979
+ url: "/certs/{certId}",
980
+ ...options
981
+ });
982
+ var certControllerGetCertificate = (options) => (options.client ?? client).get({
983
+ security: [{ scheme: "bearer", type: "http" }],
984
+ url: "/certs/{certId}",
985
+ ...options
986
+ });
987
+ var certControllerUpdateCertificate = (options) => (options.client ?? client).patch({
988
+ security: [{ scheme: "bearer", type: "http" }],
989
+ url: "/certs/{certId}",
990
+ ...options,
991
+ headers: {
992
+ "Content-Type": "application/json",
993
+ ...options.headers
994
+ }
995
+ });
996
+ var certControllerExportConfig = (options) => (options.client ?? client).get({
997
+ security: [{ scheme: "bearer", type: "http" }],
998
+ url: "/certs/{certId}/config",
999
+ ...options
1000
+ });
1001
+ var statusListControllerGetList = (options) => (options.client ?? client).get({ url: "/{tenantId}/status-management/status-list/{listId}", ...options });
1002
+ var statusListControllerGetStatusListAggregation = (options) => (options.client ?? client).get({
1003
+ url: "/{tenantId}/status-management/status-list-aggregation",
1004
+ ...options
1005
+ });
1006
+ var statusListConfigControllerResetConfig = (options) => (options?.client ?? client).delete({
1007
+ security: [{ scheme: "bearer", type: "http" }],
1008
+ url: "/status-list-config",
1009
+ ...options
1010
+ });
1011
+ var statusListConfigControllerGetConfig = (options) => (options?.client ?? client).get({
1012
+ security: [{ scheme: "bearer", type: "http" }],
1013
+ url: "/status-list-config",
1014
+ ...options
1015
+ });
1016
+ var statusListConfigControllerUpdateConfig = (options) => (options.client ?? client).put({
1017
+ security: [{ scheme: "bearer", type: "http" }],
1018
+ url: "/status-list-config",
1019
+ ...options,
1020
+ headers: {
1021
+ "Content-Type": "application/json",
1022
+ ...options.headers
1023
+ }
1024
+ });
1025
+ var statusListManagementControllerGetLists = (options) => (options?.client ?? client).get({
1026
+ security: [{ scheme: "bearer", type: "http" }],
1027
+ url: "/status-lists",
1028
+ ...options
1029
+ });
1030
+ var statusListManagementControllerCreateList = (options) => (options.client ?? client).post({
1031
+ security: [{ scheme: "bearer", type: "http" }],
1032
+ url: "/status-lists",
1033
+ ...options,
1034
+ headers: {
1035
+ "Content-Type": "application/json",
1036
+ ...options.headers
1037
+ }
1038
+ });
1039
+ var statusListManagementControllerDeleteList = (options) => (options.client ?? client).delete({
1040
+ security: [{ scheme: "bearer", type: "http" }],
1041
+ url: "/status-lists/{listId}",
1042
+ ...options
1043
+ });
1044
+ var statusListManagementControllerGetList = (options) => (options.client ?? client).get({
1045
+ security: [{ scheme: "bearer", type: "http" }],
1046
+ url: "/status-lists/{listId}",
1047
+ ...options
1048
+ });
1049
+ var statusListManagementControllerUpdateList = (options) => (options.client ?? client).patch({
1050
+ security: [{ scheme: "bearer", type: "http" }],
1051
+ url: "/status-lists/{listId}",
1052
+ ...options,
1053
+ headers: {
1054
+ "Content-Type": "application/json",
1055
+ ...options.headers
1056
+ }
1057
+ });
1058
+ var sessionControllerGetAllSessions = (options) => (options?.client ?? client).get({
1059
+ security: [{ scheme: "bearer", type: "http" }],
1060
+ url: "/session",
1061
+ ...options
1062
+ });
1063
+ var sessionControllerDeleteSession = (options) => (options.client ?? client).delete({
1064
+ security: [{ scheme: "bearer", type: "http" }],
1065
+ url: "/session/{id}",
1066
+ ...options
1067
+ });
1068
+ var sessionControllerGetSession = (options) => (options.client ?? client).get({
1069
+ security: [{ scheme: "bearer", type: "http" }],
1070
+ url: "/session/{id}",
1071
+ ...options
1072
+ });
1073
+ var sessionControllerRevokeAll = (options) => (options.client ?? client).post({
1074
+ security: [{ scheme: "bearer", type: "http" }],
1075
+ url: "/session/revoke",
1076
+ ...options,
1077
+ headers: {
1078
+ "Content-Type": "application/json",
1079
+ ...options.headers
1080
+ }
1081
+ });
1082
+ var sessionConfigControllerResetConfig = (options) => (options?.client ?? client).delete({
1083
+ security: [{ scheme: "bearer", type: "http" }],
1084
+ url: "/session-config",
1085
+ ...options
1086
+ });
1087
+ var sessionConfigControllerGetConfig = (options) => (options?.client ?? client).get({
1088
+ security: [{ scheme: "bearer", type: "http" }],
1089
+ url: "/session-config",
1090
+ ...options
1091
+ });
1092
+ var sessionConfigControllerUpdateConfig = (options) => (options.client ?? client).put({
1093
+ security: [{ scheme: "bearer", type: "http" }],
1094
+ url: "/session-config",
1095
+ ...options,
1096
+ headers: {
1097
+ "Content-Type": "application/json",
1098
+ ...options.headers
1099
+ }
1100
+ });
1101
+ var issuanceConfigControllerGetIssuanceConfigurations = (options) => (options?.client ?? client).get({
1102
+ security: [{ scheme: "bearer", type: "http" }],
1103
+ url: "/issuer/config",
1104
+ ...options
1105
+ });
1106
+ var issuanceConfigControllerStoreIssuanceConfiguration = (options) => (options.client ?? client).post({
1107
+ security: [{ scheme: "bearer", type: "http" }],
1108
+ url: "/issuer/config",
1109
+ ...options,
1110
+ headers: {
1111
+ "Content-Type": "application/json",
1112
+ ...options.headers
1113
+ }
1114
+ });
1115
+ var credentialConfigControllerGetConfigs = (options) => (options?.client ?? client).get({
1116
+ security: [{ scheme: "bearer", type: "http" }],
1117
+ url: "/issuer/credentials",
1118
+ ...options
1119
+ });
1120
+ var credentialConfigControllerStoreCredentialConfiguration = (options) => (options.client ?? client).post({
1121
+ security: [{ scheme: "bearer", type: "http" }],
1122
+ url: "/issuer/credentials",
1123
+ ...options,
1124
+ headers: {
1125
+ "Content-Type": "application/json",
1126
+ ...options.headers
1127
+ }
1128
+ });
1129
+ var credentialConfigControllerDeleteIssuanceConfiguration = (options) => (options.client ?? client).delete({
1130
+ security: [{ scheme: "bearer", type: "http" }],
1131
+ url: "/issuer/credentials/{id}",
1132
+ ...options
1133
+ });
1134
+ var credentialConfigControllerGetConfigById = (options) => (options.client ?? client).get({
1135
+ security: [{ scheme: "bearer", type: "http" }],
1136
+ url: "/issuer/credentials/{id}",
1137
+ ...options
1138
+ });
1139
+ var credentialConfigControllerUpdateCredentialConfiguration = (options) => (options.client ?? client).patch({
1140
+ security: [{ scheme: "bearer", type: "http" }],
1141
+ url: "/issuer/credentials/{id}",
1142
+ ...options,
1143
+ headers: {
1144
+ "Content-Type": "application/json",
1145
+ ...options.headers
1146
+ }
1147
+ });
1148
+ var oid4VciControllerCredential = (options) => (options.client ?? client).post({ url: "/{tenantId}/vci/credential", ...options });
1149
+ var oid4VciControllerNotifications = (options) => (options.client ?? client).post({
1150
+ url: "/{tenantId}/vci/notification",
1151
+ ...options,
1152
+ headers: {
1153
+ "Content-Type": "application/json",
1154
+ ...options.headers
1155
+ }
1156
+ });
1157
+ var oid4VciControllerNonce = (options) => (options.client ?? client).post({ url: "/{tenantId}/vci/nonce", ...options });
1158
+ var authorizeControllerAuthorize = (options) => (options.client ?? client).get({ url: "/{tenantId}/authorize", ...options });
1159
+ var authorizeControllerPar = (options) => (options.client ?? client).post({
1160
+ url: "/{tenantId}/authorize/par",
1161
+ ...options,
1162
+ headers: {
1163
+ "Content-Type": "application/json",
1164
+ ...options.headers
1165
+ }
1166
+ });
1167
+ var authorizeControllerToken = (options) => (options.client ?? client).post({ url: "/{tenantId}/authorize/token", ...options });
1168
+ var authorizeControllerAuthorizationChallengeEndpoint = (options) => (options.client ?? client).post({
1169
+ url: "/{tenantId}/authorize/challenge",
1170
+ ...options,
1171
+ headers: {
1172
+ "Content-Type": "application/json",
1173
+ ...options.headers
1174
+ }
1175
+ });
1176
+ var credentialOfferControllerGetOffer = (options) => (options.client ?? client).post({
1177
+ security: [{ scheme: "bearer", type: "http" }],
1178
+ url: "/issuer/offer",
1179
+ ...options,
1180
+ headers: {
1181
+ "Content-Type": "application/json",
1182
+ ...options.headers
1183
+ }
1184
+ });
1185
+ var oid4VciMetadataControllerVct = (options) => (options.client ?? client).get({ url: "/{tenantId}/credentials-metadata/vct/{id}", ...options });
1186
+ var wellKnownControllerIssuerMetadata0 = (options) => (options.client ?? client).get({ url: "/.well-known/openid-credential-issuer/{tenantId}", ...options });
1187
+ var wellKnownControllerIssuerMetadata1 = (options) => (options.client ?? client).get({ url: "/{tenantId}/.well-known/openid-credential-issuer", ...options });
1188
+ var wellKnownControllerAuthzMetadata0 = (options) => (options.client ?? client).get({ url: "/.well-known/oauth-authorization-server/{tenantId}", ...options });
1189
+ var wellKnownControllerAuthzMetadata1 = (options) => (options.client ?? client).get({ url: "/{tenantId}/.well-known/oauth-authorization-server", ...options });
1190
+ var wellKnownControllerGetJwks0 = (options) => (options.client ?? client).get({ url: "/.well-known/jwks.json/{tenantId}", ...options });
1191
+ var wellKnownControllerGetJwks1 = (options) => (options.client ?? client).get({ url: "/{tenantId}/.well-known/jwks.json", ...options });
1192
+ var oid4VpControllerGetRequestWithSession = (options) => (options.client ?? client).get({ url: "/{session}/oid4vp/request", ...options });
1193
+ var oid4VpControllerGetPostRequestWithSession = (options) => (options.client ?? client).post({ url: "/{session}/oid4vp/request", ...options });
1194
+ var oid4VpControllerGetResponse = (options) => (options.client ?? client).post({
1195
+ url: "/{session}/oid4vp",
1196
+ ...options,
1197
+ headers: {
1198
+ "Content-Type": "application/json",
1199
+ ...options.headers
1200
+ }
1201
+ });
1202
+ var presentationManagementControllerConfiguration = (options) => (options?.client ?? client).get({
1203
+ security: [{ scheme: "bearer", type: "http" }],
1204
+ url: "/verifier/config",
1205
+ ...options
1206
+ });
1207
+ var presentationManagementControllerStorePresentationConfig = (options) => (options.client ?? client).post({
1208
+ security: [{ scheme: "bearer", type: "http" }],
1209
+ url: "/verifier/config",
1210
+ ...options,
1211
+ headers: {
1212
+ "Content-Type": "application/json",
1213
+ ...options.headers
1214
+ }
1215
+ });
1216
+ var presentationManagementControllerDeleteConfiguration = (options) => (options.client ?? client).delete({
1217
+ security: [{ scheme: "bearer", type: "http" }],
1218
+ url: "/verifier/config/{id}",
1219
+ ...options
1220
+ });
1221
+ var presentationManagementControllerGetConfiguration = (options) => (options.client ?? client).get({
1222
+ security: [{ scheme: "bearer", type: "http" }],
1223
+ url: "/verifier/config/{id}",
1224
+ ...options
1225
+ });
1226
+ var presentationManagementControllerUpdateConfiguration = (options) => (options.client ?? client).patch({
1227
+ security: [{ scheme: "bearer", type: "http" }],
1228
+ url: "/verifier/config/{id}",
1229
+ ...options,
1230
+ headers: {
1231
+ "Content-Type": "application/json",
1232
+ ...options.headers
1233
+ }
1234
+ });
1235
+ var trustListControllerGetAllTrustLists = (options) => (options?.client ?? client).get({
1236
+ security: [{ scheme: "bearer", type: "http" }],
1237
+ url: "/trust-list",
1238
+ ...options
1239
+ });
1240
+ var trustListControllerCreateTrustList = (options) => (options.client ?? client).post({
1241
+ security: [{ scheme: "bearer", type: "http" }],
1242
+ url: "/trust-list",
1243
+ ...options,
1244
+ headers: {
1245
+ "Content-Type": "application/json",
1246
+ ...options.headers
1247
+ }
1248
+ });
1249
+ var trustListControllerDeleteTrustList = (options) => (options.client ?? client).delete({
1250
+ security: [{ scheme: "bearer", type: "http" }],
1251
+ url: "/trust-list/{id}",
1252
+ ...options
1253
+ });
1254
+ var trustListControllerGetTrustList = (options) => (options.client ?? client).get({
1255
+ security: [{ scheme: "bearer", type: "http" }],
1256
+ url: "/trust-list/{id}",
1257
+ ...options
1258
+ });
1259
+ var trustListControllerUpdateTrustList = (options) => (options.client ?? client).put({
1260
+ security: [{ scheme: "bearer", type: "http" }],
1261
+ url: "/trust-list/{id}",
1262
+ ...options,
1263
+ headers: {
1264
+ "Content-Type": "application/json",
1265
+ ...options.headers
1266
+ }
1267
+ });
1268
+ var trustListControllerExportTrustList = (options) => (options.client ?? client).get({
1269
+ security: [{ scheme: "bearer", type: "http" }],
1270
+ url: "/trust-list/{id}/export",
1271
+ ...options
1272
+ });
1273
+ var trustListControllerGetTrustListVersions = (options) => (options.client ?? client).get({
1274
+ security: [{ scheme: "bearer", type: "http" }],
1275
+ url: "/trust-list/{id}/versions",
1276
+ ...options
1277
+ });
1278
+ var trustListControllerGetTrustListVersion = (options) => (options.client ?? client).get({
1279
+ security: [{ scheme: "bearer", type: "http" }],
1280
+ url: "/trust-list/{id}/versions/{versionId}",
1281
+ ...options
1282
+ });
1283
+ var trustListPublicControllerGetTrustListJwt = (options) => (options.client ?? client).get({ url: "/{tenantId}/trust-list/{id}", ...options });
1284
+ var verifierOfferControllerGetOffer = (options) => (options.client ?? client).post({
1285
+ security: [{ scheme: "bearer", type: "http" }],
1286
+ url: "/verifier/offer",
1287
+ ...options,
1288
+ headers: {
1289
+ "Content-Type": "application/json",
1290
+ ...options.headers
1291
+ }
1292
+ });
1293
+ var storageControllerUpload = (options) => (options.client ?? client).post({
1294
+ ...formDataBodySerializer,
1295
+ security: [{ scheme: "bearer", type: "http" }],
1296
+ url: "/storage",
1297
+ ...options,
1298
+ headers: {
1299
+ "Content-Type": null,
1300
+ ...options.headers
1301
+ }
1302
+ });
1303
+ var storageControllerDownload = (options) => (options.client ?? client).get({ url: "/storage/{key}", ...options });
1304
+
1305
+ // src/client.ts
1306
+ var EudiploClient = class {
1307
+ config;
1308
+ accessToken;
1309
+ tokenExpiresAt;
1310
+ refreshPromise;
1311
+ constructor(config) {
1312
+ this.config = {
1313
+ autoRefresh: true,
1314
+ ...config
1315
+ };
1316
+ client.setConfig({
1317
+ baseUrl: config.baseUrl,
1318
+ fetch: config.fetch
1319
+ });
1320
+ }
1321
+ /**
1322
+ * Authenticate and obtain an access token.
1323
+ * Called automatically by other methods, but can be called explicitly.
1324
+ */
1325
+ async authenticate() {
1326
+ if (this.refreshPromise) {
1327
+ return this.refreshPromise;
1328
+ }
1329
+ this.refreshPromise = this._doAuthenticate();
1330
+ try {
1331
+ await this.refreshPromise;
1332
+ } finally {
1333
+ this.refreshPromise = void 0;
1334
+ }
1335
+ }
1336
+ async _doAuthenticate() {
1337
+ const res = await authControllerGetOAuth2Token({
1338
+ body: {
1339
+ grant_type: "client_credentials",
1340
+ client_id: this.config.clientId,
1341
+ client_secret: this.config.clientSecret
1342
+ }
1343
+ });
1344
+ if (!res.response.ok) {
1345
+ const error = await res.response.text();
1346
+ throw new Error(`Authentication failed: ${res.response.status} ${error}`);
1347
+ }
1348
+ const data = res.data;
1349
+ this.accessToken = data.access_token;
1350
+ this.tokenExpiresAt = Date.now() + data.expires_in * 1e3;
1351
+ client.setConfig({
1352
+ baseUrl: this.config.baseUrl,
1353
+ fetch: this.config.fetch,
1354
+ headers: {
1355
+ Authorization: `Bearer ${this.accessToken}`
1356
+ }
1357
+ });
1358
+ }
1359
+ /**
1360
+ * Ensure we have a valid access token, refreshing if necessary.
1361
+ */
1362
+ async ensureAuthenticated() {
1363
+ const bufferMs = 6e4;
1364
+ if (!this.accessToken || !this.tokenExpiresAt) {
1365
+ await this.authenticate();
1366
+ return;
1367
+ }
1368
+ if (this.config.autoRefresh && Date.now() > this.tokenExpiresAt - bufferMs) {
1369
+ await this.authenticate();
1370
+ }
1371
+ }
1372
+ /**
1373
+ * Create a credential issuance offer.
1374
+ *
1375
+ * @example
1376
+ * ```typescript
1377
+ * const { uri, sessionId } = await client.createIssuanceOffer({
1378
+ * credentialConfigurationIds: ['PID'],
1379
+ * claims: {
1380
+ * PID: { given_name: 'John', family_name: 'Doe' }
1381
+ * }
1382
+ * });
1383
+ * ```
1384
+ */
1385
+ async createIssuanceOffer(options) {
1386
+ await this.ensureAuthenticated();
1387
+ const body = {
1388
+ response_type: options.responseType ?? "uri",
1389
+ credentialConfigurationIds: options.credentialConfigurationIds,
1390
+ flow: options.flow ?? "pre_authorized_code",
1391
+ tx_code: options.txCode
1392
+ };
1393
+ if (options.claims) {
1394
+ body.credentialClaims = {
1395
+ additionalProperties: void 0
1396
+ };
1397
+ for (const [configId, claims] of Object.entries(options.claims)) {
1398
+ body.credentialClaims[configId] = {
1399
+ type: "inline",
1400
+ claims
1401
+ };
1402
+ }
1403
+ }
1404
+ const response = await credentialOfferControllerGetOffer({
1405
+ body
1406
+ });
1407
+ if (!response.data) {
1408
+ throw new Error("Failed to create issuance offer");
1409
+ }
1410
+ return {
1411
+ uri: response.data.uri,
1412
+ sessionId: response.data.session
1413
+ };
1414
+ }
1415
+ /**
1416
+ * Create a presentation request (for verification).
1417
+ *
1418
+ * @example
1419
+ * ```typescript
1420
+ * // Age verification
1421
+ * const { uri, sessionId } = await client.createPresentationRequest({
1422
+ * configId: 'age-over-18'
1423
+ * });
1424
+ *
1425
+ * // Show QR code, wait for wallet to respond
1426
+ * const session = await client.waitForSession(sessionId);
1427
+ * ```
1428
+ */
1429
+ async createPresentationRequest(options) {
1430
+ await this.ensureAuthenticated();
1431
+ const body = {
1432
+ response_type: options.responseType ?? "uri",
1433
+ requestId: options.configId,
1434
+ redirectUri: options.redirectUri
1435
+ };
1436
+ const response = await verifierOfferControllerGetOffer({
1437
+ body
1438
+ });
1439
+ if (!response.data) {
1440
+ throw new Error("Failed to create presentation request");
1441
+ }
1442
+ return {
1443
+ uri: response.data.uri,
1444
+ sessionId: response.data.session
1445
+ };
1446
+ }
1447
+ /**
1448
+ * Get the current status of a session.
1449
+ */
1450
+ async getSession(sessionId) {
1451
+ await this.ensureAuthenticated();
1452
+ const response = await sessionControllerGetSession({
1453
+ path: { id: sessionId }
1454
+ });
1455
+ if (!response.data) {
1456
+ throw new Error(`Session not found: ${sessionId}`);
1457
+ }
1458
+ return response.data;
1459
+ }
1460
+ /**
1461
+ * Wait for a session to complete (polling).
1462
+ *
1463
+ * @example
1464
+ * ```typescript
1465
+ * const session = await client.waitForSession(sessionId, {
1466
+ * interval: 1000,
1467
+ * timeout: 60000,
1468
+ * onUpdate: (s) => console.log('Status:', s.status)
1469
+ * });
1470
+ * ```
1471
+ */
1472
+ async waitForSession(sessionId, options = {}) {
1473
+ const {
1474
+ interval = 1e3,
1475
+ timeout = 3e5,
1476
+ onUpdate,
1477
+ signal
1478
+ } = options;
1479
+ const startTime = Date.now();
1480
+ while (true) {
1481
+ if (signal?.aborted) {
1482
+ throw new Error("Session polling aborted");
1483
+ }
1484
+ if (Date.now() - startTime > timeout) {
1485
+ throw new Error(`Session polling timed out after ${timeout}ms`);
1486
+ }
1487
+ const session = await this.getSession(sessionId);
1488
+ if (onUpdate) {
1489
+ onUpdate(session);
1490
+ }
1491
+ if (session.status === "completed") {
1492
+ return session;
1493
+ }
1494
+ if (session.status === "expired" || session.status === "failed") {
1495
+ throw new Error(`Session ${session.status}: ${sessionId}`);
1496
+ }
1497
+ await this.sleep(interval, signal);
1498
+ }
1499
+ }
1500
+ /**
1501
+ * Helper to sleep with abort support
1502
+ */
1503
+ sleep(ms, signal) {
1504
+ return new Promise((resolve, reject) => {
1505
+ const timeoutId = setTimeout(resolve, ms);
1506
+ if (signal) {
1507
+ signal.addEventListener("abort", () => {
1508
+ clearTimeout(timeoutId);
1509
+ reject(new Error("Aborted"));
1510
+ }, { once: true });
1511
+ }
1512
+ });
1513
+ }
1514
+ /**
1515
+ * Get the current access token (for advanced usage)
1516
+ */
1517
+ getAccessToken() {
1518
+ return this.accessToken;
1519
+ }
1520
+ /**
1521
+ * Get the configured base URL
1522
+ */
1523
+ getBaseUrl() {
1524
+ return this.config.baseUrl;
1525
+ }
1526
+ };
1527
+ async function verify(options) {
1528
+ const client2 = new EudiploClient({
1529
+ baseUrl: options.baseUrl,
1530
+ clientId: options.clientId,
1531
+ clientSecret: options.clientSecret
1532
+ });
1533
+ const { uri, sessionId } = await client2.createPresentationRequest({
1534
+ configId: options.configId,
1535
+ redirectUri: options.redirectUri
1536
+ });
1537
+ return {
1538
+ uri,
1539
+ sessionId,
1540
+ waitForCompletion: (pollingOptions) => client2.waitForSession(sessionId, { ...options.polling, ...pollingOptions }),
1541
+ getStatus: () => client2.getSession(sessionId)
1542
+ };
1543
+ }
1544
+ async function issue(options) {
1545
+ const client2 = new EudiploClient({
1546
+ baseUrl: options.baseUrl,
1547
+ clientId: options.clientId,
1548
+ clientSecret: options.clientSecret
1549
+ });
1550
+ const { uri, sessionId } = await client2.createIssuanceOffer({
1551
+ credentialConfigurationIds: options.credentialConfigurationIds,
1552
+ claims: options.claims,
1553
+ txCode: options.txCode
1554
+ });
1555
+ return {
1556
+ uri,
1557
+ sessionId,
1558
+ waitForCompletion: (pollingOptions) => client2.waitForSession(sessionId, { ...options.polling, ...pollingOptions }),
1559
+ getStatus: () => client2.getSession(sessionId)
1560
+ };
1561
+ }
1562
+ async function verifyAndWait(options) {
1563
+ const { uri, waitForCompletion } = await verify(options);
1564
+ options.onUri(uri);
1565
+ return waitForCompletion(options.polling);
1566
+ }
1567
+ async function issueAndWait(options) {
1568
+ const { uri, waitForCompletion } = await issue(options);
1569
+ options.onUri(uri);
1570
+ return waitForCompletion(options.polling);
1571
+ }
1572
+
1573
+ export { EudiploClient, appControllerMain, authControllerGetGlobalJwks, authControllerGetOAuth2Token, authControllerGetOidcDiscovery, authorizeControllerAuthorizationChallengeEndpoint, authorizeControllerAuthorize, authorizeControllerPar, authorizeControllerToken, certControllerAddCertificate, certControllerDeleteCertificate, certControllerExportConfig, certControllerGetCertificate, certControllerGetCertificates, certControllerUpdateCertificate, clientControllerCreateClient, clientControllerDeleteClient, clientControllerGetClient, clientControllerGetClientSecret, clientControllerGetClients, clientControllerUpdateClient, credentialConfigControllerDeleteIssuanceConfiguration, credentialConfigControllerGetConfigById, credentialConfigControllerGetConfigs, credentialConfigControllerStoreCredentialConfiguration, credentialConfigControllerUpdateCredentialConfiguration, credentialOfferControllerGetOffer, healthControllerCheck, issuanceConfigControllerGetIssuanceConfigurations, issuanceConfigControllerStoreIssuanceConfiguration, issue, issueAndWait, keyControllerAddKey, keyControllerDeleteKey, keyControllerGetKey, keyControllerGetKeys, keyControllerUpdateKey, oid4VciControllerCredential, oid4VciControllerNonce, oid4VciControllerNotifications, oid4VciMetadataControllerVct, oid4VpControllerGetPostRequestWithSession, oid4VpControllerGetRequestWithSession, oid4VpControllerGetResponse, presentationManagementControllerConfiguration, presentationManagementControllerDeleteConfiguration, presentationManagementControllerGetConfiguration, presentationManagementControllerStorePresentationConfig, presentationManagementControllerUpdateConfiguration, prometheusControllerIndex, sessionConfigControllerGetConfig, sessionConfigControllerResetConfig, sessionConfigControllerUpdateConfig, sessionControllerDeleteSession, sessionControllerGetAllSessions, sessionControllerGetSession, sessionControllerRevokeAll, statusListConfigControllerGetConfig, statusListConfigControllerResetConfig, statusListConfigControllerUpdateConfig, statusListControllerGetList, statusListControllerGetStatusListAggregation, statusListManagementControllerCreateList, statusListManagementControllerDeleteList, statusListManagementControllerGetList, statusListManagementControllerGetLists, statusListManagementControllerUpdateList, storageControllerDownload, storageControllerUpload, tenantControllerDeleteTenant, tenantControllerGetTenant, tenantControllerGetTenants, tenantControllerInitTenant, tenantControllerUpdateTenant, trustListControllerCreateTrustList, trustListControllerDeleteTrustList, trustListControllerExportTrustList, trustListControllerGetAllTrustLists, trustListControllerGetTrustList, trustListControllerGetTrustListVersion, trustListControllerGetTrustListVersions, trustListControllerUpdateTrustList, trustListPublicControllerGetTrustListJwt, verifierOfferControllerGetOffer, verify, verifyAndWait, wellKnownControllerAuthzMetadata0, wellKnownControllerAuthzMetadata1, wellKnownControllerGetJwks0, wellKnownControllerGetJwks1, wellKnownControllerIssuerMetadata0, wellKnownControllerIssuerMetadata1 };
1574
+ //# sourceMappingURL=index.mjs.map
1575
+ //# sourceMappingURL=index.mjs.map