@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.
package/dist/mod.js CHANGED
@@ -1329,9 +1329,9 @@ var legacyGetters = {
1329
1329
  // src/params/adapters/meta/index.ts
1330
1330
  var metaAdapters = {
1331
1331
  user_info: getUserInfo,
1332
- brand: (context) => {
1333
- return context.meta.brand || null;
1334
- },
1332
+ // brand: (context: MetaBrandContext) => {
1333
+ // return context.meta.brand || null;
1334
+ // },
1335
1335
  content_type: (context) => {
1336
1336
  return context.meta.content_type || null;
1337
1337
  },
@@ -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) => {
@@ -1411,6 +1411,37 @@ var getItemCategory22 = (item) => {
1411
1411
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1412
1412
  return capitalize(deepest);
1413
1413
  };
1414
+ var BRAND_CODES2 = {
1415
+ farm: "farmrio",
1416
+ "farm etc": "farmetc",
1417
+ "farm rio": "farmrio"
1418
+ };
1419
+ function getBrandCode2(brand) {
1420
+ if (!brand) return null;
1421
+ const standardized = brand.toLowerCase().trim();
1422
+ return BRAND_CODES2[standardized] || null;
1423
+ }
1424
+ function normalizeBrand2(input) {
1425
+ var _a;
1426
+ let brandStrings = [];
1427
+ if (Array.isArray(input) && input.every((item) => typeof item === "string")) {
1428
+ brandStrings = input;
1429
+ } else if (Array.isArray(input)) {
1430
+ brandStrings = input.map((item) => {
1431
+ var _a2;
1432
+ return ((_a2 = item.additionalInfo) == null ? void 0 : _a2.brandName) || item.brand;
1433
+ });
1434
+ } else if (typeof input === "object" && input !== null && "brand" in input) {
1435
+ brandStrings = [((_a = input.additionalInfo) == null ? void 0 : _a.brandName) || input.brand];
1436
+ } else if (typeof input === "string") {
1437
+ return getBrandCode2(input);
1438
+ } else {
1439
+ return null;
1440
+ }
1441
+ const brandCodes = brandStrings.map(getBrandCode2).filter((code) => code !== null);
1442
+ const uniqueSortedCodes = [...new Set(brandCodes)].sort();
1443
+ return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
1444
+ }
1414
1445
 
1415
1446
  // src/params/adapters/deco/index.ts
1416
1447
  var IN_STOCK_SCHEMA = "https://schema.org/InStock";
@@ -1453,13 +1484,16 @@ var decoAdapter = {
1453
1484
  }
1454
1485
  return null;
1455
1486
  },
1456
- // brand: (context: DecoBrandContext) => {
1457
- // if (context?.brand) return context.brand
1458
- // if (context?.products) {
1459
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1460
- // }
1461
- // return null
1462
- // },
1487
+ brand: (context, config2) => {
1488
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1489
+ if (context == null ? void 0 : context.products) {
1490
+ return normalizeBrand2(context.products.map((p) => {
1491
+ var _a;
1492
+ return (_a = p == null ? void 0 : p.brand) == null ? void 0 : _a.name;
1493
+ }));
1494
+ }
1495
+ return null;
1496
+ },
1463
1497
  line_items: (context) => {
1464
1498
  if (context == null ? void 0 : context.line_items) return context.line_items;
1465
1499
  if (context == null ? void 0 : context.products) {
@@ -1501,210 +1535,8 @@ var decoAdapter = {
1501
1535
  }
1502
1536
  };
1503
1537
 
1504
- // src/params/adapters/orderForm/utils.ts
1505
- var getItemCategory5 = (item) => {
1506
- var _a;
1507
- const categories = item == null ? void 0 : item.productCategories;
1508
- if (!categories) return "Cole\xE7\xE3o";
1509
- const text = Object.values(categories).join(" ");
1510
- const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1511
- return match != null ? match : "Cole\xE7\xE3o";
1512
- };
1513
- var getItemCategory23 = (item) => {
1514
- var _a, _b;
1515
- const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1516
- const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1517
- const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1518
- const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1519
- return capitalize(deepest);
1520
- };
1521
- function getItemShippingTier2(orderForm, item) {
1522
- var _a, _b, _c, _d;
1523
- const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1524
- (li) => li.itemId === item.id
1525
- );
1526
- const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1527
- 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;
1528
- }
1529
- var getOrderFormItems = (orderForm) => {
1530
- const idSelected = orderForm == null ? void 0 : orderForm.selected;
1531
- return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1532
- };
1533
-
1534
- // src/params/adapters/orderForm/index.ts
1535
- var orderFormAdapter = {
1536
- ...metaAdapters,
1537
- items: (context) => {
1538
- if (context == null ? void 0 : context.items) return context.items;
1539
- if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1540
- return getOrderFormItems(context.orderForm).map((item, index) => {
1541
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1542
- return {
1543
- quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1544
- index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1545
- item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1546
- item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1547
- price: (item == null ? void 0 : item.price) / 100,
1548
- discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1549
- 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,
1550
- 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,
1551
- item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1552
- item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1553
- item_category: (_o = getItemCategory5(item)) != null ? _o : null,
1554
- item_category2: (_p = getItemCategory23(item)) != null ? _p : null,
1555
- item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1556
- item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1557
- item_url: (_s = item.detailUrl) != null ? _s : null,
1558
- image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1559
- seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1560
- item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1561
- };
1562
- });
1563
- }
1564
- return null;
1565
- },
1566
- // brand: (context: any) => {
1567
- // if (context?.brand) return context.brand
1568
- // if (context?.products) {
1569
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1570
- // }
1571
- // return null
1572
- // },
1573
- line_items: (context) => {
1574
- var _a;
1575
- if (context == null ? void 0 : context.line_items) return context.line_items;
1576
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1577
- return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1578
- },
1579
- value: (context) => {
1580
- var _a;
1581
- if (context == null ? void 0 : context.value) return context.value;
1582
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1583
- 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);
1584
- },
1585
- payment_type: getPaymentType,
1586
- total_discount: (context) => {
1587
- var _a, _b;
1588
- if (context == null ? void 0 : context.total_discount) return context.total_discount;
1589
- if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1590
- const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1591
- const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1592
- const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1593
- return acc + unitDiscount * item.quantity;
1594
- }, 0);
1595
- const discounts = totalsList.find((t) => t.id === "Discounts");
1596
- return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1597
- },
1598
- subtotal: (context) => {
1599
- var _a, _b;
1600
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1601
- const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1602
- return subtotal;
1603
- },
1604
- coupon_message: (context) => {
1605
- var _a;
1606
- if (context.couponMessage) return context.couponMessage;
1607
- const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1608
- if (messages.length === 0) return null;
1609
- const couponMessages = messages.filter(
1610
- (msg) => msg.text.toLowerCase().includes("cupom")
1611
- );
1612
- if (couponMessages.length === 0) return null;
1613
- return couponMessages.map((msg) => msg.text).join(" | ");
1614
- },
1615
- zipcode: (context) => {
1616
- var _a;
1617
- return (_a = context.zipcode) != null ? _a : null;
1618
- },
1619
- flag_pickup: (context) => {
1620
- var _a;
1621
- const orderForm = context.orderForm;
1622
- if (!orderForm) return null;
1623
- const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1624
- const hasPickup = logisticsInfo.some(
1625
- (info) => {
1626
- var _a2;
1627
- return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1628
- }
1629
- );
1630
- return hasPickup;
1631
- },
1632
- shippings: (context) => {
1633
- if (!context.orderForm) return null;
1634
- const { items, shippingData } = context.orderForm;
1635
- const acc = {};
1636
- shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1637
- const item = items[itemIndex];
1638
- if (!item) return;
1639
- slas.forEach((sla) => {
1640
- if (!acc[sla.name]) acc[sla.name] = {
1641
- shipping_tier: sla.name,
1642
- delivery_time: parseInt(sla.shippingEstimate),
1643
- shipping: parseFloat((sla.price / 100).toFixed(1)),
1644
- line_items: []
1645
- };
1646
- acc[sla.name].line_items.push(item.id);
1647
- });
1648
- });
1649
- return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1650
- },
1651
- shipping: (context) => {
1652
- var _a, _b, _c;
1653
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1654
- return logistics.reduce((total, item) => {
1655
- var _a2, _b2;
1656
- const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1657
- return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1658
- }, 0);
1659
- },
1660
- shipping_tier: (context) => {
1661
- var _a, _b, _c;
1662
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1663
- const selectedSlas = logistics.map((item) => {
1664
- var _a2;
1665
- if (!item.selectedSla) return null;
1666
- return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1667
- }).filter(Boolean);
1668
- if (selectedSlas.length === 0) return null;
1669
- const uniqueTiers = Array.from(
1670
- new Map(
1671
- selectedSlas.map((sla) => {
1672
- var _a2;
1673
- const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1674
- return [key, sla];
1675
- })
1676
- ).values()
1677
- );
1678
- const sortedTiers = uniqueTiers.sort((a, b) => {
1679
- var _a2, _b2;
1680
- const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1681
- const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1682
- if (aOrder !== bOrder) return aOrder - bOrder;
1683
- const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1684
- const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1685
- return aLabel.localeCompare(bLabel, "pt-BR");
1686
- });
1687
- const shippingTier = sortedTiers.map((sla) => {
1688
- var _a2;
1689
- 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;
1690
- }).filter(Boolean).join(", ");
1691
- return shippingTier || null;
1692
- },
1693
- transaction_id: (context) => {
1694
- var _a, _b;
1695
- return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1696
- },
1697
- coupon: (context) => {
1698
- var _a, _b;
1699
- return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1700
- },
1701
- seller_cod_name: (context) => {
1702
- return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1703
- }
1704
- };
1705
-
1706
1538
  // src/params/adapters/headless/utils.ts
