@silvana-one/api 1.0.22 → 1.0.24

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.
Files changed (77) hide show
  1. package/dist/node/client/client/client.d.ts +2 -0
  2. package/dist/node/client/client/client.js +146 -0
  3. package/dist/node/client/client/client.js.map +1 -0
  4. package/dist/node/client/client/index.d.ts +7 -0
  5. package/dist/node/client/client/index.js +5 -0
  6. package/dist/node/client/client/index.js.map +1 -0
  7. package/dist/node/client/client/types.d.ts +119 -0
  8. package/dist/node/client/client/types.js +2 -0
  9. package/dist/node/client/client/types.js.map +1 -0
  10. package/dist/node/client/client/utils.d.ts +45 -0
  11. package/dist/node/client/client/utils.js +284 -0
  12. package/dist/node/client/client/utils.js.map +1 -0
  13. package/dist/node/client/client.gen.d.ts +2 -2
  14. package/dist/node/client/client.gen.js +1 -1
  15. package/dist/node/client/client.gen.js.map +1 -1
  16. package/dist/node/client/core/auth.d.ts +18 -0
  17. package/dist/node/client/core/auth.js +14 -0
  18. package/dist/node/client/core/auth.js.map +1 -0
  19. package/dist/node/client/core/bodySerializer.d.ts +17 -0
  20. package/dist/node/client/core/bodySerializer.js +54 -0
  21. package/dist/node/client/core/bodySerializer.js.map +1 -0
  22. package/dist/node/client/core/params.d.ts +23 -0
  23. package/dist/node/client/core/params.js +88 -0
  24. package/dist/node/client/core/params.js.map +1 -0
  25. package/dist/node/client/core/pathSerializer.d.ts +33 -0
  26. package/dist/node/client/core/pathSerializer.js +114 -0
  27. package/dist/node/client/core/pathSerializer.js.map +1 -0
  28. package/dist/node/client/core/types.d.ts +73 -0
  29. package/dist/node/client/core/types.js +2 -0
  30. package/dist/node/client/core/types.js.map +1 -0
  31. package/dist/node/client/sdk.gen.d.ts +38 -38
  32. package/dist/node/index.cjs +530 -2
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/dist/tsconfig.web.tsbuildinfo +1 -1
  35. package/dist/web/client/client/client.d.ts +2 -0
  36. package/dist/web/client/client/client.js +146 -0
  37. package/dist/web/client/client/client.js.map +1 -0
  38. package/dist/web/client/client/index.d.ts +7 -0
  39. package/dist/web/client/client/index.js +5 -0
  40. package/dist/web/client/client/index.js.map +1 -0
  41. package/dist/web/client/client/types.d.ts +119 -0
  42. package/dist/web/client/client/types.js +2 -0
  43. package/dist/web/client/client/types.js.map +1 -0
  44. package/dist/web/client/client/utils.d.ts +45 -0
  45. package/dist/web/client/client/utils.js +284 -0
  46. package/dist/web/client/client/utils.js.map +1 -0
  47. package/dist/web/client/client.gen.d.ts +2 -2
  48. package/dist/web/client/client.gen.js +1 -1
  49. package/dist/web/client/client.gen.js.map +1 -1
  50. package/dist/web/client/core/auth.d.ts +18 -0
  51. package/dist/web/client/core/auth.js +14 -0
  52. package/dist/web/client/core/auth.js.map +1 -0
  53. package/dist/web/client/core/bodySerializer.d.ts +17 -0
  54. package/dist/web/client/core/bodySerializer.js +54 -0
  55. package/dist/web/client/core/bodySerializer.js.map +1 -0
  56. package/dist/web/client/core/params.d.ts +23 -0
  57. package/dist/web/client/core/params.js +88 -0
  58. package/dist/web/client/core/params.js.map +1 -0
  59. package/dist/web/client/core/pathSerializer.d.ts +33 -0
  60. package/dist/web/client/core/pathSerializer.js +114 -0
  61. package/dist/web/client/core/pathSerializer.js.map +1 -0
  62. package/dist/web/client/core/types.d.ts +73 -0
  63. package/dist/web/client/core/types.js +2 -0
  64. package/dist/web/client/core/types.js.map +1 -0
  65. package/dist/web/client/sdk.gen.d.ts +38 -38
  66. package/package.json +4 -7
  67. package/src/client/client/client.ts +195 -0
  68. package/src/client/client/index.ts +22 -0
  69. package/src/client/client/types.ts +222 -0
  70. package/src/client/client/utils.ts +417 -0
  71. package/src/client/client.gen.ts +1 -1
  72. package/src/client/core/auth.ts +40 -0
  73. package/src/client/core/bodySerializer.ts +88 -0
  74. package/src/client/core/params.ts +141 -0
  75. package/src/client/core/pathSerializer.ts +179 -0
  76. package/src/client/core/types.ts +104 -0
  77. package/src/client/sdk.gen.ts +1 -1
