Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/app/src/cli/models/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,24 @@ describe('getUIExtensionRendererVersion', () => {
describe('getAppScopes', () => {
test('returns the scopes key when schema is legacy', () => {
const config = {scopes: 'read_themes,read_products'} as AppConfiguration
expect(getAppScopes(config)).toEqual('read_themes,read_products')
expect(getAppScopes(config)).toEqual('read_products,read_themes')
})

test('returns the access_scopes.scopes key when schema is current', () => {
const config = {...DEFAULT_CONFIG, access_scopes: {scopes: 'read_themes,read_themes'}}
expect(getAppScopes(config)).toEqual('read_themes,read_themes')
expect(getAppScopes(config)).toEqual('read_themes')
})
})

describe('getAppScopesArray', () => {
test('returns the scopes key when schema is legacy', () => {
const config = {scopes: 'read_themes, read_order ,write_products'} as AppConfiguration
expect(getAppScopesArray(config)).toEqual(['read_themes', 'read_order', 'write_products'])
expect(getAppScopesArray(config)).toEqual(['read_order', 'read_themes', 'write_products'])
})

test('returns the access_scopes.scopes key when schema is current', () => {
const config = {...DEFAULT_CONFIG, access_scopes: {scopes: 'read_themes, read_order ,write_products'}}
expect(getAppScopesArray(config)).toEqual(['read_themes', 'read_order', 'write_products'])
expect(getAppScopesArray(config)).toEqual(['read_order', 'read_themes', 'write_products'])
})
})

Expand Down
25 changes: 8 additions & 17 deletions packages/app/src/cli/models/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export const LegacyAppSchema = zod
.object({
client_id: zod.number().optional(),
name: zod.string().optional(),
scopes: zod
.string()
.transform((scopes) => normalizeDelimitedString(scopes) ?? '')
.default(''),
scopes: zod.string().default(''),
extension_directories: ExtensionDirectoriesSchema,
web_directories: zod.array(zod.string()).optional(),
webhooks: zod
Expand Down Expand Up @@ -85,13 +82,10 @@ export function normalizeExtensionDirectories(dirs: string[] | undefined): strin
*/
export const TemplateConfigSchema = zod
.object({
scopes: zod
.string()
.transform((scopes) => normalizeDelimitedString(scopes) ?? '')
.optional(),
scopes: zod.string().optional(),
access_scopes: zod
.object({
scopes: zod.string().transform((scopes) => normalizeDelimitedString(scopes) ?? ''),
scopes: zod.string(),
})
.optional(),
web_directories: zod.array(zod.string()).optional(),
Expand All @@ -101,12 +95,9 @@ export const TemplateConfigSchema = zod
export type TemplateConfig = zod.infer<typeof TemplateConfigSchema>

export function getTemplateScopesArray(config: TemplateConfig): string[] {
const scopesString = config.scopes ?? config.access_scopes?.scopes ?? ''
if (scopesString.length === 0) return []
return scopesString
.split(',')
.map((scope) => scope.trim())
.sort()
const scopesString = normalizeDelimitedString(config.scopes ?? config.access_scopes?.scopes)
if (!scopesString || scopesString.length === 0) return []
return scopesString.split(',').map((scope) => scope.trim())
}

/**
Expand Down Expand Up @@ -207,9 +198,9 @@ export function isCurrentAppSchema(item: AppConfiguration): item is CurrentAppCo
*/
export function getAppScopes(config: AppConfiguration): string {
if (isLegacyAppSchema(config)) {
return config.scopes
return normalizeDelimitedString(config.scopes) ?? ''
} else if (isCurrentAppSchema(config)) {
return config.access_scopes?.scopes ?? ''
return normalizeDelimitedString(config.access_scopes?.scopes) ?? ''
}
return ''
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/cli/models/app/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@ describe('getAppConfigurationState', () => {
appDirectory: expect.any(String),
configurationPath: expect.stringMatching(/shopify.app.toml$/),
startingOptions: {
scopes: 'write_abc,write_xyz',
scopes: ' write_xyz, write_abc ',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {validateUrl} from '../../app/validation/common.js'
import {TransformationConfig, createConfigExtensionSpecification} from '../specification.js'
import {BaseSchemaWithoutHandle} from '../schemas.js'
import {normalizeDelimitedString} from '@shopify/cli-kit/common/string'
import {zod} from '@shopify/cli-kit/node/schema'

const AppAccessSchema = BaseSchemaWithoutHandle.extend({
Expand All @@ -17,10 +16,7 @@ const AppAccessSchema = BaseSchemaWithoutHandle.extend({
.optional(),
access_scopes: zod
.object({
scopes: zod
.string()
.transform((scopes) => normalizeDelimitedString(scopes) ?? '')
.optional(),
scopes: zod.string().optional(),
required_scopes: zod.array(zod.string()).optional(),
optional_scopes: zod.array(zod.string()).optional(),
use_legacy_install_flow: zod.boolean().optional(),
Expand Down
Loading