@meltstudio/meltctl 4.33.1 → 4.33.2
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/dist/utils/analytics.js +20 -4
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +6 -0
- package/package.json +1 -1
package/dist/utils/analytics.js
CHANGED
|
@@ -3,6 +3,7 @@ import { join, dirname } from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { getStoredAuth, API_BASE } from './auth.js';
|
|
5
5
|
import { getGitRepository, getGitBranch, getProjectName } from './git.js';
|
|
6
|
+
import { debugLog } from './debug.js';
|
|
6
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
8
|
const __dirname = dirname(__filename);
|
|
8
9
|
function getVersion() {
|
|
@@ -16,14 +17,19 @@ function getVersion() {
|
|
|
16
17
|
}
|
|
17
18
|
export async function trackCommand(command, success, errorMessage) {
|
|
18
19
|
try {
|
|
20
|
+
if (process.env['MELTCTL_NO_ANALYTICS']) {
|
|
21
|
+
debugLog('Analytics disabled via MELTCTL_NO_ANALYTICS');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
19
24
|
const auth = await getStoredAuth();
|
|
20
25
|
if (!auth || new Date(auth.expiresAt) <= new Date()) {
|
|
26
|
+
debugLog('Analytics skipped: not authenticated or token expired');
|
|
21
27
|
return;
|
|
22
28
|
}
|
|
23
29
|
const repo = getGitRepository();
|
|
24
30
|
const controller = new AbortController();
|
|
25
31
|
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
26
|
-
await fetch(`${API_BASE}/events`, {
|
|
32
|
+
const res = await fetch(`${API_BASE}/events`, {
|
|
27
33
|
method: 'POST',
|
|
28
34
|
headers: {
|
|
29
35
|
Authorization: `Bearer ${auth.token}`,
|
|
@@ -39,10 +45,20 @@ export async function trackCommand(command, success, errorMessage) {
|
|
|
39
45
|
errorMessage: errorMessage?.slice(0, 500) ?? null,
|
|
40
46
|
}),
|
|
41
47
|
signal: controller.signal,
|
|
42
|
-
}).catch(
|
|
48
|
+
}).catch(e => {
|
|
49
|
+
debugLog(`Analytics fetch failed: ${e instanceof Error ? e.message : e}`);
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
43
52
|
clearTimeout(timeout);
|
|
53
|
+
if (res && !res.ok) {
|
|
54
|
+
const body = await res.text().catch(() => '');
|
|
55
|
+
debugLog(`Analytics API error ${res.status}: ${body}`);
|
|
56
|
+
}
|
|
57
|
+
else if (res) {
|
|
58
|
+
debugLog(`Analytics event sent for "${command}"`);
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
|
-
catch {
|
|
46
|
-
|
|
61
|
+
catch (e) {
|
|
62
|
+
debugLog(`Analytics error: ${e instanceof Error ? e.message : e}`);
|
|
47
63
|
}
|
|
48
64
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debugLog(message: string): void;
|
package/package.json
CHANGED