diff --git a/packages/app/src/cli/utilities/developer-platform-client.ts b/packages/app/src/cli/utilities/developer-platform-client.ts index 30a0d75195..2560008464 100644 --- a/packages/app/src/cli/utilities/developer-platform-client.ts +++ b/packages/app/src/cli/utilities/developer-platform-client.ts @@ -56,6 +56,8 @@ import {DevSessionCreateMutation} from '../api/graphql/app-dev/generated/dev-ses import {DevSessionUpdateMutation} from '../api/graphql/app-dev/generated/dev-session-update.js' import {DevSessionDeleteMutation} from '../api/graphql/app-dev/generated/dev-session-delete.js' import {isTruthy} from '@shopify/cli-kit/node/context/utilities' +import {blockPartnersAccess} from '@shopify/cli-kit/node/environment' +import {BugError} from '@shopify/cli-kit/node/error' export enum ClientName { AppManagement = 'app-management', @@ -77,6 +79,11 @@ export interface AppVersionIdentifiers { } export function allDeveloperPlatformClients(): DeveloperPlatformClient[] { + if (blockPartnersAccess() && isTruthy(process.env.USE_APP_MANAGEMENT_API)) { + return [new AppManagementClient()] + } else if (blockPartnersAccess()) { + throw new BugError('Both Partners and App Management APIs are deactivated.') + } const clients: DeveloperPlatformClient[] = [new PartnersClient()] if (isTruthy(process.env.USE_APP_MANAGEMENT_API)) clients.push(new AppManagementClient()) return clients diff --git a/packages/cli-kit/src/private/node/constants.ts b/packages/cli-kit/src/private/node/constants.ts index 6337664367..9e04d9c1f8 100644 --- a/packages/cli-kit/src/private/node/constants.ts +++ b/packages/cli-kit/src/private/node/constants.ts @@ -30,6 +30,7 @@ export const environmentVariables = { verbose: 'SHOPIFY_FLAG_VERBOSE', noThemeBundling: 'SHOPIFY_CLI_NO_THEME_BUNDLING', bundledThemeCLI: 'SHOPIFY_CLI_BUNDLED_THEME_CLI', + neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API', // Variables to detect if the CLI is running in a cloud environment codespaces: 'CODESPACES', codespaceName: 'CODESPACE_NAME', diff --git a/packages/cli-kit/src/public/node/context/fqdn.ts b/packages/cli-kit/src/public/node/context/fqdn.ts index cfac3dbb18..3bd79ed89a 100644 --- a/packages/cli-kit/src/public/node/context/fqdn.ts +++ b/packages/cli-kit/src/public/node/context/fqdn.ts @@ -1,7 +1,8 @@ import {spinFqdn} from './spin.js' -import {AbortError} from '../error.js' +import {AbortError, BugError} from '../error.js' import {serviceEnvironment} from '../../../private/node/context/service.js' import {DevServer, DevServerCore} from '../vendor/dev_server/DevServer.js' +import {blockPartnersAccess} from '../environment.js' export const CouldntObtainPartnersSpinFQDNError = new AbortError( "Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.", @@ -22,6 +23,10 @@ export const NotProvidedStoreFQDNError = new AbortError( * @returns Fully-qualified domain of the partners service we should interact with. */ export async function partnersFqdn(): Promise { + if (blockPartnersAccess()) { + throw new BugError('Partners API is blocked by the SHOPIFY_CLI_NEVER_USE_PARTNERS_API environment variable.') + } + const environment = serviceEnvironment() const productionFqdn = 'partners.shopify.com' switch (environment) { diff --git a/packages/cli-kit/src/public/node/environment.ts b/packages/cli-kit/src/public/node/environment.ts index 549338baf3..4ce8240663 100644 --- a/packages/cli-kit/src/public/node/environment.ts +++ b/packages/cli-kit/src/public/node/environment.ts @@ -1,4 +1,5 @@ import {nonRandomUUID} from './crypto.js' +import {isTruthy} from './context/utilities.js' import {environmentVariables, systemEnvironmentVariables} from '../../private/node/constants.js' /** @@ -70,3 +71,12 @@ export function getIdentityTokenInformation(): {accessToken: string; refreshToke userId: nonRandomUUID(identityToken), } } + +/** + * If true, the CLI should not use the Partners API. + * + * @returns True if the SHOPIFY_CLI_NEVER_USE_PARTNERS_API environment variable is set. + */ +export function blockPartnersAccess(): boolean { + return isTruthy(getEnvironmentVariables()[environmentVariables.neverUsePartnersApi]) +}