@cedros/pay-react 1.1.25 → 1.1.26

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.
Files changed (94) hide show
  1. package/dist/{AISettingsSection-Dg1kazTI.mjs → AISettingsSection-BlIv3CzS.mjs} +2 -2
  2. package/dist/{AISettingsSection-BvSSiK2G.js → AISettingsSection-DELur7D2.js} +1 -1
  3. package/dist/{AutosaveIndicator-BHfkV59p.mjs → AutosaveIndicator-Bed0-ekg.mjs} +1 -1
  4. package/dist/{AutosaveIndicator-D2l7U8R1.js → AutosaveIndicator-Dn_qA2hK.js} +1 -1
  5. package/dist/ChatLogsSection-BH5tLA4T.js +1 -0
  6. package/dist/ChatLogsSection-v4zwzCTC.mjs +201 -0
  7. package/dist/{ComplianceSection-BSE2f3Wo.mjs → ComplianceSection-CemgfDrL.mjs} +282 -166
  8. package/dist/ComplianceSection-DP2a9-S0.js +1 -0
  9. package/dist/CustomersSection-CBwy_waO.js +1 -0
  10. package/dist/CustomersSection-D_j7OrfS.mjs +207 -0
  11. package/dist/DisputesSection-BLjIk60n.js +1 -0
  12. package/dist/DisputesSection-BcAbXp3K.mjs +230 -0
  13. package/dist/{FAQSection-uZG5V3pJ.mjs → FAQSection-Dn38OhB_.mjs} +1 -1
  14. package/dist/{FAQSection-6nGI0FK9.js → FAQSection-wNeH0i6Q.js} +1 -1
  15. package/dist/ImagesSection-0ZzKlzMJ.js +1 -0
  16. package/dist/ImagesSection-Ctw9Icym.mjs +216 -0
  17. package/dist/InventorySection-DmhjUlRZ.mjs +150 -0
  18. package/dist/InventorySection-zV6lTmue.js +1 -0
  19. package/dist/{MessagingSection-M0lj5yo4.mjs → MessagingSection-B1FaGxkp.mjs} +2 -2
  20. package/dist/{MessagingSection-DrXb578q.js → MessagingSection-B_wdFR0j.js} +1 -1
  21. package/dist/{OrdersSection-DteItv_O.mjs → OrdersSection-Bj8bPdg8.mjs} +1 -1
  22. package/dist/{OrdersSection-_-rIw6XW.js → OrdersSection-Dw2FX-1d.js} +1 -1
  23. package/dist/{PaymentSettingsSection-enTbUI95.js → PaymentSettingsSection-BYF4D-GR.js} +1 -1
  24. package/dist/{PaymentSettingsSection-CdtdLFTg.mjs → PaymentSettingsSection-EnMxeWjv.mjs} +1 -1
  25. package/dist/ReturnsSection-BC0L8r2e.mjs +267 -0
  26. package/dist/ReturnsSection-D_pJVxuG.js +1 -0
  27. package/dist/{SettingsSection-mcT4LEhO.mjs → SettingsSection-KYdEizq_.mjs} +1 -1
  28. package/dist/{SettingsSection-DUTEd6uV.js → SettingsSection-vdYFSNxB.js} +1 -1
  29. package/dist/ShippingSection-1DRSTu49.js +1 -0
  30. package/dist/ShippingSection-BOgto6_9.mjs +434 -0
  31. package/dist/{SingleCategorySettings-D2LVM5mn.js → SingleCategorySettings-DwCnBdRf.js} +1 -1
  32. package/dist/{SingleCategorySettings-BvHBVfSe.mjs → SingleCategorySettings-suJ8z9d8.mjs} +2 -2
  33. package/dist/{StorefrontSection-BqQ36JIS.mjs → StorefrontSection-BRvIGBEJ.mjs} +2 -2
  34. package/dist/{StorefrontSection-Du7hV2Gc.js → StorefrontSection-RumGkb3C.js} +1 -1
  35. package/dist/{SubscriptionsSection-C4BRN1dP.js → SubscriptionsSection-C2aLLn7L.js} +1 -1
  36. package/dist/{SubscriptionsSection-BYiCBwKZ.mjs → SubscriptionsSection-D60qrX9a.mjs} +1 -1
  37. package/dist/TaxSection-C7-pv-Rl.mjs +294 -0
  38. package/dist/TaxSection-Dt1DnM51.js +1 -0
  39. package/dist/{Token22Section-BHvOhz5d.mjs → Token22Section-CrHLQ0EB.mjs} +1 -1
  40. package/dist/{Token22Section-0c22NM5G.js → Token22Section-DY3mUwTY.js} +1 -1
  41. package/dist/WebhooksSection-CKeiJ7Py.js +1 -0
  42. package/dist/WebhooksSection-COPW4Ec0.mjs +223 -0
  43. package/dist/crypto-only.js +1 -1
  44. package/dist/crypto-only.mjs +1 -1
  45. package/dist/index-C0g-JxJk.js +84 -0
  46. package/dist/{index-BkDimQDF.mjs → index-DXnuQp5x.mjs} +7068 -6768
  47. package/dist/index.js +1 -1
  48. package/dist/index.mjs +1 -1
  49. package/dist/{sections-By4H1baL.mjs → sections-C1NpK7hk.mjs} +2 -2
  50. package/dist/{sections-5jO2aHAo.js → sections-DVVSZBhW.js} +1 -1
  51. package/dist/src/components/ComplianceGatePage.d.ts +3 -1
  52. package/dist/src/components/ComplianceGatePage.d.ts.map +1 -1
  53. package/dist/src/components/admin/CedrosPayAdminDashboard.d.ts +1 -1
  54. package/dist/src/components/admin/CedrosPayAdminDashboard.d.ts.map +1 -1
  55. package/dist/src/components/admin/ChatLogsSection.d.ts +3 -0
  56. package/dist/src/components/admin/ChatLogsSection.d.ts.map +1 -0
  57. package/dist/src/components/admin/ComplianceKycTab.d.ts +3 -0
  58. package/dist/src/components/admin/ComplianceKycTab.d.ts.map +1 -0
  59. package/dist/src/components/admin/ComplianceRequirementsEditor.d.ts +8 -0
  60. package/dist/src/components/admin/ComplianceRequirementsEditor.d.ts.map +1 -0
  61. package/dist/src/components/admin/ComplianceSection.d.ts.map +1 -1
  62. package/dist/src/components/admin/CustomersSection.d.ts +3 -0
  63. package/dist/src/components/admin/CustomersSection.d.ts.map +1 -0
  64. package/dist/src/components/admin/DisputesSection.d.ts +3 -0
  65. package/dist/src/components/admin/DisputesSection.d.ts.map +1 -0
  66. package/dist/src/components/admin/ImagesSection.d.ts +3 -0
  67. package/dist/src/components/admin/ImagesSection.d.ts.map +1 -0
  68. package/dist/src/components/admin/InventorySection.d.ts +3 -0
  69. package/dist/src/components/admin/InventorySection.d.ts.map +1 -0
  70. package/dist/src/components/admin/NftMetadataPreview.d.ts +20 -0
  71. package/dist/src/components/admin/NftMetadataPreview.d.ts.map +1 -0
  72. package/dist/src/components/admin/ProductsSection.d.ts.map +1 -1
  73. package/dist/src/components/admin/ReturnsSection.d.ts +3 -0
  74. package/dist/src/components/admin/ReturnsSection.d.ts.map +1 -0
  75. package/dist/src/components/admin/ShippingSection.d.ts +3 -0
  76. package/dist/src/components/admin/ShippingSection.d.ts.map +1 -0
  77. package/dist/src/components/admin/TaxSection.d.ts +3 -0
  78. package/dist/src/components/admin/TaxSection.d.ts.map +1 -0
  79. package/dist/src/components/admin/WebhooksSection.d.ts +3 -0
  80. package/dist/src/components/admin/WebhooksSection.d.ts.map +1 -0
  81. package/dist/src/components/admin/complianceTypes.d.ts +15 -1
  82. package/dist/src/components/admin/complianceTypes.d.ts.map +1 -1
  83. package/dist/src/ecommerce/adapters/CommerceAdapter.d.ts +36 -0
  84. package/dist/src/ecommerce/adapters/CommerceAdapter.d.ts.map +1 -1
  85. package/dist/src/ecommerce/adapters/paywall/paywallAdapter.d.ts.map +1 -1
  86. package/dist/src/ecommerce/components/chat/ShopChatPanel.d.ts +8 -5
  87. package/dist/src/ecommerce/components/chat/ShopChatPanel.d.ts.map +1 -1
  88. package/dist/src/ecommerce/index.d.ts +2 -2
  89. package/dist/src/ecommerce/index.d.ts.map +1 -1
  90. package/dist/src/hooks/useComplianceCheck.d.ts +1 -1
  91. package/dist/src/hooks/useComplianceCheck.d.ts.map +1 -1
  92. package/package.json +1 -1
  93. package/dist/ComplianceSection-D6ETKG6b.js +0 -1
  94. package/dist/index-C7MWL6O8.js +0 -84
