Skip to content

Commit

Permalink
Report business platform ID instead of partner ID when relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
amcaplan committed Dec 22, 2024
1 parent 27fceb7 commit 39bfdc6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/app/src/cli/models/app/app.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -176,6 +177,7 @@ export function testOrganization(): Organization {
return {
id: '1',
businessName: 'org1',
source: OrganizationSource.BusinessPlatform,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/cli/services/app-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
15 changes: 11 additions & 4 deletions packages/app/src/cli/services/app-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
}))
Expand Down
1 change: 1 addition & 0 deletions packages/cli-kit/src/public/node/monorail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface Schemas {
env_plugin_installed_all?: Optional<string>
}
public: {
business_platform_id?: Optional<number>
partner_id?: Optional<number>
command: string
project_type?: Optional<string>
Expand Down
6 changes: 5 additions & 1 deletion packages/cli-kit/src/public/node/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export async function fanoutHooks<TPluginMap extends HookReturnsPerPlugin, TEven
return Object.fromEntries(res.successes.map(({result, plugin}) => [plugin.name, result])) as any
}

type AppSpecificMonorailFields = PickByPrefix<MonorailEventPublic, 'app_', 'project_type' | 'api_key' | 'partner_id'> &
type AppSpecificMonorailFields = PickByPrefix<
MonorailEventPublic,
'app_',
'project_type' | 'api_key' | 'partner_id' | 'business_platform_id'
> &
PickByPrefix<MonorailEventPublic, 'cmd_extensions_'> &
PickByPrefix<MonorailEventPublic, 'cmd_scaffold_'>

Expand Down

0 comments on commit 39bfdc6

Please sign in to comment.