@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.
- package/CHANGELOG.md +55 -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 +1227 -1064
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +1224 -1061
- 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 +370 -298
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +362 -290
- 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 +1409 -1075
- package/dist/index.d.cts +177 -3
- package/dist/index.d.ts +177 -3
- package/dist/index.mjs +1544 -1217
- 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-Bx4kTLmk.d.cts → types-D-9bjlM0.d.cts} +48 -1
- package/dist/{types-Dx0IrOSF.d.ts → types-bVztFQTI.d.ts} +48 -1
- 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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
|
-
var
|
|
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
|
-
|
|
16
|
-
|
|
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
|
|
19
|
-
constructor(
|
|
20
|
-
super("auth_required",
|
|
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
|
|
26
|
-
let
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
29
|
-
throw new
|
|
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
|
|
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
|
|
42
|
-
return
|
|
100
|
+
function A(e) {
|
|
101
|
+
return e.split("+")[0] ?? e;
|
|
43
102
|
}
|
|
44
|
-
function
|
|
45
|
-
let r =
|
|
46
|
-
for (let u = 0; u <
|
|
47
|
-
let
|
|
48
|
-
if (
|
|
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
|
|
111
|
+
function $() {
|
|
53
112
|
try {
|
|
54
|
-
return "3.
|
|
113
|
+
return "3.8.0";
|
|
55
114
|
} catch {
|
|
56
115
|
return;
|
|
57
116
|
}
|
|
58
117
|
}
|
|
59
|
-
function
|
|
60
|
-
let
|
|
61
|
-
return
|
|
118
|
+
function Z() {
|
|
119
|
+
let e = $();
|
|
120
|
+
return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
|
|
62
121
|
}
|
|
63
|
-
var
|
|
64
|
-
function
|
|
65
|
-
if (!
|
|
66
|
-
let
|
|
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
|
|
69
|
-
if (
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${
|
|
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
|
-
|
|
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
|
|
82
|
-
let
|
|
83
|
-
return Math.max(50, Math.round(
|
|
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
|
|
86
|
-
function
|
|
87
|
-
if (!
|
|
88
|
-
let
|
|
89
|
-
if (Number.isFinite(
|
|
90
|
-
let r = Date.parse(
|
|
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
|
|
93
|
-
if (
|
|
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
|
|
98
|
-
return new Promise((
|
|
160
|
+
function K(e) {
|
|
161
|
+
return new Promise((t) => setTimeout(t, e));
|
|
99
162
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
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
|
|
104
|
-
let
|
|
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 [
|
|
107
|
-
n !== void 0 && u.searchParams.set(
|
|
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
|
|
111
|
-
let
|
|
112
|
-
if (
|
|
173
|
+
async function j(e) {
|
|
174
|
+
let t = await e.text();
|
|
175
|
+
if (t)
|
|
113
176
|
try {
|
|
114
|
-
return JSON.parse(
|
|
177
|
+
return JSON.parse(t);
|
|
115
178
|
} catch {
|
|
116
179
|
return;
|
|
117
180
|
}
|
|
118
181
|
}
|
|
119
|
-
async function
|
|
120
|
-
let r =
|
|
121
|
-
accept: "application/json",
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
if (!
|
|
126
|
-
throw new
|
|
127
|
-
|
|
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 (
|
|
133
|
-
let p = typeof
|
|
134
|
-
|
|
192
|
+
if (t.idempotencyKey) {
|
|
193
|
+
let p = typeof t.idempotencyKey == "string" ? t.idempotencyKey : C();
|
|
194
|
+
c["idempotency-key"] = p;
|
|
135
195
|
}
|
|
136
|
-
let
|
|
137
|
-
|
|
138
|
-
let
|
|
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 (
|
|
141
|
-
throw
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
149
|
-
} catch (
|
|
150
|
-
let w =
|
|
151
|
-
if (
|
|
152
|
-
let
|
|
153
|
-
if (
|
|
154
|
-
await
|
|
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
|
|
225
|
+
throw l;
|
|
159
226
|
}
|
|
160
|
-
let
|
|
227
|
+
let X = m.headers.get("x-request-id") ?? m.headers.get("x-correlation-id") ?? void 0;
|
|
161
228
|
if (m.ok) {
|
|
162
|
-
let
|
|
163
|
-
return
|
|
229
|
+
let d = m.headers.get("x-neetru-version");
|
|
230
|
+
return d && ee(d), await j(m);
|
|
164
231
|
}
|
|
165
|
-
let y = await
|
|
232
|
+
let y = await j(m), k = ae(m.status), h = `HTTP ${m.status}`, S;
|
|
166
233
|
if (y && typeof y == "object") {
|
|
167
|
-
let
|
|
168
|
-
typeof
|
|
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
|
|
172
|
-
h === `HTTP ${m.status}` && (h = `Endpoint ${
|
|
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
|
|
175
|
-
if (
|
|
176
|
-
let w =
|
|
177
|
-
if (
|
|
178
|
-
await
|
|
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
|
|
249
|
+
throw T;
|
|
183
250
|
}
|
|
184
|
-
throw
|
|
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
|
|
189
|
-
function
|
|
190
|
-
if (typeof
|
|
191
|
-
throw new
|
|
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
|
-
`${
|
|
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
|
|
199
|
-
function
|
|
200
|
-
if (!
|
|
201
|
-
throw new
|
|
202
|
-
let
|
|
203
|
-
if (typeof
|
|
204
|
-
throw new
|
|
205
|
-
let r = Array.isArray(
|
|
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:
|
|
208
|
-
subject: typeof
|
|
209
|
-
message: typeof
|
|
210
|
-
severity:
|
|
211
|
-
status:
|
|
212
|
-
createdAt: typeof
|
|
213
|
-
updatedAt: typeof
|
|
214
|
-
productSlug: typeof
|
|
215
|
-
pageUrl: typeof
|
|
216
|
-
screenshotUrl:
|
|
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
|
|
220
|
-
resolvedAt: typeof
|
|
221
|
-
resolvedNotifiedAt: typeof
|
|
222
|
-
satisfactionAttempts: typeof
|
|
223
|
-
lastSatisfactionAttemptAt: typeof
|
|
224
|
-
satisfiedAt: typeof
|
|
225
|
-
rating: typeof
|
|
226
|
-
satisfactionComment: typeof
|
|
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
|
|
230
|
-
if (!
|
|
231
|
-
throw new
|
|
296
|
+
function b(e) {
|
|
297
|
+
if (!e || typeof e != "string")
|
|
298
|
+
throw new i("validation_failed", "ticketId is required");
|
|
232
299
|
}
|
|
233
|
-
function
|
|
234
|
-
if (typeof
|
|
235
|
-
throw new
|
|
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
|
|
238
|
-
for (let r of
|
|
304
|
+
function B(e, ...t) {
|
|
305
|
+
for (let r of t)
|
|
239
306
|
if (typeof r == "string" && r.length > 0)
|
|
240
|
-
return
|
|
241
|
-
if (
|
|
242
|
-
return
|
|
243
|
-
throw new
|
|
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
|
|
249
|
-
function
|
|
250
|
-
if (
|
|
251
|
-
if (
|
|
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
|
-
|
|
320
|
+
fe,
|
|
254
321
|
"end_user_token_required",
|
|
255
|
-
|
|
256
|
-
|
|
322
|
+
e.status,
|
|
323
|
+
e.requestId,
|
|
324
|
+
e.correlationId
|
|
257
325
|
);
|
|
258
|
-
if (
|
|
326
|
+
if (e.code === "invalid_end_user_token")
|
|
259
327
|
throw new _(
|
|
260
|
-
|
|
328
|
+
pe,
|
|
261
329
|
"invalid_end_user_token",
|
|
262
|
-
|
|
263
|
-
|
|
330
|
+
e.status,
|
|
331
|
+
e.requestId,
|
|
332
|
+
e.correlationId
|
|
264
333
|
);
|
|
265
|
-
if (
|
|
266
|
-
throw new
|
|
334
|
+
if (e.code === "end_user_token_product_mismatch")
|
|
335
|
+
throw new i(
|
|
267
336
|
"forbidden",
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
|
344
|
+
throw e;
|
|
275
345
|
}
|
|
276
|
-
function
|
|
277
|
-
return
|
|
346
|
+
function ge(e) {
|
|
347
|
+
return e instanceof i && e.code === "invalid_end_user_token";
|
|
278
348
|
}
|
|
279
|
-
function
|
|
280
|
-
function r() {
|
|
349
|
+
function Ue(e, t = {}) {
|
|
350
|
+
async function r() {
|
|
281
351
|
try {
|
|
282
|
-
let n =
|
|
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
|
|
289
|
-
if (!
|
|
358
|
+
async function o() {
|
|
359
|
+
if (!t.refreshEndUserToken) return false;
|
|
290
360
|
try {
|
|
291
|
-
return await
|
|
361
|
+
return await t.refreshEndUserToken() === !0;
|
|
292
362
|
} catch {
|
|
293
363
|
return false;
|
|
294
364
|
}
|
|
295
365
|
}
|
|
296
|
-
function
|
|
297
|
-
return n ? { [
|
|
366
|
+
function s(n) {
|
|
367
|
+
return n ? { [ce]: n } : {};
|
|
298
368
|
}
|
|
299
|
-
async function u(n,
|
|
300
|
-
let
|
|
301
|
-
if (!
|
|
302
|
-
throw new _(
|
|
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
|
|
305
|
-
} catch (
|
|
306
|
-
if (
|
|
307
|
-
let
|
|
308
|
-
if (
|
|
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
|
|
311
|
-
} catch (
|
|
312
|
-
|
|
380
|
+
return await g(s(f));
|
|
381
|
+
} catch (p) {
|
|
382
|
+
G(p);
|
|
313
383
|
}
|
|
314
384
|
}
|
|
315
|
-
|
|
385
|
+
G(l);
|
|
316
386
|
}
|
|
317
387
|
}
|
|
318
|
-
async function
|
|
388
|
+
async function c(n, g = {}) {
|
|
319
389
|
await u(
|
|
320
390
|
true,
|
|
321
|
-
(
|
|
391
|
+
(a) => v(e, {
|
|
322
392
|
method: "POST",
|
|
323
393
|
path: n,
|
|
324
394
|
requireAuth: !0,
|
|
325
|
-
headers:
|
|
326
|
-
...
|
|
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
|
|
409
|
+
throw new i("validation_failed", "input is required");
|
|
340
410
|
if (!n.subject || typeof n.subject != "string")
|
|
341
|
-
throw new
|
|
411
|
+
throw new i("validation_failed", "subject is required");
|
|
342
412
|
if (n.subject.length > 200)
|
|
343
|
-
throw new
|
|
413
|
+
throw new i("validation_failed", "subject max 200 chars");
|
|
344
414
|
if (!n.message || typeof n.message != "string")
|
|
345
|
-
throw new
|
|
415
|
+
throw new i("validation_failed", "message is required");
|
|
346
416
|
if (n.message.length > 1e4)
|
|
347
|
-
throw new
|
|
348
|
-
if (n.severity && !
|
|
349
|
-
throw new
|
|
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 ${
|
|
421
|
+
`severity must be one of ${R.join(", ")}`
|
|
352
422
|
);
|
|
353
|
-
let
|
|
354
|
-
productId:
|
|
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" && (
|
|
360
|
-
let
|
|
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
|
-
(
|
|
432
|
+
(p) => v(e, {
|
|
363
433
|
method: "POST",
|
|
364
434
|
path: "/api/sdk/v1/support/tickets",
|
|
365
|
-
body:
|
|
435
|
+
body: a,
|
|
366
436
|
requireAuth: !0,
|
|
367
437
|
idempotencyKey: !0,
|
|
368
|
-
headers:
|
|
438
|
+
headers: p
|
|
369
439
|
})
|
|
370
|
-
),
|
|
371
|
-
return
|
|
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
|
|
380
|
-
if (
|
|
381
|
-
throw new
|
|
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-${
|
|
453
|
+
`limit must be an integer 1-${V} (Core default 20)`
|
|
384
454
|
);
|
|
385
|
-
let
|
|
455
|
+
let l = await u(
|
|
386
456
|
true,
|
|
387
|
-
(
|
|
457
|
+
(p) => v(e, {
|
|
388
458
|
method: "GET",
|
|
389
459
|
path: "/api/sdk/v1/support/tickets",
|
|
390
|
-
query: { productId:
|
|
460
|
+
query: { productId: g, limit: a },
|
|
391
461
|
requireAuth: !0,
|
|
392
|
-
headers:
|
|
462
|
+
headers: p
|
|
393
463
|
})
|
|
394
464
|
);
|
|
395
|
-
return (Array.isArray(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
428
|
-
if (
|
|
429
|
-
throw new
|
|
430
|
-
|
|
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,
|
|
447
|
-
|
|
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:
|
|
519
|
+
{ body: { comment: g?.comment ?? void 0 } }
|
|
450
520
|
);
|
|
451
521
|
}
|
|
452
522
|
};
|
|
453
523
|
}
|
|
454
524
|
|
|
455
|
-
export {
|
|
525
|
+
export { ce as END_USER_TOKEN_HEADER, Ue as createSupportNamespace };
|