@shopify/cli-kit 3.68.1 → 3.69.1

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 (162) hide show
  1. package/dist/cli/api/graphql/admin/generated/public_api_versions.d.ts +14 -0
  2. package/dist/cli/api/graphql/admin/generated/public_api_versions.js +28 -0
  3. package/dist/cli/api/graphql/admin/generated/public_api_versions.js.map +1 -0
  4. package/dist/private/node/api/graphql.d.ts +1 -1
  5. package/dist/private/node/api/graphql.js +1 -0
  6. package/dist/private/node/api/graphql.js.map +1 -1
  7. package/dist/private/node/api/headers.js +2 -2
  8. package/dist/private/node/api/headers.js.map +1 -1
  9. package/dist/private/node/api/rest.js +3 -1
  10. package/dist/private/node/api/rest.js.map +1 -1
  11. package/dist/private/node/api.d.ts +2 -2
  12. package/dist/private/node/api.js +8 -6
  13. package/dist/private/node/api.js.map +1 -1
  14. package/dist/private/node/constants.d.ts +0 -1
  15. package/dist/private/node/constants.js +0 -1
  16. package/dist/private/node/constants.js.map +1 -1
  17. package/dist/private/node/demo-recorder.js +1 -0
  18. package/dist/private/node/demo-recorder.js.map +1 -1
  19. package/dist/private/node/session/device-authorization.js +15 -7
  20. package/dist/private/node/session/device-authorization.js.map +1 -1
  21. package/dist/private/node/session/exchange.d.ts +0 -8
  22. package/dist/private/node/session/exchange.js +2 -19
  23. package/dist/private/node/session/exchange.js.map +1 -1
  24. package/dist/private/node/session/validate.js +1 -0
  25. package/dist/private/node/session/validate.js.map +1 -1
  26. package/dist/private/node/session.d.ts +5 -5
  27. package/dist/private/node/session.js +4 -12
  28. package/dist/private/node/session.js.map +1 -1
  29. package/dist/private/node/testing/ui.js +0 -3
  30. package/dist/private/node/testing/ui.js.map +1 -1
  31. package/dist/private/node/themes/generate-theme-name.js +1 -0
  32. package/dist/private/node/themes/generate-theme-name.js.map +1 -1
  33. package/dist/private/node/ui/components/AutocompletePrompt.test.js +0 -3
  34. package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
  35. package/dist/private/node/ui/components/Banner.js +1 -0
  36. package/dist/private/node/ui/components/Banner.js.map +1 -1
  37. package/dist/private/node/ui/components/ConcurrentOutput.test.js +7 -7
  38. package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
  39. package/dist/private/node/ui/components/FatalError.js +1 -0
  40. package/dist/private/node/ui/components/FatalError.js.map +1 -1
  41. package/dist/private/node/ui/components/List.js +1 -1
  42. package/dist/private/node/ui/components/List.js.map +1 -1
  43. package/dist/private/node/ui/components/Prompts/InfoTable.js +1 -0
  44. package/dist/private/node/ui/components/Prompts/InfoTable.js.map +1 -1
  45. package/dist/private/node/ui/components/SelectInput.js +1 -1
  46. package/dist/private/node/ui/components/SelectInput.js.map +1 -1
  47. package/dist/private/node/ui/components/SelectPrompt.test.js +0 -4
  48. package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
  49. package/dist/private/node/ui/components/Table/Row.js.map +1 -1
  50. package/dist/private/node/ui/components/Tasks.js +2 -1
  51. package/dist/private/node/ui/components/Tasks.js.map +1 -1
  52. package/dist/private/node/ui/components/TextPrompt.d.ts +1 -1
  53. package/dist/private/node/ui/components/TextPrompt.js.map +1 -1
  54. package/dist/private/node/ui/components/TokenizedText.js +1 -0
  55. package/dist/private/node/ui/components/TokenizedText.js.map +1 -1
  56. package/dist/private/node/ui/hooks/use-abort-signal.js +1 -1
  57. package/dist/private/node/ui/hooks/use-abort-signal.js.map +1 -1
  58. package/dist/private/node/ui.js +3 -1
  59. package/dist/private/node/ui.js.map +1 -1
  60. package/dist/public/common/array.js +1 -0
  61. package/dist/public/common/array.js.map +1 -1
  62. package/dist/public/common/string.js +3 -0
  63. package/dist/public/common/string.js.map +1 -1
  64. package/dist/public/common/version.d.ts +1 -1
  65. package/dist/public/common/version.js +1 -1
  66. package/dist/public/common/version.js.map +1 -1
  67. package/dist/public/node/api/admin.d.ts +14 -1
  68. package/dist/public/node/api/admin.js +40 -31
  69. package/dist/public/node/api/admin.js.map +1 -1
  70. package/dist/public/node/api/app-management.d.ts +5 -3
  71. package/dist/public/node/api/app-management.js +16 -11
  72. package/dist/public/node/api/app-management.js.map +1 -1
  73. package/dist/public/node/api/graphql.js +13 -1
  74. package/dist/public/node/api/graphql.js.map +1 -1
  75. package/dist/public/node/api/rest-api-throttler.js +10 -3
  76. package/dist/public/node/api/rest-api-throttler.js.map +1 -1
  77. package/dist/public/node/archiver.js +6 -2
  78. package/dist/public/node/archiver.js.map +1 -1
  79. package/dist/public/node/base-command.js +1 -1
  80. package/dist/public/node/base-command.js.map +1 -1
  81. package/dist/public/node/context/local.d.ts +0 -9
  82. package/dist/public/node/context/local.js +0 -13
  83. package/dist/public/node/context/local.js.map +1 -1
  84. package/dist/public/node/context/spin.js +1 -1
  85. package/dist/public/node/context/spin.js.map +1 -1
  86. package/dist/public/node/custom-oclif-loader.js +5 -4
  87. package/dist/public/node/custom-oclif-loader.js.map +1 -1
  88. package/dist/public/node/dot-env.js +2 -1
  89. package/dist/public/node/dot-env.js.map +1 -1
  90. package/dist/public/node/environments.js +1 -1
  91. package/dist/public/node/environments.js.map +1 -1
  92. package/dist/public/node/error-handler.js +3 -3
  93. package/dist/public/node/error-handler.js.map +1 -1
  94. package/dist/public/node/error.d.ts +3 -3
  95. package/dist/public/node/error.js +29 -3
  96. package/dist/public/node/error.js.map +1 -1
  97. package/dist/public/node/framework.js +5 -4
  98. package/dist/public/node/framework.js.map +1 -1
  99. package/dist/public/node/fs.d.ts +1 -1
  100. package/dist/public/node/fs.js +1 -1
  101. package/dist/public/node/fs.js.map +1 -1
  102. package/dist/public/node/git.js +2 -0
  103. package/dist/public/node/git.js.map +1 -1
  104. package/dist/public/node/github.js +2 -0
  105. package/dist/public/node/github.js.map +1 -1
  106. package/dist/public/node/hooks/deprecations.js +1 -1
  107. package/dist/public/node/hooks/deprecations.js.map +1 -1
  108. package/dist/public/node/hooks/postrun.js +2 -1
  109. package/dist/public/node/hooks/postrun.js.map +1 -1
  110. package/dist/public/node/hooks/prerun.js +1 -1
  111. package/dist/public/node/hooks/prerun.js.map +1 -1
  112. package/dist/public/node/http.js +2 -1
  113. package/dist/public/node/http.js.map +1 -1
  114. package/dist/public/node/json-schema.d.ts +1 -1
  115. package/dist/public/node/json-schema.js.map +1 -1
  116. package/dist/public/node/liquid.js +12 -2
  117. package/dist/public/node/liquid.js.map +1 -1
  118. package/dist/public/node/metadata.js +1 -0
  119. package/dist/public/node/metadata.js.map +1 -1
  120. package/dist/public/node/monorail.d.ts +2 -1
  121. package/dist/public/node/monorail.js +1 -1
  122. package/dist/public/node/monorail.js.map +1 -1
  123. package/dist/public/node/output.js +2 -1
  124. package/dist/public/node/output.js.map +1 -1
  125. package/dist/public/node/ruby.js +1 -0
  126. package/dist/public/node/ruby.js.map +1 -1
  127. package/dist/public/node/session.d.ts +7 -6
  128. package/dist/public/node/session.js +2 -1
  129. package/dist/public/node/session.js.map +1 -1
  130. package/dist/public/node/system.js +1 -1
  131. package/dist/public/node/system.js.map +1 -1
  132. package/dist/public/node/themes/api.js +34 -4
  133. package/dist/public/node/themes/api.js.map +1 -1
  134. package/dist/public/node/themes/factories.js +1 -0
  135. package/dist/public/node/themes/factories.js.map +1 -1
  136. package/dist/public/node/themes/types.d.ts +2 -3
  137. package/dist/public/node/themes/types.js.map +1 -1
  138. package/dist/public/node/themes/urls.d.ts +1 -0
  139. package/dist/public/node/themes/urls.js +3 -0
  140. package/dist/public/node/themes/urls.js.map +1 -1
  141. package/dist/public/node/tree-kill.js +8 -4
  142. package/dist/public/node/tree-kill.js.map +1 -1
  143. package/dist/public/node/ui.js +5 -2
  144. package/dist/public/node/ui.js.map +1 -1
  145. package/dist/tsconfig.tsbuildinfo +1 -1
  146. package/package.json +1 -5
  147. package/assets/auth-error.html +0 -23
  148. package/assets/empty-url.html +0 -23
  149. package/assets/favicon.svg +0 -26
  150. package/assets/missing-code.html +0 -23
  151. package/assets/missing-state.html +0 -23
  152. package/assets/style.css +0 -58
  153. package/assets/success.html +0 -20
  154. package/dist/private/node/session/authorize.d.ts +0 -5
  155. package/dist/private/node/session/authorize.js +0 -69
  156. package/dist/private/node/session/authorize.js.map +0 -1
  157. package/dist/private/node/session/post-auth.d.ts +0 -10
  158. package/dist/private/node/session/post-auth.js +0 -61
  159. package/dist/private/node/session/post-auth.js.map +0 -1
  160. package/dist/private/node/session/redirect-listener.d.ts +0 -34
  161. package/dist/private/node/session/redirect-listener.js +0 -105
  162. package/dist/private/node/session/redirect-listener.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
+ import { AdminAPIScope, AppManagementAPIScope, BusinessPlatformScope, PartnersAPIScope, StorefrontRendererScope } from '../../private/node/session.js';
2
3
  /**
3
4
  * Session Object to access the Admin API, includes the token and the store FQDN.
4
5
  */
