Skip to content

Commit 262f988

Browse files
Rename PartnersSession to Session and move it to cli-kit
1 parent bf44c96 commit 262f988

File tree

17 files changed

+173
-116
lines changed

17 files changed

+173
-116
lines changed

packages/app/src/cli/api/graphql/current_account_info.ts

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
1-
import {AccountInfo} from '../../services/context/partner-account-info.js'
1+
import {CurrentAccountInfoQuery} from './partners/generated/current-account-info.js'
22
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
3+
import {AccountInfo} from '@shopify/cli-kit/node/session'
34
import {AbortError} from '@shopify/cli-kit/node/error'
4-
import {gql} from 'graphql-request'
55

6-
export const CurrentAccountInfoQuery = gql`
7-
query currentAccountInfo {
8-
currentAccountInfo {
9-
__typename
10-
... on ServiceAccount {
11-
orgName
12-
}
13-
... on UserAccount {
14-
email
15-
}
16-
}
17-
}
18-
`
19-
20-
type AccountInfoSchema =
21-
| {
22-
__typename: 'UserAccount'
23-
email: string
24-
}
25-
| {
26-
__typename: 'ServiceAccount'
27-
orgName: string
28-
}
29-
30-
export interface CurrentAccountInfoSchema {
31-
currentAccountInfo: AccountInfoSchema
32-
}
6+
export type CurrentAccountInfoSchema = CurrentAccountInfoQuery
337

