@@ -29,12 +29,17 @@ export type HermesClientConfig = {
29
29
* it will timeout regardless of the retries at the configured `timeout` time.
30
30
*/
31
31
httpRetries ?: number ;
32
+ /**
33
+ * Optional headers to be included in every request.
34
+ */
35
+ headers ?: HeadersInit ;
32
36
} ;
33
37
34
38
export class HermesClient {
35
39
private baseURL : string ;
36
40
private timeout : DurationInMs ;
37
41
private httpRetries : number ;
42
+ private headers : HeadersInit ;
38
43
39
44
/**
40
45
* Constructs a new Connection.
@@ -46,6 +51,7 @@ export class HermesClient {
46
51
this . baseURL = endpoint ;
47
52
this . timeout = config ?. timeout ?? DEFAULT_TIMEOUT ;
48
53
this . httpRetries = config ?. httpRetries ?? DEFAULT_HTTP_RETRIES ;
54
+ this . headers = config ?. headers ?? { } ;
49
55
}
50
56
51
57
private async httpRequest < ResponseData > (
@@ -58,7 +64,11 @@ export class HermesClient {
58
64
) : Promise < ResponseData > {
59
65
const controller = externalAbortController ?? new AbortController ( ) ;
60
66
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
62
72
63
73
// Set a timeout to abort the request if it takes too long
64
74
const timeout = setTimeout ( ( ) => controller . abort ( ) , this . timeout ) ;
@@ -129,7 +139,7 @@ export class HermesClient {
129
139
parsed ?: boolean ;
130
140
}
131
141
) : Promise < PriceUpdate > {
132
- const url = new URL ( ` v2/updates/price/latest` , this . baseURL ) ;
142
+ const url = new URL ( " v2/updates/price/latest" , this . baseURL ) ;
133
143
for ( const id of ids ) {
134
144
url . searchParams . append ( "ids[]" , id ) ;
135
145
}
@@ -208,7 +218,7 @@ export class HermesClient {
208
218
this . appendUrlSearchParams ( url , transformedOptions ) ;
209
219
}
210
220
211
- return new EventSource ( url . toString ( ) ) ;
221
+ return new EventSource ( url . toString ( ) , { headers : this . headers } ) ;
212
222
}
213
223
214
224
private appendUrlSearchParams (
0 commit comments