@@ -19,7 +20,7 @@ interface EnsureAuthenticatedAdditionalOptions {
19
20
  * @param options - Optional extra options to use.
20
21
  * @returns The access token for the Partners API.
21
22
  */
22
- export declare function ensureAuthenticatedPartners(scopes?: string[], env?: NodeJS.ProcessEnv, options?: EnsureAuthenticatedAdditionalOptions): Promise<{
23
+ export declare function ensureAuthenticatedPartners(scopes?: PartnersAPIScope[], env?: NodeJS.ProcessEnv, options?: EnsureAuthenticatedAdditionalOptions): Promise<{
23
24
  token: string;
24
25
  userId: string;
25
26
  }>;
@@ -31,7 +32,7 @@ export declare function ensureAuthenticatedPartners(scopes?: string[], env?: Nod
31
32
  * @param options - Optional extra options to use.
32
33
  * @returns The access token for the App Management API.
33
34
  */
34
- export declare function ensureAuthenticatedAppManagement(scopes?: string[], env?: NodeJS.ProcessEnv, options?: EnsureAuthenticatedAdditionalOptions): Promise<{
35
+ export declare function ensureAuthenticatedAppManagement(scopes?: AppManagementAPIScope[], env?: NodeJS.ProcessEnv, options?: EnsureAuthenticatedAdditionalOptions): Promise<{
35
36
  token: string;
36
37
  userId: string;
37
38
  }>;
@@ -43,7 +44,7 @@ export declare function ensureAuthenticatedAppManagement(scopes?: string[], env?
43
44
  * @param forceRefresh - Optional flag to force a refresh of the token.
44
45
  * @returns The access token for the Storefront API.
45
46
  */
46
- export declare function ensureAuthenticatedStorefront(scopes?: string[], password?: string | undefined, forceRefresh?: boolean): Promise<string>;
47
+ export declare function ensureAuthenticatedStorefront(scopes?: StorefrontRendererScope[], password?: string | undefined, forceRefresh?: boolean): Promise<string>;
47
48
  /**
48
49
  * Ensure that we have a valid Admin session for the given store.
49
50
  *
@@ -53,7 +54,7 @@ export declare function ensureAuthenticatedStorefront(scopes?: string[], passwor
53
54
  * @param options - Optional extra options to use.
54
55
  * @returns The access token for the Admin API.
55
56
  */
56
- export declare function ensureAuthenticatedAdmin(store: string, scopes?: string[], forceRefresh?: boolean, options?: EnsureAuthenticatedAdditionalOptions): Promise<AdminSession>;
57
+ export declare function ensureAuthenticatedAdmin(store: string, scopes?: AdminAPIScope[], forceRefresh?: boolean, options?: EnsureAuthenticatedAdditionalOptions): Promise<AdminSession>;
57
58
  /**
58
59
  * Ensure that we have a valid session to access the Theme API.
59
60
  * If a password is provided, that token will be used against Theme Access API.
@@ -65,14 +66,14 @@ export declare function ensureAuthenticatedAdmin(store: string, scopes?: string[
65
66
  * @param forceRefresh - Optional flag to force a refresh of the token.
66
67
  * @returns The access token and store.
67
68
  */
68
- export declare function ensureAuthenticatedThemes(store: string, password: string | undefined, scopes?: string[], forceRefresh?: boolean): Promise<AdminSession>;
69
+ export declare function ensureAuthenticatedThemes(store: string, password: string | undefined, scopes?: AdminAPIScope[], forceRefresh?: boolean): Promise<AdminSession>;
69
70
  /**
70
71
  * Ensure that we have a valid session to access the Business Platform API.
71
72
  *
72
73
  * @param scopes - Optional array of extra scopes to authenticate with.
73
74
  * @returns The access token for the Business Platform API.
74
75
  */
75
- export declare function ensureAuthenticatedBusinessPlatform(scopes?: string[]): Promise<string>;
76
+ export declare function ensureAuthenticatedBusinessPlatform(scopes?: BusinessPlatformScope[]): Promise<string>;
76
77
  /**
77
78
  * Logout from Shopify.
78
79
  *
@@ -5,7 +5,7 @@ import { nonRandomUUID } from './crypto.js';
5
5
  import * as secureStore from '../../private/node/session/store.js';
6
6
  import { exchangeCustomPartnerToken } from '../../private/node/session/exchange.js';
7
7
  import { outputContent, outputToken, outputDebug } from '../../public/node/output.js';
8
- import { ensureAuthenticated, setLastSeenAuthMethod, setLastSeenUserIdAfterAuth } from '../../private/node/session.js';
8
+ import { ensureAuthenticated, setLastSeenAuthMethod, setLastSeenUserIdAfterAuth, } from '../../private/node/session.js';
9
9
  import { isThemeAccessSession } from '../../private/node/api/rest.js';
10
10
  /**
11
11
  * Ensure that we have a valid session to access the Partners API.
@@ -48,6 +48,7 @@ ${outputToken.json(scopes)}
48
48
  if (!tokens) {
49
49
  throw new BugError('No App Management token found after ensuring authenticated');
50
50
  }
51
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
52
  return { token: tokens.appManagement, userId: tokens.userId };
52
53
  }
53
54
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/public/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAA;AACnC,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,WAAW,MAAM,qCAAqC,CAAA;AAClE,OAAO,EAAC,0BAA0B,EAAC,MAAM,wCAAwC,CAAA;AACjF,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,EAAC,mBAAmB,EAAE,qBAAqB,EAAE,0BAA0B,EAAC,MAAM,+BAA+B,CAAA;AACpH,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAA;AAcnE;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,C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AAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;QAC5B,MAAM,IAAI,QAAQ,CAAC,+DAA+D,CAAC,CAAA;KACpF;IACD,OAAO,MAAM,CAAC,gBAAgB,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,WAAW,CAAC,MAAM,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import {normalizeStoreFqdn} from './context/fqdn.js'\nimport {BugError} from './error.js'\nimport {getPartnersToken} from './environment.js'\nimport {nonRandomUUID} from './crypto.js'\nimport * as secureStore from '../../private/node/session/store.js'\nimport {exchangeCustomPartnerToken} from '../../private/node/session/exchange.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport {ensureAuthenticated, setLastSeenAuthMethod, setLastSeenUserIdAfterAuth} from '../../private/node/session.js'\nimport {isThemeAccessSession} from '../../private/node/api/rest.js'\n\n/**\n * Session Object to access the Admin API, includes the token and the store FQDN.\n */\nexport interface AdminSession {\n token: string\n storeFqdn: string\n}\n\ninterface EnsureAuthenticatedAdditionalOptions {\n noPrompt?: boolean\n}\n\n/**\n * Ensure that we have a valid session to access the Partners API.\n * If SHOPIFY_CLI_PARTNERS_TOKEN exists, that token will be used to obtain a valid Partners Token\n * If SHOPIFY_CLI_PARTNERS_TOKEN exists, scopes will be ignored.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param env - Optional environment variables to use.\n * @param options - Optional extra options to use.\n * @returns The access token for the Partners API.\n */\nexport async function ensureAuthenticatedPartners(\n scopes: string[] = [],\n env = process.env,\n options: EnsureAuthenticatedAdditionalOptions = {},\n): Promise<{token: string; userId: string}> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Partners API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const envToken = getPartnersToken()\n if (envToken) {\n const result = await exchangeCustomPartnerToken(envToken)\n return {token: result.accessToken, userId: result.userId}\n }\n const tokens = await ensureAuthenticated({partnersApi: {scopes}}, env, options)\n if (!tokens.partners) {\n throw new BugError('No partners token found after ensuring authenticated')\n }\n return {token: tokens.partners, userId: tokens.userId}\n}\n\n/**\n * Ensure that we have a valid session to access the App Management API.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param env - Optional environment variables to use.\n * @param options - Optional extra options to use.\n * @returns The access token for the App Management API.\n */\nexport async function ensureAuthenticatedAppManagement(\n scopes: string[] = [],\n env = process.env,\n options: EnsureAuthenticatedAdditionalOptions = {},\n): Promise<{token: string; userId: string}> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the App Management API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({appManagementApi: {scopes}}, env, options)\n if (!tokens) {\n throw new BugError('No App Management token found after ensuring authenticated')\n }\n return {token: tokens.appManagement!, userId: tokens.userId}\n}\n\n/**\n * Ensure that we have a valid session to access the Storefront API.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param password - Optional password to use.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns The access token for the Storefront API.\n */\nexport async function ensureAuthenticatedStorefront(\n scopes: string[] = [],\n password: string | undefined = undefined,\n forceRefresh = false,\n): Promise<string> {\n if (password) {\n const session = {token: password, storeFqdn: ''}\n const authMethod = isThemeAccessSession(session) ? 'theme_access_token' : 'custom_app_token'\n setLastSeenAuthMethod(authMethod)\n setLastSeenUserIdAfterAuth(nonRandomUUID(password))\n return password\n }\n\n outputDebug(outputContent`Ensuring that the user is authenticated with the Storefront API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({storefrontRendererApi: {scopes}}, process.env, {forceRefresh})\n if (!tokens.storefront) {\n throw new BugError('No storefront token found after ensuring authenticated')\n }\n return tokens.storefront\n}\n\n/**\n * Ensure that we have a valid Admin session for the given store.\n *\n * @param store - Store fqdn to request auth for.\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @param options - Optional extra options to use.\n * @returns The access token for the Admin API.\n */\nexport async function ensureAuthenticatedAdmin(\n store: string,\n scopes: string[] = [],\n forceRefresh = false,\n options: EnsureAuthenticatedAdditionalOptions = {},\n): Promise<AdminSession> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Admin API with the following scopes for the store ${outputToken.raw(\n store,\n )}:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({adminApi: {scopes, storeFqdn: store}}, process.env, {\n forceRefresh,\n ...options,\n })\n if (!tokens.admin) {\n throw new BugError('No admin token found after ensuring authenticated')\n }\n return tokens.admin\n}\n\n/**\n * Ensure that we have a valid session to access the Theme API.\n * If a password is provided, that token will be used against Theme Access API.\n * Otherwise, it will ensure that the user is authenticated with the Admin API.\n *\n * @param store - Store fqdn to request auth for.\n * @param password - Password generated from Theme Access app.\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns The access token and store.\n */\nexport async function ensureAuthenticatedThemes(\n store: string,\n password: string | undefined,\n scopes: string[] = [],\n forceRefresh = false,\n): Promise<AdminSession> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Theme API with the following scopes:\n${outputToken.json(scopes)}\n`)\n if (password) {\n const session = {token: password, storeFqdn: await normalizeStoreFqdn(store)}\n const authMethod = isThemeAccessSession(session) ? 'theme_access_token' : 'custom_app_token'\n setLastSeenAuthMethod(authMethod)\n setLastSeenUserIdAfterAuth(nonRandomUUID(password))\n return session\n }\n return ensureAuthenticatedAdmin(store, scopes, forceRefresh)\n}\n\n/**\n * Ensure that we have a valid session to access the Business Platform API.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Business Platform API.\n */\nexport async function ensureAuthenticatedBusinessPlatform(scopes: string[] = []): Promise<string> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Business Platform API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({businessPlatformApi: {scopes}}, process.env)\n if (!tokens.businessPlatform) {\n throw new BugError('No business-platform token found after ensuring authenticated')\n }\n return tokens.businessPlatform\n}\n\n/**\n * Logout from Shopify.\n *\n * @returns A promise that resolves when the logout is complete.\n */\nexport function logout(): Promise<void> {\n return secureStore.remove()\n}\n"]}
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/public/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAA;AACnC,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,WAAW,MAAM,qCAAqC,CAAA;AAClE,OAAO,EAAC,0BAA0B,EAAC,MAAM,wCAAwC,CAAA;AACjF,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,EAML,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAA;AAcnE;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,SAA6B,EAAE,EAC/B,GAAG,GAAG,OAAO,CAAC,GAAG,EACjB,UAAgD,EAAE;IAElD,WAAW,CAAC,aAAa,CAAA;EACzB,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;CACzB,CAAC,CAAA;IACA,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAA;IACnC,IAAI,QAAQ,EAAE;QACZ,MAAM,MAAM,GAAG,MAAM,0BAA0B,CAAC,QAAQ,CAAC,CAAA;QACzD,OAAO,EAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAC,CAAA;KAC1D;IACD,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAA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zB,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;CACzB,CAAC,CAAA;IACA,IAAI,QAAQ,EAAE;QACZ,MAAM,OAAO,GAAG,EAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC,KAAK,CAAC,EAAC,CAAA;QAC7E,MAAM,UAAU,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,kBAAkB,CAAA;QAC5F,qBAAqB,CAAC,UAAU,CAAC,CAAA;QACjC,0BAA0B,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAA;QACnD,OAAO,OAAO,CAAA;KACf;IACD,OAAO,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mCAAmC,CAAC,SAAkC,EAAE;IAC5F,WAAW,CAAC,aAAa,CAAA;EACzB,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;CACzB,CAAC,CAAA;IACA,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,EAAC,mBAAmB,EAAE,EAAC,MAAM,EAAC,EAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IACtF,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;QAC5B,MAAM,IAAI,QAAQ,CAAC,+DAA+D,CAAC,CAAA;KACpF;IACD,OAAO,MAAM,CAAC,gBAAgB,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,WAAW,CAAC,MAAM,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import {normalizeStoreFqdn} from './context/fqdn.js'\nimport {BugError} from './error.js'\nimport {getPartnersToken} from './environment.js'\nimport {nonRandomUUID} from './crypto.js'\nimport * as secureStore from '../../private/node/session/store.js'\nimport {exchangeCustomPartnerToken} from '../../private/node/session/exchange.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport {\n AdminAPIScope,\n AppManagementAPIScope,\n BusinessPlatformScope,\n PartnersAPIScope,\n StorefrontRendererScope,\n ensureAuthenticated,\n setLastSeenAuthMethod,\n setLastSeenUserIdAfterAuth,\n} from '../../private/node/session.js'\nimport {isThemeAccessSession} from '../../private/node/api/rest.js'\n\n/**\n * Session Object to access the Admin API, includes the token and the store FQDN.\n */\nexport interface AdminSession {\n token: string\n storeFqdn: string\n}\n\ninterface EnsureAuthenticatedAdditionalOptions {\n noPrompt?: boolean\n}\n\n/**\n * Ensure that we have a valid session to access the Partners API.\n * If SHOPIFY_CLI_PARTNERS_TOKEN exists, that token will be used to obtain a valid Partners Token\n * If SHOPIFY_CLI_PARTNERS_TOKEN exists, scopes will be ignored.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param env - Optional environment variables to use.\n * @param options - Optional extra options to use.\n * @returns The access token for the Partners API.\n */\nexport async function ensureAuthenticatedPartners(\n scopes: PartnersAPIScope[] = [],\n env = process.env,\n options: EnsureAuthenticatedAdditionalOptions = {},\n): Promise<{token: string; userId: string}> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Partners API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const envToken = getPartnersToken()\n if (envToken) {\n const result = await exchangeCustomPartnerToken(envToken)\n return {token: result.accessToken, userId: result.userId}\n }\n const tokens = await ensureAuthenticated({partnersApi: {scopes}}, env, options)\n if (!tokens.partners) {\n throw new BugError('No partners token found after ensuring authenticated')\n }\n return {token: tokens.partners, userId: tokens.userId}\n}\n\n/**\n * Ensure that we have a valid session to access the App Management API.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param env - Optional environment variables to use.\n * @param options - Optional extra options to use.\n * @returns The access token for the App Management API.\n */\nexport async function ensureAuthenticatedAppManagement(\n scopes: AppManagementAPIScope[] = [],\n env = process.env,\n options: EnsureAuthenticatedAdditionalOptions = {},\n): Promise<{token: string; userId: string}> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the App Management API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({appManagementApi: {scopes}}, env, options)\n if (!tokens) {\n throw new BugError('No App Management token found after ensuring authenticated')\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return {token: tokens.appManagement!, userId: tokens.userId}\n}\n\n/**\n * Ensure that we have a valid session to access the Storefront API.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param password - Optional password to use.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns The access token for the Storefront API.\n */\nexport async function ensureAuthenticatedStorefront(\n scopes: StorefrontRendererScope[] = [],\n password: string | undefined = undefined,\n forceRefresh = false,\n): Promise<string> {\n if (password) {\n const session = {token: password, storeFqdn: ''}\n const authMethod = isThemeAccessSession(session) ? 'theme_access_token' : 'custom_app_token'\n setLastSeenAuthMethod(authMethod)\n setLastSeenUserIdAfterAuth(nonRandomUUID(password))\n return password\n }\n\n outputDebug(outputContent`Ensuring that the user is authenticated with the Storefront API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({storefrontRendererApi: {scopes}}, process.env, {forceRefresh})\n if (!tokens.storefront) {\n throw new BugError('No storefront token found after ensuring authenticated')\n }\n return tokens.storefront\n}\n\n/**\n * Ensure that we have a valid Admin session for the given store.\n *\n * @param store - Store fqdn to request auth for.\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @param options - Optional extra options to use.\n * @returns The access token for the Admin API.\n */\nexport async function ensureAuthenticatedAdmin(\n store: string,\n scopes: AdminAPIScope[] = [],\n forceRefresh = false,\n options: EnsureAuthenticatedAdditionalOptions = {},\n): Promise<AdminSession> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Admin API with the following scopes for the store ${outputToken.raw(\n store,\n )}:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({adminApi: {scopes, storeFqdn: store}}, process.env, {\n forceRefresh,\n ...options,\n })\n if (!tokens.admin) {\n throw new BugError('No admin token found after ensuring authenticated')\n }\n return tokens.admin\n}\n\n/**\n * Ensure that we have a valid session to access the Theme API.\n * If a password is provided, that token will be used against Theme Access API.\n * Otherwise, it will ensure that the user is authenticated with the Admin API.\n *\n * @param store - Store fqdn to request auth for.\n * @param password - Password generated from Theme Access app.\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns The access token and store.\n */\nexport async function ensureAuthenticatedThemes(\n store: string,\n password: string | undefined,\n scopes: AdminAPIScope[] = [],\n forceRefresh = false,\n): Promise<AdminSession> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Theme API with the following scopes:\n${outputToken.json(scopes)}\n`)\n if (password) {\n const session = {token: password, storeFqdn: await normalizeStoreFqdn(store)}\n const authMethod = isThemeAccessSession(session) ? 'theme_access_token' : 'custom_app_token'\n setLastSeenAuthMethod(authMethod)\n setLastSeenUserIdAfterAuth(nonRandomUUID(password))\n return session\n }\n return ensureAuthenticatedAdmin(store, scopes, forceRefresh)\n}\n\n/**\n * Ensure that we have a valid session to access the Business Platform API.\n *\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Business Platform API.\n */\nexport async function ensureAuthenticatedBusinessPlatform(scopes: BusinessPlatformScope[] = []): Promise<string> {\n outputDebug(outputContent`Ensuring that the user is authenticated with the Business Platform API with the following scopes:\n${outputToken.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({businessPlatformApi: {scopes}}, process.env)\n if (!tokens.businessPlatform) {\n throw new BugError('No business-platform token found after ensuring authenticated')\n }\n return tokens.businessPlatform\n}\n\n/**\n * Logout from Shopify.\n *\n * @returns A promise that resolves when the logout is complete.\n */\nexport function logout(): Promise<void> {\n return secureStore.remove()\n}\n"]}
@@ -59,7 +59,7 @@ export async function exec(command, args, options) {
59
59
  if (aborted)
60
60
  return;
61
61
  if (options?.externalErrorHandler) {
62
- await options?.externalErrorHandler(processError);
62
+ await options.externalErrorHandler(processError);
63
63
  }
64
64
  else {
65
65
  const abortError = new ExternalError(processError.message, command, args);
@@ -1 +1 @@
1
- {"version":3,"file":"system.js","sourceRoot":"","sources":["../../../src/public/node/system.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAA;AACxC,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAC,mBAAmB,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAC5E,OAAO,EAAC,KAAK,EAAoB,MAAM,OAAO,CAAA;AAgB9C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAW;IACvC,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAA;IACzC,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACjC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAe,EAAE,IAAc,EAAE,OAAqB;IACxF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACtD,OAAO,MAAM,CAAC,MAAM,CAAA;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,OAAe,EAAE,IAAc,EAAE,OAAqB;IAC/E,MAAM,cAAc,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACxD,IAAI,OAAO,EAAE,MAAM,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE;QACnD,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAC,GAAG,EAAE,KAAK,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,CAAC,WAAW,GAAG,GAAG,CAAA;KACtB;IACD,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE;QAC1C,GAAG;QACH,GAAG,EAAE,OAAO,EAAE,GAAG;QACjB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC7D,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC7D,mEAAmE;QACnE,mDAAmD;QACnD,WAAW,EAAE,KAAK;KACnB,CAAC,CAAA;IACF,WAAW,CAAC;;eAEC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;yBACf,OAAO,EAAE,GAAG,IAAI,GAAG,EAAE;CAC7C,CAAC,CAAA;IACA,OAAO,cAAc,CAAA;AACvB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAe;IACzC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAC5B,OAAO,KAAK,CAAA;KACb;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC7D,CAAC","sourcesContent":["import {AbortSignal} from './abort.js'\nimport {ExternalError} from './error.js'\nimport {cwd} from './path.js'\nimport {treeKill} from './tree-kill.js'\nimport {isTruthy} from './context/utilities.js'\nimport {shouldDisplayColors, outputDebug} from '../../public/node/output.js'\nimport {execa, ExecaChildProcess} from 'execa'\nimport type {Writable, Readable} from 'stream'\n\nexport interface ExecOptions {\n cwd?: string\n env?: {[key: string]: string | undefined}\n stdin?: Readable | 'inherit'\n stdout?: Writable | 'inherit'\n stderr?: Writable | 'inherit'\n stdio?: 'inherit'\n input?: string\n signal?: AbortSignal\n // Custom handler if process exits with a non-zero code\n externalErrorHandler?: (error: unknown) => Promise<void>\n}\n\n/**\n * Opens a URL in the user's default browser.\n *\n * @param url - URL to open.\n */\nexport async function openURL(url: string): Promise<void> {\n const externalOpen = await import('open')\n await externalOpen.default(url)\n}\n\n/**\n * Runs a command asynchronously, aggregates the stdout data, and returns it.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n * @returns A promise that resolves with the aggregatted stdout of the command.\n */\nexport async function captureOutput(command: string, args: string[], options?: ExecOptions): Promise<string> {\n const result = await buildExec(command, args, options)\n return result.stdout\n}\n\n/**\n * Runs a command asynchronously.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n */\nexport async function exec(command: string, args: string[], options?: ExecOptions): Promise<void> {\n const commandProcess = buildExec(command, args, options)\n if (options?.stderr && options.stderr !== 'inherit') {\n commandProcess.stderr?.pipe(options.stderr, {end: false})\n }\n if (options?.stdout && options.stdout !== 'inherit') {\n commandProcess.stdout?.pipe(options.stdout, {end: false})\n }\n let aborted = false\n options?.signal?.addEventListener('abort', () => {\n const pid = commandProcess.pid\n if (pid) {\n outputDebug(`Killing process ${pid}: ${command} ${args.join(' ')}`)\n aborted = true\n treeKill(pid, 'SIGTERM')\n }\n })\n try {\n await commandProcess\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n // Windows will throw an error whenever the process is killed, no matter the reason.\n // The aborted flag tell use that we killed it, so we can ignore the error.\n if (aborted) return\n if (options?.externalErrorHandler) {\n await options?.externalErrorHandler(processError)\n } else {\n const abortError = new ExternalError(processError.message, command, args)\n abortError.stack = processError.stack\n throw abortError\n }\n }\n}\n\n/**\n * Runs a command asynchronously.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n * @returns A promise for a result with stdout and stderr properties.\n */\nfunction buildExec(command: string, args: string[], options?: ExecOptions): ExecaChildProcess<string> {\n const env = options?.env ?? process.env\n if (shouldDisplayColors()) {\n env.FORCE_COLOR = '1'\n }\n const commandProcess = execa(command, args, {\n env,\n cwd: options?.cwd,\n input: options?.input,\n stdio: options?.stdio,\n stdin: options?.stdin,\n stdout: options?.stdout === 'inherit' ? 'inherit' : undefined,\n stderr: options?.stderr === 'inherit' ? 'inherit' : undefined,\n // Setting this to false makes it possible to kill the main process\n // and all its sub-processes with Ctrl+C on Windows\n windowsHide: false,\n })\n outputDebug(`\nRunning system process:\n · Command: ${command} ${args.join(' ')}\n · Working directory: ${options?.cwd ?? cwd()}\n`)\n return commandProcess\n}\n\n/**\n * Waits for a given number of seconds.\n *\n * @param seconds - Number of seconds to wait.\n * @returns A Promise resolving after the number of seconds.\n */\nexport async function sleep(seconds: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, 1000 * seconds)\n })\n}\n\n/**\n * Check if the standard input and output streams support prompting.\n *\n * @returns True if the standard input and output streams support prompting.\n */\nexport function terminalSupportsPrompting(): boolean {\n if (isTruthy(process.env.CI)) {\n return false\n }\n return Boolean(process.stdin.isTTY && process.stdout.isTTY)\n}\n"]}
1
+ {"version":3,"file":"system.js","sourceRoot":"","sources":["../../../src/public/node/system.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAA;AACxC,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAA;AAC7B,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAA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C,CAAC,SAAS;QAC7D,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC7D,mEAAmE;QACnE,mDAAmD;QACnD,WAAW,EAAE,KAAK;KACnB,CAAC,CAAA;IACF,WAAW,CAAC;;eAEC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;yBACf,OAAO,EAAE,GAAG,IAAI,GAAG,EAAE;CAC7C,CAAC,CAAA;IACA,OAAO,cAAc,CAAA;AACvB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAe;IACzC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAC5B,OAAO,KAAK,CAAA;KACb;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC7D,CAAC","sourcesContent":["import {AbortSignal} from './abort.js'\nimport {ExternalError} from './error.js'\nimport {cwd} from './path.js'\nimport {treeKill} from './tree-kill.js'\nimport {isTruthy} from './context/utilities.js'\nimport {shouldDisplayColors, outputDebug} from '../../public/node/output.js'\nimport {execa, ExecaChildProcess} from 'execa'\nimport type {Writable, Readable} from 'stream'\n\nexport interface ExecOptions {\n cwd?: string\n env?: {[key: string]: string | undefined}\n stdin?: Readable | 'inherit'\n stdout?: Writable | 'inherit'\n stderr?: Writable | 'inherit'\n stdio?: 'inherit'\n input?: string\n signal?: AbortSignal\n // Custom handler if process exits with a non-zero code\n externalErrorHandler?: (error: unknown) => Promise<void>\n}\n\n/**\n * Opens a URL in the user's default browser.\n *\n * @param url - URL to open.\n */\nexport async function openURL(url: string): Promise<void> {\n const externalOpen = await import('open')\n await externalOpen.default(url)\n}\n\n/**\n * Runs a command asynchronously, aggregates the stdout data, and returns it.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n * @returns A promise that resolves with the aggregatted stdout of the command.\n */\nexport async function captureOutput(command: string, args: string[], options?: ExecOptions): Promise<string> {\n const result = await buildExec(command, args, options)\n return result.stdout\n}\n\n/**\n * Runs a command asynchronously.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n */\nexport async function exec(command: string, args: string[], options?: ExecOptions): Promise<void> {\n const commandProcess = buildExec(command, args, options)\n if (options?.stderr && options.stderr !== 'inherit') {\n commandProcess.stderr?.pipe(options.stderr, {end: false})\n }\n if (options?.stdout && options.stdout !== 'inherit') {\n commandProcess.stdout?.pipe(options.stdout, {end: false})\n }\n let aborted = false\n options?.signal?.addEventListener('abort', () => {\n const pid = commandProcess.pid\n if (pid) {\n outputDebug(`Killing process ${pid}: ${command} ${args.join(' ')}`)\n aborted = true\n treeKill(pid, 'SIGTERM')\n }\n })\n try {\n await commandProcess\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n // Windows will throw an error whenever the process is killed, no matter the reason.\n // The aborted flag tell use that we killed it, so we can ignore the error.\n if (aborted) return\n if (options?.externalErrorHandler) {\n await options.externalErrorHandler(processError)\n } else {\n const abortError = new ExternalError(processError.message, command, args)\n abortError.stack = processError.stack\n throw abortError\n }\n }\n}\n\n/**\n * Runs a command asynchronously.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n * @returns A promise for a result with stdout and stderr properties.\n */\nfunction buildExec(command: string, args: string[], options?: ExecOptions): ExecaChildProcess {\n const env = options?.env ?? process.env\n if (shouldDisplayColors()) {\n env.FORCE_COLOR = '1'\n }\n const commandProcess = execa(command, args, {\n env,\n cwd: options?.cwd,\n input: options?.input,\n stdio: options?.stdio,\n stdin: options?.stdin,\n stdout: options?.stdout === 'inherit' ? 'inherit' : undefined,\n stderr: options?.stderr === 'inherit' ? 'inherit' : undefined,\n // Setting this to false makes it possible to kill the main process\n // and all its sub-processes with Ctrl+C on Windows\n windowsHide: false,\n })\n outputDebug(`\nRunning system process:\n · Command: ${command} ${args.join(' ')}\n · Working directory: ${options?.cwd ?? cwd()}\n`)\n return commandProcess\n}\n\n/**\n * Waits for a given number of seconds.\n *\n * @param seconds - Number of seconds to wait.\n * @returns A Promise resolving after the number of seconds.\n */\nexport async function sleep(seconds: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, 1000 * seconds)\n })\n}\n\n/**\n * Check if the standard input and output streams support prompting.\n *\n * @returns True if the standard input and output streams support prompting.\n */\nexport function terminalSupportsPrompting(): boolean {\n if (isTruthy(process.env.CI)) {\n return false\n }\n return Boolean(process.stdin.isTTY && process.stdout.isTTY)\n}\n"]}
@@ -3,6 +3,8 @@ import * as throttler from '../api/rest-api-throttler.js';
3
3
  import { restRequest } from '@shopify/cli-kit/node/api/admin';
4
4
  import { AbortError } from '@shopify/cli-kit/node/error';
5
5
  import { buildBulkUploadResults, buildChecksum, buildTheme, buildThemeAsset, } from '@shopify/cli-kit/node/themes/factories';
6
+ import { outputDebug } from '@shopify/cli-kit/node/output';
7
+ import { sleep } from '@shopify/cli-kit/node/system';
6
8
  export async function fetchTheme(id, session) {
7
9
  const response = await request('GET', `/themes/${id}`, session, undefined, { fields: 'id,name,role,processing' });
8
10
  return buildTheme(response.json.theme);
@@ -34,7 +36,7 @@ export async function deleteThemeAsset(id, key, session) {
34
36
  const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {
35
37
  'asset[key]': key,
36
38
  });
37
- return Boolean(response.json.message);
39
+ return response.status === 200;
38
40
  }
39
41
  export async function bulkUploadThemeAssets(id, assets, session) {
40
42
  const response = await request('PUT', `/themes/${id}/assets/bulk`, session, { assets });
@@ -67,7 +69,7 @@ export async function deleteTheme(id, session) {
67
69
  const response = await request('DELETE', `/themes/${id}`, session);
68
70
  return buildTheme(response.json.theme);
69
71
  }
70
- async function request(method, path, session, params, searchParams = {}) {
72
+ async function request(method, path, session, params, searchParams = {}, retries = 1) {
71
73
  const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams));
72
74
  const status = response.status;
73
75
  throttler.updateApiCallLimitFromResponse(response);
@@ -84,13 +86,33 @@ async function request(method, path, session, params, searchParams = {}) {
84
86
  case status === 403:
85
87
  return handleForbiddenError(response, session);
86
88
  case status === 401:
87
- throw new AbortError(`[${status}] API request unauthorized error`);
89
+ // Retry 401 errors to be resilient to authentication errors.
90
+ return handleRetriableError({
91
+ path,
92
+ retries,
93
+ retry: () => {
94
+ return request(method, path, session, params, searchParams, retries + 1);
95
+ },
96
+ fail: () => {
97
+ throw new AbortError(`[${status}] API request unauthorized error`);
98
+ },
99
+ });
88
100
  case status === 422:
89
101
  throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`);
90
102
  case status >= 400 && status <= 499:
91
103
  throw new AbortError(`[${status}] API request client error`);
92
104
  case status >= 500 && status <= 599:
93
- throw new AbortError(`[${status}] API request server error`);
105
+ // Retry 500-family of errors as that may solve the issue (especially in 503 errors)
106
+ return handleRetriableError({
107
+ path,
108
+ retries,
109
+ retry: () => {
110
+ return request(method, path, session, params, searchParams, retries + 1);
111
+ },
112
+ fail: () => {
113
+ throw new AbortError(`[${status}] API request server error`);
114
+ },
115
+ });
94
116
  default:
95
117
  throw new AbortError(`[${status}] API request unexpected error`);
96
118
  }
@@ -121,4 +143,12 @@ function errorMessage(response) {
121
143
  }
122
144
  return '';
123
145
  }
146
+ async function handleRetriableError({ path, retries, retry, fail }) {
147
+ if (retries >= 3) {
148
+ fail();
149
+ }
150
+ outputDebug(`[${retries}] Retrying '${path}' request...`);
151
+ await sleep(0.2);
152
+ return retry();
153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F,gCAAgC,CACnC,CAAA;AACH,CAAC;AAED,SAAS,MAAM,CAAC,QAAsB;IACpC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,YAAY,CAAC,QAAsB;IAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IAEtC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,OAAO,CAAA;KACf;IAED,OAAO,EAAE,CAAA;AACX,CAAC","sourcesContent":["import {storeAdminUrl} from './urls.js'\nimport * as throttler from '../api/rest-api-throttler.js'\nimport {restRequest, RestResponse} from '@shopify/cli-kit/node/api/admin'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {AbortError} from '@shopify/cli-kit/node/error'\nimport {\n buildBulkUploadResults,\n buildChecksum,\n buildTheme,\n buildThemeAsset,\n} from '@shopify/cli-kit/node/themes/factories'\nimport {Result, Checksum, Key, Theme, ThemeAsset} from '@shopify/cli-kit/node/themes/types'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('GET', `/themes/${id}`, session, undefined, {fields: 'id,name,role,processing'})\n return buildTheme(response.json.theme)\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const response = await request('GET', '/themes', session, undefined, {fields: 'id,name,role,processing'})\n const themes = response.json?.themes\n if (themes?.length > 0) return themes.map(buildTheme)\n return []\n}\n\nexport async function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('POST', '/themes', session, {theme: {...params}})\n const minimumThemeAssets = [\n {key: 'config/settings_schema.json', value: '[]'},\n {key: 'layout/password.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n {key: 'layout/theme.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n ]\n\n await bulkUploadThemeAssets(response.json.theme.id, minimumThemeAssets, session)\n\n return buildTheme({...response.json.theme, createdAtRuntime: true})\n}\n\nexport async function fetchThemeAsset(id: number, key: Key, session: AdminSession): Promise<ThemeAsset | undefined> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return buildThemeAsset(response.json.asset)\n}\n\nexport async function deleteThemeAsset(id: number, key: Key, session: AdminSession): Promise<boolean> {\n const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return Boolean(response.json.message)\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const response = await request('PUT', `/themes/${id}/assets/bulk`, session, {assets})\n if (response.status !== 207) {\n throw new AbortError('Upload failed, could not reach the server')\n }\n return buildBulkUploadResults(response.json.results, assets)\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {fields: 'key,checksum'})\n const assets = response.json.assets\n\n if (assets?.length > 0) return assets.map(buildChecksum)\n\n return []\n}\n\ninterface UpgradeThemeOptions {\n fromTheme: number\n toTheme: number\n script?: string\n session: AdminSession\n}\n\nexport async function upgradeTheme(upgradeOptions: UpgradeThemeOptions): Promise<Theme | undefined> {\n const {fromTheme, toTheme, session, script} = upgradeOptions\n const params = {from_theme: fromTheme, to_theme: toTheme, ...(script && {script})}\n const response = await request('POST', `/themes`, session, params)\n return buildTheme(response.json.theme)\n}\n\nexport async function updateTheme(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('PUT', `/themes/${id}`, session, {theme: {id, ...params}})\n return buildTheme(response.json.theme)\n}\n\nexport async function publishTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n return updateTheme(id, {role: 'main'}, session)\n}\n\nexport async function deleteTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('DELETE', `/themes/${id}`, session)\n return buildTheme(response.json.theme)\n}\n\nasync function request<T>(\n method: string,\n path: string,\n session: AdminSession,\n params?: T,\n searchParams: {[name: string]: string} = {},\n): Promise<RestResponse> {\n const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams))\n\n const status = response.status\n\n throttler.updateApiCallLimitFromResponse(response)\n\n switch (true) {\n case status >= 200 && status <= 399:\n // Returns the successful reponse\n return response\n case status === 404:\n // Defer the decision when a resource is not found\n return response\n case status === 429:\n // Retry following the \"retry-after\" header\n return throttler.delayAwareRetry(response, () => request(method, path, session, params, searchParams))\n case status === 403:\n return handleForbiddenError(response, session)\n case status === 401:\n throw new AbortError(`[${status}] API request unauthorized error`)\n case status === 422:\n throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`)\n case status >= 400 && status <= 499:\n throw new AbortError(`[${status}] API request client error`)\n case status >= 500 && status <= 599:\n throw new AbortError(`[${status}] API request server error`)\n default:\n throw new AbortError(`[${status}] API request unexpected error`)\n }\n}\n\nfunction handleForbiddenError(response: RestResponse, session: AdminSession): never {\n const store = session.storeFqdn\n const adminUrl = storeAdminUrl(session)\n const error = errorMessage(response)\n\n if (error.match(/Cannot delete generated asset/) !== null) {\n throw new AbortError(error)\n }\n\n throw new AbortError(\n `You are not authorized to edit themes on \"${store}\".`,\n \"You can't use Shopify CLI with development stores if you only have Partner staff \" +\n 'member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n `store URL at least once (for example, using \"${adminUrl}\") before you log in using ` +\n 'Shopify CLI. Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.',\n )\n}\n\nfunction errors(response: RestResponse) {\n return JSON.stringify(response.json?.errors)\n}\n\nfunction errorMessage(response: RestResponse): string {\n const message = response.json?.message\n\n if (typeof message === 'string') {\n return message\n }\n\n return ''\n}\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/public/node/themes/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,WAAW,EAAe,MAAM,iCAAiC,CAAA;AAEzE,OAAO,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAA;AACtD,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,UAAU,EACV,eAAe,GAChB,MAAM,wCAAwC,CAAA;AAE/C,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAC,KAAK,EAAC,MAAM,8BAA8B,CAAA;AAKlD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,EAAU,EAAE,OAAqB;IAChE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAC,MAAM,EAAE,yBAAyB,EAAC,CAAC,CAAA;IAC/G,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAqB;IACrD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,EAAC,MAAM,EAAE,yBAAyB,EAAC,CAAC,CAAA;IACzG,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACpC,IAAI,MAAM,EAAE,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IACrD,OAAO,EAAE,CAAA;AACX,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAmB,EAAE,OAAqB;IAC1E,MAAM,QA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,CAAA;IAEzD,MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,KAAK,EAAE,CAAA;AAChB,CAAC","sourcesContent":["import {storeAdminUrl} from './urls.js'\nimport * as throttler from '../api/rest-api-throttler.js'\nimport {restRequest, RestResponse} from '@shopify/cli-kit/node/api/admin'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {AbortError} from '@shopify/cli-kit/node/error'\nimport {\n buildBulkUploadResults,\n buildChecksum,\n buildTheme,\n buildThemeAsset,\n} from '@shopify/cli-kit/node/themes/factories'\nimport {Result, Checksum, Key, Theme, ThemeAsset} from '@shopify/cli-kit/node/themes/types'\nimport {outputDebug} from '@shopify/cli-kit/node/output'\nimport {sleep} from '@shopify/cli-kit/node/system'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('GET', `/themes/${id}`, session, undefined, {fields: 'id,name,role,processing'})\n return buildTheme(response.json.theme)\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const response = await request('GET', '/themes', session, undefined, {fields: 'id,name,role,processing'})\n const themes = response.json?.themes\n if (themes?.length > 0) return themes.map(buildTheme)\n return []\n}\n\nexport async function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('POST', '/themes', session, {theme: {...params}})\n const minimumThemeAssets = [\n {key: 'config/settings_schema.json', value: '[]'},\n {key: 'layout/password.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n {key: 'layout/theme.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n ]\n\n await bulkUploadThemeAssets(response.json.theme.id, minimumThemeAssets, session)\n\n return buildTheme({...response.json.theme, createdAtRuntime: true})\n}\n\nexport async function fetchThemeAsset(id: number, key: Key, session: AdminSession): Promise<ThemeAsset | undefined> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n\n return buildThemeAsset(response.json.asset)\n}\n\nexport async function deleteThemeAsset(id: number, key: Key, session: AdminSession): Promise<boolean> {\n const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return response.status === 200\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const response = await request('PUT', `/themes/${id}/assets/bulk`, session, {assets})\n if (response.status !== 207) {\n throw new AbortError('Upload failed, could not reach the server')\n }\n return buildBulkUploadResults(response.json.results, assets)\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {fields: 'key,checksum'})\n const assets = response.json.assets\n\n if (assets?.length > 0) return assets.map(buildChecksum)\n\n return []\n}\n\ninterface UpgradeThemeOptions {\n fromTheme: number\n toTheme: number\n script?: string\n session: AdminSession\n}\n\nexport async function upgradeTheme(upgradeOptions: UpgradeThemeOptions): Promise<Theme | undefined> {\n const {fromTheme, toTheme, session, script} = upgradeOptions\n const params = {from_theme: fromTheme, to_theme: toTheme, ...(script && {script})}\n const response = await request('POST', `/themes`, session, params)\n return buildTheme(response.json.theme)\n}\n\nexport async function updateTheme(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('PUT', `/themes/${id}`, session, {theme: {id, ...params}})\n return buildTheme(response.json.theme)\n}\n\nexport async function publishTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n return updateTheme(id, {role: 'main'}, session)\n}\n\nexport async function deleteTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('DELETE', `/themes/${id}`, session)\n return buildTheme(response.json.theme)\n}\n\nasync function request<T>(\n method: string,\n path: string,\n session: AdminSession,\n params?: T,\n searchParams: {[name: string]: string} = {},\n retries = 1,\n): Promise<RestResponse> {\n const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams))\n\n const status = response.status\n\n throttler.updateApiCallLimitFromResponse(response)\n\n switch (true) {\n case status >= 200 && status <= 399:\n // Returns the successful reponse\n return response\n case status === 404:\n // Defer the decision when a resource is not found\n return response\n case status === 429:\n // Retry following the \"retry-after\" header\n return throttler.delayAwareRetry(response, () => request(method, path, session, params, searchParams))\n case status === 403:\n return handleForbiddenError(response, session)\n case status === 401:\n // Retry 401 errors to be resilient to authentication errors.\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request unauthorized error`)\n },\n })\n case status === 422:\n throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`)\n case status >= 400 && status <= 499:\n throw new AbortError(`[${status}] API request client error`)\n case status >= 500 && status <= 599:\n // Retry 500-family of errors as that may solve the issue (especially in 503 errors)\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request server error`)\n },\n })\n default:\n throw new AbortError(`[${status}] API request unexpected error`)\n }\n}\n\nfunction handleForbiddenError(response: RestResponse, session: AdminSession): never {\n const store = session.storeFqdn\n const adminUrl = storeAdminUrl(session)\n const error = errorMessage(response)\n\n if (error.match(/Cannot delete generated asset/) !== null) {\n throw new AbortError(error)\n }\n\n throw new AbortError(\n `You are not authorized to edit themes on \"${store}\".`,\n \"You can't use Shopify CLI with development stores if you only have Partner staff \" +\n 'member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n `store URL at least once (for example, using \"${adminUrl}\") before you log in using ` +\n 'Shopify CLI. Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.',\n )\n}\n\nfunction errors(response: RestResponse) {\n return JSON.stringify(response.json?.errors)\n}\n\nfunction errorMessage(response: RestResponse): string {\n const message = response.json?.message\n\n if (typeof message === 'string') {\n return message\n }\n\n return ''\n}\n\ninterface RetriableErrorOptions {\n path: string\n retries: number\n retry: () => Promise<RestResponse>\n fail: () => never\n}\n\nasync function handleRetriableError({path, retries, retry, fail}: RetriableErrorOptions): Promise<RestResponse> {\n if (retries >= 3) {\n fail()\n }\n\n outputDebug(`[${retries}] Retrying '${path}' request...`)\n\n await sleep(0.2)\n return retry()\n}\n"]}
@@ -33,6 +33,7 @@ export function buildBulkUploadResults(bulkUploadResponse, assets) {
33
33
  }
34
34
  return bulkUploadResponse.map((bulkUpload, index) => {
35
35
  return {
36
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36
37
  key: assets[index].key,
37
38
  success: bulkUpload.code === 200,
38
39
  errors: bulkUpload.body.errors || {},
@@ -1 +1 @@
1
- {"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../../src/public/node/themes/factories.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,SAAS,EAAC,MAAM,oCAAoC,CAAA;AAuBjG,MAAM,UAAU,UAAU,CAAC,SAA+B;IACxD,IAAI,CAAC,SAAS;QAAE,OAAM;IAEtB,SAAS,CAAC,UAAU,KAApB,SAAS,CAAC,UAAU,GAAK,KAAK,EAAA;IAC9B,SAAS,CAAC,gBAAgB,KAA1B,SAAS,CAAC,gBAAgB,GAAK,KAAK,EAAA;IAEpC,MAAM,EAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAC,GAAG,SAAS,CAAA;IAEhE,OAAO;QACL,EAAE;QACF,IAAI;QACJ,UAAU;QACV,gBAAgB;QAChB,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI;KACtC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAA2B;IACvD,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAA;IAC7B,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,CAAA;AACxB,CAAC;AAID,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAC,GAAG,KAAK,CAAA;IAChD,gGAAgG;IAChG,MAAM,KAAK,GAAG,EAAC,IAAI,EAAE,CAAC,KAAK,IAAI,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,EAAC,CAAA;IAC3E,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAC,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,kBAA8C,EAC9C,MAAqB;IAErB,IAAI,CAAC,kBAAkB,EAAE;QACvB,OAAO,EAAE,CAAA;KACV;IAED,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE;QAClD,OAAO;YACL,GAAG,EAAE,MAAM,CAAC,KAAK,CAAE,CAAC,GAAG;YACvB,OAAO,EAAE,UAAU,CAAC,IAAI,KAAK,GAAG;YAChC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE;YACpC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK;YAC5B,SAAS,EAAE,SAAS,CAAC,MAAM;SAC5B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {AssetParams} from './api.js'\nimport {Result, Checksum, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types'\n\ninterface RemoteThemeResponse {\n id: number\n name: string\n role: string\n createdAtRuntime?: boolean\n processing?: boolean\n}\n\ninterface RemoteAssetResponse {\n key: string\n checksum: string\n attachment: string | undefined\n // value is an empty string ('') when the file is empty\n value: string\n}\n\nexport interface RemoteBulkUploadResponse {\n body: {asset?: RemoteAssetResponse; errors?: {asset: string[]}}\n code: number\n}\n\nexport function buildTheme(themeJson?: RemoteThemeResponse): Theme | undefined {\n if (!themeJson) return\n\n themeJson.processing ??= false\n themeJson.createdAtRuntime ??= false\n\n const {id, name, role, processing, createdAtRuntime} = themeJson\n\n return {\n id,\n name,\n processing,\n createdAtRuntime,\n role: role === 'main' ? 'live' : role,\n }\n}\n\nexport function buildChecksum(asset?: RemoteAssetResponse): Checksum | undefined {\n if (!asset) return\n\n const {key, checksum} = asset\n return {key, checksum}\n}\n\nexport function buildThemeAsset(asset: undefined): undefined\nexport function buildThemeAsset(asset: RemoteAssetResponse): ThemeAsset\nexport function buildThemeAsset(asset?: RemoteAssetResponse): ThemeAsset | undefined {\n if (!asset) return\n\n const {key, checksum, attachment, value} = asset\n // Note: for attachments, this is the size of the base64 string, not the real length of the file\n const stats = {size: (value || attachment || '').length, mtime: Date.now()}\n return {key, checksum, attachment, value, stats}\n}\n\nexport function buildBulkUploadResults(\n bulkUploadResponse: RemoteBulkUploadResponse[],\n assets: AssetParams[],\n): Result[] {\n if (!bulkUploadResponse) {\n return []\n }\n\n return bulkUploadResponse.map((bulkUpload, index) => {\n return {\n key: assets[index]!.key,\n success: bulkUpload.code === 200,\n errors: bulkUpload.body.errors || {},\n asset: bulkUpload.body.asset,\n operation: Operation.Upload,\n }\n })\n}\n"]}
1
+ {"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../../src/public/node/themes/factories.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,SAAS,EAAC,MAAM,oCAAoC,CAAA;AAuBjG,MAAM,UAAU,UAAU,CAAC,SAA+B;IACxD,IAAI,CAAC,SAAS;QAAE,OAAM;IAEtB,SAAS,CAAC,UAAU,KAApB,SAAS,CAAC,UAAU,GAAK,KAAK,EAAA;IAC9B,SAAS,CAAC,gBAAgB,KAA1B,SAAS,CAAC,gBAAgB,GAAK,KAAK,EAAA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IAAI,CAAC,MAAM,IAAI,EAAE;YACpC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK;YAC5B,SAAS,EAAE,SAAS,CAAC,MAAM;SAC5B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {AssetParams} from './api.js'\nimport {Result, Checksum, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types'\n\ninterface RemoteThemeResponse {\n id: number\n name: string\n role: string\n createdAtRuntime?: boolean\n processing?: boolean\n}\n\ninterface RemoteAssetResponse {\n key: string\n checksum: string\n attachment: string | undefined\n // value is an empty string ('') when the file is empty\n value: string\n}\n\nexport interface RemoteBulkUploadResponse {\n body: {asset?: RemoteAssetResponse; errors?: {asset: string[]}}\n code: number\n}\n\nexport function buildTheme(themeJson?: RemoteThemeResponse): Theme | undefined {\n if (!themeJson) return\n\n themeJson.processing ??= false\n themeJson.createdAtRuntime ??= false\n\n const {id, name, role, processing, createdAtRuntime} = themeJson\n\n return {\n id,\n name,\n processing,\n createdAtRuntime,\n role: role === 'main' ? 'live' : role,\n }\n}\n\nexport function buildChecksum(asset?: RemoteAssetResponse): Checksum | undefined {\n if (!asset) return\n\n const {key, checksum} = asset\n return {key, checksum}\n}\n\nexport function buildThemeAsset(asset: undefined): undefined\nexport function buildThemeAsset(asset: RemoteAssetResponse): ThemeAsset\nexport function buildThemeAsset(asset?: RemoteAssetResponse): ThemeAsset | undefined {\n if (!asset) return\n\n const {key, checksum, attachment, value} = asset\n // Note: for attachments, this is the size of the base64 string, not the real length of the file\n const stats = {size: (value || attachment || '').length, mtime: Date.now()}\n return {key, checksum, attachment, value, stats}\n}\n\nexport function buildBulkUploadResults(\n bulkUploadResponse: RemoteBulkUploadResponse[],\n assets: AssetParams[],\n): Result[] {\n if (!bulkUploadResponse) {\n return []\n }\n\n return bulkUploadResponse.map((bulkUpload, index) => {\n return {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n key: assets[index]!.key,\n success: bulkUpload.code === 200,\n errors: bulkUpload.body.errors || {},\n asset: bulkUpload.body.asset,\n operation: Operation.Upload,\n }\n })\n}\n"]}
@@ -9,6 +9,7 @@ type ThemeFSEvent = {
9
9
  type: 'unlink';
10
10
  payload: {
11
11
  fileKey: Key;
12
+ onSync?: (fn: () => void) => void;
12
13
  };
13
14
  } | {
14
15
  type: 'add' | 'change';
@@ -71,9 +72,7 @@ export interface VirtualFileSystem {
71
72
  /**
72
73
  * Add callbacks to run after certain events are fired.
73
74
  */
74
- addEventListener: {
75
- <T extends ThemeFSEventName>(eventName: T, cb: (params: ThemeFSEventPayload<T>) => void): void;
76
- };
75
+ addEventListener: <T extends ThemeFSEventName>(eventName: T, cb: (params: ThemeFSEventPayload<T>) => void) => void;
77
76
  }
78
77
  /**
79
78
  * Represents a theme on the file system.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/public/node/themes/types.ts"],"names":[],"mappings":"AAwNA,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;AACnB,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB","sourcesContent":["import {AdminSession} from '../session.js'\n\n/**\n * {@link Key} represents the unique identifier of a file in a theme.\n */\nexport type Key = string\n\nexport type ThemeFSEventName = 'add' | 'change' | 'unlink'\n\ntype ThemeFSEvent =\n | {\n type: 'unlink'\n payload: {fileKey: Key}\n }\n | {\n type: 'add' | 'change'\n payload: {\n fileKey: Key\n onContent: (fn: (content: string) => void) => void\n onSync: (fn: () => void) => void\n }\n }\n\nexport type ThemeFSEventPayload<T extends ThemeFSEventName = 'add'> = (ThemeFSEvent & {type: T})['payload']\n\nexport interface ThemeFileSystemOptions {\n filters?: {ignore?: string[]; only?: string[]}\n notify?: string\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface VirtualFileSystem {\n /**\n * The root path of the theme.\n */\n root: string\n\n /**\n * Local files.\n */\n files: Map<Key, ThemeAsset>\n\n /**\n * File keys that have been modified in memory and are not uploaded yet.\n */\n unsyncedFileKeys: Set<Key>\n\n /**\n * Promise that resolves when all the initial files are found.\n */\n ready: () => Promise<void>\n\n /**\n * Removes a file from the local disk and updates the file system\n *\n * @param fileKey - The key of the file to remove\n */\n delete: (fileKey: Key) => Promise<void>\n\n /**\n * Writes a file to the local disk and updates the file system\n *\n * @param asset - The ThemeAsset representing the file to write\n */\n write: (asset: ThemeAsset) => Promise<void>\n\n /**\n * Reads a file from the local disk and updates the file system\n * Returns a ThemeAsset representing the file that was read\n * Returns undefined if the file does not exist\n *\n * @param fileKey - The key of the file to read\n */\n read: (fileKey: Key) => Promise<string | Buffer | undefined>\n\n /**\n * Add callbacks to run after certain events are fired.\n */\n addEventListener: {\n <T extends ThemeFSEventName>(eventName: T, cb: (params: ThemeFSEventPayload<T>) => void): void\n }\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface ThemeFileSystem extends VirtualFileSystem {\n /**\n * Starts a file watcher for the theme directory.\n *\n * @param themeId - The ID of the theme being watched.\n * @param adminSession - The admin session for API communication.\n * @returns A Promise that resolves to an FSWatcher instance.\n */\n startWatcher: (themeId: string, adminSession: AdminSession) => Promise<void>\n\n /**\n * Applies filters to ignore files from .shopifyignore file, --ignore and --only flags.\n */\n applyIgnoreFilters: <T extends {key: string}>(files: T[]) => T[]\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface ThemeExtensionFileSystem extends VirtualFileSystem {\n /**\n * Starts a file watcher for the theme extension directory.\n */\n startWatcher: () => Promise<void>\n}\n\n/**\n * Represents a theme.\n */\nexport interface Theme {\n /**\n * The remote ID of the theme.\n */\n id: number\n\n /**\n * The remote name of the theme.\n */\n name: string\n\n /**\n * A boolean determining whether or not the theme was created at runtime.\n */\n createdAtRuntime: boolean\n\n /**\n * A boolean determining if the theme is processing at the theme library.\n */\n processing: boolean\n\n /**\n * The remote role of the theme.\n */\n role: string\n\n /**\n * A public URL where Shopify can access the theme code.\n */\n src?: string\n}\n\n/**\n * Represents the remote checksum for a file in a theme.\n */\nexport interface Checksum {\n /**\n * Identifier of the theme file.\n */\n key: Key\n\n /**\n * Represents the checksum value of the theme file.\n */\n checksum: string\n}\n\n/**\n * Represents a theme or theme extension asset.\n */\nexport interface ThemeAsset extends Checksum {\n /**\n * A base64-encoded image.\n */\n attachment?: string\n\n /**\n * The text content of the asset, such as the HTML and Liquid markup of a template file.\n */\n value?: string\n\n /**\n * File stats at time of last modification. For attachments, this is the size of the base64 string.\n */\n stats?: {mtime: number; size: number}\n}\n\n/**\n * Represents a single result for an upload or delete operation on a single file\n * Each result includes the unique identifier for the file, the type of the operation,\n * the success status of the operation, any errors that occurred, and the asset value of the file.\n */\nexport interface Result {\n /**\n * The unique identifier for the file being uploaded.\n */\n key: string\n\n /**\n * The operation associated with the result.\n */\n operation: Operation\n\n /**\n * Indicates whether the upload operation for this file was successful.\n */\n success: boolean\n\n /**\n * Error message that was generated during the upload operation for this file.\n */\n errors?: {asset?: string[]}\n\n /**\n * The asset that was uploaded as part of the upload operation for this file.\n */\n asset?: Omit<ThemeAsset, 'stats'>\n}\n\nexport enum Operation {\n Delete = 'DELETE',\n Upload = 'UPLOAD',\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/public/node/themes/types.ts"],"names":[],"mappings":"AAsNA,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;AACnB,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB","sourcesContent":["import {AdminSession} from '../session.js'\n\n/**\n * {@link Key} represents the unique identifier of a file in a theme.\n */\nexport type Key = string\n\nexport type ThemeFSEventName = 'add' | 'change' | 'unlink'\n\ntype ThemeFSEvent =\n | {\n type: 'unlink'\n payload: {fileKey: Key; onSync?: (fn: () => void) => void}\n }\n | {\n type: 'add' | 'change'\n payload: {\n fileKey: Key\n onContent: (fn: (content: string) => void) => void\n onSync: (fn: () => void) => void\n }\n }\n\nexport type ThemeFSEventPayload<T extends ThemeFSEventName = 'add'> = (ThemeFSEvent & {type: T})['payload']\n\nexport interface ThemeFileSystemOptions {\n filters?: {ignore?: string[]; only?: string[]}\n notify?: string\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface VirtualFileSystem {\n /**\n * The root path of the theme.\n */\n root: string\n\n /**\n * Local files.\n */\n files: Map<Key, ThemeAsset>\n\n /**\n * File keys that have been modified in memory and are not uploaded yet.\n */\n unsyncedFileKeys: Set<Key>\n\n /**\n * Promise that resolves when all the initial files are found.\n */\n ready: () => Promise<void>\n\n /**\n * Removes a file from the local disk and updates the file system\n *\n * @param fileKey - The key of the file to remove\n */\n delete: (fileKey: Key) => Promise<void>\n\n /**\n * Writes a file to the local disk and updates the file system\n *\n * @param asset - The ThemeAsset representing the file to write\n */\n write: (asset: ThemeAsset) => Promise<void>\n\n /**\n * Reads a file from the local disk and updates the file system\n * Returns a ThemeAsset representing the file that was read\n * Returns undefined if the file does not exist\n *\n * @param fileKey - The key of the file to read\n */\n read: (fileKey: Key) => Promise<string | Buffer | undefined>\n\n /**\n * Add callbacks to run after certain events are fired.\n */\n addEventListener: <T extends ThemeFSEventName>(eventName: T, cb: (params: ThemeFSEventPayload<T>) => void) => void\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface ThemeFileSystem extends VirtualFileSystem {\n /**\n * Starts a file watcher for the theme directory.\n *\n * @param themeId - The ID of the theme being watched.\n * @param adminSession - The admin session for API communication.\n * @returns A Promise that resolves to an FSWatcher instance.\n */\n startWatcher: (themeId: string, adminSession: AdminSession) => Promise<void>\n\n /**\n * Applies filters to ignore files from .shopifyignore file, --ignore and --only flags.\n */\n applyIgnoreFilters: <T extends {key: string}>(files: T[]) => T[]\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface ThemeExtensionFileSystem extends VirtualFileSystem {\n /**\n * Starts a file watcher for the theme extension directory.\n */\n startWatcher: () => Promise<void>\n}\n\n/**\n * Represents a theme.\n */\nexport interface Theme {\n /**\n * The remote ID of the theme.\n */\n id: number\n\n /**\n * The remote name of the theme.\n */\n name: string\n\n /**\n * A boolean determining whether or not the theme was created at runtime.\n */\n createdAtRuntime: boolean\n\n /**\n * A boolean determining if the theme is processing at the theme library.\n */\n processing: boolean\n\n /**\n * The remote role of the theme.\n */\n role: string\n\n /**\n * A public URL where Shopify can access the theme code.\n */\n src?: string\n}\n\n/**\n * Represents the remote checksum for a file in a theme.\n */\nexport interface Checksum {\n /**\n * Identifier of the theme file.\n */\n key: Key\n\n /**\n * Represents the checksum value of the theme file.\n */\n checksum: string\n}\n\n/**\n * Represents a theme or theme extension asset.\n */\nexport interface ThemeAsset extends Checksum {\n /**\n * A base64-encoded image.\n */\n attachment?: string\n\n /**\n * The text content of the asset, such as the HTML and Liquid markup of a template file.\n */\n value?: string\n\n /**\n * File stats at time of last modification. For attachments, this is the size of the base64 string.\n */\n stats?: {mtime: number; size: number}\n}\n\n/**\n * Represents a single result for an upload or delete operation on a single file\n * Each result includes the unique identifier for the file, the type of the operation,\n * the success status of the operation, any errors that occurred, and the asset value of the file.\n */\nexport interface Result {\n /**\n * The unique identifier for the file being uploaded.\n */\n key: string\n\n /**\n * The operation associated with the result.\n */\n operation: Operation\n\n /**\n * Indicates whether the upload operation for this file was successful.\n */\n success: boolean\n\n /**\n * Error message that was generated during the upload operation for this file.\n */\n errors?: {asset?: string[]}\n\n /**\n * The asset that was uploaded as part of the upload operation for this file.\n */\n asset?: Omit<ThemeAsset, 'stats'>\n}\n\nexport enum Operation {\n Delete = 'DELETE',\n Upload = 'UPLOAD',\n}\n"]}
@@ -4,3 +4,4 @@ export declare function themePreviewUrl(theme: Theme, session: AdminSession): st
4
4
  export declare function themeEditorUrl(theme: Theme, session: AdminSession): string;
5
5
  export declare function codeEditorUrl(theme: Theme, session: AdminSession): string;
6
6
  export declare function storeAdminUrl(session: AdminSession): string;
7
+ export declare function storePasswordPage(store: AdminSession['storeFqdn']): string;
@@ -17,4 +17,7 @@ export function storeAdminUrl(session) {
17
17
  const store = session.storeFqdn;
18
18
  return `https://${store}/admin`;
19
19
  }
20
+ export function storePasswordPage(store) {
21
+ return `https://${store}/admin/online_store/preferences`;
22
+ }
20
23
  //# sourceMappingURL=urls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../../src/public/node/themes/urls.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,OAAqB;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;QACzB,OAAO,WAAW,KAAK,EAAE,CAAA;KAC1B;IAED,OAAO,WAAW,KAAK,qBAAqB,KAAK,CAAC,EAAE,EAAE,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAY,EAAE,OAAqB;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,SAAS,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,OAAqB;IAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,QAAQ,CAAA;AACjC,CAAC","sourcesContent":["import {Theme} from '@shopify/cli-kit/node/themes/types'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\nexport function themePreviewUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n if (theme.role === 'live') {\n return `https://${store}`\n }\n\n return `https://${store}?preview_theme_id=${theme.id}`\n}\n\nexport function themeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}/editor`\n}\n\nexport function codeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}`\n}\n\nexport function storeAdminUrl(session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin`\n}\n"]}
1
+ {"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../../src/public/node/themes/urls.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,OAAqB;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;QACzB,OAAO,WAAW,KAAK,EAAE,CAAA;KAC1B;IAED,OAAO,WAAW,KAAK,qBAAqB,KAAK,CAAC,EAAE,EAAE,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAY,EAAE,OAAqB;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,SAAS,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,OAAqB;IAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,QAAQ,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAgC;IAChE,OAAO,WAAW,KAAK,iCAAiC,CAAA;AAC1D,CAAC","sourcesContent":["import {Theme} from '@shopify/cli-kit/node/themes/types'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\nexport function themePreviewUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n if (theme.role === 'live') {\n return `https://${store}`\n }\n\n return `https://${store}?preview_theme_id=${theme.id}`\n}\n\nexport function themeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}/editor`\n}\n\nexport function codeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}`\n}\n\nexport function storeAdminUrl(session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin`\n}\n\nexport function storePasswordPage(store: AdminSession['storeFqdn']) {\n return `https://${store}/admin/online_store/preferences`\n}\n"]}
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
1
2
  /* eslint-disable @typescript-eslint/ban-ts-comment */
2
3
  /* eslint-disable jsdoc/require-throws */
3
4
  /* eslint-disable no-restricted-imports */
@@ -38,7 +39,8 @@ function adaptedTreeKill(pid, killSignal, killRoot, callback) {
38
39
  const rootPid = typeof pid === 'number' ? pid.toString() : pid;
39
40
  if (Number.isNaN(rootPid)) {
40
41
  if (callback) {
41
- return callback(new Error('pid must be a number'));
42
+ callback(new Error('pid must be a number'));
43
+ return;
42
44
  }
43
45
  else {
44
46
  throw new Error('pid must be a number');
@@ -100,14 +102,15 @@ function killAll(tree, killSignal, rootPid, killRoot, callback) {
100
102
  catch (err) {
101
103
  if (callback) {
102
104
  // @ts-ignore
103
- return callback(err);
105
+ callback(err);
106
+ return;
104
107
  }
105
108
  else {
106
109
  throw err;
107
110
  }
108
111
  }
109
112
  if (callback) {
110
- return callback();
113
+ callback();
111
114
  }
112
115
  }
113
116
  /**
@@ -147,7 +150,8 @@ function buildProcessTree(parentPid, tree, pidsToProcess, spawnChildProcessesLis
147
150
  if (code !== 0) {
148
151
  // no more parent processes
149
152
  if (pidsToProcess.size === 0) {
150
- return cb();
153
+ cb();
154
+ return;
151
155
  }
152
156
  return;
153
157
  }
@@ -1 +1 @@
1
- {"version":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QACtC,OAAO,IAAI,OAAO,CAAA;IACpB,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE;QAC/B,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAE/B,IAAI,IAAI,KAAK,CAAC,EAAE;YACd,2BAA2B;YAC3B,IAAI,aAAa,CAAC,IAAI,KAAK,CAAC,EAAE;gBAC5B,OAAO,EAAE,EAAE,CAAA;aACZ;YACD,OAAM;SACP;QAED,OAAO;aACJ,IAAI,EAAE;aACN,KAAK,CAAC,IAAI,CAAC;aACX,OAAO,CAAC,UAAU,IAAI;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;YACzC,IAAI,KAAK,EAAE;gBACT,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;gBACrB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;gBACrB,IAAI,CAAC,SAAS,CAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;gBACd,WAAW,CAAC,mBAAmB,GAAG,KAAK,GAAG,EAAE,CAAC,CAAA;gBAC7C,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBACtB,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAA;aACxE;QACH,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable jsdoc/require-throws */\n/* eslint-disable no-restricted-imports */\n\nimport {outputDebug} from './output.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {exec, spawn} from 'child_process'\n\ninterface ProcessTree {\n [key: string]: string[]\n}\n\ntype AfterKillCallback = (error?: Error) => void\n\n/**\n * Kills the process that calls the method and all its children.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nexport function treeKill(\n pid: number | string = process.pid,\n killSignal = 'SIGTERM',\n killRoot = true,\n callback?: AfterKillCallback,\n): void {\n const after =\n callback ??\n ((error?: Error) => {\n if (error) outputDebug(`Failed to kill process ${pid}: ${error}`)\n })\n printEventsJson()\n adaptedTreeKill(pid, killSignal, killRoot, after)\n}\n\n/**\n * Adapted from https://github.com/pkrumins/node-tree-kill.\n *\n * Our implementation allows to skip killing the root process. This is useful for example when\n * gracefully exiting the 'dev' process, as the default tree-kill implementation will cause it\n * to exit with a non-zero code. Instead, we want to treat it as a graceful termination.\n * In addition, we also add debug logging for better visibility in what tree-kill is doing.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction adaptedTreeKill(\n pid: number | string,\n killSignal: string,\n killRoot: boolean,\n callback: (error?: Error) => void,\n): void {\n const rootPid = typeof pid === 'number' ? pid.toString() : pid\n\n if (Number.isNaN(rootPid)) {\n if (callback) {\n return callback(new Error('pid must be a number'))\n } else {\n throw new Error('pid must be a number')\n }\n }\n\n // A map from parent pid to an array of children pids\n const tree: ProcessTree = {}\n tree[rootPid] = []\n\n // A set of pids to visit. We use it to recursively find all the children pids\n const pidsToProcess: Set<string> = new Set()\n pidsToProcess.add(rootPid)\n\n switch (process.platform) {\n case 'win32':\n // @ts-ignore\n exec(`taskkill /pid ${pid} /T /F`, callback)\n break\n case 'darwin':\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('pgrep', ['-lfP', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n // Linux\n default:\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('ps', ['-o', 'pid command', '--no-headers', '--ppid', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n }\n}\n\n/**\n * Kills all processes in the process tree.\n *\n * @param tree - Process tree.\n * @param killSignal - Type of kill signal to be used.\n * @param rootPid - Pid of the root process.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction killAll(\n tree: ProcessTree,\n killSignal: string,\n rootPid: string,\n killRoot: boolean,\n callback: AfterKillCallback,\n): void {\n const killed: Set<string> = new Set()\n try {\n Object.keys(tree).forEach(function (pid) {\n tree[pid]!.forEach(function (pidpid) {\n if (!killed.has(pidpid)) {\n killPid(pidpid, killSignal)\n killed.add(pidpid)\n }\n })\n if (pid === rootPid && killRoot && !killed.has(pid)) {\n killPid(pid, killSignal)\n killed.add(pid)\n }\n })\n } catch (err: unknown) {\n if (callback) {\n // @ts-ignore\n return callback(err)\n } else {\n throw err\n }\n }\n if (callback) {\n return callback()\n }\n}\n\n/**\n * Kills a process.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n */\nfunction killPid(pid: string, killSignal: string) {\n try {\n process.kill(parseInt(pid, 10), killSignal)\n } catch (err) {\n // @ts-ignore\n if (err.code !== 'ESRCH') throw err\n }\n}\n\n/**\n * Builds a process tree.\n *\n * @param parentPid - Pid of the parent process.\n * @param tree - Process tree.\n * @param pidsToProcess - Pids to process.\n * @param spawnChildProcessesList - Function to spawn child processes.\n * @param cb - Callback to run after building the process tree.\n */\nfunction buildProcessTree(\n parentPid: string,\n tree: ProcessTree,\n pidsToProcess: Set<string>,\n spawnChildProcessesList: (parentPid: string) => ReturnType<typeof spawn>,\n cb: () => void,\n) {\n const ps = spawnChildProcessesList(parentPid)\n let allData = ''\n ps.stdout?.on('data', function (data: Buffer) {\n const dataStr = data.toString('ascii')\n allData += dataStr\n })\n\n const onClose = (code: number) => {\n pidsToProcess.delete(parentPid)\n\n if (code !== 0) {\n // no more parent processes\n if (pidsToProcess.size === 0) {\n return cb()\n }\n return\n }\n\n allData\n .trim()\n .split('\\n')\n .forEach(function (line) {\n const match = line.match(/^(\\d+)\\s(.*)$/)\n if (match) {\n const pid = match[1]!\n const cmd = match[2]!\n tree[parentPid]!.push(pid)\n tree[pid] = []\n outputDebug(`Killing process ${pid}: ${cmd}`)\n pidsToProcess.add(pid)\n buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb)\n }\n })\n }\n\n ps.on('close', onClose)\n}\n"]}
1
+ {"version":3,"file":"tree-kill.js","sourceRoot":"","sources":["../../../src/public/node/tree-kill.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,sDAAsD;AACtD,yCAAyC;AACzC,0CAA0C;AAE1C,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AACvC,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAC,IAAI,EAAE,KAAK,EAAC,MAAM,eAAe,CAAA;AAQzC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAuB,OAAO,CAAC,GAAG,EAClC,UAAU,GAAG,SAAS,EACtB,QAAQ,GAAG,IAAI,EACf,QAA4B;IAE5B,MAAM,KAAK,GACT,QAAQ;QACR,CAAC,CAAC,KAAa,EAAE,EAAE;YACjB,IAAI,KAAK;gBAAE,WAAW,CAAC,0BAA0B,GAAG,KAAK,KAAK,EAAE,CAAC,CAAA;QACnE,CAAC,CAAC,CAAA;IACJ,eAAe,EAAE,CAAA;IACjB,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AACnD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,eAAe,CACtB,GAAoB,EACpB,UAAkB,EAClB,QAAiB,EACjB,QAAiC;IAEjC,MAAM,OAAO,GAAG,OAAO,GAAG,KAAK,QA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ACtB,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAA;aACxE;QACH,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable jsdoc/require-throws */\n/* eslint-disable no-restricted-imports */\n\nimport {outputDebug} from './output.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {exec, spawn} from 'child_process'\n\ninterface ProcessTree {\n [key: string]: string[]\n}\n\ntype AfterKillCallback = (error?: Error) => void\n\n/**\n * Kills the process that calls the method and all its children.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nexport function treeKill(\n pid: number | string = process.pid,\n killSignal = 'SIGTERM',\n killRoot = true,\n callback?: AfterKillCallback,\n): void {\n const after =\n callback ??\n ((error?: Error) => {\n if (error) outputDebug(`Failed to kill process ${pid}: ${error}`)\n })\n printEventsJson()\n adaptedTreeKill(pid, killSignal, killRoot, after)\n}\n\n/**\n * Adapted from https://github.com/pkrumins/node-tree-kill.\n *\n * Our implementation allows to skip killing the root process. This is useful for example when\n * gracefully exiting the 'dev' process, as the default tree-kill implementation will cause it\n * to exit with a non-zero code. Instead, we want to treat it as a graceful termination.\n * In addition, we also add debug logging for better visibility in what tree-kill is doing.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction adaptedTreeKill(\n pid: number | string,\n killSignal: string,\n killRoot: boolean,\n callback: (error?: Error) => void,\n): void {\n const rootPid = typeof pid === 'number' ? pid.toString() : pid\n\n if (Number.isNaN(rootPid)) {\n if (callback) {\n callback(new Error('pid must be a number'))\n return\n } else {\n throw new Error('pid must be a number')\n }\n }\n\n // A map from parent pid to an array of children pids\n const tree: ProcessTree = {}\n tree[rootPid] = []\n\n // A set of pids to visit. We use it to recursively find all the children pids\n const pidsToProcess = new Set<string>()\n pidsToProcess.add(rootPid)\n\n switch (process.platform) {\n case 'win32':\n // @ts-ignore\n exec(`taskkill /pid ${pid} /T /F`, callback)\n break\n case 'darwin':\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('pgrep', ['-lfP', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n // Linux\n default:\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('ps', ['-o', 'pid command', '--no-headers', '--ppid', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n }\n}\n\n/**\n * Kills all processes in the process tree.\n *\n * @param tree - Process tree.\n * @param killSignal - Type of kill signal to be used.\n * @param rootPid - Pid of the root process.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction killAll(\n tree: ProcessTree,\n killSignal: string,\n rootPid: string,\n killRoot: boolean,\n callback: AfterKillCallback,\n): void {\n const killed = new Set<string>()\n try {\n Object.keys(tree).forEach(function (pid) {\n tree[pid]!.forEach(function (pidpid) {\n if (!killed.has(pidpid)) {\n killPid(pidpid, killSignal)\n killed.add(pidpid)\n }\n })\n if (pid === rootPid && killRoot && !killed.has(pid)) {\n killPid(pid, killSignal)\n killed.add(pid)\n }\n })\n } catch (err: unknown) {\n if (callback) {\n // @ts-ignore\n callback(err)\n return\n } else {\n throw err\n }\n }\n if (callback) {\n callback()\n }\n}\n\n/**\n * Kills a process.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n */\nfunction killPid(pid: string, killSignal: string) {\n try {\n process.kill(parseInt(pid, 10), killSignal)\n } catch (err) {\n // @ts-ignore\n if (err.code !== 'ESRCH') throw err\n }\n}\n\n/**\n * Builds a process tree.\n *\n * @param parentPid - Pid of the parent process.\n * @param tree - Process tree.\n * @param pidsToProcess - Pids to process.\n * @param spawnChildProcessesList - Function to spawn child processes.\n * @param cb - Callback to run after building the process tree.\n */\nfunction buildProcessTree(\n parentPid: string,\n tree: ProcessTree,\n pidsToProcess: Set<string>,\n spawnChildProcessesList: (parentPid: string) => ReturnType<typeof spawn>,\n cb: () => void,\n) {\n const ps = spawnChildProcessesList(parentPid)\n let allData = ''\n ps.stdout?.on('data', function (data: Buffer) {\n const dataStr = data.toString('ascii')\n allData += dataStr\n })\n\n const onClose = (code: number) => {\n pidsToProcess.delete(parentPid)\n\n if (code !== 0) {\n // no more parent processes\n if (pidsToProcess.size === 0) {\n cb()\n return\n }\n return\n }\n\n allData\n .trim()\n .split('\\n')\n .forEach(function (line) {\n const match = line.match(/^(\\d+)\\s(.*)$/)\n if (match) {\n const pid = match[1]!\n const cmd = match[2]!\n tree[parentPid]!.push(pid)\n tree[pid] = []\n outputDebug(`Killing process ${pid}: ${cmd}`)\n pidsToProcess.add(pid)\n buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb)\n }\n })\n }\n\n ps.on('close', onClose)\n}\n"]}
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
1
2
  /* eslint-disable tsdoc/syntax */
2
3
  import { AbortError, AbortSilentError, FatalErrorType } from './error.js';
3
4
  import { collectLog, consoleError, consoleLog, outputContent, outputDebug, outputToken, outputWhereAppropriate, } from './output.js';
@@ -349,7 +350,7 @@ export async function renderAutocompletePrompt({ renderOptions, ...props }, uiDe
349
350
  const lowerTerm = term.toLowerCase();
350
351
  return Promise.resolve({
351
352
  data: props.choices.filter((item) => {
352
- return (item.label.toLowerCase().includes(lowerTerm) || (item.group && item.group.toLowerCase().includes(lowerTerm)));
353
+ return item.label.toLowerCase().includes(lowerTerm) || item.group?.toLowerCase().includes(lowerTerm);
353
354
  }),
354
355
  });
355
356
  },
@@ -409,7 +410,9 @@ export async function renderTasks(tasks, { renderOptions } = {}) {
409
410
  ...renderOptions,
410
411
  exitOnCtrlC: false,
411
412
  })
412
- .then(() => resetRecordedSleep())
413
+ .then(() => {
414
+ resetRecordedSleep();
415
+ })
413
416
  .catch(reject);
414
417
  });
415
418
  }