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

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
@@ -290,7 +290,7 @@ var EVENTS = {
290
290
  name: "notify_me",
291
291
  hasEcommerce: false,
292
292
  destinations: ["DataLayer"],
293
- requiredParams: ["brand", "line_items", "size", "item_ref"]
293
+ requiredParams: ["brand", "size", "item_ref"]
294
294
  },
295
295
  REFINE_RESULTS: {
296
296
  name: "refine_results",
@@ -1042,7 +1042,7 @@ var PROD_DOMAINS = {
1042
1042
  "store": "https://www.animale.com.br",
1043
1043
  "checkout": "https://secure.animale.com.br"
1044
1044
  },
1045
- "farm": {
1045
+ "lojafarm": {
1046
1046
  "store": "https://lojafarm.myvtex.com"
1047
1047
  },
1048
1048
  "mariafilo": {
@@ -1060,23 +1060,23 @@ var PROD_DOMAINS = {
1060
1060
  "bynv": {
1061
1061
  "store": "https://bynv.myvtex.com"
1062
1062
  },
1063
- "fabula": {
1063
+ "lojafabula": {
1064
1064
  "store": "https://lojafabula.myvtex.com"
1065
1065
  }
1066
1066
  };
1067
1067
  async function getUserInfo(context) {
1068
- var _a, _b, _c, _d, _e;
1069
- const domain = (_a = PROD_DOMAINS[context.account || "animale"]) == null ? void 0 : _a[context.platform || "store"];
1070
- if (!domain) return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
1068
+ 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, _F, _G, _H, _I;
1069
+ const domain = (_e = PROD_DOMAINS[(_b = (_a = context == null ? void 0 : context.meta) == null ? void 0 : _a.user_info) == null ? void 0 : _b.account]) == null ? void 0 : _e[(_d = (_c = context == null ? void 0 : context.meta) == null ? void 0 : _c.user_info) == null ? void 0 : _d.platform];
1070
+ if (!domain) return { customer: { email: (_g = (_f = context == null ? void 0 : context.meta) == null ? void 0 : _f.user_info) == null ? void 0 : _g.userEmail, id: (_i = (_h = context == null ? void 0 : context.meta) == null ? void 0 : _h.user_info) == null ? void 0 : _i.userId }, address: null };
1071
1071
  try {
1072
1072
  const api = `${domain}/_v/user-info`;
1073
1073
  const response = await fetch(api, {
1074
1074
  method: "POST",
1075
- body: JSON.stringify({ email: context.userEmail })
1075
+ body: JSON.stringify({ email: (_k = (_j = context == null ? void 0 : context.meta) == null ? void 0 : _j.user_info) == null ? void 0 : _k.userEmail })
1076
1076
  });
1077
1077
  if (response.status !== 200) {
1078
- if ((context == null ? void 0 : context.manuallyInfo) && ((_b = context.manuallyInfo) == null ? void 0 : _b.cpf)) {
1079
- const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = context.manuallyInfo;
1078
+ if (((_m = (_l = context == null ? void 0 : context.meta) == null ? void 0 : _l.user_info) == null ? void 0 : _m.manuallyInfo) && ((_p = (_o = (_n = context == null ? void 0 : context.meta) == null ? void 0 : _n.user_info) == null ? void 0 : _o.manuallyInfo) == null ? void 0 : _p.cpf)) {
1079
+ const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = (_r = (_q = context == null ? void 0 : context.meta) == null ? void 0 : _q.user_info) == null ? void 0 : _r.manuallyInfo;
1080
1080
  const document3 = cpf == null ? void 0 : cpf.replace(/\D/g, "");
1081
1081
  const hashedDocument2 = await documentToHash(document3);
1082
1082
  return {
@@ -1094,15 +1094,15 @@ async function getUserInfo(context) {
1094
1094
  }
1095
1095
  };
1096
1096
  }
1097
- return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
1097
+ return { customer: { email: (_t = (_s = context == null ? void 0 : context.meta) == null ? void 0 : _s.user_info) == null ? void 0 : _t.userEmail, id: (_v = (_u = context == null ? void 0 : context.meta) == null ? void 0 : _u.user_info) == null ? void 0 : _v.userId }, address: null };
1098
1098
  }
1099
1099
  const res = await response.json();
1100
- const document2 = (_d = (_c = res == null ? void 0 : res.customer) == null ? void 0 : _c.document) == null ? void 0 : _d.replace(/\D/g, "");
1100
+ const document2 = (_x = (_w = res == null ? void 0 : res.customer) == null ? void 0 : _w.document) == null ? void 0 : _x.replace(/\D/g, "");
1101
1101
  const hashedDocument = await documentToHash(document2);
1102
1102
  return { ...res, customer: { ...res.customer, cpf: hashedDocument, document: document2 } };
1103
1103
  } catch (_) {
1104
- if ((context == null ? void 0 : context.manuallyInfo) && ((_e = context.manuallyInfo) == null ? void 0 : _e.cpf)) {
1105
- const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = context.manuallyInfo;
1104
+ if (((_z = (_y = context == null ? void 0 : context.meta) == null ? void 0 : _y.user_info) == null ? void 0 : _z.manuallyInfo) && ((_C = (_B = (_A = context == null ? void 0 : context.meta) == null ? void 0 : _A.user_info) == null ? void 0 : _B.manuallyInfo) == null ? void 0 : _C.cpf)) {
1105
+ const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = (_E = (_D = context == null ? void 0 : context.meta) == null ? void 0 : _D.user_info) == null ? void 0 : _E.manuallyInfo;
1106
1106
  const document2 = cpf == null ? void 0 : cpf.replace(/\D/g, "");
1107
1107
  const hashedDocument = await documentToHash(document2);
1108
1108
  return {
@@ -1120,7 +1120,7 @@ async function getUserInfo(context) {
1120
1120
  }
1121
1121
  };
1122
1122
  }
1123
- return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
1123
+ return { customer: { email: (_G = (_F = context == null ? void 0 : context.meta) == null ? void 0 : _F.user_info) == null ? void 0 : _G.userEmail, id: (_I = (_H = context == null ? void 0 : context.meta) == null ? void 0 : _H.user_info) == null ? void 0 : _I.userId }, address: null };
1124
1124
  }
1125
1125
  }
1126
1126
 
@@ -1327,10 +1327,12 @@ var legacyGetters = {
1327
1327
  };
1328
1328
 
1329
1329
  // src/params/adapters/meta/index.ts
1330
- var metaAdapters = {
1330
+ var metaAdapter = {
1331
1331
  user_info: getUserInfo,
1332
- brand: (context) => {
1333
- return context.meta.brand || null;
1332
+ brand: (context, config2) => {
1333
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1334
+ if (context == null ? void 0 : context.meta.brand) return context.meta.brand;
1335
+ return null;
1334
1336
  },
1335
1337
  content_type: (context) => {
1336
1338
  return context.meta.content_type || null;
@@ -1341,8 +1343,8 @@ var metaAdapters = {
1341
1343
  pre_filled: (context) => {
1342
1344
  return !!context.preFilled;
1343
1345
  },
1344
- currency: (context) => {
1345
- if (context == null ? void 0 : context.currency) return context.currency;
1346
+ currency: (_, config2) => {
1347
+ if (config2 == null ? void 0 : config2.currency) return config2.currency;
1346
1348
  return "BRL";
1347
1349
  },
1348
1350
  slot_per_line: (context) => {
@@ -1353,7 +1355,7 @@ var metaAdapters = {
1353
1355
  return context.meta.search_term || null;
1354
1356
  },
1355
1357
  search_found: (context) => {
1356
- return context.meta.search_found || null;
1358
+ return context.meta.search_found || false;
1357
1359
  },
1358
1360
  search_quantity: (context) => {
1359
1361
  return context.meta.search_quantity || 0;
@@ -1367,17 +1369,14 @@ var metaAdapters = {
1367
1369
  creative_slot: (context) => {
1368
1370
  return context.meta.creative_slot || null;
1369
1371
  },
1370
- size: (context) => {
1371
- return context.size || null;
1372
- },
1373
1372
  item_ref: (context) => {
1374
- return context.itemRef || null;
1373
+ return context.meta.item_ref || null;
1375
1374
  },
1376
1375
  method: (context) => {
1377
- return context.method || null;
1376
+ return context.meta.method || null;
1378
1377
  },
1379
1378
  type: (context) => {
1380
- return context.type || null;
1379
+ return context.meta.type || null;
1381
1380
  },
1382
1381
  color: (context) => {
1383
1382
  return context.meta.color || null;
@@ -1390,9 +1389,45 @@ var metaAdapters = {
1390
1389
  },
1391
1390
  ordering: (context) => {
1392
1391
  return context.meta.ordering || null;
1392
+ },
1393
+ size: (context) => {
1394
+ return context.meta.size || null;
1393
1395
  }
1394
1396
  };
1395
1397
 
1398
+ // src/core/farm.ts
1399
+ var BRAND_CODES2 = {
1400
+ farm: "farmrio",
1401
+ "farm etc": "farmetc",
1402
+ "farm rio": "farmrio"
1403
+ };
1404
+ function getBrandCode2(brand) {
1405
+ if (!brand) return null;
1406
+ const standardized = brand.toLowerCase().trim();
1407
+ return BRAND_CODES2[standardized] || null;
1408
+ }
1409
+ function normalizeBrand2(input) {
1410
+ var _a;
1411
+ let brandStrings = [];
1412
+ if (Array.isArray(input) && input.every((item) => typeof item === "string")) {
1413
+ brandStrings = input;
1414
+ } else if (Array.isArray(input)) {
1415
+ brandStrings = input.map((item) => {
1416
+ var _a2;
1417
+ return ((_a2 = item.additionalInfo) == null ? void 0 : _a2.brandName) || item.brand;
1418
+ });
1419
+ } else if (typeof input === "object" && input !== null && "brand" in input) {
1420
+ brandStrings = [((_a = input.additionalInfo) == null ? void 0 : _a.brandName) || input.brand];
1421
+ } else if (typeof input === "string") {
1422
+ return getBrandCode2(input);
1423
+ } else {
1424
+ return null;
1425
+ }
1426
+ const brandCodes = brandStrings.map(getBrandCode2).filter((code) => code !== null);
1427
+ const uniqueSortedCodes = [...new Set(brandCodes)].sort();
1428
+ return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
1429
+ }
1430
+
1396
1431
  // src/params/adapters/deco/utils.ts
1397
1432
  var getItemCategory3 = (item) => {
1398
1433
  var _a;
@@ -1411,15 +1446,12 @@ var getItemCategory22 = (item) => {
1411
1446
  const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1412
1447
  return capitalize(deepest);
1413
1448
  };
1414
- function getItemShippingTier2() {
1415
- return null;
1416
- }
1417
1449
 
1418
1450
  // src/params/adapters/deco/index.ts
1419
1451
  var IN_STOCK_SCHEMA = "https://schema.org/InStock";
1420
1452
  var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
1421
1453
  var decoAdapter = {
1422
- ...metaAdapters,
1454
+ ...metaAdapter,
1423
1455
  // global adapters
1424
1456
  items: (context) => {
1425
1457
  if (context == null ? void 0 : context.items) return context.items;
@@ -1441,7 +1473,7 @@ var decoAdapter = {
1441
1473
  // cor
1442
1474
  item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
1443
1475
  // tamanho
1444
- item_shipping_tier: getItemShippingTier2(),
1476
+ item_shipping_tier: "",
1445
1477
  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
1478
  item_category: (_t = getItemCategory3(item)) != null ? _t : null,
1447
1479
  item_category2: (_u = getItemCategory22(item)) != null ? _u : null,
@@ -1456,17 +1488,21 @@ var decoAdapter = {
1456
1488
  }
1457
1489
  return null;
1458
1490
  },
1459
- // brand: (context: DecoBrandContext) => {
1460
- // if (context?.brand) return context.brand
1461
- // if (context?.products) {
1462
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1463
- // }
1464
- // return null
1465
- // },
1491
+ brand: (context, config2) => {
1492
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1493
+ if (context == null ? void 0 : context.brand) return context.brand;
1494
+ if (context == null ? void 0 : context.products) {
1495
+ return normalizeBrand2(context.products.map((p) => {
1496
+ var _a;
1497
+ return (_a = p == null ? void 0 : p.brand) == null ? void 0 : _a.name;
1498
+ }));
1499
+ }
1500
+ return null;
1501
+ },
1466
1502
  line_items: (context) => {
1467
1503
  if (context == null ? void 0 : context.line_items) return context.line_items;
1468
1504
  if (context == null ? void 0 : context.products) {
1469
- return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
1505
+ return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id)).join();
1470
1506
  }
1471
1507
  return null;
1472
1508
  },
@@ -1504,197 +1540,103 @@ var decoAdapter = {
1504
1540
  }
1505
1541
  };
1506
1542
 
1507
- // src/params/adapters/orderForm/utils.ts
1543
+ // src/params/adapters/reserva/utils.ts
1508
1544
  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();
1545
+ var _a, _b, _c;
1546
+ const categories = (_b = (_a = item == null ? void 0 : item.similarItems) == null ? void 0 : _a[0]) == null ? void 0 : _b.categories;
1547
+ if (!(categories == null ? void 0 : categories.length)) return "Cole\xE7\xE3o";
1548
+ const match = (_c = categories.join(" ").match(/outlet|bazar|sale/i)) == null ? void 0 : _c[0].toLowerCase();
1514
1549
  return match != null ? match : "Cole\xE7\xE3o";
1515
1550
  };
1516
1551
  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 : "";
1552
+ var _a, _b, _c, _d;
1553
+ const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
1554
+ const categories = (_c = (_b = (_a = item == null ? void 0 : item.similarItems) == null ? void 0 : _a[0]) == null ? void 0 : _b.categories) != null ? _c : [];
1555
+ const validHierarchy = categories.filter((c) => c && !AVOID_CATEGORIES.test(c));
1556
+ const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1522
1557
  return capitalize(deepest);
1523
1558
  };
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
1559
 
1529
- // src/params/adapters/orderForm/index.ts
1530
- var orderFormAdapter = {
1531
- ...metaAdapters,
1560
+ // src/params/adapters/reserva/index.ts
1561
+ var reservaAdapter = {
1562
+ ...metaAdapter,
1563
+ // global adapters
1532
1564
  items: (context) => {
1533
1565
  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;
1566
+ if (context == null ? void 0 : context.products) {
1567
+ return context.products.map((item) => {
1568
+ 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;
1569
+ const COLOR_REGEX = /^[^_]+_/;
1570
+ const listPrice = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].listPrice;
1571
+ const refIdValue = (_e = (_d = (_c = item.additionalProperty) == null ? void 0 : _c.find((i) => i.name === "RefId")) == null ? void 0 : _d.value) == null ? void 0 : _e.replace(/_\d+$/, "");
1537
1572
  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,
1573
+ quantity: 1,
1574
+ index: (_f = item == null ? void 0 : item.index) != null ? _f : 0,
1575
+ item_brand: (_i = (_h = (_g = item.brand) == null ? void 0 : _g.name) == null ? void 0 : _h.toLowerCase()) != null ? _i : null,
1576
+ item_name: (_j = item.name) != null ? _j : null,
1577
+ price: (_l = (_k = item.offers) == null ? void 0 : _k.lowPrice) != null ? _l : null,
1578
+ discount: Math.round((Number(listPrice) - Number((_m = item == null ? void 0 : item.offers) == null ? void 0 : _m.lowPrice)) * 100) / 100,
1579
+ item_variant: ((_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[0]) == null ? void 0 : _o.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
1580
+ // cor
1581
+ item_variant2: (_q = (_p = item == null ? void 0 : item.name) == null ? void 0 : _p.split(" - ")[1]) != null ? _q : null,
1582
+ // tamanho
1546
1583
  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
1584
+ item_ref: refIdValue != null ? refIdValue : null,
1585
+ item_category: (_r = getItemCategory5(item)) != null ? _r : null,
1586
+ item_category2: (_s = getItemCategory23(item)) != null ? _s : null,
1587
+ item_id: (_t = item == null ? void 0 : item.id) != null ? _t : null,
1588
+ item_sku: (_u = item == null ? void 0 : item.sku) != null ? _u : null,
1589
+ item_url: (_w = (_v = item == null ? void 0 : item.seo) == null ? void 0 : _v.canonical) != null ? _w : null,
1590
+ image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
1591
+ seller_id: (_D = (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) == null ? void 0 : _C.identifier) != null ? _D : null,
1592
+ item_list_name: (_E = item == null ? void 0 : item.item_list_name) != null ? _E : null
1556
1593
  };
1557
1594
  });
1558
1595
  }
1559
1596
  return null;
1560
1597
  },
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
- // },
1598
+ brand: (context, config2) => {
1599
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1600
+ if (context == null ? void 0 : context.brand) return context.brand;
1601
+ if (context == null ? void 0 : context.products) {
1602
+ return normalizeBrand2(context.products.map((p) => {
1603
+ var _a;
1604
+ return (_a = p == null ? void 0 : p.brand) == null ? void 0 : _a.name;
1605
+ }));
1606
+ }
1607
+ return null;
1608
+ },
1568
1609
  line_items: (context) => {
1569
- var _a;
1570
1610
  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));
1611
+ if (context == null ? void 0 : context.products) {
1612
+ return context.products.map((item) => item == null ? void 0 : item.id).filter((id) => Boolean(id)).join();
1613
+ }
1614
+ return null;
1573
1615
  },
1574
1616
  value: (context) => {
1575
- var _a;
1576
1617
  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;
1618
+ if (context == null ? void 0 : context.products) {
1619
+ return context.products.map((item) => {
1620
+ var _a;
1621
+ return (_a = item.offers) == null ? void 0 : _a.lowPrice;
1622
+ }).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1623
+ }
1624
+ return null;
1695
1625
  },
1696
- seller_cod_name: (context) => {
1697
- return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1626
+ available_grid: (context) => {
1627
+ if (context == null ? void 0 : context.available_grid) return context.available_grid;
1628
+ if (context == null ? void 0 : context.products) {
1629
+ const sizes = context.products.filter((product) => {
1630
+ var _a, _b;
1631
+ return (_b = (_a = product.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b.some((o) => o.availability === "https://schema.org/InStock");
1632
+ }).map((product) => {
1633
+ var _a;
1634
+ return (_a = product.name) == null ? void 0 : _a.split(" - ")[1];
1635
+ }).filter((name) => Boolean(name));
1636
+ const result = sortSizes(sizes).join(",").trim();
1637
+ return result || null;
1638
+ }
1639
+ return null;
1698
1640
  }
1699
1641
  };
1700
1642
 
@@ -1769,11 +1711,12 @@ var HeadlessPdpZone = {
1769
1711
  line_items: (context) => {
1770
1712
  if (context == null ? void 0 : context.line_items) return context.line_items;
1771
1713
  if (context == null ? void 0 : context.products) {
1772
- return context.products.map((item) => item.productId).filter((id) => Boolean(id));
1714
+ return context.products.map((item) => item.productId).filter((id) => Boolean(id)).join();
1773
1715
  }
1774
1716
  return null;
1775
1717
  },
1776
- brand: (context) => {
1718
+ brand: (context, config2) => {
1719
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1777
1720
  if (context == null ? void 0 : context.brand) return context.brand;
1778
1721
  if (context == null ? void 0 : context.products) {
1779
1722
  return context.products.map((p) => p.brand).join().trim();
@@ -1827,11 +1770,12 @@ var HeadlessPdcZone = {
1827
1770
  line_items: (context) => {
1828
1771
  if (context == null ? void 0 : context.line_items) return context.line_items;
1829
1772
  if (context == null ? void 0 : context.products) {
1830
- return context.products.map((item) => item.id).filter((id) => Boolean(id));
1773
+ return context.products.map((item) => item.id).filter((id) => Boolean(id)).join();
1831
1774
  }
1832
1775
  return null;
1833
1776
  },
1834
- brand: (context) => {
1777
+ brand: (context, config2) => {
1778
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1835
1779
  if (context == null ? void 0 : context.brand) return context.brand;
1836
1780
  if (context == null ? void 0 : context.products) {
1837
1781
  return context.products.map((p) => p.brand.name).join().trim();
@@ -1842,16 +1786,14 @@ var HeadlessPdcZone = {
1842
1786
 
1843
1787
  // src/params/adapters/headless/index.ts
1844
1788
  var headlessAdapter = {
1845
- ...metaAdapters,
1789
+ ...metaAdapter,
1846
1790
  // global adapters
1847
- ...orderFormAdapter,
1848
- // orderForm adapters, confirmar se no storefront tem evento que usa essses params
1849
- brand: (context) => {
1791
+ brand: (context, config2) => {
1850
1792
  if (context.zone === "PDP") {
1851
- return HeadlessPdpZone.brand(context);
1793
+ return HeadlessPdpZone.brand(context, config2);
1852
1794
  }
1853
1795
  if (context.zone === "PDC") {
1854
- return HeadlessPdcZone.brand(context);
1796
+ return HeadlessPdcZone.brand(context, config2);
1855
1797
  }
1856
1798
  return null;
1857
1799
  },
@@ -1912,7 +1854,7 @@ var getDeliveryTime = (sla) => {
1912
1854
 
1913
1855
  // src/params/adapters/pickup/index.ts
1914
1856
  var pickupAdapter = {
1915
- ...metaAdapters,
1857
+ ...metaAdapter,
1916
1858
  flag_pickup: (context) => {
1917
1859
  var _a;
1918
1860
  return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
@@ -1920,10 +1862,10 @@ var pickupAdapter = {
1920
1862
  shippings: (context) => {
1921
1863
  if (context.shippings) {
1922
1864
  return context.shippings.map((s) => {
1923
- var _a, _b;
1865
+ var _a;
1924
1866
  return {
1925
1867
  line_items: (_a = s.line_items) != null ? _a : "",
1926
- shipping: (_b = s.price) != null ? _b : 0,
1868
+ shipping: s.price / 100,
1927
1869
  shipping_tier: getShippingTier(s),
1928
1870
  delivery_time: getDeliveryTime(s)
1929
1871
  };
@@ -1931,20 +1873,245 @@ var pickupAdapter = {
1931
1873
  }
1932
1874
  return null;
1933
1875
  },
1876
+ brand: (context, config2) => {
1877
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1878
+ if (context == null ? void 0 : context.brand) return context.brand;
1879
+ return null;
1880
+ },
1881
+ zipcode: (context) => {
1882
+ var _a;
1883
+ return (_a = context.meta.zipcode) != null ? _a : null;
1884
+ }
1885
+ };
1886
+
1887
+ // src/params/adapters/orderForm/utils.ts
1888
+ var getOrderFormItems = (orderForm) => {
1889
+ const idSelected = orderForm == null ? void 0 : orderForm.selected;
1890
+ const isMultipleRemove = orderForm == null ? void 0 : orderForm.multipleRemove;
1891
+ return idSelected ? orderForm.items.filter((item) => item.id === idSelected).map((i) => {
1892
+ if (isMultipleRemove) return i;
1893
+ return { ...i, quantity: 1 };
1894
+ }) : orderForm.items;
1895
+ };
1896
+ var getItemCategory7 = (item) => {
1897
+ var _a;
1898
+ const categories = item == null ? void 0 : item.productCategories;
1899
+ if (!categories) return "Cole\xE7\xE3o";
1900
+ const text = Object.values(categories).join(" ");
1901
+ const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1902
+ return match != null ? match : "Cole\xE7\xE3o";
1903
+ };
1904
+ var getItemCategory25 = (item) => {
1905
+ var _a, _b;
1906
+ const AVOID_CATEGORIES = /outlet|bazar|sale/i;
1907
+ const categories = Object.values((_a = item == null ? void 0 : item.productCategories) != null ? _a : {});
1908
+ const validHierarchy = categories.map((c) => c.trim()).filter((c) => c && !AVOID_CATEGORIES.test(c));
1909
+ const deepest = (_b = validHierarchy[validHierarchy.length - 1]) != null ? _b : "";
1910
+ return capitalize(deepest);
1911
+ };
1912
+ function getItemShippingTier2(orderForm, item) {
1913
+ var _a, _b, _c, _d;
1914
+ const info = (_b = (_a = orderForm == null ? void 0 : orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) == null ? void 0 : _b.find(
1915
+ (li) => li.itemId === item.id
1916
+ );
1917
+ const selectedSla = (_c = info == null ? void 0 : info.slas) == null ? void 0 : _c.find((sla) => sla.id === info.selectedSla);
1918
+ 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;
1919
+ }
1920
+ var getPaymentType2 = (context) => {
1921
+ var _a, _b, _c, _d;
1922
+ if (context.payment_type) return context.payment_type;
1923
+ if (!context.orderForm) return null;
1924
+ const giftCards = ((_a = context.orderForm.paymentData) == null ? void 0 : _a.giftCards) || [];
1925
+ if (giftCards.some((g) => g == null ? void 0 : g.inUse)) return "vale";
1926
+ const payments = ((_b = context.orderForm.paymentData) == null ? void 0 : _b.payments) || [];
1927
+ const systems = ((_c = context.orderForm.paymentData) == null ? void 0 : _c.paymentSystems) || [];
1928
+ if (!payments.length || !systems.length) return null;
1929
+ const selectedPayment = payments.find((p) => p == null ? void 0 : p.paymentSystem) || payments[0];
1930
+ const id = String((selectedPayment == null ? void 0 : selectedPayment.paymentSystem) || "").trim();
1931
+ if (!id) return null;
1932
+ const system = systems.find((s) => String(s.id) === id);
1933
+ const name = ((_d = system == null ? void 0 : system.name) == null ? void 0 : _d.toLowerCase()) || "";
1934
+ const match = paymentTypeMap.find(([key]) => name.includes(key));
1935
+ return match ? match[1] : null;
1936
+ };
1937
+
1938
+ // src/params/adapters/orderForm/index.ts
1939
+ var orderFormAdapter = {
1940
+ ...metaAdapter,
1941
+ items: (context) => {
1942
+ if (context == null ? void 0 : context.items) return context.items;
1943
+ if ((context == null ? void 0 : context.orderForm) && (context == null ? void 0 : context.orderForm.items)) {
1944
+ return getOrderFormItems(context.orderForm).map((item, index) => {
1945
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
1946
+ return {
1947
+ quantity: (_a = item == null ? void 0 : item.quantity) != null ? _a : 1,
1948
+ index: (_c = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.index) != null ? _c : index + 1,
1949
+ item_brand: (_e = (_d = item.additionalInfo) == null ? void 0 : _d.brandName) != null ? _e : null,
1950
+ item_name: (_f = item == null ? void 0 : item.name.replace(item == null ? void 0 : item.skuName, "").trim()) != null ? _f : null,
1951
+ price: (item == null ? void 0 : item.sellingPrice) / 100,
1952
+ discount: ((item == null ? void 0 : item.listPrice) - (item == null ? void 0 : item.sellingPrice)) / 100,
1953
+ item_variant: (_j = (_i = (_h = (_g = item == null ? void 0 : item.skuName) == null ? void 0 : _g.split(" - ")[0]) == null ? void 0 : _h.split("_").pop()) == null ? void 0 : _i.trim()) != null ? _j : null,
1954
+ item_variant2: (_m = (_l = (_k = item == null ? void 0 : item.skuName) == null ? void 0 : _k.split(" - ")[1]) == null ? void 0 : _l.trim()) != null ? _m : null,
1955
+ item_shipping_tier: getItemShippingTier2(context.orderForm, item),
1956
+ item_ref: (item == null ? void 0 : item.productRefId) || (item == null ? void 0 : item.refId.replace(/_\d+$/, "")) || null,
1957
+ item_category: (_n = getItemCategory7(item)) != null ? _n : null,
1958
+ item_category2: (_o = getItemCategory25(item)) != null ? _o : null,
1959
+ item_id: (_p = item == null ? void 0 : item.productId) != null ? _p : null,
1960
+ item_sku: (_q = item == null ? void 0 : item.id) != null ? _q : null,
1961
+ item_url: (_r = item.detailUrl) != null ? _r : null,
1962
+ image_url: (_s = resizeVtexImage2(item.imageUrl)) != null ? _s : null,
1963
+ seller_id: (_t = item == null ? void 0 : item.seller) != null ? _t : null,
1964
+ item_list_name: (_v = (_u = context == null ? void 0 : context.orderForm) == null ? void 0 : _u.item_list_name) != null ? _v : null
1965
+ };
1966
+ });
1967
+ }
1968
+ return null;
1969
+ },
1970
+ brand: (context, config2) => {
1971
+ var _a;
1972
+ if (config2 == null ? void 0 : config2.brand) return config2.brand;
1973
+ if (context == null ? void 0 : context.brand) return context.brand;
1974
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1975
+ const brands = getOrderFormItems(context.orderForm).map((item) => item.additionalInfo.brandName);
1976
+ return normalizeBrand2(brands);
1977
+ },
1978
+ line_items: (context) => {
1979
+ var _a;
1980
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1981
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1982
+ return getOrderFormItems(context.orderForm).map((item) => item == null ? void 0 : item.productId).filter((id) => Boolean(id)).join();
1983
+ },
1984
+ value: (context) => {
1985
+ var _a;
1986
+ if (context == null ? void 0 : context.value) return context.value;
1987
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1988
+ return getOrderFormItems(context.orderForm).map((item) => (item == null ? void 0 : item.sellingPrice) / 100 * item.quantity).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1989
+ },
1990
+ payment_type: getPaymentType2,
1991
+ total_discount: (context) => {
1992
+ var _a, _b, _c;
1993
+ if (context == null ? void 0 : context.total_discount) return context.total_discount;
1994
+ if (!((_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.items)) return null;
1995
+ const totalizers = (_b = context == null ? void 0 : context.orderForm) == null ? void 0 : _b.totalizers;
1996
+ const productDiscount = ((_c = totalizers.find((t) => t.id === "Discounts")) == null ? void 0 : _c.value) || 0;
1997
+ return Math.abs(productDiscount) / 100 || null;
1998
+ },
1999
+ subtotal: (context) => {
2000
+ var _a, _b;
2001
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
2002
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
2003
+ return subtotal;
2004
+ },
1934
2005
  zipcode: (context) => {
1935
2006
  var _a;
1936
- return (_a = context.zipcode) != null ? _a : null;
2007
+ return (_a = context.meta.zipcode) != null ? _a : null;
2008
+ },
2009
+ flag_pickup: (context) => {
2010
+ var _a;
2011
+ const orderForm = context.orderForm;
2012
+ if (!orderForm) return null;
2013
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
2014
+ const hasPickup = logisticsInfo.some(
2015
+ (info) => {
2016
+ var _a2;
2017
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
2018
+ }
2019
+ );
2020
+ return hasPickup;
2021
+ },
2022
+ shippings: (context) => {
2023
+ if (!context.orderForm) return null;
2024
+ const { items, shippingData } = context.orderForm;
2025
+ const acc = {};
2026
+ shippingData.logisticsInfo.forEach(({ itemIndex, slas }) => {
2027
+ const item = items[itemIndex];
2028
+ if (!item) return;
2029
+ slas.forEach((sla) => {
2030
+ if (!acc[sla.name]) acc[sla.name] = {
2031
+ shipping_tier: sla.name,
2032
+ delivery_time: parseInt(sla.shippingEstimate),
2033
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
2034
+ line_items: []
2035
+ };
2036
+ acc[sla.name].line_items.push(item.id);
2037
+ });
2038
+ });
2039
+ return Object.values(acc).map((s) => ({ ...s, line_items: s.line_items.join(",") }));
2040
+ },
2041
+ shipping: (context) => {
2042
+ var _a, _b, _c;
2043
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
2044
+ return logistics.reduce((total, item) => {
2045
+ var _a2, _b2;
2046
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
2047
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
2048
+ }, 0);
2049
+ },
2050
+ shipping_tier: (context) => {
2051
+ var _a, _b, _c;
2052
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
2053
+ const selectedSlas = logistics.map((item) => {
2054
+ var _a2;
2055
+ if (!item.selectedSla) return null;
2056
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
2057
+ }).filter(Boolean);
2058
+ if (selectedSlas.length === 0) return null;
2059
+ const uniqueTiers = Array.from(
2060
+ new Map(
2061
+ selectedSlas.map((sla) => {
2062
+ var _a2;
2063
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
2064
+ return [key, sla];
2065
+ })
2066
+ ).values()
2067
+ );
2068
+ const sortedTiers = uniqueTiers.sort((a, b) => {
2069
+ var _a2, _b2;
2070
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
2071
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
2072
+ if (aOrder !== bOrder) return aOrder - bOrder;
2073
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
2074
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
2075
+ return aLabel.localeCompare(bLabel, "pt-BR");
2076
+ });
2077
+ const shippingTier = sortedTiers.map((sla) => {
2078
+ var _a2;
2079
+ 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;
2080
+ }).filter(Boolean).join(", ");
2081
+ return shippingTier || null;
2082
+ },
2083
+ transaction_id: (context) => {
2084
+ var _a, _b;
2085
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
2086
+ },
2087
+ coupon_message: (context) => {
2088
+ var _a;
2089
+ if (context.couponMessage) return context.couponMessage;
2090
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
2091
+ if (messages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
2092
+ const couponMessages = messages.filter((msg) => msg.text.toLowerCase().includes("cupom"));
2093
+ if (couponMessages.length === 0) return "C\xF3digo de desconto aplicado com sucesso";
2094
+ return couponMessages.map((msg) => msg.text).join(" | ");
2095
+ },
2096
+ coupon: (context) => {
2097
+ var _a, _b;
2098
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
2099
+ },
2100
+ seller_cod_name: (context) => {
2101
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1937
2102
  }
1938
2103
  };
1939
2104
 
1940
2105
  // src/formatter.ts
1941
2106
  var adapters = {
1942
2107
  DECO: decoAdapter,
2108
+ RESERVA: reservaAdapter,
1943
2109
  HEADLESS: headlessAdapter,
1944
2110
  PICKUP: pickupAdapter,
1945
- ORDERFORM: orderFormAdapter
2111
+ ORDERFORM: orderFormAdapter,
2112
+ META: metaAdapter
1946
2113
  };
1947
- async function getParameters(context, eventName) {
2114
+ async function getParameters(context, eventName, config2) {
1948
2115
  var _a;
1949
2116
  const eventConfig = EVENTS[eventName];
1950
2117
  if (!eventConfig) return;
@@ -1957,16 +2124,20 @@ async function getParameters(context, eventName) {
1957
2124
  console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
1958
2125
  return [param, null];
1959
2126
  }
1960
- return [param, await getter(context, eventName)];
2127
+ return [param, await getter(context, config2)];
1961
2128
  })
1962
2129
  );
1963
2130
  return Object.fromEntries(entries);
1964
2131
  }
1965
2132
 
1966
2133
  // src/index.ts
2134
+ var config = { brand: "", currency: "BRL" };
2135
+ function initTracker(c) {
2136
+ config = c;
2137
+ }
1967
2138
  async function trackWebEvent(event, context) {
1968
2139
  try {
1969
- const parameters = await getParameters(context, event);
2140
+ const parameters = await getParameters(context, event, config);
1970
2141
  if (isDebugMode()) {
1971
2142
  console.log(`[DT v2] ${event}, context e parameters: `, {
1972
2143
  context,
@@ -1988,6 +2159,7 @@ var src_default = {
1988
2159
  export {
1989
2160
  EVENTS,
1990
2161
  src_default as default,
2162
+ initTracker,
1991
2163
  trackWebEvent
1992
2164
  };
1993
2165
  //# sourceMappingURL=mod.js.map