UNPKG

liferay-headless-rest-client

Version:
2 lines (1 loc) 8.02 kB
var R=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},I=(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)=>I(B,X,G)):I(B,X,H))}),B}},_={bodySerializer:(K)=>JSON.stringify(K,(B,X)=>typeof X=="bigint"?X.toString():X)};var x={$body_:"body",$headers_:"headers",$path_:"path",$query_:"query"},l=Object.entries(x);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"&"}},S=({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):Y({allowReserved:K,name:X,value:Z})).join(J);return H==="label"||H==="matrix"?J+F:F},Y=({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)}`},T=({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(([E,O])=>{V=[...V,E,K?O:encodeURIComponent(O)]});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])=>Y({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,S({explode:J,name:F,style:Z,value:V}));continue}if(typeof V=="object"){X=X.replace(G,T({explode:J,name:F,style:Z,value:V,valueOnly:!0}));continue}if(Z==="matrix"){X=X.replace(G,`;${Y({name:F,value:V})}`);continue}let D=encodeURIComponent(Z==="label"?`.${V}`:V);X=X.replace(G,D)}return X},j=({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=S({allowReserved:K,explode:!0,name:J,style:"form",value:F,...B});Z&&G.push(Z)}else if(typeof F=="object"){let Z=T({allowReserved:K,explode:!0,name:J,style:"deepObject",value:F,...X});Z&&G.push(Z)}else{let Z=Y({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"}},d=async({security:K,...B})=>{for(let X of K){let H=await R(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)=>f({baseUrl:K.baseUrl,path:K.path,query:K.query,querySerializer:typeof K.querySerializer=="function"?K.querySerializer:j(K.querySerializer),url:K.url}),f=({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},q=(K,B)=>{let X={...K,...B};return X.baseUrl?.endsWith("/")&&(X.baseUrl=X.baseUrl.substring(0,X.baseUrl.length-1)),X.headers=z(K.headers,B.headers),X},z=(...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},k=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 k,request:new k,response:new k}),u=j({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),c={"Content-Type":"application/json"},v=(K={})=>({..._,headers:c,parseAs:"auto",querySerializer:u,...K}),A=(K={})=>{let B=q(v(),K),X=()=>({...B}),H=(F)=>(B=q(B,F),X()),G=h(),J=async(F)=>{let Z={...B,...F,fetch:F.fetch??B.fetch??globalThis.fetch,headers:z(B.headers,F.headers)};Z.security&&await d({...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},E=new Request(V,D);for(let $ of G.request._fns)$&&(E=await $(E,Z));let O=Z.fetch,W=await O(E);for(let $ of G.response._fns)$&&(W=await $(W,E,Z));let Q={request:E,response:W};if(W.ok){if(W.status===204||W.headers.get("Content-Length")==="0")return Z.responseStyle==="data"?{}:{data:{},...Q};let $=(Z.parseAs==="auto"?y(W.headers.get("Content-Type")):Z.parseAs)??"json";if($==="stream")return Z.responseStyle==="data"?W.body:{data:W.body,...Q};let M=await W[$]();return $==="json"&&(Z.responseValidator&&await Z.responseValidator(M),Z.responseTransformer&&(M=await Z.responseTransformer(M))),Z.responseStyle==="data"?M:{data:M,...Q}}let U=await W.text();try{U=JSON.parse(U)}catch{}let L=U;for(let $ of G.error._fns)$&&(L=await $(U,W,E,Z));if(L=L||{},Z.throwOnError)throw L;return Z.responseStyle==="data"?void 0:{error:L,...Q}};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 N=A(v());var t=(K)=>{return(K.client??N).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??N).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??N).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??N).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};