Skip to content

Commit

Permalink
Merge pull request #4516 from Shopify/fix-duplicated-slash-compliance…
Browse files Browse the repository at this point in the history
…-webhooks-stable

[Stable] Fix duplicated slash compliance webhooks
  • Loading branch information
gonzaloriestra authored Sep 25, 2024
2 parents 119f9ad + 27c345b commit 64de7e5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/metal-plants-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Remove duplicated slashes when deploying privacy compliance webhooks with relative URIs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ describe('privacy_compliance_webhooks', () => {
// Then
expect(isEmpty(result)).toBeTruthy()
})

test('should transform with relative URIs', () => {
// Given
const object = {
webhooks: {
api_version: '2024-07',
subscriptions: [
{
compliance_topics: ['customers/redact', 'customers/data_request'],
uri: '/customers_webhooks',
},
{
compliance_topics: ['shop/redact'],
uri: '/shop_webhooks',
},
],
},
}
const privacyComplianceSpec = spec
const appConfiguration = {application_url: 'https://example.com/', scopes: ''}

// When
const result = privacyComplianceSpec.transformLocalToRemote!(object, appConfiguration)

// Then
expect(result).toMatchObject({
api_version: '2024-07',
customers_redact_url: 'https://example.com/customers_webhooks',
customers_data_request_url: 'https://example.com/customers_webhooks',
shop_redact_url: 'https://example.com/shop_webhooks',
})
})
})

describe('reverseTransform with declarative_webhooks flag', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {WebhookSubscription, WebhooksConfig} from './types/app_config_webhook.js
import {WebhooksSchema} from './app_config_webhook_schemas/webhooks_schema.js'
import {ComplianceTopic} from './app_config_webhook_schemas/webhook_subscription_schema.js'
import {mergeAllWebhooks} from './transform/app_config_webhook.js'
import {removeTrailingSlash} from './validation/common.js'
import {CustomTransformationConfig, createConfigExtensionSpecification} from '../specification.js'
import {Flag} from '../../../utilities/developer-platform-client.js'
import {AppConfigurationWithoutPath, CurrentAppConfiguration} from '../../app/app.js'
Expand Down Expand Up @@ -89,7 +90,7 @@ function getComplianceUri(webhooks: WebhooksConfig, complianceTopic: string): st
}

function relativeUri(uri?: string, appUrl?: string) {
return appUrl && uri?.startsWith('/') ? `${appUrl}${uri}` : uri
return appUrl && uri?.startsWith('/') ? `${removeTrailingSlash(appUrl)}${uri}` : uri
}

function getCustomersDeletionUri(webhooks: WebhooksConfig) {
Expand Down

0 comments on commit 64de7e5

Please sign in to comment.