@swapkit/api
Advanced tools
Comparing version 1.0.0-rc.42 to 1.0.0-rc.43
@@ -26,4 +26,4 @@ var C = /* @__PURE__ */ ((t) => (t.Arbitrum = "ARB", t.Avalanche = "AVAX", t.Binance = "BNB", t.BinanceSmartChain = "BSC", t.Bitcoin = "BTC", t.BitcoinCash = "BCH", t.Cosmos = "GAIA", t.Dash = "DASH", t.Dogecoin = "DOGE", t.Ethereum = "ETH", t.Kujira = "KUJI", t.Litecoin = "LTC", t.Maya = "MAYA", t.Optimism = "OP", t.Polkadot = "DOT", t.Chainflip = "FLIP", t.Polygon = "MATIC", t.THORChain = "THOR", t))(C || {}), b = /* @__PURE__ */ ((t) => (t.Arbitrum = "42161", t.ArbitrumHex = "0xa4b1", t.Avalanche = "43114", t.AvalancheHex = "0xa86a", t.Binance = "Binance-Chain-Tigris", t.BinanceSmartChain = "56", t.BinanceSmartChainHex = "0x38", t.Bitcoin = "bitcoin", t.BitcoinCash = "bitcoincash", t.Chainflip = "chainflip", t.Cosmos = "cosmoshub-4", t.Dash = "dash", t.Dogecoin = "dogecoin", t.Kujira = "kaiyo-1", t.Ethereum = "1", t.EthereumHex = "0x1", t.Litecoin = "litecoin", t.Maya = "mayachain-mainnet-v1", t.MayaStagenet = "mayachain-stagenet-v1", t.Optimism = "10", t.OptimismHex = "0xa", t.Polkadot = "polkadot", t.Polygon = "137", t.PolygonHex = "0x89", t.THORChain = "thorchain-mainnet-v1", t.THORChainStagenet = "thorchain-stagenet-v2", t))(b || {}), O = /* @__PURE__ */ ((t) => (t.Arbitrum = "https://arb1.arbitrum.io/rpc", t.Avalanche = "https://node-router.thorswap.net/avalanche-c", t.Binance = "", t.BinanceSmartChain = "https://bsc-dataseed.binance.org", t.Bitcoin = "https://node-router.thorswap.net/bitcoin", t.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", t.Chainflip = "wss://mainnet-archive.chainflip.io", t.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", t.Dash = "https://node-router.thorswap.net/dash", t.Dogecoin = "https://node-router.thorswap.net/dogecoin", t.Ethereum = "https://node-router.thorswap.net/ethereum", t.Kujira = "https://rpc-kujira.synergynodes.com/", t.Litecoin = "https://node-router.thorswap.net/litecoin", t.Maya = "https://tendermint.mayachain.info", t.MayaStagenet = "https://stagenet.tendermint.mayachain.info", t.Optimism = "https://mainnet.optimism.io", t.Polkadot = "wss://rpc.polkadot.io", t.Polygon = "https://polygon-rpc.com", t.THORChain = "https://rpc.thorswap.net", t.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", t))(O || {}), d = /* @__PURE__ */ ((t) => (t.Cosmos = "https://node-router.thorswap.net/cosmos/rest", t.Kujira = "https://lcd-kujira.synergynodes.com/", t.MayanodeMainnet = "https://mayanode.mayachain.info", t.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", t.ThornodeMainnet = "https://thornode.thorswap.net", t.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", t.ThorswapApi = "https://api.thorswap.net", t.ThorswapStatic = "https://static.thorswap.net", t))(d || {}); | ||
constructor(e, s, r) { | ||
const o = e.status || e.status === 0 ? e.status : "", n = e.statusText || "", a = `${o} ${n}`.trim(), i = a ? `status code ${a}` : "an unknown error"; | ||
super(`Request failed with ${i}`), Object.defineProperty(this, "response", { | ||
const o = e.status || e.status === 0 ? e.status : "", n = e.statusText || "", i = `${o} ${n}`.trim(), a = i ? `status code ${i}` : "an unknown error"; | ||
super(`Request failed with ${a}`), Object.defineProperty(this, "response", { | ||
enumerable: !0, | ||
@@ -63,4 +63,4 @@ configurable: !0, | ||
const s = new globalThis.Headers(t), r = e instanceof globalThis.Headers, o = new globalThis.Headers(e); | ||
for (const [n, a] of o.entries()) | ||
r && a === "undefined" || a === void 0 ? s.delete(n) : s.set(n, a); | ||
for (const [n, i] of o.entries()) | ||
r && i === "undefined" || i === void 0 ? s.delete(n) : s.set(n, i); | ||
return s; | ||
@@ -122,3 +122,3 @@ }, P = (...t) => { | ||
duplex: !0 | ||
}, G = (t) => k.includes(t) ? t.toUpperCase() : t, M = ["get", "put", "head", "delete", "options", "trace"], X = [408, 413, 429, 500, 502, 503, 504], W = [413, 429, 503], w = { | ||
}, G = (t) => k.includes(t) ? t.toUpperCase() : t, M = ["get", "put", "head", "delete", "options", "trace"], X = [408, 413, 429, 500, 502, 503, 504], W = [413, 429, 503], y = { | ||
limit: 2, | ||
@@ -134,3 +134,3 @@ methods: M, | ||
return { | ||
...w, | ||
...y, | ||
limit: t | ||
@@ -143,3 +143,3 @@ }; | ||
return { | ||
...w, | ||
...y, | ||
...t, | ||
@@ -151,7 +151,7 @@ afterStatusCodes: W | ||
return new Promise((o, n) => { | ||
const a = setTimeout(() => { | ||
const i = setTimeout(() => { | ||
s && s.abort(), n(new N(t)); | ||
}, r.timeout); | ||
r.fetch(t, e).then(o).catch(n).then(() => { | ||
clearTimeout(a); | ||
clearTimeout(i); | ||
}); | ||
@@ -183,9 +183,9 @@ }); | ||
await Promise.resolve(); | ||
let i = await r._fetch(); | ||
let a = await r._fetch(); | ||
for (const h of r._options.hooks.afterResponse) { | ||
const u = await h(r.request, r._options, r._decorateResponse(i.clone())); | ||
u instanceof globalThis.Response && (i = u); | ||
const u = await h(r.request, r._options, r._decorateResponse(a.clone())); | ||
u instanceof globalThis.Response && (a = u); | ||
} | ||
if (r._decorateResponse(i), !i.ok && r._options.throwHttpErrors) { | ||
let h = new g(i, r.request, r._options); | ||
if (r._decorateResponse(a), !a.ok && r._options.throwHttpErrors) { | ||
let h = new g(a, r.request, r._options); | ||
for (const u of r._options.hooks.beforeError) | ||
@@ -200,11 +200,11 @@ h = await u(h); | ||
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing."); | ||
return r._stream(i.clone(), r._options.onDownloadProgress); | ||
return r._stream(a.clone(), r._options.onDownloadProgress); | ||
} | ||
return i; | ||
}, a = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(o) : o(); | ||
for (const [i, h] of Object.entries(V)) | ||
a[i] = async () => { | ||
return a; | ||
}, i = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(o) : o(); | ||
for (const [a, h] of Object.entries(V)) | ||
i[a] = async () => { | ||
r.request.headers.set("accept", r.request.headers.get("accept") || h); | ||
const p = (await a).clone(); | ||
if (i === "json") { | ||
const p = (await i).clone(); | ||
if (a === "json") { | ||
if (p.status === 204 || (await p.clone().arrayBuffer()).byteLength === 0) | ||
@@ -215,9 +215,9 @@ return ""; | ||
} | ||
return p[i](); | ||
return p[a](); | ||
}; | ||
return a; | ||
return i; | ||
} | ||
// eslint-disable-next-line complexity | ||
constructor(e, s = {}) { | ||
if (Object.defineProperty(this, "request", { | ||
Object.defineProperty(this, "request", { | ||
enumerable: !0, | ||
@@ -247,5 +247,6 @@ configurable: !0, | ||
value: void 0 | ||
}), this._input = e, this._options = { | ||
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208 | ||
credentials: this._input.credentials || "same-origin", | ||
}), this._input = e; | ||
const r = "credentials" in Request.prototype; | ||
if (this._options = { | ||
credentials: r ? this._input.credentials : void 0, | ||
...s, | ||
@@ -275,5 +276,5 @@ headers: D(this._input.headers, s.headers), | ||
if (this.abortController = new globalThis.AbortController(), this._options.signal) { | ||
const r = this._options.signal; | ||
const o = this._options.signal; | ||
this._options.signal.addEventListener("abort", () => { | ||
this.abortController.abort(r.reason); | ||
this.abortController.abort(o.reason); | ||
}); | ||
@@ -284,4 +285,4 @@ } | ||
if (q && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) { | ||
const o = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), n = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, o); | ||
(x && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(n, { ...this.request }), this._options); | ||
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n); | ||
(x && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(i, { ...this.request }), this._options); | ||
} | ||
@@ -354,6 +355,6 @@ this._options.json !== void 0 && (this._options.body = JSON.stringify(this._options.json), this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json"), this.request = new globalThis.Request(this.request, { body: this._options.body })); | ||
async start(n) { | ||
const a = e.body.getReader(); | ||
const i = e.body.getReader(); | ||
s && s({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array()); | ||
async function i() { | ||
const { done: h, value: u } = await a.read(); | ||
async function a() { | ||
const { done: h, value: u } = await i.read(); | ||
if (h) { | ||
@@ -368,5 +369,5 @@ n.close(); | ||
} | ||
n.enqueue(u), await i(); | ||
n.enqueue(u), await a(); | ||
} | ||
await i(); | ||
await a(); | ||
} | ||
@@ -396,3 +397,3 @@ }), { | ||
Thorname: `${d.ThorswapApi}/thorname` | ||
}, B = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, y = () => f || (f = I.create({ headers: B }), f), st = ({ apiKey: t, ...e }) => { | ||
}, B = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, w = () => f || (f = I.create({ headers: B }), f), st = ({ apiKey: t, ...e }) => { | ||
f = I.create({ | ||
@@ -403,7 +404,7 @@ ...e, | ||
}, l = { | ||
get: (t, e) => y().get(t, e).json(), | ||
post: (t, e) => y().post(t, e).json() | ||
get: (t, e) => w().get(t, e).json(), | ||
post: (t, e) => w().post(t, e).json() | ||
}, Q = ({ tokens: t, ...e }) => { | ||
const s = new URLSearchParams(), r = t.filter( | ||
(o, n, a) => a.findIndex((i) => i === o) === n | ||
(o, n, i) => i.findIndex((a) => a === o) === n | ||
); | ||
@@ -410,0 +411,0 @@ for (const o of r) |
{ | ||
"author": "swapkit-oss", | ||
"dependencies": { | ||
"ky": "1.2.0", | ||
"@swapkit/types": "1.0.0-rc.41" | ||
"ky": "1.2.2", | ||
"@swapkit/types": "1.0.0-rc.42" | ||
}, | ||
@@ -10,3 +10,3 @@ "description": "SwapKit Lib swapkit-api", | ||
"@vitest/coverage-istanbul": "1.3.1", | ||
"vite": "5.1.3", | ||
"vite": "5.1.6", | ||
"vitest": "1.3.1" | ||
@@ -37,3 +37,3 @@ }, | ||
"types": "./dist/index.d.ts", | ||
"version": "1.0.0-rc.42", | ||
"version": "1.0.0-rc.43", | ||
"scripts": { | ||
@@ -40,0 +40,0 @@ "build": "vite build", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1321
249367
+ Added@swapkit/types@1.0.0-rc.42(transitive)
+ Addedky@1.2.2(transitive)
- Removed@swapkit/types@1.0.0-rc.41(transitive)
- Removedky@1.2.0(transitive)
Updated@swapkit/types@1.0.0-rc.42
Updatedky@1.2.2