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