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

Make tophatting templates changes possible #5134

Merged
merged 3 commits into from
Dec 22, 2024
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
1 change: 1 addition & 0 deletions packages/app/src/cli/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const environmentVariableNames = {
disableGraphiQLExplorer: 'SHOPIFY_CLI_DISABLE_GRAPHIQL',
useDynamicConfigSpecifications: 'SHOPIFY_CLI_DYNAMIC_CONFIG',
enableAppLogPolling: 'SHOPIFY_CLI_ENABLE_APP_LOG_POLLING',
templatesJsonPath: 'SHOPIFY_CLI_APP_TEMPLATES_JSON_PATH',
}

export const configurationFileNames = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
OrganizationBetaFlagsQueryVariables,
organizationBetaFlagsQuery,
} from './app-management-client/graphql/organization_beta_flags.js'
import {environmentVariableNames} from '../../constants.js'
import {RemoteSpecification} from '../../api/graphql/extension_specifications.js'
import {
DeveloperPlatformClient,
Expand Down Expand Up @@ -133,6 +134,7 @@
import {developerDashboardFqdn} from '@shopify/cli-kit/node/context/fqdn'
import {webhooksRequest} from '@shopify/cli-kit/node/api/webhooks'
import {functionsRequestDoc} from '@shopify/cli-kit/node/api/functions'
import {fileExists, readFile} from '@shopify/cli-kit/node/fs'

const TEMPLATE_JSON_URL = 'https://cdn.shopify.com/static/cli/extensions/templates.json'

Expand Down Expand Up @@ -325,24 +327,27 @@
}

async templateSpecifications({organizationId}: MinimalAppIdentifiers): Promise<ExtensionTemplate[]> {
let response
let templates: GatedExtensionTemplate[]
try {
response = await fetch(TEMPLATE_JSON_URL)
templates = await (response.json() as Promise<GatedExtensionTemplate[]>)
} catch (_e) {
throw new AbortError(
[
const {templatesJsonPath} = environmentVariableNames
const overrideFile = process.env[templatesJsonPath]
if (overrideFile) {
if (!(await fileExists(overrideFile))) {
throw new AbortError('There is no file at the path specified for template specifications')
}
const templatesJson = await readFile(overrideFile)
templates = JSON.parse(templatesJson)
} else {
try {
const response = await fetch(TEMPLATE_JSON_URL)
templates = await (response.json() as Promise<GatedExtensionTemplate[]>)
} catch (_e) {
throw new AbortError([
'Failed to fetch extension templates from',
{link: {url: TEMPLATE_JSON_URL}},
{char: '.'},
'This likely means a problem with your internet connection.',
],
[
{link: {url: 'https://www.githubstatus.com', label: 'Check if GitHub is experiencing downtime'}},
'or try again later.',
],
)
])
}
}
// Fake the sortPriority as ascending, since the templates are already sorted
// in the static JSON file. This can be removed once PartnersClient, which
Expand Down Expand Up @@ -412,7 +417,7 @@
appIdentifiers: MinimalAppIdentifiers,
activeAppVersion?: AppVersion,
): Promise<AllAppExtensionRegistrationsQuerySchema> {
const app = activeAppVersion || (await this.activeAppVersion(appIdentifiers))

Check warning on line 420 in packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.

const configurationRegistrations: ExtensionRegistration[] = []
const extensionRegistrations: ExtensionRegistration[] = []
Expand Down
Loading