@shopify/cli-kit 3.17.0 → 3.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/assets/success.html +1 -1
  3. package/dist/constants.d.ts +15 -14
  4. package/dist/constants.js +15 -14
  5. package/dist/constants.js.map +1 -1
  6. package/dist/content-tokens.js.map +1 -1
  7. package/dist/environment/service.d.ts +1 -0
  8. package/dist/environment/service.js +3 -0
  9. package/dist/environment/service.js.map +1 -1
  10. package/dist/environment.d.ts +3 -1
  11. package/dist/environment.js +3 -1
  12. package/dist/environment.js.map +1 -1
  13. package/dist/error.js +3 -2
  14. package/dist/error.js.map +1 -1
  15. package/dist/git.js +4 -1
  16. package/dist/git.js.map +1 -1
  17. package/dist/node/cli.js +1 -1
  18. package/dist/node/cli.js.map +1 -1
  19. package/dist/node/colors.d.ts +2 -1
  20. package/dist/node/colors.js +2 -7
  21. package/dist/node/colors.js.map +1 -1
  22. package/dist/node/ruby.js +2 -2
  23. package/dist/node/ruby.js.map +1 -1
  24. package/dist/output.d.ts +10 -16
  25. package/dist/output.js +4 -122
  26. package/dist/output.js.map +1 -1
  27. package/dist/private/node/ui/alert.d.ts +2 -0
  28. package/dist/private/node/ui/alert.js +18 -0
  29. package/dist/private/node/ui/alert.js.map +1 -0
  30. package/dist/private/node/ui/components/Alert.d.ts +17 -0
  31. package/dist/private/node/ui/components/Alert.js +21 -0
  32. package/dist/private/node/ui/components/Alert.js.map +1 -0
  33. package/dist/private/node/ui/components/Banner.d.ts +7 -0
  34. package/dist/private/node/ui/components/Banner.js +35 -0
  35. package/dist/private/node/ui/components/Banner.js.map +1 -0
  36. package/dist/private/node/ui/components/Command.d.ts +9 -0
  37. package/dist/private/node/ui/components/Command.js +10 -0
  38. package/dist/private/node/ui/components/Command.js.map +1 -0
  39. package/dist/private/node/ui/components/ConcurrentOutput.d.ts +48 -0
  40. package/dist/private/node/ui/components/ConcurrentOutput.js +98 -0
  41. package/dist/private/node/ui/components/ConcurrentOutput.js.map +1 -0
  42. package/dist/private/node/ui/components/Error.d.ts +8 -0
  43. package/dist/private/node/ui/components/Error.js +13 -0
  44. package/dist/private/node/ui/components/Error.js.map +1 -0
  45. package/dist/private/node/ui/components/FatalError.d.ts +7 -0
  46. package/dist/private/node/ui/components/FatalError.js +42 -0
  47. package/dist/private/node/ui/components/FatalError.js.map +1 -0
  48. package/dist/private/node/ui/components/FullScreen.d.ts +8 -0
  49. package/dist/private/node/ui/components/FullScreen.js +32 -0
  50. package/dist/private/node/ui/components/FullScreen.js.map +1 -0
  51. package/dist/private/node/ui/components/Link.d.ts +10 -0
  52. package/dist/private/node/ui/components/Link.js +14 -0
  53. package/dist/private/node/ui/components/Link.js.map +1 -0
  54. package/dist/private/node/ui/components/List.d.ts +13 -0
  55. package/dist/private/node/ui/components/List.js +19 -0
  56. package/dist/private/node/ui/components/List.js.map +1 -0
  57. package/dist/private/node/ui/components/TextAnimation.d.ts +11 -0
  58. package/dist/private/node/ui/components/TextAnimation.js +46 -0
  59. package/dist/private/node/ui/components/TextAnimation.js.map +1 -0
  60. package/dist/private/node/ui/components/TokenizedText.d.ts +21 -0
  61. package/dist/private/node/ui/components/TokenizedText.js +26 -0
  62. package/dist/private/node/ui/components/TokenizedText.js.map +1 -0
  63. package/dist/private/node/ui/error.d.ts +4 -0
  64. package/dist/private/node/ui/error.js +12 -0
  65. package/dist/private/node/ui/error.js.map +1 -0
  66. package/dist/private/node/ui.d.ts +10 -0
  67. package/dist/private/node/ui.js +47 -0
  68. package/dist/private/node/ui.js.map +1 -0
  69. package/dist/public/node/ui.d.ts +155 -0
  70. package/dist/public/node/ui.js +163 -0
  71. package/dist/public/node/ui.js.map +1 -0
  72. package/dist/session.d.ts +10 -0
  73. package/dist/session.js +19 -2
  74. package/dist/session.js.map +1 -1
  75. package/dist/string.d.ts +1 -0
  76. package/dist/string.js +6 -0
  77. package/dist/string.js.map +1 -1
  78. package/dist/system.d.ts +2 -5
  79. package/dist/system.js +19 -19
  80. package/dist/system.js.map +1 -1
  81. package/dist/testing/fixtures/render-concurrent.d.ts +1 -0
  82. package/dist/testing/fixtures/render-concurrent.js +28 -0
  83. package/dist/testing/fixtures/render-concurrent.js.map +1 -0
  84. package/dist/testing/output.d.ts +1 -0
  85. package/dist/testing/output.js +1 -0
  86. package/dist/testing/output.js.map +1 -1
  87. package/dist/testing/ui.d.ts +8 -0
  88. package/dist/testing/ui.js +17 -0
  89. package/dist/testing/ui.js.map +1 -0
  90. package/dist/tsconfig.tsbuildinfo +1 -1
  91. package/dist/ui/inquirer/input.d.ts +1 -1
  92. package/package.json +9 -2
