UNPKG

liferay-headless-rest-client

Version:
2 lines (1 loc) 10.7 kB
var j=async(X,E)=>{let Z=typeof E=="function"?await E(X):E;if(Z)return X.scheme==="bearer"?`Bearer ${Z}`:X.scheme==="basic"?`Basic ${btoa(Z)}`:Z},U=(X,E,Z)=>{typeof Z=="string"||Z instanceof Blob?X.append(E,Z):X.append(E,JSON.stringify(Z))};var l={bodySerializer:(X)=>{let E=new FormData;return Object.entries(X).forEach(([Z,H])=>{H!=null&&(Array.isArray(H)?H.forEach((G)=>U(E,Z,G)):U(E,Z,H))}),E}},m={bodySerializer:(X)=>JSON.stringify(X,(E,Z)=>typeof Z=="bigint"?Z.toString():Z)};var w={$body_:"body",$headers_:"headers",$path_:"path",$query_:"query"},a=Object.entries(w);var b=(X)=>{switch(X){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},g=(X)=>{switch(X){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},d=(X)=>{switch(X){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},S=({allowReserved:X,explode:E,name:Z,style:H,value:G})=>{if(!E){let B=(X?G:G.map((Q)=>encodeURIComponent(Q))).join(g(H));switch(H){case"label":return`.${B}`;case"matrix":return`;${Z}=${B}`;case"simple":return B;default:return`${Z}=${B}`}}let J=b(H),F=G.map((B)=>H==="label"||H==="simple"?X?B:encodeURIComponent(B):N({allowReserved:X,name:Z,value:B})).join(J);return H==="label"||H==="matrix"?J+F:F},N=({allowReserved:X,name:E,value:Z})=>{if(Z==null)return"";if(typeof Z=="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${E}=${X?Z:encodeURIComponent(Z)}`},T=({allowReserved:X,explode:E,name:Z,style:H,value:G,valueOnly:J})=>{if(G instanceof Date)return J?G.toISOString():`${Z}=${G.toISOString()}`;if(H!=="deepObject"&&!E){let Q=[];Object.entries(G).forEach(([k,I])=>{Q=[...Q,k,X?I:encodeURIComponent(I)]});let $=Q.join(",");switch(H){case"form":return`${Z}=${$}`;case"label":return`.${$}`;case"matrix":return`;${Z}=${$}`;default:return $}}let F=d(H),B=Object.entries(G).map(([Q,$])=>N({allowReserved:X,name:H==="deepObject"?`${Z}[${Q}]`:Q,value:$})).join(F);return H==="label"||H==="matrix"?F+B:B},f=/\{[^{}]+\}/g,A=({path:X,url:E})=>{let Z=E,H=E.match(f);if(H)for(let G of H){let J=!1,F=G.substring(1,G.length-1),B="simple";F.endsWith("*")&&(J=!0,F=F.substring(0,F.length-1)),F.startsWith(".")?(F=F.substring(1),B="label"):F.startsWith(";")&&(F=F.substring(1),B="matrix");let Q=X[F];if(Q==null)continue;if(Array.isArray(Q)){Z=Z.replace(G,S({explode:J,name:F,style:B,value:Q}));continue}if(typeof Q=="object"){Z=Z.replace(G,T({explode:J,name:F,style:B,value:Q,valueOnly:!0}));continue}if(B==="matrix"){Z=Z.replace(G,`;${N({name:F,value:Q})}`);continue}let $=encodeURIComponent(B==="label"?`.${Q}`:Q);Z=Z.replace(G,$)}return Z},v=({allowReserved:X,array:E,object:Z}={})=>(H)=>{let G=[];if(H&&typeof H=="object")for(let J in H){let F=H[J];if(F!=null)if(Array.isArray(F)){let B=S({allowReserved:X,explode:!0,name:J,style:"form",value:F,...E});B&&G.push(B)}else if(typeof F=="object"){let B=T({allowReserved:X,explode:!0,name:J,style:"deepObject",value:F,...Z});B&&G.push(B)}else{let B=N({allowReserved:X,name:J,value:F});B&&G.push(B)}}return G.join("&")},_=(X)=>{if(!X)return"stream";let E=X.split(";")[0]?.trim();if(E){if(E.startsWith("application/json")||E.endsWith("+json"))return"json";if(E==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some((Z)=>E.startsWith(Z)))return"blob";if(E.startsWith("text/"))return"text"}},C=async({security:X,...E})=>{for(let Z of X){let H=await j(Z,E.auth);if(!H)continue;let G=Z.name??"Authorization";switch(Z.in){case"query":E.query||(E.query={}),E.query[G]=H;break;case"cookie":E.headers.append("Cookie",`${G}=${H}`);break;case"header":default:E.headers.set(G,H);break}return}},Y=(X)=>u({baseUrl:X.baseUrl,path:X.path,query:X.query,querySerializer:typeof X.querySerializer=="function"?X.querySerializer:v(X.querySerializer),url:X.url}),u=({baseUrl:X,path:E,query:Z,querySerializer:H,url:G})=>{let J=G.startsWith("/")?G:`/${G}`,F=(X??"")+J;E&&(F=A({path:E,url:F}));let B=Z?H(Z):"";return B.startsWith("?")&&(B=B.substring(1)),B&&(F+=`?${B}`),F},x=(X,E)=>{let Z={...X,...E};return Z.baseUrl?.endsWith("/")&&(Z.baseUrl=Z.baseUrl.substring(0,Z.baseUrl.length-1)),Z.headers=z(X.headers,E.headers),Z},z=(...X)=>{let E=new Headers;for(let Z of X){if(!Z||typeof Z!="object")continue;let H=Z instanceof Headers?Z.entries():Object.entries(Z);for(let[G,J]of H)if(J===null)E.delete(G);else if(Array.isArray(J))for(let F of J)E.append(G,F);else J!==void 0&&E.set(G,typeof J=="object"?JSON.stringify(J):J)}return E},O=class{_fns;constructor(){this._fns=[]}clear(){this._fns=[]}getInterceptorIndex(X){return typeof X=="number"?this._fns[X]?X:-1:this._fns.indexOf(X)}exists(X){let E=this.getInterceptorIndex(X);return!!this._fns[E]}eject(X){let E=this.getInterceptorIndex(X);this._fns[E]&&(this._fns[E]=null)}update(X,E){let Z=this.getInterceptorIndex(X);return this._fns[Z]?(this._fns[Z]=E,X):!1}use(X){return this._fns=[...this._fns,X],this._fns.length-1}},y=()=>({error:new O,request:new O,response:new O}),c=v({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),h={"Content-Type":"application/json"},P=(X={})=>({...m,headers:h,parseAs:"auto",querySerializer:c,...X}),R=(X={})=>{let E=x(P(),X),Z=()=>({...E}),H=(F)=>(E=x(E,F),Z()),G=y(),J=async(F)=>{let B={...E,...F,fetch:F.fetch??E.fetch??globalThis.fetch,headers:z(E.headers,F.headers)};B.security&&await C({...B,security:B.security}),B.body&&B.bodySerializer&&(B.body=B.bodySerializer(B.body)),(B.body===void 0||B.body==="")&&B.headers.delete("Content-Type");let Q=Y(B),$={redirect:"follow",...B},k=new Request(Q,$);for(let W of G.request._fns)W&&(k=await W(k,B));let I=B.fetch,V=await I(k);for(let W of G.response._fns)W&&(V=await W(V,k,B));let L={request:k,response:V};if(V.ok){if(V.status===204||V.headers.get("Content-Length")==="0")return B.responseStyle==="data"?{}:{data:{},...L};let W=(B.parseAs==="auto"?_(V.headers.get("Content-Type")):B.parseAs)??"json";if(W==="stream")return B.responseStyle==="data"?V.body:{data:V.body,...L};let D=await V[W]();return W==="json"&&(B.responseValidator&&await B.responseValidator(D),B.responseTransformer&&(D=await B.responseTransformer(D))),B.responseStyle==="data"?D:{data:D,...L}}let M=await V.text();try{M=JSON.parse(M)}catch{}let q=M;for(let W of G.error._fns)W&&(q=await W(M,V,k,B));if(q=q||{},B.throwOnError)throw q;return B.responseStyle==="data"?void 0:{error:q,...L}};return{buildUrl:Y,connect:(F)=>J({...F,method:"CONNECT"}),delete:(F)=>J({...F,method:"DELETE"}),get:(F)=>J({...F,method:"GET"}),getConfig:Z,head:(F)=>J({...F,method:"HEAD"}),interceptors:G,options:(F)=>J({...F,method:"OPTIONS"}),patch:(F)=>J({...F,method:"PATCH"}),post:(F)=>J({...F,method:"POST"}),put:(F)=>J({...F,method:"PUT"}),request:J,setConfig:H,trace:(F)=>J({...F,method:"TRACE"})}};var K=R(P({baseUrl:"http://localhost:8080"}));var t=(X)=>{return(X.client??K).delete({url:"/o/notification/v1.0/notification-queue-entries/{notificationQueueEntryId}",...X})},i=(X)=>{return(X.client??K).get({url:"/o/notification/v1.0/notification-queue-entries/{notificationQueueEntryId}",...X})},o=(X)=>{return(X?.client??K).delete({url:"/o/notification/v1.0/notification-queue-entries/batch",...X,headers:{"Content-Type":"application/json",...X?.headers}})},XX=(X)=>{return(X?.client??K).post({url:"/o/notification/v1.0/notification-queue-entries/batch",...X,headers:{"Content-Type":"application/json",...X?.headers}})},ZX=(X)=>{return(X?.client??K).get({url:"/o/notification/v1.0/notification-queue-entries",...X})},BX=(X)=>{return(X?.client??K).post({url:"/o/notification/v1.0/notification-queue-entries",...X,headers:{"Content-Type":"application/json",...X?.headers}})},EX=(X)=>{return(X?.client??K).post({url:"/o/notification/v1.0/notification-queue-entries/export-batch",...X})},FX=(X)=>{return(X.client??K).put({url:"/o/notification/v1.0/notification-queue-entries/{notificationQueueEntryId}/resend",...X})},GX=(X)=>{return(X.client??K).delete({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...X})},HX=(X)=>{return(X.client??K).get({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...X})},JX=(X)=>{return(X.client??K).patch({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...X,headers:{"Content-Type":"application/json",...X.headers}})},KX=(X)=>{return(X.client??K).put({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}",...X,headers:{"Content-Type":"application/json",...X.headers}})},QX=(X)=>{return(X?.client??K).delete({url:"/o/notification/v1.0/notification-templates/batch",...X,headers:{"Content-Type":"application/json",...X?.headers}})},VX=(X)=>{return(X?.client??K).post({url:"/o/notification/v1.0/notification-templates/batch",...X,headers:{"Content-Type":"application/json",...X?.headers}})},WX=(X)=>{return(X?.client??K).put({url:"/o/notification/v1.0/notification-templates/batch",...X,headers:{"Content-Type":"application/json",...X?.headers}})},$X=(X)=>{return(X.client??K).get({url:"/o/notification/v1.0/notification-templates/by-external-reference-code/{externalReferenceCode}",...X})},kX=(X)=>{return(X.client??K).put({url:"/o/notification/v1.0/notification-templates/by-external-reference-code/{externalReferenceCode}",...X,headers:{"Content-Type":"application/json",...X.headers}})},qX=(X)=>{return(X?.client??K).get({url:"/o/notification/v1.0/notification-templates",...X})},DX=(X)=>{return(X?.client??K).post({url:"/o/notification/v1.0/notification-templates",...X,headers:{"Content-Type":"application/json",...X?.headers}})},IX=(X)=>{return(X.client??K).post({url:"/o/notification/v1.0/notification-templates/{notificationTemplateId}/copy",...X})},LX=(X)=>{return(X?.client??K).post({url:"/o/notification/v1.0/notification-templates/export-batch",...X})};export{kX as putNotificationTemplateByExternalReferenceCode,WX as putNotificationTemplateBatch,KX as putNotificationTemplate,FX as putNotificationQueueEntryResend,LX as postNotificationTemplatesPageExportBatch,IX as postNotificationTemplateCopy,VX as postNotificationTemplateBatch,DX as postNotificationTemplate,XX as postNotificationQueueEntryBatch,BX as postNotificationQueueEntry,EX as postNotificationQueueEntriesPageExportBatch,JX as patchNotificationTemplate,qX as getNotificationTemplatesPage,$X as getNotificationTemplateByExternalReferenceCode,HX as getNotificationTemplate,i as getNotificationQueueEntry,ZX as getNotificationQueueEntriesPage,QX as deleteNotificationTemplateBatch,GX as deleteNotificationTemplate,o as deleteNotificationQueueEntryBatch,t as deleteNotificationQueueEntry};