@neetru/sdk 3.8.1 → 3.9.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 +33 -0
- package/README.md +4 -1
- package/dist/ai.cjs +1 -1
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +1 -1
- package/dist/auth.cjs +844 -803
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +841 -800
- package/dist/catalog.cjs +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/checkout.cjs +62 -49
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +62 -49
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +200 -187
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +193 -180
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +880 -839
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +847 -806
- package/dist/mobile.cjs +328 -276
- package/dist/mobile.d.cts +12 -2
- package/dist/mobile.d.ts +12 -2
- package/dist/mobile.mjs +328 -276
- package/dist/mocks.cjs +5 -5
- package/dist/mocks.d.cts +2 -2
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.mjs +4 -4
- package/dist/notifications.cjs +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +1 -1
- package/dist/react.cjs +119 -119
- package/dist/react.d.cts +8 -2
- package/dist/react.d.ts +8 -2
- package/dist/react.mjs +119 -119
- package/dist/support.cjs +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/support.mjs +1 -1
- package/dist/telemetry.cjs +62 -49
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +62 -49
- package/dist/{types-yv3EDKg2.d.cts → types-Bl_4HROd.d.cts} +62 -3
- package/dist/{types-BYPk_3HR.d.ts → types-Bqnsqvow.d.ts} +62 -3
- package/dist/usage.cjs +1 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +1 -1
- package/dist/webhooks.cjs +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +1 -1
- package/package.json +9 -1
package/dist/catalog.cjs
CHANGED
package/dist/catalog.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ai as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a9 as Product } from './types-Bl_4HROd.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 { ai as ResolvedConfig, C as CatalogListOptions, n as CatalogListResponse, a9 as Product } from './types-Bqnsqvow.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
|
4
4
|
|
package/dist/catalog.mjs
CHANGED
package/dist/checkout.cjs
CHANGED
|
@@ -39,11 +39,11 @@ function E() {
|
|
|
39
39
|
|
|
40
40
|
// src/correlation.ts
|
|
41
41
|
var A = "x-correlation-id";
|
|
42
|
-
var
|
|
42
|
+
var H = /^[A-Za-z0-9._:\-]+$/;
|
|
43
43
|
function x(t) {
|
|
44
|
-
return typeof t == "string" && t.length > 0 && t.length <= 128 &&
|
|
44
|
+
return typeof t == "string" && t.length > 0 && t.length <= 128 && H.test(t);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function B() {
|
|
47
47
|
let t = globalThis.crypto;
|
|
48
48
|
try {
|
|
49
49
|
if (t && typeof t.randomUUID == "function") return t.randomUUID();
|
|
@@ -70,7 +70,7 @@ function N(t, e) {
|
|
|
70
70
|
}
|
|
71
71
|
r[a] = c;
|
|
72
72
|
}
|
|
73
|
-
let o = n ?? (x(e) ? e : void 0) ??
|
|
73
|
+
let o = n ?? (x(e) ? e : void 0) ?? B();
|
|
74
74
|
return r[A] = o, { headers: r, correlationId: o };
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -90,7 +90,7 @@ function D() {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// src/http.ts
|
|
93
|
-
var
|
|
93
|
+
var G = {
|
|
94
94
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
95
95
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
96
96
|
3: "2026.05.1"
|
|
@@ -98,7 +98,7 @@ var B = {
|
|
|
98
98
|
function b(t) {
|
|
99
99
|
return t.split("+")[0] ?? t;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function F(t, e) {
|
|
102
102
|
let n = b(t).split(".").map(Number), r = b(e).split(".").map(Number), o = Math.max(n.length, r.length);
|
|
103
103
|
for (let a = 0; a < o; a++) {
|
|
104
104
|
let c = n[a] ?? 0, u = r[a] ?? 0;
|
|
@@ -108,43 +108,43 @@ function G(t, e) {
|
|
|
108
108
|
}
|
|
109
109
|
function M() {
|
|
110
110
|
try {
|
|
111
|
-
return "3.
|
|
111
|
+
return "3.9.0";
|
|
112
112
|
} catch {
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
function
|
|
116
|
+
function V() {
|
|
117
117
|
let t = M();
|
|
118
118
|
return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
|
|
119
119
|
}
|
|
120
|
-
var
|
|
121
|
-
function
|
|
120
|
+
var O = /* @__PURE__ */ new Set();
|
|
121
|
+
function z(t) {
|
|
122
122
|
if (!t) return;
|
|
123
|
-
let e =
|
|
123
|
+
let e = V(), n = G[e];
|
|
124
124
|
if (!n) return;
|
|
125
125
|
let r = b(t);
|
|
126
|
-
if (
|
|
126
|
+
if (F(r, n) < 0) {
|
|
127
127
|
let o = `${e}:${r}`;
|
|
128
|
-
|
|
128
|
+
O.has(o) || (O.add(o), console.warn(
|
|
129
129
|
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${t}" \xE9 anterior ao m\xEDnimo recomendado "${n}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
130
130
|
));
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function X() {
|
|
134
134
|
let t = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
135
135
|
return D() ? "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
136
|
}
|
|
137
|
-
var
|
|
137
|
+
var Y = 2, J = 0, W = /* @__PURE__ */ new Set(["GET", "HEAD"]), Z = /* @__PURE__ */ new Set([
|
|
138
138
|
"rate_limited",
|
|
139
139
|
"server_error",
|
|
140
140
|
"network_error"
|
|
141
141
|
]);
|
|
142
|
-
function
|
|
142
|
+
function U(t) {
|
|
143
143
|
let e = 200 * Math.pow(4, t), n = e * 0.2 * (Math.random() * 2 - 1);
|
|
144
144
|
return Math.max(50, Math.round(e + n));
|
|
145
145
|
}
|
|
146
146
|
var q = 6e4;
|
|
147
|
-
function
|
|
147
|
+
function Q(t) {
|
|
148
148
|
if (!t) return null;
|
|
149
149
|
let e = Number(t);
|
|
150
150
|
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), q);
|
|
@@ -158,10 +158,10 @@ function Z(t) {
|
|
|
158
158
|
function K(t) {
|
|
159
159
|
return new Promise((e) => setTimeout(e, t));
|
|
160
160
|
}
|
|
161
|
-
function
|
|
161
|
+
function ee(t) {
|
|
162
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";
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function te(t, e, n) {
|
|
165
165
|
let r = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, a = new URL(`${r}${o}`);
|
|
166
166
|
if (n)
|
|
167
167
|
for (let [c, u] of Object.entries(n))
|
|
@@ -177,14 +177,14 @@ async function P(t) {
|
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
async function
|
|
181
|
-
let n = e.method ?? "GET", r =
|
|
180
|
+
async function k(t, e) {
|
|
181
|
+
let n = e.method ?? "GET", r = te(t.baseUrl, e.path, e.query), o = W.has(n) ? Y : J, a = e.retries ?? o, { headers: c, correlationId: u } = N(
|
|
182
182
|
{ accept: "application/json", ...e.headers },
|
|
183
183
|
e.correlationId
|
|
184
|
-
),
|
|
185
|
-
if (
|
|
184
|
+
), v = M();
|
|
185
|
+
if (v && (c["x-neetru-sdk-version"] = v), e.requireAuth) {
|
|
186
186
|
if (!t.apiKey)
|
|
187
|
-
throw new i("missing_api_key",
|
|
187
|
+
throw new i("missing_api_key", X());
|
|
188
188
|
c.authorization = `Bearer ${t.apiKey}`;
|
|
189
189
|
}
|
|
190
190
|
if (e.idempotencyKey) {
|
|
@@ -206,15 +206,15 @@ async function y(t, e) {
|
|
|
206
206
|
);
|
|
207
207
|
let _ = { method: n, headers: c };
|
|
208
208
|
I !== void 0 && (_.body = I);
|
|
209
|
-
let
|
|
210
|
-
_.signal = AbortSignal.timeout(
|
|
209
|
+
let j = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
|
|
210
|
+
_.signal = AbortSignal.timeout(j);
|
|
211
211
|
let d;
|
|
212
212
|
try {
|
|
213
213
|
d = await t.fetch(r, _);
|
|
214
214
|
} catch (s) {
|
|
215
215
|
let m = s instanceof DOMException && s.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${s instanceof Error ? s.message : "fetch failed"}`;
|
|
216
216
|
if (g = new i("network_error", m, void 0, void 0, void 0, u), f < a) {
|
|
217
|
-
let S =
|
|
217
|
+
let S = U(f);
|
|
218
218
|
if (p == null || Date.now() + S < p) {
|
|
219
219
|
await K(S);
|
|
220
220
|
continue;
|
|
@@ -222,33 +222,46 @@ async function y(t, e) {
|
|
|
222
222
|
}
|
|
223
223
|
throw g;
|
|
224
224
|
}
|
|
225
|
-
let
|
|
225
|
+
let L = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
|
|
226
226
|
if (d.ok) {
|
|
227
227
|
let s = d.headers.get("x-neetru-version");
|
|
228
|
-
return s &&
|
|
228
|
+
return s && z(s), await P(d);
|
|
229
229
|
}
|
|
230
|
-
let l = await P(d),
|
|
230
|
+
let l = await P(d), y = ee(d.status), h = `HTTP ${d.status}`, w;
|
|
231
231
|
if (l && typeof l == "object") {
|
|
232
232
|
let s = l.error;
|
|
233
|
-
typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (
|
|
233
|
+
typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (y = s.code), typeof s.message == "string" && (h = s.message), typeof s.reason == "string" && (w = s.reason)) : (typeof l.code == "string" && (y = l.code), typeof l.message == "string" && (h = l.message)), typeof l.reason == "string" && (w = l.reason);
|
|
234
234
|
}
|
|
235
235
|
if (d.status === 410) {
|
|
236
236
|
let s = d.headers.get("x-neetru-replacement");
|
|
237
237
|
h === `HTTP ${d.status}` && (h = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), s && !h.includes(s) && (h += ` Substituto: ${s}.`);
|
|
238
238
|
}
|
|
239
|
-
let
|
|
240
|
-
if (g =
|
|
241
|
-
let m =
|
|
239
|
+
let C = new i(y, h, d.status, L, w, u);
|
|
240
|
+
if (g = C, Z.has(y) && f < a) {
|
|
241
|
+
let m = Q(d.headers.get("retry-after")) ?? U(f);
|
|
242
242
|
if (p == null || Date.now() + m < p) {
|
|
243
243
|
await K(m);
|
|
244
244
|
continue;
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
throw
|
|
247
|
+
throw C;
|
|
248
248
|
}
|
|
249
249
|
throw g ?? new i("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, u);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
// src/runtime-env.ts
|
|
253
|
+
function ne() {
|
|
254
|
+
try {
|
|
255
|
+
if (typeof process < "u" && process.env)
|
|
256
|
+
return process.env.NODE_ENV === "production";
|
|
257
|
+
} catch {
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
function $(t) {
|
|
262
|
+
return t === "dev" && !ne();
|
|
263
|
+
}
|
|
264
|
+
|
|
252
265
|
// src/checkout.ts
|
|
253
266
|
function T(t, e) {
|
|
254
267
|
let n = t?.accessToken || t?.idToken;
|
|
@@ -259,7 +272,7 @@ function T(t, e) {
|
|
|
259
272
|
);
|
|
260
273
|
return { requireAuth: false, headers: { authorization: `Bearer ${n}` } };
|
|
261
274
|
}
|
|
262
|
-
function
|
|
275
|
+
function re(t) {
|
|
263
276
|
if (!t || typeof t != "object")
|
|
264
277
|
throw new i("invalid_response", "checkout.start response is not an object");
|
|
265
278
|
let e = t;
|
|
@@ -275,7 +288,7 @@ function te(t) {
|
|
|
275
288
|
requiresKyc: e.requiresKyc === true
|
|
276
289
|
};
|
|
277
290
|
}
|
|
278
|
-
function
|
|
291
|
+
function oe(t) {
|
|
279
292
|
if (!t || typeof t != "object")
|
|
280
293
|
throw new i("invalid_response", "checkout.get response is not an object");
|
|
281
294
|
let e = t, n = e.intent;
|
|
@@ -297,20 +310,20 @@ function ne(t) {
|
|
|
297
310
|
isStale: e.isStale === true
|
|
298
311
|
};
|
|
299
312
|
}
|
|
300
|
-
function
|
|
313
|
+
function ie() {
|
|
301
314
|
try {
|
|
302
315
|
return typeof globalThis < "u" && typeof globalThis.window < "u" && typeof globalThis.location < "u" && typeof globalThis.location.assign == "function";
|
|
303
316
|
} catch {
|
|
304
317
|
return false;
|
|
305
318
|
}
|
|
306
319
|
}
|
|
307
|
-
function
|
|
320
|
+
function se(t) {
|
|
308
321
|
try {
|
|
309
322
|
globalThis.location.assign(t);
|
|
310
323
|
} catch {
|
|
311
324
|
}
|
|
312
325
|
}
|
|
313
|
-
function
|
|
326
|
+
function ae(t) {
|
|
314
327
|
return {
|
|
315
328
|
async start(e) {
|
|
316
329
|
if (!e?.productId)
|
|
@@ -328,15 +341,15 @@ function ie(t) {
|
|
|
328
341
|
let { requireAuth: r, headers: o } = T(
|
|
329
342
|
{ accessToken: e.accessToken, idToken: e.idToken },
|
|
330
343
|
"start"
|
|
331
|
-
), a = await
|
|
344
|
+
), a = await k(t, {
|
|
332
345
|
method: "POST",
|
|
333
346
|
path: "/api/v1/checkout/intents",
|
|
334
347
|
body: n,
|
|
335
348
|
requireAuth: r,
|
|
336
349
|
headers: o,
|
|
337
350
|
idempotencyKey: true
|
|
338
|
-
}), c =
|
|
339
|
-
return e.autoRedirect !== false &&
|
|
351
|
+
}), c = re(a);
|
|
352
|
+
return e.autoRedirect !== false && ie() && se(c.redirectUrl), c;
|
|
340
353
|
},
|
|
341
354
|
async get(e, n) {
|
|
342
355
|
if (!e || typeof e != "string")
|
|
@@ -344,13 +357,13 @@ function ie(t) {
|
|
|
344
357
|
let { requireAuth: r, headers: o } = T(
|
|
345
358
|
{ accessToken: n?.accessToken, idToken: n?.idToken },
|
|
346
359
|
"get"
|
|
347
|
-
), a = await
|
|
360
|
+
), a = await k(t, {
|
|
348
361
|
method: "GET",
|
|
349
362
|
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
350
363
|
requireAuth: r,
|
|
351
364
|
headers: o
|
|
352
365
|
});
|
|
353
|
-
return
|
|
366
|
+
return oe(a);
|
|
354
367
|
},
|
|
355
368
|
async cancel(e, n) {
|
|
356
369
|
if (!e || typeof e != "string")
|
|
@@ -361,7 +374,7 @@ function ie(t) {
|
|
|
361
374
|
);
|
|
362
375
|
return {
|
|
363
376
|
ok: true,
|
|
364
|
-
alreadyCancelled: (await
|
|
377
|
+
alreadyCancelled: (await k(t, {
|
|
365
378
|
method: "DELETE",
|
|
366
379
|
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
367
380
|
requireAuth: r,
|
|
@@ -414,9 +427,9 @@ var R = class {
|
|
|
414
427
|
return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled: o };
|
|
415
428
|
}
|
|
416
429
|
};
|
|
417
|
-
function
|
|
418
|
-
return t.env
|
|
430
|
+
function Te(t) {
|
|
431
|
+
return $(t.env) ? new R() : ae(t);
|
|
419
432
|
}
|
|
420
433
|
|
|
421
434
|
exports.MockCheckout = R;
|
|
422
|
-
exports.createCheckoutNamespace =
|
|
435
|
+
exports.createCheckoutNamespace = Te;
|
package/dist/checkout.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { o as CheckoutAuthOpts, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, T as MockCheckout,
|
|
1
|
+
export { o as CheckoutAuthOpts, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, T as MockCheckout, aN as createCheckoutNamespace } from './types-Bl_4HROd.cjs';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.cjs';
|
package/dist/checkout.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { o as CheckoutAuthOpts, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, T as MockCheckout,
|
|
1
|
+
export { o as CheckoutAuthOpts, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, T as MockCheckout, aN as createCheckoutNamespace } from './types-Bqnsqvow.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
package/dist/checkout.mjs
CHANGED
|
@@ -37,11 +37,11 @@ function E() {
|
|
|
37
37
|
|
|
38
38
|
// src/correlation.ts
|
|
39
39
|
var A = "x-correlation-id";
|
|
40
|
-
var
|
|
40
|
+
var H = /^[A-Za-z0-9._:\-]+$/;
|
|
41
41
|
function x(t) {
|
|
42
|
-
return typeof t == "string" && t.length > 0 && t.length <= 128 &&
|
|
42
|
+
return typeof t == "string" && t.length > 0 && t.length <= 128 && H.test(t);
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function B() {
|
|
45
45
|
let t = globalThis.crypto;
|
|
46
46
|
try {
|
|
47
47
|
if (t && typeof t.randomUUID == "function") return t.randomUUID();
|
|
@@ -68,7 +68,7 @@ function N(t, e) {
|
|
|
68
68
|
}
|
|
69
69
|
r[a] = c;
|
|
70
70
|
}
|
|
71
|
-
let o = n ?? (x(e) ? e : void 0) ??
|
|
71
|
+
let o = n ?? (x(e) ? e : void 0) ?? B();
|
|
72
72
|
return r[A] = o, { headers: r, correlationId: o };
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -88,7 +88,7 @@ function D() {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// src/http.ts
|
|
91
|
-
var
|
|
91
|
+
var G = {
|
|
92
92
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
93
93
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
94
94
|
3: "2026.05.1"
|
|
@@ -96,7 +96,7 @@ var B = {
|
|
|
96
96
|
function b(t) {
|
|
97
97
|
return t.split("+")[0] ?? t;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function F(t, e) {
|
|
100
100
|
let n = b(t).split(".").map(Number), r = b(e).split(".").map(Number), o = Math.max(n.length, r.length);
|
|
101
101
|
for (let a = 0; a < o; a++) {
|
|
102
102
|
let c = n[a] ?? 0, u = r[a] ?? 0;
|
|
@@ -106,43 +106,43 @@ function G(t, e) {
|
|
|
106
106
|
}
|
|
107
107
|
function M() {
|
|
108
108
|
try {
|
|
109
|
-
return "3.
|
|
109
|
+
return "3.9.0";
|
|
110
110
|
} catch {
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function V() {
|
|
115
115
|
let t = M();
|
|
116
116
|
return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
|
|
117
117
|
}
|
|
118
|
-
var
|
|
119
|
-
function
|
|
118
|
+
var O = /* @__PURE__ */ new Set();
|
|
119
|
+
function z(t) {
|
|
120
120
|
if (!t) return;
|
|
121
|
-
let e =
|
|
121
|
+
let e = V(), n = G[e];
|
|
122
122
|
if (!n) return;
|
|
123
123
|
let r = b(t);
|
|
124
|
-
if (
|
|
124
|
+
if (F(r, n) < 0) {
|
|
125
125
|
let o = `${e}:${r}`;
|
|
126
|
-
|
|
126
|
+
O.has(o) || (O.add(o), console.warn(
|
|
127
127
|
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${t}" \xE9 anterior ao m\xEDnimo recomendado "${n}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
128
128
|
));
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function X() {
|
|
132
132
|
let t = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
133
133
|
return D() ? "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;
|
|
134
134
|
}
|
|
135
|
-
var
|
|
135
|
+
var Y = 2, J = 0, W = /* @__PURE__ */ new Set(["GET", "HEAD"]), Z = /* @__PURE__ */ new Set([
|
|
136
136
|
"rate_limited",
|
|
137
137
|
"server_error",
|
|
138
138
|
"network_error"
|
|
139
139
|
]);
|
|
140
|
-
function
|
|
140
|
+
function U(t) {
|
|
141
141
|
let e = 200 * Math.pow(4, t), n = e * 0.2 * (Math.random() * 2 - 1);
|
|
142
142
|
return Math.max(50, Math.round(e + n));
|
|
143
143
|
}
|
|
144
144
|
var q = 6e4;
|
|
145
|
-
function
|
|
145
|
+
function Q(t) {
|
|
146
146
|
if (!t) return null;
|
|
147
147
|
let e = Number(t);
|
|
148
148
|
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), q);
|
|
@@ -156,10 +156,10 @@ function Z(t) {
|
|
|
156
156
|
function K(t) {
|
|
157
157
|
return new Promise((e) => setTimeout(e, t));
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function ee(t) {
|
|
160
160
|
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";
|
|
161
161
|
}
|
|
162
|
-
function
|
|
162
|
+
function te(t, e, n) {
|
|
163
163
|
let r = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, a = new URL(`${r}${o}`);
|
|
164
164
|
if (n)
|
|
165
165
|
for (let [c, u] of Object.entries(n))
|
|
@@ -175,14 +175,14 @@ async function P(t) {
|
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
async function
|
|
179
|
-
let n = e.method ?? "GET", r =
|
|
178
|
+
async function k(t, e) {
|
|
179
|
+
let n = e.method ?? "GET", r = te(t.baseUrl, e.path, e.query), o = W.has(n) ? Y : J, a = e.retries ?? o, { headers: c, correlationId: u } = N(
|
|
180
180
|
{ accept: "application/json", ...e.headers },
|
|
181
181
|
e.correlationId
|
|
182
|
-
),
|
|
183
|
-
if (
|
|
182
|
+
), v = M();
|
|
183
|
+
if (v && (c["x-neetru-sdk-version"] = v), e.requireAuth) {
|
|
184
184
|
if (!t.apiKey)
|
|
185
|
-
throw new i("missing_api_key",
|
|
185
|
+
throw new i("missing_api_key", X());
|
|
186
186
|
c.authorization = `Bearer ${t.apiKey}`;
|
|
187
187
|
}
|
|
188
188
|
if (e.idempotencyKey) {
|
|
@@ -204,15 +204,15 @@ async function y(t, e) {
|
|
|
204
204
|
);
|
|
205
205
|
let _ = { method: n, headers: c };
|
|
206
206
|
I !== void 0 && (_.body = I);
|
|
207
|
-
let
|
|
208
|
-
_.signal = AbortSignal.timeout(
|
|
207
|
+
let j = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
|
|
208
|
+
_.signal = AbortSignal.timeout(j);
|
|
209
209
|
let d;
|
|
210
210
|
try {
|
|
211
211
|
d = await t.fetch(r, _);
|
|
212
212
|
} catch (s) {
|
|
213
213
|
let m = s instanceof DOMException && s.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${s instanceof Error ? s.message : "fetch failed"}`;
|
|
214
214
|
if (g = new i("network_error", m, void 0, void 0, void 0, u), f < a) {
|
|
215
|
-
let S =
|
|
215
|
+
let S = U(f);
|
|
216
216
|
if (p == null || Date.now() + S < p) {
|
|
217
217
|
await K(S);
|
|
218
218
|
continue;
|
|
@@ -220,33 +220,46 @@ async function y(t, e) {
|
|
|
220
220
|
}
|
|
221
221
|
throw g;
|
|
222
222
|
}
|
|
223
|
-
let
|
|
223
|
+
let L = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
|
|
224
224
|
if (d.ok) {
|
|
225
225
|
let s = d.headers.get("x-neetru-version");
|
|
226
|
-
return s &&
|
|
226
|
+
return s && z(s), await P(d);
|
|
227
227
|
}
|
|
228
|
-
let l = await P(d),
|
|
228
|
+
let l = await P(d), y = ee(d.status), h = `HTTP ${d.status}`, w;
|
|
229
229
|
if (l && typeof l == "object") {
|
|
230
230
|
let s = l.error;
|
|
231
|
-
typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (
|
|
231
|
+
typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (y = s.code), typeof s.message == "string" && (h = s.message), typeof s.reason == "string" && (w = s.reason)) : (typeof l.code == "string" && (y = l.code), typeof l.message == "string" && (h = l.message)), typeof l.reason == "string" && (w = l.reason);
|
|
232
232
|
}
|
|
233
233
|
if (d.status === 410) {
|
|
234
234
|
let s = d.headers.get("x-neetru-replacement");
|
|
235
235
|
h === `HTTP ${d.status}` && (h = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), s && !h.includes(s) && (h += ` Substituto: ${s}.`);
|
|
236
236
|
}
|
|
237
|
-
let
|
|
238
|
-
if (g =
|
|
239
|
-
let m =
|
|
237
|
+
let C = new i(y, h, d.status, L, w, u);
|
|
238
|
+
if (g = C, Z.has(y) && f < a) {
|
|
239
|
+
let m = Q(d.headers.get("retry-after")) ?? U(f);
|
|
240
240
|
if (p == null || Date.now() + m < p) {
|
|
241
241
|
await K(m);
|
|
242
242
|
continue;
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
-
throw
|
|
245
|
+
throw C;
|
|
246
246
|
}
|
|
247
247
|
throw g ?? new i("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, u);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
// src/runtime-env.ts
|
|
251
|
+
function ne() {
|
|
252
|
+
try {
|
|
253
|
+
if (typeof process < "u" && process.env)
|
|
254
|
+
return process.env.NODE_ENV === "production";
|
|
255
|
+
} catch {
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
function $(t) {
|
|
260
|
+
return t === "dev" && !ne();
|
|
261
|
+
}
|
|
262
|
+
|
|
250
263
|
// src/checkout.ts
|
|
251
264
|
function T(t, e) {
|
|
252
265
|
let n = t?.accessToken || t?.idToken;
|
|
@@ -257,7 +270,7 @@ function T(t, e) {
|
|
|
257
270
|
);
|
|
258
271
|
return { requireAuth: false, headers: { authorization: `Bearer ${n}` } };
|
|
259
272
|
}
|
|
260
|
-
function
|
|
273
|
+
function re(t) {
|
|
261
274
|
if (!t || typeof t != "object")
|
|
262
275
|
throw new i("invalid_response", "checkout.start response is not an object");
|
|
263
276
|
let e = t;
|
|
@@ -273,7 +286,7 @@ function te(t) {
|
|
|
273
286
|
requiresKyc: e.requiresKyc === true
|
|
274
287
|
};
|
|
275
288
|
}
|
|
276
|
-
function
|
|
289
|
+
function oe(t) {
|
|
277
290
|
if (!t || typeof t != "object")
|
|
278
291
|
throw new i("invalid_response", "checkout.get response is not an object");
|
|
279
292
|
let e = t, n = e.intent;
|
|
@@ -295,20 +308,20 @@ function ne(t) {
|
|
|
295
308
|
isStale: e.isStale === true
|
|
296
309
|
};
|
|
297
310
|
}
|
|
298
|
-
function
|
|
311
|
+
function ie() {
|
|
299
312
|
try {
|
|
300
313
|
return typeof globalThis < "u" && typeof globalThis.window < "u" && typeof globalThis.location < "u" && typeof globalThis.location.assign == "function";
|
|
301
314
|
} catch {
|
|
302
315
|
return false;
|
|
303
316
|
}
|
|
304
317
|
}
|
|
305
|
-
function
|
|
318
|
+
function se(t) {
|
|
306
319
|
try {
|
|
307
320
|
globalThis.location.assign(t);
|
|
308
321
|
} catch {
|
|
309
322
|
}
|
|
310
323
|
}
|
|
311
|
-
function
|
|
324
|
+
function ae(t) {
|
|
312
325
|
return {
|
|
313
326
|
async start(e) {
|
|
314
327
|
if (!e?.productId)
|
|
@@ -326,15 +339,15 @@ function ie(t) {
|
|
|
326
339
|
let { requireAuth: r, headers: o } = T(
|
|
327
340
|
{ accessToken: e.accessToken, idToken: e.idToken },
|
|
328
341
|
"start"
|
|
329
|
-
), a = await
|
|
342
|
+
), a = await k(t, {
|
|
330
343
|
method: "POST",
|
|
331
344
|
path: "/api/v1/checkout/intents",
|
|
332
345
|
body: n,
|
|
333
346
|
requireAuth: r,
|
|
334
347
|
headers: o,
|
|
335
348
|
idempotencyKey: true
|
|
336
|
-
}), c =
|
|
337
|
-
return e.autoRedirect !== false &&
|
|
349
|
+
}), c = re(a);
|
|
350
|
+
return e.autoRedirect !== false && ie() && se(c.redirectUrl), c;
|
|
338
351
|
},
|
|
339
352
|
async get(e, n) {
|
|
340
353
|
if (!e || typeof e != "string")
|
|
@@ -342,13 +355,13 @@ function ie(t) {
|
|
|
342
355
|
let { requireAuth: r, headers: o } = T(
|
|
343
356
|
{ accessToken: n?.accessToken, idToken: n?.idToken },
|
|
344
357
|
"get"
|
|
345
|
-
), a = await
|
|
358
|
+
), a = await k(t, {
|
|
346
359
|
method: "GET",
|
|
347
360
|
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
348
361
|
requireAuth: r,
|
|
349
362
|
headers: o
|
|
350
363
|
});
|
|
351
|
-
return
|
|
364
|
+
return oe(a);
|
|
352
365
|
},
|
|
353
366
|
async cancel(e, n) {
|
|
354
367
|
if (!e || typeof e != "string")
|
|
@@ -359,7 +372,7 @@ function ie(t) {
|
|
|
359
372
|
);
|
|
360
373
|
return {
|
|
361
374
|
ok: true,
|
|
362
|
-
alreadyCancelled: (await
|
|
375
|
+
alreadyCancelled: (await k(t, {
|
|
363
376
|
method: "DELETE",
|
|
364
377
|
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
365
378
|
requireAuth: r,
|
|
@@ -412,8 +425,8 @@ var R = class {
|
|
|
412
425
|
return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled: o };
|
|
413
426
|
}
|
|
414
427
|
};
|
|
415
|
-
function
|
|
416
|
-
return t.env
|
|
428
|
+
function Te(t) {
|
|
429
|
+
return $(t.env) ? new R() : ae(t);
|
|
417
430
|
}
|
|
418
431
|
|
|
419
|
-
export { R as MockCheckout,
|
|
432
|
+
export { R as MockCheckout, Te as createCheckoutNamespace };
|
package/dist/db-react.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { at as SyncState, ay as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } from './types-Bl_4HROd.cjs';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.cjs';
|
|
4
4
|
|
package/dist/db-react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { at as SyncState, ay as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } from './types-Bqnsqvow.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
|
4
4
|
|