@biconomy/sdk
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
38 lines • 1.36 kB
JavaScript
/**
* Creates a new Http client instance
* @param params - Configuration parameters for the client
* @returns A base Http client instance that can be extended with additional functionality
*/
export const createHttpClient = (url) => {
const request = async (requesParams) => {
const { path, method = "POST", body, params } = requesParams;
const urlParams = params ? `?${new URLSearchParams(params)}` : "";
const result = await fetch(`${url}/${path}${urlParams}`, {
method,
headers: {
"Content-Type": "application/json"
},
...(body ? { body: JSON.stringify(body) } : {})
});
if (!result.ok) {
console.log({ result });
throw new Error(result.statusText);
}
return (await result.json());
};
const client = {
request
};
function extend(base) {
return (extendFn) => {
const extended = extendFn(base);
for (const key in client)
delete extended[key];
const combined = { ...base, ...extended };
return Object.assign(combined, { extend: extend(combined) });
};
}
return Object.assign(client, { extend: extend(client) });
};
export default createHttpClient;
//# sourceMappingURL=createHttpClient.js.map