-
Notifications
You must be signed in to change notification settings - Fork 77
Open
Labels
tech-debtTechnical debtTechnical debt
Description
Why
Currently all @akashnetwork/http-sdk services extend AxiosInstance. It breaks encapsulation and makes it harder to configure app because every service requires configuration of the same interceptors and configurations. Take a look at https://github.com/akash-network/console/blob/main/apps/deploy-web/src/services/http-factory/http-factory.service.ts#L16
Additionally switching to 1 or few axios instances would make it easier to configure axios to use fetch adapter -> #1423
What
Refactor http services to NOT extend axios instance and instead utilize composition:
Having one (or few) axios instance we could configure this once and pass it to every service. For example this code:
const apiConfig = { baseURL: config.BASE_API_MAINNET_URL };
return createContainer({
user: () =>
withInterceptors(new UserHttpService(apiConfig), {
request: [config.globalRequestMiddleware, authService.withAnonymousUserHeader],
response: [
response => {
if (response.config.url?.startsWith("/v1/anonymous-users") && response.config.method === "post" && response.status === 200) {
analyticsService.track("anonymous_user_created", { category: "user", label: "Anonymous User Created" });
}
return response;
}
]
}),would become this:
const mainnetAdapter = axios.create({ baseURL: config.BASE_API_MAINNET_URL });
mainnetAdapter.intercetors.use([config.globalRequestMiddleware, authService.withAnonymousUserHeader], response => {
if (response.config.url?.startsWith("/v1/anonymous-users") && response.config.method === "post" && response.status === 200) {
analyticsService.track("anonymous_user_created", { category: "user", label: "Anonymous User Created" });
}
return response;
});
return createContainer({
user: () => new UserHttpService(mainnetAdapter),
stripe: () => new StripeService(mainnetAdapter),
})Metadata
Metadata
Assignees
Labels
tech-debtTechnical debtTechnical debt