@swapkit/helpers
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -10,8 +10,8 @@ { | ||
"devDependencies": { | ||
"@swapkit/toolbox-cosmos": "1.0.11", | ||
"@swapkit/toolbox-evm": "1.1.5", | ||
"@swapkit/toolbox-solana": "1.0.10", | ||
"@swapkit/toolbox-radix": "1.0.10", | ||
"@swapkit/toolbox-substrate": "1.1.5", | ||
"@swapkit/toolbox-utxo": "1.0.10" | ||
"@swapkit/toolbox-cosmos": "1.0.12", | ||
"@swapkit/toolbox-evm": "1.1.6", | ||
"@swapkit/toolbox-solana": "1.0.11", | ||
"@swapkit/toolbox-radix": "1.0.11", | ||
"@swapkit/toolbox-substrate": "1.1.6", | ||
"@swapkit/toolbox-utxo": "1.0.11" | ||
}, | ||
@@ -41,3 +41,3 @@ "files": [ | ||
"types": "./src/index.ts", | ||
"version": "1.2.1" | ||
"version": "1.2.2" | ||
} |
@@ -1,2 +0,2 @@ | ||
type Options = { | ||
type Options = Parameters<typeof fetch>[1] & { | ||
headers?: Record<string, string>; | ||
@@ -7,3 +7,4 @@ apiKey?: string; | ||
responseHandler?: (response: NotWorth) => NotWorth; | ||
[key: string]: NotWorth; | ||
searchParams?: Record<string, string>; | ||
json?: unknown; | ||
}; | ||
@@ -22,10 +23,26 @@ | ||
async function fetchWithConfig(url: string, options: Options = {}) { | ||
async function fetchWithConfig(url: string, options: Options) { | ||
const { apiKey, ...config } = clientConfig; | ||
const headers = { ...defaultRequestHeaders, ...config.headers, ...options.headers }; | ||
const { searchParams, json, body } = options; | ||
const headers = { ...defaultRequestHeaders, ...config.headers, ...options.headers } as Record< | ||
string, | ||
string | ||
>; | ||
const bodyToSend = json ? JSON.stringify(json) : body; | ||
const urlInstance = new URL(url); | ||
if (searchParams) { | ||
urlInstance.search = new URLSearchParams(searchParams).toString(); | ||
} | ||
if (apiKey) headers["x-api-key"] = apiKey; | ||
try { | ||
const response = await fetch(url, { ...config, ...options, headers }); | ||
const response = await fetch(urlInstance.toString(), { | ||
...config, | ||
...options, | ||
body: bodyToSend, | ||
headers, | ||
}); | ||
const body = await response.json(); | ||
@@ -32,0 +49,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
445833
5538