@mintlify/cli 4.0.1812 → 4.1.1

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.
Files changed (274) hide show
  1. package/dist/assets/export-scripts/README.classic.md +15 -0
  2. package/dist/assets/export-scripts/README.md +14 -0
  3. package/dist/assets/export-scripts/serve.js +114 -0
  4. package/dist/assets/export-scripts/start-docs.bat +10 -0
  5. package/dist/assets/export-scripts/start-docs.sh +9 -0
  6. package/dist/assets/og/Inter-Bold.ttf +0 -0
  7. package/dist/assets/og/Inter-Medium.ttf +0 -0
  8. package/dist/assets/og/Inter-Regular.ttf +0 -0
  9. package/dist/assets/og/Inter-SemiBold.ttf +0 -0
  10. package/dist/assets/og/PaperMono-Regular.ttf +0 -0
  11. package/dist/assets/og/index_bg.wasm +0 -0
  12. package/dist/assets/openChrome.applescript +94 -0
  13. package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
  14. package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
  15. package/dist/assets/socket.io/socket.io.js +4907 -0
  16. package/dist/assets/socket.io/socket.io.js.map +1 -0
  17. package/dist/assets/socket.io/socket.io.min.js +7 -0
  18. package/dist/assets/socket.io/socket.io.min.js.map +1 -0
  19. package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
  20. package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
  21. package/dist/assets/xdg-open +1066 -0
  22. package/dist/assets/yargs-locales/be.json +46 -0
  23. package/dist/assets/yargs-locales/cs.json +51 -0
  24. package/dist/assets/yargs-locales/de.json +46 -0
  25. package/dist/assets/yargs-locales/en.json +55 -0
  26. package/dist/assets/yargs-locales/es.json +46 -0
  27. package/dist/assets/yargs-locales/fi.json +49 -0
  28. package/dist/assets/yargs-locales/fr.json +53 -0
  29. package/dist/assets/yargs-locales/hi.json +49 -0
  30. package/dist/assets/yargs-locales/hu.json +46 -0
  31. package/dist/assets/yargs-locales/id.json +50 -0
  32. package/dist/assets/yargs-locales/it.json +46 -0
  33. package/dist/assets/yargs-locales/ja.json +51 -0
  34. package/dist/assets/yargs-locales/ko.json +49 -0
  35. package/dist/assets/yargs-locales/nb.json +44 -0
  36. package/dist/assets/yargs-locales/nl.json +49 -0
  37. package/dist/assets/yargs-locales/nn.json +44 -0
  38. package/dist/assets/yargs-locales/pirate.json +13 -0
  39. package/dist/assets/yargs-locales/pl.json +49 -0
  40. package/dist/assets/yargs-locales/pt.json +45 -0
  41. package/dist/assets/yargs-locales/pt_BR.json +48 -0
  42. package/dist/assets/yargs-locales/ru.json +51 -0
  43. package/dist/assets/yargs-locales/th.json +46 -0
  44. package/dist/assets/yargs-locales/tr.json +48 -0
  45. package/dist/assets/yargs-locales/uk_UA.json +51 -0
  46. package/dist/assets/yargs-locales/uz.json +52 -0
  47. package/dist/assets/yargs-locales/zh_CN.json +48 -0
  48. package/dist/assets/yargs-locales/zh_TW.json +51 -0
  49. package/dist/converter-d8O3xkdU.js +102 -0
  50. package/dist/devtools-CGNZQKFV.js +24 -0
  51. package/dist/index.js +8 -0
  52. package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
  53. package/dist/schemas-CBsmCNpK.js +372 -0
  54. package/dist/start.js +2310 -0
  55. package/package.json +43 -36
  56. package/.oxlintrc.json +0 -5
  57. package/.prettierignore +0 -2
  58. package/.turbo/turbo-build.log +0 -1
  59. package/CONTRIBUTING.md +0 -45
  60. package/__test__/agent-auth.test.ts +0 -114
  61. package/__test__/agent-claim.test.ts +0 -164
  62. package/__test__/agent-credentials.test.ts +0 -149
  63. package/__test__/agent-deployment.test.ts +0 -106
  64. package/__test__/agent-setup-config.test.ts +0 -324
  65. package/__test__/agent-setup.test.ts +0 -207
  66. package/__test__/agent.test.ts +0 -64
  67. package/__test__/analytics/client.test.ts +0 -180
  68. package/__test__/analytics/dates.test.ts +0 -12
  69. package/__test__/analytics/filters.test.ts +0 -116
  70. package/__test__/analytics/format.test.ts +0 -137
  71. package/__test__/authenticatedFetch.test.ts +0 -182
  72. package/__test__/brokenLinks.test.ts +0 -283
  73. package/__test__/checkPort.test.ts +0 -92
  74. package/__test__/deploy-github-actions.test.ts +0 -202
  75. package/__test__/deploy-github-setup.test.ts +0 -240
  76. package/__test__/deploy-instructions.test.ts +0 -155
  77. package/__test__/deploy.test.ts +0 -202
  78. package/__test__/feedback.test.ts +0 -34
  79. package/__test__/foreignSyntax.test.ts +0 -73
  80. package/__test__/format.test.ts +0 -72
  81. package/__test__/helpers.test.ts +0 -52
  82. package/__test__/init.test.ts +0 -119
  83. package/__test__/instructions.test.ts +0 -53
  84. package/__test__/keyring.test.ts +0 -82
  85. package/__test__/mdxAccessibility.test.ts +0 -81
  86. package/__test__/migrate.test.ts +0 -186
  87. package/__test__/openApiCheck.test.ts +0 -185
  88. package/__test__/pathValidation.test.ts +0 -25
  89. package/__test__/resolveFiles.test.ts +0 -70
  90. package/__test__/sessionId.test.ts +0 -46
  91. package/__test__/signup.test.ts +0 -36
  92. package/__test__/update.test.ts +0 -117
  93. package/__test__/utils.ts +0 -25
  94. package/__test__/validateCommand.test.ts +0 -647
  95. package/__test__/validateEngine.test.ts +0 -245
  96. package/__test__/validateRules.test.ts +0 -1275
  97. package/__test__/welcome.test.ts +0 -15
  98. package/__test__/workflows/client.test.ts +0 -126
  99. package/bin/accessibility.js +0 -111
  100. package/bin/accessibilityCheck.js +0 -82
  101. package/bin/addDomain.js +0 -130
  102. package/bin/agent-auth.js +0 -104
  103. package/bin/agent-claim.js +0 -97
  104. package/bin/agent-credentials.js +0 -124
  105. package/bin/agent-deployment.js +0 -96
  106. package/bin/agent-http.js +0 -45
  107. package/bin/agent-setup-config.js +0 -141
  108. package/bin/agent-setup.js +0 -146
  109. package/bin/agent.js +0 -42
  110. package/bin/analytics/client.js +0 -60
  111. package/bin/analytics/dates.js +0 -6
  112. package/bin/analytics/filters.js +0 -27
  113. package/bin/analytics/format.js +0 -13
  114. package/bin/analytics/index.js +0 -496
  115. package/bin/analytics/output.js +0 -75
  116. package/bin/analytics/types.js +0 -1
  117. package/bin/authenticatedFetch.js +0 -46
  118. package/bin/brokenLinks.js +0 -122
  119. package/bin/callbackServer.js +0 -65
  120. package/bin/cli.js +0 -813
  121. package/bin/comingSoon.js +0 -26
  122. package/bin/config.js +0 -78
  123. package/bin/constants.js +0 -16
  124. package/bin/deploy-base.js +0 -20
  125. package/bin/deploy-github-actions.js +0 -102
  126. package/bin/deploy-github-setup.js +0 -165
  127. package/bin/deploy-instructions.js +0 -71
  128. package/bin/deploy.js +0 -123
  129. package/bin/feedback.js +0 -36
  130. package/bin/format.js +0 -121
  131. package/bin/helpers.js +0 -238
  132. package/bin/idToken.js +0 -14
  133. package/bin/index.js +0 -102
  134. package/bin/init.js +0 -182
  135. package/bin/instructions.js +0 -101
  136. package/bin/keyring.js +0 -78
  137. package/bin/login.js +0 -123
  138. package/bin/logout.js +0 -18
  139. package/bin/mdxAccessibility.js +0 -113
  140. package/bin/mdxLinter.js +0 -55
  141. package/bin/middlewares/subdomainMiddleware.js +0 -28
  142. package/bin/middlewares/telemetryMiddleware.js +0 -61
  143. package/bin/migrate.js +0 -54
  144. package/bin/og.js +0 -145
  145. package/bin/openApiCheck.js +0 -99
  146. package/bin/resolveFiles.js +0 -114
  147. package/bin/score/client.js +0 -40
  148. package/bin/score/index.js +0 -211
  149. package/bin/score/types.js +0 -1
  150. package/bin/signup.js +0 -118
  151. package/bin/start.js +0 -36
  152. package/bin/status.js +0 -106
  153. package/bin/telemetry/client.js +0 -53
  154. package/bin/telemetry/distinctId.js +0 -68
  155. package/bin/telemetry/sessionId.js +0 -36
  156. package/bin/telemetry/track.js +0 -149
  157. package/bin/templates.js +0 -127
  158. package/bin/tokenRefresh.js +0 -50
  159. package/bin/tsconfig.build.tsbuildinfo +0 -1
  160. package/bin/update.js +0 -65
  161. package/bin/validate/command.js +0 -127
  162. package/bin/validate/engine.js +0 -154
  163. package/bin/validate/files.js +0 -163
  164. package/bin/validate/mdx.js +0 -238
  165. package/bin/validate/output.js +0 -44
  166. package/bin/validate/report.js +0 -11
  167. package/bin/validate/rules/build.js +0 -102
  168. package/bin/validate/rules/content/duplicateH1.js +0 -57
  169. package/bin/validate/rules/content/foreignSyntax.js +0 -120
  170. package/bin/validate/rules/content/katex.js +0 -34
  171. package/bin/validate/rules/content/missingSnippet.js +0 -34
  172. package/bin/validate/rules/content/undefinedVariable.js +0 -13
  173. package/bin/validate/rules/content/unknownComponent.js +0 -121
  174. package/bin/validate/rules/content/voidTags.js +0 -38
  175. package/bin/validate/rules/index.js +0 -21
  176. package/bin/validate/rules/openapi.js +0 -50
  177. package/bin/validate/rules/parseError.js +0 -7
  178. package/bin/validate/site.js +0 -57
  179. package/bin/validate/types.js +0 -1
  180. package/bin/vendor/converter.js +0 -30882
  181. package/bin/welcome.js +0 -108
  182. package/bin/workflows/client.js +0 -34
  183. package/bin/workflows/index.js +0 -269
  184. package/bin/workflows/types.js +0 -11
  185. package/scripts/bundle-converter.mjs +0 -26
  186. package/scripts/generate-logo.mjs +0 -79
  187. package/src/accessibility.ts +0 -180
  188. package/src/accessibilityCheck.tsx +0 -150
  189. package/src/addDomain.tsx +0 -206
  190. package/src/agent-auth.ts +0 -119
  191. package/src/agent-claim.ts +0 -124
  192. package/src/agent-credentials.ts +0 -104
  193. package/src/agent-deployment.ts +0 -116
  194. package/src/agent-http.ts +0 -34
  195. package/src/agent-setup-config.ts +0 -144
  196. package/src/agent-setup.ts +0 -165
  197. package/src/agent.ts +0 -56
  198. package/src/analytics/client.ts +0 -153
  199. package/src/analytics/dates.ts +0 -6
  200. package/src/analytics/filters.ts +0 -50
  201. package/src/analytics/format.ts +0 -13
  202. package/src/analytics/index.tsx +0 -599
  203. package/src/analytics/output.ts +0 -99
  204. package/src/analytics/types.ts +0 -145
  205. package/src/authenticatedFetch.ts +0 -42
  206. package/src/brokenLinks.tsx +0 -152
  207. package/src/callbackServer.ts +0 -64
  208. package/src/cli.tsx +0 -1105
  209. package/src/comingSoon.tsx +0 -29
  210. package/src/config.ts +0 -75
  211. package/src/constants.ts +0 -28
  212. package/src/deploy-base.ts +0 -18
  213. package/src/deploy-github-actions.ts +0 -139
  214. package/src/deploy-github-setup.ts +0 -189
  215. package/src/deploy-instructions.ts +0 -76
  216. package/src/deploy.ts +0 -165
  217. package/src/feedback.tsx +0 -31
  218. package/src/format.tsx +0 -82
  219. package/src/helpers.tsx +0 -279
  220. package/src/idToken.ts +0 -17
  221. package/src/index.ts +0 -109
  222. package/src/init.tsx +0 -237
  223. package/src/instructions.ts +0 -99
  224. package/src/keyring.ts +0 -65
  225. package/src/login.tsx +0 -166
  226. package/src/logout.tsx +0 -8
  227. package/src/mdxAccessibility.ts +0 -134
  228. package/src/mdxLinter.tsx +0 -88
  229. package/src/middlewares/subdomainMiddleware.ts +0 -20
  230. package/src/middlewares/telemetryMiddleware.ts +0 -55
  231. package/src/migrate.ts +0 -76
  232. package/src/og.tsx +0 -185
  233. package/src/openApiCheck.tsx +0 -125
  234. package/src/resolveFiles.ts +0 -101
  235. package/src/score/client.ts +0 -36
  236. package/src/score/index.tsx +0 -205
  237. package/src/score/types.ts +0 -15
  238. package/src/signup.tsx +0 -172
  239. package/src/start.ts +0 -27
  240. package/src/status.tsx +0 -129
  241. package/src/telemetry/client.ts +0 -46
  242. package/src/telemetry/distinctId.ts +0 -70
  243. package/src/telemetry/sessionId.ts +0 -40
  244. package/src/telemetry/track.ts +0 -163
  245. package/src/templates.tsx +0 -143
  246. package/src/tokenRefresh.ts +0 -53
  247. package/src/update.tsx +0 -89
  248. package/src/validate/command.tsx +0 -135
  249. package/src/validate/engine.ts +0 -210
  250. package/src/validate/files.ts +0 -249
  251. package/src/validate/mdx.ts +0 -290
  252. package/src/validate/output.tsx +0 -76
  253. package/src/validate/report.ts +0 -40
  254. package/src/validate/rules/build.ts +0 -146
  255. package/src/validate/rules/content/duplicateH1.ts +0 -78
  256. package/src/validate/rules/content/foreignSyntax.ts +0 -144
  257. package/src/validate/rules/content/katex.ts +0 -33
  258. package/src/validate/rules/content/missingSnippet.ts +0 -36
  259. package/src/validate/rules/content/undefinedVariable.ts +0 -20
  260. package/src/validate/rules/content/unknownComponent.ts +0 -130
  261. package/src/validate/rules/content/voidTags.ts +0 -43
  262. package/src/validate/rules/index.ts +0 -23
  263. package/src/validate/rules/openapi.ts +0 -59
  264. package/src/validate/rules/parseError.ts +0 -9
  265. package/src/validate/site.ts +0 -53
  266. package/src/validate/types.ts +0 -102
  267. package/src/vendor/converter.ts +0 -1
  268. package/src/welcome.ts +0 -154
  269. package/src/workflows/client.ts +0 -39
  270. package/src/workflows/index.tsx +0 -287
  271. package/src/workflows/types.ts +0 -73
  272. package/tsconfig.build.json +0 -4
  273. package/tsconfig.json +0 -10
  274. package/vitest.config.ts +0 -9
