Skip to content

Commit 1387337

Browse files
authored
[SDK] Feature: update hey-api version to 0.76.0 (#7431)
1 parent a2b737e commit 1387337

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5584
-460
lines changed

.changeset/little-items-allow.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"thirdweb": minor
3+
"@thirdweb-dev/insight": minor
4+
"@thirdweb-dev/engine": minor
5+
"@thirdweb-dev/nebula": minor
6+
---
7+
8+
update hey-api version to 0.76.0

packages/engine/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
"dist/*",
2828
"src/*"
2929
],
30-
"dependencies": {
31-
"@hey-api/client-fetch": "0.10.0"
32-
},
3330
"devDependencies": {
3431
"@biomejs/biome": "2.0.4",
35-
"@hey-api/openapi-ts": "0.72.1",
32+
"@hey-api/openapi-ts": "0.76.0",
3633
"rimraf": "6.0.1",
3734
"tslib": "^2.8.1"
3835
},

packages/engine/src/client/client.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createClient,
66
createConfig,
77
type ClientOptions as DefaultClientOptions,
8-
} from "@hey-api/client-fetch";
8+
} from "./client/index.js";
99
import type { ClientOptions } from "./types.gen.js";
1010

1111
/**
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import type { Client, Config, RequestOptions } from "./types.js";
2+
import {
3+
buildUrl,
4+
createConfig,
5+
createInterceptors,
6+
getParseAs,
7+
mergeConfigs,
8+
mergeHeaders,
9+
setAuthParams,
10+
} from "./utils.js";
11+
12+
type ReqInit = Omit<RequestInit, "body" | "headers"> & {
13+
body?: any;
14+
headers: ReturnType<typeof mergeHeaders>;
15+
};
16+
17+
export const createClient = (config: Config = {}): Client => {
18+
let _config = mergeConfigs(createConfig(), config);
19+
20+
const getConfig = (): Config => ({ ..._config });
21+
22+
const setConfig = (config: Config): Config => {
23+
_config = mergeConfigs(_config, config);
24+
return getConfig();
25+
};
26+
27+
const interceptors = createInterceptors<
28+
Request,
29+
Response,
30+
unknown,
31+
RequestOptions
32+
>();
33+
34+
const request: Client["request"] = async (options) => {
35+
const opts = {
36+
..._config,
37+
...options,
38+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
39+
headers: mergeHeaders(_config.headers, options.headers),
40+
};
41+
42+
if (opts.security) {
43+
await setAuthParams({
44+
...opts,
45+
security: opts.security,
46+
});
47+
}
48+
49+
if (opts.body && opts.bodySerializer) {
50+
opts.body = opts.bodySerializer(opts.body);
51+
}
52+
53+
// remove Content-Type header if body is empty to avoid sending invalid requests
54+
if (opts.body === undefined || opts.body === "") {
55+
opts.headers.delete("Content-Type");
56+
}
57+
58+
const url = buildUrl(opts);
59+
const requestInit: ReqInit = {
60+
redirect: "follow",
61+
...opts,
62+
};
63+
64+
let request = new Request(url, requestInit);
65+
66+
for (const fn of interceptors.request._fns) {
67+
if (fn) {
68+
request = await fn(request, opts);
69+
}
70+
}
71+
72+
// fetch must be assigned here, otherwise it would throw the error:
73+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
74+
const _fetch = opts.fetch!;
75+
let response = await _fetch(request);
76+
77+
for (const fn of interceptors.response._fns) {
78+
if (fn) {
79+
response = await fn(response, request, opts);
80+
}
81+
}
82+
83+
const result = {
84+
request,
85+
response,
86+
};
87+
88+
if (response.ok) {
89+
if (
90+
response.status === 204 ||
91+
response.headers.get("Content-Length") === "0"
92+
) {
93+
return opts.responseStyle === "data"
94+
? {}
95+
: {
96+
data: {},
97+
...result,
98+
};
99+
}
100+
101+
const parseAs =
102+
(opts.parseAs === "auto"
103+
? getParseAs(response.headers.get("Content-Type"))
104+
: opts.parseAs) ?? "json";
105+
106+
let data: any;
107+
switch (parseAs) {
108+
case "arrayBuffer":
109+
case "blob":
110+
case "formData":
111+
case "json":
112+
case "text":
113+
data = await response[parseAs]();
114+
break;
115+
case "stream":
116+
return opts.responseStyle === "data"
117+
? response.body
118+
: {
119+
data: response.body,
120+
...result,
121+
};
122+
}
123+
124+
if (parseAs === "json") {
125+
if (opts.responseValidator) {
126+
await opts.responseValidator(data);
127+
}
128+
129+
if (opts.responseTransformer) {
130+
data = await opts.responseTransformer(data);
131+
}
132+
}
133+
134+
return opts.responseStyle === "data"
135+
? data
136+
: {
137+
data,
138+
...result,
139+
};
140+
}
141+
142+
let error = await response.text();
143+
144+
try {
145+
error = JSON.parse(error);
146+
} catch {
147+
// noop
148+
}
149+
150+
let finalError = error;
151+
152+
for (const fn of interceptors.error._fns) {
153+
if (fn) {
154+
finalError = (await fn(error, response, request, opts)) as string;
155+
}
156+
}
157+
158+
finalError = finalError || ({} as string);
159+
160+
if (opts.throwOnError) {
161+
throw finalError;
162+
}
163+
164+
// TODO: we probably want to return error and improve types
165+
return opts.responseStyle === "data"
166+
? undefined
167+
: {
168+
error: finalError,
169+
...result,
170+
};
171+
};
172+
173+
return {
174+
buildUrl,
175+
connect: (options) => request({ ...options, method: "CONNECT" }),
176+
delete: (options) => request({ ...options, method: "DELETE" }),
177+
get: (options) => request({ ...options, method: "GET" }),
178+
getConfig,
179+
head: (options) => request({ ...options, method: "HEAD" }),
180+
interceptors,
181+
options: (options) => request({ ...options, method: "OPTIONS" }),
182+
patch: (options) => request({ ...options, method: "PATCH" }),
183+
post: (options) => request({ ...options, method: "POST" }),
184+
put: (options) => request({ ...options, method: "PUT" }),
185+
request,
186+
setConfig,
187+
trace: (options) => request({ ...options, method: "TRACE" }),
188+
};
189+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export type { Auth } from "../core/auth.js";
2+
export type { QuerySerializerOptions } from "../core/bodySerializer.js";
3+
export {
4+
formDataBodySerializer,
5+
jsonBodySerializer,
6+
urlSearchParamsBodySerializer,
7+
} from "../core/bodySerializer.js";
8+
export { buildClientParams } from "../core/params.js";
9+
export { createClient } from "./client.js";
10+
export type {
11+
Client,
12+
ClientOptions,
13+
Config,
14+
CreateClientConfig,
15+
Options,
16+
OptionsLegacyParser,
17+
RequestOptions,
18+
RequestResult,
19+
ResponseStyle,
20+
TDataShape,
21+
} from "./types.js";
22+
export { createConfig, mergeHeaders } from "./utils.js";

0 commit comments

Comments
 (0)