Skip to content

Commit 708fb7c

Browse files
Merge pull request #6714 from Shopify/unblock-partners-api-stable
[Stable] Unblock Partners API
2 parents 502e0ae + 20bc495 commit 708fb7c

File tree

9 files changed

+53
-30
lines changed

9 files changed

+53
-30
lines changed

.changeset/clear-humans-sip.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/cli-kit': patch
3+
'@shopify/app': patch
4+
---
5+
6+
Unblock Partners API to fix import-extensions

packages/app/src/cli/services/dev/fetch.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {afterEach, describe, expect, test, vi} from 'vitest'
1212
import {renderFatalError} from '@shopify/cli-kit/node/ui'
1313
import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output'
1414
import {AbortError} from '@shopify/cli-kit/node/error'
15+
import {blockPartnersAccess} from '@shopify/cli-kit/node/environment'
1516

1617
const ORG1: Organization = {
1718
id: '1',
@@ -36,6 +37,7 @@ const STORE1: OrganizationStore = {
3637
vi.mock('@shopify/cli-kit/node/api/partners')
3738
vi.mock('../../utilities/developer-platform-client/partners-client.js')
3839
vi.mock('../../utilities/developer-platform-client/app-management-client.js')
40+
vi.mock('@shopify/cli-kit/node/environment')
3941

4042
afterEach(() => {
4143
mockAndCaptureOutput().clear()
@@ -46,6 +48,7 @@ describe('fetchOrganizations', async () => {
4648
test('returns fetched organizations from Partners and App Management for 1P development', async () => {
4749
// Given
4850
vi.stubEnv('SHOPIFY_CLI_1P_DEV', 'true')
51+
vi.mocked(blockPartnersAccess).mockReturnValue(false)
4952
const partnersClient: PartnersClient = testDeveloperPlatformClient({
5053
organizations: () => Promise.resolve([ORG1]),
5154
}) as PartnersClient
@@ -66,6 +69,7 @@ describe('fetchOrganizations', async () => {
6669

6770
test('returns fetched organizations from App Management for 3P development', async () => {
6871
// Given
72+
vi.mocked(blockPartnersAccess).mockReturnValue(true)
6973
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
7074
organizations: () => Promise.resolve([ORG2]),
7175
}) as AppManagementClient
@@ -82,6 +86,7 @@ describe('fetchOrganizations', async () => {
8286

8387
test('throws if there are no organizations', async () => {
8488
// Given
89+
vi.mocked(blockPartnersAccess).mockReturnValue(true)
8590
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
8691
organizations: () => Promise.resolve([]),
8792
}) as AppManagementClient

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {TokenItem} from '@shopify/cli-kit/node/ui'
6161
import {blockPartnersAccess} from '@shopify/cli-kit/node/environment'
6262
import {UnauthorizedHandler} from '@shopify/cli-kit/node/api/graphql'
6363
import {JsonMapType} from '@shopify/cli-kit/node/toml'
64+
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'
6465

6566
export enum ClientName {
6667
AppManagement = 'app-management',
@@ -105,9 +106,9 @@ function selectDeveloperPlatformClientByOrg(organization: Organization): Develop
105106
}
106107

107108
function defaultDeveloperPlatformClient(): DeveloperPlatformClient {
108-
if (blockPartnersAccess()) return AppManagementClient.getInstance()
109+
if (firstPartyDev() && !blockPartnersAccess()) return PartnersClient.getInstance()
109110

110-
return PartnersClient.getInstance()
111+
return AppManagementClient.getInstance()
111112
}
112113

113114
export interface CreateAppOptions {

packages/cli-kit/src/private/node/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export const environmentVariables = {
4343
themeKitAccessDomain: 'SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN',
4444
json: 'SHOPIFY_FLAG_JSON',
4545
neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API',
46-
usePartnersApi: 'SHOPIFY_CLI_USE_PARTNERS_API',
4746
skipNetworkLevelRetry: 'SHOPIFY_CLI_SKIP_NETWORK_LEVEL_RETRY',
4847
maxRequestTimeForNetworkCalls: 'SHOPIFY_CLI_MAX_REQUEST_TIME_FOR_NETWORK_CALLS',
4948
}

packages/cli-kit/src/public/node/api/partners.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {partnersRequest, handleDeprecations} from './partners.js'
22
import {graphqlRequest, GraphQLResponse} from './graphql.js'
33
import {partnersFqdn} from '../context/fqdn.js'
4+
import {blockPartnersAccess} from '../environment.js'
5+
import {BugError} from '../error.js'
46
import {setNextDeprecationDate} from '../../../private/node/context/deprecations-store.js'
57
import {test, vi, expect, describe, beforeEach, beforeAll} from 'vitest'
68

79
vi.mock('./graphql.js')
810
vi.mock('../../../private/node/context/deprecations-store.js')
911
vi.mock('../context/fqdn.js')
12+
vi.mock('../environment.js')
1013

1114
const mockedResult = 'OK'
1215
const partnersFQDN = 'partners.shopify.com'
@@ -16,6 +19,7 @@ const mockedToken = 'token'
1619

1720
beforeEach(() => {
1821
vi.mocked(partnersFqdn).mockResolvedValue(partnersFQDN)
22+
vi.mocked(blockPartnersAccess).mockReturnValue(false)
1923
})
2024

2125
describe('partnersRequest', () => {
@@ -36,6 +40,28 @@ describe('partnersRequest', () => {
3640
responseOptions: {onResponse: handleDeprecations},
3741
})
3842
})
43+
44+
test('throws BugError when blockPartnersAccess returns true', async () => {
45+
// Given
46+
vi.mocked(blockPartnersAccess).mockReturnValue(true)
47+
48+
// When/Then
49+
await expect(partnersRequest('query', mockedToken, {variables: 'variables'})).rejects.toThrow(BugError)
50+
expect(blockPartnersAccess).toHaveBeenCalled()
51+
})
52+
53+
test('does not throw when blockPartnersAccess returns false', async () => {
54+
// Given
55+
vi.mocked(blockPartnersAccess).mockReturnValue(false)
56+
vi.mocked(graphqlRequest).mockResolvedValue(mockedResult)
57+
58+
// When
59+
await partnersRequest('query', mockedToken, {variables: 'variables'})
60+
61+
// Then
62+
expect(blockPartnersAccess).toHaveBeenCalled()
63+
expect(graphqlRequest).toHaveBeenCalled()
64+
})
3965
})
4066

4167
describe('handleDeprecations', () => {

packages/cli-kit/src/public/node/api/partners.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import {partnersFqdn} from '../context/fqdn.js'
1111
import {setNextDeprecationDate} from '../../../private/node/context/deprecations-store.js'
1212
import {getPackageManager} from '../node-package-manager.js'
1313
import {cwd} from '../path.js'
14-
import {AbortError} from '../error.js'
14+
import {AbortError, BugError} from '../error.js'
1515
import {formatPackageManagerCommand} from '../output.js'
1616
import {RequestModeInput} from '../http.js'
17+
import {blockPartnersAccess} from '../environment.js'
1718
import Bottleneck from 'bottleneck'
1819
import {Variables} from 'graphql-request'
1920
import {TypedDocumentNode} from '@graphql-typed-document-node/core'
@@ -32,6 +33,10 @@ const limiter = new Bottleneck({
3233
* @param token - Partners token.
3334
*/
3435
async function setupRequest(token: string) {
36+
if (blockPartnersAccess()) {
37+
throw new BugError('Partners API is no longer available.')
38+
}
39+
3540
const api = 'Partners'
3641
const fqdn = await partnersFqdn()
3742
const url = `https://${fqdn}/api/cli/graphql`

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import {
88
adminFqdn,
99
} from './fqdn.js'
1010
import {Environment, serviceEnvironment} from '../../../private/node/context/service.js'
11-
import {blockPartnersAccess} from '../environment.js'
1211
import {expect, describe, test, vi} from 'vitest'
1312

1413
vi.mock('../../../private/node/context/service.js')
15-
vi.mock('../environment.js')
1614

1715
vi.mock('../vendor/dev_server/index.js', () => {
1816
return {
@@ -34,7 +32,6 @@ describe('partners', () => {
3432
test('returns the local fqdn when the environment is local', async () => {
3533
// Given
3634
vi.mocked(serviceEnvironment).mockReturnValue(Environment.Local)
37-
vi.mocked(blockPartnersAccess).mockReturnValue(false)
3835

3936
// When
4037
const got = await partnersFqdn()
@@ -46,7 +43,6 @@ describe('partners', () => {
4643
test('returns the production fqdn when the environment is production', async () => {
4744
// Given
4845
vi.mocked(serviceEnvironment).mockReturnValue(Environment.Production)
49-
vi.mocked(blockPartnersAccess).mockReturnValue(false)
5046

5147
// When
5248
const got = await partnersFqdn()
@@ -181,23 +177,23 @@ describe('adminFqdn', () => {
181177
describe('normalizeStore', () => {
182178
test('parses store name with http', async () => {
183179
// When
184-
const got = await normalizeStoreFqdn('http://example.myshopify.com')
180+
const got = normalizeStoreFqdn('http://example.myshopify.com')
185181

186182
// Then
187183
expect(got).toEqual('example.myshopify.com')
188184
})
189185

190186
test('parses store name with https', async () => {
191187
// When
192-
const got = await normalizeStoreFqdn('https://example.myshopify.com')
188+
const got = normalizeStoreFqdn('https://example.myshopify.com')
193189

194190
// Then
195191
expect(got).toEqual('example.myshopify.com')
196192
})
197193

198194
test('parses store name without domain', async () => {
199195
// When
200-
const got = await normalizeStoreFqdn('example')
196+
const got = normalizeStoreFqdn('example')
201197

202198
// Then
203199
expect(got).toEqual('example.myshopify.com')
@@ -208,15 +204,15 @@ describe('normalizeStore', () => {
208204
vi.mocked(serviceEnvironment).mockReturnValue(Environment.Local)
209205

210206
// When
211-
const got = await normalizeStoreFqdn('example')
207+
const got = normalizeStoreFqdn('example')
212208

213209
// Then
214210
expect(got).toEqual('example.myshopify.io')
215211
})
216212

217213
test('parses store name with admin', async () => {
218214
// When
219-
const got = await normalizeStoreFqdn('https://example.myshopify.com/admin/')
215+
const got = normalizeStoreFqdn('https://example.myshopify.com/admin/')
220216

221217
// Then
222218
expect(got).toEqual('example.myshopify.com')

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import {AbortError, BugError} from '../error.js'
1+
import {AbortError} from '../error.js'
22
import {serviceEnvironment} from '../../../private/node/context/service.js'
33
import {DevServer, DevServerCore} from '../vendor/dev_server/index.js'
4-
import {blockPartnersAccess} from '../environment.js'
54

65
export const NotProvidedStoreFQDNError = new AbortError(
76
"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.",
@@ -13,9 +12,6 @@ export const NotProvidedStoreFQDNError = new AbortError(
1312
* @returns Fully-qualified domain of the partners service we should interact with.
1413
*/
1514
export async function partnersFqdn(): Promise<string> {
16-
if (blockPartnersAccess()) {
17-
throw new BugError('Partners API is is no longer available.')
18-
}
1915
const environment = serviceEnvironment()
2016
const productionFqdn = 'partners.shopify.com'
2117
switch (environment) {

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,7 @@ export function jsonOutputEnabled(environment = getEnvironmentVariables()): bool
8989
* @returns True when the CLI should not use the Partners API.
9090
*/
9191
export function blockPartnersAccess(): boolean {
92-
// Block if explicitly set to never use Partners API
93-
if (isTruthy(getEnvironmentVariables()[environmentVariables.neverUsePartnersApi])) {
94-
return true
95-
}
96-
97-
// If explicitly forcing to use Partners API, do not block
98-
if (isTruthy(getEnvironmentVariables()[environmentVariables.usePartnersApi])) {
99-
return false
100-
}
101-
102-
// Block for 3P devs
103-
return !isTruthy(getEnvironmentVariables()[environmentVariables.firstPartyDev])
92+
return isTruthy(getEnvironmentVariables()[environmentVariables.neverUsePartnersApi])
10493
}
10594

10695
/**

0 commit comments

Comments
 (0)