348
export async function getCurrentAccountInfo(developerPlatformClient: DeveloperPlatformClient) {
359
const {currentAccountInfo} = await developerPlatformClient.currentAccountInfo()
@@ -41,7 +15,7 @@ export async function getCurrentAccountInfo(developerPlatformClient: DeveloperPl
4115
return mapAccountInfo(currentAccountInfo)
4216
}
4317

44-
function mapAccountInfo(accountInfo: AccountInfoSchema): AccountInfo {
18+
function mapAccountInfo(accountInfo: CurrentAccountInfoQuery['currentAccountInfo']): AccountInfo {
4519
if (accountInfo.__typename === 'UserAccount') {
4620
return {
4721
type: 'UserAccount',
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* eslint-disable @typescript-eslint/consistent-type-definitions */
2+
import * as Types from './types.js'
3+
4+
import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'
5+
6+
export type CurrentAccountInfoQueryVariables = Types.Exact<{[key: string]: never}>
7+
8+
export type CurrentAccountInfoQuery = {
9+
currentAccountInfo: {__typename: 'ServiceAccount'; orgName: string} | {__typename: 'UserAccount'; email: string}
10+
}
11+
12+
export const CurrentAccountInfo = {
13+
kind: 'Document',
14+
definitions: [
15+
{
16+
kind: 'OperationDefinition',
17+
operation: 'query',
18+
name: {kind: 'Name', value: 'currentAccountInfo'},
19+
selectionSet: {
20+
kind: 'SelectionSet',
21+
selections: [
22+
{
23+
kind: 'Field',
24+
name: {kind: 'Name', value: 'currentAccountInfo'},
25+
selectionSet: {
26+
kind: 'SelectionSet',
27+
selections: [
28+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
29+
{
30+
kind: 'InlineFragment',
31+
typeCondition: {kind: 'NamedType', name: {kind: 'Name', value: 'ServiceAccount'}},
32+
selectionSet: {
33+
kind: 'SelectionSet',
34+
selections: [
35+
{kind: 'Field', name: {kind: 'Name', value: 'orgName'}},
36+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
37+
],
38+
},
39+
},
40+
{
41+
kind: 'InlineFragment',
42+
typeCondition: {kind: 'NamedType', name: {kind: 'Name', value: 'UserAccount'}},
43+
selectionSet: {
44+
kind: 'SelectionSet',
45+
selections: [
46+
{kind: 'Field', name: {kind: 'Name', value: 'email'}},
47+
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
48+
],
49+
},
50+
},
51+
],
52+
},
53+
},
54+
],
55+
},
56+
},
57+
],
58+
} as unknown as DocumentNode<CurrentAccountInfoQuery, CurrentAccountInfoQueryVariables>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
query currentAccountInfo {
2+
currentAccountInfo {
3+
__typename
4+
... on ServiceAccount {
5+
orgName
6+
}
7+
... on UserAccount {
8+
email
9+
}
10+
}
11+
}

packages/app/src/cli/models/app/app.test-data.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {ExtensionInstance} from '../extensions/extension-instance.js'
2424
import {loadLocalExtensionsSpecifications} from '../extensions/load-specifications.js'
2525
import {FunctionConfigType} from '../extensions/specifications/function.js'
2626
import {BaseConfigType} from '../extensions/schemas.js'
27-
import {PartnersSession} from '../../services/context/partner-account-info.js'
2827
import {WebhooksConfig} from '../extensions/specifications/types/app_config_webhook.js'
2928
import {PaymentsAppExtensionConfigType} from '../extensions/specifications/payments_app_extension.js'
3029
import {
@@ -79,6 +78,7 @@ import {AppProxySpecIdentifier} from '../extensions/specifications/app_config_ap
7978
import {ExtensionSpecification} from '../extensions/specification.js'
8079
import {AppLogsOptions} from '../../services/app-logs/utils.js'
8180
import {AppLogsSubscribeMutationVariables} from '../../api/graphql/app-management/generated/app-logs-subscribe.js'
81+
import {Session} from '@shopify/cli-kit/node/session'
8282
import {vi} from 'vitest'
8383
import {joinPath} from '@shopify/cli-kit/node/path'
8484

@@ -1223,7 +1223,7 @@ export const testRemoteExtensionTemplates: ExtensionTemplate[] = [
12231223
themeAppExtensionTemplate,
12241224
]
12251225

1226-
export const testPartnersUserSession: PartnersSession = {
1226+
export const testPartnersUserSession: Session = {
12271227
token: 'token',
12281228
businessPlatformToken: 'businessPlatformToken',
12291229
accountInfo: {
@@ -1520,7 +1520,7 @@ export function testDeveloperPlatformClient(stubs: Partial<DeveloperPlatformClie
15201520
return retVal as DeveloperPlatformClient
15211521
}
15221522

1523-
export const testPartnersServiceSession: PartnersSession = {
1523+
export const testPartnersServiceSession: Session = {
15241524
token: 'partnersToken',
15251525
businessPlatformToken: 'businessPlatformToken',
15261526
accountInfo: {

packages/app/src/cli/models/app/loader.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ wrong = "property"
298298
await writeConfig(appConfiguration)
299299
const pnpmLockPath = joinPath(tmpDir, pnpmLockfile)
300300
await writeFile(pnpmLockPath, '')
301+
vi.mocked(captureOutput).mockResolvedValue(tmpDir)
301302

302303
// When
303304
const app = await loadTestingApp()

packages/app/src/cli/services/context.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import link from './app/config/link.js'
99
import {fetchSpecifications} from './generate/fetch-extension-specifications.js'
1010
import * as patchAppConfigurationFileModule from './app/patch-app-configuration-file.js'
1111
import {DeployOptions} from './deploy.js'
12-
import {isServiceAccount, isUserAccount} from './context/partner-account-info.js'
1312
import {
1413
MinimalAppIdentifiers,
1514
Organization,
@@ -36,6 +35,7 @@ import {
3635
selectDeveloperPlatformClient,
3736
} from '../utilities/developer-platform-client.js'
3837
import {RemoteAwareExtensionSpecification} from '../models/extensions/specification.js'
38+
import {isServiceAccount, isUserAccount} from '@shopify/cli-kit/node/session'
3939
import {afterEach, beforeAll, beforeEach, describe, expect, test, vi} from 'vitest'
4040
import {AbortError} from '@shopify/cli-kit/node/error'
4141
import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output'
@@ -138,6 +138,7 @@ vi.mock('@shopify/cli-kit/node/ui')
138138
vi.mock('./deploy/mode.js')
139139
vi.mock('./app/config/link.js')
140140
vi.mock('./context/partner-account-info.js')
141+
vi.mock('@shopify/cli-kit/node/session')
141142
vi.mock('./generate/fetch-extension-specifications.js')
142143
vi.mock('./app/select-app.js')
143144
vi.mock('../utilities/developer-platform-client.js')

packages/app/src/cli/services/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {createExtension} from './dev/create-extension.js'
55
import {CachedAppInfo} from './local-storage.js'
66
import {setAppConfigValue, unsetAppConfigValue} from './app/patch-app-configuration-file.js'
77
import {DeployOptions} from './deploy.js'
8-
import {isServiceAccount, isUserAccount} from './context/partner-account-info.js'
98
import {formatConfigInfoBody} from './format-config-info-body.js'
109
import {selectOrganizationPrompt} from '../prompts/dev.js'
1110
import {AppInterface, CurrentAppConfiguration, AppLinkedInterface} from '../models/app/app.js'
@@ -26,6 +25,7 @@ import {
2625
DeveloperPlatformClient,
2726
selectDeveloperPlatformClient,
2827
} from '../utilities/developer-platform-client.js'
28+
import {isServiceAccount, isUserAccount} from '@shopify/cli-kit/node/session'
2929
import {tryParseInt} from '@shopify/cli-kit/common/string'
3030
import {Token, renderConfirmationPrompt, renderInfo, renderWarning} from '@shopify/cli-kit/node/ui'
3131
import {AbortError} from '@shopify/cli-kit/node/error'

packages/app/src/cli/services/context/partner-account-info.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {AccountInfo, fetchCurrentAccountInformation} from './partner-account-info.js'
1+
import {fetchCurrentAccountInformation} from './partner-account-info.js'
22
import {testDeveloperPlatformClient} from '../../models/app/app.test-data.js'
33
import {getCurrentAccountInfo} from '../../api/graphql/current_account_info.js'
44
import {clearCachedAccountInfo, getCachedAccountInfo, setCachedAccountInfo} from '../../utilities/app-conf-store.js'
5+
import {AccountInfo} from '@shopify/cli-kit/node/session'
56
import {beforeEach, describe, expect, test, vi} from 'vitest'
67
import {AbortError} from '@shopify/cli-kit/node/error'
78
import {outputDebug} from '@shopify/cli-kit/node/output'

packages/app/src/cli/services/context/partner-account-info.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,7 @@ import {getCurrentAccountInfo} from '../../api/graphql/current_account_info.js'
22
import {getCachedAccountInfo, setCachedAccountInfo} from '../../utilities/app-conf-store.js'
33
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
44
import {outputDebug} from '@shopify/cli-kit/node/output'
5-
6-
export interface PartnersSession {
7-
token: string
8-
businessPlatformToken: string
9-
accountInfo: AccountInfo
10-
userId: string
11-
}
12-
13-
export type AccountInfo = UserAccountInfo | ServiceAccountInfo | UnknownAccountInfo
14-
15-
interface UserAccountInfo {
16-
type: 'UserAccount'
17-
email: string
18-
}
19-
20-
interface ServiceAccountInfo {
21-
type: 'ServiceAccount'
22-
orgName: string
23-
}
24-
25-
interface UnknownAccountInfo {
26-
type: 'UnknownAccount'
27-
}
28-
29-
export function isUserAccount(account: AccountInfo): account is UserAccountInfo {
30-
return account.type === 'UserAccount'
31-
}
32-
33-
export function isServiceAccount(account: AccountInfo): account is ServiceAccountInfo {
34-
return account.type === 'ServiceAccount'
35-
}
5+
import {AccountInfo} from '@shopify/cli-kit/node/session'
366

377
export async function fetchCurrentAccountInformation(
388
developerPlatformClient: DeveloperPlatformClient,

packages/app/src/cli/services/dev/fetch.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import {Organization, OrganizationStore} from '../../models/organization.js'
22
import {FindAppPreviewModeSchema} from '../../api/graphql/find_app_preview_mode.js'
3-
import {
4-
AccountInfo,
5-
fetchCurrentAccountInformation,
6-
isServiceAccount,
7-
isUserAccount,
8-
} from '../context/partner-account-info.js'
3+
import {fetchCurrentAccountInformation} from '../context/partner-account-info.js'
94
import {
105
DeveloperPlatformClient,
116
allDeveloperPlatformClients,
127
selectDeveloperPlatformClient,
138
} from '../../utilities/developer-platform-client.js'
9+
import {AccountInfo, isServiceAccount, isUserAccount} from '@shopify/cli-kit/node/session'
1410
import {AbortError} from '@shopify/cli-kit/node/error'
1511
import {outputContent, outputToken} from '@shopify/cli-kit/node/output'
1612

0 commit comments

Comments
 (0)