@mintlify/cli 4.0.1341 → 4.0.1343

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.
@@ -0,0 +1,90 @@
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { getRelativeRecordName } from '@mintlify/common';
12
+ import { addLog, ErrorLog, removeLastLog, SpinnerLog, SuccessLog } from '@mintlify/previewing';
13
+ import { Box, Text } from 'ink';
14
+ import { authenticatedFetch } from './authenticatedFetch.js';
15
+ import { getConfigValue } from './config.js';
16
+ import { API_URL, CUSTOM_DOMAIN_CNAME_TARGET } from './constants.js';
17
+ import { getAccessToken } from './keyring.js';
18
+ import { getCliSubdomains } from './status.js';
19
+ const DNS_POLL_INTERVAL_MS = 5000;
20
+ const DNS_POLL_MAX_ATTEMPTS = 3;
21
+ const DOMAIN_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/i;
22
+ export function addDomain(domain) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ var _a, _b, _c;
25
+ if (!DOMAIN_PATTERN.test(domain)) {
26
+ addLog(_jsx(ErrorLog, { message: `invalid domain "${domain}". Expected a bare hostname, e.g. docs.example.com` }));
27
+ return;
28
+ }
29
+ const accessToken = yield getAccessToken();
30
+ if (!accessToken) {
31
+ addLog(_jsx(ErrorLog, { message: "not logged in. Run `mint login` to authenticate." }));
32
+ return;
33
+ }
34
+ const subdomains = yield getCliSubdomains(accessToken);
35
+ const configuredSubdomain = getConfigValue('subdomain');
36
+ const subdomain = configuredSubdomain && subdomains.includes(configuredSubdomain)
37
+ ? configuredSubdomain
38
+ : subdomains[0];
39
+ if (!subdomain) {
40
+ addLog(_jsx(ErrorLog, { message: "no subdomain found. Run `mint status` to check your account." }));
41
+ return;
42
+ }
43
+ try {
44
+ const addRes = yield authenticatedFetch(`${API_URL}/api/cli/deployment/custom-domain/${subdomain}/${domain}`, {
45
+ method: 'POST',
46
+ headers: { 'Content-Type': 'application/json' },
47
+ body: JSON.stringify({ basePath: '' }),
48
+ });
49
+ if (!addRes.ok) {
50
+ const body = yield addRes.json().catch(() => ({}));
51
+ addLog(_jsx(ErrorLog, { message: `could not add domain: ${(_a = body.error) !== null && _a !== void 0 ? _a : 'unknown error'}` }));
52
+ return;
53
+ }
54
+ }
55
+ catch (_d) {
56
+ addLog(_jsx(ErrorLog, { message: "could not reach the server" }));
57
+ return;
58
+ }
59
+ const maxWaitSeconds = ((DNS_POLL_MAX_ATTEMPTS - 1) * DNS_POLL_INTERVAL_MS) / 1000;
60
+ addLog(_jsx(SpinnerLog, { message: `waiting for DNS records to generate (up to ${maxWaitSeconds}s)...` }));
61
+ let dnsRecords = [];
62
+ let recordsReady = false;
63
+ try {
64
+ for (let attempt = 0; attempt < DNS_POLL_MAX_ATTEMPTS; attempt++) {
65
+ const checkRes = yield authenticatedFetch(`${API_URL}/api/cli/deployment/custom-domain/${subdomain}/${domain}`);
66
+ if (checkRes.ok) {
67
+ const body = (yield checkRes.json());
68
+ dnsRecords = (_c = (_b = body.cloudflare) === null || _b === void 0 ? void 0 : _b.dnsRecords) !== null && _c !== void 0 ? _c : [];
69
+ const stillGenerating = dnsRecords.some((record) => record.value === 'loading');
70
+ if (dnsRecords.length > 0 && !stillGenerating) {
71
+ recordsReady = true;
72
+ break;
73
+ }
74
+ }
75
+ if (attempt < DNS_POLL_MAX_ATTEMPTS - 1) {
76
+ yield new Promise((resolve) => setTimeout(resolve, DNS_POLL_INTERVAL_MS));
77
+ }
78
+ }
79
+ }
80
+ catch (_e) {
81
+ removeLastLog();
82
+ addLog(_jsx(ErrorLog, { message: "domain added, but could not fetch DNS records" }));
83
+ return;
84
+ }
85
+ removeLastLog();
86
+ const readyTxtRecords = dnsRecords.filter((record) => record.type === 'TXT' && record.value !== 'loading');
87
+ addLog(_jsx(SuccessLog, { message: `domain ${domain} added` }));
88
+ addLog(_jsxs(Box, { flexDirection: "column", gap: 1, paddingY: 1, children: [_jsx(Text, { bold: true, children: "Add these DNS records with your domain provider:" }), _jsxs(Box, { flexDirection: "column", paddingLeft: 3, children: [readyTxtRecords.map((record) => (_jsxs(Text, { children: ["TXT ", getRelativeRecordName(record.domain, domain), " \u2192 ", record.value] }, record.domain))), _jsxs(Text, { children: ["CNAME ", getRelativeRecordName(domain, domain), " \u2192 ", CUSTOM_DOMAIN_CNAME_TARGET] })] }), _jsx(Text, { dimColor: true, children: "Add the TXT records first; add the CNAME once they're validated." }), !recordsReady && (_jsx(Text, { dimColor: true, children: "Some TXT records are still being generated. Check the dashboard in a moment for the rest." }))] }));
89
+ });
90
+ }
package/bin/cli.js CHANGED
@@ -16,6 +16,7 @@ import path from 'path';
16
16
  import yargs from 'yargs';
17
17
  import { hideBin } from 'yargs/helpers';
18
18
  import { accessibilityCheck } from './accessibilityCheck.js';
19
+ import { addDomain } from './addDomain.js';
19
20
  import { comingSoon } from './comingSoon.js';
20
21
  import { setTelemetryEnabled } from './config.js';
21
22
  import { getConfigValue, setConfigValue, clearConfigValue } from './config.js';
@@ -364,6 +365,14 @@ export const cli = ({ packageName = 'mint' }) => {
364
365
  email: argv.email,
365
366
  });
366
367
  yield terminate(0);
368
+ }))
369
+ .command('add-domain <domain>', 'Add a custom domain to your deployment', (yargs) => yargs.positional('domain', {
370
+ type: 'string',
371
+ demandOption: true,
372
+ description: 'The custom domain to add (e.g. docs.example.com)',
373
+ }), (argv) => __awaiter(void 0, void 0, void 0, function* () {
374
+ yield addDomain(argv.domain);
375
+ yield terminate(0);
367
376
  }))
368
377
  .command('config', 'Manage CLI configuration', (yargs) => yargs
369
378
  .command('set <key> <value>', 'Set a configuration value', (yargs) => yargs
package/bin/constants.js CHANGED
@@ -17,3 +17,4 @@ const PROD_TOKEN_ENDPOINT = 'https://api.stytch.com/v1/public/project-live-731b7
17
17
  const PROD_STYTCH_CLIENT_ID = 'connected-app-live-d813eedd-dbb0-434b-a1f9-2ce69e5efc49';
18
18
  export const TOKEN_ENDPOINT = IS_LOCAL_BUILD ? DEV_TOKEN_ENDPOINT : PROD_TOKEN_ENDPOINT;
19
19
  export const STYTCH_CLIENT_ID = IS_LOCAL_BUILD ? DEV_STYTCH_CLIENT_ID : PROD_STYTCH_CLIENT_ID;
20
+ export const CUSTOM_DOMAIN_CNAME_TARGET = 'cname.mintlify.builders';