Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api_version to access.admin in app.toml #4360

Closed
wants to merge 7 commits into from
2 changes: 1 addition & 1 deletion packages/app/src/cli/models/app/app.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export async function testAppAccessConfigExtension(emptyConfig = false): Promise
? ({} as unknown as BaseConfigType)
: ({
access: {
admin: {direct_api_mode: 'online'},
admin: {direct_api_mode: 'online', api_version: '2024-07'},
},
access_scopes: {
scopes: 'read_products,write_products',
Expand Down
46 changes: 46 additions & 0 deletions packages/app/src/cli/models/app/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,52 @@ wrong = "property"
await expect(loadTestingApp()).rejects.toThrow()
})

test('loads app when access.admin.api_version is 2024-07', async () => {
// Given
const config = `
name = "my_app"
client_id = "1234567890"
application_url = "https://example.com/lala"
embedded = true

[webhooks]
api_version = "2023-07"

[auth]
redirect_urls = [ "https://example.com/api/auth" ]

[access.admin]
api_version = 2024-07
`
await writeConfig(config)

// When
await expect(loadTestingApp()).rejects.toThrow()
})

test('throws an error when access.admin.api_version is invalid', async () => {
// Given
const config = `
name = "my_app"
client_id = "1234567890"
application_url = "https://example.com/lala"
embedded = true

[webhooks]
api_version = "2023-07"

[auth]
redirect_urls = [ "https://example.com/api/auth" ]

[access.admin]
api_version = false
`
await writeConfig(config)

// When
await expect(loadTestingApp()).rejects.toThrow()
})

test('loads the app when access.admin.embedded_app_direct_api_access = true', async () => {
// Given
const config = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('app_config_app_access', () => {
// Given
const object = {
access: {
admin: {direct_api_mode: 'online'},
admin: {direct_api_mode: 'online', api_version: '2024-07'},
},
access_scopes: {
scopes: 'read_products,write_products',
Expand All @@ -28,7 +28,7 @@ describe('app_config_app_access', () => {
// Then
expect(result).toMatchObject({
access: {
admin: {direct_api_mode: 'online'},
admin: {direct_api_mode: 'online', api_version: '2024-07'},
},
scopes: 'read_products,write_products',
optional_scopes: ['read_customers'],
Expand All @@ -44,7 +44,7 @@ describe('app_config_app_access', () => {
// Given
const object = {
access: {
admin: {direct_api_mode: 'offline'},
admin: {direct_api_mode: 'offline', api_version: '2024-07'},
},
scopes: 'read_products,write_products',
optional_scopes: ['read_customers'],
Expand All @@ -60,7 +60,7 @@ describe('app_config_app_access', () => {
// Then
expect(result).toMatchObject({
access: {
admin: {direct_api_mode: 'offline'},
admin: {direct_api_mode: 'offline', api_version: '2024-07'},
},
access_scopes: {
scopes: 'read_products,write_products',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const AppAccessSchema = zod.object({
.object({
direct_api_mode: zod.union([zod.literal('online'), zod.literal('offline')]).optional(),
embedded_app_direct_api_access: zod.boolean().optional(),
api_version: zod.string().optional(),
})
.optional(),
})
Expand Down
9 changes: 9 additions & 0 deletions packages/cli-kit/src/public/node/toml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ describe('decodeToml', () => {
const result = decodeToml(input)
expect(result).toStrictEqual({access: {admin: {direct_api_mode: 'online'}}})
})

test('returns {access: {admin: {api_version}}} when input is [access.admin.api_version] = "2024-07"', () => {
const input = `
[access]
admin = {api_version = "2024-07"}
`
const result = decodeToml(input)
expect(result).toStrictEqual({access: {admin: {api_version: '2024-07'}}})
})
})