@vibexp/api-client 0.1.0
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/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/axios/client/client.gen.d.ts +2 -0
- package/dist/axios/client/client.gen.js +130 -0
- package/dist/axios/client/index.d.ts +10 -0
- package/dist/axios/client/index.js +6 -0
- package/dist/axios/client/types.gen.d.ts +87 -0
- package/dist/axios/client/types.gen.js +2 -0
- package/dist/axios/client/utils.gen.d.ts +14 -0
- package/dist/axios/client/utils.gen.js +168 -0
- package/dist/axios/client.gen.d.ts +12 -0
- package/dist/axios/client.gen.js +3 -0
- package/dist/axios/core/auth.gen.d.ts +25 -0
- package/dist/axios/core/auth.gen.js +14 -0
- package/dist/axios/core/bodySerializer.gen.d.ts +25 -0
- package/dist/axios/core/bodySerializer.gen.js +57 -0
- package/dist/axios/core/params.gen.d.ts +43 -0
- package/dist/axios/core/params.gen.js +100 -0
- package/dist/axios/core/pathSerializer.gen.d.ts +33 -0
- package/dist/axios/core/pathSerializer.gen.js +106 -0
- package/dist/axios/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/axios/core/queryKeySerializer.gen.js +92 -0
- package/dist/axios/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/axios/core/serverSentEvents.gen.js +132 -0
- package/dist/axios/core/types.gen.d.ts +83 -0
- package/dist/axios/core/types.gen.js +2 -0
- package/dist/axios/core/utils.gen.d.ts +19 -0
- package/dist/axios/core/utils.gen.js +87 -0
- package/dist/axios/index.d.ts +2 -0
- package/dist/axios/index.js +2 -0
- package/dist/axios/sdk.gen.d.ts +1391 -0
- package/dist/axios/sdk.gen.js +3600 -0
- package/dist/axios/types.gen.d.ts +11043 -0
- package/dist/axios/types.gen.js +2 -0
- package/dist/axios-entry.d.ts +2 -0
- package/dist/axios-entry.js +6 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +17 -0
- package/dist/schema.d.ts +18671 -0
- package/dist/schema.js +5 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VibeXP
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @vibexp/api-client
|
|
2
|
+
|
|
3
|
+
Typed TypeScript client for the VibeXP REST API, generated from the OpenAPI
|
|
4
|
+
spec ([`backend/openapi.yaml`](https://github.com/vibexp/vibexp) → Redocly
|
|
5
|
+
bundle) at publish time. Generated code is **not** committed — every published
|
|
6
|
+
version is built from a pinned backend ref, so the package version always
|
|
7
|
+
reflects a real API contract.
|
|
8
|
+
|
|
9
|
+
- **Main entrypoint** — `openapi-typescript` types + an `openapi-fetch`
|
|
10
|
+
client factory (zero runtime overhead, native `fetch`)
|
|
11
|
+
- **`./axios` entrypoint** — a full SDK generated with `@hey-api/openapi-ts`
|
|
12
|
+
(one named function per `operationId`; consumers must install
|
|
13
|
+
`axios >= 1.6.0` themselves — see below)
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
Published to the public npm registry — no auth or scope config needed:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @vibexp/api-client # pin an exact version
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage — fetch (frontend)
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createApiClient } from "@vibexp/api-client";
|
|
27
|
+
|
|
28
|
+
const client = createApiClient({ baseUrl: "https://api.vibexp.io" });
|
|
29
|
+
// const client = createApiClient({ baseUrl: "http://localhost:8080" }); // dev
|
|
30
|
+
|
|
31
|
+
const { data, error } = await client.GET("/api/v1/teams");
|
|
32
|
+
const created = await client.POST("/api/v1/{team_id}/feed-items/{item_id}/replies", {
|
|
33
|
+
params: { path: { team_id, item_id } },
|
|
34
|
+
body: { content: "..." },
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`paths`, `components`, and `operations` types are exported for standalone use.
|
|
39
|
+
|
|
40
|
+
## Usage — axios (CLI / Node)
|
|
41
|
+
|
|
42
|
+
Consumers of this entrypoint must declare `axios >= 1.6.0` as their **own
|
|
43
|
+
dependency** — importing `./axios` without it fails at module resolution.
|
|
44
|
+
axios is intentionally not declared as a dependency here so fetch-only
|
|
45
|
+
consumers don't pull it (and its Node-only transitives) in.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { client, getMe, listTeams } from "@vibexp/api-client/axios";
|
|
49
|
+
|
|
50
|
+
client.setConfig({ baseURL: "https://api.vibexp.io", headers: { Authorization: `Bearer ${apiKey}` } });
|
|
51
|
+
|
|
52
|
+
const me = await getMe();
|
|
53
|
+
const teams = await listTeams();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Versioning & release
|
|
57
|
+
|
|
58
|
+
Publishing is **release-driven**: creating a GitHub Release with a `v*` tag
|
|
59
|
+
(e.g. `v0.1.0`) runs the **Publish** workflow
|
|
60
|
+
(`.github/workflows/publish.yml`), which:
|
|
61
|
+
|
|
62
|
+
1. derives the npm version from the tag (`v0.1.0` → `0.1.0`),
|
|
63
|
+
2. checks out `vibexp/vibexp` at the **same tag** and regenerates the client,
|
|
64
|
+
3. **runs the smoke typecheck (the generation gate) and only publishes if it passes**, then
|
|
65
|
+
4. publishes to the public npm registry.
|
|
66
|
+
|
|
67
|
+
The version mirrors the backend release the client was generated from, so
|
|
68
|
+
consumers can tell which API contract a client targets. Pin exact versions in
|
|
69
|
+
consumers.
|
|
70
|
+
|
|
71
|
+
> Manual override: the workflow can also be run via **workflow_dispatch** with
|
|
72
|
+
> optional `version` / `backend_ref` inputs — handy for the first publish before
|
|
73
|
+
> the backend is tagged (set `backend_ref=main`).
|
|
74
|
+
|
|
75
|
+
Requires the repo secret `NPM_TOKEN` (an npm automation token with publish
|
|
76
|
+
rights to the `@vibexp` scope).
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
Generation reads the backend OpenAPI spec. Point `VIBEXP_SPEC` at a local
|
|
81
|
+
`openapi.yaml`, or check the backend repo out at `spec-src/`:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
git clone https://github.com/vibexp/vibexp spec-src # provides spec-src/backend/openapi.yaml
|
|
85
|
+
npm install
|
|
86
|
+
npm run smoke # bundle spec → generate types + axios SDK → tsc build → typecheck smoke/
|
|
87
|
+
|
|
88
|
+
# or point at an existing checkout:
|
|
89
|
+
VIBEXP_SPEC=/path/to/vibexp/backend/openapi.yaml npm run smoke
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`src/schema.ts` and `src/axios/` are generated (gitignored); the only
|
|
93
|
+
hand-written sources are `src/index.ts`, `src/axios-entry.ts` and `smoke/smoke.ts`.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
4
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
5
|
+
import { buildUrl, createConfig, mergeConfigs, mergeHeaders, setAuthParams } from './utils.gen';
|
|
6
|
+
export const createClient = (config = {}) => {
|
|
7
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
8
|
+
let instance;
|
|
9
|
+
if (_config.axios && !('Axios' in _config.axios)) {
|
|
10
|
+
instance = _config.axios;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
const { auth, ...configWithoutAuth } = _config;
|
|
15
|
+
instance = axios.create(configWithoutAuth);
|
|
16
|
+
}
|
|
17
|
+
const getConfig = () => ({ ..._config });
|
|
18
|
+
const setConfig = (config) => {
|
|
19
|
+
_config = mergeConfigs(_config, config);
|
|
20
|
+
instance.defaults = {
|
|
21
|
+
...instance.defaults,
|
|
22
|
+
..._config,
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
headers: mergeHeaders(instance.defaults.headers, _config.headers),
|
|
25
|
+
};
|
|
26
|
+
return getConfig();
|
|
27
|
+
};
|
|
28
|
+
const beforeRequest = async (options) => {
|
|
29
|
+
const opts = {
|
|
30
|
+
..._config,
|
|
31
|
+
...options,
|
|
32
|
+
axios: options.axios ?? _config.axios ?? instance,
|
|
33
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
34
|
+
};
|
|
35
|
+
if (opts.security) {
|
|
36
|
+
await setAuthParams(opts);
|
|
37
|
+
}
|
|
38
|
+
if (opts.requestValidator) {
|
|
39
|
+
await opts.requestValidator(opts);
|
|
40
|
+
}
|
|
41
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
42
|
+
opts.body = opts.bodySerializer(opts.body);
|
|
43
|
+
}
|
|
44
|
+
const url = buildUrl(opts);
|
|
45
|
+
return { opts, url };
|
|
46
|
+
};
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
const request = async (options) => {
|
|
49
|
+
const { opts, url } = await beforeRequest(options);
|
|
50
|
+
try {
|
|
51
|
+
// assign Axios here for consistency with fetch
|
|
52
|
+
const _axios = opts.axios;
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
54
|
+
const { auth, ...optsWithoutAuth } = opts;
|
|
55
|
+
const response = await _axios({
|
|
56
|
+
...optsWithoutAuth,
|
|
57
|
+
baseURL: '', // the baseURL is already included in `url`
|
|
58
|
+
data: getValidRequestBody(opts),
|
|
59
|
+
headers: opts.headers,
|
|
60
|
+
// let `paramsSerializer()` handle query params if it exists
|
|
61
|
+
params: opts.paramsSerializer ? opts.query : undefined,
|
|
62
|
+
url,
|
|
63
|
+
});
|
|
64
|
+
let { data } = response;
|
|
65
|
+
if (opts.responseType === 'json') {
|
|
66
|
+
if (opts.responseValidator) {
|
|
67
|
+
await opts.responseValidator(data);
|
|
68
|
+
}
|
|
69
|
+
if (opts.responseTransformer) {
|
|
70
|
+
data = await opts.responseTransformer(data);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
...response,
|
|
75
|
+
data: data ?? {},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
const e = error;
|
|
80
|
+
if (opts.throwOnError) {
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
// @ts-expect-error
|
|
84
|
+
e.error = e.response?.data ?? {};
|
|
85
|
+
return e;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
89
|
+
const makeSseFn = (method) => async (options) => {
|
|
90
|
+
const { opts, url } = await beforeRequest(options);
|
|
91
|
+
return createSseClient({
|
|
92
|
+
...opts,
|
|
93
|
+
body: opts.body,
|
|
94
|
+
headers: opts.headers,
|
|
95
|
+
method,
|
|
96
|
+
serializedBody: getValidRequestBody(opts),
|
|
97
|
+
// @ts-expect-error
|
|
98
|
+
signal: opts.signal,
|
|
99
|
+
url,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const _buildUrl = (options) => buildUrl({ axios: instance, ..._config, ...options });
|
|
103
|
+
return {
|
|
104
|
+
buildUrl: _buildUrl,
|
|
105
|
+
connect: makeMethodFn('CONNECT'),
|
|
106
|
+
delete: makeMethodFn('DELETE'),
|
|
107
|
+
get: makeMethodFn('GET'),
|
|
108
|
+
getConfig,
|
|
109
|
+
head: makeMethodFn('HEAD'),
|
|
110
|
+
instance,
|
|
111
|
+
options: makeMethodFn('OPTIONS'),
|
|
112
|
+
patch: makeMethodFn('PATCH'),
|
|
113
|
+
post: makeMethodFn('POST'),
|
|
114
|
+
put: makeMethodFn('PUT'),
|
|
115
|
+
request,
|
|
116
|
+
setConfig,
|
|
117
|
+
sse: {
|
|
118
|
+
connect: makeSseFn('CONNECT'),
|
|
119
|
+
delete: makeSseFn('DELETE'),
|
|
120
|
+
get: makeSseFn('GET'),
|
|
121
|
+
head: makeSseFn('HEAD'),
|
|
122
|
+
options: makeSseFn('OPTIONS'),
|
|
123
|
+
patch: makeSseFn('PATCH'),
|
|
124
|
+
post: makeSseFn('POST'),
|
|
125
|
+
put: makeSseFn('PUT'),
|
|
126
|
+
trace: makeSseFn('TRACE'),
|
|
127
|
+
},
|
|
128
|
+
trace: makeMethodFn('TRACE'),
|
|
129
|
+
};
|
|
130
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { Auth } from '../core/auth.gen';
|
|
2
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
|
+
export { buildClientParams } from '../core/params.gen';
|
|
5
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
6
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
7
|
+
export type { ClientMeta } from '../core/types.gen';
|
|
8
|
+
export { createClient } from './client.gen';
|
|
9
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, TDataShape, } from './types.gen';
|
|
10
|
+
export { createConfig } from './utils.gen';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
3
|
+
export { buildClientParams } from '../core/params.gen';
|
|
4
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
5
|
+
export { createClient } from './client.gen';
|
|
6
|
+
export { createConfig } from './utils.gen';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { AxiosError, AxiosInstance, AxiosRequestHeaders, AxiosResponse, AxiosStatic, CreateAxiosDefaults } from 'axios';
|
|
2
|
+
import type { Auth } from '../core/auth.gen';
|
|
3
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
4
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
5
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<CreateAxiosDefaults, 'auth' | 'baseURL' | 'headers' | 'method'>, CoreConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Axios implementation. You can use this option to provide either an
|
|
8
|
+
* `AxiosStatic` or an `AxiosInstance`.
|
|
9
|
+
*
|
|
10
|
+
* @default axios
|
|
11
|
+
*/
|
|
12
|
+
axios?: AxiosStatic | AxiosInstance;
|
|
13
|
+
/**
|
|
14
|
+
* Base URL for all requests made by this client.
|
|
15
|
+
*/
|
|
16
|
+
baseURL?: T['baseURL'];
|
|
17
|
+
/**
|
|
18
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
19
|
+
* `Headers` object with.
|
|
20
|
+
*
|
|
21
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
22
|
+
*/
|
|
23
|
+
headers?: AxiosRequestHeaders | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Throw an error instead of returning it in the response?
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
throwOnError?: T['throwOnError'];
|
|
30
|
+
}
|
|
31
|
+
export interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
32
|
+
throwOnError: ThrowOnError;
|
|
33
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
34
|
+
/**
|
|
35
|
+
* Any body that you want to add to your request.
|
|
36
|
+
*
|
|
37
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
38
|
+
*/
|
|
39
|
+
body?: unknown;
|
|
40
|
+
path?: Record<string, unknown>;
|
|
41
|
+
query?: Record<string, unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Security mechanism(s) to use for the request.
|
|
44
|
+
*/
|
|
45
|
+
security?: ReadonlyArray<Auth>;
|
|
46
|
+
url: Url;
|
|
47
|
+
}
|
|
48
|
+
export interface ClientOptions {
|
|
49
|
+
baseURL?: string;
|
|
50
|
+
throwOnError?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export 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> & {
|
|
53
|
+
error: undefined;
|
|
54
|
+
}) | (AxiosError<TError extends Record<string, unknown> ? TError[keyof TError] : TError> & {
|
|
55
|
+
data: undefined;
|
|
56
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
57
|
+
})>;
|
|
58
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
|
|
59
|
+
type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<never, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData>>;
|
|
60
|
+
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>;
|
|
61
|
+
type BuildUrlFn = <TData extends {
|
|
62
|
+
path?: Record<string, unknown>;
|
|
63
|
+
query?: Record<string, unknown>;
|
|
64
|
+
url: string;
|
|
65
|
+
}>(options: TData & Pick<RequestOptions<unknown, boolean>, 'axios' | 'baseURL' | 'paramsSerializer' | 'querySerializer'>) => string;
|
|
66
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
67
|
+
instance: AxiosInstance;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
71
|
+
* and the returned object will become the client's initial configuration.
|
|
72
|
+
*
|
|
73
|
+
* You may want to initialize your client this way instead of calling
|
|
74
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
75
|
+
* to ensure your client always has the correct values.
|
|
76
|
+
*/
|
|
77
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
78
|
+
export interface TDataShape {
|
|
79
|
+
body?: unknown;
|
|
80
|
+
headers?: unknown;
|
|
81
|
+
path?: unknown;
|
|
82
|
+
query?: unknown;
|
|
83
|
+
url: string;
|
|
84
|
+
}
|
|
85
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
86
|
+
export 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'>);
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
2
|
+
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => ((queryParams: T) => string);
|
|
4
|
+
export declare function setAuthParams(options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
|
|
5
|
+
headers: Record<any, unknown>;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
export declare const buildUrl: Client['buildUrl'];
|
|
8
|
+
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
9
|
+
/**
|
|
10
|
+
* Special Axios headers keywords allowing to set headers by request method.
|
|
11
|
+
*/
|
|
12
|
+
export declare const axiosHeadersKeywords: readonly ["common", "delete", "get", "head", "patch", "post", "put"];
|
|
13
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Record<any, unknown>;
|
|
14
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { getAuthToken } from '../core/auth.gen';
|
|
3
|
+
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from '../core/pathSerializer.gen';
|
|
4
|
+
import { getUrl } from '../core/utils.gen';
|
|
5
|
+
export const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
6
|
+
const querySerializer = (queryParams) => {
|
|
7
|
+
const search = [];
|
|
8
|
+
if (queryParams && typeof queryParams === 'object') {
|
|
9
|
+
for (const name in queryParams) {
|
|
10
|
+
const value = queryParams[name];
|
|
11
|
+
if (value === undefined || value === null) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const options = parameters[name] || args;
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
const serializedArray = serializeArrayParam({
|
|
17
|
+
allowReserved: options.allowReserved,
|
|
18
|
+
explode: true,
|
|
19
|
+
name,
|
|
20
|
+
style: 'form',
|
|
21
|
+
value,
|
|
22
|
+
...options.array,
|
|
23
|
+
});
|
|
24
|
+
if (serializedArray)
|
|
25
|
+
search.push(serializedArray);
|
|
26
|
+
}
|
|
27
|
+
else if (typeof value === 'object') {
|
|
28
|
+
const serializedObject = serializeObjectParam({
|
|
29
|
+
allowReserved: options.allowReserved,
|
|
30
|
+
explode: true,
|
|
31
|
+
name,
|
|
32
|
+
style: 'deepObject',
|
|
33
|
+
value: value,
|
|
34
|
+
...options.object,
|
|
35
|
+
});
|
|
36
|
+
if (serializedObject)
|
|
37
|
+
search.push(serializedObject);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
41
|
+
allowReserved: options.allowReserved,
|
|
42
|
+
name,
|
|
43
|
+
value: value,
|
|
44
|
+
});
|
|
45
|
+
if (serializedPrimitive)
|
|
46
|
+
search.push(serializedPrimitive);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return search.join('&');
|
|
51
|
+
};
|
|
52
|
+
return querySerializer;
|
|
53
|
+
};
|
|
54
|
+
const checkForExistence = (options, name) => {
|
|
55
|
+
if (!name) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (name in options.headers || options.query?.[name]) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if ('Cookie' in options.headers &&
|
|
62
|
+
options.headers['Cookie'] &&
|
|
63
|
+
typeof options.headers['Cookie'] === 'string') {
|
|
64
|
+
return options.headers['Cookie'].includes(`${name}=`);
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
export async function setAuthParams(options) {
|
|
69
|
+
for (const auth of options.security ?? []) {
|
|
70
|
+
if (checkForExistence(options, auth.name)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const token = await getAuthToken(auth, options.auth);
|
|
74
|
+
if (!token) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const name = auth.name ?? 'Authorization';
|
|
78
|
+
switch (auth.in) {
|
|
79
|
+
case 'query':
|
|
80
|
+
if (!options.query) {
|
|
81
|
+
options.query = {};
|
|
82
|
+
}
|
|
83
|
+
options.query[name] = token;
|
|
84
|
+
break;
|
|
85
|
+
case 'cookie': {
|
|
86
|
+
const value = `${name}=${token}`;
|
|
87
|
+
if ('Cookie' in options.headers && options.headers['Cookie']) {
|
|
88
|
+
options.headers['Cookie'] = `${options.headers['Cookie']}; ${value}`;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
options.headers['Cookie'] = value;
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'header':
|
|
96
|
+
default:
|
|
97
|
+
options.headers[name] = token;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export const buildUrl = (options) => {
|
|
103
|
+
const instanceBaseUrl = options.axios?.defaults?.baseURL;
|
|
104
|
+
const baseUrl = options.baseURL && typeof options.baseURL === 'string' ? options.baseURL : instanceBaseUrl;
|
|
105
|
+
return getUrl({
|
|
106
|
+
baseUrl: baseUrl,
|
|
107
|
+
path: options.path,
|
|
108
|
+
// let `paramsSerializer()` handle query params if it exists
|
|
109
|
+
query: !options.paramsSerializer ? options.query : undefined,
|
|
110
|
+
querySerializer: typeof options.querySerializer === 'function'
|
|
111
|
+
? options.querySerializer
|
|
112
|
+
: createQuerySerializer(options.querySerializer),
|
|
113
|
+
url: options.url,
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
export const mergeConfigs = (a, b) => {
|
|
117
|
+
const config = { ...a, ...b };
|
|
118
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
119
|
+
return config;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Special Axios headers keywords allowing to set headers by request method.
|
|
123
|
+
*/
|
|
124
|
+
export const axiosHeadersKeywords = [
|
|
125
|
+
'common',
|
|
126
|
+
'delete',
|
|
127
|
+
'get',
|
|
128
|
+
'head',
|
|
129
|
+
'patch',
|
|
130
|
+
'post',
|
|
131
|
+
'put',
|
|
132
|
+
];
|
|
133
|
+
export const mergeHeaders = (...headers) => {
|
|
134
|
+
const mergedHeaders = {};
|
|
135
|
+
for (const header of headers) {
|
|
136
|
+
if (!header || typeof header !== 'object') {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const iterator = Object.entries(header);
|
|
140
|
+
for (const [key, value] of iterator) {
|
|
141
|
+
if (axiosHeadersKeywords.includes(key) &&
|
|
142
|
+
typeof value === 'object') {
|
|
143
|
+
mergedHeaders[key] = {
|
|
144
|
+
...mergedHeaders[key],
|
|
145
|
+
...value,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
else if (value === null) {
|
|
149
|
+
delete mergedHeaders[key];
|
|
150
|
+
}
|
|
151
|
+
else if (Array.isArray(value)) {
|
|
152
|
+
for (const v of value) {
|
|
153
|
+
// @ts-expect-error
|
|
154
|
+
mergedHeaders[key] = [...(mergedHeaders[key] ?? []), v];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (value !== undefined) {
|
|
158
|
+
// assume object headers are meant to be JSON stringified, i.e., their
|
|
159
|
+
// content value in OpenAPI specification is 'application/json'
|
|
160
|
+
mergedHeaders[key] = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return mergedHeaders;
|
|
165
|
+
};
|
|
166
|
+
export const createConfig = (override = {}) => ({
|
|
167
|
+
...override,
|
|
168
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Client, type ClientOptions, type Config } from './client';
|
|
2
|
+
import type { ClientOptions as ClientOptions2 } from './types.gen';
|
|
3
|
+
/**
|
|
4
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
5
|
+
* and the returned object will become the client's initial configuration.
|
|
6
|
+
*
|
|
7
|
+
* You may want to initialize your client this way instead of calling
|
|
8
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
9
|
+
* to ensure your client always has the correct values.
|
|
10
|
+
*/
|
|
11
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
|
+
export declare const client: Client;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type AuthToken = string | undefined;
|
|
2
|
+
export interface Auth {
|
|
3
|
+
/**
|
|
4
|
+
* Which part of the request do we use to send the auth?
|
|
5
|
+
*
|
|
6
|
+
* @default 'header'
|
|
7
|
+
*/
|
|
8
|
+
in?: 'header' | 'query' | 'cookie';
|
|
9
|
+
/**
|
|
10
|
+
* A unique identifier for the security scheme.
|
|
11
|
+
*
|
|
12
|
+
* Defined only when there are multiple security schemes whose `Auth`
|
|
13
|
+
* shape would otherwise be identical.
|
|
14
|
+
*/
|
|
15
|
+
key?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Header or query parameter name.
|
|
18
|
+
*
|
|
19
|
+
* @default 'Authorization'
|
|
20
|
+
*/
|
|
21
|
+
name?: string;
|
|
22
|
+
scheme?: 'basic' | 'bearer';
|
|
23
|
+
type: 'apiKey' | 'http';
|
|
24
|
+
}
|
|
25
|
+
export declare const getAuthToken: (auth: Auth, callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken) => Promise<string | undefined>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export const getAuthToken = async (auth, callback) => {
|
|
3
|
+
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
|
4
|
+
if (!token) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (auth.scheme === 'bearer') {
|
|
8
|
+
return `Bearer ${token}`;
|
|
9
|
+
}
|
|
10
|
+
if (auth.scheme === 'basic') {
|
|
11
|
+
return `Basic ${btoa(token)}`;
|
|
12
|
+
}
|
|
13
|
+
return token;
|
|
14
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen';
|
|
2
|
+
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
3
|
+
export type BodySerializer = (body: unknown) => unknown;
|
|
4
|
+
type QuerySerializerOptionsObject = {
|
|
5
|
+
allowReserved?: boolean;
|
|
6
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
7
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
8
|
+
};
|
|
9
|
+
export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
10
|
+
/**
|
|
11
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
12
|
+
* override the global array/object settings for specific parameter names.
|
|
13
|
+
*/
|
|
14
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
15
|
+
};
|
|
16
|
+
export declare const formDataBodySerializer: {
|
|
17
|
+
bodySerializer: (body: unknown) => FormData;
|
|
18
|
+
};
|
|
19
|
+
export declare const jsonBodySerializer: {
|
|
20
|
+
bodySerializer: (body: unknown) => string;
|
|
21
|
+
};
|
|
22
|
+
export declare const urlSearchParamsBodySerializer: {
|
|
23
|
+
bodySerializer: (body: unknown) => string;
|
|
24
|
+
};
|
|
25
|
+
export {};
|