@shopify/cli-kit 3.0.25 → 3.0.26

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 (286) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/assets/auth-error.html +2 -4
  3. package/assets/empty-url.html +2 -4
  4. package/assets/missing-code.html +2 -4
  5. package/assets/missing-state.html +2 -4
  6. package/assets/style.css +5 -8
  7. package/assets/success.html +1 -1
  8. package/dist/abort.d.ts +1 -0
  9. package/dist/abort.js +2 -0
  10. package/dist/abort.js.map +1 -0
  11. package/dist/analytics.d.ts +11 -0
  12. package/dist/analytics.js +96 -0
  13. package/dist/analytics.js.map +1 -0
  14. package/dist/api/admin.d.ts +3 -0
  15. package/dist/api/admin.js +80 -0
  16. package/dist/api/admin.js.map +1 -0
  17. package/dist/api/common.d.ts +11 -0
  18. package/dist/api/common.js +40 -0
  19. package/dist/api/common.js.map +1 -0
  20. package/dist/api/graphql/all_app_extension_registrations.d.ts +14 -0
  21. package/dist/api/graphql/all_app_extension_registrations.js +14 -0
  22. package/dist/api/graphql/all_app_extension_registrations.js.map +1 -0
  23. package/dist/api/graphql/all_orgs.d.ts +12 -0
  24. package/dist/api/graphql/all_orgs.js +14 -0
  25. package/dist/api/graphql/all_orgs.js.map +1 -0
  26. package/dist/api/graphql/all_stores_by_org.d.ts +18 -0
  27. package/dist/api/graphql/all_stores_by_org.js +21 -0
  28. package/dist/api/graphql/all_stores_by_org.js.map +1 -0
  29. package/dist/api/graphql/convert_dev_to_test_store.d.ts +16 -0
  30. package/dist/api/graphql/convert_dev_to_test_store.js +13 -0
  31. package/dist/api/graphql/convert_dev_to_test_store.js.map +1 -0
  32. package/dist/api/graphql/create_app.d.ts +28 -0
  33. package/dist/api/graphql/create_app.js +32 -0
  34. package/dist/api/graphql/create_app.js.map +1 -0
  35. package/dist/api/graphql/create_deployment.d.ts +33 -0
  36. package/dist/api/graphql/create_deployment.js +25 -0
  37. package/dist/api/graphql/create_deployment.js.map +1 -0
  38. package/dist/api/graphql/extension_create.d.ts +30 -0
  39. package/dist/api/graphql/extension_create.js +26 -0
  40. package/dist/api/graphql/extension_create.js.map +1 -0
  41. package/dist/api/graphql/extension_specifications.d.ts +18 -0
  42. package/dist/api/graphql/extension_specifications.js +18 -0
  43. package/dist/api/graphql/extension_specifications.js.map +1 -0
  44. package/dist/api/graphql/find_app.d.ts +13 -0
  45. package/dist/api/graphql/find_app.js +16 -0
  46. package/dist/api/graphql/find_app.js.map +1 -0
  47. package/dist/api/graphql/find_org.d.ts +23 -0
  48. package/dist/api/graphql/find_org.js +26 -0
  49. package/dist/api/graphql/find_org.js.map +1 -0
  50. package/dist/api/graphql/find_org_basic.d.ts +11 -0
  51. package/dist/api/graphql/find_org_basic.js +14 -0
  52. package/dist/api/graphql/find_org_basic.js.map +1 -0
  53. package/dist/api/graphql/functions/app_function_set.d.ts +43 -0
  54. package/dist/api/graphql/functions/app_function_set.js +52 -0
  55. package/dist/api/graphql/functions/app_function_set.js.map +1 -0
  56. package/dist/api/graphql/functions/compile_module.d.ts +15 -0
  57. package/dist/api/graphql/functions/compile_module.js +13 -0
  58. package/dist/api/graphql/functions/compile_module.js.map +1 -0
  59. package/dist/api/graphql/functions/function_service_proxy.d.ts +4 -0
  60. package/dist/api/graphql/functions/function_service_proxy.js +7 -0
  61. package/dist/api/graphql/functions/function_service_proxy.js.map +1 -0
  62. package/dist/api/graphql/functions/get_app_functions.d.ts +1 -0
  63. package/dist/api/graphql/functions/get_app_functions.js +10 -0
  64. package/dist/api/graphql/functions/get_app_functions.js.map +1 -0
  65. package/dist/api/graphql/functions/module_compilation_status.d.ts +15 -0
  66. package/dist/api/graphql/functions/module_compilation_status.js +13 -0
  67. package/dist/api/graphql/functions/module_compilation_status.js.map +1 -0
  68. package/dist/api/graphql/functions/module_upload_url_generate.d.ts +18 -0
  69. package/dist/api/graphql/functions/module_upload_url_generate.js +17 -0
  70. package/dist/api/graphql/functions/module_upload_url_generate.js.map +1 -0
  71. package/dist/api/graphql/generate_signed_upload_url.d.ts +15 -0
  72. package/dist/api/graphql/generate_signed_upload_url.js +15 -0
  73. package/dist/api/graphql/generate_signed_upload_url.js.map +1 -0
  74. package/dist/api/graphql/get_variant_id.d.ts +17 -0
  75. package/dist/api/graphql/get_variant_id.js +20 -0
  76. package/dist/api/graphql/get_variant_id.js.map +1 -0
  77. package/dist/api/graphql/index.d.ts +21 -0
  78. package/dist/api/graphql/index.js +22 -0
  79. package/dist/api/graphql/index.js.map +1 -0
  80. package/dist/api/graphql/update_draft.d.ts +33 -0
  81. package/dist/api/graphql/update_draft.js +24 -0
  82. package/dist/api/graphql/update_draft.js.map +1 -0
  83. package/dist/api/graphql/update_urls.d.ts +14 -0
  84. package/dist/api/graphql/update_urls.js +12 -0
  85. package/dist/api/graphql/update_urls.js.map +1 -0
  86. package/dist/api/identity.d.ts +1 -0
  87. package/dist/api/identity.js +29 -0
  88. package/dist/api/identity.js.map +1 -0
  89. package/dist/api/partners.d.ts +25 -0
  90. package/dist/api/partners.js +100 -0
  91. package/dist/api/partners.js.map +1 -0
  92. package/dist/api.d.ts +5 -0
  93. package/dist/api.js +6 -0
  94. package/dist/api.js.map +1 -0
  95. package/dist/checksum.d.ts +15 -0
  96. package/dist/checksum.js +27 -0
  97. package/dist/checksum.js.map +1 -0
  98. package/dist/cli.d.ts +7 -0
  99. package/dist/cli.js +13 -0
  100. package/dist/cli.js.map +1 -0
  101. package/dist/colors.d.ts +1 -0
  102. package/dist/colors.js +8 -0
  103. package/dist/colors.js.map +1 -0
  104. package/dist/constants.d.ts +43 -0
  105. package/dist/constants.js +63 -0
  106. package/dist/constants.js.map +1 -0
  107. package/dist/dependency.d.ts +128 -0
  108. package/dist/dependency.js +302 -0
  109. package/dist/dependency.js.map +1 -0
  110. package/dist/dot-env.d.ts +28 -0
  111. package/dist/dot-env.js +31 -0
  112. package/dist/dot-env.js.map +1 -0
  113. package/dist/environment/fqdn.d.ts +23 -0
  114. package/dist/environment/fqdn.js +61 -0
  115. package/dist/environment/fqdn.js.map +1 -0
  116. package/dist/environment/local.d.ts +48 -0
  117. package/dist/environment/local.js +82 -0
  118. package/dist/environment/local.js.map +1 -0
  119. package/dist/environment/service.d.ts +17 -0
  120. package/dist/environment/service.js +41 -0
  121. package/dist/environment/service.js.map +1 -0
  122. package/dist/environment/spin.d.ts +47 -0
  123. package/dist/environment/spin.js +83 -0
  124. package/dist/environment/spin.js.map +1 -0
  125. package/dist/environment/utilities.d.ts +6 -0
  126. package/dist/environment/utilities.js +12 -0
  127. package/dist/environment/utilities.js.map +1 -0
  128. package/dist/environment.d.ts +5 -0
  129. package/dist/environment.js +6 -0
  130. package/dist/environment.js.map +1 -0
  131. package/dist/error.d.ts +44 -0
  132. package/dist/error.js +91 -0
  133. package/dist/error.js.map +1 -0
  134. package/dist/file.d.ts +67 -0
  135. package/dist/file.js +165 -0
  136. package/dist/file.js.map +1 -0
  137. package/dist/git.d.ts +15 -0
  138. package/dist/git.js +48 -0
  139. package/dist/git.js.map +1 -0
  140. package/dist/github.d.ts +33 -0
  141. package/dist/github.js +56 -0
  142. package/dist/github.js.map +1 -0
  143. package/dist/haiku.d.ts +1 -0
  144. package/dist/haiku.js +8 -0
  145. package/dist/haiku.js.map +1 -0
  146. package/dist/http/fetch.d.ts +16 -0
  147. package/dist/http/fetch.js +18 -0
  148. package/dist/http/fetch.js.map +1 -0
  149. package/dist/http/formdata.d.ts +3 -0
  150. package/dist/http/formdata.js +6 -0
  151. package/dist/http/formdata.js.map +1 -0
  152. package/dist/http.d.ts +2 -0
  153. package/dist/http.js +3 -0
  154. package/dist/http.js.map +1 -0
  155. package/dist/id.d.ts +6 -0
  156. package/dist/id.js +18 -0
  157. package/dist/id.js.map +1 -0
  158. package/dist/index.d.ts +37 -2179
  159. package/dist/index.js +38 -3264
  160. package/dist/index.js.map +1 -1
  161. package/dist/network/api.d.ts +2 -0
  162. package/dist/network/api.js +2 -0
  163. package/dist/network/api.js.map +1 -0
  164. package/dist/network/service.d.ts +16 -0
  165. package/dist/network/service.js +12 -0
  166. package/dist/network/service.js.map +1 -0
  167. package/dist/{archiver.d.ts → node/archiver.d.ts} +1 -4
  168. package/dist/node/archiver.js +22 -42
  169. package/dist/node/archiver.js.map +1 -1
  170. package/dist/node/cli.d.ts +18 -0
  171. package/dist/node/cli.js +91 -0
  172. package/dist/node/cli.js.map +1 -0
  173. package/dist/npm.d.ts +27 -0
  174. package/dist/npm.js +20 -0
  175. package/dist/npm.js.map +1 -0
  176. package/dist/os.d.ts +10 -0
  177. package/dist/os.js +70 -0
  178. package/dist/os.js.map +1 -0
  179. package/dist/output.d.ts +142 -0
  180. package/dist/output.js +505 -0
  181. package/dist/output.js.map +1 -0
  182. package/dist/path.d.ts +22 -0
  183. package/dist/path.js +43 -0
  184. package/dist/path.js.map +1 -0
  185. package/dist/plugins.d.ts +9 -0
  186. package/dist/plugins.js +12 -0
  187. package/dist/plugins.js.map +1 -0
  188. package/dist/port.d.ts +5 -0
  189. package/dist/port.js +13 -0
  190. package/dist/port.js.map +1 -0
  191. package/dist/ruby.d.ts +21 -0
  192. package/dist/ruby.js +192 -0
  193. package/dist/ruby.js.map +1 -0
  194. package/dist/schema.d.ts +1 -0
  195. package/dist/schema.js +2 -0
  196. package/dist/schema.js.map +1 -0
  197. package/dist/secure-store.d.ts +19 -0
  198. package/dist/secure-store.js +63 -0
  199. package/dist/secure-store.js.map +1 -0
  200. package/dist/semver.d.ts +3 -0
  201. package/dist/semver.js +6 -0
  202. package/dist/semver.js.map +1 -0
  203. package/dist/session/authorize.d.ts +7 -0
  204. package/dist/session/authorize.js +40 -0
  205. package/dist/session/authorize.js.map +1 -0
  206. package/dist/session/exchange.d.ts +42 -0
  207. package/dist/session/exchange.js +144 -0
  208. package/dist/session/exchange.js.map +1 -0
  209. package/dist/session/identity.d.ts +3 -0
  210. package/dist/session/identity.js +58 -0
  211. package/dist/session/identity.js.map +1 -0
  212. package/dist/session/post-auth.d.ts +13 -0
  213. package/dist/session/post-auth.js +56 -0
  214. package/dist/session/post-auth.js.map +1 -0
  215. package/dist/session/redirect-listener.d.ts +34 -0
  216. package/dist/session/redirect-listener.js +97 -0
  217. package/dist/session/redirect-listener.js.map +1 -0
  218. package/dist/session/schema.d.ts +174 -0
  219. package/dist/session/schema.js +59 -0
  220. package/dist/session/schema.js.map +1 -0
  221. package/dist/session/scopes.d.ts +16 -0
  222. package/dist/session/scopes.js +53 -0
  223. package/dist/session/scopes.js.map +1 -0
  224. package/dist/session/store.d.ts +24 -0
  225. package/dist/session/store.js +88 -0
  226. package/dist/session/store.js.map +1 -0
  227. package/dist/session/token.d.ts +40 -0
  228. package/dist/session/token.js +22 -0
  229. package/dist/session/token.js.map +1 -0
  230. package/dist/session/validate.d.ts +17 -0
  231. package/dist/session/validate.js +75 -0
  232. package/dist/session/validate.js.map +1 -0
  233. package/dist/session.d.ts +88 -0
  234. package/dist/session.js +251 -0
  235. package/dist/session.js.map +1 -0
  236. package/dist/store/schema.d.ts +3 -0
  237. package/dist/store/schema.js +27 -0
  238. package/dist/store/schema.js.map +1 -0
  239. package/dist/store.d.ts +32 -0
  240. package/dist/store.js +102 -0
  241. package/dist/store.js.map +1 -0
  242. package/dist/string.d.ts +22 -0
  243. package/dist/string.js +38 -0
  244. package/dist/string.js.map +1 -0
  245. package/dist/system.d.ts +53 -0
  246. package/dist/system.js +109 -0
  247. package/dist/system.js.map +1 -0
  248. package/dist/template.d.ts +11 -0
  249. package/dist/template.js +50 -0
  250. package/dist/template.js.map +1 -0
  251. package/dist/testing/output.d.ts +9 -0
  252. package/dist/testing/output.js +15 -0
  253. package/dist/testing/output.js.map +1 -0
  254. package/dist/testing/store.d.ts +7 -0
  255. package/dist/testing/store.js +26 -0
  256. package/dist/testing/store.js.map +1 -0
  257. package/dist/toml.d.ts +3 -0
  258. package/dist/toml.js +8 -0
  259. package/dist/toml.js.map +1 -0
  260. package/dist/tsconfig.tsbuildinfo +1 -0
  261. package/dist/ui/autocomplete.d.ts +7 -0
  262. package/dist/ui/autocomplete.js +43 -0
  263. package/dist/ui/autocomplete.js.map +1 -0
  264. package/dist/ui/input.d.ts +7 -0
  265. package/dist/ui/input.js +48 -0
  266. package/dist/ui/input.js.map +1 -0
  267. package/dist/ui/select.d.ts +6 -0
  268. package/dist/ui/select.js +30 -0
  269. package/dist/ui/select.js.map +1 -0
  270. package/dist/ui.d.ts +36 -0
  271. package/dist/ui.js +124 -0
  272. package/dist/ui.js.map +1 -0
  273. package/dist/version.d.ts +19 -0
  274. package/dist/version.js +34 -0
  275. package/dist/version.js.map +1 -0
  276. package/dist/vscode.d.ts +8 -0
  277. package/dist/vscode.js +36 -0
  278. package/dist/vscode.js.map +1 -0
  279. package/dist/yaml.d.ts +2 -0
  280. package/dist/yaml.js +8 -0
  281. package/dist/yaml.js.map +1 -0
  282. package/package.json +14 -7
  283. package/dist/archiver.d.ts.map +0 -1
  284. package/dist/index.d.ts.map +0 -1
  285. package/dist/local-d0094ffe.js +0 -1344
  286. package/dist/local-d0094ffe.js.map +0 -1
