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