karajan-code 1.56.0 → 1.57.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.
@@ -0,0 +1,47 @@
1
+ const TELEMETRY_ENDPOINT = "https://karajan-code.web.app/api/telemetry";
2
+
3
+ /**
4
+ * Send an anonymous telemetry event. Non-blocking, fire-and-forget.
5
+ * Never throws, never blocks the pipeline.
6
+ *
7
+ * @param {string} eventName - Event name (e.g. "install", "pipeline_complete", "cli_command")
8
+ * @param {object} data - Event-specific data
9
+ * @param {object} [config] - Karajan config (checked for telemetry opt-out)
10
+ */
11
+ export async function sendTelemetryEvent(eventName, data, config) {
12
+ if (!isTelemetryEnabled(config)) return;
13
+
14
+ try {
15
+ const payload = {
16
+ event: eventName,
17
+ v: data.version || "unknown",
18
+ os: process.platform,
19
+ node: process.version,
20
+ ts: Date.now(),
21
+ ...data
22
+ };
23
+ const controller = new AbortController();
24
+ const timeout = setTimeout(() => controller.abort(), 3000);
25
+ try {
26
+ await fetch(TELEMETRY_ENDPOINT, {
27
+ method: "POST",
28
+ headers: { "Content-Type": "application/json" },
29
+ body: JSON.stringify(payload),
30
+ signal: controller.signal
31
+ });
32
+ } finally {
33
+ clearTimeout(timeout);
34
+ }
35
+ } catch { /* never block, never fail */ }
36
+ }
37
+
38
+ /**
39
+ * Check if telemetry is enabled (opt-out model).
40
+ * Returns false only when the user explicitly sets telemetry: false.
41
+ *
42
+ * @param {object} [config] - Karajan config
43
+ * @returns {boolean}
44
+ */
45
+ export function isTelemetryEnabled(config) {
46
+ return config?.telemetry !== false;
47
+ }