@llamaduck/forgejo-ts 14.0.2 → 14.0.4

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