Skip to content
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
18 changes: 13 additions & 5 deletions packages/app/src/cli/models/app/app.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ClientName,
CreateAppOptions,
DeveloperPlatformClient,
MigrationDeveloperPlatformClient,
DevSessionCreateOptions,
DevSessionDeleteOptions,
DevSessionUpdateOptions,
Expand Down Expand Up @@ -1300,8 +1301,12 @@ const appLogsSubscribeResponse: AppLogsSubscribeResponse = {
},
}

export function testDeveloperPlatformClient(stubs: Partial<DeveloperPlatformClient> = {}): DeveloperPlatformClient {
const clientStub: DeveloperPlatformClient = {
type TestDeveloperPlatformClient = DeveloperPlatformClient & MigrationDeveloperPlatformClient

export function testDeveloperPlatformClient(
stubs: Partial<TestDeveloperPlatformClient> = {},
): TestDeveloperPlatformClient {
const clientStub: TestDeveloperPlatformClient = {
clientName: ClientName.AppManagement,
webUiName: 'Test Dashboard',
organizationSource: OrganizationSource.BusinessPlatform,
Expand Down Expand Up @@ -1374,15 +1379,18 @@ export function testDeveloperPlatformClient(stubs: Partial<DeveloperPlatformClie
),
...stubs,
}
const retVal: Partial<DeveloperPlatformClient> = clientStub
const retVal: Partial<TestDeveloperPlatformClient> = clientStub
for (const [key, value] of Object.entries(clientStub)) {
if (typeof value === 'function') {
retVal[
key as keyof Omit<DeveloperPlatformClient, 'clientName' | 'webUiName' | 'organizationSource' | 'bundleFormat'>
key as keyof Omit<
TestDeveloperPlatformClient,
'clientName' | 'webUiName' | 'organizationSource' | 'bundleFormat'
>
] = vi.fn().mockImplementation(value)
}
}
return retVal as DeveloperPlatformClient
return retVal as TestDeveloperPlatformClient
}

export const testPartnersServiceSession: Session = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
migrateAppModules,
UIModulesMap,
} from '../dev/migrate-app-module.js'
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {MigrationDeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {PartnersClient} from '../../utilities/developer-platform-client/partners-client.js'
import {AbortSilentError} from '@shopify/cli-kit/node/error'

Expand Down Expand Up @@ -94,7 +94,7 @@ function migrationGroup(typesMap: {[key: string]: string[]}, type: string) {
extensionsToMigrate: Parameters<typeof migrateAppModules>[0]['extensionsToMigrate']
appId: string
remoteExtensions: RemoteSource[]
migrationClient: DeveloperPlatformClient
migrationClient: MigrationDeveloperPlatformClient
}) => migrateAppModules({...options, type}),
}
}
4 changes: 2 additions & 2 deletions packages/app/src/cli/services/dev/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('fetchOrganizations', async () => {
// Given
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([ORG2]),
}) as AppManagementClient
}) as unknown as AppManagementClient
vi.mocked(AppManagementClient.getInstance).mockReturnValue(appManagementClient)

// When
Expand All @@ -60,7 +60,7 @@ describe('fetchOrganizations', async () => {
// Given
const appManagementClient: AppManagementClient = testDeveloperPlatformClient({
organizations: () => Promise.resolve([]),
}) as AppManagementClient
}) as unknown as AppManagementClient
vi.mocked(AppManagementClient.getInstance).mockReturnValue(appManagementClient)

