karajan-code 2.34.0 → 3.0.0

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,4 +1,30 @@
1
- const TELEMETRY_ENDPOINT = "https://karajan-code.web.app/api/telemetry";
1
+ export const TELEMETRY_ENDPOINT = "https://karajan-code.web.app/api/telemetry";
2
+
3
+ /**
4
+ * Build the exact JSON payload that would be POSTed for an event.
5
+ * Pure function: deterministic given (eventName, data) — exposed so
6
+ * `kj telemetry preview` can render the literal bytes the backend
7
+ * receives without performing any network call.
8
+ *
9
+ * The `data.version` field is folded into `v`; the rest of the
10
+ * event-specific keys ride through `...data` after the common ones,
11
+ * matching the order sent over the wire.
12
+ *
13
+ * @param {string} eventName
14
+ * @param {object} [data]
15
+ * @returns {object}
16
+ */
17
+ export function buildTelemetryPayload(eventName, data = {}) {
18
+ const { version, ...rest } = data;
19
+ return {
20
+ event: eventName,
21
+ v: version || "unknown",
22
+ os: process.platform,
23
+ node: process.version,
24
+ ts: Date.now(),
25
+ ...rest
26
+ };
27
+ }
2
28
 
3
29
  /**
4
30
  * Send an anonymous telemetry event. Non-blocking, fire-and-forget.
@@ -12,14 +38,7 @@ export async function sendTelemetryEvent(eventName, data, config) {
12
38
  if (!isTelemetryEnabled(config)) return;
13
39
 
14
40
  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
- };
41
+ const payload = buildTelemetryPayload(eventName, data);
23
42
  const controller = new AbortController();
24
43
  const timeout = setTimeout(() => controller.abort(), 3000);
25
44
  try {
@@ -48,12 +67,15 @@ export async function sendTelemetryEvent(eventName, data, config) {
48
67
  }
49
68
 
50
69
  /**
51
- * Check if telemetry is enabled (opt-out model).
52
- * Returns false only when the user explicitly sets telemetry: false.
70
+ * Check if telemetry is enabled (opt-in model).
71
+ *
72
+ * Returns true ONLY when the user explicitly answered "yes" in the
73
+ * `kj init` wizard and we persisted `telemetry: true` to their config.
74
+ * Anything else — undefined, null, missing key, false — disables sending.
53
75
  *
54
76
  * @param {object} [config] - Karajan config
55
77
  * @returns {boolean}
56
78
  */
57
79
  export function isTelemetryEnabled(config) {
58
- return config?.telemetry !== false;
80
+ return config?.telemetry === true;
59
81
  }