@shopify/cli-kit 3.36.1 → 3.36.2

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 (146) hide show
  1. package/dist/git.d.ts +5 -5
  2. package/dist/git.js +11 -14
  3. package/dist/git.js.map +1 -1
  4. package/dist/index.d.ts +0 -6
  5. package/dist/index.js +0 -6
  6. package/dist/index.js.map +1 -1
  7. package/dist/private/node/analytics.js +5 -4
  8. package/dist/private/node/analytics.js.map +1 -1
  9. package/dist/private/node/api/graphql.js +2 -2
  10. package/dist/private/node/api/graphql.js.map +1 -1
  11. package/dist/private/node/api/headers.d.ts +1 -1
  12. package/dist/private/node/api/headers.js +1 -1
  13. package/dist/private/node/api/headers.js.map +1 -1
  14. package/dist/{secure-store.d.ts → private/node/secure-store.d.ts} +3 -3
  15. package/dist/{secure-store.js → private/node/secure-store.js} +7 -7
  16. package/dist/private/node/secure-store.js.map +1 -0
  17. package/dist/private/node/session/authorize.d.ts +0 -2
  18. package/dist/private/node/session/authorize.js +2 -3
  19. package/dist/private/node/session/authorize.js.map +1 -1
  20. package/dist/private/node/session/device-authorization.js +2 -2
  21. package/dist/private/node/session/device-authorization.js.map +1 -1
  22. package/dist/private/node/session/exchange.d.ts +1 -1
  23. package/dist/private/node/session/exchange.js +1 -2
  24. package/dist/private/node/session/exchange.js.map +1 -1
  25. package/dist/private/node/session/identity.js +2 -2
  26. package/dist/private/node/session/identity.js.map +1 -1
  27. package/dist/private/node/session/post-auth.d.ts +2 -2
  28. package/dist/private/node/session/post-auth.js +2 -2
  29. package/dist/private/node/session/post-auth.js.map +1 -1
  30. package/dist/private/node/session/redirect-listener.js +5 -5
  31. package/dist/private/node/session/redirect-listener.js.map +1 -1
  32. package/dist/private/node/session/schema.d.ts +46 -46
  33. package/dist/private/node/session/schema.js +12 -12
  34. package/dist/private/node/session/schema.js.map +1 -1
  35. package/dist/private/node/session/scopes.js +2 -2
  36. package/dist/private/node/session/scopes.js.map +1 -1
  37. package/dist/private/node/session/store.js +4 -4
  38. package/dist/private/node/session/store.js.map +1 -1
  39. package/dist/private/node/session.js +3 -4
  40. package/dist/private/node/session.js.map +1 -1
  41. package/dist/{testing → private/node/testing}/store.d.ts +1 -1
  42. package/dist/{testing → private/node/testing}/store.js +2 -2
  43. package/dist/private/node/testing/store.js.map +1 -0
  44. package/dist/{testing → private/node/testing}/ui.d.ts +0 -0
  45. package/dist/{testing → private/node/testing}/ui.js +1 -1
  46. package/dist/private/node/testing/ui.js.map +1 -0
  47. package/dist/private/node/ui/components/AutocompletePrompt.test.js +1 -1
  48. package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
  49. package/dist/private/node/ui/components/ConcurrentOutput.test.js +1 -1
  50. package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
  51. package/dist/private/node/ui/components/FatalError.d.ts +1 -1
  52. package/dist/private/node/ui/components/FatalError.js +2 -2
  53. package/dist/private/node/ui/components/FatalError.js.map +1 -1
  54. package/dist/private/node/ui/components/FatalError.test.js +4 -4
  55. package/dist/private/node/ui/components/FatalError.test.js.map +1 -1
  56. package/dist/private/node/ui/components/SelectInput.test.js +1 -1
  57. package/dist/private/node/ui/components/SelectInput.test.js.map +1 -1
  58. package/dist/private/node/ui/components/SelectPrompt.test.js +1 -1
  59. package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
  60. package/dist/private/node/ui/components/Tasks.test.js +1 -1
  61. package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
  62. package/dist/private/node/ui/components/TextInput.test.js +1 -1
  63. package/dist/private/node/ui/components/TextInput.test.js.map +1 -1
  64. package/dist/private/node/ui/components/TextPrompt.test.js +1 -1
  65. package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
  66. package/dist/public/common/version.d.ts +1 -1
  67. package/dist/public/common/version.js +1 -1
  68. package/dist/public/common/version.js.map +1 -1
  69. package/dist/public/node/analytics.js +6 -6
  70. package/dist/public/node/analytics.js.map +1 -1
  71. package/dist/public/node/api/admin.js +3 -3
  72. package/dist/public/node/api/admin.js.map +1 -1
  73. package/dist/public/node/base-command.js +6 -5
  74. package/dist/public/node/base-command.js.map +1 -1
  75. package/dist/public/node/environment/fqdn.d.ts +5 -5
  76. package/dist/public/node/environment/fqdn.js +5 -5
  77. package/dist/public/node/environment/fqdn.js.map +1 -1
  78. package/dist/public/node/environment/spin.js +2 -2
  79. package/dist/public/node/environment/spin.js.map +1 -1
  80. package/dist/public/node/error-handler.d.ts +2 -2
  81. package/dist/public/node/error-handler.js +7 -7
  82. package/dist/public/node/error-handler.js.map +1 -1
  83. package/dist/public/node/error.d.ts +84 -4
  84. package/dist/public/node/error.js +165 -4
  85. package/dist/public/node/error.js.map +1 -1
  86. package/dist/public/node/fs.js +4 -0
  87. package/dist/public/node/fs.js.map +1 -1
  88. package/dist/public/node/git.d.ts +2 -2
  89. package/dist/public/node/git.js +11 -10
  90. package/dist/public/node/git.js.map +1 -1
  91. package/dist/{metadata.d.ts → public/node/metadata.d.ts} +13 -13
  92. package/dist/{metadata.js → public/node/metadata.js} +13 -8
  93. package/dist/public/node/metadata.js.map +1 -0
  94. package/dist/{monorail.d.ts → public/node/monorail.d.ts} +11 -3
  95. package/dist/{monorail.js → public/node/monorail.js} +11 -3
  96. package/dist/public/node/monorail.js.map +1 -0
  97. package/dist/public/node/node-package-manager.d.ts +2 -2
  98. package/dist/public/node/node-package-manager.js +7 -2
  99. package/dist/public/node/node-package-manager.js.map +1 -1
  100. package/dist/public/node/path.d.ts +12 -2
  101. package/dist/public/node/path.js +17 -4
  102. package/dist/public/node/path.js.map +1 -1
  103. package/dist/public/node/plugins/tunnel.d.ts +2 -2
  104. package/dist/public/node/plugins/tunnel.js +1 -1
  105. package/dist/public/node/plugins/tunnel.js.map +1 -1
  106. package/dist/{plugins.d.ts → public/node/plugins.d.ts} +17 -11
  107. package/dist/{plugins.js → public/node/plugins.js} +15 -9
  108. package/dist/public/node/plugins.js.map +1 -0
  109. package/dist/public/node/result.js +3 -4
  110. package/dist/public/node/result.js.map +1 -1
  111. package/dist/public/node/ruby.js +8 -8
  112. package/dist/public/node/ruby.js.map +1 -1
  113. package/dist/public/node/schema.d.ts +1 -0
  114. package/dist/public/node/schema.js +2 -0
  115. package/dist/public/node/schema.js.map +1 -0
  116. package/dist/public/node/session.js +4 -4
  117. package/dist/public/node/session.js.map +1 -1
  118. package/dist/public/node/system.js +4 -3
  119. package/dist/public/node/system.js.map +1 -1
  120. package/dist/public/node/tcp.js +2 -2
  121. package/dist/public/node/tcp.js.map +1 -1
  122. package/dist/public/node/testing/output.d.ts +16 -0
  123. package/dist/{testing → public/node/testing}/output.js +6 -2
  124. package/dist/public/node/testing/output.js.map +1 -0
  125. package/dist/public/node/ui.d.ts +1 -1
  126. package/dist/public/node/ui.js.map +1 -1
  127. package/dist/public/node/vscode.js +2 -2
  128. package/dist/public/node/vscode.js.map +1 -1
  129. package/dist/tsconfig.tsbuildinfo +1 -1
  130. package/dist/ui.js +5 -5
  131. package/dist/ui.js.map +1 -1
  132. package/package.json +1 -1
  133. package/dist/error.d.ts +0 -68
  134. package/dist/error.js +0 -143
  135. package/dist/error.js.map +0 -1
  136. package/dist/metadata.js.map +0 -1
  137. package/dist/monorail.js.map +0 -1
  138. package/dist/plugins.js.map +0 -1
  139. package/dist/schema.d.ts +0 -1
  140. package/dist/schema.js +0 -2
  141. package/dist/schema.js.map +0 -1
  142. package/dist/secure-store.js.map +0 -1
  143. package/dist/testing/output.d.ts +0 -10
  144. package/dist/testing/output.js.map +0 -1
  145. package/dist/testing/store.js.map +0 -1
  146. package/dist/testing/ui.js.map +0 -1
package/dist/git.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { Abort } from './error.js';
1
+ import { AbortError } from './public/node/error.js';
2
2
  import { DefaultLogFields, ListLogLine } from 'simple-git';
3
3
  export declare const factory: import("simple-git").SimpleGitFactory;
