From 2041d6002da1e4d707a745390e1f8709eaec53d5 Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Thu, 19 Dec 2024 21:31:44 +0200 Subject: [PATCH] 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 a4c0d52fa54..4f04b2c5d6c 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