@neetru/sdk 3.7.0 → 3.8.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 (73) hide show
  1. package/CHANGELOG.md +55 -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 +1227 -1064
  8. package/dist/auth.d.cts +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/auth.mjs +1224 -1061
  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 +370 -298
  22. package/dist/db.d.cts +1 -1
  23. package/dist/db.d.ts +1 -1
  24. package/dist/db.mjs +362 -290
  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 +1409 -1075
  36. package/dist/index.d.cts +177 -3
  37. package/dist/index.d.ts +177 -3
  38. package/dist/index.mjs +1544 -1217
  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-Bx4kTLmk.d.cts → types-D-9bjlM0.d.cts} +48 -1
  64. package/dist/{types-Dx0IrOSF.d.ts → types-bVztFQTI.d.ts} +48 -1
  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
package/dist/mocks.cjs CHANGED
@@ -14,8 +14,15 @@ var l = class m extends Error {
14
14
  * para um `NeetruDbErrorCode` mais específico (recuperável vs não).
15
15
  */
16
16
  reason;
17
- constructor(e, r, i, o, a) {
18
- super(r), this.name = "NeetruError", this.code = e, this.status = i, this.requestId = o, this.reason = a, Object.setPrototypeOf(this, m.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(e, r, i, o, a, c) {
25
+ super(r), this.name = "NeetruError", this.code = e, this.status = i, this.requestId = o, this.reason = a, this.correlationId = c, Object.setPrototypeOf(this, m.prototype);
19
26
  }
20
27
  };
21
28
 
package/dist/mocks.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a5 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, aj as SignInOptions, m as AuthStateListener, ae as RedirectCallbackResult, v as CompleteSignInResult, Y as NeetruDb, E as DbCollectionRef, a4 as NeetruSqlClient, aq as SyncState, av as Unsubscribe, w as ConflictRecord, O as EntitlementCheck, al as SupportNamespace, y as CreateTicketInput, ao as SupportTicket, ax as UsageNamespace, ay as UsageQuota } from './types-Bx4kTLmk.cjs';
1
+ import { a6 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, ak as SignInOptions, m as AuthStateListener, af as RedirectCallbackResult, v as CompleteSignInResult, Z as NeetruDb, E as DbCollectionRef, a5 as NeetruSqlClient, ar as SyncState, aw as Unsubscribe, w as ConflictRecord, P as EntitlementCheck, am as SupportNamespace, y as CreateTicketInput, ap as SupportTicket, ay as UsageNamespace, az as UsageQuota } from './types-D-9bjlM0.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
4
4
 
package/dist/mocks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a5 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, aj as SignInOptions, m as AuthStateListener, ae as RedirectCallbackResult, v as CompleteSignInResult, Y as NeetruDb, E as DbCollectionRef, a4 as NeetruSqlClient, aq as SyncState, av as Unsubscribe, w as ConflictRecord, O as EntitlementCheck, al as SupportNamespace, y as CreateTicketInput, ao as SupportTicket, ax as UsageNamespace, ay as UsageQuota } from './types-Dx0IrOSF.js';
1
+ import { a6 as NeetruUser, g as AiNamespace, b as AiChatOptions, c as AiChatResult, i as AiStreamHandle, l as AuthNamespace, ak as SignInOptions, m as AuthStateListener, af as RedirectCallbackResult, v as CompleteSignInResult, Z as NeetruDb, E as DbCollectionRef, a5 as NeetruSqlClient, ar as SyncState, aw as Unsubscribe, w as ConflictRecord, P as EntitlementCheck, am as SupportNamespace, y as CreateTicketInput, ap as SupportTicket, ay as UsageNamespace, az as UsageQuota } from './types-bVztFQTI.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4
 
