liferay-headless-rest-client
Version:
A collection of Headless Clients used in Liferay Portal
2 lines (1 loc) • 14.8 kB
JavaScript
var R=async(K,D)=>{let X=typeof D=="function"?await D(K):D;if(X)return K.scheme==="bearer"?`Bearer ${X}`:K.scheme==="basic"?`Basic ${btoa(X)}`:X},U=(K,D,X)=>{typeof X=="string"||X instanceof Blob?K.append(D,X):K.append(D,JSON.stringify(X))};var a={bodySerializer:(K)=>{let D=new FormData;return Object.entries(K).forEach(([X,J])=>{J!=null&&(Array.isArray(J)?J.forEach((H)=>U(D,X,H)):U(D,X,J))}),D}},b={bodySerializer:(K)=>JSON.stringify(K,(D,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"&"}},g=(K)=>{switch(K){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},d=(K)=>{switch(K){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},v=({allowReserved:K,explode:D,name:X,style:J,value:H})=>{if(!D){let Z=(K?H:H.map((V)=>encodeURIComponent(V))).join(g(J));switch(J){case"label":return`.${Z}`;case"matrix":return`;${X}=${Z}`;case"simple":return Z;default:return`${X}=${Z}`}}let Q=w(J),E=H.map((Z)=>J==="label"||J==="simple"?K?Z:encodeURIComponent(Z):N({allowReserved:K,name:X,value:Z})).join(Q);return J==="label"||J==="matrix"?Q+E:E},N=({allowReserved:K,name:D,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`${D}=${K?X:encodeURIComponent(X)}`},z=({allowReserved:K,explode:D,name:X,style:J,value:H,valueOnly:Q})=>{if(H instanceof Date)return Q?H.toISOString():`${X}=${H.toISOString()}`;if(J!=="deepObject"&&!D){let V=[];Object.entries(H).forEach(([k,F])=>{V=[...V,k,K?F:encodeURIComponent(F)]});let $=V.join(",");switch(J){case"form":return`${X}=${$}`;case"label":return`.${$}`;case"matrix":return`;${X}=${$}`;default:return $}}let E=d(J),Z=Object.entries(H).map(([V,$])=>N({allowReserved:K,name:J==="deepObject"?`${X}[${V}]`:V,value:$})).join(E);return J==="label"||J==="matrix"?E+Z:Z},f=/\{[^{}]+\}/g,u=({path:K,url:D})=>{let X=D,J=D.match(f);if(J)for(let H of J){let Q=!1,E=H.substring(1,H.length-1),Z="simple";E.endsWith("*")&&(Q=!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 V=K[E];if(V==null)continue;if(Array.isArray(V)){X=X.replace(H,v({explode:Q,name:E,style:Z,value:V}));continue}if(typeof V=="object"){X=X.replace(H,z({explode:Q,name:E,style:Z,value:V,valueOnly:!0}));continue}if(Z==="matrix"){X=X.replace(H,`;${N({name:E,value:V})}`);continue}let $=encodeURIComponent(Z==="label"?`.${V}`:V);X=X.replace(H,$)}return X},I=({allowReserved:K,array:D,object:X}={})=>(J)=>{let H=[];if(J&&typeof J=="object")for(let Q in J){let E=J[Q];if(E!=null)if(Array.isArray(E)){let Z=v({allowReserved:K,explode:!0,name:Q,style:"form",value:E,...D});Z&&H.push(Z)}else if(typeof E=="object"){let Z=z({allowReserved:K,explode:!0,name:Q,style:"deepObject",value:E,...X});Z&&H.push(Z)}else{let Z=N({allowReserved:K,name:Q,value:E});Z&&H.push(Z)}}return H.join("&")},c=(K)=>{if(!K)return"stream";let D=K.split(";")[0]?.trim();if(D){if(D.startsWith("application/json")||D.endsWith("+json"))return"json";if(D==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some((X)=>D.startsWith(X)))return"blob";if(D.startsWith("text/"))return"text"}},_=async({security:K,...D})=>{for(let X of K){let J=await R(X,D.auth);if(!J)continue;let H=X.name??"Authorization";switch(X.in){case"query":D.query||(D.query={}),D.query[H]=J;break;case"cookie":D.headers.append("Cookie",`${H}=${J}`);break;case"header":default:D.headers.set(H,J);break}return}},x=(K)=>A({baseUrl:K.baseUrl,path:K.path,query:K.query,querySerializer:typeof K.querySerializer=="function"?K.querySerializer:I(K.querySerializer),url:K.url}),A=({baseUrl:K,path:D,query:X,querySerializer:J,url:H})=>{let Q=H.startsWith("/")?H:`/${H}`,E=(K??"")+Q;D&&(E=u({path:D,url:E}));let Z=X?J(X):"";return Z.startsWith("?")&&(Z=Z.substring(1)),Z&&(E+=`?${Z}`),E},T=(K,D)=>{let X={...K,...D};return X.baseUrl?.endsWith("/")&&(X.baseUrl=X.baseUrl.substring(0,X.baseUrl.length-1)),X.headers=P(K.headers,D.headers),X},P=(...K)=>{let D=new Headers;for(let X of K){if(!X||typeof X!="object")continue;let J=X instanceof Headers?X.entries():Object.entries(X);for(let[H,Q]of J)if(Q===null)D.delete(H);else if(Array.isArray(Q))for(let E of Q)D.append(H,E);else Q!==void 0&&D.set(H,typeof Q=="object"?JSON.stringify(Q):Q)}return D},O=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 D=this.getInterceptorIndex(K);return!!this._fns[D]}eject(K){let D=this.getInterceptorIndex(K);this._fns[D]&&(this._fns[D]=null)}update(K,D){let X=this.getInterceptorIndex(K);return this._fns[X]?(this._fns[X]=D,K):!1}use(K){return this._fns=[...this._fns,K],this._fns.length-1}},C=()=>({error:new O,request:new O,response:new O}),y=I({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),h={"Content-Type":"application/json"},S=(K={})=>({...b,headers:h,parseAs:"auto",querySerializer:y,...K}),j=(K={})=>{let D=T(S(),K),X=()=>({...D}),J=(E)=>(D=T(D,E),X()),H=C(),Q=async(E)=>{let Z={...D,...E,fetch:E.fetch??D.fetch??globalThis.fetch,headers:P(D.headers,E.headers)};Z.security&&await _({...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=x(Z),$={redirect:"follow",...Z},k=new Request(V,$);for(let Y of H.request._fns)Y&&(k=await Y(k,Z));let F=Z.fetch,W=await F(k);for(let Y of H.response._fns)Y&&(W=await Y(W,k,Z));let L={request:k,response:W};if(W.ok){if(W.status===204||W.headers.get("Content-Length")==="0")return Z.responseStyle==="data"?{}:{data:{},...L};let Y=(Z.parseAs==="auto"?c(W.headers.get("Content-Type")):Z.parseAs)??"json";if(Y==="stream")return Z.responseStyle==="data"?W.body:{data:W.body,...L};let B=await W[Y]();return Y==="json"&&(Z.responseValidator&&await Z.responseValidator(B),Z.responseTransformer&&(B=await Z.responseTransformer(B))),Z.responseStyle==="data"?B:{data:B,...L}}let M=await W.text();try{M=JSON.parse(M)}catch{}let q=M;for(let Y of H.error._fns)Y&&(q=await Y(M,W,k,Z));if(q=q||{},Z.throwOnError)throw q;return Z.responseStyle==="data"?void 0:{error:q,...L}};return{buildUrl:x,connect:(E)=>Q({...E,method:"CONNECT"}),delete:(E)=>Q({...E,method:"DELETE"}),get:(E)=>Q({...E,method:"GET"}),getConfig:X,head:(E)=>Q({...E,method:"HEAD"}),interceptors:H,options:(E)=>Q({...E,method:"OPTIONS"}),patch:(E)=>Q({...E,method:"PATCH"}),post:(E)=>Q({...E,method:"POST"}),put:(E)=>Q({...E,method:"PUT"}),request:Q,setConfig:J,trace:(E)=>Q({...E,method:"TRACE"})}};var G=j(S({baseUrl:"http://localhost:8080"}));var t=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/field-mapping-infos",...K})},i=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/field-mapping-infos/export-batch",...K})},o=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/keyword-query-contributors",...K})},KK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/keyword-query-contributors/export-batch",...K})},XK=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/model-prefilter-contributors",...K})},ZK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/model-prefilter-contributors/export-batch",...K})},DK=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/query-prefilter-contributors",...K})},EK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/query-prefilter-contributors/export-batch",...K})},GK=(K)=>{return(K.client??G).delete({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}",...K})},HK=(K)=>{return(K.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}",...K})},JK=(K)=>{return(K.client??G).patch({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}",...K,headers:{"Content-Type":"application/json",...K.headers}})},QK=(K)=>{return(K.client??G).put({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}",...K,headers:{"Content-Type":"application/json",...K.headers}})},VK=(K)=>{return(K?.client??G).delete({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/batch",...K,headers:{"Content-Type":"application/json",...K?.headers}})},WK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/batch",...K,headers:{"Content-Type":"application/json",...K?.headers}})},YK=(K)=>{return(K?.client??G).put({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/batch",...K,headers:{"Content-Type":"application/json",...K?.headers}})},$K=(K)=>{return(K.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/by-external-reference-code/{externalReferenceCode}",...K})},kK=(K)=>{return(K.client??G).put({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/by-external-reference-code/{externalReferenceCode}",...K,headers:{"Content-Type":"application/json",...K.headers}})},qK=(K)=>{return(K.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}/export",...K})},BK=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-blueprints",...K})},FK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-blueprints",...K,headers:{"Content-Type":"application/json",...K?.headers}})},LK=(K)=>{return(K.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/{sxpBlueprintId}/copy",...K})},MK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/validate",...K,headers:{"Content-Type":"application/json",...K?.headers}})},NK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-blueprints/export-batch",...K})},OK=(K)=>{return(K.client??G).delete({url:"/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}",...K})},SK=(K)=>{return(K.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}",...K})},UK=(K)=>{return(K.client??G).patch({url:"/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}",...K,headers:{"Content-Type":"application/json",...K.headers}})},xK=(K)=>{return(K.client??G).put({url:"/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}",...K,headers:{"Content-Type":"application/json",...K.headers}})},TK=(K)=>{return(K?.client??G).delete({url:"/o/search-experiences-rest/v1.0/sxp-elements/batch",...K,headers:{"Content-Type":"application/json",...K?.headers}})},vK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-elements/batch",...K,headers:{"Content-Type":"application/json",...K?.headers}})},zK=(K)=>{return(K?.client??G).put({url:"/o/search-experiences-rest/v1.0/sxp-elements/batch",...K,headers:{"Content-Type":"application/json",...K?.headers}})},IK=(K)=>{return(K.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-elements/by-external-reference-code/{externalReferenceCode}",...K})},PK=(K)=>{return(K.client??G).put({url:"/o/search-experiences-rest/v1.0/sxp-elements/by-external-reference-code/{externalReferenceCode}",...K,headers:{"Content-Type":"application/json",...K.headers}})},jK=(K)=>{return(K.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}/export",...K})},RK=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-elements",...K})},bK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-elements",...K,headers:{"Content-Type":"application/json",...K?.headers}})},mK=(K)=>{return(K.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-elements/{sxpElementId}/copy",...K})},wK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-elements/preview",...K,headers:{"Content-Type":"application/json",...K?.headers}})},gK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-elements/validate",...K,headers:{"Content-Type":"application/json",...K?.headers}})},dK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-elements/export-batch",...K})},fK=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/sxp-parameter-contributor-definitions",...K})},uK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/sxp-parameter-contributor-definitions/export-batch",...K})},cK=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/search-indexes",...K})},_K=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/search-indexes/export-batch",...K})},AK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/search",...K,headers:{"Content-Type":"application/json",...K?.headers}})},CK=(K)=>{return(K.client??G).get({url:"/o/search-experiences-rest/v1.0/searchable-asset-names/{languageId}",...K})},yK=(K)=>{return(K?.client??G).get({url:"/o/search-experiences-rest/v1.0/searchable-asset-names",...K})},hK=(K)=>{return(K?.client??G).post({url:"/o/search-experiences-rest/v1.0/searchable-asset-names/export-batch",...K})};export{PK as putSxpElementByExternalReferenceCode,zK as putSxpElementBatch,xK as putSxpElement,kK as putSxpBlueprintByExternalReferenceCode,YK as putSxpBlueprintBatch,QK as putSxpBlueprint,uK as postSxpParameterContributorDefinitionsPageExportBatch,dK as postSxpElementsPageExportBatch,gK as postSxpElementValidate,wK as postSxpElementPreview,mK as postSxpElementCopy,vK as postSxpElementBatch,bK as postSxpElement,NK as postSxpBlueprintsPageExportBatch,MK as postSxpBlueprintValidate,LK as postSxpBlueprintCopy,WK as postSxpBlueprintBatch,FK as postSxpBlueprint,hK as postSearchableAssetNamesPageExportBatch,_K as postSearchIndexesPageExportBatch,AK as postSearch,EK as postQueryPrefilterContributorsPageExportBatch,ZK as postModelPrefilterContributorsPageExportBatch,KK as postKeywordQueryContributorsPageExportBatch,i as postFieldMappingInfosPageExportBatch,UK as patchSxpElement,JK as patchSxpBlueprint,fK as getSxpParameterContributorDefinitionsPage,RK as getSxpElementsPage,jK as getSxpElementExport,IK as getSxpElementByExternalReferenceCode,SK as getSxpElement,BK as getSxpBlueprintsPage,qK as getSxpBlueprintExport,$K as getSxpBlueprintByExternalReferenceCode,HK as getSxpBlueprint,yK as getSearchableAssetNamesPage,CK as getSearchableAssetNameLanguagePage,cK as getSearchIndexesPage,DK as getQueryPrefilterContributorsPage,XK as getModelPrefilterContributorsPage,o as getKeywordQueryContributorsPage,t as getFieldMappingInfosPage,TK as deleteSxpElementBatch,OK as deleteSxpElement,VK as deleteSxpBlueprintBatch,GK as deleteSxpBlueprint};