@neetru/sdk 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +66 -1
- package/dist/ai.cjs +221 -177
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +221 -177
- package/dist/auth.cjs +1227 -1064
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +1224 -1061
- package/dist/catalog.cjs +164 -97
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +164 -97
- package/dist/checkout.cjs +182 -115
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +181 -114
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +370 -298
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +362 -290
- package/dist/entitlements.cjs +17 -10
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +17 -10
- package/dist/errors.cjs +15 -8
- package/dist/errors.d.cts +24 -3
- package/dist/errors.d.ts +24 -3
- package/dist/errors.mjs +14 -7
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +1409 -1075
- package/dist/index.d.cts +177 -3
- package/dist/index.d.ts +177 -3
- package/dist/index.mjs +1544 -1217
- package/dist/mobile.cjs +400 -181
- package/dist/mobile.d.cts +59 -4
- package/dist/mobile.d.ts +59 -4
- package/dist/mobile.mjs +400 -181
- package/dist/mocks.cjs +9 -2
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs +9 -2
- package/dist/notifications.cjs +197 -130
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +196 -129
- package/dist/react.cjs +303 -282
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +295 -274
- package/dist/support.cjs +299 -229
- package/dist/support.d.cts +8 -4
- package/dist/support.d.ts +8 -4
- package/dist/support.mjs +298 -228
- package/dist/telemetry.cjs +234 -167
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +234 -167
- package/dist/{types-Bx4kTLmk.d.cts → types-D-9bjlM0.d.cts} +48 -1
- package/dist/{types-Dx0IrOSF.d.ts → types-bVztFQTI.d.ts} +48 -1
- package/dist/usage.cjs +183 -116
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +183 -116
- package/dist/webhooks.cjs +215 -148
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +212 -145
- package/package.json +2 -1
package/dist/checkout.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,8 +12,15 @@ var o = class t extends Error {
|
|
|
12
12
|
* para um `NeetruDbErrorCode` mais específico (recuperável vs não).
|
|
13
13
|
*/
|
|
14
14
|
reason;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
|
|
17
|
+
* chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
|
|
18
|
+
* mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
|
|
19
|
+
* `undefined` em erros que acontecem antes de qualquer requisição.
|
|
20
|
+
*/
|
|
21
|
+
correlationId;
|
|
22
|
+
constructor(e, n, r, o, a, c) {
|
|
23
|
+
super(n), this.name = "NeetruError", this.code = e, this.status = r, this.requestId = o, this.reason = a, this.correlationId = c, Object.setPrototypeOf(this, t.prototype);
|
|
17
24
|
}
|
|
18
25
|
};
|
|
19
26
|
|
|
@@ -22,14 +29,66 @@ function E() {
|
|
|
22
29
|
let t = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
23
30
|
if (t && typeof t.randomUUID == "function")
|
|
24
31
|
return t.randomUUID();
|
|
25
|
-
throw new
|
|
32
|
+
throw new i(
|
|
26
33
|
"runtime_unsupported",
|
|
27
34
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
28
35
|
);
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
// src/correlation.ts
|
|
39
|
+
var A = "x-correlation-id";
|
|
40
|
+
var L = /^[A-Za-z0-9._:\-]+$/;
|
|
41
|
+
function x(t) {
|
|
42
|
+
return typeof t == "string" && t.length > 0 && t.length <= 128 && L.test(t);
|
|
43
|
+
}
|
|
44
|
+
function H() {
|
|
45
|
+
let t = globalThis.crypto;
|
|
46
|
+
try {
|
|
47
|
+
if (t && typeof t.randomUUID == "function") return t.randomUUID();
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
let e = new Uint8Array(16), n = false;
|
|
51
|
+
try {
|
|
52
|
+
t && typeof t.getRandomValues == "function" && (t.getRandomValues(e), n = !0);
|
|
53
|
+
} catch {
|
|
54
|
+
n = false;
|
|
55
|
+
}
|
|
56
|
+
if (!n)
|
|
57
|
+
for (let o = 0; o < e.length; o++) e[o] = Math.floor(Math.random() * 256);
|
|
58
|
+
e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
|
|
59
|
+
let r = Array.from(e, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
60
|
+
return `${r.slice(0, 8)}-${r.slice(8, 12)}-${r.slice(12, 16)}-${r.slice(16, 20)}-${r.slice(20)}`;
|
|
61
|
+
}
|
|
62
|
+
function N(t, e) {
|
|
63
|
+
let n, r = {};
|
|
64
|
+
for (let [a, c] of Object.entries(t)) {
|
|
65
|
+
if (a.toLowerCase() === A) {
|
|
66
|
+
x(c) && (n = c);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
r[a] = c;
|
|
70
|
+
}
|
|
71
|
+
let o = n ?? (x(e) ? e : void 0) ?? H();
|
|
72
|
+
return r[A] = o, { headers: r, correlationId: o };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/server-only-key.ts
|
|
76
|
+
function D() {
|
|
77
|
+
try {
|
|
78
|
+
let t = globalThis.navigator;
|
|
79
|
+
if (t && t.product === "ReactNative") return "react-native";
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
let t = globalThis;
|
|
84
|
+
if (typeof t.window < "u" && typeof t.document < "u") return "browser";
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
31
90
|
// src/http.ts
|
|
32
|
-
var
|
|
91
|
+
var B = {
|
|
33
92
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
34
93
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
35
94
|
3: "2026.05.1"
|
|
@@ -37,73 +96,77 @@ var P = {
|
|
|
37
96
|
function b(t) {
|
|
38
97
|
return t.split("+")[0] ?? t;
|
|
39
98
|
}
|
|
40
|
-
function
|
|
41
|
-
let n = b(t).split(".").map(Number), r = b(e).split(".").map(Number),
|
|
42
|
-
for (let a = 0; a <
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
99
|
+
function G(t, e) {
|
|
100
|
+
let n = b(t).split(".").map(Number), r = b(e).split(".").map(Number), o = Math.max(n.length, r.length);
|
|
101
|
+
for (let a = 0; a < o; a++) {
|
|
102
|
+
let c = n[a] ?? 0, u = r[a] ?? 0;
|
|
103
|
+
if (c !== u) return c - u;
|
|
45
104
|
}
|
|
46
105
|
return 0;
|
|
47
106
|
}
|
|
48
|
-
function
|
|
107
|
+
function M() {
|
|
49
108
|
try {
|
|
50
|
-
return "3.
|
|
109
|
+
return "3.8.0";
|
|
51
110
|
} catch {
|
|
52
111
|
return;
|
|
53
112
|
}
|
|
54
113
|
}
|
|
55
|
-
function
|
|
56
|
-
let t =
|
|
114
|
+
function F() {
|
|
115
|
+
let t = M();
|
|
57
116
|
return t ? parseInt(t.split(".")[0] ?? "3", 10) : 3;
|
|
58
117
|
}
|
|
59
|
-
var
|
|
60
|
-
function
|
|
118
|
+
var U = /* @__PURE__ */ new Set();
|
|
119
|
+
function V(t) {
|
|
61
120
|
if (!t) return;
|
|
62
|
-
let e =
|
|
121
|
+
let e = F(), n = B[e];
|
|
63
122
|
if (!n) return;
|
|
64
123
|
let r = b(t);
|
|
65
|
-
if (
|
|
66
|
-
let
|
|
67
|
-
|
|
124
|
+
if (G(r, n) < 0) {
|
|
125
|
+
let o = `${e}:${r}`;
|
|
126
|
+
U.has(o) || (U.add(o), console.warn(
|
|
68
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.`
|
|
69
128
|
));
|
|
70
129
|
}
|
|
71
130
|
}
|
|
72
|
-
|
|
131
|
+
function z() {
|
|
132
|
+
let t = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
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
|
+
}
|
|
135
|
+
var X = 2, Y = 0, J = /* @__PURE__ */ new Set(["GET", "HEAD"]), W = /* @__PURE__ */ new Set([
|
|
73
136
|
"rate_limited",
|
|
74
137
|
"server_error",
|
|
75
138
|
"network_error"
|
|
76
139
|
]);
|
|
77
|
-
function
|
|
140
|
+
function O(t) {
|
|
78
141
|
let e = 200 * Math.pow(4, t), n = e * 0.2 * (Math.random() * 2 - 1);
|
|
79
142
|
return Math.max(50, Math.round(e + n));
|
|
80
143
|
}
|
|
81
|
-
var
|
|
82
|
-
function
|
|
144
|
+
var q = 6e4;
|
|
145
|
+
function Z(t) {
|
|
83
146
|
if (!t) return null;
|
|
84
147
|
let e = Number(t);
|
|
85
|
-
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3),
|
|
148
|
+
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), q);
|
|
86
149
|
let n = Date.parse(t);
|
|
87
150
|
if (Number.isFinite(n)) {
|
|
88
151
|
let r = n - Date.now();
|
|
89
|
-
if (r > 0) return Math.min(r,
|
|
152
|
+
if (r > 0) return Math.min(r, q);
|
|
90
153
|
}
|
|
91
154
|
return null;
|
|
92
155
|
}
|
|
93
|
-
function
|
|
156
|
+
function K(t) {
|
|
94
157
|
return new Promise((e) => setTimeout(e, t));
|
|
95
158
|
}
|
|
96
|
-
function
|
|
159
|
+
function Q(t) {
|
|
97
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";
|
|
98
161
|
}
|
|
99
|
-
function
|
|
100
|
-
let r = t.replace(/\/+$/, ""),
|
|
162
|
+
function ee(t, e, n) {
|
|
163
|
+
let r = t.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, a = new URL(`${r}${o}`);
|
|
101
164
|
if (n)
|
|
102
|
-
for (let [
|
|
103
|
-
u !== void 0 && a.searchParams.set(
|
|
165
|
+
for (let [c, u] of Object.entries(n))
|
|
166
|
+
u !== void 0 && a.searchParams.set(c, String(u));
|
|
104
167
|
return a.toString();
|
|
105
168
|
}
|
|
106
|
-
async function
|
|
169
|
+
async function P(t) {
|
|
107
170
|
let e = await t.text();
|
|
108
171
|
if (e)
|
|
109
172
|
try {
|
|
@@ -113,91 +176,95 @@ async function q(t) {
|
|
|
113
176
|
}
|
|
114
177
|
}
|
|
115
178
|
async function y(t, e) {
|
|
116
|
-
let n = e.method ?? "GET", r =
|
|
117
|
-
accept: "application/json",
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
179
|
+
let n = e.method ?? "GET", r = ee(t.baseUrl, e.path, e.query), o = J.has(n) ? X : Y, a = e.retries ?? o, { headers: c, correlationId: u } = N(
|
|
180
|
+
{ accept: "application/json", ...e.headers },
|
|
181
|
+
e.correlationId
|
|
182
|
+
), C = M();
|
|
183
|
+
if (C && (c["x-neetru-sdk-version"] = C), e.requireAuth) {
|
|
121
184
|
if (!t.apiKey)
|
|
122
|
-
throw new
|
|
123
|
-
|
|
124
|
-
"This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
125
|
-
);
|
|
126
|
-
d.authorization = `Bearer ${t.apiKey}`;
|
|
185
|
+
throw new i("missing_api_key", z());
|
|
186
|
+
c.authorization = `Bearer ${t.apiKey}`;
|
|
127
187
|
}
|
|
128
188
|
if (e.idempotencyKey) {
|
|
129
189
|
let f = typeof e.idempotencyKey == "string" ? e.idempotencyKey : E();
|
|
130
|
-
|
|
190
|
+
c["idempotency-key"] = f;
|
|
131
191
|
}
|
|
132
192
|
let I = e.body !== void 0 && n !== "GET" && n !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
133
|
-
I !== void 0 && (
|
|
193
|
+
I !== void 0 && (c["content-type"] = "application/json");
|
|
134
194
|
let g = null, p = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
|
|
135
195
|
for (let f = 0; f <= a; f++) {
|
|
136
196
|
if (p != null && Date.now() >= p)
|
|
137
|
-
throw g ?? new
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
197
|
+
throw g ?? new i(
|
|
198
|
+
"network_error",
|
|
199
|
+
"Deadline excedido antes de completar a request",
|
|
200
|
+
void 0,
|
|
201
|
+
void 0,
|
|
202
|
+
void 0,
|
|
203
|
+
u
|
|
204
|
+
);
|
|
205
|
+
let _ = { method: n, headers: c };
|
|
206
|
+
I !== void 0 && (_.body = I);
|
|
207
|
+
let $ = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
|
|
208
|
+
_.signal = AbortSignal.timeout($);
|
|
209
|
+
let d;
|
|
143
210
|
try {
|
|
144
|
-
|
|
145
|
-
} catch (
|
|
146
|
-
let
|
|
147
|
-
if (g = new
|
|
148
|
-
let S =
|
|
211
|
+
d = await t.fetch(r, _);
|
|
212
|
+
} catch (s) {
|
|
213
|
+
let m = s instanceof DOMException && s.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${s instanceof Error ? s.message : "fetch failed"}`;
|
|
214
|
+
if (g = new i("network_error", m, void 0, void 0, void 0, u), f < a) {
|
|
215
|
+
let S = O(f);
|
|
149
216
|
if (p == null || Date.now() + S < p) {
|
|
150
|
-
await
|
|
217
|
+
await K(S);
|
|
151
218
|
continue;
|
|
152
219
|
}
|
|
153
220
|
}
|
|
154
221
|
throw g;
|
|
155
222
|
}
|
|
156
|
-
let
|
|
157
|
-
if (
|
|
158
|
-
let
|
|
159
|
-
return
|
|
223
|
+
let j = d.headers.get("x-request-id") ?? d.headers.get("x-correlation-id") ?? void 0;
|
|
224
|
+
if (d.ok) {
|
|
225
|
+
let s = d.headers.get("x-neetru-version");
|
|
226
|
+
return s && V(s), await P(d);
|
|
160
227
|
}
|
|
161
|
-
let l = await
|
|
228
|
+
let l = await P(d), k = Q(d.status), h = `HTTP ${d.status}`, w;
|
|
162
229
|
if (l && typeof l == "object") {
|
|
163
|
-
let
|
|
164
|
-
typeof
|
|
230
|
+
let s = l.error;
|
|
231
|
+
typeof s == "string" ? h = s : s && typeof s == "object" ? (typeof s.code == "string" && (k = s.code), typeof s.message == "string" && (h = s.message), typeof s.reason == "string" && (w = s.reason)) : (typeof l.code == "string" && (k = l.code), typeof l.message == "string" && (h = l.message)), typeof l.reason == "string" && (w = l.reason);
|
|
165
232
|
}
|
|
166
|
-
if (
|
|
167
|
-
let
|
|
168
|
-
h === `HTTP ${
|
|
233
|
+
if (d.status === 410) {
|
|
234
|
+
let s = d.headers.get("x-neetru-replacement");
|
|
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}.`);
|
|
169
236
|
}
|
|
170
|
-
let
|
|
171
|
-
if (g =
|
|
172
|
-
let
|
|
173
|
-
if (p == null || Date.now() +
|
|
174
|
-
await
|
|
237
|
+
let v = new i(k, h, d.status, j, w, u);
|
|
238
|
+
if (g = v, W.has(k) && f < a) {
|
|
239
|
+
let m = Z(d.headers.get("retry-after")) ?? O(f);
|
|
240
|
+
if (p == null || Date.now() + m < p) {
|
|
241
|
+
await K(m);
|
|
175
242
|
continue;
|
|
176
243
|
}
|
|
177
244
|
}
|
|
178
|
-
throw
|
|
245
|
+
throw v;
|
|
179
246
|
}
|
|
180
|
-
throw g ?? new
|
|
247
|
+
throw g ?? new i("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, u);
|
|
181
248
|
}
|
|
182
249
|
|
|
183
250
|
// src/checkout.ts
|
|
184
|
-
function
|
|
251
|
+
function T(t, e) {
|
|
185
252
|
let n = t?.accessToken || t?.idToken;
|
|
186
253
|
if (!n || typeof n != "string")
|
|
187
|
-
throw new
|
|
254
|
+
throw new i(
|
|
188
255
|
"validation_failed",
|
|
189
256
|
`checkout.${e} requer o access_token OU o id_token OIDC do usu\xE1rio final (passe \`accessToken\` ou \`idToken\`). A chave de API do SDK (nrt_*) N\xC3O \xE9 aceita pelo endpoint de checkout \u2014 ele autentica a identidade do cliente que est\xE1 assinando (Bearer access_token/id_token OIDC ou cookie de sess\xE3o). No padr\xE3o BFF/cookie, passe o \`idToken\` que seu servidor guardou no cookie httpOnly.`
|
|
190
257
|
);
|
|
191
258
|
return { requireAuth: false, headers: { authorization: `Bearer ${n}` } };
|
|
192
259
|
}
|
|
193
|
-
function
|
|
260
|
+
function te(t) {
|
|
194
261
|
if (!t || typeof t != "object")
|
|
195
|
-
throw new
|
|
262
|
+
throw new i("invalid_response", "checkout.start response is not an object");
|
|
196
263
|
let e = t;
|
|
197
264
|
if (typeof e.intentId != "string" || !e.intentId)
|
|
198
|
-
throw new
|
|
265
|
+
throw new i("invalid_response", "checkout.start response missing intentId");
|
|
199
266
|
if (typeof e.redirectUrl != "string" || !e.redirectUrl)
|
|
200
|
-
throw new
|
|
267
|
+
throw new i("invalid_response", "checkout.start response missing redirectUrl");
|
|
201
268
|
return {
|
|
202
269
|
intentId: e.intentId,
|
|
203
270
|
redirectUrl: e.redirectUrl,
|
|
@@ -206,14 +273,14 @@ function V(t) {
|
|
|
206
273
|
requiresKyc: e.requiresKyc === true
|
|
207
274
|
};
|
|
208
275
|
}
|
|
209
|
-
function
|
|
276
|
+
function ne(t) {
|
|
210
277
|
if (!t || typeof t != "object")
|
|
211
|
-
throw new
|
|
278
|
+
throw new i("invalid_response", "checkout.get response is not an object");
|
|
212
279
|
let e = t, n = e.intent;
|
|
213
280
|
if (!n || typeof n != "object")
|
|
214
|
-
throw new
|
|
281
|
+
throw new i("invalid_response", "checkout.get response missing intent");
|
|
215
282
|
if (typeof n.intentId != "string")
|
|
216
|
-
throw new
|
|
283
|
+
throw new i("invalid_response", "checkout.get response missing intentId");
|
|
217
284
|
return {
|
|
218
285
|
intentId: n.intentId,
|
|
219
286
|
uid: n.uid ?? "",
|
|
@@ -228,35 +295,35 @@ function J(t) {
|
|
|
228
295
|
isStale: e.isStale === true
|
|
229
296
|
};
|
|
230
297
|
}
|
|
231
|
-
function
|
|
298
|
+
function re() {
|
|
232
299
|
try {
|
|
233
300
|
return typeof globalThis < "u" && typeof globalThis.window < "u" && typeof globalThis.location < "u" && typeof globalThis.location.assign == "function";
|
|
234
301
|
} catch {
|
|
235
302
|
return false;
|
|
236
303
|
}
|
|
237
304
|
}
|
|
238
|
-
function
|
|
305
|
+
function oe(t) {
|
|
239
306
|
try {
|
|
240
307
|
globalThis.location.assign(t);
|
|
241
308
|
} catch {
|
|
242
309
|
}
|
|
243
310
|
}
|
|
244
|
-
function
|
|
311
|
+
function ie(t) {
|
|
245
312
|
return {
|
|
246
313
|
async start(e) {
|
|
247
314
|
if (!e?.productId)
|
|
248
|
-
throw new
|
|
315
|
+
throw new i("validation_failed", "checkout.start: productId is required");
|
|
249
316
|
if (!e?.planId)
|
|
250
|
-
throw new
|
|
317
|
+
throw new i("validation_failed", "checkout.start: planId is required");
|
|
251
318
|
if (!e?.callbackUrl)
|
|
252
|
-
throw new
|
|
319
|
+
throw new i("validation_failed", "checkout.start: callbackUrl is required");
|
|
253
320
|
let n = {
|
|
254
321
|
productId: e.productId,
|
|
255
322
|
planId: e.planId,
|
|
256
323
|
callbackUrl: e.callbackUrl
|
|
257
324
|
};
|
|
258
325
|
e.tenantType && (n.targetTenantType = e.tenantType), e.tenantId && (n.targetTenantId = e.tenantId);
|
|
259
|
-
let { requireAuth: r, headers:
|
|
326
|
+
let { requireAuth: r, headers: o } = T(
|
|
260
327
|
{ accessToken: e.accessToken, idToken: e.idToken },
|
|
261
328
|
"start"
|
|
262
329
|
), a = await y(t, {
|
|
@@ -264,29 +331,29 @@ function X(t) {
|
|
|
264
331
|
path: "/api/v1/checkout/intents",
|
|
265
332
|
body: n,
|
|
266
333
|
requireAuth: r,
|
|
267
|
-
headers:
|
|
334
|
+
headers: o,
|
|
268
335
|
idempotencyKey: true
|
|
269
|
-
}),
|
|
270
|
-
return e.autoRedirect !== false &&
|
|
336
|
+
}), c = te(a);
|
|
337
|
+
return e.autoRedirect !== false && re() && oe(c.redirectUrl), c;
|
|
271
338
|
},
|
|
272
339
|
async get(e, n) {
|
|
273
340
|
if (!e || typeof e != "string")
|
|
274
|
-
throw new
|
|
275
|
-
let { requireAuth: r, headers:
|
|
341
|
+
throw new i("validation_failed", "checkout.get: intentId is required");
|
|
342
|
+
let { requireAuth: r, headers: o } = T(
|
|
276
343
|
{ accessToken: n?.accessToken, idToken: n?.idToken },
|
|
277
344
|
"get"
|
|
278
345
|
), a = await y(t, {
|
|
279
346
|
method: "GET",
|
|
280
347
|
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
281
348
|
requireAuth: r,
|
|
282
|
-
headers:
|
|
349
|
+
headers: o
|
|
283
350
|
});
|
|
284
|
-
return
|
|
351
|
+
return ne(a);
|
|
285
352
|
},
|
|
286
353
|
async cancel(e, n) {
|
|
287
354
|
if (!e || typeof e != "string")
|
|
288
|
-
throw new
|
|
289
|
-
let { requireAuth: r, headers:
|
|
355
|
+
throw new i("validation_failed", "checkout.cancel: intentId is required");
|
|
356
|
+
let { requireAuth: r, headers: o } = T(
|
|
290
357
|
{ accessToken: n?.accessToken, idToken: n?.idToken },
|
|
291
358
|
"cancel"
|
|
292
359
|
);
|
|
@@ -296,22 +363,22 @@ function X(t) {
|
|
|
296
363
|
method: "DELETE",
|
|
297
364
|
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
298
365
|
requireAuth: r,
|
|
299
|
-
headers:
|
|
366
|
+
headers: o
|
|
300
367
|
}))?.alreadyCancelled === true
|
|
301
368
|
};
|
|
302
369
|
}
|
|
303
370
|
};
|
|
304
371
|
}
|
|
305
|
-
var
|
|
372
|
+
var R = class {
|
|
306
373
|
intents = /* @__PURE__ */ new Map();
|
|
307
374
|
async start(e) {
|
|
308
375
|
if (!e?.productId)
|
|
309
|
-
throw new
|
|
376
|
+
throw new i("validation_failed", "checkout.start: productId is required");
|
|
310
377
|
if (!e?.planId)
|
|
311
|
-
throw new
|
|
378
|
+
throw new i("validation_failed", "checkout.start: planId is required");
|
|
312
379
|
if (!e?.callbackUrl)
|
|
313
|
-
throw new
|
|
314
|
-
let n = `chk_mock_${Math.random().toString(36).slice(2, 10)}`, r = new Date(Date.now() + 900 * 1e3).toISOString(),
|
|
380
|
+
throw new i("validation_failed", "checkout.start: callbackUrl is required");
|
|
381
|
+
let n = `chk_mock_${Math.random().toString(36).slice(2, 10)}`, r = new Date(Date.now() + 900 * 1e3).toISOString(), o = `https://localhost:9003/portal/checkout/${n}`;
|
|
315
382
|
return this.intents.set(n, {
|
|
316
383
|
intentId: n,
|
|
317
384
|
uid: "dev-fixture-uid",
|
|
@@ -325,7 +392,7 @@ var C = class {
|
|
|
325
392
|
expiresAt: r
|
|
326
393
|
}), {
|
|
327
394
|
intentId: n,
|
|
328
|
-
redirectUrl:
|
|
395
|
+
redirectUrl: o,
|
|
329
396
|
status: "pending",
|
|
330
397
|
expiresAt: r,
|
|
331
398
|
requiresKyc: false
|
|
@@ -334,19 +401,19 @@ var C = class {
|
|
|
334
401
|
async get(e, n) {
|
|
335
402
|
let r = this.intents.get(e);
|
|
336
403
|
if (!r)
|
|
337
|
-
throw new
|
|
404
|
+
throw new i("not_found", `Mock intent ${e} not found`);
|
|
338
405
|
return { ...r };
|
|
339
406
|
}
|
|
340
407
|
async cancel(e, n) {
|
|
341
408
|
let r = this.intents.get(e);
|
|
342
409
|
if (!r)
|
|
343
|
-
throw new
|
|
344
|
-
let
|
|
345
|
-
return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled:
|
|
410
|
+
throw new i("not_found", `Mock intent ${e} not found`);
|
|
411
|
+
let o = r.status === "cancelled";
|
|
412
|
+
return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled: o };
|
|
346
413
|
}
|
|
347
414
|
};
|
|
348
|
-
function
|
|
349
|
-
return t.env === "dev" ? new
|
|
415
|
+
function Ie(t) {
|
|
416
|
+
return t.env === "dev" ? new R() : ie(t);
|
|
350
417
|
}
|
|
351
418
|
|
|
352
|
-
export {
|
|
419
|
+
export { R as MockCheckout, Ie as createCheckoutNamespace };
|
package/dist/db-react.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ar as SyncState, aw as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } from './types-D-9bjlM0.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 { ar as SyncState, aw as Unsubscribe, F as DbDoc, X as NeetruClient, E as DbCollectionRef, K as DbQuery } from './types-bVztFQTI.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
|
4
4
|
|