shopify-chatbot-widget 0.9.3 → 0.9.4

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.
@@ -690,4 +690,4 @@ html body {
690
690
  userAgent: `).concat(navigator.userAgent,`
691
691
  timeBetweenLoadAndGet: `).concat(o-a,`
692
692
  visitorId: `).concat(f.visitorId,`
693
- components: `).concat(n8(u),"\n```")),[2,f]}})})}}}function Soe(){if(!(window.__fpjs_d_m||Math.random()>=.001))try{var e=new XMLHttpRequest;e.open("get","https://m1.openfpcdn.io/fingerprintjs/v".concat(N2,"/npm-monitoring"),!0),e.send()}catch(t){console.error(t)}}function xoe(e){var t;return e===void 0&&(e={}),rc(this,void 0,void 0,function(){var a,r,o;return ic(this,function(u){switch(u.label){case 0:return(!((t=e.monitoring)!==null&&t!==void 0)||t)&&Soe(),a=e.delayFallback,r=e.debug,[4,yoe(a)];case 1:return u.sent(),o=foe({cache:{},debug:r}),[2,boe(o,r)]}})})}var Coe={load:xoe,hashComponents:a8,componentsToDebugString:n8};const Eoe=()=>({checkOut:async t=>{try{const a=localStorage.getItem("company_username");if(!a)throw new Error("No company username found.");const r=await fetch(`${oi.apiUrl}checkout/shopify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,company_username:a})});if(!r.ok)throw new Error("Failed to initiate checkout.");const o=await r.json();o?.checkoutUrl?window.parent?.postMessage({type:"JAWEB_CHAT",action:"navigate",target:"_blank",url:o.checkoutUrl},"*"):alert("No checkout URL returned.")}catch(a){console.error("Checkout error:",a)}}}),woe=({colorCode:e,setOpen:t,Opened:a,onBack:r,sessionId:o})=>{const{items:u,loading:f,removeFromCart:m,refresh:g}=M2(o||""),{checkOut:p}=Eoe(),[v,x]=S.useState(!1),C=_=>{if(!_)return{symbol:"",value:0};const N=_.match(/[^0-9.,\s]+/),j=N?N[0]:"",L=parseFloat(_.replace(/[^0-9.]/g,""));return{symbol:j,value:isNaN(L)?0:L}},O=S.useMemo(()=>u.length?u.reduce((_,N)=>{const{value:j}=C(N.price);return _+j*N.quantity},0):0,[u]),T=async()=>{if(!o){sx.warning("No session found — please start a chat first.");return}x(!0);try{await p(o)}catch(_){sx.error("Checkout failed. Please try again."),console.error("Checkout error:",_)}finally{x(!1)}},M=J.jsx(Cl,{style:{fontSize:24,color:e||"#7F28F8"},spin:!0}),R=async _=>{await m(_,1),sx.info("Item removed from cart"),await g()};return J.jsxs("div",{style:{maxWidth:"100%",height:"100%",border:"1px solid #f0f0f0",borderRadius:8,display:"flex",flexDirection:"column",backgroundColor:"#fff",overflow:"hidden"},children:[J.jsxs("div",{style:{padding:"16px",display:"flex",alignItems:"center",borderBottom:"1px solid #f5f5f5",boxShadow:"0 2px 6px rgba(0,0,0,0.03)",zIndex:5,height:"8%"},children:[J.jsx(fr,{type:"text",icon:J.jsx(Xd,{}),onClick:r,style:{color:"#333",fontWeight:500},children:"Back"}),J.jsx("div",{style:{marginLeft:"auto"},children:J.jsx(Vd,{onClick:()=>t(!a),style:{fontSize:18,cursor:"pointer",color:"#555",transition:"color 0.2s ease"},onMouseEnter:_=>_.currentTarget.style.color=e||"#7F28F8",onMouseLeave:_=>_.currentTarget.style.color="#555"})})]}),J.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px",height:"66%"},children:[J.jsxs("h3",{style:{fontWeight:600,marginBottom:16},children:[J.jsx(uz,{style:{marginRight:8}}),"Your Cart (",u.length,")"]}),f?J.jsx("div",{style:{textAlign:"center",marginTop:40},children:J.jsx(tc,{indicator:M})}):u.length===0?J.jsx("div",{style:{textAlign:"center",color:"#888",marginTop:60},children:"Your cart is empty 🛒"}):J.jsx("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",height:"80%",gap:"12px",paddingRight:"4px"},children:u.map(_=>{const{symbol:N,value:j}=C(_.price),L=j*_.quantity;return J.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",background:"#fafafa",borderRadius:10,padding:"12px 10px",transition:"all 0.2s ease"},className:"hover:shadow-sm",children:[J.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[J.jsx("img",{src:_.variantImage,alt:_.name,style:{width:64,height:64,borderRadius:8,objectFit:"cover",backgroundColor:"#f3f3f3"}}),J.jsxs("div",{children:[J.jsx("p",{style:{fontWeight:600,color:"#222",marginBottom:4},children:_.name}),J.jsxs("p",{style:{fontSize:13,color:"#777",margin:0},children:["Qty: ",_.quantity]})]})]}),J.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[J.jsxs("span",{style:{fontWeight:600},children:[N,L.toLocaleString()]}),J.jsx(az,{onClick:()=>R(_.variantId),style:{cursor:"pointer",color:"#999",fontSize:16,transition:"color 0.2s ease"},onMouseEnter:z=>z.currentTarget.style.color="#e74c3c",onMouseLeave:z=>z.currentTarget.style.color="#999"})]})]},_.variantId)})})]}),J.jsxs("div",{style:{position:"sticky",bottom:0,left:0,right:0,background:"#fff",borderTop:"1px solid #f0f0f0",padding:"16px 20px",boxShadow:"0 -3px 10px rgba(0,0,0,0.05)",zIndex:10},children:[J.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"10px",fontWeight:600,color:"#222"},children:[J.jsx("span",{children:"Subtotal:"}),J.jsx("span",{children:O.toLocaleString()})]}),J.jsx(fr,{type:"primary",block:!0,size:"large",onClick:T,loading:v,disabled:u.length===0,style:{backgroundColor:e||"black",borderColor:e||"black",borderRadius:10,fontWeight:600},children:J.jsx("span",{style:{color:"white"},children:"CHECKOUT"})})]})]})},Ooe=()=>{const[e,t]=S.useState(!1),[a,r]=S.useState("sessions"),[o,u]=S.useState(null),[f,m]=S.useState(!1),[g,p]=S.useState(""),[v,x]=S.useState(""),[C,O]=S.useState(!1),{chatbotLogo:T,colorCode:M,messagesSuggestions:R,disableForm:_,merchantPhone:N,userType:j,isFetchingDetails:L,calendly:z,disbleCheckout:V,chatbotName:B,setMessagesSuggestions:D}=O7(),[P,H]=S.useState(null),K=J.jsx(Cl,{style:{fontSize:24,color:M||"#7F28F8"},spin:!0}),X=()=>{if(!_&&!f){r("create");return}else{const U=crypto.randomUUID();u(U),x(T),p(B),O(!0),r("messenger")}};S.useEffect(()=>{(async()=>{try{let G=localStorage.getItem("visitor_id");G||(G=(await(await Coe.load()).get()).visitorId,localStorage.setItem("visitor_id",G));const se=await(await fetch(`${oi.apiUrl}register-ip/`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({visitor_id:G})})).json();se.visitor&&se.country?(localStorage.setItem("country",se.country),H({visitorId:se.visitor,country:se.country}),m(se.has_user_info||!1)):console.warn("Backend did not return country")}catch(G){console.error("Failed to fetch or send visitor info",G)}})()},[]);const W=(U,G,Z)=>{u(U),p(G),x(Z),O(!1),r("messenger")};S.useEffect(()=>{const U=G=>{const Z=G.data||{};if(Z.type==="JAWEB_CHAT")switch(Z.action){case"open-ready":t(!0);break;case"closed":t(!1);break;case"start-session":console.log("[Chatbot] start-session message received"),X();break}};return window.addEventListener("message",U),()=>window.removeEventListener("message",U)},[]);const Q=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"open"},"*")},ie=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"close"},"*")};return S.useEffect(()=>{L||window.parent?.postMessage({type:"JAWEB_CHAT",action:"ready-confirm"},"*")},[L]),J.jsx("div",{children:e&&J.jsx("div",{className:"chatbot-box",children:L?J.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:J.jsx(tc,{indicator:K,tip:"..."})}):J.jsxs(Ij,{mode:"sync",children:[a==="sessions"&&J.jsx(Ti.div,{initial:{opacity:0,x:-30},animate:{opacity:1,x:0},exit:{opacity:0,x:30},transition:{duration:.3},style:{height:"100%"},children:J.jsx(UQ,{chatbotLogo:T,Phone:N||"",colorCode:M,visitorId:P?.visitorId||"",Opened:e,setOpen:U=>U?Q():ie(),onNewSession:X,onSessionSelect:W})},"sessions"),a==="create"&&J.jsx(Ti.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-30},transition:{duration:.3},children:J.jsx(Tae,{colorCode:M,visitorId:P?.visitorId||"",country:P?.country||"",onBack:()=>r("sessions"),onCreate:U=>{u(U.session_id),m(U.hasInfo),r("messenger")}})},"create"),a==="cartView"&&J.jsx(Ti.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-30},transition:{duration:.3},style:{height:"100%"},children:J.jsx(woe,{setOpen:U=>U?Q():ie(),sessionId:o,Opened:e,chatbotLogo:T,colorCode:M,onBack:()=>{O(!1),r("messenger")}})},"create"),a==="messenger"&&o&&J.jsx(Ti.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.3},children:J.jsx(fre,{sessionId:o,chatbotLogo:v||T,agentName:g||B||"Ai Assistant",colorCode:M,messagesSuggestions:R,newSession:C,disableForm:_,calendly:z??"",setOpen:U=>U?Q():ie(),setNewSession:O,Opened:e,setView:r,userType:j,disbleCheckout:V,setMessagesSuggestions:D})},"messenger")]})})})},r8="jaweb-chatbot-container";if(!document.getElementById(r8)){const e=document.createElement("div");e.id=r8,document.body.appendChild(e),vV.createRoot(e).render(J.jsx(Ooe,{}))}})();
693
+ components: `).concat(n8(u),"\n```")),[2,f]}})})}}}function Soe(){if(!(window.__fpjs_d_m||Math.random()>=.001))try{var e=new XMLHttpRequest;e.open("get","https://m1.openfpcdn.io/fingerprintjs/v".concat(N2,"/npm-monitoring"),!0),e.send()}catch(t){console.error(t)}}function xoe(e){var t;return e===void 0&&(e={}),rc(this,void 0,void 0,function(){var a,r,o;return ic(this,function(u){switch(u.label){case 0:return(!((t=e.monitoring)!==null&&t!==void 0)||t)&&Soe(),a=e.delayFallback,r=e.debug,[4,yoe(a)];case 1:return u.sent(),o=foe({cache:{},debug:r}),[2,boe(o,r)]}})})}var Coe={load:xoe,hashComponents:a8,componentsToDebugString:n8};const Eoe=()=>({checkOut:async t=>{try{const a=localStorage.getItem("company_username");if(!a)throw new Error("No company username found.");const r=await fetch(`${oi.apiUrl}checkout/shopify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,company_username:a})});if(!r.ok)throw new Error("Failed to initiate checkout.");const o=await r.json();o?.checkoutUrl?window.parent?.postMessage({type:"JAWEB_CHAT",action:"navigate",target:"_blank",url:o.checkoutUrl},"*"):alert("No checkout URL returned.")}catch(a){console.error("Checkout error:",a)}}}),woe=({colorCode:e,setOpen:t,Opened:a,onBack:r,sessionId:o})=>{const{items:u,loading:f,removeFromCart:m,refresh:g}=M2(o||""),{checkOut:p}=Eoe(),[v,x]=S.useState(!1),C=_=>{if(!_)return{symbol:"",value:0};const N=_.match(/[^0-9.,\s]+/),j=N?N[0]:"",L=parseFloat(_.replace(/[^0-9.]/g,""));return{symbol:j,value:isNaN(L)?0:L}},O=S.useMemo(()=>u.length?u.reduce((_,N)=>{const{value:j}=C(N.price);return _+j*N.quantity},0):0,[u]),T=async()=>{if(!o){sx.warning("No session found — please start a chat first.");return}x(!0);try{await p(o)}catch(_){sx.error("Checkout failed. Please try again."),console.error("Checkout error:",_)}finally{x(!1)}},M=J.jsx(Cl,{style:{fontSize:24,color:e||"#7F28F8"},spin:!0}),R=async _=>{await m(_,1),sx.info("Item removed from cart"),await g()};return J.jsxs("div",{style:{maxWidth:"100%",height:"100%",border:"1px solid #f0f0f0",borderRadius:8,display:"flex",flexDirection:"column",backgroundColor:"#fff",overflow:"hidden"},children:[J.jsxs("div",{style:{padding:"16px",display:"flex",alignItems:"center",borderBottom:"1px solid #f5f5f5",boxShadow:"0 2px 6px rgba(0,0,0,0.03)",zIndex:5,height:"8%"},children:[J.jsx(fr,{type:"text",icon:J.jsx(Xd,{}),onClick:r,style:{color:"#333",fontWeight:500},children:"Back"}),J.jsx("div",{style:{marginLeft:"auto"},children:J.jsx(Vd,{onClick:()=>t(!a),style:{fontSize:18,cursor:"pointer",color:"#555",transition:"color 0.2s ease"},onMouseEnter:_=>_.currentTarget.style.color=e||"#7F28F8",onMouseLeave:_=>_.currentTarget.style.color="#555"})})]}),J.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px",height:"66%"},children:[J.jsxs("h3",{style:{fontWeight:600,marginBottom:16},children:[J.jsx(uz,{style:{marginRight:8}}),"Your Cart (",u.length,")"]}),f?J.jsx("div",{style:{textAlign:"center",marginTop:40},children:J.jsx(tc,{indicator:M})}):u.length===0?J.jsx("div",{style:{textAlign:"center",color:"#888",marginTop:60},children:"Your cart is empty 🛒"}):J.jsx("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",height:"80%",gap:"12px",paddingRight:"4px"},children:u.map(_=>{const{symbol:N,value:j}=C(_.price),L=j*_.quantity;return J.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",background:"#fafafa",borderRadius:10,padding:"12px 10px",transition:"all 0.2s ease"},className:"hover:shadow-sm",children:[J.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[J.jsx("img",{src:_.variantImage,alt:_.name,style:{width:64,height:64,borderRadius:8,objectFit:"cover",backgroundColor:"#f3f3f3"}}),J.jsxs("div",{children:[J.jsx("p",{style:{fontWeight:600,color:"#222",marginBottom:4},children:_.name}),J.jsxs("p",{style:{fontSize:13,color:"#777",margin:0},children:["Qty: ",_.quantity]})]})]}),J.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[J.jsxs("span",{style:{fontWeight:600},children:[N,L.toLocaleString()]}),J.jsx(az,{onClick:()=>R(_.variantId),style:{cursor:"pointer",color:"#999",fontSize:16,transition:"color 0.2s ease"},onMouseEnter:z=>z.currentTarget.style.color="#e74c3c",onMouseLeave:z=>z.currentTarget.style.color="#999"})]})]},_.variantId)})})]}),J.jsxs("div",{style:{position:"sticky",bottom:0,left:0,right:0,background:"#fff",borderTop:"1px solid #f0f0f0",padding:"16px 20px",boxShadow:"0 -3px 10px rgba(0,0,0,0.05)",zIndex:10},children:[J.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"10px",fontWeight:600,color:"#222"},children:[J.jsx("span",{children:"Subtotal:"}),J.jsx("span",{children:O.toLocaleString()})]}),J.jsx(fr,{type:"primary",block:!0,size:"large",onClick:T,loading:v,disabled:u.length===0,style:{backgroundColor:e||"black",borderColor:e||"black",borderRadius:10,fontWeight:600},children:J.jsx("span",{style:{color:"white"},children:"CHECKOUT"})})]})]})},Ooe=()=>{const[e,t]=S.useState(!0),[a,r]=S.useState("sessions"),[o,u]=S.useState(null),[f,m]=S.useState(!1),[g,p]=S.useState(""),[v,x]=S.useState(""),[C,O]=S.useState(!1),{chatbotLogo:T,colorCode:M,messagesSuggestions:R,disableForm:_,merchantPhone:N,userType:j,isFetchingDetails:L,calendly:z,disbleCheckout:V,chatbotName:B,setMessagesSuggestions:D}=O7(),[P,H]=S.useState(null),K=J.jsx(Cl,{style:{fontSize:24,color:M||"#7F28F8"},spin:!0}),X=()=>{if(console.log(_),console.log(f),!_&&!f){r("create");return}else{const U=crypto.randomUUID();u(U),x(T),p(B),O(!0),r("messenger")}};S.useEffect(()=>{(async()=>{try{let G=localStorage.getItem("visitor_id");G||(G=(await(await Coe.load()).get()).visitorId,localStorage.setItem("visitor_id",G));const se=await(await fetch(`${oi.apiUrl}register-ip/`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({visitor_id:G})})).json();se.visitor&&se.country?(localStorage.setItem("country",se.country),H({visitorId:se.visitor,country:se.country}),m(se.has_user_info||!1)):console.warn("Backend did not return country")}catch(G){console.error("Failed to fetch or send visitor info",G)}})()},[]);const W=(U,G,Z)=>{u(U),p(G),x(Z),O(!1),r("messenger")};S.useEffect(()=>{const U=G=>{const Z=G.data||{};if(Z.type==="JAWEB_CHAT")switch(Z.action){case"open-ready":t(!0);break;case"closed":t(!1);break;case"start-session":console.log("[Chatbot] start-session message received"),X();break}};return window.addEventListener("message",U),()=>window.removeEventListener("message",U)},[]);const Q=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"open"},"*")},ie=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"close"},"*")};return S.useEffect(()=>{L||window.parent?.postMessage({type:"JAWEB_CHAT",action:"ready-confirm"},"*")},[L]),J.jsx("div",{children:e&&J.jsx("div",{className:"chatbot-box",children:L?J.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:J.jsx(tc,{indicator:K,tip:"..."})}):J.jsxs(Ij,{mode:"sync",children:[a==="sessions"&&J.jsx(Ti.div,{initial:{opacity:0,x:-30},animate:{opacity:1,x:0},exit:{opacity:0,x:30},transition:{duration:.3},style:{height:"100%"},children:J.jsx(UQ,{chatbotLogo:T,Phone:N||"",colorCode:M,visitorId:P?.visitorId||"",Opened:e,setOpen:U=>U?Q():ie(),onNewSession:X,onSessionSelect:W})},"sessions"),a==="create"&&J.jsx(Ti.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-30},transition:{duration:.3},children:J.jsx(Tae,{colorCode:M,visitorId:P?.visitorId||"",country:P?.country||"",onBack:()=>r("sessions"),onCreate:U=>{u(U.session_id),m(U.hasInfo),r("messenger")}})},"create"),a==="cartView"&&J.jsx(Ti.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-30},transition:{duration:.3},style:{height:"100%"},children:J.jsx(woe,{setOpen:U=>U?Q():ie(),sessionId:o,Opened:e,chatbotLogo:T,colorCode:M,onBack:()=>{O(!1),r("messenger")}})},"create"),a==="messenger"&&o&&J.jsx(Ti.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.3},children:J.jsx(fre,{sessionId:o,chatbotLogo:v||T,agentName:g||B||"Ai Assistant",colorCode:M,messagesSuggestions:R,newSession:C,disableForm:_,calendly:z??"",setOpen:U=>U?Q():ie(),setNewSession:O,Opened:e,setView:r,userType:j,disbleCheckout:V,setMessagesSuggestions:D})},"messenger")]})})})},r8="jaweb-chatbot-container";if(!document.getElementById(r8)){const e=document.createElement("div");e.id=r8,document.body.appendChild(e),vV.createRoot(e).render(J.jsx(Ooe,{}))}})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shopify-chatbot-widget",
3
3
  "private": false,
4
- "version": "0.9.3",
4
+ "version": "0.9.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -12,7 +12,7 @@ import { motion, AnimatePresence } from 'framer-motion';
12
12
  import CartLayout from './components/Cart/Index';
13
13
 
14
14
  const Chatbot: React.FC = () => {
15
- const [open, setOpen] = useState(false);
15
+ const [open, setOpen] = useState(true);
16
16
  const [viewMode, setViewMode] = useState<'sessions' | 'create' | 'messenger' | 'cartView' >('sessions');
17
17
  const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
18
18
  const [HasInfo, setHasInfo] = useState(false);
@@ -39,6 +39,8 @@ const Chatbot: React.FC = () => {
39
39
  const antIcon = <LoadingOutlined style={{ fontSize: 24, color: colorCode||'#7F28F8' }} spin />;
40
40
 
41
41
  const handleNewSessionClick = () => {
42
+ console.log(disableForm)
43
+ console.log(HasInfo)
42
44
  if (!disableForm && !HasInfo) {
43
45
  setViewMode('create');
44
46
  return;