Skip to content

Commit e754d36

Browse files
committed
Loosen metafield owner_type validation since the server will validate it
1 parent fa3a665 commit e754d36

3 files changed

Lines changed: 28 additions & 47 deletions

File tree

‎packages/app/src/cli/models/extensions/schemas.test.ts‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,20 @@ describe('UIDSchema', () => {
5757
})
5858

5959
describe('MetafieldSchema', () => {
60-
test.each(['COMPANY', 'COMPANY_LOCATION', 'CUSTOMER', 'CART', 'PRODUCT', 'PRODUCTVARIANT', 'SHOP'])(
61-
'accepts %s as an owner type',
62-
(ownerType) => {
63-
const result = MetafieldSchema.safeParse({namespace: 'custom', key: 'value', owner_type: ownerType})
60+
test('accepts an owner type for API validation', () => {
61+
const result = MetafieldSchema.safeParse({namespace: 'custom', key: 'value', owner_type: 'PRODUCT'})
6462

65-
expect(result).toEqual({
66-
success: true,
67-
data: {namespace: 'custom', key: 'value', owner_type: ownerType},
68-
})
69-
},
70-
)
63+
expect(result).toEqual({
64+
success: true,
65+
data: {namespace: 'custom', key: 'value', owner_type: 'PRODUCT'},
66+
})
67+
})
7168

7269
test('accepts a metafield without an owner type', () => {
7370
const result = MetafieldSchema.safeParse({namespace: 'custom', key: 'value'})
7471

7572
expect(result.success).toBe(true)
7673
})
77-
78-
test('rejects an unsupported owner type', () => {
79-
const result = MetafieldSchema.safeParse({namespace: 'custom', key: 'value', owner_type: 'ORDER'})
80-
81-
expect(result.success).toBe(false)
82-
})
8374
})
8475

