@neetru/sdk 3.7.0 → 3.8.1

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +66 -1
  3. package/dist/ai.cjs +221 -177
  4. package/dist/ai.d.cts +1 -1
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.mjs +221 -177
  7. package/dist/auth.cjs +1051 -868
  8. package/dist/auth.d.cts +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/auth.mjs +1048 -865
  11. package/dist/catalog.cjs +164 -97
  12. package/dist/catalog.d.cts +1 -1
  13. package/dist/catalog.d.ts +1 -1
  14. package/dist/catalog.mjs +164 -97
  15. package/dist/checkout.cjs +182 -115
  16. package/dist/checkout.d.cts +1 -1
  17. package/dist/checkout.d.ts +1 -1
  18. package/dist/checkout.mjs +181 -114
  19. package/dist/db-react.d.cts +1 -1
  20. package/dist/db-react.d.ts +1 -1
  21. package/dist/db.cjs +437 -345
  22. package/dist/db.d.cts +1 -1
  23. package/dist/db.d.ts +1 -1
  24. package/dist/db.mjs +455 -363
  25. package/dist/entitlements.cjs +17 -10
  26. package/dist/entitlements.d.cts +1 -1
  27. package/dist/entitlements.d.ts +1 -1
  28. package/dist/entitlements.mjs +17 -10
  29. package/dist/errors.cjs +15 -8
  30. package/dist/errors.d.cts +24 -3
  31. package/dist/errors.d.ts +24 -3
  32. package/dist/errors.mjs +14 -7
  33. package/dist/firestore-compat.d.cts +1 -1
  34. package/dist/firestore-compat.d.ts +1 -1
  35. package/dist/index.cjs +1544 -1190
  36. package/dist/index.d.cts +177 -3
  37. package/dist/index.d.ts +177 -3
  38. package/dist/index.mjs +1676 -1329
  39. package/dist/mobile.cjs +400 -181
  40. package/dist/mobile.d.cts +59 -4
  41. package/dist/mobile.d.ts +59 -4
  42. package/dist/mobile.mjs +400 -181
  43. package/dist/mocks.cjs +9 -2
  44. package/dist/mocks.d.cts +1 -1
  45. package/dist/mocks.d.ts +1 -1
  46. package/dist/mocks.mjs +9 -2
  47. package/dist/notifications.cjs +197 -130
  48. package/dist/notifications.d.cts +1 -1
  49. package/dist/notifications.d.ts +1 -1
  50. package/dist/notifications.mjs +196 -129
  51. package/dist/react.cjs +303 -282
  52. package/dist/react.d.cts +1 -1
  53. package/dist/react.d.ts +1 -1
  54. package/dist/react.mjs +295 -274
  55. package/dist/support.cjs +299 -229
  56. package/dist/support.d.cts +8 -4
  57. package/dist/support.d.ts +8 -4
  58. package/dist/support.mjs +298 -228
  59. package/dist/telemetry.cjs +234 -167
  60. package/dist/telemetry.d.cts +1 -1
  61. package/dist/telemetry.d.ts +1 -1
  62. package/dist/telemetry.mjs +234 -167
  63. package/dist/{types-Dx0IrOSF.d.ts → types-BYPk_3HR.d.ts} +104 -17
  64. package/dist/{types-Bx4kTLmk.d.cts → types-yv3EDKg2.d.cts} +104 -17
  65. package/dist/usage.cjs +183 -116
  66. package/dist/usage.d.cts +1 -1
  67. package/dist/usage.d.ts +1 -1
  68. package/dist/usage.mjs +183 -116
  69. package/dist/webhooks.cjs +215 -148
  70. package/dist/webhooks.d.cts +1 -1
  71. package/dist/webhooks.d.ts +1 -1
  72. package/dist/webhooks.mjs +212 -145
  73. package/package.json +2 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // src/errors.ts