4
- export declare const GitNotPresentError: () => Abort;
5
- export declare const OutsideGitDirectoryError: (directory: string) => Abort;
6
- export declare const NoCommitError: () => Abort;
7
- export declare const DetachedHeadError: () => Abort;
4
+ export declare const GitNotPresentError: () => AbortError;
5
+ export declare const OutsideGitDirectoryError: (directory: string) => AbortError;
6
+ export declare const NoCommitError: () => AbortError;
7
+ export declare const DetachedHeadError: () => AbortError;
8
8
  export declare function initializeRepository(directory: string, initialBranch?: string): Promise<void>;
9
9
  export interface GitIgnoreTemplate {
10
10
  [section: string]: string[];
package/dist/git.js CHANGED
@@ -1,24 +1,21 @@
1
- import { Abort } from './error.js';
1
+ import { AbortError } from './public/node/error.js';
2
2
  import { hasGit, isTerminalInteractive } from './public/node/environment/local.js';
3
3
  import { content, token, debug } from './output.js';
4
4
  import { appendFileSync } from './public/node/fs.js';
5
+ import { cwd } from './public/node/path.js';
5
6
  import git from 'simple-git';
6
7
  export const factory = git;
7
8
  export const GitNotPresentError = () => {
8
- // eslint-disable-next-line rulesdir/no-error-factory-functions
9
- return new Abort(`Git is necessary in the environment to continue`, content `Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`);
9
+ return new AbortError(`Git is necessary in the environment to continue`, content `Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`);
10
10
  };
11
11
  export const OutsideGitDirectoryError = (directory) => {
12
- // eslint-disable-next-line rulesdir/no-error-factory-functions
13
- return new Abort(`${token.path(directory)} is not a Git directory`);
12
+ return new AbortError(`${token.path(directory)} is not a Git directory`);
14
13
  };
15
14
  export const NoCommitError = () => {
16
- // eslint-disable-next-line rulesdir/no-error-factory-functions
17
- return new Abort('Must have at least one commit to run command', content `Run ${token.genericShellCommand("git commit -m 'Initial commit'")} to create your first commit.`);
15
+ return new AbortError('Must have at least one commit to run command', content `Run ${token.genericShellCommand("git commit -m 'Initial commit'")} to create your first commit.`);
18
16
  };
19
17
  export const DetachedHeadError = () => {
20
- // eslint-disable-next-line rulesdir/no-error-factory-functions
21
- return new Abort("Git HEAD can't be detached to run command", content `Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link('documentation', 'https://git-scm.com/book/en/v2/Git-Internals-Git-References')} for more details`);
18
+ return new AbortError("Git HEAD can't be detached to run command", content `Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link('documentation', 'https://git-scm.com/book/en/v2/Git-Internals-Git-References')} for more details`);
22
19
  };
23
20
  export async function initializeRepository(directory, initialBranch = 'main') {
24
21
  debug(content `Initializing git repository at ${token.path(directory)}...`);
@@ -44,13 +41,13 @@ export async function downloadRepository({ repoUrl, destination, progressUpdater
44
41
  const [repository, branch] = repoUrl.split('#');
45
42
  const options = { '--recurse-submodules': null };
46
43
  if (branch && latestTag) {
47
- throw new Abort("Error cloning the repository. Git can't clone the latest release with a 'branch'.");
44
+ throw new AbortError("Error cloning the repository. Git can't clone the latest release with a 'branch'.");
48
45
  }
49
46
  if (branch) {
50
47
  options['--branch'] = branch;
51
48
  }
52
49
  if (shallow && latestTag) {
53
- throw new Abort("Error cloning the repository. Git can't clone the latest release with the 'shallow' property.");
50
+ throw new AbortError("Error cloning the repository. Git can't clone the latest release with the 'shallow' property.");
54
51
  }
55
52
  if (shallow) {
56
53
  options['--depth'] = 1;
@@ -74,7 +71,7 @@ export async function downloadRepository({ repoUrl, destination, progressUpdater
74
71
  }
75
72
  catch (err) {
76
73
  if (err instanceof Error) {
77
- const abortError = new Abort(err.message);
74
+ const abortError = new AbortError(err.message);
78
75
  abortError.stack = err.stack;
79
76
  throw abortError;
80
77
  }
@@ -84,7 +81,7 @@ export async function downloadRepository({ repoUrl, destination, progressUpdater
84
81
  async function getLocalLatestTag(repository, repoUrl) {
85
82
  const latest = (await repository.tags()).latest;
86
83
  if (!latest) {
87
- throw new Abort(`Couldn't obtain the most recent tag of the repository ${repoUrl}`);
84
+ throw new AbortError(`Couldn't obtain the most recent tag of the repository ${repoUrl}`);
88
85
  }
89
86
  return latest;
90
87
  }
@@ -127,7 +124,7 @@ export async function ensurePresentOrAbort() {
127
124
  */
128
125
  export async function ensureInsideGitDirectory(directory) {
129
126
  if (!(await git({ baseDir: directory }).checkIsRepo())) {
130
- throw OutsideGitDirectoryError(directory || process.cwd());
127
+ throw OutsideGitDirectoryError(directory || cwd());
131
128
  }
132
129
  }
133
130
  //# sourceMappingURL=git.js.map
package/dist/git.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,MAAM,EAAE,qBAAqB,EAAC,MAAM,oCAAoC,CAAA;AAChF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAA;AAClD,OAAO,GAAoF,MAAM,YAAY,CAAA;AAE7G,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAA;AAE1B,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,+DAA+D;IAC/D,OAAO,IAAI,KAAK,CACd,iDAAiD,EACjD,OAAO,CAAA,WAAW,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,+DAA+D,CAAC,EAAE,CACvG,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC5D,+DAA+D;IAC/D,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAA;AACrE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,+DAA+D;IAC/D,OAAO,IAAI,KAAK,CACd,8CAA8C,EAC9C,OAAO,CAAA,OAAO,KAAK,CAAC,mBAAmB,CAAC,gCAAgC,CAAC,+BAA+B,CACzG,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM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,OAA+C;IAC3F,MAAM,SAAS,GAAG,GAAG,CAAC,EAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,CAAC,CAAA;IAEpD,MAAM,aAAa,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAC,UAAU,EAAE,OAAO,CAAC,MAAM,EAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAChF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IAE7D,OAAO,MAAM,CAAC,MAAM,CAAA;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,SAAkB;IACzD,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,CAAC,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IAC7E,IAAI,CAAC,GAAG;QAAE,MAAM,iBAAiB,EAAE,CAAA;IACnC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,EAAE;QACrB,MAAM,kBAAkB,EAAE,CAAA;KAC3B;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,SAAkB;IAC/D,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE;QACpD,MAAM,wBAAwB,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;KAC3D;AACH,CAAC","sourcesContent":["import {Abort} from './error.js'\nimport {hasGit, isTerminalInteractive} from './public/node/environment/local.js'\nimport {content, token, debug} from './output.js'\nimport {appendFileSync} from './public/node/fs.js'\nimport git, {TaskOptions, SimpleGitProgressEvent, DefaultLogFields, ListLogLine, SimpleGit} from 'simple-git'\n\nexport const factory = git\n\nexport const GitNotPresentError = () => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(\n `Git is necessary in the environment to continue`,\n content`Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`,\n )\n}\n\nexport const OutsideGitDirectoryError = (directory: string) => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(`${token.path(directory)} is not a Git directory`)\n}\n\nexport const NoCommitError = () => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(\n 'Must have at least one commit to run command',\n content`Run ${token.genericShellCommand(\"git commit -m 'Initial commit'\")} to create your first commit.`,\n )\n}\n\nexport const DetachedHeadError = () => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(\n \"Git HEAD can't be detached to run command\",\n content`Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link(\n 'documentation',\n 'https://git-scm.com/book/en/v2/Git-Internals-Git-References',\n )} for more details`,\n )\n}\n\nexport async function initializeRepository(directory: string, initialBranch = 'main') {\n debug(content`Initializing git repository at ${token.path(directory)}...`)\n await ensurePresentOrAbort()\n // We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+\n const repo = git(directory)\n await repo.init()\n await repo.checkoutLocalBranch(initialBranch)\n}\n\nexport interface GitIgnoreTemplate {\n [section: string]: string[]\n}\nexport function createGitIgnore(directory: string, template: GitIgnoreTemplate): void {\n debug(content`Creating .gitignore at ${token.path(directory)}...`)\n const filePath = `${directory}/.gitignore`\n\n let fileContent = ''\n for (const [section, lines] of Object.entries(template)) {\n fileContent += `# ${section}\\n`\n fileContent += `${lines.join('\\n')}\\n\\n`\n }\n\n appendFileSync(filePath, fileContent)\n}\n\nexport async function downloadRepository({\n repoUrl,\n destination,\n progressUpdater,\n shallow,\n latestTag,\n}: {\n repoUrl: string\n destination: string\n progressUpdater?: (statusString: string) => void\n shallow?: boolean\n latestTag?: boolean\n}) {\n debug(content`Git-cloning repository ${repoUrl} into ${token.path(destination)}...`)\n await ensurePresentOrAbort()\n const [repository, branch] = repoUrl.split('#')\n const options: TaskOptions = {'--recurse-submodules': null}\n\n if (branch && latestTag) {\n throw new Abort(\"Error cloning the repository. Git can't clone the latest release with a 'branch'.\")\n }\n if (branch) {\n options['--branch'] = branch\n }\n\n if (shallow && latestTag) {\n throw new Abort(\"Error cloning the repository. Git can't clone the latest release with the 'shallow' property.\")\n }\n if (shallow) {\n options['--depth'] = 1\n }\n\n const progress = ({stage, progress, processed, total}: SimpleGitProgressEvent) => {\n const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`\n if (progressUpdater) progressUpdater(updateString)\n }\n\n const simpleGitOptions = {\n progress,\n ...(!isTerminalInteractive() && {config: ['core.askpass=true']}),\n }\n try {\n await git(simpleGitOptions).clone(repository!, destination, options)\n\n if (latestTag) {\n const localGitRepository = git(destination)\n const latestTag = await getLocalLatestTag(localGitRepository, repoUrl)\n await localGitRepository.checkout(latestTag)\n }\n } catch (err) {\n if (err instanceof Error) {\n const abortError = new Abort(err.message)\n abortError.stack = err.stack\n throw abortError\n }\n throw err\n }\n}\n\nasync function getLocalLatestTag(repository: SimpleGit, repoUrl: string) {\n const latest = (await repository.tags()).latest\n\n if (!latest) {\n throw new Abort(`Couldn't obtain the most recent tag of the repository ${repoUrl}`)\n }\n\n return latest\n}\n\nexport async function getLatestCommit(directory?: string): Promise<DefaultLogFields & ListLogLine> {\n const logs = await git({baseDir: directory}).log({\n maxCount: 1,\n })\n if (!logs.latest) throw NoCommitError()\n return logs.latest\n}\n\nexport async function addAll(directory?: string): Promise<void> {\n const simpleGit = git({baseDir: directory})\n await simpleGit.raw('add', '--all')\n}\n\nexport async function commit(message: string, options?: {directory?: string; author?: string}): Promise<string> {\n const simpleGit = git({baseDir: options?.directory})\n\n const commitOptions = options?.author ? {'--author': options.author} : undefined\n const result = await simpleGit.commit(message, commitOptions)\n\n return result.commit\n}\n\nexport async function getHeadSymbolicRef(directory?: string): Promise<string> {\n const ref = await git({baseDir: directory}).raw('symbolic-ref', '-q', 'HEAD')\n if (!ref) throw DetachedHeadError()\n return ref.trim()\n}\n\n/**\n * If \"git\" is not present in the environment it throws\n * an abort error.\n */\nexport async function ensurePresentOrAbort() {\n if (!(await hasGit())) {\n throw GitNotPresentError()\n }\n}\n\n/**\n * If command run from outside a .git directory tree\n * it throws an abort error.\n */\nexport async function ensureInsideGitDirectory(directory?: string) {\n if (!(await git({baseDir: directory}).checkIsRepo())) {\n throw OutsideGitDirectoryError(directory || process.cwd())\n }\n}\n"]}
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAC,MAAM,EAAE,qBAAqB,EAAC,MAAM,oCAAoC,CAAA;AAChF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAC,GAAG,EAAC,MAAM,uBAAuB,CAAA;AACzC,OAAO,GAAoF,MAAM,YAAY,CAAA;AAE7G,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAA;AAE1B,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO,IAAI,UAAU,CACnB,iDAAiD,EACjD,OAAO,CAAA,WAAW,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,+DAA+D,CAAC,EAAE,CACvG,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC5D,OAAO,IAAI,UAAU,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAA;AAC1E,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa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D;AACH,CAAC","sourcesContent":["import {AbortError} from './public/node/error.js'\nimport {hasGit, isTerminalInteractive} from './public/node/environment/local.js'\nimport {content, token, debug} from './output.js'\nimport {appendFileSync} from './public/node/fs.js'\nimport {cwd} from './public/node/path.js'\nimport git, {TaskOptions, SimpleGitProgressEvent, DefaultLogFields, ListLogLine, SimpleGit} from 'simple-git'\n\nexport const factory = git\n\nexport const GitNotPresentError = () => {\n return new AbortError(\n `Git is necessary in the environment to continue`,\n content`Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`,\n )\n}\n\nexport const OutsideGitDirectoryError = (directory: string) => {\n return new AbortError(`${token.path(directory)} is not a Git directory`)\n}\n\nexport const NoCommitError = () => {\n return new AbortError(\n 'Must have at least one commit to run command',\n content`Run ${token.genericShellCommand(\"git commit -m 'Initial commit'\")} to create your first commit.`,\n )\n}\n\nexport const DetachedHeadError = () => {\n return new AbortError(\n \"Git HEAD can't be detached to run command\",\n content`Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link(\n 'documentation',\n 'https://git-scm.com/book/en/v2/Git-Internals-Git-References',\n )} for more details`,\n )\n}\n\nexport async function initializeRepository(directory: string, initialBranch = 'main') {\n debug(content`Initializing git repository at ${token.path(directory)}...`)\n await ensurePresentOrAbort()\n // We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+\n const repo = git(directory)\n await repo.init()\n await repo.checkoutLocalBranch(initialBranch)\n}\n\nexport interface GitIgnoreTemplate {\n [section: string]: string[]\n}\nexport function createGitIgnore(directory: string, template: GitIgnoreTemplate): void {\n debug(content`Creating .gitignore at ${token.path(directory)}...`)\n const filePath = `${directory}/.gitignore`\n\n let fileContent = ''\n for (const [section, lines] of Object.entries(template)) {\n fileContent += `# ${section}\\n`\n fileContent += `${lines.join('\\n')}\\n\\n`\n }\n\n appendFileSync(filePath, fileContent)\n}\n\nexport async function downloadRepository({\n repoUrl,\n destination,\n progressUpdater,\n shallow,\n latestTag,\n}: {\n repoUrl: string\n destination: string\n progressUpdater?: (statusString: string) => void\n shallow?: boolean\n latestTag?: boolean\n}) {\n debug(content`Git-cloning repository ${repoUrl} into ${token.path(destination)}...`)\n await ensurePresentOrAbort()\n const [repository, branch] = repoUrl.split('#')\n const options: TaskOptions = {'--recurse-submodules': null}\n\n if (branch && latestTag) {\n throw new AbortError(\"Error cloning the repository. Git can't clone the latest release with a 'branch'.\")\n }\n if (branch) {\n options['--branch'] = branch\n }\n\n if (shallow && latestTag) {\n throw new AbortError(\n \"Error cloning the repository. Git can't clone the latest release with the 'shallow' property.\",\n )\n }\n if (shallow) {\n options['--depth'] = 1\n }\n\n const progress = ({stage, progress, processed, total}: SimpleGitProgressEvent) => {\n const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`\n if (progressUpdater) progressUpdater(updateString)\n }\n\n const simpleGitOptions = {\n progress,\n ...(!isTerminalInteractive() && {config: ['core.askpass=true']}),\n }\n try {\n await git(simpleGitOptions).clone(repository!, destination, options)\n\n if (latestTag) {\n const localGitRepository = git(destination)\n const latestTag = await getLocalLatestTag(localGitRepository, repoUrl)\n await localGitRepository.checkout(latestTag)\n }\n } catch (err) {\n if (err instanceof Error) {\n const abortError = new AbortError(err.message)\n abortError.stack = err.stack\n throw abortError\n }\n throw err\n }\n}\n\nasync function getLocalLatestTag(repository: SimpleGit, repoUrl: string) {\n const latest = (await repository.tags()).latest\n\n if (!latest) {\n throw new AbortError(`Couldn't obtain the most recent tag of the repository ${repoUrl}`)\n }\n\n return latest\n}\n\nexport async function getLatestCommit(directory?: string): Promise<DefaultLogFields & ListLogLine> {\n const logs = await git({baseDir: directory}).log({\n maxCount: 1,\n })\n if (!logs.latest) throw NoCommitError()\n return logs.latest\n}\n\nexport async function addAll(directory?: string): Promise<void> {\n const simpleGit = git({baseDir: directory})\n await simpleGit.raw('add', '--all')\n}\n\nexport async function commit(message: string, options?: {directory?: string; author?: string}): Promise<string> {\n const simpleGit = git({baseDir: options?.directory})\n\n const commitOptions = options?.author ? {'--author': options.author} : undefined\n const result = await simpleGit.commit(message, commitOptions)\n\n return result.commit\n}\n\nexport async function getHeadSymbolicRef(directory?: string): Promise<string> {\n const ref = await git({baseDir: directory}).raw('symbolic-ref', '-q', 'HEAD')\n if (!ref) throw DetachedHeadError()\n return ref.trim()\n}\n\n/**\n * If \"git\" is not present in the environment it throws\n * an abort error.\n */\nexport async function ensurePresentOrAbort() {\n if (!(await hasGit())) {\n throw GitNotPresentError()\n }\n}\n\n/**\n * If command run from outside a .git directory tree\n * it throws an abort error.\n */\nexport async function ensureInsideGitDirectory(directory?: string) {\n if (!(await git({baseDir: directory}).checkIsRepo())) {\n throw OutsideGitDirectoryError(directory || cwd())\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,3 @@
1
- export * as error from './error.js';
2
1
  export * as output from './output.js';
3
- export * as plugins from './plugins.js';
4
- export * as schema from './schema.js';
5
2
  export * as store from './store.js';
6
3
  export * as ui from './ui.js';
7
- export * as outputMocker from './testing/output.js';
8
- export * as metadata from './metadata.js';
9
- export * as monorail from './monorail.js';
package/dist/index.js CHANGED
@@ -1,10 +1,4 @@
1
- export * as error from './error.js';
2
1
  export * as output from './output.js';
3
- export * as plugins from './plugins.js';
4
- export * as schema from './schema.js';
5
2
  export * as store from './store.js';
6
3
  export * as ui from './ui.js';
7
- export * as outputMocker from './testing/output.js';
8
- export * as metadata from './metadata.js';
9
- export * as monorail from './monorail.js';
10
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA","sourcesContent":["export * as error from './error.js'\nexport * as output from './output.js'\nexport * as plugins from './plugins.js'\nexport * as schema from './schema.js'\nexport * as store from './store.js'\nexport * as ui from './ui.js'\nexport * as outputMocker from './testing/output.js'\nexport * as metadata from './metadata.js'\nexport * as monorail from './monorail.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA","sourcesContent":["export * as output from './output.js'\nexport * as store from './store.js'\nexport * as ui from './ui.js'\n"]}
@@ -1,21 +1,22 @@
1
1
  import { hashString } from '../../public/node/crypto.js';
2
2
  import { getPackageManager, packageManagerUsedForCreating } from '../../public/node/node-package-manager.js';
3
- import * as metadata from '../../metadata.js';
3
+ import * as metadata from '../../public/node/metadata.js';
4
4
  import { platformAndArch } from '../../public/node/os.js';
5
5
  import { ciPlatform, cloudEnvironment, macAddress } from '@shopify/cli-kit/node/environment/local';
6
+ import { cwd } from '@shopify/cli-kit/node/path';
6
7
  export async function startAnalytics({ commandContent, args, currentTime = new Date().getTime(), commandClass, }) {
7
8
  let startCommand = commandContent.command;
8
9
  if (commandClass && Object.prototype.hasOwnProperty.call(commandClass, 'analyticsNameOverride')) {
9
10
  startCommand = commandClass.analyticsNameOverride() ?? commandContent.command;
10
11
  }
11
- await metadata.addSensitive(() => ({
12
+ await metadata.addSensitiveMetadata(() => ({
12
13
  commandStartOptions: {
13
14
  startTime: currentTime,
14
15
  startCommand,
15
16
  startArgs: args,
16
17
  },
17
18
  }));
18
- await metadata.addPublic(() => ({
19
+ await metadata.addPublicMetadata(() => ({
19
20
  cmd_all_launcher: packageManagerUsedForCreating(),
20
21
  cmd_all_alias_used: commandContent.alias,
21
22
  cmd_all_topic: commandContent.topic,
@@ -37,7 +38,7 @@ export async function getEnvironmentData(config) {
37
38
  env_web_ide: cloudEnvironment().editor ? cloudEnvironment().platform : undefined,
38
39
  env_device_id: hashString(await macAddress()),
39
40
  env_cloud: cloudEnvironment().platform,
40
- env_package_manager: await getPackageManager(process.cwd()),
41
+ env_package_manager: await getPackageManager(cwd()),
41
42
  };
42
43
  }
43
44
  export async function getSensitiveEnvironmentData(config) {
@@ -1 +1 @@
1
- {"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../../src/private/node/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAC,iBAAiB,EAAE,6BAA6B,EAAC,MAAM,2CAA2C,CAAA;AAG1G,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAA;AAEvD,OAAO,EAAC,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAC,MAAM,yCAAyC,CAAA;AAShG,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,cAAc,EACd,IAAI,EACJ,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAClC,YAAY,GACC;IACb,IAAI,YAAY,GAAW,cAAc,CAAC,OAAO,CAAA;IACjD,IAAI,YAAY,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,uBAAuB,CAAC,EAAE;QAC/F,YAAY,GAAI,YAAmC,CAAC,qBAAqB,EAAE,IAAI,cAAc,CAAC,OAAO,CAAA;KACtG;IAED,MAAM,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;QACjC,mBAAmB,EAAE;YACnB,SAAS,E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AAC,GAAG,EAAE,CAAC;KAC5D,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,MAAyB;IACzE,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 {hashString} from '../../public/node/crypto.js'\nimport {getPackageManager, packageManagerUsedForCreating} from '../../public/node/node-package-manager.js'\nimport BaseCommand from '../../public/node/base-command.js'\nimport {CommandContent} from '../../public/node/hooks/prerun.js'\nimport * as metadata from '../../metadata.js'\nimport {platformAndArch} from '../../public/node/os.js'\nimport {Interfaces} from '@oclif/core'\nimport {ciPlatform, cloudEnvironment, macAddress} from '@shopify/cli-kit/node/environment/local'\n\ninterface StartOptions {\n commandContent: CommandContent\n args: string[]\n currentTime?: number\n commandClass?: Interfaces.Command.Class | typeof BaseCommand\n}\n\nexport async function startAnalytics({\n commandContent,\n args,\n currentTime = new Date().getTime(),\n commandClass,\n}: StartOptions): Promise<void> {\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 EnvironmentData {\n uname: string\n env_ci: boolean\n env_ci_platform?: string\n env_plugin_installed_any_custom: boolean\n env_plugin_installed_shopify: string\n env_shell: string\n env_web_ide: string | undefined\n env_device_id: string\n env_cloud: string\n env_package_manager: string\n}\n\nexport async function getEnvironmentData(config: Interfaces.Config): Promise<EnvironmentData> {\n const ciplatform = 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: cloudEnvironment().editor ? cloudEnvironment().platform : undefined,\n env_device_id: hashString(await macAddress()),\n env_cloud: cloudEnvironment().platform,\n env_package_manager: await getPackageManager(process.cwd()),\n }\n}\n\nexport async 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"]}
1
+ {"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../../src/private/node/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAC,iBAAiB,EAAE,6BAA6B,EAAC,MAAM,2CAA2C,CAAA;AAG1G,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAA;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAA;AAEvD,OAAO,EAAC,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAC,MAAM,yCAAyC,CAAA;AAChG,OAAO,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,IAAI,EAAE;QAC5B,MAAM,EAAE,UAAU,CAAC,IAAI;QACvB,eAAe,EAAE,UAAU,CAAC,IAAI;QAChC,+BAA+B,EAAE,WAAW,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM;QAC7E,4BAA4B,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;QAC5D,SAAS,EAAE,MAAM,CAAC,KAAK;QACvB,WAAW,EAAE,gBAAgB,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QAChF,aAAa,EAAE,UAAU,CAAC,MAAM,UAAU,EAAE,CAAC;QAC7C,SAAS,EAAE,gBAAgB,EAAE,CAAC,QAAQ;QACtC,mBAAmB,EAAE,MAAM,iBAAiB,CAAC,GAAG,EAAE,CAAC;KACpD,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,MAAyB;IACzE,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 {hashString} from '../../public/node/crypto.js'\nimport {getPackageManager, packageManagerUsedForCreating} from '../../public/node/node-package-manager.js'\nimport BaseCommand from '../../public/node/base-command.js'\nimport {CommandContent} from '../../public/node/hooks/prerun.js'\nimport * as metadata from '../../public/node/metadata.js'\nimport {platformAndArch} from '../../public/node/os.js'\nimport {Interfaces} from '@oclif/core'\nimport {ciPlatform, cloudEnvironment, macAddress} from '@shopify/cli-kit/node/environment/local'\nimport {cwd} from '@shopify/cli-kit/node/path'\n\ninterface StartOptions {\n commandContent: CommandContent\n args: string[]\n currentTime?: number\n commandClass?: Interfaces.Command.Class | typeof BaseCommand\n}\n\nexport async function startAnalytics({\n commandContent,\n args,\n currentTime = new Date().getTime(),\n commandClass,\n}: StartOptions): Promise<void> {\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.addSensitiveMetadata(() => ({\n commandStartOptions: {\n startTime: currentTime,\n startCommand,\n startArgs: args,\n },\n }))\n\n await metadata.addPublicMetadata(() => ({\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 EnvironmentData {\n uname: string\n env_ci: boolean\n env_ci_platform?: string\n env_plugin_installed_any_custom: boolean\n env_plugin_installed_shopify: string\n env_shell: string\n env_web_ide: string | undefined\n env_device_id: string\n env_cloud: string\n env_package_manager: string\n}\n\nexport async function getEnvironmentData(config: Interfaces.Config): Promise<EnvironmentData> {\n const ciplatform = 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: cloudEnvironment().editor ? cloudEnvironment().platform : undefined,\n env_device_id: hashString(await macAddress()),\n env_cloud: cloudEnvironment().platform,\n env_package_manager: await getPackageManager(cwd()),\n }\n}\n\nexport async 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"]}
@@ -1,6 +1,6 @@
1
1
  import { buildHeaders, httpsAgent, RequestClientError, sanitizedHeadersOutput } from './headers.js';
2
2
  import { stringifyMessage, content, token as outputToken, token, debug } from '../../../output.js';
3
- import { Abort } from '../../../error.js';
3
+ import { AbortError } from '../../../public/node/error.js';
4
4
  import { ClientError, GraphQLClient } from 'graphql-request';
5
5
  import { performance } from 'perf_hooks';
6
6
  export function graphqlRequest(query, api, url, token, variables, handleErrors = true) {
@@ -50,7 +50,7 @@ async function handlingErrors(api, action) {
50
50
  mappedError = new RequestClientError(errorMessage, error.response.status);
51
51
  }
52
52
  else {
53
- mappedError = new Abort(errorMessage);
53
+ mappedError = new AbortError(errorMessage);
54
54
  }
55
55
  mappedError.stack = error.stack;
56
56
  throw mappedError;
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../../src/private/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,cAAc,CAAA;AACjG,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AAChG,OAAO,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAC,WAAW,EAAE,aAAa,EAA6B,MAAM,iBAAiB,CAAA;AACtF,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAA;AAOtC,MAAM,UAAU,cAAc,CAC5B,KAAsB,EACtB,GAAW,EACX,GAAW,EACX,KAAa,EACb,SAAqB,EACrB,YAAY,GAAG,IAAI;IAEnB,MAAM,MAAM,GAAG,KAAK,IAA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ACpE,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 {buildHeaders, httpsAgent, RequestClientError, sanitizedHeadersOutput} from './headers.js'\nimport {stringifyMessage, content, token as outputToken, token, debug} from '../../../output.js'\nimport {Abort} from '../../../error.js'\nimport {ClientError, GraphQLClient, RequestDocument, Variables} from 'graphql-request'\nimport {performance} from 'perf_hooks'\n\nexport interface GraphQLVariables {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n}\n\nexport function graphqlRequest<T>(\n query: RequestDocument,\n api: string,\n url: string,\n token: string,\n variables?: Variables,\n handleErrors = true,\n): Promise<T> {\n const action = async () => {\n const headers = buildHeaders(token)\n debugLogRequest(api, query, variables, headers)\n const clientOptions = {agent: await httpsAgent(), headers}\n const client = new GraphQLClient(url, clientOptions)\n const t0 = performance.now()\n const response = await client.request<T>(query, variables)\n const t1 = performance.now()\n debug(`Request to ${url.toString()} completed in ${Math.round(t1 - t0)} ms`)\n return response\n }\n\n if (handleErrors) {\n return handlingErrors(api, action)\n } else {\n return action()\n }\n}\n\nfunction debugLogRequest<T>(\n api: string,\n query: RequestDocument,\n variables?: Variables,\n headers: {[key: string]: string} = {},\n) {\n debug(content`\nSending ${token.json(api)} GraphQL request:\n${token.raw(query.toString())}\n\nWith variables:\n${variables ? JSON.stringify(variables, null, 2) : ''}\n\nAnd headers:\n${sanitizedHeadersOutput(headers)}\n`)\n}\n\nasync 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":"graphql.js","sourceRoot":"","sources":["../../../../src/private/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,cAAc,CAAA;AACjG,OAAO,EAAC,gBAAgB,EAAE,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AAChG,OAAO,EAAC,UAAU,EAAC,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAC,WAAW,EAAE,aAAa,EAA6B,MAAM,iBAAiB,CAAA;AACtF,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAA;AAOtC,MAAM,UAAU,cAAc,CAC5B,KAAsB,EACtB,GAAW,EACX,GAAW,EACX,KAAa,EACb,SAAqB,EACrB,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AC;AAED,KAAK,UAAU,cAAc,CAAI,GAAW,EAAE,MAAwB;IACpE,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,UAAU,CAAC,YAAY,CAAC,CAAA;aAC3C;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 {buildHeaders, httpsAgent, RequestClientError, sanitizedHeadersOutput} from './headers.js'\nimport {stringifyMessage, content, token as outputToken, token, debug} from '../../../output.js'\nimport {AbortError} from '../../../public/node/error.js'\nimport {ClientError, GraphQLClient, RequestDocument, Variables} from 'graphql-request'\nimport {performance} from 'perf_hooks'\n\nexport interface GraphQLVariables {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any\n}\n\nexport function graphqlRequest<T>(\n query: RequestDocument,\n api: string,\n url: string,\n token: string,\n variables?: Variables,\n handleErrors = true,\n): Promise<T> {\n const action = async () => {\n const headers = buildHeaders(token)\n debugLogRequest(api, query, variables, headers)\n const clientOptions = {agent: await httpsAgent(), headers}\n const client = new GraphQLClient(url, clientOptions)\n const t0 = performance.now()\n const response = await client.request<T>(query, variables)\n const t1 = performance.now()\n debug(`Request to ${url.toString()} completed in ${Math.round(t1 - t0)} ms`)\n return response\n }\n\n if (handleErrors) {\n return handlingErrors(api, action)\n } else {\n return action()\n }\n}\n\nfunction debugLogRequest<T>(\n api: string,\n query: RequestDocument,\n variables?: Variables,\n headers: {[key: string]: string} = {},\n) {\n debug(content`\nSending ${token.json(api)} GraphQL request:\n${token.raw(query.toString())}\n\nWith variables:\n${variables ? JSON.stringify(variables, null, 2) : ''}\n\nAnd headers:\n${sanitizedHeadersOutput(headers)}\n`)\n}\n\nasync 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 AbortError(errorMessage)\n }\n mappedError.stack = error.stack\n throw mappedError\n } else {\n throw error\n }\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { ExtendableError } from '../../../error.js';
2
+ import { ExtendableError } from '../../../public/node/error.js';
3
3
  import https from 'https';
4
4
  export declare class RequestClientError extends ExtendableError {
5
5
  statusCode: number;
@@ -1,8 +1,8 @@
1
1
  import { CLI_KIT_VERSION } from '../../../public/common/version.js';
2
2
  import { firstPartyDev } from '../../../public/node/environment/local.js';
3
- import { ExtendableError } from '../../../error.js';
4
3
  import { randomUUID } from '../../../public/node/crypto.js';
5
4
  import { Environment, serviceEnvironment } from '../environment/service.js';
5
+ import { ExtendableError } from '../../../public/node/error.js';
6
6
  import https from 'https';
7
7
  export class RequestClientError extends ExtendableError {
8
8
  constructor(message, statusCode) {
@@ -1 +1 @@
1
-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A;AACf,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,SAAS,GAAG,kBAAkB,eAAe,EAAE,CAAA;IAErD,MAAM,OAAO,GAA+B;QAC1C,YAAY,EAAE,SAAS;QACvB,0DAA0D;QAC1D,oBAAoB,EAAE,OAAO,CAAC,QAAQ;QACtC,cAAc,EAAE,UAAU,EAAE;QAC5B,cAAc,EAAE,kBAAkB;QAClC,GAAG,CAAC,aAAa,EAAE,IAAI,EAAC,wBAAwB,EAAE,GAAG,EAAC,CAAC;KACxD,CAAA;IACD,IAAI,KAAK,EAAE;QACT,wCAAwC;QACxC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,KAAK,EAAE,CAAA;QAC5C,OAAO,CAAC,wBAAwB,CAAC,GAAG,UAAU,KAAK,EAAE,CAAA;KACtD;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,EAAC,kBAAkB,EAAE,MAAM,gCAAgC,EAAE,EAAC,CAAC,CAAA;AACxF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,gCAAgC;IAC7C,OAAO,CAAC,MAAM,kBAAkB,EAAE,CAAC,KAAK,WAAW,CAAC,IAAI,CAAA;AAC1D,CAAC","sourcesContent":["import {CLI_KIT_VERSION} from '../../../public/common/version.js'\nimport {firstPartyDev} from '../../../public/node/environment/local.js'\nimport {ExtendableError} from '../../../error.js'\nimport {randomUUID} from '../../../public/node/crypto.js'\nimport {Environment, serviceEnvironment} from '../environment/service.js'\nimport https from 'https'\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\n/**\n * Removes the sensitive data from the headers and outputs them as a string.\n * @param headers - HTTP headers.\n * @returns 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 buildHeaders(token?: string): {[key: string]: string} {\n const userAgent = `Shopify CLI; v=${CLI_KIT_VERSION}`\n\n const headers: {[header: string]: string} = {\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 'Content-Type': 'application/json',\n ...(firstPartyDev() && {'X-Shopify-Cli-Employee': '1'}),\n }\n if (token) {\n // eslint-disable-next-line dot-notation\n headers['authorization'] = `Bearer ${token}`\n headers['X-Shopify-Access-Token'] = `Bearer ${token}`\n }\n\n return headers\n}\n\n/**\n * This utility function returns the https.Agent to use for a given service. The agent\n * includes the right configuration based on the service's environment. For example,\n * if the service is running in a Spin environment, the attribute \"rejectUnauthorized\" is\n * set to false\n */\nexport async function httpsAgent() {\n return new https.Agent({rejectUnauthorized: await shouldRejectUnauthorizedRequests()})\n}\n\n/**\n * Spin stores the CA certificate in the keychain and it should be used when sending HTTP\n * requests to Spin instances. However, Node doesn't read certificates from the Keychain\n * by default, which leads to Shopifolks running into issues that they workaround by setting the\n * NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable, which applies to all the HTTP\n * requests sent from the CLI (context: https://github.com/nodejs/node/issues/39657)\n * This utility function allows controlling the behavior in a per-service level by returning\n * the value of for the \"rejectUnauthorized\" attribute that's used in the https agent.\n *\n * @returns A promise that resolves with a boolean indicating whether\n * unauthorized requests should be rejected or not.\n */\nasync function shouldRejectUnauthorizedRequests(): Promise<boolean> {\n return (await serviceEnvironment()) !== Environment.Spin\n}\n"]}
1
+ {"version":3,"file":"headers.js","source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AM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,SAAS,GAAG,kBAAkB,eAAe,EAAE,CAAA;IAErD,MAAM,OAAO,GAA+B;QAC1C,YAAY,EAAE,SAAS;QACvB,0DAA0D;QAC1D,oBAAoB,EAAE,OAAO,CAAC,QAAQ;QACtC,cAAc,EAAE,UAAU,EAAE;QAC5B,cAAc,EAAE,kBAAkB;QAClC,GAAG,CAAC,aAAa,EAAE,IAAI,EAAC,wBAAwB,EAAE,GAAG,EAAC,CAAC;KACxD,CAAA;IACD,IAAI,KAAK,EAAE;QACT,wCAAwC;QACxC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,KAAK,EAAE,CAAA;QAC5C,OAAO,CAAC,wBAAwB,CAAC,GAAG,UAAU,KAAK,EAAE,CAAA;KACtD;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,EAAC,kBAAkB,EAAE,MAAM,gCAAgC,EAAE,EAAC,CAAC,CAAA;AACxF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,gCAAgC;IAC7C,OAAO,CAAC,MAAM,kBAAkB,EAAE,CAAC,KAAK,WAAW,CAAC,IAAI,CAAA;AAC1D,CAAC","sourcesContent":["import {CLI_KIT_VERSION} from '../../../public/common/version.js'\nimport {firstPartyDev} from '../../../public/node/environment/local.js'\nimport {randomUUID} from '../../../public/node/crypto.js'\nimport {Environment, serviceEnvironment} from '../environment/service.js'\nimport {ExtendableError} from '../../../public/node/error.js'\nimport https from 'https'\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\n/**\n * Removes the sensitive data from the headers and outputs them as a string.\n * @param headers - HTTP headers.\n * @returns 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 buildHeaders(token?: string): {[key: string]: string} {\n const userAgent = `Shopify CLI; v=${CLI_KIT_VERSION}`\n\n const headers: {[header: string]: string} = {\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 'Content-Type': 'application/json',\n ...(firstPartyDev() && {'X-Shopify-Cli-Employee': '1'}),\n }\n if (token) {\n // eslint-disable-next-line dot-notation\n headers['authorization'] = `Bearer ${token}`\n headers['X-Shopify-Access-Token'] = `Bearer ${token}`\n }\n\n return headers\n}\n\n/**\n * This utility function returns the https.Agent to use for a given service. The agent\n * includes the right configuration based on the service's environment. For example,\n * if the service is running in a Spin environment, the attribute \"rejectUnauthorized\" is\n * set to false\n */\nexport async function httpsAgent() {\n return new https.Agent({rejectUnauthorized: await shouldRejectUnauthorizedRequests()})\n}\n\n/**\n * Spin stores the CA certificate in the keychain and it should be used when sending HTTP\n * requests to Spin instances. However, Node doesn't read certificates from the Keychain\n * by default, which leads to Shopifolks running into issues that they workaround by setting the\n * NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable, which applies to all the HTTP\n * requests sent from the CLI (context: https://github.com/nodejs/node/issues/39657)\n * This utility function allows controlling the behavior in a per-service level by returning\n * the value of for the \"rejectUnauthorized\" attribute that's used in the https agent.\n *\n * @returns A promise that resolves with a boolean indicating whether\n * unauthorized requests should be rejected or not.\n */\nasync function shouldRejectUnauthorizedRequests(): Promise<boolean> {\n return (await serviceEnvironment()) !== Environment.Spin\n}\n"]}
@@ -3,17 +3,17 @@
3
3
  * @param identifier - Identifier to identify the content.
4
4
  * @returns A promise that resolves with the content or null if it doesn't exist.
5
5
  */
6
- export declare function fetch(identifier: string): Promise<string | null>;
6
+ export declare function secureStoreFetch(identifier: string): Promise<string | null>;
7
7
  /**
8
8
  * Securely stores the content under the given key.
9
9
  * @param identifier - Identifier to identify the content.
10
10
  * @param content - The content to be stored.
11
11
  * @returns A promise that resolves when the storing completes.
12
12
  */
13
- export declare function store(identifier: string, content: string): Promise<void>;
13
+ export declare function secureStoreSave(identifier: string, content: string): Promise<void>;
14
14
  /**
15
15
  * Removes the content with the given identifier.
16
16
  * @param identifier - Identifier to identify the content.
17
17
  * @returns A promise that resolves with true if the content was deleted.
18
18
  */
19
- export declare function remove(identifier: string): Promise<boolean>;
19
+ export declare function secureStoreRemove(identifier: string): Promise<boolean>;
@@ -1,12 +1,12 @@
1
- import { content as outputContent, debug } from './output.js';
2
- import { Abort } from './error.js';
3
- import { keychainConstants } from './private/node/constants.js';
1
+ import { keychainConstants } from './constants.js';
2
+ import { AbortError } from '../../public/node/error.js';
3
+ import { content as outputContent, debug } from '../../output.js';
4
4
  /**
5
5
  * Fetches secured content from the system's keychain.
6
6
  * @param identifier - Identifier to identify the content.
7
7
  * @returns A promise that resolves with the content or null if it doesn't exist.
8
8
  */
9
- export async function fetch(identifier) {
9
+ export async function secureStoreFetch(identifier) {
10
10
  debug(outputContent `Reading ${identifier} from the secure store...`);
11
11
  try {
12
12
  const keytar = await import('keytar');
@@ -23,7 +23,7 @@ export async function fetch(identifier) {
23
23
  * @param content - The content to be stored.
24
24
  * @returns A promise that resolves when the storing completes.
25
25
  */
26
- export async function store(identifier, content) {
26
+ export async function secureStoreSave(identifier, content) {
27
27
  debug(outputContent `Updating ${identifier} in the secure store with new content...`);
28
28
  try {
29
29
  const keytar = await import('keytar');
@@ -38,7 +38,7 @@ export async function store(identifier, content) {
38
38
  * @param identifier - Identifier to identify the content.
39
39
  * @returns A promise that resolves with true if the content was deleted.
40
40
  */
41
- export async function remove(identifier) {
41
+ export async function secureStoreRemove(identifier) {
42
42
  debug(outputContent `Removing ${identifier} from the secure store...`);
43
43
  try {
44
44
  const keytar = await import('keytar');
@@ -56,7 +56,7 @@ function createAbort(error, message) {
56
56
  newMessage = message.concat(`: ${error.message}`);
57
57
  stack = error.stack;
58
58
  }
59
- const abort = new Abort(newMessage);
59
+ const abort = new AbortError(newMessage);
60
60
  abort.stack = stack;
61
61
  return abort;
62
62
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-store.js","sourceRoot":"","sources":["../../../src/private/node/secure-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAC,OAAO,IAAI,aAAa,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAA;AAE/D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,UAAkB;IACvD,KAAK,CAAC,aAAa,CAAA,WAAW,UAAU,2BAA2B,CAAC,CAAA;IACpE,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QAC/E,OAAO,OAAO,CAAA;KACf;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,CAAC,KAAK,EAAE,sCAAsC,CAAC,CAAA;KACjE;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAAkB,EAAE,OAAe;IACvE,KAAK,CAAC,aAAa,CAAA,YAAY,UAAU,0CAA0C,CAAC,CAAA;IACpF,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;KACjF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,CAAC,KAAK,EAAE,mCAAmC,CAAC,CAAA;KAC9D;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAkB;IACxD,KAAK,CAAC,aAAa,CAAA,YAAY,UAAU,2BAA2B,CAAC,CAAA;IACrE,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QACzF,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,CAAC,KAAK,EAAE,wCAAwC,CAAC,CAAA;KACnE;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,OAAe;IAClD,IAAI,UAAU,GAAG,OAAO,CAAA;IACxB,IAAI,KAAK,GAAuB,EAAE,CAAA;IAClC,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;QACjD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;KACpB;IACD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAA;IACxC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAA;IACnB,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {keychainConstants} from './constants.js'\nimport {AbortError} from '../../public/node/error.js'\nimport {content as outputContent, debug} from '../../output.js'\n\n/**\n * Fetches secured content from the system's keychain.\n * @param identifier - Identifier to identify the content.\n * @returns A promise that resolves with the content or null if it doesn't exist.\n */\nexport async function secureStoreFetch(identifier: string): Promise<string | null> {\n debug(outputContent`Reading ${identifier} from the secure store...`)\n try {\n const keytar = await import('keytar')\n const content = await keytar.getPassword(keychainConstants.service, identifier)\n return content\n } catch (error) {\n throw createAbort(error, 'Unable to read from the secure store')\n }\n}\n\n/**\n * Securely stores the content under the given key.\n * @param identifier - Identifier to identify the content.\n * @param content - The content to be stored.\n * @returns A promise that resolves when the storing completes.\n */\nexport async function secureStoreSave(identifier: string, content: string): Promise<void> {\n debug(outputContent`Updating ${identifier} in the secure store with new content...`)\n try {\n const keytar = await import('keytar')\n await keytar.default.setPassword(keychainConstants.service, identifier, content)\n } catch (error) {\n throw createAbort(error, 'Unable to update the secure store')\n }\n}\n\n/**\n * Removes the content with the given identifier.\n * @param identifier - Identifier to identify the content.\n * @returns A promise that resolves with true if the content was deleted.\n */\nexport async function secureStoreRemove(identifier: string): Promise<boolean> {\n debug(outputContent`Removing ${identifier} from the secure store...`)\n try {\n const keytar = await import('keytar')\n const result = await keytar.default.deletePassword(keychainConstants.service, identifier)\n return result\n } catch (error) {\n throw createAbort(error, 'Unable to remove from the secure store')\n }\n}\n\nfunction createAbort(error: unknown, message: string) {\n let newMessage = message\n let stack: string | undefined = ''\n if (error instanceof Error) {\n newMessage = message.concat(`: ${error.message}`)\n stack = error.stack\n }\n const abort = new AbortError(newMessage)\n abort.stack = stack\n return abort\n}\n"]}
@@ -1,5 +1,3 @@
1
- import { Abort } from '../../../error.js';
2
- export declare const MismatchStateError: Abort;
3
1
  export interface CodeAuthResult {
4
2
  code: string;
5
3
  codeVerifier: string;
@@ -2,12 +2,11 @@ import { clientId } from './identity.js';
2
2
  import { listenRedirect } from './redirect-listener.js';
3
3
  import { base64URLEncode, randomBytes, randomHex, sha256 } from '../../../public/node/crypto.js';
4
4
  import { openURL } from '../../../public/node/system.js';
5
- import { Abort, CancelExecution } from '../../../error.js';
5
+ import { AbortError, CancelExecution } from '../../../public/node/error.js';
6
6
  import { identityFqdn } from '../../../public/node/environment/fqdn.js';
7
7
  import * as output from '../../../output.js';
8
8
  import { keypress, terminateBlockingPortProcessPrompt } from '../../../ui.js';
9
9
  import { checkPort as isPortAvailable } from 'get-port-please';
10
- export const MismatchStateError = new Abort("The state received from the authentication doesn't match the one that initiated the authentication process.");
11
10
  export async function authorize(scopes, state = randomHex(30)) {
12
11
  const port = 3456;
13
12
  const host = '127.0.0.1';
@@ -33,7 +32,7 @@ export async function authorize(scopes, state = randomHex(30)) {
33
32
  await openURL(url);
34
33
  const result = await listenRedirect(host, port, url);
35
34
  if (result.state !== state) {
36
- throw MismatchStateError;
35
+ throw new AbortError("The state received from the authentication doesn't match the one that initiated the authentication process.");
37
36
  }
38
37
  return { code: result.code, codeVerifier };
39
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../../src/private/node/session/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAC,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,gCAAgC,CAAA;AAC9F,OAAO,EAAC,OAAO,EAAC,MAAM,gCAAgC,CAAA;AACtD,OAAO,EAAC,KAAK,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAC,QAAQ,EAAE,kCAAkC,EAAC,MAAM,gBAAgB,CAAA;AAC3E,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAE5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,KAAK,CACzC,6GAA6G,CAC9G,CAAA;AAOD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAgB,EAAE,QAAgB,SAAS,CAAC,EAAE,CAAC;IAC7E,MAAM,IAAI,GAAG,IAAI,CAAA;IACjB,MAA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AM,CAAC,YAAY,CAAC,CAAC,CAAA;IAC3D,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,CAAA;AACtC,CAAC;AAED,KAAK,UAAU,mCAAmC,CAAC,IAAY;IAC7D,MAAM,EAAC,eAAe,EAAC,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAA;IAE3D,IAAI,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE;QAC/B,OAAM;KACP;IAED,IAAI,MAAM,kCAAkC,CAAC,IAAI,EAAE,gBAAgB,CAAC,EAAE;QACpE,MAAM,eAAe,CAAC,IAAI,CAAC,CAAA;KAC5B;SAAM;QACL,MAAM,IAAI,eAAe,EAAE,CAAA;KAC5B;AACH,CAAC","sourcesContent":["import {clientId} from './identity.js'\nimport {listenRedirect} from './redirect-listener.js'\nimport {base64URLEncode, randomBytes, randomHex, sha256} from '../../../public/node/crypto.js'\nimport {openURL} from '../../../public/node/system.js'\nimport {Abort, CancelExecution} from '../../../error.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport * as output from '../../../output.js'\nimport {keypress, terminateBlockingPortProcessPrompt} from '../../../ui.js'\nimport {checkPort as isPortAvailable} from 'get-port-please'\n\nexport const MismatchStateError = new Abort(\n \"The state received from the authentication doesn't match the one that initiated the authentication process.\",\n)\n\nexport interface CodeAuthResult {\n code: string\n codeVerifier: string\n}\n\nexport async function authorize(scopes: string[], state: string = randomHex(30)): Promise<CodeAuthResult> {\n const port = 3456\n const host = '127.0.0.1'\n const redirectUri = `http://${host}:${port}`\n const fqdn = await identityFqdn()\n const identityClientId = clientId()\n\n await validateRedirectionPortAvailability(port)\n\n let url = `http://${fqdn}/oauth/authorize`\n\n const {codeVerifier, codeChallenge} = generateRandomChallengePair()\n\n const params = {\n client_id: identityClientId,\n scope: scopes.join(' '),\n redirect_uri: redirectUri,\n state,\n response_type: 'code',\n code_challenge_method: 'S256',\n code_challenge: codeChallenge,\n }\n\n output.info('\\nTo run this command, log in to Shopify Partners.')\n output.info('👉 Press any key to open the login page on your browser')\n await keypress()\n\n url = `${url}?${new URLSearchParams(params).toString()}`\n await openURL(url)\n\n const result = await listenRedirect(host, port, url)\n\n if (result.state !== state) {\n throw MismatchStateError\n }\n\n return {code: result.code, codeVerifier}\n}\n\nfunction generateRandomChallengePair() {\n const codeVerifier = base64URLEncode(randomBytes(32))\n const codeChallenge = base64URLEncode(sha256(codeVerifier))\n return {codeVerifier, codeChallenge}\n}\n\nasync function validateRedirectionPortAvailability(port: number) {\n const {killPortProcess} = await import('kill-port-process')\n\n if (await isPortAvailable(port)) {\n return\n }\n\n if (await terminateBlockingPortProcessPrompt(port, 'Authentication')) {\n await killPortProcess(port)\n } else {\n throw new CancelExecution()\n }\n}\n"]}
1
+ {"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../../src/private/node/session/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAC,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,gCAAgC,CAAA;AAC9F,OAAO,EAAC,OAAO,EAAC,MAAM,gCAAgC,CAAA;AACtD,OAAO,EAAC,UAAU,EAAE,eAAe,EAAC,MAAM,+BAA+B,CAAA;AACzE,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAC,QAAQ,EAAE,kCAAkC,EAAC,MAAM,gBAAgB,CAAA;AAC3E,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAO5D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAgB,EAAE,QAAgB,SAAS,CAAC,EAAE,CAAC;IAC7E,MAAM,IAAI,GAAG,IAAI,CAAA;IACjB,MAAM,IAAI,GAAG,WAAW,CAAA;IACxB,M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YAAY,CAAC,CAAC,CAAA;IAC3D,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,CAAA;AACtC,CAAC;AAED,KAAK,UAAU,mCAAmC,CAAC,IAAY;IAC7D,MAAM,EAAC,eAAe,EAAC,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAA;IAE3D,IAAI,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE;QAC/B,OAAM;KACP;IAED,IAAI,MAAM,kCAAkC,CAAC,IAAI,EAAE,gBAAgB,CAAC,EAAE;QACpE,MAAM,eAAe,CAAC,IAAI,CAAC,CAAA;KAC5B;SAAM;QACL,MAAM,IAAI,eAAe,EAAE,CAAA;KAC5B;AACH,CAAC","sourcesContent":["import {clientId} from './identity.js'\nimport {listenRedirect} from './redirect-listener.js'\nimport {base64URLEncode, randomBytes, randomHex, sha256} from '../../../public/node/crypto.js'\nimport {openURL} from '../../../public/node/system.js'\nimport {AbortError, CancelExecution} from '../../../public/node/error.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport * as output from '../../../output.js'\nimport {keypress, terminateBlockingPortProcessPrompt} from '../../../ui.js'\nimport {checkPort as isPortAvailable} from 'get-port-please'\n\nexport interface CodeAuthResult {\n code: string\n codeVerifier: string\n}\n\nexport async function authorize(scopes: string[], state: string = randomHex(30)): Promise<CodeAuthResult> {\n const port = 3456\n const host = '127.0.0.1'\n const redirectUri = `http://${host}:${port}`\n const fqdn = await identityFqdn()\n const identityClientId = clientId()\n\n await validateRedirectionPortAvailability(port)\n\n let url = `http://${fqdn}/oauth/authorize`\n\n const {codeVerifier, codeChallenge} = generateRandomChallengePair()\n\n const params = {\n client_id: identityClientId,\n scope: scopes.join(' '),\n redirect_uri: redirectUri,\n state,\n response_type: 'code',\n code_challenge_method: 'S256',\n code_challenge: codeChallenge,\n }\n\n output.info('\\nTo run this command, log in to Shopify Partners.')\n output.info('👉 Press any key to open the login page on your browser')\n await keypress()\n\n url = `${url}?${new URLSearchParams(params).toString()}`\n await openURL(url)\n\n const result = await listenRedirect(host, port, url)\n\n if (result.state !== state) {\n throw new AbortError(\n \"The state received from the authentication doesn't match the one that initiated the authentication process.\",\n )\n }\n\n return {code: result.code, codeVerifier}\n}\n\nfunction generateRandomChallengePair() {\n const codeVerifier = base64URLEncode(randomBytes(32))\n const codeChallenge = base64URLEncode(sha256(codeVerifier))\n return {codeVerifier, codeChallenge}\n}\n\nasync function validateRedirectionPortAvailability(port: number) {\n const {killPortProcess} = await import('kill-port-process')\n\n if (await isPortAvailable(port)) {\n return\n }\n\n if (await terminateBlockingPortProcessPrompt(port, 'Authentication')) {\n await killPortProcess(port)\n } else {\n throw new CancelExecution()\n }\n}\n"]}
@@ -3,7 +3,7 @@ import { exchangeDeviceCodeForAccessToken } from './exchange.js';
3
3
  import { identityFqdn } from '../../../public/node/environment/fqdn.js';
4
4
  import { shopifyFetch } from '../../../public/node/http.js';
5
5
  import { content, debug, info, token } from '../../../output.js';
6
- import { Bug } from '../../../error.js';
6
+ import { BugError } from '../../../public/node/error.js';
7
7
  /**
8
8
  * Initiate a device authorization flow.
9
9
  * This will return a DeviceAuthorizationResponse containing the URL where user
@@ -28,7 +28,7 @@ export async function requestDeviceAuthorization(scopes) {
28
28
  const jsonResult = await response.json();
29
29
  debug(content `Received device authorization code: ${token.json(jsonResult)}`);
30
30
  if (!jsonResult.device_code || !jsonResult.verification_uri_complete) {
31
- throw new Bug('Failed to start authorization process');
31
+ throw new BugError('Failed to start authorization process');
32
32
  }
33
33
  info('\nTo run this command, log in to Shopify Partners.');
34
34
  info(content `User verification code: ${jsonResult.user_code}`);
@@ -1 +1 @@
1
- {"version":3,"file":"device-authorization.js","sourceRoot":"","sources":["../../../../src/private/node/session/device-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,gCAAgC,EAAC,MAAM,eAAe,CAAA;AAE9D,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C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C,CAAA;QACrD,CAAC,CAAA;QAED,YAAY,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,WAA+C;IAC7E,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;SAC/B,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;SACjD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SACvC,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC","sourcesContent":["import {clientId} from './identity.js'\nimport {exchangeDeviceCodeForAccessToken} from './exchange.js'\nimport {IdentityToken} from './schema.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {shopifyFetch} from '../../../public/node/http.js'\nimport {content, debug, info, token} from '../../../output.js'\nimport {Bug} from '../../../error.js'\n\nexport interface DeviceAuthorizationResponse {\n deviceCode: string\n userCode: string\n verificationUri: string\n expiresIn: number\n verificationUriComplete?: string\n interval?: number\n}\n\n/**\n * Initiate a device authorization flow.\n * This will return a DeviceAuthorizationResponse containing the URL where user\n * should go to authorize the device without the need of a callback to the CLI.\n *\n * Also returns a `deviceCode` used for polling the token endpoint in the next step.\n *\n * @param scopes - The scopes to request\n * @returns An object with the device authorization response.\n */\nexport async function requestDeviceAuthorization(scopes: string[]): Promise<DeviceAuthorizationResponse> {\n const fqdn = await identityFqdn()\n const identityClientId = await clientId()\n const queryParams = {client_id: identityClientId, scope: scopes.join(' ')}\n const url = `https://${fqdn}/oauth/device_authorization`\n\n const response = await shopifyFetch(url, {\n method: 'POST',\n headers: {'Content-type': 'application/x-www-form-urlencoded'},\n body: convertRequestToParams(queryParams),\n })\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const jsonResult: any = await response.json()\n\n debug(content`Received device authorization code: ${token.json(jsonResult)}`)\n if (!jsonResult.device_code || !jsonResult.verification_uri_complete) {\n throw new Bug('Failed to start authorization process')\n }\n\n info('\\nTo run this command, log in to Shopify Partners.')\n info(content`User verification code: ${jsonResult.user_code}`)\n info(content`👉 Open this link to start the auth process: ${token.green(jsonResult.verification_uri_complete)}`)\n\n return {\n deviceCode: jsonResult.device_code,\n userCode: jsonResult.user_code,\n verificationUri: jsonResult.verification_uri,\n expiresIn: jsonResult.expires_in,\n verificationUriComplete: jsonResult.verification_uri_complete,\n interval: jsonResult.interval,\n }\n}\n\n/**\n * Poll the Oauth token endpoint with the device code obtained from a DeviceAuthorizationResponse.\n * The endpoint will return `authorization_pending` until the user completes the auth flow in the browser.\n * Once the user completes the auth flow, the endpoint will return the identity token.\n *\n * Timeout for the polling is defined by the server and is around 600 seconds.\n *\n * @param code - The device code obtained after starting a device identity flow\n * @param interval - The interval to poll the token endpoint\n * @returns The identity token\n */\nexport async function pollForDeviceAuthorization(code: string, interval = 5): Promise<IdentityToken> {\n let currentIntervalInSeconds = interval\n\n return new Promise<IdentityToken>((resolve, reject) => {\n const onPoll = async () => {\n const result = await exchangeDeviceCodeForAccessToken(code)\n if (!result.isErr()) return resolve(result.value)\n\n const error = result.error ?? 'unknown_failure'\n\n debug(content`Polling for device authorization... status: ${error}`)\n switch (error) {\n case 'authorization_pending':\n return startPolling()\n case 'slow_down':\n currentIntervalInSeconds += 5\n return startPolling()\n case 'access_denied':\n case 'expired_token':\n case 'unknown_failure':\n return reject(result)\n }\n }\n\n const startPolling = () => {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n setTimeout(onPoll, currentIntervalInSeconds * 1000)\n }\n\n startPolling()\n })\n}\n\nfunction convertRequestToParams(queryParams: {client_id: string; scope: string}): string {\n return Object.entries(queryParams)\n .map(([key, value]) => value && `${key}=${value}`)\n .filter((hasValue) => Boolean(hasValue))\n .join('&')\n}\n"]}
1
+ {"version":3,"file":"device-authorization.js","sourceRoot":"","sources":["../../../../src/private/node/session/device-authorization.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B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;aACxB;QACH,CAAC,CAAA;QAED,MAAM,YAAY,GAAG,GAAG,EAAE;YACxB,kEAAkE;YAClE,UAAU,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAAC,CAAA;QACrD,CAAC,CAAA;QAED,YAAY,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,WAA+C;IAC7E,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;SAC/B,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;SACjD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SACvC,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC","sourcesContent":["import {clientId} from './identity.js'\nimport {exchangeDeviceCodeForAccessToken} from './exchange.js'\nimport {IdentityToken} from './schema.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {shopifyFetch} from '../../../public/node/http.js'\nimport {content, debug, info, token} from '../../../output.js'\nimport {BugError} from '../../../public/node/error.js'\n\nexport interface DeviceAuthorizationResponse {\n deviceCode: string\n userCode: string\n verificationUri: string\n expiresIn: number\n verificationUriComplete?: string\n interval?: number\n}\n\n/**\n * Initiate a device authorization flow.\n * This will return a DeviceAuthorizationResponse containing the URL where user\n * should go to authorize the device without the need of a callback to the CLI.\n *\n * Also returns a `deviceCode` used for polling the token endpoint in the next step.\n *\n * @param scopes - The scopes to request\n * @returns An object with the device authorization response.\n */\nexport async function requestDeviceAuthorization(scopes: string[]): Promise<DeviceAuthorizationResponse> {\n const fqdn = await identityFqdn()\n const identityClientId = await clientId()\n const queryParams = {client_id: identityClientId, scope: scopes.join(' ')}\n const url = `https://${fqdn}/oauth/device_authorization`\n\n const response = await shopifyFetch(url, {\n method: 'POST',\n headers: {'Content-type': 'application/x-www-form-urlencoded'},\n body: convertRequestToParams(queryParams),\n })\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const jsonResult: any = await response.json()\n\n debug(content`Received device authorization code: ${token.json(jsonResult)}`)\n if (!jsonResult.device_code || !jsonResult.verification_uri_complete) {\n throw new BugError('Failed to start authorization process')\n }\n\n info('\\nTo run this command, log in to Shopify Partners.')\n info(content`User verification code: ${jsonResult.user_code}`)\n info(content`👉 Open this link to start the auth process: ${token.green(jsonResult.verification_uri_complete)}`)\n\n return {\n deviceCode: jsonResult.device_code,\n userCode: jsonResult.user_code,\n verificationUri: jsonResult.verification_uri,\n expiresIn: jsonResult.expires_in,\n verificationUriComplete: jsonResult.verification_uri_complete,\n interval: jsonResult.interval,\n }\n}\n\n/**\n * Poll the Oauth token endpoint with the device code obtained from a DeviceAuthorizationResponse.\n * The endpoint will return `authorization_pending` until the user completes the auth flow in the browser.\n * Once the user completes the auth flow, the endpoint will return the identity token.\n *\n * Timeout for the polling is defined by the server and is around 600 seconds.\n *\n * @param code - The device code obtained after starting a device identity flow\n * @param interval - The interval to poll the token endpoint\n * @returns The identity token\n */\nexport async function pollForDeviceAuthorization(code: string, interval = 5): Promise<IdentityToken> {\n let currentIntervalInSeconds = interval\n\n return new Promise<IdentityToken>((resolve, reject) => {\n const onPoll = async () => {\n const result = await exchangeDeviceCodeForAccessToken(code)\n if (!result.isErr()) return resolve(result.value)\n\n const error = result.error ?? 'unknown_failure'\n\n debug(content`Polling for device authorization... status: ${error}`)\n switch (error) {\n case 'authorization_pending':\n return startPolling()\n case 'slow_down':\n currentIntervalInSeconds += 5\n return startPolling()\n case 'access_denied':\n case 'expired_token':\n case 'unknown_failure':\n return reject(result)\n }\n }\n\n const startPolling = () => {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n setTimeout(onPoll, currentIntervalInSeconds * 1000)\n }\n\n startPolling()\n })\n}\n\nfunction convertRequestToParams(queryParams: {client_id: string; scope: string}): string {\n return Object.entries(queryParams)\n .map(([key, value]) => value && `${key}=${value}`)\n .filter((hasValue) => Boolean(hasValue))\n .join('&')\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { ApplicationToken, IdentityToken } from './schema.js';
2
2
  import { CodeAuthResult } from './authorize.js';
3
3
  import { Result } from '../../../public/node/result.js';
4
- import { ExtendableError } from '../../../error.js';
4
+ import { ExtendableError } from '../../../public/node/error.js';
5
5
  export declare class InvalidGrantError extends ExtendableError {
6
6
  }
7
7
  export declare class InvalidRequestError extends ExtendableError {
@@ -2,8 +2,7 @@ import { applicationId, clientId as getIdentityClientId } from './identity.js';
2
2
  import { identityFqdn } from '../../../public/node/environment/fqdn.js';
3
3
  import { shopifyFetch } from '../../../public/node/http.js';
4
4
  import { err, ok } from '../../../public/node/result.js';
5
- import { AbortError } from '../../../public/node/error.js';
6
- import { ExtendableError } from '../../../error.js';
5
+ import { AbortError, ExtendableError } from '../../../public/node/error.js';
7
6
  export class InvalidGrantError extends ExtendableError {
8
7
  }
9
8
  export class InvalidRequestError extends ExtendableError {