@shopify/cli-kit 3.32.1 → 3.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/constants.d.ts +2 -6
  2. package/dist/constants.js +0 -4
  3. package/dist/constants.js.map +1 -1
  4. package/dist/file.d.ts +1 -1
  5. package/dist/git.js +1 -1
  6. package/dist/git.js.map +1 -1
  7. package/dist/http.js +2 -2
  8. package/dist/http.js.map +1 -1
  9. package/dist/index.d.ts +0 -5
  10. package/dist/index.js +0 -5
  11. package/dist/index.js.map +1 -1
  12. package/dist/metadata.js +1 -1
  13. package/dist/metadata.js.map +1 -1
  14. package/dist/output.js +1 -1
  15. package/dist/output.js.map +1 -1
  16. package/dist/path.d.ts +1 -1
  17. package/dist/path.js +5 -3
  18. package/dist/path.js.map +1 -1
  19. package/dist/private/common/array.d.ts +1 -0
  20. package/dist/private/common/array.js +4 -0
  21. package/dist/private/common/array.js.map +1 -0
  22. package/dist/private/node/analytics.js +6 -9
  23. package/dist/private/node/analytics.js.map +1 -1
  24. package/dist/private/node/api/graphql.js +1 -0
  25. package/dist/private/node/api/graphql.js.map +1 -1
  26. package/dist/private/node/api/headers.js +1 -1
  27. package/dist/private/node/api/headers.js.map +1 -1
  28. package/dist/private/node/api/rest.d.ts +6 -0
  29. package/dist/private/node/api/rest.js +27 -0
  30. package/dist/private/node/api/rest.js.map +1 -0
  31. package/dist/private/node/environment/service.d.ts +18 -0
  32. package/dist/private/node/environment/service.js +32 -0
  33. package/dist/private/node/environment/service.js.map +1 -0
  34. package/dist/{environment → private/node/environment}/spin-cache.d.ts +0 -0
  35. package/dist/{environment → private/node/environment}/spin-cache.js +0 -0
  36. package/dist/private/node/environment/spin-cache.js.map +1 -0
  37. package/dist/{environment → private/node/environment}/utilities.d.ts +0 -0
  38. package/dist/{environment → private/node/environment}/utilities.js +0 -0
  39. package/dist/private/node/environment/utilities.js.map +1 -0
  40. package/dist/{session → private/node/session}/authorize.d.ts +1 -5
  41. package/dist/{session → private/node/session}/authorize.js +9 -9
  42. package/dist/private/node/session/authorize.js.map +1 -0
  43. package/dist/{session → private/node/session}/device-authorization.d.ts +0 -0
  44. package/dist/{session → private/node/session}/device-authorization.js +7 -9
  45. package/dist/private/node/session/device-authorization.js.map +1 -0
  46. package/dist/{session → private/node/session}/exchange.d.ts +2 -2
  47. package/dist/{session → private/node/session}/exchange.js +5 -5
  48. package/dist/private/node/session/exchange.js.map +1 -0
  49. package/dist/{session → private/node/session}/identity-token-validation.d.ts +0 -0
  50. package/dist/{session → private/node/session}/identity-token-validation.js +4 -4
  51. package/dist/private/node/session/identity-token-validation.js.map +1 -0
  52. package/dist/{session → private/node/session}/identity.d.ts +1 -1
  53. package/dist/{session → private/node/session}/identity.js +2 -3
  54. package/dist/private/node/session/identity.js.map +1 -0
  55. package/dist/{session → private/node/session}/post-auth.d.ts +1 -1
  56. package/dist/{session → private/node/session}/post-auth.js +3 -3
  57. package/dist/private/node/session/post-auth.js.map +1 -0
  58. package/dist/{session → private/node/session}/redirect-listener.d.ts +0 -0
  59. package/dist/{session → private/node/session}/redirect-listener.js +2 -2
  60. package/dist/private/node/session/redirect-listener.js.map +1 -0
  61. package/dist/{session → private/node/session}/schema.d.ts +1 -1
  62. package/dist/{session → private/node/session}/schema.js +1 -1
  63. package/dist/private/node/session/schema.js.map +1 -0
  64. package/dist/{session → private/node/session}/scopes.d.ts +1 -1
  65. package/dist/{session → private/node/session}/scopes.js +2 -2
  66. package/dist/private/node/session/scopes.js.map +1 -0
  67. package/dist/{session → private/node/session}/store.d.ts +0 -0
  68. package/dist/{session → private/node/session}/store.js +5 -5
  69. package/dist/private/node/session/store.js.map +1 -0
  70. package/dist/{session → private/node/session}/validate.d.ts +0 -0
  71. package/dist/{session → private/node/session}/validate.js +5 -5
  72. package/dist/private/node/session/validate.js.map +1 -0
  73. package/dist/private/node/session.d.ts +56 -0
  74. package/dist/{session.js → private/node/session.js} +97 -133
  75. package/dist/private/node/session.js.map +1 -0
  76. package/dist/private/node/ui/components/Subdued.d.ts +9 -0
  77. package/dist/private/node/ui/components/Subdued.js +10 -0
  78. package/dist/private/node/ui/components/Subdued.js.map +1 -0
  79. package/dist/private/node/ui/components/Subdued.test.d.ts +1 -0
  80. package/dist/private/node/ui/components/Subdued.test.js +11 -0
  81. package/dist/private/node/ui/components/Subdued.test.js.map +1 -0
  82. package/dist/private/node/ui/components/TokenizedText.d.ts +4 -1
  83. package/dist/private/node/ui/components/TokenizedText.js +4 -0
  84. package/dist/private/node/ui/components/TokenizedText.js.map +1 -1
  85. package/dist/private/node/ui/components/TokenizedText.test.js +4 -1
  86. package/dist/private/node/ui/components/TokenizedText.test.js.map +1 -1
  87. package/dist/private/node/ui.js +1 -1
  88. package/dist/private/node/ui.js.map +1 -1
  89. package/dist/public/common/array.d.ts +4 -0
  90. package/dist/public/common/array.js +4 -0
  91. package/dist/public/common/array.js.map +1 -1
  92. package/dist/public/common/object.d.ts +3 -3
  93. package/dist/public/common/object.js +5 -7
  94. package/dist/public/common/object.js.map +1 -1
  95. package/dist/public/common/url.d.ts +2 -1
  96. package/dist/public/common/url.js +3 -2
  97. package/dist/public/common/url.js.map +1 -1
  98. package/dist/public/node/analytics.js +3 -3
  99. package/dist/public/node/analytics.js.map +1 -1
  100. package/dist/public/node/api/admin.d.ts +31 -1
  101. package/dist/public/node/api/admin.js +28 -0
  102. package/dist/public/node/api/admin.js.map +1 -1
  103. package/dist/public/node/api/partners.js +7 -2
  104. package/dist/public/node/api/partners.js.map +1 -1
  105. package/dist/public/node/base-command.js +2 -2
  106. package/dist/public/node/base-command.js.map +1 -1
  107. package/dist/public/node/cli.d.ts +8 -0
  108. package/dist/public/node/cli.js +21 -4
  109. package/dist/public/node/cli.js.map +1 -1
  110. package/dist/public/node/environment/fqdn.d.ts +26 -0
  111. package/dist/{environment → public/node/environment}/fqdn.js +15 -31
  112. package/dist/public/node/environment/fqdn.js.map +1 -0
  113. package/dist/{environment → public/node/environment}/local.d.ts +62 -16
  114. package/dist/{environment → public/node/environment}/local.js +66 -24
  115. package/dist/public/node/environment/local.js.map +1 -0
  116. package/dist/public/node/environment/spin.d.ts +43 -0
  117. package/dist/{environment → public/node/environment}/spin.js +28 -35
  118. package/dist/public/node/environment/spin.js.map +1 -0
  119. package/dist/public/node/node-package-manager.js +1 -1
  120. package/dist/public/node/node-package-manager.js.map +1 -1
  121. package/dist/public/node/ruby.d.ts +1 -1
  122. package/dist/public/node/ruby.js +12 -13
  123. package/dist/public/node/ruby.js.map +1 -1
  124. package/dist/public/node/session.d.ts +53 -0
  125. package/dist/public/node/session.js +95 -0
  126. package/dist/public/node/session.js.map +1 -0
  127. package/dist/public/node/system.d.ts +44 -0
  128. package/dist/{system.js → public/node/system.js} +34 -54
  129. package/dist/public/node/system.js.map +1 -0
  130. package/dist/public/node/tcp.js +1 -1
  131. package/dist/public/node/tcp.js.map +1 -1
  132. package/dist/public/node/ui.d.ts +1 -1
  133. package/dist/public/node/ui.js.map +1 -1
  134. package/dist/testing/ui.js +1 -1
  135. package/dist/testing/ui.js.map +1 -1
  136. package/dist/tsconfig.tsbuildinfo +1 -1
  137. package/dist/ui.js +1 -1
  138. package/dist/ui.js.map +1 -1
  139. package/package.json +9 -7
  140. package/dist/api/graphql/all_app_extension_registrations.d.ts +0 -20
  141. package/dist/api/graphql/all_app_extension_registrations.js +0 -20
  142. package/dist/api/graphql/all_app_extension_registrations.js.map +0 -1
  143. package/dist/api/graphql/all_dev_stores_by_org.d.ts +0 -18
  144. package/dist/api/graphql/all_dev_stores_by_org.js +0 -21
  145. package/dist/api/graphql/all_dev_stores_by_org.js.map +0 -1
  146. package/dist/api/graphql/all_orgs.d.ts +0 -12
  147. package/dist/api/graphql/all_orgs.js +0 -14
  148. package/dist/api/graphql/all_orgs.js.map +0 -1
  149. package/dist/api/graphql/convert_dev_to_test_store.d.ts +0 -16
  150. package/dist/api/graphql/convert_dev_to_test_store.js +0 -13
  151. package/dist/api/graphql/convert_dev_to_test_store.js.map +0 -1
  152. package/dist/api/graphql/create_app.d.ts +0 -29
  153. package/dist/api/graphql/create_app.js +0 -33
  154. package/dist/api/graphql/create_app.js.map +0 -1
  155. package/dist/api/graphql/create_deployment.d.ts +0 -33
  156. package/dist/api/graphql/create_deployment.js +0 -25
  157. package/dist/api/graphql/create_deployment.js.map +0 -1
  158. package/dist/api/graphql/extension_create.d.ts +0 -30
  159. package/dist/api/graphql/extension_create.js +0 -26
  160. package/dist/api/graphql/extension_create.js.map +0 -1
  161. package/dist/api/graphql/extension_specifications.d.ts +0 -27
  162. package/dist/api/graphql/extension_specifications.js +0 -22
  163. package/dist/api/graphql/extension_specifications.js.map +0 -1
  164. package/dist/api/graphql/find_app.d.ts +0 -14
  165. package/dist/api/graphql/find_app.js +0 -17
  166. package/dist/api/graphql/find_app.js.map +0 -1
  167. package/dist/api/graphql/find_org.d.ts +0 -18
  168. package/dist/api/graphql/find_org.js +0 -21
  169. package/dist/api/graphql/find_org.js.map +0 -1
  170. package/dist/api/graphql/find_org_basic.d.ts +0 -11
  171. package/dist/api/graphql/find_org_basic.js +0 -14
  172. package/dist/api/graphql/find_org_basic.js.map +0 -1
  173. package/dist/api/graphql/find_store_by_domain.d.ts +0 -21
  174. package/dist/api/graphql/find_store_by_domain.js +0 -24
  175. package/dist/api/graphql/find_store_by_domain.js.map +0 -1
  176. package/dist/api/graphql/functions/api_schema_definition.d.ts +0 -9
  177. package/dist/api/graphql/functions/api_schema_definition.js +0 -7
  178. package/dist/api/graphql/functions/api_schema_definition.js.map +0 -1
  179. package/dist/api/graphql/functions/app_function_set.d.ts +0 -30
  180. package/dist/api/graphql/functions/app_function_set.js +0 -38
  181. package/dist/api/graphql/functions/app_function_set.js.map +0 -1
  182. package/dist/api/graphql/functions/function_service_proxy.d.ts +0 -4
  183. package/dist/api/graphql/functions/function_service_proxy.js +0 -7
  184. package/dist/api/graphql/functions/function_service_proxy.js.map +0 -1
  185. package/dist/api/graphql/functions/upload_url_generate.d.ts +0 -12
  186. package/dist/api/graphql/functions/upload_url_generate.js +0 -11
  187. package/dist/api/graphql/functions/upload_url_generate.js.map +0 -1
  188. package/dist/api/graphql/generate_signed_upload_url.d.ts +0 -15
  189. package/dist/api/graphql/generate_signed_upload_url.js +0 -15
  190. package/dist/api/graphql/generate_signed_upload_url.js.map +0 -1
  191. package/dist/api/graphql/get_urls.d.ts +0 -10
  192. package/dist/api/graphql/get_urls.js +0 -10
  193. package/dist/api/graphql/get_urls.js.map +0 -1
  194. package/dist/api/graphql/get_variant_id.d.ts +0 -17
  195. package/dist/api/graphql/get_variant_id.js +0 -20
  196. package/dist/api/graphql/get_variant_id.js.map +0 -1
  197. package/dist/api/graphql/index.d.ts +0 -21
  198. package/dist/api/graphql/index.js +0 -22
  199. package/dist/api/graphql/index.js.map +0 -1
  200. package/dist/api/graphql/update_draft.d.ts +0 -33
  201. package/dist/api/graphql/update_draft.js +0 -24
  202. package/dist/api/graphql/update_draft.js.map +0 -1
  203. package/dist/api/graphql/update_urls.d.ts +0 -14
  204. package/dist/api/graphql/update_urls.js +0 -12
  205. package/dist/api/graphql/update_urls.js.map +0 -1
  206. package/dist/api.d.ts +0 -3
  207. package/dist/api.js +0 -4
  208. package/dist/api.js.map +0 -1
  209. package/dist/cli.d.ts +0 -8
  210. package/dist/cli.js +0 -18
  211. package/dist/cli.js.map +0 -1
  212. package/dist/environment/fqdn.d.ts +0 -29
  213. package/dist/environment/fqdn.js.map +0 -1
  214. package/dist/environment/local.js.map +0 -1
  215. package/dist/environment/service.d.ts +0 -4
  216. package/dist/environment/service.js +0 -19
  217. package/dist/environment/service.js.map +0 -1
  218. package/dist/environment/spin-cache.js.map +0 -1
  219. package/dist/environment/spin.d.ts +0 -50
  220. package/dist/environment/spin.js.map +0 -1
  221. package/dist/environment/utilities.js.map +0 -1
  222. package/dist/environment.d.ts +0 -7
  223. package/dist/environment.js +0 -8
  224. package/dist/environment.js.map +0 -1
  225. package/dist/network/service.d.ts +0 -14
  226. package/dist/network/service.js +0 -11
  227. package/dist/network/service.js.map +0 -1
  228. package/dist/public/node/checksum.d.ts +0 -20
  229. package/dist/public/node/checksum.js +0 -32
  230. package/dist/public/node/checksum.js.map +0 -1
  231. package/dist/session/authorize.js.map +0 -1
  232. package/dist/session/device-authorization.js.map +0 -1
  233. package/dist/session/exchange.js.map +0 -1
  234. package/dist/session/identity-token-validation.js.map +0 -1
  235. package/dist/session/identity.js.map +0 -1
  236. package/dist/session/post-auth.js.map +0 -1
  237. package/dist/session/redirect-listener.js.map +0 -1
  238. package/dist/session/schema.js.map +0 -1
  239. package/dist/session/scopes.js.map +0 -1
  240. package/dist/session/store.js.map +0 -1
  241. package/dist/session/token.d.ts +0 -40
  242. package/dist/session/token.js +0 -22
  243. package/dist/session/token.js.map +0 -1
  244. package/dist/session/validate.js.map +0 -1
  245. package/dist/session.d.ts +0 -96
  246. package/dist/session.js.map +0 -1
  247. package/dist/system.d.ts +0 -51
  248. package/dist/system.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ import { buildHeaders } from './headers.js';
