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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mod.js CHANGED
@@ -291,6 +291,18 @@ var EVENTS = {
291
291
  hasEcommerce: false,
292
292
  destinations: ["DataLayer"],
293
293
  requiredParams: ["brand", "line_items", "size", "item_ref"]
294
+ },
295
+ REFINE_RESULTS: {
296
+ name: "refine_results",
297
+ hasEcommerce: false,
298
+ destinations: ["DataLayer"],
299
+ requiredParams: ["brand", "region", "color", "price_range", "size", "category", "ordering"]
300
+ },
301
+ GRID_SIZE: {
302
+ name: "grid_size",
303
+ hasEcommerce: false,
304
+ destinations: ["DataLayer"],
305
+ requiredParams: ["brand", "slot_per_line"]
294
306
  }
295
307
  };
296
308
 
@@ -972,6 +984,12 @@ var sortSizes = (sizes) => {
972
984
  return unique;
973
985
  };
974
986
  var capitalize = (str) => str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
987
+ var resizeVtexImage2 = (url, width = 500, height = 500) => {
988
+ return url == null ? void 0 : url.replace(
989
+ /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
990
+ `$1-${width}-${height}/`
991
+ );
992
+ };
975
993
 
976
994
  // src/params/legacy/resolvers/paymentType/fromOrderForm.ts
