Skip to content

Commit 936d7ac

Browse files
authored
Merge pull request #5199 from Shopify/shauns/01-15-support_local_dev_in_cli
Support local dev in CLI
2 parents 6385fd3 + a86670a commit 936d7ac

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import {DevSessionCreateMutation} from '../api/graphql/app-dev/generated/dev-ses
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'
5858
import {isAppManagementDisabled} from '@shopify/cli-kit/node/context/local'
59+
import {blockPartnersAccess} from '@shopify/cli-kit/node/environment'
60+
import {AbortError} from '@shopify/cli-kit/node/error'
5961

6062
export enum ClientName {
6163
AppManagement = 'app-management',
@@ -77,7 +79,17 @@ export interface AppVersionIdentifiers {
7779
}
7880

7981
export function allDeveloperPlatformClients(): DeveloperPlatformClient[] {
80-
return isAppManagementDisabled() ? [new PartnersClient()] : [new PartnersClient(), new AppManagementClient()]
82+
const clients: DeveloperPlatformClient[] = []
83+
if (!blockPartnersAccess()) {
84+
clients.push(new PartnersClient())
85+
}
86+
if (!isAppManagementDisabled()) {
87+
clients.push(new AppManagementClient())
88+
}
89+
if (clients.length === 0) {
90+
throw new AbortError('Both Partners and App Management APIs are deactivated.')
91+
}
92+
return clients
8193
}
8294

8395
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const environmentVariables = {
4545
otelURL: 'SHOPIFY_CLI_OTEL_EXPORTER_OTLP_ENDPOINT',
4646
themeKitAccessDomain: 'SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN',
4747
json: 'SHOPIFY_FLAG_JSON',
48+
neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API',
4849
}
4950

5051
export const defaultThemeKitAccessDomain = 'theme-kit-access.shopifyapps.com'

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {spinFqdn} from './spin.js'
2-
import {AbortError} from '../error.js'
2+
import {AbortError, BugError} from '../error.js'
33
import {serviceEnvironment} from '../../../private/node/context/service.js'
44
import {DevServer, DevServerCore} from '../vendor/dev_server/DevServer.js'
5+
import {blockPartnersAccess} from '../environment.js'
56

67
export const CouldntObtainPartnersSpinFQDNError = new AbortError(
78
"Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.",
@@ -22,6 +23,9 @@ export const NotProvidedStoreFQDNError = new AbortError(
2223
* @returns Fully-qualified domain of the partners service we should interact with.
2324
*/
2425
export async function partnersFqdn(): Promise<string> {
26+
if (blockPartnersAccess()) {
27+
throw new BugError('Partners API is blocked by the SHOPIFY_CLI_NEVER_USE_PARTNERS_API environment variable.')
28+
}
2529
const environment = serviceEnvironment()
2630
const productionFqdn = 'partners.shopify.com'
2731
switch (environment) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@ export function getIdentityTokenInformation(): {accessToken: string; refreshToke
8282
export function jsonOutputEnabled(environment = getEnvironmentVariables()): boolean {
8383
return sniffForJson() || isTruthy(environment[environmentVariables.json])
8484
}
85+
86+
/**
87+
* If true, the CLI should not use the Partners API.
88+
*
89+
* @returns True if the SHOPIFY_CLI_NEVER_USE_PARTNERS_API environment variable is set.
90+
*/
91+
export function blockPartnersAccess(): boolean {
92+
return isTruthy(getEnvironmentVariables()[environmentVariables.neverUsePartnersApi])
93+
}

0 commit comments

Comments
 (0)