@azzas/azzas-tracker-web 2.0.0-preview.1 → 2.0.0-preview.11

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 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", "line_items", "size", "item_ref"]
322
+ requiredParams: ["brand", "size", "item_ref"]
322
323
  },
323
324
  REFINE_RESULTS: {
324
325
  name: "refine_results",
@@ -1012,6 +1013,12 @@ var sortSizes = (sizes) => {
1012
1013
  return unique;
1013
1014
  };
1014
1015
  var capitalize = (str) => str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
1016
+ var resizeVtexImage2 = (url, width = 500, height = 500) => {
1017
+ return url == null ? void 0 : url.replace(
1018
+ /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1019
+ `$1-${width}-${height}/`
1020
+ );
1021
+ };
1015
1022
 
1016
1023
  // src/params/legacy/resolvers/paymentType/fromOrderForm.ts
1017
1024
  function paymentTypeFromOrderForm(context) {
@@ -1064,7 +1071,7 @@ var PROD_DOMAINS = {
1064
1071
  "store": "https://www.animale.com.br",
1065
1072
  "checkout": "https://secure.animale.com.br"
1066
1073
  },
1067
- "farm": {
1074
+ "lojafarm": {
1068
1075
  "store": "https://lojafarm.myvtex.com"
1069
1076
  },
1070
1077
  "mariafilo": {
@@ -1082,7 +1089,7 @@ var PROD_DOMAINS = {
1082
1089
  "bynv": {
1083
1090
  "store": "https://bynv.myvtex.com"
1084
1091
  },
1085
- "fabula": {
1092
+ "lojafabula": {
1086
1093
  "store": "https://lojafabula.myvtex.com"
1087
1094
  }
1088
1095
  };
@@ -1349,11 +1356,8 @@ var legacyGetters = {
1349
1356
  };
1350
1357
 
1351
1358
  // src/params/adapters/meta/index.ts
1352
- var metaAdapters = {
1359
+ var metaAdapter = {
1353
1360
  user_info: getUserInfo,
1354
- brand: (context) => {
1355
- return context.meta.brand || null;
1356
- },
1357
1361
  content_type: (context) => {
1358
1362
  return context.meta.content_type || null;
1359
1363
  },
@@ -1363,8 +1367,8 @@ var metaAdapters = {
1363
1367
  pre_filled: (context) => {
1364
1368
  return !!context.preFilled;
1365
1369
  },
1366
- currency: (context) => {
1367
- if (context == null ? void 0 : context.currency) return context.currency;
1370
+ currency: (_, config2) => {
1371
+ if (config2 == null ? void 0 : config2.currency) return config2.currency;
1368
1372
  return "BRL";
1369
1373
  },
1370
1374
  slot_per_line: (context) => {
@@ -1389,17 +1393,14 @@ var metaAdapters = {
1389
1393
  creative_slot: (context) => {
1390
1394
  return context.meta.creative_slot || null;
1391
1395
  },
1392
- size: (context) => {
1393
- return context.size || null;
1394
- },
1395
1396
  item_ref: (context) => {
1396
- return context.itemRef || null;
1397
+ return context.meta.item_ref || null;
1397
1398
  },
1398
1399
  method: (context) => {
1399
- return context.method || null;
1400
+ return context.meta.method || null;
1400
1401
  },
1401
1402
  type: (context) => {
1402
- return context.type || null;
1403
+ return context.meta.type || null;
1403
1404
  },
1404
1405
  color: (context) => {
1405
1406
  return context.meta.color || null;
@@ -1412,9 +1413,45 @@ var metaAdapters = {
1412
1413
  },
1413
1414
  ordering: (context) => {
1414
1415
  return context.meta.ordering || null;
1416
+ },
1417
+ size: (context) => {
1418
+ return context.meta.size || null;
1415
1419
  }
1416
1420
  };
1417
1421
 
1422
+ // src/core/farm.ts
1423
+ var BRAND_CODES2 = {
1424
+ farm: "farmrio",
1425
+ "farm etc": "farmetc",
1426
+ "farm rio": "farmrio"
1427
+ };
1428
+ function getBrandCode2(brand) {
1429
+ if (!brand) return null;
1430
+ const standardized = brand.toLowerCase().trim();
1431
+ return BRAND_CODES2[standardized] || null;
1432
+ }
1433
+ function normalizeBrand2(input) {
1434
+ var _a;
1435
+ let brandStrings = [];
1436
+ if (Array.isArray(input) && input.every((item) => typeof item === "string")) {
1437
+ brandStrings = input;
1438
+ } else if (Array.isArray(input)) {
1439
+ brandStrings = input.map((item) => {
1440
+ var _a2;
1441
+ return ((_a2 = item.additionalInfo) == null ? void 0 : _a2.brandName) || item.brand;
1442
+ });
1443
+ } else if (typeof input === "object" && input !== null && "brand" in input) {
1444
+ brandStrings = [((_a = input.additionalInfo) == null ? void 0 : _a.brandName) || input.brand];
1445
+ } else if (typeof input === "string") {
1446
+ return getBrandCode2(input);
1447
+ } else {
1448
+ return null;
1449
+ }
1450
+ const brandCodes = brandStrings.map(getBrandCode2).filter((code) => code !== null);
1451
+ const uniqueSortedCodes = [...new Set(brandCodes)].sort();
1452
+ return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
1453
+ }
1454
+
1418
1455
  // src/params/adapters/deco/utils.ts
1419
1456
  var getItemCategory3 = (item) => {
1420
1457
  var _a;
@@ -1433,27 +1470,18 @@ var getItemCategory22 = (item) => {
1433
1470
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1434
1471
  return capitalize(deepest);
1435
1472
  };
1436
- var resizeVtexImage2 = (url, width = 500, height = 500) => {
1437
- return url == null ? void 0 : url.replace(
1438
- /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1439
- `$1-${width}-${height}/`
1440
- );
1441
- };
1442
- function getItemShippingTier2() {
1443
- return null;
1444
- }
1445
1473
 
1446
1474
  // src/params/adapters/deco/index.ts
1447
1475
  var IN_STOCK_SCHEMA = "https://schema.org/InStock";
1448
1476
  var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
1449
1477
  var decoAdapter = {
1450
- ...metaAdapters,
1478
+ ...metaAdapter,
1451
1479
  // global adapters
1452
1480
  items: (context) => {
1453
1481
  if (context == null ? void 0 : context.items) return context.items;
1454
1482
  if (context == null ? void 0 : context.products) {
1455
1483
  return context.products.map((item) => {
1456
- 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;
1484
+ 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;
1457
1485
  const COLOR_REGEX = /^[^_]+_/;
1458
1486
  const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
1459
1487
  (s) => s.priceType === LIST_PRICE_SCHEMA
@@ -1464,33 +1492,37 @@ var decoAdapter = {
1464
1492
  item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
1465
1493
  item_name: (_h = item.alternateName) != null ? _h : null,
1466
1494
  price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
1467
- discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
1495
+ discount: Math.round((Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice)) * 100) / 100,
1468
1496
  item_variant: ((_m = (_l = item == null ? void 0 : item.name) == null ? void 0 : _l.split(" - ")[0]) == null ? void 0 : _m.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
1469
1497
  // cor
1470
1498
  item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
1471
1499
  // tamanho
1472
- item_shipping_tier: getItemShippingTier2(),
1473
- item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
1474
- item_category: (_s = getItemCategory3(item)) != null ? _s : null,
1475
- item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
1476
- item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
1477
- item_sku: (_v = item.sku) != null ? _v : null,
1478
- item_url: (_w = item.url) != null ? _w : null,
1479
- image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
1480
- seller_id: (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) != null ? _C : null,
1481
- item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
1500
+ item_shipping_tier: "",
1501
+ 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,
1502
+ item_category: (_t = getItemCategory3(item)) != null ? _t : null,
1503
+ item_category2: (_u = getItemCategory22(item)) != null ? _u : null,
1504
+ item_id: (_v = item == null ? void 0 : item.inProductGroupWithID) != null ? _v : null,
1505
+ item_sku: (_w = item.sku) != null ? _w : null,
1506
+ item_url: (_x = item.url) != null ? _x : null,
1507
+ image_url: (_z = resizeVtexImage2((_y = item == null ? void 0 : item.image) == null ? void 0 : _y[0].url)) != null ? _z : null,
1508
+ seller_id: (_D = (_C = (_B = (_A = item.offers) == null ? void 0 : _A.offers) == null ? void 0 : _B[0]) == null ? void 0 : _C.seller) != null ? _D : null,
1509
+ item_list_name: (_E = item == null ? void 0 : item.item_list_name) != null ? _E : null
1482
1510
  };
1483
1511
  });
1484
1512
  }
1485
1513
  return null;
1486
1514
  },
1487
- // brand: (context: DecoBrandContext) => {
1488
- // if (context?.brand) return context.brand
1489
- // if (context?.products) {
1490
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1491
- // }
1492
- // return null
1493
- // },
1515
+ brand: (context, config2) => {
1516
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1517
+ if (context == null ? void 0 : context.brand) return context.brand;
1518
+ if (context == null ? void 0 : context.products) {
1519
+ return normalizeBrand2(context.products.map((p) => {
1520
+ var _a;
1521
+ return (_a = p == null ? void 0 : p.brand) == null ? void 0 : _a.name;
1522
+ }));
1523
+ }
1524
+ return null;
1525
+ },
1494
1526
  line_items: (context) => {
1495
1527
  if (context == null ? void 0 : context.line_items) return context.line_items;
1496
1528
  if (context == null ? void 0 : context.products) {
@@ -1532,135 +1564,6 @@ var decoAdapter = {
1532
1564
  }
1533
1565
  };
1534
1566
 
1535
- // src/params/adapters/orderForm/index.ts
1536
- var orderFormAdapters = {
1537
- // orderform
1538
- payment_type: getPaymentType,
1539
- total_discount: (context) => {
1540
- var _a, _b;
1541
- if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
1542
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1543
- const items = context.orderForm.items;
1544
- const totalDiscount = items.reduce((acc, item) => {
1545
- const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1546
- return acc + unitDiscount * item.quantity;
1547
- }, 0);
1548
- const discounts = totalsList.find((t) => t.id === "Discounts");
1549
- return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1550
- },
1551
- subtotal: (context) => {
1552
- var _a, _b;
1553
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1554
- const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1555
- return subtotal;
1556
- },
1557
- coupon_message: (context) => {
1558
- var _a;
1559
- if (context.couponMessage) return context.couponMessage;
1560
- const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1561
- if (messages.length === 0) return null;
1562
- const couponMessages = messages.filter(
1563
- (msg) => msg.text.toLowerCase().includes("cupom")
1564
- );
1565
- if (couponMessages.length === 0) return null;
1566
- return couponMessages.map((msg) => msg.text).join(" | ");
1567
- },
1568
- flag_pickup: (context) => {
1569
- var _a;
1570
- const orderForm = context.orderForm;
1571
- if (!orderForm) return null;
1572
- const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1573
- const hasPickup = logisticsInfo.some(
1574
- (info) => {
1575
- var _a2;
1576
- return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1577
- }
1578
- );
1579
- return hasPickup;
1580
- },
1581
- shippings: (context) => {
1582
- const orderForm = context.orderForm;
1583
- if (!orderForm) return null;
1584
- const groupShipping = {};
1585
- for (const info of orderForm.shippingData.logisticsInfo) {
1586
- const item = orderForm.items[info.itemIndex];
1587
- if (!item) continue;
1588
- for (const sla of info.slas) {
1589
- const key = sla.name;
1590
- if (!groupShipping[key]) {
1591
- groupShipping[key] = {
1592
- shipping_tier: sla.name,
1593
- delivery_time: parseInt(sla.shippingEstimate),
1594
- shipping: parseFloat((sla.price / 100).toFixed(1)),
1595
- line_items: []
1596
- };
1597
- }
1598
- groupShipping[key].line_items.push(item.id);
1599
- }
1600
- }
1601
- const shippings = Object.values(groupShipping).map((s) => ({
1602
- shipping: s.shipping,
1603
- shipping_tier: s.shipping_tier,
1604
- delivery_time: s.delivery_time,
1605
- line_items: s.line_items.join(",")
1606
- }));
1607
- return shippings || null;
1608
- },
1609
- shipping: (context) => {
1610
- var _a, _b, _c;
1611
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1612
- return logistics.reduce((total, item) => {
1613
- var _a2, _b2;
1614
- const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1615
- return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1616
- }, 0);
1617
- },
1618
- shipping_tier: (context) => {
1619
- var _a, _b, _c;
1620
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1621
- const selectedSlas = logistics.map((item) => {
1622
- var _a2;
1623
- if (!item.selectedSla) return null;
1624
- return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1625
- }).filter(Boolean);
1626
- if (selectedSlas.length === 0) return null;
1627
- const uniqueTiers = Array.from(
1628
- new Map(
1629
- selectedSlas.map((sla) => {
1630
- var _a2;
1631
- const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1632
- return [key, sla];
1633
- })
1634
- ).values()
1635
- );
1636
- const sortedTiers = uniqueTiers.sort((a, b) => {
1637
- var _a2, _b2;
1638
- const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1639
- const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1640
- if (aOrder !== bOrder) return aOrder - bOrder;
1641
- const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1642
- const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1643
- return aLabel.localeCompare(bLabel, "pt-BR");
1644
- });
1645
- const shippingTier = sortedTiers.map((sla) => {
1646
- var _a2;
1647
- 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;
1648
- }).filter(Boolean).join(", ");
1649
- return shippingTier || null;
1650
- },
1651
- transaction_id: (context) => {
1652
- var _a, _b;
1653
- return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1654
- },
1655
- coupon: (context) => {
1656
- var _a, _b;
1657
- return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1658
- },
1659
- seller_cod_name: (context) => {
1660
- return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1661
- }
1662
- };
1663
-
1664
1567
  // src/params/adapters/headless/utils.ts
1665
1568
  var getItemCategory5 = (item) => {
1666
1569
  const keywords = ["outlet", "bazar", "sale"];
@@ -1683,12 +1586,6 @@ var getItemCategory23 = (item) => {
1683
1586
  const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
1684
1587
  return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
1685
1588
  };
1686
- function resizeVtexImage3(url, width = 500, height = 500) {
1687
- return url == null ? void 0 : url.replace(
1688
- /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1689
- `$1-${width}-${height}/`
1690
- );
1691
- }
1692
1589
 
1693
1590
  // src/params/adapters/headless/zones/PDP.ts
1694
1591
  var HeadlessPdpZone = {
@@ -1705,6 +1602,7 @@ var HeadlessPdpZone = {
1705
1602
  item_brand: (_d = item.brand) != null ? _d : null,
1706
1603
  item_name: (_e = item.productName) != null ? _e : null,
1707
1604
  price: price != null ? price : null,
1605
+ item_shipping_tier: null,
1708
1606
  discount: Number(listPrice) - Number(price),
1709
1607
  item_variant: (_h = (_g = (_f = item.items[0]) == null ? void 0 : _f.name) == null ? void 0 : _g.split(" - ")[0]) != null ? _h : null,
1710
1608
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
@@ -1716,7 +1614,7 @@ var HeadlessPdpZone = {
1716
1614
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1717
1615
  item_url: (_q = item.link) != null ? _q : null,
1718
1616
  // sem link/url no retorno do IS na multi-lib produtos PDC
1719
- image_url: (_t = resizeVtexImage3((_s = (_r = item == null ? void 0 : item.items) == null ? void 0 : _r[0].images) == null ? void 0 : _s[0].imageUrl)) != null ? _t : null,
1617
+ image_url: (_t = resizeVtexImage2((_s = (_r = item == null ? void 0 : item.items) == null ? void 0 : _r[0].images) == null ? void 0 : _s[0].imageUrl)) != null ? _t : null,
1720
1618
  seller_id: (_x = (_w = (_v = (_u = item.items) == null ? void 0 : _u[0]) == null ? void 0 : _v.sellers) == null ? void 0 : _w[0].sellerId) != null ? _x : null,
1721
1619
  item_list_name: (_y = item.item_list_name) != null ? _y : null
1722
1620
  };
@@ -1741,7 +1639,8 @@ var HeadlessPdpZone = {
1741
1639
  }
1742
1640
  return null;
1743
1641
  },
1744
- brand: (context) => {
1642
+ brand: (context, config2) => {
1643
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1745
1644
  if (context == null ? void 0 : context.brand) return context.brand;
1746
1645
  if (context == null ? void 0 : context.products) {
1747
1646
  return context.products.map((p) => p.brand).join().trim();
@@ -1765,6 +1664,7 @@ var HeadlessPdcZone = {
1765
1664
  item_brand: (_b = item.brand.name) != null ? _b : null,
1766
1665
  item_name: (_c = item.name) != null ? _c : null,
1767
1666
  price: price != null ? price : null,
1667
+ item_shipping_tier: null,
1768
1668
  discount: Number(listPrice) - Number(price),
1769
1669
  item_variant: (_f = (_e = (_d = item.isVariantOf) == null ? void 0 : _d.hasVariant) == null ? void 0 : _e[0].name.split(" - ")[0]) != null ? _f : null,
1770
1670
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
@@ -1776,7 +1676,7 @@ var HeadlessPdcZone = {
1776
1676
  item_sku: (_l = item.sku) != null ? _l : null,
1777
1677
  item_url: null,
1778
1678
  // sem link/url no retorno do IS na multi-lib produtos PDC
1779
- image_url: (_n = resizeVtexImage3((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
1679
+ image_url: (_n = resizeVtexImage2((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
1780
1680
  seller_id: (_s = (_r = (_q = (_p = (_o = item.offers) == null ? void 0 : _o.offers) == null ? void 0 : _p.find((o) => o.availability)) == null ? void 0 : _q.seller) == null ? void 0 : _r.identifier) != null ? _s : null,
1781
1681
  item_list_name: (_t = item.item_list_name) != null ? _t : null
1782
1682
  };
@@ -1798,7 +1698,8 @@ var HeadlessPdcZone = {
1798
1698
  }
1799
1699
  return null;
1800
1700
  },
1801
- brand: (context) => {
1701
+ brand: (context, config2) => {
1702
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1802
1703
  if (context == null ? void 0 : context.brand) return context.brand;
1803
1704
  if (context == null ? void 0 : context.products) {
1804
1705
  return context.products.map((p) => p.brand.name).join().trim();
@@ -1809,16 +1710,14 @@ var HeadlessPdcZone = {
1809
1710
 
1810
1711
  // src/params/adapters/headless/index.ts
1811
1712
  var headlessAdapter = {
1812
- ...metaAdapters,
1713
+ ...metaAdapter,
1813
1714
  // global adapters
1814
- ...orderFormAdapters,
1815
- // orderForm adapters, confirmar se no storefront tem evento que usa essses params
1816
- brand: (context) => {
1715
+ brand: (context, config2) => {
1817
1716
  if (context.zone === "PDP") {
1818
- return HeadlessPdpZone.brand(context);
1717
+ return HeadlessPdpZone.brand(context, config2);
1819
1718
  }
1820
1719
  if (context.zone === "PDC") {
1821
- return HeadlessPdcZone.brand(context);
1720
+ return HeadlessPdcZone.brand(context, config2);
1822
1721
  }
1823
1722
  return null;
1824
1723
  },
@@ -1879,7 +1778,7 @@ var getDeliveryTime = (sla) => {
1879
1778
 
1880
1779
  // src/params/adapters/pickup/index.ts
1881
1780
  var pickupAdapter = {
1882
- ...metaAdapters,
1781
+ ...metaAdapter,
1883
1782
  flag_pickup: (context) => {
1884
1783
  var _a;
1885
1784
  return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
@@ -1887,10 +1786,10 @@ var pickupAdapter = {
1887
1786
  shippings: (context) => {
1888
1787
  if (context.shippings) {
1889
1788
  return context.shippings.map((s) => {
1890
- var _a, _b;
1789
+ var _a;
1891
1790
  return {
1892
1791
  line_items: (_a = s.line_items) != null ? _a : "",
1893
- shipping: (_b = s.price) != null ? _b : 0,
1792
+ shipping: s.price / 100,
1894
1793
  shipping_tier: getShippingTier(s),
1895
1794
  delivery_time: getDeliveryTime(s)
1896
1795
  };
@@ -1898,9 +1797,217 @@ var pickupAdapter = {
1898
1797
  }
1899
1798
  return null;
1900
1799
  },
1800
+ brand: (context, config2) => {
1801
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1802
+ if (context == null ? void 0 : context.brand) return context.brand;
1803
+ return null;
1804
+ },
1901
1805
  zipcode: (context) => {
1902
1806
  var _a;
1903
- return (_a = context.zipcode) != null ? _a : null;
1807
+ return (_a = context.meta.zipcode) != null ? _a : null;
1808
+ }
1809
+ };
1810
+
1811
+ // src/params/adapters/orderForm/utils.ts
1812
+ var getItemCategory6 = (item) => {
1813
+ var _a;
1814
+ const categories = item == null ? void 0 : item.productCategories;
1815
+ if (!categories) return "Cole\xE7\xE3o";
1816
+ const text = Object.values(categories).join(" ");
1817
+ const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1818
+ return match != null ? match : "Cole\xE7\xE3o";
1819
+ };
1820
+ var getItemCategory24 = (item) => {
1821
+ var _a, _b;
1822
+ const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1823
+ const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1824
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1825
+ const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1826
+ return capitalize(deepest);
1827
+ };
1828
+ function getItemShippingTier2(orderForm, item) {
1829
+ var _a, _b, _c, _d;
1830
+ const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1831
+ (li) => li.itemId === item.id
1832
+ );
1833
+ const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1834
+ 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;
1835
+ }
1836
+ var getOrderFormItems = (orderForm) => {
1837
+ const idSelected = orderForm == null ? void 0 : orderForm.selected;
1838
+ return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1839
+ };
1840
+
1841
+ // src/params/adapters/orderForm/index.ts
1842
+ var orderFormAdapter = {
1843
+ ...metaAdapter,
1844
+ items: (context) => {
1845
+ if (context == null ? void 0 : context.items) return context.items;
1846
+ if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1847
+ return getOrderFormItems(context.orderForm).map((item, index) => {
1848
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1849
+ return {
1850
+ quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1851
+ index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1852
+ item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1853
+ item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1854
+ price: (item == null ? void 0 : item.price) / 100,
1855
+ discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1856
+ item_variant: (_k = (_j = (_i = (_h = item == null ? void 0 : item.skuName) == null ? void 0 : _h.split(" - ")[0]) == null ? void 0 : _i.split("_").pop()) == null ? void 0 : _j.trim()) != null ? _k : null,
1857
+ item_variant2: (_n = (_m = (_l = item == null ? void 0 : item.skuName) == null ? void 0 : _l.split(" - ")[1]) == null ? void 0 : _m.trim()) != null ? _n : null,
1858
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1859
+ item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1860
+ item_category: (_o = getItemCategory6(item)) != null ? _o : null,
1861
+ item_category2: (_p = getItemCategory24(item)) != null ? _p : null,
1862
+ item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1863
+ item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1864
+ item_url: (_s = item.detailUrl) != null ? _s : null,
1865
+ image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1866
+ seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1867
+ item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1868
+ };
1869
+ });
1870
+ }
1871
+ return null;
1872
+ },
1873
+ brand: (context, config2) => {
1874
+ var _a;
1875
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1876
+ if (context == null ? void 0 : context.brand) return context.brand;
1877
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1878
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1879
+ return normalizeBrand2(brands);
1880
+ },
1881
+ line_items: (context) => {
1882
+ var _a;
1883
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1884
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1885
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1886
+ },
1887
+ value: (context) => {
1888
+ var _a;
1889
+ if (context == null ? void 0 : context.value) return context.value;
1890
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1891
+ return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.price) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1892
+ },
1893
+ payment_type: getPaymentType,
1894
+ total_discount: (context) => {
1895
+ var _a, _b;
1896
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1897
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1898
+ const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1899
+ const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1900
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1901
+ return acc + unitDiscount * item.quantity;
1902
+ }, 0);
1903
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1904
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1905
+ },
1906
+ subtotal: (context) => {
1907
+ var _a, _b;
1908
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1909
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1910
+ return subtotal;
1911
+ },
1912
+ coupon_message: (context) => {
1913
+ var _a;
1914
+ if (context.couponMessage) return context.couponMessage;
1915
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1916
+ if (messages.length === 0) return null;
1917
+ const couponMessages = messages.filter(
1918
+ (msg) => msg.text.toLowerCase().includes("cupom")
1919
+ );
1920
+ if (couponMessages.length === 0) return null;
1921
+ return couponMessages.map((msg) => msg.text).join(" | ");
1922
+ },
1923
+ zipcode: (context) => {
1924
+ var _a;
1925
+ return (_a = context.meta.zipcode) != null ? _a : null;
1926
+ },
1927
+ flag_pickup: (context) => {
1928
+ var _a;
1929
+ const orderForm = context.orderForm;
1930
+ if (!orderForm) return null;
1931
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1932
+ const hasPickup = logisticsInfo.some(
1933
+ (info) => {
1934
+ var _a2;
1935
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1936
+ }
1937
+ );
1938
+ return hasPickup;
1939
+ },
1940
+ shippings: (context) => {
1941
+ if (!context.orderForm) return null;
1942
+ const { items, shippingData } = context.orderForm;
1943
+ const acc = {};
1944
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1945
+ const item = items[itemIndex];
1946
+ if (!item) return;
1947
+ slas.forEach((sla) => {
1948
+ if (!acc[sla.name]) acc[sla.name] = {
1949
+ shipping_tier: sla.name,
1950
+ delivery_time: parseInt(sla.shippingEstimate),
1951
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1952
+ line_items: []
1953
+ };
1954
+ acc[sla.name].line_items.push(item.id);
1955
+ });
1956
+ });
1957
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1958
+ },
1959
+ shipping: (context) => {
1960
+ var _a, _b, _c;
1961
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1962
+ return logistics.reduce((total, item) => {
1963
+ var _a2, _b2;
1964
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1965
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1966
+ }, 0);
1967
+ },
1968
+ shipping_tier: (context) => {
1969
+ var _a, _b, _c;
1970
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1971
+ const selectedSlas = logistics.map((item) => {
1972
+ var _a2;
1973
+ if (!item.selectedSla) return null;
1974
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1975
+ }).filter(Boolean);
1976
+ if (selectedSlas.length === 0) return null;
1977
+ const uniqueTiers = Array.from(
1978
+ new Map(
1979
+ selectedSlas.map((sla) => {
1980
+ var _a2;
1981
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1982
+ return [key, sla];
1983
+ })
1984
+ ).values()
1985
+ );
1986
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1987
+ var _a2, _b2;
1988
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1989
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1990
+ if (aOrder !== bOrder) return aOrder - bOrder;
1991
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1992
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1993
+ return aLabel.localeCompare(bLabel, "pt-BR");
1994
+ });
1995
+ const shippingTier = sortedTiers.map((sla) => {
1996
+ var _a2;
1997
+ 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;
1998
+ }).filter(Boolean).join(", ");
1999
+ return shippingTier || null;
2000
+ },
2001
+ transaction_id: (context) => {
2002
+ var _a, _b;
2003
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
2004
+ },
2005
+ coupon: (context) => {
2006
+ var _a, _b;
2007
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
2008
+ },
2009
+ seller_cod_name: (context) => {
2010
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1904
2011
  }
1905
2012
  };
1906
2013
 
@@ -1908,9 +2015,11 @@ var pickupAdapter = {
1908
2015
  var adapters = {
1909
2016
  DECO: decoAdapter,
1910
2017
  HEADLESS: headlessAdapter,
1911
- PICKUP: pickupAdapter
2018
+ PICKUP: pickupAdapter,
2019
+ ORDERFORM: orderFormAdapter,
2020
+ META: metaAdapter
1912
2021
  };
1913
- async function getParameters(context, eventName) {
2022
+ async function getParameters(context, eventName, config2) {
1914
2023
  var _a;
1915
2024
  const eventConfig = EVENTS[eventName];
1916
2025
  if (!eventConfig) return;
@@ -1923,16 +2032,20 @@ async function getParameters(context, eventName) {
1923
2032
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
1924
2033
  return [param, null];
1925
2034
  }
1926
- return [param, await getter(context, eventName)];
2035
+ return [param, await getter(context, config2)];
1927
2036
  })
1928
2037
  );
1929
2038
  return Object.fromEntries(entries);
1930
2039
  }
1931
2040
 
1932
2041
  // src/index.ts
2042
+ var config = { brand: "", currency: "BRL" };
2043
+ function initTracker(c) {
2044
+ config = c;
2045
+ }
1933
2046
  async function trackWebEvent(event, context) {
1934
2047
  try {
1935
- const parameters = await getParameters(context, event);
2048
+ const parameters = await getParameters(context, event, config);
1936
2049
  if (isDebugMode()) {
1937
2050
  console.log(`[DT v2] ${event}, context e parameters: `, {
1938
2051
  context,
@@ -1954,6 +2067,7 @@ var src_default = {
1954
2067
  // Annotate the CommonJS export names for ESM import in node:
1955
2068
  0 && (module.exports = {
1956
2069
  EVENTS,
2070
+ initTracker,
1957
2071
  trackWebEvent
1958
2072
  });
1959
2073
  //# sourceMappingURL=mod.cjs.map