Skip to content

Commit 54c4aca

Browse files
committed
rename refreshToken to unsafeRefreshToken
1 parent bb18dc1 commit 54c4aca

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

packages/app/src/cli/models/app/app.test-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ export function testDeveloperPlatformClient(stubs: Partial<DeveloperPlatformClie
14231423
organizationSource: OrganizationSource.BusinessPlatform,
14241424
bundleFormat: 'zip',
14251425
session: () => Promise.resolve(testPartnersUserSession),
1426-
refreshToken: () => Promise.resolve(testPartnersUserSession.token),
1426+
unsafeRefreshToken: () => Promise.resolve(testPartnersUserSession.token),
14271427
accountInfo: () => Promise.resolve(testPartnersUserSession.accountInfo),
14281428
appFromIdentifiers: (_app: AppApiKeyAndOrgId) => Promise.resolve(testOrganizationApp()),
14291429
organizations: () => Promise.resolve(organizationsResponse),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('createUnauthorizedHandler', () => {
2424
const result = await handler.handler()
2525

2626
expect(result).toEqual({token: mockToken})
27-
expect(mockClient.refreshToken).toHaveBeenCalledTimes(1)
27+
expect(mockClient.unsafeRefreshToken).toHaveBeenCalledTimes(1)
2828
})
2929

3030
test('reuses existing token refresh when one is in progress', async () => {
@@ -36,19 +36,19 @@ describe('createUnauthorizedHandler', () => {
3636
const result = await handler.handler()
3737

3838
expect(result).toEqual({token: mockToken})
39-
expect(mockClient.refreshToken).toHaveBeenCalledTimes(1)
39+
expect(mockClient.unsafeRefreshToken).toHaveBeenCalledTimes(1)
4040
})
4141

4242
test('handles token refresh failure and cleans up in-progress promise', async () => {
4343
const mockClient = createMockClient()
4444
const error = new Error('Token refresh failed')
45-
mockClient.refreshToken = vi.fn().mockRejectedValue(error)
45+
mockClient.unsafeRefreshToken = vi.fn().mockRejectedValue(error)
4646
const handler = createUnauthorizedHandler(mockClient)
4747

4848
await expect(handler.handler()).rejects.toThrow(error)
4949
await expect(handler.handler()).rejects.toThrow(error)
5050

5151
// The following is evidence that the finally block is called correctly
52-
expect(mockClient.refreshToken).toHaveBeenCalledTimes(2)
52+
expect(mockClient.unsafeRefreshToken).toHaveBeenCalledTimes(2)
5353
})
5454
})

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@ export interface DeveloperPlatformClient {
263263
readonly organizationSource: OrganizationSource
264264
readonly bundleFormat: 'zip' | 'br'
265265
session: () => Promise<PartnersSession>
266-
refreshToken: () => Promise<string>
266+
/**
267+
* This is an unsafe method that should only be used when the session is expired.
268+
* It is not safe to use this method in other contexts as it may lead to race conditions.
269+
* Use only if you know what you are doing.
270+
*/
271+
unsafeRefreshToken: () => Promise<string>
267272
accountInfo: () => Promise<PartnersSession['accountInfo']>
268273
appFromIdentifiers: (app: AppApiKeyAndOrgId) => Promise<OrganizationApp | undefined>
269274
organizations: () => Promise<Organization[]>
@@ -336,7 +341,7 @@ export function createUnauthorizedHandler(client: DeveloperPlatformClient): Unau
336341
return {token}
337342
} else {
338343
try {
339-
tokenRefresher = client.refreshToken()
344+
tokenRefresher = client.unsafeRefreshToken()
340345
inProgressRefreshes.set(client, tokenRefresher)
341346
const token = await tokenRefresher
342347
return {token}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
318318
return (await this.session()).businessPlatformToken
319319
}
320320

321-
async refreshToken(): Promise<string> {
321+
async unsafeRefreshToken(): Promise<string> {
322322
const result = await ensureAuthenticatedAppManagementAndBusinessPlatform({noPrompt: true, forceRefresh: true})
323323
const session = await this.session()
324324
session.token = result.appManagementToken

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class PartnersClient implements DeveloperPlatformClient {
273273
return (await this.session()).token
274274
}
275275

276-
async refreshToken(): Promise<string> {
276+
async unsafeRefreshToken(): Promise<string> {
277277
const {token} = await ensureAuthenticatedPartners([], process.env, {noPrompt: true, forceRefresh: true})
278278
const session = await this.session()
279279
if (token) {

0 commit comments

Comments
 (0)