@neetru/sdk 3.8.1 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +14 -1
- package/dist/ai.cjs +1 -1
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +1 -1
- package/dist/auth.cjs +844 -803
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +841 -800
- package/dist/build-guard.cjs +186 -82
- package/dist/build-guard.d.cts +53 -1
- package/dist/build-guard.d.ts +53 -1
- package/dist/build-guard.mjs +175 -74
- package/dist/catalog.cjs +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/checkout.cjs +62 -49
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +62 -49
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +200 -187
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +193 -180
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +880 -839
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +847 -806
- package/dist/mobile.cjs +328 -276
- package/dist/mobile.d.cts +12 -2
- package/dist/mobile.d.ts +12 -2
- package/dist/mobile.mjs +328 -276
- package/dist/mocks.cjs +5 -5
- package/dist/mocks.d.cts +2 -2
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.mjs +4 -4
- package/dist/notifications.cjs +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +1 -1
- package/dist/react.cjs +119 -119
- package/dist/react.d.cts +8 -2
- package/dist/react.d.ts +8 -2
- package/dist/react.mjs +119 -119
- package/dist/support.cjs +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/support.mjs +1 -1
- package/dist/telemetry.cjs +62 -49
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +62 -49
- package/dist/{types-yv3EDKg2.d.cts → types-Bl_4HROd.d.cts} +62 -3
- package/dist/{types-BYPk_3HR.d.ts → types-Bqnsqvow.d.ts} +62 -3
- package/dist/usage.cjs +1 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +1 -1
- package/dist/webhooks.cjs +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +1 -1
- package/package.json +9 -1
package/dist/db.cjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var idb = require('idb');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var Ze = Object.defineProperty;
|
|
6
6
|
var S = (r, e) => () => (r && (e = r(r = 0)), e);
|
|
7
7
|
var me = (r, e) => {
|
|
8
8
|
for (var t in e)
|
|
9
|
-
|
|
9
|
+
Ze(r, t, { get: e[t], enumerable: true });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// src/errors.ts
|
|
@@ -38,9 +38,9 @@ var b, x = S(() => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
// src/db-errors.ts
|
|
41
|
-
var
|
|
41
|
+
var et; exports.NeetruDbError = void 0; var I = S(() => {
|
|
42
42
|
x();
|
|
43
|
-
|
|
43
|
+
et = /* @__PURE__ */ new Set([
|
|
44
44
|
"db_unavailable",
|
|
45
45
|
"db_conflict",
|
|
46
46
|
"db_timeout"
|
|
@@ -58,13 +58,13 @@ var Ze; exports.NeetruDbError = void 0; var I = S(() => {
|
|
|
58
58
|
*/
|
|
59
59
|
dbId;
|
|
60
60
|
constructor(e, t, n) {
|
|
61
|
-
super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable =
|
|
61
|
+
super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable = et.has(e), this.dbId = n, Object.setPrototypeOf(this, r.prototype);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
// src/idempotency.ts
|
|
67
|
-
function
|
|
67
|
+
function Re() {
|
|
68
68
|
let r = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
69
69
|
if (r && typeof r.randomUUID == "function")
|
|
70
70
|
return r.randomUUID();
|
|
@@ -73,15 +73,15 @@ function Te() {
|
|
|
73
73
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
|
-
var
|
|
76
|
+
var De = S(() => {
|
|
77
77
|
x();
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
// src/correlation.ts
|
|
81
|
-
function
|
|
82
|
-
return typeof r == "string" && r.length > 0 && r.length <= 128 &&
|
|
81
|
+
function Ce(r) {
|
|
82
|
+
return typeof r == "string" && r.length > 0 && r.length <= 128 && Tt.test(r);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function Rt() {
|
|
85
85
|
let r = globalThis.crypto;
|
|
86
86
|
try {
|
|
87
87
|
if (r && typeof r.randomUUID == "function") return r.randomUUID();
|
|
@@ -99,24 +99,24 @@ function St() {
|
|
|
99
99
|
let n = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
100
100
|
return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function Ie(r, e) {
|
|
103
103
|
let t, n = {};
|
|
104
104
|
for (let [i, s] of Object.entries(r)) {
|
|
105
|
-
if (i.toLowerCase() ===
|
|
106
|
-
|
|
105
|
+
if (i.toLowerCase() === ke) {
|
|
106
|
+
Ce(s) && (t = s);
|
|
107
107
|
continue;
|
|
108
108
|
}
|
|
109
109
|
n[i] = s;
|
|
110
110
|
}
|
|
111
|
-
let o = t ?? (
|
|
112
|
-
return n[
|
|
111
|
+
let o = t ?? (Ce(e) ? e : void 0) ?? Rt();
|
|
112
|
+
return n[ke] = o, { headers: n, correlationId: o };
|
|
113
113
|
}
|
|
114
|
-
var
|
|
115
|
-
|
|
114
|
+
var ke, Tt, Pe = S(() => {
|
|
115
|
+
ke = "x-correlation-id", Tt = /^[A-Za-z0-9._:\-]+$/;
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
// src/server-only-key.ts
|
|
119
|
-
function
|
|
119
|
+
function Ee() {
|
|
120
120
|
try {
|
|
121
121
|
let r = globalThis.navigator;
|
|
122
122
|
if (r && r.product === "ReactNative") return "react-native";
|
|
@@ -129,20 +129,20 @@ function Pe() {
|
|
|
129
129
|
}
|
|
130
130
|
return null;
|
|
131
131
|
}
|
|
132
|
-
var
|
|
132
|
+
var Le = S(() => {
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
// src/http.ts
|
|
136
136
|
var U = {};
|
|
137
137
|
me(U, {
|
|
138
|
-
checkCoreVersionCompat: () =>
|
|
139
|
-
httpRequest: () =>
|
|
140
|
-
statusToCode: () =>
|
|
138
|
+
checkCoreVersionCompat: () => Fe,
|
|
139
|
+
httpRequest: () => At,
|
|
140
|
+
statusToCode: () => Ue
|
|
141
141
|
});
|
|
142
142
|
function se(r) {
|
|
143
143
|
return r.split("+")[0] ?? r;
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function kt(r, e) {
|
|
146
146
|
let t = se(r).split(".").map(Number), n = se(e).split(".").map(Number), o = Math.max(t.length, n.length);
|
|
147
147
|
for (let i = 0; i < o; i++) {
|
|
148
148
|
let s = t[i] ?? 0, a = n[i] ?? 0;
|
|
@@ -150,62 +150,62 @@ function Rt(r, e) {
|
|
|
150
150
|
}
|
|
151
151
|
return 0;
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function qe() {
|
|
154
154
|
try {
|
|
155
|
-
return "3.
|
|
155
|
+
return "3.9.1";
|
|
156
156
|
} catch {
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
function
|
|
161
|
-
let r =
|
|
160
|
+
function Ct() {
|
|
161
|
+
let r = qe();
|
|
162
162
|
return r ? parseInt(r.split(".")[0] ?? "3", 10) : 3;
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function Fe(r) {
|
|
165
165
|
if (!r) return;
|
|
166
|
-
let e =
|
|
166
|
+
let e = Ct(), t = Dt[e];
|
|
167
167
|
if (!t) return;
|
|
168
168
|
let n = se(r);
|
|
169
|
-
if (
|
|
169
|
+
if (kt(n, t) < 0) {
|
|
170
170
|
let o = `${e}:${n}`;
|
|
171
|
-
|
|
171
|
+
Me.has(o) || (Me.add(o), console.warn(
|
|
172
172
|
`[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.`
|
|
173
173
|
));
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function It() {
|
|
177
177
|
let r = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
178
|
-
return
|
|
178
|
+
return Ee() ? "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;
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function Oe(r) {
|
|
181
181
|
let e = 200 * Math.pow(4, r), t = e * 0.2 * (Math.random() * 2 - 1);
|
|
182
182
|
return Math.max(50, Math.round(e + t));
|
|
183
183
|
}
|
|
184
|
-
function
|
|
184
|
+
function Ot(r) {
|
|
185
185
|
if (!r) return null;
|
|
186
186
|
let e = Number(r);
|
|
187
|
-
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3),
|
|
187
|
+
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), xe);
|
|
188
188
|
let t = Date.parse(r);
|
|
189
189
|
if (Number.isFinite(t)) {
|
|
190
190
|
let n = t - Date.now();
|
|
191
|
-
if (n > 0) return Math.min(n,
|
|
191
|
+
if (n > 0) return Math.min(n, xe);
|
|
192
192
|
}
|
|
193
193
|
return null;
|
|
194
194
|
}
|
|
195
|
-
function
|
|
195
|
+
function Ae(r) {
|
|
196
196
|
return new Promise((e) => setTimeout(e, r));
|
|
197
197
|
}
|
|
198
|
-
function
|
|
198
|
+
function Ue(r) {
|
|
199
199
|
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";
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function xt(r, e, t) {
|
|
202
202
|
let n = r.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, i = new URL(`${n}${o}`);
|
|
203
203
|
if (t)
|
|
204
204
|
for (let [s, a] of Object.entries(t))
|
|
205
205
|
a !== void 0 && i.searchParams.set(s, String(a));
|
|
206
206
|
return i.toString();
|
|
207
207
|
}
|
|
208
|
-
async function
|
|
208
|
+
async function Ne(r) {
|
|
209
209
|
let e = await r.text();
|
|
210
210
|
if (e)
|
|
211
211
|
try {
|
|
@@ -214,18 +214,18 @@ async function Ae(r) {
|
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
async function
|
|
218
|
-
let t = e.method ?? "GET", n =
|
|
217
|
+
async function At(r, e) {
|
|
218
|
+
let t = e.method ?? "GET", n = xt(r.baseUrl, e.path, e.query), o = Lt.has(t) ? Pt : Et, i = e.retries ?? o, { headers: s, correlationId: a } = Ie(
|
|
219
219
|
{ accept: "application/json", ...e.headers },
|
|
220
220
|
e.correlationId
|
|
221
|
-
), c =
|
|
221
|
+
), c = qe();
|
|
222
222
|
if (c && (s["x-neetru-sdk-version"] = c), e.requireAuth) {
|
|
223
223
|
if (!r.apiKey)
|
|
224
|
-
throw new b("missing_api_key",
|
|
224
|
+
throw new b("missing_api_key", It());
|
|
225
225
|
s.authorization = `Bearer ${r.apiKey}`;
|
|
226
226
|
}
|
|
227
227
|
if (e.idempotencyKey) {
|
|
228
|
-
let p = typeof e.idempotencyKey == "string" ? e.idempotencyKey :
|
|
228
|
+
let p = typeof e.idempotencyKey == "string" ? e.idempotencyKey : Re();
|
|
229
229
|
s["idempotency-key"] = p;
|
|
230
230
|
}
|
|
231
231
|
let l = e.body !== void 0 && t !== "GET" && t !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
@@ -251,9 +251,9 @@ async function Ot(r, e) {
|
|
|
251
251
|
} catch (m) {
|
|
252
252
|
let O = m instanceof DOMException && m.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${m instanceof Error ? m.message : "fetch failed"}`;
|
|
253
253
|
if (d = new b("network_error", O, void 0, void 0, void 0, a), p < i) {
|
|
254
|
-
let he =
|
|
254
|
+
let he = Oe(p);
|
|
255
255
|
if (u == null || Date.now() + he < u) {
|
|
256
|
-
await
|
|
256
|
+
await Ae(he);
|
|
257
257
|
continue;
|
|
258
258
|
}
|
|
259
259
|
}
|
|
@@ -262,9 +262,9 @@ async function Ot(r, e) {
|
|
|
262
262
|
let B = y.headers.get("x-request-id") ?? y.headers.get("x-correlation-id") ?? void 0;
|
|
263
263
|
if (y.ok) {
|
|
264
264
|
let m = y.headers.get("x-neetru-version");
|
|
265
|
-
return m &&
|
|
265
|
+
return m && Fe(m), await Ne(y);
|
|
266
266
|
}
|
|
267
|
-
let g = await
|
|
267
|
+
let g = await Ne(y), v = Ue(y.status), w = `HTTP ${y.status}`, C;
|
|
268
268
|
if (g && typeof g == "object") {
|
|
269
269
|
let m = g.error;
|
|
270
270
|
typeof m == "string" ? w = m : m && typeof m == "object" ? (typeof m.code == "string" && (v = m.code), typeof m.message == "string" && (w = m.message), typeof m.reason == "string" && (C = m.reason)) : (typeof g.code == "string" && (v = g.code), typeof g.message == "string" && (w = g.message)), typeof g.reason == "string" && (C = g.reason);
|
|
@@ -274,10 +274,10 @@ async function Ot(r, e) {
|
|
|
274
274
|
w === `HTTP ${y.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}.`);
|
|
275
275
|
}
|
|
276
276
|
let fe = new b(v, w, y.status, B, C, a);
|
|
277
|
-
if (d = fe,
|
|
278
|
-
let O =
|
|
277
|
+
if (d = fe, Mt.has(v) && p < i) {
|
|
278
|
+
let O = Ot(y.headers.get("retry-after")) ?? Oe(p);
|
|
279
279
|
if (u == null || Date.now() + O < u) {
|
|
280
|
-
await
|
|
280
|
+
await Ae(O);
|
|
281
281
|
continue;
|
|
282
282
|
}
|
|
283
283
|
}
|
|
@@ -285,30 +285,30 @@ async function Ot(r, e) {
|
|
|
285
285
|
}
|
|
286
286
|
throw d ?? new b("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
|
|
287
287
|
}
|
|
288
|
-
var
|
|
288
|
+
var Dt, Me, Pt, Et, Lt, Mt, xe, W = S(() => {
|
|
289
289
|
x();
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
290
|
+
De();
|
|
291
|
+
Pe();
|
|
292
|
+
Le();
|
|
293
|
+
Dt = {
|
|
294
294
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
295
295
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
296
296
|
3: "2026.05.1"
|
|
297
297
|
};
|
|
298
|
-
|
|
299
|
-
|
|
298
|
+
Me = /* @__PURE__ */ new Set();
|
|
299
|
+
Pt = 2, Et = 0, Lt = /* @__PURE__ */ new Set(["GET", "HEAD"]), Mt = /* @__PURE__ */ new Set([
|
|
300
300
|
"rate_limited",
|
|
301
301
|
"server_error",
|
|
302
302
|
"network_error"
|
|
303
303
|
]);
|
|
304
|
-
|
|
304
|
+
xe = 6e4;
|
|
305
305
|
});
|
|
306
306
|
|
|
307
307
|
// src/db/sql/resilient-pool.ts
|
|
308
308
|
function J(r) {
|
|
309
309
|
return typeof r == "object" && r !== null && r[ae] === true;
|
|
310
310
|
}
|
|
311
|
-
function
|
|
311
|
+
function Nt(r) {
|
|
312
312
|
let e = r && typeof r == "object" && "code" in r ? r.code : void 0;
|
|
313
313
|
if (e === "ECONNREFUSED" || e === "ETIMEDOUT" || e === "ENOTFOUND" || e === "EHOSTUNREACH" || e === "EAI_AGAIN")
|
|
314
314
|
return true;
|
|
@@ -320,15 +320,15 @@ function xt(r) {
|
|
|
320
320
|
let n = (r instanceof Error ? r.message : typeof r == "string" ? r : "").toLowerCase();
|
|
321
321
|
return n.length === 0 ? false : !!(n.includes("certificate expired") || n.includes("certificate has expired") || n.includes("cert_has_expired") || n.includes("alert certificate expired") || n.includes("err_ssl") || n.includes("sslv3 alert") || n.includes("tlsv1 alert") || n.includes("econnrefused") || n.includes("etimedout") || n.includes("enotfound") || n.includes("ehostunreach") || n.includes("getaddrinfo"));
|
|
322
322
|
}
|
|
323
|
-
function
|
|
323
|
+
function We(r) {
|
|
324
324
|
let e = r && typeof r == "object" && "code" in r ? r.code : void 0;
|
|
325
|
-
if (typeof e == "string" &&
|
|
325
|
+
if (typeof e == "string" && qt.has(e.toUpperCase()))
|
|
326
326
|
return true;
|
|
327
327
|
let n = (r instanceof Error ? r.message : typeof r == "string" ? r : "").toLowerCase();
|
|
328
328
|
return n.length === 0 ? false : n.includes("password authentication failed") || n.includes("sasl authentication failed");
|
|
329
329
|
}
|
|
330
|
-
function
|
|
331
|
-
return
|
|
330
|
+
function Ft(r) {
|
|
331
|
+
return Nt(r) || We(r);
|
|
332
332
|
}
|
|
333
333
|
function ce(r) {
|
|
334
334
|
let e = { current: r }, t = null, n = {
|
|
@@ -358,7 +358,7 @@ function ce(r) {
|
|
|
358
358
|
}
|
|
359
359
|
return await o(d, e.current, p);
|
|
360
360
|
}
|
|
361
|
-
})(), s = i("query",
|
|
361
|
+
})(), s = i("query", Ft), a = i("connect", We), c = Object.create(Object.getPrototypeOf(r));
|
|
362
362
|
return new Proxy(c, {
|
|
363
363
|
get(d, u) {
|
|
364
364
|
if (u === ae) return true;
|
|
@@ -377,16 +377,16 @@ function ce(r) {
|
|
|
377
377
|
}
|
|
378
378
|
});
|
|
379
379
|
}
|
|
380
|
-
var ae,
|
|
380
|
+
var ae, qt, le = S(() => {
|
|
381
381
|
ae = /* @__PURE__ */ Symbol.for("neetru.sdk.resilientPool");
|
|
382
|
-
|
|
382
|
+
qt = /* @__PURE__ */ new Set(["28P01", "28000"]);
|
|
383
383
|
});
|
|
384
384
|
|
|
385
385
|
// src/db/sql/lease.ts
|
|
386
|
-
function
|
|
386
|
+
function Wt(r, e) {
|
|
387
387
|
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;
|
|
388
388
|
}
|
|
389
|
-
function
|
|
389
|
+
function $t(r) {
|
|
390
390
|
if (r instanceof exports.NeetruDbError) return r;
|
|
391
391
|
let e = r instanceof Error ? r.message : String(r), t = r instanceof Error ? r.code : void 0;
|
|
392
392
|
return typeof t == "string" && (t === "ECONNREFUSED" || t === "ENOTFOUND" || t === "ETIMEDOUT") ? new exports.NeetruDbError(
|
|
@@ -394,10 +394,10 @@ function Ut(r) {
|
|
|
394
394
|
`Pool connection failed (${t}): ${e}`
|
|
395
395
|
) : e.includes("statement timeout") || e.includes("lock timeout") ? new exports.NeetruDbError("db_timeout", `Query timeout: ${e}`) : e.includes("40001") || e.includes("40P01") || e.includes("deadlock") ? new exports.NeetruDbError("db_conflict", `Transaction conflict: ${e}`) : e.includes("42501") || e.toLowerCase().includes("permission denied") ? new exports.NeetruDbError("db_permission_denied", `Permission denied: ${e}`) : new exports.NeetruDbError("db_unavailable", `Database error: ${e}`);
|
|
396
396
|
}
|
|
397
|
-
var
|
|
397
|
+
var Ut, M, $, $e = S(() => {
|
|
398
398
|
I();
|
|
399
399
|
le();
|
|
400
|
-
|
|
400
|
+
Ut = 0.8, M = 3e4, $ = class {
|
|
401
401
|
/**
|
|
402
402
|
* Lease atual. `null` no modo LAZY antes da 1ª query (o 1º lease é adiado —
|
|
403
403
|
* ver `_ensureInitialLease`). Após a 1ª aquisição, sempre não-nulo.
|
|
@@ -437,7 +437,7 @@ var qt, M, $, We = S(() => {
|
|
|
437
437
|
isolationLevel: t.isolationLevel
|
|
438
438
|
}) : await this._orm.transaction(e);
|
|
439
439
|
} catch (n) {
|
|
440
|
-
throw
|
|
440
|
+
throw $t(n);
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
443
|
async close() {
|
|
@@ -460,7 +460,7 @@ var qt, M, $, We = S(() => {
|
|
|
460
460
|
if (!Number.isFinite(e)) return M;
|
|
461
461
|
let t = this._deps.now(), n = e - t;
|
|
462
462
|
if (n <= 0) return M;
|
|
463
|
-
let o = n * (1 -
|
|
463
|
+
let o = n * (1 - Ut);
|
|
464
464
|
return Math.max(M, Math.round(o));
|
|
465
465
|
}
|
|
466
466
|
_scheduleRenewal() {
|
|
@@ -599,7 +599,7 @@ var qt, M, $, We = S(() => {
|
|
|
599
599
|
* Exposto como método protegido para testes.
|
|
600
600
|
*/
|
|
601
601
|
async _swapPool(e) {
|
|
602
|
-
if (!
|
|
602
|
+
if (!Wt(this._lease, e)) {
|
|
603
603
|
this._lease = e;
|
|
604
604
|
return;
|
|
605
605
|
}
|
|
@@ -626,29 +626,29 @@ var qt, M, $, We = S(() => {
|
|
|
626
626
|
});
|
|
627
627
|
|
|
628
628
|
// src/db/sql/sql-client.ts
|
|
629
|
-
var
|
|
630
|
-
me(
|
|
631
|
-
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () =>
|
|
632
|
-
DEFAULT_POOL_IDLE_MS: () =>
|
|
633
|
-
DEFAULT_POOL_MAX: () =>
|
|
634
|
-
LEASE_ENDPOINT: () =>
|
|
635
|
-
LEASE_RENEW_ENDPOINT: () =>
|
|
636
|
-
createDrizzleHandle: () =>
|
|
629
|
+
var Ge = {};
|
|
630
|
+
me(Ge, {
|
|
631
|
+
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () => Ke,
|
|
632
|
+
DEFAULT_POOL_IDLE_MS: () => ze,
|
|
633
|
+
DEFAULT_POOL_MAX: () => Qe,
|
|
634
|
+
LEASE_ENDPOINT: () => Be,
|
|
635
|
+
LEASE_RENEW_ENDPOINT: () => Ve,
|
|
636
|
+
createDrizzleHandle: () => Qt,
|
|
637
637
|
createHttpLeaseFetcher: () => je,
|
|
638
|
-
createPgPool: () =>
|
|
639
|
-
createSqlClientFromConfig: () =>
|
|
640
|
-
createSqlClientWithDeps: () =>
|
|
638
|
+
createPgPool: () => jt,
|
|
639
|
+
createSqlClientFromConfig: () => Kt,
|
|
640
|
+
createSqlClientWithDeps: () => He,
|
|
641
641
|
resolvePoolTuning: () => ue
|
|
642
642
|
});
|
|
643
|
-
function
|
|
643
|
+
function Bt(r) {
|
|
644
644
|
return r === "workspace" ? "staging" : r === "prod" ? "production" : "dev-local";
|
|
645
645
|
}
|
|
646
646
|
function je(r) {
|
|
647
647
|
return async (e) => {
|
|
648
|
-
let { httpRequest: t } = await Promise.resolve().then(() => (W(), U)), n = !!e?.leaseId, o = n ?
|
|
648
|
+
let { httpRequest: t } = await Promise.resolve().then(() => (W(), U)), n = !!e?.leaseId, o = n ? Ve : Be, i;
|
|
649
649
|
n ? i = { leaseId: e.leaseId } : (i = {
|
|
650
650
|
productId: r.productId ?? "",
|
|
651
|
-
environment:
|
|
651
|
+
environment: Bt(r.env ?? "prod")
|
|
652
652
|
}, e?.database !== void 0 && (i.database = e.database));
|
|
653
653
|
let s;
|
|
654
654
|
try {
|
|
@@ -674,10 +674,10 @@ function je(r) {
|
|
|
674
674
|
`Falha ao ${c} lease SQL: ${l}`
|
|
675
675
|
);
|
|
676
676
|
}
|
|
677
|
-
return
|
|
677
|
+
return Vt(s);
|
|
678
678
|
};
|
|
679
679
|
}
|
|
680
|
-
function
|
|
680
|
+
function Vt(r) {
|
|
681
681
|
if (!r || typeof r != "object")
|
|
682
682
|
throw new exports.NeetruDbError("db_unavailable", "Resposta de lease inv\xE1lida (n\xE3o \xE9 objeto).");
|
|
683
683
|
let t = r.lease;
|
|
@@ -719,12 +719,12 @@ function ue() {
|
|
|
719
719
|
return {
|
|
720
720
|
// Teto 100: bem abaixo do `max_client_conn = 500` do PgBouncer, com folga
|
|
721
721
|
// para múltiplas instâncias do app dividirem o mesmo front-door.
|
|
722
|
-
max: de("NEETRU_DB_POOL_MAX",
|
|
722
|
+
max: de("NEETRU_DB_POOL_MAX", Qe, 1, 100),
|
|
723
723
|
// Teto 15min = janela do cert; piso 1s.
|
|
724
|
-
idleTimeoutMillis: de("NEETRU_DB_POOL_IDLE_MS",
|
|
724
|
+
idleTimeoutMillis: de("NEETRU_DB_POOL_IDLE_MS", ze, 1e3, 9e5),
|
|
725
725
|
connectionTimeoutMillis: de(
|
|
726
726
|
"NEETRU_DB_POOL_CONNECT_TIMEOUT_MS",
|
|
727
|
-
|
|
727
|
+
Ke,
|
|
728
728
|
1e3,
|
|
729
729
|
12e4
|
|
730
730
|
),
|
|
@@ -732,7 +732,7 @@ function ue() {
|
|
|
732
732
|
keepAliveInitialDelayMillis: 1e4
|
|
733
733
|
};
|
|
734
734
|
}
|
|
735
|
-
async function
|
|
735
|
+
async function jt(r) {
|
|
736
736
|
let { Pool: e } = await import(
|
|
737
737
|
/* webpackIgnore: true */
|
|
738
738
|
'pg'
|
|
@@ -752,14 +752,14 @@ async function Bt(r) {
|
|
|
752
752
|
...ue()
|
|
753
753
|
});
|
|
754
754
|
}
|
|
755
|
-
async function
|
|
755
|
+
async function Qt(r, e) {
|
|
756
756
|
let { drizzle: t } = await import(
|
|
757
757
|
/* webpackIgnore: true */
|
|
758
758
|
'drizzle-orm/node-postgres'
|
|
759
759
|
);
|
|
760
760
|
return t(r, { schema: e });
|
|
761
761
|
}
|
|
762
|
-
function
|
|
762
|
+
function zt(r, e) {
|
|
763
763
|
let t = null, n = null, o = () => t ? Promise.resolve(t) : (n || (n = e().then((s) => (t = s, n = null, s)).catch((s) => {
|
|
764
764
|
throw n = null, s;
|
|
765
765
|
})), n), i = {
|
|
@@ -775,10 +775,10 @@ function Vt(r, e) {
|
|
|
775
775
|
};
|
|
776
776
|
return r && Object.setPrototypeOf(i, r), i;
|
|
777
777
|
}
|
|
778
|
-
async function
|
|
778
|
+
async function He(r, e) {
|
|
779
779
|
let t = e?.database !== void 0 ? { ...r, database: e.database } : r;
|
|
780
780
|
if (t.lazy) {
|
|
781
|
-
let c = null, l =
|
|
781
|
+
let c = null, l = zt(t.poolPrototype ?? null, () => {
|
|
782
782
|
if (!c)
|
|
783
783
|
throw new exports.NeetruDbError("db_unavailable", "SQL client n\xE3o inicializado (manager ausente).");
|
|
784
784
|
return c._ensureInitialLease();
|
|
@@ -819,7 +819,7 @@ async function Ke(r, e) {
|
|
|
819
819
|
let a = new $(n, i, s, t);
|
|
820
820
|
return i.__neetruSetReLease(() => a._reactiveReLease()), a;
|
|
821
821
|
}
|
|
822
|
-
async function
|
|
822
|
+
async function Kt(r, e, t) {
|
|
823
823
|
let n = je(r), o, i;
|
|
824
824
|
try {
|
|
825
825
|
o = await import(
|
|
@@ -836,7 +836,7 @@ async function Qt(r, e, t) {
|
|
|
836
836
|
);
|
|
837
837
|
}
|
|
838
838
|
let s = o.Pool ?? o.default?.Pool;
|
|
839
|
-
return
|
|
839
|
+
return He(
|
|
840
840
|
{
|
|
841
841
|
fetchLease: n,
|
|
842
842
|
createPool: (l) => {
|
|
@@ -871,24 +871,37 @@ async function Qt(r, e, t) {
|
|
|
871
871
|
t
|
|
872
872
|
);
|
|
873
873
|
}
|
|
874
|
-
var
|
|
874
|
+
var Be, Ve, Qe, ze, Ke, Xe = S(() => {
|
|
875
875
|
I();
|
|
876
876
|
x();
|
|
877
|
-
|
|
877
|
+
$e();
|
|
878
878
|
le();
|
|
879
|
-
|
|
880
|
-
|
|
879
|
+
Be = "/api/sdk/v1/db/lease", Ve = "/api/sdk/v1/db/lease/renew";
|
|
880
|
+
Qe = 10, ze = 6e4, Ke = 1e4;
|
|
881
881
|
});
|
|
882
882
|
|
|
883
883
|
// src/db/client-db.ts
|
|
884
884
|
I();
|
|
885
885
|
|
|
886
|
-
// src/
|
|
886
|
+
// src/runtime-env.ts
|
|
887
|
+
function tt() {
|
|
888
|
+
try {
|
|
889
|
+
if (typeof process < "u" && process.env)
|
|
890
|
+
return process.env.NODE_ENV === "production";
|
|
891
|
+
} catch {
|
|
892
|
+
}
|
|
893
|
+
return false;
|
|
894
|
+
}
|
|
887
895
|
function _e(r) {
|
|
896
|
+
return r === "dev" && !tt();
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// src/db/offline/query-engine.ts
|
|
900
|
+
function ye(r) {
|
|
888
901
|
return r == null ? 0 : typeof r == "number" ? 1 : typeof r == "string" ? 2 : typeof r == "boolean" ? 3 : 4;
|
|
889
902
|
}
|
|
890
903
|
function A(r, e) {
|
|
891
|
-
let t =
|
|
904
|
+
let t = ye(r), n = ye(e);
|
|
892
905
|
if (t !== n) return t - n;
|
|
893
906
|
if (r == null) return 0;
|
|
894
907
|
if (typeof r == "number" && typeof e == "number") return r - e;
|
|
@@ -906,7 +919,7 @@ function Z(r, e) {
|
|
|
906
919
|
}
|
|
907
920
|
return n;
|
|
908
921
|
}
|
|
909
|
-
function
|
|
922
|
+
function nt(r, e) {
|
|
910
923
|
let t = Z(r, e.field);
|
|
911
924
|
if (t === void 0) return false;
|
|
912
925
|
let { op: n, value: o } = e;
|
|
@@ -937,10 +950,10 @@ function et(r, e) {
|
|
|
937
950
|
);
|
|
938
951
|
}
|
|
939
952
|
}
|
|
940
|
-
function
|
|
941
|
-
return e.every((t) =>
|
|
953
|
+
function rt(r, e) {
|
|
954
|
+
return e.every((t) => nt(r, t));
|
|
942
955
|
}
|
|
943
|
-
function
|
|
956
|
+
function ot(r) {
|
|
944
957
|
return (e, t) => {
|
|
945
958
|
if (r) {
|
|
946
959
|
let n = Z(e.data, r.field), o = Z(t.data, r.field), i = A(n, o);
|
|
@@ -950,7 +963,7 @@ function nt(r) {
|
|
|
950
963
|
return e.id < t.id ? -1 : e.id > t.id ? 1 : 0;
|
|
951
964
|
};
|
|
952
965
|
}
|
|
953
|
-
function
|
|
966
|
+
function it(r, e) {
|
|
954
967
|
let t = r.findIndex((n) => n.id === e.docId);
|
|
955
968
|
return t === -1 ? r : e.type === "startAfter" ? r.slice(t + 1) : r.slice(0, t);
|
|
956
969
|
}
|
|
@@ -968,9 +981,9 @@ var P = class r {
|
|
|
968
981
|
evaluate(e, t) {
|
|
969
982
|
let n = e.filter((d) => !d.meta.deleted), o = t.where ?? [];
|
|
970
983
|
o.length > 0 && (n = n.filter(
|
|
971
|
-
(d) =>
|
|
984
|
+
(d) => rt(d.data, o)
|
|
972
985
|
));
|
|
973
|
-
let i =
|
|
986
|
+
let i = ot(t.orderBy), s = [...n].sort(i), a = t.cursor ? it(s, t.cursor) : s, c = Math.min(t.limit ?? 20, 500);
|
|
974
987
|
return {
|
|
975
988
|
docs: a.slice(0, c).map((d) => ({ id: d.id, data: d.data })),
|
|
976
989
|
// `incomplete` é sempre true aqui — o QueryEngine não sabe se o cache
|
|
@@ -990,7 +1003,7 @@ var P = class r {
|
|
|
990
1003
|
};
|
|
991
1004
|
|
|
992
1005
|
// src/db/offline/local-store.ts
|
|
993
|
-
var
|
|
1006
|
+
var at = 1, T = "documents", R = "mutations", N = "query_cache", V = "sync_meta", E = "conflict_log", j = class {
|
|
994
1007
|
db = null;
|
|
995
1008
|
dbName;
|
|
996
1009
|
constructor(e) {
|
|
@@ -1002,7 +1015,7 @@ var it = 1, T = "documents", R = "mutations", N = "query_cache", j = "sync_meta"
|
|
|
1002
1015
|
* Idempotente — chamadas subsequentes são no-ops se o banco já está aberto.
|
|
1003
1016
|
*/
|
|
1004
1017
|
async open() {
|
|
1005
|
-
this.db === null && (this.db = await idb.openDB(this.dbName,
|
|
1018
|
+
this.db === null && (this.db = await idb.openDB(this.dbName, at, {
|
|
1006
1019
|
upgrade(e) {
|
|
1007
1020
|
if (!e.objectStoreNames.contains(T)) {
|
|
1008
1021
|
let t = e.createObjectStore(T, {
|
|
@@ -1016,7 +1029,7 @@ var it = 1, T = "documents", R = "mutations", N = "query_cache", j = "sync_meta"
|
|
|
1016
1029
|
});
|
|
1017
1030
|
t.createIndex("by_seq", "seq"), t.createIndex("by_status", "status"), t.createIndex("by_doc", ["collection", "docId"]), t.createIndex("by_batch", "batchId");
|
|
1018
1031
|
}
|
|
1019
|
-
if (e.objectStoreNames.contains(N) || e.createObjectStore(N, { keyPath: "queryHash" }), e.objectStoreNames.contains(
|
|
1032
|
+
if (e.objectStoreNames.contains(N) || e.createObjectStore(N, { keyPath: "queryHash" }), e.objectStoreNames.contains(V) || e.createObjectStore(V, { keyPath: "key" }), !e.objectStoreNames.contains(E)) {
|
|
1020
1033
|
let t = e.createObjectStore(E, {
|
|
1021
1034
|
keyPath: "id",
|
|
1022
1035
|
autoIncrement: true
|
|
@@ -1103,14 +1116,14 @@ var it = 1, T = "documents", R = "mutations", N = "query_cache", j = "sync_meta"
|
|
|
1103
1116
|
* 'lastFullResyncAt', 'leaderTabId'.
|
|
1104
1117
|
*/
|
|
1105
1118
|
async getMeta(e) {
|
|
1106
|
-
let n = await this.assertOpen().get(
|
|
1119
|
+
let n = await this.assertOpen().get(V, e);
|
|
1107
1120
|
return n ? n.value : null;
|
|
1108
1121
|
}
|
|
1109
1122
|
/**
|
|
1110
1123
|
* Armazena ou atualiza um valor na store `sync_meta`.
|
|
1111
1124
|
*/
|
|
1112
1125
|
async setMeta(e, t) {
|
|
1113
|
-
await this.assertOpen().put(
|
|
1126
|
+
await this.assertOpen().put(V, { key: e, value: t });
|
|
1114
1127
|
}
|
|
1115
1128
|
// ─── Conflict log ───────────────────────────────────────────────────────────
|
|
1116
1129
|
/**
|
|
@@ -1551,10 +1564,10 @@ var z = class {
|
|
|
1551
1564
|
|
|
1552
1565
|
// src/db/field-value.ts
|
|
1553
1566
|
var te = "__neetru__";
|
|
1554
|
-
function
|
|
1567
|
+
function ct() {
|
|
1555
1568
|
return { __neetru__: "serverTimestamp" };
|
|
1556
1569
|
}
|
|
1557
|
-
function
|
|
1570
|
+
function lt(r) {
|
|
1558
1571
|
if (typeof r != "number" || !Number.isFinite(r))
|
|
1559
1572
|
throw new TypeError(
|
|
1560
1573
|
`increment(n): n deve ser um n\xFAmero finito (recebido: ${String(r)}).`
|
|
@@ -1564,19 +1577,19 @@ function at(r) {
|
|
|
1564
1577
|
function D(r) {
|
|
1565
1578
|
return typeof r == "object" && r !== null && te in r && typeof r[te] == "string";
|
|
1566
1579
|
}
|
|
1567
|
-
function
|
|
1580
|
+
function ge(r) {
|
|
1568
1581
|
return D(r) && r.__neetru__ === "serverTimestamp";
|
|
1569
1582
|
}
|
|
1570
|
-
function
|
|
1583
|
+
function be(r) {
|
|
1571
1584
|
return D(r) && r.__neetru__ === "increment" && typeof r.operand == "number" && Number.isFinite(r.operand);
|
|
1572
1585
|
}
|
|
1573
|
-
function
|
|
1574
|
-
return
|
|
1586
|
+
function dt(r, e) {
|
|
1587
|
+
return ge(r) ? Date.now() : be(r) ? (typeof e == "number" && Number.isFinite(e) ? e : 0) + r.operand : r;
|
|
1575
1588
|
}
|
|
1576
1589
|
function k(r, e) {
|
|
1577
1590
|
let t = false, n = {};
|
|
1578
1591
|
for (let [o, i] of Object.entries(r))
|
|
1579
|
-
D(i) ? (t = true, n[o] =
|
|
1592
|
+
D(i) ? (t = true, n[o] = dt(i, e?.[o])) : n[o] = i;
|
|
1580
1593
|
return t ? n : r;
|
|
1581
1594
|
}
|
|
1582
1595
|
function ne(r) {
|
|
@@ -1586,11 +1599,11 @@ function ne(r) {
|
|
|
1586
1599
|
}
|
|
1587
1600
|
|
|
1588
1601
|
// src/db/offline/sync-engine.ts
|
|
1589
|
-
var
|
|
1590
|
-
function
|
|
1602
|
+
var ut = 8, pt = 1e3, ft = 300 * 1e3, re = "truncatedCollections";
|
|
1603
|
+
function ht(r) {
|
|
1591
1604
|
return r !== null && ne(r);
|
|
1592
1605
|
}
|
|
1593
|
-
function
|
|
1606
|
+
function mt(r) {
|
|
1594
1607
|
if (r === null) return null;
|
|
1595
1608
|
if (!ne(r)) return r;
|
|
1596
1609
|
let e = {};
|
|
@@ -1792,13 +1805,13 @@ var K = class {
|
|
|
1792
1805
|
}), s.push({ type: "removed", collection: e, doc: { id: t, data: a.data } }));
|
|
1793
1806
|
return;
|
|
1794
1807
|
}
|
|
1795
|
-
let l =
|
|
1808
|
+
let l = mt(i.payload) ?? a?.data ?? {}, d = {
|
|
1796
1809
|
collection: e,
|
|
1797
1810
|
id: t,
|
|
1798
1811
|
data: i.op === "update" ? { ...a?.data ?? {}, ...l } : (
|
|
1799
1812
|
// add/set: se o payload tinha sentinels, o cache otimista (existing.data)
|
|
1800
1813
|
// é a fonte de verdade até o pull; senão usa o payload literal.
|
|
1801
|
-
|
|
1814
|
+
ht(i.payload) ? { ...a?.data ?? {}, ...l } : l
|
|
1802
1815
|
),
|
|
1803
1816
|
meta: {
|
|
1804
1817
|
serverVersion: n,
|
|
@@ -1951,7 +1964,7 @@ var K = class {
|
|
|
1951
1964
|
* pending do doc no cache + registra `lastError`/dispara `onError`.
|
|
1952
1965
|
*/
|
|
1953
1966
|
async _retryOrDeadLetter(e, t, n) {
|
|
1954
|
-
if (e.attempts + 1 <
|
|
1967
|
+
if (e.attempts + 1 < ut) {
|
|
1955
1968
|
await this._queue.markRetry(e.mutationId, t);
|
|
1956
1969
|
return;
|
|
1957
1970
|
}
|
|
@@ -1992,7 +2005,7 @@ var K = class {
|
|
|
1992
2005
|
}
|
|
1993
2006
|
/** Backoff exponencial keyed em `attempts`, com teto `BACKOFF_CAP_MS`. */
|
|
1994
2007
|
_backoffDelayMs(e) {
|
|
1995
|
-
return Math.min(
|
|
2008
|
+
return Math.min(pt * 2 ** (e - 1), ft);
|
|
1996
2009
|
}
|
|
1997
2010
|
// ─── FASE 2 — pull (reconciliar o cache) ─────────────────────────────────────
|
|
1998
2011
|
/**
|
|
@@ -2244,7 +2257,7 @@ var K = class {
|
|
|
2244
2257
|
};
|
|
2245
2258
|
|
|
2246
2259
|
// src/db/offline/conflict-resolver.ts
|
|
2247
|
-
function
|
|
2260
|
+
function ve(r, e) {
|
|
2248
2261
|
return e === null ? false : r === null ? true : e > r;
|
|
2249
2262
|
}
|
|
2250
2263
|
var H = class r {
|
|
@@ -2281,7 +2294,7 @@ var H = class r {
|
|
|
2281
2294
|
resolvedData: t.data,
|
|
2282
2295
|
conflictRecord: null
|
|
2283
2296
|
};
|
|
2284
|
-
if (!
|
|
2297
|
+
if (!ve(
|
|
2285
2298
|
e.meta.updatedAtServer,
|
|
2286
2299
|
t.meta.updatedAtServer
|
|
2287
2300
|
))
|
|
@@ -2328,7 +2341,7 @@ var H = class r {
|
|
|
2328
2341
|
let i = t.data;
|
|
2329
2342
|
if (e === null)
|
|
2330
2343
|
return { outcome: "no_conflict", resolvedData: { ...i, ...n.payload ?? {} }, conflictRecord: null };
|
|
2331
|
-
if (!
|
|
2344
|
+
if (!ve(
|
|
2332
2345
|
e.meta.updatedAtServer,
|
|
2333
2346
|
t.meta.updatedAtServer
|
|
2334
2347
|
))
|
|
@@ -2406,7 +2419,7 @@ var H = class r {
|
|
|
2406
2419
|
};
|
|
2407
2420
|
|
|
2408
2421
|
// src/db/offline/change-bus.ts
|
|
2409
|
-
function
|
|
2422
|
+
function _t(r) {
|
|
2410
2423
|
return `${r.collection}::${r.doc.id}`;
|
|
2411
2424
|
}
|
|
2412
2425
|
var G = class {
|
|
@@ -2454,7 +2467,7 @@ var G = class {
|
|
|
2454
2467
|
if (e.length === 0) return;
|
|
2455
2468
|
let t = /* @__PURE__ */ new Map();
|
|
2456
2469
|
for (let i of e)
|
|
2457
|
-
t.set(
|
|
2470
|
+
t.set(_t(i), i);
|
|
2458
2471
|
let n = Array.from(t.values()), o = /* @__PURE__ */ new Map();
|
|
2459
2472
|
for (let i of n)
|
|
2460
2473
|
o.has(i.collection) || o.set(i.collection, []), o.get(i.collection).push(i);
|
|
@@ -2773,15 +2786,15 @@ var q = class {
|
|
|
2773
2786
|
|
|
2774
2787
|
// src/db/collection-ref.ts
|
|
2775
2788
|
I();
|
|
2776
|
-
function
|
|
2789
|
+
function yt() {
|
|
2777
2790
|
return typeof indexedDB > "u" || typeof window > "u";
|
|
2778
2791
|
}
|
|
2779
|
-
var
|
|
2780
|
-
function
|
|
2781
|
-
if (!
|
|
2792
|
+
var we = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
2793
|
+
function gt(r) {
|
|
2794
|
+
if (!we.test(r))
|
|
2782
2795
|
throw new exports.NeetruDbError(
|
|
2783
2796
|
"db_invalid_query",
|
|
2784
|
-
`Nome de cole\xE7\xE3o inv\xE1lido: "${r}". Deve seguir o padr\xE3o ${
|
|
2797
|
+
`Nome de cole\xE7\xE3o inv\xE1lido: "${r}". Deve seguir o padr\xE3o ${we}.`
|
|
2785
2798
|
);
|
|
2786
2799
|
}
|
|
2787
2800
|
function L(r, e = "id") {
|
|
@@ -2791,7 +2804,7 @@ function L(r, e = "id") {
|
|
|
2791
2804
|
`${e} \xE9 obrigat\xF3rio e deve ser uma string n\xE3o-vazia.`
|
|
2792
2805
|
);
|
|
2793
2806
|
}
|
|
2794
|
-
function
|
|
2807
|
+
function bt(r) {
|
|
2795
2808
|
let e = {};
|
|
2796
2809
|
if (r?.where && (e.where = r.where.map((t) => ({
|
|
2797
2810
|
field: t.field,
|
|
@@ -2808,7 +2821,7 @@ function yt(r) {
|
|
|
2808
2821
|
}
|
|
2809
2822
|
return e;
|
|
2810
2823
|
}
|
|
2811
|
-
function
|
|
2824
|
+
function vt(r, e) {
|
|
2812
2825
|
if (r.length < e) return null;
|
|
2813
2826
|
let t = r[r.length - 1];
|
|
2814
2827
|
return t ? btoa(JSON.stringify({ type: "startAfter", docId: t.id })) : null;
|
|
@@ -2855,7 +2868,7 @@ var oe = class {
|
|
|
2855
2868
|
}
|
|
2856
2869
|
/** Constrói um DbListResult para a coleção com query opcional. */
|
|
2857
2870
|
async _buildListResult(e) {
|
|
2858
|
-
let t =
|
|
2871
|
+
let t = bt(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 = vt(o.docs, n), l = await this._store.getMeta(re), d = Array.isArray(l) && l.includes(this._collection), u = !s || a.status === "offline" || d, p = i || a.lastSyncedAt === null || u;
|
|
2859
2872
|
return {
|
|
2860
2873
|
docs: o.docs.map((h) => ({ id: h.id, data: h.data })),
|
|
2861
2874
|
nextCursor: c,
|
|
@@ -3198,7 +3211,7 @@ var oe = class {
|
|
|
3198
3211
|
this._store = e.store, this._queue = e.queue, this._bus = e.bus, this._engine = e.engine, this._connectivity = e.connectivity;
|
|
3199
3212
|
}
|
|
3200
3213
|
collection(e) {
|
|
3201
|
-
return
|
|
3214
|
+
return gt(e), new oe(
|
|
3202
3215
|
e,
|
|
3203
3216
|
this._store,
|
|
3204
3217
|
this._queue,
|
|
@@ -3227,8 +3240,8 @@ var oe = class {
|
|
|
3227
3240
|
return this._engine.onError(e);
|
|
3228
3241
|
}
|
|
3229
3242
|
};
|
|
3230
|
-
async function
|
|
3231
|
-
let e =
|
|
3243
|
+
async function Se(r) {
|
|
3244
|
+
let e = yt() ? new Q() : new j(r.dbName);
|
|
3232
3245
|
await e.open();
|
|
3233
3246
|
let t = new z(e), n = new H(), o = new G(), i = new X({
|
|
3234
3247
|
// Se startOnline=false, injeta um navigator falso
|
|
@@ -3263,9 +3276,9 @@ async function we(r) {
|
|
|
3263
3276
|
}
|
|
3264
3277
|
|
|
3265
3278
|
// src/db/realtime/realtime-client.ts
|
|
3266
|
-
var
|
|
3267
|
-
function
|
|
3268
|
-
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++
|
|
3279
|
+
var wt = 0;
|
|
3280
|
+
function Te() {
|
|
3281
|
+
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++wt}-${Math.random().toString(36).slice(2)}`;
|
|
3269
3282
|
}
|
|
3270
3283
|
var F = class {
|
|
3271
3284
|
// ── configuração ──────────────────────────────────────────────────────────
|
|
@@ -3305,7 +3318,7 @@ var F = class {
|
|
|
3305
3318
|
_pendingFrames = [];
|
|
3306
3319
|
// ── construtor ────────────────────────────────────────────────────────────
|
|
3307
3320
|
constructor(e) {
|
|
3308
|
-
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ??
|
|
3321
|
+
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ?? St, 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();
|
|
3309
3322
|
}
|
|
3310
3323
|
// ── API pública ───────────────────────────────────────────────────────────
|
|
3311
3324
|
/**
|
|
@@ -3319,8 +3332,8 @@ var F = class {
|
|
|
3319
3332
|
*/
|
|
3320
3333
|
subscribe(e, t, n) {
|
|
3321
3334
|
if (this._closed)
|
|
3322
|
-
return
|
|
3323
|
-
let o =
|
|
3335
|
+
return Te();
|
|
3336
|
+
let o = Te();
|
|
3324
3337
|
this._subscriptions.set(o, {
|
|
3325
3338
|
subscriptionId: o,
|
|
3326
3339
|
collection: e,
|
|
@@ -3584,7 +3597,7 @@ var F = class {
|
|
|
3584
3597
|
_detachHandlers(e) {
|
|
3585
3598
|
e.onopen = null, e.onmessage = null, e.onclose = null, e.onerror = null;
|
|
3586
3599
|
}
|
|
3587
|
-
},
|
|
3600
|
+
}, St = (r) => {
|
|
3588
3601
|
if (typeof WebSocket > "u")
|
|
3589
3602
|
throw new Error(
|
|
3590
3603
|
"[NeetruRealtimeClient] WebSocket n\xE3o dispon\xEDvel neste ambiente. Injete uma implementa\xE7\xE3o via `webSocketFactory` nas op\xE7\xF5es."
|
|
@@ -3594,11 +3607,11 @@ var F = class {
|
|
|
3594
3607
|
|
|
3595
3608
|
// src/db/client-db.ts
|
|
3596
3609
|
I();
|
|
3597
|
-
var
|
|
3598
|
-
function
|
|
3599
|
-
return e._transport ? e._transport : r === "firestore" && e.firestoreTransport ? e.firestoreTransport : r === "nosql-vm" && e.realtimeGatewayUrl ?
|
|
3610
|
+
var Ht = (r) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}`, Y = (r, e) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}/${encodeURIComponent(e)}`, Je = 200;
|
|
3611
|
+
function Gt(r, e, t) {
|
|
3612
|
+
return e._transport ? e._transport : r === "firestore" && e.firestoreTransport ? e.firestoreTransport : r === "nosql-vm" && e.realtimeGatewayUrl ? Xt(e.realtimeGatewayUrl, t, e) : Ye(t);
|
|
3600
3613
|
}
|
|
3601
|
-
function
|
|
3614
|
+
function Ye(r) {
|
|
3602
3615
|
return {
|
|
3603
3616
|
async pushMutations(e) {
|
|
3604
3617
|
if (!r)
|
|
@@ -3676,7 +3689,7 @@ function Je(r) {
|
|
|
3676
3689
|
try {
|
|
3677
3690
|
l = await t(r, {
|
|
3678
3691
|
method: "GET",
|
|
3679
|
-
path:
|
|
3692
|
+
path: Ht(c),
|
|
3680
3693
|
requireAuth: !0,
|
|
3681
3694
|
retries: 2,
|
|
3682
3695
|
headers: o,
|
|
@@ -3684,7 +3697,7 @@ function Je(r) {
|
|
|
3684
3697
|
// TRUNCADAS — reportadas em `truncatedCollections` p/ o SyncEngine
|
|
3685
3698
|
// (a) NÃO rodar deleção-por-ausência e (b) sinalizar
|
|
3686
3699
|
// `DbListResult.truncated`. Paginação por cursor é tarefa Core (gated).
|
|
3687
|
-
query: { limit:
|
|
3700
|
+
query: { limit: Je }
|
|
3688
3701
|
});
|
|
3689
3702
|
} catch (p) {
|
|
3690
3703
|
let h = p instanceof Error ? p.message : String(p);
|
|
@@ -3694,7 +3707,7 @@ function Je(r) {
|
|
|
3694
3707
|
);
|
|
3695
3708
|
}
|
|
3696
3709
|
let d = l, u = Array.isArray(d?.items) ? d.items : [];
|
|
3697
|
-
u.length >=
|
|
3710
|
+
u.length >= Je && a.push(c);
|
|
3698
3711
|
for (let p of u) {
|
|
3699
3712
|
if (!p || typeof p != "object") continue;
|
|
3700
3713
|
let h = p, _ = typeof h.id == "string" ? h.id : null;
|
|
@@ -3723,10 +3736,10 @@ function Je(r) {
|
|
|
3723
3736
|
}
|
|
3724
3737
|
};
|
|
3725
3738
|
}
|
|
3726
|
-
function
|
|
3727
|
-
let n =
|
|
3739
|
+
function Xt(r, e, t) {
|
|
3740
|
+
let n = Ye(e), o = new F({
|
|
3728
3741
|
gatewayUrl: r,
|
|
3729
|
-
ticketProvider:
|
|
3742
|
+
ticketProvider: Jt(e, t),
|
|
3730
3743
|
dbId: t.dbId,
|
|
3731
3744
|
webSocketFactory: t._wsFactory
|
|
3732
3745
|
});
|
|
@@ -3762,7 +3775,7 @@ function Ht(r, e, t) {
|
|
|
3762
3775
|
}
|
|
3763
3776
|
};
|
|
3764
3777
|
}
|
|
3765
|
-
function
|
|
3778
|
+
function Jt(r, e) {
|
|
3766
3779
|
return async () => {
|
|
3767
3780
|
let { httpRequest: t } = await Promise.resolve().then(() => (W(), U));
|
|
3768
3781
|
return await t(r, {
|
|
@@ -3777,27 +3790,27 @@ function Gt(r, e) {
|
|
|
3777
3790
|
});
|
|
3778
3791
|
};
|
|
3779
3792
|
}
|
|
3780
|
-
function
|
|
3793
|
+
function Zn(r, e, t, n) {
|
|
3781
3794
|
return new F({ gatewayUrl: r, ticketProvider: e, dbId: t, webSocketFactory: n });
|
|
3782
3795
|
}
|
|
3783
3796
|
var pe = false;
|
|
3784
|
-
function
|
|
3797
|
+
function er() {
|
|
3785
3798
|
pe = false;
|
|
3786
3799
|
}
|
|
3787
|
-
function
|
|
3800
|
+
function Yt(r, e) {
|
|
3788
3801
|
pe || e.dbId && r.env !== "prod" && (typeof window > "u" || typeof console > "u" || typeof console.warn != "function" || (pe = true, console.warn(
|
|
3789
3802
|
'[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.'
|
|
3790
3803
|
)));
|
|
3791
3804
|
}
|
|
3792
|
-
function
|
|
3793
|
-
|
|
3805
|
+
function tr(r, e = {}) {
|
|
3806
|
+
Yt(r, e);
|
|
3794
3807
|
let t;
|
|
3795
3808
|
e.transport !== void 0 ? t = e.transport : e.engine !== void 0 ? (console.warn(
|
|
3796
3809
|
'[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).'
|
|
3797
3810
|
), t = e.engine) : t = "rest";
|
|
3798
|
-
let n =
|
|
3811
|
+
let n = Gt(t, e, r), o = e.dbId ?? "default", i = e.dbName ?? `neetru-db__${r.productId ?? "sdk"}__${o}__${r.env}`, s = null, a = null;
|
|
3799
3812
|
function c() {
|
|
3800
|
-
return s || (s =
|
|
3813
|
+
return s || (s = Se({
|
|
3801
3814
|
dbName: i,
|
|
3802
3815
|
transport: n,
|
|
3803
3816
|
singleTab: e.singleTab ?? r.env !== "prod"
|
|
@@ -3805,15 +3818,15 @@ function Jn(r, e = {}) {
|
|
|
3805
3818
|
}
|
|
3806
3819
|
return {
|
|
3807
3820
|
collection(l) {
|
|
3808
|
-
return a ? a.collection(l) :
|
|
3821
|
+
return a ? a.collection(l) : Zt(l, c);
|
|
3809
3822
|
},
|
|
3810
3823
|
async sql(l, d) {
|
|
3811
|
-
if (r.env
|
|
3824
|
+
if (_e(r.env))
|
|
3812
3825
|
throw new exports.NeetruDbError(
|
|
3813
3826
|
"db_unavailable",
|
|
3814
3827
|
"[SDK] db.sql() n\xE3o dispon\xEDvel em NEETRU_ENV=dev. Use `neetru dev` para subir o container Postgres local."
|
|
3815
3828
|
);
|
|
3816
|
-
return (await Promise.resolve().then(() => (
|
|
3829
|
+
return (await Promise.resolve().then(() => (Xe(), Ge))).createSqlClientFromConfig(r, l, d);
|
|
3817
3830
|
},
|
|
3818
3831
|
get syncState() {
|
|
3819
3832
|
return a?.syncState ?? {
|
|
@@ -3852,7 +3865,7 @@ function Jn(r, e = {}) {
|
|
|
3852
3865
|
}
|
|
3853
3866
|
};
|
|
3854
3867
|
}
|
|
3855
|
-
function
|
|
3868
|
+
function Zt(r, e) {
|
|
3856
3869
|
async function t() {
|
|
3857
3870
|
return (await e()).collection(r);
|
|
3858
3871
|
}
|
|
@@ -3931,12 +3944,12 @@ function Jt(r, e) {
|
|
|
3931
3944
|
}
|
|
3932
3945
|
|
|
3933
3946
|
exports.NEETRU_SENTINEL_KEY = te;
|
|
3934
|
-
exports.__resetDbIdWarningForTests =
|
|
3935
|
-
exports.createNeetruDb =
|
|
3936
|
-
exports.createRestSyncTransport =
|
|
3937
|
-
exports.getWebSocketRealtimeClient =
|
|
3938
|
-
exports.increment =
|
|
3947
|
+
exports.__resetDbIdWarningForTests = er;
|
|
3948
|
+
exports.createNeetruDb = tr;
|
|
3949
|
+
exports.createRestSyncTransport = Ye;
|
|
3950
|
+
exports.getWebSocketRealtimeClient = Zn;
|
|
3951
|
+
exports.increment = lt;
|
|
3939
3952
|
exports.isFieldSentinel = D;
|
|
3940
|
-
exports.isIncrementSentinel =
|
|
3941
|
-
exports.isServerTimestampSentinel =
|
|
3942
|
-
exports.serverTimestamp =
|
|
3953
|
+
exports.isIncrementSentinel = be;
|
|
3954
|
+
exports.isServerTimestampSentinel = ge;
|
|
3955
|
+
exports.serverTimestamp = ct;
|