zubbl-sdk 1.1.12 → 1.1.14

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.
@@ -27,7 +27,10 @@ function setSamplingRatio(ratio) {
27
27
 
28
28
  function emitEndpoint(payload) {
29
29
  if (!shouldSample()) return;
30
- endpointBuffer.push({ ...payload, ts: Date.now(), source: "sdk" });
30
+ const enriched = { ...payload, ts: Date.now(), source: "sdk" };
31
+ endpointBuffer.push(enriched);
32
+ console.log("[Zubbl SDK][Telemetry] Queued endpoint:", enriched);
33
+
31
34
  if (!debounceTimer) {
32
35
  debounceTimer = setTimeout(flushEndpointBuffer, 200);
33
36
  }
@@ -41,14 +44,39 @@ async function flushEndpointBuffer() {
41
44
  const batch = [...endpointBuffer];
42
45
  endpointBuffer = [];
43
46
  debounceTimer = null;
47
+
48
+ const telemetryUrl =
49
+ process.env.ZUBBL_TELEMETRY_URL || `${config.baseUrl.replace(/\/$/, "")}/sdk/log`;
50
+
51
+ const headers = {
52
+ "Content-Type": "application/json",
53
+ Authorization: `Bearer ${config.apiKey}`,
54
+ "X-Tenant-Id": config.tenantId,
55
+ "X-App-Id": config.appId,
56
+ };
57
+
58
+ console.log("[Zubbl SDK][Telemetry] Flushing batch:", {
59
+ url: telemetryUrl,
60
+ count: batch.length,
61
+ sampleRatio,
62
+ payload: batch,
63
+ headers,
64
+ });
65
+
44
66
  try {
45
- await fetch(`${config.baseUrl}/sdk/telemetry/endpoints`, {
67
+ const resp = await fetch(telemetryUrl, {
46
68
  method: "POST",
47
- headers: { "Content-Type": "application/json" },
69
+ headers,
48
70
  body: JSON.stringify(batch),
49
71
  });
72
+
73
+ const text = await resp.text();
74
+ console.log("[Zubbl SDK][Telemetry] Response:", {
75
+ status: resp.status,
76
+ body: text,
77
+ });
50
78
  } catch (err) {
51
- console.error("[Zubbl SDK] Failed to send endpoint telemetry", err);
79
+ console.error("[Zubbl SDK][Telemetry] Failed to send batch:", err);
52
80
  }
53
81
  }
54
82
 
@@ -67,7 +95,7 @@ async function zubblFetch(input, init = {}, context = {}) {
67
95
  app_id: context.app_id || config.appId,
68
96
  external_user_id: context.external_user_id,
69
97
  method: init.method || "GET",
70
- pathname: url.pathname,
98
+ path: url.pathname, // fixed to "path"
71
99
  status: response?.status ?? 0,
72
100
  latency_ms,
73
101
  });
@@ -25,7 +25,10 @@ function setSamplingRatio(ratio) {
25
25
 
26
26
  function emitEndpoint(payload) {
27
27
  if (!shouldSample()) return;
28
- endpointBuffer.push({ ...payload, ts: Date.now(), source: "sdk" });
28
+ const enriched = { ...payload, ts: Date.now(), source: "sdk" };
29
+ endpointBuffer.push(enriched);
30
+ console.log("[Zubbl SDK][Telemetry] Queued endpoint:", enriched);
31
+
29
32
  if (!debounceTimer) {
30
33
  debounceTimer = setTimeout(flushEndpointBuffer, 200);
31
34
  }
@@ -39,14 +42,39 @@ async function flushEndpointBuffer() {
39
42
  const batch = [...endpointBuffer];
40
43
  endpointBuffer = [];
41
44
  debounceTimer = null;
45
+
46
+ const telemetryUrl =
47
+ process.env.ZUBBL_TELEMETRY_URL || `${config.baseUrl.replace(/\/$/, "")}/sdk/log`;
48
+
49
+ const headers = {
50
+ "Content-Type": "application/json",
51
+ Authorization: `Bearer ${config.apiKey}`,
52
+ "X-Tenant-Id": config.tenantId,
53
+ "X-App-Id": config.appId,
54
+ };
55
+
56
+ console.log("[Zubbl SDK][Telemetry] Flushing batch:", {
57
+ url: telemetryUrl,
58
+ count: batch.length,
59
+ sampleRatio,
60
+ payload: batch,
61
+ headers,
62
+ });
63
+
42
64
  try {
43
- await fetch(`${config.baseUrl}/sdk/telemetry/endpoints`, {
65
+ const resp = await fetch(telemetryUrl, {
44
66
  method: "POST",
45
- headers: { "Content-Type": "application/json" },
67
+ headers,
46
68
  body: JSON.stringify(batch),
47
69
  });
70
+
71
+ const text = await resp.text();
72
+ console.log("[Zubbl SDK][Telemetry] Response:", {
73
+ status: resp.status,
74
+ body: text,
75
+ });
48
76
  } catch (err) {
49
- console.error("[Zubbl SDK] Failed to send endpoint telemetry", err);
77
+ console.error("[Zubbl SDK][Telemetry] Failed to send batch:", err);
50
78
  }
51
79
  }
52
80
 
@@ -65,7 +93,7 @@ async function zubblFetch(input, init = {}, context = {}) {
65
93
  app_id: context.app_id || config.appId,
66
94
  external_user_id: context.external_user_id,
67
95
  method: init.method || "GET",
68
- pathname: url.pathname,
96
+ path: url.pathname, // fixed to "path"
69
97
  status: response?.status ?? 0,
70
98
  latency_ms,
71
99
  });
@@ -29,7 +29,10 @@
29
29
 
30
30
  function emitEndpoint(payload) {
31
31
  if (!shouldSample()) return;
32
- endpointBuffer.push({ ...payload, ts: Date.now(), source: "sdk" });
32
+ const enriched = { ...payload, ts: Date.now(), source: "sdk" };
33
+ endpointBuffer.push(enriched);
34
+ console.log("[Zubbl SDK][Telemetry] Queued endpoint:", enriched);
35
+
33
36
  if (!debounceTimer) {
34
37
  debounceTimer = setTimeout(flushEndpointBuffer, 200);
35
38
  }
@@ -43,14 +46,39 @@
43
46
  const batch = [...endpointBuffer];
44
47
  endpointBuffer = [];
45
48
  debounceTimer = null;
49
+
50
+ const telemetryUrl =
51
+ process.env.ZUBBL_TELEMETRY_URL || `${config.baseUrl.replace(/\/$/, "")}/sdk/log`;
52
+
53
+ const headers = {
54
+ "Content-Type": "application/json",
55
+ Authorization: `Bearer ${config.apiKey}`,
56
+ "X-Tenant-Id": config.tenantId,
57
+ "X-App-Id": config.appId,
58
+ };
59
+
60
+ console.log("[Zubbl SDK][Telemetry] Flushing batch:", {
61
+ url: telemetryUrl,
62
+ count: batch.length,
63
+ sampleRatio,
64
+ payload: batch,
65
+ headers,
66
+ });
67
+
46
68
  try {
47
- await fetch(`${config.baseUrl}/sdk/telemetry/endpoints`, {
69
+ const resp = await fetch(telemetryUrl, {
48
70
  method: "POST",
49
- headers: { "Content-Type": "application/json" },
71
+ headers,
50
72
  body: JSON.stringify(batch),
51
73
  });
74
+
75
+ const text = await resp.text();
76
+ console.log("[Zubbl SDK][Telemetry] Response:", {
77
+ status: resp.status,
78
+ body: text,
79
+ });
52
80
  } catch (err) {
53
- console.error("[Zubbl SDK] Failed to send endpoint telemetry", err);
81
+ console.error("[Zubbl SDK][Telemetry] Failed to send batch:", err);
54
82
  }
55
83
  }
56
84
 
@@ -69,7 +97,7 @@
69
97
  app_id: context.app_id || config.appId,
70
98
  external_user_id: context.external_user_id,
71
99
  method: init.method || "GET",
72
- pathname: url.pathname,
100
+ path: url.pathname, // fixed to "path"
73
101
  status: response?.status ?? 0,
74
102
  latency_ms,
75
103
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zubbl-sdk",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "type": "module",
5
5
  "description": "Zubbl SDK for secure policy enforcement (browser, Node, universal)",
6
6
  "main": "dist/zubbl-sdk.cjs.js",