@@ -15,22 +15,27 @@ export class AllureServiceClient {
1515 throw new Error ( "Allure service access token is required" ) ;
1616 }
1717
18- const [ prefix , body ] = atob ( config . accessToken ) . split ( ":" ) ;
18+ const { iss , projectId , url : baseUrl } = this . decodeToken ( config . accessToken ) ?? { } ;
1919
20- if ( prefix !== "allure-service" ) {
21- throw new Error ( "Invalid access token" ) ;
22- }
23-
24- const { projectId, url : baseUrl } = JSON . parse ( atob ( body ) ) ;
25-
26- if ( ! baseUrl || ! projectId ) {
20+ if ( iss !== "allure-service" || ! baseUrl || ! projectId ) {
2721 throw new Error ( "Invalid access token" ) ;
2822 }
2923
3024 this . #url = baseUrl ;
3125 this . #client = createServiceHttpClient ( this . #url, config . accessToken ) ;
3226 }
3327
28+ decodeToken ( token : string ) {
29+ try {
30+ const base64Url = token . split ( "." ) [ 1 ] ;
31+ const base64 = base64Url . replace ( / - / g, "+" ) . replace ( / _ / g, "/" ) ;
32+
33+ return JSON . parse ( atob ( base64 ) ) ;
34+ } catch {
35+ return undefined ;
36+ }
37+ }
38+
3439 /**
3540 * Returns user profile and current project
3641 */
@@ -71,34 +76,16 @@ export class AllureServiceClient {
7176 return this . #client. get < { project : { id : string ; name : string } } > ( `/projects/${ uuid } ` ) ;
7277 }
7378
74- /**
75- * Creates a new project
76- * @param payload
77- */
78- async createProject ( payload : { name : string } ) {
79- const { project } = await this . #client. post < { project : { id : string ; name : string } } > ( "/projects" , {
80- body : payload ,
81- } ) ;
82-
83- return project ;
84- }
85-
86- /**
87- * Deletes a project
88- * @param payload
89- */
90- async deleteProject ( payload : { id : string } ) {
91- return this . #client. delete ( `/projects/${ payload . id } ` ) ;
92- }
93-
9479 /**
9580 * Downloads history data for a specific branch
9681 * @param payload
9782 */
9883 async downloadHistory ( payload : { branch : string ; limit ?: number } ) {
9984 const { branch, limit } = payload ;
10085 const { history } = await this . #client. get < { history : HistoryDataPoint [ ] } > (
101- limit ? `/projects/history/${ encodeURIComponent ( branch ) } ?limit=${ limit } ` : `/projects/history/${ encodeURIComponent ( branch ) } ` ,
86+ limit
87+ ? `/projects/history/${ encodeURIComponent ( branch ) } ?limit=${ encodeURIComponent ( limit . toString ( ) ) } `
88+ : `/projects/history/${ encodeURIComponent ( branch ) } ` ,
10289 ) ;
10390
10491 return history ;
0 commit comments