UNPKG

liferay-headless-rest-client

Version:
2 lines (1 loc) 10.5 kB
var j=async(F,X)=>{let G=typeof X=="function"?await X(F):X;if(G)return F.scheme==="bearer"?`Bearer ${G}`:F.scheme==="basic"?`Basic ${btoa(G)}`:G},O=(F,X,G)=>{typeof G=="string"||G instanceof Blob?F.append(X,G):F.append(X,JSON.stringify(G))};var h={bodySerializer:(F)=>{let X=new FormData;return Object.entries(F).forEach(([G,B])=>{B!=null&&(Array.isArray(B)?B.forEach((k)=>O(X,G,k)):O(X,G,B))}),X}},m={bodySerializer:(F)=>JSON.stringify(F,(X,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","}},g=(F)=>{switch(F){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},x=({allowReserved:F,explode:X,name:G,style:B,value:k})=>{if(!X){let V=(F?k:k.map((J)=>encodeURIComponent(J))).join(b(B));switch(B){case"label":return`.${V}`;case"matrix":return`;${G}=${V}`;case"simple":return V;default:return`${G}=${V}`}}let E=w(B),Z=k.map((V)=>B==="label"||B==="simple"?F?V:encodeURIComponent(V):D({allowReserved:F,name:G,value:V})).join(E);return B==="label"||B==="matrix"?E+Z:Z},D=({allowReserved:F,name:X,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`${X}=${F?G:encodeURIComponent(G)}`},R=({allowReserved:F,explode:X,name:G,style:B,value:k})=>{if(k instanceof Date)return`${G}=${k.toISOString()}`;if(B!=="deepObject"&&!X){let V=[];Object.entries(k).forEach(([P,M])=>{V=[...V,P,F?M:encodeURIComponent(M)]});let J=V.join(",");switch(B){case"form":return`${G}=${J}`;case"label":return`.${J}`;case"matrix":return`;${G}=${J}`;default:return J}}let E=g(B),Z=Object.entries(k).map(([V,J])=>D({allowReserved:F,name:B==="deepObject"?`${G}[${V}]`:V,value:J})).join(E);return B==="label"||B==="matrix"?E+Z:Z},d=/\{[^{}]+\}/g,f=({path:F,url:X})=>{let G=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 J=F[Z];if(J==null)continue;if(Array.isArray(J)){G=G.replace(k,x({explode:E,name:Z,style:V,value:J}));continue}if(typeof J=="object"){G=G.replace(k,R({explode:E,name:Z,style:V,value:J}));continue}if(V==="matrix"){G=G.replace(k,`;${D({name:Z,value:J})}`);continue}let P=encodeURIComponent(V==="label"?`.${J}`:J);G=G.replace(k,P)}return G},S=({allowReserved:F,array:X,object:G}={})=>(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=x({allowReserved:F,explode:!0,name:E,style:"form",value:Z,...X});V&&k.push(V)}else if(typeof Z=="object"){let V=R({allowReserved:F,explode:!0,name:E,style:"deepObject",value:Z,...G});V&&k.push(V)}else{let V=D({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((G)=>X.startsWith(G)))return"blob";if(X.startsWith("text/"))return"text"}},A=async({security:F,...X})=>{for(let G of F){let B=await j(G,X.auth);if(!B)continue;let k=G.name??"Authorization";switch(G.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}},U=(F)=>u({baseUrl:F.baseUrl,path:F.path,query:F.query,querySerializer:typeof F.querySerializer=="function"?F.querySerializer:S(F.querySerializer),url:F.url}),u=({baseUrl:F,path:X,query:G,querySerializer:B,url:k})=>{let E=k.startsWith("/")?k:`/${k}`,Z=(F??"")+E;X&&(Z=f({path:X,url:Z}));let V=G?B(G):"";return V.startsWith("?")&&(V=V.substring(1)),V&&(Z+=`?${V}`),Z},Y=(F,X)=>{let G={...F,...X};return G.baseUrl?.endsWith("/")&&(G.baseUrl=G.baseUrl.substring(0,G.baseUrl.length-1)),G.headers=T(F.headers,X.headers),G},T=(...F)=>{let X=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)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},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 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 G=this.getInterceptorIndex(F);return this._fns[G]?(this._fns[G]=X,F):!1}use(F){return this._fns=[...this._fns,F],this._fns.length-1}},C=()=>({error:new I,request:new I,response:new I}),y=S({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),c={"Content-Type":"application/json"},N=(F={})=>({...m,headers:c,parseAs:"auto",querySerializer:y,...F}),v=(F={})=>{let X=Y(N(),F),G=()=>({...X}),B=(Z)=>(X=Y(X,Z),G()),k=C(),E=async(Z)=>{let V={...X,...Z,fetch:Z.fetch??X.fetch??globalThis.fetch,headers:T(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 J=U(V),P={redirect:"follow",...V},M=new Request(J,P);for(let L of k.request._fns)L&&(M=await L(M,V));let z=V.fetch,K=await z(M);for(let L of k.response._fns)L&&(K=await L(K,M,V));let $={request:M,response:K};if(K.ok){if(K.status===204||K.headers.get("Content-Length")==="0")return V.responseStyle==="data"?{}:{data:{},...$};let L=(V.parseAs==="auto"?_(K.headers.get("Content-Type")):V.parseAs)??"json";if(L==="stream")return V.responseStyle==="data"?K.body:{data:K.body,...$};let W=await K[L]();return L==="json"&&(V.responseValidator&&await V.responseValidator(W),V.responseTransformer&&(W=await V.responseTransformer(W))),V.responseStyle==="data"?W:{data:W,...$}}let q=await K.text();try{q=JSON.parse(q)}catch{}let Q=q;for(let L of k.error._fns)L&&(Q=await L(q,K,M,V));if(Q=Q||{},V.throwOnError)throw Q;return V.responseStyle==="data"?void 0:{error:Q,...$}};return{buildUrl:U,connect:(Z)=>E({...Z,method:"CONNECT"}),delete:(Z)=>E({...Z,method:"DELETE"}),get:(Z)=>E({...Z,method:"GET"}),getConfig:G,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 H=v(N({baseUrl:"http://localhost:8080"}));var s=(F)=>{return(F.client??H).delete({url:"/o/notification/v1.0/notification-queue-entries/{notificationQueueEntryId}",...F})},n=(F)=>{return(F.client??H).get({url:"/o/notification/v1.0/notification-queue-entries/{notificationQueueEntryId}",...F})},t=(F)=>{return(F?.client??H).delete({url:"/o/notification/v1.0/notification-queue-entries/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},i=(F)=>{return(F?.client??H).post({url:"/o/notification/v1.0/notification-queue-entries/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},o=(F)=>{return(F?.client??H).get({url:"/o/notification/v1.0/notification-queue-entries",...F})},FF=(F)=>{return(F?.client??H).post({url:"/o/notification/v1.0/notification-queue-entries",...F,headers:{"Content-Type":"application/json",...F?.headers}})},GF=(F)=>{return(F?.client??H).post({url:"/o/notification/v1.0/notification-queue-entries/export-batch",...F})},VF=(F)=>{return(F.client??H).put({url:"/o/notification/v1.0/notification-queue-entries/{notificationQueueEntryId}/resend",...F})},XF=(F)=>{return(F.client??H).delete({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...F})},ZF=(F)=>{return(F.client??H).get({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...F})},kF=(F)=>{return(F.client??H).patch({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...F,headers:{"Content-Type":"application/json",...F.headers}})},BF=(F)=>{return(F.client??H).put({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...F,headers:{"Content-Type":"application/json",...F.headers}})},EF=(F)=>{return(F?.client??H).delete({url:"/o/notification/v1.0/notification-templates/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},HF=(F)=>{return(F?.client??H).post({url:"/o/notification/v1.0/notification-templates/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},JF=(F)=>{return(F?.client??H).put({url:"/o/notification/v1.0/notification-templates/batch",...F,headers:{"Content-Type":"application/json",...F?.headers}})},KF=(F)=>{return(F.client??H).get({url:"/o/notification/v1.0/notification-templates/by-external-reference-code/{externalReferenceCode}",...F})},LF=(F)=>{return(F.client??H).put({url:"/o/notification/v1.0/notification-templates/by-external-reference-code/{externalReferenceCode}",...F,headers:{"Content-Type":"application/json",...F.headers}})},MF=(F)=>{return(F?.client??H).get({url:"/o/notification/v1.0/notification-templates",...F})},PF=(F)=>{return(F?.client??H).post({url:"/o/notification/v1.0/notification-templates",...F,headers:{"Content-Type":"application/json",...F?.headers}})},QF=(F)=>{return(F.client??H).post({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}/copy",...F})},WF=(F)=>{return(F?.client??H).post({url:"/o/notification/v1.0/notification-templates/export-batch",...F})};export{LF as putNotificationTemplateByExternalReferenceCode,JF as putNotificationTemplateBatch,BF as putNotificationTemplate,VF as putNotificationQueueEntryResend,WF as postNotificationTemplatesPageExportBatch,QF as postNotificationTemplateCopy,HF as postNotificationTemplateBatch,PF as postNotificationTemplate,i as postNotificationQueueEntryBatch,FF as postNotificationQueueEntry,GF as postNotificationQueueEntriesPageExportBatch,kF as patchNotificationTemplate,MF as getNotificationTemplatesPage,KF as getNotificationTemplateByExternalReferenceCode,ZF as getNotificationTemplate,n as getNotificationQueueEntry,o as getNotificationQueueEntriesPage,EF as deleteNotificationTemplateBatch,XF as deleteNotificationTemplate,t as deleteNotificationQueueEntryBatch,s as deleteNotificationQueueEntry};