@azzas/azzas-tracker-web 2.0.0-preview.5 → 2.0.0-preview.7

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.js CHANGED
@@ -1329,9 +1329,6 @@ var legacyGetters = {
1329
1329
  // src/params/adapters/meta/index.ts
1330
1330
  var metaAdapters = {
1331
1331
  user_info: getUserInfo,
1332
- // brand: (context: MetaBrandContext) => {
1333
- // return context.meta.brand || null;
1334
- // },
1335
1332
  content_type: (context) => {
1336
1333
  return context.meta.content_type || null;
1337
1334
  },
@@ -1341,8 +1338,8 @@ var metaAdapters = {
1341
1338
  pre_filled: (context) => {
1342
1339
  return !!context.preFilled;
1343
1340
  },
1344
- currency: (context) => {
1345
- if (context == null ? void 0 : context.currency) return context.currency;
1341
+ currency: (_, config2) => {
1342
+ if (config2 == null ? void 0 : config2.currency) return config2.currency;
1346
1343
  return "BRL";
1347
1344
  },
1348
1345
  slot_per_line: (context) => {
@@ -1484,7 +1481,8 @@ var decoAdapter = {
1484
1481
  }
1485
1482
  return null;
1486
1483
  },
1487
- brand: (context) => {
1484
+ brand: (context, config2) => {
1485
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1488
1486
  if (context == null ? void 0 : context.brand) return context.brand;
1489
1487
  if (context == null ? void 0 : context.products) {
1490
1488
  return normalizeBrand2(context.products.map((p) => {
@@ -1535,210 +1533,8 @@ var decoAdapter = {
1535
1533
  }
1536
1534
  };
1537
1535
 
1538
- // src/params/adapters/orderForm/utils.ts
1539
- var getItemCategory5 = (item) => {
1540
- var _a;
1541
- const categories = item == null ? void 0 : item.productCategories;
1542
- if (!categories) return "Cole\xE7\xE3o";
1543
- const text = Object.values(categories).join(" ");
1544
- const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1545
- return match != null ? match : "Cole\xE7\xE3o";
1546
- };
1547
- var getItemCategory23 = (item) => {
1548
- var _a, _b;
1549
- const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1550
- const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1551
- const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1552
- const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1553
- return capitalize(deepest);
1554
- };
1555
- function getItemShippingTier2(orderForm, item) {
1556
- var _a, _b, _c, _d;
1557
- const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1558
- (li) => li.itemId === item.id
1559
- );
1560
- const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1561
- 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;
1562
- }
1563
- var getOrderFormItems = (orderForm) => {
1564
- const idSelected = orderForm == null ? void 0 : orderForm.selected;
1565
- return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1566
- };
1567
-
1568
- // src/params/adapters/orderForm/index.ts
1569
- var orderFormAdapter = {
1570
- ...metaAdapters,
1571
- items: (context) => {
1572
- if (context == null ? void 0 : context.items) return context.items;
1573
- if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1574
- return getOrderFormItems(context.orderForm).map((item, index) => {
1575
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1576
- return {
1577
- quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1578
- index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1579
- item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1580
- item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1581
- price: (item == null ? void 0 : item.price) / 100,
1582
- discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1583
- 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,
1584
- 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,
1585
- item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1586
- item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1587
- item_category: (_o = getItemCategory5(item)) != null ? _o : null,
1588
- item_category2: (_p = getItemCategory23(item)) != null ? _p : null,
1589
- item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1590
- item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1591
- item_url: (_s = item.detailUrl) != null ? _s : null,
1592
- image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1593
- seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1594
- item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1595
- };
1596
- });
1597
- }
1598
- return null;
1599
- },
1600
- brand: (context) => {
1601
- var _a;
1602
- if (context == null ? void 0 : context.brand) return context.brand;
1603
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1604
- const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1605
- return normalizeBrand2(brands);
1606
- },
1607
- line_items: (context) => {
1608
- var _a;
1609
- if (context == null ? void 0 : context.line_items) return context.line_items;
1610
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1611
- return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1612
- },
1613
- value: (context) => {
1614
- var _a;
1615
- if (context == null ? void 0 : context.value) return context.value;
1616
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1617
- 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);
1618
- },
1619
- payment_type: getPaymentType,
1620
- total_discount: (context) => {
1621
- var _a, _b;
1622
- if (context == null ? void 0 : context.total_discount) return context.total_discount;
1623
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1624
- const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1625
- const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1626
- const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1627
- return acc + unitDiscount * item.quantity;
1628
- }, 0);
1629
- const discounts = totalsList.find((t) => t.id === "Discounts");
1630
- return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1631
- },
1632
- subtotal: (context) => {
1633
- var _a, _b;
1634
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1635
- const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1636
- return subtotal;
1637
- },
1638
- coupon_message: (context) => {
1639
- var _a;
1640
- if (context.couponMessage) return context.couponMessage;
1641
- const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1642
- if (messages.length === 0) return null;
1643
- const couponMessages = messages.filter(
1644
- (msg) => msg.text.toLowerCase().includes("cupom")
1645
- );
1646
- if (couponMessages.length === 0) return null;
1647
- return couponMessages.map((msg) => msg.text).join(" | ");
1648
- },
1649
- zipcode: (context) => {
1650
- var _a;
1651
- return (_a = context.zipcode) != null ? _a : null;
1652
- },
1653
- flag_pickup: (context) => {
1654
- var _a;
1655
- const orderForm = context.orderForm;
1656
- if (!orderForm) return null;
1657
- const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1658
- const hasPickup = logisticsInfo.some(
1659
- (info) => {
1660
- var _a2;
1661
- return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1662
- }
1663
- );
1664
- return hasPickup;
1665
- },
1666
- shippings: (context) => {
1667
- if (!context.orderForm) return null;
1668
- const { items, shippingData } = context.orderForm;
1669
- const acc = {};
1670
- shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1671
- const item = items[itemIndex];
1672
- if (!item) return;
1673
- slas.forEach((sla) => {
1674
- if (!acc[sla.name]) acc[sla.name] = {
1675
- shipping_tier: sla.name,
1676
- delivery_time: parseInt(sla.shippingEstimate),
1677
- shipping: parseFloat((sla.price / 100).toFixed(1)),
1678
- line_items: []
1679
- };
1680
- acc[sla.name].line_items.push(item.id);
1681
- });
1682
- });
1683
- return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1684
- },
1685
- shipping: (context) => {
1686
- var _a, _b, _c;
1687
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1688
- return logistics.reduce((total, item) => {
1689
- var _a2, _b2;
1690
- const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1691
- return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1692
- }, 0);
1693
- },
1694
- shipping_tier: (context) => {
1695
- var _a, _b, _c;
1696
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1697
- const selectedSlas = logistics.map((item) => {
1698
- var _a2;
1699
- if (!item.selectedSla) return null;
1700
- return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1701
- }).filter(Boolean);
1702
- if (selectedSlas.length === 0) return null;
1703
- const uniqueTiers = Array.from(
1704
- new Map(
1705
- selectedSlas.map((sla) => {
1706
- var _a2;
1707
- const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1708
- return [key, sla];
1709
- })
1710
- ).values()
1711
- );
1712
- const sortedTiers = uniqueTiers.sort((a, b) => {
1713
- var _a2, _b2;
1714
- const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1715
- const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1716
- if (aOrder !== bOrder) return aOrder - bOrder;
1717
- const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1718
- const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1719
- return aLabel.localeCompare(bLabel, "pt-BR");
1720
- });
1721
- const shippingTier = sortedTiers.map((sla) => {
1722
- var _a2;
1723
- 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;
1724
- }).filter(Boolean).join(", ");
1725
- return shippingTier || null;
1726
- },
1727
- transaction_id: (context) => {
1728
- var _a, _b;
1729
- return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1730
- },
1731
- coupon: (context) => {
1732
- var _a, _b;
1733
- return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1734
- },
1735
- seller_cod_name: (context) => {
1736
- return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1737
- }
1738
- };
1739
-
1740
1536
  // src/params/adapters/headless/utils.ts
1741
- var getItemCategory6 = (item) => {
1537
+ var getItemCategory5 = (item) => {
1742
1538
  const keywords = ["outlet", "bazar", "sale"];
1743
1539
  const regex = new RegExp(keywords.join("|"), "i");
1744
1540
  const value = item == null ? void 0 : item.categories;
@@ -1751,7 +1547,7 @@ var getItemCategory6 = (item) => {
1751
1547
  }
1752
1548
  return "Cole\xE7\xE3o";
1753
1549
  };
1754
- var getItemCategory24 = (item) => {
1550
+ var getItemCategory23 = (item) => {
1755
1551
  var _a, _b, _c;
1756
1552
  const avoidList = /outlet|bazar|sale/i;
1757
1553
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1781,8 +1577,8 @@ var HeadlessPdpZone = {
1781
1577
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1782
1578
  item_ref: (_l = item.productReference) != null ? _l : null,
1783
1579
  // sem ref no retorno do IS na multi-lib produtos PDC
1784
- item_category: getItemCategory6(item),
1785
- item_category2: (_m = getItemCategory24(item)) != null ? _m : null,
1580
+ item_category: getItemCategory5(item),
1581
+ item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
1786
1582
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1787
1583
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1788
1584
  item_url: (_q = item.link) != null ? _q : null,
@@ -1812,7 +1608,8 @@ var HeadlessPdpZone = {
1812
1608
  }
1813
1609
  return null;
1814
1610
  },
1815
- brand: (context) => {
1611
+ brand: (context, config2) => {
1612
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1816
1613
  if (context == null ? void 0 : context.brand) return context.brand;
1817
1614
  if (context == null ? void 0 : context.products) {
1818
1615
  return context.products.map((p) => p.brand).join().trim();
@@ -1842,8 +1639,8 @@ var HeadlessPdcZone = {
1842
1639
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1843
1640
  item_ref: null,
1844
1641
  // sem ref no retorno do IS na multi-lib produtos PDC
1845
- item_category: getItemCategory6(item),
1846
- item_category2: (_j = getItemCategory24(item)) != null ? _j : null,
1642
+ item_category: getItemCategory5(item),
1643
+ item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
1847
1644
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1848
1645
  item_sku: (_l = item.sku) != null ? _l : null,
1849
1646
  item_url: null,
@@ -1870,7 +1667,8 @@ var HeadlessPdcZone = {
1870
1667
  }
1871
1668
  return null;
1872
1669
  },
1873
- brand: (context) => {
1670
+ brand: (context, config2) => {
1671
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1874
1672
  if (context == null ? void 0 : context.brand) return context.brand;
1875
1673
  if (context == null ? void 0 : context.products) {
1876
1674
  return context.products.map((p) => p.brand.name).join().trim();
@@ -1883,14 +1681,12 @@ var HeadlessPdcZone = {
1883
1681
  var headlessAdapter = {
1884
1682
  ...metaAdapters,
1885
1683
  // global adapters
1886
- ...orderFormAdapter,
1887
- // orderForm adapters, confirmar se no storefront tem evento que usa essses params
1888
- brand: (context) => {
1684
+ brand: (context, config2) => {
1889
1685
  if (context.zone === "PDP") {
1890
- return HeadlessPdpZone.brand(context);
1686
+ return HeadlessPdpZone.brand(context, config2);
1891
1687
  }
1892
1688
  if (context.zone === "PDC") {
1893
- return HeadlessPdcZone.brand(context);
1689
+ return HeadlessPdcZone.brand(context, config2);
1894
1690
  }
1895
1691
  return null;
1896
1692
  },
@@ -1976,6 +1772,209 @@ var pickupAdapter = {
1976
1772
  }
1977
1773
  };
1978
1774
 
1775
+ // src/params/adapters/orderForm/utils.ts
1776
+ var getItemCategory6 = (item) => {
1777
+ var _a;
1778
+ const categories = item == null ? void 0 : item.productCategories;
1779
+ if (!categories) return "Cole\xE7\xE3o";
1780
+ const text = Object.values(categories).join(" ");
1781
+ const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1782
+ return match != null ? match : "Cole\xE7\xE3o";
1783
+ };
1784
+ var getItemCategory24 = (item) => {
1785
+ var _a, _b;
1786
+ const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1787
+ const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1788
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1789
+ const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1790
+ return capitalize(deepest);
1791
+ };
1792
+ function getItemShippingTier2(orderForm, item) {
1793
+ var _a, _b, _c, _d;
1794
+ const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1795
+ (li) => li.itemId === item.id
1796
+ );
1797
+ const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1798
+ 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;
1799
+ }
1800
+ var getOrderFormItems = (orderForm) => {
1801
+ const idSelected = orderForm == null ? void 0 : orderForm.selected;
1802
+ return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1803
+ };
1804
+
1805
+ // src/params/adapters/orderForm/index.ts
1806
+ var orderFormAdapter = {
1807
+ ...metaAdapters,
1808
+ items: (context) => {
1809
+ if (context == null ? void 0 : context.items) return context.items;
1810
+ if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1811
+ return getOrderFormItems(context.orderForm).map((item, index) => {
1812
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1813
+ return {
1814
+ quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1815
+ index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1816
+ item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1817
+ item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1818
+ price: (item == null ? void 0 : item.price) / 100,
1819
+ discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1820
+ 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,
1821
+ 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,
1822
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1823
+ item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1824
+ item_category: (_o = getItemCategory6(item)) != null ? _o : null,
1825
+ item_category2: (_p = getItemCategory24(item)) != null ? _p : null,
1826
+ item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1827
+ item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1828
+ item_url: (_s = item.detailUrl) != null ? _s : null,
1829
+ image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1830
+ seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1831
+ item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1832
+ };
1833
+ });
1834
+ }
1835
+ return null;
1836
+ },
1837
+ brand: (context, config2) => {
1838
+ var _a;
1839
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1840
+ if (context == null ? void 0 : context.brand) return context.brand;
1841
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1842
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1843
+ return normalizeBrand2(brands);
1844
+ },
1845
+ line_items: (context) => {
1846
+ var _a;
1847
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1848
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1849
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1850
+ },
1851
+ value: (context) => {
1852
+ var _a;
1853
+ if (context == null ? void 0 : context.value) return context.value;
1854
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1855
+ 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);
1856
+ },
1857
+ payment_type: getPaymentType,
1858
+ total_discount: (context) => {
1859
+ var _a, _b;
1860
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1861
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1862
+ const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1863
+ const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1864
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1865
+ return acc + unitDiscount * item.quantity;
1866
+ }, 0);
1867
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1868
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1869
+ },
1870
+ subtotal: (context) => {
1871
+ var _a, _b;
1872
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1873
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1874
+ return subtotal;
1875
+ },
1876
+ coupon_message: (context) => {
1877
+ var _a;
1878
+ if (context.couponMessage) return context.couponMessage;
1879
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1880
+ if (messages.length === 0) return null;
1881
+ const couponMessages = messages.filter(
1882
+ (msg) => msg.text.toLowerCase().includes("cupom")
1883
+ );
1884
+ if (couponMessages.length === 0) return null;
1885
+ return couponMessages.map((msg) => msg.text).join(" | ");
1886
+ },
1887
+ zipcode: (context) => {
1888
+ var _a;
1889
+ return (_a = context.zipcode) != null ? _a : null;
1890
+ },
1891
+ flag_pickup: (context) => {
1892
+ var _a;
1893
+ const orderForm = context.orderForm;
1894
+ if (!orderForm) return null;
1895
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1896
+ const hasPickup = logisticsInfo.some(
1897
+ (info) => {
1898
+ var _a2;
1899
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1900
+ }
1901
+ );
1902
+ return hasPickup;
1903
+ },
1904
+ shippings: (context) => {
1905
+ if (!context.orderForm) return null;
1906
+ const { items, shippingData } = context.orderForm;
1907
+ const acc = {};
1908
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1909
+ const item = items[itemIndex];
1910
+ if (!item) return;
1911
+ slas.forEach((sla) => {
1912
+ if (!acc[sla.name]) acc[sla.name] = {
1913
+ shipping_tier: sla.name,
1914
+ delivery_time: parseInt(sla.shippingEstimate),
1915
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1916
+ line_items: []
1917
+ };
1918
+ acc[sla.name].line_items.push(item.id);
1919
+ });
1920
+ });
1921
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1922
+ },
1923
+ shipping: (context) => {
1924
+ var _a, _b, _c;
1925
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1926
+ return logistics.reduce((total, item) => {
1927
+ var _a2, _b2;
1928
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1929
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1930
+ }, 0);
1931
+ },
1932
+ shipping_tier: (context) => {
1933
+ var _a, _b, _c;
1934
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1935
+ const selectedSlas = logistics.map((item) => {
1936
+ var _a2;
1937
+ if (!item.selectedSla) return null;
1938
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1939
+ }).filter(Boolean);
1940
+ if (selectedSlas.length === 0) return null;
1941
+ const uniqueTiers = Array.from(
1942
+ new Map(
1943
+ selectedSlas.map((sla) => {
1944
+ var _a2;
1945
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1946
+ return [key, sla];
1947
+ })
1948
+ ).values()
1949
+ );
1950
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1951
+ var _a2, _b2;
1952
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1953
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1954
+ if (aOrder !== bOrder) return aOrder - bOrder;
1955
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1956
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1957
+ return aLabel.localeCompare(bLabel, "pt-BR");
1958
+ });
1959
+ const shippingTier = sortedTiers.map((sla) => {
1960
+ var _a2;
1961
+ 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;
1962
+ }).filter(Boolean).join(", ");
1963
+ return shippingTier || null;
1964
+ },
1965
+ transaction_id: (context) => {
1966
+ var _a, _b;
1967
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1968
+ },
1969
+ coupon: (context) => {
1970
+ var _a, _b;
1971
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1972
+ },
1973
+ seller_cod_name: (context) => {
1974
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1975
+ }
1976
+ };
1977
+
1979
1978
  // src/formatter.ts
1980
1979
  var adapters = {
1981
1980
  DECO: decoAdapter,
@@ -1983,7 +1982,7 @@ var adapters = {
1983
1982
  PICKUP: pickupAdapter,
1984
1983
  ORDERFORM: orderFormAdapter
1985
1984
  };
1986
- async function getParameters(context, eventName) {
1985
+ async function getParameters(context, eventName, config2) {
1987
1986
  var _a;
1988
1987
  const eventConfig = EVENTS[eventName];
1989
1988
  if (!eventConfig) return;
@@ -1996,16 +1995,20 @@ async function getParameters(context, eventName) {
1996
1995
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
1997
1996
  return [param, null];
1998
1997
  }
1999
- return [param, await getter(context, eventName)];
1998
+ return [param, await getter(context, config2)];
2000
1999
  })
2001
2000
  );
2002
2001
  return Object.fromEntries(entries);
2003
2002
  }
2004
2003
 
2005
2004
  // src/index.ts
2005
+ var config = { brand: "", currency: "BRL" };
2006
+ function initTracker(c) {
2007
+ config = c;
2008
+ }
2006
2009
  async function trackWebEvent(event, context) {
2007
2010
  try {
2008
- const parameters = await getParameters(context, event);
2011
+ const parameters = await getParameters(context, event, config);
2009
2012
  if (isDebugMode()) {
2010
2013
  console.log(`[DT v2] ${event}, context e parameters: `, {
2011
2014
  context,
@@ -2027,6 +2030,7 @@ var src_default = {
2027
2030
  export {
2028
2031
  EVENTS,
2029
2032
  src_default as default,
2033
+ initTracker,
2030
2034
  trackWebEvent
2031
2035
  };
2032
2036
  //# sourceMappingURL=mod.js.map