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
6 changes: 6 additions & 0 deletions .changeset/app-client-secret-on-demand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/app': patch
'@shopify/cli': patch
---

Improve error messages and guidance for app commands.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ActiveAppReleaseFromApiKeyQuery = {
id: string
key: string
organizationId: string
activeRoot: {grantedShopifyApprovalScopes: string[]; clientCredentials: {secrets: {key: string}[]}}
activeRoot: {grantedShopifyApprovalScopes: string[]}
activeRelease: {
id: string
version: {
Expand Down Expand Up @@ -120,26 +120,7 @@ export const ActiveAppReleaseFromApiKey = {
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: 'grantedShopifyApprovalScopes'}},
],
selections: [{kind: 'Field', name: {kind: 'Name', value: 'grantedShopifyApprovalScopes'}}],
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ActiveAppReleaseQuery = {
id: string
key: string
organizationId: string
activeRoot: {grantedShopifyApprovalScopes: string[]; clientCredentials: {secrets: {key: string}[]}}
activeRoot: {grantedShopifyApprovalScopes: string[]}
activeRelease: {
id: string
version: {
Expand Down Expand Up @@ -41,7 +41,7 @@ export type AppVersionInfoFragment = {
id: string
key: string
organizationId: string
activeRoot: {grantedShopifyApprovalScopes: string[]; clientCredentials: {secrets: {key: string}[]}}
activeRoot: {grantedShopifyApprovalScopes: string[]}
activeRelease: {
id: string
version: {
Expand Down Expand Up @@ -131,26 +131,7 @@ export const AppVersionInfoFragmentDoc = {
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: 'grantedShopifyApprovalScopes'}},
],
selections: [{kind: 'Field', name: {kind: 'Name', value: 'grantedShopifyApprovalScopes'}}],
},
},
{
Expand Down Expand Up @@ -297,26 +278,7 @@ export const ActiveAppRelease = {
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: 'grantedShopifyApprovalScopes'}},
],
selections: [{kind: 'Field', name: {kind: 'Name', value: 'grantedShopifyApprovalScopes'}}],
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import * as Types from './types.js'

import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'

export type AppClientCredentialsQueryVariables = Types.Exact<{
apiKey: Types.Scalars['String']['input']
}>

export type AppClientCredentialsQuery = {
app: {id: string; activeRoot: {clientCredentials: {secrets: {key: string}[]}}}
}

export const AppClientCredentials = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: {kind: 'Name', value: 'AppClientCredentials'},
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'apiKey'}},
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
alias: {kind: 'Name', value: 'app'},
name: {kind: 'Name', value: 'appByKey'},
arguments: [
{
kind: 'Argument',
name: {kind: 'Name', value: 'key'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'apiKey'}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'id'}},
{
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'}},
],
},
},
],
},
},
],
} as unknown as DocumentNode<AppClientCredentialsQuery, AppClientCredentialsQueryVariables>
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; activeRoot: {clientCredentials: {secrets: {key: string}[]}}} | null
app?: {id: string; key: string} | null
userErrors: {category: string; message: string; on: JsonMapType}[]
}
}
Expand Down Expand Up @@ -64,37 +64,6 @@ 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 @@ -9,11 +9,6 @@ fragment AppVersionInfo on App {
key
organizationId
activeRoot {
clientCredentials {
secrets {
key
}
}
grantedShopifyApprovalScopes
}
activeRelease {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
query AppClientCredentials($apiKey: String!) {
app: appByKey(key: $apiKey) {
id
activeRoot {
clientCredentials {
secrets {
key
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ mutation CreateApp($initialVersion: AppVersionInput!, $organizationId: ID!) {
app {
id
key
activeRoot {
clientCredentials {
secrets {
key
}
}
}
}
userErrors {
category
Expand Down
15 changes: 11 additions & 4 deletions packages/app/src/cli/commands/app/info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AppInfo from './info.js'
import {
testAppLinked,
testOrganizationApp,
testOrganizationAppWithoutClientSecret,
testProject,
testDeveloperPlatformClient,
} from '../../models/app/app.test-data.js'
Expand Down Expand Up @@ -95,26 +96,32 @@ test('keeps app information on stderr in text mode', async () => {
test.each([{secret: 'api-secret'}, {secret: undefined}])(
'preserves web environment JSON: $secret',
async ({secret}) => {
const remoteApp = testOrganizationApp({apiSecretKeys: secret === undefined ? [] : [{secret}]})
const remoteApp = secret
? testOrganizationApp({apiSecretKeys: [{secret}]})
: testOrganizationAppWithoutClientSecret()
await withCapturedStandardStreams(async ({stdout, stderr}) => {
await runCommand(['--web-env', '--json'], testAppLinked(), remoteApp)
expect(stdout()).toBe(
secret === undefined
? '{\n "SHOPIFY_API_KEY": "api-key",\n "SCOPES": "read_products"\n}\n'
: '{\n "SHOPIFY_API_KEY": "api-key",\n "SHOPIFY_API_SECRET": "api-secret",\n "SCOPES": "read_products"\n}\n',
)
expect(stderr()).toBe('')
if (secret === undefined) {
expect(stderr()).toContain("SHOPIFY_API_SECRET isn't included")
} else {
expect(stderr()).toBe('')
}
})
},
)

test('keeps web environment text on stdout, with an empty missing secret', async () => {
await withCapturedStandardStreams(async ({stdout, stderr}) => {
await runCommand(['--web-env'], testAppLinked(), testOrganizationApp({apiSecretKeys: []}))
await runCommand(['--web-env'], testAppLinked(), testOrganizationAppWithoutClientSecret())
expect(unstyled(stdout())).toBe(
'\n SHOPIFY_API_KEY=api-key\n SHOPIFY_API_SECRET=\n SCOPES=read_products\n \n',
)
expect(stderr()).toBe('')
expect(stderr()).toContain("SHOPIFY_API_SECRET isn't included")
})
})

Expand Down
15 changes: 14 additions & 1 deletion packages/app/src/cli/models/app/app.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ export function testOrganizationApp(app: Partial<OrganizationApp> = {}): Organiz
id: '1',
title: 'app1',
apiKey: 'api-key',
apiSecretKeys: [{secret: 'api-secret'}],
// As in production: app lookups leave the secret out, and commands fetch it with appClientSecrets.
apiSecretKeys: [],
organizationId: '1',
grantedScopes: [],
disabledFlags: ['5b25141b'],
Expand All @@ -206,6 +207,17 @@ export function testOrganizationApp(app: Partial<OrganizationApp> = {}): Organiz
return {...defaultApp, ...app}
}

/**
* An app whose client secret the App Management API doesn't return, as for credentials that can't read it.
*/
export function testOrganizationAppWithoutClientSecret(app: Partial<OrganizationApp> = {}): OrganizationApp {
return testOrganizationApp({
apiSecretKeys: [],
developerPlatformClient: testDeveloperPlatformClient({appClientSecrets: () => Promise.resolve([])}),
...app,
})
}

export const placeholderAppConfiguration: AppConfiguration = {
client_id: '',
}
Expand Down Expand Up @@ -1340,6 +1352,7 @@ export function testDeveloperPlatformClient(
unsafeRefreshToken: () => Promise.resolve(testPartnersUserSession.token),
accountInfo: () => Promise.resolve(testPartnersUserSession.accountInfo),
appFromIdentifiers: (_apiKey: string) => Promise.resolve(testOrganizationApp()),
appClientSecrets: (_app: Pick<MinimalAppIdentifiers, 'apiKey'>) => Promise.resolve([{secret: 'api-secret'}]),
organizations: () => Promise.resolve(organizationsResponse),
orgFromId: (_organizationId: string) => Promise.resolve(testOrganization()),
appsForOrg: (_organizationId: string) => Promise.resolve({apps: [testOrganizationApp()], hasMorePages: false}),
Expand Down
Loading
Loading