From 7f0817a1fc1316fbfd8365af6c21174f6e4363e8 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Tue, 8 Oct 2024 15:12:39 -0700 Subject: [PATCH 1/4] Add app/version useragent for tracking clients in runtime --- src/commands/app/deploy.js | 1 + src/commands/app/run.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/commands/app/deploy.js b/src/commands/app/deploy.js index ac495500..7ee052f5 100644 --- a/src/commands/app/deploy.js +++ b/src/commands/app/deploy.js @@ -30,6 +30,7 @@ class Deploy extends BuildCommand { // cli input const { flags } = await this.parse(Deploy) + process.env.__OW_USER_AGENT = 'aio-cli-plugin-app@' + require('../../../package.json').version // flags flags['web-assets'] = flags['web-assets'] && !flags.action flags.publish = flags.publish && !flags.action diff --git a/src/commands/app/run.js b/src/commands/app/run.js index f48c65cb..767aa10b 100644 --- a/src/commands/app/run.js +++ b/src/commands/app/run.js @@ -36,6 +36,7 @@ class Run extends BaseCommand { // cli input const { flags } = await this.parse(Run) + process.env.__OW_USER_AGENT = 'aio-cli-plugin-app@' + require('../../../package.json').version if (flags.local) { const [firstCpu] = os.cpus() // note: the earliest versions of M1 macs return 'Apple processor' under model. From cf4a4587490ed84d47fd6483989e5e0e19550ad4 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Tue, 8 Oct 2024 17:47:30 -0700 Subject: [PATCH 2/4] one ring to rule them all --- src/BaseCommand.js | 2 ++ src/commands/app/deploy.js | 1 - src/commands/app/run.js | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BaseCommand.js b/src/BaseCommand.js index 9a8e18cb..529ee3fa 100644 --- a/src/BaseCommand.js +++ b/src/BaseCommand.js @@ -31,6 +31,7 @@ const { } = require('@adobe/aio-lib-env') class BaseCommand extends Command { + // default error handler for app commands async catch (error) { const { flags } = await this.parse(this.prototype) @@ -42,6 +43,7 @@ class BaseCommand extends Command { await super.init() // setup a prompt that outputs to stderr this.prompt = inquirer.createPromptModule({ output: process.stderr }) + process.env.__OW_USER_AGENT = 'aio-cli-plugin-app@' + require('../package.json').version } async getLibConsoleCLI () { diff --git a/src/commands/app/deploy.js b/src/commands/app/deploy.js index 0d9f50f1..7781f11a 100644 --- a/src/commands/app/deploy.js +++ b/src/commands/app/deploy.js @@ -31,7 +31,6 @@ class Deploy extends BuildCommand { // cli input const { flags } = await this.parse(Deploy) - process.env.__OW_USER_AGENT = 'aio-cli-plugin-app@' + require('../../../package.json').version // flags flags['web-assets'] = flags['web-assets'] && !flags.action flags.publish = flags.publish && !flags.action diff --git a/src/commands/app/run.js b/src/commands/app/run.js index 767aa10b..f48c65cb 100644 --- a/src/commands/app/run.js +++ b/src/commands/app/run.js @@ -36,7 +36,6 @@ class Run extends BaseCommand { // cli input const { flags } = await this.parse(Run) - process.env.__OW_USER_AGENT = 'aio-cli-plugin-app@' + require('../../../package.json').version if (flags.local) { const [firstCpu] = os.cpus() // note: the earliest versions of M1 macs return 'Apple processor' under model. From cff72bc8534195cdba45f07618ed453f265537f9 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Tue, 8 Oct 2024 18:33:19 -0700 Subject: [PATCH 3/4] I never get tired of being held up by silly linting rules protecting whitespace. --- src/BaseCommand.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BaseCommand.js b/src/BaseCommand.js index 529ee3fa..e66c43c7 100644 --- a/src/BaseCommand.js +++ b/src/BaseCommand.js @@ -31,7 +31,6 @@ const { } = require('@adobe/aio-lib-env') class BaseCommand extends Command { - // default error handler for app commands async catch (error) { const { flags } = await this.parse(this.prototype) From 16cc2318e415a240b35169fd598f7663eb25a237 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Fri, 8 Nov 2024 16:47:17 -0800 Subject: [PATCH 4/4] generate realish useragent with more info --- src/BaseCommand.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BaseCommand.js b/src/BaseCommand.js index e66c43c7..d7835404 100644 --- a/src/BaseCommand.js +++ b/src/BaseCommand.js @@ -42,7 +42,13 @@ class BaseCommand extends Command { await super.init() // setup a prompt that outputs to stderr this.prompt = inquirer.createPromptModule({ output: process.stderr }) - process.env.__OW_USER_AGENT = 'aio-cli-plugin-app@' + require('../package.json').version + + // set User-Agent for runtime calls + // ex. aio-cli-plugin-app/@adobe/aio-cli/10.3.1 (darwin-arm64; node-v18.20.4; zsh) + const vs = this.config.versionDetails + // some tests might not have this set, so we use ? nullish coalescing + process.env.__OW_USER_AGENT = + `aio-cli-plugin-app/${vs?.cliVersion} (${vs?.architecture}; ${vs?.nodeVersion}; ${vs?.shell})` } async getLibConsoleCLI () {