tanya-chatbot 0.3.4 → 0.3.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=${Z()}&siteId=${
|
|
104
|
+
`${t}api/auth/token-bm-grant?baseUrl=${Z()}&siteId=${V()}`
|
|
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=${V()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
115
115
|
{},
|
|
116
116
|
{
|
|
117
117
|
headers: {
|
|
@@ -137,7 +137,7 @@ async function Ot() {
|
|
|
137
137
|
).usrRef;
|
|
138
138
|
try {
|
|
139
139
|
const d = r ? "unregister-auth" : "register-auth", i = await E.get(
|
|
140
|
-
`${o}sc-api/${d}?dwsid=${n}&email=${l}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}&siteId=${
|
|
140
|
+
`${o}sc-api/${d}?dwsid=${n}&email=${l}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}&siteId=${V()}&token=true`,
|
|
141
141
|
{
|
|
142
142
|
withCredentials: !0
|
|
143
143
|
}
|
|
@@ -150,7 +150,7 @@ async function Ot() {
|
|
|
150
150
|
console.log(d);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
const Z = () => sessionStorage.getItem("Host"),
|
|
153
|
+
const Z = () => sessionStorage.getItem("Host"), V = () => sessionStorage.getItem("SiteId"), tt = () => sessionStorage.getItem("pubCfg"), et = () => sessionStorage.getItem("envRef"), rt = () => sessionStorage.getItem("orgRef"), be = async (t) => {
|
|
154
154
|
console.log("fetching results");
|
|
155
155
|
const { serverUrl: e, basePath: r } = st();
|
|
156
156
|
let o = "";
|
|
@@ -161,7 +161,7 @@ const Z = () => sessionStorage.getItem("Host"), R = () => sessionStorage.getItem
|
|
|
161
161
|
try {
|
|
162
162
|
const n = Z();
|
|
163
163
|
return (await E.get(
|
|
164
|
-
`${e}${r}/search-sfcc?baseUrl=${n}&query=${t}&siteId=${
|
|
164
|
+
`${e}${r}/search-sfcc?baseUrl=${n}&query=${t}&siteId=${V()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
165
165
|
{
|
|
166
166
|
headers: {
|
|
167
167
|
"Content-Type": "application/json",
|
|
@@ -178,7 +178,7 @@ const Z = () => sessionStorage.getItem("Host"), R = () => sessionStorage.getItem
|
|
|
178
178
|
console.log("calling access");
|
|
179
179
|
const { access_token: n } = await Ot();
|
|
180
180
|
return console.log(n), (await E.get(
|
|
181
|
-
`${e}${r}/product-sfcc/${t}?baseUrl=${o}&siteId=${
|
|
181
|
+
`${e}${r}/product-sfcc/${t}?baseUrl=${o}&siteId=${V()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
182
182
|
{
|
|
183
183
|
headers: {
|
|
184
184
|
"Content-Type": "application/json",
|
|
@@ -192,7 +192,7 @@ const Z = () => sessionStorage.getItem("Host"), R = () => sessionStorage.getItem
|
|
|
192
192
|
e
|
|
193
193
|
), { serverUrl: o, basePath: n } = st(), s = (await Ot()).access_token;
|
|
194
194
|
return (await E.get(
|
|
195
|
-
`${o}${n}/get-interest?baseUrl=${Z()}&customerId=${t}&siteId=${
|
|
195
|
+
`${o}${n}/get-interest?baseUrl=${Z()}&customerId=${t}&siteId=${V()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
196
196
|
{
|
|
197
197
|
headers: {
|
|
198
198
|
"Content-Type": "application/json",
|
|
@@ -246,7 +246,9 @@ const _r = ({
|
|
|
246
246
|
className: "absolute z-50 left-0 text-[#000000] bg-[#ffffff] rounded-full p-2 flex items-center h-fit",
|
|
247
247
|
style: {
|
|
248
248
|
height: "30px",
|
|
249
|
-
width: "30px"
|
|
249
|
+
width: "30px",
|
|
250
|
+
boxShadow: "0 4px 10px rgba(0, 0, 0, 0.25)",
|
|
251
|
+
borderRadius: "8px"
|
|
250
252
|
},
|
|
251
253
|
children: "<"
|
|
252
254
|
}
|
|
@@ -323,7 +325,9 @@ const _r = ({
|
|
|
323
325
|
className: "absolute z-50 right-0 text-[#000000] bg-[#ffffff] rounded-full p-2 flex items-center h-fit",
|
|
324
326
|
style: {
|
|
325
327
|
height: "30px",
|
|
326
|
-
width: "30px"
|
|
328
|
+
width: "30px",
|
|
329
|
+
boxShadow: "0 4px 10px rgba(0, 0, 0, 0.25)",
|
|
330
|
+
borderRadius: "8px"
|
|
327
331
|
},
|
|
328
332
|
children: ">"
|
|
329
333
|
}
|
|
@@ -355,13 +359,13 @@ const _r = ({
|
|
|
355
359
|
]
|
|
356
360
|
},
|
|
357
361
|
o
|
|
358
|
-
)) }),
|
|
362
|
+
)) }), Re = async (t, e) => {
|
|
359
363
|
const { serverUrl: r, basePath: o } = st(), n = `${r}`;
|
|
360
364
|
console.log(`customer_token
|
|
361
365
|
`, t);
|
|
362
366
|
try {
|
|
363
367
|
return (await E.post(
|
|
364
|
-
`${n}${o}/basket/create?baseUrl=${Z()}&siteId=${
|
|
368
|
+
`${n}${o}/basket/create?baseUrl=${Z()}&siteId=${V()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
365
369
|
e,
|
|
366
370
|
{
|
|
367
371
|
headers: {
|
|
@@ -373,11 +377,11 @@ const _r = ({
|
|
|
373
377
|
} catch (l) {
|
|
374
378
|
return E.isAxiosError(l) ? console.error("Error creating basket:", l.response || l.message) : console.error("Unexpected error:", l), null;
|
|
375
379
|
}
|
|
376
|
-
},
|
|
380
|
+
}, Rt = async (t, e, r) => {
|
|
377
381
|
const { serverUrl: o, basePath: n } = st(), l = `${o}`;
|
|
378
382
|
try {
|
|
379
383
|
const s = await E.post(
|
|
380
|
-
`${l}${n}/basket/add-product/${t}?baseUrl=${Z()}&siteId=${
|
|
384
|
+
`${l}${n}/basket/add-product/${t}?baseUrl=${Z()}&siteId=${V()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
381
385
|
e,
|
|
382
386
|
{
|
|
383
387
|
headers: {
|
|
@@ -393,7 +397,7 @@ const _r = ({
|
|
|
393
397
|
s.response || s.message
|
|
394
398
|
) : console.error("Unexpected error:", s), null;
|
|
395
399
|
}
|
|
396
|
-
},
|
|
400
|
+
}, Ve = async ({
|
|
397
401
|
basketId: t,
|
|
398
402
|
customer_token: e
|
|
399
403
|
}) => {
|
|
@@ -401,7 +405,7 @@ const _r = ({
|
|
|
401
405
|
const { serverUrl: r, basePath: o } = st(), n = `${r}`;
|
|
402
406
|
try {
|
|
403
407
|
const s = await E.get(
|
|
404
|
-
`${n}${o}/basket/${t}?baseUrl=${Z()}&siteId=${
|
|
408
|
+
`${n}${o}/basket/${t}?baseUrl=${Z()}&siteId=${V()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
405
409
|
{
|
|
406
410
|
headers: {
|
|
407
411
|
"Content-Type": "application/json",
|
|
@@ -413,10 +417,10 @@ const _r = ({
|
|
|
413
417
|
} catch (s) {
|
|
414
418
|
return E.isAxiosError(s) ? { status: (l = s.response) == null ? void 0 : l.status, data: null } : { status: null, data: null };
|
|
415
419
|
}
|
|
416
|
-
},
|
|
420
|
+
}, Vt = "sfcc_basket_id", Se = "sfcc_customer_token", Tt = "sfcc_token_expiry", Fr = 300 * 1e3, Ft = "1.0.0";
|
|
417
421
|
const xt = (t) => {
|
|
418
422
|
try {
|
|
419
|
-
t ? localStorage.setItem(
|
|
423
|
+
t ? localStorage.setItem(Vt, t) : localStorage.removeItem(Vt);
|
|
420
424
|
} catch (e) {
|
|
421
425
|
console.error("Error saving basket ID to storage:", e);
|
|
422
426
|
}
|
|
@@ -457,7 +461,7 @@ const xt = (t) => {
|
|
|
457
461
|
console.log(p, "the product data");
|
|
458
462
|
const _t = JSON.parse(
|
|
459
463
|
sessionStorage.getItem("customerData") || "{}"
|
|
460
|
-
), nt = (_t == null ? void 0 : _t.basketId) || localStorage.getItem(
|
|
464
|
+
), nt = (_t == null ? void 0 : _t.basketId) || localStorage.getItem(Vt), Kt = !1, jt = localStorage.getItem(Tt), Y = Date.now();
|
|
461
465
|
if (!Kt || !jt || Y >= parseInt(jt)) {
|
|
462
466
|
let $ = "";
|
|
463
467
|
{
|
|
@@ -470,12 +474,12 @@ const xt = (t) => {
|
|
|
470
474
|
}
|
|
471
475
|
const At = Y + 300 * 1e3;
|
|
472
476
|
if (Yt($), localStorage.setItem(Tt, At.toString()), nt) {
|
|
473
|
-
const K = await
|
|
477
|
+
const K = await Ve({
|
|
474
478
|
basketId: nt,
|
|
475
479
|
customer_token: $
|
|
476
480
|
});
|
|
477
481
|
if (console.log(nt, "basket id from customer"), K.status === 200 && K) {
|
|
478
|
-
const G = await
|
|
482
|
+
const G = await Rt(
|
|
479
483
|
nt,
|
|
480
484
|
p,
|
|
481
485
|
$
|
|
@@ -500,7 +504,7 @@ const xt = (t) => {
|
|
|
500
504
|
]
|
|
501
505
|
};
|
|
502
506
|
console.log("before create basket");
|
|
503
|
-
const h = await
|
|
507
|
+
const h = await Re($, Gt);
|
|
504
508
|
if (console.log(
|
|
505
509
|
h,
|
|
506
510
|
h == null ? void 0 : h.basket_id,
|
|
@@ -516,7 +520,7 @@ const xt = (t) => {
|
|
|
516
520
|
), xt(
|
|
517
521
|
(h == null ? void 0 : h.basket_id) || (h == null ? void 0 : h.basketId)
|
|
518
522
|
), console.log("adding product to basket");
|
|
519
|
-
const J = await
|
|
523
|
+
const J = await Rt(
|
|
520
524
|
(h == null ? void 0 : h.basket_id) || (h == null ? void 0 : h.basketId),
|
|
521
525
|
p,
|
|
522
526
|
$
|
|
@@ -778,7 +782,7 @@ const xt = (t) => {
|
|
|
778
782
|
try {
|
|
779
783
|
O(
|
|
780
784
|
(L) => L.map(
|
|
781
|
-
(H,
|
|
785
|
+
(H, R) => R === L.length - 1 ? { ...H, secondaryLoading: !0 } : H
|
|
782
786
|
)
|
|
783
787
|
);
|
|
784
788
|
const y = await At();
|
|
@@ -811,10 +815,10 @@ const xt = (t) => {
|
|
|
811
815
|
const { done: L, value: H } = await ft.read();
|
|
812
816
|
if (L) break;
|
|
813
817
|
D += mt.decode(H, { stream: !0 });
|
|
814
|
-
const
|
|
818
|
+
const R = D.split(`
|
|
815
819
|
`);
|
|
816
|
-
D =
|
|
817
|
-
for (const W of
|
|
820
|
+
D = R.pop() || "";
|
|
821
|
+
for (const W of R)
|
|
818
822
|
if (W.startsWith("data:")) {
|
|
819
823
|
const m = W.slice(5).trim();
|
|
820
824
|
try {
|
|
@@ -883,9 +887,9 @@ const xt = (t) => {
|
|
|
883
887
|
let D = "", L = "";
|
|
884
888
|
for (; ; ) {
|
|
885
889
|
ot(!0);
|
|
886
|
-
const { done: H, value:
|
|
890
|
+
const { done: H, value: R } = await ft.read();
|
|
887
891
|
if (H) break;
|
|
888
|
-
D += mt.decode(
|
|
892
|
+
D += mt.decode(R, { stream: !0 });
|
|
889
893
|
const W = D.split(`
|
|
890
894
|
`);
|
|
891
895
|
D = W.pop() || "";
|
|
@@ -980,7 +984,7 @@ const xt = (t) => {
|
|
|
980
984
|
}
|
|
981
985
|
ot(!1);
|
|
982
986
|
}, rr = async (c, k) => {
|
|
983
|
-
var w, y, f, g, z, ut, pt, A, ft, mt, D, L, H,
|
|
987
|
+
var w, y, f, g, z, ut, pt, A, ft, mt, D, L, H, R, W;
|
|
984
988
|
M(!0);
|
|
985
989
|
try {
|
|
986
990
|
const m = await He(c.id);
|
|
@@ -1000,7 +1004,7 @@ const xt = (t) => {
|
|
|
1000
1004
|
console.log(B, "product data", "app version", Ft);
|
|
1001
1005
|
const I = JSON.parse(
|
|
1002
1006
|
sessionStorage.getItem("customerData") || "{}"
|
|
1003
|
-
), T = (I == null ? void 0 : I.basketId) || localStorage.getItem(
|
|
1007
|
+
), T = (I == null ? void 0 : I.basketId) || localStorage.getItem(Vt), X = !1, Dt = localStorage.getItem(Tt), he = Date.now();
|
|
1004
1008
|
if (!X || !Dt || he >= parseInt(Dt)) {
|
|
1005
1009
|
const or = await qe();
|
|
1006
1010
|
let { customer_token: at } = await Me(
|
|
@@ -1012,12 +1016,12 @@ const xt = (t) => {
|
|
|
1012
1016
|
}
|
|
1013
1017
|
const nr = he + 300 * 1e3;
|
|
1014
1018
|
if (Yt(at), localStorage.setItem(Tt, nr.toString()), console.log(T, "basketIdFromCustomer"), T) {
|
|
1015
|
-
const we = await
|
|
1019
|
+
const we = await Ve({
|
|
1016
1020
|
basketId: T,
|
|
1017
1021
|
customer_token: at
|
|
1018
1022
|
});
|
|
1019
1023
|
if (we.status === 200 && we) {
|
|
1020
|
-
const Wt = await
|
|
1024
|
+
const Wt = await Rt(
|
|
1021
1025
|
T,
|
|
1022
1026
|
B,
|
|
1023
1027
|
at
|
|
@@ -1040,7 +1044,7 @@ const xt = (t) => {
|
|
|
1040
1044
|
quantity: 1
|
|
1041
1045
|
}
|
|
1042
1046
|
]
|
|
1043
|
-
}, v = await
|
|
1047
|
+
}, v = await Re(at, ar);
|
|
1044
1048
|
if (console.log(
|
|
1045
1049
|
v,
|
|
1046
1050
|
v == null ? void 0 : v.basket_id,
|
|
@@ -1053,7 +1057,7 @@ const xt = (t) => {
|
|
|
1053
1057
|
xt(
|
|
1054
1058
|
(v == null ? void 0 : v.basket_id) || (v == null ? void 0 : v.basketId)
|
|
1055
1059
|
);
|
|
1056
|
-
const ht = await
|
|
1060
|
+
const ht = await Rt(
|
|
1057
1061
|
(v == null ? void 0 : v.basket_id) || (v == null ? void 0 : v.basketId),
|
|
1058
1062
|
B,
|
|
1059
1063
|
at
|
|
@@ -1072,7 +1076,7 @@ const xt = (t) => {
|
|
|
1072
1076
|
position: "bottom-right",
|
|
1073
1077
|
autoClose: 3e3
|
|
1074
1078
|
}), ((L = m == null ? void 0 : m.response) == null ? void 0 : L.status) === 404 || // Basket not found
|
|
1075
|
-
((H = m == null ? void 0 : m.response) == null ? void 0 : H.status) === 401 ? (((
|
|
1079
|
+
((H = m == null ? void 0 : m.response) == null ? void 0 : H.status) === 401 ? (((R = m == null ? void 0 : m.response) == null ? void 0 : R.status) === 404 && xt(null), ((W = m == null ? void 0 : m.response) == null ? void 0 : W.status) === 401 && (xt(null), Yt(null))) : (console.error("Failed to add product to basket:", m.message), U.error("Failed to add product to cart", {
|
|
1076
1080
|
position: "bottom-right",
|
|
1077
1081
|
autoClose: 3e3
|
|
1078
1082
|
}));
|
|
@@ -1965,7 +1969,7 @@ function Qe(t) {
|
|
|
1965
1969
|
function se(t) {
|
|
1966
1970
|
t._observer = void 0, t._queue = void 0, t._state = "closed";
|
|
1967
1971
|
}
|
|
1968
|
-
function
|
|
1972
|
+
function Rr(t) {
|
|
1969
1973
|
var e = t._queue;
|
|
1970
1974
|
if (e) {
|
|
1971
1975
|
t._queue = void 0, t._state = "ready";
|
|
@@ -2009,14 +2013,14 @@ function ee(t, e, r) {
|
|
|
2009
2013
|
type: e,
|
|
2010
2014
|
value: r
|
|
2011
2015
|
}], qt(function() {
|
|
2012
|
-
return
|
|
2016
|
+
return Rr(t);
|
|
2013
2017
|
});
|
|
2014
2018
|
return;
|
|
2015
2019
|
}
|
|
2016
2020
|
Ze(t, e, r);
|
|
2017
2021
|
}
|
|
2018
2022
|
}
|
|
2019
|
-
var
|
|
2023
|
+
var Vr = /* @__PURE__ */ (function() {
|
|
2020
2024
|
function t(r, o) {
|
|
2021
2025
|
this._cleanup = void 0, this._observer = r, this._queue = void 0, this._state = "initializing";
|
|
2022
2026
|
var n = new Yr(this);
|
|
@@ -2065,7 +2069,7 @@ var Rr = /* @__PURE__ */ (function() {
|
|
|
2065
2069
|
next: o,
|
|
2066
2070
|
error: arguments[1],
|
|
2067
2071
|
complete: arguments[2]
|
|
2068
|
-
}), new
|
|
2072
|
+
}), new Vr(o, this._subscriber);
|
|
2069
2073
|
}, e.forEach = function(o) {
|
|
2070
2074
|
var n = this;
|
|
2071
2075
|
return new Promise(function(l, s) {
|