Skip to content

Commit 80909e4

Browse files
authored
Merge pull request #6212 from Shopify/08-05-pass_app_module_context_through_to_registration_s_activeversion_if_it_exists
Pass app module context through to registration's activeVersion if it exists
2 parents d80c3dc + 1afbe62 commit 80909e4

File tree

9 files changed

+157
-1
lines changed

9 files changed

+157
-1
lines changed

packages/app/src/cli/api/graphql/app-management/generated/active-app-release-from-api-key.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type ActiveAppReleaseFromApiKeyQuery = {
2323
userIdentifier: string
2424
handle: string
2525
config: JsonMapType
26+
target?: string | null
2627
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
2728
}[]
2829
}
@@ -80,6 +81,7 @@ export const ActiveAppReleaseFromApiKey = {
8081
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
8182
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
8283
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
84+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
8385
{
8486
kind: 'Field',
8587
name: {kind: 'Name', value: 'specification'},

packages/app/src/cli/api/graphql/app-management/generated/active-app-release.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type ActiveAppReleaseQuery = {
2323
userIdentifier: string
2424
handle: string
2525
config: JsonMapType
26+
target?: string | null
2627
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
2728
}[]
2829
}
@@ -44,6 +45,7 @@ export type AppVersionInfoFragment = {
4445
userIdentifier: string
4546
handle: string
4647
config: JsonMapType
48+
target?: string | null
4749
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
4850
}[]
4951
}
@@ -55,6 +57,7 @@ export type ReleasedAppModuleFragment = {
5557
userIdentifier: string
5658
handle: string
5759
config: JsonMapType
60+
target?: string | null
5861
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
5962
}
6063

