@cedros/pay-react 1.1.16 → 1.1.17
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/dist/AISettingsSection--jn-BNmd.mjs +539 -0
- package/dist/AISettingsSection-BrXUD4l_.js +51 -0
- package/dist/AutosaveIndicator-B3T328jH.mjs +35 -0
- package/dist/AutosaveIndicator-BQkm3cn8.js +1 -0
- package/dist/{CedrosContext-D7nh5-Zh.mjs → CedrosContext-BnJ2Cf7R.mjs} +1179 -642
- package/dist/CedrosContext-C26DlvLF.js +6 -0
- package/dist/CryptoButton-B4-oJ8lF.js +1 -0
- package/dist/CryptoButton-Dhxnk9d7.mjs +542 -0
- package/dist/FAQSection-BB1wJRsR.mjs +366 -0
- package/dist/FAQSection-aoAz35MV.js +1 -0
- package/dist/MessagingSection-BG9O62ko.mjs +347 -0
- package/dist/MessagingSection-DId-WJdU.js +1 -0
- package/dist/PaymentSettingsSection-D92IO4xJ.js +1 -0
- package/dist/PaymentSettingsSection-c13RAUxn.mjs +94 -0
- package/dist/SettingsSection-DUxjXl2G.js +1 -0
- package/dist/SettingsSection-htem-WL3.mjs +57 -0
- package/dist/SingleCategorySettings-BIEs6s6Z.mjs +1421 -0
- package/dist/SingleCategorySettings-CQ-osdzb.js +3 -0
- package/dist/StorefrontSection-CKTQt255.mjs +765 -0
- package/dist/StorefrontSection-DcSoDx-k.js +1 -0
- package/dist/SubscriptionsSection-C0hYf7Hr.js +1 -0
- package/dist/SubscriptionsSection-CONwHhT4.mjs +616 -0
- package/dist/Toggle-CsPSF8Dr.js +1 -0
- package/dist/Toggle-DAxIdpY4.mjs +48 -0
- package/dist/WalletManager-D6BYTwXn.js +1 -0
- package/dist/{WalletManager-oEjZhaFk.mjs → WalletManager-HXXyARQ7.mjs} +36 -32
- package/dist/components/CedrosPay.d.ts.map +1 -1
- package/dist/components/CryptoSubscribeButton.d.ts.map +1 -1
- package/dist/components/PaymentModal.d.ts.map +1 -1
- package/dist/components/SubscriptionManagementPanel.d.ts.map +1 -1
- package/dist/components/admin/AISettingsSection.d.ts.map +1 -1
- package/dist/components/admin/AdminAuthManager.d.ts +2 -1
- package/dist/components/admin/AdminAuthManager.d.ts.map +1 -1
- package/dist/components/admin/AutosaveIndicator.d.ts +7 -0
- package/dist/components/admin/AutosaveIndicator.d.ts.map +1 -0
- package/dist/components/admin/CedrosPayAdminDashboard.d.ts.map +1 -1
- package/dist/components/admin/ConfigEditor.d.ts +0 -2
- package/dist/components/admin/ConfigEditor.d.ts.map +1 -1
- package/dist/components/admin/MessagingSection.d.ts.map +1 -1
- package/dist/components/admin/ProductsSection.d.ts.map +1 -1
- package/dist/components/admin/RefundsSection.d.ts.map +1 -1
- package/dist/components/admin/SecretArrayEditor.d.ts +16 -0
- package/dist/components/admin/SecretArrayEditor.d.ts.map +1 -0
- package/dist/components/admin/SingleCategorySettings.d.ts.map +1 -1
- package/dist/components/admin/StorefrontSection.d.ts.map +1 -1
- package/dist/components/admin/Toggle.d.ts +14 -0
- package/dist/components/admin/Toggle.d.ts.map +1 -0
- package/dist/components/admin/TokenMintSelector.d.ts +27 -0
- package/dist/components/admin/TokenMintSelector.d.ts.map +1 -0
- package/dist/components/admin/configApi.d.ts +5 -3
- package/dist/components/admin/configApi.d.ts.map +1 -1
- package/dist/components/admin/index.d.ts +8 -9
- package/dist/components/admin/index.d.ts.map +1 -1
- package/dist/components/admin/sections-more.d.ts +2 -9
- package/dist/components/admin/sections-more.d.ts.map +1 -1
- package/dist/context/CedrosContext.d.ts +1 -1
- package/dist/context/CedrosContext.d.ts.map +1 -1
- package/dist/crypto-only.js +1 -1
- package/dist/crypto-only.mjs +391 -380
- package/dist/ecommerce/__tests__/inventoryHooks.test.d.ts +2 -0
- package/dist/ecommerce/__tests__/inventoryHooks.test.d.ts.map +1 -0
- package/dist/ecommerce/__tests__/storage.test.d.ts +2 -0
- package/dist/ecommerce/__tests__/storage.test.d.ts.map +1 -0
- package/dist/ecommerce/adapters/CommerceAdapter.d.ts +5 -0
- package/dist/ecommerce/adapters/CommerceAdapter.d.ts.map +1 -1
- package/dist/ecommerce/adapters/mock/mockAdapter.d.ts.map +1 -1
- package/dist/ecommerce/adapters/paywall/paywallAdapter.d.ts.map +1 -1
- package/dist/ecommerce/adapters/paywall/paywallAdapter.test.d.ts +2 -0
- package/dist/ecommerce/adapters/paywall/paywallAdapter.test.d.ts.map +1 -0
- package/dist/ecommerce/components/catalog/ProductCard.d.ts.map +1 -1
- package/dist/ecommerce/components/catalog/QuickViewDialog.d.ts.map +1 -1
- package/dist/ecommerce/components/chat/ShopChatPanel.d.ts +4 -0
- package/dist/ecommerce/components/chat/ShopChatPanel.d.ts.map +1 -1
- package/dist/ecommerce/components/checkout/PaymentStep.d.ts.map +1 -1
- package/dist/ecommerce/components/faq/FAQItem.d.ts.map +1 -1
- package/dist/ecommerce/config/context.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useAIRelatedProducts.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useCartInventory.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useHoldExpiry.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useInventoryVerification.d.ts.map +1 -1
- package/dist/ecommerce/hooks/useProducts.d.ts.map +1 -1
- package/dist/ecommerce/index.d.ts +2 -0
- package/dist/ecommerce/index.d.ts.map +1 -1
- package/dist/ecommerce/integrations/cedros-pay/useCedrosPayCheckoutAdapter.d.ts.map +1 -1
- package/dist/ecommerce/state/cart/CartProvider.d.ts.map +1 -1
- package/dist/ecommerce/state/checkout/checkoutSchema.d.ts +1 -1
- package/dist/ecommerce/state/checkout/useCheckout.d.ts.map +1 -1
- package/dist/ecommerce/templates/ProductTemplate.d.ts.map +1 -1
- package/dist/ecommerce/utils/storage.d.ts +1 -1
- package/dist/ecommerce/utils/storage.d.ts.map +1 -1
- package/dist/hooks/useCreditsPayment.d.ts.map +1 -1
- package/dist/hooks/useCreditsSubscription.d.ts.map +1 -1
- package/dist/hooks/useCryptoSubscription.d.ts.map +1 -1
- package/dist/hooks/useRefundVerification.d.ts.map +1 -1
- package/dist/hooks/useStripeCheckout.d.ts +1 -1
- package/dist/hooks/useStripeCheckout.d.ts.map +1 -1
- package/dist/hooks/useSubscription.d.ts.map +1 -1
- package/dist/hooks/useSubscriptionManagement.d.ts.map +1 -1
- package/dist/hooks/useX402Payment.d.ts.map +1 -1
- package/dist/index-2N_CMVAv.js +84 -0
- package/dist/index-C1hbnxn0.mjs +22915 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +67 -72
- package/dist/managers/CreditsManager.d.ts +6 -0
- package/dist/managers/CreditsManager.d.ts.map +1 -1
- package/dist/managers/ManagerCache.d.ts.map +1 -1
- package/dist/managers/RouteDiscoveryManager.d.ts +3 -0
- package/dist/managers/RouteDiscoveryManager.d.ts.map +1 -1
- package/dist/managers/StripeManager.d.ts +15 -0
- package/dist/managers/StripeManager.d.ts.map +1 -1
- package/dist/managers/SubscriptionChangeManager.d.ts.map +1 -1
- package/dist/managers/SubscriptionManager.d.ts +7 -14
- package/dist/managers/SubscriptionManager.d.ts.map +1 -1
- package/dist/managers/WalletManager.d.ts +2 -1
- package/dist/managers/WalletManager.d.ts.map +1 -1
- package/dist/managers/X402Manager.d.ts.map +1 -1
- package/dist/{sections-CL3lbNui.js → sections-D2GMJuKq.js} +1 -1
- package/dist/{sections-DnmB0qdx.mjs → sections-DICaHGhz.mjs} +1 -1
- package/dist/stripe-only.js +1 -1
- package/dist/stripe-only.mjs +67 -72
- package/dist/telemetry.js +1 -1
- package/dist/telemetry.mjs +23 -25
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/types/index.d.ts +13 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/useAutosave-B2p6iwh8.js +1 -0
- package/dist/useAutosave-YwMqRzqy.mjs +44 -0
- package/dist/utils/circuitBreaker.d.ts +3 -1
- package/dist/utils/circuitBreaker.d.ts.map +1 -1
- package/dist/utils/cspHelper.d.ts +6 -0
- package/dist/utils/cspHelper.d.ts.map +1 -1
- package/dist/utils/csvHelpers.d.ts +0 -41
- package/dist/utils/csvHelpers.d.ts.map +1 -1
- package/dist/utils/errorHandling.d.ts.map +1 -1
- package/dist/utils/exponentialBackoff.d.ts.map +1 -1
- package/dist/utils/requestDeduplication.d.ts.map +1 -1
- package/dist/utils/telemetry.d.ts.map +1 -1
- package/dist/utils/validateConfig.d.ts +1 -1
- package/dist/utils/validateConfig.d.ts.map +1 -1
- package/dist/walletDetection-JZR3UCOa.mjs +27 -0
- package/dist/walletDetection-bNmV5ItZ.js +1 -0
- package/dist/{walletPool-BR6etEiq.mjs → walletPool-BV_z1lEA.mjs} +1 -1
- package/dist/{walletPool-BZyAG4YS.js → walletPool-DjA7J3a9.js} +1 -1
- package/package.json +8 -7
- package/dist/CedrosContext-C2v_s8cc.js +0 -6
- package/dist/WalletManager-B5KLZK2D.js +0 -1
- package/dist/index-BU0vgA-7.js +0 -136
- package/dist/index-DWXEBUbu.mjs +0 -27912
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { g as
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var e = document.querySelectorAll('script[src^="'.concat(
|
|
1
|
+
import { jsx as W } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as Ae, useContext as ne, useState as N, useRef as ge, useEffect as I, useMemo as ee } from "react";
|
|
3
|
+
import { g as S } from "./uuid-_z3jSatJ.mjs";
|
|
4
|
+
var we = "https://js.stripe.com/v3", qe = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/;
|
|
5
|
+
var je = function() {
|
|
6
|
+
for (var e = document.querySelectorAll('script[src^="'.concat(we, '"]')), r = 0; r < e.length; r++) {
|
|
7
7
|
var a = e[r];
|
|
8
|
-
if (
|
|
8
|
+
if (qe.test(a.src))
|
|
9
9
|
return a;
|
|
10
10
|
}
|
|
11
11
|
return null;
|
|
12
|
-
},
|
|
12
|
+
}, ce = function(e) {
|
|
13
13
|
var r = "", a = document.createElement("script");
|
|
14
|
-
a.src = "".concat(
|
|
14
|
+
a.src = "".concat(we).concat(r);
|
|
15
15
|
var n = document.head || document.body;
|
|
16
16
|
if (!n)
|
|
17
17
|
throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");
|
|
18
18
|
return n.appendChild(a), a;
|
|
19
|
-
},
|
|
19
|
+
}, ze = function(e, r) {
|
|
20
20
|
!e || !e._registerWrapper || e._registerWrapper({
|
|
21
21
|
name: "stripe-js",
|
|
22
22
|
version: "4.6.0",
|
|
23
23
|
startTime: r
|
|
24
24
|
});
|
|
25
|
-
},
|
|
25
|
+
}, H = null, z = null, Q = null, Qe = function(e) {
|
|
26
26
|
return function() {
|
|
27
27
|
e(new Error("Failed to load Stripe.js"));
|
|
28
28
|
};
|
|
29
|
-
},
|
|
29
|
+
}, Ke = function(e, r) {
|
|
30
30
|
return function() {
|
|
31
31
|
window.Stripe ? e(window.Stripe) : r(new Error("Stripe.js not available"));
|
|
32
32
|
};
|
|
33
|
-
},
|
|
34
|
-
return
|
|
33
|
+
}, We = function(e) {
|
|
34
|
+
return H !== null ? H : (H = new Promise(function(r, a) {
|
|
35
35
|
if (typeof window > "u" || typeof document > "u") {
|
|
36
36
|
r(null);
|
|
37
37
|
return;
|
|
@@ -41,48 +41,48 @@ var Ue = function() {
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
try {
|
|
44
|
-
var n =
|
|
44
|
+
var n = je();
|
|
45
45
|
if (!(n && e)) {
|
|
46
46
|
if (!n)
|
|
47
|
-
n =
|
|
48
|
-
else if (n &&
|
|
47
|
+
n = ce(e);
|
|
48
|
+
else if (n && Q !== null && z !== null) {
|
|
49
49
|
var i;
|
|
50
|
-
n.removeEventListener("load",
|
|
50
|
+
n.removeEventListener("load", Q), n.removeEventListener("error", z), (i = n.parentNode) === null || i === void 0 || i.removeChild(n), n = ce(e);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
Q = Ke(r, a), z = Qe(a), n.addEventListener("load", Q), n.addEventListener("error", z);
|
|
54
54
|
} catch (o) {
|
|
55
55
|
a(o);
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
}),
|
|
59
|
-
return
|
|
58
|
+
}), H.catch(function(r) {
|
|
59
|
+
return H = null, Promise.reject(r);
|
|
60
60
|
}));
|
|
61
|
-
},
|
|
61
|
+
}, Ve = function(e, r, a) {
|
|
62
62
|
if (e === null)
|
|
63
63
|
return null;
|
|
64
64
|
var n = e.apply(void 0, r);
|
|
65
|
-
return
|
|
66
|
-
},
|
|
67
|
-
return
|
|
68
|
-
return
|
|
69
|
-
}),
|
|
65
|
+
return ze(n, a), n;
|
|
66
|
+
}, L, be = !1, ve = function() {
|
|
67
|
+
return L || (L = We(null).catch(function(e) {
|
|
68
|
+
return L = null, Promise.reject(e);
|
|
69
|
+
}), L);
|
|
70
70
|
};
|
|
71
71
|
Promise.resolve().then(function() {
|
|
72
|
-
return
|
|
72
|
+
return ve();
|
|
73
73
|
}).catch(function(t) {
|
|
74
|
-
|
|
74
|
+
be || console.warn(t);
|
|
75
75
|
});
|
|
76
|
-
var
|
|
76
|
+
var Ce = function() {
|
|
77
77
|
for (var e = arguments.length, r = new Array(e), a = 0; a < e; a++)
|
|
78
78
|
r[a] = arguments[a];
|
|
79
|
-
|
|
79
|
+
be = !0;
|
|
80
80
|
var n = Date.now();
|
|
81
|
-
return
|
|
82
|
-
return
|
|
81
|
+
return ve().then(function(i) {
|
|
82
|
+
return Ve(i, r, n);
|
|
83
83
|
});
|
|
84
|
-
},
|
|
85
|
-
class
|
|
84
|
+
}, Ge = /* @__PURE__ */ ((t) => (t[t.DEBUG = 0] = "DEBUG", t[t.INFO = 1] = "INFO", t[t.WARN = 2] = "WARN", t[t.ERROR = 3] = "ERROR", t[t.SILENT = 4] = "SILENT", t))(Ge || {});
|
|
85
|
+
class Ee {
|
|
86
86
|
config;
|
|
87
87
|
constructor(e) {
|
|
88
88
|
this.config = e;
|
|
@@ -135,24 +135,24 @@ class ye {
|
|
|
135
135
|
r(`[${i}] ${n}[${e}]`, ...a);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
const
|
|
139
|
-
let
|
|
138
|
+
const Je = () => typeof process < "u" && process.env.NODE_ENV === "development" ? 0 : 2;
|
|
139
|
+
let V = null;
|
|
140
140
|
function c() {
|
|
141
|
-
return
|
|
142
|
-
level:
|
|
141
|
+
return V || (V = new Ee({
|
|
142
|
+
level: Je(),
|
|
143
143
|
prefix: "[CedrosPay]"
|
|
144
|
-
})),
|
|
144
|
+
})), V;
|
|
145
145
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
146
|
+
function Ye(t) {
|
|
147
|
+
V = t;
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
return new
|
|
149
|
+
function Xe(t) {
|
|
150
|
+
return new Ee(t);
|
|
151
151
|
}
|
|
152
|
-
function
|
|
152
|
+
function T(t, e) {
|
|
153
153
|
return t instanceof Error ? t.message : typeof t == "string" ? t : e;
|
|
154
154
|
}
|
|
155
|
-
const
|
|
155
|
+
const Ze = {
|
|
156
156
|
service_unavailable: "Service temporarily unavailable. Please try again later or contact support.",
|
|
157
157
|
server_insufficient_funds: "Service temporarily unavailable. Please try again later or contact support.",
|
|
158
158
|
insufficient_funds_token: "Insufficient token balance in your wallet. Please add more tokens and try again.",
|
|
@@ -162,21 +162,34 @@ const Ge = {
|
|
|
162
162
|
send_failed: "Failed to send transaction. Please try again or contact support.",
|
|
163
163
|
timeout: "Transaction timed out. Please check the blockchain explorer or try again."
|
|
164
164
|
};
|
|
165
|
-
async function
|
|
165
|
+
async function g(t, e, r = !1) {
|
|
166
|
+
const a = typeof t.clone == "function", n = a ? t.clone() : void 0;
|
|
166
167
|
try {
|
|
167
|
-
const
|
|
168
|
-
if (r &&
|
|
169
|
-
c().debug(`Payment verification failed: ${
|
|
170
|
-
const
|
|
171
|
-
return
|
|
168
|
+
const i = await t.json();
|
|
169
|
+
if (r && i.verificationError) {
|
|
170
|
+
c().debug(`Payment verification failed: ${i.verificationError.code}`);
|
|
171
|
+
const o = i.verificationError.code;
|
|
172
|
+
return Ze[o] || i.verificationError.message || e;
|
|
172
173
|
}
|
|
173
|
-
return typeof
|
|
174
|
+
return typeof i.error == "string" ? i.error : i.error && typeof i.error == "object" && "message" in i.error ? i.error.message : e;
|
|
174
175
|
} catch {
|
|
175
|
-
|
|
176
|
+
if (n)
|
|
177
|
+
try {
|
|
178
|
+
const i = await n.text();
|
|
179
|
+
if (i) return i;
|
|
180
|
+
} catch {
|
|
181
|
+
}
|
|
182
|
+
if (!a && typeof t.text == "function")
|
|
183
|
+
try {
|
|
184
|
+
const i = await t.text();
|
|
185
|
+
if (i) return i;
|
|
186
|
+
} catch {
|
|
187
|
+
}
|
|
188
|
+
return e;
|
|
176
189
|
}
|
|
177
190
|
}
|
|
178
|
-
const
|
|
179
|
-
async function
|
|
191
|
+
const $e = 15e3;
|
|
192
|
+
async function p(t, e = {}, r = $e) {
|
|
180
193
|
const a = new AbortController(), n = e.signal;
|
|
181
194
|
if (n?.aborted)
|
|
182
195
|
throw a.abort(), new DOMException("The operation was aborted", "AbortError");
|
|
@@ -194,15 +207,15 @@ async function h(t, e = {}, r = We) {
|
|
|
194
207
|
clearTimeout(i), n && o && n.removeEventListener("abort", o);
|
|
195
208
|
}
|
|
196
209
|
}
|
|
197
|
-
function
|
|
210
|
+
function R(t) {
|
|
198
211
|
const { maxRequests: e, windowMs: r } = t;
|
|
199
212
|
let a = e, n = Date.now();
|
|
200
213
|
const i = e / r;
|
|
201
214
|
function o() {
|
|
202
|
-
const u = Date.now(),
|
|
203
|
-
if (
|
|
204
|
-
const
|
|
205
|
-
a = Math.min(e, a +
|
|
215
|
+
const u = Date.now(), y = u - n;
|
|
216
|
+
if (y > 0) {
|
|
217
|
+
const f = y * i;
|
|
218
|
+
a = Math.min(e, a + f), n = u;
|
|
206
219
|
}
|
|
207
220
|
}
|
|
208
221
|
function s() {
|
|
@@ -211,23 +224,23 @@ function P(t) {
|
|
|
211
224
|
function l() {
|
|
212
225
|
return o(), Math.floor(a);
|
|
213
226
|
}
|
|
214
|
-
function
|
|
227
|
+
function d() {
|
|
215
228
|
if (o(), a >= 1)
|
|
216
229
|
return 0;
|
|
217
|
-
const
|
|
218
|
-
return Math.ceil(
|
|
230
|
+
const y = (1 - a) / i;
|
|
231
|
+
return Math.ceil(y);
|
|
219
232
|
}
|
|
220
|
-
function
|
|
233
|
+
function m() {
|
|
221
234
|
a = e, n = Date.now();
|
|
222
235
|
}
|
|
223
236
|
return {
|
|
224
237
|
tryConsume: s,
|
|
225
238
|
getAvailableTokens: l,
|
|
226
|
-
getTimeUntilRefill:
|
|
227
|
-
reset:
|
|
239
|
+
getTimeUntilRefill: d,
|
|
240
|
+
reset: m
|
|
228
241
|
};
|
|
229
242
|
}
|
|
230
|
-
const
|
|
243
|
+
const M = {
|
|
231
244
|
/** 10 requests per minute - recommended for payment requests */
|
|
232
245
|
PAYMENT: { maxRequests: 10, windowMs: 6e4 },
|
|
233
246
|
/** 30 requests per minute - for quote fetching */
|
|
@@ -237,123 +250,551 @@ const T = {
|
|
|
237
250
|
/** 100 requests per minute - permissive for UI interactions */
|
|
238
251
|
PERMISSIVE: { maxRequests: 100, windowMs: 6e4 }
|
|
239
252
|
};
|
|
240
|
-
var
|
|
241
|
-
class
|
|
253
|
+
var et = /* @__PURE__ */ ((t) => (t.CLOSED = "CLOSED", t.OPEN = "OPEN", t.HALF_OPEN = "HALF_OPEN", t))(et || {});
|
|
254
|
+
class A extends Error {
|
|
242
255
|
constructor(e) {
|
|
243
256
|
super(e), this.name = "CircuitBreakerOpenError";
|
|
244
257
|
}
|
|
245
258
|
}
|
|
246
|
-
function
|
|
247
|
-
const { failureThreshold: e, timeout: r,
|
|
248
|
-
let
|
|
249
|
-
function
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
function j(t) {
|
|
260
|
+
const { failureThreshold: e, timeout: r, failureWindow: a = r * 2, name: n = "circuit-breaker" } = t;
|
|
261
|
+
let i = "CLOSED", o = [], s = 0, l = 0, d = null, m = null, u = null, y = !1;
|
|
262
|
+
function f() {
|
|
263
|
+
const _ = Date.now() - a;
|
|
264
|
+
o = o.filter((P) => P > _);
|
|
265
|
+
}
|
|
266
|
+
function h() {
|
|
267
|
+
i === "OPEN" && u !== null && Date.now() >= u && (c().debug(`[CircuitBreaker:${n}] Transitioning OPEN → HALF_OPEN (timeout expired)`), i = "HALF_OPEN", u = null);
|
|
268
|
+
}
|
|
269
|
+
function w() {
|
|
270
|
+
m = Date.now(), s++, i === "HALF_OPEN" ? (c().debug(`[CircuitBreaker:${n}] Success in HALF_OPEN → CLOSED`), i = "CLOSED", o = []) : i === "CLOSED" && (o = []);
|
|
271
|
+
}
|
|
272
|
+
function C(_) {
|
|
273
|
+
const P = Date.now();
|
|
274
|
+
d = P, o.push(P), f();
|
|
275
|
+
const Y = o.length;
|
|
276
|
+
c().warn(`[CircuitBreaker:${n}] Failure recorded (${Y}/${e}):`, _.message), i === "HALF_OPEN" ? (c().warn(`[CircuitBreaker:${n}] Failed in HALF_OPEN → OPEN`), i = "OPEN", u = P + r) : i === "CLOSED" && Y >= e && (c().error(`[CircuitBreaker:${n}] Failure threshold reached (${Y}) → OPEN`), i = "OPEN", u = P + r);
|
|
277
|
+
}
|
|
278
|
+
async function x(_) {
|
|
279
|
+
if (h(), i === "OPEN") {
|
|
280
|
+
l++;
|
|
281
|
+
const P = u ? Math.ceil((u - Date.now()) / 1e3) : 0;
|
|
282
|
+
throw new A(
|
|
283
|
+
`Circuit breaker is OPEN. Service is unavailable. Retry in ${P}s.`
|
|
264
284
|
);
|
|
265
285
|
}
|
|
286
|
+
if (i === "HALF_OPEN" && y)
|
|
287
|
+
throw l++, new A(
|
|
288
|
+
"Circuit breaker is HALF_OPEN. A probe request is already in progress."
|
|
289
|
+
);
|
|
290
|
+
i === "HALF_OPEN" && (y = !0);
|
|
266
291
|
try {
|
|
267
|
-
const
|
|
268
|
-
return
|
|
269
|
-
} catch (
|
|
270
|
-
throw
|
|
292
|
+
const P = await _();
|
|
293
|
+
return w(), P;
|
|
294
|
+
} catch (P) {
|
|
295
|
+
throw C(P instanceof Error ? P : new Error(String(P))), P;
|
|
296
|
+
} finally {
|
|
297
|
+
y && (y = !1);
|
|
271
298
|
}
|
|
272
299
|
}
|
|
273
|
-
function
|
|
274
|
-
return
|
|
275
|
-
}
|
|
276
|
-
function
|
|
277
|
-
return
|
|
278
|
-
state:
|
|
279
|
-
failures:
|
|
280
|
-
successes:
|
|
281
|
-
rejections:
|
|
282
|
-
lastFailureTime:
|
|
283
|
-
lastSuccessTime:
|
|
300
|
+
function B() {
|
|
301
|
+
return h(), i;
|
|
302
|
+
}
|
|
303
|
+
function k() {
|
|
304
|
+
return h(), f(), {
|
|
305
|
+
state: i,
|
|
306
|
+
failures: o.length,
|
|
307
|
+
successes: s,
|
|
308
|
+
rejections: l,
|
|
309
|
+
lastFailureTime: d,
|
|
310
|
+
lastSuccessTime: m
|
|
284
311
|
};
|
|
285
312
|
}
|
|
286
|
-
function
|
|
287
|
-
c().debug(`[CircuitBreaker:${
|
|
313
|
+
function D() {
|
|
314
|
+
c().debug(`[CircuitBreaker:${n}] Manual reset → CLOSED`), i = "CLOSED", o = [], s = 0, l = 0, d = null, m = null, u = null;
|
|
288
315
|
}
|
|
289
|
-
function
|
|
290
|
-
c().warn(`[CircuitBreaker:${
|
|
316
|
+
function Le() {
|
|
317
|
+
c().warn(`[CircuitBreaker:${n}] Manual trip → OPEN`), i = "OPEN", u = Date.now() + r;
|
|
291
318
|
}
|
|
292
319
|
return {
|
|
293
|
-
execute:
|
|
294
|
-
getState:
|
|
295
|
-
getStats:
|
|
296
|
-
reset:
|
|
297
|
-
trip:
|
|
320
|
+
execute: x,
|
|
321
|
+
getState: B,
|
|
322
|
+
getStats: k,
|
|
323
|
+
reset: D,
|
|
324
|
+
trip: Le
|
|
298
325
|
};
|
|
299
326
|
}
|
|
300
|
-
const
|
|
327
|
+
const zt = {
|
|
301
328
|
/** Strict: Opens quickly (3 failures), long timeout (60s) */
|
|
302
329
|
STRICT: { failureThreshold: 3, timeout: 6e4 },
|
|
303
330
|
/** Standard: Balanced settings (5 failures, 30s timeout) */
|
|
304
331
|
STANDARD: { failureThreshold: 5, timeout: 3e4 },
|
|
305
332
|
/** Lenient: Tolerates more failures (10 failures, 15s timeout) */
|
|
306
333
|
LENIENT: { failureThreshold: 10, timeout: 15e3 }
|
|
334
|
+
}, tt = {
|
|
335
|
+
// ===== PAYMENT VERIFICATION ERRORS (402) =====
|
|
336
|
+
invalid_payment_proof: {
|
|
337
|
+
message: "Payment verification failed",
|
|
338
|
+
action: "Please try your payment again. If this continues, contact support.",
|
|
339
|
+
technicalHint: "Invalid payment proof format"
|
|
340
|
+
},
|
|
341
|
+
invalid_signature: {
|
|
342
|
+
message: "Transaction signature is invalid",
|
|
343
|
+
action: "Please approve the transaction in your wallet and try again.",
|
|
344
|
+
technicalHint: "Transaction signature verification failed"
|
|
345
|
+
},
|
|
346
|
+
invalid_transaction: {
|
|
347
|
+
message: "Transaction format is invalid",
|
|
348
|
+
action: "Please try your payment again. If this continues, try updating your wallet app.",
|
|
349
|
+
technicalHint: "Malformed transaction structure"
|
|
350
|
+
},
|
|
351
|
+
transaction_not_found: {
|
|
352
|
+
message: "Transaction not found on the blockchain",
|
|
353
|
+
action: "Your transaction may still be processing. Please wait a moment and check your wallet, or try again.",
|
|
354
|
+
technicalHint: "Transaction signature not found on-chain"
|
|
355
|
+
},
|
|
356
|
+
transaction_not_confirmed: {
|
|
357
|
+
message: "Transaction is still processing",
|
|
358
|
+
action: "Please wait a moment for the blockchain to confirm your transaction, then try again.",
|
|
359
|
+
technicalHint: "Transaction not yet confirmed"
|
|
360
|
+
},
|
|
361
|
+
transaction_failed: {
|
|
362
|
+
message: "Transaction failed on the blockchain",
|
|
363
|
+
action: "Check your wallet for details. You may need to adjust your transaction settings or add more SOL for fees.",
|
|
364
|
+
technicalHint: "On-chain transaction failure"
|
|
365
|
+
},
|
|
366
|
+
transaction_expired: {
|
|
367
|
+
message: "Transaction took too long to process",
|
|
368
|
+
action: "Please try your payment again. Consider increasing transaction priority if your wallet supports it.",
|
|
369
|
+
technicalHint: "Transaction blockhash expired"
|
|
370
|
+
},
|
|
371
|
+
invalid_recipient: {
|
|
372
|
+
message: "Payment was sent to the wrong address",
|
|
373
|
+
action: "Please try again and ensure you approve the correct transaction in your wallet.",
|
|
374
|
+
technicalHint: "Recipient address mismatch"
|
|
375
|
+
},
|
|
376
|
+
invalid_sender: {
|
|
377
|
+
message: "Payment sender wallet is invalid",
|
|
378
|
+
action: "Please reconnect your wallet and try again.",
|
|
379
|
+
technicalHint: "Sender address validation failed"
|
|
380
|
+
},
|
|
381
|
+
unauthorized_refund_issuer: {
|
|
382
|
+
message: "You are not authorized to issue refunds",
|
|
383
|
+
action: "Only authorized accounts can process refunds. Please contact support if you believe this is an error.",
|
|
384
|
+
technicalHint: "Refund issuer not in authorized list"
|
|
385
|
+
},
|
|
386
|
+
amount_below_minimum: {
|
|
387
|
+
message: "Payment amount is too low",
|
|
388
|
+
action: "Please check the required amount and try again.",
|
|
389
|
+
technicalHint: "Amount below minimum threshold"
|
|
390
|
+
},
|
|
391
|
+
amount_mismatch: {
|
|
392
|
+
message: "Payment amount does not match the quote",
|
|
393
|
+
action: "The price may have changed. Please refresh and try your payment again.",
|
|
394
|
+
technicalHint: "Amount does not match quote"
|
|
395
|
+
},
|
|
396
|
+
insufficient_funds_sol: {
|
|
397
|
+
message: "Not enough SOL for transaction fees",
|
|
398
|
+
action: "Add at least 0.001 SOL to your wallet to cover network fees, then try again.",
|
|
399
|
+
technicalHint: "Insufficient SOL balance for fees"
|
|
400
|
+
},
|
|
401
|
+
insufficient_funds_token: {
|
|
402
|
+
message: "Insufficient balance in your wallet",
|
|
403
|
+
action: "Add more funds to your wallet and try again.",
|
|
404
|
+
technicalHint: "Insufficient token balance"
|
|
405
|
+
},
|
|
406
|
+
invalid_token_mint: {
|
|
407
|
+
message: "Incorrect payment token",
|
|
408
|
+
action: "Please pay with the correct token as shown in the payment details.",
|
|
409
|
+
technicalHint: "Token mint address mismatch"
|
|
410
|
+
},
|
|
411
|
+
not_spl_transfer: {
|
|
412
|
+
message: "Transaction is not a valid token transfer",
|
|
413
|
+
action: "Please ensure you are sending the correct token type from your wallet.",
|
|
414
|
+
technicalHint: "Transaction is not an SPL token transfer"
|
|
415
|
+
},
|
|
416
|
+
missing_token_account: {
|
|
417
|
+
message: "Token account not found",
|
|
418
|
+
action: "Your wallet may need to create a token account first. Try again or use a different wallet.",
|
|
419
|
+
technicalHint: "Associated token account does not exist"
|
|
420
|
+
},
|
|
421
|
+
invalid_token_program: {
|
|
422
|
+
message: "Invalid token program",
|
|
423
|
+
action: "Please try your payment again. If this continues, try using a different wallet.",
|
|
424
|
+
technicalHint: "Token program ID mismatch"
|
|
425
|
+
},
|
|
426
|
+
missing_memo: {
|
|
427
|
+
message: "Payment memo is required but was not included",
|
|
428
|
+
action: "Please try your payment again and ensure transaction details are approved in your wallet.",
|
|
429
|
+
technicalHint: "Required memo instruction missing"
|
|
430
|
+
},
|
|
431
|
+
invalid_memo: {
|
|
432
|
+
message: "Payment memo format is invalid",
|
|
433
|
+
action: "Please try your payment again.",
|
|
434
|
+
technicalHint: "Memo does not match expected format"
|
|
435
|
+
},
|
|
436
|
+
payment_already_used: {
|
|
437
|
+
message: "This payment has already been processed",
|
|
438
|
+
action: "Check your transaction history. If you need to make another payment, please start a new transaction.",
|
|
439
|
+
technicalHint: "Payment signature already recorded"
|
|
440
|
+
},
|
|
441
|
+
signature_reused: {
|
|
442
|
+
message: "Transaction signature has already been used",
|
|
443
|
+
action: "Please create a new payment transaction.",
|
|
444
|
+
technicalHint: "Duplicate signature detected"
|
|
445
|
+
},
|
|
446
|
+
quote_expired: {
|
|
447
|
+
message: "Payment quote has expired",
|
|
448
|
+
action: "Prices are updated frequently. Please refresh and try your payment again.",
|
|
449
|
+
technicalHint: "Quote timestamp expired"
|
|
450
|
+
},
|
|
451
|
+
// ===== VALIDATION ERRORS (400) =====
|
|
452
|
+
missing_field: {
|
|
453
|
+
message: "Required information is missing",
|
|
454
|
+
action: "Please check all required fields and try again.",
|
|
455
|
+
technicalHint: "Required field not provided"
|
|
456
|
+
},
|
|
457
|
+
invalid_field: {
|
|
458
|
+
message: "Some information is invalid",
|
|
459
|
+
action: "Please check your input and try again.",
|
|
460
|
+
technicalHint: "Field validation failed"
|
|
461
|
+
},
|
|
462
|
+
invalid_amount: {
|
|
463
|
+
message: "Payment amount is invalid",
|
|
464
|
+
action: "Please check the amount and try again.",
|
|
465
|
+
technicalHint: "Amount validation failed"
|
|
466
|
+
},
|
|
467
|
+
invalid_wallet: {
|
|
468
|
+
message: "Wallet address is invalid",
|
|
469
|
+
action: "Please reconnect your wallet and try again.",
|
|
470
|
+
technicalHint: "Wallet address validation failed"
|
|
471
|
+
},
|
|
472
|
+
invalid_resource: {
|
|
473
|
+
message: "Invalid item selection",
|
|
474
|
+
action: "Please refresh the page and try again.",
|
|
475
|
+
technicalHint: "Resource ID validation failed"
|
|
476
|
+
},
|
|
477
|
+
invalid_coupon: {
|
|
478
|
+
message: "Invalid coupon code",
|
|
479
|
+
action: "Please check the coupon code and try again.",
|
|
480
|
+
technicalHint: "Coupon code format invalid"
|
|
481
|
+
},
|
|
482
|
+
invalid_cart_item: {
|
|
483
|
+
message: "One or more cart items are invalid",
|
|
484
|
+
action: "Please review your cart and try again.",
|
|
485
|
+
technicalHint: "Cart item validation failed"
|
|
486
|
+
},
|
|
487
|
+
empty_cart: {
|
|
488
|
+
message: "Your cart is empty",
|
|
489
|
+
action: "Please add items to your cart before checking out.",
|
|
490
|
+
technicalHint: "Cart contains no items"
|
|
491
|
+
},
|
|
492
|
+
// ===== RESOURCE/STATE ERRORS (404) =====
|
|
493
|
+
resource_not_found: {
|
|
494
|
+
message: "Item not found",
|
|
495
|
+
action: "This item may no longer be available. Please refresh and try again.",
|
|
496
|
+
technicalHint: "Resource not found in database"
|
|
497
|
+
},
|
|
498
|
+
cart_not_found: {
|
|
499
|
+
message: "Shopping cart not found",
|
|
500
|
+
action: "Your cart may have expired. Please start a new order.",
|
|
501
|
+
technicalHint: "Cart ID not found"
|
|
502
|
+
},
|
|
503
|
+
refund_not_found: {
|
|
504
|
+
message: "Refund not found",
|
|
505
|
+
action: "Please check your refund reference number or contact support.",
|
|
506
|
+
technicalHint: "Refund ID not found"
|
|
507
|
+
},
|
|
508
|
+
product_not_found: {
|
|
509
|
+
message: "Product not available",
|
|
510
|
+
action: "This product may no longer be available. Please browse our current selection.",
|
|
511
|
+
technicalHint: "Product ID not found"
|
|
512
|
+
},
|
|
513
|
+
coupon_not_found: {
|
|
514
|
+
message: "Coupon code not found",
|
|
515
|
+
action: "Please check the coupon code or remove it to continue.",
|
|
516
|
+
technicalHint: "Coupon code not in database"
|
|
517
|
+
},
|
|
518
|
+
session_not_found: {
|
|
519
|
+
message: "Payment session expired",
|
|
520
|
+
action: "Please start a new payment.",
|
|
521
|
+
technicalHint: "Session ID not found or expired"
|
|
522
|
+
},
|
|
523
|
+
cart_already_paid: {
|
|
524
|
+
message: "This order has already been paid",
|
|
525
|
+
action: "Check your order history. If you need to make another purchase, please start a new order.",
|
|
526
|
+
technicalHint: "Cart marked as paid"
|
|
527
|
+
},
|
|
528
|
+
refund_already_processed: {
|
|
529
|
+
message: "This refund has already been processed",
|
|
530
|
+
action: "Check your transaction history or contact support for details.",
|
|
531
|
+
technicalHint: "Refund already completed"
|
|
532
|
+
},
|
|
533
|
+
// ===== COUPON-SPECIFIC ERRORS (409) =====
|
|
534
|
+
coupon_expired: {
|
|
535
|
+
message: "Coupon has expired",
|
|
536
|
+
action: "Please remove the coupon code or use a different code.",
|
|
537
|
+
technicalHint: "Coupon expiration date passed"
|
|
538
|
+
},
|
|
539
|
+
coupon_usage_limit_reached: {
|
|
540
|
+
message: "Coupon usage limit reached",
|
|
541
|
+
action: "This coupon has been fully redeemed. Please try a different code.",
|
|
542
|
+
technicalHint: "Coupon max uses exceeded"
|
|
543
|
+
},
|
|
544
|
+
coupon_not_applicable: {
|
|
545
|
+
message: "Coupon cannot be applied to this purchase",
|
|
546
|
+
action: "Please check the coupon terms or remove it to continue.",
|
|
547
|
+
technicalHint: "Coupon conditions not met"
|
|
548
|
+
},
|
|
549
|
+
coupon_wrong_payment_method: {
|
|
550
|
+
message: "Coupon not valid for this payment method",
|
|
551
|
+
action: "Try a different payment method or remove the coupon code.",
|
|
552
|
+
technicalHint: "Coupon restricted to specific payment methods"
|
|
553
|
+
},
|
|
554
|
+
// ===== EXTERNAL SERVICE ERRORS (502) =====
|
|
555
|
+
stripe_error: {
|
|
556
|
+
message: "Card payment service temporarily unavailable",
|
|
557
|
+
action: "Please try again in a moment, or use cryptocurrency payment instead.",
|
|
558
|
+
technicalHint: "Stripe API error"
|
|
559
|
+
},
|
|
560
|
+
rpc_error: {
|
|
561
|
+
message: "Blockchain network temporarily unavailable",
|
|
562
|
+
action: "Please try again in a moment, or use card payment instead.",
|
|
563
|
+
technicalHint: "Solana RPC error"
|
|
564
|
+
},
|
|
565
|
+
network_error: {
|
|
566
|
+
message: "Network connection issue",
|
|
567
|
+
action: "Please check your internet connection and try again.",
|
|
568
|
+
technicalHint: "Network request failed"
|
|
569
|
+
},
|
|
570
|
+
// ===== INTERNAL/SYSTEM ERRORS (500) =====
|
|
571
|
+
internal_error: {
|
|
572
|
+
message: "Something went wrong on our end",
|
|
573
|
+
action: "Please try again. If this continues, contact support.",
|
|
574
|
+
technicalHint: "Internal server error"
|
|
575
|
+
},
|
|
576
|
+
database_error: {
|
|
577
|
+
message: "Service temporarily unavailable",
|
|
578
|
+
action: "Please try again in a moment.",
|
|
579
|
+
technicalHint: "Database operation failed"
|
|
580
|
+
},
|
|
581
|
+
config_error: {
|
|
582
|
+
message: "Service configuration error",
|
|
583
|
+
action: "Please contact support for assistance.",
|
|
584
|
+
technicalHint: "Server misconfiguration"
|
|
585
|
+
}
|
|
307
586
|
};
|
|
308
|
-
function
|
|
309
|
-
|
|
310
|
-
|
|
587
|
+
function rt(t) {
|
|
588
|
+
return tt[t] || {
|
|
589
|
+
message: "An unexpected error occurred",
|
|
590
|
+
action: "Please try again or contact support if this continues.",
|
|
591
|
+
technicalHint: `Unknown error code: ${t}`
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
class O extends Error {
|
|
595
|
+
/** Machine-readable error code enum */
|
|
596
|
+
code;
|
|
597
|
+
/** Whether this error can be safely retried */
|
|
598
|
+
retryable;
|
|
599
|
+
/** Additional error context */
|
|
600
|
+
details;
|
|
601
|
+
/** HTTP status code (if from API response) */
|
|
602
|
+
httpStatus;
|
|
603
|
+
constructor(e, r, a = !1, n, i) {
|
|
604
|
+
super(r), this.name = "PaymentError", this.code = e, this.retryable = a, this.details = n, this.httpStatus = i, Object.setPrototypeOf(this, O.prototype);
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Check if this error is retryable
|
|
608
|
+
*/
|
|
609
|
+
canRetry() {
|
|
610
|
+
return this.retryable;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Check if this is a specific error code
|
|
614
|
+
*/
|
|
615
|
+
is(e) {
|
|
616
|
+
return this.code === e;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Check if this error is in a specific category
|
|
620
|
+
*/
|
|
621
|
+
isInCategory(e) {
|
|
622
|
+
return e.includes(this.code);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Get a user-friendly error message
|
|
626
|
+
* Uses structured error messages with actionable guidance
|
|
627
|
+
*/
|
|
628
|
+
getUserMessage() {
|
|
629
|
+
const e = this.getErrorInfo();
|
|
630
|
+
return e.action ? `${e.message} ${e.action}` : e.message;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Get short error message without action guidance
|
|
634
|
+
*/
|
|
635
|
+
getShortMessage() {
|
|
636
|
+
return this.getErrorInfo().message;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Get actionable guidance for this error
|
|
640
|
+
*/
|
|
641
|
+
getAction() {
|
|
642
|
+
return this.getErrorInfo().action;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Get error info from error messages map
|
|
646
|
+
* @private
|
|
647
|
+
*/
|
|
648
|
+
getErrorInfo() {
|
|
649
|
+
return rt(this.code);
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Create PaymentError from API error response
|
|
653
|
+
*
|
|
654
|
+
* If `retryable` field is not present (Rust server), infers retryability
|
|
655
|
+
* from error codes using ERROR_CATEGORIES.RETRYABLE.
|
|
656
|
+
*/
|
|
657
|
+
static fromErrorResponse(e, r) {
|
|
658
|
+
const a = e.error.retryable ?? at.RETRYABLE.includes(e.error.code);
|
|
659
|
+
return new O(
|
|
660
|
+
e.error.code,
|
|
661
|
+
e.error.message,
|
|
662
|
+
a,
|
|
663
|
+
e.error.details,
|
|
664
|
+
r
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Create PaymentError from unknown error
|
|
669
|
+
* Useful for catch blocks where error type is unknown
|
|
670
|
+
*/
|
|
671
|
+
static fromUnknown(e) {
|
|
672
|
+
return e instanceof O ? e : e instanceof Error ? new O(
|
|
673
|
+
"internal_error",
|
|
674
|
+
e.message,
|
|
675
|
+
!1
|
|
676
|
+
) : new O(
|
|
677
|
+
"internal_error",
|
|
678
|
+
String(e),
|
|
679
|
+
!1
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
const at = {
|
|
684
|
+
/** Insufficient funds errors requiring user to add funds */
|
|
685
|
+
INSUFFICIENT_FUNDS: [
|
|
686
|
+
"insufficient_funds_sol",
|
|
687
|
+
"insufficient_funds_token"
|
|
688
|
+
/* INSUFFICIENT_FUNDS_TOKEN */
|
|
689
|
+
],
|
|
690
|
+
/** Transaction state errors that may resolve with time */
|
|
691
|
+
TRANSACTION_PENDING: [
|
|
692
|
+
"transaction_not_confirmed",
|
|
693
|
+
"transaction_not_found"
|
|
694
|
+
/* TRANSACTION_NOT_FOUND */
|
|
695
|
+
],
|
|
696
|
+
/** Validation errors requiring input correction */
|
|
697
|
+
VALIDATION: [
|
|
698
|
+
"missing_field",
|
|
699
|
+
"invalid_field",
|
|
700
|
+
"invalid_amount",
|
|
701
|
+
"invalid_wallet",
|
|
702
|
+
"invalid_resource",
|
|
703
|
+
"invalid_cart_item",
|
|
704
|
+
"empty_cart"
|
|
705
|
+
/* EMPTY_CART */
|
|
706
|
+
],
|
|
707
|
+
/** Coupon-related errors */
|
|
708
|
+
COUPON: [
|
|
709
|
+
"invalid_coupon",
|
|
710
|
+
"coupon_not_found",
|
|
711
|
+
"coupon_expired",
|
|
712
|
+
"coupon_usage_limit_reached",
|
|
713
|
+
"coupon_not_applicable",
|
|
714
|
+
"coupon_wrong_payment_method"
|
|
715
|
+
/* COUPON_WRONG_PAYMENT_METHOD */
|
|
716
|
+
],
|
|
717
|
+
/** Retryable errors (temporary failures) */
|
|
718
|
+
RETRYABLE: [
|
|
719
|
+
"transaction_not_confirmed",
|
|
720
|
+
"rpc_error",
|
|
721
|
+
"network_error",
|
|
722
|
+
"stripe_error"
|
|
723
|
+
/* STRIPE_ERROR */
|
|
724
|
+
],
|
|
725
|
+
/** Resource not found errors */
|
|
726
|
+
NOT_FOUND: [
|
|
727
|
+
"resource_not_found",
|
|
728
|
+
"cart_not_found",
|
|
729
|
+
"refund_not_found",
|
|
730
|
+
"product_not_found",
|
|
731
|
+
"coupon_not_found",
|
|
732
|
+
"session_not_found",
|
|
733
|
+
"credits_hold_not_found"
|
|
734
|
+
/* CREDITS_HOLD_NOT_FOUND */
|
|
735
|
+
],
|
|
736
|
+
/** Credits-related errors */
|
|
737
|
+
CREDITS: [
|
|
738
|
+
"insufficient_credits",
|
|
739
|
+
"credits_hold_expired",
|
|
740
|
+
"credits_hold_not_found"
|
|
741
|
+
/* CREDITS_HOLD_NOT_FOUND */
|
|
742
|
+
],
|
|
743
|
+
/** Security/rate limit errors */
|
|
744
|
+
SECURITY: [
|
|
745
|
+
"invalid_redirect_url",
|
|
746
|
+
"rate_limit_exceeded",
|
|
747
|
+
"nonce_already_used"
|
|
748
|
+
/* NONCE_ALREADY_USED */
|
|
749
|
+
]
|
|
750
|
+
};
|
|
751
|
+
function nt(t, e) {
|
|
752
|
+
if (t instanceof O && t.httpStatus != null) {
|
|
753
|
+
const a = t.httpStatus;
|
|
754
|
+
return a === 429 || a >= 500 && a < 600;
|
|
755
|
+
}
|
|
311
756
|
const r = t.message.toLowerCase();
|
|
312
|
-
return r.includes("network") || r.includes("timeout") || r.includes("fetch failed") || r.includes("econnrefused")
|
|
757
|
+
return !!(r.includes("network") || r.includes("timeout") || r.includes("fetch failed") || r.includes("econnrefused"));
|
|
313
758
|
}
|
|
314
|
-
function
|
|
759
|
+
function it(t, e, r, a, n) {
|
|
315
760
|
const i = e * Math.pow(r, t), o = Math.min(i, a);
|
|
316
|
-
|
|
317
|
-
const s = Math.random() * o;
|
|
318
|
-
return Math.floor(s);
|
|
319
|
-
}
|
|
320
|
-
return Math.floor(o);
|
|
761
|
+
return Math.floor(n ? o * 0.5 + Math.random() * o * 0.5 : o);
|
|
321
762
|
}
|
|
322
|
-
function
|
|
763
|
+
function ot(t) {
|
|
323
764
|
return new Promise((e) => setTimeout(e, t));
|
|
324
765
|
}
|
|
325
|
-
async function
|
|
766
|
+
async function b(t, e = {}) {
|
|
326
767
|
const {
|
|
327
768
|
maxRetries: r = 3,
|
|
328
769
|
initialDelayMs: a = 1e3,
|
|
329
770
|
backoffFactor: n = 2,
|
|
330
771
|
maxDelayMs: i = 3e4,
|
|
331
772
|
jitter: o = !0,
|
|
332
|
-
shouldRetry: s =
|
|
773
|
+
shouldRetry: s = nt,
|
|
333
774
|
name: l = "retry"
|
|
334
775
|
} = e;
|
|
335
|
-
let
|
|
776
|
+
let d = null, m = 0;
|
|
336
777
|
for (let u = 0; u <= r; u++)
|
|
337
778
|
try {
|
|
338
|
-
const
|
|
779
|
+
const y = await t();
|
|
339
780
|
return u > 0 && c().debug(
|
|
340
|
-
`[Retry:${l}] Succeeded on attempt ${u + 1}/${r + 1} after ${
|
|
341
|
-
),
|
|
342
|
-
} catch (
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
if (
|
|
781
|
+
`[Retry:${l}] Succeeded on attempt ${u + 1}/${r + 1} after ${m}ms`
|
|
782
|
+
), y;
|
|
783
|
+
} catch (y) {
|
|
784
|
+
d = y instanceof Error ? y : new Error(String(y));
|
|
785
|
+
const f = u === r, h = s(d, u);
|
|
786
|
+
if (f || !h)
|
|
346
787
|
throw c().warn(
|
|
347
|
-
`[Retry:${l}] Failed on attempt ${u + 1}/${r + 1}. ${
|
|
348
|
-
),
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
`[Retry:${l}] Attempt ${u + 1}/${r + 1} failed: ${
|
|
352
|
-
), await
|
|
788
|
+
`[Retry:${l}] Failed on attempt ${u + 1}/${r + 1}. ${f ? "No more retries." : "Error not retryable."}`
|
|
789
|
+
), d;
|
|
790
|
+
const w = it(u, a, n, i, o);
|
|
791
|
+
m += w, c().warn(
|
|
792
|
+
`[Retry:${l}] Attempt ${u + 1}/${r + 1} failed: ${d.message}. Retrying in ${w}ms...`
|
|
793
|
+
), await ot(w);
|
|
353
794
|
}
|
|
354
|
-
throw
|
|
795
|
+
throw d || new Error("Retry failed with no error");
|
|
355
796
|
}
|
|
356
|
-
const
|
|
797
|
+
const E = {
|
|
357
798
|
/** Quick retries for transient errors (3 retries, 1s initial, 2x backoff) */
|
|
358
799
|
QUICK: {
|
|
359
800
|
maxRetries: 3,
|
|
@@ -383,12 +824,13 @@ const g = {
|
|
|
383
824
|
maxDelayMs: 6e4
|
|
384
825
|
}
|
|
385
826
|
};
|
|
386
|
-
class
|
|
827
|
+
class st {
|
|
387
828
|
stripe = null;
|
|
829
|
+
initPromise = null;
|
|
388
830
|
publicKey;
|
|
389
831
|
routeDiscovery;
|
|
390
|
-
rateLimiter =
|
|
391
|
-
circuitBreaker =
|
|
832
|
+
rateLimiter = R(M.PAYMENT);
|
|
833
|
+
circuitBreaker = j({
|
|
392
834
|
failureThreshold: 5,
|
|
393
835
|
timeout: 1e4,
|
|
394
836
|
// 10 seconds for faster recovery in payment flows
|
|
@@ -399,10 +841,17 @@ class Ze {
|
|
|
399
841
|
}
|
|
400
842
|
/**
|
|
401
843
|
* Initialize Stripe.js library
|
|
844
|
+
*
|
|
845
|
+
* Concurrent callers share a single loadStripe() call via a cached promise.
|
|
402
846
|
*/
|
|
403
847
|
async initialize() {
|
|
404
|
-
|
|
405
|
-
|
|
848
|
+
this.stripe || (this.initPromise || (this.initPromise = (async () => {
|
|
849
|
+
try {
|
|
850
|
+
if (this.stripe = await Ce(this.publicKey), !this.stripe) throw new Error("Failed to initialize Stripe");
|
|
851
|
+
} catch (e) {
|
|
852
|
+
throw this.initPromise = null, e;
|
|
853
|
+
}
|
|
854
|
+
})()), await this.initPromise);
|
|
406
855
|
}
|
|
407
856
|
/**
|
|
408
857
|
* Create a Stripe checkout session
|
|
@@ -410,29 +859,35 @@ class Ze {
|
|
|
410
859
|
async createSession(e) {
|
|
411
860
|
if (!this.rateLimiter.tryConsume())
|
|
412
861
|
throw new Error("Rate limit exceeded for Stripe session creation. Please try again later.");
|
|
862
|
+
const r = S();
|
|
413
863
|
try {
|
|
414
|
-
return await this.circuitBreaker.execute(async () => await
|
|
864
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
415
865
|
async () => {
|
|
416
|
-
const
|
|
417
|
-
c().debug("[StripeManager] Creating session
|
|
418
|
-
|
|
866
|
+
const a = await this.routeDiscovery.buildUrl("/paywall/v1/stripe-session");
|
|
867
|
+
c().debug("[StripeManager] Creating session", {
|
|
868
|
+
resource: e.resource,
|
|
869
|
+
hasCouponCode: !!e.couponCode,
|
|
870
|
+
hasMetadata: !!(e.metadata && Object.keys(e.metadata).length),
|
|
871
|
+
metadataKeyCount: e.metadata ? Object.keys(e.metadata).length : 0
|
|
872
|
+
});
|
|
873
|
+
const n = await p(a, {
|
|
419
874
|
method: "POST",
|
|
420
875
|
headers: {
|
|
421
876
|
"Content-Type": "application/json",
|
|
422
|
-
"Idempotency-Key":
|
|
877
|
+
"Idempotency-Key": r
|
|
423
878
|
},
|
|
424
879
|
body: JSON.stringify(e)
|
|
425
880
|
});
|
|
426
|
-
if (!
|
|
427
|
-
const
|
|
428
|
-
throw new Error(
|
|
881
|
+
if (!n.ok) {
|
|
882
|
+
const i = await g(n, "Failed to create Stripe session");
|
|
883
|
+
throw new Error(i);
|
|
429
884
|
}
|
|
430
|
-
return await
|
|
885
|
+
return await n.json();
|
|
431
886
|
},
|
|
432
|
-
{ ...
|
|
887
|
+
{ ...E.STANDARD, name: "stripe-create-session" }
|
|
433
888
|
));
|
|
434
|
-
} catch (
|
|
435
|
-
throw
|
|
889
|
+
} catch (a) {
|
|
890
|
+
throw a instanceof A ? (c().error("[StripeManager] Circuit breaker is OPEN - Stripe service unavailable"), new Error("Stripe payment service is temporarily unavailable. Please try again in a few moments.")) : a;
|
|
436
891
|
}
|
|
437
892
|
}
|
|
438
893
|
/**
|
|
@@ -460,7 +915,7 @@ class Ze {
|
|
|
460
915
|
} catch (r) {
|
|
461
916
|
return {
|
|
462
917
|
success: !1,
|
|
463
|
-
error:
|
|
918
|
+
error: T(r, "Unknown error")
|
|
464
919
|
};
|
|
465
920
|
}
|
|
466
921
|
}
|
|
@@ -468,157 +923,179 @@ class Ze {
|
|
|
468
923
|
* Create a Stripe cart checkout session for multiple items
|
|
469
924
|
*/
|
|
470
925
|
async processCartCheckout(e) {
|
|
471
|
-
const {
|
|
926
|
+
const {
|
|
927
|
+
items: r,
|
|
928
|
+
successUrl: a,
|
|
929
|
+
cancelUrl: n,
|
|
930
|
+
metadata: i,
|
|
931
|
+
customerEmail: o,
|
|
932
|
+
customerName: s,
|
|
933
|
+
customerPhone: l,
|
|
934
|
+
shippingAddress: d,
|
|
935
|
+
billingAddress: m,
|
|
936
|
+
couponCode: u,
|
|
937
|
+
tipAmount: y,
|
|
938
|
+
shippingMethodId: f,
|
|
939
|
+
paymentMethodId: h
|
|
940
|
+
} = e;
|
|
472
941
|
if (!this.rateLimiter.tryConsume())
|
|
473
942
|
return {
|
|
474
943
|
success: !1,
|
|
475
944
|
error: "Rate limit exceeded for cart checkout. Please try again later."
|
|
476
945
|
};
|
|
946
|
+
const w = S();
|
|
477
947
|
try {
|
|
478
|
-
const
|
|
948
|
+
const C = await this.circuitBreaker.execute(async () => await b(
|
|
479
949
|
async () => {
|
|
480
|
-
const
|
|
481
|
-
items: r,
|
|
482
|
-
successUrl: a,
|
|
483
|
-
cancelUrl: n,
|
|
484
|
-
metadata: i,
|
|
485
|
-
customerEmail: o,
|
|
486
|
-
coupon: s,
|
|
487
|
-
// New Rust server field
|
|
488
|
-
couponCode: s
|
|
489
|
-
// Legacy Go server field (backwards compat)
|
|
490
|
-
}, u = await h(A, {
|
|
950
|
+
const x = await this.routeDiscovery.buildUrl("/paywall/v1/cart/checkout"), k = await p(x, {
|
|
491
951
|
method: "POST",
|
|
492
952
|
headers: {
|
|
493
953
|
"Content-Type": "application/json",
|
|
494
|
-
"Idempotency-Key":
|
|
954
|
+
"Idempotency-Key": w
|
|
495
955
|
},
|
|
496
|
-
body: JSON.stringify(
|
|
956
|
+
body: JSON.stringify({
|
|
957
|
+
items: r,
|
|
958
|
+
successUrl: a,
|
|
959
|
+
cancelUrl: n,
|
|
960
|
+
metadata: i,
|
|
961
|
+
customerEmail: o,
|
|
962
|
+
customerName: s,
|
|
963
|
+
customerPhone: l,
|
|
964
|
+
shippingAddress: d,
|
|
965
|
+
billingAddress: m,
|
|
966
|
+
coupon: u,
|
|
967
|
+
// New Rust server field
|
|
968
|
+
couponCode: u,
|
|
969
|
+
// Legacy Go server field (backwards compat)
|
|
970
|
+
tipAmount: y,
|
|
971
|
+
shippingMethodId: f,
|
|
972
|
+
paymentMethodId: h
|
|
973
|
+
})
|
|
497
974
|
});
|
|
498
|
-
if (!
|
|
499
|
-
const
|
|
500
|
-
throw new Error(
|
|
975
|
+
if (!k.ok) {
|
|
976
|
+
const D = await g(k, "Failed to create cart checkout session");
|
|
977
|
+
throw new Error(D);
|
|
501
978
|
}
|
|
502
|
-
return await
|
|
979
|
+
return await k.json();
|
|
503
980
|
},
|
|
504
|
-
{ ...
|
|
981
|
+
{ ...E.STANDARD, name: "stripe-cart-checkout" }
|
|
505
982
|
));
|
|
506
|
-
return await this.redirectToCheckout(
|
|
507
|
-
} catch (
|
|
508
|
-
return
|
|
983
|
+
return await this.redirectToCheckout(C.sessionId);
|
|
984
|
+
} catch (C) {
|
|
985
|
+
return C instanceof A ? {
|
|
509
986
|
success: !1,
|
|
510
987
|
error: "Stripe payment service is temporarily unavailable. Please try again in a few moments."
|
|
511
988
|
} : {
|
|
512
989
|
success: !1,
|
|
513
|
-
error:
|
|
990
|
+
error: T(C, "Cart checkout failed")
|
|
514
991
|
};
|
|
515
992
|
}
|
|
516
993
|
}
|
|
517
994
|
}
|
|
518
|
-
const
|
|
995
|
+
const Pe = "3.7.8", ct = Pe, F = typeof Buffer == "function", le = typeof TextDecoder == "function" ? new TextDecoder() : void 0, ue = typeof TextEncoder == "function" ? new TextEncoder() : void 0, lt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", q = Array.prototype.slice.call(lt), K = ((t) => {
|
|
519
996
|
let e = {};
|
|
520
997
|
return t.forEach((r, a) => e[r] = a), e;
|
|
521
|
-
})(
|
|
998
|
+
})(q), ut = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/, v = String.fromCharCode.bind(String), de = typeof Uint8Array.from == "function" ? Uint8Array.from.bind(Uint8Array) : (t) => new Uint8Array(Array.prototype.slice.call(t, 0)), Se = (t) => t.replace(/=/g, "").replace(/[+\/]/g, (e) => e == "+" ? "-" : "_"), xe = (t) => t.replace(/[^A-Za-z0-9\+\/]/g, ""), ke = (t) => {
|
|
522
999
|
let e, r, a, n, i = "";
|
|
523
1000
|
const o = t.length % 3;
|
|
524
1001
|
for (let s = 0; s < t.length; ) {
|
|
525
1002
|
if ((r = t.charCodeAt(s++)) > 255 || (a = t.charCodeAt(s++)) > 255 || (n = t.charCodeAt(s++)) > 255)
|
|
526
1003
|
throw new TypeError("invalid character found");
|
|
527
|
-
e = r << 16 | a << 8 | n, i +=
|
|
1004
|
+
e = r << 16 | a << 8 | n, i += q[e >> 18 & 63] + q[e >> 12 & 63] + q[e >> 6 & 63] + q[e & 63];
|
|
528
1005
|
}
|
|
529
1006
|
return o ? i.slice(0, o - 3) + "===".substring(o) : i;
|
|
530
|
-
},
|
|
1007
|
+
}, ie = typeof btoa == "function" ? (t) => btoa(t) : F ? (t) => Buffer.from(t, "binary").toString("base64") : ke, te = F ? (t) => Buffer.from(t).toString("base64") : (t) => {
|
|
531
1008
|
let r = [];
|
|
532
1009
|
for (let a = 0, n = t.length; a < n; a += 4096)
|
|
533
|
-
r.push(
|
|
534
|
-
return
|
|
535
|
-
},
|
|
1010
|
+
r.push(v.apply(null, t.subarray(a, a + 4096)));
|
|
1011
|
+
return ie(r.join(""));
|
|
1012
|
+
}, G = (t, e = !1) => e ? Se(te(t)) : te(t), dt = (t) => {
|
|
536
1013
|
if (t.length < 2) {
|
|
537
1014
|
var e = t.charCodeAt(0);
|
|
538
|
-
return e < 128 ? t : e < 2048 ?
|
|
1015
|
+
return e < 128 ? t : e < 2048 ? v(192 | e >>> 6) + v(128 | e & 63) : v(224 | e >>> 12 & 15) + v(128 | e >>> 6 & 63) + v(128 | e & 63);
|
|
539
1016
|
} else {
|
|
540
1017
|
var e = 65536 + (t.charCodeAt(0) - 55296) * 1024 + (t.charCodeAt(1) - 56320);
|
|
541
|
-
return
|
|
1018
|
+
return v(240 | e >>> 18 & 7) + v(128 | e >>> 12 & 63) + v(128 | e >>> 6 & 63) + v(128 | e & 63);
|
|
542
1019
|
}
|
|
543
|
-
},
|
|
1020
|
+
}, ft = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g, Te = (t) => t.replace(ft, dt), fe = F ? (t) => Buffer.from(t, "utf8").toString("base64") : ue ? (t) => te(ue.encode(t)) : (t) => ie(Te(t)), U = (t, e = !1) => e ? Se(fe(t)) : fe(t), he = (t) => U(t, !0), ht = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g, mt = (t) => {
|
|
544
1021
|
switch (t.length) {
|
|
545
1022
|
case 4:
|
|
546
1023
|
var e = (7 & t.charCodeAt(0)) << 18 | (63 & t.charCodeAt(1)) << 12 | (63 & t.charCodeAt(2)) << 6 | 63 & t.charCodeAt(3), r = e - 65536;
|
|
547
|
-
return
|
|
1024
|
+
return v((r >>> 10) + 55296) + v((r & 1023) + 56320);
|
|
548
1025
|
case 3:
|
|
549
|
-
return
|
|
1026
|
+
return v((15 & t.charCodeAt(0)) << 12 | (63 & t.charCodeAt(1)) << 6 | 63 & t.charCodeAt(2));
|
|
550
1027
|
default:
|
|
551
|
-
return
|
|
1028
|
+
return v((31 & t.charCodeAt(0)) << 6 | 63 & t.charCodeAt(1));
|
|
552
1029
|
}
|
|
553
|
-
},
|
|
554
|
-
if (t = t.replace(/\s+/g, ""), !
|
|
1030
|
+
}, Re = (t) => t.replace(ht, mt), Me = (t) => {
|
|
1031
|
+
if (t = t.replace(/\s+/g, ""), !ut.test(t))
|
|
555
1032
|
throw new TypeError("malformed base64.");
|
|
556
1033
|
t += "==".slice(2 - (t.length & 3));
|
|
557
1034
|
let e, r, a, n = [];
|
|
558
1035
|
for (let i = 0; i < t.length; )
|
|
559
|
-
e =
|
|
1036
|
+
e = K[t.charAt(i++)] << 18 | K[t.charAt(i++)] << 12 | (r = K[t.charAt(i++)]) << 6 | (a = K[t.charAt(i++)]), r === 64 ? n.push(v(e >> 16 & 255)) : a === 64 ? n.push(v(e >> 16 & 255, e >> 8 & 255)) : n.push(v(e >> 16 & 255, e >> 8 & 255, e & 255));
|
|
560
1037
|
return n.join("");
|
|
561
|
-
},
|
|
1038
|
+
}, oe = typeof atob == "function" ? (t) => atob(xe(t)) : F ? (t) => Buffer.from(t, "base64").toString("binary") : Me, De = F ? (t) => de(Buffer.from(t, "base64")) : (t) => de(oe(t).split("").map((e) => e.charCodeAt(0))), Oe = (t) => De(Be(t)), yt = F ? (t) => Buffer.from(t, "base64").toString("utf8") : le ? (t) => le.decode(De(t)) : (t) => Re(oe(t)), Be = (t) => xe(t.replace(/[-_]/g, (e) => e == "-" ? "+" : "/")), re = (t) => yt(Be(t)), pt = (t) => {
|
|
562
1039
|
if (typeof t != "string")
|
|
563
1040
|
return !1;
|
|
564
1041
|
const e = t.replace(/\s+/g, "").replace(/={0,2}$/, "");
|
|
565
1042
|
return !/[^\s0-9a-zA-Z\+/]/.test(e) || !/[^\s0-9a-zA-Z\-_]/.test(e);
|
|
566
|
-
},
|
|
1043
|
+
}, _e = (t) => ({
|
|
567
1044
|
value: t,
|
|
568
1045
|
enumerable: !1,
|
|
569
1046
|
writable: !0,
|
|
570
1047
|
configurable: !0
|
|
571
|
-
}),
|
|
572
|
-
const t = (e, r) => Object.defineProperty(String.prototype, e,
|
|
1048
|
+
}), Ie = function() {
|
|
1049
|
+
const t = (e, r) => Object.defineProperty(String.prototype, e, _e(r));
|
|
573
1050
|
t("fromBase64", function() {
|
|
574
|
-
return
|
|
1051
|
+
return re(this);
|
|
575
1052
|
}), t("toBase64", function(e) {
|
|
576
|
-
return
|
|
1053
|
+
return U(this, e);
|
|
577
1054
|
}), t("toBase64URI", function() {
|
|
578
|
-
return
|
|
1055
|
+
return U(this, !0);
|
|
579
1056
|
}), t("toBase64URL", function() {
|
|
580
|
-
return
|
|
1057
|
+
return U(this, !0);
|
|
581
1058
|
}), t("toUint8Array", function() {
|
|
582
|
-
return
|
|
1059
|
+
return Oe(this);
|
|
583
1060
|
});
|
|
584
|
-
},
|
|
585
|
-
const t = (e, r) => Object.defineProperty(Uint8Array.prototype, e,
|
|
1061
|
+
}, Ne = function() {
|
|
1062
|
+
const t = (e, r) => Object.defineProperty(Uint8Array.prototype, e, _e(r));
|
|
586
1063
|
t("toBase64", function(e) {
|
|
587
|
-
return
|
|
1064
|
+
return G(this, e);
|
|
588
1065
|
}), t("toBase64URI", function() {
|
|
589
|
-
return
|
|
1066
|
+
return G(this, !0);
|
|
590
1067
|
}), t("toBase64URL", function() {
|
|
591
|
-
return
|
|
1068
|
+
return G(this, !0);
|
|
592
1069
|
});
|
|
593
|
-
},
|
|
594
|
-
|
|
595
|
-
},
|
|
596
|
-
version:
|
|
597
|
-
VERSION:
|
|
598
|
-
atob:
|
|
599
|
-
atobPolyfill:
|
|
600
|
-
btoa:
|
|
601
|
-
btoaPolyfill:
|
|
602
|
-
fromBase64:
|
|
603
|
-
toBase64:
|
|
604
|
-
encode:
|
|
605
|
-
encodeURI:
|
|
606
|
-
encodeURL:
|
|
607
|
-
utob:
|
|
608
|
-
btou:
|
|
609
|
-
decode:
|
|
610
|
-
isValid:
|
|
611
|
-
fromUint8Array:
|
|
612
|
-
toUint8Array:
|
|
613
|
-
extendString:
|
|
614
|
-
extendUint8Array:
|
|
615
|
-
extendBuiltins:
|
|
1070
|
+
}, At = () => {
|
|
1071
|
+
Ie(), Ne();
|
|
1072
|
+
}, me = {
|
|
1073
|
+
version: Pe,
|
|
1074
|
+
VERSION: ct,
|
|
1075
|
+
atob: oe,
|
|
1076
|
+
atobPolyfill: Me,
|
|
1077
|
+
btoa: ie,
|
|
1078
|
+
btoaPolyfill: ke,
|
|
1079
|
+
fromBase64: re,
|
|
1080
|
+
toBase64: U,
|
|
1081
|
+
encode: U,
|
|
1082
|
+
encodeURI: he,
|
|
1083
|
+
encodeURL: he,
|
|
1084
|
+
utob: Te,
|
|
1085
|
+
btou: Re,
|
|
1086
|
+
decode: re,
|
|
1087
|
+
isValid: pt,
|
|
1088
|
+
fromUint8Array: G,
|
|
1089
|
+
toUint8Array: Oe,
|
|
1090
|
+
extendString: Ie,
|
|
1091
|
+
extendUint8Array: Ne,
|
|
1092
|
+
extendBuiltins: At
|
|
616
1093
|
};
|
|
617
|
-
class
|
|
1094
|
+
class gt {
|
|
618
1095
|
routeDiscovery;
|
|
619
|
-
quoteRateLimiter =
|
|
620
|
-
verifyRateLimiter =
|
|
621
|
-
circuitBreaker =
|
|
1096
|
+
quoteRateLimiter = R(M.QUOTE);
|
|
1097
|
+
verifyRateLimiter = R(M.PAYMENT);
|
|
1098
|
+
circuitBreaker = j({
|
|
622
1099
|
failureThreshold: 5,
|
|
623
1100
|
timeout: 1e4,
|
|
624
1101
|
// 10 seconds for faster recovery in payment flows
|
|
@@ -637,14 +1114,14 @@ class ct {
|
|
|
637
1114
|
if (!this.quoteRateLimiter.tryConsume())
|
|
638
1115
|
throw new Error("Rate limit exceeded for quote requests. Please try again later.");
|
|
639
1116
|
try {
|
|
640
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1117
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
641
1118
|
async () => {
|
|
642
1119
|
const n = "/paywall/v1/quote";
|
|
643
1120
|
c().debug(
|
|
644
1121
|
"[X402Manager] Requesting quote",
|
|
645
1122
|
a ? "with coupon" : "without coupon"
|
|
646
1123
|
);
|
|
647
|
-
const i = await this.routeDiscovery.buildUrl(n), o = await
|
|
1124
|
+
const i = await this.routeDiscovery.buildUrl(n), o = await p(i, {
|
|
648
1125
|
method: "POST",
|
|
649
1126
|
headers: {
|
|
650
1127
|
"Content-Type": "application/json"
|
|
@@ -657,16 +1134,23 @@ class ct {
|
|
|
657
1134
|
if (o.status !== 402)
|
|
658
1135
|
throw new Error(`Expected 402 status, got ${o.status}`);
|
|
659
1136
|
const s = await o.json();
|
|
660
|
-
if (s.crypto)
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
1137
|
+
if (s.crypto) {
|
|
1138
|
+
const l = s.crypto;
|
|
1139
|
+
if (!this.validateRequirement(l))
|
|
1140
|
+
throw new Error("Invalid x402 requirement received from server: missing required fields");
|
|
1141
|
+
return l;
|
|
1142
|
+
} else if (s.accepts && s.accepts.length > 0) {
|
|
1143
|
+
const l = s.accepts[0];
|
|
1144
|
+
if (!this.validateRequirement(l))
|
|
1145
|
+
throw new Error("Invalid x402 requirement received from server: missing required fields");
|
|
1146
|
+
return l;
|
|
1147
|
+
} else
|
|
1148
|
+
throw new Error("Invalid x402 response: missing crypto or accepts field");
|
|
665
1149
|
},
|
|
666
|
-
{ ...
|
|
1150
|
+
{ ...E.QUICK, name: "x402-quote" }
|
|
667
1151
|
));
|
|
668
1152
|
} catch (n) {
|
|
669
|
-
throw n instanceof
|
|
1153
|
+
throw n instanceof A ? (c().error("[X402Manager] Circuit breaker is OPEN - x402 service unavailable"), new Error("Payment service is temporarily unavailable. Please try again in a few moments.")) : n;
|
|
670
1154
|
}
|
|
671
1155
|
}
|
|
672
1156
|
/**
|
|
@@ -676,34 +1160,40 @@ class ct {
|
|
|
676
1160
|
const { items: r, metadata: a, couponCode: n } = e;
|
|
677
1161
|
if (!this.quoteRateLimiter.tryConsume())
|
|
678
1162
|
throw new Error("Rate limit exceeded for cart quote requests. Please try again later.");
|
|
1163
|
+
const i = S();
|
|
679
1164
|
try {
|
|
680
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1165
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
681
1166
|
async () => {
|
|
682
|
-
const
|
|
683
|
-
items: r,
|
|
684
|
-
metadata: a,
|
|
685
|
-
coupon: n,
|
|
686
|
-
// New Rust server field
|
|
687
|
-
couponCode: n
|
|
688
|
-
// Legacy Go server field (backwards compat)
|
|
689
|
-
}, s = await h(i, {
|
|
1167
|
+
const o = await this.routeDiscovery.buildUrl("/paywall/v1/cart/quote"), l = await p(o, {
|
|
690
1168
|
method: "POST",
|
|
691
1169
|
headers: {
|
|
692
1170
|
"Content-Type": "application/json",
|
|
693
|
-
"Idempotency-Key":
|
|
1171
|
+
"Idempotency-Key": i
|
|
694
1172
|
},
|
|
695
|
-
body: JSON.stringify(
|
|
1173
|
+
body: JSON.stringify({
|
|
1174
|
+
items: r,
|
|
1175
|
+
metadata: a,
|
|
1176
|
+
coupon: n,
|
|
1177
|
+
// New Rust server field
|
|
1178
|
+
couponCode: n
|
|
1179
|
+
// Legacy Go server field (backwards compat)
|
|
1180
|
+
})
|
|
696
1181
|
});
|
|
697
|
-
if (
|
|
698
|
-
const
|
|
699
|
-
throw new Error(
|
|
1182
|
+
if (l.status !== 402 && !l.ok) {
|
|
1183
|
+
const m = await g(l, "Failed to get cart quote");
|
|
1184
|
+
throw new Error(m);
|
|
700
1185
|
}
|
|
701
|
-
|
|
1186
|
+
const d = await l.json();
|
|
1187
|
+
if (!d.cartId || !d.quote)
|
|
1188
|
+
throw new Error("Invalid cart quote response: missing cartId or quote");
|
|
1189
|
+
if (d.quote.crypto && !this.validateRequirement(d.quote.crypto))
|
|
1190
|
+
throw new Error("Invalid x402 cart quote: missing required fields in crypto quote");
|
|
1191
|
+
return d;
|
|
702
1192
|
},
|
|
703
|
-
{ ...
|
|
1193
|
+
{ ...E.QUICK, name: "x402-cart-quote" }
|
|
704
1194
|
));
|
|
705
|
-
} catch (
|
|
706
|
-
throw
|
|
1195
|
+
} catch (o) {
|
|
1196
|
+
throw o instanceof A ? (c().error("[X402Manager] Circuit breaker is OPEN - cart quote service unavailable"), new Error("Payment service is temporarily unavailable. Please try again in a few moments.")) : o;
|
|
707
1197
|
}
|
|
708
1198
|
}
|
|
709
1199
|
/**
|
|
@@ -711,7 +1201,7 @@ class ct {
|
|
|
711
1201
|
*/
|
|
712
1202
|
buildPaymentHeader(e) {
|
|
713
1203
|
const r = JSON.stringify(e);
|
|
714
|
-
return
|
|
1204
|
+
return me.encode(r);
|
|
715
1205
|
}
|
|
716
1206
|
/**
|
|
717
1207
|
* Parse X-PAYMENT-RESPONSE header (base64 encoded settlement response)
|
|
@@ -721,7 +1211,7 @@ class ct {
|
|
|
721
1211
|
if (!r)
|
|
722
1212
|
return null;
|
|
723
1213
|
try {
|
|
724
|
-
const a =
|
|
1214
|
+
const a = me.decode(r), n = JSON.parse(a);
|
|
725
1215
|
return typeof n.success != "boolean" ? (c().error("Invalid settlement response: missing success field"), null) : n;
|
|
726
1216
|
} catch (a) {
|
|
727
1217
|
return c().error("Failed to parse settlement response:", a), null;
|
|
@@ -744,10 +1234,11 @@ class ct {
|
|
|
744
1234
|
success: !1,
|
|
745
1235
|
error: "Rate limit exceeded for payment verification. Please try again later."
|
|
746
1236
|
};
|
|
1237
|
+
const s = S();
|
|
747
1238
|
try {
|
|
748
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1239
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
749
1240
|
async () => {
|
|
750
|
-
const
|
|
1241
|
+
const d = {
|
|
751
1242
|
...a,
|
|
752
1243
|
payload: {
|
|
753
1244
|
...a.payload,
|
|
@@ -762,45 +1253,45 @@ class ct {
|
|
|
762
1253
|
// Add coupon if present
|
|
763
1254
|
}
|
|
764
1255
|
}
|
|
765
|
-
},
|
|
1256
|
+
}, m = this.buildPaymentHeader(d), u = "/paywall/v1/verify";
|
|
766
1257
|
c().debug("[X402Manager] Submitting payment", {
|
|
767
1258
|
resourceType: o,
|
|
768
1259
|
hasCoupon: !!n,
|
|
769
1260
|
hasMetadata: !!i
|
|
770
1261
|
});
|
|
771
|
-
const
|
|
1262
|
+
const y = await this.routeDiscovery.buildUrl(u), f = await p(y, {
|
|
772
1263
|
method: "POST",
|
|
773
1264
|
headers: {
|
|
774
1265
|
"Content-Type": "application/json",
|
|
775
|
-
"X-PAYMENT":
|
|
776
|
-
"Idempotency-Key":
|
|
1266
|
+
"X-PAYMENT": m,
|
|
1267
|
+
"Idempotency-Key": s
|
|
777
1268
|
}
|
|
778
1269
|
});
|
|
779
|
-
if (
|
|
780
|
-
const { settlement:
|
|
781
|
-
|
|
1270
|
+
if (f.ok) {
|
|
1271
|
+
const { settlement: w, transactionId: C } = await this.handlePaymentVerification(
|
|
1272
|
+
f,
|
|
782
1273
|
a.payload.signature
|
|
783
1274
|
);
|
|
784
1275
|
return {
|
|
785
1276
|
success: !0,
|
|
786
|
-
transactionId:
|
|
787
|
-
settlement:
|
|
1277
|
+
transactionId: C,
|
|
1278
|
+
settlement: w || void 0
|
|
788
1279
|
};
|
|
789
1280
|
}
|
|
790
1281
|
return {
|
|
791
1282
|
success: !1,
|
|
792
|
-
error: await
|
|
1283
|
+
error: await g(f, "Payment verification failed", !0)
|
|
793
1284
|
};
|
|
794
1285
|
},
|
|
795
|
-
{
|
|
1286
|
+
{ maxRetries: 0, initialDelayMs: 0, backoffFactor: 1, maxDelayMs: 0, name: "x402-verify" }
|
|
796
1287
|
));
|
|
797
|
-
} catch (
|
|
798
|
-
return
|
|
1288
|
+
} catch (l) {
|
|
1289
|
+
return l instanceof A ? {
|
|
799
1290
|
success: !1,
|
|
800
1291
|
error: "Payment verification service is temporarily unavailable. Please try again in a few moments."
|
|
801
1292
|
} : {
|
|
802
1293
|
success: !1,
|
|
803
|
-
error:
|
|
1294
|
+
error: T(l, "Unknown error")
|
|
804
1295
|
};
|
|
805
1296
|
}
|
|
806
1297
|
}
|
|
@@ -813,11 +1304,11 @@ class ct {
|
|
|
813
1304
|
if (!this.quoteRateLimiter.tryConsume())
|
|
814
1305
|
throw new Error("Rate limit exceeded for gasless transaction requests. Please try again later.");
|
|
815
1306
|
try {
|
|
816
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1307
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
817
1308
|
async () => {
|
|
818
1309
|
const o = await this.routeDiscovery.buildUrl(
|
|
819
1310
|
"/paywall/v1/gasless-transaction"
|
|
820
|
-
), s = await
|
|
1311
|
+
), s = await p(o, {
|
|
821
1312
|
method: "POST",
|
|
822
1313
|
headers: {
|
|
823
1314
|
"Content-Type": "application/json"
|
|
@@ -830,15 +1321,15 @@ class ct {
|
|
|
830
1321
|
})
|
|
831
1322
|
});
|
|
832
1323
|
if (!s.ok) {
|
|
833
|
-
const l = await
|
|
1324
|
+
const l = await g(s, "Failed to build gasless transaction");
|
|
834
1325
|
throw new Error(l);
|
|
835
1326
|
}
|
|
836
1327
|
return await s.json();
|
|
837
1328
|
},
|
|
838
|
-
{ ...
|
|
1329
|
+
{ ...E.QUICK, name: "x402-gasless-build" }
|
|
839
1330
|
));
|
|
840
1331
|
} catch (o) {
|
|
841
|
-
throw o instanceof
|
|
1332
|
+
throw o instanceof A ? (c().error("[X402Manager] Circuit breaker is OPEN - gasless transaction service unavailable"), new Error("Gasless transaction service is temporarily unavailable. Please try again in a few moments.")) : o;
|
|
842
1333
|
}
|
|
843
1334
|
}
|
|
844
1335
|
/**
|
|
@@ -860,10 +1351,11 @@ class ct {
|
|
|
860
1351
|
success: !1,
|
|
861
1352
|
error: "Rate limit exceeded for gasless transaction verification. Please try again later."
|
|
862
1353
|
};
|
|
1354
|
+
const l = S();
|
|
863
1355
|
try {
|
|
864
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1356
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
865
1357
|
async () => {
|
|
866
|
-
const
|
|
1358
|
+
const m = {
|
|
867
1359
|
x402Version: 0,
|
|
868
1360
|
scheme: s?.scheme || "solana-spl-transfer",
|
|
869
1361
|
network: s?.network || "mainnet-beta",
|
|
@@ -879,39 +1371,39 @@ class ct {
|
|
|
879
1371
|
...n ? { couponCode: n } : {}
|
|
880
1372
|
}
|
|
881
1373
|
}
|
|
882
|
-
},
|
|
1374
|
+
}, u = this.buildPaymentHeader(m), f = await this.routeDiscovery.buildUrl("/paywall/v1/verify"), h = await p(f, {
|
|
883
1375
|
method: "POST",
|
|
884
1376
|
headers: {
|
|
885
1377
|
"Content-Type": "application/json",
|
|
886
|
-
"X-PAYMENT":
|
|
887
|
-
"Idempotency-Key":
|
|
1378
|
+
"X-PAYMENT": u,
|
|
1379
|
+
"Idempotency-Key": l
|
|
888
1380
|
}
|
|
889
1381
|
});
|
|
890
|
-
if (
|
|
891
|
-
const { settlement:
|
|
892
|
-
|
|
1382
|
+
if (h.ok) {
|
|
1383
|
+
const { settlement: C, transactionId: x } = await this.handlePaymentVerification(
|
|
1384
|
+
h,
|
|
893
1385
|
"gasless-tx"
|
|
894
1386
|
);
|
|
895
1387
|
return {
|
|
896
1388
|
success: !0,
|
|
897
|
-
transactionId:
|
|
898
|
-
settlement:
|
|
1389
|
+
transactionId: x,
|
|
1390
|
+
settlement: C || void 0
|
|
899
1391
|
};
|
|
900
1392
|
}
|
|
901
1393
|
return {
|
|
902
1394
|
success: !1,
|
|
903
|
-
error: await
|
|
1395
|
+
error: await g(h, "Gasless transaction failed", !0)
|
|
904
1396
|
};
|
|
905
1397
|
},
|
|
906
|
-
{
|
|
1398
|
+
{ maxRetries: 0, initialDelayMs: 0, backoffFactor: 1, maxDelayMs: 0, name: "x402-gasless-verify" }
|
|
907
1399
|
));
|
|
908
|
-
} catch (
|
|
909
|
-
return
|
|
1400
|
+
} catch (d) {
|
|
1401
|
+
return d instanceof A ? {
|
|
910
1402
|
success: !1,
|
|
911
1403
|
error: "Gasless transaction verification service is temporarily unavailable. Please try again in a few moments."
|
|
912
1404
|
} : {
|
|
913
1405
|
success: !1,
|
|
914
|
-
error:
|
|
1406
|
+
error: T(d, "Unknown error")
|
|
915
1407
|
};
|
|
916
1408
|
}
|
|
917
1409
|
}
|
|
@@ -940,14 +1432,15 @@ class ct {
|
|
|
940
1432
|
return !!(e.scheme && e.network && e.maxAmountRequired && e.resource && e.payTo && e.asset && e.maxTimeoutSeconds > 0);
|
|
941
1433
|
}
|
|
942
1434
|
}
|
|
943
|
-
class
|
|
1435
|
+
class wt {
|
|
944
1436
|
stripe = null;
|
|
1437
|
+
initPromise = null;
|
|
945
1438
|
publicKey;
|
|
946
1439
|
routeDiscovery;
|
|
947
1440
|
// Separate rate limiters for different operation types
|
|
948
|
-
sessionRateLimiter =
|
|
949
|
-
statusRateLimiter =
|
|
950
|
-
circuitBreaker =
|
|
1441
|
+
sessionRateLimiter = R(M.PAYMENT);
|
|
1442
|
+
statusRateLimiter = R(M.QUOTE);
|
|
1443
|
+
circuitBreaker = j({
|
|
951
1444
|
failureThreshold: 5,
|
|
952
1445
|
timeout: 1e4,
|
|
953
1446
|
// 10 seconds for faster recovery
|
|
@@ -956,10 +1449,15 @@ class ut {
|
|
|
956
1449
|
constructor(e, r) {
|
|
957
1450
|
this.publicKey = e, this.routeDiscovery = r;
|
|
958
1451
|
}
|
|
959
|
-
/**
|
|
1452
|
+
/**
|
|
1453
|
+
* Initialize Stripe.js library
|
|
1454
|
+
*
|
|
1455
|
+
* Concurrent callers share a single loadStripe() call via a cached promise.
|
|
1456
|
+
*/
|
|
960
1457
|
async initialize() {
|
|
961
|
-
|
|
962
|
-
throw new Error("Failed to initialize Stripe");
|
|
1458
|
+
this.stripe || (this.initPromise || (this.initPromise = (async () => {
|
|
1459
|
+
if (this.stripe = await Ce(this.publicKey), !this.stripe) throw new Error("Failed to initialize Stripe");
|
|
1460
|
+
})()), await this.initPromise);
|
|
963
1461
|
}
|
|
964
1462
|
/** Internal helper: execute with rate limiting, circuit breaker, and retry */
|
|
965
1463
|
async executeWithResilience(e, r, a, n) {
|
|
@@ -967,10 +1465,10 @@ class ut {
|
|
|
967
1465
|
throw new Error("Rate limit exceeded. Please try again later.");
|
|
968
1466
|
try {
|
|
969
1467
|
return await this.circuitBreaker.execute(
|
|
970
|
-
() =>
|
|
1468
|
+
() => b(r, { ...E.STANDARD, name: a })
|
|
971
1469
|
);
|
|
972
1470
|
} catch (i) {
|
|
973
|
-
throw i instanceof
|
|
1471
|
+
throw i instanceof A ? (c().error(`[SubscriptionManager] Circuit breaker OPEN for ${n}`), new Error("Service temporarily unavailable. Please try again in a few moments.")) : i;
|
|
974
1472
|
}
|
|
975
1473
|
}
|
|
976
1474
|
/**
|
|
@@ -979,38 +1477,39 @@ class ut {
|
|
|
979
1477
|
async createSubscriptionSession(e) {
|
|
980
1478
|
if (!this.sessionRateLimiter.tryConsume())
|
|
981
1479
|
throw new Error("Rate limit exceeded for subscription session creation. Please try again later.");
|
|
1480
|
+
const r = S();
|
|
982
1481
|
try {
|
|
983
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1482
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
984
1483
|
async () => {
|
|
985
|
-
const
|
|
1484
|
+
const a = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/stripe-session");
|
|
986
1485
|
c().debug("[SubscriptionManager] Creating subscription session:", {
|
|
987
1486
|
resource: e.resource,
|
|
988
1487
|
interval: e.interval,
|
|
989
1488
|
trialDays: e.trialDays
|
|
990
1489
|
});
|
|
991
|
-
const
|
|
1490
|
+
const n = await p(a, {
|
|
992
1491
|
method: "POST",
|
|
993
1492
|
headers: {
|
|
994
1493
|
"Content-Type": "application/json",
|
|
995
|
-
"Idempotency-Key":
|
|
1494
|
+
"Idempotency-Key": r
|
|
996
1495
|
},
|
|
997
1496
|
body: JSON.stringify(e)
|
|
998
1497
|
});
|
|
999
|
-
if (!
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1498
|
+
if (!n.ok) {
|
|
1499
|
+
const i = await g(
|
|
1500
|
+
n,
|
|
1002
1501
|
"Failed to create subscription session"
|
|
1003
1502
|
);
|
|
1004
|
-
throw new Error(
|
|
1503
|
+
throw new Error(i);
|
|
1005
1504
|
}
|
|
1006
|
-
return await
|
|
1505
|
+
return await n.json();
|
|
1007
1506
|
},
|
|
1008
|
-
{ ...
|
|
1507
|
+
{ ...E.STANDARD, name: "subscription-create-session" }
|
|
1009
1508
|
));
|
|
1010
|
-
} catch (
|
|
1011
|
-
throw
|
|
1509
|
+
} catch (a) {
|
|
1510
|
+
throw a instanceof A ? (c().error("[SubscriptionManager] Circuit breaker is OPEN - service unavailable"), new Error(
|
|
1012
1511
|
"Subscription service is temporarily unavailable. Please try again in a few moments."
|
|
1013
|
-
)) :
|
|
1512
|
+
)) : a;
|
|
1014
1513
|
}
|
|
1015
1514
|
}
|
|
1016
1515
|
/**
|
|
@@ -1038,7 +1537,7 @@ class ut {
|
|
|
1038
1537
|
} catch (r) {
|
|
1039
1538
|
return {
|
|
1040
1539
|
success: !1,
|
|
1041
|
-
error:
|
|
1540
|
+
error: T(r, "Subscription failed")
|
|
1042
1541
|
};
|
|
1043
1542
|
}
|
|
1044
1543
|
}
|
|
@@ -1049,7 +1548,7 @@ class ut {
|
|
|
1049
1548
|
if (!this.statusRateLimiter.tryConsume())
|
|
1050
1549
|
throw new Error("Rate limit exceeded for subscription status check. Please try again later.");
|
|
1051
1550
|
try {
|
|
1052
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1551
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1053
1552
|
async () => {
|
|
1054
1553
|
const r = new URLSearchParams({
|
|
1055
1554
|
resource: e.resource,
|
|
@@ -1058,14 +1557,14 @@ class ut {
|
|
|
1058
1557
|
`/paywall/v1/subscription/status?${r.toString()}`
|
|
1059
1558
|
);
|
|
1060
1559
|
c().debug("[SubscriptionManager] Checking subscription status:", e);
|
|
1061
|
-
const n = await
|
|
1560
|
+
const n = await p(a, {
|
|
1062
1561
|
method: "GET",
|
|
1063
1562
|
headers: {
|
|
1064
1563
|
"Content-Type": "application/json"
|
|
1065
1564
|
}
|
|
1066
1565
|
});
|
|
1067
1566
|
if (!n.ok) {
|
|
1068
|
-
const i = await
|
|
1567
|
+
const i = await g(
|
|
1069
1568
|
n,
|
|
1070
1569
|
"Failed to check subscription status"
|
|
1071
1570
|
);
|
|
@@ -1073,10 +1572,10 @@ class ut {
|
|
|
1073
1572
|
}
|
|
1074
1573
|
return await n.json();
|
|
1075
1574
|
},
|
|
1076
|
-
{ ...
|
|
1575
|
+
{ ...E.STANDARD, name: "subscription-status-check" }
|
|
1077
1576
|
));
|
|
1078
1577
|
} catch (r) {
|
|
1079
|
-
throw r instanceof
|
|
1578
|
+
throw r instanceof A ? (c().error("[SubscriptionManager] Circuit breaker is OPEN for status check"), new Error(
|
|
1080
1579
|
"Subscription status service is temporarily unavailable. Please try again in a few moments."
|
|
1081
1580
|
)) : r;
|
|
1082
1581
|
}
|
|
@@ -1088,7 +1587,7 @@ class ut {
|
|
|
1088
1587
|
if (!this.statusRateLimiter.tryConsume())
|
|
1089
1588
|
throw new Error("Rate limit exceeded for subscription quote. Please try again later.");
|
|
1090
1589
|
try {
|
|
1091
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1590
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1092
1591
|
async () => {
|
|
1093
1592
|
const n = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/quote"), i = {
|
|
1094
1593
|
resource: e,
|
|
@@ -1097,7 +1596,7 @@ class ut {
|
|
|
1097
1596
|
intervalDays: a?.intervalDays
|
|
1098
1597
|
};
|
|
1099
1598
|
c().debug("[SubscriptionManager] Requesting subscription quote:", i);
|
|
1100
|
-
const o = await
|
|
1599
|
+
const o = await p(n, {
|
|
1101
1600
|
method: "POST",
|
|
1102
1601
|
headers: {
|
|
1103
1602
|
"Content-Type": "application/json"
|
|
@@ -1105,7 +1604,7 @@ class ut {
|
|
|
1105
1604
|
body: JSON.stringify(i)
|
|
1106
1605
|
});
|
|
1107
1606
|
if (o.status !== 402 && !o.ok) {
|
|
1108
|
-
const s = await
|
|
1607
|
+
const s = await g(
|
|
1109
1608
|
o,
|
|
1110
1609
|
"Failed to get subscription quote"
|
|
1111
1610
|
);
|
|
@@ -1113,52 +1612,14 @@ class ut {
|
|
|
1113
1612
|
}
|
|
1114
1613
|
return await o.json();
|
|
1115
1614
|
},
|
|
1116
|
-
{ ...
|
|
1615
|
+
{ ...E.STANDARD, name: "subscription-quote" }
|
|
1117
1616
|
));
|
|
1118
1617
|
} catch (n) {
|
|
1119
|
-
throw n instanceof
|
|
1618
|
+
throw n instanceof A ? (c().error("[SubscriptionManager] Circuit breaker is OPEN for quote"), new Error(
|
|
1120
1619
|
"Subscription quote service is temporarily unavailable. Please try again in a few moments."
|
|
1121
1620
|
)) : n;
|
|
1122
1621
|
}
|
|
1123
1622
|
}
|
|
1124
|
-
/** Cancel a subscription */
|
|
1125
|
-
async cancelSubscription(e) {
|
|
1126
|
-
return this.executeWithResilience(
|
|
1127
|
-
this.sessionRateLimiter,
|
|
1128
|
-
async () => {
|
|
1129
|
-
const r = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/cancel");
|
|
1130
|
-
c().debug("[SubscriptionManager] Canceling subscription:", e);
|
|
1131
|
-
const a = await h(r, {
|
|
1132
|
-
method: "POST",
|
|
1133
|
-
headers: { "Content-Type": "application/json" },
|
|
1134
|
-
body: JSON.stringify(e)
|
|
1135
|
-
});
|
|
1136
|
-
if (!a.ok) throw new Error(await p(a, "Failed to cancel"));
|
|
1137
|
-
return await a.json();
|
|
1138
|
-
},
|
|
1139
|
-
"subscription-cancel",
|
|
1140
|
-
"cancellation"
|
|
1141
|
-
);
|
|
1142
|
-
}
|
|
1143
|
-
/** Get Stripe billing portal URL for subscription management */
|
|
1144
|
-
async getBillingPortalUrl(e) {
|
|
1145
|
-
return this.executeWithResilience(
|
|
1146
|
-
this.statusRateLimiter,
|
|
1147
|
-
async () => {
|
|
1148
|
-
const r = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/portal");
|
|
1149
|
-
c().debug("[SubscriptionManager] Getting billing portal URL:", e);
|
|
1150
|
-
const a = await h(r, {
|
|
1151
|
-
method: "POST",
|
|
1152
|
-
headers: { "Content-Type": "application/json" },
|
|
1153
|
-
body: JSON.stringify(e)
|
|
1154
|
-
});
|
|
1155
|
-
if (!a.ok) throw new Error(await p(a, "Failed to get portal"));
|
|
1156
|
-
return await a.json();
|
|
1157
|
-
},
|
|
1158
|
-
"subscription-portal",
|
|
1159
|
-
"portal"
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
1623
|
/** Activate x402 subscription after payment verification */
|
|
1163
1624
|
async activateX402Subscription(e) {
|
|
1164
1625
|
return this.executeWithResilience(
|
|
@@ -1166,12 +1627,12 @@ class ut {
|
|
|
1166
1627
|
async () => {
|
|
1167
1628
|
const r = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/x402/activate");
|
|
1168
1629
|
c().debug("[SubscriptionManager] Activating x402 subscription:", e);
|
|
1169
|
-
const a = await
|
|
1630
|
+
const a = await p(r, {
|
|
1170
1631
|
method: "POST",
|
|
1171
1632
|
headers: { "Content-Type": "application/json" },
|
|
1172
1633
|
body: JSON.stringify(e)
|
|
1173
1634
|
});
|
|
1174
|
-
if (!a.ok) throw new Error(await
|
|
1635
|
+
if (!a.ok) throw new Error(await g(a, "Failed to activate"));
|
|
1175
1636
|
return await a.json();
|
|
1176
1637
|
},
|
|
1177
1638
|
"subscription-activate",
|
|
@@ -1179,11 +1640,11 @@ class ut {
|
|
|
1179
1640
|
);
|
|
1180
1641
|
}
|
|
1181
1642
|
}
|
|
1182
|
-
class
|
|
1643
|
+
class bt {
|
|
1183
1644
|
routeDiscovery;
|
|
1184
|
-
rateLimiter =
|
|
1185
|
-
queryRateLimiter =
|
|
1186
|
-
circuitBreaker =
|
|
1645
|
+
rateLimiter = R(M.PAYMENT);
|
|
1646
|
+
queryRateLimiter = R(M.QUOTE);
|
|
1647
|
+
circuitBreaker = j({
|
|
1187
1648
|
failureThreshold: 5,
|
|
1188
1649
|
timeout: 1e4,
|
|
1189
1650
|
name: "subscription-change-manager"
|
|
@@ -1197,27 +1658,28 @@ class lt {
|
|
|
1197
1658
|
throw new Error("Rate limit exceeded. Please try again later.");
|
|
1198
1659
|
try {
|
|
1199
1660
|
return await this.circuitBreaker.execute(
|
|
1200
|
-
() =>
|
|
1661
|
+
() => b(r, { ...E.STANDARD, name: a })
|
|
1201
1662
|
);
|
|
1202
1663
|
} catch (i) {
|
|
1203
|
-
throw i instanceof
|
|
1664
|
+
throw i instanceof A ? (c().error(`[SubscriptionChangeManager] Circuit breaker OPEN for ${n}`), new Error("Service temporarily unavailable. Please try again in a few moments.")) : i;
|
|
1204
1665
|
}
|
|
1205
1666
|
}
|
|
1206
1667
|
/** Change subscription plan (upgrade or downgrade) */
|
|
1207
1668
|
async changeSubscription(e) {
|
|
1669
|
+
const r = S();
|
|
1208
1670
|
return this.executeWithResilience(
|
|
1209
1671
|
this.rateLimiter,
|
|
1210
1672
|
async () => {
|
|
1211
|
-
const
|
|
1673
|
+
const a = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/change");
|
|
1212
1674
|
c().debug("[SubscriptionChangeManager] Changing subscription:", e);
|
|
1213
|
-
const
|
|
1675
|
+
const n = await p(a, {
|
|
1214
1676
|
method: "POST",
|
|
1215
|
-
headers: { "Content-Type": "application/json", "Idempotency-Key":
|
|
1677
|
+
headers: { "Content-Type": "application/json", "Idempotency-Key": r },
|
|
1216
1678
|
body: JSON.stringify(e)
|
|
1217
1679
|
});
|
|
1218
|
-
if (!
|
|
1219
|
-
throw new Error(await
|
|
1220
|
-
return await
|
|
1680
|
+
if (!n.ok)
|
|
1681
|
+
throw new Error(await g(n, "Failed to change subscription"));
|
|
1682
|
+
return await n.json();
|
|
1221
1683
|
},
|
|
1222
1684
|
"subscription-change",
|
|
1223
1685
|
"plan change"
|
|
@@ -1230,13 +1692,13 @@ class lt {
|
|
|
1230
1692
|
async () => {
|
|
1231
1693
|
const r = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/change/preview");
|
|
1232
1694
|
c().debug("[SubscriptionChangeManager] Previewing subscription change:", e);
|
|
1233
|
-
const a = await
|
|
1695
|
+
const a = await p(r, {
|
|
1234
1696
|
method: "POST",
|
|
1235
1697
|
headers: { "Content-Type": "application/json" },
|
|
1236
1698
|
body: JSON.stringify(e)
|
|
1237
1699
|
});
|
|
1238
1700
|
if (!a.ok)
|
|
1239
|
-
throw new Error(await
|
|
1701
|
+
throw new Error(await g(a, "Failed to preview change"));
|
|
1240
1702
|
return await a.json();
|
|
1241
1703
|
},
|
|
1242
1704
|
"subscription-preview",
|
|
@@ -1250,12 +1712,12 @@ class lt {
|
|
|
1250
1712
|
async () => {
|
|
1251
1713
|
const a = new URLSearchParams({ resource: e, userId: r }), n = await this.routeDiscovery.buildUrl(`/paywall/v1/subscription/details?${a}`);
|
|
1252
1714
|
c().debug("[SubscriptionChangeManager] Getting subscription details:", { resource: e, userId: r });
|
|
1253
|
-
const i = await
|
|
1715
|
+
const i = await p(n, {
|
|
1254
1716
|
method: "GET",
|
|
1255
1717
|
headers: { "Content-Type": "application/json" }
|
|
1256
1718
|
});
|
|
1257
1719
|
if (!i.ok)
|
|
1258
|
-
throw new Error(await
|
|
1720
|
+
throw new Error(await g(i, "Failed to get subscription details"));
|
|
1259
1721
|
return await i.json();
|
|
1260
1722
|
},
|
|
1261
1723
|
"subscription-details",
|
|
@@ -1269,13 +1731,13 @@ class lt {
|
|
|
1269
1731
|
async () => {
|
|
1270
1732
|
const r = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/cancel");
|
|
1271
1733
|
c().debug("[SubscriptionChangeManager] Canceling subscription:", e);
|
|
1272
|
-
const a = await
|
|
1734
|
+
const a = await p(r, {
|
|
1273
1735
|
method: "POST",
|
|
1274
1736
|
headers: { "Content-Type": "application/json" },
|
|
1275
1737
|
body: JSON.stringify(e)
|
|
1276
1738
|
});
|
|
1277
1739
|
if (!a.ok)
|
|
1278
|
-
throw new Error(await
|
|
1740
|
+
throw new Error(await g(a, "Failed to cancel subscription"));
|
|
1279
1741
|
return await a.json();
|
|
1280
1742
|
},
|
|
1281
1743
|
"subscription-cancel",
|
|
@@ -1289,13 +1751,13 @@ class lt {
|
|
|
1289
1751
|
async () => {
|
|
1290
1752
|
const r = await this.routeDiscovery.buildUrl("/paywall/v1/subscription/portal");
|
|
1291
1753
|
c().debug("[SubscriptionChangeManager] Getting billing portal URL:", e);
|
|
1292
|
-
const a = await
|
|
1754
|
+
const a = await p(r, {
|
|
1293
1755
|
method: "POST",
|
|
1294
1756
|
headers: { "Content-Type": "application/json" },
|
|
1295
1757
|
body: JSON.stringify(e)
|
|
1296
1758
|
});
|
|
1297
1759
|
if (!a.ok)
|
|
1298
|
-
throw new Error(await
|
|
1760
|
+
throw new Error(await g(a, "Failed to get billing portal URL"));
|
|
1299
1761
|
return await a.json();
|
|
1300
1762
|
},
|
|
1301
1763
|
"subscription-portal",
|
|
@@ -1303,10 +1765,10 @@ class lt {
|
|
|
1303
1765
|
);
|
|
1304
1766
|
}
|
|
1305
1767
|
}
|
|
1306
|
-
class
|
|
1768
|
+
class vt {
|
|
1307
1769
|
routeDiscovery;
|
|
1308
|
-
rateLimiter =
|
|
1309
|
-
circuitBreaker =
|
|
1770
|
+
rateLimiter = R(M.PAYMENT);
|
|
1771
|
+
circuitBreaker = j({
|
|
1310
1772
|
failureThreshold: 5,
|
|
1311
1773
|
timeout: 1e4,
|
|
1312
1774
|
name: "credits-manager"
|
|
@@ -1318,11 +1780,11 @@ class dt {
|
|
|
1318
1780
|
if (!this.rateLimiter.tryConsume())
|
|
1319
1781
|
throw new Error("Rate limit exceeded for credits quote. Please try again later.");
|
|
1320
1782
|
try {
|
|
1321
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1783
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1322
1784
|
async () => {
|
|
1323
1785
|
const a = await this.routeDiscovery.buildUrl("/paywall/v1/quote");
|
|
1324
|
-
c().debug("[CreditsManager] Requesting quote
|
|
1325
|
-
const n = await
|
|
1786
|
+
c().debug("[CreditsManager] Requesting quote");
|
|
1787
|
+
const n = await p(a, {
|
|
1326
1788
|
method: "POST",
|
|
1327
1789
|
headers: { "Content-Type": "application/json" },
|
|
1328
1790
|
body: JSON.stringify({ resource: e, couponCode: r })
|
|
@@ -1330,44 +1792,44 @@ class dt {
|
|
|
1330
1792
|
if (n.status === 402)
|
|
1331
1793
|
return (await n.json()).credits || null;
|
|
1332
1794
|
if (!n.ok) {
|
|
1333
|
-
const i = await
|
|
1795
|
+
const i = await g(n, "Failed to get credits quote");
|
|
1334
1796
|
throw new Error(i);
|
|
1335
1797
|
}
|
|
1336
1798
|
return null;
|
|
1337
1799
|
},
|
|
1338
|
-
{ ...
|
|
1800
|
+
{ ...E.STANDARD, name: "credits-quote" }
|
|
1339
1801
|
));
|
|
1340
1802
|
} catch (a) {
|
|
1341
|
-
throw a instanceof
|
|
1803
|
+
throw a instanceof A ? (c().error("[CreditsManager] Circuit breaker is OPEN - credits service unavailable"), new Error("Credits service is temporarily unavailable. Please try again in a few moments.")) : a;
|
|
1342
1804
|
}
|
|
1343
1805
|
}
|
|
1344
1806
|
async requestCartQuote(e, r) {
|
|
1345
1807
|
if (!this.rateLimiter.tryConsume())
|
|
1346
1808
|
throw new Error("Rate limit exceeded for cart credits quote. Please try again later.");
|
|
1347
1809
|
try {
|
|
1348
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1810
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1349
1811
|
async () => {
|
|
1350
1812
|
const a = await this.routeDiscovery.buildUrl("/paywall/v1/cart/quote");
|
|
1351
1813
|
c().debug("[CreditsManager] Requesting cart quote for items:", e.length);
|
|
1352
|
-
const n = await
|
|
1814
|
+
const n = await p(a, {
|
|
1353
1815
|
method: "POST",
|
|
1354
1816
|
headers: { "Content-Type": "application/json" },
|
|
1355
1817
|
body: JSON.stringify({ items: e, couponCode: r })
|
|
1356
1818
|
});
|
|
1357
|
-
if (
|
|
1358
|
-
const o = await
|
|
1359
|
-
|
|
1819
|
+
if (n.status === 402 || n.ok) {
|
|
1820
|
+
const o = await n.json();
|
|
1821
|
+
return o.credits ? {
|
|
1822
|
+
cartId: o.cartId,
|
|
1823
|
+
credits: o.credits
|
|
1824
|
+
} : null;
|
|
1360
1825
|
}
|
|
1361
|
-
const i = await n
|
|
1362
|
-
|
|
1363
|
-
cartId: i.cartId,
|
|
1364
|
-
credits: i.credits
|
|
1365
|
-
} : null;
|
|
1826
|
+
const i = await g(n, "Failed to get cart credits quote");
|
|
1827
|
+
throw new Error(i);
|
|
1366
1828
|
},
|
|
1367
|
-
{ ...
|
|
1829
|
+
{ ...E.STANDARD, name: "credits-cart-quote" }
|
|
1368
1830
|
));
|
|
1369
1831
|
} catch (a) {
|
|
1370
|
-
throw a instanceof
|
|
1832
|
+
throw a instanceof A ? new Error("Credits service is temporarily unavailable. Please try again in a few moments.") : a;
|
|
1371
1833
|
}
|
|
1372
1834
|
}
|
|
1373
1835
|
/**
|
|
@@ -1378,30 +1840,31 @@ class dt {
|
|
|
1378
1840
|
const { resource: r, couponCode: a, authToken: n } = e;
|
|
1379
1841
|
if (!this.rateLimiter.tryConsume())
|
|
1380
1842
|
throw new Error("Rate limit exceeded for credits hold. Please try again later.");
|
|
1843
|
+
const i = S();
|
|
1381
1844
|
try {
|
|
1382
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1845
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1383
1846
|
async () => {
|
|
1384
|
-
const
|
|
1385
|
-
c().debug("[CreditsManager] Creating hold
|
|
1386
|
-
const
|
|
1847
|
+
const o = await this.routeDiscovery.buildUrl("/paywall/v1/credits/hold");
|
|
1848
|
+
c().debug("[CreditsManager] Creating hold");
|
|
1849
|
+
const s = await p(o, {
|
|
1387
1850
|
method: "POST",
|
|
1388
1851
|
headers: {
|
|
1389
1852
|
"Content-Type": "application/json",
|
|
1390
1853
|
Authorization: `Bearer ${n}`,
|
|
1391
|
-
"Idempotency-Key":
|
|
1854
|
+
"Idempotency-Key": i
|
|
1392
1855
|
},
|
|
1393
1856
|
body: JSON.stringify({ resource: r, couponCode: a })
|
|
1394
1857
|
});
|
|
1395
|
-
if (!
|
|
1396
|
-
const
|
|
1397
|
-
throw new Error(
|
|
1858
|
+
if (!s.ok) {
|
|
1859
|
+
const l = await g(s, "Failed to create credits hold");
|
|
1860
|
+
throw new Error(l);
|
|
1398
1861
|
}
|
|
1399
|
-
return await
|
|
1862
|
+
return await s.json();
|
|
1400
1863
|
},
|
|
1401
|
-
{ ...
|
|
1864
|
+
{ ...E.STANDARD, name: "credits-create-hold" }
|
|
1402
1865
|
));
|
|
1403
|
-
} catch (
|
|
1404
|
-
throw
|
|
1866
|
+
} catch (o) {
|
|
1867
|
+
throw o instanceof A ? new Error("Credits service is temporarily unavailable. Please try again in a few moments.") : o;
|
|
1405
1868
|
}
|
|
1406
1869
|
}
|
|
1407
1870
|
/**
|
|
@@ -1412,30 +1875,31 @@ class dt {
|
|
|
1412
1875
|
const { cartId: r, authToken: a } = e;
|
|
1413
1876
|
if (!this.rateLimiter.tryConsume())
|
|
1414
1877
|
throw new Error("Rate limit exceeded for cart credits hold. Please try again later.");
|
|
1878
|
+
const n = S();
|
|
1415
1879
|
try {
|
|
1416
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1880
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1417
1881
|
async () => {
|
|
1418
|
-
const
|
|
1882
|
+
const i = await this.routeDiscovery.buildUrl(`/paywall/v1/cart/${encodeURIComponent(r)}/credits/hold`);
|
|
1419
1883
|
c().debug("[CreditsManager] Creating cart hold for cart:", r);
|
|
1420
|
-
const
|
|
1884
|
+
const o = await p(i, {
|
|
1421
1885
|
method: "POST",
|
|
1422
1886
|
headers: {
|
|
1423
1887
|
"Content-Type": "application/json",
|
|
1424
1888
|
Authorization: `Bearer ${a}`,
|
|
1425
|
-
"Idempotency-Key":
|
|
1889
|
+
"Idempotency-Key": n
|
|
1426
1890
|
},
|
|
1427
1891
|
body: JSON.stringify({})
|
|
1428
1892
|
});
|
|
1429
|
-
if (!
|
|
1430
|
-
const
|
|
1431
|
-
throw new Error(
|
|
1893
|
+
if (!o.ok) {
|
|
1894
|
+
const s = await g(o, "Failed to create cart credits hold");
|
|
1895
|
+
throw new Error(s);
|
|
1432
1896
|
}
|
|
1433
|
-
return await
|
|
1897
|
+
return await o.json();
|
|
1434
1898
|
},
|
|
1435
|
-
{ ...
|
|
1899
|
+
{ ...E.STANDARD, name: "credits-create-cart-hold" }
|
|
1436
1900
|
));
|
|
1437
|
-
} catch (
|
|
1438
|
-
throw
|
|
1901
|
+
} catch (i) {
|
|
1902
|
+
throw i instanceof A ? new Error("Credits service is temporarily unavailable. Please try again in a few moments.") : i;
|
|
1439
1903
|
}
|
|
1440
1904
|
}
|
|
1441
1905
|
async authorizePayment(e) {
|
|
@@ -1446,17 +1910,18 @@ class dt {
|
|
|
1446
1910
|
error: "Rate limit exceeded for credits authorization. Please try again later.",
|
|
1447
1911
|
errorCode: "rate_limit_exceeded"
|
|
1448
1912
|
};
|
|
1913
|
+
const s = S();
|
|
1449
1914
|
try {
|
|
1450
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1915
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1451
1916
|
async () => {
|
|
1452
|
-
const
|
|
1453
|
-
c().debug("[CreditsManager] Authorizing payment
|
|
1454
|
-
const
|
|
1917
|
+
const l = await this.routeDiscovery.buildUrl("/paywall/v1/credits/authorize");
|
|
1918
|
+
c().debug("[CreditsManager] Authorizing payment");
|
|
1919
|
+
const d = await p(l, {
|
|
1455
1920
|
method: "POST",
|
|
1456
1921
|
headers: {
|
|
1457
1922
|
"Content-Type": "application/json",
|
|
1458
1923
|
Authorization: `Bearer ${i}`,
|
|
1459
|
-
"Idempotency-Key":
|
|
1924
|
+
"Idempotency-Key": s
|
|
1460
1925
|
},
|
|
1461
1926
|
body: JSON.stringify({
|
|
1462
1927
|
resource: r,
|
|
@@ -1465,29 +1930,29 @@ class dt {
|
|
|
1465
1930
|
...o && { metadata: o }
|
|
1466
1931
|
})
|
|
1467
1932
|
});
|
|
1468
|
-
if (!
|
|
1469
|
-
const
|
|
1933
|
+
if (!d.ok) {
|
|
1934
|
+
const u = await d.json().catch(() => ({}));
|
|
1470
1935
|
return {
|
|
1471
1936
|
success: !1,
|
|
1472
|
-
error:
|
|
1473
|
-
errorCode:
|
|
1937
|
+
error: u.error?.message || "Credits authorization failed",
|
|
1938
|
+
errorCode: u.error?.code || "authorization_failed"
|
|
1474
1939
|
};
|
|
1475
1940
|
}
|
|
1476
1941
|
return {
|
|
1477
1942
|
success: !0,
|
|
1478
|
-
transactionId: (await
|
|
1943
|
+
transactionId: (await d.json()).transactionId
|
|
1479
1944
|
};
|
|
1480
1945
|
},
|
|
1481
|
-
{ ...
|
|
1946
|
+
{ ...E.STANDARD, name: "credits-authorize" }
|
|
1482
1947
|
));
|
|
1483
|
-
} catch (
|
|
1484
|
-
return
|
|
1948
|
+
} catch (l) {
|
|
1949
|
+
return l instanceof A ? {
|
|
1485
1950
|
success: !1,
|
|
1486
1951
|
error: "Credits service is temporarily unavailable. Please try again in a few moments.",
|
|
1487
1952
|
errorCode: "service_unavailable"
|
|
1488
1953
|
} : {
|
|
1489
1954
|
success: !1,
|
|
1490
|
-
error:
|
|
1955
|
+
error: T(l, "Credits authorization failed"),
|
|
1491
1956
|
errorCode: "authorization_failed"
|
|
1492
1957
|
};
|
|
1493
1958
|
}
|
|
@@ -1500,54 +1965,75 @@ class dt {
|
|
|
1500
1965
|
error: "Rate limit exceeded for cart credits authorization. Please try again later.",
|
|
1501
1966
|
errorCode: "rate_limit_exceeded"
|
|
1502
1967
|
};
|
|
1968
|
+
const o = S();
|
|
1503
1969
|
try {
|
|
1504
|
-
return await this.circuitBreaker.execute(async () => await
|
|
1970
|
+
return await this.circuitBreaker.execute(async () => await b(
|
|
1505
1971
|
async () => {
|
|
1506
|
-
const
|
|
1972
|
+
const s = await this.routeDiscovery.buildUrl(`/paywall/v1/cart/${encodeURIComponent(r)}/credits/authorize`);
|
|
1507
1973
|
c().debug("[CreditsManager] Authorizing cart payment for cart:", r);
|
|
1508
|
-
const
|
|
1974
|
+
const l = await p(s, {
|
|
1509
1975
|
method: "POST",
|
|
1510
1976
|
headers: {
|
|
1511
1977
|
"Content-Type": "application/json",
|
|
1512
1978
|
Authorization: `Bearer ${n}`,
|
|
1513
|
-
"Idempotency-Key":
|
|
1979
|
+
"Idempotency-Key": o
|
|
1514
1980
|
},
|
|
1515
1981
|
body: JSON.stringify({
|
|
1516
1982
|
holdId: a,
|
|
1517
1983
|
...i && { metadata: i }
|
|
1518
1984
|
})
|
|
1519
1985
|
});
|
|
1520
|
-
if (!
|
|
1521
|
-
const
|
|
1986
|
+
if (!l.ok) {
|
|
1987
|
+
const m = await l.json().catch((u) => (c().error("[CreditsManager] Failed to parse error response JSON:", u, {
|
|
1522
1988
|
cartId: r,
|
|
1523
|
-
status:
|
|
1524
|
-
statusText:
|
|
1989
|
+
status: l.status,
|
|
1990
|
+
statusText: l.statusText
|
|
1525
1991
|
}), {}));
|
|
1526
1992
|
return {
|
|
1527
1993
|
success: !1,
|
|
1528
|
-
error:
|
|
1529
|
-
errorCode:
|
|
1994
|
+
error: m.error?.message || "Cart credits authorization failed",
|
|
1995
|
+
errorCode: m.error?.code || "authorization_failed"
|
|
1530
1996
|
};
|
|
1531
1997
|
}
|
|
1532
1998
|
return {
|
|
1533
1999
|
success: !0,
|
|
1534
|
-
transactionId: (await
|
|
2000
|
+
transactionId: (await l.json()).transactionId
|
|
1535
2001
|
};
|
|
1536
2002
|
},
|
|
1537
|
-
{ ...
|
|
2003
|
+
{ ...E.STANDARD, name: "credits-cart-authorize" }
|
|
1538
2004
|
));
|
|
1539
|
-
} catch (
|
|
1540
|
-
return
|
|
2005
|
+
} catch (s) {
|
|
2006
|
+
return s instanceof A ? {
|
|
1541
2007
|
success: !1,
|
|
1542
2008
|
error: "Credits service is temporarily unavailable. Please try again in a few moments.",
|
|
1543
2009
|
errorCode: "service_unavailable"
|
|
1544
2010
|
} : {
|
|
1545
2011
|
success: !1,
|
|
1546
|
-
error:
|
|
2012
|
+
error: T(s, "Cart credits authorization failed"),
|
|
1547
2013
|
errorCode: "authorization_failed"
|
|
1548
2014
|
};
|
|
1549
2015
|
}
|
|
1550
2016
|
}
|
|
2017
|
+
async releaseHold(e, r) {
|
|
2018
|
+
if (e)
|
|
2019
|
+
try {
|
|
2020
|
+
await this.circuitBreaker.execute(async () => {
|
|
2021
|
+
const a = await this.routeDiscovery.buildUrl(`/paywall/v1/credits/hold/${encodeURIComponent(e)}/release`), n = await p(a, {
|
|
2022
|
+
method: "POST",
|
|
2023
|
+
headers: {
|
|
2024
|
+
Authorization: `Bearer ${r}`,
|
|
2025
|
+
"Idempotency-Key": S()
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
if (!n.ok) {
|
|
2029
|
+
const i = await g(n, "Failed to release credits hold");
|
|
2030
|
+
throw new Error(i);
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
} catch (a) {
|
|
2034
|
+
throw a instanceof A ? new Error("Credits service is temporarily unavailable. Please try again in a few moments.") : a;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
1551
2037
|
/**
|
|
1552
2038
|
* Process a complete credits payment (convenience method)
|
|
1553
2039
|
* Combines createHold + authorizePayment in one call
|
|
@@ -1558,35 +2044,52 @@ class dt {
|
|
|
1558
2044
|
* @param metadata - Optional metadata
|
|
1559
2045
|
*/
|
|
1560
2046
|
async processPayment(e, r, a, n) {
|
|
2047
|
+
let i = null;
|
|
1561
2048
|
try {
|
|
1562
|
-
|
|
2049
|
+
i = (await this.createHold({ resource: e, couponCode: a, authToken: r })).holdId;
|
|
2050
|
+
const s = await this.authorizePayment({
|
|
1563
2051
|
resource: e,
|
|
1564
|
-
holdId: i
|
|
2052
|
+
holdId: i,
|
|
1565
2053
|
couponCode: a,
|
|
1566
2054
|
authToken: r,
|
|
1567
2055
|
metadata: n
|
|
1568
2056
|
});
|
|
2057
|
+
if (!s.success && i)
|
|
2058
|
+
try {
|
|
2059
|
+
await this.releaseHold(i, r);
|
|
2060
|
+
} catch (l) {
|
|
2061
|
+
c().warn("[CreditsManager] Failed to release hold after auth failure:", l);
|
|
2062
|
+
}
|
|
1569
2063
|
return {
|
|
1570
|
-
success:
|
|
1571
|
-
transactionId:
|
|
1572
|
-
error:
|
|
2064
|
+
success: s.success,
|
|
2065
|
+
transactionId: s.transactionId,
|
|
2066
|
+
error: s.error
|
|
1573
2067
|
};
|
|
1574
|
-
} catch (
|
|
2068
|
+
} catch (o) {
|
|
2069
|
+
if (i)
|
|
2070
|
+
try {
|
|
2071
|
+
await this.releaseHold(i, r);
|
|
2072
|
+
} catch (s) {
|
|
2073
|
+
c().warn("[CreditsManager] Failed to release hold after payment failure:", s);
|
|
2074
|
+
}
|
|
1575
2075
|
return {
|
|
1576
2076
|
success: !1,
|
|
1577
|
-
error:
|
|
2077
|
+
error: T(o, "Credits payment failed")
|
|
1578
2078
|
};
|
|
1579
2079
|
}
|
|
1580
2080
|
}
|
|
1581
2081
|
}
|
|
1582
|
-
class
|
|
2082
|
+
class Ct {
|
|
1583
2083
|
serverUrl;
|
|
1584
2084
|
routePrefix = null;
|
|
1585
2085
|
discoveryPromise = null;
|
|
1586
|
-
|
|
2086
|
+
failedDiscoveryAt = null;
|
|
2087
|
+
maxRetries = 2;
|
|
1587
2088
|
baseDelayMs = 1e3;
|
|
2089
|
+
discoveryTimeoutMs = 2e3;
|
|
2090
|
+
failedDiscoveryTtlMs = 3e4;
|
|
1588
2091
|
constructor(e) {
|
|
1589
|
-
this.serverUrl = e;
|
|
2092
|
+
this.serverUrl = e.replace(/\/+$/, "");
|
|
1590
2093
|
}
|
|
1591
2094
|
/**
|
|
1592
2095
|
* Discover route prefix from backend health endpoint
|
|
@@ -1600,24 +2103,30 @@ class ft {
|
|
|
1600
2103
|
return this.routePrefix;
|
|
1601
2104
|
if (this.discoveryPromise)
|
|
1602
2105
|
return this.discoveryPromise;
|
|
2106
|
+
if (this.failedDiscoveryAt !== null && Date.now() - this.failedDiscoveryAt < this.failedDiscoveryTtlMs)
|
|
2107
|
+
return c().warn("[RouteDiscoveryManager] Returning empty prefix from negative cache (previous discovery failed)"), "";
|
|
1603
2108
|
const e = (async () => {
|
|
1604
2109
|
let r = 0;
|
|
1605
2110
|
for (; r < this.maxRetries; )
|
|
1606
2111
|
try {
|
|
1607
|
-
const a = await
|
|
2112
|
+
const a = await p(
|
|
2113
|
+
`${this.serverUrl}/cedros-health`,
|
|
2114
|
+
{},
|
|
2115
|
+
this.discoveryTimeoutMs
|
|
2116
|
+
);
|
|
1608
2117
|
if (!a.ok) {
|
|
1609
2118
|
if (a.status >= 400 && a.status < 500)
|
|
1610
|
-
return c().warn(`Route discovery received ${a.status} - not retrying client error`), this.
|
|
2119
|
+
return c().warn(`Route discovery received ${a.status} - not retrying client error`), this.failedDiscoveryAt = Date.now(), "";
|
|
1611
2120
|
throw new Error(`Health check returned ${a.status}`);
|
|
1612
2121
|
}
|
|
1613
2122
|
const i = (await a.json()).routePrefix || "";
|
|
1614
|
-
return this.routePrefix = i, c().debug("Route discovery successful, prefix:", i || "(empty)"), i;
|
|
2123
|
+
return this.routePrefix = i, this.failedDiscoveryAt = null, c().debug("Route discovery successful, prefix:", i || "(empty)"), i;
|
|
1615
2124
|
} catch (a) {
|
|
1616
2125
|
if (r++, r >= this.maxRetries)
|
|
1617
2126
|
return c().warn(
|
|
1618
2127
|
`Route discovery failed after ${r} attempts, using empty prefix for this request:`,
|
|
1619
2128
|
a
|
|
1620
|
-
), "";
|
|
2129
|
+
), this.failedDiscoveryAt = Date.now(), "";
|
|
1621
2130
|
const n = this.baseDelayMs * Math.pow(2, r - 1);
|
|
1622
2131
|
c().warn(
|
|
1623
2132
|
`Route discovery failed (attempt ${r}/${this.maxRetries}), retrying in ${n}ms:`,
|
|
@@ -1644,15 +2153,15 @@ class ft {
|
|
|
1644
2153
|
* Reset cached prefix (useful for testing or reconnecting)
|
|
1645
2154
|
*/
|
|
1646
2155
|
reset() {
|
|
1647
|
-
this.routePrefix = null, this.discoveryPromise = null;
|
|
2156
|
+
this.routePrefix = null, this.discoveryPromise = null, this.failedDiscoveryAt = null;
|
|
1648
2157
|
}
|
|
1649
2158
|
}
|
|
1650
|
-
let
|
|
1651
|
-
async function
|
|
1652
|
-
return
|
|
2159
|
+
let X = null;
|
|
2160
|
+
async function Et() {
|
|
2161
|
+
return X || (X = (await import("./WalletManager-HXXyARQ7.mjs")).WalletManager), X;
|
|
1653
2162
|
}
|
|
1654
|
-
const
|
|
1655
|
-
function
|
|
2163
|
+
const J = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map();
|
|
2164
|
+
function Ue(t, e, r, a, n) {
|
|
1656
2165
|
return JSON.stringify({
|
|
1657
2166
|
stripePublicKey: t,
|
|
1658
2167
|
serverUrl: e,
|
|
@@ -1661,48 +2170,62 @@ function Me(t, e, r, a, n) {
|
|
|
1661
2170
|
dangerouslyAllowUnknownMint: n || !1
|
|
1662
2171
|
});
|
|
1663
2172
|
}
|
|
1664
|
-
async function
|
|
1665
|
-
const i =
|
|
2173
|
+
async function Pt(t, e, r, a, n) {
|
|
2174
|
+
const i = Ue(
|
|
1666
2175
|
t,
|
|
1667
2176
|
e,
|
|
1668
2177
|
r,
|
|
1669
2178
|
a,
|
|
1670
2179
|
n
|
|
1671
2180
|
);
|
|
1672
|
-
let o =
|
|
2181
|
+
let o = J.get(i);
|
|
1673
2182
|
if (o)
|
|
1674
2183
|
return o.refCount++, c().debug(
|
|
1675
2184
|
`[ManagerCache] Reusing cached managers (refCount: ${o.refCount}):`,
|
|
1676
2185
|
{ stripePublicKey: t.slice(0, 10) + "...", serverUrl: e }
|
|
1677
2186
|
), o;
|
|
2187
|
+
const s = Z.get(i);
|
|
2188
|
+
if (s)
|
|
2189
|
+
return o = await s, o.refCount++, c().debug(
|
|
2190
|
+
`[ManagerCache] Reusing in-flight managers (refCount: ${o.refCount}):`,
|
|
2191
|
+
{ stripePublicKey: t.slice(0, 10) + "...", serverUrl: e }
|
|
2192
|
+
), o;
|
|
1678
2193
|
c().debug(
|
|
1679
2194
|
"[ManagerCache] Creating new manager instances:",
|
|
1680
2195
|
{ stripePublicKey: t.slice(0, 10) + "...", serverUrl: e }
|
|
1681
2196
|
);
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
2197
|
+
const l = (async () => {
|
|
2198
|
+
const d = new Ct(e), m = new st(t, d), u = new gt(d), y = await Et(), f = new y(
|
|
2199
|
+
r,
|
|
2200
|
+
a,
|
|
2201
|
+
n ?? !1
|
|
2202
|
+
), h = new wt(t, d), w = new bt(d), C = new vt(d);
|
|
2203
|
+
return {
|
|
2204
|
+
stripeManager: m,
|
|
2205
|
+
x402Manager: u,
|
|
2206
|
+
walletManager: f,
|
|
2207
|
+
subscriptionManager: h,
|
|
2208
|
+
subscriptionChangeManager: w,
|
|
2209
|
+
creditsManager: C,
|
|
2210
|
+
routeDiscovery: d,
|
|
2211
|
+
refCount: 1
|
|
2212
|
+
};
|
|
2213
|
+
})();
|
|
2214
|
+
Z.set(i, l);
|
|
2215
|
+
try {
|
|
2216
|
+
return o = await l, J.set(i, o), o;
|
|
2217
|
+
} finally {
|
|
2218
|
+
Z.delete(i);
|
|
2219
|
+
}
|
|
1697
2220
|
}
|
|
1698
|
-
function
|
|
1699
|
-
const i =
|
|
2221
|
+
function ye(t, e, r, a, n) {
|
|
2222
|
+
const i = Ue(
|
|
1700
2223
|
t,
|
|
1701
2224
|
e,
|
|
1702
2225
|
r,
|
|
1703
2226
|
a,
|
|
1704
2227
|
n
|
|
1705
|
-
), o =
|
|
2228
|
+
), o = J.get(i);
|
|
1706
2229
|
if (!o) {
|
|
1707
2230
|
c().warn("[ManagerCache] Attempted to release non-existent managers:", { cacheKey: i });
|
|
1708
2231
|
return;
|
|
@@ -1710,49 +2233,49 @@ function pt(t, e, r, a, n) {
|
|
|
1710
2233
|
o.refCount--, c().debug(
|
|
1711
2234
|
`[ManagerCache] Released manager reference (refCount: ${o.refCount}):`,
|
|
1712
2235
|
{ stripePublicKey: t.slice(0, 10) + "...", serverUrl: e }
|
|
1713
|
-
), o.refCount <= 0 && (
|
|
2236
|
+
), o.refCount <= 0 && (J.delete(i), c().debug("[ManagerCache] Removed managers from cache (refCount reached 0)"));
|
|
1714
2237
|
}
|
|
1715
|
-
const
|
|
2238
|
+
const St = "data:image/webp;base64,UklGRnIIAABXRUJQVlA4WAoAAAAYAAAAOwAAOwAAQUxQSK4BAAABkHPbtrE9+z73/RTbqWw7Lf+BbbNKbTudbZe2qy+VbVv3PmeHj05G6ohg4LaRounNMtN1voB42ABA5R7TNlx5+O7du9e3Tiwb0b4EgFyAOCQM1Z16+DWFUZC7m3uVB2zKQGBhe+77RGHonJffCL1zQuHDxQ1hrEmTatDjHIXOC2MgzpNf1tVJkWgsGhyihI7JIE74aUYp2ITFAoz9QO+ZAs7zanvkEilKbIkMJS5ANwoJmrCodYVOmBqh5zIEJjZc9xods4A4rrPGxGitrJSU71yNyH4Myl7JTEl+5zzYSH9nlkrxHBzxWUzLVEnhh+YI/gq3+UphpvA8m/s7/wg9M4bjFNg/0vplrxQ+rQEDg/xihmT23jxYJZ8UPq8OA5z77Wt405FDR4poSMjiAJhPRxUIu8D+UVonOhfNPEVHPM9juFacwo+1V6kJQ3Y9Sa8ljhPuUvRk4UdNWU9ST3b9n0W3iG5DumdS9y7o3kHVu6/75ii/dbpvrO7brvtPUf2X6f5DVf/dmpxBmauociRVbqbKCXW5qCoHVuXempxf1dZQtXFUbat/yKZTtSUBVlA4INwFAABwGgCdASo8ADwAPm0qj0WkIqEZ+zYAQAbEtgBOmZoZF+E8zGoP3X8VbcdLvma8t+jH0E+YB+ofSA8wH7VdQv0AP75/iOsG9ADy3/Y5/b/91fgI/Y7MOesb0e/q+TUR1vt7VO6mwG0imO70GM5/0P7BX6qelv7EP209lz9oDRea09ZR+SjhX7sBu/ZS7tG917rPgI3Q7XsB7luy2hAg/95C2Z1L362OH1oFziDY/K5gWoSytSAtiKvA/jW1MehBzdLzJfszPPBvGa15IYwIVRTjO2Hz5ZS9HjLMehwAAP64SgjD3qeg6NRe/Ok+iFhrG3pgglCfbam3yBaDUH36sUiQx0PB1ZZyOHq0ky+f97h6tJMvo0p9LkfXecWOFJ8J5G7yRPuL4tzGLT09QulTJw42xp2hd+lMgIa51XoHx/iftn8B2D3k92H5jOQr+uIXFHHK5FpcTG+qGEF+np0LiQa+vdW7/+ZzOLVRf7jR5X3ANPt93Ng92DW7NflVr6kMr88O/v2ZNb0vtgao2Am/R3CDKiNq89f86CT6r2L2g1oTui7H3E1yhSPQpEOz01I3fhfiMMv4weqKuoedxn/xLg5uzHa6Gte4C/dQYkG3ZFSy4CXQtRjftBrjX/Oj+HpSUPDsv0wPW+ml5NbBKDCj2f3SD8TVMf2ZfHrOkR602RVk2UmKC+H0Y9iK6k98vsgPINtz0II8X7Mj2nJkTC6IMLuQ8dNTUq9VXOnhXrdhNZoaH94ePo6baBl3hTGFAnD3/b+gR/vtbqV7wktuX6fpnjeTBe/Drp6z3neeANj/aX4CsU9w67nwYOjZhueCjxaDKUnNjLPjI1e0BoTbcOzOQ0wHJHZJ+Pt608StBu4HiJ8NjH46fnvXL3yiMoSvkAuwCE1AakA+eU1u3unyjl1/MnZQmbp8fzfsfrFesehLPcIkYdCiZ+52QbmINNTjEsvjuBuZRubBE+Laihppsxoo4efGIo0xkw0etu1+yzvkqp88w3pBq0mRl13gnnc+2zl6SmhwgmNFbz+F8qAqmdfJL8iaNSGEWlPlpczDDe62GBZMlBhQmq/XCn/1b+VazHvJXkoIFDF+wktMg+rKfLyfTlXdK0cs+Kn8h+rjMakkf3WLo1TftMLn+O+x/Gat+BGstJrM1xvCSSnHQY+NV4B4gRqyZ55gRNnqN/0lWrATOcHUaGXpkTIM/yxFjxcePcSFo+t2aJ5lShtVukETzRxaIXgRkpROeWQHWpTHOaexmXOzF0b833qJSoXMk2zB/uMrgDzKd7d3ohUz8Ra08WYKlAuMQD08bF4+jUepEspqPLoYLQ73TfmL+1LwKxyTV3gEu6WnxBPWPLnYIGYN9U47ZNlB+NgHgYtKTyii6060RAG+wN32WUVFxCZw0HMHnHFgwxD34L/anlpS7mOrjKgyuGYhFC7iHqTQHuoAO1ekBHV+rndnbETKfa1F7LxNLYq+dmJyytmQrJUCGjelorI1m/TMQNiFVrY4FCI1Gl2W1JsZsw9zA+Bh3JmjkC0H5/0JV6JotNMatJIZ4v5PqwJe3r8xd+FNS3ynccdu+xtVdc27qwVdoomciZD5oXYey9KAFSAKO594sBKZNWUJTLXnt0BJbdF8FkQYvg3DQajYY2p+ixd5Ag7o92gw0pVVDDOP+WQxiEmKqgWJyTBsnsBk2Bxi2Unsv8S/4PmE8Hy/vy+Mij+aTAKZvg716IHfHX0/JMeFfmAnsZ39Q0qkfdPtq6+CxbGZ7wKDsK/8l/MVGuyd6faJFt5wyoOXuNrr3JC9EoBmjcOzkVw/6RNP49poZ1xzsX3q7B4HGfI/XSfRQq3HeZ2j12d0E3gCAube4oExaT1sx/v8F+f61QOsGdSaqM2im6qOGkSRkrRQ7L8hvS8vEYJeVkAbFvX5ov7e/egYYNToMHj651c5/rCVYtB9Ned6GvGN8R0x3t7+lsf8+ofhHRzpyvwxd6c5pREZVOKnXzplhJ61mki4JmAAAABFWElGugAAAEV4aWYAAElJKgAIAAAABgASAQMAAQAAAAEAAAAaAQUAAQAAAFYAAAAbAQUAAQAAAF4AAAAoAQMAAQAAAAIAAAATAgMAAQAAAAEAAABphwQAAQAAAGYAAAAAAAAASAAAAAEAAABIAAAAAQAAAAYAAJAHAAQAAAAwMjEwAZEHAAQAAAABAgMAAKAHAAQAAAAwMTAwAaADAAEAAAD//wAAAqAEAAEAAAA8AAAAA6AEAAEAAAA8AAAAAAAAAA==", xt = "data:image/svg+xml,%3csvg%20width='868'%20height='868'%20viewBox='0%200%20868%20868'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='434'%20cy='434'%20r='434'%20fill='%231B262D'/%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M234.563%20184H640.697C650.387%20184%20659.339%20189.164%20664.172%20197.542L782.495%20402.657C788.631%20413.294%20786.808%20426.72%20778.056%20435.346L452.368%20756.327C441.818%20766.724%20424.846%20766.724%20414.296%20756.327L89.0484%20435.78C80.0927%20426.954%2078.4157%20413.136%2085.0013%20402.433L211.48%20196.884C216.405%20188.879%20225.146%20184%20234.563%20184ZM588.257%20275.577V333.129H472.567V373.032C553.82%20377.296%20614.782%20394.81%20615.234%20415.802L615.231%20459.563C614.779%20480.556%20553.82%20498.069%20472.567%20502.333V600.259H395.746V502.333C314.492%20498.069%20253.531%20480.555%20253.078%20459.563L253.081%20415.802C253.533%20394.81%20314.492%20377.296%20395.746%20373.032V333.129H280.055V275.577H588.257ZM434.156%20472.268C520.868%20472.268%20593.345%20457.459%20611.082%20437.683C596.041%20420.912%20541.636%20407.713%20472.567%20404.089V445.867C460.187%20446.516%20447.336%20446.858%20434.156%20446.858C420.976%20446.858%20408.125%20446.516%20395.746%20445.867V404.089C326.676%20407.713%20272.271%20420.912%20257.23%20437.683C274.968%20457.459%20347.444%20472.268%20434.156%20472.268Z'%20fill='%23009393'/%3e%3c/svg%3e", kt = "data:image/webp;base64,UklGRqwEAABXRUJQVlA4WAoAAAAYAAAAOwAAOwAAQUxQSL8BAAABkGvbtmlLc5997yvbmW19gBnbDm2kjF5UmW3bthXZVZFdZ+81r+87Z1XlEaHIbSNlMstwos4XUBSTLAFQo/u01Zdf/yLDDze3zB/YwADJEoOoJAKg7oTdH4SF+XxiZlMgSESzwAJdVn2iUJzzOUMiLhQKf+/va2FtBLMBuu1zpHcsincUXhtoTKLsCTVX/KF3wrLhPLm/OWzZtjQWfZ7RhYyAC/lxMowpSzJYJAyFkZDQc21FBMUT7BqGjpHxf3m+XlEPUHE/f3vGgPzmw4awRUaTexkyJhwfNShctVgZXyJDXq4CUyjNy6Y4fVOBIkAPR2GcOE7Jm2NQ/RE9YzXht3a5VYvlOX0xF0fy+tp/ozBuQg6DzZYb6Bi7ed4rB5Mp/1Co4cNhLUo1StLxDIDqrynUoRswiF6nFnIxsDpnZ5WBW0GFZ1qZ8HfLDk5txHHsGDpSa6B0cXZEa+DsTr1M+P4qPdXwjynU4+1/a7oN3Sm6G+meSd27oHsHde++7puj+tYpv7G6b7vun6L7l6n+oZp/t7JmUNUqqhpJV5upakJVLaqqgVW1t6rmV401NGMc1djqH4rpIseSfyPFkgAAVlA4IAQCAABQDACdASo8ADwAPm0yk0akIyGhJgzogA2JaQAThroHvLxu+aPf5G2BYxv+B6XHzx6GPon/o+qz/tOAA/TM82gR0vnExWoiQRM36jlg2UIvwCSqySErzuguz9EP2x/7hsNazr91aIworWI7AAD+/TZ+6Ipl444OdT+2wU0Ov+T8oJuVP/vUbT/w1Jsv6Awnl6rvF/xetfOPt3gTQZZi0Y/AOx563J7CJkqTR/fc/n34zyeKzR80fhfv4ef+Hjhz/CX5aQo+58zg/FdE+7bLoophGfG0szI513EH+q+Gc73H1PFdJYf7CF8v5dhr3tMwEVX5Ji2ZxejK8xrf/E6nVXqlA4DrYNRP09InHc+fEqO/fH8xr+rMf4y1F9TOnwVffZblLoTP6lot0m/sh7sTiDQr0mIA8TiHoOffGDG6KzV+B3239udfhzD740gkRi/m53abX0Ku3vAgadgFFqL0vk8M/4aI+cI+0fbLW17mWGeMu21wSRRQiv5iNgGKR3vEGXAItcLDft1uUzWAfbe1X3zK/ymT7bA/76PB6UUknm+Y5MM4osurUXU/k7P38pN/3slnGfpFzjl4c3USY4mH9ZCJYUuC/kGEnq/yRPalPdODNFvW6s8MiQeQejYNRY0LsJ0WXkK8vXiDmihCivYAOPoSovesL7on+WAArDNM/BcQSQvCYABFWElGugAAAEV4aWYAAElJKgAIAAAABgASAQMAAQAAAAEAAAAaAQUAAQAAAFYAAAAbAQUAAQAAAF4AAAAoAQMAAQAAAAIAAAATAgMAAQAAAAEAAABphwQAAQAAAGYAAAAAAAAASAAAAAEAAABIAAAAAQAAAAYAAJAHAAQAAAAwMjEwAZEHAAQAAAABAgMAAKAHAAQAAAAwMTAwAaADAAEAAAD//wAAAqAEAAEAAAA8AAAAA6AEAAEAAAA8AAAAAAAAAA==", Tt = "data:image/webp;base64,UklGRtgCAABXRUJQVlA4WAoAAAAIAAAAOwAAOwAAVlA4IPgBAABQCwCdASo8ADwAPm0wk0ekIqGhKBQMqIANiWkADPF3uV2D8VcQGk1mg+P36i9SLnZvYAQxszEWYzEwX1RVkqG/4BGbJgMSHqhKDFsjWsGfPPrvfef11goNmCDDlBJHVVD+8gAA/vu4q03kl+E7FpjtZ2gc8pQ619Hjv9NywoRZ6az43C1wcrRr/lWzJlJhLWMHN0MkVl1ueAf6Hn8StVzeUfMBXOKkgfe2msx7QWR5PnHW/5c6/35yrtWnrURc2q6UYlGin+v8C2dQqexkW6rX2EEijTI9eEQ46PWH3/59fM2AlMvvR2abaRk5XX7V1triQncRxvMfz5YmYDN+PY/ikcZUNaiFucKoUq5riv0eKCezuFNHecE11ojwJqWRSTWpalkz5autXp6vFS+FT1tWUsB/fs1CCOZxaA1vR1grOEaiuKe1RYm7e05psWtqbXLVmm1bA8Ly9PFkVdCbc6hR3UuBBsFGnVeGOUeMn2onnfvYhBMcM9YPxGdQkwZLXOk1VuQSTk01Shf3fZrFyRlFauftFdPYhKXwqrr+meav1P+KLKBVosqmHnFFfgExsQ/rOf3TSd+mOqQfJA+cF+HojNU7nmM3uDkoCBi+//Gqp+gPNNW8M4LFrol8rxE+7WsjqMgfwv1f+Nr25RtG1Wa/KkniRCAAAABFWElGugAAAEV4aWYAAElJKgAIAAAABgASAQMAAQAAAAEAAAAaAQUAAQAAAFYAAAAbAQUAAQAAAF4AAAAoAQMAAQAAAAIAAAATAgMAAQAAAAEAAABphwQAAQAAAGYAAAAAAAAASAAAAAEAAABIAAAAAQAAAAYAAJAHAAQAAAAwMjEwAZEHAAQAAAABAgMAAKAHAAQAAAAwMTAwAaADAAEAAAD//wAAAqAEAAEAAAA8AAAAA6AEAAEAAAA8AAAAAAAAAA==", Rt = {
|
|
1716
2239
|
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: {
|
|
1717
2240
|
symbol: "USDC",
|
|
1718
2241
|
decimals: 6,
|
|
1719
|
-
icon:
|
|
2242
|
+
icon: St
|
|
1720
2243
|
},
|
|
1721
2244
|
Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB: {
|
|
1722
2245
|
symbol: "USDT",
|
|
1723
2246
|
decimals: 6,
|
|
1724
|
-
icon:
|
|
2247
|
+
icon: xt
|
|
1725
2248
|
},
|
|
1726
2249
|
"2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo": {
|
|
1727
2250
|
symbol: "PYUSD",
|
|
1728
2251
|
decimals: 6,
|
|
1729
|
-
icon:
|
|
2252
|
+
icon: kt
|
|
1730
2253
|
},
|
|
1731
2254
|
CASHx9KJUStyftLFWGvEVf59SGeG9sh5FfcnZMVPCASH: {
|
|
1732
2255
|
symbol: "CASH",
|
|
1733
2256
|
decimals: 6,
|
|
1734
|
-
icon:
|
|
2257
|
+
icon: Tt
|
|
1735
2258
|
}
|
|
1736
|
-
},
|
|
1737
|
-
Object.entries(
|
|
2259
|
+
}, ae = Object.fromEntries(
|
|
2260
|
+
Object.entries(Rt).map(([t, e]) => [t, e.symbol])
|
|
1738
2261
|
);
|
|
1739
|
-
function
|
|
1740
|
-
return t in
|
|
2262
|
+
function Mt(t) {
|
|
2263
|
+
return t in ae;
|
|
1741
2264
|
}
|
|
1742
|
-
function
|
|
2265
|
+
function Fe(t, e = "token mint", r = !1) {
|
|
1743
2266
|
if (!t || t.trim().length === 0)
|
|
1744
2267
|
return {
|
|
1745
2268
|
isValid: !0,
|
|
1746
2269
|
isKnownStablecoin: !1
|
|
1747
2270
|
};
|
|
1748
2271
|
const a = t.trim();
|
|
1749
|
-
if (
|
|
2272
|
+
if (Mt(a))
|
|
1750
2273
|
return {
|
|
1751
2274
|
isValid: !0,
|
|
1752
2275
|
isKnownStablecoin: !0,
|
|
1753
|
-
symbol:
|
|
2276
|
+
symbol: ae[a]
|
|
1754
2277
|
};
|
|
1755
|
-
const n = Object.entries(
|
|
2278
|
+
const n = Object.entries(ae).map(([i, o]) => ` ${o}: ${i}`).join(`
|
|
1756
2279
|
`);
|
|
1757
2280
|
return r ? {
|
|
1758
2281
|
isValid: !0,
|
|
@@ -1801,46 +2324,47 @@ function De(t, e = "token mint", r = !1) {
|
|
|
1801
2324
|
`)
|
|
1802
2325
|
};
|
|
1803
2326
|
}
|
|
1804
|
-
function
|
|
1805
|
-
return
|
|
2327
|
+
function Qt(t, e = "unknown", r = !1) {
|
|
2328
|
+
return Fe(t, `X402Requirement (resource: ${e})`, r);
|
|
1806
2329
|
}
|
|
1807
|
-
const
|
|
1808
|
-
|
|
1809
|
-
], ue = /* @__PURE__ */ new Set(["mainnet-beta", "devnet", "testnet"]);
|
|
1810
|
-
function Ct() {
|
|
2330
|
+
const pe = /* @__PURE__ */ new Set(["mainnet-beta", "devnet", "testnet"]);
|
|
2331
|
+
function Dt() {
|
|
1811
2332
|
if (typeof window < "u" && window.location)
|
|
1812
2333
|
return window.location.origin;
|
|
1813
2334
|
throw new Error(
|
|
1814
2335
|
"serverUrl is required in SSR/Node environments. In browser environments, it defaults to window.location.origin"
|
|
1815
2336
|
);
|
|
1816
2337
|
}
|
|
1817
|
-
function
|
|
2338
|
+
function Ot(t) {
|
|
1818
2339
|
const e = [];
|
|
1819
|
-
|
|
1820
|
-
const n = t
|
|
2340
|
+
if (t.showCard !== !1) {
|
|
2341
|
+
const n = t.stripePublicKey;
|
|
1821
2342
|
(typeof n != "string" || n.trim().length === 0) && e.push({
|
|
1822
|
-
field:
|
|
1823
|
-
message: "must be a non-empty string"
|
|
2343
|
+
field: "stripePublicKey",
|
|
2344
|
+
message: "must be a non-empty string when card payments are enabled (showCard is not false)"
|
|
1824
2345
|
});
|
|
1825
|
-
}
|
|
1826
|
-
let
|
|
2346
|
+
}
|
|
2347
|
+
let a;
|
|
1827
2348
|
if (t.serverUrl !== void 0)
|
|
1828
2349
|
typeof t.serverUrl != "string" || t.serverUrl.trim().length === 0 ? (e.push({
|
|
1829
2350
|
field: "serverUrl",
|
|
1830
2351
|
message: "must be a non-empty string when provided"
|
|
1831
|
-
}),
|
|
2352
|
+
}), a = "") : (!t.serverUrl.startsWith("http://") && !t.serverUrl.startsWith("https://") && e.push({
|
|
2353
|
+
field: "serverUrl",
|
|
2354
|
+
message: 'must start with "http://" or "https://"'
|
|
2355
|
+
}), a = t.serverUrl);
|
|
1832
2356
|
else
|
|
1833
2357
|
try {
|
|
1834
|
-
|
|
1835
|
-
} catch (
|
|
2358
|
+
a = Dt();
|
|
2359
|
+
} catch (n) {
|
|
1836
2360
|
e.push({
|
|
1837
2361
|
field: "serverUrl",
|
|
1838
|
-
message:
|
|
1839
|
-
}),
|
|
2362
|
+
message: n instanceof Error ? n.message : "failed to determine default"
|
|
2363
|
+
}), a = "";
|
|
1840
2364
|
}
|
|
1841
|
-
if (
|
|
2365
|
+
if (pe.has(t.solanaCluster) || e.push({
|
|
1842
2366
|
field: "solanaCluster",
|
|
1843
|
-
message: `must be one of ${Array.from(
|
|
2367
|
+
message: `must be one of ${Array.from(pe).join(", ")}`
|
|
1844
2368
|
}), t.solanaEndpoint !== void 0 && (typeof t.solanaEndpoint != "string" ? e.push({
|
|
1845
2369
|
field: "solanaEndpoint",
|
|
1846
2370
|
message: "must be a string when provided"
|
|
@@ -1854,23 +2378,23 @@ function St(t) {
|
|
|
1854
2378
|
field: "tokenMint",
|
|
1855
2379
|
message: "must be a string when provided"
|
|
1856
2380
|
}), e.length > 0) {
|
|
1857
|
-
const
|
|
2381
|
+
const n = e.map((i) => `- ${i.field} ${i.message}`).join(`
|
|
1858
2382
|
`);
|
|
1859
2383
|
throw new Error(`Invalid Cedros configuration:
|
|
1860
|
-
${
|
|
2384
|
+
${n}`);
|
|
1861
2385
|
}
|
|
1862
2386
|
if (t.tokenMint) {
|
|
1863
|
-
const
|
|
1864
|
-
if (!
|
|
1865
|
-
throw new Error(
|
|
1866
|
-
|
|
2387
|
+
const n = t.dangerouslyAllowUnknownMint === !0, i = Fe(t.tokenMint, "CedrosConfig.tokenMint", n);
|
|
2388
|
+
if (!i.isValid && i.error)
|
|
2389
|
+
throw new Error(i.error);
|
|
2390
|
+
i.warning && c().warn(i.warning);
|
|
1867
2391
|
}
|
|
1868
2392
|
return {
|
|
1869
2393
|
...t,
|
|
1870
|
-
serverUrl:
|
|
2394
|
+
serverUrl: a
|
|
1871
2395
|
};
|
|
1872
2396
|
}
|
|
1873
|
-
const
|
|
2397
|
+
const Bt = Object.freeze({
|
|
1874
2398
|
surfaceBackground: "rgba(255, 255, 255, 0)",
|
|
1875
2399
|
surfaceText: "#111827",
|
|
1876
2400
|
surfaceBorder: "rgba(15, 23, 42, 0.08)",
|
|
@@ -1893,7 +2417,7 @@ const xt = Object.freeze({
|
|
|
1893
2417
|
buttonPadding: "0.75rem 1.5rem",
|
|
1894
2418
|
buttonFontSize: "1rem",
|
|
1895
2419
|
buttonFontWeight: "600"
|
|
1896
|
-
}),
|
|
2420
|
+
}), _t = Object.freeze({
|
|
1897
2421
|
surfaceBackground: "rgba(17, 24, 39, 0.6)",
|
|
1898
2422
|
surfaceText: "#f9fafb",
|
|
1899
2423
|
surfaceBorder: "rgba(148, 163, 184, 0.25)",
|
|
@@ -1916,7 +2440,7 @@ const xt = Object.freeze({
|
|
|
1916
2440
|
buttonPadding: "0.75rem 1.5rem",
|
|
1917
2441
|
buttonFontSize: "1rem",
|
|
1918
2442
|
buttonFontWeight: "600"
|
|
1919
|
-
}),
|
|
2443
|
+
}), It = {
|
|
1920
2444
|
surfaceBackground: "--cedros-surface-bg",
|
|
1921
2445
|
surfaceText: "--cedros-surface-text",
|
|
1922
2446
|
surfaceBorder: "--cedros-surface-border",
|
|
@@ -1939,109 +2463,119 @@ const xt = Object.freeze({
|
|
|
1939
2463
|
buttonPadding: "--cedros-button-padding",
|
|
1940
2464
|
buttonFontSize: "--cedros-button-font-size",
|
|
1941
2465
|
buttonFontWeight: "--cedros-button-font-weight"
|
|
1942
|
-
},
|
|
1943
|
-
function
|
|
2466
|
+
}, se = Ae(null);
|
|
2467
|
+
function Nt(t, e) {
|
|
1944
2468
|
return {
|
|
1945
|
-
...t === "dark" ?
|
|
2469
|
+
...t === "dark" ? _t : Bt,
|
|
1946
2470
|
...e
|
|
1947
2471
|
};
|
|
1948
2472
|
}
|
|
1949
|
-
function
|
|
2473
|
+
function Ut(t) {
|
|
1950
2474
|
const e = Object.entries(t).map(([r, a]) => [
|
|
1951
|
-
|
|
2475
|
+
It[r],
|
|
1952
2476
|
a
|
|
1953
2477
|
]);
|
|
1954
2478
|
return Object.fromEntries(e);
|
|
1955
2479
|
}
|
|
1956
|
-
function
|
|
2480
|
+
function Ft({
|
|
1957
2481
|
initialMode: t = "light",
|
|
1958
2482
|
overrides: e,
|
|
1959
2483
|
unstyled: r = !1,
|
|
1960
2484
|
children: a
|
|
1961
2485
|
}) {
|
|
1962
|
-
const [n, i] =
|
|
1963
|
-
|
|
2486
|
+
const [n, i] = N(t), [o, s] = N(e), l = ge(e);
|
|
2487
|
+
I(() => {
|
|
1964
2488
|
if (e === l.current)
|
|
1965
2489
|
return;
|
|
1966
2490
|
(!e || !l.current ? e !== l.current : Object.keys({ ...e, ...l.current }).some(
|
|
1967
2491
|
(u) => e[u] !== l.current?.[u]
|
|
1968
2492
|
)) && (l.current = e, s(e));
|
|
1969
2493
|
}, [e]);
|
|
1970
|
-
const
|
|
1971
|
-
const
|
|
2494
|
+
const d = ee(() => {
|
|
2495
|
+
const m = Nt(n, o), u = r ? {} : Ut(m), y = r ? "" : `cedros-theme-root cedros-theme cedros-theme--${n}`;
|
|
1972
2496
|
return {
|
|
1973
2497
|
mode: n,
|
|
1974
2498
|
setMode: i,
|
|
1975
|
-
tokens:
|
|
1976
|
-
className:
|
|
2499
|
+
tokens: m,
|
|
2500
|
+
className: y,
|
|
1977
2501
|
style: u,
|
|
1978
2502
|
unstyled: r
|
|
1979
2503
|
};
|
|
1980
2504
|
}, [n, o, r]);
|
|
1981
|
-
return /* @__PURE__ */
|
|
2505
|
+
return /* @__PURE__ */ W(se.Provider, { value: d, children: a });
|
|
1982
2506
|
}
|
|
1983
|
-
function
|
|
1984
|
-
const t =
|
|
2507
|
+
function Kt() {
|
|
2508
|
+
const t = ne(se);
|
|
1985
2509
|
if (!t)
|
|
1986
2510
|
throw new Error("useCedrosTheme must be used within CedrosProvider");
|
|
1987
2511
|
return t;
|
|
1988
2512
|
}
|
|
1989
|
-
function
|
|
1990
|
-
return
|
|
2513
|
+
function Wt() {
|
|
2514
|
+
return ne(se);
|
|
1991
2515
|
}
|
|
1992
|
-
const
|
|
2516
|
+
const $ = {
|
|
1993
2517
|
getAdapters: () => [],
|
|
1994
2518
|
cleanup: async () => {
|
|
1995
2519
|
},
|
|
1996
2520
|
isInitialized: () => !1,
|
|
1997
2521
|
getId: () => "stub"
|
|
1998
2522
|
};
|
|
1999
|
-
function
|
|
2523
|
+
function Ht() {
|
|
2000
2524
|
return typeof process < "u" && process.env.NODE_ENV === "development" ? 0 : 2;
|
|
2001
2525
|
}
|
|
2002
|
-
const
|
|
2003
|
-
function
|
|
2004
|
-
const r =
|
|
2005
|
-
|
|
2006
|
-
let
|
|
2007
|
-
return import("./walletPool-
|
|
2008
|
-
if (
|
|
2009
|
-
const
|
|
2010
|
-
|
|
2526
|
+
const He = Ae(null);
|
|
2527
|
+
function Vt({ config: t, children: e }) {
|
|
2528
|
+
const r = ee(() => Ot(t), [t]), [a, n] = N(null), [i, o] = N($), s = ge($);
|
|
2529
|
+
I(() => {
|
|
2530
|
+
let f = !1;
|
|
2531
|
+
return import("./walletPool-BV_z1lEA.mjs").then(({ createWalletPool: h }) => {
|
|
2532
|
+
if (f) return;
|
|
2533
|
+
const w = h();
|
|
2534
|
+
s.current = w, o(w);
|
|
2535
|
+
}).catch((h) => {
|
|
2536
|
+
f || (c().error("[CedrosProvider] Wallet pool initialization failed:", h), n("Failed to initialize Cedros provider"));
|
|
2011
2537
|
}), () => {
|
|
2012
|
-
|
|
2538
|
+
f = !0;
|
|
2013
2539
|
};
|
|
2014
2540
|
}, []);
|
|
2015
|
-
const [
|
|
2016
|
-
|
|
2017
|
-
let
|
|
2541
|
+
const [l, d] = N(null);
|
|
2542
|
+
I(() => {
|
|
2543
|
+
let f = !1;
|
|
2018
2544
|
return import("./solanaCheck-IlYsbXDd.mjs").then(
|
|
2019
|
-
({ checkSolanaAvailability:
|
|
2020
|
-
).then((
|
|
2021
|
-
|
|
2545
|
+
({ checkSolanaAvailability: h }) => h()
|
|
2546
|
+
).then((h) => {
|
|
2547
|
+
f || (h.available ? d(void 0) : d(h.error || "Solana dependencies not available"));
|
|
2548
|
+
}).catch((h) => {
|
|
2549
|
+
f || (c().warn("[CedrosProvider] Solana availability check failed:", h), d("Unable to verify Solana availability"));
|
|
2022
2550
|
}), () => {
|
|
2023
|
-
|
|
2551
|
+
f = !0;
|
|
2024
2552
|
};
|
|
2025
|
-
}, []),
|
|
2026
|
-
const
|
|
2027
|
-
level:
|
|
2553
|
+
}, []), I(() => {
|
|
2554
|
+
const f = r.logLevel ?? Ht(), h = Xe({
|
|
2555
|
+
level: f,
|
|
2028
2556
|
prefix: "[CedrosPay]"
|
|
2029
2557
|
});
|
|
2030
|
-
|
|
2031
|
-
}, [r.logLevel]),
|
|
2032
|
-
const
|
|
2033
|
-
|
|
2034
|
-
c().warn("[CedrosProvider] Wallet pool cleanup failed:",
|
|
2558
|
+
Ye(h);
|
|
2559
|
+
}, [r.logLevel]), I(() => () => {
|
|
2560
|
+
const f = s.current;
|
|
2561
|
+
f && f !== $ && f.cleanup().catch((h) => {
|
|
2562
|
+
c().warn("[CedrosProvider] Wallet pool cleanup failed:", h);
|
|
2035
2563
|
});
|
|
2036
2564
|
}, []);
|
|
2037
|
-
const [
|
|
2038
|
-
|
|
2039
|
-
let
|
|
2040
|
-
const
|
|
2041
|
-
return
|
|
2042
|
-
|
|
2565
|
+
const [m, u] = N(null);
|
|
2566
|
+
I(() => {
|
|
2567
|
+
let f = !1, h = !1;
|
|
2568
|
+
const w = r.stripePublicKey ?? "", C = r.serverUrl ?? "", x = r.solanaCluster, B = r.solanaEndpoint, k = r.dangerouslyAllowUnknownMint;
|
|
2569
|
+
return Pt(w, C, x, B, k).then((D) => {
|
|
2570
|
+
if (f) {
|
|
2571
|
+
ye(w, C, x, B, k);
|
|
2572
|
+
return;
|
|
2573
|
+
}
|
|
2574
|
+
h = !0, u(D);
|
|
2575
|
+
}).catch((D) => {
|
|
2576
|
+
f || (c().error("[CedrosProvider] Manager initialization failed:", D), n("Failed to initialize Cedros provider"));
|
|
2043
2577
|
}), () => {
|
|
2044
|
-
|
|
2578
|
+
f = !0, h && ye(w, C, x, B, k);
|
|
2045
2579
|
};
|
|
2046
2580
|
}, [
|
|
2047
2581
|
r.stripePublicKey,
|
|
@@ -2050,51 +2584,54 @@ function jt({ config: t, children: e }) {
|
|
|
2050
2584
|
r.solanaEndpoint,
|
|
2051
2585
|
r.dangerouslyAllowUnknownMint
|
|
2052
2586
|
]);
|
|
2053
|
-
const
|
|
2587
|
+
const y = ee(() => m ? {
|
|
2054
2588
|
config: r,
|
|
2055
|
-
...
|
|
2056
|
-
walletPool:
|
|
2057
|
-
solanaError:
|
|
2058
|
-
} : null, [r,
|
|
2059
|
-
return
|
|
2060
|
-
|
|
2589
|
+
...m,
|
|
2590
|
+
walletPool: i,
|
|
2591
|
+
solanaError: l
|
|
2592
|
+
} : null, [r, m, i, l]);
|
|
2593
|
+
return a ? /* @__PURE__ */ W("div", { role: "alert", children: a }) : /* @__PURE__ */ W(
|
|
2594
|
+
Ft,
|
|
2061
2595
|
{
|
|
2062
2596
|
initialMode: r.theme ?? "light",
|
|
2063
2597
|
overrides: r.themeOverrides,
|
|
2064
2598
|
unstyled: r.unstyled ?? !1,
|
|
2065
|
-
children: e
|
|
2599
|
+
children: y ? /* @__PURE__ */ W(He.Provider, { value: y, children: e }) : null
|
|
2066
2600
|
}
|
|
2067
|
-
)
|
|
2601
|
+
);
|
|
2068
2602
|
}
|
|
2069
|
-
function
|
|
2070
|
-
const t =
|
|
2603
|
+
function Gt() {
|
|
2604
|
+
const t = ne(He);
|
|
2071
2605
|
if (!t)
|
|
2072
2606
|
throw new Error("useCedrosContext must be used within CedrosProvider");
|
|
2073
2607
|
return t;
|
|
2074
2608
|
}
|
|
2075
2609
|
export {
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2610
|
+
Vt as C,
|
|
2611
|
+
at as E,
|
|
2612
|
+
ae as K,
|
|
2613
|
+
Ge as L,
|
|
2614
|
+
O as P,
|
|
2615
|
+
M as R,
|
|
2616
|
+
Rt as S,
|
|
2617
|
+
Kt as a,
|
|
2618
|
+
j as b,
|
|
2619
|
+
R as c,
|
|
2620
|
+
et as d,
|
|
2621
|
+
A as e,
|
|
2622
|
+
zt as f,
|
|
2623
|
+
E as g,
|
|
2624
|
+
Ee as h,
|
|
2089
2625
|
c as i,
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2626
|
+
Xe as j,
|
|
2627
|
+
Qt as k,
|
|
2628
|
+
me as l,
|
|
2629
|
+
T as m,
|
|
2630
|
+
Fe as n,
|
|
2631
|
+
rt as o,
|
|
2632
|
+
p,
|
|
2633
|
+
Wt as q,
|
|
2634
|
+
b as r,
|
|
2635
|
+
Gt as u,
|
|
2636
|
+
Ot as v
|
|
2100
2637
|
};
|