@azzas/azzas-tracker-web 2.0.0-preview.4 → 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.
@@ -23,6 +23,7 @@ var AzzasTracker = (() => {
23
23
  __export(src_exports, {
24
24
  EVENTS: () => EVENTS,
25
25
  default: () => src_default,
26
+ initTracker: () => initTracker,
26
27
  trackWebEvent: () => trackWebEvent
27
28
  });
28
29
 
@@ -1357,9 +1358,9 @@ var AzzasTracker = (() => {
1357
1358
  // src/params/adapters/meta/index.ts
1358
1359
  var metaAdapters = {
1359
1360
  user_info: getUserInfo,
1360
- brand: (context) => {
1361
- return context.meta.brand || null;
1362
- },
1361
+ // brand: (context: MetaBrandContext) => {
1362
+ // return context.meta.brand || null;
1363
+ // },
1363
1364
  content_type: (context) => {
1364
1365
  return context.meta.content_type || null;
1365
1366
  },
@@ -1369,8 +1370,8 @@ var AzzasTracker = (() => {
1369
1370
  pre_filled: (context) => {
1370
1371
  return !!context.preFilled;
1371
1372
  },
1372
- currency: (context) => {
1373
- if (context == null ? void 0 : context.currency) return context.currency;
1373
+ currency: (_, config2) => {
1374
+ if (config2 == null ? void 0 : config2.currency) return config2.currency;
1374
1375
  return "BRL";
1375
1376
  },
1376
1377
  slot_per_line: (context) => {
@@ -1439,6 +1440,37 @@ var AzzasTracker = (() => {
1439
1440
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1440
1441
  return capitalize(deepest);
1441
1442
  };
1443
+ var BRAND_CODES2 = {
1444
+ farm: "farmrio",
1445
+ "farm etc": "farmetc",
1446
+ "farm rio": "farmrio"
1447
+ };
1448
+ function getBrandCode2(brand) {
1449
+ if (!brand) return null;
1450
+ const standardized = brand.toLowerCase().trim();
1451
+ return BRAND_CODES2[standardized] || null;
1452
+ }
1453
+ function normalizeBrand2(input) {
1454
+ var _a;
1455
+ let brandStrings = [];
1456
+ if (Array.isArray(input) && input.every((item) => typeof item === "string")) {
1457
+ brandStrings = input;
1458
+ } else if (Array.isArray(input)) {
1459
+ brandStrings = input.map((item) => {
1460
+ var _a2;
1461
+ return ((_a2 = item.additionalInfo) == null ? void 0 : _a2.brandName) || item.brand;
1462
+ });
1463
+ } else if (typeof input === "object" && input !== null && "brand" in input) {
1464
+ brandStrings = [((_a = input.additionalInfo) == null ? void 0 : _a.brandName) || input.brand];
1465
+ } else if (typeof input === "string") {
1466
+ return getBrandCode2(input);
1467
+ } else {
1468
+ return null;
1469
+ }
1470
+ const brandCodes = brandStrings.map(getBrandCode2).filter((code) => code !== null);
1471
+ const uniqueSortedCodes = [...new Set(brandCodes)].sort();
1472
+ return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
1473
+ }
1442
1474
 
1443
1475
  // src/params/adapters/deco/index.ts
1444
1476
  var IN_STOCK_SCHEMA = "https://schema.org/InStock";
@@ -1481,13 +1513,16 @@ var AzzasTracker = (() => {
1481
1513
  }
1482
1514
  return null;
1483
1515
  },
1484
- // brand: (context: DecoBrandContext) => {
1485
- // if (context?.brand) return context.brand
1486
- // if (context?.products) {
1487
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1488
- // }
1489
- // return null
1490
- // },
1516
+ brand: (context, config2) => {
1517
+ if (config2 == null ? void 0 : config2.brand) return config2.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
+ },
1491
1526
  line_items: (context) => {
1492
1527
  if (context == null ? void 0 : context.line_items) return context.line_items;
1493
1528
  if (context == null ? void 0 : context.products) {
@@ -1529,210 +1564,8 @@ var AzzasTracker = (() => {
1529
1564
  }
1530
1565
  };
1531
1566
 
1532
- // src/params/adapters/orderForm/utils.ts
1533
- var getItemCategory5 = (item) => {
1534
- var _a;
1535
- const categories = item == null ? void 0 : item.productCategories;
1536
- if (!categories) return "Cole\xE7\xE3o";
1537
- const text = Object.values(categories).join(" ");
1538
- const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1539
- return match != null ? match : "Cole\xE7\xE3o";
1540
- };
1541
- var getItemCategory23 = (item) => {
1542
- var _a, _b;
1543
- const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1544
- const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1545
- const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1546
- const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1547
- return capitalize(deepest);
1548
- };
1549
- function getItemShippingTier2(orderForm, item) {
1550
- var _a, _b, _c, _d;
1551
- const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1552
- (li) => li.itemId === item.id
1553
- );
1554
- const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1555
- 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;
1556
- }
1557
- var getOrderFormItems = (orderForm) => {
1558
- const idSelected = orderForm == null ? void 0 : orderForm.selected;
1559
- return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1560
- };
1561
-
1562
- // src/params/adapters/orderForm/index.ts
1563
- var orderFormAdapter = {
1564
- ...metaAdapters,
1565
- items: (context) => {
1566
- if (context == null ? void 0 : context.items) return context.items;
1567
- if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1568
- return getOrderFormItems(context.orderForm).map((item, index) => {
1569
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1570
- return {
1571
- quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1572
- index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1573
- item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1574
- item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1575
- price: (item == null ? void 0 : item.price) / 100,
1576
- discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1577
- 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,
1578
- 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,
1579
- item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1580
- item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1581
- item_category: (_o = getItemCategory5(item)) != null ? _o : null,
1582
- item_category2: (_p = getItemCategory23(item)) != null ? _p : null,
1583
- item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1584
- item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1585
- item_url: (_s = item.detailUrl) != null ? _s : null,
1586
- image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1587
- seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1588
- item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1589
- };
1590
- });
1591
- }
1592
- return null;
1593
- },
1594
- // brand: (context: any) => {
1595
- // if (context?.brand) return context.brand
1596
- // if (context?.products) {
1597
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1598
- // }
1599
- // return null
1600
- // },
1601
- line_items: (context) => {
1602
- var _a;
1603
- if (context == null ? void 0 : context.line_items) return context.line_items;
1604
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1605
- return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1606
- },
1607
- value: (context) => {
1608
- var _a;
1609
- if (context == null ? void 0 : context.value) return context.value;
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.price) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1612
- },
1613
- payment_type: getPaymentType,
1614
- total_discount: (context) => {
1615
- var _a, _b;
1616
- if (context == null ? void 0 : context.total_discount) return context.total_discount;
1617
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1618
- const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1619
- const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1620
- const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1621
- return acc + unitDiscount * item.quantity;
1622
- }, 0);
1623
- const discounts = totalsList.find((t) => t.id === "Discounts");
1624
- return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1625
- },
1626
- subtotal: (context) => {
1627
- var _a, _b;
1628
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1629
- const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1630
- return subtotal;
1631
- },
1632
- coupon_message: (context) => {
1633
- var _a;
1634
- if (context.couponMessage) return context.couponMessage;
1635
- const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1636
- if (messages.length === 0) return null;
1637
- const couponMessages = messages.filter(
1638
- (msg) => msg.text.toLowerCase().includes("cupom")
1639
- );
1640
- if (couponMessages.length === 0) return null;
1641
- return couponMessages.map((msg) => msg.text).join(" | ");
1642
- },
1643
- zipcode: (context) => {
1644
- var _a;
1645
- return (_a = context.zipcode) != null ? _a : null;
1646
- },
1647
- flag_pickup: (context) => {
1648
- var _a;
1649
- const orderForm = context.orderForm;
1650
- if (!orderForm) return null;
1651
- const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1652
- const hasPickup = logisticsInfo.some(
1653
- (info) => {
1654
- var _a2;
1655
- return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1656
- }
1657
- );
1658
- return hasPickup;
1659
- },
1660
- shippings: (context) => {
1661
- if (!context.orderForm) return null;
1662
- const { items, shippingData } = context.orderForm;
1663
- const acc = {};
1664
- shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1665
- const item = items[itemIndex];
1666
- if (!item) return;
1667
- slas.forEach((sla) => {
1668
- if (!acc[sla.name]) acc[sla.name] = {
1669
- shipping_tier: sla.name,
1670
- delivery_time: parseInt(sla.shippingEstimate),
1671
- shipping: parseFloat((sla.price / 100).toFixed(1)),
1672
- line_items: []
1673
- };
1674
- acc[sla.name].line_items.push(item.id);
1675
- });
1676
- });
1677
- return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1678
- },
1679
- shipping: (context) => {
1680
- var _a, _b, _c;
1681
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1682
- return logistics.reduce((total, item) => {
1683
- var _a2, _b2;
1684
- const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1685
- return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1686
- }, 0);
1687
- },
1688
- shipping_tier: (context) => {
1689
- var _a, _b, _c;
1690
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1691
- const selectedSlas = logistics.map((item) => {
1692
- var _a2;
1693
- if (!item.selectedSla) return null;
1694
- return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1695
- }).filter(Boolean);
1696
- if (selectedSlas.length === 0) return null;
1697
- const uniqueTiers = Array.from(
1698
- new Map(
1699
- selectedSlas.map((sla) => {
1700
- var _a2;
1701
- const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1702
- return [key, sla];
1703
- })
1704
- ).values()
1705
- );
1706
- const sortedTiers = uniqueTiers.sort((a, b) => {
1707
- var _a2, _b2;
1708
- const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1709
- const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1710
- if (aOrder !== bOrder) return aOrder - bOrder;
1711
- const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1712
- const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1713
- return aLabel.localeCompare(bLabel, "pt-BR");
1714
- });
1715
- const shippingTier = sortedTiers.map((sla) => {
1716
- var _a2;
1717
- 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;
1718
- }).filter(Boolean).join(", ");
1719
- return shippingTier || null;
1720
- },
1721
- transaction_id: (context) => {
1722
- var _a, _b;
1723
- return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1724
- },
1725
- coupon: (context) => {
1726
- var _a, _b;
1727
- return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1728
- },
1729
- seller_cod_name: (context) => {
1730
- return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1731
- }
1732
- };
1733
-
1734
1567
  // src/params/adapters/headless/utils.ts
1735
- var getItemCategory6 = (item) => {
1568
+ var getItemCategory5 = (item) => {
1736
1569
  const keywords = ["outlet", "bazar", "sale"];
1737
1570
  const regex = new RegExp(keywords.join("|"), "i");
1738
1571
  const value = item == null ? void 0 : item.categories;
@@ -1745,7 +1578,7 @@ var AzzasTracker = (() => {
1745
1578
  }
1746
1579
  return "Cole\xE7\xE3o";
1747
1580
  };
1748
- var getItemCategory24 = (item) => {
1581
+ var getItemCategory23 = (item) => {
1749
1582
  var _a, _b, _c;
1750
1583
  const avoidList = /outlet|bazar|sale/i;
1751
1584
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1775,8 +1608,8 @@ var AzzasTracker = (() => {
1775
1608
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1776
1609
  item_ref: (_l = item.productReference) != null ? _l : null,
1777
1610
  // sem ref no retorno do IS na multi-lib produtos PDC
1778
- item_category: getItemCategory6(item),
1779
- item_category2: (_m = getItemCategory24(item)) != null ? _m : null,
1611
+ item_category: getItemCategory5(item),
1612
+ item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
1780
1613
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1781
1614
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1782
1615
  item_url: (_q = item.link) != null ? _q : null,
@@ -1806,8 +1639,8 @@ var AzzasTracker = (() => {
1806
1639
  }
1807
1640
  return null;
1808
1641
  },
1809
- brand: (context) => {
1810
- if (context == null ? void 0 : context.brand) return context.brand;
1642
+ brand: (context, config2) => {
1643
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1811
1644
  if (context == null ? void 0 : context.products) {
1812
1645
  return context.products.map((p) => p.brand).join().trim();
1813
1646
  }
@@ -1836,8 +1669,8 @@ var AzzasTracker = (() => {
1836
1669
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1837
1670
  item_ref: null,
1838
1671
  // sem ref no retorno do IS na multi-lib produtos PDC
1839
- item_category: getItemCategory6(item),
1840
- item_category2: (_j = getItemCategory24(item)) != null ? _j : null,
1672
+ item_category: getItemCategory5(item),
1673
+ item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
1841
1674
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1842
1675
  item_sku: (_l = item.sku) != null ? _l : null,
1843
1676
  item_url: null,
@@ -1864,8 +1697,8 @@ var AzzasTracker = (() => {
1864
1697
  }
1865
1698
  return null;
1866
1699
  },
1867
- brand: (context) => {
1868
- if (context == null ? void 0 : context.brand) return context.brand;
1700
+ brand: (context, config2) => {
1701
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1869
1702
  if (context == null ? void 0 : context.products) {
1870
1703
  return context.products.map((p) => p.brand.name).join().trim();
1871
1704
  }
@@ -1877,14 +1710,12 @@ var AzzasTracker = (() => {
1877
1710
  var headlessAdapter = {
1878
1711
  ...metaAdapters,
1879
1712
  // global adapters
1880
- ...orderFormAdapter,
1881
- // orderForm adapters, confirmar se no storefront tem evento que usa essses params
1882
- brand: (context) => {
1713
+ brand: (context, config2) => {
1883
1714
  if (context.zone === "PDP") {
1884
- return HeadlessPdpZone.brand(context);
1715
+ return HeadlessPdpZone.brand(context, config2);
1885
1716
  }
1886
1717
  if (context.zone === "PDC") {
1887
- return HeadlessPdcZone.brand(context);
1718
+ return HeadlessPdcZone.brand(context, config2);
1888
1719
  }
1889
1720
  return null;
1890
1721
  },
@@ -1953,10 +1784,10 @@ var AzzasTracker = (() => {
1953
1784
  shippings: (context) => {
1954
1785
  if (context.shippings) {
1955
1786
  return context.shippings.map((s) => {
1956
- var _a, _b;
1787
+ var _a;
1957
1788
  return {
1958
1789
  line_items: (_a = s.line_items) != null ? _a : "",
1959
- shipping: (_b = s.price) != null ? _b : 0,
1790
+ shipping: s.price / 100,
1960
1791
  shipping_tier: getShippingTier(s),
1961
1792
  delivery_time: getDeliveryTime(s)
1962
1793
  };
@@ -1970,6 +1801,208 @@ var AzzasTracker = (() => {
1970
1801
  }
1971
1802
  };
1972
1803
 
1804
+ // src/params/adapters/orderForm/utils.ts
1805
+ var getItemCategory6 = (item) => {
1806
+ var _a;
1807
+ const categories = item == null ? void 0 : item.productCategories;
1808
+ if (!categories) return "Cole\xE7\xE3o";
1809
+ const text = Object.values(categories).join(" ");
1810
+ const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1811
+ return match != null ? match : "Cole\xE7\xE3o";
1812
+ };
1813
+ var getItemCategory24 = (item) => {
1814
+ var _a, _b;
1815
+ const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1816
+ const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1817
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1818
+ const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1819
+ return capitalize(deepest);
1820
+ };
1821
+ function getItemShippingTier2(orderForm, item) {
1822
+ var _a, _b, _c, _d;
1823
+ const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1824
+ (li) => li.itemId === item.id
1825
+ );
1826
+ const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1827
+ 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;
1828
+ }
1829
+ var getOrderFormItems = (orderForm) => {
1830
+ const idSelected = orderForm == null ? void 0 : orderForm.selected;
1831
+ return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1832
+ };
1833
+
1834
+ // src/params/adapters/orderForm/index.ts
1835
+ var orderFormAdapter = {
1836
+ ...metaAdapters,
1837
+ items: (context) => {
1838
+ if (context == null ? void 0 : context.items) return context.items;
1839
+ if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1840
+ return getOrderFormItems(context.orderForm).map((item, index) => {
1841
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1842
+ return {
1843
+ quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1844
+ index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1845
+ item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1846
+ item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1847
+ price: (item == null ? void 0 : item.price) / 100,
1848
+ discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1849
+ 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,
1850
+ 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,
1851
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1852
+ item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1853
+ item_category: (_o = getItemCategory6(item)) != null ? _o : null,
1854
+ item_category2: (_p = getItemCategory24(item)) != null ? _p : null,
1855
+ item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1856
+ item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1857
+ item_url: (_s = item.detailUrl) != null ? _s : null,
1858
+ image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1859
+ seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1860
+ item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1861
+ };
1862
+ });
1863
+ }
1864
+ return null;
1865
+ },
1866
+ brand: (context, config2) => {
1867
+ var _a;
1868
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1869
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1870
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1871
+ return normalizeBrand2(brands);
1872
+ },
1873
+ line_items: (context) => {
1874
+ var _a;
1875
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1876
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1877
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1878
+ },
1879
+ value: (context) => {
1880
+ var _a;
1881
+ if (context == null ? void 0 : context.value) return context.value;
1882
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1883
+ 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);
1884
+ },
1885
+ payment_type: getPaymentType,
1886
+ total_discount: (context) => {
1887
+ var _a, _b;
1888
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1889
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1890
+ const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1891
+ const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1892
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1893
+ return acc + unitDiscount * item.quantity;
1894
+ }, 0);
1895
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1896
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1897
+ },
1898
+ subtotal: (context) => {
1899
+ var _a, _b;
1900
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1901
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1902
+ return subtotal;
1903
+ },
1904
+ coupon_message: (context) => {
1905
+ var _a;
1906
+ if (context.couponMessage) return context.couponMessage;
1907
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1908
+ if (messages.length === 0) return null;
1909
+ const couponMessages = messages.filter(
1910
+ (msg) => msg.text.toLowerCase().includes("cupom")
1911
+ );
1912
+ if (couponMessages.length === 0) return null;
1913
+ return couponMessages.map((msg) => msg.text).join(" | ");
1914
+ },
1915
+ zipcode: (context) => {
1916
+ var _a;
1917
+ return (_a = context.zipcode) != null ? _a : null;
1918
+ },
1919
+ flag_pickup: (context) => {
1920
+ var _a;
1921
+ const orderForm = context.orderForm;
1922
+ if (!orderForm) return null;
1923
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1924
+ const hasPickup = logisticsInfo.some(
1925
+ (info) => {
1926
+ var _a2;
1927
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1928
+ }
1929
+ );
1930
+ return hasPickup;
1931
+ },
1932
+ shippings: (context) => {
1933
+ if (!context.orderForm) return null;
1934
+ const { items, shippingData } = context.orderForm;
1935
+ const acc = {};
1936
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1937
+ const item = items[itemIndex];
1938
+ if (!item) return;
1939
+ slas.forEach((sla) => {
1940
+ if (!acc[sla.name]) acc[sla.name] = {
1941
+ shipping_tier: sla.name,
1942
+ delivery_time: parseInt(sla.shippingEstimate),
1943
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1944
+ line_items: []
1945
+ };
1946
+ acc[sla.name].line_items.push(item.id);
1947
+ });
1948
+ });
1949
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1950
+ },
1951
+ shipping: (context) => {
1952
+ var _a, _b, _c;
1953
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1954
+ return logistics.reduce((total, item) => {
1955
+ var _a2, _b2;
1956
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1957
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1958
+ }, 0);
1959
+ },
1960
+ shipping_tier: (context) => {
1961
+ var _a, _b, _c;
1962
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1963
+ const selectedSlas = logistics.map((item) => {
1964
+ var _a2;
1965
+ if (!item.selectedSla) return null;
1966
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1967
+ }).filter(Boolean);
1968
+ if (selectedSlas.length === 0) return null;
1969
+ const uniqueTiers = Array.from(
1970
+ new Map(
1971
+ selectedSlas.map((sla) => {
1972
+ var _a2;
1973
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1974
+ return [key, sla];
1975
+ })
1976
+ ).values()
1977
+ );
1978
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1979
+ var _a2, _b2;
1980
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1981
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1982
+ if (aOrder !== bOrder) return aOrder - bOrder;
1983
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1984
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1985
+ return aLabel.localeCompare(bLabel, "pt-BR");
1986
+ });
1987
+ const shippingTier = sortedTiers.map((sla) => {
1988
+ var _a2;
1989
+ 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;
1990
+ }).filter(Boolean).join(", ");
1991
+ return shippingTier || null;
1992
+ },
1993
+ transaction_id: (context) => {
1994
+ var _a, _b;
1995
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1996
+ },
1997
+ coupon: (context) => {
1998
+ var _a, _b;
1999
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
2000
+ },
2001
+ seller_cod_name: (context) => {
2002
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
2003
+ }
2004
+ };
2005
+
1973
2006
  // src/formatter.ts
1974
2007
  var adapters = {
1975
2008
  DECO: decoAdapter,
@@ -1977,7 +2010,7 @@ var AzzasTracker = (() => {
1977
2010
  PICKUP: pickupAdapter,
1978
2011
  ORDERFORM: orderFormAdapter
1979
2012
  };
1980
- async function getParameters(context, eventName) {
2013
+ async function getParameters(context, eventName, config2) {
1981
2014
  var _a;
1982
2015
  const eventConfig = EVENTS[eventName];
1983
2016
  if (!eventConfig) return;
@@ -1990,16 +2023,20 @@ var AzzasTracker = (() => {
1990
2023
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
1991
2024
  return [param, null];
1992
2025
  }
1993
- return [param, await getter(context, eventName)];
2026
+ return [param, await getter(context, config2)];
1994
2027
  })
1995
2028
  );
1996
2029
  return Object.fromEntries(entries);
1997
2030
  }
1998
2031
 
1999
2032
  // src/index.ts
2033
+ var config = { brand: "", currency: "BRL" };
2034
+ function initTracker(c) {
2035
+ config = c;
2036
+ }
2000
2037
  async function trackWebEvent(event, context) {
2001
2038
  try {
2002
- const parameters = await getParameters(context, event);
2039
+ const parameters = await getParameters(context, event, config);
2003
2040
  if (isDebugMode()) {
2004
2041
  console.log(`[DT v2] ${event}, context e parameters: `, {
2005
2042
  context,