From e51c6c6d2dff912c490a561cf03869d8c3904377 Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Tue, 17 Dec 2024 16:52:45 +0200 Subject: [PATCH] Report business platform ID instead of partner ID when relevant --- packages/app/src/cli/models/app/app.test-data.ts | 2 ++ packages/app/src/cli/services/app-context.test.ts | 2 +- packages/app/src/cli/services/app-context.ts | 15 +++++++++++---- packages/cli-kit/src/public/node/monorail.ts | 1 + packages/cli-kit/src/public/node/plugins.ts | 6 +++++- 5 files changed, 20 insertions(+), 6 deletions(-) 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 2ea50a349d8..7f46adf12f4 100644 --- a/packages/app/src/cli/models/app/app.test-data.ts +++ b/packages/app/src/cli/models/app/app.test-data.ts @@ -18,6 +18,7 @@ import { OrganizationApp, MinimalOrganizationApp, AppApiKeyAndOrgId, + OrganizationSource, } from '../organization.js' import {RemoteSpecification} from '../../api/graphql/extension_specifications.js' import {ExtensionInstance} from '../extensions/extension-instance.js' @@ -176,6 +177,7 @@ export function testOrganization(): Organization { return { id: '1', businessName: 'org1', + source: OrganizationSource.BusinessPlatform, } } diff --git a/packages/app/src/cli/services/app-context.test.ts b/packages/app/src/cli/services/app-context.test.ts index c6bc55bbcd5..f96d12127f6 100644 --- a/packages/app/src/cli/services/app-context.test.ts +++ b/packages/app/src/cli/services/app-context.test.ts @@ -232,7 +232,7 @@ describe('linkedAppContext', () => { const meta = metadata.getAllPublicMetadata() expect(meta).toEqual( expect.objectContaining({ - partner_id: tryParseInt(mockRemoteApp.organizationId), + business_platform_id: tryParseInt(mockOrganization.id), api_key: mockRemoteApp.apiKey, cmd_app_reset_used: false, }), diff --git a/packages/app/src/cli/services/app-context.ts b/packages/app/src/cli/services/app-context.ts index db2888d3f58..85f23b05078 100644 --- a/packages/app/src/cli/services/app-context.ts +++ b/packages/app/src/cli/services/app-context.ts @@ -3,7 +3,7 @@ import {getCachedAppInfo, setCachedAppInfo} from './local-storage.js' import {fetchSpecifications} from './generate/fetch-extension-specifications.js' import link from './app/config/link.js' import {fetchOrgFromId} from './dev/fetch.js' -import {Organization, OrganizationApp} from '../models/organization.js' +import {Organization, OrganizationApp, OrganizationSource} from '../models/organization.js' import {DeveloperPlatformClient, selectDeveloperPlatformClient} from '../utilities/developer-platform-client.js' import {getAppConfigurationState, loadAppUsingConfigurationState} from '../models/app/loader.js' import {RemoteAwareExtensionSpecification} from '../models/extensions/specification.js' @@ -97,14 +97,21 @@ export async function linkedAppContext({ setCachedAppInfo({appId: remoteApp.apiKey, title: remoteApp.title, directory, orgId: remoteApp.organizationId}) } - await logMetadata(remoteApp, forceRelink) + await logMetadata(remoteApp, organization, forceRelink) return {app: localApp, remoteApp, developerPlatformClient, specifications, organization} } -async function logMetadata(app: {organizationId: string; apiKey: string}, resetUsed: boolean) { +async function logMetadata(app: {apiKey: string}, organization: Organization, resetUsed: boolean) { + let organizationInfo: {partner_id?: number; business_platform_id?: number} + if (organization.source === OrganizationSource.BusinessPlatform) { + organizationInfo = {business_platform_id: tryParseInt(organization.id)} + } else { + organizationInfo = {partner_id: tryParseInt(organization.id)} + } + await metadata.addPublicMetadata(() => ({ - partner_id: tryParseInt(app.organizationId), + ...organizationInfo, api_key: app.apiKey, cmd_app_reset_used: resetUsed, })) diff --git a/packages/cli-kit/src/public/node/monorail.ts b/packages/cli-kit/src/public/node/monorail.ts index 6f79d6b1289..0af299b8acb 100644 --- a/packages/cli-kit/src/public/node/monorail.ts +++ b/packages/cli-kit/src/public/node/monorail.ts @@ -29,6 +29,7 @@ export interface Schemas { env_plugin_installed_all?: Optional } public: { + business_platform_id?: Optional partner_id?: Optional command: string project_type?: Optional diff --git a/packages/cli-kit/src/public/node/plugins.ts b/packages/cli-kit/src/public/node/plugins.ts index 1e9eb99c3db..d8752d2617a 100644 --- a/packages/cli-kit/src/public/node/plugins.ts +++ b/packages/cli-kit/src/public/node/plugins.ts @@ -28,7 +28,11 @@ export async function fanoutHooks [plugin.name, result])) as any } -type AppSpecificMonorailFields = PickByPrefix & +type AppSpecificMonorailFields = PickByPrefix< + MonorailEventPublic, + 'app_', + 'project_type' | 'api_key' | 'partner_id' | 'business_platform_id' +> & PickByPrefix & PickByPrefix