2
+ export function restRequestBody(requestBody) {
3
+ if (!requestBody) {
4
+ return;
5
+ }
6
+ return JSON.stringify(requestBody);
7
+ }
8
+ export function restRequestUrl(session, apiVersion, path) {
9
+ if (isThemeAccessSession(session)) {
10
+ return `https://theme-kit-access.shopifyapps.com/cli/admin/api/${apiVersion}${path}.json`;
11
+ }
12
+ return `https://${session.storeFqdn}/admin/api/${apiVersion}${path}.json`;
13
+ }
14
+ export async function restRequestHeaders(session) {
15
+ const store = session.storeFqdn;
16
+ const token = session.token;
17
+ const headers = await buildHeaders(session.token);
18
+ if (isThemeAccessSession(session)) {
19
+ headers['X-Shopify-Shop'] = store;
20
+ headers['X-Shopify-Access-Token'] = token;
21
+ }
22
+ return headers;
23
+ }
24
+ function isThemeAccessSession(session) {
25
+ return session.token.startsWith('shptka_');
26
+ }
27
+ //# sourceMappingURL=rest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/private/node/api/rest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAA;AAGzC,MAAM,UAAU,eAAe,CAAI,WAAe;IAChD,IAAI,CAAC,WAAW,EAAE;QAChB,OAAM;KACP;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAqB,EAAE,UAAkB,EAAE,IAAY;IACpF,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE;QACjC,OAAO,0DAA0D,UAAU,GAAG,IAAI,OAAO,CAAA;KAC1F;IAED,OAAO,WAAW,OAAO,CAAC,SAAS,cAAc,UAAU,GAAG,IAAI,OAAO,CAAA;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAqB;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAC3B,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAEjD,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE;QACjC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAA;QACjC,OAAO,CAAC,wBAAwB,CAAC,GAAG,KAAK,CAAA;KAC1C;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAqB;IACjD,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;AAC5C,CAAC","sourcesContent":["import {buildHeaders} from './headers.js'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\nexport function restRequestBody<T>(requestBody?: T) {\n if (!requestBody) {\n return\n }\n return JSON.stringify(requestBody)\n}\n\nexport function restRequestUrl(session: AdminSession, apiVersion: string, path: string) {\n if (isThemeAccessSession(session)) {\n return `https://theme-kit-access.shopifyapps.com/cli/admin/api/${apiVersion}${path}.json`\n }\n\n return `https://${session.storeFqdn}/admin/api/${apiVersion}${path}.json`\n}\n\nexport async function restRequestHeaders(session: AdminSession) {\n const store = session.storeFqdn\n const token = session.token\n const headers = await buildHeaders(session.token)\n\n if (isThemeAccessSession(session)) {\n headers['X-Shopify-Shop'] = store\n headers['X-Shopify-Access-Token'] = token\n }\n\n return headers\n}\n\nfunction isThemeAccessSession(session: AdminSession) {\n return session.token.startsWith('shptka_')\n}\n"]}
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Enum that represents the environment to use for a given service.
4
+ *
5
+ * @readonly
6
+ */
7
+ export declare enum Environment {
8
+ Local = "local",
9
+ Production = "production",
10
+ Spin = "spin"
11
+ }
12
+ /**
13
+ * Returns the environment to use for a given service.
14
+ *
15
+ * @param env - Environment variables.
16
+ * @returns The environment to use for a given service.
17
+ */
18
+ export declare function serviceEnvironment(env?: NodeJS.ProcessEnv): Environment;
@@ -0,0 +1,32 @@
1
+ import { isSpin } from '../../../public/node/environment/spin.js';
2
+ import constants from '../../../constants.js';
3
+ /**
4
+ * Enum that represents the environment to use for a given service.
5
+ *
6
+ * @readonly
7
+ */
8
+ export var Environment;
9
+ (function (Environment) {
10
+ Environment["Local"] = "local";
11
+ Environment["Production"] = "production";
12
+ Environment["Spin"] = "spin";
13
+ })(Environment || (Environment = {}));
14
+ /**
15
+ * Returns the environment to use for a given service.
16
+ *
17
+ * @param env - Environment variables.
18
+ * @returns The environment to use for a given service.
19
+ */
20
+ export function serviceEnvironment(env = process.env) {
21
+ const value = env[constants.environmentVariables.serviceEnv];
22
+ if (value === 'local') {
23
+ return Environment.Local;
24
+ }
25
+ else if (value === 'spin' || isSpin(env)) {
26
+ return Environment.Spin;
27
+ }
28
+ else {
29
+ return Environment.Production;
30
+ }
31
+ }
32
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../src/private/node/environment/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,0CAA0C,CAAA;AAC/D,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,wCAAyB,CAAA;IACzB,4BAAa,CAAA;AACf,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAClD,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAA;IAC5D,IAAI,KAAK,KAAK,OAAO,EAAE;QACrB,OAAO,WAAW,CAAC,KAAK,CAAA;KACzB;SAAM,IAAI,KAAK,KAAK,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;QAC1C,OAAO,WAAW,CAAC,IAAI,CAAA;KACxB;SAAM;QACL,OAAO,WAAW,CAAC,UAAU,CAAA;KAC9B;AACH,CAAC","sourcesContent":["import {isSpin} from '../../../public/node/environment/spin.js'\nimport constants from '../../../constants.js'\n\n/**\n * Enum that represents the environment to use for a given service.\n *\n * @readonly\n */\nexport enum Environment {\n Local = 'local',\n Production = 'production',\n Spin = 'spin',\n}\n\n/**\n * Returns the environment to use for a given service.\n *\n * @param env - Environment variables.\n * @returns The environment to use for a given service.\n */\nexport function serviceEnvironment(env = process.env): Environment {\n const value = env[constants.environmentVariables.serviceEnv]\n if (value === 'local') {\n return Environment.Local\n } else if (value === 'spin' || isSpin(env)) {\n return Environment.Spin\n } else {\n return Environment.Production\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spin-cache.js","sourceRoot":"","sources":["../../../../src/private/node/environment/spin-cache.ts"],"names":[],"mappings":"AAAA,IAAI,cAAsB,CAAA;AAE1B,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,cAAc,GAAG,IAAI,CAAA;AACvB,CAAC","sourcesContent":["let cachedSpinFQDN: string\n\nexport function getCachedSpinFqdn(): string | undefined {\n return cachedSpinFQDN\n}\n\nexport function setCachedSpinFqdn(fqdn: string) {\n cachedSpinFQDN = fqdn\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../../../../src/private/node/environment/utilities.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,QAA4B;IACnD,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,KAAK,CAAA;KACb;IACD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAC/D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,QAA4B;IAChD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACpD,OAAO,KAAK,CAAA;KACb;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["/**\n * Returns whether an environment variable value represents a truthy value.\n */\nexport function isTruthy(variable: string | undefined): boolean {\n if (!variable) {\n return false\n }\n return ['1', 'true', 'TRUE', 'yes', 'YES'].includes(variable)\n}\n\n/**\n * Returns whether an environment variable has been set and is non-empty\n */\nexport function isSet(variable: string | undefined): boolean {\n if (variable === undefined || variable.trim() === '') {\n return false\n }\n return true\n}\n"]}
@@ -1,11 +1,7 @@
1
- import { Abort } from '../error.js';
1
+ import { Abort } from '../../../error.js';
2
2
  export declare const MismatchStateError: Abort;
3
3
  export interface CodeAuthResult {
4
4
  code: string;
5
5
  codeVerifier: string;
6
6
  }
7
7
  export declare function authorize(scopes: string[], state?: string): Promise<CodeAuthResult>;
8
- export declare function generateRandomChallengePair(): {
9
- codeVerifier: string;
10
- codeChallenge: string;
11
- };
@@ -1,11 +1,11 @@
1
- import { listenRedirect } from './redirect-listener.js';
2
1
  import { clientId } from './identity.js';
3
- import { base64URLEncode, randomBytes, randomHex, sha256 } from '../public/node/crypto.js';
4
- import { open } from '../system.js';
5
- import { Abort, CancelExecution } from '../error.js';
6
- import { identity as identityFqdn } from '../environment/fqdn.js';
7
- import * as output from '../output.js';
8
- import { keypress, terminateBlockingPortProcessPrompt } from '../ui.js';
2
+ import { listenRedirect } from './redirect-listener.js';
3
+ import { base64URLEncode, randomBytes, randomHex, sha256 } from '../../../public/node/crypto.js';
4
+ import { openURL } from '../../../public/node/system.js';
5
+ import { Abort, CancelExecution } from '../../../error.js';
6
+ import { identityFqdn } from '../../../public/node/environment/fqdn.js';
7
+ import * as output from '../../../output.js';
8
+ import { keypress, terminateBlockingPortProcessPrompt } from '../../../ui.js';
9
9
  import { checkPort as isPortAvailable } from 'get-port-please';
10
10
  export const MismatchStateError = new Abort("The state received from the authentication doesn't match the one that initiated the authentication process.");
11
11
  export async function authorize(scopes, state = randomHex(30)) {
@@ -30,14 +30,14 @@ export async function authorize(scopes, state = randomHex(30)) {
30
30
  output.info('👉 Press any key to open the login page on your browser');
31
31
  await keypress();
32
32
  url = `${url}?${new URLSearchParams(params).toString()}`;
33
- await open(url);
33
+ await openURL(url);
34
34
  const result = await listenRedirect(host, port, url);
35
35
  if (result.state !== state) {
36
36
  throw MismatchStateError;
37
37
  }
38
38
  return { code: result.code, codeVerifier };
39
39
  }
40
- export function generateRandomChallengePair() {
40
+ function generateRandomChallengePair() {
41
41
  const codeVerifier = base64URLEncode(randomBytes(32));
42
42
  const codeChallenge = base64URLEncode(sha256(codeVerifier));
43
43
  return { codeVerifier, codeChallenge };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../../src/private/node/session/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MA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B,EAAE,MAAM;QAC7B,cAAc,EAAE,aAAa;KAC9B,CAAA;IAED,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAA;IACjE,MAAM,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAA;IACtE,MAAM,QAAQ,EAAE,CAAA;IAEhB,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAA;IACxD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;IAElB,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;IAEpD,IAAI,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;AAED,SAAS,2BAA2B;IAClC,MAAM,YAAY,GAAG,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;IACrD,MAAM,aAAa,GAAG,eAAe,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;IAC3D,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,CAAA;AACtC,CAAC;AAED,KAAK,UAAU,mCAAmC,CAAC,IAAY;IAC7D,MAAM,EAAC,eAAe,EAAC,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAA;IAE3D,IAAI,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE;QAC/B,OAAM;KACP;IAED,IAAI,MAAM,kCAAkC,CAAC,IAAI,EAAE,gBAAgB,CAAC,EAAE;QACpE,MAAM,eAAe,CAAC,IAAI,CAAC,CAAA;KAC5B;SAAM;QACL,MAAM,IAAI,eAAe,EAAE,CAAA;KAC5B;AACH,CAAC","sourcesContent":["import {clientId} from './identity.js'\nimport {listenRedirect} from './redirect-listener.js'\nimport {base64URLEncode, randomBytes, randomHex, sha256} from '../../../public/node/crypto.js'\nimport {openURL} from '../../../public/node/system.js'\nimport {Abort, CancelExecution} from '../../../error.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport * as output from '../../../output.js'\nimport {keypress, terminateBlockingPortProcessPrompt} from '../../../ui.js'\nimport {checkPort as isPortAvailable} from 'get-port-please'\n\nexport const MismatchStateError = new Abort(\n \"The state received from the authentication doesn't match the one that initiated the authentication process.\",\n)\n\nexport interface CodeAuthResult {\n code: string\n codeVerifier: string\n}\n\nexport async function authorize(scopes: string[], state: string = randomHex(30)): Promise<CodeAuthResult> {\n const port = 3456\n const host = '127.0.0.1'\n const redirectUri = `http://${host}:${port}`\n const fqdn = await identityFqdn()\n const identityClientId = clientId()\n\n await validateRedirectionPortAvailability(port)\n\n let url = `http://${fqdn}/oauth/authorize`\n\n const {codeVerifier, codeChallenge} = generateRandomChallengePair()\n\n const params = {\n client_id: identityClientId,\n scope: scopes.join(' '),\n redirect_uri: redirectUri,\n state,\n response_type: 'code',\n code_challenge_method: 'S256',\n code_challenge: codeChallenge,\n }\n\n output.info('\\nTo run this command, log in to Shopify Partners.')\n output.info('👉 Press any key to open the login page on your browser')\n await keypress()\n\n url = `${url}?${new URLSearchParams(params).toString()}`\n await openURL(url)\n\n const result = await listenRedirect(host, port, url)\n\n if (result.state !== state) {\n throw MismatchStateError\n }\n\n return {code: result.code, codeVerifier}\n}\n\nfunction generateRandomChallengePair() {\n const codeVerifier = base64URLEncode(randomBytes(32))\n const codeChallenge = base64URLEncode(sha256(codeVerifier))\n return {codeVerifier, codeChallenge}\n}\n\nasync function validateRedirectionPortAvailability(port: number) {\n const {killPortProcess} = await import('kill-port-process')\n\n if (await isPortAvailable(port)) {\n return\n }\n\n if (await terminateBlockingPortProcessPrompt(port, 'Authentication')) {\n await killPortProcess(port)\n } else {\n throw new CancelExecution()\n }\n}\n"]}
@@ -1,12 +1,9 @@
1
1
  import { clientId } from './identity.js';
2
2
  import { exchangeDeviceCodeForAccessToken } from './exchange.js';
3
- import { identity as identityFqdn } from '../environment/fqdn.js';
4
- import { shopifyFetch } from '../http.js';
5
- import { content, debug, info, token } from '../output.js';
6
- import { Bug } from '../error.js';
7
- const DeviceAuthError = () => {
8
- return new Bug('Failed to start authorization process');
9
- };
3
+ import { identityFqdn } from '../../../public/node/environment/fqdn.js';
4
+ import { shopifyFetch } from '../../../http.js';
5
+ import { content, debug, info, token } from '../../../output.js';
6
+ import { Bug } from '../../../error.js';
10
7
  /**
11
8
  * Initiate a device authorization flow.
12
9
  * This will return a DeviceAuthorizationResponse containing the URL where user
@@ -30,8 +27,9 @@ export async function requestDeviceAuthorization(scopes) {
30
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
28
  const jsonResult = await response.json();
32
29
  debug(content `Received device authorization code: ${token.json(jsonResult)}`);
33
- if (!jsonResult.device_code || !jsonResult.verification_uri_complete)
34
- throw DeviceAuthError();
30
+ if (!jsonResult.device_code || !jsonResult.verification_uri_complete) {
31
+ throw new Bug('Failed to start authorization process');
32
+ }
35
33
  info('\nTo run this command, log in to Shopify Partners.');
36
34
  info(content `User verification code: ${jsonResult.user_code}`);
37
35
  info(content `👉 Open this link to start the auth process: ${token.green(jsonResult.verification_uri_complete)}`);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device-authorization.js","sourceRoot":"","sources":["../../../../src/private/node/session/device-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,gCAAgC,EAAC,MAAM,eAAe,CAAA;AAE9D,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAC,GAAG,EAAC,MAAM,mBAAmB,CAAA;AAWrC;;;;;;;;;G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K,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;SACjD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SACvC,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC","sourcesContent":["import {clientId} from './identity.js'\nimport {exchangeDeviceCodeForAccessToken} from './exchange.js'\nimport {IdentityToken} from './schema.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {shopifyFetch} from '../../../http.js'\nimport {content, debug, info, token} from '../../../output.js'\nimport {Bug} from '../../../error.js'\n\nexport interface DeviceAuthorizationResponse {\n deviceCode: string\n userCode: string\n verificationUri: string\n expiresIn: number\n verificationUriComplete?: string\n interval?: number\n}\n\n/**\n * Initiate a device authorization flow.\n * This will return a DeviceAuthorizationResponse containing the URL where user\n * should go to authorize the device without the need of a callback to the CLI.\n *\n * Also returns a `deviceCode` used for polling the token endpoint in the next step.\n *\n * @param scopes - The scopes to request\n * @returns An object with the device authorization response.\n */\nexport async function requestDeviceAuthorization(scopes: string[]): Promise<DeviceAuthorizationResponse> {\n const fqdn = await identityFqdn()\n const identityClientId = await clientId()\n const queryParams = {client_id: identityClientId, scope: scopes.join(' ')}\n const url = `https://${fqdn}/oauth/device_authorization`\n\n const response = await shopifyFetch(url, {\n method: 'POST',\n headers: {'Content-type': 'application/x-www-form-urlencoded'},\n body: convertRequestToParams(queryParams),\n })\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const jsonResult: any = await response.json()\n\n debug(content`Received device authorization code: ${token.json(jsonResult)}`)\n if (!jsonResult.device_code || !jsonResult.verification_uri_complete) {\n throw new Bug('Failed to start authorization process')\n }\n\n info('\\nTo run this command, log in to Shopify Partners.')\n info(content`User verification code: ${jsonResult.user_code}`)\n info(content`👉 Open this link to start the auth process: ${token.green(jsonResult.verification_uri_complete)}`)\n\n return {\n deviceCode: jsonResult.device_code,\n userCode: jsonResult.user_code,\n verificationUri: jsonResult.verification_uri,\n expiresIn: jsonResult.expires_in,\n verificationUriComplete: jsonResult.verification_uri_complete,\n interval: jsonResult.interval,\n }\n}\n\n/**\n * Poll the Oauth token endpoint with the device code obtained from a DeviceAuthorizationResponse.\n * The endpoint will return `authorization_pending` until the user completes the auth flow in the browser.\n * Once the user completes the auth flow, the endpoint will return the identity token.\n *\n * Timeout for the polling is defined by the server and is around 600 seconds.\n *\n * @param code - The device code obtained after starting a device identity flow\n * @param interval - The interval to poll the token endpoint\n * @returns The identity token\n */\nexport async function pollForDeviceAuthorization(code: string, interval = 5): Promise<IdentityToken> {\n let currentIntervalInSeconds = interval\n\n return new Promise<IdentityToken>((resolve, reject) => {\n const onPoll = async () => {\n const result = await exchangeDeviceCodeForAccessToken(code)\n if (!result.isErr()) return resolve(result.value)\n\n const error = result.error ?? 'unknown_failure'\n\n debug(content`Polling for device authorization... status: ${error}`)\n switch (error) {\n case 'authorization_pending':\n return startPolling()\n case 'slow_down':\n currentIntervalInSeconds += 5\n return startPolling()\n case 'access_denied':\n case 'expired_token':\n case 'unknown_failure':\n return reject(result)\n }\n }\n\n const startPolling = () => {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n setTimeout(onPoll, currentIntervalInSeconds * 1000)\n }\n\n startPolling()\n })\n}\n\nfunction convertRequestToParams(queryParams: {client_id: string; scope: string}): string {\n return Object.entries(queryParams)\n .map(([key, value]) => value && `${key}=${value}`)\n .filter((hasValue) => Boolean(hasValue))\n .join('&')\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { ApplicationToken, IdentityToken } from './schema.js';
2
2
  import { CodeAuthResult } from './authorize.js';
3
- import { Result } from '../public/node/result.js';
4
- import { ExtendableError } from '../error.js';
3
+ import { Result } from '../../../public/node/result.js';
4
+ import { ExtendableError } from '../../../error.js';
5
5
  export declare class InvalidGrantError extends ExtendableError {
6
6
  }
7
7
  export declare class InvalidRequestError extends ExtendableError {
@@ -1,9 +1,9 @@
1
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';
2
+ import { identityFqdn } from '../../../public/node/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
7
  export class InvalidGrantError extends ExtendableError {
8
8
  }
9
9
  export class InvalidRequestError extends ExtendableError {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../../../src/private/node/session/exchange.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAE,QAAQ,IAAI,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAG5E,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAC,GAAG,EAAE,EAAE,EAAS,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAC,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AAEjD,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,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IACnE,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC,CAAA;IAC1D,8DAA8D;IAC9D,MAAM,OAAO,GAAQ,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;IAErC,IAAI,GAAG,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 {identityFqdn} from '../../../public/node/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"]}
@@ -1,6 +1,6 @@
1
- import { identity } from '../environment/fqdn.js';
2
- import { debug } from '../output.js';
3
- import { shopifyFetch } from '../http.js';
1
+ import { identityFqdn } from '../../../public/node/environment/fqdn.js';
2
+ import { debug } from '../../../output.js';
3
+ import { shopifyFetch } from '../../../http.js';
4
4
  export async function validateIdentityToken(token) {
5
5
  try {
6
6
  const instrospectionURL = await getInstrospectionEndpoint();
@@ -33,7 +33,7 @@ export async function validateIdentityToken(token) {
33
33
  }
34
34
  }
35
35
  async function getInstrospectionEndpoint() {
36
- const response = await shopifyFetch(`https://${await identity()}/.well-known/openid-configuration.json`);
36
+ const response = await shopifyFetch(`https://${await identityFqdn()}/.well-known/openid-configuration.json`);
37
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
38
  const json = await response.json();
39
39
  return json.introspection_endpoint;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-token-validation.js","sourceRoot":"","sources":["../../../../src/private/node/session/identity-token-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAE7C,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,KAAa;IACvD,IAAI;QACF,MAAM,iBAAiB,GAAG,MAAM,yBAAyB,EAAE,CAAA;QAC3D,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAC,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAC;YAC/E,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAC,KAAK,EAAC,CAAC;SAC9B,CAAA;QACD,KAAK,CAAC,kDAAkD,iBAAiB,EAAE,CAAC,CAAA;QAE5E,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;QAE/D,IAAI,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE;YACzE,8DAA8D;YAC9D,MAAM,IAAI,GAAQ,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YACvC,KAAK,CAAC,gCAAgC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;YACnD,OAAO,IAAI,CAAC,KAAK,CAAA;SAClB;aAAM;YACL,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YAClC,KAAK,CAAC;aACC,QAAQ,CAAC,MAAM;8BACE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;WAC3E,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC5B,OAAO,KAAK,CAAA;SACb;QACD,qDAAqD;KACtD;IAAC,OAAO,KAAK,EAAE;QACd,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAA;QAChD,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED,KAAK,UAAU,yBAAyB;IACtC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,WAAW,MAAM,YAAY,EAAE,wCAAwC,CAAC,CAAA;IAC5G,8DAA8D;IAC9D,MAAM,IAAI,GAAQ,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACvC,OAAO,IAAI,CAAC,sBAAsB,CAAA;AACpC,CAAC","sourcesContent":["import {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {debug} from '../../../output.js'\nimport {shopifyFetch} from '../../../http.js'\n\nexport async function validateIdentityToken(token: string) {\n try {\n const instrospectionURL = await getInstrospectionEndpoint()\n const options = {\n method: 'POST',\n headers: {Authorization: `Bearer ${token}`, 'Content-Type': 'application/json'},\n body: JSON.stringify({token}),\n }\n debug(`Sending Identity Introspection request to URL: ${instrospectionURL}`)\n\n const response = await shopifyFetch(instrospectionURL, options)\n\n if (response.ok && response.headers.get('content-type')?.includes('json')) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const json: any = await response.json()\n debug(`The identity token is valid: ${json.valid}`)\n return json.valid\n } else {\n const text = await response.text()\n debug(`The Introspection request failed with:\n - status: ${response.status}\n - www-authenticate header: ${JSON.stringify(response.headers.get('www-authenticate'))}\n - body: ${JSON.stringify(text)}`)\n return false\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n debug(`The identity token is invalid: ${error}`)\n return false\n }\n}\n\nasync function getInstrospectionEndpoint(): Promise<string> {\n const response = await shopifyFetch(`https://${await identityFqdn()}/.well-known/openid-configuration.json`)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const json: any = await response.json()\n return json.introspection_endpoint\n}\n"]}
@@ -1,3 +1,3 @@
1
- import { API } from '../network/api.js';
1
+ import { API } from '../../../network/api.js';
2
2
  export declare function clientId(): string;
3
3
  export declare function applicationId(api: API): string;
@@ -1,6 +1,5 @@
1
- import { Bug } from '../error.js';
2
- import { Environment } from '../network/service.js';
3
- import { serviceEnvironment } from '../environment/service.js';
1
+ import { Bug } from '../../../error.js';
2
+ import { Environment, serviceEnvironment } from '../environment/service.js';
4
3
  export function clientId() {
5
4
  const environment = serviceEnvironment();
6
5
  if (environment === Environment.Local) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../../src/private/node/session/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,mBAAmB,CAAA;AAErC,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,2BAA2B,CAAA;AAEzE,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 {API} from '../../../network/api.js'\nimport {Environment, 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"]}
@@ -1,4 +1,4 @@
1
- import { Bug } from '../error.js';
1
+ import { Bug } from '../../../error.js';
2
2
  export declare const getEmptyUrlHTML: () => Promise<string>;
3
3
  export declare const getAuthErrorHTML: () => Promise<string>;
4
4
  export declare const getMissingCodeHTML: () => Promise<string>;
@@ -1,6 +1,6 @@
1
- import { findUp, moduleDirectory } from '../path.js';
2
- import { read } from '../file.js';
3
- import { Bug } from '../error.js';
1
+ import { findUp, moduleDirectory } from '../../../path.js';
2
+ import { read } from '../../../file.js';
3
+ import { Bug } from '../../../error.js';
4
4
  const HTMLFileNames = [
5
5
  'empty-url.html',
6
6
  'auth-error.html',
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-auth.js","sourceRoot":"","sources":["../../../../src/private/node/session/post-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAC,IAAI,EAAC,MAAM,kBAAkB,CAAA;AACrC,OAAO,EAAC,GAAG,EAAC,MAAM,mBAAmB,CAAA;AAErC,MAAM,aAAa,GAAG;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,cAAc;CACN,CAAA;AACV,MAAM,kBAAkB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c,GAAG,KAAK,IAAqB,EAAE;IACxD,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,aAAa,GAAG,KAAK,IAAqB,EAAE;IACvD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACtD,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,IAAqB,EAAE;IACpD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,eAAe,CAAC,CAAA;IACnD,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,+DAA+D,CAAA;AAE7F,MAAM,CAAC,MAAM,eAAe,GAAG,kDAAkD,CAAA;AAEjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,kFAAkF,CAAA;AAEnH,MAAM,CAAC,MAAM,kBAAkB,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"]}
@@ -1,6 +1,6 @@
1
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';
2
+ import { Abort, Bug } from '../../../error.js';
3
+ import { content, info, token } from '../../../output.js';
4
4
  import { createApp } from 'h3';
5
5
  import url from 'url';
6
6
  import { createServer } from 'http';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect-listener.js","sourceRoot":"","sources":["../../../../src/private/node/session/redirect-listener.ts"],"names":[],"mappings":"AAA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,CAAgC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAClF,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,MAAM,OAAO,GAAG,8CAA8C,CAAA;YAC9D,IAAI,CAAC,OAAO,CAAA,GAAG,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,4BAA4B,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;QAC7E,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC,CAAA;QAEjC,MAAM,QAAQ,GAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;YACxD,YAAY,CAAC,OAAO,CAAC,CAAA;YACrB,UAAU,CAAC,GAAG,EAAE;gBACd,mEAAmE;gBACnE,gBAAgB,CAAC,IAAI,EAAE,CAAA;gBACvB,IAAI,KAAK;oBAAE,MAAM,CAAC,KAAK,CAAC,CAAA;;oBACnB,OAAO,CAAC,EAAC,IAAI,EAAE,IAAc,EAAE,KAAK,EAAE,KAAe,EAAC,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"]}
@@ -1,4 +1,4 @@
1
- import { define } from '../schema.js';
1
+ import { define } from '../../../schema.js';
2
2
  /**
3
3
  * The schema represents an Identity token.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { define } from '../schema.js';
1
+ import { define } from '../../../schema.js';
2
2
  const DateSchema = define.preprocess((arg) => {
3
3
  if (typeof arg === 'string' || arg instanceof Date)
4
4
  return new Date(arg);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/private/node/session/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAA;AAEzC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,EAAE;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,IAAI;QAAE,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,CAAA;IACxE,OAAO,IAAI,CAAA;AACb,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;AAEjB;;GAEG;AACH,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;IAC5B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;IAC7B,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;CACtC,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;IAC5B,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;CACtC,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CACrD,MAAM,CAAC,MAAM,CAAC;IACZ;;;;OAIG;IACH,QAAQ,EAAE,mBAAmB;IAC7B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC;CACjE,CAAC,CACH,CAAA","sourcesContent":["import {define} from '../../../schema.js'\n\nconst DateSchema = define.preprocess((arg) => {\n if (typeof arg === 'string' || arg instanceof Date) return new Date(arg)\n return null\n}, define.date())\n\n/**\n * The schema represents an Identity token.\n */\nconst IdentityTokenSchema = define.object({\n accessToken: define.string(),\n refreshToken: define.string(),\n expiresAt: DateSchema,\n scopes: define.array(define.string()),\n})\n\n/**\n * The schema represents an application token.\n */\nconst ApplicationTokenSchema = define.object({\n accessToken: define.string(),\n expiresAt: DateSchema,\n scopes: define.array(define.string()),\n})\n\n/**\n * This schema represents the format of the session\n * that we cache in the system to avoid unnecessary\n * token exchanges.\n *\n * @example\n * ```\n * {\n * \"accounts.shopify.com\": {\n * \"identity\": {...} // IdentityTokenSchema\n * \"applications\": {\n * \"${domain}-application-id\": { // Admin APIs includes domain in the key\n * \"accessToken\": \"...\",\n * },\n * \"$application-id\": { // ApplicationTokenSchema\n * \"accessToken\": \"...\",\n * },\n * }\n * },\n * \"identity.spin.com\": {...}\n * }\n * ```\n */\nexport const SessionSchema = define.object({}).catchall(\n define.object({\n /**\n * It contains the identity token. Before usint it, we exchange it\n * to get a token that we can use with different applications. The exchanged\n * tokens for the applications are stored under applications.\n */\n identity: IdentityTokenSchema,\n /**\n * It contains exchanged tokens for the applications the CLI\n * authenticates with. Tokens are scoped under the fqdn of the applications.\n */\n applications: define.object({}).catchall(ApplicationTokenSchema),\n }),\n)\n\nexport type Session = define.infer<typeof SessionSchema>\nexport type IdentityToken = define.infer<typeof IdentityTokenSchema>\nexport type ApplicationToken = define.infer<typeof ApplicationTokenSchema>\n"]}
@@ -1,4 +1,4 @@
1
- import { API } from '../network/api.js';
1
+ import { API } from '../../../network/api.js';
2
2
  /**
3
3
  * Generate a flat array with all the default scopes for all the APIs plus
4
4
  * any custom scope defined by the user.
@@ -1,5 +1,5 @@
1
- import { Bug } from '../error.js';
2
- import { allAPIs } from '../network/api.js';
1
+ import { Bug } from '../../../error.js';
2
+ import { allAPIs } from '../../../network/api.js';
3
3
  /**
4
4
  * Generate a flat array with all the default scopes for all the APIs plus
5
5
  * any custom scope defined by the user.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../../../src/private/node/session/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,mBAAmB,CAAA;AACrC,OAAO,EAAC,OAAO,EAAM,MAAM,yBAAyB,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,cA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;QACzE;YACE,OAAO,KAAK,CAAA;KACf;AACH,CAAC","sourcesContent":["import {Bug} from '../../../error.js'\nimport {allAPIs, API} from '../../../network/api.js'\n\n/**\n * Generate a flat array with all the default scopes for all the APIs plus\n * any custom scope defined by the user.\n * @param extraScopes - custom user-defined scopes\n * @returns Array of scopes\n */\nexport function allDefaultScopes(extraScopes: string[] = []): string[] {\n let scopes = allAPIs.map(defaultApiScopes).flat()\n scopes = ['openid', ...scopes, ...extraScopes].map(scopeTransform)\n return Array.from(new Set(scopes))\n}\n\n/**\n * Generate a flat array with the default scopes for the given API plus\n * any custom scope defined by the user\n * @param api - API to get the scopes for\n * @param extraScopes - custom user-defined scopes\n * @returns Array of scopes\n */\nexport function apiScopes(api: API, extraScopes: string[] = []): string[] {\n const scopes = ['openid', ...defaultApiScopes(api), ...extraScopes.map(scopeTransform)].map(scopeTransform)\n return Array.from(new Set(scopes))\n}\n\nfunction defaultApiScopes(api: API): string[] {\n switch (api) {\n case 'admin':\n return ['graphql', 'themes', 'collaborator']\n case 'storefront-renderer':\n return ['devtools']\n case 'partners':\n return ['cli']\n default:\n throw new Bug(`Unknown API: ${api}`)\n }\n}\n\nfunction scopeTransform(scope: string): string {\n switch (scope) {\n case 'graphql':\n return 'https://api.shopify.com/auth/shop.admin.graphql'\n case 'themes':\n return 'https://api.shopify.com/auth/shop.admin.themes'\n case 'collaborator':\n return 'https://api.shopify.com/auth/partners.collaborator-relationships.readonly'\n case 'cli':\n return 'https://api.shopify.com/auth/partners.app.cli.access'\n case 'devtools':\n return 'https://api.shopify.com/auth/shop.storefront-renderer.devtools'\n default:\n return scope\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import { SessionSchema } from './schema.js';
2
- import constants from '../constants.js';
3
- import { platformAndArch } from '../public/node/os.js';
4
- import { store as secureStore, fetch as secureFetch, remove as secureRemove } from '../secure-store.js';
5
- import { content, debug } from '../output.js';
6
- import { getSession, removeSession, setSession, clearAllAppInfo } from '../store.js';
2
+ import constants from '../../../constants.js';
3
+ import { platformAndArch } from '../../../public/node/os.js';
4
+ import { store as secureStore, fetch as secureFetch, remove as secureRemove } from '../../../secure-store.js';
5
+ import { content, debug } from '../../../output.js';
6
+ import { getSession, removeSession, setSession, clearAllAppInfo } from '../../../store.js';
7
7
  /**
8
8
  * The identifier of the session in the secure store.
9
9
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/private/node/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;AACzC,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAC,KAAK,IAAI,WAAW,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,IAAI,YAAY,EAAC,MAAM,0BAA0B,CAAA;AAC3G,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAC,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAA;AAGxF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAgB;IAC1C,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAC3C,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,MAAM,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;KAC3C;SAAM;QACL,MAAM,UAAU,CAAC,WAAW,CAAC,CAAA;KAC9B;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK;IACzB,IAAI,OAAO,CAAA;IACX,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,OAAO,GAAG,MAAM,WAAW,CAAC,UAAU,CAAC,CAAA;KACxC;SAAM;QACL,OAAO,GAAG,MAAM,UAAU,EAAE,CAAA;KAC7B;IAED,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,SAAS,CAAA;KACjB;IACD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvC,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACrE,IAAI,aAAa,CAAC,OAAO,EAAE;QACzB,OAAO,aAAa,CAAC,IAAI,CAAA;KAC1B;SAAM;QACL,MAAM,MAAM,EAAE,CAAA;QACd,OAAO,SAAS,CAAA;KACjB;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,MAAM,YAAY,CAAC,UAAU,CAAC,CAAA;KAC/B;SAAM;QACL,MAAM,aAAa,EAAE,CAAA;KACtB;IAED,MAAM,eAAe,EAAE,CAAA;AACzB,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,oBAAoB;IACjC,IAAI;QACF,IAAI,eAAe,EAAE,CAAC,QAAQ,KAAK,SAAS,EAAE;YAC5C,KAAK,CAAC,OAAO,CAAA,uCAAuC,CAAC,CAAA;YACrD,OAAO,KAAK,CAAA;SACb;QACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAChE,KAAK,CAAC,OAAO,CAAA,2BAA2B,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;QACX,qDAAqD;KACtD;IAAC,OAAO,MAAM,EAAE;QACf,KAAK,CAAC,OAAO,CAAA,6BAA6B,CAAC,CAAA;QAC3C,OAAO,KAAK,CAAA;KACb;AACH,CAAC","sourcesContent":["import {SessionSchema} from './schema.js'\nimport constants from '../../../constants.js'\nimport {platformAndArch} from '../../../public/node/os.js'\nimport {store as secureStore, fetch as secureFetch, remove as secureRemove} from '../../../secure-store.js'\nimport {content, debug} from '../../../output.js'\nimport {getSession, removeSession, setSession, clearAllAppInfo} from '../../../store.js'\nimport type {Session} from './schema.js'\n\n/**\n * The identifier of the session in the secure store.\n */\nexport const identifier = 'session'\n\n/**\n * Serializes the session as a JSON and stores it securely in the system.\n * If the secure store is not available, the session is stored in the local config.\n * @param session - the session to store.\n */\nexport async function store(session: Session) {\n const jsonSession = JSON.stringify(session)\n if (await secureStoreAvailable()) {\n await secureStore(identifier, jsonSession)\n } else {\n await setSession(jsonSession)\n }\n}\n\n/**\n * Fetches the session from the secure store and returns it.\n * If the secure store is not available, the session is fetched from the local config.\n * If the format of the session is invalid, the method will discard it.\n * In the future might add some logic for supporting migrating the schema\n * of already-persisted sessions.\n * @returns Returns a promise that resolves with the session if it exists and is valid.\n */\nexport async function fetch(): Promise<Session | undefined> {\n let content\n if (await secureStoreAvailable()) {\n content = await secureFetch(identifier)\n } else {\n content = await getSession()\n }\n\n if (!content) {\n return undefined\n }\n const contentJson = JSON.parse(content)\n const parsedSession = await SessionSchema.safeParseAsync(contentJson)\n if (parsedSession.success) {\n return parsedSession.data\n } else {\n await remove()\n return undefined\n }\n}\n\n/**\n * Removes a session from the system.\n */\nexport async function remove() {\n if (await secureStoreAvailable()) {\n await secureRemove(identifier)\n } else {\n await removeSession()\n }\n\n await clearAllAppInfo()\n}\n\n/**\n * Returns true if the secure store is available on the system.\n * Keytar it's not supported on some Linux environments or Windows.\n * More details: https://github.com/Shopify/shopify-cli-planning/issues/261\n * @returns a boolean indicating if the secure store is available.\n */\nasync function secureStoreAvailable(): Promise<boolean> {\n try {\n if (platformAndArch().platform === 'windows') {\n debug(content`Secure store not supported on Windows`)\n return false\n }\n const keytar = await import('keytar')\n await keytar.default.findCredentials(constants.keychain.service)\n debug(content`Secure store is available`)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (_error) {\n debug(content`Failed to load secure store`)\n return false\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { applicationId } from './identity.js';
2
- import constants from '../constants.js';
3
- import { identity } from '../api.js';
4
- import { debug } from '../output.js';
5
- import { firstPartyDev } from '../environment/local.js';
2
+ import { validateIdentityToken } from './identity-token-validation.js';
3
+ import constants from '../../../constants.js';
4
+ import { debug } from '../../../output.js';
5
+ import { firstPartyDev } from '../../../public/node/environment/local.js';
6
6
  /**
7
7
  * Validate if an identity token is valid for the requested scopes
8
8
  */
@@ -23,7 +23,7 @@ export async function validateSession(scopes, applications, session) {
23
23
  if (!session)
24
24
  return 'needs_full_auth';
25
25
  const scopesAreValid = validateScopes(scopes, session.identity);
26
- const identityIsValid = await identity.validateIdentityToken(session.identity.accessToken);
26
+ const identityIsValid = await validateIdentityToken(session.identity.accessToken);
27
27
  if (!scopesAreValid)
28
28
  return 'needs_full_auth';
29
29
  let tokensAreExpired = isTokenExpired(session.identity);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/private/node/session/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAA;AACpE,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAC,aAAa,EAAC,MAAM,2CAA2C,CAAA;AAKvE;;GAEG;AACH,SAAS,cAAc,CAAC,eAAyB,EAAE,QAAuB;IACxE,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAA;IACrC,IAAI,aAAa,EAAE,KAAK,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAA;IACxE,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,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C7D;IAED,KAAK,CAAC;;kBAEU,gBAAgB;8BACJ,CAAC,eAAe;GAC3C,CAAC,CAAA;IAEF,IAAI,gBAAgB;QAAE,OAAO,eAAe,CAAA;IAC5C,IAAI,CAAC,eAAe;QAAE,OAAO,iBAAiB,CAAA;IAC9C,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,cAAc,CAAC,KAAuB;IAC7C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,OAAO,KAAK,CAAC,SAAS,GAAG,eAAe,EAAE,CAAA;AAC5C,CAAC;AAED,SAAS,eAAe;IACtB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,6BAA6B,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;AAC3F,CAAC","sourcesContent":["import {applicationId} from './identity.js'\nimport {ApplicationToken, IdentityToken} from './schema.js'\nimport {validateIdentityToken} from './identity-token-validation.js'\nimport constants from '../../../constants.js'\nimport {debug} from '../../../output.js'\nimport {firstPartyDev} from '../../../public/node/environment/local.js'\nimport {OAuthApplications} from '../session.js'\n\ntype ValidationResult = 'needs_refresh' | 'needs_full_auth' | 'ok'\n\n/**\n * Validate if an identity token is valid for the requested scopes\n */\nfunction validateScopes(requestedScopes: string[], identity: IdentityToken) {\n const currentScopes = identity.scopes\n if (firstPartyDev() !== currentScopes.includes('employee')) return false\n return requestedScopes.every((scope) => currentScopes.includes(scope))\n}\n\n/**\n * Validate if the current session is valid or we need to refresh/re-authenticate\n * @param scopes - requested scopes to validate\n * @param applications - requested applications\n * @param session - current session with identity and application tokens\n * @returns 'ok' if the session is valid, 'needs_full_auth' if we need to re-authenticate, 'needs_refresh' if we need to refresh the session\n */\nexport async function validateSession(\n scopes: string[],\n applications: OAuthApplications,\n session: {\n identity: IdentityToken\n applications: {[x: string]: ApplicationToken}\n },\n): Promise<ValidationResult> {\n if (!session) return 'needs_full_auth'\n const scopesAreValid = validateScopes(scopes, session.identity)\n const identityIsValid = await validateIdentityToken(session.identity.accessToken)\n if (!scopesAreValid) return 'needs_full_auth'\n let tokensAreExpired = isTokenExpired(session.identity)\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n const token = session.applications[appId]!\n tokensAreExpired = tokensAreExpired || isTokenExpired(token)\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n const token = session.applications[appId]!\n tokensAreExpired = tokensAreExpired || isTokenExpired(token)\n }\n\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = session.applications[realAppId]!\n tokensAreExpired = tokensAreExpired || isTokenExpired(token)\n }\n\n debug(`\nThe validation of the token for application/identity completed with the following results:\n- It's expired: ${tokensAreExpired}\n- It's invalid in identity: ${!identityIsValid}\n `)\n\n if (tokensAreExpired) return 'needs_refresh'\n if (!identityIsValid) return 'needs_full_auth'\n return 'ok'\n}\n\nfunction isTokenExpired(token: ApplicationToken): boolean {\n if (!token) return true\n return token.expiresAt < expireThreshold()\n}\n\nfunction expireThreshold(): Date {\n return new Date(Date.now() + constants.session.expirationTimeMarginInMinutes * 60 * 1000)\n}\n"]}
@@ -0,0 +1,56 @@
1
+ /// <reference types="node" />
2
+ import { AdminSession } from '@shopify/cli-kit/node/session';
3
+ /**
4
+ * A scope supported by the Shopify Admin API.
5
+ */
6
+ declare type AdminAPIScope = 'graphql' | 'themes' | 'collaborator' | string;
7
+ /**
8
+ * It represents the options to authenticate against the Shopify Admin API.
9
+ */
10
+ interface AdminAPIOAuthOptions {
11
+ /** Store to request permissions for. */
12
+ storeFqdn: string;
13
+ /** List of scopes to request permissions for. */
14
+ scopes: AdminAPIScope[];
15
+ }
16
+ /**
17
+ * A scope supported by the Partners API.
18
+ */
19
+ declare type PartnersAPIScope = 'cli' | string;
20
+ interface PartnersAPIOAuthOptions {
21
+ /** List of scopes to request permissions for. */
22
+ scopes: PartnersAPIScope[];
23
+ }
24
+ /**
25
+ * A scope supported by the Storefront Renderer API.
26
+ */
27
+ declare type StorefrontRendererScope = 'devtools' | string;
28
+ interface StorefrontRendererAPIOAuthOptions {
29
+ /** List of scopes to request permissions for. */
30
+ scopes: StorefrontRendererScope[];
31
+ }
32
+ /**
33
+ * It represents the authentication requirements and
34
+ * is the input necessary to trigger the authentication
35
+ * flow.
36
+ */
37
+ export interface OAuthApplications {
38
+ adminApi?: AdminAPIOAuthOptions;
39
+ storefrontRendererApi?: StorefrontRendererAPIOAuthOptions;
40
+ partnersApi?: PartnersAPIOAuthOptions;
41
+ }
42
+ export interface OAuthSession {
43
+ admin?: AdminSession;
44
+ partners?: string;
45
+ storefront?: string;
46
+ }
47
+ /**
48
+ * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
49
+ *
50
+ * @param applications - An object containing the applications we need to be authenticated with.
51
+ * @param env - Optional environment variables to use.
52
+ * @param forceRefresh - Optional flag to force a refresh of the token.
53
+ * @returns An instance with the access tokens organized by application.
54
+ */
55
+ export declare function ensureAuthenticated(applications: OAuthApplications, env?: NodeJS.ProcessEnv, forceRefresh?: boolean): Promise<OAuthSession>;
56
+ export {};