Skip to content

Commit 2ec721d

Browse files
committed
chore: change to fetch
1 parent 2fabcc6 commit 2ec721d

File tree

1 file changed

+12
-38
lines changed
  • infrastructure/web3-adapter/src/evault

1 file changed

+12
-38
lines changed

infrastructure/web3-adapter/src/evault/evault.ts

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Agent } from "node:http";
2-
import axios, { type AxiosInstance } from "axios";
31
import { GraphQLClient } from "graphql-request";
42
import { v4 } from "uuid";
53

@@ -127,30 +125,12 @@ export class EVaultClient {
127125
private client: GraphQLClient | null = null;
128126
private endpoint: string | null = null;
129127
private tokenInfo: TokenInfo | null = null;
130-
private httpClient: AxiosInstance;
131128
private isDisposed = false;
132129

133130
constructor(
134131
private registryUrl: string,
135132
private platform: string,
136-
) {
137-
// Configure axios with connection pooling and timeouts
138-
this.httpClient = axios.create({
139-
timeout: CONFIG.REQUEST_TIMEOUT,
140-
maxRedirects: 3,
141-
// Connection pooling configuration
142-
httpAgent: new Agent({
143-
keepAlive: true,
144-
maxSockets: CONFIG.CONNECTION_POOL_SIZE,
145-
timeout: CONFIG.CONNECTION_TIMEOUT,
146-
}),
147-
httpsAgent: new Agent({
148-
keepAlive: true,
149-
maxSockets: CONFIG.CONNECTION_POOL_SIZE,
150-
timeout: CONFIG.CONNECTION_TIMEOUT,
151-
}),
152-
});
153-
}
133+
) {}
154134

155135
/**
156136
* Cleanup method to properly dispose of resources
@@ -162,14 +142,6 @@ export class EVaultClient {
162142
this.client = null;
163143
this.endpoint = null;
164144
this.tokenInfo = null;
165-
166-
// Close HTTP agents to free connections
167-
if (this.httpClient.defaults.httpAgent) {
168-
this.httpClient.defaults.httpAgent.destroy();
169-
}
170-
if (this.httpClient.defaults.httpsAgent) {
171-
this.httpClient.defaults.httpsAgent.destroy();
172-
}
173145
}
174146

175147
/**
@@ -217,25 +189,27 @@ export class EVaultClient {
217189
*/
218190
private async requestPlatformToken(): Promise<TokenInfo> {
219191
try {
220-
const response = await this.httpClient.post<PlatformTokenResponse>(
221-
new URL(
222-
"/platforms/certification",
223-
this.registryUrl,
224-
).toString(),
225-
{ platform: this.platform },
192+
const response = await fetch(
193+
new URL("/platforms/certification", this.registryUrl).toString(),
226194
{
195+
method: "POST",
227196
headers: {
228197
"Content-Type": "application/json",
229198
},
230-
timeout: CONFIG.REQUEST_TIMEOUT,
199+
body: JSON.stringify({ platform: this.platform }),
231200
},
232201
);
233202

203+
if (!response.ok) {
204+
throw new Error(`HTTP error! status: ${response.status}`);
205+
}
206+
207+
const data = await response.json() as PlatformTokenResponse;
234208
const now = Date.now();
235-
const expiresAt = response.data.expiresAt || now + 3600000; // Default 1 hour
209+
const expiresAt = data.expiresAt || now + 3600000; // Default 1 hour
236210

237211
return {
238-
token: response.data.token,
212+
token: data.token,
239213
expiresAt,
240214
obtainedAt: now,
241215
};

0 commit comments

Comments
 (0)