@@ -72,6 +75,7 @@ export const ReleasedAppModuleFragmentDoc = {
7275
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
7376
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
7477
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
78+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
7579
{
7680
kind: 'Field',
7781
name: {kind: 'Name', value: 'specification'},
@@ -171,6 +175,7 @@ export const AppVersionInfoFragmentDoc = {
171175
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
172176
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
173177
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
178+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
174179
{
175180
kind: 'Field',
176181
name: {kind: 'Name', value: 'specification'},
@@ -238,6 +243,7 @@ export const ActiveAppRelease = {
238243
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
239244
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
240245
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
246+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
241247
{
242248
kind: 'Field',
243249
name: {kind: 'Name', value: 'specification'},

packages/app/src/cli/api/graphql/app-management/generated/app-version-by-id.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type AppVersionByIdQuery = {
1717
userIdentifier: string
1818
handle: string
1919
config: JsonMapType
20+
target?: string | null
2021
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
2122
}[]
2223
}
@@ -30,6 +31,7 @@ export type VersionInfoFragment = {
3031
userIdentifier: string
3132
handle: string
3233
config: JsonMapType
34+
target?: string | null
3335
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
3436
}[]
3537
}
@@ -78,6 +80,7 @@ export const VersionInfoFragmentDoc = {
7880
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
7981
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
8082
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
83+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
8184
{
8285
kind: 'Field',
8386
name: {kind: 'Name', value: 'specification'},
@@ -145,6 +148,7 @@ export const AppVersionById = {
145148
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
146149
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
147150
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
151+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
148152
{
149153
kind: 'Field',
150154
name: {kind: 'Name', value: 'specification'},

packages/app/src/cli/api/graphql/app-management/generated/app-version-by-tag.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type AppVersionByTagQuery = {
1717
userIdentifier: string
1818
handle: string
1919
config: JsonMapType
20+
target?: string | null
2021
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
2122
}[]
2223
}
@@ -71,6 +72,7 @@ export const AppVersionByTag = {
7172
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
7273
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
7374
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
75+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
7476
{
7577
kind: 'Field',
7678
name: {kind: 'Name', value: 'specification'},

packages/app/src/cli/api/graphql/app-management/generated/create-app-version.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type CreateAppVersionMutation = {
1919
userIdentifier: string
2020
handle: string
2121
config: JsonMapType
22+
target?: string | null
2223
specification: {identifier: string; externalIdentifier: string; name: string; managementExperience: string}
2324
}[]
2425
metadata: {versionTag?: string | null; message?: string | null}
@@ -150,6 +151,7 @@ export const CreateAppVersion = {
150151
{kind: 'Field', name: {kind: 'Name', value: 'userIdentifier'}},
151152
{kind: 'Field', name: {kind: 'Name', value: 'handle'}},
152153
{kind: 'Field', name: {kind: 'Name', value: 'config'}},
154+
{kind: 'Field', name: {kind: 'Name', value: 'target'}},
153155
{
154156
kind: 'Field',
155157
name: {kind: 'Name', value: 'specification'},

packages/app/src/cli/api/graphql/app-management/queries/active-app-release.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fragment ReleasedAppModule on AppModule {
3131
userIdentifier
3232
handle
3333
config
34+
target
3435
specification {
3536
identifier
3637
externalIdentifier

packages/app/src/cli/utilities/developer-platform-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export interface AppModuleVersion {
125125
registrationUuid?: string
126126
registrationTitle: string
127127
config?: object
128+
target?: string
128129
type: string
129130
specification?: AppModuleVersionSpecification
130131
}

packages/app/src/cli/utilities/developer-platform-client/app-management-client.test.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,4 +1602,136 @@ describe('appExtensionRegistrations', () => {
16021602
expect(result.app.extensionRegistrations).toHaveLength(2)
16031603
expect(result.app.dashboardManagedExtensionRegistrations).toHaveLength(2)
16041604
})
1605+
1606+
test('includes activeVersion with config when config is present', async () => {
1607+
const configData = {name: 'Test Extension', enabled: true}
1608+
const extensionModule = createMockAppModuleVersion({
1609+
registrationId: 'extension-with-config',
1610+
registrationTitle: 'Extension With Config',
1611+
config: configData,
1612+
})
1613+
1614+
const activeAppVersion = {
1615+
appModuleVersions: [extensionModule],
1616+
}
1617+
1618+
const result = await client.appExtensionRegistrations(appIdentifiers, activeAppVersion)
1619+
1620+
expect(result.app.extensionRegistrations).toHaveLength(1)
1621+
expect(result.app.extensionRegistrations[0]).toEqual({
1622+
id: 'extension-with-config',
1623+
uuid: 'mock-uuid',
1624+
title: 'Extension With Config',
1625+
type: 'ui_extension',
1626+
activeVersion: {
1627+
config: JSON.stringify(configData),
1628+
},
1629+
})
1630+
})
1631+
1632+
test('includes activeVersion with config and context when both are present', async () => {
1633+
const configData = {name: 'Test Extension', enabled: true}
1634+
const contextData = 'some-context-value'
1635+
const extensionModule = createMockAppModuleVersion({
1636+
registrationId: 'extension-with-config-and-context',
1637+
registrationTitle: 'Extension With Config And Context',
1638+
config: configData,
1639+
target: contextData,
1640+
})
1641+
1642+
const activeAppVersion = {
1643+
appModuleVersions: [extensionModule],
1644+
}
1645+
1646+
const result = await client.appExtensionRegistrations(appIdentifiers, activeAppVersion)
1647+
1648+
expect(result.app.extensionRegistrations).toHaveLength(1)
1649+
expect(result.app.extensionRegistrations[0]).toEqual({
1650+
id: 'extension-with-config-and-context',
1651+
uuid: 'mock-uuid',
1652+
title: 'Extension With Config And Context',
1653+
type: 'ui_extension',
1654+
activeVersion: {
1655+
config: JSON.stringify(configData),
1656+
context: contextData,
1657+
},
1658+
})
1659+
})
1660+
1661+
test('excludes activeVersion when config is not present', async () => {
1662+
const extensionModule = createMockAppModuleVersion({
1663+
registrationId: 'extension-without-config',
1664+
registrationTitle: 'Extension Without Config',
1665+
config: undefined,
1666+
target: 'some-context',
1667+
})
1668+
1669+
const activeAppVersion = {
1670+
appModuleVersions: [extensionModule],
1671+
}
1672+
1673+
const result = await client.appExtensionRegistrations(appIdentifiers, activeAppVersion)
1674+
1675+
expect(result.app.extensionRegistrations).toHaveLength(1)
1676+
expect(result.app.extensionRegistrations[0]).toEqual({
1677+
id: 'extension-without-config',
1678+
uuid: 'mock-uuid',
1679+
title: 'Extension Without Config',
1680+
type: 'ui_extension',
1681+
activeVersion: undefined,
1682+
})
1683+
})
1684+
1685+
test('includes only config when context is not present', async () => {
1686+
const configData = {name: 'Test Extension', enabled: false}
1687+
const extensionModule = createMockAppModuleVersion({
1688+
registrationId: 'extension-with-config-only',
1689+
registrationTitle: 'Extension With Config Only',
1690+
config: configData,
1691+
target: undefined,
1692+
})
1693+
1694+
const activeAppVersion = {
1695+
appModuleVersions: [extensionModule],
1696+
}
1697+
1698+
const result = await client.appExtensionRegistrations(appIdentifiers, activeAppVersion)
1699+
1700+
expect(result.app.extensionRegistrations).toHaveLength(1)
1701+
expect(result.app.extensionRegistrations[0]).toEqual({
1702+
id: 'extension-with-config-only',
1703+
uuid: 'mock-uuid',
1704+
title: 'Extension With Config Only',
1705+
type: 'ui_extension',
1706+
activeVersion: {
1707+
config: JSON.stringify(configData),
1708+
},
1709+
})
1710+
})
1711+
1712+
test('handles empty config object correctly', async () => {
1713+
const configData = {}
1714+
const extensionModule = createMockAppModuleVersion({
1715+
registrationId: 'extension-with-empty-config',
1716+
registrationTitle: 'Extension With Empty Config',
1717+
config: configData,
1718+
})
1719+
1720+
const activeAppVersion = {
1721+
appModuleVersions: [extensionModule],
1722+
}
1723+
1724+
const result = await client.appExtensionRegistrations(appIdentifiers, activeAppVersion)
1725+
1726+
expect(result.app.extensionRegistrations).toHaveLength(1)
1727+
expect(result.app.extensionRegistrations[0]).toEqual({
1728+
id: 'extension-with-empty-config',
1729+
uuid: 'mock-uuid',
1730+
title: 'Extension With Empty Config',
1731+
type: 'ui_extension',
1732+
activeVersion: {
1733+
config: JSON.stringify(configData),
1734+
},
1735+
})
1736+
})
16051737
})

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,12 @@ export class AppManagementClient implements DeveloperPlatformClient {
571571
uuid: mod.registrationUuid!,
572572
title: mod.registrationTitle,
573573
type: mod.type,
574-
activeVersion: mod.config ? {config: JSON.stringify(mod.config)} : undefined,
574+
activeVersion: mod.config
575+
? {
576+
config: JSON.stringify(mod.config),
577+
...(mod.target && {context: mod.target}),
578+
}
579+
: undefined,
575580
}
576581
if (CONFIG_EXTENSION_IDS.includes(registration.id)) {
577582
configurationRegistrations.push(registration)
@@ -1331,6 +1336,7 @@ function appModuleVersion(mod: ReleasedAppModuleFragment): Required<AppModuleVer
13311336
registrationTitle: mod.handle,
13321337
type: mod.specification.externalIdentifier,
13331338
config: mod.config,
1339+
target: mod.target ?? '',
13341340
specification: {
13351341
...mod.specification,
13361342
identifier: mod.specification.identifier,

0 commit comments

Comments
 (0)