diff --git a/package.json b/package.json index 2f0ac13..d7cbb99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lambdatest/smartui-cli", - "version": "4.0.11", + "version": "4.0.12", "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest", "files": [ "dist/**/*" diff --git a/src/lib/env.ts b/src/lib/env.ts index 1a15032..5594385 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -16,7 +16,8 @@ export default (): Env => { LT_ACCESS_KEY, LT_SDK_DEBUG, BASELINE_BRANCH, - CURRENT_BRANCH + CURRENT_BRANCH, + PROJECT_NAME } = process.env return { @@ -34,6 +35,7 @@ export default (): Env => { BASELINE_BRANCH, CURRENT_BRANCH, LT_SDK_DEBUG: LT_SDK_DEBUG === 'true', - SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true' + SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true', + PROJECT_NAME } } diff --git a/src/lib/httpClient.ts b/src/lib/httpClient.ts index 93e9132..460fd31 100644 --- a/src/lib/httpClient.ts +++ b/src/lib/httpClient.ts @@ -8,12 +8,27 @@ import pkgJSON from './../../package.json' export default class httpClient { axiosInstance: AxiosInstance; + projectToken: string; + projectName: string; + username: string; + accessKey: string; + + constructor({ SMARTUI_CLIENT_API_URL, PROJECT_TOKEN, PROJECT_NAME, LT_USERNAME, LT_ACCESS_KEY }: Env) { + this.projectToken = PROJECT_TOKEN || ''; + this.projectName = PROJECT_NAME || ''; + this.username = LT_USERNAME || ''; + this.accessKey = LT_ACCESS_KEY || ''; - constructor({ SMARTUI_CLIENT_API_URL, PROJECT_TOKEN }: Env) { this.axiosInstance = axios.create({ baseURL: SMARTUI_CLIENT_API_URL, - headers: { 'projectToken': PROJECT_TOKEN }, - }) + }); + this.axiosInstance.interceptors.request.use((config) => { + config.headers['projectToken'] = this.projectToken; + config.headers['projectName'] = this.projectName; + config.headers['username'] = this.username; + config.headers['accessKey'] = this.accessKey; + return config; + }); } async request(config: AxiosRequestConfig, log: Logger): Promise> { @@ -46,13 +61,27 @@ export default class httpClient { }) } - auth(log: Logger) { - return this.request({ + async auth(log: Logger, env: Env): Promise { + let result = 1; + if (this.projectToken) { + result = 0; + } + const response = await this.request({ url: '/token/verify', - method: 'GET' - }, log) + method: 'GET', + }, log); + if (response && response.projectToken) { + this.projectToken = response.projectToken; + env.PROJECT_TOKEN = response.projectToken; + if (response.message && response.message.includes('Project created successfully')) { + result = 2; + } + return result; + } else { + throw new Error('Authentication failed, project token not received'); + } } - + createBuild(git: Git, config: any, log: Logger) { return this.request({ url: '/build', diff --git a/src/lib/snapshotQueue.ts b/src/lib/snapshotQueue.ts index f19b288..2d5db2e 100644 --- a/src/lib/snapshotQueue.ts +++ b/src/lib/snapshotQueue.ts @@ -271,7 +271,7 @@ export default class Queue { if (!this.ctx.config.delayedUpload && snapshot && snapshot.name && this.snapshotNames.includes(snapshot.name)) { drop = true; - this.ctx.log.info(`Skipping duplicate SmartUI snapshot '${snapshot.name}'. To capture duplicate screenshots, please set the 'delayedUploads' configuration as true in your config file.`); + this.ctx.log.info(`Skipping duplicate SmartUI snapshot '${snapshot.name}'. To capture duplicate screenshots, please set the 'delayedUpload' configuration as true in your config file.`); } if (this.ctx.config.delayedUpload && snapshot && snapshot.name && this.snapshotNames.includes(snapshot.name)) { diff --git a/src/tasks/auth.ts b/src/tasks/auth.ts index f86545e..3ca9c1b 100644 --- a/src/tasks/auth.ts +++ b/src/tasks/auth.ts @@ -10,8 +10,14 @@ export default (ctx: Context): ListrTask