@@ -8,12 +8,27 @@ import pkgJSON from './../../package.json'
88
99export default class httpClient {
1010 axiosInstance : AxiosInstance ;
11+ projectToken : string ;
12+ projectName : string ;
13+ username : string ;
14+ accessKey : string ;
15+
16+ constructor ( { SMARTUI_CLIENT_API_URL , PROJECT_TOKEN , PROJECT_NAME , LT_USERNAME , LT_ACCESS_KEY } : Env ) {
17+ this . projectToken = PROJECT_TOKEN || '' ;
18+ this . projectName = PROJECT_NAME || '' ;
19+ this . username = LT_USERNAME || '' ;
20+ this . accessKey = LT_ACCESS_KEY || '' ;
1121
12- constructor ( { SMARTUI_CLIENT_API_URL , PROJECT_TOKEN } : Env ) {
1322 this . axiosInstance = axios . create ( {
1423 baseURL : SMARTUI_CLIENT_API_URL ,
15- headers : { 'projectToken' : PROJECT_TOKEN } ,
16- } )
24+ } ) ;
25+ this . axiosInstance . interceptors . request . use ( ( config ) => {
26+ config . headers [ 'projectToken' ] = this . projectToken ;
27+ config . headers [ 'projectName' ] = this . projectName ;
28+ config . headers [ 'username' ] = this . username ;
29+ config . headers [ 'accessKey' ] = this . accessKey ;
30+ return config ;
31+ } ) ;
1732 }
1833
1934 async request ( config : AxiosRequestConfig , log : Logger ) : Promise < Record < string , any > > {
@@ -46,11 +61,19 @@ export default class httpClient {
4661 } )
4762 }
4863
49- auth ( log : Logger ) {
50- return this . request ( {
64+ async auth ( log : Logger ) : Promise < void > {
65+ const response = await this . request ( {
5166 url : '/token/verify' ,
52- method : 'GET'
53- } , log )
67+ method : 'GET' ,
68+ } , log ) ;
69+
70+ // Update the projectToken after authentication
71+ if ( response && response . projectToken ) {
72+ this . projectToken = response . projectToken ;
73+ log . info ( 'Project token updated successfully' ) ;
74+ } else {
75+ throw new Error ( 'Authentication failed, project token not received' ) ;
76+ }
5477 }
5578
5679 createBuild ( git : Git , config : any , log : Logger ) {
0 commit comments