4
- var a = class e extends Error {
4
+ var d = class e extends Error {
5
5
  code;
6
6
  status;
7
7
  requestId;
@@ -14,183 +14,250 @@ var a = class e extends Error {
14
14
  * para um `NeetruDbErrorCode` mais específico (recuperável vs não).
15
15
  */
16
16
  reason;
17
- constructor(r, n, d, m, c) {
18
- super(n), this.name = "NeetruError", this.code = r, this.status = d, this.requestId = m, this.reason = c, Object.setPrototypeOf(this, e.prototype);
17
+ /**
18
+ * 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
19
+ * chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
20
+ * mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
21
+ * `undefined` em erros que acontecem antes de qualquer requisição.
22
+ */
23
+ correlationId;
24
+ constructor(t, n, o, i, u, r) {
25
+ super(n), this.name = "NeetruError", this.code = t, this.status = o, this.requestId = i, this.reason = u, this.correlationId = r, Object.setPrototypeOf(this, e.prototype);
19
26
  }
20
27
  };
21
28
 
22
29
  // src/idempotency.ts
23
- function R() {
30
+ function I() {
24
31
  let e = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
25
32
  if (e && typeof e.randomUUID == "function")
26
33
  return e.randomUUID();
27
- throw new a(
34
+ throw new d(
28
35
  "runtime_unsupported",
29
36
  "crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
30
37
  );
31
38
  }
32
39
 
40
+ // src/correlation.ts
41
+ var A = "x-correlation-id";
42
+ var j = /^[A-Za-z0-9._:\-]+$/;
43
+ function S(e) {
44
+ return typeof e == "string" && e.length > 0 && e.length <= 128 && j.test(e);
45
+ }
46
+ function H() {
47
+ let e = globalThis.crypto;
48
+ try {
49
+ if (e && typeof e.randomUUID == "function") return e.randomUUID();
50
+ } catch {
51
+ }
52
+ let t = new Uint8Array(16), n = false;
53
+ try {
54
+ e && typeof e.getRandomValues == "function" && (e.getRandomValues(t), n = !0);
55
+ } catch {
56
+ n = false;
57
+ }
58
+ if (!n)
59
+ for (let i = 0; i < t.length; i++) t[i] = Math.floor(Math.random() * 256);
60
+ t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
61
+ let o = Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("");
62
+ return `${o.slice(0, 8)}-${o.slice(8, 12)}-${o.slice(12, 16)}-${o.slice(16, 20)}-${o.slice(20)}`;
63
+ }
64
+ function N(e, t) {
65
+ let n, o = {};
66
+ for (let [u, r] of Object.entries(e)) {
67
+ if (u.toLowerCase() === A) {
68
+ S(r) && (n = r);
69
+ continue;
70
+ }
71
+ o[u] = r;
72
+ }
73
+ let i = n ?? (S(t) ? t : void 0) ?? H();
74
+ return o[A] = i, { headers: o, correlationId: i };
75
+ }
76
+
77
+ // src/server-only-key.ts
78
+ function x() {
79
+ try {
80
+ let e = globalThis.navigator;
81
+ if (e && e.product === "ReactNative") return "react-native";
82
+ } catch {
83
+ }
84
+ try {
85
+ let e = globalThis;
86
+ if (typeof e.window < "u" && typeof e.document < "u") return "browser";
87
+ } catch {
88
+ }
89
+ return null;
90
+ }
91
+
33
92
  // src/http.ts
34
- var L = {
93
+ var F = {
35
94
  // SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
36
95
  // runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
37
96
  3: "2026.05.1"
38
97
  };
39
- function v(e) {
98
+ function R(e) {
40
99
  return e.split("+")[0] ?? e;
41
100
  }
42
- function O(e, r) {
43
- let n = v(e).split(".").map(Number), d = v(r).split(".").map(Number), m = Math.max(n.length, d.length);
44
- for (let c = 0; c < m; c++) {
45
- let t = n[c] ?? 0, i = d[c] ?? 0;
46
- if (t !== i) return t - i;
101
+ function V(e, t) {
102
+ let n = R(e).split(".").map(Number), o = R(t).split(".").map(Number), i = Math.max(n.length, o.length);
103
+ for (let u = 0; u < i; u++) {
104
+ let r = n[u] ?? 0, a = o[u] ?? 0;
105
+ if (r !== a) return r - a;
47
106
  }
48
107
  return 0;
49
108
  }
50
- function D() {
109
+ function L() {
51
110
  try {
52
- return "3.7.0";
111
+ return "3.8.1";
53
112
  } catch {
54
113
  return;
55
114
  }
56
115
  }
57
- function U() {
58
- let e = D();
116
+ function B() {
117
+ let e = L();
59
118
  return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
60
119
  }
61
- var A = /* @__PURE__ */ new Set();
62
- function j(e) {
120
+ var D = /* @__PURE__ */ new Set();
121
+ function z(e) {
63
122
  if (!e) return;
64
- let r = U(), n = L[r];
123
+ let t = B(), n = F[t];
65
124
  if (!n) return;
66
- let d = v(e);
67
- if (O(d, n) < 0) {
68
- let m = `${r}:${d}`;
69
- A.has(m) || (A.add(m), console.warn(
70
- `[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${e}" \xE9 anterior ao m\xEDnimo recomendado "${n}" para SDK major ${r}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
125
+ let o = R(e);
126
+ if (V(o, n) < 0) {
127
+ let i = `${t}:${o}`;
128
+ D.has(i) || (D.add(i), console.warn(
129
+ `[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${e}" \xE9 anterior ao m\xEDnimo recomendado "${n}" para SDK major ${t}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
71
130
  ));
72
131
  }
73
132
  }
74
- var $ = 2, K = 0, H = /* @__PURE__ */ new Set(["GET", "HEAD"]), F = /* @__PURE__ */ new Set([
133
+ function G() {
134
+ let e = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
135
+ return x() ? "Esta opera\xE7\xE3o exige a credencial nrt_ do produto, que \xE9 S\xD3 DE SERVIDOR. No navegador/app, chame a API do seu produto (ex.: https://<produto>.neetru.com/api/v1) com o token do usu\xE1rio \u2014 o backend do produto faz esta chamada com o SDK e a chave. (" + e + ")" : e;
136
+ }
137
+ var X = 2, Y = 0, J = /* @__PURE__ */ new Set(["GET", "HEAD"]), W = /* @__PURE__ */ new Set([
75
138
  "rate_limited",
76
139
  "server_error",
77
140
  "network_error"
78
141
  ]);
79
- function I(e) {
80
- let r = 200 * Math.pow(4, e), n = r * 0.2 * (Math.random() * 2 - 1);
81
- return Math.max(50, Math.round(r + n));
142
+ function C(e) {
143
+ let t = 200 * Math.pow(4, e), n = t * 0.2 * (Math.random() * 2 - 1);
144
+ return Math.max(50, Math.round(t + n));
82
145
  }
83
- var S = 6e4;
84
- function V(e) {
146
+ var O = 6e4;
147
+ function Q(e) {
85
148
  if (!e) return null;
86
- let r = Number(e);
87
- if (Number.isFinite(r) && r >= 0) return Math.min(Math.round(r * 1e3), S);
149
+ let t = Number(e);
150
+ if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3), O);
88
151
  let n = Date.parse(e);
89
152
  if (Number.isFinite(n)) {
90
- let d = n - Date.now();
91
- if (d > 0) return Math.min(d, S);
153
+ let o = n - Date.now();
154
+ if (o > 0) return Math.min(o, O);
92
155
  }
93
156
  return null;
94
157
  }
95
158
  function q(e) {
96
- return new Promise((r) => setTimeout(r, e));
159
+ return new Promise((t) => setTimeout(t, e));
97
160
  }
98
- function G(e) {
161
+ function Z(e) {
99
162
  return e === 401 ? "unauthorized" : e === 403 ? "forbidden" : e === 404 ? "not_found" : e === 409 ? "conflict" : e === 410 ? "gone" : e === 422 || e === 400 ? "validation_failed" : e === 429 ? "rate_limited" : e >= 500 ? "server_error" : "unknown";
100
163
  }
101
- function z(e, r, n) {
102
- let d = e.replace(/\/+$/, ""), m = r.startsWith("/") ? r : `/${r}`, c = new URL(`${d}${m}`);
164
+ function ee(e, t, n) {
165
+ let o = e.replace(/\/+$/, ""), i = t.startsWith("/") ? t : `/${t}`, u = new URL(`${o}${i}`);
103
166
  if (n)
104
- for (let [t, i] of Object.entries(n))
105
- i !== void 0 && c.searchParams.set(t, String(i));
106
- return c.toString();
167
+ for (let [r, a] of Object.entries(n))
168
+ a !== void 0 && u.searchParams.set(r, String(a));
169
+ return u.toString();
107
170
  }
108
- async function x(e) {
109
- let r = await e.text();
110
- if (r)
171
+ async function K(e) {
172
+ let t = await e.text();
173
+ if (t)
111
174
  try {
112
- return JSON.parse(r);
175
+ return JSON.parse(t);
113
176
  } catch {
114
177
  return;
115
178
  }
116
179
  }
117
- async function _(e, r) {
118
- let n = r.method ?? "GET", d = z(e.baseUrl, r.path, r.query), m = H.has(n) ? $ : K, c = r.retries ?? m, t = {
119
- accept: "application/json",
120
- ...r.headers
121
- }, i = D();
122
- if (i && (t["x-neetru-sdk-version"] = i), r.requireAuth) {
180
+ async function v(e, t) {
181
+ let n = t.method ?? "GET", o = ee(e.baseUrl, t.path, t.query), i = J.has(n) ? X : Y, u = t.retries ?? i, { headers: r, correlationId: a } = N(
182
+ { accept: "application/json", ...t.headers },
183
+ t.correlationId
184
+ ), l = L();
185
+ if (l && (r["x-neetru-sdk-version"] = l), t.requireAuth) {
123
186
  if (!e.apiKey)
124
- throw new a(
125
- "missing_api_key",
126
- "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
127
- );
128
- t.authorization = `Bearer ${e.apiKey}`;
187
+ throw new d("missing_api_key", G());
188
+ r.authorization = `Bearer ${e.apiKey}`;
129
189
  }
130
- if (r.idempotencyKey) {
131
- let f = typeof r.idempotencyKey == "string" ? r.idempotencyKey : R();
132
- t["idempotency-key"] = f;
190
+ if (t.idempotencyKey) {
191
+ let g = typeof t.idempotencyKey == "string" ? t.idempotencyKey : I();
192
+ r["idempotency-key"] = g;
133
193
  }
134
- let l = r.body !== void 0 && n !== "GET" && n !== "DELETE" ? JSON.stringify(r.body) : void 0;
135
- l !== void 0 && (t["content-type"] = "application/json");
136
- let s = null, u = r.deadlineMs != null ? Date.now() + r.deadlineMs : null;
137
- for (let f = 0; f <= c; f++) {
138
- if (u != null && Date.now() >= u)
139
- throw s ?? new a("network_error", "Deadline excedido antes de completar a request");
140
- let y = { method: n, headers: t };
141
- l !== void 0 && (y.body = l);
142
- let M = u != null ? Math.max(1, Math.min(3e4, u - Date.now())) : 3e4;
143
- y.signal = AbortSignal.timeout(M);
194
+ let c = t.body !== void 0 && n !== "GET" && n !== "DELETE" ? JSON.stringify(t.body) : void 0;
195
+ c !== void 0 && (r["content-type"] = "application/json");
196
+ let f = null, m = t.deadlineMs != null ? Date.now() + t.deadlineMs : null;
197
+ for (let g = 0; g <= u; g++) {
198
+ if (m != null && Date.now() >= m)
199
+ throw f ?? new d(
200
+ "network_error",
201
+ "Deadline excedido antes de completar a request",
202
+ void 0,
203
+ void 0,
204
+ void 0,
205
+ a
206
+ );
207
+ let b = { method: n, headers: r };
208
+ c !== void 0 && (b.body = c);
209
+ let U = m != null ? Math.max(1, Math.min(3e4, m - Date.now())) : 3e4;
210
+ b.signal = AbortSignal.timeout(U);
144
211
  let p;
145
212
  try {
146
- p = await e.fetch(d, y);
147
- } catch (o) {
148
- let w = o instanceof DOMException && o.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${o instanceof Error ? o.message : "fetch failed"}`;
149
- if (s = new a("network_error", w), f < c) {
150
- let k = I(f);
151
- if (u == null || Date.now() + k < u) {
213
+ p = await e.fetch(o, b);
214
+ } catch (s) {
215
+ let _ = s instanceof DOMException && s.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${s instanceof Error ? s.message : "fetch failed"}`;
216
+ if (f = new d("network_error", _, void 0, void 0, void 0, a), g < u) {
217
+ let k = C(g);
218
+ if (m == null || Date.now() + k < m) {
152
219
  await q(k);
153
220
  continue;
154
221
  }
155
222
  }
156
- throw s;
223
+ throw f;
157
224
  }
158
- let P = p.headers.get("x-request-id") ?? p.headers.get("x-correlation-id") ?? void 0;
225
+ let $ = p.headers.get("x-request-id") ?? p.headers.get("x-correlation-id") ?? void 0;
159
226
  if (p.ok) {
160
- let o = p.headers.get("x-neetru-version");
161
- return o && j(o), await x(p);
227
+ let s = p.headers.get("x-neetru-version");
228
+ return s && z(s), await K(p);
162
229
  }
163
- let g = await x(p), b = G(p.status), h = `HTTP ${p.status}`, T;
164
- if (g && typeof g == "object") {
165
- let o = g.error;
166
- typeof o == "string" ? h = o : o && typeof o == "object" ? (typeof o.code == "string" && (b = o.code), typeof o.message == "string" && (h = o.message), typeof o.reason == "string" && (T = o.reason)) : (typeof g.code == "string" && (b = g.code), typeof g.message == "string" && (h = g.message)), typeof g.reason == "string" && (T = g.reason);
230
+ let y = await K(p), w = Z(p.status), h = `HTTP ${p.status}`, E;
231
+ if (y && typeof y == "object") {
232
+ let s = y.error;
233
+ typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (w = s.code), typeof s.message == "string" && (h = s.message), typeof s.reason == "string" && (E = s.reason)) : (typeof y.code == "string" && (w = y.code), typeof y.message == "string" && (h = y.message)), typeof y.reason == "string" && (E = y.reason);
167
234
  }
168
235
  if (p.status === 410) {
169
- let o = p.headers.get("x-neetru-replacement");
170
- h === `HTTP ${p.status}` && (h = `Endpoint ${r.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), o && !h.includes(o) && (h += ` Substituto: ${o}.`);
236
+ let s = p.headers.get("x-neetru-replacement");
237
+ h === `HTTP ${p.status}` && (h = `Endpoint ${t.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), s && !h.includes(s) && (h += ` Substituto: ${s}.`);
171
238
  }
172
- let E = new a(b, h, p.status, P, T);
173
- if (s = E, F.has(b) && f < c) {
174
- let w = V(p.headers.get("retry-after")) ?? I(f);
175
- if (u == null || Date.now() + w < u) {
176
- await q(w);
239
+ let T = new d(w, h, p.status, $, E, a);
240
+ if (f = T, W.has(w) && g < u) {
241
+ let _ = Q(p.headers.get("retry-after")) ?? C(g);
242
+ if (m == null || Date.now() + _ < m) {
243
+ await q(_);
177
244
  continue;
178
245
  }
179
246
  }
180
- throw E;
247
+ throw T;
181
248
  }
182
- throw s ?? new a("unknown", "unexpected httpRequest exit");
249
+ throw f ?? new d("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
183
250
  }
184
251
 
185
252
  // src/telemetry.ts
186
- var N = ["debug", "info", "warn", "error", "fatal"];
187
- function B() {
253
+ var P = ["debug", "info", "warn", "error", "fatal"];
254
+ function te() {
188
255
  return typeof globalThis < "u" && typeof globalThis.window < "u";
189
256
  }
190
- function C() {
191
- return B() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
257
+ function M() {
258
+ return te() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
192
259
  }
193
- function J(e) {
260
+ function re(e) {
194
261
  switch (e) {
195
262
  case "debug":
196
263
  return console.debug.bind(console);
@@ -206,41 +273,41 @@ function J(e) {
206
273
  return console.log.bind(console);
207
274
  }
208
275
  }
209
- var X = 500, Y = 50;
210
- function se(e) {
211
- let r = [], n = null, d = null;
212
- async function m() {
213
- if (r.length === 0) return;
214
- let t = r.splice(0, r.length), i = Promise.allSettled(
215
- t.map(async (l) => {
276
+ var ne = 500, oe = 50;
277
+ function _e(e) {
278
+ let t = [], n = null, o = null;
279
+ async function i() {
280
+ if (t.length === 0) return;
281
+ let r = t.splice(0, t.length), a = Promise.allSettled(
282
+ r.map(async (l) => {
216
283
  try {
217
- let s = { name: l.name }, u = l.productSlug ?? e.productId;
218
- u && (s.productSlug = u), l.properties && typeof l.properties == "object" && (s.properties = l.properties), l.timestamp && (s.timestamp = l.timestamp);
219
- let f = C();
220
- await _(e, {
284
+ let c = { name: l.name }, f = l.productSlug ?? e.productId;
285
+ f && (c.productSlug = f), l.properties && typeof l.properties == "object" && (c.properties = l.properties), l.timestamp && (c.timestamp = l.timestamp);
286
+ let m = M();
287
+ await v(e, {
221
288
  method: "POST",
222
- path: f.path,
223
- body: s,
224
- requireAuth: f.requireAuth,
289
+ path: m.path,
290
+ body: c,
291
+ requireAuth: m.requireAuth,
225
292
  retries: 1,
226
293
  // caça-bruxas: retry sem Idempotency-Key duplicava o evento se o
227
294
  // servidor já tinha persistido antes da falha transiente. Mesmo
228
295
  // padrão do usage.report (key estável por chamada, reusada no retry).
229
296
  idempotencyKey: !0
230
297
  });
231
- } catch (s) {
232
- typeof console < "u" && console.warn("[neetru-sdk] telemetry.track flush failed for event", l.name, s);
298
+ } catch (c) {
299
+ typeof console < "u" && console.warn("[neetru-sdk] telemetry.track flush failed for event", l.name, c);
233
300
  }
234
301
  })
235
302
  );
236
- d = i.then(() => {
237
- d = null;
238
- }), await i, n = null, r.length > 0 && c();
303
+ o = a.then(() => {
304
+ o = null;
305
+ }), await a, n = null, t.length > 0 && u();
239
306
  }
240
- function c() {
307
+ function u() {
241
308
  n || (n = setTimeout(() => {
242
- m();
243
- }, X));
309
+ i();
310
+ }, ne));
244
311
  }
245
312
  return {
246
313
  /**
@@ -255,24 +322,24 @@ function se(e) {
255
322
  * });
256
323
  * ```
257
324
  */
258
- async event(t) {
259
- if (!t || typeof t != "object")
260
- throw new a("validation_failed", "event input is required");
261
- if (typeof t.name != "string" || t.name.length === 0)
262
- throw new a("validation_failed", "event.name is required");
263
- if (t.name.length > 128)
264
- throw new a("validation_failed", "event.name max 128 chars");
265
- let i = { name: t.name }, l = t.productSlug ?? e.productId;
266
- l && (i.productSlug = l), t.properties && typeof t.properties == "object" && (i.properties = t.properties), t.timestamp && (i.timestamp = t.timestamp);
267
- let s = C(), u = await _(e, {
325
+ async event(r) {
326
+ if (!r || typeof r != "object")
327
+ throw new d("validation_failed", "event input is required");
328
+ if (typeof r.name != "string" || r.name.length === 0)
329
+ throw new d("validation_failed", "event.name is required");
330
+ if (r.name.length > 128)
331
+ throw new d("validation_failed", "event.name max 128 chars");
332
+ let a = { name: r.name }, l = r.productSlug ?? e.productId;
333
+ l && (a.productSlug = l), r.properties && typeof r.properties == "object" && (a.properties = r.properties), r.timestamp && (a.timestamp = r.timestamp);
334
+ let c = M(), f = await v(e, {
268
335
  method: "POST",
269
- path: s.path,
270
- body: i,
271
- requireAuth: s.requireAuth
336
+ path: c.path,
337
+ body: a,
338
+ requireAuth: c.requireAuth
272
339
  });
273
- if (!u || u.ok !== true || typeof u.eventId != "string")
274
- throw new a("invalid_response", "Telemetry response missing eventId");
275
- return { ok: true, eventId: u.eventId };
340
+ if (!f || f.ok !== true || typeof f.eventId != "string")
341
+ throw new d("invalid_response", "Telemetry response missing eventId");
342
+ return { ok: true, eventId: f.eventId };
276
343
  },
277
344
  /**
278
345
  * Fire-and-forget: enqueue + flush 500ms debounce. Não retorna `eventId`
@@ -284,15 +351,15 @@ function se(e) {
284
351
  * // segue execução; flush async em background
285
352
  * ```
286
353
  */
287
- track(t) {
288
- !t || typeof t != "object" || typeof t.name != "string" || t.name.length === 0 || t.name.length > 128 || (r.push(t), r.length >= Y ? (n && (clearTimeout(n), n = null), m()) : c());
354
+ track(r) {
355
+ !r || typeof r != "object" || typeof r.name != "string" || r.name.length === 0 || r.name.length > 128 || (t.push(r), t.length >= oe ? (n && (clearTimeout(n), n = null), i()) : u());
289
356
  },
290
357
  /**
291
358
  * Força flush imediato da queue de `track()`. Resolva antes de
292
359
  * page unload / SSR boundary pra não perder eventos.
293
360
  */
294
361
  async flush() {
295
- n && (clearTimeout(n), n = null), d && await d, await m();
362
+ n && (clearTimeout(n), n = null), o && await o, await i();
296
363
  },
297
364
  /**
298
365
  * Registra um log estruturado per-product (Sprint 6).
@@ -309,49 +376,49 @@ function se(e) {
309
376
  * });
310
377
  * ```
311
378
  */
312
- async log(t) {
313
- if (!t || typeof t != "object")
314
- throw new a("validation_failed", "log input is required");
315
- if (!N.includes(t.level))
316
- throw new a("validation_failed", `level must be one of ${N.join(", ")}`);
317
- if (typeof t.message != "string" || t.message.length === 0)
318
- throw new a("validation_failed", "message is required");
319
- if (t.message.length > 4e3)
320
- throw new a("validation_failed", "message max 4000 chars");
379
+ async log(r) {
380
+ if (!r || typeof r != "object")
381
+ throw new d("validation_failed", "log input is required");
382
+ if (!P.includes(r.level))
383
+ throw new d("validation_failed", `level must be one of ${P.join(", ")}`);
384
+ if (typeof r.message != "string" || r.message.length === 0)
385
+ throw new d("validation_failed", "message is required");
386
+ if (r.message.length > 4e3)
387
+ throw new d("validation_failed", "message max 4000 chars");
321
388
  if (e.env === "dev")
322
- return J(t.level)(`[neetru-sdk] ${t.level}: ${t.message}`, t.metadata ?? {}), { ok: true, mode: "mock" };
323
- let i = {
324
- level: t.level,
325
- message: t.message
389
+ return re(r.level)(`[neetru-sdk] ${r.level}: ${r.message}`, r.metadata ?? {}), { ok: true, mode: "mock" };
390
+ let a = {
391
+ level: r.level,
392
+ message: r.message
326
393
  };
327
- t.metadata && (i.metadata = t.metadata);
328
- let l = t.productSlug ?? e.productId;
329
- l && (i.productSlug = l);
330
- let s = t.correlationId;
331
- if (!s)
394
+ r.metadata && (a.metadata = r.metadata);
395
+ let l = r.productSlug ?? e.productId;
396
+ l && (a.productSlug = l);
397
+ let c = r.correlationId;
398
+ if (!c)
332
399
  try {
333
- let y = globalThis.NEETRU_CORRELATION_ID;
334
- typeof y == "string" && y.length > 0 && (s = y);
400
+ let g = globalThis.NEETRU_CORRELATION_ID;
401
+ typeof g == "string" && g.length > 0 && (c = g);
335
402
  } catch {
336
403
  }
337
- let u = {};
338
- s && (u["x-correlation-id"] = s);
339
- let f = await _(e, {
404
+ let f = {};
405
+ c && (f["x-correlation-id"] = c);
406
+ let m = await v(e, {
340
407
  method: "POST",
341
408
  path: "/api/sdk/v1/telemetry/log",
342
- body: i,
409
+ body: a,
343
410
  requireAuth: true,
344
- headers: u
411
+ headers: f
345
412
  });
346
- if (!f || f.ok !== true)
347
- throw new a("invalid_response", "Telemetry log response missing ok");
413
+ if (!m || m.ok !== true)
414
+ throw new d("invalid_response", "Telemetry log response missing ok");
348
415
  return {
349
416
  ok: true,
350
- logId: typeof f.logId == "string" ? f.logId : void 0,
417
+ logId: typeof m.logId == "string" ? m.logId : void 0,
351
418
  mode: "http"
352
419
  };
353
420
  }
354
421
  };
355
422
  }
356
423
 
357
- exports.createTelemetryNamespace = se;
424
+ exports.createTelemetryNamespace = _e;
@@ -1,4 +1,4 @@
1
- import { ag as ResolvedConfig, as as TelemetryEventInput, ar as TelemetryEventAck, au as TelemetryLogInput, at as TelemetryLogAck } from './types-Bx4kTLmk.cjs';
1
+ import { ah as ResolvedConfig, at as TelemetryEventInput, as as TelemetryEventAck, av as TelemetryLogInput, au as TelemetryLogAck } from './types-yv3EDKg2.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { ag as ResolvedConfig, as as TelemetryEventInput, ar as TelemetryEventAck, au as TelemetryLogInput, at as TelemetryLogAck } from './types-Dx0IrOSF.js';
1
+ import { ah as ResolvedConfig, at as TelemetryEventInput, as as TelemetryEventAck, av as TelemetryLogInput, au as TelemetryLogAck } from './types-BYPk_3HR.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4