@shopify/cli-kit 0.0.0-nightly-20230110194301

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 (488) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +63 -0
  3. package/assets/auth-error.html +23 -0
  4. package/assets/empty-url.html +23 -0
  5. package/assets/favicon.svg +26 -0
  6. package/assets/missing-code.html +23 -0
  7. package/assets/missing-state.html +23 -0
  8. package/assets/style.css +58 -0
  9. package/assets/success.html +20 -0
  10. package/dist/api/admin.d.ts +3 -0
  11. package/dist/api/admin.js +56 -0
  12. package/dist/api/admin.js.map +1 -0
  13. package/dist/api/common.d.ts +21 -0
  14. package/dist/api/common.js +87 -0
  15. package/dist/api/common.js.map +1 -0
  16. package/dist/api/graphql/all_app_extension_registrations.d.ts +20 -0
  17. package/dist/api/graphql/all_app_extension_registrations.js +20 -0
  18. package/dist/api/graphql/all_app_extension_registrations.js.map +1 -0
  19. package/dist/api/graphql/all_dev_stores_by_org.d.ts +18 -0
  20. package/dist/api/graphql/all_dev_stores_by_org.js +21 -0
  21. package/dist/api/graphql/all_dev_stores_by_org.js.map +1 -0
  22. package/dist/api/graphql/all_orgs.d.ts +12 -0
  23. package/dist/api/graphql/all_orgs.js +14 -0
  24. package/dist/api/graphql/all_orgs.js.map +1 -0
  25. package/dist/api/graphql/convert_dev_to_test_store.d.ts +16 -0
  26. package/dist/api/graphql/convert_dev_to_test_store.js +13 -0
  27. package/dist/api/graphql/convert_dev_to_test_store.js.map +1 -0
  28. package/dist/api/graphql/create_app.d.ts +29 -0
  29. package/dist/api/graphql/create_app.js +33 -0
  30. package/dist/api/graphql/create_app.js.map +1 -0
  31. package/dist/api/graphql/create_deployment.d.ts +33 -0
  32. package/dist/api/graphql/create_deployment.js +25 -0
  33. package/dist/api/graphql/create_deployment.js.map +1 -0
  34. package/dist/api/graphql/extension_create.d.ts +30 -0
  35. package/dist/api/graphql/extension_create.js +26 -0
  36. package/dist/api/graphql/extension_create.js.map +1 -0
  37. package/dist/api/graphql/extension_specifications.d.ts +27 -0
  38. package/dist/api/graphql/extension_specifications.js +22 -0
  39. package/dist/api/graphql/extension_specifications.js.map +1 -0
  40. package/dist/api/graphql/find_app.d.ts +14 -0
  41. package/dist/api/graphql/find_app.js +17 -0
  42. package/dist/api/graphql/find_app.js.map +1 -0
  43. package/dist/api/graphql/find_org.d.ts +18 -0
  44. package/dist/api/graphql/find_org.js +21 -0
  45. package/dist/api/graphql/find_org.js.map +1 -0
  46. package/dist/api/graphql/find_org_basic.d.ts +11 -0
  47. package/dist/api/graphql/find_org_basic.js +14 -0
  48. package/dist/api/graphql/find_org_basic.js.map +1 -0
  49. package/dist/api/graphql/find_store_by_domain.d.ts +21 -0
  50. package/dist/api/graphql/find_store_by_domain.js +24 -0
  51. package/dist/api/graphql/find_store_by_domain.js.map +1 -0
  52. package/dist/api/graphql/functions/api_schema_definition.d.ts +9 -0
  53. package/dist/api/graphql/functions/api_schema_definition.js +7 -0
  54. package/dist/api/graphql/functions/api_schema_definition.js.map +1 -0
  55. package/dist/api/graphql/functions/app_function_set.d.ts +30 -0
  56. package/dist/api/graphql/functions/app_function_set.js +38 -0
  57. package/dist/api/graphql/functions/app_function_set.js.map +1 -0
  58. package/dist/api/graphql/functions/function_service_proxy.d.ts +4 -0
  59. package/dist/api/graphql/functions/function_service_proxy.js +7 -0
  60. package/dist/api/graphql/functions/function_service_proxy.js.map +1 -0
  61. package/dist/api/graphql/functions/upload_url_generate.d.ts +12 -0
  62. package/dist/api/graphql/functions/upload_url_generate.js +11 -0
  63. package/dist/api/graphql/functions/upload_url_generate.js.map +1 -0
  64. package/dist/api/graphql/generate_signed_upload_url.d.ts +15 -0
  65. package/dist/api/graphql/generate_signed_upload_url.js +15 -0
  66. package/dist/api/graphql/generate_signed_upload_url.js.map +1 -0
  67. package/dist/api/graphql/get_urls.d.ts +10 -0
  68. package/dist/api/graphql/get_urls.js +10 -0
  69. package/dist/api/graphql/get_urls.js.map +1 -0
  70. package/dist/api/graphql/get_variant_id.d.ts +17 -0
  71. package/dist/api/graphql/get_variant_id.js +20 -0
  72. package/dist/api/graphql/get_variant_id.js.map +1 -0
  73. package/dist/api/graphql/index.d.ts +21 -0
  74. package/dist/api/graphql/index.js +22 -0
  75. package/dist/api/graphql/index.js.map +1 -0
  76. package/dist/api/graphql/update_draft.d.ts +33 -0
  77. package/dist/api/graphql/update_draft.js +24 -0
  78. package/dist/api/graphql/update_draft.js.map +1 -0
  79. package/dist/api/graphql/update_urls.d.ts +14 -0
  80. package/dist/api/graphql/update_urls.js +12 -0
  81. package/dist/api/graphql/update_urls.js.map +1 -0
  82. package/dist/api/identity.d.ts +1 -0
  83. package/dist/api/identity.js +41 -0
  84. package/dist/api/identity.js.map +1 -0
  85. package/dist/api/oxygen.d.ts +5 -0
  86. package/dist/api/oxygen.js +30 -0
  87. package/dist/api/oxygen.js.map +1 -0
  88. package/dist/api/partners.d.ts +14 -0
  89. package/dist/api/partners.js +44 -0
  90. package/dist/api/partners.js.map +1 -0
  91. package/dist/api.d.ts +6 -0
  92. package/dist/api.js +7 -0
  93. package/dist/api.js.map +1 -0
  94. package/dist/cli.d.ts +8 -0
  95. package/dist/cli.js +18 -0
  96. package/dist/cli.js.map +1 -0
  97. package/dist/constants.d.ts +52 -0
  98. package/dist/constants.js +71 -0
  99. package/dist/constants.js.map +1 -0
  100. package/dist/content-tokens.d.ts +44 -0
  101. package/dist/content-tokens.js +105 -0
  102. package/dist/content-tokens.js.map +1 -0
  103. package/dist/environment/fqdn.d.ts +29 -0
  104. package/dist/environment/fqdn.js +72 -0
  105. package/dist/environment/fqdn.js.map +1 -0
  106. package/dist/environment/local.d.ts +92 -0
  107. package/dist/environment/local.js +169 -0
  108. package/dist/environment/local.js.map +1 -0
  109. package/dist/environment/service.d.ts +4 -0
  110. package/dist/environment/service.js +19 -0
  111. package/dist/environment/service.js.map +1 -0
  112. package/dist/environment/spin-cache.d.ts +2 -0
  113. package/dist/environment/spin-cache.js +8 -0
  114. package/dist/environment/spin-cache.js.map +1 -0
  115. package/dist/environment/spin.d.ts +50 -0
  116. package/dist/environment/spin.js +99 -0
  117. package/dist/environment/spin.js.map +1 -0
  118. package/dist/environment/utilities.d.ts +8 -0
  119. package/dist/environment/utilities.js +19 -0
  120. package/dist/environment/utilities.js.map +1 -0
  121. package/dist/environment.d.ts +7 -0
  122. package/dist/environment.js +8 -0
  123. package/dist/environment.js.map +1 -0
  124. package/dist/error.d.ts +68 -0
  125. package/dist/error.js +143 -0
  126. package/dist/error.js.map +1 -0
  127. package/dist/file.d.ts +98 -0
  128. package/dist/file.js +216 -0
  129. package/dist/file.js.map +1 -0
  130. package/dist/git.d.ts +36 -0
  131. package/dist/git.js +133 -0
  132. package/dist/git.js.map +1 -0
  133. package/dist/http/fetch.d.ts +22 -0
  134. package/dist/http/fetch.js +44 -0
  135. package/dist/http/fetch.js.map +1 -0
  136. package/dist/http/formdata.d.ts +3 -0
  137. package/dist/http/formdata.js +6 -0
  138. package/dist/http/formdata.js.map +1 -0
  139. package/dist/http/graphql.d.ts +13 -0
  140. package/dist/http/graphql.js +12 -0
  141. package/dist/http/graphql.js.map +1 -0
  142. package/dist/http.d.ts +27 -0
  143. package/dist/http.js +32 -0
  144. package/dist/http.js.map +1 -0
  145. package/dist/index.d.ts +24 -0
  146. package/dist/index.js +25 -0
  147. package/dist/index.js.map +1 -0
  148. package/dist/metadata.d.ts +53 -0
  149. package/dist/metadata.js +62 -0
  150. package/dist/metadata.js.map +1 -0
  151. package/dist/monorail.d.ts +100 -0
  152. package/dist/monorail.js +39 -0
  153. package/dist/monorail.js.map +1 -0
  154. package/dist/network/api.d.ts +2 -0
  155. package/dist/network/api.js +2 -0
  156. package/dist/network/api.js.map +1 -0
  157. package/dist/network/service.d.ts +14 -0
  158. package/dist/network/service.js +11 -0
  159. package/dist/network/service.js.map +1 -0
  160. package/dist/npm.d.ts +27 -0
  161. package/dist/npm.js +20 -0
  162. package/dist/npm.js.map +1 -0
  163. package/dist/output.d.ts +129 -0
  164. package/dist/output.js +310 -0
  165. package/dist/output.js.map +1 -0
  166. package/dist/path.d.ts +25 -0
  167. package/dist/path.js +48 -0
  168. package/dist/path.js.map +1 -0
  169. package/dist/plugins.d.ts +73 -0
  170. package/dist/plugins.js +49 -0
  171. package/dist/plugins.js.map +1 -0
  172. package/dist/private/common/json.d.ts +6 -0
  173. package/dist/private/common/json.js +2 -0
  174. package/dist/private/common/json.js.map +1 -0
  175. package/dist/private/common/lodash.d.ts +47 -0
  176. package/dist/private/common/lodash.js +2 -0
  177. package/dist/private/common/lodash.js.map +1 -0
  178. package/dist/private/node/analytics.d.ts +27 -0
  179. package/dist/private/node/analytics.js +57 -0
  180. package/dist/private/node/analytics.js.map +1 -0
  181. package/dist/private/node/ui/alert.d.ts +2 -0
  182. package/dist/private/node/ui/alert.js +18 -0
  183. package/dist/private/node/ui/alert.js.map +1 -0
  184. package/dist/private/node/ui/components/Alert.d.ts +17 -0
  185. package/dist/private/node/ui/components/Alert.js +21 -0
  186. package/dist/private/node/ui/components/Alert.js.map +1 -0
  187. package/dist/private/node/ui/components/Alert.test.d.ts +1 -0
  188. package/dist/private/node/ui/components/Alert.test.js +95 -0
  189. package/dist/private/node/ui/components/Alert.test.js.map +1 -0
  190. package/dist/private/node/ui/components/Banner.d.ts +8 -0
  191. package/dist/private/node/ui/components/Banner.js +41 -0
  192. package/dist/private/node/ui/components/Banner.js.map +1 -0
  193. package/dist/private/node/ui/components/Banner.test.d.ts +1 -0
  194. package/dist/private/node/ui/components/Banner.test.js +52 -0
  195. package/dist/private/node/ui/components/Banner.test.js.map +1 -0
  196. package/dist/private/node/ui/components/Command.d.ts +9 -0
  197. package/dist/private/node/ui/components/Command.js +13 -0
  198. package/dist/private/node/ui/components/Command.js.map +1 -0
  199. package/dist/private/node/ui/components/Command.test.d.ts +1 -0
  200. package/dist/private/node/ui/components/Command.test.js +11 -0
  201. package/dist/private/node/ui/components/Command.test.js.map +1 -0
  202. package/dist/private/node/ui/components/ConcurrentOutput.d.ts +47 -0
  203. package/dist/private/node/ui/components/ConcurrentOutput.js +86 -0
  204. package/dist/private/node/ui/components/ConcurrentOutput.js.map +1 -0
  205. package/dist/private/node/ui/components/ConcurrentOutput.test.d.ts +1 -0
  206. package/dist/private/node/ui/components/ConcurrentOutput.test.js +54 -0
  207. package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -0
  208. package/dist/private/node/ui/components/FatalError.d.ts +7 -0
  209. package/dist/private/node/ui/components/FatalError.js +54 -0
  210. package/dist/private/node/ui/components/FatalError.js.map +1 -0
  211. package/dist/private/node/ui/components/FatalError.test.d.ts +1 -0
  212. package/dist/private/node/ui/components/FatalError.test.js +119 -0
  213. package/dist/private/node/ui/components/FatalError.test.js.map +1 -0
  214. package/dist/private/node/ui/components/FilePath.d.ts +9 -0
  215. package/dist/private/node/ui/components/FilePath.js +13 -0
  216. package/dist/private/node/ui/components/FilePath.js.map +1 -0
  217. package/dist/private/node/ui/components/FilePath.test.d.ts +1 -0
  218. package/dist/private/node/ui/components/FilePath.test.js +11 -0
  219. package/dist/private/node/ui/components/FilePath.test.js.map +1 -0
  220. package/dist/private/node/ui/components/FullScreen.d.ts +8 -0
  221. package/dist/private/node/ui/components/FullScreen.js +32 -0
  222. package/dist/private/node/ui/components/FullScreen.js.map +1 -0
  223. package/dist/private/node/ui/components/Link.d.ts +10 -0
  224. package/dist/private/node/ui/components/Link.js +15 -0
  225. package/dist/private/node/ui/components/Link.js.map +1 -0
  226. package/dist/private/node/ui/components/Link.test.d.ts +1 -0
  227. package/dist/private/node/ui/components/Link.test.js +22 -0
  228. package/dist/private/node/ui/components/Link.test.js.map +1 -0
  229. package/dist/private/node/ui/components/List.d.ts +13 -0
  230. package/dist/private/node/ui/components/List.js +19 -0
  231. package/dist/private/node/ui/components/List.js.map +1 -0
  232. package/dist/private/node/ui/components/List.test.d.ts +1 -0
  233. package/dist/private/node/ui/components/List.test.js +34 -0
  234. package/dist/private/node/ui/components/List.test.js.map +1 -0
  235. package/dist/private/node/ui/components/SelectInput.d.ts +12 -0
  236. package/dist/private/node/ui/components/SelectInput.js +87 -0
  237. package/dist/private/node/ui/components/SelectInput.js.map +1 -0
  238. package/dist/private/node/ui/components/SelectInput.test.d.ts +1 -0
  239. package/dist/private/node/ui/components/SelectInput.test.js +230 -0
  240. package/dist/private/node/ui/components/SelectInput.test.js.map +1 -0
  241. package/dist/private/node/ui/components/SelectPrompt.d.ts +11 -0
  242. package/dist/private/node/ui/components/SelectPrompt.js +34 -0
  243. package/dist/private/node/ui/components/SelectPrompt.js.map +1 -0
  244. package/dist/private/node/ui/components/SelectPrompt.test.d.ts +1 -0
  245. package/dist/private/node/ui/components/SelectPrompt.test.js +74 -0
  246. package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -0
  247. package/dist/private/node/ui/components/Table.d.ts +8 -0
  248. package/dist/private/node/ui/components/Table.js +17 -0
  249. package/dist/private/node/ui/components/Table.js.map +1 -0
  250. package/dist/private/node/ui/components/Tasks.d.ts +10 -0
  251. package/dist/private/node/ui/components/Tasks.js +27 -0
  252. package/dist/private/node/ui/components/Tasks.js.map +1 -0
  253. package/dist/private/node/ui/components/Tasks.test.d.ts +1 -0
  254. package/dist/private/node/ui/components/Tasks.test.js +50 -0
  255. package/dist/private/node/ui/components/Tasks.test.js.map +1 -0
  256. package/dist/private/node/ui/components/TextAnimation.d.ts +9 -0
  257. package/dist/private/node/ui/components/TextAnimation.js +35 -0
  258. package/dist/private/node/ui/components/TextAnimation.js.map +1 -0
  259. package/dist/private/node/ui/components/TextInput.d.ts +9 -0
  260. package/dist/private/node/ui/components/TextInput.js +74 -0
  261. package/dist/private/node/ui/components/TextInput.js.map +1 -0
  262. package/dist/private/node/ui/components/TextInput.test.d.ts +1 -0
  263. package/dist/private/node/ui/components/TextInput.test.js +139 -0
  264. package/dist/private/node/ui/components/TextInput.test.js.map +1 -0
  265. package/dist/private/node/ui/components/TextPrompt.d.ts +8 -0
  266. package/dist/private/node/ui/components/TextPrompt.js +52 -0
  267. package/dist/private/node/ui/components/TextPrompt.js.map +1 -0
  268. package/dist/private/node/ui/components/TextPrompt.test.d.ts +1 -0
  269. package/dist/private/node/ui/components/TextPrompt.test.js +68 -0
  270. package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -0
  271. package/dist/private/node/ui/components/TokenizedText.d.ts +36 -0
  272. package/dist/private/node/ui/components/TokenizedText.js +70 -0
  273. package/dist/private/node/ui/components/TokenizedText.js.map +1 -0
  274. package/dist/private/node/ui/components/TokenizedText.test.d.ts +1 -0
  275. package/dist/private/node/ui/components/TokenizedText.test.js +44 -0
  276. package/dist/private/node/ui/components/TokenizedText.test.js.map +1 -0
  277. package/dist/private/node/ui/components/UserInput.d.ts +10 -0
  278. package/dist/private/node/ui/components/UserInput.js +11 -0
  279. package/dist/private/node/ui/components/UserInput.js.map +1 -0
  280. package/dist/private/node/ui/components/UserInput.test.d.ts +1 -0
  281. package/dist/private/node/ui/components/UserInput.test.js +11 -0
  282. package/dist/private/node/ui/components/UserInput.test.js.map +1 -0
  283. package/dist/private/node/ui/hooks/use-async-and-unmount.d.ts +6 -0
  284. package/dist/private/node/ui/hooks/use-async-and-unmount.js +17 -0
  285. package/dist/private/node/ui/hooks/use-async-and-unmount.js.map +1 -0
  286. package/dist/private/node/ui/hooks/use-layout.d.ts +6 -0
  287. package/dist/private/node/ui/hooks/use-layout.js +30 -0
  288. package/dist/private/node/ui/hooks/use-layout.js.map +1 -0
  289. package/dist/private/node/ui.d.ts +23 -0
  290. package/dist/private/node/ui.js +53 -0
  291. package/dist/private/node/ui.js.map +1 -0
  292. package/dist/public/common/array.d.ts +37 -0
  293. package/dist/public/common/array.js +51 -0
  294. package/dist/public/common/array.js.map +1 -0
  295. package/dist/public/common/collection.d.ts +23 -0
  296. package/dist/public/common/collection.js +29 -0
  297. package/dist/public/common/collection.js.map +1 -0
  298. package/dist/public/common/function.d.ts +30 -0
  299. package/dist/public/common/function.js +40 -0
  300. package/dist/public/common/function.js.map +1 -0
  301. package/dist/public/common/lang.d.ts +16 -0
  302. package/dist/public/common/lang.js +22 -0
  303. package/dist/public/common/lang.js.map +1 -0
  304. package/dist/public/common/object.d.ts +32 -0
  305. package/dist/public/common/object.js +45 -0
  306. package/dist/public/common/object.js.map +1 -0
  307. package/dist/public/common/string.d.ts +6 -0
  308. package/dist/public/common/string.js +109 -0
  309. package/dist/public/common/string.js.map +1 -0
  310. package/dist/public/common/url.d.ts +7 -0
  311. package/dist/public/common/url.js +17 -0
  312. package/dist/public/common/url.js.map +1 -0
  313. package/dist/public/node/abort.d.ts +16 -0
  314. package/dist/public/node/abort.js +17 -0
  315. package/dist/public/node/abort.js.map +1 -0
  316. package/dist/public/node/analytics.d.ts +13 -0
  317. package/dist/public/node/analytics.js +82 -0
  318. package/dist/public/node/analytics.js.map +1 -0
  319. package/dist/public/node/archiver.d.ts +9 -0
  320. package/dist/public/node/archiver.js +34 -0
  321. package/dist/public/node/archiver.js.map +1 -0
  322. package/dist/public/node/base-command.d.ts +26 -0
  323. package/dist/public/node/base-command.js +172 -0
  324. package/dist/public/node/base-command.js.map +1 -0
  325. package/dist/public/node/checksum.d.ts +20 -0
  326. package/dist/public/node/checksum.js +32 -0
  327. package/dist/public/node/checksum.js.map +1 -0
  328. package/dist/public/node/cli.d.ts +29 -0
  329. package/dist/public/node/cli.js +106 -0
  330. package/dist/public/node/cli.js.map +1 -0
  331. package/dist/public/node/colors.d.ts +2 -0
  332. package/dist/public/node/colors.js +3 -0
  333. package/dist/public/node/colors.js.map +1 -0
  334. package/dist/public/node/dot-env.d.ts +42 -0
  335. package/dist/public/node/dot-env.js +67 -0
  336. package/dist/public/node/dot-env.js.map +1 -0
  337. package/dist/public/node/error-handler.d.ts +41 -0
  338. package/dist/public/node/error-handler.js +198 -0
  339. package/dist/public/node/error-handler.js.map +1 -0
  340. package/dist/public/node/error.d.ts +4 -0
  341. package/dist/public/node/error.js +5 -0
  342. package/dist/public/node/error.js.map +1 -0
  343. package/dist/public/node/framework.d.ts +8 -0
  344. package/dist/public/node/framework.js +135 -0
  345. package/dist/public/node/framework.js.map +1 -0
  346. package/dist/public/node/fs.d.ts +17 -0
  347. package/dist/public/node/fs.js +21 -0
  348. package/dist/public/node/fs.js.map +1 -0
  349. package/dist/public/node/github.d.ts +50 -0
  350. package/dist/public/node/github.js +71 -0
  351. package/dist/public/node/github.js.map +1 -0
  352. package/dist/public/node/hooks/postrun.d.ts +2 -0
  353. package/dist/public/node/hooks/postrun.js +9 -0
  354. package/dist/public/node/hooks/postrun.js.map +1 -0
  355. package/dist/public/node/hooks/prerun.d.ts +12 -0
  356. package/dist/public/node/hooks/prerun.js +66 -0
  357. package/dist/public/node/hooks/prerun.js.map +1 -0
  358. package/dist/public/node/node-package-manager.d.ts +243 -0
  359. package/dist/public/node/node-package-manager.js +369 -0
  360. package/dist/public/node/node-package-manager.js.map +1 -0
  361. package/dist/public/node/os.d.ts +16 -0
  362. package/dist/public/node/os.js +77 -0
  363. package/dist/public/node/os.js.map +1 -0
  364. package/dist/public/node/plugins/tunnel.d.ts +47 -0
  365. package/dist/public/node/plugins/tunnel.js +19 -0
  366. package/dist/public/node/plugins/tunnel.js.map +1 -0
  367. package/dist/public/node/presets.d.ts +8 -0
  368. package/dist/public/node/presets.js +26 -0
  369. package/dist/public/node/presets.js.map +1 -0
  370. package/dist/public/node/result.d.ts +94 -0
  371. package/dist/public/node/result.js +134 -0
  372. package/dist/public/node/result.js.map +1 -0
  373. package/dist/public/node/ruby.d.ts +38 -0
  374. package/dist/public/node/ruby.js +234 -0
  375. package/dist/public/node/ruby.js.map +1 -0
  376. package/dist/public/node/semver.d.ts +3 -0
  377. package/dist/public/node/semver.js +6 -0
  378. package/dist/public/node/semver.js.map +1 -0
  379. package/dist/public/node/tcp.d.ts +5 -0
  380. package/dist/public/node/tcp.js +35 -0
  381. package/dist/public/node/tcp.js.map +1 -0
  382. package/dist/public/node/ui.d.ts +184 -0
  383. package/dist/public/node/ui.js +203 -0
  384. package/dist/public/node/ui.js.map +1 -0
  385. package/dist/schema.d.ts +1 -0
  386. package/dist/schema.js +2 -0
  387. package/dist/schema.js.map +1 -0
  388. package/dist/secure-store.d.ts +19 -0
  389. package/dist/secure-store.js +63 -0
  390. package/dist/secure-store.js.map +1 -0
  391. package/dist/session/authorize.d.ts +7 -0
  392. package/dist/session/authorize.js +52 -0
  393. package/dist/session/authorize.js.map +1 -0
  394. package/dist/session/device-authorization.d.ts +32 -0
  395. package/dist/session/device-authorization.js +92 -0
  396. package/dist/session/device-authorization.js.map +1 -0
  397. package/dist/session/exchange.d.ts +48 -0
  398. package/dist/session/exchange.js +159 -0
  399. package/dist/session/exchange.js.map +1 -0
  400. package/dist/session/identity.d.ts +3 -0
  401. package/dist/session/identity.js +58 -0
  402. package/dist/session/identity.js.map +1 -0
  403. package/dist/session/post-auth.d.ts +13 -0
  404. package/dist/session/post-auth.js +62 -0
  405. package/dist/session/post-auth.js.map +1 -0
  406. package/dist/session/redirect-listener.d.ts +34 -0
  407. package/dist/session/redirect-listener.js +106 -0
  408. package/dist/session/redirect-listener.js.map +1 -0
  409. package/dist/session/schema.d.ts +175 -0
  410. package/dist/session/schema.js +60 -0
  411. package/dist/session/schema.js.map +1 -0
  412. package/dist/session/scopes.d.ts +16 -0
  413. package/dist/session/scopes.js +53 -0
  414. package/dist/session/scopes.js.map +1 -0
  415. package/dist/session/store.d.ts +24 -0
  416. package/dist/session/store.js +89 -0
  417. package/dist/session/store.js.map +1 -0
  418. package/dist/session/token.d.ts +40 -0
  419. package/dist/session/token.js +22 -0
  420. package/dist/session/token.js.map +1 -0
  421. package/dist/session/validate.d.ts +17 -0
  422. package/dist/session/validate.js +65 -0
  423. package/dist/session/validate.js.map +1 -0
  424. package/dist/session.d.ts +96 -0
  425. package/dist/session.js +293 -0
  426. package/dist/session.js.map +1 -0
  427. package/dist/store/schema.d.ts +3 -0
  428. package/dist/store/schema.js +27 -0
  429. package/dist/store/schema.js.map +1 -0
  430. package/dist/store.d.ts +53 -0
  431. package/dist/store.js +134 -0
  432. package/dist/store.js.map +1 -0
  433. package/dist/string.d.ts +28 -0
  434. package/dist/string.js +77 -0
  435. package/dist/string.js.map +1 -0
  436. package/dist/system.d.ts +51 -0
  437. package/dist/system.js +128 -0
  438. package/dist/system.js.map +1 -0
  439. package/dist/template.d.ts +11 -0
  440. package/dist/template.js +50 -0
  441. package/dist/template.js.map +1 -0
  442. package/dist/testing/output.d.ts +10 -0
  443. package/dist/testing/output.js +16 -0
  444. package/dist/testing/output.js.map +1 -0
  445. package/dist/testing/store.d.ts +7 -0
  446. package/dist/testing/store.js +26 -0
  447. package/dist/testing/store.js.map +1 -0
  448. package/dist/testing/ui.d.ts +5 -0
  449. package/dist/testing/ui.js +23 -0
  450. package/dist/testing/ui.js.map +1 -0
  451. package/dist/toml.d.ts +3 -0
  452. package/dist/toml.js +8 -0
  453. package/dist/toml.js.map +1 -0
  454. package/dist/tsconfig.tsbuildinfo +1 -0
  455. package/dist/typing/deep-required.d.ts +12 -0
  456. package/dist/typing/deep-required.js +2 -0
  457. package/dist/typing/deep-required.js.map +1 -0
  458. package/dist/typing/overloaded-parameters.d.ts +6 -0
  459. package/dist/typing/overloaded-parameters.js +2 -0
  460. package/dist/typing/overloaded-parameters.js.map +1 -0
  461. package/dist/typing/pick-by-prefix.d.ts +12 -0
  462. package/dist/typing/pick-by-prefix.js +2 -0
  463. package/dist/typing/pick-by-prefix.js.map +1 -0
  464. package/dist/typing/simple-definitions.d.ts +4 -0
  465. package/dist/typing/simple-definitions.js +2 -0
  466. package/dist/typing/simple-definitions.js.map +1 -0
  467. package/dist/ui/executor.d.ts +14 -0
  468. package/dist/ui/executor.js +90 -0
  469. package/dist/ui/executor.js.map +1 -0
  470. package/dist/ui/inquirer/autocomplete.d.ts +11 -0
  471. package/dist/ui/inquirer/autocomplete.js +110 -0
  472. package/dist/ui/inquirer/autocomplete.js.map +1 -0
  473. package/dist/ui/inquirer/input.d.ts +16 -0
  474. package/dist/ui/inquirer/input.js +45 -0
  475. package/dist/ui/inquirer/input.js.map +1 -0
  476. package/dist/ui/inquirer/password.d.ts +7 -0
  477. package/dist/ui/inquirer/password.js +8 -0
  478. package/dist/ui/inquirer/password.js.map +1 -0
  479. package/dist/ui/inquirer/select.d.ts +14 -0
  480. package/dist/ui/inquirer/select.js +26 -0
  481. package/dist/ui/inquirer/select.js.map +1 -0
  482. package/dist/ui.d.ts +54 -0
  483. package/dist/ui.js +128 -0
  484. package/dist/ui.js.map +1 -0
  485. package/dist/vscode.d.ts +8 -0
  486. package/dist/vscode.js +36 -0
  487. package/dist/vscode.js.map +1 -0
  488. package/package.json +177 -0
