@eudiplo/sdk-core 1.14.0-main.0f12c71 → 1.14.0-main.551a58f

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,1039 @@
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 serializeUrlSearchParamsPair = (data, key, value) => {
12
+ if (typeof value === "string") {
13
+ data.append(key, value);
14
+ } else {
15
+ data.append(key, JSON.stringify(value));
16
+ }
17
+ };
18
+ var formDataBodySerializer = {
19
+ bodySerializer: (body) => {
20
+ const data = new FormData();
21
+ Object.entries(body).forEach(([key, value]) => {
22
+ if (value === void 0 || value === null) {
23
+ return;
24
+ }
25
+ if (Array.isArray(value)) {
26
+ value.forEach((v) => serializeFormDataPair(data, key, v));
27
+ } else {
28
+ serializeFormDataPair(data, key, value);
29
+ }
30
+ });
31
+ return data;
32
+ }
33
+ };
34
+ var jsonBodySerializer = {
35
+ bodySerializer: (body) => JSON.stringify(
36
+ body,
37
+ (_key, value) => typeof value === "bigint" ? value.toString() : value
38
+ )
39
+ };
40
+ var urlSearchParamsBodySerializer = {
41
+ bodySerializer: (body) => {
42
+ const data = new URLSearchParams();
43
+ Object.entries(body).forEach(([key, value]) => {
44
+ if (value === void 0 || value === null) {
45
+ return;
46
+ }
47
+ if (Array.isArray(value)) {
48
+ value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
49
+ } else {
50
+ serializeUrlSearchParamsPair(data, key, value);
51
+ }
52
+ });
53
+ return data.toString();
54
+ }
55
+ };
56
+
57
+ // src/api/core/params.gen.ts
58
+ var extraPrefixesMap = {
59
+ $body_: "body",
60
+ $headers_: "headers",
61
+ $path_: "path",
62
+ $query_: "query"
63
+ };
64
+ var extraPrefixes = Object.entries(extraPrefixesMap);
65
+ var buildKeyMap = (fields, map) => {
66
+ if (!map) {
67
+ map = /* @__PURE__ */ new Map();
68
+ }
69
+ for (const config of fields) {
70
+ if ("in" in config) {
71
+ if (config.key) {
72
+ map.set(config.key, {
73
+ in: config.in,
74
+ map: config.map
75
+ });
76
+ }
77
+ } else if ("key" in config) {
78
+ map.set(config.key, {
79
+ map: config.map
80
+ });
81
+ } else if (config.args) {
82
+ buildKeyMap(config.args, map);
83
+ }
84
+ }
85
+ return map;
86
+ };
87
+ var stripEmptySlots = (params) => {
88
+ for (const [slot, value] of Object.entries(params)) {
89
+ if (value && typeof value === "object" && !Object.keys(value).length) {
90
+ delete params[slot];
91
+ }
92
+ }
93
+ };
94
+ var buildClientParams = (args, fields) => {
95
+ const params = {
96
+ body: {},
97
+ headers: {},
98
+ path: {},
99
+ query: {}
100
+ };
101
+ const map = buildKeyMap(fields);
102
+ let config;
103
+ for (const [index, arg] of args.entries()) {
104
+ if (fields[index]) {
105
+ config = fields[index];
106
+ }
107
+ if (!config) {
108
+ continue;
109
+ }
110
+ if ("in" in config) {
111
+ if (config.key) {
112
+ const field = map.get(config.key);
113
+ const name = field.map || config.key;
114
+ if (field.in) {
115
+ params[field.in][name] = arg;
116
+ }
117
+ } else {
118
+ params.body = arg;
119
+ }
120
+ } else {
121
+ for (const [key, value] of Object.entries(arg ?? {})) {
122
+ const field = map.get(key);
123
+ if (field) {
124
+ if (field.in) {
125
+ const name = field.map || key;
126
+ params[field.in][name] = value;
127
+ } else {
128
+ params[field.map] = value;
129
+ }
130
+ } else {
131
+ const extra = extraPrefixes.find(
132
+ ([prefix]) => key.startsWith(prefix)
133
+ );
134
+ if (extra) {
135
+ const [prefix, slot] = extra;
136
+ params[slot][key.slice(prefix.length)] = value;
137
+ } else if ("allowExtra" in config && config.allowExtra) {
138
+ for (const [slot, allowed] of Object.entries(config.allowExtra)) {
139
+ if (allowed) {
140
+ params[slot][key] = value;
141
+ break;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ stripEmptySlots(params);
150
+ return params;
151
+ };
152
+
153
+ // src/api/core/queryKeySerializer.gen.ts
154
+ var queryKeyJsonReplacer = (_key, value) => {
155
+ if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
156
+ return void 0;
157
+ }
158
+ if (typeof value === "bigint") {
159
+ return value.toString();
160
+ }
161
+ if (value instanceof Date) {
162
+ return value.toISOString();
163
+ }
164
+ return value;
165
+ };
166
+ var stringifyToJsonValue = (input) => {
167
+ try {
168
+ const json = JSON.stringify(input, queryKeyJsonReplacer);
169
+ if (json === void 0) {
170
+ return void 0;
171
+ }
172
+ return JSON.parse(json);
173
+ } catch {
174
+ return void 0;
175
+ }
176
+ };
177
+ var isPlainObject = (value) => {
178
+ if (value === null || typeof value !== "object") {
179
+ return false;
180
+ }
181
+ const prototype = Object.getPrototypeOf(value);
182
+ return prototype === Object.prototype || prototype === null;
183
+ };
184
+ var serializeSearchParams = (params) => {
185
+ const entries = Array.from(params.entries()).sort(
186
+ ([a], [b]) => a.localeCompare(b)
187
+ );
188
+ const result = {};
189
+ for (const [key, value] of entries) {
190
+ const existing = result[key];
191
+ if (existing === void 0) {
192
+ result[key] = value;
193
+ continue;
194
+ }
195
+ if (Array.isArray(existing)) {
196
+ existing.push(value);
197
+ } else {
198
+ result[key] = [existing, value];
199
+ }
200
+ }
201
+ return result;
202
+ };
203
+ var serializeQueryKeyValue = (value) => {
204
+ if (value === null) {
205
+ return null;
206
+ }
207
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
208
+ return value;
209
+ }
210
+ if (value === void 0 || typeof value === "function" || typeof value === "symbol") {
211
+ return void 0;
212
+ }
213
+ if (typeof value === "bigint") {
214
+ return value.toString();
215
+ }
216
+ if (value instanceof Date) {
217
+ return value.toISOString();
218
+ }
219
+ if (Array.isArray(value)) {
220
+ return stringifyToJsonValue(value);
221
+ }
222
+ if (typeof URLSearchParams !== "undefined" && value instanceof URLSearchParams) {
223
+ return serializeSearchParams(value);
224
+ }
225
+ if (isPlainObject(value)) {
226
+ return stringifyToJsonValue(value);
227
+ }
228
+ return void 0;
229
+ };
230
+
231
+ // src/api/core/serverSentEvents.gen.ts
232
+ var createSseClient = ({
233
+ onRequest,
234
+ onSseError,
235
+ onSseEvent,
236
+ responseTransformer,
237
+ responseValidator,
238
+ sseDefaultRetryDelay,
239
+ sseMaxRetryAttempts,
240
+ sseMaxRetryDelay,
241
+ sseSleepFn,
242
+ url,
243
+ ...options
244
+ }) => {
245
+ let lastEventId;
246
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
247
+ const createStream = async function* () {
248
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
249
+ let attempt = 0;
250
+ const signal = options.signal ?? new AbortController().signal;
251
+ while (true) {
252
+ if (signal.aborted) break;
253
+ attempt++;
254
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
255
+ if (lastEventId !== void 0) {
256
+ headers.set("Last-Event-ID", lastEventId);
257
+ }
258
+ try {
259
+ const requestInit = {
260
+ redirect: "follow",
261
+ ...options,
262
+ body: options.serializedBody,
263
+ headers,
264
+ signal
265
+ };
266
+ let request = new Request(url, requestInit);
267
+ if (onRequest) {
268
+ request = await onRequest(url, requestInit);
269
+ }
270
+ const _fetch = options.fetch ?? globalThis.fetch;
271
+ const response = await _fetch(request);
272
+ if (!response.ok)
273
+ throw new Error(
274
+ `SSE failed: ${response.status} ${response.statusText}`
275
+ );
276
+ if (!response.body) throw new Error("No body in SSE response");
277
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
278
+ let buffer = "";
279
+ const abortHandler = () => {
280
+ try {
281
+ reader.cancel();
282
+ } catch {
283
+ }
284
+ };
285
+ signal.addEventListener("abort", abortHandler);
286
+ try {
287
+ while (true) {
288
+ const { done, value } = await reader.read();
289
+ if (done) break;
290
+ buffer += value;
291
+ buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
292
+ const chunks = buffer.split("\n\n");
293
+ buffer = chunks.pop() ?? "";
294
+ for (const chunk of chunks) {
295
+ const lines = chunk.split("\n");
296
+ const dataLines = [];
297
+ let eventName;
298
+ for (const line of lines) {
299
+ if (line.startsWith("data:")) {
300
+ dataLines.push(line.replace(/^data:\s*/, ""));
301
+ } else if (line.startsWith("event:")) {
302
+ eventName = line.replace(/^event:\s*/, "");
303
+ } else if (line.startsWith("id:")) {
304
+ lastEventId = line.replace(/^id:\s*/, "");
305
+ } else if (line.startsWith("retry:")) {
306
+ const parsed = Number.parseInt(
307
+ line.replace(/^retry:\s*/, ""),
308
+ 10
309
+ );
310
+ if (!Number.isNaN(parsed)) {
311
+ retryDelay = parsed;
312
+ }
313
+ }
314
+ }
315
+ let data;
316
+ let parsedJson = false;
317
+ if (dataLines.length) {
318
+ const rawData = dataLines.join("\n");
319
+ try {
320
+ data = JSON.parse(rawData);
321
+ parsedJson = true;
322
+ } catch {
323
+ data = rawData;
324
+ }
325
+ }
326
+ if (parsedJson) {
327
+ if (responseValidator) {
328
+ await responseValidator(data);
329
+ }
330
+ if (responseTransformer) {
331
+ data = await responseTransformer(data);
332
+ }
333
+ }
334
+ onSseEvent?.({
335
+ data,
336
+ event: eventName,
337
+ id: lastEventId,
338
+ retry: retryDelay
339
+ });
340
+ if (dataLines.length) {
341
+ yield data;
342
+ }
343
+ }
344
+ }
345
+ } finally {
346
+ signal.removeEventListener("abort", abortHandler);
347
+ reader.releaseLock();
348
+ }
349
+ break;
350
+ } catch (error) {
351
+ onSseError?.(error);
352
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
353
+ break;
354
+ }
355
+ const backoff = Math.min(
356
+ retryDelay * 2 ** (attempt - 1),
357
+ sseMaxRetryDelay ?? 3e4
358
+ );
359
+ await sleep(backoff);
360
+ }
361
+ }
362
+ };
363
+ const stream = createStream();
364
+ return { stream };
365
+ };
366
+
367
+ // src/api/core/pathSerializer.gen.ts
368
+ var separatorArrayExplode = (style) => {
369
+ switch (style) {
370
+ case "label":
371
+ return ".";
372
+ case "matrix":
373
+ return ";";
374
+ case "simple":
375
+ return ",";
376
+ default:
377
+ return "&";
378
+ }
379
+ };
380
+ var separatorArrayNoExplode = (style) => {
381
+ switch (style) {
382
+ case "form":
383
+ return ",";
384
+ case "pipeDelimited":
385
+ return "|";
386
+ case "spaceDelimited":
387
+ return "%20";
388
+ default:
389
+ return ",";
390
+ }
391
+ };
392
+ var separatorObjectExplode = (style) => {
393
+ switch (style) {
394
+ case "label":
395
+ return ".";
396
+ case "matrix":
397
+ return ";";
398
+ case "simple":
399
+ return ",";
400
+ default:
401
+ return "&";
402
+ }
403
+ };
404
+ var serializeArrayParam = ({
405
+ allowReserved,
406
+ explode,
407
+ name,
408
+ style,
409
+ value
410
+ }) => {
411
+ if (!explode) {
412
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
413
+ switch (style) {
414
+ case "label":
415
+ return `.${joinedValues2}`;
416
+ case "matrix":
417
+ return `;${name}=${joinedValues2}`;
418
+ case "simple":
419
+ return joinedValues2;
420
+ default:
421
+ return `${name}=${joinedValues2}`;
422
+ }
423
+ }
424
+ const separator = separatorArrayExplode(style);
425
+ const joinedValues = value.map((v) => {
426
+ if (style === "label" || style === "simple") {
427
+ return allowReserved ? v : encodeURIComponent(v);
428
+ }
429
+ return serializePrimitiveParam({
430
+ allowReserved,
431
+ name,
432
+ value: v
433
+ });
434
+ }).join(separator);
435
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
436
+ };
437
+ var serializePrimitiveParam = ({
438
+ allowReserved,
439
+ name,
440
+ value
441
+ }) => {
442
+ if (value === void 0 || value === null) {
443
+ return "";
444
+ }
445
+ if (typeof value === "object") {
446
+ throw new Error(
447
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
448
+ );
449
+ }
450
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
451
+ };
452
+ var serializeObjectParam = ({
453
+ allowReserved,
454
+ explode,
455
+ name,
456
+ style,
457
+ value,
458
+ valueOnly
459
+ }) => {
460
+ if (value instanceof Date) {
461
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
462
+ }
463
+ if (style !== "deepObject" && !explode) {
464
+ let values = [];
465
+ Object.entries(value).forEach(([key, v]) => {
466
+ values = [
467
+ ...values,
468
+ key,
469
+ allowReserved ? v : encodeURIComponent(v)
470
+ ];
471
+ });
472
+ const joinedValues2 = values.join(",");
473
+ switch (style) {
474
+ case "form":
475
+ return `${name}=${joinedValues2}`;
476
+ case "label":
477
+ return `.${joinedValues2}`;
478
+ case "matrix":
479
+ return `;${name}=${joinedValues2}`;
480
+ default:
481
+ return joinedValues2;
482
+ }
483
+ }
484
+ const separator = separatorObjectExplode(style);
485
+ const joinedValues = Object.entries(value).map(
486
+ ([key, v]) => serializePrimitiveParam({
487
+ allowReserved,
488
+ name: style === "deepObject" ? `${name}[${key}]` : key,
489
+ value: v
490
+ })
491
+ ).join(separator);
492
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
493
+ };
494
+
495
+ // src/api/core/utils.gen.ts
496
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
497
+ var defaultPathSerializer = ({ path, url: _url }) => {
498
+ let url = _url;
499
+ const matches = _url.match(PATH_PARAM_RE);
500
+ if (matches) {
501
+ for (const match of matches) {
502
+ let explode = false;
503
+ let name = match.substring(1, match.length - 1);
504
+ let style = "simple";
505
+ if (name.endsWith("*")) {
506
+ explode = true;
507
+ name = name.substring(0, name.length - 1);
508
+ }
509
+ if (name.startsWith(".")) {
510
+ name = name.substring(1);
511
+ style = "label";
512
+ } else if (name.startsWith(";")) {
513
+ name = name.substring(1);
514
+ style = "matrix";
515
+ }
516
+ const value = path[name];
517
+ if (value === void 0 || value === null) {
518
+ continue;
519
+ }
520
+ if (Array.isArray(value)) {
521
+ url = url.replace(
522
+ match,
523
+ serializeArrayParam({ explode, name, style, value })
524
+ );
525
+ continue;
526
+ }
527
+ if (typeof value === "object") {
528
+ url = url.replace(
529
+ match,
530
+ serializeObjectParam({
531
+ explode,
532
+ name,
533
+ style,
534
+ value,
535
+ valueOnly: true
536
+ })
537
+ );
538
+ continue;
539
+ }
540
+ if (style === "matrix") {
541
+ url = url.replace(
542
+ match,
543
+ `;${serializePrimitiveParam({
544
+ name,
545
+ value
546
+ })}`
547
+ );
548
+ continue;
549
+ }
550
+ const replaceValue = encodeURIComponent(
551
+ style === "label" ? `.${value}` : value
552
+ );
553
+ url = url.replace(match, replaceValue);
554
+ }
555
+ }
556
+ return url;
557
+ };
558
+ var getUrl = ({
559
+ baseUrl,
560
+ path,
561
+ query,
562
+ querySerializer,
563
+ url: _url
564
+ }) => {
565
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
566
+ let url = (baseUrl ?? "") + pathUrl;
567
+ if (path) {
568
+ url = defaultPathSerializer({ path, url });
569
+ }
570
+ let search = query ? querySerializer(query) : "";
571
+ if (search.startsWith("?")) {
572
+ search = search.substring(1);
573
+ }
574
+ if (search) {
575
+ url += `?${search}`;
576
+ }
577
+ return url;
578
+ };
579
+ function getValidRequestBody(options) {
580
+ const hasBody = options.body !== void 0;
581
+ const isSerializedBody = hasBody && options.bodySerializer;
582
+ if (isSerializedBody) {
583
+ if ("serializedBody" in options) {
584
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
585
+ return hasSerializedBody ? options.serializedBody : null;
586
+ }
587
+ return options.body !== "" ? options.body : null;
588
+ }
589
+ if (hasBody) {
590
+ return options.body;
591
+ }
592
+ return void 0;
593
+ }
594
+
595
+ // src/api/core/auth.gen.ts
596
+ var getAuthToken = async (auth, callback) => {
597
+ const token = typeof callback === "function" ? await callback(auth) : callback;
598
+ if (!token) {
599
+ return;
600
+ }
601
+ if (auth.scheme === "bearer") {
602
+ return `Bearer ${token}`;
603
+ }
604
+ if (auth.scheme === "basic") {
605
+ return `Basic ${btoa(token)}`;
606
+ }
607
+ return token;
608
+ };
609
+
610
+ // src/api/client/utils.gen.ts
611
+ var createQuerySerializer = ({
612
+ parameters = {},
613
+ ...args
614
+ } = {}) => {
615
+ const querySerializer = (queryParams) => {
616
+ const search = [];
617
+ if (queryParams && typeof queryParams === "object") {
618
+ for (const name in queryParams) {
619
+ const value = queryParams[name];
620
+ if (value === void 0 || value === null) {
621
+ continue;
622
+ }
623
+ const options = parameters[name] || args;
624
+ if (Array.isArray(value)) {
625
+ const serializedArray = serializeArrayParam({
626
+ allowReserved: options.allowReserved,
627
+ explode: true,
628
+ name,
629
+ style: "form",
630
+ value,
631
+ ...options.array
632
+ });
633
+ if (serializedArray) search.push(serializedArray);
634
+ } else if (typeof value === "object") {
635
+ const serializedObject = serializeObjectParam({
636
+ allowReserved: options.allowReserved,
637
+ explode: true,
638
+ name,
639
+ style: "deepObject",
640
+ value,
641
+ ...options.object
642
+ });
643
+ if (serializedObject) search.push(serializedObject);
644
+ } else {
645
+ const serializedPrimitive = serializePrimitiveParam({
646
+ allowReserved: options.allowReserved,
647
+ name,
648
+ value
649
+ });
650
+ if (serializedPrimitive) search.push(serializedPrimitive);
651
+ }
652
+ }
653
+ }
654
+ return search.join("&");
655
+ };
656
+ return querySerializer;
657
+ };
658
+ var getParseAs = (contentType) => {
659
+ if (!contentType) {
660
+ return "stream";
661
+ }
662
+ const cleanContent = contentType.split(";")[0]?.trim();
663
+ if (!cleanContent) {
664
+ return;
665
+ }
666
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
667
+ return "json";
668
+ }
669
+ if (cleanContent === "multipart/form-data") {
670
+ return "formData";
671
+ }
672
+ if (["application/", "audio/", "image/", "video/"].some(
673
+ (type) => cleanContent.startsWith(type)
674
+ )) {
675
+ return "blob";
676
+ }
677
+ if (cleanContent.startsWith("text/")) {
678
+ return "text";
679
+ }
680
+ return;
681
+ };
682
+ var checkForExistence = (options, name) => {
683
+ if (!name) {
684
+ return false;
685
+ }
686
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
687
+ return true;
688
+ }
689
+ return false;
690
+ };
691
+ var setAuthParams = async ({
692
+ security,
693
+ ...options
694
+ }) => {
695
+ for (const auth of security) {
696
+ if (checkForExistence(options, auth.name)) {
697
+ continue;
698
+ }
699
+ const token = await getAuthToken(auth, options.auth);
700
+ if (!token) {
701
+ continue;
702
+ }
703
+ const name = auth.name ?? "Authorization";
704
+ switch (auth.in) {
705
+ case "query":
706
+ if (!options.query) {
707
+ options.query = {};
708
+ }
709
+ options.query[name] = token;
710
+ break;
711
+ case "cookie":
712
+ options.headers.append("Cookie", `${name}=${token}`);
713
+ break;
714
+ case "header":
715
+ default:
716
+ options.headers.set(name, token);
717
+ break;
718
+ }
719
+ }
720
+ };
721
+ var buildUrl = (options) => getUrl({
722
+ baseUrl: options.baseUrl,
723
+ path: options.path,
724
+ query: options.query,
725
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
726
+ url: options.url
727
+ });
728
+ var mergeConfigs = (a, b) => {
729
+ const config = { ...a, ...b };
730
+ if (config.baseUrl?.endsWith("/")) {
731
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
732
+ }
733
+ config.headers = mergeHeaders(a.headers, b.headers);
734
+ return config;
735
+ };
736
+ var headersEntries = (headers) => {
737
+ const entries = [];
738
+ headers.forEach((value, key) => {
739
+ entries.push([key, value]);
740
+ });
741
+ return entries;
742
+ };
743
+ var mergeHeaders = (...headers) => {
744
+ const mergedHeaders = new Headers();
745
+ for (const header of headers) {
746
+ if (!header) {
747
+ continue;
748
+ }
749
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
750
+ for (const [key, value] of iterator) {
751
+ if (value === null) {
752
+ mergedHeaders.delete(key);
753
+ } else if (Array.isArray(value)) {
754
+ for (const v of value) {
755
+ mergedHeaders.append(key, v);
756
+ }
757
+ } else if (value !== void 0) {
758
+ mergedHeaders.set(
759
+ key,
760
+ typeof value === "object" ? JSON.stringify(value) : value
761
+ );
762
+ }
763
+ }
764
+ }
765
+ return mergedHeaders;
766
+ };
767
+ var Interceptors = class {
768
+ fns = [];
769
+ clear() {
770
+ this.fns = [];
771
+ }
772
+ eject(id) {
773
+ const index = this.getInterceptorIndex(id);
774
+ if (this.fns[index]) {
775
+ this.fns[index] = null;
776
+ }
777
+ }
778
+ exists(id) {
779
+ const index = this.getInterceptorIndex(id);
780
+ return Boolean(this.fns[index]);
781
+ }
782
+ getInterceptorIndex(id) {
783
+ if (typeof id === "number") {
784
+ return this.fns[id] ? id : -1;
785
+ }
786
+ return this.fns.indexOf(id);
787
+ }
788
+ update(id, fn) {
789
+ const index = this.getInterceptorIndex(id);
790
+ if (this.fns[index]) {
791
+ this.fns[index] = fn;
792
+ return id;
793
+ }
794
+ return false;
795
+ }
796
+ use(fn) {
797
+ this.fns.push(fn);
798
+ return this.fns.length - 1;
799
+ }
800
+ };
801
+ var createInterceptors = () => ({
802
+ error: new Interceptors(),
803
+ request: new Interceptors(),
804
+ response: new Interceptors()
805
+ });
806
+ var defaultQuerySerializer = createQuerySerializer({
807
+ allowReserved: false,
808
+ array: {
809
+ explode: true,
810
+ style: "form"
811
+ },
812
+ object: {
813
+ explode: true,
814
+ style: "deepObject"
815
+ }
816
+ });
817
+ var defaultHeaders = {
818
+ "Content-Type": "application/json"
819
+ };
820
+ var createConfig = (override = {}) => ({
821
+ ...jsonBodySerializer,
822
+ headers: defaultHeaders,
823
+ parseAs: "auto",
824
+ querySerializer: defaultQuerySerializer,
825
+ ...override
826
+ });
827
+
828
+ // src/api/client/client.gen.ts
829
+ var createClient = (config = {}) => {
830
+ let _config = mergeConfigs(createConfig(), config);
831
+ const getConfig = () => ({ ..._config });
832
+ const setConfig = (config2) => {
833
+ _config = mergeConfigs(_config, config2);
834
+ return getConfig();
835
+ };
836
+ const interceptors = createInterceptors();
837
+ const beforeRequest = async (options) => {
838
+ const opts = {
839
+ ..._config,
840
+ ...options,
841
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
842
+ headers: mergeHeaders(_config.headers, options.headers),
843
+ serializedBody: void 0
844
+ };
845
+ if (opts.security) {
846
+ await setAuthParams({
847
+ ...opts,
848
+ security: opts.security
849
+ });
850
+ }
851
+ if (opts.requestValidator) {
852
+ await opts.requestValidator(opts);
853
+ }
854
+ if (opts.body !== void 0 && opts.bodySerializer) {
855
+ opts.serializedBody = opts.bodySerializer(opts.body);
856
+ }
857
+ if (opts.body === void 0 || opts.serializedBody === "") {
858
+ opts.headers.delete("Content-Type");
859
+ }
860
+ const url = buildUrl(opts);
861
+ return { opts, url };
862
+ };
863
+ const request = async (options) => {
864
+ const { opts, url } = await beforeRequest(options);
865
+ const requestInit = {
866
+ redirect: "follow",
867
+ ...opts,
868
+ body: getValidRequestBody(opts)
869
+ };
870
+ let request2 = new Request(url, requestInit);
871
+ for (const fn of interceptors.request.fns) {
872
+ if (fn) {
873
+ request2 = await fn(request2, opts);
874
+ }
875
+ }
876
+ const _fetch = opts.fetch;
877
+ let response;
878
+ try {
879
+ response = await _fetch(request2);
880
+ } catch (error2) {
881
+ let finalError2 = error2;
882
+ for (const fn of interceptors.error.fns) {
883
+ if (fn) {
884
+ finalError2 = await fn(
885
+ error2,
886
+ void 0,
887
+ request2,
888
+ opts
889
+ );
890
+ }
891
+ }
892
+ finalError2 = finalError2 || {};
893
+ if (opts.throwOnError) {
894
+ throw finalError2;
895
+ }
896
+ return opts.responseStyle === "data" ? void 0 : {
897
+ error: finalError2,
898
+ request: request2,
899
+ response: void 0
900
+ };
901
+ }
902
+ for (const fn of interceptors.response.fns) {
903
+ if (fn) {
904
+ response = await fn(response, request2, opts);
905
+ }
906
+ }
907
+ const result = {
908
+ request: request2,
909
+ response
910
+ };
911
+ if (response.ok) {
912
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
913
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
914
+ let emptyData;
915
+ switch (parseAs) {
916
+ case "arrayBuffer":
917
+ case "blob":
918
+ case "text":
919
+ emptyData = await response[parseAs]();
920
+ break;
921
+ case "formData":
922
+ emptyData = new FormData();
923
+ break;
924
+ case "stream":
925
+ emptyData = response.body;
926
+ break;
927
+ case "json":
928
+ default:
929
+ emptyData = {};
930
+ break;
931
+ }
932
+ return opts.responseStyle === "data" ? emptyData : {
933
+ data: emptyData,
934
+ ...result
935
+ };
936
+ }
937
+ let data;
938
+ switch (parseAs) {
939
+ case "arrayBuffer":
940
+ case "blob":
941
+ case "formData":
942
+ case "json":
943
+ case "text":
944
+ data = await response[parseAs]();
945
+ break;
946
+ case "stream":
947
+ return opts.responseStyle === "data" ? response.body : {
948
+ data: response.body,
949
+ ...result
950
+ };
951
+ }
952
+ if (parseAs === "json") {
953
+ if (opts.responseValidator) {
954
+ await opts.responseValidator(data);
955
+ }
956
+ if (opts.responseTransformer) {
957
+ data = await opts.responseTransformer(data);
958
+ }
959
+ }
960
+ return opts.responseStyle === "data" ? data : {
961
+ data,
962
+ ...result
963
+ };
964
+ }
965
+ const textError = await response.text();
966
+ let jsonError;
967
+ try {
968
+ jsonError = JSON.parse(textError);
969
+ } catch {
970
+ }
971
+ const error = jsonError ?? textError;
972
+ let finalError = error;
973
+ for (const fn of interceptors.error.fns) {
974
+ if (fn) {
975
+ finalError = await fn(error, response, request2, opts);
976
+ }
977
+ }
978
+ finalError = finalError || {};
979
+ if (opts.throwOnError) {
980
+ throw finalError;
981
+ }
982
+ return opts.responseStyle === "data" ? void 0 : {
983
+ error: finalError,
984
+ ...result
985
+ };
986
+ };
987
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
988
+ const makeSseFn = (method) => async (options) => {
989
+ const { opts, url } = await beforeRequest(options);
990
+ return createSseClient({
991
+ ...opts,
992
+ body: opts.body,
993
+ headers: opts.headers,
994
+ method,
995
+ onRequest: async (url2, init) => {
996
+ let request2 = new Request(url2, init);
997
+ for (const fn of interceptors.request.fns) {
998
+ if (fn) {
999
+ request2 = await fn(request2, opts);
1000
+ }
1001
+ }
1002
+ return request2;
1003
+ },
1004
+ serializedBody: getValidRequestBody(opts),
1005
+ url
1006
+ });
1007
+ };
1008
+ return {
1009
+ buildUrl,
1010
+ connect: makeMethodFn("CONNECT"),
1011
+ delete: makeMethodFn("DELETE"),
1012
+ get: makeMethodFn("GET"),
1013
+ getConfig,
1014
+ head: makeMethodFn("HEAD"),
1015
+ interceptors,
1016
+ options: makeMethodFn("OPTIONS"),
1017
+ patch: makeMethodFn("PATCH"),
1018
+ post: makeMethodFn("POST"),
1019
+ put: makeMethodFn("PUT"),
1020
+ request,
1021
+ setConfig,
1022
+ sse: {
1023
+ connect: makeSseFn("CONNECT"),
1024
+ delete: makeSseFn("DELETE"),
1025
+ get: makeSseFn("GET"),
1026
+ head: makeSseFn("HEAD"),
1027
+ options: makeSseFn("OPTIONS"),
1028
+ patch: makeSseFn("PATCH"),
1029
+ post: makeSseFn("POST"),
1030
+ put: makeSseFn("PUT"),
1031
+ trace: makeSseFn("TRACE")
1032
+ },
1033
+ trace: makeMethodFn("TRACE")
1034
+ };
1035
+ };
1036
+
1037
+ export { buildClientParams, createClient, createConfig, formDataBodySerializer, jsonBodySerializer, mergeHeaders, serializeQueryKeyValue, urlSearchParamsBodySerializer };
1038
+ //# sourceMappingURL=index.mjs.map
1039
+ //# sourceMappingURL=index.mjs.map