Skip to content

Commit 3e52bb5

Browse files
Add a comment and rename the tokenType for clarity
1 parent 0d80b3b commit 3e52bb5

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ describe('createUnauthorizedHandler', () => {
6767
expect(mockClient.unsafeRefreshToken).toHaveBeenCalledTimes(1)
6868
})
6969

70-
test('returns appManagement token when tokenType is appManagement', async () => {
70+
test('returns default token when tokenType is default', async () => {
7171
const mockClient = createMockClient()
72-
const handler = createUnauthorizedHandler(mockClient, 'appManagement')
72+
const handler = createUnauthorizedHandler(mockClient, 'default')
7373

7474
const result = await handler.handler()
7575

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,18 @@ export interface DeveloperPlatformClient {
296296

297297
const inProgressRefreshes = new WeakMap<DeveloperPlatformClient, Promise<string>>()
298298

299+
/**
300+
* Creates an unauthorized handler for a developer platform client that will refresh the token
301+
* and return the appropriate token based on the token type.
302+
* If the tokenType is 'businessPlatform', the handler will return the business platform token.
303+
* Otherwise, it will return the default token (App Management API or Partners API).
304+
* @param client - The developer platform client.
305+
* @param tokenType - The type of token to return ('default' or 'businessPlatform')
306+
* @returns The unauthorized handler.
307+
*/
299308
export function createUnauthorizedHandler(
300309
client: DeveloperPlatformClient,
301-
tokenType: 'appManagement' | 'businessPlatform' = 'appManagement',
310+
tokenType: 'default' | 'businessPlatform' = 'default',
302311
): UnauthorizedHandler {
303312
return {
304313
type: 'token_refresh',

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
856856
token: await this.businessPlatformToken(),
857857
organizationId: String(numberFromGid(orgId)),
858858
variables,
859-
unauthorizedHandler: this.createUnauthorizedHandler('appManagement'),
859+
unauthorizedHandler: this.createUnauthorizedHandler(),
860860
})
861861
const provisionResult = fullResult.organizationUserProvisionShopAccess
862862
if (!provisionResult.success) {
@@ -1057,7 +1057,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
10571057
token: await this.businessPlatformToken(),
10581058
organizationId,
10591059
variables,
1060-
unauthorizedHandler: this.createUnauthorizedHandler('appManagement'),
1060+
unauthorizedHandler: this.createUnauthorizedHandler(),
10611061
})
10621062
const result: {[flag: (typeof allBetaFlags)[number]]: boolean} = {}
10631063
allBetaFlags.forEach((flag) => {
@@ -1072,7 +1072,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
10721072
return appManagementRequestDoc({
10731073
...options,
10741074
token: await this.token(),
1075-
unauthorizedHandler: this.createUnauthorizedHandler('appManagement'),
1075+
unauthorizedHandler: this.createUnauthorizedHandler(),
10761076
})
10771077
}
10781078

@@ -1082,7 +1082,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
10821082
return appDevRequestDoc({
10831083
...options,
10841084
token: await this.token(),
1085-
unauthorizedHandler: this.createUnauthorizedHandler('appManagement'),
1085+
unauthorizedHandler: this.createUnauthorizedHandler(),
10861086
})
10871087
}
10881088

@@ -1112,7 +1112,7 @@ export class AppManagementClient implements DeveloperPlatformClient {
11121112
return functionsRequestDoc<TResult, TVariables>({
11131113
...options,
11141114
token: await this.token(),
1115-
unauthorizedHandler: this.createUnauthorizedHandler('appManagement'),
1115+
unauthorizedHandler: this.createUnauthorizedHandler(),
11161116
})
11171117
}
11181118

@@ -1122,13 +1122,11 @@ export class AppManagementClient implements DeveloperPlatformClient {
11221122
return webhooksRequestDoc<TResult, TVariables>({
11231123
...options,
11241124
token: await this.token(),
1125-
unauthorizedHandler: this.createUnauthorizedHandler('appManagement'),
1125+
unauthorizedHandler: this.createUnauthorizedHandler(),
11261126
})
11271127
}
11281128

1129-
private createUnauthorizedHandler(
1130-
tokenType: 'appManagement' | 'businessPlatform' = 'appManagement',
1131-
): UnauthorizedHandler {
1129+
private createUnauthorizedHandler(tokenType: 'default' | 'businessPlatform' = 'default'): UnauthorizedHandler {
11321130
return createUnauthorizedHandler(this, tokenType)
11331131
}
11341132
}

0 commit comments

Comments
 (0)