@flaqai/network 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mergeRequestData as e}from"./merge-request-data.mjs";import{appendQueryString as t}from"./query-string.mjs";function n(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function r(e){return typeof e==`string`?{endpoint:e}:{endpoint:e[0],data:e[1]}}function i(i){return async(a,o={})=>{let{body:s,enableAuthorization:c=i.defaultEnableAuthorization??!1,headers:l,method:u,...d}=o;if(s!==void 0&&!n(s))throw TypeError(`@flaqai/network supports only plain JSON object request bodies`);let[f,p,m,h,g]=await Promise.all([i.getBaseUrl(),i.getBaseRequestData?.(),i.getAuthorization?.(),i.getContentLanguage?.(),i.getDefaultHeaders?.()]),{endpoint:_,data:v}=r(a),y=u?.toUpperCase()??`GET`,b=new Headers(g);h!==void 0&&b.set(`Content-Language`,h),new Headers(l).forEach((e,t)=>{b.set(t,e)}),c&&m!==void 0&&!b.has(`authorization`)&&b.set(`authorization`,m);let
|
|
1
|
+
import{mergeRequestData as e}from"./merge-request-data.mjs";import{appendQueryString as t}from"./query-string.mjs";function n(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function r(e){return typeof e==`string`?{endpoint:e}:{endpoint:e[0],data:e[1]}}function i(i){return async(a,o={})=>{let{body:s,enableAuthorization:c=i.defaultEnableAuthorization??!1,headers:l,method:u,...d}=o;if(s!==void 0&&!n(s))throw TypeError(`@flaqai/network supports only plain JSON object request bodies`);let[f,p,m,h,g]=await Promise.all([i.getBaseUrl(),i.getBaseRequestData?.(),i.getAuthorization?.(),i.getContentLanguage?.(),i.getDefaultHeaders?.()]),{endpoint:_,data:v}=r(a),y=u?.toUpperCase()??`GET`,b=new Headers(g),x=y===`GET`||y===`HEAD`||y===`DELETE`&&v!==void 0&&s===void 0;h!==void 0&&b.set(`Content-Language`,h),new Headers(l).forEach((e,t)=>{b.set(t,e)}),c&&m!==void 0&&!b.has(`authorization`)&&b.set(`authorization`,m);let S=`${f}${_}`,C;if(x)S=t(S,e(p,v,s));else{let t=e(p,v,s);Object.keys(t).length>0&&(C=JSON.stringify(t))}return await(await(i.fetch??globalThis.fetch)(S,{...d,headers:b,method:y,...C===void 0?{}:{body:C}})).json()}}export{i as createJsonFetch};
|