@shopify/cli-kit 4.1.0 → 4.2.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 (63) hide show
  1. package/assets/graphiql/favicon.ico +0 -0
  2. package/assets/graphiql/style.css +58 -0
  3. package/dist/private/common/array.js +2 -1
  4. package/dist/private/common/array.js.map +1 -1
  5. package/dist/private/node/api/headers.js +6 -3
  6. package/dist/private/node/api/headers.js.map +1 -1
  7. package/dist/private/node/session/device-authorization.js +4 -16
  8. package/dist/private/node/session/device-authorization.js.map +1 -1
  9. package/dist/private/node/ui.js +4 -1
  10. package/dist/private/node/ui.js.map +1 -1
  11. package/dist/public/common/gid.d.ts +24 -0
  12. package/dist/public/common/gid.js +32 -0
  13. package/dist/public/common/gid.js.map +1 -0
  14. package/dist/public/common/url.d.ts +16 -0
  15. package/dist/public/common/url.js +30 -0
  16. package/dist/public/common/url.js.map +1 -1
  17. package/dist/public/common/version.d.ts +1 -1
  18. package/dist/public/common/version.js +1 -1
  19. package/dist/public/common/version.js.map +1 -1
  20. package/dist/public/node/analytics.js +3 -5
  21. package/dist/public/node/analytics.js.map +1 -1
  22. package/dist/public/node/cli.d.ts +13 -0
  23. package/dist/public/node/cli.js +12 -0
  24. package/dist/public/node/cli.js.map +1 -1
  25. package/dist/public/node/error-handler.js +1 -1
  26. package/dist/public/node/error-handler.js.map +1 -1
  27. package/dist/public/node/graphiql/server.d.ts +80 -0
  28. package/dist/public/node/graphiql/server.js +234 -0
  29. package/dist/public/node/graphiql/server.js.map +1 -0
  30. package/dist/public/node/graphiql/templates/graphiql.d.ts +12 -0
  31. package/dist/public/node/graphiql/templates/graphiql.js +314 -0
  32. package/dist/public/node/graphiql/templates/graphiql.js.map +1 -0
  33. package/dist/public/node/graphiql/templates/unauthorized.d.ts +5 -0
  34. package/dist/public/node/graphiql/templates/unauthorized.js +111 -0
  35. package/dist/public/node/graphiql/templates/unauthorized.js.map +1 -0
  36. package/dist/public/node/graphiql/utilities.d.ts +12 -0
  37. package/dist/public/node/graphiql/utilities.js +44 -0
  38. package/dist/public/node/graphiql/utilities.js.map +1 -0
  39. package/dist/public/node/graphql.d.ts +19 -0
  40. package/dist/public/node/graphql.js +41 -0
  41. package/dist/public/node/graphql.js.map +1 -0
  42. package/dist/public/node/hooks/postrun.js +12 -2
  43. package/dist/public/node/hooks/postrun.js.map +1 -1
  44. package/dist/public/node/http.js +27 -31
  45. package/dist/public/node/http.js.map +1 -1
  46. package/dist/public/node/metadata.d.ts +3 -0
  47. package/dist/public/node/metadata.js.map +1 -1
  48. package/dist/public/node/monorail.d.ts +2 -1
  49. package/dist/public/node/monorail.js +1 -1
  50. package/dist/public/node/monorail.js.map +1 -1
  51. package/dist/public/node/output.js +20 -11
  52. package/dist/public/node/output.js.map +1 -1
  53. package/dist/public/node/system.js +3 -0
  54. package/dist/public/node/system.js.map +1 -1
  55. package/dist/public/node/tcp.js +11 -3
  56. package/dist/public/node/tcp.js.map +1 -1
  57. package/dist/public/node/themes/api.js +76 -4
  58. package/dist/public/node/themes/api.js.map +1 -1
  59. package/dist/public/node/toml/toml-file.d.ts +3 -2
  60. package/dist/public/node/toml/toml-file.js +3 -2
  61. package/dist/public/node/toml/toml-file.js.map +1 -1
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +34 -29
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/public/node/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAC,SAAS,IAAI,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AAgBjC,KAAK,UAAU,oBAAoB,CAAC,WAAmC,OAAO,CAAC,QAAQ;IACrF,MAAM,WAAW,GAAG,QAAQ,CAAC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C,OAAO,CAAC;QAClB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,iEAAiE;QAC9E,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,oBAAoB,CAAC,IAAI;KAC/B,CAAC;CACH,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,MAAM,EAAC,UAAU,EAAC,GAAG,MAAM,MAAM,CAAC,kCAAkC,CAAC,CAAA;IACrE,UAAU,EAAE,CAAA;AACd,CAAC","sourcesContent":["import {isTruthy} from './context/utilities.js'\nimport {launchCLI as defaultLaunchCli} from './cli-launcher.js'\nimport {environmentVariables} from '../../private/node/constants.js'\nimport {Flags} from '@oclif/core'\nimport type {LazyCommandLoader} from './custom-oclif-loader.js'\n\n/**\n * IMPORTANT NOTE: Imports in this module are dynamic to ensure that \"setupEnvironmentVariables\" can dynamically\n * set the DEBUG environment variable before the 'debug' package sets up its configuration when modules\n * are loaded statically.\n */\ninterface RunCLIOptions {\n /** The value of import.meta.url of the CLI executable module */\n moduleURL: string\n development: boolean\n /** Optional lazy command loader for on-demand command loading */\n lazyCommandLoader?: LazyCommandLoader\n}\n\nasync function exitIfOldNodeVersion(versions: NodeJS.ProcessVersions = process.versions) {\n const nodeVersion = versions.node\n const nodeMajorVersion = Number(nodeVersion.split('.')[0])\n\n const currentSupportedNodeVersion = 18\n if (nodeMajorVersion < currentSupportedNodeVersion) {\n const {renderError} = await import('./ui.js')\n renderError({\n headline: 'Upgrade to a supported Node version now.',\n body: [\n `Node ${nodeMajorVersion} has reached end-of-life and poses security risks. When you upgrade to a`,\n {\n link: {\n url: 'https://nodejs.dev/en/about/previous-releases',\n label: 'supported version',\n },\n },\n {char: ','},\n \"you'll be able to use Shopify CLI without interruption.\",\n ],\n })\n process.exit(1)\n }\n}\n\nfunction setupEnvironmentVariables(\n options: Pick<RunCLIOptions, 'development'>,\n argv: string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n) {\n /**\n * By setting DEBUG=* when --verbose is passed we are increasing the\n * verbosity of oclif. Oclif uses debug (https://www.npmjs.com/package/debug)\n * for logging, and it's configured through the DEBUG= environment variable.\n */\n if (argv.includes('--verbose')) {\n env.DEBUG = env.DEBUG ?? '*'\n }\n if (options.development) {\n env.SHOPIFY_CLI_ENV = env.SHOPIFY_CLI_ENV ?? 'development'\n }\n}\n\nfunction forceNoColor(argv: string[] = process.argv, env: NodeJS.ProcessEnv = process.env) {\n if (\n argv.includes('--no-color') ||\n argv.includes('--json') ||\n argv.includes('-j') ||\n isTruthy(env.NO_COLOR) ||\n isTruthy(env.SHOPIFY_FLAG_NO_COLOR) ||\n isTruthy(env[environmentVariables.json]) ||\n env.TERM === 'dumb'\n ) {\n env.FORCE_COLOR = '0'\n }\n}\n\n/**\n * A function that abstracts away setting up the environment and running\n * a CLI\n * @param options - Options.\n */\nexport async function runCLI(\n options: RunCLIOptions & {runInCreateMode?: boolean},\n launchCLI: (options: {moduleURL: string; lazyCommandLoader?: LazyCommandLoader}) => Promise<void> = defaultLaunchCli,\n argv: string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n versions: NodeJS.ProcessVersions = process.versions,\n): Promise<void> {\n setupEnvironmentVariables(options, argv, env)\n if (options.runInCreateMode) {\n await addInitToArgvWhenRunningCreateCLI(options, argv)\n }\n forceNoColor(argv, env)\n await exitIfOldNodeVersion(versions)\n return launchCLI({moduleURL: options.moduleURL, lazyCommandLoader: options.lazyCommandLoader})\n}\n\nasync function addInitToArgvWhenRunningCreateCLI(\n options: Pick<RunCLIOptions, 'moduleURL'>,\n argv: string[] = process.argv,\n): Promise<void> {\n const {findUpAndReadPackageJson} = await import('./node-package-manager.js')\n const {moduleDirectory} = await import('./path.js')\n\n const packageJson = await findUpAndReadPackageJson(moduleDirectory(options.moduleURL))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const packageName = (packageJson.content as any).name as string\n const name = packageName.replace('@shopify/create-', '')\n const initIndex = argv.findIndex((arg) => arg.includes('init'))\n if (initIndex === -1) {\n const initIndex = argv.findIndex((arg) => arg.match(new RegExp(`bin(\\\\/|\\\\\\\\)+(create-${name}|dev|run)`))) + 1\n argv.splice(initIndex, 0, 'init')\n }\n}\n\n/**\n * A function for create-x CLIs that automatically runs the \"init\" command.\n */\nexport async function runCreateCLI(\n options: RunCLIOptions,\n launchCLI: (options: {moduleURL: string}) => Promise<void> = defaultLaunchCli,\n argv: string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n versions: NodeJS.ProcessVersions = process.versions,\n): Promise<void> {\n return runCLI({...options, runInCreateMode: true}, launchCLI, argv, env, versions)\n}\n\n/**\n * An object that contains the flags that\n * are shared across all the commands.\n */\nexport const globalFlags = {\n 'no-color': Flags.boolean({\n hidden: false,\n description: 'Disable color output.',\n env: 'SHOPIFY_FLAG_NO_COLOR',\n }),\n verbose: Flags.boolean({\n hidden: false,\n description: 'Increase the verbosity of the output.',\n env: 'SHOPIFY_FLAG_VERBOSE',\n }),\n}\n\nexport const jsonFlag = {\n json: Flags.boolean({\n char: 'j',\n description: 'Output the result as JSON. Automatically disables color output.',\n hidden: false,\n default: false,\n env: environmentVariables.json,\n }),\n}\n\n/**\n * Clear the CLI cache, used to store some API responses and handle notifications status\n */\nexport async function clearCache(): Promise<void> {\n const {cacheClear} = await import('../../private/node/conf-store.js')\n cacheClear()\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/public/node/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAC,SAAS,IAAI,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AAgBjC,KAAK,UAAU,oBAAoB,CAAC,WAAmC,OAAO,CAAC,QAAQ;IACrF,MAAM,WAAW,GAAG,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E,KAAK,CAAC,OAAO,CAAC;QAClB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,iEAAiE;QAC9E,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,GAAG,EAAE,oBAAoB,CAAC,IAAI;KAC/B,CAAC;CACH,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,UAAkE,EAAE,EAAE,EAAE;IAC/F,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,8BAA8B,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACnG,OAAO,KAAK,CAAC,OAAO,CAAC,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,WAAW,EAAC,CAAC,CAAA;AACrE,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,MAAM,EAAC,UAAU,EAAC,GAAG,MAAM,MAAM,CAAC,kCAAkC,CAAC,CAAA;IACrE,UAAU,EAAE,CAAA;AACd,CAAC","sourcesContent":["import {isTruthy} from './context/utilities.js'\nimport {launchCLI as defaultLaunchCli} from './cli-launcher.js'\nimport {environmentVariables} from '../../private/node/constants.js'\nimport {Flags} from '@oclif/core'\nimport type {LazyCommandLoader} from './custom-oclif-loader.js'\n\n/**\n * IMPORTANT NOTE: Imports in this module are dynamic to ensure that \"setupEnvironmentVariables\" can dynamically\n * set the DEBUG environment variable before the 'debug' package sets up its configuration when modules\n * are loaded statically.\n */\ninterface RunCLIOptions {\n /** The value of import.meta.url of the CLI executable module */\n moduleURL: string\n development: boolean\n /** Optional lazy command loader for on-demand command loading */\n lazyCommandLoader?: LazyCommandLoader\n}\n\nasync function exitIfOldNodeVersion(versions: NodeJS.ProcessVersions = process.versions) {\n const nodeVersion = versions.node\n const nodeMajorVersion = Number(nodeVersion.split('.')[0])\n\n const currentSupportedNodeVersion = 18\n if (nodeMajorVersion < currentSupportedNodeVersion) {\n const {renderError} = await import('./ui.js')\n renderError({\n headline: 'Upgrade to a supported Node version now.',\n body: [\n `Node ${nodeMajorVersion} has reached end-of-life and poses security risks. When you upgrade to a`,\n {\n link: {\n url: 'https://nodejs.dev/en/about/previous-releases',\n label: 'supported version',\n },\n },\n {char: ','},\n \"you'll be able to use Shopify CLI without interruption.\",\n ],\n })\n process.exit(1)\n }\n}\n\nfunction setupEnvironmentVariables(\n options: Pick<RunCLIOptions, 'development'>,\n argv: string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n) {\n /**\n * By setting DEBUG=* when --verbose is passed we are increasing the\n * verbosity of oclif. Oclif uses debug (https://www.npmjs.com/package/debug)\n * for logging, and it's configured through the DEBUG= environment variable.\n */\n if (argv.includes('--verbose')) {\n env.DEBUG = env.DEBUG ?? '*'\n }\n if (options.development) {\n env.SHOPIFY_CLI_ENV = env.SHOPIFY_CLI_ENV ?? 'development'\n }\n}\n\nfunction forceNoColor(argv: string[] = process.argv, env: NodeJS.ProcessEnv = process.env) {\n if (\n argv.includes('--no-color') ||\n argv.includes('--json') ||\n argv.includes('-j') ||\n isTruthy(env.NO_COLOR) ||\n isTruthy(env.SHOPIFY_FLAG_NO_COLOR) ||\n isTruthy(env[environmentVariables.json]) ||\n env.TERM === 'dumb'\n ) {\n env.FORCE_COLOR = '0'\n }\n}\n\n/**\n * A function that abstracts away setting up the environment and running\n * a CLI\n * @param options - Options.\n */\nexport async function runCLI(\n options: RunCLIOptions & {runInCreateMode?: boolean},\n launchCLI: (options: {moduleURL: string; lazyCommandLoader?: LazyCommandLoader}) => Promise<void> = defaultLaunchCli,\n argv: string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n versions: NodeJS.ProcessVersions = process.versions,\n): Promise<void> {\n setupEnvironmentVariables(options, argv, env)\n if (options.runInCreateMode) {\n await addInitToArgvWhenRunningCreateCLI(options, argv)\n }\n forceNoColor(argv, env)\n await exitIfOldNodeVersion(versions)\n return launchCLI({moduleURL: options.moduleURL, lazyCommandLoader: options.lazyCommandLoader})\n}\n\nasync function addInitToArgvWhenRunningCreateCLI(\n options: Pick<RunCLIOptions, 'moduleURL'>,\n argv: string[] = process.argv,\n): Promise<void> {\n const {findUpAndReadPackageJson} = await import('./node-package-manager.js')\n const {moduleDirectory} = await import('./path.js')\n\n const packageJson = await findUpAndReadPackageJson(moduleDirectory(options.moduleURL))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const packageName = (packageJson.content as any).name as string\n const name = packageName.replace('@shopify/create-', '')\n const initIndex = argv.findIndex((arg) => arg.includes('init'))\n if (initIndex === -1) {\n const initIndex = argv.findIndex((arg) => arg.match(new RegExp(`bin(\\\\/|\\\\\\\\)+(create-${name}|dev|run)`))) + 1\n argv.splice(initIndex, 0, 'init')\n }\n}\n\n/**\n * A function for create-x CLIs that automatically runs the \"init\" command.\n */\nexport async function runCreateCLI(\n options: RunCLIOptions,\n launchCLI: (options: {moduleURL: string}) => Promise<void> = defaultLaunchCli,\n argv: string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n versions: NodeJS.ProcessVersions = process.versions,\n): Promise<void> {\n return runCLI({...options, runInCreateMode: true}, launchCLI, argv, env, versions)\n}\n\n/**\n * An object that contains the flags that\n * are shared across all the commands.\n */\nexport const globalFlags = {\n 'no-color': Flags.boolean({\n hidden: false,\n description: 'Disable color output.',\n env: 'SHOPIFY_FLAG_NO_COLOR',\n }),\n verbose: Flags.boolean({\n hidden: false,\n description: 'Increase the verbosity of the output.',\n env: 'SHOPIFY_FLAG_VERBOSE',\n }),\n}\n\nexport const jsonFlag = {\n json: Flags.boolean({\n char: 'j',\n description: 'Output the result as JSON. Automatically disables color output.',\n hidden: false,\n default: false,\n env: environmentVariables.json,\n }),\n}\n\n/**\n * Builds a `--port` flag that only accepts a valid port number. The flag parses its\n * value as an integer and rejects anything that isn't a whole number between 1 and\n * 65535, so commands fail with a clear message instead of crashing on an out-of-range\n * port. The accepted range is appended to the description so it shows up in `--help`.\n * @param options - Optional overrides for the flag's description, environment variable, and visibility.\n * @returns An oclif integer flag constrained to the valid port range.\n */\nexport const portFlag = (options: {description?: string; env?: string; hidden?: boolean} = {}) => {\n const description = [options.description, 'Must be between 1 and 65535.'].filter(Boolean).join(' ')\n return Flags.integer({min: 1, max: 65535, ...options, description})\n}\n\n/**\n * Clear the CLI cache, used to store some API responses and handle notifications status\n */\nexport async function clearCache(): Promise<void> {\n const {cacheClear} = await import('../../private/node/conf-store.js')\n cacheClear()\n}\n"]}
@@ -161,7 +161,7 @@ export function cleanStackFrameFilePath({ currentFilePath, projectRoot, pluginLo
161
161
  const fullLocation = path.isAbsolutePath(currentFilePath)
162
162
  ? currentFilePath
163
163
  : path.joinPath(projectRoot, currentFilePath);
164
- const matchingPluginPath = pluginLocations.filter(({ pluginPath }) => fullLocation.startsWith(pluginPath))[0];
164
+ const matchingPluginPath = pluginLocations.find(({ pluginPath }) => fullLocation.startsWith(pluginPath));
165
165
  if (matchingPluginPath !== undefined) {
166
166
  // the plugin name (e.g. @shopify/cli-kit), plus the relative path of the error line from within the plugin's code (e.g. dist/something.js )
167
167
  return path.joinPath(matchingPluginPath.name, path.relativePath(matchingPluginPath.pluginPath, fullLocation));
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/public/node/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,oBAAoB,EAAC,MAAM,gBAAgB,CAAA;AACpE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,6BAA6B,EAC7B,OAAO,EACP,yBAAyB,GAC1B,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,aAAa,CA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,aAAa;QACrB,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,eAAe;QAC3B,iBAAiB,EAAE,KAAK;QACxB,gBAAgB,EAAE,KAAK;QACvB,oBAAoB,EAAE,CAAC,YAAY,CAAC;QACpC,SAAS,EAAE;YACT,MAAM,EAAE,mDAAmD;YAC3D,QAAQ,EAAE,4DAA4D;SACvE;QACD,oEAAoE;QACpE,0EAA0E;QAC1E,oEAAoE;QACpE,+BAA+B;QAC/B,WAAW,EAAE,IAAI;KAClB,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {CommandExitMode, reportAnalyticsEvent} from './analytics.js'\nimport * as path from './path.js'\nimport {fanoutHooks} from './plugins.js'\nimport * as metadata from './metadata.js'\nimport {\n AbortSilentError,\n CancelExecution,\n errorMapper,\n shouldReportErrorAsUnexpected,\n handler,\n cleanSingleStackTracePath,\n} from './error.js'\nimport {outputDebug, outputInfo} from './output.js'\nimport {getEnvironmentData} from '../../private/node/analytics.js'\nimport {isLocalEnvironment} from '../../private/node/context/service.js'\nimport {bugsnagApiKey, reportingRateLimit} from '../../private/node/constants.js'\nimport {CLI_KIT_VERSION} from '../common/version.js'\nimport {runWithRateLimit} from '../../private/node/conf-store.js'\nimport {getLastSeenUserIdAfterAuth} from '../../private/node/session.js'\n\nimport {settings, Interfaces} from '@oclif/core'\nimport StackTracey from 'stacktracey'\nimport Bugsnag, {Event} from '@bugsnag/js'\n\nimport {realpath} from 'fs/promises'\n\n// Allowed slice names for error analytics grouping.\n// Hardcoded list per product slices to keep analytics consistent.\nconst ALLOWED_SLICE_NAMES = new Set<string>(['app', 'theme', 'hydrogen', 'store'])\n\nexport async function errorHandler(\n error: Error & {exitCode?: number | undefined},\n config?: Interfaces.Config,\n): Promise<void> {\n if (error instanceof CancelExecution) {\n if (error.message && error.message !== '') {\n outputInfo(`✨ ${error.message}`)\n }\n } else if (error instanceof AbortSilentError) {\n /* empty */\n } else {\n return errorMapper(error)\n .then((error) => {\n return handler(error)\n })\n .then((mappedError) => {\n return reportError(mappedError, config)\n })\n }\n}\n\nconst reportError = async (error: unknown, config?: Interfaces.Config): Promise<void> => {\n // categorise the error first\n let exitMode: CommandExitMode = 'expected_error'\n if (shouldReportErrorAsUnexpected(error)) exitMode = 'unexpected_error'\n\n if (config !== undefined) {\n // Log an analytics event when there's an error\n await reportAnalyticsEvent({config, errorMessage: error instanceof Error ? error.message : undefined, exitMode})\n }\n await sendErrorToBugsnag(error, exitMode)\n}\n\n/**\n * Sends an error to Bugsnag. This is configured automatically for uncaught errors from CLI commands, but can also be used to manually record an error.\n *\n * @returns the reported error (this may have been tweaked for better reporting), and a bool to indicate if the error was actually submitted or not\n */\nexport async function sendErrorToBugsnag(\n error: unknown,\n exitMode: Omit<CommandExitMode, 'ok'>,\n): Promise<{reported: false; error: unknown; unhandled: unknown} | {error: Error; reported: true; unhandled: boolean}> {\n try {\n if (isLocalEnvironment() || settings.debug) {\n outputDebug(`Skipping Bugsnag report`)\n return {reported: false, error, unhandled: undefined}\n }\n\n if (exitMode === 'expected_error') {\n outputDebug(`Skipping Bugsnag report for expected error`)\n return {reported: false, error, unhandled: undefined}\n }\n\n // If the error was unexpected, we flag it as \"unhandled\" in Bugsnag. This is a helpful distinction.\n const unhandled = exitMode === 'unexpected_error'\n\n let reportableError: Error\n let stacktrace: string | undefined\n let report = false\n\n if (error instanceof Error) {\n report = true\n reportableError = new Error(error.message)\n stacktrace = error.stack\n\n /**\n * Some errors that reach this point have an empty string. For example:\n * https://app.bugsnag.com/shopify/cli/errors/62cd5d31fd5040000814086c?filters[event.since]=30d&filters[error.status]=new&filters[release.seen_in]=3.1.0\n *\n * Because at this point we have neither the error message nor a stack trace reporting them\n * to Bugsnag is pointless and adds noise.\n */\n } else if (typeof error === 'string' && error.trim().length !== 0) {\n report = true\n reportableError = new Error(error)\n stacktrace = reportableError.stack\n } else {\n report = false\n reportableError = new Error('Unknown error')\n }\n\n const formattedStacktrace = new StackTracey(stacktrace ?? '')\n .clean()\n .items.map((item) => {\n const filePath = cleanSingleStackTracePath(item.file)\n return ` at ${item.callee} (${filePath}:${item.line}:${item.column})`\n })\n .join('\\n')\n reportableError.stack = `Error: ${reportableError.message}\\n${formattedStacktrace}`\n\n let withinRateLimit = false\n await runWithRateLimit({\n key: 'send-error-to-bugsnag',\n ...reportingRateLimit,\n task: async () => {\n withinRateLimit = true\n },\n })\n if (!withinRateLimit) {\n outputDebug(`Skipping Bugsnag report due to rate limiting`)\n report = false\n }\n\n if (report) {\n initializeBugsnag()\n let userId: string | undefined = await getLastSeenUserIdAfterAuth()\n if (userId === 'unknown') {\n // Observe will use the IP when undefined\n userId = undefined\n }\n await new Promise((resolve, reject) => {\n outputDebug(`Reporting ${unhandled ? 'unhandled' : 'handled'} error to Bugsnag: ${reportableError.message}`)\n const eventHandler = (event: Event) => {\n event.severity = 'error'\n event.unhandled = unhandled\n event.setUser(userId)\n // Attach command metadata so we know which CLI command triggered the error\n const {commandStartOptions} = metadata.getAllSensitiveMetadata()\n const {startCommand} = commandStartOptions ?? {}\n if (startCommand) {\n const firstWord = startCommand.trim().split(/\\s+/)[0] ?? 'cli'\n const sliceName = ALLOWED_SLICE_NAMES.has(firstWord) ? firstWord : 'cli'\n event.addMetadata('custom', {slice_name: sliceName})\n }\n }\n const errorHandler = (error: unknown) => {\n if (error) {\n reject(error instanceof Error ? error : new Error(String(error)))\n } else {\n resolve(reportableError)\n }\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.notify(reportableError, eventHandler, errorHandler)\n })\n }\n return {error: reportableError, reported: report, unhandled}\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (err) {\n outputDebug(`Error reporting to Bugsnag: ${err}`)\n return {error, reported: false, unhandled: undefined}\n }\n}\n\n/**\n * If the given file path is within a node_modules folder, remove prefix up\n * to and including the node_modules folder.\n *\n * This gives us very consistent paths for errors generated by the CLI.\n */\nexport function cleanStackFrameFilePath({\n currentFilePath,\n projectRoot,\n pluginLocations,\n}: {\n currentFilePath: string\n projectRoot: string\n pluginLocations: {name: string; pluginPath: string}[]\n}): string {\n const fullLocation = path.isAbsolutePath(currentFilePath)\n ? currentFilePath\n : path.joinPath(projectRoot, currentFilePath)\n\n const matchingPluginPath = pluginLocations.filter(({pluginPath}) => fullLocation.startsWith(pluginPath))[0]\n\n if (matchingPluginPath !== undefined) {\n // the plugin name (e.g. @shopify/cli-kit), plus the relative path of the error line from within the plugin's code (e.g. dist/something.js )\n return path.joinPath(matchingPluginPath.name, path.relativePath(matchingPluginPath.pluginPath, fullLocation))\n }\n\n // strip prefix up to node_modules folder, so we can normalize error reporting\n return currentFilePath.replace(/.*node_modules\\//, '')\n}\n\n/**\n * Register a Bugsnag error listener to clean up stack traces for errors within plugin code.\n *\n */\nexport async function registerCleanBugsnagErrorsFromWithinPlugins(config: Interfaces.Config): Promise<void> {\n // Bugsnag have their own plug-ins that use this private field\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const bugsnagConfigProjectRoot: string = (Bugsnag as any)?._client?._config?.projectRoot ?? path.cwd()\n const projectRoot = path.normalizePath(bugsnagConfigProjectRoot)\n const pluginLocations = await Promise.all(\n [...config.plugins].map(async ([_, plugin]) => {\n const followSymlinks = await realpath(plugin.root)\n return {name: plugin.name, pluginPath: path.normalizePath(followSymlinks)}\n }),\n )\n initializeBugsnag()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.addOnError(async (event) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event.errors.forEach((error: any) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error.stacktrace.forEach((stackFrame: any) => {\n stackFrame.file = cleanStackFrameFilePath({currentFilePath: stackFrame.file, projectRoot, pluginLocations})\n })\n })\n try {\n await addBugsnagMetadata(event, config)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (metadataError) {\n outputDebug(`There was an error adding metadata to the Bugsnag report; Ignoring and carrying on ${metadataError}`)\n }\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function addBugsnagMetadata(event: any, config: Interfaces.Config): Promise<void> {\n const publicData = metadata.getAllPublicMetadata()\n const {commandStartOptions} = metadata.getAllSensitiveMetadata()\n const {startCommand} = commandStartOptions ?? {}\n\n const {'@shopify/app': appPublic, ...otherPluginsPublic} = await fanoutHooks(config, 'public_command_metadata', {})\n\n const environment = await getEnvironmentData(config)\n\n const allMetadata = {\n command: startCommand,\n ...appPublic,\n ...publicData,\n ...environment,\n pluginData: otherPluginsPublic,\n }\n\n const appData = {} as Record<string, unknown>\n const commandData = {} as Record<string, unknown>\n const environmentData = {} as Record<string, unknown>\n const miscData = {} as Record<string, unknown>\n const appKeys = ['api_key', 'business_platform_id', 'partner_id', 'project_type']\n const commandKeys = ['command']\n const environmentKeys = ['cli_version', 'node_version', 'uname']\n\n Object.entries(allMetadata).forEach(([key, value]) => {\n if (key.startsWith('app_') || appKeys.includes(key)) {\n appData[key] = value\n } else if (key.startsWith('cmd_') || commandKeys.includes(key)) {\n commandData[key] = value\n } else if (key.startsWith('env_') || environmentKeys) {\n environmentData[key] = value\n } else {\n miscData[key] = value\n }\n })\n\n // app, command, environment, misc\n const bugsnagMetadata = {\n 'Shopify App': appData,\n Command: commandData,\n Environment: environmentData,\n Misc: miscData,\n }\n Object.entries(bugsnagMetadata).forEach(([section, values]) => {\n event.addMetadata(section, values)\n })\n}\n\nfunction initializeBugsnag() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (Bugsnag.isStarted()) {\n return\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.start({\n appType: 'node',\n apiKey: bugsnagApiKey,\n logger: null,\n appVersion: CLI_KIT_VERSION,\n autoTrackSessions: false,\n autoDetectErrors: false,\n enabledReleaseStages: ['production'],\n endpoints: {\n notify: 'https://error-analytics-production.shopifysvc.com',\n sessions: 'https://error-analytics-sessions-production.shopifysvc.com',\n },\n // Set the project root to `null` to prevent the default behavior of\n // Bugsnag which is to set it to the cwd. That is unhelpful for us because\n // the cwd can be anywhere in the user's filesystem, not necessarily\n // related to the CLI codebase.\n projectRoot: null,\n })\n}\n"]}
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/public/node/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,oBAAoB,EAAC,MAAM,gBAAgB,CAAA;AACpE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,6BAA6B,EAC7B,OAAO,EACP,yBAAyB,GAC1B,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,aAAa,CAAA;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,uCAAuC,CAAA;AACxE,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AACjF,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAC,gBAAgB,EAAC,MAAM,kCAAkC,CAAA;AACjE,OAAO,EAAC,0BAA0B,EAAC,MAAM,+BAA+B,CAAA;AAExE,OAAO,EAAC,QAAQ,EAAa,MAAM,aAAa,CAAA;AAChD,OAAO,WAAW,MAAM,aAAa,CAAA;AACrC,OAAO,OAAgB,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AAEpC,oDAAoD;AACpD,kEAAkE;AAClE,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AAElF,MAAM,CAAC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C;IAClC,MAAM,eAAe,GAAG;QACtB,aAAa,EAAE,OAAO;QACtB,OAAO,EAAE,WAAW;QACpB,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,QAAQ;KACf,CAAA;IACD,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE;QAC5D,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,iBAAiB;IACxB,6DAA6D;IAC7D,aAAa;IACb,IAAI,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;QACxB,OAAM;IACR,CAAC;IACD,6DAA6D;IAC7D,aAAa;IACb,OAAO,CAAC,KAAK,CAAC;QACZ,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,aAAa;QACrB,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,eAAe;QAC3B,iBAAiB,EAAE,KAAK;QACxB,gBAAgB,EAAE,KAAK;QACvB,oBAAoB,EAAE,CAAC,YAAY,CAAC;QACpC,SAAS,EAAE;YACT,MAAM,EAAE,mDAAmD;YAC3D,QAAQ,EAAE,4DAA4D;SACvE;QACD,oEAAoE;QACpE,0EAA0E;QAC1E,oEAAoE;QACpE,+BAA+B;QAC/B,WAAW,EAAE,IAAI;KAClB,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {CommandExitMode, reportAnalyticsEvent} from './analytics.js'\nimport * as path from './path.js'\nimport {fanoutHooks} from './plugins.js'\nimport * as metadata from './metadata.js'\nimport {\n AbortSilentError,\n CancelExecution,\n errorMapper,\n shouldReportErrorAsUnexpected,\n handler,\n cleanSingleStackTracePath,\n} from './error.js'\nimport {outputDebug, outputInfo} from './output.js'\nimport {getEnvironmentData} from '../../private/node/analytics.js'\nimport {isLocalEnvironment} from '../../private/node/context/service.js'\nimport {bugsnagApiKey, reportingRateLimit} from '../../private/node/constants.js'\nimport {CLI_KIT_VERSION} from '../common/version.js'\nimport {runWithRateLimit} from '../../private/node/conf-store.js'\nimport {getLastSeenUserIdAfterAuth} from '../../private/node/session.js'\n\nimport {settings, Interfaces} from '@oclif/core'\nimport StackTracey from 'stacktracey'\nimport Bugsnag, {Event} from '@bugsnag/js'\n\nimport {realpath} from 'fs/promises'\n\n// Allowed slice names for error analytics grouping.\n// Hardcoded list per product slices to keep analytics consistent.\nconst ALLOWED_SLICE_NAMES = new Set<string>(['app', 'theme', 'hydrogen', 'store'])\n\nexport async function errorHandler(\n error: Error & {exitCode?: number | undefined},\n config?: Interfaces.Config,\n): Promise<void> {\n if (error instanceof CancelExecution) {\n if (error.message && error.message !== '') {\n outputInfo(`✨ ${error.message}`)\n }\n } else if (error instanceof AbortSilentError) {\n /* empty */\n } else {\n return errorMapper(error)\n .then((error) => {\n return handler(error)\n })\n .then((mappedError) => {\n return reportError(mappedError, config)\n })\n }\n}\n\nconst reportError = async (error: unknown, config?: Interfaces.Config): Promise<void> => {\n // categorise the error first\n let exitMode: CommandExitMode = 'expected_error'\n if (shouldReportErrorAsUnexpected(error)) exitMode = 'unexpected_error'\n\n if (config !== undefined) {\n // Log an analytics event when there's an error\n await reportAnalyticsEvent({config, errorMessage: error instanceof Error ? error.message : undefined, exitMode})\n }\n await sendErrorToBugsnag(error, exitMode)\n}\n\n/**\n * Sends an error to Bugsnag. This is configured automatically for uncaught errors from CLI commands, but can also be used to manually record an error.\n *\n * @returns the reported error (this may have been tweaked for better reporting), and a bool to indicate if the error was actually submitted or not\n */\nexport async function sendErrorToBugsnag(\n error: unknown,\n exitMode: Omit<CommandExitMode, 'ok'>,\n): Promise<{reported: false; error: unknown; unhandled: unknown} | {error: Error; reported: true; unhandled: boolean}> {\n try {\n if (isLocalEnvironment() || settings.debug) {\n outputDebug(`Skipping Bugsnag report`)\n return {reported: false, error, unhandled: undefined}\n }\n\n if (exitMode === 'expected_error') {\n outputDebug(`Skipping Bugsnag report for expected error`)\n return {reported: false, error, unhandled: undefined}\n }\n\n // If the error was unexpected, we flag it as \"unhandled\" in Bugsnag. This is a helpful distinction.\n const unhandled = exitMode === 'unexpected_error'\n\n let reportableError: Error\n let stacktrace: string | undefined\n let report = false\n\n if (error instanceof Error) {\n report = true\n reportableError = new Error(error.message)\n stacktrace = error.stack\n\n /**\n * Some errors that reach this point have an empty string. For example:\n * https://app.bugsnag.com/shopify/cli/errors/62cd5d31fd5040000814086c?filters[event.since]=30d&filters[error.status]=new&filters[release.seen_in]=3.1.0\n *\n * Because at this point we have neither the error message nor a stack trace reporting them\n * to Bugsnag is pointless and adds noise.\n */\n } else if (typeof error === 'string' && error.trim().length !== 0) {\n report = true\n reportableError = new Error(error)\n stacktrace = reportableError.stack\n } else {\n report = false\n reportableError = new Error('Unknown error')\n }\n\n const formattedStacktrace = new StackTracey(stacktrace ?? '')\n .clean()\n .items.map((item) => {\n const filePath = cleanSingleStackTracePath(item.file)\n return ` at ${item.callee} (${filePath}:${item.line}:${item.column})`\n })\n .join('\\n')\n reportableError.stack = `Error: ${reportableError.message}\\n${formattedStacktrace}`\n\n let withinRateLimit = false\n await runWithRateLimit({\n key: 'send-error-to-bugsnag',\n ...reportingRateLimit,\n task: async () => {\n withinRateLimit = true\n },\n })\n if (!withinRateLimit) {\n outputDebug(`Skipping Bugsnag report due to rate limiting`)\n report = false\n }\n\n if (report) {\n initializeBugsnag()\n let userId: string | undefined = await getLastSeenUserIdAfterAuth()\n if (userId === 'unknown') {\n // Observe will use the IP when undefined\n userId = undefined\n }\n await new Promise((resolve, reject) => {\n outputDebug(`Reporting ${unhandled ? 'unhandled' : 'handled'} error to Bugsnag: ${reportableError.message}`)\n const eventHandler = (event: Event) => {\n event.severity = 'error'\n event.unhandled = unhandled\n event.setUser(userId)\n // Attach command metadata so we know which CLI command triggered the error\n const {commandStartOptions} = metadata.getAllSensitiveMetadata()\n const {startCommand} = commandStartOptions ?? {}\n if (startCommand) {\n const firstWord = startCommand.trim().split(/\\s+/)[0] ?? 'cli'\n const sliceName = ALLOWED_SLICE_NAMES.has(firstWord) ? firstWord : 'cli'\n event.addMetadata('custom', {slice_name: sliceName})\n }\n }\n const errorHandler = (error: unknown) => {\n if (error) {\n reject(error instanceof Error ? error : new Error(String(error)))\n } else {\n resolve(reportableError)\n }\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.notify(reportableError, eventHandler, errorHandler)\n })\n }\n return {error: reportableError, reported: report, unhandled}\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (err) {\n outputDebug(`Error reporting to Bugsnag: ${err}`)\n return {error, reported: false, unhandled: undefined}\n }\n}\n\n/**\n * If the given file path is within a node_modules folder, remove prefix up\n * to and including the node_modules folder.\n *\n * This gives us very consistent paths for errors generated by the CLI.\n */\nexport function cleanStackFrameFilePath({\n currentFilePath,\n projectRoot,\n pluginLocations,\n}: {\n currentFilePath: string\n projectRoot: string\n pluginLocations: {name: string; pluginPath: string}[]\n}): string {\n const fullLocation = path.isAbsolutePath(currentFilePath)\n ? currentFilePath\n : path.joinPath(projectRoot, currentFilePath)\n\n const matchingPluginPath = pluginLocations.find(({pluginPath}) => fullLocation.startsWith(pluginPath))\n\n if (matchingPluginPath !== undefined) {\n // the plugin name (e.g. @shopify/cli-kit), plus the relative path of the error line from within the plugin's code (e.g. dist/something.js )\n return path.joinPath(matchingPluginPath.name, path.relativePath(matchingPluginPath.pluginPath, fullLocation))\n }\n\n // strip prefix up to node_modules folder, so we can normalize error reporting\n return currentFilePath.replace(/.*node_modules\\//, '')\n}\n\n/**\n * Register a Bugsnag error listener to clean up stack traces for errors within plugin code.\n *\n */\nexport async function registerCleanBugsnagErrorsFromWithinPlugins(config: Interfaces.Config): Promise<void> {\n // Bugsnag have their own plug-ins that use this private field\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const bugsnagConfigProjectRoot: string = (Bugsnag as any)?._client?._config?.projectRoot ?? path.cwd()\n const projectRoot = path.normalizePath(bugsnagConfigProjectRoot)\n const pluginLocations = await Promise.all(\n [...config.plugins].map(async ([_, plugin]) => {\n const followSymlinks = await realpath(plugin.root)\n return {name: plugin.name, pluginPath: path.normalizePath(followSymlinks)}\n }),\n )\n initializeBugsnag()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.addOnError(async (event) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event.errors.forEach((error: any) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error.stacktrace.forEach((stackFrame: any) => {\n stackFrame.file = cleanStackFrameFilePath({currentFilePath: stackFrame.file, projectRoot, pluginLocations})\n })\n })\n try {\n await addBugsnagMetadata(event, config)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (metadataError) {\n outputDebug(`There was an error adding metadata to the Bugsnag report; Ignoring and carrying on ${metadataError}`)\n }\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function addBugsnagMetadata(event: any, config: Interfaces.Config): Promise<void> {\n const publicData = metadata.getAllPublicMetadata()\n const {commandStartOptions} = metadata.getAllSensitiveMetadata()\n const {startCommand} = commandStartOptions ?? {}\n\n const {'@shopify/app': appPublic, ...otherPluginsPublic} = await fanoutHooks(config, 'public_command_metadata', {})\n\n const environment = await getEnvironmentData(config)\n\n const allMetadata = {\n command: startCommand,\n ...appPublic,\n ...publicData,\n ...environment,\n pluginData: otherPluginsPublic,\n }\n\n const appData = {} as Record<string, unknown>\n const commandData = {} as Record<string, unknown>\n const environmentData = {} as Record<string, unknown>\n const miscData = {} as Record<string, unknown>\n const appKeys = ['api_key', 'business_platform_id', 'partner_id', 'project_type']\n const commandKeys = ['command']\n const environmentKeys = ['cli_version', 'node_version', 'uname']\n\n Object.entries(allMetadata).forEach(([key, value]) => {\n if (key.startsWith('app_') || appKeys.includes(key)) {\n appData[key] = value\n } else if (key.startsWith('cmd_') || commandKeys.includes(key)) {\n commandData[key] = value\n } else if (key.startsWith('env_') || environmentKeys) {\n environmentData[key] = value\n } else {\n miscData[key] = value\n }\n })\n\n // app, command, environment, misc\n const bugsnagMetadata = {\n 'Shopify App': appData,\n Command: commandData,\n Environment: environmentData,\n Misc: miscData,\n }\n Object.entries(bugsnagMetadata).forEach(([section, values]) => {\n event.addMetadata(section, values)\n })\n}\n\nfunction initializeBugsnag() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (Bugsnag.isStarted()) {\n return\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.start({\n appType: 'node',\n apiKey: bugsnagApiKey,\n logger: null,\n appVersion: CLI_KIT_VERSION,\n autoTrackSessions: false,\n autoDetectErrors: false,\n enabledReleaseStages: ['production'],\n endpoints: {\n notify: 'https://error-analytics-production.shopifysvc.com',\n sessions: 'https://error-analytics-sessions-production.shopifysvc.com',\n },\n // Set the project root to `null` to prevent the default behavior of\n // Bugsnag which is to set it to the cwd. That is unhelpful for us because\n // the cwd can be anywhere in the user's filesystem, not necessarily\n // related to the CLI codebase.\n projectRoot: null,\n })\n}\n"]}
@@ -0,0 +1,80 @@
1
+ import { Server } from 'http';
2
+ import { Writable } from 'stream';
3
+ /**
4
+ * Derives a deterministic GraphiQL authentication key from the app's API secret and store FQDN.
5
+ * The key is stable across dev server restarts (so browser tabs survive restarts)
6
+ * but is not guessable without the app secret.
7
+ *
8
+ * @param apiSecret - The Partners app's client secret used as the HMAC key.
9
+ * @param storeFqdn - The myshopify.com domain the GraphiQL session targets.
10
+ * @returns A 64-character hex string suitable for use as the `?key=` query param.
11
+ */
12
+ export declare function deriveGraphiQLKey(apiSecret: string, storeFqdn: string): string;
13
+ /**
14
+ * Resolves the GraphiQL authentication key. Uses the explicitly provided key
15
+ * if non-empty, otherwise derives one deterministically from the app secret.
16
+ *
17
+ * @param providedKey - An explicit key supplied by the caller; takes precedence when non-empty.
18
+ * @param apiSecret - The Partners app's client secret, used to derive a stable key as a fallback.
19
+ * @param storeFqdn - The myshopify.com domain the GraphiQL session targets.
20
+ * @returns The resolved key.
21
+ */
22
+ export declare function resolveGraphiQLKey(providedKey: string | undefined, apiSecret: string, storeFqdn: string): string;
23
+ /**
24
+ * Pluggable strategy for obtaining and refreshing the Admin API access token
25
+ * that the GraphiQL proxy injects into every request.
26
+ *
27
+ * - `getToken` may return a cached token; the proxy calls it for every request.
28
+ * - `refreshToken` (optional) is invoked when the upstream Admin API returns 401.
29
+ * When omitted, the proxy falls back to calling `getToken` again on 401.
30
+ *
31
+ * Implementations must throw `TokenRefreshError` (or any thrown error) when the
32
+ * token cannot be obtained; the proxy renders the unauthorized template in that case.
33
+ */
34
+ export interface TokenProvider {
35
+ getToken: () => Promise<string>;
36
+ refreshToken?: () => Promise<string>;
37
+ }
38
+ /**
39
+ * Optional app-specific context, used to render the app pill and scopes note in the
40
+ * GraphiQL header and to drive the deterministic key derivation. Pass when the GraphiQL
41
+ * server is hosted as part of `shopify app dev`; omit for app-less use cases such as
42
+ * `shopify store execute`.
43
+ */
44
+ export interface GraphiQLAppContext {
45
+ appName: string;
46
+ appUrl: string;
47
+ apiSecret: string;
48
+ }
49
+ export interface SetupGraphiQLServerOptions {
50
+ stdout: Writable;
51
+ port: number;
52
+ storeFqdn: string;
53
+ tokenProvider: TokenProvider;
54
+ /**
55
+ * Authentication key required as a `?key=` query string on every request. When omitted:
56
+ * - if `appContext` is provided, derived deterministically from `apiSecret` + `storeFqdn`
57
+ * so browser tabs survive dev server restarts.
58
+ * - otherwise, generated randomly per process.
59
+ */
60
+ key?: string;
61
+ appContext?: GraphiQLAppContext;
62
+ /**
63
+ * When true, the proxy rejects mutation operations with HTTP 400 before forwarding
64
+ * them to the Admin API. Use this to mirror non-interactive safety guarantees in the
65
+ * interactive UI.
66
+ */
67
+ protectMutations?: boolean;
68
+ }
69
+ export declare const MUTATIONS_BLOCKED_MESSAGE = "Mutations are disabled. Re-run with --allow-mutations to enable mutations.";
70
+ /**
71
+ * Starts a local HTTP server that hosts the GraphiQL UI and proxies requests to the
72
+ * Admin API for the configured store. Authentication is delegated to the supplied
73
+ * `tokenProvider`, so the same server can serve both `shopify app dev` and stored-session
74
+ * use cases.
75
+ *
76
+ * @param options - Configuration for the server, including the target store, the
77
+ * pluggable token provider, and the local port to bind to.
78
+ * @returns The underlying Node `http.Server` instance, already listening on `options.port`.
79
+ */
80
+ export declare function setupGraphiQLServer(options: SetupGraphiQLServerOptions): Server;
@@ -0,0 +1,234 @@
1
+ import { defaultQuery, graphiqlTemplate } from './templates/graphiql.js';
2
+ import { unauthorizedTemplate } from './templates/unauthorized.js';
3
+ import { filterCustomHeaders } from './utilities.js';
4
+ import { performActionWithRetryAfterRecovery } from '../../common/retry.js';
5
+ import { CLI_KIT_VERSION } from '../../common/version.js';
6
+ import { AbortError } from '../error.js';
7
+ import { adminUrl, supportedApiVersions } from '../api/admin.js';
8
+ import { fetch } from '../http.js';
9
+ import { renderLiquidTemplate } from '../liquid.js';
10
+ import { outputDebug } from '../output.js';
11
+ import { containsMutation } from '../graphql.js';
12
+ import { createApp, createRouter, defineEventHandler, getQuery, getRequestHeader, getRequestHeaders, readBody, setResponseHeader, setResponseStatus, toNodeListener, } from 'h3';
13
+ import { createHmac, randomBytes } from 'crypto';
14
+ import { createServer } from 'http';
15
+ import { readFileSync } from 'fs';
16
+ import { createRequire } from 'module';
17
+ /**
18
+ * Derives a deterministic GraphiQL authentication key from the app's API secret and store FQDN.
19
+ * The key is stable across dev server restarts (so browser tabs survive restarts)
20
+ * but is not guessable without the app secret.
21
+ *
22
+ * @param apiSecret - The Partners app's client secret used as the HMAC key.
23
+ * @param storeFqdn - The myshopify.com domain the GraphiQL session targets.
24
+ * @returns A 64-character hex string suitable for use as the `?key=` query param.
25
+ */
26
+ export function deriveGraphiQLKey(apiSecret, storeFqdn) {
27
+ return createHmac('sha256', apiSecret).update(`graphiql:${storeFqdn}`).digest('hex');
28
+ }
29
+ /**
30
+ * Resolves the GraphiQL authentication key. Uses the explicitly provided key
31
+ * if non-empty, otherwise derives one deterministically from the app secret.
32
+ *
33
+ * @param providedKey - An explicit key supplied by the caller; takes precedence when non-empty.
34
+ * @param apiSecret - The Partners app's client secret, used to derive a stable key as a fallback.
35
+ * @param storeFqdn - The myshopify.com domain the GraphiQL session targets.
36
+ * @returns The resolved key.
37
+ */
38
+ export function resolveGraphiQLKey(providedKey, apiSecret, storeFqdn) {
39
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- intentional: empty string after trim should fall through to deriveGraphiQLKey
40
+ return providedKey?.trim() || deriveGraphiQLKey(apiSecret, storeFqdn);
41
+ }
42
+ const require = createRequire(import.meta.url);
43
+ class TokenRefreshError extends AbortError {
44
+ constructor() {
45
+ super('Failed to refresh credentials. Check that your app is installed, and try again.');
46
+ }
47
+ }
48
+ export const MUTATIONS_BLOCKED_MESSAGE = 'Mutations are disabled. Re-run with --allow-mutations to enable mutations.';
49
+ /**
50
+ * Starts a local HTTP server that hosts the GraphiQL UI and proxies requests to the
51
+ * Admin API for the configured store. Authentication is delegated to the supplied
52
+ * `tokenProvider`, so the same server can serve both `shopify app dev` and stored-session
53
+ * use cases.
54
+ *
55
+ * @param options - Configuration for the server, including the target store, the
56
+ * pluggable token provider, and the local port to bind to.
57
+ * @returns The underlying Node `http.Server` instance, already listening on `options.port`.
58
+ */
59
+ export function setupGraphiQLServer(options) {
60
+ const { stdout, port, storeFqdn, tokenProvider, key: providedKey, appContext, protectMutations = false } = options;
61
+ const key = resolveGraphiQLServerKey(providedKey, appContext, storeFqdn);
62
+ outputDebug(`Setting up GraphiQL HTTP server on port ${port}...`, stdout);
63
+ const app = createApp();
64
+ const router = createRouter();
65
+ const refreshUpstreamToken = async () => {
66
+ try {
67
+ outputDebug('refreshing token', stdout);
68
+ return await (tokenProvider.refreshToken ?? tokenProvider.getToken)();
69
+ }
70
+ catch (_error) {
71
+ throw new TokenRefreshError();
72
+ }
73
+ };
74
+ const currentToken = async () => {
75
+ try {
76
+ return await tokenProvider.getToken();
77
+ }
78
+ catch (_error) {
79
+ throw new TokenRefreshError();
80
+ }
81
+ };
82
+ async function fetchApiVersionsWithTokenRefresh() {
83
+ return performActionWithRetryAfterRecovery(async () => supportedApiVersions({ storeFqdn, token: await currentToken() }), refreshUpstreamToken);
84
+ }
85
+ const faviconPath = require.resolve('@shopify/cli-kit/assets/graphiql/favicon.ico');
86
+ const faviconContent = readFileSync(faviconPath);
87
+ const stylePath = require.resolve('@shopify/cli-kit/assets/graphiql/style.css');
88
+ const styleContent = readFileSync(stylePath, 'utf8');
89
+ app.use(defineEventHandler((event) => {
90
+ setResponseHeader(event, 'Access-Control-Allow-Origin', '*');
91
+ setResponseHeader(event, 'Access-Control-Allow-Methods', 'GET, OPTIONS');
92
+ setResponseHeader(event, 'Access-Control-Allow-Headers', 'Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, ngrok-skip-browser-warning');
93
+ }));
94
+ router.get('/graphiql/ping', defineEventHandler(() => 'pong'));
95
+ router.get('/graphiql/favicon.ico', defineEventHandler((event) => {
96
+ setResponseHeader(event, 'Content-Type', 'image/x-icon');
97
+ return faviconContent;
98
+ }));
99
+ router.get('/graphiql/simple.css', defineEventHandler((event) => {
100
+ setResponseHeader(event, 'Content-Type', 'text/css');
101
+ return styleContent;
102
+ }));
103
+ router.get('/graphiql/status', defineEventHandler(async () => {
104
+ try {
105
+ await fetchApiVersionsWithTokenRefresh();
106
+ return { status: 'OK', storeFqdn, appName: appContext?.appName, appUrl: appContext?.appUrl };
107
+ // eslint-disable-next-line no-catch-all/no-catch-all
108
+ }
109
+ catch {
110
+ return { status: 'UNAUTHENTICATED' };
111
+ }
112
+ }));
113
+ router.get('/graphiql', defineEventHandler(async (event) => {
114
+ outputDebug('Handling /graphiql request', stdout);
115
+ const query = getQuery(event);
116
+ if (key && query.key !== key) {
117
+ setResponseStatus(event, 404);
118
+ return `Invalid path ${event.path}`;
119
+ }
120
+ const forwardedProto = getRequestHeader(event, 'x-forwarded-proto');
121
+ const usesHttps = forwardedProto === 'https';
122
+ const host = getRequestHeader(event, 'host');
123
+ const url = `http${usesHttps ? 's' : ''}://${host}`;
124
+ let apiVersions;
125
+ try {
126
+ apiVersions = await fetchApiVersionsWithTokenRefresh();
127
+ }
128
+ catch (err) {
129
+ if (err instanceof TokenRefreshError) {
130
+ return renderLiquidTemplate(unauthorizedTemplate({ hasAppContext: Boolean(appContext) }), {
131
+ previewUrl: appContext?.appUrl ?? '',
132
+ storeFqdn,
133
+ url,
134
+ });
135
+ }
136
+ throw err;
137
+ }
138
+ const apiVersion = apiVersions.sort().reverse()[0];
139
+ function decodeQueryString(input) {
140
+ return input ? decodeURIComponent(input).replace(/\n/g, '\\n') : undefined;
141
+ }
142
+ const queryParam = decodeQueryString(query.query);
143
+ const variables = decodeQueryString(query.variables);
144
+ return renderLiquidTemplate(graphiqlTemplate({
145
+ apiVersion,
146
+ apiVersions: [...apiVersions, 'unstable'],
147
+ appName: appContext?.appName,
148
+ appUrl: appContext?.appUrl,
149
+ key,
150
+ storeFqdn,
151
+ protectMutations,
152
+ }), {
153
+ url,
154
+ defaultQueries: [{ query: defaultQuery }],
155
+ query: queryParam ? JSON.stringify(queryParam) : undefined,
156
+ variables: variables ? JSON.stringify(variables) : undefined,
157
+ });
158
+ }));
159
+ router.post('/graphiql/graphql.json', defineEventHandler(async (event) => {
160
+ outputDebug('Handling /graphiql/graphql.json request', stdout);
161
+ const query = getQuery(event);
162
+ if (key && query.key !== key) {
163
+ setResponseStatus(event, 404);
164
+ return `Invalid path ${event.path}`;
165
+ }
166
+ const graphqlUrl = adminUrl(storeFqdn, query.api_version);
167
+ try {
168
+ const body = await readBody(event);
169
+ if (protectMutations && isMutationRequestBody(body)) {
170
+ setResponseStatus(event, 400);
171
+ return { errors: [{ message: MUTATIONS_BLOCKED_MESSAGE }] };
172
+ }
173
+ const reqBody = JSON.stringify(body);
174
+ const reqHeaders = getRequestHeaders(event);
175
+ const customHeaders = filterCustomHeaders(reqHeaders);
176
+ const runRequest = async (token) => {
177
+ const headers = {
178
+ ...customHeaders,
179
+ Accept: 'application/json',
180
+ 'Content-Type': 'application/json',
181
+ 'X-Shopify-Access-Token': token,
182
+ 'User-Agent': `ShopifyCLIGraphiQL/${CLI_KIT_VERSION}`,
183
+ };
184
+ return fetch(graphqlUrl, {
185
+ method: 'POST',
186
+ headers,
187
+ body: reqBody,
188
+ });
189
+ };
190
+ let result = await runRequest(await currentToken());
191
+ if (result.status === 401) {
192
+ outputDebug('Token expired, fetching new token', stdout);
193
+ result = await runRequest(await refreshUpstreamToken());
194
+ }
195
+ setResponseHeader(event, 'Content-Type', 'application/json');
196
+ setResponseStatus(event, result.status);
197
+ return result.json();
198
+ // eslint-disable-next-line no-catch-all/no-catch-all
199
+ }
200
+ catch (error) {
201
+ setResponseStatus(event, 500);
202
+ if (error instanceof Error) {
203
+ return { errors: [error.message] };
204
+ }
205
+ return { errors: ['Unknown error'] };
206
+ }
207
+ }));
208
+ app.use(router);
209
+ const server = createServer(toNodeListener(app));
210
+ server.listen(port, 'localhost', () => stdout.write(`GraphiQL server started on port ${port}`));
211
+ return server;
212
+ }
213
+ // Picks the right key based on what the caller supplied:
214
+ // - explicit non-empty key → use it
215
+ // - app context with apiSecret → derive deterministically (stable across restarts)
216
+ // - otherwise → random per-process key (browser tabs won't survive restarts, which is
217
+ // the right tradeoff when there's no stable secret to derive from).
218
+ function resolveGraphiQLServerKey(providedKey, appContext, storeFqdn) {
219
+ const trimmed = providedKey?.trim();
220
+ if (trimmed)
221
+ return trimmed;
222
+ if (appContext)
223
+ return deriveGraphiQLKey(appContext.apiSecret, storeFqdn);
224
+ return randomBytes(32).toString('hex');
225
+ }
226
+ function isMutationRequestBody(body) {
227
+ if (typeof body !== 'object' || body === null)
228
+ return false;
229
+ const { query, operationName } = body;
230
+ if (typeof query !== 'string')
231
+ return false;
232
+ return containsMutation(query, typeof operationName === 'string' ? operationName : undefined);
233
+ }
234
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
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AAC,CAAC,CAAA;IAC/F,OAAO,MAAM,CAAA;AACf,CAAC;AAED,yDAAyD;AACzD,oCAAoC;AACpC,mFAAmF;AACnF,sFAAsF;AACtF,sEAAsE;AACtE,SAAS,wBAAwB,CAC/B,WAA+B,EAC/B,UAA0C,EAC1C,SAAiB;IAEjB,MAAM,OAAO,GAAG,WAAW,EAAE,IAAI,EAAE,CAAA;IACnC,IAAI,OAAO;QAAE,OAAO,OAAO,CAAA;IAC3B,IAAI,UAAU;QAAE,OAAO,iBAAiB,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IACzE,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAa;IAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAC3D,MAAM,EAAC,KAAK,EAAE,aAAa,EAAC,GAAG,IAAkD,CAAA;IACjF,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,OAAO,gBAAgB,CAAC,KAAK,EAAE,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAC/F,CAAC","sourcesContent":["import {defaultQuery, graphiqlTemplate} from './templates/graphiql.js'\nimport {unauthorizedTemplate} from './templates/unauthorized.js'\nimport {filterCustomHeaders} from './utilities.js'\nimport {performActionWithRetryAfterRecovery} from '../../common/retry.js'\nimport {CLI_KIT_VERSION} from '../../common/version.js'\nimport {AbortError} from '../error.js'\nimport {adminUrl, supportedApiVersions} from '../api/admin.js'\nimport {fetch} from '../http.js'\nimport {renderLiquidTemplate} from '../liquid.js'\nimport {outputDebug} from '../output.js'\nimport {containsMutation} from '../graphql.js'\nimport {\n createApp,\n createRouter,\n defineEventHandler,\n getQuery,\n getRequestHeader,\n getRequestHeaders,\n readBody,\n setResponseHeader,\n setResponseStatus,\n toNodeListener,\n} from 'h3'\nimport {createHmac, randomBytes} from 'crypto'\nimport {createServer, Server} from 'http'\nimport {readFileSync} from 'fs'\nimport {Writable} from 'stream'\nimport {createRequire} from 'module'\n\n/**\n * Derives a deterministic GraphiQL authentication key from the app's API secret and store FQDN.\n * The key is stable across dev server restarts (so browser tabs survive restarts)\n * but is not guessable without the app secret.\n *\n * @param apiSecret - The Partners app's client secret used as the HMAC key.\n * @param storeFqdn - The myshopify.com domain the GraphiQL session targets.\n * @returns A 64-character hex string suitable for use as the `?key=` query param.\n */\nexport function deriveGraphiQLKey(apiSecret: string, storeFqdn: string): string {\n return createHmac('sha256', apiSecret).update(`graphiql:${storeFqdn}`).digest('hex')\n}\n\n/**\n * Resolves the GraphiQL authentication key. Uses the explicitly provided key\n * if non-empty, otherwise derives one deterministically from the app secret.\n *\n * @param providedKey - An explicit key supplied by the caller; takes precedence when non-empty.\n * @param apiSecret - The Partners app's client secret, used to derive a stable key as a fallback.\n * @param storeFqdn - The myshopify.com domain the GraphiQL session targets.\n * @returns The resolved key.\n */\nexport function resolveGraphiQLKey(providedKey: string | undefined, apiSecret: string, storeFqdn: string): string {\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- intentional: empty string after trim should fall through to deriveGraphiQLKey\n return providedKey?.trim() || deriveGraphiQLKey(apiSecret, storeFqdn)\n}\n\nconst require = createRequire(import.meta.url)\n\nclass TokenRefreshError extends AbortError {\n constructor() {\n super('Failed to refresh credentials. Check that your app is installed, and try again.')\n }\n}\n\n/**\n * Pluggable strategy for obtaining and refreshing the Admin API access token\n * that the GraphiQL proxy injects into every request.\n *\n * - `getToken` may return a cached token; the proxy calls it for every request.\n * - `refreshToken` (optional) is invoked when the upstream Admin API returns 401.\n * When omitted, the proxy falls back to calling `getToken` again on 401.\n *\n * Implementations must throw `TokenRefreshError` (or any thrown error) when the\n * token cannot be obtained; the proxy renders the unauthorized template in that case.\n */\nexport interface TokenProvider {\n getToken: () => Promise<string>\n refreshToken?: () => Promise<string>\n}\n\n/**\n * Optional app-specific context, used to render the app pill and scopes note in the\n * GraphiQL header and to drive the deterministic key derivation. Pass when the GraphiQL\n * server is hosted as part of `shopify app dev`; omit for app-less use cases such as\n * `shopify store execute`.\n */\nexport interface GraphiQLAppContext {\n appName: string\n appUrl: string\n apiSecret: string\n}\n\nexport interface SetupGraphiQLServerOptions {\n stdout: Writable\n port: number\n storeFqdn: string\n tokenProvider: TokenProvider\n /**\n * Authentication key required as a `?key=` query string on every request. When omitted:\n * - if `appContext` is provided, derived deterministically from `apiSecret` + `storeFqdn`\n * so browser tabs survive dev server restarts.\n * - otherwise, generated randomly per process.\n */\n key?: string\n appContext?: GraphiQLAppContext\n /**\n * When true, the proxy rejects mutation operations with HTTP 400 before forwarding\n * them to the Admin API. Use this to mirror non-interactive safety guarantees in the\n * interactive UI.\n */\n protectMutations?: boolean\n}\n\nexport const MUTATIONS_BLOCKED_MESSAGE = 'Mutations are disabled. Re-run with --allow-mutations to enable mutations.'\n\n/**\n * Starts a local HTTP server that hosts the GraphiQL UI and proxies requests to the\n * Admin API for the configured store. Authentication is delegated to the supplied\n * `tokenProvider`, so the same server can serve both `shopify app dev` and stored-session\n * use cases.\n *\n * @param options - Configuration for the server, including the target store, the\n * pluggable token provider, and the local port to bind to.\n * @returns The underlying Node `http.Server` instance, already listening on `options.port`.\n */\nexport function setupGraphiQLServer(options: SetupGraphiQLServerOptions): Server {\n const {stdout, port, storeFqdn, tokenProvider, key: providedKey, appContext, protectMutations = false} = options\n const key = resolveGraphiQLServerKey(providedKey, appContext, storeFqdn)\n outputDebug(`Setting up GraphiQL HTTP server on port ${port}...`, stdout)\n\n const app = createApp()\n const router = createRouter()\n\n const refreshUpstreamToken = async (): Promise<string> => {\n try {\n outputDebug('refreshing token', stdout)\n return await (tokenProvider.refreshToken ?? tokenProvider.getToken)()\n } catch (_error) {\n throw new TokenRefreshError()\n }\n }\n\n const currentToken = async (): Promise<string> => {\n try {\n return await tokenProvider.getToken()\n } catch (_error) {\n throw new TokenRefreshError()\n }\n }\n\n async function fetchApiVersionsWithTokenRefresh(): Promise<string[]> {\n return performActionWithRetryAfterRecovery(\n async () => supportedApiVersions({storeFqdn, token: await currentToken()}),\n refreshUpstreamToken,\n )\n }\n\n const faviconPath = require.resolve('@shopify/cli-kit/assets/graphiql/favicon.ico')\n const faviconContent = readFileSync(faviconPath)\n const stylePath = require.resolve('@shopify/cli-kit/assets/graphiql/style.css')\n const styleContent = readFileSync(stylePath, 'utf8')\n\n app.use(\n defineEventHandler((event) => {\n setResponseHeader(event, 'Access-Control-Allow-Origin', '*')\n setResponseHeader(event, 'Access-Control-Allow-Methods', 'GET, OPTIONS')\n setResponseHeader(\n event,\n 'Access-Control-Allow-Headers',\n 'Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, ngrok-skip-browser-warning',\n )\n }),\n )\n\n router.get(\n '/graphiql/ping',\n defineEventHandler(() => 'pong'),\n )\n\n router.get(\n '/graphiql/favicon.ico',\n defineEventHandler((event) => {\n setResponseHeader(event, 'Content-Type', 'image/x-icon')\n return faviconContent\n }),\n )\n\n router.get(\n '/graphiql/simple.css',\n defineEventHandler((event) => {\n setResponseHeader(event, 'Content-Type', 'text/css')\n return styleContent\n }),\n )\n\n router.get(\n '/graphiql/status',\n defineEventHandler(async () => {\n try {\n await fetchApiVersionsWithTokenRefresh()\n return {status: 'OK', storeFqdn, appName: appContext?.appName, appUrl: appContext?.appUrl}\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return {status: 'UNAUTHENTICATED'}\n }\n }),\n )\n\n router.get(\n '/graphiql',\n defineEventHandler(async (event) => {\n outputDebug('Handling /graphiql request', stdout)\n\n const query = getQuery(event)\n\n if (key && query.key !== key) {\n setResponseStatus(event, 404)\n return `Invalid path ${event.path}`\n }\n\n const forwardedProto = getRequestHeader(event, 'x-forwarded-proto')\n const usesHttps = forwardedProto === 'https'\n const host = getRequestHeader(event, 'host')\n const url = `http${usesHttps ? 's' : ''}://${host}`\n\n let apiVersions: string[]\n try {\n apiVersions = await fetchApiVersionsWithTokenRefresh()\n } catch (err) {\n if (err instanceof TokenRefreshError) {\n return renderLiquidTemplate(unauthorizedTemplate({hasAppContext: Boolean(appContext)}), {\n previewUrl: appContext?.appUrl ?? '',\n storeFqdn,\n url,\n })\n }\n throw err\n }\n\n const apiVersion = apiVersions.sort().reverse()[0]!\n\n function decodeQueryString(input: string | undefined) {\n return input ? decodeURIComponent(input).replace(/\\n/g, '\\\\n') : undefined\n }\n\n const queryParam = decodeQueryString(query.query as string | undefined)\n const variables = decodeQueryString(query.variables as string | undefined)\n\n return renderLiquidTemplate(\n graphiqlTemplate({\n apiVersion,\n apiVersions: [...apiVersions, 'unstable'],\n appName: appContext?.appName,\n appUrl: appContext?.appUrl,\n key,\n storeFqdn,\n protectMutations,\n }),\n {\n url,\n defaultQueries: [{query: defaultQuery}],\n query: queryParam ? JSON.stringify(queryParam) : undefined,\n variables: variables ? JSON.stringify(variables) : undefined,\n },\n )\n }),\n )\n\n router.post(\n '/graphiql/graphql.json',\n defineEventHandler(async (event) => {\n outputDebug('Handling /graphiql/graphql.json request', stdout)\n\n const query = getQuery(event)\n\n if (key && query.key !== key) {\n setResponseStatus(event, 404)\n return `Invalid path ${event.path}`\n }\n\n const graphqlUrl = adminUrl(storeFqdn, query.api_version as string)\n try {\n const body = await readBody(event)\n\n if (protectMutations && isMutationRequestBody(body)) {\n setResponseStatus(event, 400)\n return {errors: [{message: MUTATIONS_BLOCKED_MESSAGE}]}\n }\n\n const reqBody = JSON.stringify(body)\n\n const reqHeaders = getRequestHeaders(event)\n const customHeaders = filterCustomHeaders(reqHeaders)\n\n const runRequest = async (token: string) => {\n const headers = {\n ...customHeaders,\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'X-Shopify-Access-Token': token,\n 'User-Agent': `ShopifyCLIGraphiQL/${CLI_KIT_VERSION}`,\n }\n\n return fetch(graphqlUrl, {\n method: 'POST',\n headers,\n body: reqBody,\n })\n }\n\n let result = await runRequest(await currentToken())\n if (result.status === 401) {\n outputDebug('Token expired, fetching new token', stdout)\n result = await runRequest(await refreshUpstreamToken())\n }\n\n setResponseHeader(event, 'Content-Type', 'application/json')\n setResponseStatus(event, result.status)\n return result.json()\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error: unknown) {\n setResponseStatus(event, 500)\n if (error instanceof Error) {\n return {errors: [error.message]}\n }\n return {errors: ['Unknown error']}\n }\n }),\n )\n\n app.use(router)\n\n const server = createServer(toNodeListener(app))\n server.listen(port, 'localhost', () => stdout.write(`GraphiQL server started on port ${port}`))\n return server\n}\n\n// Picks the right key based on what the caller supplied:\n// - explicit non-empty key → use it\n// - app context with apiSecret → derive deterministically (stable across restarts)\n// - otherwise → random per-process key (browser tabs won't survive restarts, which is\n// the right tradeoff when there's no stable secret to derive from).\nfunction resolveGraphiQLServerKey(\n providedKey: string | undefined,\n appContext: GraphiQLAppContext | undefined,\n storeFqdn: string,\n): string {\n const trimmed = providedKey?.trim()\n if (trimmed) return trimmed\n if (appContext) return deriveGraphiQLKey(appContext.apiSecret, storeFqdn)\n return randomBytes(32).toString('hex')\n}\n\nfunction isMutationRequestBody(body: unknown): boolean {\n if (typeof body !== 'object' || body === null) return false\n const {query, operationName} = body as {query?: unknown; operationName?: unknown}\n if (typeof query !== 'string') return false\n return containsMutation(query, typeof operationName === 'string' ? operationName : undefined)\n}\n"]}
@@ -0,0 +1,12 @@
1
+ export declare const defaultQuery: string;
2
+ interface GraphiQLTemplateOptions {
3
+ apiVersion: string;
4
+ apiVersions: string[];
5
+ appName?: string;
6
+ appUrl?: string;
7
+ key: string;
8
+ storeFqdn: string;
9
+ protectMutations?: boolean;
10
+ }
11
+ export declare function graphiqlTemplate({ apiVersion, apiVersions, appName, appUrl, key, storeFqdn, protectMutations, }: GraphiQLTemplateOptions): string;
12
+ export {};