@neetru/sdk 3.7.0 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +75 -0
- package/README.md +66 -1
- package/dist/ai.cjs +221 -177
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +221 -177
- package/dist/auth.cjs +1051 -868
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +1048 -865
- package/dist/catalog.cjs +164 -97
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +164 -97
- package/dist/checkout.cjs +182 -115
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +181 -114
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +437 -345
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +455 -363
- package/dist/entitlements.cjs +17 -10
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +17 -10
- package/dist/errors.cjs +15 -8
- package/dist/errors.d.cts +24 -3
- package/dist/errors.d.ts +24 -3
- package/dist/errors.mjs +14 -7
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +1544 -1190
- package/dist/index.d.cts +177 -3
- package/dist/index.d.ts +177 -3
- package/dist/index.mjs +1676 -1329
- package/dist/mobile.cjs +400 -181
- package/dist/mobile.d.cts +59 -4
- package/dist/mobile.d.ts +59 -4
- package/dist/mobile.mjs +400 -181
- package/dist/mocks.cjs +9 -2
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs +9 -2
- package/dist/notifications.cjs +197 -130
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +196 -129
- package/dist/react.cjs +303 -282
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +295 -274
- package/dist/support.cjs +299 -229
- package/dist/support.d.cts +8 -4
- package/dist/support.d.ts +8 -4
- package/dist/support.mjs +298 -228
- package/dist/telemetry.cjs +234 -167
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +234 -167
- package/dist/{types-Dx0IrOSF.d.ts → types-BYPk_3HR.d.ts} +104 -17
- package/dist/{types-Bx4kTLmk.d.cts → types-yv3EDKg2.d.cts} +104 -17
- package/dist/usage.cjs +183 -116
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +183 -116
- package/dist/webhooks.cjs +215 -148
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +212 -145
- 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
|
|
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
|
-
|
|
18
|
-
|
|
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
|
|
21
|
-
constructor(
|
|
22
|
-
super("auth_required",
|
|
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
|
|
28
|
-
let
|
|
29
|
-
if (
|
|
30
|
-
return
|
|
31
|
-
throw new
|
|
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
|
|
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
|
|
44
|
-
return
|
|
102
|
+
function A(e) {
|
|
103
|
+
return e.split("+")[0] ?? e;
|
|
45
104
|
}
|
|
46
|
-
function
|
|
47
|
-
let r =
|
|
48
|
-
for (let u = 0; u <
|
|
49
|
-
let
|
|
50
|
-
if (
|
|
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
|
|
113
|
+
function $() {
|
|
55
114
|
try {
|
|
56
|
-
return "3.
|
|
115
|
+
return "3.8.1";
|
|
57
116
|
} catch {
|
|
58
117
|
return;
|
|
59
118
|
}
|
|
60
119
|
}
|
|
61
|
-
function
|
|
62
|
-
let
|
|
63
|
-
return
|
|
120
|
+
function Z() {
|
|
121
|
+
let e = $();
|
|
122
|
+
return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
|
|
64
123
|
}
|
|
65
|
-
var
|
|
66
|
-
function
|
|
67
|
-
if (!
|
|
68
|
-
let
|
|
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
|
|
71
|
-
if (
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${
|
|
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
|
-
|
|
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
|
|
84
|
-
let
|
|
85
|
-
return Math.max(50, Math.round(
|
|
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
|
|
88
|
-
function
|
|
89
|
-
if (!
|
|
90
|
-
let
|
|
91
|
-
if (Number.isFinite(
|
|
92
|
-
let r = Date.parse(
|
|
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
|
|
95
|
-
if (
|
|
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
|
|
100
|
-
return new Promise((
|
|
162
|
+
function K(e) {
|
|
163
|
+
return new Promise((t) => setTimeout(t, e));
|
|
101
164
|
}
|
|
102
|
-
function
|
|
103
|
-
return
|
|
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
|
|
106
|
-
let
|
|
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 [
|
|
109
|
-
n !== void 0 && u.searchParams.set(
|
|
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
|
|
113
|
-
let
|
|
114
|
-
if (
|
|
175
|
+
async function j(e) {
|
|
176
|
+
let t = await e.text();
|
|
177
|
+
if (t)
|
|
115
178
|
try {
|
|
116
|
-
return JSON.parse(
|
|
179
|
+
return JSON.parse(t);
|
|
117
180
|
} catch {
|
|
118
181
|
return;
|
|
119
182
|
}
|
|
120
183
|
}
|
|
121
|
-
async function
|
|
122
|
-
let r =
|
|
123
|
-
accept: "application/json",
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
if (!
|
|
128
|
-
throw new
|
|
129
|
-
|
|
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 (
|
|
135
|
-
let p = typeof
|
|
136
|
-
|
|
194
|
+
if (t.idempotencyKey) {
|
|
195
|
+
let p = typeof t.idempotencyKey == "string" ? t.idempotencyKey : C();
|
|
196
|
+
c["idempotency-key"] = p;
|
|
137
197
|
}
|
|
138
|
-
let
|
|
139
|
-
|
|
140
|
-
let
|
|
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 (
|
|
143
|
-
throw
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
151
|
-
} catch (
|
|
152
|
-
let w =
|
|
153
|
-
if (
|
|
154
|
-
let
|
|
155
|
-
if (
|
|
156
|
-
await
|
|
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
|
|
227
|
+
throw l;
|
|
161
228
|
}
|
|
162
|
-
let
|
|
229
|
+
let X = m.headers.get("x-request-id") ?? m.headers.get("x-correlation-id") ?? void 0;
|
|
163
230
|
if (m.ok) {
|
|
164
|
-
let
|
|
165
|
-
return
|
|
231
|
+
let d = m.headers.get("x-neetru-version");
|
|
232
|
+
return d && ee(d), await j(m);
|
|
166
233
|
}
|
|
167
|
-
let y = await
|
|
234
|
+
let y = await j(m), k = ae(m.status), h = `HTTP ${m.status}`, S;
|
|
168
235
|
if (y && typeof y == "object") {
|
|
169
|
-
let
|
|
170
|
-
typeof
|
|
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
|
|
174
|
-
h === `HTTP ${m.status}` && (h = `Endpoint ${
|
|
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
|
|
177
|
-
if (
|
|
178
|
-
let w =
|
|
179
|
-
if (
|
|
180
|
-
await
|
|
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
|
|
251
|
+
throw T;
|
|
185
252
|
}
|
|
186
|
-
throw
|
|
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
|
|
191
|
-
function
|
|
192
|
-
if (typeof
|
|
193
|
-
throw new
|
|
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
|
-
`${
|
|
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
|
|
201
|
-
function
|
|
202
|
-
if (!
|
|
203
|
-
throw new
|
|
204
|
-
let
|
|
205
|
-
if (typeof
|
|
206
|
-
throw new
|
|
207
|
-
let r = Array.isArray(
|
|
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:
|
|
210
|
-
subject: typeof
|
|
211
|
-
message: typeof
|
|
212
|
-
severity:
|
|
213
|
-
status:
|
|
214
|
-
createdAt: typeof
|
|
215
|
-
updatedAt: typeof
|
|
216
|
-
productSlug: typeof
|
|
217
|
-
pageUrl: typeof
|
|
218
|
-
screenshotUrl:
|
|
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
|
|
222
|
-
resolvedAt: typeof
|
|
223
|
-
resolvedNotifiedAt: typeof
|
|
224
|
-
satisfactionAttempts: typeof
|
|
225
|
-
lastSatisfactionAttemptAt: typeof
|
|
226
|
-
satisfiedAt: typeof
|
|
227
|
-
rating: typeof
|
|
228
|
-
satisfactionComment: typeof
|
|
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
|
|
232
|
-
if (!
|
|
233
|
-
throw new
|
|
298
|
+
function b(e) {
|
|
299
|
+
if (!e || typeof e != "string")
|
|
300
|
+
throw new i("validation_failed", "ticketId is required");
|
|
234
301
|
}
|
|
235
|
-
function
|
|
236
|
-
if (typeof
|
|
237
|
-
throw new
|
|
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
|
|
240
|
-
for (let r of
|
|
306
|
+
function B(e, ...t) {
|
|
307
|
+
for (let r of t)
|
|
241
308
|
if (typeof r == "string" && r.length > 0)
|
|
242
|
-
return
|
|
243
|
-
if (
|
|
244
|
-
return
|
|
245
|
-
throw new
|
|
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
|
|
251
|
-
function
|
|
252
|
-
if (
|
|
253
|
-
if (
|
|
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
|
-
|
|
322
|
+
fe,
|
|
256
323
|
"end_user_token_required",
|
|
257
|
-
|
|
258
|
-
|
|
324
|
+
e.status,
|
|
325
|
+
e.requestId,
|
|
326
|
+
e.correlationId
|
|
259
327
|
);
|
|
260
|
-
if (
|
|
328
|
+
if (e.code === "invalid_end_user_token")
|
|
261
329
|
throw new _(
|
|
262
|
-
|
|
330
|
+
pe,
|
|
263
331
|
"invalid_end_user_token",
|
|
264
|
-
|
|
265
|
-
|
|
332
|
+
e.status,
|
|
333
|
+
e.requestId,
|
|
334
|
+
e.correlationId
|
|
266
335
|
);
|
|
267
|
-
if (
|
|
268
|
-
throw new
|
|
336
|
+
if (e.code === "end_user_token_product_mismatch")
|
|
337
|
+
throw new i(
|
|
269
338
|
"forbidden",
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
|
346
|
+
throw e;
|
|
277
347
|
}
|
|
278
|
-
function
|
|
279
|
-
return
|
|
348
|
+
function ge(e) {
|
|
349
|
+
return e instanceof i && e.code === "invalid_end_user_token";
|
|
280
350
|
}
|
|
281
|
-
function
|
|
282
|
-
function r() {
|
|
351
|
+
function Ue(e, t = {}) {
|
|
352
|
+
async function r() {
|
|
283
353
|
try {
|
|
284
|
-
let n =
|
|
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
|
|
291
|
-
if (!
|
|
360
|
+
async function o() {
|
|
361
|
+
if (!t.refreshEndUserToken) return false;
|
|
292
362
|
try {
|
|
293
|
-
return await
|
|
363
|
+
return await t.refreshEndUserToken() === !0;
|
|
294
364
|
} catch {
|
|
295
365
|
return false;
|
|
296
366
|
}
|
|
297
367
|
}
|
|
298
|
-
function
|
|
299
|
-
return n ? { [
|
|
368
|
+
function s(n) {
|
|
369
|
+
return n ? { [ce]: n } : {};
|
|
300
370
|
}
|
|
301
|
-
async function u(n,
|
|
302
|
-
let
|
|
303
|
-
if (!
|
|
304
|
-
throw new _(
|
|
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
|
|
307
|
-
} catch (
|
|
308
|
-
if (
|
|
309
|
-
let
|
|
310
|
-
if (
|
|
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
|
|
313
|
-
} catch (
|
|
314
|
-
|
|
382
|
+
return await g(s(f));
|
|
383
|
+
} catch (p) {
|
|
384
|
+
G(p);
|
|
315
385
|
}
|
|
316
386
|
}
|
|
317
|
-
|
|
387
|
+
G(l);
|
|
318
388
|
}
|
|
319
389
|
}
|
|
320
|
-
async function
|
|
390
|
+
async function c(n, g = {}) {
|
|
321
391
|
await u(
|
|
322
392
|
true,
|
|
323
|
-
(
|
|
393
|
+
(a) => v(e, {
|
|
324
394
|
method: "POST",
|
|
325
395
|
path: n,
|
|
326
396
|
requireAuth: !0,
|
|
327
|
-
headers:
|
|
328
|
-
...
|
|
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
|
|
411
|
+
throw new i("validation_failed", "input is required");
|
|
342
412
|
if (!n.subject || typeof n.subject != "string")
|
|
343
|
-
throw new
|
|
413
|
+
throw new i("validation_failed", "subject is required");
|
|
344
414
|
if (n.subject.length > 200)
|
|
345
|
-
throw new
|
|
415
|
+
throw new i("validation_failed", "subject max 200 chars");
|
|
346
416
|
if (!n.message || typeof n.message != "string")
|
|
347
|
-
throw new
|
|
417
|
+
throw new i("validation_failed", "message is required");
|
|
348
418
|
if (n.message.length > 1e4)
|
|
349
|
-
throw new
|
|
350
|
-
if (n.severity && !
|
|
351
|
-
throw new
|
|
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 ${
|
|
423
|
+
`severity must be one of ${R.join(", ")}`
|
|
354
424
|
);
|
|
355
|
-
let
|
|
356
|
-
productId:
|
|
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" && (
|
|
362
|
-
let
|
|
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
|
-
(
|
|
434
|
+
(p) => v(e, {
|
|
365
435
|
method: "POST",
|
|
366
436
|
path: "/api/sdk/v1/support/tickets",
|
|
367
|
-
body:
|
|
437
|
+
body: a,
|
|
368
438
|
requireAuth: !0,
|
|
369
439
|
idempotencyKey: !0,
|
|
370
|
-
headers:
|
|
440
|
+
headers: p
|
|
371
441
|
})
|
|
372
|
-
),
|
|
373
|
-
return
|
|
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
|
|
382
|
-
if (
|
|
383
|
-
throw new
|
|
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-${
|
|
455
|
+
`limit must be an integer 1-${V} (Core default 20)`
|
|
386
456
|
);
|
|
387
|
-
let
|
|
457
|
+
let l = await u(
|
|
388
458
|
true,
|
|
389
|
-
(
|
|
459
|
+
(p) => v(e, {
|
|
390
460
|
method: "GET",
|
|
391
461
|
path: "/api/sdk/v1/support/tickets",
|
|
392
|
-
query: { productId:
|
|
462
|
+
query: { productId: g, limit: a },
|
|
393
463
|
requireAuth: !0,
|
|
394
|
-
headers:
|
|
464
|
+
headers: p
|
|
395
465
|
})
|
|
396
466
|
);
|
|
397
|
-
return (Array.isArray(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
430
|
-
if (
|
|
431
|
-
throw new
|
|
432
|
-
|
|
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,
|
|
449
|
-
|
|
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:
|
|
521
|
+
{ body: { comment: g?.comment ?? void 0 } }
|
|
452
522
|
);
|
|
453
523
|
}
|
|
454
524
|
};
|
|
455
525
|
}
|
|
456
526
|
|
|
457
|
-
exports.END_USER_TOKEN_HEADER =
|
|
458
|
-
exports.createSupportNamespace =
|
|
527
|
+
exports.END_USER_TOKEN_HEADER = ce;
|
|
528
|
+
exports.createSupportNamespace = Ue;
|