UNPKG

liferay-headless-rest-client

Version:
2 lines (1 loc) 8.05 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},U=(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,G])=>{G!=null&&(Array.isArray(G)?G.forEach((F)=>U(B,X,F)):U(B,X,G))}),B}},b={bodySerializer:(K)=>JSON.stringify(K,(B,X)=>typeof X=="bigint"?X.toString():X)};var m={$body_:"body",$headers_:"headers",$path_:"path",$query_:"query"},l=Object.entries(m);var w=(K)=>{switch(K){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},A=(K)=>{switch(K){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},_=(K)=>{switch(K){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},T=({allowReserved:K,explode:B,name:X,style:G,value:F})=>{if(!B){let Z=(K?F:F.map((J)=>encodeURIComponent(J))).join(A(G));switch(G){case"label":return`.${Z}`;case"matrix":return`;${X}=${Z}`;case"simple":return Z;default:return`${X}=${Z}`}}let H=w(G),E=F.map((Z)=>G==="label"||G==="simple"?K?Z:encodeURIComponent(Z):O({allowReserved:K,name:X,value:Z})).join(H);return G==="label"||G==="matrix"?H+E:E},O=({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)}`},z=({allowReserved:K,explode:B,name:X,style:G,value:F,valueOnly:H})=>{if(F instanceof Date)return H?F.toISOString():`${X}=${F.toISOString()}`;if(G!=="deepObject"&&!B){let J=[];Object.entries(F).forEach(([$,L])=>{J=[...J,$,K?L:encodeURIComponent(L)]});let Y=J.join(",");switch(G){case"form":return`${X}=${Y}`;case"label":return`.${Y}`;case"matrix":return`;${X}=${Y}`;default:return Y}}let E=_(G),Z=Object.entries(F).map(([J,Y])=>O({allowReserved:K,name:G==="deepObject"?`${X}[${J}]`:J,value:Y})).join(E);return G==="label"||G==="matrix"?E+Z:Z},g=/\{[^{}]+\}/g,C=({path:K,url:B})=>{let X=B,G=B.match(g);if(G)for(let F of G){let H=!1,E=F.substring(1,F.length-1),Z="simple";E.endsWith("*")&&(H=!0,E=E.substring(0,E.length-1)),E.startsWith(".")?(E=E.substring(1),Z="label"):E.startsWith(";")&&(E=E.substring(1),Z="matrix");let J=K[E];if(J==null)continue;if(Array.isArray(J)){X=X.replace(F,T({explode:H,name:E,style:Z,value:J}));continue}if(typeof J=="object"){X=X.replace(F,z({explode:H,name:E,style:Z,value:J,valueOnly:!0}));continue}if(Z==="matrix"){X=X.replace(F,`;${O({name:E,value:J})}`);continue}let Y=encodeURIComponent(Z==="label"?`.${J}`:J);X=X.replace(F,Y)}return X},j=({allowReserved:K,array:B,object:X}={})=>(G)=>{let F=[];if(G&&typeof G=="object")for(let H in G){let E=G[H];if(E!=null)if(Array.isArray(E)){let Z=T({allowReserved:K,explode:!0,name:H,style:"form",value:E,...B});Z&&F.push(Z)}else if(typeof E=="object"){let Z=z({allowReserved:K,explode:!0,name:H,style:"deepObject",value:E,...X});Z&&F.push(Z)}else{let Z=O({allowReserved:K,name:H,value:E});Z&&F.push(Z)}}return F.join("&")},d=(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 G=await R(X,B.auth);if(!G)continue;let F=X.name??"Authorization";switch(X.in){case"query":B.query||(B.query={}),B.query[F]=G;break;case"cookie":B.headers.append("Cookie",`${F}=${G}`);break;case"header":default:B.headers.set(F,G);break}return}},W=(K)=>y({baseUrl:K.baseUrl,path:K.path,query:K.query,querySerializer:typeof K.querySerializer=="function"?K.querySerializer:j(K.querySerializer),url:K.url}),y=({baseUrl:K,path:B,query:X,querySerializer:G,url:F})=>{let H=F.startsWith("/")?F:`/${F}`,E=(K??"")+H;B&&(E=C({path:B,url:E}));let Z=X?G(X):"";return Z.startsWith("?")&&(Z=Z.substring(1)),Z&&(E+=`?${Z}`),E},q=(K,B)=>{let X={...K,...B};return X.baseUrl?.endsWith("/")&&(X.baseUrl=X.baseUrl.substring(0,X.baseUrl.length-1)),X.headers=v(K.headers,B.headers),X},v=(...K)=>{let B=new Headers;for(let X of K){if(!X||typeof X!="object")continue;let G=X instanceof Headers?X.entries():Object.entries(X);for(let[F,H]of G)if(H===null)B.delete(F);else if(Array.isArray(H))for(let E of H)B.append(F,E);else H!==void 0&&B.set(F,typeof H=="object"?JSON.stringify(H):H)}return B},P=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 P,request:new P,response:new P}),u=j({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),c={"Content-Type":"application/json"},S=(K={})=>({...b,headers:c,parseAs:"auto",querySerializer:u,...K}),x=(K={})=>{let B=q(S(),K),X=()=>({...B}),G=(E)=>(B=q(B,E),X()),F=h(),H=async(E)=>{let Z={...B,...E,fetch:E.fetch??B.fetch??globalThis.fetch,headers:v(B.headers,E.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 J=W(Z),Y={redirect:"follow",...Z},$=new Request(J,Y);for(let V of F.request._fns)V&&($=await V($,Z));let L=Z.fetch,Q=await L($);for(let V of F.response._fns)V&&(Q=await V(Q,$,Z));let M={request:$,response:Q};if(Q.ok){if(Q.status===204||Q.headers.get("Content-Length")==="0")return Z.responseStyle==="data"?{}:{data:{},...M};let V=(Z.parseAs==="auto"?d(Q.headers.get("Content-Type")):Z.parseAs)??"json";if(V==="stream")return Z.responseStyle==="data"?Q.body:{data:Q.body,...M};let I=await Q[V]();return V==="json"&&(Z.responseValidator&&await Z.responseValidator(I),Z.responseTransformer&&(I=await Z.responseTransformer(I))),Z.responseStyle==="data"?I:{data:I,...M}}let N=await Q.text();try{N=JSON.parse(N)}catch{}let D=N;for(let V of F.error._fns)V&&(D=await V(N,Q,$,Z));if(D=D||{},Z.throwOnError)throw D;return Z.responseStyle==="data"?void 0:{error:D,...M}};return{buildUrl:W,connect:(E)=>H({...E,method:"CONNECT"}),delete:(E)=>H({...E,method:"DELETE"}),get:(E)=>H({...E,method:"GET"}),getConfig:X,head:(E)=>H({...E,method:"HEAD"}),interceptors:F,options:(E)=>H({...E,method:"OPTIONS"}),patch:(E)=>H({...E,method:"PATCH"}),post:(E)=>H({...E,method:"POST"}),put:(E)=>H({...E,method:"PUT"}),request:H,setConfig:G,trace:(E)=>H({...E,method:"TRACE"})}};var k=x(S({baseUrl:"http://localhost:8080"}));var t=(K)=>{return(K.client??k).delete({url:"/o/headless-portal-instances/v1.0/portal-instances/{portalInstanceId}",...K})},i=(K)=>{return(K.client??k).get({url:"/o/headless-portal-instances/v1.0/portal-instances/{portalInstanceId}",...K})},e=(K)=>{return(K.client??k).patch({url:"/o/headless-portal-instances/v1.0/portal-instances/{portalInstanceId}",...K,headers:{"Content-Type":"application/json",...K.headers}})},KK=(K)=>{return(K?.client??k).get({url:"/o/headless-portal-instances/v1.0/portal-instances",...K})},XK=(K)=>{return(K?.client??k).post({url:"/o/headless-portal-instances/v1.0/portal-instances",...K,headers:{"Content-Type":"application/json",...K?.headers}})},ZK=(K)=>{return(K.client??k).put({url:"/o/headless-portal-instances/v1.0/portal-instances/{portalInstanceId}/activate",...K})},BK=(K)=>{return(K.client??k).put({url:"/o/headless-portal-instances/v1.0/portal-instances/{portalInstanceId}/deactivate",...K})};export{BK as putPortalInstanceDeactivate,ZK as putPortalInstanceActivate,XK as postPortalInstance,e as patchPortalInstance,KK as getPortalInstancesPage,i as getPortalInstance,t as deletePortalInstance};