brainerce 1.35.1 → 1.36.0

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.
@@ -246,6 +246,6 @@
246
246
  transition: color .12s ease; }
247
247
  .bb-foot a:hover { color: #6b7280; }
248
248
  .bb-foot-mark { width: 14px; height: 14px; border-radius: 3px; display: block; }
249
- `}render(e){let n=this.settings.accentColor||"#6366F1",t=j.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(document.createTextNode(r.charAt(0).toUpperCase()));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 M=document.createElement("button");M.className="bb-chip",M.textContent=g,M.addEventListener("click",()=>this.send(g)),this.chipsEl.appendChild(M)}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 m=document.createElement("div");m.className="bb-composer",this.inputEl=document.createElement("textarea"),this.inputEl.className="bb-input",this.inputEl.rows=1,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(f("send")),this.sendBtn.addEventListener("click",()=>this.send(this.inputEl?.value??"")),m.appendChild(this.inputEl),m.appendChild(this.sendBtn),this.windowEl.appendChild(m);let A=document.createElement("div");A.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=z,N.alt="",N.className="bb-foot-mark",x.appendChild(N),x.appendChild(document.createTextNode(this.t("poweredBy"))),A.appendChild(x),this.windowEl.appendChild(A),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=f("chat");g.classList.add("bb-l-chat"),this.launcherEl.appendChild(g)}let T=f("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(f(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(f(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(`
249
+ `}render(e){let n=this.settings.accentColor||"#6366F1",t=j.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(document.createTextNode(r.charAt(0).toUpperCase()));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 M=document.createElement("button");M.className="bb-chip",M.textContent=g,M.addEventListener("click",()=>this.send(g)),this.chipsEl.appendChild(M)}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 m=document.createElement("div");m.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(f("send")),this.sendBtn.addEventListener("click",()=>this.send(this.inputEl?.value??"")),m.appendChild(this.inputEl),m.appendChild(this.sendBtn),this.windowEl.appendChild(m);let A=document.createElement("div");A.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=z,N.alt="",N.className="bb-foot-mark",x.appendChild(N),x.appendChild(document.createTextNode(this.t("poweredBy"))),A.appendChild(x),this.windowEl.appendChild(A),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=f("chat");g.classList.add("bb-l-chat"),this.launcherEl.appendChild(g)}let T=f("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(f(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(f(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
250
 
251
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"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(f("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(f("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.appendChild(f("cart")),s.appendChild(document.createTextNode(this.t("addToCart"))),s.addEventListener("click",()=>void this.addToCart(e,s));let b=document.createElement("button");b.className="bb-btn bb-btn-ghost",b.appendChild(document.createTextNode(this.t("view"))),b.addEventListener("click",i),l.appendChild(s),l.appendChild(b)}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 m=I.attributes[c];if(!m||C.has(m))continue;C.add(m);let A=r.some(N=>N.attributes[c]===m&&d.every(T=>T===c||!a[T]||N.attributes[T]===a[T])),x=document.createElement("button");x.className=`bb-chipv${a[c]===m?" sel":""}${A?"":" off"}`,x.textContent=m,x.addEventListener("click",()=>{a[c]===m?delete a[c]:a[c]=m,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(f("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",y.appendChild(f("cart")),y.appendChild(document.createTextNode(this.t("addToCart"))),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(f("check"),document.createTextNode(this.t("added"))),setTimeout(()=>{!this.destroyed&&n.isConnected&&(delete n.dataset.state,n.replaceChildren(f("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")}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(f("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
@@ -560,7 +560,9 @@ var BrainerceBot = class _BrainerceBot {
560
560
  this.expandBtn = this.iconButton("expand", this.t("expand"), () => this.toggleExpand());
561
561
  actions.appendChild(this.expandBtn);
562
562
  }
563
- actions.appendChild(this.iconButton("mail", this.t("leaveMessage"), () => this.toggleEscalation()));
563
+ actions.appendChild(
564
+ this.iconButton("mail", this.t("leaveMessage"), () => this.toggleEscalation())
565
+ );
564
566
  actions.appendChild(this.iconButton("close", this.t("close"), () => this.close()));
565
567
  header.appendChild(avatar);
566
568
  header.appendChild(headMain);
@@ -607,6 +609,7 @@ var BrainerceBot = class _BrainerceBot {
607
609
  this.inputEl = document.createElement("textarea");
608
610
  this.inputEl.className = "bb-input";
609
611
  this.inputEl.rows = 1;
612
+ this.inputEl.maxLength = 4e3;
610
613
  this.inputEl.placeholder = this.t("placeholder");
611
614
  this.inputEl.addEventListener("keydown", (e) => {
612
615
  if (e.key === "Enter" && !e.shiftKey) {
@@ -534,7 +534,9 @@ var BrainerceBot = class _BrainerceBot {
534
534
  this.expandBtn = this.iconButton("expand", this.t("expand"), () => this.toggleExpand());
535
535
  actions.appendChild(this.expandBtn);
536
536
  }
537
- actions.appendChild(this.iconButton("mail", this.t("leaveMessage"), () => this.toggleEscalation()));
537
+ actions.appendChild(
538
+ this.iconButton("mail", this.t("leaveMessage"), () => this.toggleEscalation())
539
+ );
538
540
  actions.appendChild(this.iconButton("close", this.t("close"), () => this.close()));
539
541
  header.appendChild(avatar);
540
542
  header.appendChild(headMain);
@@ -581,6 +583,7 @@ var BrainerceBot = class _BrainerceBot {
581
583
  this.inputEl = document.createElement("textarea");
582
584
  this.inputEl.className = "bb-input";
583
585
  this.inputEl.rows = 1;
586
+ this.inputEl.maxLength = 4e3;
584
587
  this.inputEl.placeholder = this.t("placeholder");
585
588
  this.inputEl.addEventListener("keydown", (e) => {
586
589
  if (e.key === "Enter" && !e.shiftKey) {
package/dist/index.d.mts CHANGED
@@ -248,6 +248,13 @@ interface Product {
248
248
  id: string;
249
249
  name: string;
250
250
  slug?: string | null;
251
+ /**
252
+ * Per-locale URL slugs derived from the product's translation map.
253
+ * Key = BCP-47 locale (e.g. `"en"`, `"he"`, `"ar"`), value = the translated slug for that locale.
254
+ * Used by storefronts to build hreflang tags and locale-specific sitemap entries.
255
+ * Only populated when the product has at least one locale-specific slug configured.
256
+ */
257
+ localeSlugs?: Record<string, string> | null;
251
258
  /**
252
259
  * Product description as HTML. **Always sanitize before rendering**, e.g.:
253
260
  *
package/dist/index.d.ts CHANGED
@@ -248,6 +248,13 @@ interface Product {
248
248
  id: string;
249
249
  name: string;
250
250
  slug?: string | null;
251
+ /**
252
+ * Per-locale URL slugs derived from the product's translation map.
253
+ * Key = BCP-47 locale (e.g. `"en"`, `"he"`, `"ar"`), value = the translated slug for that locale.
254
+ * Used by storefronts to build hreflang tags and locale-specific sitemap entries.
255
+ * Only populated when the product has at least one locale-specific slug configured.
256
+ */
257
+ localeSlugs?: Record<string, string> | null;
251
258
  /**
252
259
  * Product description as HTML. **Always sanitize before rendering**, e.g.:
253
260
  *
package/package.json CHANGED
@@ -1,81 +1,81 @@
1
- {
2
- "name": "brainerce",
3
- "version": "1.35.1",
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
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "require": "./dist/index.js",
12
- "import": "./dist/index.mjs"
13
- },
14
- "./bot": {
15
- "types": "./dist/bot/index.d.ts",
16
- "require": "./dist/bot/index.js",
17
- "import": "./dist/bot/index.mjs"
18
- }
19
- },
20
- "files": [
21
- "dist",
22
- "README.md"
23
- ],
24
- "scripts": {
25
- "build": "tsup src/index.ts --format cjs,esm --dts && tsup src/bot/index.ts --format cjs,esm --dts --out-dir dist/bot && tsup src/bot/bootstrap.ts --format iife --minify --out-dir dist/bot",
26
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
27
- "lint": "eslint \"src/**/*.ts\"",
28
- "test": "vitest run",
29
- "test:watch": "vitest",
30
- "prepublishOnly": "pnpm build"
31
- },
32
- "keywords": [
33
- "brainerce",
34
- "e-commerce",
35
- "ecommerce",
36
- "sdk",
37
- "vibe-coding",
38
- "vibe-coded",
39
- "ai-commerce",
40
- "storefront",
41
- "headless-commerce",
42
- "multi-platform",
43
- "shopify",
44
- "tiktok",
45
- "cursor",
46
- "lovable",
47
- "v0",
48
- "cart",
49
- "checkout",
50
- "products",
51
- "sync"
52
- ],
53
- "author": "Brainerce",
54
- "license": "MIT",
55
- "repository": {
56
- "type": "git",
57
- "url": "https://github.com/brainerce/brainerce.git",
58
- "directory": "packages/sdk"
59
- },
60
- "homepage": "https://brainerce.com",
61
- "bugs": {
62
- "url": "https://github.com/brainerce/brainerce/issues"
63
- },
64
- "devDependencies": {
65
- "@types/node": "^25.0.3",
66
- "@typescript-eslint/eslint-plugin": "^8.50.1",
67
- "@typescript-eslint/parser": "^8.50.1",
68
- "eslint": "^9.39.2",
69
- "tsup": "^8.0.0",
70
- "typescript": "^5.3.0",
71
- "vitest": "^1.0.0"
72
- },
73
- "peerDependencies": {
74
- "typescript": ">=4.7.0"
75
- },
76
- "peerDependenciesMeta": {
77
- "typescript": {
78
- "optional": true
79
- }
80
- }
81
- }
1
+ {
2
+ "name": "brainerce",
3
+ "version": "1.36.0",
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
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ },
14
+ "./bot": {
15
+ "types": "./dist/bot/index.d.ts",
16
+ "require": "./dist/bot/index.js",
17
+ "import": "./dist/bot/index.mjs"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup src/index.ts --format cjs,esm --dts && tsup src/bot/index.ts --format cjs,esm --dts --out-dir dist/bot && tsup src/bot/bootstrap.ts --format iife --minify --out-dir dist/bot",
26
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
27
+ "lint": "eslint \"src/**/*.ts\"",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest",
30
+ "prepublishOnly": "pnpm build"
31
+ },
32
+ "keywords": [
33
+ "brainerce",
34
+ "e-commerce",
35
+ "ecommerce",
36
+ "sdk",
37
+ "vibe-coding",
38
+ "vibe-coded",
39
+ "ai-commerce",
40
+ "storefront",
41
+ "headless-commerce",
42
+ "multi-platform",
43
+ "shopify",
44
+ "tiktok",
45
+ "cursor",
46
+ "lovable",
47
+ "v0",
48
+ "cart",
49
+ "checkout",
50
+ "products",
51
+ "sync"
52
+ ],
53
+ "author": "Brainerce",
54
+ "license": "MIT",
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "https://github.com/brainerce/brainerce.git",
58
+ "directory": "packages/sdk"
59
+ },
60
+ "homepage": "https://brainerce.com",
61
+ "bugs": {
62
+ "url": "https://github.com/brainerce/brainerce/issues"
63
+ },
64
+ "devDependencies": {
65
+ "@types/node": "^25.0.3",
66
+ "@typescript-eslint/eslint-plugin": "^8.50.1",
67
+ "@typescript-eslint/parser": "^8.50.1",
68
+ "eslint": "^9.39.2",
69
+ "tsup": "^8.0.0",
70
+ "typescript": "^5.3.0",
71
+ "vitest": "^1.0.0"
72
+ },
73
+ "peerDependencies": {
74
+ "typescript": ">=4.7.0"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "typescript": {
78
+ "optional": true
79
+ }
80
+ }
81
+ }