977
995
  function paymentTypeFromOrderForm(context) {
@@ -1107,7 +1125,7 @@ async function getUserInfo(context) {
1107
1125
  }
1108
1126
 
1109
1127
  // src/params/legacy/index.ts
1110
- var paramGetters = {
1128
+ var legacyGetters = {
1111
1129
  brand: getBrand,
1112
1130
  items: getItems,
1113
1131
  payment_type: getPaymentType,
@@ -1315,8 +1333,7 @@ var metaAdapters = {
1315
1333
  return context.meta.brand || null;
1316
1334
  },
1317
1335
  content_type: (context) => {
1318
- if (context == null ? void 0 : context.content_type) return context.content_type;
1319
- return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
1336
+ return context.meta.content_type || null;
1320
1337
  },
1321
1338
  region: (context) => {
1322
1339
  return context.meta.region || null;
@@ -1328,14 +1345,18 @@ var metaAdapters = {
1328
1345
  if (context == null ? void 0 : context.currency) return context.currency;
1329
1346
  return "BRL";
1330
1347
  },
1348
+ slot_per_line: (context) => {
1349
+ var _a;
1350
+ return (_a = context.meta.slot_per_line) != null ? _a : null;
1351
+ },
1331
1352
  search_term: (context) => {
1332
- return context.searchTerm || null;
1353
+ return context.meta.search_term || null;
1333
1354
  },
1334
1355
  search_found: (context) => {
1335
- return !!context.searchFound;
1356
+ return context.meta.search_found || null;
1336
1357
  },
1337
1358
  search_quantity: (context) => {
1338
- return context.searchQuantity || 0;
1359
+ return context.meta.search_quantity || 0;
1339
1360
  },
1340
1361
  promotion_name: (context) => {
1341
1362
  return context.meta.promotion_name || null;
@@ -1346,9 +1367,6 @@ var metaAdapters = {
1346
1367
  creative_slot: (context) => {
1347
1368
  return context.meta.creative_slot || null;
1348
1369
  },
1349
- zipcode: (context) => {
1350
- return context.zipCode || null;
1351
- },
1352
1370
  size: (context) => {
1353
1371
  return context.size || null;
1354
1372
  },
@@ -1360,139 +1378,22 @@ var metaAdapters = {
1360
1378
  },
1361
1379
  type: (context) => {
1362
1380
  return context.type || null;
1363
- }
1364
- };
1365
-
1366
- // src/params/adapters/orderForm/index.ts
1367
- var orderFormAdapters = {
1368
- // orderform
1369
- payment_type: getPaymentType,
1370
- total_discount: (context) => {
1371
- var _a, _b;
1372
- if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
1373
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1374
- const items = context.orderForm.items;
1375
- const totalDiscount = items.reduce((acc, item) => {
1376
- const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1377
- return acc + unitDiscount * item.quantity;
1378
- }, 0);
1379
- const discounts = totalsList.find((t) => t.id === "Discounts");
1380
- return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1381
1381
  },
1382
- subtotal: (context) => {
1383
- var _a, _b;
1384
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1385
- const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1386
- return subtotal;
1382
+ color: (context) => {
1383
+ return context.meta.color || null;
1387
1384
  },
1388
- coupon_message: (context) => {
1389
- var _a;
1390
- if (context.couponMessage) return context.couponMessage;
1391
- const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1392
- if (messages.length === 0) return null;
1393
- const couponMessages = messages.filter(
1394
- (msg) => msg.text.toLowerCase().includes("cupom")
1395
- );
1396
- if (couponMessages.length === 0) return null;
1397
- return couponMessages.map((msg) => msg.text).join(" | ");
1385
+ price_range: (context) => {
1386
+ return context.meta.price_range || null;
1398
1387
  },
1399
- flag_pickup: (context) => {
1400
- var _a;
1401
- const orderForm = context.orderForm;
1402
- if (!orderForm) return null;
1403
- const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1404
- const hasPickup = logisticsInfo.some(
1405
- (info) => {
1406
- var _a2;
1407
- return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1408
- }
1409
- );
1410
- return hasPickup;
1388
+ category: (context) => {
1389
+ return context.meta.category || null;
1411
1390
  },
1412
- shippings: (context) => {
1413
- const orderForm = context.orderForm;
1414
- if (!orderForm) return null;
1415
- const groupShipping = {};
1416
- for (const info of orderForm.shippingData.logisticsInfo) {
1417
- const item = orderForm.items[info.itemIndex];
1418
- if (!item) continue;
1419
- for (const sla of info.slas) {
1420
- const key = sla.name;
1421
- if (!groupShipping[key]) {
1422
- groupShipping[key] = {
1423
- shipping_tier: sla.name,
1424
- delivery_time: parseInt(sla.shippingEstimate),
1425
- shipping: parseFloat((sla.price / 100).toFixed(1)),
1426
- line_items: []
1427
- };
1428
- }
1429
- groupShipping[key].line_items.push(item.id);
1430
- }
1431
- }
1432
- const shippings = Object.values(groupShipping).map((s) => ({
1433
- shipping: s.shipping,
1434
- shipping_tier: s.shipping_tier,
1435
- delivery_time: s.delivery_time,
1436
- line_items: s.line_items.join(",")
1437
- }));
1438
- return shippings || null;
1439
- },
1440
- shipping: (context) => {
1441
- var _a, _b, _c;
1442
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1443
- return logistics.reduce((total, item) => {
1444
- var _a2, _b2;
1445
- const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1446
- return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1447
- }, 0);
1448
- },
1449
- shipping_tier: (context) => {
1450
- var _a, _b, _c;
1451
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1452
- const selectedSlas = logistics.map((item) => {
1453
- var _a2;
1454
- if (!item.selectedSla) return null;
1455
- return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1456
- }).filter(Boolean);
1457
- if (selectedSlas.length === 0) return null;
1458
- const uniqueTiers = Array.from(
1459
- new Map(
1460
- selectedSlas.map((sla) => {
1461
- var _a2;
1462
- const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1463
- return [key, sla];
1464
- })
1465
- ).values()
1466
- );
1467
- const sortedTiers = uniqueTiers.sort((a, b) => {
1468
- var _a2, _b2;
1469
- const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1470
- const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1471
- if (aOrder !== bOrder) return aOrder - bOrder;
1472
- const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1473
- const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1474
- return aLabel.localeCompare(bLabel, "pt-BR");
1475
- });
1476
- const shippingTier = sortedTiers.map((sla) => {
1477
- var _a2;
1478
- return sla.deliveryChannel === "pickup-in-point" ? `retirada em loja${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) ? `: ${sla.pickupStoreInfo.friendlyName}` : ""}` : sla.deliveryChannel === "delivery" ? `receba em casa${sla.name ? `: ${sla.name}` : ""}` : null;
1479
- }).filter(Boolean).join(", ");
1480
- return shippingTier || null;
1481
- },
1482
- transaction_id: (context) => {
1483
- var _a, _b;
1484
- return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1485
- },
1486
- coupon: (context) => {
1487
- var _a, _b;
1488
- return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1489
- },
1490
- seller_cod_name: (context) => {
1491
- return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1391
+ ordering: (context) => {
1392
+ return context.meta.ordering || null;
1492
1393
  }
1493
1394
  };
1494
1395
 
1495
- // src/params/adapters/deco/utils/index.ts
1396
+ // src/params/adapters/deco/utils.ts
1496
1397
  var getItemCategory3 = (item) => {
1497
1398
  var _a;
1498
1399
  const value = item == null ? void 0 : item.category;
@@ -1510,12 +1411,6 @@ var getItemCategory22 = (item) => {
1510
1411
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1511
1412
  return capitalize(deepest);
1512
1413
  };
1513
- var resizeVtexImage2 = (url, width = 500, height = 500) => {
1514
- return url == null ? void 0 : url.replace(
1515
- /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1516
- `$1-${width}-${height}/`
1517
- );
1518
- };
1519
1414
  function getItemShippingTier2() {
1520
1415
  return null;
1521
1416
  }
@@ -1526,13 +1421,11 @@ var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
1526
1421
  var decoAdapter = {
1527
1422
  ...metaAdapters,
1528
1423
  // global adapters
1529
- ...orderFormAdapters,
1530
- // orderform adapters
1531
1424
  items: (context) => {
1532
1425
  if (context == null ? void 0 : context.items) return context.items;
1533
1426
  if (context == null ? void 0 : context.products) {
1534
1427
  return context.products.map((item) => {
1535
- 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;
1428
+ 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;
1536
1429
  const COLOR_REGEX = /^[^_]+_/;
1537
1430
  const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
1538
1431
  (s) => s.priceType === LIST_PRICE_SCHEMA
@@ -1543,21 +1436,21 @@ var decoAdapter = {
1543
1436
  item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
1544
1437
  item_name: (_h = item.alternateName) != null ? _h : null,
1545
1438
  price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
1546
- discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
1439
+ discount: Math.round((Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice)) * 100) / 100,
1547
1440
  item_variant: ((_m = (_l = item == null ? void 0 : item.name) == null ? void 0 : _l.split(" - ")[0]) == null ? void 0 : _m.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
1548
1441
  // cor
1549
1442
  item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
1550
1443
  // tamanho
1551
1444
  item_shipping_tier: getItemShippingTier2(),
1552
- item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
1553
- item_category: (_s = getItemCategory3(item)) != null ? _s : null,
1554
- item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
1555
- item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
1556
- item_sku: (_v = item.sku) != null ? _v : null,
1557
- item_url: (_w = item.url) != null ? _w : null,
1558
- image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
1559
- seller_id: (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) != null ? _C : null,
1560
- item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
1445
+ 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
+ item_category: (_t = getItemCategory3(item)) != null ? _t : null,
1447
+ item_category2: (_u = getItemCategory22(item)) != null ? _u : null,
1448
+ item_id: (_v = item == null ? void 0 : item.inProductGroupWithID) != null ? _v : null,
1449
+ item_sku: (_w = item.sku) != null ? _w : null,
1450
+ item_url: (_x = item.url) != null ? _x : null,
1451
+ image_url: (_z = resizeVtexImage2((_y = item == null ? void 0 : item.image) == null ? void 0 : _y[0].url)) != null ? _z : null,
1452
+ seller_id: (_D = (_C = (_B = (_A = item.offers) == null ? void 0 : _A.offers) == null ? void 0 : _B[0]) == null ? void 0 : _C.seller) != null ? _D : null,
1453
+ item_list_name: (_E = item == null ? void 0 : item.item_list_name) != null ? _E : null
1561
1454
  };
1562
1455
  });
1563
1456
  }
@@ -1611,8 +1504,202 @@ var decoAdapter = {
1611
1504
  }
1612
1505
  };
1613
1506
 
1614
- // src/params/adapters/headless/utils/index.ts
1507
+ // src/params/adapters/orderForm/utils.ts
1615
1508
  var getItemCategory5 = (item) => {
1509
+ var _a;
1510
+ const categories = item == null ? void 0 : item.productCategories;
1511
+ if (!categories) return "Cole\xE7\xE3o";
1512
+ const text = Object.values(categories).join(" ");
1513
+ const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1514
+ return match != null ? match : "Cole\xE7\xE3o";
1515
+ };
1516
+ var getItemCategory23 = (item) => {
1517
+ var _a, _b;
1518
+ const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1519
+ const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1520
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1521
+ const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1522
+ return capitalize(deepest);
1523
+ };
1524
+ var getOrderFormItems = (orderForm) => {
1525
+ const idSelected = orderForm == null ? void 0 : orderForm.selected;
1526
+ return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1527
+ };
1528
+
1529
+ // src/params/adapters/orderForm/index.ts
1530
+ var orderFormAdapter = {
1531
+ ...metaAdapters,
1532
+ items: (context) => {
1533
+ if (context == null ? void 0 : context.items) return context.items;
1534
+ if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1535
+ return getOrderFormItems(context.orderForm).map((item, index) => {
1536
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1537
+ return {
1538
+ quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1539
+ index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1540
+ item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1541
+ item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1542
+ price: (item == null ? void 0 : item.price) / 100,
1543
+ discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1544
+ 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
+ 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: "",
1547
+ item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1548
+ item_category: (_o = getItemCategory5(item)) != null ? _o : null,
1549
+ item_category2: (_p = getItemCategory23(item)) != null ? _p : null,
1550
+ item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1551
+ item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1552
+ item_url: (_s = item.detailUrl) != null ? _s : null,
1553
+ image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1554
+ seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1555
+ item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1556
+ };
1557
+ });
1558
+ }
1559
+ return null;
1560
+ },
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
+ // },
1568
+ line_items: (context) => {
1569
+ var _a;
1570
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1571
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1572
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1573
+ },
1574
+ value: (context) => {
1575
+ var _a;
1576
+ if (context == null ? void 0 : context.value) return context.value;
1577
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1578
+ return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.price) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1579
+ },
1580
+ payment_type: getPaymentType,
1581
+ total_discount: (context) => {
1582
+ 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) => {
1587
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1588
+ return acc + unitDiscount * item.quantity;
1589
+ }, 0);
1590
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1591
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1592
+ },
1593
+ subtotal: (context) => {
1594
+ var _a, _b;
1595
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1596
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1597
+ return subtotal;
1598
+ },
1599
+ coupon_message: (context) => {
1600
+ var _a;
1601
+ if (context.couponMessage) return context.couponMessage;
1602
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1603
+ if (messages.length === 0) return null;
1604
+ const couponMessages = messages.filter(
1605
+ (msg) => msg.text.toLowerCase().includes("cupom")
1606
+ );
1607
+ if (couponMessages.length === 0) return null;
1608
+ return couponMessages.map((msg) => msg.text).join(" | ");
1609
+ },
1610
+ zipcode: (context) => {
1611
+ var _a;
1612
+ return (_a = context.zipcode) != null ? _a : null;
1613
+ },
1614
+ flag_pickup: (context) => {
1615
+ var _a;
1616
+ const orderForm = context.orderForm;
1617
+ if (!orderForm) return null;
1618
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1619
+ const hasPickup = logisticsInfo.some(
1620
+ (info) => {
1621
+ var _a2;
1622
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1623
+ }
1624
+ );
1625
+ return hasPickup;
1626
+ },
1627
+ shippings: (context) => {
1628
+ if (!context.orderForm) return null;
1629
+ const { items, shippingData } = context.orderForm;
1630
+ const acc = {};
1631
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1632
+ const item = items[itemIndex];
1633
+ if (!item) return;
1634
+ slas.forEach((sla) => {
1635
+ if (!acc[sla.name]) acc[sla.name] = {
1636
+ shipping_tier: sla.name,
1637
+ delivery_time: parseInt(sla.shippingEstimate),
1638
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1639
+ line_items: []
1640
+ };
1641
+ acc[sla.name].line_items.push(item.id);
1642
+ });
1643
+ });
1644
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1645
+ },
1646
+ shipping: (context) => {
1647
+ var _a, _b, _c;
1648
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1649
+ return logistics.reduce((total, item) => {
1650
+ var _a2, _b2;
1651
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1652
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1653
+ }, 0);
1654
+ },
1655
+ shipping_tier: (context) => {
1656
+ var _a, _b, _c;
1657
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1658
+ const selectedSlas = logistics.map((item) => {
1659
+ var _a2;
1660
+ if (!item.selectedSla) return null;
1661
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1662
+ }).filter(Boolean);
1663
+ if (selectedSlas.length === 0) return null;
1664
+ const uniqueTiers = Array.from(
1665
+ new Map(
1666
+ selectedSlas.map((sla) => {
1667
+ var _a2;
1668
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1669
+ return [key, sla];
1670
+ })
1671
+ ).values()
1672
+ );
1673
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1674
+ var _a2, _b2;
1675
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1676
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1677
+ if (aOrder !== bOrder) return aOrder - bOrder;
1678
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1679
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1680
+ return aLabel.localeCompare(bLabel, "pt-BR");
1681
+ });
1682
+ const shippingTier = sortedTiers.map((sla) => {
1683
+ var _a2;
1684
+ return sla.deliveryChannel === "pickup-in-point" ? `retirada em loja${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) ? `: ${sla.pickupStoreInfo.friendlyName}` : ""}` : sla.deliveryChannel === "delivery" ? `receba em casa${sla.name ? `: ${sla.name}` : ""}` : null;
1685
+ }).filter(Boolean).join(", ");
1686
+ return shippingTier || null;
1687
+ },
1688
+ transaction_id: (context) => {
1689
+ var _a, _b;
1690
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1691
+ },
1692
+ coupon: (context) => {
1693
+ var _a, _b;
1694
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1695
+ },
1696
+ seller_cod_name: (context) => {
1697
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1698
+ }
1699
+ };
1700
+
1701
+ // src/params/adapters/headless/utils.ts
1702
+ var getItemCategory6 = (item) => {
1616
1703
  const keywords = ["outlet", "bazar", "sale"];
1617
1704
  const regex = new RegExp(keywords.join("|"), "i");
1618
1705
  const value = item == null ? void 0 : item.categories;
@@ -1625,7 +1712,7 @@ var getItemCategory5 = (item) => {
1625
1712
  }
1626
1713
  return "Cole\xE7\xE3o";
1627
1714
  };
1628
- var getItemCategory23 = (item) => {
1715
+ var getItemCategory24 = (item) => {
1629
1716
  var _a, _b, _c;
1630
1717
  const avoidList = /outlet|bazar|sale/i;
1631
1718
  const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
@@ -1633,12 +1720,6 @@ var getItemCategory23 = (item) => {
1633
1720
  const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
1634
1721
  return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
1635
1722
  };
1636
- function resizeVtexImage3(url, width = 500, height = 500) {
1637
- return url == null ? void 0 : url.replace(
1638
- /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1639
- `$1-${width}-${height}/`
1640
- );
1641
- }
1642
1723
 
1643
1724
  // src/params/adapters/headless/zones/PDP.ts
1644
1725
  var HeadlessPdpZone = {
@@ -1655,18 +1736,19 @@ var HeadlessPdpZone = {
1655
1736
  item_brand: (_d = item.brand) != null ? _d : null,
1656
1737
  item_name: (_e = item.productName) != null ? _e : null,
1657
1738
  price: price != null ? price : null,
1739
+ item_shipping_tier: null,
1658
1740
  discount: Number(listPrice) - Number(price),
1659
1741
  item_variant: (_h = (_g = (_f = item.items[0]) == null ? void 0 : _f.name) == null ? void 0 : _g.split(" - ")[0]) != null ? _h : null,
1660
1742
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
1661
1743
  item_ref: (_l = item.productReference) != null ? _l : null,
1662
1744
  // sem ref no retorno do IS na multi-lib produtos PDC
1663
- item_category: getItemCategory5(item),
1664
- item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
1745
+ item_category: getItemCategory6(item),
1746
+ item_category2: (_m = getItemCategory24(item)) != null ? _m : null,
1665
1747
  item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
1666
1748
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1667
1749
  item_url: (_q = item.link) != null ? _q : null,
1668
1750
  // sem link/url no retorno do IS na multi-lib produtos PDC
1669
- image_url: (_t = resizeVtexImage3((_s = (_r = item == null ? void 0 : item.items) == null ? void 0 : _r[0].images) == null ? void 0 : _s[0].imageUrl)) != null ? _t : null,
1751
+ image_url: (_t = resizeVtexImage2((_s = (_r = item == null ? void 0 : item.items) == null ? void 0 : _r[0].images) == null ? void 0 : _s[0].imageUrl)) != null ? _t : null,
1670
1752
  seller_id: (_x = (_w = (_v = (_u = item.items) == null ? void 0 : _u[0]) == null ? void 0 : _v.sellers) == null ? void 0 : _w[0].sellerId) != null ? _x : null,
1671
1753
  item_list_name: (_y = item.item_list_name) != null ? _y : null
1672
1754
  };
@@ -1715,18 +1797,19 @@ var HeadlessPdcZone = {
1715
1797
  item_brand: (_b = item.brand.name) != null ? _b : null,
1716
1798
  item_name: (_c = item.name) != null ? _c : null,
1717
1799
  price: price != null ? price : null,
1800
+ item_shipping_tier: null,
1718
1801
  discount: Number(listPrice) - Number(price),
1719
1802
  item_variant: (_f = (_e = (_d = item.isVariantOf) == null ? void 0 : _d.hasVariant) == null ? void 0 : _e[0].name.split(" - ")[0]) != null ? _f : null,
1720
1803
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
1721
1804
  item_ref: null,
1722
1805
  // sem ref no retorno do IS na multi-lib produtos PDC
1723
- item_category: getItemCategory5(item),
1724
- item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
1806
+ item_category: getItemCategory6(item),
1807
+ item_category2: (_j = getItemCategory24(item)) != null ? _j : null,
1725
1808
  item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
1726
1809
  item_sku: (_l = item.sku) != null ? _l : null,
1727
1810
  item_url: null,
1728
1811
  // sem link/url no retorno do IS na multi-lib produtos PDC
1729
- image_url: (_n = resizeVtexImage3((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
1812
+ image_url: (_n = resizeVtexImage2((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
1730
1813
  seller_id: (_s = (_r = (_q = (_p = (_o = item.offers) == null ? void 0 : _o.offers) == null ? void 0 : _p.find((o) => o.availability)) == null ? void 0 : _q.seller) == null ? void 0 : _r.identifier) != null ? _s : null,
1731
1814
  item_list_name: (_t = item.item_list_name) != null ? _t : null
1732
1815
  };
@@ -1761,7 +1844,7 @@ var HeadlessPdcZone = {
1761
1844
  var headlessAdapter = {
1762
1845
  ...metaAdapters,
1763
1846
  // global adapters
1764
- ...orderFormAdapters,
1847
+ ...orderFormAdapter,
1765
1848
  // orderForm adapters, confirmar se no storefront tem evento que usa essses params
1766
1849
  brand: (context) => {
1767
1850
  if (context.zone === "PDP") {
@@ -1810,17 +1893,63 @@ var headlessAdapter = {
1810
1893
  }
1811
1894
  };
1812
1895
 
1896
+ // src/params/adapters/pickup/utils.ts
1897
+ var getShippingTier = (sla) => {
1898
+ var _a, _b;
1899
+ const isPickup = sla.deliveryChannel === "pickup-in-point" /* PickupInPoint */;
1900
+ if (isPickup) {
1901
+ const storeName = (_b = (_a = sla.pickupStoreInfo) == null ? void 0 : _a.friendlyName) == null ? void 0 : _b.trim();
1902
+ return storeName ? `retirada em loja: ${storeName}` : "retirada em loja";
1903
+ }
1904
+ return sla.name ? `receba em casa: ${sla.name.toLowerCase()}` : "receba em casa";
1905
+ };
1906
+ var getDeliveryTime = (sla) => {
1907
+ const estimate = sla.shippingEstimate;
1908
+ if (!estimate) return 0;
1909
+ const days = parseInt(estimate, 10);
1910
+ return isNaN(days) ? 0 : days;
1911
+ };
1912
+
1913
+ // src/params/adapters/pickup/index.ts
1914
+ var pickupAdapter = {
1915
+ ...metaAdapters,
1916
+ flag_pickup: (context) => {
1917
+ var _a;
1918
+ return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
1919
+ },
1920
+ shippings: (context) => {
1921
+ if (context.shippings) {
1922
+ return context.shippings.map((s) => {
1923
+ var _a, _b;
1924
+ return {
1925
+ line_items: (_a = s.line_items) != null ? _a : "",
1926
+ shipping: (_b = s.price) != null ? _b : 0,
1927
+ shipping_tier: getShippingTier(s),
1928
+ delivery_time: getDeliveryTime(s)
1929
+ };
1930
+ });
1931
+ }
1932
+ return null;
1933
+ },
1934
+ zipcode: (context) => {
1935
+ var _a;
1936
+ return (_a = context.zipcode) != null ? _a : null;
1937
+ }
1938
+ };
1939
+
1813
1940
  // src/formatter.ts
1814
1941
  var adapters = {
1815
1942
  DECO: decoAdapter,
1816
- HEADLESS: headlessAdapter
1943
+ HEADLESS: headlessAdapter,
1944
+ PICKUP: pickupAdapter,
1945
+ ORDERFORM: orderFormAdapter
1817
1946
  };
1818
1947
  async function getParameters(context, eventName) {
1819
1948
  var _a;
1820
1949
  const eventConfig = EVENTS[eventName];
1821
1950
  if (!eventConfig) return;
1822
1951
  const currentAdapter = context.adapter;
1823
- const getters = (_a = adapters[currentAdapter]) != null ? _a : paramGetters;
1952
+ const getters = (_a = adapters[currentAdapter]) != null ? _a : legacyGetters;
1824
1953
  const entries = await Promise.all(
1825
1954
  eventConfig.requiredParams.map(async (param) => {
1826
1955
  const getter = getters[param];