@neetru/sdk 3.8.0 → 3.9.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +4 -1
  3. package/dist/ai.cjs +1 -1
  4. package/dist/ai.d.cts +1 -1
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.mjs +1 -1
  7. package/dist/auth.cjs +1171 -1110
  8. package/dist/auth.d.cts +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/auth.mjs +1168 -1107
  11. package/dist/catalog.cjs +1 -1
  12. package/dist/catalog.d.cts +1 -1
  13. package/dist/catalog.d.ts +1 -1
  14. package/dist/catalog.mjs +1 -1
  15. package/dist/checkout.cjs +62 -49
  16. package/dist/checkout.d.cts +1 -1
  17. package/dist/checkout.d.ts +1 -1
  18. package/dist/checkout.mjs +62 -49
  19. package/dist/db-react.d.cts +1 -1
  20. package/dist/db-react.d.ts +1 -1
  21. package/dist/db.cjs +303 -270
  22. package/dist/db.d.cts +1 -1
  23. package/dist/db.d.ts +1 -1
  24. package/dist/db.mjs +322 -289
  25. package/dist/entitlements.d.cts +1 -1
  26. package/dist/entitlements.d.ts +1 -1
  27. package/dist/firestore-compat.d.cts +1 -1
  28. package/dist/firestore-compat.d.ts +1 -1
  29. package/dist/index.cjs +1275 -1214
  30. package/dist/index.d.cts +2 -2
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.mjs +1390 -1329
  33. package/dist/mobile.cjs +328 -276
  34. package/dist/mobile.d.cts +12 -2
  35. package/dist/mobile.d.ts +12 -2
  36. package/dist/mobile.mjs +328 -276
  37. package/dist/mocks.cjs +5 -5
  38. package/dist/mocks.d.cts +2 -2
  39. package/dist/mocks.d.ts +2 -2
  40. package/dist/mocks.mjs +4 -4
  41. package/dist/notifications.cjs +1 -1
  42. package/dist/notifications.d.cts +1 -1
  43. package/dist/notifications.d.ts +1 -1
  44. package/dist/notifications.mjs +1 -1
  45. package/dist/react.cjs +119 -119
  46. package/dist/react.d.cts +8 -2
  47. package/dist/react.d.ts +8 -2
  48. package/dist/react.mjs +119 -119
  49. package/dist/support.cjs +1 -1
  50. package/dist/support.d.cts +1 -1
  51. package/dist/support.d.ts +1 -1
  52. package/dist/support.mjs +1 -1
  53. package/dist/telemetry.cjs +62 -49
  54. package/dist/telemetry.d.cts +1 -1
  55. package/dist/telemetry.d.ts +1 -1
  56. package/dist/telemetry.mjs +62 -49
  57. package/dist/{types-D-9bjlM0.d.cts → types-Bl_4HROd.d.cts} +118 -19
  58. package/dist/{types-bVztFQTI.d.ts → types-Bqnsqvow.d.ts} +118 -19
  59. package/dist/usage.cjs +1 -1
  60. package/dist/usage.d.cts +1 -1
  61. package/dist/usage.d.ts +1 -1
  62. package/dist/usage.mjs +1 -1
  63. package/dist/webhooks.cjs +1 -1
  64. package/dist/webhooks.d.cts +1 -1
  65. package/dist/webhooks.d.ts +1 -1
  66. package/dist/webhooks.mjs +1 -1
  67. package/package.json +9 -1