@@ -0,0 +1,163 @@
1
+ import ConcurrentOutput from '../../private/node/ui/components/ConcurrentOutput.js';
2
+ import { render } from '../../private/node/ui.js';
3
+ import { alert } from '../../private/node/ui/alert.js';
4
+ import { fatalError, error } from '../../private/node/ui/error.js';
5
+ import React from 'react';
6
+ import { AbortController } from 'abort-controller';
7
+ /**
8
+ * Renders output from concurrent processes to the terminal with {@link ConcurrentOutput}.
9
+ */
10
+ export async function renderConcurrent({ processes, abortController, showTimestamps = true }) {
11
+ const { waitUntilExit } = render(React.createElement(ConcurrentOutput, { processes: processes, abortController: abortController ?? new AbortController(), showTimestamps: showTimestamps }));
12
+ return waitUntilExit();
13
+ }
14
+ /**
15
+ * Renders an information banner to the console.
16
+ *
17
+ * Basic:
18
+ *
19
+ * ```
20
+ * ╭─ info ───────────────────────────────────────────────────╮
21
+ * │ │
22
+ * │ Body │
23
+ * │ │
24
+ * ╰──────────────────────────────────────────────────────────╯
25
+ * ```
26
+ *
27
+ * Complete:
28
+ * ```
29
+ * ╭─ info ───────────────────────────────────────────────────╮
30
+ * │ │
31
+ * │ Title │
32
+ * │ │
33
+ * │ Body │
34
+ * │ │
35
+ * │ Next steps │
36
+ * │ • Run cd santorini-goods │
37
+ * │ • To preview your project, run npm app dev │
38
+ * │ • To add extensions, run npm generate extension │
39
+ * │ │
40
+ * │ Reference │
41
+ * │ • Run npm shopify help │
42
+ * │ • Press 'return' to open the dev docs: │
43
+ * │ https://shopify.dev │
44
+ * │ │
45
+ * │ Link: https://shopify.com │
46
+ * │ │
47
+ * ╰──────────────────────────────────────────────────────────╯
48
+ * ```
49
+ */
50
+ export function renderInfo(options) {
51
+ alert({ ...options, type: 'info' });
52
+ }
53
+ /**
54
+ * Renders a success banner to the console.
55
+ *
56
+ * Basic:
57
+ *
58
+ * ```
59
+ * ╭─ success ────────────────────────────────────────────────╮
60
+ * │ │
61
+ * │ Title │
62
+ * │ │
63
+ * ╰──────────────────────────────────────────────────────────╯
64
+ * ```
65
+ *
66
+ * Complete:
67
+ * ```
68
+ * ╭─ success ────────────────────────────────────────────────╮
69
+ * │ │
70
+ * │ Title │
71
+ * │ │
72
+ * │ Body │
73
+ * │ │
74
+ * │ Next steps │
75
+ * │ • Run cd santorini-goods │
76
+ * │ • To preview your project, run npm app dev │
77
+ * │ • To add extensions, run npm generate extension │
78
+ * │ │
79
+ * │ Reference │
80
+ * │ • Run npm shopify help │
81
+ * │ • Press 'return' to open the dev docs: │
82
+ * │ https://shopify.dev │
83
+ * │ │
84
+ * │ Link: https://shopify.com │
85
+ * │ │
86
+ * ╰──────────────────────────────────────────────────────────╯
87
+ * ```
88
+ */
89
+ export function renderSuccess(options) {
90
+ alert({ ...options, type: 'success' });
91
+ }
92
+ /**
93
+ * Renders a warning banner to the console.
94
+ *
95
+ * Basic:
96
+ *
97
+ * ```
98
+ * ╭─ warning ────────────────────────────────────────────────╮
99
+ * │ │
100
+ * │ Title │
101
+ * │ │
102
+ * ╰──────────────────────────────────────────────────────────╯
103
+ * ```
104
+ *
105
+ * Complete:
106
+ * ```
107
+ * ╭─ warning ────────────────────────────────────────────────╮
108
+ * │ │
109
+ * │ Title │
110
+ * │ │
111
+ * │ Body │
112
+ * │ │
113
+ * │ Next steps │
114
+ * │ • Run cd santorini-goods │
115
+ * │ • To preview your project, run npm app dev │
116
+ * │ • To add extensions, run npm generate extension │
117
+ * │ │
118
+ * │ Reference │
119
+ * │ • Run npm shopify help │
120
+ * │ • Press 'return' to open the dev docs: │
121
+ * │ https://shopify.dev │
122
+ * │ │
123
+ * │ Link: https://shopify.com │
124
+ * │ │
125
+ * ╰──────────────────────────────────────────────────────────╯
126
+ * ```
127
+ */
128
+ export function renderWarning(options) {
129
+ alert({ ...options, type: 'warning' });
130
+ }
131
+ /**
132
+ * Renders a Fatal error to the console inside a banner.
133
+ *
134
+ * ```
135
+ * ╭─ error ──────────────────────────────────────────────────╮
136
+ * │ │
137
+ * │ Couldn't connect to the Shopify Partner Dashboard. │
138
+ * │ │
139
+ * │ Check your internet connection and try again. │
140
+ * │ │
141
+ * ╰──────────────────────────────────────────────────────────╯
142
+ * ```
143
+ */
144
+ export function renderFatalError(error) {
145
+ fatalError(error);
146
+ }
147
+ /**
148
+ * Renders a generic error to the console inside a banner.
149
+ *
150
+ * ```
151
+ * ╭─ error ──────────────────────────────────────────────────╮
152
+ * │ │
153
+ * │ Something went wrong. │
154
+ * │ │
155
+ * │ Check your internet connection. │
156
+ * │ │
157
+ * ╰──────────────────────────────────────────────────────────╯
158
+ * ```
159
+ */
160
+ export function renderError(options) {
161
+ error(options);
162
+ }
163
+ //# sourceMappingURL=ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/public/node/ui.tsx"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,sDAAsD,CAAA;AAEnF,OAAO,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAA;AAE/C,OAAO,EAAC,KAAK,EAAC,MAAM,gCAAgC,CAAA;AACpD,OAAO,EAAC,UAAU,EAAE,KAAK,EAAC,MAAM,gCAAgC,CAAA;AAGhE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAA;AAQhD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EAAC,SAAS,EAAE,eAAe,EAAE,cAAc,GAAG,IAAI,EAA0B;IACjH,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,CAC5B,oBAAC,gBAAgB,IACf,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,eAAe,IAAI,IAAI,eAAe,EAAE,EACzD,cAAc,EAAE,cAAc,GAC9B,CACH,CAAA;IAED,OAAO,aAAa,EAAE,CAAA;AACxB,CAAC;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,KAAK,CAAC,EAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAC,CAAC,CAAA;AACnC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,aAAa,CAAC,OAA2B;IACvD,KAAK,CAAC,EAAC,GAAG,OAAO,EAAE,IAAI,EAAE,SAAS,EAAC,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,aAAa,CAAC,OAA2B;IACvD,KAAK,CAAC,EAAC,GAAG,OAAO,EAAE,IAAI,EAAE,SAAS,EAAC,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAY;IAC3C,UAAU,CAAC,KAAK,CAAC,CAAA;AACnB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,OAAmB;IAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;AAChB,CAAC","sourcesContent":["import ConcurrentOutput from '../../private/node/ui/components/ConcurrentOutput.js'\nimport {OutputProcess} from '../../output.js'\nimport {render} from '../../private/node/ui.js'\nimport {Fatal} from '../../error.js'\nimport {alert} from '../../private/node/ui/alert.js'\nimport {fatalError, error} from '../../private/node/ui/error.js'\nimport {AlertProps} from '../../private/node/ui/components/Alert.js'\nimport {ErrorProps} from '../../private/node/ui/components/Error.js'\nimport React from 'react'\nimport {AbortController} from 'abort-controller'\n\ninterface RenderConcurrentOptions {\n processes: OutputProcess[]\n abortController?: AbortController\n showTimestamps?: boolean\n}\n\n/**\n * Renders output from concurrent processes to the terminal with {@link ConcurrentOutput}.\n */\nexport async function renderConcurrent({processes, abortController, showTimestamps = true}: RenderConcurrentOptions) {\n const {waitUntilExit} = render(\n <ConcurrentOutput\n processes={processes}\n abortController={abortController ?? new AbortController()}\n showTimestamps={showTimestamps}\n />,\n )\n\n return waitUntilExit()\n}\n\ntype RenderAlertOptions = Omit<AlertProps, 'type'>\n\n/**\n * Renders an information banner to the console.\n *\n * Basic:\n *\n * ```\n * ╭─ info ───────────────────────────────────────────────────╮\n * │ │\n * │ Body │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n *\n * Complete:\n * ```\n * ╭─ info ───────────────────────────────────────────────────╮\n * │ │\n * │ Title │\n * │ │\n * │ Body │\n * │ │\n * │ Next steps │\n * │ • Run cd santorini-goods │\n * │ • To preview your project, run npm app dev │\n * │ • To add extensions, run npm generate extension │\n * │ │\n * │ Reference │\n * │ • Run npm shopify help │\n * │ • Press 'return' to open the dev docs: │\n * │ https://shopify.dev │\n * │ │\n * │ Link: https://shopify.com │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n */\nexport function renderInfo(options: RenderAlertOptions) {\n alert({...options, type: 'info'})\n}\n\n/**\n * Renders a success banner to the console.\n *\n * Basic:\n *\n * ```\n * ╭─ success ────────────────────────────────────────────────╮\n * │ │\n * │ Title │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n *\n * Complete:\n * ```\n * ╭─ success ────────────────────────────────────────────────╮\n * │ │\n * │ Title │\n * │ │\n * │ Body │\n * │ │\n * │ Next steps │\n * │ • Run cd santorini-goods │\n * │ • To preview your project, run npm app dev │\n * │ • To add extensions, run npm generate extension │\n * │ │\n * │ Reference │\n * │ • Run npm shopify help │\n * │ • Press 'return' to open the dev docs: │\n * │ https://shopify.dev │\n * │ │\n * │ Link: https://shopify.com │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n */\nexport function renderSuccess(options: RenderAlertOptions) {\n alert({...options, type: 'success'})\n}\n\n/**\n * Renders a warning banner to the console.\n *\n * Basic:\n *\n * ```\n * ╭─ warning ────────────────────────────────────────────────╮\n * │ │\n * │ Title │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n *\n * Complete:\n * ```\n * ╭─ warning ────────────────────────────────────────────────╮\n * │ │\n * │ Title │\n * │ │\n * │ Body │\n * │ │\n * │ Next steps │\n * │ • Run cd santorini-goods │\n * │ • To preview your project, run npm app dev │\n * │ • To add extensions, run npm generate extension │\n * │ │\n * │ Reference │\n * │ • Run npm shopify help │\n * │ • Press 'return' to open the dev docs: │\n * │ https://shopify.dev │\n * │ │\n * │ Link: https://shopify.com │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n */\nexport function renderWarning(options: RenderAlertOptions) {\n alert({...options, type: 'warning'})\n}\n\n/**\n * Renders a Fatal error to the console inside a banner.\n *\n * ```\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ Couldn't connect to the Shopify Partner Dashboard. │\n * │ │\n * │ Check your internet connection and try again. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n */\nexport function renderFatalError(error: Fatal) {\n fatalError(error)\n}\n\n/**\n * Renders a generic error to the console inside a banner.\n *\n * ```\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ Something went wrong. │\n * │ │\n * │ Check your internet connection. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * ```\n */\nexport function renderError(options: ErrorProps) {\n error(options)\n}\n"]}
package/dist/session.d.ts CHANGED
@@ -70,6 +70,16 @@ export declare function ensureAuthenticatedStorefront(scopes?: string[]): Promis
70
70
  * @returns The access token for the Admin API
