@kubb/plugin-fetch 5.5.10 → 5.5.12
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/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/docs/guides/authentication.md +0 -5
- package/docs/guides/base-url.md +0 -5
- package/docs/guides/calling-operations.md +0 -7
- package/docs/guides/error-handling.md +0 -6
- package/docs/guides/interceptors.md +0 -6
- package/docs/guides/serialization.md +0 -6
- package/docs/guides/server-sent-events.md +0 -5
- package/docs/guides/transport.md +0 -6
- package/docs/options.md +0 -27
- package/docs/overview.md +14 -15
- package/kubb-extension.json +1 -0
- package/package.json +5 -5
- package/src/types.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1487,7 +1487,7 @@ var compatibility = {
|
|
|
1487
1487
|
};
|
|
1488
1488
|
//#endregion
|
|
1489
1489
|
//#region package.json
|
|
1490
|
-
var version = "5.5.
|
|
1490
|
+
var version = "5.5.12";
|
|
1491
1491
|
//#endregion
|
|
1492
1492
|
//#region src/templates.ts
|
|
1493
1493
|
/** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { Exclude, Group, Include, Output, OutputOptions, Override,
|
|
2
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
3
|
import "kubb/jsx";
|
|
4
4
|
import "@kubb/plugin-zod";
|
|
5
5
|
//#region ../../internals/client/src/types.d.ts
|
|
@@ -188,7 +188,7 @@ type ResolvedOptions = {
|
|
|
188
188
|
* resolved-options shape with the other client plugins; only the plugin name and transport
|
|
189
189
|
* differ.
|
|
190
190
|
*/
|
|
191
|
-
type PluginFetch =
|
|
191
|
+
type PluginFetch = PluginType<'plugin-fetch', Options, ResolvedOptions, ResolverClient>;
|
|
192
192
|
declare global {
|
|
193
193
|
namespace Kubb {
|
|
194
194
|
interface PluginRegistry {
|
package/dist/index.js
CHANGED
|
@@ -1461,7 +1461,7 @@ var compatibility = {
|
|
|
1461
1461
|
};
|
|
1462
1462
|
//#endregion
|
|
1463
1463
|
//#region package.json
|
|
1464
|
-
var version = "5.5.
|
|
1464
|
+
var version = "5.5.12";
|
|
1465
1465
|
//#endregion
|
|
1466
1466
|
//#region src/templates.ts
|
|
1467
1467
|
/** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */
|
|
@@ -70,8 +70,3 @@ const { data } = await getPetById({ path: { petId: 1 }, client: tenant })
|
|
|
70
70
|
To override the client for one request, pass `auth` on that single call, which suits a one-off token refresh. An explicit `headers` value you set on a call always wins over the resolved token.
|
|
71
71
|
|
|
72
72
|
For authentication outside OpenAPI security schemes, use an async request interceptor to sign requests or supply custom headers.
|
|
73
|
-
|
|
74
|
-
## See also
|
|
75
|
-
|
|
76
|
-
- [Add interceptors](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/interceptors)
|
|
77
|
-
- [Set the base URL](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/base-url)
|
package/docs/guides/base-url.md
CHANGED
|
@@ -56,8 +56,3 @@ const { data } = await getPetById({ path: { petId: 1 }, baseURL: 'https://localh
|
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
A `baseURL` set on the call wins over `createClient`, which wins over `setConfig`, which wins over the build-time value.
|
|
59
|
-
|
|
60
|
-
## See also
|
|
61
|
-
|
|
62
|
-
- [Authenticate requests](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/authentication)
|
|
63
|
-
- [Use a custom transport](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/transport)
|
|
@@ -138,10 +138,3 @@ const url = client.getUrl({
|
|
|
138
138
|
})
|
|
139
139
|
// https://api.example.com/v1/pets/1?fields=name
|
|
140
140
|
```
|
|
141
|
-
|
|
142
|
-
## See also
|
|
143
|
-
|
|
144
|
-
- [Handle errors](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/error-handling)
|
|
145
|
-
- [Configure serialization](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/serialization)
|
|
146
|
-
- [Set the base URL](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/base-url)
|
|
147
|
-
- [Server-sent events](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/server-sent-events)
|
|
@@ -116,9 +116,3 @@ A `ParseError` reports schema validation issues. A `ResponseError` reports a non
|
|
|
116
116
|
|
|
117
117
|
Calling `.unwrap()` on a `throwOnError: false` call turns that same `error` into a rejection, so a
|
|
118
118
|
`try`/`catch` works there too.
|
|
119
|
-
|
|
120
|
-
## See also
|
|
121
|
-
|
|
122
|
-
- [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/calling-operations)
|
|
123
|
-
- [Configure serialization](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/serialization)
|
|
124
|
-
- [Add interceptors](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/interceptors)
|
|
@@ -70,9 +70,3 @@ client.interceptors.request.eject(id)
|
|
|
70
70
|
## Where to set them
|
|
71
71
|
|
|
72
72
|
Register handlers on the shared `client` for all operations, or on a separate `createClient` instance for isolated calls. Interceptors are instance-level settings.
|
|
73
|
-
|
|
74
|
-
## See also
|
|
75
|
-
|
|
76
|
-
- [Handle errors](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/error-handling)
|
|
77
|
-
- [Authenticate requests](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/authentication)
|
|
78
|
-
- [Use a custom transport](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/transport)
|
|
@@ -112,9 +112,3 @@ pluginFetch({ validator: { request: 'zod', response: 'zod' } })
|
|
|
112
112
|
With a validator set, Kubb passes the matching schema to each generated call, and the runtime
|
|
113
113
|
parses the body through it. A body that does not match throws a `ParseError` with the schema's
|
|
114
114
|
`issues`.
|
|
115
|
-
|
|
116
|
-
## See also
|
|
117
|
-
|
|
118
|
-
- [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/calling-operations)
|
|
119
|
-
- [Handle errors](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/error-handling)
|
|
120
|
-
- [Server-sent events](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/server-sent-events)
|
|
@@ -92,8 +92,3 @@ try {
|
|
|
92
92
|
> [!NOTE]
|
|
93
93
|
> A drop mid-stream ends the `for await` loop. Track the last event's `id` if you need to reconnect
|
|
94
94
|
> from where the stream stopped.
|
|
95
|
-
|
|
96
|
-
## See also
|
|
97
|
-
|
|
98
|
-
- [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/calling-operations)
|
|
99
|
-
- [Handle errors](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/error-handling)
|
package/docs/guides/transport.md
CHANGED
|
@@ -63,9 +63,3 @@ Pass the isolated client per operation or to a query plugin.
|
|
|
63
63
|
## Where to set it
|
|
64
64
|
|
|
65
65
|
Use `client.setConfig({ transport })` for shared configuration, `createClient({ transport })` for an isolated instance, or pass `transport` on an operation to override it for one call.
|
|
66
|
-
|
|
67
|
-
## See also
|
|
68
|
-
|
|
69
|
-
- [Add interceptors](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/interceptors)
|
|
70
|
-
- [Set the base URL](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/base-url)
|
|
71
|
-
- [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-fetch/guides/calling-operations)
|
package/docs/options.md
CHANGED
|
@@ -11,7 +11,6 @@ Pass these options to `pluginFetch()`. Shared options link to [Shared plugin opt
|
|
|
11
11
|
| [`baseURL`](#baseurl) | Base URL prepended to every request. | None |
|
|
12
12
|
| [`throwOnErrorDefault`](#throwonerrordefault) | Default error behavior and return type for generated operations. | `true` |
|
|
13
13
|
| [`validator`](#validator) | Validate request and response bodies with Zod. | `false` |
|
|
14
|
-
| [`comments`](#comments) | How much of each description reaches the JSDoc. | `'full'` |
|
|
15
14
|
| [`sdk`](#sdk) | Generate a class-based SDK instead of functions. | None |
|
|
16
15
|
| [`returnType`](#returntype) | Shape of the value a generated call resolves to. | `'full'` |
|
|
17
16
|
| [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
|
|
@@ -90,32 +89,6 @@ export default defineConfig({
|
|
|
90
89
|
})
|
|
91
90
|
```
|
|
92
91
|
|
|
93
|
-
### comments
|
|
94
|
-
|
|
95
|
-
Controls generated JSDoc.
|
|
96
|
-
|
|
97
|
-
| | |
|
|
98
|
-
| -------- | ----------------------------- |
|
|
99
|
-
| Type | `'full' \| 'brief' \| 'none'` |
|
|
100
|
-
| Required | `false` |
|
|
101
|
-
| Default | `'full'` |
|
|
102
|
-
|
|
103
|
-
::field-group
|
|
104
|
-
|
|
105
|
-
:::field{name="'full'"}
|
|
106
|
-
Default value. Keeps complete descriptions and tags.
|
|
107
|
-
:::
|
|
108
|
-
|
|
109
|
-
:::field{name="'brief'"}
|
|
110
|
-
Keeps the first sentence and other tags. Descriptions over 150 characters without a sentence ending are cut at the last word before 120.
|
|
111
|
-
:::
|
|
112
|
-
|
|
113
|
-
:::field{name="'none'"}
|
|
114
|
-
Omits JSDoc but keeps the generated-by banner.
|
|
115
|
-
:::
|
|
116
|
-
|
|
117
|
-
::
|
|
118
|
-
|
|
119
92
|
### sdk
|
|
120
93
|
|
|
121
94
|
Generates a class-based SDK. Each instance takes its own client config, so environments can use separate clients. Leave `sdk` unset to keep the standalone functions that query plugins call.
|
package/docs/overview.md
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
# Fetch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Fetch plugin turns each operation in your OpenAPI spec into a typed async function that sends the request with the native Fetch API. Each function takes grouped `path`, `query`, `headers`, and `body` parameters and returns a result keyed by status code.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The query plugins (`@kubb/plugin-react-query`, `@kubb/plugin-vue-query`, and `@kubb/plugin-swr`) and `@kubb/plugin-mcp` call these functions. The plugin also copies its runtime files (`client.ts`, `serializers.ts`, and `standardSchema.ts`) to `.kubb/` in the root output folder.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
9
|
-
- Add `@kubb/plugin-ts` for the operation types
|
|
10
|
-
- Add `@kubb/plugin-zod` when you set `validator
|
|
11
|
-
- No HTTP client package is needed.
|
|
9
|
+
- Add `@kubb/plugin-ts` for the operation types, or `@kubb/plugin-zod` with `inferred: true`.
|
|
10
|
+
- Add `@kubb/plugin-zod` when you set `validator`, and install `zod` v4. Without the plugin, `validator` does nothing.
|
|
11
|
+
- No HTTP client package is needed. The generated code calls the global `fetch`.
|
|
12
12
|
|
|
13
13
|
## Options worth knowing
|
|
14
14
|
|
|
15
|
-
- `baseURL` is prepended to every request.
|
|
16
|
-
- `validator: 'zod'` validates
|
|
17
|
-
- `
|
|
18
|
-
- `returnType: 'data'` makes a call resolve to the success body instead of the full result
|
|
19
|
-
- `
|
|
15
|
+
- `baseURL` is prepended to every request. The spec's `servers` URL is not used, so without `baseURL` you set one at runtime with `client.setConfig({ baseURL })`.
|
|
16
|
+
- `validator: 'zod'` validates response bodies with the schemas from `@kubb/plugin-zod`. Use `{ request: 'zod', response: 'zod' }` to also validate request bodies.
|
|
17
|
+
- `throwOnErrorDefault: false` returns non-2xx responses as values instead of throwing. A single call can still pass `throwOnError`.
|
|
18
|
+
- `returnType: 'data'` makes a call resolve to the success body instead of the full result. With `throwOnError: false`, the call still returns the full result.
|
|
19
|
+
- `sdk` generates a class-based SDK, grouped by tag or flat, instead of standalone functions. The query plugins and `@kubb/plugin-mcp` need the standalone functions, so leave `sdk` unset when you use them.
|
|
20
|
+
|
|
21
|
+
See [Options](https://kubb.dev/extensions/kubb-labs/plugin-fetch/options) for every option and its default.
|
|
20
22
|
|
|
21
23
|
## Example
|
|
22
24
|
|
|
25
|
+
The config below generates a Fetch client that sends every request to the Petstore API.
|
|
26
|
+
|
|
23
27
|
```typescript [kubb.config.ts]
|
|
24
28
|
import { defineConfig } from 'kubb/config'
|
|
25
29
|
import { pluginTs } from '@kubb/plugin-ts'
|
|
@@ -34,8 +38,3 @@ export default defineConfig({
|
|
|
34
38
|
],
|
|
35
39
|
})
|
|
36
40
|
```
|
|
37
|
-
|
|
38
|
-
## See also
|
|
39
|
-
|
|
40
|
-
- [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
41
|
-
- [`@kubb/plugin-ts`](https://kubb.dev/extensions/kubb-labs/plugin-ts)
|
package/kubb-extension.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-fetch",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.12",
|
|
4
4
|
"description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"registry": "https://registry.npmjs.org/"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@kubb/plugin-ts": "^5.0.
|
|
72
|
-
"@kubb/plugin-zod": "^5.4.
|
|
71
|
+
"@kubb/plugin-ts": "^5.0.11",
|
|
72
|
+
"@kubb/plugin-zod": "^5.4.9"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@internals/client": "0.0.0",
|
|
76
76
|
"@internals/shared": "0.0.0",
|
|
77
|
-
"kubb": "^5.
|
|
77
|
+
"kubb": "^5.9.2",
|
|
78
78
|
"typescript": "^6.0.3"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"kubb": "^5.
|
|
81
|
+
"kubb": "^5.9.2"
|
|
82
82
|
},
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=22"
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PluginType } from 'kubb/kit'
|
|
2
2
|
import type { Options, ResolvedOptions, ResolverClient } from '@internals/client'
|
|
3
3
|
|
|
4
4
|
export type { Options, ResolvedOptions, ResolverClient } from '@internals/client'
|
|
@@ -8,7 +8,7 @@ export type { Options, ResolvedOptions, ResolverClient } from '@internals/client
|
|
|
8
8
|
* resolved-options shape with the other client plugins; only the plugin name and transport
|
|
9
9
|
* differ.
|
|
10
10
|
*/
|
|
11
|
-
export type PluginFetch =
|
|
11
|
+
export type PluginFetch = PluginType<'plugin-fetch', Options, ResolvedOptions, ResolverClient>
|
|
12
12
|
|
|
13
13
|
declare global {
|
|
14
14
|
namespace Kubb {
|