Skip to content

Commit afb00b7

Browse files
initial commit
1 parent 8bc94c4 commit afb00b7

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/lib/env.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default (): Env => {
1616
LT_ACCESS_KEY,
1717
LT_SDK_DEBUG,
1818
BASELINE_BRANCH,
19-
CURRENT_BRANCH
19+
CURRENT_BRANCH,
20+
PROJECT_NAME
2021
} = process.env
2122

2223
return {
@@ -34,6 +35,7 @@ export default (): Env => {
3435
BASELINE_BRANCH,
3536
CURRENT_BRANCH,
3637
LT_SDK_DEBUG: LT_SDK_DEBUG === 'true',
37-
SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true'
38+
SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true',
39+
PROJECT_NAME
3840
}
3941
}

src/lib/httpClient.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@ import pkgJSON from './../../package.json'
88

99
export 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) {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface Env {
6969
LT_SDK_DEBUG: boolean;
7070
BASELINE_BRANCH: string | undefined;
7171
CURRENT_BRANCH: string | undefined;
72+
PROJECT_NAME: string | undefined;
7273
}
7374

7475
export interface Snapshot {

0 commit comments

Comments
 (0)