Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 3 additions & 35 deletions packages/app/src/cli/models/app/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2172,10 +2172,7 @@ redirect_urls = [ "https://example.com/api/auth" ]
{
webhooks: {
api_version: '2024-01',
subscriptions: [
{topics: ['orders/create'], uri: 'https://example.com'},
{topics: ['orders/delete'], uri: 'https://example.com'},
],
subscriptions: [{topics: ['orders/create', 'orders/delete'], uri: 'https://example.com'}],
},
name: 'for-testing-webhooks',
},
Expand Down Expand Up @@ -3084,39 +3081,10 @@ describe('WebhooksSchema', () => {
],
}

const expandedWebhookConfig: WebhooksConfig = {
api_version: '2021-07',
subscriptions: [
{
uri: 'arn:aws:events:us-west-2::event-source/aws.partner/shopify.com/1234567890/SOME_PATH',
topics: ['products/create'],
},
{
uri: 'arn:aws:events:us-west-2::event-source/aws.partner/shopify.com/1234567890/SOME_PATH',
topics: ['products/update'],
},
{
uri: 'https://example.com',
topics: ['products/create'],
},
{
uri: 'https://example.com',
topics: ['products/update'],
},
{
uri: 'pubsub://my-project-123:my-topic',
topics: ['products/create'],
},
{
uri: 'pubsub://my-project-123:my-topic',
topics: ['products/update'],
},
],
}

const {abortOrReport, parsedConfiguration} = await setupParsing({}, webhookConfig)
expect(abortOrReport).not.toHaveBeenCalled()
expect(parsedConfiguration.webhooks).toMatchObject(expandedWebhookConfig)
// Without the parse-time mergeAllWebhooks transform, subscriptions preserve their raw multi-topic form
expect(parsedConfiguration.webhooks).toMatchObject(webhookConfig)
})

test('throws an error if we have duplicate subscriptions in same topics array', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {WebhookSubscriptionSchema} from './webhook_subscription_schema.js'
import {webhookValidator} from '../validation/app_config_webhook.js'
import {WebhookSubscriptionUriValidation} from '../validation/common.js'
import {SingleWebhookSubscriptionSchema} from '../app_config_webhook_subscription.js'
import {mergeAllWebhooks} from '../transform/app_config_webhook.js'
import {BaseSchemaWithoutHandle} from '../../schemas.js'
import {zod} from '@shopify/cli-kit/node/schema'

Expand All @@ -15,10 +14,7 @@ const WebhooksConfigSchema = zod.object({
shop_deletion_url: WebhookSubscriptionUriValidation.optional(),
})
.optional(),
subscriptions: zod
.array(WebhookSubscriptionSchema)
.optional()
.transform((value) => mergeAllWebhooks(value ?? [])),
subscriptions: zod.array(WebhookSubscriptionSchema).optional(),
})

export type SingleWebhookSubscriptionType = zod.infer<typeof SingleWebhookSubscriptionSchema>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Config pipeline snapshots > config round-trip (write → read → write) reorders webhook subscriptions 1`] = `
"# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration

client_id = \\"12345\\"
name = \\"My Test App\\"
application_url = \\"https://myapp.example.com\\"
embedded = true

[build]
automatically_update_urls_on_dev = true
dev_store_url = \\"test-store.myshopify.com\\"
include_config_on_deploy = true

[access.admin]
direct_api_mode = \\"online\\"
embedded_app_direct_api_access = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = \\"read_products,write_orders\\"
required_scopes = [ \\"read_products\\" ]
optional_scopes = [ \\"write_orders\\" ]
use_legacy_install_flow = false

[auth]
redirect_urls = [
\\"https://myapp.example.com/auth/callback\\",
\\"https://myapp.example.com/auth/shopify/callback\\"
]

[webhooks]
api_version = \\"2024-01\\"

