@neetru/sdk 3.6.0 → 3.7.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 +49 -0
- package/dist/ai.cjs +254 -391
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +254 -391
- package/dist/auth.cjs +3547 -4998
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +3544 -4995
- package/dist/build-guard.cjs +101 -119
- package/dist/build-guard.mjs +91 -109
- package/dist/catalog.cjs +152 -224
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +152 -224
- package/dist/checkout.cjs +237 -320
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +236 -319
- 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 +2055 -3013
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +2068 -3026
- package/dist/entitlements.cjs +12 -20
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +12 -20
- package/dist/errors.cjs +9 -12
- package/dist/errors.d.cts +37 -2
- package/dist/errors.d.ts +37 -2
- package/dist/errors.mjs +8 -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 +3605 -5131
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +3710 -5236
- package/dist/mobile.cjs +238 -342
- package/dist/mobile.d.cts +1 -1
- package/dist/mobile.d.ts +1 -1
- package/dist/mobile.mjs +238 -342
- package/dist/mocks.cjs +312 -447
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs +306 -441
- package/dist/notifications.cjs +226 -314
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +225 -313
- package/dist/react.cjs +522 -693
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +512 -683
- package/dist/support.cjs +329 -325
- package/dist/support.d.cts +25 -3
- package/dist/support.d.ts +25 -3
- package/dist/support.mjs +328 -325
- package/dist/telemetry.cjs +197 -301
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +197 -301
- package/dist/{types-Du_iioJ7.d.cts → types-Bx4kTLmk.d.cts} +26 -0
- package/dist/{types-BPATkXYu.d.ts → types-Dx0IrOSF.d.ts} +26 -0
- package/dist/usage.cjs +163 -227
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +163 -227
- package/dist/webhooks.cjs +258 -359
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +255 -356
- package/package.json +4 -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 i = class t extends Error {
|
|
5
5
|
code;
|
|
6
6
|
status;
|
|
7
7
|
requestId;
|
|
@@ -14,281 +14,213 @@ 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
|
-
constructor(
|
|
18
|
-
super(
|
|
19
|
-
this.name = "NeetruError";
|
|
20
|
-
this.code = code;
|
|
21
|
-
this.status = status;
|
|
22
|
-
this.requestId = requestId;
|
|
23
|
-
this.reason = reason;
|
|
24
|
-
Object.setPrototypeOf(this, _NeetruError.prototype);
|
|
17
|
+
constructor(e, r, n, a, s) {
|
|
18
|
+
super(r), this.name = "NeetruError", this.code = e, this.status = n, this.requestId = a, this.reason = s, Object.setPrototypeOf(this, t.prototype);
|
|
25
19
|
}
|
|
26
20
|
};
|
|
27
21
|
|
|
28
22
|
// src/idempotency.ts
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
throw new NeetruError(
|
|
23
|
+
function T() {
|
|
24
|
+
let t = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
25
|
+
if (t && typeof t.randomUUID == "function")
|
|
26
|
+
return t.randomUUID();
|
|
27
|
+
throw new i(
|
|
35
28
|
"runtime_unsupported",
|
|
36
29
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
37
30
|
);
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
// src/http.ts
|
|
41
|
-
var
|
|
34
|
+
var q = {
|
|
42
35
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
43
36
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
44
37
|
3: "2026.05.1"
|
|
45
38
|
};
|
|
46
|
-
function
|
|
47
|
-
return
|
|
39
|
+
function R(t) {
|
|
40
|
+
return t.split("+")[0] ?? t;
|
|
48
41
|
}
|
|
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;
|
|
42
|
+
function O(t, e) {
|
|
43
|
+
let r = R(t).split(".").map(Number), n = R(e).split(".").map(Number), a = Math.max(r.length, n.length);
|
|
44
|
+
for (let s = 0; s < a; s++) {
|
|
45
|
+
let d = r[s] ?? 0, f = n[s] ?? 0;
|
|
46
|
+
if (d !== f) return d - f;
|
|
57
47
|
}
|
|
58
48
|
return 0;
|
|
59
49
|
}
|
|
60
|
-
function
|
|
50
|
+
function N() {
|
|
61
51
|
try {
|
|
62
|
-
return "3.
|
|
52
|
+
return "3.7.0";
|
|
63
53
|
} catch {
|
|
64
|
-
return
|
|
54
|
+
return;
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return 3;
|
|
57
|
+
function U() {
|
|
58
|
+
let t = N();
|
|
59
|
+
return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
|
|
71
60
|
}
|
|
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
|
-
}
|
|
61
|
+
var A = /* @__PURE__ */ new Set();
|
|
62
|
+
function K(t) {
|
|
63
|
+
if (!t) return;
|
|
64
|
+
let e = U(), r = q[e];
|
|
65
|
+
if (!r) return;
|
|
66
|
+
let n = R(t);
|
|
67
|
+
if (O(n, r) < 0) {
|
|
68
|
+
let a = `${e}:${n}`;
|
|
69
|
+
A.has(a) || (A.add(a), console.warn(
|
|
70
|
+
`[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.`
|
|
71
|
+
));
|
|
87
72
|
}
|
|
88
73
|
}
|
|
89
|
-
var
|
|
90
|
-
var DEFAULT_RETRIES_WRITE = 0;
|
|
91
|
-
var READ_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
|
|
92
|
-
var RETRYABLE_CODES = /* @__PURE__ */ new Set([
|
|
74
|
+
var $ = 2, j = 0, L = /* @__PURE__ */ new Set(["GET", "HEAD"]), H = /* @__PURE__ */ new Set([
|
|
93
75
|
"rate_limited",
|
|
94
76
|
"server_error",
|
|
95
77
|
"network_error"
|
|
96
78
|
]);
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return Math.max(50, Math.round(base + jitter));
|
|
79
|
+
function v(t) {
|
|
80
|
+
let e = 200 * Math.pow(4, t), r = e * 0.2 * (Math.random() * 2 - 1);
|
|
81
|
+
return Math.max(50, Math.round(e + r));
|
|
101
82
|
}
|
|
102
|
-
var
|
|
103
|
-
function
|
|
104
|
-
if (!
|
|
105
|
-
|
|
106
|
-
if (Number.isFinite(
|
|
107
|
-
|
|
108
|
-
if (Number.isFinite(
|
|
109
|
-
|
|
110
|
-
if (
|
|
83
|
+
var P = 6e4;
|
|
84
|
+
function G(t) {
|
|
85
|
+
if (!t) return null;
|
|
86
|
+
let e = Number(t);
|
|
87
|
+
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), P);
|
|
88
|
+
let r = Date.parse(t);
|
|
89
|
+
if (Number.isFinite(r)) {
|
|
90
|
+
let n = r - Date.now();
|
|
91
|
+
if (n > 0) return Math.min(n, P);
|
|
111
92
|
}
|
|
112
93
|
return null;
|
|
113
94
|
}
|
|
114
|
-
function
|
|
115
|
-
return new Promise((
|
|
95
|
+
function x(t) {
|
|
96
|
+
return new Promise((e) => setTimeout(e, t));
|
|
116
97
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
if (status === 403) return "forbidden";
|
|
120
|
-
if (status === 404) return "not_found";
|
|
121
|
-
if (status === 409) return "conflict";
|
|
122
|
-
if (status === 422 || status === 400) return "validation_failed";
|
|
123
|
-
if (status === 429) return "rate_limited";
|
|
124
|
-
if (status >= 500) return "server_error";
|
|
125
|
-
return "unknown";
|
|
98
|
+
function F(t) {
|
|
99
|
+
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";
|
|
126
100
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (v === void 0) continue;
|
|
134
|
-
url.searchParams.set(k, String(v));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return url.toString();
|
|
101
|
+
function z(t, e, r) {
|
|
102
|
+
let n = t.replace(/\/+$/, ""), a = e.startsWith("/") ? e : `/${e}`, s = new URL(`${n}${a}`);
|
|
103
|
+
if (r)
|
|
104
|
+
for (let [d, f] of Object.entries(r))
|
|
105
|
+
f !== void 0 && s.searchParams.set(d, String(f));
|
|
106
|
+
return s.toString();
|
|
138
107
|
}
|
|
139
|
-
async function
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
108
|
+
async function D(t) {
|
|
109
|
+
let e = await t.text();
|
|
110
|
+
if (e)
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(e);
|
|
113
|
+
} catch {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
147
116
|
}
|
|
148
|
-
async function
|
|
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 = {
|
|
117
|
+
async function E(t, e) {
|
|
118
|
+
let r = e.method ?? "GET", n = z(t.baseUrl, e.path, e.query), a = L.has(r) ? $ : j, s = e.retries ?? a, d = {
|
|
154
119
|
accept: "application/json",
|
|
155
|
-
...
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
if (opts.requireAuth) {
|
|
162
|
-
if (!config.apiKey) {
|
|
163
|
-
throw new NeetruError(
|
|
120
|
+
...e.headers
|
|
121
|
+
}, f = N();
|
|
122
|
+
if (f && (d["x-neetru-sdk-version"] = f), e.requireAuth) {
|
|
123
|
+
if (!t.apiKey)
|
|
124
|
+
throw new i(
|
|
164
125
|
"missing_api_key",
|
|
165
126
|
"This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
166
127
|
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
let
|
|
128
|
+
d.authorization = `Bearer ${t.apiKey}`;
|
|
129
|
+
}
|
|
130
|
+
if (e.idempotencyKey) {
|
|
131
|
+
let l = typeof e.idempotencyKey == "string" ? e.idempotencyKey : T();
|
|
132
|
+
d["idempotency-key"] = l;
|
|
133
|
+
}
|
|
134
|
+
let w = e.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
135
|
+
w !== void 0 && (d["content-type"] = "application/json");
|
|
136
|
+
let m = null, p = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
|
|
137
|
+
for (let l = 0; l <= s; l++) {
|
|
138
|
+
if (p != null && Date.now() >= p)
|
|
139
|
+
throw m ?? new i("network_error", "Deadline excedido antes de completar a request");
|
|
140
|
+
let b = { method: r, headers: d };
|
|
141
|
+
w !== void 0 && (b.body = w);
|
|
142
|
+
let M = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
|
|
143
|
+
b.signal = AbortSignal.timeout(M);
|
|
144
|
+
let u;
|
|
184
145
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
146
|
+
u = await t.fetch(n, b);
|
|
147
|
+
} catch (o) {
|
|
148
|
+
let y = o instanceof DOMException && o.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${o instanceof Error ? o.message : "fetch failed"}`;
|
|
149
|
+
if (m = new i("network_error", y), l < s) {
|
|
150
|
+
let C = v(l);
|
|
151
|
+
if (p == null || Date.now() + C < p) {
|
|
152
|
+
await x(C);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
192
155
|
}
|
|
193
|
-
throw
|
|
156
|
+
throw m;
|
|
194
157
|
}
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const parsed = await safeJson(res);
|
|
200
|
-
return parsed;
|
|
158
|
+
let I = u.headers.get("x-request-id") ?? u.headers.get("x-correlation-id") ?? void 0;
|
|
159
|
+
if (u.ok) {
|
|
160
|
+
let o = u.headers.get("x-neetru-version");
|
|
161
|
+
return o && K(o), await D(u);
|
|
201
162
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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;
|
|
163
|
+
let c = await D(u), h = F(u.status), g = `HTTP ${u.status}`, _;
|
|
164
|
+
if (c && typeof c == "object") {
|
|
165
|
+
let o = c.error;
|
|
166
|
+
typeof o == "string" ? g = o : o && typeof o == "object" ? (typeof o.code == "string" && (h = o.code), typeof o.message == "string" && (g = o.message), typeof o.reason == "string" && (_ = o.reason)) : (typeof c.code == "string" && (h = c.code), typeof c.message == "string" && (g = c.message)), typeof c.reason == "string" && (_ = c.reason);
|
|
167
|
+
}
|
|
168
|
+
if (u.status === 410) {
|
|
169
|
+
let o = u.headers.get("x-neetru-replacement");
|
|
170
|
+
g === `HTTP ${u.status}` && (g = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), o && !g.includes(o) && (g += ` Substituto: ${o}.`);
|
|
219
171
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
continue;
|
|
172
|
+
let k = new i(h, g, u.status, I, _);
|
|
173
|
+
if (m = k, H.has(h) && l < s) {
|
|
174
|
+
let y = G(u.headers.get("retry-after")) ?? v(l);
|
|
175
|
+
if (p == null || Date.now() + y < p) {
|
|
176
|
+
await x(y);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
228
179
|
}
|
|
229
|
-
throw
|
|
180
|
+
throw k;
|
|
230
181
|
}
|
|
231
|
-
throw
|
|
182
|
+
throw m ?? new i("unknown", "unexpected httpRequest exit");
|
|
232
183
|
}
|
|
233
184
|
|
|
234
185
|
// 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
|
|
186
|
+
function S(t) {
|
|
187
|
+
if (!t || typeof t != "object")
|
|
188
|
+
throw new i("invalid_response", "Catalog response item is not an object");
|
|
189
|
+
let e = t;
|
|
190
|
+
if (typeof e.slug != "string" || !e.slug)
|
|
191
|
+
throw new i("invalid_response", "Catalog product missing slug");
|
|
192
|
+
if (typeof e.name != "string" || !e.name)
|
|
193
|
+
throw new i("invalid_response", "Catalog product missing name");
|
|
194
|
+
let r = {
|
|
195
|
+
slug: e.slug,
|
|
196
|
+
name: e.name
|
|
249
197
|
};
|
|
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;
|
|
198
|
+
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(
|
|
199
|
+
(n) => typeof n == "object" && n !== null && typeof n.id == "string" && typeof n.name == "string"
|
|
200
|
+
).map((n) => {
|
|
201
|
+
let a = { id: n.id, name: n.name };
|
|
202
|
+
return typeof n.amountCents == "number" && (a.amountCents = n.amountCents), Array.isArray(n.features) && n.features.every((s) => typeof s == "string") && (a.features = n.features), a;
|
|
203
|
+
})), r;
|
|
271
204
|
}
|
|
272
|
-
function
|
|
205
|
+
function te(t) {
|
|
273
206
|
return {
|
|
274
207
|
/**
|
|
275
208
|
* Lista produtos publicados. Por default só `published=true`; staff
|
|
276
209
|
* pode passar `includeDrafts: true` (requer Bearer com role admin/operator).
|
|
277
210
|
*/
|
|
278
|
-
async list(
|
|
279
|
-
|
|
211
|
+
async list(e = {}) {
|
|
212
|
+
let r = await E(t, {
|
|
280
213
|
method: "GET",
|
|
281
214
|
path: "/api/sdk/v1/catalog"
|
|
282
215
|
});
|
|
283
|
-
if (!
|
|
284
|
-
throw new
|
|
216
|
+
if (!r || !Array.isArray(r.products))
|
|
217
|
+
throw new i(
|
|
285
218
|
"invalid_response",
|
|
286
219
|
"Catalog list response missing products array"
|
|
287
220
|
);
|
|
288
|
-
}
|
|
289
221
|
return {
|
|
290
|
-
products:
|
|
291
|
-
fetchedAt: typeof
|
|
222
|
+
products: r.products.map(S),
|
|
223
|
+
fetchedAt: typeof r.fetchedAt == "string" ? r.fetchedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
292
224
|
};
|
|
293
225
|
},
|
|
294
226
|
/**
|
|
@@ -296,25 +228,21 @@ function createCatalogNamespace(config) {
|
|
|
296
228
|
*
|
|
297
229
|
* @throws {NeetruError} `not_found` se slug inexistente ou não publicado.
|
|
298
230
|
*/
|
|
299
|
-
async get(
|
|
300
|
-
if (!
|
|
301
|
-
throw new
|
|
302
|
-
|
|
303
|
-
const raw = await httpRequest(config, {
|
|
231
|
+
async get(e) {
|
|
232
|
+
if (!e || typeof e != "string")
|
|
233
|
+
throw new i("validation_failed", "slug is required");
|
|
234
|
+
let r = await E(t, {
|
|
304
235
|
method: "GET",
|
|
305
|
-
path: `/api/sdk/v1/catalog/${encodeURIComponent(
|
|
236
|
+
path: `/api/sdk/v1/catalog/${encodeURIComponent(e)}`
|
|
306
237
|
});
|
|
307
|
-
if (!
|
|
308
|
-
throw new
|
|
238
|
+
if (!r || !r.product)
|
|
239
|
+
throw new i(
|
|
309
240
|
"invalid_response",
|
|
310
241
|
"Catalog get response missing product"
|
|
311
242
|
);
|
|
312
|
-
|
|
313
|
-
return toProduct(raw.product);
|
|
243
|
+
return S(r.product);
|
|
314
244
|
}
|
|
315
245
|
};
|
|
316
246
|
}
|
|
317
247
|
|
|
318
|
-
exports.createCatalogNamespace =
|
|
319
|
-
//# sourceMappingURL=catalog.cjs.map
|
|
320
|
-
//# sourceMappingURL=catalog.cjs.map
|
|
248
|
+
exports.createCatalogNamespace = te;
|
package/dist/catalog.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ag as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a8 as Product } from './types-
|
|
1
|
+
import { ag as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a8 as Product } from './types-Bx4kTLmk.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 { ag as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a8 as Product } from './types-
|
|
1
|
+
import { ag as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a8 as Product } from './types-Dx0IrOSF.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
|
4
4
|
|