class h{constructor(e,o,t,i){this.url=e,this.user=o,this.pwd=t,this.apiKey=i,this.id=0}async sendQuery(e,o){let t=new Headers;t.append("x-api-key",this.apiKey);let i=btoa(this.user+":"+this.pwd);t.append("Authorization","Basic "+i),t.append("Content-type","application/json");let n=++this.id,s=await fetch(this.url,{headers:t,mode:"cors",cache:"no-cache",method:"POST",body:JSON.stringify({method:e,params:o,id:n})});if(s.ok){let r=await s.json();if(r.id!=n)throw new Error("L'identifiant de la réponse ne correspond pas");if(r.error==="no session"){let a=new Event("reconnection");window.dispatchEvent(a);return}if(r.error)throw new Error(r.error);return r.result}throw new Error("Impossible de joindre le webservice !")}async getCatalog(){let e=await fetch(this.url,{cache:"no-cache",headers:{"Content-type":"application/json"},method:"GET"});if(e.ok)return await e.json();throw new Error("Impossible de joindre le webservice !")}}export{h as default};