@@ -1,46 +0,0 @@
1
- import { PostHog } from 'posthog-node';
2
-
3
- const TELEMETRY_ASYNC_TIMEOUT_MS = 10_000;
4
-
5
- const POSTHOG_API_KEY = 'phc_eNuN6Ojnk9O7uWfC17z12AK85fNR0BY6IiGVy0Gfwzw';
6
- const POSTHOG_HOST = 'https://ph.mintlify.com';
7
-
8
- let client: PostHog | null = null;
9
- let pendingWork: Promise<void> = Promise.resolve();
10
-
11
- export function getPostHogClient(): PostHog {
12
- if (!client) {
13
- client = new PostHog(POSTHOG_API_KEY, {
14
- host: POSTHOG_HOST,
15
- });
16
- }
17
- return client;
18
- }
19
-
20
- export function deferShutdownUntil(work: Promise<void>): void {
21
- pendingWork = Promise.allSettled([pendingWork, work]).then(() => undefined);
22
- }
23
-
24
- export async function shutdownPostHog(): Promise<void> {
25
- try {
26
- await Promise.race([
27
- pendingWork,
28
- new Promise<void>((resolve) => {
29
- const t = setTimeout(resolve, TELEMETRY_ASYNC_TIMEOUT_MS);
30
- t.unref();
31
- }),
32
- ]);
33
- } catch {}
34
-
35
- if (!client) return;
36
- try {
37
- await Promise.race([
38
- client.shutdown(),
39
- new Promise<void>((resolve) => {
40
- const t = setTimeout(resolve, TELEMETRY_ASYNC_TIMEOUT_MS);
41
- t.unref();
42
- }),
43
- ]);
44
- } catch {}
45
- client = null;
46
- }
@@ -1,70 +0,0 @@
1
- import crypto from 'crypto';
2
- import fs from 'fs';
3
- import os from 'os';
4
- import path from 'path';
5
-
6
- import { CONFIG_DIR } from '../constants.js';
7
-
8
- const ID_FILE = path.join(CONFIG_DIR, 'anonymous-id');
9
- const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
10
-
11
- function readValidIdFromFile(): string | null {
12
- try {
13
- const raw = fs.readFileSync(ID_FILE, 'utf-8').trim();
14
- if (UUID_RE.test(raw)) return raw;
15
- } catch {}
16
- return null;
17
- }
18
-
19
- function stableMachineDistinctId(): string {
20
- const h = crypto.createHash('sha256');
21
- h.update(os.hostname());
22
- h.update('\0');
23
- h.update(os.homedir());
24
- h.update('\0');
25
- h.update(process.env.USER ?? process.env.USERNAME ?? '');
26
- const hex = h.digest('hex').slice(0, 32);
27
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
28
- }
29
-
30
- function tryPersistId(id: string): void {
31
- fs.mkdirSync(path.dirname(ID_FILE), { recursive: true });
32
- fs.writeFileSync(ID_FILE, id, { flag: 'wx' });
33
- }
34
-
35
- let createdThisRun = false;
36
-
37
- export function isFirstRun(): boolean {
38
- getDistinctId();
39
- return createdThisRun;
40
- }
41
-
42
- export function getDistinctId(): string {
43
- const existing = readValidIdFromFile();
44
- if (existing) return existing;
45
-
46
- const randomId = crypto.randomUUID();
47
-
48
- try {
49
- tryPersistId(randomId);
50
- createdThisRun = true;
51
- return readValidIdFromFile() ?? randomId;
52
- } catch (err) {
53
- const code = (err as NodeJS.ErrnoException).code;
54
- if (code === 'EEXIST') {
55
- const concurrent = readValidIdFromFile();
56
- if (concurrent) return concurrent;
57
- try {
58
- fs.writeFileSync(ID_FILE, randomId);
59
- } catch {}
60
- return readValidIdFromFile() ?? randomId;
61
- }
62
- }
63
-
64
- const stable = stableMachineDistinctId();
65
- try {
66
- fs.mkdirSync(path.dirname(ID_FILE), { recursive: true });
67
- fs.writeFileSync(ID_FILE, stable);
68
- } catch {}
69
- return readValidIdFromFile() ?? stable;
70
- }
@@ -1,40 +0,0 @@
1
- import crypto from 'crypto';
2
- import fs from 'fs';
3
- import path from 'path';
4
-
5
- import { CONFIG_DIR } from '../constants.js';
6
-
7
- const SESSION_FILE = path.join(CONFIG_DIR, 'telemetry-session.json');
8
- const SESSION_IDLE_MS = 30 * 60 * 1000;
9
-
10
- let current: string | undefined;
11
-
12
- function uuidv7(now: number): string {
13
- const bytes = crypto.randomBytes(16);
14
- bytes.writeUIntBE(now, 0, 6);
15
- bytes[6] = (bytes[6]! & 0x0f) | 0x70;
16
- bytes[8] = (bytes[8]! & 0x3f) | 0x80;
17
- const hex = bytes.toString('hex');
18
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
19
- }
20
-
21
- function readSession(): { id: string; lastSeenAt: number } | null {
22
- try {
23
- const { id, lastSeenAt } = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
24
- return typeof id === 'string' && typeof lastSeenAt === 'number' ? { id, lastSeenAt } : null;
25
- } catch {
26
- return null;
27
- }
28
- }
29
-
30
- export function getSessionId(now = Date.now()): string {
31
- if (!current) {
32
- const saved = readSession();
33
- current = saved && now - saved.lastSeenAt < SESSION_IDLE_MS ? saved.id : uuidv7(now);
34
- }
35
- try {
36
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
37
- fs.writeFileSync(SESSION_FILE, JSON.stringify({ id: current, lastSeenAt: now }));
38
- } catch {}
39
- return current;
40
- }
@@ -1,163 +0,0 @@
1
- import os from 'os';
2
-
3
- import { detectAgent, isCI } from '../agent.js';
4
- import { isTelemetryEnabled } from '../config.js';
5
- import { TELEMETRY_ASYNC_TIMEOUT_MS, TELEMETRY_IDENTITY_TIMEOUT_MS } from '../constants.js';
6
- import { getVersions } from '../helpers.js';
7
- import { getAccessToken, getUserEmail, storeUserEmail } from '../keyring.js';
8
- import { fetchCliStatus } from '../status.js';
9
- import { deferShutdownUntil, getPostHogClient } from './client.js';
10
- import { getDistinctId, isFirstRun } from './distinctId.js';
11
- import { getSessionId } from './sessionId.js';
12
-
13
- export interface TrackCommandOptions {
14
- command: string;
15
- cliVersion?: string;
16
- subdomain?: string;
17
- }
18
-
19
- function getEnvironmentProperties(): Record<string, unknown> {
20
- const agent = detectAgent();
21
- return {
22
- os: os.platform(),
23
- arch: os.arch(),
24
- node_version: process.version,
25
- is_ai_agent: agent !== undefined,
26
- ai_agent: agent,
27
- is_ci: isCI(),
28
- is_tty: Boolean(process.stdin.isTTY),
29
- is_first_run: isFirstRun(),
30
- $session_id: getSessionId(),
31
- };
32
- }
33
-
34
- async function captureWithTimeout(
35
- event: string,
36
- properties: Record<string, unknown>
37
- ): Promise<void> {
38
- await Promise.race([
39
- getPostHogClient()
40
- .captureImmediate({
41
- distinctId: getDistinctId(),
42
- event,
43
- properties,
44
- })
45
- .catch(() => {}),
46
- new Promise<void>((resolve) => {
47
- const t = setTimeout(resolve, TELEMETRY_ASYNC_TIMEOUT_MS);
48
- t.unref();
49
- }),
50
- ]);
51
- }
52
-
53
- async function getIdentity(): Promise<{ loggedIn: boolean; email: string | null }> {
54
- try {
55
- const [accessToken, storedEmail] = await Promise.all([
56
- getAccessToken(),
57
- getUserEmail().catch(() => null),
58
- ]);
59
- if (!accessToken) return { loggedIn: false, email: null };
60
- if (storedEmail) return { loggedIn: true, email: storedEmail };
61
-
62
- const status = await fetchCliStatus(AbortSignal.timeout(TELEMETRY_IDENTITY_TIMEOUT_MS));
63
- if (!status.ok) return { loggedIn: true, email: null };
64
-
65
- const email = status.status.user.email;
66
- await storeUserEmail(email).catch(() => {});
67
- return { loggedIn: true, email };
68
- } catch {
69
- return { loggedIn: false, email: null };
70
- }
71
- }
72
-
73
- async function getIdentityProperties(): Promise<Record<string, unknown>> {
74
- const { loggedIn, email } = await getIdentity();
75
- return { is_logged_in: loggedIn, ...(email ? { email, $set: { email } } : {}) };
76
- }
77
-
78
- export async function trackCommand({
79
- command,
80
- cliVersion,
81
- subdomain,
82
- }: TrackCommandOptions): Promise<void> {
83
- if (!isTelemetryEnabled()) return;
84
-
85
- const work = (async () => {
86
- try {
87
- await captureWithTimeout('cli.command.executed', {
88
- command,
89
- cli_version: cliVersion,
90
- ...getEnvironmentProperties(),
91
- ...(await getIdentityProperties()),
92
- subdomain,
93
- });
94
- } catch {}
95
- })();
96
-
97
- deferShutdownUntil(work);
98
- await work;
99
- }
100
-
101
- async function trackLoginEvent(event: string, extra?: Record<string, unknown>): Promise<void> {
102
- if (!isTelemetryEnabled()) return;
103
-
104
- const work = (async () => {
105
- try {
106
- const { cli: cliVersion } = getVersions();
107
- await captureWithTimeout(event, {
108
- ...extra,
109
- cli_version: cliVersion,
110
- ...getEnvironmentProperties(),
111
- ...(await getIdentityProperties()),
112
- });
113
- } catch {}
114
- })();
115
- deferShutdownUntil(work);
116
- await work;
117
- }
118
-
119
- export async function trackLoginAttempt(): Promise<void> {
120
- return trackLoginEvent('cli.login.attempted');
121
- }
122
-
123
- export async function trackLoginSuccess(): Promise<void> {
124
- return trackLoginEvent('cli.login.succeeded');
125
- }
126
-
127
- export async function trackLoginFailed(reason: string): Promise<void> {
128
- return trackLoginEvent('cli.login.failed', { reason });
129
- }
130
-
131
- export async function trackEvent(
132
- event: string,
133
- properties?: Record<string, unknown>
134
- ): Promise<void> {
135
- if (!isTelemetryEnabled()) return;
136
-
137
- const work = (async () => {
138
- try {
139
- const { cli: cliVersion } = getVersions();
140
- await captureWithTimeout(event, {
141
- ...properties,
142
- cli_version: cliVersion,
143
- ...getEnvironmentProperties(),
144
- ...(await getIdentityProperties()),
145
- });
146
- } catch {}
147
- })();
148
- deferShutdownUntil(work);
149
- await work;
150
- }
151
-
152
- export async function trackTelemetryPreferenceChange(options: { enabled: boolean }): Promise<void> {
153
- if (process.env.CLI_TEST_MODE === 'true') return;
154
-
155
- try {
156
- const { cli: cliVersion } = getVersions();
157
- await captureWithTimeout('cli.telemetry.preference_changed', {
158
- enabled: options.enabled,
159
- cli_version: cliVersion,
160
- ...getEnvironmentProperties(),
161
- });
162
- } catch {}
163
- }
package/src/templates.tsx DELETED
@@ -1,143 +0,0 @@
1
- import { select } from '@inquirer/prompts';
2
- import { addLog, SpinnerLog, removeLastLog } from '@mintlify/previewing';
3
- import AdmZip from 'adm-zip';
4
- import fse from 'fs-extra';
5
- import path from 'path';
6
-
7
- const TEMPLATES_REPO_OWNER = 'mintlify';
8
- const TEMPLATES_REPO_NAME = 'templates';
9
- const TEMPLATES_REPO_BRANCH = 'main';
10
-
11
- interface GitHubContentEntry {
12
- name: string;
13
- type: 'file' | 'dir';
14
- path: string;
15
- }
16
-
17
- export async function fetchAvailableTemplates(): Promise<string[]> {
18
- const url = `https://api.github.com/repos/${TEMPLATES_REPO_OWNER}/${TEMPLATES_REPO_NAME}/contents/?ref=${TEMPLATES_REPO_BRANCH}`;
19
- const response = await fetch(url, {
20
- headers: { Accept: 'application/vnd.github.v3+json' },
21
- });
22
-
23
- if (!response.ok) {
24
- throw new Error(`Failed to fetch templates: ${response.status} ${response.statusText}`);
25
- }
26
-
27
- const entries: GitHubContentEntry[] = (await response.json()) as GitHubContentEntry[];
28
- return entries.filter((entry) => entry.type === 'dir').map((entry) => entry.name);
29
- }
30
-
31
- export async function validateTemplateName(templateName: string): Promise<string> {
32
- if (
33
- !templateName ||
34
- templateName === '.' ||
35
- templateName === '..' ||
36
- templateName.includes('/')
37
- ) {
38
- throw new Error(`Invalid template name: "${templateName}".`);
39
- }
40
-
41
- const url = `https://api.github.com/repos/${TEMPLATES_REPO_OWNER}/${TEMPLATES_REPO_NAME}/contents/${encodeURIComponent(templateName)}?ref=${TEMPLATES_REPO_BRANCH}`;
42
- const response = await fetch(url, {
43
- headers: { Accept: 'application/vnd.github.v3+json' },
44
- });
45
-
46
- if (!response.ok) {
47
- const available = await fetchAvailableTemplates().catch(() => []);
48
- const suggestion = available.length > 0 ? ` Available templates: ${available.join(', ')}` : '';
49
- throw new Error(
50
- `Template "${templateName}" not found in ${TEMPLATES_REPO_OWNER}/${TEMPLATES_REPO_NAME}.${suggestion}`
51
- );
52
- }
53
-
54
- const entries: GitHubContentEntry[] = (await response.json()) as GitHubContentEntry[];
55
- const hasDocsJson = entries.some((entry) => entry.name === 'docs.json');
56
- if (!hasDocsJson) {
57
- throw new Error(
58
- `Template "${templateName}" is not a valid Mintlify template (missing docs.json).`
59
- );
60
- }
61
-
62
- return templateName;
63
- }
64
-
65
- export async function promptForTemplate(): Promise<string> {
66
- addLog(<SpinnerLog message="fetching available templates..." />);
67
- let templateNames: string[];
68
- try {
69
- templateNames = await fetchAvailableTemplates();
70
- } catch {
71
- removeLastLog();
72
- throw new Error(
73
- 'Failed to fetch templates. Please check your network connection and try again.'
74
- );
75
- }
76
- removeLastLog();
77
-
78
- if (templateNames.length === 0) {
79
- throw new Error('No templates are currently available.');
80
- }
81
-
82
- return select({
83
- message: 'Choose a template',
84
- choices: templateNames.map((t) => ({ name: t, value: t })),
85
- });
86
- }
87
-
88
- export async function installFromTemplate(
89
- installDir: string,
90
- templateName: string,
91
- projectName?: string,
92
- theme?: string
93
- ): Promise<void> {
94
- const zipPath = path.join(installDir, '__template__.zip');
95
- const extractDir = path.join(installDir, '__template_extract__');
96
-
97
- try {
98
- addLog(<SpinnerLog message={`downloading template "${templateName}"...`} />);
99
- try {
100
- const zipUrl = `https://github.com/${TEMPLATES_REPO_OWNER}/${TEMPLATES_REPO_NAME}/archive/refs/heads/${TEMPLATES_REPO_BRANCH}.zip`;
101
- const response = await fetch(zipUrl);
102
- if (!response.ok) {
103
- throw new Error(`Failed to download templates archive: ${response.status}`);
104
- }
105
- const buffer = await response.arrayBuffer();
106
- await fse.writeFile(zipPath, Buffer.from(buffer));
107
- } finally {
108
- removeLastLog();
109
- }
110
-
111
- addLog(<SpinnerLog message="extracting template..." />);
112
- try {
113
- const zip = new AdmZip(zipPath);
114
- zip.extractAllTo(extractDir, true);
115
- } finally {
116
- removeLastLog();
117
- }
118
-
119
- const repoRoot = path.join(extractDir, `${TEMPLATES_REPO_NAME}-${TEMPLATES_REPO_BRANCH}`);
120
- const templateDir = path.join(repoRoot, templateName);
121
-
122
- if (!(await fse.pathExists(templateDir))) {
123
- throw new Error(`Template directory "${templateName}" not found in the downloaded archive.`);
124
- }
125
-
126
- await fse.copy(templateDir, installDir, { overwrite: true });
127
- } finally {
128
- await fse.remove(zipPath).catch(() => {});
129
- await fse.remove(extractDir).catch(() => {});
130
- }
131
-
132
- const docsJsonPath = path.join(installDir, 'docs.json');
133
- if (await fse.pathExists(docsJsonPath)) {
134
- const docsConfig = await fse.readJson(docsJsonPath);
135
- if (projectName) {
136
- docsConfig.name = projectName;
137
- }
138
- if (theme) {
139
- docsConfig.theme = theme;
140
- }
141
- await fse.writeJson(docsJsonPath, docsConfig, { spaces: 2 });
142
- }
143
- }
@@ -1,53 +0,0 @@
1
- import { TOKEN_ENDPOINT } from './constants.js';
2
- import { getEmailFromIdToken } from './idToken.js';
3
- import { getRefreshToken, storeCredentials } from './keyring.js';
4
-
5
- interface TokenResponse {
6
- access_token: string;
7
- id_token?: string;
8
- refresh_token: string;
9
- token_type: 'bearer';
10
- expires_in: number;
11
- }
12
-
13
- let inflightRefresh: Promise<string | null> | null = null;
14
-
15
- export async function refreshAccessToken(): Promise<string | null> {
16
- if (inflightRefresh) return inflightRefresh;
17
-
18
- inflightRefresh = doRefresh().finally(() => {
19
- inflightRefresh = null;
20
- });
21
-
22
- return inflightRefresh;
23
- }
24
-
25
- async function doRefresh(): Promise<string | null> {
26
- try {
27
- const refreshToken = await getRefreshToken();
28
- if (!refreshToken) return null;
29
-
30
- const res = await fetch(TOKEN_ENDPOINT, {
31
- method: 'POST',
32
- headers: { 'Content-Type': 'application/json' },
33
- body: JSON.stringify({
34
- grant_type: 'refresh_token',
35
- refresh_token: refreshToken,
36
- }),
37
- });
38
-
39
- if (!res.ok) return null;
40
-
41
- const body = (await res.json().catch(() => null)) as TokenResponse | null;
42
- if (!body?.access_token || !body.refresh_token) return null;
43
-
44
- await storeCredentials(
45
- body.access_token,
46
- body.refresh_token,
47
- getEmailFromIdToken(body.id_token)
48
- );
49
- return body.access_token;
50
- } catch {
51
- return null;
52
- }
53
- }
package/src/update.tsx DELETED
@@ -1,89 +0,0 @@
1
- import {
2
- SpinnerLog,
3
- SuccessLog,
4
- ErrorLog,
5
- addLog,
6
- addErrorLog,
7
- clearLogs,
8
- getLatestClientVersion,
9
- downloadTargetMint,
10
- getClientVersion,
11
- } from '@mintlify/previewing';
12
-
13
- import {
14
- assertValidPackageName,
15
- execFileAsync,
16
- getLatestCliVersion,
17
- getVersions,
18
- detectPackageManager,
19
- windowsCompatibleSpawnOptions,
20
- } from './helpers.js';
21
-
22
- export const update = async ({ packageName }: { packageName: string }) => {
23
- assertValidPackageName(packageName);
24
- addLog(<SpinnerLog message="updating..." />);
25
- const { cli: existingCliVersion } = getVersions(packageName);
26
- const latestCliVersion = getLatestCliVersion(packageName);
27
- const isUpToDate =
28
- existingCliVersion && latestCliVersion && latestCliVersion.trim() === existingCliVersion.trim();
29
-
30
- if (!isUpToDate && existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
31
- const packageManager = await detectPackageManager({ packageName });
32
- try {
33
- clearLogs();
34
- addLog(<SpinnerLog message={`updating ${packageName} package...`} />);
35
-
36
- if (packageManager === 'pnpm') {
37
- await execFileAsync(
38
- 'pnpm',
39
- ['install', '-g', `${packageName}@latest`, '--silent'],
40
- windowsCompatibleSpawnOptions
41
- );
42
- } else {
43
- await execFileAsync(
44
- 'npm',
45
- ['install', '-g', `${packageName}@latest`, '--silent'],
46
- windowsCompatibleSpawnOptions
47
- );
48
- }
49
- } catch (err) {
50
- const errorMessage = err instanceof Error ? err.message : String(err);
51
- addErrorLog(
52
- <ErrorLog
53
- message={`Failed to update ${packageName}@${latestCliVersion} using ${packageManager}: ${errorMessage}`}
54
- />
55
- );
56
- return;
57
- }
58
- }
59
-
60
- clearLogs();
61
- addLog(<SpinnerLog message="updating client..." />);
62
- let clientUpdated = false;
63
- const latestClientVersion = await getLatestClientVersion();
64
- if (latestClientVersion) {
65
- const existingClientVersion = getClientVersion().trim();
66
- if (existingClientVersion !== latestClientVersion.trim()) {
67
- try {
68
- await downloadTargetMint({
69
- targetVersion: latestClientVersion,
70
- existingVersion: existingClientVersion === 'none' ? null : existingClientVersion,
71
- });
72
- clientUpdated = true;
73
- } catch (err) {
74
- const errorMessage = err instanceof Error ? err.message : String(err);
75
- addErrorLog(<ErrorLog message={`Failed to update client: ${errorMessage}`} />);
76
- return;
77
- }
78
- }
79
- }
80
-
81
- clearLogs();
82
- if (isUpToDate && !clientUpdated) {
83
- addLog(<SuccessLog message="already up to date" />);
84
- } else {
85
- addLog(
86
- <SuccessLog message={`updated ${packageName} to the latest version: ${latestCliVersion}`} />
87
- );
88
- }
89
- };