@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/support.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // src/errors.ts
4
- var o = class t extends Error {
4
+ var i = class e extends Error {
5
5
  code;
6
6
  status;
7
7
  requestId;
@@ -14,318 +14,388 @@ var o = 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, d, c, u) {
18
- super(r), this.name = "NeetruError", this.code = e, this.status = d, this.requestId = c, this.reason = u, 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(t, r, o, s, u, c) {
25
+ super(r), this.name = "NeetruError", this.code = t, this.status = o, this.requestId = s, this.reason = u, this.correlationId = c, Object.setPrototypeOf(this, e.prototype);
19
26
  }
20
- }, _ = class t extends o {
21
- constructor(e, r, d, c) {
22
- super("auth_required", e, d, c, r), this.name = "NeetruAuthRequiredError", Object.setPrototypeOf(this, t.prototype);
27
+ }, _ = class e extends i {
28
+ constructor(t, r, o, s, u) {
29
+ super("auth_required", t, o, s, r, u), this.name = "NeetruAuthRequiredError", Object.setPrototypeOf(this, e.prototype);
23
30
  }
24
31
  };
25
32
 
26
33
  // src/idempotency.ts
27
- function U() {
28
- let t = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
29
- if (t && typeof t.randomUUID == "function")
30
- return t.randomUUID();
31
- throw new o(
34
+ function C() {
35
+ let e = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
36
+ if (e && typeof e.randomUUID == "function")
37
+ return e.randomUUID();
38
+ throw new i(
32
39
  "runtime_unsupported",
33
40
  "crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
34
41
  );
35
42
  }
36
43
 
44
+ // src/correlation.ts
45
+ var D = "x-correlation-id";
46
+ var Y = /^[A-Za-z0-9._:\-]+$/;
47
+ function U(e) {
48
+ return typeof e == "string" && e.length > 0 && e.length <= 128 && Y.test(e);
49
+ }
50
+ function J() {
51
+ let e = globalThis.crypto;
52
+ try {
53
+ if (e && typeof e.randomUUID == "function") return e.randomUUID();
54
+ } catch {
55
+ }
56
+ let t = new Uint8Array(16), r = false;
57
+ try {
58
+ e && typeof e.getRandomValues == "function" && (e.getRandomValues(t), r = !0);
59
+ } catch {
60
+ r = false;
61
+ }
62
+ if (!r)
63
+ for (let s = 0; s < t.length; s++) t[s] = Math.floor(Math.random() * 256);
64
+ t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
65
+ let o = Array.from(t, (s) => s.toString(16).padStart(2, "0")).join("");
66
+ return `${o.slice(0, 8)}-${o.slice(8, 12)}-${o.slice(12, 16)}-${o.slice(16, 20)}-${o.slice(20)}`;
67
+ }
68
+ function x(e, t) {
69
+ let r, o = {};
70
+ for (let [u, c] of Object.entries(e)) {
71
+ if (u.toLowerCase() === D) {
72
+ U(c) && (r = c);
73
+ continue;
74
+ }
75
+ o[u] = c;
76
+ }
77
+ let s = r ?? (U(t) ? t : void 0) ?? J();
78
+ return o[D] = s, { headers: o, correlationId: s };
79
+ }
80
+
81
+ // src/server-only-key.ts
82
+ function O() {
83
+ try {
84
+ let e = globalThis.navigator;
85
+ if (e && e.product === "ReactNative") return "react-native";
86
+ } catch {
87
+ }
88
+ try {
89
+ let e = globalThis;
90
+ if (typeof e.window < "u" && typeof e.document < "u") return "browser";
91
+ } catch {
92
+ }
93
+ return null;
94
+ }
95
+
37
96
  // src/http.ts
38
- var H = {
97
+ var W = {
39
98
  // SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
40
99
  // runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
41
100
  3: "2026.05.1"
42
101
  };
43
- function S(t) {
44
- return t.split("+")[0] ?? t;
102
+ function A(e) {
103
+ return e.split("+")[0] ?? e;
45
104
  }
46
- function G(t, e) {
47
- let r = S(t).split(".").map(Number), d = S(e).split(".").map(Number), c = Math.max(r.length, d.length);
48
- for (let u = 0; u < c; u++) {
49
- let l = r[u] ?? 0, n = d[u] ?? 0;
50
- if (l !== n) return l - n;
105
+ function Q(e, t) {
106
+ let r = A(e).split(".").map(Number), o = A(t).split(".").map(Number), s = Math.max(r.length, o.length);
107
+ for (let u = 0; u < s; u++) {
108
+ let c = r[u] ?? 0, n = o[u] ?? 0;
109
+ if (c !== n) return c - n;
51
110
  }
52
111
  return 0;
53
112
  }
54
- function M() {
113
+ function $() {
55
114
  try {
56
- return "3.7.0";
115
+ return "3.8.0";
57
116
  } catch {
58
117
  return;
59
118
  }
60
119
  }
61
- function z() {
62
- let t = M();
63
- return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
120
+ function Z() {
121
+ let e = $();
122
+ return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
64
123
  }
65
- var N = /* @__PURE__ */ new Set();
66
- function B(t) {
67
- if (!t) return;
68
- let e = z(), r = H[e];
124
+ var M = /* @__PURE__ */ new Set();
125
+ function ee(e) {
126
+ if (!e) return;
127
+ let t = Z(), r = W[t];
69
128
  if (!r) return;
70
- let d = S(t);
71
- if (G(d, r) < 0) {
72
- let c = `${e}:${d}`;
73
- N.has(c) || (N.add(c), console.warn(
74
- `[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.`
129
+ let o = A(e);
130
+ if (Q(o, r) < 0) {
131
+ let s = `${t}:${o}`;
132
+ M.has(s) || (M.add(s), console.warn(
133
+ `[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${e}" \xE9 anterior ao m\xEDnimo recomendado "${r}" para SDK major ${t}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
75
134
  ));
76
135
  }
77
136
  }
78
- var X = 2, Y = 0, J = /* @__PURE__ */ new Set(["GET", "HEAD"]), W = /* @__PURE__ */ new Set([
137
+ function te() {
138
+ let e = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
139
+ return O() ? "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. (" + e + ")" : e;
140
+ }
141
+ var ne = 2, re = 0, oe = /* @__PURE__ */ new Set(["GET", "HEAD"]), ie = /* @__PURE__ */ new Set([
79
142
  "rate_limited",
80
143
  "server_error",
81
144
  "network_error"
82
145
  ]);
83
- function C(t) {
84
- let e = 200 * Math.pow(4, t), r = e * 0.2 * (Math.random() * 2 - 1);
85
- return Math.max(50, Math.round(e + r));
146
+ function P(e) {
147
+ let t = 200 * Math.pow(4, e), r = t * 0.2 * (Math.random() * 2 - 1);
148
+ return Math.max(50, Math.round(t + r));
86
149
  }
87
- var D = 6e4;
88
- function Q(t) {
89
- if (!t) return null;
90
- let e = Number(t);
91
- if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), D);
92
- let r = Date.parse(t);
150
+ var q = 6e4;
151
+ function se(e) {
152
+ if (!e) return null;
153
+ let t = Number(e);
154
+ if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3), q);
155
+ let r = Date.parse(e);
93
156
  if (Number.isFinite(r)) {
94
- let d = r - Date.now();
95
- if (d > 0) return Math.min(d, D);
157
+ let o = r - Date.now();
158
+ if (o > 0) return Math.min(o, q);
96
159
  }
97
160
  return null;
98
161
  }
99
- function x(t) {
100
- return new Promise((e) => setTimeout(e, t));
162
+ function K(e) {
163
+ return new Promise((t) => setTimeout(t, e));
101
164
  }
102
- function Z(t) {
103
- 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";
165
+ function ae(e) {
166
+ return e === 401 ? "unauthorized" : e === 403 ? "forbidden" : e === 404 ? "not_found" : e === 409 ? "conflict" : e === 410 ? "gone" : e === 422 || e === 400 ? "validation_failed" : e === 429 ? "rate_limited" : e >= 500 ? "server_error" : "unknown";
104
167
  }
105
- function ee(t, e, r) {
106
- let d = t.replace(/\/+$/, ""), c = e.startsWith("/") ? e : `/${e}`, u = new URL(`${d}${c}`);
168
+ function de(e, t, r) {
169
+ let o = e.replace(/\/+$/, ""), s = t.startsWith("/") ? t : `/${t}`, u = new URL(`${o}${s}`);
107
170
  if (r)
108
- for (let [l, n] of Object.entries(r))
109
- n !== void 0 && u.searchParams.set(l, String(n));
171
+ for (let [c, n] of Object.entries(r))
172
+ n !== void 0 && u.searchParams.set(c, String(n));
110
173
  return u.toString();
111
174
  }
112
- async function q(t) {
113
- let e = await t.text();
114
- if (e)
175
+ async function j(e) {
176
+ let t = await e.text();
177
+ if (t)
115
178
  try {
116
- return JSON.parse(e);
179
+ return JSON.parse(t);
117
180
  } catch {
118
181
  return;
119
182
  }
120
183
  }
121
- async function b(t, e) {
122
- let r = e.method ?? "GET", d = ee(t.baseUrl, e.path, e.query), c = J.has(r) ? X : Y, u = e.retries ?? c, l = {
123
- accept: "application/json",
124
- ...e.headers
125
- }, n = M();
126
- if (n && (l["x-neetru-sdk-version"] = n), e.requireAuth) {
127
- if (!t.apiKey)
128
- throw new o(
129
- "missing_api_key",
130
- "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
131
- );
132
- l.authorization = `Bearer ${t.apiKey}`;
184
+ async function v(e, t) {
185
+ let r = t.method ?? "GET", o = de(e.baseUrl, t.path, t.query), s = oe.has(r) ? ne : re, u = t.retries ?? s, { headers: c, correlationId: n } = x(
186
+ { accept: "application/json", ...t.headers },
187
+ t.correlationId
188
+ ), g = $();
189
+ if (g && (c["x-neetru-sdk-version"] = g), t.requireAuth) {
190
+ if (!e.apiKey)
191
+ throw new i("missing_api_key", te());
192
+ c.authorization = `Bearer ${e.apiKey}`;
133
193
  }
134
- if (e.idempotencyKey) {
135
- let p = typeof e.idempotencyKey == "string" ? e.idempotencyKey : U();
136
- l["idempotency-key"] = p;
194
+ if (t.idempotencyKey) {
195
+ let p = typeof t.idempotencyKey == "string" ? t.idempotencyKey : C();
196
+ c["idempotency-key"] = p;
137
197
  }
138
- let f = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
139
- f !== void 0 && (l["content-type"] = "application/json");
140
- let i = null, s = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
198
+ let a = t.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(t.body) : void 0;
199
+ a !== void 0 && (c["content-type"] = "application/json");
200
+ let l = null, f = t.deadlineMs != null ? Date.now() + t.deadlineMs : null;
141
201
  for (let p = 0; p <= u; p++) {
142
- if (s != null && Date.now() >= s)
143
- throw i ?? new o("network_error", "Deadline excedido antes de completar a request");
144
- let g = { method: r, headers: l };
145
- f !== void 0 && (g.body = f);
146
- let F = s != null ? Math.max(1, Math.min(3e4, s - Date.now())) : 3e4;
147
- g.signal = AbortSignal.timeout(F);
202
+ if (f != null && Date.now() >= f)
203
+ throw l ?? new i(
204
+ "network_error",
205
+ "Deadline excedido antes de completar a request",
206
+ void 0,
207
+ void 0,
208
+ void 0,
209
+ n
210
+ );
211
+ let E = { method: r, headers: c };
212
+ a !== void 0 && (E.body = a);
213
+ let z = f != null ? Math.max(1, Math.min(3e4, f - Date.now())) : 3e4;
214
+ E.signal = AbortSignal.timeout(z);
148
215
  let m;
149
216
  try {
150
- m = await t.fetch(d, g);
151
- } catch (a) {
152
- let w = a instanceof DOMException && a.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${a instanceof Error ? a.message : "fetch failed"}`;
153
- if (i = new o("network_error", w), p < u) {
154
- let R = C(p);
155
- if (s == null || Date.now() + R < s) {
156
- await x(R);
217
+ m = await e.fetch(o, E);
218
+ } catch (d) {
219
+ let w = d instanceof DOMException && d.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${d instanceof Error ? d.message : "fetch failed"}`;
220
+ if (l = new i("network_error", w, void 0, void 0, void 0, n), p < u) {
221
+ let N = P(p);
222
+ if (f == null || Date.now() + N < f) {
223
+ await K(N);
157
224
  continue;
158
225
  }
159
226
  }
160
- throw i;
227
+ throw l;
161
228
  }
162
- let V = m.headers.get("x-request-id") ?? m.headers.get("x-correlation-id") ?? void 0;
229
+ let X = m.headers.get("x-request-id") ?? m.headers.get("x-correlation-id") ?? void 0;
163
230
  if (m.ok) {
164
- let a = m.headers.get("x-neetru-version");
165
- return a && B(a), await q(m);
231
+ let d = m.headers.get("x-neetru-version");
232
+ return d && ee(d), await j(m);
166
233
  }
167
- let y = await q(m), k = Z(m.status), h = `HTTP ${m.status}`, v;
234
+ let y = await j(m), k = ae(m.status), h = `HTTP ${m.status}`, S;
168
235
  if (y && typeof y == "object") {
169
- let a = y.error;
170
- typeof a == "string" ? h = a : a && typeof a == "object" ? (typeof a.code == "string" && (k = a.code), typeof a.message == "string" && (h = a.message), typeof a.reason == "string" && (v = a.reason)) : (typeof y.code == "string" && (k = y.code), typeof y.message == "string" && (h = y.message)), typeof y.reason == "string" && (v = y.reason);
236
+ let d = y.error;
237
+ typeof d == "string" ? h = d : d && typeof d == "object" ? (typeof d.code == "string" && (k = d.code), typeof d.message == "string" && (h = d.message), typeof d.reason == "string" && (S = d.reason)) : (typeof y.code == "string" && (k = y.code), typeof y.message == "string" && (h = y.message)), typeof y.reason == "string" && (S = y.reason);
171
238
  }
172
239
  if (m.status === 410) {
173
- let a = m.headers.get("x-neetru-replacement");
174
- h === `HTTP ${m.status}` && (h = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), a && !h.includes(a) && (h += ` Substituto: ${a}.`);
240
+ let d = m.headers.get("x-neetru-replacement");
241
+ h === `HTTP ${m.status}` && (h = `Endpoint ${t.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), d && !h.includes(d) && (h += ` Substituto: ${d}.`);
175
242
  }
176
- let I = new o(k, h, m.status, V, v);
177
- if (i = I, W.has(k) && p < u) {
178
- let w = Q(m.headers.get("retry-after")) ?? C(p);
179
- if (s == null || Date.now() + w < s) {
180
- await x(w);
243
+ let T = new i(k, h, m.status, X, S, n);
244
+ if (l = T, ie.has(k) && p < u) {
245
+ let w = se(m.headers.get("retry-after")) ?? P(p);
246
+ if (f == null || Date.now() + w < f) {
247
+ await K(w);
181
248
  continue;
182
249
  }
183
250
  }
184
- throw I;
251
+ throw T;
185
252
  }
186
- throw i ?? new o("unknown", "unexpected httpRequest exit");
253
+ throw l ?? new i("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, n);
187
254
  }
188
255
 
189
256
  // src/validators.ts
190
- var O = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
191
- function A(t, e) {
192
- if (typeof e != "string" || !O.test(e))
193
- throw new o(
257
+ var L = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
258
+ function I(e, t) {
259
+ if (typeof t != "string" || !L.test(t))
260
+ throw new i(
194
261
  "validation_failed",
195
- `${t} must match ${O.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
262
+ `${e} must match ${L.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
196
263
  );
197
264
  }
198
265
 
199
266
  // src/support.ts
200
- var T = ["low", "normal", "high", "urgent"], te = ["open", "pending", "resolved", "closed"], j = 50;
201
- function P(t) {
202
- if (!t || typeof t != "object")
203
- throw new o("invalid_response", "Ticket response is not an object");
204
- let e = t;
205
- if (typeof e.id != "string")
206
- throw new o("invalid_response", "Ticket missing id");
207
- let r = Array.isArray(e.attachments) && typeof e.attachments[0] == "string" ? e.attachments[0] : void 0, d = typeof e.screenshotUrl == "string" ? e.screenshotUrl : r ?? null;
267
+ var R = ["low", "normal", "high", "urgent"], ue = ["open", "pending", "resolved", "closed"], V = 50;
268
+ function F(e) {
269
+ if (!e || typeof e != "object")
270
+ throw new i("invalid_response", "Ticket response is not an object");
271
+ let t = e;
272
+ if (typeof t.id != "string")
273
+ throw new i("invalid_response", "Ticket missing id");
274
+ let r = Array.isArray(t.attachments) && typeof t.attachments[0] == "string" ? t.attachments[0] : void 0, o = typeof t.screenshotUrl == "string" ? t.screenshotUrl : r ?? null;
208
275
  return {
209
- id: e.id,
210
- subject: typeof e.subject == "string" ? e.subject : "",
211
- message: typeof e.message == "string" ? e.message : "",
212
- severity: T.includes(e.severity) ? e.severity : "normal",
213
- status: te.includes(e.status) ? e.status : "open",
214
- createdAt: typeof e.createdAt == "string" ? e.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
215
- updatedAt: typeof e.updatedAt == "string" ? e.updatedAt : void 0,
216
- productSlug: typeof e.productId == "string" ? e.productId : typeof e.productSlug == "string" ? e.productSlug : void 0,
217
- pageUrl: typeof e.pageUrl == "string" ? e.pageUrl : null,
218
- screenshotUrl: d,
276
+ id: t.id,
277
+ subject: typeof t.subject == "string" ? t.subject : "",
278
+ message: typeof t.message == "string" ? t.message : "",
279
+ severity: R.includes(t.severity) ? t.severity : "normal",
280
+ status: ue.includes(t.status) ? t.status : "open",
281
+ createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
282
+ updatedAt: typeof t.updatedAt == "string" ? t.updatedAt : void 0,
283
+ productSlug: typeof t.productId == "string" ? t.productId : typeof t.productSlug == "string" ? t.productSlug : void 0,
284
+ pageUrl: typeof t.pageUrl == "string" ? t.pageUrl : null,
285
+ screenshotUrl: o,
219
286
  // 3.7.0: a listagem do Core não traz mais `attachments` (screenshotUrl vem
220
287
  // null) — `screenshotAttached` diz se o ticket tem print. Fallback: há URL.
221
- screenshotAttached: typeof e.screenshotAttached == "boolean" ? e.screenshotAttached : d !== null,
222
- resolvedAt: typeof e.resolvedAt == "string" ? e.resolvedAt : null,
223
- resolvedNotifiedAt: typeof e.resolvedNotifiedAt == "string" ? e.resolvedNotifiedAt : null,
224
- satisfactionAttempts: typeof e.satisfactionAttempts == "number" && Number.isFinite(e.satisfactionAttempts) ? e.satisfactionAttempts : 0,
225
- lastSatisfactionAttemptAt: typeof e.lastSatisfactionAttemptAt == "string" ? e.lastSatisfactionAttemptAt : null,
226
- satisfiedAt: typeof e.satisfiedAt == "string" ? e.satisfiedAt : null,
227
- rating: typeof e.rating == "number" && Number.isFinite(e.rating) ? e.rating : null,
228
- satisfactionComment: typeof e.satisfactionComment == "string" ? e.satisfactionComment : null
288
+ screenshotAttached: typeof t.screenshotAttached == "boolean" ? t.screenshotAttached : o !== null,
289
+ resolvedAt: typeof t.resolvedAt == "string" ? t.resolvedAt : null,
290
+ resolvedNotifiedAt: typeof t.resolvedNotifiedAt == "string" ? t.resolvedNotifiedAt : null,
291
+ satisfactionAttempts: typeof t.satisfactionAttempts == "number" && Number.isFinite(t.satisfactionAttempts) ? t.satisfactionAttempts : 0,
292
+ lastSatisfactionAttemptAt: typeof t.lastSatisfactionAttemptAt == "string" ? t.lastSatisfactionAttemptAt : null,
293
+ satisfiedAt: typeof t.satisfiedAt == "string" ? t.satisfiedAt : null,
294
+ rating: typeof t.rating == "number" && Number.isFinite(t.rating) ? t.rating : null,
295
+ satisfactionComment: typeof t.satisfactionComment == "string" ? t.satisfactionComment : null
229
296
  };
230
297
  }
231
- function E(t) {
232
- if (!t || typeof t != "string")
233
- throw new o("validation_failed", "ticketId is required");
298
+ function b(e) {
299
+ if (!e || typeof e != "string")
300
+ throw new i("validation_failed", "ticketId is required");
234
301
  }
235
- function $(t) {
236
- if (typeof t == "string" && t.length > 2e3)
237
- throw new o("validation_failed", "comment max 2000 chars");
302
+ function H(e) {
303
+ if (typeof e == "string" && e.length > 2e3)
304
+ throw new i("validation_failed", "comment max 2000 chars");
238
305
  }
239
- function K(t, ...e) {
240
- for (let r of e)
306
+ function B(e, ...t) {
307
+ for (let r of t)
241
308
  if (typeof r == "string" && r.length > 0)
242
- return A("productSlug", r), r;
243
- if (t.productId)
244
- return A("productId", t.productId), t.productId;
245
- throw new o(
309
+ return I("productSlug", r), r;
310
+ if (e.productId)
311
+ return I("productId", e.productId), e.productId;
312
+ throw new i(
246
313
  "validation_failed",
247
314
  "productId required (pass to input.productSlug or set on createNeetruClient)"
248
315
  );
249
316
  }
250
- var ne = "X-Neetru-End-User-Token", re = "Esta opera\xE7\xE3o de suporte exige um usu\xE1rio final logado: o Core s\xF3 mostra/altera os tickets do pr\xF3prio usu\xE1rio (header X-Neetru-End-User-Token com o id_token OIDC). Fa\xE7a login com client.auth.signIn() e tente de novo.", oe = "O Core exige a identidade do usu\xE1rio final para esta opera\xE7\xE3o (403 end_user_token_required) e nenhum id_token foi aceito. Fa\xE7a login com client.auth.signIn() e tente de novo.", ie = "O Core recusou o token do usu\xE1rio final (401 invalid_end_user_token \u2014 sess\xE3o expirada, usu\xE1rio inativo ou token que n\xE3o \xE9 id_token) e a renova\xE7\xE3o autom\xE1tica n\xE3o resolveu. Fa\xE7a login novamente com client.auth.signIn() e tente de novo.", se = "O id_token do usu\xE1rio final foi emitido para o client OIDC de OUTRO produto (403 end_user_token_product_mismatch). Confira se o login (client.auth / clientId OIDC) e a apiKey/productId do createNeetruClient s\xE3o do MESMO produto.";
251
- function L(t) {
252
- if (t instanceof o && !(t instanceof _)) {
253
- if (t.code === "end_user_token_required")
317
+ var ce = "X-Neetru-End-User-Token", le = "Esta opera\xE7\xE3o de suporte exige um usu\xE1rio final logado: o Core s\xF3 mostra/altera os tickets do pr\xF3prio usu\xE1rio (header X-Neetru-End-User-Token com o id_token OIDC). Fa\xE7a login com client.auth.signIn() e tente de novo.", fe = "O Core exige a identidade do usu\xE1rio final para esta opera\xE7\xE3o (403 end_user_token_required) e nenhum id_token foi aceito. Fa\xE7a login com client.auth.signIn() e tente de novo.", pe = "O Core recusou o token do usu\xE1rio final (401 invalid_end_user_token \u2014 sess\xE3o expirada, usu\xE1rio inativo ou token que n\xE3o \xE9 id_token) e a renova\xE7\xE3o autom\xE1tica n\xE3o resolveu. Fa\xE7a login novamente com client.auth.signIn() e tente de novo.", me = "O id_token do usu\xE1rio final foi emitido para o client OIDC de OUTRO produto (403 end_user_token_product_mismatch). Confira se o login (client.auth / clientId OIDC) e a apiKey/productId do createNeetruClient s\xE3o do MESMO produto.";
318
+ function G(e) {
319
+ if (e instanceof i && !(e instanceof _)) {
320
+ if (e.code === "end_user_token_required")
254
321
  throw new _(
255
- oe,
322
+ fe,
256
323
  "end_user_token_required",
257
- t.status,
258
- t.requestId
324
+ e.status,
325
+ e.requestId,
326
+ e.correlationId
259
327
  );
260
- if (t.code === "invalid_end_user_token")
328
+ if (e.code === "invalid_end_user_token")
261
329
  throw new _(
262
- ie,
330
+ pe,
263
331
  "invalid_end_user_token",
264
- t.status,
265
- t.requestId
332
+ e.status,
333
+ e.requestId,
334
+ e.correlationId
266
335
  );
267
- if (t.code === "end_user_token_product_mismatch")
268
- throw new o(
336
+ if (e.code === "end_user_token_product_mismatch")
337
+ throw new i(
269
338
  "forbidden",
270
- se,
271
- t.status,
272
- t.requestId,
273
- "end_user_token_product_mismatch"
339
+ me,
340
+ e.status,
341
+ e.requestId,
342
+ "end_user_token_product_mismatch",
343
+ e.correlationId
274
344
  );
275
345
  }
276
- throw t;
346
+ throw e;
277
347
  }
278
- function ae(t) {
279
- return t instanceof o && t.code === "invalid_end_user_token";
348
+ function ge(e) {
349
+ return e instanceof i && e.code === "invalid_end_user_token";
280
350
  }
281
- function ke(t, e = {}) {
282
- function r() {
351
+ function Ue(e, t = {}) {
352
+ async function r() {
283
353
  try {
284
- let n = e.getEndUserToken?.();
354
+ let n = await t.getEndUserToken?.();
285
355
  return typeof n == "string" && n.length > 0 ? n : null;
286
356
  } catch {
287
357
  return null;
288
358
  }
289
359
  }
290
- async function d() {
291
- if (!e.refreshEndUserToken) return false;
360
+ async function o() {
361
+ if (!t.refreshEndUserToken) return false;
292
362
  try {
293
- return await e.refreshEndUserToken() === !0;
363
+ return await t.refreshEndUserToken() === !0;
294
364
  } catch {
295
365
  return false;
296
366
  }
297
367
  }
298
- function c(n) {
299
- return n ? { [ne]: n } : {};
368
+ function s(n) {
369
+ return n ? { [ce]: n } : {};
300
370
  }
301
- async function u(n, f) {
302
- let i = r();
303
- if (!i && n && await d() && (i = r()), !i && n)
304
- throw new _(re, "no_signed_in_user");
371
+ async function u(n, g) {
372
+ let a = await r();
373
+ if (!a && n && await o() && (a = await r()), !a && n)
374
+ throw new _(le, "no_signed_in_user");
305
375
  try {
306
- return await f(c(i));
307
- } catch (s) {
308
- if (i && ae(s) && await d()) {
309
- let p = r();
310
- if (p)
376
+ return await g(s(a));
377
+ } catch (l) {
378
+ if (a && ge(l) && await o()) {
379
+ let f = await r();
380
+ if (f)
311
381
  try {
312
- return await f(c(p));
313
- } catch (g) {
314
- L(g);
382
+ return await g(s(f));
383
+ } catch (p) {
384
+ G(p);
315
385
  }
316
386
  }
317
- L(s);
387
+ G(l);
318
388
  }
319
389
  }
320
- async function l(n, f = {}) {
390
+ async function c(n, g = {}) {
321
391
  await u(
322
392
  true,
323
- (i) => b(t, {
393
+ (a) => v(e, {
324
394
  method: "POST",
325
395
  path: n,
326
396
  requireAuth: !0,
327
- headers: i,
328
- ...f
397
+ headers: a,
398
+ ...g
329
399
  })
330
400
  );
331
401
  }
@@ -338,39 +408,39 @@ function ke(t, e = {}) {
338
408
  */
339
409
  async createTicket(n) {
340
410
  if (!n || typeof n != "object")
341
- throw new o("validation_failed", "input is required");
411
+ throw new i("validation_failed", "input is required");
342
412
  if (!n.subject || typeof n.subject != "string")
343
- throw new o("validation_failed", "subject is required");
413
+ throw new i("validation_failed", "subject is required");
344
414
  if (n.subject.length > 200)
345
- throw new o("validation_failed", "subject max 200 chars");
415
+ throw new i("validation_failed", "subject max 200 chars");
346
416
  if (!n.message || typeof n.message != "string")
347
- throw new o("validation_failed", "message is required");
417
+ throw new i("validation_failed", "message is required");
348
418
  if (n.message.length > 1e4)
349
- throw new o("validation_failed", "message max 10000 chars");
350
- if (n.severity && !T.includes(n.severity))
351
- throw new o(
419
+ throw new i("validation_failed", "message max 10000 chars");
420
+ if (n.severity && !R.includes(n.severity))
421
+ throw new i(
352
422
  "validation_failed",
353
- `severity must be one of ${T.join(", ")}`
423
+ `severity must be one of ${R.join(", ")}`
354
424
  );
355
- let i = {
356
- productId: K(t, n.productSlug),
425
+ let a = {
426
+ productId: B(e, n.productSlug),
357
427
  subject: n.subject,
358
428
  message: n.message,
359
429
  severity: n.severity ?? "normal"
360
430
  };
361
- n.metadata && typeof n.metadata == "object" && (i.metadata = n.metadata), typeof n.pageUrl == "string" && (i.pageUrl = n.pageUrl), typeof n.screenshotBase64 == "string" && (i.screenshotBase64 = n.screenshotBase64), typeof n.consoleLogs == "string" && (i.consoleLogs = n.consoleLogs);
362
- let s = await u(
431
+ n.metadata && typeof n.metadata == "object" && (a.metadata = n.metadata), typeof n.pageUrl == "string" && (a.pageUrl = n.pageUrl), typeof n.screenshotBase64 == "string" && (a.screenshotBase64 = n.screenshotBase64), typeof n.consoleLogs == "string" && (a.consoleLogs = n.consoleLogs);
432
+ let l = await u(
363
433
  false,
364
- (g) => b(t, {
434
+ (p) => v(e, {
365
435
  method: "POST",
366
436
  path: "/api/sdk/v1/support/tickets",
367
- body: i,
437
+ body: a,
368
438
  requireAuth: !0,
369
439
  idempotencyKey: !0,
370
- headers: g
440
+ headers: p
371
441
  })
372
- ), p = s && typeof s == "object" && "ticket" in s ? s.ticket : s;
373
- return P(p);
442
+ ), f = l && typeof l == "object" && "ticket" in l ? l.ticket : l;
443
+ return F(f);
374
444
  },
375
445
  /**
376
446
  * Lista tickets do customer no produto atual. `productSlug` no contexto.
@@ -378,23 +448,23 @@ function ke(t, e = {}) {
378
448
  * Endpoint canonical: `GET /api/sdk/v1/support/tickets?productId=...`.
379
449
  */
380
450
  async listMyTickets(n) {
381
- let f = K(t, n?.productSlug), i = n?.limit;
382
- if (i !== void 0 && (!Number.isInteger(i) || i < 1 || i > j))
383
- throw new o(
451
+ let g = B(e, n?.productSlug), a = n?.limit;
452
+ if (a !== void 0 && (!Number.isInteger(a) || a < 1 || a > V))
453
+ throw new i(
384
454
  "validation_failed",
385
- `limit must be an integer 1-${j} (Core default 20)`
455
+ `limit must be an integer 1-${V} (Core default 20)`
386
456
  );
387
- let s = await u(
457
+ let l = await u(
388
458
  true,
389
- (g) => b(t, {
459
+ (p) => v(e, {
390
460
  method: "GET",
391
461
  path: "/api/sdk/v1/support/tickets",
392
- query: { productId: f, limit: i },
462
+ query: { productId: g, limit: a },
393
463
  requireAuth: !0,
394
- headers: g
464
+ headers: p
395
465
  })
396
466
  );
397
- return (Array.isArray(s) ? s : s && typeof s == "object" && "tickets" in s ? s.tickets ?? [] : []).map(P);
467
+ return (Array.isArray(l) ? l : l && typeof l == "object" && "tickets" in l ? l.tickets ?? [] : []).map(F);
398
468
  },
399
469
  /**
400
470
  * 3.4: marca a notificação de resolução como vista (`resolvedNotifiedAt`,
@@ -402,7 +472,7 @@ function ke(t, e = {}) {
402
472
  * `POST /api/sdk/v1/support/tickets/{id}/resolved-seen`.
403
473
  */
404
474
  async markResolvedSeen(n) {
405
- E(n), await l(
475
+ b(n), await c(
406
476
  `/api/sdk/v1/support/tickets/${encodeURIComponent(n)}/resolved-seen`
407
477
  );
408
478
  },
@@ -413,7 +483,7 @@ function ke(t, e = {}) {
413
483
  * `POST /api/sdk/v1/support/tickets/{id}/satisfaction-attempt`.
414
484
  */
415
485
  async recordSatisfactionAttempt(n) {
416
- E(n), await l(
486
+ b(n), await c(
417
487
  `/api/sdk/v1/support/tickets/${encodeURIComponent(n)}/satisfaction-attempt`,
418
488
  // Incrementa satisfactionAttempts += 1 no Core — sem idempotencyKey,
419
489
  // um retry de rede infla o contador (mesmo padrão de createTicket acima).
@@ -426,10 +496,10 @@ function ke(t, e = {}) {
426
496
  */
427
497
  async submitSatisfaction(n) {
428
498
  if (!n || typeof n != "object")
429
- throw new o("validation_failed", "input is required");
430
- if (E(n.ticketId), n.rating !== null && n.rating !== void 0 && (!Number.isInteger(n.rating) || n.rating < 1 || n.rating > 5))
431
- throw new o("validation_failed", "rating must be an integer 1-5 or null");
432
- $(n.comment), await l(
499
+ throw new i("validation_failed", "input is required");
500
+ if (b(n.ticketId), n.rating !== null && n.rating !== void 0 && (!Number.isInteger(n.rating) || n.rating < 1 || n.rating > 5))
501
+ throw new i("validation_failed", "rating must be an integer 1-5 or null");
502
+ H(n.comment), await c(
433
503
  `/api/sdk/v1/support/tickets/${encodeURIComponent(n.ticketId)}/satisfaction`,
434
504
  {
435
505
  body: {
@@ -445,14 +515,14 @@ function ke(t, e = {}) {
445
515
  * satisfação/notificação. Endpoint canonical:
446
516
  * `POST /api/sdk/v1/support/tickets/{id}/contest`.
447
517
  */
448
- async contestTicket(n, f) {
449
- E(n), $(f?.comment), await l(
518
+ async contestTicket(n, g) {
519
+ b(n), H(g?.comment), await c(
450
520
  `/api/sdk/v1/support/tickets/${encodeURIComponent(n)}/contest`,
451
- { body: { comment: f?.comment ?? void 0 } }
521
+ { body: { comment: g?.comment ?? void 0 } }
452
522
  );
453
523
  }
454
524
  };
455
525
  }
456
526
 
457
- exports.END_USER_TOKEN_HEADER = ne;
458
- exports.createSupportNamespace = ke;
527
+ exports.END_USER_TOKEN_HEADER = ce;
528
+ exports.createSupportNamespace = Ue;