@@ -0,0 +1,223 @@
1
+ import { jsxs as n, jsx as t, Fragment as q } from "react/jsx-runtime";
2
+ import { useState as r, useCallback as _, useEffect as G } from "react";
3
+ import { E as W, I as C, k as N } from "./index-DXnuQp5x.mjs";
4
+ const H = (o) => o === "success" ? "success" : o === "failed" ? "failed" : o === "pending" || o === "processing" ? "pending" : "muted", y = (o, s = 48) => o.length > s ? `${o.slice(0, s)}…` : o;
5
+ function Z({ serverUrl: o, apiKey: s, authManager: p }) {
6
+ const [a, w] = r("active"), [g, k] = r([]), [h, A] = r(0), [m, F] = r("all"), [T, v] = r(!0), [x, D] = r([]), [E, $] = r(0), [z, S] = r(!1), [I, R] = r(!1), [Q, c] = r(null), [B, d] = r(null), i = _(async (e, l) => {
7
+ if (p?.isAuthenticated())
8
+ return p.fetchWithAuth(e, l);
9
+ const L = { "Content-Type": "application/json" };
10
+ s && (L["X-API-Key"] = s);
11
+ const b = await fetch(`${o}${e}`, { ...l, headers: { ...L, ...l?.headers } });
12
+ if (!b.ok) throw new Error(`Request failed: ${b.status}`);
13
+ if (b.status !== 204)
14
+ return b.json();
15
+ }, [o, s, p]), u = _(async () => {
16
+ v(!0), c(null);
17
+ try {
18
+ const e = new URLSearchParams({ limit: "100" });
19
+ m !== "all" && e.set("status", m);
20
+ const l = await i(
21
+ `/admin/webhooks?${e.toString()}`
22
+ );
23
+ k(l.webhooks ?? []), A(l.count ?? 0);
24
+ } catch {
25
+ c("Failed to load webhooks"), k([]);
26
+ } finally {
27
+ v(!1);
28
+ }
29
+ }, [i, m]);
30
+ G(() => {
31
+ u();
32
+ }, [u]);
33
+ const f = _(async () => {
34
+ S(!0), c(null);
35
+ try {
36
+ const e = await i(
37
+ "/admin/webhooks/dlq?limit=100"
38
+ );
39
+ D(e.webhooks ?? []), $(e.count ?? 0), R(!0);
40
+ } catch {
41
+ c("Failed to load DLQ webhooks"), D([]);
42
+ } finally {
43
+ S(!1);
44
+ }
45
+ }, [i]), P = (e) => {
46
+ w(e), c(null), d(null), e === "dlq" && !I && f();
47
+ }, U = async (e) => {
48
+ d(null);
49
+ try {
50
+ await i(`/admin/webhooks/${encodeURIComponent(e)}/retry`, { method: "POST" }), u();
51
+ } catch {
52
+ d("Failed to retry webhook");
53
+ }
54
+ }, j = async (e) => {
55
+ if (window.confirm("Delete this webhook?")) {
56
+ d(null);
57
+ try {
58
+ await i(`/admin/webhooks/${encodeURIComponent(e)}`, { method: "DELETE" }), u();
59
+ } catch {
60
+ d("Failed to delete webhook");
61
+ }
62
+ }
63
+ }, O = async (e) => {
64
+ d(null);
65
+ try {
66
+ await i(`/admin/webhooks/dlq/${encodeURIComponent(e)}/retry`, { method: "POST" }), f();
67
+ } catch {
68
+ d("Failed to retry DLQ webhook");
69
+ }
70
+ }, X = async (e) => {
71
+ if (window.confirm("Delete this DLQ entry?")) {
72
+ d(null);
73
+ try {
74
+ await i(`/admin/webhooks/dlq/${encodeURIComponent(e)}`, { method: "DELETE" }), f();
75
+ } catch {
76
+ d("Failed to delete DLQ entry");
77
+ }
78
+ }
79
+ };
80
+ return /* @__PURE__ */ n("div", { children: [
81
+ /* @__PURE__ */ t("div", { className: "cedros-admin__section-header", children: /* @__PURE__ */ t("h3", { className: "cedros-admin__section-title", children: "Webhooks" }) }),
82
+ /* @__PURE__ */ t(W, { message: Q }),
83
+ /* @__PURE__ */ t(W, { message: B }),
84
+ /* @__PURE__ */ t("div", { style: { display: "flex", gap: "0.25rem", marginBottom: "1rem", borderBottom: "1px solid var(--cedros-admin-border, #e0e0e0)" }, children: ["active", "dlq"].map((e) => /* @__PURE__ */ t(
85
+ "button",
86
+ {
87
+ type: "button",
88
+ onClick: () => P(e),
89
+ style: {
90
+ padding: "0.5rem 1rem",
91
+ fontSize: "0.85rem",
92
+ fontWeight: a === e ? 600 : 400,
93
+ background: "none",
94
+ border: "none",
95
+ borderBottom: a === e ? "2px solid var(--cedros-admin-primary, #000)" : "2px solid transparent",
96
+ cursor: "pointer",
97
+ color: a === e ? "var(--cedros-admin-text, #333)" : "var(--cedros-admin-text-muted, #888)",
98
+ marginBottom: "-1px"
99
+ },
100
+ children: e === "active" ? `Active Webhooks${h > 0 ? ` (${h})` : ""}` : `Dead Letter Queue${E > 0 ? ` (${E})` : ""}`
101
+ },
102
+ e
103
+ )) }),
104
+ a === "active" && /* @__PURE__ */ n(q, { children: [
105
+ /* @__PURE__ */ n("div", { style: { display: "flex", gap: "0.5rem", marginBottom: "1rem", alignItems: "center" }, children: [
106
+ /* @__PURE__ */ n(
107
+ "select",
108
+ {
109
+ className: "cedros-admin__input",
110
+ value: m,
111
+ onChange: (e) => {
112
+ F(e.target.value);
113
+ },
114
+ style: { width: "auto", fontSize: "0.85rem" },
115
+ children: [
116
+ /* @__PURE__ */ t("option", { value: "all", children: "All statuses" }),
117
+ /* @__PURE__ */ t("option", { value: "pending", children: "Pending" }),
118
+ /* @__PURE__ */ t("option", { value: "processing", children: "Processing" }),
119
+ /* @__PURE__ */ t("option", { value: "failed", children: "Failed" }),
120
+ /* @__PURE__ */ t("option", { value: "success", children: "Success" })
121
+ ]
122
+ }
123
+ ),
124
+ /* @__PURE__ */ n("span", { style: { fontSize: "0.85rem", color: "var(--cedros-admin-text-muted, #888)" }, children: [
125
+ h,
126
+ " webhook",
127
+ h !== 1 ? "s" : ""
128
+ ] })
129
+ ] }),
130
+ T ? /* @__PURE__ */ n("div", { className: "cedros-admin__loading", children: [
131
+ C.loading,
132
+ " Loading webhooks..."
133
+ ] }) : g.length === 0 ? /* @__PURE__ */ t("div", { className: "cedros-admin__empty", children: "No webhooks found." }) : /* @__PURE__ */ t("div", { className: "cedros-admin__table-container", children: /* @__PURE__ */ n("table", { className: "cedros-admin__table", children: [
134
+ /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ n("tr", { children: [
135
+ /* @__PURE__ */ t("th", { children: "URL" }),
136
+ /* @__PURE__ */ t("th", { children: "Event Type" }),
137
+ /* @__PURE__ */ t("th", { children: "Status" }),
138
+ /* @__PURE__ */ t("th", { children: "Attempts" }),
139
+ /* @__PURE__ */ t("th", { children: "Last Error" }),
140
+ /* @__PURE__ */ t("th", { children: "Created" }),
141
+ /* @__PURE__ */ t("th", {})
142
+ ] }) }),
143
+ /* @__PURE__ */ t("tbody", { children: g.map((e) => /* @__PURE__ */ n("tr", { children: [
144
+ /* @__PURE__ */ t("td", { style: { maxWidth: "200px" }, children: /* @__PURE__ */ t("span", { title: e.url, style: { fontSize: "0.8rem", fontFamily: "monospace" }, children: y(e.url, 40) }) }),
145
+ /* @__PURE__ */ t("td", { style: { fontSize: "0.85rem" }, children: e.eventType }),
146
+ /* @__PURE__ */ t("td", { children: /* @__PURE__ */ t("span", { className: `cedros-admin__badge cedros-admin__badge--${H(e.status)}`, children: e.status }) }),
147
+ /* @__PURE__ */ n("td", { style: { fontSize: "0.85rem" }, children: [
148
+ e.attempts,
149
+ "/",
150
+ e.maxAttempts
151
+ ] }),
152
+ /* @__PURE__ */ t("td", { style: { fontSize: "0.8rem", maxWidth: "180px", color: "var(--cedros-admin-text-muted, #888)" }, children: e.lastError ? /* @__PURE__ */ t("span", { title: e.lastError, children: y(e.lastError, 40) }) : "—" }),
153
+ /* @__PURE__ */ t("td", { style: { fontSize: "0.8rem" }, children: N(e.createdAt) }),
154
+ /* @__PURE__ */ t("td", { children: /* @__PURE__ */ n("div", { style: { display: "flex", gap: "0.25rem" }, children: [
155
+ /* @__PURE__ */ t(
156
+ "button",
157
+ {
158
+ type: "button",
159
+ className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
160
+ onClick: () => U(e.id),
161
+ children: "Retry"
162
+ }
163
+ ),
164
+ /* @__PURE__ */ t(
165
+ "button",
166
+ {
167
+ type: "button",
168
+ className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
169
+ onClick: () => j(e.id),
170
+ style: { color: "var(--cedros-admin-danger, #c00)" },
171
+ children: "Delete"
172
+ }
173
+ )
174
+ ] }) })
175
+ ] }, e.id)) })
176
+ ] }) })
177
+ ] }),
178
+ a === "dlq" && /* @__PURE__ */ t(q, { children: z ? /* @__PURE__ */ n("div", { className: "cedros-admin__loading", children: [
179
+ C.loading,
180
+ " Loading DLQ..."
181
+ ] }) : x.length === 0 ? /* @__PURE__ */ t("div", { className: "cedros-admin__empty", children: "Dead Letter Queue is empty." }) : /* @__PURE__ */ t("div", { className: "cedros-admin__table-container", children: /* @__PURE__ */ n("table", { className: "cedros-admin__table", children: [
182
+ /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ n("tr", { children: [
183
+ /* @__PURE__ */ t("th", { children: "URL" }),
184
+ /* @__PURE__ */ t("th", { children: "Event Type" }),
185
+ /* @__PURE__ */ t("th", { children: "Attempts" }),
186
+ /* @__PURE__ */ t("th", { children: "Final Error" }),
187
+ /* @__PURE__ */ t("th", { children: "Moved to DLQ" }),
188
+ /* @__PURE__ */ t("th", {})
189
+ ] }) }),
190
+ /* @__PURE__ */ t("tbody", { children: x.map((e) => /* @__PURE__ */ n("tr", { children: [
191
+ /* @__PURE__ */ t("td", { style: { maxWidth: "200px" }, children: /* @__PURE__ */ t("span", { title: e.url, style: { fontSize: "0.8rem", fontFamily: "monospace" }, children: y(e.url, 40) }) }),
192
+ /* @__PURE__ */ t("td", { style: { fontSize: "0.85rem" }, children: e.eventType }),
193
+ /* @__PURE__ */ t("td", { style: { fontSize: "0.85rem" }, children: e.totalAttempts }),
194
+ /* @__PURE__ */ t("td", { style: { fontSize: "0.8rem", maxWidth: "200px", color: "var(--cedros-admin-text-muted, #888)" }, children: /* @__PURE__ */ t("span", { title: e.finalError, children: y(e.finalError, 40) }) }),
195
+ /* @__PURE__ */ t("td", { style: { fontSize: "0.8rem" }, children: N(e.movedToDlqAt) }),
196
+ /* @__PURE__ */ t("td", { children: /* @__PURE__ */ n("div", { style: { display: "flex", gap: "0.25rem" }, children: [
197
+ /* @__PURE__ */ t(
198
+ "button",
199
+ {
200
+ type: "button",
201
+ className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
202
+ onClick: () => O(e.id),
203
+ children: "Retry"
204
+ }
205
+ ),
206
+ /* @__PURE__ */ t(
207
+ "button",
208
+ {
209
+ type: "button",
210
+ className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
211
+ onClick: () => X(e.id),
212
+ style: { color: "var(--cedros-admin-danger, #c00)" },
213
+ children: "Delete"
214
+ }
215
+ )
216
+ ] }) })
217
+ ] }, e.id)) })
218
+ ] }) }) })
219
+ ] });
220
+ }
221
+ export {
222
+ Z as WebhooksSection
223
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./styles-BT4bhFey.js"),T=require("./index-C7MWL6O8.js"),t=require("./CedrosContext-C2RjHLaQ.js"),ce=require("./CryptoButton-DpiCnyXE.js"),C=require("react/jsx-runtime"),a=require("react"),Y=require("@solana/wallet-adapter-react"),ie=require("@solana/wallet-adapter-base"),Ee=require("@solana/wallet-adapter-react-ui"),le=require("./walletPool-IS7R3MR1.js");function ue(){const{subscriptionManager:o,x402Manager:d,walletManager:f}=t.useCedrosContext(),{publicKey:u,signTransaction:k}=Y.useWallet(),[E,y]=a.useState({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),[B,R]=a.useState(null),x=a.useRef(!1),w=a.useCallback(()=>{if(!u){const c="Wallet not connected";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}if(!k){const c="Wallet does not support signing";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}return{valid:!0}},[u,k]),_=a.useCallback(async c=>{if(!u)return y(n=>({...n,status:"error",error:"Wallet not connected"})),null;y(n=>({...n,status:"checking",error:null}));try{const n=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});return y(s=>({...s,status:n.active?"success":"idle",subscriptionStatus:n.status,expiresAt:n.expiresAt||n.currentPeriodEnd||null})),n}catch(n){const s=t.formatError(n,"Failed to check subscription status");return y(g=>({...g,status:"error",error:s})),null}},[u,o]),W=a.useCallback(async(c,n,s)=>{y(g=>({...g,status:"loading",error:null}));try{const g=await o.requestSubscriptionQuote(c,n,s);return R(g),y(i=>({...i,status:"idle"})),g}catch(g){const i=t.formatError(g,"Failed to get subscription quote");return y(l=>({...l,status:"error",error:i})),null}},[o]),S=a.useCallback(async(c,n,s)=>{if(x.current)return{success:!1,error:"Payment already in progress"};const g=w();if(!g.valid)return{success:!1,error:g.error};x.current=!0,y(i=>({...i,status:"loading",error:null}));try{const i=await o.requestSubscriptionQuote(c,n,s);R(i);const l=i.requirement;if(!d.validateRequirement(l))throw new Error("Invalid subscription quote received from server");const P=!!l.extra?.feePayer;let b;if(P){const{transaction:h,blockhash:M}=await d.buildGaslessTransaction({resourceId:c,userWallet:u.toString(),feePayer:l.extra.feePayer,couponCode:s?.couponCode}),q=f.deserializeTransaction(h),O=await f.partiallySignTransaction({transaction:q,signTransaction:k,blockhash:M});b=await d.submitGaslessTransaction({resource:c,partialTx:O,couponCode:s?.couponCode,resourceType:"regular",requirement:l})}else{const h=await f.buildTransaction({requirement:l,payerPublicKey:u}),M=await f.signTransaction({transaction:h,signTransaction:k}),q=f.buildPaymentPayload({requirement:l,signedTx:M,payerPublicKey:u});b=await d.submitPayment({resource:c,payload:q,couponCode:s?.couponCode,resourceType:"regular"})}if(b.success){const h=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});y({status:"success",error:null,sessionId:b.transactionId||null,subscriptionStatus:h.status,expiresAt:h.expiresAt||h.currentPeriodEnd||null})}else y(h=>({...h,status:"error",error:b.error||"Subscription payment failed"}));return b}catch(i){const l=t.formatError(i,"Subscription payment failed");return y(P=>({...P,status:"error",error:l})),{success:!1,error:l}}finally{x.current=!1}},[w,o,d,f,u,k]),I=a.useCallback(()=>{y({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),R(null)},[]);return{...E,quote:B,checkStatus:_,requestQuote:W,processPayment:S,reset:I}}function he({resource:o,interval:d,intervalDays:f,couponCode:u,label:k,disabled:E=!1,onAttempt:y,onSuccess:B,onError:R,className:x="",testPageUrl:w,hideMessages:_=!1,autoCheckStatus:W=!0}){const{connected:S,connecting:I,connect:c,disconnect:n,select:s,wallets:g,wallet:i,publicKey:l}=Y.useWallet(),{status:P,error:b,subscriptionStatus:h,expiresAt:M,checkStatus:q,processPayment:O}=ue(),p=t.useCedrosTheme(),{solanaError:L}=t.useCedrosContext(),{t:v,translations:$}=e.useTranslation(),de=k||v("ui.subscribe_with_crypto"),Q=a.useRef(B),F=a.useRef(R),V=a.useRef(O),X=a.useRef(q);Q.current=B,F.current=R,V.current=O,X.current=q;const ge=b&&typeof b!="string"?b?.code??null:null,pe=L&&typeof L!="string"?L?.code??null:null,H=r=>{if(!r||!$)return"";const m=$.errors[r];return m?m.action?`${m.message} ${m.action}`:m.message:""},J=b?typeof b=="string"?b:H(ge):null,Z=L?typeof L=="string"?L:H(pe):null,me=a.useMemo(()=>g.map(r=>`${r.adapter.name}-${r.readyState}`).join(","),[g]),G=a.useMemo(()=>g.filter(({readyState:r})=>r===ie.WalletReadyState.Installed||r===ie.WalletReadyState.Loadable),[me]);a.useEffect(()=>{W&&S&&l&&(t.getLogger().debug("[CryptoSubscribeButton] Auto-checking subscription status"),X.current(o))},[W,S,l,o]),a.useEffect(()=>{P==="success"&&h==="active"&&(e.emitPaymentSuccess("crypto","subscription-active",o),Q.current?.("subscription-active"))},[P,h,o]),a.useEffect(()=>{P==="error"&&b&&(e.emitPaymentError("crypto",b,o),F.current?.(b))},[P,b,o]);const ee=typeof window<"u"&&window.top!==window.self,[te,A]=a.useState(!1),[re,K]=a.useState(!1),[ne,D]=a.useState(!1),N=L;a.useEffect(()=>{let r=!1;return r||(async()=>{if(re&&i&&!S&&!I){t.getLogger().debug("[CryptoSubscribeButton] Wallet detected, attempting auto-connect:",i.adapter.name),K(!1),e.emitWalletConnect(i.adapter.name);try{await c(),r||t.getLogger().debug("[CryptoSubscribeButton] Auto-connect successful")}catch(U){if(!r){t.getLogger().error("[CryptoSubscribeButton] Auto-connect failed:",U);const Pe=U instanceof Error?U.message:"Failed to connect wallet";e.emitWalletError(Pe,i.adapter.name),D(!1)}}}})(),()=>{r=!0}},[i,re,S,I,c]),a.useEffect(()=>{S&&ne&&l&&i&&(e.emitWalletConnected(i.adapter.name,l.toString()),t.getLogger().debug("[CryptoSubscribeButton] Processing pending subscription payment"),D(!1),A(!1),e.emitPaymentProcessing("crypto",o),V.current(o,d,{couponCode:u,intervalDays:f}))},[S,ne,l,i,o,d,u,f]);const oe=a.useCallback(async()=>{if(t.getLogger().debug("[CryptoSubscribeButton] executeSubscriptionFlow called",{connected:S,wallet:i?.adapter.name,resource:o,interval:d}),e.emitPaymentStart("crypto",o),y&&y("crypto"),N){t.getLogger().error("[CryptoSubscribeButton] Solana dependencies missing:",N),e.emitPaymentError("crypto",N,o),R&&R(N);return}if(ee){const r=w||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoSubscribeButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(m){throw t.getLogger().error("[CryptoSubscribeButton] URL validation failed:",m),m}return}if(S)e.emitPaymentProcessing("crypto",o),await O(o,d,{couponCode:u,intervalDays:f});else{D(!0);try{if(i)t.getLogger().debug("[CryptoSubscribeButton] Wallet already selected, connecting:",i.adapter.name),e.emitWalletConnect(i.adapter.name),await c();else{if(t.getLogger().debug("[CryptoSubscribeButton] No wallet selected, showing selector"),G.length===0){D(!1);const r="No wallets available";throw e.emitWalletError(r),new Error(r)}A(!0)}}catch(r){D(!1);const m=r instanceof Error?r.message:"Failed to connect wallet";t.getLogger().error("[CryptoSubscribeButton] Connection error:",m),e.emitWalletError(m,i?.adapter.name)}}},[S,i,o,d,u,f,ee,w,G,c,O,N,y,R]),ae=a.useMemo(()=>`crypto-subscribe-${o}-${d}`,[o,d]),ye=a.useMemo(()=>e.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=P==="loading"||P==="checking",j=h==="active"||h==="trialing",fe=E||se||I||!!N||j;let z=de;if(se)z=v("ui.processing");else if(j&&M){const r=new Date(M).toLocaleDateString();z=`${v("ui.subscribed_until")} ${r}`}else j&&(z=v("ui.subscribed"));const be=a.useCallback(async()=>{try{K(!1),S&&await n(),s(null),A(!0)}catch(r){t.getLogger().error("Failed to change wallet:",r)}},[S,n,s]),Ce=a.useCallback(r=>{t.getLogger().debug("[CryptoSubscribeButton] Wallet clicked:",r),A(!1),s(r),K(!0)},[s]),Se=a.useCallback(async()=>{try{if(await n(),D(!1),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(r){r instanceof Error&&r.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",r)}}catch(r){t.getLogger().error("Failed to disconnect wallet:",r)}},[n]);return C.jsxs("div",{className:p.unstyled?x:`${p.className} cedros-theme__crypto-button ${x||""}`,style:p.unstyled?{}:p.style,children:[C.jsx("button",{onClick:ye,disabled:fe,className:p.unstyled?x:"cedros-theme__button cedros-theme__crypto",type:"button",children:z}),te&&!_&&C.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:p.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>A(!1),children:C.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:p.tokens.modalBackground,borderRadius:"12px",padding:"2rem",maxWidth:"400px",width:"100%",boxShadow:"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",border:`1px solid ${p.tokens.modalBorder}`},onClick:r=>r.stopPropagation(),children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[C.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:p.tokens.surfaceText},children:v("wallet.select_wallet")}),C.jsx("button",{onClick:()=>A(!1),style:e.getModalCloseButtonStyles(p.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:G.map(r=>C.jsxs("button",{onClick:()=>Ce(r.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:p.tokens.surfaceBackground,border:`1px solid ${p.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:p.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:m=>{m.currentTarget.style.backgroundColor=p.tokens.modalBackground,m.currentTarget.style.borderColor=p.tokens.surfaceText,m.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:m=>{m.currentTarget.style.backgroundColor=p.tokens.surfaceBackground,m.currentTarget.style.borderColor=p.tokens.surfaceBorder,m.currentTarget.style.transform="translateY(0)"},type:"button",children:[C.jsx(Ee.WalletIcon,{wallet:r,style:{width:"24px",height:"24px"}}),C.jsx("span",{style:{fontWeight:500},children:r.adapter.name})]},r.adapter.name))})]})}),S&&!_&&!te&&C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:p.tokens.surfaceText,opacity:.7},children:[C.jsx("button",{onClick:be,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:v("wallet.change")}),C.jsx("button",{onClick:Se,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:v("ui.disconnect")})]}),!_&&Z&&C.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:Z}),!_&&J&&C.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:J}),!_&&j&&C.jsx("div",{className:p.unstyled?"":"cedros-theme__success",children:v("ui.subscription_active")})]})}function we(){const{x402Manager:o,walletManager:d}=t.useCedrosContext(),{publicKey:f,signTransaction:u}=Y.useWallet(),[k,E]=a.useState({status:"idle",error:null,transactionId:null}),[y,B]=a.useState(null),[R,x]=a.useState(null),w=a.useRef(!1),_=a.useCallback(async c=>{try{E(s=>({...s,status:"loading"}));const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received from server");return B(n),E(s=>({...s,status:"idle"})),n}catch(n){const s=t.formatError(n,"Failed to fetch refund requirement");throw E({status:"error",error:s,transactionId:null}),n}},[o]),W=a.useCallback(async(c,n)=>{if(w.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");w.current=!0;try{E({status:"loading",error:null,transactionId:null});const s=await o.requestQuote({resource:c,couponCode:n});if(!o.validateRequirement(s))throw new Error("Invalid refund requirement received");B(s);const g=await d.buildTransaction({requirement:s,payerPublicKey:f}),i=await d.signTransaction({transaction:g,signTransaction:u}),l=d.buildPaymentPayload({requirement:s,signedTx:i,payerPublicKey:f}),P=await o.submitPayment({resource:c,payload:l,couponCode:n,metadata:void 0,resourceType:"refund"});return P.settlement&&x(P.settlement),E({status:"success",error:null,transactionId:P.transactionId||i.signature}),P}catch(s){const g=t.formatError(s,"Refund payment failed");throw E({status:"error",error:g,transactionId:null}),s}finally{w.current=!1}},[f,u,o,d]),S=a.useCallback(async c=>{if(w.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");w.current=!0;try{E({status:"loading",error:null,transactionId:null});const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received");B(n);const{transaction:s}=await o.buildGaslessTransaction({resourceId:c,userWallet:f.toString(),feePayer:n.extra.feePayer}),g=d.deserializeTransaction(s),i=await d.partiallySignTransaction({transaction:g,signTransaction:u}),l=await o.submitGaslessTransaction({resource:c,partialTx:i,couponCode:void 0,metadata:void 0,resourceType:"refund",requirement:n});return l.settlement&&x(l.settlement),E({status:"success",error:null,transactionId:l.transactionId||"gasless-refund-tx"}),l}catch(n){const s=t.formatError(n,"Gasless refund payment failed");throw E({status:"error",error:s,transactionId:null}),n}finally{w.current=!1}},[f,u,o,d]),I=a.useCallback(()=>{E({status:"idle",error:null,transactionId:null}),B(null),x(null)},[]);return{state:k,requirement:y,settlement:R,fetchRefundQuote:_,processRefund:W,processGaslessRefund:S,reset:I}}exports.CEDROS_EVENTS=e.CEDROS_EVENTS;exports.CSP_PRESETS=e.CSP_PRESETS;exports.CedrosPay=e.CedrosPay;exports.CreditsButton=e.CreditsButton;exports.CreditsSubscribeButton=e.CreditsSubscribeButton;exports.PaymentMethodBadge=e.PaymentMethodBadge;exports.PaymentModal=e.PaymentModal;exports.ProductPrice=e.ProductPrice;exports.PurchaseButton=e.PurchaseButton;exports.RPC_PROVIDERS=e.RPC_PROVIDERS;exports.SECURITY_RECOMMENDATIONS=e.SECURITY_RECOMMENDATIONS;exports.StripeButton=e.StripeButton;exports.SubscribeButton=e.SubscribeButton;exports.SubscriptionManagementPanel=e.SubscriptionManagementPanel;exports.calculateDiscountPercentage=e.calculateDiscountPercentage;exports.createTranslator=e.createTranslator;exports.detectLocale=e.detectLocale;exports.emitPaymentError=e.emitPaymentError;exports.emitPaymentProcessing=e.emitPaymentProcessing;exports.emitPaymentStart=e.emitPaymentStart;exports.emitPaymentSuccess=e.emitPaymentSuccess;exports.emitWalletConnect=e.emitWalletConnect;exports.emitWalletConnected=e.emitWalletConnected;exports.emitWalletError=e.emitWalletError;exports.formatCSP=e.formatCSP;exports.formatCouponCodes=e.formatCouponCodes;exports.generateCSP=e.generateCSP;exports.generateCSPDirectives=e.generateCSPDirectives;exports.getAvailableLocales=e.getAvailableLocales;exports.getLocalizedError=e.getLocalizedError;exports.getUserErrorMessage=e.getUserErrorMessage;exports.isRetryableError=e.isRetryableError;exports.loadLocale=e.loadLocale;exports.logSecurityReport=e.logSecurityReport;exports.parseCouponCodes=e.parseCouponCodes;exports.stackCheckoutCoupons=e.stackCheckoutCoupons;exports.useCreditsPayment=e.useCreditsPayment;exports.useCreditsSubscription=e.useCreditsSubscription;exports.useLocalizedError=e.useLocalizedError;exports.usePaymentMode=e.usePaymentMode;exports.useStripeCheckout=e.useStripeCheckout;exports.useSubscription=e.useSubscription;exports.useSubscriptionManagement=e.useSubscriptionManagement;exports.useTranslation=e.useTranslation;exports.validateSecurity=e.validateSecurity;exports.CEDROS_PAY_GROUPS=T.CEDROS_PAY_GROUPS;exports.CEDROS_PAY_SECTIONS=T.CEDROS_PAY_SECTIONS;exports.CEDROS_PAY_SECTION_IDS=T.CEDROS_PAY_SECTION_IDS;exports.CedrosPayAdminDashboard=T.CedrosPayAdminDashboard;exports.ComplianceGatePage=T.ComplianceGatePage;exports.CreditsBalance=T.CreditsBalance;exports.cedrosPayPlugin=T.cedrosPayPlugin;exports.ecommerce=T.index;exports.useComplianceCheck=T.useComplianceCheck;exports.useCreditsBalance=T.useCreditsBalance;exports.CIRCUIT_BREAKER_PRESETS=t.CIRCUIT_BREAKER_PRESETS;exports.CedrosProvider=t.CedrosProvider;exports.CircuitBreakerOpenError=t.CircuitBreakerOpenError;exports.CircuitState=t.CircuitState;exports.ERROR_CATEGORIES=t.ERROR_CATEGORIES;exports.KNOWN_STABLECOINS=t.KNOWN_STABLECOINS;exports.LogLevel=t.LogLevel;exports.Logger=t.Logger;exports.RATE_LIMITER_PRESETS=t.RATE_LIMITER_PRESETS;exports.RETRY_PRESETS=t.RETRY_PRESETS;exports.createCircuitBreaker=t.createCircuitBreaker;exports.createLogger=t.createLogger;exports.createRateLimiter=t.createRateLimiter;exports.getLogger=t.getLogger;exports.retryWithBackoff=t.retryWithBackoff;exports.useCedrosContext=t.useCedrosContext;exports.useCedrosTheme=t.useCedrosTheme;exports.validateConfig=t.validateConfig;exports.validateTokenMint=t.validateTokenMint;exports.CryptoButton=ce.CryptoButton;exports.useX402Payment=ce.useX402Payment;exports.WalletPool=le.WalletPool;exports.createWalletPool=le.createWalletPool;exports.CryptoSubscribeButton=he;exports.useCryptoSubscription=ue;exports.useRefundVerification=we;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./styles-BT4bhFey.js"),T=require("./index-C0g-JxJk.js"),t=require("./CedrosContext-C2RjHLaQ.js"),ce=require("./CryptoButton-DpiCnyXE.js"),C=require("react/jsx-runtime"),a=require("react"),Y=require("@solana/wallet-adapter-react"),ie=require("@solana/wallet-adapter-base"),Ee=require("@solana/wallet-adapter-react-ui"),le=require("./walletPool-IS7R3MR1.js");function ue(){const{subscriptionManager:o,x402Manager:d,walletManager:f}=t.useCedrosContext(),{publicKey:u,signTransaction:k}=Y.useWallet(),[E,y]=a.useState({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),[B,R]=a.useState(null),x=a.useRef(!1),w=a.useCallback(()=>{if(!u){const c="Wallet not connected";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}if(!k){const c="Wallet does not support signing";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}return{valid:!0}},[u,k]),_=a.useCallback(async c=>{if(!u)return y(n=>({...n,status:"error",error:"Wallet not connected"})),null;y(n=>({...n,status:"checking",error:null}));try{const n=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});return y(s=>({...s,status:n.active?"success":"idle",subscriptionStatus:n.status,expiresAt:n.expiresAt||n.currentPeriodEnd||null})),n}catch(n){const s=t.formatError(n,"Failed to check subscription status");return y(g=>({...g,status:"error",error:s})),null}},[u,o]),W=a.useCallback(async(c,n,s)=>{y(g=>({...g,status:"loading",error:null}));try{const g=await o.requestSubscriptionQuote(c,n,s);return R(g),y(i=>({...i,status:"idle"})),g}catch(g){const i=t.formatError(g,"Failed to get subscription quote");return y(l=>({...l,status:"error",error:i})),null}},[o]),S=a.useCallback(async(c,n,s)=>{if(x.current)return{success:!1,error:"Payment already in progress"};const g=w();if(!g.valid)return{success:!1,error:g.error};x.current=!0,y(i=>({...i,status:"loading",error:null}));try{const i=await o.requestSubscriptionQuote(c,n,s);R(i);const l=i.requirement;if(!d.validateRequirement(l))throw new Error("Invalid subscription quote received from server");const P=!!l.extra?.feePayer;let b;if(P){const{transaction:h,blockhash:M}=await d.buildGaslessTransaction({resourceId:c,userWallet:u.toString(),feePayer:l.extra.feePayer,couponCode:s?.couponCode}),q=f.deserializeTransaction(h),O=await f.partiallySignTransaction({transaction:q,signTransaction:k,blockhash:M});b=await d.submitGaslessTransaction({resource:c,partialTx:O,couponCode:s?.couponCode,resourceType:"regular",requirement:l})}else{const h=await f.buildTransaction({requirement:l,payerPublicKey:u}),M=await f.signTransaction({transaction:h,signTransaction:k}),q=f.buildPaymentPayload({requirement:l,signedTx:M,payerPublicKey:u});b=await d.submitPayment({resource:c,payload:q,couponCode:s?.couponCode,resourceType:"regular"})}if(b.success){const h=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});y({status:"success",error:null,sessionId:b.transactionId||null,subscriptionStatus:h.status,expiresAt:h.expiresAt||h.currentPeriodEnd||null})}else y(h=>({...h,status:"error",error:b.error||"Subscription payment failed"}));return b}catch(i){const l=t.formatError(i,"Subscription payment failed");return y(P=>({...P,status:"error",error:l})),{success:!1,error:l}}finally{x.current=!1}},[w,o,d,f,u,k]),I=a.useCallback(()=>{y({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),R(null)},[]);return{...E,quote:B,checkStatus:_,requestQuote:W,processPayment:S,reset:I}}function he({resource:o,interval:d,intervalDays:f,couponCode:u,label:k,disabled:E=!1,onAttempt:y,onSuccess:B,onError:R,className:x="",testPageUrl:w,hideMessages:_=!1,autoCheckStatus:W=!0}){const{connected:S,connecting:I,connect:c,disconnect:n,select:s,wallets:g,wallet:i,publicKey:l}=Y.useWallet(),{status:P,error:b,subscriptionStatus:h,expiresAt:M,checkStatus:q,processPayment:O}=ue(),p=t.useCedrosTheme(),{solanaError:L}=t.useCedrosContext(),{t:v,translations:$}=e.useTranslation(),de=k||v("ui.subscribe_with_crypto"),Q=a.useRef(B),F=a.useRef(R),V=a.useRef(O),X=a.useRef(q);Q.current=B,F.current=R,V.current=O,X.current=q;const ge=b&&typeof b!="string"?b?.code??null:null,pe=L&&typeof L!="string"?L?.code??null:null,H=r=>{if(!r||!$)return"";const m=$.errors[r];return m?m.action?`${m.message} ${m.action}`:m.message:""},J=b?typeof b=="string"?b:H(ge):null,Z=L?typeof L=="string"?L:H(pe):null,me=a.useMemo(()=>g.map(r=>`${r.adapter.name}-${r.readyState}`).join(","),[g]),G=a.useMemo(()=>g.filter(({readyState:r})=>r===ie.WalletReadyState.Installed||r===ie.WalletReadyState.Loadable),[me]);a.useEffect(()=>{W&&S&&l&&(t.getLogger().debug("[CryptoSubscribeButton] Auto-checking subscription status"),X.current(o))},[W,S,l,o]),a.useEffect(()=>{P==="success"&&h==="active"&&(e.emitPaymentSuccess("crypto","subscription-active",o),Q.current?.("subscription-active"))},[P,h,o]),a.useEffect(()=>{P==="error"&&b&&(e.emitPaymentError("crypto",b,o),F.current?.(b))},[P,b,o]);const ee=typeof window<"u"&&window.top!==window.self,[te,A]=a.useState(!1),[re,K]=a.useState(!1),[ne,D]=a.useState(!1),N=L;a.useEffect(()=>{let r=!1;return r||(async()=>{if(re&&i&&!S&&!I){t.getLogger().debug("[CryptoSubscribeButton] Wallet detected, attempting auto-connect:",i.adapter.name),K(!1),e.emitWalletConnect(i.adapter.name);try{await c(),r||t.getLogger().debug("[CryptoSubscribeButton] Auto-connect successful")}catch(U){if(!r){t.getLogger().error("[CryptoSubscribeButton] Auto-connect failed:",U);const Pe=U instanceof Error?U.message:"Failed to connect wallet";e.emitWalletError(Pe,i.adapter.name),D(!1)}}}})(),()=>{r=!0}},[i,re,S,I,c]),a.useEffect(()=>{S&&ne&&l&&i&&(e.emitWalletConnected(i.adapter.name,l.toString()),t.getLogger().debug("[CryptoSubscribeButton] Processing pending subscription payment"),D(!1),A(!1),e.emitPaymentProcessing("crypto",o),V.current(o,d,{couponCode:u,intervalDays:f}))},[S,ne,l,i,o,d,u,f]);const oe=a.useCallback(async()=>{if(t.getLogger().debug("[CryptoSubscribeButton] executeSubscriptionFlow called",{connected:S,wallet:i?.adapter.name,resource:o,interval:d}),e.emitPaymentStart("crypto",o),y&&y("crypto"),N){t.getLogger().error("[CryptoSubscribeButton] Solana dependencies missing:",N),e.emitPaymentError("crypto",N,o),R&&R(N);return}if(ee){const r=w||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoSubscribeButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(m){throw t.getLogger().error("[CryptoSubscribeButton] URL validation failed:",m),m}return}if(S)e.emitPaymentProcessing("crypto",o),await O(o,d,{couponCode:u,intervalDays:f});else{D(!0);try{if(i)t.getLogger().debug("[CryptoSubscribeButton] Wallet already selected, connecting:",i.adapter.name),e.emitWalletConnect(i.adapter.name),await c();else{if(t.getLogger().debug("[CryptoSubscribeButton] No wallet selected, showing selector"),G.length===0){D(!1);const r="No wallets available";throw e.emitWalletError(r),new Error(r)}A(!0)}}catch(r){D(!1);const m=r instanceof Error?r.message:"Failed to connect wallet";t.getLogger().error("[CryptoSubscribeButton] Connection error:",m),e.emitWalletError(m,i?.adapter.name)}}},[S,i,o,d,u,f,ee,w,G,c,O,N,y,R]),ae=a.useMemo(()=>`crypto-subscribe-${o}-${d}`,[o,d]),ye=a.useMemo(()=>e.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=P==="loading"||P==="checking",j=h==="active"||h==="trialing",fe=E||se||I||!!N||j;let z=de;if(se)z=v("ui.processing");else if(j&&M){const r=new Date(M).toLocaleDateString();z=`${v("ui.subscribed_until")} ${r}`}else j&&(z=v("ui.subscribed"));const be=a.useCallback(async()=>{try{K(!1),S&&await n(),s(null),A(!0)}catch(r){t.getLogger().error("Failed to change wallet:",r)}},[S,n,s]),Ce=a.useCallback(r=>{t.getLogger().debug("[CryptoSubscribeButton] Wallet clicked:",r),A(!1),s(r),K(!0)},[s]),Se=a.useCallback(async()=>{try{if(await n(),D(!1),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(r){r instanceof Error&&r.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",r)}}catch(r){t.getLogger().error("Failed to disconnect wallet:",r)}},[n]);return C.jsxs("div",{className:p.unstyled?x:`${p.className} cedros-theme__crypto-button ${x||""}`,style:p.unstyled?{}:p.style,children:[C.jsx("button",{onClick:ye,disabled:fe,className:p.unstyled?x:"cedros-theme__button cedros-theme__crypto",type:"button",children:z}),te&&!_&&C.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:p.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>A(!1),children:C.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:p.tokens.modalBackground,borderRadius:"12px",padding:"2rem",maxWidth:"400px",width:"100%",boxShadow:"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",border:`1px solid ${p.tokens.modalBorder}`},onClick:r=>r.stopPropagation(),children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[C.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:p.tokens.surfaceText},children:v("wallet.select_wallet")}),C.jsx("button",{onClick:()=>A(!1),style:e.getModalCloseButtonStyles(p.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:G.map(r=>C.jsxs("button",{onClick:()=>Ce(r.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:p.tokens.surfaceBackground,border:`1px solid ${p.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:p.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:m=>{m.currentTarget.style.backgroundColor=p.tokens.modalBackground,m.currentTarget.style.borderColor=p.tokens.surfaceText,m.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:m=>{m.currentTarget.style.backgroundColor=p.tokens.surfaceBackground,m.currentTarget.style.borderColor=p.tokens.surfaceBorder,m.currentTarget.style.transform="translateY(0)"},type:"button",children:[C.jsx(Ee.WalletIcon,{wallet:r,style:{width:"24px",height:"24px"}}),C.jsx("span",{style:{fontWeight:500},children:r.adapter.name})]},r.adapter.name))})]})}),S&&!_&&!te&&C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:p.tokens.surfaceText,opacity:.7},children:[C.jsx("button",{onClick:be,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:v("wallet.change")}),C.jsx("button",{onClick:Se,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:v("ui.disconnect")})]}),!_&&Z&&C.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:Z}),!_&&J&&C.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:J}),!_&&j&&C.jsx("div",{className:p.unstyled?"":"cedros-theme__success",children:v("ui.subscription_active")})]})}function we(){const{x402Manager:o,walletManager:d}=t.useCedrosContext(),{publicKey:f,signTransaction:u}=Y.useWallet(),[k,E]=a.useState({status:"idle",error:null,transactionId:null}),[y,B]=a.useState(null),[R,x]=a.useState(null),w=a.useRef(!1),_=a.useCallback(async c=>{try{E(s=>({...s,status:"loading"}));const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received from server");return B(n),E(s=>({...s,status:"idle"})),n}catch(n){const s=t.formatError(n,"Failed to fetch refund requirement");throw E({status:"error",error:s,transactionId:null}),n}},[o]),W=a.useCallback(async(c,n)=>{if(w.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");w.current=!0;try{E({status:"loading",error:null,transactionId:null});const s=await o.requestQuote({resource:c,couponCode:n});if(!o.validateRequirement(s))throw new Error("Invalid refund requirement received");B(s);const g=await d.buildTransaction({requirement:s,payerPublicKey:f}),i=await d.signTransaction({transaction:g,signTransaction:u}),l=d.buildPaymentPayload({requirement:s,signedTx:i,payerPublicKey:f}),P=await o.submitPayment({resource:c,payload:l,couponCode:n,metadata:void 0,resourceType:"refund"});return P.settlement&&x(P.settlement),E({status:"success",error:null,transactionId:P.transactionId||i.signature}),P}catch(s){const g=t.formatError(s,"Refund payment failed");throw E({status:"error",error:g,transactionId:null}),s}finally{w.current=!1}},[f,u,o,d]),S=a.useCallback(async c=>{if(w.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");w.current=!0;try{E({status:"loading",error:null,transactionId:null});const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received");B(n);const{transaction:s}=await o.buildGaslessTransaction({resourceId:c,userWallet:f.toString(),feePayer:n.extra.feePayer}),g=d.deserializeTransaction(s),i=await d.partiallySignTransaction({transaction:g,signTransaction:u}),l=await o.submitGaslessTransaction({resource:c,partialTx:i,couponCode:void 0,metadata:void 0,resourceType:"refund",requirement:n});return l.settlement&&x(l.settlement),E({status:"success",error:null,transactionId:l.transactionId||"gasless-refund-tx"}),l}catch(n){const s=t.formatError(n,"Gasless refund payment failed");throw E({status:"error",error:s,transactionId:null}),n}finally{w.current=!1}},[f,u,o,d]),I=a.useCallback(()=>{E({status:"idle",error:null,transactionId:null}),B(null),x(null)},[]);return{state:k,requirement:y,settlement:R,fetchRefundQuote:_,processRefund:W,processGaslessRefund:S,reset:I}}exports.CEDROS_EVENTS=e.CEDROS_EVENTS;exports.CSP_PRESETS=e.CSP_PRESETS;exports.CedrosPay=e.CedrosPay;exports.CreditsButton=e.CreditsButton;exports.CreditsSubscribeButton=e.CreditsSubscribeButton;exports.PaymentMethodBadge=e.PaymentMethodBadge;exports.PaymentModal=e.PaymentModal;exports.ProductPrice=e.ProductPrice;exports.PurchaseButton=e.PurchaseButton;exports.RPC_PROVIDERS=e.RPC_PROVIDERS;exports.SECURITY_RECOMMENDATIONS=e.SECURITY_RECOMMENDATIONS;exports.StripeButton=e.StripeButton;exports.SubscribeButton=e.SubscribeButton;exports.SubscriptionManagementPanel=e.SubscriptionManagementPanel;exports.calculateDiscountPercentage=e.calculateDiscountPercentage;exports.createTranslator=e.createTranslator;exports.detectLocale=e.detectLocale;exports.emitPaymentError=e.emitPaymentError;exports.emitPaymentProcessing=e.emitPaymentProcessing;exports.emitPaymentStart=e.emitPaymentStart;exports.emitPaymentSuccess=e.emitPaymentSuccess;exports.emitWalletConnect=e.emitWalletConnect;exports.emitWalletConnected=e.emitWalletConnected;exports.emitWalletError=e.emitWalletError;exports.formatCSP=e.formatCSP;exports.formatCouponCodes=e.formatCouponCodes;exports.generateCSP=e.generateCSP;exports.generateCSPDirectives=e.generateCSPDirectives;exports.getAvailableLocales=e.getAvailableLocales;exports.getLocalizedError=e.getLocalizedError;exports.getUserErrorMessage=e.getUserErrorMessage;exports.isRetryableError=e.isRetryableError;exports.loadLocale=e.loadLocale;exports.logSecurityReport=e.logSecurityReport;exports.parseCouponCodes=e.parseCouponCodes;exports.stackCheckoutCoupons=e.stackCheckoutCoupons;exports.useCreditsPayment=e.useCreditsPayment;exports.useCreditsSubscription=e.useCreditsSubscription;exports.useLocalizedError=e.useLocalizedError;exports.usePaymentMode=e.usePaymentMode;exports.useStripeCheckout=e.useStripeCheckout;exports.useSubscription=e.useSubscription;exports.useSubscriptionManagement=e.useSubscriptionManagement;exports.useTranslation=e.useTranslation;exports.validateSecurity=e.validateSecurity;exports.CEDROS_PAY_GROUPS=T.CEDROS_PAY_GROUPS;exports.CEDROS_PAY_SECTIONS=T.CEDROS_PAY_SECTIONS;exports.CEDROS_PAY_SECTION_IDS=T.CEDROS_PAY_SECTION_IDS;exports.CedrosPayAdminDashboard=T.CedrosPayAdminDashboard;exports.ComplianceGatePage=T.ComplianceGatePage;exports.CreditsBalance=T.CreditsBalance;exports.cedrosPayPlugin=T.cedrosPayPlugin;exports.ecommerce=T.index;exports.useComplianceCheck=T.useComplianceCheck;exports.useCreditsBalance=T.useCreditsBalance;exports.CIRCUIT_BREAKER_PRESETS=t.CIRCUIT_BREAKER_PRESETS;exports.CedrosProvider=t.CedrosProvider;exports.CircuitBreakerOpenError=t.CircuitBreakerOpenError;exports.CircuitState=t.CircuitState;exports.ERROR_CATEGORIES=t.ERROR_CATEGORIES;exports.KNOWN_STABLECOINS=t.KNOWN_STABLECOINS;exports.LogLevel=t.LogLevel;exports.Logger=t.Logger;exports.RATE_LIMITER_PRESETS=t.RATE_LIMITER_PRESETS;exports.RETRY_PRESETS=t.RETRY_PRESETS;exports.createCircuitBreaker=t.createCircuitBreaker;exports.createLogger=t.createLogger;exports.createRateLimiter=t.createRateLimiter;exports.getLogger=t.getLogger;exports.retryWithBackoff=t.retryWithBackoff;exports.useCedrosContext=t.useCedrosContext;exports.useCedrosTheme=t.useCedrosTheme;exports.validateConfig=t.validateConfig;exports.validateTokenMint=t.validateTokenMint;exports.CryptoButton=ce.CryptoButton;exports.useX402Payment=ce.useX402Payment;exports.WalletPool=le.WalletPool;exports.createWalletPool=le.createWalletPool;exports.CryptoSubscribeButton=he;exports.useCryptoSubscription=ue;exports.useRefundVerification=we;
@@ -1,6 +1,6 @@
1
1
  import { O as Te, q as ve, n as fe, s as Be, o as me, p as Ie, r as ye, t as V, V as _e, W as We } from "./styles-D4SQkuV3.mjs";
