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