@azzas/azzas-tracker-web 2.0.0-preview.2 → 2.0.0-preview.20
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/mod.cjs +399 -226
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +644 -29
- package/dist/mod.d.ts +644 -29
- package/dist/mod.global.js +398 -226
- package/dist/mod.global.js.map +1 -1
- package/dist/mod.js +398 -226
- package/dist/mod.js.map +1 -1
- package/dist/mod.vtex.global.js +472 -257
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
EVENTS: () => EVENTS,
|
|
24
24
|
default: () => src_default,
|
|
25
|
+
initTracker: () => initTracker,
|
|
25
26
|
trackWebEvent: () => trackWebEvent
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -318,7 +319,7 @@ var EVENTS = {
|
|
|
318
319
|
name: "notify_me",
|
|
319
320
|
hasEcommerce: false,
|
|
320
321
|
destinations: ["DataLayer"],
|
|
321
|
-
requiredParams: ["brand", "
|
|
322
|
+
requiredParams: ["brand", "size", "item_ref"]
|
|
322
323
|
},
|
|
323
324
|
REFINE_RESULTS: {
|
|
324
325
|
name: "refine_results",
|
|
@@ -1070,7 +1071,7 @@ var PROD_DOMAINS = {
|
|
|
1070
1071
|
"store": "https://www.animale.com.br",
|
|
1071
1072
|
"checkout": "https://secure.animale.com.br"
|
|
1072
1073
|
},
|
|
1073
|
-
"
|
|
1074
|
+
"lojafarm": {
|
|
1074
1075
|
"store": "https://lojafarm.myvtex.com"
|
|
1075
1076
|
},
|
|
1076
1077
|
"mariafilo": {
|
|
@@ -1088,23 +1089,23 @@ var PROD_DOMAINS = {
|
|
|
1088
1089
|
"bynv": {
|
|
1089
1090
|
"store": "https://bynv.myvtex.com"
|
|
1090
1091
|
},
|
|
1091
|
-
"
|
|
1092
|
+
"lojafabula": {
|
|
1092
1093
|
"store": "https://lojafabula.myvtex.com"
|
|
1093
1094
|
}
|
|
1094
1095
|
};
|
|
1095
1096
|
async function getUserInfo(context) {
|
|
1096
|
-
var _a, _b, _c, _d, _e;
|
|
1097
|
-
const domain = (
|
|
1098
|
-
if (!domain) return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
|
|
1097
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I;
|
|
1098
|
+
const domain = (_e = PROD_DOMAINS[(_b = (_a = context == null ? void 0 : context.meta) == null ? void 0 : _a.user_info) == null ? void 0 : _b.account]) == null ? void 0 : _e[(_d = (_c = context == null ? void 0 : context.meta) == null ? void 0 : _c.user_info) == null ? void 0 : _d.platform];
|
|
1099
|
+
if (!domain) return { customer: { email: (_g = (_f = context == null ? void 0 : context.meta) == null ? void 0 : _f.user_info) == null ? void 0 : _g.userEmail, id: (_i = (_h = context == null ? void 0 : context.meta) == null ? void 0 : _h.user_info) == null ? void 0 : _i.userId }, address: null };
|
|
1099
1100
|
try {
|
|
1100
1101
|
const api = `${domain}/_v/user-info`;
|
|
1101
1102
|
const response = await fetch(api, {
|
|
1102
1103
|
method: "POST",
|
|
1103
|
-
body: JSON.stringify({ email: context.userEmail })
|
|
1104
|
+
body: JSON.stringify({ email: (_k = (_j = context == null ? void 0 : context.meta) == null ? void 0 : _j.user_info) == null ? void 0 : _k.userEmail })
|
|
1104
1105
|
});
|
|
1105
1106
|
if (response.status !== 200) {
|
|
1106
|
-
if ((context == null ? void 0 : context.manuallyInfo) && ((
|
|
1107
|
-
const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = context.manuallyInfo;
|
|
1107
|
+
if (((_m = (_l = context == null ? void 0 : context.meta) == null ? void 0 : _l.user_info) == null ? void 0 : _m.manuallyInfo) && ((_p = (_o = (_n = context == null ? void 0 : context.meta) == null ? void 0 : _n.user_info) == null ? void 0 : _o.manuallyInfo) == null ? void 0 : _p.cpf)) {
|
|
1108
|
+
const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = (_r = (_q = context == null ? void 0 : context.meta) == null ? void 0 : _q.user_info) == null ? void 0 : _r.manuallyInfo;
|
|
1108
1109
|
const document3 = cpf == null ? void 0 : cpf.replace(/\D/g, "");
|
|
1109
1110
|
const hashedDocument2 = await documentToHash(document3);
|
|
1110
1111
|
return {
|
|
@@ -1122,15 +1123,15 @@ async function getUserInfo(context) {
|
|
|
1122
1123
|
}
|
|
1123
1124
|
};
|
|
1124
1125
|
}
|
|
1125
|
-
return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
|
|
1126
|
+
return { customer: { email: (_t = (_s = context == null ? void 0 : context.meta) == null ? void 0 : _s.user_info) == null ? void 0 : _t.userEmail, id: (_v = (_u = context == null ? void 0 : context.meta) == null ? void 0 : _u.user_info) == null ? void 0 : _v.userId }, address: null };
|
|
1126
1127
|
}
|
|
1127
1128
|
const res = await response.json();
|
|
1128
|
-
const document2 = (
|
|
1129
|
+
const document2 = (_x = (_w = res == null ? void 0 : res.customer) == null ? void 0 : _w.document) == null ? void 0 : _x.replace(/\D/g, "");
|
|
1129
1130
|
const hashedDocument = await documentToHash(document2);
|
|
1130
1131
|
return { ...res, customer: { ...res.customer, cpf: hashedDocument, document: document2 } };
|
|
1131
1132
|
} catch (_) {
|
|
1132
|
-
if ((context == null ? void 0 : context.manuallyInfo) && ((
|
|
1133
|
-
const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = context.manuallyInfo;
|
|
1133
|
+
if (((_z = (_y = context == null ? void 0 : context.meta) == null ? void 0 : _y.user_info) == null ? void 0 : _z.manuallyInfo) && ((_C = (_B = (_A = context == null ? void 0 : context.meta) == null ? void 0 : _A.user_info) == null ? void 0 : _B.manuallyInfo) == null ? void 0 : _C.cpf)) {
|
|
1134
|
+
const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = (_E = (_D = context == null ? void 0 : context.meta) == null ? void 0 : _D.user_info) == null ? void 0 : _E.manuallyInfo;
|
|
1134
1135
|
const document2 = cpf == null ? void 0 : cpf.replace(/\D/g, "");
|
|
1135
1136
|
const hashedDocument = await documentToHash(document2);
|
|
1136
1137
|
return {
|
|
@@ -1148,7 +1149,7 @@ async function getUserInfo(context) {
|
|
|
1148
1149
|
}
|
|
1149
1150
|
};
|
|
1150
1151
|
}
|
|
1151
|
-
return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
|
|
1152
|
+
return { customer: { email: (_G = (_F = context == null ? void 0 : context.meta) == null ? void 0 : _F.user_info) == null ? void 0 : _G.userEmail, id: (_I = (_H = context == null ? void 0 : context.meta) == null ? void 0 : _H.user_info) == null ? void 0 : _I.userId }, address: null };
|
|
1152
1153
|
}
|
|
1153
1154
|
}
|
|
1154
1155
|
|
|
@@ -1355,10 +1356,12 @@ var legacyGetters = {
|
|
|
1355
1356
|
};
|
|
1356
1357
|
|
|
1357
1358
|
// src/params/adapters/meta/index.ts
|
|
1358
|
-
var
|
|
1359
|
+
var metaAdapter = {
|
|
1359
1360
|
user_info: getUserInfo,
|
|
1360
|
-
brand: (context) => {
|
|
1361
|
-
|
|
1361
|
+
brand: (context, config2) => {
|
|
1362
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1363
|
+
if (context == null ? void 0 : context.meta.brand) return context.meta.brand;
|
|
1364
|
+
return null;
|
|
1362
1365
|
},
|
|
1363
1366
|
content_type: (context) => {
|
|
1364
1367
|
return context.meta.content_type || null;
|
|
@@ -1369,8 +1372,8 @@ var metaAdapters = {
|
|
|
1369
1372
|
pre_filled: (context) => {
|
|
1370
1373
|
return !!context.preFilled;
|
|
1371
1374
|
},
|
|
1372
|
-
currency: (
|
|
1373
|
-
if (
|
|
1375
|
+
currency: (_, config2) => {
|
|
1376
|
+
if (config2 == null ? void 0 : config2.currency) return config2.currency;
|
|
1374
1377
|
return "BRL";
|
|
1375
1378
|
},
|
|
1376
1379
|
slot_per_line: (context) => {
|
|
@@ -1381,7 +1384,7 @@ var metaAdapters = {
|
|
|
1381
1384
|
return context.meta.search_term || null;
|
|
1382
1385
|
},
|
|
1383
1386
|
search_found: (context) => {
|
|
1384
|
-
return context.meta.search_found ||
|
|
1387
|
+
return context.meta.search_found || false;
|
|
1385
1388
|
},
|
|
1386
1389
|
search_quantity: (context) => {
|
|
1387
1390
|
return context.meta.search_quantity || 0;
|
|
@@ -1395,17 +1398,14 @@ var metaAdapters = {
|
|
|
1395
1398
|
creative_slot: (context) => {
|
|
1396
1399
|
return context.meta.creative_slot || null;
|
|
1397
1400
|
},
|
|
1398
|
-
size: (context) => {
|
|
1399
|
-
return context.size || null;
|
|
1400
|
-
},
|
|
1401
1401
|
item_ref: (context) => {
|
|
1402
|
-
return context.
|
|
1402
|
+
return context.meta.item_ref || null;
|
|
1403
1403
|
},
|
|
1404
1404
|
method: (context) => {
|
|
1405
|
-
return context.method || null;
|
|
1405
|
+
return context.meta.method || null;
|
|
1406
1406
|
},
|
|
1407
1407
|
type: (context) => {
|
|
1408
|
-
return context.type || null;
|
|
1408
|
+
return context.meta.type || null;
|
|
1409
1409
|
},
|
|
1410
1410
|
color: (context) => {
|
|
1411
1411
|
return context.meta.color || null;
|
|
@@ -1418,9 +1418,45 @@ var metaAdapters = {
|
|
|
1418
1418
|
},
|
|
1419
1419
|
ordering: (context) => {
|
|
1420
1420
|
return context.meta.ordering || null;
|
|
1421
|
+
},
|
|
1422
|
+
size: (context) => {
|
|
1423
|
+
return context.meta.size || null;
|
|
1421
1424
|
}
|
|
1422
1425
|
};
|
|
1423
1426
|
|
|
1427
|
+
// src/core/farm.ts
|
|
1428
|
+
var BRAND_CODES2 = {
|
|
1429
|
+
farm: "farmrio",
|
|
1430
|
+
"farm etc": "farmetc",
|
|
1431
|
+
"farm rio": "farmrio"
|
|
1432
|
+
};
|
|
1433
|
+
function getBrandCode2(brand) {
|
|
1434
|
+
if (!brand) return null;
|
|
1435
|
+
const standardized = brand.toLowerCase().trim();
|
|
1436
|
+
return BRAND_CODES2[standardized] || null;
|
|
1437
|
+
}
|
|
1438
|
+
function normalizeBrand2(input) {
|
|
1439
|
+
var _a;
|
|
1440
|
+
let brandStrings = [];
|
|
1441
|
+
if (Array.isArray(input) && input.every((item) => typeof item === "string")) {
|
|
1442
|
+
brandStrings = input;
|
|
1443
|
+
} else if (Array.isArray(input)) {
|
|
1444
|
+
brandStrings = input.map((item) => {
|
|
1445
|
+
var _a2;
|
|
1446
|
+
return ((_a2 = item.additionalInfo) == null ? void 0 : _a2.brandName) || item.brand;
|
|
1447
|
+
});
|
|
1448
|
+
} else if (typeof input === "object" && input !== null && "brand" in input) {
|
|
1449
|
+
brandStrings = [((_a = input.additionalInfo) == null ? void 0 : _a.brandName) || input.brand];
|
|
1450
|
+
} else if (typeof input === "string") {
|
|
1451
|
+
return getBrandCode2(input);
|
|
1452
|
+
} else {
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
const brandCodes = brandStrings.map(getBrandCode2).filter((code) => code !== null);
|
|
1456
|
+
const uniqueSortedCodes = [...new Set(brandCodes)].sort();
|
|
1457
|
+
return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1424
1460
|
// src/params/adapters/deco/utils.ts
|
|
1425
1461
|
var getItemCategory3 = (item) => {
|
|
1426
1462
|
var _a;
|
|
@@ -1439,15 +1475,12 @@ var getItemCategory22 = (item) => {
|
|
|
1439
1475
|
const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
|
|
1440
1476
|
return capitalize(deepest);
|
|
1441
1477
|
};
|
|
1442
|
-
function getItemShippingTier2() {
|
|
1443
|
-
return null;
|
|
1444
|
-
}
|
|
1445
1478
|
|
|
1446
1479
|
// src/params/adapters/deco/index.ts
|
|
1447
1480
|
var IN_STOCK_SCHEMA = "https://schema.org/InStock";
|
|
1448
1481
|
var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
|
|
1449
1482
|
var decoAdapter = {
|
|
1450
|
-
...
|
|
1483
|
+
...metaAdapter,
|
|
1451
1484
|
// global adapters
|
|
1452
1485
|
items: (context) => {
|
|
1453
1486
|
if (context == null ? void 0 : context.items) return context.items;
|
|
@@ -1469,7 +1502,7 @@ var decoAdapter = {
|
|
|
1469
1502
|
// cor
|
|
1470
1503
|
item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
|
|
1471
1504
|
// tamanho
|
|
1472
|
-
item_shipping_tier:
|
|
1505
|
+
item_shipping_tier: "",
|
|
1473
1506
|
item_ref: (_s = (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find((i) => i.name === "RefId")) == null ? void 0 : _q.value) == null ? void 0 : _r.replace(/_\d+$/, "")) != null ? _s : null,
|
|
1474
1507
|
item_category: (_t = getItemCategory3(item)) != null ? _t : null,
|
|
1475
1508
|
item_category2: (_u = getItemCategory22(item)) != null ? _u : null,
|
|
@@ -1484,17 +1517,21 @@ var decoAdapter = {
|
|
|
1484
1517
|
}
|
|
1485
1518
|
return null;
|
|
1486
1519
|
},
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1520
|
+
brand: (context, config2) => {
|
|
1521
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1522
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1523
|
+
if (context == null ? void 0 : context.products) {
|
|
1524
|
+
return normalizeBrand2(context.products.map((p) => {
|
|
1525
|
+
var _a;
|
|
1526
|
+
return (_a = p == null ? void 0 : p.brand) == null ? void 0 : _a.name;
|
|
1527
|
+
}));
|
|
1528
|
+
}
|
|
1529
|
+
return null;
|
|
1530
|
+
},
|
|
1494
1531
|
line_items: (context) => {
|
|
1495
1532
|
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1496
1533
|
if (context == null ? void 0 : context.products) {
|
|
1497
|
-
return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
|
|
1534
|
+
return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id)).join();
|
|
1498
1535
|
}
|
|
1499
1536
|
return null;
|
|
1500
1537
|
},
|
|
@@ -1532,197 +1569,103 @@ var decoAdapter = {
|
|
|
1532
1569
|
}
|
|
1533
1570
|
};
|
|
1534
1571
|
|
|
1535
|
-
// src/params/adapters/
|
|
1572
|
+
// src/params/adapters/reserva/utils.ts
|
|
1536
1573
|
var getItemCategory5 = (item) => {
|
|
1537
|
-
var _a;
|
|
1538
|
-
const categories = item == null ? void 0 : item.
|
|
1539
|
-
if (!categories) return "Cole\xE7\xE3o";
|
|
1540
|
-
const
|
|
1541
|
-
const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
|
|
1574
|
+
var _a, _b, _c;
|
|
1575
|
+
const categories = (_b = (_a = item == null ? void 0 : item.similarItems) == null ? void 0 : _a[0]) == null ? void 0 : _b.categories;
|
|
1576
|
+
if (!(categories == null ? void 0 : categories.length)) return "Cole\xE7\xE3o";
|
|
1577
|
+
const match = (_c = categories.join(" ").match(/outlet|bazar|sale/i)) == null ? void 0 : _c[0].toLowerCase();
|
|
1542
1578
|
return match != null ? match : "Cole\xE7\xE3o";
|
|
1543
1579
|
};
|
|
1544
1580
|
var getItemCategory23 = (item) => {
|
|
1545
|
-
var _a, _b;
|
|
1546
|
-
const AVOID_CATEGORIES =
|
|
1547
|
-
const categories =
|
|
1548
|
-
const validHierarchy = categories.
|
|
1549
|
-
const deepest = (
|
|
1581
|
+
var _a, _b, _c, _d;
|
|
1582
|
+
const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
|
|
1583
|
+
const categories = (_c = (_b = (_a = item == null ? void 0 : item.similarItems) == null ? void 0 : _a[0]) == null ? void 0 : _b.categories) != null ? _c : [];
|
|
1584
|
+
const validHierarchy = categories.filter((c) => c && !AVOID_CATEGORIES.test(c));
|
|
1585
|
+
const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
|
|
1550
1586
|
return capitalize(deepest);
|
|
1551
1587
|
};
|
|
1552
|
-
var getOrderFormItems = (orderForm) => {
|
|
1553
|
-
const idSelected = orderForm == null ? void 0 : orderForm.selected;
|
|
1554
|
-
return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
|
|
1555
|
-
};
|
|
1556
1588
|
|
|
1557
|
-
// src/params/adapters/
|
|
1558
|
-
var
|
|
1559
|
-
...
|
|
1589
|
+
// src/params/adapters/reserva/index.ts
|
|
1590
|
+
var reservaAdapter = {
|
|
1591
|
+
...metaAdapter,
|
|
1592
|
+
// global adapters
|
|
1560
1593
|
items: (context) => {
|
|
1561
1594
|
if (context == null ? void 0 : context.items) return context.items;
|
|
1562
|
-
if (
|
|
1563
|
-
return
|
|
1564
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1595
|
+
if (context == null ? void 0 : context.products) {
|
|
1596
|
+
return context.products.map((item) => {
|
|
1597
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E;
|
|
1598
|
+
const COLOR_REGEX = /^[^_]+_/;
|
|
1599
|
+
const listPrice = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].listPrice;
|
|
1600
|
+
const refIdValue = (_e = (_d = (_c = item.additionalProperty) == null ? void 0 : _c.find((i) => i.name === "RefId")) == null ? void 0 : _d.value) == null ? void 0 : _e.replace(/_\d+$/, "");
|
|
1565
1601
|
return {
|
|
1566
|
-
quantity:
|
|
1567
|
-
index: (
|
|
1568
|
-
item_brand: (
|
|
1569
|
-
item_name: (
|
|
1570
|
-
price: (item == null ? void 0 :
|
|
1571
|
-
discount: ((item == null ? void 0 : item.
|
|
1572
|
-
item_variant: (
|
|
1573
|
-
|
|
1602
|
+
quantity: 1,
|
|
1603
|
+
index: (_f = item == null ? void 0 : item.index) != null ? _f : 0,
|
|
1604
|
+
item_brand: (_i = (_h = (_g = item.brand) == null ? void 0 : _g.name) == null ? void 0 : _h.toLowerCase()) != null ? _i : null,
|
|
1605
|
+
item_name: (_j = item.name) != null ? _j : null,
|
|
1606
|
+
price: (_l = (_k = item.offers) == null ? void 0 : _k.lowPrice) != null ? _l : null,
|
|
1607
|
+
discount: Math.round((Number(listPrice) - Number((_m = item == null ? void 0 : item.offers) == null ? void 0 : _m.lowPrice)) * 100) / 100,
|
|
1608
|
+
item_variant: ((_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[0]) == null ? void 0 : _o.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
|
|
1609
|
+
// cor
|
|
1610
|
+
item_variant2: (_q = (_p = item == null ? void 0 : item.name) == null ? void 0 : _p.split(" - ")[1]) != null ? _q : null,
|
|
1611
|
+
// tamanho
|
|
1574
1612
|
item_shipping_tier: "",
|
|
1575
|
-
item_ref:
|
|
1576
|
-
item_category: (
|
|
1577
|
-
item_category2: (
|
|
1578
|
-
item_id: (
|
|
1579
|
-
item_sku: (
|
|
1580
|
-
item_url: (
|
|
1581
|
-
image_url: (
|
|
1582
|
-
seller_id: (
|
|
1583
|
-
item_list_name: (
|
|
1613
|
+
item_ref: refIdValue != null ? refIdValue : null,
|
|
1614
|
+
item_category: (_r = getItemCategory5(item)) != null ? _r : null,
|
|
1615
|
+
item_category2: (_s = getItemCategory23(item)) != null ? _s : null,
|
|
1616
|
+
item_id: (_t = item == null ? void 0 : item.id) != null ? _t : null,
|
|
1617
|
+
item_sku: (_u = item == null ? void 0 : item.sku) != null ? _u : null,
|
|
1618
|
+
item_url: (_w = (_v = item == null ? void 0 : item.seo) == null ? void 0 : _v.canonical) != null ? _w : null,
|
|
1619
|
+
image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
|
|
1620
|
+
seller_id: (_D = (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) == null ? void 0 : _C.identifier) != null ? _D : null,
|
|
1621
|
+
item_list_name: (_E = item == null ? void 0 : item.item_list_name) != null ? _E : null
|
|
1584
1622
|
};
|
|
1585
1623
|
});
|
|
1586
1624
|
}
|
|
1587
1625
|
return null;
|
|
1588
1626
|
},
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1627
|
+
brand: (context, config2) => {
|
|
1628
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1629
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1630
|
+
if (context == null ? void 0 : context.products) {
|
|
1631
|
+
return normalizeBrand2(context.products.map((p) => {
|
|
1632
|
+
var _a;
|
|
1633
|
+
return (_a = p == null ? void 0 : p.brand) == null ? void 0 : _a.name;
|
|
1634
|
+
}));
|
|
1635
|
+
}
|
|
1636
|
+
return null;
|
|
1637
|
+
},
|
|
1596
1638
|
line_items: (context) => {
|
|
1597
|
-
var _a;
|
|
1598
1639
|
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1599
|
-
if (
|
|
1600
|
-
|
|
1640
|
+
if (context == null ? void 0 : context.products) {
|
|
1641
|
+
return context.products.map((item) => item == null ? void 0 : item.id).filter((id) => Boolean(id)).join();
|
|
1642
|
+
}
|
|
1643
|
+
return null;
|
|
1601
1644
|
},
|
|
1602
1645
|
value: (context) => {
|
|
1603
|
-
var _a;
|
|
1604
1646
|
if (context == null ? void 0 : context.value) return context.value;
|
|
1605
|
-
if (
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1613
|
-
const items = context.orderForm.items;
|
|
1614
|
-
const totalDiscount = items.reduce((acc, item) => {
|
|
1615
|
-
const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
1616
|
-
return acc + unitDiscount * item.quantity;
|
|
1617
|
-
}, 0);
|
|
1618
|
-
const discounts = totalsList.find((t) => t.id === "Discounts");
|
|
1619
|
-
return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
1620
|
-
},
|
|
1621
|
-
subtotal: (context) => {
|
|
1622
|
-
var _a, _b;
|
|
1623
|
-
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1624
|
-
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
1625
|
-
return subtotal;
|
|
1626
|
-
},
|
|
1627
|
-
coupon_message: (context) => {
|
|
1628
|
-
var _a;
|
|
1629
|
-
if (context.couponMessage) return context.couponMessage;
|
|
1630
|
-
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
1631
|
-
if (messages.length === 0) return null;
|
|
1632
|
-
const couponMessages = messages.filter(
|
|
1633
|
-
(msg) => msg.text.toLowerCase().includes("cupom")
|
|
1634
|
-
);
|
|
1635
|
-
if (couponMessages.length === 0) return null;
|
|
1636
|
-
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
1637
|
-
},
|
|
1638
|
-
zipcode: (context) => {
|
|
1639
|
-
var _a;
|
|
1640
|
-
return (_a = context.zipcode) != null ? _a : null;
|
|
1641
|
-
},
|
|
1642
|
-
flag_pickup: (context) => {
|
|
1643
|
-
var _a;
|
|
1644
|
-
const orderForm = context.orderForm;
|
|
1645
|
-
if (!orderForm) return null;
|
|
1646
|
-
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
1647
|
-
const hasPickup = logisticsInfo.some(
|
|
1648
|
-
(info) => {
|
|
1649
|
-
var _a2;
|
|
1650
|
-
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
1651
|
-
}
|
|
1652
|
-
);
|
|
1653
|
-
return hasPickup;
|
|
1654
|
-
},
|
|
1655
|
-
shippings: (context) => {
|
|
1656
|
-
if (!context.orderForm) return null;
|
|
1657
|
-
const { items, shippingData } = context.orderForm;
|
|
1658
|
-
const acc = {};
|
|
1659
|
-
shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
|
|
1660
|
-
const item = items[itemIndex];
|
|
1661
|
-
if (!item) return;
|
|
1662
|
-
slas.forEach((sla) => {
|
|
1663
|
-
if (!acc[sla.name]) acc[sla.name] = {
|
|
1664
|
-
shipping_tier: sla.name,
|
|
1665
|
-
delivery_time: parseInt(sla.shippingEstimate),
|
|
1666
|
-
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
1667
|
-
line_items: []
|
|
1668
|
-
};
|
|
1669
|
-
acc[sla.name].line_items.push(item.id);
|
|
1670
|
-
});
|
|
1671
|
-
});
|
|
1672
|
-
return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
|
|
1673
|
-
},
|
|
1674
|
-
shipping: (context) => {
|
|
1675
|
-
var _a, _b, _c;
|
|
1676
|
-
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1677
|
-
return logistics.reduce((total, item) => {
|
|
1678
|
-
var _a2, _b2;
|
|
1679
|
-
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
1680
|
-
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
1681
|
-
}, 0);
|
|
1682
|
-
},
|
|
1683
|
-
shipping_tier: (context) => {
|
|
1684
|
-
var _a, _b, _c;
|
|
1685
|
-
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1686
|
-
const selectedSlas = logistics.map((item) => {
|
|
1687
|
-
var _a2;
|
|
1688
|
-
if (!item.selectedSla) return null;
|
|
1689
|
-
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
1690
|
-
}).filter(Boolean);
|
|
1691
|
-
if (selectedSlas.length === 0) return null;
|
|
1692
|
-
const uniqueTiers = Array.from(
|
|
1693
|
-
new Map(
|
|
1694
|
-
selectedSlas.map((sla) => {
|
|
1695
|
-
var _a2;
|
|
1696
|
-
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
1697
|
-
return [key, sla];
|
|
1698
|
-
})
|
|
1699
|
-
).values()
|
|
1700
|
-
);
|
|
1701
|
-
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
1702
|
-
var _a2, _b2;
|
|
1703
|
-
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1704
|
-
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1705
|
-
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
1706
|
-
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
1707
|
-
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
1708
|
-
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
1709
|
-
});
|
|
1710
|
-
const shippingTier = sortedTiers.map((sla) => {
|
|
1711
|
-
var _a2;
|
|
1712
|
-
return sla.deliveryChannel === "pickup-in-point" ? `retirada em loja${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) ? `: ${sla.pickupStoreInfo.friendlyName}` : ""}` : sla.deliveryChannel === "delivery" ? `receba em casa${sla.name ? `: ${sla.name}` : ""}` : null;
|
|
1713
|
-
}).filter(Boolean).join(", ");
|
|
1714
|
-
return shippingTier || null;
|
|
1715
|
-
},
|
|
1716
|
-
transaction_id: (context) => {
|
|
1717
|
-
var _a, _b;
|
|
1718
|
-
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
1719
|
-
},
|
|
1720
|
-
coupon: (context) => {
|
|
1721
|
-
var _a, _b;
|
|
1722
|
-
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
1647
|
+
if (context == null ? void 0 : context.products) {
|
|
1648
|
+
return context.products.map((item) => {
|
|
1649
|
+
var _a;
|
|
1650
|
+
return (_a = item.offers) == null ? void 0 : _a.lowPrice;
|
|
1651
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1652
|
+
}
|
|
1653
|
+
return null;
|
|
1723
1654
|
},
|
|
1724
|
-
|
|
1725
|
-
|
|
1655
|
+
available_grid: (context) => {
|
|
1656
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1657
|
+
if (context == null ? void 0 : context.products) {
|
|
1658
|
+
const sizes = context.products.filter((product) => {
|
|
1659
|
+
var _a, _b;
|
|
1660
|
+
return (_b = (_a = product.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b.some((o) => o.availability === "https://schema.org/InStock");
|
|
1661
|
+
}).map((product) => {
|
|
1662
|
+
var _a;
|
|
1663
|
+
return (_a = product.name) == null ? void 0 : _a.split(" - ")[1];
|
|
1664
|
+
}).filter((name) => Boolean(name));
|
|
1665
|
+
const result = sortSizes(sizes).join(",").trim();
|
|
1666
|
+
return result || null;
|
|
1667
|
+
}
|
|
1668
|
+
return null;
|
|
1726
1669
|
}
|
|
1727
1670
|
};
|
|
1728
1671
|
|
|
@@ -1797,11 +1740,12 @@ var HeadlessPdpZone = {
|
|
|
1797
1740
|
line_items: (context) => {
|
|
1798
1741
|
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1799
1742
|
if (context == null ? void 0 : context.products) {
|
|
1800
|
-
return context.products.map((item) => item.productId).filter((id) => Boolean(id));
|
|
1743
|
+
return context.products.map((item) => item.productId).filter((id) => Boolean(id)).join();
|
|
1801
1744
|
}
|
|
1802
1745
|
return null;
|
|
1803
1746
|
},
|
|
1804
|
-
brand: (context) => {
|
|
1747
|
+
brand: (context, config2) => {
|
|
1748
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1805
1749
|
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1806
1750
|
if (context == null ? void 0 : context.products) {
|
|
1807
1751
|
return context.products.map((p) => p.brand).join().trim();
|
|
@@ -1855,11 +1799,12 @@ var HeadlessPdcZone = {
|
|
|
1855
1799
|
line_items: (context) => {
|
|
1856
1800
|
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1857
1801
|
if (context == null ? void 0 : context.products) {
|
|
1858
|
-
return context.products.map((item) => item.id).filter((id) => Boolean(id));
|
|
1802
|
+
return context.products.map((item) => item.id).filter((id) => Boolean(id)).join();
|
|
1859
1803
|
}
|
|
1860
1804
|
return null;
|
|
1861
1805
|
},
|
|
1862
|
-
brand: (context) => {
|
|
1806
|
+
brand: (context, config2) => {
|
|
1807
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1863
1808
|
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1864
1809
|
if (context == null ? void 0 : context.products) {
|
|
1865
1810
|
return context.products.map((p) => p.brand.name).join().trim();
|
|
@@ -1870,16 +1815,14 @@ var HeadlessPdcZone = {
|
|
|
1870
1815
|
|
|
1871
1816
|
// src/params/adapters/headless/index.ts
|
|
1872
1817
|
var headlessAdapter = {
|
|
1873
|
-
...
|
|
1818
|
+
...metaAdapter,
|
|
1874
1819
|
// global adapters
|
|
1875
|
-
|
|
1876
|
-
// orderForm adapters, confirmar se no storefront tem evento que usa essses params
|
|
1877
|
-
brand: (context) => {
|
|
1820
|
+
brand: (context, config2) => {
|
|
1878
1821
|
if (context.zone === "PDP") {
|
|
1879
|
-
return HeadlessPdpZone.brand(context);
|
|
1822
|
+
return HeadlessPdpZone.brand(context, config2);
|
|
1880
1823
|
}
|
|
1881
1824
|
if (context.zone === "PDC") {
|
|
1882
|
-
return HeadlessPdcZone.brand(context);
|
|
1825
|
+
return HeadlessPdcZone.brand(context, config2);
|
|
1883
1826
|
}
|
|
1884
1827
|
return null;
|
|
1885
1828
|
},
|
|
@@ -1940,7 +1883,7 @@ var getDeliveryTime = (sla) => {
|
|
|
1940
1883
|
|
|
1941
1884
|
// src/params/adapters/pickup/index.ts
|
|
1942
1885
|
var pickupAdapter = {
|
|
1943
|
-
...
|
|
1886
|
+
...metaAdapter,
|
|
1944
1887
|
flag_pickup: (context) => {
|
|
1945
1888
|
var _a;
|
|
1946
1889
|
return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
|
|
@@ -1948,10 +1891,10 @@ var pickupAdapter = {
|
|
|
1948
1891
|
shippings: (context) => {
|
|
1949
1892
|
if (context.shippings) {
|
|
1950
1893
|
return context.shippings.map((s) => {
|
|
1951
|
-
var _a
|
|
1894
|
+
var _a;
|
|
1952
1895
|
return {
|
|
1953
1896
|
line_items: (_a = s.line_items) != null ? _a : "",
|
|
1954
|
-
shipping:
|
|
1897
|
+
shipping: s.price / 100,
|
|
1955
1898
|
shipping_tier: getShippingTier(s),
|
|
1956
1899
|
delivery_time: getDeliveryTime(s)
|
|
1957
1900
|
};
|
|
@@ -1959,20 +1902,245 @@ var pickupAdapter = {
|
|
|
1959
1902
|
}
|
|
1960
1903
|
return null;
|
|
1961
1904
|
},
|
|
1905
|
+
brand: (context, config2) => {
|
|
1906
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
1907
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1908
|
+
return null;
|
|
1909
|
+
},
|
|
1910
|
+
zipcode: (context) => {
|
|
1911
|
+
var _a;
|
|
1912
|
+
return (_a = context.meta.zipcode) != null ? _a : null;
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
|
|
1916
|
+
// src/params/adapters/orderForm/utils.ts
|
|
1917
|
+
var getOrderFormItems = (orderForm) => {
|
|
1918
|
+
const idSelected = orderForm == null ? void 0 : orderForm.selected;
|
|
1919
|
+
const isMultipleRemove = orderForm == null ? void 0 : orderForm.multipleRemove;
|
|
1920
|
+
return idSelected ? orderForm.items.filter((item) => item.id === idSelected).map((i) => {
|
|
1921
|
+
if (isMultipleRemove) return i;
|
|
1922
|
+
return { ...i, quantity: 1 };
|
|
1923
|
+
}) : orderForm.items;
|
|
1924
|
+
};
|
|
1925
|
+
var getItemCategory7 = (item) => {
|
|
1926
|
+
var _a;
|
|
1927
|
+
const categories = item == null ? void 0 : item.productCategories;
|
|
1928
|
+
if (!categories) return "Cole\xE7\xE3o";
|
|
1929
|
+
const text = Object.values(categories).join(" ");
|
|
1930
|
+
const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
|
|
1931
|
+
return match != null ? match : "Cole\xE7\xE3o";
|
|
1932
|
+
};
|
|
1933
|
+
var getItemCategory25 = (item) => {
|
|
1934
|
+
var _a, _b;
|
|
1935
|
+
const AVOID_CATEGORIES = /outlet|bazar|sale/i;
|
|
1936
|
+
const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
|
|
1937
|
+
const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
|
|
1938
|
+
const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
|
|
1939
|
+
return capitalize(deepest);
|
|
1940
|
+
};
|
|
1941
|
+
function getItemShippingTier2(orderForm, item) {
|
|
1942
|
+
var _a, _b, _c, _d;
|
|
1943
|
+
const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
|
|
1944
|
+
(li) => li.itemId === item.id
|
|
1945
|
+
);
|
|
1946
|
+
const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
|
|
1947
|
+
return ((_d = selectedSla == null ? void 0 : selectedSla.pickupStoreInfo) == null ? void 0 : _d.friendlyName) ? `retirada em loja: ${selectedSla.pickupStoreInfo.friendlyName}` : (selectedSla == null ? void 0 : selectedSla.name) ? `Receba em casa: ${selectedSla.name}` : null;
|
|
1948
|
+
}
|
|
1949
|
+
var getPaymentType2 = (context) => {
|
|
1950
|
+
var _a, _b, _c, _d;
|
|
1951
|
+
if (context.payment_type) return context.payment_type;
|
|
1952
|
+
if (!context.orderForm) return null;
|
|
1953
|
+
const giftCards = ((_a = context.orderForm.paymentData) == null ? void 0 : _a.giftCards) || [];
|
|
1954
|
+
if (giftCards.some((g) => g == null ? void 0 : g.inUse)) return "vale";
|
|
1955
|
+
const payments = ((_b = context.orderForm.paymentData) == null ? void 0 : _b.payments) || [];
|
|
1956
|
+
const systems = ((_c = context.orderForm.paymentData) == null ? void 0 : _c.paymentSystems) || [];
|
|
1957
|
+
if (!payments.length || !systems.length) return null;
|
|
1958
|
+
const selectedPayment = payments.find((p) => p == null ? void 0 : p.paymentSystem) || payments[0];
|
|
1959
|
+
const id = String((selectedPayment == null ? void 0 : selectedPayment.paymentSystem) || "").trim();
|
|
1960
|
+
if (!id) return null;
|
|
1961
|
+
const system = systems.find((s) => String(s.id) === id);
|
|
1962
|
+
const name = ((_d = system == null ? void 0 : system.name) == null ? void 0 : _d.toLowerCase()) || "";
|
|
1963
|
+
const match = paymentTypeMap.find(([key]) => name.includes(key));
|
|
1964
|
+
return match ? match[1] : null;
|
|
1965
|
+
};
|
|
1966
|
+
|
|
1967
|
+
// src/params/adapters/orderForm/index.ts
|
|
1968
|
+
var orderFormAdapter = {
|
|
1969
|
+
...metaAdapter,
|
|
1970
|
+
items: (context) => {
|
|
1971
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1972
|
+
if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
|
|
1973
|
+
return getOrderFormItems(context.orderForm).map((item, index) => {
|
|
1974
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
1975
|
+
return {
|
|
1976
|
+
quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
|
|
1977
|
+
index: (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index + 1,
|
|
1978
|
+
item_brand: (_e = (_d = item.additionalInfo) == null ? void 0 : _d.brandName) != null ? _e : null,
|
|
1979
|
+
item_name: (_f = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _f : null,
|
|
1980
|
+
price: (item == null ? void 0 : item.sellingPrice) / 100,
|
|
1981
|
+
discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
|
|
1982
|
+
item_variant: (_j = (_i = (_h = (_g = item == null ? void 0 : item.skuName) == null ? void 0 : _g.split(" - ")[0]) == null ? void 0 : _h.split("_").pop()) == null ? void 0 : _i.trim()) != null ? _j : null,
|
|
1983
|
+
item_variant2: (_m = (_l = (_k = item == null ? void 0 : item.skuName) == null ? void 0 : _k.split(" - ")[1]) == null ? void 0 : _l.trim()) != null ? _m : null,
|
|
1984
|
+
item_shipping_tier: getItemShippingTier2(context.orderForm, item),
|
|
1985
|
+
item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
|
|
1986
|
+
item_category: (_n = getItemCategory7(item)) != null ? _n : null,
|
|
1987
|
+
item_category2: (_o = getItemCategory25(item)) != null ? _o : null,
|
|
1988
|
+
item_id: (_p = item == null ? void 0 : item.productId) != null ? _p : null,
|
|
1989
|
+
item_sku: (_q = item == null ? void 0 : item.id) != null ? _q : null,
|
|
1990
|
+
item_url: (_r = item.detailUrl) != null ? _r : null,
|
|
1991
|
+
image_url: (_s = resizeVtexImage2(item.imageUrl)) != null ? _s : null,
|
|
1992
|
+
seller_id: (_t = item == null ? void 0 : item.seller) != null ? _t : null,
|
|
1993
|
+
item_list_name: (_v = (_u = context == null ? void 0 : context.orderForm) == null ? void 0 : _u.item_list_name) != null ? _v : null
|
|
1994
|
+
};
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
return null;
|
|
1998
|
+
},
|
|
1999
|
+
brand: (context, config2) => {
|
|
2000
|
+
var _a;
|
|
2001
|
+
if (config2 == null ? void 0 : config2.brand) return config2.brand;
|
|
2002
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
2003
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
2004
|
+
const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
|
|
2005
|
+
return normalizeBrand2(brands);
|
|
2006
|
+
},
|
|
2007
|
+
line_items: (context) => {
|
|
2008
|
+
var _a;
|
|
2009
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
2010
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
2011
|
+
return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id)).join();
|
|
2012
|
+
},
|
|
2013
|
+
value: (context) => {
|
|
2014
|
+
var _a;
|
|
2015
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
2016
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
2017
|
+
return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.sellingPrice) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
2018
|
+
},
|
|
2019
|
+
payment_type: getPaymentType2,
|
|
2020
|
+
total_discount: (context) => {
|
|
2021
|
+
var _a, _b, _c;
|
|
2022
|
+
if (context == null ? void 0 : context.total_discount) return context.total_discount;
|
|
2023
|
+
if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
|
|
2024
|
+
const totalizers = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.totalizers;
|
|
2025
|
+
const productDiscount = ((_c = totalizers.find((t) => t.id === "Discounts")) == null ? void 0 : _c.value) || 0;
|
|
2026
|
+
return Math.abs(productDiscount) / 100 || null;
|
|
2027
|
+
},
|
|
2028
|
+
subtotal: (context) => {
|
|
2029
|
+
var _a, _b;
|
|
2030
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
2031
|
+
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
2032
|
+
return subtotal;
|
|
2033
|
+
},
|
|
1962
2034
|
zipcode: (context) => {
|
|
1963
2035
|
var _a;
|
|
1964
|
-
return (_a = context.zipcode) != null ? _a : null;
|
|
2036
|
+
return (_a = context.meta.zipcode) != null ? _a : null;
|
|
2037
|
+
},
|
|
2038
|
+
flag_pickup: (context) => {
|
|
2039
|
+
var _a;
|
|
2040
|
+
const orderForm = context.orderForm;
|
|
2041
|
+
if (!orderForm) return null;
|
|
2042
|
+
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
2043
|
+
const hasPickup = logisticsInfo.some(
|
|
2044
|
+
(info) => {
|
|
2045
|
+
var _a2;
|
|
2046
|
+
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
2047
|
+
}
|
|
2048
|
+
);
|
|
2049
|
+
return hasPickup;
|
|
2050
|
+
},
|
|
2051
|
+
shippings: (context) => {
|
|
2052
|
+
if (!context.orderForm) return null;
|
|
2053
|
+
const { items, shippingData } = context.orderForm;
|
|
2054
|
+
const acc = {};
|
|
2055
|
+
shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
|
|
2056
|
+
const item = items[itemIndex];
|
|
2057
|
+
if (!item) return;
|
|
2058
|
+
slas.forEach((sla) => {
|
|
2059
|
+
if (!acc[sla.name]) acc[sla.name] = {
|
|
2060
|
+
shipping_tier: sla.name,
|
|
2061
|
+
delivery_time: parseInt(sla.shippingEstimate),
|
|
2062
|
+
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
2063
|
+
line_items: []
|
|
2064
|
+
};
|
|
2065
|
+
acc[sla.name].line_items.push(item.id);
|
|
2066
|
+
});
|
|
2067
|
+
});
|
|
2068
|
+
return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
|
|
2069
|
+
},
|
|
2070
|
+
shipping: (context) => {
|
|
2071
|
+
var _a, _b, _c;
|
|
2072
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
2073
|
+
return logistics.reduce((total, item) => {
|
|
2074
|
+
var _a2, _b2;
|
|
2075
|
+
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
2076
|
+
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
2077
|
+
}, 0);
|
|
2078
|
+
},
|
|
2079
|
+
shipping_tier: (context) => {
|
|
2080
|
+
var _a, _b, _c;
|
|
2081
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
2082
|
+
const selectedSlas = logistics.map((item) => {
|
|
2083
|
+
var _a2;
|
|
2084
|
+
if (!item.selectedSla) return null;
|
|
2085
|
+
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
2086
|
+
}).filter(Boolean);
|
|
2087
|
+
if (selectedSlas.length === 0) return null;
|
|
2088
|
+
const uniqueTiers = Array.from(
|
|
2089
|
+
new Map(
|
|
2090
|
+
selectedSlas.map((sla) => {
|
|
2091
|
+
var _a2;
|
|
2092
|
+
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
2093
|
+
return [key, sla];
|
|
2094
|
+
})
|
|
2095
|
+
).values()
|
|
2096
|
+
);
|
|
2097
|
+
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
2098
|
+
var _a2, _b2;
|
|
2099
|
+
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
2100
|
+
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
2101
|
+
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
2102
|
+
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
2103
|
+
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
2104
|
+
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
2105
|
+
});
|
|
2106
|
+
const shippingTier = sortedTiers.map((sla) => {
|
|
2107
|
+
var _a2;
|
|
2108
|
+
return sla.deliveryChannel === "pickup-in-point" ? `retirada em loja${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) ? `: ${sla.pickupStoreInfo.friendlyName}` : ""}` : sla.deliveryChannel === "delivery" ? `receba em casa${sla.name ? `: ${sla.name}` : ""}` : null;
|
|
2109
|
+
}).filter(Boolean).join(", ");
|
|
2110
|
+
return shippingTier || null;
|
|
2111
|
+
},
|
|
2112
|
+
transaction_id: (context) => {
|
|
2113
|
+
var _a, _b;
|
|
2114
|
+
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
2115
|
+
},
|
|
2116
|
+
coupon_message: (context) => {
|
|
2117
|
+
var _a;
|
|
2118
|
+
if (context.couponMessage) return context.couponMessage;
|
|
2119
|
+
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
2120
|
+
if (messages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
|
|
2121
|
+
const couponMessages = messages.filter((msg) => msg.text.toLowerCase().includes("cupom"));
|
|
2122
|
+
if (couponMessages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
|
|
2123
|
+
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
2124
|
+
},
|
|
2125
|
+
coupon: (context) => {
|
|
2126
|
+
var _a, _b;
|
|
2127
|
+
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
2128
|
+
},
|
|
2129
|
+
seller_cod_name: (context) => {
|
|
2130
|
+
return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
1965
2131
|
}
|
|
1966
2132
|
};
|
|
1967
2133
|
|
|
1968
2134
|
// src/formatter.ts
|
|
1969
2135
|
var adapters = {
|
|
1970
2136
|
DECO: decoAdapter,
|
|
2137
|
+
RESERVA: reservaAdapter,
|
|
1971
2138
|
HEADLESS: headlessAdapter,
|
|
1972
2139
|
PICKUP: pickupAdapter,
|
|
1973
|
-
ORDERFORM: orderFormAdapter
|
|
2140
|
+
ORDERFORM: orderFormAdapter,
|
|
2141
|
+
META: metaAdapter
|
|
1974
2142
|
};
|
|
1975
|
-
async function getParameters(context, eventName) {
|
|
2143
|
+
async function getParameters(context, eventName, config2) {
|
|
1976
2144
|
var _a;
|
|
1977
2145
|
const eventConfig = EVENTS[eventName];
|
|
1978
2146
|
if (!eventConfig) return;
|
|
@@ -1985,16 +2153,20 @@ async function getParameters(context, eventName) {
|
|
|
1985
2153
|
console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
|
|
1986
2154
|
return [param, null];
|
|
1987
2155
|
}
|
|
1988
|
-
return [param, await getter(context,
|
|
2156
|
+
return [param, await getter(context, config2)];
|
|
1989
2157
|
})
|
|
1990
2158
|
);
|
|
1991
2159
|
return Object.fromEntries(entries);
|
|
1992
2160
|
}
|
|
1993
2161
|
|
|
1994
2162
|
// src/index.ts
|
|
2163
|
+
var config = { brand: "", currency: "BRL" };
|
|
2164
|
+
function initTracker(c) {
|
|
2165
|
+
config = c;
|
|
2166
|
+
}
|
|
1995
2167
|
async function trackWebEvent(event, context) {
|
|
1996
2168
|
try {
|
|
1997
|
-
const parameters = await getParameters(context, event);
|
|
2169
|
+
const parameters = await getParameters(context, event, config);
|
|
1998
2170
|
if (isDebugMode()) {
|
|
1999
2171
|
console.log(`[DT v2] ${event}, context e parameters: `, {
|
|
2000
2172
|
context,
|
|
@@ -2016,6 +2188,7 @@ var src_default = {
|
|
|
2016
2188
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2017
2189
|
0 && (module.exports = {
|
|
2018
2190
|
EVENTS,
|
|
2191
|
+
initTracker,
|
|
2019
2192
|
trackWebEvent
|
|
2020
2193
|
});
|
|
2021
2194
|
//# sourceMappingURL=mod.cjs.map
|