UNPKG

liferay-headless-rest-client

Version:
2 lines (1 loc) 9.28 kB
var b=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},P=(K,B,X)=>{typeof X=="string"||X instanceof Blob?K.append(B,X):K.append(B,JSON.stringify(X))};var l={bodySerializer:(K)=>{let B=new FormData;return Object.entries(K).forEach(([X,F])=>{F!=null&&(Array.isArray(F)?F.forEach((E)=>P(B,X,E)):P(B,X,F))}),B}},m={bodySerializer:(K)=>JSON.stringify(K,(B,X)=>typeof X=="bigint"?X.toString():X)};var R={$body_:"body",$headers_:"headers",$path_:"path",$query_:"query"},a=Object.entries(R);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"&"}},U=({allowReserved:K,explode:B,name:X,style:F,value:E})=>{if(!B){let Z=(K?E:E.map((H)=>encodeURIComponent(H))).join(g(F));switch(F){case"label":return`.${Z}`;case"matrix":return`;${X}=${Z}`;case"simple":return Z;default:return`${X}=${Z}`}}let G=w(F),D=E.map((Z)=>F==="label"||F==="simple"?K?Z:encodeURIComponent(Z):M({allowReserved:K,name:X,value:Z})).join(G);return F==="label"||F==="matrix"?G+D:D},M=({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)}`},v=({allowReserved:K,explode:B,name:X,style:F,value:E,valueOnly:G})=>{if(E instanceof Date)return G?E.toISOString():`${X}=${E.toISOString()}`;if(F!=="deepObject"&&!B){let H=[];Object.entries(E).forEach(([Y,q])=>{H=[...H,Y,K?q:encodeURIComponent(q)]});let W=H.join(",");switch(F){case"form":return`${X}=${W}`;case"label":return`.${W}`;case"matrix":return`;${X}=${W}`;default:return W}}let D=d(F),Z=Object.entries(E).map(([H,W])=>M({allowReserved:K,name:F==="deepObject"?`${X}[${H}]`:H,value:W})).join(D);return F==="label"||F==="matrix"?D+Z:Z},A=/\{[^{}]+\}/g,_=({path:K,url:B})=>{let X=B,F=B.match(A);if(F)for(let E of F){let G=!1,D=E.substring(1,E.length-1),Z="simple";D.endsWith("*")&&(G=!0,D=D.substring(0,D.length-1)),D.startsWith(".")?(D=D.substring(1),Z="label"):D.startsWith(";")&&(D=D.substring(1),Z="matrix");let H=K[D];if(H==null)continue;if(Array.isArray(H)){X=X.replace(E,U({explode:G,name:D,style:Z,value:H}));continue}if(typeof H=="object"){X=X.replace(E,v({explode:G,name:D,style:Z,value:H,valueOnly:!0}));continue}if(Z==="matrix"){X=X.replace(E,`;${M({name:D,value:H})}`);continue}let W=encodeURIComponent(Z==="label"?`.${H}`:H);X=X.replace(E,W)}return X},x=({allowReserved:K,array:B,object:X}={})=>(F)=>{let E=[];if(F&&typeof F=="object")for(let G in F){let D=F[G];if(D!=null)if(Array.isArray(D)){let Z=U({allowReserved:K,explode:!0,name:G,style:"form",value:D,...B});Z&&E.push(Z)}else if(typeof D=="object"){let Z=v({allowReserved:K,explode:!0,name:G,style:"deepObject",value:D,...X});Z&&E.push(Z)}else{let Z=M({allowReserved:K,name:G,value:D});Z&&E.push(Z)}}return E.join("&")},f=(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"}},C=async({security:K,...B})=>{for(let X of K){let F=await b(X,B.auth);if(!F)continue;let E=X.name??"Authorization";switch(X.in){case"query":B.query||(B.query={}),B.query[E]=F;break;case"cookie":B.headers.append("Cookie",`${E}=${F}`);break;case"header":default:B.headers.set(E,F);break}return}},S=(K)=>u({baseUrl:K.baseUrl,path:K.path,query:K.query,querySerializer:typeof K.querySerializer=="function"?K.querySerializer:x(K.querySerializer),url:K.url}),u=({baseUrl:K,path:B,query:X,querySerializer:F,url:E})=>{let G=E.startsWith("/")?E:`/${E}`,D=(K??"")+G;B&&(D=_({path:B,url:D}));let Z=X?F(X):"";return Z.startsWith("?")&&(Z=Z.substring(1)),Z&&(D+=`?${Z}`),D},T=(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 F=X instanceof Headers?X.entries():Object.entries(X);for(let[E,G]of F)if(G===null)B.delete(E);else if(Array.isArray(G))for(let D of G)B.append(E,D);else G!==void 0&&B.set(E,typeof G=="object"?JSON.stringify(G):G)}return B},N=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}},y=()=>({error:new N,request:new N,response:new N}),h=x({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),c={"Content-Type":"application/json"},O=(K={})=>({...m,headers:c,parseAs:"auto",querySerializer:h,...K}),j=(K={})=>{let B=T(O(),K),X=()=>({...B}),F=(D)=>(B=T(B,D),X()),E=y(),G=async(D)=>{let Z={...B,...D,fetch:D.fetch??B.fetch??globalThis.fetch,headers:z(B.headers,D.headers)};Z.security&&await C({...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 H=S(Z),W={redirect:"follow",...Z},Y=new Request(H,W);for(let V of E.request._fns)V&&(Y=await V(Y,Z));let q=Z.fetch,Q=await q(Y);for(let V of E.response._fns)V&&(Q=await V(Q,Y,Z));let I={request:Y,response:Q};if(Q.ok){if(Q.status===204||Q.headers.get("Content-Length")==="0")return Z.responseStyle==="data"?{}:{data:{},...I};let V=(Z.parseAs==="auto"?f(Q.headers.get("Content-Type")):Z.parseAs)??"json";if(V==="stream")return Z.responseStyle==="data"?Q.body:{data:Q.body,...I};let k=await Q[V]();return V==="json"&&(Z.responseValidator&&await Z.responseValidator(k),Z.responseTransformer&&(k=await Z.responseTransformer(k))),Z.responseStyle==="data"?k:{data:k,...I}}let L=await Q.text();try{L=JSON.parse(L)}catch{}let $=L;for(let V of E.error._fns)V&&($=await V(L,Q,Y,Z));if($=$||{},Z.throwOnError)throw $;return Z.responseStyle==="data"?void 0:{error:$,...I}};return{buildUrl:S,connect:(D)=>G({...D,method:"CONNECT"}),delete:(D)=>G({...D,method:"DELETE"}),get:(D)=>G({...D,method:"GET"}),getConfig:X,head:(D)=>G({...D,method:"HEAD"}),interceptors:E,options:(D)=>G({...D,method:"OPTIONS"}),patch:(D)=>G({...D,method:"PATCH"}),post:(D)=>G({...D,method:"POST"}),put:(D)=>G({...D,method:"PUT"}),request:G,setConfig:F,trace:(D)=>G({...D,method:"TRACE"})}};var J=j(O({baseUrl:"http://localhost:8080"}));var t=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/export-task/{exportTaskId}",...K})},e=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/export-task/by-external-reference-code/{externalReferenceCode}",...K})},i=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/export-task/by-external-reference-code/{externalReferenceCode}/content",...K})},KK=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/export-task/{exportTaskId}/content",...K})},XK=(K)=>{return(K.client??J).post({url:"/o/headless-batch-engine/v1.0/export-task/{className}/{contentType}",...K})},ZK=(K)=>{return(K.client??J).delete({url:"/o/headless-batch-engine/v1.0/import-task/{className}",...K,headers:{"Content-Type":"application/json",...K.headers}})},BK=(K)=>{return(K.client??J).post({url:"/o/headless-batch-engine/v1.0/import-task/{className}",...K,headers:{"Content-Type":"application/json",...K.headers}})},DK=(K)=>{return(K.client??J).put({url:"/o/headless-batch-engine/v1.0/import-task/{className}",...K,headers:{"Content-Type":"application/json",...K.headers}})},EK=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/import-task/{importTaskId}",...K})},FK=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/import-task/by-external-reference-code/{externalReferenceCode}",...K})},GK=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/import-task/by-external-reference-code/{externalReferenceCode}/content",...K})},HK=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/import-task/by-external-reference-code/{externalReferenceCode}/failed-items/report",...K})},JK=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/import-task/{importTaskId}/content",...K})},QK=(K)=>{return(K.client??J).get({url:"/o/headless-batch-engine/v1.0/import-task/{importTaskId}/failed-items/report",...K})};export{DK as putImportTask1,BK as postImportTask1,XK as postExportTask,QK as getImportTaskFailedItemReport,JK as getImportTaskContent,HK as getImportTaskByExternalReferenceCodeFailedItemReport,GK as getImportTaskByExternalReferenceCodeContent,FK as getImportTaskByExternalReferenceCode,EK as getImportTask,KK as getExportTaskContent,i as getExportTaskByExternalReferenceCodeContent,e as getExportTaskByExternalReferenceCode,t as getExportTask,ZK as deleteImportTask1};