Skip to content

Commit

Permalink
Merge pull request #4749 from Shopify/fix-redirect-urls-updates-in-to…
Browse files Browse the repository at this point in the history
…ml-stable

[stable] Fix redirect_urls updates in app toml
  • Loading branch information
isaacroldan authored Oct 25, 2024
2 parents e7323f7 + 90bfd9b commit 1ed573c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-ads-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Fix redirect_urls being appended instead of replaced during app dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {describe, expect, test} from 'vitest'
const defaultToml = `# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration
client_id = "12345"
name = "app1"
application_url = "https://example.com"
embedded = true
[access_scopes]
Expand Down Expand Up @@ -42,6 +43,9 @@ describe('patchAppConfigurationFile', () => {
access_scopes: {
use_legacy_install_flow: false,
},
auth: {
redirect_urls: ['https://example.com/redirect3', 'https://example.com/redirect4'],
},
}

await patchAppConfigurationFile({path: configPath, patch, schema})
Expand All @@ -61,8 +65,8 @@ use_legacy_install_flow = false
[auth]
redirect_urls = [
"https://example.com/redirect",
"https://example.com/redirect2"
"https://example.com/redirect3",
"https://example.com/redirect4"
]
[webhooks]
Expand Down Expand Up @@ -92,9 +96,6 @@ name = "app1"
application_url = "https://example.com"
embedded = true
[build]
dev_store_url = "example.myshopify.com"
[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
use_legacy_install_flow = true
Expand All @@ -107,6 +108,9 @@ redirect_urls = [
[webhooks]
api_version = "2023-04"
[build]
dev_store_url = "example.myshopify.com"
`)
})
})
Expand Down Expand Up @@ -134,8 +138,8 @@ embedded = true
[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "read_products"
use_legacy_install_flow = true
scopes = "read_products"
[auth]
redirect_urls = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ export interface PatchTomlOptions {
export async function patchAppConfigurationFile({path, patch, schema}: PatchTomlOptions) {
const tomlContents = await readFile(path)
const configuration = decodeToml(tomlContents)
const updatedConfig = deepMergeObjects(configuration, patch)
const updatedConfig = deepMergeObjects(configuration, patch, replaceArrayStrategy)

// Re-parse the config with the schema to validate the patch and keep the same order in the file
// Make every field optional to not crash on invalid tomls that are missing fields.
const validSchema = schema ?? zod.object({}).passthrough()
const validatedConfig = validSchema.partial().parse(updatedConfig)
let encodedString = encodeToml(validatedConfig)
validSchema.partial().parse(updatedConfig)

let encodedString = encodeToml(updatedConfig)
encodedString = addDefaultCommentsToToml(encodedString)
await writeFile(path, encodedString)
}

function replaceArrayStrategy(_: unknown[], sourceArray: unknown[]): unknown[] {
return sourceArray
}

0 comments on commit 1ed573c

Please sign in to comment.