wineater-bot 1.2.1 → 1.3.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.
@@ -289,10 +289,11 @@ function u() {
289
289
  document.addEventListener("DOMContentLoaded", () => {
290
290
  setupCloseButton(), setupOutsideClick();
291
291
  });
292
- const m = ["climats", "telckel", "biobio", "weinpoint"];
292
+ const m = ["climats", "telckel", "biobio", "weinpoint"], f = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
293
293
  class p {
294
294
  constructor(t) {
295
- this.baseURL = "https://api.wineater.com/", this.store = m.find((e) => window.location.href.includes(e)), console.log(this.store);
295
+ var e;
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;
296
297
  }
297
298
  async getStoreConfig(t) {
298
299
  console.log(t);
@@ -300,7 +301,8 @@ class p {
300
301
  const e = await fetch(`${this.baseURL}stores/store`, {
301
302
  method: "POST",
302
303
  headers: {
303
- "Content-Type": "application/json"
304
+ "Content-Type": "application/json",
305
+ Authorization: `Bearer ${this.token}`
304
306
  },
305
307
  body: JSON.stringify({ store: t })
306
308
  });
@@ -317,7 +319,8 @@ class p {
317
319
  const e = await fetch(`${this.baseURL}dish/recommendations`, {
318
320
  method: "POST",
319
321
  headers: {
320
- "Content-Type": "application/json"
322
+ "Content-Type": "application/json",
323
+ Authorization: `Bearer ${this.token}`
321
324
  },
322
325
  body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
323
326
  }), o = await e.json();
@@ -329,7 +332,7 @@ class p {
329
332
  }
330
333
  }
331
334
  }
332
- class f {
335
+ class y {
333
336
  constructor() {
334
337
  this.api = new p(), this.language = "en", this.translations = {
335
338
  fr: {
@@ -380,8 +383,8 @@ class f {
380
383
  return this.translations[this.language][t] || t;
381
384
  }
382
385
  }
383
- const s = new f();
384
- class y {
386
+ const s = new y();
387
+ class b {
385
388
  constructor() {
386
389
  this.api = new p(), this.displayFirstMessage(s.translate("welcomeMessage"));
387
390
  }
@@ -437,7 +440,7 @@ class y {
437
440
  document.addEventListener("DOMContentLoaded", () => {
438
441
  window.toggleChatWindow = l, window.closeChatWindow = h, window.openChatWindow = u;
439
442
  });
440
- function b() {
443
+ function w() {
441
444
  const n = `
442
445
  <div id="chatbot-container">
443
446
  <div id="chat-icon" onclick="toggleChatWindow()">
@@ -467,10 +470,10 @@ function b() {
467
470
  `;
468
471
  document.body.insertAdjacentHTML("beforeend", n);
469
472
  }
470
- function w() {
473
+ function x() {
471
474
  document.getElementById("close-btn").addEventListener("click", l);
472
475
  }
473
- function x() {
476
+ function v() {
474
477
  window.addEventListener("click", function(n) {
475
478
  const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
476
479
  !t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
@@ -481,11 +484,11 @@ function d(n) {
481
484
  const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
482
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");
483
486
  }
484
- typeof window < "u" && window.addEventListener("DOMContentLoaded", async () => {
487
+ typeof window < "u" && (console.log("привет"), console.log(window.wineaterClientData), window.addEventListener("DOMContentLoaded", async () => {
485
488
  const t = ["climats", "telckel", "biobio", "weinpoint"].find((i) => window.location.href.includes(i)) || null;
486
489
  let e;
487
- t && (e = t.charAt(0).toUpperCase() + t.slice(1)), await s.fetchConfig(e || null), b(), w(), x(), d(t && t === "biobio" ? "right-center" : "bottom-right"), new y().initialize();
488
- });
490
+ t && (e = t.charAt(0).toUpperCase() + t.slice(1)), await s.fetchConfig(e || null), w(), x(), v(), d(t && t === "biobio" ? "right-center" : "bottom-right"), new b().initialize();
491
+ }));
489
492
  export {
490
493
  h as closeChatWindow,
491
494
  u as openChatWindow,
@@ -273,13 +273,13 @@
273
273
  .typing-indicator.visible {
274
274
  visibility: visible;
275
275
  height: 50px;
276
- }`,c=document.createElement("style");c.textContent=r,document.head.appendChild(c);function d(){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 l(){document.getElementById("chat-window").classList.remove("visible")}function p(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const f=["climats","telckel","biobio","weinpoint"];class g{constructor(t){this.baseURL="https://api.wineater.com/",this.store=f.find(e=>window.location.href.includes(e)),console.log(this.store)}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json"},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"},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 g,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 g,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 u=document.createElement("img");u.src=o.Image,i.appendChild(u);const m=document.createElement("div");m.innerHTML=`
276
+ }`,c=document.createElement("style");c.textContent=r,document.head.appendChild(c);function d(){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 l(){document.getElementById("chat-window").classList.remove("visible")}function p(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const f=["climats","telckel","biobio","weinpoint"],y="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class g{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 g,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 g,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 u=document.createElement("img");u.src=o.Image,i.appendChild(u);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(m),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=d,window.closeChatWindow=l,window.openChatWindow=p});function w(){const n=`
282
+ `,i.appendChild(m),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=d,window.closeChatWindow=l,window.openChatWindow=p});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",d)}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 h(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")}typeof window<"u"&&window.addEventListener("DOMContentLoaded",async()=>{const t=["climats","telckel","biobio","weinpoint"].find(i=>window.location.href.includes(i))||null;let e;t&&(e=t.charAt(0).toUpperCase()+t.slice(1)),await s.fetchConfig(e||null),w(),x(),v(),h(t&&t==="biobio"?"right-center":"bottom-right"),new b().initialize()}),a.closeChatWindow=l,a.openChatWindow=p,a.toggleChatWindow=d,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
308
+ `;document.body.insertAdjacentHTML("beforeend",n)}function v(){document.getElementById("close-btn").addEventListener("click",d)}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 h(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")}typeof window<"u"&&(console.log("привет"),console.log(window.wineaterClientData),window.addEventListener("DOMContentLoaded",async()=>{const t=["climats","telckel","biobio","weinpoint"].find(i=>window.location.href.includes(i))||null;let e;t&&(e=t.charAt(0).toUpperCase()+t.slice(1)),await s.fetchConfig(e||null),x(),v(),E(),h(t&&t==="biobio"?"right-center":"bottom-right"),new w().initialize()})),a.closeChatWindow=l,a.openChatWindow=p,a.toggleChatWindow=d,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/index.html CHANGED
@@ -5,8 +5,25 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Chatbot</title>
7
7
  <!-- <script type="module" src="https://unpkg.com/wineater-bot@1.0.0/dist/wineater-chatbot.umd.js"></script> -->
8
+ <script>
9
+
10
+ </script>
8
11
  <script type="module" src="./src/index.js"></script>
9
12
 
13
+ <script>
14
+ // Set the unique token for the chatbot
15
+ window.wineaterData = {
16
+ };
17
+
18
+ // Asynchronously load the chatbot script
19
+ (function() {
20
+ var script = document.createElement('script');
21
+ script.src = "./src/index.js";
22
+ script.type = 'module';
23
+ document.body.appendChild(script);
24
+ })();
25
+ </script>
26
+
10
27
  </head>
11
28
  <body>
12
29
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/index.js CHANGED
@@ -91,6 +91,8 @@ 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
+ console.log('привет');
95
+ console.log(window.wineaterClientData);
94
96
  window.addEventListener('DOMContentLoaded', async () => {
95
97
  const stores = ['climats', 'telckel', 'biobio', 'weinpoint'];
96
98
  const store = stores.find(value => window.location.href.includes(value)) || null;
package/src/js/api.js CHANGED
@@ -1,13 +1,14 @@
1
1
  // api.js
2
2
 
3
3
  const stores = ['climats', 'telckel', 'biobio', 'weinpoint'];
4
+ const DEMO_TOKEN='OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL';
4
5
 
5
6
  export class Api {
6
7
  constructor(apiEndpoint) {
7
8
  // Allow users of the library to specify their own endpoint if needed
8
9
  this.baseURL = 'https://api.wineater.com/';
9
10
  this.store = stores.find(value => window.location.href.includes(value));
10
- console.log(this.store);
11
+ this.token = window?.wineaterData?.CLIENT_TOKEN || DEMO_TOKEN;
11
12
  }
12
13
 
13
14
  async getStoreConfig(storeName) {
@@ -16,7 +17,8 @@ export class Api {
16
17
  const response = await fetch(`${this.baseURL}stores/store`, {
17
18
  method: 'POST',
18
19
  headers: {
19
- 'Content-Type': 'application/json'
20
+ 'Content-Type': 'application/json',
21
+ 'Authorization': `Bearer ${this.token}`
20
22
  },
21
23
  body: JSON.stringify({ store: storeName })
22
24
  });
@@ -34,7 +36,8 @@ export class Api {
34
36
  const response = await fetch(`${this.baseURL}dish/recommendations`, {
35
37
  method: 'POST',
36
38
  headers: {
37
- 'Content-Type': 'application/json'
39
+ 'Content-Type': 'application/json',
40
+ 'Authorization': `Bearer ${this.token}`
38
41
  },
39
42
  body: JSON.stringify({ text: text, store: this.store ? (this.store.toString().charAt(0).toUpperCase() + this.store.slice(1)) : undefined})
40
43
  });