@mintlify/cli 4.0.1076 → 4.0.1077
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/bin/login.js +21 -6
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/login.tsx +40 -5
package/bin/login.js
CHANGED
|
@@ -7,10 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { input } from '@inquirer/prompts';
|
|
12
12
|
import { addLog } from '@mintlify/previewing';
|
|
13
|
-
import
|
|
13
|
+
import chalk from 'chalk';
|
|
14
|
+
import { Box, Text } from 'ink';
|
|
15
|
+
import open from 'open';
|
|
14
16
|
import { calculatePKCECodeChallenge, randomNonce, randomPKCECodeVerifier, randomState, } from 'openid-client';
|
|
15
17
|
import { DASHBOARD_URL, STYTCH_CLIENT_ID, TOKEN_ENDPOINT } from './constants.js';
|
|
16
18
|
import { storeCredentials } from './keyring.js';
|
|
@@ -25,8 +27,21 @@ export function login() {
|
|
|
25
27
|
const authorizeUrl = new URL('/api/cli/oauth/authorize', DASHBOARD_URL);
|
|
26
28
|
authorizeUrl.searchParams.set('state', state);
|
|
27
29
|
authorizeUrl.searchParams.set('code_challenge', codeChallenge);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const url = authorizeUrl.toString();
|
|
31
|
+
addLog(_jsxs(Box, { flexDirection: "column", gap: 1, paddingY: 1, children: [_jsxs(Text, { bold: true, children: [_jsx(Text, { color: "green", children: "\u25C6 " }), "A browser window will open for Mintlify authentication"] }), _jsxs(Box, { flexDirection: "column", paddingLeft: 3, gap: 1, children: [_jsx(Text, { dimColor: true, children: "If your browser doesn't open automatically, copy this URL:" }), _jsx(Text, { color: "cyan", children: url })] })] }));
|
|
32
|
+
open(url).catch(() => { });
|
|
33
|
+
addLog(_jsxs(Box, { flexDirection: "column", paddingLeft: 1, marginTop: 1, children: [_jsx(Text, { dimColor: true, children: "\u256D\u2500 Paste the authorization code from your browser" }), _jsx(Text, { dimColor: true, children: "\u2502" })] }));
|
|
34
|
+
// Let ink finish rendering before inquirer takes over stdout
|
|
35
|
+
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
36
|
+
const code = yield input({
|
|
37
|
+
message: '█',
|
|
38
|
+
theme: {
|
|
39
|
+
prefix: chalk.dim(' │'),
|
|
40
|
+
style: {
|
|
41
|
+
answer: (text) => chalk.cyan(text),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
30
45
|
const res = yield fetch(TOKEN_ENDPOINT, {
|
|
31
46
|
method: 'POST',
|
|
32
47
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -40,11 +55,11 @@ export function login() {
|
|
|
40
55
|
});
|
|
41
56
|
const body = yield res.json().catch(() => ({}));
|
|
42
57
|
if (!res.ok) {
|
|
43
|
-
addLog(_jsxs(Text, { color: "red", children: ["Login failed: ", (_b = (_a = body.error_message) !== null && _a !== void 0 ? _a : body.error) !== null && _b !== void 0 ? _b : 'unknown error'] }));
|
|
58
|
+
addLog(_jsxs(Text, { color: "red", children: ["\u2716 Login failed: ", (_b = (_a = body.error_message) !== null && _a !== void 0 ? _a : body.error) !== null && _b !== void 0 ? _b : 'unknown error'] }));
|
|
44
59
|
return;
|
|
45
60
|
}
|
|
46
61
|
const token = body;
|
|
47
62
|
yield storeCredentials(token.access_token, token.refresh_token);
|
|
48
|
-
addLog(_jsx(Text, { color: "green", children: "Logged in successfully." }));
|
|
63
|
+
addLog(_jsx(Text, { color: "green", children: "\u2714 Logged in successfully." }));
|
|
49
64
|
});
|
|
50
65
|
}
|