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