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

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
  },
@@ -1411,8 +1411,36 @@ var getItemCategory22 = (item) => {
1411
1411
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1412
1412
  return capitalize(deepest);
1413
1413
  };
1414
- function getItemShippingTier2() {
1415
- return null;
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;
1416
1444
  }
1417
1445
 
1418
1446
  // src/params/adapters/deco/index.ts
@@ -1441,7 +1469,7 @@ var decoAdapter = {
1441
1469
  // cor
1442
1470
  item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
1443
1471
  // tamanho
1444
- item_shipping_tier: getItemShippingTier2(),
1472
+ item_shipping_tier: "",
1445
1473
  item_ref: (_s = (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find((i) => i.name === "RefId")) == null ? void 0 : _q.value) == null ? void 0 : _r.replace(/_\d+$/, "")) != null ? _s : null,
1446
1474
  item_category: (_t = getItemCategory3(item)) != null ? _t : null,
1447
1475
  item_category2: (_u = getItemCategory22(item)) != null ? _u : null,
@@ -1456,13 +1484,16 @@ var decoAdapter = {
1456
1484
  }
1457
1485
  return null;
1458
1486
  },
1459
- // brand: (context: DecoBrandContext) => {
1460
- // if (context?.brand) return context.brand
1461
- // if (context?.products) {
1462
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1463
- // }
1464
- // return null
1465
- // },
1487
+ brand: (context) => {
1488
+ if (context == null ? void 0 : context.brand) return context.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
+ },
1466
1497
  line_items: (context) => {
1467
1498
  if (context == null ? void 0 : context.line_items) return context.line_items;
1468
1499
  if (context == null ? void 0 : context.products) {
@@ -1521,6 +1552,14 @@ var getItemCategory23 = (item) => {
1521
1552
  const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1522
1553
  return capitalize(deepest);
1523
1554
  };
1555
+ function getItemShippingTier2(orderForm, item) {
1556
+ var _a, _b, _c, _d;
1557
+ const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1558
+ (li) => li.itemId === item.id
1559
+ );
1560
+ const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1561
+ return ((_d = selectedSla == null ? void 0 : selectedSla.pickupStoreInfo) == null ? void 0 : _d.friendlyName) ? `retirada em loja: ${selectedSla.pickupStoreInfo.friendlyName}` : (selectedSla == null ? void 0 : selectedSla.name) ? `Receba em casa: ${selectedSla.name}` : null;
1562
+ }
1524
1563
  var getOrderFormItems = (orderForm) => {
1525
1564
  const idSelected = orderForm == null ? void 0 : orderForm.selected;
1526
1565
  return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
@@ -1543,7 +1582,7 @@ var orderFormAdapter = {
1543
1582
  discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1544
1583
  item_variant: (_k = (_j = (_i = (_h = item == null ? void 0 : item.skuName) == null ? void 0 : _h.split(" - ")[0]) == null ? void 0 : _i.split("_").pop()) == null ? void 0 : _j.trim()) != null ? _k : null,
1545
1584
  item_variant2: (_n = (_m = (_l = item == null ? void 0 : item.skuName) == null ? void 0 : _l.split(" - ")[1]) == null ? void 0 : _m.trim()) != null ? _n : null,
1546
- item_shipping_tier: "",
1585
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1547
1586
  item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1548
1587
  item_category: (_o = getItemCategory5(item)) != null ? _o : null,
1549
1588
  item_category2: (_p = getItemCategory23(item)) != null ? _p : null,
@@ -1558,13 +1597,13 @@ var orderFormAdapter = {
1558
1597
  }
1559
1598
  return null;
1560
1599
  },
1561
- // brand: (context: any) => {
1562
- // if (context?.brand) return context.brand
1563
- // if (context?.products) {
1564
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1565
- // }
1566
- // return null
1567
- // },
1600
+ brand: (context) => {
1601
+ var _a;
1602
+ if (context == null ? void 0 : context.brand) return context.brand;
1603
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1604
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1605
+ return normalizeBrand2(brands);
1606
+ },
1568
1607
  line_items: (context) => {
1569
1608
  var _a;
1570
1609
  if (context == null ? void 0 : context.line_items) return context.line_items;
@@ -1580,10 +1619,10 @@ var orderFormAdapter = {
1580
1619
  payment_type: getPaymentType,
1581
1620
  total_discount: (context) => {
1582
1621
  var _a, _b;
1583
- if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
1584
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1585
- const items = context.orderForm.items;
1586
- const totalDiscount = items.reduce((acc, item) => {
1622
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1623
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1624
+ const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1625
+ const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1587
1626
  const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1588
1627
  return acc + unitDiscount * item.quantity;
1589
1628
  }, 0);
@@ -1920,10 +1959,10 @@ var pickupAdapter = {
1920
1959
  shippings: (context) => {
1921
1960
  if (context.shippings) {
1922
1961
  return context.shippings.map((s) => {
1923
- var _a, _b;
1962
+ var _a;
1924
1963
  return {
1925
1964
  line_items: (_a = s.line_items) != null ? _a : "",
1926
- shipping: (_b = s.price) != null ? _b : 0,
1965
+ shipping: s.price / 100,
1927
1966
  shipping_tier: getShippingTier(s),
1928
1967
  delivery_time: getDeliveryTime(s)
1929
1968
  };