package/dist/mocks.mjs CHANGED
@@ -12,8 +12,15 @@ var l = class m extends Error {
12
12
  * para um `NeetruDbErrorCode` mais específico (recuperável vs não).
13
13
  */
14
14
  reason;
15
- constructor(e, r, i, o, a) {
16
- super(r), this.name = "NeetruError", this.code = e, this.status = i, this.requestId = o, this.reason = a, Object.setPrototypeOf(this, m.prototype);
15
+ /**
16
+ * 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
17
+ * chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
18
+ * mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
19
+ * `undefined` em erros que acontecem antes de qualquer requisição.
20
+ */
21
+ correlationId;
22
+ constructor(e, r, i, o, a, c) {
23
+ super(r), this.name = "NeetruError", this.code = e, this.status = i, this.requestId = o, this.reason = a, this.correlationId = c, Object.setPrototypeOf(this, m.prototype);
17
24
  }
18
25
  };
19
26
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // src/errors.ts
4
- var n = class t extends Error {
4
+ var i = class t extends Error {
5
5
  code;
6
6
  status;
7
7
  requestId;
@@ -14,98 +14,161 @@ var n = class t extends Error {
14
14
  * para um `NeetruDbErrorCode` mais específico (recuperável vs não).
15
15
  */
16
16
  reason;
17
- constructor(e, r, i, o, s) {
18
- super(r), this.name = "NeetruError", this.code = e, this.status = i, this.requestId = o, this.reason = s, Object.setPrototypeOf(this, t.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(e, r, n, o, s, d) {
25
+ super(r), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = o, this.reason = s, this.correlationId = d, Object.setPrototypeOf(this, t.prototype);
19
26
  }
20
27
  };
21
28
 
22
29
  // src/idempotency.ts
23
- function S() {
30
+ function x() {
24
31
  let t = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
25
32
  if (t && typeof t.randomUUID == "function")
26
33
  return t.randomUUID();
27
- throw new n(
34
+ throw new i(
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 D = "x-correlation-id";
42
+ var B = /^[A-Za-z0-9._:\-]+$/;
43
+ function T(t) {
44
+ return typeof t == "string" && t.length > 0 && t.length <= 128 && B.test(t);
45
+ }
46
+ function G() {
47
+ let t = globalThis.crypto;
48
+ try {
49
+ if (t && typeof t.randomUUID == "function") return t.randomUUID();
50
+ } catch {
51
+ }
52
+ let e = new Uint8Array(16), r = false;
53
+ try {
54
+ t && typeof t.getRandomValues == "function" && (t.getRandomValues(e), r = !0);
55
+ } catch {
56
+ r = false;
57
+ }
58
+ if (!r)
59
+ for (let o = 0; o < e.length; o++) e[o] = Math.floor(Math.random() * 256);
60
+ e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
61
+ let n = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
62
+ return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
63
+ }
64
+ function O(t, e) {
65
+ let r, n = {};
66
+ for (let [s, d] of Object.entries(t)) {
67
+ if (s.toLowerCase() === D) {
68
+ T(d) && (r = d);
69
+ continue;
70
+ }
71
+ n[s] = d;
72
+ }
73
+ let o = r ?? (T(e) ? e : void 0) ?? G();
74
+ return n[D] = o, { headers: n, correlationId: o };
75
+ }
76
+
77
+ // src/server-only-key.ts
78
+ function P() {
79
+ try {
80
+ let t = globalThis.navigator;
81
+ if (t && t.product === "ReactNative") return "react-native";
82
+ } catch {
83
+ }
84
+ try {
85
+ let t = globalThis;
86
+ if (typeof t.window < "u" && typeof t.document < "u") return "browser";
87
+ } catch {
88
+ }
89
+ return null;
90
+ }
91
+
33
92
  // src/http.ts
34
- var L = {
93
+ var X = {
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(t) {
98
+ function k(t) {
40
99
  return t.split("+")[0] ?? t;
41
100
  }
42
- function H(t, e) {
43
- let r = v(t).split(".").map(Number), i = v(e).split(".").map(Number), o = Math.max(r.length, i.length);
101
+ function Y(t, e) {
102
+ let r = k(t).split(".").map(Number), n = k(e).split(".").map(Number), o = Math.max(r.length, n.length);
44
103
  for (let s = 0; s < o; s++) {
45
- let c = r[s] ?? 0, f = i[s] ?? 0;
46
- if (c !== f) return c - f;
104
+ let d = r[s] ?? 0, u = n[s] ?? 0;
105
+ if (d !== u) return d - u;
47
106
  }
48
107
  return 0;
49
108
  }
50
- function C() {
109
+ function q() {
51
110
  try {
52
- return "3.7.0";
111
+ return "3.8.0";
53
112
  } catch {
54
113
  return;
55
114
  }
56
115
  }
57
- function V() {
58
- let t = C();
116
+ function J() {
117
+ let t = q();
59
118
  return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
60
119
  }
61
- var x = /* @__PURE__ */ new Set();
62
- function z(t) {
120
+ var C = /* @__PURE__ */ new Set();
121
+ function W(t) {
63
122
  if (!t) return;
64
- let e = V(), r = L[e];
123
+ let e = J(), r = X[e];
65
124
  if (!r) return;
66
- let i = v(t);
67
- if (H(i, r) < 0) {
68
- let o = `${e}:${i}`;
69
- x.has(o) || (x.add(o), console.warn(
125
+ let n = k(t);
126
+ if (Y(n, r) < 0) {
127
+ let o = `${e}:${n}`;
128
+ C.has(o) || (C.add(o), console.warn(
70
129
  `[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${t}" \xE9 anterior ao m\xEDnimo recomendado "${r}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
71
130
  ));
72
131
  }
73
132
  }
74
- var F = 2, G = 0, B = /* @__PURE__ */ new Set(["GET", "HEAD"]), J = /* @__PURE__ */ new Set([
133
+ function Z() {
134
+ let t = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
135
+ return P() ? "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;
136
+ }
137
+ var Q = 2, ee = 0, te = /* @__PURE__ */ new Set(["GET", "HEAD"]), re = /* @__PURE__ */ new Set([
75
138
  "rate_limited",
76
139
  "server_error",
77
140
  "network_error"
78
141
  ]);
79
- function T(t) {
142
+ function U(t) {
80
143
  let e = 200 * Math.pow(4, t), r = e * 0.2 * (Math.random() * 2 - 1);
81
144
  return Math.max(50, Math.round(e + r));
82
145
  }
83
- var P = 6e4;
84
- function Y(t) {
146
+ var M = 6e4;
147
+ function ne(t) {
85
148
  if (!t) return null;
86
149
  let e = Number(t);
87
- if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), P);
150
+ if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), M);
88
151
  let r = Date.parse(t);
89
152
  if (Number.isFinite(r)) {
90
- let i = r - Date.now();
91
- if (i > 0) return Math.min(i, P);
153
+ let n = r - Date.now();
154
+ if (n > 0) return Math.min(n, M);
92
155
  }
93
156
  return null;
94
157
  }
95
- function D(t) {
158
+ function $(t) {
96
159
  return new Promise((e) => setTimeout(e, t));
97
160
  }
98
- function W(t) {
161
+ function oe(t) {
99
162
  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";
100
163
  }
101
- function X(t, e, r) {
102
- let i = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, s = new URL(`${i}${o}`);
164
+ function ie(t, e, r) {
165
+ let n = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, s = new URL(`${n}${o}`);
103
166
  if (r)
104
- for (let [c, f] of Object.entries(r))
105
- f !== void 0 && s.searchParams.set(c, String(f));
167
+ for (let [d, u] of Object.entries(r))
168
+ u !== void 0 && s.searchParams.set(d, String(u));
106
169
  return s.toString();
107
170
  }
108
- async function O(t) {
171
+ async function K(t) {
109
172
  let e = await t.text();
110
173
  if (e)
111
174
  try {
@@ -115,97 +178,101 @@ async function O(t) {
115
178
  }
116
179
  }
117
180
  async function h(t, e) {
118
- let r = e.method ?? "GET", i = X(t.baseUrl, e.path, e.query), o = B.has(r) ? F : G, s = e.retries ?? o, c = {
119
- accept: "application/json",
120
- ...e.headers
121
- }, f = C();
122
- if (f && (c["x-neetru-sdk-version"] = f), e.requireAuth) {
181
+ let r = e.method ?? "GET", n = ie(t.baseUrl, e.path, e.query), o = te.has(r) ? Q : ee, s = e.retries ?? o, { headers: d, correlationId: u } = O(
182
+ { accept: "application/json", ...e.headers },
183
+ e.correlationId
184
+ ), E = q();
185
+ if (E && (d["x-neetru-sdk-version"] = E), e.requireAuth) {
123
186
  if (!t.apiKey)
124
- throw new n(
125
- "missing_api_key",
126
- "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
127
- );
128
- c.authorization = `Bearer ${t.apiKey}`;
187
+ throw new i("missing_api_key", Z());
188
+ d.authorization = `Bearer ${t.apiKey}`;
129
189
  }
130
190
  if (e.idempotencyKey) {
131
- let m = typeof e.idempotencyKey == "string" ? e.idempotencyKey : S();
132
- c["idempotency-key"] = m;
191
+ let p = typeof e.idempotencyKey == "string" ? e.idempotencyKey : x();
192
+ d["idempotency-key"] = p;
133
193
  }
134
- let _ = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
135
- _ !== void 0 && (c["content-type"] = "application/json");
194
+ let b = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
195
+ b !== void 0 && (d["content-type"] = "application/json");
136
196
  let g = null, l = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
137
- for (let m = 0; m <= s; m++) {
197
+ for (let p = 0; p <= s; p++) {
138
198
  if (l != null && Date.now() >= l)
139
- throw g ?? new n("network_error", "Deadline excedido antes de completar a request");
140
- let k = { method: r, headers: c };
141
- _ !== void 0 && (k.body = _);
142
- let j = l != null ? Math.max(1, Math.min(3e4, l - Date.now())) : 3e4;
143
- k.signal = AbortSignal.timeout(j);
144
- let d;
199
+ throw g ?? new i(
200
+ "network_error",
201
+ "Deadline excedido antes de completar a request",
202
+ void 0,
203
+ void 0,
204
+ void 0,
205
+ u
206
+ );
207
+ let v = { method: r, headers: d };
208
+ b !== void 0 && (v.body = b);
209
+ let z = l != null ? Math.max(1, Math.min(3e4, l - Date.now())) : 3e4;
210
+ v.signal = AbortSignal.timeout(z);
211
+ let c;
145
212
  try {
146
- d = await t.fetch(i, k);
213
+ c = await t.fetch(n, v);
147
214
  } catch (a) {
148
215
  let y = a instanceof DOMException && a.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${a instanceof Error ? a.message : "fetch failed"}`;
149
- if (g = new n("network_error", y), m < s) {
150
- let R = T(m);
151
- if (l == null || Date.now() + R < l) {
152
- await D(R);
216
+ if (g = new i("network_error", y, void 0, void 0, void 0, u), p < s) {
217
+ let A = U(p);
218
+ if (l == null || Date.now() + A < l) {
219
+ await $(A);
153
220
  continue;
154
221
  }
155
222
  }
156
223
  throw g;
157
224
  }
158
- let K = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
159
- if (d.ok) {
160
- let a = d.headers.get("x-neetru-version");
161
- return a && z(a), await O(d);
225
+ let F = c.headers.get("x-request-id") ?? c.headers.get("x-correlation-id") ?? void 0;
226
+ if (c.ok) {
227
+ let a = c.headers.get("x-neetru-version");
228
+ return a && W(a), await K(c);
162
229
  }
163
- let u = await O(d), w = W(d.status), p = `HTTP ${d.status}`, I;
164
- if (u && typeof u == "object") {
165
- let a = u.error;
166
- typeof a == "string" ? p = a : a && typeof a == "object" ? (typeof a.code == "string" && (w = a.code), typeof a.message == "string" && (p = a.message), typeof a.reason == "string" && (I = a.reason)) : (typeof u.code == "string" && (w = u.code), typeof u.message == "string" && (p = u.message)), typeof u.reason == "string" && (I = u.reason);
230
+ let f = await K(c), _ = oe(c.status), m = `HTTP ${c.status}`, I;
231
+ if (f && typeof f == "object") {
232
+ let a = f.error;
233
+ typeof a == "string" ? m = a : a && typeof a == "object" ? (typeof a.code == "string" && (_ = a.code), typeof a.message == "string" && (m = a.message), typeof a.reason == "string" && (I = a.reason)) : (typeof f.code == "string" && (_ = f.code), typeof f.message == "string" && (m = f.message)), typeof f.reason == "string" && (I = f.reason);
167
234
  }
168
- if (d.status === 410) {
169
- let a = d.headers.get("x-neetru-replacement");
170
- p === `HTTP ${d.status}` && (p = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), a && !p.includes(a) && (p += ` Substituto: ${a}.`);
235
+ if (c.status === 410) {
236
+ let a = c.headers.get("x-neetru-replacement");
237
+ m === `HTTP ${c.status}` && (m = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), a && !m.includes(a) && (m += ` Substituto: ${a}.`);
171
238
  }
172
- let A = new n(w, p, d.status, K, I);
173
- if (g = A, J.has(w) && m < s) {
174
- let y = Y(d.headers.get("retry-after")) ?? T(m);
239
+ let S = new i(_, m, c.status, F, I, u);
240
+ if (g = S, re.has(_) && p < s) {
241
+ let y = ne(c.headers.get("retry-after")) ?? U(p);
175
242
  if (l == null || Date.now() + y < l) {
176
- await D(y);
243
+ await $(y);
177
244
  continue;
178
245
  }
179
246
  }
180
- throw A;
247
+ throw S;
181
248
  }
182
- throw g ?? new n("unknown", "unexpected httpRequest exit");
249
+ throw g ?? new i("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, u);
183
250
  }
184
251
 
185
252
  // src/validators.ts
186
- var q = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
253
+ var L = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
187
254
  function N(t, e) {
188
- if (typeof e != "string" || !q.test(e))
189
- throw new n(
255
+ if (typeof e != "string" || !L.test(e))
256
+ throw new i(
190
257
  "validation_failed",
191
- `${t} must match ${q.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
258
+ `${t} must match ${L.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
192
259
  );
193
260
  }
194
261
 
195
262
  // src/notifications.ts
196
- var E = [
263
+ var R = [
197
264
  "info",
198
265
  "success",
199
266
  "warning",
200
267
  "error"
201
268
  ];
202
- function M(t) {
269
+ function j(t) {
203
270
  if (!t || typeof t != "object")
204
- throw new n("invalid_response", "Notification response is not an object");
271
+ throw new i("invalid_response", "Notification response is not an object");
205
272
  let e = t;
206
273
  if (typeof e.id != "string")
207
- throw new n("invalid_response", "Notification missing id");
208
- let r = E.includes(e.severity) ? e.severity : "info";
274
+ throw new i("invalid_response", "Notification missing id");
275
+ let r = R.includes(e.severity) ? e.severity : "info";
209
276
  return {
210
277
  id: e.id,
211
278
  userId: typeof e.userId == "string" ? e.userId : "",
@@ -220,56 +287,56 @@ function M(t) {
220
287
  dismissedAt: typeof e.dismissedAt == "string" ? e.dismissedAt : void 0
221
288
  };
222
289
  }
223
- function $(t) {
224
- if (!t.userId) throw new n("validation_failed", "userId obrigat\xF3rio");
225
- if (!t.kind) throw new n("validation_failed", "kind obrigat\xF3rio");
226
- if (!t.title) throw new n("validation_failed", "title obrigat\xF3rio");
227
- if (t.severity && !E.includes(t.severity))
228
- throw new n(
290
+ function H(t) {
291
+ if (!t.userId) throw new i("validation_failed", "userId obrigat\xF3rio");
292
+ if (!t.kind) throw new i("validation_failed", "kind obrigat\xF3rio");
293
+ if (!t.title) throw new i("validation_failed", "title obrigat\xF3rio");
294
+ if (t.severity && !R.includes(t.severity))
295
+ throw new i(
229
296
  "validation_failed",
230
- `severity inv\xE1lida: ${t.severity} (use ${E.join("|")})`
297
+ `severity inv\xE1lida: ${t.severity} (use ${R.join("|")})`
231
298
  );
232
299
  if (t.title.length > 200)
233
- throw new n("validation_failed", "title m\xE1x 200 chars");
300
+ throw new i("validation_failed", "title m\xE1x 200 chars");
234
301
  if (t.body && t.body.length > 2e3)
235
- throw new n("validation_failed", "body m\xE1x 2000 chars");
302
+ throw new i("validation_failed", "body m\xE1x 2000 chars");
236
303
  }
237
- function b(t, ...e) {
304
+ function w(t, ...e) {
238
305
  for (let r of e)
239
306
  if (typeof r == "string" && r.length > 0)
240
307
  return N("productId", r), r;
241
308
  if (t.productId)
242
309
  return N("productId", t.productId), t.productId;
243
- throw new n(
310
+ throw new i(
244
311
  "validation_failed",
245
312
  "productId required (pass to options/input or set on createNeetruClient)"
246
313
  );
247
314
  }
248
- function ue(t) {
315
+ function Ie(t) {
249
316
  return {
250
317
  async send(e) {
251
- $(e);
252
- let i = {
253
- productId: b(t, e.productId),
318
+ H(e);
319
+ let n = {
320
+ productId: w(t, e.productId),
254
321
  userId: e.userId,
255
322
  kind: e.kind,
256
323
  title: e.title,
257
324
  severity: e.severity ?? "info"
258
325
  };
259
- e.body !== void 0 && (i.body = e.body), e.link !== void 0 && (i.link = e.link), e.metadata !== void 0 && (i.metadata = e.metadata), e.fingerprint !== void 0 && (i.fingerprint = e.fingerprint);
326
+ e.body !== void 0 && (n.body = e.body), e.link !== void 0 && (n.link = e.link), e.metadata !== void 0 && (n.metadata = e.metadata), e.fingerprint !== void 0 && (n.fingerprint = e.fingerprint);
260
327
  let o = await h(t, {
261
328
  method: "POST",
262
329
  path: "/api/sdk/v1/notifications",
263
- body: i,
330
+ body: n,
264
331
  requireAuth: true,
265
332
  idempotencyKey: true
266
333
  });
267
- return M(o);
334
+ return j(o);
268
335
  },
269
336
  async list(e, r) {
270
- if (!e) throw new n("validation_failed", "userId obrigat\xF3rio");
337
+ if (!e) throw new i("validation_failed", "userId obrigat\xF3rio");
271
338
  let o = {
272
- productId: b(t, r?.productId)
339
+ productId: w(t, r?.productId)
273
340
  };
274
341
  r?.includeDismissed && (o.includeDismissed = true), r?.onlyUnread && (o.onlyUnread = true), r?.limit && (o.limit = Math.min(Math.max(1, r.limit), 200));
275
342
  let s = await h(t, {
@@ -278,41 +345,41 @@ function ue(t) {
278
345
  query: o,
279
346
  requireAuth: true
280
347
  });
281
- return (Array.isArray(s?.notifications) ? s.notifications : []).map(M);
348
+ return (Array.isArray(s?.notifications) ? s.notifications : []).map(j);
282
349
  },
283
350
  async markRead(e, r) {
284
- if (!e) throw new n("validation_failed", "id obrigat\xF3rio");
285
- let i = b(t, r?.productId);
351
+ if (!e) throw new i("validation_failed", "id obrigat\xF3rio");
352
+ let n = w(t, r?.productId);
286
353
  return await h(t, {
287
354
  method: "POST",
288
355
  path: `/api/sdk/v1/notifications/${encodeURIComponent(e)}/read`,
289
- query: { productId: i },
356
+ query: { productId: n },
290
357
  requireAuth: true
291
358
  }), { ok: true };
292
359
  },
293
360
  async dismiss(e, r) {
294
- if (!e) throw new n("validation_failed", "id obrigat\xF3rio");
295
- let i = b(t, r?.productId);
361
+ if (!e) throw new i("validation_failed", "id obrigat\xF3rio");
362
+ let n = w(t, r?.productId);
296
363
  return await h(t, {
297
364
  method: "POST",
298
365
  path: `/api/sdk/v1/notifications/${encodeURIComponent(e)}/dismiss`,
299
- query: { productId: i },
366
+ query: { productId: n },
300
367
  requireAuth: true
301
368
  }), { ok: true };
302
369
  }
303
370
  };
304
371
  }
305
- var U = class {
372
+ var V = class {
306
373
  notifications = /* @__PURE__ */ new Map();
307
374
  nextId = 1;
308
375
  async send(e) {
309
- if ($(e), e.fingerprint) {
376
+ if (H(e), e.fingerprint) {
310
377
  let o = Date.now() - 864e5;
311
378
  for (let s of this.notifications.values())
312
379
  if ((s.metadata ?? {}).fingerprint === e.fingerprint && s.userId === e.userId && new Date(s.createdAt).getTime() > o)
313
380
  return s;
314
381
  }
315
- let r = `mock_notif_${this.nextId++}`, i = {
382
+ let r = `mock_notif_${this.nextId++}`, n = {
316
383
  id: r,
317
384
  userId: e.userId,
318
385
  kind: e.kind,
@@ -323,24 +390,24 @@ var U = class {
323
390
  metadata: e.fingerprint ? { ...e.metadata ?? {}, fingerprint: e.fingerprint } : e.metadata,
324
391
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
325
392
  };
326
- return this.notifications.set(r, i), i;
393
+ return this.notifications.set(r, n), n;
327
394
  }
328
395
  async list(e, r) {
329
- if (!e) throw new n("validation_failed", "userId obrigat\xF3rio");
330
- let i = Math.min(Math.max(1, r?.limit ?? 50), 200);
331
- return [...this.notifications.values()].filter((o) => o.userId === e).filter((o) => r?.includeDismissed || !o.dismissedAt).filter((o) => !r?.onlyUnread || !o.readAt).sort((o, s) => s.createdAt.localeCompare(o.createdAt)).slice(0, i);
396
+ if (!e) throw new i("validation_failed", "userId obrigat\xF3rio");
397
+ let n = Math.min(Math.max(1, r?.limit ?? 50), 200);
398
+ return [...this.notifications.values()].filter((o) => o.userId === e).filter((o) => r?.includeDismissed || !o.dismissedAt).filter((o) => !r?.onlyUnread || !o.readAt).sort((o, s) => s.createdAt.localeCompare(o.createdAt)).slice(0, n);
332
399
  }
333
400
  async markRead(e, r) {
334
- let i = this.notifications.get(e);
335
- if (!i) throw new n("not_found", `Notification ${e} n\xE3o encontrada`);
336
- return i.readAt || (i.readAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, i)), { ok: true };
401
+ let n = this.notifications.get(e);
402
+ if (!n) throw new i("not_found", `Notification ${e} n\xE3o encontrada`);
403
+ return n.readAt || (n.readAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, n)), { ok: true };
337
404
  }
338
405
  async dismiss(e, r) {
339
- let i = this.notifications.get(e);
340
- if (!i) throw new n("not_found", `Notification ${e} n\xE3o encontrada`);
341
- return i.dismissedAt || (i.dismissedAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, i)), { ok: true };
406
+ let n = this.notifications.get(e);
407
+ if (!n) throw new i("not_found", `Notification ${e} n\xE3o encontrada`);
408
+ return n.dismissedAt || (n.dismissedAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, n)), { ok: true };
342
409
  }
343
410
  };
344
411
 
345
- exports.MockNotifications = U;
346
- exports.createNotificationsNamespace = ue;
412
+ exports.MockNotifications = V;
413
+ exports.createNotificationsNamespace = Ie;
@@ -1,3 +1,3 @@
1
- export { R as ListNotificationsOptions, T as MockNotifications, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a9 as ProductNotification, aa as ProductNotificationSeverity, ah as SendNotificationInput, aM as createNotificationsNamespace } from './types-Bx4kTLmk.cjs';
1
+ export { S as ListNotificationsOptions, U as MockNotifications, a7 as NotificationScopeOptions, a8 as NotificationsNamespace, aa as ProductNotification, ab as ProductNotificationSeverity, ai as SendNotificationInput, aN as createNotificationsNamespace } from './types-D-9bjlM0.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
@@ -1,3 +1,3 @@
1
- export { R as ListNotificationsOptions, T as MockNotifications, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a9 as ProductNotification, aa as ProductNotificationSeverity, ah as SendNotificationInput, aM as createNotificationsNamespace } from './types-Dx0IrOSF.js';
1
+ export { S as ListNotificationsOptions, U as MockNotifications, a7 as NotificationScopeOptions, a8 as NotificationsNamespace, aa as ProductNotification, ab as ProductNotificationSeverity, ai as SendNotificationInput, aN as createNotificationsNamespace } from './types-bVztFQTI.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';