@azzas/azzas-tracker-web 2.0.3-preview.0 → 2.0.3-preview.2

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
@@ -1073,8 +1073,8 @@ function getPaymentType(context, eventName) {
1073
1073
 
1074
1074
  // src/params/userInfo.ts
1075
1075
  var PROD_DOMAINS = {
1076
- "animale": {
1077
- "store": "https://www.animale.com.br",
1076
+ "lojaanimale": {
1077
+ "store": "https://lojaanimale.myvtex.com",
1078
1078
  "checkout": "https://secure.animale.com.br"
1079
1079
  },
1080
1080
  "lojafarm": {
@@ -1487,10 +1487,10 @@ var getItemCategory3 = (item) => {
1487
1487
  };
1488
1488
  var getItemCategory22 = (item) => {
1489
1489
  var _a, _b, _c, _d;
1490
- const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
1490
+ const AVOID_CATEGORIES2 = /^(outlet|bazar|sale)$/i;
1491
1491
  const categories = (_b = (_a = item.category) == null ? void 0 : _a.split(">")) != null ? _b : [];
1492
1492
  const last = (_c = categories[categories.length - 1]) != null ? _c : "";
1493
- const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES.test(c));
1493
+ const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES2.test(c));
1494
1494
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1495
1495
  return capitalize(deepest);
1496
1496
  };
@@ -1598,9 +1598,9 @@ var getItemCategory5 = (item) => {
1598
1598
  };
1599
1599
  var getItemCategory23 = (item) => {
1600
1600
  var _a, _b, _c, _d;
1601
- const AVOID_CATEGORIES = /^(outlet|bazar|sale|coleção|promoção)$/i;
1601
+ const AVOID_CATEGORIES2 = /^(outlet|bazar|sale|coleção|promoção)$/i;
1602
1602
  const categories = (_c = (_b = (_a = item == null ? void 0 : item.similarItems) == null ? void 0 : _a[0]) == null ? void 0 : _b.categories) != null ? _c : [];
1603
- const validHierarchy = categories.filter((c) => c && !AVOID_CATEGORIES.test(c));
1603
+ const validHierarchy = categories.filter((c) => c && !AVOID_CATEGORIES2.test(c));
1604
1604
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1605
1605
  return capitalize(deepest);
1606
1606
  };
@@ -1686,8 +1686,222 @@ var reservaAdapter = {
1686
1686
  }
1687
1687
  };
1688
1688
 
1689
- // src/params/adapters/headless/utils.ts
1689
+ // src/params/adapters/animale/utils.ts
1690
+ var SALE_CATEGORIES = /outlet|bazar|sale/i;
1691
+ var AVOID_CATEGORIES = /^(outlet|bazar|sale|cole(ç|c)(ã|a)o)$/i;
1692
+ var getLevels = (path) => path.split("/").filter(Boolean);
1693
+ var isProductCrumb = (path) => /\/p\/?$/.test(path != null ? path : "");
1694
+ var getCategoryPaths = (item) => {
1695
+ var _a, _b, _c;
1696
+ if (item && "categories" in item && ((_a = item.categories) == null ? void 0 : _a.length)) return item.categories;
1697
+ const names = [...(_c = (_b = item == null ? void 0 : item.breadcrumbList) == null ? void 0 : _b.itemListElement) != null ? _c : []].sort((a, b) => {
1698
+ var _a2, _b2;
1699
+ return ((_a2 = a == null ? void 0 : a.position) != null ? _a2 : 0) - ((_b2 = b == null ? void 0 : b.position) != null ? _b2 : 0);
1700
+ }).filter((crumb) => (crumb == null ? void 0 : crumb.name) && !isProductCrumb(crumb == null ? void 0 : crumb.item)).map((crumb) => crumb.name.trim());
1701
+ return names.length ? [`/${names.join("/")}/`] : [];
1702
+ };
1690
1703
  var getItemCategory6 = (item) => {
1704
+ var _a;
1705
+ const categories = getCategoryPaths(item);
1706
+ if (!categories.length) return "Cole\xE7\xE3o";
1707
+ const match = (_a = categories.join(" ").match(SALE_CATEGORIES)) == null ? void 0 : _a[0].toLowerCase();
1708
+ return match != null ? match : "Cole\xE7\xE3o";
1709
+ };
1710
+ var getItemCategory24 = (item) => {
1711
+ const categories = getCategoryPaths(item);
1712
+ for (const path of [...categories].reverse()) {
1713
+ const deepest = getLevels(path).reverse().find((level) => !AVOID_CATEGORIES.test(level.trim()));
1714
+ if (deepest) return capitalize(deepest.trim());
1715
+ }
1716
+ return "";
1717
+ };
1718
+ var isInStock = (availability) => /InStock/i.test(availability != null ? availability : "");
1719
+
1720
+ // src/params/adapters/animale/zones/PDC.ts
1721
+ var AnimalePdcZone = {
1722
+ items: (context) => {
1723
+ if (context == null ? void 0 : context.items) return context.items;
1724
+ if (context == null ? void 0 : context.products) {
1725
+ return context.products.map((item) => {
1726
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
1727
+ const listPrice = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].listPrice;
1728
+ const price = (_d = (_c = item.offers) == null ? void 0 : _c.offers) == null ? void 0 : _d[0].price;
1729
+ const sellerId = (_h = (_g = (_f = (_e = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _e.hasVariant) == null ? void 0 : _f.find((v) => v.offers.offers.find((o) => o.availability))) == null ? void 0 : _g.offers.offers[0]) == null ? void 0 : _h.seller.identifier;
1730
+ return {
1731
+ quantity: 1,
1732
+ index: (_i = item == null ? void 0 : item.index) != null ? _i : 0,
1733
+ item_brand: (_j = item.brand.name.toLowerCase()) != null ? _j : null,
1734
+ item_name: (_l = (_k = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _k.name) != null ? _l : null,
1735
+ price: price != null ? price : null,
1736
+ item_shipping_tier: null,
1737
+ discount: Number(listPrice) - Number(price),
1738
+ item_variant: (_o = (_n = (_m = item.isVariantOf) == null ? void 0 : _m.hasVariant) == null ? void 0 : _n[0].name.split(" - ")[0]) != null ? _o : null,
1739
+ item_variant2: (_r = (_q = ((_p = item.additionalProperty) != null ? _p : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _q.value) != null ? _r : null,
1740
+ item_ref: (_s = item == null ? void 0 : item.gtin) != null ? _s : null,
1741
+ item_category: getItemCategory6(item),
1742
+ item_category2: (_t = getItemCategory24(item)) != null ? _t : null,
1743
+ item_id: (_v = (_u = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _u.productGroupID) != null ? _v : null,
1744
+ item_sku: (_w = item == null ? void 0 : item.sku) != null ? _w : null,
1745
+ item_url: (_x = item == null ? void 0 : item.slug) != null ? _x : null,
1746
+ // sem link/url no retorno do IS na multi-lib produtos PDC
1747
+ image_url: (_z = resizeVtexImage2((_y = item == null ? void 0 : item.image) == null ? void 0 : _y[0].url)) != null ? _z : null,
1748
+ seller_id: sellerId != null ? sellerId : null,
1749
+ item_list_name: (_A = item.item_list_name) != null ? _A : null
1750
+ };
1751
+ });
1752
+ }
1753
+ return null;
1754
+ },
1755
+ value: (context) => {
1756
+ if (context == null ? void 0 : context.value) return context.value;
1757
+ if (context == null ? void 0 : context.products) {
1758
+ return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1759
+ }
1760
+ return null;
1761
+ },
1762
+ line_items: (context) => {
1763
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1764
+ if (context == null ? void 0 : context.products) {
1765
+ return context.products.map((item) => item.id).filter((id) => Boolean(id)).join();
1766
+ }
1767
+ return null;
1768
+ },
1769
+ brand: (context, config2) => {
1770
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1771
+ if (context == null ? void 0 : context.brand) return context.brand;
1772
+ if (context == null ? void 0 : context.products) {
1773
+ return context.products.map((p) => p.brand.name).join().trim();
1774
+ }
1775
+ return null;
1776
+ }
1777
+ };
1778
+
1779
+ // src/params/adapters/animale/zones/PDP.ts
1780
+ var AnimalePdpZone = {
1781
+ items: (context) => {
1782
+ if (context == null ? void 0 : context.items) return context.items;
1783
+ if (context == null ? void 0 : context.products) {
1784
+ return context.products.map((item) => {
1785
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
1786
+ const listPrice = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].listPrice;
1787
+ const price = (_d = (_c = item.offers) == null ? void 0 : _c.offers) == null ? void 0 : _d[0].price;
1788
+ const availableOffer = (_g = (_f = (_e = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _e.hasVariant) == null ? void 0 : _f.flatMap((v) => {
1789
+ var _a2, _b2;
1790
+ return (_b2 = (_a2 = v == null ? void 0 : v.offers) == null ? void 0 : _a2.offers) != null ? _b2 : [];
1791
+ })) == null ? void 0 : _g.find((o) => isInStock(o == null ? void 0 : o.availability));
1792
+ const sellerId = (_m = (_h = availableOffer == null ? void 0 : availableOffer.seller) == null ? void 0 : _h.identifier) != null ? _m : (_l = (_k = (_j = (_i = item == null ? void 0 : item.offers) == null ? void 0 : _i.offers) == null ? void 0 : _j[0]) == null ? void 0 : _k.seller) == null ? void 0 : _l.identifier;
1793
+ return {
1794
+ quantity: 1,
1795
+ index: (_n = item == null ? void 0 : item.index) != null ? _n : 0,
1796
+ item_brand: (_o = item.brand.name.toLowerCase()) != null ? _o : null,
1797
+ item_name: (_q = (_p = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _p.name) != null ? _q : null,
1798
+ price: price != null ? price : null,
1799
+ item_shipping_tier: null,
1800
+ discount: Number(listPrice) - Number(price),
1801
+ item_variant: (_t = (_s = (_r = item.isVariantOf) == null ? void 0 : _r.hasVariant) == null ? void 0 : _s[0].name.split(" - ")[0]) != null ? _t : null,
1802
+ item_variant2: (_w = (_v = ((_u = item.additionalProperty) != null ? _u : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _v.value) != null ? _w : null,
1803
+ item_ref: (_x = item == null ? void 0 : item.gtin) != null ? _x : null,
1804
+ item_category: getItemCategory6(item),
1805
+ item_category2: (_y = getItemCategory24(item)) != null ? _y : null,
1806
+ item_id: (_A = (_z = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _z.productGroupID) != null ? _A : null,
1807
+ item_sku: (_B = item == null ? void 0 : item.sku) != null ? _B : null,
1808
+ item_url: (_C = item == null ? void 0 : item.slug) != null ? _C : null,
1809
+ // sem link/url no retorno do IS na multi-lib produtos PDC
1810
+ image_url: (_E = resizeVtexImage2((_D = item == null ? void 0 : item.image) == null ? void 0 : _D[0].url)) != null ? _E : null,
1811
+ seller_id: sellerId != null ? sellerId : null,
1812
+ item_list_name: (_F = item.item_list_name) != null ? _F : null
1813
+ };
1814
+ });
1815
+ }
1816
+ return null;
1817
+ },
1818
+ value: (context) => {
1819
+ if (context == null ? void 0 : context.value) return context.value;
1820
+ if (context == null ? void 0 : context.products) {
1821
+ return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1822
+ }
1823
+ return null;
1824
+ },
1825
+ line_items: (context) => {
1826
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1827
+ if (context == null ? void 0 : context.products) {
1828
+ return context.products.map((item) => item.id).filter((id) => Boolean(id)).join();
1829
+ }
1830
+ return null;
1831
+ },
1832
+ brand: (context, config2) => {
1833
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1834
+ if (context == null ? void 0 : context.brand) return context.brand;
1835
+ if (context == null ? void 0 : context.products) {
1836
+ return context.products.map((p) => p.brand.name).join().trim();
1837
+ }
1838
+ return null;
1839
+ }
1840
+ };
1841
+
1842
+ // src/params/adapters/animale/index.ts
1843
+ var animaleAdapter = {
1844
+ ...metaAdapter,
1845
+ // global adapters
1846
+ brand: (context, config2) => {
1847
+ if (context.zone === "PDP") {
1848
+ return AnimalePdpZone.brand(context, config2);
1849
+ }
1850
+ if (context.zone === "PDC") {
1851
+ return AnimalePdcZone.brand(context, config2);
1852
+ }
1853
+ return null;
1854
+ },
1855
+ line_items: (context) => {
1856
+ if (context.zone === "PDP") {
1857
+ return AnimalePdpZone.line_items(context);
1858
+ }
1859
+ if (context.zone === "PDC") {
1860
+ return AnimalePdcZone.line_items(context);
1861
+ }
1862
+ return null;
1863
+ },
1864
+ value: (context) => {
1865
+ if (context.zone === "PDP") {
1866
+ return AnimalePdpZone.value(context);
1867
+ }
1868
+ if (context.zone === "PDC") {
1869
+ return AnimalePdcZone.value(context);
1870
+ }
1871
+ return null;
1872
+ },
1873
+ items: (context) => {
1874
+ if (context.zone === "PDP") {
1875
+ return AnimalePdpZone.items(context);
1876
+ }
1877
+ if (context.zone === "PDC") {
1878
+ return AnimalePdcZone.items(context);
1879
+ }
1880
+ },
1881
+ // param used only in one Zone, the PDP; no need condition
1882
+ available_grid: (context) => {
1883
+ if (context == null ? void 0 : context.available_grid) return context.available_grid;
1884
+ if (context == null ? void 0 : context.products) {
1885
+ const sizes = context.products.flatMap(
1886
+ (p) => {
1887
+ var _a, _b;
1888
+ return ((_b = (_a = p == null ? void 0 : p.isVariantOf) == null ? void 0 : _a.hasVariant) != null ? _b : []).flatMap((variant) => {
1889
+ var _a2, _b2, _c, _d;
1890
+ const available = (_b2 = (_a2 = variant == null ? void 0 : variant.offers) == null ? void 0 : _a2.offers) == null ? void 0 : _b2.some((o) => isInStock(o == null ? void 0 : o.availability));
1891
+ const size = (_d = (_c = variant == null ? void 0 : variant.additionalProperty) == null ? void 0 : _c.find((prop) => (prop == null ? void 0 : prop.name) === "Tamanho")) == null ? void 0 : _d.value;
1892
+ return available && size ? [size] : [];
1893
+ });
1894
+ }
1895
+ );
1896
+ const result = sortSizes(sizes).join(",");
1897
+ return result || null;
1898
+ }
1899
+ return null;
1900
+ }
1901
+ };
1902
+
1903
+ // src/params/adapters/headless/utils.ts
1904
+ var getItemCategory7 = (item) => {
1691
1905
  const keywords = ["outlet", "bazar", "sale"];
1692
1906
  const regex = new RegExp(keywords.join("|"), "i");
1693
1907
  const value = item == null ? void 0 : item.categories;
@@ -1700,7 +1914,7 @@ var getItemCategory6 = (item) => {
1700
1914
  }
1701
1915
  return "Cole\xE7\xE3o";
1702
1916
  };
1703
- var getItemCategory24 = (item) => {
1917
+ var getItemCategory25 = (item) => {
1704
1918
  var _a, _b, _c;
1705
1919
  const avoidList = /outlet|bazar|sale/i;
1706
1920
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1730,8 +1944,8 @@ var HeadlessPdpZone = {
1730
1944
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1731
1945
  item_ref: (_l = item.productReference) != null ? _l : null,
1732
1946
  // sem ref no retorno do IS na multi-lib produtos PDC
1733
- item_category: getItemCategory6(item),
1734
- item_category2: (_m = getItemCategory24(item)) != null ? _m : null,
1947
+ item_category: getItemCategory7(item),
1948
+ item_category2: (_m = getItemCategory25(item)) != null ? _m : null,
1735
1949
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1736
1950
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1737
1951
  item_url: (_q = item.link) != null ? _q : null,
@@ -1792,8 +2006,8 @@ var HeadlessPdcZone = {
1792
2006
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1793
2007
  item_ref: null,
1794
2008
  // sem ref no retorno do IS na multi-lib produtos PDC
1795
- item_category: getItemCategory6(item),
1796
- item_category2: (_j = getItemCategory24(item)) != null ? _j : null,
2009
+ item_category: getItemCategory7(item),
2010
+ item_category2: (_j = getItemCategory25(item)) != null ? _j : null,
1797
2011
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1798
2012
  item_sku: (_l = item.sku) != null ? _l : null,
1799
2013
  item_url: null,
@@ -1939,7 +2153,7 @@ var getOrderFormItems = (orderForm) => {
1939
2153
  return { ...i, quantity: 1 };
1940
2154
  }) : orderForm.items;
1941
2155
  };
1942
- var getItemCategory7 = (item) => {
2156
+ var getItemCategory8 = (item) => {
1943
2157
  var _a;
1944
2158
  const categories = item == null ? void 0 : item.productCategories;
1945
2159
  if (!categories) return "Cole\xE7\xE3o";
@@ -1947,11 +2161,11 @@ var getItemCategory7 = (item) => {
1947
2161
  const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1948
2162
  return match != null ? match : "Cole\xE7\xE3o";
1949
2163
  };
1950
- var getItemCategory25 = (item) => {
2164
+ var getItemCategory26 = (item) => {
1951
2165
  var _a, _b;
1952
- const AVOID_CATEGORIES = /outlet|bazar|sale|coleção|promoção/i;
2166
+ const AVOID_CATEGORIES2 = /outlet|bazar|sale|coleção|promoção/i;
1953
2167
  const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1954
- const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
2168
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES2.test(c));
1955
2169
  const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1956
2170
  return capitalize(deepest);
1957
2171
  };
@@ -1998,12 +2212,12 @@ var orderFormAdapter = {
1998
2212
  item_name: (_l = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _l : null,
1999
2213
  price: (item == null ? void 0 : item.sellingPrice) / 100,
2000
2214
  discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
2001
- item_variant: (_m = color == null ? void 0 : color.toUpperCase()) != null ? _m : null,
2002
- item_variant2: size != null ? size : null,
2215
+ item_variant: color != null ? color : null,
2216
+ item_variant2: (_m = size == null ? void 0 : size.toUpperCase()) != null ? _m : null,
2003
2217
  item_shipping_tier: getItemShippingTier2(context.orderForm, item),
2004
2218
  item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
2005
- item_category: (_n = getItemCategory7(item)) != null ? _n : null,
2006
- item_category2: (_o = getItemCategory25(item)) != null ? _o : null,
2219
+ item_category: (_n = getItemCategory8(item)) != null ? _n : null,
2220
+ item_category2: (_o = getItemCategory26(item)) != null ? _o : null,
2007
2221
  item_id: (_p = item == null ? void 0 : item.productId) != null ? _p : null,
2008
2222
  item_sku: (_q = item == null ? void 0 : item.id) != null ? _q : null,
2009
2223
  item_url: (_r = item.detailUrl) != null ? _r : null,
@@ -2248,7 +2462,8 @@ var adapters = {
2248
2462
  HEADLESS: headlessAdapter,
2249
2463
  PICKUP: pickupAdapter,
2250
2464
  ORDERFORM: orderFormAdapter,
2251
- META: metaAdapter
2465
+ META: metaAdapter,
2466
+ ANIMALE: animaleAdapter
2252
2467
  };
2253
2468
  async function getParameters(context, eventName, config2) {
2254
2469
  var _a;
@@ -2292,7 +2507,7 @@ async function trackWebEvent(event, context) {
2292
2507
  }
2293
2508
  if (isDebugMode()) {
2294
2509
  console.log(
2295
- `%c [DT v2] %c ${event} `,
2510
+ `%c [DT v2 - Animale Preview] %c ${event} `,
2296
2511
  "background: #6366f1; color: #fff; font-weight: bold; padding: 2px 6px; border-radius: 4px 0 0 4px;",
2297
2512
  "background: #1e1e2e; color: #a5b4fc; font-weight: bold; padding: 2px 6px; border-radius: 0 4px 4px 0;",
2298
2513
  { context, parameters }