Skip to content

Commit

Permalink
Merge pull request #3921 from Shopify/rename-to-app-management-client
Browse files Browse the repository at this point in the history
Rename Shopify Developers references to App Management
  • Loading branch information
gonzaloriestra committed May 22, 2024
2 parents 87c6de2 + 3be473c commit 95945c4
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 89 deletions.
26 changes: 13 additions & 13 deletions packages/app/src/cli/services/dev/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../models/app/app.test-data.js'
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {PartnersClient} from '../../utilities/developer-platform-client/partners-client.js'
import {ShopifyDevelopersClient} from '../../utilities/developer-platform-client/shopify-developers-client.js'
import {AppManagementClient} from '../../utilities/developer-platform-client/app-management-client.js'
import {afterEach, describe, expect, test, vi} from 'vitest'
import {renderFatalError} from '@shopify/cli-kit/node/ui'
import {partnersRequest} from '@shopify/cli-kit/node/api/partners'
Expand Down Expand Up @@ -69,53 +69,53 @@ const FETCH_STORE_RESPONSE_VALUE: FindStoreByDomainSchema = {

vi.mock('@shopify/cli-kit/node/api/partners')
vi.mock('../../utilities/developer-platform-client/partners-client.js')
vi.mock('../../utilities/developer-platform-client/shopify-developers-client.js')
vi.mock('../../utilities/developer-platform-client/app-management-client.js')

afterEach(() => {
mockAndCaptureOutput().clear()
vi.unstubAllEnvs()
})

describe('fetchOrganizations', async () => {
test('returns fetched organizations from Partners without USE_SHOPIFY_DEVELOPERS_CLIENT', async () => {
test('returns fetched organizations from Partners without USE_APP_MANAGEMENT_API', async () => {
// Given
const partnersClient: PartnersClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG1]),
}) as PartnersClient
const shopifyDevelopersClient: ShopifyDevelopersClient = testDeveloperPlatformClient({
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG2]),
}) as ShopifyDevelopersClient
}) as AppManagementClient
vi.mocked(PartnersClient).mockReturnValue(partnersClient)
vi.mocked(ShopifyDevelopersClient).mockReturnValue(shopifyDevelopersClient)
vi.mocked(AppManagementClient).mockReturnValue(appManagementClient)

// When
const got = await fetchOrganizations()

// Then
expect(got).toEqual([ORG1])
expect(partnersClient.organizations).toHaveBeenCalled()
expect(shopifyDevelopersClient.organizations).not.toHaveBeenCalled()
expect(appManagementClient.organizations).not.toHaveBeenCalled()
})

test('returns fetched organizations from Partners and Shopify Developers with USE_SHOPIFY_DEVELOPERS_CLIENT', async () => {
test('returns fetched organizations from Partners and App Management with USE_APP_MANAGEMENT_API', async () => {
// Given
vi.stubEnv('USE_SHOPIFY_DEVELOPERS_CLIENT', '1')
vi.stubEnv('USE_APP_MANAGEMENT_API', '1')
const partnersClient: PartnersClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG1]),
}) as PartnersClient
const shopifyDevelopersClient: ShopifyDevelopersClient = testDeveloperPlatformClient({
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG2]),
}) as ShopifyDevelopersClient
}) as AppManagementClient
vi.mocked(PartnersClient).mockReturnValue(partnersClient)
vi.mocked(ShopifyDevelopersClient).mockReturnValue(shopifyDevelopersClient)
vi.mocked(AppManagementClient).mockReturnValue(appManagementClient)

// When
const got = await fetchOrganizations()

// Then
expect(got).toEqual([ORG1, ORG2])
expect(partnersClient.organizations).toHaveBeenCalled()
expect(shopifyDevelopersClient.organizations).toHaveBeenCalled()
expect(appManagementClient.organizations).toHaveBeenCalled()
})

