@vendian/cli 0.0.40 → 0.0.41
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/cli-wrapper.mjs +33 -2
- package/package.json +1 -1
package/cli-wrapper.mjs
CHANGED
|
@@ -43,7 +43,9 @@ __export(auth_exports, {
|
|
|
43
43
|
buildWindowsOpenCommand: () => buildWindowsOpenCommand,
|
|
44
44
|
cloudAuthStatus: () => cloudAuthStatus,
|
|
45
45
|
cloudConfigPath: () => cloudConfigPath,
|
|
46
|
+
defaultOAuthRedirectUri: () => defaultOAuthRedirectUri,
|
|
46
47
|
fetchPackageCredentials: () => fetchPackageCredentials,
|
|
48
|
+
formatOAuthError: () => formatOAuthError,
|
|
47
49
|
loadCloudConfig: () => loadCloudConfig,
|
|
48
50
|
loginWithVendianOAuth: () => loginWithVendianOAuth,
|
|
49
51
|
resolveApiUrl: () => resolveApiUrl,
|
|
@@ -91,6 +93,11 @@ async function loginWithVendianOAuth({ backend, apiUrl, noBrowser = false, env =
|
|
|
91
93
|
clerkToken
|
|
92
94
|
});
|
|
93
95
|
return { apiUrl: resolvedApiUrl, ...exchange };
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw new Error(formatOAuthError(error, {
|
|
98
|
+
apiUrl: resolvedApiUrl,
|
|
99
|
+
redirectUri: callback.redirectUri
|
|
100
|
+
}), { cause: error });
|
|
94
101
|
} finally {
|
|
95
102
|
await callback.close();
|
|
96
103
|
}
|
|
@@ -175,6 +182,16 @@ function activateCloudProfile({ backend, apiUrl, env = process.env, platform = p
|
|
|
175
182
|
profiles
|
|
176
183
|
};
|
|
177
184
|
}
|
|
185
|
+
function defaultOAuthRedirectUri(env = process.env) {
|
|
186
|
+
const port = Number(env.VENDIAN_CLI_OAUTH_REDIRECT_PORT || DEFAULT_OAUTH_REDIRECT_PORT);
|
|
187
|
+
return `http://127.0.0.1:${port}/callback`;
|
|
188
|
+
}
|
|
189
|
+
function formatOAuthError(error, { apiUrl, redirectUri } = {}) {
|
|
190
|
+
const message = error && typeof error.message === "string" ? error.message : String(error || "OAuth login failed");
|
|
191
|
+
const hint = oauthRedirectHint(message, { apiUrl, redirectUri });
|
|
192
|
+
return hint ? `${message}
|
|
193
|
+
${hint}` : message;
|
|
194
|
+
}
|
|
178
195
|
async function getOAuthConfig(apiUrl, redirectUri) {
|
|
179
196
|
const url = new URL(`${apiUrl}/api/v1/cli/auth/oauth/config`);
|
|
180
197
|
url.searchParams.set("redirectUri", redirectUri);
|
|
@@ -256,6 +273,7 @@ async function createCallbackServer(env) {
|
|
|
256
273
|
const code = url.searchParams.get("code");
|
|
257
274
|
const state = url.searchParams.get("state");
|
|
258
275
|
const error = url.searchParams.get("error");
|
|
276
|
+
const errorDescription = url.searchParams.get("error_description");
|
|
259
277
|
const body = code ? "Vendian CLI authentication complete. You can close this window." : "Vendian CLI authentication failed. Return to the terminal.";
|
|
260
278
|
res.writeHead(code ? 200 : 400, {
|
|
261
279
|
"Content-Type": "text/plain; charset=utf-8",
|
|
@@ -268,7 +286,8 @@ async function createCallbackServer(env) {
|
|
|
268
286
|
}
|
|
269
287
|
settled = true;
|
|
270
288
|
if (error) {
|
|
271
|
-
|
|
289
|
+
const details = errorDescription ? `${error} (${errorDescription})` : error;
|
|
290
|
+
reject(new Error(`OAuth login failed: ${details}`));
|
|
272
291
|
return;
|
|
273
292
|
}
|
|
274
293
|
if (!code) {
|
|
@@ -290,6 +309,18 @@ async function createCallbackServer(env) {
|
|
|
290
309
|
close: () => new Promise((resolve) => server.close(resolve))
|
|
291
310
|
};
|
|
292
311
|
}
|
|
312
|
+
function oauthRedirectHint(message, { apiUrl, redirectUri } = {}) {
|
|
313
|
+
if (!redirectUri) {
|
|
314
|
+
return "";
|
|
315
|
+
}
|
|
316
|
+
const lower = String(message || "").toLowerCase();
|
|
317
|
+
const looksLikeRedirectMismatch = lower.includes("redirect_uri") || lower.includes("pre-registered redirect") || lower.includes("oauth login timed out before callback completed") || lower.includes("oauth callback did not include an authorization code");
|
|
318
|
+
if (!looksLikeRedirectMismatch) {
|
|
319
|
+
return "";
|
|
320
|
+
}
|
|
321
|
+
const target = apiUrl || "this backend";
|
|
322
|
+
return `If Clerk rejected the CLI callback for ${target}, add this redirect URL in Clerk: ${redirectUri}`;
|
|
323
|
+
}
|
|
293
324
|
function openBrowser(url) {
|
|
294
325
|
const platform = process.platform;
|
|
295
326
|
if (platform === "win32") {
|
|
@@ -2404,7 +2435,7 @@ function buildLocalServeEventStreamArgs({ agentsDir: agentsDir2 = "./agents", co
|
|
|
2404
2435
|
}
|
|
2405
2436
|
|
|
2406
2437
|
// src/version.js
|
|
2407
|
-
var CLI_VERSION = true ? "0.0.
|
|
2438
|
+
var CLI_VERSION = true ? "0.0.41" : process.env.npm_package_version || "0.0.0-dev";
|
|
2408
2439
|
|
|
2409
2440
|
// src/dev-server.js
|
|
2410
2441
|
var __dirname = path8.dirname(fileURLToPath(import.meta.url));
|