@hey-api/openapi-ts 0.97.1 → 0.97.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -61
- package/dist/clients/angular/client.ts +1 -4
- package/dist/clients/angular/types.ts +3 -2
- package/dist/clients/angular/utils.ts +7 -8
- package/dist/clients/axios/client.ts +1 -4
- package/dist/clients/axios/types.ts +7 -2
- package/dist/clients/axios/utils.ts +6 -8
- package/dist/clients/core/params.ts +4 -4
- package/dist/clients/fetch/client.ts +1 -4
- package/dist/clients/fetch/types.ts +3 -2
- package/dist/clients/fetch/utils.ts +6 -8
- package/dist/clients/ky/client.ts +1 -4
- package/dist/clients/ky/types.ts +3 -2
- package/dist/clients/ky/utils.ts +6 -8
- package/dist/clients/next/client.ts +1 -4
- package/dist/clients/next/types.ts +7 -2
- package/dist/clients/next/utils.ts +6 -8
- package/dist/clients/nuxt/client.ts +7 -6
- package/dist/clients/nuxt/utils.ts +6 -8
- package/dist/clients/ofetch/client.ts +1 -4
- package/dist/clients/ofetch/types.ts +3 -2
- package/dist/clients/ofetch/utils.ts +6 -8
- package/dist/index.d.mts +988 -671
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{init-Bi6_Uyy_.mjs → init-D3VuY80Z.mjs} +1435 -978
- package/dist/init-D3VuY80Z.mjs.map +1 -0
- package/dist/internal.mjs +1 -1
- package/dist/run.mjs +2 -2
- package/dist/{src-CSz9FXkH.mjs → src-BeNy9O9X.mjs} +2 -2
- package/dist/{src-CSz9FXkH.mjs.map → src-BeNy9O9X.mjs.map} +1 -1
- package/package.json +6 -6
- package/dist/init-Bi6_Uyy_.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -19,27 +19,27 @@
|
|
|
19
19
|
<span> • </span>
|
|
20
20
|
<a href="https://github.com/hey-api/openapi-ts/issues">Issues</a>
|
|
21
21
|
<span> • </span>
|
|
22
|
-
<a href="https://heyapi.dev/openapi
|
|
22
|
+
<a href="https://heyapi.dev/docs/openapi/typescript/community/contributing">Contribute</a>
|
|
23
23
|
</p>
|
|
24
24
|
|
|
25
25
|
## About
|
|
26
26
|
|
|
27
27
|
The OpenAPI to TypeScript code generator used by Vercel, OpenCode, and PayPal.
|
|
28
28
|
|
|
29
|
-
Generate production-
|
|
29
|
+
Generate production-grade SDKs, Zod schemas, TanStack Query hooks, or choose from 20+ other plugins.
|
|
30
30
|
|
|
31
31
|
Part of the Hey API ecosystem.
|
|
32
32
|
|
|
33
33
|
## Features
|
|
34
34
|
|
|
35
|
-
- production-
|
|
35
|
+
- production-grade code that compiles
|
|
36
36
|
- runs in any Node.js 22+ environment
|
|
37
37
|
- accepts any OpenAPI specification
|
|
38
38
|
- core plugins for SDKs, types, and schemas
|
|
39
39
|
- HTTP clients for Fetch API, Angular, Axios, Next.js, Nuxt, and more
|
|
40
40
|
- 20+ plugins to reduce third-party boilerplate
|
|
41
41
|
- highly customizable via plugins
|
|
42
|
-
- [sync with Hey API Registry](https://heyapi.dev/openapi
|
|
42
|
+
- [sync with Hey API Registry](https://heyapi.dev/docs/openapi/typescript/integrations) for spec management
|
|
43
43
|
|
|
44
44
|
<!-- template-contributing-start -->
|
|
45
45
|
|
|
@@ -47,7 +47,7 @@ Part of the Hey API ecosystem.
|
|
|
47
47
|
|
|
48
48
|
Want to see your code in products used by millions?
|
|
49
49
|
|
|
50
|
-
Start with our [Contributing](https://heyapi.dev/openapi
|
|
50
|
+
Start with our [Contributing](https://heyapi.dev/docs/openapi/typescript/community/contributing) guide and release your first feature.
|
|
51
51
|
|
|
52
52
|
<!-- template-contributing-end -->
|
|
53
53
|
|
|
@@ -156,6 +156,14 @@ Partners behind the future of API tooling. [Become a sponsor](https://github.com
|
|
|
156
156
|
</picture>
|
|
157
157
|
</a>
|
|
158
158
|
</td>
|
|
159
|
+
<td align="center" width="136px">
|
|
160
|
+
<a href="https://kutt.to/HW4GYR" target="_blank">
|
|
161
|
+
<picture height="34px">
|
|
162
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/photon/logo-light.svg">
|
|
163
|
+
<img alt="Photon logo" height="34px" src="https://heyapi.dev/assets/photon/logo-dark.svg">
|
|
164
|
+
</picture>
|
|
165
|
+
</a>
|
|
166
|
+
</td>
|
|
159
167
|
</tr>
|
|
160
168
|
</tbody>
|
|
161
169
|
</table>
|
|
@@ -169,7 +177,7 @@ The fastest way to use `@hey-api/openapi-ts` is via npx
|
|
|
169
177
|
npx @hey-api/openapi-ts -i hey-api/backend -o src/client
|
|
170
178
|
```
|
|
171
179
|
|
|
172
|
-
Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/openapi
|
|
180
|
+
Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/docs/openapi/typescript/output) page.
|
|
173
181
|
|
|
174
182
|
## Installation
|
|
175
183
|
|
|
@@ -178,7 +186,7 @@ You can download `@hey-api/openapi-ts` from npm using your favorite package mana
|
|
|
178
186
|
#### npm
|
|
179
187
|
|
|
180
188
|
```sh
|
|
181
|
-
npm
|
|
189
|
+
npm install @hey-api/openapi-ts -D -E
|
|
182
190
|
```
|
|
183
191
|
|
|
184
192
|
#### pnpm
|
|
@@ -196,14 +204,14 @@ yarn add @hey-api/openapi-ts -D -E
|
|
|
196
204
|
#### bun
|
|
197
205
|
|
|
198
206
|
```sh
|
|
199
|
-
bun add @hey-api/openapi-ts -D
|
|
207
|
+
bun add @hey-api/openapi-ts -D
|
|
200
208
|
```
|
|
201
209
|
|
|
202
210
|
### Versioning
|
|
203
211
|
|
|
204
212
|
This package is in [initial development](https://semver.org/#spec-item-4). Please pin an exact version so you can safely upgrade when you're ready.
|
|
205
213
|
|
|
206
|
-
We publish [migration notes](https://heyapi.dev/openapi
|
|
214
|
+
We publish [migration notes](https://heyapi.dev/docs/openapi/typescript/migrating) for every breaking release. You might not be impacted by a breaking change if you don't use the affected features.
|
|
207
215
|
|
|
208
216
|
## Usage
|
|
209
217
|
|
|
@@ -217,7 +225,7 @@ Most people run `@hey-api/openapi-ts` via CLI. To do that, add a script to your
|
|
|
217
225
|
}
|
|
218
226
|
```
|
|
219
227
|
|
|
220
|
-
The above script can be executed by running `npm run openapi-ts` or equivalent command in other package managers. Next, we will create a [configuration](https://heyapi.dev/openapi
|
|
228
|
+
The above script can be executed by running `npm run openapi-ts` or equivalent command in other package managers. Next, we will create a [configuration](https://heyapi.dev/docs/openapi/typescript/configuration) file and move our options from Quick Start to it.
|
|
221
229
|
|
|
222
230
|
### Node.js
|
|
223
231
|
|
|
@@ -241,7 +249,7 @@ If you're using [Vite](https://vite.dev), you can integrate `@hey-api/openapi-ts
|
|
|
241
249
|
#### npm
|
|
242
250
|
|
|
243
251
|
```sh
|
|
244
|
-
npm
|
|
252
|
+
npm install @hey-api/vite-plugin -D -E
|
|
245
253
|
```
|
|
246
254
|
|
|
247
255
|
#### pnpm
|
|
@@ -259,7 +267,7 @@ yarn add @hey-api/vite-plugin -D -E
|
|
|
259
267
|
#### bun
|
|
260
268
|
|
|
261
269
|
```sh
|
|
262
|
-
bun add @hey-api/vite-plugin -D
|
|
270
|
+
bun add @hey-api/vite-plugin -D
|
|
263
271
|
```
|
|
264
272
|
|
|
265
273
|
Then add the plugin to your Vite configuration:
|
|
@@ -282,7 +290,7 @@ export default defineConfig({
|
|
|
282
290
|
});
|
|
283
291
|
```
|
|
284
292
|
|
|
285
|
-
See the [Vite](https://heyapi.dev/openapi
|
|
293
|
+
See the [Vite](https://heyapi.dev/docs/openapi/typescript/configuration/vite) page for full configuration options.
|
|
286
294
|
|
|
287
295
|
## Configuration
|
|
288
296
|
|
|
@@ -347,73 +355,74 @@ Clients are responsible for sending the actual HTTP requests. We default to Fetc
|
|
|
347
355
|
|
|
348
356
|
### Available Clients
|
|
349
357
|
|
|
350
|
-
- [`@hey-api/client-fetch`](https://heyapi.dev/openapi
|
|
351
|
-
- [`@hey-api/client-angular`](https://heyapi.dev/openapi
|
|
352
|
-
- [`@hey-api/client-axios`](https://heyapi.dev/openapi
|
|
353
|
-
- [`@hey-api/client-ky`](https://heyapi.dev/openapi
|
|
354
|
-
- [`@hey-api/client-next`](https://heyapi.dev/openapi
|
|
355
|
-
- [`@hey-api/client-nuxt`](https://heyapi.dev/openapi
|
|
356
|
-
- [`@hey-api/client-ofetch`](https://heyapi.dev/openapi
|
|
358
|
+
- [`@hey-api/client-fetch`](https://heyapi.dev/docs/openapi/typescript/clients/fetch)
|
|
359
|
+
- [`@hey-api/client-angular`](https://heyapi.dev/docs/openapi/typescript/clients/angular)
|
|
360
|
+
- [`@hey-api/client-axios`](https://heyapi.dev/docs/openapi/typescript/clients/axios)
|
|
361
|
+
- [`@hey-api/client-ky`](https://heyapi.dev/docs/openapi/typescript/clients/ky)
|
|
362
|
+
- [`@hey-api/client-next`](https://heyapi.dev/docs/openapi/typescript/clients/next-js)
|
|
363
|
+
- [`@hey-api/client-nuxt`](https://heyapi.dev/docs/openapi/typescript/clients/nuxt)
|
|
364
|
+
- [`@hey-api/client-ofetch`](https://heyapi.dev/docs/openapi/typescript/clients/ofetch)
|
|
357
365
|
|
|
358
366
|
### Proposed Clients (Vote to Prioritize)
|
|
359
367
|
|
|
360
368
|
The following clients are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
|
|
361
369
|
|
|
362
|
-
- [`@hey-api/client-effect`](https://heyapi.dev/openapi
|
|
370
|
+
- [`@hey-api/client-effect`](https://heyapi.dev/docs/openapi/typescript/clients/effect)
|
|
363
371
|
|
|
364
|
-
Don't see your client? [Build your own](https://heyapi.dev/openapi
|
|
372
|
+
Don't see your client? [Build your own](https://heyapi.dev/docs/openapi/typescript/clients/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
|
|
365
373
|
|
|
366
374
|
### Available Plugins
|
|
367
375
|
|
|
368
376
|
These plugins help reduce boilerplate associated with third-party dependencies. Hey API natively supports the most popular packages. Please open an issue on [GitHub](https://github.com/hey-api/openapi-ts/issues) if you'd like us to support your favorite package.
|
|
369
377
|
|
|
370
|
-
- [`@angular/common`](https://heyapi.dev/openapi
|
|
371
|
-
- [`@hey-api/schemas`](https://heyapi.dev/openapi
|
|
372
|
-
- [`@hey-api/sdk`](https://heyapi.dev/openapi
|
|
373
|
-
- [`@hey-api/transformers`](https://heyapi.dev/openapi
|
|
374
|
-
- [`@hey-api/typescript`](https://heyapi.dev/openapi
|
|
375
|
-
- [`@pinia/colada`](https://heyapi.dev/openapi
|
|
376
|
-
- [`@tanstack/angular-query-experimental`](https://heyapi.dev/openapi
|
|
377
|
-
- [`@tanstack/preact-query`](https://heyapi.dev/openapi
|
|
378
|
-
- [`@tanstack/react-query`](https://heyapi.dev/openapi
|
|
379
|
-
- [`@tanstack/solid-query`](https://heyapi.dev/openapi
|
|
380
|
-
- [`@tanstack/svelte-query`](https://heyapi.dev/openapi
|
|
381
|
-
- [`@tanstack/vue-query`](https://heyapi.dev/openapi
|
|
382
|
-
- [`fastify`](https://heyapi.dev/openapi
|
|
383
|
-
- [`orpc`](https://heyapi.dev/openapi
|
|
384
|
-
- [`nestjs`](https://heyapi.dev/openapi
|
|
385
|
-
- [`valibot`](https://heyapi.dev/openapi
|
|
386
|
-
- [`zod`](https://heyapi.dev/openapi
|
|
378
|
+
- [`@angular/common`](https://heyapi.dev/docs/openapi/typescript/plugins/angular)
|
|
379
|
+
- [`@hey-api/schemas`](https://heyapi.dev/docs/openapi/typescript/plugins/schemas)
|
|
380
|
+
- [`@hey-api/sdk`](https://heyapi.dev/docs/openapi/typescript/plugins/sdk)
|
|
381
|
+
- [`@hey-api/transformers`](https://heyapi.dev/docs/openapi/typescript/plugins/transformers)
|
|
382
|
+
- [`@hey-api/typescript`](https://heyapi.dev/docs/openapi/typescript/plugins/typescript)
|
|
383
|
+
- [`@pinia/colada`](https://heyapi.dev/docs/openapi/typescript/plugins/pinia-colada)
|
|
384
|
+
- [`@tanstack/angular-query-experimental`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
385
|
+
- [`@tanstack/preact-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
386
|
+
- [`@tanstack/react-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
387
|
+
- [`@tanstack/solid-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
388
|
+
- [`@tanstack/svelte-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
389
|
+
- [`@tanstack/vue-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
390
|
+
- [`fastify`](https://heyapi.dev/docs/openapi/typescript/plugins/fastify)
|
|
391
|
+
- [`orpc`](https://heyapi.dev/docs/openapi/typescript/plugins/orpc)
|
|
392
|
+
- [`nestjs`](https://heyapi.dev/docs/openapi/typescript/plugins/nest)
|
|
393
|
+
- [`valibot`](https://heyapi.dev/docs/openapi/typescript/plugins/valibot)
|
|
394
|
+
- [`zod`](https://heyapi.dev/docs/openapi/typescript/plugins/zod)
|
|
387
395
|
|
|
388
396
|
### Proposed Plugins (Vote to Prioritize)
|
|
389
397
|
|
|
390
398
|
The following plugins are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
|
|
391
399
|
|
|
392
|
-
- [Adonis](https://heyapi.dev/openapi
|
|
393
|
-
- [Ajv](https://heyapi.dev/openapi
|
|
394
|
-
- [Arktype](https://heyapi.dev/openapi
|
|
395
|
-
- [Chance](https://heyapi.dev/openapi
|
|
396
|
-
- [Elysia](https://heyapi.dev/openapi
|
|
397
|
-
- [Express](https://heyapi.dev/openapi
|
|
398
|
-
- [Faker](https://heyapi.dev/openapi
|
|
399
|
-
- [Falso](https://heyapi.dev/openapi
|
|
400
|
-
- [Hono](https://heyapi.dev/openapi
|
|
401
|
-
- [Joi](https://heyapi.dev/openapi
|
|
402
|
-
- [Koa](https://heyapi.dev/openapi
|
|
403
|
-
- [MSW](https://heyapi.dev/openapi
|
|
404
|
-
- [Nock](https://heyapi.dev/openapi
|
|
405
|
-
- [Superstruct](https://heyapi.dev/openapi
|
|
406
|
-
- [Supertest](https://heyapi.dev/openapi
|
|
407
|
-
- [SWR](https://heyapi.dev/openapi
|
|
408
|
-
- [
|
|
409
|
-
- [
|
|
410
|
-
- [
|
|
411
|
-
|
|
412
|
-
|
|
400
|
+
- [Adonis](https://heyapi.dev/docs/openapi/typescript/plugins/adonis)
|
|
401
|
+
- [Ajv](https://heyapi.dev/docs/openapi/typescript/plugins/ajv)
|
|
402
|
+
- [Arktype](https://heyapi.dev/docs/openapi/typescript/plugins/arktype)
|
|
403
|
+
- [Chance](https://heyapi.dev/docs/openapi/typescript/plugins/chance)
|
|
404
|
+
- [Elysia](https://heyapi.dev/docs/openapi/typescript/plugins/elysia)
|
|
405
|
+
- [Express](https://heyapi.dev/docs/openapi/typescript/plugins/express)
|
|
406
|
+
- [Faker](https://heyapi.dev/docs/openapi/typescript/plugins/faker)
|
|
407
|
+
- [Falso](https://heyapi.dev/docs/openapi/typescript/plugins/falso)
|
|
408
|
+
- [Hono](https://heyapi.dev/docs/openapi/typescript/plugins/hono)
|
|
409
|
+
- [Joi](https://heyapi.dev/docs/openapi/typescript/plugins/joi)
|
|
410
|
+
- [Koa](https://heyapi.dev/docs/openapi/typescript/plugins/koa)
|
|
411
|
+
- [MSW](https://heyapi.dev/docs/openapi/typescript/plugins/msw)
|
|
412
|
+
- [Nock](https://heyapi.dev/docs/openapi/typescript/plugins/nock)
|
|
413
|
+
- [Superstruct](https://heyapi.dev/docs/openapi/typescript/plugins/superstruct)
|
|
414
|
+
- [Supertest](https://heyapi.dev/docs/openapi/typescript/plugins/supertest)
|
|
415
|
+
- [SWR](https://heyapi.dev/docs/openapi/typescript/plugins/swr)
|
|
416
|
+
- [TanStack Start](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-start)
|
|
417
|
+
- [TypeBox](https://heyapi.dev/docs/openapi/typescript/plugins/typebox)
|
|
418
|
+
- [Yup](https://heyapi.dev/docs/openapi/typescript/plugins/yup)
|
|
419
|
+
- [Zustand](https://heyapi.dev/docs/openapi/typescript/plugins/zustand)
|
|
420
|
+
|
|
421
|
+
Don't see your plugin? [Build your own](https://heyapi.dev/docs/openapi/typescript/plugins/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
|
|
413
422
|
|
|
414
423
|
## Migrating
|
|
415
424
|
|
|
416
|
-
You can learn more on the [Migrating](https://heyapi.dev/openapi
|
|
425
|
+
You can learn more on the [Migrating](https://heyapi.dev/docs/openapi/typescript/migrating) page.
|
|
417
426
|
|
|
418
427
|
<!-- template-license-start -->
|
|
419
428
|
|
|
@@ -106,10 +106,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
106
106
|
const { opts, req, url } = requestOptions(options);
|
|
107
107
|
|
|
108
108
|
if (opts.security) {
|
|
109
|
-
await setAuthParams(
|
|
110
|
-
...opts,
|
|
111
|
-
security: opts.security,
|
|
112
|
-
});
|
|
109
|
+
await setAuthParams(opts);
|
|
113
110
|
}
|
|
114
111
|
|
|
115
112
|
if (opts.requestValidator) {
|
|
@@ -156,12 +156,13 @@ type MethodFn = <
|
|
|
156
156
|
|
|
157
157
|
type SseFn = <
|
|
158
158
|
TData = unknown,
|
|
159
|
-
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
160
|
+
_TError = unknown,
|
|
160
161
|
ThrowOnError extends boolean = false,
|
|
161
162
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
162
163
|
>(
|
|
163
164
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
|
164
|
-
) => Promise<ServerSentEventsResult<TData
|
|
165
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
165
166
|
|
|
166
167
|
type RequestFn = <
|
|
167
168
|
TData = unknown,
|
|
@@ -180,13 +180,12 @@ export const getParseAs = (
|
|
|
180
180
|
return;
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
-
export
|
|
184
|
-
options: Pick<
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
189
|
-
for (const auth of options.security) {
|
|
183
|
+
export async function setAuthParams(
|
|
184
|
+
options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
185
|
+
headers: HttpHeaders;
|
|
186
|
+
},
|
|
187
|
+
): Promise<void> {
|
|
188
|
+
for (const auth of options.security ?? []) {
|
|
190
189
|
const token = await getAuthToken(auth, options.auth);
|
|
191
190
|
|
|
192
191
|
if (!token) {
|
|
@@ -213,7 +212,7 @@ export const setAuthParams = async (
|
|
|
213
212
|
|
|
214
213
|
return;
|
|
215
214
|
}
|
|
216
|
-
}
|
|
215
|
+
}
|
|
217
216
|
|
|
218
217
|
export const buildUrl: Client['buildUrl'] = (options) => {
|
|
219
218
|
const url = getUrl({
|
|
@@ -105,9 +105,14 @@ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean
|
|
|
105
105
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
106
106
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
107
107
|
|
|
108
|
-
type SseFn = <
|
|
108
|
+
type SseFn = <
|
|
109
|
+
TData = unknown,
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
111
|
+
_TError = unknown,
|
|
112
|
+
ThrowOnError extends boolean = false,
|
|
113
|
+
>(
|
|
109
114
|
options: Omit<RequestOptions<never, ThrowOnError>, 'method'>,
|
|
110
|
-
) => Promise<ServerSentEventsResult<TData
|
|
115
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
111
116
|
|
|
112
117
|
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
113
118
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> &
|
|
@@ -81,14 +81,12 @@ const checkForExistence = (
|
|
|
81
81
|
return false;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
export
|
|
85
|
-
security
|
|
86
|
-
...options
|
|
87
|
-
}: Pick<Required<RequestOptions>, 'security'> &
|
|
88
|
-
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
84
|
+
export async function setAuthParams(
|
|
85
|
+
options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
89
86
|
headers: Record<any, unknown>;
|
|
90
|
-
}
|
|
91
|
-
|
|
87
|
+
},
|
|
88
|
+
): Promise<void> {
|
|
89
|
+
for (const auth of options.security ?? []) {
|
|
92
90
|
if (checkForExistence(options, auth.name)) {
|
|
93
91
|
continue;
|
|
94
92
|
}
|
|
@@ -122,7 +120,7 @@ export const setAuthParams = async ({
|
|
|
122
120
|
break;
|
|
123
121
|
}
|
|
124
122
|
}
|
|
125
|
-
}
|
|
123
|
+
}
|
|
126
124
|
|
|
127
125
|
export const buildUrl: Client['buildUrl'] = (options) => {
|
|
128
126
|
const instanceBaseUrl = options.axios?.defaults?.baseURL;
|
|
@@ -102,10 +102,10 @@ const stripEmptySlots = (params: Params) => {
|
|
|
102
102
|
|
|
103
103
|
export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
|
|
104
104
|
const params: Params = {
|
|
105
|
-
body:
|
|
106
|
-
headers:
|
|
107
|
-
path:
|
|
108
|
-
query:
|
|
105
|
+
body: Object.create(null),
|
|
106
|
+
headers: Object.create(null),
|
|
107
|
+
path: Object.create(null),
|
|
108
|
+
query: Object.create(null),
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
const map = buildKeyMap(fields);
|
|
@@ -149,12 +149,13 @@ type MethodFn = <
|
|
|
149
149
|
|
|
150
150
|
type SseFn = <
|
|
151
151
|
TData = unknown,
|
|
152
|
-
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
+
_TError = unknown,
|
|
153
154
|
ThrowOnError extends boolean = false,
|
|
154
155
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
155
156
|
>(
|
|
156
157
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
|
157
|
-
) => Promise<ServerSentEventsResult<TData
|
|
158
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
158
159
|
|
|
159
160
|
type RequestFn = <
|
|
160
161
|
TData = unknown,
|
|
@@ -116,14 +116,12 @@ const checkForExistence = (
|
|
|
116
116
|
return false;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
export
|
|
120
|
-
security
|
|
121
|
-
...options
|
|
122
|
-
}: Pick<Required<RequestOptions>, 'security'> &
|
|
123
|
-
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
119
|
+
export async function setAuthParams(
|
|
120
|
+
options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
124
121
|
headers: Headers;
|
|
125
|
-
}
|
|
126
|
-
|
|
122
|
+
},
|
|
123
|
+
): Promise<void> {
|
|
124
|
+
for (const auth of options.security ?? []) {
|
|
127
125
|
if (checkForExistence(options, auth.name)) {
|
|
128
126
|
continue;
|
|
129
127
|
}
|
|
@@ -152,7 +150,7 @@ export const setAuthParams = async ({
|
|
|
152
150
|
break;
|
|
153
151
|
}
|
|
154
152
|
}
|
|
155
|
-
}
|
|
153
|
+
}
|
|
156
154
|
|
|
157
155
|
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
158
156
|
getUrl({
|
package/dist/clients/ky/types.ts
CHANGED
|
@@ -167,12 +167,13 @@ type MethodFn = <
|
|
|
167
167
|
|
|
168
168
|
type SseFn = <
|
|
169
169
|
TData = unknown,
|
|
170
|
-
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
171
|
+
_TError = unknown,
|
|
171
172
|
ThrowOnError extends boolean = false,
|
|
172
173
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
173
174
|
>(
|
|
174
175
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
|
175
|
-
) => Promise<ServerSentEventsResult<TData
|
|
176
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
176
177
|
|
|
177
178
|
type RequestFn = <
|
|
178
179
|
TData = unknown,
|
package/dist/clients/ky/utils.ts
CHANGED
|
@@ -114,14 +114,12 @@ const checkForExistence = (
|
|
|
114
114
|
return false;
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
-
export
|
|
118
|
-
security
|
|
119
|
-
...options
|
|
120
|
-
}: Pick<Required<RequestOptions>, 'security'> &
|
|
121
|
-
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
117
|
+
export async function setAuthParams(
|
|
118
|
+
options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
122
119
|
headers: Headers;
|
|
123
|
-
}
|
|
124
|
-
|
|
120
|
+
},
|
|
121
|
+
): Promise<void> {
|
|
122
|
+
for (const auth of options.security ?? []) {
|
|
125
123
|
if (checkForExistence(options, auth.name)) {
|
|
126
124
|
continue;
|
|
127
125
|
}
|
|
@@ -150,7 +148,7 @@ export const setAuthParams = async ({
|
|
|
150
148
|
break;
|
|
151
149
|
}
|
|
152
150
|
}
|
|
153
|
-
}
|
|
151
|
+
}
|
|
154
152
|
|
|
155
153
|
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
156
154
|
getUrl({
|
|
@@ -111,9 +111,14 @@ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean
|
|
|
111
111
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
112
112
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
113
113
|
|
|
114
|
-
type SseFn = <
|
|
114
|
+
type SseFn = <
|
|
115
|
+
TData = unknown,
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
117
|
+
_TError = unknown,
|
|
118
|
+
ThrowOnError extends boolean = false,
|
|
119
|
+
>(
|
|
115
120
|
options: Omit<RequestOptions<never, ThrowOnError>, 'method'>,
|
|
116
|
-
) => Promise<ServerSentEventsResult<TData
|
|
121
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
117
122
|
|
|
118
123
|
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
119
124
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> &
|
|
@@ -196,14 +196,12 @@ const checkForExistence = (
|
|
|
196
196
|
return false;
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
export
|
|
200
|
-
security
|
|
201
|
-
...options
|
|
202
|
-
}: Pick<Required<RequestOptions>, 'security'> &
|
|
203
|
-
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
199
|
+
export async function setAuthParams(
|
|
200
|
+
options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
204
201
|
headers: Headers;
|
|
205
|
-
}
|
|
206
|
-
|
|
202
|
+
},
|
|
203
|
+
): Promise<void> {
|
|
204
|
+
for (const auth of options.security ?? []) {
|
|
207
205
|
if (checkForExistence(options, auth.name)) {
|
|
208
206
|
continue;
|
|
209
207
|
}
|
|
@@ -231,7 +229,7 @@ export const setAuthParams = async ({
|
|
|
231
229
|
break;
|
|
232
230
|
}
|
|
233
231
|
}
|
|
234
|
-
}
|
|
232
|
+
}
|
|
235
233
|
|
|
236
234
|
export const buildUrl: Client['buildUrl'] = (options) => {
|
|
237
235
|
const url = getUrl({
|
|
@@ -38,10 +38,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
if (opts.security) {
|
|
41
|
-
await setAuthParams(
|
|
42
|
-
...opts,
|
|
43
|
-
security: opts.security,
|
|
44
|
-
});
|
|
41
|
+
await setAuthParams(opts);
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
if (opts.requestValidator) {
|
|
@@ -72,12 +69,16 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
72
69
|
opts.onRequest = [
|
|
73
70
|
async ({ options }) => {
|
|
74
71
|
if (security) {
|
|
75
|
-
|
|
72
|
+
const authOpts: Parameters<typeof setAuthParams>[0] = {
|
|
76
73
|
auth: opts.auth,
|
|
77
74
|
headers: options.headers,
|
|
78
75
|
query: options.query,
|
|
79
76
|
security,
|
|
80
|
-
}
|
|
77
|
+
};
|
|
78
|
+
await setAuthParams(authOpts);
|
|
79
|
+
if (authOpts.query !== options.query) {
|
|
80
|
+
options.query = authOpts.query;
|
|
81
|
+
}
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
if (requestValidator) {
|
|
@@ -163,14 +163,12 @@ const checkForExistence = (
|
|
|
163
163
|
return false;
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
export
|
|
167
|
-
security
|
|
168
|
-
...options
|
|
169
|
-
}: Pick<Required<RequestOptions>, 'security'> &
|
|
170
|
-
Pick<RequestOptions, 'auth' | 'query'> & {
|
|
166
|
+
export async function setAuthParams(
|
|
167
|
+
options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
171
168
|
headers: Headers;
|
|
172
|
-
}
|
|
173
|
-
|
|
169
|
+
},
|
|
170
|
+
): Promise<void> {
|
|
171
|
+
for (const auth of options.security ?? []) {
|
|
174
172
|
if (checkForExistence(options, auth.name)) {
|
|
175
173
|
continue;
|
|
176
174
|
}
|
|
@@ -202,7 +200,7 @@ export const setAuthParams = async ({
|
|
|
202
200
|
break;
|
|
203
201
|
}
|
|
204
202
|
}
|
|
205
|
-
}
|
|
203
|
+
}
|
|
206
204
|
|
|
207
205
|
export const buildUrl: Client['buildUrl'] = (options) => {
|
|
208
206
|
const url = getUrl({
|