@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.
Files changed (73) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +66 -1
  3. package/dist/ai.cjs +221 -177
  4. package/dist/ai.d.cts +1 -1
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.mjs +221 -177
  7. package/dist/auth.cjs +1227 -1064
  8. package/dist/auth.d.cts +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/auth.mjs +1224 -1061
  11. package/dist/catalog.cjs +164 -97
  12. package/dist/catalog.d.cts +1 -1
  13. package/dist/catalog.d.ts +1 -1
  14. package/dist/catalog.mjs +164 -97
  15. package/dist/checkout.cjs +182 -115
  16. package/dist/checkout.d.cts +1 -1
  17. package/dist/checkout.d.ts +1 -1
  18. package/dist/checkout.mjs +181 -114
  19. package/dist/db-react.d.cts +1 -1
  20. package/dist/db-react.d.ts +1 -1
  21. package/dist/db.cjs +370 -298
  22. package/dist/db.d.cts +1 -1
  23. package/dist/db.d.ts +1 -1
  24. package/dist/db.mjs +362 -290
  25. package/dist/entitlements.cjs +17 -10
  26. package/dist/entitlements.d.cts +1 -1
  27. package/dist/entitlements.d.ts +1 -1
  28. package/dist/entitlements.mjs +17 -10
  29. package/dist/errors.cjs +15 -8
  30. package/dist/errors.d.cts +24 -3
  31. package/dist/errors.d.ts +24 -3
  32. package/dist/errors.mjs +14 -7
  33. package/dist/firestore-compat.d.cts +1 -1
  34. package/dist/firestore-compat.d.ts +1 -1
  35. package/dist/index.cjs +1409 -1075
  36. package/dist/index.d.cts +177 -3
  37. package/dist/index.d.ts +177 -3
  38. package/dist/index.mjs +1544 -1217
  39. package/dist/mobile.cjs +400 -181
  40. package/dist/mobile.d.cts +59 -4
  41. package/dist/mobile.d.ts +59 -4
  42. package/dist/mobile.mjs +400 -181
  43. package/dist/mocks.cjs +9 -2
  44. package/dist/mocks.d.cts +1 -1
  45. package/dist/mocks.d.ts +1 -1
  46. package/dist/mocks.mjs +9 -2
  47. package/dist/notifications.cjs +197 -130
  48. package/dist/notifications.d.cts +1 -1
  49. package/dist/notifications.d.ts +1 -1
  50. package/dist/notifications.mjs +196 -129
  51. package/dist/react.cjs +303 -282
  52. package/dist/react.d.cts +1 -1
  53. package/dist/react.d.ts +1 -1
  54. package/dist/react.mjs +295 -274
  55. package/dist/support.cjs +299 -229
  56. package/dist/support.d.cts +8 -4
  57. package/dist/support.d.ts +8 -4
  58. package/dist/support.mjs +298 -228
  59. package/dist/telemetry.cjs +234 -167
  60. package/dist/telemetry.d.cts +1 -1
  61. package/dist/telemetry.d.ts +1 -1
  62. package/dist/telemetry.mjs +234 -167
  63. package/dist/{types-Bx4kTLmk.d.cts → types-D-9bjlM0.d.cts} +48 -1
  64. package/dist/{types-Dx0IrOSF.d.ts → types-bVztFQTI.d.ts} +48 -1
  65. package/dist/usage.cjs +183 -116
  66. package/dist/usage.d.cts +1 -1
  67. package/dist/usage.d.ts +1 -1
  68. package/dist/usage.mjs +183 -116
  69. package/dist/webhooks.cjs +215 -148
  70. package/dist/webhooks.d.cts +1 -1
  71. package/dist/webhooks.d.ts +1 -1
  72. package/dist/webhooks.mjs +212 -145
  73. package/package.json +2 -1