2
2
  import { C as Ue, a as Ye, b as Ve, c as He, d as Je, P as Xe, e as Ze, f as et, g as tt, R as rt, S as nt, h as at, i as st, j as ot, k as it, l as ct, m as lt, u as ut, v as dt, w as pt, x as ft, y as mt, z as yt, A as gt, B as bt, D as St, E as wt, F as Ct, G as ht, H as xt, I as Pt, J as Et, K as Rt, L as kt, M as Tt, N as vt, Q as Bt } from "./styles-D4SQkuV3.mjs";
3
- import { C as _t, a as Wt, b as qt, c as Mt, d as Lt, e as At, f as Dt, i as Ot, u as Nt, g as zt } from "./index-BkDimQDF.mjs";
3
+ import { C as _t, a as Wt, b as qt, c as Mt, d as Lt, e as At, f as Dt, i as Ot, u as Nt, g as zt } from "./index-DXnuQp5x.mjs";
4
4
  import { u as H, m as z, j as qe, i as y } from "./CedrosContext-CY6zvjvJ.mjs";
5
5
  import { C as Qt, a as $t, b as Ft, c as Gt, E as jt, K as Ut, L as Yt, d as Vt, R as Ht, e as Jt, f as Xt, g as Zt, h as er, r as tr, v as rr, n as nr } from "./CedrosContext-CY6zvjvJ.mjs";
6
6
  import { C as sr, u as or } from "./CryptoButton-BV9owVe2.mjs";