@@ -39,11 +39,11 @@ function I() {
39
39
 
40
40
  // src/correlation.ts
41
41
  var A = "x-correlation-id";
42
- var j = /^[A-Za-z0-9._:\-]+$/;
42
+ var H = /^[A-Za-z0-9._:\-]+$/;
43
43
  function S(e) {
44
- return typeof e == "string" && e.length > 0 && e.length <= 128 && j.test(e);
44
+ return typeof e == "string" && e.length > 0 && e.length <= 128 && H.test(e);
45
45
  }
46
- function H() {
46
+ function V() {
47
47
  let e = globalThis.crypto;
48
48
  try {
49
49
  if (e && typeof e.randomUUID == "function") return e.randomUUID();
@@ -70,12 +70,12 @@ function N(e, t) {
70
70
  }
71
71
  o[u] = r;
72
72
  }
73
- let i = n ?? (S(t) ? t : void 0) ?? H();
73
+ let i = n ?? (S(t) ? t : void 0) ?? V();
74
74
  return o[A] = i, { headers: o, correlationId: i };
75
75
  }
76
76
 
77
77
  // src/server-only-key.ts
78
- function x() {
78
+ function D() {
79
79
  try {
80
80
  let e = globalThis.navigator;
81
81
  if (e && e.product === "ReactNative") return "react-native";
@@ -98,7 +98,7 @@ var F = {
98
98
  function R(e) {
99
99
  return e.split("+")[0] ?? e;
100
100
  }
101
- function V(e, t) {
101
+ function B(e, t) {
102
102
  let n = R(e).split(".").map(Number), o = R(t).split(".").map(Number), i = Math.max(n.length, o.length);
103
103
  for (let u = 0; u < i; u++) {
104
104
  let r = n[u] ?? 0, a = o[u] ?? 0;
@@ -106,35 +106,35 @@ function V(e, t) {
106
106
  }
107
107
  return 0;
108
108
  }
109
- function L() {
109
+ function P() {
110
110
  try {
111
- return "3.8.0";
111
+ return "3.9.0";
112
112
  } catch {
113
113
  return;
114
114
  }
115
115
  }
116
- function B() {
117
- let e = L();
116
+ function z() {
117
+ let e = P();
118
118
  return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
119
119
  }
120
- var D = /* @__PURE__ */ new Set();
121
- function z(e) {
120
+ var x = /* @__PURE__ */ new Set();
121
+ function G(e) {
122
122
  if (!e) return;
123
- let t = B(), n = F[t];
123
+ let t = z(), n = F[t];
124
124
  if (!n) return;
125
125
  let o = R(e);
126
- if (V(o, n) < 0) {
126
+ if (B(o, n) < 0) {
127
127
  let i = `${t}:${o}`;
128
- D.has(i) || (D.add(i), console.warn(
128
+ x.has(i) || (x.add(i), console.warn(
129
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.`
130
130
  ));
131
131
  }
132
132
  }
133
- function G() {
133
+ function X() {
134
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;
135
+ return D() ? "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
136
  }
137
- var X = 2, Y = 0, J = /* @__PURE__ */ new Set(["GET", "HEAD"]), W = /* @__PURE__ */ new Set([
137
+ var Y = 2, J = 0, W = /* @__PURE__ */ new Set(["GET", "HEAD"]), Q = /* @__PURE__ */ new Set([
138
138
  "rate_limited",
139
139
  "server_error",
140
140
  "network_error"
@@ -144,7 +144,7 @@ function C(e) {
144
144
  return Math.max(50, Math.round(t + n));
145
145
  }
146
146
  var O = 6e4;
147
- function Q(e) {
147
+ function Z(e) {
148
148
  if (!e) return null;
149
149
  let t = Number(e);
150
150
  if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3), O);
@@ -158,17 +158,17 @@ function Q(e) {
158
158
  function q(e) {
159
159
  return new Promise((t) => setTimeout(t, e));
160
160
  }
161
- function Z(e) {
161
+ function ee(e) {
162
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";
163
163
  }
164
- function ee(e, t, n) {
164
+ function te(e, t, n) {
165
165
  let o = e.replace(/\/+$/, ""), i = t.startsWith("/") ? t : `/${t}`, u = new URL(`${o}${i}`);
166
166
  if (n)
167
167
  for (let [r, a] of Object.entries(n))
168
168
  a !== void 0 && u.searchParams.set(r, String(a));
169
169
  return u.toString();
170
170
  }
171
- async function K(e) {
171
+ async function M(e) {
172
172
  let t = await e.text();
173
173
  if (t)
174
174
  try {
@@ -178,13 +178,13 @@ async function K(e) {
178
178
  }
179
179
  }
180
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(
181
+ let n = t.method ?? "GET", o = te(e.baseUrl, t.path, t.query), i = W.has(n) ? Y : J, u = t.retries ?? i, { headers: r, correlationId: a } = N(
182
182
  { accept: "application/json", ...t.headers },
183
183
  t.correlationId
184
- ), l = L();
184
+ ), l = P();
185
185
  if (l && (r["x-neetru-sdk-version"] = l), t.requireAuth) {
186
186
  if (!e.apiKey)
187
- throw new d("missing_api_key", G());
187
+ throw new d("missing_api_key", X());
188
188
  r.authorization = `Bearer ${e.apiKey}`;
189
189
  }
190
190
  if (t.idempotencyKey) {
@@ -206,8 +206,8 @@ async function v(e, t) {
206
206
  );
207
207
  let b = { method: n, headers: r };
208
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);
209
+ let $ = m != null ? Math.max(1, Math.min(3e4, m - Date.now())) : 3e4;
210
+ b.signal = AbortSignal.timeout($);
211
211
  let p;
212
212
  try {
213
213
  p = await e.fetch(o, b);
@@ -222,12 +222,12 @@ async function v(e, t) {
222
222
  }
223
223
  throw f;
224
224
  }
225
- let $ = p.headers.get("x-request-id") ?? p.headers.get("x-correlation-id") ?? void 0;
225
+ let j = p.headers.get("x-request-id") ?? p.headers.get("x-correlation-id") ?? void 0;
226
226
  if (p.ok) {
227
227
  let s = p.headers.get("x-neetru-version");
228
- return s && z(s), await K(p);
228
+ return s && G(s), await M(p);
229
229
  }
230
- let y = await K(p), w = Z(p.status), h = `HTTP ${p.status}`, E;
230
+ let y = await M(p), w = ee(p.status), h = `HTTP ${p.status}`, E;
231
231
  if (y && typeof y == "object") {
232
232
  let s = y.error;
233
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);
@@ -236,9 +236,9 @@ async function v(e, t) {
236
236
  let s = p.headers.get("x-neetru-replacement");
237
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}.`);
238
238
  }
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);
239
+ let T = new d(w, h, p.status, j, E, a);
240
+ if (f = T, Q.has(w) && g < u) {
241
+ let _ = Z(p.headers.get("retry-after")) ?? C(g);
242
242
  if (m == null || Date.now() + _ < m) {
243
243
  await q(_);
244
244
  continue;
@@ -249,15 +249,28 @@ async function v(e, t) {
249
249
  throw f ?? new d("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
250
250
  }
251
251
 
252
+ // src/runtime-env.ts
253
+ function re() {
254
+ try {
255
+ if (typeof process < "u" && process.env)
256
+ return process.env.NODE_ENV === "production";
257
+ } catch {
258
+ }
259
+ return false;
260
+ }
261
+ function K(e) {
262
+ return e === "dev" && !re();
263
+ }
264
+
252
265
  // src/telemetry.ts
253
- var P = ["debug", "info", "warn", "error", "fatal"];
254
- function te() {
266
+ var L = ["debug", "info", "warn", "error", "fatal"];
267
+ function ne() {
255
268
  return typeof globalThis < "u" && typeof globalThis.window < "u";
256
269
  }
257
- function M() {
258
- return te() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
270
+ function U() {
271
+ return ne() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
259
272
  }
260
- function re(e) {
273
+ function oe(e) {
261
274
  switch (e) {
262
275
  case "debug":
263
276
  return console.debug.bind(console);
@@ -273,8 +286,8 @@ function re(e) {
273
286
  return console.log.bind(console);
274
287
  }
275
288
  }
276
- var ne = 500, oe = 50;
277
- function _e(e) {
289
+ var ie = 500, se = 50;
290
+ function Ee(e) {
278
291
  let t = [], n = null, o = null;
279
292
  async function i() {
280
293
  if (t.length === 0) return;
@@ -283,7 +296,7 @@ function _e(e) {
283
296
  try {
284
297
  let c = { name: l.name }, f = l.productSlug ?? e.productId;
285
298
  f && (c.productSlug = f), l.properties && typeof l.properties == "object" && (c.properties = l.properties), l.timestamp && (c.timestamp = l.timestamp);
286
- let m = M();
299
+ let m = U();
287
300
  await v(e, {
288
301
  method: "POST",
289
302
  path: m.path,
@@ -307,7 +320,7 @@ function _e(e) {
307
320
  function u() {
308
321
  n || (n = setTimeout(() => {
309
322
  i();
310
- }, ne));
323
+ }, ie));
311
324
  }
312
325
  return {
313
326
  /**
@@ -331,7 +344,7 @@ function _e(e) {
331
344
  throw new d("validation_failed", "event.name max 128 chars");
332
345
  let a = { name: r.name }, l = r.productSlug ?? e.productId;
333
346
  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, {
347
+ let c = U(), f = await v(e, {
335
348
  method: "POST",
336
349
  path: c.path,
337
350
  body: a,
@@ -352,7 +365,7 @@ function _e(e) {
352
365
  * ```
353
366
  */
354
367
  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());
368
+ !r || typeof r != "object" || typeof r.name != "string" || r.name.length === 0 || r.name.length > 128 || (t.push(r), t.length >= se ? (n && (clearTimeout(n), n = null), i()) : u());
356
369
  },
357
370
  /**
358
371
  * Força flush imediato da queue de `track()`. Resolva antes de
@@ -379,14 +392,14 @@ function _e(e) {
379
392
  async log(r) {
380
393
  if (!r || typeof r != "object")
381
394
  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(", ")}`);
395
+ if (!L.includes(r.level))
396
+ throw new d("validation_failed", `level must be one of ${L.join(", ")}`);
384
397
  if (typeof r.message != "string" || r.message.length === 0)
385
398
  throw new d("validation_failed", "message is required");
386
399
  if (r.message.length > 4e3)
387
400
  throw new d("validation_failed", "message max 4000 chars");
388
- if (e.env === "dev")
389
- return re(r.level)(`[neetru-sdk] ${r.level}: ${r.message}`, r.metadata ?? {}), { ok: true, mode: "mock" };
401
+ if (K(e.env))
402
+ return oe(r.level)(`[neetru-sdk] ${r.level}: ${r.message}`, r.metadata ?? {}), { ok: true, mode: "mock" };
390
403
  let a = {
391
404
  level: r.level,
392
405
  message: r.message
@@ -421,4 +434,4 @@ function _e(e) {
421
434
  };
422
435
  }
423
436
 
424
- exports.createTelemetryNamespace = _e;
437
+ exports.createTelemetryNamespace = Ee;
@@ -1,4 +1,4 @@
1
- import { ah as ResolvedConfig, at as TelemetryEventInput, as as TelemetryEventAck, av as TelemetryLogInput, au as TelemetryLogAck } from './types-D-9bjlM0.cjs';
1
+ import { ai as ResolvedConfig, av as TelemetryEventInput, au as TelemetryEventAck, ax as TelemetryLogInput, aw as TelemetryLogAck } from './types-Bl_4HROd.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { ah as ResolvedConfig, at as TelemetryEventInput, as as TelemetryEventAck, av as TelemetryLogInput, au as TelemetryLogAck } from './types-bVztFQTI.js';
1
+ import { ai as ResolvedConfig, av as TelemetryEventInput, au as TelemetryEventAck, ax as TelemetryLogInput, aw as TelemetryLogAck } from './types-Bqnsqvow.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4
 
@@ -37,11 +37,11 @@ function I() {
37
37
 
38
38
  // src/correlation.ts
39
39
  var A = "x-correlation-id";
40
- var j = /^[A-Za-z0-9._:\-]+$/;
40
+ var H = /^[A-Za-z0-9._:\-]+$/;
41
41
  function S(e) {
42
- return typeof e == "string" && e.length > 0 && e.length <= 128 && j.test(e);
42
+ return typeof e == "string" && e.length > 0 && e.length <= 128 && H.test(e);
43
43
  }
44
- function H() {
44
+ function V() {
45
45
  let e = globalThis.crypto;
46
46
  try {
47
47
  if (e && typeof e.randomUUID == "function") return e.randomUUID();
@@ -68,12 +68,12 @@ function N(e, t) {
68
68
  }
69
69
  o[u] = r;
70
70
  }
71
- let i = n ?? (S(t) ? t : void 0) ?? H();
71
+ let i = n ?? (S(t) ? t : void 0) ?? V();
72
72
  return o[A] = i, { headers: o, correlationId: i };
73
73
  }
74
74
 
75
75
  // src/server-only-key.ts
76
- function x() {
76
+ function D() {
77
77
  try {
78
78
  let e = globalThis.navigator;
79
79
  if (e && e.product === "ReactNative") return "react-native";
@@ -96,7 +96,7 @@ var F = {
96
96
  function R(e) {
97
97
  return e.split("+")[0] ?? e;
98
98
  }
99
- function V(e, t) {
99
+ function B(e, t) {
100
100
  let n = R(e).split(".").map(Number), o = R(t).split(".").map(Number), i = Math.max(n.length, o.length);
101
101
  for (let u = 0; u < i; u++) {
102
102
  let r = n[u] ?? 0, a = o[u] ?? 0;
@@ -104,35 +104,35 @@ function V(e, t) {
104
104
  }
105
105
  return 0;
106
106
  }
107
- function L() {
107
+ function P() {
108
108
  try {
109
- return "3.8.0";
109
+ return "3.9.0";
110
110
  } catch {
111
111
  return;
112
112
  }
113
113
  }
114
- function B() {
115
- let e = L();
114
+ function z() {
115
+ let e = P();
116
116
  return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
117
117
  }
118
- var D = /* @__PURE__ */ new Set();
119
- function z(e) {
118
+ var x = /* @__PURE__ */ new Set();
119
+ function G(e) {
120
120
  if (!e) return;
121
- let t = B(), n = F[t];
121
+ let t = z(), n = F[t];
122
122
  if (!n) return;
123
123
  let o = R(e);
124
- if (V(o, n) < 0) {
124
+ if (B(o, n) < 0) {
125
125
  let i = `${t}:${o}`;
126
- D.has(i) || (D.add(i), console.warn(
126
+ x.has(i) || (x.add(i), console.warn(
127
127
  `[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.`
128
128
  ));
129
129
  }
130
130
  }
131
- function G() {
131
+ function X() {
132
132
  let e = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
133
- 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;
133
+ return D() ? "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;
134
134
  }
135
- var X = 2, Y = 0, J = /* @__PURE__ */ new Set(["GET", "HEAD"]), W = /* @__PURE__ */ new Set([
135
+ var Y = 2, J = 0, W = /* @__PURE__ */ new Set(["GET", "HEAD"]), Q = /* @__PURE__ */ new Set([
136
136
  "rate_limited",
137
137
  "server_error",
138
138
  "network_error"
@@ -142,7 +142,7 @@ function C(e) {
142
142
  return Math.max(50, Math.round(t + n));
143
143
  }
144
144
  var O = 6e4;
145
- function Q(e) {
145
+ function Z(e) {
146
146
  if (!e) return null;
147
147
  let t = Number(e);
148
148
  if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3), O);
@@ -156,17 +156,17 @@ function Q(e) {
156
156
  function q(e) {
157
157
  return new Promise((t) => setTimeout(t, e));
158
158
  }
159
- function Z(e) {
159
+ function ee(e) {
160
160
  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";
161
161
  }
162
- function ee(e, t, n) {
162
+ function te(e, t, n) {
163
163
  let o = e.replace(/\/+$/, ""), i = t.startsWith("/") ? t : `/${t}`, u = new URL(`${o}${i}`);
164
164
  if (n)
165
165
  for (let [r, a] of Object.entries(n))
166
166
  a !== void 0 && u.searchParams.set(r, String(a));
167
167
  return u.toString();
168
168
  }
169
- async function K(e) {
169
+ async function M(e) {
170
170
  let t = await e.text();
171
171
  if (t)
172
172
  try {
@@ -176,13 +176,13 @@ async function K(e) {
176
176
  }
177
177
  }
178
178
  async function v(e, t) {
179
- 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(
179
+ let n = t.method ?? "GET", o = te(e.baseUrl, t.path, t.query), i = W.has(n) ? Y : J, u = t.retries ?? i, { headers: r, correlationId: a } = N(
180
180
  { accept: "application/json", ...t.headers },
181
181
  t.correlationId
182
- ), l = L();
182
+ ), l = P();
183
183
  if (l && (r["x-neetru-sdk-version"] = l), t.requireAuth) {
184
184
  if (!e.apiKey)
185
- throw new d("missing_api_key", G());
185
+ throw new d("missing_api_key", X());
186
186
  r.authorization = `Bearer ${e.apiKey}`;
187
187
  }
188
188
  if (t.idempotencyKey) {
@@ -204,8 +204,8 @@ async function v(e, t) {
204
204
  );
205
205
  let b = { method: n, headers: r };
206
206
  c !== void 0 && (b.body = c);
207
- let U = m != null ? Math.max(1, Math.min(3e4, m - Date.now())) : 3e4;
208
- b.signal = AbortSignal.timeout(U);
207
+ let $ = m != null ? Math.max(1, Math.min(3e4, m - Date.now())) : 3e4;
208
+ b.signal = AbortSignal.timeout($);
209
209
  let p;
210
210
  try {
211
211
  p = await e.fetch(o, b);
@@ -220,12 +220,12 @@ async function v(e, t) {
220
220
  }
221
221
  throw f;
222
222
  }
223
- let $ = p.headers.get("x-request-id") ?? p.headers.get("x-correlation-id") ?? void 0;
223
+ let j = p.headers.get("x-request-id") ?? p.headers.get("x-correlation-id") ?? void 0;
224
224
  if (p.ok) {
225
225
  let s = p.headers.get("x-neetru-version");
226
- return s && z(s), await K(p);
226
+ return s && G(s), await M(p);
227
227
  }
228
- let y = await K(p), w = Z(p.status), h = `HTTP ${p.status}`, E;
228
+ let y = await M(p), w = ee(p.status), h = `HTTP ${p.status}`, E;
229
229
  if (y && typeof y == "object") {
230
230
  let s = y.error;
231
231
  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);
@@ -234,9 +234,9 @@ async function v(e, t) {
234
234
  let s = p.headers.get("x-neetru-replacement");
235
235
  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}.`);
236
236
  }
237
- let T = new d(w, h, p.status, $, E, a);
238
- if (f = T, W.has(w) && g < u) {
239
- let _ = Q(p.headers.get("retry-after")) ?? C(g);
237
+ let T = new d(w, h, p.status, j, E, a);
238
+ if (f = T, Q.has(w) && g < u) {
239
+ let _ = Z(p.headers.get("retry-after")) ?? C(g);
240
240
  if (m == null || Date.now() + _ < m) {
241
241
  await q(_);
242
242
  continue;
@@ -247,15 +247,28 @@ async function v(e, t) {
247
247
  throw f ?? new d("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
248
248
  }
249
249
 
250
+ // src/runtime-env.ts
251
+ function re() {
252
+ try {
253
+ if (typeof process < "u" && process.env)
254
+ return process.env.NODE_ENV === "production";
255
+ } catch {
256
+ }
257
+ return false;
258
+ }
259
+ function K(e) {
260
+ return e === "dev" && !re();
261
+ }
262
+
250
263
  // src/telemetry.ts
251
- var P = ["debug", "info", "warn", "error", "fatal"];
252
- function te() {
264
+ var L = ["debug", "info", "warn", "error", "fatal"];
265
+ function ne() {
253
266
  return typeof globalThis < "u" && typeof globalThis.window < "u";
254
267
  }
255
- function M() {
256
- return te() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
268
+ function U() {
269
+ return ne() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
257
270
  }
258
- function re(e) {
271
+ function oe(e) {
259
272
  switch (e) {
260
273
  case "debug":
261
274
  return console.debug.bind(console);
@@ -271,8 +284,8 @@ function re(e) {
271
284
  return console.log.bind(console);
272
285
  }
273
286
  }
274
- var ne = 500, oe = 50;
275
- function _e(e) {
287
+ var ie = 500, se = 50;
288
+ function Ee(e) {
276
289
  let t = [], n = null, o = null;
277
290
  async function i() {
278
291
  if (t.length === 0) return;
@@ -281,7 +294,7 @@ function _e(e) {
281
294
  try {
282
295
  let c = { name: l.name }, f = l.productSlug ?? e.productId;
283
296
  f && (c.productSlug = f), l.properties && typeof l.properties == "object" && (c.properties = l.properties), l.timestamp && (c.timestamp = l.timestamp);
284
- let m = M();
297
+ let m = U();
285
298
  await v(e, {
286
299
  method: "POST",
287
300
  path: m.path,
@@ -305,7 +318,7 @@ function _e(e) {
305
318
  function u() {
306
319
  n || (n = setTimeout(() => {
307
320
  i();
308
- }, ne));
321
+ }, ie));
309
322
  }
310
323
  return {
311
324
  /**
@@ -329,7 +342,7 @@ function _e(e) {
329
342
  throw new d("validation_failed", "event.name max 128 chars");
330
343
  let a = { name: r.name }, l = r.productSlug ?? e.productId;
331
344
  l && (a.productSlug = l), r.properties && typeof r.properties == "object" && (a.properties = r.properties), r.timestamp && (a.timestamp = r.timestamp);
332
- let c = M(), f = await v(e, {
345
+ let c = U(), f = await v(e, {
333
346
  method: "POST",
334
347
  path: c.path,
335
348
  body: a,
@@ -350,7 +363,7 @@ function _e(e) {
350
363
  * ```
351
364
  */
352
365
  track(r) {
353
- !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());
366
+ !r || typeof r != "object" || typeof r.name != "string" || r.name.length === 0 || r.name.length > 128 || (t.push(r), t.length >= se ? (n && (clearTimeout(n), n = null), i()) : u());
354
367
  },
355
368
  /**
356
369
  * Força flush imediato da queue de `track()`. Resolva antes de
@@ -377,14 +390,14 @@ function _e(e) {
377
390
  async log(r) {
378
391
  if (!r || typeof r != "object")
379
392
  throw new d("validation_failed", "log input is required");
380
- if (!P.includes(r.level))
381
- throw new d("validation_failed", `level must be one of ${P.join(", ")}`);
393
+ if (!L.includes(r.level))
394
+ throw new d("validation_failed", `level must be one of ${L.join(", ")}`);
382
395
  if (typeof r.message != "string" || r.message.length === 0)
383
396
  throw new d("validation_failed", "message is required");
384
397
  if (r.message.length > 4e3)
385
398
  throw new d("validation_failed", "message max 4000 chars");
386
- if (e.env === "dev")
387
- return re(r.level)(`[neetru-sdk] ${r.level}: ${r.message}`, r.metadata ?? {}), { ok: true, mode: "mock" };
399
+ if (K(e.env))
400
+ return oe(r.level)(`[neetru-sdk] ${r.level}: ${r.message}`, r.metadata ?? {}), { ok: true, mode: "mock" };
388
401
  let a = {
389
402
  level: r.level,
390
403
  message: r.message
@@ -419,4 +432,4 @@ function _e(e) {
419
432
  };
420
433
  }
421
434
 
422
- export { _e as createTelemetryNamespace };
435
+ export { Ee as createTelemetryNamespace };