Skip to content

Commit

Permalink
Merge pull request #4253 from Shopify/fix-relative-webhooks-rewrite
Browse files Browse the repository at this point in the history
Fix relative webhooks TOML transformation
  • Loading branch information
gonzaloriestra committed Jul 31, 2024
2 parents d7cbaa8 + 253d1ce commit 394ca71
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-donkeys-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Fix webhook URI transformation in TOML to relative path when the app URL ends with a slash
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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]
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -97,7 +98,7 @@ export const rewriteConfiguration = <T extends zod.ZodTypeAny>(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,
Expand Down

0 comments on commit 394ca71

Please sign in to comment.