@mesadev/rest 0.3.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/LICENSE +201 -0
- package/README.md +28 -0
- package/dist/client/client.gen.d.ts +2 -0
- package/dist/client/client.gen.js +234 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +6 -0
- package/dist/client/types.gen.d.ts +117 -0
- package/dist/client/types.gen.js +2 -0
- package/dist/client/utils.gen.d.ts +33 -0
- package/dist/client/utils.gen.js +228 -0
- package/dist/client.gen.d.ts +12 -0
- package/dist/client.gen.js +3 -0
- package/dist/core/auth.gen.d.ts +18 -0
- package/dist/core/auth.gen.js +14 -0
- package/dist/core/bodySerializer.gen.d.ts +25 -0
- package/dist/core/bodySerializer.gen.js +57 -0
- package/dist/core/params.gen.d.ts +43 -0
- package/dist/core/params.gen.js +100 -0
- package/dist/core/pathSerializer.gen.d.ts +33 -0
- package/dist/core/pathSerializer.gen.js +106 -0
- package/dist/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/core/queryKeySerializer.gen.js +92 -0
- package/dist/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/core/serverSentEvents.gen.js +133 -0
- package/dist/core/types.gen.d.ts +78 -0
- package/dist/core/types.gen.js +2 -0
- package/dist/core/utils.gen.d.ts +19 -0
- package/dist/core/utils.gen.js +87 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/sdk.gen.d.ts +135 -0
- package/dist/sdk.gen.js +226 -0
- package/dist/types.gen.d.ts +2547 -0
- package/dist/types.gen.js +2 -0
- package/package.json +37 -0
- package/src/client/client.gen.ts +288 -0
- package/src/client/index.ts +25 -0
- package/src/client/types.gen.ts +214 -0
- package/src/client/utils.gen.ts +316 -0
- package/src/client.gen.ts +16 -0
- package/src/core/auth.gen.ts +41 -0
- package/src/core/bodySerializer.gen.ts +84 -0
- package/src/core/params.gen.ts +169 -0
- package/src/core/pathSerializer.gen.ts +171 -0
- package/src/core/queryKeySerializer.gen.ts +117 -0
- package/src/core/serverSentEvents.gen.ts +243 -0
- package/src/core/types.gen.ts +104 -0
- package/src/core/utils.gen.ts +140 -0
- package/src/index.ts +4 -0
- package/src/sdk.gen.ts +263 -0
- package/src/types.gen.ts +2649 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @mesadev/rest
|
|
2
|
+
|
|
3
|
+
TypeScript REST SDK for the [Mesa](https://mesa.dev) API.
|
|
4
|
+
|
|
5
|
+
Generated from the OpenAPI specification using [@hey-api/openapi-ts](https://heyapi.dev).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mesadev/rest
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from "@mesadev/rest";
|
|
17
|
+
|
|
18
|
+
const client = createClient({
|
|
19
|
+
baseUrl: "https://depot.mesa.dev/api/v1",
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: "Bearer YOUR_API_KEY",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
Apache-2.0
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
3
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
4
|
+
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from './utils.gen';
|
|
5
|
+
export const createClient = (config = {}) => {
|
|
6
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
7
|
+
const getConfig = () => ({ ..._config });
|
|
8
|
+
const setConfig = (config) => {
|
|
9
|
+
_config = mergeConfigs(_config, config);
|
|
10
|
+
return getConfig();
|
|
11
|
+
};
|
|
12
|
+
const interceptors = createInterceptors();
|
|
13
|
+
const beforeRequest = async (options) => {
|
|
14
|
+
const opts = {
|
|
15
|
+
..._config,
|
|
16
|
+
...options,
|
|
17
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
19
|
+
serializedBody: undefined,
|
|
20
|
+
};
|
|
21
|
+
if (opts.security) {
|
|
22
|
+
await setAuthParams({
|
|
23
|
+
...opts,
|
|
24
|
+
security: opts.security,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (opts.requestValidator) {
|
|
28
|
+
await opts.requestValidator(opts);
|
|
29
|
+
}
|
|
30
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
31
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
32
|
+
}
|
|
33
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
34
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
35
|
+
opts.headers.delete('Content-Type');
|
|
36
|
+
}
|
|
37
|
+
const url = buildUrl(opts);
|
|
38
|
+
return { opts, url };
|
|
39
|
+
};
|
|
40
|
+
const request = async (options) => {
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
const { opts, url } = await beforeRequest(options);
|
|
43
|
+
const requestInit = {
|
|
44
|
+
redirect: 'follow',
|
|
45
|
+
...opts,
|
|
46
|
+
body: getValidRequestBody(opts),
|
|
47
|
+
};
|
|
48
|
+
let request = new Request(url, requestInit);
|
|
49
|
+
for (const fn of interceptors.request.fns) {
|
|
50
|
+
if (fn) {
|
|
51
|
+
request = await fn(request, opts);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
55
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
56
|
+
const _fetch = opts.fetch;
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await _fetch(request);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
63
|
+
let finalError = error;
|
|
64
|
+
for (const fn of interceptors.error.fns) {
|
|
65
|
+
if (fn) {
|
|
66
|
+
finalError = (await fn(error, undefined, request, opts));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finalError = finalError || {};
|
|
70
|
+
if (opts.throwOnError) {
|
|
71
|
+
throw finalError;
|
|
72
|
+
}
|
|
73
|
+
// Return error response
|
|
74
|
+
return opts.responseStyle === 'data'
|
|
75
|
+
? undefined
|
|
76
|
+
: {
|
|
77
|
+
error: finalError,
|
|
78
|
+
request,
|
|
79
|
+
response: undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
for (const fn of interceptors.response.fns) {
|
|
83
|
+
if (fn) {
|
|
84
|
+
response = await fn(response, request, opts);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const result = {
|
|
88
|
+
request,
|
|
89
|
+
response,
|
|
90
|
+
};
|
|
91
|
+
if (response.ok) {
|
|
92
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
93
|
+
? getParseAs(response.headers.get('Content-Type'))
|
|
94
|
+
: opts.parseAs) ?? 'json';
|
|
95
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
96
|
+
let emptyData;
|
|
97
|
+
switch (parseAs) {
|
|
98
|
+
case 'arrayBuffer':
|
|
99
|
+
case 'blob':
|
|
100
|
+
case 'text':
|
|
101
|
+
emptyData = await response[parseAs]();
|
|
102
|
+
break;
|
|
103
|
+
case 'formData':
|
|
104
|
+
emptyData = new FormData();
|
|
105
|
+
break;
|
|
106
|
+
case 'stream':
|
|
107
|
+
emptyData = response.body;
|
|
108
|
+
break;
|
|
109
|
+
case 'json':
|
|
110
|
+
default:
|
|
111
|
+
emptyData = {};
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return opts.responseStyle === 'data'
|
|
115
|
+
? emptyData
|
|
116
|
+
: {
|
|
117
|
+
data: emptyData,
|
|
118
|
+
...result,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
let data;
|
|
122
|
+
switch (parseAs) {
|
|
123
|
+
case 'arrayBuffer':
|
|
124
|
+
case 'blob':
|
|
125
|
+
case 'formData':
|
|
126
|
+
case 'text':
|
|
127
|
+
data = await response[parseAs]();
|
|
128
|
+
break;
|
|
129
|
+
case 'json': {
|
|
130
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
131
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
132
|
+
const text = await response.text();
|
|
133
|
+
data = text ? JSON.parse(text) : {};
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'stream':
|
|
137
|
+
return opts.responseStyle === 'data'
|
|
138
|
+
? response.body
|
|
139
|
+
: {
|
|
140
|
+
data: response.body,
|
|
141
|
+
...result,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (parseAs === 'json') {
|
|
145
|
+
if (opts.responseValidator) {
|
|
146
|
+
await opts.responseValidator(data);
|
|
147
|
+
}
|
|
148
|
+
if (opts.responseTransformer) {
|
|
149
|
+
data = await opts.responseTransformer(data);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return opts.responseStyle === 'data'
|
|
153
|
+
? data
|
|
154
|
+
: {
|
|
155
|
+
data,
|
|
156
|
+
...result,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const textError = await response.text();
|
|
160
|
+
let jsonError;
|
|
161
|
+
try {
|
|
162
|
+
jsonError = JSON.parse(textError);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// noop
|
|
166
|
+
}
|
|
167
|
+
const error = jsonError ?? textError;
|
|
168
|
+
let finalError = error;
|
|
169
|
+
for (const fn of interceptors.error.fns) {
|
|
170
|
+
if (fn) {
|
|
171
|
+
finalError = (await fn(error, response, request, opts));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
finalError = finalError || {};
|
|
175
|
+
if (opts.throwOnError) {
|
|
176
|
+
throw finalError;
|
|
177
|
+
}
|
|
178
|
+
// TODO: we probably want to return error and improve types
|
|
179
|
+
return opts.responseStyle === 'data'
|
|
180
|
+
? undefined
|
|
181
|
+
: {
|
|
182
|
+
error: finalError,
|
|
183
|
+
...result,
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
187
|
+
const makeSseFn = (method) => async (options) => {
|
|
188
|
+
const { opts, url } = await beforeRequest(options);
|
|
189
|
+
return createSseClient({
|
|
190
|
+
...opts,
|
|
191
|
+
body: opts.body,
|
|
192
|
+
headers: opts.headers,
|
|
193
|
+
method,
|
|
194
|
+
onRequest: async (url, init) => {
|
|
195
|
+
let request = new Request(url, init);
|
|
196
|
+
for (const fn of interceptors.request.fns) {
|
|
197
|
+
if (fn) {
|
|
198
|
+
request = await fn(request, opts);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return request;
|
|
202
|
+
},
|
|
203
|
+
serializedBody: getValidRequestBody(opts),
|
|
204
|
+
url,
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
buildUrl,
|
|
209
|
+
connect: makeMethodFn('CONNECT'),
|
|
210
|
+
delete: makeMethodFn('DELETE'),
|
|
211
|
+
get: makeMethodFn('GET'),
|
|
212
|
+
getConfig,
|
|
213
|
+
head: makeMethodFn('HEAD'),
|
|
214
|
+
interceptors,
|
|
215
|
+
options: makeMethodFn('OPTIONS'),
|
|
216
|
+
patch: makeMethodFn('PATCH'),
|
|
217
|
+
post: makeMethodFn('POST'),
|
|
218
|
+
put: makeMethodFn('PUT'),
|
|
219
|
+
request,
|
|
220
|
+
setConfig,
|
|
221
|
+
sse: {
|
|
222
|
+
connect: makeSseFn('CONNECT'),
|
|
223
|
+
delete: makeSseFn('DELETE'),
|
|
224
|
+
get: makeSseFn('GET'),
|
|
225
|
+
head: makeSseFn('HEAD'),
|
|
226
|
+
options: makeSseFn('OPTIONS'),
|
|
227
|
+
patch: makeSseFn('PATCH'),
|
|
228
|
+
post: makeSseFn('POST'),
|
|
229
|
+
put: makeSseFn('PUT'),
|
|
230
|
+
trace: makeSseFn('TRACE'),
|
|
231
|
+
},
|
|
232
|
+
trace: makeMethodFn('TRACE'),
|
|
233
|
+
};
|
|
234
|
+
};
|
|
@@ -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, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
8
|
+
export { createConfig, mergeHeaders } 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, mergeHeaders } from './utils.gen';
|
|
@@ -0,0 +1,117 @@
|
|
|
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 type ResponseStyle = 'data' | 'fields';
|
|
6
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for all requests made by this client.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: T['baseUrl'];
|
|
11
|
+
/**
|
|
12
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
13
|
+
* fetch instance.
|
|
14
|
+
*
|
|
15
|
+
* @default globalThis.fetch
|
|
16
|
+
*/
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/**
|
|
19
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
20
|
+
* options won't have any effect.
|
|
21
|
+
*
|
|
22
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
23
|
+
*/
|
|
24
|
+
next?: never;
|
|
25
|
+
/**
|
|
26
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
27
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
28
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
29
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
30
|
+
*
|
|
31
|
+
* @default 'auto'
|
|
32
|
+
*/
|
|
33
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
34
|
+
/**
|
|
35
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
36
|
+
*
|
|
37
|
+
* @default 'fields'
|
|
38
|
+
*/
|
|
39
|
+
responseStyle?: ResponseStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Throw an error instead of returning it in the response?
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
throwOnError?: T['throwOnError'];
|
|
46
|
+
}
|
|
47
|
+
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
|
+
responseStyle: TResponseStyle;
|
|
49
|
+
throwOnError: ThrowOnError;
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
51
|
+
/**
|
|
52
|
+
* Any body that you want to add to your request.
|
|
53
|
+
*
|
|
54
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
55
|
+
*/
|
|
56
|
+
body?: unknown;
|
|
57
|
+
path?: Record<string, unknown>;
|
|
58
|
+
query?: Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Security mechanism(s) to use for the request.
|
|
61
|
+
*/
|
|
62
|
+
security?: ReadonlyArray<Auth>;
|
|
63
|
+
url: Url;
|
|
64
|
+
}
|
|
65
|
+
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
serializedBody?: string;
|
|
67
|
+
}
|
|
68
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
69
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
70
|
+
request: Request;
|
|
71
|
+
response: Response;
|
|
72
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
73
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
74
|
+
error: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
data: undefined;
|
|
77
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
78
|
+
}) & {
|
|
79
|
+
request: Request;
|
|
80
|
+
response: Response;
|
|
81
|
+
}>;
|
|
82
|
+
export interface ClientOptions {
|
|
83
|
+
baseUrl?: string;
|
|
84
|
+
responseStyle?: ResponseStyle;
|
|
85
|
+
throwOnError?: boolean;
|
|
86
|
+
}
|
|
87
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
89
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
90
|
+
type BuildUrlFn = <TData extends {
|
|
91
|
+
body?: unknown;
|
|
92
|
+
path?: Record<string, unknown>;
|
|
93
|
+
query?: Record<string, unknown>;
|
|
94
|
+
url: string;
|
|
95
|
+
}>(options: TData & Options<TData>) => string;
|
|
96
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
97
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
101
|
+
* and the returned object will become the client's initial configuration.
|
|
102
|
+
*
|
|
103
|
+
* You may want to initialize your client this way instead of calling
|
|
104
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
105
|
+
* to ensure your client always has the correct values.
|
|
106
|
+
*/
|
|
107
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T> | Promise<Config<Required<ClientOptions> & T>>;
|
|
108
|
+
export interface TDataShape {
|
|
109
|
+
body?: unknown;
|
|
110
|
+
headers?: unknown;
|
|
111
|
+
path?: unknown;
|
|
112
|
+
query?: unknown;
|
|
113
|
+
url: string;
|
|
114
|
+
}
|
|
115
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
116
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
/**
|
|
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 mergeConfigs: (a: Config, b: Config) => Config;
|
|
13
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
14
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>;
|
|
15
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
16
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
17
|
+
declare class Interceptors<Interceptor> {
|
|
18
|
+
fns: Array<Interceptor | null>;
|
|
19
|
+
clear(): void;
|
|
20
|
+
eject(id: number | Interceptor): void;
|
|
21
|
+
exists(id: number | Interceptor): boolean;
|
|
22
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
23
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
24
|
+
use(fn: Interceptor): number;
|
|
25
|
+
}
|
|
26
|
+
export interface Middleware<Req, Res, Err, Options> {
|
|
27
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
28
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
29
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
30
|
+
}
|
|
31
|
+
export declare const createInterceptors: <Req, Res, Err, Options>() => Middleware<Req, Res, Err, Options>;
|
|
32
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
33
|
+
export {};
|