wineater-bot 1.4.0 → 1.4.1

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.
@@ -1,4 +1,4 @@
1
- const p = `
1
+ const g = `
2
2
  @font-face {
3
3
  font-family: 'Poppins';
4
4
  src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
@@ -273,27 +273,27 @@ const p = `
273
273
  .typing-indicator.visible {
274
274
  visibility: visible;
275
275
  height: 50px;
276
- }`, d = document.createElement("style");
277
- d.textContent = p;
278
- document.head.appendChild(d);
279
- function c() {
276
+ }`, c = document.createElement("style");
277
+ c.textContent = g;
278
+ document.head.appendChild(c);
279
+ function l() {
280
280
  const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
281
281
  n.classList.contains("visible") ? (n.classList.remove("visible"), t.style.display = "flex") : (n.classList.add("visible"), t.style.display = "none");
282
282
  }
283
- function g() {
283
+ function h() {
284
284
  document.getElementById("chat-window").classList.remove("visible");
285
285
  }
286
- function h() {
286
+ function u() {
287
287
  document.getElementById("chat-window").classList.add("visible");
288
288
  }
289
289
  document.addEventListener("DOMContentLoaded", () => {
290
290
  setupCloseButton(), setupOutsideClick();
291
291
  });
292
- const u = ["climats", "telckel", "biobio", "weinpoint"], m = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
293
- class l {
292
+ const m = ["climats", "telckel", "biobio", "weinpoint"], f = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
293
+ class p {
294
294
  constructor(t) {
295
295
  var e;
296
- this.baseURL = "https://api.wineater.com/", this.store = u.find((o) => window.location.href.includes(o)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || m;
296
+ this.baseURL = "https://api.wineater.com/", this.store = m.find((o) => window.location.href.includes(o)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || f;
297
297
  }
298
298
  async getStoreConfig(t) {
299
299
  console.log(t);
@@ -332,9 +332,9 @@ class l {
332
332
  }
333
333
  }
334
334
  }
335
- class f {
335
+ class y {
336
336
  constructor() {
337
- this.api = new l(), this.language = "en", this.translations = {
337
+ this.api = new p(), this.language = "en", this.translations = {
338
338
  fr: {
339
339
  welcomeMessage: "Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",
340
340
  noResultsFound: "Aucun résultat trouvé.",
@@ -383,10 +383,10 @@ class f {
383
383
  return this.translations[this.language][t] || t;
384
384
  }
385
385
  }
386
- const s = new f();
387
- class y {
386
+ const s = new y();
387
+ class b {
388
388
  constructor() {
389
- this.api = new l(), this.displayFirstMessage(s.translate("welcomeMessage"));
389
+ this.api = new p(), this.displayFirstMessage(s.translate("welcomeMessage"));
390
390
  }
391
391
  initialize() {
392
392
  document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (o) => {
@@ -438,9 +438,9 @@ class y {
438
438
  }
439
439
  }
440
440
  document.addEventListener("DOMContentLoaded", () => {
441
- window.toggleChatWindow = c, window.closeChatWindow = g, window.openChatWindow = h;
441
+ window.toggleChatWindow = l, window.closeChatWindow = h, window.openChatWindow = u;
442
442
  });
443
- function b() {
443
+ function w() {
444
444
  const n = `
445
445
  <div id="chatbot-container">
446
446
  <div id="chat-icon" onclick="toggleChatWindow()">
@@ -470,30 +470,31 @@ function b() {
470
470
  `;
471
471
  document.body.insertAdjacentHTML("beforeend", n);
472
472
  }
473
- function w() {
474
- document.getElementById("close-btn").addEventListener("click", c);
475
- }
476
473
  function x() {
474
+ document.getElementById("close-btn").addEventListener("click", l);
475
+ }
476
+ function v() {
477
477
  window.addEventListener("click", function(n) {
478
478
  const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
479
479
  !t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
480
480
  });
481
481
  }
482
- function v(n) {
482
+ function E(n) {
483
483
  console.log(n);
484
484
  const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
485
485
  t.className = "", e.className = "", n === "right-center" ? (t.classList.add("chat-icon-right-center"), e.classList.add("right-center-aligned")) : t.classList.add("chat-icon-bottom-right");
486
486
  }
487
+ var d;
487
488
  if (typeof window < "u") {
488
- const n = window.wineaterData.POSITION || "bottom-right";
489
+ const n = ((d = window.wineaterData) == null ? void 0 : d.POSITION) || "bottom-right";
489
490
  window.addEventListener("DOMContentLoaded", async () => {
490
491
  const e = ["climats", "telckel", "biobio", "weinpoint"].find((a) => window.location.href.includes(a)) || null;
491
492
  let o;
492
- e && (o = e.charAt(0).toUpperCase() + e.slice(1)), await s.fetchConfig(o || null), b(), w(), x(), v(n), new y().initialize();
493
+ e && (o = e.charAt(0).toUpperCase() + e.slice(1)), await s.fetchConfig(o || null), w(), x(), v(), E(n), new b().initialize();
493
494
  });
494
495
  }
495
496
  export {
496
- g as closeChatWindow,
497
- h as openChatWindow,
498
- c as toggleChatWindow
497
+ h as closeChatWindow,
498
+ u as openChatWindow,
499
+ l as toggleChatWindow
499
500
  };
@@ -1,4 +1,4 @@
1
- (function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.WineaterChatbot={}))})(this,function(a){"use strict";const r=`
1
+ (function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.WineaterChatbot={}))})(this,function(a){"use strict";var u;const r=`
2
2
  @font-face {
3
3
  font-family: 'Poppins';
4
4
  src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
@@ -273,13 +273,13 @@
273
273
  .typing-indicator.visible {
274
274
  visibility: visible;
275
275
  height: 50px;
276
- }`,l=document.createElement("style");l.textContent=r,document.head.appendChild(l);function c(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(n.classList.remove("visible"),t.style.display="flex"):(n.classList.add("visible"),t.style.display="none")}function p(){document.getElementById("chat-window").classList.remove("visible")}function g(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const m=["climats","telckel","biobio","weinpoint"],f="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class h{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=m.find(o=>window.location.href.includes(o)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||f}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),o=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${o.message||"No additional error information"}`);return o}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class y{constructor(){this.api=new h,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"}}}async fetchConfig(t){if(t){const e=await this.api.getStoreConfig(t);this.language=e.lang}}translate(t){return this.translations[this.language][t]||t}}const s=new y;class b{constructor(){this.api=new h,this.displayFirstMessage(s.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",o=>{o.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const o=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,o.appendChild(i),o.scrollTop=o.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{const o=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),o&&o.length?this.displayResults(o):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(s.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const o=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,o.appendChild(i),o.scrollTop=o.scrollHeight}displayResults(t){const e=document.getElementById("message-container");t.forEach(o=>{const i=document.createElement("div");i.className="wine-item";const d=document.createElement("img");d.src=o.Image,i.appendChild(d);const u=document.createElement("div");u.innerHTML=`
276
+ }`,l=document.createElement("style");l.textContent=r,document.head.appendChild(l);function c(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(n.classList.remove("visible"),t.style.display="flex"):(n.classList.add("visible"),t.style.display="none")}function p(){document.getElementById("chat-window").classList.remove("visible")}function g(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const f=["climats","telckel","biobio","weinpoint"],y="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class h{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=f.find(o=>window.location.href.includes(o)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||y}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),o=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${o.message||"No additional error information"}`);return o}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class b{constructor(){this.api=new h,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"}}}async fetchConfig(t){if(t){const e=await this.api.getStoreConfig(t);this.language=e.lang}}translate(t){return this.translations[this.language][t]||t}}const s=new b;class w{constructor(){this.api=new h,this.displayFirstMessage(s.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",o=>{o.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const o=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,o.appendChild(i),o.scrollTop=o.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{const o=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),o&&o.length?this.displayResults(o):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(s.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const o=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,o.appendChild(i),o.scrollTop=o.scrollHeight}displayResults(t){const e=document.getElementById("message-container");t.forEach(o=>{const i=document.createElement("div");i.className="wine-item";const d=document.createElement("img");d.src=o.Image,i.appendChild(d);const m=document.createElement("div");m.innerHTML=`
277
277
  <strong>${o.Title}</strong><br>
278
278
  ${s.translate("price")}: ${o.Price}<br>
279
279
  ${s.translate("region")}: ${o.Region}<br>
280
280
  ${s.translate("type")}: ${o.Type}<br>
281
281
  <a href="${o.Url}" target="_blank">${s.translate("moreInfo")}</a>
282
- `,i.appendChild(u),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=c,window.closeChatWindow=p,window.openChatWindow=g});function w(){const n=`
282
+ `,i.appendChild(m),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=c,window.closeChatWindow=p,window.openChatWindow=g});function x(){const n=`
283
283
  <div id="chatbot-container">
284
284
  <div id="chat-icon" onclick="toggleChatWindow()">
285
285
  <img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon"> <!-- Update the path to your logo image -->
@@ -305,4 +305,4 @@
305
305
  </div>
306
306
  </div>
307
307
  </div>
308
- `;document.body.insertAdjacentHTML("beforeend",n)}function x(){document.getElementById("close-btn").addEventListener("click",c)}function v(){window.addEventListener("click",function(n){const t=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!t.contains(n.target)&&!e.contains(n.target)&&(t.classList.remove("visible"),e.style.display="flex")})}function E(n){console.log(n);const t=document.getElementById("chat-icon"),e=document.getElementById("chat-window");t.className="",e.className="",n==="right-center"?(t.classList.add("chat-icon-right-center"),e.classList.add("right-center-aligned")):t.classList.add("chat-icon-bottom-right")}if(typeof window<"u"){const n=window.wineaterData.POSITION||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{const e=["climats","telckel","biobio","weinpoint"].find(d=>window.location.href.includes(d))||null;let o;e&&(o=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(o||null),w(),x(),v(),E(n),new b().initialize()})}a.closeChatWindow=p,a.openChatWindow=g,a.toggleChatWindow=c,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
308
+ `;document.body.insertAdjacentHTML("beforeend",n)}function v(){document.getElementById("close-btn").addEventListener("click",c)}function E(){window.addEventListener("click",function(n){const t=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!t.contains(n.target)&&!e.contains(n.target)&&(t.classList.remove("visible"),e.style.display="flex")})}function I(n){console.log(n);const t=document.getElementById("chat-icon"),e=document.getElementById("chat-window");t.className="",e.className="",n==="right-center"?(t.classList.add("chat-icon-right-center"),e.classList.add("right-center-aligned")):t.classList.add("chat-icon-bottom-right")}if(typeof window<"u"){const n=((u=window.wineaterData)==null?void 0:u.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{const e=["climats","telckel","biobio","weinpoint"].find(d=>window.location.href.includes(d))||null;let o;e&&(o=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(o||null),x(),v(),E(),I(n),new w().initialize()})}a.closeChatWindow=p,a.openChatWindow=g,a.toggleChatWindow=c,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/index.js CHANGED
@@ -91,7 +91,7 @@ function toggleChatIconPosition(position) {
91
91
 
92
92
  // If you want to initialize your chatbot automatically when the script is loaded
93
93
  if (typeof window !== 'undefined') {
94
- const position = window.wineaterData['POSITION'] || 'bottom-right';
94
+ const position = window.wineaterData?.POSITION || 'bottom-right';
95
95
  window.addEventListener('DOMContentLoaded', async () => {
96
96
  const stores = ['climats', 'telckel', 'biobio', 'weinpoint'];
97
97
  const store = stores.find(value => window.location.href.includes(value)) || null;