// When
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/cli/services/dev/migrate-app-module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {LocalSource, RemoteSource} from '../context/identifiers.js'
import {ExtensionUuidsByLocalIdentifier} from '../../models/app/identifiers.js'
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {MigrationDeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {MigrateAppModuleSchema, MigrateAppModuleVariables} from '../../api/graphql/extension_migrate_app_module.js'
import {MAX_EXTENSION_HANDLE_LENGTH} from '../../models/extensions/schemas.js'
import {AbortError} from '@shopify/cli-kit/node/error'
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function migrateAppModules(options: {
appId: string
type: string
remoteExtensions: RemoteSource[]
migrationClient: DeveloperPlatformClient
migrationClient: MigrationDeveloperPlatformClient
}) {
const {extensionsToMigrate, appId, type, remoteExtensions, migrationClient} = options

Expand Down Expand Up @@ -123,7 +123,7 @@ async function migrateAppModule(options: {
registrationId: MigrateAppModuleVariables['registrationId']
registrationUuid: MigrateAppModuleVariables['registrationUuid']
type: MigrateAppModuleVariables['type']
migrationClient: DeveloperPlatformClient
migrationClient: MigrationDeveloperPlatformClient
}) {
const {apiKey, registrationId, registrationUuid, type, migrationClient} = options

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/cli/services/dev/migrate-flow-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
MigrateFlowExtensionSchema,
MigrateFlowExtensionVariables,
} from '../../api/graphql/extension_migrate_flow_extension.js'
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {MigrationDeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {AbortError} from '@shopify/cli-kit/node/error'

export async function migrateFlowExtensions(options: {
extensionsToMigrate: LocalRemoteSource[]
appId: string
remoteExtensions: RemoteSource[]
migrationClient: DeveloperPlatformClient
migrationClient: MigrationDeveloperPlatformClient
}) {
const {extensionsToMigrate, appId, remoteExtensions, migrationClient} = options

Expand Down Expand Up @@ -46,7 +46,7 @@ async function migrateFlowExtension(options: {
apiKey: MigrateFlowExtensionVariables['apiKey']
registrationId: MigrateFlowExtensionVariables['registrationId']
registrationUuid: MigrateFlowExtensionVariables['registrationUuid']
migrationClient: DeveloperPlatformClient
migrationClient: MigrationDeveloperPlatformClient
}) {
const {apiKey, registrationId, registrationUuid, migrationClient} = options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
MigrateToUiExtensionVariables,
} from '../../api/graphql/extension_migrate_to_ui_extension.js'
import {RemoteSource} from '../context/identifiers.js'
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {MigrationDeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {AbortError} from '@shopify/cli-kit/node/error'

export async function migrateExtensionsToUIExtension(options: {
extensionsToMigrate: LocalRemoteSource[]
appId: string
remoteExtensions: RemoteSource[]
migrationClient: DeveloperPlatformClient
migrationClient: MigrationDeveloperPlatformClient
}) {
const {extensionsToMigrate, appId, remoteExtensions, migrationClient} = options

Expand Down Expand Up @@ -41,7 +41,7 @@ async function migrateExtensionToUIExtension(options: {
apiKey: MigrateToUiExtensionVariables['apiKey']
registrationId: MigrateToUiExtensionVariables['registrationId']
registrationUuid: MigrateToUiExtensionVariables['registrationUuid']
migrationClient: DeveloperPlatformClient
migrationClient: MigrationDeveloperPlatformClient
}) {
const {apiKey, registrationId, registrationUuid, migrationClient} = options

Expand Down
22 changes: 17 additions & 5 deletions packages/app/src/cli/utilities/developer-platform-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ export interface DeveloperPlatformClient {
sendSampleWebhook: (input: SendSampleWebhookVariables, organizationId: string) => Promise<SendSampleWebhookSchema>
apiVersions: (organizationId: string) => Promise<PublicApiVersionsSchema>
topics: (input: WebhookTopicsVariables, organizationId: string) => Promise<WebhookTopicsSchema>
migrateFlowExtension: (input: MigrateFlowExtensionVariables) => Promise<MigrateFlowExtensionSchema>
migrateAppModule: (input: MigrateAppModuleVariables) => Promise<MigrateAppModuleSchema>
updateURLs: (input: UpdateURLsVariables) => Promise<UpdateURLsSchema>
currentAccountInfo: () => Promise<CurrentAccountInfoQuery>
targetSchemaDefinition: (
Expand All @@ -240,7 +238,6 @@ export interface DeveloperPlatformClient {
apiKey: string,
organizationId: string,
) => Promise<string | null>
migrateToUiExtension: (input: MigrateToUiExtensionVariables) => Promise<MigrateToUiExtensionSchema>
toExtensionGraphQLType: (input: string) => string
subscribeToAppLogs: (
input: AppLogsSubscribeMutationVariables,
Expand All @@ -254,7 +251,22 @@ export interface DeveloperPlatformClient {
getCreateDevStoreLink: (org: Organization) => Promise<TokenItem>
}

const inProgressRefreshes = new WeakMap<DeveloperPlatformClient, Promise<string>>()
/**
* The legacy extension migrations (Flow, app module, and UI extension) are only implemented by
* {@link PartnersClient}; the default {@link AppManagementClient} does not support them. Keeping
* these mutations on a dedicated interface lets the migration callers depend on just this surface
* rather than the full {@link DeveloperPlatformClient}.
*/
export interface MigrationDeveloperPlatformClient {
migrateFlowExtension: (input: MigrateFlowExtensionVariables) => Promise<MigrateFlowExtensionSchema>
migrateAppModule: (input: MigrateAppModuleVariables) => Promise<MigrateAppModuleSchema>
migrateToUiExtension: (input: MigrateToUiExtensionVariables) => Promise<MigrateToUiExtensionSchema>
}

/** The subset of a developer platform client needed to refresh an expired token. */
type TokenRefreshableClient = Pick<DeveloperPlatformClient, 'session' | 'unsafeRefreshToken'>

const inProgressRefreshes = new WeakMap<TokenRefreshableClient, Promise<string>>()

/**
* Creates an unauthorized handler for a developer platform client that will refresh the token
Expand All @@ -266,7 +278,7 @@ const inProgressRefreshes = new WeakMap<DeveloperPlatformClient, Promise<string>
* @returns The unauthorized handler.
*/
export function createUnauthorizedHandler(
client: DeveloperPlatformClient,
client: TokenRefreshableClient,
tokenType: 'default' | 'businessPlatform' = 'default',
): UnauthorizedHandler {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,9 @@ import {
} from '../../services/webhook/request-sample.js'
import {PublicApiVersionsSchema} from '../../services/webhook/request-api-versions.js'
import {WebhookTopicsSchema, WebhookTopicsVariables} from '../../services/webhook/request-topics.js'
import {
MigrateFlowExtensionSchema,
MigrateFlowExtensionVariables,
} from '../../api/graphql/extension_migrate_flow_extension.js'
import {UpdateURLsSchema, UpdateURLsVariables} from '../../api/graphql/update_urls.js'
import {CurrentAccountInfoQuery} from '../../api/graphql/partners/generated/current-account-info.js'
import {ExtensionTemplate, ExtensionTemplatesResult} from '../../models/app/template.js'
import {
MigrateToUiExtensionVariables,
MigrateToUiExtensionSchema,
} from '../../api/graphql/extension_migrate_to_ui_extension.js'
import {MigrateAppModuleSchema, MigrateAppModuleVariables} from '../../api/graphql/extension_migrate_app_module.js'
import {AppHomeSpecIdentifier} from '../../models/extensions/specifications/app_config_app_home.js'
import {BrandingSpecIdentifier} from '../../models/extensions/specifications/app_config_branding.js'
import {AppAccessSpecIdentifier} from '../../models/extensions/specifications/app_config_app_access.js'
Expand Down Expand Up @@ -935,14 +926,6 @@ export class AppManagementClient implements DeveloperPlatformClient {
}
}

async migrateFlowExtension(_input: MigrateFlowExtensionVariables): Promise<MigrateFlowExtensionSchema> {
throw new BugError('Not implemented: migrateFlowExtension')
}

async migrateAppModule(_input: MigrateAppModuleVariables): Promise<MigrateAppModuleSchema> {
throw new BugError('Not implemented: migrateAppModule')
}

async updateURLs(_input: UpdateURLsVariables): Promise<UpdateURLsSchema> {
outputDebug('⚠️ updateURLs is not implemented')
return {appUpdate: {userErrors: []}}
Expand Down Expand Up @@ -997,10 +980,6 @@ export class AppManagementClient implements DeveloperPlatformClient {
}
}

async migrateToUiExtension(_input: MigrateToUiExtensionVariables): Promise<MigrateToUiExtensionSchema> {
throw new BugError('Not implemented: migrateToUiExtension')
}

toExtensionGraphQLType(input: string) {
return input.toLowerCase()
}
Expand Down
Loading