@cedros/pay-react 1.1.17 → 1.1.18
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-BrXUD4l_.js → AISettingsSection-C-thWh51.js} +1 -1
- package/dist/{AISettingsSection--jn-BNmd.mjs → AISettingsSection-CD9IRyR1.mjs} +2 -2
- package/dist/{AutosaveIndicator-BQkm3cn8.js → AutosaveIndicator-DxemlKnX.js} +1 -1
- package/dist/{AutosaveIndicator-B3T328jH.mjs → AutosaveIndicator-G2CRN8hH.mjs} +1 -1
- package/dist/{CryptoButton-Dhxnk9d7.mjs → CryptoButton-BdOtL7w-.mjs} +1 -1
- package/dist/{CryptoButton-B4-oJ8lF.js → CryptoButton-N8kRfNDO.js} +1 -1
- package/dist/{FAQSection-BB1wJRsR.mjs → FAQSection-CyYK9OAN.mjs} +1 -1
- package/dist/{FAQSection-aoAz35MV.js → FAQSection-_pm1ekTe.js} +1 -1
- package/dist/{MessagingSection-DId-WJdU.js → MessagingSection-BHzf1Mhu.js} +1 -1
- package/dist/{MessagingSection-BG9O62ko.mjs → MessagingSection-DO2yPTvs.mjs} +2 -2
- package/dist/{PaymentSettingsSection-c13RAUxn.mjs → PaymentSettingsSection--Aqlne1F.mjs} +1 -1
- package/dist/{PaymentSettingsSection-D92IO4xJ.js → PaymentSettingsSection-DpENgoca.js} +1 -1
- package/dist/{SettingsSection-htem-WL3.mjs → SettingsSection-CGKKGXWz.mjs} +1 -1
- package/dist/{SettingsSection-DUxjXl2G.js → SettingsSection-DNoODw7i.js} +1 -1
- package/dist/{SingleCategorySettings-BIEs6s6Z.mjs → SingleCategorySettings-8DCtLcow.mjs} +22 -22
- package/dist/{SingleCategorySettings-CQ-osdzb.js → SingleCategorySettings-NLBYxM0O.js} +2 -2
- package/dist/{StorefrontSection-DcSoDx-k.js → StorefrontSection-BEOMtSAg.js} +1 -1
- package/dist/{StorefrontSection-CKTQt255.mjs → StorefrontSection-Mzr1H51w.mjs} +2 -2
- package/dist/{SubscriptionsSection-C0hYf7Hr.js → SubscriptionsSection-4b29i-41.js} +1 -1
- package/dist/{SubscriptionsSection-CONwHhT4.mjs → SubscriptionsSection-Dy1e15fe.mjs} +1 -1
- package/dist/components/admin/SingleCategorySettings.d.ts.map +1 -1
- package/dist/crypto-only.js +1 -1
- package/dist/crypto-only.mjs +3 -3
- package/dist/{index-2N_CMVAv.js → index-B-0trqeD.js} +1 -1
- package/dist/{index-C1hbnxn0.mjs → index-bbSf3B7-.mjs} +24 -24
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{sections-D2GMJuKq.js → sections-CKwGmrzV.js} +1 -1
- package/dist/{sections-DICaHGhz.mjs → sections-DpEdFL1B.mjs} +1 -1
- package/dist/stripe-only.js +1 -1
- package/dist/stripe-only.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),a=require("react"),b=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),a=require("react"),b=require("./index-B-0trqeD.js"),z=require("./AutosaveIndicator-DxemlKnX.js"),w=[{id:"not_set",label:"Disabled",provider:null},{id:"gemini-2.5-flash",label:"Gemini 2.5 Flash",provider:"gemini"},{id:"gemini-2.5-pro",label:"Gemini 2.5 Pro",provider:"gemini"},{id:"openai-4o",label:"OpenAI 4o",provider:"openai"},{id:"openai-5.1",label:"OpenAI 5.1",provider:"openai"},{id:"openai-5.2",label:"OpenAI 5.2",provider:"openai"}],P=[{task:"site_chat",label:"Site Chat",description:"The conversational model that crafts responses to customer messages",defaultPrompt:`You are a friendly and helpful shopping assistant for our store. Your role is to:
|
|
2
2
|
|
|
3
3
|
- Help customers find products that match their needs
|
|
4
4
|
- Answer questions about products, shipping, returns, and store policies
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
2
2
|
import { useState as u, useRef as S, useCallback as A, useEffect as T, useMemo as q } from "react";
|
|
3
|
-
import { $ as w, a0 as J, a2 as Y } from "./index-
|
|
4
|
-
import { A as X } from "./AutosaveIndicator-
|
|
3
|
+
import { $ as w, a0 as J, a2 as Y } from "./index-bbSf3B7-.mjs";
|
|
4
|
+
import { A as X } from "./AutosaveIndicator-G2CRN8hH.mjs";
|
|
5
5
|
const E = [
|
|
6
6
|
{ id: "not_set", label: "Disabled", provider: null },
|
|
7
7
|
{ id: "gemini-2.5-flash", label: "Gemini 2.5 Flash", provider: "gemini" },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),i=require("./index-
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),i=require("./index-B-0trqeD.js");function a({status:n,error:r}){return n==="idle"?null:e.jsxs("span",{className:`cedros-admin__autosave-indicator cedros-admin__autosave-indicator--${n}`,style:{display:"inline-flex",alignItems:"center",gap:"0.375rem",fontSize:"0.8125rem",color:n==="error"?"var(--cedros-admin-error, #ef4444)":"var(--cedros-admin-text-muted, #64748b)"},children:[n==="pending"&&e.jsx("span",{style:{opacity:.7},children:"Unsaved changes"}),n==="saving"&&e.jsxs(e.Fragment,{children:[i.Icons.loading,e.jsx("span",{children:"Saving..."})]}),n==="saved"&&e.jsxs(e.Fragment,{children:[i.Icons.check,e.jsx("span",{style:{color:"var(--cedros-admin-success, #22c55e)"},children:"Saved"})]}),n==="error"&&e.jsxs("span",{children:["Save failed",r?`: ${r}`:""]})]})}exports.AutosaveIndicator=a;
|
|
@@ -4,7 +4,7 @@ import { useWallet as be } from "@solana/wallet-adapter-react";
|
|
|
4
4
|
import { WalletReadyState as pe } from "@solana/wallet-adapter-base";
|
|
5
5
|
import { WalletIcon as Te } from "@solana/wallet-adapter-react-ui";
|
|
6
6
|
import { u as he, m as Z, i as n, a as Ie } from "./CedrosContext-BnJ2Cf7R.mjs";
|
|
7
|
-
import { a3 as Ee, k as We, T as Re, a4 as J, E as _e, F as fe, A as qe, D as ge, y as ze, z as we, B as ee, a5 as Me, a6 as De } from "./index-
|
|
7
|
+
import { a3 as Ee, k as We, T as Re, a4 as J, E as _e, F as fe, A as qe, D as ge, y as ze, z as we, B as ee, a5 as Me, a6 as De } from "./index-bbSf3B7-.mjs";
|
|
8
8
|
function Fe() {
|
|
9
9
|
const { x402Manager: g, walletManager: s } = he(), { publicKey: _, signTransaction: q } = be(), [X, d] = L({
|
|
10
10
|
status: "idle",
|
|
@@ -1 +1 @@
|
|
|
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"),t=require("./CedrosContext-C26DlvLF.js"),i=require("./index-2N_CMVAv.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
|
+
"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"),t=require("./CedrosContext-C26DlvLF.js"),i=require("./index-B-0trqeD.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,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as a, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { useState as r, useCallback as R, useEffect as V, useMemo as G } from "react";
|
|
3
|
-
import { a0 as H, a1 as Y, $ as l } from "./index-
|
|
3
|
+
import { a0 as H, a1 as Y, $ as l } from "./index-bbSf3B7-.mjs";
|
|
4
4
|
function M({ serverUrl: u, apiKey: d, pageSize: A = 20, authManager: o }) {
|
|
5
5
|
const [_, F] = r([]), [$, C] = r(!0), [S, N] = r(!1), [v, k] = r(null), [Q, I] = r(!1), [y, E] = r(""), [f, x] = r("all"), [q, w] = r(null), [T, b] = r(null), [n, m] = r({
|
|
6
6
|
question: "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),d=require("./index-2N_CMVAv.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
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),d=require("./index-B-0trqeD.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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),v=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),v=require("./index-B-0trqeD.js"),j=require("./Toggle-CsPSF8Dr.js"),I=require("./useAutosave-B2p6iwh8.js"),P=require("./AutosaveIndicator-DxemlKnX.js"),g={email_enabled:!1,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:h,apiKey:d,authManager:r}){const[l,_]=o.useState("messages"),[a,p]=o.useState(g),[y,w]=o.useState(!0),[N,S]=o.useState(!0),[k,b]=o.useState(null),[m,C]=o.useState(new Set),u=o.useCallback(async()=>{try{b(null);let s;const n="/admin/config/messaging";if(r?.isAuthenticated())s=await r.fetchWithAuth(n);else{const t={"Content-Type":"application/json"};d&&(t["X-API-Key"]=d);const c=await fetch(`${h}${n}`,{headers:t});if(!c.ok)throw new Error(`Failed to fetch: ${c.status}`);s=await c.json()}p({...g,...s.config})}catch{p(g),b("Could not load saved settings. Showing defaults.")}finally{w(!1),setTimeout(()=>S(!1),100)}},[h,d,r]);o.useEffect(()=>{u()},[u]);const E=o.useCallback(async s=>{const n="/admin/config/messaging",t={...s};m.has("smtp_password")||delete t.smtp_password,m.has("webhook_secret")||delete t.webhook_secret;const c=JSON.stringify({config:t});try{if(r?.isAuthenticated())await r.fetchWithAuth(n,{method:"PUT",body:c});else{const f={"Content-Type":"application/json"};d&&(f["X-API-Key"]=d);const x=await fetch(`${h}${n}`,{method:"PUT",headers:f,body:c});if(!x.ok)throw new Error(`Failed to save: ${x.status}`)}}catch{throw b("Failed to save messaging settings"),new Error("Save failed")}},[h,d,r,m]),{status:T,error:A}=I.useAutosave({data:a,onSave:E,debounceMs:1500,enabled:!N}),i=(s,n)=>{(s==="smtp_password"||s==="webhook_secret")&&C(t=>new Set(t).add(s)),p(t=>({...t,[s]:n}))};return y?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:[v.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 ${l==="messages"?"cedros-admin__tab--active":""}`,onClick:()=>_("messages"),children:"Messages"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${l==="email"?"cedros-admin__tab--active":""}`,onClick:()=>_("email"),children:"Email"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${l==="webhooks"?"cedros-admin__tab--active":""}`,onClick:()=>_("webhooks"),children:"Webhooks"}),e.jsx("div",{style:{flex:1}}),e.jsx(P.AutosaveIndicator,{status:T,error:A})]}),e.jsx(v.ErrorBanner,{message:k,onRetry:u}),e.jsxs("div",{className:"cedros-admin__tab-content",style:{marginTop:"1rem"},children:[l==="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(j.Toggle,{checked:a.email_enabled,onChange:s=>i("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(j.Toggle,{checked:a.webhook_enabled,onChange:s=>i("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"})]})]})]})]}),l==="email"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Configure your email provider for sending customer notifications."}),!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:"SMTP Host"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.smtp_host,onChange:s=>i("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=>i("smtp_port",parseInt(s.target.value)||587),placeholder:"587",disabled:!a.email_enabled,style:{maxWidth:120}})]}),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=>i("smtp_username",s.target.value),placeholder:"username or API key",disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Password"}),e.jsx("input",{type:"password",className:"cedros-admin__input",value:m.has("smtp_password")?a.smtp_password:"",onChange:s=>i("smtp_password",s.target.value),placeholder:a.smtp_password?"••••••••":"Enter password",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=>i("from_email",s.target.value),placeholder:"orders@yourstore.com",disabled:!a.email_enabled})]}),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=>i("from_name",s.target.value),placeholder:"Your Store",disabled:!a.email_enabled})]})]})]}),l==="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=>i("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:m.has("webhook_secret")?a.webhook_secret:"",onChange:s=>i("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=>i("webhook_timeout",parseInt(s.target.value)||30),placeholder:"30",disabled:!a.webhook_enabled,style:{maxWidth:120}})]})]})]})]})]})}exports.MessagingSection=W;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsxs as i, jsx as e } from "react/jsx-runtime";
|
|
2
2
|
import { useState as m, useCallback as w, useEffect as W } from "react";
|
|
3
|
-
import { $ as z, a0 as $ } from "./index-
|
|
3
|
+
import { $ as z, a0 as $ } from "./index-bbSf3B7-.mjs";
|
|
4
4
|
import { T as N } from "./Toggle-DAxIdpY4.mjs";
|
|
5
5
|
import { u as M } from "./useAutosave-YwMqRzqy.mjs";
|
|
6
|
-
import { A as F } from "./AutosaveIndicator-
|
|
6
|
+
import { A as F } from "./AutosaveIndicator-G2CRN8hH.mjs";
|
|
7
7
|
const g = {
|
|
8
8
|
email_enabled: !1,
|
|
9
9
|
smtp_host: "",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as i, jsx as e, Fragment as s } from "react/jsx-runtime";
|
|
2
2
|
import { useState as h } from "react";
|
|
3
|
-
import { S as m } from "./SingleCategorySettings-
|
|
3
|
+
import { S as m } from "./SingleCategorySettings-8DCtLcow.mjs";
|
|
4
4
|
function r({ href: o, children: a }) {
|
|
5
5
|
return /* @__PURE__ */ e(
|
|
6
6
|
"a",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),p=require("./SingleCategorySettings-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),p=require("./SingleCategorySettings-NLBYxM0O.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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("react"),g=require("./SingleCategorySettings-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("react"),g=require("./SingleCategorySettings-NLBYxM0O.js"),n=[{id:"logging",label:"Logging",category:"logging",description:"Configure log levels, format, and environment settings."},{id:"metrics",label:"Metrics",category:"metrics",description:"Configure metrics collection and API access for monitoring."},{id:"security",label:"Security",category:"security",description:"Configure CORS, rate limiting, and other security settings."}];function l({serverUrl:r,apiKey:c,authManager:o}){const[s,a]=d.useState("logging"),t=n.find(i=>i.id===s);return e.jsxs("div",{className:"cedros-admin__server-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Server"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure logging, metrics, and security settings."})]}),e.jsx("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:n.map(i=>e.jsx("button",{type:"button",className:`cedros-admin__tab ${s===i.id?"cedros-admin__tab--active":""}`,onClick:()=>a(i.id),children:i.label},i.id))}),e.jsx("div",{style:{marginTop:"1rem"},children:e.jsx(g.SingleCategorySettings,{serverUrl:r,apiKey:c,authManager:o,category:t.category,title:`${t.label} Settings`,description:t.description},t.category)})]})}exports.SettingsSection=l;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs as o, jsx as t, Fragment as U } from "react/jsx-runtime";
|
|
2
|
-
import { useState as k, useEffect as V, useMemo as H, useCallback as
|
|
3
|
-
import { $ as T, a2 as Z, a0 as Q, a7 as ee } from "./index-
|
|
2
|
+
import { useState as k, useEffect as V, useMemo as H, useCallback as M } from "react";
|
|
3
|
+
import { $ as T, a2 as Z, a0 as Q, a7 as ee } from "./index-bbSf3B7-.mjs";
|
|
4
4
|
import { u as te } from "./useAutosave-YwMqRzqy.mjs";
|
|
5
|
-
import { A as re } from "./AutosaveIndicator-
|
|
5
|
+
import { A as re } from "./AutosaveIndicator-G2CRN8hH.mjs";
|
|
6
6
|
import { S as O } from "./CedrosContext-BnJ2Cf7R.mjs";
|
|
7
7
|
import { PublicKey as ie } from "@solana/web3.js";
|
|
8
8
|
class ne {
|
|
@@ -672,7 +672,7 @@ function se({
|
|
|
672
672
|
});
|
|
673
673
|
}, f = () => {
|
|
674
674
|
d([...w, ""]), h(w.length), g("");
|
|
675
|
-
},
|
|
675
|
+
}, I = (e, i) => {
|
|
676
676
|
const r = [...w];
|
|
677
677
|
r[e] = i, d(r);
|
|
678
678
|
}, _ = (e) => {
|
|
@@ -686,7 +686,7 @@ function se({
|
|
|
686
686
|
}, R = (e) => {
|
|
687
687
|
h(e), g(w[e] || "");
|
|
688
688
|
}, x = () => {
|
|
689
|
-
m !== null && (
|
|
689
|
+
m !== null && (I(m, p), h(null), g(""));
|
|
690
690
|
}, C = () => {
|
|
691
691
|
m !== null && w[m] === "" && _(m), h(null), g("");
|
|
692
692
|
};
|
|
@@ -904,9 +904,9 @@ function ae({
|
|
|
904
904
|
onSave: S,
|
|
905
905
|
debounceMs: 1500,
|
|
906
906
|
enabled: !g
|
|
907
|
-
}), f =
|
|
907
|
+
}), f = M((e, i) => {
|
|
908
908
|
l((r) => ({ ...r, [e]: i }));
|
|
909
|
-
}, []),
|
|
909
|
+
}, []), I = M((e) => {
|
|
910
910
|
h((i) => {
|
|
911
911
|
const r = new Set(i);
|
|
912
912
|
return r.has(e) ? r.delete(e) : r.add(e), r;
|
|
@@ -1002,7 +1002,7 @@ function ae({
|
|
|
1002
1002
|
type: "text",
|
|
1003
1003
|
className: `cedros-admin__input ${N.valid ? "" : "cedros-admin__input--error"}`,
|
|
1004
1004
|
value: a,
|
|
1005
|
-
onChange: (
|
|
1005
|
+
onChange: (D) => f(e, D.target.value),
|
|
1006
1006
|
disabled: n,
|
|
1007
1007
|
placeholder: "e.g. 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
|
|
1008
1008
|
style: {
|
|
@@ -1146,7 +1146,7 @@ function ae({
|
|
|
1146
1146
|
{
|
|
1147
1147
|
type: "button",
|
|
1148
1148
|
className: "cedros-admin__button cedros-admin__button--ghost",
|
|
1149
|
-
onClick: () =>
|
|
1149
|
+
onClick: () => I(e),
|
|
1150
1150
|
style: { padding: "0.5rem", minWidth: "auto" },
|
|
1151
1151
|
title: y ? "Hide" : "Show",
|
|
1152
1152
|
children: y ? T.eyeOff : T.eye
|
|
@@ -1184,7 +1184,7 @@ function fe({
|
|
|
1184
1184
|
const h = H(
|
|
1185
1185
|
() => new ne(b, void 0, d),
|
|
1186
1186
|
[b, d]
|
|
1187
|
-
), [p, g] = k(null), [w, A] = k([]), [f,
|
|
1187
|
+
), [p, g] = k(null), [w, A] = k([]), [f, I] = k(!1), [_, R] = k(!0), [x, C] = k(null), [e, i] = k(null), [r, y] = k(!1), v = L[n] || { label: n, icon: "⚙️" }, a = S || v.label, N = c || v.description, D = M(async () => {
|
|
1188
1188
|
R(!0), C(null);
|
|
1189
1189
|
try {
|
|
1190
1190
|
const u = await h.getConfig(n, !0);
|
|
@@ -1196,9 +1196,9 @@ function fe({
|
|
|
1196
1196
|
}
|
|
1197
1197
|
}, [h, n]);
|
|
1198
1198
|
V(() => {
|
|
1199
|
-
|
|
1200
|
-
}, [
|
|
1201
|
-
const j =
|
|
1199
|
+
D();
|
|
1200
|
+
}, [D]);
|
|
1201
|
+
const j = M(async () => {
|
|
1202
1202
|
try {
|
|
1203
1203
|
const u = await h.getHistory(n, 20);
|
|
1204
1204
|
A(u.history);
|
|
@@ -1209,14 +1209,14 @@ function fe({
|
|
|
1209
1209
|
V(() => {
|
|
1210
1210
|
f && j();
|
|
1211
1211
|
}, [f, j]);
|
|
1212
|
-
const Y =
|
|
1213
|
-
await h.updateConfig(n, u, "Updated via admin dashboard")
|
|
1214
|
-
}, [h, n
|
|
1212
|
+
const Y = M(async (u) => {
|
|
1213
|
+
await h.updateConfig(n, u, "Updated via admin dashboard");
|
|
1214
|
+
}, [h, n]), F = M(async (u) => h.validateConfig(n, u), [h, n]), [W, K] = k(!1), X = M(async () => {
|
|
1215
1215
|
if (!p || W) return;
|
|
1216
|
-
const u = !!p.config[l],
|
|
1216
|
+
const u = !!p.config[l], P = !u, $ = { ...p.config, [l]: P };
|
|
1217
1217
|
K(!0), g({ ...p, config: $ });
|
|
1218
1218
|
try {
|
|
1219
|
-
await h.updateConfig(n, $, `${
|
|
1219
|
+
await h.updateConfig(n, $, `${P ? "Enabled" : "Disabled"} via admin dashboard`);
|
|
1220
1220
|
} catch (q) {
|
|
1221
1221
|
g({ ...p, config: { ...p.config, [l]: u } }), C(q instanceof Error ? q.message : "Failed to save enabled state");
|
|
1222
1222
|
} finally {
|
|
@@ -1229,7 +1229,7 @@ function fe({
|
|
|
1229
1229
|
a,
|
|
1230
1230
|
" settings..."
|
|
1231
1231
|
] }) }) : /* @__PURE__ */ o("div", { className: "cedros-admin__section", children: [
|
|
1232
|
-
/* @__PURE__ */ t(Q, { message: x, onRetry:
|
|
1232
|
+
/* @__PURE__ */ t(Q, { message: x, onRetry: D }),
|
|
1233
1233
|
/* @__PURE__ */ o("div", { className: "cedros-admin__section-header", children: [
|
|
1234
1234
|
/* @__PURE__ */ o("div", { children: [
|
|
1235
1235
|
/* @__PURE__ */ o("h3", { className: "cedros-admin__section-title", children: [
|
|
@@ -1353,8 +1353,8 @@ function fe({
|
|
|
1353
1353
|
color: e.valid ? "var(--cedros-admin-success, #16a34a)" : "var(--cedros-admin-error, #dc2626)",
|
|
1354
1354
|
marginBottom: e.errors.length > 0 || e.warnings.length > 0 ? "0.5rem" : 0
|
|
1355
1355
|
}, children: e.valid ? "✓ Configuration is valid" : "✗ Validation failed" }),
|
|
1356
|
-
e.errors.length > 0 && /* @__PURE__ */ t("ul", { style: { margin: 0, paddingLeft: "1.25rem", color: "var(--cedros-admin-error, #dc2626)", fontSize: "0.875rem" }, children: e.errors.map((u,
|
|
1357
|
-
e.warnings.length > 0 && /* @__PURE__ */ t("ul", { style: { margin: e.errors.length > 0 ? "0.5rem 0 0" : 0, paddingLeft: "1.25rem", color: "var(--cedros-admin-warning, #ca8a04)", fontSize: "0.875rem" }, children: e.warnings.map((u,
|
|
1356
|
+
e.errors.length > 0 && /* @__PURE__ */ t("ul", { style: { margin: 0, paddingLeft: "1.25rem", color: "var(--cedros-admin-error, #dc2626)", fontSize: "0.875rem" }, children: e.errors.map((u, P) => /* @__PURE__ */ t("li", { children: u }, P)) }),
|
|
1357
|
+
e.warnings.length > 0 && /* @__PURE__ */ t("ul", { style: { margin: e.errors.length > 0 ? "0.5rem 0 0" : 0, paddingLeft: "1.25rem", color: "var(--cedros-admin-warning, #ca8a04)", fontSize: "0.875rem" }, children: e.warnings.map((u, P) => /* @__PURE__ */ t("li", { children: u }, P)) })
|
|
1358
1358
|
] }),
|
|
1359
1359
|
/* @__PURE__ */ t(
|
|
1360
1360
|
"button",
|
|
@@ -1383,7 +1383,7 @@ function fe({
|
|
|
1383
1383
|
{
|
|
1384
1384
|
type: "button",
|
|
1385
1385
|
className: "cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",
|
|
1386
|
-
onClick: () =>
|
|
1386
|
+
onClick: () => I(!f),
|
|
1387
1387
|
children: f ? "Hide History" : "History"
|
|
1388
1388
|
}
|
|
1389
1389
|
),
|