@@ -0,0 +1,222 @@
1
+ import type { Auth } from '../core/auth.js';
2
+ import type {
3
+ Client as CoreClient,
4
+ Config as CoreConfig,
5
+ } from '../core/types.js';
6
+ import type { Middleware } from './utils.js';
7
+
8
+ export type ResponseStyle = 'data' | 'fields';
9
+
10
+ export interface Config<T extends ClientOptions = ClientOptions>
11
+ extends Omit<RequestInit, 'body' | 'headers' | 'method'>,
12
+ CoreConfig {
13
+ /**
14
+ * Base URL for all requests made by this client.
15
+ */
16
+ baseUrl?: T['baseUrl'];
17
+ /**
18
+ * Fetch API implementation. You can use this option to provide a custom
19
+ * fetch instance.
20
+ *
21
+ * @default globalThis.fetch
22
+ */
23
+ fetch?: (request: Request) => ReturnType<typeof fetch>;
24
+ /**
25
+ * Please don't use the Fetch client for Next.js applications. The `next`
26
+ * options won't have any effect.
27
+ *
28
+ * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
29
+ */
30
+ next?: never;
31
+ /**
32
+ * Return the response data parsed in a specified format. By default, `auto`
33
+ * will infer the appropriate method from the `Content-Type` response header.
34
+ * You can override this behavior with any of the {@link Body} methods.
35
+ * Select `stream` if you don't want to parse response data at all.
36
+ *
37
+ * @default 'auto'
38
+ */
39
+ parseAs?:
40
+ | 'arrayBuffer'
41
+ | 'auto'
42
+ | 'blob'
43
+ | 'formData'
44
+ | 'json'
45
+ | 'stream'
46
+ | 'text';
47
+ /**
48
+ * Should we return only data or multiple fields (data, error, response, etc.)?
49
+ *
50
+ * @default 'fields'
51
+ */
52
+ responseStyle?: ResponseStyle;
53
+ /**
54
+ * Throw an error instead of returning it in the response?
55
+ *
56
+ * @default false
57
+ */
58
+ throwOnError?: T['throwOnError'];
59
+ }
60
+
61
+ export interface RequestOptions<
62
+ TResponseStyle extends ResponseStyle = 'fields',
63
+ ThrowOnError extends boolean = boolean,
64
+ Url extends string = string,
65
+ > extends Config<{
66
+ responseStyle: TResponseStyle;
67
+ throwOnError: ThrowOnError;
68
+ }> {
69
+ /**
70
+ * Any body that you want to add to your request.
71
+ *
72
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
73
+ */
74
+ body?: unknown;
75
+ path?: Record<string, unknown>;
76
+ query?: Record<string, unknown>;
77
+ /**
78
+ * Security mechanism(s) to use for the request.
79
+ */
80
+ security?: ReadonlyArray<Auth>;
81
+ url: Url;
82
+ }
83
+
84
+ export type RequestResult<
85
+ TData = unknown,
86
+ TError = unknown,
87
+ ThrowOnError extends boolean = boolean,
88
+ TResponseStyle extends ResponseStyle = 'fields',
89
+ > = ThrowOnError extends true
90
+ ? Promise<
91
+ TResponseStyle extends 'data'
92
+ ? TData extends Record<string, unknown>
93
+ ? TData[keyof TData]
94
+ : TData
95
+ : {
96
+ data: TData extends Record<string, unknown>
97
+ ? TData[keyof TData]
98
+ : TData;
99
+ request: Request;
100
+ response: Response;
101
+ }
102
+ >
103
+ : Promise<
104
+ TResponseStyle extends 'data'
105
+ ?
106
+ | (TData extends Record<string, unknown>
107
+ ? TData[keyof TData]
108
+ : TData)
109
+ | undefined
110
+ : (
111
+ | {
112
+ data: TData extends Record<string, unknown>
113
+ ? TData[keyof TData]
114
+ : TData;
115
+ error: undefined;
116
+ }
117
+ | {
118
+ data: undefined;
119
+ error: TError extends Record<string, unknown>
120
+ ? TError[keyof TError]
121
+ : TError;
122
+ }
123
+ ) & {
124
+ request: Request;
125
+ response: Response;
126
+ }
127
+ >;
128
+
129
+ export interface ClientOptions {
130
+ baseUrl?: string;
131
+ responseStyle?: ResponseStyle;
132
+ throwOnError?: boolean;
133
+ }
134
+
135
+ type MethodFn = <
136
+ TData = unknown,
137
+ TError = unknown,
138
+ ThrowOnError extends boolean = false,
139
+ TResponseStyle extends ResponseStyle = 'fields',
140
+ >(
141
+ options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'>,
142
+ ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
143
+
144
+ type RequestFn = <
145
+ TData = unknown,
146
+ TError = unknown,
147
+ ThrowOnError extends boolean = false,
148
+ TResponseStyle extends ResponseStyle = 'fields',
149
+ >(
150
+ options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'> &
151
+ Pick<Required<RequestOptions<TResponseStyle, ThrowOnError>>, 'method'>,
152
+ ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
153
+
154
+ type BuildUrlFn = <
155
+ TData extends {
156
+ body?: unknown;
157
+ path?: Record<string, unknown>;
158
+ query?: Record<string, unknown>;
159
+ url: string;
160
+ },
161
+ >(
162
+ options: Pick<TData, 'url'> & Options<TData>,
163
+ ) => string;
164
+
165
+ export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
166
+ interceptors: Middleware<Request, Response, unknown, RequestOptions>;
167
+ };
168
+
169
+ /**
170
+ * The `createClientConfig()` function will be called on client initialization
171
+ * and the returned object will become the client's initial configuration.
172
+ *
173
+ * You may want to initialize your client this way instead of calling
174
+ * `setConfig()`. This is useful for example if you're using Next.js
175
+ * to ensure your client always has the correct values.
176
+ */
177
+ export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
178
+ override?: Config<ClientOptions & T>,
179
+ ) => Config<Required<ClientOptions> & T>;
180
+
181
+ export interface TDataShape {
182
+ body?: unknown;
183
+ headers?: unknown;
184
+ path?: unknown;
185
+ query?: unknown;
186
+ url: string;
187
+ }
188
+
189
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
190
+
191
+ export type Options<
192
+ TData extends TDataShape = TDataShape,
193
+ ThrowOnError extends boolean = boolean,
194
+ TResponseStyle extends ResponseStyle = 'fields',
195
+ > = OmitKeys<
196
+ RequestOptions<TResponseStyle, ThrowOnError>,
197
+ 'body' | 'path' | 'query' | 'url'
198
+ > &
199
+ Omit<TData, 'url'>;
200
+
201
+ export type OptionsLegacyParser<
202
+ TData = unknown,
203
+ ThrowOnError extends boolean = boolean,
204
+ TResponseStyle extends ResponseStyle = 'fields',
205
+ > = TData extends { body?: any }
206
+ ? TData extends { headers?: any }
207
+ ? OmitKeys<
208
+ RequestOptions<TResponseStyle, ThrowOnError>,
209
+ 'body' | 'headers' | 'url'
210
+ > &
211
+ TData
212
+ : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'url'> &
213
+ TData &
214
+ Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'headers'>
215
+ : TData extends { headers?: any }
216
+ ? OmitKeys<
217
+ RequestOptions<TResponseStyle, ThrowOnError>,
218
+ 'headers' | 'url'
219
+ > &
220
+ TData &
221
+ Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'body'>
222
+ : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'url'> & TData;
@@ -0,0 +1,417 @@
1
+ import { getAuthToken } from '../core/auth.js';
2
+ import type {
3
+ QuerySerializer,
4
+ QuerySerializerOptions,
5
+ } from '../core/bodySerializer.js';
6
+ import { jsonBodySerializer } from '../core/bodySerializer.js';
7
+ import {
8
+ serializeArrayParam,
9
+ serializeObjectParam,
10
+ serializePrimitiveParam,
11
+ } from '../core/pathSerializer.js';
12
+ import type { Client, ClientOptions, Config, RequestOptions } from './types.js';
13
+
14
+ interface PathSerializer {
15
+ path: Record<string, unknown>;
16
+ url: string;
17
+ }
18
+
19
+ const PATH_PARAM_RE = /\{[^{}]+\}/g;
20
+
21
+ type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
22
+ type MatrixStyle = 'label' | 'matrix' | 'simple';
23
+ type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
24
+
25
+ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
26
+ let url = _url;
27
+ const matches = _url.match(PATH_PARAM_RE);
28
+ if (matches) {
29
+ for (const match of matches) {
30
+ let explode = false;
31
+ let name = match.substring(1, match.length - 1);
32
+ let style: ArraySeparatorStyle = 'simple';
33
+
34
+ if (name.endsWith('*')) {
35
+ explode = true;
36
+ name = name.substring(0, name.length - 1);
37
+ }
38
+
39
+ if (name.startsWith('.')) {
40
+ name = name.substring(1);
41
+ style = 'label';
42
+ } else if (name.startsWith(';')) {
43
+ name = name.substring(1);
44
+ style = 'matrix';
45
+ }
46
+
47
+ const value = path[name];
48
+
49
+ if (value === undefined || value === null) {
50
+ continue;
51
+ }
52
+
53
+ if (Array.isArray(value)) {
54
+ url = url.replace(
55
+ match,
56
+ serializeArrayParam({ explode, name, style, value }),
57
+ );
58
+ continue;
59
+ }
60
+
61
+ if (typeof value === 'object') {
62
+ url = url.replace(
63
+ match,
64
+ serializeObjectParam({
65
+ explode,
66
+ name,
67
+ style,
68
+ value: value as Record<string, unknown>,
69
+ valueOnly: true,
70
+ }),
71
+ );
72
+ continue;
73
+ }
74
+
75
+ if (style === 'matrix') {
76
+ url = url.replace(
77
+ match,
78
+ `;${serializePrimitiveParam({
79
+ name,
80
+ value: value as string,
81
+ })}`,
82
+ );
83
+ continue;
84
+ }
85
+
86
+ const replaceValue = encodeURIComponent(
87
+ style === 'label' ? `.${value as string}` : (value as string),
88
+ );
89
+ url = url.replace(match, replaceValue);
90
+ }
91
+ }
92
+ return url;
93
+ };
94
+
95
+ export const createQuerySerializer = <T = unknown>({
96
+ allowReserved,
97
+ array,
98
+ object,
99
+ }: QuerySerializerOptions = {}) => {
100
+ const querySerializer = (queryParams: T) => {
101
+ const search: string[] = [];
102
+ if (queryParams && typeof queryParams === 'object') {
103
+ for (const name in queryParams) {
104
+ const value = queryParams[name];
105
+
106
+ if (value === undefined || value === null) {
107
+ continue;
108
+ }
109
+
110
+ if (Array.isArray(value)) {
111
+ const serializedArray = serializeArrayParam({
112
+ allowReserved,
113
+ explode: true,
114
+ name,
115
+ style: 'form',
116
+ value,
117
+ ...array,
118
+ });
119
+ if (serializedArray) search.push(serializedArray);
120
+ } else if (typeof value === 'object') {
121
+ const serializedObject = serializeObjectParam({
122
+ allowReserved,
123
+ explode: true,
124
+ name,
125
+ style: 'deepObject',
126
+ value: value as Record<string, unknown>,
127
+ ...object,
128
+ });
129
+ if (serializedObject) search.push(serializedObject);
130
+ } else {
131
+ const serializedPrimitive = serializePrimitiveParam({
132
+ allowReserved,
133
+ name,
134
+ value: value as string,
135
+ });
136
+ if (serializedPrimitive) search.push(serializedPrimitive);
137
+ }
138
+ }
139
+ }
140
+ return search.join('&');
141
+ };
142
+ return querySerializer;
143
+ };
144
+
145
+ /**
146
+ * Infers parseAs value from provided Content-Type header.
147
+ */
148
+ export const getParseAs = (
149
+ contentType: string | null,
150
+ ): Exclude<Config['parseAs'], 'auto'> => {
151
+ if (!contentType) {
152
+ // If no Content-Type header is provided, the best we can do is return the raw response body,
153
+ // which is effectively the same as the 'stream' option.
154
+ return 'stream';
155
+ }
156
+
157
+ const cleanContent = contentType.split(';')[0]?.trim();
158
+
159
+ if (!cleanContent) {
160
+ return;
161
+ }
162
+
163
+ if (
164
+ cleanContent.startsWith('application/json') ||
165
+ cleanContent.endsWith('+json')
166
+ ) {
167
+ return 'json';
168
+ }
169
+
170
+ if (cleanContent === 'multipart/form-data') {
171
+ return 'formData';
172
+ }
173
+
174
+ if (
175
+ ['application/', 'audio/', 'image/', 'video/'].some((type) =>
176
+ cleanContent.startsWith(type),
177
+ )
178
+ ) {
179
+ return 'blob';
180
+ }
181
+
182
+ if (cleanContent.startsWith('text/')) {
183
+ return 'text';
184
+ }
185
+
186
+ return;
187
+ };
188
+
189
+ export const setAuthParams = async ({
190
+ security,
191
+ ...options
192
+ }: Pick<Required<RequestOptions>, 'security'> &
193
+ Pick<RequestOptions, 'auth' | 'query'> & {
194
+ headers: Headers;
195
+ }) => {
196
+ for (const auth of security) {
197
+ const token = await getAuthToken(auth, options.auth);
198
+
199
+ if (!token) {
200
+ continue;
201
+ }
202
+
203
+ const name = auth.name ?? 'Authorization';
204
+
205
+ switch (auth.in) {
206
+ case 'query':
207
+ if (!options.query) {
208
+ options.query = {};
209
+ }
210
+ options.query[name] = token;
211
+ break;
212
+ case 'cookie':
213
+ options.headers.append('Cookie', `${name}=${token}`);
214
+ break;
215
+ case 'header':
216
+ default:
217
+ options.headers.set(name, token);
218
+ break;
219
+ }
220
+
221
+ return;
222
+ }
223
+ };
224
+
225
+ export const buildUrl: Client['buildUrl'] = (options) => {
226
+ const url = getUrl({
227
+ baseUrl: options.baseUrl as string,
228
+ path: options.path,
229
+ query: options.query,
230
+ querySerializer:
231
+ typeof options.querySerializer === 'function'
232
+ ? options.querySerializer
233
+ : createQuerySerializer(options.querySerializer),
234
+ url: options.url,
235
+ });
236
+ return url;
237
+ };
238
+
239
+ export const getUrl = ({
240
+ baseUrl,
241
+ path,
242
+ query,
243
+ querySerializer,
244
+ url: _url,
245
+ }: {
246
+ baseUrl?: string;
247
+ path?: Record<string, unknown>;
248
+ query?: Record<string, unknown>;
249
+ querySerializer: QuerySerializer;
250
+ url: string;
251
+ }) => {
252
+ const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
253
+ let url = (baseUrl ?? '') + pathUrl;
254
+ if (path) {
255
+ url = defaultPathSerializer({ path, url });
256
+ }
257
+ let search = query ? querySerializer(query) : '';
258
+ if (search.startsWith('?')) {
259
+ search = search.substring(1);
260
+ }
261
+ if (search) {
262
+ url += `?${search}`;
263
+ }
264
+ return url;
265
+ };
266
+
267
+ export const mergeConfigs = (a: Config, b: Config): Config => {
268
+ const config = { ...a, ...b };
269
+ if (config.baseUrl?.endsWith('/')) {
270
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
271
+ }
272
+ config.headers = mergeHeaders(a.headers, b.headers);
273
+ return config;
274
+ };
275
+
276
+ export const mergeHeaders = (
277
+ ...headers: Array<Required<Config>['headers'] | undefined>
278
+ ): Headers => {
279
+ const mergedHeaders = new Headers();
280
+ for (const header of headers) {
281
+ if (!header || typeof header !== 'object') {
282
+ continue;
283
+ }
284
+
285
+ const iterator =
286
+ header instanceof Headers ? header.entries() : Object.entries(header);
287
+
288
+ for (const [key, value] of iterator) {
289
+ if (value === null) {
290
+ mergedHeaders.delete(key);
291
+ } else if (Array.isArray(value)) {
292
+ for (const v of value) {
293
+ mergedHeaders.append(key, v as string);
294
+ }
295
+ } else if (value !== undefined) {
296
+ // assume object headers are meant to be JSON stringified, i.e. their
297
+ // content value in OpenAPI specification is 'application/json'
298
+ mergedHeaders.set(
299
+ key,
300
+ typeof value === 'object' ? JSON.stringify(value) : (value as string),
301
+ );
302
+ }
303
+ }
304
+ }
305
+ return mergedHeaders;
306
+ };
307
+
308
+ type ErrInterceptor<Err, Res, Req, Options> = (
309
+ error: Err,
310
+ response: Res,
311
+ request: Req,
312
+ options: Options,
313
+ ) => Err | Promise<Err>;
314
+
315
+ type ReqInterceptor<Req, Options> = (
316
+ request: Req,
317
+ options: Options,
318
+ ) => Req | Promise<Req>;
319
+
320
+ type ResInterceptor<Res, Req, Options> = (
321
+ response: Res,
322
+ request: Req,
323
+ options: Options,
324
+ ) => Res | Promise<Res>;
325
+
326
+ class Interceptors<Interceptor> {
327
+ _fns: (Interceptor | null)[];
328
+
329
+ constructor() {
330
+ this._fns = [];
331
+ }
332
+
333
+ clear() {
334
+ this._fns = [];
335
+ }
336
+
337
+ getInterceptorIndex(id: number | Interceptor): number {
338
+ if (typeof id === 'number') {
339
+ return this._fns[id] ? id : -1;
340
+ } else {
341
+ return this._fns.indexOf(id);
342
+ }
343
+ }
344
+ exists(id: number | Interceptor) {
345
+ const index = this.getInterceptorIndex(id);
346
+ return !!this._fns[index];
347
+ }
348
+
349
+ eject(id: number | Interceptor) {
350
+ const index = this.getInterceptorIndex(id);
351
+ if (this._fns[index]) {
352
+ this._fns[index] = null;
353
+ }
354
+ }
355
+
356
+ update(id: number | Interceptor, fn: Interceptor) {
357
+ const index = this.getInterceptorIndex(id);
358
+ if (this._fns[index]) {
359
+ this._fns[index] = fn;
360
+ return id;
361
+ } else {
362
+ return false;
363
+ }
364
+ }
365
+
366
+ use(fn: Interceptor) {
367
+ this._fns = [...this._fns, fn];
368
+ return this._fns.length - 1;
369
+ }
370
+ }
371
+
372
+ // `createInterceptors()` response, meant for external use as it does not
373
+ // expose internals
374
+ export interface Middleware<Req, Res, Err, Options> {
375
+ error: Pick<
376
+ Interceptors<ErrInterceptor<Err, Res, Req, Options>>,
377
+ 'eject' | 'use'
378
+ >;
379
+ request: Pick<Interceptors<ReqInterceptor<Req, Options>>, 'eject' | 'use'>;
380
+ response: Pick<
381
+ Interceptors<ResInterceptor<Res, Req, Options>>,
382
+ 'eject' | 'use'
383
+ >;
384
+ }
385
+
386
+ // do not add `Middleware` as return type so we can use _fns internally
387
+ export const createInterceptors = <Req, Res, Err, Options>() => ({
388
+ error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
389
+ request: new Interceptors<ReqInterceptor<Req, Options>>(),
390
+ response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
391
+ });
392
+
393
+ const defaultQuerySerializer = createQuerySerializer({
394
+ allowReserved: false,
395
+ array: {
396
+ explode: true,
397
+ style: 'form',
398
+ },
399
+ object: {
400
+ explode: true,
401
+ style: 'deepObject',
402
+ },
403
+ });
404
+
405
+ const defaultHeaders = {
406
+ 'Content-Type': 'application/json',
407
+ };
408
+
409
+ export const createConfig = <T extends ClientOptions = ClientOptions>(
410
+ override: Config<Omit<ClientOptions, keyof T> & T> = {},
411
+ ): Config<Omit<ClientOptions, keyof T> & T> => ({
412
+ ...jsonBodySerializer,
413
+ headers: defaultHeaders,
414
+ parseAs: 'auto',
415
+ querySerializer: defaultQuerySerializer,
416
+ ...override,
417
+ });
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated by @hey-api/openapi-ts
2
2
 