package/dist/webhooks.cjs CHANGED
@@ -14,13 +14,20 @@ var s = class t extends Error {
14
14
  * para um `NeetruDbErrorCode` mais específico (recuperável vs não).
15
15
  */
16
16
  reason;
17
- constructor(e, r, n, i, o) {
18
- super(r), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = i, this.reason = o, Object.setPrototypeOf(this, t.prototype);
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, i, a) {
25
+ super(r), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = o, this.reason = i, this.correlationId = a, Object.setPrototypeOf(this, t.prototype);
19
26
  }
20
27
  };
21
28
 
22
29
  // src/idempotency.ts
23
- function S() {
30
+ function N() {
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();
@@ -30,8 +37,60 @@ function S() {
30
37
  );
31
38
  }
32
39
 
40
+ // src/correlation.ts
41
+ var D = "x-correlation-id";
42
+ var F = /^[A-Za-z0-9._:\-]+$/;
43
+ function C(t) {
44
+ return typeof t == "string" && t.length > 0 && t.length <= 128 && F.test(t);
45
+ }
46
+ function z() {
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 [i, a] of Object.entries(t)) {
67
+ if (i.toLowerCase() === D) {
68
+ C(a) && (r = a);
69
+ continue;
70
+ }
71
+ n[i] = a;
72
+ }
73
+ let o = r ?? (C(e) ? e : void 0) ?? z();
74
+ return n[D] = o, { headers: n, correlationId: o };
75
+ }
76
+
77
+ // src/server-only-key.ts
78
+ function M() {
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 H = {
93
+ var G = {
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"
@@ -39,73 +98,77 @@ var H = {
39
98
  function A(t) {
40
99
  return t.split("+")[0] ?? t;
41
100
  }
42
- function j(t, e) {
43
- let r = A(t).split(".").map(Number), n = A(e).split(".").map(Number), i = Math.max(r.length, n.length);
44
- for (let o = 0; o < i; o++) {
45
- let d = r[o] ?? 0, c = n[o] ?? 0;
46
- if (d !== c) return d - c;
101
+ function X(t, e) {
102
+ let r = A(t).split(".").map(Number), n = A(e).split(".").map(Number), o = Math.max(r.length, n.length);
103
+ for (let i = 0; i < o; i++) {
104
+ let a = r[i] ?? 0, c = n[i] ?? 0;
105
+ if (a !== c) return a - c;
47
106
  }
48
107
  return 0;
49
108
  }
50
- function q() {
109
+ function $() {
51
110
  try {
52
- return "3.7.0";
111
+ return "3.8.0";
53
112
  } catch {
54
113
  return;
55
114
  }
56
115
  }
57
- function V() {
58
- let t = q();
116
+ function Y() {
117
+ let t = $();
59
118
  return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
60
119
  }
61
120
  var W = /* @__PURE__ */ new Set();
62
- function B(t) {
121
+ function J(t) {
63
122
  if (!t) return;
64
- let e = V(), r = H[e];
123
+ let e = Y(), r = G[e];
65
124
  if (!r) return;
66
125
  let n = A(t);
67
- if (j(n, r) < 0) {
68
- let i = `${e}:${n}`;
69
- W.has(i) || (W.add(i), console.warn(
126
+ if (X(n, r) < 0) {
127
+ let o = `${e}:${n}`;
128
+ W.has(o) || (W.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
- var L = 2, F = 0, z = /* @__PURE__ */ new Set(["GET", "HEAD"]), G = /* @__PURE__ */ new Set([
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 M() ? "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 N(t) {
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 C = 6e4;
84
- function J(t) {
146
+ var q = 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), C);
150
+ if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), q);
88
151
  let r = Date.parse(t);
89
152
  if (Number.isFinite(r)) {
90
153
  let n = r - Date.now();
91
- if (n > 0) return Math.min(n, C);
154
+ if (n > 0) return Math.min(n, q);
92
155
  }
93
156
  return null;
94
157
  }
95
- function D(t) {
158
+ function P(t) {
96
159
  return new Promise((e) => setTimeout(e, t));
97
160
  }
98
- function Y(t) {
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 X(t, e, r) {
102
- let n = t.replace(/\/+$/, ""), i = e.startsWith("/") ? e : `/${e}`, o = new URL(`${n}${i}`);
164
+ function ie(t, e, r) {
165
+ let n = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, i = new URL(`${n}${o}`);
103
166
  if (r)
104
- for (let [d, c] of Object.entries(r))
105
- c !== void 0 && o.searchParams.set(d, String(c));
106
- return o.toString();
167
+ for (let [a, c] of Object.entries(r))
168
+ c !== void 0 && i.searchParams.set(a, String(c));
169
+ return i.toString();
107
170
  }
108
- async function M(t) {
171
+ async function K(t) {
109
172
  let e = await t.text();
110
173
  if (e)
111
174
  try {
@@ -114,147 +177,151 @@ async function M(t) {
114
177
  return;
115
178
  }
116
179
  }
117
- async function _(t, e) {
118
- let r = e.method ?? "GET", n = X(t.baseUrl, e.path, e.query), i = z.has(r) ? L : F, o = e.retries ?? i, d = {
119
- accept: "application/json",
120
- ...e.headers
121
- }, c = q();
122
- if (c && (d["x-neetru-sdk-version"] = c), e.requireAuth) {
180
+ async function k(t, e) {
181
+ let r = e.method ?? "GET", n = ie(t.baseUrl, e.path, e.query), o = te.has(r) ? Q : ee, i = e.retries ?? o, { headers: a, correlationId: c } = O(
182
+ { accept: "application/json", ...e.headers },
183
+ e.correlationId
184
+ ), b = $();
185
+ if (b && (a["x-neetru-sdk-version"] = b), e.requireAuth) {
123
186
  if (!t.apiKey)
124
- throw new s(
125
- "missing_api_key",
126
- "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
127
- );
128
- d.authorization = `Bearer ${t.apiKey}`;
187
+ throw new s("missing_api_key", Z());
188
+ a.authorization = `Bearer ${t.apiKey}`;
129
189
  }
130
190
  if (e.idempotencyKey) {
131
- let l = typeof e.idempotencyKey == "string" ? e.idempotencyKey : S();
132
- d["idempotency-key"] = l;
191
+ let l = typeof e.idempotencyKey == "string" ? e.idempotencyKey : N();
192
+ a["idempotency-key"] = l;
133
193
  }
134
- let y = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
135
- y !== void 0 && (d["content-type"] = "application/json");
136
- let h = null, f = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
137
- for (let l = 0; l <= o; l++) {
138
- if (f != null && Date.now() >= f)
139
- throw h ?? new s("network_error", "Deadline excedido antes de completar a request");
140
- let m = { method: r, headers: d };
141
- y !== void 0 && (m.body = y);
142
- let k = f != null ? Math.max(1, Math.min(3e4, f - Date.now())) : 3e4;
143
- m.signal = AbortSignal.timeout(k);
144
- let u;
194
+ let h = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
195
+ h !== void 0 && (a["content-type"] = "application/json");
196
+ let g = null, p = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
197
+ for (let l = 0; l <= i; l++) {
198
+ if (p != null && Date.now() >= p)
199
+ throw g ?? new s(
200
+ "network_error",
201
+ "Deadline excedido antes de completar a request",
202
+ void 0,
203
+ void 0,
204
+ void 0,
205
+ c
206
+ );
207
+ let f = { method: r, headers: a };
208
+ h !== void 0 && (f.body = h);
209
+ let v = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
210
+ f.signal = AbortSignal.timeout(v);
211
+ let d;
145
212
  try {
146
- u = await t.fetch(n, m);
147
- } catch (a) {
148
- let w = a instanceof DOMException && a.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${a instanceof Error ? a.message : "fetch failed"}`;
149
- if (h = new s("network_error", w), l < o) {
150
- let x = N(l);
151
- if (f == null || Date.now() + x < f) {
152
- await D(x);
213
+ d = await t.fetch(n, f);
214
+ } catch (u) {
215
+ let _ = u instanceof DOMException && u.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${u instanceof Error ? u.message : "fetch failed"}`;
216
+ if (g = new s("network_error", _, void 0, void 0, void 0, c), l < i) {
217
+ let T = U(l);
218
+ if (p == null || Date.now() + T < p) {
219
+ await P(T);
153
220
  continue;
154
221
  }
155
222
  }
156
- throw h;
223
+ throw g;
157
224
  }
158
- let g = u.headers.get("x-request-id") ?? u.headers.get("x-correlation-id") ?? void 0;
159
- if (u.ok) {
160
- let a = u.headers.get("x-neetru-version");
161
- return a && B(a), await M(u);
225
+ let w = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
226
+ if (d.ok) {
227
+ let u = d.headers.get("x-neetru-version");
228
+ return u && J(u), await K(d);
162
229
  }
163
- let p = await M(u), v = Y(u.status), b = `HTTP ${u.status}`, R;
164
- if (p && typeof p == "object") {
165
- let a = p.error;
166
- typeof a == "string" ? b = a : a && typeof a == "object" ? (typeof a.code == "string" && (v = a.code), typeof a.message == "string" && (b = a.message), typeof a.reason == "string" && (R = a.reason)) : (typeof p.code == "string" && (v = p.code), typeof p.message == "string" && (b = p.message)), typeof p.reason == "string" && (R = p.reason);
230
+ let m = await K(d), E = oe(d.status), y = `HTTP ${d.status}`, I;
231
+ if (m && typeof m == "object") {
232
+ let u = m.error;
233
+ typeof u == "string" ? y = u : u && typeof u == "object" ? (typeof u.code == "string" && (E = u.code), typeof u.message == "string" && (y = u.message), typeof u.reason == "string" && (I = u.reason)) : (typeof m.code == "string" && (E = m.code), typeof m.message == "string" && (y = m.message)), typeof m.reason == "string" && (I = m.reason);
167
234
  }
168
- if (u.status === 410) {
169
- let a = u.headers.get("x-neetru-replacement");
170
- b === `HTTP ${u.status}` && (b = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), a && !b.includes(a) && (b += ` Substituto: ${a}.`);
235
+ if (d.status === 410) {
236
+ let u = d.headers.get("x-neetru-replacement");
237
+ y === `HTTP ${d.status}` && (y = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), u && !y.includes(u) && (y += ` Substituto: ${u}.`);
171
238
  }
172
- let T = new s(v, b, u.status, g, R);
173
- if (h = T, G.has(v) && l < o) {
174
- let w = J(u.headers.get("retry-after")) ?? N(l);
175
- if (f == null || Date.now() + w < f) {
176
- await D(w);
239
+ let x = new s(E, y, d.status, w, I, c);
240
+ if (g = x, re.has(E) && l < i) {
241
+ let _ = ne(d.headers.get("retry-after")) ?? U(l);
242
+ if (p == null || Date.now() + _ < p) {
243
+ await P(_);
177
244
  continue;
178
245
  }
179
246
  }
180
- throw T;
247
+ throw x;
181
248
  }
182
- throw h ?? new s("unknown", "unexpected httpRequest exit");
249
+ throw g ?? new s("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, c);
183
250
  }
184
251
 
185
252
  // src/validators.ts
186
- var O = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
187
- function I(t, e) {
188
- if (typeof e != "string" || !O.test(e))
253
+ var L = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
254
+ function S(t, e) {
255
+ if (typeof e != "string" || !L.test(e))
189
256
  throw new s(
190
257
  "validation_failed",
191
- `${t} must match ${O.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
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/webhooks.ts
196
- async function Q(t, e, r, n) {
263
+ async function se(t, e, r, n) {
197
264
  if (!e || !r) return false;
198
- let i = e.startsWith("sha256=") ? e.slice(7) : e;
199
- if (!/^[0-9a-f]+$/i.test(i)) return false;
200
- let o = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto?.subtle : void 0;
201
- if (!o)
265
+ let o = e.startsWith("sha256=") ? e.slice(7) : e;
266
+ if (!/^[0-9a-f]+$/i.test(o)) return false;
267
+ let i = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto?.subtle : void 0;
268
+ if (!i)
202
269
  throw new s(
203
270
  "runtime_unsupported",
204
271
  "verifyWebhookSignature requires globalThis.crypto.subtle (Node \u226520, modern browser, or Edge runtime)."
205
272
  );
206
- let d = new TextEncoder(), c = d.encode(r), y = typeof t == "string" ? d.encode(t) : t, h = y;
273
+ let a = new TextEncoder(), c = a.encode(r), b = typeof t == "string" ? a.encode(t) : t, h = b;
207
274
  if (n !== void 0) {
208
- let g = d.encode(`${n}.`), p = new Uint8Array(g.length + y.length);
209
- p.set(g, 0), p.set(y, g.length), h = p;
275
+ let d = a.encode(`${n}.`), w = new Uint8Array(d.length + b.length);
276
+ w.set(d, 0), w.set(b, d.length), h = w;
210
277
  }
211
- let f = await o.importKey(
278
+ let g = await i.importKey(
212
279
  "raw",
213
280
  c,
214
281
  { name: "HMAC", hash: "SHA-256" },
215
282
  false,
216
283
  ["sign"]
217
- ), l = await o.sign(
284
+ ), p = await i.sign(
218
285
  "HMAC",
219
- f,
286
+ g,
220
287
  h
221
- ), m = new Uint8Array(l), k = Z(i.toLowerCase());
222
- if (!k || k.length !== m.length) return false;
223
- let u = 0;
224
- for (let g = 0; g < m.length; g++)
225
- u |= m[g] ^ k[g];
226
- return u === 0;
288
+ ), l = new Uint8Array(p), f = ae(o.toLowerCase());
289
+ if (!f || f.length !== l.length) return false;
290
+ let v = 0;
291
+ for (let d = 0; d < l.length; d++)
292
+ v |= l[d] ^ f[d];
293
+ return v === 0;
227
294
  }
228
- async function pe(t, e, r, n = {}) {
229
- let i = n.toleranceMs ?? 3e5, o = (l) => {
295
+ async function Re(t, e, r, n = {}) {
296
+ let o = n.toleranceMs ?? 3e5, i = (p) => {
230
297
  if (typeof e.get == "function")
231
- return e.get(l);
232
- let m = e, k = l.toLowerCase();
233
- for (let u of Object.keys(m))
234
- if (u.toLowerCase() === k) return m[u] ?? null;
298
+ return e.get(p);
299
+ let l = e, f = p.toLowerCase();
300
+ for (let v of Object.keys(l))
301
+ if (v.toLowerCase() === f) return l[v] ?? null;
235
302
  return null;
236
- }, d = o("x-neetru-timestamp");
237
- if (!d)
303
+ }, a = i("x-neetru-timestamp");
304
+ if (!a)
238
305
  return { ok: false, reason: "timestamp_missing" };
239
- let c = Number(d);
306
+ let c = Number(a);
240
307
  if (!Number.isFinite(c))
241
308
  return { ok: false, reason: "timestamp_missing" };
242
- if (Math.abs(Date.now() - c) > i)
309
+ if (Math.abs(Date.now() - c) > o)
243
310
  return { ok: false, reason: "timestamp_expired" };
244
- let h = o("x-neetru-signature");
245
- return await Q(t, h, r, d) ? { ok: true } : { ok: false, reason: "invalid_signature" };
311
+ let h = i("x-neetru-signature");
312
+ return await se(t, h, r, a) ? { ok: true } : { ok: false, reason: "invalid_signature" };
246
313
  }
247
- function Z(t) {
314
+ function ae(t) {
248
315
  if (t.length % 2 !== 0) return null;
249
316
  let e = new Uint8Array(t.length / 2);
250
317
  for (let r = 0; r < e.length; r++) {
251
- let n = parseInt(t[r * 2], 16), i = parseInt(t[r * 2 + 1], 16);
252
- if (Number.isNaN(n) || Number.isNaN(i)) return null;
253
- e[r] = n << 4 | i;
318
+ let n = parseInt(t[r * 2], 16), o = parseInt(t[r * 2 + 1], 16);
319
+ if (Number.isNaN(n) || Number.isNaN(o)) return null;
320
+ e[r] = n << 4 | o;
254
321
  }
255
322
  return e;
256
323
  }
257
- var $ = [
324
+ var V = [
258
325
  "subscription.activated",
259
326
  "subscription.cancelled",
260
327
  "subscription.payment_failed",
@@ -264,7 +331,7 @@ var $ = [
264
331
  "account.reactivated",
265
332
  "support.ticket_replied"
266
333
  ];
267
- function U(t) {
334
+ function H(t) {
268
335
  if (!t || typeof t != "object")
269
336
  throw new s("invalid_response", "Webhook response is not an object");
270
337
  let e = t;
@@ -274,7 +341,7 @@ function U(t) {
274
341
  id: e.id,
275
342
  url: typeof e.url == "string" ? e.url : "",
276
343
  events: Array.isArray(e.events) ? e.events.filter(
277
- (r) => $.includes(r)
344
+ (r) => V.includes(r)
278
345
  ) : [],
279
346
  hasSecret: e.hasSecret === true,
280
347
  status: e.status === "active" || e.status === "degraded" || e.status === "disabled" ? e.status : "active",
@@ -283,7 +350,7 @@ function U(t) {
283
350
  createdAt: typeof e.createdAt == "string" ? e.createdAt : (/* @__PURE__ */ new Date()).toISOString()
284
351
  };
285
352
  }
286
- function K(t) {
353
+ function B(t) {
287
354
  if (!t.url || typeof t.url != "string")
288
355
  throw new s("validation_failed", "url \xE9 obrigat\xF3ria");
289
356
  try {
@@ -296,27 +363,27 @@ function K(t) {
296
363
  if (!Array.isArray(t.events) || t.events.length === 0)
297
364
  throw new s("validation_failed", "events deve ter pelo menos 1 evento");
298
365
  for (let e of t.events)
299
- if (!$.includes(e))
366
+ if (!V.includes(e))
300
367
  throw new s("validation_failed", `evento desconhecido: ${e}`);
301
368
  if (t.secret !== void 0 && t.secret.length < 16)
302
369
  throw new s("validation_failed", "secret deve ter \u226516 chars (recomendado 32+)");
303
370
  }
304
- function E(t, ...e) {
371
+ function R(t, ...e) {
305
372
  for (let r of e)
306
373
  if (typeof r == "string" && r.length > 0)
307
- return I("productId", r), r;
374
+ return S("productId", r), r;
308
375
  if (t.productId)
309
- return I("productId", t.productId), t.productId;
376
+ return S("productId", t.productId), t.productId;
310
377
  throw new s(
311
378
  "validation_failed",
312
379
  "productId required (pass to options/input or set on createNeetruClient)"
313
380
  );
314
381
  }
315
- function fe(t) {
382
+ function Ie(t) {
316
383
  return {
317
384
  async register(e) {
318
- K(e);
319
- let r = E(t, e.productId), n = await _(t, {
385
+ B(e);
386
+ let r = R(t, e.productId), n = await k(t, {
320
387
  method: "POST",
321
388
  path: "/api/sdk/v1/webhooks",
322
389
  body: {
@@ -332,21 +399,21 @@ function fe(t) {
332
399
  // dedup TTL 24h (mesmo padrão de usage.report/support.createTicket).
333
400
  idempotencyKey: true
334
401
  });
335
- return U(n);
402
+ return H(n);
336
403
  },
337
404
  async list(e) {
338
- let r = E(t, e?.productId), n = await _(t, {
405
+ let r = R(t, e?.productId), n = await k(t, {
339
406
  method: "GET",
340
407
  path: "/api/sdk/v1/webhooks",
341
408
  query: { productId: r },
342
409
  requireAuth: true
343
410
  });
344
- return (Array.isArray(n?.endpoints) ? n.endpoints : []).map(U);
411
+ return (Array.isArray(n?.endpoints) ? n.endpoints : []).map(H);
345
412
  },
346
413
  async unregister(e, r) {
347
414
  if (!e) throw new s("validation_failed", "id obrigat\xF3rio");
348
- let n = E(t, r?.productId);
349
- return await _(t, {
415
+ let n = R(t, r?.productId);
416
+ return await k(t, {
350
417
  method: "DELETE",
351
418
  path: `/api/sdk/v1/webhooks/${encodeURIComponent(e)}`,
352
419
  query: { productId: n },
@@ -355,30 +422,30 @@ function fe(t) {
355
422
  },
356
423
  async test(e, r) {
357
424
  if (!e) throw new s("validation_failed", "id obrigat\xF3rio");
358
- let n = E(t, r?.productId), i = await _(t, {
425
+ let n = R(t, r?.productId), o = await k(t, {
359
426
  method: "POST",
360
427
  path: `/api/sdk/v1/webhooks/${encodeURIComponent(e)}/test`,
361
428
  query: { productId: n },
362
429
  requireAuth: true,
363
430
  idempotencyKey: true
364
431
  });
365
- if (!i || typeof i != "object")
432
+ if (!o || typeof o != "object")
366
433
  return { ok: false, error: "invalid response" };
367
- let o = i;
434
+ let i = o;
368
435
  return {
369
- ok: o.ok === true,
370
- statusCode: typeof o.statusCode == "number" ? o.statusCode : void 0,
371
- durationMs: typeof o.durationMs == "number" ? o.durationMs : void 0,
372
- error: typeof o.error == "string" ? o.error : void 0
436
+ ok: i.ok === true,
437
+ statusCode: typeof i.statusCode == "number" ? i.statusCode : void 0,
438
+ durationMs: typeof i.durationMs == "number" ? i.durationMs : void 0,
439
+ error: typeof i.error == "string" ? i.error : void 0
373
440
  };
374
441
  }
375
442
  };
376
443
  }
377
- var P = class {
444
+ var j = class {
378
445
  endpoints = /* @__PURE__ */ new Map();
379
446
  nextId = 1;
380
447
  async register(e) {
381
- K(e);
448
+ B(e);
382
449
  let r = `mock_wh_${this.nextId++}`, n = {
383
450
  id: r,
384
451
  url: e.url,
@@ -404,7 +471,7 @@ var P = class {
404
471
  }
405
472
  };
406
473
 
407
- exports.MockWebhooks = P;
408
- exports.createWebhooksNamespace = fe;
409
- exports.verifyWebhookRequest = pe;
410
- exports.verifyWebhookSignature = Q;
474
+ exports.MockWebhooks = j;
475
+ exports.createWebhooksNamespace = Ie;
476
+ exports.verifyWebhookRequest = Re;
477
+ exports.verifyWebhookSignature = se;
@@ -1,3 +1,3 @@
1
- export { U as MockWebhooks, af as RegisterWebhookInput, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aO as createWebhooksNamespace, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-Bx4kTLmk.cjs';
1
+ export { V as MockWebhooks, ag as RegisterWebhookInput, aB as VerifyWebhookRequestOptions, aC as VerifyWebhookRequestResult, aD as WebhookEndpoint, aE as WebhookEvent, aF as WebhookScopeOptions, aG as WebhookTestResult, aH as WebhooksNamespace, aP as createWebhooksNamespace, aW as verifyWebhookRequest, aX as verifyWebhookSignature } from './types-D-9bjlM0.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
@@ -1,3 +1,3 @@
1
- export { U as MockWebhooks, af as RegisterWebhookInput, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aO as createWebhooksNamespace, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-Dx0IrOSF.js';
1
+ export { V as MockWebhooks, ag as RegisterWebhookInput, aB as VerifyWebhookRequestOptions, aC as VerifyWebhookRequestResult, aD as WebhookEndpoint, aE as WebhookEvent, aF as WebhookScopeOptions, aG as WebhookTestResult, aH as WebhooksNamespace, aP as createWebhooksNamespace, aW as verifyWebhookRequest, aX as verifyWebhookSignature } from './types-bVztFQTI.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';