Skip to content

Commit

Permalink
Support app-management only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shauns committed Nov 19, 2024
1 parent 69aa727 commit d2b5fb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/app/src/cli/utilities/developer-platform-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/cli-kit/src/private/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion packages/cli-kit/src/public/node/context/fqdn.ts
Original file line number Diff line number Diff line change
@@ -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.",
Expand All @@ -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<string> {
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) {
Expand Down
10 changes: 10 additions & 0 deletions packages/cli-kit/src/public/node/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {nonRandomUUID} from './crypto.js'
import {isTruthy} from './context/utilities.js'
import {environmentVariables, systemEnvironmentVariables} from '../../private/node/constants.js'

/**
Expand Down Expand Up @@ -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])
}

0 comments on commit d2b5fb7

Please sign in to comment.