From 2041d6002da1e4d707a745390e1f8709eaec53d5 Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Thu, 19 Dec 2024 21:31:44 +0200 Subject: [PATCH 1/3] Make it possible to tophat changes to the extension templates JSON Just pass `SHOPIFY_APP_TEMPLATES_JSON_PATH=/path/to/your/file` and it will draw from there instead of pulling from the live URL. --- .../app-management-client.ts | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts index a4c0d52fa5..4f04b2c5d6 100644 --- a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts +++ b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts @@ -133,8 +133,10 @@ import {outputDebug} from '@shopify/cli-kit/node/output' 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' +const TEMPLATE_PATH_ENV_VARIABLE = 'SHOPIFY_APP_TEMPLATES_JSON_PATH' type OrgType = NonNullable type AccessibleShops = NonNullable @@ -325,24 +327,32 @@ export class AppManagementClient implements DeveloperPlatformClient { } async templateSpecifications({organizationId}: MinimalAppIdentifiers): Promise { - let response let templates: GatedExtensionTemplate[] - try { - response = await fetch(TEMPLATE_JSON_URL) - templates = await (response.json() as Promise) - } 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.', - ], - ) + if (process.env[TEMPLATE_PATH_ENV_VARIABLE]) { + if (!(await fileExists(process.env[TEMPLATE_PATH_ENV_VARIABLE]))) { + throw new AbortError("There is no file at the path specified for template specifications") + } else { + const templatesJson = await readFile(process.env[TEMPLATE_PATH_ENV_VARIABLE]) + templates = JSON.parse(templatesJson) + } + } else { + try { + const response = await fetch(TEMPLATE_JSON_URL) + templates = await (response.json() as Promise) + } 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 From 762cd7b173cdceae73fcffd24bc6f3b510fbd11f Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Thu, 19 Dec 2024 21:36:10 +0200 Subject: [PATCH 2/3] Remove irrelevant link to GitHub --- .../app-management-client.ts | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts index 4f04b2c5d6..77bc30c8ab 100644 --- a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts +++ b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts @@ -330,28 +330,21 @@ export class AppManagementClient implements DeveloperPlatformClient { let templates: GatedExtensionTemplate[] if (process.env[TEMPLATE_PATH_ENV_VARIABLE]) { if (!(await fileExists(process.env[TEMPLATE_PATH_ENV_VARIABLE]))) { - throw new AbortError("There is no file at the path specified for template specifications") - } else { - const templatesJson = await readFile(process.env[TEMPLATE_PATH_ENV_VARIABLE]) - templates = JSON.parse(templatesJson) + throw new AbortError('There is no file at the path specified for template specifications') } + const templatesJson = await readFile(process.env[TEMPLATE_PATH_ENV_VARIABLE]) + templates = JSON.parse(templatesJson) } else { try { const response = await fetch(TEMPLATE_JSON_URL) templates = await (response.json() as Promise) } 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.', - ], - ) + throw new AbortError([ + 'Failed to fetch extension templates from', + {link: {url: TEMPLATE_JSON_URL}}, + {char: '.'}, + 'This likely means a problem with your internet connection.', + ]) } } // Fake the sortPriority as ascending, since the templates are already sorted From a8e7cd99c2ae442459f6df2062d4d0985228f951 Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Sun, 22 Dec 2024 23:46:37 +0200 Subject: [PATCH 3/3] Move constant to constants file --- packages/app/src/cli/constants.ts | 1 + .../developer-platform-client/app-management-client.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/app/src/cli/constants.ts b/packages/app/src/cli/constants.ts index 36afe8a097..1f9a91d131 100644 --- a/packages/app/src/cli/constants.ts +++ b/packages/app/src/cli/constants.ts @@ -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 = { diff --git a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts index 77bc30c8ab..d3d782ba30 100644 --- a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts +++ b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts @@ -4,6 +4,7 @@ import { 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, @@ -136,7 +137,6 @@ 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' -const TEMPLATE_PATH_ENV_VARIABLE = 'SHOPIFY_APP_TEMPLATES_JSON_PATH' type OrgType = NonNullable type AccessibleShops = NonNullable @@ -328,11 +328,13 @@ export class AppManagementClient implements DeveloperPlatformClient { async templateSpecifications({organizationId}: MinimalAppIdentifiers): Promise { let templates: GatedExtensionTemplate[] - if (process.env[TEMPLATE_PATH_ENV_VARIABLE]) { - if (!(await fileExists(process.env[TEMPLATE_PATH_ENV_VARIABLE]))) { + 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(process.env[TEMPLATE_PATH_ENV_VARIABLE]) + const templatesJson = await readFile(overrideFile) templates = JSON.parse(templatesJson) } else { try {