@neetru/sdk 3.8.0 → 3.8.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 +20 -0
- 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 +708 -688
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +705 -685
- 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 +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +1 -1
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +242 -222
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +263 -243
- 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 +730 -710
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +874 -854
- package/dist/mobile.d.cts +1 -1
- package/dist/mobile.d.ts +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- 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.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- 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 +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +1 -1
- package/dist/{types-bVztFQTI.d.ts → types-BYPk_3HR.d.ts} +56 -16
- package/dist/{types-D-9bjlM0.d.cts → types-yv3EDKg2.d.cts} +56 -16
- 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 +1 -1
package/dist/auth.cjs
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
var jose = require('jose');
|
|
4
4
|
var idb = require('idb');
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var Qn = Object.defineProperty;
|
|
7
7
|
var $ = (n, e) => () => (n && (e = n(n = 0)), e);
|
|
8
8
|
var ot = (n, e) => {
|
|
9
9
|
for (var t in e)
|
|
10
|
-
|
|
10
|
+
Qn(n, t, { get: e[t], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// src/errors.ts
|
|
14
|
-
var
|
|
15
|
-
|
|
14
|
+
var c, V, I = $(() => {
|
|
15
|
+
c = class n extends Error {
|
|
16
16
|
code;
|
|
17
17
|
status;
|
|
18
18
|
requestId;
|
|
@@ -35,7 +35,7 @@ var l, V, I = $(() => {
|
|
|
35
35
|
constructor(e, t, r, o, i, s) {
|
|
36
36
|
super(t), this.name = "NeetruError", this.code = e, this.status = r, this.requestId = o, this.reason = i, this.correlationId = s, Object.setPrototypeOf(this, n.prototype);
|
|
37
37
|
}
|
|
38
|
-
}, V = class n extends
|
|
38
|
+
}, V = class n extends c {
|
|
39
39
|
constructor(e, t, r, o, i) {
|
|
40
40
|
super("auth_required", e, r, o, t, i), this.name = "NeetruAuthRequiredError", Object.setPrototypeOf(this, n.prototype);
|
|
41
41
|
}
|
|
@@ -47,7 +47,7 @@ function ht() {
|
|
|
47
47
|
let n = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
48
48
|
if (n && typeof n.randomUUID == "function")
|
|
49
49
|
return n.randomUUID();
|
|
50
|
-
throw new
|
|
50
|
+
throw new c(
|
|
51
51
|
"runtime_unsupported",
|
|
52
52
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
53
53
|
);
|
|
@@ -58,9 +58,9 @@ var gt = $(() => {
|
|
|
58
58
|
|
|
59
59
|
// src/correlation.ts
|
|
60
60
|
function _t(n) {
|
|
61
|
-
return typeof n == "string" && n.length > 0 && n.length <= 128 &&
|
|
61
|
+
return typeof n == "string" && n.length > 0 && n.length <= 128 && tr.test(n);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function nr() {
|
|
64
64
|
let n = globalThis.crypto;
|
|
65
65
|
try {
|
|
66
66
|
if (n && typeof n.randomUUID == "function") return n.randomUUID();
|
|
@@ -87,11 +87,11 @@ function ae(n, e) {
|
|
|
87
87
|
}
|
|
88
88
|
r[i] = s;
|
|
89
89
|
}
|
|
90
|
-
let o = t ?? (_t(e) ? e : void 0) ??
|
|
90
|
+
let o = t ?? (_t(e) ? e : void 0) ?? nr();
|
|
91
91
|
return r[yt] = o, { headers: r, correlationId: o };
|
|
92
92
|
}
|
|
93
|
-
var yt,
|
|
94
|
-
yt = "x-correlation-id",
|
|
93
|
+
var yt, tr, Me = $(() => {
|
|
94
|
+
yt = "x-correlation-id", tr = /^[A-Za-z0-9._:\-]+$/;
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
// src/server-only-key.ts
|
|
@@ -109,7 +109,7 @@ function X() {
|
|
|
109
109
|
return null;
|
|
110
110
|
}
|
|
111
111
|
function bt(n, e) {
|
|
112
|
-
let t =
|
|
112
|
+
let t = rr[n];
|
|
113
113
|
return (`${e ? `[Neetru SDK] Recusado: a credencial nrt_ do produto foi passada ao SDK rodando ${t}.` : `[Neetru SDK] ATEN\xC7\xC3O: a credencial nrt_ do produto est\xE1 sendo usada ${t}.`} Essa chave \xE9 S\xD3 DE SERVIDOR \u2014 quem abrir o DevTools (ou descompactar o app) copia a chave e fala com o Core como se fosse o seu produto. Como corrigir: o site/app chama a API do SEU produto (ex.: https://<produto>.neetru.com/api/v1) com o token do usu\xE1rio (Authorization: Bearer <access_token>); o backend do produto valida com verifyAccessToken() e usa o SDK com a chave (NEETRU_API_KEY, sem prefixo NEXT_PUBLIC_/EXPO_PUBLIC_). ` + (e ? "" : "Nesta vers\xE3o \xE9 s\xF3 um aviso; use strictServerOnlyKey: true para bloquear j\xE1. Na pr\xF3xima vers\xE3o MAJOR do SDK isso passa a falhar sempre.")).trim();
|
|
114
114
|
}
|
|
115
115
|
function wt(n) {
|
|
@@ -117,7 +117,7 @@ function wt(n) {
|
|
|
117
117
|
let e = n.runtime === void 0 ? X() : n.runtime;
|
|
118
118
|
if (e) {
|
|
119
119
|
if (n.strict)
|
|
120
|
-
throw new
|
|
120
|
+
throw new c("server_only_key", bt(e, true), void 0, void 0, e);
|
|
121
121
|
if (!vt) {
|
|
122
122
|
vt = true;
|
|
123
123
|
try {
|
|
@@ -127,9 +127,9 @@ function wt(n) {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
var
|
|
130
|
+
var rr, vt, qe = $(() => {
|
|
131
131
|
I();
|
|
132
|
-
|
|
132
|
+
rr = {
|
|
133
133
|
browser: "no navegador",
|
|
134
134
|
"react-native": "num app React Native"
|
|
135
135
|
};
|
|
@@ -146,7 +146,7 @@ ot(Y, {
|
|
|
146
146
|
function Fe(n) {
|
|
147
147
|
return n.split("+")[0] ?? n;
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function ir(n, e) {
|
|
150
150
|
let t = Fe(n).split(".").map(Number), r = Fe(e).split(".").map(Number), o = Math.max(t.length, r.length);
|
|
151
151
|
for (let i = 0; i < o; i++) {
|
|
152
152
|
let s = t[i] ?? 0, a = r[i] ?? 0;
|
|
@@ -156,28 +156,28 @@ function or(n, e) {
|
|
|
156
156
|
}
|
|
157
157
|
function Ct() {
|
|
158
158
|
try {
|
|
159
|
-
return "3.8.
|
|
159
|
+
return "3.8.1";
|
|
160
160
|
} catch {
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function sr() {
|
|
165
165
|
let n = Ct();
|
|
166
166
|
return n ? parseInt(n.split(".")[0] ?? "3", 10) : 3;
|
|
167
167
|
}
|
|
168
168
|
function ce(n) {
|
|
169
169
|
if (!n) return;
|
|
170
|
-
let e =
|
|
170
|
+
let e = sr(), t = or[e];
|
|
171
171
|
if (!t) return;
|
|
172
172
|
let r = Fe(n);
|
|
173
|
-
if (
|
|
173
|
+
if (ir(r, t) < 0) {
|
|
174
174
|
let o = `${e}:${r}`;
|
|
175
175
|
kt.has(o) || (kt.add(o), console.warn(
|
|
176
176
|
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${n}" \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.`
|
|
177
177
|
));
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function ar() {
|
|
181
181
|
let n = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
182
182
|
return X() ? "Esta opera\xE7\xE3o exige a credencial nrt_ do produto, que \xE9 S\xD3 DE SERVIDOR. No navegador/app, chame a API do seu produto (ex.: https://<produto>.neetru.com/api/v1) com o token do usu\xE1rio \u2014 o backend do produto faz esta chamada com o SDK e a chave. (" + n + ")" : n;
|
|
183
183
|
}
|
|
@@ -185,7 +185,7 @@ function St(n) {
|
|
|
185
185
|
let e = 200 * Math.pow(4, n), t = e * 0.2 * (Math.random() * 2 - 1);
|
|
186
186
|
return Math.max(50, Math.round(e + t));
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function pr(n) {
|
|
189
189
|
if (!n) return null;
|
|
190
190
|
let e = Number(n);
|
|
191
191
|
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), Tt);
|
|
@@ -202,7 +202,7 @@ function Rt(n) {
|
|
|
202
202
|
function le(n) {
|
|
203
203
|
return n === 401 ? "unauthorized" : n === 403 ? "forbidden" : n === 404 ? "not_found" : n === 409 ? "conflict" : n === 410 ? "gone" : n === 422 || n === 400 ? "validation_failed" : n === 429 ? "rate_limited" : n >= 500 ? "server_error" : "unknown";
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function fr(n, e, t) {
|
|
206
206
|
let r = n.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, i = new URL(`${r}${o}`);
|
|
207
207
|
if (t)
|
|
208
208
|
for (let [s, a] of Object.entries(t))
|
|
@@ -219,13 +219,13 @@ async function It(n) {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
async function v(n, e) {
|
|
222
|
-
let t = e.method ?? "GET", r =
|
|
222
|
+
let t = e.method ?? "GET", r = fr(n.baseUrl, e.path, e.query), o = dr.has(t) ? cr : lr, i = e.retries ?? o, { headers: s, correlationId: a } = ae(
|
|
223
223
|
{ accept: "application/json", ...e.headers },
|
|
224
224
|
e.correlationId
|
|
225
|
-
),
|
|
226
|
-
if (
|
|
225
|
+
), l = Ct();
|
|
226
|
+
if (l && (s["x-neetru-sdk-version"] = l), e.requireAuth) {
|
|
227
227
|
if (!n.apiKey)
|
|
228
|
-
throw new
|
|
228
|
+
throw new c("missing_api_key", ar());
|
|
229
229
|
s.authorization = `Bearer ${n.apiKey}`;
|
|
230
230
|
}
|
|
231
231
|
if (e.idempotencyKey) {
|
|
@@ -237,7 +237,7 @@ async function v(n, e) {
|
|
|
237
237
|
let u = null, p = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
|
|
238
238
|
for (let f = 0; f <= i; f++) {
|
|
239
239
|
if (p != null && Date.now() >= p)
|
|
240
|
-
throw u ?? new
|
|
240
|
+
throw u ?? new c(
|
|
241
241
|
"network_error",
|
|
242
242
|
"Deadline excedido antes de completar a request",
|
|
243
243
|
void 0,
|
|
@@ -245,16 +245,16 @@ async function v(n, e) {
|
|
|
245
245
|
void 0,
|
|
246
246
|
a
|
|
247
247
|
);
|
|
248
|
-
let
|
|
249
|
-
d !== void 0 && (
|
|
250
|
-
let
|
|
251
|
-
|
|
248
|
+
let h = { method: t, headers: s };
|
|
249
|
+
d !== void 0 && (h.body = d);
|
|
250
|
+
let y = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
|
|
251
|
+
h.signal = AbortSignal.timeout(y);
|
|
252
252
|
let S;
|
|
253
253
|
try {
|
|
254
|
-
S = await n.fetch(r,
|
|
255
|
-
} catch (
|
|
256
|
-
let C =
|
|
257
|
-
if (u = new
|
|
254
|
+
S = await n.fetch(r, h);
|
|
255
|
+
} catch (g) {
|
|
256
|
+
let C = g instanceof DOMException && g.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${g instanceof Error ? g.message : "fetch failed"}`;
|
|
257
|
+
if (u = new c("network_error", C, void 0, void 0, void 0, a), f < i) {
|
|
258
258
|
let D = St(f);
|
|
259
259
|
if (p == null || Date.now() + D < p) {
|
|
260
260
|
await Rt(D);
|
|
@@ -265,42 +265,42 @@ async function v(n, e) {
|
|
|
265
265
|
}
|
|
266
266
|
let x = S.headers.get("x-request-id") ?? S.headers.get("x-correlation-id") ?? void 0;
|
|
267
267
|
if (S.ok) {
|
|
268
|
-
let
|
|
269
|
-
return
|
|
268
|
+
let g = S.headers.get("x-neetru-version");
|
|
269
|
+
return g && ce(g), await It(S);
|
|
270
270
|
}
|
|
271
271
|
let T = await It(S), P = le(S.status), q = `HTTP ${S.status}`, m;
|
|
272
272
|
if (T && typeof T == "object") {
|
|
273
|
-
let
|
|
274
|
-
typeof
|
|
273
|
+
let g = T.error;
|
|
274
|
+
typeof g == "string" ? q = g : g && typeof g == "object" ? (typeof g.code == "string" && (P = g.code), typeof g.message == "string" && (q = g.message), typeof g.reason == "string" && (m = g.reason)) : (typeof T.code == "string" && (P = T.code), typeof T.message == "string" && (q = T.message)), typeof T.reason == "string" && (m = T.reason);
|
|
275
275
|
}
|
|
276
276
|
if (S.status === 410) {
|
|
277
|
-
let
|
|
278
|
-
q === `HTTP ${S.status}` && (q = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`),
|
|
277
|
+
let g = S.headers.get("x-neetru-replacement");
|
|
278
|
+
q === `HTTP ${S.status}` && (q = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), g && !q.includes(g) && (q += ` Substituto: ${g}.`);
|
|
279
279
|
}
|
|
280
|
-
let
|
|
281
|
-
if (u =
|
|
282
|
-
let C =
|
|
280
|
+
let _ = new c(P, q, S.status, x, m, a);
|
|
281
|
+
if (u = _, ur.has(P) && f < i) {
|
|
282
|
+
let C = pr(S.headers.get("retry-after")) ?? St(f);
|
|
283
283
|
if (p == null || Date.now() + C < p) {
|
|
284
284
|
await Rt(C);
|
|
285
285
|
continue;
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
throw
|
|
288
|
+
throw _;
|
|
289
289
|
}
|
|
290
|
-
throw u ?? new
|
|
290
|
+
throw u ?? new c("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
|
|
291
291
|
}
|
|
292
|
-
var
|
|
292
|
+
var or, kt, cr, lr, dr, ur, Tt, M = $(() => {
|
|
293
293
|
I();
|
|
294
294
|
gt();
|
|
295
295
|
Me();
|
|
296
296
|
qe();
|
|
297
|
-
|
|
297
|
+
or = {
|
|
298
298
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
299
299
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
300
300
|
3: "2026.05.1"
|
|
301
301
|
};
|
|
302
302
|
kt = /* @__PURE__ */ new Set();
|
|
303
|
-
|
|
303
|
+
cr = 2, lr = 0, dr = /* @__PURE__ */ new Set(["GET", "HEAD"]), ur = /* @__PURE__ */ new Set([
|
|
304
304
|
"rate_limited",
|
|
305
305
|
"server_error",
|
|
306
306
|
"network_error"
|
|
@@ -309,13 +309,13 @@ var rr, kt, ar, cr, lr, dr, Tt, M = $(() => {
|
|
|
309
309
|
});
|
|
310
310
|
|
|
311
311
|
// src/db-errors.ts
|
|
312
|
-
var
|
|
312
|
+
var Ir, b, Z = $(() => {
|
|
313
313
|
I();
|
|
314
|
-
|
|
314
|
+
Ir = /* @__PURE__ */ new Set([
|
|
315
315
|
"db_unavailable",
|
|
316
316
|
"db_conflict",
|
|
317
317
|
"db_timeout"
|
|
318
|
-
]),
|
|
318
|
+
]), b = class n extends c {
|
|
319
319
|
/** Código de erro fechado — específico de DB. */
|
|
320
320
|
code;
|
|
321
321
|
/**
|
|
@@ -329,7 +329,7 @@ var Rr, y, Z = $(() => {
|
|
|
329
329
|
*/
|
|
330
330
|
dbId;
|
|
331
331
|
constructor(e, t, r) {
|
|
332
|
-
super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable =
|
|
332
|
+
super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable = Ir.has(e), this.dbId = r, Object.setPrototypeOf(this, n.prototype);
|
|
333
333
|
}
|
|
334
334
|
};
|
|
335
335
|
});
|
|
@@ -338,7 +338,7 @@ var Rr, y, Z = $(() => {
|
|
|
338
338
|
function ve(n) {
|
|
339
339
|
return typeof n == "object" && n !== null && n[He] === true;
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function Qr(n) {
|
|
342
342
|
let e = n && typeof n == "object" && "code" in n ? n.code : void 0;
|
|
343
343
|
if (e === "ECONNREFUSED" || e === "ETIMEDOUT" || e === "ENOTFOUND" || e === "EHOSTUNREACH" || e === "EAI_AGAIN")
|
|
344
344
|
return true;
|
|
@@ -350,67 +350,84 @@ function Hr(n) {
|
|
|
350
350
|
let r = (n instanceof Error ? n.message : typeof n == "string" ? n : "").toLowerCase();
|
|
351
351
|
return r.length === 0 ? false : !!(r.includes("certificate expired") || r.includes("certificate has expired") || r.includes("cert_has_expired") || r.includes("alert certificate expired") || r.includes("err_ssl") || r.includes("sslv3 alert") || r.includes("tlsv1 alert") || r.includes("econnrefused") || r.includes("etimedout") || r.includes("enotfound") || r.includes("ehostunreach") || r.includes("getaddrinfo"));
|
|
352
352
|
}
|
|
353
|
+
function Gt(n) {
|
|
354
|
+
let e = n && typeof n == "object" && "code" in n ? n.code : void 0;
|
|
355
|
+
if (typeof e == "string" && Gr.has(e.toUpperCase()))
|
|
356
|
+
return true;
|
|
357
|
+
let r = (n instanceof Error ? n.message : typeof n == "string" ? n : "").toLowerCase();
|
|
358
|
+
return r.length === 0 ? false : r.includes("password authentication failed") || r.includes("sasl authentication failed");
|
|
359
|
+
}
|
|
360
|
+
function Jr(n) {
|
|
361
|
+
return Qr(n) || Gt(n);
|
|
362
|
+
}
|
|
353
363
|
function Qe(n) {
|
|
354
364
|
let e = { current: n }, t = null, r = {
|
|
355
|
-
__neetruSwapInner(
|
|
356
|
-
let
|
|
357
|
-
return e.current =
|
|
365
|
+
__neetruSwapInner(u) {
|
|
366
|
+
let p = e.current;
|
|
367
|
+
return e.current = u, p;
|
|
358
368
|
},
|
|
359
369
|
__neetruGetInner() {
|
|
360
370
|
return e.current;
|
|
361
371
|
},
|
|
362
|
-
__neetruSetReLease(
|
|
363
|
-
t =
|
|
372
|
+
__neetruSetReLease(u) {
|
|
373
|
+
t = u;
|
|
364
374
|
}
|
|
365
|
-
}, o = (
|
|
375
|
+
}, o = (u, p, f) => p[u](
|
|
376
|
+
...f
|
|
377
|
+
), i = (u, p) => (...f) => f.length > 0 && typeof f[f.length - 1] == "function" ? o(u, e.current, f) : (async () => {
|
|
366
378
|
try {
|
|
367
|
-
return await o(e.current,
|
|
368
|
-
} catch (
|
|
369
|
-
let
|
|
370
|
-
if (
|
|
371
|
-
throw
|
|
379
|
+
return await o(u, e.current, f);
|
|
380
|
+
} catch (h) {
|
|
381
|
+
let y = t;
|
|
382
|
+
if (y === null || !p(h))
|
|
383
|
+
throw h;
|
|
372
384
|
try {
|
|
373
|
-
await
|
|
385
|
+
await y();
|
|
374
386
|
} catch {
|
|
375
|
-
throw
|
|
387
|
+
throw h;
|
|
376
388
|
}
|
|
377
|
-
return await o(e.current,
|
|
389
|
+
return await o(u, e.current, f);
|
|
378
390
|
}
|
|
379
|
-
})(), s = Object.create(Object.getPrototypeOf(n));
|
|
380
|
-
return new Proxy(
|
|
381
|
-
get(
|
|
382
|
-
if (
|
|
383
|
-
if (
|
|
384
|
-
if (
|
|
385
|
-
if (
|
|
386
|
-
if (
|
|
387
|
-
if (
|
|
391
|
+
})(), s = i("query", Jr), a = i("connect", Gt), l = Object.create(Object.getPrototypeOf(n));
|
|
392
|
+
return new Proxy(l, {
|
|
393
|
+
get(u, p) {
|
|
394
|
+
if (p === He) return true;
|
|
395
|
+
if (p === "__neetruSwapInner") return r.__neetruSwapInner;
|
|
396
|
+
if (p === "__neetruGetInner") return r.__neetruGetInner;
|
|
397
|
+
if (p === "__neetruSetReLease") return r.__neetruSetReLease;
|
|
398
|
+
if (p === "query") return s;
|
|
399
|
+
if (p === "connect") {
|
|
400
|
+
let y = e.current;
|
|
401
|
+
return typeof y.connect == "function" ? a : y.connect;
|
|
402
|
+
}
|
|
403
|
+
if (p === "constructor")
|
|
388
404
|
return e.current.constructor;
|
|
389
|
-
let
|
|
390
|
-
return typeof
|
|
405
|
+
let f = e.current, h = Reflect.get(f, p, f);
|
|
406
|
+
return typeof h == "function" ? h.bind(f) : h;
|
|
391
407
|
}
|
|
392
408
|
});
|
|
393
409
|
}
|
|
394
|
-
var He, Ge = $(() => {
|
|
410
|
+
var He, Gr, Ge = $(() => {
|
|
395
411
|
He = /* @__PURE__ */ Symbol.for("neetru.sdk.resilientPool");
|
|
412
|
+
Gr = /* @__PURE__ */ new Set(["28P01", "28000"]);
|
|
396
413
|
});
|
|
397
414
|
|
|
398
415
|
// src/db/sql/lease.ts
|
|
399
|
-
function
|
|
416
|
+
function Yr(n, e) {
|
|
400
417
|
return n ? n.leaseId !== e.leaseId || n.credentialVersion !== e.credentialVersion || n.host !== e.host || n.port !== e.port || n.dbName !== e.dbName || n.user !== e.user || n.password !== e.password || n.sslca !== e.sslca || n.clientCert !== e.clientCert || n.clientKey !== e.clientKey : true;
|
|
401
418
|
}
|
|
402
|
-
function
|
|
403
|
-
if (n instanceof
|
|
419
|
+
function Zr(n) {
|
|
420
|
+
if (n instanceof b) return n;
|
|
404
421
|
let e = n instanceof Error ? n.message : String(n), t = n instanceof Error ? n.code : void 0;
|
|
405
|
-
return typeof t == "string" && (t === "ECONNREFUSED" || t === "ENOTFOUND" || t === "ETIMEDOUT") ? new
|
|
422
|
+
return typeof t == "string" && (t === "ECONNREFUSED" || t === "ENOTFOUND" || t === "ETIMEDOUT") ? new b(
|
|
406
423
|
"db_unavailable",
|
|
407
424
|
`Pool connection failed (${t}): ${e}`
|
|
408
|
-
) : e.includes("statement timeout") || e.includes("lock timeout") ? new
|
|
425
|
+
) : e.includes("statement timeout") || e.includes("lock timeout") ? new b("db_timeout", `Query timeout: ${e}`) : e.includes("40001") || e.includes("40P01") || e.includes("deadlock") ? new b("db_conflict", `Transaction conflict: ${e}`) : e.includes("42501") || e.toLowerCase().includes("permission denied") ? new b("db_permission_denied", `Permission denied: ${e}`) : new b("db_unavailable", `Database error: ${e}`);
|
|
409
426
|
}
|
|
410
|
-
var
|
|
427
|
+
var Xr, J, re, Jt = $(() => {
|
|
411
428
|
Z();
|
|
412
429
|
Ge();
|
|
413
|
-
|
|
430
|
+
Xr = 0.8, J = 3e4, re = class {
|
|
414
431
|
/**
|
|
415
432
|
* Lease atual. `null` no modo LAZY antes da 1ª query (o 1º lease é adiado —
|
|
416
433
|
* ver `_ensureInitialLease`). Após a 1ª aquisição, sempre não-nulo.
|
|
@@ -450,7 +467,7 @@ var Qr, J, re, Gt = $(() => {
|
|
|
450
467
|
isolationLevel: t.isolationLevel
|
|
451
468
|
}) : await this._orm.transaction(e);
|
|
452
469
|
} catch (r) {
|
|
453
|
-
throw
|
|
470
|
+
throw Zr(r);
|
|
454
471
|
}
|
|
455
472
|
}
|
|
456
473
|
async close() {
|
|
@@ -473,7 +490,7 @@ var Qr, J, re, Gt = $(() => {
|
|
|
473
490
|
if (!Number.isFinite(e)) return J;
|
|
474
491
|
let t = this._deps.now(), r = e - t;
|
|
475
492
|
if (r <= 0) return J;
|
|
476
|
-
let o = r * (1 -
|
|
493
|
+
let o = r * (1 - Xr);
|
|
477
494
|
return Math.max(J, Math.round(o));
|
|
478
495
|
}
|
|
479
496
|
_scheduleRenewal() {
|
|
@@ -502,7 +519,7 @@ var Qr, J, re, Gt = $(() => {
|
|
|
502
519
|
this._renewalTimer = setTimeout(() => {
|
|
503
520
|
this._doRenew();
|
|
504
521
|
}, J), console.warn(
|
|
505
|
-
`[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${J}ms (cert
|
|
522
|
+
`[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${J}ms (o cert de cliente mTLS do lease expira ~15min ap\xF3s o \xFAltimo swap):`,
|
|
506
523
|
t instanceof Error ? t.message : t
|
|
507
524
|
);
|
|
508
525
|
return;
|
|
@@ -514,10 +531,13 @@ var Qr, J, re, Gt = $(() => {
|
|
|
514
531
|
/**
|
|
515
532
|
* Recuperação REATIVA: chamado pelo wrapper resiliente (`resilient-pool.ts`)
|
|
516
533
|
* quando uma query plana falha num erro de ESTABELECIMENTO de conexão (cert
|
|
517
|
-
* TLS
|
|
518
|
-
* renovação que não disparou)
|
|
519
|
-
* do
|
|
520
|
-
*
|
|
534
|
+
* TLS de cliente mTLS do lease expirado no meio de uma request, ou timer de
|
|
535
|
+
* renovação que não disparou) ou de AUTENTICAÇÃO (senha rotacionada por
|
|
536
|
+
* `rotate-credentials` antes do próximo renew — SQLSTATE 28P01/28000, ou o
|
|
537
|
+
* 08P01+SASL do PgBouncer; também no `connect()` de uma transação). Emite um
|
|
538
|
+
* lease NOVO e faz o swap do pool interno do wrapper com a credencial e o
|
|
539
|
+
* certificado frescos (o pool velho é drenado com `end()`); o wrapper então
|
|
540
|
+
* re-tenta a operação 1x no pool novo.
|
|
521
541
|
*
|
|
522
542
|
* Vai DIRETO ao lease novo (sem `leaseId`) — a conexão falhou porque o
|
|
523
543
|
* certificado do lease atual está ruim, então `renew` (que depende do lease
|
|
@@ -533,7 +553,7 @@ var Qr, J, re, Gt = $(() => {
|
|
|
533
553
|
*/
|
|
534
554
|
async _reactiveReLease() {
|
|
535
555
|
if (this._closed)
|
|
536
|
-
throw new
|
|
556
|
+
throw new b(
|
|
537
557
|
"db_unavailable",
|
|
538
558
|
"SqlLeaseManager foi fechado \u2014 re-lease reativo abortado."
|
|
539
559
|
);
|
|
@@ -570,7 +590,7 @@ var Qr, J, re, Gt = $(() => {
|
|
|
570
590
|
*/
|
|
571
591
|
async _ensureInitialLease() {
|
|
572
592
|
if (this._closed)
|
|
573
|
-
throw new
|
|
593
|
+
throw new b(
|
|
574
594
|
"db_unavailable",
|
|
575
595
|
"SqlLeaseManager foi fechado \u2014 aquisi\xE7\xE3o de lease inicial abortada."
|
|
576
596
|
);
|
|
@@ -582,16 +602,16 @@ var Qr, J, re, Gt = $(() => {
|
|
|
582
602
|
try {
|
|
583
603
|
t = this._deps.database !== void 0 ? await this._deps.fetchLease({ database: this._deps.database }) : await this._deps.fetchLease();
|
|
584
604
|
} catch (o) {
|
|
585
|
-
if (o instanceof
|
|
605
|
+
if (o instanceof b) throw o;
|
|
586
606
|
let i = o instanceof Error ? o.message : String(o);
|
|
587
|
-
throw new
|
|
607
|
+
throw new b("db_unavailable", `Falha ao obter lease inicial: ${i}`);
|
|
588
608
|
}
|
|
589
609
|
let r;
|
|
590
610
|
try {
|
|
591
611
|
r = this._deps.createPool(t);
|
|
592
612
|
} catch (o) {
|
|
593
613
|
let i = o instanceof Error ? o.message : String(o);
|
|
594
|
-
throw new
|
|
614
|
+
throw new b("db_unavailable", `Falha ao abrir pool: ${i}`);
|
|
595
615
|
}
|
|
596
616
|
return ve(this._pool) ? this._pool.__neetruSwapInner(r).end().catch(() => {
|
|
597
617
|
}) : this._pool = r, this._lease = t, this._scheduleRenewal(), r;
|
|
@@ -609,7 +629,7 @@ var Qr, J, re, Gt = $(() => {
|
|
|
609
629
|
* Exposto como método protegido para testes.
|
|
610
630
|
*/
|
|
611
631
|
async _swapPool(e) {
|
|
612
|
-
if (!
|
|
632
|
+
if (!Yr(this._lease, e)) {
|
|
613
633
|
this._lease = e;
|
|
614
634
|
return;
|
|
615
635
|
}
|
|
@@ -627,7 +647,7 @@ var Qr, J, re, Gt = $(() => {
|
|
|
627
647
|
// ─── Helpers ───────────────────────────────────────────────────────────────
|
|
628
648
|
_assertOpen() {
|
|
629
649
|
if (this._closed)
|
|
630
|
-
throw new
|
|
650
|
+
throw new b(
|
|
631
651
|
"db_unavailable",
|
|
632
652
|
"SqlLeaseManager foi fechado \u2014 chame close() apenas no shutdown."
|
|
633
653
|
);
|
|
@@ -636,29 +656,29 @@ var Qr, J, re, Gt = $(() => {
|
|
|
636
656
|
});
|
|
637
657
|
|
|
638
658
|
// src/db/sql/sql-client.ts
|
|
639
|
-
var
|
|
640
|
-
ot(
|
|
641
|
-
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () =>
|
|
642
|
-
DEFAULT_POOL_IDLE_MS: () =>
|
|
643
|
-
DEFAULT_POOL_MAX: () =>
|
|
644
|
-
LEASE_ENDPOINT: () =>
|
|
645
|
-
LEASE_RENEW_ENDPOINT: () =>
|
|
646
|
-
createDrizzleHandle: () =>
|
|
647
|
-
createHttpLeaseFetcher: () =>
|
|
648
|
-
createPgPool: () =>
|
|
649
|
-
createSqlClientFromConfig: () =>
|
|
650
|
-
createSqlClientWithDeps: () =>
|
|
659
|
+
var on = {};
|
|
660
|
+
ot(on, {
|
|
661
|
+
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () => nn,
|
|
662
|
+
DEFAULT_POOL_IDLE_MS: () => tn,
|
|
663
|
+
DEFAULT_POOL_MAX: () => en,
|
|
664
|
+
LEASE_ENDPOINT: () => Xt,
|
|
665
|
+
LEASE_RENEW_ENDPOINT: () => Yt,
|
|
666
|
+
createDrizzleHandle: () => ro,
|
|
667
|
+
createHttpLeaseFetcher: () => Zt,
|
|
668
|
+
createPgPool: () => no,
|
|
669
|
+
createSqlClientFromConfig: () => io,
|
|
670
|
+
createSqlClientWithDeps: () => rn,
|
|
651
671
|
resolvePoolTuning: () => Xe
|
|
652
672
|
});
|
|
653
|
-
function
|
|
673
|
+
function eo(n) {
|
|
654
674
|
return n === "workspace" ? "staging" : n === "prod" ? "production" : "dev-local";
|
|
655
675
|
}
|
|
656
|
-
function
|
|
676
|
+
function Zt(n) {
|
|
657
677
|
return async (e) => {
|
|
658
|
-
let { httpRequest: t } = await Promise.resolve().then(() => (M(), Y)), r = !!e?.leaseId, o = r ?
|
|
678
|
+
let { httpRequest: t } = await Promise.resolve().then(() => (M(), Y)), r = !!e?.leaseId, o = r ? Yt : Xt, i;
|
|
659
679
|
r ? i = { leaseId: e.leaseId } : (i = {
|
|
660
680
|
productId: n.productId ?? "",
|
|
661
|
-
environment:
|
|
681
|
+
environment: eo(n.env ?? "prod")
|
|
662
682
|
}, e?.database !== void 0 && (i.database = e.database));
|
|
663
683
|
let s;
|
|
664
684
|
try {
|
|
@@ -671,35 +691,35 @@ function Yt(n) {
|
|
|
671
691
|
retries: 2
|
|
672
692
|
});
|
|
673
693
|
} catch (a) {
|
|
674
|
-
let
|
|
694
|
+
let l = r ? "renovar" : "obter", d = a instanceof Error ? a.message : String(a), u = a instanceof c ? a.reason : void 0;
|
|
675
695
|
if (u === "suspended" || u === "archived" || u === "revoked") {
|
|
676
696
|
let p = u === "suspended" ? "ambiente suspenso \u2014 a m\xE1quina que o servia parou; ser\xE1 religado quando o ambiente voltar" : u === "archived" ? "ambiente arquivado \u2014 este banco foi arquivado e n\xE3o aceita mais conex\xF5es" : "lease revogado \u2014 as credenciais deste ambiente foram revogadas pelo Core";
|
|
677
|
-
throw new
|
|
697
|
+
throw new b(
|
|
678
698
|
"db_suspended",
|
|
679
|
-
`Falha ao ${
|
|
699
|
+
`Falha ao ${l} lease SQL: ${p} (reason=${u}).`
|
|
680
700
|
);
|
|
681
701
|
}
|
|
682
|
-
throw new
|
|
702
|
+
throw new b(
|
|
683
703
|
"db_unavailable",
|
|
684
|
-
`Falha ao ${
|
|
704
|
+
`Falha ao ${l} lease SQL: ${d}`
|
|
685
705
|
);
|
|
686
706
|
}
|
|
687
|
-
return
|
|
707
|
+
return to(s);
|
|
688
708
|
};
|
|
689
709
|
}
|
|
690
|
-
function
|
|
710
|
+
function to(n) {
|
|
691
711
|
if (!n || typeof n != "object")
|
|
692
|
-
throw new
|
|
712
|
+
throw new b("db_unavailable", "Resposta de lease inv\xE1lida (n\xE3o \xE9 objeto).");
|
|
693
713
|
let t = n.lease;
|
|
694
714
|
if (!t || typeof t != "object")
|
|
695
|
-
throw new
|
|
715
|
+
throw new b(
|
|
696
716
|
"db_unavailable",
|
|
697
717
|
'Resposta de lease inv\xE1lida: campo "lease" ausente ou n\xE3o \xE9 objeto. O Core retorna { kind, lease: { leaseId, host, ... } }.'
|
|
698
718
|
);
|
|
699
719
|
let r = t;
|
|
700
720
|
function o(i, s) {
|
|
701
721
|
if (typeof r[i] !== s)
|
|
702
|
-
throw new
|
|
722
|
+
throw new b(
|
|
703
723
|
"db_unavailable",
|
|
704
724
|
`Campo obrigat\xF3rio "${i}" ausente ou tipo inv\xE1lido na resposta de lease.`
|
|
705
725
|
);
|
|
@@ -729,12 +749,12 @@ function Xe() {
|
|
|
729
749
|
return {
|
|
730
750
|
// Teto 100: bem abaixo do `max_client_conn = 500` do PgBouncer, com folga
|
|
731
751
|
// para múltiplas instâncias do app dividirem o mesmo front-door.
|
|
732
|
-
max: Je("NEETRU_DB_POOL_MAX",
|
|
752
|
+
max: Je("NEETRU_DB_POOL_MAX", en, 1, 100),
|
|
733
753
|
// Teto 15min = janela do cert; piso 1s.
|
|
734
|
-
idleTimeoutMillis: Je("NEETRU_DB_POOL_IDLE_MS",
|
|
754
|
+
idleTimeoutMillis: Je("NEETRU_DB_POOL_IDLE_MS", tn, 1e3, 9e5),
|
|
735
755
|
connectionTimeoutMillis: Je(
|
|
736
756
|
"NEETRU_DB_POOL_CONNECT_TIMEOUT_MS",
|
|
737
|
-
|
|
757
|
+
nn,
|
|
738
758
|
1e3,
|
|
739
759
|
12e4
|
|
740
760
|
),
|
|
@@ -742,7 +762,7 @@ function Xe() {
|
|
|
742
762
|
keepAliveInitialDelayMillis: 1e4
|
|
743
763
|
};
|
|
744
764
|
}
|
|
745
|
-
async function
|
|
765
|
+
async function no(n) {
|
|
746
766
|
let { Pool: e } = await import(
|
|
747
767
|
/* webpackIgnore: true */
|
|
748
768
|
'pg'
|
|
@@ -762,14 +782,14 @@ async function Zr(n) {
|
|
|
762
782
|
...Xe()
|
|
763
783
|
});
|
|
764
784
|
}
|
|
765
|
-
async function
|
|
785
|
+
async function ro(n, e) {
|
|
766
786
|
let { drizzle: t } = await import(
|
|
767
787
|
/* webpackIgnore: true */
|
|
768
788
|
'drizzle-orm/node-postgres'
|
|
769
789
|
);
|
|
770
790
|
return t(n, { schema: e });
|
|
771
791
|
}
|
|
772
|
-
function
|
|
792
|
+
function oo(n, e) {
|
|
773
793
|
let t = null, r = null, o = () => t ? Promise.resolve(t) : (r || (r = e().then((s) => (t = s, r = null, s)).catch((s) => {
|
|
774
794
|
throw r = null, s;
|
|
775
795
|
})), r), i = {
|
|
@@ -785,52 +805,52 @@ function to(n, e) {
|
|
|
785
805
|
};
|
|
786
806
|
return n && Object.setPrototypeOf(i, n), i;
|
|
787
807
|
}
|
|
788
|
-
async function
|
|
808
|
+
async function rn(n, e) {
|
|
789
809
|
let t = e?.database !== void 0 ? { ...n, database: e.database } : n;
|
|
790
810
|
if (t.lazy) {
|
|
791
|
-
let
|
|
792
|
-
if (!
|
|
793
|
-
throw new
|
|
794
|
-
return
|
|
811
|
+
let l = null, d = oo(t.poolPrototype ?? null, () => {
|
|
812
|
+
if (!l)
|
|
813
|
+
throw new b("db_unavailable", "SQL client n\xE3o inicializado (manager ausente).");
|
|
814
|
+
return l._ensureInitialLease();
|
|
795
815
|
}), u = Qe(d), p;
|
|
796
816
|
try {
|
|
797
817
|
p = t.createDrizzle(u, t.schema);
|
|
798
|
-
} catch (
|
|
799
|
-
let
|
|
800
|
-
throw new
|
|
818
|
+
} catch (h) {
|
|
819
|
+
let y = h instanceof Error ? h.message : String(h);
|
|
820
|
+
throw new b("db_unavailable", `Falha ao criar handle Drizzle: ${y}`);
|
|
801
821
|
}
|
|
802
822
|
let f = new re(null, u, p, t);
|
|
803
|
-
return
|
|
823
|
+
return l = f, u.__neetruSetReLease(() => f._reactiveReLease()), f;
|
|
804
824
|
}
|
|
805
825
|
let r;
|
|
806
826
|
try {
|
|
807
827
|
e?.database !== void 0 ? r = await t.fetchLease({ database: e.database }) : r = await t.fetchLease();
|
|
808
|
-
} catch (
|
|
809
|
-
if (
|
|
810
|
-
let d =
|
|
811
|
-
throw new
|
|
828
|
+
} catch (l) {
|
|
829
|
+
if (l instanceof b) throw l;
|
|
830
|
+
let d = l instanceof Error ? l.message : String(l);
|
|
831
|
+
throw new b("db_unavailable", `Falha ao obter lease inicial: ${d}`);
|
|
812
832
|
}
|
|
813
833
|
let o;
|
|
814
834
|
try {
|
|
815
835
|
o = t.createPool(r);
|
|
816
|
-
} catch (
|
|
817
|
-
let d =
|
|
818
|
-
throw new
|
|
836
|
+
} catch (l) {
|
|
837
|
+
let d = l instanceof Error ? l.message : String(l);
|
|
838
|
+
throw new b("db_unavailable", `Falha ao abrir pool: ${d}`);
|
|
819
839
|
}
|
|
820
840
|
let i = Qe(o), s;
|
|
821
841
|
try {
|
|
822
842
|
s = t.createDrizzle(i, t.schema);
|
|
823
|
-
} catch (
|
|
843
|
+
} catch (l) {
|
|
824
844
|
await o.end().catch(() => {
|
|
825
845
|
});
|
|
826
|
-
let d =
|
|
827
|
-
throw new
|
|
846
|
+
let d = l instanceof Error ? l.message : String(l);
|
|
847
|
+
throw new b("db_unavailable", `Falha ao criar handle Drizzle: ${d}`);
|
|
828
848
|
}
|
|
829
849
|
let a = new re(r, i, s, t);
|
|
830
850
|
return i.__neetruSetReLease(() => a._reactiveReLease()), a;
|
|
831
851
|
}
|
|
832
|
-
async function
|
|
833
|
-
let r =
|
|
852
|
+
async function io(n, e, t) {
|
|
853
|
+
let r = Zt(n), o, i;
|
|
834
854
|
try {
|
|
835
855
|
o = await import(
|
|
836
856
|
/* webpackIgnore: true */
|
|
@@ -840,13 +860,13 @@ async function no(n, e, t) {
|
|
|
840
860
|
'drizzle-orm/node-postgres'
|
|
841
861
|
);
|
|
842
862
|
} catch (d) {
|
|
843
|
-
throw new
|
|
863
|
+
throw new b(
|
|
844
864
|
"db_unavailable",
|
|
845
865
|
`[client.db.sql] requer pg + drizzle-orm como peerDependencies do servidor. Instale: npm install pg drizzle-orm. (${d.message})`
|
|
846
866
|
);
|
|
847
867
|
}
|
|
848
868
|
let s = o.Pool ?? o.default?.Pool;
|
|
849
|
-
return
|
|
869
|
+
return rn(
|
|
850
870
|
{
|
|
851
871
|
fetchLease: r,
|
|
852
872
|
createPool: (d) => {
|
|
@@ -881,13 +901,13 @@ async function no(n, e, t) {
|
|
|
881
901
|
t
|
|
882
902
|
);
|
|
883
903
|
}
|
|
884
|
-
var
|
|
904
|
+
var Xt, Yt, en, tn, nn, sn = $(() => {
|
|
885
905
|
Z();
|
|
886
906
|
I();
|
|
887
|
-
|
|
907
|
+
Jt();
|
|
888
908
|
Ge();
|
|
889
|
-
|
|
890
|
-
|
|
909
|
+
Xt = "/api/sdk/v1/db/lease", Yt = "/api/sdk/v1/db/lease/renew";
|
|
910
|
+
en = 10, tn = 6e4, nn = 1e4;
|
|
891
911
|
});
|
|
892
912
|
var Le = /* @__PURE__ */ new Map(), Ue = 3600 * 1e3;
|
|
893
913
|
function it(n, e = Ue) {
|
|
@@ -909,13 +929,13 @@ I();
|
|
|
909
929
|
var at = /^nrt_([A-Za-z0-9]+)_([A-Za-z0-9]+)$/;
|
|
910
930
|
function ct(n) {
|
|
911
931
|
if (typeof n != "string" || n.length === 0)
|
|
912
|
-
throw new
|
|
932
|
+
throw new c(
|
|
913
933
|
"invalid_config",
|
|
914
934
|
"apiKey is required (formato nrt_<keyId>_<secret>)"
|
|
915
935
|
);
|
|
916
936
|
let e = at.exec(n);
|
|
917
937
|
if (!e)
|
|
918
|
-
throw new
|
|
938
|
+
throw new c(
|
|
919
939
|
"invalid_config",
|
|
920
940
|
"apiKey malformado - esperado formato nrt_<keyId>_<secret>"
|
|
921
941
|
);
|
|
@@ -929,52 +949,52 @@ function lt(n) {
|
|
|
929
949
|
|
|
930
950
|
// src/base-url-allowlist.ts
|
|
931
951
|
I();
|
|
932
|
-
var dt = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]),
|
|
952
|
+
var dt = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]), Jn = ".neetru.com", Xn = "neetru.com", Yn = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?\.(test|localhost)$/;
|
|
933
953
|
function ut(n) {
|
|
934
|
-
return
|
|
954
|
+
return Yn.test(n);
|
|
935
955
|
}
|
|
936
|
-
function
|
|
956
|
+
function Zn(n) {
|
|
937
957
|
return n.toLowerCase().replace(/\.+$/, "");
|
|
938
958
|
}
|
|
939
959
|
function pt(n, e = []) {
|
|
940
960
|
if (typeof n != "string" || n.length === 0)
|
|
941
|
-
throw new
|
|
961
|
+
throw new c("invalid_config", "baseUrl is required");
|
|
942
962
|
let t;
|
|
943
963
|
try {
|
|
944
964
|
t = new URL(n);
|
|
945
965
|
} catch {
|
|
946
|
-
throw new
|
|
966
|
+
throw new c("invalid_config", `baseUrl is not a valid URL: ${n}`);
|
|
947
967
|
}
|
|
948
|
-
let r = t.protocol, o =
|
|
949
|
-
if (
|
|
968
|
+
let r = t.protocol, o = Zn(t.hostname);
|
|
969
|
+
if (er())
|
|
950
970
|
return typeof console < "u" && console.warn(
|
|
951
971
|
`[neetru-sdk] NEETRU_ALLOW_INSECURE_BASEURL=1 ativo. baseUrl=${n} aceito sem valida\xE7\xE3o.`
|
|
952
972
|
), n.replace(/\/+$/, "");
|
|
953
973
|
if (r !== "https:" && r !== "http:")
|
|
954
|
-
throw new
|
|
974
|
+
throw new c(
|
|
955
975
|
"invalid_config",
|
|
956
976
|
`baseUrl protocol must be http: or https:, got ${r}`
|
|
957
977
|
);
|
|
958
978
|
if (r === "http:") {
|
|
959
979
|
if (!(dt.has(o) || ut(o)))
|
|
960
|
-
throw new
|
|
980
|
+
throw new c(
|
|
961
981
|
"invalid_config",
|
|
962
982
|
`baseUrl with http: only allowed for localhost/127.0.0.1/*.test/*.localhost. Got: ${o}. Use https: or set NEETRU_ALLOW_INSECURE_BASEURL=1 to bypass.`
|
|
963
983
|
);
|
|
964
984
|
return n.replace(/\/+$/, "");
|
|
965
985
|
}
|
|
966
|
-
let i = o ===
|
|
967
|
-
let d =
|
|
986
|
+
let i = o === Xn || o.endsWith(Jn), s = e.some((l) => {
|
|
987
|
+
let d = l.toLowerCase();
|
|
968
988
|
return o === d || o.endsWith(`.${d}`);
|
|
969
989
|
}), a = dt.has(o) || ut(o);
|
|
970
990
|
if (!i && !s && !a)
|
|
971
|
-
throw new
|
|
991
|
+
throw new c(
|
|
972
992
|
"invalid_config",
|
|
973
993
|
`baseUrl ${o} is not in the allowlist. Allowed: *.neetru.com, localhost, or configure { allowedHosts: ['...'] }. Bypass: NEETRU_ALLOW_INSECURE_BASEURL=1.`
|
|
974
994
|
);
|
|
975
995
|
return n.replace(/\/+$/, "");
|
|
976
996
|
}
|
|
977
|
-
function
|
|
997
|
+
function er() {
|
|
978
998
|
try {
|
|
979
999
|
let e = globalThis.process?.env?.NEETRU_ALLOW_INSECURE_BASEURL;
|
|
980
1000
|
if (e === "1" || e === "true") return !0;
|
|
@@ -996,12 +1016,12 @@ I();
|
|
|
996
1016
|
M();
|
|
997
1017
|
function At(n) {
|
|
998
1018
|
if (!n || typeof n != "object")
|
|
999
|
-
throw new
|
|
1019
|
+
throw new c("invalid_response", "Catalog response item is not an object");
|
|
1000
1020
|
let e = n;
|
|
1001
1021
|
if (typeof e.slug != "string" || !e.slug)
|
|
1002
|
-
throw new
|
|
1022
|
+
throw new c("invalid_response", "Catalog product missing slug");
|
|
1003
1023
|
if (typeof e.name != "string" || !e.name)
|
|
1004
|
-
throw new
|
|
1024
|
+
throw new c("invalid_response", "Catalog product missing name");
|
|
1005
1025
|
let t = {
|
|
1006
1026
|
slug: e.slug,
|
|
1007
1027
|
name: e.name
|
|
@@ -1025,7 +1045,7 @@ function Et(n) {
|
|
|
1025
1045
|
path: "/api/sdk/v1/catalog"
|
|
1026
1046
|
});
|
|
1027
1047
|
if (!t || !Array.isArray(t.products))
|
|
1028
|
-
throw new
|
|
1048
|
+
throw new c(
|
|
1029
1049
|
"invalid_response",
|
|
1030
1050
|
"Catalog list response missing products array"
|
|
1031
1051
|
);
|
|
@@ -1041,13 +1061,13 @@ function Et(n) {
|
|
|
1041
1061
|
*/
|
|
1042
1062
|
async get(e) {
|
|
1043
1063
|
if (!e || typeof e != "string")
|
|
1044
|
-
throw new
|
|
1064
|
+
throw new c("validation_failed", "slug is required");
|
|
1045
1065
|
let t = await v(n, {
|
|
1046
1066
|
method: "GET",
|
|
1047
1067
|
path: `/api/sdk/v1/catalog/${encodeURIComponent(e)}`
|
|
1048
1068
|
});
|
|
1049
1069
|
if (!t || !t.product)
|
|
1050
|
-
throw new
|
|
1070
|
+
throw new c(
|
|
1051
1071
|
"invalid_response",
|
|
1052
1072
|
"Catalog get response missing product"
|
|
1053
1073
|
);
|
|
@@ -1058,9 +1078,9 @@ function Et(n) {
|
|
|
1058
1078
|
|
|
1059
1079
|
// src/entitlements.ts
|
|
1060
1080
|
I();
|
|
1061
|
-
var
|
|
1081
|
+
var mr = "client.entitlements.check()/checkDetailed() est\xE3o DEPRECADOS \u2014 apontavam para GET /api/v1/sdk/entitlements/check, um endpoint que o Core nunca escreve (sempre retornava not_subscribed). Use client.usage.check(resource, { productId, tenantId }) no lugar \u2014 mesmo resultado (allowed/reason/remaining/limit/behavior), endpoint real.";
|
|
1062
1082
|
function Pt() {
|
|
1063
|
-
throw new
|
|
1083
|
+
throw new c("validation_failed", mr);
|
|
1064
1084
|
}
|
|
1065
1085
|
function Dt(n) {
|
|
1066
1086
|
return {
|
|
@@ -1088,13 +1108,13 @@ function Dt(n) {
|
|
|
1088
1108
|
I();
|
|
1089
1109
|
M();
|
|
1090
1110
|
var Nt = ["debug", "info", "warn", "error", "fatal"];
|
|
1091
|
-
function
|
|
1111
|
+
function hr() {
|
|
1092
1112
|
return typeof globalThis < "u" && typeof globalThis.window < "u";
|
|
1093
1113
|
}
|
|
1094
1114
|
function xt() {
|
|
1095
|
-
return
|
|
1115
|
+
return hr() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
|
|
1096
1116
|
}
|
|
1097
|
-
function
|
|
1117
|
+
function gr(n) {
|
|
1098
1118
|
switch (n) {
|
|
1099
1119
|
case "debug":
|
|
1100
1120
|
return console.debug.bind(console);
|
|
@@ -1110,16 +1130,16 @@ function hr(n) {
|
|
|
1110
1130
|
return console.log.bind(console);
|
|
1111
1131
|
}
|
|
1112
1132
|
}
|
|
1113
|
-
var
|
|
1133
|
+
var yr = 500, _r = 50;
|
|
1114
1134
|
function Ot(n) {
|
|
1115
1135
|
let e = [], t = null, r = null;
|
|
1116
1136
|
async function o() {
|
|
1117
1137
|
if (e.length === 0) return;
|
|
1118
1138
|
let s = e.splice(0, e.length), a = Promise.allSettled(
|
|
1119
|
-
s.map(async (
|
|
1139
|
+
s.map(async (l) => {
|
|
1120
1140
|
try {
|
|
1121
|
-
let d = { name:
|
|
1122
|
-
u && (d.productSlug = u),
|
|
1141
|
+
let d = { name: l.name }, u = l.productSlug ?? n.productId;
|
|
1142
|
+
u && (d.productSlug = u), l.properties && typeof l.properties == "object" && (d.properties = l.properties), l.timestamp && (d.timestamp = l.timestamp);
|
|
1123
1143
|
let p = xt();
|
|
1124
1144
|
await v(n, {
|
|
1125
1145
|
method: "POST",
|
|
@@ -1133,7 +1153,7 @@ function Ot(n) {
|
|
|
1133
1153
|
idempotencyKey: !0
|
|
1134
1154
|
});
|
|
1135
1155
|
} catch (d) {
|
|
1136
|
-
typeof console < "u" && console.warn("[neetru-sdk] telemetry.track flush failed for event",
|
|
1156
|
+
typeof console < "u" && console.warn("[neetru-sdk] telemetry.track flush failed for event", l.name, d);
|
|
1137
1157
|
}
|
|
1138
1158
|
})
|
|
1139
1159
|
);
|
|
@@ -1144,7 +1164,7 @@ function Ot(n) {
|
|
|
1144
1164
|
function i() {
|
|
1145
1165
|
t || (t = setTimeout(() => {
|
|
1146
1166
|
o();
|
|
1147
|
-
},
|
|
1167
|
+
}, yr));
|
|
1148
1168
|
}
|
|
1149
1169
|
return {
|
|
1150
1170
|
/**
|
|
@@ -1161,13 +1181,13 @@ function Ot(n) {
|
|
|
1161
1181
|
*/
|
|
1162
1182
|
async event(s) {
|
|
1163
1183
|
if (!s || typeof s != "object")
|
|
1164
|
-
throw new
|
|
1184
|
+
throw new c("validation_failed", "event input is required");
|
|
1165
1185
|
if (typeof s.name != "string" || s.name.length === 0)
|
|
1166
|
-
throw new
|
|
1186
|
+
throw new c("validation_failed", "event.name is required");
|
|
1167
1187
|
if (s.name.length > 128)
|
|
1168
|
-
throw new
|
|
1169
|
-
let a = { name: s.name },
|
|
1170
|
-
|
|
1188
|
+
throw new c("validation_failed", "event.name max 128 chars");
|
|
1189
|
+
let a = { name: s.name }, l = s.productSlug ?? n.productId;
|
|
1190
|
+
l && (a.productSlug = l), s.properties && typeof s.properties == "object" && (a.properties = s.properties), s.timestamp && (a.timestamp = s.timestamp);
|
|
1171
1191
|
let d = xt(), u = await v(n, {
|
|
1172
1192
|
method: "POST",
|
|
1173
1193
|
path: d.path,
|
|
@@ -1175,7 +1195,7 @@ function Ot(n) {
|
|
|
1175
1195
|
requireAuth: d.requireAuth
|
|
1176
1196
|
});
|
|
1177
1197
|
if (!u || u.ok !== true || typeof u.eventId != "string")
|
|
1178
|
-
throw new
|
|
1198
|
+
throw new c("invalid_response", "Telemetry response missing eventId");
|
|
1179
1199
|
return { ok: true, eventId: u.eventId };
|
|
1180
1200
|
},
|
|
1181
1201
|
/**
|
|
@@ -1189,7 +1209,7 @@ function Ot(n) {
|
|
|
1189
1209
|
* ```
|
|
1190
1210
|
*/
|
|
1191
1211
|
track(s) {
|
|
1192
|
-
!s || typeof s != "object" || typeof s.name != "string" || s.name.length === 0 || s.name.length > 128 || (e.push(s), e.length >=
|
|
1212
|
+
!s || typeof s != "object" || typeof s.name != "string" || s.name.length === 0 || s.name.length > 128 || (e.push(s), e.length >= _r ? (t && (clearTimeout(t), t = null), o()) : i());
|
|
1193
1213
|
},
|
|
1194
1214
|
/**
|
|
1195
1215
|
* Força flush imediato da queue de `track()`. Resolva antes de
|
|
@@ -1215,22 +1235,22 @@ function Ot(n) {
|
|
|
1215
1235
|
*/
|
|
1216
1236
|
async log(s) {
|
|
1217
1237
|
if (!s || typeof s != "object")
|
|
1218
|
-
throw new
|
|
1238
|
+
throw new c("validation_failed", "log input is required");
|
|
1219
1239
|
if (!Nt.includes(s.level))
|
|
1220
|
-
throw new
|
|
1240
|
+
throw new c("validation_failed", `level must be one of ${Nt.join(", ")}`);
|
|
1221
1241
|
if (typeof s.message != "string" || s.message.length === 0)
|
|
1222
|
-
throw new
|
|
1242
|
+
throw new c("validation_failed", "message is required");
|
|
1223
1243
|
if (s.message.length > 4e3)
|
|
1224
|
-
throw new
|
|
1244
|
+
throw new c("validation_failed", "message max 4000 chars");
|
|
1225
1245
|
if (n.env === "dev")
|
|
1226
|
-
return
|
|
1246
|
+
return gr(s.level)(`[neetru-sdk] ${s.level}: ${s.message}`, s.metadata ?? {}), { ok: true, mode: "mock" };
|
|
1227
1247
|
let a = {
|
|
1228
1248
|
level: s.level,
|
|
1229
1249
|
message: s.message
|
|
1230
1250
|
};
|
|
1231
1251
|
s.metadata && (a.metadata = s.metadata);
|
|
1232
|
-
let
|
|
1233
|
-
|
|
1252
|
+
let l = s.productSlug ?? n.productId;
|
|
1253
|
+
l && (a.productSlug = l);
|
|
1234
1254
|
let d = s.correlationId;
|
|
1235
1255
|
if (!d)
|
|
1236
1256
|
try {
|
|
@@ -1248,7 +1268,7 @@ function Ot(n) {
|
|
|
1248
1268
|
headers: u
|
|
1249
1269
|
});
|
|
1250
1270
|
if (!p || p.ok !== true)
|
|
1251
|
-
throw new
|
|
1271
|
+
throw new c("invalid_response", "Telemetry log response missing ok");
|
|
1252
1272
|
return {
|
|
1253
1273
|
ok: true,
|
|
1254
1274
|
logId: typeof p.logId == "string" ? p.logId : void 0,
|
|
@@ -1267,7 +1287,7 @@ I();
|
|
|
1267
1287
|
var Lt = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
|
|
1268
1288
|
function N(n, e) {
|
|
1269
1289
|
if (typeof e != "string" || !Lt.test(e))
|
|
1270
|
-
throw new
|
|
1290
|
+
throw new c(
|
|
1271
1291
|
"validation_failed",
|
|
1272
1292
|
`${n} must match ${Lt.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
|
|
1273
1293
|
);
|
|
@@ -1290,17 +1310,17 @@ function Ut(n) {
|
|
|
1290
1310
|
*/
|
|
1291
1311
|
async report(e, t = 1, r) {
|
|
1292
1312
|
if (!e || typeof e != "string")
|
|
1293
|
-
throw new
|
|
1313
|
+
throw new c("validation_failed", "resource is required");
|
|
1294
1314
|
if (!Number.isFinite(t) || t <= 0 || !Number.isInteger(t))
|
|
1295
|
-
throw new
|
|
1315
|
+
throw new c("validation_failed", "qty must be a positive integer");
|
|
1296
1316
|
let o = r?.productId ?? n.productId, i = r?.tenantId ?? n.tenantId;
|
|
1297
1317
|
if (!o)
|
|
1298
|
-
throw new
|
|
1318
|
+
throw new c(
|
|
1299
1319
|
"validation_failed",
|
|
1300
1320
|
"productId required (pass to options or set on createNeetruClient)"
|
|
1301
1321
|
);
|
|
1302
1322
|
if (!i)
|
|
1303
|
-
throw new
|
|
1323
|
+
throw new c(
|
|
1304
1324
|
"validation_failed",
|
|
1305
1325
|
"tenantId required (pass to options or set on createNeetruClient)"
|
|
1306
1326
|
);
|
|
@@ -1313,7 +1333,7 @@ function Ut(n) {
|
|
|
1313
1333
|
idempotencyKey: true
|
|
1314
1334
|
});
|
|
1315
1335
|
if (!s || s.ok !== true)
|
|
1316
|
-
throw new
|
|
1336
|
+
throw new c("invalid_response", "usage.report response missing ok");
|
|
1317
1337
|
return {
|
|
1318
1338
|
ok: true,
|
|
1319
1339
|
counterId: s.counterId,
|
|
@@ -1331,10 +1351,10 @@ function Ut(n) {
|
|
|
1331
1351
|
*/
|
|
1332
1352
|
async check(e, t) {
|
|
1333
1353
|
if (!e || typeof e != "string")
|
|
1334
|
-
throw new
|
|
1354
|
+
throw new c("validation_failed", "resource is required");
|
|
1335
1355
|
let r = t?.productId ?? n.productId, o = t?.tenantId ?? n.tenantId;
|
|
1336
1356
|
if (!r || !o)
|
|
1337
|
-
throw new
|
|
1357
|
+
throw new c(
|
|
1338
1358
|
"validation_failed",
|
|
1339
1359
|
"productId and tenantId required (pass to options or set on createNeetruClient)"
|
|
1340
1360
|
);
|
|
@@ -1346,7 +1366,7 @@ function Ut(n) {
|
|
|
1346
1366
|
requireAuth: true
|
|
1347
1367
|
});
|
|
1348
1368
|
if (!i || typeof i.allowed != "boolean")
|
|
1349
|
-
throw new
|
|
1369
|
+
throw new c("invalid_response", "usage.check response missing allowed");
|
|
1350
1370
|
let s = i.behavior ?? (i.reason === "limit_exceeded" ? "readonly" : null);
|
|
1351
1371
|
return {
|
|
1352
1372
|
allowed: i.allowed,
|
|
@@ -1364,20 +1384,20 @@ function Ut(n) {
|
|
|
1364
1384
|
// src/support.ts
|
|
1365
1385
|
I();
|
|
1366
1386
|
M();
|
|
1367
|
-
var je = ["low", "normal", "high", "urgent"],
|
|
1387
|
+
var je = ["low", "normal", "high", "urgent"], br = ["open", "pending", "resolved", "closed"], Mt = 50;
|
|
1368
1388
|
function qt(n) {
|
|
1369
1389
|
if (!n || typeof n != "object")
|
|
1370
|
-
throw new
|
|
1390
|
+
throw new c("invalid_response", "Ticket response is not an object");
|
|
1371
1391
|
let e = n;
|
|
1372
1392
|
if (typeof e.id != "string")
|
|
1373
|
-
throw new
|
|
1393
|
+
throw new c("invalid_response", "Ticket missing id");
|
|
1374
1394
|
let t = Array.isArray(e.attachments) && typeof e.attachments[0] == "string" ? e.attachments[0] : void 0, r = typeof e.screenshotUrl == "string" ? e.screenshotUrl : t ?? null;
|
|
1375
1395
|
return {
|
|
1376
1396
|
id: e.id,
|
|
1377
1397
|
subject: typeof e.subject == "string" ? e.subject : "",
|
|
1378
1398
|
message: typeof e.message == "string" ? e.message : "",
|
|
1379
1399
|
severity: je.includes(e.severity) ? e.severity : "normal",
|
|
1380
|
-
status:
|
|
1400
|
+
status: br.includes(e.status) ? e.status : "open",
|
|
1381
1401
|
createdAt: typeof e.createdAt == "string" ? e.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1382
1402
|
updatedAt: typeof e.updatedAt == "string" ? e.updatedAt : void 0,
|
|
1383
1403
|
productSlug: typeof e.productId == "string" ? e.productId : typeof e.productSlug == "string" ? e.productSlug : void 0,
|
|
@@ -1397,11 +1417,11 @@ function qt(n) {
|
|
|
1397
1417
|
}
|
|
1398
1418
|
function de(n) {
|
|
1399
1419
|
if (!n || typeof n != "string")
|
|
1400
|
-
throw new
|
|
1420
|
+
throw new c("validation_failed", "ticketId is required");
|
|
1401
1421
|
}
|
|
1402
1422
|
function Ft(n) {
|
|
1403
1423
|
if (typeof n == "string" && n.length > 2e3)
|
|
1404
|
-
throw new
|
|
1424
|
+
throw new c("validation_failed", "comment max 2000 chars");
|
|
1405
1425
|
}
|
|
1406
1426
|
function jt(n, ...e) {
|
|
1407
1427
|
for (let t of e)
|
|
@@ -1409,17 +1429,17 @@ function jt(n, ...e) {
|
|
|
1409
1429
|
return N("productSlug", t), t;
|
|
1410
1430
|
if (n.productId)
|
|
1411
1431
|
return N("productId", n.productId), n.productId;
|
|
1412
|
-
throw new
|
|
1432
|
+
throw new c(
|
|
1413
1433
|
"validation_failed",
|
|
1414
1434
|
"productId required (pass to input.productSlug or set on createNeetruClient)"
|
|
1415
1435
|
);
|
|
1416
1436
|
}
|
|
1417
|
-
var
|
|
1437
|
+
var vr = "X-Neetru-End-User-Token", wr = "Esta opera\xE7\xE3o de suporte exige um usu\xE1rio final logado: o Core s\xF3 mostra/altera os tickets do pr\xF3prio usu\xE1rio (header X-Neetru-End-User-Token com o id_token OIDC). Fa\xE7a login com client.auth.signIn() e tente de novo.", kr = "O Core exige a identidade do usu\xE1rio final para esta opera\xE7\xE3o (403 end_user_token_required) e nenhum id_token foi aceito. Fa\xE7a login com client.auth.signIn() e tente de novo.", Sr = "O Core recusou o token do usu\xE1rio final (401 invalid_end_user_token \u2014 sess\xE3o expirada, usu\xE1rio inativo ou token que n\xE3o \xE9 id_token) e a renova\xE7\xE3o autom\xE1tica n\xE3o resolveu. Fa\xE7a login novamente com client.auth.signIn() e tente de novo.", Tr = "O id_token do usu\xE1rio final foi emitido para o client OIDC de OUTRO produto (403 end_user_token_product_mismatch). Confira se o login (client.auth / clientId OIDC) e a apiKey/productId do createNeetruClient s\xE3o do MESMO produto.";
|
|
1418
1438
|
function $t(n) {
|
|
1419
|
-
if (n instanceof
|
|
1439
|
+
if (n instanceof c && !(n instanceof V)) {
|
|
1420
1440
|
if (n.code === "end_user_token_required")
|
|
1421
1441
|
throw new V(
|
|
1422
|
-
|
|
1442
|
+
kr,
|
|
1423
1443
|
"end_user_token_required",
|
|
1424
1444
|
n.status,
|
|
1425
1445
|
n.requestId,
|
|
@@ -1427,16 +1447,16 @@ function $t(n) {
|
|
|
1427
1447
|
);
|
|
1428
1448
|
if (n.code === "invalid_end_user_token")
|
|
1429
1449
|
throw new V(
|
|
1430
|
-
|
|
1450
|
+
Sr,
|
|
1431
1451
|
"invalid_end_user_token",
|
|
1432
1452
|
n.status,
|
|
1433
1453
|
n.requestId,
|
|
1434
1454
|
n.correlationId
|
|
1435
1455
|
);
|
|
1436
1456
|
if (n.code === "end_user_token_product_mismatch")
|
|
1437
|
-
throw new
|
|
1457
|
+
throw new c(
|
|
1438
1458
|
"forbidden",
|
|
1439
|
-
|
|
1459
|
+
Tr,
|
|
1440
1460
|
n.status,
|
|
1441
1461
|
n.requestId,
|
|
1442
1462
|
"end_user_token_product_mismatch",
|
|
@@ -1445,8 +1465,8 @@ function $t(n) {
|
|
|
1445
1465
|
}
|
|
1446
1466
|
throw n;
|
|
1447
1467
|
}
|
|
1448
|
-
function
|
|
1449
|
-
return n instanceof
|
|
1468
|
+
function Rr(n) {
|
|
1469
|
+
return n instanceof c && n.code === "invalid_end_user_token";
|
|
1450
1470
|
}
|
|
1451
1471
|
function Wt(n, e = {}) {
|
|
1452
1472
|
async function t() {
|
|
@@ -1466,20 +1486,20 @@ function Wt(n, e = {}) {
|
|
|
1466
1486
|
}
|
|
1467
1487
|
}
|
|
1468
1488
|
function o(a) {
|
|
1469
|
-
return a ? { [
|
|
1489
|
+
return a ? { [vr]: a } : {};
|
|
1470
1490
|
}
|
|
1471
|
-
async function i(a,
|
|
1491
|
+
async function i(a, l) {
|
|
1472
1492
|
let d = await t();
|
|
1473
1493
|
if (!d && a && await r() && (d = await t()), !d && a)
|
|
1474
|
-
throw new V(
|
|
1494
|
+
throw new V(wr, "no_signed_in_user");
|
|
1475
1495
|
try {
|
|
1476
|
-
return await
|
|
1496
|
+
return await l(o(d));
|
|
1477
1497
|
} catch (u) {
|
|
1478
|
-
if (d &&
|
|
1498
|
+
if (d && Rr(u) && await r()) {
|
|
1479
1499
|
let p = await t();
|
|
1480
1500
|
if (p)
|
|
1481
1501
|
try {
|
|
1482
|
-
return await
|
|
1502
|
+
return await l(o(p));
|
|
1483
1503
|
} catch (f) {
|
|
1484
1504
|
$t(f);
|
|
1485
1505
|
}
|
|
@@ -1487,7 +1507,7 @@ function Wt(n, e = {}) {
|
|
|
1487
1507
|
$t(u);
|
|
1488
1508
|
}
|
|
1489
1509
|
}
|
|
1490
|
-
async function s(a,
|
|
1510
|
+
async function s(a, l = {}) {
|
|
1491
1511
|
await i(
|
|
1492
1512
|
true,
|
|
1493
1513
|
(d) => v(n, {
|
|
@@ -1495,7 +1515,7 @@ function Wt(n, e = {}) {
|
|
|
1495
1515
|
path: a,
|
|
1496
1516
|
requireAuth: !0,
|
|
1497
1517
|
headers: d,
|
|
1498
|
-
...
|
|
1518
|
+
...l
|
|
1499
1519
|
})
|
|
1500
1520
|
);
|
|
1501
1521
|
}
|
|
@@ -1508,17 +1528,17 @@ function Wt(n, e = {}) {
|
|
|
1508
1528
|
*/
|
|
1509
1529
|
async createTicket(a) {
|
|
1510
1530
|
if (!a || typeof a != "object")
|
|
1511
|
-
throw new
|
|
1531
|
+
throw new c("validation_failed", "input is required");
|
|
1512
1532
|
if (!a.subject || typeof a.subject != "string")
|
|
1513
|
-
throw new
|
|
1533
|
+
throw new c("validation_failed", "subject is required");
|
|
1514
1534
|
if (a.subject.length > 200)
|
|
1515
|
-
throw new
|
|
1535
|
+
throw new c("validation_failed", "subject max 200 chars");
|
|
1516
1536
|
if (!a.message || typeof a.message != "string")
|
|
1517
|
-
throw new
|
|
1537
|
+
throw new c("validation_failed", "message is required");
|
|
1518
1538
|
if (a.message.length > 1e4)
|
|
1519
|
-
throw new
|
|
1539
|
+
throw new c("validation_failed", "message max 10000 chars");
|
|
1520
1540
|
if (a.severity && !je.includes(a.severity))
|
|
1521
|
-
throw new
|
|
1541
|
+
throw new c(
|
|
1522
1542
|
"validation_failed",
|
|
1523
1543
|
`severity must be one of ${je.join(", ")}`
|
|
1524
1544
|
);
|
|
@@ -1548,9 +1568,9 @@ function Wt(n, e = {}) {
|
|
|
1548
1568
|
* Endpoint canonical: `GET /api/sdk/v1/support/tickets?productId=...`.
|
|
1549
1569
|
*/
|
|
1550
1570
|
async listMyTickets(a) {
|
|
1551
|
-
let
|
|
1571
|
+
let l = jt(n, a?.productSlug), d = a?.limit;
|
|
1552
1572
|
if (d !== void 0 && (!Number.isInteger(d) || d < 1 || d > Mt))
|
|
1553
|
-
throw new
|
|
1573
|
+
throw new c(
|
|
1554
1574
|
"validation_failed",
|
|
1555
1575
|
`limit must be an integer 1-${Mt} (Core default 20)`
|
|
1556
1576
|
);
|
|
@@ -1559,7 +1579,7 @@ function Wt(n, e = {}) {
|
|
|
1559
1579
|
(f) => v(n, {
|
|
1560
1580
|
method: "GET",
|
|
1561
1581
|
path: "/api/sdk/v1/support/tickets",
|
|
1562
|
-
query: { productId:
|
|
1582
|
+
query: { productId: l, limit: d },
|
|
1563
1583
|
requireAuth: !0,
|
|
1564
1584
|
headers: f
|
|
1565
1585
|
})
|
|
@@ -1596,9 +1616,9 @@ function Wt(n, e = {}) {
|
|
|
1596
1616
|
*/
|
|
1597
1617
|
async submitSatisfaction(a) {
|
|
1598
1618
|
if (!a || typeof a != "object")
|
|
1599
|
-
throw new
|
|
1619
|
+
throw new c("validation_failed", "input is required");
|
|
1600
1620
|
if (de(a.ticketId), a.rating !== null && a.rating !== void 0 && (!Number.isInteger(a.rating) || a.rating < 1 || a.rating > 5))
|
|
1601
|
-
throw new
|
|
1621
|
+
throw new c("validation_failed", "rating must be an integer 1-5 or null");
|
|
1602
1622
|
Ft(a.comment), await s(
|
|
1603
1623
|
`/api/sdk/v1/support/tickets/${encodeURIComponent(a.ticketId)}/satisfaction`,
|
|
1604
1624
|
{
|
|
@@ -1615,10 +1635,10 @@ function Wt(n, e = {}) {
|
|
|
1615
1635
|
* satisfação/notificação. Endpoint canonical:
|
|
1616
1636
|
* `POST /api/sdk/v1/support/tickets/{id}/contest`.
|
|
1617
1637
|
*/
|
|
1618
|
-
async contestTicket(a,
|
|
1619
|
-
de(a), Ft(
|
|
1638
|
+
async contestTicket(a, l) {
|
|
1639
|
+
de(a), Ft(l?.comment), await s(
|
|
1620
1640
|
`/api/sdk/v1/support/tickets/${encodeURIComponent(a)}/contest`,
|
|
1621
|
-
{ body: { comment:
|
|
1641
|
+
{ body: { comment: l?.comment ?? void 0 } }
|
|
1622
1642
|
);
|
|
1623
1643
|
}
|
|
1624
1644
|
};
|
|
@@ -1650,7 +1670,7 @@ function $e(n, e) {
|
|
|
1650
1670
|
}
|
|
1651
1671
|
return r;
|
|
1652
1672
|
}
|
|
1653
|
-
function
|
|
1673
|
+
function Cr(n, e) {
|
|
1654
1674
|
let t = $e(n, e.field);
|
|
1655
1675
|
if (t === void 0) return false;
|
|
1656
1676
|
let { op: r, value: o } = e;
|
|
@@ -1681,10 +1701,10 @@ function Ir(n, e) {
|
|
|
1681
1701
|
);
|
|
1682
1702
|
}
|
|
1683
1703
|
}
|
|
1684
|
-
function
|
|
1685
|
-
return e.every((t) =>
|
|
1704
|
+
function Ar(n, e) {
|
|
1705
|
+
return e.every((t) => Cr(n, t));
|
|
1686
1706
|
}
|
|
1687
|
-
function
|
|
1707
|
+
function Er(n) {
|
|
1688
1708
|
return (e, t) => {
|
|
1689
1709
|
if (n) {
|
|
1690
1710
|
let r = $e(e.data, n.field), o = $e(t.data, n.field), i = ee(r, o);
|
|
@@ -1694,7 +1714,7 @@ function Ar(n) {
|
|
|
1694
1714
|
return e.id < t.id ? -1 : e.id > t.id ? 1 : 0;
|
|
1695
1715
|
};
|
|
1696
1716
|
}
|
|
1697
|
-
function
|
|
1717
|
+
function Pr(n, e) {
|
|
1698
1718
|
let t = n.findIndex((r) => r.id === e.docId);
|
|
1699
1719
|
return t === -1 ? n : e.type === "startAfter" ? n.slice(t + 1) : n.slice(0, t);
|
|
1700
1720
|
}
|
|
@@ -1712,11 +1732,11 @@ var z = class n {
|
|
|
1712
1732
|
evaluate(e, t) {
|
|
1713
1733
|
let r = e.filter((u) => !u.meta.deleted), o = t.where ?? [];
|
|
1714
1734
|
o.length > 0 && (r = r.filter(
|
|
1715
|
-
(u) =>
|
|
1735
|
+
(u) => Ar(u.data, o)
|
|
1716
1736
|
));
|
|
1717
|
-
let i =
|
|
1737
|
+
let i = Er(t.orderBy), s = [...r].sort(i), a = t.cursor ? Pr(s, t.cursor) : s, l = Math.min(t.limit ?? 20, 500);
|
|
1718
1738
|
return {
|
|
1719
|
-
docs: a.slice(0,
|
|
1739
|
+
docs: a.slice(0, l).map((u) => ({ id: u.id, data: u.data })),
|
|
1720
1740
|
// `incomplete` é sempre true aqui — o QueryEngine não sabe se o cache
|
|
1721
1741
|
// tem todos os docs da coleção. É responsabilidade do chamador (LocalStore)
|
|
1722
1742
|
// injetar o flag de completude baseado nos metadados do query_cache.
|
|
@@ -1734,7 +1754,7 @@ var z = class n {
|
|
|
1734
1754
|
};
|
|
1735
1755
|
|
|
1736
1756
|
// src/db/offline/local-store.ts
|
|
1737
|
-
var
|
|
1757
|
+
var Nr = 1, W = "documents", B = "mutations", te = "query_cache", ue = "sync_meta", H = "conflict_log", pe = class {
|
|
1738
1758
|
db = null;
|
|
1739
1759
|
dbName;
|
|
1740
1760
|
constructor(e) {
|
|
@@ -1746,7 +1766,7 @@ var Dr = 1, W = "documents", B = "mutations", te = "query_cache", ue = "sync_met
|
|
|
1746
1766
|
* Idempotente — chamadas subsequentes são no-ops se o banco já está aberto.
|
|
1747
1767
|
*/
|
|
1748
1768
|
async open() {
|
|
1749
|
-
this.db === null && (this.db = await idb.openDB(this.dbName,
|
|
1769
|
+
this.db === null && (this.db = await idb.openDB(this.dbName, Nr, {
|
|
1750
1770
|
upgrade(e) {
|
|
1751
1771
|
if (!e.objectStoreNames.contains(W)) {
|
|
1752
1772
|
let t = e.createObjectStore(W, {
|
|
@@ -2154,18 +2174,18 @@ var me = class {
|
|
|
2154
2174
|
* Atômico: a persistência final é uma única operação putMutation.
|
|
2155
2175
|
*/
|
|
2156
2176
|
async enqueue(e) {
|
|
2157
|
-
let { collection: t, op: r, payload: o, baseVersion: i, batchId: s, upsert: a } = e,
|
|
2177
|
+
let { collection: t, op: r, payload: o, baseVersion: i, batchId: s, upsert: a } = e, l = e.docId ?? (r === "add" ? We() : "");
|
|
2158
2178
|
await this.syncSeq();
|
|
2159
|
-
let u = (await this.store.listMutations({ collection: t, docId:
|
|
2179
|
+
let u = (await this.store.listMutations({ collection: t, docId: l })).filter((h) => h.status === "queued").sort((h, y) => y.seq - h.seq)[0];
|
|
2160
2180
|
if (u !== void 0) {
|
|
2161
|
-
let
|
|
2162
|
-
if (
|
|
2163
|
-
if ("removed" in
|
|
2181
|
+
let h = this.tryCoalesce(u, r, o, s, a);
|
|
2182
|
+
if (h !== null) {
|
|
2183
|
+
if ("removed" in h)
|
|
2164
2184
|
return await this.store.deleteMutation(u.mutationId), {
|
|
2165
2185
|
seq: u.seq,
|
|
2166
2186
|
mutationId: We(),
|
|
2167
2187
|
collection: t,
|
|
2168
|
-
docId:
|
|
2188
|
+
docId: l,
|
|
2169
2189
|
op: "remove",
|
|
2170
2190
|
payload: null,
|
|
2171
2191
|
baseVersion: i,
|
|
@@ -2175,15 +2195,15 @@ var me = class {
|
|
|
2175
2195
|
status: "queued",
|
|
2176
2196
|
batchId: s
|
|
2177
2197
|
};
|
|
2178
|
-
let { coalesced:
|
|
2179
|
-
return await this.store.putMutation(
|
|
2198
|
+
let { coalesced: y } = h;
|
|
2199
|
+
return await this.store.putMutation(y), y;
|
|
2180
2200
|
}
|
|
2181
2201
|
}
|
|
2182
2202
|
let f = {
|
|
2183
2203
|
seq: this.nextSeq(),
|
|
2184
2204
|
mutationId: We(),
|
|
2185
2205
|
collection: t,
|
|
2186
|
-
docId:
|
|
2206
|
+
docId: l,
|
|
2187
2207
|
op: r,
|
|
2188
2208
|
payload: o,
|
|
2189
2209
|
baseVersion: i,
|
|
@@ -2298,19 +2318,19 @@ var Vt = "__neetru__";
|
|
|
2298
2318
|
function Q(n) {
|
|
2299
2319
|
return typeof n == "object" && n !== null && Vt in n && typeof n[Vt] == "string";
|
|
2300
2320
|
}
|
|
2301
|
-
function
|
|
2321
|
+
function xr(n) {
|
|
2302
2322
|
return Q(n) && n.__neetru__ === "serverTimestamp";
|
|
2303
2323
|
}
|
|
2304
|
-
function
|
|
2324
|
+
function Or(n) {
|
|
2305
2325
|
return Q(n) && n.__neetru__ === "increment" && typeof n.operand == "number" && Number.isFinite(n.operand);
|
|
2306
2326
|
}
|
|
2307
|
-
function
|
|
2308
|
-
return
|
|
2327
|
+
function Lr(n, e) {
|
|
2328
|
+
return xr(n) ? Date.now() : Or(n) ? (typeof e == "number" && Number.isFinite(e) ? e : 0) + n.operand : n;
|
|
2309
2329
|
}
|
|
2310
2330
|
function K(n, e) {
|
|
2311
2331
|
let t = false, r = {};
|
|
2312
2332
|
for (let [o, i] of Object.entries(n))
|
|
2313
|
-
Q(i) ? (t = true, r[o] =
|
|
2333
|
+
Q(i) ? (t = true, r[o] = Lr(i, e?.[o])) : r[o] = i;
|
|
2314
2334
|
return t ? r : n;
|
|
2315
2335
|
}
|
|
2316
2336
|
function Be(n) {
|
|
@@ -2320,11 +2340,11 @@ function Be(n) {
|
|
|
2320
2340
|
}
|
|
2321
2341
|
|
|
2322
2342
|
// src/db/offline/sync-engine.ts
|
|
2323
|
-
var
|
|
2324
|
-
function
|
|
2343
|
+
var Ur = 8, Mr = 1e3, qr = 300 * 1e3, Ve = "truncatedCollections";
|
|
2344
|
+
function Fr(n) {
|
|
2325
2345
|
return n !== null && Be(n);
|
|
2326
2346
|
}
|
|
2327
|
-
function
|
|
2347
|
+
function jr(n) {
|
|
2328
2348
|
if (n === null) return null;
|
|
2329
2349
|
if (!Be(n)) return n;
|
|
2330
2350
|
let e = {};
|
|
@@ -2476,16 +2496,16 @@ var he = class {
|
|
|
2476
2496
|
try {
|
|
2477
2497
|
t = await this._transport.pushMutations(e);
|
|
2478
2498
|
} catch (s) {
|
|
2479
|
-
let a = s instanceof Error ? s.message : String(s),
|
|
2480
|
-
await this._retryOrDeadLetter(d, a,
|
|
2499
|
+
let a = s instanceof Error ? s.message : String(s), l = [], [d, ...u] = e;
|
|
2500
|
+
await this._retryOrDeadLetter(d, a, l);
|
|
2481
2501
|
for (let p of u)
|
|
2482
2502
|
await this._queue.requeueInflight(p.mutationId);
|
|
2483
|
-
return
|
|
2503
|
+
return l.length > 0 && this._bus.emit(l), this._refreshPendingWrites().catch(() => {
|
|
2484
2504
|
}), false;
|
|
2485
2505
|
}
|
|
2486
2506
|
let r = [];
|
|
2487
2507
|
for (let s of t.results) {
|
|
2488
|
-
let a = e.find((
|
|
2508
|
+
let a = e.find((l) => l.mutationId === s.mutationId);
|
|
2489
2509
|
a && (s.outcome === "confirmed" ? (await this._queue.markApplied(a.mutationId), await this._applySyncedDoc(
|
|
2490
2510
|
a.collection,
|
|
2491
2511
|
a.docId,
|
|
@@ -2503,8 +2523,8 @@ var he = class {
|
|
|
2503
2523
|
"partial_push: muta\xE7\xE3o n\xE3o processada no lote",
|
|
2504
2524
|
r
|
|
2505
2525
|
);
|
|
2506
|
-
for (let
|
|
2507
|
-
await this._queue.requeueInflight(
|
|
2526
|
+
for (let l of a)
|
|
2527
|
+
await this._queue.requeueInflight(l.mutationId);
|
|
2508
2528
|
}
|
|
2509
2529
|
return r.length > 0 && this._bus.emit(r), i.length === 0;
|
|
2510
2530
|
}
|
|
@@ -2526,13 +2546,13 @@ var he = class {
|
|
|
2526
2546
|
}), s.push({ type: "removed", collection: e, doc: { id: t, data: a.data } }));
|
|
2527
2547
|
return;
|
|
2528
2548
|
}
|
|
2529
|
-
let d =
|
|
2549
|
+
let d = jr(i.payload) ?? a?.data ?? {}, u = {
|
|
2530
2550
|
collection: e,
|
|
2531
2551
|
id: t,
|
|
2532
2552
|
data: i.op === "update" ? { ...a?.data ?? {}, ...d } : (
|
|
2533
2553
|
// add/set: se o payload tinha sentinels, o cache otimista (existing.data)
|
|
2534
2554
|
// é a fonte de verdade até o pull; senão usa o payload literal.
|
|
2535
|
-
|
|
2555
|
+
Fr(i.payload) ? { ...a?.data ?? {}, ...d } : d
|
|
2536
2556
|
),
|
|
2537
2557
|
meta: {
|
|
2538
2558
|
serverVersion: r,
|
|
@@ -2579,7 +2599,7 @@ var he = class {
|
|
|
2579
2599
|
deleted: false,
|
|
2580
2600
|
ownerId: null
|
|
2581
2601
|
}
|
|
2582
|
-
},
|
|
2602
|
+
}, l = this._resolver.resolve(
|
|
2583
2603
|
s,
|
|
2584
2604
|
i,
|
|
2585
2605
|
e
|
|
@@ -2593,7 +2613,7 @@ var he = class {
|
|
|
2593
2613
|
detectedAt: Date.now(),
|
|
2594
2614
|
delivered: false
|
|
2595
2615
|
};
|
|
2596
|
-
await this._store.appendConflict(
|
|
2616
|
+
await this._store.appendConflict(l);
|
|
2597
2617
|
let d = {
|
|
2598
2618
|
collection: e.collection,
|
|
2599
2619
|
id: e.docId,
|
|
@@ -2636,7 +2656,7 @@ var he = class {
|
|
|
2636
2656
|
...i.meta,
|
|
2637
2657
|
serverVersion: t.serverVersion ?? i.meta.serverVersion
|
|
2638
2658
|
}
|
|
2639
|
-
} : null,
|
|
2659
|
+
} : null, l = this._resolver.resolveRejected(
|
|
2640
2660
|
i,
|
|
2641
2661
|
s,
|
|
2642
2662
|
e,
|
|
@@ -2651,7 +2671,7 @@ var he = class {
|
|
|
2651
2671
|
detectedAt: Date.now(),
|
|
2652
2672
|
delivered: false
|
|
2653
2673
|
};
|
|
2654
|
-
await this._store.appendConflict(
|
|
2674
|
+
await this._store.appendConflict(l), t.serverData ? (await this._store.putDoc({
|
|
2655
2675
|
...i,
|
|
2656
2676
|
data: t.serverData,
|
|
2657
2677
|
meta: {
|
|
@@ -2685,7 +2705,7 @@ var he = class {
|
|
|
2685
2705
|
* pending do doc no cache + registra `lastError`/dispara `onError`.
|
|
2686
2706
|
*/
|
|
2687
2707
|
async _retryOrDeadLetter(e, t, r) {
|
|
2688
|
-
if (e.attempts + 1 <
|
|
2708
|
+
if (e.attempts + 1 < Ur) {
|
|
2689
2709
|
await this._queue.markRetry(e.mutationId, t);
|
|
2690
2710
|
return;
|
|
2691
2711
|
}
|
|
@@ -2726,7 +2746,7 @@ var he = class {
|
|
|
2726
2746
|
}
|
|
2727
2747
|
/** Backoff exponencial keyed em `attempts`, com teto `BACKOFF_CAP_MS`. */
|
|
2728
2748
|
_backoffDelayMs(e) {
|
|
2729
|
-
return Math.min(
|
|
2749
|
+
return Math.min(Mr * 2 ** (e - 1), qr);
|
|
2730
2750
|
}
|
|
2731
2751
|
// ─── FASE 2 — pull (reconciliar o cache) ─────────────────────────────────────
|
|
2732
2752
|
/**
|
|
@@ -2765,8 +2785,8 @@ var he = class {
|
|
|
2765
2785
|
);
|
|
2766
2786
|
for (let a of e) {
|
|
2767
2787
|
if (i.has(a)) continue;
|
|
2768
|
-
let
|
|
2769
|
-
for (let { id: d } of
|
|
2788
|
+
let l = await this._store.listDocs(a, {});
|
|
2789
|
+
for (let { id: d } of l.docs) {
|
|
2770
2790
|
let u = `${a}::${d}`;
|
|
2771
2791
|
if (!s.has(u)) {
|
|
2772
2792
|
let p = await this._store.getDoc(a, d);
|
|
@@ -2816,7 +2836,7 @@ var he = class {
|
|
|
2816
2836
|
continue;
|
|
2817
2837
|
}
|
|
2818
2838
|
if (i && i.meta.state === "pending") {
|
|
2819
|
-
let
|
|
2839
|
+
let l = {
|
|
2820
2840
|
collection: o.collection,
|
|
2821
2841
|
id: o.id,
|
|
2822
2842
|
data: o.data,
|
|
@@ -2833,7 +2853,7 @@ var he = class {
|
|
|
2833
2853
|
(p) => p.collection === o.collection && p.docId === o.id
|
|
2834
2854
|
);
|
|
2835
2855
|
if (u) {
|
|
2836
|
-
let p = this._resolver.resolve(i,
|
|
2856
|
+
let p = this._resolver.resolve(i, l, u);
|
|
2837
2857
|
p.conflictRecord && await this._store.appendConflict(p.conflictRecord), await this._store.putDoc({
|
|
2838
2858
|
...i,
|
|
2839
2859
|
meta: { ...i.meta, state: "conflict" }
|
|
@@ -3070,7 +3090,7 @@ var ge = class n {
|
|
|
3070
3090
|
let a = {};
|
|
3071
3091
|
for (let d of o)
|
|
3072
3092
|
a[d] = e.data[d];
|
|
3073
|
-
let
|
|
3093
|
+
let l = {
|
|
3074
3094
|
collection: r.collection,
|
|
3075
3095
|
docId: r.docId,
|
|
3076
3096
|
mutationId: r.mutationId,
|
|
@@ -3083,7 +3103,7 @@ var ge = class n {
|
|
|
3083
3103
|
return {
|
|
3084
3104
|
outcome: "server_wins",
|
|
3085
3105
|
resolvedData: i,
|
|
3086
|
-
conflictRecord:
|
|
3106
|
+
conflictRecord: l
|
|
3087
3107
|
};
|
|
3088
3108
|
}
|
|
3089
3109
|
/**
|
|
@@ -3140,7 +3160,7 @@ var ge = class n {
|
|
|
3140
3160
|
};
|
|
3141
3161
|
|
|
3142
3162
|
// src/db/offline/change-bus.ts
|
|
3143
|
-
function
|
|
3163
|
+
function $r(n) {
|
|
3144
3164
|
return `${n.collection}::${n.doc.id}`;
|
|
3145
3165
|
}
|
|
3146
3166
|
var ye = class {
|
|
@@ -3188,15 +3208,15 @@ var ye = class {
|
|
|
3188
3208
|
if (e.length === 0) return;
|
|
3189
3209
|
let t = /* @__PURE__ */ new Map();
|
|
3190
3210
|
for (let i of e)
|
|
3191
|
-
t.set(
|
|
3211
|
+
t.set($r(i), i);
|
|
3192
3212
|
let r = Array.from(t.values()), o = /* @__PURE__ */ new Map();
|
|
3193
3213
|
for (let i of r)
|
|
3194
3214
|
o.has(i.collection) || o.set(i.collection, []), o.get(i.collection).push(i);
|
|
3195
3215
|
for (let [i, s] of o) {
|
|
3196
3216
|
let a = this._collectionListeners.get(i);
|
|
3197
3217
|
if (a)
|
|
3198
|
-
for (let
|
|
3199
|
-
this._safeCall(
|
|
3218
|
+
for (let l of a)
|
|
3219
|
+
this._safeCall(l, s);
|
|
3200
3220
|
}
|
|
3201
3221
|
for (let i of this._globalListeners)
|
|
3202
3222
|
this._safeCall(i, r);
|
|
@@ -3507,25 +3527,25 @@ var ne = class {
|
|
|
3507
3527
|
|
|
3508
3528
|
// src/db/collection-ref.ts
|
|
3509
3529
|
Z();
|
|
3510
|
-
function
|
|
3530
|
+
function Wr() {
|
|
3511
3531
|
return typeof indexedDB > "u" || typeof window > "u";
|
|
3512
3532
|
}
|
|
3513
3533
|
var zt = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
3514
|
-
function
|
|
3534
|
+
function Br(n) {
|
|
3515
3535
|
if (!zt.test(n))
|
|
3516
|
-
throw new
|
|
3536
|
+
throw new b(
|
|
3517
3537
|
"db_invalid_query",
|
|
3518
3538
|
`Nome de cole\xE7\xE3o inv\xE1lido: "${n}". Deve seguir o padr\xE3o ${zt}.`
|
|
3519
3539
|
);
|
|
3520
3540
|
}
|
|
3521
3541
|
function G(n, e = "id") {
|
|
3522
3542
|
if (!n || typeof n != "string" || n.trim() === "")
|
|
3523
|
-
throw new
|
|
3543
|
+
throw new b(
|
|
3524
3544
|
"db_invalid_query",
|
|
3525
3545
|
`${e} \xE9 obrigat\xF3rio e deve ser uma string n\xE3o-vazia.`
|
|
3526
3546
|
);
|
|
3527
3547
|
}
|
|
3528
|
-
function
|
|
3548
|
+
function Vr(n) {
|
|
3529
3549
|
let e = {};
|
|
3530
3550
|
if (n?.where && (e.where = n.where.map((t) => ({
|
|
3531
3551
|
field: t.field,
|
|
@@ -3542,7 +3562,7 @@ function Br(n) {
|
|
|
3542
3562
|
}
|
|
3543
3563
|
return e;
|
|
3544
3564
|
}
|
|
3545
|
-
function
|
|
3565
|
+
function Kr(n, e) {
|
|
3546
3566
|
if (n.length < e) return null;
|
|
3547
3567
|
let t = n[n.length - 1];
|
|
3548
3568
|
return t ? btoa(JSON.stringify({ type: "startAfter", docId: t.id })) : null;
|
|
@@ -3589,10 +3609,10 @@ var Ke = class {
|
|
|
3589
3609
|
}
|
|
3590
3610
|
/** Constrói um DbListResult para a coleção com query opcional. */
|
|
3591
3611
|
async _buildListResult(e) {
|
|
3592
|
-
let t =
|
|
3612
|
+
let t = Vr(e), r = t.limit ?? 20, o = await this._store.listDocs(this._collection, t), i = await this._hasPendingWrites(), s = this._isOnline(), a = this._engine.getSyncState(), l = Kr(o.docs, r), d = await this._store.getMeta(Ve), u = Array.isArray(d) && d.includes(this._collection), p = !s || a.status === "offline" || u, f = i || a.lastSyncedAt === null || p;
|
|
3593
3613
|
return {
|
|
3594
|
-
docs: o.docs.map((
|
|
3595
|
-
nextCursor:
|
|
3614
|
+
docs: o.docs.map((h) => ({ id: h.id, data: h.data })),
|
|
3615
|
+
nextCursor: l,
|
|
3596
3616
|
fromCache: f,
|
|
3597
3617
|
stale: p,
|
|
3598
3618
|
hasPendingWrites: i,
|
|
@@ -3665,7 +3685,7 @@ var Ke = class {
|
|
|
3665
3685
|
}
|
|
3666
3686
|
async update(e, t, r) {
|
|
3667
3687
|
G(e);
|
|
3668
|
-
let o = await this._store.getDoc(this._collection, e), i = t, s = o?.meta.deleted ? void 0 : o?.data, a = K(i, s),
|
|
3688
|
+
let o = await this._store.getDoc(this._collection, e), i = t, s = o?.meta.deleted ? void 0 : o?.data, a = K(i, s), l = o?.meta.deleted ? { ...a } : { ...o?.data ?? {}, ...a }, d = await this._queue.enqueue({
|
|
3669
3689
|
collection: this._collection,
|
|
3670
3690
|
docId: e,
|
|
3671
3691
|
op: "update",
|
|
@@ -3678,7 +3698,7 @@ var Ke = class {
|
|
|
3678
3698
|
return await this._store.putDoc({
|
|
3679
3699
|
collection: this._collection,
|
|
3680
3700
|
id: e,
|
|
3681
|
-
data:
|
|
3701
|
+
data: l,
|
|
3682
3702
|
meta: {
|
|
3683
3703
|
serverVersion: o?.meta.serverVersion ?? null,
|
|
3684
3704
|
updatedAtServer: o?.meta.updatedAtServer ?? null,
|
|
@@ -3694,7 +3714,7 @@ var Ke = class {
|
|
|
3694
3714
|
}), this._bus.emit([{
|
|
3695
3715
|
type: "modified",
|
|
3696
3716
|
collection: this._collection,
|
|
3697
|
-
doc: { id: e, data:
|
|
3717
|
+
doc: { id: e, data: l }
|
|
3698
3718
|
}]), { ok: true };
|
|
3699
3719
|
}
|
|
3700
3720
|
async remove(e) {
|
|
@@ -3718,13 +3738,13 @@ var Ke = class {
|
|
|
3718
3738
|
for (let o of e) {
|
|
3719
3739
|
let i = this._collection;
|
|
3720
3740
|
if (o.kind === "add") {
|
|
3721
|
-
let s = o.data, a = K(s, void 0),
|
|
3741
|
+
let s = o.data, a = K(s, void 0), l = await this._queue.enqueue({
|
|
3722
3742
|
collection: i,
|
|
3723
3743
|
op: "add",
|
|
3724
3744
|
payload: s,
|
|
3725
3745
|
baseVersion: null,
|
|
3726
3746
|
batchId: t
|
|
3727
|
-
}), d =
|
|
3747
|
+
}), d = l.docId;
|
|
3728
3748
|
await this._store.putDoc({
|
|
3729
3749
|
collection: i,
|
|
3730
3750
|
id: d,
|
|
@@ -3734,18 +3754,18 @@ var Ke = class {
|
|
|
3734
3754
|
updatedAtServer: null,
|
|
3735
3755
|
updatedAtLocal: Date.now(),
|
|
3736
3756
|
state: "pending",
|
|
3737
|
-
pendingMutationIds: [
|
|
3757
|
+
pendingMutationIds: [l.mutationId],
|
|
3738
3758
|
deleted: false,
|
|
3739
3759
|
ownerId: null
|
|
3740
3760
|
}
|
|
3741
3761
|
}), r.push({ type: "added", collection: i, doc: { id: d, data: a } });
|
|
3742
3762
|
} else if (o.kind === "set") {
|
|
3743
|
-
let s = o.id, a = o.data,
|
|
3763
|
+
let s = o.id, a = o.data, l = await this._store.getDoc(i, s), d = K(a, void 0), u = await this._queue.enqueue({
|
|
3744
3764
|
collection: i,
|
|
3745
3765
|
docId: s,
|
|
3746
3766
|
op: "set",
|
|
3747
3767
|
payload: a,
|
|
3748
|
-
baseVersion:
|
|
3768
|
+
baseVersion: l?.meta.serverVersion ?? null,
|
|
3749
3769
|
batchId: t
|
|
3750
3770
|
});
|
|
3751
3771
|
await this._store.putDoc({
|
|
@@ -3753,8 +3773,8 @@ var Ke = class {
|
|
|
3753
3773
|
id: s,
|
|
3754
3774
|
data: d,
|
|
3755
3775
|
meta: {
|
|
3756
|
-
serverVersion:
|
|
3757
|
-
updatedAtServer:
|
|
3776
|
+
serverVersion: l?.meta.serverVersion ?? null,
|
|
3777
|
+
updatedAtServer: l?.meta.updatedAtServer ?? null,
|
|
3758
3778
|
updatedAtLocal: Date.now(),
|
|
3759
3779
|
state: "pending",
|
|
3760
3780
|
pendingMutationIds: [u.mutationId],
|
|
@@ -3762,17 +3782,17 @@ var Ke = class {
|
|
|
3762
3782
|
ownerId: null
|
|
3763
3783
|
}
|
|
3764
3784
|
}), r.push({
|
|
3765
|
-
type:
|
|
3785
|
+
type: l && !l.meta.deleted ? "modified" : "added",
|
|
3766
3786
|
collection: i,
|
|
3767
3787
|
doc: { id: s, data: d }
|
|
3768
3788
|
});
|
|
3769
3789
|
} else if (o.kind === "update") {
|
|
3770
|
-
let s = o.id, a = o.data,
|
|
3790
|
+
let s = o.id, a = o.data, l = await this._store.getDoc(i, s), d = l?.meta.deleted ? void 0 : l?.data, u = K(a, d), p = { ...l?.data ?? {}, ...u }, f = await this._queue.enqueue({
|
|
3771
3791
|
collection: i,
|
|
3772
3792
|
docId: s,
|
|
3773
3793
|
op: "update",
|
|
3774
3794
|
payload: a,
|
|
3775
|
-
baseVersion:
|
|
3795
|
+
baseVersion: l?.meta.serverVersion ?? null,
|
|
3776
3796
|
batchId: t,
|
|
3777
3797
|
// bug_0273e4dd: propaga merge-upsert (writeBatch.set(merge) cria-se-ausente).
|
|
3778
3798
|
upsert: o.upsert
|
|
@@ -3782,16 +3802,16 @@ var Ke = class {
|
|
|
3782
3802
|
id: s,
|
|
3783
3803
|
data: p,
|
|
3784
3804
|
meta: {
|
|
3785
|
-
serverVersion:
|
|
3786
|
-
updatedAtServer:
|
|
3805
|
+
serverVersion: l?.meta.serverVersion ?? null,
|
|
3806
|
+
updatedAtServer: l?.meta.updatedAtServer ?? null,
|
|
3787
3807
|
updatedAtLocal: Date.now(),
|
|
3788
3808
|
state: "pending",
|
|
3789
3809
|
pendingMutationIds: [
|
|
3790
|
-
...
|
|
3810
|
+
...l?.meta.pendingMutationIds ?? [],
|
|
3791
3811
|
f.mutationId
|
|
3792
3812
|
],
|
|
3793
3813
|
deleted: false,
|
|
3794
|
-
ownerId:
|
|
3814
|
+
ownerId: l?.meta.ownerId ?? null
|
|
3795
3815
|
}
|
|
3796
3816
|
}), r.push({ type: "modified", collection: i, doc: { id: s, data: p } });
|
|
3797
3817
|
} else if (o.kind === "remove") {
|
|
@@ -3822,11 +3842,11 @@ var Ke = class {
|
|
|
3822
3842
|
});
|
|
3823
3843
|
let r = this._bus.subscribe(this._collection, async (s) => {
|
|
3824
3844
|
try {
|
|
3825
|
-
let a = await this._buildListResult(e),
|
|
3845
|
+
let a = await this._buildListResult(e), l = s.map((d) => ({
|
|
3826
3846
|
type: d.type,
|
|
3827
3847
|
doc: { id: d.doc.id, data: d.doc.data }
|
|
3828
3848
|
}));
|
|
3829
|
-
t({ ...a, changes:
|
|
3849
|
+
t({ ...a, changes: l });
|
|
3830
3850
|
} catch {
|
|
3831
3851
|
}
|
|
3832
3852
|
}), o = this._engine.onSyncStateChange(async () => {
|
|
@@ -3840,15 +3860,15 @@ var Ke = class {
|
|
|
3840
3860
|
this._collection,
|
|
3841
3861
|
async (s, a) => {
|
|
3842
3862
|
if (!a)
|
|
3843
|
-
for (let
|
|
3844
|
-
|
|
3863
|
+
for (let l of s)
|
|
3864
|
+
l.type === "removed" || l.data === null ? (await this._store.deleteDoc(this._collection, l.docId), this._bus.emit([{
|
|
3845
3865
|
type: "removed",
|
|
3846
3866
|
collection: this._collection,
|
|
3847
|
-
doc: { id:
|
|
3867
|
+
doc: { id: l.docId, data: {} }
|
|
3848
3868
|
}])) : (await this._store.putDoc({
|
|
3849
3869
|
collection: this._collection,
|
|
3850
|
-
id:
|
|
3851
|
-
data:
|
|
3870
|
+
id: l.docId,
|
|
3871
|
+
data: l.data,
|
|
3852
3872
|
meta: {
|
|
3853
3873
|
serverVersion: `rt_${Date.now()}`,
|
|
3854
3874
|
updatedAtServer: Date.now(),
|
|
@@ -3859,9 +3879,9 @@ var Ke = class {
|
|
|
3859
3879
|
ownerId: null
|
|
3860
3880
|
}
|
|
3861
3881
|
}), this._bus.emit([{
|
|
3862
|
-
type:
|
|
3882
|
+
type: l.type,
|
|
3863
3883
|
collection: this._collection,
|
|
3864
|
-
doc: { id:
|
|
3884
|
+
doc: { id: l.docId, data: l.data }
|
|
3865
3885
|
}]));
|
|
3866
3886
|
}
|
|
3867
3887
|
)), () => {
|
|
@@ -3896,14 +3916,14 @@ var Ke = class {
|
|
|
3896
3916
|
onSnapshot(r) {
|
|
3897
3917
|
t._buildGetResult(e).then((s) => r(s)).catch(() => r(null));
|
|
3898
3918
|
let o = t._bus.subscribe(t._collection, async (s) => {
|
|
3899
|
-
let a = s.find((
|
|
3919
|
+
let a = s.find((l) => l.doc.id === e);
|
|
3900
3920
|
if (a)
|
|
3901
3921
|
try {
|
|
3902
3922
|
if (a.type === "removed")
|
|
3903
3923
|
r(null);
|
|
3904
3924
|
else {
|
|
3905
|
-
let
|
|
3906
|
-
r(
|
|
3925
|
+
let l = await t._buildGetResult(e);
|
|
3926
|
+
r(l);
|
|
3907
3927
|
}
|
|
3908
3928
|
} catch {
|
|
3909
3929
|
r(null);
|
|
@@ -3932,7 +3952,7 @@ var Ke = class {
|
|
|
3932
3952
|
this._store = e.store, this._queue = e.queue, this._bus = e.bus, this._engine = e.engine, this._connectivity = e.connectivity;
|
|
3933
3953
|
}
|
|
3934
3954
|
collection(e) {
|
|
3935
|
-
return
|
|
3955
|
+
return Br(e), new Ke(
|
|
3936
3956
|
e,
|
|
3937
3957
|
this._store,
|
|
3938
3958
|
this._queue,
|
|
@@ -3962,7 +3982,7 @@ var Ke = class {
|
|
|
3962
3982
|
}
|
|
3963
3983
|
};
|
|
3964
3984
|
async function Ht(n) {
|
|
3965
|
-
let e =
|
|
3985
|
+
let e = Wr() ? new fe() : new pe(n.dbName);
|
|
3966
3986
|
await e.open();
|
|
3967
3987
|
let t = new me(e), r = new ge(), o = new ye(), i = new _e({
|
|
3968
3988
|
// Se startOnline=false, injeta um navigator falso
|
|
@@ -3971,7 +3991,7 @@ async function Ht(n) {
|
|
|
3971
3991
|
// Fake tab coordinator para single-tab mode (sempre líder)
|
|
3972
3992
|
{
|
|
3973
3993
|
isLeader: () => true,
|
|
3974
|
-
onRoleChange: (
|
|
3994
|
+
onRoleChange: (l) => () => {
|
|
3975
3995
|
}
|
|
3976
3996
|
}
|
|
3977
3997
|
) : new ne({
|
|
@@ -3997,9 +4017,9 @@ async function Ht(n) {
|
|
|
3997
4017
|
}
|
|
3998
4018
|
|
|
3999
4019
|
// src/db/realtime/realtime-client.ts
|
|
4000
|
-
var
|
|
4020
|
+
var zr = 0;
|
|
4001
4021
|
function Qt() {
|
|
4002
|
-
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++
|
|
4022
|
+
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++zr}-${Math.random().toString(36).slice(2)}`;
|
|
4003
4023
|
}
|
|
4004
4024
|
var be = class {
|
|
4005
4025
|
// ── configuração ──────────────────────────────────────────────────────────
|
|
@@ -4039,7 +4059,7 @@ var be = class {
|
|
|
4039
4059
|
_pendingFrames = [];
|
|
4040
4060
|
// ── construtor ────────────────────────────────────────────────────────────
|
|
4041
4061
|
constructor(e) {
|
|
4042
|
-
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ??
|
|
4062
|
+
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ?? Hr, 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();
|
|
4043
4063
|
}
|
|
4044
4064
|
// ── API pública ───────────────────────────────────────────────────────────
|
|
4045
4065
|
/**
|
|
@@ -4318,7 +4338,7 @@ var be = class {
|
|
|
4318
4338
|
_detachHandlers(e) {
|
|
4319
4339
|
e.onopen = null, e.onmessage = null, e.onclose = null, e.onerror = null;
|
|
4320
4340
|
}
|
|
4321
|
-
},
|
|
4341
|
+
}, Hr = (n) => {
|
|
4322
4342
|
if (typeof WebSocket > "u")
|
|
4323
4343
|
throw new Error(
|
|
4324
4344
|
"[NeetruRealtimeClient] WebSocket n\xE3o dispon\xEDvel neste ambiente. Injete uma implementa\xE7\xE3o via `webSocketFactory` nas op\xE7\xF5es."
|
|
@@ -4327,15 +4347,15 @@ var be = class {
|
|
|
4327
4347
|
};
|
|
4328
4348
|
|
|
4329
4349
|
// src/db/client-db.ts
|
|
4330
|
-
var
|
|
4331
|
-
function
|
|
4332
|
-
return e._transport ? e._transport : n === "firestore" && e.firestoreTransport ? e.firestoreTransport : n === "nosql-vm" && e.realtimeGatewayUrl ?
|
|
4350
|
+
var so = (n) => `/api/sdk/v1/datastore/${encodeURIComponent(n)}`, we = (n, e) => `/api/sdk/v1/datastore/${encodeURIComponent(n)}/${encodeURIComponent(e)}`, an = 200;
|
|
4351
|
+
function ao(n, e, t) {
|
|
4352
|
+
return e._transport ? e._transport : n === "firestore" && e.firestoreTransport ? e.firestoreTransport : n === "nosql-vm" && e.realtimeGatewayUrl ? co(e.realtimeGatewayUrl, t, e) : ln(t);
|
|
4333
4353
|
}
|
|
4334
|
-
function
|
|
4354
|
+
function ln(n) {
|
|
4335
4355
|
return {
|
|
4336
4356
|
async pushMutations(e) {
|
|
4337
4357
|
if (!n)
|
|
4338
|
-
throw new
|
|
4358
|
+
throw new b(
|
|
4339
4359
|
"db_unavailable",
|
|
4340
4360
|
"[RestSyncTransport] config n\xE3o dispon\xEDvel \u2014 n\xE3o \xE9 poss\xEDvel enviar ao Core. Inicialize o transporte via createNeetruDb."
|
|
4341
4361
|
);
|
|
@@ -4371,15 +4391,15 @@ function cn(n) {
|
|
|
4371
4391
|
retries: 2,
|
|
4372
4392
|
headers: i
|
|
4373
4393
|
});
|
|
4374
|
-
let
|
|
4394
|
+
let l = a;
|
|
4375
4395
|
r.push({
|
|
4376
4396
|
mutationId: s.mutationId,
|
|
4377
4397
|
outcome: "confirmed",
|
|
4378
|
-
serverVersion:
|
|
4398
|
+
serverVersion: l?.serverVersion ?? l?.id ?? `rest_${Date.now()}`,
|
|
4379
4399
|
serverTimestamp: Date.now()
|
|
4380
4400
|
});
|
|
4381
4401
|
} catch (a) {
|
|
4382
|
-
let
|
|
4402
|
+
let l = a instanceof Error ? a.message : String(a), d = a?.code, u = a?.status;
|
|
4383
4403
|
if (d === "forbidden" || d === "unauthorized" || d === "not_found" || d === "conflict" || d === "validation_failed" || typeof u == "number" && u >= 400 && u < 500 && u !== 408 && u !== 429) {
|
|
4384
4404
|
let f = d === "forbidden" || d === "unauthorized" ? "rejected_permission" : "rejected_validation";
|
|
4385
4405
|
r.push({
|
|
@@ -4392,7 +4412,7 @@ function cn(n) {
|
|
|
4392
4412
|
continue;
|
|
4393
4413
|
}
|
|
4394
4414
|
if (r.length === 0)
|
|
4395
|
-
throw new
|
|
4415
|
+
throw new b("db_unavailable", `pushMutations falhou: ${l}`);
|
|
4396
4416
|
break;
|
|
4397
4417
|
}
|
|
4398
4418
|
return { results: r };
|
|
@@ -4404,12 +4424,12 @@ function cn(n) {
|
|
|
4404
4424
|
if (!n)
|
|
4405
4425
|
return { docs: [], newWatermark: Date.now() };
|
|
4406
4426
|
let { httpRequest: t } = await Promise.resolve().then(() => (M(), Y)), r = n.tenantId ?? n.productId, o = r ? { "x-neetru-tenant": r } : void 0, i = Date.now(), s = [], a = [];
|
|
4407
|
-
for (let
|
|
4427
|
+
for (let l of e) {
|
|
4408
4428
|
let d;
|
|
4409
4429
|
try {
|
|
4410
4430
|
d = await t(n, {
|
|
4411
4431
|
method: "GET",
|
|
4412
|
-
path:
|
|
4432
|
+
path: so(l),
|
|
4413
4433
|
requireAuth: !0,
|
|
4414
4434
|
retries: 2,
|
|
4415
4435
|
headers: o,
|
|
@@ -4417,22 +4437,22 @@ function cn(n) {
|
|
|
4417
4437
|
// TRUNCADAS — reportadas em `truncatedCollections` p/ o SyncEngine
|
|
4418
4438
|
// (a) NÃO rodar deleção-por-ausência e (b) sinalizar
|
|
4419
4439
|
// `DbListResult.truncated`. Paginação por cursor é tarefa Core (gated).
|
|
4420
|
-
query: { limit:
|
|
4440
|
+
query: { limit: an }
|
|
4421
4441
|
});
|
|
4422
4442
|
} catch (f) {
|
|
4423
|
-
let
|
|
4424
|
-
throw new
|
|
4443
|
+
let h = f instanceof Error ? f.message : String(f);
|
|
4444
|
+
throw new b(
|
|
4425
4445
|
"db_unavailable",
|
|
4426
|
-
`[RestSyncTransport] fullResync falhou na cole\xE7\xE3o "${
|
|
4446
|
+
`[RestSyncTransport] fullResync falhou na cole\xE7\xE3o "${l}": ${h}`
|
|
4427
4447
|
);
|
|
4428
4448
|
}
|
|
4429
4449
|
let u = d, p = Array.isArray(u?.items) ? u.items : [];
|
|
4430
|
-
p.length >=
|
|
4450
|
+
p.length >= an && a.push(l);
|
|
4431
4451
|
for (let f of p) {
|
|
4432
4452
|
if (!f || typeof f != "object") continue;
|
|
4433
|
-
let
|
|
4434
|
-
if (!
|
|
4435
|
-
let { id: S, ...x } =
|
|
4453
|
+
let h = f, y = typeof h.id == "string" ? h.id : null;
|
|
4454
|
+
if (!y) continue;
|
|
4455
|
+
let { id: S, ...x } = h, T = i, P = x._updatedAt;
|
|
4436
4456
|
if (typeof P == "number")
|
|
4437
4457
|
T = P;
|
|
4438
4458
|
else if (P !== null && typeof P == "object" && typeof P._seconds == "number")
|
|
@@ -4441,10 +4461,10 @@ function cn(n) {
|
|
|
4441
4461
|
let m = Date.parse(P);
|
|
4442
4462
|
Number.isNaN(m) || (T = m);
|
|
4443
4463
|
}
|
|
4444
|
-
let q = `rest_${
|
|
4464
|
+
let q = `rest_${y}_${T}`;
|
|
4445
4465
|
s.push({
|
|
4446
|
-
collection:
|
|
4447
|
-
id:
|
|
4466
|
+
collection: l,
|
|
4467
|
+
id: y,
|
|
4448
4468
|
data: x,
|
|
4449
4469
|
serverVersion: q,
|
|
4450
4470
|
serverTimestamp: T,
|
|
@@ -4456,10 +4476,10 @@ function cn(n) {
|
|
|
4456
4476
|
}
|
|
4457
4477
|
};
|
|
4458
4478
|
}
|
|
4459
|
-
function
|
|
4460
|
-
let r =
|
|
4479
|
+
function co(n, e, t) {
|
|
4480
|
+
let r = ln(e), o = new be({
|
|
4461
4481
|
gatewayUrl: n,
|
|
4462
|
-
ticketProvider:
|
|
4482
|
+
ticketProvider: lo(e, t),
|
|
4463
4483
|
dbId: t.dbId,
|
|
4464
4484
|
webSocketFactory: t._wsFactory
|
|
4465
4485
|
});
|
|
@@ -4471,17 +4491,17 @@ function io(n, e, t) {
|
|
|
4471
4491
|
// quando o engine é nosql-vm. Registra a subscription no NeetruRealtimeClient
|
|
4472
4492
|
// e traduz os frames inbound para o contrato de `onChange`.
|
|
4473
4493
|
subscribeCollection(i, s) {
|
|
4474
|
-
let a = o.subscribe(i, {}, (
|
|
4475
|
-
if (
|
|
4494
|
+
let a = o.subscribe(i, {}, (l) => {
|
|
4495
|
+
if (l.op === "resync") {
|
|
4476
4496
|
s([], true);
|
|
4477
4497
|
return;
|
|
4478
4498
|
}
|
|
4479
|
-
if (
|
|
4499
|
+
if (l.op === "stale") {
|
|
4480
4500
|
s([], true);
|
|
4481
4501
|
return;
|
|
4482
4502
|
}
|
|
4483
|
-
if (
|
|
4484
|
-
let d =
|
|
4503
|
+
if (l.op === "delta" && l.changes) {
|
|
4504
|
+
let d = l.changes.map((u) => ({
|
|
4485
4505
|
type: u.type === "insert" ? "added" : u.type === "delete" ? "removed" : "modified",
|
|
4486
4506
|
docId: u.documentId,
|
|
4487
4507
|
data: u.data ?? null
|
|
@@ -4495,7 +4515,7 @@ function io(n, e, t) {
|
|
|
4495
4515
|
}
|
|
4496
4516
|
};
|
|
4497
4517
|
}
|
|
4498
|
-
function
|
|
4518
|
+
function lo(n, e) {
|
|
4499
4519
|
return async () => {
|
|
4500
4520
|
let { httpRequest: t } = await Promise.resolve().then(() => (M(), Y));
|
|
4501
4521
|
return await t(n, {
|
|
@@ -4510,20 +4530,20 @@ function so(n, e) {
|
|
|
4510
4530
|
});
|
|
4511
4531
|
};
|
|
4512
4532
|
}
|
|
4513
|
-
var
|
|
4514
|
-
function
|
|
4515
|
-
|
|
4533
|
+
var cn = false;
|
|
4534
|
+
function uo(n, e) {
|
|
4535
|
+
cn || e.dbId && n.env !== "prod" && (typeof window > "u" || typeof console > "u" || typeof console.warn != "function" || (cn = true, console.warn(
|
|
4516
4536
|
'[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.'
|
|
4517
4537
|
)));
|
|
4518
4538
|
}
|
|
4519
|
-
function
|
|
4520
|
-
|
|
4539
|
+
function dn(n, e = {}) {
|
|
4540
|
+
uo(n, e);
|
|
4521
4541
|
let t;
|
|
4522
4542
|
e.transport !== void 0 ? t = e.transport : e.engine !== void 0 ? (console.warn(
|
|
4523
4543
|
'[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).'
|
|
4524
4544
|
), t = e.engine) : t = "rest";
|
|
4525
|
-
let r =
|
|
4526
|
-
function
|
|
4545
|
+
let r = ao(t, e, n), o = e.dbId ?? "default", i = e.dbName ?? `neetru-db__${n.productId ?? "sdk"}__${o}__${n.env}`, s = null, a = null;
|
|
4546
|
+
function l() {
|
|
4527
4547
|
return s || (s = Ht({
|
|
4528
4548
|
dbName: i,
|
|
4529
4549
|
transport: r,
|
|
@@ -4532,15 +4552,15 @@ function ln(n, e = {}) {
|
|
|
4532
4552
|
}
|
|
4533
4553
|
return {
|
|
4534
4554
|
collection(d) {
|
|
4535
|
-
return a ? a.collection(d) :
|
|
4555
|
+
return a ? a.collection(d) : po(d, l);
|
|
4536
4556
|
},
|
|
4537
4557
|
async sql(d, u) {
|
|
4538
4558
|
if (n.env === "dev")
|
|
4539
|
-
throw new
|
|
4559
|
+
throw new b(
|
|
4540
4560
|
"db_unavailable",
|
|
4541
4561
|
"[SDK] db.sql() n\xE3o dispon\xEDvel em NEETRU_ENV=dev. Use `neetru dev` para subir o container Postgres local."
|
|
4542
4562
|
);
|
|
4543
|
-
return (await Promise.resolve().then(() => (
|
|
4563
|
+
return (await Promise.resolve().then(() => (sn(), on))).createSqlClientFromConfig(n, d, u);
|
|
4544
4564
|
},
|
|
4545
4565
|
get syncState() {
|
|
4546
4566
|
return a?.syncState ?? {
|
|
@@ -4553,25 +4573,25 @@ function ln(n, e = {}) {
|
|
|
4553
4573
|
onSyncStateChanged(d) {
|
|
4554
4574
|
if (a) return a.onSyncStateChanged(d);
|
|
4555
4575
|
let u = null, p = false;
|
|
4556
|
-
return
|
|
4576
|
+
return l().then((f) => {
|
|
4557
4577
|
p || (u = f.onSyncStateChanged(d));
|
|
4558
4578
|
}), () => {
|
|
4559
4579
|
p = true, u?.();
|
|
4560
4580
|
};
|
|
4561
4581
|
},
|
|
4562
4582
|
async flush() {
|
|
4563
|
-
return (await
|
|
4583
|
+
return (await l()).flush();
|
|
4564
4584
|
},
|
|
4565
4585
|
async clearCache() {
|
|
4566
|
-
return (await
|
|
4586
|
+
return (await l()).clearCache();
|
|
4567
4587
|
},
|
|
4568
4588
|
async getConflicts() {
|
|
4569
|
-
return (await
|
|
4589
|
+
return (await l()).getConflicts();
|
|
4570
4590
|
},
|
|
4571
4591
|
onError(d) {
|
|
4572
4592
|
if (a) return a.onError(d);
|
|
4573
4593
|
let u = null, p = false;
|
|
4574
|
-
return
|
|
4594
|
+
return l().then((f) => {
|
|
4575
4595
|
p || (u = f.onError(d));
|
|
4576
4596
|
}), () => {
|
|
4577
4597
|
p = true, u?.();
|
|
@@ -4579,7 +4599,7 @@ function ln(n, e = {}) {
|
|
|
4579
4599
|
}
|
|
4580
4600
|
};
|
|
4581
4601
|
}
|
|
4582
|
-
function
|
|
4602
|
+
function po(n, e) {
|
|
4583
4603
|
async function t() {
|
|
4584
4604
|
return (await e()).collection(n);
|
|
4585
4605
|
}
|
|
@@ -4663,20 +4683,20 @@ M();
|
|
|
4663
4683
|
function Ye(n, e) {
|
|
4664
4684
|
let t = n?.accessToken || n?.idToken;
|
|
4665
4685
|
if (!t || typeof t != "string")
|
|
4666
|
-
throw new
|
|
4686
|
+
throw new c(
|
|
4667
4687
|
"validation_failed",
|
|
4668
4688
|
`checkout.${e} requer o access_token OU o id_token OIDC do usu\xE1rio final (passe \`accessToken\` ou \`idToken\`). A chave de API do SDK (nrt_*) N\xC3O \xE9 aceita pelo endpoint de checkout \u2014 ele autentica a identidade do cliente que est\xE1 assinando (Bearer access_token/id_token OIDC ou cookie de sess\xE3o). No padr\xE3o BFF/cookie, passe o \`idToken\` que seu servidor guardou no cookie httpOnly.`
|
|
4669
4689
|
);
|
|
4670
4690
|
return { requireAuth: false, headers: { authorization: `Bearer ${t}` } };
|
|
4671
4691
|
}
|
|
4672
|
-
function
|
|
4692
|
+
function fo(n) {
|
|
4673
4693
|
if (!n || typeof n != "object")
|
|
4674
|
-
throw new
|
|
4694
|
+
throw new c("invalid_response", "checkout.start response is not an object");
|
|
4675
4695
|
let e = n;
|
|
4676
4696
|
if (typeof e.intentId != "string" || !e.intentId)
|
|
4677
|
-
throw new
|
|
4697
|
+
throw new c("invalid_response", "checkout.start response missing intentId");
|
|
4678
4698
|
if (typeof e.redirectUrl != "string" || !e.redirectUrl)
|
|
4679
|
-
throw new
|
|
4699
|
+
throw new c("invalid_response", "checkout.start response missing redirectUrl");
|
|
4680
4700
|
return {
|
|
4681
4701
|
intentId: e.intentId,
|
|
4682
4702
|
redirectUrl: e.redirectUrl,
|
|
@@ -4685,14 +4705,14 @@ function lo(n) {
|
|
|
4685
4705
|
requiresKyc: e.requiresKyc === true
|
|
4686
4706
|
};
|
|
4687
4707
|
}
|
|
4688
|
-
function
|
|
4708
|
+
function mo(n) {
|
|
4689
4709
|
if (!n || typeof n != "object")
|
|
4690
|
-
throw new
|
|
4710
|
+
throw new c("invalid_response", "checkout.get response is not an object");
|
|
4691
4711
|
let e = n, t = e.intent;
|
|
4692
4712
|
if (!t || typeof t != "object")
|
|
4693
|
-
throw new
|
|
4713
|
+
throw new c("invalid_response", "checkout.get response missing intent");
|
|
4694
4714
|
if (typeof t.intentId != "string")
|
|
4695
|
-
throw new
|
|
4715
|
+
throw new c("invalid_response", "checkout.get response missing intentId");
|
|
4696
4716
|
return {
|
|
4697
4717
|
intentId: t.intentId,
|
|
4698
4718
|
uid: t.uid ?? "",
|
|
@@ -4707,28 +4727,28 @@ function uo(n) {
|
|
|
4707
4727
|
isStale: e.isStale === true
|
|
4708
4728
|
};
|
|
4709
4729
|
}
|
|
4710
|
-
function
|
|
4730
|
+
function ho() {
|
|
4711
4731
|
try {
|
|
4712
4732
|
return typeof globalThis < "u" && typeof globalThis.window < "u" && typeof globalThis.location < "u" && typeof globalThis.location.assign == "function";
|
|
4713
4733
|
} catch {
|
|
4714
4734
|
return false;
|
|
4715
4735
|
}
|
|
4716
4736
|
}
|
|
4717
|
-
function
|
|
4737
|
+
function go(n) {
|
|
4718
4738
|
try {
|
|
4719
4739
|
globalThis.location.assign(n);
|
|
4720
4740
|
} catch {
|
|
4721
4741
|
}
|
|
4722
4742
|
}
|
|
4723
|
-
function
|
|
4743
|
+
function yo(n) {
|
|
4724
4744
|
return {
|
|
4725
4745
|
async start(e) {
|
|
4726
4746
|
if (!e?.productId)
|
|
4727
|
-
throw new
|
|
4747
|
+
throw new c("validation_failed", "checkout.start: productId is required");
|
|
4728
4748
|
if (!e?.planId)
|
|
4729
|
-
throw new
|
|
4749
|
+
throw new c("validation_failed", "checkout.start: planId is required");
|
|
4730
4750
|
if (!e?.callbackUrl)
|
|
4731
|
-
throw new
|
|
4751
|
+
throw new c("validation_failed", "checkout.start: callbackUrl is required");
|
|
4732
4752
|
let t = {
|
|
4733
4753
|
productId: e.productId,
|
|
4734
4754
|
planId: e.planId,
|
|
@@ -4745,12 +4765,12 @@ function mo(n) {
|
|
|
4745
4765
|
requireAuth: r,
|
|
4746
4766
|
headers: o,
|
|
4747
4767
|
idempotencyKey: true
|
|
4748
|
-
}), s =
|
|
4749
|
-
return e.autoRedirect !== false &&
|
|
4768
|
+
}), s = fo(i);
|
|
4769
|
+
return e.autoRedirect !== false && ho() && go(s.redirectUrl), s;
|
|
4750
4770
|
},
|
|
4751
4771
|
async get(e, t) {
|
|
4752
4772
|
if (!e || typeof e != "string")
|
|
4753
|
-
throw new
|
|
4773
|
+
throw new c("validation_failed", "checkout.get: intentId is required");
|
|
4754
4774
|
let { requireAuth: r, headers: o } = Ye(
|
|
4755
4775
|
{ accessToken: t?.accessToken, idToken: t?.idToken },
|
|
4756
4776
|
"get"
|
|
@@ -4760,11 +4780,11 @@ function mo(n) {
|
|
|
4760
4780
|
requireAuth: r,
|
|
4761
4781
|
headers: o
|
|
4762
4782
|
});
|
|
4763
|
-
return
|
|
4783
|
+
return mo(i);
|
|
4764
4784
|
},
|
|
4765
4785
|
async cancel(e, t) {
|
|
4766
4786
|
if (!e || typeof e != "string")
|
|
4767
|
-
throw new
|
|
4787
|
+
throw new c("validation_failed", "checkout.cancel: intentId is required");
|
|
4768
4788
|
let { requireAuth: r, headers: o } = Ye(
|
|
4769
4789
|
{ accessToken: t?.accessToken, idToken: t?.idToken },
|
|
4770
4790
|
"cancel"
|
|
@@ -4785,11 +4805,11 @@ var Ze = class {
|
|
|
4785
4805
|
intents = /* @__PURE__ */ new Map();
|
|
4786
4806
|
async start(e) {
|
|
4787
4807
|
if (!e?.productId)
|
|
4788
|
-
throw new
|
|
4808
|
+
throw new c("validation_failed", "checkout.start: productId is required");
|
|
4789
4809
|
if (!e?.planId)
|
|
4790
|
-
throw new
|
|
4810
|
+
throw new c("validation_failed", "checkout.start: planId is required");
|
|
4791
4811
|
if (!e?.callbackUrl)
|
|
4792
|
-
throw new
|
|
4812
|
+
throw new c("validation_failed", "checkout.start: callbackUrl is required");
|
|
4793
4813
|
let t = `chk_mock_${Math.random().toString(36).slice(2, 10)}`, r = new Date(Date.now() + 900 * 1e3).toISOString(), o = `https://localhost:9003/portal/checkout/${t}`;
|
|
4794
4814
|
return this.intents.set(t, {
|
|
4795
4815
|
intentId: t,
|
|
@@ -4813,25 +4833,25 @@ var Ze = class {
|
|
|
4813
4833
|
async get(e, t) {
|
|
4814
4834
|
let r = this.intents.get(e);
|
|
4815
4835
|
if (!r)
|
|
4816
|
-
throw new
|
|
4836
|
+
throw new c("not_found", `Mock intent ${e} not found`);
|
|
4817
4837
|
return { ...r };
|
|
4818
4838
|
}
|
|
4819
4839
|
async cancel(e, t) {
|
|
4820
4840
|
let r = this.intents.get(e);
|
|
4821
4841
|
if (!r)
|
|
4822
|
-
throw new
|
|
4842
|
+
throw new c("not_found", `Mock intent ${e} not found`);
|
|
4823
4843
|
let o = r.status === "cancelled";
|
|
4824
4844
|
return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled: o };
|
|
4825
4845
|
}
|
|
4826
4846
|
};
|
|
4827
|
-
function
|
|
4828
|
-
return n.env === "dev" ? new Ze() :
|
|
4847
|
+
function un(n) {
|
|
4848
|
+
return n.env === "dev" ? new Ze() : yo(n);
|
|
4829
4849
|
}
|
|
4830
4850
|
|
|
4831
4851
|
// src/webhooks.ts
|
|
4832
4852
|
I();
|
|
4833
4853
|
M();
|
|
4834
|
-
var
|
|
4854
|
+
var fn = [
|
|
4835
4855
|
"subscription.activated",
|
|
4836
4856
|
"subscription.cancelled",
|
|
4837
4857
|
"subscription.payment_failed",
|
|
@@ -4841,17 +4861,17 @@ var pn = [
|
|
|
4841
4861
|
"account.reactivated",
|
|
4842
4862
|
"support.ticket_replied"
|
|
4843
4863
|
];
|
|
4844
|
-
function
|
|
4864
|
+
function pn(n) {
|
|
4845
4865
|
if (!n || typeof n != "object")
|
|
4846
|
-
throw new
|
|
4866
|
+
throw new c("invalid_response", "Webhook response is not an object");
|
|
4847
4867
|
let e = n;
|
|
4848
4868
|
if (typeof e.id != "string")
|
|
4849
|
-
throw new
|
|
4869
|
+
throw new c("invalid_response", "Webhook missing id");
|
|
4850
4870
|
return {
|
|
4851
4871
|
id: e.id,
|
|
4852
4872
|
url: typeof e.url == "string" ? e.url : "",
|
|
4853
4873
|
events: Array.isArray(e.events) ? e.events.filter(
|
|
4854
|
-
(t) =>
|
|
4874
|
+
(t) => fn.includes(t)
|
|
4855
4875
|
) : [],
|
|
4856
4876
|
hasSecret: e.hasSecret === true,
|
|
4857
4877
|
status: e.status === "active" || e.status === "degraded" || e.status === "disabled" ? e.status : "active",
|
|
@@ -4860,23 +4880,23 @@ function un(n) {
|
|
|
4860
4880
|
createdAt: typeof e.createdAt == "string" ? e.createdAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
4861
4881
|
};
|
|
4862
4882
|
}
|
|
4863
|
-
function
|
|
4883
|
+
function mn(n) {
|
|
4864
4884
|
if (!n.url || typeof n.url != "string")
|
|
4865
|
-
throw new
|
|
4885
|
+
throw new c("validation_failed", "url \xE9 obrigat\xF3ria");
|
|
4866
4886
|
try {
|
|
4867
4887
|
let e = new URL(n.url);
|
|
4868
4888
|
if (e.protocol !== "https:" && e.protocol !== "http:")
|
|
4869
4889
|
throw new Error("invalid protocol");
|
|
4870
4890
|
} catch {
|
|
4871
|
-
throw new
|
|
4891
|
+
throw new c("validation_failed", `url inv\xE1lida: ${n.url}`);
|
|
4872
4892
|
}
|
|
4873
4893
|
if (!Array.isArray(n.events) || n.events.length === 0)
|
|
4874
|
-
throw new
|
|
4894
|
+
throw new c("validation_failed", "events deve ter pelo menos 1 evento");
|
|
4875
4895
|
for (let e of n.events)
|
|
4876
|
-
if (!
|
|
4877
|
-
throw new
|
|
4896
|
+
if (!fn.includes(e))
|
|
4897
|
+
throw new c("validation_failed", `evento desconhecido: ${e}`);
|
|
4878
4898
|
if (n.secret !== void 0 && n.secret.length < 16)
|
|
4879
|
-
throw new
|
|
4899
|
+
throw new c("validation_failed", "secret deve ter \u226516 chars (recomendado 32+)");
|
|
4880
4900
|
}
|
|
4881
4901
|
function ke(n, ...e) {
|
|
4882
4902
|
for (let t of e)
|
|
@@ -4884,15 +4904,15 @@ function ke(n, ...e) {
|
|
|
4884
4904
|
return N("productId", t), t;
|
|
4885
4905
|
if (n.productId)
|
|
4886
4906
|
return N("productId", n.productId), n.productId;
|
|
4887
|
-
throw new
|
|
4907
|
+
throw new c(
|
|
4888
4908
|
"validation_failed",
|
|
4889
4909
|
"productId required (pass to options/input or set on createNeetruClient)"
|
|
4890
4910
|
);
|
|
4891
4911
|
}
|
|
4892
|
-
function
|
|
4912
|
+
function hn(n) {
|
|
4893
4913
|
return {
|
|
4894
4914
|
async register(e) {
|
|
4895
|
-
|
|
4915
|
+
mn(e);
|
|
4896
4916
|
let t = ke(n, e.productId), r = await v(n, {
|
|
4897
4917
|
method: "POST",
|
|
4898
4918
|
path: "/api/sdk/v1/webhooks",
|
|
@@ -4909,7 +4929,7 @@ function mn(n) {
|
|
|
4909
4929
|
// dedup TTL 24h (mesmo padrão de usage.report/support.createTicket).
|
|
4910
4930
|
idempotencyKey: true
|
|
4911
4931
|
});
|
|
4912
|
-
return
|
|
4932
|
+
return pn(r);
|
|
4913
4933
|
},
|
|
4914
4934
|
async list(e) {
|
|
4915
4935
|
let t = ke(n, e?.productId), r = await v(n, {
|
|
@@ -4918,10 +4938,10 @@ function mn(n) {
|
|
|
4918
4938
|
query: { productId: t },
|
|
4919
4939
|
requireAuth: true
|
|
4920
4940
|
});
|
|
4921
|
-
return (Array.isArray(r?.endpoints) ? r.endpoints : []).map(
|
|
4941
|
+
return (Array.isArray(r?.endpoints) ? r.endpoints : []).map(pn);
|
|
4922
4942
|
},
|
|
4923
4943
|
async unregister(e, t) {
|
|
4924
|
-
if (!e) throw new
|
|
4944
|
+
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
4925
4945
|
let r = ke(n, t?.productId);
|
|
4926
4946
|
return await v(n, {
|
|
4927
4947
|
method: "DELETE",
|
|
@@ -4931,7 +4951,7 @@ function mn(n) {
|
|
|
4931
4951
|
}), { ok: true };
|
|
4932
4952
|
},
|
|
4933
4953
|
async test(e, t) {
|
|
4934
|
-
if (!e) throw new
|
|
4954
|
+
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
4935
4955
|
let r = ke(n, t?.productId), o = await v(n, {
|
|
4936
4956
|
method: "POST",
|
|
4937
4957
|
path: `/api/sdk/v1/webhooks/${encodeURIComponent(e)}/test`,
|
|
@@ -4955,7 +4975,7 @@ var Se = class {
|
|
|
4955
4975
|
endpoints = /* @__PURE__ */ new Map();
|
|
4956
4976
|
nextId = 1;
|
|
4957
4977
|
async register(e) {
|
|
4958
|
-
|
|
4978
|
+
mn(e);
|
|
4959
4979
|
let t = `mock_wh_${this.nextId++}`, r = {
|
|
4960
4980
|
id: t,
|
|
4961
4981
|
url: e.url,
|
|
@@ -4971,12 +4991,12 @@ var Se = class {
|
|
|
4971
4991
|
}
|
|
4972
4992
|
async unregister(e, t) {
|
|
4973
4993
|
if (!this.endpoints.has(e))
|
|
4974
|
-
throw new
|
|
4994
|
+
throw new c("not_found", `Webhook ${e} n\xE3o encontrado`);
|
|
4975
4995
|
return this.endpoints.delete(e), { ok: true };
|
|
4976
4996
|
}
|
|
4977
4997
|
async test(e, t) {
|
|
4978
4998
|
if (!this.endpoints.has(e))
|
|
4979
|
-
throw new
|
|
4999
|
+
throw new c("not_found", `Webhook ${e} n\xE3o encontrado`);
|
|
4980
5000
|
return { ok: true, statusCode: 200, durationMs: 42 };
|
|
4981
5001
|
}
|
|
4982
5002
|
};
|
|
@@ -4990,12 +5010,12 @@ var et = [
|
|
|
4990
5010
|
"warning",
|
|
4991
5011
|
"error"
|
|
4992
5012
|
];
|
|
4993
|
-
function
|
|
5013
|
+
function gn(n) {
|
|
4994
5014
|
if (!n || typeof n != "object")
|
|
4995
|
-
throw new
|
|
5015
|
+
throw new c("invalid_response", "Notification response is not an object");
|
|
4996
5016
|
let e = n;
|
|
4997
5017
|
if (typeof e.id != "string")
|
|
4998
|
-
throw new
|
|
5018
|
+
throw new c("invalid_response", "Notification missing id");
|
|
4999
5019
|
let t = et.includes(e.severity) ? e.severity : "info";
|
|
5000
5020
|
return {
|
|
5001
5021
|
id: e.id,
|
|
@@ -5011,19 +5031,19 @@ function hn(n) {
|
|
|
5011
5031
|
dismissedAt: typeof e.dismissedAt == "string" ? e.dismissedAt : void 0
|
|
5012
5032
|
};
|
|
5013
5033
|
}
|
|
5014
|
-
function
|
|
5015
|
-
if (!n.userId) throw new
|
|
5016
|
-
if (!n.kind) throw new
|
|
5017
|
-
if (!n.title) throw new
|
|
5034
|
+
function yn(n) {
|
|
5035
|
+
if (!n.userId) throw new c("validation_failed", "userId obrigat\xF3rio");
|
|
5036
|
+
if (!n.kind) throw new c("validation_failed", "kind obrigat\xF3rio");
|
|
5037
|
+
if (!n.title) throw new c("validation_failed", "title obrigat\xF3rio");
|
|
5018
5038
|
if (n.severity && !et.includes(n.severity))
|
|
5019
|
-
throw new
|
|
5039
|
+
throw new c(
|
|
5020
5040
|
"validation_failed",
|
|
5021
5041
|
`severity inv\xE1lida: ${n.severity} (use ${et.join("|")})`
|
|
5022
5042
|
);
|
|
5023
5043
|
if (n.title.length > 200)
|
|
5024
|
-
throw new
|
|
5044
|
+
throw new c("validation_failed", "title m\xE1x 200 chars");
|
|
5025
5045
|
if (n.body && n.body.length > 2e3)
|
|
5026
|
-
throw new
|
|
5046
|
+
throw new c("validation_failed", "body m\xE1x 2000 chars");
|
|
5027
5047
|
}
|
|
5028
5048
|
function Te(n, ...e) {
|
|
5029
5049
|
for (let t of e)
|
|
@@ -5031,15 +5051,15 @@ function Te(n, ...e) {
|
|
|
5031
5051
|
return N("productId", t), t;
|
|
5032
5052
|
if (n.productId)
|
|
5033
5053
|
return N("productId", n.productId), n.productId;
|
|
5034
|
-
throw new
|
|
5054
|
+
throw new c(
|
|
5035
5055
|
"validation_failed",
|
|
5036
5056
|
"productId required (pass to options/input or set on createNeetruClient)"
|
|
5037
5057
|
);
|
|
5038
5058
|
}
|
|
5039
|
-
function
|
|
5059
|
+
function _n(n) {
|
|
5040
5060
|
return {
|
|
5041
5061
|
async send(e) {
|
|
5042
|
-
|
|
5062
|
+
yn(e);
|
|
5043
5063
|
let r = {
|
|
5044
5064
|
productId: Te(n, e.productId),
|
|
5045
5065
|
userId: e.userId,
|
|
@@ -5055,10 +5075,10 @@ function yn(n) {
|
|
|
5055
5075
|
requireAuth: true,
|
|
5056
5076
|
idempotencyKey: true
|
|
5057
5077
|
});
|
|
5058
|
-
return
|
|
5078
|
+
return gn(o);
|
|
5059
5079
|
},
|
|
5060
5080
|
async list(e, t) {
|
|
5061
|
-
if (!e) throw new
|
|
5081
|
+
if (!e) throw new c("validation_failed", "userId obrigat\xF3rio");
|
|
5062
5082
|
let o = {
|
|
5063
5083
|
productId: Te(n, t?.productId)
|
|
5064
5084
|
};
|
|
@@ -5069,10 +5089,10 @@ function yn(n) {
|
|
|
5069
5089
|
query: o,
|
|
5070
5090
|
requireAuth: true
|
|
5071
5091
|
});
|
|
5072
|
-
return (Array.isArray(i?.notifications) ? i.notifications : []).map(
|
|
5092
|
+
return (Array.isArray(i?.notifications) ? i.notifications : []).map(gn);
|
|
5073
5093
|
},
|
|
5074
5094
|
async markRead(e, t) {
|
|
5075
|
-
if (!e) throw new
|
|
5095
|
+
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
5076
5096
|
let r = Te(n, t?.productId);
|
|
5077
5097
|
return await v(n, {
|
|
5078
5098
|
method: "POST",
|
|
@@ -5082,7 +5102,7 @@ function yn(n) {
|
|
|
5082
5102
|
}), { ok: true };
|
|
5083
5103
|
},
|
|
5084
5104
|
async dismiss(e, t) {
|
|
5085
|
-
if (!e) throw new
|
|
5105
|
+
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
5086
5106
|
let r = Te(n, t?.productId);
|
|
5087
5107
|
return await v(n, {
|
|
5088
5108
|
method: "POST",
|
|
@@ -5097,7 +5117,7 @@ var Re = class {
|
|
|
5097
5117
|
notifications = /* @__PURE__ */ new Map();
|
|
5098
5118
|
nextId = 1;
|
|
5099
5119
|
async send(e) {
|
|
5100
|
-
if (
|
|
5120
|
+
if (yn(e), e.fingerprint) {
|
|
5101
5121
|
let o = Date.now() - 864e5;
|
|
5102
5122
|
for (let i of this.notifications.values())
|
|
5103
5123
|
if ((i.metadata ?? {}).fingerprint === e.fingerprint && i.userId === e.userId && new Date(i.createdAt).getTime() > o)
|
|
@@ -5117,18 +5137,18 @@ var Re = class {
|
|
|
5117
5137
|
return this.notifications.set(t, r), r;
|
|
5118
5138
|
}
|
|
5119
5139
|
async list(e, t) {
|
|
5120
|
-
if (!e) throw new
|
|
5140
|
+
if (!e) throw new c("validation_failed", "userId obrigat\xF3rio");
|
|
5121
5141
|
let r = Math.min(Math.max(1, t?.limit ?? 50), 200);
|
|
5122
5142
|
return [...this.notifications.values()].filter((o) => o.userId === e).filter((o) => t?.includeDismissed || !o.dismissedAt).filter((o) => !t?.onlyUnread || !o.readAt).sort((o, i) => i.createdAt.localeCompare(o.createdAt)).slice(0, r);
|
|
5123
5143
|
}
|
|
5124
5144
|
async markRead(e, t) {
|
|
5125
5145
|
let r = this.notifications.get(e);
|
|
5126
|
-
if (!r) throw new
|
|
5146
|
+
if (!r) throw new c("not_found", `Notification ${e} n\xE3o encontrada`);
|
|
5127
5147
|
return r.readAt || (r.readAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, r)), { ok: true };
|
|
5128
5148
|
}
|
|
5129
5149
|
async dismiss(e, t) {
|
|
5130
5150
|
let r = this.notifications.get(e);
|
|
5131
|
-
if (!r) throw new
|
|
5151
|
+
if (!r) throw new c("not_found", `Notification ${e} n\xE3o encontrada`);
|
|
5132
5152
|
return r.dismissedAt || (r.dismissedAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, r)), { ok: true };
|
|
5133
5153
|
}
|
|
5134
5154
|
};
|
|
@@ -5137,41 +5157,41 @@ var Re = class {
|
|
|
5137
5157
|
I();
|
|
5138
5158
|
M();
|
|
5139
5159
|
Me();
|
|
5140
|
-
var
|
|
5160
|
+
var _o = "/api/sdk/v1/ai/chat", bn = 12e4, Ie = 32768, vn = 32, wn = 4194304, kn = 2048, bo = /^data:image\/(?:png|jpe?g|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/, vo = /^https:\/\/[^\s]+$/, wo = /* @__PURE__ */ new Set(["low", "high", "auto"]), ko = /* @__PURE__ */ new Set(["system", "user", "assistant"]), Sn = 100, Tn = 128, Rn = 32768, In = 0, Cn = 2, An = 200, En = 20, Pn = 12 * 1024 * 1024, Dn = 5e4, Nn = 16, xn = 500, So = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]), To = /^[a-zA-Z0-9_-]+$/;
|
|
5141
5161
|
function k(n) {
|
|
5142
|
-
throw new
|
|
5162
|
+
throw new c("validation_failed", n);
|
|
5143
5163
|
}
|
|
5144
|
-
function
|
|
5164
|
+
function Ro(n) {
|
|
5145
5165
|
if (n.length === 0 || n.length % 4 !== 0) return false;
|
|
5146
5166
|
let e = n.endsWith("==") ? 2 : n.endsWith("=") ? 1 : 0;
|
|
5147
5167
|
return !(e > 0 ? n.slice(0, n.length - e) : n).includes("=");
|
|
5148
5168
|
}
|
|
5149
|
-
function
|
|
5169
|
+
function Io(n) {
|
|
5150
5170
|
let e = n.indexOf(",");
|
|
5151
5171
|
if (e === -1) return 0;
|
|
5152
5172
|
let t = n.slice(e + 1), r = t.endsWith("==") ? 2 : t.endsWith("=") ? 1 : 0;
|
|
5153
5173
|
return Math.max(0, Math.floor(t.length * 3 / 4) - r);
|
|
5154
5174
|
}
|
|
5155
|
-
function
|
|
5175
|
+
function Co(n) {
|
|
5156
5176
|
let e = 0, t = 0, r = 0;
|
|
5157
5177
|
for (let o of n) {
|
|
5158
5178
|
let i = o?.content;
|
|
5159
5179
|
if (Array.isArray(i))
|
|
5160
5180
|
for (let s of i) {
|
|
5161
|
-
if (e++, e >
|
|
5162
|
-
return `ai: total content parts exceeds ${
|
|
5181
|
+
if (e++, e > An)
|
|
5182
|
+
return `ai: total content parts exceeds ${An} per request`;
|
|
5163
5183
|
if (s && typeof s == "object" && s.type === "image_url") {
|
|
5164
|
-
if (t++, t >
|
|
5165
|
-
return `ai: total images exceeds ${
|
|
5184
|
+
if (t++, t > En)
|
|
5185
|
+
return `ai: total images exceeds ${En} per request`;
|
|
5166
5186
|
let a = s.image_url?.url;
|
|
5167
|
-
if (typeof a == "string" && a.startsWith("data:") && (r +=
|
|
5168
|
-
return `ai: aggregate image bytes exceeds ${
|
|
5187
|
+
if (typeof a == "string" && a.startsWith("data:") && (r += Io(a), r > Pn))
|
|
5188
|
+
return `ai: aggregate image bytes exceeds ${Pn} per request`;
|
|
5169
5189
|
}
|
|
5170
5190
|
}
|
|
5171
5191
|
}
|
|
5172
5192
|
return null;
|
|
5173
5193
|
}
|
|
5174
|
-
function
|
|
5194
|
+
function Ao(n) {
|
|
5175
5195
|
if (n === void 0) return null;
|
|
5176
5196
|
if (n === null || typeof n != "object")
|
|
5177
5197
|
return "ai: responseFormat json_schema.schema must be an object";
|
|
@@ -5182,11 +5202,11 @@ function Ro(n) {
|
|
|
5182
5202
|
return "ai: responseFormat json_schema.schema is not serializable";
|
|
5183
5203
|
}
|
|
5184
5204
|
if (e === void 0) return "ai: responseFormat json_schema.schema is invalid";
|
|
5185
|
-
if (e.length >
|
|
5186
|
-
return `ai: responseFormat json_schema.schema exceeds ${
|
|
5205
|
+
if (e.length > Dn)
|
|
5206
|
+
return `ai: responseFormat json_schema.schema exceeds ${Dn} serialized chars`;
|
|
5187
5207
|
let t = 0, r = (o, i) => {
|
|
5188
|
-
if (i >
|
|
5189
|
-
return `ai: responseFormat json_schema.schema exceeds max depth ${
|
|
5208
|
+
if (i > Nn)
|
|
5209
|
+
return `ai: responseFormat json_schema.schema exceeds max depth ${Nn}`;
|
|
5190
5210
|
if (Array.isArray(o)) {
|
|
5191
5211
|
for (let s of o) {
|
|
5192
5212
|
let a = r(s, i + 1);
|
|
@@ -5196,10 +5216,10 @@ function Ro(n) {
|
|
|
5196
5216
|
}
|
|
5197
5217
|
if (o && typeof o == "object")
|
|
5198
5218
|
for (let s of Object.getOwnPropertyNames(o)) {
|
|
5199
|
-
if (
|
|
5219
|
+
if (So.has(s))
|
|
5200
5220
|
return `ai: responseFormat json_schema.schema has forbidden key: ${s}`;
|
|
5201
|
-
if (t++, t >
|
|
5202
|
-
return `ai: responseFormat json_schema.schema exceeds ${
|
|
5221
|
+
if (t++, t > xn)
|
|
5222
|
+
return `ai: responseFormat json_schema.schema exceeds ${xn} keys`;
|
|
5203
5223
|
let a = r(o[s], i + 1);
|
|
5204
5224
|
if (a) return a;
|
|
5205
5225
|
}
|
|
@@ -5207,27 +5227,27 @@ function Ro(n) {
|
|
|
5207
5227
|
};
|
|
5208
5228
|
return r(n, 0);
|
|
5209
5229
|
}
|
|
5210
|
-
function
|
|
5230
|
+
function Eo(n) {
|
|
5211
5231
|
(typeof n != "string" || n.length === 0) && k("ai: image_url.url must be a non-empty string");
|
|
5212
5232
|
let e = n;
|
|
5213
5233
|
if (e.startsWith("data:")) {
|
|
5214
|
-
e.length >
|
|
5234
|
+
e.length > wn && k(`ai: image_url.url (data:) exceeds ${wn} chars`), bo.test(e) || k("ai: image_url.url data: must be data:image/<png|jpeg|jpg|gif|webp>;base64,<...>");
|
|
5215
5235
|
let t = e.slice(e.indexOf(",") + 1);
|
|
5216
|
-
|
|
5236
|
+
Ro(t) || k("ai: image_url.url data: has invalid base64 (length/padding)");
|
|
5217
5237
|
return;
|
|
5218
5238
|
}
|
|
5219
5239
|
if (e.startsWith("https://")) {
|
|
5220
|
-
e.length >
|
|
5240
|
+
e.length > kn && k(`ai: image_url.url (https:) exceeds ${kn} chars`), vo.test(e) || k("ai: image_url.url https: is invalid");
|
|
5221
5241
|
return;
|
|
5222
5242
|
}
|
|
5223
5243
|
k("ai: image_url.url must be a data:image/...;base64 or https:// URL (other schemes are rejected)");
|
|
5224
5244
|
}
|
|
5225
|
-
function
|
|
5245
|
+
function Po(n, e) {
|
|
5226
5246
|
if (typeof n == "string") {
|
|
5227
5247
|
n.length === 0 && k("ai: message content string must be non-empty"), n.length > Ie && k(`ai: message content exceeds ${Ie} chars`);
|
|
5228
5248
|
return;
|
|
5229
5249
|
}
|
|
5230
|
-
(!Array.isArray(n) || n.length === 0) && k("ai: message content must be a non-empty string or array of parts"), n.length >
|
|
5250
|
+
(!Array.isArray(n) || n.length === 0) && k("ai: message content must be a non-empty string or array of parts"), n.length > vn && k(`ai: message content has more than ${vn} parts`);
|
|
5231
5251
|
for (let t of n) {
|
|
5232
5252
|
(!t || typeof t != "object") && k("ai: each content part must be an object");
|
|
5233
5253
|
let r = t.type;
|
|
@@ -5237,14 +5257,14 @@ function Co(n, e) {
|
|
|
5237
5257
|
} else if (r === "image_url") {
|
|
5238
5258
|
e !== "user" && k(`ai: image_url is only allowed in role 'user' messages (got '${e}')`);
|
|
5239
5259
|
let o = t.image_url;
|
|
5240
|
-
(!o || typeof o != "object") && k("ai: image_url part must have { image_url: { url } }"),
|
|
5260
|
+
(!o || typeof o != "object") && k("ai: image_url part must have { image_url: { url } }"), Eo(o.url);
|
|
5241
5261
|
let i = o.detail;
|
|
5242
|
-
i !== void 0 && (typeof i != "string" || !
|
|
5262
|
+
i !== void 0 && (typeof i != "string" || !wo.has(i)) && k("ai: image_url.detail must be 'low' | 'high' | 'auto'");
|
|
5243
5263
|
} else
|
|
5244
5264
|
k("ai: content part type must be 'text' or 'image_url'");
|
|
5245
5265
|
}
|
|
5246
5266
|
}
|
|
5247
|
-
function
|
|
5267
|
+
function Do(n) {
|
|
5248
5268
|
(!n || typeof n != "object") && k("ai: responseFormat must be an object");
|
|
5249
5269
|
let e = n.type;
|
|
5250
5270
|
if (!(e === "text" || e === "json_object")) {
|
|
@@ -5252,8 +5272,8 @@ function Ao(n) {
|
|
|
5252
5272
|
let t = n.json_schema;
|
|
5253
5273
|
(!t || typeof t != "object") && k("ai: responseFormat json_schema requires { json_schema: { name } }");
|
|
5254
5274
|
let r = t, o = r.name;
|
|
5255
|
-
if ((typeof o != "string" || o.length === 0) && k("ai: responseFormat json_schema.name is required"), o.length > 64 && k("ai: responseFormat json_schema.name exceeds 64 chars"),
|
|
5256
|
-
let i =
|
|
5275
|
+
if ((typeof o != "string" || o.length === 0) && k("ai: responseFormat json_schema.name is required"), o.length > 64 && k("ai: responseFormat json_schema.name exceeds 64 chars"), To.test(o) || k("ai: responseFormat json_schema.name must match a-zA-Z0-9_-"), r.description !== void 0 && (typeof r.description != "string" && k("ai: responseFormat json_schema.description must be a string"), r.description.length > 1e3 && k("ai: responseFormat json_schema.description exceeds 1000 chars")), r.strict !== void 0 && typeof r.strict != "boolean" && k("ai: responseFormat json_schema.strict must be a boolean"), r.schema !== void 0) {
|
|
5276
|
+
let i = Ao(r.schema);
|
|
5257
5277
|
i && k(i);
|
|
5258
5278
|
}
|
|
5259
5279
|
return;
|
|
@@ -5261,35 +5281,35 @@ function Ao(n) {
|
|
|
5261
5281
|
k("ai: responseFormat.type must be 'text' | 'json_object' | 'json_schema'");
|
|
5262
5282
|
}
|
|
5263
5283
|
}
|
|
5264
|
-
function
|
|
5284
|
+
function On(n, e, t) {
|
|
5265
5285
|
if (!e || typeof e != "object")
|
|
5266
|
-
throw new
|
|
5286
|
+
throw new c("validation_failed", "ai: options object is required");
|
|
5267
5287
|
if (typeof e.model != "string" || e.model.length === 0)
|
|
5268
|
-
throw new
|
|
5269
|
-
if (e.model.length >
|
|
5270
|
-
throw new
|
|
5288
|
+
throw new c("validation_failed", "ai: model is required");
|
|
5289
|
+
if (e.model.length > Tn)
|
|
5290
|
+
throw new c("validation_failed", `ai: model exceeds ${Tn} chars`);
|
|
5271
5291
|
if (!Array.isArray(e.messages) || e.messages.length === 0)
|
|
5272
|
-
throw new
|
|
5273
|
-
if (e.messages.length >
|
|
5274
|
-
throw new
|
|
5292
|
+
throw new c("validation_failed", "ai: messages must be a non-empty array");
|
|
5293
|
+
if (e.messages.length > Sn)
|
|
5294
|
+
throw new c("validation_failed", `ai: messages exceeds ${Sn} per request`);
|
|
5275
5295
|
for (let a of e.messages) {
|
|
5276
|
-
if (!a || typeof a != "object" || typeof a.role != "string" || !
|
|
5277
|
-
throw new
|
|
5296
|
+
if (!a || typeof a != "object" || typeof a.role != "string" || !ko.has(a.role))
|
|
5297
|
+
throw new c(
|
|
5278
5298
|
"validation_failed",
|
|
5279
5299
|
"ai: each message role must be 'system' | 'user' | 'assistant'"
|
|
5280
5300
|
);
|
|
5281
|
-
|
|
5301
|
+
Po(a.content, a.role);
|
|
5282
5302
|
}
|
|
5283
|
-
let r =
|
|
5284
|
-
if (r) throw new
|
|
5303
|
+
let r = Co(e.messages);
|
|
5304
|
+
if (r) throw new c("validation_failed", r);
|
|
5285
5305
|
let o = e.productId ?? n.productId, i = e.tenantId ?? n.tenantId;
|
|
5286
5306
|
if (!o)
|
|
5287
|
-
throw new
|
|
5307
|
+
throw new c(
|
|
5288
5308
|
"validation_failed",
|
|
5289
5309
|
"ai: productId required (pass to options or set on createNeetruClient)"
|
|
5290
5310
|
);
|
|
5291
5311
|
if (!i)
|
|
5292
|
-
throw new
|
|
5312
|
+
throw new c(
|
|
5293
5313
|
"validation_failed",
|
|
5294
5314
|
"ai: tenantId required (pass to options or set on createNeetruClient)"
|
|
5295
5315
|
);
|
|
@@ -5302,24 +5322,24 @@ function xn(n, e, t) {
|
|
|
5302
5322
|
stream: t
|
|
5303
5323
|
};
|
|
5304
5324
|
if (e.maxTokens !== void 0) {
|
|
5305
|
-
if (!Number.isInteger(e.maxTokens) || e.maxTokens <= 0 || e.maxTokens >
|
|
5306
|
-
throw new
|
|
5325
|
+
if (!Number.isInteger(e.maxTokens) || e.maxTokens <= 0 || e.maxTokens > Rn)
|
|
5326
|
+
throw new c(
|
|
5307
5327
|
"validation_failed",
|
|
5308
|
-
`ai: maxTokens must be a positive integer <= ${
|
|
5328
|
+
`ai: maxTokens must be a positive integer <= ${Rn}`
|
|
5309
5329
|
);
|
|
5310
5330
|
s.maxTokens = e.maxTokens;
|
|
5311
5331
|
}
|
|
5312
5332
|
if (e.temperature !== void 0) {
|
|
5313
|
-
if (typeof e.temperature != "number" || !Number.isFinite(e.temperature) || e.temperature <
|
|
5314
|
-
throw new
|
|
5333
|
+
if (typeof e.temperature != "number" || !Number.isFinite(e.temperature) || e.temperature < In || e.temperature > Cn)
|
|
5334
|
+
throw new c(
|
|
5315
5335
|
"validation_failed",
|
|
5316
|
-
`ai: temperature must be a finite number between ${
|
|
5336
|
+
`ai: temperature must be a finite number between ${In} and ${Cn}`
|
|
5317
5337
|
);
|
|
5318
5338
|
s.temperature = e.temperature;
|
|
5319
5339
|
}
|
|
5320
|
-
return e.responseFormat !== void 0 && (
|
|
5340
|
+
return e.responseFormat !== void 0 && (Do(e.responseFormat), s.responseFormat = e.responseFormat), s;
|
|
5321
5341
|
}
|
|
5322
|
-
async function
|
|
5342
|
+
async function qn(n) {
|
|
5323
5343
|
try {
|
|
5324
5344
|
let e = await n.text();
|
|
5325
5345
|
return e ? JSON.parse(e) : void 0;
|
|
@@ -5327,48 +5347,48 @@ async function Mn(n) {
|
|
|
5327
5347
|
return;
|
|
5328
5348
|
}
|
|
5329
5349
|
}
|
|
5330
|
-
function
|
|
5350
|
+
function No(n, e) {
|
|
5331
5351
|
let t = n.replace(/\/+$/, ""), r = e.startsWith("/") ? e : `/${e}`;
|
|
5332
5352
|
return `${t}${r}`;
|
|
5333
5353
|
}
|
|
5334
|
-
async function
|
|
5354
|
+
async function Ln(n, e, t, r) {
|
|
5335
5355
|
if (!n.apiKey)
|
|
5336
|
-
throw new
|
|
5356
|
+
throw new c(
|
|
5337
5357
|
"missing_api_key",
|
|
5338
5358
|
"ai requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
5339
5359
|
);
|
|
5340
|
-
let o =
|
|
5360
|
+
let o = No(n.baseUrl, _o), { headers: i, correlationId: s } = ae({
|
|
5341
5361
|
"content-type": "application/json",
|
|
5342
5362
|
accept: r ? "text/event-stream" : "application/json",
|
|
5343
5363
|
authorization: `Bearer ${n.apiKey}`
|
|
5344
5364
|
}), a = { method: "POST", headers: i, body: JSON.stringify(e) };
|
|
5345
|
-
r ? t && (a.signal = t) : a.signal = t ?? AbortSignal.timeout(
|
|
5346
|
-
let
|
|
5365
|
+
r ? t && (a.signal = t) : a.signal = t ?? AbortSignal.timeout(bn);
|
|
5366
|
+
let l;
|
|
5347
5367
|
try {
|
|
5348
|
-
|
|
5368
|
+
l = await n.fetch(o, a);
|
|
5349
5369
|
} catch (p) {
|
|
5350
|
-
let f = p instanceof DOMException && p.name === "TimeoutError" ? `Network error: timeout after ${
|
|
5351
|
-
throw new
|
|
5370
|
+
let f = p instanceof DOMException && p.name === "TimeoutError" ? `Network error: timeout after ${bn / 1e3}s` : p instanceof DOMException && p.name === "AbortError" ? "Network error: request aborted" : `Network error: ${p instanceof Error ? p.message : "fetch failed"}`;
|
|
5371
|
+
throw new c("network_error", f, void 0, void 0, void 0, s);
|
|
5352
5372
|
}
|
|
5353
|
-
let d =
|
|
5354
|
-
if (!
|
|
5355
|
-
let p = await
|
|
5373
|
+
let d = l.headers.get("x-request-id") ?? l.headers.get("x-correlation-id") ?? void 0;
|
|
5374
|
+
if (!l.ok) {
|
|
5375
|
+
let p = await qn(l), f = le(l.status), h = `HTTP ${l.status}`;
|
|
5356
5376
|
if (p && typeof p == "object" && "error" in p) {
|
|
5357
|
-
let
|
|
5358
|
-
typeof
|
|
5377
|
+
let y = p.error;
|
|
5378
|
+
typeof y == "string" ? h = y : y && typeof y == "object" && (typeof y.code == "string" && (f = y.code), typeof y.message == "string" && (h = y.message));
|
|
5359
5379
|
}
|
|
5360
|
-
throw new
|
|
5380
|
+
throw new c(f, h, l.status, d, void 0, s);
|
|
5361
5381
|
}
|
|
5362
|
-
let u =
|
|
5363
|
-
return u && ce(u),
|
|
5382
|
+
let u = l.headers.get("x-neetru-version");
|
|
5383
|
+
return u && ce(u), l;
|
|
5364
5384
|
}
|
|
5365
|
-
function
|
|
5385
|
+
function Un(n) {
|
|
5366
5386
|
return {
|
|
5367
5387
|
provider: n.headers.get("x-neetru-provider") ?? "",
|
|
5368
5388
|
usageWarning: n.headers.get("x-neetru-ai-usage-warning") === "1"
|
|
5369
5389
|
};
|
|
5370
5390
|
}
|
|
5371
|
-
function
|
|
5391
|
+
function Mn(n) {
|
|
5372
5392
|
let e = [];
|
|
5373
5393
|
for (let r of n.split(`
|
|
5374
5394
|
`)) {
|
|
@@ -5389,12 +5409,12 @@ function Un(n) {
|
|
|
5389
5409
|
return null;
|
|
5390
5410
|
}
|
|
5391
5411
|
}
|
|
5392
|
-
function
|
|
5412
|
+
function Fn(n) {
|
|
5393
5413
|
return {
|
|
5394
5414
|
async chat(e) {
|
|
5395
|
-
let t =
|
|
5415
|
+
let t = On(n, e, false), r = await Ln(n, t, e.signal, false), { provider: o, usageWarning: i } = Un(r), s = await qn(r);
|
|
5396
5416
|
if (!s || s.ok !== true || !Array.isArray(s.choices))
|
|
5397
|
-
throw new
|
|
5417
|
+
throw new c("invalid_response", "ai.chat response missing ok/choices");
|
|
5398
5418
|
return {
|
|
5399
5419
|
choices: s.choices,
|
|
5400
5420
|
usage: s.usage ?? { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 },
|
|
@@ -5404,38 +5424,38 @@ function qn(n) {
|
|
|
5404
5424
|
};
|
|
5405
5425
|
},
|
|
5406
5426
|
stream(e) {
|
|
5407
|
-
let t =
|
|
5427
|
+
let t = On(n, e, true), r = Ln(n, t, e.signal, true), o = r.then(Un);
|
|
5408
5428
|
o.catch(() => {
|
|
5409
5429
|
});
|
|
5410
5430
|
async function* i() {
|
|
5411
5431
|
let a = (await r).body;
|
|
5412
5432
|
if (!a)
|
|
5413
|
-
throw new
|
|
5414
|
-
let
|
|
5433
|
+
throw new c("invalid_response", "ai.stream: response has no body");
|
|
5434
|
+
let l = a.getReader(), d = new TextDecoder(), u = "";
|
|
5415
5435
|
try {
|
|
5416
5436
|
for (; ; ) {
|
|
5417
|
-
let { done: f, value:
|
|
5437
|
+
let { done: f, value: h } = await l.read();
|
|
5418
5438
|
if (f) break;
|
|
5419
|
-
u += d.decode(
|
|
5420
|
-
let
|
|
5421
|
-
for (; (
|
|
5439
|
+
u += d.decode(h, { stream: !0 });
|
|
5440
|
+
let y;
|
|
5441
|
+
for (; (y = u.indexOf(`
|
|
5422
5442
|
|
|
5423
5443
|
`)) !== -1; ) {
|
|
5424
|
-
let S = u.slice(0,
|
|
5425
|
-
u = u.slice(
|
|
5426
|
-
let x =
|
|
5444
|
+
let S = u.slice(0, y);
|
|
5445
|
+
u = u.slice(y + 2);
|
|
5446
|
+
let x = Mn(S);
|
|
5427
5447
|
if (x && "done" in x) return;
|
|
5428
5448
|
x && "content" in x && (yield x.content);
|
|
5429
5449
|
}
|
|
5430
5450
|
}
|
|
5431
5451
|
let p = u.trim();
|
|
5432
5452
|
if (p) {
|
|
5433
|
-
let f =
|
|
5453
|
+
let f = Mn(p);
|
|
5434
5454
|
f && "content" in f && (yield f.content);
|
|
5435
5455
|
}
|
|
5436
5456
|
} finally {
|
|
5437
5457
|
try {
|
|
5438
|
-
|
|
5458
|
+
l.releaseLock();
|
|
5439
5459
|
} catch {
|
|
5440
5460
|
}
|
|
5441
5461
|
try {
|
|
@@ -5479,7 +5499,7 @@ var tt = Object.freeze({
|
|
|
5479
5499
|
_allowUnsignedDecode;
|
|
5480
5500
|
constructor(e = null, t) {
|
|
5481
5501
|
if (this._user = e, this._listeners = /* @__PURE__ */ new Set(), this._allowUnsignedDecode = t?.allowUnsignedDecode ?? false, this._allowUnsignedDecode && Ce())
|
|
5482
|
-
throw new
|
|
5502
|
+
throw new c(
|
|
5483
5503
|
"invalid_config",
|
|
5484
5504
|
"MockAuth com allowUnsignedDecode=true \xE9 PROIBIDO em produ\xE7\xE3o (NODE_ENV=production): decodificar JWT sem verificar assinatura \xE9 bypass de autentica\xE7\xE3o. Este modo existe exclusivamente para testes."
|
|
5485
5505
|
);
|
|
@@ -5520,9 +5540,9 @@ var tt = Object.freeze({
|
|
|
5520
5540
|
if (this._verifyTokenOverride)
|
|
5521
5541
|
return this._verifyTokenOverride(e);
|
|
5522
5542
|
if (!e)
|
|
5523
|
-
throw new
|
|
5543
|
+
throw new c("token_invalid_signature", "Token inv\xE1lido: string vazia");
|
|
5524
5544
|
if (!this._allowUnsignedDecode)
|
|
5525
|
-
throw new
|
|
5545
|
+
throw new c(
|
|
5526
5546
|
"unauthorized",
|
|
5527
5547
|
"MockAuth.verifyToken n\xE3o verifica assinaturas JWT e N\xC3O deve ser usado como security boundary em c\xF3digo deployado. Em testes, use new MockAuth(user, { allowUnsignedDecode: true }) para habilitar decodifica\xE7\xE3o sem assinatura, ou __mockVerifyToken(fn) para injetar resultado customizado."
|
|
5528
5548
|
);
|
|
@@ -5548,7 +5568,7 @@ var tt = Object.freeze({
|
|
|
5548
5568
|
} catch {
|
|
5549
5569
|
}
|
|
5550
5570
|
if (this._user) return this._user;
|
|
5551
|
-
throw new
|
|
5571
|
+
throw new c("token_invalid_signature", "Nenhum user mock dispon\xEDvel e JWT sem sub v\xE1lido");
|
|
5552
5572
|
}
|
|
5553
5573
|
/**
|
|
5554
5574
|
* Mock de `handleRedirectCallback` (Bug 2 / 3.1.3) — não há redirect real no
|
|
@@ -5626,14 +5646,14 @@ var tt = Object.freeze({
|
|
|
5626
5646
|
tenantId: r?.tenantId,
|
|
5627
5647
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
5628
5648
|
});
|
|
5629
|
-
let
|
|
5649
|
+
let l = this._quotas.get(e)?.limit ?? -1;
|
|
5630
5650
|
return {
|
|
5631
5651
|
ok: true,
|
|
5632
5652
|
counterId: `mock_${e}`,
|
|
5633
5653
|
value: s,
|
|
5634
|
-
limit:
|
|
5635
|
-
remaining:
|
|
5636
|
-
status:
|
|
5654
|
+
limit: l,
|
|
5655
|
+
remaining: l < 0 ? -1 : Math.max(0, l - s),
|
|
5656
|
+
status: l > 0 && s >= l ? "read_only_overlimit" : "ok"
|
|
5637
5657
|
};
|
|
5638
5658
|
}
|
|
5639
5659
|
async check(e, t) {
|
|
@@ -5675,10 +5695,10 @@ var tt = Object.freeze({
|
|
|
5675
5695
|
_tickets = [];
|
|
5676
5696
|
_ticketSeq = 0;
|
|
5677
5697
|
async createTicket(e) {
|
|
5678
|
-
if (!e?.subject) throw new
|
|
5679
|
-
if (!e?.message) throw new
|
|
5698
|
+
if (!e?.subject) throw new c("validation_failed", "subject required");
|
|
5699
|
+
if (!e?.message) throw new c("validation_failed", "message required");
|
|
5680
5700
|
if (!e?.productSlug)
|
|
5681
|
-
throw new
|
|
5701
|
+
throw new c(
|
|
5682
5702
|
"validation_failed",
|
|
5683
5703
|
"productSlug required (3.0 breaking \u2014 pass to input or set on createNeetruClient)"
|
|
5684
5704
|
);
|
|
@@ -5710,10 +5730,10 @@ var tt = Object.freeze({
|
|
|
5710
5730
|
}
|
|
5711
5731
|
_find(e) {
|
|
5712
5732
|
if (!e || typeof e != "string")
|
|
5713
|
-
throw new
|
|
5733
|
+
throw new c("validation_failed", "ticketId is required");
|
|
5714
5734
|
let t = this._tickets.find((r) => r.id === e);
|
|
5715
5735
|
if (!t)
|
|
5716
|
-
throw new
|
|
5736
|
+
throw new c("not_found", `ticket ${e} not found`);
|
|
5717
5737
|
return t;
|
|
5718
5738
|
}
|
|
5719
5739
|
/** 3.4: espelha `markResolvedSeen` — idempotente (só seta se ainda null). */
|
|
@@ -5729,18 +5749,18 @@ var tt = Object.freeze({
|
|
|
5729
5749
|
/** 3.4: espelha `submitSatisfaction` — terminal, seta `satisfiedAt`. */
|
|
5730
5750
|
async submitSatisfaction(e) {
|
|
5731
5751
|
if (!e || typeof e != "object")
|
|
5732
|
-
throw new
|
|
5752
|
+
throw new c("validation_failed", "input is required");
|
|
5733
5753
|
if (e.rating !== null && e.rating !== void 0 && (!Number.isInteger(e.rating) || e.rating < 1 || e.rating > 5))
|
|
5734
|
-
throw new
|
|
5754
|
+
throw new c("validation_failed", "rating must be an integer 1-5 or null");
|
|
5735
5755
|
if (typeof e.comment == "string" && e.comment.length > 2e3)
|
|
5736
|
-
throw new
|
|
5756
|
+
throw new c("validation_failed", "comment max 2000 chars");
|
|
5737
5757
|
let t = this._find(e.ticketId);
|
|
5738
5758
|
t.satisfiedAt = (/* @__PURE__ */ new Date()).toISOString(), t.rating = e.rating ?? null, t.satisfactionComment = e.comment ?? null;
|
|
5739
5759
|
}
|
|
5740
5760
|
/** 3.4: espelha `contestTicket` — reabre e zera o ciclo de satisfação. */
|
|
5741
5761
|
async contestTicket(e, t) {
|
|
5742
5762
|
if (typeof t?.comment == "string" && t.comment.length > 2e3)
|
|
5743
|
-
throw new
|
|
5763
|
+
throw new c("validation_failed", "comment max 2000 chars");
|
|
5744
5764
|
let r = this._find(e);
|
|
5745
5765
|
r.status = "open", r.resolvedAt = null, r.resolvedNotifiedAt = null, r.satisfactionAttempts = 0, r.lastSatisfactionAttemptAt = null, r.satisfiedAt = null, r.rating = null, r.satisfactionComment = null;
|
|
5746
5766
|
}
|
|
@@ -5783,9 +5803,9 @@ var Ne = class {
|
|
|
5783
5803
|
}
|
|
5784
5804
|
async chat(e) {
|
|
5785
5805
|
if (!e || typeof e.model != "string" || e.model.length === 0)
|
|
5786
|
-
throw new
|
|
5806
|
+
throw new c("validation_failed", "ai: model is required");
|
|
5787
5807
|
if (!Array.isArray(e.messages) || e.messages.length === 0)
|
|
5788
|
-
throw new
|
|
5808
|
+
throw new c("validation_failed", "ai: messages must be a non-empty array");
|
|
5789
5809
|
this._calls.push({ model: e.model, messages: e.messages, stream: false });
|
|
5790
5810
|
let t = this._reply(e), r = e.messages.reduce((i, s) => i + this._contentToText(s.content).length, 0), o = t.length;
|
|
5791
5811
|
return {
|
|
@@ -5802,9 +5822,9 @@ var Ne = class {
|
|
|
5802
5822
|
}
|
|
5803
5823
|
stream(e) {
|
|
5804
5824
|
if (!e || typeof e.model != "string" || e.model.length === 0)
|
|
5805
|
-
throw new
|
|
5825
|
+
throw new c("validation_failed", "ai: model is required");
|
|
5806
5826
|
if (!Array.isArray(e.messages) || e.messages.length === 0)
|
|
5807
|
-
throw new
|
|
5827
|
+
throw new c("validation_failed", "ai: messages must be a non-empty array");
|
|
5808
5828
|
this._calls.push({ model: e.model, messages: e.messages, stream: true });
|
|
5809
5829
|
let t = this._reply(e), r = t.match(/\S+\s*/g) ?? [t], o = Promise.resolve({ provider: "mock", usageWarning: false });
|
|
5810
5830
|
async function* i() {
|
|
@@ -5820,41 +5840,41 @@ var Ne = class {
|
|
|
5820
5840
|
|
|
5821
5841
|
// src/auth-pkce-shared.ts
|
|
5822
5842
|
I();
|
|
5823
|
-
function
|
|
5843
|
+
function jn() {
|
|
5824
5844
|
let n = globalThis.crypto;
|
|
5825
5845
|
if (!n || typeof n.getRandomValues != "function" || !n.subtle)
|
|
5826
|
-
throw new
|
|
5846
|
+
throw new c(
|
|
5827
5847
|
"runtime_unsupported",
|
|
5828
5848
|
"auth.signIn requer WebCrypto (crypto.subtle) \u2014 indispon\xEDvel neste runtime. Use HTTPS (ou http://localhost) num browser moderno, ou instale um polyfill WebCrypto (ex: react-native-quick-crypto) em React Native."
|
|
5829
5849
|
);
|
|
5830
5850
|
return n;
|
|
5831
5851
|
}
|
|
5832
|
-
function
|
|
5852
|
+
function $n(n) {
|
|
5833
5853
|
let e = "";
|
|
5834
5854
|
for (let r of n) e += String.fromCharCode(r);
|
|
5835
5855
|
return (typeof btoa == "function" ? btoa(e) : Buffer.from(e, "binary").toString("base64")).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
5836
5856
|
}
|
|
5837
5857
|
function xe(n, e) {
|
|
5838
5858
|
let t = new Uint8Array(e);
|
|
5839
|
-
return n.getRandomValues(t),
|
|
5859
|
+
return n.getRandomValues(t), $n(t);
|
|
5840
5860
|
}
|
|
5841
|
-
async function
|
|
5861
|
+
async function Wn(n, e) {
|
|
5842
5862
|
let t = new TextEncoder().encode(e), r = await n.subtle.digest("SHA-256", t);
|
|
5843
|
-
return
|
|
5863
|
+
return $n(new Uint8Array(r));
|
|
5844
5864
|
}
|
|
5845
5865
|
function oe(n) {
|
|
5846
5866
|
return (typeof globalThis.NEETRU_AUTH_URL == "string" ? globalThis.NEETRU_AUTH_URL : null) ?? n.replace(/^https?:\/\/api\./, "https://auth.");
|
|
5847
5867
|
}
|
|
5848
|
-
function
|
|
5868
|
+
function Bn(n) {
|
|
5849
5869
|
let e = n.oidcClientId;
|
|
5850
5870
|
if (!e && n.apiKey && (e = ct(n.apiKey).keyId), !e)
|
|
5851
|
-
throw new
|
|
5871
|
+
throw new c(
|
|
5852
5872
|
"invalid_config",
|
|
5853
5873
|
"auth OIDC requer `oidcClientId` (ou `apiKey`) configurado para montar o client_id."
|
|
5854
5874
|
);
|
|
5855
5875
|
return e;
|
|
5856
5876
|
}
|
|
5857
|
-
function
|
|
5877
|
+
function Vn(n) {
|
|
5858
5878
|
let e = new URL("/api/v1/oauth/authorize", n.idpOrigin);
|
|
5859
5879
|
return e.searchParams.set("response_type", "code"), e.searchParams.set("client_id", n.clientId), e.searchParams.set("redirect_uri", n.redirectUri), e.searchParams.set("scope", n.scope), e.searchParams.set("state", n.state), e.searchParams.set("nonce", n.nonce), e.searchParams.set("code_challenge", n.codeChallenge), e.searchParams.set("code_challenge_method", "S256"), e;
|
|
5860
5880
|
}
|
|
@@ -5882,27 +5902,27 @@ function ie(n) {
|
|
|
5882
5902
|
...e
|
|
5883
5903
|
};
|
|
5884
5904
|
}
|
|
5885
|
-
var
|
|
5886
|
-
async function
|
|
5887
|
-
let o = `${e}${
|
|
5905
|
+
var xo = "/api/v1/oauth/revoke";
|
|
5906
|
+
async function Kn(n, e, t, r) {
|
|
5907
|
+
let o = `${e}${xo}`, i = true;
|
|
5888
5908
|
for (let s of r) {
|
|
5889
5909
|
if (!s.token) continue;
|
|
5890
5910
|
let a = new URLSearchParams({
|
|
5891
5911
|
token: s.token,
|
|
5892
5912
|
token_type_hint: s.hint,
|
|
5893
5913
|
client_id: t
|
|
5894
|
-
}).toString(),
|
|
5895
|
-
for (let d = 0; d < 2 && !
|
|
5914
|
+
}).toString(), l = false;
|
|
5915
|
+
for (let d = 0; d < 2 && !l; d++)
|
|
5896
5916
|
try {
|
|
5897
|
-
if (
|
|
5917
|
+
if (l = (await n(o, {
|
|
5898
5918
|
method: "POST",
|
|
5899
5919
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
5900
5920
|
body: a
|
|
5901
|
-
})).ok, !
|
|
5921
|
+
})).ok, !l) break;
|
|
5902
5922
|
} catch {
|
|
5903
5923
|
d === 0 && await new Promise((u) => setTimeout(u, 500));
|
|
5904
5924
|
}
|
|
5905
|
-
|
|
5925
|
+
l || (i = false);
|
|
5906
5926
|
}
|
|
5907
5927
|
return i;
|
|
5908
5928
|
}
|
|
@@ -5911,14 +5931,14 @@ async function Vn(n, e, t, r) {
|
|
|
5911
5931
|
qe();
|
|
5912
5932
|
|
|
5913
5933
|
// src/end-user-token.ts
|
|
5914
|
-
var
|
|
5915
|
-
function
|
|
5916
|
-
|
|
5934
|
+
var Oo = /* @__PURE__ */ new WeakMap();
|
|
5935
|
+
function zn(n, e) {
|
|
5936
|
+
Oo.set(n, e);
|
|
5917
5937
|
}
|
|
5918
5938
|
|
|
5919
5939
|
// src/unsupported-db.ts
|
|
5920
5940
|
I();
|
|
5921
|
-
var
|
|
5941
|
+
var Lo = "[Neetru SDK] client.db n\xE3o est\xE1 dispon\xEDvel em React Native. O app n\xE3o acessa o banco do produto diretamente: chame a API do SEU produto (ex.: https://<produto>.neetru.com/api/v1) com o access_token do usu\xE1rio (Authorization: Bearer) \u2014 o backend do produto usa client.db no servidor. (At\xE9 a 3.7.x o db ca\xEDa em mem\xF3ria em sil\xEAncio e os dados sumiam ao fechar o app.)", Uo = /* @__PURE__ */ new Set([
|
|
5922
5942
|
"then",
|
|
5923
5943
|
"toJSON",
|
|
5924
5944
|
"valueOf",
|
|
@@ -5927,13 +5947,13 @@ var No = "[Neetru SDK] client.db n\xE3o est\xE1 dispon\xEDvel em React Native. O
|
|
|
5927
5947
|
"asymmetricMatch",
|
|
5928
5948
|
"nodeType"
|
|
5929
5949
|
]);
|
|
5930
|
-
function
|
|
5950
|
+
function Hn() {
|
|
5931
5951
|
let n = () => {
|
|
5932
|
-
throw new
|
|
5952
|
+
throw new c("runtime_unsupported", Lo, void 0, void 0, "react-native");
|
|
5933
5953
|
}, e = {};
|
|
5934
5954
|
return new Proxy(e, {
|
|
5935
5955
|
get(t, r) {
|
|
5936
|
-
if (!(typeof r == "symbol" ||
|
|
5956
|
+
if (!(typeof r == "symbol" || Uo.has(r)))
|
|
5937
5957
|
return r === "toString" ? () => "[NeetruDb indispon\xEDvel em React Native]" : n;
|
|
5938
5958
|
},
|
|
5939
5959
|
set() {
|
|
@@ -5943,7 +5963,7 @@ function zn() {
|
|
|
5943
5963
|
}
|
|
5944
5964
|
|
|
5945
5965
|
// src/auth.ts
|
|
5946
|
-
function
|
|
5966
|
+
function qo() {
|
|
5947
5967
|
try {
|
|
5948
5968
|
let e = globalThis.process?.env?.NEETRU_API_KEY;
|
|
5949
5969
|
return typeof e == "string" && e.length > 0 ? e : void 0;
|
|
@@ -5951,7 +5971,7 @@ function Lo() {
|
|
|
5951
5971
|
return;
|
|
5952
5972
|
}
|
|
5953
5973
|
}
|
|
5954
|
-
function
|
|
5974
|
+
function Fo(n) {
|
|
5955
5975
|
if (n) return n;
|
|
5956
5976
|
try {
|
|
5957
5977
|
let t = globalThis.process?.env?.NEETRU_ENV;
|
|
@@ -5965,11 +5985,11 @@ function Uo(n) {
|
|
|
5965
5985
|
}
|
|
5966
5986
|
return "prod";
|
|
5967
5987
|
}
|
|
5968
|
-
var
|
|
5969
|
-
function
|
|
5988
|
+
var jo = it;
|
|
5989
|
+
function sa() {
|
|
5970
5990
|
st();
|
|
5971
5991
|
}
|
|
5972
|
-
function
|
|
5992
|
+
function $o(n) {
|
|
5973
5993
|
let e = n.sub ?? "", t = typeof n.email == "string" ? n.email : "";
|
|
5974
5994
|
return {
|
|
5975
5995
|
uid: e,
|
|
@@ -5996,7 +6016,7 @@ function rt(n) {
|
|
|
5996
6016
|
} catch {
|
|
5997
6017
|
}
|
|
5998
6018
|
}
|
|
5999
|
-
function
|
|
6019
|
+
function Wo(n) {
|
|
6000
6020
|
let e = "neetru_id_token", t = "neetru_refresh_token", r = /* @__PURE__ */ new Set(), o = null, i = null, s = null;
|
|
6001
6021
|
function a() {
|
|
6002
6022
|
try {
|
|
@@ -6005,7 +6025,7 @@ function Fo(n) {
|
|
|
6005
6025
|
return null;
|
|
6006
6026
|
}
|
|
6007
6027
|
}
|
|
6008
|
-
function
|
|
6028
|
+
function l() {
|
|
6009
6029
|
try {
|
|
6010
6030
|
return typeof globalThis.sessionStorage < "u" ? globalThis.sessionStorage : null;
|
|
6011
6031
|
} catch {
|
|
@@ -6014,15 +6034,15 @@ function Fo(n) {
|
|
|
6014
6034
|
}
|
|
6015
6035
|
function d() {
|
|
6016
6036
|
if (o) {
|
|
6017
|
-
let
|
|
6018
|
-
return typeof
|
|
6037
|
+
let g = o.exp;
|
|
6038
|
+
return typeof g == "number" && g * 1e3 < Date.now() ? (o = null, a()?.removeItem(e), u(), S(), null) : o;
|
|
6019
6039
|
}
|
|
6020
6040
|
let m = a();
|
|
6021
6041
|
if (!m) return null;
|
|
6022
|
-
let
|
|
6023
|
-
if (!
|
|
6042
|
+
let _ = m.getItem(e);
|
|
6043
|
+
if (!_)
|
|
6024
6044
|
return S(), null;
|
|
6025
|
-
let w = ie(
|
|
6045
|
+
let w = ie(_);
|
|
6026
6046
|
return w ? (o = w, x(w), o) : (m.removeItem(e), S(), null);
|
|
6027
6047
|
}
|
|
6028
6048
|
function u() {
|
|
@@ -6038,28 +6058,28 @@ function Fo(n) {
|
|
|
6038
6058
|
function f() {
|
|
6039
6059
|
return a()?.getItem(t) ?? null;
|
|
6040
6060
|
}
|
|
6041
|
-
function
|
|
6061
|
+
function h() {
|
|
6042
6062
|
o = null;
|
|
6043
6063
|
let m = a();
|
|
6044
6064
|
m?.removeItem(e), m?.removeItem(t), u();
|
|
6045
6065
|
}
|
|
6046
|
-
function
|
|
6066
|
+
function y() {
|
|
6047
6067
|
return s || (s = (async () => {
|
|
6048
6068
|
let m = f();
|
|
6049
6069
|
if (!m) return false;
|
|
6050
|
-
let
|
|
6070
|
+
let _;
|
|
6051
6071
|
try {
|
|
6052
|
-
|
|
6072
|
+
_ = T();
|
|
6053
6073
|
} catch {
|
|
6054
6074
|
return false;
|
|
6055
6075
|
}
|
|
6056
|
-
let
|
|
6076
|
+
let g = `${oe(n.baseUrl)}/api/v1/oauth/token`, C = new URLSearchParams({
|
|
6057
6077
|
grant_type: "refresh_token",
|
|
6058
6078
|
refresh_token: m,
|
|
6059
|
-
client_id:
|
|
6079
|
+
client_id: _
|
|
6060
6080
|
}), D;
|
|
6061
6081
|
try {
|
|
6062
|
-
D = await n.fetch(
|
|
6082
|
+
D = await n.fetch(g, {
|
|
6063
6083
|
method: "POST",
|
|
6064
6084
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
6065
6085
|
body: C.toString()
|
|
@@ -6087,21 +6107,21 @@ function Fo(n) {
|
|
|
6087
6107
|
}), s);
|
|
6088
6108
|
}
|
|
6089
6109
|
function S() {
|
|
6090
|
-
f() &&
|
|
6091
|
-
m ||
|
|
6110
|
+
f() && y().then((m) => {
|
|
6111
|
+
m || h();
|
|
6092
6112
|
});
|
|
6093
6113
|
}
|
|
6094
6114
|
function x(m) {
|
|
6095
6115
|
p();
|
|
6096
|
-
let
|
|
6097
|
-
if (typeof
|
|
6098
|
-
let w =
|
|
6116
|
+
let _ = m.exp;
|
|
6117
|
+
if (typeof _ != "number") return;
|
|
6118
|
+
let w = _ * 1e3 - Date.now();
|
|
6099
6119
|
if (!(w <= 0)) {
|
|
6100
6120
|
if (f()) {
|
|
6101
|
-
let
|
|
6121
|
+
let g = Math.min(w, Math.max(3e4, w * 0.2)), C = Math.max(1, w - g);
|
|
6102
6122
|
i = setTimeout(() => {
|
|
6103
|
-
i = null,
|
|
6104
|
-
D ||
|
|
6123
|
+
i = null, y().then((D) => {
|
|
6124
|
+
D || h();
|
|
6105
6125
|
});
|
|
6106
6126
|
}, C);
|
|
6107
6127
|
return;
|
|
@@ -6112,25 +6132,25 @@ function Fo(n) {
|
|
|
6112
6132
|
}
|
|
6113
6133
|
}
|
|
6114
6134
|
function T() {
|
|
6115
|
-
return
|
|
6135
|
+
return Bn(n);
|
|
6116
6136
|
}
|
|
6117
6137
|
async function P(m) {
|
|
6118
|
-
let
|
|
6119
|
-
if (!
|
|
6138
|
+
let _ = m ?? (typeof globalThis.location < "u" ? globalThis.location.href : void 0);
|
|
6139
|
+
if (!_) return null;
|
|
6120
6140
|
let w;
|
|
6121
6141
|
try {
|
|
6122
|
-
w = new URL(
|
|
6142
|
+
w = new URL(_);
|
|
6123
6143
|
} catch {
|
|
6124
6144
|
return null;
|
|
6125
6145
|
}
|
|
6126
|
-
let
|
|
6146
|
+
let g = w.searchParams, C = g.get("error");
|
|
6127
6147
|
if (C) {
|
|
6128
|
-
let U =
|
|
6129
|
-
throw
|
|
6148
|
+
let U = g.get("error_description") ?? C;
|
|
6149
|
+
throw l()?.removeItem(se), rt(w), new c(C, `OIDC authorize falhou: ${U}`);
|
|
6130
6150
|
}
|
|
6131
|
-
let D =
|
|
6151
|
+
let D = g.get("code");
|
|
6132
6152
|
if (!D) return null;
|
|
6133
|
-
let E =
|
|
6153
|
+
let E = g.get("state"), R = l(), O = R?.getItem(se) ?? null, A = null;
|
|
6134
6154
|
if (O)
|
|
6135
6155
|
try {
|
|
6136
6156
|
A = JSON.parse(O);
|
|
@@ -6138,12 +6158,12 @@ function Fo(n) {
|
|
|
6138
6158
|
A = null;
|
|
6139
6159
|
}
|
|
6140
6160
|
if (!A)
|
|
6141
|
-
throw new
|
|
6161
|
+
throw new c(
|
|
6142
6162
|
"oidc_state_mismatch",
|
|
6143
6163
|
"Callback OIDC sem transa\xE7\xE3o pendente \u2014 `signIn` n\xE3o foi iniciado nesta sess\xE3o (ou j\xE1 consumido)."
|
|
6144
6164
|
);
|
|
6145
6165
|
if (!E || E !== A.state)
|
|
6146
|
-
throw R?.removeItem(se), rt(w), new
|
|
6166
|
+
throw R?.removeItem(se), rt(w), new c(
|
|
6147
6167
|
"oidc_state_mismatch",
|
|
6148
6168
|
"state do callback OIDC n\xE3o confere com o da transa\xE7\xE3o (poss\xEDvel CSRF)."
|
|
6149
6169
|
);
|
|
@@ -6157,14 +6177,14 @@ function Fo(n) {
|
|
|
6157
6177
|
};
|
|
6158
6178
|
}
|
|
6159
6179
|
async function q(m) {
|
|
6160
|
-
let
|
|
6161
|
-
if (!
|
|
6180
|
+
let _ = await P(m);
|
|
6181
|
+
if (!_) return null;
|
|
6162
6182
|
let w = T(), C = `${oe(n.baseUrl)}/api/v1/oauth/token`, D = new URLSearchParams({
|
|
6163
6183
|
grant_type: "authorization_code",
|
|
6164
|
-
code:
|
|
6165
|
-
redirect_uri:
|
|
6184
|
+
code: _.code,
|
|
6185
|
+
redirect_uri: _.redirectUri,
|
|
6166
6186
|
client_id: w,
|
|
6167
|
-
code_verifier:
|
|
6187
|
+
code_verifier: _.codeVerifier
|
|
6168
6188
|
}), E;
|
|
6169
6189
|
try {
|
|
6170
6190
|
E = await n.fetch(C, {
|
|
@@ -6173,7 +6193,7 @@ function Fo(n) {
|
|
|
6173
6193
|
body: D.toString()
|
|
6174
6194
|
});
|
|
6175
6195
|
} catch (L) {
|
|
6176
|
-
throw new
|
|
6196
|
+
throw new c(
|
|
6177
6197
|
"network_error",
|
|
6178
6198
|
`POST ${C} falhou (network): ${L?.message ?? String(L)}`
|
|
6179
6199
|
);
|
|
@@ -6186,7 +6206,7 @@ function Fo(n) {
|
|
|
6186
6206
|
}
|
|
6187
6207
|
if (!E.ok || typeof R?.error == "string") {
|
|
6188
6208
|
let L = typeof R?.error_description == "string" && R.error_description || typeof R?.error == "string" && R.error || `HTTP ${E.status}`;
|
|
6189
|
-
throw new
|
|
6209
|
+
throw new c(
|
|
6190
6210
|
"token_exchange_failed",
|
|
6191
6211
|
`Troca do authorization_code por tokens falhou no /token: ${L}`,
|
|
6192
6212
|
E.status
|
|
@@ -6194,39 +6214,39 @@ function Fo(n) {
|
|
|
6194
6214
|
}
|
|
6195
6215
|
let O = R?.id_token;
|
|
6196
6216
|
if (typeof O != "string" || O.length === 0)
|
|
6197
|
-
throw new
|
|
6217
|
+
throw new c(
|
|
6198
6218
|
"token_exchange_failed",
|
|
6199
6219
|
"Resposta do /token sem `id_token` \u2014 o login n\xE3o pode ser completado.",
|
|
6200
6220
|
E.status
|
|
6201
6221
|
);
|
|
6202
6222
|
let A = nt(O);
|
|
6203
6223
|
if (!A)
|
|
6204
|
-
throw new
|
|
6224
|
+
throw new c(
|
|
6205
6225
|
"token_exchange_failed",
|
|
6206
6226
|
"id_token retornado pelo /token \xE9 malformado (payload indecodific\xE1vel)."
|
|
6207
6227
|
);
|
|
6208
|
-
if (A.nonce !==
|
|
6209
|
-
throw new
|
|
6228
|
+
if (A.nonce !== _.nonce)
|
|
6229
|
+
throw new c(
|
|
6210
6230
|
"oidc_nonce_mismatch",
|
|
6211
6231
|
"nonce do id_token n\xE3o confere com o da transa\xE7\xE3o OIDC (poss\xEDvel replay). Token descartado."
|
|
6212
6232
|
);
|
|
6213
6233
|
let U = ie(O);
|
|
6214
6234
|
if (!U)
|
|
6215
|
-
throw new
|
|
6235
|
+
throw new c(
|
|
6216
6236
|
"token_exchange_failed",
|
|
6217
6237
|
"id_token retornado pelo /token n\xE3o tem `sub` ou j\xE1 est\xE1 expirado."
|
|
6218
6238
|
);
|
|
6219
6239
|
let F = a();
|
|
6220
6240
|
F?.setItem(e, O);
|
|
6221
6241
|
let j = R?.refresh_token;
|
|
6222
|
-
return typeof j == "string" && j.length > 0 && F?.setItem(t, j), o = U, x(U), u(), { user: U, postLoginRedirect:
|
|
6242
|
+
return typeof j == "string" && j.length > 0 && F?.setItem(t, j), o = U, x(U), u(), { user: U, postLoginRedirect: _.postLoginRedirect };
|
|
6223
6243
|
}
|
|
6224
6244
|
return {
|
|
6225
6245
|
async signIn(m) {
|
|
6226
6246
|
if (typeof globalThis.location < "u" && typeof globalThis.location.assign == "function") {
|
|
6227
|
-
let
|
|
6247
|
+
let _ = jn(), w = m?.redirectUri ?? globalThis.location.origin, g = m?.scope ?? "openid profile email", C = T(), D = xe(_, 16), E = xe(_, 16), R = xe(_, 32), O = await Wn(_, R), A = l();
|
|
6228
6248
|
if (!A)
|
|
6229
|
-
throw new
|
|
6249
|
+
throw new c(
|
|
6230
6250
|
"runtime_unsupported",
|
|
6231
6251
|
"auth.signIn requer sessionStorage para guardar a transa\xE7\xE3o PKCE entre o redirect e o callback."
|
|
6232
6252
|
);
|
|
@@ -6238,11 +6258,11 @@ function Fo(n) {
|
|
|
6238
6258
|
postLoginRedirect: m?.postLoginRedirect
|
|
6239
6259
|
};
|
|
6240
6260
|
A.setItem(se, JSON.stringify(U));
|
|
6241
|
-
let F = oe(n.baseUrl), j =
|
|
6261
|
+
let F = oe(n.baseUrl), j = Vn({
|
|
6242
6262
|
idpOrigin: F,
|
|
6243
6263
|
clientId: C,
|
|
6244
6264
|
redirectUri: w,
|
|
6245
|
-
scope:
|
|
6265
|
+
scope: g,
|
|
6246
6266
|
state: D,
|
|
6247
6267
|
nonce: E,
|
|
6248
6268
|
codeChallenge: O
|
|
@@ -6250,7 +6270,7 @@ function Fo(n) {
|
|
|
6250
6270
|
globalThis.location.assign(j.toString());
|
|
6251
6271
|
return;
|
|
6252
6272
|
}
|
|
6253
|
-
throw new
|
|
6273
|
+
throw new c(
|
|
6254
6274
|
"invalid_config",
|
|
6255
6275
|
"auth.signIn requires a browser context or mocks. Use NEETRU_ENV=dev or pass mocks.auth."
|
|
6256
6276
|
);
|
|
@@ -6259,22 +6279,22 @@ function Fo(n) {
|
|
|
6259
6279
|
completeSignIn: q,
|
|
6260
6280
|
// 3.7.0: exposto pro client.support renovar a sessão 1x num 401
|
|
6261
6281
|
// invalid_end_user_token (mesma função do refresh proativo, com dedup).
|
|
6262
|
-
refreshTokens:
|
|
6282
|
+
refreshTokens: y,
|
|
6263
6283
|
getIdToken() {
|
|
6264
|
-
let
|
|
6265
|
-
return
|
|
6284
|
+
let _ = a()?.getItem(e) ?? null;
|
|
6285
|
+
return _ && ie(_) ? _ : null;
|
|
6266
6286
|
},
|
|
6267
6287
|
async signOut() {
|
|
6268
|
-
let m = a(),
|
|
6269
|
-
if (m && (m.removeItem(e), m.removeItem(t)), p(), o = null,
|
|
6288
|
+
let m = a(), _ = m?.getItem(t) ?? null;
|
|
6289
|
+
if (m && (m.removeItem(e), m.removeItem(t)), p(), o = null, _) {
|
|
6270
6290
|
let w = null;
|
|
6271
6291
|
try {
|
|
6272
6292
|
w = T();
|
|
6273
6293
|
} catch {
|
|
6274
6294
|
w = null;
|
|
6275
6295
|
}
|
|
6276
|
-
!(w && await
|
|
6277
|
-
{ token:
|
|
6296
|
+
!(w && await Kn(n.fetch, oe(n.baseUrl), w, [
|
|
6297
|
+
{ token: _, hint: "refresh_token" }
|
|
6278
6298
|
])) && typeof console < "u" && console.warn(
|
|
6279
6299
|
"[neetru-sdk] signOut: a revoga\xE7\xE3o do refresh_token no servidor n\xE3o foi confirmada. A sess\xE3o local foi encerrada, mas o refresh_token pode seguir v\xE1lido at\xE9 expirar."
|
|
6280
6300
|
);
|
|
@@ -6294,40 +6314,40 @@ function Fo(n) {
|
|
|
6294
6314
|
r.delete(m);
|
|
6295
6315
|
};
|
|
6296
6316
|
},
|
|
6297
|
-
async verifyToken(m,
|
|
6317
|
+
async verifyToken(m, _) {
|
|
6298
6318
|
if (!m || typeof m != "string")
|
|
6299
|
-
throw new
|
|
6300
|
-
let
|
|
6319
|
+
throw new c("token_invalid_signature", "token must be a non-empty string");
|
|
6320
|
+
let g = (typeof globalThis.NEETRU_AUTH_URL == "string" ? globalThis.NEETRU_AUTH_URL : null) ?? n.baseUrl.replace(/^https?:\/\/api\./, "https://auth."), C = g, D = `${g}/api/v1/oauth/.well-known/jwks`, E = _?.jwksCacheTtlMs ?? Ue, R = _?.audience, O = lt(n.apiKey), A = R ?? n.oidcClientId ?? O?.keyId;
|
|
6301
6321
|
if (!A)
|
|
6302
|
-
throw new
|
|
6322
|
+
throw new c(
|
|
6303
6323
|
"invalid_config",
|
|
6304
6324
|
"verifyToken requires an audience: provide oidcClientId/apiKey on the client or pass options.audience. Calling jwtVerify without an audience allows tokens issued for other OIDC clients to pass."
|
|
6305
6325
|
);
|
|
6306
|
-
let U =
|
|
6326
|
+
let U = jo(D, E);
|
|
6307
6327
|
try {
|
|
6308
6328
|
let { payload: F } = await jose.jwtVerify(m, U, {
|
|
6309
6329
|
issuer: C,
|
|
6310
6330
|
audience: A,
|
|
6311
6331
|
algorithms: ["RS256"]
|
|
6312
6332
|
});
|
|
6313
|
-
return
|
|
6333
|
+
return $o(F);
|
|
6314
6334
|
} catch (F) {
|
|
6315
6335
|
let j = F?.code ?? F?.name ?? "", L = F?.message ?? String(F);
|
|
6316
|
-
throw j === "ERR_JWT_EXPIRED" ? new
|
|
6336
|
+
throw j === "ERR_JWT_EXPIRED" ? new c("token_expired", `Token expired: ${L}`) : j === "ERR_JWS_SIGNATURE_VERIFICATION_FAILED" ? new c("token_invalid_signature", `Token signature invalid: ${L}`) : j === "ERR_JWT_CLAIM_VALIDATION_FAILED" ? L.includes('"aud"') || L.includes("audience") ? new c("token_invalid_audience", `Token audience mismatch: ${L}`) : L.includes('"iss"') || L.includes("issuer") ? new c("token_invalid_issuer", `Token issuer mismatch: ${L}`) : new c("token_invalid_signature", `Token claim validation failed: ${L}`) : new c("token_invalid_signature", `Token verification failed: ${L}`);
|
|
6317
6337
|
}
|
|
6318
6338
|
}
|
|
6319
6339
|
};
|
|
6320
6340
|
}
|
|
6321
|
-
function
|
|
6341
|
+
function Bo(n = {}) {
|
|
6322
6342
|
let e = n.fetch ?? globalThis.fetch;
|
|
6323
6343
|
if (typeof e != "function")
|
|
6324
|
-
throw new
|
|
6344
|
+
throw new c(
|
|
6325
6345
|
"invalid_config",
|
|
6326
6346
|
"fetch is not available in this runtime. Pass `fetch` explicitly to createNeetruClient."
|
|
6327
6347
|
);
|
|
6328
|
-
let t = n.apiKey ??
|
|
6348
|
+
let t = n.apiKey ?? qo();
|
|
6329
6349
|
wt({ hasApiKey: !!t, strict: n.strictServerOnlyKey === true });
|
|
6330
|
-
let r =
|
|
6350
|
+
let r = Fo(n.env), o = n.baseUrl ?? (r === "dev-local" ? mt : ft), i = pt(o, n.allowedHosts ?? []), s = Object.freeze({
|
|
6331
6351
|
apiKey: t,
|
|
6332
6352
|
oidcClientId: n.oidcClientId,
|
|
6333
6353
|
baseUrl: i,
|
|
@@ -6335,39 +6355,39 @@ function jo(n = {}) {
|
|
|
6335
6355
|
env: r,
|
|
6336
6356
|
productId: n.productId,
|
|
6337
6357
|
tenantId: n.tenantId
|
|
6338
|
-
}), a = r === "dev" && !Ce(),
|
|
6358
|
+
}), a = r === "dev" && !Ce(), l = n.mocks?.auth ?? (a ? new Ae({ ...tt }) : Wo(s)), d = n.mocks?.usage ?? (a ? new Ee() : Ut(s)), u = n.endUserAuth ?? l, p = n.mocks?.support ?? (a ? new Pe() : Wt(s, {
|
|
6339
6359
|
getEndUserToken: () => u.getIdToken(),
|
|
6340
6360
|
// `refreshTokens` é opcional (MockAuth/mocks próprios omitem).
|
|
6341
6361
|
refreshEndUserToken: (() => {
|
|
6342
6362
|
let P = u.refreshTokens;
|
|
6343
6363
|
return typeof P == "function" ? () => P.call(u) : void 0;
|
|
6344
6364
|
})()
|
|
6345
|
-
})), f = n.mocks?.entitlements ?? (a ? new De() : Dt()),
|
|
6365
|
+
})), f = n.mocks?.entitlements ?? (a ? new De() : Dt()), h = n.mocks?.db ?? (X() === "react-native" ? Hn() : dn(s, n.db)), y = n.mocks?.webhooks ?? (a ? new Se() : hn(s)), S = n.mocks?.notifications ?? (a ? new Re() : _n(s)), x = n.mocks?.ai ?? (a ? new Ne() : Fn(s)), T = Object.freeze({
|
|
6346
6366
|
config: s,
|
|
6347
|
-
auth:
|
|
6367
|
+
auth: l,
|
|
6348
6368
|
catalog: Et(s),
|
|
6349
6369
|
entitlements: f,
|
|
6350
6370
|
telemetry: Ot(s),
|
|
6351
6371
|
usage: d,
|
|
6352
6372
|
support: p,
|
|
6353
|
-
db:
|
|
6354
|
-
checkout:
|
|
6355
|
-
webhooks:
|
|
6373
|
+
db: h,
|
|
6374
|
+
checkout: un(s),
|
|
6375
|
+
webhooks: y,
|
|
6356
6376
|
notifications: S,
|
|
6357
6377
|
ai: x
|
|
6358
6378
|
});
|
|
6359
|
-
return n.endUserAuth &&
|
|
6379
|
+
return n.endUserAuth && zn(T, n.endUserAuth), T;
|
|
6360
6380
|
}
|
|
6361
6381
|
var Oe = /* @__PURE__ */ Symbol.for("@neetru/sdk:serverClient");
|
|
6362
|
-
function
|
|
6382
|
+
function aa(n = {}) {
|
|
6363
6383
|
let e = globalThis;
|
|
6364
|
-
return e[Oe] || (e[Oe] =
|
|
6384
|
+
return e[Oe] || (e[Oe] = Bo(n)), e[Oe];
|
|
6365
6385
|
}
|
|
6366
|
-
function
|
|
6386
|
+
function ca() {
|
|
6367
6387
|
delete globalThis[Oe];
|
|
6368
6388
|
}
|
|
6369
6389
|
|
|
6370
|
-
exports.__resetJwksCacheForTests =
|
|
6371
|
-
exports.__resetServerNeetruClientForTests =
|
|
6372
|
-
exports.createNeetruClient =
|
|
6373
|
-
exports.getServerNeetruClient =
|
|
6390
|
+
exports.__resetJwksCacheForTests = sa;
|
|
6391
|
+
exports.__resetServerNeetruClientForTests = ca;
|
|
6392
|
+
exports.createNeetruClient = Bo;
|
|
6393
|
+
exports.getServerNeetruClient = aa;
|