Skip to content

Commit

Permalink
Merge pull request #4652 from Shopify/cp/preloads
Browse files Browse the repository at this point in the history
extension targeting preloads
  • Loading branch information
cpeddecord authored Oct 21, 2024
2 parents 073c104 + 851867c commit 4830e15
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-lions-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

adding optional preloads to ui extension targets
5 changes: 5 additions & 0 deletions packages/app/src/cli/models/extensions/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const NewExtensionPointSchema = zod.object({
metafields: zod.array(MetafieldSchema).optional(),
default_placement: zod.string().optional(),
capabilities: TargetCapabilitiesSchema.optional(),
preloads: zod
.object({
chat: zod.string().optional(),
})
.optional(),
})

export const NewExtensionPointsSchema = zod.array(NewExtensionPointSchema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('ui_extension', async () => {
metafields: [{namespace: 'test', key: 'test'}],
default_placement_reference: undefined,
capabilities: undefined,
preloads: {},
},
])
})
Expand Down Expand Up @@ -170,6 +171,7 @@ describe('ui_extension', async () => {
metafields: [],
default_placement_reference: 'PLACEMENT_REFERENCE1',
capabilities: undefined,
preloads: {},
},
])
})
Expand Down Expand Up @@ -220,6 +222,58 @@ describe('ui_extension', async () => {
metafields: [],
default_placement_reference: undefined,
capabilities: {allow_direct_linking: true},
preloads: {},
},
])
})

test('targeting object accepts preloads', async () => {
const allSpecs = await loadLocalExtensionsSpecifications()
const specification = allSpecs.find((spec) => spec.identifier === 'ui_extension')!
const configuration = {
targeting: [
{
target: 'EXTENSION::POINT::A',
module: './src/ExtensionPointA.js',
preloads: {chat: '/chat', not_supported: '/hello'},
},
],
api_version: '2023-01' as const,
name: 'UI Extension',
description: 'This is an ordinary test extension',
type: 'ui_extension',
capabilities: {
block_progress: false,
network_access: false,
api_access: false,
collect_buyer_consent: {
customer_privacy: true,
sms_marketing: false,
},
iframe: {
sources: [],
},
},
settings: {},
}

// When
const parsed = specification.parseConfigurationObject(configuration)
if (parsed.state !== 'ok') {
throw new Error("Couldn't parse configuration")
}

const got = parsed.data

// Then
expect(got.extension_points).toStrictEqual([
{
target: 'EXTENSION::POINT::A',
module: './src/ExtensionPointA.js',
metafields: [],
default_placement_reference: undefined,
capabilities: undefined,
preloads: {chat: '/chat'},
},
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const UIExtensionSchema = BaseSchema.extend({
metafields: targeting.metafields ?? config.metafields ?? [],
default_placement_reference: targeting.default_placement,
capabilities: targeting.capabilities,
preloads: targeting.preloads ?? {},
}
})
return {...config, extension_points: extensionPoints}
Expand Down

0 comments on commit 4830e15

Please sign in to comment.