@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/checkout.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/errors.ts
|
|
4
|
-
var
|
|
4
|
+
var o = class t extends Error {
|
|
5
5
|
code;
|
|
6
6
|
status;
|
|
7
7
|
requestId;
|
|
@@ -14,425 +14,342 @@ 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, n, r, s, a) {
|
|
18
|
+
super(n), this.name = "NeetruError", this.code = e, this.status = r, this.requestId = s, this.reason = a, 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 E() {
|
|
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 o(
|
|
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 P = {
|
|
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 b(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 M(t, e) {
|
|
43
|
+
let n = b(t).split(".").map(Number), r = b(e).split(".").map(Number), s = Math.max(n.length, r.length);
|
|
44
|
+
for (let a = 0; a < s; a++) {
|
|
45
|
+
let d = n[a] ?? 0, u = r[a] ?? 0;
|
|
46
|
+
if (d !== u) return d - u;
|
|
57
47
|
}
|
|
58
48
|
return 0;
|
|
59
49
|
}
|
|
60
|
-
function
|
|
50
|
+
function D() {
|
|
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 $() {
|
|
58
|
+
let t = D();
|
|
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 v = /* @__PURE__ */ new Set();
|
|
62
|
+
function K(t) {
|
|
63
|
+
if (!t) return;
|
|
64
|
+
let e = $(), n = P[e];
|
|
65
|
+
if (!n) return;
|
|
66
|
+
let r = b(t);
|
|
67
|
+
if (M(r, n) < 0) {
|
|
68
|
+
let s = `${e}:${r}`;
|
|
69
|
+
v.has(s) || (v.add(s), console.warn(
|
|
70
|
+
`[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.`
|
|
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 j = 2, G = 0, H = /* @__PURE__ */ new Set(["GET", "HEAD"]), F = /* @__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 x(t) {
|
|
80
|
+
let e = 200 * Math.pow(4, t), n = e * 0.2 * (Math.random() * 2 - 1);
|
|
81
|
+
return Math.max(50, Math.round(e + n));
|
|
101
82
|
}
|
|
102
|
-
var
|
|
103
|
-
function
|
|
104
|
-
if (!
|
|
105
|
-
|
|
106
|
-
if (Number.isFinite(
|
|
107
|
-
|
|
108
|
-
if (Number.isFinite(
|
|
109
|
-
|
|
110
|
-
if (
|
|
83
|
+
var A = 6e4;
|
|
84
|
+
function B(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), A);
|
|
88
|
+
let n = Date.parse(t);
|
|
89
|
+
if (Number.isFinite(n)) {
|
|
90
|
+
let r = n - Date.now();
|
|
91
|
+
if (r > 0) return Math.min(r, A);
|
|
111
92
|
}
|
|
112
93
|
return null;
|
|
113
94
|
}
|
|
114
|
-
function
|
|
115
|
-
return new Promise((
|
|
95
|
+
function U(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 L(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, n) {
|
|
102
|
+
let r = t.replace(/\/+$/, ""), s = e.startsWith("/") ? e : `/${e}`, a = new URL(`${r}${s}`);
|
|
103
|
+
if (n)
|
|
104
|
+
for (let [d, u] of Object.entries(n))
|
|
105
|
+
u !== void 0 && a.searchParams.set(d, String(u));
|
|
106
|
+
return a.toString();
|
|
138
107
|
}
|
|
139
|
-
async function
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
108
|
+
async function q(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 y(t, e) {
|
|
118
|
+
let n = e.method ?? "GET", r = z(t.baseUrl, e.path, e.query), s = H.has(n) ? j : G, a = e.retries ?? s, 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
|
+
}, u = D();
|
|
122
|
+
if (u && (d["x-neetru-sdk-version"] = u), e.requireAuth) {
|
|
123
|
+
if (!t.apiKey)
|
|
124
|
+
throw new o(
|
|
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
|
-
headers.authorization = `Bearer ${config.apiKey}`;
|
|
169
|
-
}
|
|
170
|
-
if (opts.idempotencyKey) {
|
|
171
|
-
const key = typeof opts.idempotencyKey === "string" ? opts.idempotencyKey : generateIdempotencyKey();
|
|
172
|
-
headers["idempotency-key"] = key;
|
|
128
|
+
d.authorization = `Bearer ${t.apiKey}`;
|
|
173
129
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
130
|
+
if (e.idempotencyKey) {
|
|
131
|
+
let f = typeof e.idempotencyKey == "string" ? e.idempotencyKey : E();
|
|
132
|
+
d["idempotency-key"] = f;
|
|
177
133
|
}
|
|
178
|
-
let
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
134
|
+
let I = e.body !== void 0 && n !== "GET" && n !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
135
|
+
I !== void 0 && (d["content-type"] = "application/json");
|
|
136
|
+
let g = null, p = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
|
|
137
|
+
for (let f = 0; f <= a; f++) {
|
|
138
|
+
if (p != null && Date.now() >= p)
|
|
139
|
+
throw g ?? new o("network_error", "Deadline excedido antes de completar a request");
|
|
140
|
+
let w = { method: n, headers: d };
|
|
141
|
+
I !== void 0 && (w.body = I);
|
|
142
|
+
let N = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
|
|
143
|
+
w.signal = AbortSignal.timeout(N);
|
|
144
|
+
let c;
|
|
184
145
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
146
|
+
c = await t.fetch(r, w);
|
|
147
|
+
} catch (i) {
|
|
148
|
+
let k = i instanceof DOMException && i.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${i instanceof Error ? i.message : "fetch failed"}`;
|
|
149
|
+
if (g = new o("network_error", k), f < a) {
|
|
150
|
+
let S = x(f);
|
|
151
|
+
if (p == null || Date.now() + S < p) {
|
|
152
|
+
await U(S);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
192
155
|
}
|
|
193
|
-
throw
|
|
156
|
+
throw g;
|
|
194
157
|
}
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const parsed = await safeJson(res);
|
|
200
|
-
return parsed;
|
|
158
|
+
let O = c.headers.get("x-request-id") ?? c.headers.get("x-correlation-id") ?? void 0;
|
|
159
|
+
if (c.ok) {
|
|
160
|
+
let i = c.headers.get("x-neetru-version");
|
|
161
|
+
return i && K(i), await q(c);
|
|
201
162
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (body && typeof body === "object") {
|
|
207
|
-
const errField = body.error;
|
|
208
|
-
if (typeof errField === "string") {
|
|
209
|
-
message = errField;
|
|
210
|
-
} else if (errField && typeof errField === "object") {
|
|
211
|
-
if (typeof errField.code === "string") code = errField.code;
|
|
212
|
-
if (typeof errField.message === "string") message = errField.message;
|
|
213
|
-
if (typeof errField.reason === "string") reason = errField.reason;
|
|
214
|
-
} else {
|
|
215
|
-
if (typeof body.code === "string") code = body.code;
|
|
216
|
-
if (typeof body.message === "string") message = body.message;
|
|
217
|
-
}
|
|
218
|
-
if (typeof body.reason === "string") reason = body.reason;
|
|
163
|
+
let l = await q(c), m = L(c.status), h = `HTTP ${c.status}`, T;
|
|
164
|
+
if (l && typeof l == "object") {
|
|
165
|
+
let i = l.error;
|
|
166
|
+
typeof i == "string" ? h = i : i && typeof i == "object" ? (typeof i.code == "string" && (m = i.code), typeof i.message == "string" && (h = i.message), typeof i.reason == "string" && (T = i.reason)) : (typeof l.code == "string" && (m = l.code), typeof l.message == "string" && (h = l.message)), typeof l.reason == "string" && (T = l.reason);
|
|
219
167
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (isRetryable && attempt < maxRetries) {
|
|
224
|
-
const retryAfter = parseRetryAfter(res.headers.get("retry-after"));
|
|
225
|
-
const delay = retryAfter ?? backoffMs(attempt);
|
|
226
|
-
await sleep(delay);
|
|
227
|
-
continue;
|
|
168
|
+
if (c.status === 410) {
|
|
169
|
+
let i = c.headers.get("x-neetru-replacement");
|
|
170
|
+
h === `HTTP ${c.status}` && (h = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), i && !h.includes(i) && (h += ` Substituto: ${i}.`);
|
|
228
171
|
}
|
|
229
|
-
|
|
172
|
+
let R = new o(m, h, c.status, O, T);
|
|
173
|
+
if (g = R, F.has(m) && f < a) {
|
|
174
|
+
let k = B(c.headers.get("retry-after")) ?? x(f);
|
|
175
|
+
if (p == null || Date.now() + k < p) {
|
|
176
|
+
await U(k);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
throw R;
|
|
230
181
|
}
|
|
231
|
-
throw
|
|
182
|
+
throw g ?? new o("unknown", "unexpected httpRequest exit");
|
|
232
183
|
}
|
|
233
184
|
|
|
234
185
|
// src/checkout.ts
|
|
235
|
-
function
|
|
236
|
-
|
|
237
|
-
if (!
|
|
238
|
-
throw new
|
|
186
|
+
function _(t, e) {
|
|
187
|
+
let n = t?.accessToken || t?.idToken;
|
|
188
|
+
if (!n || typeof n != "string")
|
|
189
|
+
throw new o(
|
|
239
190
|
"validation_failed",
|
|
240
|
-
`checkout.${
|
|
191
|
+
`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.`
|
|
241
192
|
);
|
|
242
|
-
}
|
|
243
|
-
return { requireAuth: false, headers: { authorization: `Bearer ${token}` } };
|
|
193
|
+
return { requireAuth: false, headers: { authorization: `Bearer ${n}` } };
|
|
244
194
|
}
|
|
245
|
-
function
|
|
246
|
-
if (!
|
|
247
|
-
throw new
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (typeof r.redirectUrl !== "string" || !r.redirectUrl) {
|
|
254
|
-
throw new NeetruError("invalid_response", "checkout.start response missing redirectUrl");
|
|
255
|
-
}
|
|
195
|
+
function V(t) {
|
|
196
|
+
if (!t || typeof t != "object")
|
|
197
|
+
throw new o("invalid_response", "checkout.start response is not an object");
|
|
198
|
+
let e = t;
|
|
199
|
+
if (typeof e.intentId != "string" || !e.intentId)
|
|
200
|
+
throw new o("invalid_response", "checkout.start response missing intentId");
|
|
201
|
+
if (typeof e.redirectUrl != "string" || !e.redirectUrl)
|
|
202
|
+
throw new o("invalid_response", "checkout.start response missing redirectUrl");
|
|
256
203
|
return {
|
|
257
|
-
intentId:
|
|
258
|
-
redirectUrl:
|
|
259
|
-
status:
|
|
260
|
-
expiresAt: typeof
|
|
261
|
-
requiresKyc:
|
|
204
|
+
intentId: e.intentId,
|
|
205
|
+
redirectUrl: e.redirectUrl,
|
|
206
|
+
status: e.status ?? "pending",
|
|
207
|
+
expiresAt: typeof e.expiresAt == "string" ? e.expiresAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
208
|
+
requiresKyc: e.requiresKyc === true
|
|
262
209
|
};
|
|
263
210
|
}
|
|
264
|
-
function
|
|
265
|
-
if (!
|
|
266
|
-
throw new
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
throw new
|
|
272
|
-
}
|
|
273
|
-
if (typeof intent.intentId !== "string") {
|
|
274
|
-
throw new NeetruError("invalid_response", "checkout.get response missing intentId");
|
|
275
|
-
}
|
|
211
|
+
function J(t) {
|
|
212
|
+
if (!t || typeof t != "object")
|
|
213
|
+
throw new o("invalid_response", "checkout.get response is not an object");
|
|
214
|
+
let e = t, n = e.intent;
|
|
215
|
+
if (!n || typeof n != "object")
|
|
216
|
+
throw new o("invalid_response", "checkout.get response missing intent");
|
|
217
|
+
if (typeof n.intentId != "string")
|
|
218
|
+
throw new o("invalid_response", "checkout.get response missing intentId");
|
|
276
219
|
return {
|
|
277
|
-
intentId:
|
|
278
|
-
uid:
|
|
279
|
-
targetTenantId:
|
|
280
|
-
targetTenantType:
|
|
281
|
-
productId:
|
|
282
|
-
planId:
|
|
283
|
-
callbackUrl:
|
|
284
|
-
status:
|
|
285
|
-
stripeSessionId:
|
|
286
|
-
expiresAt:
|
|
287
|
-
isStale:
|
|
220
|
+
intentId: n.intentId,
|
|
221
|
+
uid: n.uid ?? "",
|
|
222
|
+
targetTenantId: n.targetTenantId ?? "",
|
|
223
|
+
targetTenantType: n.targetTenantType ?? "pf",
|
|
224
|
+
productId: n.productId ?? "",
|
|
225
|
+
planId: n.planId ?? "",
|
|
226
|
+
callbackUrl: n.callbackUrl ?? "",
|
|
227
|
+
status: n.status ?? "pending",
|
|
228
|
+
stripeSessionId: n.stripeSessionId ?? null,
|
|
229
|
+
expiresAt: n.expiresAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
230
|
+
isStale: e.isStale === true
|
|
288
231
|
};
|
|
289
232
|
}
|
|
290
|
-
function
|
|
233
|
+
function Y() {
|
|
291
234
|
try {
|
|
292
|
-
return typeof globalThis
|
|
235
|
+
return typeof globalThis < "u" && typeof globalThis.window < "u" && typeof globalThis.location < "u" && typeof globalThis.location.assign == "function";
|
|
293
236
|
} catch {
|
|
294
237
|
return false;
|
|
295
238
|
}
|
|
296
239
|
}
|
|
297
|
-
function
|
|
240
|
+
function W(t) {
|
|
298
241
|
try {
|
|
299
|
-
globalThis.location.assign(
|
|
242
|
+
globalThis.location.assign(t);
|
|
300
243
|
} catch {
|
|
301
244
|
}
|
|
302
245
|
}
|
|
303
|
-
function
|
|
246
|
+
function X(t) {
|
|
304
247
|
return {
|
|
305
|
-
async start(
|
|
306
|
-
if (!
|
|
307
|
-
throw new
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
productId: input.productId,
|
|
317
|
-
planId: input.planId,
|
|
318
|
-
callbackUrl: input.callbackUrl
|
|
248
|
+
async start(e) {
|
|
249
|
+
if (!e?.productId)
|
|
250
|
+
throw new o("validation_failed", "checkout.start: productId is required");
|
|
251
|
+
if (!e?.planId)
|
|
252
|
+
throw new o("validation_failed", "checkout.start: planId is required");
|
|
253
|
+
if (!e?.callbackUrl)
|
|
254
|
+
throw new o("validation_failed", "checkout.start: callbackUrl is required");
|
|
255
|
+
let n = {
|
|
256
|
+
productId: e.productId,
|
|
257
|
+
planId: e.planId,
|
|
258
|
+
callbackUrl: e.callbackUrl
|
|
319
259
|
};
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
{ accessToken: input.accessToken, idToken: input.idToken },
|
|
260
|
+
e.tenantType && (n.targetTenantType = e.tenantType), e.tenantId && (n.targetTenantId = e.tenantId);
|
|
261
|
+
let { requireAuth: r, headers: s } = _(
|
|
262
|
+
{ accessToken: e.accessToken, idToken: e.idToken },
|
|
324
263
|
"start"
|
|
325
|
-
)
|
|
326
|
-
const raw = await httpRequest(config, {
|
|
264
|
+
), a = await y(t, {
|
|
327
265
|
method: "POST",
|
|
328
266
|
path: "/api/v1/checkout/intents",
|
|
329
|
-
body,
|
|
330
|
-
requireAuth,
|
|
331
|
-
headers,
|
|
267
|
+
body: n,
|
|
268
|
+
requireAuth: r,
|
|
269
|
+
headers: s,
|
|
332
270
|
idempotencyKey: true
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
const shouldRedirect = input.autoRedirect !== false;
|
|
336
|
-
if (shouldRedirect && inBrowser()) {
|
|
337
|
-
performRedirect(result.redirectUrl);
|
|
338
|
-
}
|
|
339
|
-
return result;
|
|
271
|
+
}), d = V(a);
|
|
272
|
+
return e.autoRedirect !== false && Y() && W(d.redirectUrl), d;
|
|
340
273
|
},
|
|
341
|
-
async get(
|
|
342
|
-
if (!
|
|
343
|
-
throw new
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
{ accessToken: opts?.accessToken, idToken: opts?.idToken },
|
|
274
|
+
async get(e, n) {
|
|
275
|
+
if (!e || typeof e != "string")
|
|
276
|
+
throw new o("validation_failed", "checkout.get: intentId is required");
|
|
277
|
+
let { requireAuth: r, headers: s } = _(
|
|
278
|
+
{ accessToken: n?.accessToken, idToken: n?.idToken },
|
|
347
279
|
"get"
|
|
348
|
-
)
|
|
349
|
-
const raw = await httpRequest(config, {
|
|
280
|
+
), a = await y(t, {
|
|
350
281
|
method: "GET",
|
|
351
|
-
path: `/api/v1/checkout/intents/${encodeURIComponent(
|
|
352
|
-
requireAuth,
|
|
353
|
-
headers
|
|
282
|
+
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
283
|
+
requireAuth: r,
|
|
284
|
+
headers: s
|
|
354
285
|
});
|
|
355
|
-
return
|
|
286
|
+
return J(a);
|
|
356
287
|
},
|
|
357
|
-
async cancel(
|
|
358
|
-
if (!
|
|
359
|
-
throw new
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
{ accessToken: opts?.accessToken, idToken: opts?.idToken },
|
|
288
|
+
async cancel(e, n) {
|
|
289
|
+
if (!e || typeof e != "string")
|
|
290
|
+
throw new o("validation_failed", "checkout.cancel: intentId is required");
|
|
291
|
+
let { requireAuth: r, headers: s } = _(
|
|
292
|
+
{ accessToken: n?.accessToken, idToken: n?.idToken },
|
|
363
293
|
"cancel"
|
|
364
294
|
);
|
|
365
|
-
const raw = await httpRequest(config, {
|
|
366
|
-
method: "DELETE",
|
|
367
|
-
path: `/api/v1/checkout/intents/${encodeURIComponent(intentId)}`,
|
|
368
|
-
requireAuth,
|
|
369
|
-
headers
|
|
370
|
-
});
|
|
371
295
|
return {
|
|
372
296
|
ok: true,
|
|
373
|
-
alreadyCancelled:
|
|
297
|
+
alreadyCancelled: (await y(t, {
|
|
298
|
+
method: "DELETE",
|
|
299
|
+
path: `/api/v1/checkout/intents/${encodeURIComponent(e)}`,
|
|
300
|
+
requireAuth: r,
|
|
301
|
+
headers: s
|
|
302
|
+
}))?.alreadyCancelled === true
|
|
374
303
|
};
|
|
375
304
|
}
|
|
376
305
|
};
|
|
377
306
|
}
|
|
378
|
-
var
|
|
307
|
+
var C = class {
|
|
379
308
|
intents = /* @__PURE__ */ new Map();
|
|
380
|
-
async start(
|
|
381
|
-
if (!
|
|
382
|
-
throw new
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const intentId = `chk_mock_${Math.random().toString(36).slice(2, 10)}`;
|
|
391
|
-
const expiresAt = new Date(Date.now() + 15 * 60 * 1e3).toISOString();
|
|
392
|
-
const redirectUrl = `https://localhost:9003/portal/checkout/${intentId}`;
|
|
393
|
-
this.intents.set(intentId, {
|
|
394
|
-
intentId,
|
|
309
|
+
async start(e) {
|
|
310
|
+
if (!e?.productId)
|
|
311
|
+
throw new o("validation_failed", "checkout.start: productId is required");
|
|
312
|
+
if (!e?.planId)
|
|
313
|
+
throw new o("validation_failed", "checkout.start: planId is required");
|
|
314
|
+
if (!e?.callbackUrl)
|
|
315
|
+
throw new o("validation_failed", "checkout.start: callbackUrl is required");
|
|
316
|
+
let n = `chk_mock_${Math.random().toString(36).slice(2, 10)}`, r = new Date(Date.now() + 900 * 1e3).toISOString(), s = `https://localhost:9003/portal/checkout/${n}`;
|
|
317
|
+
return this.intents.set(n, {
|
|
318
|
+
intentId: n,
|
|
395
319
|
uid: "dev-fixture-uid",
|
|
396
|
-
targetTenantId:
|
|
397
|
-
targetTenantType:
|
|
398
|
-
productId:
|
|
399
|
-
planId:
|
|
400
|
-
callbackUrl:
|
|
320
|
+
targetTenantId: e.tenantId ?? "dev-fixture-uid",
|
|
321
|
+
targetTenantType: e.tenantType ?? "pf",
|
|
322
|
+
productId: e.productId,
|
|
323
|
+
planId: e.planId,
|
|
324
|
+
callbackUrl: e.callbackUrl,
|
|
401
325
|
status: "pending",
|
|
402
326
|
stripeSessionId: null,
|
|
403
|
-
expiresAt
|
|
404
|
-
})
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
redirectUrl,
|
|
327
|
+
expiresAt: r
|
|
328
|
+
}), {
|
|
329
|
+
intentId: n,
|
|
330
|
+
redirectUrl: s,
|
|
408
331
|
status: "pending",
|
|
409
|
-
expiresAt,
|
|
332
|
+
expiresAt: r,
|
|
410
333
|
requiresKyc: false
|
|
411
334
|
};
|
|
412
335
|
}
|
|
413
|
-
async get(
|
|
414
|
-
|
|
415
|
-
if (!
|
|
416
|
-
throw new
|
|
417
|
-
}
|
|
418
|
-
return { ...found };
|
|
336
|
+
async get(e, n) {
|
|
337
|
+
let r = this.intents.get(e);
|
|
338
|
+
if (!r)
|
|
339
|
+
throw new o("not_found", `Mock intent ${e} not found`);
|
|
340
|
+
return { ...r };
|
|
419
341
|
}
|
|
420
|
-
async cancel(
|
|
421
|
-
|
|
422
|
-
if (!
|
|
423
|
-
throw new
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
this.intents.set(intentId, { ...found, status: "cancelled" });
|
|
427
|
-
return { ok: true, alreadyCancelled };
|
|
342
|
+
async cancel(e, n) {
|
|
343
|
+
let r = this.intents.get(e);
|
|
344
|
+
if (!r)
|
|
345
|
+
throw new o("not_found", `Mock intent ${e} not found`);
|
|
346
|
+
let s = r.status === "cancelled";
|
|
347
|
+
return this.intents.set(e, { ...r, status: "cancelled" }), { ok: true, alreadyCancelled: s };
|
|
428
348
|
}
|
|
429
349
|
};
|
|
430
|
-
function
|
|
431
|
-
|
|
432
|
-
return createHttpCheckoutNamespace(config);
|
|
350
|
+
function ae(t) {
|
|
351
|
+
return t.env === "dev" ? new C() : X(t);
|
|
433
352
|
}
|
|
434
353
|
|
|
435
|
-
exports.MockCheckout =
|
|
436
|
-
exports.createCheckoutNamespace =
|
|
437
|
-
//# sourceMappingURL=checkout.cjs.map
|
|
438
|
-
//# sourceMappingURL=checkout.cjs.map
|
|
354
|
+
exports.MockCheckout = C;
|
|
355
|
+
exports.createCheckoutNamespace = ae;
|