brainerce 1.36.1 → 1.36.3
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/bot/bootstrap.global.js +6 -7
- package/dist/bot/index.js +9 -10
- package/dist/bot/index.mjs +9 -10
- package/dist/index.d.mts +40 -4
- package/dist/index.d.ts +40 -4
- package/dist/index.js +79 -7
- package/dist/index.mjs +79 -7
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";(()=>{var U="https://api.brainerce.com",j=new Set(["he","ar"]),L={en:{online:"Online",placeholder:"Ask anything\u2026",error:"Something went wrong \u2014 please try again.",leaveMessage:"Leave a message for the team",yourEmail:"Your email",yourMessage:"Your message",send:"Send",sent:"Thanks! The team will get back to you by email.",close:"Close",expand:"Expand",collapse:"Collapse",searching:"Searching the store\u2026",addToCart:"Add to cart",added:"Added",view:"View",chooseOptions:"View product",results:"From the store",poweredBy:"Powered by Brainerce",addFailed:"I couldn\u2019t add that to the cart \u2014 try the button on the product card."},he:{online:"\u05DE\u05D7\u05D5\u05D1\u05E8",placeholder:"\u05E9\u05D0\u05DC\u05D5 \u05D0\u05D5\u05EA\u05D9 \u05D4\u05DB\u05DC\u2026",error:"\u05DE\u05E9\u05D4\u05D5 \u05D4\u05E9\u05EA\u05D1\u05E9 \u2014 \u05E0\u05E1\u05D5 \u05E9\u05D5\u05D1.",leaveMessage:"\u05D4\u05E9\u05D0\u05D9\u05E8\u05D5 \u05D4\u05D5\u05D3\u05E2\u05D4 \u05DC\u05E6\u05D5\u05D5\u05EA",yourEmail:"\u05D4\u05D0\u05D9\u05DE\u05D9\u05D9\u05DC \u05E9\u05DC\u05DB\u05DD",yourMessage:"\u05D4\u05D4\u05D5\u05D3\u05E2\u05D4 \u05E9\u05DC\u05DB\u05DD",send:"\u05E9\u05DC\u05D9\u05D7\u05D4",sent:"\u05EA\u05D5\u05D3\u05D4! \u05D4\u05E6\u05D5\u05D5\u05EA \u05D9\u05D7\u05D6\u05D5\u05E8 \u05D0\u05DC\u05D9\u05DB\u05DD \u05D1\u05DE\u05D9\u05D9\u05DC.",close:"\u05E1\u05D2\u05D9\u05E8\u05D4",expand:"\u05D4\u05E8\u05D7\u05D1\u05D4",collapse:"\u05DB\u05D9\u05D5\u05D5\u05E5",searching:"\u05DE\u05D7\u05E4\u05E9 \u05D1\u05D7\u05E0\u05D5\u05EA\u2026",addToCart:"\u05D4\u05D5\u05E1\u05E4\u05D4 \u05DC\u05E1\u05DC",added:"\u05E0\u05D5\u05E1\u05E3",view:"\u05E6\u05E4\u05D9\u05D9\u05D4",chooseOptions:"\u05DC\u05E6\u05E4\u05D5\u05EA \u05D1\u05DE\u05D5\u05E6\u05E8",results:"\u05DE\u05EA\u05D5\u05DA \u05D4\u05D7\u05E0\u05D5\u05EA",poweredBy:"\u05DE\u05D5\u05E4\u05E2\u05DC \u05E2\u05DC \u05D9\u05D3\u05D9 Brainerce",addFailed:"\u05DC\u05D0 \u05D4\u05E6\u05DC\u05D7\u05EA\u05D9 \u05DC\u05D4\u05D5\u05E1\u05D9\u05E3 \u05DC\u05E1\u05DC \u2014 \u05E0\u05E1\u05D5 \u05D3\u05E8\u05DA \u05D4\u05DB\u05E4\u05EA\u05D5\u05E8 \u05D1\u05DB\u05E8\u05D8\u05D9\u05E1 \u05D4\u05DE\u05D5\u05E6\u05E8."}},H={chat:'<svg viewBox="0 0 24 24" fill="none"><path d="M12 3C7.03 3 3 6.58 3 11c0 2.04.86 3.9 2.28 5.32-.15 1.23-.62 2.39-1.1 3.21-.13.23.05.52.31.47 1.56-.27 3.07-.93 4.13-1.62A10.6 10.6 0 0 0 12 19c4.97 0 9-3.58 9-8s-4.03-8-9-8Z" fill="currentColor"/></svg>',close:'<svg viewBox="0 0 24 24" fill="none"><path d="M6 6l12 12M18 6L6 18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',expand:'<svg viewBox="0 0 24 24" fill="none"><path d="M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',collapse:'<svg viewBox="0 0 24 24" fill="none"><path d="M20 10h-6V4M4 14h6v6M20 4l-6 6M4 20l6-6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',mail:'<svg viewBox="0 0 24 24" fill="none"><rect x="3.5" y="5.5" width="17" height="13" rx="2.5" stroke="currentColor" stroke-width="1.7"/><path d="m4.5 7.5 7.5 5.5 7.5-5.5" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>',send:'<svg viewBox="0 0 24 24" fill="none"><path d="M4.4 11.2 19 4.6c.7-.3 1.4.4 1.1 1.1l-6.6 14.6c-.3.7-1.3.6-1.5-.1l-1.7-5.4a1 1 0 0 0-.6-.6l-5.4-1.7c-.7-.2-.8-1.2-.1-1.5Z" fill="currentColor"/></svg>',cart:'<svg viewBox="0 0 24 24" fill="none"><path d="M3 4h2l2.4 11.2A2 2 0 0 0 9.36 17H17.5a2 2 0 0 0 1.95-1.55L21 8H6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/><circle cx="10" cy="20.5" r="1.4" fill="currentColor"/><circle cx="17" cy="20.5" r="1.4" fill="currentColor"/></svg>',check:'<svg viewBox="0 0 24 24" fill="none"><path d="m5 12.5 4.5 4.5L19 7.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',arrow:'<svg viewBox="0 0 24 24" fill="none"><path d="M7 17 17 7M9 7h8v8" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',sparkle:'<svg viewBox="0 0 24 24" fill="none"><path d="M12 3v2M12 19v2M3 12h2M19 12h2M6.34 6.34l1.42 1.42M16.24 16.24l1.42 1.42M6.34 17.66l1.42-1.42M16.24 7.76l1.42-1.42" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><circle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g8kkIWPJv3Fv90JIPk8lupuMmlUBuL10BMoWuDC6+8PwaADIJaa+DJMX7a1IuO3shF5Ww8X+8JfFYLIugZNcP2t/3sNNHQ+7CmhBuHatgCTDOCL+cDWpo8QuDIwZZjhwDNEykwPHoHsYOkmCpEU5OP/9arTnpKHiSwEqP42HiPgdZa5MQIZG8Vzk9A8y/3IszBpLmPQnc+nB3DOD6EyZ61wzzDRcOh7xjRGYq5mCxObXkCyesfqy7p2gtC2H4TmphuUR3UTPLISlFlIRWuBMgLlFyjF8SjWC5+RicdYenDqbiabi+ag6MQdF3yWh4mAkKveOJ+wNQ1WKMwMumyTFX8wGBzBovJaY8rHGmks0aT00j4/YO4ORJByLeSTkmapYsyz1dCyTJXM++y0FO6ULkZW3Eqt++gjv792O9H3b8cFPH2PHRTK1uvMeyuTzUCFJReENAa6fTcKNU5NQdoSEdP8YFK74B24JnJiwHlpgYQjr3w7UDV/INvEgHukQdNQOc8lkfk6RG9LKh2EpAbqiwd/i88ZI8+31CdjVPBUH22fgWGcyzpCB5CUy77umTMG1hhScq0zGyZszcP7GZFy5EonrlwJwK2csM70q+MoVV4kR02z95r8Yov8eqIBDQ873JWPZBeS/DoxAV94egqzqUfhE7IMdtYH4WhSK3VUR+K4iEgdLI3GsOArHCyPw861gnC2eiAv53si9NBL5Z4Yg/xDR2reOuJxhx/hcdvb/Ozj/X+wq94A9XinEAAAAAElFTkSuQmCC",P=typeof DOMParser<"u"?new DOMParser:null;function m(p){let e=(H[p]??H.chat).replace("<svg ",'<svg xmlns="http://www.w3.org/2000/svg" '),t=P?.parseFromString(e,"image/svg+xml")?.documentElement;return!t||t.nodeName==="parsererror"?document.createTextNode(""):(t.setAttribute("aria-hidden","true"),t.setAttribute("class","bb-ic"),t)}function F(p){let e=new Uint8Array(16);crypto.getRandomValues(e);let n=btoa(String.fromCharCode(...e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`${p}${n}`}function B(p){return/^\/(?!\/)/.test(p)||/^https?:\/\//i.test(p)}var R=/\*\*([^*\n]+)\*\*|\[([^\]\n]+)\]\(([^)\s]+)\)/g;function D(p,e){let n=0;R.lastIndex=0;for(let t=R.exec(e);t;t=R.exec(e)){if(t.index>n&&p.appendChild(document.createTextNode(e.slice(n,t.index))),t[1]!==void 0){let i=document.createElement("strong");i.textContent=t[1],p.appendChild(i)}else if(B(t[3])){let i=document.createElement("a");i.href=t[3],i.target="_blank",i.rel="noopener noreferrer",i.textContent=t[2],p.appendChild(i)}else p.appendChild(document.createTextNode(t[2]));n=t.index+t[0].length}n<e.length&&p.appendChild(document.createTextNode(e.slice(n)))}function O(p,e){p.replaceChildren();let n=e.split(`
|
|
1
|
+
"use strict";(()=>{var U="https://api.brainerce.com",z=new Set(["he","ar"]),L={en:{online:"Online",placeholder:"Ask anything\u2026",error:"Something went wrong \u2014 please try again.",leaveMessage:"Leave a message for the team",yourEmail:"Your email",yourMessage:"Your message",send:"Send",sent:"Thanks! The team will get back to you by email.",close:"Close",expand:"Expand",collapse:"Collapse",searching:"Searching the store\u2026",addToCart:"Add to cart",added:"Added",view:"View",chooseOptions:"View product",results:"From the store",poweredBy:"Powered by Brainerce",addFailed:"I couldn\u2019t add that to the cart \u2014 try the button on the product card."},he:{online:"\u05DE\u05D7\u05D5\u05D1\u05E8",placeholder:"\u05E9\u05D0\u05DC\u05D5 \u05D0\u05D5\u05EA\u05D9 \u05D4\u05DB\u05DC\u2026",error:"\u05DE\u05E9\u05D4\u05D5 \u05D4\u05E9\u05EA\u05D1\u05E9 \u2014 \u05E0\u05E1\u05D5 \u05E9\u05D5\u05D1.",leaveMessage:"\u05D4\u05E9\u05D0\u05D9\u05E8\u05D5 \u05D4\u05D5\u05D3\u05E2\u05D4 \u05DC\u05E6\u05D5\u05D5\u05EA",yourEmail:"\u05D4\u05D0\u05D9\u05DE\u05D9\u05D9\u05DC \u05E9\u05DC\u05DB\u05DD",yourMessage:"\u05D4\u05D4\u05D5\u05D3\u05E2\u05D4 \u05E9\u05DC\u05DB\u05DD",send:"\u05E9\u05DC\u05D9\u05D7\u05D4",sent:"\u05EA\u05D5\u05D3\u05D4! \u05D4\u05E6\u05D5\u05D5\u05EA \u05D9\u05D7\u05D6\u05D5\u05E8 \u05D0\u05DC\u05D9\u05DB\u05DD \u05D1\u05DE\u05D9\u05D9\u05DC.",close:"\u05E1\u05D2\u05D9\u05E8\u05D4",expand:"\u05D4\u05E8\u05D7\u05D1\u05D4",collapse:"\u05DB\u05D9\u05D5\u05D5\u05E5",searching:"\u05DE\u05D7\u05E4\u05E9 \u05D1\u05D7\u05E0\u05D5\u05EA\u2026",addToCart:"\u05D4\u05D5\u05E1\u05E4\u05D4 \u05DC\u05E1\u05DC",added:"\u05E0\u05D5\u05E1\u05E3",view:"\u05E6\u05E4\u05D9\u05D9\u05D4",chooseOptions:"\u05DC\u05E6\u05E4\u05D5\u05EA \u05D1\u05DE\u05D5\u05E6\u05E8",results:"\u05DE\u05EA\u05D5\u05DA \u05D4\u05D7\u05E0\u05D5\u05EA",poweredBy:"\u05DE\u05D5\u05E4\u05E2\u05DC \u05E2\u05DC \u05D9\u05D3\u05D9 Brainerce",addFailed:"\u05DC\u05D0 \u05D4\u05E6\u05DC\u05D7\u05EA\u05D9 \u05DC\u05D4\u05D5\u05E1\u05D9\u05E3 \u05DC\u05E1\u05DC \u2014 \u05E0\u05E1\u05D5 \u05D3\u05E8\u05DA \u05D4\u05DB\u05E4\u05EA\u05D5\u05E8 \u05D1\u05DB\u05E8\u05D8\u05D9\u05E1 \u05D4\u05DE\u05D5\u05E6\u05E8."}},H={chat:'<svg viewBox="0 0 24 24" fill="none"><path d="M12 3C7.03 3 3 6.58 3 11c0 2.04.86 3.9 2.28 5.32-.15 1.23-.62 2.39-1.1 3.21-.13.23.05.52.31.47 1.56-.27 3.07-.93 4.13-1.62A10.6 10.6 0 0 0 12 19c4.97 0 9-3.58 9-8s-4.03-8-9-8Z" fill="currentColor"/></svg>',close:'<svg viewBox="0 0 24 24" fill="none"><path d="M6 6l12 12M18 6L6 18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',expand:'<svg viewBox="0 0 24 24" fill="none"><path d="M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',collapse:'<svg viewBox="0 0 24 24" fill="none"><path d="M20 10h-6V4M4 14h6v6M20 4l-6 6M4 20l6-6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',mail:'<svg viewBox="0 0 24 24" fill="none"><rect x="3.5" y="5.5" width="17" height="13" rx="2.5" stroke="currentColor" stroke-width="1.7"/><path d="m4.5 7.5 7.5 5.5 7.5-5.5" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>',send:'<svg viewBox="0 0 24 24" fill="none"><path d="M4.4 11.2 19 4.6c.7-.3 1.4.4 1.1 1.1l-6.6 14.6c-.3.7-1.3.6-1.5-.1l-1.7-5.4a1 1 0 0 0-.6-.6l-5.4-1.7c-.7-.2-.8-1.2-.1-1.5Z" fill="currentColor"/></svg>',cart:'<svg viewBox="0 0 24 24" fill="none"><path d="M3 4h2l2.4 11.2A2 2 0 0 0 9.36 17H17.5a2 2 0 0 0 1.95-1.55L21 8H6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/><circle cx="10" cy="20.5" r="1.4" fill="currentColor"/><circle cx="17" cy="20.5" r="1.4" fill="currentColor"/></svg>',check:'<svg viewBox="0 0 24 24" fill="none"><path d="m5 12.5 4.5 4.5L19 7.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',arrow:'<svg viewBox="0 0 24 24" fill="none"><path d="M7 17 17 7M9 7h8v8" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',sparkle:'<svg viewBox="0 0 24 24" fill="none"><path d="M12 3v2M12 19v2M3 12h2M19 12h2M6.34 6.34l1.42 1.42M16.24 16.24l1.42 1.42M6.34 17.66l1.42-1.42M16.24 7.76l1.42-1.42" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><circle cx="12" cy="12" r="3.5" fill="currentColor"/></svg>'},j="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAPoAAAD6AG1e1JrAAARlElEQVR42pVZB1RU19rdM0NvIzAw1GfDDqj0XgQUo0LQDCrGaKLRREHFFqNEYoqap0lejMZn9FmiJv7E3hUMIkUgiJRhCkOZDgIaxUbT+c+5M4Ok/H/Wu2vdhWvOzD377m9/+/vOJ/B/X6xsZJvsQ7ZVLvZxK5HjlIcL7mdwe8hZVI/KgXDsXtSO3wmx/1bUBm60bAxab9cYtIDb4J/ClfvFmkrHu9gIx9raVo7g8quGWtiXe1pZFbgiOp+H5DODkPCDNRIzzIFsNt0L/+XFJuDMzuKAbRlOO4px1q0CN4bfQN24S2gIuARJ+CFI4vZDkXACj+P3oTd+CdRxCaiLGglFhCsaIyLxLGyoSU+QCQHO5Yr9nYY0jTcbIR2DiJphSCn1gOCWE+JzuBDkWCKjH+jfXwIIOIeQbUFZq8I1ZwmuDRWh2LsRwqBSSCZdQeO0WnRNr4du+kXcF2wy/WXRFJNvVh9cKEwvPt750eUjbZtP7Xma4T/0xGJr02Npjtz2WAtbXRh4ymjrOFWMZWJ9CN6S+GKZ0AuZJe5YnuuIdWdtkZlpiehok78F9yUyLSk4IS66yHDVS44SvyaIoqsgnqHE0xQ1dKnbTM5nhtilH+Q5TiuEfajCeWTcr319vXU6/fX84aPfqq08o+rAC5fDIa5oRMCmr+atf5YKjiyWE6t6DQubpiBDHIYssY/5ptKh2HHNGbmEzexsK3ITkLo/h5yElIaVYU6EK66NyB3ZgtvBTaiaIof8DR0Btsvk5PpR3NmX2E6hCjgFdHDcwu7Bwlu785vDRQRYd3d3LwX48stvj9TC1Fth5hmjgukY7b5DJ1Tk85bS2oc7Iza0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4ygNLZkZZr+aGRKQAjNfAtLDLsfB0bGIAWlnJwm0Htk+iROlS8CorC847rElarVWMWCU8Tgo7q162PqrmTDy+jVmaNloS09N3wDMPqgDg8kkIWPJv3Fv90JIPk8lupuMmlUBuL10BMoWuDC6+8PwaADIJaa+DJMX7a1IuO3shF5Ww8X+8JfFYLIugZNcP2t/3sNNHQ+7CmhBuHatgCTDOCL+cDWpo8QuDIwZZjhwDNEykwPHoHsYOkmCpEU5OP/9arTnpKHiSwEqP42HiPgdZa5MQIZG8Vzk9A8y/3IszBpLmPQnc+nB3DOD6EyZ61wzzDRcOh7xjRGYq5mCxObXkCyesfqy7p2gtC2H4TmphuUR3UTPLISlFlIRWuBMgLlFyjF8SjWC5+RicdYenDqbiabi+ag6MQdF3yWh4mAkKveOJ+wNQ1WKMwMumyTFX8wGBzBovJaY8rHGmks0aT00j4/YO4ORJByLeSTkmapYsyz1dCyTJXM++y0FO6ULkZW3Eqt++gjv792O9H3b8cFPH2PHRTK1uvMeyuTzUCFJReENAa6fTcKNU5NQdoSEdP8YFK74B24JnJiwHlpgYQjr3w7UDV/INvEgHukQdNQOc8lkfk6RG9LKh2EpAbqiwd/i88ZI8+31CdjVPBUH22fgWGcyzpCB5CUy77umTMG1hhScq0zGyZszcP7GZFy5EonrlwJwK2csM70q+MoVV4kR02z95r8Yov8eqIBDQ873JWPZBeS/DoxAV94egqzqUfhE7IMdtYH4WhSK3VUR+K4iEgdLI3GsOArHCyPw861gnC2eiAv53si9NBL5Z4Yg/xDR2reOuJxhx/hcdvb/Ozj/X+wq94A9XinEAAAAAElFTkSuQmCC",P=typeof DOMParser<"u"?new DOMParser:null;function m(p){let e=(H[p]??H.chat).replace("<svg ",'<svg xmlns="http://www.w3.org/2000/svg" '),t=P?.parseFromString(e,"image/svg+xml")?.documentElement;return!t||t.nodeName==="parsererror"?document.createTextNode(""):(t.setAttribute("aria-hidden","true"),t.setAttribute("class","bb-ic"),t)}function F(p){let e=new Uint8Array(16);crypto.getRandomValues(e);let n=btoa(String.fromCharCode(...e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`${p}${n}`}function B(p){return/^\/(?!\/)/.test(p)||/^https?:\/\//i.test(p)}var R=/\*\*([^*\n]+)\*\*|\[([^\]\n]+)\]\(([^)\s]+)\)/g;function D(p,e){let n=0;R.lastIndex=0;for(let t=R.exec(e);t;t=R.exec(e)){if(t.index>n&&p.appendChild(document.createTextNode(e.slice(n,t.index))),t[1]!==void 0){let i=document.createElement("strong");i.textContent=t[1],p.appendChild(i)}else if(B(t[3])){let i=document.createElement("a");i.href=t[3],i.target="_blank",i.rel="noopener noreferrer",i.textContent=t[2],p.appendChild(i)}else p.appendChild(document.createTextNode(t[2]));n=t.index+t[0].length}n<e.length&&p.appendChild(document.createTextNode(e.slice(n)))}function O(p,e){p.replaceChildren();let n=e.split(`
|
|
2
2
|
`),t=null,i=null;for(let o of n){let r=/^\s*[-•*]\s+(.*)$/.exec(o);if(r){i=null,t||(t=document.createElement("ul"),p.appendChild(t));let d=document.createElement("li");D(d,r[1]),t.appendChild(d);continue}if(t=null,!o.trim()){i=null;continue}i?i.appendChild(document.createElement("br")):(i=document.createElement("p"),p.appendChild(i)),D(i,o)}}var S=class p{constructor(e){this.settings={enabled:!1};this.locale="en";this.sessionId=null;this.conversationId=null;this.busy=!1;this.opened=!1;this.expanded=!1;this.destroyed=!1;this.pendingText="";this.cardsRow=null;this.cardIds=new Set;this.prevBodyOverflow=null;this.connectionId=e.connectionId,this.baseUrl=(e.baseUrl||U).replace(/\/$/,""),this.storageKey=`brainerce-bot:${this.connectionId}`,this.onAddToCart=e.onAddToCart}static async mount(e){if(!e?.connectionId)return console.warn("[BrainerceBot] connectionId is required"),null;let n=new p(e);return await n.boot(e.target??document.body)?n:null}destroy(){this.destroyed=!0,this.prevBodyOverflow!==null&&(document.body.style.overflow=this.prevBodyOverflow,this.prevBodyOverflow=null),this.host?.remove()}async boot(e){try{let n=await fetch(`${this.baseUrl}/api/storefront-bot/${encodeURIComponent(this.connectionId)}/settings`);if(!n.ok)return!1;this.settings=await n.json()}catch{return!1}return this.settings.enabled?(this.locale=this.settings.languages?.[0]??"en",this.restoreIds(),this.render(e),this.settings.displayMode==="auto_open"&&setTimeout(()=>!this.destroyed&&this.open(),3e3),!0):!1}t(e){return(L[this.locale]??L.en)[e]??L.en[e]??e}restoreIds(){try{let e=localStorage.getItem(this.storageKey);if(e){let n=JSON.parse(e);this.sessionId=n.sessionId??null,this.conversationId=n.conversationId??null}}catch{}}persistIds(){try{localStorage.setItem(this.storageKey,JSON.stringify({sessionId:this.sessionId,conversationId:this.conversationId}))}catch{}}css(e,n,t){let i=this.settings.bubbleShape==="square",o=i?"14px":"22px",r=i?"8px":"15px",d="5px",a=this.settings.displayMode??"floating",l=a==="side_rail",s=a==="full_screen";return`
|
|
3
3
|
:host { all: initial; }
|
|
4
4
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0;
|
|
@@ -168,6 +168,7 @@
|
|
|
168
168
|
.bb-btn-add:hover { filter: brightness(1.08); }
|
|
169
169
|
.bb-btn-add[data-state="busy"] { opacity: .65; pointer-events: none; }
|
|
170
170
|
.bb-btn-add[data-state="done"] { background: #059669; pointer-events: none; }
|
|
171
|
+
.bb-btn.bb-sq { flex: 0 0 auto; padding: 0; width: var(--bb-btn-h); }
|
|
171
172
|
.bb-btn-ghost { background: #fff; border: 1px solid #e3e5ec; color: #3c4150; flex: 0 0 auto; padding: 0 11px; }
|
|
172
173
|
.bb-btn-ghost:hover { background: #f6f7f9; border-color: #d5d8e1; }
|
|
173
174
|
.bb-btn-ghost.bb-wide { flex: 1; color: ${e}; border-color: color-mix(in srgb, ${e} 35%, #e3e5ec); }
|
|
@@ -192,11 +193,9 @@
|
|
|
192
193
|
.bb-chipv:hover { border-color: color-mix(in srgb, ${e} 50%, #e3e5ec); }
|
|
193
194
|
.bb-chipv.sel { background: ${e}; border-color: ${e}; color: #fff; }
|
|
194
195
|
.bb-chipv.off { opacity: .35; pointer-events: none; }
|
|
195
|
-
.bb-pick-foot { display: flex; align-items: center;
|
|
196
|
-
gap: 6px; margin-top: 2px; }
|
|
197
|
-
.bb-pick-foot .bb-btn { flex: 0 0 auto; padding: 0 11px; }
|
|
196
|
+
.bb-pick-foot { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
|
|
198
197
|
.bb-pick-price { font-size: 12.5px; font-weight: 700; color: #14161f;
|
|
199
|
-
font-variant-numeric: tabular-nums; }
|
|
198
|
+
font-variant-numeric: tabular-nums; flex: 1; }
|
|
200
199
|
|
|
201
200
|
/* ---- starter chips -------------------------------------------------- */
|
|
202
201
|
.bb-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 4px 14px 12px; background: #f7f8fa; }
|
|
@@ -246,6 +245,6 @@
|
|
|
246
245
|
transition: color .12s ease; }
|
|
247
246
|
.bb-foot a:hover { color: #6b7280; }
|
|
248
247
|
.bb-foot-mark { width: 14px; height: 14px; border-radius: 3px; display: block; }
|
|
249
|
-
`}render(e){let n=this.settings.accentColor||"#6366F1",t=
|
|
248
|
+
`}render(e){let n=this.settings.accentColor||"#6366F1",t=z.has(this.locale)?"rtl":"ltr",i=this.settings.position==="start"?"left":"right",o=t==="rtl"?i==="left"?"right":"left":i,r=this.settings.displayName||"Assistant";this.host=document.createElement("div"),this.host.setAttribute("data-brainerce-bot",this.connectionId),this.root=this.host.attachShadow({mode:"open"});let d=document.createElement("style");d.textContent=this.css(n,t,o),this.root.appendChild(d);let a=document.createElement("div");a.className="bb",this.root.appendChild(a);let l=document.createElement("div");l.className="bb-scrim",l.addEventListener("click",()=>{this.expanded?this.toggleExpand():this.close()}),a.appendChild(l),this.windowEl=document.createElement("div"),this.windowEl.className="bb-window",a.appendChild(this.windowEl);let s=document.createElement("div");s.className="bb-header";let b=document.createElement("span");if(b.className="bb-avatar",this.settings.avatarUrl&&B(this.settings.avatarUrl)){let g=document.createElement("img");g.src=this.settings.avatarUrl,g.alt="",b.appendChild(g)}else b.appendChild(m("sparkle"));let u=document.createElement("span");u.className="bb-head-main";let h=document.createElement("span");h.className="bb-name",h.textContent=r;let w=document.createElement("span");w.className="bb-status",w.textContent=this.t("online"),u.appendChild(h),u.appendChild(w);let v=document.createElement("span");v.className="bb-actions",(this.settings.displayMode??"floating")!=="full_screen"&&this.settings.allowExpand!==!1&&(this.expandBtn=this.iconButton("expand",this.t("expand"),()=>this.toggleExpand()),v.appendChild(this.expandBtn)),v.appendChild(this.iconButton("mail",this.t("leaveMessage"),()=>this.toggleEscalation())),v.appendChild(this.iconButton("close",this.t("close"),()=>this.close())),s.appendChild(b),s.appendChild(u),s.appendChild(v),this.windowEl.appendChild(s),this.messagesEl=document.createElement("div"),this.messagesEl.className="bb-msgs",this.windowEl.appendChild(this.messagesEl),this.chipsEl=document.createElement("div"),this.chipsEl.className="bb-chips";for(let g of this.settings.starterQuestions??[]){let A=document.createElement("button");A.className="bb-chip",A.textContent=g,A.addEventListener("click",()=>this.send(g)),this.chipsEl.appendChild(A)}this.windowEl.appendChild(this.chipsEl);let c=document.createElement("div");c.className="bb-esc";let k=document.createElement("span");k.className="bb-esc-title",k.textContent=this.t("leaveMessage");let E=document.createElement("input");E.type="email",E.name="email",E.placeholder=this.t("yourEmail");let C=document.createElement("textarea");C.name="message",C.rows=2,C.placeholder=this.t("yourMessage");let I=document.createElement("button");I.type="button",I.className="bb-esc-send",I.textContent=this.t("send"),I.addEventListener("click",()=>this.submitEscalation(c)),c.appendChild(k),c.appendChild(E),c.appendChild(C),c.appendChild(I),this.windowEl.appendChild(c);let f=document.createElement("div");f.className="bb-composer",this.inputEl=document.createElement("textarea"),this.inputEl.className="bb-input",this.inputEl.rows=1,this.inputEl.maxLength=4e3,this.inputEl.placeholder=this.t("placeholder"),this.inputEl.addEventListener("keydown",g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),this.send(this.inputEl?.value??""))}),this.inputEl.addEventListener("input",()=>this.syncSendState()),this.sendBtn=document.createElement("button"),this.sendBtn.className="bb-send",this.sendBtn.disabled=!0,this.sendBtn.setAttribute("aria-label",this.t("send")),this.sendBtn.appendChild(m("send")),this.sendBtn.addEventListener("click",()=>this.send(this.inputEl?.value??"")),f.appendChild(this.inputEl),f.appendChild(this.sendBtn),this.windowEl.appendChild(f);let M=document.createElement("div");M.className="bb-foot";let x=document.createElement("a");x.href="https://brainerce.com",x.target="_blank",x.rel="noopener noreferrer";let N=document.createElement("img");if(N.src=j,N.alt="",N.className="bb-foot-mark",x.appendChild(N),x.appendChild(document.createTextNode(this.t("poweredBy"))),M.appendChild(x),this.windowEl.appendChild(M),this.launcherEl=document.createElement("button"),this.launcherEl.className="bb-launcher",this.launcherEl.setAttribute("aria-label",r),this.settings.avatarUrl&&B(this.settings.avatarUrl)){let g=document.createElement("img");g.src=this.settings.avatarUrl,g.alt="",this.launcherEl.appendChild(g)}else{let g=m("chat");g.classList.add("bb-l-chat"),this.launcherEl.appendChild(g)}let T=m("close");T.classList.add("bb-l-close"),this.launcherEl.appendChild(T),this.launcherEl.addEventListener("click",()=>this.opened?this.close():this.open()),a.appendChild(this.launcherEl),e.appendChild(this.host)}iconButton(e,n,t){let i=document.createElement("button");return i.className="bb-iconbtn",i.title=n,i.setAttribute("aria-label",n),i.appendChild(m(e)),i.addEventListener("click",t),i}syncSendState(){this.sendBtn&&(this.sendBtn.disabled=!(this.inputEl?.value??"").trim()||this.busy)}open(){if(!this.windowEl||this.opened)return;this.opened=!0;let e=this.root?.querySelector(".bb");e?.classList.add("open");let n=(this.settings.displayMode??"floating")==="full_screen"||window.innerWidth<=520;e?.classList.toggle("big",n||this.expanded),this.syncBodyScroll(),this.messagesEl&&this.messagesEl.childElementCount===0&&this.primeThread(),this.inputEl?.focus()}close(){this.opened=!1;let e=this.root?.querySelector(".bb");e?.classList.remove("open"),this.expanded||e?.classList.remove("big"),this.syncBodyScroll()}syncBodyScroll(){let e=this.opened&&!!this.root?.querySelector(".bb")?.classList.contains("big");e&&this.prevBodyOverflow===null?(this.prevBodyOverflow=document.body.style.overflow||"",document.body.style.overflow="hidden"):!e&&this.prevBodyOverflow!==null&&(document.body.style.overflow=this.prevBodyOverflow,this.prevBodyOverflow=null)}toggleExpand(){if(this.expanded=!this.expanded,this.root?.querySelector(".bb")?.classList.toggle("expanded",this.expanded),this.root?.querySelector(".bb")?.classList.toggle("big",this.expanded),this.syncBodyScroll(),this.expandBtn){this.expandBtn.replaceChildren(m(this.expanded?"collapse":"expand"));let e=this.t(this.expanded?"collapse":"expand");this.expandBtn.title=e,this.expandBtn.setAttribute("aria-label",e)}}async primeThread(){if(this.conversationId&&this.sessionId)try{let e=await fetch(`${this.baseUrl}/api/storefront-bot/${encodeURIComponent(this.connectionId)}/conversations/${encodeURIComponent(this.conversationId)}?limit=50`,{headers:{"X-Bot-Session":this.sessionId}});if(e.ok){let n=await e.json();for(let t of n.data){let i=this.appendMessage(t.role==="assistant"?"bot":"user","");O(i,t.content)}if(n.data.length>0){this.chipsEl?.remove();return}}else this.conversationId=null,this.sessionId=null,this.persistIds()}catch{}if(this.settings.greeting){let e=this.appendMessage("bot","");O(e,this.settings.greeting)}}async send(e){let n=e.trim();if(!n||this.busy)return;this.busy=!0,this.inputEl&&(this.inputEl.value=""),this.syncSendState(),this.chipsEl?.remove(),this.appendMessage("user",n);let t=this.appendTyping();this.pendingText="",this.cardsRow=null,this.cardIds=new Set;let i=null;try{let o=await fetch(`${this.baseUrl}/api/storefront-bot/${encodeURIComponent(this.connectionId)}/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:n,turnId:F("trn_"),...this.conversationId?{conversationId:this.conversationId}:{},...this.sessionId?{anonymousSessionId:this.sessionId}:{},locale:this.locale})});if(!o.ok||!o.body)throw new Error(`chat failed (${o.status})`);let r=o.body.getReader(),d=new TextDecoder,a="";for(;;){let{value:l,done:s}=await r.read();if(s)break;a+=d.decode(l,{stream:!0});let b;for(;(b=a.indexOf(`
|
|
250
249
|
|
|
251
|
-
`))>=0;){let u=a.slice(0,b);if(a=a.slice(b+2),!u.startsWith("data: "))continue;let h;try{h=JSON.parse(u.slice(6))}catch{continue}i=this.handleFrame(h,t,i)}}i&&this.pendingText&&O(i,this.pendingText)}catch{this.appendMessage("err",this.t("error"))}finally{t.remove(),this.busy=!1,this.syncSendState()}}handleFrame(e,n,t){switch(e.type){case"connected":return this.conversationId=e.conversationId||this.conversationId,this.sessionId=e.anonymousSessionId||this.sessionId,this.persistIds(),t;case"token":return t||(n.remove(),t=this.appendMessage("bot","")),this.pendingText+=e.text,t.textContent=this.pendingText,this.scrollDown(),t;case"tool":return n.classList.toggle("searching",e.status==="running"),t;case"card":return this.appendCard(e.card),t;case"action":return this.handleAction(e),t;case"error":return this.appendMessage("err",e.message||this.t("error")),t;case"escalate_offer":return this.openEscalation(),t;case"done":default:return t}}appendCard(e){if(!this.messagesEl||this.cardIds.has(e.productId))return;if(this.cardIds.add(e.productId),!this.cardsRow){let s=document.createElement("div");s.className="bb-shelf";let b=document.createElement("div");b.className="bb-shelf-cap",b.textContent=this.t("results"),this.cardsRow=document.createElement("div"),this.cardsRow.className="bb-cards",s.appendChild(b),s.appendChild(this.cardsRow),this.messagesEl.appendChild(s)}let n=B(e.url)?e.url:null,t=document.createElement("div");t.className="bb-card";let i=()=>{this.beacon(e.botRef),n&&(window.location.href=n)},o=document.createElement("span");if(o.className="bb-card-img",e.imageUrl&&B(e.imageUrl)){let s=document.createElement("img");s.src=e.imageUrl,s.alt="",s.loading="lazy",o.appendChild(s)}else o.appendChild(m("cart"));o.addEventListener("click",i),t.appendChild(o);let r=document.createElement("span");r.className="bb-card-body";let d=document.createElement("span");d.className="bb-card-title",d.textContent=e.title,d.addEventListener("click",i);let a=document.createElement("span");a.className="bb-card-price",a.textContent=e.price.formatted,r.appendChild(d),r.appendChild(a);let l=document.createElement("span");if(l.className="bb-card-cta",e.requiresOptions){let s=document.createElement("button");s.className="bb-btn bb-btn-add",s.setAttribute("aria-label",this.t("addToCart")),s.appendChild(m("cart")),e.variants?.length?s.addEventListener("click",()=>this.togglePicker(r,e,o)):s.addEventListener("click",i),l.appendChild(s)}else{let s=document.createElement("button");s.className="bb-btn bb-btn-add",s.
|
|
250
|
+
`))>=0;){let u=a.slice(0,b);if(a=a.slice(b+2),!u.startsWith("data: "))continue;let h;try{h=JSON.parse(u.slice(6))}catch{continue}i=this.handleFrame(h,t,i)}}i&&this.pendingText&&O(i,this.pendingText)}catch{this.appendMessage("err",this.t("error"))}finally{t.remove(),this.busy=!1,this.syncSendState()}}handleFrame(e,n,t){switch(e.type){case"connected":return this.conversationId=e.conversationId||this.conversationId,this.sessionId=e.anonymousSessionId||this.sessionId,this.persistIds(),t;case"token":return t||(n.remove(),t=this.appendMessage("bot","")),this.pendingText+=e.text,t.textContent=this.pendingText,this.scrollDown(),t;case"tool":return n.classList.toggle("searching",e.status==="running"),t;case"card":return this.appendCard(e.card),t;case"action":return this.handleAction(e),t;case"error":return this.appendMessage("err",e.message||this.t("error")),t;case"escalate_offer":return this.openEscalation(),t;case"done":default:return t}}appendCard(e){if(!this.messagesEl||this.cardIds.has(e.productId))return;if(this.cardIds.add(e.productId),!this.cardsRow){let s=document.createElement("div");s.className="bb-shelf";let b=document.createElement("div");b.className="bb-shelf-cap",b.textContent=this.t("results"),this.cardsRow=document.createElement("div"),this.cardsRow.className="bb-cards",s.appendChild(b),s.appendChild(this.cardsRow),this.messagesEl.appendChild(s)}let n=B(e.url)?e.url:null,t=document.createElement("div");t.className="bb-card";let i=()=>{this.beacon(e.botRef),n&&(window.location.href=n)},o=document.createElement("span");if(o.className="bb-card-img",e.imageUrl&&B(e.imageUrl)){let s=document.createElement("img");s.src=e.imageUrl,s.alt="",s.loading="lazy",o.appendChild(s)}else o.appendChild(m("cart"));o.addEventListener("click",i),t.appendChild(o);let r=document.createElement("span");r.className="bb-card-body";let d=document.createElement("span");d.className="bb-card-title",d.textContent=e.title,d.addEventListener("click",i);let a=document.createElement("span");a.className="bb-card-price",a.textContent=e.price.formatted,r.appendChild(d),r.appendChild(a);let l=document.createElement("span");if(l.className="bb-card-cta",e.requiresOptions){let s=document.createElement("button");s.className="bb-btn bb-btn-add",s.setAttribute("aria-label",this.t("addToCart")),s.appendChild(m("cart")),e.variants?.length?s.addEventListener("click",()=>this.togglePicker(r,e,o)):s.addEventListener("click",i),l.appendChild(s)}else{let s=document.createElement("button");s.className="bb-btn bb-btn-add bb-sq",s.setAttribute("aria-label",this.t("addToCart")),s.appendChild(m("cart")),s.addEventListener("click",()=>void this.addToCart(e,s));let b=document.createElement("button");b.className="bb-btn bb-btn-ghost bb-wide",b.appendChild(document.createTextNode(this.t("view"))),b.addEventListener("click",i),l.appendChild(b),l.appendChild(s)}r.appendChild(l),t.appendChild(r),this.cardsRow.appendChild(t),this.scrollDown()}togglePicker(e,n,t){let i=e.parentElement,o=e.querySelector(".bb-pick");if(o){o.remove(),i?.classList.remove("picking");return}i?.classList.add("picking");let r=n.variants??[],d=[];for(let u of r)for(let h of Object.keys(u.attributes))d.includes(h)||d.push(h);let a={},l=document.createElement("span");l.className="bb-pick";let s=()=>r.find(u=>d.every(h=>a[h]&&u.attributes[h]===a[h]))??null,b=()=>{l.replaceChildren();for(let c of d){let k=document.createElement("span");k.className="bb-pick-key",k.textContent=c;let E=document.createElement("span");E.className="bb-pick-vals";let C=new Set;for(let I of r){let f=I.attributes[c];if(!f||C.has(f))continue;C.add(f);let M=r.some(N=>N.attributes[c]===f&&d.every(T=>T===c||!a[T]||N.attributes[T]===a[T])),x=document.createElement("button");x.className=`bb-chipv${a[c]===f?" sel":""}${M?"":" off"}`,x.textContent=f,x.addEventListener("click",()=>{a[c]===f?delete a[c]:a[c]=f,b()}),E.appendChild(x)}l.appendChild(k),l.appendChild(E)}let u=document.createElement("button");u.className="bb-pick-close",u.setAttribute("aria-label",this.t("close")),u.appendChild(m("close")),u.addEventListener("click",()=>{l.remove(),i?.classList.remove("picking")}),l.appendChild(u);let h=s(),w=document.createElement("span");w.className="bb-pick-foot";let v=document.createElement("span");v.className="bb-pick-price",v.textContent=h?h.price.formatted:"";let y=document.createElement("button");if(y.className="bb-btn bb-btn-add bb-sq",y.setAttribute("aria-label",this.t("addToCart")),y.appendChild(m("cart")),h||(y.disabled=!0),y.addEventListener("click",()=>{let c=s();c&&this.addToCart(n,y,c.id)}),w.appendChild(v),w.appendChild(y),l.appendChild(w),h?.imageUrl&&B(h.imageUrl)){let c=t.querySelector("img");c&&(c.src=h.imageUrl)}this.scrollDown()};b(),e.appendChild(l),this.scrollDown()}async addToCart(e,n,t){this.beacon(e.botRef),n.dataset.state="busy",await this.dispatchAdd(e.productId,t??null)?(n.dataset.state="done",n.replaceChildren(m("check"),document.createTextNode(this.t("added"))),setTimeout(()=>{!this.destroyed&&n.isConnected&&(delete n.dataset.state,n.replaceChildren(m("cart"),document.createTextNode(this.t("addToCart"))))},2200)):(delete n.dataset.state,B(e.url)&&(window.location.href=e.url))}async dispatchAdd(e,n){try{if(this.onAddToCart)return await this.onAddToCart({productId:e,variantId:n,quantity:1})!==!1;let t=new CustomEvent("brainerce:bot:add-to-cart",{detail:{productId:e,variantId:n,quantity:1,connectionId:this.connectionId},cancelable:!0,bubbles:!0,composed:!0});return!window.dispatchEvent(t)}catch{return!1}}async handleAction(e){if(e.action!=="add_to_cart")return;e.botRef&&this.beacon(e.botRef),await this.dispatchAdd(e.productId,e.variantId)||this.appendMessage("err",this.t("addFailed"))}beacon(e){try{navigator.sendBeacon?.(`${this.baseUrl}/api/storefront-bot/attribution/click`,new Blob([JSON.stringify({botRef:e})],{type:"application/json"}))}catch{}}toggleEscalation(){this.root?.querySelector(".bb-esc")?.classList.toggle("open")}openEscalation(){this.root?.querySelector(".bb-esc")?.classList.add("open")}async submitEscalation(e){let n=e.querySelector('input[name="email"]')?.value.trim(),t=e.querySelector('textarea[name="message"]')?.value.trim();if(!(!n||!t||!this.conversationId||!this.sessionId))try{if((await fetch(`${this.baseUrl}/api/storefront-bot/${encodeURIComponent(this.connectionId)}/escalate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:n,message:t,conversationId:this.conversationId,anonymousSessionId:this.sessionId,locale:this.locale})})).ok){let o=document.createElement("span");o.className="bb-esc-note",o.appendChild(m("check")),o.appendChild(document.createTextNode(this.t("sent"))),e.replaceChildren(o)}}catch{}}appendMessage(e,n){let t=document.createElement("div");return t.className=`bb-msg ${e}`,t.setAttribute("dir","auto"),t.textContent=n,this.messagesEl?.appendChild(t),this.scrollDown(),t}appendTyping(){let e=document.createElement("div");e.className="bb-typing";let n=document.createElement("span");n.className="bb-dots";for(let i=0;i<3;i++)n.appendChild(document.createElement("i"));let t=document.createElement("span");return t.className="bb-tool",t.textContent=this.t("searching"),e.appendChild(n),e.appendChild(t),this.messagesEl?.appendChild(e),this.scrollDown(),e}scrollDown(){this.messagesEl&&(this.messagesEl.scrollTop=this.messagesEl.scrollHeight)}};(()=>{let p=document.currentScript,e=p?.dataset.connectionId;if(!e){console.warn("[BrainerceBot] missing data-connection-id on the bot.js script tag");return}let n=p?.dataset.apiBase||void 0,t=()=>void S.mount({connectionId:e,baseUrl:n});document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()})();})();
|
package/dist/bot/index.js
CHANGED
|
@@ -427,6 +427,7 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
427
427
|
.bb-btn-add:hover { filter: brightness(1.08); }
|
|
428
428
|
.bb-btn-add[data-state="busy"] { opacity: .65; pointer-events: none; }
|
|
429
429
|
.bb-btn-add[data-state="done"] { background: #059669; pointer-events: none; }
|
|
430
|
+
.bb-btn.bb-sq { flex: 0 0 auto; padding: 0; width: var(--bb-btn-h); }
|
|
430
431
|
.bb-btn-ghost { background: #fff; border: 1px solid #e3e5ec; color: #3c4150; flex: 0 0 auto; padding: 0 11px; }
|
|
431
432
|
.bb-btn-ghost:hover { background: #f6f7f9; border-color: #d5d8e1; }
|
|
432
433
|
.bb-btn-ghost.bb-wide { flex: 1; color: ${accent}; border-color: color-mix(in srgb, ${accent} 35%, #e3e5ec); }
|
|
@@ -451,11 +452,9 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
451
452
|
.bb-chipv:hover { border-color: color-mix(in srgb, ${accent} 50%, #e3e5ec); }
|
|
452
453
|
.bb-chipv.sel { background: ${accent}; border-color: ${accent}; color: #fff; }
|
|
453
454
|
.bb-chipv.off { opacity: .35; pointer-events: none; }
|
|
454
|
-
.bb-pick-foot { display: flex; align-items: center;
|
|
455
|
-
gap: 6px; margin-top: 2px; }
|
|
456
|
-
.bb-pick-foot .bb-btn { flex: 0 0 auto; padding: 0 11px; }
|
|
455
|
+
.bb-pick-foot { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
|
|
457
456
|
.bb-pick-price { font-size: 12.5px; font-weight: 700; color: #14161f;
|
|
458
|
-
font-variant-numeric: tabular-nums; }
|
|
457
|
+
font-variant-numeric: tabular-nums; flex: 1; }
|
|
459
458
|
|
|
460
459
|
/* ---- starter chips -------------------------------------------------- */
|
|
461
460
|
.bb-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 4px 14px 12px; background: #f7f8fa; }
|
|
@@ -913,16 +912,16 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
913
912
|
cta.appendChild(cartBtn);
|
|
914
913
|
} else {
|
|
915
914
|
const addBtn = document.createElement("button");
|
|
916
|
-
addBtn.className = "bb-btn bb-btn-add";
|
|
915
|
+
addBtn.className = "bb-btn bb-btn-add bb-sq";
|
|
916
|
+
addBtn.setAttribute("aria-label", this.t("addToCart"));
|
|
917
917
|
addBtn.appendChild(icon("cart"));
|
|
918
|
-
addBtn.appendChild(document.createTextNode(this.t("addToCart")));
|
|
919
918
|
addBtn.addEventListener("click", () => void this.addToCart(card, addBtn));
|
|
920
919
|
const viewBtn = document.createElement("button");
|
|
921
|
-
viewBtn.className = "bb-btn bb-btn-ghost";
|
|
920
|
+
viewBtn.className = "bb-btn bb-btn-ghost bb-wide";
|
|
922
921
|
viewBtn.appendChild(document.createTextNode(this.t("view")));
|
|
923
922
|
viewBtn.addEventListener("click", goToProduct);
|
|
924
|
-
cta.appendChild(addBtn);
|
|
925
923
|
cta.appendChild(viewBtn);
|
|
924
|
+
cta.appendChild(addBtn);
|
|
926
925
|
}
|
|
927
926
|
body.appendChild(cta);
|
|
928
927
|
el.appendChild(body);
|
|
@@ -997,9 +996,9 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
997
996
|
priceEl.className = "bb-pick-price";
|
|
998
997
|
priceEl.textContent = match ? match.price.formatted : "";
|
|
999
998
|
const addBtn = document.createElement("button");
|
|
1000
|
-
addBtn.className = "bb-btn bb-btn-add";
|
|
999
|
+
addBtn.className = "bb-btn bb-btn-add bb-sq";
|
|
1000
|
+
addBtn.setAttribute("aria-label", this.t("addToCart"));
|
|
1001
1001
|
addBtn.appendChild(icon("cart"));
|
|
1002
|
-
addBtn.appendChild(document.createTextNode(this.t("addToCart")));
|
|
1003
1002
|
if (!match) addBtn.disabled = true;
|
|
1004
1003
|
addBtn.addEventListener("click", () => {
|
|
1005
1004
|
const m = resolved();
|
package/dist/bot/index.mjs
CHANGED
|
@@ -401,6 +401,7 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
401
401
|
.bb-btn-add:hover { filter: brightness(1.08); }
|
|
402
402
|
.bb-btn-add[data-state="busy"] { opacity: .65; pointer-events: none; }
|
|
403
403
|
.bb-btn-add[data-state="done"] { background: #059669; pointer-events: none; }
|
|
404
|
+
.bb-btn.bb-sq { flex: 0 0 auto; padding: 0; width: var(--bb-btn-h); }
|
|
404
405
|
.bb-btn-ghost { background: #fff; border: 1px solid #e3e5ec; color: #3c4150; flex: 0 0 auto; padding: 0 11px; }
|
|
405
406
|
.bb-btn-ghost:hover { background: #f6f7f9; border-color: #d5d8e1; }
|
|
406
407
|
.bb-btn-ghost.bb-wide { flex: 1; color: ${accent}; border-color: color-mix(in srgb, ${accent} 35%, #e3e5ec); }
|
|
@@ -425,11 +426,9 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
425
426
|
.bb-chipv:hover { border-color: color-mix(in srgb, ${accent} 50%, #e3e5ec); }
|
|
426
427
|
.bb-chipv.sel { background: ${accent}; border-color: ${accent}; color: #fff; }
|
|
427
428
|
.bb-chipv.off { opacity: .35; pointer-events: none; }
|
|
428
|
-
.bb-pick-foot { display: flex; align-items: center;
|
|
429
|
-
gap: 6px; margin-top: 2px; }
|
|
430
|
-
.bb-pick-foot .bb-btn { flex: 0 0 auto; padding: 0 11px; }
|
|
429
|
+
.bb-pick-foot { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
|
|
431
430
|
.bb-pick-price { font-size: 12.5px; font-weight: 700; color: #14161f;
|
|
432
|
-
font-variant-numeric: tabular-nums; }
|
|
431
|
+
font-variant-numeric: tabular-nums; flex: 1; }
|
|
433
432
|
|
|
434
433
|
/* ---- starter chips -------------------------------------------------- */
|
|
435
434
|
.bb-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 4px 14px 12px; background: #f7f8fa; }
|
|
@@ -887,16 +886,16 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
887
886
|
cta.appendChild(cartBtn);
|
|
888
887
|
} else {
|
|
889
888
|
const addBtn = document.createElement("button");
|
|
890
|
-
addBtn.className = "bb-btn bb-btn-add";
|
|
889
|
+
addBtn.className = "bb-btn bb-btn-add bb-sq";
|
|
890
|
+
addBtn.setAttribute("aria-label", this.t("addToCart"));
|
|
891
891
|
addBtn.appendChild(icon("cart"));
|
|
892
|
-
addBtn.appendChild(document.createTextNode(this.t("addToCart")));
|
|
893
892
|
addBtn.addEventListener("click", () => void this.addToCart(card, addBtn));
|
|
894
893
|
const viewBtn = document.createElement("button");
|
|
895
|
-
viewBtn.className = "bb-btn bb-btn-ghost";
|
|
894
|
+
viewBtn.className = "bb-btn bb-btn-ghost bb-wide";
|
|
896
895
|
viewBtn.appendChild(document.createTextNode(this.t("view")));
|
|
897
896
|
viewBtn.addEventListener("click", goToProduct);
|
|
898
|
-
cta.appendChild(addBtn);
|
|
899
897
|
cta.appendChild(viewBtn);
|
|
898
|
+
cta.appendChild(addBtn);
|
|
900
899
|
}
|
|
901
900
|
body.appendChild(cta);
|
|
902
901
|
el.appendChild(body);
|
|
@@ -971,9 +970,9 @@ var BrainerceBot = class _BrainerceBot {
|
|
|
971
970
|
priceEl.className = "bb-pick-price";
|
|
972
971
|
priceEl.textContent = match ? match.price.formatted : "";
|
|
973
972
|
const addBtn = document.createElement("button");
|
|
974
|
-
addBtn.className = "bb-btn bb-btn-add";
|
|
973
|
+
addBtn.className = "bb-btn bb-btn-add bb-sq";
|
|
974
|
+
addBtn.setAttribute("aria-label", this.t("addToCart"));
|
|
975
975
|
addBtn.appendChild(icon("cart"));
|
|
976
|
-
addBtn.appendChild(document.createTextNode(this.t("addToCart")));
|
|
977
976
|
if (!match) addBtn.disabled = true;
|
|
978
977
|
addBtn.addEventListener("click", () => {
|
|
979
978
|
const m = resolved();
|
package/dist/index.d.mts
CHANGED
|
@@ -2710,6 +2710,7 @@ interface BulkVariantInput {
|
|
|
2710
2710
|
price?: number | null;
|
|
2711
2711
|
salePrice?: number | null;
|
|
2712
2712
|
stock: number;
|
|
2713
|
+
position?: number;
|
|
2713
2714
|
image?: unknown | null;
|
|
2714
2715
|
isEnabled: boolean;
|
|
2715
2716
|
isDeleted?: boolean;
|
|
@@ -5286,6 +5287,13 @@ declare class BrainerceClient {
|
|
|
5286
5287
|
private sessionToken;
|
|
5287
5288
|
private _sessionCartPromise;
|
|
5288
5289
|
private _migrationDone;
|
|
5290
|
+
/**
|
|
5291
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
5292
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
5293
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
5294
|
+
* so the recovered cart shows up with zero per-store code.
|
|
5295
|
+
*/
|
|
5296
|
+
private _pendingRecoverCartId;
|
|
5289
5297
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
5290
5298
|
private readonly SESSION_CART_KEY;
|
|
5291
5299
|
/**
|
|
@@ -5581,8 +5589,12 @@ declare class BrainerceClient {
|
|
|
5581
5589
|
*/
|
|
5582
5590
|
convertToVariable(productId: string): Promise<Product>;
|
|
5583
5591
|
/**
|
|
5584
|
-
* Convert a VARIABLE product to SIMPLE
|
|
5585
|
-
*
|
|
5592
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
5593
|
+
*
|
|
5594
|
+
* The product must have **at most one variant**. That variant's price and
|
|
5595
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
5596
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
5597
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
5586
5598
|
*
|
|
5587
5599
|
* @example
|
|
5588
5600
|
* ```typescript
|
|
@@ -5617,7 +5629,16 @@ declare class BrainerceClient {
|
|
|
5617
5629
|
*/
|
|
5618
5630
|
createVariant(productId: string, data: CreateVariantDto): Promise<ProductVariant>;
|
|
5619
5631
|
/**
|
|
5620
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
5632
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
5633
|
+
*
|
|
5634
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
5635
|
+
* includes new variants (entries without an `id`), the product is
|
|
5636
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
5637
|
+
* You do **not** need to call `convertToVariable` first.
|
|
5638
|
+
*
|
|
5639
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
5640
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
5641
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
5621
5642
|
*
|
|
5622
5643
|
* @example
|
|
5623
5644
|
* ```typescript
|
|
@@ -7223,6 +7244,21 @@ declare class BrainerceClient {
|
|
|
7223
7244
|
* @internal
|
|
7224
7245
|
*/
|
|
7225
7246
|
private hydrateSessionCart;
|
|
7247
|
+
/**
|
|
7248
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
7249
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
7250
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
7251
|
+
* @internal
|
|
7252
|
+
*/
|
|
7253
|
+
private detectRecoverCartFromUrl;
|
|
7254
|
+
/**
|
|
7255
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
7256
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
7257
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
7258
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
7259
|
+
* @internal
|
|
7260
|
+
*/
|
|
7261
|
+
private adoptPendingRecoverCart;
|
|
7226
7262
|
/**
|
|
7227
7263
|
* Persist session cart reference to localStorage.
|
|
7228
7264
|
* @internal
|
|
@@ -9371,7 +9407,7 @@ declare class BrainerceError extends Error {
|
|
|
9371
9407
|
constructor(message: string, statusCode: number, details?: unknown);
|
|
9372
9408
|
}
|
|
9373
9409
|
|
|
9374
|
-
declare const SDK_VERSION = "1.
|
|
9410
|
+
declare const SDK_VERSION = "1.36.1";
|
|
9375
9411
|
|
|
9376
9412
|
/**
|
|
9377
9413
|
* Verify a webhook signature from Brainerce
|
package/dist/index.d.ts
CHANGED
|
@@ -2710,6 +2710,7 @@ interface BulkVariantInput {
|
|
|
2710
2710
|
price?: number | null;
|
|
2711
2711
|
salePrice?: number | null;
|
|
2712
2712
|
stock: number;
|
|
2713
|
+
position?: number;
|
|
2713
2714
|
image?: unknown | null;
|
|
2714
2715
|
isEnabled: boolean;
|
|
2715
2716
|
isDeleted?: boolean;
|
|
@@ -5286,6 +5287,13 @@ declare class BrainerceClient {
|
|
|
5286
5287
|
private sessionToken;
|
|
5287
5288
|
private _sessionCartPromise;
|
|
5288
5289
|
private _migrationDone;
|
|
5290
|
+
/**
|
|
5291
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
5292
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
5293
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
5294
|
+
* so the recovered cart shows up with zero per-store code.
|
|
5295
|
+
*/
|
|
5296
|
+
private _pendingRecoverCartId;
|
|
5289
5297
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
5290
5298
|
private readonly SESSION_CART_KEY;
|
|
5291
5299
|
/**
|
|
@@ -5581,8 +5589,12 @@ declare class BrainerceClient {
|
|
|
5581
5589
|
*/
|
|
5582
5590
|
convertToVariable(productId: string): Promise<Product>;
|
|
5583
5591
|
/**
|
|
5584
|
-
* Convert a VARIABLE product to SIMPLE
|
|
5585
|
-
*
|
|
5592
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
5593
|
+
*
|
|
5594
|
+
* The product must have **at most one variant**. That variant's price and
|
|
5595
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
5596
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
5597
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
5586
5598
|
*
|
|
5587
5599
|
* @example
|
|
5588
5600
|
* ```typescript
|
|
@@ -5617,7 +5629,16 @@ declare class BrainerceClient {
|
|
|
5617
5629
|
*/
|
|
5618
5630
|
createVariant(productId: string, data: CreateVariantDto): Promise<ProductVariant>;
|
|
5619
5631
|
/**
|
|
5620
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
5632
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
5633
|
+
*
|
|
5634
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
5635
|
+
* includes new variants (entries without an `id`), the product is
|
|
5636
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
5637
|
+
* You do **not** need to call `convertToVariable` first.
|
|
5638
|
+
*
|
|
5639
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
5640
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
5641
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
5621
5642
|
*
|
|
5622
5643
|
* @example
|
|
5623
5644
|
* ```typescript
|
|
@@ -7223,6 +7244,21 @@ declare class BrainerceClient {
|
|
|
7223
7244
|
* @internal
|
|
7224
7245
|
*/
|
|
7225
7246
|
private hydrateSessionCart;
|
|
7247
|
+
/**
|
|
7248
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
7249
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
7250
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
7251
|
+
* @internal
|
|
7252
|
+
*/
|
|
7253
|
+
private detectRecoverCartFromUrl;
|
|
7254
|
+
/**
|
|
7255
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
7256
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
7257
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
7258
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
7259
|
+
* @internal
|
|
7260
|
+
*/
|
|
7261
|
+
private adoptPendingRecoverCart;
|
|
7226
7262
|
/**
|
|
7227
7263
|
* Persist session cart reference to localStorage.
|
|
7228
7264
|
* @internal
|
|
@@ -9371,7 +9407,7 @@ declare class BrainerceError extends Error {
|
|
|
9371
9407
|
constructor(message: string, statusCode: number, details?: unknown);
|
|
9372
9408
|
}
|
|
9373
9409
|
|
|
9374
|
-
declare const SDK_VERSION = "1.
|
|
9410
|
+
declare const SDK_VERSION = "1.36.1";
|
|
9375
9411
|
|
|
9376
9412
|
/**
|
|
9377
9413
|
* Verify a webhook signature from Brainerce
|
package/dist/index.js
CHANGED
|
@@ -185,7 +185,7 @@ function isDevGuardsEnabled() {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
// src/version.ts
|
|
188
|
-
var SDK_VERSION = "1.
|
|
188
|
+
var SDK_VERSION = "1.36.1";
|
|
189
189
|
|
|
190
190
|
// src/client.ts
|
|
191
191
|
var DEFAULT_BASE_URL = "https://api.brainerce.com";
|
|
@@ -234,6 +234,13 @@ var BrainerceClient = class {
|
|
|
234
234
|
this.sessionToken = null;
|
|
235
235
|
this._sessionCartPromise = null;
|
|
236
236
|
this._migrationDone = false;
|
|
237
|
+
/**
|
|
238
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
239
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
240
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
241
|
+
* so the recovered cart shows up with zero per-store code.
|
|
242
|
+
*/
|
|
243
|
+
this._pendingRecoverCartId = null;
|
|
237
244
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
238
245
|
this.SESSION_CART_KEY = "brainerce_session";
|
|
239
246
|
/**
|
|
@@ -648,6 +655,7 @@ var BrainerceClient = class {
|
|
|
648
655
|
this.proxyMode = options.proxyMode || false;
|
|
649
656
|
this.onAuthError = options.onAuthError;
|
|
650
657
|
this.hydrateSessionCart();
|
|
658
|
+
this.detectRecoverCartFromUrl();
|
|
651
659
|
}
|
|
652
660
|
// -------------------- Locale --------------------
|
|
653
661
|
/**
|
|
@@ -787,12 +795,15 @@ var BrainerceClient = class {
|
|
|
787
795
|
}
|
|
788
796
|
});
|
|
789
797
|
}
|
|
798
|
+
const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
|
|
790
799
|
const headers = {
|
|
791
800
|
Authorization: `Bearer ${this.apiKey}`,
|
|
792
|
-
"Content-Type": "application/json",
|
|
793
801
|
"X-SDK-Version": SDK_VERSION,
|
|
794
802
|
"ngrok-skip-browser-warning": "true"
|
|
795
803
|
};
|
|
804
|
+
if (!isFormData) {
|
|
805
|
+
headers["Content-Type"] = "application/json";
|
|
806
|
+
}
|
|
796
807
|
if (this.origin) {
|
|
797
808
|
headers["Origin"] = this.origin;
|
|
798
809
|
}
|
|
@@ -806,7 +817,7 @@ var BrainerceClient = class {
|
|
|
806
817
|
const response = await fetch(url.toString(), {
|
|
807
818
|
method,
|
|
808
819
|
headers,
|
|
809
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
820
|
+
body: body ? isFormData ? body : JSON.stringify(body) : void 0,
|
|
810
821
|
signal: controller.signal
|
|
811
822
|
});
|
|
812
823
|
clearTimeout(timeoutId);
|
|
@@ -1376,8 +1387,12 @@ var BrainerceClient = class {
|
|
|
1376
1387
|
);
|
|
1377
1388
|
}
|
|
1378
1389
|
/**
|
|
1379
|
-
* Convert a VARIABLE product to SIMPLE
|
|
1380
|
-
*
|
|
1390
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
1391
|
+
*
|
|
1392
|
+
* The product must have **at most one variant**. That variant's price and
|
|
1393
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
1394
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
1395
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
1381
1396
|
*
|
|
1382
1397
|
* @example
|
|
1383
1398
|
* ```typescript
|
|
@@ -1432,7 +1447,16 @@ var BrainerceClient = class {
|
|
|
1432
1447
|
);
|
|
1433
1448
|
}
|
|
1434
1449
|
/**
|
|
1435
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
1450
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
1451
|
+
*
|
|
1452
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
1453
|
+
* includes new variants (entries without an `id`), the product is
|
|
1454
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
1455
|
+
* You do **not** need to call `convertToVariable` first.
|
|
1456
|
+
*
|
|
1457
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
1458
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
1459
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
1436
1460
|
*
|
|
1437
1461
|
* @example
|
|
1438
1462
|
* ```typescript
|
|
@@ -3950,6 +3974,48 @@ var BrainerceClient = class {
|
|
|
3950
3974
|
} catch {
|
|
3951
3975
|
}
|
|
3952
3976
|
}
|
|
3977
|
+
/**
|
|
3978
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
3979
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
3980
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
3981
|
+
* @internal
|
|
3982
|
+
*/
|
|
3983
|
+
detectRecoverCartFromUrl() {
|
|
3984
|
+
if (typeof window === "undefined" || !window.location?.search) return;
|
|
3985
|
+
try {
|
|
3986
|
+
const recoverId = new URLSearchParams(window.location.search).get("brainerce_cart");
|
|
3987
|
+
if (recoverId) this._pendingRecoverCartId = recoverId;
|
|
3988
|
+
} catch {
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
/**
|
|
3992
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
3993
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
3994
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
3995
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
3996
|
+
* @internal
|
|
3997
|
+
*/
|
|
3998
|
+
async adoptPendingRecoverCart() {
|
|
3999
|
+
const recoverId = this._pendingRecoverCartId;
|
|
4000
|
+
if (!recoverId) return null;
|
|
4001
|
+
this._pendingRecoverCartId = null;
|
|
4002
|
+
try {
|
|
4003
|
+
const cart = await this.getCart(recoverId);
|
|
4004
|
+
if (cart.status !== "ACTIVE") return null;
|
|
4005
|
+
if (cart.sessionToken) {
|
|
4006
|
+
this.saveSessionCart({
|
|
4007
|
+
sessionToken: cart.sessionToken,
|
|
4008
|
+
cartId: cart.id,
|
|
4009
|
+
itemCount: cart.itemCount
|
|
4010
|
+
});
|
|
4011
|
+
} else {
|
|
4012
|
+
this.sessionCartId = cart.id;
|
|
4013
|
+
}
|
|
4014
|
+
return cart;
|
|
4015
|
+
} catch {
|
|
4016
|
+
return null;
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
3953
4019
|
/**
|
|
3954
4020
|
* Persist session cart reference to localStorage.
|
|
3955
4021
|
* @internal
|
|
@@ -4049,6 +4115,8 @@ var BrainerceClient = class {
|
|
|
4049
4115
|
}
|
|
4050
4116
|
/** @internal */
|
|
4051
4117
|
async _getOrCreateSessionCartImpl() {
|
|
4118
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4119
|
+
if (recovered) return recovered;
|
|
4052
4120
|
const migrated = await this.migrateLocalCartToSession();
|
|
4053
4121
|
if (migrated) return migrated;
|
|
4054
4122
|
if (this.sessionCartId && this.sessionToken) {
|
|
@@ -4282,9 +4350,13 @@ var BrainerceClient = class {
|
|
|
4282
4350
|
*/
|
|
4283
4351
|
async smartGetCart(options) {
|
|
4284
4352
|
if (this.isCustomerLoggedIn()) {
|
|
4353
|
+
if (this._pendingRecoverCartId) {
|
|
4354
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4355
|
+
if (recovered) return recovered;
|
|
4356
|
+
}
|
|
4285
4357
|
return this.getOrCreateCustomerCart(options);
|
|
4286
4358
|
} else {
|
|
4287
|
-
if (!this.sessionToken) {
|
|
4359
|
+
if (!this.sessionToken && !this._pendingRecoverCartId) {
|
|
4288
4360
|
return this.emptyCart();
|
|
4289
4361
|
}
|
|
4290
4362
|
return this.getOrCreateSessionCart(options);
|
package/dist/index.mjs
CHANGED
|
@@ -115,7 +115,7 @@ function isDevGuardsEnabled() {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
// src/version.ts
|
|
118
|
-
var SDK_VERSION = "1.
|
|
118
|
+
var SDK_VERSION = "1.36.1";
|
|
119
119
|
|
|
120
120
|
// src/client.ts
|
|
121
121
|
var DEFAULT_BASE_URL = "https://api.brainerce.com";
|
|
@@ -164,6 +164,13 @@ var BrainerceClient = class {
|
|
|
164
164
|
this.sessionToken = null;
|
|
165
165
|
this._sessionCartPromise = null;
|
|
166
166
|
this._migrationDone = false;
|
|
167
|
+
/**
|
|
168
|
+
* Cart id to adopt from an abandoned-checkout recovery redirect. brainerce's
|
|
169
|
+
* recover endpoint 302s the shopper to `{storeDomain}/cart?brainerce_cart=<id>`;
|
|
170
|
+
* we pick it up on construction and adopt it as the active cart on first access,
|
|
171
|
+
* so the recovered cart shows up with zero per-store code.
|
|
172
|
+
*/
|
|
173
|
+
this._pendingRecoverCartId = null;
|
|
167
174
|
/** localStorage key for session cart reference (sessionToken + cartId) */
|
|
168
175
|
this.SESSION_CART_KEY = "brainerce_session";
|
|
169
176
|
/**
|
|
@@ -578,6 +585,7 @@ var BrainerceClient = class {
|
|
|
578
585
|
this.proxyMode = options.proxyMode || false;
|
|
579
586
|
this.onAuthError = options.onAuthError;
|
|
580
587
|
this.hydrateSessionCart();
|
|
588
|
+
this.detectRecoverCartFromUrl();
|
|
581
589
|
}
|
|
582
590
|
// -------------------- Locale --------------------
|
|
583
591
|
/**
|
|
@@ -717,12 +725,15 @@ var BrainerceClient = class {
|
|
|
717
725
|
}
|
|
718
726
|
});
|
|
719
727
|
}
|
|
728
|
+
const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
|
|
720
729
|
const headers = {
|
|
721
730
|
Authorization: `Bearer ${this.apiKey}`,
|
|
722
|
-
"Content-Type": "application/json",
|
|
723
731
|
"X-SDK-Version": SDK_VERSION,
|
|
724
732
|
"ngrok-skip-browser-warning": "true"
|
|
725
733
|
};
|
|
734
|
+
if (!isFormData) {
|
|
735
|
+
headers["Content-Type"] = "application/json";
|
|
736
|
+
}
|
|
726
737
|
if (this.origin) {
|
|
727
738
|
headers["Origin"] = this.origin;
|
|
728
739
|
}
|
|
@@ -736,7 +747,7 @@ var BrainerceClient = class {
|
|
|
736
747
|
const response = await fetch(url.toString(), {
|
|
737
748
|
method,
|
|
738
749
|
headers,
|
|
739
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
750
|
+
body: body ? isFormData ? body : JSON.stringify(body) : void 0,
|
|
740
751
|
signal: controller.signal
|
|
741
752
|
});
|
|
742
753
|
clearTimeout(timeoutId);
|
|
@@ -1306,8 +1317,12 @@ var BrainerceClient = class {
|
|
|
1306
1317
|
);
|
|
1307
1318
|
}
|
|
1308
1319
|
/**
|
|
1309
|
-
* Convert a VARIABLE product to SIMPLE
|
|
1310
|
-
*
|
|
1320
|
+
* Convert a VARIABLE product back to SIMPLE.
|
|
1321
|
+
*
|
|
1322
|
+
* The product must have **at most one variant**. That variant's price and
|
|
1323
|
+
* inventory are merged back into the parent product, then the variant row is
|
|
1324
|
+
* deleted. Throws `400` if more than one variant exists — delete the extras
|
|
1325
|
+
* first. Throws `400` if the product is already SIMPLE.
|
|
1311
1326
|
*
|
|
1312
1327
|
* @example
|
|
1313
1328
|
* ```typescript
|
|
@@ -1362,7 +1377,16 @@ var BrainerceClient = class {
|
|
|
1362
1377
|
);
|
|
1363
1378
|
}
|
|
1364
1379
|
/**
|
|
1365
|
-
* Bulk save variants (create, update, delete in one operation)
|
|
1380
|
+
* Bulk save variants (create, update, delete in one atomic operation).
|
|
1381
|
+
*
|
|
1382
|
+
* **Auto-conversion:** if the product is currently `SIMPLE` and the payload
|
|
1383
|
+
* includes new variants (entries without an `id`), the product is
|
|
1384
|
+
* automatically converted to `VARIABLE` before the variants are created.
|
|
1385
|
+
* You do **not** need to call `convertToVariable` first.
|
|
1386
|
+
*
|
|
1387
|
+
* To delete a variant include its `id` and set `isDeleted: true`.
|
|
1388
|
+
* To update an existing variant supply its `id` with changed fields.
|
|
1389
|
+
* Entries without an `id` (or with an `id` prefixed `new-`) are created.
|
|
1366
1390
|
*
|
|
1367
1391
|
* @example
|
|
1368
1392
|
* ```typescript
|
|
@@ -3880,6 +3904,48 @@ var BrainerceClient = class {
|
|
|
3880
3904
|
} catch {
|
|
3881
3905
|
}
|
|
3882
3906
|
}
|
|
3907
|
+
/**
|
|
3908
|
+
* Detect an abandoned-checkout recovery redirect. brainerce's recover endpoint
|
|
3909
|
+
* sends the shopper to `{storeDomain}/cart?brainerce_cart=<cartId>`; we stash
|
|
3910
|
+
* the id and adopt it (with its real session token) on the first cart access.
|
|
3911
|
+
* @internal
|
|
3912
|
+
*/
|
|
3913
|
+
detectRecoverCartFromUrl() {
|
|
3914
|
+
if (typeof window === "undefined" || !window.location?.search) return;
|
|
3915
|
+
try {
|
|
3916
|
+
const recoverId = new URLSearchParams(window.location.search).get("brainerce_cart");
|
|
3917
|
+
if (recoverId) this._pendingRecoverCartId = recoverId;
|
|
3918
|
+
} catch {
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
/**
|
|
3922
|
+
* Adopt a recovery-redirect cart if one is pending. Runs as the first step of
|
|
3923
|
+
* session-cart resolution so the recovered cart wins over any stale local
|
|
3924
|
+
* session. Returns the adopted cart, or null to fall through to normal
|
|
3925
|
+
* resolution (no pending id, or the cart is no longer recoverable).
|
|
3926
|
+
* @internal
|
|
3927
|
+
*/
|
|
3928
|
+
async adoptPendingRecoverCart() {
|
|
3929
|
+
const recoverId = this._pendingRecoverCartId;
|
|
3930
|
+
if (!recoverId) return null;
|
|
3931
|
+
this._pendingRecoverCartId = null;
|
|
3932
|
+
try {
|
|
3933
|
+
const cart = await this.getCart(recoverId);
|
|
3934
|
+
if (cart.status !== "ACTIVE") return null;
|
|
3935
|
+
if (cart.sessionToken) {
|
|
3936
|
+
this.saveSessionCart({
|
|
3937
|
+
sessionToken: cart.sessionToken,
|
|
3938
|
+
cartId: cart.id,
|
|
3939
|
+
itemCount: cart.itemCount
|
|
3940
|
+
});
|
|
3941
|
+
} else {
|
|
3942
|
+
this.sessionCartId = cart.id;
|
|
3943
|
+
}
|
|
3944
|
+
return cart;
|
|
3945
|
+
} catch {
|
|
3946
|
+
return null;
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3883
3949
|
/**
|
|
3884
3950
|
* Persist session cart reference to localStorage.
|
|
3885
3951
|
* @internal
|
|
@@ -3979,6 +4045,8 @@ var BrainerceClient = class {
|
|
|
3979
4045
|
}
|
|
3980
4046
|
/** @internal */
|
|
3981
4047
|
async _getOrCreateSessionCartImpl() {
|
|
4048
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4049
|
+
if (recovered) return recovered;
|
|
3982
4050
|
const migrated = await this.migrateLocalCartToSession();
|
|
3983
4051
|
if (migrated) return migrated;
|
|
3984
4052
|
if (this.sessionCartId && this.sessionToken) {
|
|
@@ -4212,9 +4280,13 @@ var BrainerceClient = class {
|
|
|
4212
4280
|
*/
|
|
4213
4281
|
async smartGetCart(options) {
|
|
4214
4282
|
if (this.isCustomerLoggedIn()) {
|
|
4283
|
+
if (this._pendingRecoverCartId) {
|
|
4284
|
+
const recovered = await this.adoptPendingRecoverCart();
|
|
4285
|
+
if (recovered) return recovered;
|
|
4286
|
+
}
|
|
4215
4287
|
return this.getOrCreateCustomerCart(options);
|
|
4216
4288
|
} else {
|
|
4217
|
-
if (!this.sessionToken) {
|
|
4289
|
+
if (!this.sessionToken && !this._pendingRecoverCartId) {
|
|
4218
4290
|
return this.emptyCart();
|
|
4219
4291
|
}
|
|
4220
4292
|
return this.getOrCreateSessionCart(options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainerce",
|
|
3
|
-
"version": "1.36.
|
|
3
|
+
"version": "1.36.3",
|
|
4
4
|
"description": "Official SDK for building e-commerce storefronts with Brainerce Platform. Perfect for vibe-coded sites, AI-built stores (Cursor, Lovable, v0), and custom storefronts.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|