Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/clear-humans-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/cli-kit': patch
'@shopify/app': patch
---

Unblock Partners API to fix import-extensions
5 changes: 5 additions & 0 deletions packages/app/src/cli/services/dev/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {afterEach, describe, expect, test, vi} from 'vitest'
import {renderFatalError} from '@shopify/cli-kit/node/ui'
import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output'
import {AbortError} from '@shopify/cli-kit/node/error'
import {blockPartnersAccess} from '@shopify/cli-kit/node/environment'

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

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

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

test('throws if there are no organizations', async () => {
// Given
vi.mocked(blockPartnersAccess).mockReturnValue(true)
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([]),
}) as AppManagementClient
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/cli/utilities/developer-platform-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {TokenItem} from '@shopify/cli-kit/node/ui'
import {blockPartnersAccess} from '@shopify/cli-kit/node/environment'
import {UnauthorizedHandler} from '@shopify/cli-kit/node/api/graphql'
import {JsonMapType} from '@shopify/cli-kit/node/toml'
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'

export enum ClientName {
AppManagement = 'app-management',
Expand Down Expand Up @@ -105,9 +106,9 @@ function selectDeveloperPlatformClientByOrg(organization: Organization): Develop
}

function defaultDeveloperPlatformClient(): DeveloperPlatformClient {
if (blockPartnersAccess()) return AppManagementClient.getInstance()
if (firstPartyDev() && !blockPartnersAccess()) return PartnersClient.getInstance()

return PartnersClient.getInstance()
return AppManagementClient.getInstance()
}

export interface CreateAppOptions {
Expand Down
1 change: 0 additions & 1 deletion packages/cli-kit/src/private/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const environmentVariables = {
themeKitAccessDomain: 'SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN',
json: 'SHOPIFY_FLAG_JSON',
neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API',
usePartnersApi: 'SHOPIFY_CLI_USE_PARTNERS_API',
skipNetworkLevelRetry: 'SHOPIFY_CLI_SKIP_NETWORK_LEVEL_RETRY',
maxRequestTimeForNetworkCalls: 'SHOPIFY_CLI_MAX_REQUEST_TIME_FOR_NETWORK_CALLS',
}
Expand Down
26 changes: 26 additions & 0 deletions packages/cli-kit/src/public/node/api/partners.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {partnersRequest, handleDeprecations} from './partners.js'
import {graphqlRequest, GraphQLResponse} from './graphql.js'
import {partnersFqdn} from '../context/fqdn.js'
import {blockPartnersAccess} from '../environment.js'
import {BugError} from '../error.js'
import {setNextDeprecationDate} from '../../../private/node/context/deprecations-store.js'
import {test, vi, expect, describe, beforeEach, beforeAll} from 'vitest'

vi.mock('./graphql.js')
vi.mock('../../../private/node/context/deprecations-store.js')
vi.mock('../context/fqdn.js')
vi.mock('../environment.js')

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

beforeEach(() => {
vi.mocked(partnersFqdn).mockResolvedValue(partnersFQDN)
vi.mocked(blockPartnersAccess).mockReturnValue(false)
})

describe('partnersRequest', () => {
Expand All @@ -36,6 +40,28 @@ describe('partnersRequest', () => {
responseOptions: {onResponse: handleDeprecations},
})
})

test('throws BugError when blockPartnersAccess returns true', async () => {
// Given
vi.mocked(blockPartnersAccess).mockReturnValue(true)

// When/Then
await expect(partnersRequest('query', mockedToken, {variables: 'variables'})).rejects.toThrow(BugError)
expect(blockPartnersAccess).toHaveBeenCalled()
})

test('does not throw when blockPartnersAccess returns false', async () => {
// Given
vi.mocked(blockPartnersAccess).mockReturnValue(false)
vi.mocked(graphqlRequest).mockResolvedValue(mockedResult)

// When
await partnersRequest('query', mockedToken, {variables: 'variables'})

// Then
expect(blockPartnersAccess).toHaveBeenCalled()
expect(graphqlRequest).toHaveBeenCalled()
})
})

