@neetru/sdk 3.8.1 → 3.9.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 (71) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +14 -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 +844 -803
  8. package/dist/auth.d.cts +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/auth.mjs +841 -800
  11. package/dist/build-guard.cjs +186 -82
  12. package/dist/build-guard.d.cts +53 -1
  13. package/dist/build-guard.d.ts +53 -1
  14. package/dist/build-guard.mjs +175 -74
  15. package/dist/catalog.cjs +1 -1
  16. package/dist/catalog.d.cts +1 -1
  17. package/dist/catalog.d.ts +1 -1
  18. package/dist/catalog.mjs +1 -1
  19. package/dist/checkout.cjs +62 -49
  20. package/dist/checkout.d.cts +1 -1
  21. package/dist/checkout.d.ts +1 -1
  22. package/dist/checkout.mjs +62 -49
  23. package/dist/db-react.d.cts +1 -1
  24. package/dist/db-react.d.ts +1 -1
  25. package/dist/db.cjs +200 -187
  26. package/dist/db.d.cts +1 -1
  27. package/dist/db.d.ts +1 -1
  28. package/dist/db.mjs +193 -180
  29. package/dist/entitlements.d.cts +1 -1
  30. package/dist/entitlements.d.ts +1 -1
  31. package/dist/firestore-compat.d.cts +1 -1
  32. package/dist/firestore-compat.d.ts +1 -1
  33. package/dist/index.cjs +880 -839
  34. package/dist/index.d.cts +2 -2
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.mjs +847 -806
  37. package/dist/mobile.cjs +328 -276
  38. package/dist/mobile.d.cts +12 -2
  39. package/dist/mobile.d.ts +12 -2
  40. package/dist/mobile.mjs +328 -276
  41. package/dist/mocks.cjs +5 -5
  42. package/dist/mocks.d.cts +2 -2
  43. package/dist/mocks.d.ts +2 -2
  44. package/dist/mocks.mjs +4 -4
  45. package/dist/notifications.cjs +1 -1
  46. package/dist/notifications.d.cts +1 -1
  47. package/dist/notifications.d.ts +1 -1
  48. package/dist/notifications.mjs +1 -1
  49. package/dist/react.cjs +119 -119
  50. package/dist/react.d.cts +8 -2
  51. package/dist/react.d.ts +8 -2
  52. package/dist/react.mjs +119 -119
  53. package/dist/support.cjs +1 -1
  54. package/dist/support.d.cts +1 -1
  55. package/dist/support.d.ts +1 -1
  56. package/dist/support.mjs +1 -1
  57. package/dist/telemetry.cjs +62 -49
  58. package/dist/telemetry.d.cts +1 -1
  59. package/dist/telemetry.d.ts +1 -1
  60. package/dist/telemetry.mjs +62 -49
  61. package/dist/{types-yv3EDKg2.d.cts → types-Bl_4HROd.d.cts} +62 -3
  62. package/dist/{types-BYPk_3HR.d.ts → types-Bqnsqvow.d.ts} +62 -3
  63. package/dist/usage.cjs +1 -1
  64. package/dist/usage.d.cts +1 -1
  65. package/dist/usage.d.ts +1 -1
  66. package/dist/usage.mjs +1 -1
  67. package/dist/webhooks.cjs +1 -1
  68. package/dist/webhooks.d.cts +1 -1
  69. package/dist/webhooks.d.ts +1 -1
  70. package/dist/webhooks.mjs +1 -1
  71. package/package.json +9 -1
