@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.cjs CHANGED
@@ -1102,8 +1102,8 @@ function getPaymentType(context, eventName) {
1102
1102
 
1103
1103
  // src/params/userInfo.ts
1104
1104
  var PROD_DOMAINS = {
1105
- "animale": {
1106
- "store": "https://www.animale.com.br",
1105
+ "lojaanimale": {
1106
+ "store": "https://lojaanimale.myvtex.com",
1107
1107
  "checkout": "https://secure.animale.com.br"
1108
1108
  },
1109
1109
  "lojafarm": {
@@ -1516,10 +1516,10 @@ var getItemCategory3 = (item) => {
1516
1516
  };
1517
1517
  var getItemCategory22 = (item) => {
1518
1518
  var _a, _b, _c, _d;
1519
- const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
1519
+ const AVOID_CATEGORIES2 = /^(outlet|bazar|sale)$/i;
1520
1520
  const categories = (_b = (_a = item.category) == null ? void 0 : _a.split(">")) != null ? _b : [];
1521
1521
  const last = (_c = categories[categories.length - 1]) != null ? _c : "";
1522
- const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES.test(c));
1522
+ const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES2.test(c));
1523
1523
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1524
1524
  return capitalize(deepest);
1525
1525
  };
@@ -1627,9 +1627,9 @@ var getItemCategory5 = (item) => {
1627
1627
  };
1628
1628
  var getItemCategory23 = (item) => {
1629
1629
  var _a, _b, _c, _d;
1630
- const AVOID_CATEGORIES = /^(outlet|bazar|sale|coleção|promoção)$/i;
1630
+ const AVOID_CATEGORIES2 = /^(outlet|bazar|sale|coleção|promoção)$/i;
1631
1631
  const categories = (_c = (_b = (_a = item == null ? void 0 : item.similarItems) == null ? void 0 : _a[0]) == null ? void 0 : _b.categories) != null ? _c : [];
1632
- const validHierarchy = categories.filter((c) => c && !AVOID_CATEGORIES.test(c));
1632
+ const validHierarchy = categories.filter((c) => c && !AVOID_CATEGORIES2.test(c));
1633
1633
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1634
1634
  return capitalize(deepest);
1635
1635
  };
@@ -1715,8 +1715,222 @@ var reservaAdapter = {
1715
1715
  }
1716
1716
  };
1717
1717
 
1718
- // src/params/adapters/headless/utils.ts
1718
+ // src/params/adapters/animale/utils.ts
1719
+ var SALE_CATEGORIES = /outlet|bazar|sale/i;
1720
+ var AVOID_CATEGORIES = /^(outlet|bazar|sale|cole(ç|c)(ã|a)o)$/i;
1721
+ var getLevels = (path) => path.split("/").filter(Boolean);
1722
+ var isProductCrumb = (path) => /\/p\/?$/.test(path != null ? path : "");
1723
+ var getCategoryPaths = (item) => {
1724
+ var _a, _b, _c;
1725
+ if (item && "categories" in item && ((_a = item.categories) == null ? void 0 : _a.length)) return item.categories;
1726
+ const names = [...(_c = (_b = item == null ? void 0 : item.breadcrumbList) == null ? void 0 : _b.itemListElement) != null ? _c : []].sort((a, b) => {
1727
+ var _a2, _b2;
1728
+ return ((_a2 = a == null ? void 0 : a.position) != null ? _a2 : 0) - ((_b2 = b == null ? void 0 : b.position) != null ? _b2 : 0);
1729
+ }).filter((crumb) => (crumb == null ? void 0 : crumb.name) && !isProductCrumb(crumb == null ? void 0 : crumb.item)).map((crumb) => crumb.name.trim());
1730
+ return names.length ? [`/${names.join("/")}/`] : [];
1731
+ };
1719
1732
  var getItemCategory6 = (item) => {
1733
+ var _a;
1734
+ const categories = getCategoryPaths(item);
1735
+ if (!categories.length) return "Cole\xE7\xE3o";
1736
+ const match = (_a = categories.join(" ").match(SALE_CATEGORIES)) == null ? void 0 : _a[0].toLowerCase();
1737
+ return match != null ? match : "Cole\xE7\xE3o";
1738
+ };
1739
+ var getItemCategory24 = (item) => {
1740
+ const categories = getCategoryPaths(item);
1741
+ for (const path of [...categories].reverse()) {
1742
+ const deepest = getLevels(path).reverse().find((level) => !AVOID_CATEGORIES.test(level.trim()));
1743
+ if (deepest) return capitalize(deepest.trim());
1744
+ }
1745
+ return "";
1746
+ };
1747
+ var isInStock = (availability) => /InStock/i.test(availability != null ? availability : "");
1748
+
1749
+ // src/params/adapters/animale/zones/PDC.ts
1750
+ var AnimalePdcZone = {
1751
+ items: (context) => {
1752
+ if (context == null ? void 0 : context.items) return context.items;
1753
+ if (context == null ? void 0 : context.products) {
1754
+ return context.products.map((item) => {
1755
+ 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;
1756
+ const listPrice = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].listPrice;
1757
+ const price = (_d = (_c = item.offers) == null ? void 0 : _c.offers) == null ? void 0 : _d[0].price;
1758
+ 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;
1759
+ return {
1760
+ quantity: 1,
1761
+ index: (_i = item == null ? void 0 : item.index) != null ? _i : 0,
1762
+ item_brand: (_j = item.brand.name.toLowerCase()) != null ? _j : null,
1763
+ item_name: (_l = (_k = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _k.name) != null ? _l : null,
1764
+ price: price != null ? price : null,
1765
+ item_shipping_tier: null,
1766
+ discount: Number(listPrice) - Number(price),
1767
+ item_variant: (_o = (_n = (_m = item.isVariantOf) == null ? void 0 : _m.hasVariant) == null ? void 0 : _n[0].name.split(" - ")[0]) != null ? _o : null,
1768
+ item_variant2: (_r = (_q = ((_p = item.additionalProperty) != null ? _p : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _q.value) != null ? _r : null,
1769
+ item_ref: (_s = item == null ? void 0 : item.gtin) != null ? _s : null,
1770
+ item_category: getItemCategory6(item),
1771
+ item_category2: (_t = getItemCategory24(item)) != null ? _t : null,
1772
+ item_id: (_v = (_u = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _u.productGroupID) != null ? _v : null,
1773
+ item_sku: (_w = item == null ? void 0 : item.sku) != null ? _w : null,
1774
+ item_url: (_x = item == null ? void 0 : item.slug) != null ? _x : null,
1775
+ // sem link/url no retorno do IS na multi-lib produtos PDC
1776
+ image_url: (_z = resizeVtexImage2((_y = item == null ? void 0 : item.image) == null ? void 0 : _y[0].url)) != null ? _z : null,
1777
+ seller_id: sellerId != null ? sellerId : null,
1778
+ item_list_name: (_A = item.item_list_name) != null ? _A : null
1779
+ };
1780
+ });
1781
+ }
1782
+ return null;
1783
+ },
1784
+ value: (context) => {
1785
+ if (context == null ? void 0 : context.value) return context.value;
1786
+ if (context == null ? void 0 : context.products) {
1787
+ return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1788
+ }
1789
+ return null;
1790
+ },
1791
+ line_items: (context) => {
1792
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1793
+ if (context == null ? void 0 : context.products) {
1794
+ return context.products.map((item) => item.id).filter((id) => Boolean(id)).join();
1795
+ }
1796
+ return null;
1797
+ },
1798
+ brand: (context, config2) => {
1799
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1800
+ if (context == null ? void 0 : context.brand) return context.brand;
1801
+ if (context == null ? void 0 : context.products) {
1802
+ return context.products.map((p) => p.brand.name).join().trim();
1803
+ }
1804
+ return null;
1805
+ }
1806
+ };
1807
+
1808
+ // src/params/adapters/animale/zones/PDP.ts
1809
+ var AnimalePdpZone = {
1810
+ items: (context) => {
1811
+ if (context == null ? void 0 : context.items) return context.items;
1812
+ if (context == null ? void 0 : context.products) {
1813
+ return context.products.map((item) => {
1814
+ 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;
1815
+ const listPrice = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].listPrice;
1816
+ const price = (_d = (_c = item.offers) == null ? void 0 : _c.offers) == null ? void 0 : _d[0].price;
1817
+ const availableOffer = (_g = (_f = (_e = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _e.hasVariant) == null ? void 0 : _f.flatMap((v) => {
1818
+ var _a2, _b2;
1819
+ return (_b2 = (_a2 = v == null ? void 0 : v.offers) == null ? void 0 : _a2.offers) != null ? _b2 : [];
1820
+ })) == null ? void 0 : _g.find((o) => isInStock(o == null ? void 0 : o.availability));
1821
+ 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;
1822
+ return {
1823
+ quantity: 1,
1824
+ index: (_n = item == null ? void 0 : item.index) != null ? _n : 0,
1825
+ item_brand: (_o = item.brand.name.toLowerCase()) != null ? _o : null,
1826
+ item_name: (_q = (_p = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _p.name) != null ? _q : null,
1827
+ price: price != null ? price : null,
1828
+ item_shipping_tier: null,
1829
+ discount: Number(listPrice) - Number(price),
1830
+ item_variant: (_t = (_s = (_r = item.isVariantOf) == null ? void 0 : _r.hasVariant) == null ? void 0 : _s[0].name.split(" - ")[0]) != null ? _t : null,
1831
+ item_variant2: (_w = (_v = ((_u = item.additionalProperty) != null ? _u : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _v.value) != null ? _w : null,
1832
+ item_ref: (_x = item == null ? void 0 : item.gtin) != null ? _x : null,
1833
+ item_category: getItemCategory6(item),
1834
+ item_category2: (_y = getItemCategory24(item)) != null ? _y : null,
1835
+ item_id: (_A = (_z = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _z.productGroupID) != null ? _A : null,
1836
+ item_sku: (_B = item == null ? void 0 : item.sku) != null ? _B : null,
1837
+ item_url: (_C = item == null ? void 0 : item.slug) != null ? _C : null,
1838
+ // sem link/url no retorno do IS na multi-lib produtos PDC
1839
+ image_url: (_E = resizeVtexImage2((_D = item == null ? void 0 : item.image) == null ? void 0 : _D[0].url)) != null ? _E : null,
1840
+ seller_id: sellerId != null ? sellerId : null,
1841
+ item_list_name: (_F = item.item_list_name) != null ? _F : null
1842
+ };
1843
+ });
1844
+ }
1845
+ return null;
1846
+ },
1847
+ value: (context) => {
1848
+ if (context == null ? void 0 : context.value) return context.value;
1849
+ if (context == null ? void 0 : context.products) {
1850
+ return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1851
+ }
1852
+ return null;
1853
+ },
1854
+ line_items: (context) => {
1855
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1856
+ if (context == null ? void 0 : context.products) {
1857
+ return context.products.map((item) => item.id).filter((id) => Boolean(id)).join();
1858
+ }
1859
+ return null;
1860
+ },
1861
+ brand: (context, config2) => {
1862
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1863
+ if (context == null ? void 0 : context.brand) return context.brand;
1864
+ if (context == null ? void 0 : context.products) {
1865
+ return context.products.map((p) => p.brand.name).join().trim();
1866
+ }
1867
+ return null;
1868
+ }
1869
+ };
1870
+
1871
+ // src/params/adapters/animale/index.ts
1872
+ var animaleAdapter = {
1873
+ ...metaAdapter,
1874
+ // global adapters
1875
+ brand: (context, config2) => {
1876
+ if (context.zone === "PDP") {
1877
+ return AnimalePdpZone.brand(context, config2);
1878
+ }
1879
+ if (context.zone === "PDC") {
1880
+ return AnimalePdcZone.brand(context, config2);
1881
+ }
1882
+ return null;
1883
+ },
1884
+ line_items: (context) => {
1885
+ if (context.zone === "PDP") {
1886
+ return AnimalePdpZone.line_items(context);
1887
+ }
1888
+ if (context.zone === "PDC") {
1889
+ return AnimalePdcZone.line_items(context);
1890
+ }
1891
+ return null;
1892
+ },
1893
+ value: (context) => {
1894
+ if (context.zone === "PDP") {
1895
+ return AnimalePdpZone.value(context);
1896
+ }
1897
+ if (context.zone === "PDC") {
1898
+ return AnimalePdcZone.value(context);
1899
+ }
1900
+ return null;
1901
+ },
1902
+ items: (context) => {
1903
+ if (context.zone === "PDP") {
1904
+ return AnimalePdpZone.items(context);
1905
+ }
1906
+ if (context.zone === "PDC") {
1907
+ return AnimalePdcZone.items(context);
1908
+ }
1909
+ },
1910
+ // param used only in one Zone, the PDP; no need condition
1911
+ available_grid: (context) => {
1912
+ if (context == null ? void 0 : context.available_grid) return context.available_grid;
1913
+ if (context == null ? void 0 : context.products) {
1914
+ const sizes = context.products.flatMap(
1915
+ (p) => {
1916
+ var _a, _b;
1917
+ return ((_b = (_a = p == null ? void 0 : p.isVariantOf) == null ? void 0 : _a.hasVariant) != null ? _b : []).flatMap((variant) => {
1918
+ var _a2, _b2, _c, _d;
1919
+ 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));
1920
+ 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;
1921
+ return available && size ? [size] : [];
1922
+ });
1923
+ }
1924
+ );
1925
+ const result = sortSizes(sizes).join(",");
1926
+ return result || null;
1927
+ }
1928
+ return null;
1929
+ }
1930
+ };
1931
+
1932
+ // src/params/adapters/headless/utils.ts
1933
+ var getItemCategory7 = (item) => {
1720
1934
  const keywords = ["outlet", "bazar", "sale"];
1721
1935
  const regex = new RegExp(keywords.join("|"), "i");
1722
1936
  const value = item == null ? void 0 : item.categories;
@@ -1729,7 +1943,7 @@ var getItemCategory6 = (item) => {
1729
1943
  }
1730
1944
  return "Cole\xE7\xE3o";
1731
1945
  };
1732
- var getItemCategory24 = (item) => {
1946
+ var getItemCategory25 = (item) => {
1733
1947
  var _a, _b, _c;
1734
1948
  const avoidList = /outlet|bazar|sale/i;
1735
1949
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1759,8 +1973,8 @@ var HeadlessPdpZone = {
1759
1973
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1760
1974
  item_ref: (_l = item.productReference) != null ? _l : null,
1761
1975
  // sem ref no retorno do IS na multi-lib produtos PDC
1762
- item_category: getItemCategory6(item),
1763
- item_category2: (_m = getItemCategory24(item)) != null ? _m : null,
1976
+ item_category: getItemCategory7(item),
1977
+ item_category2: (_m = getItemCategory25(item)) != null ? _m : null,
1764
1978
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1765
1979
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1766
1980
  item_url: (_q = item.link) != null ? _q : null,
@@ -1821,8 +2035,8 @@ var HeadlessPdcZone = {
1821
2035
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1822
2036
  item_ref: null,
1823
2037
  // sem ref no retorno do IS na multi-lib produtos PDC
1824
- item_category: getItemCategory6(item),
1825
- item_category2: (_j = getItemCategory24(item)) != null ? _j : null,
2038
+ item_category: getItemCategory7(item),
2039
+ item_category2: (_j = getItemCategory25(item)) != null ? _j : null,
1826
2040
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1827
2041
  item_sku: (_l = item.sku) != null ? _l : null,
1828
2042
  item_url: null,
@@ -1968,7 +2182,7 @@ var getOrderFormItems = (orderForm) => {
1968
2182
  return { ...i, quantity: 1 };
1969
2183
  }) : orderForm.items;
1970
2184
  };
1971
- var getItemCategory7 = (item) => {
2185
+ var getItemCategory8 = (item) => {
1972
2186
  var _a;
1973
2187
  const categories = item == null ? void 0 : item.productCategories;
1974
2188
  if (!categories) return "Cole\xE7\xE3o";
@@ -1976,11 +2190,11 @@ var getItemCategory7 = (item) => {
1976
2190
  const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1977
2191
  return match != null ? match : "Cole\xE7\xE3o";
1978
2192
  };
1979
- var getItemCategory25 = (item) => {
2193
+ var getItemCategory26 = (item) => {
1980
2194
  var _a, _b;
1981
- const AVOID_CATEGORIES = /outlet|bazar|sale|coleção|promoção/i;
2195
+ const AVOID_CATEGORIES2 = /outlet|bazar|sale|coleção|promoção/i;
1982
2196
  const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1983
- const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
2197
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES2.test(c));
1984
2198
  const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1985
2199
  return capitalize(deepest);
1986
2200
  };
@@ -2027,12 +2241,12 @@ var orderFormAdapter = {
2027
2241
  item_name: (_l = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _l : null,
2028
2242
  price: (item == null ? void 0 : item.sellingPrice) / 100,
2029
2243
  discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
2030
- item_variant: (_m = color == null ? void 0 : color.toUpperCase()) != null ? _m : null,
2031
- item_variant2: size != null ? size : null,
2244
+ item_variant: color != null ? color : null,
2245
+ item_variant2: (_m = size == null ? void 0 : size.toUpperCase()) != null ? _m : null,
2032
2246
  item_shipping_tier: getItemShippingTier2(context.orderForm, item),
2033
2247
  item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
2034
- item_category: (_n = getItemCategory7(item)) != null ? _n : null,
2035
- item_category2: (_o = getItemCategory25(item)) != null ? _o : null,
2248
+ item_category: (_n = getItemCategory8(item)) != null ? _n : null,
2249
+ item_category2: (_o = getItemCategory26(item)) != null ? _o : null,
2036
2250
  item_id: (_p = item == null ? void 0 : item.productId) != null ? _p : null,
2037
2251
  item_sku: (_q = item == null ? void 0 : item.id) != null ? _q : null,
2038
2252
  item_url: (_r = item.detailUrl) != null ? _r : null,
@@ -2277,7 +2491,8 @@ var adapters = {
2277
2491
  HEADLESS: headlessAdapter,
2278
2492
  PICKUP: pickupAdapter,
2279
2493
  ORDERFORM: orderFormAdapter,
2280
- META: metaAdapter
2494
+ META: metaAdapter,
2495
+ ANIMALE: animaleAdapter
2281
2496
  };
2282
2497
  async function getParameters(context, eventName, config2) {
2283
2498
  var _a;
@@ -2321,7 +2536,7 @@ async function trackWebEvent(event, context) {
2321
2536
  }
2322
2537
  if (isDebugMode()) {
2323
2538
  console.log(
2324
- `%c [DT v2] %c ${event} `,
2539
+ `%c [DT v2 - Animale Preview] %c ${event} `,
2325
2540
  "background: #6366f1; color: #fff; font-weight: bold; padding: 2px 6px; border-radius: 4px 0 0 4px;",
2326
2541
  "background: #1e1e2e; color: #a5b4fc; font-weight: bold; padding: 2px 6px; border-radius: 0 4px 4px 0;",
2327
2542
  { context, parameters }