tanya-chatbot 0.6.0 → 0.6.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
- import { useEffect as q, useState as z, useRef as xt } from "react";
1
+ import { useEffect as q, useState as A, useRef as xt } from "react";
2
2
  import { jsx as a, jsxs as u, Fragment as re } from "react/jsx-runtime";
3
3
  import { createHttpLink as lr, ApolloClient as cr, InMemoryCache as dr, ApolloProvider as ur } from "@apollo/client";
4
4
  import { Provider as pr, useDispatch as De, useSelector as Rt } from "react-redux";
@@ -197,7 +197,7 @@ const tt = () => sessionStorage.getItem("Host"), J = () => sessionStorage.getIte
197
197
  return o ? `<p key=${r} class="mb-2"><strong>${o[1]}.</strong> ${o[2]}</p>` : e.trim() ? `<p key=${r} class="mb-2">${e}</p>` : "<br/>";
198
198
  }).join("");
199
199
  function Ir() {
200
- const t = () => window.innerWidth < 425 ? 1 : window.innerWidth < 768 ? 2 : 4, [e, r] = z(t);
200
+ const t = () => window.innerWidth < 425 ? 1 : window.innerWidth < 768 ? 2 : 4, [e, r] = A(t);
201
201
  return q(() => {
202
202
  const o = () => r(t());
203
203
  return window.addEventListener("resize", o), () => window.removeEventListener("resize", o);
@@ -206,7 +206,7 @@ function Ir() {
206
206
  const Fr = ({
207
207
  product: t
208
208
  }) => {
209
- const e = De(), r = Ir(), [o, n] = z(0), c = () => {
209
+ const e = De(), r = Ir(), [o, n] = A(0), c = () => {
210
210
  n(
211
211
  (s) => s + r >= t.length ? 0 : s + r
212
212
  );
@@ -421,14 +421,14 @@ const nt = (t) => {
421
421
  }
422
422
  }, Ce = 300, Tr = ({ addToCartPwa: t }) => {
423
423
  var s, x, y, C, S, H;
424
- const e = De(), r = Rt((N) => N.product.product), o = Rt((N) => N.store.store), [n, c] = z(!!r);
424
+ const e = De(), r = Rt((N) => N.product.product), o = Rt((N) => N.store.store), [n, c] = A(!!r);
425
425
  if (q(() => {
426
426
  c(!!r);
427
427
  }, [r]), !r) return null;
428
428
  const l = async () => {
429
- var N, A, W, lt, R, ct, _t, $t, et, Ct, It, dt, zt, At, rt, P;
429
+ var N, P, W, lt, R, ct, _t, $t, et, Ct, It, dt, zt, At, rt, O;
430
430
  try {
431
- if (!((A = (N = r == null ? void 0 : r.variants) == null ? void 0 : N[0]) != null && A.product_id) && !(r.type.item || r.type.bundle) && !((lt = (W = r == null ? void 0 : r.variants) == null ? void 0 : W[0]) != null && lt.productId)) {
431
+ if (!((P = (N = r == null ? void 0 : r.variants) == null ? void 0 : N[0]) != null && P.product_id) && !(r.type.item || r.type.bundle) && !((lt = (W = r == null ? void 0 : r.variants) == null ? void 0 : W[0]) != null && lt.productId)) {
432
432
  M.error("Variants not available", {
433
433
  position: "bottom-right",
434
434
  autoClose: 1e3
@@ -444,22 +444,22 @@ const nt = (t) => {
444
444
  sessionStorage.getItem("customerData") || "{}"
445
445
  ), ut = (v == null ? void 0 : v.basketId) || localStorage.getItem(Yt), Wt = !1, jt = localStorage.getItem(Pt), Dt = Date.now();
446
446
  if (!Wt || !jt || Dt >= parseInt(jt)) {
447
- let $ = "";
448
- if ($ = "Bearer " + (await Ot()).access_token, !$) {
447
+ let z = "";
448
+ if (z = "Bearer " + (await Ot()).access_token, !z) {
449
449
  console.error("Failed to get customer_token");
450
450
  return;
451
451
  }
452
452
  const pt = Dt + 300 * 1e3;
453
- if (Kt($), localStorage.setItem(Pt, pt.toString()), ut) {
453
+ if (Kt(z), localStorage.setItem(Pt, pt.toString()), ut) {
454
454
  const Ft = await Ye({
455
455
  basketId: ut,
456
- customer_token: $
456
+ customer_token: z
457
457
  });
458
458
  if (Ft.status === 200 && Ft) {
459
459
  const D = await ne(
460
460
  ut,
461
461
  _,
462
- $
462
+ z
463
463
  );
464
464
  (((_t = D == null ? void 0 : D.product_items) == null ? void 0 : _t.length) > 0 || (($t = D == null ? void 0 : D.productItems) == null ? void 0 : $t.length) > 0) && (M.success("Added to cart", {
465
465
  position: "bottom-right",
@@ -479,7 +479,7 @@ const nt = (t) => {
479
479
  quantity: 1
480
480
  }
481
481
  ]
482
- }, k = await Ve($, Lt);
482
+ }, k = await Ve(z, Lt);
483
483
  if (!(k != null && k.basket_id) && !(k != null && k.basketId)) {
484
484
  console.error("Failed to create basket");
485
485
  return;
@@ -490,7 +490,7 @@ const nt = (t) => {
490
490
  const G = await ne(
491
491
  (k == null ? void 0 : k.basket_id) || (k == null ? void 0 : k.basketId),
492
492
  _,
493
- $
493
+ z
494
494
  );
495
495
  console.log("object added to basket"), (((It = G == null ? void 0 : G.product_items) == null ? void 0 : It.length) > 0 || ((dt = G == null ? void 0 : G.productItems) == null ? void 0 : dt.length) > 0) && M.success("Added to cart", {
496
496
  position: "bottom-right",
@@ -506,7 +506,7 @@ const nt = (t) => {
506
506
  position: "bottom-right",
507
507
  autoClose: 3e3
508
508
  }), ((zt = _ == null ? void 0 : _.response) == null ? void 0 : zt.status) === 404 || // Basket not found
509
- ((At = _ == null ? void 0 : _.response) == null ? void 0 : At.status) === 401 ? (((rt = _ == null ? void 0 : _.response) == null ? void 0 : rt.status) === 404 && nt(null), ((P = _ == null ? void 0 : _.response) == null ? void 0 : P.status) === 401 && (nt(null), Kt(null))) : (console.error("Failed to add product to basket:", _.message), M.error("Failed to add product to cart", {
509
+ ((At = _ == null ? void 0 : _.response) == null ? void 0 : At.status) === 401 ? (((rt = _ == null ? void 0 : _.response) == null ? void 0 : rt.status) === 404 && nt(null), ((O = _ == null ? void 0 : _.response) == null ? void 0 : O.status) === 401 && (nt(null), Kt(null))) : (console.error("Failed to add product to basket:", _.message), M.error("Failed to add product to cart", {
510
510
  position: "bottom-right",
511
511
  autoClose: 3e3
512
512
  }));
@@ -561,14 +561,14 @@ const nt = (t) => {
561
561
  }
562
562
  ) }),
563
563
  /* @__PURE__ */ a("div", { className: "flex flex-col items-center gap-2", children: r.imageGroups.slice(1, 2).map(
564
- (N) => N.images.slice(1, 2).map((A) => /* @__PURE__ */ a(
564
+ (N) => N.images.slice(1, 2).map((P) => /* @__PURE__ */ a(
565
565
  "img",
566
566
  {
567
- src: A.link,
567
+ src: P.link,
568
568
  alt: r.name,
569
569
  className: "rounded-[10px] w-[60px] h-[60px]"
570
570
  },
571
- A.link
571
+ P.link
572
572
  ))
573
573
  ) })
574
574
  ] }),
@@ -615,7 +615,7 @@ const nt = (t) => {
615
615
  " ratings"
616
616
  ] })
617
617
  ] }) }),
618
- /* @__PURE__ */ a("div", { className: "mt-2 flex flex-row items-center gap-2", children: Array.from({ length: 5 }).map((N, A) => {
618
+ /* @__PURE__ */ a("div", { className: "mt-2 flex flex-row items-center gap-2", children: Array.from({ length: 5 }).map((N, P) => {
619
619
  var W;
620
620
  return /* @__PURE__ */ a(
621
621
  be,
@@ -624,10 +624,10 @@ const nt = (t) => {
624
624
  width: "20",
625
625
  height: "20",
626
626
  className: `text-yellow-500
627
- ${((W = r == null ? void 0 : r.rating) == null ? void 0 : W.rate) > A ? "text-yellow-500" : "text-gray-300"}
627
+ ${((W = r == null ? void 0 : r.rating) == null ? void 0 : W.rate) > P ? "text-yellow-500" : "text-gray-300"}
628
628
  `
629
629
  },
630
- A
630
+ P
631
631
  );
632
632
  }) })
633
633
  ] }),
@@ -681,14 +681,14 @@ const nt = (t) => {
681
681
  "Niece/Nephew": "his/her niece/nephew",
682
682
  "My Friends": "his/her friends",
683
683
  Others: "others"
684
- }, c = xt(null), l = xt(null), d = xt(null), s = xt(null), [x, y] = z(null);
684
+ }, c = xt(null), l = xt(null), d = xt(null), s = xt(null), [x, y] = A(null);
685
685
  xt(null);
686
- const [C, S] = z(!1), [H, N] = z(!1), [A, W] = z(!1), [lt, R] = z(!1), [ct, _t] = z(!1), [$t, et] = z(!1), [Ct, It] = z(""), [dt, zt] = z(""), At = (i) => ({
686
+ const [C, S] = A(!1), [H, N] = A(!1), [P, W] = A(!1), [lt, R] = A(!1), [ct, _t] = A(!1), [$t, et] = A(!1), [Ct, It] = A(""), [dt, zt] = A(""), At = (i) => ({
687
687
  id: i.id,
688
688
  title: i.name,
689
689
  image: i.image ?? "",
690
690
  price: i.price ?? 0
691
- }), [rt, P] = z([]), _ = xt(null), v = Rt((i) => i.store.store), ut = Rt((i) => i.product.product);
691
+ }), [rt, O] = A([]), _ = xt(null), v = Rt((i) => i.store.store), ut = Rt((i) => i.product.product);
692
692
  q(() => {
693
693
  const i = localStorage.getItem(
694
694
  `access_token_${t.siteId}`
@@ -697,7 +697,7 @@ const nt = (t) => {
697
697
  );
698
698
  if (i && w === i) {
699
699
  const m = localStorage.getItem("chatHistory");
700
- m && P(JSON.parse(m));
700
+ m && O(JSON.parse(m));
701
701
  } else
702
702
  localStorage.setItem("chatHistory", JSON.stringify([])), localStorage.setItem(
703
703
  `chat-token-${t.siteId}`,
@@ -722,12 +722,15 @@ const nt = (t) => {
722
722
  zt(n[i]);
723
723
  };
724
724
  q(() => {
725
- _.current && (_.current.scrollTop += 150);
726
- }, [rt]);
727
- let $ = null, pt = null;
725
+ P && _.current && _.current.scrollTo({
726
+ top: _.current.scrollHeight,
727
+ behavior: "smooth"
728
+ });
729
+ }, [rt, P]);
730
+ let z = null, pt = null;
728
731
  const Lt = async () => {
729
- if ($ && pt && Date.now() < pt)
730
- return $;
732
+ if (z && pt && Date.now() < pt)
733
+ return z;
731
734
  try {
732
735
  const i = "https://us-east-1lsr29ln3u.auth.us-east-1.amazoncognito.com/oauth2/token", w = new URLSearchParams({
733
736
  grant_type: "client_credentials",
@@ -746,11 +749,11 @@ const nt = (t) => {
746
749
  `Token request failed! status: ${m.status}`
747
750
  );
748
751
  const g = await m.json();
749
- $ = g.access_token;
752
+ z = g.access_token;
750
753
  const p = g.expires_in || 3600;
751
- return pt = Date.now() + (p - 60) * 1e3, $;
754
+ return pt = Date.now() + (p - 60) * 1e3, z;
752
755
  } catch (i) {
753
- return console.error("Error obtaining JWT token:", i), $ = null, pt = null, null;
756
+ return console.error("Error obtaining JWT token:", i), z = null, pt = null, null;
754
757
  }
755
758
  }, k = async () => {
756
759
  const i = await Ot();
@@ -775,7 +778,7 @@ const nt = (t) => {
775
778
  const m = await G();
776
779
  if (console.log(m, "interests of customer", Nt), !!m)
777
780
  try {
778
- P(
781
+ O(
779
782
  (U) => U.map(
780
783
  (V, Y) => Y === U.length - 1 ? { ...V, secondaryLoading: !0 } : V
781
784
  )
@@ -818,19 +821,19 @@ const nt = (t) => {
818
821
  const f = X.slice(5).trim();
819
822
  try {
820
823
  const K = JSON.parse(f);
821
- K.index === 0 && P(
824
+ K.index === 0 && O(
822
825
  (I) => I.map(
823
- (O, Q) => Q === I.length - 1 ? {
824
- ...O,
826
+ ($, Q) => Q === I.length - 1 ? {
827
+ ...$,
825
828
  secondaryResponse: K.data,
826
829
  secondaryLoading: !1
827
- } : O
830
+ } : $
828
831
  )
829
832
  );
830
833
  } catch (K) {
831
- P(
834
+ O(
832
835
  (I) => I.map(
833
- (O, Q) => Q === I.length - 1 ? { ...O, secondaryLoading: !1 } : O
836
+ ($, Q) => Q === I.length - 1 ? { ...$, secondaryLoading: !1 } : $
834
837
  )
835
838
  ), console.error("Secondary flow JSON parse error:", K);
836
839
  }
@@ -842,7 +845,7 @@ const nt = (t) => {
842
845
  }, D = async (i) => {
843
846
  const w = i || Ct.trim();
844
847
  if (w) {
845
- _t(!0), It(""), c.current = null, l.current = null, d.current = null, s.current = null, P((m) => [
848
+ _t(!0), It(""), c.current = null, l.current = null, d.current = null, s.current = null, O((m) => [
846
849
  ...m,
847
850
  {
848
851
  query: w,
@@ -893,9 +896,9 @@ const nt = (t) => {
893
896
  const K = f.slice(5).trim();
894
897
  try {
895
898
  const I = JSON.parse(K);
896
- I.index == 1 && (U = I.data), P(
897
- (O) => O.map(
898
- (Q, Bt) => Bt === O.length - 1 ? {
899
+ I.index == 1 && (U = I.data), O(
900
+ ($) => $.map(
901
+ (Q, Bt) => Bt === $.length - 1 ? {
899
902
  ...Q,
900
903
  [I.index == 0 ? "response" : I.index == 1 ? "keywords" : I.index == 2 ? "potentialQuestions" : "end"]: I.data
901
904
  } : Q
@@ -924,7 +927,7 @@ const nt = (t) => {
924
927
  const w = i.split(",");
925
928
  for (const m of w) {
926
929
  const g = await xe(m);
927
- if (et(!1), (g == null ? void 0 : g.length) > 0 && (P(
930
+ if (et(!1), (g == null ? void 0 : g.length) > 0 && (O(
928
931
  (p) => p.map(
929
932
  (h, j) => j === p.length - 1 ? {
930
933
  ...h,
@@ -944,7 +947,7 @@ const nt = (t) => {
944
947
  } else
945
948
  for (const w of i) {
946
949
  const m = await xe(w);
947
- et(!1), (m == null ? void 0 : m.length) > 0 && P(
950
+ et(!1), (m == null ? void 0 : m.length) > 0 && O(
948
951
  (g) => g.map(
949
952
  (p, h) => h === g.length - 1 ? {
950
953
  ...p,
@@ -957,7 +960,7 @@ const nt = (t) => {
957
960
  );
958
961
  }
959
962
  if (c.current) {
960
- P(
963
+ O(
961
964
  (m) => m.map(
962
965
  (g, p) => p === m.length - 1 ? {
963
966
  ...g,
@@ -999,7 +1002,7 @@ const nt = (t) => {
999
1002
  console.log(K, "product data", "app version", Nt);
1000
1003
  const I = JSON.parse(
1001
1004
  sessionStorage.getItem("customerData") || "{}"
1002
- ), O = (I == null ? void 0 : I.basketId) || localStorage.getItem(Yt), Q = !1, Bt = localStorage.getItem(Pt), we = Date.now();
1005
+ ), $ = (I == null ? void 0 : I.basketId) || localStorage.getItem(Yt), Q = !1, Bt = localStorage.getItem(Pt), we = Date.now();
1003
1006
  if (!Q || !Bt || we >= parseInt(Bt)) {
1004
1007
  const ar = await Me();
1005
1008
  let { customer_token: gt } = await He(
@@ -1010,14 +1013,14 @@ const nt = (t) => {
1010
1013
  return;
1011
1014
  }
1012
1015
  const ir = we + 300 * 1e3;
1013
- if (Kt(gt), localStorage.setItem(Pt, ir.toString()), console.log(O, "basketIdFromCustomer"), O) {
1016
+ if (Kt(gt), localStorage.setItem(Pt, ir.toString()), console.log($, "basketIdFromCustomer"), $) {
1014
1017
  const ge = await Ye({
1015
- basketId: O,
1018
+ basketId: $,
1016
1019
  customer_token: gt
1017
1020
  });
1018
1021
  if (ge.status === 200 && ge) {
1019
1022
  const Gt = await ne(
1020
- O,
1023
+ $,
1021
1024
  K,
1022
1025
  gt
1023
1026
  );
@@ -1028,7 +1031,7 @@ const nt = (t) => {
1028
1031
  closeOnClick: !0,
1029
1032
  pauseOnHover: !0,
1030
1033
  draggable: !0
1031
- }), Vt(O), R(!1));
1034
+ }), Vt($), R(!1));
1032
1035
  return;
1033
1036
  }
1034
1037
  }
@@ -1081,8 +1084,8 @@ const nt = (t) => {
1081
1084
  R(!1);
1082
1085
  };
1083
1086
  return q(() => {
1084
- A ? setTimeout(() => N(!0), 10) : N(!1);
1085
- }, [A]), /* @__PURE__ */ a("div", { className: "relative flex justify-center", children: /* @__PURE__ */ u(vr, { open: C, onOpenChange: S, children: [
1087
+ P ? setTimeout(() => N(!0), 10) : N(!1);
1088
+ }, [P]), /* @__PURE__ */ a("div", { className: "relative flex justify-center", children: /* @__PURE__ */ u(vr, { open: C, onOpenChange: S, children: [
1086
1089
  /* @__PURE__ */ a(
1087
1090
  kr,
1088
1091
  {
@@ -1146,7 +1149,7 @@ const nt = (t) => {
1146
1149
  ) })
1147
1150
  }
1148
1151
  ),
1149
- A && /* @__PURE__ */ u(re, { children: [
1152
+ P && /* @__PURE__ */ u(re, { children: [
1150
1153
  /* @__PURE__ */ a(
1151
1154
  "div",
1152
1155
  {
@@ -1478,7 +1481,7 @@ const nt = (t) => {
1478
1481
  "button",
1479
1482
  {
1480
1483
  className: "px-3 py-1 text-sm",
1481
- onClick: () => P(
1484
+ onClick: () => O(
1482
1485
  (p) => p.map(
1483
1486
  (h, j) => j === w && h.productSnapshot ? {
1484
1487
  ...h,
@@ -1504,7 +1507,7 @@ const nt = (t) => {
1504
1507
  "button",
1505
1508
  {
1506
1509
  className: "px-3 py-1 text-sm",
1507
- onClick: () => P(
1510
+ onClick: () => O(
1508
1511
  (p) => p.map(
1509
1512
  (h, j) => j === w && h.productSnapshot ? {
1510
1513
  ...h,