@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/notifications.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
|
-
var
|
|
2
|
+
var i = class t extends Error {
|
|
3
3
|
code;
|
|
4
4
|
status;
|
|
5
5
|
requestId;
|
|
@@ -12,98 +12,161 @@ var n = class t extends Error {
|
|
|
12
12
|
* para um `NeetruDbErrorCode` mais específico (recuperável vs não).
|
|
13
13
|
*/
|
|
14
14
|
reason;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
|
|
17
|
+
* chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
|
|
18
|
+
* mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
|
|
19
|
+
* `undefined` em erros que acontecem antes de qualquer requisição.
|
|
20
|
+
*/
|
|
21
|
+
correlationId;
|
|
22
|
+
constructor(e, r, n, o, s, d) {
|
|
23
|
+
super(r), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = o, this.reason = s, this.correlationId = d, Object.setPrototypeOf(this, t.prototype);
|
|
17
24
|
}
|
|
18
25
|
};
|
|
19
26
|
|
|
20
27
|
// src/idempotency.ts
|
|
21
|
-
function
|
|
28
|
+
function x() {
|
|
22
29
|
let t = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
23
30
|
if (t && typeof t.randomUUID == "function")
|
|
24
31
|
return t.randomUUID();
|
|
25
|
-
throw new
|
|
32
|
+
throw new i(
|
|
26
33
|
"runtime_unsupported",
|
|
27
34
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
28
35
|
);
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
// src/correlation.ts
|
|
39
|
+
var D = "x-correlation-id";
|
|
40
|
+
var B = /^[A-Za-z0-9._:\-]+$/;
|
|
41
|
+
function T(t) {
|
|
42
|
+
return typeof t == "string" && t.length > 0 && t.length <= 128 && B.test(t);
|
|
43
|
+
}
|
|
44
|
+
function G() {
|
|
45
|
+
let t = globalThis.crypto;
|
|
46
|
+
try {
|
|
47
|
+
if (t && typeof t.randomUUID == "function") return t.randomUUID();
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
let e = new Uint8Array(16), r = false;
|
|
51
|
+
try {
|
|
52
|
+
t && typeof t.getRandomValues == "function" && (t.getRandomValues(e), r = !0);
|
|
53
|
+
} catch {
|
|
54
|
+
r = false;
|
|
55
|
+
}
|
|
56
|
+
if (!r)
|
|
57
|
+
for (let o = 0; o < e.length; o++) e[o] = Math.floor(Math.random() * 256);
|
|
58
|
+
e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
|
|
59
|
+
let n = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
60
|
+
return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
|
|
61
|
+
}
|
|
62
|
+
function O(t, e) {
|
|
63
|
+
let r, n = {};
|
|
64
|
+
for (let [s, d] of Object.entries(t)) {
|
|
65
|
+
if (s.toLowerCase() === D) {
|
|
66
|
+
T(d) && (r = d);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
n[s] = d;
|
|
70
|
+
}
|
|
71
|
+
let o = r ?? (T(e) ? e : void 0) ?? G();
|
|
72
|
+
return n[D] = o, { headers: n, correlationId: o };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/server-only-key.ts
|
|
76
|
+
function P() {
|
|
77
|
+
try {
|
|
78
|
+
let t = globalThis.navigator;
|
|
79
|
+
if (t && t.product === "ReactNative") return "react-native";
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
let t = globalThis;
|
|
84
|
+
if (typeof t.window < "u" && typeof t.document < "u") return "browser";
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
31
90
|
// src/http.ts
|
|
32
|
-
var
|
|
91
|
+
var X = {
|
|
33
92
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
34
93
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
35
94
|
3: "2026.05.1"
|
|
36
95
|
};
|
|
37
|
-
function
|
|
96
|
+
function k(t) {
|
|
38
97
|
return t.split("+")[0] ?? t;
|
|
39
98
|
}
|
|
40
|
-
function
|
|
41
|
-
let r =
|
|
99
|
+
function Y(t, e) {
|
|
100
|
+
let r = k(t).split(".").map(Number), n = k(e).split(".").map(Number), o = Math.max(r.length, n.length);
|
|
42
101
|
for (let s = 0; s < o; s++) {
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
102
|
+
let d = r[s] ?? 0, u = n[s] ?? 0;
|
|
103
|
+
if (d !== u) return d - u;
|
|
45
104
|
}
|
|
46
105
|
return 0;
|
|
47
106
|
}
|
|
48
|
-
function
|
|
107
|
+
function q() {
|
|
49
108
|
try {
|
|
50
|
-
return "3.
|
|
109
|
+
return "3.8.0";
|
|
51
110
|
} catch {
|
|
52
111
|
return;
|
|
53
112
|
}
|
|
54
113
|
}
|
|
55
|
-
function
|
|
56
|
-
let t =
|
|
114
|
+
function J() {
|
|
115
|
+
let t = q();
|
|
57
116
|
return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
|
|
58
117
|
}
|
|
59
|
-
var
|
|
60
|
-
function
|
|
118
|
+
var C = /* @__PURE__ */ new Set();
|
|
119
|
+
function W(t) {
|
|
61
120
|
if (!t) return;
|
|
62
|
-
let e =
|
|
121
|
+
let e = J(), r = X[e];
|
|
63
122
|
if (!r) return;
|
|
64
|
-
let
|
|
65
|
-
if (
|
|
66
|
-
let o = `${e}:${
|
|
67
|
-
|
|
123
|
+
let n = k(t);
|
|
124
|
+
if (Y(n, r) < 0) {
|
|
125
|
+
let o = `${e}:${n}`;
|
|
126
|
+
C.has(o) || (C.add(o), console.warn(
|
|
68
127
|
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${t}" \xE9 anterior ao m\xEDnimo recomendado "${r}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
69
128
|
));
|
|
70
129
|
}
|
|
71
130
|
}
|
|
72
|
-
|
|
131
|
+
function Z() {
|
|
132
|
+
let t = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
133
|
+
return P() ? "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. (" + t + ")" : t;
|
|
134
|
+
}
|
|
135
|
+
var Q = 2, ee = 0, te = /* @__PURE__ */ new Set(["GET", "HEAD"]), re = /* @__PURE__ */ new Set([
|
|
73
136
|
"rate_limited",
|
|
74
137
|
"server_error",
|
|
75
138
|
"network_error"
|
|
76
139
|
]);
|
|
77
|
-
function
|
|
140
|
+
function U(t) {
|
|
78
141
|
let e = 200 * Math.pow(4, t), r = e * 0.2 * (Math.random() * 2 - 1);
|
|
79
142
|
return Math.max(50, Math.round(e + r));
|
|
80
143
|
}
|
|
81
|
-
var
|
|
82
|
-
function
|
|
144
|
+
var M = 6e4;
|
|
145
|
+
function ne(t) {
|
|
83
146
|
if (!t) return null;
|
|
84
147
|
let e = Number(t);
|
|
85
|
-
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3),
|
|
148
|
+
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), M);
|
|
86
149
|
let r = Date.parse(t);
|
|
87
150
|
if (Number.isFinite(r)) {
|
|
88
|
-
let
|
|
89
|
-
if (
|
|
151
|
+
let n = r - Date.now();
|
|
152
|
+
if (n > 0) return Math.min(n, M);
|
|
90
153
|
}
|
|
91
154
|
return null;
|
|
92
155
|
}
|
|
93
|
-
function
|
|
156
|
+
function $(t) {
|
|
94
157
|
return new Promise((e) => setTimeout(e, t));
|
|
95
158
|
}
|
|
96
|
-
function
|
|
159
|
+
function oe(t) {
|
|
97
160
|
return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 404 ? "not_found" : t === 409 ? "conflict" : t === 410 ? "gone" : t === 422 || t === 400 ? "validation_failed" : t === 429 ? "rate_limited" : t >= 500 ? "server_error" : "unknown";
|
|
98
161
|
}
|
|
99
|
-
function
|
|
100
|
-
let
|
|
162
|
+
function ie(t, e, r) {
|
|
163
|
+
let n = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, s = new URL(`${n}${o}`);
|
|
101
164
|
if (r)
|
|
102
|
-
for (let [
|
|
103
|
-
|
|
165
|
+
for (let [d, u] of Object.entries(r))
|
|
166
|
+
u !== void 0 && s.searchParams.set(d, String(u));
|
|
104
167
|
return s.toString();
|
|
105
168
|
}
|
|
106
|
-
async function
|
|
169
|
+
async function K(t) {
|
|
107
170
|
let e = await t.text();
|
|
108
171
|
if (e)
|
|
109
172
|
try {
|
|
@@ -113,97 +176,101 @@ async function O(t) {
|
|
|
113
176
|
}
|
|
114
177
|
}
|
|
115
178
|
async function h(t, e) {
|
|
116
|
-
let r = e.method ?? "GET",
|
|
117
|
-
accept: "application/json",
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
179
|
+
let r = e.method ?? "GET", n = ie(t.baseUrl, e.path, e.query), o = te.has(r) ? Q : ee, s = e.retries ?? o, { headers: d, correlationId: u } = O(
|
|
180
|
+
{ accept: "application/json", ...e.headers },
|
|
181
|
+
e.correlationId
|
|
182
|
+
), E = q();
|
|
183
|
+
if (E && (d["x-neetru-sdk-version"] = E), e.requireAuth) {
|
|
121
184
|
if (!t.apiKey)
|
|
122
|
-
throw new
|
|
123
|
-
|
|
124
|
-
"This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
125
|
-
);
|
|
126
|
-
c.authorization = `Bearer ${t.apiKey}`;
|
|
185
|
+
throw new i("missing_api_key", Z());
|
|
186
|
+
d.authorization = `Bearer ${t.apiKey}`;
|
|
127
187
|
}
|
|
128
188
|
if (e.idempotencyKey) {
|
|
129
|
-
let
|
|
130
|
-
|
|
189
|
+
let p = typeof e.idempotencyKey == "string" ? e.idempotencyKey : x();
|
|
190
|
+
d["idempotency-key"] = p;
|
|
131
191
|
}
|
|
132
|
-
let
|
|
133
|
-
|
|
192
|
+
let b = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
193
|
+
b !== void 0 && (d["content-type"] = "application/json");
|
|
134
194
|
let g = null, l = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
|
|
135
|
-
for (let
|
|
195
|
+
for (let p = 0; p <= s; p++) {
|
|
136
196
|
if (l != null && Date.now() >= l)
|
|
137
|
-
throw g ?? new
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
197
|
+
throw g ?? new i(
|
|
198
|
+
"network_error",
|
|
199
|
+
"Deadline excedido antes de completar a request",
|
|
200
|
+
void 0,
|
|
201
|
+
void 0,
|
|
202
|
+
void 0,
|
|
203
|
+
u
|
|
204
|
+
);
|
|
205
|
+
let v = { method: r, headers: d };
|
|
206
|
+
b !== void 0 && (v.body = b);
|
|
207
|
+
let z = l != null ? Math.max(1, Math.min(3e4, l - Date.now())) : 3e4;
|
|
208
|
+
v.signal = AbortSignal.timeout(z);
|
|
209
|
+
let c;
|
|
143
210
|
try {
|
|
144
|
-
|
|
211
|
+
c = await t.fetch(n, v);
|
|
145
212
|
} catch (a) {
|
|
146
213
|
let y = a instanceof DOMException && a.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${a instanceof Error ? a.message : "fetch failed"}`;
|
|
147
|
-
if (g = new
|
|
148
|
-
let
|
|
149
|
-
if (l == null || Date.now() +
|
|
150
|
-
await
|
|
214
|
+
if (g = new i("network_error", y, void 0, void 0, void 0, u), p < s) {
|
|
215
|
+
let A = U(p);
|
|
216
|
+
if (l == null || Date.now() + A < l) {
|
|
217
|
+
await $(A);
|
|
151
218
|
continue;
|
|
152
219
|
}
|
|
153
220
|
}
|
|
154
221
|
throw g;
|
|
155
222
|
}
|
|
156
|
-
let
|
|
157
|
-
if (
|
|
158
|
-
let a =
|
|
159
|
-
return a &&
|
|
223
|
+
let F = c.headers.get("x-request-id") ?? c.headers.get("x-correlation-id") ?? void 0;
|
|
224
|
+
if (c.ok) {
|
|
225
|
+
let a = c.headers.get("x-neetru-version");
|
|
226
|
+
return a && W(a), await K(c);
|
|
160
227
|
}
|
|
161
|
-
let
|
|
162
|
-
if (
|
|
163
|
-
let a =
|
|
164
|
-
typeof a == "string" ?
|
|
228
|
+
let f = await K(c), _ = oe(c.status), m = `HTTP ${c.status}`, I;
|
|
229
|
+
if (f && typeof f == "object") {
|
|
230
|
+
let a = f.error;
|
|
231
|
+
typeof a == "string" ? m = a : a && typeof a == "object" ? (typeof a.code == "string" && (_ = a.code), typeof a.message == "string" && (m = a.message), typeof a.reason == "string" && (I = a.reason)) : (typeof f.code == "string" && (_ = f.code), typeof f.message == "string" && (m = f.message)), typeof f.reason == "string" && (I = f.reason);
|
|
165
232
|
}
|
|
166
|
-
if (
|
|
167
|
-
let a =
|
|
168
|
-
|
|
233
|
+
if (c.status === 410) {
|
|
234
|
+
let a = c.headers.get("x-neetru-replacement");
|
|
235
|
+
m === `HTTP ${c.status}` && (m = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), a && !m.includes(a) && (m += ` Substituto: ${a}.`);
|
|
169
236
|
}
|
|
170
|
-
let
|
|
171
|
-
if (g =
|
|
172
|
-
let y =
|
|
237
|
+
let S = new i(_, m, c.status, F, I, u);
|
|
238
|
+
if (g = S, re.has(_) && p < s) {
|
|
239
|
+
let y = ne(c.headers.get("retry-after")) ?? U(p);
|
|
173
240
|
if (l == null || Date.now() + y < l) {
|
|
174
|
-
await
|
|
241
|
+
await $(y);
|
|
175
242
|
continue;
|
|
176
243
|
}
|
|
177
244
|
}
|
|
178
|
-
throw
|
|
245
|
+
throw S;
|
|
179
246
|
}
|
|
180
|
-
throw g ?? new
|
|
247
|
+
throw g ?? new i("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, u);
|
|
181
248
|
}
|
|
182
249
|
|
|
183
250
|
// src/validators.ts
|
|
184
|
-
var
|
|
251
|
+
var L = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
|
|
185
252
|
function N(t, e) {
|
|
186
|
-
if (typeof e != "string" || !
|
|
187
|
-
throw new
|
|
253
|
+
if (typeof e != "string" || !L.test(e))
|
|
254
|
+
throw new i(
|
|
188
255
|
"validation_failed",
|
|
189
|
-
`${t} must match ${
|
|
256
|
+
`${t} must match ${L.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
|
|
190
257
|
);
|
|
191
258
|
}
|
|
192
259
|
|
|
193
260
|
// src/notifications.ts
|
|
194
|
-
var
|
|
261
|
+
var R = [
|
|
195
262
|
"info",
|
|
196
263
|
"success",
|
|
197
264
|
"warning",
|
|
198
265
|
"error"
|
|
199
266
|
];
|
|
200
|
-
function
|
|
267
|
+
function j(t) {
|
|
201
268
|
if (!t || typeof t != "object")
|
|
202
|
-
throw new
|
|
269
|
+
throw new i("invalid_response", "Notification response is not an object");
|
|
203
270
|
let e = t;
|
|
204
271
|
if (typeof e.id != "string")
|
|
205
|
-
throw new
|
|
206
|
-
let r =
|
|
272
|
+
throw new i("invalid_response", "Notification missing id");
|
|
273
|
+
let r = R.includes(e.severity) ? e.severity : "info";
|
|
207
274
|
return {
|
|
208
275
|
id: e.id,
|
|
209
276
|
userId: typeof e.userId == "string" ? e.userId : "",
|
|
@@ -218,56 +285,56 @@ function M(t) {
|
|
|
218
285
|
dismissedAt: typeof e.dismissedAt == "string" ? e.dismissedAt : void 0
|
|
219
286
|
};
|
|
220
287
|
}
|
|
221
|
-
function
|
|
222
|
-
if (!t.userId) throw new
|
|
223
|
-
if (!t.kind) throw new
|
|
224
|
-
if (!t.title) throw new
|
|
225
|
-
if (t.severity && !
|
|
226
|
-
throw new
|
|
288
|
+
function H(t) {
|
|
289
|
+
if (!t.userId) throw new i("validation_failed", "userId obrigat\xF3rio");
|
|
290
|
+
if (!t.kind) throw new i("validation_failed", "kind obrigat\xF3rio");
|
|
291
|
+
if (!t.title) throw new i("validation_failed", "title obrigat\xF3rio");
|
|
292
|
+
if (t.severity && !R.includes(t.severity))
|
|
293
|
+
throw new i(
|
|
227
294
|
"validation_failed",
|
|
228
|
-
`severity inv\xE1lida: ${t.severity} (use ${
|
|
295
|
+
`severity inv\xE1lida: ${t.severity} (use ${R.join("|")})`
|
|
229
296
|
);
|
|
230
297
|
if (t.title.length > 200)
|
|
231
|
-
throw new
|
|
298
|
+
throw new i("validation_failed", "title m\xE1x 200 chars");
|
|
232
299
|
if (t.body && t.body.length > 2e3)
|
|
233
|
-
throw new
|
|
300
|
+
throw new i("validation_failed", "body m\xE1x 2000 chars");
|
|
234
301
|
}
|
|
235
|
-
function
|
|
302
|
+
function w(t, ...e) {
|
|
236
303
|
for (let r of e)
|
|
237
304
|
if (typeof r == "string" && r.length > 0)
|
|
238
305
|
return N("productId", r), r;
|
|
239
306
|
if (t.productId)
|
|
240
307
|
return N("productId", t.productId), t.productId;
|
|
241
|
-
throw new
|
|
308
|
+
throw new i(
|
|
242
309
|
"validation_failed",
|
|
243
310
|
"productId required (pass to options/input or set on createNeetruClient)"
|
|
244
311
|
);
|
|
245
312
|
}
|
|
246
|
-
function
|
|
313
|
+
function Ie(t) {
|
|
247
314
|
return {
|
|
248
315
|
async send(e) {
|
|
249
|
-
|
|
250
|
-
let
|
|
251
|
-
productId:
|
|
316
|
+
H(e);
|
|
317
|
+
let n = {
|
|
318
|
+
productId: w(t, e.productId),
|
|
252
319
|
userId: e.userId,
|
|
253
320
|
kind: e.kind,
|
|
254
321
|
title: e.title,
|
|
255
322
|
severity: e.severity ?? "info"
|
|
256
323
|
};
|
|
257
|
-
e.body !== void 0 && (
|
|
324
|
+
e.body !== void 0 && (n.body = e.body), e.link !== void 0 && (n.link = e.link), e.metadata !== void 0 && (n.metadata = e.metadata), e.fingerprint !== void 0 && (n.fingerprint = e.fingerprint);
|
|
258
325
|
let o = await h(t, {
|
|
259
326
|
method: "POST",
|
|
260
327
|
path: "/api/sdk/v1/notifications",
|
|
261
|
-
body:
|
|
328
|
+
body: n,
|
|
262
329
|
requireAuth: true,
|
|
263
330
|
idempotencyKey: true
|
|
264
331
|
});
|
|
265
|
-
return
|
|
332
|
+
return j(o);
|
|
266
333
|
},
|
|
267
334
|
async list(e, r) {
|
|
268
|
-
if (!e) throw new
|
|
335
|
+
if (!e) throw new i("validation_failed", "userId obrigat\xF3rio");
|
|
269
336
|
let o = {
|
|
270
|
-
productId:
|
|
337
|
+
productId: w(t, r?.productId)
|
|
271
338
|
};
|
|
272
339
|
r?.includeDismissed && (o.includeDismissed = true), r?.onlyUnread && (o.onlyUnread = true), r?.limit && (o.limit = Math.min(Math.max(1, r.limit), 200));
|
|
273
340
|
let s = await h(t, {
|
|
@@ -276,41 +343,41 @@ function ue(t) {
|
|
|
276
343
|
query: o,
|
|
277
344
|
requireAuth: true
|
|
278
345
|
});
|
|
279
|
-
return (Array.isArray(s?.notifications) ? s.notifications : []).map(
|
|
346
|
+
return (Array.isArray(s?.notifications) ? s.notifications : []).map(j);
|
|
280
347
|
},
|
|
281
348
|
async markRead(e, r) {
|
|
282
|
-
if (!e) throw new
|
|
283
|
-
let
|
|
349
|
+
if (!e) throw new i("validation_failed", "id obrigat\xF3rio");
|
|
350
|
+
let n = w(t, r?.productId);
|
|
284
351
|
return await h(t, {
|
|
285
352
|
method: "POST",
|
|
286
353
|
path: `/api/sdk/v1/notifications/${encodeURIComponent(e)}/read`,
|
|
287
|
-
query: { productId:
|
|
354
|
+
query: { productId: n },
|
|
288
355
|
requireAuth: true
|
|
289
356
|
}), { ok: true };
|
|
290
357
|
},
|
|
291
358
|
async dismiss(e, r) {
|
|
292
|
-
if (!e) throw new
|
|
293
|
-
let
|
|
359
|
+
if (!e) throw new i("validation_failed", "id obrigat\xF3rio");
|
|
360
|
+
let n = w(t, r?.productId);
|
|
294
361
|
return await h(t, {
|
|
295
362
|
method: "POST",
|
|
296
363
|
path: `/api/sdk/v1/notifications/${encodeURIComponent(e)}/dismiss`,
|
|
297
|
-
query: { productId:
|
|
364
|
+
query: { productId: n },
|
|
298
365
|
requireAuth: true
|
|
299
366
|
}), { ok: true };
|
|
300
367
|
}
|
|
301
368
|
};
|
|
302
369
|
}
|
|
303
|
-
var
|
|
370
|
+
var V = class {
|
|
304
371
|
notifications = /* @__PURE__ */ new Map();
|
|
305
372
|
nextId = 1;
|
|
306
373
|
async send(e) {
|
|
307
|
-
if (
|
|
374
|
+
if (H(e), e.fingerprint) {
|
|
308
375
|
let o = Date.now() - 864e5;
|
|
309
376
|
for (let s of this.notifications.values())
|
|
310
377
|
if ((s.metadata ?? {}).fingerprint === e.fingerprint && s.userId === e.userId && new Date(s.createdAt).getTime() > o)
|
|
311
378
|
return s;
|
|
312
379
|
}
|
|
313
|
-
let r = `mock_notif_${this.nextId++}`,
|
|
380
|
+
let r = `mock_notif_${this.nextId++}`, n = {
|
|
314
381
|
id: r,
|
|
315
382
|
userId: e.userId,
|
|
316
383
|
kind: e.kind,
|
|
@@ -321,23 +388,23 @@ var U = class {
|
|
|
321
388
|
metadata: e.fingerprint ? { ...e.metadata ?? {}, fingerprint: e.fingerprint } : e.metadata,
|
|
322
389
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
323
390
|
};
|
|
324
|
-
return this.notifications.set(r,
|
|
391
|
+
return this.notifications.set(r, n), n;
|
|
325
392
|
}
|
|
326
393
|
async list(e, r) {
|
|
327
|
-
if (!e) throw new
|
|
328
|
-
let
|
|
329
|
-
return [...this.notifications.values()].filter((o) => o.userId === e).filter((o) => r?.includeDismissed || !o.dismissedAt).filter((o) => !r?.onlyUnread || !o.readAt).sort((o, s) => s.createdAt.localeCompare(o.createdAt)).slice(0,
|
|
394
|
+
if (!e) throw new i("validation_failed", "userId obrigat\xF3rio");
|
|
395
|
+
let n = Math.min(Math.max(1, r?.limit ?? 50), 200);
|
|
396
|
+
return [...this.notifications.values()].filter((o) => o.userId === e).filter((o) => r?.includeDismissed || !o.dismissedAt).filter((o) => !r?.onlyUnread || !o.readAt).sort((o, s) => s.createdAt.localeCompare(o.createdAt)).slice(0, n);
|
|
330
397
|
}
|
|
331
398
|
async markRead(e, r) {
|
|
332
|
-
let
|
|
333
|
-
if (!
|
|
334
|
-
return
|
|
399
|
+
let n = this.notifications.get(e);
|
|
400
|
+
if (!n) throw new i("not_found", `Notification ${e} n\xE3o encontrada`);
|
|
401
|
+
return n.readAt || (n.readAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, n)), { ok: true };
|
|
335
402
|
}
|
|
336
403
|
async dismiss(e, r) {
|
|
337
|
-
let
|
|
338
|
-
if (!
|
|
339
|
-
return
|
|
404
|
+
let n = this.notifications.get(e);
|
|
405
|
+
if (!n) throw new i("not_found", `Notification ${e} n\xE3o encontrada`);
|
|
406
|
+
return n.dismissedAt || (n.dismissedAt = (/* @__PURE__ */ new Date()).toISOString(), this.notifications.set(e, n)), { ok: true };
|
|
340
407
|
}
|
|
341
408
|
};
|
|
342
409
|
|
|
343
|
-
export {
|
|
410
|
+
export { V as MockNotifications, Ie as createNotificationsNamespace };
|