@@ -122,18 +122,21 @@ export class EVaultClient {
122122 private httpClient : AxiosInstance ;
123123 private isDisposed = false ;
124124
125- constructor ( private registryUrl : string , private platform : string ) {
125+ constructor (
126+ private registryUrl : string ,
127+ private platform : string ,
128+ ) {
126129 // Configure axios with connection pooling and timeouts
127130 this . httpClient = axios . create ( {
128131 timeout : CONFIG . REQUEST_TIMEOUT ,
129132 maxRedirects : 3 ,
130133 // Connection pooling configuration
131- httpAgent : new ( require ( ' http' ) . Agent ) ( {
134+ httpAgent : new ( require ( " http" ) . Agent ) ( {
132135 keepAlive : true ,
133136 maxSockets : CONFIG . CONNECTION_POOL_SIZE ,
134137 timeout : CONFIG . CONNECTION_TIMEOUT ,
135138 } ) ,
136- httpsAgent : new ( require ( ' https' ) . Agent ) ( {
139+ httpsAgent : new ( require ( " https" ) . Agent ) ( {
137140 keepAlive : true ,
138141 maxSockets : CONFIG . CONNECTION_POOL_SIZE ,
139142 timeout : CONFIG . CONNECTION_TIMEOUT ,
@@ -146,12 +149,12 @@ export class EVaultClient {
146149 */
147150 public dispose ( ) : void {
148151 if ( this . isDisposed ) return ;
149-
152+
150153 this . isDisposed = true ;
151154 this . client = null ;
152155 this . endpoint = null ;
153156 this . tokenInfo = null ;
154-
157+
155158 // Close HTTP agents to free connections
156159 if ( this . httpClient . defaults . httpAgent ) {
157160 this . httpClient . defaults . httpAgent . destroy ( ) ;
@@ -166,36 +169,36 @@ export class EVaultClient {
166169 */
167170 private async withRetry < T > (
168171 operation : ( ) => Promise < T > ,
169- maxRetries : number = CONFIG . MAX_RETRIES
172+ maxRetries : number = CONFIG . MAX_RETRIES ,
170173 ) : Promise < T > {
171174 let lastError : Error ;
172-
175+
173176 for ( let attempt = 0 ; attempt <= maxRetries ; attempt ++ ) {
174177 try {
175178 return await operation ( ) ;
176179 } catch ( error ) {
177180 lastError = error as Error ;
178-
181+
179182 // Don't retry on the last attempt
180183 if ( attempt === maxRetries ) break ;
181-
184+
182185 // Don't retry on certain errors
183186 if ( error instanceof Error ) {
184187 const isRetryable = ! (
185- error . message . includes ( ' 401' ) ||
186- error . message . includes ( ' 403' ) ||
187- error . message . includes ( ' 404' )
188+ error . message . includes ( " 401" ) ||
189+ error . message . includes ( " 403" ) ||
190+ error . message . includes ( " 404" )
188191 ) ;
189-
192+
190193 if ( ! isRetryable ) break ;
191194 }
192-
195+
193196 // Exponential backoff
194197 const delay = CONFIG . RETRY_DELAY * Math . pow ( 2 , attempt ) ;
195- await new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
198+ await new Promise ( ( resolve ) => setTimeout ( resolve , delay ) ) ;
196199 }
197200 }
198-
201+
199202 throw lastError ! ;
200203 }
201204
@@ -206,19 +209,22 @@ export class EVaultClient {
206209 private async requestPlatformToken ( ) : Promise < TokenInfo > {
207210 try {
208211 const response = await this . httpClient . post < PlatformTokenResponse > (
209- new URL ( "/platforms/certification" , this . registryUrl ) . toString ( ) ,
212+ new URL (
213+ "/platforms/certification" ,
214+ this . registryUrl ,
215+ ) . toString ( ) ,
210216 { platform : this . platform } ,
211217 {
212218 headers : {
213219 "Content-Type" : "application/json" ,
214220 } ,
215221 timeout : CONFIG . REQUEST_TIMEOUT ,
216- }
222+ } ,
217223 ) ;
218-
224+
219225 const now = Date . now ( ) ;
220- const expiresAt = response . data . expiresAt || ( now + 3600000 ) ; // Default 1 hour
221-
226+ const expiresAt = response . data . expiresAt || now + 3600000 ; // Default 1 hour
227+
222228 return {
223229 token : response . data . token ,
224230 expiresAt,
@@ -235,10 +241,10 @@ export class EVaultClient {
235241 */
236242 private isTokenExpired ( ) : boolean {
237243 if ( ! this . tokenInfo ) return true ;
238-
244+
239245 const now = Date . now ( ) ;
240246 const timeUntilExpiry = this . tokenInfo . expiresAt - now ;
241-
247+
242248 return timeUntilExpiry <= CONFIG . TOKEN_REFRESH_THRESHOLD ;
243249 }
244250
@@ -259,7 +265,7 @@ export class EVaultClient {
259265 new URL ( `/resolve?w3id=${ w3id } ` , this . registryUrl ) . toString ( ) ,
260266 {
261267 timeout : CONFIG . REQUEST_TIMEOUT ,
262- }
268+ } ,
263269 ) ;
264270 return new URL ( "/graphql" , response . data . uri ) . toString ( ) ;
265271 } catch ( error ) {
@@ -294,7 +300,7 @@ export class EVaultClient {
294300 return null ;
295301 } ) ;
296302 if ( ! client ) return v4 ( ) ;
297-
303+
298304 console . log ( "sending payload" , envelope ) ;
299305
300306 const response = await client
@@ -306,7 +312,7 @@ export class EVaultClient {
306312 } ,
307313 } )
308314 . catch ( ( ) => null ) ;
309-
315+
310316 if ( ! response ) return v4 ( ) ;
311317 return response . storeMetaEnvelope . metaEnvelope . id ;
312318 } ) ;
@@ -327,7 +333,7 @@ export class EVaultClient {
327333 } ,
328334 } )
329335 . catch ( ( ) => null ) ;
330-
336+
331337 if ( ! response ) {
332338 console . error ( "Failed to store reference" ) ;
333339 throw new Error ( "Failed to store reference" ) ;
@@ -345,7 +351,7 @@ export class EVaultClient {
345351 {
346352 id,
347353 w3id,
348- }
354+ } ,
349355 ) ;
350356 return response . metaEnvelope ;
351357 } catch ( error ) {
@@ -357,12 +363,15 @@ export class EVaultClient {
357363
358364 async updateMetaEnvelopeById (
359365 id : string ,
360- envelope : MetaEnvelope
366+ envelope : MetaEnvelope ,
361367 ) : Promise < void > {
362368 return this . withRetry ( async ( ) => {
363369 console . log ( "sending to eVault" , envelope . w3id ) ;
364- const client = await this . ensureClient ( envelope . w3id ) . catch ( ( ) => null ) ;
365- if ( ! client ) throw new Error ( "Failed to establish client connection" ) ;
370+ const client = await this . ensureClient ( envelope . w3id ) . catch (
371+ ( ) => null ,
372+ ) ;
373+ if ( ! client )
374+ throw new Error ( "Failed to establish client connection" ) ;
366375
367376 try {
368377 const variables = {
@@ -374,10 +383,11 @@ export class EVaultClient {
374383 } ,
375384 } ;
376385
377- const response = await client . request < StoreMetaEnvelopeResponse > (
378- UPDATE_META_ENVELOPE ,
379- variables
380- ) ;
386+ const response =
387+ await client . request < StoreMetaEnvelopeResponse > (
388+ UPDATE_META_ENVELOPE ,
389+ variables ,
390+ ) ;
381391 } catch ( error ) {
382392 console . error ( "Error updating meta envelope:" , error ) ;
383393 throw error ;
0 commit comments