@@ -0,0 +1,12 @@
1
+ import { join, pathToFileURL } from './path.js';
2
+ import { debug, content } from './output.js';
3
+ const TUNNEL_PLUGINS = ['@shopify/plugin-ngrok'];
4
+ export async function lookupTunnelPlugin(plugins) {
5
+ debug(content `Looking up the Ngrok tunnel plugin...`);
6
+ const tunnelPlugin = plugins.find((plugin) => TUNNEL_PLUGINS.includes(plugin.name));
7
+ if (!tunnelPlugin)
8
+ return undefined;
9
+ const tunnelPath = pathToFileURL(join(tunnelPlugin.root, 'dist/tunnel.js')).toString();
10
+ return import(tunnelPath).catch(() => undefined);
11
+ }
12
+ //# sourceMappingURL=plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,aAAa,EAAC,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAC,KAAK,EAAE,OAAO,EAAC,MAAM,aAAa,CAAA;AAG1C,MAAM,cAAc,GAAG,CAAC,uBAAuB,CAAC,CAAA;AAUhD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAiB;IACxD,KAAK,CAAC,OAAO,CAAA,uCAAuC,CAAC,CAAA;IACrD,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IACnF,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAA;IACnC,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;IACtF,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AAClD,CAAC","sourcesContent":["import {join, pathToFileURL} from './path.js'\nimport {debug, content} from './output.js'\nimport {Plugin} from '@oclif/core/lib/interfaces'\n\nconst TUNNEL_PLUGINS = ['@shopify/plugin-ngrok']\n\ninterface TunnelPlugin {\n start: (options: TunnelStartOptions) => Promise<string>\n}\n\ninterface TunnelStartOptions {\n port: number\n}\n\nexport async function lookupTunnelPlugin(plugins: Plugin[]): Promise<TunnelPlugin | undefined> {\n debug(content`Looking up the Ngrok tunnel plugin...`)\n const tunnelPlugin = plugins.find((plugin) => TUNNEL_PLUGINS.includes(plugin.name))\n if (!tunnelPlugin) return undefined\n const tunnelPath = pathToFileURL(join(tunnelPlugin.root, 'dist/tunnel.js')).toString()\n return import(tunnelPath).catch(() => undefined)\n}\n"]}
package/dist/port.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns an available port in the current environment.
3
+ * @returns {Promise<number>} A promise that resolves with an availabe port.
4
+ */
5
+ export declare function getRandomPort(): Promise<number>;
package/dist/port.js ADDED
@@ -0,0 +1,13 @@
1
+ import { debug, content, token } from './output.js';
2
+ import * as port from 'get-port-please';
3
+ /**
4
+ * Returns an available port in the current environment.
5
+ * @returns {Promise<number>} A promise that resolves with an availabe port.
6
+ */
7
+ export async function getRandomPort() {
8
+ debug(content `Getting a random port...`);
9
+ const randomPort = await port.getRandomPort();
10
+ debug(content `Random port obtained: ${token.raw(`${randomPort}`)}`);
11
+ return randomPort;
12
+ }
13
+ //# sourceMappingURL=port.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"port.js","sourceRoot":"","sources":["../src/port.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AAEvC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,KAAK,CAAC,OAAO,CAAA,0BAA0B,CAAC,CAAA;IACxC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAA;IAC7C,KAAK,CAAC,OAAO,CAAA,yBAAyB,KAAK,CAAC,GAAG,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,CAAC,CAAA;IACnE,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import {debug, content, token} from './output.js'\nimport * as port from 'get-port-please'\n\n/**\n * Returns an available port in the current environment.\n * @returns {Promise<number>} A promise that resolves with an availabe port.\n */\nexport async function getRandomPort(): Promise<number> {\n debug(content`Getting a random port...`)\n const randomPort = await port.getRandomPort()\n debug(content`Random port obtained: ${token.raw(`${randomPort}`)}`)\n return randomPort\n}\n"]}
package/dist/ruby.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import { AdminSession } from './session.js';
3
+ import { Writable } from 'node:stream';
4
+ /**
5
+ * Execute CLI 2.0 commands.
6
+ * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.
7
+ * User must have a valid ruby+bundler environment to run any command.
8
+ *
9
+ * @param args {string[]} List of argumets to execute. (ex: ['theme', 'pull'])
10
+ * @param adminSession {AdminSession} Contains token and store to pass to CLI 2.0, which will be set as environment variables
11
+ */
12
+ export declare function execCLI(args: string[], adminSession?: AdminSession): Promise<void>;
13
+ interface ExecThemeCheckCLIOptions {
14
+ directories: string[];
15
+ args?: string[];
16
+ stdout: Writable;
17
+ stderr: Writable;
18
+ }
19
+ export declare function execThemeCheckCLI({ directories, args, stdout, stderr, }: ExecThemeCheckCLIOptions): Promise<void[]>;
20
+ export declare function version(): Promise<string | undefined>;
21
+ export {};
package/dist/ruby.js ADDED
@@ -0,0 +1,192 @@
1
+ import * as file from './file.js';
2
+ import * as ui from './ui.js';
3
+ import * as system from './system.js';
4
+ import { Abort } from './error.js';
5
+ import { glob, join } from './path.js';
6
+ import constants from './constants.js';
7
+ import { coerce } from './semver.js';
8
+ import { content, token } from './output.js';
9
+ // eslint-disable-next-line no-restricted-imports
10
+ import { spawn } from 'child_process';
11
+ import { Writable } from 'node:stream';
12
+ const RubyCLIVersion = '2.16.0';
13
+ const ThemeCheckVersion = '1.10.2';
14
+ const MinBundlerVersion = '2.3.8';
15
+ const MinRubyVersion = '2.3.0';
16
+ const MinRubyGemVersion = '2.5.0';
17
+ /**
18
+ * Execute CLI 2.0 commands.
19
+ * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.
20
+ * User must have a valid ruby+bundler environment to run any command.
21
+ *
22
+ * @param args {string[]} List of argumets to execute. (ex: ['theme', 'pull'])
23
+ * @param adminSession {AdminSession} Contains token and store to pass to CLI 2.0, which will be set as environment variables
24
+ */
25
+ export async function execCLI(args, adminSession) {
26
+ await installCLIDependencies();
27
+ const env = {
28
+ ...process.env,
29
+ SHOPIFY_CLI_ADMIN_AUTH_TOKEN: adminSession?.token,
30
+ SHOPIFY_CLI_STORE: adminSession?.storeFqdn,
31
+ };
32
+ spawn('bundle', ['exec', 'shopify'].concat(args), {
33
+ stdio: 'inherit',
34
+ cwd: shopifyCLIDirectory(),
35
+ shell: true,
36
+ env,
37
+ });
38
+ }
39
+ export async function execThemeCheckCLI({ directories, args, stdout, stderr, }) {
40
+ await installThemeCheckCLIDependencies(stdout);
41
+ const processes = directories.map(async (directory) => {
42
+ // Check that there are files aside from the extension TOML config file,
43
+ // otherwise theme-check will return a false failure.
44
+ const files = await glob(join(directory, '/**/*'));
45
+ const fileCount = files.filter((file) => !file.match(/\.toml$/)).length;
46
+ if (fileCount === 0)
47
+ return;
48
+ const customStderr = new Writable({
49
+ write(chunk, ...args) {
50
+ // For some reason, theme-check reports this initial status line to stderr
51
+ // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31
52
+ // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65
53
+ if (chunk.toString('ascii').match(/^Checking/)) {
54
+ stdout.write(chunk, ...args);
55
+ }
56
+ else {
57
+ stderr.write(chunk, ...args);
58
+ }
59
+ },
60
+ });
61
+ await system.exec('bundle', ['exec', 'theme-check'].concat([directory, ...(args || [])]), {
62
+ stdout,
63
+ stderr: customStderr,
64
+ cwd: themeCheckDirectory(),
65
+ });
66
+ });
67
+ return Promise.all(processes);
68
+ }
69
+ /**
70
+ * Validate Ruby Enviroment
71
+ * Install Theme Check CLI and its dependencies
72
+ * Shows a loading message if it's the first time installing dependencies
73
+ * or if we are installing a new version of Theme Check CLI
74
+ */
75
+ async function installThemeCheckCLIDependencies(stdout) {
76
+ const exists = await file.exists(themeCheckDirectory());
77
+ if (!exists)
78
+ stdout.write('Installing theme dependencies...');
79
+ const list = ui.newListr([
80
+ {
81
+ title: 'Installing theme dependencies',
82
+ task: async () => {
83
+ await validateRubyEnv();
84
+ await createThemeCheckCLIWorkingDirectory();
85
+ await createThemeCheckGemfile();
86
+ await bundleInstallThemeCheck();
87
+ },
88
+ },
89
+ ], { renderer: 'silent' });
90
+ await list.run();
91
+ if (!exists)
92
+ stdout.write('Installed theme dependencies!');
93
+ }
94
+ /**
95
+ * Validate Ruby Enviroment
96
+ * Install RubyCLI and its dependencies
97
+ * Shows a loading spinner if it's the first time installing dependencies
98
+ * or if we are installing a new version of RubyCLI
99
+ */
100
+ async function installCLIDependencies() {
101
+ const exists = await file.exists(shopifyCLIDirectory());
102
+ const renderer = exists ? 'silent' : 'default';
103
+ const list = ui.newListr([
104
+ {
105
+ title: 'Installing theme dependencies',
106
+ task: async () => {
107
+ await validateRubyEnv();
108
+ await createShopifyCLIWorkingDirectory();
109
+ await createShopifyCLIGemfile();
110
+ await bundleInstallShopifyCLI();
111
+ },
112
+ },
113
+ ], { renderer });
114
+ await list.run();
115
+ }
116
+ async function validateRubyEnv() {
117
+ await validateRuby();
118
+ await validateRubyGems();
119
+ await validateBundler();
120
+ }
121
+ async function validateRuby() {
122
+ let version;
123
+ try {
124
+ const stdout = await system.captureOutput('ruby', ['-v']);
125
+ version = coerce(stdout);
126
+ }
127
+ catch {
128
+ throw new Abort('Ruby environment not found', `Make sure you have Ruby installed on your system: ${content `${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value}`);
129
+ }
130
+ const isValid = version?.compare(MinRubyVersion);
131
+ if (isValid === -1 || isValid === undefined) {
132
+ throw new Abort(`Ruby version ${content `${token.yellow(version.raw)}`.value} is not supported`, `Make sure you have at least Ruby ${content `${token.yellow(MinRubyVersion)}`.value} installed on your system: ${content `${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value}`);
133
+ }
134
+ }
135
+ async function validateRubyGems() {
136
+ const stdout = await system.captureOutput('gem', ['-v']);
137
+ const version = coerce(stdout);
138
+ const isValid = version?.compare(MinRubyGemVersion);
139
+ if (isValid === -1 || isValid === undefined) {
140
+ throw new Abort(`RubyGems version ${content `${token.yellow(version.raw)}`.value} is not supported`, `To update to the latest version of RubyGems, run ${content `${token.genericShellCommand('gem update --system')}`.value}`);
141
+ }
142
+ }
143
+ async function validateBundler() {
144
+ let version;
145
+ try {
146
+ const stdout = await system.captureOutput('bundler', ['-v']);
147
+ version = coerce(stdout);
148
+ }
149
+ catch {
150
+ throw new Abort('Bundler not found', `To install the latest version of Bundler, run ${content `${token.genericShellCommand('gem install bundler')}`.value}`);
151
+ }
152
+ const isValid = version?.compare(MinBundlerVersion);
153
+ if (isValid === -1 || isValid === undefined) {
154
+ throw new Abort(`Bundler version ${content `${token.yellow(version.raw)}`.value} is not supported`, `To update to the latest version of Bundler, run ${content `${token.genericShellCommand('gem install bundler')}`.value}`);
155
+ }
156
+ }
157
+ function createShopifyCLIWorkingDirectory() {
158
+ return file.mkdir(shopifyCLIDirectory());
159
+ }
160
+ function createThemeCheckCLIWorkingDirectory() {
161
+ return file.mkdir(themeCheckDirectory());
162
+ }
163
+ async function createShopifyCLIGemfile() {
164
+ const gemPath = join(shopifyCLIDirectory(), 'Gemfile');
165
+ await file.write(gemPath, `source 'https://rubygems.org'\ngem 'shopify-cli', '${RubyCLIVersion}'`);
166
+ }
167
+ async function createThemeCheckGemfile() {
168
+ const gemPath = join(themeCheckDirectory(), 'Gemfile');
169
+ await file.write(gemPath, `source 'https://rubygems.org'\ngem 'theme-check', '${ThemeCheckVersion}'`);
170
+ }
171
+ async function bundleInstallShopifyCLI() {
172
+ await system.exec('bundle', ['config', 'set', '--local', 'path', shopifyCLIDirectory()], { cwd: shopifyCLIDirectory() });
173
+ await system.exec('bundle', ['install'], { cwd: shopifyCLIDirectory() });
174
+ }
175
+ async function bundleInstallThemeCheck() {
176
+ await system.exec('bundle', ['config', 'set', '--local', 'path', themeCheckDirectory()], { cwd: themeCheckDirectory() });
177
+ await system.exec('bundle', ['install'], { cwd: themeCheckDirectory() });
178
+ }
179
+ function shopifyCLIDirectory() {
180
+ return join(constants.paths.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion);
181
+ }
182
+ function themeCheckDirectory() {
183
+ return join(constants.paths.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion);
184
+ }
185
+ export async function version() {
186
+ const parseOutput = (version) => version.match(/ruby (\d+\.\d+\.\d+)/)?.[1];
187
+ return system
188
+ .captureOutput('ruby', ['-v'])
189
+ .then(parseOutput)
190
+ .catch(() => undefined);
191
+ }
192
+ //# sourceMappingURL=ruby.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ruby.js","sourceRoot":"","sources":["../src/ruby.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,WAAW,CAAA;AACpC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAElC,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AAC1C,iDAAiD;AACjD,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAA;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AAEpC,MAAM,cAAc,GAAG,QAAQ,CAAA;AAC/B,MAAM,iBAAiB,GAAG,QAAQ,CAAA;AAClC,MAAM,iBAAiB,GAAG,OAAO,CAAA;AACjC,MAAM,cAAc,GAAG,OAAO,CAAA;AAC9B,MAAM,iBAAiB,GAAG,OAAO,CAAA;AAEjC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAc,EAAE,YAA2B;IACvE,MAAM,sBAAsB,EAAE,CAAA;IAC9B,MAAM,GAAG,GAAG;QACV,GAAG,OAAO,CAAC,GAAG;QACd,4BAA4B,EAAE,YAAY,EAAE,KAAK;QACjD,iBAAiB,EAAE,YAAY,EAAE,SAAS;KAC3C,CAAA;IAED,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,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C,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,EAAC,GAAG,EAAE,mBAAmB,EAAE,EAAC,CAAC,CAAA;AACxE,CAAC;AAED,SAAS,mBAAmB;IAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,cAAc,CAAC,CAAA;AAC1F,CAAC;AAED,SAAS,mBAAmB;IAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAA;AAChG,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO;IAC3B,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACnF,OAAO,MAAM;SACV,aAAa,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;SAC7B,IAAI,CAAC,WAAW,CAAC;SACjB,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AAC3B,CAAC","sourcesContent":["import * as file from './file.js'\nimport * as ui from './ui.js'\nimport * as system from './system.js'\nimport {Abort} from './error.js'\nimport {glob, join} from './path.js'\nimport constants from './constants.js'\nimport {coerce} from './semver.js'\nimport {AdminSession} from './session.js'\nimport {content, token} from './output.js'\n// eslint-disable-next-line no-restricted-imports\nimport {spawn} from 'child_process'\nimport {Writable} from 'node:stream'\n\nconst RubyCLIVersion = '2.16.0'\nconst ThemeCheckVersion = '1.10.2'\nconst MinBundlerVersion = '2.3.8'\nconst MinRubyVersion = '2.3.0'\nconst MinRubyGemVersion = '2.5.0'\n\n/**\n * Execute CLI 2.0 commands.\n * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.\n * User must have a valid ruby+bundler environment to run any command.\n *\n * @param args {string[]} List of argumets to execute. (ex: ['theme', 'pull'])\n * @param adminSession {AdminSession} Contains token and store to pass to CLI 2.0, which will be set as environment variables\n */\nexport async function execCLI(args: string[], adminSession?: AdminSession) {\n await installCLIDependencies()\n const env = {\n ...process.env,\n SHOPIFY_CLI_ADMIN_AUTH_TOKEN: adminSession?.token,\n SHOPIFY_CLI_STORE: adminSession?.storeFqdn,\n }\n\n spawn('bundle', ['exec', 'shopify'].concat(args), {\n stdio: 'inherit',\n cwd: shopifyCLIDirectory(),\n shell: true,\n env,\n })\n}\n\ninterface ExecThemeCheckCLIOptions {\n directories: string[]\n args?: string[]\n stdout: Writable\n stderr: Writable\n}\nexport async function execThemeCheckCLI({\n directories,\n args,\n stdout,\n stderr,\n}: ExecThemeCheckCLIOptions): Promise<void[]> {\n await installThemeCheckCLIDependencies(stdout)\n\n const processes = directories.map(async (directory): Promise<void> => {\n // Check that there are files aside from the extension TOML config file,\n // otherwise theme-check will return a false failure.\n const files = await glob(join(directory, '/**/*'))\n const fileCount = files.filter((file) => !file.match(/\\.toml$/)).length\n if (fileCount === 0) return\n\n const customStderr = new Writable({\n write(chunk, ...args) {\n // For some reason, theme-check reports this initial status line to stderr\n // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31\n // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65\n if (chunk.toString('ascii').match(/^Checking/)) {\n stdout.write(chunk, ...args)\n } else {\n stderr.write(chunk, ...args)\n }\n },\n })\n await system.exec('bundle', ['exec', 'theme-check'].concat([directory, ...(args || [])]), {\n stdout,\n stderr: customStderr,\n cwd: themeCheckDirectory(),\n })\n })\n return Promise.all(processes)\n}\n\n/**\n * Validate Ruby Enviroment\n * Install Theme Check CLI and its dependencies\n * Shows a loading message if it's the first time installing dependencies\n * or if we are installing a new version of Theme Check CLI\n */\nasync function installThemeCheckCLIDependencies(stdout: Writable) {\n const exists = await file.exists(themeCheckDirectory())\n\n if (!exists) stdout.write('Installing theme dependencies...')\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n await validateRubyEnv()\n await createThemeCheckCLIWorkingDirectory()\n await createThemeCheckGemfile()\n await bundleInstallThemeCheck()\n },\n },\n ],\n {renderer: 'silent'},\n )\n await list.run()\n if (!exists) stdout.write('Installed theme dependencies!')\n}\n\n/**\n * Validate Ruby Enviroment\n * Install RubyCLI and its dependencies\n * Shows a loading spinner if it's the first time installing dependencies\n * or if we are installing a new version of RubyCLI\n */\nasync function installCLIDependencies() {\n const exists = await file.exists(shopifyCLIDirectory())\n const renderer = exists ? 'silent' : 'default'\n\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n await validateRubyEnv()\n await createShopifyCLIWorkingDirectory()\n await createShopifyCLIGemfile()\n await bundleInstallShopifyCLI()\n },\n },\n ],\n {renderer},\n )\n await list.run()\n}\n\nasync function validateRubyEnv() {\n await validateRuby()\n await validateRubyGems()\n await validateBundler()\n}\n\nasync function validateRuby() {\n let version\n try {\n const stdout = await system.captureOutput('ruby', ['-v'])\n version = coerce(stdout)\n } catch {\n throw new Abort(\n 'Ruby environment not found',\n `Make sure you have Ruby installed on your system: ${\n content`${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinRubyVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Ruby version ${content`${token.yellow(version!.raw)}`.value} is not supported`,\n `Make sure you have at least Ruby ${content`${token.yellow(MinRubyVersion)}`.value} installed on your system: ${\n content`${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n}\n\nasync function validateRubyGems() {\n const stdout = await system.captureOutput('gem', ['-v'])\n const version = coerce(stdout)\n\n const isValid = version?.compare(MinRubyGemVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `RubyGems version ${content`${token.yellow(version!.raw)}`.value} is not supported`,\n `To update to the latest version of RubyGems, run ${\n content`${token.genericShellCommand('gem update --system')}`.value\n }`,\n )\n }\n}\n\nasync function validateBundler() {\n let version\n try {\n const stdout = await system.captureOutput('bundler', ['-v'])\n version = coerce(stdout)\n } catch {\n throw new Abort(\n 'Bundler not found',\n `To install the latest version of Bundler, run ${\n content`${token.genericShellCommand('gem install bundler')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinBundlerVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Bundler version ${content`${token.yellow(version!.raw)}`.value} is not supported`,\n `To update to the latest version of Bundler, run ${\n content`${token.genericShellCommand('gem install bundler')}`.value\n }`,\n )\n }\n}\n\nfunction createShopifyCLIWorkingDirectory() {\n return file.mkdir(shopifyCLIDirectory())\n}\n\nfunction createThemeCheckCLIWorkingDirectory() {\n return file.mkdir(themeCheckDirectory())\n}\n\nasync function createShopifyCLIGemfile() {\n const gemPath = join(shopifyCLIDirectory(), 'Gemfile')\n await file.write(gemPath, `source 'https://rubygems.org'\\ngem 'shopify-cli', '${RubyCLIVersion}'`)\n}\n\nasync function createThemeCheckGemfile() {\n const gemPath = join(themeCheckDirectory(), 'Gemfile')\n await file.write(gemPath, `source 'https://rubygems.org'\\ngem 'theme-check', '${ThemeCheckVersion}'`)\n}\n\nasync function bundleInstallShopifyCLI() {\n await system.exec('bundle', ['config', 'set', '--local', 'path', shopifyCLIDirectory()], {cwd: shopifyCLIDirectory()})\n await system.exec('bundle', ['install'], {cwd: shopifyCLIDirectory()})\n}\n\nasync function bundleInstallThemeCheck() {\n await system.exec('bundle', ['config', 'set', '--local', 'path', themeCheckDirectory()], {cwd: themeCheckDirectory()})\n await system.exec('bundle', ['install'], {cwd: themeCheckDirectory()})\n}\n\nfunction shopifyCLIDirectory() {\n return join(constants.paths.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion)\n}\n\nfunction themeCheckDirectory() {\n return join(constants.paths.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion)\n}\n\nexport async function version(): Promise<string | undefined> {\n const parseOutput = (version: string) => version.match(/ruby (\\d+\\.\\d+\\.\\d+)/)?.[1]\n return system\n .captureOutput('ruby', ['-v'])\n .then(parseOutput)\n .catch(() => undefined)\n}\n"]}
@@ -0,0 +1 @@
1
+ export { z as define } from 'zod';
package/dist/schema.js ADDED
@@ -0,0 +1,2 @@
1
+ export { z as define } from 'zod';
2
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,IAAI,MAAM,EAAC,MAAM,KAAK,CAAA","sourcesContent":["export {z as define} from 'zod'\n"]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Fetches secured content from the system's keychain.
3
+ * @param identifier {string} Identifier to identify the content.
4
+ * @returns A promise that resolves with the content or null if it doesn't exist.
5
+ */
6
+ export declare function fetch(identifier: string): Promise<string | null>;
7
+ /**
8
+ * Securely stores the content under the given key.
9
+ * @param identifier {string} Identifier to identify the content.
10
+ * @param content {string} The content to be stored.
11
+ * @returns A promise that resolves when the storing completes.
12
+ */
13
+ export declare function store(identifier: string, content: string): Promise<void>;
14
+ /**
15
+ * Removes the content with the given identifier.
16
+ * @param identifier {string} Identifier to identify the content.
17
+ * @returns A promise that resolves with true if the content was deleted.
18
+ */
19
+ export declare function remove(identifier: string): Promise<boolean>;
@@ -0,0 +1,63 @@
1
+ import constants from './constants.js';
2
+ import { content as outputContent, debug } from './output.js';
3
+ import { Abort } from './error.js';
4
+ /**
5
+ * Fetches secured content from the system's keychain.
6
+ * @param identifier {string} Identifier to identify the content.
7
+ * @returns A promise that resolves with the content or null if it doesn't exist.
8
+ */
9
+ export async function fetch(identifier) {
10
+ debug(outputContent `Reading ${identifier} from the secure store...`);
11
+ try {
12
+ const keytar = await import('keytar');
13
+ const content = await keytar.getPassword(constants.keychain.service, identifier);
14
+ return content;
15
+ }
16
+ catch (error) {
17
+ throw createAbort(error, 'Unable to read from the secure store');
18
+ }
19
+ }
20
+ /**
21
+ * Securely stores the content under the given key.
22
+ * @param identifier {string} Identifier to identify the content.
23
+ * @param content {string} The content to be stored.
24
+ * @returns A promise that resolves when the storing completes.
25
+ */
26
+ export async function store(identifier, content) {
27
+ debug(outputContent `Updating ${identifier} in the secure store with new content...`);
28
+ try {
29
+ const keytar = await import('keytar');
30
+ await keytar.default.setPassword(constants.keychain.service, identifier, content);
31
+ }
32
+ catch (error) {
33
+ throw createAbort(error, 'Unable to update the secure store');
34
+ }
35
+ }
36
+ /**
37
+ * Removes the content with the given identifier.
38
+ * @param identifier {string} Identifier to identify the content.
39
+ * @returns A promise that resolves with true if the content was deleted.
40
+ */
41
+ export async function remove(identifier) {
42
+ debug(outputContent `Removing ${identifier} from the secure store...`);
43
+ try {
44
+ const keytar = await import('keytar');
45
+ const result = await keytar.default.deletePassword(constants.keychain.service, identifier);
46
+ return result;
47
+ }
48
+ catch (error) {
49
+ throw createAbort(error, 'Unable to remove from the secure store');
50
+ }
51
+ }
52
+ function createAbort(error, message) {
53
+ let newMessage = message;
54
+ let stack = '';
55
+ if (error instanceof Error) {
56
+ newMessage = message.concat(`: ${error.message}`);
57
+ stack = error.stack;
58
+ }
59
+ const abort = new Abort(newMessage);
60
+ abort.stack = stack;
61
+ return abort;
62
+ }
63
+ //# sourceMappingURL=secure-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secure-store.js","sourceRoot":"","sources":["../src/secure-store.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAC,OAAO,IAAI,aAAa,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AAC3D,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAEhC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,UAAkB;IAC5C,KAA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AAC;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,KAAK,CAAC,UAAU,CAAC,CAAA;IACnC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAA;IACnB,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import constants from './constants.js'\nimport {content as outputContent, debug} from './output.js'\nimport {Abort} from './error.js'\n\n/**\n * Fetches secured content from the system's keychain.\n * @param identifier {string} 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 fetch(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(constants.keychain.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 {string} Identifier to identify the content.\n * @param content {string} The content to be stored.\n * @returns A promise that resolves when the storing completes.\n */\nexport async function store(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(constants.keychain.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 {string} Identifier to identify the content.\n * @returns A promise that resolves with true if the content was deleted.\n */\nexport async function remove(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(constants.keychain.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 Abort(newMessage)\n abort.stack = stack\n return abort\n}\n"]}
@@ -0,0 +1,3 @@
1
+ declare const coerce: any, SemVer: any;
2
+ export { SemVer as Version };
3
+ export { coerce };
package/dist/semver.js ADDED
@@ -0,0 +1,6 @@
1
+ import { createRequire } from 'module';
2
+ const require = createRequire(import.meta.url);
3
+ const { coerce, SemVer } = require('semver');
4
+ export { SemVer as Version };
5
+ export { coerce };
6
+ //# sourceMappingURL=semver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semver.js","sourceRoot":"","sources":["../src/semver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,QAAQ,CAAA;AAEpC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,MAAM,EAAC,MAAM,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAE1C,OAAO,EAAC,MAAM,IAAI,OAAO,EAAC,CAAA;AAC1B,OAAO,EAAC,MAAM,EAAC,CAAA","sourcesContent":["import {createRequire} from 'module'\n\nconst require = createRequire(import.meta.url)\nconst {coerce, SemVer} = require('semver')\n\nexport {SemVer as Version}\nexport {coerce}\n"]}
@@ -0,0 +1,7 @@
1
+ import { Abort } from '../error.js';
2
+ export declare const MismatchStateError: Abort;
3
+ export interface CodeAuthResult {
4
+ code: string;
5
+ codeVerifier: string;
6
+ }
7
+ export declare function authorize(scopes: string[], state?: string): Promise<CodeAuthResult>;
@@ -0,0 +1,40 @@
1
+ import { listenRedirect } from './redirect-listener.js';
2
+ import { clientId } from './identity.js';
3
+ import { generateRandomChallengePair, randomHex } from '../string.js';
4
+ import { open } from '../system.js';
5
+ import { Abort } from '../error.js';
6
+ import { identity as identityFqdn } from '../environment/fqdn.js';
7
+ import * as output from '../output.js';
8
+ import { keypress } from '../ui.js';
9
+ export const MismatchStateError = new Abort("The state received from the authentication doesn't match the one that initiated the authentication process.");
10
+ export async function authorize(scopes, state = randomHex(30)) {
11
+ const port = 3456;
12
+ const host = '127.0.0.1';
13
+ const redirectUri = `http://${host}:${port}`;
14
+ const fqdn = await identityFqdn();
15
+ const identityClientId = await clientId();
16
+ let url = `http://${fqdn}/oauth/authorize`;
17
+ const { codeVerifier, codeChallenge } = generateRandomChallengePair();
18
+ /* eslint-disable @typescript-eslint/naming-convention */
19
+ const params = {
20
+ client_id: identityClientId,
21
+ scope: scopes.join(' '),
22
+ redirect_uri: redirectUri,
23
+ state,
24
+ response_type: 'code',
25
+ code_challenge_method: 'S256',
26
+ code_challenge: codeChallenge,
27
+ };
28
+ /* eslint-enable @typescript-eslint/naming-convention */
29
+ output.info('\nTo run this command, log in to Shopify Partners.');
30
+ output.info('👉 Press any key to open the login page on your browser');
31
+ await keypress();
32
+ url = `${url}?${new URLSearchParams(params).toString()}`;
33
+ open(url);
34
+ const result = await listenRedirect(host, port, url);
35
+ if (result.state !== state) {
36
+ throw MismatchStateError;
37
+ }
38
+ return { code: result.code, codeVerifier };
39
+ }
40
+ //# sourceMappingURL=authorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/session/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,2BAA2B,EAAE,SAAS,EAAC,MAAM,cAAc,CAAA;AACnE,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAA;AACjC,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AACjC,OAAO,EAAC,QAAQ,IAAI,YAAY,EAAC,MAAM,wBAAwB,CAAA;AA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,MAAM,CAAC,KAAK,KAAK,KAAK,EAAE;QAC1B,MAAM,kBAAkB,CAAA;KACzB;IAED,OAAO,EAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,YAAY,EAAC,CAAA;AAC1C,CAAC","sourcesContent":["import {listenRedirect} from './redirect-listener.js'\nimport {clientId} from './identity.js'\nimport {generateRandomChallengePair, randomHex} from '../string.js'\nimport {open} from '../system.js'\nimport {Abort} from '../error.js'\nimport {identity as identityFqdn} from '../environment/fqdn.js'\nimport * as output from '../output.js'\nimport {keypress} from '../ui.js'\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 = await clientId()\n\n let url = `http://${fqdn}/oauth/authorize`\n\n const {codeVerifier, codeChallenge} = generateRandomChallengePair()\n\n /* eslint-disable @typescript-eslint/naming-convention */\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 /* eslint-enable @typescript-eslint/naming-convention */\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 open(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"]}
@@ -0,0 +1,42 @@
1
+ import { ApplicationToken, IdentityToken } from './schema.js';
2
+ import { CodeAuthResult } from './authorize.js';
3
+ export declare class InvalidGrantError extends Error {
4
+ }
5
+ export interface ExchangeScopes {
6
+ admin: string[];
7
+ partners: string[];
8
+ storefront: string[];
9
+ }
10
+ /**
11
+ * Given a valid authorization code, request an identity access token.
12
+ * This token can then be used to get API specific tokens.
13
+ * @param codeData code and codeVerifier from the authorize endpoint
14
+ * @param clientId
15
+ * @param identityFqdn
16
+ * @returns {Promise<IdentityToken>} An instance with the identity access tokens.
17
+ */
18
+ export declare function exchangeCodeForAccessToken(codeData: CodeAuthResult): Promise<IdentityToken>;
19
+ /**
20
+ * Given an identity token, request an application token.
21
+ * @param token access token obtained in a previous step
22
+ * @param store the store to use, only needed for admin API
23
+ * @param clientId
24
+ * @param identityFqdn
25
+ * @returns {Promise<ApplicationSchema>} An array with the application access tokens.
26
+ */
27
+ export declare function exchangeAccessForApplicationTokens(identityToken: IdentityToken, scopes: ExchangeScopes, store?: string): Promise<{
28
+ [x: string]: ApplicationToken;
29
+ }>;
30
+ /**
31
+ * Given an expired access token, refresh it to get a new one.
32
+ * @param currentToken
33
+ * @returns
34
+ */
35
+ export declare function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken>;
36
+ /**
37
+ * Given a custom CLI token passed as ENV variable, request a valid partners API token
38
+ * This token does not accept extra scopes, just the cli one.
39
+ * @param token {string} The CLI token passed as ENV variable
40
+ * @returns {Promise<ApplicationToken>} An instance with the application access tokens.
41
+ */
42
+ export declare function exchangeCustomPartnerToken(token: string): Promise<ApplicationToken>;