@mintlify/cli 4.0.1731 → 4.0.1733
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__/agent-claim.test.ts +12 -1
- package/__test__/deploy-instructions.test.ts +6 -1
- package/__test__/deploy.test.ts +16 -0
- package/bin/agent-claim.js +6 -0
- package/bin/deploy.js +4 -0
- package/bin/telemetry/track.js +9 -5
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/agent-claim.ts +6 -0
- package/src/deploy.ts +4 -0
- package/src/telemetry/track.ts +12 -8
|
@@ -2,11 +2,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
import { claimDeployment } from '../src/agent-claim.js';
|
|
4
4
|
import { loadAgentCredentials, saveAgentCredentials } from '../src/agent-credentials.js';
|
|
5
|
+
import { trackEvent } from '../src/telemetry/track.js';
|
|
5
6
|
|
|
6
7
|
vi.mock('../src/agent-credentials.js', () => ({
|
|
7
8
|
loadAgentCredentials: vi.fn(),
|
|
8
9
|
saveAgentCredentials: vi.fn(),
|
|
9
10
|
}));
|
|
11
|
+
vi.mock('../src/telemetry/track.js', () => ({ trackEvent: vi.fn() }));
|
|
10
12
|
const issuer = 'https://auth.example.com';
|
|
11
13
|
const apiUrl = 'https://api.example.com';
|
|
12
14
|
const options = { apiUrl, directory: '/docs', code: 'ABCDEFGH' };
|
|
@@ -72,6 +74,9 @@ describe('claim command', () => {
|
|
|
72
74
|
expect(vi.mocked(saveAgentCredentials).mock.invocationCallOrder[0]).toBeLessThan(
|
|
73
75
|
fetchMock.mock.invocationCallOrder[3]!
|
|
74
76
|
);
|
|
77
|
+
expect(vi.mocked(trackEvent).mock.calls).toEqual([
|
|
78
|
+
['agent_signup.claim_completed', { registration_id: 'reg' }],
|
|
79
|
+
]);
|
|
75
80
|
});
|
|
76
81
|
it('resumes after signup fails without consuming the code again', async () => {
|
|
77
82
|
const implementation = fetchMock.getMockImplementation()!;
|
|
@@ -94,6 +99,7 @@ describe('claim command', () => {
|
|
|
94
99
|
);
|
|
95
100
|
await expect(claimDeployment(options, vi.fn())).rejects.toThrow('invalid_user_code');
|
|
96
101
|
expect(saveAgentCredentials).not.toHaveBeenCalled();
|
|
102
|
+
expect(trackEvent).not.toHaveBeenCalled();
|
|
97
103
|
expect(fetchMock.mock.calls.some(([url]) => url.endsWith('/signup'))).toBe(false);
|
|
98
104
|
});
|
|
99
105
|
it('warns on storage failure and continues signup without exposing secrets', async () => {
|
|
@@ -110,7 +116,12 @@ describe('claim command', () => {
|
|
|
110
116
|
{ apiUrl, directory: '/docs', email: 'person@example.com' },
|
|
111
117
|
vi.fn()
|
|
112
118
|
);
|
|
113
|
-
expect(output).
|
|
119
|
+
expect(new URL(output.match(/https?:\/\/\S+/)![0]).searchParams.get('registration')).toBe(
|
|
120
|
+
'reg'
|
|
121
|
+
);
|
|
122
|
+
expect(vi.mocked(trackEvent).mock.calls).toEqual([
|
|
123
|
+
['agent_signup.claim_started', { registration_id: 'reg' }],
|
|
124
|
+
]);
|
|
114
125
|
expect(
|
|
115
126
|
fetchMock.mock.calls.some(([url]) => url.endsWith('/signup') || url.endsWith('/complete'))
|
|
116
127
|
).toBe(false);
|
|
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
3
3
|
import { createAgentClaimLink } from '../src/agent-claim.js';
|
|
4
4
|
import { DASHBOARD_URL } from '../src/constants.js';
|
|
5
5
|
import { deploymentInstructions, DEPLOY_HELP } from '../src/deploy-instructions.js';
|
|
6
|
+
import { trackEvent } from '../src/telemetry/track.js';
|
|
6
7
|
import { renderWelcome } from '../src/welcome.js';
|
|
7
8
|
|
|
8
9
|
vi.mock('../src/agent-auth.js', async (importOriginal) => ({
|
|
@@ -12,6 +13,7 @@ vi.mock('../src/agent-auth.js', async (importOriginal) => ({
|
|
|
12
13
|
agent_auth: { claim_endpoint: 'https://auth.example.com/agent/identity/claim' },
|
|
13
14
|
}),
|
|
14
15
|
}));
|
|
16
|
+
vi.mock('../src/telemetry/track.js', () => ({ trackEvent: vi.fn() }));
|
|
15
17
|
afterEach(() => vi.unstubAllGlobals());
|
|
16
18
|
const credentials = {
|
|
17
19
|
registrationId: 'reg',
|
|
@@ -43,7 +45,10 @@ describe('deploy help and claim handoff', () => {
|
|
|
43
45
|
vi.stubGlobal('fetch', request);
|
|
44
46
|
expect(
|
|
45
47
|
await createAgentClaimLink('https://api.example.com', credentials, 'user@example.com')
|
|
46
|
-
).toBe(`${DASHBOARD_URL}/agent-claim?token=attempt%2Btoken%26value`);
|
|
48
|
+
).toBe(`${DASHBOARD_URL}/agent-claim?token=attempt%2Btoken%26value®istration=reg`);
|
|
49
|
+
expect(trackEvent).toHaveBeenCalledWith('agent_signup.claim_started', {
|
|
50
|
+
registration_id: 'reg',
|
|
51
|
+
});
|
|
47
52
|
expect(JSON.parse(request.mock.calls[0]?.[1].body)).toEqual({
|
|
48
53
|
type: 'service_auth',
|
|
49
54
|
claim_token: 'claim-secret',
|
package/__test__/deploy.test.ts
CHANGED
|
@@ -6,11 +6,13 @@ import * as storage from '../src/agent-credentials.js';
|
|
|
6
6
|
import * as deployment from '../src/agent-deployment.js';
|
|
7
7
|
import * as config from '../src/config.js';
|
|
8
8
|
import { prepareAgentDeployment, formatDeployment } from '../src/deploy.js';
|
|
9
|
+
import { trackEvent } from '../src/telemetry/track.js';
|
|
9
10
|
|
|
10
11
|
vi.mock('../src/agent-auth.js');
|
|
11
12
|
vi.mock('../src/agent-credentials.js');
|
|
12
13
|
vi.mock('../src/agent-deployment.js');
|
|
13
14
|
vi.mock('../src/config.js');
|
|
15
|
+
vi.mock('../src/telemetry/track.js');
|
|
14
16
|
|
|
15
17
|
const credentials = {
|
|
16
18
|
registrationId: 'reg_1',
|
|
@@ -59,6 +61,20 @@ beforeEach(() => {
|
|
|
59
61
|
});
|
|
60
62
|
|
|
61
63
|
describe('mint deploy', () => {
|
|
64
|
+
it('tracks discovery and registration for a new agent', async () => {
|
|
65
|
+
await prepareAgentDeployment(options, warn);
|
|
66
|
+
expect(vi.mocked(trackEvent).mock.calls).toEqual([
|
|
67
|
+
['agent_signup.discovered', { registration_id: 'reg_1' }],
|
|
68
|
+
['agent_signup.registered', { registration_id: 'reg_1' }],
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
it('tracks only discovery for a saved registration', async () => {
|
|
72
|
+
vi.mocked(storage.loadAgentCredentials).mockResolvedValue(credentials);
|
|
73
|
+
await prepareAgentDeployment(options, warn);
|
|
74
|
+
expect(vi.mocked(trackEvent).mock.calls).toEqual([
|
|
75
|
+
['agent_signup.discovered', { registration_id: 'reg_1' }],
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
62
78
|
it.each([
|
|
63
79
|
['https://leaves.mintlify.com', 'https://allocated.mintlify.site/'],
|
|
64
80
|
['https://leaves-dev.mintlify.com', 'https://allocated.mint-dev.mintlify.me/'],
|
package/bin/agent-claim.js
CHANGED
|
@@ -12,6 +12,7 @@ import { agentIdentityAssertionSchema, discoverAgentAuth, exchangeAgentToken, }
|
|
|
12
12
|
import { loadAgentCredentials, saveAgentCredentials, } from './agent-credentials.js';
|
|
13
13
|
import { agentRequest, agentResponse } from './agent-http.js';
|
|
14
14
|
import { DASHBOARD_URL } from './constants.js';
|
|
15
|
+
import { trackEvent } from './telemetry/track.js';
|
|
15
16
|
const claimAttemptSchema = z.object({ attempt: z.object({ verification_uri: z.url() }) });
|
|
16
17
|
export function createAgentClaimLink(apiUrl, credentials, email) {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -35,6 +36,8 @@ export function createAgentClaimLink(apiUrl, credentials, email) {
|
|
|
35
36
|
.parse(new URL(claim.attempt.verification_uri).searchParams.get('token'));
|
|
36
37
|
const claimUrl = new URL('/agent-claim', DASHBOARD_URL);
|
|
37
38
|
claimUrl.searchParams.set('token', token);
|
|
39
|
+
claimUrl.searchParams.set('registration', credentials.registrationId);
|
|
40
|
+
void trackEvent('agent_signup.claim_started', { registration_id: credentials.registrationId });
|
|
38
41
|
return claimUrl.toString();
|
|
39
42
|
});
|
|
40
43
|
}
|
|
@@ -78,6 +81,9 @@ export function claimDeployment(options_1, warn_1) {
|
|
|
78
81
|
headers: { 'Content-Type': 'application/json' },
|
|
79
82
|
body: JSON.stringify({ claim_token: credentials.claimToken, user_code: code }),
|
|
80
83
|
}), completedClaimSchema);
|
|
84
|
+
void trackEvent('agent_signup.claim_completed', {
|
|
85
|
+
registration_id: credentials.registrationId,
|
|
86
|
+
});
|
|
81
87
|
credentials = Object.assign(Object.assign({}, credentials), { assertion: completed.identity.assertion, claimVerified: true, accessToken: undefined, accessTokenExpiresAt: undefined });
|
|
82
88
|
yield save(credentials);
|
|
83
89
|
}
|
package/bin/deploy.js
CHANGED
|
@@ -12,6 +12,7 @@ import { discoverAgentAuth, exchangeAgentToken, getAgentIdentity, registerAgent,
|
|
|
12
12
|
import { loadAgentCredentials, saveAgentCredentials, } from './agent-credentials.js';
|
|
13
13
|
import { getAgentWriteToken, provisionAgentSite, } from './agent-deployment.js';
|
|
14
14
|
import { getAgentSiteMetadata, setAgentSiteMetadata } from './config.js';
|
|
15
|
+
import { trackEvent } from './telemetry/track.js';
|
|
15
16
|
export function prepareAgentDeployment(options_1, warn_1) {
|
|
16
17
|
return __awaiter(this, arguments, void 0, function* (options, warn, progress = () => { }) {
|
|
17
18
|
var _a;
|
|
@@ -42,6 +43,9 @@ export function prepareAgentDeployment(options_1, warn_1) {
|
|
|
42
43
|
});
|
|
43
44
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
44
45
|
const credentials = saved !== null && saved !== void 0 ? saved : (yield registerAgent(discovery));
|
|
46
|
+
void trackEvent('agent_signup.discovered', { registration_id: credentials.registrationId });
|
|
47
|
+
if (!saved)
|
|
48
|
+
void trackEvent('agent_signup.registered', { registration_id: credentials.registrationId });
|
|
45
49
|
yield save(credentials);
|
|
46
50
|
const authenticated = yield exchangeAgentToken(discovery, credentials);
|
|
47
51
|
yield save(authenticated);
|
package/bin/telemetry/track.js
CHANGED
|
@@ -114,11 +114,15 @@ export function trackEvent(event, properties) {
|
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
115
|
if (!isTelemetryEnabled())
|
|
116
116
|
return;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
const work = (() => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
try {
|
|
119
|
+
const { cli: cliVersion } = getVersions();
|
|
120
|
+
yield captureWithTimeout(event, Object.assign(Object.assign(Object.assign({}, properties), { cli_version: cliVersion }), getEnvironmentProperties()));
|
|
121
|
+
}
|
|
122
|
+
catch (_a) { }
|
|
123
|
+
}))();
|
|
124
|
+
deferShutdownUntil(work);
|
|
125
|
+
yield work;
|
|
122
126
|
});
|
|
123
127
|
}
|
|
124
128
|
export function trackTelemetryPreferenceChange(options) {
|