[[webhooks.subscriptions]]
uri = \\"/webhooks/compliance\\"
compliance_topics = [ \\"customers/data_request\\", \\"customers/redact\\" ]

[[webhooks.subscriptions]]
topics = [ \\"orders/create\\" ]
uri = \\"/webhooks/orders\\"

[[webhooks.subscriptions]]
topics = [ \\"products/create\\", \\"products/update\\" ]
uri = \\"/webhooks/products\\"

[app_proxy]
url = \\"https://myapp.example.com/proxy\\"
subpath = \\"app\\"
prefix = \\"apps\\"

[pos]
embedded = false

[app_preferences]
url = \\"https://myapp.example.com/preferences\\"
"
`;

exports[`Config pipeline snapshots > minimal config without webhooks produces stable output 1`] = `
"# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration

Expand All @@ -69,172 +11,6 @@ embedded = true
[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = \\"read_products\\"

[auth]
redirect_urls = [ \\"https://example.com/auth/callback\\" ]
"
`;

exports[`Config pipeline snapshots > subscription with both topics and compliance_topics on same URI splits after round-trip 1`] = `
"# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration

client_id = \\"12345\\"
name = \\"My Test App\\"
application_url = \\"https://myapp.example.com\\"
embedded = true

[build]
automatically_update_urls_on_dev = true
dev_store_url = \\"test-store.myshopify.com\\"
include_config_on_deploy = true

[access.admin]
direct_api_mode = \\"online\\"
embedded_app_direct_api_access = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = \\"read_products,write_orders\\"
required_scopes = [ \\"read_products\\" ]
optional_scopes = [ \\"write_orders\\" ]
use_legacy_install_flow = false

[auth]
redirect_urls = [
\\"https://myapp.example.com/auth/callback\\",
\\"https://myapp.example.com/auth/shopify/callback\\"
]

[webhooks]
api_version = \\"2024-01\\"

[[webhooks.subscriptions]]
topics = [ \\"orders/create\\" ]
uri = \\"/webhooks\\"
compliance_topics = [ \\"customers/data_request\\", \\"customers/redact\\" ]

[app_proxy]
url = \\"https://myapp.example.com/proxy\\"
subpath = \\"app\\"
prefix = \\"apps\\"

[pos]
embedded = false

[app_preferences]
url = \\"https://myapp.example.com/preferences\\"
"
`;

exports[`Config pipeline snapshots > subscriptions with same URI but different filters stay separate through round-trip 1`] = `
"# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration

client_id = \\"12345\\"
name = \\"My Test App\\"
application_url = \\"https://myapp.example.com\\"
embedded = true

[build]
automatically_update_urls_on_dev = true
dev_store_url = \\"test-store.myshopify.com\\"
include_config_on_deploy = true

[access.admin]
direct_api_mode = \\"online\\"
embedded_app_direct_api_access = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = \\"read_products,write_orders\\"
required_scopes = [ \\"read_products\\" ]
optional_scopes = [ \\"write_orders\\" ]
use_legacy_install_flow = false

[auth]
redirect_urls = [
\\"https://myapp.example.com/auth/callback\\",
\\"https://myapp.example.com/auth/shopify/callback\\"
]

[webhooks]
api_version = \\"2024-01\\"

[[webhooks.subscriptions]]
topics = [ \\"orders/create\\" ]
uri = \\"/webhooks/orders\\"
filter = \\"status:paid\\"

[[webhooks.subscriptions]]
topics = [ \\"orders/update\\" ]
uri = \\"/webhooks/orders\\"
filter = \\"status:pending\\"

[app_proxy]
url = \\"https://myapp.example.com/proxy\\"
subpath = \\"app\\"
prefix = \\"apps\\"

[pos]
embedded = false

[app_preferences]
url = \\"https://myapp.example.com/preferences\\"
"
`;

exports[`Config pipeline snapshots > subscriptions with same URI but different include_fields stay separate through round-trip 1`] = `
"# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration

client_id = \\"12345\\"
name = \\"My Test App\\"
application_url = \\"https://myapp.example.com\\"
embedded = true

[build]
automatically_update_urls_on_dev = true
dev_store_url = \\"test-store.myshopify.com\\"
include_config_on_deploy = true

[access.admin]
direct_api_mode = \\"online\\"
embedded_app_direct_api_access = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = \\"read_products,write_orders\\"
required_scopes = [ \\"read_products\\" ]
optional_scopes = [ \\"write_orders\\" ]
use_legacy_install_flow = false

[auth]
redirect_urls = [
\\"https://myapp.example.com/auth/callback\\",
\\"https://myapp.example.com/auth/shopify/callback\\"
]

[webhooks]
api_version = \\"2024-01\\"

[[webhooks.subscriptions]]
topics = [ \\"products/create\\" ]
uri = \\"/webhooks/products\\"
include_fields = [ \\"id\\", \\"title\\" ]

[[webhooks.subscriptions]]
topics = [ \\"products/update\\" ]
uri = \\"/webhooks/products\\"
include_fields = [ \\"id\\" ]

[app_proxy]
url = \\"https://myapp.example.com/proxy\\"
subpath = \\"app\\"
prefix = \\"apps\\"

[pos]
embedded = false

[app_preferences]
url = \\"https://myapp.example.com/preferences\\"
"
`;

Expand All @@ -251,15 +27,9 @@ automatically_update_urls_on_dev = true
dev_store_url = \\"test-store.myshopify.com\\"
include_config_on_deploy = true

[access.admin]
direct_api_mode = \\"online\\"
embedded_app_direct_api_access = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = \\"read_products,write_orders\\"
required_scopes = [ \\"read_products\\" ]
optional_scopes = [ \\"write_orders\\" ]
use_legacy_install_flow = false

[auth]
Expand Down Expand Up @@ -301,7 +71,7 @@ url = \\"https://myapp.example.com/preferences\\"
"
`;

exports[`Config pipeline snapshots > webhook subscriptions with mixed topics and compliance topics produce stable output 2`] = `
exports[`Config pipeline snapshots > writeAppConfigurationFile produces stable TOML output for a full config 1`] = `
"# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration

client_id = \\"12345\\"
Expand All @@ -314,15 +84,9 @@ automatically_update_urls_on_dev = true
dev_store_url = \\"test-store.myshopify.com\\"
include_config_on_deploy = true

[access.admin]
direct_api_mode = \\"online\\"
embedded_app_direct_api_access = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = \\"read_products,write_orders\\"
required_scopes = [ \\"read_products\\" ]
optional_scopes = [ \\"write_orders\\" ]
use_legacy_install_flow = false

[auth]
Expand All @@ -335,21 +99,16 @@ redirect_urls = [
api_version = \\"2024-01\\"

[[webhooks.subscriptions]]
uri = \\"/webhooks/compliance\\"
compliance_topics = [ \\"customers/data_request\\", \\"customers/redact\\", \\"shop/redact\\" ]

[[webhooks.subscriptions]]
topics = [ \\"app/uninstalled\\" ]
uri = \\"/webhooks/app\\"
topics = [ \\"products/create\\", \\"products/update\\" ]
uri = \\"/webhooks/products\\"

[[webhooks.subscriptions]]
topics = [ \\"orders/cancelled\\", \\"orders/create\\", \\"orders/updated\\" ]
topics = [ \\"orders/create\\" ]
uri = \\"/webhooks/orders\\"

[[webhooks.subscriptions]]
topics = [ \\"products/create\\" ]
uri = \\"/webhooks/products\\"
include_fields = [ \\"id\\", \\"title\\" ]
uri = \\"/webhooks/compliance\\"
compliance_topics = [ \\"customers/data_request\\", \\"customers/redact\\" ]

[app_proxy]
url = \\"https://myapp.example.com/proxy\\"
Expand Down
Loading
Loading