@@ -1,3 +1,3 @@
1
- export { o as CheckoutAuthOpts, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, T as MockCheckout, aL as createCheckoutNamespace } from './types-BYPk_3HR.js';
1
+ export { o as CheckoutAuthOpts, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, T as MockCheckout, aN as createCheckoutNamespace } from './types-Bqnsqvow.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
package/dist/checkout.mjs CHANGED
@@ -37,11 +37,11 @@ function E() {
37
37
 
38
38
  // src/correlation.ts
39
39
  var A = "x-correlation-id";
40
- var L = /^[A-Za-z0-9._:\-]+$/;
40
+ var H = /^[A-Za-z0-9._:\-]+$/;
41
41
  function x(t) {
42
- return typeof t == "string" && t.length > 0 && t.length <= 128 && L.test(t);
42
+ return typeof t == "string" && t.length > 0 && t.length <= 128 && H.test(t);
43
43
  }
44
- function H() {
44
+ function B() {
45
45
  let t = globalThis.crypto;
46
46
  try {
47
47
  if (t && typeof t.randomUUID == "function") return t.randomUUID();
@@ -68,7 +68,7 @@ function N(t, e) {
68
68
  }
69
69
  r[a] = c;
70
70
  }
71
- let o = n ?? (x(e) ? e : void 0) ?? H();
71
+ let o = n ?? (x(e) ? e : void 0) ?? B();
72
72
  return r[A] = o, { headers: r, correlationId: o };
73
73
  }
74
74
 
@@ -88,7 +88,7 @@ function D() {
88
88
  }
89
89
 
90
90
  // src/http.ts
91
- var B = {
91
+ var G = {
92
92
  // SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
93
93
  // runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
94
94
  3: "2026.05.1"
@@ -96,7 +96,7 @@ var B = {
96
96
  function b(t) {
97
97
  return t.split("+")[0] ?? t;
98
98
  }
99
- function G(t, e) {
99
+ function F(t, e) {
100
100
  let n = b(t).split(".").map(Number), r = b(e).split(".").map(Number), o = Math.max(n.length, r.length);
101
101
  for (let a = 0; a < o; a++) {
102
102
  let c = n[a] ?? 0, u = r[a] ?? 0;
@@ -106,43 +106,43 @@ function G(t, e) {
106
106
  }
107
107
  function M() {
108
108
  try {
109
- return "3.8.1";
109
+ return "3.9.1";
110
110
  } catch {
111
111
  return;
112
112
  }
113
113
  }
114
- function F() {
114
+ function V() {
115
115
  let t = M();
116
116
  return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
117
117
  }
118
- var U = /* @__PURE__ */ new Set();
119
- function V(t) {
118
+ var O = /* @__PURE__ */ new Set();
119
+ function z(t) {
120
120
  if (!t) return;
121
- let e = F(), n = B[e];
121
+ let e = V(), n = G[e];
122
122
  if (!n) return;
123
123
  let r = b(t);
124
- if (G(r, n) < 0) {
124
+ if (F(r, n) < 0) {
125
125
  let o = `${e}:${r}`;
126
- U.has(o) || (U.add(o), console.warn(
126
+ O.has(o) || (O.add(o), console.warn(
127
127
  `[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${t}" \xE9 anterior ao m\xEDnimo recomendado "${n}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
128
128
  ));
129
129
  }
130
130
  }
131
- function z() {
131
+ function X() {
132
132
  let t = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
133
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. (" + t + ")" : t;
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"]), Z = /* @__PURE__ */ new Set([
136
136
  "rate_limited",
137
137
  "server_error",
138
138
  "network_error"
139
139
  ]);
140
- function O(t) {
140
+ function U(t) {
141
141
  let e = 200 * Math.pow(4, t), n = e * 0.2 * (Math.random() * 2 - 1);
142
142
  return Math.max(50, Math.round(e + n));
143
143
  }
144
144
  var q = 6e4;
145
- function Z(t) {
145
+ function Q(t) {
146
146
  if (!t) return null;
147
147
  let e = Number(t);
148
148
  if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), q);
@@ -156,10 +156,10 @@ function Z(t) {
156
156
  function K(t) {
157
157
  return new Promise((e) => setTimeout(e, t));
158
158
  }
159
- function Q(t) {
159
+ function ee(t) {
160
160
  return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 404 ? "not_found" : t === 409 ? "conflict" : t === 410 ? "gone" : t === 422 || t === 400 ? "validation_failed" : t === 429 ? "rate_limited" : t >= 500 ? "server_error" : "unknown";
161
161
  }
162
- function ee(t, e, n) {
162
+ function te(t, e, n) {
163
163
  let r = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, a = new URL(`${r}${o}`);
164
164
  if (n)
165
165
  for (let [c, u] of Object.entries(n))
@@ -175,14 +175,14 @@ async function P(t) {
175
175
  return;
176
176
  }
177
177
  }
178
- async function y(t, e) {
179
- let n = e.method ?? "GET", r = ee(t.baseUrl, e.path, e.query), o = J.has(n) ? X : Y, a = e.retries ?? o, { headers: c, correlationId: u } = N(
178
+ async function k(t, e) {
179
+ let n = e.method ?? "GET", r = te(t.baseUrl, e.path, e.query), o = W.has(n) ? Y : J, a = e.retries ?? o, { headers: c, correlationId: u } = N(
180
180
  { accept: "application/json", ...e.headers },
181
181
  e.correlationId
182
- ), C = M();
183
- if (C && (c["x-neetru-sdk-version"] = C), e.requireAuth) {
182
+ ), v = M();
183
+ if (v && (c["x-neetru-sdk-version"] = v), e.requireAuth) {
184
184
  if (!t.apiKey)
185
- throw new i("missing_api_key", z());
185
+ throw new i("missing_api_key", X());
186
186
  c.authorization = `Bearer ${t.apiKey}`;
187
187
  }
188
188
  if (e.idempotencyKey) {
@@ -204,15 +204,15 @@ async function y(t, e) {
204
204
  );
205
205
  let _ = { method: n, headers: c };
206
206
  I !== void 0 && (_.body = I);
207
- let $ = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
208
- _.signal = AbortSignal.timeout($);
207
+ let j = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
208
+ _.signal = AbortSignal.timeout(j);
209
209
  let d;
210
210
  try {
211
211
  d = await t.fetch(r, _);
212
212
  } catch (s) {
213
213
  let m = s instanceof DOMException && s.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${s instanceof Error ? s.message : "fetch failed"}`;
214
214
  if (g = new i("network_error", m, void 0, void 0, void 0, u), f < a) {
215
- let S = O(f);
215
+ let S = U(f);
216
216
  if (p == null || Date.now() + S < p) {
217
217
  await K(S);
218
218
  continue;
@@ -220,33 +220,46 @@ async function y(t, e) {
220
220
  }
221
221
  throw g;
222
222
  }
223
- let j = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
223
+ let L = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
224
224
  if (d.ok) {
225
225
  let s = d.headers.get("x-neetru-version");
226
- return s && V(s), await P(d);
226
+ return s && z(s), await P(d);
227
227
  }
228
- let l = await P(d), k = Q(d.status), h = `HTTP ${d.status}`, w;
228
+ let l = await P(d), y = ee(d.status), h = `HTTP ${d.status}`, w;
229
229
  if (l && typeof l == "object") {
230
230
  let s = l.error;
231
- typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (k = s.code), typeof s.message == "string" && (h = s.message), typeof s.reason == "string" && (w = s.reason)) : (typeof l.code == "string" && (k = l.code), typeof l.message == "string" && (h = l.message)), typeof l.reason == "string" && (w = l.reason);
231
+ typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (y = s.code), typeof s.message == "string" && (h = s.message), typeof s.reason == "string" && (w = s.reason)) : (typeof l.code == "string" && (y = l.code), typeof l.message == "string" && (h = l.message)), typeof l.reason == "string" && (w = l.reason);
232
232
  }
233
233
  if (d.status === 410) {
234
234
  let s = d.headers.get("x-neetru-replacement");
235
235
  h === `HTTP ${d.status}` && (h = `Endpoint ${e.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 v = new i(k, h, d.status, j, w, u);
238
- if (g = v, W.has(k) && f < a) {
239
- let m = Z(d.headers.get("retry-after")) ?? O(f);
237
+ let C = new i(y, h, d.status, L, w, u);
238
+ if (g = C, Z.has(y) && f < a) {
239
+ let m = Q(d.headers.get("retry-after")) ?? U(f);
240
240
  if (p == null || Date.now() + m < p) {
241
241
  await K(m);
242
242
  continue;
243
243
  }
244
244
  }
245
- throw v;
245
+ throw C;
246
246
  }
247
247
  throw g ?? new i("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, u);
248
248
  }
249
249
 
250
+ // src/runtime-env.ts
251
+ function ne() {
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 $(t) {
260
+ return t === "dev" && !ne();
261
+ }
262
+
250
263
  // src/checkout.ts
251
264
  function T(t, e) {
252
265
  let n = t?.accessToken || t?.idToken;
@@ -257,7 +270,7 @@ function T(t, e) {
257
270
  );
258
271
  return { requireAuth: false, headers: { authorization: `Bearer ${n}` } };
259
272
  }
260
- function te(t) {
273
+ function re(t) {
261
274
  if (!t || typeof t != "object")
262
275
  throw new i("invalid_response", "checkout.start response is not an object");
263
276
  let e = t;
@@ -273,7 +286,7 @@ function te(t) {
273
286
  requiresKyc: e.requiresKyc === true
274
287
  };
275
288
  }
276
- function ne(t) {
289
+ function oe(t) {
277
290
  if (!t || typeof t != "object")
278
291
  throw new i("invalid_response", "checkout.get response is not an object");
279
292
  let e = t, n = e.intent;
@@ -295,20 +308,20 @@ function ne(t) {
295
308
  isStale: e.isStale === true
296
309
  };
297
310
  }
298
- function re() {
311
+ function ie() {
299
312
  try {
300
313
  return typeof globalThis < "u" && typeof globalThis.window < "u" && typeof globalThis.location < "u" && typeof globalThis.location.assign == "function";
301
314
  } catch {
302
315
  return false;
303
316
  }
304
317
  }
305
- function oe(t) {
318
+ function se(t) {
306
319
  try {
307
320
  globalThis.location.assign(t);
308
321
  } catch {
309
322
  }
310
323
  }
311
- function ie(t) {
324
+ function ae(t) {
312
325
  return {
313
326
  async start(e) {
314
327
  if (!e?.productId)
@@ -326,15 +339,15 @@ function ie(t) {
326
339
  let { requireAuth: r, headers: o } = T(
327
340
  { accessToken: e.accessToken, idToken: e.idToken },
328
341
  "start"
329
- ), a = await y(t, {
342
+ ), a = await k(t, {
330
343
  method: "POST",
331
344
  path: "/api/v1/checkout/intents",
332
345
  body: n,
333
346
  requireAuth: r,
334
347
  headers: o,
335
348
  idempotencyKey: true
336
- }), c = te(a);
337
- return e.autoRedirect !== false && re() && oe(c.redirectUrl), c;
349
+ }), c = re(a);
350
+ return e.autoRedirect !== false && ie() && se(c.redirectUrl), c;
338
351
  },
339
352
  async get(e, n) {
340
353
  if (!e || typeof e != "string")
@@ -342,13 +355,13 @@ function ie(t) {
342
355
  let { requireAuth: r, headers: o } = T(
343
356
  { accessToken: n?.accessToken, idToken: n?.idToken },
344
357
  "get"
345
- ), a = await y(t, {
358
+ ), a = await k(t, {
346
359
  method: "GET",
347
360
  path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
348
361
  requireAuth: r,
349
362
  headers: o
350
363
  });
351
- return ne(a);
364
+ return oe(a);
352
365
  },
353
366
  async cancel(e, n) {
354
367
  if (!e || typeof e != "string")
@@ -359,7 +372,7 @@ function ie(t) {
359
372
  );
360
373
  return {
361
374
  ok: true,
362
- alreadyCancelled: (await y(t, {
375
+ alreadyCancelled: (await k(t, {
363
376
  method: "DELETE",
364
377
  path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
365
378
  requireAuth: r,
@@ -412,8 +425,8 @@ var R = class {
412
425
  return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled: o };
413
426
  }
414
427
  };
415
- function Ie(t) {
416
- return t.env === "dev" ? new R() : ie(t);
428
+ function Te(t) {
429
+ return $(t.env) ? new R() : ae(t);
417
430
  }
418
431
 
419
- export { R as MockCheckout, Ie as createCheckoutNamespace };
432
+ export { R as MockCheckout, Te as createCheckoutNamespace };
@@ -1,4 +1,4 @@
1
- import { ar as SyncState, aw as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } from './types-yv3EDKg2.cjs';
1
+ import { at as SyncState, ay as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } 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 { ar as SyncState, aw as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } from './types-BYPk_3HR.js';
1
+ import { at as SyncState, ay as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } from './types-Bqnsqvow.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4