Skip to content

Commit f148928

Browse files
committed
Modify config update message for legacy install flow
1 parent 415d367 commit f148928

File tree

5 files changed

+127
-4
lines changed

5 files changed

+127
-4
lines changed

.changeset/poor-ghosts-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/app': patch
3+
---
4+
5+
Modify app access config update message for legacy install flow

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export async function testAppConfigExtensions(emptyConfig = false, directory?: s
325325
export async function testAppAccessConfigExtension(
326326
emptyConfig = false,
327327
directory?: string,
328+
useLegacyInstallFlow = true,
328329
): Promise<ExtensionInstance> {
329330
const configuration = emptyConfig
330331
? ({} as unknown as BaseConfigType)
@@ -334,7 +335,7 @@ export async function testAppAccessConfigExtension(
334335
},
335336
access_scopes: {
336337
scopes: 'read_products,write_products',
337-
use_legacy_install_flow: true,
338+
use_legacy_install_flow: useLegacyInstallFlow,
338339
},
339340
auth: {
340341
redirect_urls: ['https://example.com/auth/callback'],

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

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('app_config_app_access', () => {
112112
expect(result).toEqual(['Access scopes auto-granted: write_orders, read_inventory'])
113113
})
114114

115-
test('should return default message when no scopes are provided', async () => {
115+
test('should return managed install flow empty scopes message when no access_scopes are provided', async () => {
116116
// Given
117117
const config = {
118118
auth: {
@@ -126,5 +126,114 @@ describe('app_config_app_access', () => {
126126
// Then
127127
expect(result).toEqual(['App has been installed'])
128128
})
129+
130+
test('should return legacy install flow message when use_legacy_install_flow is true', async () => {
131+
// Given
132+
const config = {
133+
access_scopes: {
134+
scopes: 'read_products,write_products',
135+
use_legacy_install_flow: true,
136+
},
137+
auth: {
138+
redirect_urls: ['https://example.com/auth/callback'],
139+
},
140+
}
141+
142+
// When
143+
const result = await spec.getDevSessionUpdateMessages!(config)
144+
145+
// Then
146+
expect(result).toEqual(['Using legacy install flow - access scopes are not auto-granted'])
147+
})
148+
149+
test('should return legacy install flow message even with required_scopes when use_legacy_install_flow is true', async () => {
150+
// Given
151+
const config = {
152+
access_scopes: {
153+
required_scopes: ['write_orders', 'read_inventory'],
154+
use_legacy_install_flow: true,
155+
},
156+
auth: {
157+
redirect_urls: ['https://example.com/auth/callback'],
158+
},
159+
}
160+
161+
// When
162+
const result = await spec.getDevSessionUpdateMessages!(config)
163+
164+
// Then
165+
expect(result).toEqual(['Using legacy install flow - access scopes are not auto-granted'])
166+
})
167+
168+
test('should return normal scopes message when use_legacy_install_flow is false', async () => {
169+
// Given
170+
const config = {
171+
access_scopes: {
172+
scopes: 'read_products,write_products',
173+
use_legacy_install_flow: false,
174+
},
175+
auth: {
176+
redirect_urls: ['https://example.com/auth/callback'],
177+
},
178+
}
179+
180+
// When
181+
const result = await spec.getDevSessionUpdateMessages!(config)
182+
183+
// Then
184+
expect(result).toEqual(['Access scopes auto-granted: read_products, write_products'])
185+
})
186+
187+
test('should return legacy install flow message when both scopes and required_scopes are nil', async () => {
188+
// Given
189+
const config = {
190+
access_scopes: {},
191+
auth: {
192+
redirect_urls: ['https://example.com/auth/callback'],
193+
},
194+
}
195+
196+
// When
197+
const result = await spec.getDevSessionUpdateMessages!(config)
198+
199+
// Then
200+
expect(result).toEqual(['Using legacy install flow - access scopes are not auto-granted'])
201+
})
202+
203+
test('should handle empty string scopes', async () => {
204+
// Given
205+
const config = {
206+
access_scopes: {
207+
scopes: '',
208+
},
209+
auth: {
210+
redirect_urls: ['https://example.com/auth/callback'],
211+
},
212+
}
213+
214+
// When
215+
const result = await spec.getDevSessionUpdateMessages!(config)
216+
217+
// Then
218+
expect(result).toEqual(['App has been installed'])
219+
})
220+
221+
test('should handle empty array required_scopes', async () => {
222+
// Given
223+
const config = {
224+
access_scopes: {
225+
required_scopes: [],
226+
},
227+
auth: {
228+
redirect_urls: ['https://example.com/auth/callback'],
229+
},
230+
}
231+
232+
// When
233+
const result = await spec.getDevSessionUpdateMessages!(config)
234+
235+
// Then
236+
expect(result).toEqual(['App has been installed'])
237+
})
129238
})
130239
})

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,22 @@ const appAccessSpec = createConfigExtensionSpecification({
4747
schema: AppAccessSchema,
4848
transformConfig: AppAccessTransformConfig,
4949
getDevSessionUpdateMessages: async (config) => {
50+
const hasAccessModule = config.access_scopes !== undefined
51+
const isLegacyInstallFlow = config.access_scopes?.use_legacy_install_flow === true
52+
const hasNoScopes = config.access_scopes?.scopes == null && config.access_scopes?.required_scopes == null
53+
54+
if (isLegacyInstallFlow || (hasAccessModule && hasNoScopes)) {
55+
return [`Using legacy install flow - access scopes are not auto-granted`]
56+
}
57+
5058
const scopesString = config.access_scopes?.scopes
5159
? config.access_scopes.scopes
5260
.split(',')
5361
.map((scope) => scope.trim())
5462
.join(', ')
5563
: config.access_scopes?.required_scopes?.join(', ')
5664

57-
return [scopesString ? `Access scopes auto-granted: ${scopesString}` : `App has been installed`]
65+
return scopesString ? [`Access scopes auto-granted: ${scopesString}`] : [`App has been installed`]
5866
},
5967
patchWithAppDevURLs: (config, urls) => {
6068
if (urls.redirectUrlWhitelist) {

packages/app/src/cli/services/dev/processes/dev-session/dev-session-process.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe('pushUpdatesForDevSession', () => {
186186
test('handles scope changes and displays updated message', async () => {
187187
// Given
188188
vi.mocked(buildAppURLForWeb).mockResolvedValue('https://test.myshopify.com/admin/apps/test')
189-
const appAccess = await testAppAccessConfigExtension()
189+
const appAccess = await testAppAccessConfigExtension(false, undefined, false)
190190
const event = {extensionEvents: [{type: 'updated', extension: appAccess}], app}
191191
const contextSpy = vi.spyOn(outputContext, 'useConcurrentOutputContext')
192192

0 commit comments

Comments
 (0)