@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.
@@ -1308,8 +1308,47 @@ var AzzasTracker = function() {
1308
1308
  });
1309
1309
  })();
1310
1310
  };
1311
- var getItemShippingTier2 = function getItemShippingTier2() {
1312
- return null;
1311
+ var getBrandCode2 = function getBrandCode2(brand) {
1312
+ if (!brand) return null;
1313
+ var standardized = brand.toLowerCase().trim();
1314
+ return BRAND_CODES2[standardized] || null;
1315
+ };
1316
+ var normalizeBrand2 = function normalizeBrand2(input) {
1317
+ var brandStrings = [];
1318
+ if (Array.isArray(input) && input.every(function(item) {
1319
+ return typeof item === "string";
1320
+ })) {
1321
+ brandStrings = input;
1322
+ } else if (Array.isArray(input)) {
1323
+ brandStrings = input.map(function(item) {
1324
+ var _item_additionalInfo;
1325
+ return ((_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) || item.brand;
1326
+ });
1327
+ } else if ((typeof input === "undefined" ? "undefined" : _type_of(input)) === "object" && input !== null && "brand" in input) {
1328
+ var _input_additionalInfo;
1329
+ brandStrings = [
1330
+ ((_input_additionalInfo = input.additionalInfo) === null || _input_additionalInfo === void 0 ? void 0 : _input_additionalInfo.brandName) || input.brand
1331
+ ];
1332
+ } else if (typeof input === "string") {
1333
+ return getBrandCode2(input);
1334
+ } else {
1335
+ return null;
1336
+ }
1337
+ var brandCodes = brandStrings.map(getBrandCode2).filter(function(code) {
1338
+ return code !== null;
1339
+ });
1340
+ var uniqueSortedCodes = _to_consumable_array(new Set(brandCodes)).sort();
1341
+ return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
1342
+ };
1343
+ var getItemShippingTier2 = function getItemShippingTier2(orderForm, item) {
1344
+ var _orderForm_shippingData_logisticsInfo, _orderForm_shippingData, _info_slas, _selectedSla_pickupStoreInfo;
1345
+ var info = orderForm === null || orderForm === void 0 ? void 0 : (_orderForm_shippingData = orderForm.shippingData) === null || _orderForm_shippingData === void 0 ? void 0 : (_orderForm_shippingData_logisticsInfo = _orderForm_shippingData.logisticsInfo) === null || _orderForm_shippingData_logisticsInfo === void 0 ? void 0 : _orderForm_shippingData_logisticsInfo.find(function(li) {
1346
+ return li.itemId === item.id;
1347
+ });
1348
+ var selectedSla = info === null || info === void 0 ? void 0 : (_info_slas = info.slas) === null || _info_slas === void 0 ? void 0 : _info_slas.find(function(sla) {
1349
+ return sla.id === info.selectedSla;
1350
+ });
1351
+ return (selectedSla === null || selectedSla === void 0 ? void 0 : (_selectedSla_pickupStoreInfo = selectedSla.pickupStoreInfo) === null || _selectedSla_pickupStoreInfo === void 0 ? void 0 : _selectedSla_pickupStoreInfo.friendlyName) ? "retirada em loja: ".concat(selectedSla.pickupStoreInfo.friendlyName) : (selectedSla === null || selectedSla === void 0 ? void 0 : selectedSla.name) ? "Receba em casa: ".concat(selectedSla.name) : null;
1313
1352
  };
1314
1353
  var getParameters = function getParameters(context, eventName) {
1315
1354
  return _async_to_generator(function() {
@@ -2395,9 +2434,9 @@ var AzzasTracker = function() {
2395
2434
  // src/params/adapters/meta/index.ts
2396
2435
  var metaAdapters = {
2397
2436
  user_info: getUserInfo,
2398
- brand: function(context) {
2399
- return context.meta.brand || null;
2400
- },
2437
+ // brand: (context: MetaBrandContext) => {
2438
+ // return context.meta.brand || null;
2439
+ // },
2401
2440
  content_type: function(context) {
2402
2441
  return context.meta.content_type || null;
2403
2442
  },
@@ -2479,6 +2518,11 @@ var AzzasTracker = function() {
2479
2518
  var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
2480
2519
  return capitalize(deepest);
2481
2520
  };
2521
+ var BRAND_CODES2 = {
2522
+ farm: "farmrio",
2523
+ "farm etc": "farmetc",
2524
+ "farm rio": "farmrio"
2525
+ };
2482
2526
  // src/params/adapters/deco/index.ts
2483
2527
  var IN_STOCK_SCHEMA = "https://schema.org/InStock";
2484
2528
  var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
@@ -2505,7 +2549,7 @@ var AzzasTracker = function() {
2505
2549
  // cor
2506
2550
  item_variant2: (_ref3 = item === null || item === void 0 ? void 0 : (_item_name1 = item.name) === null || _item_name1 === void 0 ? void 0 : _item_name1.split(" - ")[1]) !== null && _ref3 !== void 0 ? _ref3 : null,
2507
2551
  // tamanho
2508
- item_shipping_tier: getItemShippingTier2(),
2552
+ item_shipping_tier: "",
2509
2553
  item_ref: (_ref4 = (_item_additionalProperty = item.additionalProperty) === null || _item_additionalProperty === void 0 ? void 0 : (_item_additionalProperty_find = _item_additionalProperty.find(function(i) {
2510
2554
  return i.name === "RefId";
2511
2555
  })) === null || _item_additionalProperty_find === void 0 ? void 0 : (_item_additionalProperty_find_value = _item_additionalProperty_find.value) === null || _item_additionalProperty_find_value === void 0 ? void 0 : _item_additionalProperty_find_value.replace(/_\d+$/, "")) !== null && _ref4 !== void 0 ? _ref4 : null,
@@ -2522,13 +2566,16 @@ var AzzasTracker = function() {
2522
2566
  }
2523
2567
  return null;
2524
2568
  },
2525
- // brand: (context: DecoBrandContext) => {
2526
- // if (context?.brand) return context.brand
2527
- // if (context?.products) {
2528
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
2529
- // }
2530
- // return null
2531
- // },
2569
+ brand: function(context) {
2570
+ if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2571
+ if (context === null || context === void 0 ? void 0 : context.products) {
2572
+ return normalizeBrand2(context.products.map(function(p) {
2573
+ var _p_brand;
2574
+ return p === null || p === void 0 ? void 0 : (_p_brand = p.brand) === null || _p_brand === void 0 ? void 0 : _p_brand.name;
2575
+ }));
2576
+ }
2577
+ return null;
2578
+ },
2532
2579
  line_items: function(context) {
2533
2580
  if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
2534
2581
  if (context === null || context === void 0 ? void 0 : context.products) {
@@ -2622,7 +2669,7 @@ var AzzasTracker = function() {
2622
2669
  discount: ((item === null || item === void 0 ? void 0 : item.listPrice) - (item === null || item === void 0 ? void 0 : item.sellingPrice)) / 100,
2623
2670
  item_variant: (_ref5 = item === null || item === void 0 ? void 0 : (_item_skuName = item.skuName) === null || _item_skuName === void 0 ? void 0 : (_item_skuName_split_ = _item_skuName.split(" - ")[0]) === null || _item_skuName_split_ === void 0 ? void 0 : (_item_skuName_split__split_pop = _item_skuName_split_.split("_").pop()) === null || _item_skuName_split__split_pop === void 0 ? void 0 : _item_skuName_split__split_pop.trim()) !== null && _ref5 !== void 0 ? _ref5 : null,
2624
2671
  item_variant2: (_ref6 = item === null || item === void 0 ? void 0 : (_item_skuName1 = item.skuName) === null || _item_skuName1 === void 0 ? void 0 : (_item_skuName_split_1 = _item_skuName1.split(" - ")[1]) === null || _item_skuName_split_1 === void 0 ? void 0 : _item_skuName_split_1.trim()) !== null && _ref6 !== void 0 ? _ref6 : null,
2625
- item_shipping_tier: "",
2672
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
2626
2673
  item_ref: (item === null || item === void 0 ? void 0 : item.productRefId) || (item === null || item === void 0 ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
2627
2674
  item_category: (_getItemCategory5 = getItemCategory5(item)) !== null && _getItemCategory5 !== void 0 ? _getItemCategory5 : null,
2628
2675
  item_category2: (_getItemCategory23 = getItemCategory23(item)) !== null && _getItemCategory23 !== void 0 ? _getItemCategory23 : null,
@@ -2637,13 +2684,15 @@ var AzzasTracker = function() {
2637
2684
  }
2638
2685
  return null;
2639
2686
  },
2640
- // brand: (context: any) => {
2641
- // if (context?.brand) return context.brand
2642
- // if (context?.products) {
2643
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
2644
- // }
2645
- // return null
2646
- // },
2687
+ brand: function(context) {
2688
+ var _context_orderForm;
2689
+ if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2690
+ if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
2691
+ var brands = getOrderFormItems(context.orderForm).map(function(item) {
2692
+ return item.additionalInfo.brandName;
2693
+ });
2694
+ return normalizeBrand2(brands);
2695
+ },
2647
2696
  line_items: function(context) {
2648
2697
  var _context_orderForm;
2649
2698
  if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
@@ -2669,10 +2718,10 @@ var AzzasTracker = function() {
2669
2718
  payment_type: getPaymentType,
2670
2719
  total_discount: function(context) {
2671
2720
  var _context_orderForm, _context_orderForm1;
2672
- if (context === null || context === void 0 ? void 0 : context.totalDiscount) return context.totalDiscount;
2673
- var totalsList = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.totalizers) || ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totals) || [];
2674
- var items = context.orderForm.items;
2675
- var totalDiscount = items.reduce(function(acc, item) {
2721
+ if (context === null || context === void 0 ? void 0 : context.total_discount) return context.total_discount;
2722
+ if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
2723
+ var totalsList = ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totalizers) || [];
2724
+ var totalDiscount = getOrderFormItems(context.orderForm).reduce(function(acc, item) {
2676
2725
  var unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
2677
2726
  return acc + unitDiscount * item.quantity;
2678
2727
  }, 0);
@@ -3057,10 +3106,10 @@ var AzzasTracker = function() {
3057
3106
  shippings: function(context) {
3058
3107
  if (context.shippings) {
3059
3108
  return context.shippings.map(function(s) {
3060
- var _s_line_items, _s_price;
3109
+ var _s_line_items;
3061
3110
  return {
3062
3111
  line_items: (_s_line_items = s.line_items) !== null && _s_line_items !== void 0 ? _s_line_items : "",
3063
- shipping: (_s_price = s.price) !== null && _s_price !== void 0 ? _s_price : 0,
3112
+ shipping: s.price / 100,
3064
3113
  shipping_tier: getShippingTier(s),
3065
3114
  delivery_time: getDeliveryTime(s)
3066
3115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azzas/azzas-tracker-web",
3
- "version": "2.0.0-preview.3",
3
+ "version": "2.0.0-preview.5",
4
4
  "type": "module",
5
5
  "main": "./dist/mod.cjs",
6
6
  "module": "./dist/mod.js",