Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support local dev in CLI #5199

Merged
merged 1 commit into from
Jan 31, 2025
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
14 changes: 13 additions & 1 deletion 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 {isAppManagementDisabled} from '@shopify/cli-kit/node/context/local'
import {blockPartnersAccess} from '@shopify/cli-kit/node/environment'
import {AbortError} from '@shopify/cli-kit/node/error'

export enum ClientName {
AppManagement = 'app-management',
Expand All @@ -77,7 +79,17 @@ export interface AppVersionIdentifiers {
}

export function allDeveloperPlatformClients(): DeveloperPlatformClient[] {
return isAppManagementDisabled() ? [new PartnersClient()] : [new PartnersClient(), new AppManagementClient()]
const clients: DeveloperPlatformClient[] = []
if (!blockPartnersAccess()) {
clients.push(new PartnersClient())
}
if (!isAppManagementDisabled()) {
clients.push(new AppManagementClient())
}
if (clients.length === 0) {
throw new AbortError('Both Partners and App Management APIs are deactivated.')
}
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 @@ -45,6 +45,7 @@ export const environmentVariables = {
otelURL: 'SHOPIFY_CLI_OTEL_EXPORTER_OTLP_ENDPOINT',
themeKitAccessDomain: 'SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN',
json: 'SHOPIFY_FLAG_JSON',
neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API',
}

export const defaultThemeKitAccessDomain = 'theme-kit-access.shopifyapps.com'
Expand Down
6 changes: 5 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,9 @@ 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.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BugError because this shouldn't happen.

}
const environment = serviceEnvironment()
const productionFqdn = 'partners.shopify.com'
switch (environment) {
Expand Down
9 changes: 9 additions & 0 deletions packages/cli-kit/src/public/node/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ export function getIdentityTokenInformation(): {accessToken: string; refreshToke
export function jsonOutputEnabled(environment = getEnvironmentVariables()): boolean {
return sniffForJson() || isTruthy(environment[environmentVariables.json])
}

/**
* 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])
}
Loading