@azzas/azzas-tracker-web 2.0.0-preview.1 → 2.0.0-preview.10

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,14 +1308,49 @@ 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;
1313
1315
  };
1314
- var resizeVtexImage3 = function resizeVtexImage3(url) {
1315
- var width = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 500, height = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 500;
1316
- return url === null || url === void 0 ? void 0 : url.replace(/(\/arquivos\/ids\/\d+)-\d+-\d+\//, "$1-".concat(width, "-").concat(height, "/"));
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;
1317
1342
  };
1318
- var getParameters = function getParameters(context, eventName) {
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;
1352
+ };
1353
+ var getParameters = function getParameters(context, eventName, config2) {
1319
1354
  return _async_to_generator(function() {
1320
1355
  var _adapters_currentAdapter, eventConfig, currentAdapter, getters, entries;
1321
1356
  return _ts_generator(this, function(_state) {
@@ -1351,7 +1386,7 @@ var AzzasTracker = function() {
1351
1386
  ];
1352
1387
  return [
1353
1388
  4,
1354
- getter(context, eventName)
1389
+ getter(context, config2)
1355
1390
  ];
1356
1391
  case 1:
1357
1392
  return [
@@ -1375,8 +1410,10 @@ var AzzasTracker = function() {
1375
1410
  });
1376
1411
  })();
1377
1412
  };
1378
- var trackWebEvent = // src/index.ts
1379
- function trackWebEvent(event, context) {
1413
+ var initTracker = function initTracker(c) {
1414
+ config = c;
1415
+ };
1416
+ var trackWebEvent = function trackWebEvent(event, context) {
1380
1417
  return _async_to_generator(function() {
1381
1418
  var parameters, err;
1382
1419
  return _ts_generator(this, function(_state) {
@@ -1390,7 +1427,7 @@ var AzzasTracker = function() {
1390
1427
  ]);
1391
1428
  return [
1392
1429
  4,
1393
- getParameters(context, event)
1430
+ getParameters(context, event, config)
1394
1431
  ];
1395
1432
  case 1:
1396
1433
  parameters = _state.sent();
@@ -1480,6 +1517,9 @@ var AzzasTracker = function() {
1480
1517
  default: function() {
1481
1518
  return src_default;
1482
1519
  },
1520
+ initTracker: function() {
1521
+ return initTracker;
1522
+ },
1483
1523
  trackWebEvent: function() {
1484
1524
  return trackWebEvent;
1485
1525
  }
@@ -1893,7 +1933,6 @@ var AzzasTracker = function() {
1893
1933
  ],
1894
1934
  requiredParams: [
1895
1935
  "brand",
1896
- "line_items",
1897
1936
  "size",
1898
1937
  "item_ref"
1899
1938
  ]
@@ -2106,13 +2145,17 @@ var AzzasTracker = function() {
2106
2145
  var capitalize = function(str) {
2107
2146
  return str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
2108
2147
  };
2148
+ var resizeVtexImage2 = function(url) {
2149
+ var width = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 500, height = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 500;
2150
+ return url === null || url === void 0 ? void 0 : url.replace(/(\/arquivos\/ids\/\d+)-\d+-\d+\//, "$1-".concat(width, "-").concat(height, "/"));
2151
+ };
2109
2152
  // src/params/userInfo.ts
2110
2153
  var PROD_DOMAINS = {
2111
2154
  "animale": {
2112
2155
  "store": "https://www.animale.com.br",
2113
2156
  "checkout": "https://secure.animale.com.br"
2114
2157
  },
2115
- "farm": {
2158
+ "lojafarm": {
2116
2159
  "store": "https://lojafarm.myvtex.com"
2117
2160
  },
2118
2161
  "mariafilo": {
@@ -2130,7 +2173,7 @@ var AzzasTracker = function() {
2130
2173
  "bynv": {
2131
2174
  "store": "https://bynv.myvtex.com"
2132
2175
  },
2133
- "fabula": {
2176
+ "lojafabula": {
2134
2177
  "store": "https://lojafabula.myvtex.com"
2135
2178
  }
2136
2179
  };
@@ -2395,9 +2438,6 @@ var AzzasTracker = function() {
2395
2438
  // src/params/adapters/meta/index.ts
2396
2439
  var metaAdapters = {
2397
2440
  user_info: getUserInfo,
2398
- brand: function(context) {
2399
- return context.meta.brand || null;
2400
- },
2401
2441
  content_type: function(context) {
2402
2442
  return context.meta.content_type || null;
2403
2443
  },
@@ -2407,8 +2447,8 @@ var AzzasTracker = function() {
2407
2447
  pre_filled: function(context) {
2408
2448
  return !!context.preFilled;
2409
2449
  },
2410
- currency: function(context) {
2411
- if (context === null || context === void 0 ? void 0 : context.currency) return context.currency;
2450
+ currency: function(_, config2) {
2451
+ if (config2 === null || config2 === void 0 ? void 0 : config2.currency) return config2.currency;
2412
2452
  return "BRL";
2413
2453
  },
2414
2454
  slot_per_line: function(context) {
@@ -2433,17 +2473,14 @@ var AzzasTracker = function() {
2433
2473
  creative_slot: function(context) {
2434
2474
  return context.meta.creative_slot || null;
2435
2475
  },
2436
- size: function(context) {
2437
- return context.size || null;
2438
- },
2439
2476
  item_ref: function(context) {
2440
- return context.itemRef || null;
2477
+ return context.meta.item_ref || null;
2441
2478
  },
2442
2479
  method: function(context) {
2443
- return context.method || null;
2480
+ return context.meta.method || null;
2444
2481
  },
2445
2482
  type: function(context) {
2446
- return context.type || null;
2483
+ return context.meta.type || null;
2447
2484
  },
2448
2485
  color: function(context) {
2449
2486
  return context.meta.color || null;
@@ -2456,8 +2493,17 @@ var AzzasTracker = function() {
2456
2493
  },
2457
2494
  ordering: function(context) {
2458
2495
  return context.meta.ordering || null;
2496
+ },
2497
+ size: function(context) {
2498
+ return context.meta.size || null;
2459
2499
  }
2460
2500
  };
2501
+ // src/core/farm.ts
2502
+ var BRAND_CODES2 = {
2503
+ farm: "farmrio",
2504
+ "farm etc": "farmetc",
2505
+ "farm rio": "farmrio"
2506
+ };
2461
2507
  // src/params/adapters/deco/utils.ts
2462
2508
  var getItemCategory3 = function(item) {
2463
2509
  var _text_match;
@@ -2479,10 +2525,6 @@ var AzzasTracker = function() {
2479
2525
  var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
2480
2526
  return capitalize(deepest);
2481
2527
  };
2482
- var resizeVtexImage2 = function(url) {
2483
- var width = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 500, height = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 500;
2484
- return url === null || url === void 0 ? void 0 : url.replace(/(\/arquivos\/ids\/\d+)-\d+-\d+\//, "$1-".concat(width, "-").concat(height, "/"));
2485
- };
2486
2528
  // src/params/adapters/deco/index.ts
2487
2529
  var IN_STOCK_SCHEMA = "https://schema.org/InStock";
2488
2530
  var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
@@ -2493,7 +2535,7 @@ var AzzasTracker = function() {
2493
2535
  if (context === null || context === void 0 ? void 0 : context.products) {
2494
2536
  return context.products.map(function(item) {
2495
2537
  var _ref, _ref1, _item_alternateName, _ref2, _ref3, _ref4, _getItemCategory3, _getItemCategory22, _ref5, _item_sku, _item_url, _resizeVtexImage2, _ref6, _ref7;
2496
- var _item_offers_offers__priceSpecification_find, _item_offers_offers, _item_offers, _item_brand_name, _item_brand, _item_offers1, _item_offers2, _item_name_split_, _item_name, _item_name1, _item_additionalProperty_find, _item_additionalProperty, _item_image, _item_offers_offers_, _item_offers_offers1, _item_offers3;
2538
+ var _item_offers_offers__priceSpecification_find, _item_offers_offers, _item_offers, _item_brand_name, _item_brand, _item_offers1, _item_offers2, _item_name_split_, _item_name, _item_name1, _item_additionalProperty_find_value, _item_additionalProperty_find, _item_additionalProperty, _item_image, _item_offers_offers_, _item_offers_offers1, _item_offers3;
2497
2539
  var COLOR_REGEX = /^[^_]+_/;
2498
2540
  var listPrice = item === null || item === void 0 ? void 0 : (_item_offers = item.offers) === null || _item_offers === void 0 ? void 0 : (_item_offers_offers = _item_offers.offers) === null || _item_offers_offers === void 0 ? void 0 : (_item_offers_offers__priceSpecification_find = _item_offers_offers[0].priceSpecification.find(function(s) {
2499
2541
  return s.priceType === LIST_PRICE_SCHEMA;
@@ -2504,15 +2546,15 @@ var AzzasTracker = function() {
2504
2546
  item_brand: (_ref1 = (_item_brand = item.brand) === null || _item_brand === void 0 ? void 0 : (_item_brand_name = _item_brand.name) === null || _item_brand_name === void 0 ? void 0 : _item_brand_name.toLowerCase()) !== null && _ref1 !== void 0 ? _ref1 : null,
2505
2547
  item_name: (_item_alternateName = item.alternateName) !== null && _item_alternateName !== void 0 ? _item_alternateName : null,
2506
2548
  price: (_ref2 = (_item_offers1 = item.offers) === null || _item_offers1 === void 0 ? void 0 : _item_offers1.lowPrice) !== null && _ref2 !== void 0 ? _ref2 : null,
2507
- discount: Number(listPrice) - Number(item === null || item === void 0 ? void 0 : (_item_offers2 = item.offers) === null || _item_offers2 === void 0 ? void 0 : _item_offers2.lowPrice),
2549
+ discount: Math.round((Number(listPrice) - Number(item === null || item === void 0 ? void 0 : (_item_offers2 = item.offers) === null || _item_offers2 === void 0 ? void 0 : _item_offers2.lowPrice)) * 100) / 100,
2508
2550
  item_variant: (item === null || item === void 0 ? void 0 : (_item_name = item.name) === null || _item_name === void 0 ? void 0 : (_item_name_split_ = _item_name.split(" - ")[0]) === null || _item_name_split_ === void 0 ? void 0 : _item_name_split_.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
2509
2551
  // cor
2510
2552
  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,
2511
2553
  // tamanho
2512
- item_shipping_tier: getItemShippingTier2(),
2554
+ item_shipping_tier: "",
2513
2555
  item_ref: (_ref4 = (_item_additionalProperty = item.additionalProperty) === null || _item_additionalProperty === void 0 ? void 0 : (_item_additionalProperty_find = _item_additionalProperty.find(function(i) {
2514
2556
  return i.name === "RefId";
2515
- })) === null || _item_additionalProperty_find === void 0 ? void 0 : _item_additionalProperty_find.value) !== null && _ref4 !== void 0 ? _ref4 : null,
2557
+ })) === 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,
2516
2558
  item_category: (_getItemCategory3 = getItemCategory3(item)) !== null && _getItemCategory3 !== void 0 ? _getItemCategory3 : null,
2517
2559
  item_category2: (_getItemCategory22 = getItemCategory22(item)) !== null && _getItemCategory22 !== void 0 ? _getItemCategory22 : null,
2518
2560
  item_id: (_ref5 = item === null || item === void 0 ? void 0 : item.inProductGroupWithID) !== null && _ref5 !== void 0 ? _ref5 : null,
@@ -2526,13 +2568,17 @@ var AzzasTracker = function() {
2526
2568
  }
2527
2569
  return null;
2528
2570
  },
2529
- // brand: (context: DecoBrandContext) => {
2530
- // if (context?.brand) return context.brand
2531
- // if (context?.products) {
2532
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
2533
- // }
2534
- // return null
2535
- // },
2571
+ brand: function(context, config2) {
2572
+ if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
2573
+ if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2574
+ if (context === null || context === void 0 ? void 0 : context.products) {
2575
+ return normalizeBrand2(context.products.map(function(p) {
2576
+ var _p_brand;
2577
+ return p === null || p === void 0 ? void 0 : (_p_brand = p.brand) === null || _p_brand === void 0 ? void 0 : _p_brand.name;
2578
+ }));
2579
+ }
2580
+ return null;
2581
+ },
2536
2582
  line_items: function(context) {
2537
2583
  if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
2538
2584
  if (context === null || context === void 0 ? void 0 : context.products) {
@@ -2582,184 +2628,6 @@ var AzzasTracker = function() {
2582
2628
  return null;
2583
2629
  }
2584
2630
  });
2585
- // src/params/adapters/orderForm/index.ts
2586
- var orderFormAdapters = {
2587
- // orderform
2588
- payment_type: getPaymentType,
2589
- total_discount: function(context) {
2590
- var _context_orderForm, _context_orderForm1;
2591
- if (context === null || context === void 0 ? void 0 : context.totalDiscount) return context.totalDiscount;
2592
- 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) || [];
2593
- var items = context.orderForm.items;
2594
- var totalDiscount = items.reduce(function(acc, item) {
2595
- var unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
2596
- return acc + unitDiscount * item.quantity;
2597
- }, 0);
2598
- var discounts = totalsList.find(function(t) {
2599
- return t.id === "Discounts";
2600
- });
2601
- return Math.abs(((discounts === null || discounts === void 0 ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
2602
- },
2603
- subtotal: function(context) {
2604
- var _context_orderForm, _context_orderForm1;
2605
- 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) || [];
2606
- var subtotal = totalsList.filter(function(t) {
2607
- return t.id === "Items";
2608
- }).reduce(function(acc, t) {
2609
- return acc + (t.value || 0);
2610
- }, 0) / 100 || 0;
2611
- return subtotal;
2612
- },
2613
- coupon_message: function(context) {
2614
- var _context_orderForm;
2615
- if (context.couponMessage) return context.couponMessage;
2616
- var messages = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.messages) || [];
2617
- if (messages.length === 0) return null;
2618
- var couponMessages = messages.filter(function(msg) {
2619
- return msg.text.toLowerCase().includes("cupom");
2620
- });
2621
- if (couponMessages.length === 0) return null;
2622
- return couponMessages.map(function(msg) {
2623
- return msg.text;
2624
- }).join(" | ");
2625
- },
2626
- flag_pickup: function(context) {
2627
- var _orderForm_shippingData;
2628
- var orderForm = context.orderForm;
2629
- if (!orderForm) return null;
2630
- var logisticsInfo = ((_orderForm_shippingData = orderForm.shippingData) === null || _orderForm_shippingData === void 0 ? void 0 : _orderForm_shippingData.logisticsInfo) || [];
2631
- var hasPickup = logisticsInfo.some(function(info) {
2632
- var _info_slas;
2633
- return (_info_slas = info.slas) === null || _info_slas === void 0 ? void 0 : _info_slas.some(function(sla) {
2634
- return sla.deliveryChannel === "pickup-in-point";
2635
- });
2636
- });
2637
- return hasPickup;
2638
- },
2639
- shippings: function(context) {
2640
- var orderForm = context.orderForm;
2641
- if (!orderForm) return null;
2642
- var groupShipping = {};
2643
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2644
- try {
2645
- for(var _iterator = orderForm.shippingData.logisticsInfo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2646
- var info = _step.value;
2647
- var item = orderForm.items[info.itemIndex];
2648
- if (!item) continue;
2649
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2650
- try {
2651
- for(var _iterator1 = info.slas[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2652
- var sla = _step1.value;
2653
- var key = sla.name;
2654
- if (!groupShipping[key]) {
2655
- groupShipping[key] = {
2656
- shipping_tier: sla.name,
2657
- delivery_time: parseInt(sla.shippingEstimate),
2658
- shipping: parseFloat((sla.price / 100).toFixed(1)),
2659
- line_items: []
2660
- };
2661
- }
2662
- groupShipping[key].line_items.push(item.id);
2663
- }
2664
- } catch (err) {
2665
- _didIteratorError1 = true;
2666
- _iteratorError1 = err;
2667
- } finally{
2668
- try {
2669
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2670
- _iterator1.return();
2671
- }
2672
- } finally{
2673
- if (_didIteratorError1) {
2674
- throw _iteratorError1;
2675
- }
2676
- }
2677
- }
2678
- }
2679
- } catch (err) {
2680
- _didIteratorError = true;
2681
- _iteratorError = err;
2682
- } finally{
2683
- try {
2684
- if (!_iteratorNormalCompletion && _iterator.return != null) {
2685
- _iterator.return();
2686
- }
2687
- } finally{
2688
- if (_didIteratorError) {
2689
- throw _iteratorError;
2690
- }
2691
- }
2692
- }
2693
- var shippings = Object.values(groupShipping).map(function(s) {
2694
- return {
2695
- shipping: s.shipping,
2696
- shipping_tier: s.shipping_tier,
2697
- delivery_time: s.delivery_time,
2698
- line_items: s.line_items.join(",")
2699
- };
2700
- });
2701
- return shippings || null;
2702
- },
2703
- shipping: function(context) {
2704
- var _ref;
2705
- var _context_orderForm_shippingData, _context_orderForm;
2706
- var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
2707
- return logistics.reduce(function(total, item) {
2708
- var _ref;
2709
- var _item_slas;
2710
- var selected = (_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
2711
- return sla.id === item.selectedSla;
2712
- });
2713
- return total + ((_ref = selected === null || selected === void 0 ? void 0 : selected.price) !== null && _ref !== void 0 ? _ref : 0);
2714
- }, 0);
2715
- },
2716
- shipping_tier: function(context) {
2717
- var _ref;
2718
- var _context_orderForm_shippingData, _context_orderForm;
2719
- var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
2720
- var selectedSlas = logistics.map(function(item) {
2721
- var _item_slas;
2722
- if (!item.selectedSla) return null;
2723
- return ((_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
2724
- return sla.id === item.selectedSla;
2725
- })) || null;
2726
- }).filter(Boolean);
2727
- if (selectedSlas.length === 0) return null;
2728
- var uniqueTiers = Array.from(new Map(selectedSlas.map(function(sla) {
2729
- var _sla_pickupStoreInfo;
2730
- var key = sla.deliveryChannel === "pickup-in-point" ? "pickup:".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) || sla.name || "") : "delivery:".concat(sla.name || "");
2731
- return [
2732
- key,
2733
- sla
2734
- ];
2735
- })).values());
2736
- var sortedTiers = uniqueTiers.sort(function(a, b) {
2737
- var _a_pickupStoreInfo, _b_pickupStoreInfo;
2738
- var aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
2739
- var bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
2740
- if (aOrder !== bOrder) return aOrder - bOrder;
2741
- var aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a_pickupStoreInfo = a.pickupStoreInfo) === null || _a_pickupStoreInfo === void 0 ? void 0 : _a_pickupStoreInfo.friendlyName) || a.name || "" : a.name || "";
2742
- var bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b_pickupStoreInfo = b.pickupStoreInfo) === null || _b_pickupStoreInfo === void 0 ? void 0 : _b_pickupStoreInfo.friendlyName) || b.name || "" : b.name || "";
2743
- return aLabel.localeCompare(bLabel, "pt-BR");
2744
- });
2745
- var shippingTier = sortedTiers.map(function(sla) {
2746
- var _sla_pickupStoreInfo;
2747
- return sla.deliveryChannel === "pickup-in-point" ? "retirada em loja".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) ? ": ".concat(sla.pickupStoreInfo.friendlyName) : "") : sla.deliveryChannel === "delivery" ? "receba em casa".concat(sla.name ? ": ".concat(sla.name) : "") : null;
2748
- }).filter(Boolean).join(", ");
2749
- return shippingTier || null;
2750
- },
2751
- transaction_id: function(context) {
2752
- var _context_orderForm_orderGroup, _context_orderForm;
2753
- return ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_orderGroup = _context_orderForm.orderGroup) === null || _context_orderForm_orderGroup === void 0 ? void 0 : _context_orderForm_orderGroup.toString()) || null;
2754
- },
2755
- coupon: function(context) {
2756
- var _context_orderForm_marketingData, _context_orderForm;
2757
- return context.appliedCoupon || (context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_marketingData = _context_orderForm.marketingData) === null || _context_orderForm_marketingData === void 0 ? void 0 : _context_orderForm_marketingData.coupon) || null;
2758
- },
2759
- seller_cod_name: function(context) {
2760
- return context.appliedSellerCodName || (context === null || context === void 0 ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
2761
- }
2762
- };
2763
2631
  // src/params/adapters/headless/utils.ts
2764
2632
  var getItemCategory5 = function(item) {
2765
2633
  var keywords = [
@@ -2795,7 +2663,7 @@ var AzzasTracker = function() {
2795
2663
  if (context === null || context === void 0 ? void 0 : context.items) return context.items;
2796
2664
  if (context === null || context === void 0 ? void 0 : context.products) {
2797
2665
  return context.products.map(function(item) {
2798
- var _ref, _item_brand, _item_productName, _ref1, _ref2, _item_productReference, _getItemCategory23, _ref3, _ref4, _item_link, _resizeVtexImage3, _ref5, _item_item_list_name;
2666
+ var _ref, _item_brand, _item_productName, _ref1, _ref2, _item_productReference, _getItemCategory23, _ref3, _ref4, _item_link, _resizeVtexImage2, _ref5, _item_item_list_name;
2799
2667
  var _item_items__sellers, _item_items__sellers1, _item_items__name, _item_items_, _item_items__name1, _item_items_1, _item_items, _item_items__images, _item_items1, _item_items__sellers2, _item_items_2, _item_items2;
2800
2668
  var listPrice = item === null || item === void 0 ? void 0 : (_item_items__sellers = item.items[0].sellers) === null || _item_items__sellers === void 0 ? void 0 : _item_items__sellers[0].commertialOffer.ListPrice;
2801
2669
  var price = item === null || item === void 0 ? void 0 : (_item_items__sellers1 = item.items[0].sellers) === null || _item_items__sellers1 === void 0 ? void 0 : _item_items__sellers1[0].commertialOffer.Price;
@@ -2805,6 +2673,7 @@ var AzzasTracker = function() {
2805
2673
  item_brand: (_item_brand = item.brand) !== null && _item_brand !== void 0 ? _item_brand : null,
2806
2674
  item_name: (_item_productName = item.productName) !== null && _item_productName !== void 0 ? _item_productName : null,
2807
2675
  price: price !== null && price !== void 0 ? price : null,
2676
+ item_shipping_tier: null,
2808
2677
  discount: Number(listPrice) - Number(price),
2809
2678
  item_variant: (_ref1 = (_item_items_ = item.items[0]) === null || _item_items_ === void 0 ? void 0 : (_item_items__name = _item_items_.name) === null || _item_items__name === void 0 ? void 0 : _item_items__name.split(" - ")[0]) !== null && _ref1 !== void 0 ? _ref1 : null,
2810
2679
  item_variant2: (_ref2 = (_item_items_1 = item.items[0]) === null || _item_items_1 === void 0 ? void 0 : (_item_items__name1 = _item_items_1.name) === null || _item_items__name1 === void 0 ? void 0 : _item_items__name1.split(" - ")[1]) !== null && _ref2 !== void 0 ? _ref2 : null,
@@ -2816,7 +2685,7 @@ var AzzasTracker = function() {
2816
2685
  item_sku: (_ref4 = (_item_items = item.items) === null || _item_items === void 0 ? void 0 : _item_items[0].itemId) !== null && _ref4 !== void 0 ? _ref4 : null,
2817
2686
  item_url: (_item_link = item.link) !== null && _item_link !== void 0 ? _item_link : null,
2818
2687
  // sem link/url no retorno do IS na multi-lib produtos PDC
2819
- image_url: (_resizeVtexImage3 = resizeVtexImage3(item === null || item === void 0 ? void 0 : (_item_items1 = item.items) === null || _item_items1 === void 0 ? void 0 : (_item_items__images = _item_items1[0].images) === null || _item_items__images === void 0 ? void 0 : _item_items__images[0].imageUrl)) !== null && _resizeVtexImage3 !== void 0 ? _resizeVtexImage3 : null,
2688
+ image_url: (_resizeVtexImage2 = resizeVtexImage2(item === null || item === void 0 ? void 0 : (_item_items1 = item.items) === null || _item_items1 === void 0 ? void 0 : (_item_items__images = _item_items1[0].images) === null || _item_items__images === void 0 ? void 0 : _item_items__images[0].imageUrl)) !== null && _resizeVtexImage2 !== void 0 ? _resizeVtexImage2 : null,
2820
2689
  seller_id: (_ref5 = (_item_items2 = item.items) === null || _item_items2 === void 0 ? void 0 : (_item_items_2 = _item_items2[0]) === null || _item_items_2 === void 0 ? void 0 : (_item_items__sellers2 = _item_items_2.sellers) === null || _item_items__sellers2 === void 0 ? void 0 : _item_items__sellers2[0].sellerId) !== null && _ref5 !== void 0 ? _ref5 : null,
2821
2690
  item_list_name: (_item_item_list_name = item.item_list_name) !== null && _item_item_list_name !== void 0 ? _item_item_list_name : null
2822
2691
  };
@@ -2849,7 +2718,8 @@ var AzzasTracker = function() {
2849
2718
  }
2850
2719
  return null;
2851
2720
  },
2852
- brand: function(context) {
2721
+ brand: function(context, config2) {
2722
+ if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
2853
2723
  if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2854
2724
  if (context === null || context === void 0 ? void 0 : context.products) {
2855
2725
  return context.products.map(function(p) {
@@ -2865,7 +2735,7 @@ var AzzasTracker = function() {
2865
2735
  if (context === null || context === void 0 ? void 0 : context.items) return context.items;
2866
2736
  if (context === null || context === void 0 ? void 0 : context.products) {
2867
2737
  return context.products.map(function(item) {
2868
- var _ref, _item_brand_name, _item_name, _ref1, _ref2, _item_additionalProperty, _getItemCategory23, _item_isVariantOf_productGroupID, _item_sku, _resizeVtexImage3, _ref3, _item_item_list_name;
2738
+ var _ref, _item_brand_name, _item_name, _ref1, _ref2, _item_additionalProperty, _getItemCategory23, _item_isVariantOf_productGroupID, _item_sku, _resizeVtexImage2, _ref3, _item_item_list_name;
2869
2739
  var _item_isVariantOf_hasVariant, _item_isVariantOf, _find, _item_image, _item_offers_offers_find_seller, _item_offers_offers_find, _item_offers_offers, _item_offers;
2870
2740
  var listPrice = item.offers.highPrice;
2871
2741
  var price = item.offers.lowPrice;
@@ -2875,6 +2745,7 @@ var AzzasTracker = function() {
2875
2745
  item_brand: (_item_brand_name = item.brand.name) !== null && _item_brand_name !== void 0 ? _item_brand_name : null,
2876
2746
  item_name: (_item_name = item.name) !== null && _item_name !== void 0 ? _item_name : null,
2877
2747
  price: price !== null && price !== void 0 ? price : null,
2748
+ item_shipping_tier: null,
2878
2749
  discount: Number(listPrice) - Number(price),
2879
2750
  item_variant: (_ref1 = (_item_isVariantOf = item.isVariantOf) === null || _item_isVariantOf === void 0 ? void 0 : (_item_isVariantOf_hasVariant = _item_isVariantOf.hasVariant) === null || _item_isVariantOf_hasVariant === void 0 ? void 0 : _item_isVariantOf_hasVariant[0].name.split(" - ")[0]) !== null && _ref1 !== void 0 ? _ref1 : null,
2880
2751
  item_variant2: (_ref2 = (_find = ((_item_additionalProperty = item.additionalProperty) !== null && _item_additionalProperty !== void 0 ? _item_additionalProperty : []).find(function(p) {
@@ -2888,7 +2759,7 @@ var AzzasTracker = function() {
2888
2759
  item_sku: (_item_sku = item.sku) !== null && _item_sku !== void 0 ? _item_sku : null,
2889
2760
  item_url: null,
2890
2761
  // sem link/url no retorno do IS na multi-lib produtos PDC
2891
- image_url: (_resizeVtexImage3 = resizeVtexImage3(item === null || item === void 0 ? void 0 : (_item_image = item.image) === null || _item_image === void 0 ? void 0 : _item_image[0].url)) !== null && _resizeVtexImage3 !== void 0 ? _resizeVtexImage3 : null,
2762
+ image_url: (_resizeVtexImage2 = resizeVtexImage2(item === null || item === void 0 ? void 0 : (_item_image = item.image) === null || _item_image === void 0 ? void 0 : _item_image[0].url)) !== null && _resizeVtexImage2 !== void 0 ? _resizeVtexImage2 : null,
2892
2763
  seller_id: (_ref3 = (_item_offers = item.offers) === null || _item_offers === void 0 ? void 0 : (_item_offers_offers = _item_offers.offers) === null || _item_offers_offers === void 0 ? void 0 : (_item_offers_offers_find = _item_offers_offers.find(function(o) {
2893
2764
  return o.availability;
2894
2765
  })) === null || _item_offers_offers_find === void 0 ? void 0 : (_item_offers_offers_find_seller = _item_offers_offers_find.seller) === null || _item_offers_offers_find_seller === void 0 ? void 0 : _item_offers_offers_find_seller.identifier) !== null && _ref3 !== void 0 ? _ref3 : null,
@@ -2922,7 +2793,8 @@ var AzzasTracker = function() {
2922
2793
  }
2923
2794
  return null;
2924
2795
  },
2925
- brand: function(context) {
2796
+ brand: function(context, config2) {
2797
+ if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
2926
2798
  if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2927
2799
  if (context === null || context === void 0 ? void 0 : context.products) {
2928
2800
  return context.products.map(function(p) {
@@ -2933,14 +2805,14 @@ var AzzasTracker = function() {
2933
2805
  }
2934
2806
  };
2935
2807
  // src/params/adapters/headless/index.ts
2936
- var headlessAdapter = _object_spread_props(_object_spread({}, metaAdapters, orderFormAdapters), {
2937
- // orderForm adapters, confirmar se no storefront tem evento que usa essses params
2938
- brand: function(context) {
2808
+ var headlessAdapter = _object_spread_props(_object_spread({}, metaAdapters), {
2809
+ // global adapters
2810
+ brand: function(context, config2) {
2939
2811
  if (context.zone === "PDP") {
2940
- return HeadlessPdpZone.brand(context);
2812
+ return HeadlessPdpZone.brand(context, config2);
2941
2813
  }
2942
2814
  if (context.zone === "PDC") {
2943
- return HeadlessPdcZone.brand(context);
2815
+ return HeadlessPdcZone.brand(context, config2);
2944
2816
  }
2945
2817
  return null;
2946
2818
  },
@@ -3010,10 +2882,10 @@ var AzzasTracker = function() {
3010
2882
  shippings: function(context) {
3011
2883
  if (context.shippings) {
3012
2884
  return context.shippings.map(function(s) {
3013
- var _s_line_items, _s_price;
2885
+ var _s_line_items;
3014
2886
  return {
3015
2887
  line_items: (_s_line_items = s.line_items) !== null && _s_line_items !== void 0 ? _s_line_items : "",
3016
- shipping: (_s_price = s.price) !== null && _s_price !== void 0 ? _s_price : 0,
2888
+ shipping: s.price / 100,
3017
2889
  shipping_tier: getShippingTier(s),
3018
2890
  delivery_time: getDeliveryTime(s)
3019
2891
  };
@@ -3021,16 +2893,257 @@ var AzzasTracker = function() {
3021
2893
  }
3022
2894
  return null;
3023
2895
  },
2896
+ brand: function(context, config2) {
2897
+ if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
2898
+ if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2899
+ return null;
2900
+ },
2901
+ zipcode: function(context) {
2902
+ var _context_meta_zipcode;
2903
+ return (_context_meta_zipcode = context.meta.zipcode) !== null && _context_meta_zipcode !== void 0 ? _context_meta_zipcode : null;
2904
+ }
2905
+ });
2906
+ // src/params/adapters/orderForm/utils.ts
2907
+ var getItemCategory6 = function(item) {
2908
+ var _text_match;
2909
+ var categories = item === null || item === void 0 ? void 0 : item.productCategories;
2910
+ if (!categories) return "Cole\xE7\xE3o";
2911
+ var text = Object.values(categories).join(" ");
2912
+ var match = (_text_match = text.match(/outlet|bazar|sale/i)) === null || _text_match === void 0 ? void 0 : _text_match[0].toLowerCase();
2913
+ return match !== null && match !== void 0 ? match : "Cole\xE7\xE3o";
2914
+ };
2915
+ var getItemCategory24 = function(item) {
2916
+ var _ref, _validHierarchy_;
2917
+ var AVOID_CATEGORIES = /outlet|bazar|sale/i;
2918
+ var categories = Object.values((_ref = item === null || item === void 0 ? void 0 : item.productCategories) !== null && _ref !== void 0 ? _ref : {});
2919
+ var validHierarchy = categories.map(function(c) {
2920
+ return c.trim();
2921
+ }).filter(function(c) {
2922
+ return c && !AVOID_CATEGORIES.test(c);
2923
+ });
2924
+ var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
2925
+ return capitalize(deepest);
2926
+ };
2927
+ var getOrderFormItems = function(orderForm) {
2928
+ var idSelected = orderForm === null || orderForm === void 0 ? void 0 : orderForm.selected;
2929
+ return idSelected ? orderForm.items.filter(function(item) {
2930
+ return item.id === idSelected;
2931
+ }) : orderForm.items;
2932
+ };
2933
+ // src/params/adapters/orderForm/index.ts
2934
+ var orderFormAdapter = _object_spread_props(_object_spread({}, metaAdapters), {
2935
+ items: function(context) {
2936
+ if (context === null || context === void 0 ? void 0 : context.items) return context.items;
2937
+ if ((context === null || context === void 0 ? void 0 : context.orderForm) && (context === null || context === void 0 ? void 0 : context.orderForm.items)) {
2938
+ return getOrderFormItems(context.orderForm).map(function(item, index) {
2939
+ var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _getItemCategory6, _getItemCategory24, _ref7, _ref8, _item_detailUrl, _resizeVtexImage2, _ref9, _ref10;
2940
+ var _context_orderForm, _item_additionalInfo, _item_skuName_split__split_pop, _item_skuName_split_, _item_skuName, _item_skuName_split_1, _item_skuName1, _context_orderForm1;
2941
+ return {
2942
+ quantity: (_ref = item === null || item === void 0 ? void 0 : item.quantity) !== null && _ref !== void 0 ? _ref : 1,
2943
+ index: (_ref1 = (_ref2 = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.index) !== null && _ref2 !== void 0 ? _ref2 : index) !== null && _ref1 !== void 0 ? _ref1 : null,
2944
+ item_brand: (_ref3 = (_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) !== null && _ref3 !== void 0 ? _ref3 : null,
2945
+ item_name: (_ref4 = item === null || item === void 0 ? void 0 : item.name.replace(item === null || item === void 0 ? void 0 : item.skuName, "").trim()) !== null && _ref4 !== void 0 ? _ref4 : null,
2946
+ price: (item === null || item === void 0 ? void 0 : item.price) / 100,
2947
+ discount: ((item === null || item === void 0 ? void 0 : item.listPrice) - (item === null || item === void 0 ? void 0 : item.sellingPrice)) / 100,
2948
+ 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,
2949
+ 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,
2950
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
2951
+ item_ref: (item === null || item === void 0 ? void 0 : item.productRefId) || (item === null || item === void 0 ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
2952
+ item_category: (_getItemCategory6 = getItemCategory6(item)) !== null && _getItemCategory6 !== void 0 ? _getItemCategory6 : null,
2953
+ item_category2: (_getItemCategory24 = getItemCategory24(item)) !== null && _getItemCategory24 !== void 0 ? _getItemCategory24 : null,
2954
+ item_id: (_ref7 = item === null || item === void 0 ? void 0 : item.productId) !== null && _ref7 !== void 0 ? _ref7 : null,
2955
+ item_sku: (_ref8 = item === null || item === void 0 ? void 0 : item.id) !== null && _ref8 !== void 0 ? _ref8 : null,
2956
+ item_url: (_item_detailUrl = item.detailUrl) !== null && _item_detailUrl !== void 0 ? _item_detailUrl : null,
2957
+ image_url: (_resizeVtexImage2 = resizeVtexImage2(item.imageUrl)) !== null && _resizeVtexImage2 !== void 0 ? _resizeVtexImage2 : null,
2958
+ seller_id: (_ref9 = item === null || item === void 0 ? void 0 : item.seller) !== null && _ref9 !== void 0 ? _ref9 : null,
2959
+ item_list_name: (_ref10 = context === null || context === void 0 ? void 0 : (_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.item_list_name) !== null && _ref10 !== void 0 ? _ref10 : null
2960
+ };
2961
+ });
2962
+ }
2963
+ return null;
2964
+ },
2965
+ brand: function(context, config2) {
2966
+ var _context_orderForm;
2967
+ if (config2 === null || config2 === void 0 ? void 0 : config2.brand) return config2.brand;
2968
+ if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2969
+ if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
2970
+ var brands = getOrderFormItems(context.orderForm).map(function(item) {
2971
+ return item.additionalInfo.brandName;
2972
+ });
2973
+ return normalizeBrand2(brands);
2974
+ },
2975
+ line_items: function(context) {
2976
+ var _context_orderForm;
2977
+ if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
2978
+ if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
2979
+ return getOrderFormItems(context.orderForm).map(function(item) {
2980
+ return item === null || item === void 0 ? void 0 : item.productId;
2981
+ }).filter(function(id) {
2982
+ return Boolean(id);
2983
+ });
2984
+ },
2985
+ value: function(context) {
2986
+ var _context_orderForm;
2987
+ if (context === null || context === void 0 ? void 0 : context.value) return context.value;
2988
+ if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
2989
+ return getOrderFormItems(context.orderForm).map(function(item) {
2990
+ return (item === null || item === void 0 ? void 0 : item.price) / 100 * item.quantity;
2991
+ }).filter(function(price) {
2992
+ return price !== void 0;
2993
+ }).reduce(function(sum, price) {
2994
+ return sum + price;
2995
+ }, 0);
2996
+ },
2997
+ payment_type: getPaymentType,
2998
+ total_discount: function(context) {
2999
+ var _context_orderForm, _context_orderForm1;
3000
+ if (context === null || context === void 0 ? void 0 : context.total_discount) return context.total_discount;
3001
+ if (!(context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.items)) return null;
3002
+ var totalsList = ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totalizers) || [];
3003
+ var totalDiscount = getOrderFormItems(context.orderForm).reduce(function(acc, item) {
3004
+ var unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
3005
+ return acc + unitDiscount * item.quantity;
3006
+ }, 0);
3007
+ var discounts = totalsList.find(function(t) {
3008
+ return t.id === "Discounts";
3009
+ });
3010
+ return Math.abs(((discounts === null || discounts === void 0 ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
3011
+ },
3012
+ subtotal: function(context) {
3013
+ var _context_orderForm, _context_orderForm1;
3014
+ 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) || [];
3015
+ var subtotal = totalsList.filter(function(t) {
3016
+ return t.id === "Items";
3017
+ }).reduce(function(acc, t) {
3018
+ return acc + (t.value || 0);
3019
+ }, 0) / 100 || 0;
3020
+ return subtotal;
3021
+ },
3022
+ coupon_message: function(context) {
3023
+ var _context_orderForm;
3024
+ if (context.couponMessage) return context.couponMessage;
3025
+ var messages = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.messages) || [];
3026
+ if (messages.length === 0) return null;
3027
+ var couponMessages = messages.filter(function(msg) {
3028
+ return msg.text.toLowerCase().includes("cupom");
3029
+ });
3030
+ if (couponMessages.length === 0) return null;
3031
+ return couponMessages.map(function(msg) {
3032
+ return msg.text;
3033
+ }).join(" | ");
3034
+ },
3024
3035
  zipcode: function(context) {
3025
- var _context_zipcode;
3026
- return (_context_zipcode = context.zipcode) !== null && _context_zipcode !== void 0 ? _context_zipcode : null;
3036
+ var _context_meta_zipcode;
3037
+ return (_context_meta_zipcode = context.meta.zipcode) !== null && _context_meta_zipcode !== void 0 ? _context_meta_zipcode : null;
3038
+ },
3039
+ flag_pickup: function(context) {
3040
+ var _orderForm_shippingData;
3041
+ var orderForm = context.orderForm;
3042
+ if (!orderForm) return null;
3043
+ var logisticsInfo = ((_orderForm_shippingData = orderForm.shippingData) === null || _orderForm_shippingData === void 0 ? void 0 : _orderForm_shippingData.logisticsInfo) || [];
3044
+ var hasPickup = logisticsInfo.some(function(info) {
3045
+ var _info_slas;
3046
+ return (_info_slas = info.slas) === null || _info_slas === void 0 ? void 0 : _info_slas.some(function(sla) {
3047
+ return sla.deliveryChannel === "pickup-in-point";
3048
+ });
3049
+ });
3050
+ return hasPickup;
3051
+ },
3052
+ shippings: function(context) {
3053
+ if (!context.orderForm) return null;
3054
+ var _context_orderForm = context.orderForm, items = _context_orderForm.items, shippingData = _context_orderForm.shippingData;
3055
+ var acc = {};
3056
+ shippingData.logisticsInfo.forEach(function(param) {
3057
+ var itemIndex = param.itemIndex, slas = param.slas;
3058
+ var item = items[itemIndex];
3059
+ if (!item) return;
3060
+ slas.forEach(function(sla) {
3061
+ if (!acc[sla.name]) acc[sla.name] = {
3062
+ shipping_tier: sla.name,
3063
+ delivery_time: parseInt(sla.shippingEstimate),
3064
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
3065
+ line_items: []
3066
+ };
3067
+ acc[sla.name].line_items.push(item.id);
3068
+ });
3069
+ });
3070
+ return Object.values(acc).map(function(s) {
3071
+ return _object_spread_props(_object_spread({}, s), {
3072
+ line_items: s.line_items.join(",")
3073
+ });
3074
+ });
3075
+ },
3076
+ shipping: function(context) {
3077
+ var _ref;
3078
+ var _context_orderForm_shippingData, _context_orderForm;
3079
+ var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
3080
+ return logistics.reduce(function(total, item) {
3081
+ var _ref;
3082
+ var _item_slas;
3083
+ var selected = (_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
3084
+ return sla.id === item.selectedSla;
3085
+ });
3086
+ return total + ((_ref = selected === null || selected === void 0 ? void 0 : selected.price) !== null && _ref !== void 0 ? _ref : 0);
3087
+ }, 0);
3088
+ },
3089
+ shipping_tier: function(context) {
3090
+ var _ref;
3091
+ var _context_orderForm_shippingData, _context_orderForm;
3092
+ var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
3093
+ var selectedSlas = logistics.map(function(item) {
3094
+ var _item_slas;
3095
+ if (!item.selectedSla) return null;
3096
+ return ((_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
3097
+ return sla.id === item.selectedSla;
3098
+ })) || null;
3099
+ }).filter(Boolean);
3100
+ if (selectedSlas.length === 0) return null;
3101
+ var uniqueTiers = Array.from(new Map(selectedSlas.map(function(sla) {
3102
+ var _sla_pickupStoreInfo;
3103
+ var key = sla.deliveryChannel === "pickup-in-point" ? "pickup:".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) || sla.name || "") : "delivery:".concat(sla.name || "");
3104
+ return [
3105
+ key,
3106
+ sla
3107
+ ];
3108
+ })).values());
3109
+ var sortedTiers = uniqueTiers.sort(function(a, b) {
3110
+ var _a_pickupStoreInfo, _b_pickupStoreInfo;
3111
+ var aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
3112
+ var bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
3113
+ if (aOrder !== bOrder) return aOrder - bOrder;
3114
+ var aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a_pickupStoreInfo = a.pickupStoreInfo) === null || _a_pickupStoreInfo === void 0 ? void 0 : _a_pickupStoreInfo.friendlyName) || a.name || "" : a.name || "";
3115
+ var bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b_pickupStoreInfo = b.pickupStoreInfo) === null || _b_pickupStoreInfo === void 0 ? void 0 : _b_pickupStoreInfo.friendlyName) || b.name || "" : b.name || "";
3116
+ return aLabel.localeCompare(bLabel, "pt-BR");
3117
+ });
3118
+ var shippingTier = sortedTiers.map(function(sla) {
3119
+ var _sla_pickupStoreInfo;
3120
+ return sla.deliveryChannel === "pickup-in-point" ? "retirada em loja".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) ? ": ".concat(sla.pickupStoreInfo.friendlyName) : "") : sla.deliveryChannel === "delivery" ? "receba em casa".concat(sla.name ? ": ".concat(sla.name) : "") : null;
3121
+ }).filter(Boolean).join(", ");
3122
+ return shippingTier || null;
3123
+ },
3124
+ transaction_id: function(context) {
3125
+ var _context_orderForm_orderGroup, _context_orderForm;
3126
+ return ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_orderGroup = _context_orderForm.orderGroup) === null || _context_orderForm_orderGroup === void 0 ? void 0 : _context_orderForm_orderGroup.toString()) || null;
3127
+ },
3128
+ coupon: function(context) {
3129
+ var _context_orderForm_marketingData, _context_orderForm;
3130
+ return context.appliedCoupon || (context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_marketingData = _context_orderForm.marketingData) === null || _context_orderForm_marketingData === void 0 ? void 0 : _context_orderForm_marketingData.coupon) || null;
3131
+ },
3132
+ seller_cod_name: function(context) {
3133
+ return context.appliedSellerCodName || (context === null || context === void 0 ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
3027
3134
  }
3028
3135
  });
3029
3136
  // src/formatter.ts
3030
3137
  var adapters = {
3031
3138
  DECO: decoAdapter,
3032
3139
  HEADLESS: headlessAdapter,
3033
- PICKUP: pickupAdapter
3140
+ PICKUP: pickupAdapter,
3141
+ ORDERFORM: orderFormAdapter
3142
+ };
3143
+ // src/index.ts
3144
+ var config = {
3145
+ brand: "",
3146
+ currency: "BRL"
3034
3147
  };
3035
3148
  var src_default = {
3036
3149
  trackWebEvent: trackWebEvent,