8576
describe('NewExtensionPointsSchema', () => {

‎packages/app/src/cli/models/extensions/schemas.ts‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,10 @@ export const MAX_UID_LENGTH = 250
66
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77
export type ZodSchemaType<T> = zod.ZodType<T, any, any>
88

9-
const MetafieldOwnerTypeSchema = zod.enum([
10-
'COMPANY',
11-
'COMPANY_LOCATION',
12-
'CUSTOMER',
13-
'CART',
14-
'PRODUCT',
15-
'PRODUCTVARIANT',
16-
'SHOP',
17-
])
18-
199
export const MetafieldSchema = zod.object({
2010
namespace: zod.string(),
2111
key: zod.string(),
22-
owner_type: MetafieldOwnerTypeSchema.optional(),
12+
owner_type: zod.string().optional(),
2313
})
2414

2515
const CollectBuyerConsentCapabilitySchema = zod.object({

‎packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('ui_extension', async () => {
4949
const specification = allSpecs.find((spec) => spec.identifier === 'ui_extension')!
5050
const configuration = {
5151
extension_points: extensionPoints,
52-
api_version: apiVersion ?? ('2023-01' as const),
52+
api_version: apiVersion ?? '2023-01',
5353
name: 'UI Extension',
5454
description: 'This is an ordinary test extension.',
5555
type: 'ui_extension',
@@ -117,12 +117,12 @@ describe('ui_extension', async () => {
117117
},
118118
},
119119
],
120-
api_version: '2026-10' as const,
120+
api_version: '2026-10',
121121
handle: 'test-ui-extension',
122122
name: 'UI Extension',
123123
description: 'This is an ordinary test extension',
124124
type: 'ui_extension',
125-
metafields: [{namespace: 'test', key: 'test', owner_type: 'PRODUCT' as const}],
125+
metafields: [{namespace: 'test', key: 'test', owner_type: 'PRODUCT'}],
126126
capabilities: {
127127
block_progress: false,
128128
network_access: false,
@@ -184,14 +184,14 @@ describe('ui_extension', async () => {
184184
{
185185
target: 'EXTENSION::POINT::A',
186186
module: './src/ExtensionPointA.js',
187-
metafields: [{namespace: 'target', key: 'value', owner_type: 'COMPANY_LOCATION' as const}],
187+
metafields: [{namespace: 'target', key: 'value', owner_type: 'COMPANY_LOCATION'}],
188188
},
189189
],
190-
api_version: '2026-10' as const,
190+
api_version: '2026-10',
191191
handle: 'test-ui-extension',
192192
name: 'UI Extension',
193193
type: 'ui_extension',
194-
metafields: [{namespace: 'extension', key: 'value', owner_type: 'SHOP' as const}],
194+
metafields: [{namespace: 'extension', key: 'value', owner_type: 'SHOP'}],
195195
}
196196

197197
const parsed = specification.parseConfigurationObject(configuration)
@@ -215,7 +215,7 @@ describe('ui_extension', async () => {
215215
default_placement: 'PLACEMENT_REFERENCE1',
216216
},
217217
],
218-
api_version: '2023-01' as const,
218+
api_version: '2023-01',
219219
name: 'UI Extension',
220220
description: 'This is an ordinary test extension',
221221
type: 'ui_extension',
@@ -284,7 +284,7 @@ describe('ui_extension', async () => {
284284
capabilities: {allow_direct_linking: true, intercepts},
285285
},
286286
],
287-
api_version: '2023-01' as const,
287+
api_version: '2023-01',
288288
name: 'UI Extension',
289289
description: 'This is an ordinary test extension',
290290
type: 'ui_extension',
@@ -355,7 +355,7 @@ describe('ui_extension', async () => {
355355
preloads: {chat: '/chat', not_supported: '/hello'},
356356
},
357357
],
358-
api_version: '2023-01' as const,
358+
api_version: '2023-01',
359359
name: 'UI Extension',
360360
description: 'This is an ordinary test extension',
361361
type: 'ui_extension',
@@ -423,7 +423,7 @@ describe('ui_extension', async () => {
423423
},
424424
},
425425
],
426-
api_version: '2023-01' as const,
426+
api_version: '2023-01',
427427
name: 'UI Extension',
428428
description: 'This is an ordinary test extension',
429429
type: 'ui_extension',
@@ -493,7 +493,7 @@ describe('ui_extension', async () => {
493493
preloads: {chat: '/chat', not_supported: '/hello'},
494494
},
495495
],
496-
api_version: '2023-01' as const,
496+
api_version: '2023-01',
497497
name: 'UI Extension',
498498
description: 'This is an ordinary test extension',
499499
type: 'ui_extension',
@@ -562,7 +562,7 @@ describe('ui_extension', async () => {
562562
tools: './tools.json',
563563
},
564564
],
565-
api_version: '2023-01' as const,
565+
api_version: '2023-01',
566566
name: 'UI Extension',
567567
description: 'This is an ordinary test extension',
568568
type: 'ui_extension',
@@ -627,7 +627,7 @@ describe('ui_extension', async () => {
627627
instructions: './instructions.md',
628628
},
629629
],
630-
api_version: '2023-01' as const,
630+
api_version: '2023-01',
631631
name: 'UI Extension',
632632
description: 'This is an ordinary test extension',
633633
type: 'ui_extension',
@@ -692,7 +692,7 @@ describe('ui_extension', async () => {
692692
assets: './assets',
693693
},
694694
],
695-
api_version: '2023-01' as const,
695+
api_version: '2023-01',
696696
name: 'UI Extension',
697697
description: 'This is an ordinary test extension',
698698
type: 'ui_extension',
@@ -751,7 +751,7 @@ describe('ui_extension', async () => {
751751
const allSpecs = await loadLocalExtensionsSpecifications()
752752
const specification = allSpecs.find((spec) => spec.identifier === 'ui_extension')!
753753
const configuration = {
754-
api_version: '2023-01' as const,
754+
api_version: '2023-01',
755755
name: 'UI Extension',
756756
description: 'This is an ordinary test extension',
757757
type: 'ui_extension',
@@ -856,7 +856,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
856856
instructions: './instructions.md',
857857
},
858858
],
859-
api_version: '2023-01' as const,
859+
api_version: '2023-01',
860860
name: 'UI Extension',
861861
description: 'This is an ordinary test extension',
862862
type: 'ui_extension',
@@ -994,7 +994,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
994994
module: './src/ExtensionPointA.js',
995995
},
996996
],
997-
api_version: '2025-10' as const,
997+
api_version: '2025-10',
998998
name: 'UI Extension',
999999
type: 'ui_extension',
10001000
handle: 'test-ui-extension',
@@ -1037,7 +1037,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
10371037
const uiExtension = new ExtensionInstance({
10381038
configuration: {
10391039
extension_points: [],
1040-
api_version: '2023-01' as const,
1040+
api_version: '2023-01',
10411041
name: 'UI Extension',
10421042
type: 'ui_extension',
10431043
metafields: [],
@@ -1076,7 +1076,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
10761076
const uiExtension = new ExtensionInstance({
10771077
configuration: {
10781078
extension_points: [],
1079-
api_version: '2023-01' as const,
1079+
api_version: '2023-01',
10801080
name: 'UI Extension',
10811081
type: 'ui_extension',
10821082
metafields: [],
@@ -1115,7 +1115,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
11151115
const uiExtension = new ExtensionInstance({
11161116
configuration: {
11171117
extension_points: [],
1118-
api_version: '2023-01' as const,
1118+
api_version: '2023-01',
11191119
name: 'UI Extension',
11201120
type: 'ui_extension',
11211121
metafields: [],

0 commit comments

Comments
 (0)