1707
- var getItemCategory6 = (item) => {
1539
+ var getItemCategory5 = (item) => {
1708
1540
  const keywords = ["outlet", "bazar", "sale"];
1709
1541
  const regex = new RegExp(keywords.join("|"), "i");
1710
1542
  const value = item == null ? void 0 : item.categories;
@@ -1717,7 +1549,7 @@ var getItemCategory6 = (item) => {
1717
1549
  }
1718
1550
  return "Cole\xE7\xE3o";
1719
1551
  };
1720
- var getItemCategory24 = (item) => {
1552
+ var getItemCategory23 = (item) => {
1721
1553
  var _a, _b, _c;
1722
1554
  const avoidList = /outlet|bazar|sale/i;
1723
1555
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1747,8 +1579,8 @@ var HeadlessPdpZone = {
1747
1579
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1748
1580
  item_ref: (_l = item.productReference) != null ? _l : null,
1749
1581
  // sem ref no retorno do IS na multi-lib produtos PDC
1750
- item_category: getItemCategory6(item),
1751
- item_category2: (_m = getItemCategory24(item)) != null ? _m : null,
1582
+ item_category: getItemCategory5(item),
1583
+ item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
1752
1584
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1753
1585
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1754
1586
  item_url: (_q = item.link) != null ? _q : null,
@@ -1778,8 +1610,8 @@ var HeadlessPdpZone = {
1778
1610
  }
1779
1611
  return null;
1780
1612
  },
1781
- brand: (context) => {
1782
- 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;
1783
1615
  if (context == null ? void 0 : context.products) {
1784
1616
  return context.products.map((p) => p.brand).join().trim();
1785
1617
  }
@@ -1808,8 +1640,8 @@ var HeadlessPdcZone = {
1808
1640
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1809
1641
  item_ref: null,
1810
1642
  // sem ref no retorno do IS na multi-lib produtos PDC
1811
- item_category: getItemCategory6(item),
1812
- item_category2: (_j = getItemCategory24(item)) != null ? _j : null,
1643
+ item_category: getItemCategory5(item),
1644
+ item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
1813
1645
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1814
1646
  item_sku: (_l = item.sku) != null ? _l : null,
1815
1647
  item_url: null,
@@ -1836,8 +1668,8 @@ var HeadlessPdcZone = {
1836
1668
  }
1837
1669
  return null;
1838
1670
  },
1839
- brand: (context) => {
1840
- 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;
1841
1673
  if (context == null ? void 0 : context.products) {
1842
1674
  return context.products.map((p) => p.brand.name).join().trim();
1843
1675
  }
@@ -1849,14 +1681,12 @@ var HeadlessPdcZone = {
1849
1681
  var headlessAdapter = {
1850
1682
  ...metaAdapters,
1851
1683
  // global adapters
1852
- ...orderFormAdapter,
1853
- // orderForm adapters, confirmar se no storefront tem evento que usa essses params
1854
- brand: (context) => {
1684
+ brand: (context, config2) => {
1855
1685
  if (context.zone === "PDP") {
1856
- return HeadlessPdpZone.brand(context);
1686
+ return HeadlessPdpZone.brand(context, config2);
1857
1687
  }
1858
1688
  if (context.zone === "PDC") {
1859
- return HeadlessPdcZone.brand(context);
1689
+ return HeadlessPdcZone.brand(context, config2);
1860
1690
  }
1861
1691
  return null;
1862
1692
  },
@@ -1925,10 +1755,10 @@ var pickupAdapter = {
1925
1755
  shippings: (context) => {
1926
1756
  if (context.shippings) {
1927
1757
  return context.shippings.map((s) => {
1928
- var _a, _b;
1758
+ var _a;
1929
1759
  return {
1930
1760
  line_items: (_a = s.line_items) != null ? _a : "",
1931
- shipping: (_b = s.price) != null ? _b : 0,
1761
+ shipping: s.price / 100,
1932
1762
  shipping_tier: getShippingTier(s),
1933
1763
  delivery_time: getDeliveryTime(s)
1934
1764
  };
@@ -1942,6 +1772,208 @@ var pickupAdapter = {
1942
1772
  }
1943
1773
  };
1944
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
+
1945
1977
  // src/formatter.ts
1946
1978
  var adapters = {
1947
1979
  DECO: decoAdapter,
@@ -1949,7 +1981,7 @@ var adapters = {
1949
1981
  PICKUP: pickupAdapter,
1950
1982
  ORDERFORM: orderFormAdapter
1951
1983
  };
1952
- async function getParameters(context, eventName) {
1984
+ async function getParameters(context, eventName, config2) {
1953
1985
  var _a;
1954
1986
  const eventConfig = EVENTS[eventName];
1955
1987
  if (!eventConfig) return;
@@ -1962,16 +1994,20 @@ async function getParameters(context, eventName) {
1962
1994
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
1963
1995
  return [param, null];
1964
1996
  }
1965
- return [param, await getter(context, eventName)];
1997
+ return [param, await getter(context, config2)];
1966
1998
  })
1967
1999
  );
1968
2000
  return Object.fromEntries(entries);
1969
2001
  }
1970
2002
 
1971
2003
  // src/index.ts
2004
+ var config = { brand: "", currency: "BRL" };
2005
+ function initTracker(c) {
2006
+ config = c;
2007
+ }
1972
2008
  async function trackWebEvent(event, context) {
1973
2009
  try {
1974
- const parameters = await getParameters(context, event);
2010
+ const parameters = await getParameters(context, event, config);
1975
2011
  if (isDebugMode()) {
1976
2012
  console.log(`[DT v2] ${event}, context e parameters: `, {
1977
2013
  context,
@@ -1993,6 +2029,7 @@ var src_default = {
1993
2029
  export {
1994
2030
  EVENTS,
1995
2031
  src_default as default,
2032
+ initTracker,
1996
2033
  trackWebEvent
1997
2034
  };
1998
2035
  //# sourceMappingURL=mod.js.map