Skip to content

Commit e17bd88

Browse files
committed
adding all SHOPIFY_ prefixed environment variables to monorail
1 parent 8ce1f05 commit e17bd88

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

packages/app/src/cli/commands/app/function/run.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ export default class FunctionRun extends AppUnlinkedCommand {
3333
description: 'Name of the WebAssembly export to invoke.',
3434
env: 'SHOPIFY_FLAG_EXPORT',
3535
}),
36-
'invoked-by': Flags.string({
37-
char: 'b',
38-
hidden: true,
39-
description: 'The client that invoked this command.',
40-
env: 'SHOPIFY_FLAG_INVOKED_BY',
41-
}),
4236
}
4337

4438
public async run(): Promise<AppUnlinkedCommandOutput> {

packages/cli-kit/src/private/node/analytics.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,20 @@ export async function getEnvironmentData(config: Interfaces.Config): Promise<Env
9797
export async function getSensitiveEnvironmentData(config: Interfaces.Config) {
9898
return {
9999
env_plugin_installed_all: JSON.stringify(getPluginNames(config)),
100+
env_shopify_variables: JSON.stringify(Object.fromEntries(getShopifyEnvironmentVariables())),
100101
}
101102
}
102103

104+
function getShopifyEnvironmentVariables() {
105+
const shopifyEnvVars = new Map<string, string>()
106+
for (const [key, value] of Object.entries(process.env)) {
107+
if (key.startsWith('SHOPIFY_') && value !== undefined) {
108+
shopifyEnvVars.set(key, value)
109+
}
110+
}
111+
return shopifyEnvVars
112+
}
113+
103114
function getPluginNames(config: Interfaces.Config) {
104115
const pluginNames = [...config.plugins.keys()]
105116
return pluginNames.sort().filter((plugin) => !plugin.startsWith('@oclif/'))

packages/cli-kit/src/public/node/analytics.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,36 @@ describe('event tracking', () => {
185185
})
186186
})
187187

188+
test('sends SHOPIFY_ environment variables in sensitive payload', async () => {
189+
const originalEnv = {...process.env}
190+
process.env.SHOPIFY_TEST_VAR = 'test_value'
191+
process.env.SHOPIFY_ANOTHER_VAR = 'another_value'
192+
process.env.NOT_SHOPIFY_VAR = 'should_not_appear'
193+
194+
await inProjectWithFile('package.json', async (args) => {
195+
const commandContent = {command: 'dev', topic: 'app'}
196+
await startAnalytics({commandContent, args, currentTime: currentDate.getTime() - 100})
197+
198+
// When
199+
const config = {
200+
runHook: vi.fn().mockResolvedValue({successes: [], failures: []}),
201+
plugins: [],
202+
} as any
203+
await reportAnalyticsEvent({config, exitMode: 'ok'})
204+
205+
// Then
206+
const sensitivePayload = publishEventMock.mock.calls[0]![2]
207+
expect(publishEventMock).toHaveBeenCalledOnce()
208+
expect(sensitivePayload).toHaveProperty('env_shopify_variables')
209+
expect(sensitivePayload.env_shopify_variables).toBeDefined()
210+
211+
const shopifyVars = JSON.parse(sensitivePayload.env_shopify_variables as string)
212+
expect(shopifyVars).toHaveProperty('SHOPIFY_TEST_VAR', 'test_value')
213+
expect(shopifyVars).toHaveProperty('SHOPIFY_ANOTHER_VAR', 'another_value')
214+
expect(shopifyVars).not.toHaveProperty('NOT_SHOPIFY_VAR')
215+
})
216+
})
217+
188218
test('does nothing when analytics are disabled', async () => {
189219
await inProjectWithFile('package.json', async (args) => {
190220
// Given

packages/cli-kit/src/public/node/monorail.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface Schemas {
2727

2828
// Environment
2929
env_plugin_installed_all?: Optional<string>
30+
env_shopify_variables?: Optional<string>
3031
}
3132
public: {
3233
business_platform_id?: Optional<number>

0 commit comments

Comments
 (0)