@mintlify/cli 4.0.1071 → 4.0.1072
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/cli.js +10 -0
- package/bin/keyring.js +34 -0
- package/bin/login.js +2 -0
- package/bin/logout.js +19 -0
- package/bin/status.js +49 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/src/cli.tsx +20 -0
- package/src/keyring.ts +23 -0
- package/src/login.tsx +3 -0
- package/src/logout.tsx +9 -0
- package/src/status.tsx +50 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1072",
|
|
4
4
|
"description": "The Mintlify CLI",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -61,13 +61,15 @@
|
|
|
61
61
|
"ink": "6.3.0",
|
|
62
62
|
"inquirer": "12.3.0",
|
|
63
63
|
"js-yaml": "4.1.0",
|
|
64
|
+
"keytar": "^7.9.0",
|
|
64
65
|
"mdast-util-mdx-jsx": "3.2.0",
|
|
65
66
|
"openid-client": "^6.8.2",
|
|
66
67
|
"posthog-node": "5.17.2",
|
|
67
68
|
"react": "19.2.3",
|
|
68
69
|
"semver": "7.7.2",
|
|
69
70
|
"unist-util-visit": "5.0.0",
|
|
70
|
-
"yargs": "17.7.1"
|
|
71
|
+
"yargs": "17.7.1",
|
|
72
|
+
"zod": "^4.3.6"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
75
|
"@mintlify/eslint-config-typescript": "1.0.13",
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"@tsconfig/recommended": "1.0.2",
|
|
78
80
|
"@types/adm-zip": "0.5.7",
|
|
79
81
|
"@types/detect-port": "1.3.2",
|
|
82
|
+
"@types/keytar": "^4.4.2",
|
|
80
83
|
"@types/mdast": "4.0.4",
|
|
81
84
|
"@types/node": "18.15.0",
|
|
82
85
|
"@types/yargs": "17.0.22",
|
|
@@ -89,5 +92,5 @@
|
|
|
89
92
|
"vitest": "2.1.9",
|
|
90
93
|
"vitest-mock-process": "1.0.4"
|
|
91
94
|
},
|
|
92
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "3531b920f9f41a9470119b685c3bb87c514e5ff0"
|
|
93
96
|
}
|
package/src/cli.tsx
CHANGED
|
@@ -36,9 +36,11 @@ import {
|
|
|
36
36
|
} from './helpers.js';
|
|
37
37
|
import { init } from './init.js';
|
|
38
38
|
import { login } from './login.js';
|
|
39
|
+
import { logout } from './logout.js';
|
|
39
40
|
import { mdxLinter } from './mdxLinter.js';
|
|
40
41
|
import { migrateMdx } from './migrateMdx.js';
|
|
41
42
|
import { scrapeSite, scrapePage, scrapeOpenApi } from './scrape.js';
|
|
43
|
+
import { status } from './status.js';
|
|
42
44
|
import { createTelemetryMiddleware } from './telemetry/middleware.js';
|
|
43
45
|
import { trackTelemetryPreferenceChange } from './telemetry/track.js';
|
|
44
46
|
import { update } from './update.js';
|
|
@@ -356,6 +358,24 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
|
|
|
356
358
|
await terminate(0);
|
|
357
359
|
}
|
|
358
360
|
)
|
|
361
|
+
.command(
|
|
362
|
+
'status',
|
|
363
|
+
false,
|
|
364
|
+
() => undefined,
|
|
365
|
+
async () => {
|
|
366
|
+
await status();
|
|
367
|
+
await terminate(0);
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
.command(
|
|
371
|
+
'logout',
|
|
372
|
+
false,
|
|
373
|
+
() => undefined,
|
|
374
|
+
async () => {
|
|
375
|
+
await logout();
|
|
376
|
+
await terminate(0);
|
|
377
|
+
}
|
|
378
|
+
)
|
|
359
379
|
.command(
|
|
360
380
|
'login',
|
|
361
381
|
false,
|
package/src/keyring.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import keytar from 'keytar';
|
|
2
|
+
|
|
3
|
+
const SERVICE = 'mintlify';
|
|
4
|
+
const ACCESS_TOKEN_ACCOUNT = 'access_token';
|
|
5
|
+
const REFRESH_TOKEN_ACCOUNT = 'refresh_token';
|
|
6
|
+
|
|
7
|
+
export async function storeCredentials(accessToken: string, refreshToken: string): Promise<void> {
|
|
8
|
+
await Promise.all([
|
|
9
|
+
keytar.setPassword(SERVICE, ACCESS_TOKEN_ACCOUNT, accessToken),
|
|
10
|
+
keytar.setPassword(SERVICE, REFRESH_TOKEN_ACCOUNT, refreshToken),
|
|
11
|
+
]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function getAccessToken(): Promise<string | null> {
|
|
15
|
+
return keytar.getPassword(SERVICE, ACCESS_TOKEN_ACCOUNT);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function clearCredentials(): Promise<void> {
|
|
19
|
+
await Promise.all([
|
|
20
|
+
keytar.deletePassword(SERVICE, ACCESS_TOKEN_ACCOUNT),
|
|
21
|
+
keytar.deletePassword(SERVICE, REFRESH_TOKEN_ACCOUNT),
|
|
22
|
+
]);
|
|
23
|
+
}
|
package/src/login.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from 'openid-client';
|
|
10
10
|
|
|
11
11
|
import { DASHBOARD_URL, STYTCH_CLIENT_ID, TOKEN_ENDPOINT } from './constants.js';
|
|
12
|
+
import { storeCredentials } from './keyring.js';
|
|
12
13
|
|
|
13
14
|
interface TokenResponse {
|
|
14
15
|
access_token: string;
|
|
@@ -58,5 +59,7 @@ export async function login(): Promise<void> {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
const token = body as TokenResponse;
|
|
62
|
+
await storeCredentials(token.access_token, token.refresh_token);
|
|
63
|
+
|
|
61
64
|
addLog(<Text color="green">Logged in successfully.</Text>);
|
|
62
65
|
}
|
package/src/logout.tsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { addLog } from '@mintlify/previewing';
|
|
2
|
+
import { Text } from 'ink';
|
|
3
|
+
|
|
4
|
+
import { clearCredentials } from './keyring.js';
|
|
5
|
+
|
|
6
|
+
export async function logout(): Promise<void> {
|
|
7
|
+
await clearCredentials();
|
|
8
|
+
addLog(<Text color="green">Logged out successfully.</Text>);
|
|
9
|
+
}
|
package/src/status.tsx
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { addLog } from '@mintlify/previewing';
|
|
2
|
+
import { Text } from 'ink';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
import { getAccessToken } from './keyring.js';
|
|
6
|
+
|
|
7
|
+
const API_URL = process.env.MINTLIFY_API_URL ?? 'http://localhost:5000';
|
|
8
|
+
|
|
9
|
+
const StatusResponseSchema = z.object({
|
|
10
|
+
user: z.object({ email: z.string() }),
|
|
11
|
+
org: z.object({ name: z.string() }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export async function status(): Promise<void> {
|
|
15
|
+
const accessToken = await getAccessToken();
|
|
16
|
+
|
|
17
|
+
if (!accessToken) {
|
|
18
|
+
addLog(<Text color="red">Not logged in. Run `mint login` to authenticate.</Text>);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const res = await fetch(`${API_URL}/api/cli/status`, {
|
|
24
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
addLog(<Text color="red">Not logged in. Run `mint login` to authenticate.</Text>);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const json = await res.json().catch(() => null);
|
|
33
|
+
const parsed = StatusResponseSchema.safeParse(json);
|
|
34
|
+
|
|
35
|
+
if (!parsed.success) {
|
|
36
|
+
addLog(<Text color="red">Unexpected response from server. Please try again.</Text>);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { user, org } = parsed.data;
|
|
41
|
+
addLog(
|
|
42
|
+
<Text>
|
|
43
|
+
Logged in as <Text color="green">{user.email}</Text> in org{' '}
|
|
44
|
+
<Text color="green">{org.name}</Text>
|
|
45
|
+
</Text>
|
|
46
|
+
);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
addLog(<Text color="red">Unexpected response from server. Please try again.</Text>);
|
|
49
|
+
}
|
|
50
|
+
}
|