-
Notifications
You must be signed in to change notification settings - Fork 559
[SDK] Feature: update hey-api version to 0.76.0 #7431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0399623
feat: update hey-api to 0.76.0 in @thirdweb-dev/nebula.
PaoloRollo 401a159
feat: update hey-api to 0.76.0 in @thirdweb-dev/insight and @thirdweb…
PaoloRollo 83dc83b
fix: lint fix + check chain_id type and cast it.
PaoloRollo 52b336a
feat: add changeset file.
PaoloRollo a48d1cc
fix: update pnpm-lock file.
PaoloRollo 36de8f3
fix: removed loop dependency.
PaoloRollo ede4083
fix: add number infer.
PaoloRollo 79e18f9
fix: lint.
PaoloRollo 047043d
fix: test size limit.
PaoloRollo 5ec35e1
feat: merged main.
PaoloRollo 74e1f14
[SDK] Feature: update hey-api version to 0.76.0 (#7431)
PaoloRollo d574ea2
fix: update nebula SDK with latest changes.
PaoloRollo 58be2d6
fix: update.
PaoloRollo a036969
fix: lint.
PaoloRollo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"thirdweb": minor | ||
"@thirdweb-dev/insight": minor | ||
"@thirdweb-dev/engine": minor | ||
"@thirdweb-dev/nebula": minor | ||
--- | ||
|
||
update hey-api version to 0.76.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
import type { Client, Config, RequestOptions } from "./types.js"; | ||
import { | ||
buildUrl, | ||
createConfig, | ||
createInterceptors, | ||
getParseAs, | ||
mergeConfigs, | ||
mergeHeaders, | ||
setAuthParams, | ||
} from "./utils.js"; | ||
|
||
type ReqInit = Omit<RequestInit, "body" | "headers"> & { | ||
body?: any; | ||
headers: ReturnType<typeof mergeHeaders>; | ||
}; | ||
|
||
export const createClient = (config: Config = {}): Client => { | ||
let _config = mergeConfigs(createConfig(), config); | ||
|
||
const getConfig = (): Config => ({ ..._config }); | ||
|
||
const setConfig = (config: Config): Config => { | ||
_config = mergeConfigs(_config, config); | ||
return getConfig(); | ||
}; | ||
|
||
const interceptors = createInterceptors< | ||
Request, | ||
Response, | ||
unknown, | ||
RequestOptions | ||
>(); | ||
|
||
const request: Client["request"] = async (options) => { | ||
const opts = { | ||
..._config, | ||
...options, | ||
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch, | ||
headers: mergeHeaders(_config.headers, options.headers), | ||
}; | ||
|
||
if (opts.security) { | ||
await setAuthParams({ | ||
...opts, | ||
security: opts.security, | ||
}); | ||
} | ||
|
||
if (opts.body && opts.bodySerializer) { | ||
opts.body = opts.bodySerializer(opts.body); | ||
} | ||
|
||
// remove Content-Type header if body is empty to avoid sending invalid requests | ||
if (opts.body === undefined || opts.body === "") { | ||
opts.headers.delete("Content-Type"); | ||
} | ||
|
||
const url = buildUrl(opts); | ||
const requestInit: ReqInit = { | ||
redirect: "follow", | ||
...opts, | ||
}; | ||
|
||
let request = new Request(url, requestInit); | ||
|
||
for (const fn of interceptors.request._fns) { | ||
if (fn) { | ||
request = await fn(request, opts); | ||
} | ||
} | ||
|
||
// fetch must be assigned here, otherwise it would throw the error: | ||
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation | ||
const _fetch = opts.fetch!; | ||
let response = await _fetch(request); | ||
|
||
for (const fn of interceptors.response._fns) { | ||
if (fn) { | ||
response = await fn(response, request, opts); | ||
} | ||
} | ||
|
||
const result = { | ||
request, | ||
response, | ||
}; | ||
|
||
if (response.ok) { | ||
if ( | ||
response.status === 204 || | ||
response.headers.get("Content-Length") === "0" | ||
) { | ||
return opts.responseStyle === "data" | ||
? {} | ||
: { | ||
data: {}, | ||
...result, | ||
}; | ||
} | ||
|
||
const parseAs = | ||
(opts.parseAs === "auto" | ||
? getParseAs(response.headers.get("Content-Type")) | ||
: opts.parseAs) ?? "json"; | ||
|
||
let data: any; | ||
switch (parseAs) { | ||
case "arrayBuffer": | ||
case "blob": | ||
case "formData": | ||
case "json": | ||
case "text": | ||
data = await response[parseAs](); | ||
break; | ||
case "stream": | ||
return opts.responseStyle === "data" | ||
? response.body | ||
: { | ||
data: response.body, | ||
...result, | ||
}; | ||
} | ||
|
||
if (parseAs === "json") { | ||
if (opts.responseValidator) { | ||
await opts.responseValidator(data); | ||
} | ||
|
||
if (opts.responseTransformer) { | ||
data = await opts.responseTransformer(data); | ||
} | ||
} | ||
|
||
return opts.responseStyle === "data" | ||
? data | ||
: { | ||
data, | ||
...result, | ||
}; | ||
} | ||
|
||
let error = await response.text(); | ||
|
||
try { | ||
error = JSON.parse(error); | ||
} catch { | ||
// noop | ||
} | ||
|
||
let finalError = error; | ||
|
||
for (const fn of interceptors.error._fns) { | ||
if (fn) { | ||
finalError = (await fn(error, response, request, opts)) as string; | ||
} | ||
} | ||
|
||
finalError = finalError || ({} as string); | ||
|
||
if (opts.throwOnError) { | ||
throw finalError; | ||
} | ||
|
||
// TODO: we probably want to return error and improve types | ||
return opts.responseStyle === "data" | ||
? undefined | ||
: { | ||
error: finalError, | ||
...result, | ||
}; | ||
}; | ||
|
||
return { | ||
buildUrl, | ||
connect: (options) => request({ ...options, method: "CONNECT" }), | ||
delete: (options) => request({ ...options, method: "DELETE" }), | ||
get: (options) => request({ ...options, method: "GET" }), | ||
getConfig, | ||
head: (options) => request({ ...options, method: "HEAD" }), | ||
interceptors, | ||
options: (options) => request({ ...options, method: "OPTIONS" }), | ||
patch: (options) => request({ ...options, method: "PATCH" }), | ||
post: (options) => request({ ...options, method: "POST" }), | ||
put: (options) => request({ ...options, method: "PUT" }), | ||
request, | ||
setConfig, | ||
trace: (options) => request({ ...options, method: "TRACE" }), | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export type { Auth } from "../core/auth.js"; | ||
export type { QuerySerializerOptions } from "../core/bodySerializer.js"; | ||
export { | ||
formDataBodySerializer, | ||
jsonBodySerializer, | ||
urlSearchParamsBodySerializer, | ||
} from "../core/bodySerializer.js"; | ||
export { buildClientParams } from "../core/params.js"; | ||
export { createClient } from "./client.js"; | ||
export type { | ||
Client, | ||
ClientOptions, | ||
Config, | ||
CreateClientConfig, | ||
Options, | ||
OptionsLegacyParser, | ||
RequestOptions, | ||
RequestResult, | ||
ResponseStyle, | ||
TDataShape, | ||
} from "./types.js"; | ||
export { createConfig, mergeHeaders } from "./utils.js"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type casting issue with error fallback.
The code casts an empty object as a string, which is incorrect and could lead to runtime type errors.
Apply this diff to fix the type casting:
Alternatively, if you need to preserve object errors:
📝 Committable suggestion
🤖 Prompt for AI Agents