3
3
  import type { ClientOptions } from './types.gen.js';
4
- import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
4
+ import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from './client/index.js';
5
5
 
6
6
  /**
7
7
  * The `createClientConfig()` function will be called on client initialization
@@ -0,0 +1,40 @@
1
+ export type AuthToken = string | undefined;
2
+
3
+ export interface Auth {
4
+ /**
5
+ * Which part of the request do we use to send the auth?
6
+ *
7
+ * @default 'header'
8
+ */
9
+ in?: 'header' | 'query' | 'cookie';
10
+ /**
11
+ * Header or query parameter name.
12
+ *
13
+ * @default 'Authorization'
14
+ */
15
+ name?: string;
16
+ scheme?: 'basic' | 'bearer';
17
+ type: 'apiKey' | 'http';
18
+ }
19
+
20
+ export const getAuthToken = async (
21
+ auth: Auth,
22
+ callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
23
+ ): Promise<string | undefined> => {
24
+ const token =
25
+ typeof callback === 'function' ? await callback(auth) : callback;
26
+
27
+ if (!token) {
28
+ return;
29
+ }
30
+
31
+ if (auth.scheme === 'bearer') {
32
+ return `Bearer ${token}`;
33
+ }
34
+
35
+ if (auth.scheme === 'basic') {
36
+ return `Basic ${btoa(token)}`;
37
+ }
38
+
39
+ return token;
40
+ };