@cedros/pay-react 1.1.27 → 1.1.29
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-DELur7D2.js → AISettingsSection-B7qrycfY.js} +2 -2
- package/dist/{AISettingsSection-BlIv3CzS.mjs → AISettingsSection-DtAgMsDw.mjs} +6 -4
- package/dist/{AutosaveIndicator-Bed0-ekg.mjs → AutosaveIndicator-BEvABoKU.mjs} +1 -1
- package/dist/AutosaveIndicator-DiyeAg93.js +1 -0
- package/dist/CedrosContext-5Gjveoba.mjs +2555 -0
- package/dist/CedrosContext-CCakH2SZ.js +3 -0
- package/dist/CedrosPayAdminDashboard-CAwEvn66.js +1 -0
- package/dist/CedrosPayAdminDashboard-CBuvNAtB.mjs +250 -0
- package/dist/{ChatLogsSection-v4zwzCTC.mjs → ChatLogsSection-Ber5o8hF.mjs} +19 -17
- package/dist/ChatLogsSection-DLxMMi9I.js +1 -0
- package/dist/ComplianceSection-Buu0zTiL.js +1 -0
- package/dist/{ComplianceSection-CemgfDrL.mjs → ComplianceSection-ZCr0wsvw.mjs} +18 -15
- package/dist/{CryptoButton-BV9owVe2.mjs → CryptoButton-Cl2kZbOP.mjs} +26 -24
- package/dist/CryptoButton-DxFCYDlJ.js +1 -0
- package/dist/CustomersSection-BywmMLur.js +1 -0
- package/dist/{CustomersSection-D_j7OrfS.mjs → CustomersSection-D9UknSKC.mjs} +21 -19
- package/dist/{DisputesSection-BcAbXp3K.mjs → DisputesSection-C_eySK-W.mjs} +19 -17
- package/dist/DisputesSection-DwkHGv2a.js +1 -0
- package/dist/Dropdown-B90Zabxr.mjs +111 -0
- package/dist/Dropdown-CtY91emj.js +1 -0
- package/dist/ErrorBanner-CZXsHi3H.mjs +22 -0
- package/dist/ErrorBanner-Cx2dUhps.js +1 -0
- package/dist/{FAQSection-Dn38OhB_.mjs → FAQSection-Bv_Hdt8B.mjs} +8 -6
- package/dist/FAQSection-DlPLnIJD.js +1 -0
- package/dist/ImagesSection-B4Jzet79.js +1 -0
- package/dist/{ImagesSection-Ctw9Icym.mjs → ImagesSection-DpdXQ6qu.mjs} +6 -4
- package/dist/InventorySection-BgRdpn1l.js +1 -0
- package/dist/{InventorySection-DmhjUlRZ.mjs → InventorySection-DZMu9DMw.mjs} +25 -23
- package/dist/MessagingSection-CxV-pf-f.js +1 -0
- package/dist/{MessagingSection-B1FaGxkp.mjs → MessagingSection-D_cOBfFt.mjs} +5 -4
- package/dist/OrdersSection-BbAX79Ff.js +1 -0
- package/dist/{OrdersSection-Bj8bPdg8.mjs → OrdersSection-wfPavit9.mjs} +27 -24
- package/dist/PaymentSettingsSection-BdBDgaRg.js +1 -0
- package/dist/PaymentSettingsSection-DunzBo9n.mjs +648 -0
- package/dist/ReturnsSection-7k4LZ8yp.js +1 -0
- package/dist/{ReturnsSection-BC0L8r2e.mjs → ReturnsSection-B4FL7bUv.mjs} +11 -9
- package/dist/{SettingsSection-vdYFSNxB.js → SettingsSection-Cz2Yjdhr.js} +1 -1
- package/dist/{SettingsSection-KYdEizq_.mjs → SettingsSection-DoeNDbqd.mjs} +1 -1
- package/dist/{ShippingSection-BOgto6_9.mjs → ShippingSection-BlVsYC6B.mjs} +5 -3
- package/dist/ShippingSection-C-HI8rOb.js +1 -0
- package/dist/{SingleCategorySettings-suJ8z9d8.mjs → SingleCategorySettings-B406nnF-.mjs} +143 -140
- package/dist/SingleCategorySettings-BqC2UXt3.js +3 -0
- package/dist/StatsBar-D4v-I_Dj.mjs +25 -0
- package/dist/StatsBar-m6GSRNxs.js +1 -0
- package/dist/StorefrontSection-Axvh_KeS.js +1 -0
- package/dist/{StorefrontSection-BRvIGBEJ.mjs → StorefrontSection-BK_rhrAi.mjs} +121 -119
- package/dist/{SubscriptionsSection-D60qrX9a.mjs → SubscriptionsSection-D8V9RBv-.mjs} +11 -9
- package/dist/SubscriptionsSection-EeULMWIB.js +1 -0
- package/dist/{TaxSection-C7-pv-Rl.mjs → TaxSection-Cj6TXL6x.mjs} +23 -21
- package/dist/TaxSection-CzHPhaHl.js +1 -0
- package/dist/ThemeContext-CFXyYx7A.js +1 -0
- package/dist/ThemeContext-l0bqcOGW.mjs +126 -0
- package/dist/Token22Section-DqRKVG_G.js +1 -0
- package/dist/{Token22Section-CrHLQ0EB.mjs → Token22Section-DtYAcT54.mjs} +7 -6
- package/dist/{WalletManager-BIwH8Dw_.mjs → WalletManager-D-eoqUDy.mjs} +21 -19
- package/dist/WalletManager-DXChB9LA.js +1 -0
- package/dist/WebhooksSection-D--iPZuM.js +1 -0
- package/dist/{WebhooksSection-COPW4Ec0.mjs → WebhooksSection-DBAIxtBy.mjs} +40 -38
- package/dist/admin.d.ts +2 -0
- package/dist/admin.js +1 -0
- package/dist/admin.mjs +8 -0
- package/dist/configApi-BS5UJfzm.js +1 -0
- package/dist/{configApi-6XhAJGKX.mjs → configApi-BUXZOMWK.mjs} +57 -3
- package/dist/crypto-only.js +1 -1
- package/dist/crypto-only.mjs +214 -202
- package/dist/dateHelpers-BKW_lGND.js +1 -0
- package/dist/dateHelpers-yvPkofYQ.mjs +6 -0
- package/dist/fetchWithTimeout-CG0EKbhf.js +1 -0
- package/dist/fetchWithTimeout-DmMOwL0Q.mjs +195 -0
- package/dist/index-9QF_UfSN.mjs +18668 -0
- package/dist/index-Cq9ya93W.js +84 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +74 -64
- package/dist/safeHref-DqJPLPl5.mjs +12 -0
- package/dist/safeHref-DyHIpVjY.js +1 -0
- package/dist/sectionIds-B_tFiNvF.js +1 -0
- package/dist/sectionIds-DBavltrL.mjs +359 -0
- package/dist/sections-BHph7CYj.mjs +9 -0
- package/dist/sections-C2zEJr5G.js +1 -0
- package/dist/sections-more-C1VNVwkp.js +1 -0
- package/dist/sections-more-CMFgfU4d.mjs +3082 -0
- package/dist/src/admin/index.d.ts +3 -3
- package/dist/src/admin/index.d.ts.map +1 -1
- package/dist/src/admin/plugin.d.ts.map +1 -1
- package/dist/src/admin/types.d.ts +2 -6
- package/dist/src/admin/types.d.ts.map +1 -1
- package/dist/src/admin.d.ts +9 -0
- package/dist/src/admin.d.ts.map +1 -0
- package/dist/src/components/admin/LazyCedrosPayAdminDashboard.d.ts +4 -0
- package/dist/src/components/admin/LazyCedrosPayAdminDashboard.d.ts.map +1 -0
- package/dist/src/components/admin/PaymentReadinessChecklist.d.ts +9 -0
- package/dist/src/components/admin/PaymentReadinessChecklist.d.ts.map +1 -0
- package/dist/src/components/admin/PaymentSettingsSection.d.ts.map +1 -1
- package/dist/src/components/admin/PaymentSetupGuide.d.ts +6 -0
- package/dist/src/components/admin/PaymentSetupGuide.d.ts.map +1 -0
- package/dist/src/components/admin/ProductsSection.d.ts.map +1 -1
- package/dist/src/components/admin/configApi.d.ts +1 -1
- package/dist/src/components/admin/configApi.d.ts.map +1 -1
- package/dist/src/components/admin/icons.d.ts +3 -50
- package/dist/src/components/admin/icons.d.ts.map +1 -1
- package/dist/src/components/admin/index.d.ts +1 -1
- package/dist/src/components/admin/index.d.ts.map +1 -1
- package/dist/src/components/admin/types.d.ts +43 -0
- package/dist/src/components/admin/types.d.ts.map +1 -1
- package/dist/src/context/CedrosContext.d.ts +2 -0
- package/dist/src/context/CedrosContext.d.ts.map +1 -1
- package/dist/src/ecommerce/__tests__/featureFlags.test.d.ts +2 -0
- package/dist/src/ecommerce/__tests__/featureFlags.test.d.ts.map +1 -0
- package/dist/src/ecommerce/adapters/paywall/paywallAdapter.d.ts.map +1 -1
- package/dist/src/ecommerce/components/general/ErrorBoundary.d.ts +1 -1
- package/dist/src/ecommerce/components/ui/button.d.ts +1 -1
- package/dist/src/ecommerce/components/ui/sheet.d.ts +1 -1
- package/dist/src/ecommerce/config/context.d.ts +2 -0
- package/dist/src/ecommerce/config/context.d.ts.map +1 -1
- package/dist/src/ecommerce/config/types.d.ts +2 -0
- package/dist/src/ecommerce/config/types.d.ts.map +1 -1
- package/dist/src/ecommerce/index.d.ts +2 -0
- package/dist/src/ecommerce/index.d.ts.map +1 -1
- package/dist/src/featureFlags.d.ts +41 -0
- package/dist/src/featureFlags.d.ts.map +1 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/managers/StripeManager.d.ts.map +1 -1
- package/dist/src/managers/SubscriptionManager.d.ts +1 -0
- package/dist/src/managers/SubscriptionManager.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +14 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/subscription.d.ts +47 -1
- package/dist/src/types/subscription.d.ts.map +1 -1
- package/dist/src/utils/validateConfig.d.ts.map +1 -1
- package/dist/stripe-only.js +1 -1
- package/dist/stripe-only.mjs +35 -33
- package/dist/styles--fxb3lCl.js +1 -0
- package/dist/{styles-D4SQkuV3.mjs → styles-DGagylUj.mjs} +53 -51
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/tokenMintValidator-DAjQld0r.mjs +98 -0
- package/dist/tokenMintValidator-DNBhoefh.js +4 -0
- package/dist/{walletPool-DE-t1wSW.mjs → walletPool-9MylB2QK.mjs} +1 -1
- package/dist/walletPool-BjTXX6Vn.js +1 -0
- package/package.json +6 -5
- package/dist/AutosaveIndicator-Dn_qA2hK.js +0 -1
- package/dist/CedrosContext-C2RjHLaQ.js +0 -6
- package/dist/CedrosContext-CY6zvjvJ.mjs +0 -2801
- package/dist/ChatLogsSection-BH5tLA4T.js +0 -1
- package/dist/ComplianceSection-DP2a9-S0.js +0 -1
- package/dist/CryptoButton-DpiCnyXE.js +0 -1
- package/dist/CustomersSection-CBwy_waO.js +0 -1
- package/dist/DisputesSection-BLjIk60n.js +0 -1
- package/dist/FAQSection-wNeH0i6Q.js +0 -1
- package/dist/ImagesSection-0ZzKlzMJ.js +0 -1
- package/dist/InventorySection-zV6lTmue.js +0 -1
- package/dist/MessagingSection-B_wdFR0j.js +0 -1
- package/dist/OrdersSection-Dw2FX-1d.js +0 -1
- package/dist/PaymentSettingsSection-BYF4D-GR.js +0 -1
- package/dist/PaymentSettingsSection-EnMxeWjv.mjs +0 -94
- package/dist/ReturnsSection-D_pJVxuG.js +0 -1
- package/dist/ShippingSection-1DRSTu49.js +0 -1
- package/dist/SingleCategorySettings-DwCnBdRf.js +0 -3
- package/dist/StorefrontSection-RumGkb3C.js +0 -1
- package/dist/SubscriptionsSection-C2aLLn7L.js +0 -1
- package/dist/TaxSection-Dt1DnM51.js +0 -1
- package/dist/Token22Section-DY3mUwTY.js +0 -1
- package/dist/WalletManager-B3UdQ5pQ.js +0 -1
- package/dist/WebhooksSection-CKeiJ7Py.js +0 -1
- package/dist/configApi-DkduMQg1.js +0 -1
- package/dist/index-C0g-JxJk.js +0 -84
- package/dist/index-DXnuQp5x.mjs +0 -22128
- package/dist/sections-C1NpK7hk.mjs +0 -9
- package/dist/sections-DVVSZBhW.js +0 -1
- package/dist/styles-BT4bhFey.js +0 -1
- package/dist/walletPool-IS7R3MR1.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),i=require("./index-C0g-JxJk.js");function D({serverUrl:_,apiKey:l,pageSize:o=20,authManager:m}){const[g,b]=a.useState([]),[h,w]=a.useState(0),[r,u]=a.useState(0),[A,p]=a.useState(!0),[k,x]=a.useState(null),[d,T]=a.useState("all"),[y,v]=a.useState(null),[L,S]=a.useState(!1),f=a.useCallback(async t=>{if(m?.isAuthenticated())return m.fetchWithAuth(t);const n={"Content-Type":"application/json"};l&&(n["X-API-Key"]=l);const s=await fetch(`${_}${t}`,{headers:n});if(!s.ok)throw new Error(`Request failed: ${s.status}`);return s.json()},[_,l,m]),C=a.useCallback(async()=>{p(!0),x(null);try{const t=new URLSearchParams;t.set("limit",String(o)),t.set("offset",String(r)),d!=="all"&&t.set("status",d);const n=await f(`/admin/chats?${t.toString()}`);b(n.sessions??[]),w(n.total??0)}catch{x("Failed to load chat sessions"),b([])}finally{p(!1)}},[f,o,r,d]);a.useEffect(()=>{C()},[C]);const I=async t=>{S(!0);try{const n=await f(`/admin/chats/${encodeURIComponent(t)}`);v(n)}catch{x("Failed to load chat session")}finally{S(!1)}},j=Math.max(1,Math.ceil(h/o)),N=Math.floor(r/o)+1;if(y){const{session:t,messages:n}=y;return e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>v(null),style:{marginBottom:"1rem"},children:"← Back to sessions"}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsxs("h3",{className:"cedros-admin__section-title",children:["Chat Session",e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--muted",style:{marginLeft:"0.5rem"},children:[t.messageCount," messages"]})]})}),e.jsxs("div",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)",marginBottom:"1rem"},children:[t.customerEmail&&e.jsxs("span",{children:["Customer: ",e.jsx("strong",{children:t.customerEmail})," · "]}),"Started ",i.formatDateTime(t.createdAt)," · Last message ",i.formatDateTime(t.lastMessageAt)]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"640px"},children:n.map(s=>e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:s.role==="user"?"flex-end":"flex-start"},children:[e.jsx("div",{style:{maxWidth:"85%",padding:"0.5rem 0.75rem",borderRadius:"0.75rem",fontSize:"0.85rem",lineHeight:"1.4",background:s.role==="user"?"var(--cedros-admin-bg-dark, #1a1a1a)":"var(--cedros-admin-bg-muted, #f5f5f5)",color:s.role==="user"?"#fff":"var(--cedros-admin-text, #333)"},children:e.jsx("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:s.content})}),s.products&&s.products.length>0&&e.jsx("div",{style:{maxWidth:"85%",marginTop:"0.25rem",display:"flex",flexWrap:"wrap",gap:"0.25rem"},children:s.products.map(c=>e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--muted",style:{fontSize:"0.75rem"},children:[c.name,c.priceCents!=null?` ($${(c.priceCents/100).toFixed(2)})`:""]},c.id))}),s.actions&&s.actions.length>0&&e.jsx("div",{style:{maxWidth:"85%",marginTop:"0.25rem",fontSize:"0.75rem",fontStyle:"italic",color:"var(--cedros-admin-text-muted, #888)"},children:s.actions.join(" · ")}),e.jsx("div",{style:{fontSize:"0.7rem",color:"var(--cedros-admin-text-muted, #aaa)",marginTop:"0.15rem"},children:i.formatDateTime(s.createdAt)})]},s.id))})]})}return e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Chat Logs"})}),e.jsx(i.ErrorBanner,{message:k}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginBottom:"1rem",alignItems:"center"},children:[e.jsxs("select",{className:"cedros-admin__input",value:d,onChange:t=>{T(t.target.value),u(0)},style:{width:"auto",fontSize:"0.85rem"},children:[e.jsx("option",{value:"all",children:"All statuses"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"archived",children:"Archived"})]}),e.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)"},children:[h," session",h!==1?"s":""]})]}),A||L?e.jsxs("div",{className:"cedros-admin__loading",children:[i.Icons.loading," Loading chat sessions..."]}):g.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No chat sessions found."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Customer"}),e.jsx("th",{children:"Messages"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Last Message"}),e.jsx("th",{children:"Started"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:g.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:t.customerEmail?e.jsx("span",{title:t.customerId,children:t.customerEmail}):t.customerId?e.jsxs("code",{style:{fontSize:"0.75rem"},children:[t.customerId.slice(0,12),"..."]}):e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"Anonymous"})}),e.jsx("td",{children:t.messageCount}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${t.status==="active"?"success":"muted"}`,children:t.status})}),e.jsx("td",{children:i.formatDateTime(t.lastMessageAt)}),e.jsx("td",{children:i.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>I(t.id),children:"View"})})]},t.id))})]})}),j>1&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:r===0,onClick:()=>u(Math.max(0,r-o)),children:"Previous"}),e.jsxs("span",{children:["Page ",N," of ",j]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:N>=j,onClick:()=>u(r+o),children:"Next"})]})]})]})}exports.ChatLogsSection=D;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),m=require("./index-C0g-JxJk.js"),y=require("./CedrosContext-C2RjHLaQ.js"),_=a=>a.length>12?`${a.slice(0,6)}...${a.slice(-4)}`:a,ie=a=>{switch(a){case"active":return"success";case"frozen":return"failed";case"thawed":return"pending";default:return"muted"}},G=a=>{switch(a){case"freeze":return"failed";case"thaw":return"success";case"sweep_freeze":return"failed";case"report_generated":return"muted";default:return"muted"}},re=a=>{switch(a){case"verified":return"success";case"pending":return"pending";case"expired":return"failed";case"none":default:return"muted"}},ce="https://explorer.solana.com/tx/",de={apiUrl:"",refreshIntervalSecs:3600,enabled:!1};function oe({serverUrl:a,apiKey:h,authManager:u}){const[r,o]=n.useState(de),[b,A]=n.useState(!0),[x,p]=n.useState(!1),[i,N]=n.useState(!1),[C,f]=n.useState(null),[k,j]=n.useState(null),S=n.useCallback(async(s,l)=>{if(u?.isAuthenticated())return u.fetchWithAuth(s,l);const v={"Content-Type":"application/json"};h&&(v["X-API-Key"]=h);const z=await fetch(`${a}${s}`,{...l,headers:{...v,...l?.headers}});if(!z.ok)throw new Error(`Request failed: ${z.status}`);return z.json()},[a,h,u]);n.useEffect(()=>{(async()=>{try{const s=await S("/admin/compliance/sanctions-api");o(s)}catch(s){y.getLogger().error("[ComplianceSanctionsApi] Failed to fetch settings:",s)}finally{A(!1)}})()},[S]);const T=async()=>{p(!0),f(null),j(null);try{await S("/admin/compliance/sanctions-api",{method:"PUT",body:JSON.stringify(r)}),j("Settings saved")}catch(s){y.getLogger().error("[ComplianceSanctionsApi] Save failed:",s),f("Failed to save settings")}finally{p(!1)}},d=async()=>{N(!0),f(null),j(null);try{await S("/admin/compliance/sanctions-api/refresh",{method:"POST"}),j("Sanctions list refreshed")}catch(s){y.getLogger().error("[ComplianceSanctionsApi] Refresh failed:",s),f("Failed to refresh sanctions list")}finally{N(!1)}};return b?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading sanctions API settings..."]}):e.jsxs("div",{style:{maxWidth:"500px",display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Dynamic Sanctions API"})}),C&&e.jsx("div",{className:"cedros-admin__badge cedros-admin__badge--failed",style:{padding:"0.5rem"},children:C}),k&&e.jsx("div",{className:"cedros-admin__badge cedros-admin__badge--success",style:{padding:"0.5rem"},children:k}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.9rem"},children:[e.jsx("input",{type:"checkbox",checked:r.enabled,onChange:s=>o(l=>({...l,enabled:s.target.checked}))}),"Enable dynamic sanctions list"]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["API URL",e.jsx("input",{type:"url",className:"cedros-admin__input",placeholder:"https://sunscreen.cedros.io",value:r.apiUrl,onChange:s=>o(l=>({...l,apiUrl:s.target.value}))})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["Refresh interval (seconds, min 60)",e.jsx("input",{type:"number",className:"cedros-admin__input",min:60,value:r.refreshIntervalSecs,onChange:s=>o(l=>({...l,refreshIntervalSecs:Number(s.target.value)})),style:{width:"160px"}})]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:T,disabled:x,children:x?"Saving...":"Save Settings"}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:d,disabled:i||!r.enabled||!r.apiUrl,children:i?"Refreshing...":"Force Refresh"})]})]})}function le({serverUrl:a,apiKey:h,authManager:u}){const[r,o]=n.useState(""),[b,A]=n.useState(!1),[x,p]=n.useState(null),[i,N]=n.useState(null),[C,f]=n.useState(!1),k=n.useCallback(async(d,s)=>{if(u?.isAuthenticated())return u.fetchWithAuth(d,s);const l={"Content-Type":"application/json"};h&&(l["X-API-Key"]=h);const v=await fetch(`${a}${d}`,{...s,headers:{...l,...s?.headers}});if(!v.ok)throw new Error(`Request failed: ${v.status}`);return v.json()},[a,h,u]),j=async()=>{const d=r.trim();if(d){A(!0),p(null),N(null),f(!0);try{const s=await k(`/admin/compliance/user-status/${encodeURIComponent(d)}`);N(s)}catch(s){y.getLogger().error("[ComplianceKycTab] Lookup failed:",s),p("Failed to fetch user compliance status. Ensure cedros-login is configured.")}finally{A(!1)}}},S=d=>{d.key==="Enter"&&j()},T=d=>{switch(d){case"verified":return"Verified";case"pending":return"Pending";case"expired":return"Expired";case"none":default:return"Not Started"}};return e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"KYC & Accredited Investor Status"})}),e.jsx("p",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)",marginBottom:"1rem"},children:"Look up a user's KYC verification and accredited investor status from cedros-login."}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"flex-end",marginBottom:"1.5rem",maxWidth:"500px"},children:[e.jsxs("label",{style:{flex:1,display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["User ID",e.jsx("input",{type:"text",className:"cedros-admin__input",placeholder:"user_abc123",value:r,onChange:d=>o(d.target.value),onKeyDown:S})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:j,disabled:b||!r.trim(),children:b?"Looking up...":"Look Up"})]}),x&&e.jsx("div",{className:"cedros-admin__badge cedros-admin__badge--failed",style:{padding:"0.5rem",marginBottom:"1rem"},children:x}),b&&e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Fetching compliance status..."]}),i&&!b&&e.jsxs("div",{style:{maxWidth:"500px"},children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsx("table",{className:"cedros-admin__table",children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600,width:"40%"},children:"User ID"}),e.jsx("td",{children:e.jsx("code",{children:i.userId})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"KYC Status"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${re(i.kycStatus)}`,children:T(i.kycStatus)})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Accredited Investor"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${i.accreditedInvestor?"success":"muted"}`,children:i.accreditedInvestor?"Yes":"No"})})]}),i.accreditedVerifiedAt&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Accredited Since"}),e.jsx("td",{children:m.formatDateTime(i.accreditedVerifiedAt)})]})]})})}),e.jsx("div",{style:{marginTop:"0.75rem",padding:"0.75rem",borderRadius:"4px",fontSize:"0.85rem",background:i.kycStatus==="verified"?"var(--cedros-admin-bg-success, #f0fdf4)":"var(--cedros-admin-bg-muted, #f5f5f5)",color:"var(--cedros-admin-text, #333)"},children:i.kycStatus==="verified"&&i.accreditedInvestor?"This user is fully verified and accredited. They can access all compliance-gated products.":i.kycStatus==="verified"?"This user has KYC verification but is not an accredited investor.":i.kycStatus==="pending"?"This user has submitted KYC documents. Verification is in progress.":i.kycStatus==="expired"?"This user's KYC verification has expired. They will need to re-verify.":"This user has not started KYC verification."})]}),C&&!i&&!b&&!x&&e.jsx("div",{className:"cedros-admin__empty",children:"No compliance record found for this user."})]})}function me({serverUrl:a,apiKey:h,pageSize:u=50,authManager:r}){const[o,b]=n.useState("holders"),[A,x]=n.useState(null),[p,i]=n.useState([]),[N,C]=n.useState(!0),[f,k]=n.useState(""),[j,S]=n.useState([]),[T,d]=n.useState(!0),[s,l]=n.useState(null),[v,z]=n.useState(!1),[P,V]=n.useState(""),[W,X]=n.useState(""),[B,O]=n.useState({enabled:!0,batchSize:100}),[M,Q]=n.useState(!0),[H,Y]=n.useState(!1),[g,L]=n.useState(null),[R,$]=n.useState(""),[F,q]=n.useState(!1),w=n.useCallback(async(t,c)=>{if(r?.isAuthenticated())return r.fetchWithAuth(t,c);const I={"Content-Type":"application/json"};h&&(I["X-API-Key"]=h);const U=await fetch(`${a}${t}`,{...c,headers:{...I,...c?.headers}});if(!U.ok)throw new Error(`Request failed: ${U.status}`);return U.json()},[a,h,r]),D=n.useCallback(async()=>{try{const t=f?`&status=${f}`:"",c=await w(`/admin/compliance/holders?limit=${u}&offset=0${t}`);i(c.holders||[])}catch(t){y.getLogger().error("[ComplianceSection] Failed to fetch holders:",t),i([]),x("Failed to load token holders")}finally{C(!1)}},[w,u,f]),E=n.useCallback(async()=>{try{const t=await w(`/admin/compliance/actions?limit=${u}&offset=0`);S(t.actions||[])}catch(t){y.getLogger().error("[ComplianceSection] Failed to fetch actions:",t),S([]),x("Failed to load compliance actions")}finally{d(!1)}},[w,u]),K=n.useCallback(async()=>{try{const t=await w("/admin/compliance/sweep-settings");O(t)}catch(t){y.getLogger().error("[ComplianceSection] Failed to fetch sweep settings:",t)}finally{Q(!1)}},[w]),Z=async()=>{Y(!0);try{await w("/admin/compliance/sweep-settings",{method:"PUT",body:JSON.stringify(B)})}catch(t){y.getLogger().error("[ComplianceSection] Failed to save sweep settings:",t),x("Failed to save sweep settings")}finally{Y(!1)}};n.useEffect(()=>{D()},[D]),n.useEffect(()=>{E()},[E]),n.useEffect(()=>{K()},[K]);const ee=async()=>{if(!(!g||!R.trim())){q(!0);try{const t=g.action==="freeze"?"/admin/compliance/freeze":"/admin/compliance/thaw";await w(t,{method:"POST",body:JSON.stringify({holderId:g.holder.id,reason:R})}),L(null),$(""),await D(),await E()}catch(t){y.getLogger().error(`[ComplianceSection] ${g.action} failed:`,t),x(`Failed to ${g.action} holder`)}finally{q(!1)}}},te=async()=>{z(!0);try{const t=new URLSearchParams;P&&t.set("from",new Date(P).toISOString()),W&&t.set("to",new Date(W).toISOString());const c=await w(`/admin/compliance/report?${t.toString()}`);l(c.report)}catch(t){y.getLogger().error("[ComplianceSection] Failed to generate report:",t),x("Failed to generate compliance report")}finally{z(!1)}},se=()=>{if(!s)return;const t=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),c=URL.createObjectURL(t),I=document.createElement("a");I.href=c,I.download=`compliance-report-${new Date().toISOString().slice(0,10)}.json`,I.click(),URL.revokeObjectURL(c)},ne=p.length,J=p.filter(t=>t.status==="frozen").length,ae=p.filter(t=>t.status==="active").length;return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(m.ErrorBanner,{message:A,onRetry:()=>{D(),E()}}),e.jsx(m.StatsBar,{stats:[{label:"Total Holders",value:ne},{label:"Active",value:ae,variant:"success"},{label:"Frozen",value:J,variant:J>0?"warning":"muted"},{label:"Actions Logged",value:j.length}],isLoading:N||T}),e.jsx("div",{className:"cedros-admin__tabs",style:{display:"flex",gap:"0.5rem",marginBottom:"1rem"},children:["holders","actions","reports","sweep-settings","sanctions-api","kyc"].map(t=>{const c=t==="holders"?"Token Holders":t==="actions"?"Actions Log":t==="reports"?"Reports":t==="sweep-settings"?"Sweep Settings":t==="sanctions-api"?"Sanctions API":"KYC & Accreditation";return e.jsx("button",{type:"button",className:`cedros-admin__button ${o===t?"cedros-admin__button--primary":"cedros-admin__button--ghost"}`,onClick:()=>b(t),children:c},t)})}),o==="holders"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__section-header",style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Token Holders"}),e.jsxs("select",{value:f,onChange:t=>{k(t.target.value),C(!0)},className:"cedros-admin__input",style:{width:"auto",padding:"0.25rem 0.5rem",fontSize:"0.85rem"},children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"frozen",children:"Frozen"}),e.jsx("option",{value:"thawed",children:"Thawed"})]})]}),N?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading holders..."]}):p.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No token holders found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Wallet"}),e.jsx("th",{children:"Collection"}),e.jsx("th",{children:"Mint"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Created"}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:p.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{title:t.walletAddress,children:_(t.walletAddress)})}),e.jsx("td",{children:e.jsx("code",{title:t.collectionId,children:_(t.collectionId)})}),e.jsx("td",{children:e.jsx("code",{title:t.mintAddress,children:_(t.mintAddress)})}),e.jsx("td",{children:t.amountMinted}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${ie(t.status)}`,children:t.status})}),e.jsx("td",{children:m.formatDateTime(t.createdAt)}),e.jsx("td",{children:t.status==="active"||t.status==="thawed"?e.jsx("button",{className:"cedros-admin__button cedros-admin__button--danger cedros-admin__button--sm",onClick:()=>{L({holder:t,action:"freeze"}),$("")},children:"Freeze"}):t.status==="frozen"?e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",onClick:()=>{L({holder:t,action:"thaw"}),$("")},children:"Thaw"}):null})]},t.id))})]})})]}),o==="actions"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Compliance Actions"})}),T?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading actions..."]}):j.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No compliance actions recorded."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Timestamp"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Wallet"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Actor"}),e.jsx("th",{children:"Tx Signature"})]})}),e.jsx("tbody",{children:j.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:m.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${G(t.actionType)}`,children:t.actionType})}),e.jsx("td",{children:e.jsx("code",{title:t.walletAddress,children:_(t.walletAddress)})}),e.jsx("td",{children:t.reason||"—"}),e.jsx("td",{children:e.jsx("code",{children:_(t.actor)})}),e.jsx("td",{children:t.txSignature?e.jsx("a",{href:`${ce}${t.txSignature}`,target:"_blank",rel:"noopener noreferrer",className:"cedros-admin__link",children:_(t.txSignature)}):"—"})]},t.id))})]})})]}),o==="reports"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Compliance Report"})}),e.jsxs("div",{style:{display:"flex",gap:"0.75rem",alignItems:"flex-end",marginBottom:"1rem"},children:[e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["From",e.jsx("input",{type:"date",className:"cedros-admin__input",value:P,onChange:t=>V(t.target.value)})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["To",e.jsx("input",{type:"date",className:"cedros-admin__input",value:W,onChange:t=>X(t.target.value)})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:te,disabled:v,children:v?"Generating...":"Generate Report"})]}),s&&e.jsxs("div",{children:[e.jsx(m.StatsBar,{stats:[{label:"Total Holders",value:s.totalHolders},{label:"Frozen",value:s.totalFrozen,variant:s.totalFrozen>0?"warning":"muted"},{label:"Freezes",value:s.freezeCount},{label:"Thaws",value:s.thawCount},{label:"Sweep Freezes",value:s.sweepFreezeCount,variant:s.sweepFreezeCount>0?"warning":"muted"}],isLoading:!1}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",margin:"1rem 0 0.5rem"},children:[e.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)"},children:["Generated ",m.formatDateTime(s.generatedAt)," · ",s.actionsInPeriod," actions in period"]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:se,children:"Download JSON"})]}),s.actions.length>0&&e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Timestamp"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Wallet"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Actor"})]})}),e.jsx("tbody",{children:s.actions.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:m.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${G(t.actionType)}`,children:t.actionType})}),e.jsx("td",{children:e.jsx("code",{title:t.walletAddress,children:_(t.walletAddress)})}),e.jsx("td",{children:t.reason||"—"}),e.jsx("td",{children:e.jsx("code",{children:_(t.actor)})})]},t.id))})]})})]})]}),o==="sweep-settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Sanctions Sweep Settings"})}),M?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading settings..."]}):e.jsxs("div",{style:{maxWidth:"400px",display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.9rem"},children:[e.jsx("input",{type:"checkbox",checked:B.enabled,onChange:t=>O(c=>({...c,enabled:t.target.checked}))}),"Enable automated sanctions sweep"]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["Batch size (1 – 10,000)",e.jsx("input",{type:"number",className:"cedros-admin__input",min:1,max:1e4,value:B.batchSize,onChange:t=>O(c=>({...c,batchSize:Number(t.target.value)})),style:{width:"160px"}})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:Z,disabled:H,style:{alignSelf:"flex-start"},children:H?"Saving...":"Save Settings"})]})]}),o==="sanctions-api"&&e.jsx(oe,{serverUrl:a,apiKey:h,authManager:r}),o==="kyc"&&e.jsx(le,{serverUrl:a,apiKey:h,authManager:r}),g&&e.jsx("div",{className:"cedros-admin__modal-overlay",onClick:()=>!F&&L(null),children:e.jsxs("div",{className:"cedros-admin__modal",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"cedros-admin__modal-header",children:[e.jsxs("h4",{className:"cedros-admin__modal-title",children:[g.action==="freeze"?"Freeze":"Thaw"," Token Account"]}),e.jsx("button",{type:"button",className:"cedros-admin__modal-close",onClick:()=>!F&&L(null),children:m.Icons.close})]}),e.jsxs("div",{className:"cedros-admin__modal-body",children:[e.jsxs("p",{style:{marginBottom:"0.5rem",fontSize:"0.9rem"},children:["Wallet: ",e.jsx("code",{children:_(g.holder.walletAddress)})]}),e.jsxs("p",{style:{marginBottom:"0.75rem",fontSize:"0.9rem"},children:["Mint: ",e.jsx("code",{children:_(g.holder.mintAddress)})]}),e.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.85rem"},children:["Reason (required)",e.jsx("textarea",{className:"cedros-admin__input",rows:3,value:R,onChange:t=>$(t.target.value),placeholder:`Reason for ${g.action}...`,maxLength:1024})]})]}),e.jsxs("div",{className:"cedros-admin__modal-footer",children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>L(null),disabled:F,children:"Cancel"}),e.jsx("button",{className:`cedros-admin__button ${g.action==="freeze"?"cedros-admin__button--danger":"cedros-admin__button--primary"}`,onClick:ee,disabled:F||!R.trim(),children:F?"Processing...":g.action==="freeze"?"Freeze Account":"Thaw Account"})]})]})})]})}exports.ComplianceSection=me;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const p=require("react/jsx-runtime"),a=require("react"),ce=require("@solana/wallet-adapter-react"),le=require("@solana/wallet-adapter-base"),be=require("@solana/wallet-adapter-react-ui"),i=require("./styles-BT4bhFey.js"),t=require("./CedrosContext-C2RjHLaQ.js");function ie(){const{x402Manager:C,walletManager:l}=t.useCedrosContext(),{publicKey:W,signTransaction:j}=ce.useWallet(),[N,y]=a.useState({status:"idle",error:null,transactionId:null}),[R,L]=a.useState(null),[K,k]=a.useState(null),P=a.useRef(W);P.current=W;const h=a.useRef(j);h.current=j;const g=a.useRef(0),X=6e4,I=()=>{const o=g.current;return o>0&&Date.now()-o<X},S=a.useCallback(()=>{if(!W){const o="Wallet not connected";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}if(!j){const o="Wallet does not support signing";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}return{valid:!0}},[W,j]),q=a.useCallback(async o=>{try{y(d=>({...d,status:"loading"}));const c=await C.requestQuote({resource:o});if(!C.validateRequirement(c))throw new Error("Invalid requirement received from server");return L(c),y(d=>({...d,status:"idle"})),c}catch(c){const d=t.formatError(c,"Failed to fetch requirement");throw y({status:"error",error:d,transactionId:null}),c}},[C]),B=a.useCallback(async(o,c,d,x,n="regular")=>{const s=P.current,m=h.current;if(!s||!m)throw new Error("Wallet disconnected during payment flow");if(!!o.extra?.feePayer){t.getLogger().debug("[useX402Payment] Gasless flow enabled"),t.getLogger().debug("[useX402Payment] Building gasless transaction");const{transaction:b,blockhash:M}=await C.buildGaslessTransaction({resourceId:c,userWallet:s.toString(),feePayer:o.extra.feePayer,couponCode:d});t.getLogger().debug("[useX402Payment] Deserializing backend transaction");const A=l.deserializeTransaction(b);if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");t.getLogger().debug("[useX402Payment] Requesting partial signature");const E=await l.partiallySignTransaction({transaction:A,signTransaction:m,blockhash:M});t.getLogger().debug("[useX402Payment] Submitting partial transaction");const z=await C.submitGaslessTransaction({resource:c,partialTx:E,couponCode:d,metadata:x,resourceType:n,requirement:o});return z.success&&z.settlement&&k(z.settlement),z}else{const b=await l.buildTransaction({requirement:o,payerPublicKey:s});if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");const M=await l.signTransaction({transaction:b,signTransaction:m}),A=l.buildPaymentPayload({requirement:o,signedTx:M,payerPublicKey:s}),E=await C.submitPayment({resource:c,payload:A,couponCode:d,metadata:x,resourceType:n});return E.success&&E.settlement&&k(E.settlement),E}},[C,l]),w=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{t.getLogger().debug("[useX402Payment] Fetching fresh quote");const n=await C.requestQuote({resource:o,couponCode:c});t.getLogger().debug("[useX402Payment] Received quote",{amount:n.maxAmountRequired}),L(n),t.getLogger().debug("[useX402Payment] Executing payment flow");const s=await B(n,o,c,d,"regular");return s.success?y({status:"success",error:null,transactionId:s.transactionId||"payment-success"}):y({status:"error",error:s.error||"Payment failed",transactionId:null}),s}catch(n){const s=t.formatError(n,"Payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),_=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{const n=i.normalizeCartItems(o),s=await C.requestCartQuote({items:n,metadata:c,couponCode:d}),m=s.cartId,u=s.quote;if(!C.validateRequirement(u))throw new Error("Invalid cart quote received from server");L(u);const b=await B(u,m,d,c,"cart");return b.success?y({status:"success",error:null,transactionId:b.transactionId||"cart-payment-success"}):y({status:"error",error:b.error||"Cart payment failed",transactionId:null}),b}catch(n){const s=t.formatError(n,"Cart payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),T=a.useCallback(()=>{y({status:"idle",error:null,transactionId:null}),L(null),k(null),g.current=0},[]);return{...N,requirement:R,settlement:K,fetchQuote:q,processPayment:w,processCartPayment:_,reset:T}}function ue({resource:C,items:l,label:W,disabled:j=!1,onAttempt:N,onSuccess:y,onError:R,className:L="",testPageUrl:K,hideMessages:k=!1,metadata:P,couponCode:h}){const{connected:g,connecting:X,connect:I,disconnect:S,select:q,wallets:B,wallet:w,publicKey:_}=ce.useWallet(),{status:T,error:o,transactionId:c,processPayment:d,processCartPayment:x}=ie(),n=t.useCedrosTheme(),{solanaError:s}=t.useCedrosContext(),{isCartMode:m,effectiveResource:u}=i.usePaymentMode(C,l),{t:b,translations:M}=i.useTranslation(),A=W||b("ui.pay_with_crypto"),E=o&&typeof o!="string"?o?.code??null:null,z=s&&typeof s!="string"?s?.code??null:null,U=e=>{if(!e||!M)return"";const r=M.errors[e];return r?r.action?`${r.message} ${r.action}`:r.message:""},Y=o?typeof o=="string"?o:U(E):null,H=s?typeof s=="string"?s:U(z):null,J=a.useRef(y),V=a.useRef(R),Z=a.useRef(d),ee=a.useRef(x);J.current=y,V.current=R,Z.current=d,ee.current=x;const de=a.useMemo(()=>B.map(e=>`${e.adapter.name}-${e.readyState}`).join(","),[B]),G=a.useMemo(()=>B.filter(({readyState:e})=>e===le.WalletReadyState.Installed||e===le.WalletReadyState.Loadable),[de]);a.useEffect(()=>{if(T==="success"&&c){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentSuccess("crypto",c,u,e),J.current?.(c)}},[T,c,m,l,u]),a.useEffect(()=>{if(T==="error"&&o){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentError("crypto",o,u,e),V.current?.(o)}},[T,o,m,l,u]);const te=typeof window<"u"&&window.top!==window.self,[re,$]=a.useState(!1),[ne,Q]=a.useState(!1),[D,v]=a.useState(null),F=s;a.useEffect(()=>{let e=!1;return e||(async()=>{if(ne&&w&&!g&&!X){t.getLogger().debug("[CryptoButton] Wallet detected, attempting auto-connect:",w.adapter.name),Q(!1),i.emitWalletConnect(w.adapter.name);try{await I(),e||t.getLogger().debug("[CryptoButton] Auto-connect successful")}catch(f){if(!e){t.getLogger().error("[CryptoButton] Auto-connect failed:",f);const O=f instanceof Error?f.message:"Failed to connect wallet";i.emitWalletError(O,w.adapter.name),v(null)}}}})(),()=>{e=!0}},[w,ne,g,X,I]),a.useEffect(()=>{let e=!0;if(t.getLogger().debug("[CryptoButton] Payment useEffect triggered",{connected:g,hasPendingPayment:!!D,hasPublicKey:!!_,pendingPaymentType:D?.type}),g&&D&&_&&w&&e){i.emitWalletConnected(w.adapter.name,_.toString()),t.getLogger().debug("[CryptoButton] All conditions met! Processing pending payment:",D);const r=D;v(null),$(!1);const f=r.type==="cart"&&r.items?i.getCartItemCount(r.items):void 0;i.emitPaymentProcessing("crypto",r.resource,f),r.type==="cart"&&r.items?(t.getLogger().debug("[CryptoButton] Auto-processing cart payment"),ee.current(r.items,r.metadata,r.couponCode)):r.type==="single"&&r.resource&&(t.getLogger().debug("[CryptoButton] Auto-processing single payment"),Z.current(r.resource,r.couponCode,r.metadata))}return()=>{e=!1}},[g,D,_,w]);const oe=a.useCallback(async()=>{t.getLogger().debug("[CryptoButton] executePaymentFlow called",{connected:g,wallet:w?.adapter.name,couponCode:h,isCartMode:m,hasItems:!!l,effectiveResource:u});const e=m&&l?i.getCartItemCount(l):void 0;if(i.emitPaymentStart("crypto",u,e),N&&N("crypto"),F){t.getLogger().error("[CryptoButton] Solana dependencies missing:",F),i.emitPaymentError("crypto",F,u,e),R&&R(F);return}if(te){const r=K||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(f){throw t.getLogger().error("[CryptoButton] URL validation failed:",f),f}return}if(g)i.emitPaymentProcessing("crypto",u,e),m&&l?(t.getLogger().debug("[CryptoButton] Processing cart payment with coupon:",h),await x(l,P,h)):u&&(t.getLogger().debug("[CryptoButton] Processing single payment with coupon:",h),await d(u,h,P));else{let r=!1;if(m&&l?(t.getLogger().debug("[CryptoButton] Setting pending cart payment with coupon:",h),v({type:"cart",items:l,metadata:P,couponCode:h}),r=!0):u&&(t.getLogger().debug("[CryptoButton] Setting pending single payment with coupon:",h),v({type:"single",resource:u,metadata:P,couponCode:h}),r=!0),!r){t.getLogger().error("[CryptoButton] No valid payment to process");return}try{if(w)t.getLogger().debug("[CryptoButton] Wallet already selected, connecting:",w.adapter.name),i.emitWalletConnect(w.adapter.name),await I();else{if(t.getLogger().debug("[CryptoButton] No wallet selected, showing selector. Available wallets:",G.map(f=>f.adapter.name)),G.length===0){v(null);const f="No wallets available";throw i.emitWalletError(f),new Error(f)}$(!0)}}catch(f){v(null);const O=f instanceof Error?f.message:"Failed to connect wallet";t.getLogger().error("[CryptoButton] Connection error:",O),i.emitWalletError(O,w?.adapter.name)}}},[g,w,h,m,l,u,te,K,G,I,P,x,d,F,N,R]),ae=a.useMemo(()=>m&&l?`crypto-cart-${l.map(e=>e.resource).join("-")}`:`crypto-${u||"unknown"}`,[m,l,u]),ge=a.useMemo(()=>i.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=T==="loading",ye=j||se||X||!!F,me=se?b("ui.processing"):A,fe=a.useCallback(async()=>{try{Q(!1),g&&await S(),q(null),$(!0)}catch(e){t.getLogger().error("Failed to change wallet:",e)}},[g,S,q]),pe=a.useCallback(e=>{t.getLogger().debug("[CryptoButton] Wallet clicked:",e),$(!1),q(e),Q(!0),t.getLogger().debug("[CryptoButton] Wallet selected, useEffect will auto-connect")},[q]),we=a.useCallback(async()=>{try{if(await S(),v(null),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(e){e instanceof Error&&e.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",e)}}catch(e){t.getLogger().error("Failed to disconnect wallet:",e)}},[S]);return p.jsxs("div",{className:n.unstyled?L:`${n.className} cedros-theme__crypto-button ${L||""}`,style:n.unstyled?{}:n.style,children:[p.jsx("button",{onClick:ge,disabled:ye,className:n.unstyled?L:"cedros-theme__button cedros-theme__crypto",type:"button",children:me}),re&&!k&&p.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:n.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>{$(!1),v(null)},children:p.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:n.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 ${n.tokens.modalBorder}`},onClick:e=>e.stopPropagation(),children:[p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[p.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:n.tokens.surfaceText},children:b("wallet.select_wallet")}),p.jsx("button",{onClick:()=>{$(!1),v(null)},style:i.getModalCloseButtonStyles(n.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),p.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:G.map(e=>p.jsxs("button",{onClick:()=>pe(e.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:n.tokens.surfaceBackground,border:`1px solid ${n.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:n.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:r=>{r.currentTarget.style.backgroundColor=n.tokens.modalBackground,r.currentTarget.style.borderColor=n.tokens.surfaceText,r.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:r=>{r.currentTarget.style.backgroundColor=n.tokens.surfaceBackground,r.currentTarget.style.borderColor=n.tokens.surfaceBorder,r.currentTarget.style.transform="translateY(0)"},type:"button",children:[p.jsx(be.WalletIcon,{wallet:e,style:{width:"24px",height:"24px"}}),p.jsx("span",{style:{fontWeight:500},children:e.adapter.name})]},e.adapter.name))})]})}),g&&!k&&!re&&p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:n.tokens.surfaceText,opacity:.7},children:[p.jsx("button",{onClick:fe,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("wallet.change")}),p.jsx("button",{onClick:we,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("ui.disconnect")})]}),!k&&H&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:H}),!k&&Y&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:Y}),!k&&c&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__success",children:b("ui.payment_successful")})]})}const Ce=Object.freeze(Object.defineProperty({__proto__:null,CryptoButton:ue},Symbol.toStringTag,{value:"Module"}));exports.CryptoButton=ue;exports.CryptoButton$1=Ce;exports.useX402Payment=ie;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),y=require("./index-C0g-JxJk.js");function q({serverUrl:g,apiKey:h,pageSize:i=20,authManager:x}){const[_,C]=n.useState([]),[A,N]=n.useState(!0),[F,l]=n.useState(null),[o,v]=n.useState(0),[D,p]=n.useState(!1),[S,w]=n.useState(!1),[r,E]=n.useState(null),[c,I]=n.useState(""),[a,d]=n.useState({email:"",name:"",phone:""}),m=n.useCallback(async(t,s)=>{if(x?.isAuthenticated())return x.fetchWithAuth(t,s);const k={"Content-Type":"application/json"};h&&(k["X-API-Key"]=h);const b=await fetch(`${g}${t}`,{...s,headers:{...k,...s?.headers}});if(!b.ok)throw new Error(`Request failed: ${b.status}`);return b.json()},[g,h,x]),f=n.useCallback(async()=>{N(!0),l(null);try{const t=await m(`/admin/customers?limit=${i}&offset=${o}`);C(t.customers??[])}catch{l("Failed to load customers"),C([])}finally{N(!1)}},[m,i,o]);n.useEffect(()=>{f()},[f]);const j=()=>{d({email:"",name:"",phone:""}),E(null),p(!1)},L=t=>{E(t),d({email:t.email,name:t.name??"",phone:t.phone??""}),p(!0)},P=async t=>{t.preventDefault(),w(!0),l(null);try{r?await m(`/admin/customers/${encodeURIComponent(r.id)}`,{method:"PUT",body:JSON.stringify({email:a.email,name:a.name||null,phone:a.phone||null,addresses:r.addresses})}):await m("/admin/customers",{method:"POST",body:JSON.stringify({email:a.email,name:a.name||null,phone:a.phone||null,addresses:[]})}),j(),f()}catch(s){l(s instanceof Error?s.message:"Failed to save customer")}finally{w(!1)}},u=c.trim()?_.filter(t=>{const s=c.toLowerCase();return t.email.toLowerCase().includes(s)||(t.name??"").toLowerCase().includes(s)||t.id.toLowerCase().includes(s)}):_,T=t=>[t.line1,t.city,t.state,t.postalCode,t.country].filter(Boolean).join(", ");return e.jsxs("div",{children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Customers"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:()=>{j(),p(!0)},children:"+ Add Customer"})]}),e.jsx(y.ErrorBanner,{message:F}),e.jsx("div",{style:{marginBottom:"1rem",maxWidth:"400px"},children:e.jsx("input",{type:"text",className:"cedros-admin__input",placeholder:"Search by email, name, or ID...",value:c,onChange:t=>I(t.target.value),style:{fontSize:"0.85rem"}})}),D&&e.jsxs("form",{onSubmit:P,style:{border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",padding:"1rem",marginBottom:"1.5rem",maxWidth:"500px"},children:[e.jsx("h4",{style:{margin:"0 0 0.75rem",fontSize:"0.9rem",fontWeight:600},children:r?"Edit Customer":"New Customer"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Email *"}),e.jsx("input",{type:"email",className:"cedros-admin__input",value:a.email,onChange:t=>d(s=>({...s,email:t.target.value})),required:!0,placeholder:"customer@example.com"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Name"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.name,onChange:t=>d(s=>({...s,name:t.target.value})),placeholder:"Jane Doe"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Phone"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.phone,onChange:t=>d(s=>({...s,phone:t.target.value})),placeholder:"+1 555 123 4567"})]})]}),e.jsxs("div",{style:{marginTop:"0.75rem",display:"flex",gap:"0.5rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:S,children:S?"Saving...":r?"Update":"Create"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:j,children:"Cancel"})]})]}),A?e.jsxs("div",{className:"cedros-admin__loading",children:[y.Icons.loading," Loading customers..."]}):u.length===0?e.jsx("div",{className:"cedros-admin__empty",children:c?"No matching customers.":"No customers found."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Email"}),e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Phone"}),e.jsx("th",{children:"Address"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:u.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:t.email}),e.jsx("td",{children:t.name??e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"—"})}),e.jsx("td",{children:t.phone??e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"—"})}),e.jsx("td",{style:{fontSize:"0.8rem",maxWidth:"200px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.addresses.length>0?T(t.addresses[0]):"—"}),e.jsx("td",{children:y.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>L(t),children:"Edit"})})]},t.id))})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:o===0,onClick:()=>v(Math.max(0,o-i)),children:"Previous"}),e.jsxs("span",{children:["Showing ",u.length," customer",u.length!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:_.length<i,onClick:()=>v(o+i),children:"Next"})]})]})]})}exports.CustomersSection=q;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),l=require("./index-C0g-JxJk.js"),I=d=>{switch(d){case"won":return"success";case"lost":return"failed";case"needs_response":case"warning_needs_response":return"pending";default:return"muted"}},C=(d,i)=>`${i.toUpperCase()} ${(d/100).toFixed(2)}`;function k({serverUrl:d,apiKey:i,pageSize:a=20,authManager:j}){const[r,y]=s.useState([]),[W,b]=s.useState(!0),[D,o]=s.useState(null),[c,p]=s.useState(0),[h,U]=s.useState("all"),[u,_]=s.useState(null),[m,v]=s.useState(""),[S,N]=s.useState(!1),x=s.useCallback(async(t,n)=>{if(j?.isAuthenticated())return j.fetchWithAuth(t,n);const w={"Content-Type":"application/json"};i&&(w["X-API-Key"]=i);const g=await fetch(`${d}${t}`,{...n,headers:{...w,...n?.headers}});if(!g.ok)throw new Error(`Request failed: ${g.status}`);return g.json()},[d,i,j]),f=s.useCallback(async()=>{b(!0),o(null);try{const t=new URLSearchParams;t.set("limit",String(a)),t.set("offset",String(c)),h!=="all"&&t.set("status",h);const n=await x(`/admin/disputes?${t.toString()}`);y(n.disputes??[])}catch{o("Failed to load disputes"),y([])}finally{b(!1)}},[x,a,c,h]);s.useEffect(()=>{f()},[f]);const A=async t=>{try{const n=await x(`/admin/disputes/${encodeURIComponent(t)}`);_(n),v(n.status)}catch{o("Failed to load dispute details")}},R=async()=>{if(!(!u||!m.trim())){N(!0);try{const t=await x(`/admin/disputes/${encodeURIComponent(u.id)}/status`,{method:"PUT",body:JSON.stringify({status:m})});_(t),f()}catch{o("Failed to update dispute status")}finally{N(!1)}}};if(u){const t=u;return e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>_(null),style:{marginBottom:"1rem"},children:"← Back to disputes"}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsxs("h3",{className:"cedros-admin__section-title",children:["Dispute ",e.jsx("code",{style:{fontSize:"0.8rem"},children:t.id.slice(0,12)})]})}),e.jsx("div",{className:"cedros-admin__table-container",style:{maxWidth:"500px"},children:e.jsx("table",{className:"cedros-admin__table",children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600,width:"35%"},children:"Status"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I(t.status)}`,children:t.status})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Amount"}),e.jsx("td",{children:C(t.amount,t.currency)})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Source"}),e.jsx("td",{children:t.source})]}),t.reason&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Reason"}),e.jsx("td",{children:t.reason})]}),t.orderId&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Order ID"}),e.jsx("td",{children:e.jsx("code",{children:t.orderId})})]}),t.chargeId&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Charge ID"}),e.jsx("td",{children:e.jsx("code",{children:t.chargeId})})]}),t.paymentIntentId&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Payment Intent"}),e.jsx("td",{children:e.jsx("code",{children:t.paymentIntentId})})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Created"}),e.jsx("td",{children:l.formatDateTime(t.createdAt)})]}),t.statusUpdatedAt&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Status Updated"}),e.jsx("td",{children:l.formatDateTime(t.statusUpdatedAt)})]})]})})}),e.jsxs("div",{style:{marginTop:"1rem",display:"flex",gap:"0.5rem",alignItems:"flex-end",maxWidth:"400px"},children:[e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Update Status"}),e.jsxs("select",{className:"cedros-admin__input",value:m,onChange:n=>v(n.target.value),children:[e.jsx("option",{value:"needs_response",children:"Needs Response"}),e.jsx("option",{value:"under_review",children:"Under Review"}),e.jsx("option",{value:"won",children:"Won"}),e.jsx("option",{value:"lost",children:"Lost"}),e.jsx("option",{value:"warning_closed",children:"Warning Closed"})]})]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:R,disabled:S||m===t.status,children:S?"Updating...":"Update"})]})]})}return e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Disputes & Chargebacks"})}),e.jsx(l.ErrorBanner,{message:D}),e.jsx("div",{style:{display:"flex",gap:"0.5rem",marginBottom:"1rem",alignItems:"center"},children:e.jsxs("select",{className:"cedros-admin__input",value:h,onChange:t=>{U(t.target.value),p(0)},style:{width:"auto",fontSize:"0.85rem"},children:[e.jsx("option",{value:"all",children:"All statuses"}),e.jsx("option",{value:"needs_response",children:"Needs Response"}),e.jsx("option",{value:"under_review",children:"Under Review"}),e.jsx("option",{value:"won",children:"Won"}),e.jsx("option",{value:"lost",children:"Lost"})]})}),W?e.jsxs("div",{className:"cedros-admin__loading",children:[l.Icons.loading," Loading disputes..."]}):r.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No disputes found."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"ID"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Source"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:r.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{style:{fontSize:"0.75rem"},children:t.id.slice(0,12)})}),e.jsx("td",{children:C(t.amount,t.currency)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I(t.status)}`,children:t.status})}),e.jsx("td",{children:t.reason??"—"}),e.jsx("td",{children:t.source}),e.jsx("td",{children:l.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>A(t.id),children:"View"})})]},t.id))})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:c===0,onClick:()=>p(Math.max(0,c-a)),children:"Previous"}),e.jsxs("span",{children:["Showing ",r.length," dispute",r.length!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:r.length<a,onClick:()=>p(c+a),children:"Next"})]})]})]})}exports.DisputesSection=k;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),d=require("./index-C0g-JxJk.js");function R({serverUrl:h,apiKey:o,pageSize:g=20,authManager:r}){const[u,N]=c.useState([]),[Q,w]=c.useState(!0),[S,f]=c.useState(!1),[p,A]=c.useState(null),[F,C]=c.useState(!1),[x,P]=c.useState(""),[v,O]=c.useState("all"),[q,b]=c.useState(null),[$,j]=c.useState(null),[n,l]=c.useState({question:"",answer:"",keywordsCsv:"",active:!0,useInChat:!0,displayOnPage:!0}),_=c.useCallback(async()=>{w(!0);try{j(null);let s;const t=`/admin/faqs?limit=${g}`;if(r?.isAuthenticated())s=await r.fetchWithAuth(t);else{const i={"Content-Type":"application/json"};o&&(i["X-API-Key"]=o);const a=await fetch(`${h}${t}`,{headers:i});if(!a.ok)throw new Error(`Failed to fetch FAQs: ${a.status}`);s=await a.json()}N(s.faqs||[])}catch{N([]),j("Failed to load FAQs")}finally{w(!1)}},[h,o,g,r]);c.useEffect(()=>{_()},[_]);const E=async s=>{if(s.preventDefault(),!(!n.question.trim()||!n.answer.trim())){C(!0);try{const t=n.keywordsCsv.split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),i={question:n.question.trim(),answer:n.answer.trim(),keywords:t,active:n.active,useInChat:n.useInChat,displayOnPage:n.displayOnPage};if(p){const a=`/admin/faqs/${p.id}`;if(r?.isAuthenticated())await r.fetchWithAuth(a,{method:"PUT",body:JSON.stringify(i)});else{const m={"Content-Type":"application/json"};o&&(m["X-API-Key"]=o);const I=await fetch(`${h}${a}`,{method:"PUT",headers:m,body:JSON.stringify(i)});if(!I.ok)throw new Error(`Failed to update FAQ: ${I.status}`)}}else if(r?.isAuthenticated())await r.fetchWithAuth("/admin/faqs",{method:"POST",body:JSON.stringify(i)});else{const a={"Content-Type":"application/json"};o&&(a["X-API-Key"]=o);const m=await fetch(`${h}/admin/faqs`,{method:"POST",headers:a,body:JSON.stringify(i)});if(!m.ok)throw new Error(`Failed to create FAQ: ${m.status}`)}y(),_()}catch{j(p?"Failed to update FAQ":"Failed to create FAQ")}finally{C(!1)}}},T=async s=>{try{const t=`/admin/faqs/${s}`;if(r?.isAuthenticated())await r.fetchWithAuth(t,{method:"DELETE"});else{const i={"Content-Type":"application/json"};o&&(i["X-API-Key"]=o);const a=await fetch(`${h}${t}`,{method:"DELETE",headers:i});if(!a.ok)throw new Error(`Failed to delete FAQ: ${a.status}`)}_()}catch{j("Failed to delete FAQ")}b(null)},D=async s=>{try{const t=`/admin/faqs/${s.id}`,i={...s,active:!s.active};if(r?.isAuthenticated())await r.fetchWithAuth(t,{method:"PUT",body:JSON.stringify(i)});else{const a={"Content-Type":"application/json"};o&&(a["X-API-Key"]=o);const m=await fetch(`${h}${t}`,{method:"PUT",headers:a,body:JSON.stringify(i)});if(!m.ok)throw new Error(`Failed to update FAQ: ${m.status}`)}_()}catch{j("Failed to update FAQ status")}},y=()=>{l({question:"",answer:"",keywordsCsv:"",active:!0,useInChat:!0,displayOnPage:!0}),A(null),f(!1)},L=s=>{l({question:s.question,answer:s.answer,keywordsCsv:s.keywords.join(", "),active:s.active,useInChat:s.useInChat??!0,displayOnPage:s.displayOnPage??!0}),A(s),f(!0)},W=u.length,B=u.filter(s=>s.active).length,J=u.filter(s=>s.active&&s.useInChat).length,X=u.filter(s=>s.active&&s.displayOnPage).length,k=c.useMemo(()=>u.filter(s=>{if(v==="active"&&!s.active||v==="inactive"&&s.active)return!1;if(x){const t=x.toLowerCase();return s.question.toLowerCase().includes(t)||s.answer.toLowerCase().includes(t)||s.keywords.some(i=>i.includes(t))}return!0}),[u,v,x]);return e.jsxs("div",{className:"cedros-admin__faqs",children:[e.jsx(d.ErrorBanner,{message:$,onRetry:_}),e.jsx(d.StatsBar,{stats:[{label:"Total FAQs",value:W},{label:"Active",value:B,variant:"success"},{label:"In Chat",value:J},{label:"On Page",value:X}]}),e.jsxs("div",{className:"cedros-admin__section",children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsxs("div",{className:"cedros-admin__section-header-left",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Knowledge Base"}),e.jsx("p",{className:"cedros-admin__section-subtitle",children:"Manage FAQs for the AI chat assistant and public FAQ page."})]}),e.jsx("div",{className:"cedros-admin__section-header-right",children:e.jsxs("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:()=>{y(),f(!0)},children:[d.Icons.plus," Add FAQ"]})})]}),e.jsxs("div",{className:"cedros-admin__filters",style:{display:"flex",gap:"1rem",marginBottom:"1rem"},children:[e.jsx("input",{type:"text",placeholder:"Search FAQs...",value:x,onChange:s=>P(s.target.value),className:"cedros-admin__input",style:{flex:1,maxWidth:300}}),e.jsxs("select",{value:v,onChange:s=>O(s.target.value),className:"cedros-admin__select",children:[e.jsx("option",{value:"all",children:"All Status"}),e.jsx("option",{value:"active",children:"Active Only"}),e.jsx("option",{value:"inactive",children:"Inactive Only"})]})]}),S&&e.jsx("div",{className:"cedros-admin__form-container",style:{marginBottom:"1.5rem"},children:e.jsxs("form",{onSubmit:E,className:"cedros-admin__form",children:[e.jsxs("div",{className:"cedros-admin__form-header",children:[e.jsx("h4",{children:p?"Edit FAQ":"Add New FAQ"}),e.jsx("button",{type:"button",className:"cedros-admin__button--icon",onClick:y,children:d.Icons.close})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Question *"}),e.jsx("input",{type:"text",value:n.question,onChange:s=>l(t=>({...t,question:s.target.value})),className:"cedros-admin__input",placeholder:"What is your return policy?",required:!0})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Answer *"}),e.jsx("textarea",{value:n.answer,onChange:s=>l(t=>({...t,answer:s.target.value})),className:"cedros-admin__textarea",placeholder:"We accept returns within 30 days...",rows:4,required:!0}),e.jsx("span",{className:"cedros-admin__hint",children:"Supports markdown formatting."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Keywords"}),e.jsx("input",{type:"text",value:n.keywordsCsv,onChange:s=>l(t=>({...t,keywordsCsv:s.target.value})),className:"cedros-admin__input",placeholder:"returns, refund, policy"}),e.jsx("span",{className:"cedros-admin__hint",children:"Comma-separated keywords to help AI find this FAQ."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.active,onChange:s=>l(t=>({...t,active:s.target.checked}))}),e.jsx("span",{children:"Active"})]}),e.jsx("span",{className:"cedros-admin__hint",children:"Inactive FAQs won't appear anywhere."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Visibility"}),e.jsxs("div",{className:"cedros-admin__checkbox-group",children:[e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.useInChat,onChange:s=>l(t=>({...t,useInChat:s.target.checked}))}),e.jsx("span",{children:"Use in AI Chat"})]}),e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.displayOnPage,onChange:s=>l(t=>({...t,displayOnPage:s.target.checked}))}),e.jsx("span",{children:"Display on FAQ Page"})]})]}),e.jsx("span",{className:"cedros-admin__hint",children:"Choose where this FAQ should appear."})]}),e.jsxs("div",{className:"cedros-admin__form-actions",children:[e.jsx("button",{type:"button",className:"cedros-admin__button",onClick:y,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:F||!n.question.trim()||!n.answer.trim(),children:F?d.Icons.loading:p?"Update FAQ":"Create FAQ"})]})]})}),Q?e.jsxs("div",{className:"cedros-admin__loading",children:[d.Icons.loading,e.jsx("span",{children:"Loading FAQs..."})]}):k.length===0?e.jsx("div",{className:"cedros-admin__empty",children:e.jsx("p",{children:x||v!=="all"?"No FAQs match your filters.":"No FAQs yet. Add one to get started."})}):e.jsx("div",{className:"cedros-admin__faq-list",children:k.map(s=>e.jsxs("div",{className:`cedros-admin__faq-item ${s.active?"":"cedros-admin__faq-item--inactive"}`,children:[e.jsxs("div",{className:"cedros-admin__faq-content",children:[e.jsxs("div",{className:"cedros-admin__faq-question",children:[e.jsx("span",{className:`cedros-admin__status-dot ${s.active?"cedros-admin__status-dot--active":"cedros-admin__status-dot--inactive"}`}),s.question]}),e.jsx("div",{className:"cedros-admin__faq-answer",children:s.answer}),e.jsxs("div",{className:"cedros-admin__faq-meta",children:[s.keywords.length>0&&e.jsx("div",{className:"cedros-admin__faq-keywords",children:s.keywords.map(t=>e.jsx("span",{className:"cedros-admin__tag",children:t},t))}),e.jsxs("div",{className:"cedros-admin__faq-visibility",children:[s.useInChat&&e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--chat",title:"Used in AI Chat",children:[d.Icons.chat," Chat"]}),s.displayOnPage&&e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--page",title:"Displayed on FAQ Page",children:[d.Icons.globe," Page"]})]})]})]}),e.jsxs("div",{className:"cedros-admin__faq-actions",children:[e.jsx("button",{className:"cedros-admin__button--icon",onClick:()=>D(s),title:s.active?"Deactivate":"Activate",children:s.active?d.Icons.eyeOff:d.Icons.eye}),e.jsx("button",{className:"cedros-admin__button--icon",onClick:()=>L(s),title:"Edit",children:d.Icons.edit}),e.jsx("button",{className:"cedros-admin__button--icon cedros-admin__btn--danger",onClick:()=>b(s.id),title:"Delete",children:d.Icons.trash})]}),q===s.id&&e.jsx("div",{className:"cedros-admin__confirm-overlay",children:e.jsxs("div",{className:"cedros-admin__confirm-dialog",children:[e.jsx("p",{children:"Delete this FAQ?"}),e.jsxs("div",{className:"cedros-admin__confirm-actions",children:[e.jsx("button",{className:"cedros-admin__button",onClick:()=>b(null),children:"Cancel"}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--danger",onClick:()=>T(s.id),children:"Delete"})]})]})})]},s.id))})]})]})}exports.FAQSection=R;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("react"),u=require("./index-C0g-JxJk.js"),v=require("./CedrosContext-C2RjHLaQ.js");async function E(s,l,n,c){const o=new FormData;if(o.append("file",c),n?.isAuthenticated())return n.fetchWithAuth("/admin/images/upload",{method:"POST",body:o,headers:{}});const r={};l&&(r["X-API-Key"]=l);const d=await fetch(`${s}/admin/images/upload`,{method:"POST",headers:r,body:o});if(!d.ok)throw new Error(`Upload failed: ${d.status}`);return d.json()}async function O(s,l,n,c){const o=JSON.stringify({url:c});if(n?.isAuthenticated()){await n.fetchWithAuth("/admin/images",{method:"DELETE",body:o});return}const r={"Content-Type":"application/json"};l&&(r["X-API-Key"]=l);const d=await fetch(`${s}/admin/images`,{method:"DELETE",headers:r,body:o});if(!d.ok)throw new Error(`Delete failed: ${d.status}`)}function R({serverUrl:s,apiKey:l,authManager:n}){const[c,o]=i.useState([]),[r,d]=i.useState(!1),[x,j]=i.useState(null),[C,m]=i.useState(null),[_,S]=i.useState(null),[p,f]=i.useState(!1),[h,g]=i.useState(null),b=i.useRef(null),D=i.useCallback(async t=>{d(!0),m(null);try{const a=await E(s,l,n,t);o(y=>[{url:a.url,thumbUrl:a.thumbUrl,uploadedAt:new Date().toISOString()},...y]),g(null),b.current&&(b.current.value="")}catch(a){v.getLogger().error("[ImagesSection] Upload failed:",a,{serverUrl:s.slice(0,20)+"..."}),m("Upload failed. Check file type and try again.")}finally{d(!1)}},[s,l,n]),w=t=>{const a=t.target.files?.[0]??null;g(a),m(null)},I=()=>{h&&D(h)},U=t=>{t.preventDefault(),f(!0)},N=()=>f(!1),k=t=>{t.preventDefault(),f(!1);const a=t.dataTransfer.files?.[0];a&&a.type.startsWith("image/")?(g(a),m(null)):a&&m("Only image files are accepted.")},T=i.useCallback(async t=>{j(t),m(null);try{await O(s,l,n,t),o(a=>a.filter(y=>y.url!==t))}catch(a){v.getLogger().error("[ImagesSection] Delete failed:",a,{serverUrl:s.slice(0,20)+"..."}),m("Failed to delete image.")}finally{j(null)}},[s,l,n]),L=async t=>{try{await navigator.clipboard.writeText(t),S(t),setTimeout(()=>S(null),2e3)}catch{m("Could not copy to clipboard.")}},A=["cedros-admin__drop-zone",p?"cedros-admin__drop-zone--active":""].filter(Boolean).join(" ");return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(u.ErrorBanner,{message:C}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Image Upload"})}),e.jsxs("div",{className:A,onDragOver:U,onDragLeave:N,onDrop:k,role:"region","aria-label":"Image drop zone",style:{border:"2px dashed",borderColor:p?"var(--cedros-accent, #6366f1)":"var(--cedros-border, #e2e8f0)",borderRadius:"0.5rem",padding:"1.5rem",textAlign:"center",marginBottom:"1rem",transition:"border-color 0.15s",backgroundColor:p?"var(--cedros-accent-subtle, rgba(99,102,241,0.06))":void 0},children:[e.jsx("p",{style:{marginBottom:"0.75rem",fontSize:"0.9rem",opacity:.7},children:"Drag and drop an image here, or select a file below"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",justifyContent:"center",alignItems:"center",flexWrap:"wrap"},children:[e.jsx("input",{ref:b,id:"cedros-image-file-input",type:"file",accept:"image/*",className:"cedros-admin__input",style:{maxWidth:260},onChange:w,"aria-label":"Select image file"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:I,disabled:!h||r,"aria-busy":r,children:r?e.jsxs(e.Fragment,{children:[u.Icons.loading," Uploading..."]}):"Upload"})]}),h&&!r&&e.jsxs("p",{style:{marginTop:"0.5rem",fontSize:"0.8rem",opacity:.65},children:["Selected: ",h.name," (",(h.size/1024).toFixed(1)," KB)"]})]}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsxs("h3",{className:"cedros-admin__section-title",children:["Uploaded This Session",c.length>0&&e.jsx("span",{className:"cedros-admin__section-badge",style:{marginLeft:"0.5rem"},children:c.length})]})}),c.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No images uploaded yet."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Preview"}),e.jsx("th",{children:"URL"}),e.jsx("th",{children:"Uploaded"}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:c.map(t=>e.jsxs("tr",{children:[e.jsx("td",{style:{width:72},children:e.jsx("img",{src:t.thumbUrl,alt:"Thumbnail preview",style:{width:56,height:56,objectFit:"cover",borderRadius:"0.25rem",display:"block"}})}),e.jsx("td",{style:{maxWidth:320,wordBreak:"break-all"},children:e.jsx("code",{style:{fontSize:"0.8rem"},children:t.url})}),e.jsx("td",{style:{whiteSpace:"nowrap"},children:u.formatDateTime(t.uploadedAt)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:"0.4rem"},children:[e.jsxs("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>L(t.url),"aria-label":"Copy URL to clipboard",title:"Copy URL",children:[_===t.url?u.Icons.check:u.Icons.eye,_===t.url?"Copied":"Copy URL"]}),e.jsxs("button",{type:"button",className:"cedros-admin__button cedros-admin__button--destructive",onClick:()=>T(t.url),disabled:x===t.url,"aria-label":"Delete image",title:"Delete",children:[x===t.url?u.Icons.loading:u.Icons.trash,"Delete"]})]})})]},t.url))})]})})]})}exports.ImagesSection=R;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),m=require("./index-C0g-JxJk.js"),S=require("./CedrosContext-C2RjHLaQ.js"),c=50;function q({serverUrl:d,apiKey:h,authManager:j}){const[_,N]=s.useState([]),[A,g]=s.useState(!0),[P,p]=s.useState(null),[o,C]=s.useState(""),[i,x]=s.useState([]),[w,v]=s.useState(!1),[I,f]=s.useState(null),[a,y]=s.useState(0),l=s.useCallback(async t=>{if(j?.isAuthenticated())return j.fetchWithAuth(t);const n={"Content-Type":"application/json"};h&&(n["X-API-Key"]=h);const r=await fetch(`${d}${t}`,{headers:n});if(!r.ok)throw new Error(`Request failed: ${r.status}`);return r.json()},[d,h,j]);s.useEffect(()=>{let t=!1;return g(!0),p(null),l("/admin/products?limit=100&offset=0").then(n=>{if(t)return;const r=Array.isArray(n)?n:n.products??[];N(r)}).catch(n=>{t||(S.getLogger().error("[InventorySection] Failed to load products:",n,{serverUrl:d.slice(0,20)+"..."}),p("Failed to load products"))}).finally(()=>{t||g(!1)}),()=>{t=!0}},[l,d]);const b=s.useCallback(async(t,n)=>{if(t){v(!0),f(null);try{const r=`/admin/products/${encodeURIComponent(t)}/inventory/adjustments?limit=${c}&offset=${n}`,L=await l(r);x(L.adjustments??[])}catch(r){S.getLogger().error("[InventorySection] Failed to load adjustments:",r,{productId:t,serverUrl:d.slice(0,20)+"..."}),f("Failed to load inventory adjustments"),x([])}finally{v(!1)}}},[l,d]);s.useEffect(()=>{o&&b(o,a)},[b,o,a]);const E=t=>{C(t),y(0),x([]),f(null)},$=()=>y(t=>Math.max(0,t-c)),F=()=>y(t=>t+c),u=_.find(t=>t.id===o);return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(m.ErrorBanner,{message:P??I}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Inventory Adjustments"})}),e.jsx("div",{className:"cedros-admin__add-form",style:{marginBottom:"1rem"},children:e.jsx("div",{className:"cedros-admin__form-row",children:e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{htmlFor:"inventory-product-select",className:"cedros-admin__field-label",children:"Select Product"}),A?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading products..."]}):e.jsxs("select",{id:"inventory-product-select",className:"cedros-admin__input",value:o,onChange:t=>E(t.target.value),"aria-label":"Select product to view inventory adjustments",children:[e.jsx("option",{value:"",children:"-- Choose a product --"}),_.map(t=>e.jsx("option",{value:t.id,children:t.title??t.description??t.id},t.id))]})]})})}),o?w?e.jsxs("div",{className:"cedros-admin__loading",children:[m.Icons.loading," Loading adjustments..."]}):e.jsxs(e.Fragment,{children:[u&&e.jsxs("p",{style:{marginBottom:"0.75rem",fontSize:"0.9rem",opacity:.7},children:["Showing adjustments for: ",e.jsx("strong",{children:u.title??u.description??u.id})]}),i.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No inventory adjustments found."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Delta"}),e.jsx("th",{children:"Before"}),e.jsx("th",{children:"After"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Actor"})]})}),e.jsx("tbody",{children:i.map(t=>e.jsxs("tr",{children:[e.jsx("td",{style:{whiteSpace:"nowrap"},children:m.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("span",{style:{fontWeight:600,color:t.delta>0?"var(--cedros-success, #16a34a)":t.delta<0?"var(--cedros-danger, #dc2626)":void 0},"aria-label":`Delta: ${t.delta>0?"plus":""}${t.delta}`,children:t.delta>0?`+${t.delta}`:t.delta})}),e.jsx("td",{children:t.quantityBefore}),e.jsx("td",{children:t.quantityAfter}),e.jsx("td",{children:t.reason??e.jsx("span",{style:{opacity:.45},children:"—"})}),e.jsx("td",{children:t.actor??e.jsx("span",{style:{opacity:.45},children:"—"})})]},t.id))})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:a===0,onClick:$,children:"Previous"}),e.jsxs("span",{children:["Page ",Math.floor(a/c)+1," · ",i.length," record",i.length!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:i.length<c,onClick:F,children:"Next"})]})]})]}):e.jsx("div",{className:"cedros-admin__empty",children:"Select a product to view its inventory adjustments."})]})}exports.InventorySection=q;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),y=require("./index-C0g-JxJk.js"),S=require("./Toggle-CsPSF8Dr.js"),q=require("./useAutosave-B2p6iwh8.js"),z=require("./AutosaveIndicator-Dn_qA2hK.js"),p={mailgun:{label:"Mailgun",host:"smtp.mailgun.org",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1},sendgrid:{label:"SendGrid",host:"smtp.sendgrid.net",username:"apikey",credentialLabel:"API Key",showUsername:!1,usernameEqualsPassword:!1},postmark:{label:"Postmark",host:"smtp.postmarkapp.com",username:"",credentialLabel:"Server API Token",showUsername:!1,usernameEqualsPassword:!0},ses:{label:"AWS SES",host:"email-smtp.us-east-1.amazonaws.com",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1},resend:{label:"Resend",host:"smtp.resend.com",username:"resend",credentialLabel:"API Key",showUsername:!1,usernameEqualsPassword:!1},custom:{label:"Custom SMTP",host:"",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1}};function R(c){if(!c)return"custom";for(const[d,n]of Object.entries(p))if(n.host&&c===n.host)return d;return"custom"}const v={email_enabled:!1,email_provider:"custom",smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",from_email:"",from_name:"",webhook_enabled:!1,webhook_url:"",webhook_secret:"",webhook_timeout:30};function W({serverUrl:c,apiKey:d,authManager:n}){const[m,b]=l.useState("messages"),[a,h]=l.useState(v),[N,k]=l.useState(!0),[C,E]=l.useState(!0),[P,f]=l.useState(null),[_,j]=l.useState(new Set),g=l.useCallback(async()=>{try{f(null);let s;const t="/admin/config/messaging";if(n?.isAuthenticated())s=await n.fetchWithAuth(t);else{const o={"Content-Type":"application/json"};d&&(o["X-API-Key"]=d);const u=await fetch(`${c}${t}`,{headers:o});if(!u.ok)throw new Error(`Failed to fetch: ${u.status}`);s=await u.json()}const i={...v,...s.config};i.email_provider||(i.email_provider=R(i.smtp_host)),h(i)}catch{h(v),f("Could not load saved settings. Showing defaults.")}finally{k(!1),setTimeout(()=>E(!1),100)}},[c,d,n]);l.useEffect(()=>{g()},[g]);const T=l.useCallback(async s=>{const t="/admin/config/messaging",i={...s};_.has("smtp_password")||delete i.smtp_password,_.has("webhook_secret")||delete i.webhook_secret;const o=JSON.stringify({config:i});try{if(n?.isAuthenticated())await n.fetchWithAuth(t,{method:"PUT",body:o});else{const u={"Content-Type":"application/json"};d&&(u["X-API-Key"]=d);const w=await fetch(`${c}${t}`,{method:"PUT",headers:u,body:o});if(!w.ok)throw new Error(`Failed to save: ${w.status}`)}}catch{throw f("Failed to save messaging settings"),new Error("Save failed")}},[c,d,n,_]),{status:A,error:I}=q.useAutosave({data:a,onSave:T,debounceMs:1500,enabled:!C}),r=(s,t)=>{(s==="smtp_password"||s==="webhook_secret")&&j(i=>new Set(i).add(s)),h(i=>({...i,[s]:t}))},L=s=>{const t=p[s];h(i=>({...i,email_provider:s,smtp_host:t.host||i.smtp_host,smtp_port:587,smtp_username:t.username||(t.showUsername?i.smtp_username:"")}))},M=s=>{const t=a.email_provider||"custom",i=p[t];j(o=>new Set(o).add("smtp_password")),i.usernameEqualsPassword?h(o=>({...o,smtp_password:s,smtp_username:s})):h(o=>({...o,smtp_password:s}))},x=p[a.email_provider||"custom"]??p.custom;return N?e.jsxs("div",{className:"cedros-admin__messaging-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Messages"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure email delivery and webhook notifications."})]}),e.jsxs("div",{className:"cedros-admin__loading",style:{marginTop:"1rem"},children:[y.Icons.loading," Loading message settings..."]})]}):e.jsxs("div",{className:"cedros-admin__messaging-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Messages"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure email delivery and webhook notifications."})]}),e.jsxs("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:[e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="messages"?"cedros-admin__tab--active":""}`,onClick:()=>b("messages"),children:"Messages"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="email"?"cedros-admin__tab--active":""}`,onClick:()=>b("email"),children:"Email"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="webhooks"?"cedros-admin__tab--active":""}`,onClick:()=>b("webhooks"),children:"Webhooks"}),e.jsx("div",{style:{flex:1}}),e.jsx(z.AutosaveIndicator,{status:A,error:I})]}),e.jsx(y.ErrorBanner,{message:P,onRetry:g}),e.jsxs("div",{className:"cedros-admin__tab-content",style:{marginTop:"1rem"},children:[m==="messages"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Enable or disable notification types. Configure the delivery settings in the Email or Webhooks tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"1rem",padding:"1rem",border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:"0.5rem"},children:[e.jsx(S.Toggle,{checked:a.email_enabled,onChange:s=>r("email_enabled",s)}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:"Email Confirmation"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.8125rem",opacity:.6},children:"Send order confirmation emails to customers after successful purchase."}),e.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.75rem",opacity:.5},children:"Requires Email configuration"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"1rem",padding:"1rem",border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:"0.5rem"},children:[e.jsx(S.Toggle,{checked:a.webhook_enabled,onChange:s=>r("webhook_enabled",s)}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:"Admin Purchase Notification"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.8125rem",opacity:.6},children:"Send webhook notifications to your server when a purchase is completed."}),e.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.75rem",opacity:.5},children:"Requires Webhook configuration"})]})]})]})]}),m==="email"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Select your email service provider for automatic configuration."}),!a.email_enabled&&e.jsx("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #fef3c7)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-warning, #f59e0b)",fontSize:"0.875rem"},children:"Email notifications are disabled. Enable them in the Messages tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",opacity:a.email_enabled?1:.5},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Email Provider"}),e.jsx("select",{className:"cedros-admin__input",value:a.email_provider||"custom",onChange:s=>L(s.target.value),disabled:!a.email_enabled,children:Object.entries(p).map(([s,{label:t}])=>e.jsx("option",{value:s,children:t},s))})]}),a.email_provider==="custom"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Host"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.smtp_host,onChange:s=>r("smtp_host",s.target.value),placeholder:"smtp.example.com",disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Port"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.smtp_port,onChange:s=>r("smtp_port",parseInt(s.target.value)||587),placeholder:"587",disabled:!a.email_enabled,style:{maxWidth:120}}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Common: 587 (TLS), 465 (SSL), 25 (unencrypted)."})]})]}),x.showUsername&&e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Username"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.smtp_username,onChange:s=>r("smtp_username",s.target.value),placeholder:a.email_provider==="mailgun"?"postmaster@your-domain.com":"username",disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:x.credentialLabel}),e.jsx("input",{type:"password",className:"cedros-admin__input",value:_.has("smtp_password")?a.smtp_password:"",onChange:s=>M(s.target.value),placeholder:a.smtp_password?"••••••••":`Enter ${x.credentialLabel.toLowerCase()}`,disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"From Email"}),e.jsx("input",{type:"email",className:"cedros-admin__input",value:a.from_email,onChange:s=>r("from_email",s.target.value),placeholder:"noreply@example.com",disabled:!a.email_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Default sender email address."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"From Name"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.from_name,onChange:s=>r("from_name",s.target.value),placeholder:"Your Store",disabled:!a.email_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Default sender display name."})]})]})]}),m==="webhooks"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Configure webhook endpoint for receiving purchase notifications."}),!a.webhook_enabled&&e.jsx("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #fef3c7)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-warning, #f59e0b)",fontSize:"0.875rem"},children:"Webhook notifications are disabled. Enable them in the Messages tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",opacity:a.webhook_enabled?1:.5},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Webhook URL"}),e.jsx("input",{type:"url",className:"cedros-admin__input",value:a.webhook_url,onChange:s=>r("webhook_url",s.target.value),placeholder:"https://api.yoursite.com/webhooks/orders",disabled:!a.webhook_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Webhook Secret"}),e.jsx("input",{type:"password",className:"cedros-admin__input",value:_.has("webhook_secret")?a.webhook_secret:"",onChange:s=>r("webhook_secret",s.target.value),placeholder:a.webhook_secret?"••••••••":"Enter secret for HMAC-SHA256",disabled:!a.webhook_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Used for HMAC-SHA256 signature verification"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Timeout (seconds)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.webhook_timeout,onChange:s=>r("webhook_timeout",parseInt(s.target.value)||30),placeholder:"30",disabled:!a.webhook_enabled,style:{maxWidth:120}})]})]})]})]})]})}exports.MessagingSection=W;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),u=require("./index-C0g-JxJk.js");function A({serverUrl:n,apiKey:d,pageSize:o=20,authManager:r}){const[l,s]=a.useState([]),[c,p]=a.useState(0),[w,v]=a.useState(!0),[b,S]=a.useState(null),[h,N]=a.useState(null),[L,_]=a.useState(null),[R,y]=a.useState([]),[$,C]=a.useState(!1),[j,F]=a.useState(""),x=a.useCallback(async(t,i)=>{if(r?.isAuthenticated())return r.fetchWithAuth(t,i);const f={"Content-Type":"application/json"};d&&(f["X-API-Key"]=d);const m=await fetch(`${n}${t}`,{...i,headers:{...f,...i?.headers}});if(!m.ok){const I=await m.text().catch(()=>`HTTP ${m.status}`);throw new Error(I)}return m.json()},[n,d,r]),g=a.useCallback(async()=>{v(!0);try{S(null);const t=new URLSearchParams({limit:String(o)});j&&t.set("status",j);const i=await x(`/admin/orders?${t}`);s(i.orders),p(i.total)}catch{S("Failed to load orders")}finally{v(!1)}},[x,o,j]);a.useEffect(()=>{g()},[g]);const O=a.useCallback(async t=>{C(!0);try{const[i,f]=await Promise.all([x(`/admin/orders/${encodeURIComponent(t)}`),x("/admin/gift-card-redemptions?limit=50").catch(()=>[])]);_(i),y(f.filter(m=>m.orderId===t))}catch{_(null),y([])}finally{C(!1)}},[x]),T=t=>{h===t?(N(null),_(null),y([])):(N(t),O(t))},D=(t,i)=>i==="USD"||i==="usd"?`$${(t/100).toFixed(2)}`:`${t} ${i}`;return e.jsxs("div",{className:"cedros-admin__section",children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h2",{className:"cedros-admin__section-title",children:"Orders"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e.jsxs("select",{className:"cedros-admin__input",style:{width:"auto",minWidth:"120px"},value:j,onChange:t=>F(t.target.value),children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"paid",children:"Paid"}),e.jsx("option",{value:"processing",children:"Processing"}),e.jsx("option",{value:"fulfilled",children:"Fulfilled"}),e.jsx("option",{value:"shipped",children:"Shipped"}),e.jsx("option",{value:"delivered",children:"Delivered"}),e.jsx("option",{value:"cancelled",children:"Cancelled"}),e.jsx("option",{value:"refunded",children:"Refunded"})]}),e.jsxs("button",{type:"button",className:"cedros-admin__button cedros-admin__button--secondary",onClick:g,children:[u.Icons.refresh," Refresh"]})]})]}),b?e.jsx(u.ErrorBanner,{message:b,onRetry:g}):null,w?e.jsx("div",{className:"cedros-admin__loading-text",children:"Loading orders..."}):l.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No orders found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__table-info",children:[c," order",c===1?"":"s"," total"]}),e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Order"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Source"}),e.jsx("th",{children:"Customer"}),e.jsx("th",{children:"Date"})]})}),e.jsx("tbody",{children:l.map(t=>e.jsx(E,{order:t,expanded:h===t.id,detail:h===t.id?L:null,redemptions:h===t.id?R:[],detailLoading:h===t.id&&$,onToggle:()=>T(t.id),formatAmount:D},t.id))})]})]})]})}function E({order:n,expanded:d,detail:o,redemptions:r,detailLoading:l,onToggle:s,formatAmount:c}){const p=n.metadata?.recipient_email||r.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{onClick:s,style:{cursor:"pointer"},className:d?"cedros-admin__table-row--active":"",children:[e.jsxs("td",{children:[e.jsxs("span",{className:"cedros-admin__mono",children:[n.id.slice(0,12),"..."]}),p?e.jsx("span",{className:"cedros-admin__badge cedros-admin__badge--info",style:{marginLeft:"0.5rem"},children:"Gift Card"}):null]}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${k(n.status)}`,children:n.status})}),e.jsx("td",{children:c(n.amount,n.amountAsset)}),e.jsx("td",{children:n.source}),e.jsx("td",{children:n.customerEmail||n.customerName||"—"}),e.jsx("td",{children:u.formatDateTime(n.createdAt)})]}),d?e.jsx("tr",{children:e.jsx("td",{colSpan:6,style:{padding:0},children:e.jsx(P,{detail:o,redemptions:r,loading:l,formatAmount:c,metadata:n.metadata})})}):null]})}function P({detail:n,redemptions:d,loading:o,formatAmount:r,metadata:l}){return o?e.jsx("div",{style:{padding:"1rem"},className:"cedros-admin__loading-text",children:"Loading details..."}):e.jsxs("div",{style:{padding:"1rem",background:"var(--cedros-admin-bg-muted, #f9fafb)"},children:[Object.keys(l).length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Order Metadata"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"0.25rem 1rem",fontSize:"0.8125rem"},children:Object.entries(l).map(([s,c])=>e.jsxs("div",{style:{display:"contents"},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--cedros-admin-text-muted)"},children:s}),e.jsx("span",{children:c})]},s))})]}):null,d.length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Gift Card Fulfillment"}),d.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",padding:"0.5rem",border:"1px solid var(--cedros-admin-border)",borderRadius:"0.5rem",marginBottom:"0.5rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("span",{children:["Face value: ",r(s.faceValueCents,s.currency)]}),e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${s.creditsIssued>0?"success":"warning"}`,children:s.creditsIssued>0?"Credits issued":"Pending"})]}),e.jsxs("div",{style:{marginTop:"0.25rem",color:"var(--cedros-admin-text-muted)"},children:["Recipient: ",s.recipientUserId||"—",s.tokenMinted?e.jsx("span",{className:"cedros-admin__badge cedros-admin__badge--info",style:{marginLeft:"0.5rem"},children:"Token minted"}):null]})]},s.id))]}):null,n?.fulfillments&&n.fulfillments.length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Fulfillments"}),n.fulfillments.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",marginBottom:"0.25rem"},children:[e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${k(s.status)}`,children:s.status}),s.carrier?e.jsx("span",{style:{marginLeft:"0.5rem"},children:s.carrier}):null,s.trackingNumber?u.safeHref(s.trackingUrl)?e.jsx("a",{href:u.safeHref(s.trackingUrl),target:"_blank",rel:"noreferrer",style:{marginLeft:"0.5rem"},children:s.trackingNumber}):e.jsx("span",{style:{marginLeft:"0.5rem"},children:s.trackingNumber}):null]},s.id))]}):null,n?.history&&n.history.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__label",children:"Status History"}),n.history.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",marginBottom:"0.25rem"},children:[e.jsx("span",{style:{color:"var(--cedros-admin-text-muted)"},children:u.formatDateTime(s.createdAt)})," ",s.fromStatus," → ",s.toStatus,s.note?e.jsx("span",{style:{marginLeft:"0.5rem",fontStyle:"italic"},children:s.note}):null]},s.id))]}):null]})}function k(n){switch(n){case"paid":case"fulfilled":case"delivered":case"success":return"success";case"processing":case"shipped":case"pending":return"warning";case"cancelled":case"refunded":case"failed":return"error";default:return"default"}}exports.OrdersSection=A;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),p=require("./SingleCategorySettings-DwCnBdRf.js");function r({href:s,children:n}){return e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"},children:n})}const a=[{id:"stripe",label:"Stripe",category:"stripe",description:e.jsxs(e.Fragment,{children:["Configure your Stripe integration for card payments. Get your API keys from the"," ",e.jsx(r,{href:"https://dashboard.stripe.com/apikeys",children:"Stripe Dashboard"}),"."]})},{id:"crypto",label:"Crypto",category:"x402",description:e.jsxs(e.Fragment,{children:["Configure Solana wallet and token settings for crypto payments. Get a fast RPC endpoint from"," ",e.jsx(r,{href:"https://www.helius.dev",children:"Helius"})," or"," ",e.jsx(r,{href:"https://www.quicknode.com/chains/sol",children:"QuickNode"}),". Set up a payment address using"," ",e.jsx(r,{href:"https://phantom.app",children:"Phantom"})," or"," ",e.jsx(r,{href:"https://solflare.com",children:"Solflare"})," wallet."]})},{id:"credits",label:"Credits",category:"cedros_login",description:e.jsxs(e.Fragment,{children:["Configure Cedros Login integration for credits payments. See the"," ",e.jsx(r,{href:"https://docs.cedros.dev/credits",children:"Credits API documentation"}),"."]})}];function h({serverUrl:s,apiKey:n,authManager:c}){const[o,d]=l.useState("stripe"),i=a.find(t=>t.id===o);return e.jsxs("div",{className:"cedros-admin__payment-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Payment Options"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure payment methods including Stripe, crypto, and credits."})]}),e.jsx("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:a.map(t=>e.jsx("button",{type:"button",className:`cedros-admin__tab ${o===t.id?"cedros-admin__tab--active":""}`,onClick:()=>d(t.id),children:t.label},t.id))}),e.jsx("div",{style:{marginTop:"1rem"},children:e.jsx(p.SingleCategorySettings,{serverUrl:s,apiKey:n,authManager:c,category:i.category,title:`${i.label} Settings`,description:i.description,showEnabledToggle:!0},i.category)})]})}exports.PaymentSettingsSection=h;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { jsxs as i, jsx as e, Fragment as s } from "react/jsx-runtime";
|
|
2
|
-
import { useState as h } from "react";
|
|
3
|
-
import { S as m } from "./SingleCategorySettings-suJ8z9d8.mjs";
|
|
4
|
-
function r({ href: o, children: a }) {
|
|
5
|
-
return /* @__PURE__ */ e(
|
|
6
|
-
"a",
|
|
7
|
-
{
|
|
8
|
-
href: o,
|
|
9
|
-
target: "_blank",
|
|
10
|
-
rel: "noopener noreferrer",
|
|
11
|
-
style: { color: "inherit", textDecoration: "underline" },
|
|
12
|
-
children: a
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
const c = [
|
|
17
|
-
{
|
|
18
|
-
id: "stripe",
|
|
19
|
-
label: "Stripe",
|
|
20
|
-
category: "stripe",
|
|
21
|
-
description: /* @__PURE__ */ i(s, { children: [
|
|
22
|
-
"Configure your Stripe integration for card payments. Get your API keys from the",
|
|
23
|
-
" ",
|
|
24
|
-
/* @__PURE__ */ e(r, { href: "https://dashboard.stripe.com/apikeys", children: "Stripe Dashboard" }),
|
|
25
|
-
"."
|
|
26
|
-
] })
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: "crypto",
|
|
30
|
-
label: "Crypto",
|
|
31
|
-
category: "x402",
|
|
32
|
-
description: /* @__PURE__ */ i(s, { children: [
|
|
33
|
-
"Configure Solana wallet and token settings for crypto payments. Get a fast RPC endpoint from",
|
|
34
|
-
" ",
|
|
35
|
-
/* @__PURE__ */ e(r, { href: "https://www.helius.dev", children: "Helius" }),
|
|
36
|
-
" or",
|
|
37
|
-
" ",
|
|
38
|
-
/* @__PURE__ */ e(r, { href: "https://www.quicknode.com/chains/sol", children: "QuickNode" }),
|
|
39
|
-
". Set up a payment address using",
|
|
40
|
-
" ",
|
|
41
|
-
/* @__PURE__ */ e(r, { href: "https://phantom.app", children: "Phantom" }),
|
|
42
|
-
" or",
|
|
43
|
-
" ",
|
|
44
|
-
/* @__PURE__ */ e(r, { href: "https://solflare.com", children: "Solflare" }),
|
|
45
|
-
" wallet."
|
|
46
|
-
] })
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: "credits",
|
|
50
|
-
label: "Credits",
|
|
51
|
-
category: "cedros_login",
|
|
52
|
-
description: /* @__PURE__ */ i(s, { children: [
|
|
53
|
-
"Configure Cedros Login integration for credits payments. See the",
|
|
54
|
-
" ",
|
|
55
|
-
/* @__PURE__ */ e(r, { href: "https://docs.cedros.dev/credits", children: "Credits API documentation" }),
|
|
56
|
-
"."
|
|
57
|
-
] })
|
|
58
|
-
}
|
|
59
|
-
];
|
|
60
|
-
function u({ serverUrl: o, apiKey: a, authManager: l }) {
|
|
61
|
-
const [d, p] = h("stripe"), n = c.find((t) => t.id === d);
|
|
62
|
-
return /* @__PURE__ */ i("div", { className: "cedros-admin__payment-settings", children: [
|
|
63
|
-
/* @__PURE__ */ i("div", { className: "cedros-admin__page-header", children: [
|
|
64
|
-
/* @__PURE__ */ e("h2", { className: "cedros-admin__page-title", children: "Payment Options" }),
|
|
65
|
-
/* @__PURE__ */ e("p", { className: "cedros-admin__page-description", children: "Configure payment methods including Stripe, crypto, and credits." })
|
|
66
|
-
] }),
|
|
67
|
-
/* @__PURE__ */ e("div", { className: "cedros-admin__tabs cedros-admin__tabs--line", children: c.map((t) => /* @__PURE__ */ e(
|
|
68
|
-
"button",
|
|
69
|
-
{
|
|
70
|
-
type: "button",
|
|
71
|
-
className: `cedros-admin__tab ${d === t.id ? "cedros-admin__tab--active" : ""}`,
|
|
72
|
-
onClick: () => p(t.id),
|
|
73
|
-
children: t.label
|
|
74
|
-
},
|
|
75
|
-
t.id
|
|
76
|
-
)) }),
|
|
77
|
-
/* @__PURE__ */ e("div", { style: { marginTop: "1rem" }, children: /* @__PURE__ */ e(
|
|
78
|
-
m,
|
|
79
|
-
{
|
|
80
|
-
serverUrl: o,
|
|
81
|
-
apiKey: a,
|
|
82
|
-
authManager: l,
|
|
83
|
-
category: n.category,
|
|
84
|
-
title: `${n.label} Settings`,
|
|
85
|
-
description: n.description,
|
|
86
|
-
showEnabledToggle: !0
|
|
87
|
-
},
|
|
88
|
-
n.category
|
|
89
|
-
) })
|
|
90
|
-
] });
|
|
91
|
-
}
|
|
92
|
-
export {
|
|
93
|
-
u as PaymentSettingsSection
|
|
94
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("react"),h=require("./index-C0g-JxJk.js"),w=["requested","approved","rejected","received","refunded"],I=s=>{switch(s){case"approved":return"success";case"refunded":return"success";case"rejected":return"failed";case"received":return"muted";case"requested":return"pending";default:return"muted"}};function A({returnRequest:s,onBack:u,onStatusUpdated:l,onError:m,fetchWithAuth:a}){const[r,p]=d.useState(s.status),[x,_]=d.useState(!1),c=async()=>{if(!(!r||r===s.status)){_(!0);try{const n=await a(`/admin/returns/${encodeURIComponent(s.id)}/status`,{method:"PUT",body:JSON.stringify({status:r})});l(n)}catch{m("Failed to update return status")}finally{_(!1)}}};return e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:u,style:{marginBottom:"1rem"},children:"← Back to returns"}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsxs("h3",{className:"cedros-admin__section-title",children:["Return ",e.jsx("code",{style:{fontSize:"0.8rem"},children:s.id.slice(0,12)}),e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I(s.status)}`,style:{marginLeft:"0.5rem"},children:s.status})]})}),e.jsx("div",{className:"cedros-admin__table-container",style:{maxWidth:"500px",marginBottom:"1rem"},children:e.jsx("table",{className:"cedros-admin__table",children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600,width:"35%"},children:"Order ID"}),e.jsx("td",{children:e.jsx("code",{children:s.orderId})})]}),s.reason&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Reason"}),e.jsx("td",{children:s.reason})]}),e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Created"}),e.jsx("td",{children:h.formatDateTime(s.createdAt)})]}),s.statusUpdatedAt&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Status Updated"}),e.jsx("td",{children:h.formatDateTime(s.statusUpdatedAt)})]}),s.updatedAt&&e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600},children:"Last Updated"}),e.jsx("td",{children:h.formatDateTime(s.updatedAt)})]})]})})}),e.jsxs("h4",{style:{fontSize:"0.85rem",fontWeight:600,margin:"0 0 0.5rem"},children:["Items (",s.items.length,")"]}),e.jsx("div",{className:"cedros-admin__table-container",style:{maxWidth:"500px",marginBottom:"1.25rem"},children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Product ID"}),e.jsx("th",{children:"Variant ID"}),e.jsx("th",{children:"Qty"})]})}),e.jsx("tbody",{children:s.items.map((n,o)=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{style:{fontSize:"0.75rem"},children:n.productId})}),e.jsx("td",{children:n.variantId?e.jsx("code",{style:{fontSize:"0.75rem"},children:n.variantId}):e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"—"})}),e.jsx("td",{children:n.quantity})]},o))})]})}),Object.keys(s.metadata).length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{style:{fontSize:"0.85rem",fontWeight:600,margin:"0 0 0.5rem"},children:"Metadata"}),e.jsx("div",{className:"cedros-admin__table-container",style:{maxWidth:"500px",marginBottom:"1.25rem"},children:e.jsx("table",{className:"cedros-admin__table",children:e.jsx("tbody",{children:Object.entries(s.metadata).map(([n,o])=>e.jsxs("tr",{children:[e.jsx("td",{style:{fontWeight:600,width:"40%"},children:n}),e.jsx("td",{children:o})]},n))})})})]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"flex-end",maxWidth:"400px"},children:[e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Update Status"}),e.jsx("select",{className:"cedros-admin__input",value:r,onChange:n=>p(n.target.value),children:w.map(n=>e.jsx("option",{value:n,children:n},n))})]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:c,disabled:x||r===s.status,children:x?"Updating...":"Update"})]})]})}function D({serverUrl:s,apiKey:u,pageSize:l=20,authManager:m}){const[a,r]=d.useState([]),[p,x]=d.useState(!0),[_,c]=d.useState(null),[n,o]=d.useState(0),[f,R]=d.useState("all"),[S,y]=d.useState(null),[C,v]=d.useState(!1),g=d.useCallback(async(t,i)=>{if(m?.isAuthenticated())return m.fetchWithAuth(t,i);const j={"Content-Type":"application/json"};u&&(j["X-API-Key"]=u);const b=await fetch(`${s}${t}`,{...i,headers:{...j,...i?.headers}});if(!b.ok)throw new Error(`Request failed: ${b.status}`);return b.json()},[s,u,m]),N=d.useCallback(async()=>{x(!0),c(null);try{const t=new URLSearchParams;t.set("limit",String(l)),t.set("offset",String(n)),f!=="all"&&t.set("status",f);const i=await g(`/admin/returns?${t.toString()}`);r(i.returns??[])}catch{c("Failed to load returns"),r([])}finally{x(!1)}},[g,l,n,f]);d.useEffect(()=>{N()},[N]);const U=async t=>{v(!0),c(null);try{const i=await g(`/admin/returns/${encodeURIComponent(t)}`);y(i)}catch{c("Failed to load return details")}finally{v(!1)}},W=t=>{y(t),r(i=>i.map(j=>j.id===t.id?t:j))};return S?e.jsx(A,{returnRequest:S,onBack:()=>y(null),onStatusUpdated:W,onError:c,fetchWithAuth:g}):e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Returns"})}),e.jsx(h.ErrorBanner,{message:_}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginBottom:"1rem",alignItems:"center"},children:[e.jsxs("select",{className:"cedros-admin__input",value:f,onChange:t=>{R(t.target.value),o(0)},style:{width:"auto",fontSize:"0.85rem"},children:[e.jsx("option",{value:"all",children:"All statuses"}),w.map(t=>e.jsx("option",{value:t,children:t.charAt(0).toUpperCase()+t.slice(1)},t))]}),e.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)"},children:[a.length," result",a.length!==1?"s":""]})]}),p||C?e.jsxs("div",{className:"cedros-admin__loading",children:[h.Icons.loading," Loading returns..."]}):a.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No returns found."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Order ID"}),e.jsx("th",{children:"Items"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Reason"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:a.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{style:{fontSize:"0.75rem"},children:t.orderId})}),e.jsx("td",{children:t.items.length}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I(t.status)}`,children:t.status})}),e.jsx("td",{style:{maxWidth:"180px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.reason??e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"—"})}),e.jsx("td",{children:h.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>U(t.id),children:"View"})})]},t.id))})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:n===0,onClick:()=>o(Math.max(0,n-l)),children:"Previous"}),e.jsxs("span",{children:["Showing ",a.length," return",a.length!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:a.length<l,onClick:()=>o(n+l),children:"Next"})]})]})]})}exports.ReturnsSection=D;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),c=require("./index-C0g-JxJk.js"),z={name:"",description:"",countries:"",active:!0},W={name:"",rateType:"flat",amountAtomic:"",currency:"USD",minSubtotal:"",maxSubtotal:"",active:!0},A=(_,h)=>`${h.toUpperCase()} ${(_/100).toFixed(2)}`;function Z({serverUrl:_,apiKey:h,authManager:S}){const[R,E]=a.useState([]),[q,P]=a.useState(!0),[w,p]=a.useState(null),[I,d]=a.useState(null),[J,f]=a.useState(!1),[b,g]=a.useState(null),[o,m]=a.useState(z),[k,T]=a.useState(!1),[n,F]=a.useState(null),[D,U]=a.useState([]),[M,$]=a.useState(!1),[G,u]=a.useState(!1),[y,x]=a.useState(null),[i,r]=a.useState(W),[L,B]=a.useState(!1),l=a.useCallback(async(t,s)=>{if(S?.isAuthenticated())return S.fetchWithAuth(t,s);const v={"Content-Type":"application/json"};h&&(v["X-API-Key"]=h);const C=await fetch(`${_}${t}`,{...s,headers:{...v,...s?.headers}});if(!C.ok)throw new Error(`Request failed: ${C.status}`);return C.json()},[_,h,S]),j=a.useCallback(async()=>{P(!0),p(null);try{const t=await l("/admin/shipping/profiles?limit=50&offset=0");E(t.profiles??[])}catch{p("Failed to load shipping profiles"),E([])}finally{P(!1)}},[l]);a.useEffect(()=>{j()},[j]);const K=t=>{g(t),m({name:t.name,description:t.description??"",countries:t.countries.join(", "),active:t.active}),f(!0)},X=async t=>{t.preventDefault(),T(!0),d(null);try{const s={name:o.name,description:o.description||void 0,countries:o.countries.split(",").map(v=>v.trim()).filter(Boolean),active:o.active};b?await l(`/admin/shipping/profiles/${encodeURIComponent(b.id)}`,{method:"PUT",body:JSON.stringify(s)}):await l("/admin/shipping/profiles",{method:"POST",body:JSON.stringify(s)}),f(!1),g(null),j()}catch(s){d(s instanceof Error?s.message:"Failed to save profile")}finally{T(!1)}},H=async t=>{if(window.confirm("Delete this shipping profile?")){d(null);try{await l(`/admin/shipping/profiles/${encodeURIComponent(t)}`,{method:"DELETE"}),j()}catch{d("Failed to delete profile")}}},N=a.useCallback(async t=>{$(!0),p(null);try{const s=await l(`/admin/shipping/profiles/${encodeURIComponent(t.id)}/rates?limit=50&offset=0`);U(s.rates??[])}catch{p("Failed to load rates"),U([])}finally{$(!1)}},[l]),O=t=>{F(t),u(!1),x(null),N(t)},Q=t=>{x(t),r({name:t.name,rateType:t.rateType,amountAtomic:String(t.amountAtomic),currency:t.currency,minSubtotal:t.minSubtotal!=null?String(t.minSubtotal):"",maxSubtotal:t.maxSubtotal!=null?String(t.maxSubtotal):"",active:t.active}),u(!0)},V=async t=>{if(t.preventDefault(),!!n){B(!0),d(null);try{const s={name:i.name,rateType:i.rateType,amountAtomic:parseInt(i.amountAtomic,10),currency:i.currency,active:i.active,profileId:n.id,minSubtotal:i.minSubtotal?parseInt(i.minSubtotal,10):void 0,maxSubtotal:i.maxSubtotal?parseInt(i.maxSubtotal,10):void 0};y?await l(`/admin/shipping/rates/${encodeURIComponent(y.id)}`,{method:"PUT",body:JSON.stringify(s)}):await l(`/admin/shipping/profiles/${encodeURIComponent(n.id)}/rates`,{method:"POST",body:JSON.stringify(s)}),u(!1),x(null),N(n)}catch(s){d(s instanceof Error?s.message:"Failed to save rate")}finally{B(!1)}}},Y=async t=>{if(!(!window.confirm("Delete this rate?")||!n)){d(null);try{await l(`/admin/shipping/rates/${encodeURIComponent(t)}`,{method:"DELETE"}),N(n)}catch{d("Failed to delete rate")}}};return n?e.jsxs("div",{children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>{F(null),u(!1),p(null),d(null)},style:{marginBottom:"1rem"},children:"← Back to profiles"}),e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsxs("h3",{className:"cedros-admin__section-title",children:[n.name,e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${n.active?"success":"muted"}`,style:{marginLeft:"0.5rem"},children:n.active?"Active":"Inactive"})]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:()=>{x(null),r(W),u(!0)},children:"+ Add Rate"})]}),e.jsx(c.ErrorBanner,{message:w}),e.jsx(c.ErrorBanner,{message:I}),e.jsxs("p",{style:{fontSize:"0.8rem",color:"var(--cedros-admin-text-muted, #888)",margin:"0 0 1rem"},children:[n.description&&e.jsxs(e.Fragment,{children:[n.description," · "]}),"Countries: ",n.countries.length>0?n.countries.join(", "):"All"]}),G&&e.jsxs("form",{onSubmit:V,style:{border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",padding:"1rem",marginBottom:"1.5rem",maxWidth:"520px"},children:[e.jsx("h4",{style:{margin:"0 0 0.75rem",fontSize:"0.9rem",fontWeight:600},children:y?"Edit Rate":"New Rate"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Name *"}),e.jsx("input",{type:"text",className:"cedros-admin__input",required:!0,value:i.name,onChange:t=>r(s=>({...s,name:t.target.value})),placeholder:"Standard Shipping"})]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Rate Type *"}),e.jsxs("select",{className:"cedros-admin__input",value:i.rateType,onChange:t=>r(s=>({...s,rateType:t.target.value})),children:[e.jsx("option",{value:"flat",children:"Flat"}),e.jsx("option",{value:"price",children:"Price-based"}),e.jsx("option",{value:"weight",children:"Weight-based"})]})]}),e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Amount (atomic) *"}),e.jsx("input",{type:"number",className:"cedros-admin__input",required:!0,min:0,value:i.amountAtomic,onChange:t=>r(s=>({...s,amountAtomic:t.target.value})),placeholder:"500"})]}),e.jsxs("div",{className:"cedros-admin__field",style:{width:"80px"},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Currency"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:i.currency,maxLength:3,onChange:t=>r(s=>({...s,currency:t.target.value.toUpperCase()})),placeholder:"USD"})]})]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Min Subtotal"}),e.jsx("input",{type:"number",className:"cedros-admin__input",min:0,value:i.minSubtotal,onChange:t=>r(s=>({...s,minSubtotal:t.target.value})),placeholder:"0"})]}),e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Max Subtotal"}),e.jsx("input",{type:"number",className:"cedros-admin__input",min:0,value:i.maxSubtotal,onChange:t=>r(s=>({...s,maxSubtotal:t.target.value})),placeholder:"10000"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("input",{type:"checkbox",id:"rate-active",checked:i.active,onChange:t=>r(s=>({...s,active:t.target.checked}))}),e.jsx("label",{htmlFor:"rate-active",className:"cedros-admin__field-label",style:{margin:0},children:"Active"})]})]}),e.jsxs("div",{style:{marginTop:"0.75rem",display:"flex",gap:"0.5rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:L,children:L?"Saving...":y?"Update":"Create"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>{u(!1),x(null)},children:"Cancel"})]})]}),M?e.jsxs("div",{className:"cedros-admin__loading",children:[c.Icons.loading," Loading rates..."]}):D.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No rates yet. Add one above."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Min / Max Subtotal"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Updated"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:D.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:t.name}),e.jsx("td",{style:{fontSize:"0.85rem"},children:t.rateType}),e.jsx("td",{style:{fontSize:"0.85rem"},children:A(t.amountAtomic,t.currency)}),e.jsxs("td",{style:{fontSize:"0.8rem",color:"var(--cedros-admin-text-muted, #888)"},children:[t.minSubtotal!=null?A(t.minSubtotal,t.currency):"—"," / ",t.maxSubtotal!=null?A(t.maxSubtotal,t.currency):"—"]}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${t.active?"success":"muted"}`,children:t.active?"Active":"Inactive"})}),e.jsx("td",{style:{fontSize:"0.8rem"},children:c.formatDateTime(t.updatedAt)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:"0.25rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>Q(t),children:"Edit"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>Y(t.id),style:{color:"var(--cedros-admin-danger, #c00)"},children:"Delete"})]})})]},t.id))})]})})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Shipping"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:()=>{g(null),m(z),f(!0)},children:"+ Add Profile"})]}),e.jsx(c.ErrorBanner,{message:w}),e.jsx(c.ErrorBanner,{message:I}),J&&e.jsxs("form",{onSubmit:X,style:{border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",padding:"1rem",marginBottom:"1.5rem",maxWidth:"500px"},children:[e.jsx("h4",{style:{margin:"0 0 0.75rem",fontSize:"0.9rem",fontWeight:600},children:b?"Edit Profile":"New Profile"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Name *"}),e.jsx("input",{type:"text",className:"cedros-admin__input",required:!0,value:o.name,onChange:t=>m(s=>({...s,name:t.target.value})),placeholder:"Domestic Shipping"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Description"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:o.description,onChange:t=>m(s=>({...s,description:t.target.value})),placeholder:"Optional description"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Countries (comma-separated ISO codes)"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:o.countries,onChange:t=>m(s=>({...s,countries:t.target.value})),placeholder:"US, CA, GB"})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("input",{type:"checkbox",id:"profile-active",checked:o.active,onChange:t=>m(s=>({...s,active:t.target.checked}))}),e.jsx("label",{htmlFor:"profile-active",className:"cedros-admin__field-label",style:{margin:0},children:"Active"})]})]}),e.jsxs("div",{style:{marginTop:"0.75rem",display:"flex",gap:"0.5rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:k,children:k?"Saving...":b?"Update":"Create"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>{f(!1),g(null)},children:"Cancel"})]})]}),q?e.jsxs("div",{className:"cedros-admin__loading",children:[c.Icons.loading," Loading profiles..."]}):R.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No shipping profiles found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Countries"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:R.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("button",{type:"button",style:{background:"none",border:"none",cursor:"pointer",fontWeight:600,padding:0,color:"var(--cedros-admin-text, #333)",fontSize:"0.9rem"},onClick:()=>O(t),children:t.name})}),e.jsx("td",{style:{fontSize:"0.8rem",color:"var(--cedros-admin-text-muted, #888)",maxWidth:"200px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.countries.length>0?t.countries.join(", "):"All"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${t.active?"success":"muted"}`,children:t.active?"Active":"Inactive"})}),e.jsx("td",{style:{fontSize:"0.8rem"},children:c.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:"0.25rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>O(t),children:"Rates"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>K(t),children:"Edit"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>H(t.id),style:{color:"var(--cedros-admin-danger, #c00)"},children:"Delete"})]})})]},t.id))})]})})]})}exports.ShippingSection=Z;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),l=require("react"),j=require("./index-C0g-JxJk.js"),N=require("./configApi-DkduMQg1.js"),K=require("./useAutosave-B2p6iwh8.js"),L=require("./AutosaveIndicator-Dn_qA2hK.js"),V=require("./CedrosContext-C2RjHLaQ.js"),J=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function M(b){return!b||b.trim()===""?{valid:!0}:J.test(b.trim())?{valid:!0}:{valid:!1,error:"Invalid Solana address"}}function P({label:b,value:f,onChange:h,decimals:n,onDecimalsChange:S,disabled:o=!1,description:a,customSymbol:d="",customIcon:u="",onCustomSymbolChange:c,onCustomIconChange:x}){const[v,E]=l.useState(!1),p=Object.entries(V.STABLECOIN_METADATA),y=!!V.STABLECOIN_METADATA[f],C=v||!!f&&!y,w=t=>{if(t==="custom")E(!0),y&&h("");else{E(!1),h(t);const s=V.STABLECOIN_METADATA[t];s&&S&&S(s.decimals),c&&c(""),x&&x("")}};return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:b}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.5rem"},children:[p.map(([t,s])=>e.jsxs("button",{type:"button",onClick:()=>w(t),disabled:o,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:f===t?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:f===t?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,fontWeight:f===t?600:400},children:[e.jsx("img",{src:s.icon,alt:s.symbol,style:{width:20,height:20,borderRadius:"50%"},onError:r=>{r.target.style.display="none"}}),e.jsx("span",{children:s.symbol})]},t)),e.jsxs("button",{type:"button",onClick:()=>w("custom"),disabled:o,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:C?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:C?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,fontWeight:C?600:400},children:[e.jsx("span",{style:{fontSize:"1rem"},children:"+"}),e.jsx("span",{children:"Custom"})]})]}),C&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem",padding:"1rem",background:"var(--cedros-admin-bg-muted, #f9fafb)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Mint Address"}),(()=>{const t=M(f);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:`cedros-admin__input ${t.valid?"":"cedros-admin__input--error"}`,value:f,onChange:s=>h(s.target.value),placeholder:"e.g., EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",disabled:o,style:{fontFamily:"monospace",fontSize:"0.875rem",borderColor:t.valid?void 0:"var(--cedros-admin-error, #dc2626)"}}),!t.valid&&e.jsx("span",{style:{color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.75rem",marginTop:"0.25rem",display:"block"},children:t.error})]})})()]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Symbol"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:d,onChange:t=>c?.(t.target.value),placeholder:"e.g., MYTOKEN",disabled:o,style:{textTransform:"uppercase"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Icon URL"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e.jsx("input",{type:"text",className:"cedros-admin__input",value:u,onChange:t=>x?.(t.target.value),placeholder:"https://example.com/token-logo.png",disabled:o,style:{flex:1}}),u&&e.jsx("img",{src:u,alt:"Token icon preview",style:{width:32,height:32,borderRadius:"50%",border:"1px solid var(--cedros-admin-border, #e5e7eb)",objectFit:"cover"},onError:t=>{t.target.style.display="none"}})]}),e.jsx("div",{style:{fontSize:"0.7rem",color:"var(--cedros-admin-text-muted, #94a3b8)",marginTop:"0.25rem"},children:"Shown to customers during checkout"})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Decimals"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:n??6,onChange:t=>S?.(parseInt(t.target.value,10)||0),min:0,max:18,disabled:o,style:{width:"100px"}}),e.jsx("div",{style:{fontSize:"0.7rem",color:"var(--cedros-admin-text-muted, #94a3b8)",marginTop:"0.25rem"},children:"Most SPL tokens use 6 decimals (like USDC)"})]})]}),f&&y&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",fontFamily:"monospace",wordBreak:"break-all"},children:f}),a&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.25rem"},children:a})]})]})}function Z({label:b,value:f,onChange:h,disabled:n=!1,description:S}){const[o,a]=l.useState(new Set),[d,u]=l.useState(null),[c,x]=l.useState(""),v=Array.isArray(f)?f:[],E=t=>{a(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},p=()=>{h([...v,""]),u(v.length),x("")},I=(t,s)=>{const r=[...v];r[t]=s,h(r)},y=t=>{const s=v.filter((r,g)=>g!==t);h(s),a(r=>{const g=new Set;return r.forEach(_=>{_<t?g.add(_):_>t&&g.add(_-1)}),g})},T=t=>{u(t),x(v[t]||"")},C=()=>{d!==null&&(I(d,c),u(null),x(""))},w=()=>{d!==null&&v[d]===""&&y(d),u(null),x("")};return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"0.5rem"},children:[e.jsx("label",{className:"cedros-admin__field-label",style:{marginBottom:0},children:b}),e.jsxs("button",{type:"button",onClick:p,disabled:n,style:{display:"flex",alignItems:"center",gap:"0.25rem",padding:"0.25rem 0.5rem",fontSize:"0.75rem",border:"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.375rem",background:"var(--cedros-admin-bg, #fff)",cursor:n?"not-allowed":"pointer",opacity:n?.5:1},children:[j.Icons.plus,"Add"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[v.length===0&&e.jsx("div",{style:{padding:"1rem",textAlign:"center",color:"var(--cedros-admin-text-muted, #64748b)",fontSize:"0.875rem",border:"1px dashed var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem"},children:'No items. Click "Add" to create one.'}),v.map((t,s)=>{const r=o.has(s),g=d===s,_=t===N.REDACTED_VALUE;return e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem",background:"var(--cedros-admin-bg-muted, #f9fafb)",borderRadius:"0.375rem",border:"1px solid var(--cedros-admin-border, #e5e7eb)"},children:g?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"cedros-admin__input",value:c,onChange:i=>x(i.target.value),placeholder:"Enter wallet keypair...",autoFocus:!0,style:{flex:1,fontFamily:"monospace",fontSize:"0.75rem"},onKeyDown:i=>{i.key==="Enter"&&C(),i.key==="Escape"&&w()}}),e.jsx("button",{type:"button",onClick:C,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-success, #22c55e)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Save",children:j.Icons.check}),e.jsx("button",{type:"button",onClick:w,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-text-muted, #64748b)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Cancel",children:j.Icons.close})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{flex:1,fontFamily:"monospace",fontSize:"0.75rem",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r&&!_?t:_?"[REDACTED]":"••••••••••••••••••••"}),e.jsx("button",{type:"button",onClick:()=>E(s),disabled:n||_,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n||_?"not-allowed":"pointer",opacity:n||_?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:r?"Hide":"Show",children:r?j.Icons.eyeOff:j.Icons.eye}),e.jsx("button",{type:"button",onClick:()=>T(s),disabled:n,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:"Edit",children:j.Icons.settings}),e.jsx("button",{type:"button",onClick:()=>y(s),disabled:n,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,color:"var(--cedros-admin-error, #ef4444)"},title:"Delete",children:j.Icons.trash})]})},s)})]}),S&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.5rem"},children:S})]})}function q(b,f,h){const n=N.isSecretField(b,f),S=f.replace(/_/g," ").replace(/\b\w/g,u=>u.toUpperCase()),a=N.CONFIG_CATEGORIES[b]?.fields?.[f],d={isSecret:n,label:S,description:a?.description,hidden:a?.hidden,showWhen:a?.showWhen};return a?.type==="dropdown"&&a.options?{...d,type:"dropdown",options:a.options}:a?.type==="token_mint"?{...d,type:"token_mint"}:a?.type==="toggle"?{...d,type:"toggle"}:a?.type==="secret_array"?{...d,type:"secret_array",isSecret:!0}:a?.type==="solana_address"?{...d,type:"solana_address"}:a?.type==="number"?{...d,type:"number",unit:a.unit}:typeof h=="boolean"?{...d,type:"boolean"}:typeof h=="number"?{...d,type:"number",unit:a?.unit}:Array.isArray(h)?{...d,type:"array"}:typeof h=="object"&&h!==null?{...d,type:"object"}:{...d,type:"string"}}function X({category:b,config:f,originalConfig:h,isLoading:n=!1,onSave:S}){const[o,a]=l.useState(f),[d,u]=l.useState(new Set);l.useEffect(()=>{a(f)},[f]);const c=l.useMemo(()=>{const t={...o};for(const s of Object.keys(t))if(N.isSecretField(b,s)){const r=h[s],g=t[s];(g===N.REDACTED_VALUE||g===r)&&(t[s]=N.REDACTED_VALUE)}return t},[o,h,b]),x=l.useMemo(()=>{const t=o.token_mint;return typeof t!="string"||!t?!1:!M(t).valid},[o]),{status:v,error:E}=K.useAutosave({data:c,onSave:S,debounceMs:1500,enabled:!x}),p=l.useCallback((t,s)=>{a(r=>({...r,[t]:s}))},[]),I=l.useCallback(t=>{u(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},[]),y=t=>t?e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.25rem"},children:t}):null,T=(t,s)=>{const r=q(b,t,h[t]??s);if(r.type==="dropdown"&&r.options)return e.jsx(j.FormDropdown,{value:s,onChange:i=>p(t,i),options:r.options.map(i=>({value:i,label:i})),label:r.label,description:r.description,disabled:n});if(r.type==="token_mint")return e.jsx(P,{label:r.label,value:s,onChange:i=>p(t,i),decimals:o.token_decimals??6,onDecimalsChange:i=>p("token_decimals",i),disabled:n,description:r.description,customSymbol:o.custom_token_symbol||"",customIcon:o.custom_token_icon||"",onCustomSymbolChange:i=>p("custom_token_symbol",i),onCustomIconChange:i=>p("custom_token_icon",i)});if(r.type==="toggle")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx("button",{type:"button",role:"switch","aria-checked":s,onClick:()=>p(t,!s),disabled:n,style:{width:44,height:24,borderRadius:12,border:"none",backgroundColor:s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #d4d4d4)",cursor:n?"not-allowed":"pointer",position:"relative",transition:"background-color 0.2s",opacity:n?.5:1,flexShrink:0},children:e.jsx("span",{style:{position:"absolute",top:2,left:s?22:2,width:20,height:20,borderRadius:"50%",backgroundColor:"#fff",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}})}),e.jsx("span",{className:"cedros-admin__field-label",style:{marginBottom:0},children:r.label})]}),y(r.description)]});if(r.type==="solana_address"){const i=s||"",k=M(i);return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:r.label}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",className:`cedros-admin__input ${k.valid?"":"cedros-admin__input--error"}`,value:i,onChange:D=>p(t,D.target.value),disabled:n,placeholder:"e.g. 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",style:{width:"100%",fontFamily:"monospace",fontSize:"0.875rem",borderColor:k.valid?void 0:"var(--cedros-admin-error, #dc2626)",paddingRight:i&&k.valid?"2rem":void 0}}),i&&k.valid&&e.jsx("span",{style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",color:"var(--cedros-admin-success, #16a34a)",fontSize:"1rem"},title:"Valid Solana address",children:"✓"})]}),!k.valid&&e.jsx("span",{style:{color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.75rem",marginTop:"0.25rem",display:"block"},children:k.error}),y(r.description)]})}if(r.type==="boolean")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("label",{className:"cedros-admin__checkbox",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:i=>p(t,i.target.checked),disabled:n}),r.label]}),y(r.description)]});if(r.type==="number")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("label",{className:"cedros-admin__field-label",children:[r.label,r.unit&&e.jsxs("span",{className:"cedros-admin__field-unit",children:[" (",r.unit,")"]})]}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s,onChange:i=>p(t,parseFloat(i.target.value)||0),disabled:n}),y(r.description)]});if(r.type==="secret_array")return e.jsx(Z,{label:r.label,value:s,onChange:i=>p(t,i),disabled:n,description:r.description});if(r.type==="array"){const i=s;return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:r.label}),e.jsx("textarea",{className:"cedros-admin__textarea",value:i.join(`
|
|
2
|
-
`),onChange:k=>p(t,k.target.value.split(`
|
|
3
|
-
`).filter(Boolean)),placeholder:"One item per line",rows:3,disabled:n}),y(r.description)]})}if(r.type==="object")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:r.label}),e.jsx("textarea",{className:"cedros-admin__textarea cedros-admin__textarea--mono",value:JSON.stringify(s,null,2),onChange:i=>{try{p(t,JSON.parse(i.target.value))}catch{}},rows:5,disabled:n}),y(r.description)]});const g=d.has(t),_=r.isSecret&&!g&&s===N.REDACTED_VALUE?N.REDACTED_VALUE:s;return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("label",{className:"cedros-admin__field-label",children:[r.label,r.isSecret&&e.jsx("span",{className:"cedros-admin__field-secret",children:" (secret)"})]}),e.jsxs("div",{className:"cedros-admin__input-group",children:[e.jsx("input",{type:r.isSecret&&!g?"password":"text",className:"cedros-admin__input",value:_,onChange:i=>p(t,i.target.value),disabled:n,placeholder:r.isSecret?"••••••••":""}),r.isSecret&&e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>I(t),style:{padding:"0.5rem",minWidth:"auto"},title:g?"Hide":"Show",children:g?j.Icons.eyeOff:j.Icons.eye})]}),y(r.description)]})},C=Object.keys(o),w=t=>{const s=q(b,t,h[t]??o[t]);if(s.hidden||s.showWhen&&!o[s.showWhen])return!1;if(t==="token_decimals"){const r=o.token_mint;if(r&&V.STABLECOIN_METADATA[r])return!1}return!0};return e.jsxs("div",{className:"cedros-admin__config-editor",children:[e.jsx("div",{className:"cedros-admin__config-fields",children:C.filter(w).map(t=>e.jsx("div",{className:"cedros-admin__config-field",children:T(t,o[t])},t))}),e.jsx("div",{className:"cedros-admin__config-actions",children:e.jsx("div",{className:"cedros-admin__autosave-status",children:e.jsx(L.AutosaveIndicator,{status:v,error:E})})})]})}function Y({serverUrl:b,apiKey:f,authManager:h,category:n,title:S,description:o,enabledField:a="enabled",showEnabledToggle:d=!1}){const u=l.useMemo(()=>new N.ConfigApiClient(b,void 0,h),[b,h]),[c,x]=l.useState(null),[v,E]=l.useState([]),[p,I]=l.useState(!1),[y,T]=l.useState(!0),[C,w]=l.useState(null),[t,s]=l.useState(null),[r,g]=l.useState(!1),_=N.CONFIG_CATEGORIES[n]||{label:n,icon:"⚙️"},i=S||_.label,k=o||_.description,D=l.useCallback(async()=>{T(!0),w(null);try{const m=await u.getConfig(n,!0);x(m)}catch{x(null),w("Failed to load settings")}finally{T(!1)}},[u,n]);l.useEffect(()=>{D()},[D]);const B=l.useCallback(async()=>{try{const m=await u.getHistory(n,20);E(m.history)}catch{E([])}},[u,n]);l.useEffect(()=>{p&&B()},[p,B]);const U=l.useCallback(async m=>{await u.updateConfig(n,m,"Updated via admin dashboard")},[u,n]),F=l.useCallback(async m=>u.validateConfig(n,m),[u,n]),[z,O]=l.useState(!1),G=l.useCallback(async()=>{if(!c||z)return;const m=!!c.config[a],R=!m,W={...c.config,[a]:R};O(!0),x({...c,config:W});try{await u.updateConfig(n,W,`${R?"Enabled":"Disabled"} via admin dashboard`)}catch(H){x({...c,config:{...c.config,[a]:m}}),w(H instanceof Error?H.message:"Failed to save enabled state")}finally{O(!1)}},[c,u,n,a,z]),A=!!c?.config[a];return y&&!c?e.jsx("div",{className:"cedros-admin__section",children:e.jsxs("div",{className:"cedros-admin__loading",children:[j.Icons.loading," Loading ",i," settings..."]})}):e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx(j.ErrorBanner,{message:C,onRetry:D}),e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"cedros-admin__section-title",children:[e.jsx("span",{style:{marginRight:"0.5rem"},children:_.icon}),i]}),k&&e.jsx("p",{className:"cedros-admin__text-muted",style:{marginTop:"0.25rem"},children:k})]}),d&&c&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx("span",{style:{fontSize:"0.875rem",color:A?"var(--cedros-admin-text, #171717)":"var(--cedros-admin-muted, #737373)"},children:A?"Enabled":"Disabled"}),e.jsx("button",{type:"button",role:"switch","aria-checked":A,onClick:G,disabled:z,style:{width:44,height:24,borderRadius:12,border:"none",backgroundColor:A?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #d4d4d4)",cursor:z?"wait":"pointer",position:"relative",transition:"background-color 0.2s",flexShrink:0,opacity:z?.6:1},children:e.jsx("span",{style:{position:"absolute",top:2,left:A?22:2,width:20,height:20,borderRadius:"50%",backgroundColor:"#fff",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}})})]})]}),c&&e.jsxs("div",{className:"cedros-admin__settings-editor",style:{marginTop:"1rem",opacity:d&&!A?.6:1,pointerEvents:d&&!A?"none":"auto"},children:[d&&!A&&e.jsx("div",{style:{padding:"0.75rem 1rem",marginBottom:"1rem",backgroundColor:"var(--cedros-admin-warning-bg, #fef3c7)",border:"1px solid var(--cedros-admin-warning-border, #f59e0b)",borderRadius:"0.375rem",fontSize:"0.875rem",color:"var(--cedros-admin-warning-text, #92400e)",pointerEvents:"auto"},children:"This payment method is disabled. Enable it using the toggle above to accept payments."}),e.jsx(X,{category:c.category,config:c.config,originalConfig:c.config,onSave:U,onValidate:F})]}),p&&e.jsxs("div",{className:"cedros-admin__settings-history",style:{marginTop:"1.5rem"},children:[e.jsx("h4",{style:{marginBottom:"0.75rem",fontWeight:600},children:"Change History"}),v.length===0?e.jsx("p",{className:"cedros-admin__text-muted",children:"No history entries found."}):e.jsx("div",{className:"cedros-admin__settings-timeline",children:v.map(m=>e.jsxs("div",{className:"cedros-admin__settings-timeline-item",children:[e.jsx("div",{className:"cedros-admin__settings-timeline-dot"}),e.jsxs("div",{className:"cedros-admin__settings-timeline-content",children:[e.jsxs("div",{className:"cedros-admin__settings-timeline-header",children:[e.jsx("code",{children:m.configKey}),e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${m.action.toLowerCase()}`,children:m.action})]}),e.jsxs("div",{className:"cedros-admin__settings-timeline-meta",children:[j.formatDateTime(m.changedAt)," by ",m.changedBy]})]})]},m.id))})]}),t&&e.jsx("div",{style:{marginTop:"1rem",padding:"0.75rem 1rem",borderRadius:"0.375rem",backgroundColor:t.valid?"var(--cedros-admin-success-bg, #dcfce7)":"var(--cedros-admin-error-bg, #fef2f2)",border:`1px solid ${t.valid?"var(--cedros-admin-success-border, #86efac)":"var(--cedros-admin-error-border, #fecaca)"}`},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:600,color:t.valid?"var(--cedros-admin-success, #16a34a)":"var(--cedros-admin-error, #dc2626)",marginBottom:t.errors.length>0||t.warnings.length>0?"0.5rem":0},children:t.valid?"✓ Configuration is valid":"✗ Validation failed"}),t.errors.length>0&&e.jsx("ul",{style:{margin:0,paddingLeft:"1.25rem",color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.875rem"},children:t.errors.map((m,R)=>e.jsx("li",{children:m},R))}),t.warnings.length>0&&e.jsx("ul",{style:{margin:t.errors.length>0?"0.5rem 0 0":0,paddingLeft:"1.25rem",color:"var(--cedros-admin-warning, #ca8a04)",fontSize:"0.875rem"},children:t.warnings.map((m,R)=>e.jsx("li",{children:m},R))})]}),e.jsx("button",{type:"button",onClick:()=>s(null),style:{background:"none",border:"none",cursor:"pointer",padding:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)",fontSize:"1.25rem",lineHeight:1},title:"Dismiss",children:"×"})]})}),e.jsxs("div",{style:{marginTop:"1.5rem",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>I(!p),children:p?"Hide History":"History"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:r||!c,onClick:async()=>{if(c){g(!0),s(null);try{const m=await F(c.config);s(m)}catch(m){s({valid:!1,errors:[m instanceof Error?m.message:"Validation failed"],warnings:[]})}finally{g(!1)}}},children:r?"Validating...":"Validate"})]})]})}exports.SingleCategorySettings=Y;
|