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
3 changes: 2 additions & 1 deletion packages/app/src/cli/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_extensions_'
PickByPrefix<MonorailEventPublic, 'cmd_release_'> &
PickByPrefix<MonorailEventPublic, 'app_'> &
PickByPrefix<MonorailEventPublic, 'env_'> &
PickByPrefix<MonorailEventPublic, 'store_'>
PickByPrefix<MonorailEventPublic, 'store_'> &
Pick<MonorailEventPublic, 'shop_domain'>

type CmdSensitiveFieldsFromMonorail = PickByPrefix<MonorailEventSensitive, 'app_'> &
PickByPrefix<MonorailEventSensitive, 'cmd_dev_'> &
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/cli/services/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ async function logMetadataForDev(options: {
cmd_dev_tunnel_custom_hash: tunnelType === 'custom' ? hashString(options.tunnelUrl) : undefined,
cmd_dev_urls_updated: options.shouldUpdateURLs,
store_fqdn_hash: hashString(options.storeFqdn),
shop_domain: options.storeFqdn,
cmd_app_dependency_installation_skipped: options.devOptions.skipDependenciesInstallation,
}))

Expand Down
26 changes: 26 additions & 0 deletions packages/app/src/cli/services/store-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ describe('storeContext', () => {
expect(meta).toEqual(
expect.objectContaining({
store_fqdn_hash: hashString(mockStore.shopDomain),
shop_domain: mockStore.shopDomain,
}),
)

Expand All @@ -186,6 +187,31 @@ describe('storeContext', () => {
})
})

test('normalizes the selected store before logging metadata', async () => {
await inTemporaryDirectory(async (dir) => {
const unnormalizedStore = testOrganizationStore({shopId: 'store1', shopDomain: 'test-store'})
vi.mocked(fetchStore).mockResolvedValue(unnormalizedStore)
await prepareAppFolder(mockApp, dir)

await storeContext({appContextResult, forceReselectStore: false})

const meta = metadata.getAllPublicMetadata()
expect(meta).toEqual(
expect.objectContaining({
store_fqdn_hash: hashString('test-store.myshopify.com'),
shop_domain: 'test-store.myshopify.com',
}),
)

const sensitiveMeta = metadata.getAllSensitiveMetadata()
expect(sensitiveMeta).toEqual(
expect.objectContaining({
store_fqdn: 'test-store.myshopify.com',
}),
)
})
})

test('adds hidden config to gitignore if needed', async () => {
await inTemporaryDirectory(async (dir) => {
await prepareAppFolder(mockApp, dir)
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/services/store-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export async function storeContext({
selectedStore = await selectStore(allStores, organization, developerPlatformClient)
}

await logMetadata(selectedStore, forceReselectStore)
selectedStore.shopDomain = normalizeStoreFqdn(selectedStore.shopDomain)
await logMetadata(selectedStore, forceReselectStore)

// Save the selected store in the hidden config file
if (selectedStore.shopDomain !== cachedStoreURL || !devStoreUrlFromHiddenConfig) {
Expand All @@ -82,6 +82,7 @@ async function logMetadata(selectedStore: OrganizationStore, resetUsed: boolean)
await metadata.addPublicMetadata(() => ({
cmd_app_reset_used: resetUsed,
store_fqdn_hash: hashString(selectedStore.shopDomain),
shop_domain: selectedStore.shopDomain,
}))

await metadata.addSensitiveMetadata(() => ({
Expand Down
1 change: 1 addition & 0 deletions packages/cli-kit/src/public/node/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ type CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_all_'> &
PickByPrefix<MonorailEventPublic, 'cmd_create_app_'> &
PickByPrefix<MonorailEventPublic, 'cmd_theme_'> &
PickByPrefix<MonorailEventPublic, 'store_'> &
Pick<MonorailEventPublic, 'shop_domain'> &
PickByPrefix<MonorailEventPublic, 'env_auto_upgrade_'>

const coreData = createRuntimeMetadataContainer<
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-kit/src/public/node/monorail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('monorail', () => {
user_id: '42',
store_fqdn_hash: 'hashed-store',
store_fqdn_validated: true,
shop_domain: 'shop.myshopify.com',
},
{
args: '--store shop.myshopify.com',
Expand Down Expand Up @@ -98,6 +99,7 @@ describe('monorail', () => {
user_id: '42',
store_fqdn_hash: 'hashed-store',
store_fqdn_validated: true,
shop_domain: 'shop.myshopify.com',
args: '--store shop.myshopify.com',
store_fqdn: 'shop.myshopify.com',
},
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-kit/src/public/node/monorail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const url = 'https://monorail-edge.shopifysvc.com/v1/produce'
type Optional<T> = T | null

// This is the topic name of the main event we log to Monorail, the command tracker
export const MONORAIL_COMMAND_TOPIC = 'app_cli3_command/1.24'
export const MONORAIL_COMMAND_TOPIC = 'app_cli3_command/1.25'

export interface Schemas {
[MONORAIL_COMMAND_TOPIC]: {
Expand Down Expand Up @@ -46,6 +46,7 @@ export interface Schemas {
is_employee: boolean
store_fqdn_hash?: Optional<string>
store_fqdn_validated?: Optional<boolean>
shop_domain?: Optional<string>
user_id: string

// Any and all commands
Expand Down
4 changes: 3 additions & 1 deletion packages/store/src/cli/services/store/attribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('store command attribution', () => {
vi.mocked(hashString).mockReturnValue('hashed-store')
})

test('records the sensitive, hashed, and validation state for a store fqdn', async () => {
test('records the sensitive, hashed, validation, and public shop domain for a store fqdn', async () => {
await recordStoreFqdnMetadata('shop.myshopify.com', true)

expect(addSensitiveMetadata).toHaveBeenCalledWith(expect.any(Function))
Expand All @@ -21,7 +21,9 @@ describe('store command attribution', () => {
expect(vi.mocked(addPublicMetadata).mock.calls[0]![0]()).toEqual({
store_fqdn_hash: 'hashed-store',
store_fqdn_validated: true,
shop_domain: 'shop.myshopify.com',
})
expect(hashString).toHaveBeenCalledWith('shop.myshopify.com')
})

})
6 changes: 5 additions & 1 deletion packages/store/src/cli/services/store/attribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ import {addPublicMetadata, addSensitiveMetadata} from '@shopify/cli-kit/node/met

export async function recordStoreFqdnMetadata(storeFqdn: string, validated: boolean): Promise<void> {
await addSensitiveMetadata(() => ({store_fqdn: storeFqdn}))
await addPublicMetadata(() => ({store_fqdn_hash: hashString(storeFqdn), store_fqdn_validated: validated}))
await addPublicMetadata(() => ({
store_fqdn_hash: hashString(storeFqdn),
store_fqdn_validated: validated,
shop_domain: storeFqdn,
}))
}
1 change: 1 addition & 0 deletions packages/theme/src/cli/utilities/theme-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export default abstract class ThemeCommand extends Command {
const data = compileData()
await addPublicMetadata(() => ({
store_fqdn_hash: hashString(session.storeFqdn),
shop_domain: session.storeFqdn,

cmd_theme_timings: JSON.stringify(data.timings),
cmd_theme_errors: JSON.stringify(data.errors),
Expand Down
Loading