@shopify/cli-kit 3.90.0 → 3.91.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/private/node/constants.d.ts +1 -1
- package/dist/private/node/constants.js +1 -1
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/otel-metrics.js +4 -1
- package/dist/private/node/otel-metrics.js.map +1 -1
- package/dist/public/common/string.d.ts +7 -0
- package/dist/public/common/string.js +10 -1
- package/dist/public/common/string.js.map +1 -1
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/analytics.js +2 -0
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/context/fqdn.d.ts +8 -0
- package/dist/public/node/context/fqdn.js +14 -0
- package/dist/public/node/context/fqdn.js.map +1 -1
- package/dist/public/node/context/local.d.ts +3 -3
- package/dist/public/node/context/local.js +4 -4
- package/dist/public/node/context/local.js.map +1 -1
- package/dist/public/node/doctor/framework.d.ts +162 -0
- package/dist/public/node/doctor/framework.js +355 -0
- package/dist/public/node/doctor/framework.js.map +1 -0
- package/dist/public/node/doctor/reporter.d.ts +10 -0
- package/dist/public/node/doctor/reporter.js +90 -0
- package/dist/public/node/doctor/reporter.js.map +1 -0
- package/dist/public/node/doctor/types.d.ts +21 -0
- package/dist/public/node/doctor/types.js +2 -0
- package/dist/public/node/doctor/types.js.map +1 -0
- package/dist/public/node/error-handler.js +5 -1
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/system.d.ts +54 -0
- package/dist/public/node/system.js +146 -2
- package/dist/public/node/system.js.map +1 -1
- package/dist/public/node/themes/api.js +0 -1
- package/dist/public/node/themes/api.js.map +1 -1
- package/dist/public/node/themes/types.d.ts +2 -1
- package/dist/public/node/themes/types.js.map +1 -1
- package/dist/public/node/ui.js +3 -0
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/vendor/otel-js/export/InstantaneousMetricReader.js +5 -7
- package/dist/public/node/vendor/otel-js/export/InstantaneousMetricReader.js.map +1 -1
- package/dist/public/node/vendor/otel-js/utils/throttle.js +6 -0
- package/dist/public/node/vendor/otel-js/utils/throttle.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -3,10 +3,10 @@ export declare const environmentVariables: {
|
|
|
3
3
|
alwaysLogAnalytics: string;
|
|
4
4
|
alwaysLogMetrics: string;
|
|
5
5
|
deviceAuth: string;
|
|
6
|
+
doctor: string;
|
|
6
7
|
enableCliRedirect: string;
|
|
7
8
|
env: string;
|
|
8
9
|
firstPartyDev: string;
|
|
9
|
-
skipLocalDevConsole: string;
|
|
10
10
|
noAnalytics: string;
|
|
11
11
|
partnersToken: string;
|
|
12
12
|
runAsUser: string;
|
|
@@ -13,10 +13,10 @@ export const environmentVariables = {
|
|
|
13
13
|
alwaysLogAnalytics: 'SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS',
|
|
14
14
|
alwaysLogMetrics: 'SHOPIFY_CLI_ALWAYS_LOG_METRICS',
|
|
15
15
|
deviceAuth: 'SHOPIFY_CLI_DEVICE_AUTH',
|
|
16
|
+
doctor: 'SHOPIFY_CLI_DOCTOR',
|
|
16
17
|
enableCliRedirect: 'SHOPIFY_CLI_ENABLE_CLI_REDIRECT',
|
|
17
18
|
env: 'SHOPIFY_CLI_ENV',
|
|
18
19
|
firstPartyDev: 'SHOPIFY_CLI_1P_DEV',
|
|
19
|
-
skipLocalDevConsole: 'SHOPIFY_SKIP_LOCAL_DEV_CONSOLE',
|
|
20
20
|
noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS',
|
|
21
21
|
partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN',
|
|
22
22
|
runAsUser: 'SHOPIFY_RUN_AS_USER',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/private/node/constants.ts"],"names":[],"mappings":"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AI,EAAE,GAAG,EAAE;oBACT,OAAO,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAA;gBAC1C,CAAC;gBACD,QAAQ,EAAE,GAAG,EAAE;oBACb,OAAO,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;gBACtD,CAAC;aACF;SACF;KACF;CACF,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,6BAA6B,EAAE,CAAC;CACjC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,kCAAkC,CAAA;AAE/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAC,IAAI,EAAE,CAAC,EAAC,EAAC,CAAA;AAElE,MAAM,CAAC,MAAM,oBAAoB,GAC/B,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,IAAI,2BAA2B,CAAA","sourcesContent":["import {joinPath} from '../../public/node/path.js'\nimport envPaths from 'env-paths'\n\nconst identifier = 'shopify-cli'\n\nconst cacheFolder = () => {\n if (process.env.XDG_CACHE_HOME) return process.env.XDG_CACHE_HOME\n return envPaths(identifier).cache\n}\n\nexport const logsFolder = () => {\n return envPaths(identifier).log\n}\n\nexport const environmentVariables = {\n alwaysLogAnalytics: 'SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS',\n alwaysLogMetrics: 'SHOPIFY_CLI_ALWAYS_LOG_METRICS',\n deviceAuth: 'SHOPIFY_CLI_DEVICE_AUTH',\n doctor: 'SHOPIFY_CLI_DOCTOR',\n enableCliRedirect: 'SHOPIFY_CLI_ENABLE_CLI_REDIRECT',\n env: 'SHOPIFY_CLI_ENV',\n firstPartyDev: 'SHOPIFY_CLI_1P_DEV',\n noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS',\n partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN',\n runAsUser: 'SHOPIFY_RUN_AS_USER',\n serviceEnv: 'SHOPIFY_SERVICE_ENV',\n skipCliRedirect: 'SHOPIFY_CLI_SKIP_CLI_REDIRECT',\n spinInstance: 'SPIN_INSTANCE',\n themeToken: 'SHOPIFY_CLI_THEME_TOKEN',\n unitTest: 'SHOPIFY_UNIT_TEST',\n verbose: 'SHOPIFY_FLAG_VERBOSE',\n // Variables to detect if the CLI is running in a cloud environment\n codespaces: 'CODESPACES',\n codespaceName: 'CODESPACE_NAME',\n codespacePortForwardingDomain: 'GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN',\n gitpod: 'GITPOD_WORKSPACE_URL',\n cloudShell: 'CLOUD_SHELL',\n spinAppPort: 'SERVER_PORT',\n spinAppHost: 'SPIN_APP_HOST',\n organization: 'SHOPIFY_CLI_ORGANIZATION',\n identityToken: 'SHOPIFY_CLI_IDENTITY_TOKEN',\n refreshToken: 'SHOPIFY_CLI_REFRESH_TOKEN',\n otelURL: 'SHOPIFY_CLI_OTEL_EXPORTER_OTLP_ENDPOINT',\n themeKitAccessDomain: 'SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN',\n json: 'SHOPIFY_FLAG_JSON',\n neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API',\n skipNetworkLevelRetry: 'SHOPIFY_CLI_SKIP_NETWORK_LEVEL_RETRY',\n maxRequestTimeForNetworkCalls: 'SHOPIFY_CLI_MAX_REQUEST_TIME_FOR_NETWORK_CALLS',\n}\n\nexport const defaultThemeKitAccessDomain = 'theme-kit-access.shopifyapps.com'\n\nexport const systemEnvironmentVariables = {\n backendPort: 'BACKEND_PORT',\n}\n\nexport const pathConstants = {\n executables: {\n dev: '/opt/dev/bin/dev',\n },\n directories: {\n cache: {\n path: () => {\n return cacheFolder()\n },\n vendor: {\n path: () => {\n return joinPath(cacheFolder(), 'vendor')\n },\n binaries: () => {\n return joinPath(cacheFolder(), 'vendor', 'binaries')\n },\n },\n },\n },\n}\n\nexport const sessionConstants = {\n expirationTimeMarginInMinutes: 4,\n}\n\nexport const bugsnagApiKey = '9e1e6889176fd0c795d5c659225e0fae'\n\nexport const reportingRateLimit = {limit: 300, timeout: {days: 1}}\n\nexport const themeKitAccessDomain =\n process.env[environmentVariables.themeKitAccessDomain] ?? defaultThemeKitAccessDomain\n"]}
|
|
@@ -2,7 +2,7 @@ import { MetricInstrumentType } from '../../public/node/vendor/otel-js/service/t
|
|
|
2
2
|
import { outputContent, outputDebug, outputToken } from '../../public/node/output.js';
|
|
3
3
|
import { DefaultOtelService, } from '../../public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.js';
|
|
4
4
|
import { isUnitTest, opentelemetryDomain } from '../../public/node/context/local.js';
|
|
5
|
-
import { ValueType } from '@opentelemetry/api';
|
|
5
|
+
import { ValueType, diag } from '@opentelemetry/api';
|
|
6
6
|
var Name;
|
|
7
7
|
(function (Name) {
|
|
8
8
|
Name["Counter"] = "cli_commands_total";
|
|
@@ -94,6 +94,9 @@ function globalOtelService(options) {
|
|
|
94
94
|
env: undefined,
|
|
95
95
|
otelEndpoint: `${opentelemetryDomain()}/v1/metrics`,
|
|
96
96
|
});
|
|
97
|
+
// Suppress OTEL diagnostic output — internal export errors (e.g. retryable failures)
|
|
98
|
+
// should never appear in user-facing CLI output.
|
|
99
|
+
diag.disable();
|
|
97
100
|
}
|
|
98
101
|
return _otelService;
|
|
99
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-metrics.js","sourceRoot":"","sources":["../../../src/private/node/otel-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAc,MAAM,mDAAmD,CAAA;AACnG,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,EACL,kBAAkB,GAEnB,MAAM,mFAAmF,CAAA;AAC1F,OAAO,EAAC,UAAU,EAAE,mBAAmB,EAAC,MAAM,oCAAoC,CAAA;AAClF,OAAO,EAAC,SAA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C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC1D,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,EAAC,GAAG,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAC,CAAC,CAAA;IACjF,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAAC,GAAG,MAAM,EAAE,KAAK,EAAE,SAAS,EAAC,CAAC,CAAA;IACnF,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,EAAC,GAAG,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAC,CAAC,CAAA;IACjF,CAAC;AACH,CAAC","sourcesContent":["import {MetricInstrumentType, OtelService} from '../../public/node/vendor/otel-js/service/types.js'\nimport {outputContent, outputDebug, outputToken} from '../../public/node/output.js'\nimport {\n DefaultOtelService,\n DefaultOtelServiceOptions,\n} from '../../public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.js'\nimport {isUnitTest, opentelemetryDomain} from '../../public/node/context/local.js'\nimport {ValueType} from '@opentelemetry/api'\n\ntype MetricRecorder =\n | 'console'\n | {\n type: 'otel'\n otel: Pick<OtelService, 'record'>\n }\n\n// this should be type, not interface\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ntype Labels = {\n exit: string\n job: string\n cli_version: string\n}\n\ninterface Timing {\n active: number\n network: number\n prompt: number\n}\n\nenum Name {\n Counter = 'cli_commands_total',\n Duration = 'cli_commands_duration_ms',\n Elapsed = 'cli_commands_wall_clock_elapsed_ms',\n}\n\ninterface CreateMetricRecorderOptions {\n skipMetricAnalytics: boolean\n otelOptions: Omit<DefaultOtelServiceOptions, 'env' | 'otelEndpoint'>\n}\n\ninterface RecordMetricsOptions {\n /** If true, don't log anything */\n skipMetricAnalytics: boolean\n /** The CLI version running the command */\n cliVersion: string\n /** The plug-in that owns the command */\n owningPlugin: string\n /** The command name, e.g. `app dev` */\n command: string\n /** The exit mode for the command */\n exitMode: string\n}\n\n/**\n * Record reliability metrics.\n */\nexport async function recordMetrics(\n options: RecordMetricsOptions,\n timing: Timing,\n recorderFactory: (options: CreateMetricRecorderOptions) => MetricRecorder = createMetricRecorder,\n) {\n const recorder = recorderFactory({\n skipMetricAnalytics: options.skipMetricAnalytics,\n otelOptions: defaultOtelOptions(),\n })\n\n let regularisedCliVersion = options.cliVersion\n\n if (options.cliVersion.includes('nightly')) {\n regularisedCliVersion = 'nightly'\n } else if (options.cliVersion.includes('pre')) {\n regularisedCliVersion = 'pre'\n }\n const labels = {\n exit: options.exitMode,\n job: `${options.owningPlugin}::${options.command}`,\n cli_version: regularisedCliVersion,\n }\n\n recordCommandCounter(recorder, labels)\n recordCommandTiming(recorder, labels, timing)\n}\n\nconst COMMAND_DURATION_BOUNDARIES_MS = [\n 0, 100, 200, 300, 500, 750, 1000, 1500, 2000, 3000, 5000, 7500, 10_000, 15_000, 20_000, 30_000, 50_000, 70_000,\n 85_000, 100_000,\n]\n\n/**\n * Get the default options for the OTEL service. These are the same across environments.\n */\nfunction defaultOtelOptions(): Omit<DefaultOtelServiceOptions, 'env' | 'otelEndpoint'> {\n return {\n serviceName: 'shopify-cli',\n throttleLimit: 1000,\n prefixMetric: false,\n metrics: {\n [Name.Counter]: {\n type: MetricInstrumentType.Counter,\n description: 'Total number of CLI commands executed',\n valueType: ValueType.INT,\n },\n [Name.Duration]: {\n type: MetricInstrumentType.Histogram,\n description:\n 'Total time spent in execution of CLI commands. Does not include time spent waiting for network, prompts, etc.',\n valueType: ValueType.INT,\n boundaries: COMMAND_DURATION_BOUNDARIES_MS,\n },\n [Name.Elapsed]: {\n type: MetricInstrumentType.Histogram,\n description:\n 'Total time elapsed from start to finish of CLI commands. Includes time spent waiting for network, prompts, etc.',\n valueType: ValueType.INT,\n boundaries: COMMAND_DURATION_BOUNDARIES_MS,\n },\n },\n }\n}\n\n/**\n * Create the metric recorder for this command.\n *\n * If metric logging is disabled, or we are running in a unit test, we record to the console.\n *\n */\nfunction createMetricRecorder(options: CreateMetricRecorderOptions): MetricRecorder {\n let recorder: MetricRecorder = 'console'\n if (!(options.skipMetricAnalytics || isUnitTest())) {\n recorder = {\n type: 'otel',\n otel: globalOtelService(options),\n }\n }\n return recorder\n}\n\nlet _otelService: OtelService | undefined\n\n/**\n * OTEL service singleton.\n *\n * The service is a singleton as it uses a global diagnostic logger that assumes its the only one in the process.\n */\nfunction globalOtelService(options: CreateMetricRecorderOptions): OtelService {\n if (!_otelService) {\n _otelService = new DefaultOtelService({\n ...options.otelOptions,\n env: undefined,\n otelEndpoint: `${opentelemetryDomain()}/v1/metrics`,\n })\n }\n return _otelService\n}\n\n/**\n * Log command counter metrics.\n */\nfunction recordCommandCounter(recorder: MetricRecorder, labels: Labels) {\n if (recorder === 'console') {\n outputDebug(outputContent`[OTEL] record ${Name.Counter} counter ${outputToken.json({labels})}`)\n return\n }\n recorder.otel.record(Name.Counter, 1, labels)\n}\n\n/**\n * Log command timing metrics.\n */\nfunction recordCommandTiming(recorder: MetricRecorder, labels: Labels, timing: Timing) {\n if (recorder === 'console') {\n outputDebug(\n outputContent`[OTEL] record ${Name.Duration} histogram ${timing.active.toString()}ms ${outputToken.json({\n labels,\n })}`,\n )\n outputDebug(outputContent`[OTEL] record ${Name.Elapsed} histogram stage=\"active\" ${timing.active.toString()}ms`)\n outputDebug(outputContent`[OTEL] record ${Name.Elapsed} histogram stage=\"network\" ${timing.network.toString()}ms`)\n outputDebug(outputContent`[OTEL] record ${Name.Elapsed} histogram stage=\"prompt\" ${timing.prompt.toString()}ms`)\n return\n }\n\n if (timing.active > 0) {\n recorder.otel.record(Name.Duration, timing.active, labels)\n recorder.otel.record(Name.Elapsed, timing.active, {...labels, stage: 'active'})\n }\n if (timing.network > 0) {\n recorder.otel.record(Name.Elapsed, timing.network, {...labels, stage: 'network'})\n }\n if (timing.prompt > 0) {\n recorder.otel.record(Name.Elapsed, timing.prompt, {...labels, stage: 'prompt'})\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"otel-metrics.js","sourceRoot":"","sources":["../../../src/private/node/otel-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAc,MAAM,mDAAmD,CAAA;AACnG,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,EACL,kBAAkB,GAEnB,MAAM,mFAAmF,CAAA;AAC1F,OAAO,EAAC,UAAU,EAAE,mBAAmB,EAAC,MAAM,oCAAoC,CAAA;AAClF,OAAO,EAAC,SAAS,EAAE,IAAI,EAAC,MAAM,oBAAoB,CAAA;AAuBlD,IAAK,IAIJ;AAJD,WAAK,IAAI;IACP,sCAA8B,CAAA;IAC9B,6CAAqC,CAAA;IACrC,sDAA8C,CAAA;AAChD,CAAC,EAJI,IAAI,KAAJ,IAAI,QAIR;AAoBD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA6B,EAC7B,MAAc,EACd,kBAA4E,oBAAoB;IAEhG,MAAM,QAAQ,GAAG,eAAe,CAAC;QAC/B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;QAChD,WAAW,EAAE,kBAAkB,EAAE;KAClC,CAAC,CAAA;IAEF,IAAI,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAA;IAE9C,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3C,qBAAqB,GAAG,SAAS,CAAA;IACnC,CAAC;SAAM,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,E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,MAAM,EAAE,EAAC,GAAG,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAC,CAAC,CAAA;IACjF,CAAC;AACH,CAAC","sourcesContent":["import {MetricInstrumentType, OtelService} from '../../public/node/vendor/otel-js/service/types.js'\nimport {outputContent, outputDebug, outputToken} from '../../public/node/output.js'\nimport {\n DefaultOtelService,\n DefaultOtelServiceOptions,\n} from '../../public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.js'\nimport {isUnitTest, opentelemetryDomain} from '../../public/node/context/local.js'\nimport {ValueType, diag} from '@opentelemetry/api'\n\ntype MetricRecorder =\n | 'console'\n | {\n type: 'otel'\n otel: Pick<OtelService, 'record'>\n }\n\n// this should be type, not interface\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ntype Labels = {\n exit: string\n job: string\n cli_version: string\n}\n\ninterface Timing {\n active: number\n network: number\n prompt: number\n}\n\nenum Name {\n Counter = 'cli_commands_total',\n Duration = 'cli_commands_duration_ms',\n Elapsed = 'cli_commands_wall_clock_elapsed_ms',\n}\n\ninterface CreateMetricRecorderOptions {\n skipMetricAnalytics: boolean\n otelOptions: Omit<DefaultOtelServiceOptions, 'env' | 'otelEndpoint'>\n}\n\ninterface RecordMetricsOptions {\n /** If true, don't log anything */\n skipMetricAnalytics: boolean\n /** The CLI version running the command */\n cliVersion: string\n /** The plug-in that owns the command */\n owningPlugin: string\n /** The command name, e.g. `app dev` */\n command: string\n /** The exit mode for the command */\n exitMode: string\n}\n\n/**\n * Record reliability metrics.\n */\nexport async function recordMetrics(\n options: RecordMetricsOptions,\n timing: Timing,\n recorderFactory: (options: CreateMetricRecorderOptions) => MetricRecorder = createMetricRecorder,\n) {\n const recorder = recorderFactory({\n skipMetricAnalytics: options.skipMetricAnalytics,\n otelOptions: defaultOtelOptions(),\n })\n\n let regularisedCliVersion = options.cliVersion\n\n if (options.cliVersion.includes('nightly')) {\n regularisedCliVersion = 'nightly'\n } else if (options.cliVersion.includes('pre')) {\n regularisedCliVersion = 'pre'\n }\n const labels = {\n exit: options.exitMode,\n job: `${options.owningPlugin}::${options.command}`,\n cli_version: regularisedCliVersion,\n }\n\n recordCommandCounter(recorder, labels)\n recordCommandTiming(recorder, labels, timing)\n}\n\nconst COMMAND_DURATION_BOUNDARIES_MS = [\n 0, 100, 200, 300, 500, 750, 1000, 1500, 2000, 3000, 5000, 7500, 10_000, 15_000, 20_000, 30_000, 50_000, 70_000,\n 85_000, 100_000,\n]\n\n/**\n * Get the default options for the OTEL service. These are the same across environments.\n */\nfunction defaultOtelOptions(): Omit<DefaultOtelServiceOptions, 'env' | 'otelEndpoint'> {\n return {\n serviceName: 'shopify-cli',\n throttleLimit: 1000,\n prefixMetric: false,\n metrics: {\n [Name.Counter]: {\n type: MetricInstrumentType.Counter,\n description: 'Total number of CLI commands executed',\n valueType: ValueType.INT,\n },\n [Name.Duration]: {\n type: MetricInstrumentType.Histogram,\n description:\n 'Total time spent in execution of CLI commands. Does not include time spent waiting for network, prompts, etc.',\n valueType: ValueType.INT,\n boundaries: COMMAND_DURATION_BOUNDARIES_MS,\n },\n [Name.Elapsed]: {\n type: MetricInstrumentType.Histogram,\n description:\n 'Total time elapsed from start to finish of CLI commands. Includes time spent waiting for network, prompts, etc.',\n valueType: ValueType.INT,\n boundaries: COMMAND_DURATION_BOUNDARIES_MS,\n },\n },\n }\n}\n\n/**\n * Create the metric recorder for this command.\n *\n * If metric logging is disabled, or we are running in a unit test, we record to the console.\n *\n */\nfunction createMetricRecorder(options: CreateMetricRecorderOptions): MetricRecorder {\n let recorder: MetricRecorder = 'console'\n if (!(options.skipMetricAnalytics || isUnitTest())) {\n recorder = {\n type: 'otel',\n otel: globalOtelService(options),\n }\n }\n return recorder\n}\n\nlet _otelService: OtelService | undefined\n\n/**\n * OTEL service singleton.\n *\n * The service is a singleton as it uses a global diagnostic logger that assumes its the only one in the process.\n */\nfunction globalOtelService(options: CreateMetricRecorderOptions): OtelService {\n if (!_otelService) {\n _otelService = new DefaultOtelService({\n ...options.otelOptions,\n env: undefined,\n otelEndpoint: `${opentelemetryDomain()}/v1/metrics`,\n })\n // Suppress OTEL diagnostic output — internal export errors (e.g. retryable failures)\n // should never appear in user-facing CLI output.\n diag.disable()\n }\n return _otelService\n}\n\n/**\n * Log command counter metrics.\n */\nfunction recordCommandCounter(recorder: MetricRecorder, labels: Labels) {\n if (recorder === 'console') {\n outputDebug(outputContent`[OTEL] record ${Name.Counter} counter ${outputToken.json({labels})}`)\n return\n }\n recorder.otel.record(Name.Counter, 1, labels)\n}\n\n/**\n * Log command timing metrics.\n */\nfunction recordCommandTiming(recorder: MetricRecorder, labels: Labels, timing: Timing) {\n if (recorder === 'console') {\n outputDebug(\n outputContent`[OTEL] record ${Name.Duration} histogram ${timing.active.toString()}ms ${outputToken.json({\n labels,\n })}`,\n )\n outputDebug(outputContent`[OTEL] record ${Name.Elapsed} histogram stage=\"active\" ${timing.active.toString()}ms`)\n outputDebug(outputContent`[OTEL] record ${Name.Elapsed} histogram stage=\"network\" ${timing.network.toString()}ms`)\n outputDebug(outputContent`[OTEL] record ${Name.Elapsed} histogram stage=\"prompt\" ${timing.prompt.toString()}ms`)\n return\n }\n\n if (timing.active > 0) {\n recorder.otel.record(Name.Duration, timing.active, labels)\n recorder.otel.record(Name.Elapsed, timing.active, {...labels, stage: 'active'})\n }\n if (timing.network > 0) {\n recorder.otel.record(Name.Elapsed, timing.network, {...labels, stage: 'network'})\n }\n if (timing.prompt > 0) {\n recorder.otel.record(Name.Elapsed, timing.prompt, {...labels, stage: 'prompt'})\n }\n}\n"]}
|
|
@@ -60,6 +60,13 @@ export declare function escapeRegExp(str: string): string;
|
|
|
60
60
|
* @returns The escaped string.
|
|
61
61
|
*/
|
|
62
62
|
export declare function camelize(input: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Transform a string to capitalCase.
|
|
65
|
+
*
|
|
66
|
+
* @param input - String to transform.
|
|
67
|
+
* @returns The transformed string.
|
|
68
|
+
*/
|
|
69
|
+
export declare function capitalizeWords(input: string): string;
|
|
63
70
|
/**
|
|
64
71
|
* Transform a string to param-case.
|
|
65
72
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { takeRandomFromArray } from './array.js';
|
|
2
2
|
import { unstyled } from '../../public/node/output.js';
|
|
3
|
-
import { camelCase, constantCase, paramCase, snakeCase, pascalCase } from 'change-case';
|
|
3
|
+
import { camelCase, capitalCase, constantCase, paramCase, snakeCase, pascalCase } from 'change-case';
|
|
4
4
|
const SAFE_RANDOM_BUSINESS_ADJECTIVES = [
|
|
5
5
|
'commercial',
|
|
6
6
|
'profitable',
|
|
@@ -277,6 +277,15 @@ export function escapeRegExp(str) {
|
|
|
277
277
|
export function camelize(input) {
|
|
278
278
|
return camelCase(input);
|
|
279
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Transform a string to capitalCase.
|
|
282
|
+
*
|
|
283
|
+
* @param input - String to transform.
|
|
284
|
+
* @returns The transformed string.
|
|
285
|
+
*/
|
|
286
|
+
export function capitalizeWords(input) {
|
|
287
|
+
return capitalCase(input);
|
|
288
|
+
}
|
|
280
289
|
/**
|
|
281
290
|
* Transform a string to param-case.
|
|
282
291
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/public/common/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,6BAA6B,CAAA;AAEpD,OAAO,EAAC,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,aAAa,CAAA;AAErF,MAAM,+BAA+B,GAAG;IACtC,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,SAAS;IACT,YAAY;IACZ,aAAa;IACb,cAAc;IACd,aAAa;IACb,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,UAAU;IACV,WAAW;IACX,WAAW;IACX,eAAe;I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C,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAA;IACnC,OAAO,GAAG,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAA;AAC7C,CAAC;AAED,SAAS,cAAc,CAAC,KAAa,EAAE,IAAY;IACjD,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;AACpD,CAAC","sourcesContent":["import {takeRandomFromArray} from './array.js'\nimport {unstyled} from '../../public/node/output.js'\nimport {Token, TokenItem} from '../../private/node/ui/components/TokenizedText.js'\nimport {camelCase, constantCase, paramCase, snakeCase, pascalCase} from 'change-case'\n\nconst SAFE_RANDOM_BUSINESS_ADJECTIVES = [\n 'commercial',\n 'profitable',\n 'amortizable',\n 'branded',\n 'integrated',\n 'synergistic',\n 'consolidated',\n 'diversified',\n 'lean',\n 'niche',\n 'premium',\n 'luxury',\n 'scalable',\n 'optimized',\n 'empowered',\n 'international',\n 'beneficial',\n 'fruitful',\n 'extensive',\n 'lucrative',\n 'modern',\n 'stable',\n 'strategic',\n 'adaptive',\n 'efficient',\n 'growing',\n 'sustainable',\n 'innovative',\n 'regional',\n 'specialized',\n 'focused',\n 'pragmatic',\n 'ethical',\n 'flexible',\n 'competitive',\n]\n\nconst SAFE_RANDOM_CREATIVE_ADJECTIVES = [\n 'bright',\n 'impactful',\n 'stylish',\n 'colorful',\n 'modern',\n 'minimal',\n 'trendy',\n 'creative',\n 'artistic',\n 'spectacular',\n 'glamorous',\n 'luxury',\n 'retro',\n 'nostalgic',\n 'comfy',\n 'polished',\n 'fabulous',\n 'balanced',\n 'monochrome',\n 'glitched',\n 'contrasted',\n 'elegant',\n 'textured',\n 'vibrant',\n 'harmonious',\n 'versatile',\n 'eclectic',\n 'futuristic',\n 'idealistic',\n 'intricate',\n 'bohemian',\n 'abstract',\n 'meticulous',\n 'refined',\n 'flamboyant',\n]\n\nconst SAFE_RANDOM_BUSINESS_NOUNS = [\n 'account',\n 'consumer',\n 'customer',\n 'enterprise',\n 'business',\n 'venture',\n 'marketplace',\n 'revenue',\n 'vertical',\n 'portfolio',\n 'negotiation',\n 'shipping',\n 'demand',\n 'supply',\n 'growth',\n 'merchant',\n 'investment',\n 'shareholder',\n 'conversion',\n 'capital',\n 'projection',\n 'upside',\n 'trade',\n 'deal',\n 'merchandise',\n 'transaction',\n 'sale',\n 'franchise',\n 'subsidiary',\n 'logistics',\n 'sponsorship',\n 'partnership',\n 'tax',\n 'policy',\n 'outsource',\n 'equity',\n 'strategy',\n 'valuation',\n 'benchmark',\n 'metrics',\n 'duplication',\n]\n\nconst SAFE_RANDOM_CREATIVE_NOUNS = [\n 'vibe',\n 'style',\n 'moment',\n 'mood',\n 'flavor',\n 'look',\n 'appearance',\n 'perspective',\n 'aspect',\n 'ambience',\n 'quality',\n 'backdrop',\n 'focus',\n 'tone',\n 'inspiration',\n 'imagery',\n 'aesthetics',\n 'palette',\n 'ornamentation',\n 'contrast',\n 'colorway',\n 'visuals',\n 'typography',\n 'composition',\n 'scale',\n 'symmetry',\n 'gradients',\n 'proportions',\n 'textures',\n 'harmony',\n 'shapes',\n 'patterns',\n]\n\nexport type RandomNameFamily = 'business' | 'creative'\n\n/**\n * Generates a random name by combining an adjective and noun.\n *\n * @param family - Theme to use for the random name (business or creative).\n * @returns A random name generated by combining an adjective and noun.\n */\nexport function getRandomName(family: RandomNameFamily = 'business'): string {\n const mapping = {\n business: {\n adjectives: SAFE_RANDOM_BUSINESS_ADJECTIVES,\n nouns: SAFE_RANDOM_BUSINESS_NOUNS,\n },\n creative: {\n adjectives: SAFE_RANDOM_CREATIVE_ADJECTIVES,\n nouns: SAFE_RANDOM_CREATIVE_NOUNS,\n },\n }\n return `${takeRandomFromArray(mapping[family].adjectives)}-${takeRandomFromArray(mapping[family].nouns)}`\n}\n\n/**\n * Given a string, it returns it with the first letter capitalized.\n *\n * @param str - String to capitalize.\n * @returns String with the first letter capitalized.\n */\nexport function capitalize(str: string): string {\n return str.substring(0, 1).toUpperCase() + str.substring(1)\n}\n\n/**\n * Given a list of items, it returns a pluralized string based on the amount of items.\n *\n * @param items - List of items.\n * @param plural - Supplier used when the list of items has more than one item.\n * @param singular - Supplier used when the list of items has a single item.\n * @param none - Supplier used when the list has no items.\n * @returns The {@link TokenItem} supplied by the {@link plural}, {@link singular}, or {@link none} functions.\n */\nexport function pluralize<\n T,\n TToken extends Token = Token,\n TPluralToken extends TToken = TToken,\n TSingularToken extends TToken = TToken,\n TNoneToken extends TToken = TToken,\n>(\n items: T[],\n plural: (items: T[]) => TokenItem<TPluralToken>,\n singular: (item: T) => TokenItem<TSingularToken>,\n none?: () => TokenItem<TNoneToken>,\n): TokenItem<TPluralToken | TSingularToken | TNoneToken> | string {\n if (items.length === 1) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return singular(items[0]!)\n }\n\n if (items.length > 1) {\n return plural(items)\n }\n\n if (none) {\n return none()\n }\n\n return ''\n}\n\n/**\n * Try to convert a string to an int, falling back to undefined if unable to.\n *\n * @param maybeInt - String to convert to an int.\n * @returns The int if it was able to convert, otherwise undefined.\n */\nexport function tryParseInt(maybeInt: string | undefined): number | undefined {\n let asInt: number | undefined\n if (maybeInt !== undefined) {\n asInt = parseInt(maybeInt, 10)\n if (isNaN(asInt)) {\n asInt = undefined\n }\n }\n return asInt\n}\n\n/**\n * Transforms a matrix of strings into a single string with the columns aligned.\n *\n * @param lines - Array of rows, where each row is an array of strings (representing columns).\n * @returns A string with the columns aligned.\n */\nexport function linesToColumns(lines: string[][]): string {\n const widths: number[] = []\n for (let i = 0; lines[0] && i < lines[0].length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const columnRows = lines.map((line) => line[i]!)\n widths.push(Math.max(...columnRows.map((row) => unstyled(row).length)))\n }\n const paddedLines = lines\n .map((line) => {\n return line\n .map((col, index) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return `${col}${' '.repeat(widths[index]! - unstyled(col).length)}`\n })\n .join(' ')\n .trimEnd()\n })\n .join('\\n')\n return paddedLines\n}\n\n/**\n * Given a string, it transforms it to a slug (lowercase, hyphenated, no special chars, trimmed...).\n *\n * @param str - String to slugify.\n * @returns The slugified string.\n */\nexport function slugify(str: string): string {\n return str\n .toLowerCase()\n .trim()\n .replace(/[^\\w\\s-]/g, '')\n .replace(/[\\s_-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n}\n\n/**\n * Given a string, it returns it with the special regex characters escaped.\n * More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping.\n *\n * @param str - String to escape.\n * @returns The escaped string.\n */\nexport function escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Transform a string to camelCase.\n *\n * @param input - String to escape.\n * @returns The escaped string.\n */\nexport function camelize(input: string): string {\n return camelCase(input)\n}\n\n/**\n * Transform a string to param-case.\n *\n * @param input - String to transform.\n * @returns The transformed string.\n */\nexport function hyphenate(input: string): string {\n return paramCase(input)\n}\n\n/**\n * Transform a string to snake_case.\n *\n * @param input - String to transform.\n * @returns The transformed string.\n */\nexport function underscore(input: string): string {\n return snakeCase(input)\n}\n\n/**\n * Transform a string to CONSTANT_CASE.\n *\n * @param input - String to transform.\n * @returns The transformed string.\n */\nexport function constantize(input: string): string {\n return constantCase(input)\n}\n\n/**\n * Given a date, return a formatted string like \"2021-01-01 12:00:00\".\n *\n * @param date - Date to format.\n * @returns The transformed string.\n */\nexport function formatDate(date: Date): string {\n const components = date.toISOString().split('T')\n const dateString = components[0] ?? date.toDateString()\n const timeString = components[1]?.split('.')[0] ?? date.toTimeString()\n return `${dateString} ${timeString}`\n}\n\n/**\n * Given a date in UTC ISO String format, return a formatted string in local time like \"2021-01-01 12:00:00\".\n *\n * @param dateString - UTC ISO Date String.\n * @returns The transformed string in local system time.\n */\nexport function formatLocalDate(dateString: string): string {\n const dateObj = new Date(dateString)\n const localDate = new Date(\n Date.UTC(\n dateObj.getFullYear(),\n dateObj.getMonth(),\n dateObj.getDate(),\n dateObj.getHours(),\n dateObj.getMinutes(),\n dateObj.getSeconds(),\n ),\n )\n return formatDate(localDate)\n}\n\n/**\n * Given a list of items, it returns a string with the items joined by commas and the last item joined by \"and\".\n * All items are wrapped in double quotes.\n * For example: [\"a\", \"b\", \"c\"] returns \"a\", \"b\" and \"c\".\n *\n * @param items - List of items.\n * @returns The joined string.\n */\nexport function joinWithAnd(items: string[]): string {\n if (items.length === 0) return ''\n if (items.length === 1) return `\"${items[0]}\"`\n\n return `${items\n .slice(0, -1)\n .map((item) => `\"${item}\"`)\n .join(', ')} and \"${items[items.length - 1]}\"`\n}\n\n/**\n * Given a string, it returns the PascalCase form of it.\n * Eg: \"pascal_case\" returns \"PascalCase\".\n *\n * @param str - String to PascalCase.\n * @returns String with all the first letter capitalized with no spaces.\n */\nexport function pascalize(str: string): string {\n return pascalCase(str)\n}\n\n/**\n * Given a string that represents a list of delimited tokens, it returns the normalized string representing the same\n * list, without empty elements, sorted, and with no duplicates.\n *\n * @param delimitedString - String to normalize.\n * @param delimiter - Delimiter used to split the string into tokens.\n * @returns String with the normalized list of tokens.\n */\nexport function normalizeDelimitedString(delimitedString?: string, delimiter = ','): string | undefined {\n if (!delimitedString) return\n\n const items = delimitedString.split(delimiter).map((value) => value.trim())\n const nonEmptyItems = items.filter((value) => value !== '')\n const sortedItems = nonEmptyItems.sort()\n const uniqueSortedItems = [...new Set(sortedItems)]\n\n return uniqueSortedItems.join(delimiter)\n}\n\n/**\n * Given two dates, it returns a human-readable string representing the time elapsed between them.\n *\n * @param from - Start date.\n * @param to - End date.\n * @returns A string like \"5 minutes ago\" or \"2 days ago\".\n */\nexport function timeAgo(from: Date, to: Date): string {\n const seconds = Math.floor((to.getTime() - from.getTime()) / 1000)\n if (seconds < 60) return `${formatTimeUnit(seconds, 'second')} ago`\n\n const minutes = Math.floor(seconds / 60)\n if (minutes < 60) return `${formatTimeUnit(minutes, 'minute')} ago`\n\n const hours = Math.floor(minutes / 60)\n if (hours < 24) return `${formatTimeUnit(hours, 'hour')} ago`\n\n const days = Math.floor(hours / 24)\n return `${formatTimeUnit(days, 'day')} ago`\n}\n\nfunction formatTimeUnit(count: number, unit: string): string {\n return `${count} ${unit}${count === 1 ? '' : 's'}`\n}\n"]}
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/public/common/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,6BAA6B,CAAA;AAEpD,OAAO,EAAC,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAC,MAAM,aAAa,CAAA;AAElG,MAAM,+BAA+B,GAAG;IACtC,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,SAAS;IACT,YAAY;IACZ,aAAa;IACb,cAAc;IACd,aAAa;IACb,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,UAAU;IACV,WAAW;IACX,WAAW;IACX,eAAe;IACf,YAAY;IACZ,UAAU;IACV,WAAW;IACX,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,UAAU;IACV,WAAW;IACX,SAAS;IACT,aAAa;IACb,YAAY;IACZ,UAAU;IACV,aAAa;IACb,SAAS;IACT,WAAW;IACX,SAAS;IACT,UAAU;IACV,aAAa;CACd,CAAA;AAED,MAAM,+BAA+B,GAAG;IACtC,QAAQ;IACR,WAAW;IACX,SAAS;IACT,UAAU;IACV,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,UAAU;IACV,UAAU;IACV,aAAa;IACb,WAAW;IACX,QAAQ;IACR,OAAO;IACP,WAAW;IACX,OAAO;IACP,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,UAAU;IACV,YAAY;IACZ,SAAS;IACT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A;IACxC,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAA;IAEnD,OAAO,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,IAAU,EAAE,EAAQ;IAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;IAClE,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAA;IAEnE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IACxC,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAA;IAEnE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAA;IACtC,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAA;IAE7D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAA;IACnC,OAAO,GAAG,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAA;AAC7C,CAAC;AAED,SAAS,cAAc,CAAC,KAAa,EAAE,IAAY;IACjD,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;AACpD,CAAC","sourcesContent":["import {takeRandomFromArray} from './array.js'\nimport {unstyled} from '../../public/node/output.js'\nimport {Token, TokenItem} from '../../private/node/ui/components/TokenizedText.js'\nimport {camelCase, capitalCase, constantCase, paramCase, snakeCase, pascalCase} from 'change-case'\n\nconst SAFE_RANDOM_BUSINESS_ADJECTIVES = [\n 'commercial',\n 'profitable',\n 'amortizable',\n 'branded',\n 'integrated',\n 'synergistic',\n 'consolidated',\n 'diversified',\n 'lean',\n 'niche',\n 'premium',\n 'luxury',\n 'scalable',\n 'optimized',\n 'empowered',\n 'international',\n 'beneficial',\n 'fruitful',\n 'extensive',\n 'lucrative',\n 'modern',\n 'stable',\n 'strategic',\n 'adaptive',\n 'efficient',\n 'growing',\n 'sustainable',\n 'innovative',\n 'regional',\n 'specialized',\n 'focused',\n 'pragmatic',\n 'ethical',\n 'flexible',\n 'competitive',\n]\n\nconst SAFE_RANDOM_CREATIVE_ADJECTIVES = [\n 'bright',\n 'impactful',\n 'stylish',\n 'colorful',\n 'modern',\n 'minimal',\n 'trendy',\n 'creative',\n 'artistic',\n 'spectacular',\n 'glamorous',\n 'luxury',\n 'retro',\n 'nostalgic',\n 'comfy',\n 'polished',\n 'fabulous',\n 'balanced',\n 'monochrome',\n 'glitched',\n 'contrasted',\n 'elegant',\n 'textured',\n 'vibrant',\n 'harmonious',\n 'versatile',\n 'eclectic',\n 'futuristic',\n 'idealistic',\n 'intricate',\n 'bohemian',\n 'abstract',\n 'meticulous',\n 'refined',\n 'flamboyant',\n]\n\nconst SAFE_RANDOM_BUSINESS_NOUNS = [\n 'account',\n 'consumer',\n 'customer',\n 'enterprise',\n 'business',\n 'venture',\n 'marketplace',\n 'revenue',\n 'vertical',\n 'portfolio',\n 'negotiation',\n 'shipping',\n 'demand',\n 'supply',\n 'growth',\n 'merchant',\n 'investment',\n 'shareholder',\n 'conversion',\n 'capital',\n 'projection',\n 'upside',\n 'trade',\n 'deal',\n 'merchandise',\n 'transaction',\n 'sale',\n 'franchise',\n 'subsidiary',\n 'logistics',\n 'sponsorship',\n 'partnership',\n 'tax',\n 'policy',\n 'outsource',\n 'equity',\n 'strategy',\n 'valuation',\n 'benchmark',\n 'metrics',\n 'duplication',\n]\n\nconst SAFE_RANDOM_CREATIVE_NOUNS = [\n 'vibe',\n 'style',\n 'moment',\n 'mood',\n 'flavor',\n 'look',\n 'appearance',\n 'perspective',\n 'aspect',\n 'ambience',\n 'quality',\n 'backdrop',\n 'focus',\n 'tone',\n 'inspiration',\n 'imagery',\n 'aesthetics',\n 'palette',\n 'ornamentation',\n 'contrast',\n 'colorway',\n 'visuals',\n 'typography',\n 'composition',\n 'scale',\n 'symmetry',\n 'gradients',\n 'proportions',\n 'textures',\n 'harmony',\n 'shapes',\n 'patterns',\n]\n\nexport type RandomNameFamily = 'business' | 'creative'\n\n/**\n * Generates a random name by combining an adjective and noun.\n *\n * @param family - Theme to use for the random name (business or creative).\n * @returns A random name generated by combining an adjective and noun.\n */\nexport function getRandomName(family: RandomNameFamily = 'business'): string {\n const mapping = {\n business: {\n adjectives: SAFE_RANDOM_BUSINESS_ADJECTIVES,\n nouns: SAFE_RANDOM_BUSINESS_NOUNS,\n },\n creative: {\n adjectives: SAFE_RANDOM_CREATIVE_ADJECTIVES,\n nouns: SAFE_RANDOM_CREATIVE_NOUNS,\n },\n }\n return `${takeRandomFromArray(mapping[family].adjectives)}-${takeRandomFromArray(mapping[family].nouns)}`\n}\n\n/**\n * Given a string, it returns it with the first letter capitalized.\n *\n * @param str - String to capitalize.\n * @returns String with the first letter capitalized.\n */\nexport function capitalize(str: string): string {\n return str.substring(0, 1).toUpperCase() + str.substring(1)\n}\n\n/**\n * Given a list of items, it returns a pluralized string based on the amount of items.\n *\n * @param items - List of items.\n * @param plural - Supplier used when the list of items has more than one item.\n * @param singular - Supplier used when the list of items has a single item.\n * @param none - Supplier used when the list has no items.\n * @returns The {@link TokenItem} supplied by the {@link plural}, {@link singular}, or {@link none} functions.\n */\nexport function pluralize<\n T,\n TToken extends Token = Token,\n TPluralToken extends TToken = TToken,\n TSingularToken extends TToken = TToken,\n TNoneToken extends TToken = TToken,\n>(\n items: T[],\n plural: (items: T[]) => TokenItem<TPluralToken>,\n singular: (item: T) => TokenItem<TSingularToken>,\n none?: () => TokenItem<TNoneToken>,\n): TokenItem<TPluralToken | TSingularToken | TNoneToken> | string {\n if (items.length === 1) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return singular(items[0]!)\n }\n\n if (items.length > 1) {\n return plural(items)\n }\n\n if (none) {\n return none()\n }\n\n return ''\n}\n\n/**\n * Try to convert a string to an int, falling back to undefined if unable to.\n *\n * @param maybeInt - String to convert to an int.\n * @returns The int if it was able to convert, otherwise undefined.\n */\nexport function tryParseInt(maybeInt: string | undefined): number | undefined {\n let asInt: number | undefined\n if (maybeInt !== undefined) {\n asInt = parseInt(maybeInt, 10)\n if (isNaN(asInt)) {\n asInt = undefined\n }\n }\n return asInt\n}\n\n/**\n * Transforms a matrix of strings into a single string with the columns aligned.\n *\n * @param lines - Array of rows, where each row is an array of strings (representing columns).\n * @returns A string with the columns aligned.\n */\nexport function linesToColumns(lines: string[][]): string {\n const widths: number[] = []\n for (let i = 0; lines[0] && i < lines[0].length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const columnRows = lines.map((line) => line[i]!)\n widths.push(Math.max(...columnRows.map((row) => unstyled(row).length)))\n }\n const paddedLines = lines\n .map((line) => {\n return line\n .map((col, index) => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return `${col}${' '.repeat(widths[index]! - unstyled(col).length)}`\n })\n .join(' ')\n .trimEnd()\n })\n .join('\\n')\n return paddedLines\n}\n\n/**\n * Given a string, it transforms it to a slug (lowercase, hyphenated, no special chars, trimmed...).\n *\n * @param str - String to slugify.\n * @returns The slugified string.\n */\nexport function slugify(str: string): string {\n return str\n .toLowerCase()\n .trim()\n .replace(/[^\\w\\s-]/g, '')\n .replace(/[\\s_-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n}\n\n/**\n * Given a string, it returns it with the special regex characters escaped.\n * More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping.\n *\n * @param str - String to escape.\n * @returns The escaped string.\n */\nexport function escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Transform a string to camelCase.\n *\n * @param input - String to escape.\n * @returns The escaped string.\n */\nexport function camelize(input: string): string {\n return camelCase(input)\n}\n\n/**\n * Transform a string to capitalCase.\n *\n * @param input - String to transform.\n * @returns The transformed string.\n */\nexport function capitalizeWords(input: string): string {\n return capitalCase(input)\n}\n\n/**\n * Transform a string to param-case.\n *\n * @param input - String to transform.\n * @returns The transformed string.\n */\nexport function hyphenate(input: string): string {\n return paramCase(input)\n}\n\n/**\n * Transform a string to snake_case.\n *\n * @param input - String to transform.\n * @returns The transformed string.\n */\nexport function underscore(input: string): string {\n return snakeCase(input)\n}\n\n/**\n * Transform a string to CONSTANT_CASE.\n *\n * @param input - String to transform.\n * @returns The transformed string.\n */\nexport function constantize(input: string): string {\n return constantCase(input)\n}\n\n/**\n * Given a date, return a formatted string like \"2021-01-01 12:00:00\".\n *\n * @param date - Date to format.\n * @returns The transformed string.\n */\nexport function formatDate(date: Date): string {\n const components = date.toISOString().split('T')\n const dateString = components[0] ?? date.toDateString()\n const timeString = components[1]?.split('.')[0] ?? date.toTimeString()\n return `${dateString} ${timeString}`\n}\n\n/**\n * Given a date in UTC ISO String format, return a formatted string in local time like \"2021-01-01 12:00:00\".\n *\n * @param dateString - UTC ISO Date String.\n * @returns The transformed string in local system time.\n */\nexport function formatLocalDate(dateString: string): string {\n const dateObj = new Date(dateString)\n const localDate = new Date(\n Date.UTC(\n dateObj.getFullYear(),\n dateObj.getMonth(),\n dateObj.getDate(),\n dateObj.getHours(),\n dateObj.getMinutes(),\n dateObj.getSeconds(),\n ),\n )\n return formatDate(localDate)\n}\n\n/**\n * Given a list of items, it returns a string with the items joined by commas and the last item joined by \"and\".\n * All items are wrapped in double quotes.\n * For example: [\"a\", \"b\", \"c\"] returns \"a\", \"b\" and \"c\".\n *\n * @param items - List of items.\n * @returns The joined string.\n */\nexport function joinWithAnd(items: string[]): string {\n if (items.length === 0) return ''\n if (items.length === 1) return `\"${items[0]}\"`\n\n return `${items\n .slice(0, -1)\n .map((item) => `\"${item}\"`)\n .join(', ')} and \"${items[items.length - 1]}\"`\n}\n\n/**\n * Given a string, it returns the PascalCase form of it.\n * Eg: \"pascal_case\" returns \"PascalCase\".\n *\n * @param str - String to PascalCase.\n * @returns String with all the first letter capitalized with no spaces.\n */\nexport function pascalize(str: string): string {\n return pascalCase(str)\n}\n\n/**\n * Given a string that represents a list of delimited tokens, it returns the normalized string representing the same\n * list, without empty elements, sorted, and with no duplicates.\n *\n * @param delimitedString - String to normalize.\n * @param delimiter - Delimiter used to split the string into tokens.\n * @returns String with the normalized list of tokens.\n */\nexport function normalizeDelimitedString(delimitedString?: string, delimiter = ','): string | undefined {\n if (!delimitedString) return\n\n const items = delimitedString.split(delimiter).map((value) => value.trim())\n const nonEmptyItems = items.filter((value) => value !== '')\n const sortedItems = nonEmptyItems.sort()\n const uniqueSortedItems = [...new Set(sortedItems)]\n\n return uniqueSortedItems.join(delimiter)\n}\n\n/**\n * Given two dates, it returns a human-readable string representing the time elapsed between them.\n *\n * @param from - Start date.\n * @param to - End date.\n * @returns A string like \"5 minutes ago\" or \"2 days ago\".\n */\nexport function timeAgo(from: Date, to: Date): string {\n const seconds = Math.floor((to.getTime() - from.getTime()) / 1000)\n if (seconds < 60) return `${formatTimeUnit(seconds, 'second')} ago`\n\n const minutes = Math.floor(seconds / 60)\n if (minutes < 60) return `${formatTimeUnit(minutes, 'minute')} ago`\n\n const hours = Math.floor(minutes / 60)\n if (hours < 24) return `${formatTimeUnit(hours, 'hour')} ago`\n\n const days = Math.floor(hours / 24)\n return `${formatTimeUnit(days, 'day')} ago`\n}\n\nfunction formatTimeUnit(count: number, unit: string): string {\n return `${count} ${unit}${count === 1 ? '' : 's'}`\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLI_KIT_VERSION = "3.
|
|
1
|
+
export declare const CLI_KIT_VERSION = "3.91.0";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const CLI_KIT_VERSION = '3.
|
|
1
|
+
export const CLI_KIT_VERSION = '3.91.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.91.0'\n"]}
|
|
@@ -2,6 +2,7 @@ import { alwaysLogAnalytics, alwaysLogMetrics, analyticsDisabled, isShopify } fr
|
|
|
2
2
|
import * as metadata from './metadata.js';
|
|
3
3
|
import { publishMonorailEvent, MONORAIL_COMMAND_TOPIC } from './monorail.js';
|
|
4
4
|
import { fanoutHooks } from './plugins.js';
|
|
5
|
+
import { sendErrorToBugsnag } from './error-handler.js';
|
|
5
6
|
import { recordTiming as storageRecordTiming, recordError as storageRecordError, recordRetry as storageRecordRetry, recordEvent as storageRecordEvent, compileData as storageCompileData, } from '../../private/node/analytics/storage.js';
|
|
6
7
|
import { outputContent, outputDebug, outputToken } from '../../public/node/output.js';
|
|
7
8
|
import { getEnvironmentData, getSensitiveEnvironmentData } from '../../private/node/analytics.js';
|
|
@@ -75,6 +76,7 @@ export async function reportAnalyticsEvent(options) {
|
|
|
75
76
|
message = message.concat(`: ${error.message}`);
|
|
76
77
|
}
|
|
77
78
|
outputDebug(message);
|
|
79
|
+
await sendErrorToBugsnag(error, 'expected_error');
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
async function buildPayload({ config, errorMess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AsB,GAAG,aAAa,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;IAC5E,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,mBAAmB,CAAC,SAAS,CAAC,CAAA;AAChC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CAAI,KAAQ;IACrC,kBAAkB,CAAC,KAAK,CAAC,CAAA;IACzB,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,SAAiB;IACxD,kBAAkB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB;IAC3C,kBAAkB,CAAC,SAAS,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,kBAAkB,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import {alwaysLogAnalytics, alwaysLogMetrics, analyticsDisabled, isShopify} from './context/local.js'\nimport * as metadata from './metadata.js'\nimport {publishMonorailEvent, MONORAIL_COMMAND_TOPIC} from './monorail.js'\nimport {fanoutHooks} from './plugins.js'\nimport {\n recordTiming as storageRecordTiming,\n recordError as storageRecordError,\n recordRetry as storageRecordRetry,\n recordEvent as storageRecordEvent,\n compileData as storageCompileData,\n RuntimeData,\n} from '../../private/node/analytics/storage.js'\nimport {outputContent, outputDebug, outputToken} from '../../public/node/output.js'\nimport {getEnvironmentData, getSensitiveEnvironmentData} from '../../private/node/analytics.js'\nimport {CLI_KIT_VERSION} from '../common/version.js'\nimport {recordMetrics} from '../../private/node/otel-metrics.js'\nimport {runWithRateLimit} from '../../private/node/conf-store.js'\nimport {reportingRateLimit} from '../../private/node/constants.js'\nimport {getLastSeenUserIdAfterAuth} from '../../private/node/session.js'\nimport {requestIdsCollection} from '../../private/node/request-ids.js'\nimport {Interfaces} from '@oclif/core'\n\nexport type CommandExitMode =\n // The command completed successfully\n | 'ok'\n // The command exited for some unexpected reason -- i.e. a bug\n | 'unexpected_error'\n // The command exited with an error, but its one we expect and doesn't point to a bug -- i.e. malformed config files\n | 'expected_error'\n\ninterface ReportAnalyticsEventOptions {\n config: Interfaces.Config\n errorMessage?: string\n exitMode: CommandExitMode\n}\n\n/**\n * Report an analytics event, sending it off to Monorail -- Shopify's internal analytics service.\n *\n * The payload for an event includes both generic data, and data gathered from installed plug-ins.\n *\n */\nexport async function reportAnalyticsEvent(options: ReportAnalyticsEventOptions): Promise<void> {\n try {\n const payload = await buildPayload(options)\n if (payload === undefined) {\n // Nothing to log\n return\n }\n\n let withinRateLimit = false\n await runWithRateLimit({\n key: 'report-analytics-event',\n ...reportingRateLimit,\n task: async () => {\n withinRateLimit = true\n },\n })\n if (!withinRateLimit) {\n outputDebug(outputContent`Skipping command analytics due to rate limiting, payload: ${outputToken.json(payload)}`)\n return\n }\n\n const skipMonorailAnalytics = !alwaysLogAnalytics() && analyticsDisabled()\n const skipMetricAnalytics = !alwaysLogMetrics() && analyticsDisabled()\n if (skipMonorailAnalytics || skipMetricAnalytics) {\n outputDebug(outputContent`Skipping command analytics, payload: ${outputToken.json(payload)}`)\n }\n\n const doMonorail = async () => {\n if (skipMonorailAnalytics) {\n return\n }\n const response = await publishMonorailEvent(MONORAIL_COMMAND_TOPIC, payload.public, payload.sensitive)\n if (response.type === 'error') {\n outputDebug(response.message)\n }\n }\n const doOpenTelemetry = async () => {\n const active = payload.public.cmd_all_timing_active_ms || 0\n const network = payload.public.cmd_all_timing_network_ms || 0\n const prompt = payload.public.cmd_all_timing_prompts_ms || 0\n\n return recordMetrics(\n {\n skipMetricAnalytics,\n cliVersion: payload.public.cli_version,\n owningPlugin: payload.public.cmd_all_plugin || '@shopify/cli',\n command: payload.public.command,\n exitMode: options.exitMode,\n },\n {\n active,\n network,\n prompt,\n },\n )\n }\n await Promise.all([doMonorail(), doOpenTelemetry()])\n\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n let message = 'Failed to report usage analytics'\n if (error instanceof Error) {\n message = message.concat(`: ${error.message}`)\n }\n outputDebug(message)\n }\n}\n\nasync function buildPayload({config, errorMessage, exitMode}: ReportAnalyticsEventOptions) {\n const {commandStartOptions, environmentFlags, ...sensitiveMetadata} = metadata.getAllSensitiveMetadata()\n if (commandStartOptions === undefined) {\n outputDebug('Unable to log analytics event - no information on executed command')\n return\n }\n const {startCommand, startArgs, startTime} = commandStartOptions\n const currentTime = new Date().getTime()\n\n // All bundled plugins appear as `@shopify/cli` in the payload\n const {'@shopify/cli': internalPluginsPublic, ...externalPluginsPublic} = await fanoutHooks(\n config,\n 'public_command_metadata',\n {},\n )\n const {'@shopify/cli': internalPluginsSensitive, ...externalPluginsSensitive} = await fanoutHooks(\n config,\n 'sensitive_command_metadata',\n {},\n )\n\n const environmentData = await getEnvironmentData(config)\n const sensitiveEnvironmentData = await getSensitiveEnvironmentData(config)\n const publicMetadata = metadata.getAllPublicMetadata()\n\n // Automatically calculate the total time spent in the command, excluding time spent in subtimers.\n const subTimers = ['cmd_all_timing_network_ms', 'cmd_all_timing_prompts_ms'] as const\n const totalTimeFromSubtimers = subTimers.reduce((total, timer) => {\n const value = publicMetadata[timer]\n if (value !== undefined) {\n return total + value\n }\n return total\n }, 0)\n const wallClockElapsed = currentTime - startTime\n const totalTimeWithoutSubtimers = wallClockElapsed - totalTimeFromSubtimers\n\n let payload = {\n public: {\n command: startCommand,\n time_start: startTime,\n time_end: currentTime,\n total_time: wallClockElapsed,\n success: exitMode === 'ok' && errorMessage === undefined,\n cli_version: CLI_KIT_VERSION,\n ruby_version: '',\n node_version: process.version.replace('v', ''),\n is_employee: await isShopify(),\n ...environmentData,\n ...internalPluginsPublic,\n ...publicMetadata,\n cmd_all_timing_active_ms: totalTimeWithoutSubtimers,\n cmd_all_exit: exitMode,\n user_id: await getLastSeenUserIdAfterAuth(),\n request_ids: requestIdsCollection.getRequestIds(),\n },\n sensitive: {\n args: startArgs.join(' '),\n cmd_all_environment_flags: environmentFlags,\n error_message: errorMessage,\n ...internalPluginsSensitive,\n ...sensitiveEnvironmentData,\n metadata: JSON.stringify({\n ...sensitiveMetadata,\n extraPublic: {\n ...externalPluginsPublic,\n },\n extraSensitive: {...externalPluginsSensitive},\n }),\n },\n }\n\n // round down timing metrics\n const timingMetrics = ['cmd_all_timing_active_ms', 'cmd_all_timing_network_ms', 'cmd_all_timing_prompts_ms'] as const\n timingMetrics.forEach((metric) => {\n const current = payload.public[metric]\n if (current !== undefined) {\n payload.public[metric] = Math.floor(current)\n }\n })\n\n // strip undefined fields -- they make up the majority of payloads due to wide metadata structure.\n payload = JSON.parse(JSON.stringify(payload))\n\n return sanitizePayload(payload)\n}\n\nfunction sanitizePayload<T>(payload: T): T {\n const payloadString = JSON.stringify(payload)\n // Remove Theme Access passwords from the payload\n const sanitizedPayloadString = payloadString.replace(/shptka_\\w*/g, '*****')\n return JSON.parse(sanitizedPayloadString)\n}\n\n/**\n * Records timing data for performance monitoring. Call twice with the same\n * event name to start and stop timing. First call starts the timer, second\n * call stops it and records the duration.\n *\n * @example\n * ```ts\n * recordTiming('theme-upload') // Start timing\n * // ... do work ...\n * recordTiming('theme-upload') // Stop timing and record duration\n * ```\n *\n * @param eventName - Unique identifier for the timing event\n */\nexport function recordTiming(eventName: string): void {\n storageRecordTiming(eventName)\n}\n\n/**\n * Records error information for debugging and monitoring. Use this to track\n * any exceptions or error conditions that occur during theme operations.\n * Errors are automatically categorized for easier analysis.\n *\n * @example\n * ```ts\n * try {\n * // ... risky operation ...\n * } catch (error) {\n * recordError(error)\n * }\n * ```\n *\n * @param error - Error object or message to record\n */\nexport function recordError<T>(error: T): T {\n storageRecordError(error)\n return error\n}\n\n/**\n * Records retry attempts for network operations. Use this to track when\n * operations are retried due to transient failures. Helps identify\n * problematic endpoints or operations that frequently fail.\n *\n * @example\n * ```ts\n * recordRetry('https://api.shopify.com/themes', 'upload')\n * ```\n *\n * @param url - The URL or endpoint being retried\n * @param operation - Description of the operation being retried\n */\nexport function recordRetry(url: string, operation: string): void {\n storageRecordRetry(url, operation)\n}\n\n/**\n * Records custom events for tracking specific user actions or system events.\n * Use this for important milestones, user interactions, or significant\n * state changes in the application.\n *\n * @example\n * ```ts\n * recordEvent('theme-dev-started')\n * recordEvent('file-watcher-connected')\n * ```\n *\n * @param eventName - Descriptive name for the event\n */\nexport function recordEvent(eventName: string): void {\n storageRecordEvent(eventName)\n}\n\n/**\n * Compiles and returns all runtime analytics data collected during the session.\n * This includes timing measurements, error records, retry attempts, and custom\n * events. Use this to retrieve a complete snapshot of analytics data for\n * reporting or debugging purposes.\n *\n * @example\n * ```ts\n * const analyticsData = compileData()\n * console.log(`Recorded ${analyticsData.timings.length} timing events`)\n * console.log(`Recorded ${analyticsData.errors.length} errors`)\n * ```\n *\n * @returns Object containing all collected analytics data including timings, errors, retries, and events\n */\nexport function compileData(): RuntimeData {\n return storageCompileData()\n}\n"]}
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../../src/public/node/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAC,MAAM,oBAAoB,CAAA;AACrG,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,EAAC,oBAAoB,EAAE,sBAAsB,EAAC,MAAM,eAAe,CAAA;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAA;AACrD,OAAO,EACL,YAAY,IAAI,mBAAmB,EACnC,WAAW,IAAI,kBAAkB,EACjC,WAAW,IAAI,kBAAkB,EACjC,WAAW,IAAI,kBAAkB,EACjC,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AW,CAAC,GAAW,EAAE,SAAiB;IACxD,kBAAkB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB;IAC3C,kBAAkB,CAAC,SAAS,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,kBAAkB,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import {alwaysLogAnalytics, alwaysLogMetrics, analyticsDisabled, isShopify} from './context/local.js'\nimport * as metadata from './metadata.js'\nimport {publishMonorailEvent, MONORAIL_COMMAND_TOPIC} from './monorail.js'\nimport {fanoutHooks} from './plugins.js'\nimport {sendErrorToBugsnag} from './error-handler.js'\nimport {\n recordTiming as storageRecordTiming,\n recordError as storageRecordError,\n recordRetry as storageRecordRetry,\n recordEvent as storageRecordEvent,\n compileData as storageCompileData,\n RuntimeData,\n} from '../../private/node/analytics/storage.js'\nimport {outputContent, outputDebug, outputToken} from '../../public/node/output.js'\nimport {getEnvironmentData, getSensitiveEnvironmentData} from '../../private/node/analytics.js'\nimport {CLI_KIT_VERSION} from '../common/version.js'\nimport {recordMetrics} from '../../private/node/otel-metrics.js'\nimport {runWithRateLimit} from '../../private/node/conf-store.js'\nimport {reportingRateLimit} from '../../private/node/constants.js'\nimport {getLastSeenUserIdAfterAuth} from '../../private/node/session.js'\nimport {requestIdsCollection} from '../../private/node/request-ids.js'\nimport {Interfaces} from '@oclif/core'\n\nexport type CommandExitMode =\n // The command completed successfully\n | 'ok'\n // The command exited for some unexpected reason -- i.e. a bug\n | 'unexpected_error'\n // The command exited with an error, but its one we expect and doesn't point to a bug -- i.e. malformed config files\n | 'expected_error'\n\ninterface ReportAnalyticsEventOptions {\n config: Interfaces.Config\n errorMessage?: string\n exitMode: CommandExitMode\n}\n\n/**\n * Report an analytics event, sending it off to Monorail -- Shopify's internal analytics service.\n *\n * The payload for an event includes both generic data, and data gathered from installed plug-ins.\n *\n */\nexport async function reportAnalyticsEvent(options: ReportAnalyticsEventOptions): Promise<void> {\n try {\n const payload = await buildPayload(options)\n if (payload === undefined) {\n // Nothing to log\n return\n }\n\n let withinRateLimit = false\n await runWithRateLimit({\n key: 'report-analytics-event',\n ...reportingRateLimit,\n task: async () => {\n withinRateLimit = true\n },\n })\n if (!withinRateLimit) {\n outputDebug(outputContent`Skipping command analytics due to rate limiting, payload: ${outputToken.json(payload)}`)\n return\n }\n\n const skipMonorailAnalytics = !alwaysLogAnalytics() && analyticsDisabled()\n const skipMetricAnalytics = !alwaysLogMetrics() && analyticsDisabled()\n if (skipMonorailAnalytics || skipMetricAnalytics) {\n outputDebug(outputContent`Skipping command analytics, payload: ${outputToken.json(payload)}`)\n }\n\n const doMonorail = async () => {\n if (skipMonorailAnalytics) {\n return\n }\n const response = await publishMonorailEvent(MONORAIL_COMMAND_TOPIC, payload.public, payload.sensitive)\n if (response.type === 'error') {\n outputDebug(response.message)\n }\n }\n const doOpenTelemetry = async () => {\n const active = payload.public.cmd_all_timing_active_ms || 0\n const network = payload.public.cmd_all_timing_network_ms || 0\n const prompt = payload.public.cmd_all_timing_prompts_ms || 0\n\n return recordMetrics(\n {\n skipMetricAnalytics,\n cliVersion: payload.public.cli_version,\n owningPlugin: payload.public.cmd_all_plugin || '@shopify/cli',\n command: payload.public.command,\n exitMode: options.exitMode,\n },\n {\n active,\n network,\n prompt,\n },\n )\n }\n await Promise.all([doMonorail(), doOpenTelemetry()])\n\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n let message = 'Failed to report usage analytics'\n if (error instanceof Error) {\n message = message.concat(`: ${error.message}`)\n }\n outputDebug(message)\n await sendErrorToBugsnag(error, 'expected_error')\n }\n}\n\nasync function buildPayload({config, errorMessage, exitMode}: ReportAnalyticsEventOptions) {\n const {commandStartOptions, environmentFlags, ...sensitiveMetadata} = metadata.getAllSensitiveMetadata()\n if (commandStartOptions === undefined) {\n outputDebug('Unable to log analytics event - no information on executed command')\n return\n }\n const {startCommand, startArgs, startTime} = commandStartOptions\n const currentTime = new Date().getTime()\n\n // All bundled plugins appear as `@shopify/cli` in the payload\n const {'@shopify/cli': internalPluginsPublic, ...externalPluginsPublic} = await fanoutHooks(\n config,\n 'public_command_metadata',\n {},\n )\n const {'@shopify/cli': internalPluginsSensitive, ...externalPluginsSensitive} = await fanoutHooks(\n config,\n 'sensitive_command_metadata',\n {},\n )\n\n const environmentData = await getEnvironmentData(config)\n const sensitiveEnvironmentData = await getSensitiveEnvironmentData(config)\n const publicMetadata = metadata.getAllPublicMetadata()\n\n // Automatically calculate the total time spent in the command, excluding time spent in subtimers.\n const subTimers = ['cmd_all_timing_network_ms', 'cmd_all_timing_prompts_ms'] as const\n const totalTimeFromSubtimers = subTimers.reduce((total, timer) => {\n const value = publicMetadata[timer]\n if (value !== undefined) {\n return total + value\n }\n return total\n }, 0)\n const wallClockElapsed = currentTime - startTime\n const totalTimeWithoutSubtimers = wallClockElapsed - totalTimeFromSubtimers\n\n let payload = {\n public: {\n command: startCommand,\n time_start: startTime,\n time_end: currentTime,\n total_time: wallClockElapsed,\n success: exitMode === 'ok' && errorMessage === undefined,\n cli_version: CLI_KIT_VERSION,\n ruby_version: '',\n node_version: process.version.replace('v', ''),\n is_employee: await isShopify(),\n ...environmentData,\n ...internalPluginsPublic,\n ...publicMetadata,\n cmd_all_timing_active_ms: totalTimeWithoutSubtimers,\n cmd_all_exit: exitMode,\n user_id: await getLastSeenUserIdAfterAuth(),\n request_ids: requestIdsCollection.getRequestIds(),\n },\n sensitive: {\n args: startArgs.join(' '),\n cmd_all_environment_flags: environmentFlags,\n error_message: errorMessage,\n ...internalPluginsSensitive,\n ...sensitiveEnvironmentData,\n metadata: JSON.stringify({\n ...sensitiveMetadata,\n extraPublic: {\n ...externalPluginsPublic,\n },\n extraSensitive: {...externalPluginsSensitive},\n }),\n },\n }\n\n // round down timing metrics\n const timingMetrics = ['cmd_all_timing_active_ms', 'cmd_all_timing_network_ms', 'cmd_all_timing_prompts_ms'] as const\n timingMetrics.forEach((metric) => {\n const current = payload.public[metric]\n if (current !== undefined) {\n payload.public[metric] = Math.floor(current)\n }\n })\n\n // strip undefined fields -- they make up the majority of payloads due to wide metadata structure.\n payload = JSON.parse(JSON.stringify(payload))\n\n return sanitizePayload(payload)\n}\n\nfunction sanitizePayload<T>(payload: T): T {\n const payloadString = JSON.stringify(payload)\n // Remove Theme Access passwords from the payload\n const sanitizedPayloadString = payloadString.replace(/shptka_\\w*/g, '*****')\n return JSON.parse(sanitizedPayloadString)\n}\n\n/**\n * Records timing data for performance monitoring. Call twice with the same\n * event name to start and stop timing. First call starts the timer, second\n * call stops it and records the duration.\n *\n * @example\n * ```ts\n * recordTiming('theme-upload') // Start timing\n * // ... do work ...\n * recordTiming('theme-upload') // Stop timing and record duration\n * ```\n *\n * @param eventName - Unique identifier for the timing event\n */\nexport function recordTiming(eventName: string): void {\n storageRecordTiming(eventName)\n}\n\n/**\n * Records error information for debugging and monitoring. Use this to track\n * any exceptions or error conditions that occur during theme operations.\n * Errors are automatically categorized for easier analysis.\n *\n * @example\n * ```ts\n * try {\n * // ... risky operation ...\n * } catch (error) {\n * recordError(error)\n * }\n * ```\n *\n * @param error - Error object or message to record\n */\nexport function recordError<T>(error: T): T {\n storageRecordError(error)\n return error\n}\n\n/**\n * Records retry attempts for network operations. Use this to track when\n * operations are retried due to transient failures. Helps identify\n * problematic endpoints or operations that frequently fail.\n *\n * @example\n * ```ts\n * recordRetry('https://api.shopify.com/themes', 'upload')\n * ```\n *\n * @param url - The URL or endpoint being retried\n * @param operation - Description of the operation being retried\n */\nexport function recordRetry(url: string, operation: string): void {\n storageRecordRetry(url, operation)\n}\n\n/**\n * Records custom events for tracking specific user actions or system events.\n * Use this for important milestones, user interactions, or significant\n * state changes in the application.\n *\n * @example\n * ```ts\n * recordEvent('theme-dev-started')\n * recordEvent('file-watcher-connected')\n * ```\n *\n * @param eventName - Descriptive name for the event\n */\nexport function recordEvent(eventName: string): void {\n storageRecordEvent(eventName)\n}\n\n/**\n * Compiles and returns all runtime analytics data collected during the session.\n * This includes timing measurements, error records, retry attempts, and custom\n * events. Use this to retrieve a complete snapshot of analytics data for\n * reporting or debugging purposes.\n *\n * @example\n * ```ts\n * const analyticsData = compileData()\n * console.log(`Recorded ${analyticsData.timings.length} timing events`)\n * console.log(`Recorded ${analyticsData.errors.length} errors`)\n * ```\n *\n * @returns Object containing all collected analytics data including timings, errors, retries, and events\n */\nexport function compileData(): RuntimeData {\n return storageCompileData()\n}\n"]}
|
|
@@ -51,3 +51,11 @@ export declare function identityFqdn(): Promise<string>;
|
|
|
51
51
|
* @returns Normalized store name.
|
|
52
52
|
*/
|
|
53
53
|
export declare function normalizeStoreFqdn(store: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Convert a store FQDN to the admin URL pattern for local development.
|
|
56
|
+
* In local mode, transforms \{store\}.my.shop.dev to admin.shop.dev/store/\{store\}.
|
|
57
|
+
*
|
|
58
|
+
* @param storeFqdn - Normalized store FQDN.
|
|
59
|
+
* @returns Store admin URL base (without protocol or path).
|
|
60
|
+
*/
|
|
61
|
+
export declare function storeAdminUrl(storeFqdn: string): string;
|
|
@@ -130,4 +130,18 @@ export function normalizeStoreFqdn(store) {
|
|
|
130
130
|
const containDomain = (storeFqdn) => storeFqdn.endsWith('.myshopify.com') || storeFqdn.endsWith('shopify.io') || storeFqdn.endsWith('.shop.dev');
|
|
131
131
|
return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn);
|
|
132
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Convert a store FQDN to the admin URL pattern for local development.
|
|
135
|
+
* In local mode, transforms \{store\}.my.shop.dev to admin.shop.dev/store/\{store\}.
|
|
136
|
+
*
|
|
137
|
+
* @param storeFqdn - Normalized store FQDN.
|
|
138
|
+
* @returns Store admin URL base (without protocol or path).
|
|
139
|
+
*/
|
|
140
|
+
export function storeAdminUrl(storeFqdn) {
|
|
141
|
+
if (serviceEnvironment() === 'local' && storeFqdn.endsWith('.my.shop.dev')) {
|
|
142
|
+
const storeName = storeFqdn.replace('.my.shop.dev', '');
|
|
143
|
+
return `admin.shop.dev/store/${storeName}`;
|
|
144
|
+
}
|
|
145
|
+
return storeFqdn;
|
|
146
|
+
}
|
|
133
147
|
//# sourceMappingURL=fqdn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../../../src/public/node/context/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAC3E,OAAO,EAAC,SAAS,EAAE,aAAa,EAAC,MAAM,+BAA+B,CAAA;AAEtE,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,UAAU,CACrD,2EAA2E,CAC5E,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;IACxC,MAAM,cAAc,GAAG,sBAAsB,CAAA;IAC7C,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAA;QACzC;YACE,OAAO,cAAc,CAAA;IACzB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;IACxC,MAAM,cAAc,GAAG,mBAAmB,CAAA;IAC1C,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,IAAI,aAAa,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC1C;YACE,OAAO,cAAc,CAAA;IACzB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB;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M,cAAc,GAAG,sBAAsB,CAAA;IAC7C,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAA;QACzC;YACE,OAAO,cAAc,CAAA;IACzB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,SAAS,GAAG,KAAK;SACpB,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;SAClB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAC1B,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAE,EAAE;QACtC,QAAQ,kBAAkB,EAAE,EAAE,CAAC;YAC7B,KAAK,OAAO;gBACV,OAAO,IAAI,aAAa,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC5C;gBACE,OAAO,GAAG,SAAS,gBAAgB,CAAA;QACvC,CAAC;IACH,CAAC,CAAA;IACD,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAC1C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IAC7G,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACpE,CAAC","sourcesContent":["import {AbortError} from '../error.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\nimport {DevServer, DevServerCore} from '../vendor/dev_server/index.js'\n\nexport const NotProvidedStoreFQDNError = new AbortError(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partnersFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('partners').host()\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Admin service we should interact with.\n *\n * @returns Fully-qualified domain of the Admin service we should interact with.\n */\nexport async function adminFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'admin.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('admin')\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Management API service we should interact with.\n *\n * @returns Fully-qualified domain of the App Management service we should interact with.\n */\nexport async function appManagementFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'app.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Dev API service we should interact with.\n *\n * @param storeFqdn - The store FQDN.\n * @returns Fully-qualified domain of the App Dev service we should interact with.\n */\nexport async function appDevFqdn(storeFqdn: string): Promise<string> {\n const environment = serviceEnvironment()\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n default:\n return storeFqdn\n }\n}\n/**\n * It returns the Developer Dashboard domain we should interact with.\n *\n * @returns Fully-qualified domain of the Developer Dashboard we should interact with.\n */\nexport async function developerDashboardFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'dev.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('dev')\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the BusinessPlatform' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function businessPlatformFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'destinations.shopifysvc.com'\n switch (environment) {\n case 'local':\n return new DevServer('business-platform').host()\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n *\n * @returns Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identityFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('identity').host()\n default:\n return productionFqdn\n }\n}\n\n/**\n * Normalize the store name to be used in the CLI.\n * It will add the .myshopify.com domain if it's not present.\n *\n * @param store - Store name.\n * @returns Normalized store name.\n */\nexport function normalizeStoreFqdn(store: string): string {\n const storeFqdn = store\n .replace(/^https?:\\/\\//, '')\n .replace(/\\/$/, '')\n .replace(/\\/admin$/, '')\n const addDomain = (storeFqdn: string) => {\n switch (serviceEnvironment()) {\n case 'local':\n return new DevServerCore().host(storeFqdn)\n default:\n return `${storeFqdn}.myshopify.com`\n }\n }\n const containDomain = (storeFqdn: string) =>\n storeFqdn.endsWith('.myshopify.com') || storeFqdn.endsWith('shopify.io') || storeFqdn.endsWith('.shop.dev')\n return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../../../src/public/node/context/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,0CAA0C,CAAA;AAC3E,OAAO,EAAC,SAAS,EAAE,aAAa,EAAC,MAAM,+BAA+B,CAAA;AAEtE,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,UAAU,CACrD,2EAA2E,CAC5E,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;IACxC,MAAM,cAAc,GAAG,sBAAsB,CAAA;IAC7C,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAA;QACzC;YACE,OAAO,cAAc,CAAA;IACzB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CA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C,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACpE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,IAAI,kBAAkB,EAAE,KAAK,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QAC3E,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;QACvD,OAAO,wBAAwB,SAAS,EAAE,CAAA;IAC5C,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import {AbortError} from '../error.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\nimport {DevServer, DevServerCore} from '../vendor/dev_server/index.js'\n\nexport const NotProvidedStoreFQDNError = new AbortError(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partnersFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('partners').host()\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Admin service we should interact with.\n *\n * @returns Fully-qualified domain of the Admin service we should interact with.\n */\nexport async function adminFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'admin.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('admin')\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Management API service we should interact with.\n *\n * @returns Fully-qualified domain of the App Management service we should interact with.\n */\nexport async function appManagementFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'app.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Dev API service we should interact with.\n *\n * @param storeFqdn - The store FQDN.\n * @returns Fully-qualified domain of the App Dev service we should interact with.\n */\nexport async function appDevFqdn(storeFqdn: string): Promise<string> {\n const environment = serviceEnvironment()\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n default:\n return storeFqdn\n }\n}\n/**\n * It returns the Developer Dashboard domain we should interact with.\n *\n * @returns Fully-qualified domain of the Developer Dashboard we should interact with.\n */\nexport async function developerDashboardFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'dev.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('dev')\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the BusinessPlatform' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function businessPlatformFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'destinations.shopifysvc.com'\n switch (environment) {\n case 'local':\n return new DevServer('business-platform').host()\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n *\n * @returns Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identityFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('identity').host()\n default:\n return productionFqdn\n }\n}\n\n/**\n * Normalize the store name to be used in the CLI.\n * It will add the .myshopify.com domain if it's not present.\n *\n * @param store - Store name.\n * @returns Normalized store name.\n */\nexport function normalizeStoreFqdn(store: string): string {\n const storeFqdn = store\n .replace(/^https?:\\/\\//, '')\n .replace(/\\/$/, '')\n .replace(/\\/admin$/, '')\n const addDomain = (storeFqdn: string) => {\n switch (serviceEnvironment()) {\n case 'local':\n return new DevServerCore().host(storeFqdn)\n default:\n return `${storeFqdn}.myshopify.com`\n }\n }\n const containDomain = (storeFqdn: string) =>\n storeFqdn.endsWith('.myshopify.com') || storeFqdn.endsWith('shopify.io') || storeFqdn.endsWith('.shop.dev')\n return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)\n}\n\n/**\n * Convert a store FQDN to the admin URL pattern for local development.\n * In local mode, transforms \\{store\\}.my.shop.dev to admin.shop.dev/store/\\{store\\}.\n *\n * @param storeFqdn - Normalized store FQDN.\n * @returns Store admin URL base (without protocol or path).\n */\nexport function storeAdminUrl(storeFqdn: string): string {\n if (serviceEnvironment() === 'local' && storeFqdn.endsWith('.my.shop.dev')) {\n const storeName = storeFqdn.replace('.my.shop.dev', '')\n return `admin.shop.dev/store/${storeName}`\n }\n return storeFqdn\n}\n"]}
|
|
@@ -71,12 +71,12 @@ export declare function alwaysLogMetrics(env?: NodeJS.ProcessEnv): boolean;
|
|
|
71
71
|
*/
|
|
72
72
|
export declare function firstPartyDev(env?: NodeJS.ProcessEnv): boolean;
|
|
73
73
|
/**
|
|
74
|
-
* Returns true if the
|
|
74
|
+
* Returns true if the CLI can run the "doctor-release" command.
|
|
75
75
|
*
|
|
76
76
|
* @param env - The environment variables from the environment of the current process.
|
|
77
|
-
* @returns True if
|
|
77
|
+
* @returns True if the CLI can run the "doctor-release" command.
|
|
78
78
|
*/
|
|
79
|
-
export declare function
|
|
79
|
+
export declare function canRunDoctorRelease(env?: NodeJS.ProcessEnv): boolean;
|
|
80
80
|
/**
|
|
81
81
|
* Return gitpodURL if we are running in gitpod.
|
|
82
82
|
* Https://www.gitpod.io/docs/environment-variables#default-environment-variables.
|
|
@@ -102,13 +102,13 @@ export function firstPartyDev(env = process.env) {
|
|
|
102
102
|
return isTruthy(env[environmentVariables.firstPartyDev]);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
* Returns true if the
|
|
105
|
+
* Returns true if the CLI can run the "doctor-release" command.
|
|
106
106
|
*
|
|
107
107
|
* @param env - The environment variables from the environment of the current process.
|
|
108
|
-
* @returns True if
|
|
108
|
+
* @returns True if the CLI can run the "doctor-release" command.
|
|
109
109
|
*/
|
|
110
|
-
export function
|
|
111
|
-
return isTruthy(env[environmentVariables.
|
|
110
|
+
export function canRunDoctorRelease(env = process.env) {
|
|
111
|
+
return isTruthy(env[environmentVariables.doctor]);
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
114
|
* Return gitpodURL if we are running in gitpod.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../../src/public/node/context/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAC,aAAa,EAAE,KAAK,EAAW,MAAM,4CAA4C,CAAA;AACzF,OAAO,EAAC,2BAA2B,EAAE,oBAAoB,EAAE,aAAa,EAAC,MAAM,oCAAoC,CAAA;AACnH,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAA;AACnC,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAA;AACjC,OAAO,aAAa,MAAM,gBAAgB,CAAA;AAC1C,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,EAAC,OAAO,EAAC,MAAM,IAAI,CAAA;AAE1B;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,aAAa,EAAE,CAAA;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,EAAE,CAAA;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC7C,OAAO,GAAG,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,aAAa,CAAA;AACxD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACzC,OAAO,QAAQ,CAAC,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;AAC1F,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC/C,IAAI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YACL,IAAI,EAAE,IAAI;YACV,IAAI;YACJ,QAAQ,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC;SACnC,CAAA;IACH,CAAC;SAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO;YACL,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC;SACtC,CAAA;IACH,CAAC;IACD,OAAO;QACL,IAAI,EAAE,KAAK;KACZ,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,UAAU,CAAC,GAAG,EAAE,CAAA;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACvD,MAAM,MAAM,GAAG,GAAG,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAA;IAE7D,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,2BAA2B,CAAA;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACnD,MAAM,MAAM,GAAG,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAA;IAEhD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,iDAAiD,CAAA;AACnF,CAAC","sourcesContent":["import {isTruthy} from './utilities.js'\nimport {getCIMetadata, isSet, Metadata} from '../../../private/node/context/utilities.js'\nimport {defaultThemeKitAccessDomain, environmentVariables, pathConstants} from '../../../private/node/constants.js'\nimport {fileExists} from '../fs.js'\nimport {exec} from '../system.js'\nimport isInteractive from 'is-interactive'\nimport macaddress from 'macaddress'\nimport {homedir} from 'os'\n\n/**\n * It returns true if the terminal is interactive.\n *\n * @returns True if the terminal is interactive.\n */\nexport function isTerminalInteractive(): boolean {\n return isInteractive()\n}\n\n/**\n * Returns the path to the user's home directory.\n *\n * @returns The path to the user's home directory.\n */\nexport function homeDirectory(): string {\n return homedir()\n}\n\n/**\n * Returns true if the CLI is running in debug mode.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_ENV is development.\n */\nexport function isDevelopment(env = process.env): boolean {\n return env[environmentVariables.env] === 'development'\n}\n\n/**\n * Returns true if the CLI is running in verbose mode.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_FLAG_VERBOSE is truthy or the flag --verbose has been passed.\n */\nexport function isVerbose(env = process.env): boolean {\n return isTruthy(env[environmentVariables.verbose]) || process.argv.includes('--verbose')\n}\n\n/**\n * Returns true if the environment in which the CLI is running is either\n * a local environment (where dev is present).\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if the CLI is used in a Shopify environment.\n */\nexport async function isShopify(env = process.env): Promise<boolean> {\n if (Object.prototype.hasOwnProperty.call(env, environmentVariables.runAsUser)) {\n return !isTruthy(env[environmentVariables.runAsUser])\n }\n const devInstalled = await fileExists(pathConstants.executables.dev)\n return devInstalled\n}\n\n/**\n * This variable is used when running unit tests to indicate that the CLI's business logic\n * is run as a subject of a unit test. We can use this variable to disable output through\n * the standard streams.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if the SHOPIFY_UNIT_TEST environment variable is truthy.\n */\nexport function isUnitTest(env = process.env): boolean {\n return isTruthy(env[environmentVariables.unitTest])\n}\n\n/**\n * Returns true if reporting analytics is enabled.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True unless SHOPIFY_CLI_NO_ANALYTICS is truthy or debug mode is enabled.\n */\nexport function analyticsDisabled(env = process.env): boolean {\n return isTruthy(env[environmentVariables.noAnalytics]) || isDevelopment(env)\n}\n\n/**\n * Returns true if reporting analytics should always happen, regardless of DEBUG mode etc.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS is truthy.\n */\nexport function alwaysLogAnalytics(env = process.env): boolean {\n return isTruthy(env[environmentVariables.alwaysLogAnalytics])\n}\n\n/**\n * Returns true if reporting metrics should always happen, regardless of DEBUG mode etc.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_CLI_ALWAYS_LOG_METRICS is truthy.\n */\nexport function alwaysLogMetrics(env = process.env): boolean {\n return isTruthy(env[environmentVariables.alwaysLogMetrics])\n}\n\n/**\n * Returns true if the CLI User is 1P.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_CLI_1P is truthy.\n */\nexport function firstPartyDev(env = process.env): boolean {\n return isTruthy(env[environmentVariables.firstPartyDev])\n}\n\n/**\n * Returns true if the local dev console should be skipped.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_SKIP_LOCAL_DEV_CONSOLE is truthy.\n */\nexport function skipLocalDevConsole(env = process.env): boolean {\n return isTruthy(env[environmentVariables.skipLocalDevConsole])\n}\n\n/**\n * Return gitpodURL if we are running in gitpod.\n * Https://www.gitpod.io/docs/environment-variables#default-environment-variables.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The gitpod URL.\n */\nexport function gitpodURL(env = process.env): string | undefined {\n return env[environmentVariables.gitpod]\n}\n\n/**\n * Return codespaceURL if we are running in codespaces.\n * Https://docs.github.com/en/codespaces/developing-in-codespaces/default-environment-variables-for-your-codespace#list-of-default-environment-variables.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The codespace URL.\n */\nexport function codespaceURL(env = process.env): string | undefined {\n return env[environmentVariables.codespaceName]\n}\n\n/**\n * Return codespacePortForwardingDomain if we are running in codespaces.\n * Https://docs.github.com/en/codespaces/developing-in-codespaces/default-environment-variables-for-your-codespace#list-of-default-environment-variables.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The codespace port forwarding domain.\n */\nexport function codespacePortForwardingDomain(env = process.env): string | undefined {\n return env[environmentVariables.codespacePortForwardingDomain]\n}\n\n/**\n * Checks if the CLI is run from a cloud environment.\n *\n * @param env - Environment variables used when the cli is launched.\n * @returns True in case the CLI is run from a cloud environment.\n */\nexport function isCloudEnvironment(env: NodeJS.ProcessEnv = process.env): boolean {\n return cloudEnvironment(env).platform !== 'localhost'\n}\n\n/**\n * The token used to run a theme command with a custom password.\n *\n * @param env - Environment variables used when the cli is launched.\n * @returns A string with the token.\n */\nexport function themeToken(env = process.env): string | undefined {\n return env[environmentVariables.themeToken]\n}\n\n/**\n * Returns the cloud environment platform name and if the platform support online IDE in case the CLI is run from one of\n * them. Platform name 'localhost' is returned otherwise.\n *\n * @param env - Environment variables used when the cli is launched.\n * @returns Cloud platform information.\n */\nexport function cloudEnvironment(env: NodeJS.ProcessEnv = process.env): {\n platform: 'codespaces' | 'gitpod' | 'cloudShell' | 'localhost'\n editor: boolean\n} {\n if (isSet(env[environmentVariables.codespaces])) {\n return {platform: 'codespaces', editor: true}\n }\n if (isSet(env[environmentVariables.gitpod])) {\n return {platform: 'gitpod', editor: true}\n }\n if (isSet(env[environmentVariables.cloudShell])) {\n return {platform: 'cloudShell', editor: true}\n }\n return {platform: 'localhost', editor: false}\n}\n\n/**\n * Returns whether the environment has Git available.\n *\n * @returns A promise that resolves with the value.\n */\nexport async function hasGit(): Promise<boolean> {\n try {\n await exec('git', ['--version'])\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * Gets info on the CI platform the CLI is running on, if applicable.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The CI platform info.\n */\nexport function ciPlatform(\n env = process.env,\n): {isCI: true; name: string; metadata: Metadata} | {isCI: false; name?: undefined; metadata?: undefined} {\n if (isTruthy(env.CI)) {\n let name = 'unknown'\n if (isSet(env.BITBUCKET_BUILD_NUMBER)) {\n name = 'bitbucket'\n } else if (isTruthy(env.CIRCLECI)) {\n name = 'circleci'\n } else if (isSet(env.GITHUB_ACTION)) {\n name = 'github'\n } else if (isTruthy(env.GITLAB_CI)) {\n name = 'gitlab'\n } else if (isSet(env.BUILDKITE)) {\n name = 'buildkite'\n }\n\n return {\n isCI: true,\n name,\n metadata: getCIMetadata(name, env),\n }\n } else if (isTruthy(env.TF_BUILD)) {\n return {\n isCI: true,\n name: 'azure',\n metadata: getCIMetadata('azure', env),\n }\n }\n return {\n isCI: false,\n }\n}\n\n/**\n * Returns the first mac address found.\n *\n * @returns Mac address.\n */\nexport function macAddress(): Promise<string> {\n return macaddress.one()\n}\n\n/**\n * Get the domain for theme kit access.\n *\n * It can be overridden via the SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN environment\n * variable.\n *\n * @param env - The environment variables from the environment of the process.\n *\n * @returns The domain for theme kit access.\n */\nexport function getThemeKitAccessDomain(env = process.env): string {\n const domain = env[environmentVariables.themeKitAccessDomain]\n\n return isSet(domain) ? domain : defaultThemeKitAccessDomain\n}\n\n/**\n * Get the domain to send OTEL metrics to.\n *\n * It can be overridden via the SHOPIFY_CLI_OTEL_EXPORTER_OTLP_ENDPOINT environment variable.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The domain to send OTEL metrics to.\n */\nexport function opentelemetryDomain(env = process.env): string {\n const domain = env[environmentVariables.otelURL]\n\n return isSet(domain) ? domain : 'https://otlp-http-production-cli.shopifysvc.com'\n}\n\nexport type CIMetadata = Metadata\n"]}
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../../src/public/node/context/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAC,aAAa,EAAE,KAAK,EAAW,MAAM,4CAA4C,CAAA;AACzF,OAAO,EAAC,2BAA2B,EAAE,oBAAoB,EAAE,aAAa,EAAC,MAAM,oCAAoC,CAAA;AACnH,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAA;AACnC,OAAO,EAAC,IAAI,EAAC,MAAM,cAA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;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACvD,MAAM,MAAM,GAAG,GAAG,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAA;IAE7D,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,2BAA2B,CAAA;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACnD,MAAM,MAAM,GAAG,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAA;IAEhD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,iDAAiD,CAAA;AACnF,CAAC","sourcesContent":["import {isTruthy} from './utilities.js'\nimport {getCIMetadata, isSet, Metadata} from '../../../private/node/context/utilities.js'\nimport {defaultThemeKitAccessDomain, environmentVariables, pathConstants} from '../../../private/node/constants.js'\nimport {fileExists} from '../fs.js'\nimport {exec} from '../system.js'\nimport isInteractive from 'is-interactive'\nimport macaddress from 'macaddress'\nimport {homedir} from 'os'\n\n/**\n * It returns true if the terminal is interactive.\n *\n * @returns True if the terminal is interactive.\n */\nexport function isTerminalInteractive(): boolean {\n return isInteractive()\n}\n\n/**\n * Returns the path to the user's home directory.\n *\n * @returns The path to the user's home directory.\n */\nexport function homeDirectory(): string {\n return homedir()\n}\n\n/**\n * Returns true if the CLI is running in debug mode.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_ENV is development.\n */\nexport function isDevelopment(env = process.env): boolean {\n return env[environmentVariables.env] === 'development'\n}\n\n/**\n * Returns true if the CLI is running in verbose mode.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_FLAG_VERBOSE is truthy or the flag --verbose has been passed.\n */\nexport function isVerbose(env = process.env): boolean {\n return isTruthy(env[environmentVariables.verbose]) || process.argv.includes('--verbose')\n}\n\n/**\n * Returns true if the environment in which the CLI is running is either\n * a local environment (where dev is present).\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if the CLI is used in a Shopify environment.\n */\nexport async function isShopify(env = process.env): Promise<boolean> {\n if (Object.prototype.hasOwnProperty.call(env, environmentVariables.runAsUser)) {\n return !isTruthy(env[environmentVariables.runAsUser])\n }\n const devInstalled = await fileExists(pathConstants.executables.dev)\n return devInstalled\n}\n\n/**\n * This variable is used when running unit tests to indicate that the CLI's business logic\n * is run as a subject of a unit test. We can use this variable to disable output through\n * the standard streams.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if the SHOPIFY_UNIT_TEST environment variable is truthy.\n */\nexport function isUnitTest(env = process.env): boolean {\n return isTruthy(env[environmentVariables.unitTest])\n}\n\n/**\n * Returns true if reporting analytics is enabled.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True unless SHOPIFY_CLI_NO_ANALYTICS is truthy or debug mode is enabled.\n */\nexport function analyticsDisabled(env = process.env): boolean {\n return isTruthy(env[environmentVariables.noAnalytics]) || isDevelopment(env)\n}\n\n/**\n * Returns true if reporting analytics should always happen, regardless of DEBUG mode etc.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS is truthy.\n */\nexport function alwaysLogAnalytics(env = process.env): boolean {\n return isTruthy(env[environmentVariables.alwaysLogAnalytics])\n}\n\n/**\n * Returns true if reporting metrics should always happen, regardless of DEBUG mode etc.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_CLI_ALWAYS_LOG_METRICS is truthy.\n */\nexport function alwaysLogMetrics(env = process.env): boolean {\n return isTruthy(env[environmentVariables.alwaysLogMetrics])\n}\n\n/**\n * Returns true if the CLI User is 1P.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if SHOPIFY_CLI_1P is truthy.\n */\nexport function firstPartyDev(env = process.env): boolean {\n return isTruthy(env[environmentVariables.firstPartyDev])\n}\n\n/**\n * Returns true if the CLI can run the \"doctor-release\" command.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns True if the CLI can run the \"doctor-release\" command.\n */\nexport function canRunDoctorRelease(env = process.env): boolean {\n return isTruthy(env[environmentVariables.doctor])\n}\n\n/**\n * Return gitpodURL if we are running in gitpod.\n * Https://www.gitpod.io/docs/environment-variables#default-environment-variables.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The gitpod URL.\n */\nexport function gitpodURL(env = process.env): string | undefined {\n return env[environmentVariables.gitpod]\n}\n\n/**\n * Return codespaceURL if we are running in codespaces.\n * Https://docs.github.com/en/codespaces/developing-in-codespaces/default-environment-variables-for-your-codespace#list-of-default-environment-variables.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The codespace URL.\n */\nexport function codespaceURL(env = process.env): string | undefined {\n return env[environmentVariables.codespaceName]\n}\n\n/**\n * Return codespacePortForwardingDomain if we are running in codespaces.\n * Https://docs.github.com/en/codespaces/developing-in-codespaces/default-environment-variables-for-your-codespace#list-of-default-environment-variables.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The codespace port forwarding domain.\n */\nexport function codespacePortForwardingDomain(env = process.env): string | undefined {\n return env[environmentVariables.codespacePortForwardingDomain]\n}\n\n/**\n * Checks if the CLI is run from a cloud environment.\n *\n * @param env - Environment variables used when the cli is launched.\n * @returns True in case the CLI is run from a cloud environment.\n */\nexport function isCloudEnvironment(env: NodeJS.ProcessEnv = process.env): boolean {\n return cloudEnvironment(env).platform !== 'localhost'\n}\n\n/**\n * The token used to run a theme command with a custom password.\n *\n * @param env - Environment variables used when the cli is launched.\n * @returns A string with the token.\n */\nexport function themeToken(env = process.env): string | undefined {\n return env[environmentVariables.themeToken]\n}\n\n/**\n * Returns the cloud environment platform name and if the platform support online IDE in case the CLI is run from one of\n * them. Platform name 'localhost' is returned otherwise.\n *\n * @param env - Environment variables used when the cli is launched.\n * @returns Cloud platform information.\n */\nexport function cloudEnvironment(env: NodeJS.ProcessEnv = process.env): {\n platform: 'codespaces' | 'gitpod' | 'cloudShell' | 'localhost'\n editor: boolean\n} {\n if (isSet(env[environmentVariables.codespaces])) {\n return {platform: 'codespaces', editor: true}\n }\n if (isSet(env[environmentVariables.gitpod])) {\n return {platform: 'gitpod', editor: true}\n }\n if (isSet(env[environmentVariables.cloudShell])) {\n return {platform: 'cloudShell', editor: true}\n }\n return {platform: 'localhost', editor: false}\n}\n\n/**\n * Returns whether the environment has Git available.\n *\n * @returns A promise that resolves with the value.\n */\nexport async function hasGit(): Promise<boolean> {\n try {\n await exec('git', ['--version'])\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * Gets info on the CI platform the CLI is running on, if applicable.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The CI platform info.\n */\nexport function ciPlatform(\n env = process.env,\n): {isCI: true; name: string; metadata: Metadata} | {isCI: false; name?: undefined; metadata?: undefined} {\n if (isTruthy(env.CI)) {\n let name = 'unknown'\n if (isSet(env.BITBUCKET_BUILD_NUMBER)) {\n name = 'bitbucket'\n } else if (isTruthy(env.CIRCLECI)) {\n name = 'circleci'\n } else if (isSet(env.GITHUB_ACTION)) {\n name = 'github'\n } else if (isTruthy(env.GITLAB_CI)) {\n name = 'gitlab'\n } else if (isSet(env.BUILDKITE)) {\n name = 'buildkite'\n }\n\n return {\n isCI: true,\n name,\n metadata: getCIMetadata(name, env),\n }\n } else if (isTruthy(env.TF_BUILD)) {\n return {\n isCI: true,\n name: 'azure',\n metadata: getCIMetadata('azure', env),\n }\n }\n return {\n isCI: false,\n }\n}\n\n/**\n * Returns the first mac address found.\n *\n * @returns Mac address.\n */\nexport function macAddress(): Promise<string> {\n return macaddress.one()\n}\n\n/**\n * Get the domain for theme kit access.\n *\n * It can be overridden via the SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN environment\n * variable.\n *\n * @param env - The environment variables from the environment of the process.\n *\n * @returns The domain for theme kit access.\n */\nexport function getThemeKitAccessDomain(env = process.env): string {\n const domain = env[environmentVariables.themeKitAccessDomain]\n\n return isSet(domain) ? domain : defaultThemeKitAccessDomain\n}\n\n/**\n * Get the domain to send OTEL metrics to.\n *\n * It can be overridden via the SHOPIFY_CLI_OTEL_EXPORTER_OTLP_ENDPOINT environment variable.\n *\n * @param env - The environment variables from the environment of the current process.\n * @returns The domain to send OTEL metrics to.\n */\nexport function opentelemetryDomain(env = process.env): string {\n const domain = env[environmentVariables.otelURL]\n\n return isSet(domain) ? domain : 'https://otlp-http-production-cli.shopifysvc.com'\n}\n\nexport type CIMetadata = Metadata\n"]}
|