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