@opencode-ai/sdk 0.0.0-snapshot-kmdr-debug-202512052155 → 0.0.0-snapshot-kmdr-debug-202512081538
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 +24 -7
- package/dist/gen/sdk.gen.js +56 -15
- package/dist/gen/types.gen.d.ts +146 -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 +836 -0
- package/dist/v2/gen/sdk.gen.js +1590 -0
- package/dist/v2/gen/types.gen.d.ts +3322 -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,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
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.gen.js";
|
|
2
|
+
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
3
|
+
export type BodySerializer = (body: any) => any;
|
|
4
|
+
type QuerySerializerOptionsObject = {
|
|
5
|
+
allowReserved?: boolean;
|
|
6
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
7
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
8
|
+
};
|
|
9
|
+
export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
10
|
+
/**
|
|
11
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
12
|
+
* override the global array/object settings for specific parameter names.
|
|
13
|
+
*/
|
|
14
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
15
|
+
};
|
|
16
|
+
export declare const formDataBodySerializer: {
|
|
17
|
+
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
|
|
18
|
+
};
|
|
19
|
+
export declare const jsonBodySerializer: {
|
|
20
|
+
bodySerializer: <T>(body: T) => string;
|
|
21
|
+
};
|
|
22
|
+
export declare const urlSearchParamsBodySerializer: {
|
|
23
|
+
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
const serializeFormDataPair = (data, key, value) => {
|
|
3
|
+
if (typeof value === "string" || value instanceof Blob) {
|
|
4
|
+
data.append(key, value);
|
|
5
|
+
}
|
|
6
|
+
else if (value instanceof Date) {
|
|
7
|
+
data.append(key, value.toISOString());
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
data.append(key, JSON.stringify(value));
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const serializeUrlSearchParamsPair = (data, key, value) => {
|
|
14
|
+
if (typeof value === "string") {
|
|
15
|
+
data.append(key, value);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
data.append(key, JSON.stringify(value));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const formDataBodySerializer = {
|
|
22
|
+
bodySerializer: (body) => {
|
|
23
|
+
const data = new FormData();
|
|
24
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
25
|
+
if (value === undefined || value === null) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
value.forEach((v) => serializeFormDataPair(data, key, v));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
serializeFormDataPair(data, key, value);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return data;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export const jsonBodySerializer = {
|
|
39
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => (typeof value === "bigint" ? value.toString() : value)),
|
|
40
|
+
};
|
|
41
|
+
export const urlSearchParamsBodySerializer = {
|
|
42
|
+
bodySerializer: (body) => {
|
|
43
|
+
const data = new URLSearchParams();
|
|
44
|
+
Object.entries(body).forEach(([key, value]) => {
|
|
45
|
+
if (value === undefined || value === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
serializeUrlSearchParamsPair(data, key, value);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return data.toString();
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type Slot = "body" | "headers" | "path" | "query";
|
|
2
|
+
export type Field = {
|
|
3
|
+
in: Exclude<Slot, "body">;
|
|
4
|
+
/**
|
|
5
|
+
* Field name. This is the name we want the user to see and use.
|
|
6
|
+
*/
|
|
7
|
+
key: string;
|
|
8
|
+
/**
|
|
9
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
10
|
+
* If omitted, we use the same value as `key`.
|
|
11
|
+
*/
|
|
12
|
+
map?: string;
|
|
13
|
+
} | {
|
|
14
|
+
in: Extract<Slot, "body">;
|
|
15
|
+
/**
|
|
16
|
+
* Key isn't required for bodies.
|
|
17
|
+
*/
|
|
18
|
+
key?: string;
|
|
19
|
+
map?: string;
|
|
20
|
+
} | {
|
|
21
|
+
/**
|
|
22
|
+
* Field name. This is the name we want the user to see and use.
|
|
23
|
+
*/
|
|
24
|
+
key: string;
|
|
25
|
+
/**
|
|
26
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
27
|
+
* If `in` is omitted, `map` aliases `key` to the transport layer.
|
|
28
|
+
*/
|
|
29
|
+
map: Slot;
|
|
30
|
+
};
|
|
31
|
+
export interface Fields {
|
|
32
|
+
allowExtra?: Partial<Record<Slot, boolean>>;
|
|
33
|
+
args?: ReadonlyArray<Field>;
|
|
34
|
+
}
|
|
35
|
+
export type FieldsConfig = ReadonlyArray<Field | Fields>;
|
|
36
|
+
interface Params {
|
|
37
|
+
body: unknown;
|
|
38
|
+
headers: Record<string, unknown>;
|
|
39
|
+
path: Record<string, unknown>;
|
|
40
|
+
query: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
export declare const buildClientParams: (args: ReadonlyArray<unknown>, fields: FieldsConfig) => Params;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
const extraPrefixesMap = {
|
|
3
|
+
$body_: "body",
|
|
4
|
+
$headers_: "headers",
|
|
5
|
+
$path_: "path",
|
|
6
|
+
$query_: "query",
|
|
7
|
+
};
|
|
8
|
+
const extraPrefixes = Object.entries(extraPrefixesMap);
|
|
9
|
+
const buildKeyMap = (fields, map) => {
|
|
10
|
+
if (!map) {
|
|
11
|
+
map = new Map();
|
|
12
|
+
}
|
|
13
|
+
for (const config of fields) {
|
|
14
|
+
if ("in" in config) {
|
|
15
|
+
if (config.key) {
|
|
16
|
+
map.set(config.key, {
|
|
17
|
+
in: config.in,
|
|
18
|
+
map: config.map,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if ("key" in config) {
|
|
23
|
+
map.set(config.key, {
|
|
24
|
+
map: config.map,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else if (config.args) {
|
|
28
|
+
buildKeyMap(config.args, map);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return map;
|
|
32
|
+
};
|
|
33
|
+
const stripEmptySlots = (params) => {
|
|
34
|
+
for (const [slot, value] of Object.entries(params)) {
|
|
35
|
+
if (value && typeof value === "object" && !Object.keys(value).length) {
|
|
36
|
+
delete params[slot];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const buildClientParams = (args, fields) => {
|
|
41
|
+
const params = {
|
|
42
|
+
body: {},
|
|
43
|
+
headers: {},
|
|
44
|
+
path: {},
|
|
45
|
+
query: {},
|
|
46
|
+
};
|
|
47
|
+
const map = buildKeyMap(fields);
|
|
48
|
+
let config;
|
|
49
|
+
for (const [index, arg] of args.entries()) {
|
|
50
|
+
if (fields[index]) {
|
|
51
|
+
config = fields[index];
|
|
52
|
+
}
|
|
53
|
+
if (!config) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if ("in" in config) {
|
|
57
|
+
if (config.key) {
|
|
58
|
+
const field = map.get(config.key);
|
|
59
|
+
const name = field.map || config.key;
|
|
60
|
+
if (field.in) {
|
|
61
|
+
;
|
|
62
|
+
params[field.in][name] = arg;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
params.body = arg;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
for (const [key, value] of Object.entries(arg ?? {})) {
|
|
71
|
+
const field = map.get(key);
|
|
72
|
+
if (field) {
|
|
73
|
+
if (field.in) {
|
|
74
|
+
const name = field.map || key;
|
|
75
|
+
params[field.in][name] = value;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
params[field.map] = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
|
|
83
|
+
if (extra) {
|
|
84
|
+
const [prefix, slot] = extra;
|
|
85
|
+
params[slot][key.slice(prefix.length)] = value;
|
|
86
|
+
}
|
|
87
|
+
else if ("allowExtra" in config && config.allowExtra) {
|
|
88
|
+
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
89
|
+
if (allowed) {
|
|
90
|
+
;
|
|
91
|
+
params[slot][key] = value;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
stripEmptySlots(params);
|
|
101
|
+
return params;
|
|
102
|
+
};
|