@mintlify/cli 4.0.1094 → 4.0.1095

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 CHANGED
@@ -17,6 +17,7 @@ import { calculatePKCECodeChallenge, randomNonce, randomPKCECodeVerifier, random
17
17
  import { startCallbackServer } from './callbackServer.js';
18
18
  import { DASHBOARD_URL, STYTCH_CLIENT_ID, TOKEN_ENDPOINT } from './constants.js';
19
19
  import { storeCredentials } from './keyring.js';
20
+ import { trackLoginAttempt, trackLoginFailed, trackLoginSuccess } from './telemetry/track.js';
20
21
  export function login() {
21
22
  return __awaiter(this, void 0, void 0, function* () {
22
23
  var _a, _b;
@@ -29,6 +30,7 @@ export function login() {
29
30
  authorizeUrl.searchParams.set('state', state);
30
31
  authorizeUrl.searchParams.set('code_challenge', codeChallenge);
31
32
  const url = authorizeUrl.toString();
33
+ void trackLoginAttempt();
32
34
  const { codePromise, close: closeServer } = yield startCallbackServer();
33
35
  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 })] })] }));
34
36
  open(url).catch(() => { });
@@ -69,11 +71,14 @@ export function login() {
69
71
  });
70
72
  const body = yield res.json().catch(() => ({}));
71
73
  if (!res.ok) {
72
- 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'] }));
74
+ const reason = (_b = (_a = body.error_message) !== null && _a !== void 0 ? _a : body.error) !== null && _b !== void 0 ? _b : 'unknown error';
75
+ void trackLoginFailed(reason);
76
+ addLog(_jsxs(Text, { color: "red", children: ["\u2716 Login failed: ", reason] }));
73
77
  return;
74
78
  }
75
79
  const token = body;
76
80
  yield storeCredentials(token.access_token, token.refresh_token);
81
+ void trackLoginSuccess();
77
82
  addLog(_jsx(Text, { color: "green", children: "\u2714 Logged in successfully." }));
78
83
  });
79
84
  }
@@ -46,6 +46,32 @@ export function trackCommand(_a) {
46
46
  catch (_b) { }
47
47
  });
48
48
  }
49
+ function trackLoginEvent(event, extra) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (!isTelemetryEnabled())
52
+ return;
53
+ try {
54
+ const { cli: cliVersion } = getVersions();
55
+ yield captureWithTimeout(event, Object.assign(Object.assign({}, extra), { cli_version: cliVersion, os: os.platform(), arch: os.arch(), node_version: process.version }));
56
+ }
57
+ catch (_a) { }
58
+ });
59
+ }
60
+ export function trackLoginAttempt() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return trackLoginEvent('cli.login.attempted');
63
+ });
64
+ }
65
+ export function trackLoginSuccess() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ return trackLoginEvent('cli.login.succeeded');
68
+ });
69
+ }
70
+ export function trackLoginFailed(reason) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ return trackLoginEvent('cli.login.failed', { reason });
73
+ });
74
+ }
49
75
  export function trackTelemetryPreferenceChange(options) {
50
76
  return __awaiter(this, void 0, void 0, function* () {
51
77
  if (process.env.CLI_TEST_MODE === 'true')