UNPKG

@embrace-io/web-sdk

Version:
3 lines (2 loc) 1.68 kB
import{__awaiter as e,__generator as t,__values as r,__assign as n}from"tslib";var o=function(){function o(e){this._config=e}return o._compressRequest=function(n){return e(this,void 0,void 0,(function(){var e,o,s,i,a,u,c,l,h,f,d,p,g;return t(this,(function(t){switch(t.label){case 0:e=new CompressionStream("gzip"),(o=e.writable.getWriter()).write(n),o.close(),s=[],i=e.readable.getReader(),a=!1,t.label=1;case 1:return a?[3,3]:[4,i.read()];case 2:return(u=t.sent()).value&&s.push(u.value),a=u.done,[3,1];case 3:c=new Uint8Array(s.reduce((function(e,t){return e+t.length}),0)),l=0;try{for(h=r(s),f=h.next();!f.done;f=h.next())d=f.value,c.set(d,l),l+=d.length}catch(e){p={error:e}}finally{try{f&&!f.done&&(g=h.return)&&g.call(h)}finally{if(p)throw p.error}}return[2,c]}}))}))},o.prototype.send=function(e,t){return this._asyncSend(e,t)},o.prototype.shutdown=function(){},o.prototype._asyncSend=function(r,s){return e(this,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return e=r,i=n({"Content-Type":"application/json"},this._config.headers),"gzip"!==this._config.compression?[3,2]:[4,o._compressRequest(r)];case 1:e=t.sent(),i["Content-Encoding"]="gzip",i["Content-Length"]=e.length.toString(),t.label=2;case 2:return t.trys.push([2,4,,5]),[4,fetch(this._config.url,{method:"POST",keepalive:!0,headers:i,body:e,signal:AbortSignal.timeout(s)})];case 3:return t.sent().ok?[2,{status:"success"}]:[2,{status:"failure",error:new Error("Fetch request failed")}];case 4:return t.sent(),[2,{status:"failure",error:new Error("Fetch request errored")}];case 5:return[2]}}))}))},o}();export{o as FetchTransport}; //# sourceMappingURL=FetchTransport.js.map