From ee1682386454fad3fb78e168e33e14e3078375a6 Mon Sep 17 00:00:00 2001 From: Syd Amir Date: Wed, 29 May 2024 09:15:45 +0330 Subject: [PATCH] :adhesive_bandage: add setHeader fn for lesanApi --- src/types/mod.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/types/mod.ts b/src/types/mod.ts index a1f4d1d..ab0a09d 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -90,6 +90,15 @@ export const lesanApi = ( ...settings, }; + const setHeaders = (headers: Record) => { + setting.headers = { + ...setting.headers, + ...headers, + }; + }; + + const getSetting = () => setting; + const send = async < TService extends keyof ReqType, TModel extends keyof ReqType[TService], @@ -106,9 +115,9 @@ export const lesanApi = ( }; }, additionalHeaders?: Record) => { const req = await fetch(URL, { - ...setting, + ...getSetting(), headers: { - ...setting.headers, + ...getSetting().headers, ...additionalHeaders, }, body: JSON.stringify(body), @@ -117,7 +126,7 @@ export const lesanApi = ( return await req.json(); }; - return { send }; + return { send, setHeaders }; };\n `;