Skip to content

Commit 2a032b1

Browse files
committed
Address PR comments
1 parent bdb6cbe commit 2a032b1

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,24 @@ export class AppManagementClient implements DeveloperPlatformClient {
171171
throw new Error('AppManagementClient.session() should not be invoked dynamically in a unit test')
172172
}
173173

174-
const {appToken, userId, businessPlatformToken} = await ensureAuthenticatedAppManagementAndBusinessPlatform()
175-
const userAccount = await businessPlatformRequestDoc(UserInfo, businessPlatformToken)
174+
const tokenResult = await ensureAuthenticatedAppManagementAndBusinessPlatform()
175+
const {appManagementToken, businessPlatformToken, userId} = tokenResult
176176

177-
if (userAccount.currentUserAccount) {
177+
const userInfoResult = await businessPlatformRequestDoc(UserInfo, businessPlatformToken)
178+
179+
if (userInfoResult.currentUserAccount) {
178180
this._session = {
179-
token: appToken,
181+
token: appManagementToken,
180182
businessPlatformToken,
181183
accountInfo: {
182184
type: 'UserAccount',
183-
email: userAccount.currentUserAccount.email,
185+
email: userInfoResult.currentUserAccount.email,
184186
},
185187
userId,
186188
}
187189
} else {
188190
this._session = {
189-
token: appToken,
191+
token: appManagementToken,
190192
businessPlatformToken,
191193
accountInfo: {
192194
type: 'UnknownAccount',
@@ -207,15 +209,10 @@ export class AppManagementClient implements DeveloperPlatformClient {
207209
}
208210

209211
async refreshToken(): Promise<string> {
210-
const {appToken, businessPlatformToken} = await ensureAuthenticatedAppManagementAndBusinessPlatform(
211-
[],
212-
[],
213-
process.env,
214-
{noPrompt: true},
215-
)
212+
const result = await ensureAuthenticatedAppManagementAndBusinessPlatform({noPrompt: true})
216213
const session = await this.session()
217-
session.token = appToken
218-
session.businessPlatformToken = businessPlatformToken
214+
session.token = result.appManagementToken
215+
session.businessPlatformToken = result.businessPlatformToken
219216

220217
return session.token
221218
}

packages/cli-kit/src/public/node/session.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ describe('ensureAuthenticatedAppManagementAndBusinessPlatform', () => {
226226

227227
// Then
228228
expect(got).toEqual({
229-
appToken: 'app_management_token',
229+
appManagementToken: 'app_management_token',
230230
businessPlatformToken: 'business_platform_token',
231231
userId: '1234-5678',
232232
})

packages/cli-kit/src/public/node/session.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ ${outputToken.json(scopes)}
6262
/**
6363
* Ensure that we have a valid session to access the App Management API.
6464
*
65+
* @param options - Optional extra options to use.
6566
* @param appManagementScopes - Optional array of extra scopes to authenticate with.
6667
* @param businessPlatformScopes - Optional array of extra scopes to authenticate with.
6768
* @param env - Optional environment variables to use.
68-
* @param options - Optional extra options to use.
6969
* @returns The access token for the App Management API.
7070
*/
7171
export async function ensureAuthenticatedAppManagementAndBusinessPlatform(
72+
options: EnsureAuthenticatedAdditionalOptions = {},
7273
appManagementScopes: AppManagementAPIScope[] = [],
7374
businessPlatformScopes: BusinessPlatformScope[] = [],
7475
env = process.env,
75-
options: EnsureAuthenticatedAdditionalOptions = {},
76-
): Promise<{appToken: string; userId: string; businessPlatformToken: string}> {
76+
): Promise<{appManagementToken: string; userId: string; businessPlatformToken: string}> {
7777
outputDebug(outputContent`Ensuring that the user is authenticated with the App Management API with the following scopes:
7878
${outputToken.json(appManagementScopes)}
7979
`)
@@ -87,7 +87,7 @@ ${outputToken.json(appManagementScopes)}
8787
}
8888

8989
return {
90-
appToken: tokens.appManagement,
90+
appManagementToken: tokens.appManagement,
9191
userId: tokens.userId,
9292
businessPlatformToken: tokens.businessPlatform,
9393
}

0 commit comments

Comments
 (0)