Skip to content
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@velora-dex/sdk",
"version": "9.3.1",
"version": "9.3.2-dev.1",
"main": "dist/index.js",
"module": "dist/sdk.esm.js",
"typings": "dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/fetchers/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ export const constructFetcher =
// adding apiKey to headers if it's provided
const headers = extra?.apiKey
? {
...extra.headers,
'X-API-KEY': extra.apiKey,
...rest.headers,
...requestParams?.headers,
}
: { ...rest.headers, ...requestParams?.headers };
: { ...extra?.headers, ...rest.headers, ...requestParams?.headers };

const allParams = { ...rest, ...requestParams, headers };

Expand Down
13 changes: 11 additions & 2 deletions src/helpers/fetchers/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { FetcherError } from '../misc';
type Fetch = typeof fetch;

export const constructFetcher =
(fetch: Fetch, extra?: ExtraFetchParams): FetcherFunction =>
(
fetch: Fetch,
extra?: ExtraFetchParams & { keepalive?: boolean }
): FetcherFunction =>
async (params) => {
try {
const { url, method, requestParams } = params;
Expand All @@ -25,8 +28,13 @@ export const constructFetcher =

// all headers combined
const headers =
POSTheaders || apiHeaders || params.headers || requestParams?.headers
POSTheaders ||
apiHeaders ||
params.headers ||
requestParams?.headers ||
extra?.headers
? {
...extra?.headers,
...apiHeaders,
...POSTheaders,
...params.headers,
Expand All @@ -39,6 +47,7 @@ export const constructFetcher =
body,
...requestParams,
headers,
keepalive: extra?.keepalive,
});

const data = await response.json();
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import type {
OptimalRate,
OptionalRate,
APIVersion,
ExtraFetchParams,
} from './types';

import type {
Expand Down Expand Up @@ -420,6 +421,7 @@ export type {
FetcherErrorInterface,
APIVersion,
SwapSideUnion,
ExtraFetchParams,
};

export { SDKConfig, constructPartialSDK } from './sdk/partial';
Expand Down
2 changes: 1 addition & 1 deletion src/methods/swap/rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type RateQueryParams = {
destTokenDexTransferFee?: string;

/**
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 5.
* @description To specify the protocol version. **Values:** 5 or 6.2 **Default**: 6.2.
*/
version?: number | string;

Expand Down
3 changes: 2 additions & 1 deletion src/sdk/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,12 @@ const constructFetcher = (options: FetcherOptions): FetcherFunction => {
// adding apiKey to headers if it's provided
const headers = options?.apiKey
? {
...options.headers,
'X-API-KEY': options.apiKey,
...params.headers,
...params.requestParams?.headers,
}
: params.headers;
: { ...options.headers, ...params.headers };

return options.fetcher({ ...params, headers });
};
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export type FetcherFunction = <T, URL extends string = string>(
) => Promise<T>;

// authentication or some other params required in `fetcher`
export type ExtraFetchParams = { apiKey?: string };
export type ExtraFetchParams = {
apiKey?: string;
headers?: Record<string, string>;
};

export interface ConstructFetchInput extends ConstructBaseInput {
fetcher: FetcherFunction;
Expand Down
Loading