UNPKG

liferay-headless-rest-client

Version:
2 lines (1 loc) 8.02 kB
var A=async(K,B)=>{let X=typeof B=="function"?await B(K):B;if(X)return K.scheme==="bearer"?`Bearer ${X}`:K.scheme==="basic"?`Basic ${btoa(X)}`:X},N=(K,B,X)=>{typeof X=="string"||X instanceof Blob?K.append(B,X):K.append(B,JSON.stringify(X))};var p={bodySerializer:(K)=>{let B=new FormData;return Object.entries(K).forEach(([X,H])=>{H!=null&&(Array.isArray(H)?H.forEach((G)=>N(B,X,G)):N(B,X,H))}),B}},R={bodySerializer:(K)=>JSON.stringify(K,(B,X)=>typeof X=="bigint"?X.toString():X)};var _={$body_:"body",$headers_:"headers",$path_:"path",$query_:"query"},l=Object.entries(_);var w=(K)=>{switch(K){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},b=(K)=>{switch(K){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},C=(K)=>{switch(K){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},q=({allowReserved:K,explode:B,name:X,style:H,value:G})=>{if(!B){let Z=(K?G:G.map((V)=>encodeURIComponent(V))).join(b(H));switch(H){case"label":return`.${Z}`;case"matrix":return`;${X}=${Z}`;case"simple":return Z;default:return`${X}=${Z}`}}let J=w(H),F=G.map((Z)=>H==="label"||H==="simple"?K?Z:encodeURIComponent(Z):v({allowReserved:K,name:X,value:Z})).join(J);return H==="label"||H==="matrix"?J+F:F},v=({allowReserved:K,name:B,value:X})=>{if(X==null)return"";if(typeof X=="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${B}=${K?X:encodeURIComponent(X)}`},x=({allowReserved:K,explode:B,name:X,style:H,value:G,valueOnly:J})=>{if(G instanceof Date)return J?G.toISOString():`${X}=${G.toISOString()}`;if(H!=="deepObject"&&!B){let V=[];Object.entries(G).forEach(([L,U])=>{V=[...V,L,K?U:encodeURIComponent(U)]});let D=V.join(",");switch(H){case"form":return`${X}=${D}`;case"label":return`.${D}`;case"matrix":return`;${X}=${D}`;default:return D}}let F=C(H),Z=Object.entries(G).map(([V,D])=>v({allowReserved:K,name:H==="deepObject"?`${X}[${V}]`:V,value:D})).join(F);return H==="label"||H==="matrix"?F+Z:Z},g=/\{[^{}]+\}/g,m=({path:K,url:B})=>{let X=B,H=B.match(g);if(H)for(let G of H){let J=!1,F=G.substring(1,G.length-1),Z="simple";F.endsWith("*")&&(J=!0,F=F.substring(0,F.length-1)),F.startsWith(".")?(F=F.substring(1),Z="label"):F.startsWith(";")&&(F=F.substring(1),Z="matrix");let V=K[F];if(V==null)continue;if(Array.isArray(V)){X=X.replace(G,q({explode:J,name:F,style:Z,value:V}));continue}if(typeof V=="object"){X=X.replace(G,x({explode:J,name:F,style:Z,value:V,valueOnly:!0}));continue}if(Z==="matrix"){X=X.replace(G,`;${v({name:F,value:V})}`);continue}let D=encodeURIComponent(Z==="label"?`.${V}`:V);X=X.replace(G,D)}return X},S=({allowReserved:K,array:B,object:X}={})=>(H)=>{let G=[];if(H&&typeof H=="object")for(let J in H){let F=H[J];if(F!=null)if(Array.isArray(F)){let Z=q({allowReserved:K,explode:!0,name:J,style:"form",value:F,...B});Z&&G.push(Z)}else if(typeof F=="object"){let Z=x({allowReserved:K,explode:!0,name:J,style:"deepObject",value:F,...X});Z&&G.push(Z)}else{let Z=v({allowReserved:K,name:J,value:F});Z&&G.push(Z)}}return G.join("&")},y=(K)=>{if(!K)return"stream";let B=K.split(";")[0]?.trim();if(B){if(B.startsWith("application/json")||B.endsWith("+json"))return"json";if(B==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some((X)=>B.startsWith(X)))return"blob";if(B.startsWith("text/"))return"text"}},f=async({security:K,...B})=>{for(let X of K){let H=await A(X,B.auth);if(!H)continue;let G=X.name??"Authorization";switch(X.in){case"query":B.query||(B.query={}),B.query[G]=H;break;case"cookie":B.headers.append("Cookie",`${G}=${H}`);break;case"header":default:B.headers.set(G,H);break}return}},P=(K)=>d({baseUrl:K.baseUrl,path:K.path,query:K.query,querySerializer:typeof K.querySerializer=="function"?K.querySerializer:S(K.querySerializer),url:K.url}),d=({baseUrl:K,path:B,query:X,querySerializer:H,url:G})=>{let J=G.startsWith("/")?G:`/${G}`,F=(K??"")+J;B&&(F=m({path:B,url:F}));let Z=X?H(X):"";return Z.startsWith("?")&&(Z=Z.substring(1)),Z&&(F+=`?${Z}`),F},T=(K,B)=>{let X={...K,...B};return X.baseUrl?.endsWith("/")&&(X.baseUrl=X.baseUrl.substring(0,X.baseUrl.length-1)),X.headers=j(K.headers,B.headers),X},j=(...K)=>{let B=new Headers;for(let X of K){if(!X||typeof X!="object")continue;let H=X instanceof Headers?X.entries():Object.entries(X);for(let[G,J]of H)if(J===null)B.delete(G);else if(Array.isArray(J))for(let F of J)B.append(G,F);else J!==void 0&&B.set(G,typeof J=="object"?JSON.stringify(J):J)}return B},E=class{_fns;constructor(){this._fns=[]}clear(){this._fns=[]}getInterceptorIndex(K){return typeof K=="number"?this._fns[K]?K:-1:this._fns.indexOf(K)}exists(K){let B=this.getInterceptorIndex(K);return!!this._fns[B]}eject(K){let B=this.getInterceptorIndex(K);this._fns[B]&&(this._fns[B]=null)}update(K,B){let X=this.getInterceptorIndex(K);return this._fns[X]?(this._fns[X]=B,K):!1}use(K){return this._fns=[...this._fns,K],this._fns.length-1}},h=()=>({error:new E,request:new E,response:new E}),u=S({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),c={"Content-Type":"application/json"},I=(K={})=>({...R,headers:c,parseAs:"auto",querySerializer:u,...K}),z=(K={})=>{let B=T(I(),K),X=()=>({...B}),H=(F)=>(B=T(B,F),X()),G=h(),J=async(F)=>{let Z={...B,...F,fetch:F.fetch??B.fetch??globalThis.fetch,headers:j(B.headers,F.headers)};Z.security&&await f({...Z,security:Z.security}),Z.body&&Z.bodySerializer&&(Z.body=Z.bodySerializer(Z.body)),(Z.body===void 0||Z.body==="")&&Z.headers.delete("Content-Type");let V=P(Z),D={redirect:"follow",...Z},L=new Request(V,D);for(let $ of G.request._fns)$&&(L=await $(L,Z));let U=Z.fetch,W=await U(L);for(let $ of G.response._fns)$&&(W=await $(W,L,Z));let Y={request:L,response:W};if(W.ok){if(W.status===204||W.headers.get("Content-Length")==="0")return Z.responseStyle==="data"?{}:{data:{},...Y};let $=(Z.parseAs==="auto"?y(W.headers.get("Content-Type")):Z.parseAs)??"json";if($==="stream")return Z.responseStyle==="data"?W.body:{data:W.body,...Y};let O=await W[$]();return $==="json"&&(Z.responseValidator&&await Z.responseValidator(O),Z.responseTransformer&&(O=await Z.responseTransformer(O))),Z.responseStyle==="data"?O:{data:O,...Y}}let k=await W.text();try{k=JSON.parse(k)}catch{}let M=k;for(let $ of G.error._fns)$&&(M=await $(k,W,L,Z));if(M=M||{},Z.throwOnError)throw M;return Z.responseStyle==="data"?void 0:{error:M,...Y}};return{buildUrl:P,connect:(F)=>J({...F,method:"CONNECT"}),delete:(F)=>J({...F,method:"DELETE"}),get:(F)=>J({...F,method:"GET"}),getConfig:X,head:(F)=>J({...F,method:"HEAD"}),interceptors:G,options:(F)=>J({...F,method:"OPTIONS"}),patch:(F)=>J({...F,method:"PATCH"}),post:(F)=>J({...F,method:"POST"}),put:(F)=>J({...F,method:"PUT"}),request:J,setConfig:H,trace:(F)=>J({...F,method:"TRACE"})}};var Q=z(I());var t=(K)=>{return(K.client??Q).post({security:[{name:"X-VTEX-API-AppKey",type:"apiKey"},{name:"X-VTEX-API-AppToken",type:"apiKey"},{name:"VtexIdclientAutCookie",type:"apiKey"}],url:"/api/audience-manager/pvt/audience",...K})},i=(K)=>{return(K.client??Q).delete({security:[{name:"X-VTEX-API-AppKey",type:"apiKey"},{name:"X-VTEX-API-AppToken",type:"apiKey"},{name:"VtexIdclientAutCookie",type:"apiKey"}],url:"/api/price-table-mapper/pvt/mapping/{audienceId}",...K})},e=(K)=>{return(K.client??Q).get({security:[{name:"X-VTEX-API-AppKey",type:"apiKey"},{name:"X-VTEX-API-AppToken",type:"apiKey"},{name:"VtexIdclientAutCookie",type:"apiKey"}],url:"/api/price-table-mapper/pvt/mapping/{audienceId}",...K})},KK=(K)=>{return(K.client??Q).put({security:[{name:"X-VTEX-API-AppKey",type:"apiKey"},{name:"X-VTEX-API-AppToken",type:"apiKey"},{name:"VtexIdclientAutCookie",type:"apiKey"}],url:"/api/price-table-mapper/pvt/mapping/{audienceId}",...K})};export{KK as putApiPriceTableMapperPvtMappingByAudienceId,t as postApiAudienceManagerPvtAudience,e as getApiPriceTableMapperPvtMappingByAudienceId,i as deleteApiPriceTableMapperPvtMappingByAudienceId};