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