describe('handleDeprecations', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/cli-kit/src/public/node/api/partners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {partnersFqdn} from '../context/fqdn.js'
import {setNextDeprecationDate} from '../../../private/node/context/deprecations-store.js'
import {getPackageManager} from '../node-package-manager.js'
import {cwd} from '../path.js'
import {AbortError} from '../error.js'
import {AbortError, BugError} from '../error.js'
import {formatPackageManagerCommand} from '../output.js'
import {RequestModeInput} from '../http.js'
import {blockPartnersAccess} from '../environment.js'
import Bottleneck from 'bottleneck'
import {Variables} from 'graphql-request'
import {TypedDocumentNode} from '@graphql-typed-document-node/core'
Expand All @@ -32,6 +33,10 @@ const limiter = new Bottleneck({
* @param token - Partners token.
*/
async function setupRequest(token: string) {
if (blockPartnersAccess()) {
throw new BugError('Partners API is no longer available.')
}

const api = 'Partners'
const fqdn = await partnersFqdn()
const url = `https://${fqdn}/api/cli/graphql`
Expand Down
14 changes: 5 additions & 9 deletions packages/cli-kit/src/public/node/context/fqdn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import {
adminFqdn,
} from './fqdn.js'
import {Environment, serviceEnvironment} from '../../../private/node/context/service.js'
import {blockPartnersAccess} from '../environment.js'
import {expect, describe, test, vi} from 'vitest'

vi.mock('../../../private/node/context/service.js')
vi.mock('../environment.js')

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

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

// When
const got = await partnersFqdn()
Expand Down Expand Up @@ -181,23 +177,23 @@ describe('adminFqdn', () => {
describe('normalizeStore', () => {
test('parses store name with http', async () => {
// When
const got = await normalizeStoreFqdn('http://example.myshopify.com')
const got = normalizeStoreFqdn('http://example.myshopify.com')

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

test('parses store name with https', async () => {
// When
const got = await normalizeStoreFqdn('https://example.myshopify.com')
const got = normalizeStoreFqdn('https://example.myshopify.com')

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

test('parses store name without domain', async () => {
// When
const got = await normalizeStoreFqdn('example')
const got = normalizeStoreFqdn('example')

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

// When
const got = await normalizeStoreFqdn('example')
const got = normalizeStoreFqdn('example')

// Then
expect(got).toEqual('example.myshopify.io')
})

test('parses store name with admin', async () => {
// When
const got = await normalizeStoreFqdn('https://example.myshopify.com/admin/')
const got = normalizeStoreFqdn('https://example.myshopify.com/admin/')

// Then
expect(got).toEqual('example.myshopify.com')
Expand Down
6 changes: 1 addition & 5 deletions packages/cli-kit/src/public/node/context/fqdn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {AbortError, BugError} from '../error.js'
import {AbortError} from '../error.js'
import {serviceEnvironment} from '../../../private/node/context/service.js'
import {DevServer, DevServerCore} from '../vendor/dev_server/index.js'
import {blockPartnersAccess} from '../environment.js'

export const NotProvidedStoreFQDNError = new AbortError(
"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.",
Expand All @@ -13,9 +12,6 @@ export const NotProvidedStoreFQDNError = new AbortError(
* @returns Fully-qualified domain of the partners service we should interact with.
*/
export async function partnersFqdn(): Promise<string> {
if (blockPartnersAccess()) {
throw new BugError('Partners API is is no longer available.')
}
const environment = serviceEnvironment()
const productionFqdn = 'partners.shopify.com'
switch (environment) {
Expand Down
13 changes: 1 addition & 12 deletions packages/cli-kit/src/public/node/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,7 @@ export function jsonOutputEnabled(environment = getEnvironmentVariables()): bool
* @returns True when the CLI should not use the Partners API.
*/
export function blockPartnersAccess(): boolean {
// Block if explicitly set to never use Partners API
if (isTruthy(getEnvironmentVariables()[environmentVariables.neverUsePartnersApi])) {
return true
}

// If explicitly forcing to use Partners API, do not block
if (isTruthy(getEnvironmentVariables()[environmentVariables.usePartnersApi])) {
return false
}

// Block for 3P devs
return !isTruthy(getEnvironmentVariables()[environmentVariables.firstPartyDev])
return isTruthy(getEnvironmentVariables()[environmentVariables.neverUsePartnersApi])
}

/**
Expand Down