Skip to content

Commit 16bbcb0

Browse files
Change teamId initialization
1 parent 2f202b8 commit 16bbcb0

3 files changed

Lines changed: 18 additions & 39 deletions

File tree

src/api/yepcodeApi.ts

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,9 @@ export class YepCodeApi {
107107
this.teamId = finalConfig.teamId;
108108
this.accessToken = finalConfig.accessToken;
109109
this.timeout = finalConfig.timeout;
110-
if (!this.clientId && this.accessToken) {
111-
this.clientId = this.clientIdFromAccessToken();
112-
}
113-
if (!this.teamId && this.clientId) {
114-
this.teamId = this.teamIdFromClientId();
115-
}
116-
}
117-
118-
getClientId(): string {
119-
if (!this.clientId) {
120-
throw new Error("Client ID is not set");
110+
if (!this.teamId) {
111+
this.initTeamId();
121112
}
122-
return this.clientId;
123113
}
124114

125115
getTeamId(): string {
@@ -129,28 +119,25 @@ export class YepCodeApi {
129119
return this.teamId;
130120
}
131121

132-
private clientIdFromAccessToken(): string {
133-
if (!this.accessToken) {
134-
throw new Error("Access token is not set");
135-
}
136-
const [, payload] = this.accessToken.split(".");
137-
const decodedPayload = JSON.parse(
138-
Buffer.from(payload, "base64").toString()
139-
);
140-
return decodedPayload.client_id;
141-
}
142-
143-
private teamIdFromClientId(): string {
144-
if (!this.clientId) {
145-
throw new Error("Client ID is not set");
122+
private initTeamId(): void {
123+
if (this.clientId) {
124+
const match = this.clientId.match(/^sa-(.*)-[a-z0-9]{8}$/);
125+
if (match) {
126+
this.teamId = match[1];
127+
}
146128
}
147-
const match = this.clientId.match(/^sa-(.*)-[a-z0-9]{8}$/);
148-
if (!match) {
149-
throw new Error(
150-
"Client ID is not valid. It must be in the format sa-<teamId>-<8randomCharsOrDigits>"
129+
if (!this.teamId && this.accessToken) {
130+
const [, payload] = this.accessToken.split(".");
131+
const decodedPayload = JSON.parse(
132+
Buffer.from(payload, "base64").toString()
151133
);
134+
this.teamId =
135+
decodedPayload.groups &&
136+
decodedPayload.groups.filter((group: string) => group !== "sandbox")[0];
137+
}
138+
if (!this.teamId) {
139+
throw new Error("Team ID is not set");
152140
}
153-
return match[1];
154141
}
155142

156143
private getBaseURL(): string {

src/env/yepcodeEnv.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ export class YepCodeEnv {
1313
this.yepCodeApi = YepCodeApiManager.getInstance(config);
1414
}
1515

16-
getClientId(): string {
17-
return this.yepCodeApi.getClientId();
18-
}
19-
2016
getTeamId(): string {
2117
return this.yepCodeApi.getTeamId();
2218
}

src/run/yepcodeRun.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ export class YepCodeRun {
1414
this.PROCESS_NAME_PREFIX = "yepcode-run-";
1515
}
1616

17-
getClientId(): string {
18-
return this.yepCodeApi.getClientId();
19-
}
20-
2117
getTeamId(): string {
2218
return this.yepCodeApi.getTeamId();
2319
}

0 commit comments

Comments
 (0)