@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/db.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  import { openDB } from 'idb';
2
2
 
3
- var Ve = Object.defineProperty;
4
- var T = (r, e) => () => (r && (e = r(r = 0)), e);
5
- var he = (r, e) => {
3
+ var Je = Object.defineProperty;
4
+ var S = (r, e) => () => (r && (e = r(r = 0)), e);
5
+ var me = (r, e) => {
6
6
  for (var t in e)
7
- Ve(r, t, { get: e[t], enumerable: true });
7
+ Je(r, t, { get: e[t], enumerable: true });
8
8
  };
9
9
 
10
10
  // src/errors.ts
11
- var g, x = T(() => {
11
+ var g, x = S(() => {
12
12
  g = class r extends Error {
13
13
  code;
14
14
  status;
@@ -22,16 +22,23 @@ var g, x = T(() => {
22
22
  * para um `NeetruDbErrorCode` mais específico (recuperável vs não).
23
23
  */
24
24
  reason;
25
- constructor(e, t, n, o, i) {
26
- super(t), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = o, this.reason = i, Object.setPrototypeOf(this, r.prototype);
25
+ /**
26
+ * 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
27
+ * chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
28
+ * mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
29
+ * `undefined` em erros que acontecem antes de qualquer requisição.
30
+ */
31
+ correlationId;
32
+ constructor(e, t, n, o, i, s) {
33
+ super(t), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = o, this.reason = i, this.correlationId = s, Object.setPrototypeOf(this, r.prototype);
27
34
  }
28
35
  };
29
36
  });
30
37
 
31
38
  // src/db-errors.ts
32
- var Qe, p, k = T(() => {
39
+ var Ye, p, I = S(() => {
33
40
  x();
34
- Qe = /* @__PURE__ */ new Set([
41
+ Ye = /* @__PURE__ */ new Set([
35
42
  "db_unavailable",
36
43
  "db_conflict",
37
44
  "db_timeout"
@@ -49,13 +56,13 @@ var Qe, p, k = T(() => {
49
56
  */
50
57
  dbId;
51
58
  constructor(e, t, n) {
52
- super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable = Qe.has(e), this.dbId = n, Object.setPrototypeOf(this, r.prototype);
59
+ super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable = Ye.has(e), this.dbId = n, Object.setPrototypeOf(this, r.prototype);
53
60
  }
54
61
  };
55
62
  });
56
63
 
57
64
  // src/idempotency.ts
58
- function Se() {
65
+ function Te() {
59
66
  let r = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
60
67
  if (r && typeof r.randomUUID == "function")
61
68
  return r.randomUUID();
@@ -64,21 +71,76 @@ function Se() {
64
71
  "crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
65
72
  );
66
73
  }
67
- var Te = T(() => {
74
+ var Re = S(() => {
68
75
  x();
69
76
  });
70
77
 
78
+ // src/correlation.ts
79
+ function ke(r) {
80
+ return typeof r == "string" && r.length > 0 && r.length <= 128 && vt.test(r);
81
+ }
82
+ function wt() {
83
+ let r = globalThis.crypto;
84
+ try {
85
+ if (r && typeof r.randomUUID == "function") return r.randomUUID();
86
+ } catch {
87
+ }
88
+ let e = new Uint8Array(16), t = false;
89
+ try {
90
+ r && typeof r.getRandomValues == "function" && (r.getRandomValues(e), t = !0);
91
+ } catch {
92
+ t = false;
93
+ }
94
+ if (!t)
95
+ for (let o = 0; o < e.length; o++) e[o] = Math.floor(Math.random() * 256);
96
+ e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
97
+ let n = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
98
+ return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
99
+ }
100
+ function Ce(r, e) {
101
+ let t, n = {};
102
+ for (let [i, s] of Object.entries(r)) {
103
+ if (i.toLowerCase() === De) {
104
+ ke(s) && (t = s);
105
+ continue;
106
+ }
107
+ n[i] = s;
108
+ }
109
+ let o = t ?? (ke(e) ? e : void 0) ?? wt();
110
+ return n[De] = o, { headers: n, correlationId: o };
111
+ }
112
+ var De, vt, Ie = S(() => {
113
+ De = "x-correlation-id", vt = /^[A-Za-z0-9._:\-]+$/;
114
+ });
115
+
116
+ // src/server-only-key.ts
117
+ function Pe() {
118
+ try {
119
+ let r = globalThis.navigator;
120
+ if (r && r.product === "ReactNative") return "react-native";
121
+ } catch {
122
+ }
123
+ try {
124
+ let r = globalThis;
125
+ if (typeof r.window < "u" && typeof r.document < "u") return "browser";
126
+ } catch {
127
+ }
128
+ return null;
129
+ }
130
+ var Ee = S(() => {
131
+ });
132
+
71
133
  // src/http.ts
72
134
  var U = {};
73
- he(U, {
74
- checkCoreVersionCompat: () => Ee,
75
- httpRequest: () => St,
76
- statusToCode: () => Le
135
+ me(U, {
136
+ checkCoreVersionCompat: () => qe,
137
+ httpRequest: () => Mt,
138
+ statusToCode: () => Fe
77
139
  });
78
140
  function se(r) {
79
141
  return r.split("+")[0] ?? r;
80
142
  }
81
- function ht(r, e) {
143
+ function Tt(r, e) {
82
144
  let t = se(r).split(".").map(Number), n = se(e).split(".").map(Number), o = Math.max(t.length, n.length);
83
145
  for (let i = 0; i < o; i++) {
84
146
  let s = t[i] ?? 0, a = n[i] ?? 0;
@@ -86,58 +148,62 @@ function ht(r, e) {
86
148
  }
87
149
  return 0;
88
150
  }
89
- function Ie() {
151
+ function Ne() {
90
152
  try {
91
- return "3.7.0";
153
+ return "3.8.0";
92
154
  } catch {
93
155
  return;
94
156
  }
95
157
  }
96
- function mt() {
97
- let r = Ie();
158
+ function Rt() {
159
+ let r = Ne();
98
160
  return r ? parseInt(r.split(".")[0] ?? "3", 10) : 3;
99
161
  }
100
- function Ee(r) {
162
+ function qe(r) {
101
163
  if (!r) return;
102
- let e = mt(), t = ft[e];
164
+ let e = Rt(), t = St[e];
103
165
  if (!t) return;
104
166
  let n = se(r);
105
- if (ht(n, t) < 0) {
167
+ if (Tt(n, t) < 0) {
106
168
  let o = `${e}:${n}`;
107
- Re.has(o) || (Re.add(o), console.warn(
169
+ Le.has(o) || (Le.add(o), console.warn(
108
170
  `[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${r}" \xE9 anterior ao m\xEDnimo recomendado "${t}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
109
171
  ));
110
172
  }
111
173
  }
112
- function De(r) {
174
+ function Dt() {
175
+ let r = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
176
+ return Pe() ? "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. (" + r + ")" : r;
177
+ }
178
+ function Me(r) {
113
179
  let e = 200 * Math.pow(4, r), t = e * 0.2 * (Math.random() * 2 - 1);
114
180
  return Math.max(50, Math.round(e + t));
115
181
  }
116
- function vt(r) {
182
+ function Et(r) {
117
183
  if (!r) return null;
118
184
  let e = Number(r);
119
- if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), ke);
185
+ if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), Oe);
120
186
  let t = Date.parse(r);
121
187
  if (Number.isFinite(t)) {
122
188
  let n = t - Date.now();
123
- if (n > 0) return Math.min(n, ke);
189
+ if (n > 0) return Math.min(n, Oe);
124
190
  }
125
191
  return null;
126
192
  }
127
- function Ce(r) {
193
+ function xe(r) {
128
194
  return new Promise((e) => setTimeout(e, r));
129
195
  }
130
- function Le(r) {
196
+ function Fe(r) {
131
197
  return r === 401 ? "unauthorized" : r === 403 ? "forbidden" : r === 404 ? "not_found" : r === 409 ? "conflict" : r === 410 ? "gone" : r === 422 || r === 400 ? "validation_failed" : r === 429 ? "rate_limited" : r >= 500 ? "server_error" : "unknown";
132
198
  }
133
- function wt(r, e, t) {
199
+ function Lt(r, e, t) {
134
200
  let n = r.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, i = new URL(`${n}${o}`);
135
201
  if (t)
136
202
  for (let [s, a] of Object.entries(t))
137
203
  a !== void 0 && i.searchParams.set(s, String(a));
138
204
  return i.toString();
139
205
  }
140
- async function Pe(r) {
206
+ async function Ae(r) {
141
207
  let e = await r.text();
142
208
  if (e)
143
209
  try {
@@ -146,95 +212,101 @@ async function Pe(r) {
146
212
  return;
147
213
  }
148
214
  }
149
- async function St(r, e) {
150
- let t = e.method ?? "GET", n = wt(r.baseUrl, e.path, e.query), o = gt.has(t) ? _t : yt, i = e.retries ?? o, s = {
151
- accept: "application/json",
152
- ...e.headers
153
- }, a = Ie();
154
- if (a && (s["x-neetru-sdk-version"] = a), e.requireAuth) {
215
+ async function Mt(r, e) {
216
+ let t = e.method ?? "GET", n = Lt(r.baseUrl, e.path, e.query), o = It.has(t) ? kt : Ct, i = e.retries ?? o, { headers: s, correlationId: a } = Ce(
217
+ { accept: "application/json", ...e.headers },
218
+ e.correlationId
219
+ ), c = Ne();
220
+ if (c && (s["x-neetru-sdk-version"] = c), e.requireAuth) {
155
221
  if (!r.apiKey)
156
- throw new g(
157
- "missing_api_key",
158
- "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
159
- );
222
+ throw new g("missing_api_key", Dt());
160
223
  s.authorization = `Bearer ${r.apiKey}`;
161
224
  }
162
225
  if (e.idempotencyKey) {
163
- let u = typeof e.idempotencyKey == "string" ? e.idempotencyKey : Se();
164
- s["idempotency-key"] = u;
165
- }
166
- let c = e.body !== void 0 && t !== "GET" && t !== "DELETE" ? JSON.stringify(e.body) : void 0;
167
- c !== void 0 && (s["content-type"] = "application/json");
168
- let l = null, d = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
169
- for (let u = 0; u <= i; u++) {
170
- if (d != null && Date.now() >= d)
171
- throw l ?? new g("network_error", "Deadline excedido antes de completar a request");
172
- let f = { method: t, headers: s };
173
- c !== void 0 && (f.body = c);
174
- let _ = d != null ? Math.max(1, Math.min(3e4, d - Date.now())) : 3e4;
175
- f.signal = AbortSignal.timeout(_);
176
- let h;
226
+ let f = typeof e.idempotencyKey == "string" ? e.idempotencyKey : Te();
227
+ s["idempotency-key"] = f;
228
+ }
229
+ let l = e.body !== void 0 && t !== "GET" && t !== "DELETE" ? JSON.stringify(e.body) : void 0;
230
+ l !== void 0 && (s["content-type"] = "application/json");
231
+ let d = null, u = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
232
+ for (let f = 0; f <= i; f++) {
233
+ if (u != null && Date.now() >= u)
234
+ throw d ?? new g(
235
+ "network_error",
236
+ "Deadline excedido antes de completar a request",
237
+ void 0,
238
+ void 0,
239
+ void 0,
240
+ a
241
+ );
242
+ let h = { method: t, headers: s };
243
+ l !== void 0 && (h.body = l);
244
+ let v = u != null ? Math.max(1, Math.min(3e4, u - Date.now())) : 3e4;
245
+ h.signal = AbortSignal.timeout(v);
246
+ let _;
177
247
  try {
178
- h = await r.fetch(n, f);
248
+ _ = await r.fetch(n, h);
179
249
  } catch (m) {
180
250
  let O = m instanceof DOMException && m.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${m instanceof Error ? m.message : "fetch failed"}`;
181
- if (l = new g("network_error", O), u < i) {
182
- let fe = De(u);
183
- if (d == null || Date.now() + fe < d) {
184
- await Ce(fe);
251
+ if (d = new g("network_error", O, void 0, void 0, void 0, a), f < i) {
252
+ let he = Me(f);
253
+ if (u == null || Date.now() + he < u) {
254
+ await xe(he);
185
255
  continue;
186
256
  }
187
257
  }
188
- throw l;
258
+ throw d;
189
259
  }
190
- let X = h.headers.get("x-request-id") ?? h.headers.get("x-correlation-id") ?? void 0;
191
- if (h.ok) {
192
- let m = h.headers.get("x-neetru-version");
193
- return m && Ee(m), await Pe(h);
260
+ let B = _.headers.get("x-request-id") ?? _.headers.get("x-correlation-id") ?? void 0;
261
+ if (_.ok) {
262
+ let m = _.headers.get("x-neetru-version");
263
+ return m && qe(m), await Ae(_);
194
264
  }
195
- let b = await Pe(h), v = Le(h.status), y = `HTTP ${h.status}`, L;
196
- if (b && typeof b == "object") {
197
- let m = b.error;
198
- typeof m == "string" ? y = m : m && typeof m == "object" ? (typeof m.code == "string" && (v = m.code), typeof m.message == "string" && (y = m.message), typeof m.reason == "string" && (L = m.reason)) : (typeof b.code == "string" && (v = b.code), typeof b.message == "string" && (y = b.message)), typeof b.reason == "string" && (L = b.reason);
265
+ let y = await Ae(_), b = Fe(_.status), w = `HTTP ${_.status}`, C;
266
+ if (y && typeof y == "object") {
267
+ let m = y.error;
268
+ typeof m == "string" ? w = m : m && typeof m == "object" ? (typeof m.code == "string" && (b = m.code), typeof m.message == "string" && (w = m.message), typeof m.reason == "string" && (C = m.reason)) : (typeof y.code == "string" && (b = y.code), typeof y.message == "string" && (w = y.message)), typeof y.reason == "string" && (C = y.reason);
199
269
  }
200
- if (h.status === 410) {
201
- let m = h.headers.get("x-neetru-replacement");
202
- y === `HTTP ${h.status}` && (y = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), m && !y.includes(m) && (y += ` Substituto: ${m}.`);
270
+ if (_.status === 410) {
271
+ let m = _.headers.get("x-neetru-replacement");
272
+ w === `HTTP ${_.status}` && (w = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), m && !w.includes(m) && (w += ` Substituto: ${m}.`);
203
273
  }
204
- let M = new g(v, y, h.status, X, L);
205
- if (l = M, bt.has(v) && u < i) {
206
- let O = vt(h.headers.get("retry-after")) ?? De(u);
207
- if (d == null || Date.now() + O < d) {
208
- await Ce(O);
274
+ let fe = new g(b, w, _.status, B, C, a);
275
+ if (d = fe, Pt.has(b) && f < i) {
276
+ let O = Et(_.headers.get("retry-after")) ?? Me(f);
277
+ if (u == null || Date.now() + O < u) {
278
+ await xe(O);
209
279
  continue;
210
280
  }
211
281
  }
212
- throw M;
282
+ throw fe;
213
283
  }
214
- throw l ?? new g("unknown", "unexpected httpRequest exit");
284
+ throw d ?? new g("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
215
285
  }
216
- var ft, Re, _t, yt, gt, bt, ke, W = T(() => {
286
+ var St, Le, kt, Ct, It, Pt, Oe, W = S(() => {
217
287
  x();
218
- Te();
219
- ft = {
288
+ Re();
289
+ Ie();
290
+ Ee();
291
+ St = {
220
292
  // SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
221
293
  // runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
222
294
  3: "2026.05.1"
223
295
  };
224
- Re = /* @__PURE__ */ new Set();
225
- _t = 2, yt = 0, gt = /* @__PURE__ */ new Set(["GET", "HEAD"]), bt = /* @__PURE__ */ new Set([
296
+ Le = /* @__PURE__ */ new Set();
297
+ kt = 2, Ct = 0, It = /* @__PURE__ */ new Set(["GET", "HEAD"]), Pt = /* @__PURE__ */ new Set([
226
298
  "rate_limited",
227
299
  "server_error",
228
300
  "network_error"
229
301
  ]);
230
- ke = 6e4;
302
+ Oe = 6e4;
231
303
  });
232
304
 
233
305
  // src/db/sql/resilient-pool.ts
234
306
  function J(r) {
235
307
  return typeof r == "object" && r !== null && r[ae] === true;
236
308
  }
237
- function Tt(r) {
309
+ function Ot(r) {
238
310
  let e = r && typeof r == "object" && "code" in r ? r.code : void 0;
239
311
  if (e === "ECONNREFUSED" || e === "ETIMEDOUT" || e === "ENOTFOUND" || e === "EHOSTUNREACH" || e === "EAI_AGAIN")
240
312
  return true;
@@ -263,7 +335,7 @@ function ce(r) {
263
335
  return await o(e.current, c);
264
336
  } catch (l) {
265
337
  let d = t;
266
- if (d === null || !Tt(l))
338
+ if (d === null || !Ot(l))
267
339
  throw l;
268
340
  try {
269
341
  await d();
@@ -287,15 +359,15 @@ function ce(r) {
287
359
  }
288
360
  });
289
361
  }
290
- var ae, le = T(() => {
362
+ var ae, le = S(() => {
291
363
  ae = /* @__PURE__ */ Symbol.for("neetru.sdk.resilientPool");
292
364
  });
293
365
 
294
366
  // src/db/sql/lease.ts
295
- function Dt(r, e) {
367
+ function At(r, e) {
296
368
  return r ? r.leaseId !== e.leaseId || r.credentialVersion !== e.credentialVersion || r.host !== e.host || r.port !== e.port || r.dbName !== e.dbName || r.user !== e.user || r.password !== e.password || r.sslca !== e.sslca || r.clientCert !== e.clientCert || r.clientKey !== e.clientKey : true;
297
369
  }
298
- function kt(r) {
370
+ function Nt(r) {
299
371
  if (r instanceof p) return r;
300
372
  let e = r instanceof Error ? r.message : String(r), t = r instanceof Error ? r.code : void 0;
301
373
  return typeof t == "string" && (t === "ECONNREFUSED" || t === "ENOTFOUND" || t === "ETIMEDOUT") ? new p(
@@ -303,10 +375,10 @@ function kt(r) {
303
375
  `Pool connection failed (${t}): ${e}`
304
376
  ) : e.includes("statement timeout") || e.includes("lock timeout") ? new p("db_timeout", `Query timeout: ${e}`) : e.includes("40001") || e.includes("40P01") || e.includes("deadlock") ? new p("db_conflict", `Transaction conflict: ${e}`) : e.includes("42501") || e.toLowerCase().includes("permission denied") ? new p("db_permission_denied", `Permission denied: ${e}`) : new p("db_unavailable", `Database error: ${e}`);
305
377
  }
306
- var Rt, E, $, Me = T(() => {
307
- k();
378
+ var xt, M, $, Ue = S(() => {
379
+ I();
308
380
  le();
309
- Rt = 0.8, E = 3e4, $ = class {
381
+ xt = 0.8, M = 3e4, $ = class {
310
382
  /**
311
383
  * Lease atual. `null` no modo LAZY antes da 1ª query (o 1º lease é adiado —
312
384
  * ver `_ensureInitialLease`). Após a 1ª aquisição, sempre não-nulo.
@@ -346,7 +418,7 @@ var Rt, E, $, Me = T(() => {
346
418
  isolationLevel: t.isolationLevel
347
419
  }) : await this._orm.transaction(e);
348
420
  } catch (n) {
349
- throw kt(n);
421
+ throw Nt(n);
350
422
  }
351
423
  }
352
424
  async close() {
@@ -364,13 +436,13 @@ var Rt, E, $, Me = T(() => {
364
436
  * usa `MIN_RENEWAL_DELAY_MS` como fallback seguro.
365
437
  */
366
438
  _calcRenewalDelayMs() {
367
- if (!this._lease) return E;
439
+ if (!this._lease) return M;
368
440
  let e = Date.parse(this._lease.expiresAt);
369
- if (!Number.isFinite(e)) return E;
441
+ if (!Number.isFinite(e)) return M;
370
442
  let t = this._deps.now(), n = e - t;
371
- if (n <= 0) return E;
372
- let o = n * (1 - Rt);
373
- return Math.max(E, Math.round(o));
443
+ if (n <= 0) return M;
444
+ let o = n * (1 - xt);
445
+ return Math.max(M, Math.round(o));
374
446
  }
375
447
  _scheduleRenewal() {
376
448
  if (this._closed) return;
@@ -397,8 +469,8 @@ var Rt, E, $, Me = T(() => {
397
469
  } catch (t) {
398
470
  this._renewalTimer = setTimeout(() => {
399
471
  this._doRenew();
400
- }, E), console.warn(
401
- `[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${E}ms (cert TLS ef\xEAmero do servidor expira ~15min ap\xF3s o \xFAltimo swap):`,
472
+ }, M), console.warn(
473
+ `[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${M}ms (cert TLS ef\xEAmero do servidor expira ~15min ap\xF3s o \xFAltimo swap):`,
402
474
  t instanceof Error ? t.message : t
403
475
  );
404
476
  return;
@@ -505,7 +577,7 @@ var Rt, E, $, Me = T(() => {
505
577
  * Exposto como método protegido para testes.
506
578
  */
507
579
  async _swapPool(e) {
508
- if (!Dt(this._lease, e)) {
580
+ if (!At(this._lease, e)) {
509
581
  this._lease = e;
510
582
  return;
511
583
  }
@@ -532,29 +604,29 @@ var Rt, E, $, Me = T(() => {
532
604
  });
533
605
 
534
606
  // src/db/sql/sql-client.ts
535
- var We = {};
536
- he(We, {
537
- DEFAULT_POOL_CONNECT_TIMEOUT_MS: () => Fe,
538
- DEFAULT_POOL_IDLE_MS: () => qe,
539
- DEFAULT_POOL_MAX: () => Ne,
540
- LEASE_ENDPOINT: () => Oe,
541
- LEASE_RENEW_ENDPOINT: () => xe,
542
- createDrizzleHandle: () => Et,
543
- createHttpLeaseFetcher: () => Ae,
544
- createPgPool: () => It,
545
- createSqlClientFromConfig: () => Mt,
546
- createSqlClientWithDeps: () => Ue,
607
+ var Ke = {};
608
+ me(Ke, {
609
+ DEFAULT_POOL_CONNECT_TIMEOUT_MS: () => Qe,
610
+ DEFAULT_POOL_IDLE_MS: () => je,
611
+ DEFAULT_POOL_MAX: () => Ve,
612
+ LEASE_ENDPOINT: () => We,
613
+ LEASE_RENEW_ENDPOINT: () => $e,
614
+ createDrizzleHandle: () => Wt,
615
+ createHttpLeaseFetcher: () => Be,
616
+ createPgPool: () => Ut,
617
+ createSqlClientFromConfig: () => Bt,
618
+ createSqlClientWithDeps: () => ze,
547
619
  resolvePoolTuning: () => ue
548
620
  });
549
- function Ct(r) {
621
+ function qt(r) {
550
622
  return r === "workspace" ? "staging" : r === "prod" ? "production" : "dev-local";
551
623
  }
552
- function Ae(r) {
624
+ function Be(r) {
553
625
  return async (e) => {
554
- let { httpRequest: t } = await Promise.resolve().then(() => (W(), U)), n = !!e?.leaseId, o = n ? xe : Oe, i;
626
+ let { httpRequest: t } = await Promise.resolve().then(() => (W(), U)), n = !!e?.leaseId, o = n ? $e : We, i;
555
627
  n ? i = { leaseId: e.leaseId } : (i = {
556
628
  productId: r.productId ?? "",
557
- environment: Ct(r.env ?? "prod")
629
+ environment: qt(r.env ?? "prod")
558
630
  }, e?.database !== void 0 && (i.database = e.database));
559
631
  let s;
560
632
  try {
@@ -580,10 +652,10 @@ function Ae(r) {
580
652
  `Falha ao ${c} lease SQL: ${l}`
581
653
  );
582
654
  }
583
- return Pt(s);
655
+ return Ft(s);
584
656
  };
585
657
  }
586
- function Pt(r) {
658
+ function Ft(r) {
587
659
  if (!r || typeof r != "object")
588
660
  throw new p("db_unavailable", "Resposta de lease inv\xE1lida (n\xE3o \xE9 objeto).");
589
661
  let t = r.lease;
@@ -625,12 +697,12 @@ function ue() {
625
697
  return {
626
698
  // Teto 100: bem abaixo do `max_client_conn = 500` do PgBouncer, com folga
627
699
  // para múltiplas instâncias do app dividirem o mesmo front-door.
628
- max: de("NEETRU_DB_POOL_MAX", Ne, 1, 100),
700
+ max: de("NEETRU_DB_POOL_MAX", Ve, 1, 100),
629
701
  // Teto 15min = janela do cert; piso 1s.
630
- idleTimeoutMillis: de("NEETRU_DB_POOL_IDLE_MS", qe, 1e3, 9e5),
702
+ idleTimeoutMillis: de("NEETRU_DB_POOL_IDLE_MS", je, 1e3, 9e5),
631
703
  connectionTimeoutMillis: de(
632
704
  "NEETRU_DB_POOL_CONNECT_TIMEOUT_MS",
633
- Fe,
705
+ Qe,
634
706
  1e3,
635
707
  12e4
636
708
  ),
@@ -638,7 +710,7 @@ function ue() {
638
710
  keepAliveInitialDelayMillis: 1e4
639
711
  };
640
712
  }
641
- async function It(r) {
713
+ async function Ut(r) {
642
714
  let { Pool: e } = await import(
643
715
  /* webpackIgnore: true */
644
716
  'pg'
@@ -658,14 +730,14 @@ async function It(r) {
658
730
  ...ue()
659
731
  });
660
732
  }
661
- async function Et(r, e) {
733
+ async function Wt(r, e) {
662
734
  let { drizzle: t } = await import(
663
735
  /* webpackIgnore: true */
664
736
  'drizzle-orm/node-postgres'
665
737
  );
666
738
  return t(r, { schema: e });
667
739
  }
668
- function Lt(r, e) {
740
+ function $t(r, e) {
669
741
  let t = null, n = null, o = () => t ? Promise.resolve(t) : (n || (n = e().then((s) => (t = s, n = null, s)).catch((s) => {
670
742
  throw n = null, s;
671
743
  })), n), i = {
@@ -681,19 +753,19 @@ function Lt(r, e) {
681
753
  };
682
754
  return r && Object.setPrototypeOf(i, r), i;
683
755
  }
684
- async function Ue(r, e) {
756
+ async function ze(r, e) {
685
757
  let t = e?.database !== void 0 ? { ...r, database: e.database } : r;
686
758
  if (t.lazy) {
687
- let c = null, l = Lt(t.poolPrototype ?? null, () => {
759
+ let c = null, l = $t(t.poolPrototype ?? null, () => {
688
760
  if (!c)
689
761
  throw new p("db_unavailable", "SQL client n\xE3o inicializado (manager ausente).");
690
762
  return c._ensureInitialLease();
691
763
  }), d = ce(l), u;
692
764
  try {
693
765
  u = t.createDrizzle(d, t.schema);
694
- } catch (_) {
695
- let h = _ instanceof Error ? _.message : String(_);
696
- throw new p("db_unavailable", `Falha ao criar handle Drizzle: ${h}`);
766
+ } catch (h) {
767
+ let v = h instanceof Error ? h.message : String(h);
768
+ throw new p("db_unavailable", `Falha ao criar handle Drizzle: ${v}`);
697
769
  }
698
770
  let f = new $(null, d, u, t);
699
771
  return c = f, d.__neetruSetReLease(() => f._reactiveReLease()), f;
@@ -725,8 +797,8 @@ async function Ue(r, e) {
725
797
  let a = new $(n, i, s, t);
726
798
  return i.__neetruSetReLease(() => a._reactiveReLease()), a;
727
799
  }
728
- async function Mt(r, e, t) {
729
- let n = Ae(r), o, i;
800
+ async function Bt(r, e, t) {
801
+ let n = Be(r), o, i;
730
802
  try {
731
803
  o = await import(
732
804
  /* webpackIgnore: true */
@@ -742,7 +814,7 @@ async function Mt(r, e, t) {
742
814
  );
743
815
  }
744
816
  let s = o.Pool ?? o.default?.Pool;
745
- return Ue(
817
+ return ze(
746
818
  {
747
819
  fetchLease: n,
748
820
  createPool: (l) => {
@@ -777,24 +849,24 @@ async function Mt(r, e, t) {
777
849
  t
778
850
  );
779
851
  }
780
- var Oe, xe, Ne, qe, Fe, $e = T(() => {
781
- k();
852
+ var We, $e, Ve, je, Qe, He = S(() => {
853
+ I();
782
854
  x();
783
- Me();
855
+ Ue();
784
856
  le();
785
- Oe = "/api/sdk/v1/db/lease", xe = "/api/sdk/v1/db/lease/renew";
786
- Ne = 10, qe = 6e4, Fe = 1e4;
857
+ We = "/api/sdk/v1/db/lease", $e = "/api/sdk/v1/db/lease/renew";
858
+ Ve = 10, je = 6e4, Qe = 1e4;
787
859
  });
788
860
 
789
861
  // src/db/client-db.ts
790
- k();
862
+ I();
791
863
 
792
864
  // src/db/offline/query-engine.ts
793
- function me(r) {
865
+ function _e(r) {
794
866
  return r == null ? 0 : typeof r == "number" ? 1 : typeof r == "string" ? 2 : typeof r == "boolean" ? 3 : 4;
795
867
  }
796
868
  function A(r, e) {
797
- let t = me(r), n = me(e);
869
+ let t = _e(r), n = _e(e);
798
870
  if (t !== n) return t - n;
799
871
  if (r == null) return 0;
800
872
  if (typeof r == "number" && typeof e == "number") return r - e;
@@ -812,7 +884,7 @@ function Z(r, e) {
812
884
  }
813
885
  return n;
814
886
  }
815
- function ze(r, e) {
887
+ function Ze(r, e) {
816
888
  let t = Z(r, e.field);
817
889
  if (t === void 0) return false;
818
890
  let { op: n, value: o } = e;
@@ -843,10 +915,10 @@ function ze(r, e) {
843
915
  );
844
916
  }
845
917
  }
846
- function Ke(r, e) {
847
- return e.every((t) => ze(r, t));
918
+ function et(r, e) {
919
+ return e.every((t) => Ze(r, t));
848
920
  }
849
- function He(r) {
921
+ function tt(r) {
850
922
  return (e, t) => {
851
923
  if (r) {
852
924
  let n = Z(e.data, r.field), o = Z(t.data, r.field), i = A(n, o);
@@ -856,11 +928,11 @@ function He(r) {
856
928
  return e.id < t.id ? -1 : e.id > t.id ? 1 : 0;
857
929
  };
858
930
  }
859
- function Ge(r, e) {
931
+ function nt(r, e) {
860
932
  let t = r.findIndex((n) => n.id === e.docId);
861
933
  return t === -1 ? r : e.type === "startAfter" ? r.slice(t + 1) : r.slice(0, t);
862
934
  }
863
- var C = class r {
935
+ var P = class r {
864
936
  /**
865
937
  * Avalia um `QueryDescriptor` contra um array de `OfflineDoc`.
866
938
  *
@@ -874,9 +946,9 @@ var C = class r {
874
946
  evaluate(e, t) {
875
947
  let n = e.filter((d) => !d.meta.deleted), o = t.where ?? [];
876
948
  o.length > 0 && (n = n.filter(
877
- (d) => Ke(d.data, o)
949
+ (d) => et(d.data, o)
878
950
  ));
879
- let i = He(t.orderBy), s = [...n].sort(i), a = t.cursor ? Ge(s, t.cursor) : s, c = Math.min(t.limit ?? 20, 500);
951
+ let i = tt(t.orderBy), s = [...n].sort(i), a = t.cursor ? nt(s, t.cursor) : s, c = Math.min(t.limit ?? 20, 500);
880
952
  return {
881
953
  docs: a.slice(0, c).map((d) => ({ id: d.id, data: d.data })),
882
954
  // `incomplete` é sempre true aqui — o QueryEngine não sabe se o cache
@@ -896,7 +968,7 @@ var C = class r {
896
968
  };
897
969
 
898
970
  // src/db/offline/local-store.ts
899
- var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta", P = "conflict_log", j = class {
971
+ var ot = 1, T = "documents", R = "mutations", N = "query_cache", V = "sync_meta", E = "conflict_log", j = class {
900
972
  db = null;
901
973
  dbName;
902
974
  constructor(e) {
@@ -908,22 +980,22 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
908
980
  * Idempotente — chamadas subsequentes são no-ops se o banco já está aberto.
909
981
  */
910
982
  async open() {
911
- this.db === null && (this.db = await openDB(this.dbName, Ye, {
983
+ this.db === null && (this.db = await openDB(this.dbName, ot, {
912
984
  upgrade(e) {
913
- if (!e.objectStoreNames.contains(w)) {
914
- let t = e.createObjectStore(w, {
985
+ if (!e.objectStoreNames.contains(T)) {
986
+ let t = e.createObjectStore(T, {
915
987
  keyPath: ["collection", "id"]
916
988
  });
917
989
  t.createIndex("by_collection", "collection"), t.createIndex("by_collection_state", ["collection", "meta.state"]), t.createIndex("by_updatedAtServer", "meta.updatedAtServer");
918
990
  }
919
- if (!e.objectStoreNames.contains(S)) {
920
- let t = e.createObjectStore(S, {
991
+ if (!e.objectStoreNames.contains(R)) {
992
+ let t = e.createObjectStore(R, {
921
993
  keyPath: "mutationId"
922
994
  });
923
995
  t.createIndex("by_seq", "seq"), t.createIndex("by_status", "status"), t.createIndex("by_doc", ["collection", "docId"]), t.createIndex("by_batch", "batchId");
924
996
  }
925
- if (e.objectStoreNames.contains(N) || e.createObjectStore(N, { keyPath: "queryHash" }), e.objectStoreNames.contains(B) || e.createObjectStore(B, { keyPath: "key" }), !e.objectStoreNames.contains(P)) {
926
- let t = e.createObjectStore(P, {
997
+ if (e.objectStoreNames.contains(N) || e.createObjectStore(N, { keyPath: "queryHash" }), e.objectStoreNames.contains(V) || e.createObjectStore(V, { keyPath: "key" }), !e.objectStoreNames.contains(E)) {
998
+ let t = e.createObjectStore(E, {
927
999
  keyPath: "id",
928
1000
  autoIncrement: true
929
1001
  });
@@ -965,14 +1037,14 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
965
1037
  * Retorna tombstones (deleted: true) — o chamador decide se deve mostrá-los.
966
1038
  */
967
1039
  async getDoc(e, t) {
968
- return await this.assertOpen().get(w, [e, t]) ?? null;
1040
+ return await this.assertOpen().get(T, [e, t]) ?? null;
969
1041
  }
970
1042
  /**
971
1043
  * Insere ou atualiza um documento na store `documents`.
972
1044
  * O documento é identificado pelo keyPath composto `[collection, id]`.
973
1045
  */
974
1046
  async putDoc(e) {
975
- await this.assertOpen().put(w, e);
1047
+ await this.assertOpen().put(T, e);
976
1048
  }
977
1049
  /**
978
1050
  * Marca um documento como tombstone (`deleted: true`).
@@ -980,8 +1052,8 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
980
1052
  * No-op se o documento não existir.
981
1053
  */
982
1054
  async deleteDoc(e, t) {
983
- let n = this.assertOpen(), o = await n.get(w, [e, t]);
984
- o && await n.put(w, {
1055
+ let n = this.assertOpen(), o = await n.get(T, [e, t]);
1056
+ o && await n.put(T, {
985
1057
  ...o,
986
1058
  meta: {
987
1059
  ...o.meta,
@@ -997,8 +1069,8 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
997
1069
  * e delega a filtragem/ordenação/paginação ao QueryEngine (que opera em memória).
998
1070
  */
999
1071
  async listDocs(e, t) {
1000
- let o = await this.assertOpen().getAllFromIndex(w, "by_collection", e);
1001
- return C.evaluate(o, t);
1072
+ let o = await this.assertOpen().getAllFromIndex(T, "by_collection", e);
1073
+ return P.evaluate(o, t);
1002
1074
  }
1003
1075
  // ─── Sync meta (key-value) ──────────────────────────────────────────────────
1004
1076
  /**
@@ -1009,14 +1081,14 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
1009
1081
  * 'lastFullResyncAt', 'leaderTabId'.
1010
1082
  */
1011
1083
  async getMeta(e) {
1012
- let n = await this.assertOpen().get(B, e);
1084
+ let n = await this.assertOpen().get(V, e);
1013
1085
  return n ? n.value : null;
1014
1086
  }
1015
1087
  /**
1016
1088
  * Armazena ou atualiza um valor na store `sync_meta`.
1017
1089
  */
1018
1090
  async setMeta(e, t) {
1019
- await this.assertOpen().put(B, { key: e, value: t });
1091
+ await this.assertOpen().put(V, { key: e, value: t });
1020
1092
  }
1021
1093
  // ─── Conflict log ───────────────────────────────────────────────────────────
1022
1094
  /**
@@ -1024,7 +1096,7 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
1024
1096
  * O `id` é autoIncrement — não deve ser fornecido pelo chamador.
1025
1097
  */
1026
1098
  async appendConflict(e) {
1027
- let n = await this.assertOpen().add(P, e);
1099
+ let n = await this.assertOpen().add(E, e);
1028
1100
  return { ...e, id: n };
1029
1101
  }
1030
1102
  /**
@@ -1032,15 +1104,15 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
1032
1104
  * Filtra por `delivered` se a opção for fornecida.
1033
1105
  */
1034
1106
  async listConflicts(e) {
1035
- let n = await this.assertOpen().getAll(P);
1107
+ let n = await this.assertOpen().getAll(E);
1036
1108
  return e?.delivered !== void 0 ? n.filter((o) => o.delivered === e.delivered) : n;
1037
1109
  }
1038
1110
  /**
1039
1111
  * Marca um registro do `conflict_log` como entregue ao produto.
1040
1112
  */
1041
1113
  async markConflictDelivered(e) {
1042
- let t = this.assertOpen(), n = await t.get(P, e);
1043
- n && await t.put(P, { ...n, delivered: true });
1114
+ let t = this.assertOpen(), n = await t.get(E, e);
1115
+ n && await t.put(E, { ...n, delivered: true });
1044
1116
  }
1045
1117
  // ─── Mutations (acessores usados pelo MutationQueue) ────────────────────────
1046
1118
  /**
@@ -1048,13 +1120,13 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
1048
1120
  * Key: `mutationId`.
1049
1121
  */
1050
1122
  async putMutation(e) {
1051
- await this.assertOpen().put(S, e);
1123
+ await this.assertOpen().put(R, e);
1052
1124
  }
1053
1125
  /**
1054
1126
  * Retorna uma mutação pelo `mutationId`, ou `null` se não existir.
1055
1127
  */
1056
1128
  async getMutation(e) {
1057
- return await this.assertOpen().get(S, e) ?? null;
1129
+ return await this.assertOpen().get(R, e) ?? null;
1058
1130
  }
1059
1131
  /**
1060
1132
  * Lista mutações com filtros opcionais.
@@ -1062,14 +1134,14 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
1062
1134
  */
1063
1135
  async listMutations(e) {
1064
1136
  let t = this.assertOpen(), n;
1065
- return e?.status !== void 0 ? n = await t.getAllFromIndex(S, "by_status", e.status) : e?.collection !== void 0 && e.docId !== void 0 ? n = await t.getAllFromIndex(S, "by_doc", [e.collection, e.docId]) : n = await t.getAllFromIndex(S, "by_seq"), n.sort((o, i) => o.seq - i.seq);
1137
+ return e?.status !== void 0 ? n = await t.getAllFromIndex(R, "by_status", e.status) : e?.collection !== void 0 && e.docId !== void 0 ? n = await t.getAllFromIndex(R, "by_doc", [e.collection, e.docId]) : n = await t.getAllFromIndex(R, "by_seq"), n.sort((o, i) => o.seq - i.seq);
1066
1138
  }
1067
1139
  /**
1068
1140
  * Remove uma mutação pelo `mutationId`.
1069
1141
  * No-op se não existir.
1070
1142
  */
1071
1143
  async deleteMutation(e) {
1072
- await this.assertOpen().delete(S, e);
1144
+ await this.assertOpen().delete(R, e);
1073
1145
  }
1074
1146
  // ─── Collection discovery ────────────────────────────────────────────────────
1075
1147
  /**
@@ -1082,7 +1154,7 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
1082
1154
  * coletar os valores únicos de forma eficiente (sem carregar os docs completos).
1083
1155
  */
1084
1156
  async listCollections() {
1085
- let t = await this.assertOpen().getAllFromIndex(w, "by_collection"), n = /* @__PURE__ */ new Set();
1157
+ let t = await this.assertOpen().getAllFromIndex(T, "by_collection"), n = /* @__PURE__ */ new Set();
1086
1158
  for (let o of t)
1087
1159
  n.add(o.collection);
1088
1160
  return Array.from(n);
@@ -1109,7 +1181,7 @@ var Ye = 1, w = "documents", S = "mutations", N = "query_cache", B = "sync_meta"
1109
1181
  };
1110
1182
 
1111
1183
  // src/db/offline/memory-store.ts
1112
- var V = class {
1184
+ var Q = class {
1113
1185
  // store `documents` — key: `${collection}\0${id}`
1114
1186
  _docs = /* @__PURE__ */ new Map();
1115
1187
  // store `mutations` — key: mutationId
@@ -1157,7 +1229,7 @@ var V = class {
1157
1229
  let n = Array.from(this._docs.values()).filter(
1158
1230
  (o) => o.collection === e
1159
1231
  );
1160
- return C.evaluate(n, t);
1232
+ return P.evaluate(n, t);
1161
1233
  }
1162
1234
  // ─── Sync meta ──────────────────────────────────────────────────────────────
1163
1235
  async getMeta(e) {
@@ -1220,7 +1292,7 @@ function ee() {
1220
1292
  return (r === "x" ? e : e & 3 | 8).toString(16);
1221
1293
  });
1222
1294
  }
1223
- var Q = class {
1295
+ var z = class {
1224
1296
  store;
1225
1297
  /**
1226
1298
  * Ponteiro de sequência local.
@@ -1318,11 +1390,11 @@ var Q = class {
1318
1390
  async enqueue(e) {
1319
1391
  let { collection: t, op: n, payload: o, baseVersion: i, batchId: s, upsert: a } = e, c = e.docId ?? (n === "add" ? ee() : "");
1320
1392
  await this.syncSeq();
1321
- let d = (await this.store.listMutations({ collection: t, docId: c })).filter((_) => _.status === "queued").sort((_, h) => h.seq - _.seq)[0];
1393
+ let d = (await this.store.listMutations({ collection: t, docId: c })).filter((h) => h.status === "queued").sort((h, v) => v.seq - h.seq)[0];
1322
1394
  if (d !== void 0) {
1323
- let _ = this.tryCoalesce(d, n, o, s, a);
1324
- if (_ !== null) {
1325
- if ("removed" in _)
1395
+ let h = this.tryCoalesce(d, n, o, s, a);
1396
+ if (h !== null) {
1397
+ if ("removed" in h)
1326
1398
  return await this.store.deleteMutation(d.mutationId), {
1327
1399
  seq: d.seq,
1328
1400
  mutationId: ee(),
@@ -1337,8 +1409,8 @@ var Q = class {
1337
1409
  status: "queued",
1338
1410
  batchId: s
1339
1411
  };
1340
- let { coalesced: h } = _;
1341
- return await this.store.putMutation(h), h;
1412
+ let { coalesced: v } = h;
1413
+ return await this.store.putMutation(v), v;
1342
1414
  }
1343
1415
  }
1344
1416
  let f = {
@@ -1457,54 +1529,54 @@ var Q = class {
1457
1529
 
1458
1530
  // src/db/field-value.ts
1459
1531
  var te = "__neetru__";
1460
- function Xe() {
1532
+ function it() {
1461
1533
  return { __neetru__: "serverTimestamp" };
1462
1534
  }
1463
- function Ze(r) {
1535
+ function st(r) {
1464
1536
  if (typeof r != "number" || !Number.isFinite(r))
1465
1537
  throw new TypeError(
1466
1538
  `increment(n): n deve ser um n\xFAmero finito (recebido: ${String(r)}).`
1467
1539
  );
1468
1540
  return { __neetru__: "increment", operand: r };
1469
1541
  }
1470
- function R(r) {
1542
+ function D(r) {
1471
1543
  return typeof r == "object" && r !== null && te in r && typeof r[te] == "string";
1472
1544
  }
1473
- function _e(r) {
1474
- return R(r) && r.__neetru__ === "serverTimestamp";
1475
- }
1476
1545
  function ye(r) {
1477
- return R(r) && r.__neetru__ === "increment" && typeof r.operand == "number" && Number.isFinite(r.operand);
1546
+ return D(r) && r.__neetru__ === "serverTimestamp";
1478
1547
  }
1479
- function et(r, e) {
1480
- return _e(r) ? Date.now() : ye(r) ? (typeof e == "number" && Number.isFinite(e) ? e : 0) + r.operand : r;
1548
+ function ge(r) {
1549
+ return D(r) && r.__neetru__ === "increment" && typeof r.operand == "number" && Number.isFinite(r.operand);
1550
+ }
1551
+ function at(r, e) {
1552
+ return ye(r) ? Date.now() : ge(r) ? (typeof e == "number" && Number.isFinite(e) ? e : 0) + r.operand : r;
1481
1553
  }
1482
- function D(r, e) {
1554
+ function k(r, e) {
1483
1555
  let t = false, n = {};
1484
1556
  for (let [o, i] of Object.entries(r))
1485
- R(i) ? (t = true, n[o] = et(i, e?.[o])) : n[o] = i;
1557
+ D(i) ? (t = true, n[o] = at(i, e?.[o])) : n[o] = i;
1486
1558
  return t ? n : r;
1487
1559
  }
1488
1560
  function ne(r) {
1489
1561
  for (let e of Object.values(r))
1490
- if (R(e)) return true;
1562
+ if (D(e)) return true;
1491
1563
  return false;
1492
1564
  }
1493
1565
 
1494
1566
  // src/db/offline/sync-engine.ts
1495
- var tt = 8, nt = 1e3, rt = 300 * 1e3, re = "truncatedCollections";
1496
- function ot(r) {
1567
+ var ct = 8, lt = 1e3, dt = 300 * 1e3, re = "truncatedCollections";
1568
+ function ut(r) {
1497
1569
  return r !== null && ne(r);
1498
1570
  }
1499
- function it(r) {
1571
+ function pt(r) {
1500
1572
  if (r === null) return null;
1501
1573
  if (!ne(r)) return r;
1502
1574
  let e = {};
1503
1575
  for (let [t, n] of Object.entries(r))
1504
- R(n) || (e[t] = n);
1576
+ D(n) || (e[t] = n);
1505
1577
  return e;
1506
1578
  }
1507
- var z = class {
1579
+ var K = class {
1508
1580
  _store;
1509
1581
  _queue;
1510
1582
  _resolver;
@@ -1698,13 +1770,13 @@ var z = class {
1698
1770
  }), s.push({ type: "removed", collection: e, doc: { id: t, data: a.data } }));
1699
1771
  return;
1700
1772
  }
1701
- let l = it(i.payload) ?? a?.data ?? {}, d = {
1773
+ let l = pt(i.payload) ?? a?.data ?? {}, d = {
1702
1774
  collection: e,
1703
1775
  id: t,
1704
1776
  data: i.op === "update" ? { ...a?.data ?? {}, ...l } : (
1705
1777
  // add/set: se o payload tinha sentinels, o cache otimista (existing.data)
1706
1778
  // é a fonte de verdade até o pull; senão usa o payload literal.
1707
- ot(i.payload) ? { ...a?.data ?? {}, ...l } : l
1779
+ ut(i.payload) ? { ...a?.data ?? {}, ...l } : l
1708
1780
  ),
1709
1781
  meta: {
1710
1782
  serverVersion: n,
@@ -1857,7 +1929,7 @@ var z = class {
1857
1929
  * pending do doc no cache + registra `lastError`/dispara `onError`.
1858
1930
  */
1859
1931
  async _retryOrDeadLetter(e, t, n) {
1860
- if (e.attempts + 1 < tt) {
1932
+ if (e.attempts + 1 < ct) {
1861
1933
  await this._queue.markRetry(e.mutationId, t);
1862
1934
  return;
1863
1935
  }
@@ -1898,7 +1970,7 @@ var z = class {
1898
1970
  }
1899
1971
  /** Backoff exponencial keyed em `attempts`, com teto `BACKOFF_CAP_MS`. */
1900
1972
  _backoffDelayMs(e) {
1901
- return Math.min(nt * 2 ** (e - 1), rt);
1973
+ return Math.min(lt * 2 ** (e - 1), dt);
1902
1974
  }
1903
1975
  // ─── FASE 2 — pull (reconciliar o cache) ─────────────────────────────────────
1904
1976
  /**
@@ -2150,10 +2222,10 @@ var z = class {
2150
2222
  };
2151
2223
 
2152
2224
  // src/db/offline/conflict-resolver.ts
2153
- function ge(r, e) {
2225
+ function be(r, e) {
2154
2226
  return e === null ? false : r === null ? true : e > r;
2155
2227
  }
2156
- var K = class r {
2228
+ var H = class r {
2157
2229
  /**
2158
2230
  * Resolve um conflito com base na operação da mutação (auto-dispatch).
2159
2231
  *
@@ -2187,7 +2259,7 @@ var K = class r {
2187
2259
  resolvedData: t.data,
2188
2260
  conflictRecord: null
2189
2261
  };
2190
- if (!ge(
2262
+ if (!be(
2191
2263
  e.meta.updatedAtServer,
2192
2264
  t.meta.updatedAtServer
2193
2265
  ))
@@ -2234,7 +2306,7 @@ var K = class r {
2234
2306
  let i = t.data;
2235
2307
  if (e === null)
2236
2308
  return { outcome: "no_conflict", resolvedData: { ...i, ...n.payload ?? {} }, conflictRecord: null };
2237
- if (!ge(
2309
+ if (!be(
2238
2310
  e.meta.updatedAtServer,
2239
2311
  t.meta.updatedAtServer
2240
2312
  ))
@@ -2312,10 +2384,10 @@ var K = class r {
2312
2384
  };
2313
2385
 
2314
2386
  // src/db/offline/change-bus.ts
2315
- function st(r) {
2387
+ function ft(r) {
2316
2388
  return `${r.collection}::${r.doc.id}`;
2317
2389
  }
2318
- var H = class {
2390
+ var G = class {
2319
2391
  /** Listeners filtrados por coleção. */
2320
2392
  _collectionListeners = /* @__PURE__ */ new Map();
2321
2393
  /** Listeners globais (todas as coleções). */
@@ -2360,7 +2432,7 @@ var H = class {
2360
2432
  if (e.length === 0) return;
2361
2433
  let t = /* @__PURE__ */ new Map();
2362
2434
  for (let i of e)
2363
- t.set(st(i), i);
2435
+ t.set(ft(i), i);
2364
2436
  let n = Array.from(t.values()), o = /* @__PURE__ */ new Map();
2365
2437
  for (let i of n)
2366
2438
  o.has(i.collection) || o.set(i.collection, []), o.get(i.collection).push(i);
@@ -2399,7 +2471,7 @@ var H = class {
2399
2471
  };
2400
2472
 
2401
2473
  // src/db/offline/connectivity-monitor.ts
2402
- var G = class {
2474
+ var X = class {
2403
2475
  _state;
2404
2476
  _listeners = /* @__PURE__ */ new Set();
2405
2477
  _nav;
@@ -2678,26 +2750,26 @@ var q = class {
2678
2750
  };
2679
2751
 
2680
2752
  // src/db/collection-ref.ts
2681
- k();
2682
- function at() {
2753
+ I();
2754
+ function ht() {
2683
2755
  return typeof indexedDB > "u" || typeof window > "u";
2684
2756
  }
2685
- var be = /^[a-z0-9][a-z0-9_-]{0,62}$/;
2686
- function ct(r) {
2687
- if (!be.test(r))
2757
+ var ve = /^[a-z0-9][a-z0-9_-]{0,62}$/;
2758
+ function mt(r) {
2759
+ if (!ve.test(r))
2688
2760
  throw new p(
2689
2761
  "db_invalid_query",
2690
- `Nome de cole\xE7\xE3o inv\xE1lido: "${r}". Deve seguir o padr\xE3o ${be}.`
2762
+ `Nome de cole\xE7\xE3o inv\xE1lido: "${r}". Deve seguir o padr\xE3o ${ve}.`
2691
2763
  );
2692
2764
  }
2693
- function I(r, e = "id") {
2765
+ function L(r, e = "id") {
2694
2766
  if (!r || typeof r != "string" || r.trim() === "")
2695
2767
  throw new p(
2696
2768
  "db_invalid_query",
2697
2769
  `${e} \xE9 obrigat\xF3rio e deve ser uma string n\xE3o-vazia.`
2698
2770
  );
2699
2771
  }
2700
- function lt(r) {
2772
+ function _t(r) {
2701
2773
  let e = {};
2702
2774
  if (r?.where && (e.where = r.where.map((t) => ({
2703
2775
  field: t.field,
@@ -2714,7 +2786,7 @@ function lt(r) {
2714
2786
  }
2715
2787
  return e;
2716
2788
  }
2717
- function dt(r, e) {
2789
+ function yt(r, e) {
2718
2790
  if (r.length < e) return null;
2719
2791
  let t = r[r.length - 1];
2720
2792
  return t ? btoa(JSON.stringify({ type: "startAfter", docId: t.id })) : null;
@@ -2761,9 +2833,9 @@ var oe = class {
2761
2833
  }
2762
2834
  /** Constrói um DbListResult para a coleção com query opcional. */
2763
2835
  async _buildListResult(e) {
2764
- let t = lt(e), n = t.limit ?? 20, o = await this._store.listDocs(this._collection, t), i = await this._hasPendingWrites(), s = this._isOnline(), a = this._engine.getSyncState(), c = dt(o.docs, n), l = await this._store.getMeta(re), d = Array.isArray(l) && l.includes(this._collection), u = !s || a.status === "offline" || d, f = i || a.lastSyncedAt === null || u;
2836
+ let t = _t(e), n = t.limit ?? 20, o = await this._store.listDocs(this._collection, t), i = await this._hasPendingWrites(), s = this._isOnline(), a = this._engine.getSyncState(), c = yt(o.docs, n), l = await this._store.getMeta(re), d = Array.isArray(l) && l.includes(this._collection), u = !s || a.status === "offline" || d, f = i || a.lastSyncedAt === null || u;
2765
2837
  return {
2766
- docs: o.docs.map((_) => ({ id: _.id, data: _.data })),
2838
+ docs: o.docs.map((h) => ({ id: h.id, data: h.data })),
2767
2839
  nextCursor: c,
2768
2840
  fromCache: f,
2769
2841
  stale: u,
@@ -2774,13 +2846,13 @@ var oe = class {
2774
2846
  }
2775
2847
  // ── CRUD ────────────────────────────────────────────────────────────────────
2776
2848
  async get(e) {
2777
- return I(e), this._buildGetResult(e);
2849
+ return L(e), this._buildGetResult(e);
2778
2850
  }
2779
2851
  async list(e) {
2780
2852
  return this._buildListResult(e);
2781
2853
  }
2782
2854
  async add(e) {
2783
- let t = e, n = D(t, void 0), o = await this._queue.enqueue({
2855
+ let t = e, n = k(t, void 0), o = await this._queue.enqueue({
2784
2856
  collection: this._collection,
2785
2857
  op: "add",
2786
2858
  payload: t,
@@ -2807,8 +2879,8 @@ var oe = class {
2807
2879
  }]), { ok: true, id: i };
2808
2880
  }
2809
2881
  async set(e, t) {
2810
- I(e);
2811
- let n = await this._store.getDoc(this._collection, e), o = t, i = D(o, void 0), s = await this._queue.enqueue({
2882
+ L(e);
2883
+ let n = await this._store.getDoc(this._collection, e), o = t, i = k(o, void 0), s = await this._queue.enqueue({
2812
2884
  collection: this._collection,
2813
2885
  docId: e,
2814
2886
  op: "set",
@@ -2836,8 +2908,8 @@ var oe = class {
2836
2908
  }]), { ok: true };
2837
2909
  }
2838
2910
  async update(e, t, n) {
2839
- I(e);
2840
- let o = await this._store.getDoc(this._collection, e), i = t, s = o?.meta.deleted ? void 0 : o?.data, a = D(i, s), c = o?.meta.deleted ? { ...a } : { ...o?.data ?? {}, ...a }, l = await this._queue.enqueue({
2911
+ L(e);
2912
+ let o = await this._store.getDoc(this._collection, e), i = t, s = o?.meta.deleted ? void 0 : o?.data, a = k(i, s), c = o?.meta.deleted ? { ...a } : { ...o?.data ?? {}, ...a }, l = await this._queue.enqueue({
2841
2913
  collection: this._collection,
2842
2914
  docId: e,
2843
2915
  op: "update",
@@ -2870,7 +2942,7 @@ var oe = class {
2870
2942
  }]), { ok: true };
2871
2943
  }
2872
2944
  async remove(e) {
2873
- I(e);
2945
+ L(e);
2874
2946
  let t = await this._store.getDoc(this._collection, e);
2875
2947
  return !t || t.meta.deleted, await this._queue.enqueue({
2876
2948
  collection: this._collection,
@@ -2890,7 +2962,7 @@ var oe = class {
2890
2962
  for (let o of e) {
2891
2963
  let i = this._collection;
2892
2964
  if (o.kind === "add") {
2893
- let s = o.data, a = D(s, void 0), c = await this._queue.enqueue({
2965
+ let s = o.data, a = k(s, void 0), c = await this._queue.enqueue({
2894
2966
  collection: i,
2895
2967
  op: "add",
2896
2968
  payload: s,
@@ -2912,7 +2984,7 @@ var oe = class {
2912
2984
  }
2913
2985
  }), n.push({ type: "added", collection: i, doc: { id: l, data: a } });
2914
2986
  } else if (o.kind === "set") {
2915
- let s = o.id, a = o.data, c = await this._store.getDoc(i, s), l = D(a, void 0), d = await this._queue.enqueue({
2987
+ let s = o.id, a = o.data, c = await this._store.getDoc(i, s), l = k(a, void 0), d = await this._queue.enqueue({
2916
2988
  collection: i,
2917
2989
  docId: s,
2918
2990
  op: "set",
@@ -2939,7 +3011,7 @@ var oe = class {
2939
3011
  doc: { id: s, data: l }
2940
3012
  });
2941
3013
  } else if (o.kind === "update") {
2942
- let s = o.id, a = o.data, c = await this._store.getDoc(i, s), l = c?.meta.deleted ? void 0 : c?.data, d = D(a, l), u = { ...c?.data ?? {}, ...d }, f = await this._queue.enqueue({
3014
+ let s = o.id, a = o.data, c = await this._store.getDoc(i, s), l = c?.meta.deleted ? void 0 : c?.data, d = k(a, l), u = { ...c?.data ?? {}, ...d }, f = await this._queue.enqueue({
2943
3015
  collection: i,
2944
3016
  docId: s,
2945
3017
  op: "update",
@@ -2982,7 +3054,7 @@ var oe = class {
2982
3054
  }
2983
3055
  // ── Realtime ─────────────────────────────────────────────────────────────────
2984
3056
  onDoc(e, t) {
2985
- return I(e), this._buildGetResult(e).then((n) => {
3057
+ return L(e), this._buildGetResult(e).then((n) => {
2986
3058
  t(n ? n.docs[0]?.data ?? null : null);
2987
3059
  }).catch(() => t(null)), this._bus.subscribe(this._collection, (n) => {
2988
3060
  let o = n.find((i) => i.doc.id === e);
@@ -3041,7 +3113,7 @@ var oe = class {
3041
3113
  };
3042
3114
  }
3043
3115
  doc(e) {
3044
- I(e);
3116
+ L(e);
3045
3117
  let t = this;
3046
3118
  return {
3047
3119
  get id() {
@@ -3104,7 +3176,7 @@ var oe = class {
3104
3176
  this._store = e.store, this._queue = e.queue, this._bus = e.bus, this._engine = e.engine, this._connectivity = e.connectivity;
3105
3177
  }
3106
3178
  collection(e) {
3107
- return ct(e), new oe(
3179
+ return mt(e), new oe(
3108
3180
  e,
3109
3181
  this._store,
3110
3182
  this._queue,
@@ -3133,10 +3205,10 @@ var oe = class {
3133
3205
  return this._engine.onError(e);
3134
3206
  }
3135
3207
  };
3136
- async function ve(r) {
3137
- let e = at() ? new V() : new j(r.dbName);
3208
+ async function we(r) {
3209
+ let e = ht() ? new Q() : new j(r.dbName);
3138
3210
  await e.open();
3139
- let t = new Q(e), n = new K(), o = new H(), i = new G({
3211
+ let t = new z(e), n = new H(), o = new G(), i = new X({
3140
3212
  // Se startOnline=false, injeta um navigator falso
3141
3213
  navigator: r.startOnline === false ? { onLine: false } : typeof navigator < "u" ? navigator : void 0
3142
3214
  }), s = r.singleTab ? (
@@ -3149,7 +3221,7 @@ async function ve(r) {
3149
3221
  ) : new q({
3150
3222
  lockName: `neetru-offline:${r.dbName}`,
3151
3223
  channelName: `neetru-offline:${r.dbName}`
3152
- }), a = new z({
3224
+ }), a = new K({
3153
3225
  store: e,
3154
3226
  queue: t,
3155
3227
  resolver: n,
@@ -3169,9 +3241,9 @@ async function ve(r) {
3169
3241
  }
3170
3242
 
3171
3243
  // src/db/realtime/realtime-client.ts
3172
- var ut = 0;
3173
- function we() {
3174
- return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++ut}-${Math.random().toString(36).slice(2)}`;
3244
+ var gt = 0;
3245
+ function Se() {
3246
+ return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++gt}-${Math.random().toString(36).slice(2)}`;
3175
3247
  }
3176
3248
  var F = class {
3177
3249
  // ── configuração ──────────────────────────────────────────────────────────
@@ -3211,7 +3283,7 @@ var F = class {
3211
3283
  _pendingFrames = [];
3212
3284
  // ── construtor ────────────────────────────────────────────────────────────
3213
3285
  constructor(e) {
3214
- this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ?? pt, this._setTimeout = e.setTimeoutFn ?? globalThis.setTimeout.bind(globalThis), this._clearTimeout = e.clearTimeoutFn ?? globalThis.clearTimeout.bind(globalThis), this._backoffBaseMs = e.backoffBaseMs ?? 1e3, this._backoffMaxMs = e.backoffMaxMs ?? 3e4, this._heartbeatIntervalMs = e.heartbeatIntervalMs ?? 25e3, this._ticketProvider = e.ticketProvider, this._dbId = e.dbId, this._connect();
3286
+ this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ?? bt, this._setTimeout = e.setTimeoutFn ?? globalThis.setTimeout.bind(globalThis), this._clearTimeout = e.clearTimeoutFn ?? globalThis.clearTimeout.bind(globalThis), this._backoffBaseMs = e.backoffBaseMs ?? 1e3, this._backoffMaxMs = e.backoffMaxMs ?? 3e4, this._heartbeatIntervalMs = e.heartbeatIntervalMs ?? 25e3, this._ticketProvider = e.ticketProvider, this._dbId = e.dbId, this._connect();
3215
3287
  }
3216
3288
  // ── API pública ───────────────────────────────────────────────────────────
3217
3289
  /**
@@ -3225,8 +3297,8 @@ var F = class {
3225
3297
  */
3226
3298
  subscribe(e, t, n) {
3227
3299
  if (this._closed)
3228
- return we();
3229
- let o = we();
3300
+ return Se();
3301
+ let o = Se();
3230
3302
  this._subscriptions.set(o, {
3231
3303
  subscriptionId: o,
3232
3304
  collection: e,
@@ -3490,7 +3562,7 @@ var F = class {
3490
3562
  _detachHandlers(e) {
3491
3563
  e.onopen = null, e.onmessage = null, e.onclose = null, e.onerror = null;
3492
3564
  }
3493
- }, pt = (r) => {
3565
+ }, bt = (r) => {
3494
3566
  if (typeof WebSocket > "u")
3495
3567
  throw new Error(
3496
3568
  "[NeetruRealtimeClient] WebSocket n\xE3o dispon\xEDvel neste ambiente. Injete uma implementa\xE7\xE3o via `webSocketFactory` nas op\xE7\xF5es."
@@ -3499,12 +3571,12 @@ var F = class {
3499
3571
  };
3500
3572
 
3501
3573
  // src/db/client-db.ts
3502
- k();
3503
- var Ot = (r) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}`, Y = (r, e) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}/${encodeURIComponent(e)}`, Be = 200;
3504
- function xt(r, e, t) {
3505
- return e._transport ? e._transport : r === "firestore" && e.firestoreTransport ? e.firestoreTransport : r === "nosql-vm" && e.realtimeGatewayUrl ? At(e.realtimeGatewayUrl, t, e) : je(t);
3574
+ I();
3575
+ var Vt = (r) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}`, Y = (r, e) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}/${encodeURIComponent(e)}`, Ge = 200;
3576
+ function jt(r, e, t) {
3577
+ return e._transport ? e._transport : r === "firestore" && e.firestoreTransport ? e.firestoreTransport : r === "nosql-vm" && e.realtimeGatewayUrl ? Qt(e.realtimeGatewayUrl, t, e) : Xe(t);
3506
3578
  }
3507
- function je(r) {
3579
+ function Xe(r) {
3508
3580
  return {
3509
3581
  async pushMutations(e) {
3510
3582
  if (!r)
@@ -3582,7 +3654,7 @@ function je(r) {
3582
3654
  try {
3583
3655
  l = await t(r, {
3584
3656
  method: "GET",
3585
- path: Ot(c),
3657
+ path: Vt(c),
3586
3658
  requireAuth: !0,
3587
3659
  retries: 2,
3588
3660
  headers: o,
@@ -3590,37 +3662,37 @@ function je(r) {
3590
3662
  // TRUNCADAS — reportadas em `truncatedCollections` p/ o SyncEngine
3591
3663
  // (a) NÃO rodar deleção-por-ausência e (b) sinalizar
3592
3664
  // `DbListResult.truncated`. Paginação por cursor é tarefa Core (gated).
3593
- query: { limit: Be }
3665
+ query: { limit: Ge }
3594
3666
  });
3595
3667
  } catch (f) {
3596
- let _ = f instanceof Error ? f.message : String(f);
3668
+ let h = f instanceof Error ? f.message : String(f);
3597
3669
  throw new p(
3598
3670
  "db_unavailable",
3599
- `[RestSyncTransport] fullResync falhou na cole\xE7\xE3o "${c}": ${_}`
3671
+ `[RestSyncTransport] fullResync falhou na cole\xE7\xE3o "${c}": ${h}`
3600
3672
  );
3601
3673
  }
3602
3674
  let d = l, u = Array.isArray(d?.items) ? d.items : [];
3603
- u.length >= Be && a.push(c);
3675
+ u.length >= Ge && a.push(c);
3604
3676
  for (let f of u) {
3605
3677
  if (!f || typeof f != "object") continue;
3606
- let _ = f, h = typeof _.id == "string" ? _.id : null;
3607
- if (!h) continue;
3608
- let { id: X, ...b } = _, v = i, y = b._updatedAt;
3609
- if (typeof y == "number")
3610
- v = y;
3611
- else if (y !== null && typeof y == "object" && typeof y._seconds == "number")
3612
- v = y._seconds * 1e3;
3613
- else if (typeof y == "string") {
3614
- let M = Date.parse(y);
3615
- Number.isNaN(M) || (v = M);
3678
+ let h = f, v = typeof h.id == "string" ? h.id : null;
3679
+ if (!v) continue;
3680
+ let { id: _, ...B } = h, y = i, b = B._updatedAt;
3681
+ if (typeof b == "number")
3682
+ y = b;
3683
+ else if (b !== null && typeof b == "object" && typeof b._seconds == "number")
3684
+ y = b._seconds * 1e3;
3685
+ else if (typeof b == "string") {
3686
+ let C = Date.parse(b);
3687
+ Number.isNaN(C) || (y = C);
3616
3688
  }
3617
- let L = `rest_${h}_${v}`;
3689
+ let w = `rest_${v}_${y}`;
3618
3690
  s.push({
3619
3691
  collection: c,
3620
- id: h,
3621
- data: b,
3622
- serverVersion: L,
3623
- serverTimestamp: v,
3692
+ id: v,
3693
+ data: B,
3694
+ serverVersion: w,
3695
+ serverTimestamp: y,
3624
3696
  deleted: false
3625
3697
  });
3626
3698
  }
@@ -3629,10 +3701,10 @@ function je(r) {
3629
3701
  }
3630
3702
  };
3631
3703
  }
3632
- function At(r, e, t) {
3633
- let n = je(e), o = new F({
3704
+ function Qt(r, e, t) {
3705
+ let n = Xe(e), o = new F({
3634
3706
  gatewayUrl: r,
3635
- ticketProvider: Nt(e, t),
3707
+ ticketProvider: zt(e, t),
3636
3708
  dbId: t.dbId,
3637
3709
  webSocketFactory: t._wsFactory
3638
3710
  });
@@ -3668,7 +3740,7 @@ function At(r, e, t) {
3668
3740
  }
3669
3741
  };
3670
3742
  }
3671
- function Nt(r, e) {
3743
+ function zt(r, e) {
3672
3744
  return async () => {
3673
3745
  let { httpRequest: t } = await Promise.resolve().then(() => (W(), U));
3674
3746
  return await t(r, {
@@ -3683,27 +3755,27 @@ function Nt(r, e) {
3683
3755
  });
3684
3756
  };
3685
3757
  }
3686
- function Mn(r, e, t, n) {
3758
+ function zn(r, e, t, n) {
3687
3759
  return new F({ gatewayUrl: r, ticketProvider: e, dbId: t, webSocketFactory: n });
3688
3760
  }
3689
3761
  var pe = false;
3690
- function On() {
3762
+ function Kn() {
3691
3763
  pe = false;
3692
3764
  }
3693
- function qt(r, e) {
3765
+ function Kt(r, e) {
3694
3766
  pe || e.dbId && r.env !== "prod" && (typeof window > "u" || typeof console > "u" || typeof console.warn != "function" || (pe = true, console.warn(
3695
3767
  '[neetru/sdk] client.db recebeu `dbId` ("' + e.dbId + '") mas ele N\xC3O roteia nem escopa nada no servidor: as escritas do mundo Documentos (add/set/update/remove/list) SEMPRE caem no datastore gen\xE9rico do Core, escopado s\xF3 por tenant/produto (header x-neetru-tenant). `dbId` apenas nomeia o cache offline LOCAL (IndexedDB). ATEN\xC7\xC3O: usar dbIds distintos no MESMO tenant/produto N\xC3O isola os dados no servidor \u2014 eles se misturam (co-mingling). Veja o JSDoc de NeetruDbOptions.dbId.'
3696
3768
  )));
3697
3769
  }
3698
- function xn(r, e = {}) {
3699
- qt(r, e);
3770
+ function Hn(r, e = {}) {
3771
+ Kt(r, e);
3700
3772
  let t;
3701
3773
  e.transport !== void 0 ? t = e.transport : e.engine !== void 0 ? (console.warn(
3702
3774
  '[neetru/sdk] NeetruDbOptions.engine est\xE1 depreciado e ser\xE1 removido em v3.0. Use NeetruDbOptions.transport em vez de engine. Valores v\xE1lidos: "rest" | "firestore" | "nosql-vm". Nota: "engine" no SDK configura o TRANSPORTE (REST/Firestore/WebSocket), n\xE3o o storage engine do admin database (firestore-instance, cloud-sql-postgres, \u2026).'
3703
3775
  ), t = e.engine) : t = "rest";
3704
- let n = xt(t, e, r), o = e.dbId ?? "default", i = e.dbName ?? `neetru-db__${r.productId ?? "sdk"}__${o}__${r.env}`, s = null, a = null;
3776
+ let n = jt(t, e, r), o = e.dbId ?? "default", i = e.dbName ?? `neetru-db__${r.productId ?? "sdk"}__${o}__${r.env}`, s = null, a = null;
3705
3777
  function c() {
3706
- return s || (s = ve({
3778
+ return s || (s = we({
3707
3779
  dbName: i,
3708
3780
  transport: n,
3709
3781
  singleTab: e.singleTab ?? r.env !== "prod"
@@ -3711,7 +3783,7 @@ function xn(r, e = {}) {
3711
3783
  }
3712
3784
  return {
3713
3785
  collection(l) {
3714
- return a ? a.collection(l) : Ft(l, c);
3786
+ return a ? a.collection(l) : Ht(l, c);
3715
3787
  },
3716
3788
  async sql(l, d) {
3717
3789
  if (r.env === "dev")
@@ -3719,7 +3791,7 @@ function xn(r, e = {}) {
3719
3791
  "db_unavailable",
3720
3792
  "[SDK] db.sql() n\xE3o dispon\xEDvel em NEETRU_ENV=dev. Use `neetru dev` para subir o container Postgres local."
3721
3793
  );
3722
- return (await Promise.resolve().then(() => ($e(), We))).createSqlClientFromConfig(r, l, d);
3794
+ return (await Promise.resolve().then(() => (He(), Ke))).createSqlClientFromConfig(r, l, d);
3723
3795
  },
3724
3796
  get syncState() {
3725
3797
  return a?.syncState ?? {
@@ -3758,7 +3830,7 @@ function xn(r, e = {}) {
3758
3830
  }
3759
3831
  };
3760
3832
  }
3761
- function Ft(r, e) {
3833
+ function Ht(r, e) {
3762
3834
  async function t() {
3763
3835
  return (await e()).collection(r);
3764
3836
  }
@@ -3836,4 +3908,4 @@ function Ft(r, e) {
3836
3908
  };
3837
3909
  }
3838
3910
 
3839
- export { te as NEETRU_SENTINEL_KEY, p as NeetruDbError, On as __resetDbIdWarningForTests, xn as createNeetruDb, je as createRestSyncTransport, Mn as getWebSocketRealtimeClient, Ze as increment, R as isFieldSentinel, ye as isIncrementSentinel, _e as isServerTimestampSentinel, Xe as serverTimestamp };
3911
+ export { te as NEETRU_SENTINEL_KEY, p as NeetruDbError, Kn as __resetDbIdWarningForTests, Hn as createNeetruDb, Xe as createRestSyncTransport, zn as getWebSocketRealtimeClient, st as increment, D as isFieldSentinel, ge as isIncrementSentinel, ye as isServerTimestampSentinel, it as serverTimestamp };