Skip to content

Commit 893ee2e

Browse files
committed
Disable app management when using a Partners CLI token
Otherwise we hit permissions issues.
1 parent dfb94ce commit 893ee2e

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
import {DevSessionCreateMutation} from '../api/graphql/app-dev/generated/dev-session-create.js'
5656
import {DevSessionUpdateMutation} from '../api/graphql/app-dev/generated/dev-session-update.js'
5757
import {DevSessionDeleteMutation} from '../api/graphql/app-dev/generated/dev-session-delete.js'
58+
import {isAppManagementDisabled} from '@shopify/cli-kit/node/context/local'
5859

5960
export enum ClientName {
6061
AppManagement = 'app-management',
@@ -76,8 +77,7 @@ export interface AppVersionIdentifiers {
7677
}
7778

7879
export function allDeveloperPlatformClients(): DeveloperPlatformClient[] {
79-
const clients: DeveloperPlatformClient[] = [new PartnersClient(), new AppManagementClient()]
80-
return clients
80+
return isAppManagementDisabled() ? [new PartnersClient()] : [new PartnersClient(), new AppManagementClient()]
8181
}
8282

8383
/**
@@ -116,6 +116,7 @@ export function selectDeveloperPlatformClient({
116116
configuration,
117117
organization,
118118
}: SelectDeveloperPlatformClientOptions = {}): DeveloperPlatformClient {
119+
if (isAppManagementDisabled()) return new PartnersClient()
119120
if (organization) return selectDeveloperPlatformClientByOrg(organization)
120121
return selectDeveloperPlatformClientByConfig(configuration)
121122
}

packages/cli-kit/src/private/node/session/exchange.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,9 @@ describe('exchange identity token for application tokens', () => {
6363
// Then
6464
const expected = {
6565
'app-management': {
66-
accessToken: "access_token",
66+
accessToken: 'access_token',
6767
expiresAt: expiredDate,
68-
scopes: [
69-
"scope",
70-
"scope2",
71-
],
68+
scopes: ['scope', 'scope2'],
7269
},
7370
partners: {
7471
accessToken: 'access_token',
@@ -111,12 +108,9 @@ describe('exchange identity token for application tokens', () => {
111108
// Then
112109
const expected = {
113110
'app-management': {
114-
accessToken: "access_token",
111+
accessToken: 'access_token',
115112
expiresAt: expiredDate,
116-
scopes: [
117-
"scope",
118-
"scope2",
119-
],
113+
scopes: ['scope', 'scope2'],
120114
},
121115
partners: {
122116
accessToken: 'access_token',

packages/cli-kit/src/private/node/session/exchange.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {identityFqdn} from '../../../public/node/context/fqdn.js'
55
import {shopifyFetch} from '../../../public/node/http.js'
66
import {err, ok, Result} from '../../../public/node/result.js'
77
import {AbortError, BugError, ExtendableError} from '../../../public/node/error.js'
8+
import {isAppManagementDisabled} from '../../../public/node/context/local.js'
89
import {setLastSeenAuthMethod, setLastSeenUserIdAfterAuth} from '../session.js'
910
import * as jose from 'jose'
1011
import {nonRandomUUID} from '@shopify/cli-kit/node/crypto'
@@ -39,7 +40,7 @@ export async function exchangeAccessForApplicationTokens(
3940
requestAppToken('storefront-renderer', token, scopes.storefront),
4041
requestAppToken('business-platform', token, scopes.businessPlatform),
4142
store ? requestAppToken('admin', token, scopes.admin, store) : {},
42-
requestAppToken('app-management', token, scopes.appManagement),
43+
isAppManagementDisabled() ? {} : requestAppToken('app-management', token, scopes.appManagement),
4344
])
4445

4546
return {

packages/cli-kit/src/public/node/context/local.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import {
77
analyticsDisabled,
88
cloudEnvironment,
99
macAddress,
10+
isAppManagementDisabled,
1011
} from './local.js'
12+
import {getPartnersToken} from '../environment.js'
1113
import {fileExists} from '../fs.js'
1214
import {exec} from '../system.js'
1315
import {expect, describe, vi, test} from 'vitest'
1416

1517
vi.mock('../fs.js')
1618
vi.mock('../system.js')
19+
vi.mock('../environment.js')
1720

1821
describe('isUnitTest', () => {
1922
test('returns true when SHOPIFY_UNIT_TEST is truthy', () => {
@@ -99,6 +102,30 @@ describe('hasGit', () => {
99102
})
100103
})
101104

105+
describe('isAppManagementDisabled', () => {
106+
test('returns true when a Partners token is present', () => {
107+
// Given
108+
vi.mocked(getPartnersToken).mockReturnValue('token')
109+
110+
// When
111+
const got = isAppManagementDisabled()
112+
113+
// Then
114+
expect(got).toBe(true)
115+
})
116+
117+
test('returns false when a Partners token is not present', () => {
118+
// Given
119+
vi.mocked(getPartnersToken).mockReturnValue(undefined)
120+
121+
// When
122+
const got = isAppManagementDisabled()
123+
124+
// Then
125+
expect(got).toBe(false)
126+
})
127+
})
128+
102129
describe('analitycsDisabled', () => {
103130
test('returns true when SHOPIFY_CLI_NO_ANALYTICS is truthy', () => {
104131
// Given

packages/cli-kit/src/public/node/context/local.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {getCIMetadata, isSet, Metadata} from '../../../private/node/context/util
44
import {environmentVariables, pathConstants} from '../../../private/node/constants.js'
55
import {fileExists} from '../fs.js'
66
import {exec} from '../system.js'
7+
import {getPartnersToken} from '../environment.js'
78
import isInteractive from 'is-interactive'
89
import macaddress from 'macaddress'
910
import {homedir} from 'os'
@@ -46,6 +47,16 @@ export function isVerbose(env = process.env): boolean {
4647
return isTruthy(env[environmentVariables.verbose]) || process.argv.includes('--verbose')
4748
}
4849

50+
/**
51+
* It returns true if the App Management API is disabled.
52+
* This should only be relevant when using a Partners token.
53+
*
54+
* @returns True if the App Management API is disabled.
55+
*/
56+
export function isAppManagementDisabled(): boolean {
57+
return Boolean(getPartnersToken())
58+
}
59+
4960
/**
5061
* Returns true if the environment in which the CLI is running is either
5162
* a local environment (where dev is present) or a cloud environment (spin).

0 commit comments

Comments
 (0)