"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.RetryTransportAdapter=void 0;class RetryTransportAdapter{inner;maxRetries;baseDelayMs;maxJitterMs;constructor(e,t={}){this.inner=e,this.maxRetries=t.maxRetries??3,this.baseDelayMs=t.baseDelayMs??1e3,this.maxJitterMs=t.maxJitterMs??200}async send(e,t){let r;for(let s=0;s<=this.maxRetries;s++){const i=await this.inner.send(e,t);if(i.ok)return i;if(r=i.error,s<this.maxRetries){const e=Math.pow(2,s)*this.baseDelayMs,t=new Uint32Array(1);crypto.getRandomValues(t);const r=t[0]/4294967295*this.maxJitterMs*2-this.maxJitterMs;await this.sleep(e+r)}}throw new Error(`Failed after ${this.maxRetries} retries: ${r??"unknown error"}`)}onReceive(e){this.inner.onReceive(e)}dispose(){this.inner.dispose()}sleep(e){return new Promise(t=>setTimeout(t,e))}}exports.RetryTransportAdapter=RetryTransportAdapter;