@nextplus/js-sdk 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +228 -0
- package/dist/chunk-YEF23TVP.js +222 -0
- package/dist/index-B0kRliN0.d.ts +5156 -0
- package/dist/index-Dz0aDLqE.d.cts +5156 -0
- package/dist/index.cjs +21668 -0
- package/dist/index.d.cts +44 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +66 -221
- package/dist/sdk/client/index.cjs +750 -0
- package/dist/sdk/client/index.d.cts +39 -0
- package/dist/sdk/index.cjs +21543 -0
- package/dist/sdk/index.d.cts +2 -0
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/index.js +214 -0
- package/dist/sdk/sdk.gen.cjs +21543 -0
- package/dist/sdk/sdk.gen.d.cts +2 -0
- package/dist/sdk/sdk.gen.d.ts +2 -34568
- package/dist/sdk.gen-CPR3KdM-.d.cts +39508 -0
- package/dist/sdk.gen-D3Q8YKqz.d.ts +39508 -0
- package/dist/types.gen-vDP9AbtO.d.cts +258 -0
- package/openapi-ts.config.ts +10 -1
- package/package.json +24 -5
- package/src/index.ts +90 -7
- package/src/sdk/types.gen.ts +1 -0
- package/src/smoke.ts +37 -22
- package/src/README.md +0 -0
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/sdk/client/index.ts
|
|
23
|
+
var client_exports = {};
|
|
24
|
+
__export(client_exports, {
|
|
25
|
+
buildClientParams: () => buildClientParams,
|
|
26
|
+
createClient: () => createClient,
|
|
27
|
+
createConfig: () => createConfig,
|
|
28
|
+
formDataBodySerializer: () => formDataBodySerializer,
|
|
29
|
+
jsonBodySerializer: () => jsonBodySerializer,
|
|
30
|
+
mergeHeaders: () => mergeHeaders,
|
|
31
|
+
urlSearchParamsBodySerializer: () => urlSearchParamsBodySerializer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(client_exports);
|
|
34
|
+
|
|
35
|
+
// src/sdk/core/bodySerializer.gen.ts
|
|
36
|
+
var serializeFormDataPair = (data, key, value) => {
|
|
37
|
+
if (typeof value === "string" || value instanceof Blob) {
|
|
38
|
+
data.append(key, value);
|
|
39
|
+
} else {
|
|
40
|
+
data.append(key, JSON.stringify(value));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var serializeUrlSearchParamsPair = (data, key, value) => {
|
|
44
|
+
if (typeof value === "string") {
|
|
45
|
+
data.append(key, value);
|
|
46
|
+
} else {
|
|
47
|
+
data.append(key, JSON.stringify(value));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var formDataBodySerializer = {
|
|
51
|
+
bodySerializer: (body) => {
|
|
52
|
+
const data = new FormData();
|
|
53
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
54
|
+
if (value === void 0 || value === null) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
value.forEach((v) => serializeFormDataPair(data, key, v));
|
|
59
|
+
} else {
|
|
60
|
+
serializeFormDataPair(data, key, value);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var jsonBodySerializer = {
|
|
67
|
+
bodySerializer: (body) => JSON.stringify(
|
|
68
|
+
body,
|
|
69
|
+
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
70
|
+
)
|
|
71
|
+
};
|
|
72
|
+
var urlSearchParamsBodySerializer = {
|
|
73
|
+
bodySerializer: (body) => {
|
|
74
|
+
const data = new URLSearchParams();
|
|
75
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
76
|
+
if (value === void 0 || value === null) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
|
|
81
|
+
} else {
|
|
82
|
+
serializeUrlSearchParamsPair(data, key, value);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return data.toString();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/sdk/core/params.gen.ts
|
|
90
|
+
var extraPrefixesMap = {
|
|
91
|
+
$body_: "body",
|
|
92
|
+
$headers_: "headers",
|
|
93
|
+
$path_: "path",
|
|
94
|
+
$query_: "query"
|
|
95
|
+
};
|
|
96
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
97
|
+
var buildKeyMap = (fields, map) => {
|
|
98
|
+
if (!map) {
|
|
99
|
+
map = /* @__PURE__ */ new Map();
|
|
100
|
+
}
|
|
101
|
+
for (const config of fields) {
|
|
102
|
+
if ("in" in config) {
|
|
103
|
+
if (config.key) {
|
|
104
|
+
map.set(config.key, {
|
|
105
|
+
in: config.in,
|
|
106
|
+
map: config.map
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
} else if (config.args) {
|
|
110
|
+
buildKeyMap(config.args, map);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return map;
|
|
114
|
+
};
|
|
115
|
+
var stripEmptySlots = (params) => {
|
|
116
|
+
for (const [slot, value] of Object.entries(params)) {
|
|
117
|
+
if (value && typeof value === "object" && !Object.keys(value).length) {
|
|
118
|
+
delete params[slot];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var buildClientParams = (args, fields) => {
|
|
123
|
+
const params = {
|
|
124
|
+
body: {},
|
|
125
|
+
headers: {},
|
|
126
|
+
path: {},
|
|
127
|
+
query: {}
|
|
128
|
+
};
|
|
129
|
+
const map = buildKeyMap(fields);
|
|
130
|
+
let config;
|
|
131
|
+
for (const [index, arg] of args.entries()) {
|
|
132
|
+
if (fields[index]) {
|
|
133
|
+
config = fields[index];
|
|
134
|
+
}
|
|
135
|
+
if (!config) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if ("in" in config) {
|
|
139
|
+
if (config.key) {
|
|
140
|
+
const field = map.get(config.key);
|
|
141
|
+
const name = field.map || config.key;
|
|
142
|
+
params[field.in][name] = arg;
|
|
143
|
+
} else {
|
|
144
|
+
params.body = arg;
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
for (const [key, value] of Object.entries(arg ?? {})) {
|
|
148
|
+
const field = map.get(key);
|
|
149
|
+
if (field) {
|
|
150
|
+
const name = field.map || key;
|
|
151
|
+
params[field.in][name] = value;
|
|
152
|
+
} else {
|
|
153
|
+
const extra = extraPrefixes.find(
|
|
154
|
+
([prefix]) => key.startsWith(prefix)
|
|
155
|
+
);
|
|
156
|
+
if (extra) {
|
|
157
|
+
const [prefix, slot] = extra;
|
|
158
|
+
params[slot][key.slice(prefix.length)] = value;
|
|
159
|
+
} else {
|
|
160
|
+
for (const [slot, allowed] of Object.entries(
|
|
161
|
+
config.allowExtra ?? {}
|
|
162
|
+
)) {
|
|
163
|
+
if (allowed) {
|
|
164
|
+
params[slot][key] = value;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
stripEmptySlots(params);
|
|
174
|
+
return params;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/sdk/core/auth.gen.ts
|
|
178
|
+
var getAuthToken = async (auth, callback) => {
|
|
179
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
180
|
+
if (!token) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (auth.scheme === "bearer") {
|
|
184
|
+
return `Bearer ${token}`;
|
|
185
|
+
}
|
|
186
|
+
if (auth.scheme === "basic") {
|
|
187
|
+
return `Basic ${btoa(token)}`;
|
|
188
|
+
}
|
|
189
|
+
return token;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/sdk/core/pathSerializer.gen.ts
|
|
193
|
+
var separatorArrayExplode = (style) => {
|
|
194
|
+
switch (style) {
|
|
195
|
+
case "label":
|
|
196
|
+
return ".";
|
|
197
|
+
case "matrix":
|
|
198
|
+
return ";";
|
|
199
|
+
case "simple":
|
|
200
|
+
return ",";
|
|
201
|
+
default:
|
|
202
|
+
return "&";
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var separatorArrayNoExplode = (style) => {
|
|
206
|
+
switch (style) {
|
|
207
|
+
case "form":
|
|
208
|
+
return ",";
|
|
209
|
+
case "pipeDelimited":
|
|
210
|
+
return "|";
|
|
211
|
+
case "spaceDelimited":
|
|
212
|
+
return "%20";
|
|
213
|
+
default:
|
|
214
|
+
return ",";
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var separatorObjectExplode = (style) => {
|
|
218
|
+
switch (style) {
|
|
219
|
+
case "label":
|
|
220
|
+
return ".";
|
|
221
|
+
case "matrix":
|
|
222
|
+
return ";";
|
|
223
|
+
case "simple":
|
|
224
|
+
return ",";
|
|
225
|
+
default:
|
|
226
|
+
return "&";
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var serializeArrayParam = ({
|
|
230
|
+
allowReserved,
|
|
231
|
+
explode,
|
|
232
|
+
name,
|
|
233
|
+
style,
|
|
234
|
+
value
|
|
235
|
+
}) => {
|
|
236
|
+
if (!explode) {
|
|
237
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
238
|
+
switch (style) {
|
|
239
|
+
case "label":
|
|
240
|
+
return `.${joinedValues2}`;
|
|
241
|
+
case "matrix":
|
|
242
|
+
return `;${name}=${joinedValues2}`;
|
|
243
|
+
case "simple":
|
|
244
|
+
return joinedValues2;
|
|
245
|
+
default:
|
|
246
|
+
return `${name}=${joinedValues2}`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const separator = separatorArrayExplode(style);
|
|
250
|
+
const joinedValues = value.map((v) => {
|
|
251
|
+
if (style === "label" || style === "simple") {
|
|
252
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
253
|
+
}
|
|
254
|
+
return serializePrimitiveParam({
|
|
255
|
+
allowReserved,
|
|
256
|
+
name,
|
|
257
|
+
value: v
|
|
258
|
+
});
|
|
259
|
+
}).join(separator);
|
|
260
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
261
|
+
};
|
|
262
|
+
var serializePrimitiveParam = ({
|
|
263
|
+
allowReserved,
|
|
264
|
+
name,
|
|
265
|
+
value
|
|
266
|
+
}) => {
|
|
267
|
+
if (value === void 0 || value === null) {
|
|
268
|
+
return "";
|
|
269
|
+
}
|
|
270
|
+
if (typeof value === "object") {
|
|
271
|
+
throw new Error(
|
|
272
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
276
|
+
};
|
|
277
|
+
var serializeObjectParam = ({
|
|
278
|
+
allowReserved,
|
|
279
|
+
explode,
|
|
280
|
+
name,
|
|
281
|
+
style,
|
|
282
|
+
value,
|
|
283
|
+
valueOnly
|
|
284
|
+
}) => {
|
|
285
|
+
if (value instanceof Date) {
|
|
286
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
287
|
+
}
|
|
288
|
+
if (style !== "deepObject" && !explode) {
|
|
289
|
+
let values = [];
|
|
290
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
291
|
+
values = [
|
|
292
|
+
...values,
|
|
293
|
+
key,
|
|
294
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
295
|
+
];
|
|
296
|
+
});
|
|
297
|
+
const joinedValues2 = values.join(",");
|
|
298
|
+
switch (style) {
|
|
299
|
+
case "form":
|
|
300
|
+
return `${name}=${joinedValues2}`;
|
|
301
|
+
case "label":
|
|
302
|
+
return `.${joinedValues2}`;
|
|
303
|
+
case "matrix":
|
|
304
|
+
return `;${name}=${joinedValues2}`;
|
|
305
|
+
default:
|
|
306
|
+
return joinedValues2;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const separator = separatorObjectExplode(style);
|
|
310
|
+
const joinedValues = Object.entries(value).map(
|
|
311
|
+
([key, v]) => serializePrimitiveParam({
|
|
312
|
+
allowReserved,
|
|
313
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
314
|
+
value: v
|
|
315
|
+
})
|
|
316
|
+
).join(separator);
|
|
317
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// src/sdk/client/utils.gen.ts
|
|
321
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
322
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
323
|
+
let url = _url;
|
|
324
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
325
|
+
if (matches) {
|
|
326
|
+
for (const match of matches) {
|
|
327
|
+
let explode = false;
|
|
328
|
+
let name = match.substring(1, match.length - 1);
|
|
329
|
+
let style = "simple";
|
|
330
|
+
if (name.endsWith("*")) {
|
|
331
|
+
explode = true;
|
|
332
|
+
name = name.substring(0, name.length - 1);
|
|
333
|
+
}
|
|
334
|
+
if (name.startsWith(".")) {
|
|
335
|
+
name = name.substring(1);
|
|
336
|
+
style = "label";
|
|
337
|
+
} else if (name.startsWith(";")) {
|
|
338
|
+
name = name.substring(1);
|
|
339
|
+
style = "matrix";
|
|
340
|
+
}
|
|
341
|
+
const value = path[name];
|
|
342
|
+
if (value === void 0 || value === null) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (Array.isArray(value)) {
|
|
346
|
+
url = url.replace(
|
|
347
|
+
match,
|
|
348
|
+
serializeArrayParam({ explode, name, style, value })
|
|
349
|
+
);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (typeof value === "object") {
|
|
353
|
+
url = url.replace(
|
|
354
|
+
match,
|
|
355
|
+
serializeObjectParam({
|
|
356
|
+
explode,
|
|
357
|
+
name,
|
|
358
|
+
style,
|
|
359
|
+
value,
|
|
360
|
+
valueOnly: true
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (style === "matrix") {
|
|
366
|
+
url = url.replace(
|
|
367
|
+
match,
|
|
368
|
+
`;${serializePrimitiveParam({
|
|
369
|
+
name,
|
|
370
|
+
value
|
|
371
|
+
})}`
|
|
372
|
+
);
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
const replaceValue = encodeURIComponent(
|
|
376
|
+
style === "label" ? `.${value}` : value
|
|
377
|
+
);
|
|
378
|
+
url = url.replace(match, replaceValue);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return url;
|
|
382
|
+
};
|
|
383
|
+
var createQuerySerializer = ({
|
|
384
|
+
allowReserved,
|
|
385
|
+
array,
|
|
386
|
+
object
|
|
387
|
+
} = {}) => {
|
|
388
|
+
const querySerializer = (queryParams) => {
|
|
389
|
+
const search = [];
|
|
390
|
+
if (queryParams && typeof queryParams === "object") {
|
|
391
|
+
for (const name in queryParams) {
|
|
392
|
+
const value = queryParams[name];
|
|
393
|
+
if (value === void 0 || value === null) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (Array.isArray(value)) {
|
|
397
|
+
const serializedArray = serializeArrayParam({
|
|
398
|
+
allowReserved,
|
|
399
|
+
explode: true,
|
|
400
|
+
name,
|
|
401
|
+
style: "form",
|
|
402
|
+
value,
|
|
403
|
+
...array
|
|
404
|
+
});
|
|
405
|
+
if (serializedArray) search.push(serializedArray);
|
|
406
|
+
} else if (typeof value === "object") {
|
|
407
|
+
const serializedObject = serializeObjectParam({
|
|
408
|
+
allowReserved,
|
|
409
|
+
explode: true,
|
|
410
|
+
name,
|
|
411
|
+
style: "deepObject",
|
|
412
|
+
value,
|
|
413
|
+
...object
|
|
414
|
+
});
|
|
415
|
+
if (serializedObject) search.push(serializedObject);
|
|
416
|
+
} else {
|
|
417
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
418
|
+
allowReserved,
|
|
419
|
+
name,
|
|
420
|
+
value
|
|
421
|
+
});
|
|
422
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return search.join("&");
|
|
427
|
+
};
|
|
428
|
+
return querySerializer;
|
|
429
|
+
};
|
|
430
|
+
var getParseAs = (contentType) => {
|
|
431
|
+
if (!contentType) {
|
|
432
|
+
return "stream";
|
|
433
|
+
}
|
|
434
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
435
|
+
if (!cleanContent) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
439
|
+
return "json";
|
|
440
|
+
}
|
|
441
|
+
if (cleanContent === "multipart/form-data") {
|
|
442
|
+
return "formData";
|
|
443
|
+
}
|
|
444
|
+
if (["application/", "audio/", "image/", "video/"].some(
|
|
445
|
+
(type) => cleanContent.startsWith(type)
|
|
446
|
+
)) {
|
|
447
|
+
return "blob";
|
|
448
|
+
}
|
|
449
|
+
if (cleanContent.startsWith("text/")) {
|
|
450
|
+
return "text";
|
|
451
|
+
}
|
|
452
|
+
return;
|
|
453
|
+
};
|
|
454
|
+
var setAuthParams = async ({
|
|
455
|
+
security,
|
|
456
|
+
...options
|
|
457
|
+
}) => {
|
|
458
|
+
for (const auth of security) {
|
|
459
|
+
const token = await getAuthToken(auth, options.auth);
|
|
460
|
+
if (!token) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
const name = auth.name ?? "Authorization";
|
|
464
|
+
switch (auth.in) {
|
|
465
|
+
case "query":
|
|
466
|
+
if (!options.query) {
|
|
467
|
+
options.query = {};
|
|
468
|
+
}
|
|
469
|
+
options.query[name] = token;
|
|
470
|
+
break;
|
|
471
|
+
case "cookie":
|
|
472
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
473
|
+
break;
|
|
474
|
+
case "header":
|
|
475
|
+
default:
|
|
476
|
+
options.headers.set(name, token);
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
var buildUrl = (options) => {
|
|
483
|
+
const url = getUrl({
|
|
484
|
+
baseUrl: options.baseUrl,
|
|
485
|
+
path: options.path,
|
|
486
|
+
query: options.query,
|
|
487
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
488
|
+
url: options.url
|
|
489
|
+
});
|
|
490
|
+
return url;
|
|
491
|
+
};
|
|
492
|
+
var getUrl = ({
|
|
493
|
+
baseUrl,
|
|
494
|
+
path,
|
|
495
|
+
query,
|
|
496
|
+
querySerializer,
|
|
497
|
+
url: _url
|
|
498
|
+
}) => {
|
|
499
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
500
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
501
|
+
if (path) {
|
|
502
|
+
url = defaultPathSerializer({ path, url });
|
|
503
|
+
}
|
|
504
|
+
let search = query ? querySerializer(query) : "";
|
|
505
|
+
if (search.startsWith("?")) {
|
|
506
|
+
search = search.substring(1);
|
|
507
|
+
}
|
|
508
|
+
if (search) {
|
|
509
|
+
url += `?${search}`;
|
|
510
|
+
}
|
|
511
|
+
return url;
|
|
512
|
+
};
|
|
513
|
+
var mergeConfigs = (a, b) => {
|
|
514
|
+
const config = { ...a, ...b };
|
|
515
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
516
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
517
|
+
}
|
|
518
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
519
|
+
return config;
|
|
520
|
+
};
|
|
521
|
+
var mergeHeaders = (...headers) => {
|
|
522
|
+
const mergedHeaders = new Headers();
|
|
523
|
+
for (const header of headers) {
|
|
524
|
+
if (!header || typeof header !== "object") {
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
|
|
528
|
+
for (const [key, value] of iterator) {
|
|
529
|
+
if (value === null) {
|
|
530
|
+
mergedHeaders.delete(key);
|
|
531
|
+
} else if (Array.isArray(value)) {
|
|
532
|
+
for (const v of value) {
|
|
533
|
+
mergedHeaders.append(key, v);
|
|
534
|
+
}
|
|
535
|
+
} else if (value !== void 0) {
|
|
536
|
+
mergedHeaders.set(
|
|
537
|
+
key,
|
|
538
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return mergedHeaders;
|
|
544
|
+
};
|
|
545
|
+
var Interceptors = class {
|
|
546
|
+
constructor() {
|
|
547
|
+
__publicField(this, "_fns");
|
|
548
|
+
this._fns = [];
|
|
549
|
+
}
|
|
550
|
+
clear() {
|
|
551
|
+
this._fns = [];
|
|
552
|
+
}
|
|
553
|
+
getInterceptorIndex(id) {
|
|
554
|
+
if (typeof id === "number") {
|
|
555
|
+
return this._fns[id] ? id : -1;
|
|
556
|
+
} else {
|
|
557
|
+
return this._fns.indexOf(id);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
exists(id) {
|
|
561
|
+
const index = this.getInterceptorIndex(id);
|
|
562
|
+
return !!this._fns[index];
|
|
563
|
+
}
|
|
564
|
+
eject(id) {
|
|
565
|
+
const index = this.getInterceptorIndex(id);
|
|
566
|
+
if (this._fns[index]) {
|
|
567
|
+
this._fns[index] = null;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
update(id, fn) {
|
|
571
|
+
const index = this.getInterceptorIndex(id);
|
|
572
|
+
if (this._fns[index]) {
|
|
573
|
+
this._fns[index] = fn;
|
|
574
|
+
return id;
|
|
575
|
+
} else {
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
use(fn) {
|
|
580
|
+
this._fns = [...this._fns, fn];
|
|
581
|
+
return this._fns.length - 1;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
var createInterceptors = () => ({
|
|
585
|
+
error: new Interceptors(),
|
|
586
|
+
request: new Interceptors(),
|
|
587
|
+
response: new Interceptors()
|
|
588
|
+
});
|
|
589
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
590
|
+
allowReserved: false,
|
|
591
|
+
array: {
|
|
592
|
+
explode: true,
|
|
593
|
+
style: "form"
|
|
594
|
+
},
|
|
595
|
+
object: {
|
|
596
|
+
explode: true,
|
|
597
|
+
style: "deepObject"
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
var defaultHeaders = {
|
|
601
|
+
"Content-Type": "application/json"
|
|
602
|
+
};
|
|
603
|
+
var createConfig = (override = {}) => ({
|
|
604
|
+
...jsonBodySerializer,
|
|
605
|
+
headers: defaultHeaders,
|
|
606
|
+
parseAs: "auto",
|
|
607
|
+
querySerializer: defaultQuerySerializer,
|
|
608
|
+
...override
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
// src/sdk/client/client.gen.ts
|
|
612
|
+
var createClient = (config = {}) => {
|
|
613
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
614
|
+
const getConfig = () => ({ ..._config });
|
|
615
|
+
const setConfig = (config2) => {
|
|
616
|
+
_config = mergeConfigs(_config, config2);
|
|
617
|
+
return getConfig();
|
|
618
|
+
};
|
|
619
|
+
const interceptors = createInterceptors();
|
|
620
|
+
const request = async (options) => {
|
|
621
|
+
const opts = {
|
|
622
|
+
..._config,
|
|
623
|
+
...options,
|
|
624
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
625
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
626
|
+
serializedBody: void 0
|
|
627
|
+
};
|
|
628
|
+
if (opts.security) {
|
|
629
|
+
await setAuthParams({
|
|
630
|
+
...opts,
|
|
631
|
+
security: opts.security
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
if (opts.requestValidator) {
|
|
635
|
+
await opts.requestValidator(opts);
|
|
636
|
+
}
|
|
637
|
+
if (opts.body && opts.bodySerializer) {
|
|
638
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
639
|
+
}
|
|
640
|
+
if (opts.serializedBody === void 0 || opts.serializedBody === "") {
|
|
641
|
+
opts.headers.delete("Content-Type");
|
|
642
|
+
}
|
|
643
|
+
const url = buildUrl(opts);
|
|
644
|
+
const requestInit = {
|
|
645
|
+
redirect: "follow",
|
|
646
|
+
...opts,
|
|
647
|
+
body: opts.serializedBody
|
|
648
|
+
};
|
|
649
|
+
let request2 = new Request(url, requestInit);
|
|
650
|
+
for (const fn of interceptors.request._fns) {
|
|
651
|
+
if (fn) {
|
|
652
|
+
request2 = await fn(request2, opts);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const _fetch = opts.fetch;
|
|
656
|
+
let response = await _fetch(request2);
|
|
657
|
+
for (const fn of interceptors.response._fns) {
|
|
658
|
+
if (fn) {
|
|
659
|
+
response = await fn(response, request2, opts);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const result = {
|
|
663
|
+
request: request2,
|
|
664
|
+
response
|
|
665
|
+
};
|
|
666
|
+
if (response.ok) {
|
|
667
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
668
|
+
return opts.responseStyle === "data" ? {} : {
|
|
669
|
+
data: {},
|
|
670
|
+
...result
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
674
|
+
let data;
|
|
675
|
+
switch (parseAs) {
|
|
676
|
+
case "arrayBuffer":
|
|
677
|
+
case "blob":
|
|
678
|
+
case "formData":
|
|
679
|
+
case "json":
|
|
680
|
+
case "text":
|
|
681
|
+
data = await response[parseAs]();
|
|
682
|
+
break;
|
|
683
|
+
case "stream":
|
|
684
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
685
|
+
data: response.body,
|
|
686
|
+
...result
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
if (parseAs === "json") {
|
|
690
|
+
if (opts.responseValidator) {
|
|
691
|
+
await opts.responseValidator(data);
|
|
692
|
+
}
|
|
693
|
+
if (opts.responseTransformer) {
|
|
694
|
+
data = await opts.responseTransformer(data);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return opts.responseStyle === "data" ? data : {
|
|
698
|
+
data,
|
|
699
|
+
...result
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
const textError = await response.text();
|
|
703
|
+
let jsonError;
|
|
704
|
+
try {
|
|
705
|
+
jsonError = JSON.parse(textError);
|
|
706
|
+
} catch {
|
|
707
|
+
}
|
|
708
|
+
const error = jsonError ?? textError;
|
|
709
|
+
let finalError = error;
|
|
710
|
+
for (const fn of interceptors.error._fns) {
|
|
711
|
+
if (fn) {
|
|
712
|
+
finalError = await fn(error, response, request2, opts);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
finalError = finalError || {};
|
|
716
|
+
if (opts.throwOnError) {
|
|
717
|
+
throw finalError;
|
|
718
|
+
}
|
|
719
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
720
|
+
error: finalError,
|
|
721
|
+
...result
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
return {
|
|
725
|
+
buildUrl,
|
|
726
|
+
connect: (options) => request({ ...options, method: "CONNECT" }),
|
|
727
|
+
delete: (options) => request({ ...options, method: "DELETE" }),
|
|
728
|
+
get: (options) => request({ ...options, method: "GET" }),
|
|
729
|
+
getConfig,
|
|
730
|
+
head: (options) => request({ ...options, method: "HEAD" }),
|
|
731
|
+
interceptors,
|
|
732
|
+
options: (options) => request({ ...options, method: "OPTIONS" }),
|
|
733
|
+
patch: (options) => request({ ...options, method: "PATCH" }),
|
|
734
|
+
post: (options) => request({ ...options, method: "POST" }),
|
|
735
|
+
put: (options) => request({ ...options, method: "PUT" }),
|
|
736
|
+
request,
|
|
737
|
+
setConfig,
|
|
738
|
+
trace: (options) => request({ ...options, method: "TRACE" })
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
742
|
+
0 && (module.exports = {
|
|
743
|
+
buildClientParams,
|
|
744
|
+
createClient,
|
|
745
|
+
createConfig,
|
|
746
|
+
formDataBodySerializer,
|
|
747
|
+
jsonBodySerializer,
|
|
748
|
+
mergeHeaders,
|
|
749
|
+
urlSearchParamsBodySerializer
|
|
750
|
+
});
|