@llamaduck/forgejo-ts 14.0.2-2 → 14.0.2-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.
@@ -0,0 +1,339 @@
1
+ import { CreateAxiosDefaults, AxiosStatic, AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosError } from 'axios';
2
+
3
+ type AuthToken = string | undefined;
4
+ interface Auth {
5
+ /**
6
+ * Which part of the request do we use to send the auth?
7
+ *
8
+ * @default 'header'
9
+ */
10
+ in?: 'header' | 'query' | 'cookie';
11
+ /**
12
+ * Header or query parameter name.
13
+ *
14
+ * @default 'Authorization'
15
+ */
16
+ name?: string;
17
+ scheme?: 'basic' | 'bearer';
18
+ type: 'apiKey' | 'http';
19
+ }
20
+
21
+ interface SerializerOptions<T> {
22
+ /**
23
+ * @default true
24
+ */
25
+ explode: boolean;
26
+ style: T;
27
+ }
28
+ type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
29
+ type ObjectStyle = 'form' | 'deepObject';
30
+
31
+ type QuerySerializer = (query: Record<string, unknown>) => string;
32
+ type BodySerializer = (body: any) => any;
33
+ type QuerySerializerOptionsObject = {
34
+ allowReserved?: boolean;
35
+ array?: Partial<SerializerOptions<ArrayStyle>>;
36
+ object?: Partial<SerializerOptions<ObjectStyle>>;
37
+ };
38
+ type QuerySerializerOptions = QuerySerializerOptionsObject & {
39
+ /**
40
+ * Per-parameter serialization overrides. When provided, these settings
41
+ * override the global array/object settings for specific parameter names.
42
+ */
43
+ parameters?: Record<string, QuerySerializerOptionsObject>;
44
+ };
45
+ declare const formDataBodySerializer: {
46
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
47
+ };
48
+ declare const jsonBodySerializer: {
49
+ bodySerializer: <T>(body: T) => string;
50
+ };
51
+ declare const urlSearchParamsBodySerializer: {
52
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
53
+ };
54
+
55
+ type Slot = 'body' | 'headers' | 'path' | 'query';
56
+ type Field = {
57
+ in: Exclude<Slot, 'body'>;
58
+ /**
59
+ * Field name. This is the name we want the user to see and use.
60
+ */
61
+ key: string;
62
+ /**
63
+ * Field mapped name. This is the name we want to use in the request.
64
+ * If omitted, we use the same value as `key`.
65
+ */
66
+ map?: string;
67
+ } | {
68
+ in: Extract<Slot, 'body'>;
69
+ /**
70
+ * Key isn't required for bodies.
71
+ */
72
+ key?: string;
73
+ map?: string;
74
+ } | {
75
+ /**
76
+ * Field name. This is the name we want the user to see and use.
77
+ */
78
+ key: string;
79
+ /**
80
+ * Field mapped name. This is the name we want to use in the request.
81
+ * If `in` is omitted, `map` aliases `key` to the transport layer.
82
+ */
83
+ map: Slot;
84
+ };
85
+ interface Fields {
86
+ allowExtra?: Partial<Record<Slot, boolean>>;
87
+ args?: ReadonlyArray<Field>;
88
+ }
89
+ type FieldsConfig = ReadonlyArray<Field | Fields>;
90
+ interface Params {
91
+ body: unknown;
92
+ headers: Record<string, unknown>;
93
+ path: Record<string, unknown>;
94
+ query: Record<string, unknown>;
95
+ }
96
+ declare const buildClientParams: (args: ReadonlyArray<unknown>, fields: FieldsConfig) => Params;
97
+
98
+ /**
99
+ * JSON-friendly union that mirrors what Pinia Colada can hash.
100
+ */
101
+ type JsonValue = null | string | number | boolean | JsonValue[] | {
102
+ [key: string]: JsonValue;
103
+ };
104
+ /**
105
+ * Normalizes any accepted value into a JSON-friendly shape for query keys.
106
+ */
107
+ declare const serializeQueryKeyValue: (value: unknown) => JsonValue | undefined;
108
+
109
+ type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
110
+ type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
111
+ /**
112
+ * Returns the final request URL.
113
+ */
114
+ buildUrl: BuildUrlFn;
115
+ getConfig: () => Config;
116
+ request: RequestFn;
117
+ setConfig: (config: Config) => Config;
118
+ } & {
119
+ [K in HttpMethod]: MethodFn;
120
+ } & ([SseFn] extends [never] ? {
121
+ sse?: never;
122
+ } : {
123
+ sse: {
124
+ [K in HttpMethod]: SseFn;
125
+ };
126
+ });
127
+ interface Config$1 {
128
+ /**
129
+ * Auth token or a function returning auth token. The resolved value will be
130
+ * added to the request payload as defined by its `security` array.
131
+ */
132
+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
133
+ /**
134
+ * A function for serializing request body parameter. By default,
135
+ * {@link JSON.stringify()} will be used.
136
+ */
137
+ bodySerializer?: BodySerializer | null;
138
+ /**
139
+ * An object containing any HTTP headers that you want to pre-populate your
140
+ * `Headers` object with.
141
+ *
142
+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
143
+ */
144
+ headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
145
+ /**
146
+ * The request method.
147
+ *
148
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
149
+ */
150
+ method?: Uppercase<HttpMethod>;
151
+ /**
152
+ * A function for serializing request query parameters. By default, arrays
153
+ * will be exploded in form style, objects will be exploded in deepObject
154
+ * style, and reserved characters are percent-encoded.
155
+ *
156
+ * This method will have no effect if the native `paramsSerializer()` Axios
157
+ * API function is used.
158
+ *
159
+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
160
+ */
161
+ querySerializer?: QuerySerializer | QuerySerializerOptions;
162
+ /**
163
+ * A function validating request data. This is useful if you want to ensure
164
+ * the request conforms to the desired shape, so it can be safely sent to
165
+ * the server.
166
+ */
167
+ requestValidator?: (data: unknown) => Promise<unknown>;
168
+ /**
169
+ * A function transforming response data before it's returned. This is useful
170
+ * for post-processing data, e.g. converting ISO strings into Date objects.
171
+ */
172
+ responseTransformer?: (data: unknown) => Promise<unknown>;
173
+ /**
174
+ * A function validating response data. This is useful if you want to ensure
175
+ * the response conforms to the desired shape, so it can be safely passed to
176
+ * the transformers and returned to the user.
177
+ */
178
+ responseValidator?: (data: unknown) => Promise<unknown>;
179
+ }
180
+
181
+ type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
182
+ /**
183
+ * Fetch API implementation. You can use this option to provide a custom
184
+ * fetch instance.
185
+ *
186
+ * @default globalThis.fetch
187
+ */
188
+ fetch?: typeof fetch;
189
+ /**
190
+ * Implementing clients can call request interceptors inside this hook.
191
+ */
192
+ onRequest?: (url: string, init: RequestInit) => Promise<Request>;
193
+ /**
194
+ * Callback invoked when a network or parsing error occurs during streaming.
195
+ *
196
+ * This option applies only if the endpoint returns a stream of events.
197
+ *
198
+ * @param error The error that occurred.
199
+ */
200
+ onSseError?: (error: unknown) => void;
201
+ /**
202
+ * Callback invoked when an event is streamed from the server.
203
+ *
204
+ * This option applies only if the endpoint returns a stream of events.
205
+ *
206
+ * @param event Event streamed from the server.
207
+ * @returns Nothing (void).
208
+ */
209
+ onSseEvent?: (event: StreamEvent<TData>) => void;
210
+ serializedBody?: RequestInit['body'];
211
+ /**
212
+ * Default retry delay in milliseconds.
213
+ *
214
+ * This option applies only if the endpoint returns a stream of events.
215
+ *
216
+ * @default 3000
217
+ */
218
+ sseDefaultRetryDelay?: number;
219
+ /**
220
+ * Maximum number of retry attempts before giving up.
221
+ */
222
+ sseMaxRetryAttempts?: number;
223
+ /**
224
+ * Maximum retry delay in milliseconds.
225
+ *
226
+ * Applies only when exponential backoff is used.
227
+ *
228
+ * This option applies only if the endpoint returns a stream of events.
229
+ *
230
+ * @default 30000
231
+ */
232
+ sseMaxRetryDelay?: number;
233
+ /**
234
+ * Optional sleep function for retry backoff.
235
+ *
236
+ * Defaults to using `setTimeout`.
237
+ */
238
+ sseSleepFn?: (ms: number) => Promise<void>;
239
+ url: string;
240
+ };
241
+ interface StreamEvent<TData = unknown> {
242
+ data: TData;
243
+ event?: string;
244
+ id?: string;
245
+ retry?: number;
246
+ }
247
+ type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
248
+ stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
249
+ };
250
+
251
+ interface Config<T extends ClientOptions = ClientOptions> extends Omit<CreateAxiosDefaults, 'auth' | 'baseURL' | 'headers' | 'method'>, Config$1 {
252
+ /**
253
+ * Axios implementation. You can use this option to provide either an
254
+ * `AxiosStatic` or an `AxiosInstance`.
255
+ *
256
+ * @default axios
257
+ */
258
+ axios?: AxiosStatic | AxiosInstance;
259
+ /**
260
+ * Base URL for all requests made by this client.
261
+ */
262
+ baseURL?: T['baseURL'];
263
+ /**
264
+ * An object containing any HTTP headers that you want to pre-populate your
265
+ * `Headers` object with.
266
+ *
267
+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
268
+ */
269
+ headers?: AxiosRequestHeaders | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
270
+ /**
271
+ * Throw an error instead of returning it in the response?
272
+ *
273
+ * @default false
274
+ */
275
+ throwOnError?: T['throwOnError'];
276
+ }
277
+ interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
278
+ throwOnError: ThrowOnError;
279
+ }>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
280
+ /**
281
+ * Any body that you want to add to your request.
282
+ *
283
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
284
+ */
285
+ body?: unknown;
286
+ path?: Record<string, unknown>;
287
+ query?: Record<string, unknown>;
288
+ /**
289
+ * Security mechanism(s) to use for the request.
290
+ */
291
+ security?: ReadonlyArray<Auth>;
292
+ url: Url;
293
+ }
294
+ interface ClientOptions {
295
+ baseURL?: string;
296
+ throwOnError?: boolean;
297
+ }
298
+ type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<AxiosResponse<TData extends Record<string, unknown> ? TData[keyof TData] : TData>> : Promise<(AxiosResponse<TData extends Record<string, unknown> ? TData[keyof TData] : TData> & {
299
+ error: undefined;
300
+ }) | (AxiosError<TError extends Record<string, unknown> ? TError[keyof TError] : TError> & {
301
+ data: undefined;
302
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
303
+ })>;
304
+ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
305
+ type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
306
+ type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
307
+ type BuildUrlFn = <TData extends {
308
+ body?: unknown;
309
+ path?: Record<string, unknown>;
310
+ query?: Record<string, unknown>;
311
+ url: string;
312
+ }>(options: TData & Options<TData>) => string;
313
+ type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
314
+ instance: AxiosInstance;
315
+ };
316
+ /**
317
+ * The `createClientConfig()` function will be called on client initialization
318
+ * and the returned object will become the client's initial configuration.
319
+ *
320
+ * You may want to initialize your client this way instead of calling
321
+ * `setConfig()`. This is useful for example if you're using Next.js
322
+ * to ensure your client always has the correct values.
323
+ */
324
+ type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
325
+ interface TDataShape {
326
+ body?: unknown;
327
+ headers?: unknown;
328
+ path?: unknown;
329
+ query?: unknown;
330
+ url: string;
331
+ }
332
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
333
+ type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
334
+
335
+ declare const createClient: (config?: Config) => Client;
336
+
337
+ declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
338
+
339
+ export { type Auth, type Client, type ClientOptions, type Config, type CreateClientConfig, type Options, type QuerySerializerOptions, type RequestOptions, type RequestResult, type TDataShape, buildClientParams, createClient, createConfig, formDataBodySerializer, jsonBodySerializer, serializeQueryKeyValue, urlSearchParamsBodySerializer };
@@ -0,0 +1,339 @@
1
+ import { CreateAxiosDefaults, AxiosStatic, AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosError } from 'axios';
2
+
3
+ type AuthToken = string | undefined;
4
+ interface Auth {
5
+ /**
6
+ * Which part of the request do we use to send the auth?
7
+ *
8
+ * @default 'header'
9
+ */
10
+ in?: 'header' | 'query' | 'cookie';
11
+ /**
12
+ * Header or query parameter name.
13
+ *
14
+ * @default 'Authorization'
15
+ */
16
+ name?: string;
17
+ scheme?: 'basic' | 'bearer';
18
+ type: 'apiKey' | 'http';
19
+ }
20
+
21
+ interface SerializerOptions<T> {
22
+ /**
23
+ * @default true
24
+ */
25
+ explode: boolean;
26
+ style: T;
27
+ }
28
+ type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
29
+ type ObjectStyle = 'form' | 'deepObject';
30
+
31
+ type QuerySerializer = (query: Record<string, unknown>) => string;
32
+ type BodySerializer = (body: any) => any;
33
+ type QuerySerializerOptionsObject = {
34
+ allowReserved?: boolean;
35
+ array?: Partial<SerializerOptions<ArrayStyle>>;
36
+ object?: Partial<SerializerOptions<ObjectStyle>>;
37
+ };
38
+ type QuerySerializerOptions = QuerySerializerOptionsObject & {
39
+ /**
40
+ * Per-parameter serialization overrides. When provided, these settings
41
+ * override the global array/object settings for specific parameter names.
42
+ */
43
+ parameters?: Record<string, QuerySerializerOptionsObject>;
44
+ };
45
+ declare const formDataBodySerializer: {
46
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
47
+ };
48
+ declare const jsonBodySerializer: {
49
+ bodySerializer: <T>(body: T) => string;
50
+ };
51
+ declare const urlSearchParamsBodySerializer: {
52
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
53
+ };
54
+
55
+ type Slot = 'body' | 'headers' | 'path' | 'query';
56
+ type Field = {
57
+ in: Exclude<Slot, 'body'>;
58
+ /**
59
+ * Field name. This is the name we want the user to see and use.
60
+ */
61
+ key: string;
62
+ /**
63
+ * Field mapped name. This is the name we want to use in the request.
64
+ * If omitted, we use the same value as `key`.
65
+ */
66
+ map?: string;
67
+ } | {
68
+ in: Extract<Slot, 'body'>;
69
+ /**
70
+ * Key isn't required for bodies.
71
+ */
72
+ key?: string;
73
+ map?: string;
74
+ } | {
75
+ /**
76
+ * Field name. This is the name we want the user to see and use.
77
+ */
78
+ key: string;
79
+ /**
80
+ * Field mapped name. This is the name we want to use in the request.
81
+ * If `in` is omitted, `map` aliases `key` to the transport layer.
82
+ */
83
+ map: Slot;
84
+ };
85
+ interface Fields {
86
+ allowExtra?: Partial<Record<Slot, boolean>>;
87
+ args?: ReadonlyArray<Field>;
88
+ }
89
+ type FieldsConfig = ReadonlyArray<Field | Fields>;
90
+ interface Params {
91
+ body: unknown;
92
+ headers: Record<string, unknown>;
93
+ path: Record<string, unknown>;
94
+ query: Record<string, unknown>;
95
+ }
96
+ declare const buildClientParams: (args: ReadonlyArray<unknown>, fields: FieldsConfig) => Params;
97
+
98
+ /**
99
+ * JSON-friendly union that mirrors what Pinia Colada can hash.
100
+ */
101
+ type JsonValue = null | string | number | boolean | JsonValue[] | {
102
+ [key: string]: JsonValue;
103
+ };
104
+ /**
105
+ * Normalizes any accepted value into a JSON-friendly shape for query keys.
106
+ */
107
+ declare const serializeQueryKeyValue: (value: unknown) => JsonValue | undefined;
108
+
109
+ type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
110
+ type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
111
+ /**
112
+ * Returns the final request URL.
113
+ */
114
+ buildUrl: BuildUrlFn;
115
+ getConfig: () => Config;
116
+ request: RequestFn;
117
+ setConfig: (config: Config) => Config;
118
+ } & {
119
+ [K in HttpMethod]: MethodFn;
120
+ } & ([SseFn] extends [never] ? {
121
+ sse?: never;
122
+ } : {
123
+ sse: {
124
+ [K in HttpMethod]: SseFn;
125
+ };
126
+ });
127
+ interface Config$1 {
128
+ /**
129
+ * Auth token or a function returning auth token. The resolved value will be
130
+ * added to the request payload as defined by its `security` array.
131
+ */
132
+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
133
+ /**
134
+ * A function for serializing request body parameter. By default,
135
+ * {@link JSON.stringify()} will be used.
136
+ */
137
+ bodySerializer?: BodySerializer | null;
138
+ /**
139
+ * An object containing any HTTP headers that you want to pre-populate your
140
+ * `Headers` object with.
141
+ *
142
+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
143
+ */
144
+ headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
145
+ /**
146
+ * The request method.
147
+ *
148
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
149
+ */
150
+ method?: Uppercase<HttpMethod>;
151
+ /**
152
+ * A function for serializing request query parameters. By default, arrays
153
+ * will be exploded in form style, objects will be exploded in deepObject
154
+ * style, and reserved characters are percent-encoded.
155
+ *
156
+ * This method will have no effect if the native `paramsSerializer()` Axios
157
+ * API function is used.
158
+ *
159
+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
160
+ */
161
+ querySerializer?: QuerySerializer | QuerySerializerOptions;
162
+ /**
163
+ * A function validating request data. This is useful if you want to ensure
164
+ * the request conforms to the desired shape, so it can be safely sent to
165
+ * the server.
166
+ */
167
+ requestValidator?: (data: unknown) => Promise<unknown>;
168
+ /**
169
+ * A function transforming response data before it's returned. This is useful
170
+ * for post-processing data, e.g. converting ISO strings into Date objects.
171
+ */
172
+ responseTransformer?: (data: unknown) => Promise<unknown>;
173
+ /**
174
+ * A function validating response data. This is useful if you want to ensure
175
+ * the response conforms to the desired shape, so it can be safely passed to
176
+ * the transformers and returned to the user.
177
+ */
178
+ responseValidator?: (data: unknown) => Promise<unknown>;
179
+ }
180
+
181
+ type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
182
+ /**
183
+ * Fetch API implementation. You can use this option to provide a custom
184
+ * fetch instance.
185
+ *
186
+ * @default globalThis.fetch
187
+ */
188
+ fetch?: typeof fetch;
189
+ /**
190
+ * Implementing clients can call request interceptors inside this hook.
191
+ */
192
+ onRequest?: (url: string, init: RequestInit) => Promise<Request>;
193
+ /**
194
+ * Callback invoked when a network or parsing error occurs during streaming.
195
+ *
196
+ * This option applies only if the endpoint returns a stream of events.
197
+ *
198
+ * @param error The error that occurred.
199
+ */
200
+ onSseError?: (error: unknown) => void;
201
+ /**
202
+ * Callback invoked when an event is streamed from the server.
203
+ *
204
+ * This option applies only if the endpoint returns a stream of events.
205
+ *
206
+ * @param event Event streamed from the server.
207
+ * @returns Nothing (void).
208
+ */
209
+ onSseEvent?: (event: StreamEvent<TData>) => void;
210
+ serializedBody?: RequestInit['body'];
211
+ /**
212
+ * Default retry delay in milliseconds.
213
+ *
214
+ * This option applies only if the endpoint returns a stream of events.
215
+ *
216
+ * @default 3000
217
+ */
218
+ sseDefaultRetryDelay?: number;
219
+ /**
220
+ * Maximum number of retry attempts before giving up.
221
+ */
222
+ sseMaxRetryAttempts?: number;
223
+ /**
224
+ * Maximum retry delay in milliseconds.
225
+ *
226
+ * Applies only when exponential backoff is used.
227
+ *
228
+ * This option applies only if the endpoint returns a stream of events.
229
+ *
230
+ * @default 30000
231
+ */
232
+ sseMaxRetryDelay?: number;
233
+ /**
234
+ * Optional sleep function for retry backoff.
235
+ *
236
+ * Defaults to using `setTimeout`.
237
+ */
238
+ sseSleepFn?: (ms: number) => Promise<void>;
239
+ url: string;
240
+ };
241
+ interface StreamEvent<TData = unknown> {
242
+ data: TData;
243
+ event?: string;
244
+ id?: string;
245
+ retry?: number;
246
+ }
247
+ type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
248
+ stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
249
+ };
250
+
251
+ interface Config<T extends ClientOptions = ClientOptions> extends Omit<CreateAxiosDefaults, 'auth' | 'baseURL' | 'headers' | 'method'>, Config$1 {
252
+ /**
253
+ * Axios implementation. You can use this option to provide either an
254
+ * `AxiosStatic` or an `AxiosInstance`.
255
+ *
256
+ * @default axios
257
+ */
258
+ axios?: AxiosStatic | AxiosInstance;
259
+ /**
260
+ * Base URL for all requests made by this client.
261
+ */
262
+ baseURL?: T['baseURL'];
263
+ /**
264
+ * An object containing any HTTP headers that you want to pre-populate your
265
+ * `Headers` object with.
266
+ *
267
+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
268
+ */
269
+ headers?: AxiosRequestHeaders | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
270
+ /**
271
+ * Throw an error instead of returning it in the response?
272
+ *
273
+ * @default false
274
+ */
275
+ throwOnError?: T['throwOnError'];
276
+ }
277
+ interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
278
+ throwOnError: ThrowOnError;
279
+ }>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
280
+ /**
281
+ * Any body that you want to add to your request.
282
+ *
283
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
284
+ */
285
+ body?: unknown;
286
+ path?: Record<string, unknown>;
287
+ query?: Record<string, unknown>;
288
+ /**
289
+ * Security mechanism(s) to use for the request.
290
+ */
291
+ security?: ReadonlyArray<Auth>;
292
+ url: Url;
293
+ }
294
+ interface ClientOptions {
295
+ baseURL?: string;
296
+ throwOnError?: boolean;
297
+ }
298
+ type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<AxiosResponse<TData extends Record<string, unknown> ? TData[keyof TData] : TData>> : Promise<(AxiosResponse<TData extends Record<string, unknown> ? TData[keyof TData] : TData> & {
299
+ error: undefined;
300
+ }) | (AxiosError<TError extends Record<string, unknown> ? TError[keyof TError] : TError> & {
301
+ data: undefined;
302
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
303
+ })>;
304
+ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
305
+ type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
306
+ type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
307
+ type BuildUrlFn = <TData extends {
308
+ body?: unknown;
309
+ path?: Record<string, unknown>;
310
+ query?: Record<string, unknown>;
311
+ url: string;
312
+ }>(options: TData & Options<TData>) => string;
313
+ type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
314
+ instance: AxiosInstance;
315
+ };
316
+ /**
317
+ * The `createClientConfig()` function will be called on client initialization
318
+ * and the returned object will become the client's initial configuration.
319
+ *
320
+ * You may want to initialize your client this way instead of calling
321
+ * `setConfig()`. This is useful for example if you're using Next.js
322
+ * to ensure your client always has the correct values.
323
+ */
324
+ type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
325
+ interface TDataShape {
326
+ body?: unknown;
327
+ headers?: unknown;
328
+ path?: unknown;
329
+ query?: unknown;
330
+ url: string;
331
+ }
332
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
333
+ type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
334
+
335
+ declare const createClient: (config?: Config) => Client;
336
+
337
+ declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
338
+
339
+ export { type Auth, type Client, type ClientOptions, type Config, type CreateClientConfig, type Options, type QuerySerializerOptions, type RequestOptions, type RequestResult, type TDataShape, buildClientParams, createClient, createConfig, formDataBodySerializer, jsonBodySerializer, serializeQueryKeyValue, urlSearchParamsBodySerializer };