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

Fix dev when resetting and creating a new app #5213

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type CreateAppMutationVariables = Types.Exact<{

export type CreateAppMutation = {
appCreate: {
app?: {id: string; key: string} | null
app?: {id: string; key: string; activeRoot: {clientCredentials: {secrets: {key: string}[]}}} | null
userErrors: {category: string; message: string; on: JsonMapType}[]
}
}
Expand Down Expand Up @@ -64,6 +64,37 @@ export const CreateApp = {
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'id'}},
{kind: 'Field', name: {kind: 'Name', value: 'key'}},
{
kind: 'Field',
name: {kind: 'Name', value: 'activeRoot'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'clientCredentials'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'secrets'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'key'}},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ mutation CreateApp($appSource: AppSourceInput!, $name: String!) {
app {
id
key
activeRoot {
clientCredentials {
secrets {
key
}
}
}
}
userErrors {
category
Expand Down
9 changes: 3 additions & 6 deletions packages/app/src/cli/services/app/config/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
let developerPlatformClient = await sniffServiceOptionsAndAppConfigToSelectPlatformClient(options)

const {creationOptions, appDirectory: possibleAppDirectory} = await getAppCreationDefaultsFromLocalApp(options)
const appDirectory = possibleAppDirectory || options.directory
const appDirectory = possibleAppDirectory ?? options.directory

if (options.apiKey) {
// Remote API Key provided by the caller, so use that app specifically
Expand Down Expand Up @@ -189,12 +189,9 @@
userProvidedConfigName: options.baseConfigName,
remoteFlags: undefined,
})
const configuration = app.configuration

if (!isCurrentAppSchema(configuration)) {
return {creationOptions: app.creationDefaultOptions(), appDirectory: app.directory}
}
return {creationOptions: appCreationDefaults}
return {creationOptions: app.creationDefaultOptions(), appDirectory: app.directory}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unclear how fixes the issue with missing apiSecretKey on shopify app dev --reset. Is this saying we always create a new app with the default options? Why was the !isCurrentAppSchema(configuration) check removed?


// eslint-disable-next-line no-catch-all/no-catch-all
} catch (error) {
return {creationOptions: appCreationDefaults}
Expand Down Expand Up @@ -348,7 +345,7 @@
const currentToml = existingTomls[remoteApp.apiKey]
if (currentToml) return currentToml

return selectConfigName(localAppInfo.appDirectory || options.directory, remoteApp.title)

Check warning on line 348 in packages/app/src/cli/services/app/config/link.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/app/config/link.ts#L348

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
}

/**
Expand Down Expand Up @@ -484,8 +481,8 @@

function addRemoteAppHomeConfig(remoteApp: OrganizationApp) {
const homeConfig = {
application_url: remoteApp.applicationUrl?.replace(/\/$/, '') || '',

Check warning on line 484 in packages/app/src/cli/services/app/config/link.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/app/config/link.ts#L484

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
embedded: remoteApp.embedded === undefined ? true : remoteApp.embedded,

Check warning on line 485 in packages/app/src/cli/services/app/config/link.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/app/config/link.ts#L485

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a ternary expression, as it is simpler to read.
}
return remoteApp.preferencesUrl
? {
Expand All @@ -511,8 +508,8 @@

function addRemoteAppWebhooksConfig(remoteApp: OrganizationApp) {
const hasAnyPrivacyWebhook =
remoteApp.gdprWebhooks?.customerDataRequestUrl ||

Check warning on line 511 in packages/app/src/cli/services/app/config/link.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/app/config/link.ts#L511

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
remoteApp.gdprWebhooks?.customerDeletionUrl ||

Check warning on line 512 in packages/app/src/cli/services/app/config/link.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/app/config/link.ts#L512

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
remoteApp.gdprWebhooks?.shopDeletionUrl

const privacyComplianceContent = {
Expand All @@ -525,7 +522,7 @@

return {
webhooks: {
api_version: remoteApp.webhookApiVersion || '2023-07',

Check warning on line 525 in packages/app/src/cli/services/app/config/link.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/app/config/link.ts#L525

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
...(hasAnyPrivacyWebhook ? privacyComplianceContent : {}),
},
}
Expand Down Expand Up @@ -561,7 +558,7 @@
function addPosConfig(remoteApp: OrganizationApp) {
return {
pos: {
embedded: remoteApp.posEmbedded || false,

Check warning on line 561 in packages/app/src/cli/services/app/config/link.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/app/config/link.ts#L561

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ describe('createApp', () => {
publicApiVersions: [{handle: '2024-07'}, {handle: '2024-10'}, {handle: '2025-01'}, {handle: 'unstable'}],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test that ensures we dont run into missing ApiKeySecret error on --reset?

}
vi.mocked(webhooksRequest).mockResolvedValueOnce(mockedApiVersionResult)
vi.mocked(appManagementRequestDoc).mockResolvedValueOnce({appCreate: {app: {id: '1', key: 'key'}, userErrors: []}})
vi.mocked(appManagementRequestDoc).mockResolvedValueOnce({
appCreate: {
app: {id: '1', key: 'key', activeRoot: {clientCredentials: {secrets: [{key: 'secret'}]}}},
userErrors: [],
},
})

// When
client.token = () => Promise.resolve('token')
Expand Down Expand Up @@ -347,7 +352,7 @@ describe('createApp', () => {
id: '1',
key: 'api-key',
apiKey: 'api-key',
apiSecretKeys: [],
apiSecretKeys: [{secret: 'secret'}],
flags: [],
grantedScopes: [],
organizationId: '1',
Expand All @@ -364,6 +369,11 @@ describe('createApp', () => {
app: {
id: expectedApp.id,
key: expectedApp.key,
activeRoot: {
clientCredentials: {
secrets: [{key: 'secret'}],
},
},
},
userErrors: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,12 @@
// Need to figure this out still
const flags = filterDisabledFlags([])
const createdApp = result.appCreate.app
const apiSecretKeys = createdApp.activeRoot.clientCredentials.secrets.map((secret) => ({secret: secret.key}))
return {
...createdApp,
title: name,
apiKey: createdApp.key,
apiSecretKeys: [],
apiSecretKeys,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ever return an empty array? If it does, will we run into the same issue again?

grantedScopes: options?.scopesArray ?? [],
organizationId: org.id,
newApp: true,
Expand Down Expand Up @@ -430,7 +431,7 @@
appIdentifiers: MinimalAppIdentifiers,
activeAppVersion?: AppVersion,
): Promise<AllAppExtensionRegistrationsQuerySchema> {
const app = activeAppVersion || (await this.activeAppVersion(appIdentifiers))

Check warning on line 434 in packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts#L434

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.

const configurationRegistrations: ExtensionRegistration[] = []
const extensionRegistrations: ExtensionRegistration[] = []
Expand Down
Loading