@neetru/sdk 3.6.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 +104 -0
- package/README.md +66 -1
- package/dist/ai.cjs +298 -391
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +298 -391
- package/dist/auth.cjs +3717 -5005
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +3714 -5002
- package/dist/build-guard.cjs +101 -119
- package/dist/build-guard.mjs +91 -109
- package/dist/catalog.cjs +220 -225
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +220 -225
- package/dist/checkout.cjs +307 -323
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +306 -322
- package/dist/db-react.cjs +59 -87
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db-react.mjs +56 -84
- package/dist/db.cjs +2128 -3014
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +2141 -3027
- package/dist/entitlements.cjs +19 -20
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +19 -20
- package/dist/errors.cjs +16 -12
- package/dist/errors.d.cts +59 -3
- package/dist/errors.d.ts +59 -3
- package/dist/errors.mjs +15 -12
- package/dist/firestore-compat.cjs +241 -297
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/firestore-compat.mjs +215 -271
- package/dist/index.cjs +3942 -5134
- package/dist/index.d.cts +181 -5
- package/dist/index.d.ts +181 -5
- package/dist/index.mjs +4040 -5239
- package/dist/mobile.cjs +459 -344
- package/dist/mobile.d.cts +59 -4
- package/dist/mobile.d.ts +59 -4
- package/dist/mobile.mjs +459 -344
- package/dist/mocks.cjs +319 -447
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs +313 -441
- package/dist/notifications.cjs +296 -317
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +295 -316
- package/dist/react.cjs +557 -707
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +547 -697
- package/dist/support.cjs +402 -328
- package/dist/support.d.cts +29 -3
- package/dist/support.d.ts +29 -3
- package/dist/support.mjs +401 -328
- package/dist/telemetry.cjs +267 -304
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +267 -304
- package/dist/{types-Du_iioJ7.d.cts → types-D-9bjlM0.d.cts} +74 -1
- package/dist/{types-BPATkXYu.d.ts → types-bVztFQTI.d.ts} +74 -1
- package/dist/usage.cjs +233 -230
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +233 -230
- package/dist/webhooks.cjs +328 -362
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +325 -359
- package/package.json +5 -3
- package/dist/ai.cjs.map +0 -1
- package/dist/ai.mjs.map +0 -1
- package/dist/auth.cjs.map +0 -1
- package/dist/auth.mjs.map +0 -1
- package/dist/build-guard.cjs.map +0 -1
- package/dist/build-guard.mjs.map +0 -1
- package/dist/catalog.cjs.map +0 -1
- package/dist/catalog.mjs.map +0 -1
- package/dist/checkout.cjs.map +0 -1
- package/dist/checkout.mjs.map +0 -1
- package/dist/db-react.cjs.map +0 -1
- package/dist/db-react.mjs.map +0 -1
- package/dist/db.cjs.map +0 -1
- package/dist/db.mjs.map +0 -1
- package/dist/entitlements.cjs.map +0 -1
- package/dist/entitlements.mjs.map +0 -1
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/firestore-compat.cjs.map +0 -1
- package/dist/firestore-compat.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/mobile.cjs.map +0 -1
- package/dist/mobile.mjs.map +0 -1
- package/dist/mocks.cjs.map +0 -1
- package/dist/mocks.mjs.map +0 -1
- package/dist/notifications.cjs.map +0 -1
- package/dist/notifications.mjs.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.mjs.map +0 -1
- package/dist/support.cjs.map +0 -1
- package/dist/support.mjs.map +0 -1
- package/dist/telemetry.cjs.map +0 -1
- package/dist/telemetry.mjs.map +0 -1
- package/dist/usage.cjs.map +0 -1
- package/dist/usage.mjs.map +0 -1
- package/dist/webhooks.cjs.map +0 -1
- package/dist/webhooks.mjs.map +0 -1
package/dist/catalog.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/errors.ts
|
|
4
|
-
var
|
|
4
|
+
var a = class t extends Error {
|
|
5
5
|
code;
|
|
6
6
|
status;
|
|
7
7
|
requestId;
|
|
@@ -14,281 +14,280 @@ var NeetruError = class _NeetruError extends Error {
|
|
|
14
14
|
* para um `NeetruDbErrorCode` mais específico (recuperável vs não).
|
|
15
15
|
*/
|
|
16
16
|
reason;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
/**
|
|
18
|
+
* 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
|
|
19
|
+
* chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
|
|
20
|
+
* mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
|
|
21
|
+
* `undefined` em erros que acontecem antes de qualquer requisição.
|
|
22
|
+
*/
|
|
23
|
+
correlationId;
|
|
24
|
+
constructor(e, r, n, o, s, u) {
|
|
25
|
+
super(r), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = o, this.reason = s, this.correlationId = u, Object.setPrototypeOf(this, t.prototype);
|
|
25
26
|
}
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
// src/idempotency.ts
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
throw new NeetruError(
|
|
30
|
+
function C() {
|
|
31
|
+
let t = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
32
|
+
if (t && typeof t.randomUUID == "function")
|
|
33
|
+
return t.randomUUID();
|
|
34
|
+
throw new a(
|
|
35
35
|
"runtime_unsupported",
|
|
36
36
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
// src/correlation.ts
|
|
41
|
+
var T = "x-correlation-id";
|
|
42
|
+
var $ = /^[A-Za-z0-9._:\-]+$/;
|
|
43
|
+
function I(t) {
|
|
44
|
+
return typeof t == "string" && t.length > 0 && t.length <= 128 && $.test(t);
|
|
45
|
+
}
|
|
46
|
+
function j() {
|
|
47
|
+
let t = globalThis.crypto;
|
|
48
|
+
try {
|
|
49
|
+
if (t && typeof t.randomUUID == "function") return t.randomUUID();
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
let e = new Uint8Array(16), r = false;
|
|
53
|
+
try {
|
|
54
|
+
t && typeof t.getRandomValues == "function" && (t.getRandomValues(e), r = !0);
|
|
55
|
+
} catch {
|
|
56
|
+
r = false;
|
|
57
|
+
}
|
|
58
|
+
if (!r)
|
|
59
|
+
for (let o = 0; o < e.length; o++) e[o] = Math.floor(Math.random() * 256);
|
|
60
|
+
e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
|
|
61
|
+
let n = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
62
|
+
return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
|
|
63
|
+
}
|
|
64
|
+
function N(t, e) {
|
|
65
|
+
let r, n = {};
|
|
66
|
+
for (let [s, u] of Object.entries(t)) {
|
|
67
|
+
if (s.toLowerCase() === T) {
|
|
68
|
+
I(u) && (r = u);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
n[s] = u;
|
|
72
|
+
}
|
|
73
|
+
let o = r ?? (I(e) ? e : void 0) ?? j();
|
|
74
|
+
return n[T] = o, { headers: n, correlationId: o };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/server-only-key.ts
|
|
78
|
+
function S() {
|
|
79
|
+
try {
|
|
80
|
+
let t = globalThis.navigator;
|
|
81
|
+
if (t && t.product === "ReactNative") return "react-native";
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
let t = globalThis;
|
|
86
|
+
if (typeof t.window < "u" && typeof t.document < "u") return "browser";
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
40
92
|
// src/http.ts
|
|
41
|
-
var
|
|
93
|
+
var H = {
|
|
42
94
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
43
95
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
44
96
|
3: "2026.05.1"
|
|
45
97
|
};
|
|
46
|
-
function
|
|
47
|
-
return
|
|
98
|
+
function b(t) {
|
|
99
|
+
return t.split("+")[0] ?? t;
|
|
48
100
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const pa = partsA[i] ?? 0;
|
|
55
|
-
const pb = partsB[i] ?? 0;
|
|
56
|
-
if (pa !== pb) return pa - pb;
|
|
101
|
+
function G(t, e) {
|
|
102
|
+
let r = b(t).split(".").map(Number), n = b(e).split(".").map(Number), o = Math.max(r.length, n.length);
|
|
103
|
+
for (let s = 0; s < o; s++) {
|
|
104
|
+
let u = r[s] ?? 0, c = n[s] ?? 0;
|
|
105
|
+
if (u !== c) return u - c;
|
|
57
106
|
}
|
|
58
107
|
return 0;
|
|
59
108
|
}
|
|
60
|
-
function
|
|
109
|
+
function M() {
|
|
61
110
|
try {
|
|
62
|
-
return "3.
|
|
111
|
+
return "3.8.0";
|
|
63
112
|
} catch {
|
|
64
|
-
return
|
|
113
|
+
return;
|
|
65
114
|
}
|
|
66
115
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return 3;
|
|
116
|
+
function V() {
|
|
117
|
+
let t = M();
|
|
118
|
+
return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
|
|
71
119
|
}
|
|
72
|
-
var
|
|
73
|
-
function
|
|
74
|
-
if (!
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
console.warn(
|
|
84
|
-
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${coreVersion}" \xE9 anterior ao m\xEDnimo recomendado "${minCore}" para SDK major ${sdkMajor}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
120
|
+
var D = /* @__PURE__ */ new Set();
|
|
121
|
+
function F(t) {
|
|
122
|
+
if (!t) return;
|
|
123
|
+
let e = V(), r = H[e];
|
|
124
|
+
if (!r) return;
|
|
125
|
+
let n = b(t);
|
|
126
|
+
if (G(n, r) < 0) {
|
|
127
|
+
let o = `${e}:${n}`;
|
|
128
|
+
D.has(o) || (D.add(o), console.warn(
|
|
129
|
+
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${t}" \xE9 anterior ao m\xEDnimo recomendado "${r}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
130
|
+
));
|
|
87
131
|
}
|
|
88
132
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
133
|
+
function z() {
|
|
134
|
+
let t = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
135
|
+
return S() ? "Esta opera\xE7\xE3o exige a credencial nrt_ do produto, que \xE9 S\xD3 DE SERVIDOR. No navegador/app, chame a API do seu produto (ex.: https://<produto>.neetru.com/api/v1) com o token do usu\xE1rio \u2014 o backend do produto faz esta chamada com o SDK e a chave. (" + t + ")" : t;
|
|
136
|
+
}
|
|
137
|
+
var B = 2, X = 0, Y = /* @__PURE__ */ new Set(["GET", "HEAD"]), J = /* @__PURE__ */ new Set([
|
|
93
138
|
"rate_limited",
|
|
94
139
|
"server_error",
|
|
95
140
|
"network_error"
|
|
96
141
|
]);
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return Math.max(50, Math.round(base + jitter));
|
|
142
|
+
function x(t) {
|
|
143
|
+
let e = 200 * Math.pow(4, t), r = e * 0.2 * (Math.random() * 2 - 1);
|
|
144
|
+
return Math.max(50, Math.round(e + r));
|
|
101
145
|
}
|
|
102
|
-
var
|
|
103
|
-
function
|
|
104
|
-
if (!
|
|
105
|
-
|
|
106
|
-
if (Number.isFinite(
|
|
107
|
-
|
|
108
|
-
if (Number.isFinite(
|
|
109
|
-
|
|
110
|
-
if (
|
|
146
|
+
var O = 6e4;
|
|
147
|
+
function W(t) {
|
|
148
|
+
if (!t) return null;
|
|
149
|
+
let e = Number(t);
|
|
150
|
+
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), O);
|
|
151
|
+
let r = Date.parse(t);
|
|
152
|
+
if (Number.isFinite(r)) {
|
|
153
|
+
let n = r - Date.now();
|
|
154
|
+
if (n > 0) return Math.min(n, O);
|
|
111
155
|
}
|
|
112
156
|
return null;
|
|
113
157
|
}
|
|
114
|
-
function
|
|
115
|
-
return new Promise((
|
|
158
|
+
function P(t) {
|
|
159
|
+
return new Promise((e) => setTimeout(e, t));
|
|
160
|
+
}
|
|
161
|
+
function Z(t) {
|
|
162
|
+
return t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 404 ? "not_found" : t === 409 ? "conflict" : t === 410 ? "gone" : t === 422 || t === 400 ? "validation_failed" : t === 429 ? "rate_limited" : t >= 500 ? "server_error" : "unknown";
|
|
116
163
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (status === 429) return "rate_limited";
|
|
124
|
-
if (status >= 500) return "server_error";
|
|
125
|
-
return "unknown";
|
|
164
|
+
function Q(t, e, r) {
|
|
165
|
+
let n = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, s = new URL(`${n}${o}`);
|
|
166
|
+
if (r)
|
|
167
|
+
for (let [u, c] of Object.entries(r))
|
|
168
|
+
c !== void 0 && s.searchParams.set(u, String(c));
|
|
169
|
+
return s.toString();
|
|
126
170
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
url.searchParams.set(k, String(v));
|
|
171
|
+
async function K(t) {
|
|
172
|
+
let e = await t.text();
|
|
173
|
+
if (e)
|
|
174
|
+
try {
|
|
175
|
+
return JSON.parse(e);
|
|
176
|
+
} catch {
|
|
177
|
+
return;
|
|
135
178
|
}
|
|
136
|
-
}
|
|
137
|
-
return url.toString();
|
|
138
179
|
}
|
|
139
|
-
async function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
180
|
+
async function E(t, e) {
|
|
181
|
+
let r = e.method ?? "GET", n = Q(t.baseUrl, e.path, e.query), o = Y.has(r) ? B : X, s = e.retries ?? o, { headers: u, correlationId: c } = N(
|
|
182
|
+
{ accept: "application/json", ...e.headers },
|
|
183
|
+
e.correlationId
|
|
184
|
+
), v = M();
|
|
185
|
+
if (v && (u["x-neetru-sdk-version"] = v), e.requireAuth) {
|
|
186
|
+
if (!t.apiKey)
|
|
187
|
+
throw new a("missing_api_key", z());
|
|
188
|
+
u.authorization = `Bearer ${t.apiKey}`;
|
|
146
189
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const url = buildUrl(config.baseUrl, opts.path, opts.query);
|
|
151
|
-
const defaultRetries = READ_METHODS.has(method) ? DEFAULT_RETRIES_READ : DEFAULT_RETRIES_WRITE;
|
|
152
|
-
const maxRetries = opts.retries ?? defaultRetries;
|
|
153
|
-
const headers = {
|
|
154
|
-
accept: "application/json",
|
|
155
|
-
...opts.headers
|
|
156
|
-
};
|
|
157
|
-
const sdkVersion = readInjectedSdkVersion();
|
|
158
|
-
if (sdkVersion) {
|
|
159
|
-
headers["x-neetru-sdk-version"] = sdkVersion;
|
|
190
|
+
if (e.idempotencyKey) {
|
|
191
|
+
let p = typeof e.idempotencyKey == "string" ? e.idempotencyKey : C();
|
|
192
|
+
u["idempotency-key"] = p;
|
|
160
193
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
194
|
+
let _ = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
195
|
+
_ !== void 0 && (u["content-type"] = "application/json");
|
|
196
|
+
let g = null, l = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
|
|
197
|
+
for (let p = 0; p <= s; p++) {
|
|
198
|
+
if (l != null && Date.now() >= l)
|
|
199
|
+
throw g ?? new a(
|
|
200
|
+
"network_error",
|
|
201
|
+
"Deadline excedido antes de completar a request",
|
|
202
|
+
void 0,
|
|
203
|
+
void 0,
|
|
204
|
+
void 0,
|
|
205
|
+
c
|
|
166
206
|
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
headers["idempotency-key"] = key;
|
|
173
|
-
}
|
|
174
|
-
const bodyString = opts.body !== void 0 && method !== "GET" && method !== "DELETE" ? JSON.stringify(opts.body) : void 0;
|
|
175
|
-
if (bodyString !== void 0) {
|
|
176
|
-
headers["content-type"] = "application/json";
|
|
177
|
-
}
|
|
178
|
-
let lastError = null;
|
|
179
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
180
|
-
const init = { method, headers };
|
|
181
|
-
if (bodyString !== void 0) init.body = bodyString;
|
|
182
|
-
init.signal = AbortSignal.timeout(3e4);
|
|
183
|
-
let res;
|
|
207
|
+
let w = { method: r, headers: u };
|
|
208
|
+
_ !== void 0 && (w.body = _);
|
|
209
|
+
let L = l != null ? Math.max(1, Math.min(3e4, l - Date.now())) : 3e4;
|
|
210
|
+
w.signal = AbortSignal.timeout(L);
|
|
211
|
+
let d;
|
|
184
212
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
213
|
+
d = await t.fetch(n, w);
|
|
214
|
+
} catch (i) {
|
|
215
|
+
let y = i instanceof DOMException && i.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${i instanceof Error ? i.message : "fetch failed"}`;
|
|
216
|
+
if (g = new a("network_error", y, void 0, void 0, void 0, c), p < s) {
|
|
217
|
+
let A = x(p);
|
|
218
|
+
if (l == null || Date.now() + A < l) {
|
|
219
|
+
await P(A);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
192
222
|
}
|
|
193
|
-
throw
|
|
223
|
+
throw g;
|
|
194
224
|
}
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const parsed = await safeJson(res);
|
|
200
|
-
return parsed;
|
|
225
|
+
let q = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
|
|
226
|
+
if (d.ok) {
|
|
227
|
+
let i = d.headers.get("x-neetru-version");
|
|
228
|
+
return i && F(i), await K(d);
|
|
201
229
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (body && typeof body === "object") {
|
|
207
|
-
const errField = body.error;
|
|
208
|
-
if (typeof errField === "string") {
|
|
209
|
-
message = errField;
|
|
210
|
-
} else if (errField && typeof errField === "object") {
|
|
211
|
-
if (typeof errField.code === "string") code = errField.code;
|
|
212
|
-
if (typeof errField.message === "string") message = errField.message;
|
|
213
|
-
if (typeof errField.reason === "string") reason = errField.reason;
|
|
214
|
-
} else {
|
|
215
|
-
if (typeof body.code === "string") code = body.code;
|
|
216
|
-
if (typeof body.message === "string") message = body.message;
|
|
217
|
-
}
|
|
218
|
-
if (typeof body.reason === "string") reason = body.reason;
|
|
230
|
+
let f = await K(d), h = Z(d.status), m = `HTTP ${d.status}`, R;
|
|
231
|
+
if (f && typeof f == "object") {
|
|
232
|
+
let i = f.error;
|
|
233
|
+
typeof i == "string" ? m = i : i && typeof i == "object" ? (typeof i.code == "string" && (h = i.code), typeof i.message == "string" && (m = i.message), typeof i.reason == "string" && (R = i.reason)) : (typeof f.code == "string" && (h = f.code), typeof f.message == "string" && (m = f.message)), typeof f.reason == "string" && (R = f.reason);
|
|
219
234
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
235
|
+
if (d.status === 410) {
|
|
236
|
+
let i = d.headers.get("x-neetru-replacement");
|
|
237
|
+
m === `HTTP ${d.status}` && (m = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), i && !m.includes(i) && (m += ` Substituto: ${i}.`);
|
|
238
|
+
}
|
|
239
|
+
let k = new a(h, m, d.status, q, R, c);
|
|
240
|
+
if (g = k, J.has(h) && p < s) {
|
|
241
|
+
let y = W(d.headers.get("retry-after")) ?? x(p);
|
|
242
|
+
if (l == null || Date.now() + y < l) {
|
|
243
|
+
await P(y);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
228
246
|
}
|
|
229
|
-
throw
|
|
247
|
+
throw k;
|
|
230
248
|
}
|
|
231
|
-
throw
|
|
249
|
+
throw g ?? new a("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, c);
|
|
232
250
|
}
|
|
233
251
|
|
|
234
252
|
// src/catalog.ts
|
|
235
|
-
function
|
|
236
|
-
if (!
|
|
237
|
-
throw new
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const product = {
|
|
247
|
-
slug: r.slug,
|
|
248
|
-
name: r.name
|
|
253
|
+
function U(t) {
|
|
254
|
+
if (!t || typeof t != "object")
|
|
255
|
+
throw new a("invalid_response", "Catalog response item is not an object");
|
|
256
|
+
let e = t;
|
|
257
|
+
if (typeof e.slug != "string" || !e.slug)
|
|
258
|
+
throw new a("invalid_response", "Catalog product missing slug");
|
|
259
|
+
if (typeof e.name != "string" || !e.name)
|
|
260
|
+
throw new a("invalid_response", "Catalog product missing name");
|
|
261
|
+
let r = {
|
|
262
|
+
slug: e.slug,
|
|
263
|
+
name: e.name
|
|
249
264
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (typeof r.ctaHref === "string") product.ctaHref = r.ctaHref;
|
|
257
|
-
if (typeof r.ctaLabel === "string") product.ctaLabel = r.ctaLabel;
|
|
258
|
-
if (Array.isArray(r.plans)) {
|
|
259
|
-
product.plans = r.plans.filter(
|
|
260
|
-
(p) => typeof p === "object" && p !== null && typeof p.id === "string" && typeof p.name === "string"
|
|
261
|
-
).map((p) => {
|
|
262
|
-
const plan = { id: p.id, name: p.name };
|
|
263
|
-
if (typeof p.amountCents === "number") plan.amountCents = p.amountCents;
|
|
264
|
-
if (Array.isArray(p.features) && p.features.every((f) => typeof f === "string")) {
|
|
265
|
-
plan.features = p.features;
|
|
266
|
-
}
|
|
267
|
-
return plan;
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
return product;
|
|
265
|
+
return typeof e.tagline == "string" && (r.tagline = e.tagline), typeof e.description == "string" && (r.description = e.description), (e.status === "live" || e.status === "soon" || e.status === "beta") && (r.status = e.status), typeof e.iconKey == "string" && (r.iconKey = e.iconKey), typeof e.ctaHref == "string" && (r.ctaHref = e.ctaHref), typeof e.ctaLabel == "string" && (r.ctaLabel = e.ctaLabel), Array.isArray(e.plans) && (r.plans = e.plans.filter(
|
|
266
|
+
(n) => typeof n == "object" && n !== null && typeof n.id == "string" && typeof n.name == "string"
|
|
267
|
+
).map((n) => {
|
|
268
|
+
let o = { id: n.id, name: n.name };
|
|
269
|
+
return typeof n.amountCents == "number" && (o.amountCents = n.amountCents), Array.isArray(n.features) && n.features.every((s) => typeof s == "string") && (o.features = n.features), o;
|
|
270
|
+
})), r;
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function pe(t) {
|
|
273
273
|
return {
|
|
274
274
|
/**
|
|
275
275
|
* Lista produtos publicados. Por default só `published=true`; staff
|
|
276
276
|
* pode passar `includeDrafts: true` (requer Bearer com role admin/operator).
|
|
277
277
|
*/
|
|
278
|
-
async list(
|
|
279
|
-
|
|
278
|
+
async list(e = {}) {
|
|
279
|
+
let r = await E(t, {
|
|
280
280
|
method: "GET",
|
|
281
281
|
path: "/api/sdk/v1/catalog"
|
|
282
282
|
});
|
|
283
|
-
if (!
|
|
284
|
-
throw new
|
|
283
|
+
if (!r || !Array.isArray(r.products))
|
|
284
|
+
throw new a(
|
|
285
285
|
"invalid_response",
|
|
286
286
|
"Catalog list response missing products array"
|
|
287
287
|
);
|
|
288
|
-
}
|
|
289
288
|
return {
|
|
290
|
-
products:
|
|
291
|
-
fetchedAt: typeof
|
|
289
|
+
products: r.products.map(U),
|
|
290
|
+
fetchedAt: typeof r.fetchedAt == "string" ? r.fetchedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
292
291
|
};
|
|
293
292
|
},
|
|
294
293
|
/**
|
|
@@ -296,25 +295,21 @@ function createCatalogNamespace(config) {
|
|
|
296
295
|
*
|
|
297
296
|
* @throws {NeetruError} `not_found` se slug inexistente ou não publicado.
|
|
298
297
|
*/
|
|
299
|
-
async get(
|
|
300
|
-
if (!
|
|
301
|
-
throw new
|
|
302
|
-
|
|
303
|
-
const raw = await httpRequest(config, {
|
|
298
|
+
async get(e) {
|
|
299
|
+
if (!e || typeof e != "string")
|
|
300
|
+
throw new a("validation_failed", "slug is required");
|
|
301
|
+
let r = await E(t, {
|
|
304
302
|
method: "GET",
|
|
305
|
-
path: `/api/sdk/v1/catalog/${encodeURIComponent(
|
|
303
|
+
path: `/api/sdk/v1/catalog/${encodeURIComponent(e)}`
|
|
306
304
|
});
|
|
307
|
-
if (!
|
|
308
|
-
throw new
|
|
305
|
+
if (!r || !r.product)
|
|
306
|
+
throw new a(
|
|
309
307
|
"invalid_response",
|
|
310
308
|
"Catalog get response missing product"
|
|
311
309
|
);
|
|
312
|
-
|
|
313
|
-
return toProduct(raw.product);
|
|
310
|
+
return U(r.product);
|
|
314
311
|
}
|
|
315
312
|
};
|
|
316
313
|
}
|
|
317
314
|
|
|
318
|
-
exports.createCatalogNamespace =
|
|
319
|
-
//# sourceMappingURL=catalog.cjs.map
|
|
320
|
-
//# sourceMappingURL=catalog.cjs.map
|
|
315
|
+
exports.createCatalogNamespace = pe;
|
package/dist/catalog.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a9 as Product } from './types-D-9bjlM0.cjs';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.cjs';
|
|
4
4
|
|
package/dist/catalog.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a9 as Product } from './types-bVztFQTI.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
|
4
4
|
|