@azzas/azzas-tracker-web 2.0.0-preview.0 → 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.
@@ -23,6 +23,7 @@ var AzzasTracker = (() => {
23
23
  __export(src_exports, {
24
24
  EVENTS: () => EVENTS,
25
25
  default: () => src_default,
26
+ initTracker: () => initTracker,
26
27
  trackWebEvent: () => trackWebEvent
27
28
  });
28
29
 
@@ -318,7 +319,19 @@ var AzzasTracker = (() => {
318
319
  name: "notify_me",
319
320
  hasEcommerce: false,
320
321
  destinations: ["DataLayer"],
321
- requiredParams: ["brand", "line_items", "size", "item_ref"]
322
+ requiredParams: ["brand", "size", "item_ref"]
323
+ },
324
+ REFINE_RESULTS: {
325
+ name: "refine_results",
326
+ hasEcommerce: false,
327
+ destinations: ["DataLayer"],
328
+ requiredParams: ["brand", "region", "color", "price_range", "size", "category", "ordering"]
329
+ },
330
+ GRID_SIZE: {
331
+ name: "grid_size",
332
+ hasEcommerce: false,
333
+ destinations: ["DataLayer"],
334
+ requiredParams: ["brand", "slot_per_line"]
322
335
  }
323
336
  };
324
337
 
@@ -1000,6 +1013,12 @@ var AzzasTracker = (() => {
1000
1013
  return unique;
1001
1014
  };
1002
1015
  var capitalize = (str) => str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
1016
+ var resizeVtexImage2 = (url, width = 500, height = 500) => {
1017
+ return url == null ? void 0 : url.replace(
1018
+ /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1019
+ `$1-${width}-${height}/`
1020
+ );
1021
+ };
1003
1022
 
1004
1023
  // src/params/legacy/resolvers/paymentType/fromOrderForm.ts
1005
1024
  function paymentTypeFromOrderForm(context) {
@@ -1052,7 +1071,7 @@ var AzzasTracker = (() => {
1052
1071
  "store": "https://www.animale.com.br",
1053
1072
  "checkout": "https://secure.animale.com.br"
1054
1073
  },
1055
- "farm": {
1074
+ "lojafarm": {
1056
1075
  "store": "https://lojafarm.myvtex.com"
1057
1076
  },
1058
1077
  "mariafilo": {
@@ -1070,7 +1089,7 @@ var AzzasTracker = (() => {
1070
1089
  "bynv": {
1071
1090
  "store": "https://bynv.myvtex.com"
1072
1091
  },
1073
- "fabula": {
1092
+ "lojafabula": {
1074
1093
  "store": "https://lojafabula.myvtex.com"
1075
1094
  }
1076
1095
  };
@@ -1135,7 +1154,7 @@ var AzzasTracker = (() => {
1135
1154
  }
1136
1155
 
1137
1156
  // src/params/legacy/index.ts
1138
- var paramGetters = {
1157
+ var legacyGetters = {
1139
1158
  brand: getBrand,
1140
1159
  items: getItems,
1141
1160
  payment_type: getPaymentType,
@@ -1339,12 +1358,8 @@ var AzzasTracker = (() => {
1339
1358
  // src/params/adapters/meta/index.ts
1340
1359
  var metaAdapters = {
1341
1360
  user_info: getUserInfo,
1342
- brand: (context) => {
1343
- return context.meta.brand || null;
1344
- },
1345
1361
  content_type: (context) => {
1346
- if (context == null ? void 0 : context.content_type) return context.content_type;
1347
- return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
1362
+ return context.meta.content_type || null;
1348
1363
  },
1349
1364
  region: (context) => {
1350
1365
  return context.meta.region || null;
@@ -1352,18 +1367,22 @@ var AzzasTracker = (() => {
1352
1367
  pre_filled: (context) => {
1353
1368
  return !!context.preFilled;
1354
1369
  },
1355
- currency: (context) => {
1356
- if (context == null ? void 0 : context.currency) return context.currency;
1370
+ currency: (_, config2) => {
1371
+ if (config2 == null ? void 0 : config2.currency) return config2.currency;
1357
1372
  return "BRL";
1358
1373
  },
1374
+ slot_per_line: (context) => {
1375
+ var _a;
1376
+ return (_a = context.meta.slot_per_line) != null ? _a : null;
1377
+ },
1359
1378
  search_term: (context) => {
1360
- return context.searchTerm || null;
1379
+ return context.meta.search_term || null;
1361
1380
  },
1362
1381
  search_found: (context) => {
1363
- return !!context.searchFound;
1382
+ return context.meta.search_found || null;
1364
1383
  },
1365
1384
  search_quantity: (context) => {
1366
- return context.searchQuantity || 0;
1385
+ return context.meta.search_quantity || 0;
1367
1386
  },
1368
1387
  promotion_name: (context) => {
1369
1388
  return context.meta.promotion_name || null;
@@ -1374,153 +1393,66 @@ var AzzasTracker = (() => {
1374
1393
  creative_slot: (context) => {
1375
1394
  return context.meta.creative_slot || null;
1376
1395
  },
1377
- zipcode: (context) => {
1378
- return context.zipCode || null;
1379
- },
1380
- size: (context) => {
1381
- return context.size || null;
1382
- },
1383
1396
  item_ref: (context) => {
1384
- return context.itemRef || null;
1397
+ return context.meta.item_ref || null;
1385
1398
  },
1386
1399
  method: (context) => {
1387
- return context.method || null;
1400
+ return context.meta.method || null;
1388
1401
  },
1389
1402
  type: (context) => {
1390
- return context.type || null;
1391
- }
1392
- };
1393
-
1394
- // src/params/adapters/orderForm/index.ts
1395
- var orderFormAdapters = {
1396
- // orderform
1397
- payment_type: getPaymentType,
1398
- total_discount: (context) => {
1399
- var _a, _b;
1400
- if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
1401
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1402
- const items = context.orderForm.items;
1403
- const totalDiscount = items.reduce((acc, item) => {
1404
- const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1405
- return acc + unitDiscount * item.quantity;
1406
- }, 0);
1407
- const discounts = totalsList.find((t) => t.id === "Discounts");
1408
- return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1403
+ return context.meta.type || null;
1409
1404
  },
1410
- subtotal: (context) => {
1411
- var _a, _b;
1412
- const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1413
- const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1414
- return subtotal;
1405
+ color: (context) => {
1406
+ return context.meta.color || null;
1415
1407
  },
1416
- coupon_message: (context) => {
1417
- var _a;
1418
- if (context.couponMessage) return context.couponMessage;
1419
- const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1420
- if (messages.length === 0) return null;
1421
- const couponMessages = messages.filter(
1422
- (msg) => msg.text.toLowerCase().includes("cupom")
1423
- );
1424
- if (couponMessages.length === 0) return null;
1425
- return couponMessages.map((msg) => msg.text).join(" | ");
1408
+ price_range: (context) => {
1409
+ return context.meta.price_range || null;
1426
1410
  },
1427
- flag_pickup: (context) => {
1428
- var _a;
1429
- const orderForm = context.orderForm;
1430
- if (!orderForm) return null;
1431
- const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1432
- const hasPickup = logisticsInfo.some(
1433
- (info) => {
1434
- var _a2;
1435
- return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1436
- }
1437
- );
1438
- return hasPickup;
1411
+ category: (context) => {
1412
+ return context.meta.category || null;
1439
1413
  },
1440
- shippings: (context) => {
1441
- const orderForm = context.orderForm;
1442
- if (!orderForm) return null;
1443
- const groupShipping = {};
1444
- for (const info of orderForm.shippingData.logisticsInfo) {
1445
- const item = orderForm.items[info.itemIndex];
1446
- if (!item) continue;
1447
- for (const sla of info.slas) {
1448
- const key = sla.name;
1449
- if (!groupShipping[key]) {
1450
- groupShipping[key] = {
1451
- shipping_tier: sla.name,
1452
- delivery_time: parseInt(sla.shippingEstimate),
1453
- shipping: parseFloat((sla.price / 100).toFixed(1)),
1454
- line_items: []
1455
- };
1456
- }
1457
- groupShipping[key].line_items.push(item.id);
1458
- }
1459
- }
1460
- const shippings = Object.values(groupShipping).map((s) => ({
1461
- shipping: s.shipping,
1462
- shipping_tier: s.shipping_tier,
1463
- delivery_time: s.delivery_time,
1464
- line_items: s.line_items.join(",")
1465
- }));
1466
- return shippings || null;
1414
+ ordering: (context) => {
1415
+ return context.meta.ordering || null;
1467
1416
  },
1468
- shipping: (context) => {
1469
- var _a, _b, _c;
1470
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1471
- return logistics.reduce((total, item) => {
1472
- var _a2, _b2;
1473
- const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1474
- return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1475
- }, 0);
1476
- },
1477
- shipping_tier: (context) => {
1478
- var _a, _b, _c;
1479
- const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1480
- const selectedSlas = logistics.map((item) => {
1417
+ size: (context) => {
1418
+ return context.meta.size || null;
1419
+ }
1420
+ };
1421
+
1422
+ // src/core/farm.ts
1423
+ var BRAND_CODES2 = {
1424
+ farm: "farmrio",
1425
+ "farm etc": "farmetc",
1426
+ "farm rio": "farmrio"
1427
+ };
1428
+ function getBrandCode2(brand) {
1429
+ if (!brand) return null;
1430
+ const standardized = brand.toLowerCase().trim();
1431
+ return BRAND_CODES2[standardized] || null;
1432
+ }
1433
+ function normalizeBrand2(input) {
1434
+ var _a;
1435
+ let brandStrings = [];
1436
+ if (Array.isArray(input) && input.every((item) => typeof item === "string")) {
1437
+ brandStrings = input;
1438
+ } else if (Array.isArray(input)) {
1439
+ brandStrings = input.map((item) => {
1481
1440
  var _a2;
1482
- if (!item.selectedSla) return null;
1483
- return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1484
- }).filter(Boolean);
1485
- if (selectedSlas.length === 0) return null;
1486
- const uniqueTiers = Array.from(
1487
- new Map(
1488
- selectedSlas.map((sla) => {
1489
- var _a2;
1490
- const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1491
- return [key, sla];
1492
- })
1493
- ).values()
1494
- );
1495
- const sortedTiers = uniqueTiers.sort((a, b) => {
1496
- var _a2, _b2;
1497
- const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1498
- const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1499
- if (aOrder !== bOrder) return aOrder - bOrder;
1500
- const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1501
- const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1502
- return aLabel.localeCompare(bLabel, "pt-BR");
1441
+ return ((_a2 = item.additionalInfo) == null ? void 0 : _a2.brandName) || item.brand;
1503
1442
  });
1504
- const shippingTier = sortedTiers.map((sla) => {
1505
- var _a2;
1506
- 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;
1507
- }).filter(Boolean).join(", ");
1508
- return shippingTier || null;
1509
- },
1510
- transaction_id: (context) => {
1511
- var _a, _b;
1512
- return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1513
- },
1514
- coupon: (context) => {
1515
- var _a, _b;
1516
- return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1517
- },
1518
- seller_cod_name: (context) => {
1519
- return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1443
+ } else if (typeof input === "object" && input !== null && "brand" in input) {
1444
+ brandStrings = [((_a = input.additionalInfo) == null ? void 0 : _a.brandName) || input.brand];
1445
+ } else if (typeof input === "string") {
1446
+ return getBrandCode2(input);
1447
+ } else {
1448
+ return null;
1520
1449
  }
1521
- };
1450
+ const brandCodes = brandStrings.map(getBrandCode2).filter((code) => code !== null);
1451
+ const uniqueSortedCodes = [...new Set(brandCodes)].sort();
1452
+ return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
1453
+ }
1522
1454
 
1523
- // src/params/adapters/deco/utils/index.ts
1455
+ // src/params/adapters/deco/utils.ts
1524
1456
  var getItemCategory3 = (item) => {
1525
1457
  var _a;
1526
1458
  const value = item == null ? void 0 : item.category;
@@ -1538,15 +1470,6 @@ var AzzasTracker = (() => {
1538
1470
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1539
1471
  return capitalize(deepest);
1540
1472
  };
1541
- var resizeVtexImage2 = (url, width = 500, height = 500) => {
1542
- return url == null ? void 0 : url.replace(
1543
- /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1544
- `$1-${width}-${height}/`
1545
- );
1546
- };
1547
- function getItemShippingTier2() {
1548
- return null;
1549
- }
1550
1473
 
1551
1474
  // src/params/adapters/deco/index.ts
1552
1475
  var IN_STOCK_SCHEMA = "https://schema.org/InStock";
@@ -1554,13 +1477,11 @@ var AzzasTracker = (() => {
1554
1477
  var decoAdapter = {
1555
1478
  ...metaAdapters,
1556
1479
  // global adapters
1557
- ...orderFormAdapters,
1558
- // orderform adapters
1559
1480
  items: (context) => {
1560
1481
  if (context == null ? void 0 : context.items) return context.items;
1561
1482
  if (context == null ? void 0 : context.products) {
1562
1483
  return context.products.map((item) => {
1563
- 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;
1484
+ 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;
1564
1485
  const COLOR_REGEX = /^[^_]+_/;
1565
1486
  const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
1566
1487
  (s) => s.priceType === LIST_PRICE_SCHEMA
@@ -1571,33 +1492,37 @@ var AzzasTracker = (() => {
1571
1492
  item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
1572
1493
  item_name: (_h = item.alternateName) != null ? _h : null,
1573
1494
  price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
1574
- discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
1495
+ discount: Math.round((Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice)) * 100) / 100,
1575
1496
  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,
1576
1497
  // cor
1577
1498
  item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
1578
1499
  // tamanho
1579
- item_shipping_tier: getItemShippingTier2(),
1580
- item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
1581
- item_category: (_s = getItemCategory3(item)) != null ? _s : null,
1582
- item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
1583
- item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
1584
- item_sku: (_v = item.sku) != null ? _v : null,
1585
- item_url: (_w = item.url) != null ? _w : null,
1586
- image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
1587
- 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,
1588
- item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
1500
+ item_shipping_tier: "",
1501
+ 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,
1502
+ item_category: (_t = getItemCategory3(item)) != null ? _t : null,
1503
+ item_category2: (_u = getItemCategory22(item)) != null ? _u : null,
1504
+ item_id: (_v = item == null ? void 0 : item.inProductGroupWithID) != null ? _v : null,
1505
+ item_sku: (_w = item.sku) != null ? _w : null,
1506
+ item_url: (_x = item.url) != null ? _x : null,
1507
+ image_url: (_z = resizeVtexImage2((_y = item == null ? void 0 : item.image) == null ? void 0 : _y[0].url)) != null ? _z : null,
1508
+ 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,
1509
+ item_list_name: (_E = item == null ? void 0 : item.item_list_name) != null ? _E : null
1589
1510
  };
1590
1511
  });
1591
1512
  }
1592
1513
  return null;
1593
1514
  },
1594
- // brand: (context: DecoBrandContext) => {
1595
- // if (context?.brand) return context.brand
1596
- // if (context?.products) {
1597
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1598
- // }
1599
- // return null
1600
- // },
1515
+ brand: (context, config2) => {
1516
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1517
+ if (context == null ? void 0 : context.brand) return context.brand;
1518
+ if (context == null ? void 0 : context.products) {
1519
+ return normalizeBrand2(context.products.map((p) => {
1520
+ var _a;
1521
+ return (_a = p == null ? void 0 : p.brand) == null ? void 0 : _a.name;
1522
+ }));
1523
+ }
1524
+ return null;
1525
+ },
1601
1526
  line_items: (context) => {
1602
1527
  if (context == null ? void 0 : context.line_items) return context.line_items;
1603
1528
  if (context == null ? void 0 : context.products) {
@@ -1639,7 +1564,7 @@ var AzzasTracker = (() => {
1639
1564
  }
1640
1565
  };
1641
1566
 
1642
- // src/params/adapters/headless/utils/index.ts
1567
+ // src/params/adapters/headless/utils.ts
1643
1568
  var getItemCategory5 = (item) => {
1644
1569
  const keywords = ["outlet", "bazar", "sale"];
1645
1570
  const regex = new RegExp(keywords.join("|"), "i");
@@ -1661,12 +1586,6 @@ var AzzasTracker = (() => {
1661
1586
  const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
1662
1587
  return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
1663
1588
  };
1664
- function resizeVtexImage3(url, width = 500, height = 500) {
1665
- return url == null ? void 0 : url.replace(
1666
- /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1667
- `$1-${width}-${height}/`
1668
- );
1669
- }
1670
1589
 
1671
1590
  // src/params/adapters/headless/zones/PDP.ts
1672
1591
  var HeadlessPdpZone = {
@@ -1683,6 +1602,7 @@ var AzzasTracker = (() => {
1683
1602
  item_brand: (_d = item.brand) != null ? _d : null,
1684
1603
  item_name: (_e = item.productName) != null ? _e : null,
1685
1604
  price: price != null ? price : null,
1605
+ item_shipping_tier: null,
1686
1606
  discount: Number(listPrice) - Number(price),
1687
1607
  item_variant: (_h = (_g = (_f = item.items[0]) == null ? void 0 : _f.name) == null ? void 0 : _g.split(" - ")[0]) != null ? _h : null,
1688
1608
  item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
@@ -1694,7 +1614,7 @@ var AzzasTracker = (() => {
1694
1614
  item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
1695
1615
  item_url: (_q = item.link) != null ? _q : null,
1696
1616
  // sem link/url no retorno do IS na multi-lib produtos PDC
1697
- 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,
1617
+ 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,
1698
1618
  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,
1699
1619
  item_list_name: (_y = item.item_list_name) != null ? _y : null
1700
1620
  };
@@ -1719,7 +1639,8 @@ var AzzasTracker = (() => {
1719
1639
  }
1720
1640
  return null;
1721
1641
  },
1722
- brand: (context) => {
1642
+ brand: (context, config2) => {
1643
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1723
1644
  if (context == null ? void 0 : context.brand) return context.brand;
1724
1645
  if (context == null ? void 0 : context.products) {
1725
1646
  return context.products.map((p) => p.brand).join().trim();
@@ -1743,6 +1664,7 @@ var AzzasTracker = (() => {
1743
1664
  item_brand: (_b = item.brand.name) != null ? _b : null,
1744
1665
  item_name: (_c = item.name) != null ? _c : null,
1745
1666
  price: price != null ? price : null,
1667
+ item_shipping_tier: null,
1746
1668
  discount: Number(listPrice) - Number(price),
1747
1669
  item_variant: (_f = (_e = (_d = item.isVariantOf) == null ? void 0 : _d.hasVariant) == null ? void 0 : _e[0].name.split(" - ")[0]) != null ? _f : null,
1748
1670
  item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
@@ -1754,7 +1676,7 @@ var AzzasTracker = (() => {
1754
1676
  item_sku: (_l = item.sku) != null ? _l : null,
1755
1677
  item_url: null,
1756
1678
  // sem link/url no retorno do IS na multi-lib produtos PDC
1757
- image_url: (_n = resizeVtexImage3((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
1679
+ image_url: (_n = resizeVtexImage2((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
1758
1680
  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,
1759
1681
  item_list_name: (_t = item.item_list_name) != null ? _t : null
1760
1682
  };
@@ -1776,7 +1698,8 @@ var AzzasTracker = (() => {
1776
1698
  }
1777
1699
  return null;
1778
1700
  },
1779
- brand: (context) => {
1701
+ brand: (context, config2) => {
1702
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1780
1703
  if (context == null ? void 0 : context.brand) return context.brand;
1781
1704
  if (context == null ? void 0 : context.products) {
1782
1705
  return context.products.map((p) => p.brand.name).join().trim();
@@ -1789,14 +1712,12 @@ var AzzasTracker = (() => {
1789
1712
  var headlessAdapter = {
1790
1713
  ...metaAdapters,
1791
1714
  // global adapters
1792
- ...orderFormAdapters,
1793
- // orderForm adapters, confirmar se no storefront tem evento que usa essses params
1794
- brand: (context) => {
1715
+ brand: (context, config2) => {
1795
1716
  if (context.zone === "PDP") {
1796
- return HeadlessPdpZone.brand(context);
1717
+ return HeadlessPdpZone.brand(context, config2);
1797
1718
  }
1798
1719
  if (context.zone === "PDC") {
1799
- return HeadlessPdcZone.brand(context);
1720
+ return HeadlessPdcZone.brand(context, config2);
1800
1721
  }
1801
1722
  return null;
1802
1723
  },
@@ -1838,17 +1759,271 @@ var AzzasTracker = (() => {
1838
1759
  }
1839
1760
  };
1840
1761
 
1762
+ // src/params/adapters/pickup/utils.ts
1763
+ var getShippingTier = (sla) => {
1764
+ var _a, _b;
1765
+ const isPickup = sla.deliveryChannel === "pickup-in-point" /* PickupInPoint */;
1766
+ if (isPickup) {
1767
+ const storeName = (_b = (_a = sla.pickupStoreInfo) == null ? void 0 : _a.friendlyName) == null ? void 0 : _b.trim();
1768
+ return storeName ? `retirada em loja: ${storeName}` : "retirada em loja";
1769
+ }
1770
+ return sla.name ? `receba em casa: ${sla.name.toLowerCase()}` : "receba em casa";
1771
+ };
1772
+ var getDeliveryTime = (sla) => {
1773
+ const estimate = sla.shippingEstimate;
1774
+ if (!estimate) return 0;
1775
+ const days = parseInt(estimate, 10);
1776
+ return isNaN(days) ? 0 : days;
1777
+ };
1778
+
1779
+ // src/params/adapters/pickup/index.ts
1780
+ var pickupAdapter = {
1781
+ ...metaAdapters,
1782
+ flag_pickup: (context) => {
1783
+ var _a;
1784
+ return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
1785
+ },
1786
+ shippings: (context) => {
1787
+ if (context.shippings) {
1788
+ return context.shippings.map((s) => {
1789
+ var _a;
1790
+ return {
1791
+ line_items: (_a = s.line_items) != null ? _a : "",
1792
+ shipping: s.price / 100,
1793
+ shipping_tier: getShippingTier(s),
1794
+ delivery_time: getDeliveryTime(s)
1795
+ };
1796
+ });
1797
+ }
1798
+ return null;
1799
+ },
1800
+ brand: (context, config2) => {
1801
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1802
+ if (context == null ? void 0 : context.brand) return context.brand;
1803
+ return null;
1804
+ },
1805
+ zipcode: (context) => {
1806
+ var _a;
1807
+ return (_a = context.meta.zipcode) != null ? _a : null;
1808
+ }
1809
+ };
1810
+
1811
+ // src/params/adapters/orderForm/utils.ts
1812
+ var getItemCategory6 = (item) => {
1813
+ var _a;
1814
+ const categories = item == null ? void 0 : item.productCategories;
1815
+ if (!categories) return "Cole\xE7\xE3o";
1816
+ const text = Object.values(categories).join(" ");
1817
+ const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1818
+ return match != null ? match : "Cole\xE7\xE3o";
1819
+ };
1820
+ var getItemCategory24 = (item) => {
1821
+ var _a, _b;
1822
+ const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1823
+ const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1824
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1825
+ const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1826
+ return capitalize(deepest);
1827
+ };
1828
+ function getItemShippingTier2(orderForm, item) {
1829
+ var _a, _b, _c, _d;
1830
+ const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1831
+ (li) => li.itemId === item.id
1832
+ );
1833
+ const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1834
+ return ((_d = selectedSla == null ? void 0 : selectedSla.pickupStoreInfo) == null ? void 0 : _d.friendlyName) ? `retirada em loja: ${selectedSla.pickupStoreInfo.friendlyName}` : (selectedSla == null ? void 0 : selectedSla.name) ? `Receba em casa: ${selectedSla.name}` : null;
1835
+ }
1836
+ var getOrderFormItems = (orderForm) => {
1837
+ const idSelected = orderForm == null ? void 0 : orderForm.selected;
1838
+ return idSelected ? orderForm.items.filter((item) => item.id === idSelected) : orderForm.items;
1839
+ };
1840
+
1841
+ // src/params/adapters/orderForm/index.ts
1842
+ var orderFormAdapter = {
1843
+ ...metaAdapters,
1844
+ items: (context) => {
1845
+ if (context == null ? void 0 : context.items) return context.items;
1846
+ if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1847
+ return getOrderFormItems(context.orderForm).map((item, index) => {
1848
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1849
+ return {
1850
+ quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1851
+ index: (_d = (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index) != null ? _d : null,
1852
+ item_brand: (_f = (_e = item.additionalInfo) == null ? void 0 : _e.brandName) != null ? _f : null,
1853
+ item_name: (_g = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _g : null,
1854
+ price: (item == null ? void 0 : item.price) / 100,
1855
+ discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1856
+ 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,
1857
+ 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,
1858
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1859
+ item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1860
+ item_category: (_o = getItemCategory6(item)) != null ? _o : null,
1861
+ item_category2: (_p = getItemCategory24(item)) != null ? _p : null,
1862
+ item_id: (_q = item == null ? void 0 : item.productId) != null ? _q : null,
1863
+ item_sku: (_r = item == null ? void 0 : item.id) != null ? _r : null,
1864
+ item_url: (_s = item.detailUrl) != null ? _s : null,
1865
+ image_url: (_t = resizeVtexImage2(item.imageUrl)) != null ? _t : null,
1866
+ seller_id: (_u = item == null ? void 0 : item.seller) != null ? _u : null,
1867
+ item_list_name: (_w = (_v = context == null ? void 0 : context.orderForm) == null ? void 0 : _v.item_list_name) != null ? _w : null
1868
+ };
1869
+ });
1870
+ }
1871
+ return null;
1872
+ },
1873
+ brand: (context, config2) => {
1874
+ var _a;
1875
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1876
+ if (context == null ? void 0 : context.brand) return context.brand;
1877
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1878
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1879
+ return normalizeBrand2(brands);
1880
+ },
1881
+ line_items: (context) => {
1882
+ var _a;
1883
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1884
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1885
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id));
1886
+ },
1887
+ value: (context) => {
1888
+ var _a;
1889
+ if (context == null ? void 0 : context.value) return context.value;
1890
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1891
+ 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);
1892
+ },
1893
+ payment_type: getPaymentType,
1894
+ total_discount: (context) => {
1895
+ var _a, _b;
1896
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1897
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1898
+ const totalsList = ((_b = context.orderForm) == null ? void 0 : _b.totalizers) || [];
1899
+ const totalDiscount = getOrderFormItems(context.orderForm).reduce((acc, item) => {
1900
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1901
+ return acc + unitDiscount * item.quantity;
1902
+ }, 0);
1903
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1904
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1905
+ },
1906
+ subtotal: (context) => {
1907
+ var _a, _b;
1908
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1909
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1910
+ return subtotal;
1911
+ },
1912
+ coupon_message: (context) => {
1913
+ var _a;
1914
+ if (context.couponMessage) return context.couponMessage;
1915
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1916
+ if (messages.length === 0) return null;
1917
+ const couponMessages = messages.filter(
1918
+ (msg) => msg.text.toLowerCase().includes("cupom")
1919
+ );
1920
+ if (couponMessages.length === 0) return null;
1921
+ return couponMessages.map((msg) => msg.text).join(" | ");
1922
+ },
1923
+ zipcode: (context) => {
1924
+ var _a;
1925
+ return (_a = context.meta.zipcode) != null ? _a : null;
1926
+ },
1927
+ flag_pickup: (context) => {
1928
+ var _a;
1929
+ const orderForm = context.orderForm;
1930
+ if (!orderForm) return null;
1931
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1932
+ const hasPickup = logisticsInfo.some(
1933
+ (info) => {
1934
+ var _a2;
1935
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1936
+ }
1937
+ );
1938
+ return hasPickup;
1939
+ },
1940
+ shippings: (context) => {
1941
+ if (!context.orderForm) return null;
1942
+ const { items, shippingData } = context.orderForm;
1943
+ const acc = {};
1944
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
1945
+ const item = items[itemIndex];
1946
+ if (!item) return;
1947
+ slas.forEach((sla) => {
1948
+ if (!acc[sla.name]) acc[sla.name] = {
1949
+ shipping_tier: sla.name,
1950
+ delivery_time: parseInt(sla.shippingEstimate),
1951
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1952
+ line_items: []
1953
+ };
1954
+ acc[sla.name].line_items.push(item.id);
1955
+ });
1956
+ });
1957
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
1958
+ },
1959
+ shipping: (context) => {
1960
+ var _a, _b, _c;
1961
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1962
+ return logistics.reduce((total, item) => {
1963
+ var _a2, _b2;
1964
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1965
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1966
+ }, 0);
1967
+ },
1968
+ shipping_tier: (context) => {
1969
+ var _a, _b, _c;
1970
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1971
+ const selectedSlas = logistics.map((item) => {
1972
+ var _a2;
1973
+ if (!item.selectedSla) return null;
1974
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1975
+ }).filter(Boolean);
1976
+ if (selectedSlas.length === 0) return null;
1977
+ const uniqueTiers = Array.from(
1978
+ new Map(
1979
+ selectedSlas.map((sla) => {
1980
+ var _a2;
1981
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1982
+ return [key, sla];
1983
+ })
1984
+ ).values()
1985
+ );
1986
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1987
+ var _a2, _b2;
1988
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1989
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1990
+ if (aOrder !== bOrder) return aOrder - bOrder;
1991
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1992
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1993
+ return aLabel.localeCompare(bLabel, "pt-BR");
1994
+ });
1995
+ const shippingTier = sortedTiers.map((sla) => {
1996
+ var _a2;
1997
+ 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;
1998
+ }).filter(Boolean).join(", ");
1999
+ return shippingTier || null;
2000
+ },
2001
+ transaction_id: (context) => {
2002
+ var _a, _b;
2003
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
2004
+ },
2005
+ coupon: (context) => {
2006
+ var _a, _b;
2007
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
2008
+ },
2009
+ seller_cod_name: (context) => {
2010
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
2011
+ }
2012
+ };
2013
+
1841
2014
  // src/formatter.ts
1842
2015
  var adapters = {
1843
2016
  DECO: decoAdapter,
1844
- HEADLESS: headlessAdapter
2017
+ HEADLESS: headlessAdapter,
2018
+ PICKUP: pickupAdapter,
2019
+ ORDERFORM: orderFormAdapter
1845
2020
  };
1846
- async function getParameters(context, eventName) {
2021
+ async function getParameters(context, eventName, config2) {
1847
2022
  var _a;
1848
2023
  const eventConfig = EVENTS[eventName];
1849
2024
  if (!eventConfig) return;
1850
2025
  const currentAdapter = context.adapter;
1851
- const getters = (_a = adapters[currentAdapter]) != null ? _a : paramGetters;
2026
+ const getters = (_a = adapters[currentAdapter]) != null ? _a : legacyGetters;
1852
2027
  const entries = await Promise.all(
1853
2028
  eventConfig.requiredParams.map(async (param) => {
1854
2029
  const getter = getters[param];
@@ -1856,16 +2031,20 @@ var AzzasTracker = (() => {
1856
2031
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
1857
2032
  return [param, null];
1858
2033
  }
1859
- return [param, await getter(context, eventName)];
2034
+ return [param, await getter(context, config2)];
1860
2035
  })
1861
2036
  );
1862
2037
  return Object.fromEntries(entries);
1863
2038
  }
1864
2039
 
1865
2040
  // src/index.ts
2041
+ var config = { brand: "", currency: "BRL" };
2042
+ function initTracker(c) {
2043
+ config = c;
2044
+ }
1866
2045
  async function trackWebEvent(event, context) {
1867
2046
  try {
1868
- const parameters = await getParameters(context, event);
2047
+ const parameters = await getParameters(context, event, config);
1869
2048
  if (isDebugMode()) {
1870
2049
  console.log(`[DT v2] ${event}, context e parameters: `, {
1871
2050
  context,