@shopify/cli-kit 3.14.0 → 3.16.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/analytics.d.ts +20 -6
  3. package/dist/analytics.js +54 -14
  4. package/dist/analytics.js.map +1 -1
  5. package/dist/api/common.js +1 -1
  6. package/dist/api/common.js.map +1 -1
  7. package/dist/api/graphql/functions/api_schema_definition.d.ts +9 -0
  8. package/dist/api/graphql/functions/api_schema_definition.js +7 -0
  9. package/dist/api/graphql/functions/api_schema_definition.js.map +1 -0
  10. package/dist/api/graphql/index.d.ts +1 -0
  11. package/dist/api/graphql/index.js +1 -0
  12. package/dist/api/graphql/index.js.map +1 -1
  13. package/dist/common/object.d.ts +8 -0
  14. package/dist/common/object.js +12 -0
  15. package/dist/common/object.js.map +1 -0
  16. package/dist/environment/local.d.ts +23 -2
  17. package/dist/environment/local.js +33 -13
  18. package/dist/environment/local.js.map +1 -1
  19. package/dist/file.d.ts +12 -0
  20. package/dist/file.js +18 -0
  21. package/dist/file.js.map +1 -1
  22. package/dist/http.d.ts +1 -0
  23. package/dist/http.js +1 -0
  24. package/dist/http.js.map +1 -1
  25. package/dist/index.d.ts +0 -1
  26. package/dist/index.js +0 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/metadata.d.ts +8 -174
  29. package/dist/metadata.js.map +1 -1
  30. package/dist/monorail.d.ts +16 -1
  31. package/dist/monorail.js +1 -1
  32. package/dist/monorail.js.map +1 -1
  33. package/dist/node/cli.d.ts +7 -0
  34. package/dist/node/cli.js +1 -1
  35. package/dist/node/cli.js.map +1 -1
  36. package/dist/node/error-handler.js +1 -1
  37. package/dist/node/error-handler.js.map +1 -1
  38. package/dist/node/framework.d.ts +8 -0
  39. package/dist/node/framework.js +135 -0
  40. package/dist/node/framework.js.map +1 -0
  41. package/dist/node/hooks/prerun.d.ts +10 -0
  42. package/dist/node/hooks/prerun.js +59 -4
  43. package/dist/node/hooks/prerun.js.map +1 -1
  44. package/dist/node/node-package-manager.d.ts +13 -0
  45. package/dist/node/node-package-manager.js +14 -0
  46. package/dist/node/node-package-manager.js.map +1 -1
  47. package/dist/output.d.ts +1 -0
  48. package/dist/output.js +1 -1
  49. package/dist/output.js.map +1 -1
  50. package/dist/plugins.d.ts +11 -1
  51. package/dist/plugins.js.map +1 -1
  52. package/dist/public/common/array.d.ts +1 -1
  53. package/dist/public/common/array.js.map +1 -1
  54. package/dist/public/node/presets.d.ts +6 -0
  55. package/dist/public/node/presets.js +26 -0
  56. package/dist/public/node/presets.js.map +1 -0
  57. package/dist/session/redirect-listener.js +11 -6
  58. package/dist/session/redirect-listener.js.map +1 -1
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +7 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @shopify/cli-kit
2
2
 
3
+ ## 3.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d460e738: Add the `app generate schema <function-name>` command
8
+
9
+ ## 3.15.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 9f7d90d9: Add dev, build, deploy and another additional baseline instrumentantion
14
+
3
15
  ## 3.14.0
4
16
 
5
17
  ### Minor Changes
@@ -1,12 +1,13 @@
1
1
  import BaseCommand from './node/base-command.js';
