@neetru/sdk 3.8.1 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +14 -1
- package/dist/ai.cjs +1 -1
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +1 -1
- package/dist/auth.cjs +844 -803
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +841 -800
- package/dist/build-guard.cjs +186 -82
- package/dist/build-guard.d.cts +53 -1
- package/dist/build-guard.d.ts +53 -1
- package/dist/build-guard.mjs +175 -74
- package/dist/catalog.cjs +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/checkout.cjs +62 -49
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +62 -49
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +200 -187
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +193 -180
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +880 -839
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +847 -806
- package/dist/mobile.cjs +328 -276
- package/dist/mobile.d.cts +12 -2
- package/dist/mobile.d.ts +12 -2
- package/dist/mobile.mjs +328 -276
- package/dist/mocks.cjs +5 -5
- package/dist/mocks.d.cts +2 -2
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.mjs +4 -4
- package/dist/notifications.cjs +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +1 -1
- package/dist/react.cjs +119 -119
- package/dist/react.d.cts +8 -2
- package/dist/react.d.ts +8 -2
- package/dist/react.mjs +119 -119
- package/dist/support.cjs +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/support.mjs +1 -1
- package/dist/telemetry.cjs +62 -49
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +62 -49
- package/dist/{types-yv3EDKg2.d.cts → types-Bl_4HROd.d.cts} +62 -3
- package/dist/{types-BYPk_3HR.d.ts → types-Bqnsqvow.d.ts} +62 -3
- package/dist/usage.cjs +1 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +1 -1
- package/dist/webhooks.cjs +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +1 -1
- package/package.json +9 -1
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jwtVerify, createRemoteJWKSet } from 'jose';
|
|
2
2
|
import { openDB } from 'idb';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var ur = Object.defineProperty;
|
|
5
5
|
var W = (n, e) => () => (n && (e = n(n = 0)), e);
|
|
6
|
-
var
|
|
6
|
+
var ht = (n, e) => {
|
|
7
7
|
for (var t in e)
|
|
8
|
-
|
|
8
|
+
ur(n, t, { get: e[t], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
// src/errors.ts
|
|
12
|
-
var c, $,
|
|
12
|
+
var c, $, A = W(() => {
|
|
13
13
|
c = class n extends Error {
|
|
14
14
|
code;
|
|
15
15
|
status;
|
|
@@ -41,7 +41,7 @@ var c, $, C = W(() => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
// src/idempotency.ts
|
|
44
|
-
function
|
|
44
|
+
function Tt() {
|
|
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();
|
|
@@ -50,15 +50,15 @@ function kt() {
|
|
|
50
50
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
|
-
var
|
|
54
|
-
|
|
53
|
+
var Rt = W(() => {
|
|
54
|
+
A();
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// src/correlation.ts
|
|
58
|
-
function
|
|
59
|
-
return typeof n == "string" && n.length > 0 && n.length <= 128 &&
|
|
58
|
+
function Ct(n) {
|
|
59
|
+
return typeof n == "string" && n.length > 0 && n.length <= 128 && _r.test(n);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function br() {
|
|
62
62
|
let n = globalThis.crypto;
|
|
63
63
|
try {
|
|
64
64
|
if (n && typeof n.randomUUID == "function") return n.randomUUID();
|
|
@@ -76,24 +76,24 @@ function mr() {
|
|
|
76
76
|
let r = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
77
77
|
return `${r.slice(0, 8)}-${r.slice(8, 12)}-${r.slice(12, 16)}-${r.slice(16, 20)}-${r.slice(20)}`;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function be(n, e) {
|
|
80
80
|
let t, r = {};
|
|
81
81
|
for (let [i, s] of Object.entries(n)) {
|
|
82
|
-
if (i.toLowerCase() ===
|
|
83
|
-
|
|
82
|
+
if (i.toLowerCase() === It) {
|
|
83
|
+
Ct(s) && (t = s);
|
|
84
84
|
continue;
|
|
85
85
|
}
|
|
86
86
|
r[i] = s;
|
|
87
87
|
}
|
|
88
|
-
let o = t ?? (
|
|
89
|
-
return r[
|
|
88
|
+
let o = t ?? (Ct(e) ? e : void 0) ?? br();
|
|
89
|
+
return r[It] = o, { headers: r, correlationId: o };
|
|
90
90
|
}
|
|
91
|
-
var
|
|
92
|
-
|
|
91
|
+
var It, _r, $e = W(() => {
|
|
92
|
+
It = "x-correlation-id", _r = /^[A-Za-z0-9._:\-]+$/;
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
// src/server-only-key.ts
|
|
96
|
-
function
|
|
96
|
+
function J() {
|
|
97
97
|
try {
|
|
98
98
|
let n = globalThis.navigator;
|
|
99
99
|
if (n && n.product === "ReactNative") return "react-native";
|
|
@@ -106,108 +106,108 @@ function Q() {
|
|
|
106
106
|
}
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
let t =
|
|
109
|
+
function At(n, e) {
|
|
110
|
+
let t = vr[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
|
-
function
|
|
113
|
+
function Pt(n) {
|
|
114
114
|
if (!n.hasApiKey) return;
|
|
115
|
-
let e = n.runtime === void 0 ?
|
|
115
|
+
let e = n.runtime === void 0 ? J() : n.runtime;
|
|
116
116
|
if (e) {
|
|
117
117
|
if (n.strict)
|
|
118
|
-
throw new c("server_only_key",
|
|
119
|
-
if (!
|
|
120
|
-
|
|
118
|
+
throw new c("server_only_key", At(e, true), void 0, void 0, e);
|
|
119
|
+
if (!Et) {
|
|
120
|
+
Et = true;
|
|
121
121
|
try {
|
|
122
|
-
typeof console < "u" && typeof console.warn == "function" && console.warn(
|
|
122
|
+
typeof console < "u" && typeof console.warn == "function" && console.warn(At(e, !1));
|
|
123
123
|
} catch {
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
var
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
var vr, Et, ve = W(() => {
|
|
129
|
+
A();
|
|
130
|
+
vr = {
|
|
131
131
|
browser: "no navegador",
|
|
132
132
|
"react-native": "num app React Native"
|
|
133
133
|
};
|
|
134
|
-
|
|
134
|
+
Et = false;
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
// src/http.ts
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
checkCoreVersionCompat: () =>
|
|
138
|
+
var re = {};
|
|
139
|
+
ht(re, {
|
|
140
|
+
checkCoreVersionCompat: () => ne,
|
|
141
141
|
httpRequest: () => S,
|
|
142
|
-
statusToCode: () =>
|
|
142
|
+
statusToCode: () => we
|
|
143
143
|
});
|
|
144
|
-
function
|
|
144
|
+
function Ve(n) {
|
|
145
145
|
return n.split("+")[0] ?? n;
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
let t =
|
|
147
|
+
function kr(n, e) {
|
|
148
|
+
let t = Ve(n).split(".").map(Number), r = Ve(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;
|
|
151
151
|
if (s !== a) return s - a;
|
|
152
152
|
}
|
|
153
153
|
return 0;
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function Ut() {
|
|
156
156
|
try {
|
|
157
|
-
return "3.
|
|
157
|
+
return "3.9.1";
|
|
158
158
|
} catch {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
function
|
|
163
|
-
let n =
|
|
162
|
+
function Sr() {
|
|
163
|
+
let n = Ut();
|
|
164
164
|
return n ? parseInt(n.split(".")[0] ?? "3", 10) : 3;
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function ne(n) {
|
|
167
167
|
if (!n) return;
|
|
168
|
-
let e =
|
|
168
|
+
let e = Sr(), t = wr[e];
|
|
169
169
|
if (!t) return;
|
|
170
|
-
let r =
|
|
171
|
-
if (
|
|
170
|
+
let r = Ve(n);
|
|
171
|
+
if (kr(r, t) < 0) {
|
|
172
172
|
let o = `${e}:${r}`;
|
|
173
|
-
|
|
173
|
+
Dt.has(o) || (Dt.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 Tr() {
|
|
179
179
|
let n = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
180
|
-
return
|
|
180
|
+
return J() ? "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
|
}
|
|
182
|
-
function
|
|
182
|
+
function Nt(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 Er(n) {
|
|
187
187
|
if (!n) return null;
|
|
188
188
|
let e = Number(n);
|
|
189
|
-
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3),
|
|
189
|
+
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), xt);
|
|
190
190
|
let t = Date.parse(n);
|
|
191
191
|
if (Number.isFinite(t)) {
|
|
192
192
|
let r = t - Date.now();
|
|
193
|
-
if (r > 0) return Math.min(r,
|
|
193
|
+
if (r > 0) return Math.min(r, xt);
|
|
194
194
|
}
|
|
195
195
|
return null;
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function Ot(n) {
|
|
198
198
|
return new Promise((e) => setTimeout(e, n));
|
|
199
199
|
}
|
|
200
|
-
function
|
|
200
|
+
function we(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 Pr(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))
|
|
207
207
|
a !== void 0 && i.searchParams.set(s, String(a));
|
|
208
208
|
return i.toString();
|
|
209
209
|
}
|
|
210
|
-
async function
|
|
210
|
+
async function Lt(n) {
|
|
211
211
|
let e = await n.text();
|
|
212
212
|
if (e)
|
|
213
213
|
try {
|
|
@@ -217,17 +217,17 @@ async function xt(n) {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
async function S(n, e) {
|
|
220
|
-
let t = e.method ?? "GET", r =
|
|
220
|
+
let t = e.method ?? "GET", r = Pr(n.baseUrl, e.path, e.query), o = Cr.has(t) ? Rr : Ir, i = e.retries ?? o, { headers: s, correlationId: a } = be(
|
|
221
221
|
{ accept: "application/json", ...e.headers },
|
|
222
222
|
e.correlationId
|
|
223
|
-
), d =
|
|
223
|
+
), d = Ut();
|
|
224
224
|
if (d && (s["x-neetru-sdk-version"] = d), e.requireAuth) {
|
|
225
225
|
if (!n.apiKey)
|
|
226
|
-
throw new c("missing_api_key",
|
|
226
|
+
throw new c("missing_api_key", Tr());
|
|
227
227
|
s.authorization = `Bearer ${n.apiKey}`;
|
|
228
228
|
}
|
|
229
229
|
if (e.idempotencyKey) {
|
|
230
|
-
let f = typeof e.idempotencyKey == "string" ? e.idempotencyKey :
|
|
230
|
+
let f = typeof e.idempotencyKey == "string" ? e.idempotencyKey : Tt();
|
|
231
231
|
s["idempotency-key"] = f;
|
|
232
232
|
}
|
|
233
233
|
let p = e.body !== void 0 && t !== "GET" && t !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
@@ -247,69 +247,69 @@ async function S(n, e) {
|
|
|
247
247
|
p !== void 0 && (m.body = p);
|
|
248
248
|
let h = u != null ? Math.max(1, Math.min(3e4, u - Date.now())) : 3e4;
|
|
249
249
|
m.signal = AbortSignal.timeout(h);
|
|
250
|
-
let
|
|
250
|
+
let _;
|
|
251
251
|
try {
|
|
252
|
-
|
|
253
|
-
} catch (
|
|
254
|
-
let
|
|
255
|
-
if (l = new c("network_error",
|
|
256
|
-
let x =
|
|
252
|
+
_ = await n.fetch(r, m);
|
|
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 (l = new c("network_error", C, void 0, void 0, void 0, a), f < i) {
|
|
256
|
+
let x = Nt(f);
|
|
257
257
|
if (u == null || Date.now() + x < u) {
|
|
258
|
-
await
|
|
258
|
+
await Ot(x);
|
|
259
259
|
continue;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
throw l;
|
|
263
263
|
}
|
|
264
|
-
let I =
|
|
265
|
-
if (
|
|
266
|
-
let
|
|
267
|
-
return
|
|
264
|
+
let I = _.headers.get("x-request-id") ?? _.headers.get("x-correlation-id") ?? void 0;
|
|
265
|
+
if (_.ok) {
|
|
266
|
+
let g = _.headers.get("x-neetru-version");
|
|
267
|
+
return g && ne(g), await Lt(_);
|
|
268
268
|
}
|
|
269
|
-
let w = await
|
|
269
|
+
let w = await Lt(_), k = we(_.status), D = `HTTP ${_.status}`, y;
|
|
270
270
|
if (w && typeof w == "object") {
|
|
271
|
-
let
|
|
272
|
-
typeof
|
|
271
|
+
let g = w.error;
|
|
272
|
+
typeof g == "string" ? D = g : g && typeof g == "object" ? (typeof g.code == "string" && (k = g.code), typeof g.message == "string" && (D = g.message), typeof g.reason == "string" && (y = g.reason)) : (typeof w.code == "string" && (k = w.code), typeof w.message == "string" && (D = w.message)), typeof w.reason == "string" && (y = w.reason);
|
|
273
273
|
}
|
|
274
|
-
if (
|
|
275
|
-
let
|
|
276
|
-
|
|
274
|
+
if (_.status === 410) {
|
|
275
|
+
let g = _.headers.get("x-neetru-replacement");
|
|
276
|
+
D === `HTTP ${_.status}` && (D = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), g && !D.includes(g) && (D += ` Substituto: ${g}.`);
|
|
277
277
|
}
|
|
278
|
-
let
|
|
279
|
-
if (l =
|
|
280
|
-
let
|
|
281
|
-
if (u == null || Date.now() +
|
|
282
|
-
await
|
|
278
|
+
let b = new c(k, D, _.status, I, y, a);
|
|
279
|
+
if (l = b, Ar.has(k) && f < i) {
|
|
280
|
+
let C = Er(_.headers.get("retry-after")) ?? Nt(f);
|
|
281
|
+
if (u == null || Date.now() + C < u) {
|
|
282
|
+
await Ot(C);
|
|
283
283
|
continue;
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
throw
|
|
286
|
+
throw b;
|
|
287
287
|
}
|
|
288
288
|
throw l ?? new c("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
|
|
289
289
|
}
|
|
290
|
-
var
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
290
|
+
var wr, Dt, Rr, Ir, Cr, Ar, xt, F = W(() => {
|
|
291
|
+
A();
|
|
292
|
+
Rt();
|
|
293
|
+
$e();
|
|
294
|
+
ve();
|
|
295
|
+
wr = {
|
|
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
|
-
|
|
301
|
-
|
|
300
|
+
Dt = /* @__PURE__ */ new Set();
|
|
301
|
+
Rr = 2, Ir = 0, Cr = /* @__PURE__ */ new Set(["GET", "HEAD"]), Ar = /* @__PURE__ */ new Set([
|
|
302
302
|
"rate_limited",
|
|
303
303
|
"server_error",
|
|
304
304
|
"network_error"
|
|
305
305
|
]);
|
|
306
|
-
|
|
306
|
+
xt = 6e4;
|
|
307
307
|
});
|
|
308
308
|
|
|
309
309
|
// src/db-errors.ts
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
|
|
310
|
+
var Vr, v, H = W(() => {
|
|
311
|
+
A();
|
|
312
|
+
Vr = /* @__PURE__ */ new Set([
|
|
313
313
|
"db_unavailable",
|
|
314
314
|
"db_conflict",
|
|
315
315
|
"db_timeout"
|
|
@@ -327,16 +327,16 @@ var qr, v, z = W(() => {
|
|
|
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 = Vr.has(e), this.dbId = r, Object.setPrototypeOf(this, n.prototype);
|
|
331
331
|
}
|
|
332
332
|
};
|
|
333
333
|
});
|
|
334
334
|
|
|
335
335
|
// src/db/sql/resilient-pool.ts
|
|
336
|
-
function
|
|
337
|
-
return typeof n == "object" && n !== null && n[
|
|
336
|
+
function Ne(n) {
|
|
337
|
+
return typeof n == "object" && n !== null && n[Ze] === true;
|
|
338
338
|
}
|
|
339
|
-
function
|
|
339
|
+
function po(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,17 +348,17 @@ function so(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
|
|
351
|
+
function sn(n) {
|
|
352
352
|
let e = n && typeof n == "object" && "code" in n ? n.code : void 0;
|
|
353
|
-
if (typeof e == "string" &&
|
|
353
|
+
if (typeof e == "string" && fo.has(e.toUpperCase()))
|
|
354
354
|
return true;
|
|
355
355
|
let r = (n instanceof Error ? n.message : typeof n == "string" ? n : "").toLowerCase();
|
|
356
356
|
return r.length === 0 ? false : r.includes("password authentication failed") || r.includes("sasl authentication failed");
|
|
357
357
|
}
|
|
358
|
-
function
|
|
359
|
-
return
|
|
358
|
+
function mo(n) {
|
|
359
|
+
return po(n) || sn(n);
|
|
360
360
|
}
|
|
361
|
-
function
|
|
361
|
+
function et(n) {
|
|
362
362
|
let e = { current: n }, t = null, r = {
|
|
363
363
|
__neetruSwapInner(l) {
|
|
364
364
|
let u = e.current;
|
|
@@ -386,10 +386,10 @@ function Ye(n) {
|
|
|
386
386
|
}
|
|
387
387
|
return await o(l, e.current, f);
|
|
388
388
|
}
|
|
389
|
-
})(), s = i("query",
|
|
389
|
+
})(), s = i("query", mo), a = i("connect", sn), d = Object.create(Object.getPrototypeOf(n));
|
|
390
390
|
return new Proxy(d, {
|
|
391
391
|
get(l, u) {
|
|
392
|
-
if (u ===
|
|
392
|
+
if (u === Ze) return true;
|
|
393
393
|
if (u === "__neetruSwapInner") return r.__neetruSwapInner;
|
|
394
394
|
if (u === "__neetruGetInner") return r.__neetruGetInner;
|
|
395
395
|
if (u === "__neetruSetReLease") return r.__neetruSetReLease;
|
|
@@ -405,16 +405,16 @@ function Ye(n) {
|
|
|
405
405
|
}
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
|
-
var
|
|
409
|
-
|
|
410
|
-
|
|
408
|
+
var Ze, fo, tt = W(() => {
|
|
409
|
+
Ze = /* @__PURE__ */ Symbol.for("neetru.sdk.resilientPool");
|
|
410
|
+
fo = /* @__PURE__ */ new Set(["28P01", "28000"]);
|
|
411
411
|
});
|
|
412
412
|
|
|
413
413
|
// src/db/sql/lease.ts
|
|
414
|
-
function
|
|
414
|
+
function go(n, e) {
|
|
415
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;
|
|
416
416
|
}
|
|
417
|
-
function
|
|
417
|
+
function yo(n) {
|
|
418
418
|
if (n instanceof v) return n;
|
|
419
419
|
let e = n instanceof Error ? n.message : String(n), t = n instanceof Error ? n.code : void 0;
|
|
420
420
|
return typeof t == "string" && (t === "ECONNREFUSED" || t === "ENOTFOUND" || t === "ETIMEDOUT") ? new v(
|
|
@@ -422,10 +422,10 @@ function po(n) {
|
|
|
422
422
|
`Pool connection failed (${t}): ${e}`
|
|
423
423
|
) : e.includes("statement timeout") || e.includes("lock timeout") ? new v("db_timeout", `Query timeout: ${e}`) : e.includes("40001") || e.includes("40P01") || e.includes("deadlock") ? new v("db_conflict", `Transaction conflict: ${e}`) : e.includes("42501") || e.toLowerCase().includes("permission denied") ? new v("db_permission_denied", `Permission denied: ${e}`) : new v("db_unavailable", `Database error: ${e}`);
|
|
424
424
|
}
|
|
425
|
-
var
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
425
|
+
var ho, ee, ae, an = W(() => {
|
|
426
|
+
H();
|
|
427
|
+
tt();
|
|
428
|
+
ho = 0.8, ee = 3e4, ae = class {
|
|
429
429
|
/**
|
|
430
430
|
* Lease atual. `null` no modo LAZY antes da 1ª query (o 1º lease é adiado —
|
|
431
431
|
* ver `_ensureInitialLease`). Após a 1ª aquisição, sempre não-nulo.
|
|
@@ -465,7 +465,7 @@ var lo, Z, se, on = W(() => {
|
|
|
465
465
|
isolationLevel: t.isolationLevel
|
|
466
466
|
}) : await this._orm.transaction(e);
|
|
467
467
|
} catch (r) {
|
|
468
|
-
throw
|
|
468
|
+
throw yo(r);
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
471
|
async close() {
|
|
@@ -483,13 +483,13 @@ var lo, Z, se, on = W(() => {
|
|
|
483
483
|
* usa `MIN_RENEWAL_DELAY_MS` como fallback seguro.
|
|
484
484
|
*/
|
|
485
485
|
_calcRenewalDelayMs() {
|
|
486
|
-
if (!this._lease) return
|
|
486
|
+
if (!this._lease) return ee;
|
|
487
487
|
let e = Date.parse(this._lease.expiresAt);
|
|
488
|
-
if (!Number.isFinite(e)) return
|
|
488
|
+
if (!Number.isFinite(e)) return ee;
|
|
489
489
|
let t = this._deps.now(), r = e - t;
|
|
490
|
-
if (r <= 0) return
|
|
491
|
-
let o = r * (1 -
|
|
492
|
-
return Math.max(
|
|
490
|
+
if (r <= 0) return ee;
|
|
491
|
+
let o = r * (1 - ho);
|
|
492
|
+
return Math.max(ee, Math.round(o));
|
|
493
493
|
}
|
|
494
494
|
_scheduleRenewal() {
|
|
495
495
|
if (this._closed) return;
|
|
@@ -516,8 +516,8 @@ var lo, Z, se, on = W(() => {
|
|
|
516
516
|
} catch (t) {
|
|
517
517
|
this._renewalTimer = setTimeout(() => {
|
|
518
518
|
this._doRenew();
|
|
519
|
-
},
|
|
520
|
-
`[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${
|
|
519
|
+
}, ee), console.warn(
|
|
520
|
+
`[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${ee}ms (o cert de cliente mTLS do lease expira ~15min ap\xF3s o \xFAltimo swap):`,
|
|
521
521
|
t instanceof Error ? t.message : t
|
|
522
522
|
);
|
|
523
523
|
return;
|
|
@@ -593,7 +593,7 @@ var lo, Z, se, on = W(() => {
|
|
|
593
593
|
"SqlLeaseManager foi fechado \u2014 aquisi\xE7\xE3o de lease inicial abortada."
|
|
594
594
|
);
|
|
595
595
|
if (this._lease)
|
|
596
|
-
return
|
|
596
|
+
return Ne(this._pool) ? this._pool.__neetruGetInner() : this._pool;
|
|
597
597
|
if (this._initInFlight !== null) return this._initInFlight;
|
|
598
598
|
let e = (async () => {
|
|
599
599
|
let t;
|
|
@@ -611,7 +611,7 @@ var lo, Z, se, on = W(() => {
|
|
|
611
611
|
let i = o instanceof Error ? o.message : String(o);
|
|
612
612
|
throw new v("db_unavailable", `Falha ao abrir pool: ${i}`);
|
|
613
613
|
}
|
|
614
|
-
return
|
|
614
|
+
return Ne(this._pool) ? this._pool.__neetruSwapInner(r).end().catch(() => {
|
|
615
615
|
}) : this._pool = r, this._lease = t, this._scheduleRenewal(), r;
|
|
616
616
|
})();
|
|
617
617
|
this._initInFlight = e;
|
|
@@ -627,12 +627,12 @@ var lo, Z, se, on = W(() => {
|
|
|
627
627
|
* Exposto como método protegido para testes.
|
|
628
628
|
*/
|
|
629
629
|
async _swapPool(e) {
|
|
630
|
-
if (!
|
|
630
|
+
if (!go(this._lease, e)) {
|
|
631
631
|
this._lease = e;
|
|
632
632
|
return;
|
|
633
633
|
}
|
|
634
634
|
let t = this._deps.createPool(e);
|
|
635
|
-
if (
|
|
635
|
+
if (Ne(this._pool)) {
|
|
636
636
|
let i = this._pool.__neetruSwapInner(t);
|
|
637
637
|
this._lease = e, i.end().catch(() => {
|
|
638
638
|
});
|
|
@@ -654,29 +654,29 @@ var lo, Z, se, on = W(() => {
|
|
|
654
654
|
});
|
|
655
655
|
|
|
656
656
|
// src/db/sql/sql-client.ts
|
|
657
|
-
var
|
|
658
|
-
|
|
659
|
-
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () =>
|
|
660
|
-
DEFAULT_POOL_IDLE_MS: () =>
|
|
661
|
-
DEFAULT_POOL_MAX: () =>
|
|
662
|
-
LEASE_ENDPOINT: () =>
|
|
663
|
-
LEASE_RENEW_ENDPOINT: () =>
|
|
664
|
-
createDrizzleHandle: () =>
|
|
665
|
-
createHttpLeaseFetcher: () =>
|
|
666
|
-
createPgPool: () =>
|
|
667
|
-
createSqlClientFromConfig: () =>
|
|
668
|
-
createSqlClientWithDeps: () =>
|
|
669
|
-
resolvePoolTuning: () =>
|
|
657
|
+
var hn = {};
|
|
658
|
+
ht(hn, {
|
|
659
|
+
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () => fn,
|
|
660
|
+
DEFAULT_POOL_IDLE_MS: () => pn,
|
|
661
|
+
DEFAULT_POOL_MAX: () => un,
|
|
662
|
+
LEASE_ENDPOINT: () => cn,
|
|
663
|
+
LEASE_RENEW_ENDPOINT: () => ln,
|
|
664
|
+
createDrizzleHandle: () => wo,
|
|
665
|
+
createHttpLeaseFetcher: () => dn,
|
|
666
|
+
createPgPool: () => vo,
|
|
667
|
+
createSqlClientFromConfig: () => So,
|
|
668
|
+
createSqlClientWithDeps: () => mn,
|
|
669
|
+
resolvePoolTuning: () => rt
|
|
670
670
|
});
|
|
671
|
-
function
|
|
671
|
+
function _o(n) {
|
|
672
672
|
return n === "workspace" ? "staging" : n === "prod" ? "production" : "dev-local";
|
|
673
673
|
}
|
|
674
|
-
function
|
|
674
|
+
function dn(n) {
|
|
675
675
|
return async (e) => {
|
|
676
|
-
let { httpRequest: t } = await Promise.resolve().then(() => (
|
|
676
|
+
let { httpRequest: t } = await Promise.resolve().then(() => (F(), re)), r = !!e?.leaseId, o = r ? ln : cn, i;
|
|
677
677
|
r ? i = { leaseId: e.leaseId } : (i = {
|
|
678
678
|
productId: n.productId ?? "",
|
|
679
|
-
environment:
|
|
679
|
+
environment: _o(n.env ?? "prod")
|
|
680
680
|
}, e?.database !== void 0 && (i.database = e.database));
|
|
681
681
|
let s;
|
|
682
682
|
try {
|
|
@@ -702,10 +702,10 @@ function cn(n) {
|
|
|
702
702
|
`Falha ao ${d} lease SQL: ${p}`
|
|
703
703
|
);
|
|
704
704
|
}
|
|
705
|
-
return
|
|
705
|
+
return bo(s);
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
|
-
function
|
|
708
|
+
function bo(n) {
|
|
709
709
|
if (!n || typeof n != "object")
|
|
710
710
|
throw new v("db_unavailable", "Resposta de lease inv\xE1lida (n\xE3o \xE9 objeto).");
|
|
711
711
|
let t = n.lease;
|
|
@@ -737,22 +737,22 @@ function mo(n) {
|
|
|
737
737
|
expiresAt: o("expiresAt", "string")
|
|
738
738
|
};
|
|
739
739
|
}
|
|
740
|
-
function
|
|
740
|
+
function nt(n, e, t, r) {
|
|
741
741
|
let o = typeof process < "u" ? process.env?.[n] : void 0;
|
|
742
742
|
if (o === void 0 || o.trim() === "") return e;
|
|
743
743
|
let i = Number.parseInt(o.trim(), 10);
|
|
744
744
|
return !Number.isFinite(i) || i < t || i > r ? e : i;
|
|
745
745
|
}
|
|
746
|
-
function
|
|
746
|
+
function rt() {
|
|
747
747
|
return {
|
|
748
748
|
// Teto 100: bem abaixo do `max_client_conn = 500` do PgBouncer, com folga
|
|
749
749
|
// para múltiplas instâncias do app dividirem o mesmo front-door.
|
|
750
|
-
max:
|
|
750
|
+
max: nt("NEETRU_DB_POOL_MAX", un, 1, 100),
|
|
751
751
|
// Teto 15min = janela do cert; piso 1s.
|
|
752
|
-
idleTimeoutMillis:
|
|
753
|
-
connectionTimeoutMillis:
|
|
752
|
+
idleTimeoutMillis: nt("NEETRU_DB_POOL_IDLE_MS", pn, 1e3, 9e5),
|
|
753
|
+
connectionTimeoutMillis: nt(
|
|
754
754
|
"NEETRU_DB_POOL_CONNECT_TIMEOUT_MS",
|
|
755
|
-
|
|
755
|
+
fn,
|
|
756
756
|
1e3,
|
|
757
757
|
12e4
|
|
758
758
|
),
|
|
@@ -760,7 +760,7 @@ function tt() {
|
|
|
760
760
|
keepAliveInitialDelayMillis: 1e4
|
|
761
761
|
};
|
|
762
762
|
}
|
|
763
|
-
async function
|
|
763
|
+
async function vo(n) {
|
|
764
764
|
let { Pool: e } = await import(
|
|
765
765
|
/* webpackIgnore: true */
|
|
766
766
|
'pg'
|
|
@@ -777,17 +777,17 @@ async function ho(n) {
|
|
|
777
777
|
user: n.user,
|
|
778
778
|
password: n.password,
|
|
779
779
|
ssl: t,
|
|
780
|
-
...
|
|
780
|
+
...rt()
|
|
781
781
|
});
|
|
782
782
|
}
|
|
783
|
-
async function
|
|
783
|
+
async function wo(n, e) {
|
|
784
784
|
let { drizzle: t } = await import(
|
|
785
785
|
/* webpackIgnore: true */
|
|
786
786
|
'drizzle-orm/node-postgres'
|
|
787
787
|
);
|
|
788
788
|
return t(n, { schema: e });
|
|
789
789
|
}
|
|
790
|
-
function
|
|
790
|
+
function ko(n, e) {
|
|
791
791
|
let t = null, r = null, o = () => t ? Promise.resolve(t) : (r || (r = e().then((s) => (t = s, r = null, s)).catch((s) => {
|
|
792
792
|
throw r = null, s;
|
|
793
793
|
})), r), i = {
|
|
@@ -803,21 +803,21 @@ function yo(n, e) {
|
|
|
803
803
|
};
|
|
804
804
|
return n && Object.setPrototypeOf(i, n), i;
|
|
805
805
|
}
|
|
806
|
-
async function
|
|
806
|
+
async function mn(n, e) {
|
|
807
807
|
let t = e?.database !== void 0 ? { ...n, database: e.database } : n;
|
|
808
808
|
if (t.lazy) {
|
|
809
|
-
let d = null, p =
|
|
809
|
+
let d = null, p = ko(t.poolPrototype ?? null, () => {
|
|
810
810
|
if (!d)
|
|
811
811
|
throw new v("db_unavailable", "SQL client n\xE3o inicializado (manager ausente).");
|
|
812
812
|
return d._ensureInitialLease();
|
|
813
|
-
}), l =
|
|
813
|
+
}), l = et(p), u;
|
|
814
814
|
try {
|
|
815
815
|
u = t.createDrizzle(l, t.schema);
|
|
816
816
|
} catch (m) {
|
|
817
817
|
let h = m instanceof Error ? m.message : String(m);
|
|
818
818
|
throw new v("db_unavailable", `Falha ao criar handle Drizzle: ${h}`);
|
|
819
819
|
}
|
|
820
|
-
let f = new
|
|
820
|
+
let f = new ae(null, l, u, t);
|
|
821
821
|
return d = f, l.__neetruSetReLease(() => f._reactiveReLease()), f;
|
|
822
822
|
}
|
|
823
823
|
let r;
|
|
@@ -835,7 +835,7 @@ async function pn(n, e) {
|
|
|
835
835
|
let p = d instanceof Error ? d.message : String(d);
|
|
836
836
|
throw new v("db_unavailable", `Falha ao abrir pool: ${p}`);
|
|
837
837
|
}
|
|
838
|
-
let i =
|
|
838
|
+
let i = et(o), s;
|
|
839
839
|
try {
|
|
840
840
|
s = t.createDrizzle(i, t.schema);
|
|
841
841
|
} catch (d) {
|
|
@@ -844,11 +844,11 @@ async function pn(n, e) {
|
|
|
844
844
|
let p = d instanceof Error ? d.message : String(d);
|
|
845
845
|
throw new v("db_unavailable", `Falha ao criar handle Drizzle: ${p}`);
|
|
846
846
|
}
|
|
847
|
-
let a = new
|
|
847
|
+
let a = new ae(r, i, s, t);
|
|
848
848
|
return i.__neetruSetReLease(() => a._reactiveReLease()), a;
|
|
849
849
|
}
|
|
850
|
-
async function
|
|
851
|
-
let r =
|
|
850
|
+
async function So(n, e, t) {
|
|
851
|
+
let r = dn(n), o, i;
|
|
852
852
|
try {
|
|
853
853
|
o = await import(
|
|
854
854
|
/* webpackIgnore: true */
|
|
@@ -864,7 +864,7 @@ async function _o(n, e, t) {
|
|
|
864
864
|
);
|
|
865
865
|
}
|
|
866
866
|
let s = o.Pool ?? o.default?.Pool;
|
|
867
|
-
return
|
|
867
|
+
return mn(
|
|
868
868
|
{
|
|
869
869
|
fetchLease: r,
|
|
870
870
|
createPool: (p) => {
|
|
@@ -883,7 +883,7 @@ async function _o(n, e, t) {
|
|
|
883
883
|
ssl: l,
|
|
884
884
|
// Tuning centralizado (env-tunável) — ver resolvePoolTuning + auditoria
|
|
885
885
|
// docs/_review/AUDITORIA_DB_CONN_PERF_2026-09-06.md no Core.
|
|
886
|
-
...
|
|
886
|
+
...rt()
|
|
887
887
|
});
|
|
888
888
|
},
|
|
889
889
|
createDrizzle: (p, l) => i.drizzle(p, { schema: l }),
|
|
@@ -899,36 +899,36 @@ async function _o(n, e, t) {
|
|
|
899
899
|
t
|
|
900
900
|
);
|
|
901
901
|
}
|
|
902
|
-
var
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
902
|
+
var cn, ln, un, pn, fn, gn = W(() => {
|
|
903
|
+
H();
|
|
904
|
+
A();
|
|
905
|
+
an();
|
|
906
|
+
tt();
|
|
907
|
+
cn = "/api/sdk/v1/db/lease", ln = "/api/sdk/v1/db/lease/renew";
|
|
908
|
+
un = 10, pn = 6e4, fn = 1e4;
|
|
909
909
|
});
|
|
910
|
-
var
|
|
911
|
-
function
|
|
912
|
-
let t = Date.now(), r =
|
|
910
|
+
var gt = /* @__PURE__ */ new Map(), te = 3600 * 1e3;
|
|
911
|
+
function _e(n, e = te) {
|
|
912
|
+
let t = Date.now(), r = gt.get(n);
|
|
913
913
|
if (r && t - r.createdAt < e)
|
|
914
914
|
return r.jwks;
|
|
915
915
|
let o = createRemoteJWKSet(new URL(n));
|
|
916
|
-
return
|
|
916
|
+
return gt.set(n, { jwks: o, createdAt: t }), o;
|
|
917
917
|
}
|
|
918
918
|
|
|
919
919
|
// src/auth.ts
|
|
920
|
-
|
|
920
|
+
A();
|
|
921
921
|
|
|
922
922
|
// src/api-key.ts
|
|
923
|
-
|
|
924
|
-
var
|
|
925
|
-
function
|
|
923
|
+
A();
|
|
924
|
+
var yt = /^nrt_([A-Za-z0-9]+)_([A-Za-z0-9]+)$/;
|
|
925
|
+
function _t(n) {
|
|
926
926
|
if (typeof n != "string" || n.length === 0)
|
|
927
927
|
throw new c(
|
|
928
928
|
"invalid_config",
|
|
929
929
|
"apiKey is required (formato nrt_<keyId>_<secret>)"
|
|
930
930
|
);
|
|
931
|
-
let e =
|
|
931
|
+
let e = yt.exec(n);
|
|
932
932
|
if (!e)
|
|
933
933
|
throw new c(
|
|
934
934
|
"invalid_config",
|
|
@@ -936,22 +936,22 @@ function gt(n) {
|
|
|
936
936
|
);
|
|
937
937
|
return { keyId: e[1], secret: e[2] };
|
|
938
938
|
}
|
|
939
|
-
function
|
|
939
|
+
function bt(n) {
|
|
940
940
|
if (typeof n != "string" || n.length === 0) return null;
|
|
941
|
-
let e =
|
|
941
|
+
let e = yt.exec(n);
|
|
942
942
|
return e ? { keyId: e[1], secret: e[2] } : null;
|
|
943
943
|
}
|
|
944
944
|
|
|
945
945
|
// src/base-url-allowlist.ts
|
|
946
|
-
|
|
947
|
-
var
|
|
948
|
-
function
|
|
949
|
-
return
|
|
946
|
+
A();
|
|
947
|
+
var vt = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]), fr = ".neetru.com", mr = "neetru.com", hr = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?\.(test|localhost)$/;
|
|
948
|
+
function wt(n) {
|
|
949
|
+
return hr.test(n);
|
|
950
950
|
}
|
|
951
|
-
function
|
|
951
|
+
function gr(n) {
|
|
952
952
|
return n.toLowerCase().replace(/\.+$/, "");
|
|
953
953
|
}
|
|
954
|
-
function
|
|
954
|
+
function kt(n, e = []) {
|
|
955
955
|
if (typeof n != "string" || n.length === 0)
|
|
956
956
|
throw new c("invalid_config", "baseUrl is required");
|
|
957
957
|
let t;
|
|
@@ -960,8 +960,8 @@ function vt(n, e = []) {
|
|
|
960
960
|
} catch {
|
|
961
961
|
throw new c("invalid_config", `baseUrl is not a valid URL: ${n}`);
|
|
962
962
|
}
|
|
963
|
-
let r = t.protocol, o =
|
|
964
|
-
if (
|
|
963
|
+
let r = t.protocol, o = gr(t.hostname);
|
|
964
|
+
if (yr())
|
|
965
965
|
return typeof console < "u" && console.warn(
|
|
966
966
|
`[neetru-sdk] NEETRU_ALLOW_INSECURE_BASEURL=1 ativo. baseUrl=${n} aceito sem valida\xE7\xE3o.`
|
|
967
967
|
), n.replace(/\/+$/, "");
|
|
@@ -971,17 +971,17 @@ function vt(n, e = []) {
|
|
|
971
971
|
`baseUrl protocol must be http: or https:, got ${r}`
|
|
972
972
|
);
|
|
973
973
|
if (r === "http:") {
|
|
974
|
-
if (!(
|
|
974
|
+
if (!(vt.has(o) || wt(o)))
|
|
975
975
|
throw new c(
|
|
976
976
|
"invalid_config",
|
|
977
977
|
`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.`
|
|
978
978
|
);
|
|
979
979
|
return n.replace(/\/+$/, "");
|
|
980
980
|
}
|
|
981
|
-
let i = o ===
|
|
981
|
+
let i = o === mr || o.endsWith(fr), s = e.some((d) => {
|
|
982
982
|
let p = d.toLowerCase();
|
|
983
983
|
return o === p || o.endsWith(`.${p}`);
|
|
984
|
-
}), a =
|
|
984
|
+
}), a = vt.has(o) || wt(o);
|
|
985
985
|
if (!i && !s && !a)
|
|
986
986
|
throw new c(
|
|
987
987
|
"invalid_config",
|
|
@@ -989,7 +989,7 @@ function vt(n, e = []) {
|
|
|
989
989
|
);
|
|
990
990
|
return n.replace(/\/+$/, "");
|
|
991
991
|
}
|
|
992
|
-
function
|
|
992
|
+
function yr() {
|
|
993
993
|
try {
|
|
994
994
|
let e = globalThis.process?.env?.NEETRU_ALLOW_INSECURE_BASEURL;
|
|
995
995
|
if (e === "1" || e === "true") return !0;
|
|
@@ -1004,12 +1004,12 @@ function pr() {
|
|
|
1004
1004
|
}
|
|
1005
1005
|
|
|
1006
1006
|
// src/types.ts
|
|
1007
|
-
var
|
|
1007
|
+
var We = "https://api.neetru.com", St = "http://localhost:9003";
|
|
1008
1008
|
|
|
1009
1009
|
// src/catalog.ts
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
function
|
|
1010
|
+
A();
|
|
1011
|
+
F();
|
|
1012
|
+
function Mt(n) {
|
|
1013
1013
|
if (!n || typeof n != "object")
|
|
1014
1014
|
throw new c("invalid_response", "Catalog response item is not an object");
|
|
1015
1015
|
let e = n;
|
|
@@ -1028,7 +1028,7 @@ function Lt(n) {
|
|
|
1028
1028
|
return typeof r.amountCents == "number" && (o.amountCents = r.amountCents), Array.isArray(r.features) && r.features.every((i) => typeof i == "string") && (o.features = r.features), o;
|
|
1029
1029
|
})), t;
|
|
1030
1030
|
}
|
|
1031
|
-
function
|
|
1031
|
+
function qt(n) {
|
|
1032
1032
|
return {
|
|
1033
1033
|
/**
|
|
1034
1034
|
* Lista produtos publicados. Por default só `published=true`; staff
|
|
@@ -1045,7 +1045,7 @@ function Ut(n) {
|
|
|
1045
1045
|
"Catalog list response missing products array"
|
|
1046
1046
|
);
|
|
1047
1047
|
return {
|
|
1048
|
-
products: t.products.map(
|
|
1048
|
+
products: t.products.map(Mt),
|
|
1049
1049
|
fetchedAt: typeof t.fetchedAt == "string" ? t.fetchedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
1050
1050
|
};
|
|
1051
1051
|
},
|
|
@@ -1066,32 +1066,32 @@ function Ut(n) {
|
|
|
1066
1066
|
"invalid_response",
|
|
1067
1067
|
"Catalog get response missing product"
|
|
1068
1068
|
);
|
|
1069
|
-
return
|
|
1069
|
+
return Mt(t.product);
|
|
1070
1070
|
}
|
|
1071
1071
|
};
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
1074
1074
|
// src/entitlements.ts
|
|
1075
|
-
|
|
1076
|
-
var
|
|
1077
|
-
function
|
|
1078
|
-
throw new c("validation_failed",
|
|
1075
|
+
A();
|
|
1076
|
+
var Dr = "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.";
|
|
1077
|
+
function Ft() {
|
|
1078
|
+
throw new c("validation_failed", Dr);
|
|
1079
1079
|
}
|
|
1080
|
-
function
|
|
1080
|
+
function jt(n) {
|
|
1081
1081
|
return {
|
|
1082
1082
|
/**
|
|
1083
1083
|
* @deprecated Endpoint morto no Core — sempre retornava `not_subscribed`.
|
|
1084
1084
|
* Lança `NeetruError`. Use `client.usage.check(resource, {productId, tenantId})`.
|
|
1085
1085
|
*/
|
|
1086
1086
|
async check(e, t, r) {
|
|
1087
|
-
|
|
1087
|
+
Ft();
|
|
1088
1088
|
},
|
|
1089
1089
|
/**
|
|
1090
1090
|
* @deprecated Endpoint morto no Core — sempre retornava `not_subscribed`.
|
|
1091
1091
|
* Lança `NeetruError`. Use `client.usage.check(resource, {productId, tenantId})`.
|
|
1092
1092
|
*/
|
|
1093
1093
|
async checkDetailed(e, t, r) {
|
|
1094
|
-
|
|
1094
|
+
Ft();
|
|
1095
1095
|
},
|
|
1096
1096
|
/** Test helper legado — no-op (não há mais cache). Mantido por compat. */
|
|
1097
1097
|
__resetCache() {
|
|
@@ -1100,16 +1100,31 @@ function qt(n) {
|
|
|
1100
1100
|
}
|
|
1101
1101
|
|
|
1102
1102
|
// src/telemetry.ts
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1103
|
+
A();
|
|
1104
|
+
F();
|
|
1105
|
+
|
|
1106
|
+
// src/runtime-env.ts
|
|
1107
|
+
function Be() {
|
|
1108
|
+
try {
|
|
1109
|
+
if (typeof process < "u" && process.env)
|
|
1110
|
+
return process.env.NODE_ENV === "production";
|
|
1111
|
+
} catch {
|
|
1112
|
+
}
|
|
1113
|
+
return false;
|
|
1114
|
+
}
|
|
1115
|
+
function V(n) {
|
|
1116
|
+
return n === "dev" && !Be();
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/telemetry.ts
|
|
1120
|
+
var Wt = ["debug", "info", "warn", "error", "fatal"];
|
|
1121
|
+
function Nr() {
|
|
1107
1122
|
return typeof globalThis < "u" && typeof globalThis.window < "u";
|
|
1108
1123
|
}
|
|
1109
|
-
function
|
|
1110
|
-
return
|
|
1124
|
+
function $t() {
|
|
1125
|
+
return Nr() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
|
|
1111
1126
|
}
|
|
1112
|
-
function
|
|
1127
|
+
function xr(n) {
|
|
1113
1128
|
switch (n) {
|
|
1114
1129
|
case "debug":
|
|
1115
1130
|
return console.debug.bind(console);
|
|
@@ -1125,8 +1140,8 @@ function Ar(n) {
|
|
|
1125
1140
|
return console.log.bind(console);
|
|
1126
1141
|
}
|
|
1127
1142
|
}
|
|
1128
|
-
var
|
|
1129
|
-
function
|
|
1143
|
+
var Or = 500, Lr = 50;
|
|
1144
|
+
function Vt(n) {
|
|
1130
1145
|
let e = [], t = null, r = null;
|
|
1131
1146
|
async function o() {
|
|
1132
1147
|
if (e.length === 0) return;
|
|
@@ -1135,7 +1150,7 @@ function Wt(n) {
|
|
|
1135
1150
|
try {
|
|
1136
1151
|
let p = { name: d.name }, l = d.productSlug ?? n.productId;
|
|
1137
1152
|
l && (p.productSlug = l), d.properties && typeof d.properties == "object" && (p.properties = d.properties), d.timestamp && (p.timestamp = d.timestamp);
|
|
1138
|
-
let u =
|
|
1153
|
+
let u = $t();
|
|
1139
1154
|
await S(n, {
|
|
1140
1155
|
method: "POST",
|
|
1141
1156
|
path: u.path,
|
|
@@ -1159,7 +1174,7 @@ function Wt(n) {
|
|
|
1159
1174
|
function i() {
|
|
1160
1175
|
t || (t = setTimeout(() => {
|
|
1161
1176
|
o();
|
|
1162
|
-
},
|
|
1177
|
+
}, Or));
|
|
1163
1178
|
}
|
|
1164
1179
|
return {
|
|
1165
1180
|
/**
|
|
@@ -1183,7 +1198,7 @@ function Wt(n) {
|
|
|
1183
1198
|
throw new c("validation_failed", "event.name max 128 chars");
|
|
1184
1199
|
let a = { name: s.name }, d = s.productSlug ?? n.productId;
|
|
1185
1200
|
d && (a.productSlug = d), s.properties && typeof s.properties == "object" && (a.properties = s.properties), s.timestamp && (a.timestamp = s.timestamp);
|
|
1186
|
-
let p =
|
|
1201
|
+
let p = $t(), l = await S(n, {
|
|
1187
1202
|
method: "POST",
|
|
1188
1203
|
path: p.path,
|
|
1189
1204
|
body: a,
|
|
@@ -1204,7 +1219,7 @@ function Wt(n) {
|
|
|
1204
1219
|
* ```
|
|
1205
1220
|
*/
|
|
1206
1221
|
track(s) {
|
|
1207
|
-
!s || typeof s != "object" || typeof s.name != "string" || s.name.length === 0 || s.name.length > 128 || (e.push(s), e.length >=
|
|
1222
|
+
!s || typeof s != "object" || typeof s.name != "string" || s.name.length === 0 || s.name.length > 128 || (e.push(s), e.length >= Lr ? (t && (clearTimeout(t), t = null), o()) : i());
|
|
1208
1223
|
},
|
|
1209
1224
|
/**
|
|
1210
1225
|
* Força flush imediato da queue de `track()`. Resolva antes de
|
|
@@ -1231,14 +1246,14 @@ function Wt(n) {
|
|
|
1231
1246
|
async log(s) {
|
|
1232
1247
|
if (!s || typeof s != "object")
|
|
1233
1248
|
throw new c("validation_failed", "log input is required");
|
|
1234
|
-
if (!
|
|
1235
|
-
throw new c("validation_failed", `level must be one of ${
|
|
1249
|
+
if (!Wt.includes(s.level))
|
|
1250
|
+
throw new c("validation_failed", `level must be one of ${Wt.join(", ")}`);
|
|
1236
1251
|
if (typeof s.message != "string" || s.message.length === 0)
|
|
1237
1252
|
throw new c("validation_failed", "message is required");
|
|
1238
1253
|
if (s.message.length > 4e3)
|
|
1239
1254
|
throw new c("validation_failed", "message max 4000 chars");
|
|
1240
|
-
if (n.env
|
|
1241
|
-
return
|
|
1255
|
+
if (V(n.env))
|
|
1256
|
+
return xr(s.level)(`[neetru-sdk] ${s.level}: ${s.message}`, s.metadata ?? {}), { ok: true, mode: "mock" };
|
|
1242
1257
|
let a = {
|
|
1243
1258
|
level: s.level,
|
|
1244
1259
|
message: s.message
|
|
@@ -1274,22 +1289,22 @@ function Wt(n) {
|
|
|
1274
1289
|
}
|
|
1275
1290
|
|
|
1276
1291
|
// src/usage.ts
|
|
1277
|
-
|
|
1278
|
-
|
|
1292
|
+
A();
|
|
1293
|
+
F();
|
|
1279
1294
|
|
|
1280
1295
|
// src/validators.ts
|
|
1281
|
-
|
|
1282
|
-
var
|
|
1296
|
+
A();
|
|
1297
|
+
var Bt = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
|
|
1283
1298
|
function O(n, e) {
|
|
1284
|
-
if (typeof e != "string" ||
|
|
1299
|
+
if (typeof e != "string" || !Bt.test(e))
|
|
1285
1300
|
throw new c(
|
|
1286
1301
|
"validation_failed",
|
|
1287
|
-
`${n} must match ${
|
|
1302
|
+
`${n} must match ${Bt.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
|
|
1288
1303
|
);
|
|
1289
1304
|
}
|
|
1290
1305
|
|
|
1291
1306
|
// src/usage.ts
|
|
1292
|
-
function
|
|
1307
|
+
function Kt(n) {
|
|
1293
1308
|
return {
|
|
1294
1309
|
/**
|
|
1295
1310
|
* Reporta consumo metered de um resource. Hit no endpoint canônico
|
|
@@ -1377,10 +1392,10 @@ function Vt(n) {
|
|
|
1377
1392
|
}
|
|
1378
1393
|
|
|
1379
1394
|
// src/support.ts
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
var
|
|
1383
|
-
function
|
|
1395
|
+
A();
|
|
1396
|
+
F();
|
|
1397
|
+
var Ke = ["low", "normal", "high", "urgent"], Ur = ["open", "pending", "resolved", "closed"], zt = 50;
|
|
1398
|
+
function Ht(n) {
|
|
1384
1399
|
if (!n || typeof n != "object")
|
|
1385
1400
|
throw new c("invalid_response", "Ticket response is not an object");
|
|
1386
1401
|
let e = n;
|
|
@@ -1391,8 +1406,8 @@ function Kt(n) {
|
|
|
1391
1406
|
id: e.id,
|
|
1392
1407
|
subject: typeof e.subject == "string" ? e.subject : "",
|
|
1393
1408
|
message: typeof e.message == "string" ? e.message : "",
|
|
1394
|
-
severity:
|
|
1395
|
-
status:
|
|
1409
|
+
severity: Ke.includes(e.severity) ? e.severity : "normal",
|
|
1410
|
+
status: Ur.includes(e.status) ? e.status : "open",
|
|
1396
1411
|
createdAt: typeof e.createdAt == "string" ? e.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
1397
1412
|
updatedAt: typeof e.updatedAt == "string" ? e.updatedAt : void 0,
|
|
1398
1413
|
productSlug: typeof e.productId == "string" ? e.productId : typeof e.productSlug == "string" ? e.productSlug : void 0,
|
|
@@ -1410,15 +1425,15 @@ function Kt(n) {
|
|
|
1410
1425
|
satisfactionComment: typeof e.satisfactionComment == "string" ? e.satisfactionComment : null
|
|
1411
1426
|
};
|
|
1412
1427
|
}
|
|
1413
|
-
function
|
|
1428
|
+
function ke(n) {
|
|
1414
1429
|
if (!n || typeof n != "string")
|
|
1415
1430
|
throw new c("validation_failed", "ticketId is required");
|
|
1416
1431
|
}
|
|
1417
|
-
function
|
|
1432
|
+
function Qt(n) {
|
|
1418
1433
|
if (typeof n == "string" && n.length > 2e3)
|
|
1419
1434
|
throw new c("validation_failed", "comment max 2000 chars");
|
|
1420
1435
|
}
|
|
1421
|
-
function
|
|
1436
|
+
function Gt(n, ...e) {
|
|
1422
1437
|
for (let t of e)
|
|
1423
1438
|
if (typeof t == "string" && t.length > 0)
|
|
1424
1439
|
return O("productSlug", t), t;
|
|
@@ -1429,12 +1444,12 @@ function Ht(n, ...e) {
|
|
|
1429
1444
|
"productId required (pass to input.productSlug or set on createNeetruClient)"
|
|
1430
1445
|
);
|
|
1431
1446
|
}
|
|
1432
|
-
var
|
|
1433
|
-
function
|
|
1447
|
+
var Mr = "X-Neetru-End-User-Token", qr = "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.", Fr = "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.", jr = "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.", Wr = "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.";
|
|
1448
|
+
function Jt(n) {
|
|
1434
1449
|
if (n instanceof c && !(n instanceof $)) {
|
|
1435
1450
|
if (n.code === "end_user_token_required")
|
|
1436
1451
|
throw new $(
|
|
1437
|
-
|
|
1452
|
+
Fr,
|
|
1438
1453
|
"end_user_token_required",
|
|
1439
1454
|
n.status,
|
|
1440
1455
|
n.requestId,
|
|
@@ -1442,7 +1457,7 @@ function Gt(n) {
|
|
|
1442
1457
|
);
|
|
1443
1458
|
if (n.code === "invalid_end_user_token")
|
|
1444
1459
|
throw new $(
|
|
1445
|
-
|
|
1460
|
+
jr,
|
|
1446
1461
|
"invalid_end_user_token",
|
|
1447
1462
|
n.status,
|
|
1448
1463
|
n.requestId,
|
|
@@ -1451,7 +1466,7 @@ function Gt(n) {
|
|
|
1451
1466
|
if (n.code === "end_user_token_product_mismatch")
|
|
1452
1467
|
throw new c(
|
|
1453
1468
|
"forbidden",
|
|
1454
|
-
|
|
1469
|
+
Wr,
|
|
1455
1470
|
n.status,
|
|
1456
1471
|
n.requestId,
|
|
1457
1472
|
"end_user_token_product_mismatch",
|
|
@@ -1460,10 +1475,10 @@ function Gt(n) {
|
|
|
1460
1475
|
}
|
|
1461
1476
|
throw n;
|
|
1462
1477
|
}
|
|
1463
|
-
function
|
|
1478
|
+
function $r(n) {
|
|
1464
1479
|
return n instanceof c && n.code === "invalid_end_user_token";
|
|
1465
1480
|
}
|
|
1466
|
-
function
|
|
1481
|
+
function Xt(n, e = {}) {
|
|
1467
1482
|
async function t() {
|
|
1468
1483
|
try {
|
|
1469
1484
|
let a = await e.getEndUserToken?.();
|
|
@@ -1481,25 +1496,25 @@ function Qt(n, e = {}) {
|
|
|
1481
1496
|
}
|
|
1482
1497
|
}
|
|
1483
1498
|
function o(a) {
|
|
1484
|
-
return a ? { [
|
|
1499
|
+
return a ? { [Mr]: a } : {};
|
|
1485
1500
|
}
|
|
1486
1501
|
async function i(a, d) {
|
|
1487
1502
|
let p = await t();
|
|
1488
1503
|
if (!p && a && await r() && (p = await t()), !p && a)
|
|
1489
|
-
throw new $(
|
|
1504
|
+
throw new $(qr, "no_signed_in_user");
|
|
1490
1505
|
try {
|
|
1491
1506
|
return await d(o(p));
|
|
1492
1507
|
} catch (l) {
|
|
1493
|
-
if (p &&
|
|
1508
|
+
if (p && $r(l) && await r()) {
|
|
1494
1509
|
let u = await t();
|
|
1495
1510
|
if (u)
|
|
1496
1511
|
try {
|
|
1497
1512
|
return await d(o(u));
|
|
1498
1513
|
} catch (f) {
|
|
1499
|
-
|
|
1514
|
+
Jt(f);
|
|
1500
1515
|
}
|
|
1501
1516
|
}
|
|
1502
|
-
|
|
1517
|
+
Jt(l);
|
|
1503
1518
|
}
|
|
1504
1519
|
}
|
|
1505
1520
|
async function s(a, d = {}) {
|
|
@@ -1532,13 +1547,13 @@ function Qt(n, e = {}) {
|
|
|
1532
1547
|
throw new c("validation_failed", "message is required");
|
|
1533
1548
|
if (a.message.length > 1e4)
|
|
1534
1549
|
throw new c("validation_failed", "message max 10000 chars");
|
|
1535
|
-
if (a.severity && !
|
|
1550
|
+
if (a.severity && !Ke.includes(a.severity))
|
|
1536
1551
|
throw new c(
|
|
1537
1552
|
"validation_failed",
|
|
1538
|
-
`severity must be one of ${
|
|
1553
|
+
`severity must be one of ${Ke.join(", ")}`
|
|
1539
1554
|
);
|
|
1540
1555
|
let p = {
|
|
1541
|
-
productId:
|
|
1556
|
+
productId: Gt(n, a.productSlug),
|
|
1542
1557
|
subject: a.subject,
|
|
1543
1558
|
message: a.message,
|
|
1544
1559
|
severity: a.severity ?? "normal"
|
|
@@ -1555,7 +1570,7 @@ function Qt(n, e = {}) {
|
|
|
1555
1570
|
headers: f
|
|
1556
1571
|
})
|
|
1557
1572
|
), u = l && typeof l == "object" && "ticket" in l ? l.ticket : l;
|
|
1558
|
-
return
|
|
1573
|
+
return Ht(u);
|
|
1559
1574
|
},
|
|
1560
1575
|
/**
|
|
1561
1576
|
* Lista tickets do customer no produto atual. `productSlug` no contexto.
|
|
@@ -1563,11 +1578,11 @@ function Qt(n, e = {}) {
|
|
|
1563
1578
|
* Endpoint canonical: `GET /api/sdk/v1/support/tickets?productId=...`.
|
|
1564
1579
|
*/
|
|
1565
1580
|
async listMyTickets(a) {
|
|
1566
|
-
let d =
|
|
1567
|
-
if (p !== void 0 && (!Number.isInteger(p) || p < 1 || p >
|
|
1581
|
+
let d = Gt(n, a?.productSlug), p = a?.limit;
|
|
1582
|
+
if (p !== void 0 && (!Number.isInteger(p) || p < 1 || p > zt))
|
|
1568
1583
|
throw new c(
|
|
1569
1584
|
"validation_failed",
|
|
1570
|
-
`limit must be an integer 1-${
|
|
1585
|
+
`limit must be an integer 1-${zt} (Core default 20)`
|
|
1571
1586
|
);
|
|
1572
1587
|
let l = await i(
|
|
1573
1588
|
true,
|
|
@@ -1579,7 +1594,7 @@ function Qt(n, e = {}) {
|
|
|
1579
1594
|
headers: f
|
|
1580
1595
|
})
|
|
1581
1596
|
);
|
|
1582
|
-
return (Array.isArray(l) ? l : l && typeof l == "object" && "tickets" in l ? l.tickets ?? [] : []).map(
|
|
1597
|
+
return (Array.isArray(l) ? l : l && typeof l == "object" && "tickets" in l ? l.tickets ?? [] : []).map(Ht);
|
|
1583
1598
|
},
|
|
1584
1599
|
/**
|
|
1585
1600
|
* 3.4: marca a notificação de resolução como vista (`resolvedNotifiedAt`,
|
|
@@ -1587,7 +1602,7 @@ function Qt(n, e = {}) {
|
|
|
1587
1602
|
* `POST /api/sdk/v1/support/tickets/{id}/resolved-seen`.
|
|
1588
1603
|
*/
|
|
1589
1604
|
async markResolvedSeen(a) {
|
|
1590
|
-
|
|
1605
|
+
ke(a), await s(
|
|
1591
1606
|
`/api/sdk/v1/support/tickets/${encodeURIComponent(a)}/resolved-seen`
|
|
1592
1607
|
);
|
|
1593
1608
|
},
|
|
@@ -1598,7 +1613,7 @@ function Qt(n, e = {}) {
|
|
|
1598
1613
|
* `POST /api/sdk/v1/support/tickets/{id}/satisfaction-attempt`.
|
|
1599
1614
|
*/
|
|
1600
1615
|
async recordSatisfactionAttempt(a) {
|
|
1601
|
-
|
|
1616
|
+
ke(a), await s(
|
|
1602
1617
|
`/api/sdk/v1/support/tickets/${encodeURIComponent(a)}/satisfaction-attempt`,
|
|
1603
1618
|
// Incrementa satisfactionAttempts += 1 no Core — sem idempotencyKey,
|
|
1604
1619
|
// um retry de rede infla o contador (mesmo padrão de createTicket acima).
|
|
@@ -1612,9 +1627,9 @@ function Qt(n, e = {}) {
|
|
|
1612
1627
|
async submitSatisfaction(a) {
|
|
1613
1628
|
if (!a || typeof a != "object")
|
|
1614
1629
|
throw new c("validation_failed", "input is required");
|
|
1615
|
-
if (
|
|
1630
|
+
if (ke(a.ticketId), a.rating !== null && a.rating !== void 0 && (!Number.isInteger(a.rating) || a.rating < 1 || a.rating > 5))
|
|
1616
1631
|
throw new c("validation_failed", "rating must be an integer 1-5 or null");
|
|
1617
|
-
|
|
1632
|
+
Qt(a.comment), await s(
|
|
1618
1633
|
`/api/sdk/v1/support/tickets/${encodeURIComponent(a.ticketId)}/satisfaction`,
|
|
1619
1634
|
{
|
|
1620
1635
|
body: {
|
|
@@ -1631,7 +1646,7 @@ function Qt(n, e = {}) {
|
|
|
1631
1646
|
* `POST /api/sdk/v1/support/tickets/{id}/contest`.
|
|
1632
1647
|
*/
|
|
1633
1648
|
async contestTicket(a, d) {
|
|
1634
|
-
|
|
1649
|
+
ke(a), Qt(d?.comment), await s(
|
|
1635
1650
|
`/api/sdk/v1/support/tickets/${encodeURIComponent(a)}/contest`,
|
|
1636
1651
|
{ body: { comment: d?.comment ?? void 0 } }
|
|
1637
1652
|
);
|
|
@@ -1640,14 +1655,14 @@ function Qt(n, e = {}) {
|
|
|
1640
1655
|
}
|
|
1641
1656
|
|
|
1642
1657
|
// src/db/client-db.ts
|
|
1643
|
-
|
|
1658
|
+
H();
|
|
1644
1659
|
|
|
1645
1660
|
// src/db/offline/query-engine.ts
|
|
1646
|
-
function
|
|
1661
|
+
function Yt(n) {
|
|
1647
1662
|
return n == null ? 0 : typeof n == "number" ? 1 : typeof n == "string" ? 2 : typeof n == "boolean" ? 3 : 4;
|
|
1648
1663
|
}
|
|
1649
|
-
function
|
|
1650
|
-
let t =
|
|
1664
|
+
function oe(n, e) {
|
|
1665
|
+
let t = Yt(n), r = Yt(e);
|
|
1651
1666
|
if (t !== r) return t - r;
|
|
1652
1667
|
if (n == null) return 0;
|
|
1653
1668
|
if (typeof n == "number" && typeof e == "number") return n - e;
|
|
@@ -1656,7 +1671,7 @@ function re(n, e) {
|
|
|
1656
1671
|
let o = String(n), i = String(e);
|
|
1657
1672
|
return o < i ? -1 : o > i ? 1 : 0;
|
|
1658
1673
|
}
|
|
1659
|
-
function
|
|
1674
|
+
function ze(n, e) {
|
|
1660
1675
|
let t = e.split("."), r = n;
|
|
1661
1676
|
for (let o of t) {
|
|
1662
1677
|
if (r == null || typeof r != "object")
|
|
@@ -1665,8 +1680,8 @@ function Be(n, e) {
|
|
|
1665
1680
|
}
|
|
1666
1681
|
return r;
|
|
1667
1682
|
}
|
|
1668
|
-
function
|
|
1669
|
-
let t =
|
|
1683
|
+
function Br(n, e) {
|
|
1684
|
+
let t = ze(n, e.field);
|
|
1670
1685
|
if (t === void 0) return false;
|
|
1671
1686
|
let { op: r, value: o } = e;
|
|
1672
1687
|
switch (r) {
|
|
@@ -1675,13 +1690,13 @@ function Fr(n, e) {
|
|
|
1675
1690
|
case "!=":
|
|
1676
1691
|
return t !== o;
|
|
1677
1692
|
case "<":
|
|
1678
|
-
return
|
|
1693
|
+
return oe(t, o) < 0;
|
|
1679
1694
|
case "<=":
|
|
1680
|
-
return
|
|
1695
|
+
return oe(t, o) <= 0;
|
|
1681
1696
|
case ">":
|
|
1682
|
-
return
|
|
1697
|
+
return oe(t, o) > 0;
|
|
1683
1698
|
case ">=":
|
|
1684
|
-
return
|
|
1699
|
+
return oe(t, o) >= 0;
|
|
1685
1700
|
case "array-contains":
|
|
1686
1701
|
return Array.isArray(t) && t.includes(o);
|
|
1687
1702
|
case "in":
|
|
@@ -1696,24 +1711,24 @@ function Fr(n, e) {
|
|
|
1696
1711
|
);
|
|
1697
1712
|
}
|
|
1698
1713
|
}
|
|
1699
|
-
function
|
|
1700
|
-
return e.every((t) =>
|
|
1714
|
+
function Kr(n, e) {
|
|
1715
|
+
return e.every((t) => Br(n, t));
|
|
1701
1716
|
}
|
|
1702
|
-
function
|
|
1717
|
+
function zr(n) {
|
|
1703
1718
|
return (e, t) => {
|
|
1704
1719
|
if (n) {
|
|
1705
|
-
let r =
|
|
1720
|
+
let r = ze(e.data, n.field), o = ze(t.data, n.field), i = oe(r, o);
|
|
1706
1721
|
if (i !== 0)
|
|
1707
1722
|
return n.direction === "desc" ? -i : i;
|
|
1708
1723
|
}
|
|
1709
1724
|
return e.id < t.id ? -1 : e.id > t.id ? 1 : 0;
|
|
1710
1725
|
};
|
|
1711
1726
|
}
|
|
1712
|
-
function
|
|
1727
|
+
function Hr(n, e) {
|
|
1713
1728
|
let t = n.findIndex((r) => r.id === e.docId);
|
|
1714
1729
|
return t === -1 ? n : e.type === "startAfter" ? n.slice(t + 1) : n.slice(0, t);
|
|
1715
1730
|
}
|
|
1716
|
-
var
|
|
1731
|
+
var X = class n {
|
|
1717
1732
|
/**
|
|
1718
1733
|
* Avalia um `QueryDescriptor` contra um array de `OfflineDoc`.
|
|
1719
1734
|
*
|
|
@@ -1727,9 +1742,9 @@ var J = class n {
|
|
|
1727
1742
|
evaluate(e, t) {
|
|
1728
1743
|
let r = e.filter((l) => !l.meta.deleted), o = t.where ?? [];
|
|
1729
1744
|
o.length > 0 && (r = r.filter(
|
|
1730
|
-
(l) =>
|
|
1745
|
+
(l) => Kr(l.data, o)
|
|
1731
1746
|
));
|
|
1732
|
-
let i =
|
|
1747
|
+
let i = zr(t.orderBy), s = [...r].sort(i), a = t.cursor ? Hr(s, t.cursor) : s, d = Math.min(t.limit ?? 20, 500);
|
|
1733
1748
|
return {
|
|
1734
1749
|
docs: a.slice(0, d).map((l) => ({ id: l.id, data: l.data })),
|
|
1735
1750
|
// `incomplete` é sempre true aqui — o QueryEngine não sabe se o cache
|
|
@@ -1749,7 +1764,7 @@ var J = class n {
|
|
|
1749
1764
|
};
|
|
1750
1765
|
|
|
1751
1766
|
// src/db/offline/local-store.ts
|
|
1752
|
-
var
|
|
1767
|
+
var Gr = 1, B = "documents", K = "mutations", ie = "query_cache", Se = "sync_meta", Y = "conflict_log", Te = class {
|
|
1753
1768
|
db = null;
|
|
1754
1769
|
dbName;
|
|
1755
1770
|
constructor(e) {
|
|
@@ -1761,22 +1776,22 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1761
1776
|
* Idempotente — chamadas subsequentes são no-ops se o banco já está aberto.
|
|
1762
1777
|
*/
|
|
1763
1778
|
async open() {
|
|
1764
|
-
this.db === null && (this.db = await openDB(this.dbName,
|
|
1779
|
+
this.db === null && (this.db = await openDB(this.dbName, Gr, {
|
|
1765
1780
|
upgrade(e) {
|
|
1766
|
-
if (!e.objectStoreNames.contains(
|
|
1767
|
-
let t = e.createObjectStore(
|
|
1781
|
+
if (!e.objectStoreNames.contains(B)) {
|
|
1782
|
+
let t = e.createObjectStore(B, {
|
|
1768
1783
|
keyPath: ["collection", "id"]
|
|
1769
1784
|
});
|
|
1770
1785
|
t.createIndex("by_collection", "collection"), t.createIndex("by_collection_state", ["collection", "meta.state"]), t.createIndex("by_updatedAtServer", "meta.updatedAtServer");
|
|
1771
1786
|
}
|
|
1772
|
-
if (!e.objectStoreNames.contains(
|
|
1773
|
-
let t = e.createObjectStore(
|
|
1787
|
+
if (!e.objectStoreNames.contains(K)) {
|
|
1788
|
+
let t = e.createObjectStore(K, {
|
|
1774
1789
|
keyPath: "mutationId"
|
|
1775
1790
|
});
|
|
1776
1791
|
t.createIndex("by_seq", "seq"), t.createIndex("by_status", "status"), t.createIndex("by_doc", ["collection", "docId"]), t.createIndex("by_batch", "batchId");
|
|
1777
1792
|
}
|
|
1778
|
-
if (e.objectStoreNames.contains(
|
|
1779
|
-
let t = e.createObjectStore(
|
|
1793
|
+
if (e.objectStoreNames.contains(ie) || e.createObjectStore(ie, { keyPath: "queryHash" }), e.objectStoreNames.contains(Se) || e.createObjectStore(Se, { keyPath: "key" }), !e.objectStoreNames.contains(Y)) {
|
|
1794
|
+
let t = e.createObjectStore(Y, {
|
|
1780
1795
|
keyPath: "id",
|
|
1781
1796
|
autoIncrement: true
|
|
1782
1797
|
});
|
|
@@ -1818,14 +1833,14 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1818
1833
|
* Retorna tombstones (deleted: true) — o chamador decide se deve mostrá-los.
|
|
1819
1834
|
*/
|
|
1820
1835
|
async getDoc(e, t) {
|
|
1821
|
-
return await this.assertOpen().get(
|
|
1836
|
+
return await this.assertOpen().get(B, [e, t]) ?? null;
|
|
1822
1837
|
}
|
|
1823
1838
|
/**
|
|
1824
1839
|
* Insere ou atualiza um documento na store `documents`.
|
|
1825
1840
|
* O documento é identificado pelo keyPath composto `[collection, id]`.
|
|
1826
1841
|
*/
|
|
1827
1842
|
async putDoc(e) {
|
|
1828
|
-
await this.assertOpen().put(
|
|
1843
|
+
await this.assertOpen().put(B, e);
|
|
1829
1844
|
}
|
|
1830
1845
|
/**
|
|
1831
1846
|
* Marca um documento como tombstone (`deleted: true`).
|
|
@@ -1833,8 +1848,8 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1833
1848
|
* No-op se o documento não existir.
|
|
1834
1849
|
*/
|
|
1835
1850
|
async deleteDoc(e, t) {
|
|
1836
|
-
let r = this.assertOpen(), o = await r.get(
|
|
1837
|
-
o && await r.put(
|
|
1851
|
+
let r = this.assertOpen(), o = await r.get(B, [e, t]);
|
|
1852
|
+
o && await r.put(B, {
|
|
1838
1853
|
...o,
|
|
1839
1854
|
meta: {
|
|
1840
1855
|
...o.meta,
|
|
@@ -1850,8 +1865,8 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1850
1865
|
* e delega a filtragem/ordenação/paginação ao QueryEngine (que opera em memória).
|
|
1851
1866
|
*/
|
|
1852
1867
|
async listDocs(e, t) {
|
|
1853
|
-
let o = await this.assertOpen().getAllFromIndex(
|
|
1854
|
-
return
|
|
1868
|
+
let o = await this.assertOpen().getAllFromIndex(B, "by_collection", e);
|
|
1869
|
+
return X.evaluate(o, t);
|
|
1855
1870
|
}
|
|
1856
1871
|
// ─── Sync meta (key-value) ──────────────────────────────────────────────────
|
|
1857
1872
|
/**
|
|
@@ -1862,14 +1877,14 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1862
1877
|
* 'lastFullResyncAt', 'leaderTabId'.
|
|
1863
1878
|
*/
|
|
1864
1879
|
async getMeta(e) {
|
|
1865
|
-
let r = await this.assertOpen().get(
|
|
1880
|
+
let r = await this.assertOpen().get(Se, e);
|
|
1866
1881
|
return r ? r.value : null;
|
|
1867
1882
|
}
|
|
1868
1883
|
/**
|
|
1869
1884
|
* Armazena ou atualiza um valor na store `sync_meta`.
|
|
1870
1885
|
*/
|
|
1871
1886
|
async setMeta(e, t) {
|
|
1872
|
-
await this.assertOpen().put(
|
|
1887
|
+
await this.assertOpen().put(Se, { key: e, value: t });
|
|
1873
1888
|
}
|
|
1874
1889
|
// ─── Conflict log ───────────────────────────────────────────────────────────
|
|
1875
1890
|
/**
|
|
@@ -1877,7 +1892,7 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1877
1892
|
* O `id` é autoIncrement — não deve ser fornecido pelo chamador.
|
|
1878
1893
|
*/
|
|
1879
1894
|
async appendConflict(e) {
|
|
1880
|
-
let r = await this.assertOpen().add(
|
|
1895
|
+
let r = await this.assertOpen().add(Y, e);
|
|
1881
1896
|
return { ...e, id: r };
|
|
1882
1897
|
}
|
|
1883
1898
|
/**
|
|
@@ -1885,15 +1900,15 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1885
1900
|
* Filtra por `delivered` se a opção for fornecida.
|
|
1886
1901
|
*/
|
|
1887
1902
|
async listConflicts(e) {
|
|
1888
|
-
let r = await this.assertOpen().getAll(
|
|
1903
|
+
let r = await this.assertOpen().getAll(Y);
|
|
1889
1904
|
return e?.delivered !== void 0 ? r.filter((o) => o.delivered === e.delivered) : r;
|
|
1890
1905
|
}
|
|
1891
1906
|
/**
|
|
1892
1907
|
* Marca um registro do `conflict_log` como entregue ao produto.
|
|
1893
1908
|
*/
|
|
1894
1909
|
async markConflictDelivered(e) {
|
|
1895
|
-
let t = this.assertOpen(), r = await t.get(
|
|
1896
|
-
r && await t.put(
|
|
1910
|
+
let t = this.assertOpen(), r = await t.get(Y, e);
|
|
1911
|
+
r && await t.put(Y, { ...r, delivered: true });
|
|
1897
1912
|
}
|
|
1898
1913
|
// ─── Mutations (acessores usados pelo MutationQueue) ────────────────────────
|
|
1899
1914
|
/**
|
|
@@ -1901,13 +1916,13 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1901
1916
|
* Key: `mutationId`.
|
|
1902
1917
|
*/
|
|
1903
1918
|
async putMutation(e) {
|
|
1904
|
-
await this.assertOpen().put(
|
|
1919
|
+
await this.assertOpen().put(K, e);
|
|
1905
1920
|
}
|
|
1906
1921
|
/**
|
|
1907
1922
|
* Retorna uma mutação pelo `mutationId`, ou `null` se não existir.
|
|
1908
1923
|
*/
|
|
1909
1924
|
async getMutation(e) {
|
|
1910
|
-
return await this.assertOpen().get(
|
|
1925
|
+
return await this.assertOpen().get(K, e) ?? null;
|
|
1911
1926
|
}
|
|
1912
1927
|
/**
|
|
1913
1928
|
* Lista mutações com filtros opcionais.
|
|
@@ -1915,14 +1930,14 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1915
1930
|
*/
|
|
1916
1931
|
async listMutations(e) {
|
|
1917
1932
|
let t = this.assertOpen(), r;
|
|
1918
|
-
return e?.status !== void 0 ? r = await t.getAllFromIndex(
|
|
1933
|
+
return e?.status !== void 0 ? r = await t.getAllFromIndex(K, "by_status", e.status) : e?.collection !== void 0 && e.docId !== void 0 ? r = await t.getAllFromIndex(K, "by_doc", [e.collection, e.docId]) : r = await t.getAllFromIndex(K, "by_seq"), r.sort((o, i) => o.seq - i.seq);
|
|
1919
1934
|
}
|
|
1920
1935
|
/**
|
|
1921
1936
|
* Remove uma mutação pelo `mutationId`.
|
|
1922
1937
|
* No-op se não existir.
|
|
1923
1938
|
*/
|
|
1924
1939
|
async deleteMutation(e) {
|
|
1925
|
-
await this.assertOpen().delete(
|
|
1940
|
+
await this.assertOpen().delete(K, e);
|
|
1926
1941
|
}
|
|
1927
1942
|
// ─── Collection discovery ────────────────────────────────────────────────────
|
|
1928
1943
|
/**
|
|
@@ -1935,7 +1950,7 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1935
1950
|
* coletar os valores únicos de forma eficiente (sem carregar os docs completos).
|
|
1936
1951
|
*/
|
|
1937
1952
|
async listCollections() {
|
|
1938
|
-
let t = await this.assertOpen().getAllFromIndex(
|
|
1953
|
+
let t = await this.assertOpen().getAllFromIndex(B, "by_collection"), r = /* @__PURE__ */ new Set();
|
|
1939
1954
|
for (let o of t)
|
|
1940
1955
|
r.add(o.collection);
|
|
1941
1956
|
return Array.from(r);
|
|
@@ -1945,24 +1960,24 @@ var Br = 1, V = "documents", B = "mutations", oe = "query_cache", ke = "sync_met
|
|
|
1945
1960
|
* Retorna a entrada de `query_cache` para um hash de query, ou `null`.
|
|
1946
1961
|
*/
|
|
1947
1962
|
async getQueryCache(e) {
|
|
1948
|
-
return await this.assertOpen().get(
|
|
1963
|
+
return await this.assertOpen().get(ie, e) ?? null;
|
|
1949
1964
|
}
|
|
1950
1965
|
/**
|
|
1951
1966
|
* Insere ou atualiza uma entrada de `query_cache`.
|
|
1952
1967
|
*/
|
|
1953
1968
|
async putQueryCache(e) {
|
|
1954
|
-
await this.assertOpen().put(
|
|
1969
|
+
await this.assertOpen().put(ie, e);
|
|
1955
1970
|
}
|
|
1956
1971
|
/**
|
|
1957
1972
|
* Remove uma entrada de `query_cache` pelo queryHash.
|
|
1958
1973
|
*/
|
|
1959
1974
|
async deleteQueryCache(e) {
|
|
1960
|
-
await this.assertOpen().delete(
|
|
1975
|
+
await this.assertOpen().delete(ie, e);
|
|
1961
1976
|
}
|
|
1962
1977
|
};
|
|
1963
1978
|
|
|
1964
1979
|
// src/db/offline/memory-store.ts
|
|
1965
|
-
var
|
|
1980
|
+
var Re = class {
|
|
1966
1981
|
// store `documents` — key: `${collection}\0${id}`
|
|
1967
1982
|
_docs = /* @__PURE__ */ new Map();
|
|
1968
1983
|
// store `mutations` — key: mutationId
|
|
@@ -2010,7 +2025,7 @@ var Te = class {
|
|
|
2010
2025
|
let r = Array.from(this._docs.values()).filter(
|
|
2011
2026
|
(o) => o.collection === e
|
|
2012
2027
|
);
|
|
2013
|
-
return
|
|
2028
|
+
return X.evaluate(r, t);
|
|
2014
2029
|
}
|
|
2015
2030
|
// ─── Sync meta ──────────────────────────────────────────────────────────────
|
|
2016
2031
|
async getMeta(e) {
|
|
@@ -2067,13 +2082,13 @@ var Te = class {
|
|
|
2067
2082
|
};
|
|
2068
2083
|
|
|
2069
2084
|
// src/db/offline/mutation-queue.ts
|
|
2070
|
-
function
|
|
2085
|
+
function He() {
|
|
2071
2086
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (n) => {
|
|
2072
2087
|
let e = Math.random() * 16 | 0;
|
|
2073
2088
|
return (n === "x" ? e : e & 3 | 8).toString(16);
|
|
2074
2089
|
});
|
|
2075
2090
|
}
|
|
2076
|
-
var
|
|
2091
|
+
var Ie = class {
|
|
2077
2092
|
store;
|
|
2078
2093
|
/**
|
|
2079
2094
|
* Ponteiro de sequência local.
|
|
@@ -2169,7 +2184,7 @@ var Re = class {
|
|
|
2169
2184
|
* Atômico: a persistência final é uma única operação putMutation.
|
|
2170
2185
|
*/
|
|
2171
2186
|
async enqueue(e) {
|
|
2172
|
-
let { collection: t, op: r, payload: o, baseVersion: i, batchId: s, upsert: a } = e, d = e.docId ?? (r === "add" ?
|
|
2187
|
+
let { collection: t, op: r, payload: o, baseVersion: i, batchId: s, upsert: a } = e, d = e.docId ?? (r === "add" ? He() : "");
|
|
2173
2188
|
await this.syncSeq();
|
|
2174
2189
|
let l = (await this.store.listMutations({ collection: t, docId: d })).filter((m) => m.status === "queued").sort((m, h) => h.seq - m.seq)[0];
|
|
2175
2190
|
if (l !== void 0) {
|
|
@@ -2178,7 +2193,7 @@ var Re = class {
|
|
|
2178
2193
|
if ("removed" in m)
|
|
2179
2194
|
return await this.store.deleteMutation(l.mutationId), {
|
|
2180
2195
|
seq: l.seq,
|
|
2181
|
-
mutationId:
|
|
2196
|
+
mutationId: He(),
|
|
2182
2197
|
collection: t,
|
|
2183
2198
|
docId: d,
|
|
2184
2199
|
op: "remove",
|
|
@@ -2196,7 +2211,7 @@ var Re = class {
|
|
|
2196
2211
|
}
|
|
2197
2212
|
let f = {
|
|
2198
2213
|
seq: this.nextSeq(),
|
|
2199
|
-
mutationId:
|
|
2214
|
+
mutationId: He(),
|
|
2200
2215
|
collection: t,
|
|
2201
2216
|
docId: d,
|
|
2202
2217
|
op: r,
|
|
@@ -2309,55 +2324,55 @@ var Re = class {
|
|
|
2309
2324
|
};
|
|
2310
2325
|
|
|
2311
2326
|
// src/db/field-value.ts
|
|
2312
|
-
var
|
|
2313
|
-
function
|
|
2327
|
+
var Qe = "__neetru__";
|
|
2328
|
+
function Jr() {
|
|
2314
2329
|
return { __neetru__: "serverTimestamp" };
|
|
2315
2330
|
}
|
|
2316
|
-
function
|
|
2331
|
+
function Xr(n) {
|
|
2317
2332
|
if (typeof n != "number" || !Number.isFinite(n))
|
|
2318
2333
|
throw new TypeError(
|
|
2319
2334
|
`increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
|
|
2320
2335
|
);
|
|
2321
2336
|
return { __neetru__: "increment", operand: n };
|
|
2322
2337
|
}
|
|
2323
|
-
function
|
|
2324
|
-
return typeof n == "object" && n !== null &&
|
|
2338
|
+
function Q(n) {
|
|
2339
|
+
return typeof n == "object" && n !== null && Qe in n && typeof n[Qe] == "string";
|
|
2325
2340
|
}
|
|
2326
|
-
function
|
|
2327
|
-
return
|
|
2341
|
+
function Zt(n) {
|
|
2342
|
+
return Q(n) && n.__neetru__ === "serverTimestamp";
|
|
2328
2343
|
}
|
|
2329
|
-
function
|
|
2330
|
-
return
|
|
2344
|
+
function en(n) {
|
|
2345
|
+
return Q(n) && n.__neetru__ === "increment" && typeof n.operand == "number" && Number.isFinite(n.operand);
|
|
2331
2346
|
}
|
|
2332
|
-
function
|
|
2333
|
-
return
|
|
2347
|
+
function Yr(n, e) {
|
|
2348
|
+
return Zt(n) ? Date.now() : en(n) ? (typeof e == "number" && Number.isFinite(e) ? e : 0) + n.operand : n;
|
|
2334
2349
|
}
|
|
2335
2350
|
function G(n, e) {
|
|
2336
2351
|
let t = false, r = {};
|
|
2337
2352
|
for (let [o, i] of Object.entries(n))
|
|
2338
|
-
|
|
2353
|
+
Q(i) ? (t = true, r[o] = Yr(i, e?.[o])) : r[o] = i;
|
|
2339
2354
|
return t ? r : n;
|
|
2340
2355
|
}
|
|
2341
|
-
function
|
|
2356
|
+
function Ge(n) {
|
|
2342
2357
|
for (let e of Object.values(n))
|
|
2343
|
-
if (
|
|
2358
|
+
if (Q(e)) return true;
|
|
2344
2359
|
return false;
|
|
2345
2360
|
}
|
|
2346
2361
|
|
|
2347
2362
|
// src/db/offline/sync-engine.ts
|
|
2348
|
-
var
|
|
2349
|
-
function
|
|
2350
|
-
return n !== null &&
|
|
2363
|
+
var Zr = 8, eo = 1e3, to = 300 * 1e3, Je = "truncatedCollections";
|
|
2364
|
+
function no(n) {
|
|
2365
|
+
return n !== null && Ge(n);
|
|
2351
2366
|
}
|
|
2352
|
-
function
|
|
2367
|
+
function ro(n) {
|
|
2353
2368
|
if (n === null) return null;
|
|
2354
|
-
if (!
|
|
2369
|
+
if (!Ge(n)) return n;
|
|
2355
2370
|
let e = {};
|
|
2356
2371
|
for (let [t, r] of Object.entries(n))
|
|
2357
|
-
|
|
2372
|
+
Q(r) || (e[t] = r);
|
|
2358
2373
|
return e;
|
|
2359
2374
|
}
|
|
2360
|
-
var
|
|
2375
|
+
var Ce = class {
|
|
2361
2376
|
_store;
|
|
2362
2377
|
_queue;
|
|
2363
2378
|
_resolver;
|
|
@@ -2551,13 +2566,13 @@ var Ie = class {
|
|
|
2551
2566
|
}), s.push({ type: "removed", collection: e, doc: { id: t, data: a.data } }));
|
|
2552
2567
|
return;
|
|
2553
2568
|
}
|
|
2554
|
-
let p =
|
|
2569
|
+
let p = ro(i.payload) ?? a?.data ?? {}, l = {
|
|
2555
2570
|
collection: e,
|
|
2556
2571
|
id: t,
|
|
2557
2572
|
data: i.op === "update" ? { ...a?.data ?? {}, ...p } : (
|
|
2558
2573
|
// add/set: se o payload tinha sentinels, o cache otimista (existing.data)
|
|
2559
2574
|
// é a fonte de verdade até o pull; senão usa o payload literal.
|
|
2560
|
-
|
|
2575
|
+
no(i.payload) ? { ...a?.data ?? {}, ...p } : p
|
|
2561
2576
|
),
|
|
2562
2577
|
meta: {
|
|
2563
2578
|
serverVersion: r,
|
|
@@ -2710,7 +2725,7 @@ var Ie = class {
|
|
|
2710
2725
|
* pending do doc no cache + registra `lastError`/dispara `onError`.
|
|
2711
2726
|
*/
|
|
2712
2727
|
async _retryOrDeadLetter(e, t, r) {
|
|
2713
|
-
if (e.attempts + 1 <
|
|
2728
|
+
if (e.attempts + 1 < Zr) {
|
|
2714
2729
|
await this._queue.markRetry(e.mutationId, t);
|
|
2715
2730
|
return;
|
|
2716
2731
|
}
|
|
@@ -2751,7 +2766,7 @@ var Ie = class {
|
|
|
2751
2766
|
}
|
|
2752
2767
|
/** Backoff exponencial keyed em `attempts`, com teto `BACKOFF_CAP_MS`. */
|
|
2753
2768
|
_backoffDelayMs(e) {
|
|
2754
|
-
return Math.min(
|
|
2769
|
+
return Math.min(eo * 2 ** (e - 1), to);
|
|
2755
2770
|
}
|
|
2756
2771
|
// ─── FASE 2 — pull (reconciliar o cache) ─────────────────────────────────────
|
|
2757
2772
|
/**
|
|
@@ -2784,7 +2799,7 @@ var Ie = class {
|
|
|
2784
2799
|
let r = [];
|
|
2785
2800
|
await this._applyServerDocs(t.docs, r, true);
|
|
2786
2801
|
let o = t.truncatedCollections ?? [], i = new Set(o);
|
|
2787
|
-
await this._store.setMeta(
|
|
2802
|
+
await this._store.setMeta(Je, o);
|
|
2788
2803
|
let s = new Set(
|
|
2789
2804
|
t.docs.map((a) => `${a.collection}::${a.id}`)
|
|
2790
2805
|
);
|
|
@@ -3003,10 +3018,10 @@ var Ie = class {
|
|
|
3003
3018
|
};
|
|
3004
3019
|
|
|
3005
3020
|
// src/db/offline/conflict-resolver.ts
|
|
3006
|
-
function
|
|
3021
|
+
function tn(n, e) {
|
|
3007
3022
|
return e === null ? false : n === null ? true : e > n;
|
|
3008
3023
|
}
|
|
3009
|
-
var
|
|
3024
|
+
var Ae = class n {
|
|
3010
3025
|
/**
|
|
3011
3026
|
* Resolve um conflito com base na operação da mutação (auto-dispatch).
|
|
3012
3027
|
*
|
|
@@ -3040,7 +3055,7 @@ var Ce = class n {
|
|
|
3040
3055
|
resolvedData: t.data,
|
|
3041
3056
|
conflictRecord: null
|
|
3042
3057
|
};
|
|
3043
|
-
if (!
|
|
3058
|
+
if (!tn(
|
|
3044
3059
|
e.meta.updatedAtServer,
|
|
3045
3060
|
t.meta.updatedAtServer
|
|
3046
3061
|
))
|
|
@@ -3087,7 +3102,7 @@ var Ce = class n {
|
|
|
3087
3102
|
let i = t.data;
|
|
3088
3103
|
if (e === null)
|
|
3089
3104
|
return { outcome: "no_conflict", resolvedData: { ...i, ...r.payload ?? {} }, conflictRecord: null };
|
|
3090
|
-
if (!
|
|
3105
|
+
if (!tn(
|
|
3091
3106
|
e.meta.updatedAtServer,
|
|
3092
3107
|
t.meta.updatedAtServer
|
|
3093
3108
|
))
|
|
@@ -3165,10 +3180,10 @@ var Ce = class n {
|
|
|
3165
3180
|
};
|
|
3166
3181
|
|
|
3167
3182
|
// src/db/offline/change-bus.ts
|
|
3168
|
-
function
|
|
3183
|
+
function oo(n) {
|
|
3169
3184
|
return `${n.collection}::${n.doc.id}`;
|
|
3170
3185
|
}
|
|
3171
|
-
var
|
|
3186
|
+
var Ee = class {
|
|
3172
3187
|
/** Listeners filtrados por coleção. */
|
|
3173
3188
|
_collectionListeners = /* @__PURE__ */ new Map();
|
|
3174
3189
|
/** Listeners globais (todas as coleções). */
|
|
@@ -3213,7 +3228,7 @@ var Ae = class {
|
|
|
3213
3228
|
if (e.length === 0) return;
|
|
3214
3229
|
let t = /* @__PURE__ */ new Map();
|
|
3215
3230
|
for (let i of e)
|
|
3216
|
-
t.set(
|
|
3231
|
+
t.set(oo(i), i);
|
|
3217
3232
|
let r = Array.from(t.values()), o = /* @__PURE__ */ new Map();
|
|
3218
3233
|
for (let i of r)
|
|
3219
3234
|
o.has(i.collection) || o.set(i.collection, []), o.get(i.collection).push(i);
|
|
@@ -3252,7 +3267,7 @@ var Ae = class {
|
|
|
3252
3267
|
};
|
|
3253
3268
|
|
|
3254
3269
|
// src/db/offline/connectivity-monitor.ts
|
|
3255
|
-
var
|
|
3270
|
+
var Pe = class {
|
|
3256
3271
|
_state;
|
|
3257
3272
|
_listeners = /* @__PURE__ */ new Set();
|
|
3258
3273
|
_nav;
|
|
@@ -3354,7 +3369,7 @@ var Ee = class {
|
|
|
3354
3369
|
};
|
|
3355
3370
|
|
|
3356
3371
|
// src/db/offline/tab-coordinator.ts
|
|
3357
|
-
var
|
|
3372
|
+
var se = class {
|
|
3358
3373
|
_lockName;
|
|
3359
3374
|
_channelName;
|
|
3360
3375
|
_lockManager;
|
|
@@ -3531,26 +3546,26 @@ var ie = class {
|
|
|
3531
3546
|
};
|
|
3532
3547
|
|
|
3533
3548
|
// src/db/collection-ref.ts
|
|
3534
|
-
|
|
3535
|
-
function
|
|
3549
|
+
H();
|
|
3550
|
+
function io() {
|
|
3536
3551
|
return typeof indexedDB > "u" || typeof window > "u";
|
|
3537
3552
|
}
|
|
3538
|
-
var
|
|
3539
|
-
function
|
|
3540
|
-
if (!
|
|
3553
|
+
var nn = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
3554
|
+
function so(n) {
|
|
3555
|
+
if (!nn.test(n))
|
|
3541
3556
|
throw new v(
|
|
3542
3557
|
"db_invalid_query",
|
|
3543
|
-
`Nome de cole\xE7\xE3o inv\xE1lido: "${n}". Deve seguir o padr\xE3o ${
|
|
3558
|
+
`Nome de cole\xE7\xE3o inv\xE1lido: "${n}". Deve seguir o padr\xE3o ${nn}.`
|
|
3544
3559
|
);
|
|
3545
3560
|
}
|
|
3546
|
-
function
|
|
3561
|
+
function Z(n, e = "id") {
|
|
3547
3562
|
if (!n || typeof n != "string" || n.trim() === "")
|
|
3548
3563
|
throw new v(
|
|
3549
3564
|
"db_invalid_query",
|
|
3550
3565
|
`${e} \xE9 obrigat\xF3rio e deve ser uma string n\xE3o-vazia.`
|
|
3551
3566
|
);
|
|
3552
3567
|
}
|
|
3553
|
-
function
|
|
3568
|
+
function ao(n) {
|
|
3554
3569
|
let e = {};
|
|
3555
3570
|
if (n?.where && (e.where = n.where.map((t) => ({
|
|
3556
3571
|
field: t.field,
|
|
@@ -3567,12 +3582,12 @@ function no(n) {
|
|
|
3567
3582
|
}
|
|
3568
3583
|
return e;
|
|
3569
3584
|
}
|
|
3570
|
-
function
|
|
3585
|
+
function co(n, e) {
|
|
3571
3586
|
if (n.length < e) return null;
|
|
3572
3587
|
let t = n[n.length - 1];
|
|
3573
3588
|
return t ? btoa(JSON.stringify({ type: "startAfter", docId: t.id })) : null;
|
|
3574
3589
|
}
|
|
3575
|
-
var
|
|
3590
|
+
var Xe = class {
|
|
3576
3591
|
constructor(e, t, r, o, i, s) {
|
|
3577
3592
|
this._collection = e;
|
|
3578
3593
|
this._store = t;
|
|
@@ -3614,7 +3629,7 @@ var Qe = class {
|
|
|
3614
3629
|
}
|
|
3615
3630
|
/** Constrói um DbListResult para a coleção com query opcional. */
|
|
3616
3631
|
async _buildListResult(e) {
|
|
3617
|
-
let t =
|
|
3632
|
+
let t = ao(e), r = t.limit ?? 20, o = await this._store.listDocs(this._collection, t), i = await this._hasPendingWrites(), s = this._isOnline(), a = this._engine.getSyncState(), d = co(o.docs, r), p = await this._store.getMeta(Je), l = Array.isArray(p) && p.includes(this._collection), u = !s || a.status === "offline" || l, f = i || a.lastSyncedAt === null || u;
|
|
3618
3633
|
return {
|
|
3619
3634
|
docs: o.docs.map((m) => ({ id: m.id, data: m.data })),
|
|
3620
3635
|
nextCursor: d,
|
|
@@ -3627,7 +3642,7 @@ var Qe = class {
|
|
|
3627
3642
|
}
|
|
3628
3643
|
// ── CRUD ────────────────────────────────────────────────────────────────────
|
|
3629
3644
|
async get(e) {
|
|
3630
|
-
return
|
|
3645
|
+
return Z(e), this._buildGetResult(e);
|
|
3631
3646
|
}
|
|
3632
3647
|
async list(e) {
|
|
3633
3648
|
return this._buildListResult(e);
|
|
@@ -3660,7 +3675,7 @@ var Qe = class {
|
|
|
3660
3675
|
}]), { ok: true, id: i };
|
|
3661
3676
|
}
|
|
3662
3677
|
async set(e, t) {
|
|
3663
|
-
|
|
3678
|
+
Z(e);
|
|
3664
3679
|
let r = await this._store.getDoc(this._collection, e), o = t, i = G(o, void 0), s = await this._queue.enqueue({
|
|
3665
3680
|
collection: this._collection,
|
|
3666
3681
|
docId: e,
|
|
@@ -3689,7 +3704,7 @@ var Qe = class {
|
|
|
3689
3704
|
}]), { ok: true };
|
|
3690
3705
|
}
|
|
3691
3706
|
async update(e, t, r) {
|
|
3692
|
-
|
|
3707
|
+
Z(e);
|
|
3693
3708
|
let o = await this._store.getDoc(this._collection, e), i = t, s = o?.meta.deleted ? void 0 : o?.data, a = G(i, s), d = o?.meta.deleted ? { ...a } : { ...o?.data ?? {}, ...a }, p = await this._queue.enqueue({
|
|
3694
3709
|
collection: this._collection,
|
|
3695
3710
|
docId: e,
|
|
@@ -3723,7 +3738,7 @@ var Qe = class {
|
|
|
3723
3738
|
}]), { ok: true };
|
|
3724
3739
|
}
|
|
3725
3740
|
async remove(e) {
|
|
3726
|
-
|
|
3741
|
+
Z(e);
|
|
3727
3742
|
let t = await this._store.getDoc(this._collection, e);
|
|
3728
3743
|
return !t || t.meta.deleted, await this._queue.enqueue({
|
|
3729
3744
|
collection: this._collection,
|
|
@@ -3835,7 +3850,7 @@ var Qe = class {
|
|
|
3835
3850
|
}
|
|
3836
3851
|
// ── Realtime ─────────────────────────────────────────────────────────────────
|
|
3837
3852
|
onDoc(e, t) {
|
|
3838
|
-
return
|
|
3853
|
+
return Z(e), this._buildGetResult(e).then((r) => {
|
|
3839
3854
|
t(r ? r.docs[0]?.data ?? null : null);
|
|
3840
3855
|
}).catch(() => t(null)), this._bus.subscribe(this._collection, (r) => {
|
|
3841
3856
|
let o = r.find((i) => i.doc.id === e);
|
|
@@ -3894,7 +3909,7 @@ var Qe = class {
|
|
|
3894
3909
|
};
|
|
3895
3910
|
}
|
|
3896
3911
|
doc(e) {
|
|
3897
|
-
|
|
3912
|
+
Z(e);
|
|
3898
3913
|
let t = this;
|
|
3899
3914
|
return {
|
|
3900
3915
|
get id() {
|
|
@@ -3947,7 +3962,7 @@ var Qe = class {
|
|
|
3947
3962
|
}
|
|
3948
3963
|
};
|
|
3949
3964
|
}
|
|
3950
|
-
},
|
|
3965
|
+
}, Ye = class {
|
|
3951
3966
|
_store;
|
|
3952
3967
|
_queue;
|
|
3953
3968
|
_bus;
|
|
@@ -3957,7 +3972,7 @@ var Qe = class {
|
|
|
3957
3972
|
this._store = e.store, this._queue = e.queue, this._bus = e.bus, this._engine = e.engine, this._connectivity = e.connectivity;
|
|
3958
3973
|
}
|
|
3959
3974
|
collection(e) {
|
|
3960
|
-
return
|
|
3975
|
+
return so(e), new Xe(
|
|
3961
3976
|
e,
|
|
3962
3977
|
this._store,
|
|
3963
3978
|
this._queue,
|
|
@@ -3986,10 +4001,10 @@ var Qe = class {
|
|
|
3986
4001
|
return this._engine.onError(e);
|
|
3987
4002
|
}
|
|
3988
4003
|
};
|
|
3989
|
-
async function
|
|
3990
|
-
let e =
|
|
4004
|
+
async function rn(n) {
|
|
4005
|
+
let e = io() ? new Re() : new Te(n.dbName);
|
|
3991
4006
|
await e.open();
|
|
3992
|
-
let t = new
|
|
4007
|
+
let t = new Ie(e), r = new Ae(), o = new Ee(), i = new Pe({
|
|
3993
4008
|
// Se startOnline=false, injeta um navigator falso
|
|
3994
4009
|
navigator: n.startOnline === false ? { onLine: false } : typeof navigator < "u" ? navigator : void 0
|
|
3995
4010
|
}), s = n.singleTab ? (
|
|
@@ -3999,10 +4014,10 @@ async function tn(n) {
|
|
|
3999
4014
|
onRoleChange: (d) => () => {
|
|
4000
4015
|
}
|
|
4001
4016
|
}
|
|
4002
|
-
) : new
|
|
4017
|
+
) : new se({
|
|
4003
4018
|
lockName: `neetru-offline:${n.dbName}`,
|
|
4004
4019
|
channelName: `neetru-offline:${n.dbName}`
|
|
4005
|
-
}), a = new
|
|
4020
|
+
}), a = new Ce({
|
|
4006
4021
|
store: e,
|
|
4007
4022
|
queue: t,
|
|
4008
4023
|
resolver: r,
|
|
@@ -4012,7 +4027,7 @@ async function tn(n) {
|
|
|
4012
4027
|
connectivity: i,
|
|
4013
4028
|
periodicSyncIntervalMs: n.periodicSyncIntervalMs ?? 300 * 1e3
|
|
4014
4029
|
});
|
|
4015
|
-
return i.start(), !n.singleTab && s instanceof
|
|
4030
|
+
return i.start(), !n.singleTab && s instanceof se && s.start(), new Ye({
|
|
4016
4031
|
store: e,
|
|
4017
4032
|
queue: t,
|
|
4018
4033
|
bus: o,
|
|
@@ -4022,11 +4037,11 @@ async function tn(n) {
|
|
|
4022
4037
|
}
|
|
4023
4038
|
|
|
4024
4039
|
// src/db/realtime/realtime-client.ts
|
|
4025
|
-
var
|
|
4026
|
-
function
|
|
4027
|
-
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++
|
|
4040
|
+
var lo = 0;
|
|
4041
|
+
function on() {
|
|
4042
|
+
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++lo}-${Math.random().toString(36).slice(2)}`;
|
|
4028
4043
|
}
|
|
4029
|
-
var
|
|
4044
|
+
var De = class {
|
|
4030
4045
|
// ── configuração ──────────────────────────────────────────────────────────
|
|
4031
4046
|
_gatewayUrl;
|
|
4032
4047
|
_wsFactory;
|
|
@@ -4064,7 +4079,7 @@ var Pe = class {
|
|
|
4064
4079
|
_pendingFrames = [];
|
|
4065
4080
|
// ── construtor ────────────────────────────────────────────────────────────
|
|
4066
4081
|
constructor(e) {
|
|
4067
|
-
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ??
|
|
4082
|
+
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ?? uo, 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();
|
|
4068
4083
|
}
|
|
4069
4084
|
// ── API pública ───────────────────────────────────────────────────────────
|
|
4070
4085
|
/**
|
|
@@ -4078,8 +4093,8 @@ var Pe = class {
|
|
|
4078
4093
|
*/
|
|
4079
4094
|
subscribe(e, t, r) {
|
|
4080
4095
|
if (this._closed)
|
|
4081
|
-
return
|
|
4082
|
-
let o =
|
|
4096
|
+
return on();
|
|
4097
|
+
let o = on();
|
|
4083
4098
|
this._subscriptions.set(o, {
|
|
4084
4099
|
subscriptionId: o,
|
|
4085
4100
|
collection: e,
|
|
@@ -4343,7 +4358,7 @@ var Pe = class {
|
|
|
4343
4358
|
_detachHandlers(e) {
|
|
4344
4359
|
e.onopen = null, e.onmessage = null, e.onclose = null, e.onerror = null;
|
|
4345
4360
|
}
|
|
4346
|
-
},
|
|
4361
|
+
}, uo = (n) => {
|
|
4347
4362
|
if (typeof WebSocket > "u")
|
|
4348
4363
|
throw new Error(
|
|
4349
4364
|
"[NeetruRealtimeClient] WebSocket n\xE3o dispon\xEDvel neste ambiente. Injete uma implementa\xE7\xE3o via `webSocketFactory` nas op\xE7\xF5es."
|
|
@@ -4352,11 +4367,11 @@ var Pe = class {
|
|
|
4352
4367
|
};
|
|
4353
4368
|
|
|
4354
4369
|
// src/db/client-db.ts
|
|
4355
|
-
var
|
|
4356
|
-
function
|
|
4357
|
-
return e._transport ? e._transport : n === "firestore" && e.firestoreTransport ? e.firestoreTransport : n === "nosql-vm" && e.realtimeGatewayUrl ?
|
|
4370
|
+
var To = (n) => `/api/sdk/v1/datastore/${encodeURIComponent(n)}`, xe = (n, e) => `/api/sdk/v1/datastore/${encodeURIComponent(n)}/${encodeURIComponent(e)}`, yn = 200;
|
|
4371
|
+
function Ro(n, e, t) {
|
|
4372
|
+
return e._transport ? e._transport : n === "firestore" && e.firestoreTransport ? e.firestoreTransport : n === "nosql-vm" && e.realtimeGatewayUrl ? Io(e.realtimeGatewayUrl, t, e) : bn(t);
|
|
4358
4373
|
}
|
|
4359
|
-
function
|
|
4374
|
+
function bn(n) {
|
|
4360
4375
|
return {
|
|
4361
4376
|
async pushMutations(e) {
|
|
4362
4377
|
if (!n)
|
|
@@ -4364,34 +4379,34 @@ function yn(n) {
|
|
|
4364
4379
|
"db_unavailable",
|
|
4365
4380
|
"[RestSyncTransport] config n\xE3o dispon\xEDvel \u2014 n\xE3o \xE9 poss\xEDvel enviar ao Core. Inicialize o transporte via createNeetruDb."
|
|
4366
4381
|
);
|
|
4367
|
-
let { httpRequest: t } = await Promise.resolve().then(() => (
|
|
4382
|
+
let { httpRequest: t } = await Promise.resolve().then(() => (F(), re)), r = [], o = n.tenantId ?? n.productId, i = o ? { "x-neetru-tenant": o } : void 0;
|
|
4368
4383
|
for (let s of e)
|
|
4369
4384
|
try {
|
|
4370
4385
|
let a;
|
|
4371
4386
|
s.op === "add" ? a = await t(n, {
|
|
4372
4387
|
method: "PUT",
|
|
4373
|
-
path:
|
|
4388
|
+
path: xe(s.collection, s.docId),
|
|
4374
4389
|
body: { data: s.payload ?? {} },
|
|
4375
4390
|
requireAuth: !0,
|
|
4376
4391
|
retries: 2,
|
|
4377
4392
|
headers: i
|
|
4378
4393
|
}) : s.op === "set" ? a = await t(n, {
|
|
4379
4394
|
method: "PUT",
|
|
4380
|
-
path:
|
|
4395
|
+
path: xe(s.collection, s.docId),
|
|
4381
4396
|
body: { data: s.payload ?? {} },
|
|
4382
4397
|
requireAuth: !0,
|
|
4383
4398
|
retries: 2,
|
|
4384
4399
|
headers: i
|
|
4385
4400
|
}) : s.op === "update" ? a = await t(n, {
|
|
4386
4401
|
method: "PATCH",
|
|
4387
|
-
path:
|
|
4402
|
+
path: xe(s.collection, s.docId),
|
|
4388
4403
|
body: { data: s.payload ?? {}, ...s.upsert ? { upsert: !0 } : {} },
|
|
4389
4404
|
requireAuth: !0,
|
|
4390
4405
|
retries: 2,
|
|
4391
4406
|
headers: i
|
|
4392
4407
|
}) : a = await t(n, {
|
|
4393
4408
|
method: "DELETE",
|
|
4394
|
-
path:
|
|
4409
|
+
path: xe(s.collection, s.docId),
|
|
4395
4410
|
requireAuth: !0,
|
|
4396
4411
|
retries: 2,
|
|
4397
4412
|
headers: i
|
|
@@ -4428,13 +4443,13 @@ function yn(n) {
|
|
|
4428
4443
|
async fullResync(e) {
|
|
4429
4444
|
if (!n)
|
|
4430
4445
|
return { docs: [], newWatermark: Date.now() };
|
|
4431
|
-
let { httpRequest: t } = await Promise.resolve().then(() => (
|
|
4446
|
+
let { httpRequest: t } = await Promise.resolve().then(() => (F(), re)), r = n.tenantId ?? n.productId, o = r ? { "x-neetru-tenant": r } : void 0, i = Date.now(), s = [], a = [];
|
|
4432
4447
|
for (let d of e) {
|
|
4433
4448
|
let p;
|
|
4434
4449
|
try {
|
|
4435
4450
|
p = await t(n, {
|
|
4436
4451
|
method: "GET",
|
|
4437
|
-
path:
|
|
4452
|
+
path: To(d),
|
|
4438
4453
|
requireAuth: !0,
|
|
4439
4454
|
retries: 2,
|
|
4440
4455
|
headers: o,
|
|
@@ -4442,7 +4457,7 @@ function yn(n) {
|
|
|
4442
4457
|
// TRUNCADAS — reportadas em `truncatedCollections` p/ o SyncEngine
|
|
4443
4458
|
// (a) NÃO rodar deleção-por-ausência e (b) sinalizar
|
|
4444
4459
|
// `DbListResult.truncated`. Paginação por cursor é tarefa Core (gated).
|
|
4445
|
-
query: { limit:
|
|
4460
|
+
query: { limit: yn }
|
|
4446
4461
|
});
|
|
4447
4462
|
} catch (f) {
|
|
4448
4463
|
let m = f instanceof Error ? f.message : String(f);
|
|
@@ -4452,26 +4467,26 @@ function yn(n) {
|
|
|
4452
4467
|
);
|
|
4453
4468
|
}
|
|
4454
4469
|
let l = p, u = Array.isArray(l?.items) ? l.items : [];
|
|
4455
|
-
u.length >=
|
|
4470
|
+
u.length >= yn && a.push(d);
|
|
4456
4471
|
for (let f of u) {
|
|
4457
4472
|
if (!f || typeof f != "object") continue;
|
|
4458
4473
|
let m = f, h = typeof m.id == "string" ? m.id : null;
|
|
4459
4474
|
if (!h) continue;
|
|
4460
|
-
let { id:
|
|
4475
|
+
let { id: _, ...I } = m, w = i, k = I._updatedAt;
|
|
4461
4476
|
if (typeof k == "number")
|
|
4462
4477
|
w = k;
|
|
4463
4478
|
else if (k !== null && typeof k == "object" && typeof k._seconds == "number")
|
|
4464
4479
|
w = k._seconds * 1e3;
|
|
4465
4480
|
else if (typeof k == "string") {
|
|
4466
|
-
let
|
|
4467
|
-
Number.isNaN(
|
|
4481
|
+
let y = Date.parse(k);
|
|
4482
|
+
Number.isNaN(y) || (w = y);
|
|
4468
4483
|
}
|
|
4469
|
-
let
|
|
4484
|
+
let D = `rest_${h}_${w}`;
|
|
4470
4485
|
s.push({
|
|
4471
4486
|
collection: d,
|
|
4472
4487
|
id: h,
|
|
4473
4488
|
data: I,
|
|
4474
|
-
serverVersion:
|
|
4489
|
+
serverVersion: D,
|
|
4475
4490
|
serverTimestamp: w,
|
|
4476
4491
|
deleted: false
|
|
4477
4492
|
});
|
|
@@ -4481,10 +4496,10 @@ function yn(n) {
|
|
|
4481
4496
|
}
|
|
4482
4497
|
};
|
|
4483
4498
|
}
|
|
4484
|
-
function
|
|
4485
|
-
let r =
|
|
4499
|
+
function Io(n, e, t) {
|
|
4500
|
+
let r = bn(e), o = new De({
|
|
4486
4501
|
gatewayUrl: n,
|
|
4487
|
-
ticketProvider:
|
|
4502
|
+
ticketProvider: Co(e, t),
|
|
4488
4503
|
dbId: t.dbId,
|
|
4489
4504
|
webSocketFactory: t._wsFactory
|
|
4490
4505
|
});
|
|
@@ -4520,9 +4535,9 @@ function wo(n, e, t) {
|
|
|
4520
4535
|
}
|
|
4521
4536
|
};
|
|
4522
4537
|
}
|
|
4523
|
-
function
|
|
4538
|
+
function Co(n, e) {
|
|
4524
4539
|
return async () => {
|
|
4525
|
-
let { httpRequest: t } = await Promise.resolve().then(() => (
|
|
4540
|
+
let { httpRequest: t } = await Promise.resolve().then(() => (F(), re));
|
|
4526
4541
|
return await t(n, {
|
|
4527
4542
|
method: "POST",
|
|
4528
4543
|
path: "/api/sdk/v1/db/realtime/ticket",
|
|
@@ -4535,21 +4550,21 @@ function ko(n, e) {
|
|
|
4535
4550
|
});
|
|
4536
4551
|
};
|
|
4537
4552
|
}
|
|
4538
|
-
var
|
|
4539
|
-
function
|
|
4540
|
-
|
|
4553
|
+
var _n = false;
|
|
4554
|
+
function Ao(n, e) {
|
|
4555
|
+
_n || e.dbId && n.env !== "prod" && (typeof window > "u" || typeof console > "u" || typeof console.warn != "function" || (_n = true, console.warn(
|
|
4541
4556
|
'[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.'
|
|
4542
4557
|
)));
|
|
4543
4558
|
}
|
|
4544
|
-
function
|
|
4545
|
-
|
|
4559
|
+
function ot(n, e = {}) {
|
|
4560
|
+
Ao(n, e);
|
|
4546
4561
|
let t;
|
|
4547
4562
|
e.transport !== void 0 ? t = e.transport : e.engine !== void 0 ? (console.warn(
|
|
4548
4563
|
'[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).'
|
|
4549
4564
|
), t = e.engine) : t = "rest";
|
|
4550
|
-
let r =
|
|
4565
|
+
let r = Ro(t, e, n), o = e.dbId ?? "default", i = e.dbName ?? `neetru-db__${n.productId ?? "sdk"}__${o}__${n.env}`, s = null, a = null;
|
|
4551
4566
|
function d() {
|
|
4552
|
-
return s || (s =
|
|
4567
|
+
return s || (s = rn({
|
|
4553
4568
|
dbName: i,
|
|
4554
4569
|
transport: r,
|
|
4555
4570
|
singleTab: e.singleTab ?? n.env !== "prod"
|
|
@@ -4557,15 +4572,15 @@ function nt(n, e = {}) {
|
|
|
4557
4572
|
}
|
|
4558
4573
|
return {
|
|
4559
4574
|
collection(p) {
|
|
4560
|
-
return a ? a.collection(p) :
|
|
4575
|
+
return a ? a.collection(p) : Eo(p, d);
|
|
4561
4576
|
},
|
|
4562
4577
|
async sql(p, l) {
|
|
4563
|
-
if (n.env
|
|
4578
|
+
if (V(n.env))
|
|
4564
4579
|
throw new v(
|
|
4565
4580
|
"db_unavailable",
|
|
4566
4581
|
"[SDK] db.sql() n\xE3o dispon\xEDvel em NEETRU_ENV=dev. Use `neetru dev` para subir o container Postgres local."
|
|
4567
4582
|
);
|
|
4568
|
-
return (await Promise.resolve().then(() => (
|
|
4583
|
+
return (await Promise.resolve().then(() => (gn(), hn))).createSqlClientFromConfig(n, p, l);
|
|
4569
4584
|
},
|
|
4570
4585
|
get syncState() {
|
|
4571
4586
|
return a?.syncState ?? {
|
|
@@ -4604,7 +4619,7 @@ function nt(n, e = {}) {
|
|
|
4604
4619
|
}
|
|
4605
4620
|
};
|
|
4606
4621
|
}
|
|
4607
|
-
function
|
|
4622
|
+
function Eo(n, e) {
|
|
4608
4623
|
async function t() {
|
|
4609
4624
|
return (await e()).collection(n);
|
|
4610
4625
|
}
|
|
@@ -4683,9 +4698,9 @@ function To(n, e) {
|
|
|
4683
4698
|
}
|
|
4684
4699
|
|
|
4685
4700
|
// src/checkout.ts
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
function
|
|
4701
|
+
A();
|
|
4702
|
+
F();
|
|
4703
|
+
function it(n, e) {
|
|
4689
4704
|
let t = n?.accessToken || n?.idToken;
|
|
4690
4705
|
if (!t || typeof t != "string")
|
|
4691
4706
|
throw new c(
|
|
@@ -4694,7 +4709,7 @@ function rt(n, e) {
|
|
|
4694
4709
|
);
|
|
4695
4710
|
return { requireAuth: false, headers: { authorization: `Bearer ${t}` } };
|
|
4696
4711
|
}
|
|
4697
|
-
function
|
|
4712
|
+
function Po(n) {
|
|
4698
4713
|
if (!n || typeof n != "object")
|
|
4699
4714
|
throw new c("invalid_response", "checkout.start response is not an object");
|
|
4700
4715
|
let e = n;
|
|
@@ -4710,7 +4725,7 @@ function Ro(n) {
|
|
|
4710
4725
|
requiresKyc: e.requiresKyc === true
|
|
4711
4726
|
};
|
|
4712
4727
|
}
|
|
4713
|
-
function
|
|
4728
|
+
function Do(n) {
|
|
4714
4729
|
if (!n || typeof n != "object")
|
|
4715
4730
|
throw new c("invalid_response", "checkout.get response is not an object");
|
|
4716
4731
|
let e = n, t = e.intent;
|
|
@@ -4732,20 +4747,20 @@ function Io(n) {
|
|
|
4732
4747
|
isStale: e.isStale === true
|
|
4733
4748
|
};
|
|
4734
4749
|
}
|
|
4735
|
-
function
|
|
4750
|
+
function No() {
|
|
4736
4751
|
try {
|
|
4737
4752
|
return typeof globalThis < "u" && typeof globalThis.window < "u" && typeof globalThis.location < "u" && typeof globalThis.location.assign == "function";
|
|
4738
4753
|
} catch {
|
|
4739
4754
|
return false;
|
|
4740
4755
|
}
|
|
4741
4756
|
}
|
|
4742
|
-
function
|
|
4757
|
+
function xo(n) {
|
|
4743
4758
|
try {
|
|
4744
4759
|
globalThis.location.assign(n);
|
|
4745
4760
|
} catch {
|
|
4746
4761
|
}
|
|
4747
4762
|
}
|
|
4748
|
-
function
|
|
4763
|
+
function Oo(n) {
|
|
4749
4764
|
return {
|
|
4750
4765
|
async start(e) {
|
|
4751
4766
|
if (!e?.productId)
|
|
@@ -4760,7 +4775,7 @@ function Eo(n) {
|
|
|
4760
4775
|
callbackUrl: e.callbackUrl
|
|
4761
4776
|
};
|
|
4762
4777
|
e.tenantType && (t.targetTenantType = e.tenantType), e.tenantId && (t.targetTenantId = e.tenantId);
|
|
4763
|
-
let { requireAuth: r, headers: o } =
|
|
4778
|
+
let { requireAuth: r, headers: o } = it(
|
|
4764
4779
|
{ accessToken: e.accessToken, idToken: e.idToken },
|
|
4765
4780
|
"start"
|
|
4766
4781
|
), i = await S(n, {
|
|
@@ -4770,13 +4785,13 @@ function Eo(n) {
|
|
|
4770
4785
|
requireAuth: r,
|
|
4771
4786
|
headers: o,
|
|
4772
4787
|
idempotencyKey: true
|
|
4773
|
-
}), s =
|
|
4774
|
-
return e.autoRedirect !== false &&
|
|
4788
|
+
}), s = Po(i);
|
|
4789
|
+
return e.autoRedirect !== false && No() && xo(s.redirectUrl), s;
|
|
4775
4790
|
},
|
|
4776
4791
|
async get(e, t) {
|
|
4777
4792
|
if (!e || typeof e != "string")
|
|
4778
4793
|
throw new c("validation_failed", "checkout.get: intentId is required");
|
|
4779
|
-
let { requireAuth: r, headers: o } =
|
|
4794
|
+
let { requireAuth: r, headers: o } = it(
|
|
4780
4795
|
{ accessToken: t?.accessToken, idToken: t?.idToken },
|
|
4781
4796
|
"get"
|
|
4782
4797
|
), i = await S(n, {
|
|
@@ -4785,12 +4800,12 @@ function Eo(n) {
|
|
|
4785
4800
|
requireAuth: r,
|
|
4786
4801
|
headers: o
|
|
4787
4802
|
});
|
|
4788
|
-
return
|
|
4803
|
+
return Do(i);
|
|
4789
4804
|
},
|
|
4790
4805
|
async cancel(e, t) {
|
|
4791
4806
|
if (!e || typeof e != "string")
|
|
4792
4807
|
throw new c("validation_failed", "checkout.cancel: intentId is required");
|
|
4793
|
-
let { requireAuth: r, headers: o } =
|
|
4808
|
+
let { requireAuth: r, headers: o } = it(
|
|
4794
4809
|
{ accessToken: t?.accessToken, idToken: t?.idToken },
|
|
4795
4810
|
"cancel"
|
|
4796
4811
|
);
|
|
@@ -4806,7 +4821,7 @@ function Eo(n) {
|
|
|
4806
4821
|
}
|
|
4807
4822
|
};
|
|
4808
4823
|
}
|
|
4809
|
-
var
|
|
4824
|
+
var Oe = class {
|
|
4810
4825
|
intents = /* @__PURE__ */ new Map();
|
|
4811
4826
|
async start(e) {
|
|
4812
4827
|
if (!e?.productId)
|
|
@@ -4849,14 +4864,14 @@ var xe = class {
|
|
|
4849
4864
|
return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled: o };
|
|
4850
4865
|
}
|
|
4851
4866
|
};
|
|
4852
|
-
function
|
|
4853
|
-
return n.env
|
|
4867
|
+
function st(n) {
|
|
4868
|
+
return V(n.env) ? new Oe() : Oo(n);
|
|
4854
4869
|
}
|
|
4855
4870
|
|
|
4856
4871
|
// src/webhooks.ts
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
async function
|
|
4872
|
+
A();
|
|
4873
|
+
F();
|
|
4874
|
+
async function wn(n, e, t, r) {
|
|
4860
4875
|
if (!e || !t) return false;
|
|
4861
4876
|
let o = e.startsWith("sha256=") ? e.slice(7) : e;
|
|
4862
4877
|
if (!/^[0-9a-f]+$/i.test(o)) return false;
|
|
@@ -4868,8 +4883,8 @@ async function bn(n, e, t, r) {
|
|
|
4868
4883
|
);
|
|
4869
4884
|
let s = new TextEncoder(), a = s.encode(t), d = typeof n == "string" ? s.encode(n) : n, p = d;
|
|
4870
4885
|
if (r !== void 0) {
|
|
4871
|
-
let
|
|
4872
|
-
I.set(
|
|
4886
|
+
let _ = s.encode(`${r}.`), I = new Uint8Array(_.length + d.length);
|
|
4887
|
+
I.set(_, 0), I.set(d, _.length), p = I;
|
|
4873
4888
|
}
|
|
4874
4889
|
let l = await i.importKey(
|
|
4875
4890
|
"raw",
|
|
@@ -4881,14 +4896,14 @@ async function bn(n, e, t, r) {
|
|
|
4881
4896
|
"HMAC",
|
|
4882
4897
|
l,
|
|
4883
4898
|
p
|
|
4884
|
-
), f = new Uint8Array(u), m =
|
|
4899
|
+
), f = new Uint8Array(u), m = Uo(o.toLowerCase());
|
|
4885
4900
|
if (!m || m.length !== f.length) return false;
|
|
4886
4901
|
let h = 0;
|
|
4887
|
-
for (let
|
|
4888
|
-
h |= f[
|
|
4902
|
+
for (let _ = 0; _ < f.length; _++)
|
|
4903
|
+
h |= f[_] ^ m[_];
|
|
4889
4904
|
return h === 0;
|
|
4890
4905
|
}
|
|
4891
|
-
async function
|
|
4906
|
+
async function Lo(n, e, t, r = {}) {
|
|
4892
4907
|
let o = r.toleranceMs ?? 3e5, i = (u) => {
|
|
4893
4908
|
if (typeof e.get == "function")
|
|
4894
4909
|
return e.get(u);
|
|
@@ -4905,9 +4920,9 @@ async function Po(n, e, t, r = {}) {
|
|
|
4905
4920
|
if (Math.abs(Date.now() - a) > o)
|
|
4906
4921
|
return { ok: false, reason: "timestamp_expired" };
|
|
4907
4922
|
let p = i("x-neetru-signature");
|
|
4908
|
-
return await
|
|
4923
|
+
return await wn(n, p, t, s) ? { ok: true } : { ok: false, reason: "invalid_signature" };
|
|
4909
4924
|
}
|
|
4910
|
-
function
|
|
4925
|
+
function Uo(n) {
|
|
4911
4926
|
if (n.length % 2 !== 0) return null;
|
|
4912
4927
|
let e = new Uint8Array(n.length / 2);
|
|
4913
4928
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -4917,7 +4932,7 @@ function Do(n) {
|
|
|
4917
4932
|
}
|
|
4918
4933
|
return e;
|
|
4919
4934
|
}
|
|
4920
|
-
var
|
|
4935
|
+
var kn = [
|
|
4921
4936
|
"subscription.activated",
|
|
4922
4937
|
"subscription.cancelled",
|
|
4923
4938
|
"subscription.payment_failed",
|
|
@@ -4927,7 +4942,7 @@ var vn = [
|
|
|
4927
4942
|
"account.reactivated",
|
|
4928
4943
|
"support.ticket_replied"
|
|
4929
4944
|
];
|
|
4930
|
-
function
|
|
4945
|
+
function vn(n) {
|
|
4931
4946
|
if (!n || typeof n != "object")
|
|
4932
4947
|
throw new c("invalid_response", "Webhook response is not an object");
|
|
4933
4948
|
let e = n;
|
|
@@ -4937,7 +4952,7 @@ function _n(n) {
|
|
|
4937
4952
|
id: e.id,
|
|
4938
4953
|
url: typeof e.url == "string" ? e.url : "",
|
|
4939
4954
|
events: Array.isArray(e.events) ? e.events.filter(
|
|
4940
|
-
(t) =>
|
|
4955
|
+
(t) => kn.includes(t)
|
|
4941
4956
|
) : [],
|
|
4942
4957
|
hasSecret: e.hasSecret === true,
|
|
4943
4958
|
status: e.status === "active" || e.status === "degraded" || e.status === "disabled" ? e.status : "active",
|
|
@@ -4946,7 +4961,7 @@ function _n(n) {
|
|
|
4946
4961
|
createdAt: typeof e.createdAt == "string" ? e.createdAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
4947
4962
|
};
|
|
4948
4963
|
}
|
|
4949
|
-
function
|
|
4964
|
+
function Sn(n) {
|
|
4950
4965
|
if (!n.url || typeof n.url != "string")
|
|
4951
4966
|
throw new c("validation_failed", "url \xE9 obrigat\xF3ria");
|
|
4952
4967
|
try {
|
|
@@ -4959,12 +4974,12 @@ function wn(n) {
|
|
|
4959
4974
|
if (!Array.isArray(n.events) || n.events.length === 0)
|
|
4960
4975
|
throw new c("validation_failed", "events deve ter pelo menos 1 evento");
|
|
4961
4976
|
for (let e of n.events)
|
|
4962
|
-
if (!
|
|
4977
|
+
if (!kn.includes(e))
|
|
4963
4978
|
throw new c("validation_failed", `evento desconhecido: ${e}`);
|
|
4964
4979
|
if (n.secret !== void 0 && n.secret.length < 16)
|
|
4965
4980
|
throw new c("validation_failed", "secret deve ter \u226516 chars (recomendado 32+)");
|
|
4966
4981
|
}
|
|
4967
|
-
function
|
|
4982
|
+
function Le(n, ...e) {
|
|
4968
4983
|
for (let t of e)
|
|
4969
4984
|
if (typeof t == "string" && t.length > 0)
|
|
4970
4985
|
return O("productId", t), t;
|
|
@@ -4975,11 +4990,11 @@ function Oe(n, ...e) {
|
|
|
4975
4990
|
"productId required (pass to options/input or set on createNeetruClient)"
|
|
4976
4991
|
);
|
|
4977
4992
|
}
|
|
4978
|
-
function
|
|
4993
|
+
function at(n) {
|
|
4979
4994
|
return {
|
|
4980
4995
|
async register(e) {
|
|
4981
|
-
|
|
4982
|
-
let t =
|
|
4996
|
+
Sn(e);
|
|
4997
|
+
let t = Le(n, e.productId), r = await S(n, {
|
|
4983
4998
|
method: "POST",
|
|
4984
4999
|
path: "/api/sdk/v1/webhooks",
|
|
4985
5000
|
body: {
|
|
@@ -4995,20 +5010,20 @@ function it(n) {
|
|
|
4995
5010
|
// dedup TTL 24h (mesmo padrão de usage.report/support.createTicket).
|
|
4996
5011
|
idempotencyKey: true
|
|
4997
5012
|
});
|
|
4998
|
-
return
|
|
5013
|
+
return vn(r);
|
|
4999
5014
|
},
|
|
5000
5015
|
async list(e) {
|
|
5001
|
-
let t =
|
|
5016
|
+
let t = Le(n, e?.productId), r = await S(n, {
|
|
5002
5017
|
method: "GET",
|
|
5003
5018
|
path: "/api/sdk/v1/webhooks",
|
|
5004
5019
|
query: { productId: t },
|
|
5005
5020
|
requireAuth: true
|
|
5006
5021
|
});
|
|
5007
|
-
return (Array.isArray(r?.endpoints) ? r.endpoints : []).map(
|
|
5022
|
+
return (Array.isArray(r?.endpoints) ? r.endpoints : []).map(vn);
|
|
5008
5023
|
},
|
|
5009
5024
|
async unregister(e, t) {
|
|
5010
5025
|
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
5011
|
-
let r =
|
|
5026
|
+
let r = Le(n, t?.productId);
|
|
5012
5027
|
return await S(n, {
|
|
5013
5028
|
method: "DELETE",
|
|
5014
5029
|
path: `/api/sdk/v1/webhooks/${encodeURIComponent(e)}`,
|
|
@@ -5018,7 +5033,7 @@ function it(n) {
|
|
|
5018
5033
|
},
|
|
5019
5034
|
async test(e, t) {
|
|
5020
5035
|
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
5021
|
-
let r =
|
|
5036
|
+
let r = Le(n, t?.productId), o = await S(n, {
|
|
5022
5037
|
method: "POST",
|
|
5023
5038
|
path: `/api/sdk/v1/webhooks/${encodeURIComponent(e)}/test`,
|
|
5024
5039
|
query: { productId: r },
|
|
@@ -5037,11 +5052,11 @@ function it(n) {
|
|
|
5037
5052
|
}
|
|
5038
5053
|
};
|
|
5039
5054
|
}
|
|
5040
|
-
var
|
|
5055
|
+
var ce = class {
|
|
5041
5056
|
endpoints = /* @__PURE__ */ new Map();
|
|
5042
5057
|
nextId = 1;
|
|
5043
5058
|
async register(e) {
|
|
5044
|
-
|
|
5059
|
+
Sn(e);
|
|
5045
5060
|
let t = `mock_wh_${this.nextId++}`, r = {
|
|
5046
5061
|
id: t,
|
|
5047
5062
|
url: e.url,
|
|
@@ -5068,21 +5083,21 @@ var ae = class {
|
|
|
5068
5083
|
};
|
|
5069
5084
|
|
|
5070
5085
|
// src/notifications.ts
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
var
|
|
5086
|
+
A();
|
|
5087
|
+
F();
|
|
5088
|
+
var ct = [
|
|
5074
5089
|
"info",
|
|
5075
5090
|
"success",
|
|
5076
5091
|
"warning",
|
|
5077
5092
|
"error"
|
|
5078
5093
|
];
|
|
5079
|
-
function
|
|
5094
|
+
function Tn(n) {
|
|
5080
5095
|
if (!n || typeof n != "object")
|
|
5081
5096
|
throw new c("invalid_response", "Notification response is not an object");
|
|
5082
5097
|
let e = n;
|
|
5083
5098
|
if (typeof e.id != "string")
|
|
5084
5099
|
throw new c("invalid_response", "Notification missing id");
|
|
5085
|
-
let t =
|
|
5100
|
+
let t = ct.includes(e.severity) ? e.severity : "info";
|
|
5086
5101
|
return {
|
|
5087
5102
|
id: e.id,
|
|
5088
5103
|
userId: typeof e.userId == "string" ? e.userId : "",
|
|
@@ -5097,21 +5112,21 @@ function kn(n) {
|
|
|
5097
5112
|
dismissedAt: typeof e.dismissedAt == "string" ? e.dismissedAt : void 0
|
|
5098
5113
|
};
|
|
5099
5114
|
}
|
|
5100
|
-
function
|
|
5115
|
+
function Rn(n) {
|
|
5101
5116
|
if (!n.userId) throw new c("validation_failed", "userId obrigat\xF3rio");
|
|
5102
5117
|
if (!n.kind) throw new c("validation_failed", "kind obrigat\xF3rio");
|
|
5103
5118
|
if (!n.title) throw new c("validation_failed", "title obrigat\xF3rio");
|
|
5104
|
-
if (n.severity && !
|
|
5119
|
+
if (n.severity && !ct.includes(n.severity))
|
|
5105
5120
|
throw new c(
|
|
5106
5121
|
"validation_failed",
|
|
5107
|
-
`severity inv\xE1lida: ${n.severity} (use ${
|
|
5122
|
+
`severity inv\xE1lida: ${n.severity} (use ${ct.join("|")})`
|
|
5108
5123
|
);
|
|
5109
5124
|
if (n.title.length > 200)
|
|
5110
5125
|
throw new c("validation_failed", "title m\xE1x 200 chars");
|
|
5111
5126
|
if (n.body && n.body.length > 2e3)
|
|
5112
5127
|
throw new c("validation_failed", "body m\xE1x 2000 chars");
|
|
5113
5128
|
}
|
|
5114
|
-
function
|
|
5129
|
+
function Ue(n, ...e) {
|
|
5115
5130
|
for (let t of e)
|
|
5116
5131
|
if (typeof t == "string" && t.length > 0)
|
|
5117
5132
|
return O("productId", t), t;
|
|
@@ -5122,12 +5137,12 @@ function Le(n, ...e) {
|
|
|
5122
5137
|
"productId required (pass to options/input or set on createNeetruClient)"
|
|
5123
5138
|
);
|
|
5124
5139
|
}
|
|
5125
|
-
function
|
|
5140
|
+
function lt(n) {
|
|
5126
5141
|
return {
|
|
5127
5142
|
async send(e) {
|
|
5128
|
-
|
|
5143
|
+
Rn(e);
|
|
5129
5144
|
let r = {
|
|
5130
|
-
productId:
|
|
5145
|
+
productId: Ue(n, e.productId),
|
|
5131
5146
|
userId: e.userId,
|
|
5132
5147
|
kind: e.kind,
|
|
5133
5148
|
title: e.title,
|
|
@@ -5141,12 +5156,12 @@ function at(n) {
|
|
|
5141
5156
|
requireAuth: true,
|
|
5142
5157
|
idempotencyKey: true
|
|
5143
5158
|
});
|
|
5144
|
-
return
|
|
5159
|
+
return Tn(o);
|
|
5145
5160
|
},
|
|
5146
5161
|
async list(e, t) {
|
|
5147
5162
|
if (!e) throw new c("validation_failed", "userId obrigat\xF3rio");
|
|
5148
5163
|
let o = {
|
|
5149
|
-
productId:
|
|
5164
|
+
productId: Ue(n, t?.productId)
|
|
5150
5165
|
};
|
|
5151
5166
|
t?.includeDismissed && (o.includeDismissed = true), t?.onlyUnread && (o.onlyUnread = true), t?.limit && (o.limit = Math.min(Math.max(1, t.limit), 200));
|
|
5152
5167
|
let i = await S(n, {
|
|
@@ -5155,11 +5170,11 @@ function at(n) {
|
|
|
5155
5170
|
query: o,
|
|
5156
5171
|
requireAuth: true
|
|
5157
5172
|
});
|
|
5158
|
-
return (Array.isArray(i?.notifications) ? i.notifications : []).map(
|
|
5173
|
+
return (Array.isArray(i?.notifications) ? i.notifications : []).map(Tn);
|
|
5159
5174
|
},
|
|
5160
5175
|
async markRead(e, t) {
|
|
5161
5176
|
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
5162
|
-
let r =
|
|
5177
|
+
let r = Ue(n, t?.productId);
|
|
5163
5178
|
return await S(n, {
|
|
5164
5179
|
method: "POST",
|
|
5165
5180
|
path: `/api/sdk/v1/notifications/${encodeURIComponent(e)}/read`,
|
|
@@ -5169,7 +5184,7 @@ function at(n) {
|
|
|
5169
5184
|
},
|
|
5170
5185
|
async dismiss(e, t) {
|
|
5171
5186
|
if (!e) throw new c("validation_failed", "id obrigat\xF3rio");
|
|
5172
|
-
let r =
|
|
5187
|
+
let r = Ue(n, t?.productId);
|
|
5173
5188
|
return await S(n, {
|
|
5174
5189
|
method: "POST",
|
|
5175
5190
|
path: `/api/sdk/v1/notifications/${encodeURIComponent(e)}/dismiss`,
|
|
@@ -5179,11 +5194,11 @@ function at(n) {
|
|
|
5179
5194
|
}
|
|
5180
5195
|
};
|
|
5181
5196
|
}
|
|
5182
|
-
var
|
|
5197
|
+
var le = class {
|
|
5183
5198
|
notifications = /* @__PURE__ */ new Map();
|
|
5184
5199
|
nextId = 1;
|
|
5185
5200
|
async send(e) {
|
|
5186
|
-
if (
|
|
5201
|
+
if (Rn(e), e.fingerprint) {
|
|
5187
5202
|
let o = Date.now() - 864e5;
|
|
5188
5203
|
for (let i of this.notifications.values())
|
|
5189
5204
|
if ((i.metadata ?? {}).fingerprint === e.fingerprint && i.userId === e.userId && new Date(i.createdAt).getTime() > o)
|
|
@@ -5220,44 +5235,44 @@ var ce = class {
|
|
|
5220
5235
|
};
|
|
5221
5236
|
|
|
5222
5237
|
// src/ai.ts
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
var
|
|
5238
|
+
A();
|
|
5239
|
+
F();
|
|
5240
|
+
$e();
|
|
5241
|
+
var Mo = "/api/sdk/v1/ai/chat", In = 12e4, Me = 32768, Cn = 32, An = 4194304, En = 2048, qo = /^data:image\/(?:png|jpe?g|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/, Fo = /^https:\/\/[^\s]+$/, jo = /* @__PURE__ */ new Set(["low", "high", "auto"]), Wo = /* @__PURE__ */ new Set(["system", "user", "assistant"]), Pn = 100, Dn = 128, Nn = 32768, xn = 0, On = 2, Ln = 200, Un = 20, Mn = 12 * 1024 * 1024, qn = 5e4, Fn = 16, jn = 500, $o = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]), Vo = /^[a-zA-Z0-9_-]+$/;
|
|
5227
5242
|
function R(n) {
|
|
5228
5243
|
throw new c("validation_failed", n);
|
|
5229
5244
|
}
|
|
5230
|
-
function
|
|
5245
|
+
function Bo(n) {
|
|
5231
5246
|
if (n.length === 0 || n.length % 4 !== 0) return false;
|
|
5232
5247
|
let e = n.endsWith("==") ? 2 : n.endsWith("=") ? 1 : 0;
|
|
5233
5248
|
return !(e > 0 ? n.slice(0, n.length - e) : n).includes("=");
|
|
5234
5249
|
}
|
|
5235
|
-
function
|
|
5250
|
+
function Ko(n) {
|
|
5236
5251
|
let e = n.indexOf(",");
|
|
5237
5252
|
if (e === -1) return 0;
|
|
5238
5253
|
let t = n.slice(e + 1), r = t.endsWith("==") ? 2 : t.endsWith("=") ? 1 : 0;
|
|
5239
5254
|
return Math.max(0, Math.floor(t.length * 3 / 4) - r);
|
|
5240
5255
|
}
|
|
5241
|
-
function
|
|
5256
|
+
function zo(n) {
|
|
5242
5257
|
let e = 0, t = 0, r = 0;
|
|
5243
5258
|
for (let o of n) {
|
|
5244
5259
|
let i = o?.content;
|
|
5245
5260
|
if (Array.isArray(i))
|
|
5246
5261
|
for (let s of i) {
|
|
5247
|
-
if (e++, e >
|
|
5248
|
-
return `ai: total content parts exceeds ${
|
|
5262
|
+
if (e++, e > Ln)
|
|
5263
|
+
return `ai: total content parts exceeds ${Ln} per request`;
|
|
5249
5264
|
if (s && typeof s == "object" && s.type === "image_url") {
|
|
5250
|
-
if (t++, t >
|
|
5251
|
-
return `ai: total images exceeds ${
|
|
5265
|
+
if (t++, t > Un)
|
|
5266
|
+
return `ai: total images exceeds ${Un} per request`;
|
|
5252
5267
|
let a = s.image_url?.url;
|
|
5253
|
-
if (typeof a == "string" && a.startsWith("data:") && (r +=
|
|
5254
|
-
return `ai: aggregate image bytes exceeds ${
|
|
5268
|
+
if (typeof a == "string" && a.startsWith("data:") && (r += Ko(a), r > Mn))
|
|
5269
|
+
return `ai: aggregate image bytes exceeds ${Mn} per request`;
|
|
5255
5270
|
}
|
|
5256
5271
|
}
|
|
5257
5272
|
}
|
|
5258
5273
|
return null;
|
|
5259
5274
|
}
|
|
5260
|
-
function
|
|
5275
|
+
function Ho(n) {
|
|
5261
5276
|
if (n === void 0) return null;
|
|
5262
5277
|
if (n === null || typeof n != "object")
|
|
5263
5278
|
return "ai: responseFormat json_schema.schema must be an object";
|
|
@@ -5268,11 +5283,11 @@ function $o(n) {
|
|
|
5268
5283
|
return "ai: responseFormat json_schema.schema is not serializable";
|
|
5269
5284
|
}
|
|
5270
5285
|
if (e === void 0) return "ai: responseFormat json_schema.schema is invalid";
|
|
5271
|
-
if (e.length >
|
|
5272
|
-
return `ai: responseFormat json_schema.schema exceeds ${
|
|
5286
|
+
if (e.length > qn)
|
|
5287
|
+
return `ai: responseFormat json_schema.schema exceeds ${qn} serialized chars`;
|
|
5273
5288
|
let t = 0, r = (o, i) => {
|
|
5274
|
-
if (i >
|
|
5275
|
-
return `ai: responseFormat json_schema.schema exceeds max depth ${
|
|
5289
|
+
if (i > Fn)
|
|
5290
|
+
return `ai: responseFormat json_schema.schema exceeds max depth ${Fn}`;
|
|
5276
5291
|
if (Array.isArray(o)) {
|
|
5277
5292
|
for (let s of o) {
|
|
5278
5293
|
let a = r(s, i + 1);
|
|
@@ -5282,10 +5297,10 @@ function $o(n) {
|
|
|
5282
5297
|
}
|
|
5283
5298
|
if (o && typeof o == "object")
|
|
5284
5299
|
for (let s of Object.getOwnPropertyNames(o)) {
|
|
5285
|
-
if (
|
|
5300
|
+
if ($o.has(s))
|
|
5286
5301
|
return `ai: responseFormat json_schema.schema has forbidden key: ${s}`;
|
|
5287
|
-
if (t++, t >
|
|
5288
|
-
return `ai: responseFormat json_schema.schema exceeds ${
|
|
5302
|
+
if (t++, t > jn)
|
|
5303
|
+
return `ai: responseFormat json_schema.schema exceeds ${jn} keys`;
|
|
5289
5304
|
let a = r(o[s], i + 1);
|
|
5290
5305
|
if (a) return a;
|
|
5291
5306
|
}
|
|
@@ -5293,44 +5308,44 @@ function $o(n) {
|
|
|
5293
5308
|
};
|
|
5294
5309
|
return r(n, 0);
|
|
5295
5310
|
}
|
|
5296
|
-
function
|
|
5311
|
+
function Qo(n) {
|
|
5297
5312
|
(typeof n != "string" || n.length === 0) && R("ai: image_url.url must be a non-empty string");
|
|
5298
5313
|
let e = n;
|
|
5299
5314
|
if (e.startsWith("data:")) {
|
|
5300
|
-
e.length >
|
|
5315
|
+
e.length > An && R(`ai: image_url.url (data:) exceeds ${An} chars`), qo.test(e) || R("ai: image_url.url data: must be data:image/<png|jpeg|jpg|gif|webp>;base64,<...>");
|
|
5301
5316
|
let t = e.slice(e.indexOf(",") + 1);
|
|
5302
|
-
|
|
5317
|
+
Bo(t) || R("ai: image_url.url data: has invalid base64 (length/padding)");
|
|
5303
5318
|
return;
|
|
5304
5319
|
}
|
|
5305
5320
|
if (e.startsWith("https://")) {
|
|
5306
|
-
e.length >
|
|
5321
|
+
e.length > En && R(`ai: image_url.url (https:) exceeds ${En} chars`), Fo.test(e) || R("ai: image_url.url https: is invalid");
|
|
5307
5322
|
return;
|
|
5308
5323
|
}
|
|
5309
5324
|
R("ai: image_url.url must be a data:image/...;base64 or https:// URL (other schemes are rejected)");
|
|
5310
5325
|
}
|
|
5311
|
-
function
|
|
5326
|
+
function Go(n, e) {
|
|
5312
5327
|
if (typeof n == "string") {
|
|
5313
|
-
n.length === 0 && R("ai: message content string must be non-empty"), n.length >
|
|
5328
|
+
n.length === 0 && R("ai: message content string must be non-empty"), n.length > Me && R(`ai: message content exceeds ${Me} chars`);
|
|
5314
5329
|
return;
|
|
5315
5330
|
}
|
|
5316
|
-
(!Array.isArray(n) || n.length === 0) && R("ai: message content must be a non-empty string or array of parts"), n.length >
|
|
5331
|
+
(!Array.isArray(n) || n.length === 0) && R("ai: message content must be a non-empty string or array of parts"), n.length > Cn && R(`ai: message content has more than ${Cn} parts`);
|
|
5317
5332
|
for (let t of n) {
|
|
5318
5333
|
(!t || typeof t != "object") && R("ai: each content part must be an object");
|
|
5319
5334
|
let r = t.type;
|
|
5320
5335
|
if (r === "text") {
|
|
5321
5336
|
let o = t.text;
|
|
5322
|
-
(typeof o != "string" || o.length === 0) && R("ai: text part must have non-empty { text: string }"), o.length >
|
|
5337
|
+
(typeof o != "string" || o.length === 0) && R("ai: text part must have non-empty { text: string }"), o.length > Me && R(`ai: text part exceeds ${Me} chars`);
|
|
5323
5338
|
} else if (r === "image_url") {
|
|
5324
5339
|
e !== "user" && R(`ai: image_url is only allowed in role 'user' messages (got '${e}')`);
|
|
5325
5340
|
let o = t.image_url;
|
|
5326
|
-
(!o || typeof o != "object") && R("ai: image_url part must have { image_url: { url } }"),
|
|
5341
|
+
(!o || typeof o != "object") && R("ai: image_url part must have { image_url: { url } }"), Qo(o.url);
|
|
5327
5342
|
let i = o.detail;
|
|
5328
|
-
i !== void 0 && (typeof i != "string" || !
|
|
5343
|
+
i !== void 0 && (typeof i != "string" || !jo.has(i)) && R("ai: image_url.detail must be 'low' | 'high' | 'auto'");
|
|
5329
5344
|
} else
|
|
5330
5345
|
R("ai: content part type must be 'text' or 'image_url'");
|
|
5331
5346
|
}
|
|
5332
5347
|
}
|
|
5333
|
-
function
|
|
5348
|
+
function Jo(n) {
|
|
5334
5349
|
(!n || typeof n != "object") && R("ai: responseFormat must be an object");
|
|
5335
5350
|
let e = n.type;
|
|
5336
5351
|
if (!(e === "text" || e === "json_object")) {
|
|
@@ -5338,8 +5353,8 @@ function Ko(n) {
|
|
|
5338
5353
|
let t = n.json_schema;
|
|
5339
5354
|
(!t || typeof t != "object") && R("ai: responseFormat json_schema requires { json_schema: { name } }");
|
|
5340
5355
|
let r = t, o = r.name;
|
|
5341
|
-
if ((typeof o != "string" || o.length === 0) && R("ai: responseFormat json_schema.name is required"), o.length > 64 && R("ai: responseFormat json_schema.name exceeds 64 chars"),
|
|
5342
|
-
let i =
|
|
5356
|
+
if ((typeof o != "string" || o.length === 0) && R("ai: responseFormat json_schema.name is required"), o.length > 64 && R("ai: responseFormat json_schema.name exceeds 64 chars"), Vo.test(o) || R("ai: responseFormat json_schema.name must match a-zA-Z0-9_-"), r.description !== void 0 && (typeof r.description != "string" && R("ai: responseFormat json_schema.description must be a string"), r.description.length > 1e3 && R("ai: responseFormat json_schema.description exceeds 1000 chars")), r.strict !== void 0 && typeof r.strict != "boolean" && R("ai: responseFormat json_schema.strict must be a boolean"), r.schema !== void 0) {
|
|
5357
|
+
let i = Ho(r.schema);
|
|
5343
5358
|
i && R(i);
|
|
5344
5359
|
}
|
|
5345
5360
|
return;
|
|
@@ -5347,26 +5362,26 @@ function Ko(n) {
|
|
|
5347
5362
|
R("ai: responseFormat.type must be 'text' | 'json_object' | 'json_schema'");
|
|
5348
5363
|
}
|
|
5349
5364
|
}
|
|
5350
|
-
function
|
|
5365
|
+
function Wn(n, e, t) {
|
|
5351
5366
|
if (!e || typeof e != "object")
|
|
5352
5367
|
throw new c("validation_failed", "ai: options object is required");
|
|
5353
5368
|
if (typeof e.model != "string" || e.model.length === 0)
|
|
5354
5369
|
throw new c("validation_failed", "ai: model is required");
|
|
5355
|
-
if (e.model.length >
|
|
5356
|
-
throw new c("validation_failed", `ai: model exceeds ${
|
|
5370
|
+
if (e.model.length > Dn)
|
|
5371
|
+
throw new c("validation_failed", `ai: model exceeds ${Dn} chars`);
|
|
5357
5372
|
if (!Array.isArray(e.messages) || e.messages.length === 0)
|
|
5358
5373
|
throw new c("validation_failed", "ai: messages must be a non-empty array");
|
|
5359
|
-
if (e.messages.length >
|
|
5360
|
-
throw new c("validation_failed", `ai: messages exceeds ${
|
|
5374
|
+
if (e.messages.length > Pn)
|
|
5375
|
+
throw new c("validation_failed", `ai: messages exceeds ${Pn} per request`);
|
|
5361
5376
|
for (let a of e.messages) {
|
|
5362
|
-
if (!a || typeof a != "object" || typeof a.role != "string" || !
|
|
5377
|
+
if (!a || typeof a != "object" || typeof a.role != "string" || !Wo.has(a.role))
|
|
5363
5378
|
throw new c(
|
|
5364
5379
|
"validation_failed",
|
|
5365
5380
|
"ai: each message role must be 'system' | 'user' | 'assistant'"
|
|
5366
5381
|
);
|
|
5367
|
-
|
|
5382
|
+
Go(a.content, a.role);
|
|
5368
5383
|
}
|
|
5369
|
-
let r =
|
|
5384
|
+
let r = zo(e.messages);
|
|
5370
5385
|
if (r) throw new c("validation_failed", r);
|
|
5371
5386
|
let o = e.productId ?? n.productId, i = e.tenantId ?? n.tenantId;
|
|
5372
5387
|
if (!o)
|
|
@@ -5388,24 +5403,24 @@ function Fn(n, e, t) {
|
|
|
5388
5403
|
stream: t
|
|
5389
5404
|
};
|
|
5390
5405
|
if (e.maxTokens !== void 0) {
|
|
5391
|
-
if (!Number.isInteger(e.maxTokens) || e.maxTokens <= 0 || e.maxTokens >
|
|
5406
|
+
if (!Number.isInteger(e.maxTokens) || e.maxTokens <= 0 || e.maxTokens > Nn)
|
|
5392
5407
|
throw new c(
|
|
5393
5408
|
"validation_failed",
|
|
5394
|
-
`ai: maxTokens must be a positive integer <= ${
|
|
5409
|
+
`ai: maxTokens must be a positive integer <= ${Nn}`
|
|
5395
5410
|
);
|
|
5396
5411
|
s.maxTokens = e.maxTokens;
|
|
5397
5412
|
}
|
|
5398
5413
|
if (e.temperature !== void 0) {
|
|
5399
|
-
if (typeof e.temperature != "number" || !Number.isFinite(e.temperature) || e.temperature <
|
|
5414
|
+
if (typeof e.temperature != "number" || !Number.isFinite(e.temperature) || e.temperature < xn || e.temperature > On)
|
|
5400
5415
|
throw new c(
|
|
5401
5416
|
"validation_failed",
|
|
5402
|
-
`ai: temperature must be a finite number between ${
|
|
5417
|
+
`ai: temperature must be a finite number between ${xn} and ${On}`
|
|
5403
5418
|
);
|
|
5404
5419
|
s.temperature = e.temperature;
|
|
5405
5420
|
}
|
|
5406
|
-
return e.responseFormat !== void 0 && (
|
|
5421
|
+
return e.responseFormat !== void 0 && (Jo(e.responseFormat), s.responseFormat = e.responseFormat), s;
|
|
5407
5422
|
}
|
|
5408
|
-
async function
|
|
5423
|
+
async function Kn(n) {
|
|
5409
5424
|
try {
|
|
5410
5425
|
let e = await n.text();
|
|
5411
5426
|
return e ? JSON.parse(e) : void 0;
|
|
@@ -5413,32 +5428,32 @@ async function Vn(n) {
|
|
|
5413
5428
|
return;
|
|
5414
5429
|
}
|
|
5415
5430
|
}
|
|
5416
|
-
function
|
|
5431
|
+
function Xo(n, e) {
|
|
5417
5432
|
let t = n.replace(/\/+$/, ""), r = e.startsWith("/") ? e : `/${e}`;
|
|
5418
5433
|
return `${t}${r}`;
|
|
5419
5434
|
}
|
|
5420
|
-
async function
|
|
5435
|
+
async function $n(n, e, t, r) {
|
|
5421
5436
|
if (!n.apiKey)
|
|
5422
5437
|
throw new c(
|
|
5423
5438
|
"missing_api_key",
|
|
5424
5439
|
"ai requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
5425
5440
|
);
|
|
5426
|
-
let o =
|
|
5441
|
+
let o = Xo(n.baseUrl, Mo), { headers: i, correlationId: s } = be({
|
|
5427
5442
|
"content-type": "application/json",
|
|
5428
5443
|
accept: r ? "text/event-stream" : "application/json",
|
|
5429
5444
|
authorization: `Bearer ${n.apiKey}`
|
|
5430
5445
|
}), a = { method: "POST", headers: i, body: JSON.stringify(e) };
|
|
5431
|
-
r ? t && (a.signal = t) : a.signal = t ?? AbortSignal.timeout(
|
|
5446
|
+
r ? t && (a.signal = t) : a.signal = t ?? AbortSignal.timeout(In);
|
|
5432
5447
|
let d;
|
|
5433
5448
|
try {
|
|
5434
5449
|
d = await n.fetch(o, a);
|
|
5435
5450
|
} catch (u) {
|
|
5436
|
-
let f = u instanceof DOMException && u.name === "TimeoutError" ? `Network error: timeout after ${
|
|
5451
|
+
let f = u instanceof DOMException && u.name === "TimeoutError" ? `Network error: timeout after ${In / 1e3}s` : u instanceof DOMException && u.name === "AbortError" ? "Network error: request aborted" : `Network error: ${u instanceof Error ? u.message : "fetch failed"}`;
|
|
5437
5452
|
throw new c("network_error", f, void 0, void 0, void 0, s);
|
|
5438
5453
|
}
|
|
5439
5454
|
let p = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
|
|
5440
5455
|
if (!d.ok) {
|
|
5441
|
-
let u = await
|
|
5456
|
+
let u = await Kn(d), f = we(d.status), m = `HTTP ${d.status}`;
|
|
5442
5457
|
if (u && typeof u == "object" && "error" in u) {
|
|
5443
5458
|
let h = u.error;
|
|
5444
5459
|
typeof h == "string" ? m = h : h && typeof h == "object" && (typeof h.code == "string" && (f = h.code), typeof h.message == "string" && (m = h.message));
|
|
@@ -5446,15 +5461,15 @@ async function jn(n, e, t, r) {
|
|
|
5446
5461
|
throw new c(f, m, d.status, p, void 0, s);
|
|
5447
5462
|
}
|
|
5448
5463
|
let l = d.headers.get("x-neetru-version");
|
|
5449
|
-
return l &&
|
|
5464
|
+
return l && ne(l), d;
|
|
5450
5465
|
}
|
|
5451
|
-
function
|
|
5466
|
+
function Vn(n) {
|
|
5452
5467
|
return {
|
|
5453
5468
|
provider: n.headers.get("x-neetru-provider") ?? "",
|
|
5454
5469
|
usageWarning: n.headers.get("x-neetru-ai-usage-warning") === "1"
|
|
5455
5470
|
};
|
|
5456
5471
|
}
|
|
5457
|
-
function
|
|
5472
|
+
function Bn(n) {
|
|
5458
5473
|
let e = [];
|
|
5459
5474
|
for (let r of n.split(`
|
|
5460
5475
|
`)) {
|
|
@@ -5475,10 +5490,10 @@ function $n(n) {
|
|
|
5475
5490
|
return null;
|
|
5476
5491
|
}
|
|
5477
5492
|
}
|
|
5478
|
-
function
|
|
5493
|
+
function dt(n) {
|
|
5479
5494
|
return {
|
|
5480
5495
|
async chat(e) {
|
|
5481
|
-
let t =
|
|
5496
|
+
let t = Wn(n, e, false), r = await $n(n, t, e.signal, false), { provider: o, usageWarning: i } = Vn(r), s = await Kn(r);
|
|
5482
5497
|
if (!s || s.ok !== true || !Array.isArray(s.choices))
|
|
5483
5498
|
throw new c("invalid_response", "ai.chat response missing ok/choices");
|
|
5484
5499
|
return {
|
|
@@ -5490,7 +5505,7 @@ function ct(n) {
|
|
|
5490
5505
|
};
|
|
5491
5506
|
},
|
|
5492
5507
|
stream(e) {
|
|
5493
|
-
let t =
|
|
5508
|
+
let t = Wn(n, e, true), r = $n(n, t, e.signal, true), o = r.then(Vn);
|
|
5494
5509
|
o.catch(() => {
|
|
5495
5510
|
});
|
|
5496
5511
|
async function* i() {
|
|
@@ -5507,16 +5522,16 @@ function ct(n) {
|
|
|
5507
5522
|
for (; (h = l.indexOf(`
|
|
5508
5523
|
|
|
5509
5524
|
`)) !== -1; ) {
|
|
5510
|
-
let
|
|
5525
|
+
let _ = l.slice(0, h);
|
|
5511
5526
|
l = l.slice(h + 2);
|
|
5512
|
-
let I =
|
|
5527
|
+
let I = Bn(_);
|
|
5513
5528
|
if (I && "done" in I) return;
|
|
5514
5529
|
I && "content" in I && (yield I.content);
|
|
5515
5530
|
}
|
|
5516
5531
|
}
|
|
5517
5532
|
let u = l.trim();
|
|
5518
5533
|
if (u) {
|
|
5519
|
-
let f =
|
|
5534
|
+
let f = Bn(u);
|
|
5520
5535
|
f && "content" in f && (yield f.content);
|
|
5521
5536
|
}
|
|
5522
5537
|
} finally {
|
|
@@ -5539,20 +5554,8 @@ function ct(n) {
|
|
|
5539
5554
|
}
|
|
5540
5555
|
|
|
5541
5556
|
// src/mocks.ts
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
// src/runtime-env.ts
|
|
5546
|
-
function Me() {
|
|
5547
|
-
try {
|
|
5548
|
-
if (typeof process < "u" && process.env)
|
|
5549
|
-
return process.env.NODE_ENV === "production";
|
|
5550
|
-
} catch {
|
|
5551
|
-
}
|
|
5552
|
-
return false;
|
|
5553
|
-
}
|
|
5554
|
-
|
|
5555
|
-
// src/mocks.ts
|
|
5557
|
+
H();
|
|
5558
|
+
A();
|
|
5556
5559
|
var qe = Object.freeze({
|
|
5557
5560
|
uid: "dev-fixture-uid-0001",
|
|
5558
5561
|
email: "dev@neetru.local",
|
|
@@ -5560,12 +5563,12 @@ var qe = Object.freeze({
|
|
|
5560
5563
|
displayName: "Dev Fixture",
|
|
5561
5564
|
isCustomer: true,
|
|
5562
5565
|
isStaff: false
|
|
5563
|
-
}),
|
|
5566
|
+
}), de = class {
|
|
5564
5567
|
_user;
|
|
5565
5568
|
_listeners;
|
|
5566
5569
|
_allowUnsignedDecode;
|
|
5567
5570
|
constructor(e = null, t) {
|
|
5568
|
-
if (this._user = e, this._listeners = /* @__PURE__ */ new Set(), this._allowUnsignedDecode = t?.allowUnsignedDecode ?? false, this._allowUnsignedDecode &&
|
|
5571
|
+
if (this._user = e, this._listeners = /* @__PURE__ */ new Set(), this._allowUnsignedDecode = t?.allowUnsignedDecode ?? false, this._allowUnsignedDecode && Be())
|
|
5569
5572
|
throw new c(
|
|
5570
5573
|
"invalid_config",
|
|
5571
5574
|
"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."
|
|
@@ -5578,7 +5581,7 @@ var qe = Object.freeze({
|
|
|
5578
5581
|
return this._user || (this._user = { ...qe }), this._notify(), this._user;
|
|
5579
5582
|
}
|
|
5580
5583
|
async signOut() {
|
|
5581
|
-
this._user = null, this._notify();
|
|
5584
|
+
return this._user = null, this._notify(), { localSessionCleared: true, remoteRevocation: "skipped" };
|
|
5582
5585
|
}
|
|
5583
5586
|
getUser() {
|
|
5584
5587
|
return this._user;
|
|
@@ -5696,7 +5699,7 @@ var qe = Object.freeze({
|
|
|
5696
5699
|
} catch {
|
|
5697
5700
|
}
|
|
5698
5701
|
}
|
|
5699
|
-
},
|
|
5702
|
+
}, ue = class {
|
|
5700
5703
|
_reports = [];
|
|
5701
5704
|
_quotas;
|
|
5702
5705
|
_counters = /* @__PURE__ */ new Map();
|
|
@@ -5758,7 +5761,7 @@ var qe = Object.freeze({
|
|
|
5758
5761
|
__reset() {
|
|
5759
5762
|
this._reports = [], this._quotas.clear(), this._counters.clear();
|
|
5760
5763
|
}
|
|
5761
|
-
},
|
|
5764
|
+
}, pe = class {
|
|
5762
5765
|
_tickets = [];
|
|
5763
5766
|
_ticketSeq = 0;
|
|
5764
5767
|
async createTicket(e) {
|
|
@@ -5835,7 +5838,7 @@ var qe = Object.freeze({
|
|
|
5835
5838
|
__reset() {
|
|
5836
5839
|
this._tickets = [], this._ticketSeq = 0;
|
|
5837
5840
|
}
|
|
5838
|
-
},
|
|
5841
|
+
}, fe = class {
|
|
5839
5842
|
_denied = /* @__PURE__ */ new Set();
|
|
5840
5843
|
async check(e, t) {
|
|
5841
5844
|
return !this._denied.has(`${e}:${t}`);
|
|
@@ -5857,7 +5860,7 @@ var qe = Object.freeze({
|
|
|
5857
5860
|
__reset() {
|
|
5858
5861
|
this._denied.clear();
|
|
5859
5862
|
}
|
|
5860
|
-
},
|
|
5863
|
+
}, ut = class {
|
|
5861
5864
|
_store = /* @__PURE__ */ new Map();
|
|
5862
5865
|
_fixtures;
|
|
5863
5866
|
constructor(e = {}) {
|
|
@@ -5923,9 +5926,9 @@ var qe = Object.freeze({
|
|
|
5923
5926
|
(m) => l.where.every((h) => i(m, h))
|
|
5924
5927
|
)), l?.orderBy) {
|
|
5925
5928
|
let { field: m, direction: h } = l.orderBy;
|
|
5926
|
-
u = u.slice().sort((
|
|
5927
|
-
let w =
|
|
5928
|
-
return h === "desc" ? -
|
|
5929
|
+
u = u.slice().sort((_, I) => {
|
|
5930
|
+
let w = _[m], k = I[m], D = w ?? "", y = k ?? "", b = D < y ? -1 : D > y ? 1 : 0;
|
|
5931
|
+
return h === "desc" ? -b : b;
|
|
5929
5932
|
});
|
|
5930
5933
|
}
|
|
5931
5934
|
let f = l?.limit ?? 20;
|
|
@@ -6044,11 +6047,11 @@ var qe = Object.freeze({
|
|
|
6044
6047
|
), h = await f.PGlite.create();
|
|
6045
6048
|
for (let w of r)
|
|
6046
6049
|
await h.query(w);
|
|
6047
|
-
let
|
|
6050
|
+
let _ = m.drizzle(h, { schema: e });
|
|
6048
6051
|
return {
|
|
6049
|
-
orm:
|
|
6052
|
+
orm: _,
|
|
6050
6053
|
async transaction(w, k) {
|
|
6051
|
-
return await
|
|
6054
|
+
return await _.transaction(w);
|
|
6052
6055
|
},
|
|
6053
6056
|
async close() {
|
|
6054
6057
|
h.closed || await h.close();
|
|
@@ -6078,8 +6081,8 @@ var qe = Object.freeze({
|
|
|
6078
6081
|
let d = s.adapters.createPg().Pool, p = new d(), l = p.query.bind(p);
|
|
6079
6082
|
p.query = (f, ...m) => {
|
|
6080
6083
|
if (f !== null && typeof f == "object") {
|
|
6081
|
-
let
|
|
6082
|
-
|
|
6084
|
+
let _ = f.types;
|
|
6085
|
+
_ !== null && typeof _ == "object" && "getTypeParser" in _ && delete _.getTypeParser;
|
|
6083
6086
|
}
|
|
6084
6087
|
return l(f, ...m);
|
|
6085
6088
|
};
|
|
@@ -6123,7 +6126,7 @@ var qe = Object.freeze({
|
|
|
6123
6126
|
__reset() {
|
|
6124
6127
|
this._store.clear();
|
|
6125
6128
|
}
|
|
6126
|
-
},
|
|
6129
|
+
}, me = class {
|
|
6127
6130
|
_calls = [];
|
|
6128
6131
|
/** Extrai texto de um content string OU array multimodal (imagens ignoradas). */
|
|
6129
6132
|
_contentToText(e) {
|
|
@@ -6170,9 +6173,30 @@ var qe = Object.freeze({
|
|
|
6170
6173
|
}
|
|
6171
6174
|
};
|
|
6172
6175
|
|
|
6176
|
+
// src/timeout.ts
|
|
6177
|
+
function zn(n) {
|
|
6178
|
+
let e = globalThis.AbortSignal;
|
|
6179
|
+
if (typeof e?.timeout == "function")
|
|
6180
|
+
return { signal: e.timeout(n), clear: () => {
|
|
6181
|
+
} };
|
|
6182
|
+
if (typeof globalThis.AbortController != "function")
|
|
6183
|
+
return { signal: void 0, clear: () => {
|
|
6184
|
+
} };
|
|
6185
|
+
let t = new AbortController(), r = setTimeout(() => t.abort(), n);
|
|
6186
|
+
return r.unref?.(), { signal: t.signal, clear: () => clearTimeout(r) };
|
|
6187
|
+
}
|
|
6188
|
+
function Hn(n, e, t) {
|
|
6189
|
+
let r, o = new Promise((i) => {
|
|
6190
|
+
r = setTimeout(() => i(t()), e), r.unref?.();
|
|
6191
|
+
});
|
|
6192
|
+
return Promise.race([n, o]).finally(() => {
|
|
6193
|
+
r !== void 0 && clearTimeout(r);
|
|
6194
|
+
});
|
|
6195
|
+
}
|
|
6196
|
+
|
|
6173
6197
|
// src/auth-pkce-shared.ts
|
|
6174
|
-
|
|
6175
|
-
function
|
|
6198
|
+
A();
|
|
6199
|
+
function Qn() {
|
|
6176
6200
|
let n = globalThis.crypto;
|
|
6177
6201
|
if (!n || typeof n.getRandomValues != "function" || !n.subtle)
|
|
6178
6202
|
throw new c(
|
|
@@ -6181,36 +6205,36 @@ function Bn() {
|
|
|
6181
6205
|
);
|
|
6182
6206
|
return n;
|
|
6183
6207
|
}
|
|
6184
|
-
function
|
|
6208
|
+
function Gn(n) {
|
|
6185
6209
|
let e = "";
|
|
6186
6210
|
for (let r of n) e += String.fromCharCode(r);
|
|
6187
6211
|
return (typeof btoa == "function" ? btoa(e) : Buffer.from(e, "binary").toString("base64")).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
6188
6212
|
}
|
|
6189
6213
|
function Fe(n, e) {
|
|
6190
6214
|
let t = new Uint8Array(e);
|
|
6191
|
-
return n.getRandomValues(t),
|
|
6215
|
+
return n.getRandomValues(t), Gn(t);
|
|
6192
6216
|
}
|
|
6193
|
-
async function
|
|
6217
|
+
async function Jn(n, e) {
|
|
6194
6218
|
let t = new TextEncoder().encode(e), r = await n.subtle.digest("SHA-256", t);
|
|
6195
|
-
return
|
|
6219
|
+
return Gn(new Uint8Array(r));
|
|
6196
6220
|
}
|
|
6197
|
-
function
|
|
6221
|
+
function he(n) {
|
|
6198
6222
|
return (typeof globalThis.NEETRU_AUTH_URL == "string" ? globalThis.NEETRU_AUTH_URL : null) ?? n.replace(/^https?:\/\/api\./, "https://auth.");
|
|
6199
6223
|
}
|
|
6200
|
-
function
|
|
6224
|
+
function Xn(n) {
|
|
6201
6225
|
let e = n.oidcClientId;
|
|
6202
|
-
if (!e && n.apiKey && (e =
|
|
6226
|
+
if (!e && n.apiKey && (e = _t(n.apiKey).keyId), !e)
|
|
6203
6227
|
throw new c(
|
|
6204
6228
|
"invalid_config",
|
|
6205
6229
|
"auth OIDC requer `oidcClientId` (ou `apiKey`) configurado para montar o client_id."
|
|
6206
6230
|
);
|
|
6207
6231
|
return e;
|
|
6208
6232
|
}
|
|
6209
|
-
function
|
|
6233
|
+
function Yn(n) {
|
|
6210
6234
|
let e = new URL("/api/v1/oauth/authorize", n.idpOrigin);
|
|
6211
6235
|
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;
|
|
6212
6236
|
}
|
|
6213
|
-
function
|
|
6237
|
+
function pt(n) {
|
|
6214
6238
|
let e = n.split(".");
|
|
6215
6239
|
if (e.length !== 3) return null;
|
|
6216
6240
|
try {
|
|
@@ -6220,8 +6244,8 @@ function dt(n) {
|
|
|
6220
6244
|
return null;
|
|
6221
6245
|
}
|
|
6222
6246
|
}
|
|
6223
|
-
function
|
|
6224
|
-
let e =
|
|
6247
|
+
function ge(n) {
|
|
6248
|
+
let e = pt(n);
|
|
6225
6249
|
return !e || typeof e.sub != "string" || typeof e.exp == "number" && e.exp * 1e3 < Date.now() ? null : {
|
|
6226
6250
|
uid: e.sub,
|
|
6227
6251
|
email: typeof e.email == "string" ? e.email : "",
|
|
@@ -6234,9 +6258,9 @@ function he(n) {
|
|
|
6234
6258
|
...e
|
|
6235
6259
|
};
|
|
6236
6260
|
}
|
|
6237
|
-
var
|
|
6238
|
-
async function
|
|
6239
|
-
let o = `${e}${
|
|
6261
|
+
var Yo = "/api/v1/oauth/revoke";
|
|
6262
|
+
async function Zn(n, e, t, r) {
|
|
6263
|
+
let o = `${e}${Yo}`, i = true;
|
|
6240
6264
|
for (let s of r) {
|
|
6241
6265
|
if (!s.token) continue;
|
|
6242
6266
|
let a = new URLSearchParams({
|
|
@@ -6260,17 +6284,17 @@ async function Qn(n, e, t, r) {
|
|
|
6260
6284
|
}
|
|
6261
6285
|
|
|
6262
6286
|
// src/auth.ts
|
|
6263
|
-
|
|
6287
|
+
ve();
|
|
6264
6288
|
|
|
6265
6289
|
// src/end-user-token.ts
|
|
6266
|
-
var
|
|
6267
|
-
function
|
|
6268
|
-
|
|
6290
|
+
var Zo = /* @__PURE__ */ new WeakMap();
|
|
6291
|
+
function er(n, e) {
|
|
6292
|
+
Zo.set(n, e);
|
|
6269
6293
|
}
|
|
6270
6294
|
|
|
6271
6295
|
// src/unsupported-db.ts
|
|
6272
|
-
|
|
6273
|
-
var
|
|
6296
|
+
A();
|
|
6297
|
+
var ei = "[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.)", ti = /* @__PURE__ */ new Set([
|
|
6274
6298
|
"then",
|
|
6275
6299
|
"toJSON",
|
|
6276
6300
|
"valueOf",
|
|
@@ -6279,13 +6303,13 @@ var Qo = "[Neetru SDK] client.db n\xE3o est\xE1 dispon\xEDvel em React Native. O
|
|
|
6279
6303
|
"asymmetricMatch",
|
|
6280
6304
|
"nodeType"
|
|
6281
6305
|
]);
|
|
6282
|
-
function
|
|
6306
|
+
function tr() {
|
|
6283
6307
|
let n = () => {
|
|
6284
|
-
throw new c("runtime_unsupported",
|
|
6308
|
+
throw new c("runtime_unsupported", ei, void 0, void 0, "react-native");
|
|
6285
6309
|
}, e = {};
|
|
6286
6310
|
return new Proxy(e, {
|
|
6287
6311
|
get(t, r) {
|
|
6288
|
-
if (!(typeof r == "symbol" ||
|
|
6312
|
+
if (!(typeof r == "symbol" || ti.has(r)))
|
|
6289
6313
|
return r === "toString" ? () => "[NeetruDb indispon\xEDvel em React Native]" : n;
|
|
6290
6314
|
},
|
|
6291
6315
|
set() {
|
|
@@ -6295,7 +6319,7 @@ function Xn() {
|
|
|
6295
6319
|
}
|
|
6296
6320
|
|
|
6297
6321
|
// src/auth.ts
|
|
6298
|
-
function
|
|
6322
|
+
function ri() {
|
|
6299
6323
|
try {
|
|
6300
6324
|
let e = globalThis.process?.env?.NEETRU_API_KEY;
|
|
6301
6325
|
return typeof e == "string" && e.length > 0 ? e : void 0;
|
|
@@ -6303,7 +6327,7 @@ function Yo() {
|
|
|
6303
6327
|
return;
|
|
6304
6328
|
}
|
|
6305
6329
|
}
|
|
6306
|
-
function
|
|
6330
|
+
function oi(n) {
|
|
6307
6331
|
if (n) return n;
|
|
6308
6332
|
try {
|
|
6309
6333
|
let t = globalThis.process?.env?.NEETRU_ENV;
|
|
@@ -6317,8 +6341,8 @@ function Zo(n) {
|
|
|
6317
6341
|
}
|
|
6318
6342
|
return "prod";
|
|
6319
6343
|
}
|
|
6320
|
-
var
|
|
6321
|
-
function
|
|
6344
|
+
var ii = _e;
|
|
6345
|
+
function si(n) {
|
|
6322
6346
|
let e = n.sub ?? "", t = typeof n.email == "string" ? n.email : "";
|
|
6323
6347
|
return {
|
|
6324
6348
|
uid: e,
|
|
@@ -6333,8 +6357,8 @@ function ti(n) {
|
|
|
6333
6357
|
...n
|
|
6334
6358
|
};
|
|
6335
6359
|
}
|
|
6336
|
-
var
|
|
6337
|
-
function
|
|
6360
|
+
var ye = "neetru_oauth_tx";
|
|
6361
|
+
function ft(n) {
|
|
6338
6362
|
try {
|
|
6339
6363
|
let e = globalThis.history;
|
|
6340
6364
|
if (!e || typeof e.replaceState != "function") return;
|
|
@@ -6345,7 +6369,7 @@ function ut(n) {
|
|
|
6345
6369
|
} catch {
|
|
6346
6370
|
}
|
|
6347
6371
|
}
|
|
6348
|
-
function
|
|
6372
|
+
function ai(n) {
|
|
6349
6373
|
let e = "neetru_id_token", t = "neetru_refresh_token", r = /* @__PURE__ */ new Set(), o = null, i = null, s = null;
|
|
6350
6374
|
function a() {
|
|
6351
6375
|
try {
|
|
@@ -6363,21 +6387,21 @@ function ni(n) {
|
|
|
6363
6387
|
}
|
|
6364
6388
|
function p() {
|
|
6365
6389
|
if (o) {
|
|
6366
|
-
let
|
|
6367
|
-
return typeof
|
|
6390
|
+
let g = o.exp;
|
|
6391
|
+
return typeof g == "number" && g * 1e3 < Date.now() ? (o = null, a()?.removeItem(e), l(), _(), null) : o;
|
|
6368
6392
|
}
|
|
6369
|
-
let
|
|
6370
|
-
if (!
|
|
6371
|
-
let
|
|
6372
|
-
if (!
|
|
6373
|
-
return
|
|
6374
|
-
let T =
|
|
6375
|
-
return T ? (o = T, I(T), o) : (
|
|
6393
|
+
let y = a();
|
|
6394
|
+
if (!y) return null;
|
|
6395
|
+
let b = y.getItem(e);
|
|
6396
|
+
if (!b)
|
|
6397
|
+
return _(), null;
|
|
6398
|
+
let T = ge(b);
|
|
6399
|
+
return T ? (o = T, I(T), o) : (y.removeItem(e), _(), null);
|
|
6376
6400
|
}
|
|
6377
6401
|
function l() {
|
|
6378
|
-
for (let
|
|
6402
|
+
for (let y of r)
|
|
6379
6403
|
try {
|
|
6380
|
-
|
|
6404
|
+
y(o);
|
|
6381
6405
|
} catch {
|
|
6382
6406
|
}
|
|
6383
6407
|
}
|
|
@@ -6389,70 +6413,75 @@ function ni(n) {
|
|
|
6389
6413
|
}
|
|
6390
6414
|
function m() {
|
|
6391
6415
|
o = null;
|
|
6392
|
-
let
|
|
6393
|
-
|
|
6416
|
+
let y = a();
|
|
6417
|
+
y?.removeItem(e), y?.removeItem(t), l();
|
|
6394
6418
|
}
|
|
6395
6419
|
function h() {
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6420
|
+
if (s) return s;
|
|
6421
|
+
let y = false, b = (async () => {
|
|
6422
|
+
let T = f();
|
|
6423
|
+
if (!T) return false;
|
|
6424
|
+
let g;
|
|
6400
6425
|
try {
|
|
6401
|
-
|
|
6426
|
+
g = w();
|
|
6402
6427
|
} catch {
|
|
6403
6428
|
return false;
|
|
6404
6429
|
}
|
|
6405
|
-
let
|
|
6430
|
+
let x = `${he(n.baseUrl)}/api/v1/oauth/token`, L = new URLSearchParams({
|
|
6406
6431
|
grant_type: "refresh_token",
|
|
6407
|
-
refresh_token:
|
|
6408
|
-
client_id:
|
|
6409
|
-
}),
|
|
6432
|
+
refresh_token: T,
|
|
6433
|
+
client_id: g
|
|
6434
|
+
}), { signal: P, clear: q } = zn(15e3), E;
|
|
6410
6435
|
try {
|
|
6411
|
-
|
|
6436
|
+
E = await n.fetch(x, {
|
|
6412
6437
|
method: "POST",
|
|
6413
6438
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
6414
|
-
body:
|
|
6439
|
+
body: L.toString(),
|
|
6440
|
+
signal: P
|
|
6415
6441
|
});
|
|
6416
6442
|
} catch {
|
|
6417
6443
|
return false;
|
|
6444
|
+
} finally {
|
|
6445
|
+
q();
|
|
6418
6446
|
}
|
|
6419
|
-
let
|
|
6447
|
+
let U = null;
|
|
6420
6448
|
try {
|
|
6421
|
-
|
|
6449
|
+
U = await E.json();
|
|
6422
6450
|
} catch {
|
|
6423
|
-
|
|
6451
|
+
U = null;
|
|
6424
6452
|
}
|
|
6425
|
-
if (!
|
|
6426
|
-
let
|
|
6427
|
-
if (typeof
|
|
6428
|
-
let
|
|
6429
|
-
if (!
|
|
6430
|
-
let
|
|
6431
|
-
|
|
6432
|
-
let
|
|
6433
|
-
return typeof
|
|
6434
|
-
})()
|
|
6453
|
+
if (!E.ok || typeof U?.error == "string") return false;
|
|
6454
|
+
let M = U?.id_token;
|
|
6455
|
+
if (typeof M != "string" || M.length === 0) return false;
|
|
6456
|
+
let j = ge(M);
|
|
6457
|
+
if (!j || y) return false;
|
|
6458
|
+
let N = a();
|
|
6459
|
+
N?.setItem(e, M);
|
|
6460
|
+
let je = U?.refresh_token;
|
|
6461
|
+
return typeof je == "string" && je.length > 0 && N?.setItem(t, je), o = j, I(j), l(), true;
|
|
6462
|
+
})();
|
|
6463
|
+
return s = Hn(b, 15e3, () => (y = true, false)).finally(() => {
|
|
6435
6464
|
s = null;
|
|
6436
|
-
}), s
|
|
6465
|
+
}), s;
|
|
6437
6466
|
}
|
|
6438
|
-
function
|
|
6439
|
-
f() && h().then((
|
|
6440
|
-
|
|
6467
|
+
function _() {
|
|
6468
|
+
f() && h().then((y) => {
|
|
6469
|
+
y || m();
|
|
6441
6470
|
});
|
|
6442
6471
|
}
|
|
6443
|
-
function I(
|
|
6472
|
+
function I(y) {
|
|
6444
6473
|
u();
|
|
6445
|
-
let
|
|
6446
|
-
if (typeof
|
|
6447
|
-
let T =
|
|
6474
|
+
let b = y.exp;
|
|
6475
|
+
if (typeof b != "number") return;
|
|
6476
|
+
let T = b * 1e3 - Date.now();
|
|
6448
6477
|
if (!(T <= 0)) {
|
|
6449
6478
|
if (f()) {
|
|
6450
|
-
let
|
|
6479
|
+
let g = Math.min(T, Math.max(3e4, T * 0.2)), C = Math.max(1, T - g);
|
|
6451
6480
|
i = setTimeout(() => {
|
|
6452
6481
|
i = null, h().then((x) => {
|
|
6453
6482
|
x || m();
|
|
6454
6483
|
});
|
|
6455
|
-
},
|
|
6484
|
+
}, C);
|
|
6456
6485
|
return;
|
|
6457
6486
|
}
|
|
6458
6487
|
i = setTimeout(() => {
|
|
@@ -6461,140 +6490,140 @@ function ni(n) {
|
|
|
6461
6490
|
}
|
|
6462
6491
|
}
|
|
6463
6492
|
function w() {
|
|
6464
|
-
return
|
|
6493
|
+
return Xn(n);
|
|
6465
6494
|
}
|
|
6466
|
-
async function k(
|
|
6467
|
-
let
|
|
6468
|
-
if (!
|
|
6495
|
+
async function k(y) {
|
|
6496
|
+
let b = y ?? (typeof globalThis.location < "u" ? globalThis.location.href : void 0);
|
|
6497
|
+
if (!b) return null;
|
|
6469
6498
|
let T;
|
|
6470
6499
|
try {
|
|
6471
|
-
T = new URL(
|
|
6500
|
+
T = new URL(b);
|
|
6472
6501
|
} catch {
|
|
6473
6502
|
return null;
|
|
6474
6503
|
}
|
|
6475
|
-
let
|
|
6476
|
-
if (
|
|
6477
|
-
let
|
|
6478
|
-
throw d()?.removeItem(
|
|
6504
|
+
let g = T.searchParams, C = g.get("error");
|
|
6505
|
+
if (C) {
|
|
6506
|
+
let U = g.get("error_description") ?? C;
|
|
6507
|
+
throw d()?.removeItem(ye), ft(T), new c(C, `OIDC authorize falhou: ${U}`);
|
|
6479
6508
|
}
|
|
6480
|
-
let x =
|
|
6509
|
+
let x = g.get("code");
|
|
6481
6510
|
if (!x) return null;
|
|
6482
|
-
let
|
|
6483
|
-
if (
|
|
6511
|
+
let L = g.get("state"), P = d(), q = P?.getItem(ye) ?? null, E = null;
|
|
6512
|
+
if (q)
|
|
6484
6513
|
try {
|
|
6485
|
-
|
|
6514
|
+
E = JSON.parse(q);
|
|
6486
6515
|
} catch {
|
|
6487
|
-
|
|
6516
|
+
E = null;
|
|
6488
6517
|
}
|
|
6489
|
-
if (!
|
|
6518
|
+
if (!E)
|
|
6490
6519
|
throw new c(
|
|
6491
6520
|
"oidc_state_mismatch",
|
|
6492
6521
|
"Callback OIDC sem transa\xE7\xE3o pendente \u2014 `signIn` n\xE3o foi iniciado nesta sess\xE3o (ou j\xE1 consumido)."
|
|
6493
6522
|
);
|
|
6494
|
-
if (!
|
|
6495
|
-
throw
|
|
6523
|
+
if (!L || L !== E.state)
|
|
6524
|
+
throw P?.removeItem(ye), ft(T), new c(
|
|
6496
6525
|
"oidc_state_mismatch",
|
|
6497
6526
|
"state do callback OIDC n\xE3o confere com o da transa\xE7\xE3o (poss\xEDvel CSRF)."
|
|
6498
6527
|
);
|
|
6499
|
-
return
|
|
6528
|
+
return P?.removeItem(ye), ft(T), {
|
|
6500
6529
|
code: x,
|
|
6501
|
-
codeVerifier:
|
|
6502
|
-
redirectUri:
|
|
6503
|
-
nonce:
|
|
6504
|
-
state:
|
|
6505
|
-
postLoginRedirect:
|
|
6530
|
+
codeVerifier: E.codeVerifier,
|
|
6531
|
+
redirectUri: E.redirectUri,
|
|
6532
|
+
nonce: E.nonce,
|
|
6533
|
+
state: E.state,
|
|
6534
|
+
postLoginRedirect: E.postLoginRedirect
|
|
6506
6535
|
};
|
|
6507
6536
|
}
|
|
6508
|
-
async function
|
|
6509
|
-
let
|
|
6510
|
-
if (!
|
|
6511
|
-
let T = w(),
|
|
6537
|
+
async function D(y) {
|
|
6538
|
+
let b = await k(y);
|
|
6539
|
+
if (!b) return null;
|
|
6540
|
+
let T = w(), C = `${he(n.baseUrl)}/api/v1/oauth/token`, x = new URLSearchParams({
|
|
6512
6541
|
grant_type: "authorization_code",
|
|
6513
|
-
code:
|
|
6514
|
-
redirect_uri:
|
|
6542
|
+
code: b.code,
|
|
6543
|
+
redirect_uri: b.redirectUri,
|
|
6515
6544
|
client_id: T,
|
|
6516
|
-
code_verifier:
|
|
6517
|
-
}),
|
|
6545
|
+
code_verifier: b.codeVerifier
|
|
6546
|
+
}), L;
|
|
6518
6547
|
try {
|
|
6519
|
-
|
|
6548
|
+
L = await n.fetch(C, {
|
|
6520
6549
|
method: "POST",
|
|
6521
6550
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
6522
6551
|
body: x.toString()
|
|
6523
6552
|
});
|
|
6524
|
-
} catch (
|
|
6553
|
+
} catch (N) {
|
|
6525
6554
|
throw new c(
|
|
6526
6555
|
"network_error",
|
|
6527
|
-
`POST ${
|
|
6556
|
+
`POST ${C} falhou (network): ${N?.message ?? String(N)}`
|
|
6528
6557
|
);
|
|
6529
6558
|
}
|
|
6530
|
-
let
|
|
6559
|
+
let P = null;
|
|
6531
6560
|
try {
|
|
6532
|
-
|
|
6561
|
+
P = await L.json();
|
|
6533
6562
|
} catch {
|
|
6534
|
-
|
|
6563
|
+
P = null;
|
|
6535
6564
|
}
|
|
6536
|
-
if (!
|
|
6537
|
-
let
|
|
6565
|
+
if (!L.ok || typeof P?.error == "string") {
|
|
6566
|
+
let N = typeof P?.error_description == "string" && P.error_description || typeof P?.error == "string" && P.error || `HTTP ${L.status}`;
|
|
6538
6567
|
throw new c(
|
|
6539
6568
|
"token_exchange_failed",
|
|
6540
|
-
`Troca do authorization_code por tokens falhou no /token: ${
|
|
6541
|
-
|
|
6569
|
+
`Troca do authorization_code por tokens falhou no /token: ${N}`,
|
|
6570
|
+
L.status
|
|
6542
6571
|
);
|
|
6543
6572
|
}
|
|
6544
|
-
let
|
|
6545
|
-
if (typeof
|
|
6573
|
+
let q = P?.id_token;
|
|
6574
|
+
if (typeof q != "string" || q.length === 0)
|
|
6546
6575
|
throw new c(
|
|
6547
6576
|
"token_exchange_failed",
|
|
6548
6577
|
"Resposta do /token sem `id_token` \u2014 o login n\xE3o pode ser completado.",
|
|
6549
|
-
|
|
6578
|
+
L.status
|
|
6550
6579
|
);
|
|
6551
|
-
let
|
|
6552
|
-
if (!
|
|
6580
|
+
let E = pt(q);
|
|
6581
|
+
if (!E)
|
|
6553
6582
|
throw new c(
|
|
6554
6583
|
"token_exchange_failed",
|
|
6555
6584
|
"id_token retornado pelo /token \xE9 malformado (payload indecodific\xE1vel)."
|
|
6556
6585
|
);
|
|
6557
|
-
if (
|
|
6586
|
+
if (E.nonce !== b.nonce)
|
|
6558
6587
|
throw new c(
|
|
6559
6588
|
"oidc_nonce_mismatch",
|
|
6560
6589
|
"nonce do id_token n\xE3o confere com o da transa\xE7\xE3o OIDC (poss\xEDvel replay). Token descartado."
|
|
6561
6590
|
);
|
|
6562
|
-
let
|
|
6563
|
-
if (!
|
|
6591
|
+
let U = ge(q);
|
|
6592
|
+
if (!U)
|
|
6564
6593
|
throw new c(
|
|
6565
6594
|
"token_exchange_failed",
|
|
6566
6595
|
"id_token retornado pelo /token n\xE3o tem `sub` ou j\xE1 est\xE1 expirado."
|
|
6567
6596
|
);
|
|
6568
|
-
let
|
|
6569
|
-
|
|
6570
|
-
let j =
|
|
6571
|
-
return typeof j == "string" && j.length > 0 &&
|
|
6597
|
+
let M = a();
|
|
6598
|
+
M?.setItem(e, q);
|
|
6599
|
+
let j = P?.refresh_token;
|
|
6600
|
+
return typeof j == "string" && j.length > 0 && M?.setItem(t, j), o = U, I(U), l(), { user: U, postLoginRedirect: b.postLoginRedirect };
|
|
6572
6601
|
}
|
|
6573
6602
|
return {
|
|
6574
|
-
async signIn(
|
|
6603
|
+
async signIn(y) {
|
|
6575
6604
|
if (typeof globalThis.location < "u" && typeof globalThis.location.assign == "function") {
|
|
6576
|
-
let
|
|
6577
|
-
if (!
|
|
6605
|
+
let b = Qn(), T = y?.redirectUri ?? globalThis.location.origin, g = y?.scope ?? "openid profile email", C = w(), x = Fe(b, 16), L = Fe(b, 16), P = Fe(b, 32), q = await Jn(b, P), E = d();
|
|
6606
|
+
if (!E)
|
|
6578
6607
|
throw new c(
|
|
6579
6608
|
"runtime_unsupported",
|
|
6580
6609
|
"auth.signIn requer sessionStorage para guardar a transa\xE7\xE3o PKCE entre o redirect e o callback."
|
|
6581
6610
|
);
|
|
6582
|
-
let
|
|
6611
|
+
let U = {
|
|
6583
6612
|
state: x,
|
|
6584
|
-
nonce:
|
|
6585
|
-
codeVerifier:
|
|
6613
|
+
nonce: L,
|
|
6614
|
+
codeVerifier: P,
|
|
6586
6615
|
redirectUri: T,
|
|
6587
|
-
postLoginRedirect:
|
|
6616
|
+
postLoginRedirect: y?.postLoginRedirect
|
|
6588
6617
|
};
|
|
6589
|
-
|
|
6590
|
-
let
|
|
6591
|
-
idpOrigin:
|
|
6592
|
-
clientId:
|
|
6618
|
+
E.setItem(ye, JSON.stringify(U));
|
|
6619
|
+
let M = he(n.baseUrl), j = Yn({
|
|
6620
|
+
idpOrigin: M,
|
|
6621
|
+
clientId: C,
|
|
6593
6622
|
redirectUri: T,
|
|
6594
|
-
scope:
|
|
6623
|
+
scope: g,
|
|
6595
6624
|
state: x,
|
|
6596
|
-
nonce:
|
|
6597
|
-
codeChallenge:
|
|
6625
|
+
nonce: L,
|
|
6626
|
+
codeChallenge: q
|
|
6598
6627
|
});
|
|
6599
6628
|
globalThis.location.assign(j.toString());
|
|
6600
6629
|
return;
|
|
@@ -6605,78 +6634,90 @@ function ni(n) {
|
|
|
6605
6634
|
);
|
|
6606
6635
|
},
|
|
6607
6636
|
handleRedirectCallback: k,
|
|
6608
|
-
completeSignIn:
|
|
6637
|
+
completeSignIn: D,
|
|
6609
6638
|
// 3.7.0: exposto pro client.support renovar a sessão 1x num 401
|
|
6610
6639
|
// invalid_end_user_token (mesma função do refresh proativo, com dedup).
|
|
6611
6640
|
refreshTokens: h,
|
|
6612
6641
|
getIdToken() {
|
|
6613
|
-
let
|
|
6614
|
-
return
|
|
6642
|
+
let b = a()?.getItem(e) ?? null;
|
|
6643
|
+
return b && ge(b) ? b : null;
|
|
6615
6644
|
},
|
|
6616
6645
|
async signOut() {
|
|
6617
|
-
let
|
|
6618
|
-
if (
|
|
6619
|
-
let
|
|
6646
|
+
let y = a(), b = y?.getItem(t) ?? null, T = true;
|
|
6647
|
+
if (y)
|
|
6648
|
+
for (let C of [e, t])
|
|
6649
|
+
try {
|
|
6650
|
+
y.removeItem(C);
|
|
6651
|
+
} catch {
|
|
6652
|
+
T = false;
|
|
6653
|
+
}
|
|
6654
|
+
u(), o = null;
|
|
6655
|
+
let g = "skipped";
|
|
6656
|
+
if (b) {
|
|
6657
|
+
let C = null;
|
|
6620
6658
|
try {
|
|
6621
|
-
|
|
6659
|
+
C = w();
|
|
6622
6660
|
} catch {
|
|
6623
|
-
|
|
6661
|
+
C = null;
|
|
6624
6662
|
}
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6663
|
+
C ? g = await Zn(
|
|
6664
|
+
n.fetch,
|
|
6665
|
+
he(n.baseUrl),
|
|
6666
|
+
C,
|
|
6667
|
+
[{ token: b, hint: "refresh_token" }]
|
|
6668
|
+
) ? "accepted" : "failed" : g = "not_configured", g !== "accepted" && typeof console < "u" && console.warn(
|
|
6669
|
+
"[neetru-sdk] signOut: a revoga\xE7\xE3o do refresh_token no servidor n\xE3o foi confirmada (" + g + "). A sess\xE3o local foi encerrada, mas o refresh_token pode seguir v\xE1lido at\xE9 expirar. Trate o campo remoteRevocation do SignOutResult no produto."
|
|
6629
6670
|
);
|
|
6630
6671
|
}
|
|
6631
|
-
l();
|
|
6672
|
+
return l(), { localSessionCleared: T, remoteRevocation: g };
|
|
6632
6673
|
},
|
|
6633
6674
|
getUser() {
|
|
6634
6675
|
return p();
|
|
6635
6676
|
},
|
|
6636
|
-
onAuthStateChanged(
|
|
6637
|
-
r.add(
|
|
6677
|
+
onAuthStateChanged(y) {
|
|
6678
|
+
r.add(y);
|
|
6638
6679
|
try {
|
|
6639
|
-
|
|
6680
|
+
y(p());
|
|
6640
6681
|
} catch {
|
|
6641
6682
|
}
|
|
6642
6683
|
return () => {
|
|
6643
|
-
r.delete(
|
|
6684
|
+
r.delete(y);
|
|
6644
6685
|
};
|
|
6645
6686
|
},
|
|
6646
|
-
async verifyToken(
|
|
6647
|
-
if (!
|
|
6687
|
+
async verifyToken(y, b) {
|
|
6688
|
+
if (!y || typeof y != "string")
|
|
6648
6689
|
throw new c("token_invalid_signature", "token must be a non-empty string");
|
|
6649
|
-
let
|
|
6650
|
-
if (!
|
|
6690
|
+
let g = (typeof globalThis.NEETRU_AUTH_URL == "string" ? globalThis.NEETRU_AUTH_URL : null) ?? n.baseUrl.replace(/^https?:\/\/api\./, "https://auth."), C = g, x = `${g}/api/v1/oauth/.well-known/jwks`, L = b?.jwksCacheTtlMs ?? te, P = b?.audience, q = bt(n.apiKey), E = P ?? n.oidcClientId ?? q?.keyId;
|
|
6691
|
+
if (!E)
|
|
6651
6692
|
throw new c(
|
|
6652
6693
|
"invalid_config",
|
|
6653
6694
|
"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."
|
|
6654
6695
|
);
|
|
6655
|
-
let
|
|
6696
|
+
let U = ii(x, L);
|
|
6656
6697
|
try {
|
|
6657
|
-
let { payload:
|
|
6658
|
-
issuer:
|
|
6659
|
-
audience:
|
|
6698
|
+
let { payload: M } = await jwtVerify(y, U, {
|
|
6699
|
+
issuer: C,
|
|
6700
|
+
audience: E,
|
|
6660
6701
|
algorithms: ["RS256"]
|
|
6661
6702
|
});
|
|
6662
|
-
return
|
|
6663
|
-
} catch (
|
|
6664
|
-
let j =
|
|
6665
|
-
throw j === "ERR_JWT_EXPIRED" ? new c("token_expired", `Token expired: ${
|
|
6703
|
+
return si(M);
|
|
6704
|
+
} catch (M) {
|
|
6705
|
+
let j = M?.code ?? M?.name ?? "", N = M?.message ?? String(M);
|
|
6706
|
+
throw j === "ERR_JWT_EXPIRED" ? new c("token_expired", `Token expired: ${N}`) : j === "ERR_JWS_SIGNATURE_VERIFICATION_FAILED" ? new c("token_invalid_signature", `Token signature invalid: ${N}`) : j === "ERR_JWT_CLAIM_VALIDATION_FAILED" ? N.includes('"aud"') || N.includes("audience") ? new c("token_invalid_audience", `Token audience mismatch: ${N}`) : N.includes('"iss"') || N.includes("issuer") ? new c("token_invalid_issuer", `Token issuer mismatch: ${N}`) : new c("token_invalid_signature", `Token claim validation failed: ${N}`) : new c("token_invalid_signature", `Token verification failed: ${N}`);
|
|
6666
6707
|
}
|
|
6667
6708
|
}
|
|
6668
6709
|
};
|
|
6669
6710
|
}
|
|
6670
|
-
function
|
|
6711
|
+
function rr(n = {}) {
|
|
6671
6712
|
let e = n.fetch ?? globalThis.fetch;
|
|
6672
6713
|
if (typeof e != "function")
|
|
6673
6714
|
throw new c(
|
|
6674
6715
|
"invalid_config",
|
|
6675
6716
|
"fetch is not available in this runtime. Pass `fetch` explicitly to createNeetruClient."
|
|
6676
6717
|
);
|
|
6677
|
-
let t = n.apiKey ??
|
|
6678
|
-
|
|
6679
|
-
let r =
|
|
6718
|
+
let t = n.apiKey ?? ri();
|
|
6719
|
+
Pt({ hasApiKey: !!t, strict: n.strictServerOnlyKey === true });
|
|
6720
|
+
let r = oi(n.env), o = n.baseUrl ?? (r === "dev-local" ? St : We), i = kt(o, n.allowedHosts ?? []), s = Object.freeze({
|
|
6680
6721
|
apiKey: t,
|
|
6681
6722
|
oidcClientId: n.oidcClientId,
|
|
6682
6723
|
baseUrl: i,
|
|
@@ -6684,44 +6725,44 @@ function Yn(n = {}) {
|
|
|
6684
6725
|
env: r,
|
|
6685
6726
|
productId: n.productId,
|
|
6686
6727
|
tenantId: n.tenantId
|
|
6687
|
-
}), a = r
|
|
6728
|
+
}), a = V(r), d = n.mocks?.auth ?? (a ? new de({ ...qe }) : ai(s)), p = n.mocks?.usage ?? (a ? new ue() : Kt(s)), l = n.endUserAuth ?? d, u = n.mocks?.support ?? (a ? new pe() : Xt(s, {
|
|
6688
6729
|
getEndUserToken: () => l.getIdToken(),
|
|
6689
6730
|
// `refreshTokens` é opcional (MockAuth/mocks próprios omitem).
|
|
6690
6731
|
refreshEndUserToken: (() => {
|
|
6691
6732
|
let k = l.refreshTokens;
|
|
6692
6733
|
return typeof k == "function" ? () => k.call(l) : void 0;
|
|
6693
6734
|
})()
|
|
6694
|
-
})), f = n.mocks?.entitlements ?? (a ? new
|
|
6735
|
+
})), f = n.mocks?.entitlements ?? (a ? new fe() : jt()), m = n.mocks?.db ?? (J() === "react-native" ? tr() : ot(s, n.db)), h = n.mocks?.webhooks ?? (a ? new ce() : at(s)), _ = n.mocks?.notifications ?? (a ? new le() : lt(s)), I = n.mocks?.ai ?? (a ? new me() : dt(s)), w = Object.freeze({
|
|
6695
6736
|
config: s,
|
|
6696
6737
|
auth: d,
|
|
6697
|
-
catalog:
|
|
6738
|
+
catalog: qt(s),
|
|
6698
6739
|
entitlements: f,
|
|
6699
|
-
telemetry:
|
|
6740
|
+
telemetry: Vt(s),
|
|
6700
6741
|
usage: p,
|
|
6701
6742
|
support: u,
|
|
6702
6743
|
db: m,
|
|
6703
|
-
checkout:
|
|
6744
|
+
checkout: st(s),
|
|
6704
6745
|
webhooks: h,
|
|
6705
|
-
notifications:
|
|
6746
|
+
notifications: _,
|
|
6706
6747
|
ai: I
|
|
6707
6748
|
});
|
|
6708
|
-
return n.endUserAuth &&
|
|
6749
|
+
return n.endUserAuth && er(w, n.endUserAuth), w;
|
|
6709
6750
|
}
|
|
6710
|
-
var
|
|
6711
|
-
function
|
|
6751
|
+
var mt = /* @__PURE__ */ Symbol.for("@neetru/sdk:serverClient");
|
|
6752
|
+
function ci(n = {}) {
|
|
6712
6753
|
let e = globalThis;
|
|
6713
|
-
return e[
|
|
6754
|
+
return e[mt] || (e[mt] = rr(n)), e[mt];
|
|
6714
6755
|
}
|
|
6715
6756
|
|
|
6716
6757
|
// src/index.ts
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6758
|
+
A();
|
|
6759
|
+
H();
|
|
6760
|
+
F();
|
|
6720
6761
|
|
|
6721
6762
|
// src/access-token.ts
|
|
6722
|
-
|
|
6723
|
-
var
|
|
6724
|
-
function
|
|
6763
|
+
A();
|
|
6764
|
+
var ir = "https://auth.neetru.com", di = "/api/v1/oauth/.well-known/jwks";
|
|
6765
|
+
function sr(n) {
|
|
6725
6766
|
let e = (Array.isArray(n) ? n : [n]).filter(
|
|
6726
6767
|
(t) => typeof t == "string" && t.trim().length > 0
|
|
6727
6768
|
);
|
|
@@ -6732,17 +6773,17 @@ function tr(n) {
|
|
|
6732
6773
|
);
|
|
6733
6774
|
return e;
|
|
6734
6775
|
}
|
|
6735
|
-
var
|
|
6736
|
-
function
|
|
6776
|
+
var or = "O token apresentado n\xE3o \xE9 um access_token (parece um id_token). Mande o access_token no Authorization.";
|
|
6777
|
+
function z(n, e) {
|
|
6737
6778
|
return new c("token_invalid", n, 401, void 0, e);
|
|
6738
6779
|
}
|
|
6739
|
-
async function
|
|
6740
|
-
let t =
|
|
6780
|
+
async function ar(n, e) {
|
|
6781
|
+
let t = sr(e?.audience);
|
|
6741
6782
|
if (typeof n != "string" || n.length === 0)
|
|
6742
|
-
throw
|
|
6783
|
+
throw z("access_token ausente.", "missing_token");
|
|
6743
6784
|
if (n.split(".").length !== 3)
|
|
6744
|
-
throw
|
|
6745
|
-
let r = (e.issuer ??
|
|
6785
|
+
throw z("O token n\xE3o \xE9 um JWT (access_token OIDC esperado).", "not_a_jwt");
|
|
6786
|
+
let r = (e.issuer ?? ir).replace(/\/+$/, ""), o = e.jwksUrl ?? `${r}${di}`, i = Math.min(Math.max(e.clockToleranceSec ?? 5, 0), 60), s = _e(o, e.jwksCacheTtlMs ?? te), a;
|
|
6746
6787
|
try {
|
|
6747
6788
|
({ payload: a } = await jwtVerify(n, s, {
|
|
6748
6789
|
issuer: r,
|
|
@@ -6752,18 +6793,18 @@ async function nr(n, e) {
|
|
|
6752
6793
|
requiredClaims: ["sub", "exp", "iat", "jti"]
|
|
6753
6794
|
}));
|
|
6754
6795
|
} catch (w) {
|
|
6755
|
-
let k = w?.code ?? "",
|
|
6796
|
+
let k = w?.code ?? "", D = w?.message ?? String(w);
|
|
6756
6797
|
if (k === "ERR_JWT_EXPIRED")
|
|
6757
6798
|
throw new c("token_expired", "access_token expirado.", 401, void 0, "expired");
|
|
6758
6799
|
if (k === "ERR_JWT_CLAIM_VALIDATION_FAILED") {
|
|
6759
|
-
let
|
|
6760
|
-
throw
|
|
6800
|
+
let b = w?.claim;
|
|
6801
|
+
throw b === "aud" ? new c(
|
|
6761
6802
|
"token_invalid_audience",
|
|
6762
6803
|
"access_token emitido para um client OIDC que n\xE3o est\xE1 na lista desta API.",
|
|
6763
6804
|
401,
|
|
6764
6805
|
void 0,
|
|
6765
6806
|
"audience"
|
|
6766
|
-
) :
|
|
6807
|
+
) : b === "iss" ? new c("token_invalid_issuer", "access_token de outro emissor.", 401, void 0, "issuer") : b === "jti" ? z(or, "not_access_token") : z(`Claim obrigat\xF3rio ausente ou inv\xE1lido no access_token (${b ?? "desconhecido"}).`, "claims");
|
|
6767
6808
|
}
|
|
6768
6809
|
throw k === "ERR_JWS_SIGNATURE_VERIFICATION_FAILED" || k === "ERR_JWKS_NO_MATCHING_KEY" || k === "ERR_JOSE_ALG_NOT_ALLOWED" || k === "ERR_JWKS_MULTIPLE_MATCHING_KEYS" ? new c(
|
|
6769
6810
|
"token_invalid_signature",
|
|
@@ -6771,21 +6812,21 @@ async function nr(n, e) {
|
|
|
6771
6812
|
401,
|
|
6772
6813
|
void 0,
|
|
6773
6814
|
"signature"
|
|
6774
|
-
) : k === "ERR_JWKS_TIMEOUT" || k === "ERR_JOSE_GENERIC" && /JSON Web Key Set/i.test(
|
|
6815
|
+
) : k === "ERR_JWKS_TIMEOUT" || k === "ERR_JOSE_GENERIC" && /JSON Web Key Set/i.test(D) || k === "" && w instanceof TypeError ? new c("network_error", `Falha ao obter o JWKS do Core: ${D}`, void 0, void 0, "jwks") : z(`access_token inv\xE1lido: ${D}`, "malformed");
|
|
6775
6816
|
}
|
|
6776
6817
|
let d = a.jti, p = a.scope, l = a.client_id;
|
|
6777
6818
|
if (typeof d != "string" || d.length === 0 || typeof p != "string" || typeof l != "string")
|
|
6778
|
-
throw
|
|
6819
|
+
throw z(or, "not_access_token");
|
|
6779
6820
|
let u = a.aud, f = typeof u == "string" ? u : Array.isArray(u) && u.length === 1 ? u[0] : void 0;
|
|
6780
6821
|
if (typeof f != "string" || f !== l)
|
|
6781
|
-
throw
|
|
6822
|
+
throw z("access_token inconsistente: client_id difere do aud.", "client_id_mismatch");
|
|
6782
6823
|
let m = typeof a.sub == "string" ? a.sub : "", h = m.startsWith("client:");
|
|
6783
6824
|
if (!m || h && e.allowClientCredentials !== true)
|
|
6784
|
-
throw
|
|
6825
|
+
throw z(
|
|
6785
6826
|
"access_token de m\xE1quina (client_credentials) n\xE3o representa um usu\xE1rio final.",
|
|
6786
6827
|
"client_credentials"
|
|
6787
6828
|
);
|
|
6788
|
-
let
|
|
6829
|
+
let _ = p.split(" ").filter(Boolean), I = (e.requiredScopes ?? []).filter((w) => !_.includes(w));
|
|
6789
6830
|
if (I.length > 0)
|
|
6790
6831
|
throw new c(
|
|
6791
6832
|
"insufficient_scope",
|
|
@@ -6798,7 +6839,7 @@ async function nr(n, e) {
|
|
|
6798
6839
|
sub: m,
|
|
6799
6840
|
clientId: l,
|
|
6800
6841
|
audience: f,
|
|
6801
|
-
scopes:
|
|
6842
|
+
scopes: _,
|
|
6802
6843
|
jti: d,
|
|
6803
6844
|
issuedAt: a.iat,
|
|
6804
6845
|
expiresAt: a.exp,
|
|
@@ -6806,7 +6847,7 @@ async function nr(n, e) {
|
|
|
6806
6847
|
claims: a
|
|
6807
6848
|
};
|
|
6808
6849
|
}
|
|
6809
|
-
function
|
|
6850
|
+
function cr(n, e) {
|
|
6810
6851
|
let t = e.toLowerCase(), r = n && typeof n == "object" && "headers" in n && n.headers ? n.headers : n;
|
|
6811
6852
|
if (!r || typeof r != "object") return null;
|
|
6812
6853
|
if (typeof r.get == "function")
|
|
@@ -6816,14 +6857,14 @@ function rr(n, e) {
|
|
|
6816
6857
|
return Array.isArray(i) ? typeof i[0] == "string" ? i[0] : null : typeof i == "string" ? i : null;
|
|
6817
6858
|
return null;
|
|
6818
6859
|
}
|
|
6819
|
-
function
|
|
6820
|
-
let e =
|
|
6860
|
+
function lr(n) {
|
|
6861
|
+
let e = cr(n, "authorization");
|
|
6821
6862
|
if (!e) return null;
|
|
6822
6863
|
let t = /^\s*Bearer\s+(\S+)\s*$/i.exec(e);
|
|
6823
6864
|
return t ? t[1] : null;
|
|
6824
6865
|
}
|
|
6825
|
-
function
|
|
6826
|
-
let t =
|
|
6866
|
+
function dr(n, e) {
|
|
6867
|
+
let t = cr(n, "cookie");
|
|
6827
6868
|
if (!t) return null;
|
|
6828
6869
|
for (let r of t.split(";")) {
|
|
6829
6870
|
let o = r.indexOf("=");
|
|
@@ -6837,13 +6878,13 @@ function ir(n, e) {
|
|
|
6837
6878
|
}
|
|
6838
6879
|
return null;
|
|
6839
6880
|
}
|
|
6840
|
-
async function
|
|
6841
|
-
|
|
6842
|
-
let t =
|
|
6881
|
+
async function ui(n, e) {
|
|
6882
|
+
sr(e?.audience);
|
|
6883
|
+
let t = lr(n);
|
|
6843
6884
|
if (t)
|
|
6844
|
-
return { kind: "access_token", token: await
|
|
6885
|
+
return { kind: "access_token", token: await ar(t, e) };
|
|
6845
6886
|
if (e.cookie) {
|
|
6846
|
-
let r =
|
|
6887
|
+
let r = dr(n, e.cookie.name);
|
|
6847
6888
|
if (r) {
|
|
6848
6889
|
let o = await e.cookie.verify(r);
|
|
6849
6890
|
if (o != null) return { kind: "cookie", session: o };
|
|
@@ -6851,7 +6892,7 @@ async function si(n, e) {
|
|
|
6851
6892
|
}
|
|
6852
6893
|
return null;
|
|
6853
6894
|
}
|
|
6854
|
-
function
|
|
6895
|
+
function pi(n) {
|
|
6855
6896
|
if (n instanceof c) {
|
|
6856
6897
|
if (n.code === "insufficient_scope")
|
|
6857
6898
|
return {
|
|
@@ -6883,7 +6924,7 @@ function ai(n) {
|
|
|
6883
6924
|
}
|
|
6884
6925
|
|
|
6885
6926
|
// src/index.ts
|
|
6886
|
-
|
|
6887
|
-
var
|
|
6927
|
+
ve();
|
|
6928
|
+
var Wa = "3.9.1";
|
|
6888
6929
|
|
|
6889
|
-
export {
|
|
6930
|
+
export { We as DEFAULT_BASE_URL, qe as DEV_FIXTURE_USER, me as MockAi, de as MockAuth, Oe as MockCheckout, ut as MockDb, fe as MockEntitlements, le as MockNotifications, pe as MockSupport, ue as MockUsage, ce as MockWebhooks, ir as NEETRU_OIDC_ISSUER, Qe as NEETRU_SENTINEL_KEY, $ as NeetruAuthRequiredError, v as NeetruDbError, c as NeetruError, Wa as VERSION, pi as accessTokenErrorToHttp, ui as authenticateProductRequest, ne as checkCoreVersionCompat, dt as createAiNamespace, st as createCheckoutNamespace, rr as createNeetruClient, ot as createNeetruDb, lt as createNotificationsNamespace, at as createWebhooksNamespace, J as detectNonServerRuntime, ci as getServerNeetruClient, Xr as increment, Q as isFieldSentinel, en as isIncrementSentinel, Zt as isServerTimestampSentinel, lr as readBearerToken, dr as readCookie, Jr as serverTimestamp, ar as verifyAccessToken, Lo as verifyWebhookRequest, wn as verifyWebhookSignature };
|