test('throws if there are no organizations', async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/cli/utilities/developer-platform-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PartnersClient} from './developer-platform-client/partners-client.js'
import {ShopifyDevelopersClient} from './developer-platform-client/shopify-developers-client.js'
import {AppManagementClient} from './developer-platform-client/app-management-client.js'
import {PartnersSession} from '../../cli/services/context/partner-account-info.js'
import {
MinimalAppIdentifiers,
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface AppVersionIdentifiers {

export function allDeveloperPlatformClients(): DeveloperPlatformClient[] {
const clients: DeveloperPlatformClient[] = [new PartnersClient()]
if (isTruthy(process.env.USE_SHOPIFY_DEVELOPERS_CLIENT)) clients.push(new ShopifyDevelopersClient())
if (isTruthy(process.env.USE_APP_MANAGEMENT_API)) clients.push(new AppManagementClient())
return clients
}

Expand Down Expand Up @@ -104,21 +104,21 @@ export function selectDeveloperPlatformClient({
configuration,
organization,
}: SelectDeveloperPlatformClientOptions = {}): DeveloperPlatformClient {
if (isTruthy(process.env.USE_SHOPIFY_DEVELOPERS_CLIENT)) {
if (isTruthy(process.env.USE_APP_MANAGEMENT_API)) {
if (organization) return selectDeveloperPlatformClientByOrg(organization)
return selectDeveloperPlatformClientByConfig(configuration)
}
return new PartnersClient()
}

function selectDeveloperPlatformClientByOrg(organization: Organization): DeveloperPlatformClient {
if (organization.source === OrganizationSource.BusinessPlatform) return new ShopifyDevelopersClient()
if (organization.source === OrganizationSource.BusinessPlatform) return new AppManagementClient()
return new PartnersClient()
}

function selectDeveloperPlatformClientByConfig(configuration: AppConfiguration | undefined): DeveloperPlatformClient {
if (!configuration || (isCurrentAppSchema(configuration) && configuration.organization_id))
return new ShopifyDevelopersClient()
return new AppManagementClient()
return new PartnersClient()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {diffAppModules} from './shopify-developers-client.js'
import {AppModule} from './shopify-developers-client/graphql/app-version-by-id.js'
import {diffAppModules} from './app-management-client.js'
import {AppModule} from './app-management-client/graphql/app-version-by-id.js'
import {testUIExtension} from '../../models/app/app.test-data.js'
import {ExtensionInstance} from '../../models/extensions/extension-instance.js'
import {describe, expect, test} from 'vitest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,51 @@ import {
CreateAppMutation,
CreateAppMutationVariables,
CreateAppMutationSchema,
} from './shopify-developers-client/graphql/create-app.js'
} from './app-management-client/graphql/create-app.js'
import {
ActiveAppReleaseQuery,
ActiveAppReleaseQueryVariables,
ActiveAppReleaseQuerySchema,
} from './shopify-developers-client/graphql/active-app-release.js'
} from './app-management-client/graphql/active-app-release.js'
import {
SpecificationsQuery,
SpecificationsQueryVariables,
SpecificationsQuerySchema,
} from './shopify-developers-client/graphql/specifications.js'
} from './app-management-client/graphql/specifications.js'
import {
AppVersionsQuery,
AppVersionsQueryVariables,
AppVersionsQuerySchema,
} from './shopify-developers-client/graphql/app-versions.js'
} from './app-management-client/graphql/app-versions.js'
import {
CreateAppVersionMutation,
CreateAppVersionMutationSchema,
CreateAppVersionMutationVariables,
} from './shopify-developers-client/graphql/create-app-version.js'
} from './app-management-client/graphql/create-app-version.js'
import {
ReleaseVersionMutation,
ReleaseVersionMutationSchema,
ReleaseVersionMutationVariables,
} from './shopify-developers-client/graphql/release-version.js'
import {OrganizationsQuery, OrganizationsQuerySchema} from './shopify-developers-client/graphql/organizations.js'
import {AppsQuery, AppsQuerySchema, MinimalAppModule} from './shopify-developers-client/graphql/apps.js'
} from './app-management-client/graphql/release-version.js'
import {OrganizationsQuery, OrganizationsQuerySchema} from './app-management-client/graphql/organizations.js'
import {AppsQuery, AppsQuerySchema, MinimalAppModule} from './app-management-client/graphql/apps.js'
import {
OrganizationQuery,
OrganizationQuerySchema,
OrganizationQueryVariables,
} from './shopify-developers-client/graphql/organization.js'
import {UserInfoQuery, UserInfoQuerySchema} from './shopify-developers-client/graphql/user-info.js'
} from './app-management-client/graphql/organization.js'
import {UserInfoQuery, UserInfoQuerySchema} from './app-management-client/graphql/user-info.js'
import {
CreateAssetURLMutation,
CreateAssetURLMutationSchema,
CreateAssetURLMutationVariables,
} from './shopify-developers-client/graphql/create-asset-url.js'
} from './app-management-client/graphql/create-asset-url.js'
import {
AppVersionByIdQuery,
AppVersionByIdQuerySchema,
AppVersionByIdQueryVariables,
AppModule as AppModuleReturnType,
} from './shopify-developers-client/graphql/app-version-by-id.js'
} from './app-management-client/graphql/app-version-by-id.js'
import {RemoteSpecification} from '../../api/graphql/extension_specifications.js'
import {
DeveloperPlatformClient,
Expand All @@ -56,7 +56,7 @@ import {
AssetUrlSchema,
AppVersionIdentifiers,
} from '../developer-platform-client.js'
import {PartnersSession} from '../../../cli/services/context/partner-account-info.js'
import {PartnersSession} from '../../services/context/partner-account-info.js'
import {
MinimalAppIdentifiers,
MinimalOrganizationApp,
Expand All @@ -65,7 +65,7 @@ import {
OrganizationSource,
OrganizationStore,
} from '../../models/organization.js'
import {filterDisabledFlags} from '../../../cli/services/dev/fetch.js'
import {filterDisabledFlags} from '../../services/dev/fetch.js'
import {
AllAppExtensionRegistrationsQuerySchema,
ExtensionRegistration,
Expand Down Expand Up @@ -108,11 +108,11 @@ import {ensureAuthenticatedAppManagement, ensureAuthenticatedBusinessPlatform} f
import {FunctionUploadUrlGenerateResponse} from '@shopify/cli-kit/node/api/partners'
import {isUnitTest} from '@shopify/cli-kit/node/context/local'
import {AbortError, BugError} from '@shopify/cli-kit/node/error'
import {orgScopedShopifyDevelopersRequest} from '@shopify/cli-kit/node/api/shopify-developers'
import {appManagementRequest} from '@shopify/cli-kit/node/api/app-management'
import {businessPlatformRequest} from '@shopify/cli-kit/node/api/business-platform'
import {shopifyDevelopersFqdn} from '@shopify/cli-kit/node/context/fqdn'
import {appManagementFqdn} from '@shopify/cli-kit/node/context/fqdn'

export class ShopifyDevelopersClient implements DeveloperPlatformClient {
export class AppManagementClient implements DeveloperPlatformClient {
public requiresOrganization = true
public supportsAtomicDeployments = true
private _session: PartnersSession | undefined
Expand All @@ -125,7 +125,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
async session(): Promise<PartnersSession> {
if (!this._session) {
if (isUnitTest()) {
throw new Error('ShopifyDevelopersClient.session() should not be invoked dynamically in a unit test')
throw new Error('AppManagementClient.session() should not be invoked dynamically in a unit test')
}
const userInfoResult = await businessPlatformRequest<UserInfoQuerySchema>(
UserInfoQuery,
Expand Down Expand Up @@ -162,9 +162,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {

async businessPlatformToken(): Promise<string> {
if (isUnitTest()) {
throw new Error(
'ShopifyDevelopersClient.businessPlatformToken() should not be invoked dynamically in a unit test',
)
throw new Error('AppManagementClient.businessPlatformToken() should not be invoked dynamically in a unit test')
}
if (!this._businessPlatformToken) {
this._businessPlatformToken = await ensureAuthenticatedBusinessPlatform()
Expand Down Expand Up @@ -237,7 +235,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {

async appsForOrg(organizationId: string, _term?: string): Promise<Paginateable<{apps: MinimalOrganizationApp[]}>> {
const query = AppsQuery
const result = await orgScopedShopifyDevelopersRequest<AppsQuerySchema>(organizationId, query, await this.token())
const result = await appManagementRequest<AppsQuerySchema>(organizationId, query, await this.token())
const minimalOrganizationApps = result.apps.map((app) => {
const brandingConfig = app.activeRelease.version.modules.find(
(mod: MinimalAppModule) => mod.specification.externalIdentifier === 'branding',
Expand All @@ -258,7 +256,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
async specifications({id: appId, organizationId}: MinimalAppIdentifiers): Promise<RemoteSpecification[]> {
const query = SpecificationsQuery
const variables: SpecificationsQueryVariables = {appId}
const result = await orgScopedShopifyDevelopersRequest<SpecificationsQuerySchema>(
const result = await appManagementRequest<SpecificationsQuerySchema>(
organizationId,
query,
await this.token(),
Expand Down Expand Up @@ -298,12 +296,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
const variables = createAppVars(name, options?.isLaunchable, options?.scopesArray)

const mutation = CreateAppMutation
const result = await orgScopedShopifyDevelopersRequest<CreateAppMutationSchema>(
org.id,
mutation,
await this.token(),
variables,
)
const result = await appManagementRequest<CreateAppMutationSchema>(org.id, mutation, await this.token(), variables)
if (result.appCreate.userErrors?.length > 0) {
const errors = result.appCreate.userErrors.map((error) => error.message).join(', ')
throw new AbortError(errors)
Expand Down Expand Up @@ -358,7 +351,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
async appVersions({id, organizationId, title}: OrganizationApp): Promise<AppVersionsQuerySchemaInterface> {
const query = AppVersionsQuery
const variables: AppVersionsQueryVariables = {appId: id}
const result = await orgScopedShopifyDevelopersRequest<AppVersionsQuerySchema>(
const result = await appManagementRequest<AppVersionsQuerySchema>(
organizationId,
query,
await this.token(),
Expand Down Expand Up @@ -395,7 +388,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
): Promise<AppVersionByTagSchemaInterface> {
const query = AppVersionsQuery
const variables: AppVersionsQueryVariables = {appId}
const result = await orgScopedShopifyDevelopersRequest<AppVersionsQuerySchema>(
const result = await appManagementRequest<AppVersionsQuerySchema>(
organizationId,
query,
await this.token(),
Expand All @@ -411,7 +404,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {

const query2 = AppVersionByIdQuery
const variables2: AppVersionByIdQueryVariables = {appId, versionId: version.id}
const result2 = await orgScopedShopifyDevelopersRequest<AppVersionByIdQuerySchema>(
const result2 = await appManagementRequest<AppVersionByIdQuerySchema>(
organizationId,
query2,
await this.token(),
Expand Down Expand Up @@ -455,7 +448,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
const variables: AppVersionByIdQueryVariables = {appId: app.id, versionId}
const [currentVersion, selectedVersion] = await Promise.all([
this.activeAppVersionRawResult(app),
orgScopedShopifyDevelopersRequest<AppVersionByIdQuerySchema>(
appManagementRequest<AppVersionByIdQuerySchema>(
app.organizationId,
AppVersionByIdQuery,
await this.token(),
Expand Down Expand Up @@ -520,7 +513,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {

async generateSignedUploadUrl({organizationId, apiKey}: MinimalAppIdentifiers): Promise<AssetUrlSchema> {
const variables: CreateAssetURLMutationVariables = {appId: apiKey}
const result = await orgScopedShopifyDevelopersRequest<CreateAssetURLMutationSchema>(
const result = await appManagementRequest<CreateAssetURLMutationSchema>(
organizationId,
CreateAssetURLMutation,
await this.token(),
Expand Down Expand Up @@ -554,7 +547,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
assetsUrl: bundleUrl,
}

const result = await orgScopedShopifyDevelopersRequest<CreateAppVersionMutationSchema>(
const result = await appManagementRequest<CreateAppVersionMutationSchema>(
organizationId,
CreateAppVersionMutation,
await this.token(),
Expand All @@ -563,7 +556,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
const {version, userErrors} = result.versionCreate
if (!version) return {appDeploy: {userErrors}} as unknown as AppDeploySchema

const devDashFqdn = (await shopifyDevelopersFqdn()).replace('app.', 'developers.')
const devDashFqdn = (await appManagementFqdn()).replace('app.', 'developers.')
const versionResult = {
appDeploy: {
appVersion: {
Expand All @@ -586,7 +579,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
}

const releaseVariables: ReleaseVersionMutationVariables = {appId: apiKey, versionId: version.id}
const releaseResult = await orgScopedShopifyDevelopersRequest<ReleaseVersionMutationSchema>(
const releaseResult = await appManagementRequest<ReleaseVersionMutationSchema>(
'1',
ReleaseVersionMutation,
await this.token(),
Expand All @@ -609,7 +602,7 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
version: AppVersionIdentifiers
}): Promise<AppReleaseSchema> {
const releaseVariables: ReleaseVersionMutationVariables = {appId, versionId}
const releaseResult = await orgScopedShopifyDevelopersRequest<ReleaseVersionMutationSchema>(
const releaseResult = await appManagementRequest<ReleaseVersionMutationSchema>(
organizationId,
ReleaseVersionMutation,
await this.token(),
Expand Down Expand Up @@ -703,20 +696,15 @@ export class ShopifyDevelopersClient implements DeveloperPlatformClient {
private async fetchApp({id, organizationId}: MinimalAppIdentifiers): Promise<ActiveAppReleaseQuerySchema> {
const query = ActiveAppReleaseQuery
const variables: ActiveAppReleaseQueryVariables = {appId: id}
return orgScopedShopifyDevelopersRequest<ActiveAppReleaseQuerySchema>(
organizationId,
query,
await this.token(),
variables,
)
return appManagementRequest<ActiveAppReleaseQuerySchema>(organizationId, query, await this.token(), variables)
}

private async activeAppVersionRawResult({
id,
organizationId,
}: MinimalAppIdentifiers): Promise<ActiveAppReleaseQuerySchema> {
const variables: ActiveAppReleaseQueryVariables = {appId: id}
return orgScopedShopifyDevelopersRequest<ActiveAppReleaseQuerySchema>(
return appManagementRequest<ActiveAppReleaseQuerySchema>(
organizationId,
ActiveAppReleaseQuery,
await this.token(),
Expand Down Expand Up @@ -1559,7 +1547,7 @@ async function stubbedExtensionTemplates(): Promise<ExtensionTemplate[]> {
]
}

// Business platform uses base64-encoded GIDs, while Shopify Developers uses
// Business platform uses base64-encoded GIDs, while App Management uses
// just the integer portion of that ID. These functions convert between the two.

// 1234 => gid://organization/Organization/1234 => base64
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-kit/src/private/node/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ async function executeCompleteFlow(applications: OAuthApplications, identityFqdn
* @param partnersToken - Partners token.
*/
async function ensureUserHasPartnerAccount(partnersToken: string) {
if (isTruthy(process.env.USE_SHOPIFY_DEVELOPERS_CLIENT)) return
if (isTruthy(process.env.USE_APP_MANAGEMENT_API)) return

outputDebug(outputContent`Verifying that the user has a Partner organization`)
if (!(await hasPartnerAccount(partnersToken))) {
Expand Down

0 comments on commit 95945c4

Please sign in to comment.