@auv-js/api-client 0.0.3
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/LICENSE +201 -0
- package/README.md +72 -0
- package/dist/index.d.ts +924 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +766 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
//#region src/gen/core/bodySerializer.gen.ts
|
|
2
|
+
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/gen/core/serverSentEvents.gen.ts
|
|
5
|
+
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
6
|
+
let lastEventId;
|
|
7
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
8
|
+
const createStream = async function* () {
|
|
9
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
10
|
+
let attempt = 0;
|
|
11
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
12
|
+
while (true) {
|
|
13
|
+
if (signal.aborted) break;
|
|
14
|
+
attempt++;
|
|
15
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
16
|
+
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
17
|
+
try {
|
|
18
|
+
const requestInit = {
|
|
19
|
+
redirect: "follow",
|
|
20
|
+
...options,
|
|
21
|
+
body: options.serializedBody,
|
|
22
|
+
headers,
|
|
23
|
+
signal
|
|
24
|
+
};
|
|
25
|
+
let request = new Request(url, requestInit);
|
|
26
|
+
if (onRequest) request = await onRequest(url, requestInit);
|
|
27
|
+
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
28
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
29
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
30
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
31
|
+
let buffer = "";
|
|
32
|
+
const abortHandler = () => {
|
|
33
|
+
try {
|
|
34
|
+
reader.cancel();
|
|
35
|
+
} catch {}
|
|
36
|
+
};
|
|
37
|
+
signal.addEventListener("abort", abortHandler);
|
|
38
|
+
try {
|
|
39
|
+
while (true) {
|
|
40
|
+
const { done, value } = await reader.read();
|
|
41
|
+
if (done) break;
|
|
42
|
+
buffer += value;
|
|
43
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
44
|
+
const chunks = buffer.split("\n\n");
|
|
45
|
+
buffer = chunks.pop() ?? "";
|
|
46
|
+
for (const chunk of chunks) {
|
|
47
|
+
const lines = chunk.split("\n");
|
|
48
|
+
const dataLines = [];
|
|
49
|
+
let eventName;
|
|
50
|
+
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
51
|
+
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
52
|
+
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
53
|
+
else if (line.startsWith("retry:")) {
|
|
54
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
55
|
+
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
56
|
+
}
|
|
57
|
+
let data;
|
|
58
|
+
let parsedJson = false;
|
|
59
|
+
if (dataLines.length) {
|
|
60
|
+
const rawData = dataLines.join("\n");
|
|
61
|
+
try {
|
|
62
|
+
data = JSON.parse(rawData);
|
|
63
|
+
parsedJson = true;
|
|
64
|
+
} catch {
|
|
65
|
+
data = rawData;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (parsedJson) {
|
|
69
|
+
if (responseValidator) await responseValidator(data);
|
|
70
|
+
if (responseTransformer) data = await responseTransformer(data);
|
|
71
|
+
}
|
|
72
|
+
onSseEvent?.({
|
|
73
|
+
data,
|
|
74
|
+
event: eventName,
|
|
75
|
+
id: lastEventId,
|
|
76
|
+
retry: retryDelay
|
|
77
|
+
});
|
|
78
|
+
if (dataLines.length) yield data;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} finally {
|
|
82
|
+
signal.removeEventListener("abort", abortHandler);
|
|
83
|
+
reader.releaseLock();
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
onSseError?.(error);
|
|
88
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
89
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
90
|
+
await sleep(backoff);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return { stream: createStream() };
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/gen/core/pathSerializer.gen.ts
|
|
98
|
+
const separatorArrayExplode = (style) => {
|
|
99
|
+
switch (style) {
|
|
100
|
+
case "label": return ".";
|
|
101
|
+
case "matrix": return ";";
|
|
102
|
+
case "simple": return ",";
|
|
103
|
+
default: return "&";
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const separatorArrayNoExplode = (style) => {
|
|
107
|
+
switch (style) {
|
|
108
|
+
case "form": return ",";
|
|
109
|
+
case "pipeDelimited": return "|";
|
|
110
|
+
case "spaceDelimited": return "%20";
|
|
111
|
+
default: return ",";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const separatorObjectExplode = (style) => {
|
|
115
|
+
switch (style) {
|
|
116
|
+
case "label": return ".";
|
|
117
|
+
case "matrix": return ";";
|
|
118
|
+
case "simple": return ",";
|
|
119
|
+
default: return "&";
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
123
|
+
if (!explode) {
|
|
124
|
+
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
125
|
+
switch (style) {
|
|
126
|
+
case "label": return `.${joinedValues}`;
|
|
127
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
128
|
+
case "simple": return joinedValues;
|
|
129
|
+
default: return `${name}=${joinedValues}`;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const separator = separatorArrayExplode(style);
|
|
133
|
+
const joinedValues = value.map((v) => {
|
|
134
|
+
if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
|
|
135
|
+
return serializePrimitiveParam({
|
|
136
|
+
allowReserved,
|
|
137
|
+
name,
|
|
138
|
+
value: v
|
|
139
|
+
});
|
|
140
|
+
}).join(separator);
|
|
141
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
142
|
+
};
|
|
143
|
+
const serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
144
|
+
if (value === void 0 || value === null) return "";
|
|
145
|
+
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
146
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
147
|
+
};
|
|
148
|
+
const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
149
|
+
if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
150
|
+
if (style !== "deepObject" && !explode) {
|
|
151
|
+
let values = [];
|
|
152
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
153
|
+
values = [
|
|
154
|
+
...values,
|
|
155
|
+
key,
|
|
156
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
157
|
+
];
|
|
158
|
+
});
|
|
159
|
+
const joinedValues = values.join(",");
|
|
160
|
+
switch (style) {
|
|
161
|
+
case "form": return `${name}=${joinedValues}`;
|
|
162
|
+
case "label": return `.${joinedValues}`;
|
|
163
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
164
|
+
default: return joinedValues;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const separator = separatorObjectExplode(style);
|
|
168
|
+
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
169
|
+
allowReserved,
|
|
170
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
171
|
+
value: v
|
|
172
|
+
})).join(separator);
|
|
173
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
174
|
+
};
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/gen/core/utils.gen.ts
|
|
177
|
+
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
178
|
+
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
179
|
+
let url = _url;
|
|
180
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
181
|
+
if (matches) for (const match of matches) {
|
|
182
|
+
let explode = false;
|
|
183
|
+
let name = match.substring(1, match.length - 1);
|
|
184
|
+
let style = "simple";
|
|
185
|
+
if (name.endsWith("*")) {
|
|
186
|
+
explode = true;
|
|
187
|
+
name = name.substring(0, name.length - 1);
|
|
188
|
+
}
|
|
189
|
+
if (name.startsWith(".")) {
|
|
190
|
+
name = name.substring(1);
|
|
191
|
+
style = "label";
|
|
192
|
+
} else if (name.startsWith(";")) {
|
|
193
|
+
name = name.substring(1);
|
|
194
|
+
style = "matrix";
|
|
195
|
+
}
|
|
196
|
+
const value = path[name];
|
|
197
|
+
if (value === void 0 || value === null) continue;
|
|
198
|
+
if (Array.isArray(value)) {
|
|
199
|
+
url = url.replace(match, serializeArrayParam({
|
|
200
|
+
explode,
|
|
201
|
+
name,
|
|
202
|
+
style,
|
|
203
|
+
value
|
|
204
|
+
}));
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (typeof value === "object") {
|
|
208
|
+
url = url.replace(match, serializeObjectParam({
|
|
209
|
+
explode,
|
|
210
|
+
name,
|
|
211
|
+
style,
|
|
212
|
+
value,
|
|
213
|
+
valueOnly: true
|
|
214
|
+
}));
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (style === "matrix") {
|
|
218
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
219
|
+
name,
|
|
220
|
+
value
|
|
221
|
+
})}`);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
225
|
+
url = url.replace(match, replaceValue);
|
|
226
|
+
}
|
|
227
|
+
return url;
|
|
228
|
+
};
|
|
229
|
+
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
230
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
231
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
232
|
+
if (path) url = defaultPathSerializer({
|
|
233
|
+
path,
|
|
234
|
+
url
|
|
235
|
+
});
|
|
236
|
+
let search = query ? querySerializer(query) : "";
|
|
237
|
+
if (search.startsWith("?")) search = search.substring(1);
|
|
238
|
+
if (search) url += `?${search}`;
|
|
239
|
+
return url;
|
|
240
|
+
};
|
|
241
|
+
function getValidRequestBody(options) {
|
|
242
|
+
const hasBody = options.body !== void 0;
|
|
243
|
+
if (hasBody && options.bodySerializer) {
|
|
244
|
+
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
245
|
+
return options.body !== "" ? options.body : null;
|
|
246
|
+
}
|
|
247
|
+
if (hasBody) return options.body;
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/gen/core/auth.gen.ts
|
|
251
|
+
const getAuthToken = async (auth, callback) => {
|
|
252
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
253
|
+
if (!token) return;
|
|
254
|
+
if (auth.scheme === "bearer") return `Bearer ${token}`;
|
|
255
|
+
if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
|
|
256
|
+
return token;
|
|
257
|
+
};
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/gen/client/utils.gen.ts
|
|
260
|
+
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
261
|
+
const querySerializer = (queryParams) => {
|
|
262
|
+
const search = [];
|
|
263
|
+
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
264
|
+
const value = queryParams[name];
|
|
265
|
+
if (value === void 0 || value === null) continue;
|
|
266
|
+
const options = parameters[name] || args;
|
|
267
|
+
if (Array.isArray(value)) {
|
|
268
|
+
const serializedArray = serializeArrayParam({
|
|
269
|
+
allowReserved: options.allowReserved,
|
|
270
|
+
explode: true,
|
|
271
|
+
name,
|
|
272
|
+
style: "form",
|
|
273
|
+
value,
|
|
274
|
+
...options.array
|
|
275
|
+
});
|
|
276
|
+
if (serializedArray) search.push(serializedArray);
|
|
277
|
+
} else if (typeof value === "object") {
|
|
278
|
+
const serializedObject = serializeObjectParam({
|
|
279
|
+
allowReserved: options.allowReserved,
|
|
280
|
+
explode: true,
|
|
281
|
+
name,
|
|
282
|
+
style: "deepObject",
|
|
283
|
+
value,
|
|
284
|
+
...options.object
|
|
285
|
+
});
|
|
286
|
+
if (serializedObject) search.push(serializedObject);
|
|
287
|
+
} else {
|
|
288
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
289
|
+
allowReserved: options.allowReserved,
|
|
290
|
+
name,
|
|
291
|
+
value
|
|
292
|
+
});
|
|
293
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return search.join("&");
|
|
297
|
+
};
|
|
298
|
+
return querySerializer;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Infers parseAs value from provided Content-Type header.
|
|
302
|
+
*/
|
|
303
|
+
const getParseAs = (contentType) => {
|
|
304
|
+
if (!contentType) return "stream";
|
|
305
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
306
|
+
if (!cleanContent) return;
|
|
307
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
|
|
308
|
+
if (cleanContent === "multipart/form-data") return "formData";
|
|
309
|
+
if ([
|
|
310
|
+
"application/",
|
|
311
|
+
"audio/",
|
|
312
|
+
"image/",
|
|
313
|
+
"video/"
|
|
314
|
+
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
315
|
+
if (cleanContent.startsWith("text/")) return "text";
|
|
316
|
+
};
|
|
317
|
+
const checkForExistence = (options, name) => {
|
|
318
|
+
if (!name) return false;
|
|
319
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
320
|
+
return false;
|
|
321
|
+
};
|
|
322
|
+
async function setAuthParams(options) {
|
|
323
|
+
for (const auth of options.security ?? []) {
|
|
324
|
+
if (checkForExistence(options, auth.name)) continue;
|
|
325
|
+
const token = await getAuthToken(auth, options.auth);
|
|
326
|
+
if (!token) continue;
|
|
327
|
+
const name = auth.name ?? "Authorization";
|
|
328
|
+
switch (auth.in) {
|
|
329
|
+
case "query":
|
|
330
|
+
if (!options.query) options.query = {};
|
|
331
|
+
options.query[name] = token;
|
|
332
|
+
break;
|
|
333
|
+
case "cookie":
|
|
334
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
335
|
+
break;
|
|
336
|
+
default:
|
|
337
|
+
options.headers.set(name, token);
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const buildUrl = (options) => getUrl({
|
|
343
|
+
baseUrl: options.baseUrl,
|
|
344
|
+
path: options.path,
|
|
345
|
+
query: options.query,
|
|
346
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
347
|
+
url: options.url
|
|
348
|
+
});
|
|
349
|
+
const mergeConfigs = (a, b) => {
|
|
350
|
+
const config = {
|
|
351
|
+
...a,
|
|
352
|
+
...b
|
|
353
|
+
};
|
|
354
|
+
if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
355
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
356
|
+
return config;
|
|
357
|
+
};
|
|
358
|
+
const headersEntries = (headers) => {
|
|
359
|
+
const entries = [];
|
|
360
|
+
headers.forEach((value, key) => {
|
|
361
|
+
entries.push([key, value]);
|
|
362
|
+
});
|
|
363
|
+
return entries;
|
|
364
|
+
};
|
|
365
|
+
const mergeHeaders = (...headers) => {
|
|
366
|
+
const mergedHeaders = new Headers();
|
|
367
|
+
for (const header of headers) {
|
|
368
|
+
if (!header) continue;
|
|
369
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
370
|
+
for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
|
|
371
|
+
else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
|
|
372
|
+
else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
373
|
+
}
|
|
374
|
+
return mergedHeaders;
|
|
375
|
+
};
|
|
376
|
+
var Interceptors = class {
|
|
377
|
+
fns = [];
|
|
378
|
+
clear() {
|
|
379
|
+
this.fns = [];
|
|
380
|
+
}
|
|
381
|
+
eject(id) {
|
|
382
|
+
const index = this.getInterceptorIndex(id);
|
|
383
|
+
if (this.fns[index]) this.fns[index] = null;
|
|
384
|
+
}
|
|
385
|
+
exists(id) {
|
|
386
|
+
const index = this.getInterceptorIndex(id);
|
|
387
|
+
return Boolean(this.fns[index]);
|
|
388
|
+
}
|
|
389
|
+
getInterceptorIndex(id) {
|
|
390
|
+
if (typeof id === "number") return this.fns[id] ? id : -1;
|
|
391
|
+
return this.fns.indexOf(id);
|
|
392
|
+
}
|
|
393
|
+
update(id, fn) {
|
|
394
|
+
const index = this.getInterceptorIndex(id);
|
|
395
|
+
if (this.fns[index]) {
|
|
396
|
+
this.fns[index] = fn;
|
|
397
|
+
return id;
|
|
398
|
+
}
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
use(fn) {
|
|
402
|
+
this.fns.push(fn);
|
|
403
|
+
return this.fns.length - 1;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
const createInterceptors = () => ({
|
|
407
|
+
error: new Interceptors(),
|
|
408
|
+
request: new Interceptors(),
|
|
409
|
+
response: new Interceptors()
|
|
410
|
+
});
|
|
411
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
412
|
+
allowReserved: false,
|
|
413
|
+
array: {
|
|
414
|
+
explode: true,
|
|
415
|
+
style: "form"
|
|
416
|
+
},
|
|
417
|
+
object: {
|
|
418
|
+
explode: true,
|
|
419
|
+
style: "deepObject"
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
const defaultHeaders = { "Content-Type": "application/json" };
|
|
423
|
+
const createConfig = (override = {}) => ({
|
|
424
|
+
...jsonBodySerializer,
|
|
425
|
+
headers: defaultHeaders,
|
|
426
|
+
parseAs: "auto",
|
|
427
|
+
querySerializer: defaultQuerySerializer,
|
|
428
|
+
...override
|
|
429
|
+
});
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/gen/client/client.gen.ts
|
|
432
|
+
const createClient = (config = {}) => {
|
|
433
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
434
|
+
const getConfig = () => ({ ..._config });
|
|
435
|
+
const setConfig = (config) => {
|
|
436
|
+
_config = mergeConfigs(_config, config);
|
|
437
|
+
return getConfig();
|
|
438
|
+
};
|
|
439
|
+
const interceptors = createInterceptors();
|
|
440
|
+
const beforeRequest = async (options) => {
|
|
441
|
+
const opts = {
|
|
442
|
+
..._config,
|
|
443
|
+
...options,
|
|
444
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
445
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
446
|
+
serializedBody: void 0
|
|
447
|
+
};
|
|
448
|
+
if (opts.security) await setAuthParams(opts);
|
|
449
|
+
if (opts.requestValidator) await opts.requestValidator(opts);
|
|
450
|
+
if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
|
|
451
|
+
if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
|
|
452
|
+
const resolvedOpts = opts;
|
|
453
|
+
return {
|
|
454
|
+
opts: resolvedOpts,
|
|
455
|
+
url: buildUrl(resolvedOpts)
|
|
456
|
+
};
|
|
457
|
+
};
|
|
458
|
+
const request = async (options) => {
|
|
459
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
460
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
461
|
+
let request;
|
|
462
|
+
let response;
|
|
463
|
+
try {
|
|
464
|
+
const { opts, url } = await beforeRequest(options);
|
|
465
|
+
const requestInit = {
|
|
466
|
+
redirect: "follow",
|
|
467
|
+
...opts,
|
|
468
|
+
body: getValidRequestBody(opts)
|
|
469
|
+
};
|
|
470
|
+
request = new Request(url, requestInit);
|
|
471
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
472
|
+
const _fetch = opts.fetch;
|
|
473
|
+
response = await _fetch(request);
|
|
474
|
+
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
|
|
475
|
+
const result = {
|
|
476
|
+
request,
|
|
477
|
+
response
|
|
478
|
+
};
|
|
479
|
+
if (response.ok) {
|
|
480
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
481
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
482
|
+
let emptyData;
|
|
483
|
+
switch (parseAs) {
|
|
484
|
+
case "arrayBuffer":
|
|
485
|
+
case "blob":
|
|
486
|
+
case "text":
|
|
487
|
+
emptyData = await response[parseAs]();
|
|
488
|
+
break;
|
|
489
|
+
case "formData":
|
|
490
|
+
emptyData = new FormData();
|
|
491
|
+
break;
|
|
492
|
+
case "stream":
|
|
493
|
+
emptyData = response.body;
|
|
494
|
+
break;
|
|
495
|
+
default:
|
|
496
|
+
emptyData = {};
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
500
|
+
data: emptyData,
|
|
501
|
+
...result
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
let data;
|
|
505
|
+
switch (parseAs) {
|
|
506
|
+
case "arrayBuffer":
|
|
507
|
+
case "blob":
|
|
508
|
+
case "formData":
|
|
509
|
+
case "text":
|
|
510
|
+
data = await response[parseAs]();
|
|
511
|
+
break;
|
|
512
|
+
case "json": {
|
|
513
|
+
const text = await response.text();
|
|
514
|
+
data = text ? JSON.parse(text) : {};
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
case "stream": return opts.responseStyle === "data" ? response.body : {
|
|
518
|
+
data: response.body,
|
|
519
|
+
...result
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
if (parseAs === "json") {
|
|
523
|
+
if (opts.responseValidator) await opts.responseValidator(data);
|
|
524
|
+
if (opts.responseTransformer) data = await opts.responseTransformer(data);
|
|
525
|
+
}
|
|
526
|
+
return opts.responseStyle === "data" ? data : {
|
|
527
|
+
data,
|
|
528
|
+
...result
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
const textError = await response.text();
|
|
532
|
+
let jsonError;
|
|
533
|
+
try {
|
|
534
|
+
jsonError = JSON.parse(textError);
|
|
535
|
+
} catch {}
|
|
536
|
+
throw jsonError ?? textError;
|
|
537
|
+
} catch (error) {
|
|
538
|
+
let finalError = error;
|
|
539
|
+
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(finalError, response, request, options);
|
|
540
|
+
finalError = finalError || {};
|
|
541
|
+
if (throwOnError) throw finalError;
|
|
542
|
+
return responseStyle === "data" ? void 0 : {
|
|
543
|
+
error: finalError,
|
|
544
|
+
request,
|
|
545
|
+
response
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const makeMethodFn = (method) => (options) => request({
|
|
550
|
+
...options,
|
|
551
|
+
method
|
|
552
|
+
});
|
|
553
|
+
const makeSseFn = (method) => async (options) => {
|
|
554
|
+
const { opts, url } = await beforeRequest(options);
|
|
555
|
+
return createSseClient({
|
|
556
|
+
...opts,
|
|
557
|
+
body: opts.body,
|
|
558
|
+
method,
|
|
559
|
+
onRequest: async (url, init) => {
|
|
560
|
+
let request = new Request(url, init);
|
|
561
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
562
|
+
return request;
|
|
563
|
+
},
|
|
564
|
+
serializedBody: getValidRequestBody(opts),
|
|
565
|
+
url
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
const _buildUrl = (options) => buildUrl({
|
|
569
|
+
..._config,
|
|
570
|
+
...options
|
|
571
|
+
});
|
|
572
|
+
return {
|
|
573
|
+
buildUrl: _buildUrl,
|
|
574
|
+
connect: makeMethodFn("CONNECT"),
|
|
575
|
+
delete: makeMethodFn("DELETE"),
|
|
576
|
+
get: makeMethodFn("GET"),
|
|
577
|
+
getConfig,
|
|
578
|
+
head: makeMethodFn("HEAD"),
|
|
579
|
+
interceptors,
|
|
580
|
+
options: makeMethodFn("OPTIONS"),
|
|
581
|
+
patch: makeMethodFn("PATCH"),
|
|
582
|
+
post: makeMethodFn("POST"),
|
|
583
|
+
put: makeMethodFn("PUT"),
|
|
584
|
+
request,
|
|
585
|
+
setConfig,
|
|
586
|
+
sse: {
|
|
587
|
+
connect: makeSseFn("CONNECT"),
|
|
588
|
+
delete: makeSseFn("DELETE"),
|
|
589
|
+
get: makeSseFn("GET"),
|
|
590
|
+
head: makeSseFn("HEAD"),
|
|
591
|
+
options: makeSseFn("OPTIONS"),
|
|
592
|
+
patch: makeSseFn("PATCH"),
|
|
593
|
+
post: makeSseFn("POST"),
|
|
594
|
+
put: makeSseFn("PUT"),
|
|
595
|
+
trace: makeSseFn("TRACE")
|
|
596
|
+
},
|
|
597
|
+
trace: makeMethodFn("TRACE")
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region src/gen/client.gen.ts
|
|
602
|
+
const client = createClient(createConfig());
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/gen/sdk.gen.ts
|
|
605
|
+
const discoveryServiceListApiNamespaces = (options) => (options?.client ?? client).get({
|
|
606
|
+
url: "/apis",
|
|
607
|
+
...options
|
|
608
|
+
});
|
|
609
|
+
const deviceServiceListDevices = (options) => (options?.client ?? client).get({
|
|
610
|
+
url: "/apis/auv/daemon/v1/devices",
|
|
611
|
+
...options
|
|
612
|
+
});
|
|
613
|
+
/**
|
|
614
|
+
* NOTICE(tonic-rest-path): the generator only supports one configured
|
|
615
|
+
* nested-message wrapper type, while AUV has distinct typed resource refs.
|
|
616
|
+
* Keep the typed request and use an action body until arbitrary nested path
|
|
617
|
+
* parameters are supported.
|
|
618
|
+
*/
|
|
619
|
+
const deviceServiceGetDevice = (options) => (options.client ?? client).post({
|
|
620
|
+
url: "/apis/auv/daemon/v1/devices:get",
|
|
621
|
+
...options,
|
|
622
|
+
headers: {
|
|
623
|
+
"Content-Type": "application/json",
|
|
624
|
+
...options.headers
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
const pairingServiceRevokeDeviceCredential = (options) => (options.client ?? client).post({
|
|
628
|
+
url: "/apis/auv/daemon/v1/pairing/credentials/revoke",
|
|
629
|
+
...options,
|
|
630
|
+
headers: {
|
|
631
|
+
"Content-Type": "application/json",
|
|
632
|
+
...options.headers
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
const pairingServicePairDevice = (options) => (options.client ?? client).post({
|
|
636
|
+
url: "/apis/auv/daemon/v1/pairing/devices",
|
|
637
|
+
...options,
|
|
638
|
+
headers: {
|
|
639
|
+
"Content-Type": "application/json",
|
|
640
|
+
...options.headers
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
const pairingServiceSetPairedDeviceEnabled = (options) => (options.client ?? client).post({
|
|
644
|
+
url: "/apis/auv/daemon/v1/pairing/devices/enabled",
|
|
645
|
+
...options,
|
|
646
|
+
headers: {
|
|
647
|
+
"Content-Type": "application/json",
|
|
648
|
+
...options.headers
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
const pairingServiceUnpairDevice = (options) => (options.client ?? client).post({
|
|
652
|
+
url: "/apis/auv/daemon/v1/pairing/devices/unpair",
|
|
653
|
+
...options,
|
|
654
|
+
headers: {
|
|
655
|
+
"Content-Type": "application/json",
|
|
656
|
+
...options.headers
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
const pairingServiceCreatePairingToken = (options) => (options.client ?? client).post({
|
|
660
|
+
url: "/apis/auv/daemon/v1/pairing/tokens",
|
|
661
|
+
...options,
|
|
662
|
+
headers: {
|
|
663
|
+
"Content-Type": "application/json",
|
|
664
|
+
...options.headers
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
const runnerClassServiceGetRunnerClass = (options) => (options.client ?? client).post({
|
|
668
|
+
url: "/apis/auv/runtime/v1/runnerclasses:get",
|
|
669
|
+
...options,
|
|
670
|
+
headers: {
|
|
671
|
+
"Content-Type": "application/json",
|
|
672
|
+
...options.headers
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
/**
|
|
676
|
+
* The optional DeviceRef cannot be represented by Axum's flat query
|
|
677
|
+
* extractor without losing the typed request boundary.
|
|
678
|
+
*/
|
|
679
|
+
const runnerClassServiceListRunnerClasses = (options) => (options.client ?? client).post({
|
|
680
|
+
url: "/apis/auv/runtime/v1/runnerclasses:list",
|
|
681
|
+
...options,
|
|
682
|
+
headers: {
|
|
683
|
+
"Content-Type": "application/json",
|
|
684
|
+
...options.headers
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
const runnerServiceListRunners = (options) => (options?.client ?? client).get({
|
|
688
|
+
url: "/apis/auv/runtime/v1/runners",
|
|
689
|
+
...options
|
|
690
|
+
});
|
|
691
|
+
const runnerServiceCreateRunner = (options) => (options.client ?? client).post({
|
|
692
|
+
url: "/apis/auv/runtime/v1/runners",
|
|
693
|
+
...options,
|
|
694
|
+
headers: {
|
|
695
|
+
"Content-Type": "application/json",
|
|
696
|
+
...options.headers
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
const runnerServiceDeleteRunner = (options) => (options.client ?? client).post({
|
|
700
|
+
url: "/apis/auv/runtime/v1/runners:delete",
|
|
701
|
+
...options,
|
|
702
|
+
headers: {
|
|
703
|
+
"Content-Type": "application/json",
|
|
704
|
+
...options.headers
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
/**
|
|
708
|
+
* NOTICE(tonic-rest-path): typed RunnerRef path projection is deferred until
|
|
709
|
+
* the generator supports arbitrary nested resource-reference messages.
|
|
710
|
+
*/
|
|
711
|
+
const runnerServiceGetRunner = (options) => (options.client ?? client).post({
|
|
712
|
+
url: "/apis/auv/runtime/v1/runners:get",
|
|
713
|
+
...options,
|
|
714
|
+
headers: {
|
|
715
|
+
"Content-Type": "application/json",
|
|
716
|
+
...options.headers
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
const runServiceListRuns = (options) => (options?.client ?? client).get({
|
|
720
|
+
url: "/apis/auv/runtime/v1/runs",
|
|
721
|
+
...options
|
|
722
|
+
});
|
|
723
|
+
const runServiceCreateRun = (options) => (options.client ?? client).post({
|
|
724
|
+
url: "/apis/auv/runtime/v1/runs",
|
|
725
|
+
...options,
|
|
726
|
+
headers: {
|
|
727
|
+
"Content-Type": "application/json",
|
|
728
|
+
...options.headers
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
/**
|
|
732
|
+
* NOTICE(tonic-rest-path): typed RunRef path projection is deferred until
|
|
733
|
+
* the generator supports arbitrary nested resource-reference messages.
|
|
734
|
+
*/
|
|
735
|
+
const runServiceGetRun = (options) => (options.client ?? client).post({
|
|
736
|
+
url: "/apis/auv/runtime/v1/runs:get",
|
|
737
|
+
...options,
|
|
738
|
+
headers: {
|
|
739
|
+
"Content-Type": "application/json",
|
|
740
|
+
...options.headers
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
const runServiceStopRun = (options) => (options.client ?? client).post({
|
|
744
|
+
url: "/apis/auv/runtime/v1/runs:stop",
|
|
745
|
+
...options,
|
|
746
|
+
headers: {
|
|
747
|
+
"Content-Type": "application/json",
|
|
748
|
+
...options.headers
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
const discoveryServiceGetApiNamespace = (options) => (options.client ?? client).get({
|
|
752
|
+
url: "/apis/{namespace}",
|
|
753
|
+
...options
|
|
754
|
+
});
|
|
755
|
+
const discoveryServiceGetApiGroupVersion = (options) => (options.client ?? client).get({
|
|
756
|
+
url: "/apis/{namespace}/{group}/{version}",
|
|
757
|
+
...options
|
|
758
|
+
});
|
|
759
|
+
const healthServiceCheck = (options) => (options?.client ?? client).get({
|
|
760
|
+
url: "/health",
|
|
761
|
+
...options
|
|
762
|
+
});
|
|
763
|
+
//#endregion
|
|
764
|
+
export { createClient, deviceServiceGetDevice, deviceServiceListDevices, discoveryServiceGetApiGroupVersion, discoveryServiceGetApiNamespace, discoveryServiceListApiNamespaces, healthServiceCheck, pairingServiceCreatePairingToken, pairingServicePairDevice, pairingServiceRevokeDeviceCredential, pairingServiceSetPairedDeviceEnabled, pairingServiceUnpairDevice, runServiceCreateRun, runServiceGetRun, runServiceListRuns, runServiceStopRun, runnerClassServiceGetRunnerClass, runnerClassServiceListRunnerClasses, runnerServiceCreateRunner, runnerServiceDeleteRunner, runnerServiceGetRunner, runnerServiceListRunners };
|
|
765
|
+
|
|
766
|
+
//# sourceMappingURL=index.js.map
|