2
- import { Interfaces } from '@oclif/core';
2
+ import { CommandContent } from './node/hooks/prerun.js';
3
+ import { Config, Interfaces } from '@oclif/core';
3
4
  interface StartOptions {
4
- command: string;
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: ({ command, args, currentTime, commandClass }: StartOptions) => Promise<void>;
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
- export declare function getEnvironmentData(config: Interfaces.Config): {
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: string | undefined;
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
- export const start = async ({ command, args, currentTime = new Date().getTime(), commandClass }) => {
11
- let startCommand = command;
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 sensitivePluginData = await fanoutHooks(config, 'sensitive_command_metadata', {});
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: sensitivePluginData,
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.plugins
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.webIDEPlatform(),
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
@@ -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,6BAA6B,EAAC,MAAM,gCAAgC,CAAA;AAW5E,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,EAAe,EAAE,EAAE;IAC7G,IAAI,YAAY,GAAW,OAAO,CAAA;IAClC,IAAI,YAAY,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,uBAA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,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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AE,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,gBAAgB,EAAE,CAAC,MAAM;YACtD,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,QAAQ;YAC/C,CAAC,CAAC,SAAS;QACb,aAAa,EAAE,UAAU,CAAC,MAAM,UAAU,EAAE,CAAC;QAC7C,SAAS,EAAE,WAAW,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,QAAQ;QACxD,mBAAmB,EAAE,CAAC,MAAM,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;KACpG,CAAA;AACH,CAAC;AAED,KAAK,UAAU,2BAA2B,CAAC,MAAyB;IAClE,OAAO;QACL,wBAAwB,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;KACjE,CAAA;AACH,CAAC;AAED,SAAS,cAAc,CAAC,MAAyB;IAC/C,OAAO,MAAM,CAAC,OAAO;SAClB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,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"]}
@@ -45,7 +45,7 @@ export function sanitizedHeadersOutput(headers) {
45
45
  }
46
46
  export function debugLogRequest(api, query, variables, headers = {}) {
47
47
  debug(`
48
- Sending ${token.raw(api)} GraphQL request:
48
+ Sending ${token.json(api)} GraphQL request:
49
49
  ${query}
50
50
 
51
51
  With variables:
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/api/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAA;AACrD,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,cAAc,CAAA;AAC1F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WAAW,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,CAAA;aACtC;YACD,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;YAC/B,MAAM,WAAW,CAAA;SAClB;aAAM;YACL,MAAM,KAAK,CAAA;SACZ;KACF;AACH,CAAC","sourcesContent":["import {firstPartyDev} from '../environment/local.js'\nimport constants from '../constants.js'\nimport {stringifyMessage, content, token as outputToken, token, debug} from '../output.js'\nimport {Abort, ExtendableError} from '../error.js'\nimport {ClientError, RequestDocument, Variables} from 'graphql-request'\nimport {randomUUID} from 'crypto'\n\nexport class RequestClientError extends ExtendableError {\n statusCode: number\n public constructor(message: string, statusCode: number) {\n super(message)\n this.statusCode = statusCode\n }\n}\n\nexport async function buildHeaders(token: string): Promise<{[key: string]: string}> {\n const userAgent = `Shopify CLI; v=${await constants.versions.cliKit()}`\n\n const headers = {\n 'User-Agent': userAgent,\n // 'Sec-CH-UA': secCHUA, This header requires the Git sha.\n 'Sec-CH-UA-PLATFORM': process.platform,\n 'X-Request-Id': randomUUID(),\n authorization: `Bearer ${token}`,\n 'X-Shopify-Access-Token': `Bearer ${token}`,\n 'Content-Type': 'application/json',\n ...(firstPartyDev() && {'X-Shopify-Cli-Employee': '1'}),\n }\n\n return headers\n}\n\n/**\n * Removes the sensitive data from the headers and outputs them as a string.\n * @param headers {{[key: string]: string}} HTTP headers.\n * @returns {string} A sanitized version of the headers as a string.\n */\nexport function sanitizedHeadersOutput(headers: {[key: string]: string}): string {\n const sanitized: {[key: string]: string} = {}\n const keywords = ['token', 'authorization']\n Object.keys(headers).forEach((header) => {\n if (keywords.find((keyword) => header.toLocaleLowerCase().includes(keyword)) === undefined) {\n sanitized[header] = headers[header]!\n }\n })\n return Object.keys(sanitized)\n .map((header) => {\n return ` - ${header}: ${sanitized[header]}`\n })\n .join('\\n')\n}\n\nexport function debugLogRequest<T>(\n api: string,\n query: RequestDocument,\n variables?: Variables,\n headers: {[key: string]: string} = {},\n) {\n debug(`\nSending ${token.raw(api)} GraphQL request:\n${query}\n\nWith variables:\n${variables ? JSON.stringify(variables, null, 2) : ''}\n\nAnd headers:\n${sanitizedHeadersOutput(headers)}\n`)\n}\n\nexport async function handlingErrors<T>(api: string, action: () => Promise<T>): Promise<T> {\n try {\n return await action()\n } catch (error) {\n if (error instanceof ClientError) {\n const errorMessage = stringifyMessage(content`\n The ${token.raw(\n api,\n )} GraphQL API responded unsuccessfully with the HTTP status ${`${error.response.status}`} and errors:\n\n ${outputToken.json(error.response.errors)}\n `)\n let mappedError: Error\n if (error.response.status < 500) {\n mappedError = new RequestClientError(errorMessage, error.response.status)\n } else {\n mappedError = new Abort(errorMessage)\n }\n mappedError.stack = error.stack\n throw mappedError\n } else {\n throw error\n }\n }\n}\n"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/api/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAA;AACrD,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,cAAc,CAAA;AAC1F,OAAO,EAAC,KAAK,EAAE,eAAe,EAAC,MAAM,aAAa,CAAA;AAClD,OAAO,EAAC,WAAW,EAA6B,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AAEjC,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IAErD,YAAmB,OAAe,EAAE,UAAkB;QACpD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAAa;IAC9C,MAAM,SAAS,GAAG,kBAAkB,MAAM,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAA;IAEvE,MAAM,OAAO,GAAG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C,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;;;EAGnD,sBAAsB,CAAC,OAAO,CAAC;CAChC,CAAC,CAAA;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,GAAW,EAAE,MAAwB;IAC3E,IAAI;QACF,OAAO,MAAM,MAAM,EAAE,CAAA;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,YAAY,WAAW,EAAE;YAChC,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAA;QAC3C,KAAK,CAAC,GAAG,CACb,GAAG,CACJ,8DAA8D,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE;;IAEvF,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;OACpC,CAAC,CAAA;YACF,IAAI,WAAkB,CAAA;YACtB,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE;gBAC/B,WAAW,GAAG,IAAI,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;aAC1E;iBAAM;gBACL,WAAW,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,CAAA;aACtC;YACD,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;YAC/B,MAAM,WAAW,CAAA;SAClB;aAAM;YACL,MAAM,KAAK,CAAA;SACZ;KACF;AACH,CAAC","sourcesContent":["import {firstPartyDev} from '../environment/local.js'\nimport constants from '../constants.js'\nimport {stringifyMessage, content, token as outputToken, token, debug} from '../output.js'\nimport {Abort, ExtendableError} from '../error.js'\nimport {ClientError, RequestDocument, Variables} from 'graphql-request'\nimport {randomUUID} from 'crypto'\n\nexport class RequestClientError extends ExtendableError {\n statusCode: number\n public constructor(message: string, statusCode: number) {\n super(message)\n this.statusCode = statusCode\n }\n}\n\nexport async function buildHeaders(token: string): Promise<{[key: string]: string}> {\n const userAgent = `Shopify CLI; v=${await constants.versions.cliKit()}`\n\n const headers = {\n 'User-Agent': userAgent,\n // 'Sec-CH-UA': secCHUA, This header requires the Git sha.\n 'Sec-CH-UA-PLATFORM': process.platform,\n 'X-Request-Id': randomUUID(),\n authorization: `Bearer ${token}`,\n 'X-Shopify-Access-Token': `Bearer ${token}`,\n 'Content-Type': 'application/json',\n ...(firstPartyDev() && {'X-Shopify-Cli-Employee': '1'}),\n }\n\n return headers\n}\n\n/**\n * Removes the sensitive data from the headers and outputs them as a string.\n * @param headers {{[key: string]: string}} HTTP headers.\n * @returns {string} A sanitized version of the headers as a string.\n */\nexport function sanitizedHeadersOutput(headers: {[key: string]: string}): string {\n const sanitized: {[key: string]: string} = {}\n const keywords = ['token', 'authorization']\n Object.keys(headers).forEach((header) => {\n if (keywords.find((keyword) => header.toLocaleLowerCase().includes(keyword)) === undefined) {\n sanitized[header] = headers[header]!\n }\n })\n return Object.keys(sanitized)\n .map((header) => {\n return ` - ${header}: ${sanitized[header]}`\n })\n .join('\\n')\n}\n\nexport function debugLogRequest<T>(\n api: string,\n query: RequestDocument,\n variables?: Variables,\n headers: {[key: string]: string} = {},\n) {\n debug(`\nSending ${token.json(api)} GraphQL request:\n${query}\n\nWith variables:\n${variables ? JSON.stringify(variables, null, 2) : ''}\n\nAnd headers:\n${sanitizedHeadersOutput(headers)}\n`)\n}\n\nexport async function handlingErrors<T>(api: string, action: () => Promise<T>): Promise<T> {\n try {\n return await action()\n } catch (error) {\n if (error instanceof ClientError) {\n const errorMessage = stringifyMessage(content`\n The ${token.raw(\n api,\n )} GraphQL API responded unsuccessfully with the HTTP status ${`${error.response.status}`} and errors:\n\n ${outputToken.json(error.response.errors)}\n `)\n let mappedError: Error\n if (error.response.status < 500) {\n mappedError = new RequestClientError(errorMessage, error.response.status)\n } else {\n mappedError = new Abort(errorMessage)\n }\n mappedError.stack = error.stack\n throw mappedError\n } else {\n throw error\n }\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ export declare const ApiSchemaDefinitionQuery: string;
2
+ export interface ApiSchemaDefinitionQuerySchema {
3
+ definition: string | null;
4
+ }
5
+ export interface ApiSchemaDefinitionQueryVariables {
6
+ apiKey: string;
7
+ version: string;
8
+ type: string;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { gql } from 'graphql-request';
2
+ export const ApiSchemaDefinitionQuery = gql `
3
+ query ApiSchemaDefinitionQuery($apiKey: String!, $version: String!, $type: String!) {
4
+ definition: functionApiSchemaDefinition(apiKey: $apiKey, version: $version, type: $type)
5
+ }
6
+ `;
7
+ //# sourceMappingURL=api_schema_definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api_schema_definition.js","sourceRoot":"","sources":["../../../../src/api/graphql/functions/api_schema_definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,iBAAiB,CAAA;AAEnC,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAA;;;;CAI1C,CAAA","sourcesContent":["import {gql} from 'graphql-request'\n\nexport const ApiSchemaDefinitionQuery = gql`\n query ApiSchemaDefinitionQuery($apiKey: String!, $version: String!, $type: String!) {\n definition: functionApiSchemaDefinition(apiKey: $apiKey, version: $version, type: $type)\n }\n`\n\nexport interface ApiSchemaDefinitionQuerySchema {\n definition: string | null\n}\n\nexport interface ApiSchemaDefinitionQueryVariables {\n apiKey: string\n version: string\n type: string\n}\n"]}
@@ -12,6 +12,7 @@ export * from './find_org.js';
12
12
  export * from './find_store_by_domain.js';
13
13
  export * from './functions/app_function_set.js';
14
14
  export * from './functions/compile_module.js';
15
+ export * from './functions/api_schema_definition.js';
15
16
  export * from './functions/function_service_proxy.js';
16
17
  export * from './functions/module_compilation_status.js';
17
18
  export * from './functions/upload_url_generate.js';
@@ -12,6 +12,7 @@ export * from './find_org.js';
12
12
  export * from './find_store_by_domain.js';
13
13
  export * from './functions/app_function_set.js';
14
14
  export * from './functions/compile_module.js';
15
+ export * from './functions/api_schema_definition.js';
15
16
  export * from './functions/function_service_proxy.js';
16
17
  export * from './functions/module_compilation_status.js';
17
18
  export * from './functions/upload_url_generate.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/graphql/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAA;AACpD,cAAc,eAAe,CAAA;AAC7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uCAAuC,CAAA;AACrD,cAAc,0CAA0C,CAAA;AACxD,cAAc,oCAAoC,CAAA;AAClD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA","sourcesContent":["export * from './all_app_extension_registrations.js'\nexport * from './all_orgs.js'\nexport * from './all_stores_by_org.js'\nexport * from './convert_dev_to_test_store.js'\nexport * from './create_app.js'\nexport * from './create_deployment.js'\nexport * from './extension_create.js'\nexport * from './extension_specifications.js'\nexport * from './find_app.js'\nexport * from './find_org_basic.js'\nexport * from './find_org.js'\nexport * from './find_store_by_domain.js'\nexport * from './functions/app_function_set.js'\nexport * from './functions/compile_module.js'\nexport * from './functions/function_service_proxy.js'\nexport * from './functions/module_compilation_status.js'\nexport * from './functions/upload_url_generate.js'\nexport * from './generate_signed_upload_url.js'\nexport * from './get_urls.js'\nexport * from './get_variant_id.js'\nexport * from './update_draft.js'\nexport * from './update_urls.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/graphql/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAA;AACpD,cAAc,eAAe,CAAA;AAC7B,cAAc,wBAAwB,CAAA;AACtC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,sCAAsC,CAAA;AACpD,cAAc,uCAAuC,CAAA;AACrD,cAAc,0CAA0C,CAAA;AACxD,cAAc,oCAAoC,CAAA;AAClD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA","sourcesContent":["export * from './all_app_extension_registrations.js'\nexport * from './all_orgs.js'\nexport * from './all_stores_by_org.js'\nexport * from './convert_dev_to_test_store.js'\nexport * from './create_app.js'\nexport * from './create_deployment.js'\nexport * from './extension_create.js'\nexport * from './extension_specifications.js'\nexport * from './find_app.js'\nexport * from './find_org_basic.js'\nexport * from './find_org.js'\nexport * from './find_store_by_domain.js'\nexport * from './functions/app_function_set.js'\nexport * from './functions/compile_module.js'\nexport * from './functions/api_schema_definition.js'\nexport * from './functions/function_service_proxy.js'\nexport * from './functions/module_compilation_status.js'\nexport * from './functions/upload_url_generate.js'\nexport * from './generate_signed_upload_url.js'\nexport * from './get_urls.js'\nexport * from './get_variant_id.js'\nexport * from './update_draft.js'\nexport * from './update_urls.js'\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Deep merges the two objects and returns a new object
3
+ * with the merge result.
4
+ * @param lhs {any} One of the objects to be merged.
5
+ * @param rhs {any} Another object to be merged.
6
+ * @returns {any} A Javascrip tobject with th emerged objects.
7
+ */
8
+ export declare function deepMergeObjects<T1, T2>(lhs: Partial<T1>, rhs: Partial<T2>): T1 & T2;
@@ -0,0 +1,12 @@
1
+ import deepMerge from 'deepmerge';
2
+ /**
3
+ * Deep merges the two objects and returns a new object
4
+ * with the merge result.
5
+ * @param lhs {any} One of the objects to be merged.
6
+ * @param rhs {any} Another object to be merged.
7
+ * @returns {any} A Javascrip tobject with th emerged objects.
8
+ */
9
+ export function deepMergeObjects(lhs, rhs) {
10
+ return deepMerge(lhs, rhs);
11
+ }
12
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/common/object.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAS,GAAgB,EAAE,GAAgB;IACzE,OAAO,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAC5B,CAAC","sourcesContent":["import deepMerge from 'deepmerge'\n\n/**\n * Deep merges the two objects and returns a new object\n * with the merge result.\n * @param lhs {any} One of the objects to be merged.\n * @param rhs {any} Another object to be merged.\n * @returns {any} A Javascrip tobject with th emerged objects.\n */\nexport function deepMergeObjects<T1, T2>(lhs: Partial<T1>, rhs: Partial<T2>): T1 & T2 {\n return deepMerge(lhs, rhs)\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
- * Gets info on the Web IDE platform the CLI is running on, if applicable
87
+ * Returns the first mac address found
88
+ *
89
+ * @returns {Promise<string>} Mac address
69
90
  */
70
- export declare function webIDEPlatform(env?: NodeJS.ProcessEnv): "codespaces" | "gitpod" | undefined;
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 isCodespaces(env) || isGitpod(env) || isSpin(env);
98
+ return cloudEnvironment(env).platform !== 'localhost';
91
99
  }
92
- function isCodespaces(env = process.env) {
93
- return isTruthy(env[constants.environmentVariables.codespaces]);
94
- }
95
- function isGitpod(env = process.env) {
96
- return isSet(env[constants.environmentVariables.gitpod]);
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
- * Gets info on the Web IDE platform the CLI is running on, if applicable
159
+ * Returns the first mac address found
160
+ *
161
+ * @returns {Promise<string>} Mac address
138
162
  */
139
- export function webIDEPlatform(env = process.env) {
140
- if (isCodespaces(env))
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,CAA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AA;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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AAG,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/file.d.ts CHANGED
@@ -46,6 +46,18 @@ export declare function isDirectory(path: string): Promise<boolean>;
46
46
  export declare function size(path: string): Promise<number>;
47
47
  export declare function sizeSync(path: string): number;
48
48
  export declare function createReadStream(path: string): fs.ReadStream;
49
+ /**
50
+ * Returns the Date object for the last modification of a file.
51
+ * @param path {string} Path to the directory or file.
52
+ * @returns {number} A unix timestamp.
53
+ */
54
+ export declare function lastUpdated(path: string): Promise<Date>;
55
+ /**
56
+ * Returns the unix timestamp of the last modification of a file.
57
+ * @param path {string} Path to the directory or file.
58
+ * @returns {number} A unix timestamp.
59
+ */
60
+ export declare function lastUpdatedTimestamp(path: string): Promise<number>;
49
61
  /**
50
62
  * Moves a file.
51
63
  * @param src {string} File to be moved.
package/dist/file.js CHANGED
@@ -126,6 +126,24 @@ export function sizeSync(path) {
126
126
  export function createReadStream(path) {
127
127
  return fs.createReadStream(path);
128
128
  }
129
+ /**
130
+ * Returns the Date object for the last modification of a file.
131
+ * @param path {string} Path to the directory or file.
132
+ * @returns {number} A unix timestamp.
133
+ */
134
+ export async function lastUpdated(path) {
135
+ debug(outputContent `Getting last updated timestamp for file at ${token.path(path)}...`);
136
+ return (await fs.stat(path)).ctime;
137
+ }
138
+ /**
139
+ * Returns the unix timestamp of the last modification of a file.
140
+ * @param path {string} Path to the directory or file.
141
+ * @returns {number} A unix timestamp.
142
+ */
143
+ export async function lastUpdatedTimestamp(path) {
144
+ const lastUpdatedDateTime = await lastUpdated(path);
145
+ return lastUpdatedDateTime.getTime();
146
+ }
129
147
  /**
130
148
  * Moves a file.
131
149
  * @param src {string} File to be moved.