+'use strict';var L=require('axios');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var L__default=/*#__PURE__*/_interopDefault(L);var w=async(t,r)=>{let e=typeof r=="function"?await r(t):r;if(e)return t.scheme==="bearer"?`Bearer ${e}`:t.scheme==="basic"?`Basic ${btoa(e)}`:e},O=(t,r,e)=>{typeof e=="string"||e instanceof Blob?t.append(r,e):t.append(r,JSON.stringify(e));},z=(t,r,e)=>{typeof e=="string"?t.append(r,e):t.append(r,JSON.stringify(e));},R={bodySerializer:t=>{let r=new FormData;return Object.entries(t).forEach(([e,n])=>{n!=null&&(Array.isArray(n)?n.forEach(i=>O(r,e,i)):O(r,e,n));}),r}},$={bodySerializer:t=>JSON.stringify(t,(r,e)=>typeof e=="bigint"?e.toString():e)},q={bodySerializer:t=>{let r=new URLSearchParams;return Object.entries(t).forEach(([e,n])=>{n!=null&&(Array.isArray(n)?n.forEach(i=>z(r,e,i)):z(r,e,n));}),r.toString()}},v={$body_:"body",$headers_:"headers",$path_:"path",$query_:"query"},P=Object.entries(v),A=(t,r)=>{r||(r=new Map);for(let e of t)"in"in e?e.key&&r.set(e.key,{in:e.in,map:e.map}):e.args&&A(e.args,r);return r},T=t=>{for(let[r,e]of Object.entries(t))e&&typeof e=="object"&&!Object.keys(e).length&&delete t[r];},E=(t,r)=>{let e={body:{},headers:{},path:{},query:{}},n=A(r),i;for(let[l,o]of t.entries())if(r[l]&&(i=r[l]),!!i)if("in"in i)if(i.key){let s=n.get(i.key),a=s.map||i.key;e[s.in][a]=o;}else e.body=o;else for(let[s,a]of Object.entries(o??{})){let u=n.get(s);if(u){let d=u.map||s;e[u.in][d]=a;}else {let d=P.find(([c])=>s.startsWith(c));if(d){let[c,f]=d;e[f][s.slice(c.length)]=a;}else for(let[c,f]of Object.entries(i.allowExtra??{}))if(f){e[c][s]=a;break}}}return T(e),e},U=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},D=t=>{switch(t){case "form":return ",";case "pipeDelimited":return "|";case "spaceDelimited":return "%20";default:return ","}},H=t=>{switch(t){case "label":return ".";case "matrix":return ";";case "simple":return ",";default:return "&"}},m=({allowReserved:t,explode:r,name:e,style:n,value:i})=>{if(!r){let s=(t?i:i.map(a=>encodeURIComponent(a))).join(D(n));switch(n){case "label":return `.${s}`;case "matrix":return `;${e}=${s}`;case "simple":return s;default:return `${e}=${s}`}}let l=U(n),o=i.map(s=>n==="label"||n==="simple"?t?s:encodeURIComponent(s):p({allowReserved:t,name:e,value:s})).join(l);return n==="label"||n==="matrix"?l+o:o},p=({allowReserved:t,name:r,value:e})=>{if(e==null)return "";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${t?e:encodeURIComponent(e)}`},g=({allowReserved:t,explode:r,name:e,style:n,value:i,valueOnly:l})=>{if(i instanceof Date)return l?i.toISOString():`${e}=${i.toISOString()}`;if(n!=="deepObject"&&!r){let a=[];Object.entries(i).forEach(([d,c])=>{a=[...a,d,t?c:encodeURIComponent(c)];});let u=a.join(",");switch(n){case "form":return `${e}=${u}`;case "label":return `.${u}`;case "matrix":return `;${e}=${u}`;default:return u}}let o=H(n),s=Object.entries(i).map(([a,u])=>p({allowReserved:t,name:n==="deepObject"?`${e}[${a}]`:a,value:u})).join(o);return n==="label"||n==="matrix"?o+s:s};var B=/\{[^{}]+\}/g,I=({path:t,url:r})=>{let e=r,n=r.match(B);if(n)for(let i of n){let l=false,o=i.substring(1,i.length-1),s="simple";o.endsWith("*")&&(l=true,o=o.substring(0,o.length-1)),o.startsWith(".")?(o=o.substring(1),s="label"):o.startsWith(";")&&(o=o.substring(1),s="matrix");let a=t[o];if(a==null)continue;if(Array.isArray(a)){e=e.replace(i,m({explode:l,name:o,style:s,value:a}));continue}if(typeof a=="object"){e=e.replace(i,g({explode:l,name:o,style:s,value:a,valueOnly:true}));continue}if(s==="matrix"){e=e.replace(i,`;${p({name:o,value:a})}`);continue}let u=encodeURIComponent(s==="label"?`.${a}`:a);e=e.replace(i,u);}return e},W=({allowReserved:t,array:r,object:e}={})=>i=>{let l=[];if(i&&typeof i=="object")for(let o in i){let s=i[o];if(s!=null)if(Array.isArray(s)){let a=m({allowReserved:t,explode:true,name:o,style:"form",value:s,...r});a&&l.push(a);}else if(typeof s=="object"){let a=g({allowReserved:t,explode:true,name:o,style:"deepObject",value:s,...e});a&&l.push(a);}else {let a=p({allowReserved:t,name:o,value:s});a&&l.push(a);}}return l.join("&")},j=async({security:t,...r})=>{for(let e of t){let n=await w(e,r.auth);if(!n)continue;let i=e.name??"Authorization";switch(e.in){case "query":r.query||(r.query={}),r.query[i]=n;break;case "cookie":{let l=`${i}=${n}`;"Cookie"in r.headers&&r.headers.Cookie?r.headers.Cookie=`${r.headers.Cookie}; ${l}`:r.headers.Cookie=l;break}case "header":default:r.headers[i]=n;break}return}},b=t=>N({path:t.path,query:t.paramsSerializer?void 0:t.query,querySerializer:typeof t.querySerializer=="function"?t.querySerializer:W(t.querySerializer),url:t.url}),N=({path:t,query:r,querySerializer:e,url:n})=>{let l=n.startsWith("/")?n:`/${n}`;t&&(l=I({path:t,url:l}));let o=r?e(r):"";return o.startsWith("?")&&(o=o.substring(1)),o&&(l+=`?${o}`),l},C=(t,r)=>{let e={...t,...r};return e.headers=h(t.headers,r.headers),e},Q=["common","delete","get","head","patch","post","put"],h=(...t)=>{let r={};for(let e of t){if(!e||typeof e!="object")continue;let n=Object.entries(e);for(let[i,l]of n)if(Q.includes(i)&&typeof l=="object")r[i]={...r[i],...l};else if(l===null)delete r[i];else if(Array.isArray(l))for(let o of l)r[i]=[...r[i]??[],o];else l!==void 0&&(r[i]=typeof l=="object"?JSON.stringify(l):l);}return r},S=(t={})=>({...t});var _=(t={})=>{let r=C(S(),t),{auth:e,...n}=r,i=L__default.default.create(n),l=()=>({...r}),o=a=>(r=C(r,a),i.defaults={...i.defaults,...r,headers:h(i.defaults.headers,r.headers)},l()),s=async a=>{let u={...r,...a,axios:a.axios??r.axios??i,headers:h(r.headers,a.headers)};u.security&&await j({...u,security:u.security}),u.body&&u.bodySerializer&&(u.body=u.bodySerializer(u.body));let d=b(u);try{let c=u.axios,{auth:f,...k}=u,x=await c({...k,baseURL:u.baseURL,data:u.body,headers:u.headers,params:u.paramsSerializer?u.query:void 0,url:d}),{data:y}=x;return u.responseType==="json"&&(u.responseValidator&&await u.responseValidator(y),u.responseTransformer&&(y=await u.responseTransformer(y))),{...x,data:y??{}}}catch(c){let f=c;if(u.throwOnError)throw f;return f.error=f.response?.data??{},f}};return {buildUrl:b,delete:a=>s({...a,method:"DELETE"}),get:a=>s({...a,method:"GET"}),getConfig:l,head:a=>s({...a,method:"HEAD"}),instance:i,options:a=>s({...a,method:"OPTIONS"}),patch:a=>s({...a,method:"PATCH"}),post:a=>s({...a,method:"POST"}),put:a=>s({...a,method:"PUT"}),request:s,setConfig:o}};exports.buildClientParams=E;exports.createClient=_;exports.createConfig=S;exports.formDataBodySerializer=R;exports.jsonBodySerializer=$;exports.urlSearchParamsBodySerializer=q;//# sourceMappingURL=index.cjs.map
0 commit comments