71
71
  */
72
72
  export declare function ensureAuthenticatedAdmin(store: string, scopes?: string[]): Promise<AdminSession>;
73
+ /**
74
+ * Ensure that we have a valid session to access the Theme API.
75
+ * If a password is provided, that token will be used against Theme Access API.
76
+ * Otherwise, it will ensure that the user is authenticated with the Admin API.
77
+ * @param store - Store fqdn to request auth for
78
+ * @param password - Password generated from Theme Access app
79
+ * @param scopes - Optional array of extra scopes to authenticate with.
80
+ * @returns The access token and store
81
+ */
82
+ export declare function ensureAuthenticatedThemes(store: string, password: string | undefined, scopes?: string[]): Promise<AdminSession>;
73
83
  /**
74
84
  * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
75
85
  * @param applications - An object containing the applications we need to be authenticated with.
package/dist/session.js CHANGED
@@ -2,7 +2,7 @@ import { applicationId } from './session/identity.js';
2
2
  import { Abort, Bug } from './error.js';
3
3
  import { validateSession } from './session/validate.js';
4
4
  import { allDefaultScopes, apiScopes } from './session/scopes.js';
5
- import { identity as identityFqdn } from './environment/fqdn.js';
5
+ import { identity as identityFqdn, partners as partnersFqdn } from './environment/fqdn.js';
6
6
  import { open } from './system.js';
7
7
  import { exchangeAccessForApplicationTokens, exchangeCodeForAccessToken, exchangeCustomPartnerToken, refreshAccessToken, InvalidGrantError, } from './session/exchange.js';
8
8
  import { content, token, debug } from './output.js';
@@ -76,6 +76,23 @@ ${token.json(scopes)}
76
76
  }
77
77
  return tokens.admin;
78
78
  }
79
+ /**
80
+ * Ensure that we have a valid session to access the Theme API.
81
+ * If a password is provided, that token will be used against Theme Access API.
82
+ * Otherwise, it will ensure that the user is authenticated with the Admin API.
83
+ * @param store - Store fqdn to request auth for
84
+ * @param password - Password generated from Theme Access app
85
+ * @param scopes - Optional array of extra scopes to authenticate with.
86
+ * @returns The access token and store
87
+ */
88
+ export async function ensureAuthenticatedThemes(store, password, scopes = []) {
89
+ debug(content `Ensuring that the user is authenticated with the Theme API with the following scopes:
90
+ ${token.json(scopes)}
91
+ `);
92
+ if (password)
93
+ return { token: password, storeFqdn: normalizeStoreName(store) };
94
+ return ensureAuthenticatedAdmin(store, scopes);
95
+ }
79
96
  /**
80
97
  * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
81
98
  * @param applications - An object containing the applications we need to be authenticated with.
@@ -162,7 +179,7 @@ export async function ensureUserHasPartnerAccount(partnersToken) {
162
179
  output.info(`\nA Shopify Partners organization is needed to proceed.`);
163
180
  output.info(`👉 Press any key to create one`);
164
181
  await keypress();
165
- await open(`https://partners.shopify.com/signup`);
182
+ await open(`https://${await partnersFqdn()}/signup`);
166
183
  output.info(output.content `👉 Press any key when you have ${output.token.cyan('created the organization')}`);
167
184
  output.warn(output.content `Make sure you've confirmed your Shopify and the Partner organization from the email`);
168
185
  await keypress();
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,KAAK,EAAE,GAAG,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EAAC,QAAQ,IAAI,YAAY,EAAC,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAA;AAChC,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,0BAA0B,EAE1B,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAA;AAEhC,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAEhD,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAA;AACjD,OAAO,SAAS,MAAM,gBAAg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AAE,CAAA;IACnD,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,EAAE,MAAM,IAAI,EAAE,CAAA;IACjE,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC;QACrC,QAAQ,EAAE,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;QAC7C,UAAU,EAAE,SAAS,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;KAC/D,CAAA;AACH,CAAC;AAED,MAAM,UAAU,MAAM;IACpB,OAAO,WAAW,CAAC,MAAM,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {Abort, Bug} from './error.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {identity as identityFqdn} from './environment/fqdn.js'\nimport {open} from './system.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCodeForAccessToken,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n} from './session/exchange.js'\n\nimport {content, token, debug} from './output.js'\nimport {keypress} from './ui.js'\n\nimport {authorize} from './session/authorize.js'\nimport {IdentityToken, Session} from './session/schema.js'\nimport * as secureStore from './session/store.js'\nimport constants from './constants.js'\nimport {normalizeStoreName} from './string.js'\nimport * as output from './output.js'\nimport {partners} from './api.js'\nimport {RequestClientError} from './api/common.js'\nimport {firstPartyDev, useDeviceAuth} from './environment/local.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {gql} from 'graphql-request'\n\nconst NoSessionError = new Bug('No session found after ensuring authenticated')\nconst MissingPartnerTokenError = new Bug('No partners token found after ensuring authenticated')\nconst MissingAdminTokenError = new Bug('No admin token found after ensuring authenticated')\nconst MissingStorefrontTokenError = new Bug('No storefront token found after ensuring authenticated')\n\n/**\n * A scope supported by the Shopify Admin API.\n */\ntype AdminAPIScope = 'graphql' | 'themes' | 'collaborator' | string\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\ninterface AdminAPIOAuthOptions {\n /** Store to request permissions for */\n storeFqdn: string\n /** List of scopes to request permissions for */\n scopes: AdminAPIScope[]\n}\n\n/**\n * A scope supported by the Partners API.\n */\ntype PartnersAPIScope = 'cli' | string\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\ntype StorefrontRendererScope = 'devtools' | string\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for */\n scopes: StorefrontRendererScope[]\n}\n\n/**\n * It represents the authentication requirements and\n * is the input necessary to trigger the authentication\n * flow.\n */\nexport interface OAuthApplications {\n adminApi?: AdminAPIOAuthOptions\n storefrontRendererApi?: StorefrontRendererAPIOAuthOptions\n partnersApi?: PartnersAPIOAuthOptions\n}\n\nexport interface AdminSession {\n token: string\n storeFqdn: string\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n}\nexport const PartnerOrganizationNotFoundError = () => {\n return new Abort(\n `Couldn't find your Shopify Partners organization`,\n `Have you confirmed your accounts from the emails you received?`,\n )\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 * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Partners API.\n */\nexport async function ensureAuthenticatedPartners(scopes: string[] = [], env = process.env): Promise<string> {\n debug(content`Ensuring that the user is authenticated with the Partners API with the following scopes:\n${token.json(scopes)}\n`)\n const envToken = env[constants.environmentVariables.partnersToken]\n if (envToken) {\n return (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n const tokens = await ensureAuthenticated({partnersApi: {scopes}})\n if (!tokens.partners) {\n throw MissingPartnerTokenError\n }\n return tokens.partners\n}\n\n/**\n * Ensure that we have a valid session to access the Storefront API.\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Storefront API.\n */\nexport async function ensureAuthenticatedStorefront(scopes: string[] = []): Promise<string> {\n debug(content`Ensuring that the user is authenticated with the Storefront API with the following scopes:\n${token.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({storefrontRendererApi: {scopes}})\n if (!tokens.storefront) {\n throw MissingStorefrontTokenError\n }\n return tokens.storefront\n}\n\n/**\n * Ensure that we have a valid Admin session for the given store.\n * @param store - Store fqdn to request auth for\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Admin API\n */\nexport async function ensureAuthenticatedAdmin(store: string, scopes: string[] = []): Promise<AdminSession> {\n debug(content`Ensuring that the user is authenticated with the Admin API with the following scopes for the store ${token.raw(\n store,\n )}:\n${token.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({adminApi: {scopes, storeFqdn: store}})\n if (!tokens.admin) {\n throw MissingAdminTokenError\n }\n return tokens.admin\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n * @param applications - An object containing the applications we need to be authenticated with.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(applications: OAuthApplications, env = process.env): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n if (applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizeStoreName(applications.adminApi.storeFqdn)\n }\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdnSession = currentSession[fqdn]!\n const scopes = getFlattenScopes(applications)\n\n debug(content`Validating existing session against the scopes:\n${token.json(scopes)}\nFor applications:\n${token.json(applications)}\n`)\n const validationResult = await validateSession(scopes, applications, fqdnSession)\n\n let newSession = {}\n\n if (validationResult === 'needs_full_auth') {\n debug(content`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (validationResult === 'needs_refresh') {\n debug(content`The current session is valid but needs refresh. Refreshing...`)\n try {\n newSession = await refreshTokens(fqdnSession.identity, applications, fqdn)\n } catch (error) {\n if (error instanceof InvalidGrantError) {\n newSession = await executeCompleteFlow(applications, fqdn)\n } else {\n throw error\n }\n }\n }\n\n const completeSession: Session = {...currentSession, ...newSession}\n await secureStore.store(completeSession)\n const tokens = await tokensFor(applications, completeSession, fqdn)\n\n // Overwrite partners token if using a custom CLI Token\n const envToken = env[constants.environmentVariables.partnersToken]\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n if (!envToken && tokens.partners) {\n await ensureUserHasPartnerAccount(tokens.partners)\n }\n\n return tokens\n}\n\nexport async function hasPartnerAccount(partnersToken: string): Promise<boolean> {\n try {\n await partners.request(\n gql`\n {\n organizations(first: 1) {\n nodes {\n id\n }\n }\n }\n `,\n partnersToken,\n )\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n if (error instanceof RequestClientError && error.statusCode === 404) {\n return false\n } else {\n return true\n }\n }\n}\n\n/**\n * If the user creates an account from the Identity website, the created\n * account won't get a Partner organization created. We need to detect that\n * and take the user to create a partner organization.\n * @param partnersToken - Partners token\n */\nexport async function ensureUserHasPartnerAccount(partnersToken: string) {\n debug(content`Verifying that the user has a Partner organization`)\n if (!(await hasPartnerAccount(partnersToken))) {\n output.info(`\\nA Shopify Partners organization is needed to proceed.`)\n output.info(`👉 Press any key to create one`)\n await keypress()\n await open(`https://partners.shopify.com/signup`)\n output.info(output.content`👉 Press any key when you have ${output.token.cyan('created the organization')}`)\n output.warn(output.content`Make sure you've confirmed your Shopify and the Partner organization from the email`)\n await keypress()\n if (!(await hasPartnerAccount(partnersToken))) {\n throw PartnerOrganizationNotFoundError()\n }\n }\n}\n\nasync function executeCompleteFlow(applications: OAuthApplications, identityFqdn: string): Promise<Session> {\n const scopes = getFlattenScopes(applications)\n const exchangeScopes = getExchangeScopes(applications)\n const store = applications.adminApi?.storeFqdn\n if (firstPartyDev()) {\n debug(content`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n if (useDeviceAuth()) {\n // Request a device code to authorize without a browser redirect.\n debug(content`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n debug(content`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n } else {\n // Authorize user via browser\n debug(content`Authorizing through Identity's website...`)\n const code = await authorize(scopes)\n\n // Exchange code for identity token\n debug(content`Authorization code received. Exchanging it for a CLI token...`)\n identityToken = await exchangeCodeForAccessToken(code)\n }\n\n // Exchange identity token for application tokens\n debug(content`CLI token received. Exchanging it for application tokens...`)\n const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)\n\n const session: Session = {\n [identityFqdn]: {\n identity: identityToken,\n applications: result,\n },\n }\n\n output.completed('Logged in.')\n\n return session\n}\n\nasync function refreshTokens(token: IdentityToken, applications: OAuthApplications, fqdn: string): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(token)\n\n // Exchange new identity token for application tokens\n const exchangeScopes = getExchangeScopes(applications)\n const applicationTokens = await exchangeAccessForApplicationTokens(\n identityToken,\n exchangeScopes,\n applications.adminApi?.storeFqdn,\n )\n\n return {\n [fqdn]: {\n identity: identityToken,\n applications: applicationTokens,\n },\n }\n}\n\nasync function tokensFor(applications: OAuthApplications, session: Session, fqdn: string): Promise<OAuthSession> {\n const fqdnSession = session[fqdn]\n if (!fqdnSession) {\n throw NoSessionError\n }\n const tokens: OAuthSession = {}\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = fqdnSession.applications[realAppId]?.accessToken\n if (token) {\n tokens.admin = {token, storeFqdn: applications.adminApi.storeFqdn}\n }\n }\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n tokens.partners = fqdnSession.applications[appId]?.accessToken\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n tokens.storefront = fqdnSession.applications[appId]?.accessToken\n }\n return tokens\n}\n\n// Scope Helpers\nfunction getFlattenScopes(apps: OAuthApplications): string[] {\n const admin = apps.adminApi?.scopes || []\n const partner = apps.partnersApi?.scopes || []\n const storefront = apps.storefrontRendererApi?.scopes || []\n const requestedScopes = [...admin, ...partner, ...storefront]\n return allDefaultScopes(requestedScopes)\n}\n\nfunction getExchangeScopes(apps: OAuthApplications): ExchangeScopes {\n const adminScope = apps.adminApi?.scopes || []\n const partnerScope = apps.partnersApi?.scopes || []\n const storefrontScopes = apps.storefrontRendererApi?.scopes || []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n }\n}\n\nexport function logout() {\n return secureStore.remove()\n}\n"]}
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,KAAK,EAAE,GAAG,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EAAC,QAAQ,IAAI,YAAY,EAAE,QAAQ,IAAI,YAAY,EAAC,MAAM,uBAAuB,CAAA;AACxF,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAA;AAChC,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,0BAA0B,EAE1B,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAA;AAEhC,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAEhD,OAAO,KAAK,WAAW,MAAM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AI,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAA;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,EAAE,MAAM,IAAI,EAAE,CAAA;IAC3D,MAAM,eAAe,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,OAAO,EAAE,GAAG,UAAU,CAAC,CAAA;IAC7D,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAA;AAC1C,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAuB;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAA;IAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAA;IACnD,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,EAAE,MAAM,IAAI,EAAE,CAAA;IACjE,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC;QACrC,QAAQ,EAAE,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;QAC7C,UAAU,EAAE,SAAS,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;KAC/D,CAAA;AACH,CAAC;AAED,MAAM,UAAU,MAAM;IACpB,OAAO,WAAW,CAAC,MAAM,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {Abort, Bug} from './error.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {identity as identityFqdn, partners as partnersFqdn} from './environment/fqdn.js'\nimport {open} from './system.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCodeForAccessToken,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n} from './session/exchange.js'\n\nimport {content, token, debug} from './output.js'\nimport {keypress} from './ui.js'\n\nimport {authorize} from './session/authorize.js'\nimport {IdentityToken, Session} from './session/schema.js'\nimport * as secureStore from './session/store.js'\nimport constants from './constants.js'\nimport {normalizeStoreName} from './string.js'\nimport * as output from './output.js'\nimport {partners} from './api.js'\nimport {RequestClientError} from './api/common.js'\nimport {firstPartyDev, useDeviceAuth} from './environment/local.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {gql} from 'graphql-request'\n\nconst NoSessionError = new Bug('No session found after ensuring authenticated')\nconst MissingPartnerTokenError = new Bug('No partners token found after ensuring authenticated')\nconst MissingAdminTokenError = new Bug('No admin token found after ensuring authenticated')\nconst MissingStorefrontTokenError = new Bug('No storefront token found after ensuring authenticated')\n\n/**\n * A scope supported by the Shopify Admin API.\n */\ntype AdminAPIScope = 'graphql' | 'themes' | 'collaborator' | string\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\ninterface AdminAPIOAuthOptions {\n /** Store to request permissions for */\n storeFqdn: string\n /** List of scopes to request permissions for */\n scopes: AdminAPIScope[]\n}\n\n/**\n * A scope supported by the Partners API.\n */\ntype PartnersAPIScope = 'cli' | string\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\ntype StorefrontRendererScope = 'devtools' | string\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for */\n scopes: StorefrontRendererScope[]\n}\n\n/**\n * It represents the authentication requirements and\n * is the input necessary to trigger the authentication\n * flow.\n */\nexport interface OAuthApplications {\n adminApi?: AdminAPIOAuthOptions\n storefrontRendererApi?: StorefrontRendererAPIOAuthOptions\n partnersApi?: PartnersAPIOAuthOptions\n}\n\nexport interface AdminSession {\n token: string\n storeFqdn: string\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n}\nexport const PartnerOrganizationNotFoundError = () => {\n return new Abort(\n `Couldn't find your Shopify Partners organization`,\n `Have you confirmed your accounts from the emails you received?`,\n )\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 * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Partners API.\n */\nexport async function ensureAuthenticatedPartners(scopes: string[] = [], env = process.env): Promise<string> {\n debug(content`Ensuring that the user is authenticated with the Partners API with the following scopes:\n${token.json(scopes)}\n`)\n const envToken = env[constants.environmentVariables.partnersToken]\n if (envToken) {\n return (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n const tokens = await ensureAuthenticated({partnersApi: {scopes}})\n if (!tokens.partners) {\n throw MissingPartnerTokenError\n }\n return tokens.partners\n}\n\n/**\n * Ensure that we have a valid session to access the Storefront API.\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Storefront API.\n */\nexport async function ensureAuthenticatedStorefront(scopes: string[] = []): Promise<string> {\n debug(content`Ensuring that the user is authenticated with the Storefront API with the following scopes:\n${token.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({storefrontRendererApi: {scopes}})\n if (!tokens.storefront) {\n throw MissingStorefrontTokenError\n }\n return tokens.storefront\n}\n\n/**\n * Ensure that we have a valid Admin session for the given store.\n * @param store - Store fqdn to request auth for\n * @param scopes - Optional array of extra scopes to authenticate with.\n * @returns The access token for the Admin API\n */\nexport async function ensureAuthenticatedAdmin(store: string, scopes: string[] = []): Promise<AdminSession> {\n debug(content`Ensuring that the user is authenticated with the Admin API with the following scopes for the store ${token.raw(\n store,\n )}:\n${token.json(scopes)}\n`)\n const tokens = await ensureAuthenticated({adminApi: {scopes, storeFqdn: store}})\n if (!tokens.admin) {\n throw MissingAdminTokenError\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 * @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 * @returns The access token and store\n */\nexport async function ensureAuthenticatedThemes(\n store: string,\n password: string | undefined,\n scopes: string[] = [],\n): Promise<AdminSession> {\n debug(content`Ensuring that the user is authenticated with the Theme API with the following scopes:\n${token.json(scopes)}\n`)\n if (password) return {token: password, storeFqdn: normalizeStoreName(store)}\n return ensureAuthenticatedAdmin(store, scopes)\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n * @param applications - An object containing the applications we need to be authenticated with.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(applications: OAuthApplications, env = process.env): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n if (applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizeStoreName(applications.adminApi.storeFqdn)\n }\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdnSession = currentSession[fqdn]!\n const scopes = getFlattenScopes(applications)\n\n debug(content`Validating existing session against the scopes:\n${token.json(scopes)}\nFor applications:\n${token.json(applications)}\n`)\n const validationResult = await validateSession(scopes, applications, fqdnSession)\n\n let newSession = {}\n\n if (validationResult === 'needs_full_auth') {\n debug(content`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (validationResult === 'needs_refresh') {\n debug(content`The current session is valid but needs refresh. Refreshing...`)\n try {\n newSession = await refreshTokens(fqdnSession.identity, applications, fqdn)\n } catch (error) {\n if (error instanceof InvalidGrantError) {\n newSession = await executeCompleteFlow(applications, fqdn)\n } else {\n throw error\n }\n }\n }\n\n const completeSession: Session = {...currentSession, ...newSession}\n await secureStore.store(completeSession)\n const tokens = await tokensFor(applications, completeSession, fqdn)\n\n // Overwrite partners token if using a custom CLI Token\n const envToken = env[constants.environmentVariables.partnersToken]\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n if (!envToken && tokens.partners) {\n await ensureUserHasPartnerAccount(tokens.partners)\n }\n\n return tokens\n}\n\nexport async function hasPartnerAccount(partnersToken: string): Promise<boolean> {\n try {\n await partners.request(\n gql`\n {\n organizations(first: 1) {\n nodes {\n id\n }\n }\n }\n `,\n partnersToken,\n )\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n if (error instanceof RequestClientError && error.statusCode === 404) {\n return false\n } else {\n return true\n }\n }\n}\n\n/**\n * If the user creates an account from the Identity website, the created\n * account won't get a Partner organization created. We need to detect that\n * and take the user to create a partner organization.\n * @param partnersToken - Partners token\n */\nexport async function ensureUserHasPartnerAccount(partnersToken: string) {\n debug(content`Verifying that the user has a Partner organization`)\n if (!(await hasPartnerAccount(partnersToken))) {\n output.info(`\\nA Shopify Partners organization is needed to proceed.`)\n output.info(`👉 Press any key to create one`)\n await keypress()\n await open(`https://${await partnersFqdn()}/signup`)\n output.info(output.content`👉 Press any key when you have ${output.token.cyan('created the organization')}`)\n output.warn(output.content`Make sure you've confirmed your Shopify and the Partner organization from the email`)\n await keypress()\n if (!(await hasPartnerAccount(partnersToken))) {\n throw PartnerOrganizationNotFoundError()\n }\n }\n}\n\nasync function executeCompleteFlow(applications: OAuthApplications, identityFqdn: string): Promise<Session> {\n const scopes = getFlattenScopes(applications)\n const exchangeScopes = getExchangeScopes(applications)\n const store = applications.adminApi?.storeFqdn\n if (firstPartyDev()) {\n debug(content`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n if (useDeviceAuth()) {\n // Request a device code to authorize without a browser redirect.\n debug(content`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n debug(content`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n } else {\n // Authorize user via browser\n debug(content`Authorizing through Identity's website...`)\n const code = await authorize(scopes)\n\n // Exchange code for identity token\n debug(content`Authorization code received. Exchanging it for a CLI token...`)\n identityToken = await exchangeCodeForAccessToken(code)\n }\n\n // Exchange identity token for application tokens\n debug(content`CLI token received. Exchanging it for application tokens...`)\n const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)\n\n const session: Session = {\n [identityFqdn]: {\n identity: identityToken,\n applications: result,\n },\n }\n\n output.completed('Logged in.')\n\n return session\n}\n\nasync function refreshTokens(token: IdentityToken, applications: OAuthApplications, fqdn: string): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(token)\n\n // Exchange new identity token for application tokens\n const exchangeScopes = getExchangeScopes(applications)\n const applicationTokens = await exchangeAccessForApplicationTokens(\n identityToken,\n exchangeScopes,\n applications.adminApi?.storeFqdn,\n )\n\n return {\n [fqdn]: {\n identity: identityToken,\n applications: applicationTokens,\n },\n }\n}\n\nasync function tokensFor(applications: OAuthApplications, session: Session, fqdn: string): Promise<OAuthSession> {\n const fqdnSession = session[fqdn]\n if (!fqdnSession) {\n throw NoSessionError\n }\n const tokens: OAuthSession = {}\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = fqdnSession.applications[realAppId]?.accessToken\n if (token) {\n tokens.admin = {token, storeFqdn: applications.adminApi.storeFqdn}\n }\n }\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n tokens.partners = fqdnSession.applications[appId]?.accessToken\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n tokens.storefront = fqdnSession.applications[appId]?.accessToken\n }\n return tokens\n}\n\n// Scope Helpers\nfunction getFlattenScopes(apps: OAuthApplications): string[] {\n const admin = apps.adminApi?.scopes || []\n const partner = apps.partnersApi?.scopes || []\n const storefront = apps.storefrontRendererApi?.scopes || []\n const requestedScopes = [...admin, ...partner, ...storefront]\n return allDefaultScopes(requestedScopes)\n}\n\nfunction getExchangeScopes(apps: OAuthApplications): ExchangeScopes {\n const adminScope = apps.adminApi?.scopes || []\n const partnerScope = apps.partnersApi?.scopes || []\n const storefrontScopes = apps.storefrontRendererApi?.scopes || []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n }\n}\n\nexport function logout() {\n return secureStore.remove()\n}\n"]}
package/dist/string.d.ts CHANGED
@@ -30,3 +30,4 @@ export declare function tryParseInt(maybeInt: string | undefined): number | unde
30
30
  * Parse it into a single string with the columns aligned
31
31
  */
32
32
  export declare function linesToColumns(lines: string[][]): string;
33
+ export declare const slugify: (str: string) => string;
package/dist/string.js CHANGED
@@ -76,4 +76,10 @@ export function linesToColumns(lines) {
76
76
  .join('\n');
77
77
  return paddedLines;
78
78
  }
79
+ export const slugify = (str) => str
80
+ .toLowerCase()
81
+ .trim()
82
+ .replace(/[^\w\s-]/g, '')
83
+ .replace(/[\s_-]+/g, '-')
84
+ .replace(/^-+|-+$/g, '');
79
85
  //# sourceMappingURL=string.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AACpC,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,EAAC,SAAS,IAAI,QAAQ,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,SAAS,IAAI,SAAS,EAAC,MAAM,aAAa,CAAA;AAClD,OAAO,EAAC,SAAS,IAAI,UAAU,EAAC,MAAM,aAAa,CAAA;AACnD,OAAO,EAAC,YAAY,IAAI,WAAW,EAAC,MAAM,aAAa,CAAA;AAEvD,8BAA8B;AAC9B,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,MAAM,YAAY,GAAG,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;IAC5D,MAAM,aAAa,GAAG,eAAe,CAAC,MAAM,CAAC,Y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elCase as camelize} from 'change-case'\nexport {paramCase as hyphenize} from 'change-case'\nexport {snakeCase as underscore} from 'change-case'\nexport {constantCase as constantize} from 'change-case'\n\n/** Returns a random string */\nexport function randomHex(size: number): string {\n return crypto.randomBytes(size).toString('hex')\n}\n\nexport function generateRandomChallengePair() {\n const codeVerifier = base64URLEncode(crypto.randomBytes(32))\n const codeChallenge = base64URLEncode(sha256(codeVerifier))\n return {codeVerifier, codeChallenge}\n}\n\nfunction base64URLEncode(str: Buffer) {\n return str.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/[=]/g, '')\n}\n\nfunction sha256(str: string) {\n return crypto.createHash('sha256').update(str).digest()\n}\n\nexport function hashString(str: string): string {\n return crypto.createHash('sha1').update(str).digest('hex')\n}\n\n/**\n * Given a string, it returns it with the first letter capitalized.\n * @param string - String whose first letter will be caplitalized.\n * @returns The given string with its first letter capitalized.\n */\nexport function capitalize(string: string) {\n return string.substring(0, 1).toUpperCase() + string.substring(1)\n}\n\n/**\n * Given a store, returns a valid store fqdn removing protocol and adding .myshopify.com domain\n * @param store - Original store name provided by the user\n * @returns a valid store fqdn\n */\nexport function normalizeStoreName(store: string) {\n const storeFqdn = store.replace(/^https?:\\/\\//, '').replace(/\\/$/, '')\n return storeFqdn.includes('.myshopify.com') || storeFqdn.includes('spin.dev')\n ? storeFqdn\n : `${storeFqdn}.myshopify.com`\n}\n\n/**\n * Try to convert a string to an int, falling back to undefined if unable to\n */\nexport function tryParseInt(maybeInt: string | undefined) {\n let asInt: number | undefined\n if (maybeInt !== undefined) {\n asInt = parseInt(maybeInt, 10)\n if (isNaN(asInt)) {\n asInt = undefined\n }\n }\n return asInt\n}\n\n/**\n * Given a series of rows inside an array, where each row is an array of strings (representing columns)\n * Parse it into a single string with the columns aligned\n */\nexport function linesToColumns(lines: string[][]): string {\n const widths: number[] = []\n for (let i = 0; lines[0] && i < lines[0].length; i++) {\n const columnRows = lines.map((line) => line[i]!)\n widths.push(Math.max(...columnRows.map((row) => unstyled(row).length)))\n }\n const paddedLines = lines\n .map((line) => {\n return line\n .map((col, index) => {\n return `${col}${' '.repeat(widths[index]! - unstyled(col).length)}`\n })\n .join(' ')\n .trimEnd()\n })\n .join('\\n')\n return paddedLines\n}\n"]}
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AACpC,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,EAAC,SAAS,IAAI,QAAQ,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,SAAS,IAAI,SAAS,EAAC,MAAM,aAAa,CAAA;AAClD,OAAO,EAAC,SAAS,IAAI,UAAU,EAAC,MAAM,aAAa,CAAA;AACnD,OAAO,EAAC,YAAY,IAAI,WAAW,EAAC,MAAM,aAAa,CAAA;AAEvD,8BAA8B;AAC9B,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,MAAM,YAAY,GAAG,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;IAC5D,MAAM,aAAa,GAAG,eAAe,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;IAC3D,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,CAAA;AACtC,CAAC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAC3F,CAAC;AAED,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,MAAM,CAAC,UAAU,CAAC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,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpD,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,CAAA;QAChD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;KACxE;IACD,MAAM,WAAW,GAAG,KAAK;SACtB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,OAAO,IAAI;aACR,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAClB,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAA;QACrE,CAAC,CAAC;aACD,IAAI,CAAC,KAAK,CAAC;aACX,OAAO,EAAE,CAAA;IACd,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;IACb,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CACrC,GAAG;KACA,WAAW,EAAE;KACb,IAAI,EAAE;KACN,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;KACxB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;KACxB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA","sourcesContent":["import {unstyled} from './output.js'\nimport crypto from 'crypto'\n\nexport {camelCase as camelize} from 'change-case'\nexport {paramCase as hyphenize} from 'change-case'\nexport {snakeCase as underscore} from 'change-case'\nexport {constantCase as constantize} from 'change-case'\n\n/** Returns a random string */\nexport function randomHex(size: number): string {\n return crypto.randomBytes(size).toString('hex')\n}\n\nexport function generateRandomChallengePair() {\n const codeVerifier = base64URLEncode(crypto.randomBytes(32))\n const codeChallenge = base64URLEncode(sha256(codeVerifier))\n return {codeVerifier, codeChallenge}\n}\n\nfunction base64URLEncode(str: Buffer) {\n return str.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/[=]/g, '')\n}\n\nfunction sha256(str: string) {\n return crypto.createHash('sha256').update(str).digest()\n}\n\nexport function hashString(str: string): string {\n return crypto.createHash('sha1').update(str).digest('hex')\n}\n\n/**\n * Given a string, it returns it with the first letter capitalized.\n * @param string - String whose first letter will be caplitalized.\n * @returns The given string with its first letter capitalized.\n */\nexport function capitalize(string: string) {\n return string.substring(0, 1).toUpperCase() + string.substring(1)\n}\n\n/**\n * Given a store, returns a valid store fqdn removing protocol and adding .myshopify.com domain\n * @param store - Original store name provided by the user\n * @returns a valid store fqdn\n */\nexport function normalizeStoreName(store: string) {\n const storeFqdn = store.replace(/^https?:\\/\\//, '').replace(/\\/$/, '')\n return storeFqdn.includes('.myshopify.com') || storeFqdn.includes('spin.dev')\n ? storeFqdn\n : `${storeFqdn}.myshopify.com`\n}\n\n/**\n * Try to convert a string to an int, falling back to undefined if unable to\n */\nexport function tryParseInt(maybeInt: string | undefined) {\n let asInt: number | undefined\n if (maybeInt !== undefined) {\n asInt = parseInt(maybeInt, 10)\n if (isNaN(asInt)) {\n asInt = undefined\n }\n }\n return asInt\n}\n\n/**\n * Given a series of rows inside an array, where each row is an array of strings (representing columns)\n * Parse it into a single string with the columns aligned\n */\nexport function linesToColumns(lines: string[][]): string {\n const widths: number[] = []\n for (let i = 0; lines[0] && i < lines[0].length; i++) {\n const columnRows = lines.map((line) => line[i]!)\n widths.push(Math.max(...columnRows.map((row) => unstyled(row).length)))\n }\n const paddedLines = lines\n .map((line) => {\n return line\n .map((col, index) => {\n return `${col}${' '.repeat(widths[index]! - unstyled(col).length)}`\n })\n .join(' ')\n .trimEnd()\n })\n .join('\\n')\n return paddedLines\n}\n\nexport const slugify = (str: string) =>\n str\n .toLowerCase()\n .trim()\n .replace(/[^\\w\\s-]/g, '')\n .replace(/[\\s_-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n"]}
package/dist/system.d.ts CHANGED
@@ -33,11 +33,8 @@ interface ConcurrentExecCommand {
33
33
  }
34
34
  /**
35
35
  * Runs commands concurrently and combines the standard output and error data
36
- * into a single stream that differenciates the sources using a colored prefix:
37
- *
38
- * Example:
39
- * [my-extension] Log coming from my-extension
40
- * [my-script] Log coming from my script
36
+ * into a single stream. See {@link renderConcurrent} for more information about
37
+ * the output format.
41
38
  *
42
39
  * If one of the processes fails, it aborts the running ones and exits with that error.
43
40
  * @param commands - Commands to execute.
package/dist/system.js CHANGED
@@ -1,6 +1,7 @@
1
- import { concurrent as concurrentOutput, shouldDisplayColors, debug } from './output.js';
1
+ import { shouldDisplayColors, debug } from './output.js';
2
2
  import { platformAndArch } from './os.js';
3
3
  import { Abort } from './error.js';
4
+ import { renderConcurrent } from './public/node/ui.js';
4
5
  import { execa } from 'execa';
5
6
  export const open = async (url) => {
6
7
  const externalOpen = await import('open');
@@ -60,29 +61,28 @@ Running system process:
60
61
  };
61
62
  /**
62
63
  * Runs commands concurrently and combines the standard output and error data
63
- * into a single stream that differenciates the sources using a colored prefix:
64
- *
65
- * Example:
66
- * [my-extension] Log coming from my-extension
67
- * [my-script] Log coming from my script
64
+ * into a single stream. See {@link renderConcurrent} for more information about
65
+ * the output format.
68
66
  *
69
67
  * If one of the processes fails, it aborts the running ones and exits with that error.
70
68
  * @param commands - Commands to execute.
71
69
  */
72
70
  export const concurrentExec = async (commands) => {
73
- await concurrentOutput(commands.map((command) => {
74
- return {
75
- prefix: command.prefix,
76
- action: async (stdout, stderr, signal) => {
77
- await exec(command.executable, command.args, {
78
- stdout,
79
- stderr,
80
- cwd: command.cwd,
81
- signal,
82
- });
83
- },
84
- };
85
- }));
71
+ await renderConcurrent({
72
+ processes: commands.map((command) => {
73
+ return {
74
+ prefix: command.prefix,
75
+ action: async (stdout, stderr, signal) => {
76
+ await exec(command.executable, command.args, {
77
+ stdout,
78
+ stderr,
79
+ cwd: command.cwd,
80
+ signal,
81
+ });
82
+ },
83
+ };
84
+ }),
85
+ });
86
86
  };
87
87
  /**
88
88
  * Displays a large file using the terminal pager set by the user, or a
@@ -1 +1 @@
1
- {"version":3,"file":"system.js","sourceRoot":"","sources":["../src/system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,IAAI,gBAAgB,EAAE,mBAAmB,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACtF,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;AACvC,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,KAAK,EAAoB,MAAM,OAAO,CAAA;AAgB9C,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE;IACxC,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAA;IACzC,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACjC,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,OAAe,EAAE,IAAc,EAAE,OAAqB,EAAmB,EAAE;IAC7G,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACtD,OAAO,MAAM,CAAC,MAAM,CAAA;AACtB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,OAAe,EAAE,IAAc,EAAE,OAAqB,EAAE,EAAE;IACnF,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,EAA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C,CAAA;IAC/D,MAAM,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,EAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAC,CAAC,CAAA;AAClE,CAAC;AAED,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","sourcesContent":["import {concurrent as concurrentOutput, shouldDisplayColors, debug} from './output.js'\nimport {platformAndArch} from './os.js'\nimport {Abort} from './error.js'\nimport {execa, ExecaChildProcess} from 'execa'\nimport {AbortSignal} from 'abort-controller'\nimport type {Writable, Readable} from 'node: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}\nexport type WritableExecOptions = Omit<ExecOptions, 'stdout'> & {stdout?: Writable}\n\nexport const open = async (url: string) => {\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 * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @returns A promise that resolves with the aggregatted stdout of the command.\n */\nexport const captureOutput = async (command: string, args: string[], options?: ExecOptions): Promise<string> => {\n const result = await buildExec(command, args, options)\n return result.stdout\n}\n\nexport const exec = async (command: string, args: string[], options?: ExecOptions) => {\n const commandProcess = buildExec(command, args, options)\n if (options?.stderr && options.stderr !== 'inherit') {\n commandProcess.stderr?.pipe(options.stderr)\n }\n if (options?.stdout && options.stdout !== 'inherit') {\n commandProcess.stdout?.pipe(options.stdout)\n }\n options?.signal?.addEventListener('abort', () => {\n commandProcess.kill('SIGTERM', {forceKillAfterTimeout: 1000})\n })\n try {\n await commandProcess\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n const abortError = new Abort(processError.message)\n abortError.stack = processError.stack\n throw abortError\n }\n}\n\nconst 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 })\n debug(`\nRunning system process:\n · Command: ${command} ${args.join(' ')}\n · Working directory: ${options?.cwd ?? process.cwd()}\n`)\n return commandProcess\n}\n\ninterface ConcurrentExecCommand {\n prefix: string\n executable: string\n args: string[]\n cwd: string\n}\n\n/**\n * Runs commands concurrently and combines the standard output and error data\n * into a single stream that differenciates the sources using a colored prefix:\n *\n * Example:\n * [my-extension] Log coming from my-extension\n * [my-script] Log coming from my script\n *\n * If one of the processes fails, it aborts the running ones and exits with that error.\n * @param commands - Commands to execute.\n */\nexport const concurrentExec = async (commands: ConcurrentExecCommand[]): Promise<void> => {\n await concurrentOutput(\n commands.map((command) => {\n return {\n prefix: command.prefix,\n action: async (stdout, stderr, signal) => {\n await exec(command.executable, command.args, {\n stdout,\n stderr,\n cwd: command.cwd,\n signal,\n })\n },\n }\n }),\n )\n}\n\n/**\n * Displays a large file using the terminal pager set by the user, or a\n * reasonable default for the user's OS:\n *\n * @param filename - The path to the file to be displayed.\n */\nexport async function page(filename: string) {\n let executable: string\n if (process.env.PAGER) {\n executable = process.env.PAGER\n } else if ((await platformAndArch()).platform === 'windows') {\n executable = 'more'\n } else {\n executable = 'less -NR'\n }\n const [command, ...args] = [...executable.split(' '), filename]\n await exec(command, args, {stdout: 'inherit', stdin: 'inherit'})\n}\n\nexport async function sleep(seconds: number) {\n return new Promise((resolve) => {\n setTimeout(resolve, 1000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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","sourcesContent":["import {shouldDisplayColors, debug} from './output.js'\nimport {platformAndArch} from './os.js'\nimport {Abort} from './error.js'\nimport {renderConcurrent} from './public/node/ui.js'\nimport {execa, ExecaChildProcess} from 'execa'\nimport {AbortSignal} from 'abort-controller'\nimport type {Writable, Readable} from 'node: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}\nexport type WritableExecOptions = Omit<ExecOptions, 'stdout'> & {stdout?: Writable}\n\nexport const open = async (url: string) => {\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 * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @returns A promise that resolves with the aggregatted stdout of the command.\n */\nexport const captureOutput = async (command: string, args: string[], options?: ExecOptions): Promise<string> => {\n const result = await buildExec(command, args, options)\n return result.stdout\n}\n\nexport const exec = async (command: string, args: string[], options?: ExecOptions) => {\n const commandProcess = buildExec(command, args, options)\n if (options?.stderr && options.stderr !== 'inherit') {\n commandProcess.stderr?.pipe(options.stderr)\n }\n if (options?.stdout && options.stdout !== 'inherit') {\n commandProcess.stdout?.pipe(options.stdout)\n }\n options?.signal?.addEventListener('abort', () => {\n commandProcess.kill('SIGTERM', {forceKillAfterTimeout: 1000})\n })\n try {\n await commandProcess\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n const abortError = new Abort(processError.message)\n abortError.stack = processError.stack\n throw abortError\n }\n}\n\nconst 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 })\n debug(`\nRunning system process:\n · Command: ${command} ${args.join(' ')}\n · Working directory: ${options?.cwd ?? process.cwd()}\n`)\n return commandProcess\n}\n\ninterface ConcurrentExecCommand {\n prefix: string\n executable: string\n args: string[]\n cwd: string\n}\n\n/**\n * Runs commands concurrently and combines the standard output and error data\n * into a single stream. See {@link renderConcurrent} for more information about\n * the output format.\n *\n * If one of the processes fails, it aborts the running ones and exits with that error.\n * @param commands - Commands to execute.\n */\nexport const concurrentExec = async (commands: ConcurrentExecCommand[]): Promise<void> => {\n await renderConcurrent({\n processes: commands.map((command) => {\n return {\n prefix: command.prefix,\n action: async (stdout, stderr, signal) => {\n await exec(command.executable, command.args, {\n stdout,\n stderr,\n cwd: command.cwd,\n signal,\n })\n },\n }\n }),\n })\n}\n\n/**\n * Displays a large file using the terminal pager set by the user, or a\n * reasonable default for the user's OS:\n *\n * @param filename - The path to the file to be displayed.\n */\nexport async function page(filename: string) {\n let executable: string\n if (process.env.PAGER) {\n executable = process.env.PAGER\n } else if ((await platformAndArch()).platform === 'windows') {\n executable = 'more'\n } else {\n executable = 'less -NR'\n }\n const [command, ...args] = [...executable.split(' '), filename]\n await exec(command, args, {stdout: 'inherit', stdin: 'inherit'})\n}\n\nexport async function sleep(seconds: number) {\n return new Promise((resolve) => {\n setTimeout(resolve, 1000 * seconds)\n })\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { renderConcurrent } from '@shopify/cli-kit/node/ui';
2
+ import { AbortController } from 'abort-controller';
3
+ const abortController = new AbortController();
4
+ let backendPromiseResolve;
5
+ const backendPromise = new Promise(function (resolve, _reject) {
6
+ backendPromiseResolve = resolve;
7
+ });
8
+ const backendProcess = {
9
+ prefix: 'backend',
10
+ action: async (stdout, _stderr, _signal) => {
11
+ stdout.write('first backend message');
12
+ stdout.write('second backend message');
13
+ stdout.write('third backend message');
14
+ backendPromiseResolve();
15
+ },
16
+ };
17
+ const frontendProcess = {
18
+ prefix: 'frontend',
19
+ action: async (stdout, _stderr, _signal) => {
20
+ await backendPromise;
21
+ stdout.write('first frontend message');
22
+ stdout.write('second frontend message');
23
+ stdout.write('third frontend message');
24
+ },
25
+ };
26
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
27
+ renderConcurrent({ processes: [backendProcess, frontendProcess], abortController });
28
+ //# sourceMappingURL=render-concurrent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-concurrent.js","sourceRoot":"","sources":["../../../src/testing/fixtures/render-concurrent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAA;AAEhD,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;AAC7C,IAAI,qBAAiC,CAAA;AAErC,MAAM,cAAc,GAAG,IAAI,OAAO,CAAO,UAAU,OAAO,EAAE,OAAO;IACjE,qBAAqB,GAAG,OAAO,CAAA;AACjC,CAAC,CAAC,CAAA;AAEF,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,KAAK,EAAE,MAAgB,EAAE,OAAiB,EAAE,OAAe,EAAE,EAAE;QACrE,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;QACrC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;QACtC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAErC,qBAAqB,EAAE,CAAA;IACzB,CAAC;CACF,CAAA;AAED,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,KAAK,EAAE,MAAgB,EAAE,OAAiB,EAAE,OAAe,EAAE,EAAE;QACrE,MAAM,cAAc,CAAA;QAEpB,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;QACtC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAA;QACvC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;IACxC,CAAC;CACF,CAAA;AAED,mEAAmE;AACnE,gBAAgB,CAAC,EAAC,SAAS,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC,EAAE,eAAe,EAAC,CAAC,CAAA","sourcesContent":["import {Signal} from '../../abort.js'\nimport {Writable} from 'form-data'\nimport {renderConcurrent} from '@shopify/cli-kit/node/ui'\nimport {AbortController} from 'abort-controller'\n\nconst abortController = new AbortController()\nlet backendPromiseResolve: () => void\n\nconst backendPromise = new Promise<void>(function (resolve, _reject) {\n backendPromiseResolve = resolve\n})\n\nconst backendProcess = {\n prefix: 'backend',\n action: async (stdout: Writable, _stderr: Writable, _signal: Signal) => {\n stdout.write('first backend message')\n stdout.write('second backend message')\n stdout.write('third backend message')\n\n backendPromiseResolve()\n },\n}\n\nconst frontendProcess = {\n prefix: 'frontend',\n action: async (stdout: Writable, _stderr: Writable, _signal: Signal) => {\n await backendPromise\n\n stdout.write('first frontend message')\n stdout.write('second frontend message')\n stdout.write('third frontend message')\n },\n}\n\n// eslint-disable-next-line @typescript-eslint/no-floating-promises\nrenderConcurrent({processes: [backendProcess, frontendProcess], abortController})\n"]}
@@ -5,5 +5,6 @@ export declare function mockAndCaptureOutput(): {
5
5
  success: () => string;
6
6
  completed: () => string;
7
7
  warn: () => string;
8
+ error: () => string;
8
9
  clear: () => void;
9
10
  };
@@ -7,6 +7,7 @@ export function mockAndCaptureOutput() {
7
7
  success: () => (output.collectedLogs.success ?? []).join('\n'),
8
8
  completed: () => (output.collectedLogs.completed ?? []).join('\n'),
9
9
  warn: () => (output.collectedLogs.warn ?? []).join('\n'),
10
+ error: () => (output.collectedLogs.error ?? []).join('\n'),
10
11
  clear: () => {
11
12
  output.clearCollectedLogs();
12
13
  },
@@ -1 +1 @@
1
- {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/testing/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5D,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACxD,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1D,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9D,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAClE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACxD,KAAK,EAAE,GAAG,EAAE;YACV,MAAM,CAAC,kBAAkB,EAAE,CAAA;QAC7B,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import * as output from '../output.js'\n\nexport function mockAndCaptureOutput() {\n return {\n output: () => (output.collectedLogs.output ?? []).join('\\n'),\n info: () => (output.collectedLogs.info ?? []).join('\\n'),\n debug: () => (output.collectedLogs.debug ?? []).join('\\n'),\n success: () => (output.collectedLogs.success ?? []).join('\\n'),\n completed: () => (output.collectedLogs.completed ?? []).join('\\n'),\n warn: () => (output.collectedLogs.warn ?? []).join('\\n'),\n clear: () => {\n output.clearCollectedLogs()\n },\n }\n}\n"]}
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/testing/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5D,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACxD,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1D,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9D,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAClE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACxD,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1D,KAAK,EAAE,GAAG,EAAE;YACV,MAAM,CAAC,kBAAkB,EAAE,CAAA;QAC7B,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import * as output from '../output.js'\n\nexport function mockAndCaptureOutput() {\n return {\n output: () => (output.collectedLogs.output ?? []).join('\\n'),\n info: () => (output.collectedLogs.info ?? []).join('\\n'),\n debug: () => (output.collectedLogs.debug ?? []).join('\\n'),\n success: () => (output.collectedLogs.success ?? []).join('\\n'),\n completed: () => (output.collectedLogs.completed ?? []).join('\\n'),\n warn: () => (output.collectedLogs.warn ?? []).join('\\n'),\n error: () => (output.collectedLogs.error ?? []).join('\\n'),\n clear: () => {\n output.clearCollectedLogs()\n },\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { ExecaChildProcess } from 'execa';
2
+ declare type Run = (fixture: string, props?: {
3
+ env?: {
4
+ [key: string]: unknown;
5
+ };
6
+ }) => ExecaChildProcess<string>;
7
+ export declare const run: Run;
8
+ export {};
@@ -0,0 +1,17 @@
1
+ import * as path from '../path';
2
+ import { execa } from 'execa';
3
+ export const run = (fixture, props) => {
4
+ const env = {
5
+ ...process.env,
6
+ ...props?.env,
7
+ // we need this because ink treats the CI environment differently
8
+ // by only writing the last frame to stdout on unmount
9
+ // See more here https://github.com/vadimdemedes/ink/pull/266
10
+ CI: 'false',
11
+ };
12
+ return execa('ts-node-esm', [path.resolve(__dirname, `fixtures/${fixture}.ts`)], {
13
+ cwd: __dirname,
14
+ env,
15
+ });
16
+ };
17
+ //# sourceMappingURL=ui.js.map