UNPKG

liferay-headless-rest-client

Version:
2 lines (1 loc) 9.14 kB
var m=async(F,X)=>{let K=typeof X=="function"?await X(F):X;if(K)return F.scheme==="bearer"?`Bearer ${K}`:F.scheme==="basic"?`Basic ${btoa(K)}`:K},P=(F,X,K)=>{typeof K=="string"||K instanceof Blob?F.append(X,K):F.append(X,JSON.stringify(K))};var c={bodySerializer:(F)=>{let X=new FormData;return Object.entries(F).forEach(([K,B])=>{B!=null&&(Array.isArray(B)?B.forEach((k)=>P(X,K,k)):P(X,K,B))}),X}},b={bodySerializer:(F)=>JSON.stringify(F,(X,K)=>typeof K=="bigint"?K.toString():K)};var v=(F)=>{switch(F){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},w=(F)=>{switch(F){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},g=(F)=>{switch(F){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},T=({allowReserved:F,explode:X,name:K,style:B,value:k})=>{if(!X){let V=(F?k:k.map((H)=>encodeURIComponent(H))).join(w(B));switch(B){case"label":return`.${V}`;case"matrix":return`;${K}=${V}`;case"simple":return V;default:return`${K}=${V}`}}let E=v(B),Z=k.map((V)=>B==="label"||B==="simple"?F?V:encodeURIComponent(V):L({allowReserved:F,name:K,value:V})).join(E);return B==="label"||B==="matrix"?E+Z:Z},L=({allowReserved:F,name:X,value:K})=>{if(K==null)return"";if(typeof K=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${X}=${F?K:encodeURIComponent(K)}`},x=({allowReserved:F,explode:X,name:K,style:B,value:k})=>{if(k instanceof Date)return`${K}=${k.toISOString()}`;if(B!=="deepObject"&&!X){let V=[];Object.entries(k).forEach(([Y,W])=>{V=[...V,Y,F?W:encodeURIComponent(W)]});let H=V.join(",");switch(B){case"form":return`${K}=${H}`;case"label":return`.${H}`;case"matrix":return`;${K}=${H}`;default:return H}}let E=g(B),Z=Object.entries(k).map(([V,H])=>L({allowReserved:F,name:B==="deepObject"?`${K}[${V}]`:V,value:H})).join(E);return B==="label"||B==="matrix"?E+Z:Z},d=/\{[^{}]+\}/g,f=({path:F,url:X})=>{let K=X,B=X.match(d);if(B)for(let k of B){let E=!1,Z=k.substring(1,k.length-1),V="simple";Z.endsWith("*")&&(E=!0,Z=Z.substring(0,Z.length-1)),Z.startsWith(".")?(Z=Z.substring(1),V="label"):Z.startsWith(";")&&(Z=Z.substring(1),V="matrix");let H=F[Z];if(H==null)continue;if(Array.isArray(H)){K=K.replace(k,T({explode:E,name:Z,style:V,value:H}));continue}if(typeof H=="object"){K=K.replace(k,x({explode:E,name:Z,style:V,value:H}));continue}if(V==="matrix"){K=K.replace(k,`;${L({name:Z,value:H})}`);continue}let Y=encodeURIComponent(V==="label"?`.${H}`:H);K=K.replace(k,Y)}return K},j=({allowReserved:F,array:X,object:K}={})=>(B)=>{let k=[];if(B&&typeof B=="object")for(let E in B){let Z=B[E];if(Z!=null)if(Array.isArray(Z)){let V=T({allowReserved:F,explode:!0,name:E,style:"form",value:Z,...X});V&&k.push(V)}else if(typeof Z=="object"){let V=x({allowReserved:F,explode:!0,name:E,style:"deepObject",value:Z,...K});V&&k.push(V)}else{let V=L({allowReserved:F,name:E,value:Z});V&&k.push(V)}}return k.join("&")},_=(F)=>{if(!F)return"stream";let X=F.split(";")[0]?.trim();if(X){if(X.startsWith("application/json")||X.endsWith("+json"))return"json";if(X==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some((K)=>X.startsWith(K)))return"blob";if(X.startsWith("text/"))return"text"}},A=async({security:F,...X})=>{for(let K of F){let B=await m(K,X.auth);if(!B)continue;let k=K.name??"Authorization";switch(K.in){case"query":X.query||(X.query={}),X.query[k]=B;break;case"cookie":X.headers.append("Cookie",`${k}=${B}`);break;case"header":default:X.headers.set(k,B);break}return}},Q=(F)=>C({baseUrl:F.baseUrl,path:F.path,query:F.query,querySerializer:typeof F.querySerializer=="function"?F.querySerializer:j(F.querySerializer),url:F.url}),C=({baseUrl:F,path:X,query:K,querySerializer:B,url:k})=>{let E=k.startsWith("/")?k:`/${k}`,Z=(F??"")+E;X&&(Z=f({path:X,url:Z}));let V=K?B(K):"";return V.startsWith("?")&&(V=V.substring(1)),V&&(Z+=`?${V}`),Z},S=(F,X)=>{let K={...F,...X};return K.baseUrl?.endsWith("/")&&(K.baseUrl=K.baseUrl.substring(0,K.baseUrl.length-1)),K.headers=z(F.headers,X.headers),K},z=(...F)=>{let X=new Headers;for(let K of F){if(!K||typeof K!="object")continue;let B=K instanceof Headers?K.entries():Object.entries(K);for(let[k,E]of B)if(E===null)X.delete(k);else if(Array.isArray(E))for(let Z of E)X.append(k,Z);else E!==void 0&&X.set(k,typeof E=="object"?JSON.stringify(E):E)}return X},N=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 X=this.getInterceptorIndex(F);return!!this._fns[X]}eject(F){let X=this.getInterceptorIndex(F);this._fns[X]&&(this._fns[X]=null)}update(F,X){let K=this.getInterceptorIndex(F);return this._fns[K]?(this._fns[K]=X,F):!1}use(F){return this._fns=[...this._fns,F],this._fns.length-1}},h=()=>({error:new N,request:new N,response:new N}),u=j({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),y={"Content-Type":"application/json"},O=(F={})=>({...b,headers:y,parseAs:"auto",querySerializer:u,...F}),R=(F={})=>{let X=S(O(),F),K=()=>({...X}),B=(Z)=>(X=S(X,Z),K()),k=h(),E=async(Z)=>{let V={...X,...Z,fetch:Z.fetch??X.fetch??globalThis.fetch,headers:z(X.headers,Z.headers)};V.security&&await A({...V,security:V.security}),V.body&&V.bodySerializer&&(V.body=V.bodySerializer(V.body)),(V.body===void 0||V.body==="")&&V.headers.delete("Content-Type");let H=Q(V),Y={redirect:"follow",...V},W=new Request(H,Y);for(let M of k.request._fns)M&&(W=await M(W,V));let U=V.fetch,J=await U(W);for(let M of k.response._fns)M&&(J=await M(J,W,V));let D={request:W,response:J};if(J.ok){if(J.status===204||J.headers.get("Content-Length")==="0")return V.responseStyle==="data"?{}:{data:{},...D};let M=(V.parseAs==="auto"?_(J.headers.get("Content-Type")):V.parseAs)??"json";if(M==="stream")return V.responseStyle==="data"?J.body:{data:J.body,...D};let q=await J[M]();return M==="json"&&(V.responseValidator&&await V.responseValidator(q),V.responseTransformer&&(q=await V.responseTransformer(q))),V.responseStyle==="data"?q:{data:q,...D}}let I=await J.text();try{I=JSON.parse(I)}catch{}let $=I;for(let M of k.error._fns)M&&($=await M(I,J,W,V));if($=$||{},V.throwOnError)throw $;return V.responseStyle==="data"?void 0:{error:$,...D}};return{buildUrl:Q,connect:(Z)=>E({...Z,method:"CONNECT"}),delete:(Z)=>E({...Z,method:"DELETE"}),get:(Z)=>E({...Z,method:"GET"}),getConfig:K,head:(Z)=>E({...Z,method:"HEAD"}),interceptors:k,options:(Z)=>E({...Z,method:"OPTIONS"}),patch:(Z)=>E({...Z,method:"PATCH"}),post:(Z)=>E({...Z,method:"POST"}),put:(Z)=>E({...Z,method:"PUT"}),request:E,setConfig:B,trace:(Z)=>E({...Z,method:"TRACE"})}};var G=R(O({baseUrl:"http://localhost:8080"}));var n=(F)=>{return(F.client??G).delete({url:"/o/scim/v1.0/v2/Groups/{id}",...F})},s=(F)=>{return(F.client??G).get({url:"/o/scim/v1.0/v2/Groups/{id}",...F})},t=(F)=>{return(F.client??G).patch({url:"/o/scim/v1.0/v2/Groups/{id}",...F,headers:{"Content-Type":"application/scim+json",...F.headers}})},i=(F)=>{return(F.client??G).put({url:"/o/scim/v1.0/v2/Groups/{id}",...F,headers:{"Content-Type":"application/scim+json",...F.headers}})},o=(F)=>{return(F?.client??G).get({url:"/o/scim/v1.0/v2/Groups",...F})},FF=(F)=>{return(F?.client??G).post({url:"/o/scim/v1.0/v2/Groups",...F,headers:{"Content-Type":"application/scim+json",...F?.headers}})},KF=(F)=>{return(F?.client??G).post({url:"/o/scim/v1.0/v2/Groups/.search",...F,headers:{"Content-Type":"application/scim+json",...F?.headers}})},VF=(F)=>{return(F.client??G).get({url:"/o/scim/v1.0/v2/ResourceTypes/{id}",...F})},XF=(F)=>{return(F?.client??G).get({url:"/o/scim/v1.0/v2/ResourceTypes",...F})},ZF=(F)=>{return(F.client??G).get({url:"/o/scim/v1.0/v2/Schemas/{id}",...F})},kF=(F)=>{return(F?.client??G).get({url:"/o/scim/v1.0/v2/Schemas",...F})},BF=(F)=>{return(F?.client??G).get({url:"/o/scim/v1.0/v2/ServiceProviderConfig",...F})},EF=(F)=>{return(F.client??G).delete({url:"/o/scim/v1.0/v2/Users/{id}",...F})},GF=(F)=>{return(F.client??G).get({url:"/o/scim/v1.0/v2/Users/{id}",...F})},HF=(F)=>{return(F.client??G).patch({url:"/o/scim/v1.0/v2/Users/{id}",...F,headers:{"Content-Type":"application/scim+json",...F.headers}})},JF=(F)=>{return(F.client??G).put({url:"/o/scim/v1.0/v2/Users/{id}",...F,headers:{"Content-Type":"application/scim+json",...F.headers}})},MF=(F)=>{return(F?.client??G).get({url:"/o/scim/v1.0/v2/Users",...F})},WF=(F)=>{return(F?.client??G).post({url:"/o/scim/v1.0/v2/Users",...F,headers:{"Content-Type":"application/scim+json",...F?.headers}})},YF=(F)=>{return(F?.client??G).post({url:"/o/scim/v1.0/v2/Users/.search",...F,headers:{"Content-Type":"application/scim+json",...F?.headers}})};export{JF as putV2User,i as putV2Group,YF as postV2UserSearch,WF as postV2User,KF as postV2GroupSearch,FF as postV2Group,HF as patchV2User,t as patchV2Group,MF as getV2Users,GF as getV2UserById,BF as getV2ServiceProviderConfig,kF as getV2Schemas,ZF as getV2SchemaById,XF as getV2ResourceTypes,VF as getV2ResourceTypeById,o as getV2Groups,s as getV2GroupById,EF as deleteV2User,n as deleteV2Group};