Skip to content

Commit d20c9a8

Browse files
committed
Add support for Metafields to webhooks
1 parent ed55fc7 commit d20c9a8

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

packages/app/src/cli/models/app/app.test-data.ts

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ export async function testSingleWebhookSubscriptionExtension({
428428
topic,
429429
api_version: '2024-01',
430430
uri: 'https://my-app.com/webhooks',
431+
metafields: [{namespace: 'custom', key: 'test'}],
431432
},
432433
}: {
433434
emptyConfig?: boolean

packages/app/src/cli/models/extensions/specifications/app_config_webhook.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ describe('webhooks', () => {
1313
{
1414
topics: ['orders/create'],
1515
uri: 'https://example.com/webhooks/orders',
16+
metafields: [{namespace: 'custom', key: 'test'}],
1617
},
1718
{
1819
topics: ['products/create'],
1920
uri: 'https://example.com/webhooks/products',
21+
metafields: [{namespace: 'custom', key: 'test'}],
2022
},
2123
],
2224
},
@@ -41,10 +43,12 @@ describe('webhooks', () => {
4143
{
4244
topic: 'orders/create',
4345
uri: 'https://example.com/webhooks/orders',
46+
metafields: [{namespace: 'custom', key: 'test'}],
4447
},
4548
{
4649
topic: 'products/create',
4750
uri: 'https://example.com/webhooks/products',
51+
metafields: [{namespace: 'custom', key: 'test'}],
4852
},
4953
],
5054
}

packages/app/src/cli/models/extensions/specifications/app_config_webhook_schemas/webhook_subscription_schema.ts

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ export const WebhookSubscriptionSchema = zod.object({
1818
}),
1919
include_fields: zod.array(zod.string({invalid_type_error: 'Value must be a string'})).optional(),
2020
filter: zod.string({invalid_type_error: 'Value must be a string'}).optional(),
21+
metafields: zod
22+
.array(
23+
zod.object({
24+
namespace: zod.string({invalid_type_error: 'Metafield namespace must be a string'}),
25+
key: zod.string({invalid_type_error: 'Metafield key must be a string'}),
26+
}),
27+
{invalid_type_error: 'Metafields must be an array of objects with namespace and key'},
28+
)
29+
.optional(),
2130
compliance_topics: zod
2231
.array(
2332
zod.enum([ComplianceTopic.CustomersRedact, ComplianceTopic.CustomersDataRequest, ComplianceTopic.ShopRedact]),

packages/app/src/cli/models/extensions/specifications/app_config_webhook_subscription.ts

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ interface TransformedWebhookSubscription {
1313
compliance_topics?: string[]
1414
include_fields?: string[]
1515
filter?: string
16+
metafields?: {
17+
namespace: string
18+
key: string
19+
}[]
1620
}
1721

1822
export const SingleWebhookSubscriptionSchema = zod.object({
@@ -23,6 +27,15 @@ export const SingleWebhookSubscriptionSchema = zod.object({
2327
}),
2428
include_fields: zod.array(zod.string({invalid_type_error: 'Value must be a string'})).optional(),
2529
filter: zod.string({invalid_type_error: 'Value must be a string'}).optional(),
30+
metafields: zod
31+
.array(
32+
zod.object({
33+
namespace: zod.string({invalid_type_error: 'Metafield namespace must be a string'}),
34+
key: zod.string({invalid_type_error: 'Metafield key must be a string'}),
35+
}),
36+
{invalid_type_error: 'Metafields must be an array of objects with namespace and key'},
37+
)
38+
.optional(),
2639
})
2740

2841
/* this transforms webhooks remotely to be accepted by the TOML

packages/app/src/cli/models/extensions/specifications/types/app_config_webhook.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ export interface WebhookSubscription {
44
compliance_topics?: string[]
55
include_fields?: string[]
66
filter?: string
7+
metafields?: {
8+
namespace: string
9+
key: string
10+
}[]
711
}
812

913
interface PrivacyComplianceConfig {

0 commit comments

Comments
 (0)