From 0c765ef010dcf1b77915e58cd98334e444afc09e Mon Sep 17 00:00:00 2001 From: Chris Peddecord Date: Tue, 15 Oct 2024 16:38:57 -0700 Subject: [PATCH 1/3] extension targeting preloads --- packages/app/.changeset/README.md | 8 +++ packages/app/.changeset/config.json | 11 ++++ .../app/.changeset/nasty-fans-remember.md | 5 ++ .../app/src/cli/models/extensions/schemas.ts | 5 ++ .../specifications/ui_extension.test.ts | 55 +++++++++++++++++++ .../extensions/specifications/ui_extension.ts | 1 + 6 files changed, 85 insertions(+) create mode 100644 packages/app/.changeset/README.md create mode 100644 packages/app/.changeset/config.json create mode 100644 packages/app/.changeset/nasty-fans-remember.md diff --git a/packages/app/.changeset/README.md b/packages/app/.changeset/README.md new file mode 100644 index 0000000000..e5b6d8d6a6 --- /dev/null +++ b/packages/app/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/packages/app/.changeset/config.json b/packages/app/.changeset/config.json new file mode 100644 index 0000000000..ab848d1a1e --- /dev/null +++ b/packages/app/.changeset/config.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": false, + "fixed": [], + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/packages/app/.changeset/nasty-fans-remember.md b/packages/app/.changeset/nasty-fans-remember.md new file mode 100644 index 0000000000..5f4d0c305e --- /dev/null +++ b/packages/app/.changeset/nasty-fans-remember.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': patch +--- + +added extensions.targeting.preloads diff --git a/packages/app/src/cli/models/extensions/schemas.ts b/packages/app/src/cli/models/extensions/schemas.ts index 3eec3e299d..d9e9fbd871 100644 --- a/packages/app/src/cli/models/extensions/schemas.ts +++ b/packages/app/src/cli/models/extensions/schemas.ts @@ -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) diff --git a/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts b/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts index ac15fdea0e..17bdf92dcf 100644 --- a/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts @@ -120,6 +120,7 @@ describe('ui_extension', async () => { metafields: [{namespace: 'test', key: 'test'}], default_placement_reference: undefined, capabilities: undefined, + preloads: {}, }, ]) }) @@ -170,6 +171,7 @@ describe('ui_extension', async () => { metafields: [], default_placement_reference: 'PLACEMENT_REFERENCE1', capabilities: undefined, + preloads: {}, }, ]) }) @@ -220,6 +222,59 @@ 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', + capabilities: {allow_direct_linking: true}, + 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: {allow_direct_linking: true}, + preloads: {chat: '/chat'}, }, ]) }) diff --git a/packages/app/src/cli/models/extensions/specifications/ui_extension.ts b/packages/app/src/cli/models/extensions/specifications/ui_extension.ts index 384c0ecf7c..19bf162670 100644 --- a/packages/app/src/cli/models/extensions/specifications/ui_extension.ts +++ b/packages/app/src/cli/models/extensions/specifications/ui_extension.ts @@ -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} From 1a220b151502a8a738ed81777db7c64a611c5aba Mon Sep 17 00:00:00 2001 From: Chris Peddecord Date: Thu, 17 Oct 2024 13:45:38 -0700 Subject: [PATCH 2/3] test nits --- .../cli/models/extensions/specifications/ui_extension.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts b/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts index 17bdf92dcf..bd489a84ac 100644 --- a/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts +++ b/packages/app/src/cli/models/extensions/specifications/ui_extension.test.ts @@ -235,7 +235,6 @@ describe('ui_extension', async () => { { target: 'EXTENSION::POINT::A', module: './src/ExtensionPointA.js', - capabilities: {allow_direct_linking: true}, preloads: {chat: '/chat', not_supported: '/hello'}, }, ], @@ -273,7 +272,7 @@ describe('ui_extension', async () => { module: './src/ExtensionPointA.js', metafields: [], default_placement_reference: undefined, - capabilities: {allow_direct_linking: true}, + capabilities: undefined, preloads: {chat: '/chat'}, }, ]) From 851867cbb27f4a435ad44c1999eae709e7d27615 Mon Sep 17 00:00:00 2001 From: Chris Peddecord Date: Mon, 21 Oct 2024 08:29:18 -0700 Subject: [PATCH 3/3] proper changeset --- .changeset/heavy-lions-brush.md | 5 +++++ packages/app/.changeset/README.md | 8 -------- packages/app/.changeset/config.json | 11 ----------- packages/app/.changeset/nasty-fans-remember.md | 5 ----- 4 files changed, 5 insertions(+), 24 deletions(-) create mode 100644 .changeset/heavy-lions-brush.md delete mode 100644 packages/app/.changeset/README.md delete mode 100644 packages/app/.changeset/config.json delete mode 100644 packages/app/.changeset/nasty-fans-remember.md diff --git a/.changeset/heavy-lions-brush.md b/.changeset/heavy-lions-brush.md new file mode 100644 index 0000000000..989fa97cac --- /dev/null +++ b/.changeset/heavy-lions-brush.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': patch +--- + +adding optional preloads to ui extension targets diff --git a/packages/app/.changeset/README.md b/packages/app/.changeset/README.md deleted file mode 100644 index e5b6d8d6a6..0000000000 --- a/packages/app/.changeset/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Changesets - -Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works -with multi-package repos, or single-package repos to help you version and publish your code. You can -find the full documentation for it [in our repository](https://github.com/changesets/changesets) - -We have a quick list of common questions to get you started engaging with this project in -[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/packages/app/.changeset/config.json b/packages/app/.changeset/config.json deleted file mode 100644 index ab848d1a1e..0000000000 --- a/packages/app/.changeset/config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", - "changelog": "@changesets/cli/changelog", - "commit": false, - "fixed": [], - "linked": [], - "access": "restricted", - "baseBranch": "main", - "updateInternalDependencies": "patch", - "ignore": [] -} diff --git a/packages/app/.changeset/nasty-fans-remember.md b/packages/app/.changeset/nasty-fans-remember.md deleted file mode 100644 index 5f4d0c305e..0000000000 --- a/packages/app/.changeset/nasty-fans-remember.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@shopify/app': patch ---- - -added extensions.targeting.preloads