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