@shopify/cli-kit 3.84.1 → 3.85.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.
- package/README.md +1 -1
- package/dist/private/node/analytics/bounded-collections.js.map +1 -0
- package/dist/{public/node/themes → private/node}/analytics/error-categorizer.d.ts +7 -1
- package/dist/private/node/analytics/error-categorizer.js +106 -0
- package/dist/private/node/analytics/error-categorizer.js.map +1 -0
- package/dist/{public/node/themes → private/node}/analytics/storage.js +8 -3
- package/dist/private/node/analytics/storage.js.map +1 -0
- package/dist/private/node/api/graphql/business-platform-destinations/user-email.d.ts +6 -0
- package/dist/private/node/api/graphql/business-platform-destinations/user-email.js +8 -0
- package/dist/private/node/api/graphql/business-platform-destinations/user-email.js.map +1 -0
- package/dist/private/node/api/headers.d.ts +3 -6
- package/dist/private/node/api/headers.js +8 -24
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/conf-store.d.ts +20 -3
- package/dist/private/node/conf-store.js +32 -7
- package/dist/private/node/conf-store.js.map +1 -1
- package/dist/private/node/constants.d.ts +0 -1
- package/dist/private/node/constants.js +0 -1
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/context/service.d.ts +8 -2
- package/dist/private/node/context/service.js +9 -5
- package/dist/private/node/context/service.js.map +1 -1
- package/dist/private/node/otel-metrics.js +2 -3
- package/dist/private/node/otel-metrics.js.map +1 -1
- package/dist/private/node/session/schema.d.ts +796 -41
- package/dist/private/node/session/schema.js +24 -25
- package/dist/private/node/session/schema.js.map +1 -1
- package/dist/private/node/session/store.d.ts +21 -11
- package/dist/private/node/session/store.js +52 -18
- package/dist/private/node/session/store.js.map +1 -1
- package/dist/private/node/session/validate.d.ts +2 -7
- package/dist/private/node/session/validate.js.map +1 -1
- package/dist/private/node/session.d.ts +8 -6
- package/dist/private/node/session.js +99 -71
- package/dist/private/node/session.js.map +1 -1
- package/dist/private/node/ui/components/LoadingBar.d.ts +8 -0
- package/dist/private/node/ui/components/LoadingBar.js +21 -0
- package/dist/private/node/ui/components/LoadingBar.js.map +1 -0
- package/dist/private/node/ui/components/LoadingBar.test.d.ts +1 -0
- package/dist/private/node/ui/components/LoadingBar.test.js +182 -0
- package/dist/private/node/ui/components/LoadingBar.test.js.map +1 -0
- package/dist/private/node/ui/components/SingleTask.d.ts +8 -0
- package/dist/private/node/ui/components/SingleTask.js +27 -0
- package/dist/private/node/ui/components/SingleTask.js.map +1 -0
- package/dist/private/node/ui/components/SingleTask.test.d.ts +1 -0
- package/dist/private/node/ui/components/SingleTask.test.js +145 -0
- package/dist/private/node/ui/components/SingleTask.test.js.map +1 -0
- package/dist/private/node/ui/components/Tasks.d.ts +2 -1
- package/dist/private/node/ui/components/Tasks.js +5 -25
- package/dist/private/node/ui/components/Tasks.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.test.js +19 -103
- package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
- package/dist/private/node/ui/hooks/use-exit-on-ctrl-c.d.ts +4 -0
- package/dist/private/node/ui/hooks/use-exit-on-ctrl-c.js +15 -0
- package/dist/private/node/ui/hooks/use-exit-on-ctrl-c.js.map +1 -0
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/analytics.d.ts +77 -0
- package/dist/public/node/analytics.js +88 -0
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/admin.js +2 -3
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/app-dev.d.ts +2 -0
- package/dist/public/node/api/app-dev.js +1 -0
- package/dist/public/node/api/app-dev.js.map +1 -1
- package/dist/public/node/base-command.d.ts +22 -0
- package/dist/public/node/base-command.js +1 -1
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/context/fqdn.d.ts +0 -4
- package/dist/public/node/context/fqdn.js +1 -23
- package/dist/public/node/context/fqdn.js.map +1 -1
- package/dist/public/node/context/local.d.ts +2 -2
- package/dist/public/node/context/local.js +2 -6
- package/dist/public/node/context/local.js.map +1 -1
- package/dist/public/node/error-handler.js +2 -1
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/http.d.ts +1 -1
- package/dist/public/node/http.js +1 -1
- package/dist/public/node/http.js.map +1 -1
- package/dist/public/node/metadata.d.ts +31 -4
- package/dist/public/node/metadata.js.map +1 -1
- package/dist/public/node/session-prompt.d.ts +10 -0
- package/dist/public/node/session-prompt.js +86 -0
- package/dist/public/node/session-prompt.js.map +1 -0
- package/dist/public/node/session.d.ts +11 -6
- package/dist/public/node/session.js +15 -4
- package/dist/public/node/session.js.map +1 -1
- package/dist/public/node/themes/api.js +28 -8
- package/dist/public/node/themes/api.js.map +1 -1
- package/dist/public/node/ui.d.ts +17 -1
- package/dist/public/node/ui.js +26 -2
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/vendor/dev_server/dev-server.js +1 -5
- package/dist/public/node/vendor/dev_server/dev-server.js.map +1 -1
- package/dist/public/node/vendor/dev_server/env.js +2 -2
- package/dist/public/node/vendor/dev_server/env.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/private/node/context/spin-cache.d.ts +0 -2
- package/dist/private/node/context/spin-cache.js +0 -8
- package/dist/private/node/context/spin-cache.js.map +0 -1
- package/dist/public/node/context/spin.d.ts +0 -69
- package/dist/public/node/context/spin.js +0 -152
- package/dist/public/node/context/spin.js.map +0 -1
- package/dist/public/node/themes/analytics/bounded-collections.js.map +0 -1
- package/dist/public/node/themes/analytics/error-categorizer.js +0 -49
- package/dist/public/node/themes/analytics/error-categorizer.js.map +0 -1
- package/dist/public/node/themes/analytics/storage.js.map +0 -1
- package/dist/public/node/themes/analytics.d.ts +0 -60
- package/dist/public/node/themes/analytics.js +0 -71
- package/dist/public/node/themes/analytics.js.map +0 -1
- package/dist/public/node/vendor/dev_server/dev-server-spin.d.ts +0 -5
- package/dist/public/node/vendor/dev_server/dev-server-spin.js +0 -28
- package/dist/public/node/vendor/dev_server/dev-server-spin.js.map +0 -1
- /package/dist/{public/node/themes → private/node}/analytics/bounded-collections.d.ts +0 -0
- /package/dist/{public/node/themes → private/node}/analytics/bounded-collections.js +0 -0
- /package/dist/{public/node/themes → private/node}/analytics/storage.d.ts +0 -0
|
@@ -2,16 +2,38 @@ import { applicationId } from './session/identity.js';
|
|
|
2
2
|
import { validateSession } from './session/validate.js';
|
|
3
3
|
import { allDefaultScopes, apiScopes } from './session/scopes.js';
|
|
4
4
|
import { exchangeAccessForApplicationTokens, exchangeCustomPartnerToken, refreshAccessToken, InvalidGrantError, InvalidRequestError, } from './session/exchange.js';
|
|
5
|
-
import * as
|
|
5
|
+
import * as sessionStore from './session/store.js';
|
|
6
6
|
import { pollForDeviceAuthorization, requestDeviceAuthorization } from './session/device-authorization.js';
|
|
7
7
|
import { isThemeAccessSession } from './api/rest.js';
|
|
8
|
+
import { getCurrentSessionId, setCurrentSessionId } from './conf-store.js';
|
|
9
|
+
import { UserEmailQueryString } from './api/graphql/business-platform-destinations/user-email.js';
|
|
8
10
|
import { outputContent, outputToken, outputDebug, outputCompleted } from '../../public/node/output.js';
|
|
9
11
|
import { firstPartyDev, themeToken } from '../../public/node/context/local.js';
|
|
10
|
-
import { AbortError
|
|
12
|
+
import { AbortError } from '../../public/node/error.js';
|
|
11
13
|
import { normalizeStoreFqdn, identityFqdn } from '../../public/node/context/fqdn.js';
|
|
12
14
|
import { getIdentityTokenInformation, getPartnersToken } from '../../public/node/environment.js';
|
|
13
|
-
import {
|
|
15
|
+
import { logout } from '../../public/node/session.js';
|
|
14
16
|
import { nonRandomUUID } from '../../public/node/crypto.js';
|
|
17
|
+
import { isEmpty } from '../../public/common/object.js';
|
|
18
|
+
import { businessPlatformRequest } from '../../public/node/api/business-platform.js';
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the user's email from the Business Platform API
|
|
21
|
+
* @param businessPlatformToken - The business platform token
|
|
22
|
+
* @returns The user's email address or undefined if not found
|
|
23
|
+
*/
|
|
24
|
+
async function fetchEmail(businessPlatformToken) {
|
|
25
|
+
if (!businessPlatformToken)
|
|
26
|
+
return undefined;
|
|
27
|
+
try {
|
|
28
|
+
const userEmailResult = await businessPlatformRequest(UserEmailQueryString, businessPlatformToken);
|
|
29
|
+
return userEmailResult.currentUserAccount?.email;
|
|
30
|
+
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
outputDebug(outputContent `Failed to fetch user email: ${error.message ?? String(error)}`);
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
15
37
|
let userId;
|
|
16
38
|
let authMethod = 'none';
|
|
17
39
|
/**
|
|
@@ -19,7 +41,7 @@ let authMethod = 'none';
|
|
|
19
41
|
*
|
|
20
42
|
* This function performs the following steps:
|
|
21
43
|
* 1. Checks for a cached user ID in memory (obtained in the current run).
|
|
22
|
-
* 2. Attempts to fetch it from the
|
|
44
|
+
* 2. Attempts to fetch it from the local storage (from a previous auth session).
|
|
23
45
|
* 3. Checks if a custom token was used (either as a theme password or partners token).
|
|
24
46
|
* 4. If a custom token is present in the environment, generates a UUID and uses it as userId.
|
|
25
47
|
* 5. If after all this we don't have a userId, then reports as 'unknown'.
|
|
@@ -29,11 +51,9 @@ let authMethod = 'none';
|
|
|
29
51
|
export async function getLastSeenUserIdAfterAuth() {
|
|
30
52
|
if (userId)
|
|
31
53
|
return userId;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (cachedUserId)
|
|
36
|
-
return cachedUserId;
|
|
54
|
+
const currentSessionId = getCurrentSessionId();
|
|
55
|
+
if (currentSessionId)
|
|
56
|
+
return currentSessionId;
|
|
37
57
|
const customToken = getPartnersToken() ?? themeToken();
|
|
38
58
|
return customToken ? nonRandomUUID(customToken) : 'unknown';
|
|
39
59
|
}
|
|
@@ -55,10 +75,7 @@ export function setLastSeenUserIdAfterAuth(id) {
|
|
|
55
75
|
export async function getLastSeenAuthMethod() {
|
|
56
76
|
if (authMethod !== 'none')
|
|
57
77
|
return authMethod;
|
|
58
|
-
|
|
59
|
-
const fqdn = await identityFqdn();
|
|
60
|
-
const cachedUserId = currentSession[fqdn]?.identity.userId;
|
|
61
|
-
if (cachedUserId)
|
|
78
|
+
if (getCurrentSessionId())
|
|
62
79
|
return 'device_auth';
|
|
63
80
|
const partnersToken = getPartnersToken();
|
|
64
81
|
if (partnersToken)
|
|
@@ -77,10 +94,10 @@ export function setLastSeenAuthMethod(method) {
|
|
|
77
94
|
*
|
|
78
95
|
* @param applications - An object containing the applications we need to be authenticated with.
|
|
79
96
|
* @param _env - Optional environment variables to use.
|
|
80
|
-
* @param
|
|
97
|
+
* @param options - Optional extra options to use.
|
|
81
98
|
* @returns An instance with the access tokens organized by application.
|
|
82
99
|
*/
|
|
83
|
-
export async function ensureAuthenticated(applications, _env, { forceRefresh = false, noPrompt = false } = {}) {
|
|
100
|
+
export async function ensureAuthenticated(applications, _env, { forceRefresh = false, noPrompt = false, forceNewSession = false } = {}) {
|
|
84
101
|
const fqdn = await identityFqdn();
|
|
85
102
|
const previousStoreFqdn = applications.adminApi?.storeFqdn;
|
|
86
103
|
if (previousStoreFqdn) {
|
|
@@ -89,41 +106,40 @@ export async function ensureAuthenticated(applications, _env, { forceRefresh = f
|
|
|
89
106
|
applications.adminApi.storeFqdn = normalizedStoreName;
|
|
90
107
|
}
|
|
91
108
|
}
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
109
|
+
const sessions = (await sessionStore.fetch()) ?? {};
|
|
110
|
+
let currentSessionId = getCurrentSessionId();
|
|
111
|
+
if (!currentSessionId) {
|
|
112
|
+
const userIds = Object.keys(sessions[fqdn] ?? {});
|
|
113
|
+
if (userIds.length > 0)
|
|
114
|
+
currentSessionId = userIds[0];
|
|
115
|
+
}
|
|
116
|
+
const currentSession = currentSessionId && !forceNewSession ? sessions[fqdn]?.[currentSessionId] : undefined;
|
|
95
117
|
const scopes = getFlattenScopes(applications);
|
|
96
118
|
outputDebug(outputContent `Validating existing session against the scopes:
|
|
97
119
|
${outputToken.json(scopes)}
|
|
98
120
|
For applications:
|
|
99
121
|
${outputToken.json(applications)}
|
|
100
122
|
`);
|
|
101
|
-
const validationResult = await validateSession(scopes, applications,
|
|
123
|
+
const validationResult = await validateSession(scopes, applications, currentSession);
|
|
102
124
|
let newSession = {};
|
|
103
|
-
function throwOnNoPrompt() {
|
|
104
|
-
if (!noPrompt || (isSpin() && firstPartyDev()))
|
|
105
|
-
return;
|
|
106
|
-
throw new AbortError(`The currently available CLI credentials are invalid.
|
|
107
|
-
|
|
108
|
-
The CLI is currently unable to prompt for reauthentication.`, 'Restart the CLI process you were running. If in an interactive terminal, you will be prompted to reauthenticate. If in a non-interactive terminal, ensure the correct credentials are available in the program environment.');
|
|
109
|
-
}
|
|
110
125
|
if (validationResult === 'needs_full_auth') {
|
|
111
|
-
throwOnNoPrompt();
|
|
126
|
+
await throwOnNoPrompt(noPrompt);
|
|
112
127
|
outputDebug(outputContent `Initiating the full authentication flow...`);
|
|
113
|
-
newSession = await executeCompleteFlow(applications
|
|
128
|
+
newSession = await executeCompleteFlow(applications);
|
|
114
129
|
}
|
|
115
130
|
else if (validationResult === 'needs_refresh' || forceRefresh) {
|
|
116
131
|
outputDebug(outputContent `The current session is valid but needs refresh. Refreshing...`);
|
|
117
132
|
try {
|
|
118
|
-
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
134
|
+
newSession = await refreshTokens(currentSession, applications);
|
|
119
135
|
}
|
|
120
136
|
catch (error) {
|
|
121
137
|
if (error instanceof InvalidGrantError) {
|
|
122
|
-
throwOnNoPrompt();
|
|
123
|
-
newSession = await executeCompleteFlow(applications
|
|
138
|
+
await throwOnNoPrompt(noPrompt);
|
|
139
|
+
newSession = await executeCompleteFlow(applications);
|
|
124
140
|
}
|
|
125
141
|
else if (error instanceof InvalidRequestError) {
|
|
126
|
-
await
|
|
142
|
+
await sessionStore.remove();
|
|
127
143
|
throw new AbortError('\nError validating auth session', "We've cleared the current session, please try again");
|
|
128
144
|
}
|
|
129
145
|
else {
|
|
@@ -132,10 +148,17 @@ The CLI is currently unable to prompt for reauthentication.`, 'Restart the CLI p
|
|
|
132
148
|
}
|
|
133
149
|
}
|
|
134
150
|
const completeSession = { ...currentSession, ...newSession };
|
|
151
|
+
const newSessionId = completeSession.identity.userId;
|
|
152
|
+
const updatedSessions = {
|
|
153
|
+
...sessions,
|
|
154
|
+
[fqdn]: { ...sessions[fqdn], [newSessionId]: completeSession },
|
|
155
|
+
};
|
|
135
156
|
// Save the new session info if it has changed
|
|
136
|
-
if (
|
|
137
|
-
await
|
|
138
|
-
|
|
157
|
+
if (!isEmpty(newSession)) {
|
|
158
|
+
await sessionStore.store(updatedSessions);
|
|
159
|
+
setCurrentSessionId(newSessionId);
|
|
160
|
+
}
|
|
161
|
+
const tokens = await tokensFor(applications, completeSession);
|
|
139
162
|
// Overwrite partners token if using a custom CLI Token
|
|
140
163
|
const envToken = getPartnersToken();
|
|
141
164
|
if (envToken && applications.partnersApi) {
|
|
@@ -145,13 +168,21 @@ The CLI is currently unable to prompt for reauthentication.`, 'Restart the CLI p
|
|
|
145
168
|
setLastSeenUserIdAfterAuth(tokens.userId);
|
|
146
169
|
return tokens;
|
|
147
170
|
}
|
|
171
|
+
async function throwOnNoPrompt(noPrompt) {
|
|
172
|
+
if (!noPrompt)
|
|
173
|
+
return;
|
|
174
|
+
await logout();
|
|
175
|
+
throw new AbortError(`The currently available CLI credentials are invalid.
|
|
176
|
+
|
|
177
|
+
The CLI is currently unable to prompt for reauthentication.`, 'Restart the CLI process you were running. If in an interactive terminal, you will be prompted to reauthenticate. If in a non-interactive terminal, ensure the correct credentials are available in the program environment.');
|
|
178
|
+
}
|
|
148
179
|
/**
|
|
149
180
|
* Execute the full authentication flow.
|
|
150
181
|
*
|
|
151
182
|
* @param applications - An object containing the applications we need to be authenticated with.
|
|
152
|
-
* @param
|
|
183
|
+
* @param alias - Optional alias to use for the session.
|
|
153
184
|
*/
|
|
154
|
-
async function executeCompleteFlow(applications
|
|
185
|
+
async function executeCompleteFlow(applications) {
|
|
155
186
|
const scopes = getFlattenScopes(applications);
|
|
156
187
|
const exchangeScopes = getExchangeScopes(applications);
|
|
157
188
|
const store = applications.adminApi?.storeFqdn;
|
|
@@ -175,33 +206,33 @@ async function executeCompleteFlow(applications, identityFqdn) {
|
|
|
175
206
|
// Exchange identity token for application tokens
|
|
176
207
|
outputDebug(outputContent `CLI token received. Exchanging it for application tokens...`);
|
|
177
208
|
const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store);
|
|
209
|
+
// Get the alias for the session (email or userId)
|
|
210
|
+
const businessPlatformToken = result[applicationId('business-platform')]?.accessToken;
|
|
211
|
+
const alias = (await fetchEmail(businessPlatformToken)) ?? identityToken.userId;
|
|
178
212
|
const session = {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
213
|
+
identity: {
|
|
214
|
+
...identityToken,
|
|
215
|
+
alias,
|
|
182
216
|
},
|
|
217
|
+
applications: result,
|
|
183
218
|
};
|
|
184
|
-
outputCompleted(
|
|
219
|
+
outputCompleted(`Logged in.`);
|
|
185
220
|
return session;
|
|
186
221
|
}
|
|
187
222
|
/**
|
|
188
223
|
* Refresh the tokens for a given session.
|
|
189
224
|
*
|
|
190
|
-
* @param
|
|
191
|
-
* @param applications - An object containing the applications we need to be authenticated with.
|
|
192
|
-
* @param fqdn - The identity FQDN.
|
|
225
|
+
* @param session - The session to refresh.
|
|
193
226
|
*/
|
|
194
|
-
async function refreshTokens(
|
|
227
|
+
async function refreshTokens(session, applications) {
|
|
195
228
|
// Refresh Identity Token
|
|
196
|
-
const identityToken = await refreshAccessToken(
|
|
229
|
+
const identityToken = await refreshAccessToken(session.identity);
|
|
197
230
|
// Exchange new identity token for application tokens
|
|
198
231
|
const exchangeScopes = getExchangeScopes(applications);
|
|
199
232
|
const applicationTokens = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, applications.adminApi?.storeFqdn);
|
|
200
233
|
return {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
applications: applicationTokens,
|
|
204
|
-
},
|
|
234
|
+
identity: identityToken,
|
|
235
|
+
applications: applicationTokens,
|
|
205
236
|
};
|
|
206
237
|
}
|
|
207
238
|
/**
|
|
@@ -211,37 +242,33 @@ async function refreshTokens(token, applications, fqdn) {
|
|
|
211
242
|
* @param session - The current session.
|
|
212
243
|
* @param fqdn - The identity FQDN.
|
|
213
244
|
*/
|
|
214
|
-
async function tokensFor(applications, session
|
|
215
|
-
const fqdnSession = session[fqdn];
|
|
216
|
-
if (!fqdnSession) {
|
|
217
|
-
throw new BugError('No session found after ensuring authenticated');
|
|
218
|
-
}
|
|
245
|
+
async function tokensFor(applications, session) {
|
|
219
246
|
const tokens = {
|
|
220
|
-
userId:
|
|
247
|
+
userId: session.identity.userId,
|
|
221
248
|
};
|
|
222
249
|
if (applications.adminApi) {
|
|
223
250
|
const appId = applicationId('admin');
|
|
224
251
|
const realAppId = `${applications.adminApi.storeFqdn}-${appId}`;
|
|
225
|
-
const token =
|
|
252
|
+
const token = session.applications[realAppId]?.accessToken;
|
|
226
253
|
if (token) {
|
|
227
254
|
tokens.admin = { token, storeFqdn: applications.adminApi.storeFqdn };
|
|
228
255
|
}
|
|
229
256
|
}
|
|
230
257
|
if (applications.partnersApi) {
|
|
231
258
|
const appId = applicationId('partners');
|
|
232
|
-
tokens.partners =
|
|
259
|
+
tokens.partners = session.applications[appId]?.accessToken;
|
|
233
260
|
}
|
|
234
261
|
if (applications.storefrontRendererApi) {
|
|
235
262
|
const appId = applicationId('storefront-renderer');
|
|
236
|
-
tokens.storefront =
|
|
263
|
+
tokens.storefront = session.applications[appId]?.accessToken;
|
|
237
264
|
}
|
|
238
265
|
if (applications.businessPlatformApi) {
|
|
239
266
|
const appId = applicationId('business-platform');
|
|
240
|
-
tokens.businessPlatform =
|
|
267
|
+
tokens.businessPlatform = session.applications[appId]?.accessToken;
|
|
241
268
|
}
|
|
242
269
|
if (applications.appManagementApi) {
|
|
243
270
|
const appId = applicationId('app-management');
|
|
244
|
-
tokens.appManagement =
|
|
271
|
+
tokens.appManagement = session.applications[appId]?.accessToken;
|
|
245
272
|
}
|
|
246
273
|
return tokens;
|
|
247
274
|
}
|
|
@@ -253,11 +280,11 @@ async function tokensFor(applications, session, fqdn) {
|
|
|
253
280
|
* @returns A flattened array of scopes.
|
|
254
281
|
*/
|
|
255
282
|
function getFlattenScopes(apps) {
|
|
256
|
-
const admin = apps.adminApi?.scopes
|
|
257
|
-
const partner = apps.partnersApi?.scopes
|
|
258
|
-
const storefront = apps.storefrontRendererApi?.scopes
|
|
259
|
-
const businessPlatform = apps.businessPlatformApi?.scopes
|
|
260
|
-
const appManagement = apps.appManagementApi?.scopes
|
|
283
|
+
const admin = apps.adminApi?.scopes ?? [];
|
|
284
|
+
const partner = apps.partnersApi?.scopes ?? [];
|
|
285
|
+
const storefront = apps.storefrontRendererApi?.scopes ?? [];
|
|
286
|
+
const businessPlatform = apps.businessPlatformApi?.scopes ?? [];
|
|
287
|
+
const appManagement = apps.appManagementApi?.scopes ?? [];
|
|
261
288
|
const requestedScopes = [...admin, ...partner, ...storefront, ...businessPlatform, ...appManagement];
|
|
262
289
|
return allDefaultScopes(requestedScopes);
|
|
263
290
|
}
|
|
@@ -268,11 +295,11 @@ function getFlattenScopes(apps) {
|
|
|
268
295
|
* @returns An object containing the scopes for each application.
|
|
269
296
|
*/
|
|
270
297
|
function getExchangeScopes(apps) {
|
|
271
|
-
const adminScope = apps.adminApi?.scopes
|
|
272
|
-
const partnerScope = apps.partnersApi?.scopes
|
|
273
|
-
const storefrontScopes = apps.storefrontRendererApi?.scopes
|
|
274
|
-
const businessPlatformScopes = apps.businessPlatformApi?.scopes
|
|
275
|
-
const appManagementScopes = apps.appManagementApi?.scopes
|
|
298
|
+
const adminScope = apps.adminApi?.scopes ?? [];
|
|
299
|
+
const partnerScope = apps.partnersApi?.scopes ?? [];
|
|
300
|
+
const storefrontScopes = apps.storefrontRendererApi?.scopes ?? [];
|
|
301
|
+
const businessPlatformScopes = apps.businessPlatformApi?.scopes ?? [];
|
|
302
|
+
const appManagementScopes = apps.appManagementApi?.scopes ?? [];
|
|
276
303
|
return {
|
|
277
304
|
admin: apiScopes('admin', adminScope),
|
|
278
305
|
partners: apiScopes('partners', partnerScope),
|
|
@@ -286,6 +313,7 @@ function buildIdentityTokenFromEnv(scopes, identityTokenInformation) {
|
|
|
286
313
|
...identityTokenInformation,
|
|
287
314
|
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
|
|
288
315
|
scopes,
|
|
316
|
+
alias: identityTokenInformation.userId,
|
|
289
317
|
};
|
|
290
318
|
}
|
|
291
319
|
//# sourceMappingURL=session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/private/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAE1B,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAC,0BAA0B,EAAE,0BAA0B,EAAC,MAAM,mCAAmC,CAAA;AACxG,OAAO,EAAC,oBAAoB,EAAC,MAAM,eAAe,CAAA;AAClD,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAC,MAAM,6BAA6B,CAAA;AACpG,OAAO,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,oCAAoC,CAAA;AAC5E,OAAO,EAAC,UAAU,EAAE,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sB,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,IAAI,EAAE,CAAA;IACrE,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,IAAI,EAAE,CAAA;IAC/D,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;QAC9D,gBAAgB,EAAE,SAAS,CAAC,mBAAmB,EAAE,sBAAsB,CAAC;QACxE,aAAa,EAAE,SAAS,CAAC,gBAAgB,EAAE,mBAAmB,CAAC;KAChE,CAAA;AACH,CAAC;AAED,SAAS,yBAAyB,CAChC,MAAgB,EAChB,wBAAqF;IAErF,OAAO;QACL,GAAG,wBAAwB;QAC3B,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAC1D,MAAM;KACP,CAAA;AACH,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n InvalidRequestError,\n} from './session/exchange.js'\nimport {IdentityToken, Session} from './session/schema.js'\nimport * as secureStore from './session/store.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {isThemeAccessSession} from './api/rest.js'\nimport {outputContent, outputToken, outputDebug, outputCompleted} from '../../public/node/output.js'\nimport {firstPartyDev, themeToken} from '../../public/node/context/local.js'\nimport {AbortError, BugError} from '../../public/node/error.js'\nimport {normalizeStoreFqdn, identityFqdn} from '../../public/node/context/fqdn.js'\nimport {getIdentityTokenInformation, getPartnersToken} from '../../public/node/environment.js'\nimport {AdminSession} from '../../public/node/session.js'\nimport {isSpin} from '../../public/node/context/spin.js'\nimport {nonRandomUUID} from '../../public/node/crypto.js'\n\n/**\n * A scope supported by the Shopify Admin API.\n */\nexport type AdminAPIScope = 'graphql' | 'themes' | 'collaborator'\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\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 */\nexport type PartnersAPIScope = 'cli'\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Developer Platform API.\n */\nexport type AppManagementAPIScope = 'https://api.shopify.com/auth/organization.apps.manage'\ninterface AppManagementAPIOauthOptions {\n /** List of scopes to request permissions for. */\n scopes: AppManagementAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\nexport type StorefrontRendererScope = 'devtools'\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: StorefrontRendererScope[]\n}\n\nexport type BusinessPlatformScope = 'destinations'\ninterface BusinessPlatformAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: BusinessPlatformScope[]\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 businessPlatformApi?: BusinessPlatformAPIOAuthOptions\n appManagementApi?: AppManagementAPIOauthOptions\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n businessPlatform?: string\n appManagement?: string\n userId: string\n}\n\ntype AuthMethod = 'partners_token' | 'device_auth' | 'theme_access_token' | 'custom_app_token' | 'none'\n\nlet userId: undefined | string\nlet authMethod: AuthMethod = 'none'\n\n/**\n * Retrieves the user ID from the current session or returns 'unknown' if not found.\n *\n * This function performs the following steps:\n * 1. Checks for a cached user ID in memory (obtained in the current run).\n * 2. Attempts to fetch it from the secure store (from a previous auth session).\n * 3. Checks if a custom token was used (either as a theme password or partners token).\n * 4. If a custom token is present in the environment, generates a UUID and uses it as userId.\n * 5. If after all this we don't have a userId, then reports as 'unknown'.\n *\n * @returns A Promise that resolves to the user ID as a string.\n */\nexport async function getLastSeenUserIdAfterAuth(): Promise<string> {\n if (userId) return userId\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdn = await identityFqdn()\n const cachedUserId = currentSession[fqdn]?.identity.userId\n if (cachedUserId) return cachedUserId\n\n const customToken = getPartnersToken() ?? themeToken()\n return customToken ? nonRandomUUID(customToken) : 'unknown'\n}\n\nexport function setLastSeenUserIdAfterAuth(id: string) {\n userId = id\n}\n\n/**\n * Retrieves the last seen authentication method used in the current session.\n *\n * This function checks for the authentication method in the following order:\n * 1. Returns the cached auth method if it's not 'none'.\n * 2. Checks for a cached session, which implies 'device_auth' was used.\n * 3. Checks for a partners token in the environment.\n * 4. Checks for a theme password in the environment.\n * 5. If none of the above are true, returns 'none'.\n *\n * @returns A Promise that resolves to the last seen authentication method as an AuthMethod type.\n */\nexport async function getLastSeenAuthMethod(): Promise<AuthMethod> {\n if (authMethod !== 'none') return authMethod\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdn = await identityFqdn()\n const cachedUserId = currentSession[fqdn]?.identity.userId\n if (cachedUserId) return 'device_auth'\n\n const partnersToken = getPartnersToken()\n if (partnersToken) return 'partners_token'\n\n const themePassword = themeToken()\n if (themePassword) {\n return isThemeAccessSession({token: themePassword, storeFqdn: ''}) ? 'theme_access_token' : 'custom_app_token'\n }\n\n return 'none'\n}\n\nexport function setLastSeenAuthMethod(method: AuthMethod) {\n authMethod = method\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param _env - Optional environment variables to use.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(\n applications: OAuthApplications,\n _env?: NodeJS.ProcessEnv,\n {forceRefresh = false, noPrompt = false}: {forceRefresh?: boolean; noPrompt?: boolean} = {},\n): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n const previousStoreFqdn = applications.adminApi?.storeFqdn\n if (previousStoreFqdn) {\n const normalizedStoreName = await normalizeStoreFqdn(previousStoreFqdn)\n if (previousStoreFqdn === applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizedStoreName\n }\n }\n\n const currentSession = (await secureStore.fetch()) || {}\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const fqdnSession = currentSession[fqdn]!\n const scopes = getFlattenScopes(applications)\n\n outputDebug(outputContent`Validating existing session against the scopes:\n${outputToken.json(scopes)}\nFor applications:\n${outputToken.json(applications)}\n`)\n const validationResult = await validateSession(scopes, applications, fqdnSession)\n\n let newSession = {}\n\n function throwOnNoPrompt() {\n if (!noPrompt || (isSpin() && firstPartyDev())) return\n throw new AbortError(\n `The currently available CLI credentials are invalid.\n\nThe CLI is currently unable to prompt for reauthentication.`,\n 'Restart the CLI process you were running. If in an interactive terminal, you will be prompted to reauthenticate. If in a non-interactive terminal, ensure the correct credentials are available in the program environment.',\n )\n }\n\n if (validationResult === 'needs_full_auth') {\n throwOnNoPrompt()\n outputDebug(outputContent`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (validationResult === 'needs_refresh' || forceRefresh) {\n outputDebug(outputContent`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 throwOnNoPrompt()\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (error instanceof InvalidRequestError) {\n await secureStore.remove()\n throw new AbortError('\\nError validating auth session', \"We've cleared the current session, please try again\")\n } else {\n throw error\n }\n }\n }\n\n const completeSession: Session = {...currentSession, ...newSession}\n\n // Save the new session info if it has changed\n if (Object.keys(newSession).length > 0) 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 = getPartnersToken()\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n\n setLastSeenAuthMethod(envToken ? 'partners_token' : 'device_auth')\n setLastSeenUserIdAfterAuth(tokens.userId)\n return tokens\n}\n\n/**\n * Execute the full authentication flow.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param identityFqdn - The identity FQDN.\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 outputDebug(outputContent`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n const identityTokenInformation = getIdentityTokenInformation()\n if (identityTokenInformation) {\n identityToken = buildIdentityTokenFromEnv(scopes, identityTokenInformation)\n } else {\n // Request a device code to authorize without a browser redirect.\n outputDebug(outputContent`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n outputDebug(outputContent`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n }\n\n // Exchange identity token for application tokens\n outputDebug(outputContent`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 outputCompleted('Logged in.')\n\n return session\n}\n\n/**\n * Refresh the tokens for a given session.\n *\n * @param token - Identity token.\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param fqdn - The identity FQDN.\n */\nasync function refreshTokens(token: IdentityToken, applications: OAuthApplications, fqdn: string): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(token)\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\n/**\n * Get the application tokens for a given session.\n *\n * @param applications - An object containing the applications we need the tokens for.\n * @param session - The current session.\n * @param fqdn - The identity FQDN.\n */\nasync function tokensFor(applications: OAuthApplications, session: Session, fqdn: string): Promise<OAuthSession> {\n const fqdnSession = session[fqdn]\n if (!fqdnSession) {\n throw new BugError('No session found after ensuring authenticated')\n }\n const tokens: OAuthSession = {\n userId: fqdnSession.identity.userId,\n }\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\n if (applications.businessPlatformApi) {\n const appId = applicationId('business-platform')\n tokens.businessPlatform = fqdnSession.applications[appId]?.accessToken\n }\n\n if (applications.appManagementApi) {\n const appId = applicationId('app-management')\n tokens.appManagement = fqdnSession.applications[appId]?.accessToken\n }\n\n return tokens\n}\n\n// Scope Helpers\n/**\n * Get a flattened array of scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns A flattened array of scopes.\n */\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 businessPlatform = apps.businessPlatformApi?.scopes || []\n const appManagement = apps.appManagementApi?.scopes || []\n const requestedScopes = [...admin, ...partner, ...storefront, ...businessPlatform, ...appManagement]\n return allDefaultScopes(requestedScopes)\n}\n\n/**\n * Get the scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns An object containing the scopes for each application.\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 const businessPlatformScopes = apps.businessPlatformApi?.scopes || []\n const appManagementScopes = apps.appManagementApi?.scopes || []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n businessPlatform: apiScopes('business-platform', businessPlatformScopes),\n appManagement: apiScopes('app-management', appManagementScopes),\n }\n}\n\nfunction buildIdentityTokenFromEnv(\n scopes: string[],\n identityTokenInformation: {accessToken: string; refreshToken: string; userId: string},\n) {\n return {\n ...identityTokenInformation,\n expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),\n scopes,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/private/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAE1B,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAC,0BAA0B,EAAE,0BAA0B,EAAC,MAAM,mCA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,CAAA;IACrE,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,IAAI,EAAE,CAAA;IAC/D,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;QAC9D,gBAAgB,EAAE,SAAS,CAAC,mBAAmB,EAAE,sBAAsB,CAAC;QACxE,aAAa,EAAE,SAAS,CAAC,gBAAgB,EAAE,mBAAmB,CAAC;KAChE,CAAA;AACH,CAAC;AAED,SAAS,yBAAyB,CAChC,MAAgB,EAChB,wBAAqF;IAErF,OAAO;QACL,GAAG,wBAAwB;QAC3B,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAC1D,MAAM;QACN,KAAK,EAAE,wBAAwB,CAAC,MAAM;KACvC,CAAA;AACH,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n InvalidRequestError,\n} from './session/exchange.js'\nimport {IdentityToken, Session, Sessions} from './session/schema.js'\nimport * as sessionStore from './session/store.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {isThemeAccessSession} from './api/rest.js'\nimport {getCurrentSessionId, setCurrentSessionId} from './conf-store.js'\nimport {UserEmailQueryString, UserEmailQuery} from './api/graphql/business-platform-destinations/user-email.js'\nimport {outputContent, outputToken, outputDebug, outputCompleted} from '../../public/node/output.js'\nimport {firstPartyDev, themeToken} from '../../public/node/context/local.js'\nimport {AbortError} from '../../public/node/error.js'\nimport {normalizeStoreFqdn, identityFqdn} from '../../public/node/context/fqdn.js'\nimport {getIdentityTokenInformation, getPartnersToken} from '../../public/node/environment.js'\nimport {AdminSession, logout} from '../../public/node/session.js'\nimport {nonRandomUUID} from '../../public/node/crypto.js'\nimport {isEmpty} from '../../public/common/object.js'\nimport {businessPlatformRequest} from '../../public/node/api/business-platform.js'\n\n/**\n * Fetches the user's email from the Business Platform API\n * @param businessPlatformToken - The business platform token\n * @returns The user's email address or undefined if not found\n */\nasync function fetchEmail(businessPlatformToken: string | undefined): Promise<string | undefined> {\n if (!businessPlatformToken) return undefined\n\n try {\n const userEmailResult = await businessPlatformRequest<UserEmailQuery>(UserEmailQueryString, businessPlatformToken)\n return userEmailResult.currentUserAccount?.email\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n outputDebug(outputContent`Failed to fetch user email: ${(error as Error).message ?? String(error)}`)\n return undefined\n }\n}\n\n/**\n * A scope supported by the Shopify Admin API.\n */\nexport type AdminAPIScope = 'graphql' | 'themes' | 'collaborator'\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\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 */\nexport type PartnersAPIScope = 'cli'\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Developer Platform API.\n */\nexport type AppManagementAPIScope = 'https://api.shopify.com/auth/organization.apps.manage'\ninterface AppManagementAPIOauthOptions {\n /** List of scopes to request permissions for. */\n scopes: AppManagementAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\nexport type StorefrontRendererScope = 'devtools'\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: StorefrontRendererScope[]\n}\n\nexport type BusinessPlatformScope = 'destinations'\ninterface BusinessPlatformAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: BusinessPlatformScope[]\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 businessPlatformApi?: BusinessPlatformAPIOAuthOptions\n appManagementApi?: AppManagementAPIOauthOptions\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n businessPlatform?: string\n appManagement?: string\n userId: string\n}\n\ntype AuthMethod = 'partners_token' | 'device_auth' | 'theme_access_token' | 'custom_app_token' | 'none'\n\nlet userId: undefined | string\nlet authMethod: AuthMethod = 'none'\n\n/**\n * Retrieves the user ID from the current session or returns 'unknown' if not found.\n *\n * This function performs the following steps:\n * 1. Checks for a cached user ID in memory (obtained in the current run).\n * 2. Attempts to fetch it from the local storage (from a previous auth session).\n * 3. Checks if a custom token was used (either as a theme password or partners token).\n * 4. If a custom token is present in the environment, generates a UUID and uses it as userId.\n * 5. If after all this we don't have a userId, then reports as 'unknown'.\n *\n * @returns A Promise that resolves to the user ID as a string.\n */\nexport async function getLastSeenUserIdAfterAuth(): Promise<string> {\n if (userId) return userId\n\n const currentSessionId = getCurrentSessionId()\n if (currentSessionId) return currentSessionId\n\n const customToken = getPartnersToken() ?? themeToken()\n return customToken ? nonRandomUUID(customToken) : 'unknown'\n}\n\nexport function setLastSeenUserIdAfterAuth(id: string) {\n userId = id\n}\n\n/**\n * Retrieves the last seen authentication method used in the current session.\n *\n * This function checks for the authentication method in the following order:\n * 1. Returns the cached auth method if it's not 'none'.\n * 2. Checks for a cached session, which implies 'device_auth' was used.\n * 3. Checks for a partners token in the environment.\n * 4. Checks for a theme password in the environment.\n * 5. If none of the above are true, returns 'none'.\n *\n * @returns A Promise that resolves to the last seen authentication method as an AuthMethod type.\n */\nexport async function getLastSeenAuthMethod(): Promise<AuthMethod> {\n if (authMethod !== 'none') return authMethod\n\n if (getCurrentSessionId()) return 'device_auth'\n\n const partnersToken = getPartnersToken()\n if (partnersToken) return 'partners_token'\n\n const themePassword = themeToken()\n if (themePassword) {\n return isThemeAccessSession({token: themePassword, storeFqdn: ''}) ? 'theme_access_token' : 'custom_app_token'\n }\n\n return 'none'\n}\n\nexport function setLastSeenAuthMethod(method: AuthMethod) {\n authMethod = method\n}\n\nexport interface EnsureAuthenticatedAdditionalOptions {\n noPrompt?: boolean\n forceRefresh?: boolean\n forceNewSession?: boolean\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param _env - Optional environment variables to use.\n * @param options - Optional extra options to use.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(\n applications: OAuthApplications,\n _env?: NodeJS.ProcessEnv,\n {forceRefresh = false, noPrompt = false, forceNewSession = false}: EnsureAuthenticatedAdditionalOptions = {},\n): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n const previousStoreFqdn = applications.adminApi?.storeFqdn\n if (previousStoreFqdn) {\n const normalizedStoreName = await normalizeStoreFqdn(previousStoreFqdn)\n if (previousStoreFqdn === applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizedStoreName\n }\n }\n\n const sessions = (await sessionStore.fetch()) ?? {}\n\n let currentSessionId = getCurrentSessionId()\n if (!currentSessionId) {\n const userIds = Object.keys(sessions[fqdn] ?? {})\n if (userIds.length > 0) currentSessionId = userIds[0]\n }\n const currentSession: Session | undefined =\n currentSessionId && !forceNewSession ? sessions[fqdn]?.[currentSessionId] : undefined\n const scopes = getFlattenScopes(applications)\n\n outputDebug(outputContent`Validating existing session against the scopes:\n${outputToken.json(scopes)}\nFor applications:\n${outputToken.json(applications)}\n`)\n\n const validationResult = await validateSession(scopes, applications, currentSession)\n\n let newSession = {}\n\n if (validationResult === 'needs_full_auth') {\n await throwOnNoPrompt(noPrompt)\n outputDebug(outputContent`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications)\n } else if (validationResult === 'needs_refresh' || forceRefresh) {\n outputDebug(outputContent`The current session is valid but needs refresh. Refreshing...`)\n try {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n newSession = await refreshTokens(currentSession!, applications)\n } catch (error) {\n if (error instanceof InvalidGrantError) {\n await throwOnNoPrompt(noPrompt)\n newSession = await executeCompleteFlow(applications)\n } else if (error instanceof InvalidRequestError) {\n await sessionStore.remove()\n throw new AbortError('\\nError validating auth session', \"We've cleared the current session, please try again\")\n } else {\n throw error\n }\n }\n }\n\n const completeSession = {...currentSession, ...newSession} as Session\n const newSessionId = completeSession.identity.userId\n const updatedSessions: Sessions = {\n ...sessions,\n [fqdn]: {...sessions[fqdn], [newSessionId]: completeSession},\n }\n\n // Save the new session info if it has changed\n if (!isEmpty(newSession)) {\n await sessionStore.store(updatedSessions)\n setCurrentSessionId(newSessionId)\n }\n\n const tokens = await tokensFor(applications, completeSession)\n\n // Overwrite partners token if using a custom CLI Token\n const envToken = getPartnersToken()\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n\n setLastSeenAuthMethod(envToken ? 'partners_token' : 'device_auth')\n setLastSeenUserIdAfterAuth(tokens.userId)\n return tokens\n}\n\nasync function throwOnNoPrompt(noPrompt: boolean) {\n if (!noPrompt) return\n await logout()\n throw new AbortError(\n `The currently available CLI credentials are invalid.\n\nThe CLI is currently unable to prompt for reauthentication.`,\n 'Restart the CLI process you were running. If in an interactive terminal, you will be prompted to reauthenticate. If in a non-interactive terminal, ensure the correct credentials are available in the program environment.',\n )\n}\n\n/**\n * Execute the full authentication flow.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param alias - Optional alias to use for the session.\n */\nasync function executeCompleteFlow(applications: OAuthApplications): Promise<Session> {\n const scopes = getFlattenScopes(applications)\n const exchangeScopes = getExchangeScopes(applications)\n const store = applications.adminApi?.storeFqdn\n if (firstPartyDev()) {\n outputDebug(outputContent`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n const identityTokenInformation = getIdentityTokenInformation()\n if (identityTokenInformation) {\n identityToken = buildIdentityTokenFromEnv(scopes, identityTokenInformation)\n } else {\n // Request a device code to authorize without a browser redirect.\n outputDebug(outputContent`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n outputDebug(outputContent`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n }\n\n // Exchange identity token for application tokens\n outputDebug(outputContent`CLI token received. Exchanging it for application tokens...`)\n const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)\n\n // Get the alias for the session (email or userId)\n const businessPlatformToken = result[applicationId('business-platform')]?.accessToken\n const alias = (await fetchEmail(businessPlatformToken)) ?? identityToken.userId\n\n const session: Session = {\n identity: {\n ...identityToken,\n alias,\n },\n applications: result,\n }\n\n outputCompleted(`Logged in.`)\n\n return session\n}\n\n/**\n * Refresh the tokens for a given session.\n *\n * @param session - The session to refresh.\n */\nasync function refreshTokens(session: Session, applications: OAuthApplications): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(session.identity)\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 identity: identityToken,\n applications: applicationTokens,\n }\n}\n\n/**\n * Get the application tokens for a given session.\n *\n * @param applications - An object containing the applications we need the tokens for.\n * @param session - The current session.\n * @param fqdn - The identity FQDN.\n */\nasync function tokensFor(applications: OAuthApplications, session: Session): Promise<OAuthSession> {\n const tokens: OAuthSession = {\n userId: session.identity.userId,\n }\n\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = session.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 = session.applications[appId]?.accessToken\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n tokens.storefront = session.applications[appId]?.accessToken\n }\n\n if (applications.businessPlatformApi) {\n const appId = applicationId('business-platform')\n tokens.businessPlatform = session.applications[appId]?.accessToken\n }\n\n if (applications.appManagementApi) {\n const appId = applicationId('app-management')\n tokens.appManagement = session.applications[appId]?.accessToken\n }\n\n return tokens\n}\n\n// Scope Helpers\n/**\n * Get a flattened array of scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns A flattened array of scopes.\n */\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 businessPlatform = apps.businessPlatformApi?.scopes ?? []\n const appManagement = apps.appManagementApi?.scopes ?? []\n const requestedScopes = [...admin, ...partner, ...storefront, ...businessPlatform, ...appManagement]\n return allDefaultScopes(requestedScopes)\n}\n\n/**\n * Get the scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns An object containing the scopes for each application.\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 const businessPlatformScopes = apps.businessPlatformApi?.scopes ?? []\n const appManagementScopes = apps.appManagementApi?.scopes ?? []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n businessPlatform: apiScopes('business-platform', businessPlatformScopes),\n appManagement: apiScopes('app-management', appManagementScopes),\n }\n}\n\nfunction buildIdentityTokenFromEnv(\n scopes: string[],\n identityTokenInformation: {accessToken: string; refreshToken: string; userId: string},\n) {\n return {\n ...identityTokenInformation,\n expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),\n scopes,\n alias: identityTokenInformation.userId,\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface LoadingBarProps {
|
|
3
|
+
title: string;
|
|
4
|
+
noColor?: boolean;
|
|
5
|
+
noProgressBar?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const LoadingBar: ({ title, noColor, noProgressBar }: React.PropsWithChildren<LoadingBarProps>) => JSX.Element;
|
|
8
|
+
export { LoadingBar };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TextAnimation } from './TextAnimation.js';
|
|
2
|
+
import useLayout from '../hooks/use-layout.js';
|
|
3
|
+
import { shouldDisplayColors } from '../../../../public/node/output.js';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Box, Text } from 'ink';
|
|
6
|
+
const loadingBarChar = '▀';
|
|
7
|
+
const hillString = '▁▁▂▂▃▃▄▄▅▅▆▆▇▇██▇▇▆▆▅▅▄▄▃▃▂▂▁▁';
|
|
8
|
+
const LoadingBar = ({ title, noColor, noProgressBar }) => {
|
|
9
|
+
const { twoThirds } = useLayout();
|
|
10
|
+
let loadingBar = new Array(twoThirds).fill(loadingBarChar).join('');
|
|
11
|
+
if (noColor ?? !shouldDisplayColors()) {
|
|
12
|
+
loadingBar = hillString.repeat(Math.ceil(twoThirds / hillString.length));
|
|
13
|
+
}
|
|
14
|
+
return (React.createElement(Box, { flexDirection: "column" },
|
|
15
|
+
!noProgressBar && React.createElement(TextAnimation, { text: loadingBar, maxWidth: twoThirds }),
|
|
16
|
+
React.createElement(Text, null,
|
|
17
|
+
title,
|
|
18
|
+
" ...")));
|
|
19
|
+
};
|
|
20
|
+
export { LoadingBar };
|
|
21
|
+
//# sourceMappingURL=LoadingBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadingBar.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/components/LoadingBar.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAA;AAChD,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAC9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAA;AACrE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAE7B,MAAM,cAAc,GAAG,GAAG,CAAA;AAC1B,MAAM,UAAU,GAAG,gCAAgC,CAAA;AAQnD,MAAM,UAAU,GAAG,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAA2C,EAAE,EAAE;IAC/F,MAAM,EAAC,SAAS,EAAC,GAAG,SAAS,EAAE,CAAA;IAC/B,IAAI,UAAU,GAAG,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACnE,IAAI,OAAO,IAAI,CAAC,mBAAmB,EAAE,EAAE,CAAC;QACtC,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;IAC1E,CAAC;IAED,OAAO,CACL,oBAAC,GAAG,IAAC,aAAa,EAAC,QAAQ;QACxB,CAAC,aAAa,IAAI,oBAAC,aAAa,IAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,GAAI;QAC3E,oBAAC,IAAI;YAAE,KAAK;mBAAY,CACpB,CACP,CAAA;AACH,CAAC,CAAA;AAED,OAAO,EAAC,UAAU,EAAC,CAAA","sourcesContent":["import {TextAnimation} from './TextAnimation.js'\nimport useLayout from '../hooks/use-layout.js'\nimport {shouldDisplayColors} from '../../../../public/node/output.js'\nimport React from 'react'\nimport {Box, Text} from 'ink'\n\nconst loadingBarChar = '▀'\nconst hillString = '▁▁▂▂▃▃▄▄▅▅▆▆▇▇██▇▇▆▆▅▅▄▄▃▃▂▂▁▁'\n\ninterface LoadingBarProps {\n title: string\n noColor?: boolean\n noProgressBar?: boolean\n}\n\nconst LoadingBar = ({title, noColor, noProgressBar}: React.PropsWithChildren<LoadingBarProps>) => {\n const {twoThirds} = useLayout()\n let loadingBar = new Array(twoThirds).fill(loadingBarChar).join('')\n if (noColor ?? !shouldDisplayColors()) {\n loadingBar = hillString.repeat(Math.ceil(twoThirds / hillString.length))\n }\n\n return (\n <Box flexDirection=\"column\">\n {!noProgressBar && <TextAnimation text={loadingBar} maxWidth={twoThirds} />}\n <Text>{title} ...</Text>\n </Box>\n )\n}\n\nexport {LoadingBar}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|