tanya-chatbot 0.3.7 → 0.3.9
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=${Z()}&siteId=${
|
|
104
|
+
`${t}api/auth/token-bm-grant?baseUrl=${Z()}&siteId=${R()}`
|
|
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=${Z()}&siteId=${
|
|
114
|
+
`${e}api/auth/token-existing-guest-customer?dwsid=${r}&baseUrl=${Z()}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
115
115
|
{},
|
|
116
116
|
{
|
|
117
117
|
headers: {
|
|
@@ -127,13 +127,10 @@ const st = () => ({ aiConversationUrl: "https://mdv3qwfi2j.execute-api.us-east-1
|
|
|
127
127
|
};
|
|
128
128
|
async function Ot() {
|
|
129
129
|
var i;
|
|
130
|
-
const
|
|
130
|
+
const t = "access_token", e = "expires_in", r = localStorage.getItem(e), o = localStorage.getItem(t);
|
|
131
131
|
console.log(o);
|
|
132
132
|
const n = ((i = JSON.parse(sessionStorage.getItem("customerData") || "{}")) == null ? void 0 : i.isGuest) || !0;
|
|
133
|
-
if (
|
|
134
|
-
// expires_in &&
|
|
135
|
-
o
|
|
136
|
-
)
|
|
133
|
+
if (r && o && (/* @__PURE__ */ new Date()).getTime() < parseInt(r))
|
|
137
134
|
return console.log("access token found in local storage"), { access_token: o, expires_in: r };
|
|
138
135
|
const { serverUrl: l } = st(), s = JSON.parse(
|
|
139
136
|
sessionStorage.getItem("customerData") || "{}"
|
|
@@ -142,20 +139,20 @@ async function Ot() {
|
|
|
142
139
|
).usrRef;
|
|
143
140
|
try {
|
|
144
141
|
const g = n ? "unregister-auth" : "register-auth", w = await E.get(
|
|
145
|
-
`${l}sc-api/${g}?dwsid=${s}&email=${d}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}&siteId=${
|
|
142
|
+
`${l}sc-api/${g}?dwsid=${s}&email=${d}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}&siteId=${R()}&token=true`,
|
|
146
143
|
{
|
|
147
144
|
withCredentials: !0
|
|
148
145
|
}
|
|
149
146
|
);
|
|
150
|
-
return localStorage.setItem(
|
|
151
|
-
|
|
147
|
+
return localStorage.setItem(t, w.data.access_token), localStorage.setItem(
|
|
148
|
+
e,
|
|
152
149
|
String((/* @__PURE__ */ new Date()).getTime() + w.data.expires_in * 1e3)
|
|
153
150
|
), localStorage.setItem("isGuest", n ? "true" : "false"), w.data;
|
|
154
151
|
} catch (g) {
|
|
155
152
|
console.log(g);
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
const Z = () => sessionStorage.getItem("Host"),
|
|
155
|
+
const Z = () => sessionStorage.getItem("Host"), R = () => sessionStorage.getItem("SiteId"), tt = () => sessionStorage.getItem("pubCfg"), et = () => sessionStorage.getItem("envRef"), rt = () => sessionStorage.getItem("orgRef"), be = async (t) => {
|
|
159
156
|
console.log("fetching results");
|
|
160
157
|
const { serverUrl: e, basePath: r } = st();
|
|
161
158
|
let o = "";
|
|
@@ -166,7 +163,7 @@ const Z = () => sessionStorage.getItem("Host"), q = () => sessionStorage.getItem
|
|
|
166
163
|
try {
|
|
167
164
|
const n = Z();
|
|
168
165
|
return (await E.get(
|
|
169
|
-
`${e}${r}/search-sfcc?baseUrl=${n}&query=${t}&siteId=${
|
|
166
|
+
`${e}${r}/search-sfcc?baseUrl=${n}&query=${t}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
170
167
|
{
|
|
171
168
|
headers: {
|
|
172
169
|
"Content-Type": "application/json",
|
|
@@ -183,7 +180,7 @@ const Z = () => sessionStorage.getItem("Host"), q = () => sessionStorage.getItem
|
|
|
183
180
|
console.log("calling access");
|
|
184
181
|
const { access_token: n } = await Ot();
|
|
185
182
|
return console.log(n), (await E.get(
|
|
186
|
-
`${e}${r}/product-sfcc/${t}?baseUrl=${o}&siteId=${
|
|
183
|
+
`${e}${r}/product-sfcc/${t}?baseUrl=${o}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
187
184
|
{
|
|
188
185
|
headers: {
|
|
189
186
|
"Content-Type": "application/json",
|
|
@@ -197,7 +194,7 @@ const Z = () => sessionStorage.getItem("Host"), q = () => sessionStorage.getItem
|
|
|
197
194
|
e
|
|
198
195
|
), { serverUrl: o, basePath: n } = st(), s = (await Ot()).access_token;
|
|
199
196
|
return (await E.get(
|
|
200
|
-
`${o}${n}/get-interest?baseUrl=${Z()}&customerId=${t}&siteId=${
|
|
197
|
+
`${o}${n}/get-interest?baseUrl=${Z()}&customerId=${t}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
201
198
|
{
|
|
202
199
|
headers: {
|
|
203
200
|
"Content-Type": "application/json",
|
|
@@ -368,7 +365,7 @@ const _r = ({
|
|
|
368
365
|
`, t);
|
|
369
366
|
try {
|
|
370
367
|
return (await E.post(
|
|
371
|
-
`${n}${o}/basket/create?baseUrl=${Z()}&siteId=${
|
|
368
|
+
`${n}${o}/basket/create?baseUrl=${Z()}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
372
369
|
e,
|
|
373
370
|
{
|
|
374
371
|
headers: {
|
|
@@ -384,7 +381,7 @@ const _r = ({
|
|
|
384
381
|
const { serverUrl: o, basePath: n } = st(), l = `${o}`;
|
|
385
382
|
try {
|
|
386
383
|
const s = await E.post(
|
|
387
|
-
`${l}${n}/basket/add-product/${t}?baseUrl=${Z()}&siteId=${
|
|
384
|
+
`${l}${n}/basket/add-product/${t}?baseUrl=${Z()}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
388
385
|
e,
|
|
389
386
|
{
|
|
390
387
|
headers: {
|
|
@@ -408,7 +405,7 @@ const _r = ({
|
|
|
408
405
|
const { serverUrl: r, basePath: o } = st(), n = `${r}`;
|
|
409
406
|
try {
|
|
410
407
|
const s = await E.get(
|
|
411
|
-
`${n}${o}/basket/${t}?baseUrl=${Z()}&siteId=${
|
|
408
|
+
`${n}${o}/basket/${t}?baseUrl=${Z()}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
412
409
|
{
|
|
413
410
|
headers: {
|
|
414
411
|
"Content-Type": "application/json",
|
|
@@ -445,10 +442,10 @@ const xt = (t) => {
|
|
|
445
442
|
n(!!e);
|
|
446
443
|
}, [e]), !e) return null;
|
|
447
444
|
const l = async () => {
|
|
448
|
-
var _, j,
|
|
445
|
+
var _, j, q, M, lt, vt, Pt, ot, kt, St, ct, $t, zt, Ct, O, dt;
|
|
449
446
|
console.log(e, "the prod");
|
|
450
447
|
try {
|
|
451
|
-
if (!((j = (_ = e == null ? void 0 : e.variants) == null ? void 0 : _[0]) != null && j.product_id) && !(e.type.item || e.type.bundle) && !((
|
|
448
|
+
if (!((j = (_ = e == null ? void 0 : e.variants) == null ? void 0 : _[0]) != null && j.product_id) && !(e.type.item || e.type.bundle) && !((M = (q = e == null ? void 0 : e.variants) == null ? void 0 : q[0]) != null && M.productId)) {
|
|
452
449
|
U.error("Variants not available", {
|
|
453
450
|
position: "bottom-right",
|
|
454
451
|
autoClose: 1e3
|
|
@@ -652,7 +649,7 @@ const xt = (t) => {
|
|
|
652
649
|
] })
|
|
653
650
|
] }) }),
|
|
654
651
|
/* @__PURE__ */ a("div", { className: "mt-2 flex flex-row items-center gap-2", children: Array.from({ length: 5 }).map((_, j) => {
|
|
655
|
-
var
|
|
652
|
+
var q;
|
|
656
653
|
return /* @__PURE__ */ a(
|
|
657
654
|
ge,
|
|
658
655
|
{
|
|
@@ -660,7 +657,7 @@ const xt = (t) => {
|
|
|
660
657
|
width: "20",
|
|
661
658
|
height: "20",
|
|
662
659
|
className: `text-yellow-500
|
|
663
|
-
${((
|
|
660
|
+
${((q = e == null ? void 0 : e.rating) == null ? void 0 : q.rate) > j ? "text-yellow-500" : "text-gray-300"}
|
|
664
661
|
`
|
|
665
662
|
},
|
|
666
663
|
j
|
|
@@ -715,7 +712,7 @@ const xt = (t) => {
|
|
|
715
712
|
"Niece/Nephew": "his/her niece/nephew",
|
|
716
713
|
"My Friends": "his/her friends",
|
|
717
714
|
Others: "others"
|
|
718
|
-
}, o = It(null), n = It(null), l = It(null), s = It(null), [d, i] = P(null), [g, w] = P(!1), [C, S] = P(!1), [_, j] = P(!1), [
|
|
715
|
+
}, o = It(null), n = It(null), l = It(null), s = It(null), [d, i] = P(null), [g, w] = P(!1), [C, S] = P(!1), [_, j] = P(!1), [q, M] = P(!1), [lt, vt] = P(!1), [Pt, ot] = P(!1), [kt, St] = P(""), [ct, $t] = P(""), zt = (c) => ({
|
|
719
716
|
id: c.id,
|
|
720
717
|
title: c.name,
|
|
721
718
|
image: c.image ?? "",
|
|
@@ -785,7 +782,7 @@ const xt = (t) => {
|
|
|
785
782
|
try {
|
|
786
783
|
O(
|
|
787
784
|
(L) => L.map(
|
|
788
|
-
(
|
|
785
|
+
(H, V) => V === L.length - 1 ? { ...H, secondaryLoading: !0 } : H
|
|
789
786
|
)
|
|
790
787
|
);
|
|
791
788
|
const y = await At();
|
|
@@ -815,13 +812,13 @@ const xt = (t) => {
|
|
|
815
812
|
const ft = A.body.getReader(), mt = new TextDecoder();
|
|
816
813
|
let D = "";
|
|
817
814
|
for (; ; ) {
|
|
818
|
-
const { done: L, value:
|
|
815
|
+
const { done: L, value: H } = await ft.read();
|
|
819
816
|
if (L) break;
|
|
820
|
-
D += mt.decode(
|
|
821
|
-
const
|
|
817
|
+
D += mt.decode(H, { stream: !0 });
|
|
818
|
+
const V = D.split(`
|
|
822
819
|
`);
|
|
823
|
-
D =
|
|
824
|
-
for (const G of
|
|
820
|
+
D = V.pop() || "";
|
|
821
|
+
for (const G of V)
|
|
825
822
|
if (G.startsWith("data:")) {
|
|
826
823
|
const m = G.slice(5).trim();
|
|
827
824
|
try {
|
|
@@ -890,9 +887,9 @@ const xt = (t) => {
|
|
|
890
887
|
let D = "", L = "";
|
|
891
888
|
for (; ; ) {
|
|
892
889
|
ot(!0);
|
|
893
|
-
const { done:
|
|
894
|
-
if (
|
|
895
|
-
D += mt.decode(
|
|
890
|
+
const { done: H, value: V } = await ft.read();
|
|
891
|
+
if (H) break;
|
|
892
|
+
D += mt.decode(V, { stream: !0 });
|
|
896
893
|
const G = D.split(`
|
|
897
894
|
`);
|
|
898
895
|
D = G.pop() || "";
|
|
@@ -987,12 +984,12 @@ const xt = (t) => {
|
|
|
987
984
|
}
|
|
988
985
|
ot(!1);
|
|
989
986
|
}, rr = async (c, k) => {
|
|
990
|
-
var b, y, f, x, z, ut, pt, A, ft, mt, D, L,
|
|
991
|
-
|
|
987
|
+
var b, y, f, x, z, ut, pt, A, ft, mt, D, L, H, V, G;
|
|
988
|
+
M(!0);
|
|
992
989
|
try {
|
|
993
990
|
const m = await He(c.id);
|
|
994
991
|
if (!((y = (b = m == null ? void 0 : m.variants) == null ? void 0 : b[0]) != null && y.product_id || (x = (f = m == null ? void 0 : m.variants) == null ? void 0 : f[0]) != null && x.productId) && !(m.type.item || m.type.bundle)) {
|
|
995
|
-
|
|
992
|
+
M(!1), U.error("Variants not found", {
|
|
996
993
|
position: "bottom-right",
|
|
997
994
|
autoClose: 1e3
|
|
998
995
|
}), console.error("No product variant found");
|
|
@@ -1036,7 +1033,7 @@ const xt = (t) => {
|
|
|
1036
1033
|
closeOnClick: !0,
|
|
1037
1034
|
pauseOnHover: !0,
|
|
1038
1035
|
draggable: !0
|
|
1039
|
-
}), Ht(T),
|
|
1036
|
+
}), Ht(T), M(!1));
|
|
1040
1037
|
return;
|
|
1041
1038
|
}
|
|
1042
1039
|
}
|
|
@@ -1054,7 +1051,7 @@ const xt = (t) => {
|
|
|
1054
1051
|
v == null ? void 0 : v.basketId,
|
|
1055
1052
|
"the basket response"
|
|
1056
1053
|
), !(v != null && v.basket_id || !(v != null && v.basketId))) {
|
|
1057
|
-
|
|
1054
|
+
M(!1), console.error("Failed to create basket");
|
|
1058
1055
|
return;
|
|
1059
1056
|
}
|
|
1060
1057
|
xt(
|
|
@@ -1075,16 +1072,16 @@ const xt = (t) => {
|
|
|
1075
1072
|
}), Ht(v.basket_id || (v == null ? void 0 : v.basketId));
|
|
1076
1073
|
}
|
|
1077
1074
|
} catch (m) {
|
|
1078
|
-
|
|
1075
|
+
M(!1), console.error("Error adding to cart:", m), U.error("Failed to add product to cart", {
|
|
1079
1076
|
position: "bottom-right",
|
|
1080
1077
|
autoClose: 3e3
|
|
1081
1078
|
}), ((L = m == null ? void 0 : m.response) == null ? void 0 : L.status) === 404 || // Basket not found
|
|
1082
|
-
((
|
|
1079
|
+
((H = m == null ? void 0 : m.response) == null ? void 0 : H.status) === 401 ? (((V = m == null ? void 0 : m.response) == null ? void 0 : V.status) === 404 && xt(null), ((G = m == null ? void 0 : m.response) == null ? void 0 : G.status) === 401 && (xt(null), Yt(null))) : (console.error("Failed to add product to basket:", m.message), U.error("Failed to add product to cart", {
|
|
1083
1080
|
position: "bottom-right",
|
|
1084
1081
|
autoClose: 3e3
|
|
1085
1082
|
}));
|
|
1086
1083
|
}
|
|
1087
|
-
|
|
1084
|
+
M(!1);
|
|
1088
1085
|
};
|
|
1089
1086
|
return /* @__PURE__ */ a("div", { className: "relative flex justify-center", children: /* @__PURE__ */ u(xr, { open: g, onOpenChange: w, children: [
|
|
1090
1087
|
/* @__PURE__ */ a(
|
|
@@ -1536,14 +1533,14 @@ const xt = (t) => {
|
|
|
1536
1533
|
c.productSnapshot.quantity
|
|
1537
1534
|
);
|
|
1538
1535
|
},
|
|
1539
|
-
disabled:
|
|
1536
|
+
disabled: q,
|
|
1540
1537
|
className: "px-4 py-2 rounded-full font-medium",
|
|
1541
1538
|
style: {
|
|
1542
1539
|
background: p.tanyaThemeColor,
|
|
1543
1540
|
color: (p == null ? void 0 : p.tanyaThemeContrastColor) || "#fff",
|
|
1544
|
-
opacity:
|
|
1541
|
+
opacity: q ? 0.8 : 1
|
|
1545
1542
|
},
|
|
1546
|
-
children:
|
|
1543
|
+
children: q ? "Adding..." : "Add to cart"
|
|
1547
1544
|
}
|
|
1548
1545
|
)
|
|
1549
1546
|
] })
|