tanya-chatbot 0.3.5 → 0.3.6
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: {
|
|
@@ -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=${R()}&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"), R = () => 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"), V = () => 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=${R()}&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"), V = () => 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=${R()}&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"), V = () => 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=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
196
196
|
{
|
|
197
197
|
headers: {
|
|
198
198
|
"Content-Type": "application/json",
|
|
@@ -247,8 +247,7 @@ const _r = ({
|
|
|
247
247
|
style: {
|
|
248
248
|
height: "30px",
|
|
249
249
|
width: "30px",
|
|
250
|
-
boxShadow: "0 4px 10px rgba(0, 0, 0, 0.25)"
|
|
251
|
-
borderRadius: "8px"
|
|
250
|
+
boxShadow: "0 4px 10px rgba(0, 0, 0, 0.25)"
|
|
252
251
|
},
|
|
253
252
|
children: "<"
|
|
254
253
|
}
|
|
@@ -326,8 +325,7 @@ const _r = ({
|
|
|
326
325
|
style: {
|
|
327
326
|
height: "30px",
|
|
328
327
|
width: "30px",
|
|
329
|
-
boxShadow: "0 4px 10px rgba(0, 0, 0, 0.25)"
|
|
330
|
-
borderRadius: "8px"
|
|
328
|
+
boxShadow: "0 4px 10px rgba(0, 0, 0, 0.25)"
|
|
331
329
|
},
|
|
332
330
|
children: ">"
|
|
333
331
|
}
|
|
@@ -359,13 +357,13 @@ const _r = ({
|
|
|
359
357
|
]
|
|
360
358
|
},
|
|
361
359
|
o
|
|
362
|
-
)) }),
|
|
360
|
+
)) }), Ve = async (t, e) => {
|
|
363
361
|
const { serverUrl: r, basePath: o } = st(), n = `${r}`;
|
|
364
362
|
console.log(`customer_token
|
|
365
363
|
`, t);
|
|
366
364
|
try {
|
|
367
365
|
return (await E.post(
|
|
368
|
-
`${n}${o}/basket/create?baseUrl=${Z()}&siteId=${
|
|
366
|
+
`${n}${o}/basket/create?baseUrl=${Z()}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
369
367
|
e,
|
|
370
368
|
{
|
|
371
369
|
headers: {
|
|
@@ -377,11 +375,11 @@ const _r = ({
|
|
|
377
375
|
} catch (l) {
|
|
378
376
|
return E.isAxiosError(l) ? console.error("Error creating basket:", l.response || l.message) : console.error("Unexpected error:", l), null;
|
|
379
377
|
}
|
|
380
|
-
},
|
|
378
|
+
}, Vt = async (t, e, r) => {
|
|
381
379
|
const { serverUrl: o, basePath: n } = st(), l = `${o}`;
|
|
382
380
|
try {
|
|
383
381
|
const s = await E.post(
|
|
384
|
-
`${l}${n}/basket/add-product/${t}?baseUrl=${Z()}&siteId=${
|
|
382
|
+
`${l}${n}/basket/add-product/${t}?baseUrl=${Z()}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
385
383
|
e,
|
|
386
384
|
{
|
|
387
385
|
headers: {
|
|
@@ -397,7 +395,7 @@ const _r = ({
|
|
|
397
395
|
s.response || s.message
|
|
398
396
|
) : console.error("Unexpected error:", s), null;
|
|
399
397
|
}
|
|
400
|
-
},
|
|
398
|
+
}, Re = async ({
|
|
401
399
|
basketId: t,
|
|
402
400
|
customer_token: e
|
|
403
401
|
}) => {
|
|
@@ -405,7 +403,7 @@ const _r = ({
|
|
|
405
403
|
const { serverUrl: r, basePath: o } = st(), n = `${r}`;
|
|
406
404
|
try {
|
|
407
405
|
const s = await E.get(
|
|
408
|
-
`${n}${o}/basket/${t}?baseUrl=${Z()}&siteId=${
|
|
406
|
+
`${n}${o}/basket/${t}?baseUrl=${Z()}&siteId=${R()}&pubCfg=${tt()}&envRef=${et()}&orgRef=${rt()}`,
|
|
409
407
|
{
|
|
410
408
|
headers: {
|
|
411
409
|
"Content-Type": "application/json",
|
|
@@ -417,10 +415,10 @@ const _r = ({
|
|
|
417
415
|
} catch (s) {
|
|
418
416
|
return E.isAxiosError(s) ? { status: (l = s.response) == null ? void 0 : l.status, data: null } : { status: null, data: null };
|
|
419
417
|
}
|
|
420
|
-
},
|
|
418
|
+
}, Rt = "sfcc_basket_id", Se = "sfcc_customer_token", Tt = "sfcc_token_expiry", Fr = 300 * 1e3, Ft = "1.0.0";
|
|
421
419
|
const xt = (t) => {
|
|
422
420
|
try {
|
|
423
|
-
t ? localStorage.setItem(
|
|
421
|
+
t ? localStorage.setItem(Rt, t) : localStorage.removeItem(Rt);
|
|
424
422
|
} catch (e) {
|
|
425
423
|
console.error("Error saving basket ID to storage:", e);
|
|
426
424
|
}
|
|
@@ -461,7 +459,7 @@ const xt = (t) => {
|
|
|
461
459
|
console.log(p, "the product data");
|
|
462
460
|
const _t = JSON.parse(
|
|
463
461
|
sessionStorage.getItem("customerData") || "{}"
|
|
464
|
-
), nt = (_t == null ? void 0 : _t.basketId) || localStorage.getItem(
|
|
462
|
+
), nt = (_t == null ? void 0 : _t.basketId) || localStorage.getItem(Rt), Kt = !1, jt = localStorage.getItem(Tt), Y = Date.now();
|
|
465
463
|
if (!Kt || !jt || Y >= parseInt(jt)) {
|
|
466
464
|
let $ = "";
|
|
467
465
|
{
|
|
@@ -474,12 +472,12 @@ const xt = (t) => {
|
|
|
474
472
|
}
|
|
475
473
|
const At = Y + 300 * 1e3;
|
|
476
474
|
if (Yt($), localStorage.setItem(Tt, At.toString()), nt) {
|
|
477
|
-
const K = await
|
|
475
|
+
const K = await Re({
|
|
478
476
|
basketId: nt,
|
|
479
477
|
customer_token: $
|
|
480
478
|
});
|
|
481
479
|
if (console.log(nt, "basket id from customer"), K.status === 200 && K) {
|
|
482
|
-
const G = await
|
|
480
|
+
const G = await Vt(
|
|
483
481
|
nt,
|
|
484
482
|
p,
|
|
485
483
|
$
|
|
@@ -504,7 +502,7 @@ const xt = (t) => {
|
|
|
504
502
|
]
|
|
505
503
|
};
|
|
506
504
|
console.log("before create basket");
|
|
507
|
-
const h = await
|
|
505
|
+
const h = await Ve($, Gt);
|
|
508
506
|
if (console.log(
|
|
509
507
|
h,
|
|
510
508
|
h == null ? void 0 : h.basket_id,
|
|
@@ -520,7 +518,7 @@ const xt = (t) => {
|
|
|
520
518
|
), xt(
|
|
521
519
|
(h == null ? void 0 : h.basket_id) || (h == null ? void 0 : h.basketId)
|
|
522
520
|
), console.log("adding product to basket");
|
|
523
|
-
const J = await
|
|
521
|
+
const J = await Vt(
|
|
524
522
|
(h == null ? void 0 : h.basket_id) || (h == null ? void 0 : h.basketId),
|
|
525
523
|
p,
|
|
526
524
|
$
|
|
@@ -782,7 +780,7 @@ const xt = (t) => {
|
|
|
782
780
|
try {
|
|
783
781
|
O(
|
|
784
782
|
(L) => L.map(
|
|
785
|
-
(H,
|
|
783
|
+
(H, V) => V === L.length - 1 ? { ...H, secondaryLoading: !0 } : H
|
|
786
784
|
)
|
|
787
785
|
);
|
|
788
786
|
const y = await At();
|
|
@@ -815,10 +813,10 @@ const xt = (t) => {
|
|
|
815
813
|
const { done: L, value: H } = await ft.read();
|
|
816
814
|
if (L) break;
|
|
817
815
|
D += mt.decode(H, { stream: !0 });
|
|
818
|
-
const
|
|
816
|
+
const V = D.split(`
|
|
819
817
|
`);
|
|
820
|
-
D =
|
|
821
|
-
for (const W of
|
|
818
|
+
D = V.pop() || "";
|
|
819
|
+
for (const W of V)
|
|
822
820
|
if (W.startsWith("data:")) {
|
|
823
821
|
const m = W.slice(5).trim();
|
|
824
822
|
try {
|
|
@@ -887,9 +885,9 @@ const xt = (t) => {
|
|
|
887
885
|
let D = "", L = "";
|
|
888
886
|
for (; ; ) {
|
|
889
887
|
ot(!0);
|
|
890
|
-
const { done: H, value:
|
|
888
|
+
const { done: H, value: V } = await ft.read();
|
|
891
889
|
if (H) break;
|
|
892
|
-
D += mt.decode(
|
|
890
|
+
D += mt.decode(V, { stream: !0 });
|
|
893
891
|
const W = D.split(`
|
|
894
892
|
`);
|
|
895
893
|
D = W.pop() || "";
|
|
@@ -984,7 +982,7 @@ const xt = (t) => {
|
|
|
984
982
|
}
|
|
985
983
|
ot(!1);
|
|
986
984
|
}, rr = async (c, k) => {
|
|
987
|
-
var w, y, f, g, z, ut, pt, A, ft, mt, D, L, H,
|
|
985
|
+
var w, y, f, g, z, ut, pt, A, ft, mt, D, L, H, V, W;
|
|
988
986
|
M(!0);
|
|
989
987
|
try {
|
|
990
988
|
const m = await He(c.id);
|
|
@@ -1004,7 +1002,7 @@ const xt = (t) => {
|
|
|
1004
1002
|
console.log(B, "product data", "app version", Ft);
|
|
1005
1003
|
const I = JSON.parse(
|
|
1006
1004
|
sessionStorage.getItem("customerData") || "{}"
|
|
1007
|
-
), T = (I == null ? void 0 : I.basketId) || localStorage.getItem(
|
|
1005
|
+
), T = (I == null ? void 0 : I.basketId) || localStorage.getItem(Rt), X = !1, Dt = localStorage.getItem(Tt), he = Date.now();
|
|
1008
1006
|
if (!X || !Dt || he >= parseInt(Dt)) {
|
|
1009
1007
|
const or = await qe();
|
|
1010
1008
|
let { customer_token: at } = await Me(
|
|
@@ -1016,12 +1014,12 @@ const xt = (t) => {
|
|
|
1016
1014
|
}
|
|
1017
1015
|
const nr = he + 300 * 1e3;
|
|
1018
1016
|
if (Yt(at), localStorage.setItem(Tt, nr.toString()), console.log(T, "basketIdFromCustomer"), T) {
|
|
1019
|
-
const we = await
|
|
1017
|
+
const we = await Re({
|
|
1020
1018
|
basketId: T,
|
|
1021
1019
|
customer_token: at
|
|
1022
1020
|
});
|
|
1023
1021
|
if (we.status === 200 && we) {
|
|
1024
|
-
const Wt = await
|
|
1022
|
+
const Wt = await Vt(
|
|
1025
1023
|
T,
|
|
1026
1024
|
B,
|
|
1027
1025
|
at
|
|
@@ -1044,7 +1042,7 @@ const xt = (t) => {
|
|
|
1044
1042
|
quantity: 1
|
|
1045
1043
|
}
|
|
1046
1044
|
]
|
|
1047
|
-
}, v = await
|
|
1045
|
+
}, v = await Ve(at, ar);
|
|
1048
1046
|
if (console.log(
|
|
1049
1047
|
v,
|
|
1050
1048
|
v == null ? void 0 : v.basket_id,
|
|
@@ -1057,7 +1055,7 @@ const xt = (t) => {
|
|
|
1057
1055
|
xt(
|
|
1058
1056
|
(v == null ? void 0 : v.basket_id) || (v == null ? void 0 : v.basketId)
|
|
1059
1057
|
);
|
|
1060
|
-
const ht = await
|
|
1058
|
+
const ht = await Vt(
|
|
1061
1059
|
(v == null ? void 0 : v.basket_id) || (v == null ? void 0 : v.basketId),
|
|
1062
1060
|
B,
|
|
1063
1061
|
at
|
|
@@ -1076,7 +1074,7 @@ const xt = (t) => {
|
|
|
1076
1074
|
position: "bottom-right",
|
|
1077
1075
|
autoClose: 3e3
|
|
1078
1076
|
}), ((L = m == null ? void 0 : m.response) == null ? void 0 : L.status) === 404 || // Basket not found
|
|
1079
|
-
((H = m == null ? void 0 : m.response) == null ? void 0 : H.status) === 401 ? (((
|
|
1077
|
+
((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), ((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", {
|
|
1080
1078
|
position: "bottom-right",
|
|
1081
1079
|
autoClose: 3e3
|
|
1082
1080
|
}));
|
|
@@ -1969,7 +1967,7 @@ function Qe(t) {
|
|
|
1969
1967
|
function se(t) {
|
|
1970
1968
|
t._observer = void 0, t._queue = void 0, t._state = "closed";
|
|
1971
1969
|
}
|
|
1972
|
-
function
|
|
1970
|
+
function Vr(t) {
|
|
1973
1971
|
var e = t._queue;
|
|
1974
1972
|
if (e) {
|
|
1975
1973
|
t._queue = void 0, t._state = "ready";
|
|
@@ -2013,14 +2011,14 @@ function ee(t, e, r) {
|
|
|
2013
2011
|
type: e,
|
|
2014
2012
|
value: r
|
|
2015
2013
|
}], qt(function() {
|
|
2016
|
-
return
|
|
2014
|
+
return Vr(t);
|
|
2017
2015
|
});
|
|
2018
2016
|
return;
|
|
2019
2017
|
}
|
|
2020
2018
|
Ze(t, e, r);
|
|
2021
2019
|
}
|
|
2022
2020
|
}
|
|
2023
|
-
var
|
|
2021
|
+
var Rr = /* @__PURE__ */ (function() {
|
|
2024
2022
|
function t(r, o) {
|
|
2025
2023
|
this._cleanup = void 0, this._observer = r, this._queue = void 0, this._state = "initializing";
|
|
2026
2024
|
var n = new Yr(this);
|
|
@@ -2069,7 +2067,7 @@ var Vr = /* @__PURE__ */ (function() {
|
|
|
2069
2067
|
next: o,
|
|
2070
2068
|
error: arguments[1],
|
|
2071
2069
|
complete: arguments[2]
|
|
2072
|
-
}), new
|
|
2070
|
+
}), new Rr(o, this._subscriber);
|
|
2073
2071
|
}, e.forEach = function(o) {
|
|
2074
2072
|
var n = this;
|
|
2075
2073
|
return new Promise(function(l, s) {
|