tanya-chatbot 0.5.4 → 0.5.5
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/tanya-chatbot.es.js
CHANGED
|
@@ -101,7 +101,7 @@ const St = () => ({ aiConversationUrl: "https://mdv3qwfi2j.execute-api.us-east-1
|
|
|
101
101
|
const t = "https://tanya-sfcc-server.vercel.app/";
|
|
102
102
|
try {
|
|
103
103
|
const e = await E.post(
|
|
104
|
-
`${t}api/auth/token-bm-grant?baseUrl=${
|
|
104
|
+
`${t}api/auth/token-bm-grant?baseUrl=${Z()}&siteId=${Y()}`
|
|
105
105
|
);
|
|
106
106
|
return e.status === 200 && e.data.access_token ? e.data.access_token : (console.error("Failed to fetch token:", e.data), null);
|
|
107
107
|
} catch (e) {
|
|
@@ -111,7 +111,7 @@ const St = () => ({ aiConversationUrl: "https://mdv3qwfi2j.execute-api.us-east-1
|
|
|
111
111
|
const e = "https://tanya-sfcc-server.vercel.app/";
|
|
112
112
|
try {
|
|
113
113
|
const r = JSON.parse(sessionStorage.getItem("customerData") || "{}").dwsid, o = await E.post(
|
|
114
|
-
`${e}api/auth/token-existing-guest-customer?dwsid=${r}&baseUrl=${
|
|
114
|
+
`${e}api/auth/token-existing-guest-customer?dwsid=${r}&baseUrl=${Z()}&siteId=${Y()}&pubCfg=${it()}&envRef=${st()}&orgRef=${lt()}`,
|
|
115
115
|
{},
|
|
116
116
|
{
|
|
117
117
|
headers: {
|
|
@@ -130,7 +130,7 @@ async function $t() {
|
|
|
130
130
|
const t = Y(), e = "access_token_" + t, r = "expires_in_" + t, o = localStorage.getItem(r), n = localStorage.getItem(e);
|
|
131
131
|
return console.log(n), (c = JSON.parse(sessionStorage.getItem("customerData") || "{}")) != null && c.isGuest, console.log("access token found in local storage"), { access_token: n, expires_in: o };
|
|
132
132
|
}
|
|
133
|
-
const
|
|
133
|
+
const Z = () => sessionStorage.getItem("Host"), Y = () => sessionStorage.getItem("SiteId"), it = () => sessionStorage.getItem("pubCfg"), st = () => sessionStorage.getItem("envRef"), lt = () => sessionStorage.getItem("orgRef"), ye = async (t) => {
|
|
134
134
|
console.log("fetching results");
|
|
135
135
|
const { serverUrl: e, basePath: r } = St();
|
|
136
136
|
let o = "";
|
|
@@ -139,7 +139,7 @@ const Q = () => sessionStorage.getItem("Host"), Y = () => sessionStorage.getItem
|
|
|
139
139
|
console.log("the token from getSearchResults", n), o = n.access_token;
|
|
140
140
|
}
|
|
141
141
|
try {
|
|
142
|
-
const n =
|
|
142
|
+
const n = Z();
|
|
143
143
|
return (await E.get(
|
|
144
144
|
`${e}${r}/search-sfcc?baseUrl=${n}&query=${t}&siteId=${Y()}&pubCfg=${it()}&envRef=${st()}&orgRef=${lt()}`,
|
|
145
145
|
{
|
|
@@ -154,7 +154,7 @@ const Q = () => sessionStorage.getItem("Host"), Y = () => sessionStorage.getItem
|
|
|
154
154
|
}
|
|
155
155
|
}, Ve = async (t) => {
|
|
156
156
|
if (!t) throw new Error("Product ID is required");
|
|
157
|
-
const { serverUrl: e, basePath: r } = St(), o =
|
|
157
|
+
const { serverUrl: e, basePath: r } = St(), o = Z();
|
|
158
158
|
console.log("calling access");
|
|
159
159
|
const { access_token: n } = await $t();
|
|
160
160
|
return (await E.get(
|
|
@@ -172,7 +172,7 @@ const Q = () => sessionStorage.getItem("Host"), Y = () => sessionStorage.getItem
|
|
|
172
172
|
e
|
|
173
173
|
), { serverUrl: o, basePath: n } = St(), l = (await $t()).access_token;
|
|
174
174
|
return (await E.get(
|
|
175
|
-
`${o}${n}/get-interest?baseUrl=${
|
|
175
|
+
`${o}${n}/get-interest?baseUrl=${Z()}&customerId=${t}&siteId=${Y()}&pubCfg=${it()}&envRef=${st()}&orgRef=${lt()}`,
|
|
176
176
|
{
|
|
177
177
|
headers: {
|
|
178
178
|
"Content-Type": "application/json",
|
|
@@ -342,7 +342,7 @@ const Nr = ({
|
|
|
342
342
|
const { serverUrl: r, basePath: o } = St(), n = `${r}`;
|
|
343
343
|
try {
|
|
344
344
|
const d = await E.post(
|
|
345
|
-
`${n}${o}/basket/create?baseUrl=${
|
|
345
|
+
`${n}${o}/basket/create?baseUrl=${Z()}&siteId=${Y()}&pubCfg=${it()}&envRef=${st()}&orgRef=${lt()}`,
|
|
346
346
|
e,
|
|
347
347
|
{
|
|
348
348
|
headers: {
|
|
@@ -365,7 +365,7 @@ const Nr = ({
|
|
|
365
365
|
const { serverUrl: o, basePath: n } = St(), c = `${o}`;
|
|
366
366
|
try {
|
|
367
367
|
const l = await E.post(
|
|
368
|
-
`${c}${n}/basket/add-product/${t}?baseUrl=${
|
|
368
|
+
`${c}${n}/basket/add-product/${t}?baseUrl=${Z()}&siteId=${Y()}&pubCfg=${it()}&envRef=${st()}&orgRef=${lt()}`,
|
|
369
369
|
e,
|
|
370
370
|
{
|
|
371
371
|
headers: {
|
|
@@ -389,7 +389,7 @@ const Nr = ({
|
|
|
389
389
|
const { serverUrl: r, basePath: o } = St(), n = `${r}`;
|
|
390
390
|
try {
|
|
391
391
|
const l = await E.get(
|
|
392
|
-
`${n}${o}/basket/${t}?baseUrl=${
|
|
392
|
+
`${n}${o}/basket/${t}?baseUrl=${Z()}&siteId=${Y()}&pubCfg=${it()}&envRef=${st()}&orgRef=${lt()}`,
|
|
393
393
|
{
|
|
394
394
|
headers: {
|
|
395
395
|
"Content-Type": "application/json",
|
|
@@ -426,9 +426,9 @@ const at = (t) => {
|
|
|
426
426
|
c(!!r);
|
|
427
427
|
}, [r]), !r) return null;
|
|
428
428
|
const l = async () => {
|
|
429
|
-
var T, A,
|
|
429
|
+
var T, A, tt, _t, ct, q, dt, Ct, zt, et, It, Ft, ut, At, jt, K;
|
|
430
430
|
try {
|
|
431
|
-
if (!((A = (T = r == null ? void 0 : r.variants) == null ? void 0 : T[0]) != null && A.product_id) && !(r.type.item || r.type.bundle) && !((_t = (
|
|
431
|
+
if (!((A = (T = r == null ? void 0 : r.variants) == null ? void 0 : T[0]) != null && A.product_id) && !(r.type.item || r.type.bundle) && !((_t = (tt = r == null ? void 0 : r.variants) == null ? void 0 : tt[0]) != null && _t.productId)) {
|
|
432
432
|
U.error("Variants not available", {
|
|
433
433
|
position: "bottom-right",
|
|
434
434
|
autoClose: 1e3
|
|
@@ -456,12 +456,12 @@ const at = (t) => {
|
|
|
456
456
|
customer_token: M
|
|
457
457
|
});
|
|
458
458
|
if (Nt.status === 200 && Nt) {
|
|
459
|
-
const
|
|
459
|
+
const W = await ae(
|
|
460
460
|
k,
|
|
461
461
|
b,
|
|
462
462
|
M
|
|
463
463
|
);
|
|
464
|
-
(((dt =
|
|
464
|
+
(((dt = W == null ? void 0 : W.product_items) == null ? void 0 : dt.length) > 0 || ((Ct = W == null ? void 0 : W.productItems) == null ? void 0 : Ct.length) > 0) && (U.success("Added to cart", {
|
|
465
465
|
position: "bottom-right",
|
|
466
466
|
autoClose: 3e3,
|
|
467
467
|
hideProgressBar: !1,
|
|
@@ -475,7 +475,7 @@ const at = (t) => {
|
|
|
475
475
|
const pt = {
|
|
476
476
|
productItems: [
|
|
477
477
|
{
|
|
478
|
-
productId: ((zt = r.variants) == null ? void 0 : zt[0].product_id) || ((
|
|
478
|
+
productId: ((zt = r.variants) == null ? void 0 : zt[0].product_id) || ((et = r.variants) == null ? void 0 : et[0].productId) || (r == null ? void 0 : r.id),
|
|
479
479
|
quantity: 1
|
|
480
480
|
}
|
|
481
481
|
]
|
|
@@ -487,12 +487,12 @@ const at = (t) => {
|
|
|
487
487
|
at(
|
|
488
488
|
(S == null ? void 0 : S.basket_id) || (S == null ? void 0 : S.basketId)
|
|
489
489
|
), console.log("adding product to basket");
|
|
490
|
-
const
|
|
490
|
+
const J = await ae(
|
|
491
491
|
(S == null ? void 0 : S.basket_id) || (S == null ? void 0 : S.basketId),
|
|
492
492
|
b,
|
|
493
493
|
M
|
|
494
494
|
);
|
|
495
|
-
console.log("object added to basket"), (((It =
|
|
495
|
+
console.log("object added to basket"), (((It = J == null ? void 0 : J.product_items) == null ? void 0 : It.length) > 0 || ((Ft = J == null ? void 0 : J.productItems) == null ? void 0 : Ft.length) > 0) && U.success("Added to cart", {
|
|
496
496
|
position: "bottom-right",
|
|
497
497
|
autoClose: 3e3,
|
|
498
498
|
hideProgressBar: !1,
|
|
@@ -506,7 +506,7 @@ const at = (t) => {
|
|
|
506
506
|
position: "bottom-right",
|
|
507
507
|
autoClose: 3e3
|
|
508
508
|
}), ((ut = b == null ? void 0 : b.response) == null ? void 0 : ut.status) === 404 || // Basket not found
|
|
509
|
-
((At = b == null ? void 0 : b.response) == null ? void 0 : At.status) === 401 ? (((jt = b == null ? void 0 : b.response) == null ? void 0 : jt.status) === 404 && at(null), ((
|
|
509
|
+
((At = b == null ? void 0 : b.response) == null ? void 0 : At.status) === 401 ? (((jt = b == null ? void 0 : b.response) == null ? void 0 : jt.status) === 404 && at(null), ((K = b == null ? void 0 : b.response) == null ? void 0 : K.status) === 401 && (at(null), Kt(null))) : (console.error("Failed to add product to basket:", b.message), U.error("Failed to add product to cart", {
|
|
510
510
|
position: "bottom-right",
|
|
511
511
|
autoClose: 3e3
|
|
512
512
|
}));
|
|
@@ -616,7 +616,7 @@ const at = (t) => {
|
|
|
616
616
|
] })
|
|
617
617
|
] }) }),
|
|
618
618
|
/* @__PURE__ */ a("div", { className: "mt-2 flex flex-row items-center gap-2", children: Array.from({ length: 5 }).map((T, A) => {
|
|
619
|
-
var
|
|
619
|
+
var tt;
|
|
620
620
|
return /* @__PURE__ */ a(
|
|
621
621
|
xe,
|
|
622
622
|
{
|
|
@@ -624,7 +624,7 @@ const at = (t) => {
|
|
|
624
624
|
width: "20",
|
|
625
625
|
height: "20",
|
|
626
626
|
className: `text-yellow-500
|
|
627
|
-
${((
|
|
627
|
+
${((tt = r == null ? void 0 : r.rating) == null ? void 0 : tt.rate) > A ? "text-yellow-500" : "text-gray-300"}
|
|
628
628
|
`
|
|
629
629
|
},
|
|
630
630
|
A
|
|
@@ -681,19 +681,19 @@ const at = (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), i = xt(null), [y, v] = $(null), C = xt(null), [_, O] = $(!1), [T, A] = $(!1), [
|
|
684
|
+
}, c = xt(null), l = xt(null), d = xt(null), i = xt(null), [y, v] = $(null), C = xt(null), [_, O] = $(!1), [T, A] = $(!1), [tt, _t] = $(!1), [ct, q] = $(!1), [dt, Ct] = $(!1), [zt, et] = $(!1), [It, Ft] = $(""), [ut, At] = $(""), jt = (s) => ({
|
|
685
685
|
id: s.id,
|
|
686
686
|
title: s.name,
|
|
687
687
|
image: s.image ?? "",
|
|
688
688
|
price: s.price ?? 0
|
|
689
|
-
}), [
|
|
689
|
+
}), [K, b] = $([]), rt = xt(null), k = Rt((s) => s.store.store), Wt = Rt((s) => s.product.product);
|
|
690
690
|
B(() => {
|
|
691
691
|
const s = localStorage.getItem(
|
|
692
692
|
`access_token_${t.siteId}`
|
|
693
|
-
),
|
|
693
|
+
), m = localStorage.getItem(
|
|
694
694
|
`chat-token-${t.siteId}`
|
|
695
695
|
);
|
|
696
|
-
if (s &&
|
|
696
|
+
if (s && m === s) {
|
|
697
697
|
const h = localStorage.getItem("chatHistory");
|
|
698
698
|
h && b(JSON.parse(h));
|
|
699
699
|
} else
|
|
@@ -702,12 +702,12 @@ const at = (t) => {
|
|
|
702
702
|
s || ""
|
|
703
703
|
);
|
|
704
704
|
}, []), B(() => {
|
|
705
|
-
localStorage.setItem("chatHistory", JSON.stringify(
|
|
705
|
+
localStorage.setItem("chatHistory", JSON.stringify(K));
|
|
706
706
|
const s = localStorage.getItem(
|
|
707
707
|
`access_token_${t.siteId}`
|
|
708
708
|
);
|
|
709
709
|
s && localStorage.setItem(`chat-token-${t.siteId}`, s);
|
|
710
|
-
}, [
|
|
710
|
+
}, [K]);
|
|
711
711
|
const Dt = () => {
|
|
712
712
|
_t(!0), setTimeout(() => A(!0), 10);
|
|
713
713
|
}, Lt = () => {
|
|
@@ -721,13 +721,13 @@ const at = (t) => {
|
|
|
721
721
|
};
|
|
722
722
|
B(() => {
|
|
723
723
|
rt.current && (rt.current.scrollTop += 150);
|
|
724
|
-
}, [
|
|
724
|
+
}, [K]);
|
|
725
725
|
let ot = null, pt = null;
|
|
726
726
|
const S = async () => {
|
|
727
727
|
if (ot && pt && Date.now() < pt)
|
|
728
728
|
return ot;
|
|
729
729
|
try {
|
|
730
|
-
const s = "https://us-east-1lsr29ln3u.auth.us-east-1.amazoncognito.com/oauth2/token",
|
|
730
|
+
const s = "https://us-east-1lsr29ln3u.auth.us-east-1.amazoncognito.com/oauth2/token", m = new URLSearchParams({
|
|
731
731
|
grant_type: "client_credentials",
|
|
732
732
|
client_id: "4i8rd70sgt961tc4dhskgf08c",
|
|
733
733
|
client_secret: "bnsfq1220loh2cn2cm2ttn8fdhdpt0u8m1fgj8vfk2rn61aurjg",
|
|
@@ -737,7 +737,7 @@ const at = (t) => {
|
|
|
737
737
|
headers: {
|
|
738
738
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
739
739
|
},
|
|
740
|
-
body:
|
|
740
|
+
body: m
|
|
741
741
|
});
|
|
742
742
|
if (!h.ok)
|
|
743
743
|
throw new Error(
|
|
@@ -750,16 +750,16 @@ const at = (t) => {
|
|
|
750
750
|
} catch (s) {
|
|
751
751
|
return console.error("Error obtaining JWT token:", s), ot = null, pt = null, null;
|
|
752
752
|
}
|
|
753
|
-
},
|
|
753
|
+
}, J = async () => {
|
|
754
754
|
const s = await $t();
|
|
755
755
|
s != null && v(s);
|
|
756
756
|
};
|
|
757
757
|
B(() => {
|
|
758
758
|
if (t != null && t.siteId) {
|
|
759
|
-
const { clientID: s, host:
|
|
760
|
-
sessionStorage.setItem("Host",
|
|
759
|
+
const { clientID: s, host: m, organizationID: h, shortCode: g, siteId: p } = t;
|
|
760
|
+
sessionStorage.setItem("Host", m), sessionStorage.setItem("SiteId", p), sessionStorage.setItem("pubCfg", btoa(s)), sessionStorage.setItem("envRef", g), sessionStorage.setItem("orgRef", h);
|
|
761
761
|
}
|
|
762
|
-
|
|
762
|
+
J(), console.log("scapi environment v1");
|
|
763
763
|
}, []), B(() => {
|
|
764
764
|
e && (console.log("setting the basket id", e), at(e));
|
|
765
765
|
}, [e]);
|
|
@@ -768,7 +768,7 @@ const at = (t) => {
|
|
|
768
768
|
sessionStorage.getItem("customerData") || "{}"
|
|
769
769
|
).customerId;
|
|
770
770
|
return (await _r(s || "")).c_interests;
|
|
771
|
-
},
|
|
771
|
+
}, W = async (s, m) => {
|
|
772
772
|
console.log("in secondary flow", Et);
|
|
773
773
|
const h = await Nt();
|
|
774
774
|
if (console.log(h, "interests of customer", Et), !!h)
|
|
@@ -780,8 +780,8 @@ const at = (t) => {
|
|
|
780
780
|
);
|
|
781
781
|
const g = await S();
|
|
782
782
|
if (!g) throw new Error("Failed to fetch token");
|
|
783
|
-
const p = localStorage.getItem("customerNumber"),
|
|
784
|
-
registered: String(
|
|
783
|
+
const p = localStorage.getItem("customerNumber"), w = localStorage.getItem("isLoggedIn"), ft = `https://tanya.aspiresystems.com/api/bedrock/invoke/stream?${new URLSearchParams({
|
|
784
|
+
registered: String(w || !1),
|
|
785
785
|
userId: String(p || (/* @__PURE__ */ new Date()).getTime())
|
|
786
786
|
}).toString()}`, ht = JSON.stringify({
|
|
787
787
|
flowId: "Q166PR519W",
|
|
@@ -789,7 +789,7 @@ const at = (t) => {
|
|
|
789
789
|
input: {
|
|
790
790
|
loyaltyPoints: "",
|
|
791
791
|
productName: s,
|
|
792
|
-
productPoints: String(
|
|
792
|
+
productPoints: String(m || 0),
|
|
793
793
|
interests: h
|
|
794
794
|
}
|
|
795
795
|
}), j = await fetch(ft, {
|
|
@@ -811,14 +811,14 @@ const at = (t) => {
|
|
|
811
811
|
const R = D.split(`
|
|
812
812
|
`);
|
|
813
813
|
D = R.pop() || "";
|
|
814
|
-
for (const
|
|
815
|
-
if (
|
|
816
|
-
const f =
|
|
814
|
+
for (const G of R)
|
|
815
|
+
if (G.startsWith("data:")) {
|
|
816
|
+
const f = G.slice(5).trim();
|
|
817
817
|
try {
|
|
818
818
|
const V = JSON.parse(f);
|
|
819
819
|
V.index === 0 && b(
|
|
820
820
|
(I) => I.map(
|
|
821
|
-
(P,
|
|
821
|
+
(P, X) => X === I.length - 1 ? {
|
|
822
822
|
...P,
|
|
823
823
|
secondaryResponse: V.data,
|
|
824
824
|
secondaryLoading: !1
|
|
@@ -828,7 +828,7 @@ const at = (t) => {
|
|
|
828
828
|
} catch (V) {
|
|
829
829
|
b(
|
|
830
830
|
(I) => I.map(
|
|
831
|
-
(P,
|
|
831
|
+
(P, X) => X === I.length - 1 ? { ...P, secondaryLoading: !1 } : P
|
|
832
832
|
)
|
|
833
833
|
), console.error("Secondary flow JSON parse error:", V);
|
|
834
834
|
}
|
|
@@ -838,12 +838,12 @@ const at = (t) => {
|
|
|
838
838
|
console.error("Secondary flow error:", g);
|
|
839
839
|
}
|
|
840
840
|
}, Gt = async (s) => {
|
|
841
|
-
const
|
|
842
|
-
if (
|
|
841
|
+
const m = s || It.trim();
|
|
842
|
+
if (m) {
|
|
843
843
|
Ct(!0), Ft(""), c.current = null, l.current = null, d.current = null, i.current = null, b((h) => [
|
|
844
844
|
...h,
|
|
845
845
|
{
|
|
846
|
-
query:
|
|
846
|
+
query: m,
|
|
847
847
|
response: "Thinking for what suits you best...",
|
|
848
848
|
potentialQuestions: "",
|
|
849
849
|
products: [],
|
|
@@ -851,8 +851,8 @@ const at = (t) => {
|
|
|
851
851
|
}
|
|
852
852
|
]);
|
|
853
853
|
try {
|
|
854
|
-
const h = ut, g = localStorage.getItem("customerNumber"), p = localStorage.getItem("isLoggedIn"),
|
|
855
|
-
if (!
|
|
854
|
+
const h = ut, g = localStorage.getItem("customerNumber"), p = localStorage.getItem("isLoggedIn"), w = await S();
|
|
855
|
+
if (!w)
|
|
856
856
|
throw new Error("Failed to obtain access token");
|
|
857
857
|
const ft = `https://tanya.aspiresystems.com/api/bedrock/invoke/stream?${new URLSearchParams({
|
|
858
858
|
registered: String(p || !1),
|
|
@@ -861,7 +861,7 @@ const at = (t) => {
|
|
|
861
861
|
flowId: "MMHQKYI1NE",
|
|
862
862
|
flowAliasId: "SZF9ZK1ATE",
|
|
863
863
|
input: {
|
|
864
|
-
userPrompt:
|
|
864
|
+
userPrompt: m,
|
|
865
865
|
whom: h
|
|
866
866
|
}
|
|
867
867
|
}), j = await fetch(ft, {
|
|
@@ -869,7 +869,7 @@ const at = (t) => {
|
|
|
869
869
|
method: "POST",
|
|
870
870
|
headers: {
|
|
871
871
|
"Content-Type": "application/json",
|
|
872
|
-
Authorization: `Bearer ${
|
|
872
|
+
Authorization: `Bearer ${w}`
|
|
873
873
|
},
|
|
874
874
|
body: ht
|
|
875
875
|
});
|
|
@@ -879,24 +879,24 @@ const at = (t) => {
|
|
|
879
879
|
const mt = j.body.getReader(), wt = new TextDecoder();
|
|
880
880
|
let D = "", L = "";
|
|
881
881
|
for (; ; ) {
|
|
882
|
-
|
|
882
|
+
et(!0);
|
|
883
883
|
const { done: H, value: R } = await mt.read();
|
|
884
884
|
if (H) break;
|
|
885
885
|
D += wt.decode(R, { stream: !0 });
|
|
886
|
-
const
|
|
886
|
+
const G = D.split(`
|
|
887
887
|
`);
|
|
888
|
-
D =
|
|
889
|
-
for (const f of
|
|
888
|
+
D = G.pop() || "";
|
|
889
|
+
for (const f of G)
|
|
890
890
|
if (f.startsWith("data:")) {
|
|
891
891
|
const V = f.slice(5).trim();
|
|
892
892
|
try {
|
|
893
893
|
const I = JSON.parse(V);
|
|
894
894
|
I.index == 1 && (L = I.data), b(
|
|
895
895
|
(P) => P.map(
|
|
896
|
-
(
|
|
897
|
-
...
|
|
896
|
+
(X, Bt) => Bt === P.length - 1 ? {
|
|
897
|
+
...X,
|
|
898
898
|
[I.index == 0 ? "response" : I.index == 1 ? "keywords" : I.index == 2 ? "potentialQuestions" : "end"]: I.data
|
|
899
|
-
} :
|
|
899
|
+
} : X
|
|
900
900
|
)
|
|
901
901
|
);
|
|
902
902
|
} catch (I) {
|
|
@@ -912,43 +912,43 @@ const at = (t) => {
|
|
|
912
912
|
}
|
|
913
913
|
}
|
|
914
914
|
}, or = (s) => {
|
|
915
|
-
const
|
|
915
|
+
const m = s.match(
|
|
916
916
|
/top five relevant product or category names are: (.*)/i
|
|
917
|
-
), p = (
|
|
917
|
+
), p = (m ? m[1] : s).split(", ").map((z) => z.replace(/\s*(Toys|Bags|Miniature|etc\.*)\s*/gi, "").trim());
|
|
918
918
|
return [...new Set(p)].filter(Boolean).join(",");
|
|
919
919
|
}, nr = async (s) => {
|
|
920
920
|
if (typeof s == "string") {
|
|
921
921
|
console.log(s, "keywords");
|
|
922
|
-
const
|
|
923
|
-
for (const h of
|
|
922
|
+
const m = s.split(",");
|
|
923
|
+
for (const h of m) {
|
|
924
924
|
const g = await ye(h);
|
|
925
|
-
if (
|
|
925
|
+
if (et(!1), (g == null ? void 0 : g.length) > 0 && (b(
|
|
926
926
|
(p) => p.map(
|
|
927
|
-
(
|
|
928
|
-
...
|
|
927
|
+
(w, z) => z === p.length - 1 ? {
|
|
928
|
+
...w,
|
|
929
929
|
products: [
|
|
930
|
-
...
|
|
930
|
+
...w.products || [],
|
|
931
931
|
{ keyword: h, items: g, loading: !1 }
|
|
932
932
|
]
|
|
933
|
-
} :
|
|
933
|
+
} : w
|
|
934
934
|
)
|
|
935
935
|
), !c.current || l.current == null)) {
|
|
936
936
|
const p = g[0];
|
|
937
937
|
c.current = String((p == null ? void 0 : p.product_name) ?? ""), d.current = p.image.link, l.current = p.product_id;
|
|
938
|
-
const
|
|
939
|
-
i.current = typeof
|
|
938
|
+
const w = typeof (p == null ? void 0 : p.price) == "number" ? p.price : void 0;
|
|
939
|
+
i.current = typeof w == "number" && Number.isFinite(w) ? w : null;
|
|
940
940
|
}
|
|
941
941
|
}
|
|
942
942
|
} else
|
|
943
|
-
for (const
|
|
944
|
-
const h = await ye(
|
|
945
|
-
|
|
943
|
+
for (const m of s) {
|
|
944
|
+
const h = await ye(m);
|
|
945
|
+
et(!1), (h == null ? void 0 : h.length) > 0 && b(
|
|
946
946
|
(g) => g.map(
|
|
947
|
-
(p,
|
|
947
|
+
(p, w) => w === g.length - 1 ? {
|
|
948
948
|
...p,
|
|
949
949
|
products: [
|
|
950
950
|
...p.products || [],
|
|
951
|
-
{ keyword:
|
|
951
|
+
{ keyword: m, items: h, loading: !1 }
|
|
952
952
|
]
|
|
953
953
|
} : p
|
|
954
954
|
)
|
|
@@ -970,18 +970,18 @@ const at = (t) => {
|
|
|
970
970
|
} : g
|
|
971
971
|
)
|
|
972
972
|
);
|
|
973
|
-
const
|
|
973
|
+
const m = JSON.parse(
|
|
974
974
|
sessionStorage.getItem("customerData") || "{}"
|
|
975
975
|
);
|
|
976
|
-
(
|
|
976
|
+
(m == null ? void 0 : m.isGuest) == !1 ? (console.log("running secondary flow", Et), W(c.current, 0)) : console.log("not running secondary flow", Et);
|
|
977
977
|
}
|
|
978
|
-
|
|
979
|
-
}, ar = async (s,
|
|
980
|
-
var h, g, p,
|
|
978
|
+
et(!1);
|
|
979
|
+
}, ar = async (s, m) => {
|
|
980
|
+
var h, g, p, w, z, ft, ht, j, mt, wt, D, L, H, R, G;
|
|
981
981
|
q(!0);
|
|
982
982
|
try {
|
|
983
983
|
const f = await Ve(s.id);
|
|
984
|
-
if (!((g = (h = f == null ? void 0 : f.variants) == null ? void 0 : h[0]) != null && g.product_id || (
|
|
984
|
+
if (!((g = (h = f == null ? void 0 : f.variants) == null ? void 0 : h[0]) != null && g.product_id || (w = (p = f == null ? void 0 : f.variants) == null ? void 0 : p[0]) != null && w.productId) && !(f.type.item || f.type.bundle)) {
|
|
985
985
|
q(!1), U.error("Variants not found", {
|
|
986
986
|
position: "bottom-right",
|
|
987
987
|
autoClose: 1e3
|
|
@@ -991,14 +991,14 @@ const at = (t) => {
|
|
|
991
991
|
const V = [
|
|
992
992
|
{
|
|
993
993
|
product_id: ((z = f.variants) == null ? void 0 : z[0].product_id) || ((ft = f.variants) == null ? void 0 : ft[0].productId) || (f == null ? void 0 : f.id),
|
|
994
|
-
quantity:
|
|
994
|
+
quantity: m
|
|
995
995
|
}
|
|
996
996
|
];
|
|
997
997
|
console.log(V, "product data", "app version", Et);
|
|
998
998
|
const I = JSON.parse(
|
|
999
999
|
sessionStorage.getItem("customerData") || "{}"
|
|
1000
|
-
), P = (I == null ? void 0 : I.basketId) || localStorage.getItem(Yt),
|
|
1001
|
-
if (!
|
|
1000
|
+
), P = (I == null ? void 0 : I.basketId) || localStorage.getItem(Yt), X = !1, Bt = localStorage.getItem(Ot), ge = Date.now();
|
|
1001
|
+
if (!X || !Bt || ge >= parseInt(Bt)) {
|
|
1002
1002
|
const ir = await He();
|
|
1003
1003
|
let { customer_token: gt } = await Re(
|
|
1004
1004
|
ir
|
|
@@ -1053,7 +1053,7 @@ const at = (t) => {
|
|
|
1053
1053
|
const bt = await r(
|
|
1054
1054
|
{
|
|
1055
1055
|
productId: l,
|
|
1056
|
-
quantity:
|
|
1056
|
+
quantity: m
|
|
1057
1057
|
},
|
|
1058
1058
|
(x == null ? void 0 : x.basket_id) || (x == null ? void 0 : x.basketId)
|
|
1059
1059
|
);
|
|
@@ -1071,7 +1071,7 @@ const at = (t) => {
|
|
|
1071
1071
|
position: "bottom-right",
|
|
1072
1072
|
autoClose: 3e3
|
|
1073
1073
|
}), ((L = f == null ? void 0 : f.response) == null ? void 0 : L.status) === 404 || // Basket not found
|
|
1074
|
-
((H = f == null ? void 0 : f.response) == null ? void 0 : H.status) === 401 ? (((R = f == null ? void 0 : f.response) == null ? void 0 : R.status) === 404 && at(null), ((
|
|
1074
|
+
((H = f == null ? void 0 : f.response) == null ? void 0 : H.status) === 401 ? (((R = f == null ? void 0 : f.response) == null ? void 0 : R.status) === 404 && at(null), ((G = f == null ? void 0 : f.response) == null ? void 0 : G.status) === 401 && (at(null), Kt(null))) : (console.error("Failed to add product to basket:", f.message), U.error("Failed to add product to cart", {
|
|
1075
1075
|
position: "bottom-right",
|
|
1076
1076
|
autoClose: 3e3
|
|
1077
1077
|
}));
|
|
@@ -1144,7 +1144,7 @@ const at = (t) => {
|
|
|
1144
1144
|
) })
|
|
1145
1145
|
}
|
|
1146
1146
|
),
|
|
1147
|
-
|
|
1147
|
+
tt && /* @__PURE__ */ u(oe, { children: [
|
|
1148
1148
|
/* @__PURE__ */ a(
|
|
1149
1149
|
"div",
|
|
1150
1150
|
{
|
|
@@ -1322,10 +1322,17 @@ const at = (t) => {
|
|
|
1322
1322
|
]
|
|
1323
1323
|
}
|
|
1324
1324
|
),
|
|
1325
|
-
|
|
1325
|
+
K.map((s, m) => {
|
|
1326
1326
|
var h, g;
|
|
1327
1327
|
return /* @__PURE__ */ u("div", { children: [
|
|
1328
|
-
/* @__PURE__ */ a(
|
|
1328
|
+
/* @__PURE__ */ a(
|
|
1329
|
+
"div",
|
|
1330
|
+
{
|
|
1331
|
+
className: "flex justify-end",
|
|
1332
|
+
ref: m == K.length - 1 ? C : null,
|
|
1333
|
+
children: /* @__PURE__ */ a("p", { className: "text-sm font-nunitoSans font-bold text-[#000000] bg-[#E2DBFF] border border-[#C9C2DE] rounded-l-xl p-2 m-3 mb-4 rounded-br-xl max-w-[75%]", children: s.query })
|
|
1334
|
+
}
|
|
1335
|
+
),
|
|
1329
1336
|
s.response && s.response.includes("Thinking") ? /* @__PURE__ */ a("div", { children: /* @__PURE__ */ a(
|
|
1330
1337
|
"div",
|
|
1331
1338
|
{
|
|
@@ -1360,7 +1367,7 @@ const at = (t) => {
|
|
|
1360
1367
|
children: "Why not explore these inquiries..."
|
|
1361
1368
|
}
|
|
1362
1369
|
),
|
|
1363
|
-
s.potentialQuestions.split(",").map((p,
|
|
1370
|
+
s.potentialQuestions.split(",").map((p, w) => /* @__PURE__ */ a(
|
|
1364
1371
|
"button",
|
|
1365
1372
|
{
|
|
1366
1373
|
className: `cursor-pointer font-nunitoSans font-semibold text-[#232323] border bg-[#804C9E0D] border-${k.themeDarkColor} m-1 rounded-xl px-2 py-1`,
|
|
@@ -1370,7 +1377,7 @@ const at = (t) => {
|
|
|
1370
1377
|
},
|
|
1371
1378
|
children: p
|
|
1372
1379
|
},
|
|
1373
|
-
|
|
1380
|
+
w
|
|
1374
1381
|
))
|
|
1375
1382
|
] }),
|
|
1376
1383
|
s.secondaryLoading && /* @__PURE__ */ a("div", { className: "mt-3 mb-4 px-4", children: /* @__PURE__ */ u(
|
|
@@ -1476,16 +1483,16 @@ const at = (t) => {
|
|
|
1476
1483
|
className: "px-3 py-1 text-sm",
|
|
1477
1484
|
onClick: () => b(
|
|
1478
1485
|
(p) => p.map(
|
|
1479
|
-
(
|
|
1480
|
-
...
|
|
1486
|
+
(w, z) => z === m && w.productSnapshot ? {
|
|
1487
|
+
...w,
|
|
1481
1488
|
productSnapshot: {
|
|
1482
|
-
...
|
|
1489
|
+
...w.productSnapshot,
|
|
1483
1490
|
quantity: Math.max(
|
|
1484
1491
|
1,
|
|
1485
|
-
|
|
1492
|
+
w.productSnapshot.quantity - 1
|
|
1486
1493
|
)
|
|
1487
1494
|
}
|
|
1488
|
-
} :
|
|
1495
|
+
} : w
|
|
1489
1496
|
)
|
|
1490
1497
|
),
|
|
1491
1498
|
style: {
|
|
@@ -1502,13 +1509,13 @@ const at = (t) => {
|
|
|
1502
1509
|
className: "px-3 py-1 text-sm",
|
|
1503
1510
|
onClick: () => b(
|
|
1504
1511
|
(p) => p.map(
|
|
1505
|
-
(
|
|
1506
|
-
...
|
|
1512
|
+
(w, z) => z === m && w.productSnapshot ? {
|
|
1513
|
+
...w,
|
|
1507
1514
|
productSnapshot: {
|
|
1508
|
-
...
|
|
1509
|
-
quantity:
|
|
1515
|
+
...w.productSnapshot,
|
|
1516
|
+
quantity: w.productSnapshot.quantity + 1
|
|
1510
1517
|
}
|
|
1511
|
-
} :
|
|
1518
|
+
} : w
|
|
1512
1519
|
)
|
|
1513
1520
|
),
|
|
1514
1521
|
style: {
|
|
@@ -1546,8 +1553,8 @@ const at = (t) => {
|
|
|
1546
1553
|
}
|
|
1547
1554
|
) })
|
|
1548
1555
|
] }) }),
|
|
1549
|
-
/* @__PURE__ */ a("div", { className: "mb-20"
|
|
1550
|
-
] },
|
|
1556
|
+
/* @__PURE__ */ a("div", { className: "mb-20" })
|
|
1557
|
+
] }, m);
|
|
1551
1558
|
})
|
|
1552
1559
|
]
|
|
1553
1560
|
}
|
|
@@ -1638,14 +1645,14 @@ function $r(t, e) {
|
|
|
1638
1645
|
}
|
|
1639
1646
|
t.prototype = e === null ? Object.create(e) : (r.prototype = e.prototype, new r());
|
|
1640
1647
|
}
|
|
1641
|
-
var
|
|
1642
|
-
return
|
|
1648
|
+
var Q = function() {
|
|
1649
|
+
return Q = Object.assign || function(e) {
|
|
1643
1650
|
for (var r, o = 1, n = arguments.length; o < n; o++) {
|
|
1644
1651
|
r = arguments[o];
|
|
1645
1652
|
for (var c in r) Object.prototype.hasOwnProperty.call(r, c) && (e[c] = r[c]);
|
|
1646
1653
|
}
|
|
1647
1654
|
return e;
|
|
1648
|
-
},
|
|
1655
|
+
}, Q.apply(this, arguments);
|
|
1649
1656
|
};
|
|
1650
1657
|
function zr(t, e) {
|
|
1651
1658
|
var r = {};
|
|
@@ -2326,10 +2333,10 @@ function Xr(t) {
|
|
|
2326
2333
|
return t;
|
|
2327
2334
|
}
|
|
2328
2335
|
function Qr(t, e) {
|
|
2329
|
-
var r =
|
|
2330
|
-
typeof c == "function" ? r =
|
|
2336
|
+
var r = Q({}, t), o = function(c) {
|
|
2337
|
+
typeof c == "function" ? r = Q(Q({}, r), c(r)) : r = Q(Q({}, r), c);
|
|
2331
2338
|
}, n = function() {
|
|
2332
|
-
return
|
|
2339
|
+
return Q({}, r);
|
|
2333
2340
|
};
|
|
2334
2341
|
return Object.defineProperty(e, "setContext", {
|
|
2335
2342
|
enumerable: !1,
|