import{a as t}from"./targeting-min.js";import{g as e}from"./index-min.js";class s{constructor(){this.fetchObserver=null}start(t){this.eventCallback=t,this.observeFetch()}stop(){var t;null===(t=this.fetchObserver)||void 0===t||t.call(this),this.fetchObserver=null,this.eventCallback=void 0}notifyEvent(t){var e;null===(e=this.eventCallback)||void 0===e||e.call(this,t)}observeFetch(){const s=e();if(!s)return;const r=s.fetch;r&&(s.fetch=(e,s)=>t(this,void 0,void 0,(function*(){const t=Date.now(),n={timestamp:t,type:"fetch",method:(null==s?void 0:s.method)||"GET",url:e.toString(),requestHeaders:null==s?void 0:s.headers};try{const o=yield r(e,s),i=Date.now();n.status=o.status,n.duration=i-t;const a={};return o.headers.forEach(((t,e)=>{a[e]=t})),n.responseHeaders=a,this.notifyEvent(n),o}catch(e){const s=Date.now();n.duration=s-t;const r=e;throw n.error={name:r.name||"UnknownError",message:r.message||"An unknown error occurred"},this.notifyEvent(n),e}})),this.fetchObserver=()=>{s.fetch=r})}}export{s as NetworkObservers};
//# sourceMappingURL=observers-min.js.map