@@ -0,0 +1,159 @@
1
+ import { applicationId, clientId as getIdentityClientId } from './identity.js';
2
+ import { identity as identityFqdn } from '../environment/fqdn.js';
3
+ import { shopifyFetch } from '../http.js';
4
+ import { err, ok } from '../public/node/result.js';
5
+ import { AbortError } from '../public/node/error.js';
6
+ import { ExtendableError } from '../error.js';
7
+ export class InvalidGrantError extends ExtendableError {
8
+ }
9
+ export class InvalidRequestError extends ExtendableError {
10
+ }
11
+ /**
12
+ * Given a valid authorization code, request an identity access token.
13
+ * This token can then be used to get API specific tokens.
14
+ * @param codeData - code and codeVerifier from the authorize endpoint
15
+ * @returns An instance with the identity access tokens.
16
+ */
17
+ export async function exchangeCodeForAccessToken(codeData) {
18
+ const clientId = await getIdentityClientId();
19
+ const params = {
20
+ grant_type: 'authorization_code',
21
+ code: codeData.code,
22
+ redirect_uri: 'http://127.0.0.1:3456',
23
+ client_id: clientId,
24
+ code_verifier: codeData.codeVerifier,
25
+ };
26
+ const tokenResult = await tokenRequest(params);
27
+ const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug();
28
+ return buildIdentityToken(value);
29
+ }
30
+ /**
31
+ * Given an identity token, request an application token.
32
+ * @param identityToken - access token obtained in a previous step
33
+ * @param store - the store to use, only needed for admin API
34
+ * @returns An array with the application access tokens.
35
+ */
36
+ export async function exchangeAccessForApplicationTokens(identityToken, scopes, store) {
37
+ const token = identityToken.accessToken;
38
+ const [partners, storefront] = await Promise.all([
39
+ requestAppToken('partners', token, scopes.partners),
40
+ requestAppToken('storefront-renderer', token, scopes.storefront),
41
+ ]);
42
+ const result = {
43
+ ...partners,
44
+ ...storefront,
45
+ };
46
+ if (store) {
47
+ const admin = await requestAppToken('admin', token, scopes.admin, store);
48
+ Object.assign(result, admin);
49
+ }
50
+ return result;
51
+ }
52
+ /**
53
+ * Given an expired access token, refresh it to get a new one.
54
+ */
55
+ export async function refreshAccessToken(currentToken) {
56
+ const clientId = getIdentityClientId();
57
+ const params = {
58
+ grant_type: 'refresh_token',
59
+ access_token: currentToken.accessToken,
60
+ refresh_token: currentToken.refreshToken,
61
+ client_id: clientId,
62
+ };
63
+ const tokenResult = await tokenRequest(params);
64
+ const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug();
65
+ return buildIdentityToken(value);
66
+ }
67
+ /**
68
+ * Given a custom CLI token passed as ENV variable, request a valid partners API token
69
+ * This token does not accept extra scopes, just the cli one.
70
+ * @param token - The CLI token passed as ENV variable
71
+ * @returns An instance with the application access tokens.
72
+ */
73
+ export async function exchangeCustomPartnerToken(token) {
74
+ const appId = applicationId('partners');
75
+ const newToken = await requestAppToken('partners', token, ['https://api.shopify.com/auth/partners.app.cli.access']);
76
+ return newToken[appId];
77
+ }
78
+ /**
79
+ * Given a deviceCode obtained after starting a device identity flow, request an identity token.
80
+ * @param deviceCode - The device code obtained after starting a device identity flow
81
+ * @param scopes - The scopes to request
82
+ * @returns An instance with the identity access tokens.
83
+ */
84
+ export async function exchangeDeviceCodeForAccessToken(deviceCode) {
85
+ const clientId = await getIdentityClientId();
86
+ const params = {
87
+ grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
88
+ device_code: deviceCode,
89
+ client_id: clientId,
90
+ };
91
+ const tokenResult = await tokenRequest(params);
92
+ if (tokenResult.isErr()) {
93
+ return err(tokenResult.error);
94
+ }
95
+ const identityToken = buildIdentityToken(tokenResult.value);
96
+ return ok(identityToken);
97
+ }
98
+ async function requestAppToken(api, token, scopes = [], store) {
99
+ const appId = applicationId(api);
100
+ const clientId = await getIdentityClientId();
101
+ const params = {
102
+ grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
103
+ requested_token_type: 'urn:ietf:params:oauth:token-type:access_token',
104
+ subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',
105
+ client_id: clientId,
106
+ audience: appId,
107
+ scope: scopes.join(' '),
108
+ subject_token: token,
109
+ ...(api === 'admin' && { destination: `https://${store}/admin` }),
110
+ };
111
+ let identifier = appId;
112
+ if (api === 'admin' && store) {
113
+ identifier = `${store}-${appId}`;
114
+ }
115
+ const tokenResult = await tokenRequest(params);
116
+ const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug();
117
+ const appToken = await buildApplicationToken(value);
118
+ return { [identifier]: appToken };
119
+ }
120
+ function tokenRequestErrorHandler(error) {
121
+ if (error === 'invalid_grant') {
122
+ // There's an scenario when Identity returns "invalid_grant" when trying to refresh the token
123
+ // using a valid refresh token. When that happens, we take the user through the authentication flow.
124
+ return new InvalidGrantError();
125
+ }
126
+ if (error === 'invalid_request') {
127
+ // There's an scenario when Identity returns "invalid_request" when exchanging an identity token.
128
+ // This means the token is invalid. We clear the session and throw an error to let the caller know.
129
+ return new InvalidRequestError();
130
+ }
131
+ return new AbortError(error);
132
+ }
133
+ async function tokenRequest(params) {
134
+ const fqdn = await identityFqdn();
135
+ const url = new URL(`https://${fqdn}/oauth/token`);
136
+ url.search = new URLSearchParams(Object.entries(params)).toString();
137
+ const res = await shopifyFetch(url.href, { method: 'POST' });
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ const payload = await res.json();
140
+ if (res.ok)
141
+ return ok(payload);
142
+ return err(payload.error);
143
+ }
144
+ function buildIdentityToken(result) {
145
+ return {
146
+ accessToken: result.access_token,
147
+ refreshToken: result.refresh_token,
148
+ expiresAt: new Date(Date.now() + result.expires_in * 1000),
149
+ scopes: result.scope.split(' '),
150
+ };
151
+ }
152
+ function buildApplicationToken(result) {
153
+ return {
154
+ accessToken: result.access_token,
155
+ expiresAt: new Date(Date.now() + result.expires_in * 1000),
156
+ scopes: result.scope.split(' '),
157
+ };
158
+ }
159
+ //# sourceMappingURL=exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../src/session/exchange.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAE,QAAQ,IAAI,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAG5E,OAAO,EAAC,QAAQ,IAAI,YAAY,EAAC,MAAM,wBAAwB,CAAA;AAC/D,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AACvC,OAAO,EAAC,GAAG,EAAE,EAAE,EAAS,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAA;AAE3C,MAAM,OAAO,iBAAkB,SAAQ,eAAe;CAAG;AACzD,MAAM,OAAO,mBAAoB,SAAQ,eAAe;CAAG;AAO3D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,QAAwB;IACvE,MAAM,QAAQ,GAAG,MAAM,mBAAmB,EAAE,CAAA;IAC5C,MAAM,MAAM,GAAG;QACb,UAAU,EAAE,oBAAoB;QAChC,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,YAAY,EAAE,uBAAuB;QACrC,SAAS,EAAE,QAAQ;QACnB,aAAa,EAAE,QAAQ,CAAC,YAAY;KACrC,CAAA;IAED,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC,UAAU,EAAE,CAAA;IACzE,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAA;AACl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G,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,OAAO,CAAC,CAAA;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC;AAED,SAAS,kBAAkB,CAAC,MAA0B;IACpD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,YAAY,EAAE,MAAM,CAAC,aAAa;QAClC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,MAA0B;IACvD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {ApplicationToken, IdentityToken} from './schema.js'\nimport {applicationId, clientId as getIdentityClientId} from './identity.js'\nimport {CodeAuthResult} from './authorize.js'\nimport {API} from '../network/api.js'\nimport {identity as identityFqdn} from '../environment/fqdn.js'\nimport {shopifyFetch} from '../http.js'\nimport {err, ok, Result} from '../public/node/result.js'\nimport {AbortError} from '../public/node/error.js'\nimport {ExtendableError} from '../error.js'\n\nexport class InvalidGrantError extends ExtendableError {}\nexport class InvalidRequestError extends ExtendableError {}\n\nexport interface ExchangeScopes {\n admin: string[]\n partners: string[]\n storefront: string[]\n}\n/**\n * Given a valid authorization code, request an identity access token.\n * This token can then be used to get API specific tokens.\n * @param codeData - code and codeVerifier from the authorize endpoint\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeCodeForAccessToken(codeData: CodeAuthResult): Promise<IdentityToken> {\n const clientId = await getIdentityClientId()\n const params = {\n grant_type: 'authorization_code',\n code: codeData.code,\n redirect_uri: 'http://127.0.0.1:3456',\n client_id: clientId,\n code_verifier: codeData.codeVerifier,\n }\n\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value)\n}\n\n/**\n * Given an identity token, request an application token.\n * @param identityToken - access token obtained in a previous step\n * @param store - the store to use, only needed for admin API\n * @returns An array with the application access tokens.\n */\nexport async function exchangeAccessForApplicationTokens(\n identityToken: IdentityToken,\n scopes: ExchangeScopes,\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const token = identityToken.accessToken\n\n const [partners, storefront] = await Promise.all([\n requestAppToken('partners', token, scopes.partners),\n requestAppToken('storefront-renderer', token, scopes.storefront),\n ])\n\n const result = {\n ...partners,\n ...storefront,\n }\n\n if (store) {\n const admin = await requestAppToken('admin', token, scopes.admin, store)\n Object.assign(result, admin)\n }\n return result\n}\n\n/**\n * Given an expired access token, refresh it to get a new one.\n */\nexport async function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken> {\n const clientId = getIdentityClientId()\n const params = {\n grant_type: 'refresh_token',\n access_token: currentToken.accessToken,\n refresh_token: currentToken.refreshToken,\n client_id: clientId,\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value)\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid partners API token\n * This token does not accept extra scopes, just the cli one.\n * @param token - The CLI token passed as ENV variable\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCustomPartnerToken(token: string): Promise<ApplicationToken> {\n const appId = applicationId('partners')\n const newToken = await requestAppToken('partners', token, ['https://api.shopify.com/auth/partners.app.cli.access'])\n return newToken[appId]!\n}\n\nexport type IdentityDeviceError =\n | 'authorization_pending'\n | 'access_denied'\n | 'expired_token'\n | 'slow_down'\n | 'unknown_failure'\n\n/**\n * Given a deviceCode obtained after starting a device identity flow, request an identity token.\n * @param deviceCode - The device code obtained after starting a device identity flow\n * @param scopes - The scopes to request\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeDeviceCodeForAccessToken(\n deviceCode: string,\n): Promise<Result<IdentityToken, IdentityDeviceError>> {\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:device_code',\n device_code: deviceCode,\n client_id: clientId,\n }\n\n const tokenResult = await tokenRequest(params)\n if (tokenResult.isErr()) {\n return err(tokenResult.error as IdentityDeviceError)\n }\n const identityToken = buildIdentityToken(tokenResult.value)\n return ok(identityToken)\n}\n\nasync function requestAppToken(\n api: API,\n token: string,\n scopes: string[] = [],\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const appId = applicationId(api)\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',\n requested_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n client_id: clientId,\n audience: appId,\n scope: scopes.join(' '),\n subject_token: token,\n ...(api === 'admin' && {destination: `https://${store}/admin`}),\n }\n\n let identifier = appId\n if (api === 'admin' && store) {\n identifier = `${store}-${appId}`\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n const appToken = await buildApplicationToken(value)\n return {[identifier]: appToken}\n}\n\ninterface TokenRequestResult {\n access_token: string\n expires_in: number\n refresh_token: string\n scope: string\n}\n\nfunction tokenRequestErrorHandler(error: string) {\n if (error === 'invalid_grant') {\n // There's an scenario when Identity returns \"invalid_grant\" when trying to refresh the token\n // using a valid refresh token. When that happens, we take the user through the authentication flow.\n return new InvalidGrantError()\n }\n if (error === 'invalid_request') {\n // There's an scenario when Identity returns \"invalid_request\" when exchanging an identity token.\n // This means the token is invalid. We clear the session and throw an error to let the caller know.\n return new InvalidRequestError()\n }\n return new AbortError(error)\n}\n\nasync function tokenRequest(params: {[key: string]: string}): Promise<Result<TokenRequestResult, string>> {\n const fqdn = await identityFqdn()\n const url = new URL(`https://${fqdn}/oauth/token`)\n url.search = new URLSearchParams(Object.entries(params)).toString()\n const res = await shopifyFetch(url.href, {method: 'POST'})\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const payload: any = await res.json()\n\n if (res.ok) return ok(payload)\n return err(payload.error)\n}\n\nfunction buildIdentityToken(result: TokenRequestResult): IdentityToken {\n return {\n accessToken: result.access_token,\n refreshToken: result.refresh_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n\nfunction buildApplicationToken(result: TokenRequestResult): ApplicationToken {\n return {\n accessToken: result.access_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { API } from '../network/api.js';
2
+ export declare function clientId(): string;
3
+ export declare function applicationId(api: API): string;
@@ -0,0 +1,58 @@
1
+ import { Bug } from '../error.js';
2
+ import { Environment } from '../network/service.js';
3
+ import { serviceEnvironment } from '../environment/service.js';
4
+ export function clientId() {
5
+ const environment = serviceEnvironment();
6
+ if (environment === Environment.Local) {
7
+ return 'e5380e02-312a-7408-5718-e07017e9cf52';
8
+ }
9
+ else if (environment === Environment.Production) {
10
+ return 'fbdb2649-e327-4907-8f67-908d24cfd7e3';
11
+ }
12
+ else {
13
+ return 'e5380e02-312a-7408-5718-e07017e9cf52';
14
+ }
15
+ }
16
+ export function applicationId(api) {
17
+ switch (api) {
18
+ case 'admin': {
19
+ const environment = serviceEnvironment();
20
+ if (environment === Environment.Local) {
21
+ return 'e92482cebb9bfb9fb5a0199cc770fde3de6c8d16b798ee73e36c9d815e070e52';
22
+ }
23
+ else if (environment === Environment.Production) {
24
+ return '7ee65a63608843c577db8b23c4d7316ea0a01bd2f7594f8a9c06ea668c1b775c';
25
+ }
26
+ else {
27
+ return 'e92482cebb9bfb9fb5a0199cc770fde3de6c8d16b798ee73e36c9d815e070e52';
28
+ }
29
+ }
30
+ case 'partners': {
31
+ const environment = serviceEnvironment();
32
+ if (environment === Environment.Local) {
33
+ return 'df89d73339ac3c6c5f0a98d9ca93260763e384d51d6038da129889c308973978';
34
+ }
35
+ else if (environment === Environment.Production) {
36
+ return '271e16d403dfa18082ffb3d197bd2b5f4479c3fc32736d69296829cbb28d41a6';
37
+ }
38
+ else {
39
+ return 'df89d73339ac3c6c5f0a98d9ca93260763e384d51d6038da129889c308973978';
40
+ }
41
+ }
42
+ case 'storefront-renderer': {
43
+ const environment = serviceEnvironment();
44
+ if (environment === Environment.Local) {
45
+ return '46f603de-894f-488d-9471-5b721280ff49';
46
+ }
47
+ else if (environment === Environment.Production) {
48
+ return 'ee139b3d-5861-4d45-b387-1bc3ada7811c';
49
+ }
50
+ else {
51
+ return '46f603de-894f-488d-9471-5b721280ff49';
52
+ }
53
+ }
54
+ default:
55
+ throw new Bug(`Application id for API of type: ${api}`);
56
+ }
57
+ }
58
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/session/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,aAAa,CAAA;AAC/B,OAAO,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAA;AAEjD,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAA;AAE5D,MAAM,UAAU,QAAQ;IACtB,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;IACxC,IAAI,WAAW,KAAK,WAAW,CAAC,KAAK,EAAE;QACrC,OAAO,sCAAsC,CAAA;KAC9C;SAAM,IAAI,WAAW,KAAK,WAAW,CAAC,UAAU,EAAE;QACjD,OAAO,sCAAsC,CAAA;KAC9C;SAAM;QACL,OAAO,sCAAsC,CAAA;KAC9C;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAQ;IACpC,QAAQ,GAAG,EAAE;QACX,KAAK,OAAO,CAAC,CAAC;YACZ,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;YACxC,IAAI,WAAW,KAAK,WAAW,CAAC,KAAK,EAAE;gBACrC,OAAO,kEAAkE,CAAA;aAC1E;iBAAM,IAAI,WAAW,KAAK,WAAW,CAAC,UAAU,EAAE;gBACjD,OAAO,kEAAkE,CAAA;aAC1E;iBAAM;gBACL,OAAO,kEAAkE,CAAA;aAC1E;SACF;QACD,KAAK,UAAU,CAAC,CAAC;YACf,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;YACxC,IAAI,WAAW,KAAK,WAAW,CAAC,KAAK,EAAE;gBACrC,OAAO,kEAAkE,CAAA;aAC1E;iBAAM,IAAI,WAAW,KAAK,WAAW,CAAC,UAAU,EAAE;gBACjD,OAAO,kEAAkE,CAAA;aAC1E;iBAAM;gBACL,OAAO,kEAAkE,CAAA;aAC1E;SACF;QACD,KAAK,qBAAqB,CAAC,CAAC;YAC1B,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;YACxC,IAAI,WAAW,KAAK,WAAW,CAAC,KAAK,EAAE;gBACrC,OAAO,sCAAsC,CAAA;aAC9C;iBAAM,IAAI,WAAW,KAAK,WAAW,CAAC,UAAU,EAAE;gBACjD,OAAO,sCAAsC,CAAA;aAC9C;iBAAM;gBACL,OAAO,sCAAsC,CAAA;aAC9C;SACF;QACD;YACE,MAAM,IAAI,GAAG,CAAC,mCAAmC,GAAG,EAAE,CAAC,CAAA;KAC1D;AACH,CAAC","sourcesContent":["import {Bug} from '../error.js'\nimport {Environment} from '../network/service.js'\nimport {API} from '../network/api.js'\nimport {serviceEnvironment} from '../environment/service.js'\n\nexport function clientId(): string {\n const environment = serviceEnvironment()\n if (environment === Environment.Local) {\n return 'e5380e02-312a-7408-5718-e07017e9cf52'\n } else if (environment === Environment.Production) {\n return 'fbdb2649-e327-4907-8f67-908d24cfd7e3'\n } else {\n return 'e5380e02-312a-7408-5718-e07017e9cf52'\n }\n}\n\nexport function applicationId(api: API): string {\n switch (api) {\n case 'admin': {\n const environment = serviceEnvironment()\n if (environment === Environment.Local) {\n return 'e92482cebb9bfb9fb5a0199cc770fde3de6c8d16b798ee73e36c9d815e070e52'\n } else if (environment === Environment.Production) {\n return '7ee65a63608843c577db8b23c4d7316ea0a01bd2f7594f8a9c06ea668c1b775c'\n } else {\n return 'e92482cebb9bfb9fb5a0199cc770fde3de6c8d16b798ee73e36c9d815e070e52'\n }\n }\n case 'partners': {\n const environment = serviceEnvironment()\n if (environment === Environment.Local) {\n return 'df89d73339ac3c6c5f0a98d9ca93260763e384d51d6038da129889c308973978'\n } else if (environment === Environment.Production) {\n return '271e16d403dfa18082ffb3d197bd2b5f4479c3fc32736d69296829cbb28d41a6'\n } else {\n return 'df89d73339ac3c6c5f0a98d9ca93260763e384d51d6038da129889c308973978'\n }\n }\n case 'storefront-renderer': {\n const environment = serviceEnvironment()\n if (environment === Environment.Local) {\n return '46f603de-894f-488d-9471-5b721280ff49'\n } else if (environment === Environment.Production) {\n return 'ee139b3d-5861-4d45-b387-1bc3ada7811c'\n } else {\n return '46f603de-894f-488d-9471-5b721280ff49'\n }\n }\n default:\n throw new Bug(`Application id for API of type: ${api}`)\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { Bug } from '../error.js';
2
+ export declare const getEmptyUrlHTML: () => Promise<string>;
3
+ export declare const getAuthErrorHTML: () => Promise<string>;
4
+ export declare const getMissingCodeHTML: () => Promise<string>;
5
+ export declare const getMissingStateHTML: () => Promise<string>;
6
+ export declare const getSuccessHTML: () => Promise<string>;
7
+ export declare const getStylesheet: () => Promise<string>;
8
+ export declare const getFavicon: () => Promise<string>;
9
+ export declare const EmptyUrlString = "We received the authentication redirect but the URL is empty.";
10
+ export declare const AuthErrorString = "There was an issue while trying to authenticate.";
11
+ export declare const MissingCodeString = "The authentication can't continue because the redirect doesn't include the code.";
12
+ export declare const MissingStateString = "The authentication can't continue because the redirect doesn't include the state.";
13
+ export declare const RedirectPageAssetNotFoundError: () => Bug;
@@ -0,0 +1,62 @@
1
+ import { findUp, moduleDirectory } from '../path.js';
2
+ import { read } from '../file.js';
3
+ import { Bug } from '../error.js';
4
+ const HTMLFileNames = [
5
+ 'empty-url.html',
6
+ 'auth-error.html',
7
+ 'missing-code.html',
8
+ 'missing-state.html',
9
+ 'success.html',
10
+ ];
11
+ const StylesheetFilename = 'style.css';
12
+ const FaviconFileName = 'favicon.svg';
13
+ /**
14
+ * Finds the full path of the given file-name from the assets folder.
15
+ *
16
+ * @param fileName - The name of the file to look for.
17
+ * @returns The full path of the file, or null if not found.
18
+ */
19
+ const getFilePath = async (fileName) => {
20
+ const filePath = await findUp(`assets/${fileName}`, {
21
+ type: 'file',
22
+ cwd: moduleDirectory(import.meta.url),
23
+ });
24
+ if (!filePath) {
25
+ throw RedirectPageAssetNotFoundError();
26
+ }
27
+ return filePath;
28
+ };
29
+ export const getEmptyUrlHTML = async () => {
30
+ const filePath = await getFilePath(HTMLFileNames[0]);
31
+ return read(filePath);
32
+ };
33
+ export const getAuthErrorHTML = async () => {
34
+ const filePath = await getFilePath(HTMLFileNames[1]);
35
+ return read(filePath);
36
+ };
37
+ export const getMissingCodeHTML = async () => {
38
+ const filePath = await getFilePath(HTMLFileNames[2]);
39
+ return read(filePath);
40
+ };
41
+ export const getMissingStateHTML = async () => {
42
+ const filePath = await getFilePath(HTMLFileNames[3]);
43
+ return read(filePath);
44
+ };
45
+ export const getSuccessHTML = async () => {
46
+ const filePath = await getFilePath(HTMLFileNames[4]);
47
+ return read(filePath);
48
+ };
49
+ export const getStylesheet = async () => {
50
+ const filePath = await getFilePath(StylesheetFilename);
51
+ return read(filePath);
52
+ };
53
+ export const getFavicon = async () => {
54
+ const filePath = await getFilePath(FaviconFileName);
55
+ return read(filePath);
56
+ };
57
+ export const EmptyUrlString = 'We received the authentication redirect but the URL is empty.';
58
+ export const AuthErrorString = 'There was an issue while trying to authenticate.';
59
+ export const MissingCodeString = "The authentication can't continue because the redirect doesn't include the code.";
60
+ export const MissingStateString = "The authentication can't continue because the redirect doesn't include the state.";
61
+ export const RedirectPageAssetNotFoundError = () => new Bug(`Redirect page asset not found`);
62
+ //# sourceMappingURL=post-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-auth.js","sourceRoot":"","sources":["../../src/session/post-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,eAAe,EAAC,MAAM,YAAY,CAAA;AAClD,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAA;AAC/B,OAAO,EAAC,GAAG,EAAC,MAAM,aAAa,CAAA;AAE/B,MAAM,aAAa,GAAG;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,cAAc;CACN,CAAA;AACV,MAAM,kBAAkB,GAAG,WAAW,CAAA;AACtC,MAAM,eAAe,GAAG,aAAa,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,GAAG,KAAK,EAAE,QAAgB,EAAmB,EAAE;IAC9D,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,QAAQ,EAAE,EAAE;QAClD,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;KACtC,CAAC,CAAA;IACF,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,8BAA8B,EAAE,CAAA;KACvC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,IAAqB,EAAE;IACzD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,IAAqB,EAAE;IAC1D,MAAM,QAAQ,GAAG,MAAM,WAAW,CA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AAkB,GAAG,mFAAmF,CAAA;AAErH,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,+BAA+B,CAAC,CAAA","sourcesContent":["import {findUp, moduleDirectory} from '../path.js'\nimport {read} from '../file.js'\nimport {Bug} from '../error.js'\n\nconst HTMLFileNames = [\n 'empty-url.html',\n 'auth-error.html',\n 'missing-code.html',\n 'missing-state.html',\n 'success.html',\n] as const\nconst StylesheetFilename = 'style.css'\nconst FaviconFileName = 'favicon.svg'\n\n/**\n * Finds the full path of the given file-name from the assets folder.\n *\n * @param fileName - The name of the file to look for.\n * @returns The full path of the file, or null if not found.\n */\nconst getFilePath = async (fileName: string): Promise<string> => {\n const filePath = await findUp(`assets/${fileName}`, {\n type: 'file',\n cwd: moduleDirectory(import.meta.url),\n })\n if (!filePath) {\n throw RedirectPageAssetNotFoundError()\n }\n return filePath\n}\n\nexport const getEmptyUrlHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[0])\n return read(filePath)\n}\n\nexport const getAuthErrorHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[1])\n return read(filePath)\n}\n\nexport const getMissingCodeHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[2])\n return read(filePath)\n}\n\nexport const getMissingStateHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[3])\n return read(filePath)\n}\n\nexport const getSuccessHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[4])\n return read(filePath)\n}\n\nexport const getStylesheet = async (): Promise<string> => {\n const filePath = await getFilePath(StylesheetFilename)\n return read(filePath)\n}\n\nexport const getFavicon = async (): Promise<string> => {\n const filePath = await getFilePath(FaviconFileName)\n return read(filePath)\n}\n\nexport const EmptyUrlString = 'We received the authentication redirect but the URL is empty.'\n\nexport const AuthErrorString = 'There was an issue while trying to authenticate.'\n\nexport const MissingCodeString = \"The authentication can't continue because the redirect doesn't include the code.\"\n\nexport const MissingStateString = \"The authentication can't continue because the redirect doesn't include the state.\"\n\nexport const RedirectPageAssetNotFoundError = () => new Bug(`Redirect page asset not found`)\n"]}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * It represents the result of a redirect.
3
+ */
4
+ declare type RedirectCallback = (error: Error | undefined, state: string | undefined, code: string | undefined) => void;
5
+ /**
6
+ * Defines the interface of the options that
7
+ * are used to instantiate a redirect listener.
8
+ */
9
+ interface RedirectListenerOptions {
10
+ host: string;
11
+ port: number;
12
+ callback: RedirectCallback;
13
+ }
14
+ /**
15
+ * When the authentication completes, Identity redirects
16
+ * the user to a URL. In the case of the CLI, the redirect
17
+ * is to localhost passing some parameters that are necessary
18
+ * to continue the authentication. Because of that, we need
19
+ * an HTTP server that runs and listens to the request.
20
+ */
21
+ export declare class RedirectListener {
22
+ private static createServer;
23
+ port: number;
24
+ host: string;
25
+ server: ReturnType<typeof RedirectListener.createServer>;
26
+ constructor(options: RedirectListenerOptions);
27
+ start(): void;
28
+ stop(): Promise<void>;
29
+ }
30
+ export declare function listenRedirect(host: string, port: number, url: string): Promise<{
31
+ code: string;
32
+ state: string;
33
+ }>;
34
+ export {};
@@ -0,0 +1,106 @@
1
+ import { getFavicon, getStylesheet, getEmptyUrlHTML, getAuthErrorHTML, getMissingCodeHTML, getMissingStateHTML, getSuccessHTML, EmptyUrlString, MissingCodeString, MissingStateString, } from './post-auth.js';
2
+ import { Abort, Bug } from '../error.js';
3
+ import { content, info, token } from '../output.js';
4
+ import { createApp } from 'h3';
5
+ import url from 'url';
6
+ import { createServer } from 'http';
7
+ const ResponseTimeoutSeconds = 10;
8
+ const ServerStopDelaySeconds = 0.5;
9
+ /**
10
+ * When the authentication completes, Identity redirects
11
+ * the user to a URL. In the case of the CLI, the redirect
12
+ * is to localhost passing some parameters that are necessary
13
+ * to continue the authentication. Because of that, we need
14
+ * an HTTP server that runs and listens to the request.
15
+ */
16
+ export class RedirectListener {
17
+ constructor(options) {
18
+ this.port = options.port;
19
+ this.host = options.host;
20
+ this.server = RedirectListener.createServer(options.callback);
21
+ }
22
+ static createServer(callback) {
23
+ const app = createApp().use('*', async (request, response) => {
24
+ const requestUrl = request.url;
25
+ if (requestUrl?.includes('favicon')) {
26
+ const faviconFile = await getFavicon();
27
+ response.setHeader('Content-Type', 'image/svg+xml');
28
+ response.write(faviconFile);
29
+ response.end();
30
+ return {};
31
+ }
32
+ else if (requestUrl === '/style.css') {
33
+ const stylesheetFile = await getStylesheet();
34
+ response.setHeader('Content-Type', 'text/css');
35
+ response.write(stylesheetFile);
36
+ response.end();
37
+ return {};
38
+ }
39
+ const respond = async (contents, error, state, code) => {
40
+ response.setHeader('Content-Type', 'text/html');
41
+ response.write(contents);
42
+ response.end();
43
+ callback(error, state, code);
44
+ return {};
45
+ };
46
+ // If there was an empty/malformed URL sent back.
47
+ if (!requestUrl) {
48
+ const file = await getEmptyUrlHTML();
49
+ const err = new Bug(EmptyUrlString);
50
+ return respond(file, err, undefined, undefined);
51
+ }
52
+ // If an error was returned by the Identity server.
53
+ const queryObject = url.parse(requestUrl, true).query;
54
+ if (queryObject.error && queryObject.error_description) {
55
+ const file = await getAuthErrorHTML();
56
+ const err = new Abort(`${queryObject.error_description}`);
57
+ return respond(file, err, undefined, undefined);
58
+ }
59
+ // If the code isn't present in the URL.
60
+ if (!queryObject.code) {
61
+ const file = await getMissingCodeHTML();
62
+ const err = new Bug(MissingCodeString);
63
+ return respond(file, err, undefined, undefined);
64
+ }
65
+ // If the state isn't present in the URL.
66
+ if (!queryObject.state) {
67
+ const file = await getMissingStateHTML();
68
+ const err = new Bug(MissingStateString);
69
+ return respond(file, err, undefined, undefined);
70
+ }
71
+ const file = await getSuccessHTML();
72
+ return respond(file, undefined, `${queryObject.code}`, `${queryObject.state}`);
73
+ });
74
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
75
+ return createServer(app);
76
+ }
77
+ start() {
78
+ this.server.listen({ port: this.port, host: this.host }, () => { });
79
+ }
80
+ async stop() {
81
+ await this.server.close();
82
+ }
83
+ }
84
+ export async function listenRedirect(host, port, url) {
85
+ const result = await new Promise((resolve, reject) => {
86
+ const timeout = setTimeout(() => {
87
+ const message = '\nAuto-open timed out. Open the login page: ';
88
+ info(content `${message}${token.link('Log in to Shopify Partners', url)}\n`);
89
+ }, ResponseTimeoutSeconds * 1000);
90
+ const callback = (error, code, state) => {
91
+ clearTimeout(timeout);
92
+ setTimeout(() => {
93
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
94
+ redirectListener.stop();
95
+ if (error)
96
+ reject(error);
97
+ else
98
+ resolve({ code: code, state: state });
99
+ }, ServerStopDelaySeconds * 1000);
100
+ };
101
+ const redirectListener = new RedirectListener({ host, port, callback });
102
+ redirectListener.start();
103
+ });
104
+ return result;
105
+ }
106
+ //# sourceMappingURL=redirect-listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect-listener.js","sourceRoot":"","sources":["../../src/session/redirect-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,KAAK,EAAE,GAAG,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,cAAc,CAAA;AACjD,OAAO,EAAC,SAAS,EAAkC,MAAM,IAAI,CAAA;AAC7D,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAC,YAAY,EAAS,MAAM,MAAM,CAAA;AAEzC,MAAM,sBAAsB,GAAG,EAAE,CAAA;AACjC,MAAM,sBAAsB,GAAG,GAAG,CAAA;AAgBlC;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAmE3B,YAAY,OAAgC;QAC1C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAA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AC,CAAC,CAAA;YAC9D,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC,CAAA;QACnC,CAAC,CAAA;QAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,EAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAA;QACrE,gBAAgB,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import {\n getFavicon,\n getStylesheet,\n getEmptyUrlHTML,\n getAuthErrorHTML,\n getMissingCodeHTML,\n getMissingStateHTML,\n getSuccessHTML,\n EmptyUrlString,\n MissingCodeString,\n MissingStateString,\n} from './post-auth.js'\nimport {Abort, Bug} from '../error.js'\nimport {content, info, token} from '../output.js'\nimport {createApp, IncomingMessage, ServerResponse} from 'h3'\nimport url from 'url'\nimport {createServer, Server} from 'http'\n\nconst ResponseTimeoutSeconds = 10\nconst ServerStopDelaySeconds = 0.5\n\n/**\n * It represents the result of a redirect.\n */\ntype RedirectCallback = (error: Error | undefined, state: string | undefined, code: string | undefined) => void\n\n/**\n * Defines the interface of the options that\n * are used to instantiate a redirect listener.\n */\ninterface RedirectListenerOptions {\n host: string\n port: number\n callback: RedirectCallback\n}\n/**\n * When the authentication completes, Identity redirects\n * the user to a URL. In the case of the CLI, the redirect\n * is to localhost passing some parameters that are necessary\n * to continue the authentication. Because of that, we need\n * an HTTP server that runs and listens to the request.\n */\nexport class RedirectListener {\n private static createServer(callback: RedirectCallback): Server {\n const app = createApp().use('*', async (request: IncomingMessage, response: ServerResponse) => {\n const requestUrl = request.url\n if (requestUrl?.includes('favicon')) {\n const faviconFile = await getFavicon()\n response.setHeader('Content-Type', 'image/svg+xml')\n response.write(faviconFile)\n response.end()\n return {}\n } else if (requestUrl === '/style.css') {\n const stylesheetFile = await getStylesheet()\n response.setHeader('Content-Type', 'text/css')\n response.write(stylesheetFile)\n response.end()\n return {}\n }\n\n const respond = async (contents: string, error?: Error, state?: string, code?: string) => {\n response.setHeader('Content-Type', 'text/html')\n response.write(contents)\n response.end()\n callback(error, state, code)\n return {}\n }\n\n // If there was an empty/malformed URL sent back.\n if (!requestUrl) {\n const file = await getEmptyUrlHTML()\n const err = new Bug(EmptyUrlString)\n return respond(file, err, undefined, undefined)\n }\n\n // If an error was returned by the Identity server.\n const queryObject = url.parse(requestUrl, true).query\n if (queryObject.error && queryObject.error_description) {\n const file = await getAuthErrorHTML()\n const err = new Abort(`${queryObject.error_description}`)\n return respond(file, err, undefined, undefined)\n }\n\n // If the code isn't present in the URL.\n if (!queryObject.code) {\n const file = await getMissingCodeHTML()\n const err = new Bug(MissingCodeString)\n return respond(file, err, undefined, undefined)\n }\n\n // If the state isn't present in the URL.\n if (!queryObject.state) {\n const file = await getMissingStateHTML()\n const err = new Bug(MissingStateString)\n return respond(file, err, undefined, undefined)\n }\n\n const file = await getSuccessHTML()\n return respond(file, undefined, `${queryObject.code}`, `${queryObject.state}`)\n })\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return createServer(app)\n }\n\n port: number\n host: string\n server: ReturnType<typeof RedirectListener.createServer>\n\n constructor(options: RedirectListenerOptions) {\n this.port = options.port\n this.host = options.host\n this.server = RedirectListener.createServer(options.callback)\n }\n\n start(): void {\n this.server.listen({port: this.port, host: this.host}, () => {})\n }\n\n async stop(): Promise<void> {\n await this.server.close()\n }\n}\n\nexport async function listenRedirect(host: string, port: number, url: string): Promise<{code: string; state: string}> {\n const result = await new Promise<{code: string; state: string}>((resolve, reject) => {\n const timeout = setTimeout(() => {\n const message = '\\nAuto-open timed out. Open the login page: '\n info(content`${message}${token.link('Log in to Shopify Partners', url)}\\n`)\n }, ResponseTimeoutSeconds * 1000)\n\n const callback: RedirectCallback = (error, code, state) => {\n clearTimeout(timeout)\n setTimeout(() => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n redirectListener.stop()\n if (error) reject(error)\n else resolve({code: code as string, state: state as string})\n }, ServerStopDelaySeconds * 1000)\n }\n\n const redirectListener = new RedirectListener({host, port, callback})\n redirectListener.start()\n })\n return result\n}\n"]}