liferay-headless-rest-client
Version:
A collection of Headless Clients used in Liferay Portal
2 lines (1 loc) • 14.7 kB
JavaScript
var z=async(F,V)=>{let G=typeof V=="function"?await V(F):V;if(G)return F.scheme==="bearer"?`Bearer ${G}`:F.scheme==="basic"?`Basic ${btoa(G)}`:G},O=(F,V,G)=>{typeof G=="string"||G instanceof Blob?F.append(V,G):F.append(V,JSON.stringify(G))};var h={bodySerializer:(F)=>{let V=new FormData;return Object.entries(F).forEach(([G,B])=>{B!=null&&(Array.isArray(B)?B.forEach((k)=>O(V,G,k)):O(V,G,B))}),V}},m={bodySerializer:(F)=>JSON.stringify(F,(V,G)=>typeof G=="bigint"?G.toString():G)};var w=(F)=>{switch(F){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},b=(F)=>{switch(F){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},f=(F)=>{switch(F){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},U=({allowReserved:F,explode:V,name:G,style:B,value:k})=>{if(!V){let K=(F?k:k.map((H)=>encodeURIComponent(H))).join(b(B));switch(B){case"label":return`.${K}`;case"matrix":return`;${G}=${K}`;case"simple":return K;default:return`${G}=${K}`}}let E=w(B),X=k.map((K)=>B==="label"||B==="simple"?F?K:encodeURIComponent(K):D({allowReserved:F,name:G,value:K})).join(E);return B==="label"||B==="matrix"?E+X:X},D=({allowReserved:F,name:V,value:G})=>{if(G==null)return"";if(typeof G=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${V}=${F?G:encodeURIComponent(G)}`},v=({allowReserved:F,explode:V,name:G,style:B,value:k})=>{if(k instanceof Date)return`${G}=${k.toISOString()}`;if(B!=="deepObject"&&!V){let K=[];Object.entries(k).forEach(([P,M])=>{K=[...K,P,F?M:encodeURIComponent(M)]});let H=K.join(",");switch(B){case"form":return`${G}=${H}`;case"label":return`.${H}`;case"matrix":return`;${G}=${H}`;default:return H}}let E=f(B),X=Object.entries(k).map(([K,H])=>D({allowReserved:F,name:B==="deepObject"?`${G}[${K}]`:K,value:H})).join(E);return B==="label"||B==="matrix"?E+X:X},g=/\{[^{}]+\}/g,d=({path:F,url:V})=>{let G=V,B=V.match(g);if(B)for(let k of B){let E=!1,X=k.substring(1,k.length-1),K="simple";X.endsWith("*")&&(E=!0,X=X.substring(0,X.length-1)),X.startsWith(".")?(X=X.substring(1),K="label"):X.startsWith(";")&&(X=X.substring(1),K="matrix");let H=F[X];if(H==null)continue;if(Array.isArray(H)){G=G.replace(k,U({explode:E,name:X,style:K,value:H}));continue}if(typeof H=="object"){G=G.replace(k,v({explode:E,name:X,style:K,value:H}));continue}if(K==="matrix"){G=G.replace(k,`;${D({name:X,value:H})}`);continue}let P=encodeURIComponent(K==="label"?`.${H}`:H);G=G.replace(k,P)}return G},R=({allowReserved:F,array:V,object:G}={})=>(B)=>{let k=[];if(B&&typeof B=="object")for(let E in B){let X=B[E];if(X!=null)if(Array.isArray(X)){let K=U({allowReserved:F,explode:!0,name:E,style:"form",value:X,...V});K&&k.push(K)}else if(typeof X=="object"){let K=v({allowReserved:F,explode:!0,name:E,style:"deepObject",value:X,...G});K&&k.push(K)}else{let K=D({allowReserved:F,name:E,value:X});K&&k.push(K)}}return k.join("&")},u=(F)=>{if(!F)return"stream";let V=F.split(";")[0]?.trim();if(V){if(V.startsWith("application/json")||V.endsWith("+json"))return"json";if(V==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some((G)=>V.startsWith(G)))return"blob";if(V.startsWith("text/"))return"text"}},c=async({security:F,...V})=>{for(let G of F){let B=await z(G,V.auth);if(!B)continue;let k=G.name??"Authorization";switch(G.in){case"query":V.query||(V.query={}),V.query[k]=B;break;case"cookie":V.headers.append("Cookie",`${k}=${B}`);break;case"header":default:V.headers.set(k,B);break}return}},S=(F)=>_({baseUrl:F.baseUrl,path:F.path,query:F.query,querySerializer:typeof F.querySerializer=="function"?F.querySerializer:R(F.querySerializer),url:F.url}),_=({baseUrl:F,path:V,query:G,querySerializer:B,url:k})=>{let E=k.startsWith("/")?k:`/${k}`,X=(F??"")+E;V&&(X=d({path:V,url:X}));let K=G?B(G):"";return K.startsWith("?")&&(K=K.substring(1)),K&&(X+=`?${K}`),X},T=(F,V)=>{let G={...F,...V};return G.baseUrl?.endsWith("/")&&(G.baseUrl=G.baseUrl.substring(0,G.baseUrl.length-1)),G.headers=j(F.headers,V.headers),G},j=(...F)=>{let V=new Headers;for(let G of F){if(!G||typeof G!="object")continue;let B=G instanceof Headers?G.entries():Object.entries(G);for(let[k,E]of B)if(E===null)V.delete(k);else if(Array.isArray(E))for(let X of E)V.append(k,X);else E!==void 0&&V.set(k,typeof E=="object"?JSON.stringify(E):E)}return V},I=class{_fns;constructor(){this._fns=[]}clear(){this._fns=[]}getInterceptorIndex(F){return typeof F=="number"?this._fns[F]?F:-1:this._fns.indexOf(F)}exists(F){let V=this.getInterceptorIndex(F);return!!this._fns[V]}eject(F){let V=this.getInterceptorIndex(F);this._fns[V]&&(this._fns[V]=null)}update(F,V){let G=this.getInterceptorIndex(F);return this._fns[G]?(this._fns[G]=V,F):!1}use(F){return this._fns=[...this._fns,F],this._fns.length-1}},A=()=>({error:new I,request:new I,response:new I}),C=R({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),y={"Content-Type":"application/json"},N=(F={})=>({...m,headers:y,parseAs:"auto",querySerializer:C,...F}),q=(F={})=>{let V=T(N(),F),G=()=>({...V}),B=(X)=>(V=T(V,X),G()),k=A(),E=async(X)=>{let K={...V,...X,fetch:X.fetch??V.fetch??globalThis.fetch,headers:j(V.headers,X.headers)};K.security&&await c({...K,security:K.security}),K.body&&K.bodySerializer&&(K.body=K.bodySerializer(K.body)),(K.body===void 0||K.body==="")&&K.headers.delete("Content-Type");let H=S(K),P={redirect:"follow",...K},M=new Request(H,P);for(let L of k.request._fns)L&&(M=await L(M,K));let x=K.fetch,J=await x(M);for(let L of k.response._fns)L&&(J=await L(J,M,K));let Y={request:M,response:J};if(J.ok){if(J.status===204||J.headers.get("Content-Length")==="0")return K.responseStyle==="data"?{}:{data:{},...Y};let L=(K.parseAs==="auto"?u(J.headers.get("Content-Type")):K.parseAs)??"json";if(L==="stream")return K.responseStyle==="data"?J.body:{data:J.body,...Y};let W=await J[L]();return L==="json"&&(K.responseValidator&&await K.responseValidator(W),K.responseTransformer&&(W=await K.responseTransformer(W))),K.responseStyle==="data"?W:{data:W,...Y}}let $=await J.text();try{$=JSON.parse($)}catch{}let Q=$;for(let L of k.error._fns)L&&(Q=await L($,J,M,K));if(Q=Q||{},K.throwOnError)throw Q;return K.responseStyle==="data"?void 0:{error:Q,...Y}};return{buildUrl:S,connect:(X)=>E({...X,method:"CONNECT"}),delete:(X)=>E({...X,method:"DELETE"}),get:(X)=>E({...X,method:"GET"}),getConfig:G,head:(X)=>E({...X,method:"HEAD"}),interceptors:k,options:(X)=>E({...X,method:"OPTIONS"}),patch:(X)=>E({...X,method:"PATCH"}),post:(X)=>E({...X,method:"POST"}),put:(X)=>E({...X,method:"PUT"}),request:E,setConfig:B,trace:(X)=>E({...X,method:"TRACE"})}};var Z=q(N({baseUrl:"http://localhost:8080"}));var s=(F)=>{return(F.client??Z).delete({url:"/o/functional-cookies-entries/scopes/{scopeKey}/by-external-reference-code/{externalReferenceCode}/collaborators/by-type/{type}/{collaboratorId}",...F})},n=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/scopes/{scopeKey}/by-external-reference-code/{externalReferenceCode}/collaborators/by-type/{type}/{collaboratorId}",...F})},t=(F)=>{return(F.client??Z).put({url:"/o/functional-cookies-entries/scopes/{scopeKey}/by-external-reference-code/{externalReferenceCode}/collaborators/by-type/{type}/{collaboratorId}",...F,headers:{"Content-Type":"application/json",...F.headers}})},i=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/scopes/{scopeKey}/by-external-reference-code/{externalReferenceCode}/collaborators",...F})},o=(F)=>{return(F.client??Z).post({url:"/o/functional-cookies-entries/scopes/{scopeKey}/by-external-reference-code/{externalReferenceCode}/collaborators",...F,headers:{"Content-Type":"application/json",...F.headers}})},FF=(F)=>{return(F.client??Z).delete({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}",...F})},GF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}",...F})},KF=(F)=>{return(F.client??Z).patch({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}",...F,headers:{"Content-Type":"application/json",...F.headers}})},VF=(F)=>{return(F.client??Z).put({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}",...F,headers:{"Content-Type":"application/json",...F.headers}})},XF=(F)=>{return(F.client??Z).delete({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}/by-version/{version}",...F})},ZF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}/by-version/{version}",...F})},kF=(F)=>{return(F?.client??Z).delete({url:"/o/functional-cookies-entries/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},BF=(F)=>{return(F?.client??Z).post({url:"/o/functional-cookies-entries/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},EF=(F)=>{return(F?.client??Z).put({url:"/o/functional-cookies-entries/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},HF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}/versions",...F})},JF=(F)=>{return(F?.client??Z).get({url:"/o/functional-cookies-entries/",...F})},LF=(F)=>{return(F?.client??Z).post({url:"/o/functional-cookies-entries/",...F,headers:{"Content-Type":"application/json",...F?.headers}})},MF=(F)=>{return(F.client??Z).post({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}/by-version/{version}/copy",...F})},PF=(F)=>{return(F.client??Z).post({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}/by-version/{version}/expire",...F})},QF=(F)=>{return(F?.client??Z).post({url:"/o/functional-cookies-entries/export-batch",...F})},WF=(F)=>{return(F?.client??Z).post({url:"/o/functional-cookies-entries/validate",...F,headers:{"Content-Type":"application/json",...F?.headers}})},YF=(F)=>{return(F.client??Z).put({url:"/o/functional-cookies-entries/by-external-reference-code/{externalReferenceCode}/by-version/{version}/restore",...F})},$F=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/openapi.{type}",...F})},DF=(F)=>{return(F.client??Z).delete({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/collaborators/by-type/{type}/{collaboratorId}",...F})},IF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/collaborators/by-type/{type}/{collaboratorId}",...F})},NF=(F)=>{return(F.client??Z).put({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/collaborators/by-type/{type}/{collaboratorId}",...F,headers:{"Content-Type":"application/json",...F.headers}})},OF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/collaborators",...F})},SF=(F)=>{return(F.client??Z).post({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/collaborators",...F,headers:{"Content-Type":"application/json",...F.headers}})},TF=(F)=>{return(F.client??Z).post({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/collaborators/export-batch",...F})},UF=(F)=>{return(F.client??Z).delete({url:"/o/functional-cookies-entries/{functionalCookieEntryId}",...F})},vF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/{functionalCookieEntryId}",...F})},RF=(F)=>{return(F.client??Z).patch({url:"/o/functional-cookies-entries/{functionalCookieEntryId}",...F,headers:{"Content-Type":"application/json",...F.headers}})},jF=(F)=>{return(F.client??Z).put({url:"/o/functional-cookies-entries/{functionalCookieEntryId}",...F,headers:{"Content-Type":"application/json",...F.headers}})},qF=(F)=>{return(F.client??Z).delete({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/by-version/{version}",...F})},xF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/by-version/{version}",...F})},zF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/versions",...F})},mF=(F)=>{return(F.client??Z).get({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/permissions",...F})},wF=(F)=>{return(F.client??Z).put({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/permissions",...F,headers:{"Content-Type":"application/json",...F.headers}})},bF=(F)=>{return(F.client??Z).post({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/by-version/{version}/copy",...F})},fF=(F)=>{return(F.client??Z).post({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/by-version/{version}/expire",...F})},gF=(F)=>{return(F.client??Z).put({url:"/o/functional-cookies-entries/{functionalCookieEntryId}/by-version/{version}/restore",...F})};export{t as putScopeScopeKeyByExternalReferenceCodeCollaboratorByTypeCollaborator,wF as putFunctionalCookieEntryPermissionsPage,NF as putFunctionalCookieEntryCollaboratorByTypeCollaborator,gF as putFunctionalCookieEntryByVersionRestore,EF as putFunctionalCookieEntryBatch,jF as putFunctionalCookieEntry,YF as putByExternalReferenceCodeByVersionRestore,VF as putByExternalReferenceCode,WF as postValidate,o as postScopeScopeKeyByExternalReferenceCodeCollaboratorsPage,TF as postFunctionalCookieEntryCollaboratorsPageExportBatch,SF as postFunctionalCookieEntryCollaboratorsPage,fF as postFunctionalCookieEntryByVersionExpire,bF as postFunctionalCookieEntryByVersionCopy,BF as postFunctionalCookieEntryBatch,LF as postFunctionalCookieEntry,QF as postFunctionalCookieEntriesPageExportBatch,PF as postByExternalReferenceCodeByVersionExpire,MF as postByExternalReferenceCodeByVersionCopy,RF as patchFunctionalCookieEntry,KF as patchByExternalReferenceCode,i as getScopeScopeKeyByExternalReferenceCodeCollaboratorsPage,n as getScopeScopeKeyByExternalReferenceCodeCollaboratorByTypeCollaborator,$F as getOpenApi,mF as getFunctionalCookieEntryPermissionsPage,OF as getFunctionalCookieEntryCollaboratorsPage,IF as getFunctionalCookieEntryCollaboratorByTypeCollaborator,xF as getFunctionalCookieEntryByVersion,vF as getFunctionalCookieEntry,zF as getFunctionalCookieEntriesVersionsPage,JF as getFunctionalCookieEntriesPage,HF as getByExternalReferenceCodeVersionsPage,ZF as getByExternalReferenceCodeByVersion,GF as getByExternalReferenceCode,s as deleteScopeScopeKeyByExternalReferenceCodeCollaboratorByTypeCollaborator,DF as deleteFunctionalCookieEntryCollaboratorByTypeCollaborator,qF as deleteFunctionalCookieEntryByVersion,kF as deleteFunctionalCookieEntryBatch,UF as deleteFunctionalCookieEntry,XF as deleteByExternalReferenceCodeByVersion,FF as deleteByExternalReferenceCode};