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 new option to link for new apps #4808

Merged
merged 3 commits into from
Nov 11, 2024
Merged
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
79 changes: 79 additions & 0 deletions packages/app/src/cli/services/app/config/link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,85 @@ embedded = false
})
})

test('existing config is respected when isNewApp is true, config is current and client_id is not the same as remote app', async () => {
await inTemporaryDirectory(async (tmp) => {
// Given
const developerPlatformClient = buildDeveloperPlatformClient()
const options: LinkOptions = {
directory: tmp,
developerPlatformClient,
isNewApp: true,
configName: 'shopify.app.toml',
}
const localApp = {
configuration: {
path: joinPath(tmp, 'shopify.app.toml'),
name: 'my app',
client_id: 'invalid_client_id_from_template',
webhooks: {
api_version: '2023-04',
subscriptions: [{topics: ['products/create'], uri: 'https://my-app.com/webhooks'}],
},
application_url: 'https://myapp.com',
build: {
automatically_update_urls_on_dev: true,
dev_store_url: 'my-store.myshopify.com',
include_config_on_deploy: true,
},
access_scopes: {
scopes: 'write_products',
},
} as CurrentAppConfiguration,
}

vi.mocked(loadApp).mockResolvedValue(await mockApp(tmp, localApp, [], 'current'))
vi.mocked(fetchOrCreateOrganizationApp).mockResolvedValue(mockRemoteApp({developerPlatformClient}))
const remoteConfiguration = {
...DEFAULT_REMOTE_CONFIGURATION,
handle: 'handle',
}
vi.mocked(fetchAppRemoteConfiguration).mockResolvedValue(remoteConfiguration)

// When
await link(options)

// Then
const content = await readFile(joinPath(tmp, 'shopify.app.toml'))
const expectedContent = `# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration

client_id = "12345"
name = "app1"
handle = "handle"
application_url = "https://example.com"
embedded = true

[build]
automatically_update_urls_on_dev = true
dev_store_url = "my-store.myshopify.com"
include_config_on_deploy = true

[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "write_products"
use_legacy_install_flow = true

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

[webhooks]
api_version = "2023-07"

[[webhooks.subscriptions]]
topics = [ "products/create" ]
uri = "https://my-app.com/webhooks"

[pos]
embedded = false
`
expect(content).toEqual(expectedContent)
})
})

async function mockApp(
directory: string,
app?: Partial<AppInterface>,
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/services/app/config/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface LinkOptions {
configName?: string
baseConfigName?: string
developerPlatformClient?: DeveloperPlatformClient
isNewApp?: boolean
}

interface LinkOutput {
Expand Down Expand Up @@ -280,7 +281,7 @@ async function loadLocalAppOptions(
appDirectory: app.directory,
packageManager: app.packageManager,
}
} else if (app.configuration.client_id === remoteAppApiKey) {
} else if (app.configuration.client_id === remoteAppApiKey || options.isNewApp) {
return {
state: 'reusable-current-app',
configFormat: 'current',
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/cli/services/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ async function init(options: InitOptions) {
organizationId: app.organizationId,
configName: 'shopify.app.toml',
developerPlatformClient: options.developerPlatformClient,
isNewApp: true,
},
false,
)
Expand Down