@@ -29,12 +29,17 @@ export type HermesClientConfig = {
2929 * it will timeout regardless of the retries at the configured `timeout` time.
3030 */
3131 httpRetries ?: number ;
32+ /**
33+ * Optional headers to be included in every request.
34+ */
35+ headers ?: HeadersInit ;
3236} ;
3337
3438export class HermesClient {
3539 private baseURL : string ;
3640 private timeout : DurationInMs ;
3741 private httpRetries : number ;
42+ private headers : HeadersInit ;
3843
3944 /**
4045 * Constructs a new Connection.
@@ -46,6 +51,7 @@ export class HermesClient {
4651 this . baseURL = endpoint ;
4752 this . timeout = config ?. timeout ?? DEFAULT_TIMEOUT ;
4853 this . httpRetries = config ?. httpRetries ?? DEFAULT_HTTP_RETRIES ;
54+ this . headers = config ?. headers ?? { } ;
4955 }
5056
5157 private async httpRequest < ResponseData > (
@@ -58,7 +64,11 @@ export class HermesClient {
5864 ) : Promise < ResponseData > {
5965 const controller = externalAbortController ?? new AbortController ( ) ;
6066 const { signal } = controller ;
61- options = { ...options , signal } ; // Merge any existing options with the signal
67+ options = {
68+ ...options ,
69+ signal,
70+ headers : { ...this . headers , ...options ?. headers } ,
71+ } ; // Merge any existing options with the signal and headers
6272
6373 // Set a timeout to abort the request if it takes too long
6474 const timeout = setTimeout ( ( ) => controller . abort ( ) , this . timeout ) ;
@@ -129,7 +139,7 @@ export class HermesClient {
129139 parsed ?: boolean ;
130140 }
131141 ) : Promise < PriceUpdate > {
132- const url = new URL ( ` v2/updates/price/latest` , this . baseURL ) ;
142+ const url = new URL ( " v2/updates/price/latest" , this . baseURL ) ;
133143 for ( const id of ids ) {
134144 url . searchParams . append ( "ids[]" , id ) ;
135145 }
@@ -208,7 +218,7 @@ export class HermesClient {
208218 this . appendUrlSearchParams ( url , transformedOptions ) ;
209219 }
210220
211- return new EventSource ( url . toString ( ) ) ;
221+ return new EventSource ( url . toString ( ) , { headers : this . headers } ) ;
212222 }
213223
214224 private appendUrlSearchParams (
0 commit comments