@reverbia/sdk 1.0.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 +45 -0
- package/dist/cjs/client/client/client.gen.d.ts +2 -0
- package/dist/cjs/client/client/client.gen.js +203 -0
- package/dist/cjs/client/client/index.d.ts +8 -0
- package/dist/cjs/client/client/index.js +16 -0
- package/dist/cjs/client/client/types.gen.d.ts +99 -0
- package/dist/cjs/client/client/types.gen.js +3 -0
- package/dist/cjs/client/client/utils.gen.d.ts +40 -0
- package/dist/cjs/client/client/utils.gen.js +314 -0
- package/dist/cjs/client/client.gen.d.ts +12 -0
- package/dist/cjs/client/client.gen.js +6 -0
- package/dist/cjs/client/core/auth.gen.d.ts +18 -0
- package/dist/cjs/client/core/auth.gen.js +18 -0
- package/dist/cjs/client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/cjs/client/core/bodySerializer.gen.js +60 -0
- package/dist/cjs/client/core/params.gen.d.ts +43 -0
- package/dist/cjs/client/core/params.gen.js +104 -0
- package/dist/cjs/client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/cjs/client/core/pathSerializer.gen.js +123 -0
- package/dist/cjs/client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/cjs/client/core/queryKeySerializer.gen.js +105 -0
- package/dist/cjs/client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/cjs/client/core/serverSentEvents.gen.js +139 -0
- package/dist/cjs/client/core/types.gen.d.ts +78 -0
- package/dist/cjs/client/core/types.gen.js +3 -0
- package/dist/cjs/client/core/utils.gen.d.ts +19 -0
- package/dist/cjs/client/core/utils.gen.js +93 -0
- package/dist/cjs/client/index.d.ts +2 -0
- package/dist/cjs/client/index.js +18 -0
- package/dist/cjs/client/sdk.gen.d.ts +27 -0
- package/dist/cjs/client/sdk.gen.js +33 -0
- package/dist/cjs/client/types.gen.d.ts +120 -0
- package/dist/cjs/client/types.gen.js +3 -0
- package/dist/esm/client/client/client.gen.d.ts +2 -0
- package/dist/esm/client/client/client.gen.js +199 -0
- package/dist/esm/client/client/index.d.ts +8 -0
- package/dist/esm/client/client/index.js +6 -0
- package/dist/esm/client/client/types.gen.d.ts +99 -0
- package/dist/esm/client/client/types.gen.js +2 -0
- package/dist/esm/client/client/utils.gen.d.ts +40 -0
- package/dist/esm/client/client/utils.gen.js +302 -0
- package/dist/esm/client/client.gen.d.ts +12 -0
- package/dist/esm/client/client.gen.js +3 -0
- package/dist/esm/client/core/auth.gen.d.ts +18 -0
- package/dist/esm/client/core/auth.gen.js +14 -0
- package/dist/esm/client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/esm/client/core/bodySerializer.gen.js +57 -0
- package/dist/esm/client/core/params.gen.d.ts +43 -0
- package/dist/esm/client/core/params.gen.js +100 -0
- package/dist/esm/client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/esm/client/core/pathSerializer.gen.js +114 -0
- package/dist/esm/client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/esm/client/core/queryKeySerializer.gen.js +99 -0
- package/dist/esm/client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/esm/client/core/serverSentEvents.gen.js +135 -0
- package/dist/esm/client/core/types.gen.d.ts +78 -0
- package/dist/esm/client/core/types.gen.js +2 -0
- package/dist/esm/client/core/utils.gen.d.ts +19 -0
- package/dist/esm/client/core/utils.gen.js +87 -0
- package/dist/esm/client/index.d.ts +2 -0
- package/dist/esm/client/index.js +2 -0
- package/dist/esm/client/sdk.gen.d.ts +27 -0
- package/dist/esm/client/sdk.gen.js +28 -0
- package/dist/esm/client/types.gen.d.ts +120 -0
- package/dist/esm/client/types.gen.js +2 -0
- package/dist/types/client/client/client.gen.d.ts +2 -0
- package/dist/types/client/client/index.d.ts +8 -0
- package/dist/types/client/client/types.gen.d.ts +99 -0
- package/dist/types/client/client/utils.gen.d.ts +40 -0
- package/dist/types/client/client.gen.d.ts +12 -0
- package/dist/types/client/core/auth.gen.d.ts +18 -0
- package/dist/types/client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/types/client/core/params.gen.d.ts +43 -0
- package/dist/types/client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/types/client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/types/client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/types/client/core/types.gen.d.ts +78 -0
- package/dist/types/client/core/utils.gen.d.ts +19 -0
- package/dist/types/client/index.d.ts +2 -0
- package/dist/types/client/sdk.gen.d.ts +27 -0
- package/dist/types/client/types.gen.d.ts +120 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ZetaChain
|
|
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,45 @@
|
|
|
1
|
+
# AI SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with ZetaChain's AI Portal API. This SDK
|
|
4
|
+
provides a type-safe, developer-friendly interface for building applications
|
|
5
|
+
that leverage AI chat completion capabilities.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The AI SDK is an auto-generated TypeScript client library that wraps the
|
|
10
|
+
ZetaChain AI Portal REST API. It enables seamless integration of AI-powered chat
|
|
11
|
+
completion features into your applications with full TypeScript type safety and
|
|
12
|
+
modern async/await patterns.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Type-Safe API Client**: Fully typed interfaces generated from the OpenAPI
|
|
17
|
+
specification, ensuring compile-time safety and excellent IDE autocomplete
|
|
18
|
+
support
|
|
19
|
+
- **Chat Completions**: Generate AI-powered chat responses using configurable
|
|
20
|
+
models and conversation history
|
|
21
|
+
- **Streaming Support**: Built-in support for streaming responses for real-time
|
|
22
|
+
AI interactions
|
|
23
|
+
- **Health Monitoring**: Check service health and status to ensure reliable API
|
|
24
|
+
connectivity
|
|
25
|
+
- **Flexible Configuration**: Customizable client instances with support for
|
|
26
|
+
custom base URLs, authentication, and request/response interceptors
|
|
27
|
+
- **Error Handling**: Configurable error handling with support for throwing
|
|
28
|
+
errors or returning error objects
|
|
29
|
+
- **Server-Sent Events**: Native support for SSE (Server-Sent Events) for
|
|
30
|
+
real-time streaming capabilities
|
|
31
|
+
|
|
32
|
+
## Architecture
|
|
33
|
+
|
|
34
|
+
The SDK is automatically generated from the OpenAPI specification using
|
|
35
|
+
`@hey-api/openapi-ts`, ensuring it stays in sync with the latest API changes.
|
|
36
|
+
The generated client provides a clean, promise-based API that follows modern
|
|
37
|
+
JavaScript/TypeScript best practices.
|
|
38
|
+
|
|
39
|
+
## Use Cases
|
|
40
|
+
|
|
41
|
+
- Building AI-powered chatbots and conversational interfaces
|
|
42
|
+
- Integrating AI capabilities into web and mobile applications
|
|
43
|
+
- Creating applications that require natural language processing
|
|
44
|
+
- Developing tools that leverage large language models through ZetaChain's
|
|
45
|
+
gateway
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createClient = void 0;
|
|
5
|
+
const serverSentEvents_gen_1 = require("../core/serverSentEvents.gen");
|
|
6
|
+
const utils_gen_1 = require("../core/utils.gen");
|
|
7
|
+
const utils_gen_2 = require("./utils.gen");
|
|
8
|
+
const createClient = (config = {}) => {
|
|
9
|
+
let _config = (0, utils_gen_2.mergeConfigs)((0, utils_gen_2.createConfig)(), config);
|
|
10
|
+
const getConfig = () => ({ ..._config });
|
|
11
|
+
const setConfig = (config) => {
|
|
12
|
+
_config = (0, utils_gen_2.mergeConfigs)(_config, config);
|
|
13
|
+
return getConfig();
|
|
14
|
+
};
|
|
15
|
+
const interceptors = (0, utils_gen_2.createInterceptors)();
|
|
16
|
+
const beforeRequest = async (options) => {
|
|
17
|
+
const opts = {
|
|
18
|
+
..._config,
|
|
19
|
+
...options,
|
|
20
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
21
|
+
headers: (0, utils_gen_2.mergeHeaders)(_config.headers, options.headers),
|
|
22
|
+
serializedBody: undefined,
|
|
23
|
+
};
|
|
24
|
+
if (opts.security) {
|
|
25
|
+
await (0, utils_gen_2.setAuthParams)({
|
|
26
|
+
...opts,
|
|
27
|
+
security: opts.security,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (opts.requestValidator) {
|
|
31
|
+
await opts.requestValidator(opts);
|
|
32
|
+
}
|
|
33
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
34
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
35
|
+
}
|
|
36
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
37
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
38
|
+
opts.headers.delete('Content-Type');
|
|
39
|
+
}
|
|
40
|
+
const url = (0, utils_gen_2.buildUrl)(opts);
|
|
41
|
+
return { opts, url };
|
|
42
|
+
};
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
const request = async (options) => {
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
const { opts, url } = await beforeRequest(options);
|
|
47
|
+
for (const fn of interceptors.request.fns) {
|
|
48
|
+
if (fn) {
|
|
49
|
+
await fn(opts);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
53
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
54
|
+
const _fetch = opts.fetch;
|
|
55
|
+
const requestInit = {
|
|
56
|
+
...opts,
|
|
57
|
+
body: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
58
|
+
};
|
|
59
|
+
let response = await _fetch(url, requestInit);
|
|
60
|
+
for (const fn of interceptors.response.fns) {
|
|
61
|
+
if (fn) {
|
|
62
|
+
response = await fn(response, opts);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const result = {
|
|
66
|
+
response,
|
|
67
|
+
};
|
|
68
|
+
if (response.ok) {
|
|
69
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
70
|
+
? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
|
|
71
|
+
: opts.parseAs) ?? 'json';
|
|
72
|
+
if (response.status === 204 ||
|
|
73
|
+
response.headers.get('Content-Length') === '0') {
|
|
74
|
+
let emptyData;
|
|
75
|
+
switch (parseAs) {
|
|
76
|
+
case 'arrayBuffer':
|
|
77
|
+
case 'blob':
|
|
78
|
+
case 'text':
|
|
79
|
+
emptyData = await response[parseAs]();
|
|
80
|
+
break;
|
|
81
|
+
case 'formData':
|
|
82
|
+
emptyData = new FormData();
|
|
83
|
+
break;
|
|
84
|
+
case 'stream':
|
|
85
|
+
emptyData = response.body;
|
|
86
|
+
break;
|
|
87
|
+
case 'json':
|
|
88
|
+
default:
|
|
89
|
+
emptyData = {};
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
data: emptyData,
|
|
94
|
+
...result,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
let data;
|
|
98
|
+
switch (parseAs) {
|
|
99
|
+
case 'arrayBuffer':
|
|
100
|
+
case 'blob':
|
|
101
|
+
case 'formData':
|
|
102
|
+
case 'json':
|
|
103
|
+
case 'text':
|
|
104
|
+
data = await response[parseAs]();
|
|
105
|
+
break;
|
|
106
|
+
case 'stream':
|
|
107
|
+
return {
|
|
108
|
+
data: response.body,
|
|
109
|
+
...result,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (parseAs === 'json') {
|
|
113
|
+
if (opts.responseValidator) {
|
|
114
|
+
await opts.responseValidator(data);
|
|
115
|
+
}
|
|
116
|
+
if (opts.responseTransformer) {
|
|
117
|
+
data = await opts.responseTransformer(data);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
data,
|
|
122
|
+
...result,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const textError = await response.text();
|
|
126
|
+
let jsonError;
|
|
127
|
+
try {
|
|
128
|
+
jsonError = JSON.parse(textError);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// noop
|
|
132
|
+
}
|
|
133
|
+
const error = jsonError ?? textError;
|
|
134
|
+
let finalError = error;
|
|
135
|
+
for (const fn of interceptors.error.fns) {
|
|
136
|
+
if (fn) {
|
|
137
|
+
finalError = (await fn(error, response, opts));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
finalError = finalError || {};
|
|
141
|
+
if (opts.throwOnError) {
|
|
142
|
+
throw finalError;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
error: finalError,
|
|
146
|
+
...result,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
150
|
+
const makeSseFn = (method) => async (options) => {
|
|
151
|
+
const { opts, url } = await beforeRequest(options);
|
|
152
|
+
return (0, serverSentEvents_gen_1.createSseClient)({
|
|
153
|
+
...opts,
|
|
154
|
+
body: opts.body,
|
|
155
|
+
headers: opts.headers,
|
|
156
|
+
method,
|
|
157
|
+
onRequest: async (url, init) => {
|
|
158
|
+
let request = new Request(url, init);
|
|
159
|
+
const requestInit = {
|
|
160
|
+
...init,
|
|
161
|
+
method: init.method,
|
|
162
|
+
url,
|
|
163
|
+
};
|
|
164
|
+
for (const fn of interceptors.request.fns) {
|
|
165
|
+
if (fn) {
|
|
166
|
+
await fn(requestInit);
|
|
167
|
+
request = new Request(requestInit.url, requestInit);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return request;
|
|
171
|
+
},
|
|
172
|
+
url,
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
return {
|
|
176
|
+
buildUrl: utils_gen_2.buildUrl,
|
|
177
|
+
connect: makeMethodFn('CONNECT'),
|
|
178
|
+
delete: makeMethodFn('DELETE'),
|
|
179
|
+
get: makeMethodFn('GET'),
|
|
180
|
+
getConfig,
|
|
181
|
+
head: makeMethodFn('HEAD'),
|
|
182
|
+
interceptors,
|
|
183
|
+
options: makeMethodFn('OPTIONS'),
|
|
184
|
+
patch: makeMethodFn('PATCH'),
|
|
185
|
+
post: makeMethodFn('POST'),
|
|
186
|
+
put: makeMethodFn('PUT'),
|
|
187
|
+
request,
|
|
188
|
+
setConfig,
|
|
189
|
+
sse: {
|
|
190
|
+
connect: makeSseFn('CONNECT'),
|
|
191
|
+
delete: makeSseFn('DELETE'),
|
|
192
|
+
get: makeSseFn('GET'),
|
|
193
|
+
head: makeSseFn('HEAD'),
|
|
194
|
+
options: makeSseFn('OPTIONS'),
|
|
195
|
+
patch: makeSseFn('PATCH'),
|
|
196
|
+
post: makeSseFn('POST'),
|
|
197
|
+
put: makeSseFn('PUT'),
|
|
198
|
+
trace: makeSseFn('TRACE'),
|
|
199
|
+
},
|
|
200
|
+
trace: makeMethodFn('TRACE'),
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
exports.createClient = createClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
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 { createClient } from './client.gen';
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, TDataShape, } from './types.gen';
|
|
8
|
+
export { createConfig } from './utils.gen';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createConfig = exports.createClient = exports.serializeQueryKeyValue = exports.buildClientParams = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = void 0;
|
|
5
|
+
var bodySerializer_gen_1 = require("../core/bodySerializer.gen");
|
|
6
|
+
Object.defineProperty(exports, "formDataBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.formDataBodySerializer; } });
|
|
7
|
+
Object.defineProperty(exports, "jsonBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.jsonBodySerializer; } });
|
|
8
|
+
Object.defineProperty(exports, "urlSearchParamsBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.urlSearchParamsBodySerializer; } });
|
|
9
|
+
var params_gen_1 = require("../core/params.gen");
|
|
10
|
+
Object.defineProperty(exports, "buildClientParams", { enumerable: true, get: function () { return params_gen_1.buildClientParams; } });
|
|
11
|
+
var queryKeySerializer_gen_1 = require("../core/queryKeySerializer.gen");
|
|
12
|
+
Object.defineProperty(exports, "serializeQueryKeyValue", { enumerable: true, get: function () { return queryKeySerializer_gen_1.serializeQueryKeyValue; } });
|
|
13
|
+
var client_gen_1 = require("./client.gen");
|
|
14
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_gen_1.createClient; } });
|
|
15
|
+
var utils_gen_1 = require("./utils.gen");
|
|
16
|
+
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return utils_gen_1.createConfig; } });
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Auth } from '../core/auth.gen';
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
3
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
4
|
+
import type { Middleware } from './utils.gen';
|
|
5
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Base URL for all requests made by this client.
|
|
8
|
+
*/
|
|
9
|
+
baseUrl?: T['baseUrl'];
|
|
10
|
+
/**
|
|
11
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
12
|
+
* fetch instance.
|
|
13
|
+
*
|
|
14
|
+
* @default globalThis.fetch
|
|
15
|
+
*/
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
/**
|
|
18
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
19
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
20
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
21
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
22
|
+
*
|
|
23
|
+
* @default 'auto'
|
|
24
|
+
*/
|
|
25
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
26
|
+
/**
|
|
27
|
+
* Throw an error instead of returning it in the response?
|
|
28
|
+
*
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
throwOnError?: T['throwOnError'];
|
|
32
|
+
}
|
|
33
|
+
export interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
34
|
+
throwOnError: ThrowOnError;
|
|
35
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
36
|
+
/**
|
|
37
|
+
* Any body that you want to add to your request.
|
|
38
|
+
*
|
|
39
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
40
|
+
*/
|
|
41
|
+
body?: unknown;
|
|
42
|
+
path?: Record<string, unknown>;
|
|
43
|
+
query?: Record<string, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Security mechanism(s) to use for the request.
|
|
46
|
+
*/
|
|
47
|
+
security?: ReadonlyArray<Auth>;
|
|
48
|
+
url: Url;
|
|
49
|
+
}
|
|
50
|
+
export interface ResolvedRequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, ThrowOnError, Url> {
|
|
51
|
+
serializedBody?: string;
|
|
52
|
+
}
|
|
53
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
|
|
54
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
55
|
+
response: Response;
|
|
56
|
+
}> : Promise<({
|
|
57
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
58
|
+
error: undefined;
|
|
59
|
+
} | {
|
|
60
|
+
data: undefined;
|
|
61
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
62
|
+
}) & {
|
|
63
|
+
response: Response;
|
|
64
|
+
}>;
|
|
65
|
+
export interface ClientOptions {
|
|
66
|
+
baseUrl?: string;
|
|
67
|
+
throwOnError?: boolean;
|
|
68
|
+
}
|
|
69
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
|
|
70
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
71
|
+
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>;
|
|
72
|
+
type BuildUrlFn = <TData extends {
|
|
73
|
+
body?: unknown;
|
|
74
|
+
path?: Record<string, unknown>;
|
|
75
|
+
query?: Record<string, unknown>;
|
|
76
|
+
url: string;
|
|
77
|
+
}>(options: TData & Options<TData>) => string;
|
|
78
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
79
|
+
interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
83
|
+
* and the returned object will become the client's initial configuration.
|
|
84
|
+
*
|
|
85
|
+
* You may want to initialize your client this way instead of calling
|
|
86
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
87
|
+
* to ensure your client always has the correct values.
|
|
88
|
+
*/
|
|
89
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
90
|
+
export interface TDataShape {
|
|
91
|
+
body?: unknown;
|
|
92
|
+
headers?: unknown;
|
|
93
|
+
path?: unknown;
|
|
94
|
+
query?: unknown;
|
|
95
|
+
url: string;
|
|
96
|
+
}
|
|
97
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
98
|
+
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'>);
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { QuerySerializer, 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
|
+
/**
|
|
5
|
+
* Infers parseAs value from provided Content-Type header.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
+
export declare const setAuthParams: ({ security, ...options }: Pick<Required<RequestOptions>, "security"> & Pick<RequestOptions, "auth" | "query"> & {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
export declare const buildUrl: Client['buildUrl'];
|
|
12
|
+
export declare const getUrl: ({ baseUrl, path, query, querySerializer, url: _url, }: {
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
path?: Record<string, unknown>;
|
|
15
|
+
query?: Record<string, unknown>;
|
|
16
|
+
querySerializer: QuerySerializer;
|
|
17
|
+
url: string;
|
|
18
|
+
}) => string;
|
|
19
|
+
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
20
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
21
|
+
type ErrInterceptor<Err, Res, Options> = (error: Err, response: Res, options: Options) => Err | Promise<Err>;
|
|
22
|
+
type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
|
|
23
|
+
type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
|
|
24
|
+
declare class Interceptors<Interceptor> {
|
|
25
|
+
fns: Array<Interceptor | null>;
|
|
26
|
+
clear(): void;
|
|
27
|
+
eject(id: number | Interceptor): void;
|
|
28
|
+
exists(id: number | Interceptor): boolean;
|
|
29
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
30
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
31
|
+
use(fn: Interceptor): number;
|
|
32
|
+
}
|
|
33
|
+
export interface Middleware<Res, Err, Options> {
|
|
34
|
+
error: Interceptors<ErrInterceptor<Err, Res, Options>>;
|
|
35
|
+
request: Interceptors<ReqInterceptor<Options>>;
|
|
36
|
+
response: Interceptors<ResInterceptor<Res, Options>>;
|
|
37
|
+
}
|
|
38
|
+
export declare const createInterceptors: <Res, Err, Options>() => Middleware<Res, Err, Options>;
|
|
39
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
40
|
+
export {};
|