@mintlify/cli 4.0.1099 → 4.0.1100
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/__test__/analytics/format.test.ts +9 -14
- package/__test__/telemetry.test.ts +2 -2
- package/bin/analytics/index.js +24 -39
- package/bin/analytics/output.js +3 -2
- package/bin/cli.js +5 -5
- package/bin/login.js +42 -2
- package/bin/middlewares/subdomainMiddleware.js +28 -0
- package/bin/{telemetry/middleware.js → middlewares/telemetryMiddleware.js} +1 -1
- package/bin/status.js +8 -9
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/analytics/index.tsx +28 -43
- package/src/analytics/output.ts +4 -2
- package/src/cli.tsx +3 -3
- package/src/login.tsx +48 -2
- package/src/middlewares/subdomainMiddleware.ts +16 -0
- package/src/{telemetry/middleware.ts → middlewares/telemetryMiddleware.ts} +1 -1
- package/src/status.tsx +7 -7
|
@@ -5,6 +5,11 @@ import {
|
|
|
5
5
|
formatPrettyTable,
|
|
6
6
|
resolveFormat,
|
|
7
7
|
} from '../../src/analytics/output.js';
|
|
8
|
+
import * as helpers from '../../src/helpers.js';
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
vi.restoreAllMocks();
|
|
12
|
+
});
|
|
8
13
|
|
|
9
14
|
describe('num', () => {
|
|
10
15
|
it('formats numbers with locale separators', () => {
|
|
@@ -81,31 +86,21 @@ describe('formatPlainTable', () => {
|
|
|
81
86
|
});
|
|
82
87
|
|
|
83
88
|
describe('resolveFormat', () => {
|
|
84
|
-
it('returns json when
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('returns json when CLAUDECODE env is set', () => {
|
|
89
|
-
const prev = process.env.CLAUDECODE;
|
|
90
|
-
process.env.CLAUDECODE = '1';
|
|
89
|
+
it('returns json when AI mode is active', () => {
|
|
90
|
+
vi.spyOn(helpers, 'isAI').mockReturnValue(true);
|
|
91
91
|
expect(resolveFormat({})).toBe('json');
|
|
92
|
-
process.env.CLAUDECODE = prev;
|
|
93
92
|
});
|
|
94
93
|
|
|
95
94
|
it('returns specified format', () => {
|
|
96
|
-
|
|
97
|
-
delete process.env.CLAUDECODE;
|
|
95
|
+
vi.spyOn(helpers, 'isAI').mockReturnValue(true);
|
|
98
96
|
expect(resolveFormat({ format: 'plain' })).toBe('plain');
|
|
99
97
|
expect(resolveFormat({ format: 'json' })).toBe('json');
|
|
100
98
|
expect(resolveFormat({ format: 'graph' })).toBe('graph');
|
|
101
|
-
process.env.CLAUDECODE = prev;
|
|
102
99
|
});
|
|
103
100
|
|
|
104
101
|
it('defaults to plain', () => {
|
|
105
|
-
|
|
106
|
-
delete process.env.CLAUDECODE;
|
|
102
|
+
vi.spyOn(helpers, 'isAI').mockReturnValue(false);
|
|
107
103
|
expect(resolveFormat({})).toBe('plain');
|
|
108
|
-
process.env.CLAUDECODE = prev;
|
|
109
104
|
});
|
|
110
105
|
});
|
|
111
106
|
|
|
@@ -4,11 +4,11 @@ import os from 'os';
|
|
|
4
4
|
|
|
5
5
|
import { isTelemetryEnabled, setTelemetryEnabled } from '../src/config.js';
|
|
6
6
|
import { TELEMETRY_ASYNC_TIMEOUT_MS } from '../src/constants.js';
|
|
7
|
-
import { getDistinctId } from '../src/telemetry/distinctId.js';
|
|
8
7
|
import {
|
|
9
8
|
createTelemetryMiddleware,
|
|
10
9
|
getSanitizedCommandForTelemetry,
|
|
11
|
-
} from '../src/
|
|
10
|
+
} from '../src/middlewares/telemetryMiddleware.js';
|
|
11
|
+
import { getDistinctId } from '../src/telemetry/distinctId.js';
|
|
12
12
|
import * as trackModule from '../src/telemetry/track.js';
|
|
13
13
|
import { trackCommand, trackTelemetryPreferenceChange } from '../src/telemetry/track.js';
|
|
14
14
|
|
package/bin/analytics/index.js
CHANGED
|
@@ -13,12 +13,12 @@ import chalk from 'chalk';
|
|
|
13
13
|
import { Text } from 'ink';
|
|
14
14
|
import { getConfigValue } from '../config.js';
|
|
15
15
|
import { terminate } from '../helpers.js';
|
|
16
|
+
import { subdomainMiddleware } from '../middlewares/subdomainMiddleware.js';
|
|
16
17
|
import { getBucketThreads, getBuckets, getConversations, getFeedback, getFeedbackByPage, getKpi, getSearches, } from './client.js';
|
|
17
18
|
import { num, truncate } from './format.js';
|
|
18
19
|
import { formatBarChart, formatOutput, resolveFormat } from './output.js';
|
|
19
20
|
const withSubdomain = (yargs) => yargs.option('subdomain', {
|
|
20
21
|
type: 'string',
|
|
21
|
-
default: getConfigValue('subdomain'),
|
|
22
22
|
description: 'Documentation subdomain (default: mint config set subdomain)',
|
|
23
23
|
});
|
|
24
24
|
function defaultFrom() {
|
|
@@ -44,15 +44,10 @@ const withDates = (yargs) => yargs
|
|
|
44
44
|
default: defaultTo(),
|
|
45
45
|
description: 'End date (YYYY-MM-DD)',
|
|
46
46
|
});
|
|
47
|
-
const withFormat = (yargs) => yargs
|
|
48
|
-
.option('format', {
|
|
47
|
+
const withFormat = (yargs) => yargs.option('format', {
|
|
49
48
|
type: 'string',
|
|
50
49
|
choices: ['table', 'plain', 'json', 'graph'],
|
|
51
50
|
description: 'Output format (table=pretty, plain=pipeable, json=raw)',
|
|
52
|
-
})
|
|
53
|
-
.option('agent', {
|
|
54
|
-
type: 'boolean',
|
|
55
|
-
description: 'Agent-friendly output (equivalent to --format json)',
|
|
56
51
|
});
|
|
57
52
|
const withAll = (yargs) => withFormat(withDates(withSubdomain(yargs)));
|
|
58
53
|
function output(format, text) {
|
|
@@ -63,11 +58,12 @@ function output(format, text) {
|
|
|
63
58
|
process.stdout.write(text + '\n');
|
|
64
59
|
}
|
|
65
60
|
}
|
|
66
|
-
export const analyticsBuilder = (yargs) => yargs
|
|
67
|
-
.
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
export const analyticsBuilder = (yargs) => withAll(yargs)
|
|
62
|
+
.middleware(subdomainMiddleware)
|
|
63
|
+
.command('stats', 'display KPI numbers (views, visitors, searches)', (yargs) => withAll(yargs).option('page', {
|
|
64
|
+
type: 'string',
|
|
65
|
+
description: 'Filter to a specific page path',
|
|
66
|
+
}), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
67
|
var _a, _b;
|
|
72
68
|
const format = resolveFormat(argv);
|
|
73
69
|
try {
|
|
@@ -105,7 +101,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
105
101
|
return;
|
|
106
102
|
}
|
|
107
103
|
if (format === 'graph') {
|
|
108
|
-
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '
|
|
104
|
+
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '';
|
|
109
105
|
const lines = [];
|
|
110
106
|
lines.push(chalk.bold(`\nAnalytics \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
111
107
|
lines.push(chalk.bold(' Human vs Agent\n'));
|
|
@@ -126,31 +122,20 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
126
122
|
yield terminate(0);
|
|
127
123
|
return;
|
|
128
124
|
}
|
|
129
|
-
const agentOnly = argv.agents && !argv.humans;
|
|
130
|
-
const humanOnly = argv.humans && !argv.agents;
|
|
131
|
-
const showHuman = !agentOnly;
|
|
132
|
-
const showAgent = !humanOnly;
|
|
133
|
-
const showTotal = showHuman && showAgent;
|
|
134
125
|
const lines = [];
|
|
135
|
-
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '
|
|
126
|
+
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '';
|
|
136
127
|
lines.push(chalk.bold(`\nAnalytics \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
137
128
|
if (argv.page) {
|
|
138
129
|
lines.push(` Page: ${argv.page}\n`);
|
|
139
130
|
}
|
|
140
131
|
lines.push(chalk.bold(' Views'));
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
lines.push(` Agent: ${chalk.magenta(num(kpi.agentViews).padStart(8))}`);
|
|
145
|
-
if (showTotal)
|
|
146
|
-
lines.push(` Total: ${num(kpi.humanViews + kpi.agentViews).padStart(8)}`);
|
|
132
|
+
lines.push(` Human: ${chalk.cyan(num(kpi.humanViews).padStart(8))}`);
|
|
133
|
+
lines.push(` Agent: ${chalk.magenta(num(kpi.agentViews).padStart(8))}`);
|
|
134
|
+
lines.push(` Total: ${num(kpi.humanViews + kpi.agentViews).padStart(8)}`);
|
|
147
135
|
lines.push(chalk.bold('\n Visitors'));
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
lines.push(` Agent: ${chalk.magenta(num(kpi.agentVisitors).padStart(8))}`);
|
|
152
|
-
if (showTotal)
|
|
153
|
-
lines.push(` Total: ${num(kpi.humanVisitors + kpi.agentVisitors).padStart(8)}`);
|
|
136
|
+
lines.push(` Human: ${chalk.cyan(num(kpi.humanVisitors).padStart(8))}`);
|
|
137
|
+
lines.push(` Agent: ${chalk.magenta(num(kpi.agentVisitors).padStart(8))}`);
|
|
138
|
+
lines.push(` Total: ${num(kpi.humanVisitors + kpi.agentVisitors).padStart(8)}`);
|
|
154
139
|
lines.push(`\n Searches: ${chalk.bold(num(kpi.humanSearches))}`);
|
|
155
140
|
lines.push(` Feedback: ${chalk.bold(num(kpi.humanFeedback))}`);
|
|
156
141
|
lines.push(` Assistant: ${chalk.bold(num(kpi.humanAssistant))} web, ${chalk.bold(num(kpi.agentMcpSearches))} API`);
|
|
@@ -195,7 +180,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
195
180
|
output(format, JSON.stringify(data, null, 2));
|
|
196
181
|
}
|
|
197
182
|
else if (format === 'graph') {
|
|
198
|
-
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '
|
|
183
|
+
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '';
|
|
199
184
|
const lines = [];
|
|
200
185
|
lines.push(chalk.bold(`\nSearch Queries \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
201
186
|
lines.push(formatBarChart(rows.slice(0, 20).map((r) => ({
|
|
@@ -209,7 +194,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
209
194
|
output(format, formatOutput(format, headers, tableRows, data));
|
|
210
195
|
}
|
|
211
196
|
else {
|
|
212
|
-
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '
|
|
197
|
+
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '';
|
|
213
198
|
const lines = [];
|
|
214
199
|
lines.push(chalk.bold(`\nSearch Analytics \u2014 ${label} (${argv.from} to ${argv.to})`));
|
|
215
200
|
lines.push(`Total Searches: ${chalk.bold(num(data.totalSearches))}\n`);
|
|
@@ -256,7 +241,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
256
241
|
output(format, JSON.stringify(data, null, 2));
|
|
257
242
|
}
|
|
258
243
|
else if (format === 'graph') {
|
|
259
|
-
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '
|
|
244
|
+
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '';
|
|
260
245
|
const lines = [];
|
|
261
246
|
lines.push(chalk.bold(`\nFeedback by Page \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
262
247
|
lines.push(formatBarChart(rows.slice(0, 20).map((r) => ({
|
|
@@ -267,7 +252,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
267
252
|
output('table', lines.join('\n'));
|
|
268
253
|
}
|
|
269
254
|
else {
|
|
270
|
-
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '
|
|
255
|
+
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '';
|
|
271
256
|
const lines = [];
|
|
272
257
|
if (format === 'table')
|
|
273
258
|
lines.push(chalk.bold(`\nFeedback \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
@@ -301,7 +286,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
301
286
|
output(format, JSON.stringify(data, null, 2));
|
|
302
287
|
}
|
|
303
288
|
else {
|
|
304
|
-
const label = (_c = argv.subdomain) !== null && _c !== void 0 ? _c : '
|
|
289
|
+
const label = (_c = argv.subdomain) !== null && _c !== void 0 ? _c : '';
|
|
305
290
|
const lines = [];
|
|
306
291
|
if (format === 'table')
|
|
307
292
|
lines.push(chalk.bold(`\nFeedback \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
@@ -348,7 +333,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
348
333
|
output(format, JSON.stringify(data, null, 2));
|
|
349
334
|
}
|
|
350
335
|
else {
|
|
351
|
-
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '
|
|
336
|
+
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '';
|
|
352
337
|
const lines = [];
|
|
353
338
|
if (format === 'table')
|
|
354
339
|
lines.push(chalk.bold(`\nConversations \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
@@ -449,7 +434,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
449
434
|
output(format, JSON.stringify(data, null, 2));
|
|
450
435
|
}
|
|
451
436
|
else if (format === 'graph') {
|
|
452
|
-
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '
|
|
437
|
+
const label = (_a = argv.subdomain) !== null && _a !== void 0 ? _a : '';
|
|
453
438
|
const lines = [];
|
|
454
439
|
lines.push(chalk.bold(`\nConversation Buckets \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
|
455
440
|
lines.push(formatBarChart(data.data.slice(0, 20).map((b) => ({
|
|
@@ -460,7 +445,7 @@ export const analyticsBuilder = (yargs) => yargs
|
|
|
460
445
|
output('table', lines.join('\n'));
|
|
461
446
|
}
|
|
462
447
|
else {
|
|
463
|
-
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '
|
|
448
|
+
const label = (_b = argv.subdomain) !== null && _b !== void 0 ? _b : '';
|
|
464
449
|
const lines = [];
|
|
465
450
|
if (format === 'table')
|
|
466
451
|
lines.push(chalk.bold(`\nConversation Buckets \u2014 ${label} (${argv.from} to ${argv.to})\n`));
|
package/bin/analytics/output.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
+
import { isAI } from '../helpers.js';
|
|
2
3
|
export function resolveFormat(argv) {
|
|
3
|
-
if (argv.agent || process.env.CLAUDECODE === '1')
|
|
4
|
-
return 'json';
|
|
5
4
|
if (argv.format === 'table' ||
|
|
6
5
|
argv.format === 'plain' ||
|
|
7
6
|
argv.format === 'json' ||
|
|
8
7
|
argv.format === 'graph')
|
|
9
8
|
return argv.format;
|
|
9
|
+
if (isAI())
|
|
10
|
+
return 'json';
|
|
10
11
|
return 'plain';
|
|
11
12
|
}
|
|
12
13
|
export function formatPlainTable(headers, rows) {
|
package/bin/cli.js
CHANGED
|
@@ -27,9 +27,9 @@ import { getAccessToken } from './keyring.js';
|
|
|
27
27
|
import { login } from './login.js';
|
|
28
28
|
import { logout } from './logout.js';
|
|
29
29
|
import { mdxLinter } from './mdxLinter.js';
|
|
30
|
+
import { createTelemetryMiddleware } from './middlewares/telemetryMiddleware.js';
|
|
30
31
|
import { checkOpenApiFile, getOpenApiFilenamesFromDocsConfig } from './openApiCheck.js';
|
|
31
|
-
import { status,
|
|
32
|
-
import { createTelemetryMiddleware } from './telemetry/middleware.js';
|
|
32
|
+
import { status, getCliSubdomains } from './status.js';
|
|
33
33
|
import { trackTelemetryPreferenceChange } from './telemetry/track.js';
|
|
34
34
|
import { update } from './update.js';
|
|
35
35
|
import { addWorkflow } from './workflow.js';
|
|
@@ -89,7 +89,7 @@ export const cli = ({ packageName = 'mint' }) => {
|
|
|
89
89
|
.usage('usage: mintlify dev [options]')
|
|
90
90
|
.example('mintlify dev', 'run with default settings (opens in browser)')
|
|
91
91
|
.example('mintlify dev --no-open', 'run without opening in browser'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
-
var _a
|
|
92
|
+
var _a;
|
|
93
93
|
yield autoUpgradeIfNeeded();
|
|
94
94
|
const port = yield checkPort(argv);
|
|
95
95
|
const { cli: cliVersion } = getVersions();
|
|
@@ -99,9 +99,9 @@ export const cli = ({ packageName = 'mint' }) => {
|
|
|
99
99
|
accessToken = (_a = (yield getAccessToken())) !== null && _a !== void 0 ? _a : undefined;
|
|
100
100
|
const configuredSubdomain = getConfigValue('subdomain');
|
|
101
101
|
subdomain =
|
|
102
|
-
configuredSubdomain !== null && configuredSubdomain !== void 0 ? configuredSubdomain : (accessToken ? (
|
|
102
|
+
configuredSubdomain !== null && configuredSubdomain !== void 0 ? configuredSubdomain : (accessToken ? (yield getCliSubdomains(accessToken))[0] : undefined);
|
|
103
103
|
}
|
|
104
|
-
catch (
|
|
104
|
+
catch (_b) { }
|
|
105
105
|
if (port != undefined) {
|
|
106
106
|
yield dev(Object.assign(Object.assign({}, argv), { port,
|
|
107
107
|
packageName,
|
package/bin/login.js
CHANGED
|
@@ -8,15 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { input } from '@inquirer/prompts';
|
|
12
|
-
import { addLog, ErrorLog, SuccessLog } from '@mintlify/previewing';
|
|
11
|
+
import { input, search } from '@inquirer/prompts';
|
|
12
|
+
import { addLog, ErrorLog, InfoLog, SuccessLog } from '@mintlify/previewing';
|
|
13
13
|
import chalk from 'chalk';
|
|
14
14
|
import { Box, Text } from 'ink';
|
|
15
15
|
import open from 'open';
|
|
16
16
|
import { calculatePKCECodeChallenge, randomNonce, randomPKCECodeVerifier, randomState, } from 'openid-client';
|
|
17
17
|
import { startCallbackServer } from './callbackServer.js';
|
|
18
|
+
import { setConfigValue } from './config.js';
|
|
18
19
|
import { DASHBOARD_URL, STYTCH_CLIENT_ID, TOKEN_ENDPOINT } from './constants.js';
|
|
19
20
|
import { storeCredentials } from './keyring.js';
|
|
21
|
+
import { getCliSubdomains } from './status.js';
|
|
20
22
|
import { trackLoginAttempt, trackLoginFailed, trackLoginSuccess } from './telemetry/track.js';
|
|
21
23
|
export function login() {
|
|
22
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -80,5 +82,43 @@ export function login() {
|
|
|
80
82
|
yield storeCredentials(token.access_token, token.refresh_token);
|
|
81
83
|
void trackLoginSuccess();
|
|
82
84
|
addLog(_jsx(SuccessLog, { message: "logged in successfully" }));
|
|
85
|
+
yield promptSubdomainSelection(token.access_token);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function isPromptCancellationError(error) {
|
|
89
|
+
return error instanceof Error && error.name === 'ExitPromptError';
|
|
90
|
+
}
|
|
91
|
+
function promptSubdomainSelection(accessToken) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const subdomains = yield getCliSubdomains(accessToken);
|
|
94
|
+
if (subdomains.length === 0)
|
|
95
|
+
return;
|
|
96
|
+
if (subdomains.length === 1) {
|
|
97
|
+
yield setConfigValue('subdomain', subdomains[0]);
|
|
98
|
+
addLog(_jsx(InfoLog, { message: `default project set to ${subdomains[0]}` }));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
102
|
+
let chosen;
|
|
103
|
+
try {
|
|
104
|
+
chosen = yield search({
|
|
105
|
+
message: 'Select a default project',
|
|
106
|
+
source: (term) => {
|
|
107
|
+
const results = term
|
|
108
|
+
? subdomains.filter((s) => s.toLowerCase().includes(term.toLowerCase()))
|
|
109
|
+
: subdomains;
|
|
110
|
+
return results.map((s) => ({ name: s, value: s }));
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (isPromptCancellationError(error)) {
|
|
116
|
+
addLog(_jsx(InfoLog, { message: `No project set. To set a default project, run ${chalk.bold('mintlify config set subdomain <subdomain>')}` }));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
yield setConfigValue('subdomain', chosen);
|
|
122
|
+
addLog(_jsx(InfoLog, { message: `default project set to ${chosen}` }));
|
|
83
123
|
});
|
|
84
124
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { getConfigValue } from '../config.js';
|
|
11
|
+
import { getAccessToken } from '../keyring.js';
|
|
12
|
+
import { getCliSubdomains } from '../status.js';
|
|
13
|
+
export function subdomainMiddleware(argv) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
if (argv.subdomain)
|
|
16
|
+
return;
|
|
17
|
+
const fromConfig = getConfigValue('subdomain');
|
|
18
|
+
if (fromConfig) {
|
|
19
|
+
argv.subdomain = fromConfig;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const accessToken = yield getAccessToken();
|
|
23
|
+
if (!accessToken)
|
|
24
|
+
return;
|
|
25
|
+
const subdomains = yield getCliSubdomains(accessToken);
|
|
26
|
+
argv.subdomain = subdomains[0];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { getConfigValue } from '../config.js';
|
|
11
11
|
import { getVersions } from '../helpers.js';
|
|
12
|
-
import { trackCommand } from '
|
|
12
|
+
import { trackCommand } from '../telemetry/track.js';
|
|
13
13
|
const SCRAPE_SUBCOMMANDS = new Set(['page', 'site', 'openapi']);
|
|
14
14
|
export function getSanitizedCommandForTelemetry(_) {
|
|
15
15
|
const parts = _.filter((p) => typeof p === 'string');
|
package/bin/status.js
CHANGED
|
@@ -19,23 +19,22 @@ import { getAccessToken } from './keyring.js';
|
|
|
19
19
|
const StatusResponseSchema = z.object({
|
|
20
20
|
user: z.object({ email: z.string() }),
|
|
21
21
|
org: z.object({ name: z.string() }),
|
|
22
|
-
|
|
22
|
+
subdomains: z.array(z.string()).default([]),
|
|
23
23
|
});
|
|
24
|
-
export function
|
|
24
|
+
export function getCliSubdomains(accessToken) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
var _a;
|
|
27
26
|
try {
|
|
28
27
|
const res = yield fetch(`${API_URL}/api/cli/status`, {
|
|
29
28
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
30
29
|
});
|
|
31
30
|
if (!res.ok)
|
|
32
|
-
return
|
|
31
|
+
return [];
|
|
33
32
|
const json = yield res.json().catch(() => null);
|
|
34
33
|
const parsed = StatusResponseSchema.safeParse(json);
|
|
35
|
-
return parsed.success ?
|
|
34
|
+
return parsed.success ? parsed.data.subdomains : [];
|
|
36
35
|
}
|
|
37
|
-
catch (
|
|
38
|
-
return
|
|
36
|
+
catch (_a) {
|
|
37
|
+
return [];
|
|
39
38
|
}
|
|
40
39
|
});
|
|
41
40
|
}
|
|
@@ -59,9 +58,9 @@ export function status() {
|
|
|
59
58
|
addLog(_jsx(ErrorLog, { message: "unexpected response from server. please try again." }));
|
|
60
59
|
return;
|
|
61
60
|
}
|
|
62
|
-
const { user, org,
|
|
61
|
+
const { user, org, subdomains } = parsed.data;
|
|
63
62
|
const version = getCliVersion();
|
|
64
|
-
const subdomain = (_b = (_a = getConfigValue('subdomain')) !== null && _a !== void 0 ? _a :
|
|
63
|
+
const subdomain = (_b = (_a = getConfigValue('subdomain')) !== null && _a !== void 0 ? _a : subdomains[0]) !== null && _b !== void 0 ? _b : null;
|
|
65
64
|
addLog(_jsxs(Box, { flexDirection: "column", paddingY: 1, children: [version && (_jsxs(Box, { children: [_jsx(Box, { minWidth: 16, children: _jsx(Text, { dimColor: true, children: "Version" }) }), _jsx(Text, { children: version })] })), _jsxs(Box, { children: [_jsx(Box, { minWidth: 16, children: _jsx(Text, { dimColor: true, children: "Email" }) }), _jsx(Text, { children: user.email })] }), _jsxs(Box, { children: [_jsx(Box, { minWidth: 16, children: _jsx(Text, { dimColor: true, children: "Organization" }) }), _jsx(Text, { children: org.name })] }), subdomain && (_jsxs(Box, { children: [_jsx(Box, { minWidth: 16, children: _jsx(Text, { dimColor: true, children: "Subdomain" }) }), _jsx(Text, { children: subdomain })] }))] }));
|
|
66
65
|
}
|
|
67
66
|
catch (e) {
|