From a520fee540108c653465f00b936f5582cf1ace85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Thu, 16 Jul 2026 16:59:15 +0200 Subject: [PATCH] Remove vestigial account-info and Partners codegen plumbing Follow-up cleanup now that PartnersClient is reduced to the migration surface. currentAccountInfo was a Partners-era method. AppManagement implements it as a throwing stub, and its only caller (fetchOrganizations, via fetchCurrentAccountInformation) swallowed the throw and fell back to an "unknown account" in the "No Organization found" error. Switch that caller to session.accountInfo -- which AppManagement already populates and which the sibling fetchOrgFromId already uses -- so the error now names the real account. Then drop currentAccountInfo from the interface, the AppManagement stub, and the test double, and delete the orphaned partner-account-info service plus its generated current-account-info document. With partner-account-info gone, its account-info cache in app-conf-store had no remaining callers, so delete that file and its test. partnersRequestDoc had no remaining callers after PartnersClient stopped using it; remove the dead cli-kit export and the imports it exclusively pulled in. The Partners typed-document codegen no longer has any operations: remove the partners project from graphql.config.ts and its nx targets, delete the orphaned generated types, and drop the Partners schema from the fetch script. Co-Authored-By: Claude Opus 4.8 (1M context) --- bin/get-graphql-schemas.js | 6 -- graphql.config.ts | 1 - packages/app/project.json | 16 --- .../generated/current-account-info.ts | 58 ----------- .../api/graphql/partners/generated/types.d.ts | 33 ------- .../queries/current-account-info.graphql | 11 --- .../app/src/cli/models/app/app.test-data.ts | 9 -- .../src/cli/services/app/config/link.test.ts | 1 - packages/app/src/cli/services/context.test.ts | 1 - .../context/partner-account-info.test.ts | 98 ------------------- .../services/context/partner-account-info.ts | 54 ---------- packages/app/src/cli/services/dev/fetch.ts | 7 +- .../cli/services/import-extensions.test.ts | 1 - .../src/cli/utilities/app-conf-store.test.ts | 98 ------------------- .../app/src/cli/utilities/app-conf-store.ts | 36 ------- .../utilities/developer-platform-client.ts | 2 - .../app-management-client.ts | 5 - .../cli-kit/src/public/node/api/partners.ts | 60 +----------- 18 files changed, 3 insertions(+), 494 deletions(-) delete mode 100644 packages/app/src/cli/api/graphql/partners/generated/current-account-info.ts delete mode 100644 packages/app/src/cli/api/graphql/partners/generated/types.d.ts delete mode 100644 packages/app/src/cli/api/graphql/partners/queries/current-account-info.graphql delete mode 100644 packages/app/src/cli/services/context/partner-account-info.test.ts delete mode 100644 packages/app/src/cli/services/context/partner-account-info.ts delete mode 100644 packages/app/src/cli/utilities/app-conf-store.test.ts delete mode 100644 packages/app/src/cli/utilities/app-conf-store.ts diff --git a/bin/get-graphql-schemas.js b/bin/get-graphql-schemas.js index 7ca6ff1e873..b021a64e991 100755 --- a/bin/get-graphql-schemas.js +++ b/bin/get-graphql-schemas.js @@ -38,12 +38,6 @@ function sleep(ms) { * @type {Schema[]} */ const schemas = [ - { - owner: 'Shopify', - repo: 'partners', - pathToFile: 'db/graphql/cli_schema.graphql', - localPaths: ['./packages/app/src/cli/api/graphql/partners/cli_schema.graphql'], - }, { owner: 'shop', repo: 'world', diff --git a/graphql.config.ts b/graphql.config.ts index 215a5f81e62..7461bfe7cb4 100644 --- a/graphql.config.ts +++ b/graphql.config.ts @@ -75,7 +75,6 @@ function projectFactory(name: string, schemaName: string, project: string = 'app export default { projects: { - partners: projectFactory('partners', 'cli_schema.graphql'), businessPlatformDestinations: projectFactory('business-platform-destinations', 'destinations_schema.graphql'), businessPlatformOrganizations: projectFactory('business-platform-organizations', 'organizations_schema.graphql'), appDev: projectFactory('app-dev', 'app_dev_schema.graphql'), diff --git a/packages/app/project.json b/packages/app/project.json index 6f889c815db..b9bda81b6d7 100644 --- a/packages/app/project.json +++ b/packages/app/project.json @@ -51,7 +51,6 @@ "dependsOn": ["graphql-codegen:postfix"], "inputs": [{ "dependentTasksOutputFiles": "**/*.ts" }], "outputs": [ - "{projectRoot}/src/cli/api/graphql/partners/generated/**/*.ts", "{projectRoot}/src/cli/api/graphql/business-platform-destinations/generated/**/*.ts", "{projectRoot}/src/cli/api/graphql/business-platform-organizations/generated/**/*.ts", "{projectRoot}/src/cli/api/graphql/app-dev/generated/**/*.ts", @@ -62,7 +61,6 @@ ], "options": { "commands": [ - "pnpm eslint 'src/cli/api/graphql/partners/generated/**/*.{ts,tsx}' --fix", "pnpm eslint 'src/cli/api/graphql/business-platform-destinations/generated/**/*.{ts,tsx}' --fix", "pnpm eslint 'src/cli/api/graphql/business-platform-organizations/generated/**/*.{ts,tsx}' --fix", "pnpm eslint 'src/cli/api/graphql/app-dev/generated/**/*.{ts,tsx}' --fix", @@ -74,17 +72,6 @@ "cwd": "packages/app" } }, - "graphql-codegen:generate:partners": { - "executor": "nx:run-commands", - "inputs": ["{workspaceRoot}/graphql.config.ts", "{projectRoot}/src/cli/api/graphql/partners/**/*.graphql"], - "outputs": ["{projectRoot}/src/cli/api/graphql/partners/generated/**/*.ts"], - "options": { - "commands": [ - "pnpm exec graphql-codegen --project=partners" - ], - "cwd": "{workspaceRoot}" - } - }, "graphql-codegen:generate:business-platform-destinations": { "executor": "nx:run-commands", "inputs": ["{workspaceRoot}/graphql.config.ts", "{projectRoot}/src/cli/api/graphql/business-platform-destinations/**/*.graphql"], @@ -165,7 +152,6 @@ "graphql-codegen:postfix": { "executor": "nx:run-commands", "dependsOn": [ - "graphql-codegen:generate:partners", "graphql-codegen:generate:business-platform-destinations", "graphql-codegen:generate:business-platform-organizations", "graphql-codegen:generate:app-dev", @@ -176,7 +162,6 @@ ], "inputs": [{ "dependentTasksOutputFiles": "**/*.ts" }], "outputs": [ - "{projectRoot}/src/cli/api/graphql/partners/generated/**/*.ts", "{projectRoot}/src/cli/api/graphql/business-platform-destinations/generated/**/*.ts", "{projectRoot}/src/cli/api/graphql/business-platform-organizations/generated/**/*.ts", "{projectRoot}/src/cli/api/graphql/app-dev/generated/**/*.ts", @@ -187,7 +172,6 @@ ], "options": { "commands": [ - "find ./packages/app/src/cli/api/graphql/partners/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;", "find ./packages/app/src/cli/api/graphql/business-platform-destinations/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;", "find ./packages/app/src/cli/api/graphql/business-platform-organizations/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;", "find ./packages/app/src/cli/api/graphql/app-dev/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;", diff --git a/packages/app/src/cli/api/graphql/partners/generated/current-account-info.ts b/packages/app/src/cli/api/graphql/partners/generated/current-account-info.ts deleted file mode 100644 index ebbce6a1785..00000000000 --- a/packages/app/src/cli/api/graphql/partners/generated/current-account-info.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* 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 CurrentAccountInfoQueryVariables = Types.Exact<{[key: string]: never}> - -export type CurrentAccountInfoQuery = { - currentAccountInfo: {__typename: 'ServiceAccount'; orgName: string} | {__typename: 'UserAccount'; email: string} -} - -export const CurrentAccountInfo = { - kind: 'Document', - definitions: [ - { - kind: 'OperationDefinition', - operation: 'query', - name: {kind: 'Name', value: 'currentAccountInfo'}, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: {kind: 'Name', value: 'currentAccountInfo'}, - selectionSet: { - kind: 'SelectionSet', - selections: [ - {kind: 'Field', name: {kind: 'Name', value: '__typename'}}, - { - kind: 'InlineFragment', - typeCondition: {kind: 'NamedType', name: {kind: 'Name', value: 'ServiceAccount'}}, - selectionSet: { - kind: 'SelectionSet', - selections: [ - {kind: 'Field', name: {kind: 'Name', value: 'orgName'}}, - {kind: 'Field', name: {kind: 'Name', value: '__typename'}}, - ], - }, - }, - { - kind: 'InlineFragment', - typeCondition: {kind: 'NamedType', name: {kind: 'Name', value: 'UserAccount'}}, - selectionSet: { - kind: 'SelectionSet', - selections: [ - {kind: 'Field', name: {kind: 'Name', value: 'email'}}, - {kind: 'Field', name: {kind: 'Name', value: '__typename'}}, - ], - }, - }, - ], - }, - }, - ], - }, - }, - ], -} as unknown as DocumentNode diff --git a/packages/app/src/cli/api/graphql/partners/generated/types.d.ts b/packages/app/src/cli/api/graphql/partners/generated/types.d.ts deleted file mode 100644 index 1ffd775f795..00000000000 --- a/packages/app/src/cli/api/graphql/partners/generated/types.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any, tsdoc/syntax, @typescript-eslint/no-duplicate-type-constituents, @typescript-eslint/no-redundant-type-constituents, @nx/enforce-module-boundaries */ -import {JsonMapType} from '@shopify/cli-kit/node/toml' -export type Maybe = T | null; -export type InputMaybe = Maybe; -export type Exact = { [K in keyof T]: T[K] }; -export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; -export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -/** All built-in and custom scalars, mapped to their actual values */ -export type Scalars = { - ID: { input: string; output: string; } - String: { input: string; output: string; } - Boolean: { input: boolean; output: boolean; } - Int: { input: number; output: number; } - Float: { input: number; output: number; } - /** - * An [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) encoded UTC date time - * string. Example value: `"2019-07-03T20:47:55.123456Z"`. - */ - DateTime: { input: any; output: any; } - /** - * Deprecated: Supported extension types. - * This used to include a list of extension types, we mantain it to keep compatibility with the old schema - */ - ExtensionType: { input: any; output: any; } - /** Represents untyped JSON */ - JSON: { input: JsonMapType | string; output: JsonMapType; } - /** A valid URL, transported as a string. */ - Url: { input: any; output: any; } - /** A valid webhook subscription endpoint string. */ - WebhookSubscriptionEndpoint: { input: any; output: any; } -}; diff --git a/packages/app/src/cli/api/graphql/partners/queries/current-account-info.graphql b/packages/app/src/cli/api/graphql/partners/queries/current-account-info.graphql deleted file mode 100644 index 05d05fee2e2..00000000000 --- a/packages/app/src/cli/api/graphql/partners/queries/current-account-info.graphql +++ /dev/null @@ -1,11 +0,0 @@ -query currentAccountInfo { - currentAccountInfo { - __typename - ... on ServiceAccount { - orgName - } - ... on UserAccount { - email - } - } -} diff --git a/packages/app/src/cli/models/app/app.test-data.ts b/packages/app/src/cli/models/app/app.test-data.ts index 230c665b681..f66757b9036 100644 --- a/packages/app/src/cli/models/app/app.test-data.ts +++ b/packages/app/src/cli/models/app/app.test-data.ts @@ -52,7 +52,6 @@ import { 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 { MigrateToUiExtensionSchema, MigrateToUiExtensionVariables, @@ -1282,13 +1281,6 @@ const updateURLsResponse: UpdateURLsSchema = { }, } -const currentAccountInfoResponse: CurrentAccountInfoQuery = { - currentAccountInfo: { - __typename: 'UserAccount', - email: 'user@example.com', - }, -} - const migrateToUiExtensionResponse: MigrateToUiExtensionSchema = { migrateToUiExtension: { migratedToUiExtension: true, @@ -1344,7 +1336,6 @@ export function testDeveloperPlatformClient( migrateFlowExtension: (_input: MigrateFlowExtensionVariables) => Promise.resolve(migrateFlowExtensionResponse), migrateAppModule: (_input: MigrateAppModuleVariables) => Promise.resolve(migrateAppModuleResponse), updateURLs: (_input: UpdateURLsVariables) => Promise.resolve(updateURLsResponse), - currentAccountInfo: () => Promise.resolve(currentAccountInfoResponse), targetSchemaDefinition: (_input: SchemaDefinitionByTargetQueryVariables & {apiKey?: string}, _orgId: string) => Promise.resolve('schema'), apiSchemaDefinition: (_input: SchemaDefinitionByApiTypeQueryVariables & {apiKey?: string}, _orgId: string) => diff --git a/packages/app/src/cli/services/app/config/link.test.ts b/packages/app/src/cli/services/app/config/link.test.ts index 1e70ad58b55..c049a8f44f7 100644 --- a/packages/app/src/cli/services/app/config/link.test.ts +++ b/packages/app/src/cli/services/app/config/link.test.ts @@ -38,7 +38,6 @@ vi.mock('../../../models/app/loader.js', async () => { vi.mock('../../local-storage') vi.mock('@shopify/cli-kit/node/ui') vi.mock('@shopify/cli-kit/node/system') -vi.mock('../../context/partner-account-info.js') vi.mock('../../context.js') vi.mock('../select-app.js') diff --git a/packages/app/src/cli/services/context.test.ts b/packages/app/src/cli/services/context.test.ts index 2de57d902d0..252ea3f06cf 100644 --- a/packages/app/src/cli/services/context.test.ts +++ b/packages/app/src/cli/services/context.test.ts @@ -112,7 +112,6 @@ vi.mock('@shopify/cli-kit/node/node-package-manager.js') vi.mock('@shopify/cli-kit/node/ui') vi.mock('./deploy/mode.js') vi.mock('./app/config/link.js') -vi.mock('./context/partner-account-info.js') vi.mock('@shopify/cli-kit/node/session') vi.mock('./generate/fetch-extension-specifications.js') vi.mock('./app/select-app.js') diff --git a/packages/app/src/cli/services/context/partner-account-info.test.ts b/packages/app/src/cli/services/context/partner-account-info.test.ts deleted file mode 100644 index cc151547f53..00000000000 --- a/packages/app/src/cli/services/context/partner-account-info.test.ts +++ /dev/null @@ -1,98 +0,0 @@ -import {fetchCurrentAccountInformation} from './partner-account-info.js' -import {testDeveloperPlatformClient} from '../../models/app/app.test-data.js' -import {clearCachedAccountInfo, getCachedAccountInfo, setCachedAccountInfo} from '../../utilities/app-conf-store.js' -import {AccountInfo} from '@shopify/cli-kit/node/session' -import {beforeEach, describe, expect, test, vi} from 'vitest' -import {AbortError} from '@shopify/cli-kit/node/error' -import {outputDebug} from '@shopify/cli-kit/node/output' - -vi.mock('@shopify/cli-kit/node/output') - -const userId = '1234-5678' -const accountInfo: AccountInfo = { - type: 'UserAccount', - email: 'partner@shopify.com', -} - -describe('fetchCurrentAccountInformation', () => { - beforeEach(() => { - clearCachedAccountInfo() - }) - - test('returns cached account info if available', async () => { - // Given - const currentAccountInfo = vi.fn() - const developerPlatformClient = testDeveloperPlatformClient({currentAccountInfo}) - setCachedAccountInfo(userId, accountInfo) - - // When - const got = await fetchCurrentAccountInformation(developerPlatformClient, userId) - - // Then - expect(got).toEqual(accountInfo) - expect(outputDebug).toHaveBeenCalledWith('Getting partner account info from cache') - expect(currentAccountInfo).not.toHaveBeenCalled() - }) - - test('fetches user account info and caches it if not in cache', async () => { - // Given - const currentAccountInfo = vi.fn(async () => ({ - currentAccountInfo: { - __typename: 'UserAccount' as const, - email: accountInfo.email, - }, - })) - const developerPlatformClient = testDeveloperPlatformClient({currentAccountInfo}) - - // When - const got = await fetchCurrentAccountInformation(developerPlatformClient, userId) - - // Then - expect(got).toEqual(accountInfo) - expect(currentAccountInfo).toHaveBeenCalled() - - const cachedInfo = getCachedAccountInfo(userId) - expect(cachedInfo).toEqual(accountInfo) - }) - - test('fetches service account info and caches it if not in cache', async () => { - // Given - const serviceAccountInfo: AccountInfo = { - type: 'ServiceAccount', - orgName: 'Test Org', - } - const currentAccountInfo = vi.fn(async () => ({ - currentAccountInfo: { - __typename: 'ServiceAccount' as const, - orgName: serviceAccountInfo.orgName, - }, - })) - const developerPlatformClient = testDeveloperPlatformClient({currentAccountInfo}) - - // When - const got = await fetchCurrentAccountInformation(developerPlatformClient, userId) - - // Then - expect(got).toEqual(serviceAccountInfo) - expect(getCachedAccountInfo(userId)).toEqual(serviceAccountInfo) - }) - - test('when error fetching account info returns unknown partner info', async () => { - // Given - clearCachedAccountInfo() - const currentAccountInfo = vi.fn(async () => { - throw new AbortError('Error') - }) - const developerPlatformClient = testDeveloperPlatformClient({currentAccountInfo}) - - // When - const got = await fetchCurrentAccountInformation(developerPlatformClient, userId) - - // Then - expect(got).toEqual({type: 'UnknownAccount'}) - expect(outputDebug).toHaveBeenCalledWith('Error fetching user account info') - - const cachedInfo = getCachedAccountInfo(userId) - expect(cachedInfo).toBeUndefined() - }) -}) diff --git a/packages/app/src/cli/services/context/partner-account-info.ts b/packages/app/src/cli/services/context/partner-account-info.ts deleted file mode 100644 index de1244cfd6a..00000000000 --- a/packages/app/src/cli/services/context/partner-account-info.ts +++ /dev/null @@ -1,54 +0,0 @@ -import {CurrentAccountInfoQuery} from '../../api/graphql/partners/generated/current-account-info.js' -import {getCachedAccountInfo, setCachedAccountInfo} from '../../utilities/app-conf-store.js' -import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js' -import {AbortError} from '@shopify/cli-kit/node/error' -import {outputDebug} from '@shopify/cli-kit/node/output' -import {AccountInfo} from '@shopify/cli-kit/node/session' - -export async function fetchCurrentAccountInformation( - developerPlatformClient: DeveloperPlatformClient, - subject: string, -): Promise { - const cachedInfo = getCachedAccountInfo(subject) - - if (cachedInfo) { - outputDebug('Getting partner account info from cache') - return cachedInfo - } - - try { - const fromApi = await getCurrentAccountInfo(developerPlatformClient) - setCachedAccountInfo(subject, fromApi) - return fromApi - // eslint-disable-next-line no-catch-all/no-catch-all - } catch (error) { - outputDebug('Error fetching user account info') - return {type: 'UnknownAccount'} - } -} - -async function getCurrentAccountInfo(developerPlatformClient: DeveloperPlatformClient): Promise { - const {currentAccountInfo} = await developerPlatformClient.currentAccountInfo() - - if (!currentAccountInfo) { - throw new AbortError('Unable to get current user account') - } - - return mapAccountInfo(currentAccountInfo) -} - -function mapAccountInfo(accountInfo: CurrentAccountInfoQuery['currentAccountInfo']): AccountInfo { - if (accountInfo.__typename === 'UserAccount') { - return { - type: 'UserAccount', - email: accountInfo.email, - } - } else if (accountInfo.__typename === 'ServiceAccount') { - return { - type: 'ServiceAccount', - orgName: accountInfo.orgName, - } - } else { - return {type: 'UnknownAccount'} - } -} diff --git a/packages/app/src/cli/services/dev/fetch.ts b/packages/app/src/cli/services/dev/fetch.ts index 0796132c9c0..e7d799dfe8a 100644 --- a/packages/app/src/cli/services/dev/fetch.ts +++ b/packages/app/src/cli/services/dev/fetch.ts @@ -1,5 +1,4 @@ import {Organization, OrganizationStore} from '../../models/organization.js' -import {fetchCurrentAccountInformation} from '../context/partner-account-info.js' import { DeveloperPlatformClient, Store, @@ -79,10 +78,8 @@ export async function fetchOrganizations(): Promise { const organizations: Organization[] = await client.organizations() if (organizations.length === 0) { - const developerPlatformClient = defaultDeveloperPlatformClient() - const session = await developerPlatformClient.session() - const accountInfo = await fetchCurrentAccountInformation(developerPlatformClient, session.userId) - throw new NoOrgError(accountInfo) + const session = await client.session() + throw new NoOrgError(session.accountInfo) } return organizations } diff --git a/packages/app/src/cli/services/import-extensions.test.ts b/packages/app/src/cli/services/import-extensions.test.ts index 47e60a58c9a..bf048cb71be 100644 --- a/packages/app/src/cli/services/import-extensions.test.ts +++ b/packages/app/src/cli/services/import-extensions.test.ts @@ -12,7 +12,6 @@ import {AbortSilentError} from '@shopify/cli-kit/node/error' vi.mock('@shopify/cli-kit/node/ui') vi.mock('./context.js') vi.mock('./fetch-extensions.js') -vi.mock('./context/partner-account-info.js') const organizationApp: OrganizationApp = { id: 'id', diff --git a/packages/app/src/cli/utilities/app-conf-store.test.ts b/packages/app/src/cli/utilities/app-conf-store.test.ts deleted file mode 100644 index 53d5c7f0a00..00000000000 --- a/packages/app/src/cli/utilities/app-conf-store.test.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { - getConfigStoreForAccountInfoStatus, - getCachedAccountInfo, - setCachedAccountInfo, - clearCachedAccountInfo, -} from './app-conf-store.js' -import {AccountInfo} from '@shopify/cli-kit/node/session' -import {vi, describe, test, expect, beforeEach, afterEach} from 'vitest' -import {LocalStorage} from '@shopify/cli-kit/node/local-storage' -import {inTemporaryDirectory} from '@shopify/cli-kit/node/fs' - -describe('app-conf-store', () => { - beforeEach(async () => { - vi.useFakeTimers() - vi.setSystemTime(new Date('2023-01-01')) - }) - - afterEach(() => { - vi.useRealTimers() - }) - - test('getConfigStoreForAccountInfoStatus returns a LocalStorage instance', async () => { - await inTemporaryDirectory(async (tempDir) => { - const result = getConfigStoreForAccountInfoStatus(tempDir) - expect(result).toBeInstanceOf(LocalStorage) - }) - }) - - describe('getCachedAccountInfo', () => { - test('returns undefined when no cached data exists', async () => { - await inTemporaryDirectory(async (tempDir) => { - const result = getCachedAccountInfo('testSubject', tempDir) - expect(result).toBeUndefined() - }) - }) - - test('returns undefined when cached data is expired', async () => { - // More than 72 hours old - await inTemporaryDirectory(async (tempDir) => { - const loadedAt = new Date('2022-11-28').toISOString() - - const store = getConfigStoreForAccountInfoStatus(tempDir) - await store.set('testSubject', { - info: {type: 'UserAccount', email: 'test@example.com'} as AccountInfo, - loadedAt, - }) - - const result = getCachedAccountInfo('testSubject', tempDir) - expect(result).toBeUndefined() - }) - }) - - test('returns cached info when data is valid', async () => { - await inTemporaryDirectory(async (tempDir) => { - // Less than 72 hours old - - const validDate = new Date('2022-12-31').toISOString() - const mockInfo: AccountInfo = {type: 'UserAccount', email: 'test@example.com'} - const store = getConfigStoreForAccountInfoStatus(tempDir) - await store.set('testSubject', { - info: mockInfo, - loadedAt: validDate, - }) - - const result = getCachedAccountInfo('testSubject', tempDir) - expect(result).toEqual(mockInfo) - }) - }) - }) - - test('setCachedAccountInfo sets the data correctly', async () => { - await inTemporaryDirectory(async (tempDir) => { - const mockInfo: AccountInfo = {type: 'ServiceAccount', orgName: 'Test Org'} - - await setCachedAccountInfo('testSubject', mockInfo, tempDir) - - const store = getConfigStoreForAccountInfoStatus(tempDir) - const result = await store.get('testSubject') - expect(result).toEqual({ - info: mockInfo, - loadedAt: '2023-01-01T00:00:00.000Z', - }) - }) - }) - - test('clearCachedAccountInfo clears the store', async () => { - await inTemporaryDirectory(async (tempDir) => { - const mockInfo: AccountInfo = {type: 'UnknownAccount'} - await setCachedAccountInfo('testSubject', mockInfo, tempDir) - - await clearCachedAccountInfo(tempDir) - - const store = getConfigStoreForAccountInfoStatus(tempDir) - const result = await store.get('testSubject') - expect(result).toBeUndefined() - }) - }) -}) diff --git a/packages/app/src/cli/utilities/app-conf-store.ts b/packages/app/src/cli/utilities/app-conf-store.ts deleted file mode 100644 index c753c54d27a..00000000000 --- a/packages/app/src/cli/utilities/app-conf-store.ts +++ /dev/null @@ -1,36 +0,0 @@ -import {AccountInfo} from '@shopify/cli-kit/node/session' -import {LocalStorage} from '@shopify/cli-kit/node/local-storage' - -// max age is 72 hours (3 days) -const MAX_AGE_FOR_ACCOUNT_INFO_STATUS_MS = 3 * 24 * 60 * 60 * 1000 - -export function getConfigStoreForAccountInfoStatus(cwd?: string) { - return new LocalStorage<{[subject: string]: {info: AccountInfo; loadedAt: string}}>({ - projectName: 'shopify-app-account-info', - cwd, - }) -} - -export function getCachedAccountInfo(subject: string, cwd?: string) { - const store = getConfigStoreForAccountInfoStatus(cwd) - const cached = store.get(subject) - if (cached) { - // get age of cached data - const age = new Date().valueOf() - new Date(cached.loadedAt).valueOf() - if (age > MAX_AGE_FOR_ACCOUNT_INFO_STATUS_MS) { - return undefined - } - return cached.info - } - return undefined -} - -export function setCachedAccountInfo(subject: string, accountInfo: AccountInfo, cwd?: string) { - const store = getConfigStoreForAccountInfoStatus(cwd) - store.set(subject, {info: accountInfo, loadedAt: new Date().toISOString()}) -} - -export function clearCachedAccountInfo(cwd?: string) { - const store = getConfigStoreForAccountInfoStatus(cwd) - store.clear() -} diff --git a/packages/app/src/cli/utilities/developer-platform-client.ts b/packages/app/src/cli/utilities/developer-platform-client.ts index 821bf4d2ff3..3a1c04790e2 100644 --- a/packages/app/src/cli/utilities/developer-platform-client.ts +++ b/packages/app/src/cli/utilities/developer-platform-client.ts @@ -21,7 +21,6 @@ import { 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 {ExtensionTemplatesResult} from '../models/app/template.js' import {SchemaDefinitionByTargetQueryVariables} from '../api/graphql/functions/generated/schema-definition-by-target.js' import {SchemaDefinitionByApiTypeQueryVariables} from '../api/graphql/functions/generated/schema-definition-by-api-type.js' @@ -227,7 +226,6 @@ export interface DeveloperPlatformClient { apiVersions: (organizationId: string) => Promise topics: (input: WebhookTopicsVariables, organizationId: string) => Promise updateURLs: (input: UpdateURLsVariables) => Promise - currentAccountInfo: () => Promise targetSchemaDefinition: ( input: SchemaDefinitionByTargetQueryVariables, apiKey: string, diff --git a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts index 737b73d7b91..732fbc22509 100644 --- a/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts +++ b/packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts @@ -54,7 +54,6 @@ import { import {PublicApiVersionsSchema} from '../../services/webhook/request-api-versions.js' import {WebhookTopicsSchema, WebhookTopicsVariables} from '../../services/webhook/request-topics.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 {AppHomeSpecIdentifier} from '../../models/extensions/specifications/app_config_app_home.js' import {BrandingSpecIdentifier} from '../../models/extensions/specifications/app_config_branding.js' @@ -931,10 +930,6 @@ export class AppManagementClient implements DeveloperPlatformClient { return {appUpdate: {userErrors: []}} } - async currentAccountInfo(): Promise { - throw new BugError('Not implemented: currentAccountInfo') - } - async targetSchemaDefinition( input: SchemaDefinitionByTargetQueryVariables, apiKey: string, diff --git a/packages/cli-kit/src/public/node/api/partners.ts b/packages/cli-kit/src/public/node/api/partners.ts index 1d952ccf23a..7ba2e5118da 100644 --- a/packages/cli-kit/src/public/node/api/partners.ts +++ b/packages/cli-kit/src/public/node/api/partners.ts @@ -1,23 +1,9 @@ -import { - graphqlRequest, - GraphQLVariables, - GraphQLResponse, - graphqlRequestDoc, - CacheOptions, - UnauthorizedHandler, -} from './graphql.js' +import {graphqlRequest, GraphQLVariables, GraphQLResponse, CacheOptions, UnauthorizedHandler} from './graphql.js' import {partnersFqdn} from '../context/fqdn.js' import {setNextDeprecationDate} from '../../../private/node/context/deprecations-store.js' -import {getPackageManager} from '../node-package-manager.js' -import {cwd} from '../path.js' -import {AbortError} from '../error.js' -import {formatPackageManagerCommand} from '../output.js' import {RequestModeInput} from '../http.js' import Bottleneck from 'bottleneck' -import {Variables} from 'graphql-request' -import {TypedDocumentNode} from '@graphql-typed-document-node/core' - // API Rate limiter for partners API (Limit is 10 requests per second) // Jobs are launched every 150ms to add an extra 50ms margin per request. // Only 10 requests can be executed concurrently. @@ -77,50 +63,6 @@ export async function partnersRequest( return result } -/** - * Executes a GraphQL query against the Partners API. Uses typed documents. - * - * @param query - GraphQL query to execute. - * @param token - Partners token. - * @param variables - GraphQL variables to pass to the query. - * @param preferredBehaviour - Preferred behaviour for the request. - * @param unauthorizedHandler - Optional handler for unauthorized requests. - * @returns The response of the query of generic type . - */ -export async function partnersRequestDoc( - query: TypedDocumentNode, - token: string, - variables?: TVariables, - preferredBehaviour?: RequestModeInput, - unauthorizedHandler?: UnauthorizedHandler, -): Promise { - try { - const opts = await setupRequest(token) - const result = limiter.schedule(() => - graphqlRequestDoc({ - ...opts, - query, - variables, - preferredBehaviour, - unauthorizedHandler, - }), - ) - - return result - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (error: any) { - if (error.errors?.[0]?.extensions?.type === 'unsupported_client_version') { - const packageManager = await getPackageManager(cwd()) - - throw new AbortError(['Upgrade your CLI version to run this command.'], null, [ - ['Run', {command: formatPackageManagerCommand(packageManager, 'shopify upgrade')}], - ]) - } - - throw error - } -} - interface Deprecation { supportedUntilDate?: string }