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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mod.js CHANGED
@@ -1341,8 +1341,8 @@ var metaAdapters = {
1341
1341
  pre_filled: (context) => {
1342
1342
  return !!context.preFilled;
1343
1343
  },
1344
- currency: (context) => {
1345
- if (context == null ? void 0 : context.currency) return context.currency;
1344
+ currency: (_, config2) => {
1345
+ if (config2 == null ? void 0 : config2.currency) return config2.currency;
1346
1346
  return "BRL";
1347
1347
  },
1348
1348
  slot_per_line: (context) => {
@@ -1484,8 +1484,8 @@ var decoAdapter = {
1484
1484
  }
1485
1485
  return null;
1486
1486
  },
1487
- brand: (context) => {
1488
- if (context == null ? void 0 : context.brand) return context.brand;
1487
+ brand: (context, config2) => {
1488
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1489
1489
  if (context == null ? void 0 : context.products) {
1490
1490
  return normalizeBrand2(context.products.map((p) => {
1491
1491
  var _a;
@@ -1535,210 +1535,8 @@ var decoAdapter = {
1535
1535
  }
1536
1536
  };
1537
1537
 
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
1538
  // src/params/adapters/headless/utils.ts
1741
- var getItemCategory6 = (item) => {
1539
+ var getItemCategory5 = (item) => {
1742
1540
  const keywords = ["outlet", "bazar", "sale"];
1743
1541
  const regex = new RegExp(keywords.join("|"), "i");
1744
1542
  const value = item == null ? void 0 : item.categories;
@@ -1751,7 +1549,7 @@ var getItemCategory6 = (item) => {
1751
1549
  }
1752
1550
  return "Cole\xE7\xE3o";
1753
1551
  };
1754
- var getItemCategory24 = (item) => {
1552
+ var getItemCategory23 = (item) => {
1755
1553
  var _a, _b, _c;
1756
1554
  const avoidList = /outlet|bazar|sale/i;
1757
1555
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1781,8 +1579,8 @@ var HeadlessPdpZone = {
1781
1579
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1782
1580
  item_ref: (_l = item.productReference) != null ? _l : null,
1783
1581
  // 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,
1582
+ item_category: getItemCategory5(item),
1583
+ item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
1786
1584
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1787
1585
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1788
1586
  item_url: (_q = item.link) != null ? _q : null,
@@ -1812,8 +1610,8 @@ var HeadlessPdpZone = {
1812
1610
  }
1813
1611
  return null;
1814
1612
  },
1815
- brand: (context) => {
1816
- if (context == null ? void 0 : context.brand) return context.brand;
1613
+ brand: (context, config2) => {
1614
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1817
1615
  if (context == null ? void 0 : context.products) {
1818
1616
  return context.products.map((p) => p.brand).join().trim();
1819
1617
  }
@@ -1842,8 +1640,8 @@ var HeadlessPdcZone = {
1842
1640
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1843
1641
  item_ref: null,
1844
1642
  // 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,
1643
+ item_category: getItemCategory5(item),
1644
+ item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
1847
1645
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1848
1646
  item_sku: (_l = item.sku) != null ? _l : null,
1849
1647
  item_url: null,
@@ -1870,8 +1668,8 @@ var HeadlessPdcZone = {
1870
1668
  }
1871
1669
  return null;
1872
1670
  },
1873
- brand: (context) => {
1874
- if (context == null ? void 0 : context.brand) return context.brand;
1671
+ brand: (context, config2) => {
1672
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1875
1673
  if (context == null ? void 0 : context.products) {
1876
1674
  return context.products.map((p) => p.brand.name).join().trim();
1877
1675
  }
@@ -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,208 @@ 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 (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1841
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1842
+ return normalizeBrand2(brands);
1843
+ },
1844
+ line_items: (context) => {
1845
+ var _a;
1846
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1847
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1848
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1849
+ },
1850
+ value: (context) => {
1851
+ var _a;
1852
+ if (context == null ? void 0 : context.value) return context.value;
1853
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1854
+ 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);
1855
+ },
1856
+ payment_type: getPaymentType,
1857
+ total_discount: (context) => {
1858
+ var _a, _b;
1859
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1860
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1861
+ const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1862
+ const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1863
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1864
+ return acc + unitDiscount * item.quantity;
1865
+ }, 0);
1866
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1867
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1868
+ },
1869
+ subtotal: (context) => {
1870
+ var _a, _b;
1871
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1872
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1873
+ return subtotal;
1874
+ },
1875
+ coupon_message: (context) => {
1876
+ var _a;
1877
+ if (context.couponMessage) return context.couponMessage;
1878
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1879
+ if (messages.length === 0) return null;
1880
+ const couponMessages = messages.filter(
1881
+ (msg) => msg.text.toLowerCase().includes("cupom")
1882
+ );
1883
+ if (couponMessages.length === 0) return null;
1884
+ return couponMessages.map((msg) => msg.text).join(" | ");
1885
+ },
1886
+ zipcode: (context) => {
1887
+ var _a;
1888
+ return (_a = context.zipcode) != null ? _a : null;
1889
+ },
1890
+ flag_pickup: (context) => {
1891
+ var _a;
1892
+ const orderForm = context.orderForm;
1893
+ if (!orderForm) return null;
1894
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1895
+ const hasPickup = logisticsInfo.some(
1896
+ (info) => {
1897
+ var _a2;
1898
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1899
+ }
1900
+ );
1901
+ return hasPickup;
1902
+ },
1903
+ shippings: (context) => {
1904
+ if (!context.orderForm) return null;
1905
+ const { items, shippingData } = context.orderForm;
1906
+ const acc = {};
1907
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1908
+ const item = items[itemIndex];
1909
+ if (!item) return;
1910
+ slas.forEach((sla) => {
1911
+ if (!acc[sla.name]) acc[sla.name] = {
1912
+ shipping_tier: sla.name,
1913
+ delivery_time: parseInt(sla.shippingEstimate),
1914
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1915
+ line_items: []
1916
+ };
1917
+ acc[sla.name].line_items.push(item.id);
1918
+ });
1919
+ });
1920
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1921
+ },
1922
+ shipping: (context) => {
1923
+ var _a, _b, _c;
1924
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1925
+ return logistics.reduce((total, item) => {
1926
+ var _a2, _b2;
1927
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1928
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1929
+ }, 0);
1930
+ },
1931
+ shipping_tier: (context) => {
1932
+ var _a, _b, _c;
1933
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1934
+ const selectedSlas = logistics.map((item) => {
1935
+ var _a2;
1936
+ if (!item.selectedSla) return null;
1937
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1938
+ }).filter(Boolean);
1939
+ if (selectedSlas.length === 0) return null;
1940
+ const uniqueTiers = Array.from(
1941
+ new Map(
1942
+ selectedSlas.map((sla) => {
1943
+ var _a2;
1944
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1945
+ return [key, sla];
1946
+ })
1947
+ ).values()
1948
+ );
1949
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1950
+ var _a2, _b2;
1951
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1952
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1953
+ if (aOrder !== bOrder) return aOrder - bOrder;
1954
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1955
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1956
+ return aLabel.localeCompare(bLabel, "pt-BR");
1957
+ });
1958
+ const shippingTier = sortedTiers.map((sla) => {
1959
+ var _a2;
1960
+ 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;
1961
+ }).filter(Boolean).join(", ");
1962
+ return shippingTier || null;
1963
+ },
1964
+ transaction_id: (context) => {
1965
+ var _a, _b;
1966
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1967
+ },
1968
+ coupon: (context) => {
1969
+ var _a, _b;
1970
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1971
+ },
1972
+ seller_cod_name: (context) => {
1973
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1974
+ }
1975
+ };
1976
+
1979
1977
  // src/formatter.ts
1980
1978
  var adapters = {
1981
1979
  DECO: decoAdapter,
@@ -1983,7 +1981,7 @@ var adapters = {
1983
1981
  PICKUP: pickupAdapter,
1984
1982
  ORDERFORM: orderFormAdapter
1985
1983
  };
1986
- async function getParameters(context, eventName) {
1984
+ async function getParameters(context, eventName, config2) {
1987
1985
  var _a;
1988
1986
  const eventConfig = EVENTS[eventName];
1989
1987
  if (!eventConfig) return;
@@ -1996,16 +1994,20 @@ async function getParameters(context, eventName) {
1996
1994
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
1997
1995
  return [param, null];
1998
1996
  }
1999
- return [param, await getter(context, eventName)];
1997
+ return [param, await getter(context, config2)];
2000
1998
  })
2001
1999
  );
2002
2000
  return Object.fromEntries(entries);
2003
2001
  }
2004
2002
 
2005
2003
  // src/index.ts
2004
+ var config = { brand: "", currency: "BRL" };
2005
+ function initTracker(c) {
2006
+ config = c;
2007
+ }
2006
2008
  async function trackWebEvent(event, context) {
2007
2009
  try {
2008
- const parameters = await getParameters(context, event);
2010
+ const parameters = await getParameters(context, event, config);
2009
2011
  if (isDebugMode()) {
2010
2012
  console.log(`[DT v2] ${event}, context e parameters: `, {
2011
2013
  context,
@@ -2027,6 +2029,7 @@ var src_default = {
2027
2029
  export {
2028
2030
  EVENTS,
2029
2031
  src_default as default,
2032
+ initTracker,
2030
2033
  trackWebEvent
2031
2034
  };
2032
2035
  //# sourceMappingURL=mod.js.map