@opencode-ai/sdk 1.0.134 → 1.0.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +1 -1
- package/dist/client.js +7 -6
- package/dist/gen/sdk.gen.d.ts +32 -7
- package/dist/gen/sdk.gen.js +74 -15
- package/dist/gen/types.gen.d.ts +184 -1
- package/dist/v2/client.d.ts +7 -0
- package/dist/v2/client.js +25 -0
- package/dist/v2/gen/client/client.gen.d.ts +2 -0
- package/dist/v2/gen/client/client.gen.js +225 -0
- package/dist/v2/gen/client/index.d.ts +8 -0
- package/dist/v2/gen/client/index.js +6 -0
- package/dist/v2/gen/client/types.gen.d.ts +117 -0
- package/dist/v2/gen/client/types.gen.js +2 -0
- package/dist/v2/gen/client/utils.gen.d.ts +33 -0
- package/dist/v2/gen/client/utils.gen.js +226 -0
- package/dist/v2/gen/client.gen.d.ts +12 -0
- package/dist/v2/gen/client.gen.js +3 -0
- package/dist/v2/gen/core/auth.gen.d.ts +18 -0
- package/dist/v2/gen/core/auth.gen.js +14 -0
- package/dist/v2/gen/core/bodySerializer.gen.d.ts +25 -0
- package/dist/v2/gen/core/bodySerializer.gen.js +57 -0
- package/dist/v2/gen/core/params.gen.d.ts +43 -0
- package/dist/v2/gen/core/params.gen.js +102 -0
- package/dist/v2/gen/core/pathSerializer.gen.d.ts +33 -0
- package/dist/v2/gen/core/pathSerializer.gen.js +106 -0
- package/dist/v2/gen/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/v2/gen/core/queryKeySerializer.gen.js +93 -0
- package/dist/v2/gen/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/v2/gen/core/serverSentEvents.gen.js +131 -0
- package/dist/v2/gen/core/types.gen.d.ts +78 -0
- package/dist/v2/gen/core/types.gen.js +2 -0
- package/dist/v2/gen/core/utils.gen.d.ts +19 -0
- package/dist/v2/gen/core/utils.gen.js +87 -0
- package/dist/v2/gen/sdk.gen.d.ts +850 -0
- package/dist/v2/gen/sdk.gen.js +1626 -0
- package/dist/v2/gen/types.gen.d.ts +3357 -0
- package/dist/v2/gen/types.gen.js +2 -0
- package/dist/v2/index.d.ts +10 -0
- package/dist/v2/index.js +16 -0
- package/dist/v2/server.d.ts +23 -0
- package/dist/v2/server.js +91 -0
- package/package.json +15 -3
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { createSseClient } from "../core/serverSentEvents.gen.js";
|
|
3
|
+
import { getValidRequestBody } from "../core/utils.gen.js";
|
|
4
|
+
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from "./utils.gen.js";
|
|
5
|
+
export const createClient = (config = {}) => {
|
|
6
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
7
|
+
const getConfig = () => ({ ..._config });
|
|
8
|
+
const setConfig = (config) => {
|
|
9
|
+
_config = mergeConfigs(_config, config);
|
|
10
|
+
return getConfig();
|
|
11
|
+
};
|
|
12
|
+
const interceptors = createInterceptors();
|
|
13
|
+
const beforeRequest = async (options) => {
|
|
14
|
+
const opts = {
|
|
15
|
+
..._config,
|
|
16
|
+
...options,
|
|
17
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
19
|
+
serializedBody: undefined,
|
|
20
|
+
};
|
|
21
|
+
if (opts.security) {
|
|
22
|
+
await setAuthParams({
|
|
23
|
+
...opts,
|
|
24
|
+
security: opts.security,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (opts.requestValidator) {
|
|
28
|
+
await opts.requestValidator(opts);
|
|
29
|
+
}
|
|
30
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
31
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
32
|
+
}
|
|
33
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
34
|
+
if (opts.body === undefined || opts.serializedBody === "") {
|
|
35
|
+
opts.headers.delete("Content-Type");
|
|
36
|
+
}
|
|
37
|
+
const url = buildUrl(opts);
|
|
38
|
+
return { opts, url };
|
|
39
|
+
};
|
|
40
|
+
const request = async (options) => {
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
const { opts, url } = await beforeRequest(options);
|
|
43
|
+
const requestInit = {
|
|
44
|
+
redirect: "follow",
|
|
45
|
+
...opts,
|
|
46
|
+
body: getValidRequestBody(opts),
|
|
47
|
+
};
|
|
48
|
+
let request = new Request(url, requestInit);
|
|
49
|
+
for (const fn of interceptors.request.fns) {
|
|
50
|
+
if (fn) {
|
|
51
|
+
request = await fn(request, opts);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
55
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
56
|
+
const _fetch = opts.fetch;
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await _fetch(request);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
63
|
+
let finalError = error;
|
|
64
|
+
for (const fn of interceptors.error.fns) {
|
|
65
|
+
if (fn) {
|
|
66
|
+
finalError = (await fn(error, undefined, request, opts));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finalError = finalError || {};
|
|
70
|
+
if (opts.throwOnError) {
|
|
71
|
+
throw finalError;
|
|
72
|
+
}
|
|
73
|
+
// Return error response
|
|
74
|
+
return opts.responseStyle === "data"
|
|
75
|
+
? undefined
|
|
76
|
+
: {
|
|
77
|
+
error: finalError,
|
|
78
|
+
request,
|
|
79
|
+
response: undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
for (const fn of interceptors.response.fns) {
|
|
83
|
+
if (fn) {
|
|
84
|
+
response = await fn(response, request, opts);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const result = {
|
|
88
|
+
request,
|
|
89
|
+
response,
|
|
90
|
+
};
|
|
91
|
+
if (response.ok) {
|
|
92
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
93
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
94
|
+
let emptyData;
|
|
95
|
+
switch (parseAs) {
|
|
96
|
+
case "arrayBuffer":
|
|
97
|
+
case "blob":
|
|
98
|
+
case "text":
|
|
99
|
+
emptyData = await response[parseAs]();
|
|
100
|
+
break;
|
|
101
|
+
case "formData":
|
|
102
|
+
emptyData = new FormData();
|
|
103
|
+
break;
|
|
104
|
+
case "stream":
|
|
105
|
+
emptyData = response.body;
|
|
106
|
+
break;
|
|
107
|
+
case "json":
|
|
108
|
+
default:
|
|
109
|
+
emptyData = {};
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
return opts.responseStyle === "data"
|
|
113
|
+
? emptyData
|
|
114
|
+
: {
|
|
115
|
+
data: emptyData,
|
|
116
|
+
...result,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
let data;
|
|
120
|
+
switch (parseAs) {
|
|
121
|
+
case "arrayBuffer":
|
|
122
|
+
case "blob":
|
|
123
|
+
case "formData":
|
|
124
|
+
case "json":
|
|
125
|
+
case "text":
|
|
126
|
+
data = await response[parseAs]();
|
|
127
|
+
break;
|
|
128
|
+
case "stream":
|
|
129
|
+
return opts.responseStyle === "data"
|
|
130
|
+
? response.body
|
|
131
|
+
: {
|
|
132
|
+
data: response.body,
|
|
133
|
+
...result,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (parseAs === "json") {
|
|
137
|
+
if (opts.responseValidator) {
|
|
138
|
+
await opts.responseValidator(data);
|
|
139
|
+
}
|
|
140
|
+
if (opts.responseTransformer) {
|
|
141
|
+
data = await opts.responseTransformer(data);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return opts.responseStyle === "data"
|
|
145
|
+
? data
|
|
146
|
+
: {
|
|
147
|
+
data,
|
|
148
|
+
...result,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const textError = await response.text();
|
|
152
|
+
let jsonError;
|
|
153
|
+
try {
|
|
154
|
+
jsonError = JSON.parse(textError);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// noop
|
|
158
|
+
}
|
|
159
|
+
const error = jsonError ?? textError;
|
|
160
|
+
let finalError = error;
|
|
161
|
+
for (const fn of interceptors.error.fns) {
|
|
162
|
+
if (fn) {
|
|
163
|
+
finalError = (await fn(error, response, request, opts));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
finalError = finalError || {};
|
|
167
|
+
if (opts.throwOnError) {
|
|
168
|
+
throw finalError;
|
|
169
|
+
}
|
|
170
|
+
// TODO: we probably want to return error and improve types
|
|
171
|
+
return opts.responseStyle === "data"
|
|
172
|
+
? undefined
|
|
173
|
+
: {
|
|
174
|
+
error: finalError,
|
|
175
|
+
...result,
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
179
|
+
const makeSseFn = (method) => async (options) => {
|
|
180
|
+
const { opts, url } = await beforeRequest(options);
|
|
181
|
+
return createSseClient({
|
|
182
|
+
...opts,
|
|
183
|
+
body: opts.body,
|
|
184
|
+
headers: opts.headers,
|
|
185
|
+
method,
|
|
186
|
+
onRequest: async (url, init) => {
|
|
187
|
+
let request = new Request(url, init);
|
|
188
|
+
for (const fn of interceptors.request.fns) {
|
|
189
|
+
if (fn) {
|
|
190
|
+
request = await fn(request, opts);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return request;
|
|
194
|
+
},
|
|
195
|
+
url,
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
return {
|
|
199
|
+
buildUrl,
|
|
200
|
+
connect: makeMethodFn("CONNECT"),
|
|
201
|
+
delete: makeMethodFn("DELETE"),
|
|
202
|
+
get: makeMethodFn("GET"),
|
|
203
|
+
getConfig,
|
|
204
|
+
head: makeMethodFn("HEAD"),
|
|
205
|
+
interceptors,
|
|
206
|
+
options: makeMethodFn("OPTIONS"),
|
|
207
|
+
patch: makeMethodFn("PATCH"),
|
|
208
|
+
post: makeMethodFn("POST"),
|
|
209
|
+
put: makeMethodFn("PUT"),
|
|
210
|
+
request,
|
|
211
|
+
setConfig,
|
|
212
|
+
sse: {
|
|
213
|
+
connect: makeSseFn("CONNECT"),
|
|
214
|
+
delete: makeSseFn("DELETE"),
|
|
215
|
+
get: makeSseFn("GET"),
|
|
216
|
+
head: makeSseFn("HEAD"),
|
|
217
|
+
options: makeSseFn("OPTIONS"),
|
|
218
|
+
patch: makeSseFn("PATCH"),
|
|
219
|
+
post: makeSseFn("POST"),
|
|
220
|
+
put: makeSseFn("PUT"),
|
|
221
|
+
trace: makeSseFn("TRACE"),
|
|
222
|
+
},
|
|
223
|
+
trace: makeMethodFn("TRACE"),
|
|
224
|
+
};
|
|
225
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Auth } from "../core/auth.gen.js";
|
|
2
|
+
export type { QuerySerializerOptions } from "../core/bodySerializer.gen.js";
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from "../core/bodySerializer.gen.js";
|
|
4
|
+
export { buildClientParams } from "../core/params.gen.js";
|
|
5
|
+
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js";
|
|
6
|
+
export { createClient } from "./client.gen.js";
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from "./types.gen.js";
|
|
8
|
+
export { createConfig, mergeHeaders } from "./utils.gen.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from "../core/bodySerializer.gen.js";
|
|
3
|
+
export { buildClientParams } from "../core/params.gen.js";
|
|
4
|
+
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js";
|
|
5
|
+
export { createClient } from "./client.gen.js";
|
|
6
|
+
export { createConfig, mergeHeaders } from "./utils.gen.js";
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Auth } from "../core/auth.gen.js";
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from "../core/serverSentEvents.gen.js";
|
|
3
|
+
import type { Client as CoreClient, Config as CoreConfig } from "../core/types.gen.js";
|
|
4
|
+
import type { Middleware } from "./utils.gen.js";
|
|
5
|
+
export type ResponseStyle = "data" | "fields";
|
|
6
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, "body" | "headers" | "method">, CoreConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for all requests made by this client.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: T["baseUrl"];
|
|
11
|
+
/**
|
|
12
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
13
|
+
* fetch instance.
|
|
14
|
+
*
|
|
15
|
+
* @default globalThis.fetch
|
|
16
|
+
*/
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/**
|
|
19
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
20
|
+
* options won't have any effect.
|
|
21
|
+
*
|
|
22
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
23
|
+
*/
|
|
24
|
+
next?: never;
|
|
25
|
+
/**
|
|
26
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
27
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
28
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
29
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
30
|
+
*
|
|
31
|
+
* @default 'auto'
|
|
32
|
+
*/
|
|
33
|
+
parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text";
|
|
34
|
+
/**
|
|
35
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
36
|
+
*
|
|
37
|
+
* @default 'fields'
|
|
38
|
+
*/
|
|
39
|
+
responseStyle?: ResponseStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Throw an error instead of returning it in the response?
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
throwOnError?: T["throwOnError"];
|
|
46
|
+
}
|
|
47
|
+
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = "fields", ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
|
+
responseStyle: TResponseStyle;
|
|
49
|
+
throwOnError: ThrowOnError;
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, "onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"> {
|
|
51
|
+
/**
|
|
52
|
+
* Any body that you want to add to your request.
|
|
53
|
+
*
|
|
54
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
55
|
+
*/
|
|
56
|
+
body?: unknown;
|
|
57
|
+
path?: Record<string, unknown>;
|
|
58
|
+
query?: Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Security mechanism(s) to use for the request.
|
|
61
|
+
*/
|
|
62
|
+
security?: ReadonlyArray<Auth>;
|
|
63
|
+
url: Url;
|
|
64
|
+
}
|
|
65
|
+
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = "fields", ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
serializedBody?: string;
|
|
67
|
+
}
|
|
68
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = "fields"> = ThrowOnError extends true ? Promise<TResponseStyle extends "data" ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
69
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
70
|
+
request: Request;
|
|
71
|
+
response: Response;
|
|
72
|
+
}> : Promise<TResponseStyle extends "data" ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
73
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
74
|
+
error: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
data: undefined;
|
|
77
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
78
|
+
}) & {
|
|
79
|
+
request: Request;
|
|
80
|
+
response: Response;
|
|
81
|
+
}>;
|
|
82
|
+
export interface ClientOptions {
|
|
83
|
+
baseUrl?: string;
|
|
84
|
+
responseStyle?: ResponseStyle;
|
|
85
|
+
throwOnError?: boolean;
|
|
86
|
+
}
|
|
87
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
89
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
90
|
+
type BuildUrlFn = <TData extends {
|
|
91
|
+
body?: unknown;
|
|
92
|
+
path?: Record<string, unknown>;
|
|
93
|
+
query?: Record<string, unknown>;
|
|
94
|
+
url: string;
|
|
95
|
+
}>(options: TData & Options<TData>) => string;
|
|
96
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
97
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
101
|
+
* and the returned object will become the client's initial configuration.
|
|
102
|
+
*
|
|
103
|
+
* You may want to initialize your client this way instead of calling
|
|
104
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
105
|
+
* to ensure your client always has the correct values.
|
|
106
|
+
*/
|
|
107
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
108
|
+
export interface TDataShape {
|
|
109
|
+
body?: unknown;
|
|
110
|
+
headers?: unknown;
|
|
111
|
+
path?: unknown;
|
|
112
|
+
query?: unknown;
|
|
113
|
+
url: string;
|
|
114
|
+
}
|
|
115
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
116
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = "fields"> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> & ([TData] extends [never] ? unknown : Omit<TData, "url">);
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { QuerySerializerOptions } from "../core/bodySerializer.gen.js";
|
|
2
|
+
import type { Client, ClientOptions, Config, RequestOptions } from "./types.gen.js";
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => (queryParams: T) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Infers parseAs value from provided Content-Type header.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
+
export declare const setAuthParams: ({ security, ...options }: Pick<Required<RequestOptions>, "security"> & Pick<RequestOptions, "auth" | "query"> & {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
export declare const buildUrl: Client["buildUrl"];
|
|
12
|
+
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
13
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
14
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
|
|
15
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
16
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
17
|
+
declare class Interceptors<Interceptor> {
|
|
18
|
+
fns: Array<Interceptor | null>;
|
|
19
|
+
clear(): void;
|
|
20
|
+
eject(id: number | Interceptor): void;
|
|
21
|
+
exists(id: number | Interceptor): boolean;
|
|
22
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
23
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
24
|
+
use(fn: Interceptor): number;
|
|
25
|
+
}
|
|
26
|
+
export interface Middleware<Req, Res, Err, Options> {
|
|
27
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
28
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
29
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
30
|
+
}
|
|
31
|
+
export declare const createInterceptors: <Req, Res, Err, Options>() => Middleware<Req, Res, Err, Options>;
|
|
32
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { getAuthToken } from "../core/auth.gen.js";
|
|
3
|
+
import { jsonBodySerializer } from "../core/bodySerializer.gen.js";
|
|
4
|
+
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen.js";
|
|
5
|
+
import { getUrl } from "../core/utils.gen.js";
|
|
6
|
+
export const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
7
|
+
const querySerializer = (queryParams) => {
|
|
8
|
+
const search = [];
|
|
9
|
+
if (queryParams && typeof queryParams === "object") {
|
|
10
|
+
for (const name in queryParams) {
|
|
11
|
+
const value = queryParams[name];
|
|
12
|
+
if (value === undefined || value === null) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const options = parameters[name] || args;
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
const serializedArray = serializeArrayParam({
|
|
18
|
+
allowReserved: options.allowReserved,
|
|
19
|
+
explode: true,
|
|
20
|
+
name,
|
|
21
|
+
style: "form",
|
|
22
|
+
value,
|
|
23
|
+
...options.array,
|
|
24
|
+
});
|
|
25
|
+
if (serializedArray)
|
|
26
|
+
search.push(serializedArray);
|
|
27
|
+
}
|
|
28
|
+
else if (typeof value === "object") {
|
|
29
|
+
const serializedObject = serializeObjectParam({
|
|
30
|
+
allowReserved: options.allowReserved,
|
|
31
|
+
explode: true,
|
|
32
|
+
name,
|
|
33
|
+
style: "deepObject",
|
|
34
|
+
value: value,
|
|
35
|
+
...options.object,
|
|
36
|
+
});
|
|
37
|
+
if (serializedObject)
|
|
38
|
+
search.push(serializedObject);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
42
|
+
allowReserved: options.allowReserved,
|
|
43
|
+
name,
|
|
44
|
+
value: value,
|
|
45
|
+
});
|
|
46
|
+
if (serializedPrimitive)
|
|
47
|
+
search.push(serializedPrimitive);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return search.join("&");
|
|
52
|
+
};
|
|
53
|
+
return querySerializer;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Infers parseAs value from provided Content-Type header.
|
|
57
|
+
*/
|
|
58
|
+
export const getParseAs = (contentType) => {
|
|
59
|
+
if (!contentType) {
|
|
60
|
+
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
61
|
+
// which is effectively the same as the 'stream' option.
|
|
62
|
+
return "stream";
|
|
63
|
+
}
|
|
64
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
65
|
+
if (!cleanContent) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
69
|
+
return "json";
|
|
70
|
+
}
|
|
71
|
+
if (cleanContent === "multipart/form-data") {
|
|
72
|
+
return "formData";
|
|
73
|
+
}
|
|
74
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
75
|
+
return "blob";
|
|
76
|
+
}
|
|
77
|
+
if (cleanContent.startsWith("text/")) {
|
|
78
|
+
return "text";
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
};
|
|
82
|
+
const checkForExistence = (options, name) => {
|
|
83
|
+
if (!name) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
};
|
|
91
|
+
export const setAuthParams = async ({ security, ...options }) => {
|
|
92
|
+
for (const auth of security) {
|
|
93
|
+
if (checkForExistence(options, auth.name)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const token = await getAuthToken(auth, options.auth);
|
|
97
|
+
if (!token) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const name = auth.name ?? "Authorization";
|
|
101
|
+
switch (auth.in) {
|
|
102
|
+
case "query":
|
|
103
|
+
if (!options.query) {
|
|
104
|
+
options.query = {};
|
|
105
|
+
}
|
|
106
|
+
options.query[name] = token;
|
|
107
|
+
break;
|
|
108
|
+
case "cookie":
|
|
109
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
110
|
+
break;
|
|
111
|
+
case "header":
|
|
112
|
+
default:
|
|
113
|
+
options.headers.set(name, token);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
export const buildUrl = (options) => getUrl({
|
|
119
|
+
baseUrl: options.baseUrl,
|
|
120
|
+
path: options.path,
|
|
121
|
+
query: options.query,
|
|
122
|
+
querySerializer: typeof options.querySerializer === "function"
|
|
123
|
+
? options.querySerializer
|
|
124
|
+
: createQuerySerializer(options.querySerializer),
|
|
125
|
+
url: options.url,
|
|
126
|
+
});
|
|
127
|
+
export const mergeConfigs = (a, b) => {
|
|
128
|
+
const config = { ...a, ...b };
|
|
129
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
130
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
131
|
+
}
|
|
132
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
133
|
+
return config;
|
|
134
|
+
};
|
|
135
|
+
const headersEntries = (headers) => {
|
|
136
|
+
const entries = [];
|
|
137
|
+
headers.forEach((value, key) => {
|
|
138
|
+
entries.push([key, value]);
|
|
139
|
+
});
|
|
140
|
+
return entries;
|
|
141
|
+
};
|
|
142
|
+
export const mergeHeaders = (...headers) => {
|
|
143
|
+
const mergedHeaders = new Headers();
|
|
144
|
+
for (const header of headers) {
|
|
145
|
+
if (!header) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
149
|
+
for (const [key, value] of iterator) {
|
|
150
|
+
if (value === null) {
|
|
151
|
+
mergedHeaders.delete(key);
|
|
152
|
+
}
|
|
153
|
+
else if (Array.isArray(value)) {
|
|
154
|
+
for (const v of value) {
|
|
155
|
+
mergedHeaders.append(key, v);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (value !== undefined) {
|
|
159
|
+
// assume object headers are meant to be JSON stringified, i.e. their
|
|
160
|
+
// content value in OpenAPI specification is 'application/json'
|
|
161
|
+
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return mergedHeaders;
|
|
166
|
+
};
|
|
167
|
+
class Interceptors {
|
|
168
|
+
fns = [];
|
|
169
|
+
clear() {
|
|
170
|
+
this.fns = [];
|
|
171
|
+
}
|
|
172
|
+
eject(id) {
|
|
173
|
+
const index = this.getInterceptorIndex(id);
|
|
174
|
+
if (this.fns[index]) {
|
|
175
|
+
this.fns[index] = null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exists(id) {
|
|
179
|
+
const index = this.getInterceptorIndex(id);
|
|
180
|
+
return Boolean(this.fns[index]);
|
|
181
|
+
}
|
|
182
|
+
getInterceptorIndex(id) {
|
|
183
|
+
if (typeof id === "number") {
|
|
184
|
+
return this.fns[id] ? id : -1;
|
|
185
|
+
}
|
|
186
|
+
return this.fns.indexOf(id);
|
|
187
|
+
}
|
|
188
|
+
update(id, fn) {
|
|
189
|
+
const index = this.getInterceptorIndex(id);
|
|
190
|
+
if (this.fns[index]) {
|
|
191
|
+
this.fns[index] = fn;
|
|
192
|
+
return id;
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
use(fn) {
|
|
197
|
+
this.fns.push(fn);
|
|
198
|
+
return this.fns.length - 1;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export const createInterceptors = () => ({
|
|
202
|
+
error: new Interceptors(),
|
|
203
|
+
request: new Interceptors(),
|
|
204
|
+
response: new Interceptors(),
|
|
205
|
+
});
|
|
206
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
207
|
+
allowReserved: false,
|
|
208
|
+
array: {
|
|
209
|
+
explode: true,
|
|
210
|
+
style: "form",
|
|
211
|
+
},
|
|
212
|
+
object: {
|
|
213
|
+
explode: true,
|
|
214
|
+
style: "deepObject",
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
const defaultHeaders = {
|
|
218
|
+
"Content-Type": "application/json",
|
|
219
|
+
};
|
|
220
|
+
export const createConfig = (override = {}) => ({
|
|
221
|
+
...jsonBodySerializer,
|
|
222
|
+
headers: defaultHeaders,
|
|
223
|
+
parseAs: "auto",
|
|
224
|
+
querySerializer: defaultQuerySerializer,
|
|
225
|
+
...override,
|
|
226
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ClientOptions, type Config } from "./client/index.js";
|
|
2
|
+
import type { ClientOptions as ClientOptions2 } from "./types.gen.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
5
|
+
* and the returned object will become the client's initial configuration.
|
|
6
|
+
*
|
|
7
|
+
* You may want to initialize your client this way instead of calling
|
|
8
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
9
|
+
* to ensure your client always has the correct values.
|
|
10
|
+
*/
|
|
11
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
|
+
export declare const client: import("./client/types.gen.js").Client;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type AuthToken = string | undefined;
|
|
2
|
+
export interface Auth {
|
|
3
|
+
/**
|
|
4
|
+
* Which part of the request do we use to send the auth?
|
|
5
|
+
*
|
|
6
|
+
* @default 'header'
|
|
7
|
+
*/
|
|
8
|
+
in?: "header" | "query" | "cookie";
|
|
9
|
+
/**
|
|
10
|
+
* Header or query parameter name.
|
|
11
|
+
*
|
|
12
|
+
* @default 'Authorization'
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
scheme?: "basic" | "bearer";
|
|
16
|
+
type: "apiKey" | "http";
|
|
17
|
+
}
|
|
18
|
+
export declare const getAuthToken: (auth: Auth, callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken) => Promise<string | undefined>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export const getAuthToken = async (auth, callback) => {
|
|
3
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
4
|
+
if (!token) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (auth.scheme === "bearer") {
|
|
8
|
+
return `Bearer ${token}`;
|
|
9
|
+
}
|
|
10
|
+
if (auth.scheme === "basic") {
|
|
11
|
+
return `Basic ${btoa(token)}`;
|
|
12
|
+
}
|
|
13
|
+
return token;
|
|
14
|
+
};
|