@neetru/sdk 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +66 -1
- package/dist/ai.cjs +221 -177
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +221 -177
- package/dist/auth.cjs +1227 -1064
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +1224 -1061
- package/dist/catalog.cjs +164 -97
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +164 -97
- package/dist/checkout.cjs +182 -115
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +181 -114
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +370 -298
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +362 -290
- package/dist/entitlements.cjs +17 -10
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +17 -10
- package/dist/errors.cjs +15 -8
- package/dist/errors.d.cts +24 -3
- package/dist/errors.d.ts +24 -3
- package/dist/errors.mjs +14 -7
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +1409 -1075
- package/dist/index.d.cts +177 -3
- package/dist/index.d.ts +177 -3
- package/dist/index.mjs +1544 -1217
- package/dist/mobile.cjs +400 -181
- package/dist/mobile.d.cts +59 -4
- package/dist/mobile.d.ts +59 -4
- package/dist/mobile.mjs +400 -181
- package/dist/mocks.cjs +9 -2
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs +9 -2
- package/dist/notifications.cjs +197 -130
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +196 -129
- package/dist/react.cjs +303 -282
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +295 -274
- package/dist/support.cjs +299 -229
- package/dist/support.d.cts +8 -4
- package/dist/support.d.ts +8 -4
- package/dist/support.mjs +298 -228
- package/dist/telemetry.cjs +234 -167
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +234 -167
- package/dist/{types-Bx4kTLmk.d.cts → types-D-9bjlM0.d.cts} +48 -1
- package/dist/{types-Dx0IrOSF.d.ts → types-bVztFQTI.d.ts} +48 -1
- package/dist/usage.cjs +183 -116
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +183 -116
- package/dist/webhooks.cjs +215 -148
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +212 -145
- package/package.json +2 -1
package/dist/telemetry.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/errors.ts
|
|
4
|
-
var
|
|
4
|
+
var d = class e extends Error {
|
|
5
5
|
code;
|
|
6
6
|
status;
|
|
7
7
|
requestId;
|
|
@@ -14,183 +14,250 @@ var a = class e extends Error {
|
|
|
14
14
|
* para um `NeetruDbErrorCode` mais específico (recuperável vs não).
|
|
15
15
|
*/
|
|
16
16
|
reason;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
|
|
19
|
+
* chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
|
|
20
|
+
* mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
|
|
21
|
+
* `undefined` em erros que acontecem antes de qualquer requisição.
|
|
22
|
+
*/
|
|
23
|
+
correlationId;
|
|
24
|
+
constructor(t, n, o, i, u, r) {
|
|
25
|
+
super(n), this.name = "NeetruError", this.code = t, this.status = o, this.requestId = i, this.reason = u, this.correlationId = r, Object.setPrototypeOf(this, e.prototype);
|
|
19
26
|
}
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
// src/idempotency.ts
|
|
23
|
-
function
|
|
30
|
+
function I() {
|
|
24
31
|
let e = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
25
32
|
if (e && typeof e.randomUUID == "function")
|
|
26
33
|
return e.randomUUID();
|
|
27
|
-
throw new
|
|
34
|
+
throw new d(
|
|
28
35
|
"runtime_unsupported",
|
|
29
36
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
30
37
|
);
|
|
31
38
|
}
|
|
32
39
|
|
|
40
|
+
// src/correlation.ts
|
|
41
|
+
var A = "x-correlation-id";
|
|
42
|
+
var j = /^[A-Za-z0-9._:\-]+$/;
|
|
43
|
+
function S(e) {
|
|
44
|
+
return typeof e == "string" && e.length > 0 && e.length <= 128 && j.test(e);
|
|
45
|
+
}
|
|
46
|
+
function H() {
|
|
47
|
+
let e = globalThis.crypto;
|
|
48
|
+
try {
|
|
49
|
+
if (e && typeof e.randomUUID == "function") return e.randomUUID();
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
let t = new Uint8Array(16), n = false;
|
|
53
|
+
try {
|
|
54
|
+
e && typeof e.getRandomValues == "function" && (e.getRandomValues(t), n = !0);
|
|
55
|
+
} catch {
|
|
56
|
+
n = false;
|
|
57
|
+
}
|
|
58
|
+
if (!n)
|
|
59
|
+
for (let i = 0; i < t.length; i++) t[i] = Math.floor(Math.random() * 256);
|
|
60
|
+
t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
|
|
61
|
+
let o = Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("");
|
|
62
|
+
return `${o.slice(0, 8)}-${o.slice(8, 12)}-${o.slice(12, 16)}-${o.slice(16, 20)}-${o.slice(20)}`;
|
|
63
|
+
}
|
|
64
|
+
function N(e, t) {
|
|
65
|
+
let n, o = {};
|
|
66
|
+
for (let [u, r] of Object.entries(e)) {
|
|
67
|
+
if (u.toLowerCase() === A) {
|
|
68
|
+
S(r) && (n = r);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
o[u] = r;
|
|
72
|
+
}
|
|
73
|
+
let i = n ?? (S(t) ? t : void 0) ?? H();
|
|
74
|
+
return o[A] = i, { headers: o, correlationId: i };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/server-only-key.ts
|
|
78
|
+
function x() {
|
|
79
|
+
try {
|
|
80
|
+
let e = globalThis.navigator;
|
|
81
|
+
if (e && e.product === "ReactNative") return "react-native";
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
let e = globalThis;
|
|
86
|
+
if (typeof e.window < "u" && typeof e.document < "u") return "browser";
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
33
92
|
// src/http.ts
|
|
34
|
-
var
|
|
93
|
+
var F = {
|
|
35
94
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
36
95
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
37
96
|
3: "2026.05.1"
|
|
38
97
|
};
|
|
39
|
-
function
|
|
98
|
+
function R(e) {
|
|
40
99
|
return e.split("+")[0] ?? e;
|
|
41
100
|
}
|
|
42
|
-
function
|
|
43
|
-
let n =
|
|
44
|
-
for (let
|
|
45
|
-
let
|
|
46
|
-
if (
|
|
101
|
+
function V(e, t) {
|
|
102
|
+
let n = R(e).split(".").map(Number), o = R(t).split(".").map(Number), i = Math.max(n.length, o.length);
|
|
103
|
+
for (let u = 0; u < i; u++) {
|
|
104
|
+
let r = n[u] ?? 0, a = o[u] ?? 0;
|
|
105
|
+
if (r !== a) return r - a;
|
|
47
106
|
}
|
|
48
107
|
return 0;
|
|
49
108
|
}
|
|
50
|
-
function
|
|
109
|
+
function L() {
|
|
51
110
|
try {
|
|
52
|
-
return "3.
|
|
111
|
+
return "3.8.0";
|
|
53
112
|
} catch {
|
|
54
113
|
return;
|
|
55
114
|
}
|
|
56
115
|
}
|
|
57
|
-
function
|
|
58
|
-
let e =
|
|
116
|
+
function B() {
|
|
117
|
+
let e = L();
|
|
59
118
|
return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
|
|
60
119
|
}
|
|
61
|
-
var
|
|
62
|
-
function
|
|
120
|
+
var D = /* @__PURE__ */ new Set();
|
|
121
|
+
function z(e) {
|
|
63
122
|
if (!e) return;
|
|
64
|
-
let
|
|
123
|
+
let t = B(), n = F[t];
|
|
65
124
|
if (!n) return;
|
|
66
|
-
let
|
|
67
|
-
if (
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${e}" \xE9 anterior ao m\xEDnimo recomendado "${n}" para SDK major ${
|
|
125
|
+
let o = R(e);
|
|
126
|
+
if (V(o, n) < 0) {
|
|
127
|
+
let i = `${t}:${o}`;
|
|
128
|
+
D.has(i) || (D.add(i), console.warn(
|
|
129
|
+
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${e}" \xE9 anterior ao m\xEDnimo recomendado "${n}" para SDK major ${t}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
71
130
|
));
|
|
72
131
|
}
|
|
73
132
|
}
|
|
74
|
-
|
|
133
|
+
function G() {
|
|
134
|
+
let e = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
135
|
+
return x() ? "Esta opera\xE7\xE3o exige a credencial nrt_ do produto, que \xE9 S\xD3 DE SERVIDOR. No navegador/app, chame a API do seu produto (ex.: https://<produto>.neetru.com/api/v1) com o token do usu\xE1rio \u2014 o backend do produto faz esta chamada com o SDK e a chave. (" + e + ")" : e;
|
|
136
|
+
}
|
|
137
|
+
var X = 2, Y = 0, J = /* @__PURE__ */ new Set(["GET", "HEAD"]), W = /* @__PURE__ */ new Set([
|
|
75
138
|
"rate_limited",
|
|
76
139
|
"server_error",
|
|
77
140
|
"network_error"
|
|
78
141
|
]);
|
|
79
|
-
function
|
|
80
|
-
let
|
|
81
|
-
return Math.max(50, Math.round(
|
|
142
|
+
function C(e) {
|
|
143
|
+
let t = 200 * Math.pow(4, e), n = t * 0.2 * (Math.random() * 2 - 1);
|
|
144
|
+
return Math.max(50, Math.round(t + n));
|
|
82
145
|
}
|
|
83
|
-
var
|
|
84
|
-
function
|
|
146
|
+
var O = 6e4;
|
|
147
|
+
function Q(e) {
|
|
85
148
|
if (!e) return null;
|
|
86
|
-
let
|
|
87
|
-
if (Number.isFinite(
|
|
149
|
+
let t = Number(e);
|
|
150
|
+
if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3), O);
|
|
88
151
|
let n = Date.parse(e);
|
|
89
152
|
if (Number.isFinite(n)) {
|
|
90
|
-
let
|
|
91
|
-
if (
|
|
153
|
+
let o = n - Date.now();
|
|
154
|
+
if (o > 0) return Math.min(o, O);
|
|
92
155
|
}
|
|
93
156
|
return null;
|
|
94
157
|
}
|
|
95
158
|
function q(e) {
|
|
96
|
-
return new Promise((
|
|
159
|
+
return new Promise((t) => setTimeout(t, e));
|
|
97
160
|
}
|
|
98
|
-
function
|
|
161
|
+
function Z(e) {
|
|
99
162
|
return e === 401 ? "unauthorized" : e === 403 ? "forbidden" : e === 404 ? "not_found" : e === 409 ? "conflict" : e === 410 ? "gone" : e === 422 || e === 400 ? "validation_failed" : e === 429 ? "rate_limited" : e >= 500 ? "server_error" : "unknown";
|
|
100
163
|
}
|
|
101
|
-
function
|
|
102
|
-
let
|
|
164
|
+
function ee(e, t, n) {
|
|
165
|
+
let o = e.replace(/\/+$/, ""), i = t.startsWith("/") ? t : `/${t}`, u = new URL(`${o}${i}`);
|
|
103
166
|
if (n)
|
|
104
|
-
for (let [
|
|
105
|
-
|
|
106
|
-
return
|
|
167
|
+
for (let [r, a] of Object.entries(n))
|
|
168
|
+
a !== void 0 && u.searchParams.set(r, String(a));
|
|
169
|
+
return u.toString();
|
|
107
170
|
}
|
|
108
|
-
async function
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
171
|
+
async function K(e) {
|
|
172
|
+
let t = await e.text();
|
|
173
|
+
if (t)
|
|
111
174
|
try {
|
|
112
|
-
return JSON.parse(
|
|
175
|
+
return JSON.parse(t);
|
|
113
176
|
} catch {
|
|
114
177
|
return;
|
|
115
178
|
}
|
|
116
179
|
}
|
|
117
|
-
async function
|
|
118
|
-
let n =
|
|
119
|
-
accept: "application/json",
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
180
|
+
async function v(e, t) {
|
|
181
|
+
let n = t.method ?? "GET", o = ee(e.baseUrl, t.path, t.query), i = J.has(n) ? X : Y, u = t.retries ?? i, { headers: r, correlationId: a } = N(
|
|
182
|
+
{ accept: "application/json", ...t.headers },
|
|
183
|
+
t.correlationId
|
|
184
|
+
), l = L();
|
|
185
|
+
if (l && (r["x-neetru-sdk-version"] = l), t.requireAuth) {
|
|
123
186
|
if (!e.apiKey)
|
|
124
|
-
throw new
|
|
125
|
-
|
|
126
|
-
"This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
127
|
-
);
|
|
128
|
-
t.authorization = `Bearer ${e.apiKey}`;
|
|
187
|
+
throw new d("missing_api_key", G());
|
|
188
|
+
r.authorization = `Bearer ${e.apiKey}`;
|
|
129
189
|
}
|
|
130
|
-
if (
|
|
131
|
-
let
|
|
132
|
-
|
|
190
|
+
if (t.idempotencyKey) {
|
|
191
|
+
let g = typeof t.idempotencyKey == "string" ? t.idempotencyKey : I();
|
|
192
|
+
r["idempotency-key"] = g;
|
|
133
193
|
}
|
|
134
|
-
let
|
|
135
|
-
|
|
136
|
-
let
|
|
137
|
-
for (let
|
|
138
|
-
if (
|
|
139
|
-
throw
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
194
|
+
let c = t.body !== void 0 && n !== "GET" && n !== "DELETE" ? JSON.stringify(t.body) : void 0;
|
|
195
|
+
c !== void 0 && (r["content-type"] = "application/json");
|
|
196
|
+
let f = null, m = t.deadlineMs != null ? Date.now() + t.deadlineMs : null;
|
|
197
|
+
for (let g = 0; g <= u; g++) {
|
|
198
|
+
if (m != null && Date.now() >= m)
|
|
199
|
+
throw f ?? new d(
|
|
200
|
+
"network_error",
|
|
201
|
+
"Deadline excedido antes de completar a request",
|
|
202
|
+
void 0,
|
|
203
|
+
void 0,
|
|
204
|
+
void 0,
|
|
205
|
+
a
|
|
206
|
+
);
|
|
207
|
+
let b = { method: n, headers: r };
|
|
208
|
+
c !== void 0 && (b.body = c);
|
|
209
|
+
let U = m != null ? Math.max(1, Math.min(3e4, m - Date.now())) : 3e4;
|
|
210
|
+
b.signal = AbortSignal.timeout(U);
|
|
144
211
|
let p;
|
|
145
212
|
try {
|
|
146
|
-
p = await e.fetch(
|
|
147
|
-
} catch (
|
|
148
|
-
let
|
|
149
|
-
if (
|
|
150
|
-
let k =
|
|
151
|
-
if (
|
|
213
|
+
p = await e.fetch(o, b);
|
|
214
|
+
} catch (s) {
|
|
215
|
+
let _ = s instanceof DOMException && s.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${s instanceof Error ? s.message : "fetch failed"}`;
|
|
216
|
+
if (f = new d("network_error", _, void 0, void 0, void 0, a), g < u) {
|
|
217
|
+
let k = C(g);
|
|
218
|
+
if (m == null || Date.now() + k < m) {
|
|
152
219
|
await q(k);
|
|
153
220
|
continue;
|
|
154
221
|
}
|
|
155
222
|
}
|
|
156
|
-
throw
|
|
223
|
+
throw f;
|
|
157
224
|
}
|
|
158
|
-
let
|
|
225
|
+
let $ = p.headers.get("x-request-id") ?? p.headers.get("x-correlation-id") ?? void 0;
|
|
159
226
|
if (p.ok) {
|
|
160
|
-
let
|
|
161
|
-
return
|
|
227
|
+
let s = p.headers.get("x-neetru-version");
|
|
228
|
+
return s && z(s), await K(p);
|
|
162
229
|
}
|
|
163
|
-
let
|
|
164
|
-
if (
|
|
165
|
-
let
|
|
166
|
-
typeof
|
|
230
|
+
let y = await K(p), w = Z(p.status), h = `HTTP ${p.status}`, E;
|
|
231
|
+
if (y && typeof y == "object") {
|
|
232
|
+
let s = y.error;
|
|
233
|
+
typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (w = s.code), typeof s.message == "string" && (h = s.message), typeof s.reason == "string" && (E = s.reason)) : (typeof y.code == "string" && (w = y.code), typeof y.message == "string" && (h = y.message)), typeof y.reason == "string" && (E = y.reason);
|
|
167
234
|
}
|
|
168
235
|
if (p.status === 410) {
|
|
169
|
-
let
|
|
170
|
-
h === `HTTP ${p.status}` && (h = `Endpoint ${
|
|
236
|
+
let s = p.headers.get("x-neetru-replacement");
|
|
237
|
+
h === `HTTP ${p.status}` && (h = `Endpoint ${t.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), s && !h.includes(s) && (h += ` Substituto: ${s}.`);
|
|
171
238
|
}
|
|
172
|
-
let
|
|
173
|
-
if (
|
|
174
|
-
let
|
|
175
|
-
if (
|
|
176
|
-
await q(
|
|
239
|
+
let T = new d(w, h, p.status, $, E, a);
|
|
240
|
+
if (f = T, W.has(w) && g < u) {
|
|
241
|
+
let _ = Q(p.headers.get("retry-after")) ?? C(g);
|
|
242
|
+
if (m == null || Date.now() + _ < m) {
|
|
243
|
+
await q(_);
|
|
177
244
|
continue;
|
|
178
245
|
}
|
|
179
246
|
}
|
|
180
|
-
throw
|
|
247
|
+
throw T;
|
|
181
248
|
}
|
|
182
|
-
throw
|
|
249
|
+
throw f ?? new d("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
|
|
183
250
|
}
|
|
184
251
|
|
|
185
252
|
// src/telemetry.ts
|
|
186
|
-
var
|
|
187
|
-
function
|
|
253
|
+
var P = ["debug", "info", "warn", "error", "fatal"];
|
|
254
|
+
function te() {
|
|
188
255
|
return typeof globalThis < "u" && typeof globalThis.window < "u";
|
|
189
256
|
}
|
|
190
|
-
function
|
|
191
|
-
return
|
|
257
|
+
function M() {
|
|
258
|
+
return te() ? { path: "/api/sdk/v1/telemetry/event/public", requireAuth: false } : { path: "/api/sdk/v1/telemetry/event", requireAuth: true };
|
|
192
259
|
}
|
|
193
|
-
function
|
|
260
|
+
function re(e) {
|
|
194
261
|
switch (e) {
|
|
195
262
|
case "debug":
|
|
196
263
|
return console.debug.bind(console);
|
|
@@ -206,41 +273,41 @@ function J(e) {
|
|
|
206
273
|
return console.log.bind(console);
|
|
207
274
|
}
|
|
208
275
|
}
|
|
209
|
-
var
|
|
210
|
-
function
|
|
211
|
-
let
|
|
212
|
-
async function
|
|
213
|
-
if (
|
|
214
|
-
let
|
|
215
|
-
|
|
276
|
+
var ne = 500, oe = 50;
|
|
277
|
+
function _e(e) {
|
|
278
|
+
let t = [], n = null, o = null;
|
|
279
|
+
async function i() {
|
|
280
|
+
if (t.length === 0) return;
|
|
281
|
+
let r = t.splice(0, t.length), a = Promise.allSettled(
|
|
282
|
+
r.map(async (l) => {
|
|
216
283
|
try {
|
|
217
|
-
let
|
|
218
|
-
|
|
219
|
-
let
|
|
220
|
-
await
|
|
284
|
+
let c = { name: l.name }, f = l.productSlug ?? e.productId;
|
|
285
|
+
f && (c.productSlug = f), l.properties && typeof l.properties == "object" && (c.properties = l.properties), l.timestamp && (c.timestamp = l.timestamp);
|
|
286
|
+
let m = M();
|
|
287
|
+
await v(e, {
|
|
221
288
|
method: "POST",
|
|
222
|
-
path:
|
|
223
|
-
body:
|
|
224
|
-
requireAuth:
|
|
289
|
+
path: m.path,
|
|
290
|
+
body: c,
|
|
291
|
+
requireAuth: m.requireAuth,
|
|
225
292
|
retries: 1,
|
|
226
293
|
// caça-bruxas: retry sem Idempotency-Key duplicava o evento se o
|
|
227
294
|
// servidor já tinha persistido antes da falha transiente. Mesmo
|
|
228
295
|
// padrão do usage.report (key estável por chamada, reusada no retry).
|
|
229
296
|
idempotencyKey: !0
|
|
230
297
|
});
|
|
231
|
-
} catch (
|
|
232
|
-
typeof console < "u" && console.warn("[neetru-sdk] telemetry.track flush failed for event", l.name,
|
|
298
|
+
} catch (c) {
|
|
299
|
+
typeof console < "u" && console.warn("[neetru-sdk] telemetry.track flush failed for event", l.name, c);
|
|
233
300
|
}
|
|
234
301
|
})
|
|
235
302
|
);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}), await
|
|
303
|
+
o = a.then(() => {
|
|
304
|
+
o = null;
|
|
305
|
+
}), await a, n = null, t.length > 0 && u();
|
|
239
306
|
}
|
|
240
|
-
function
|
|
307
|
+
function u() {
|
|
241
308
|
n || (n = setTimeout(() => {
|
|
242
|
-
|
|
243
|
-
},
|
|
309
|
+
i();
|
|
310
|
+
}, ne));
|
|
244
311
|
}
|
|
245
312
|
return {
|
|
246
313
|
/**
|
|
@@ -255,24 +322,24 @@ function se(e) {
|
|
|
255
322
|
* });
|
|
256
323
|
* ```
|
|
257
324
|
*/
|
|
258
|
-
async event(
|
|
259
|
-
if (!
|
|
260
|
-
throw new
|
|
261
|
-
if (typeof
|
|
262
|
-
throw new
|
|
263
|
-
if (
|
|
264
|
-
throw new
|
|
265
|
-
let
|
|
266
|
-
l && (
|
|
267
|
-
let
|
|
325
|
+
async event(r) {
|
|
326
|
+
if (!r || typeof r != "object")
|
|
327
|
+
throw new d("validation_failed", "event input is required");
|
|
328
|
+
if (typeof r.name != "string" || r.name.length === 0)
|
|
329
|
+
throw new d("validation_failed", "event.name is required");
|
|
330
|
+
if (r.name.length > 128)
|
|
331
|
+
throw new d("validation_failed", "event.name max 128 chars");
|
|
332
|
+
let a = { name: r.name }, l = r.productSlug ?? e.productId;
|
|
333
|
+
l && (a.productSlug = l), r.properties && typeof r.properties == "object" && (a.properties = r.properties), r.timestamp && (a.timestamp = r.timestamp);
|
|
334
|
+
let c = M(), f = await v(e, {
|
|
268
335
|
method: "POST",
|
|
269
|
-
path:
|
|
270
|
-
body:
|
|
271
|
-
requireAuth:
|
|
336
|
+
path: c.path,
|
|
337
|
+
body: a,
|
|
338
|
+
requireAuth: c.requireAuth
|
|
272
339
|
});
|
|
273
|
-
if (!
|
|
274
|
-
throw new
|
|
275
|
-
return { ok: true, eventId:
|
|
340
|
+
if (!f || f.ok !== true || typeof f.eventId != "string")
|
|
341
|
+
throw new d("invalid_response", "Telemetry response missing eventId");
|
|
342
|
+
return { ok: true, eventId: f.eventId };
|
|
276
343
|
},
|
|
277
344
|
/**
|
|
278
345
|
* Fire-and-forget: enqueue + flush 500ms debounce. Não retorna `eventId`
|
|
@@ -284,15 +351,15 @@ function se(e) {
|
|
|
284
351
|
* // segue execução; flush async em background
|
|
285
352
|
* ```
|
|
286
353
|
*/
|
|
287
|
-
track(
|
|
288
|
-
!
|
|
354
|
+
track(r) {
|
|
355
|
+
!r || typeof r != "object" || typeof r.name != "string" || r.name.length === 0 || r.name.length > 128 || (t.push(r), t.length >= oe ? (n && (clearTimeout(n), n = null), i()) : u());
|
|
289
356
|
},
|
|
290
357
|
/**
|
|
291
358
|
* Força flush imediato da queue de `track()`. Resolva antes de
|
|
292
359
|
* page unload / SSR boundary pra não perder eventos.
|
|
293
360
|
*/
|
|
294
361
|
async flush() {
|
|
295
|
-
n && (clearTimeout(n), n = null),
|
|
362
|
+
n && (clearTimeout(n), n = null), o && await o, await i();
|
|
296
363
|
},
|
|
297
364
|
/**
|
|
298
365
|
* Registra um log estruturado per-product (Sprint 6).
|
|
@@ -309,49 +376,49 @@ function se(e) {
|
|
|
309
376
|
* });
|
|
310
377
|
* ```
|
|
311
378
|
*/
|
|
312
|
-
async log(
|
|
313
|
-
if (!
|
|
314
|
-
throw new
|
|
315
|
-
if (!
|
|
316
|
-
throw new
|
|
317
|
-
if (typeof
|
|
318
|
-
throw new
|
|
319
|
-
if (
|
|
320
|
-
throw new
|
|
379
|
+
async log(r) {
|
|
380
|
+
if (!r || typeof r != "object")
|
|
381
|
+
throw new d("validation_failed", "log input is required");
|
|
382
|
+
if (!P.includes(r.level))
|
|
383
|
+
throw new d("validation_failed", `level must be one of ${P.join(", ")}`);
|
|
384
|
+
if (typeof r.message != "string" || r.message.length === 0)
|
|
385
|
+
throw new d("validation_failed", "message is required");
|
|
386
|
+
if (r.message.length > 4e3)
|
|
387
|
+
throw new d("validation_failed", "message max 4000 chars");
|
|
321
388
|
if (e.env === "dev")
|
|
322
|
-
return
|
|
323
|
-
let
|
|
324
|
-
level:
|
|
325
|
-
message:
|
|
389
|
+
return re(r.level)(`[neetru-sdk] ${r.level}: ${r.message}`, r.metadata ?? {}), { ok: true, mode: "mock" };
|
|
390
|
+
let a = {
|
|
391
|
+
level: r.level,
|
|
392
|
+
message: r.message
|
|
326
393
|
};
|
|
327
|
-
|
|
328
|
-
let l =
|
|
329
|
-
l && (
|
|
330
|
-
let
|
|
331
|
-
if (!
|
|
394
|
+
r.metadata && (a.metadata = r.metadata);
|
|
395
|
+
let l = r.productSlug ?? e.productId;
|
|
396
|
+
l && (a.productSlug = l);
|
|
397
|
+
let c = r.correlationId;
|
|
398
|
+
if (!c)
|
|
332
399
|
try {
|
|
333
|
-
let
|
|
334
|
-
typeof
|
|
400
|
+
let g = globalThis.NEETRU_CORRELATION_ID;
|
|
401
|
+
typeof g == "string" && g.length > 0 && (c = g);
|
|
335
402
|
} catch {
|
|
336
403
|
}
|
|
337
|
-
let
|
|
338
|
-
|
|
339
|
-
let
|
|
404
|
+
let f = {};
|
|
405
|
+
c && (f["x-correlation-id"] = c);
|
|
406
|
+
let m = await v(e, {
|
|
340
407
|
method: "POST",
|
|
341
408
|
path: "/api/sdk/v1/telemetry/log",
|
|
342
|
-
body:
|
|
409
|
+
body: a,
|
|
343
410
|
requireAuth: true,
|
|
344
|
-
headers:
|
|
411
|
+
headers: f
|
|
345
412
|
});
|
|
346
|
-
if (!
|
|
347
|
-
throw new
|
|
413
|
+
if (!m || m.ok !== true)
|
|
414
|
+
throw new d("invalid_response", "Telemetry log response missing ok");
|
|
348
415
|
return {
|
|
349
416
|
ok: true,
|
|
350
|
-
logId: typeof
|
|
417
|
+
logId: typeof m.logId == "string" ? m.logId : void 0,
|
|
351
418
|
mode: "http"
|
|
352
419
|
};
|
|
353
420
|
}
|
|
354
421
|
};
|
|
355
422
|
}
|
|
356
423
|
|
|
357
|
-
exports.createTelemetryNamespace =
|
|
424
|
+
exports.createTelemetryNamespace = _e;
|
package/dist/telemetry.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ResolvedConfig, at as TelemetryEventInput, as as TelemetryEventAck, av as TelemetryLogInput, au as TelemetryLogAck } from './types-D-9bjlM0.cjs';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.cjs';
|
|
4
4
|
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ResolvedConfig, at as TelemetryEventInput, as as TelemetryEventAck, av as TelemetryLogInput, au as TelemetryLogAck } from './types-bVztFQTI.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
|
4
4
|
|