@shopify/cli-kit 3.13.1 → 3.15.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/CHANGELOG.md +12 -0
- package/dist/analytics.d.ts +20 -6
- package/dist/analytics.js +54 -14
- package/dist/analytics.js.map +1 -1
- package/dist/environment/local.d.ts +23 -2
- package/dist/environment/local.js +33 -13
- package/dist/environment/local.js.map +1 -1
- package/dist/metadata.d.ts +8 -174
- package/dist/metadata.js.map +1 -1
- package/dist/monorail.d.ts +16 -1
- package/dist/monorail.js +1 -1
- package/dist/monorail.js.map +1 -1
- package/dist/node/cli.d.ts +7 -0
- package/dist/node/cli.js +1 -1
- package/dist/node/cli.js.map +1 -1
- package/dist/node/error-handler.js +1 -1
- package/dist/node/error-handler.js.map +1 -1
- package/dist/node/framework.d.ts +8 -0
- package/dist/node/framework.js +135 -0
- package/dist/node/framework.js.map +1 -0
- package/dist/node/hooks/prerun.d.ts +10 -0
- package/dist/node/hooks/prerun.js +59 -4
- package/dist/node/hooks/prerun.js.map +1 -1
- package/dist/node/node-package-manager.d.ts +20 -1
- package/dist/node/node-package-manager.js +14 -0
- package/dist/node/node-package-manager.js.map +1 -1
- package/dist/os.js +3 -0
- package/dist/os.js.map +1 -1
- package/dist/output.d.ts +1 -1
- package/dist/output.js +1 -1
- package/dist/output.js.map +1 -1
- package/dist/plugins.d.ts +11 -1
- package/dist/plugins.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @shopify/cli-kit
|
|
2
2
|
|
|
3
|
+
## 3.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9f7d90d9: Add dev, build, deploy and another additional baseline instrumentantion
|
|
8
|
+
|
|
9
|
+
## 3.14.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 1dba11ec: Support upgrade of a globally installed CLI
|
|
14
|
+
|
|
3
15
|
## 3.13.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/analytics.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import BaseCommand from './node/base-command.js';
|
|
2
|
-
import {
|
|
2
|
+
import { CommandContent } from './node/hooks/prerun.js';
|
|
3
|
+
import { Config, Interfaces } from '@oclif/core';
|
|
3
4
|
interface StartOptions {
|
|
4
|
-
|
|
5
|
+
commandContent: CommandContent;
|
|
5
6
|
args: string[];
|
|
6
7
|
currentTime?: number;
|
|
7
8
|
commandClass?: Interfaces.Command.Class | typeof BaseCommand;
|
|
8
9
|
}
|
|
9
|
-
export declare const start: ({
|
|
10
|
+
export declare const start: ({ commandContent, args, currentTime, commandClass }: StartOptions) => Promise<void>;
|
|
10
11
|
interface ReportEventOptions {
|
|
11
12
|
config: Interfaces.Config;
|
|
12
13
|
errorMessage?: string;
|
|
@@ -18,13 +19,26 @@ interface ReportEventOptions {
|
|
|
18
19
|
*
|
|
19
20
|
*/
|
|
20
21
|
export declare function reportEvent(options: ReportEventOptions): Promise<void>;
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Return the name of the tunnel provider used to send analytics. Returns 'localhost' or provider name if any of those
|
|
24
|
+
* strings are included in the {@link tunnelUrl} param. Resturns 'custom' otherwise
|
|
25
|
+
*
|
|
26
|
+
* @param {Config} options - Oclif configuration. Needed to call the hook for retrieving the list of tunner providers
|
|
27
|
+
* @param {string} tunnelUrl - Tunnel url. Used as pattern to match provider name
|
|
28
|
+
* @returns {Promise<string | undefined>} - Returns 'localhost' or provider name if any of those strings are included in
|
|
29
|
+
* the tunnelUrl. Resturns 'custom' other wise
|
|
30
|
+
*/
|
|
31
|
+
export declare function getAnalyticsTunnelType(options: Config, tunnelUrl: string): Promise<string | undefined>;
|
|
32
|
+
export declare function getEnvironmentData(config: Interfaces.Config): Promise<{
|
|
22
33
|
uname: string;
|
|
23
34
|
env_ci: boolean;
|
|
24
35
|
env_ci_platform: string | undefined;
|
|
25
36
|
env_plugin_installed_any_custom: boolean;
|
|
26
37
|
env_plugin_installed_shopify: string;
|
|
27
38
|
env_shell: string;
|
|
28
|
-
env_web_ide:
|
|
29
|
-
|
|
39
|
+
env_web_ide: "spin" | "codespaces" | "gitpod" | "localhost" | undefined;
|
|
40
|
+
env_device_id: string;
|
|
41
|
+
env_cloud: "spin" | "codespaces" | "gitpod" | "localhost";
|
|
42
|
+
env_package_manager: "yarn" | "npm" | "pnpm" | undefined;
|
|
43
|
+
}>;
|
|
30
44
|
export {};
|
package/dist/analytics.js
CHANGED
|
@@ -5,12 +5,15 @@ import { content, debug, token } from './output.js';
|
|
|
5
5
|
import constants from './constants.js';
|
|
6
6
|
import * as metadata from './metadata.js';
|
|
7
7
|
import { publishEvent, MONORAIL_COMMAND_TOPIC } from './monorail.js';
|
|
8
|
-
import { fanoutHooks } from './plugins.js';
|
|
9
|
-
import { packageManagerUsedForCreating } from './node/node-package-manager.js';
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import { fanoutHooks, getListOfTunnelPlugins } from './plugins.js';
|
|
9
|
+
import { getPackageManager, packageManagerUsedForCreating } from './node/node-package-manager.js';
|
|
10
|
+
import { hashString } from './string.js';
|
|
11
|
+
import { macAddress } from './environment/local.js';
|
|
12
|
+
import { localCliPackage } from './node/cli.js';
|
|
13
|
+
export const start = async ({ commandContent, args, currentTime = new Date().getTime(), commandClass }) => {
|
|
14
|
+
let startCommand = commandContent.command;
|
|
12
15
|
if (commandClass && Object.prototype.hasOwnProperty.call(commandClass, 'analyticsNameOverride')) {
|
|
13
|
-
startCommand = commandClass.analyticsNameOverride() ?? command;
|
|
16
|
+
startCommand = commandClass.analyticsNameOverride() ?? commandContent.command;
|
|
14
17
|
}
|
|
15
18
|
await metadata.addSensitive(() => ({
|
|
16
19
|
commandStartOptions: {
|
|
@@ -21,6 +24,8 @@ export const start = async ({ command, args, currentTime = new Date().getTime(),
|
|
|
21
24
|
}));
|
|
22
25
|
await metadata.addPublic(() => ({
|
|
23
26
|
cmd_all_launcher: packageManagerUsedForCreating(),
|
|
27
|
+
cmd_all_alias_used: commandContent.alias,
|
|
28
|
+
cmd_all_topic: commandContent.topic,
|
|
24
29
|
cmd_all_plugin: commandClass?.plugin?.name,
|
|
25
30
|
}));
|
|
26
31
|
};
|
|
@@ -55,6 +60,25 @@ export async function reportEvent(options) {
|
|
|
55
60
|
debug(message);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Return the name of the tunnel provider used to send analytics. Returns 'localhost' or provider name if any of those
|
|
65
|
+
* strings are included in the {@link tunnelUrl} param. Resturns 'custom' otherwise
|
|
66
|
+
*
|
|
67
|
+
* @param {Config} options - Oclif configuration. Needed to call the hook for retrieving the list of tunner providers
|
|
68
|
+
* @param {string} tunnelUrl - Tunnel url. Used as pattern to match provider name
|
|
69
|
+
* @returns {Promise<string | undefined>} - Returns 'localhost' or provider name if any of those strings are included in
|
|
70
|
+
* the tunnelUrl. Resturns 'custom' other wise
|
|
71
|
+
*/
|
|
72
|
+
export async function getAnalyticsTunnelType(options, tunnelUrl) {
|
|
73
|
+
if (!tunnelUrl) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (tunnelUrl.includes('localhost')) {
|
|
77
|
+
return 'localhost';
|
|
78
|
+
}
|
|
79
|
+
const provider = (await getListOfTunnelPlugins(options)).plugins.find((plugin) => tunnelUrl?.includes(plugin));
|
|
80
|
+
return provider ?? 'custom';
|
|
81
|
+
}
|
|
58
82
|
const buildPayload = async ({ config, errorMessage }) => {
|
|
59
83
|
const { commandStartOptions, ...sensitiveMetadata } = metadata.getAllSensitive();
|
|
60
84
|
if (commandStartOptions === undefined) {
|
|
@@ -64,8 +88,9 @@ const buildPayload = async ({ config, errorMessage }) => {
|
|
|
64
88
|
const { startCommand, startArgs, startTime } = commandStartOptions;
|
|
65
89
|
const currentTime = new Date().getTime();
|
|
66
90
|
const { '@shopify/app': appPublic, ...otherPluginsPublic } = await fanoutHooks(config, 'public_command_metadata', {});
|
|
67
|
-
const
|
|
68
|
-
const environmentData = getEnvironmentData(config);
|
|
91
|
+
const { '@shopify/app': appSensitive, ...otherPluginsSensitive } = await fanoutHooks(config, 'sensitive_command_metadata', {});
|
|
92
|
+
const environmentData = await getEnvironmentData(config);
|
|
93
|
+
const sensitiveEnvironmentData = await getSensitiveEnvironmentData(config);
|
|
69
94
|
return {
|
|
70
95
|
public: {
|
|
71
96
|
command: startCommand,
|
|
@@ -84,22 +109,21 @@ const buildPayload = async ({ config, errorMessage }) => {
|
|
|
84
109
|
sensitive: {
|
|
85
110
|
args: startArgs.join(' '),
|
|
86
111
|
error_message: errorMessage,
|
|
112
|
+
...appSensitive,
|
|
113
|
+
...sensitiveEnvironmentData,
|
|
87
114
|
metadata: JSON.stringify({
|
|
88
115
|
...sensitiveMetadata,
|
|
89
116
|
extraPublic: {
|
|
90
117
|
...otherPluginsPublic,
|
|
91
118
|
},
|
|
92
|
-
extraSensitive:
|
|
119
|
+
extraSensitive: { ...otherPluginsSensitive },
|
|
93
120
|
}),
|
|
94
121
|
},
|
|
95
122
|
};
|
|
96
123
|
};
|
|
97
|
-
export function getEnvironmentData(config) {
|
|
124
|
+
export async function getEnvironmentData(config) {
|
|
98
125
|
const ciPlatform = environment.local.ciPlatform();
|
|
99
|
-
const pluginNames = config
|
|
100
|
-
.map((plugin) => plugin.name)
|
|
101
|
-
.sort()
|
|
102
|
-
.filter((plugin) => !plugin.startsWith('@oclif/'));
|
|
126
|
+
const pluginNames = getPluginNames(config);
|
|
103
127
|
const shopifyPlugins = pluginNames.filter((plugin) => plugin.startsWith('@shopify/'));
|
|
104
128
|
const { platform, arch } = platformAndArch();
|
|
105
129
|
return {
|
|
@@ -109,7 +133,23 @@ export function getEnvironmentData(config) {
|
|
|
109
133
|
env_plugin_installed_any_custom: pluginNames.length !== shopifyPlugins.length,
|
|
110
134
|
env_plugin_installed_shopify: JSON.stringify(shopifyPlugins),
|
|
111
135
|
env_shell: config.shell,
|
|
112
|
-
env_web_ide: environment.local.
|
|
136
|
+
env_web_ide: environment.local.cloudEnvironment().editor
|
|
137
|
+
? environment.local.cloudEnvironment().platform
|
|
138
|
+
: undefined,
|
|
139
|
+
env_device_id: hashString(await macAddress()),
|
|
140
|
+
env_cloud: environment.local.cloudEnvironment().platform,
|
|
141
|
+
env_package_manager: (await localCliPackage()) ? await getPackageManager(process.cwd()) : undefined,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async function getSensitiveEnvironmentData(config) {
|
|
145
|
+
return {
|
|
146
|
+
env_plugin_installed_all: JSON.stringify(getPluginNames(config)),
|
|
113
147
|
};
|
|
114
148
|
}
|
|
149
|
+
function getPluginNames(config) {
|
|
150
|
+
return config.plugins
|
|
151
|
+
.map((plugin) => plugin.name)
|
|
152
|
+
.sort()
|
|
153
|
+
.filter((plugin) => !plugin.startsWith('@oclif/'));
|
|
154
|
+
}
|
|
115
155
|
//# sourceMappingURL=analytics.js.map
|
package/dist/analytics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;AACvC,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,EAAC,YAAY,EAAE,sBAAsB,EAAC,MAAM,eAAe,CAAA;AAClE,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,EAAC,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AK,EAAE,GAAG,QAAQ,IAAI,IAAI,EAAE;QAC5B,MAAM,EAAE,UAAU,CAAC,IAAI;QACvB,eAAe,EAAE,UAAU,CAAC,IAAI;QAChC,+BAA+B,EAAE,WAAW,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM;QAC7E,4BAA4B,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;QAC5D,SAAS,EAAE,MAAM,CAAC,KAAK;QACvB,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,cAAc,EAAE;KAChD,CAAA;AACH,CAAC","sourcesContent":["import * as environment from './environment.js'\nimport {platformAndArch} from './os.js'\nimport {version as rubyVersion} from './node/ruby.js'\nimport {content, debug, token} from './output.js'\nimport constants from './constants.js'\nimport * as metadata from './metadata.js'\nimport {publishEvent, MONORAIL_COMMAND_TOPIC} from './monorail.js'\nimport {fanoutHooks} from './plugins.js'\nimport {packageManagerUsedForCreating} from './node/node-package-manager.js'\nimport BaseCommand from './node/base-command.js'\nimport {Interfaces} from '@oclif/core'\n\ninterface StartOptions {\n command: string\n args: string[]\n currentTime?: number\n commandClass?: Interfaces.Command.Class | typeof BaseCommand\n}\n\nexport const start = async ({command, args, currentTime = new Date().getTime(), commandClass}: StartOptions) => {\n let startCommand: string = command\n if (commandClass && Object.prototype.hasOwnProperty.call(commandClass, 'analyticsNameOverride')) {\n startCommand = (commandClass as typeof BaseCommand).analyticsNameOverride() ?? command\n }\n\n await metadata.addSensitive(() => ({\n commandStartOptions: {\n startTime: currentTime,\n startCommand,\n startArgs: args,\n },\n }))\n\n await metadata.addPublic(() => ({\n cmd_all_launcher: packageManagerUsedForCreating(),\n cmd_all_plugin: commandClass?.plugin?.name,\n }))\n}\n\ninterface ReportEventOptions {\n config: Interfaces.Config\n errorMessage?: string\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 reportEvent(options: ReportEventOptions) {\n try {\n const payload = await buildPayload(options)\n if (payload === undefined) {\n // Nothing to log\n return\n }\n if (!environment.local.alwaysLogAnalytics() && environment.local.analyticsDisabled()) {\n debug(content`Skipping command analytics, payload: ${token.json(payload)}`)\n return\n }\n const response = await publishEvent(MONORAIL_COMMAND_TOPIC, payload.public, payload.sensitive)\n if (response.type === 'error') {\n debug(response.message)\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 debug(message)\n }\n}\n\nconst buildPayload = async ({config, errorMessage}: ReportEventOptions) => {\n const {commandStartOptions, ...sensitiveMetadata} = metadata.getAllSensitive()\n if (commandStartOptions === undefined) {\n debug('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 const {'@shopify/app': appPublic, ...otherPluginsPublic} = await fanoutHooks(config, 'public_command_metadata', {})\n const sensitivePluginData = await fanoutHooks(config, 'sensitive_command_metadata', {})\n\n const environmentData = getEnvironmentData(config)\n\n return {\n public: {\n command: startCommand,\n time_start: startTime,\n time_end: currentTime,\n total_time: currentTime - startTime,\n success: errorMessage === undefined,\n cli_version: await constants.versions.cliKit(),\n ruby_version: (await rubyVersion()) || '',\n node_version: process.version.replace('v', ''),\n is_employee: await environment.local.isShopify(),\n ...environmentData,\n ...appPublic,\n ...metadata.getAllPublic(),\n },\n sensitive: {\n args: startArgs.join(' '),\n error_message: errorMessage,\n metadata: JSON.stringify({\n ...sensitiveMetadata,\n extraPublic: {\n ...otherPluginsPublic,\n },\n extraSensitive: sensitivePluginData,\n }),\n },\n }\n}\n\nexport function getEnvironmentData(config: Interfaces.Config) {\n const ciPlatform = environment.local.ciPlatform()\n\n const pluginNames = config.plugins\n .map((plugin) => plugin.name)\n .sort()\n .filter((plugin) => !plugin.startsWith('@oclif/'))\n const shopifyPlugins = pluginNames.filter((plugin) => plugin.startsWith('@shopify/'))\n\n const {platform, arch} = platformAndArch()\n\n return {\n uname: `${platform} ${arch}`,\n env_ci: ciPlatform.isCI,\n env_ci_platform: ciPlatform.name,\n env_plugin_installed_any_custom: pluginNames.length !== shopifyPlugins.length,\n env_plugin_installed_shopify: JSON.stringify(shopifyPlugins),\n env_shell: config.shell,\n env_web_ide: environment.local.webIDEPlatform(),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;AACvC,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,EAAC,YAAY,EAAE,sBAAsB,EAAC,MAAM,eAAe,CAAA;AAClE,OAAO,EAAC,WAAW,EAAE,sBAAsB,EAAC,MAAM,cAAc,CAAA;AAChE,OAAO,EAAC,iBAAiB,EAAE,6BAA6B,EAAC,MAAM,gCAAgC,CAAA;AAG/F,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAA;AAU7C,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAAE,EAAC,cAAc,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,EAAe,EAAE,EAAE;IACpH,IAAI,YAAY,GAAW,cAAc,CAAC,OAAO,CAAA;IACjD,IAAI,YAAY,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,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,CAAC;SAC5B,IAAI,EAAE;SACN,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAA;AACtD,CAAC","sourcesContent":["import * as environment from './environment.js'\nimport {platformAndArch} from './os.js'\nimport {version as rubyVersion} from './node/ruby.js'\nimport {content, debug, token} from './output.js'\nimport constants from './constants.js'\nimport * as metadata from './metadata.js'\nimport {publishEvent, MONORAIL_COMMAND_TOPIC} from './monorail.js'\nimport {fanoutHooks, getListOfTunnelPlugins} from './plugins.js'\nimport {getPackageManager, packageManagerUsedForCreating} from './node/node-package-manager.js'\nimport BaseCommand from './node/base-command.js'\nimport {CommandContent} from './node/hooks/prerun.js'\nimport {hashString} from './string.js'\nimport {macAddress} from './environment/local.js'\nimport {localCliPackage} from './node/cli.js'\nimport {Config, Interfaces} from '@oclif/core'\n\ninterface StartOptions {\n commandContent: CommandContent\n args: string[]\n currentTime?: number\n commandClass?: Interfaces.Command.Class | typeof BaseCommand\n}\n\nexport const start = async ({commandContent, args, currentTime = new Date().getTime(), commandClass}: StartOptions) => {\n let startCommand: string = commandContent.command\n if (commandClass && Object.prototype.hasOwnProperty.call(commandClass, 'analyticsNameOverride')) {\n startCommand = (commandClass as typeof BaseCommand).analyticsNameOverride() ?? commandContent.command\n }\n\n await metadata.addSensitive(() => ({\n commandStartOptions: {\n startTime: currentTime,\n startCommand,\n startArgs: args,\n },\n }))\n\n await metadata.addPublic(() => ({\n cmd_all_launcher: packageManagerUsedForCreating(),\n cmd_all_alias_used: commandContent.alias,\n cmd_all_topic: commandContent.topic,\n cmd_all_plugin: commandClass?.plugin?.name,\n }))\n}\n\ninterface ReportEventOptions {\n config: Interfaces.Config\n errorMessage?: string\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 reportEvent(options: ReportEventOptions) {\n try {\n const payload = await buildPayload(options)\n if (payload === undefined) {\n // Nothing to log\n return\n }\n if (!environment.local.alwaysLogAnalytics() && environment.local.analyticsDisabled()) {\n debug(content`Skipping command analytics, payload: ${token.json(payload)}`)\n return\n }\n const response = await publishEvent(MONORAIL_COMMAND_TOPIC, payload.public, payload.sensitive)\n if (response.type === 'error') {\n debug(response.message)\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 debug(message)\n }\n}\n\n/**\n * Return the name of the tunnel provider used to send analytics. Returns 'localhost' or provider name if any of those\n * strings are included in the {@link tunnelUrl} param. Resturns 'custom' otherwise\n *\n * @param {Config} options - Oclif configuration. Needed to call the hook for retrieving the list of tunner providers\n * @param {string} tunnelUrl - Tunnel url. Used as pattern to match provider name\n * @returns {Promise<string | undefined>} - Returns 'localhost' or provider name if any of those strings are included in\n * the tunnelUrl. Resturns 'custom' other wise\n */\nexport async function getAnalyticsTunnelType(options: Config, tunnelUrl: string): Promise<string | undefined> {\n if (!tunnelUrl) {\n return\n }\n\n if (tunnelUrl.includes('localhost')) {\n return 'localhost'\n }\n\n const provider = (await getListOfTunnelPlugins(options)).plugins.find((plugin) => tunnelUrl?.includes(plugin))\n return provider ?? 'custom'\n}\n\nconst buildPayload = async ({config, errorMessage}: ReportEventOptions) => {\n const {commandStartOptions, ...sensitiveMetadata} = metadata.getAllSensitive()\n if (commandStartOptions === undefined) {\n debug('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 const {'@shopify/app': appPublic, ...otherPluginsPublic} = await fanoutHooks(config, 'public_command_metadata', {})\n const {'@shopify/app': appSensitive, ...otherPluginsSensitive} = await fanoutHooks(\n config,\n 'sensitive_command_metadata',\n {},\n )\n\n const environmentData = await getEnvironmentData(config)\n const sensitiveEnvironmentData = await getSensitiveEnvironmentData(config)\n\n return {\n public: {\n command: startCommand,\n time_start: startTime,\n time_end: currentTime,\n total_time: currentTime - startTime,\n success: errorMessage === undefined,\n cli_version: await constants.versions.cliKit(),\n ruby_version: (await rubyVersion()) || '',\n node_version: process.version.replace('v', ''),\n is_employee: await environment.local.isShopify(),\n ...environmentData,\n ...appPublic,\n ...metadata.getAllPublic(),\n },\n sensitive: {\n args: startArgs.join(' '),\n error_message: errorMessage,\n ...appSensitive,\n ...sensitiveEnvironmentData,\n metadata: JSON.stringify({\n ...sensitiveMetadata,\n extraPublic: {\n ...otherPluginsPublic,\n },\n extraSensitive: {...otherPluginsSensitive},\n }),\n },\n }\n}\n\nexport async function getEnvironmentData(config: Interfaces.Config) {\n const ciPlatform = environment.local.ciPlatform()\n\n const pluginNames = getPluginNames(config)\n const shopifyPlugins = pluginNames.filter((plugin) => plugin.startsWith('@shopify/'))\n\n const {platform, arch} = platformAndArch()\n\n return {\n uname: `${platform} ${arch}`,\n env_ci: ciPlatform.isCI,\n env_ci_platform: ciPlatform.name,\n env_plugin_installed_any_custom: pluginNames.length !== shopifyPlugins.length,\n env_plugin_installed_shopify: JSON.stringify(shopifyPlugins),\n env_shell: config.shell,\n env_web_ide: environment.local.cloudEnvironment().editor\n ? environment.local.cloudEnvironment().platform\n : undefined,\n env_device_id: hashString(await macAddress()),\n env_cloud: environment.local.cloudEnvironment().platform,\n env_package_manager: (await localCliPackage()) ? await getPackageManager(process.cwd()) : undefined,\n }\n}\n\nasync function getSensitiveEnvironmentData(config: Interfaces.Config) {\n return {\n env_plugin_installed_all: JSON.stringify(getPluginNames(config)),\n }\n}\n\nfunction getPluginNames(config: Interfaces.Config) {\n return config.plugins\n .map((plugin) => plugin.name)\n .sort()\n .filter((plugin) => !plugin.startsWith('@oclif/'))\n}\n"]}
|
|
@@ -48,7 +48,26 @@ export declare function isDebugGoBinary(env?: NodeJS.ProcessEnv): boolean;
|
|
|
48
48
|
export declare function useDeviceAuth(env?: NodeJS.ProcessEnv): boolean;
|
|
49
49
|
export declare function gitpodURL(env?: NodeJS.ProcessEnv): string | undefined;
|
|
50
50
|
export declare function codespaceURL(env?: NodeJS.ProcessEnv): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if the CLI is run from a cloud environment
|
|
53
|
+
*
|
|
54
|
+
* @param {NodeJS.ProcessEnv} env - Environment variables used when the cli is launched
|
|
55
|
+
*
|
|
56
|
+
* @returns {boolean} True in case the CLI is run from a cloud environment
|
|
57
|
+
*/
|
|
51
58
|
export declare function isCloudEnvironment(env?: NodeJS.ProcessEnv): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the cloud environment platform name and if the platform support online IDE in case the CLI is run from one of
|
|
61
|
+
* them. Platform name 'localhost' is returned otherwise
|
|
62
|
+
*
|
|
63
|
+
* @param {NodeJS.ProcessEnv} env - Environment variables used when the cli is launched
|
|
64
|
+
*
|
|
65
|
+
* @returns {{platform: 'spin' | 'codespaces' | 'gitpod' | 'localhost', editor: boolean}} - Cloud platform information
|
|
66
|
+
*/
|
|
67
|
+
export declare function cloudEnvironment(env?: NodeJS.ProcessEnv): {
|
|
68
|
+
platform: 'spin' | 'codespaces' | 'gitpod' | 'localhost';
|
|
69
|
+
editor: boolean;
|
|
70
|
+
};
|
|
52
71
|
/**
|
|
53
72
|
* Returns whether the environment has Git available.
|
|
54
73
|
* @returns {Promise<boolean>} A promise that resolves with the value.
|
|
@@ -65,6 +84,8 @@ export declare function ciPlatform(env?: NodeJS.ProcessEnv): {
|
|
|
65
84
|
name?: undefined;
|
|
66
85
|
};
|
|
67
86
|
/**
|
|
68
|
-
*
|
|
87
|
+
* Returns the first mac address found
|
|
88
|
+
*
|
|
89
|
+
* @returns {Promise<string>} Mac address
|
|
69
90
|
*/
|
|
70
|
-
export declare function
|
|
91
|
+
export declare function macAddress(): Promise<string>;
|
|
@@ -4,6 +4,7 @@ import constants from '../constants.js';
|
|
|
4
4
|
import { exists as fileExists } from '../file.js';
|
|
5
5
|
import { exec } from '../system.js';
|
|
6
6
|
import isInteractive from 'is-interactive';
|
|
7
|
+
import macaddress from 'macaddress';
|
|
7
8
|
import { homedir } from 'node:os';
|
|
8
9
|
/**
|
|
9
10
|
* It returns true if the terminal is interactive.
|
|
@@ -86,14 +87,35 @@ export function gitpodURL(env = process.env) {
|
|
|
86
87
|
export function codespaceURL(env = process.env) {
|
|
87
88
|
return env[constants.environmentVariables.codespaceName];
|
|
88
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Checks if the CLI is run from a cloud environment
|
|
92
|
+
*
|
|
93
|
+
* @param {NodeJS.ProcessEnv} env - Environment variables used when the cli is launched
|
|
94
|
+
*
|
|
95
|
+
* @returns {boolean} True in case the CLI is run from a cloud environment
|
|
96
|
+
*/
|
|
89
97
|
export function isCloudEnvironment(env = process.env) {
|
|
90
|
-
return
|
|
98
|
+
return cloudEnvironment(env).platform !== 'localhost';
|
|
91
99
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Returns the cloud environment platform name and if the platform support online IDE in case the CLI is run from one of
|
|
102
|
+
* them. Platform name 'localhost' is returned otherwise
|
|
103
|
+
*
|
|
104
|
+
* @param {NodeJS.ProcessEnv} env - Environment variables used when the cli is launched
|
|
105
|
+
*
|
|
106
|
+
* @returns {{platform: 'spin' | 'codespaces' | 'gitpod' | 'localhost', editor: boolean}} - Cloud platform information
|
|
107
|
+
*/
|
|
108
|
+
export function cloudEnvironment(env = process.env) {
|
|
109
|
+
if (isTruthy(env[constants.environmentVariables.codespaces])) {
|
|
110
|
+
return { platform: 'codespaces', editor: true };
|
|
111
|
+
}
|
|
112
|
+
if (isTruthy(env[constants.environmentVariables.gitpod])) {
|
|
113
|
+
return { platform: 'gitpod', editor: true };
|
|
114
|
+
}
|
|
115
|
+
if (isTruthy(env[constants.environmentVariables.spin])) {
|
|
116
|
+
return { platform: 'spin', editor: false };
|
|
117
|
+
}
|
|
118
|
+
return { platform: 'localhost', editor: false };
|
|
97
119
|
}
|
|
98
120
|
/**
|
|
99
121
|
* Returns whether the environment has Git available.
|
|
@@ -134,13 +156,11 @@ export function ciPlatform(env = process.env) {
|
|
|
134
156
|
};
|
|
135
157
|
}
|
|
136
158
|
/**
|
|
137
|
-
*
|
|
159
|
+
* Returns the first mac address found
|
|
160
|
+
*
|
|
161
|
+
* @returns {Promise<string>} Mac address
|
|
138
162
|
*/
|
|
139
|
-
export function
|
|
140
|
-
|
|
141
|
-
return 'codespaces';
|
|
142
|
-
if (isGitpod(env))
|
|
143
|
-
return 'gitpod';
|
|
144
|
-
return undefined;
|
|
163
|
+
export function macAddress() {
|
|
164
|
+
return macaddress.one();
|
|
145
165
|
}
|
|
146
166
|
//# sourceMappingURL=local.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/environment/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAC,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAA;AAChC,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAC,MAAM,IAAI,UAAU,EAAC,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAA;AACjC,OAAO,aAAa,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAA;AAE/B;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,aAAa,EAAE,CAAA;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,EAAE,CAAA;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC7C,OAAO,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,aAAa,CAAA;AAClE,CAAC;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AAG;IACjC,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI;QACF,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;QAChC,OAAO,IAAI,CAAA;QACX,qDAAqD;KACtD;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC1C,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QACpB,IAAI,IAAI,GAAG,SAAS,CAAA;QACpB,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YAC1B,IAAI,GAAG,UAAU,CAAA;SAClB;aAAM,IAAI,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YACnC,IAAI,GAAG,QAAQ,CAAA;SAChB;aAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YAClC,IAAI,GAAG,QAAQ,CAAA;SAChB;QAED,OAAO;YACL,IAAI,EAAE,IAAI;YACV,IAAI;SACL,CAAA;KACF;IACD,OAAO;QACL,IAAI,EAAE,KAAK;KACZ,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC9C,IAAI,YAAY,CAAC,GAAG,CAAC;QAAE,OAAO,YAAY,CAAA;IAC1C,IAAI,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,QAAQ,CAAA;IAClC,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import {isTruthy, isSet} from './utilities.js'\nimport {isSpin} from './spin.js'\nimport constants from '../constants.js'\nimport {exists as fileExists} from '../file.js'\nimport {exec} from '../system.js'\nimport isInteractive from 'is-interactive'\nimport {homedir} from 'node:os'\n\n/**\n * It returns true if the terminal is interactive.\n * @returns {boolean} 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 * @returns {string} 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 * @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[constants.environmentVariables.env] === 'development'\n}\n\n/**\n * Returns true if the CLI is running in verbose mode.\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[constants.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) or a cloud environment (spin).\n * @returns {boolean} 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, constants.environmentVariables.runAsUser)) {\n return !isTruthy(env[constants.environmentVariables.runAsUser])\n }\n const devInstalled = await fileExists(constants.paths.executables.dev)\n return devInstalled || isSpin(env)\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 * @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[constants.environmentVariables.unitTest])\n}\n\n/**\n * Returns true if reporting analytics is enabled.\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[constants.environmentVariables.noAnalytics]) || isDevelopment(env)\n}\n\n/** Returns true if reporting analytics should always happen, regardless of DEBUG mode etc. */\nexport function alwaysLogAnalytics(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.alwaysLogAnalytics])\n}\n\nexport function firstPartyDev(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.firstPartyDev])\n}\n\nexport function isDebugGoBinary(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.debugGoBinary])\n}\n\nexport function useDeviceAuth(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.deviceAuth]) || isCloudEnvironment(env)\n}\n\n// https://www.gitpod.io/docs/environment-variables#default-environment-variables\nexport function gitpodURL(env = process.env): string | undefined {\n return env[constants.environmentVariables.gitpod]\n}\n\n// https://docs.github.com/en/codespaces/developing-in-codespaces/default-environment-variables-for-your-codespace#list-of-default-environment-variables\nexport function codespaceURL(env = process.env): string | undefined {\n return env[constants.environmentVariables.codespaceName]\n}\n\nexport function isCloudEnvironment(env = process.env): boolean {\n return isCodespaces(env) || isGitpod(env) || isSpin(env)\n}\n\nfunction isCodespaces(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.codespaces])\n}\n\nfunction isGitpod(env = process.env): boolean {\n return isSet(env[constants.environmentVariables.gitpod])\n}\n\n/**\n * Returns whether the environment has Git available.\n * @returns {Promise<boolean>} 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 */\nexport function ciPlatform(env = process.env): {isCI: true; name: string} | {isCI: false; name?: undefined} {\n if (isTruthy(env.CI)) {\n let name = 'unknown'\n 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 }\n\n return {\n isCI: true,\n name,\n }\n }\n return {\n isCI: false,\n }\n}\n\n/**\n * Gets info on the Web IDE platform the CLI is running on, if applicable\n */\nexport function webIDEPlatform(env = process.env) {\n if (isCodespaces(env)) return 'codespaces'\n if (isGitpod(env)) return 'gitpod'\n return undefined\n}\n"]}
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/environment/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAC,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAA;AAChC,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAC,MAAM,IAAI,UAAU,EAAC,MAAM,YAAY,CAAA;AAC/C,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,SAAS,CAAA;AAE/B;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,aAAa,EAAE,CAAA;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,EAAE,CAAA;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC7C,OAAO,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,aAAa,CAAA;AAClE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACzC,OAAO,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;AACpG,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG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AAE,MAAM,EAAE,KAAK,EAAC,CAAA;KACzC;IACD,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAC,CAAA;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI;QACF,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;QAChC,OAAO,IAAI,CAAA;QACX,qDAAqD;KACtD;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC1C,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QACpB,IAAI,IAAI,GAAG,SAAS,CAAA;QACpB,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YAC1B,IAAI,GAAG,UAAU,CAAA;SAClB;aAAM,IAAI,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YACnC,IAAI,GAAG,QAAQ,CAAA;SAChB;aAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YAClC,IAAI,GAAG,QAAQ,CAAA;SAChB;QAED,OAAO;YACL,IAAI,EAAE,IAAI;YACV,IAAI;SACL,CAAA;KACF;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","sourcesContent":["import {isTruthy, isSet} from './utilities.js'\nimport {isSpin} from './spin.js'\nimport constants from '../constants.js'\nimport {exists as fileExists} from '../file.js'\nimport {exec} from '../system.js'\nimport isInteractive from 'is-interactive'\nimport macaddress from 'macaddress'\nimport {homedir} from 'node:os'\n\n/**\n * It returns true if the terminal is interactive.\n * @returns {boolean} 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 * @returns {string} 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 * @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[constants.environmentVariables.env] === 'development'\n}\n\n/**\n * Returns true if the CLI is running in verbose mode.\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[constants.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) or a cloud environment (spin).\n * @returns {boolean} 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, constants.environmentVariables.runAsUser)) {\n return !isTruthy(env[constants.environmentVariables.runAsUser])\n }\n const devInstalled = await fileExists(constants.paths.executables.dev)\n return devInstalled || isSpin(env)\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 * @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[constants.environmentVariables.unitTest])\n}\n\n/**\n * Returns true if reporting analytics is enabled.\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[constants.environmentVariables.noAnalytics]) || isDevelopment(env)\n}\n\n/** Returns true if reporting analytics should always happen, regardless of DEBUG mode etc. */\nexport function alwaysLogAnalytics(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.alwaysLogAnalytics])\n}\n\nexport function firstPartyDev(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.firstPartyDev])\n}\n\nexport function isDebugGoBinary(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.debugGoBinary])\n}\n\nexport function useDeviceAuth(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.deviceAuth]) || isCloudEnvironment(env)\n}\n\n// https://www.gitpod.io/docs/environment-variables#default-environment-variables\nexport function gitpodURL(env = process.env): string | undefined {\n return env[constants.environmentVariables.gitpod]\n}\n\n// https://docs.github.com/en/codespaces/developing-in-codespaces/default-environment-variables-for-your-codespace#list-of-default-environment-variables\nexport function codespaceURL(env = process.env): string | undefined {\n return env[constants.environmentVariables.codespaceName]\n}\n\n/**\n * Checks if the CLI is run from a cloud environment\n *\n * @param {NodeJS.ProcessEnv} env - Environment variables used when the cli is launched\n *\n * @returns {boolean} 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 * 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 {NodeJS.ProcessEnv} env - Environment variables used when the cli is launched\n *\n * @returns {{platform: 'spin' | 'codespaces' | 'gitpod' | 'localhost', editor: boolean}} - Cloud platform information\n */\nexport function cloudEnvironment(env: NodeJS.ProcessEnv = process.env): {\n platform: 'spin' | 'codespaces' | 'gitpod' | 'localhost'\n editor: boolean\n} {\n if (isTruthy(env[constants.environmentVariables.codespaces])) {\n return {platform: 'codespaces', editor: true}\n }\n if (isTruthy(env[constants.environmentVariables.gitpod])) {\n return {platform: 'gitpod', editor: true}\n }\n if (isTruthy(env[constants.environmentVariables.spin])) {\n return {platform: 'spin', editor: false}\n }\n return {platform: 'localhost', editor: false}\n}\n\n/**\n * Returns whether the environment has Git available.\n * @returns {Promise<boolean>} 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 */\nexport function ciPlatform(env = process.env): {isCI: true; name: string} | {isCI: false; name?: undefined} {\n if (isTruthy(env.CI)) {\n let name = 'unknown'\n 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 }\n\n return {\n isCI: true,\n name,\n }\n }\n return {\n isCI: false,\n }\n}\n\n/**\n * Returns the first mac address found\n *\n * @returns {Promise<string>} Mac address\n */\nexport function macAddress() {\n return macaddress.one()\n}\n"]}
|
package/dist/metadata.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AnyJson } from './json.js';
|
|
2
|
+
import { MonorailEventPublic } from './monorail.js';
|
|
2
3
|
import { PickByPrefix } from './typing/pick-by-prefix.js';
|
|
3
4
|
declare type ProvideMetadata<T> = () => Partial<T> | Promise<Partial<T>>;
|
|
4
5
|
declare type MetadataErrorHandling = 'auto' | 'mute-and-report' | 'bubble';
|
|
@@ -23,194 +24,27 @@ export declare type SensitiveSchema<T> = T extends RuntimeMetadataManager<infer
|
|
|
23
24
|
export declare function createRuntimeMetadataContainer<TPublic extends AnyJson, TSensitive extends AnyJson = {
|
|
24
25
|
[key: string]: never;
|
|
25
26
|
}>(): RuntimeMetadataManager<TPublic, TSensitive>;
|
|
26
|
-
declare
|
|
27
|
-
|
|
28
|
-
command: string;
|
|
29
|
-
project_type?: (string | null) | undefined;
|
|
30
|
-
time_start: number;
|
|
31
|
-
time_end: number;
|
|
32
|
-
total_time: number;
|
|
33
|
-
success: boolean;
|
|
34
|
-
api_key?: (string | null) | undefined;
|
|
35
|
-
cli_version: string;
|
|
36
|
-
uname: string;
|
|
37
|
-
ruby_version: string;
|
|
38
|
-
node_version: string;
|
|
39
|
-
is_employee: boolean;
|
|
40
|
-
cmd_all_alias_used?: (string | null) | undefined;
|
|
41
|
-
cmd_all_launcher?: (string | null) | undefined;
|
|
42
|
-
cmd_all_path_override?: (boolean | null) | undefined;
|
|
43
|
-
cmd_all_path_override_hash?: (string | null) | undefined;
|
|
44
|
-
cmd_all_plugin?: (string | null) | undefined;
|
|
45
|
-
cmd_all_topic?: (string | null) | undefined;
|
|
46
|
-
cmd_all_verbose?: (boolean | null) | undefined;
|
|
47
|
-
cmd_extensions_binary_from_source?: (boolean | null) | undefined;
|
|
48
|
-
cmd_scaffold_required_auth?: (boolean | null) | undefined;
|
|
49
|
-
cmd_scaffold_template_custom?: (boolean | null) | undefined;
|
|
50
|
-
cmd_scaffold_template_flavor?: (string | null) | undefined;
|
|
51
|
-
cmd_scaffold_type?: (string | null) | undefined;
|
|
52
|
-
cmd_scaffold_type_category?: (string | null) | undefined;
|
|
53
|
-
cmd_scaffold_type_gated?: (boolean | null) | undefined;
|
|
54
|
-
cmd_scaffold_type_owner?: (string | null) | undefined;
|
|
55
|
-
cmd_scaffold_used_prompts_for_type?: (boolean | null) | undefined;
|
|
56
|
-
app_extensions_any?: (boolean | null) | undefined;
|
|
57
|
-
app_extensions_breakdown?: (string | null) | undefined;
|
|
58
|
-
app_extensions_count?: (number | null) | undefined;
|
|
59
|
-
app_extensions_custom_layout?: (boolean | null) | undefined;
|
|
60
|
-
app_extensions_function_any?: (boolean | null) | undefined;
|
|
61
|
-
app_extensions_function_count?: (number | null) | undefined;
|
|
62
|
-
app_extensions_function_custom_layout?: (boolean | null) | undefined;
|
|
63
|
-
app_extensions_theme_any?: (boolean | null) | undefined;
|
|
64
|
-
app_extensions_theme_count?: (number | null) | undefined;
|
|
65
|
-
app_extensions_theme_custom_layout?: (boolean | null) | undefined;
|
|
66
|
-
app_extensions_ui_any?: (boolean | null) | undefined;
|
|
67
|
-
app_extensions_ui_count?: (number | null) | undefined;
|
|
68
|
-
app_extensions_ui_custom_layout?: (boolean | null) | undefined;
|
|
69
|
-
app_name_hash?: (string | null) | undefined;
|
|
70
|
-
app_path_hash?: (string | null) | undefined;
|
|
71
|
-
app_scopes?: (string | null) | undefined;
|
|
72
|
-
app_web_backend_any?: (boolean | null) | undefined;
|
|
73
|
-
app_web_backend_count?: (number | null) | undefined;
|
|
74
|
-
app_web_custom_layout?: (boolean | null) | undefined;
|
|
75
|
-
app_web_frontend_any?: (boolean | null) | undefined;
|
|
76
|
-
app_web_frontend_count?: (number | null) | undefined;
|
|
77
|
-
env_ci?: (boolean | null) | undefined;
|
|
78
|
-
env_ci_platform?: (string | null) | undefined;
|
|
79
|
-
env_plugin_installed_any_custom?: (boolean | null) | undefined;
|
|
80
|
-
env_plugin_installed_shopify?: (string | null) | undefined;
|
|
81
|
-
env_shell?: (string | null) | undefined;
|
|
82
|
-
env_web_ide?: (string | null) | undefined;
|
|
83
|
-
}>, "cmd_all_", never>, {
|
|
27
|
+
declare type CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_all_'> & PickByPrefix<MonorailEventPublic, 'cmd_app_'>;
|
|
28
|
+
declare const coreData: RuntimeMetadataManager<CmdFieldsFromMonorail, {
|
|
84
29
|
commandStartOptions: {
|
|
85
30
|
startTime: number;
|
|
86
31
|
startCommand: string;
|
|
32
|
+
startTopic?: string;
|
|
87
33
|
startArgs: string[];
|
|
88
34
|
};
|
|
89
35
|
}>;
|
|
90
|
-
export declare const getAllPublic: () => Partial<
|
|
91
|
-
partner_id?: (number | null) | undefined;
|
|
92
|
-
command: string;
|
|
93
|
-
project_type?: (string | null) | undefined;
|
|
94
|
-
time_start: number;
|
|
95
|
-
time_end: number;
|
|
96
|
-
total_time: number;
|
|
97
|
-
success: boolean;
|
|
98
|
-
api_key?: (string | null) | undefined;
|
|
99
|
-
cli_version: string;
|
|
100
|
-
uname: string;
|
|
101
|
-
ruby_version: string;
|
|
102
|
-
node_version: string;
|
|
103
|
-
is_employee: boolean;
|
|
104
|
-
cmd_all_alias_used?: (string | null) | undefined;
|
|
105
|
-
cmd_all_launcher?: (string | null) | undefined;
|
|
106
|
-
cmd_all_path_override?: (boolean | null) | undefined;
|
|
107
|
-
cmd_all_path_override_hash?: (string | null) | undefined;
|
|
108
|
-
cmd_all_plugin?: (string | null) | undefined;
|
|
109
|
-
cmd_all_topic?: (string | null) | undefined;
|
|
110
|
-
cmd_all_verbose?: (boolean | null) | undefined;
|
|
111
|
-
cmd_extensions_binary_from_source?: (boolean | null) | undefined;
|
|
112
|
-
cmd_scaffold_required_auth?: (boolean | null) | undefined;
|
|
113
|
-
cmd_scaffold_template_custom?: (boolean | null) | undefined;
|
|
114
|
-
cmd_scaffold_template_flavor?: (string | null) | undefined;
|
|
115
|
-
cmd_scaffold_type?: (string | null) | undefined;
|
|
116
|
-
cmd_scaffold_type_category?: (string | null) | undefined;
|
|
117
|
-
cmd_scaffold_type_gated?: (boolean | null) | undefined;
|
|
118
|
-
cmd_scaffold_type_owner?: (string | null) | undefined;
|
|
119
|
-
cmd_scaffold_used_prompts_for_type?: (boolean | null) | undefined;
|
|
120
|
-
app_extensions_any?: (boolean | null) | undefined;
|
|
121
|
-
app_extensions_breakdown?: (string | null) | undefined;
|
|
122
|
-
app_extensions_count?: (number | null) | undefined;
|
|
123
|
-
app_extensions_custom_layout?: (boolean | null) | undefined;
|
|
124
|
-
app_extensions_function_any?: (boolean | null) | undefined;
|
|
125
|
-
app_extensions_function_count?: (number | null) | undefined;
|
|
126
|
-
app_extensions_function_custom_layout?: (boolean | null) | undefined;
|
|
127
|
-
app_extensions_theme_any?: (boolean | null) | undefined;
|
|
128
|
-
app_extensions_theme_count?: (number | null) | undefined;
|
|
129
|
-
app_extensions_theme_custom_layout?: (boolean | null) | undefined;
|
|
130
|
-
app_extensions_ui_any?: (boolean | null) | undefined;
|
|
131
|
-
app_extensions_ui_count?: (number | null) | undefined;
|
|
132
|
-
app_extensions_ui_custom_layout?: (boolean | null) | undefined;
|
|
133
|
-
app_name_hash?: (string | null) | undefined;
|
|
134
|
-
app_path_hash?: (string | null) | undefined;
|
|
135
|
-
app_scopes?: (string | null) | undefined;
|
|
136
|
-
app_web_backend_any?: (boolean | null) | undefined;
|
|
137
|
-
app_web_backend_count?: (number | null) | undefined;
|
|
138
|
-
app_web_custom_layout?: (boolean | null) | undefined;
|
|
139
|
-
app_web_frontend_any?: (boolean | null) | undefined;
|
|
140
|
-
app_web_frontend_count?: (number | null) | undefined;
|
|
141
|
-
env_ci?: (boolean | null) | undefined;
|
|
142
|
-
env_ci_platform?: (string | null) | undefined;
|
|
143
|
-
env_plugin_installed_any_custom?: (boolean | null) | undefined;
|
|
144
|
-
env_plugin_installed_shopify?: (string | null) | undefined;
|
|
145
|
-
env_shell?: (string | null) | undefined;
|
|
146
|
-
env_web_ide?: (string | null) | undefined;
|
|
147
|
-
}>, "cmd_all_", never>>, getAllSensitive: () => Partial<{
|
|
36
|
+
export declare const getAllPublic: () => Partial<CmdFieldsFromMonorail>, getAllSensitive: () => Partial<{
|
|
148
37
|
commandStartOptions: {
|
|
149
38
|
startTime: number;
|
|
150
39
|
startCommand: string;
|
|
40
|
+
startTopic?: string;
|
|
151
41
|
startArgs: string[];
|
|
152
42
|
};
|
|
153
|
-
}>, addPublic: (getData: ProvideMetadata<
|
|
154
|
-
partner_id?: (number | null) | undefined;
|
|
155
|
-
command: string;
|
|
156
|
-
project_type?: (string | null) | undefined;
|
|
157
|
-
time_start: number;
|
|
158
|
-
time_end: number;
|
|
159
|
-
total_time: number;
|
|
160
|
-
success: boolean;
|
|
161
|
-
api_key?: (string | null) | undefined;
|
|
162
|
-
cli_version: string;
|
|
163
|
-
uname: string;
|
|
164
|
-
ruby_version: string;
|
|
165
|
-
node_version: string;
|
|
166
|
-
is_employee: boolean;
|
|
167
|
-
cmd_all_alias_used?: (string | null) | undefined;
|
|
168
|
-
cmd_all_launcher?: (string | null) | undefined;
|
|
169
|
-
cmd_all_path_override?: (boolean | null) | undefined;
|
|
170
|
-
cmd_all_path_override_hash?: (string | null) | undefined;
|
|
171
|
-
cmd_all_plugin?: (string | null) | undefined;
|
|
172
|
-
cmd_all_topic?: (string | null) | undefined;
|
|
173
|
-
cmd_all_verbose?: (boolean | null) | undefined;
|
|
174
|
-
cmd_extensions_binary_from_source?: (boolean | null) | undefined;
|
|
175
|
-
cmd_scaffold_required_auth?: (boolean | null) | undefined;
|
|
176
|
-
cmd_scaffold_template_custom?: (boolean | null) | undefined;
|
|
177
|
-
cmd_scaffold_template_flavor?: (string | null) | undefined;
|
|
178
|
-
cmd_scaffold_type?: (string | null) | undefined;
|
|
179
|
-
cmd_scaffold_type_category?: (string | null) | undefined;
|
|
180
|
-
cmd_scaffold_type_gated?: (boolean | null) | undefined;
|
|
181
|
-
cmd_scaffold_type_owner?: (string | null) | undefined;
|
|
182
|
-
cmd_scaffold_used_prompts_for_type?: (boolean | null) | undefined;
|
|
183
|
-
app_extensions_any?: (boolean | null) | undefined;
|
|
184
|
-
app_extensions_breakdown?: (string | null) | undefined;
|
|
185
|
-
app_extensions_count?: (number | null) | undefined;
|
|
186
|
-
app_extensions_custom_layout?: (boolean | null) | undefined;
|
|
187
|
-
app_extensions_function_any?: (boolean | null) | undefined;
|
|
188
|
-
app_extensions_function_count?: (number | null) | undefined;
|
|
189
|
-
app_extensions_function_custom_layout?: (boolean | null) | undefined;
|
|
190
|
-
app_extensions_theme_any?: (boolean | null) | undefined;
|
|
191
|
-
app_extensions_theme_count?: (number | null) | undefined;
|
|
192
|
-
app_extensions_theme_custom_layout?: (boolean | null) | undefined;
|
|
193
|
-
app_extensions_ui_any?: (boolean | null) | undefined;
|
|
194
|
-
app_extensions_ui_count?: (number | null) | undefined;
|
|
195
|
-
app_extensions_ui_custom_layout?: (boolean | null) | undefined;
|
|
196
|
-
app_name_hash?: (string | null) | undefined;
|
|
197
|
-
app_path_hash?: (string | null) | undefined;
|
|
198
|
-
app_scopes?: (string | null) | undefined;
|
|
199
|
-
app_web_backend_any?: (boolean | null) | undefined;
|
|
200
|
-
app_web_backend_count?: (number | null) | undefined;
|
|
201
|
-
app_web_custom_layout?: (boolean | null) | undefined;
|
|
202
|
-
app_web_frontend_any?: (boolean | null) | undefined;
|
|
203
|
-
app_web_frontend_count?: (number | null) | undefined;
|
|
204
|
-
env_ci?: (boolean | null) | undefined;
|
|
205
|
-
env_ci_platform?: (string | null) | undefined;
|
|
206
|
-
env_plugin_installed_any_custom?: (boolean | null) | undefined;
|
|
207
|
-
env_plugin_installed_shopify?: (string | null) | undefined;
|
|
208
|
-
env_shell?: (string | null) | undefined;
|
|
209
|
-
env_web_ide?: (string | null) | undefined;
|
|
210
|
-
}>, "cmd_all_", never>>, onError?: MetadataErrorHandling | undefined) => Promise<void>, addSensitive: (getData: ProvideMetadata<{
|
|
43
|
+
}>, addPublic: (getData: ProvideMetadata<CmdFieldsFromMonorail>, onError?: MetadataErrorHandling | undefined) => Promise<void>, addSensitive: (getData: ProvideMetadata<{
|
|
211
44
|
commandStartOptions: {
|
|
212
45
|
startTime: number;
|
|
213
46
|
startCommand: string;
|
|
47
|
+
startTopic?: string;
|
|
214
48
|
startArgs: string[];
|
|
215
49
|
};
|
|
216
50
|
}>, onError?: MetadataErrorHandling | undefined) => Promise<void>;
|
package/dist/metadata.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAA;AAGjD,OAAO,EAAC,kBAAkB,EAAC,MAAM,yBAAyB,CAAA;AAa1D,SAAS,gCAAgC;IACvC,IAAI,UAAU,EAAE,EAAE;QAChB,OAAO,QAAQ,CAAA;KAChB;IACD,OAAO,iBAAiB,CAAA;AAC1B,CAAC;AAgBD;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAI5C,MAAM,GAAG,GAA+D;QACtE,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,EAAE;KACX,CAAA;IACD,MAAM,SAA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AM;YACL,IAAI;gBACF,MAAM,SAAS,EAAE,CAAA;gBACjB,yFAAyF;aAC1F;YAAC,OAAO,KAAU,EAAE;gBACnB,MAAM,kBAAkB,CAAC,KAAK,CAAC,CAAA;aAChC;SACF;IACH,CAAC,CAAA;IAED,OAAO;QACL,YAAY,EAAE,GAAG,EAAE;YACjB,OAAO,EAAC,GAAG,GAAG,CAAC,MAAM,EAAC,CAAA;QACxB,CAAC;QACD,eAAe,EAAE,GAAG,EAAE;YACpB,OAAO,EAAC,GAAG,GAAG,CAAC,SAAS,EAAC,CAAA;QAC3B,CAAC;QACD,SAAS,EAAE,KAAK,EAAE,OAAiC,EAAE,UAAiC,MAAM,EAAE,EAAE;YAC9F,OAAO,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACjD,CAAC;QACD,YAAY,EAAE,KAAK,EAAE,OAAoC,EAAE,UAAiC,MAAM,EAAE,EAAE;YACpG,OAAO,WAAW,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACpD,CAAC;KACF,CAAA;AACH,CAAC;AAOD,MAAM,QAAQ,GAAG,8BAA8B,EAU5C,CAAA;AAEH,MAAM,CAAC,MAAM,EAAC,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAC,GAAG,QAAQ,CAAA","sourcesContent":["import {isUnitTest} from './environment/local.js'\nimport {AnyJson} from './json.js'\nimport {MonorailEventPublic} from './monorail.js'\nimport {sendErrorToBugsnag} from './node/error-handler.js'\nimport {PickByPrefix} from './typing/pick-by-prefix.js'\n\ntype ProvideMetadata<T> = () => Partial<T> | Promise<Partial<T>>\n\ntype MetadataErrorHandling =\n // Mute & report errors in production, throw them whilst testing\n | 'auto'\n // Errors are not reported to the user and do not stop execution, but they are reported to Bugsnag\n | 'mute-and-report'\n // Errors are not caught and will bubble out as normal\n | 'bubble'\n\nfunction getMetadataErrorHandlingStrategy(): 'mute-and-report' | 'bubble' {\n if (isUnitTest()) {\n return 'bubble'\n }\n return 'mute-and-report'\n}\n\nexport interface RuntimeMetadataManager<TPublic extends AnyJson, TSensitive extends AnyJson> {\n /** Add some public metadata -- this should not contain any PII */\n addPublic: (getData: ProvideMetadata<TPublic>, onError?: MetadataErrorHandling) => Promise<void>\n /** Add some potentially sensitive metadata -- this may include PII, but unnecessary data should never be tracked (this is a good fit for command args for instance) */\n addSensitive: (getData: ProvideMetadata<TSensitive>, onError?: MetadataErrorHandling) => Promise<void>\n /** Get a snapshot of the tracked public data */\n getAllPublic: () => Partial<TPublic>\n /** Get a snapshot of the tracked sensitive data */\n getAllSensitive: () => Partial<TSensitive>\n}\n\nexport type PublicSchema<T> = T extends RuntimeMetadataManager<infer TPublic, infer _TSensitive> ? TPublic : never\nexport type SensitiveSchema<T> = T extends RuntimeMetadataManager<infer _TPublic, infer TSensitive> ? TSensitive : never\n\n/**\n * Creates a container for metadata collected at runtime.\n *\n * The container provides async-safe functions for extracting the gathered metadata, and for setting it.\n *\n */\nexport function createRuntimeMetadataContainer<\n TPublic extends AnyJson,\n TSensitive extends AnyJson = {[key: string]: never},\n>(): RuntimeMetadataManager<TPublic, TSensitive> {\n const raw: {sensitive: Partial<TSensitive>; public: Partial<TPublic>} = {\n sensitive: {},\n public: {},\n }\n const addPublic = (data: Partial<TPublic>) => {\n Object.assign(raw.public, data)\n }\n const addSensitive = (data: Partial<TSensitive>) => {\n Object.assign(raw.sensitive, data)\n }\n\n const addMetadata = async <T>(\n addFn: (data: Partial<T>) => void,\n getFn: ProvideMetadata<T>,\n onError: MetadataErrorHandling,\n ) => {\n const errorHandling = onError === 'auto' ? getMetadataErrorHandlingStrategy() : onError\n const getAndSet = async () => {\n const data = await getFn()\n addFn(data)\n }\n\n if (errorHandling === 'bubble') {\n await getAndSet()\n } else {\n try {\n await getAndSet()\n // eslint-disable-next-line no-catch-all/no-catch-all, @typescript-eslint/no-explicit-any\n } catch (error: any) {\n await sendErrorToBugsnag(error)\n }\n }\n }\n\n return {\n getAllPublic: () => {\n return {...raw.public}\n },\n getAllSensitive: () => {\n return {...raw.sensitive}\n },\n addPublic: async (getData: ProvideMetadata<TPublic>, onError: MetadataErrorHandling = 'auto') => {\n return addMetadata(addPublic, getData, onError)\n },\n addSensitive: async (getData: ProvideMetadata<TSensitive>, onError: MetadataErrorHandling = 'auto') => {\n return addMetadata(addSensitive, getData, onError)\n },\n }\n}\n\n// We want to track anything that ends up getting sent to monorail as `cmd_all_*` and\n// `cmd_app_*`\ntype CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_all_'> &\n PickByPrefix<MonorailEventPublic, 'cmd_app_'>\n\nconst coreData = createRuntimeMetadataContainer<\n CmdFieldsFromMonorail,\n {\n commandStartOptions: {\n startTime: number\n startCommand: string\n startTopic?: string\n startArgs: string[]\n }\n }\n>()\n\nexport const {getAllPublic, getAllSensitive, addPublic, addSensitive} = coreData\n\nexport type Public = PublicSchema<typeof coreData>\nexport type Sensitive = SensitiveSchema<typeof coreData>\n"]}
|