@@ -13,7 +13,7 @@ import { StripeService } from "@akashnetwork/http-sdk/src/stripe/stripe.service"
1313import  {  LoggerService  }  from  "@akashnetwork/logging" ; 
1414import  {  getTraceData  }  from  "@sentry/nextjs" ; 
1515import  {  MutationCache ,  QueryCache ,  QueryClient  }  from  "@tanstack/react-query" ; 
16- import  type  {  Axios ,  AxiosInstance ,  AxiosResponse ,  CreateAxiosDefaults ,  InternalAxiosRequestConfig  }  from  "axios" ; 
16+ import  type  {  Axios ,  AxiosInstance ,  AxiosRequestConfig ,   AxiosResponse ,  CreateAxiosDefaults ,  InternalAxiosRequestConfig  }  from  "axios" ; 
1717import  axios  from  "axios" ; 
1818
1919import  {  analyticsService  }  from  "@src/services/analytics/analytics.service" ; 
@@ -27,7 +27,30 @@ import { ProviderProxyService } from "../provider-proxy/provider-proxy.service";
2727
2828export  const  createAppRootContainer  =  ( config : ServicesConfig )  =>  { 
2929  const  apiConfig  =  {  baseURL : config . BASE_API_MAINNET_URL  } ; 
30+ 
3031  const  container  =  createContainer ( { 
32+     getAxiosInstance : ( )  =>  ( config ?: AxiosRequestConfig )  =>  { 
33+       const  {  headers,  ...defaults  }  =  axios . defaults ; 
34+ 
35+       return  axios . create ( { 
36+         ...defaults , 
37+         ...config 
38+       } ) ; 
39+     } , 
40+     axiosWithDefaultInterceptors : ( )  =>  ( config ?: AxiosRequestConfig )  =>  { 
41+       return  container . applyAxiosInterceptors ( container . getAxiosInstance ( config ) ,  { 
42+         request : [ container . authService . withAnonymousUserHeader ] 
43+       } ) ; 
44+     } , 
45+ 
46+     defaultAxios : ( )  =>  container . axiosWithDefaultInterceptors ( ) , 
47+     mainnetAxios : ( )  =>  container . axiosWithDefaultInterceptors ( apiConfig ) , 
48+     mainNetAxiosWithNoAnonymousUserHeaderInterceptor : ( )  =>  container . applyAxiosInterceptors ( container . getAxiosInstance ( apiConfig ) ) , 
49+     managedWalletAxios : ( )  => 
50+       container . axiosWithDefaultInterceptors ( { 
51+         baseURL : container . apiUrlService . getBaseApiUrlFor ( config . MANAGED_WALLET_NETWORK_ID ) 
52+       } ) , 
53+ 
3154    getTraceData : ( )  =>  getTraceData , 
3255    applyAxiosInterceptors : ( ) : typeof  withInterceptors  =>  { 
3356      const  otelInterceptor  =  ( config : InternalAxiosRequestConfig )  =>  { 
@@ -36,51 +59,37 @@ export const createAppRootContainer = (config: ServicesConfig) => {
3659        if  ( traceData ?. baggage )  config . headers . set ( "Baggage" ,  traceData . baggage ) ; 
3760        return  config ; 
3861      } ; 
62+ 
3963      return  ( axiosInstance ,  interceptors ?)  => 
4064        withInterceptors ( axiosInstance ,  { 
4165          request : [ config . globalRequestMiddleware ,  otelInterceptor ,  ...( interceptors ?. request  ||  [ ] ) ] , 
42-           response : [ ...( interceptors ?. response  ||  [ ] ) ] 
66+           response : [ 
67+             response  =>  { 
68+               if  ( response . config . url ?. startsWith ( "/v1/anonymous-users" )  &&  response . config . method  ===  "post"  &&  response . status  ===  200 )  { 
69+                 container . analyticsService . track ( "anonymous_user_created" ,  {  category : "user" ,  label : "Anonymous User Created"  } ) ; 
70+               } 
71+               return  response ; 
72+             } , 
73+             response  =>  { 
74+               if  ( response . config . url  ===  "v1/start-trial"  &&  response . config . method  ===  "post"  &&  response . status  ===  200 )  { 
75+                 container . analyticsService . track ( "trial_started" ,  {  category : "billing" ,  label : "Trial Started"  } ) ; 
76+               } 
77+               return  response ; 
78+             } , 
79+             ...( interceptors ?. response  ||  [ ] ) 
80+           ] 
4381        } ) ; 
4482    } , 
4583    authService : ( )  =>  new  AuthService ( ) , 
46-     user : ( )  => 
47-       container . applyAxiosInterceptors ( new  UserHttpService ( apiConfig ) ,  { 
48-         request : [ container . authService . withAnonymousUserHeader ] , 
49-         response : [ 
50-           response  =>  { 
51-             if  ( response . config . url ?. startsWith ( "/v1/anonymous-users" )  &&  response . config . method  ===  "post"  &&  response . status  ===  200 )  { 
52-               container . analyticsService . track ( "anonymous_user_created" ,  {  category : "user" ,  label : "Anonymous User Created"  } ) ; 
53-             } 
54-             return  response ; 
55-           } 
56-         ] 
57-       } ) , 
58-     stripe : ( )  => 
59-       container . applyAxiosInterceptors ( new  StripeService ( apiConfig ) ,  { 
60-         request : [ container . authService . withAnonymousUserHeader ] 
61-       } ) , 
62-     tx : ( )  => 
63-       container . applyAxiosInterceptors ( new  TxHttpService ( customRegistry ,  apiConfig ) ,  { 
64-         request : [ container . authService . withAnonymousUserHeader ] 
65-       } ) , 
66-     template : ( )  =>  container . applyAxiosInterceptors ( new  TemplateHttpService ( apiConfig ) ) , 
67-     usage : ( )  => 
68-       container . applyAxiosInterceptors ( new  UsageHttpService ( apiConfig ) ,  { 
69-         request : [ container . authService . withAnonymousUserHeader ] 
70-       } ) , 
71-     auth : ( )  => 
72-       container . applyAxiosInterceptors ( new  AuthHttpService ( apiConfig ) ,  { 
73-         request : [ container . authService . withAnonymousUserHeader ] 
74-       } ) , 
84+     user : ( )  =>  new  UserHttpService ( container . mainnetAxios ) , 
85+     stripe : ( )  =>  new  StripeService ( container . mainnetAxios ) , 
86+     tx : ( )  =>  new  TxHttpService ( container . mainnetAxios ,  customRegistry ) , 
87+     template : ( )  =>  new  TemplateHttpService ( container . mainNetAxiosWithNoAnonymousUserHeaderInterceptor ) , 
88+     usage : ( )  =>  new  UsageHttpService ( container . mainnetAxios ) , 
89+     auth : ( )  =>  new  AuthHttpService ( container . mainnetAxios ) , 
7590    providerProxy : ( )  =>  new  ProviderProxyService ( container . applyAxiosInterceptors ( container . createAxios ( {  baseURL : config . BASE_PROVIDER_PROXY_URL  } ) ,  { } ) ) , 
76-     deploymentSetting : ( )  => 
77-       container . applyAxiosInterceptors ( new  DeploymentSettingHttpService ( apiConfig ) ,  { 
78-         request : [ container . authService . withAnonymousUserHeader ] 
79-       } ) , 
80-     apiKey : ( )  => 
81-       container . applyAxiosInterceptors ( new  ApiKeyHttpService ( ) ,  { 
82-         request : [ container . authService . withAnonymousUserHeader ] 
83-       } ) , 
91+     deploymentSetting : ( )  =>  new  DeploymentSettingHttpService ( container . mainnetAxios ) , 
92+     apiKey : ( )  =>  new  ApiKeyHttpService ( container . defaultAxios ) , 
8493    externalApiHttpClient : ( )  => 
8594      container . createAxios ( { 
8695        headers : { 
@@ -97,26 +106,7 @@ export const createAppRootContainer = (config: ServicesConfig) => {
97106    certificateManager : ( )  =>  certificateManager , 
98107    analyticsService : ( )  =>  analyticsService , 
99108    apiUrlService : config . apiUrlService , 
100-     managedWalletService : ( )  => 
101-       container . applyAxiosInterceptors ( 
102-         new  ManagedWalletHttpService ( 
103-           { 
104-             baseURL : container . apiUrlService . getBaseApiUrlFor ( config . MANAGED_WALLET_NETWORK_ID ) 
105-           } , 
106-           container . analyticsService 
107-         ) , 
108-         { 
109-           request : [ container . authService . withAnonymousUserHeader ] , 
110-           response : [ 
111-             response  =>  { 
112-               if  ( response . config . url  ===  "v1/start-trial"  &&  response . config . method  ===  "post"  &&  response . status  ===  200 )  { 
113-                 container . analyticsService . track ( "trial_started" ,  {  category : "billing" ,  label : "Trial Started"  } ) ; 
114-               } 
115-               return  response ; 
116-             } 
117-           ] 
118-         } 
119-       ) , 
109+     managedWalletService : ( )  =>  new  ManagedWalletHttpService ( container . managedWalletAxios ,  container . analyticsService ) , 
120110    queryClient : ( )  => 
121111      new  QueryClient ( { 
122112        queryCache : new  QueryCache ( { 
0 commit comments