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
26 changes: 22 additions & 4 deletions packages/app/src/cli/commands/app/env/show.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import EnvShow from './show.js'
import {linkedAppContext} from '../../../services/app-context.js'
import {testAppLinked, testOrganizationApp} from '../../../models/app/app.test-data.js'
import {
testAppLinked,
testOrganizationApp,
testOrganizationAppWithoutClientSecret,
} from '../../../models/app/app.test-data.js'
import {OrganizationSource} from '../../../models/organization.js'
import {appEnvShowJsonOutputSchema} from '../../../services/app/env/show/types.js'
import {Config} from '@oclif/core'
Expand All @@ -15,7 +19,7 @@ vi.mock('../../../services/context.js')
function mockLinkedAppContext({secret, scopes}: {secret: string | undefined; scopes: string}) {
const app = testAppLinked()
app.configuration.access_scopes = {scopes}
const remoteApp = testOrganizationApp({apiSecretKeys: secret === undefined ? [] : [{secret}]})
const remoteApp = secret ? testOrganizationApp({apiSecretKeys: [{secret}]}) : testOrganizationAppWithoutClientSecret()
vi.mocked(linkedAppContext).mockImplementation(async () => {
outputInfo('Loaded app')
return {
Expand All @@ -41,15 +45,28 @@ test.each([
{
variables: [
{name: 'SHOPIFY_API_KEY', value: remoteApp.apiKey, isSecret: false},
...(secret === undefined ? [] : [{name: 'SHOPIFY_API_SECRET', value: secret, isSecret: true}]),
secret
? {name: 'SHOPIFY_API_SECRET', value: secret, isSecret: true}
: {name: 'SHOPIFY_API_SECRET', isSecret: true},
{name: 'SCOPES', value: scopes, isSecret: false},
],
},
null,
2,
)}\n`,
)
expect(JSON.parse(stderr())).toMatchObject({type: 'diagnostic', message: 'Loaded app'})
const diagnostics = stderr()
.trim()
.split('\n')
.map((line) => JSON.parse(line))
expect(diagnostics[0]).toMatchObject({type: 'diagnostic', message: 'Loaded app'})
if (!secret) {
expect(diagnostics[1]).toMatchObject({
type: 'diagnostic',
level: 'warning',
message: expect.stringContaining("SHOPIFY_API_SECRET isn't included"),
})
}
expect(linkedAppContext).toHaveBeenCalledWith({
directory: expect.any(String),
clientId: undefined,
Expand All @@ -68,6 +85,7 @@ test('keeps the environment text on stdout, with an empty missing secret', async
'\n SHOPIFY_API_KEY=api-key\n SHOPIFY_API_SECRET=\n SCOPES=read_products\n \n',
)
expect(stderr()).toContain('Loaded app')
expect(stderr()).toContain("SHOPIFY_API_SECRET isn't included")
})
})

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
Loading
Loading