@mintlify/cli 4.0.1797 → 4.0.1798

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.
@@ -1,38 +1,30 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
2
 
3
- import { authenticatedFetch } from '../src/authenticatedFetch.js';
4
3
  import { API_URL } from '../src/constants.js';
5
4
  import { sendFeedback } from '../src/feedback.js';
6
5
 
7
- vi.mock('../src/authenticatedFetch.js');
6
+ const fetchMock = vi.fn();
7
+ vi.stubGlobal('fetch', fetchMock);
8
8
 
9
9
  const input = { message: 'mint dev crashed', clientId: 'c1', category: 'bug' as const };
10
- const respond = (status: number) =>
11
- vi.mocked(authenticatedFetch).mockResolvedValue(new Response('{}', { status }));
10
+ const respond = (status: number) => fetchMock.mockResolvedValue(new Response('{}', { status }));
12
11
 
13
- beforeEach(() => vi.resetAllMocks());
12
+ beforeEach(() => {
13
+ fetchMock.mockReset();
14
+ });
14
15
 
15
16
  describe('mint feedback', () => {
16
- it('posts the feedback with the cli source', async () => {
17
+ it('posts the feedback with the cli source and no login', async () => {
17
18
  respond(201);
18
19
  expect(await sendFeedback(input)).toBeUndefined();
19
- const [url, init] = vi.mocked(authenticatedFetch).mock.calls[0]!;
20
+ const [url, init] = fetchMock.mock.calls[0]!;
20
21
  expect(url).toBe(`${API_URL}/api/cli/feedback`);
21
22
  expect(init?.method).toBe('POST');
23
+ expect(init?.headers).not.toHaveProperty('Authorization');
22
24
  expect(JSON.parse(String(init?.body))).toEqual({ ...input, source: 'cli' });
23
25
  });
24
- it('asks for login on 401', async () => {
25
- respond(401);
26
- expect(await sendFeedback(input)).toContain('mint login');
27
- });
28
- it('asks for login when no credentials are stored', async () => {
29
- vi.mocked(authenticatedFetch).mockRejectedValue(
30
- new Error('Not authenticated. Run `mint login` to authenticate.')
31
- );
32
- expect(await sendFeedback(input)).toContain('mint login');
33
- });
34
26
  it('reports a network failure', async () => {
35
- vi.mocked(authenticatedFetch).mockRejectedValue(new Error('fetch failed'));
27
+ fetchMock.mockRejectedValue(new Error('fetch failed'));
36
28
  expect(await sendFeedback(input)).toBe('could not reach the server');
37
29
  });
38
30
  it('reports a server error', async () => {
package/bin/cli.js CHANGED
@@ -561,7 +561,7 @@ export const cli = ({ packageName = 'mint' }) => {
561
561
  description: 'Feedback category',
562
562
  })
563
563
  .example('$0 feedback "mint dev crashes on a missing image" --client-id 7f3a --category bug', 'Report a bug')
564
- .epilog('Requires mint login. Never include API keys, tokens, passwords, or other secrets in the message.'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
564
+ .epilog('Never include API keys, tokens, passwords, or other secrets in the message.'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
565
565
  const sent = yield feedback({
566
566
  message: argv.message,
567
567
  clientId: argv.clientId,
package/bin/feedback.js CHANGED
@@ -9,26 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { addLog, ErrorLog, SuccessLog } from '@mintlify/previewing';
12
- import { authenticatedFetch } from './authenticatedFetch.js';
13
12
  import { API_URL } from './constants.js';
14
13
  export const FEEDBACK_CATEGORIES = ['bug', 'docs', 'idea'];
15
- const LOGIN_REQUIRED = 'not logged in. Run `mint login` first, then retry.';
16
14
  export function sendFeedback(input) {
17
15
  return __awaiter(this, void 0, void 0, function* () {
18
16
  let res;
19
17
  try {
20
- res = yield authenticatedFetch(`${API_URL}/api/cli/feedback`, {
18
+ res = yield fetch(`${API_URL}/api/cli/feedback`, {
21
19
  method: 'POST',
22
20
  headers: { 'Content-Type': 'application/json' },
23
21
  body: JSON.stringify(Object.assign(Object.assign({}, input), { source: 'cli' })),
24
22
  });
25
23
  }
26
- catch (error) {
27
- const notLoggedIn = error instanceof Error && /not authenticated/i.test(error.message);
28
- return notLoggedIn ? LOGIN_REQUIRED : 'could not reach the server';
24
+ catch (_a) {
25
+ return 'could not reach the server';
29
26
  }
30
- if (res.status === 401)
31
- return LOGIN_REQUIRED;
32
27
  return res.ok ? undefined : `could not send feedback (HTTP ${res.status})`;
33
28
  });
34
29
  }