From a2c11fe674c63843f0bd1ce8e300f75acd284a98 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Wed, 31 Jul 2024 14:18:46 +0200 Subject: [PATCH 1/2] Fix webhook URI transformation to relative path when the app URL ends with a slash --- .../app/write-app-configuration-file.test.ts | 26 ++++++++++++------- .../app/write-app-configuration-file.ts | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/app/src/cli/services/app/write-app-configuration-file.test.ts b/packages/app/src/cli/services/app/write-app-configuration-file.test.ts index e42f1dbe86..2931fb2813 100644 --- a/packages/app/src/cli/services/app/write-app-configuration-file.test.ts +++ b/packages/app/src/cli/services/app/write-app-configuration-file.test.ts @@ -12,14 +12,20 @@ const FULL_CONFIGURATION = { dev_store_url: 'example.myshopify.com', }, ...DEFAULT_CONFIG, + application_url: 'https://myapp.com/', auth: {redirect_urls: ['https://example.com/redirect', 'https://example.com/redirect2']}, webhooks: { api_version: '2023-07', - privacy_compliance: { - customer_deletion_url: 'https://example.com/auth/callback1', - customer_data_request_url: 'https://example.com/auth/callback2', - shop_deletion_url: 'https://example.com/auth/callback3', - }, + subscriptions: [ + { + topics: ['products/create'], + uri: 'https://myapp.com/webhooks', + }, + { + compliance_topics: ['customer_deletion_url', 'customer_data_request_url'], + uri: 'https://myapp.com/webhooks', + }, + ], }, app_proxy: { url: 'https://example.com/auth/prox', @@ -50,7 +56,7 @@ describe('writeAppConfigurationFile', () => { client_id = "api-key" name = "my app" -application_url = "https://myapp.com" +application_url = "https://myapp.com/" embedded = true [build] @@ -71,10 +77,10 @@ redirect_urls = [ [webhooks] api_version = "2023-07" - [webhooks.privacy_compliance] - customer_deletion_url = "https://example.com/auth/callback1" - customer_data_request_url = "https://example.com/auth/callback2" - shop_deletion_url = "https://example.com/auth/callback3" + [[webhooks.subscriptions]] + topics = [ "products/create" ] + uri = "/webhooks" + compliance_topics = [ "customer_deletion_url", "customer_data_request_url" ] [app_proxy] url = "https://example.com/auth/prox" diff --git a/packages/app/src/cli/services/app/write-app-configuration-file.ts b/packages/app/src/cli/services/app/write-app-configuration-file.ts index 2dccb4e56a..5f4cc9c376 100644 --- a/packages/app/src/cli/services/app/write-app-configuration-file.ts +++ b/packages/app/src/cli/services/app/write-app-configuration-file.ts @@ -1,5 +1,6 @@ import {CurrentAppConfiguration} from '../../models/app/app.js' import {reduceWebhooks} from '../../models/extensions/specifications/transform/app_config_webhook.js' +import {removeTrailingSlash} from '../../models/extensions/specifications/validation/common.js' import {writeFileSync} from '@shopify/cli-kit/node/fs' import {JsonMapType, encodeToml} from '@shopify/cli-kit/node/toml' import {zod} from '@shopify/cli-kit/node/schema' @@ -97,7 +98,7 @@ export const rewriteConfiguration = (schema: T, config function condenseComplianceAndNonComplianceWebhooks(config: CurrentAppConfiguration) { const webhooksConfig = config.webhooks if (webhooksConfig?.subscriptions?.length) { - const appUrl = config?.application_url as string | undefined + const appUrl = removeTrailingSlash(config?.application_url) as string | undefined webhooksConfig.subscriptions = reduceWebhooks(webhooksConfig.subscriptions) webhooksConfig.subscriptions = webhooksConfig.subscriptions.map(({uri, ...subscription}) => ({ uri: appUrl && uri.includes(appUrl) ? uri.replace(appUrl, '') : uri, From 253d1cec0a32898c9eef6db9e546c1a695036235 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Wed, 31 Jul 2024 14:19:35 +0200 Subject: [PATCH 2/2] Add changeset --- .changeset/big-donkeys-wink.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/big-donkeys-wink.md diff --git a/.changeset/big-donkeys-wink.md b/.changeset/big-donkeys-wink.md new file mode 100644 index 0000000000..5ce5631007 --- /dev/null +++ b/.changeset/big-donkeys-wink.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': patch +--- + +Fix webhook URI transformation in TOML to relative path when the app URL ends with a slash