node-ovh-ts
Version:
OVH API wrapper library for TypeScript
2 lines • 904 B
JavaScript
import{a as h}from"./chunk-EO3LCX2M.mjs";import{createHash as u}from"crypto";var p=class{constructor(t,e,s,i){this.appKey=t,this.appSecret=e,this.consumerKey=s,this.options={endpoint:"ovh-eu",...i}}async request(t,e,s){let i=h[this.options.endpoint].host,n={"Content-Type":"application/json","X-Ovh-Application":this.appKey,"X-Ovh-Consumer":this.consumerKey,"X-Ovh-Timestamp":`${Math.round(Date.now()/1e3)}`},o=null;s&&(o=JSON.stringify(s),n["Content-Length"]=o.length);let a=`https://${i}/1.0${e}`;n["X-Ovh-Signature"]=this.signRequest(t,a,o,n["X-Ovh-Timestamp"]);let r=await fetch(a,{headers:n,method:t,body:o});if(r.status!==200)throw new Error(`OVH API error: ${r.status} ${r.statusText}`);return r.json()}signRequest(t,e,s,i){let n=[this.appSecret,this.consumerKey,t,e,s||"",i];return"$1$"+u("sha1").update(n.join("+")).digest("hex")}},m=p;export{m as a};
//# sourceMappingURL=chunk-7MAL63F5.mjs.map