@mintlify/cli 4.0.1069 → 4.0.1070

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 CHANGED
@@ -20,6 +20,7 @@ import { accessibilityCheck } from './accessibilityCheck.js';
20
20
  import { setTelemetryEnabled } from './config.js';
21
21
  import { checkPort, checkNodeVersion, autoUpgradeIfNeeded, getVersions, suppressConsoleWarnings, terminate, readLocalOpenApiFile, } from './helpers.js';
22
22
  import { init } from './init.js';
23
+ import { login } from './login.js';
23
24
  import { mdxLinter } from './mdxLinter.js';
24
25
  import { migrateMdx } from './migrateMdx.js';
25
26
  import { scrapeSite, scrapePage, scrapeOpenApi } from './scrape.js';
@@ -277,6 +278,10 @@ export const cli = ({ packageName = 'mint' }) => {
277
278
  yield autoUpgradeIfNeeded();
278
279
  yield renameFilesAndUpdateLinksInContent(from, to, force);
279
280
  yield terminate(0);
281
+ }))
282
+ .command('login', false, () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
283
+ yield login();
284
+ yield terminate(0);
280
285
  }))
281
286
  .command('update', 'update the CLI to the latest version', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
282
287
  yield update({ packageName });
package/bin/constants.js CHANGED
@@ -1,3 +1,4 @@
1
+ var _a;
1
2
  import os from 'os';
2
3
  import path from 'path';
3
4
  export const HOME_DIR = os.homedir();
@@ -5,3 +6,6 @@ export const CMD_EXEC_PATH = process.cwd();
5
6
  export const CONFIG_DIR = path.join(HOME_DIR, '.config', 'mintlify');
6
7
  export const CLI_CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
7
8
  export const TELEMETRY_ASYNC_TIMEOUT_MS = 10000;
9
+ export const DASHBOARD_URL = (_a = process.env.MINTLIFY_DASHBOARD_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000';
10
+ export const TOKEN_ENDPOINT = 'https://test.stytch.com/v1/public/project-test-2d86347b-dfdb-4609-be69-12d8146220bd/oauth2/token';
11
+ export const STYTCH_CLIENT_ID = 'connected-app-test-b597afb3-304a-420f-bc13-dacca566c59f';
package/bin/login.js ADDED
@@ -0,0 +1,48 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
11
+ import { input } from '@inquirer/prompts';
12
+ import { addLog } from '@mintlify/previewing';
13
+ import { Text } from 'ink';
14
+ import { calculatePKCECodeChallenge, randomNonce, randomPKCECodeVerifier, randomState, } from 'openid-client';
15
+ import { DASHBOARD_URL, STYTCH_CLIENT_ID, TOKEN_ENDPOINT } from './constants.js';
16
+ export function login() {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b;
19
+ const codeVerifier = randomPKCECodeVerifier();
20
+ const codeChallenge = yield calculatePKCECodeChallenge(codeVerifier);
21
+ const nonce = randomNonce();
22
+ const clientState = randomState();
23
+ const state = Buffer.from(JSON.stringify({ nonce, clientState })).toString('base64url');
24
+ const authorizeUrl = new URL('/api/cli/oauth/authorize', DASHBOARD_URL);
25
+ authorizeUrl.searchParams.set('state', state);
26
+ authorizeUrl.searchParams.set('code_challenge', codeChallenge);
27
+ addLog(_jsxs(Text, { children: ["Opening browser to log in to Mintlify... ", authorizeUrl.toString()] }));
28
+ const code = yield input({ message: 'Paste the code from your browser:' });
29
+ const res = yield fetch(TOKEN_ENDPOINT, {
30
+ method: 'POST',
31
+ headers: { 'Content-Type': 'application/json' },
32
+ body: JSON.stringify({
33
+ client_id: STYTCH_CLIENT_ID,
34
+ grant_type: 'authorization_code',
35
+ code,
36
+ code_verifier: codeVerifier,
37
+ redirect_uri: `${DASHBOARD_URL}/api/cli/oauth/callback`,
38
+ }),
39
+ });
40
+ const body = yield res.json().catch(() => ({}));
41
+ if (!res.ok) {
42
+ 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'] }));
43
+ return;
44
+ }
45
+ const token = body;
46
+ addLog(_jsx(Text, { color: "green", children: "Logged in successfully." }));
47
+ });
48
+ }