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

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.
@@ -242,7 +242,7 @@ function _ts_generator(thisArg, body) {
242
242
  }
243
243
  }
244
244
  var AzzasTracker = function() {
245
- var pushToDataLayer = // src/adapters/datalayer.ts
245
+ var pushToDataLayer = // src/pushToDatalayer.ts
246
246
  function pushToDataLayer(event, context) {
247
247
  var targetWindow = context.window || (typeof window !== "undefined" ? window : null);
248
248
  if (!targetWindow) return;
@@ -256,86 +256,16 @@ var AzzasTracker = function() {
256
256
  ecommerce: null
257
257
  });
258
258
  targetWindow.dataLayer.push({
259
- event: event,
259
+ event: event.toLowerCase(),
260
260
  ecommerce: payload
261
261
  });
262
262
  } else {
263
263
  targetWindow.dataLayer.push(Object.assign({
264
- event: event
264
+ event: event.toLowerCase()
265
265
  }, payload));
266
266
  }
267
267
  };
268
- var dataTrackingLog = // src/core/utils.ts
269
- function dataTrackingLog(data, color) {
270
- console.log("%c[DT] EVENTO DISPARADO:%c ", "background: ".concat(color, "; color: white; font-weight: bold; padding: 2px 4px; border-radius: 3px;"), "color: #fff;", data || "");
271
- };
272
- var pushToDito = // src/adapters/dito.ts
273
- function pushToDito(event, ecomm) {
274
- dataTrackingLog({
275
- id: event,
276
- custom_data: ecomm
277
- }, "#00c851");
278
- };
279
- var dispatchTrackEvent = function dispatchTrackEvent(eventName, data) {
280
- return _async_to_generator(function() {
281
- var eventConfig;
282
- return _ts_generator(this, function(_state) {
283
- switch(_state.label){
284
- case 0:
285
- eventConfig = EVENTS[eventName];
286
- if (!eventConfig) return [
287
- 2
288
- ];
289
- return [
290
- 4,
291
- Promise.allSettled(eventConfig.destinations.map(function(dest) {
292
- return _async_to_generator(function() {
293
- var err;
294
- return _ts_generator(this, function(_state) {
295
- switch(_state.label){
296
- case 0:
297
- _state.trys.push([
298
- 0,
299
- 2,
300
- ,
301
- 3
302
- ]);
303
- return [
304
- 4,
305
- adapters[dest](eventName.toLowerCase(), data)
306
- ];
307
- case 1:
308
- _state.sent();
309
- return [
310
- 3,
311
- 3
312
- ];
313
- case 2:
314
- err = _state.sent();
315
- console.error("[DT] Failed to send ".concat(eventName, " to ").concat(dest, ":"), err);
316
- return [
317
- 3,
318
- 3
319
- ];
320
- case 3:
321
- return [
322
- 2
323
- ];
324
- }
325
- });
326
- })();
327
- }))
328
- ];
329
- case 1:
330
- _state.sent();
331
- return [
332
- 2
333
- ];
334
- }
335
- });
336
- })();
337
- };
338
- var getProductDataById = // src/params/utils/index.ts
268
+ var getProductDataById = // src/params/legacy/utils/index.ts
339
269
  function getProductDataById(id) {
340
270
  return _async_to_generator(function() {
341
271
  var response, e;
@@ -705,20 +635,20 @@ var AzzasTracker = function() {
705
635
  var uniqueSortedCodes = _to_consumable_array(new Set(brandCodes)).sort();
706
636
  return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
707
637
  };
708
- var brandFromOrderForm = // src/params/resolvers/brand/fromOrderForm.ts
638
+ var brandFromOrderForm = // src/params/legacy/resolvers/brand/fromOrderForm.ts
709
639
  function brandFromOrderForm(context) {
710
640
  var _context_orderForm_items;
711
641
  if (!context.orderForm && !((_context_orderForm_items = context.orderForm.items) === null || _context_orderForm_items === void 0 ? void 0 : _context_orderForm_items.length)) return null;
712
642
  var items = context.orderForm.items;
713
643
  return normalizeBrand(items);
714
644
  };
715
- var brandFromItem = // src/params/resolvers/brand/fromItem.ts
645
+ var brandFromItem = // src/params/legacy/resolvers/brand/fromItem.ts
716
646
  function brandFromItem(context) {
717
647
  var _item_additionalInfo;
718
648
  var item = context.item;
719
649
  return normalizeBrand((item === null || item === void 0 ? void 0 : (_item_additionalInfo = item.additionalInfo) === null || _item_additionalInfo === void 0 ? void 0 : _item_additionalInfo.brandName) || item.brand || item.item_brand);
720
650
  };
721
- var getBrand = // src/params/brand.ts
651
+ var getBrand = // src/params/legacy/brand.ts
722
652
  function getBrand(context, eventName) {
723
653
  if (context === null || context === void 0 ? void 0 : context.brand) return normalizeBrand(context.brand) || context.brand || null;
724
654
  switch(eventName){
@@ -919,7 +849,7 @@ var AzzasTracker = function() {
919
849
  var listName = (_ref = (_ref1 = (_ref2 = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.item_list_name) !== null && _ref2 !== void 0 ? _ref2 : source === null || source === void 0 ? void 0 : source.itemListName) !== null && _ref1 !== void 0 ? _ref1 : source === null || source === void 0 ? void 0 : source.item_list_name) !== null && _ref !== void 0 ? _ref : null;
920
850
  saveSelectedItem(productId, listName);
921
851
  };
922
- var itemsFromOrderForm = // src/params/resolvers/items/fromOrderForm.ts
852
+ var itemsFromOrderForm = // src/params/legacy/resolvers/items/fromOrderForm.ts
923
853
  function itemsFromOrderForm(context) {
924
854
  return _async_to_generator(function() {
925
855
  var _context_orderForm, items, cartHistoryMap;
@@ -973,7 +903,7 @@ var AzzasTracker = function() {
973
903
  });
974
904
  })();
975
905
  };
976
- var itemsFromItem = // src/params/resolvers/items/fromItem.ts
906
+ var itemsFromItem = // src/params/legacy/resolvers/items/fromItem.ts
977
907
  function itemsFromItem(context, event) {
978
908
  return _async_to_generator(function() {
979
909
  var _item_additionalProperty, _item_itemOffered, _item_itemOffered1, _item_additionalInfo, _item_brand, _item_itemOffered_brand, _item_itemOffered2, _item_itemOffered3, _item_name, _item_name1, _item_item_name, _item_itemOffered_isVariantOf_name, _item_itemOffered_isVariantOf, _item_itemOffered4, _split_, _item_itemAttributes, _split_1, _this, item, orderForm, itemListName, resolvedListName, resolvedItemId, _tmp, _tmp1;
@@ -1029,7 +959,7 @@ var AzzasTracker = function() {
1029
959
  });
1030
960
  })();
1031
961
  };
1032
- var itemsFromList = // src/params/resolvers/items/fromList.ts
962
+ var itemsFromList = // src/params/legacy/resolvers/items/fromList.ts
1033
963
  function itemsFromList(context) {
1034
964
  return _async_to_generator(function() {
1035
965
  return _ts_generator(this, function(_state) {
@@ -1058,7 +988,7 @@ var AzzasTracker = function() {
1058
988
  });
1059
989
  })();
1060
990
  };
1061
- var itemsFromPDP = // src/params/resolvers/items/fromPdp.ts
991
+ var itemsFromPDP = // src/params/legacy/resolvers/items/fromPdp.ts
1062
992
  function itemsFromPDP(context, event) {
1063
993
  return _async_to_generator(function() {
1064
994
  var _item_additionalProperty, _item_name, _item_category_split_, _item_category, item, value, brand, resolvedListName, resolvedItemId;
@@ -1101,7 +1031,7 @@ var AzzasTracker = function() {
1101
1031
  });
1102
1032
  })();
1103
1033
  };
1104
- var itemsFromBanner = // src/params/resolvers/items/fromBanner.ts
1034
+ var itemsFromBanner = // src/params/legacy/resolvers/items/fromBanner.ts
1105
1035
  function itemsFromBanner(context) {
1106
1036
  return _async_to_generator(function() {
1107
1037
  var _item_name, isUrlFromPDP, product, item;
@@ -1139,7 +1069,7 @@ var AzzasTracker = function() {
1139
1069
  });
1140
1070
  })();
1141
1071
  };
1142
- var getItems = // src/params/items.ts
1072
+ var getItems = // src/params/legacy/items.ts
1143
1073
  function getItems(context, eventName) {
1144
1074
  if (context === null || context === void 0 ? void 0 : context.items) return context.items;
1145
1075
  switch(eventName){
@@ -1172,7 +1102,7 @@ var AzzasTracker = function() {
1172
1102
  return null;
1173
1103
  }
1174
1104
  };
1175
- var paymentTypeFromOrderForm = // src/params/resolvers/paymentType/fromOrderForm.ts
1105
+ var paymentTypeFromOrderForm = // src/params/legacy/resolvers/paymentType/fromOrderForm.ts
1176
1106
  function paymentTypeFromOrderForm(context) {
1177
1107
  var _context_orderForm_paymentData, _context_orderForm_paymentData1, _system_name;
1178
1108
  if (context.payment_type) return context.payment_type;
@@ -1195,7 +1125,7 @@ var AzzasTracker = function() {
1195
1125
  });
1196
1126
  return match ? match[1] : null;
1197
1127
  };
1198
- var paymentTypeFromOrderGroup = // src/params/resolvers/paymentType/fromOrderGroup.ts
1128
+ var paymentTypeFromOrderGroup = // src/params/legacy/resolvers/paymentType/fromOrderGroup.ts
1199
1129
  function paymentTypeFromOrderGroup(context) {
1200
1130
  var _context_orderForm_paymentData, _transactions_, _payments__paymentSystemName, _payments_;
1201
1131
  if (!context.orderForm) return null;
@@ -1210,7 +1140,7 @@ var AzzasTracker = function() {
1210
1140
  });
1211
1141
  return match ? match[1] : null;
1212
1142
  };
1213
- var getPaymentType = // src/params/paymentType.ts
1143
+ var getPaymentType = // src/params/legacy/paymentType.ts
1214
1144
  function getPaymentType(context, eventName) {
1215
1145
  if (context === null || context === void 0 ? void 0 : context.paymentType) return context.paymentType;
1216
1146
  switch(eventName){
@@ -1224,41 +1154,13 @@ var AzzasTracker = function() {
1224
1154
  return null;
1225
1155
  }
1226
1156
  };
1227
- var getUserInfo = // src/params/userInfo.ts
1228
- function getUserInfo(context, eventName) {
1157
+ var getUserInfo = function getUserInfo(context) {
1229
1158
  return _async_to_generator(function() {
1230
- var _PROD_DOMAINS_, PROD_DOMAINS, domain, _res_customer_document, _res_customer, api, response, _context_manuallyInfo, _context_manuallyInfo1, cpf, birthDate, phone, firstName, lastName, email, email_optin, document3, hashedDocument2, res, document2, hashedDocument, _, _context_manuallyInfo2, _context_manuallyInfo3, cpf1, birthDate1, phone1, firstName1, lastName1, email1, email_optin1, document21, hashedDocument1;
1159
+ var _PROD_DOMAINS_, domain, _res_customer_document, _res_customer, api, response, _context_manuallyInfo, _context_manuallyInfo1, cpf, birthDate, phone, firstName, lastName, email, email_optin, document3, hashedDocument2, res, document2, hashedDocument, _, _context_manuallyInfo2, _context_manuallyInfo3, cpf1, birthDate1, phone1, firstName1, lastName1, email1, email_optin1, document21, hashedDocument1;
1231
1160
  return _ts_generator(this, function(_state) {
1232
1161
  switch(_state.label){
1233
1162
  case 0:
1234
- PROD_DOMAINS = {
1235
- "animale": {
1236
- "store": "https://www.animale.com.br",
1237
- "checkout": "https://secure.animale.com.br"
1238
- },
1239
- "farm": {
1240
- "store": "https://lojafarm.myvtex.com"
1241
- },
1242
- "mariafilo": {
1243
- "store": "https://mariafilo.myvtex.com",
1244
- "checkout": "https://secure.mariafilo.com.br"
1245
- },
1246
- "lojacrisbarros": {
1247
- "store": "https://lojacrisbarros.myvtex.com",
1248
- "checkout": "https://secure.crisbarros.com.br"
1249
- },
1250
- "lojaoffpremium": {
1251
- "store": "https://lojaoffpremium.myvtex.com",
1252
- "checkout": "https://secure.offpremium.com.br"
1253
- },
1254
- "bynv": {
1255
- "store": "https://bynv.myvtex.com"
1256
- },
1257
- "fabula": {
1258
- "store": "https://lojafabula.myvtex.com"
1259
- }
1260
- };
1261
- domain = (_PROD_DOMAINS_ = PROD_DOMAINS[context.account || "https://www.animale.com.br"]) === null || _PROD_DOMAINS_ === void 0 ? void 0 : _PROD_DOMAINS_[context.platform || "store"];
1163
+ domain = (_PROD_DOMAINS_ = PROD_DOMAINS[context.account || "animale"]) === null || _PROD_DOMAINS_ === void 0 ? void 0 : _PROD_DOMAINS_[context.platform || "store"];
1262
1164
  if (!domain) return [
1263
1165
  2,
1264
1166
  {
@@ -1406,20 +1308,25 @@ var AzzasTracker = function() {
1406
1308
  });
1407
1309
  })();
1408
1310
  };
1409
- var getParameters = // src/formatter/index.ts
1410
- function getParameters(_0) {
1311
+ var getItemShippingTier2 = function getItemShippingTier2() {
1312
+ return null;
1313
+ };
1314
+ var resizeVtexImage3 = function resizeVtexImage3(url) {
1315
+ var width = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 500, height = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 500;
1316
+ return url === null || url === void 0 ? void 0 : url.replace(/(\/arquivos\/ids\/\d+)-\d+-\d+\//, "$1-".concat(width, "-").concat(height, "/"));
1317
+ };
1318
+ var getParameters = function getParameters(context, eventName) {
1411
1319
  return _async_to_generator(function() {
1412
- var context, eventName, eventConfig, params, _;
1413
- var _arguments = arguments;
1320
+ var _adapters_currentAdapter, eventConfig, currentAdapter, getters, entries;
1414
1321
  return _ts_generator(this, function(_state) {
1415
1322
  switch(_state.label){
1416
1323
  case 0:
1417
- context = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}, eventName = _arguments.length > 1 ? _arguments[1] : void 0;
1418
1324
  eventConfig = EVENTS[eventName];
1419
1325
  if (!eventConfig) return [
1420
1326
  2
1421
1327
  ];
1422
- _ = Object.fromEntries;
1328
+ currentAdapter = context.adapter;
1329
+ getters = (_adapters_currentAdapter = adapters[currentAdapter]) !== null && _adapters_currentAdapter !== void 0 ? _adapters_currentAdapter : paramGetters;
1423
1330
  return [
1424
1331
  4,
1425
1332
  Promise.all(eventConfig.requiredParams.map(function(param) {
@@ -1428,9 +1335,9 @@ var AzzasTracker = function() {
1428
1335
  return _ts_generator(this, function(_state) {
1429
1336
  switch(_state.label){
1430
1337
  case 0:
1431
- getter = paramGetters[param];
1338
+ getter = getters[param];
1432
1339
  if (typeof getter !== "function") {
1433
- console.error("[DT] Missing paramGetter for param: ".concat(param));
1340
+ console.error('[DT] Missing getter "'.concat(param, '" for adapter "').concat(currentAdapter, '"'));
1434
1341
  return [
1435
1342
  2,
1436
1343
  [
@@ -1459,64 +1366,64 @@ var AzzasTracker = function() {
1459
1366
  }))
1460
1367
  ];
1461
1368
  case 1:
1462
- params = _.apply(Object, [
1463
- _state.sent()
1464
- ]);
1369
+ entries = _state.sent();
1465
1370
  return [
1466
1371
  2,
1467
- params
1372
+ Object.fromEntries(entries)
1468
1373
  ];
1469
1374
  }
1470
1375
  });
1471
- }).apply(this, arguments);
1376
+ })();
1472
1377
  };
1473
1378
  var trackWebEvent = // src/index.ts
1474
- function trackWebEvent(_0) {
1475
- return _async_to_generator(function(event) {
1476
- var context, parameters, err;
1477
- var _arguments = arguments;
1379
+ function trackWebEvent(event, context) {
1380
+ return _async_to_generator(function() {
1381
+ var parameters, err;
1478
1382
  return _ts_generator(this, function(_state) {
1479
1383
  switch(_state.label){
1480
1384
  case 0:
1481
- context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
1482
- _state.label = 1;
1483
- case 1:
1484
1385
  _state.trys.push([
1485
- 1,
1486
- 4,
1386
+ 0,
1387
+ 3,
1487
1388
  ,
1488
- 5
1389
+ 4
1489
1390
  ]);
1490
1391
  return [
1491
1392
  4,
1492
1393
  getParameters(context, event)
1493
1394
  ];
1494
- case 2:
1395
+ case 1:
1495
1396
  parameters = _state.sent();
1397
+ if (isDebugMode()) {
1398
+ console.log("[DT v2] ".concat(event, ", context e parameters: "), {
1399
+ context: context,
1400
+ parameters: parameters
1401
+ });
1402
+ }
1496
1403
  return [
1497
1404
  4,
1498
- dispatchTrackEvent(event, Object.assign({}, parameters, {
1405
+ pushToDataLayer(event, Object.assign({}, parameters, {
1499
1406
  window: context.window
1500
1407
  }))
1501
1408
  ];
1502
- case 3:
1409
+ case 2:
1503
1410
  return [
1504
1411
  2,
1505
1412
  _state.sent()
1506
1413
  ];
1507
- case 4:
1414
+ case 3:
1508
1415
  err = _state.sent();
1509
1416
  return [
1510
1417
  2,
1511
1418
  console.error("[DT] Error tracking event ".concat(event, ":"), err)
1512
1419
  ];
1513
- case 5:
1420
+ case 4:
1514
1421
  return [
1515
1422
  2
1516
1423
  ];
1517
1424
  }
1518
1425
  });
1519
- }).apply(this, arguments);
1426
+ })();
1520
1427
  };
1521
1428
  var __defProp = Object.defineProperty;
1522
1429
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1724,8 +1631,7 @@ var AzzasTracker = function() {
1724
1631
  "currency",
1725
1632
  "promotion_name",
1726
1633
  "creative_slot",
1727
- "creative_name",
1728
- "items"
1634
+ "creative_name"
1729
1635
  ]
1730
1636
  },
1731
1637
  SELECT_PROMOTION: {
@@ -1740,8 +1646,7 @@ var AzzasTracker = function() {
1740
1646
  "currency",
1741
1647
  "promotion_name",
1742
1648
  "creative_slot",
1743
- "creative_name",
1744
- "items"
1649
+ "creative_name"
1745
1650
  ]
1746
1651
  },
1747
1652
  SELECT_CONTENT: {
@@ -1994,6 +1899,26 @@ var AzzasTracker = function() {
1994
1899
  ]
1995
1900
  }
1996
1901
  };
1902
+ var BRAND_CODES = {
1903
+ farm: "farmrio",
1904
+ "farm etc": "farmetc",
1905
+ "farm rio": "farmrio"
1906
+ };
1907
+ // src/params/legacy/utils/itemListAttribution.ts
1908
+ var LAST_SELECTED_ITEM_KEY = "last_selected_item";
1909
+ var STORAGE_VIEWED = "last_viewed_item";
1910
+ var CART_LIST_HISTORY_KEY = "cart_list_history";
1911
+ var DAY_IN_MS = 24 * 60 * 60 * 1e3;
1912
+ // src/core/utils.ts
1913
+ var isDebugMode = function() {
1914
+ if (typeof window === "undefined") return false;
1915
+ try {
1916
+ var params = new URLSearchParams(window.location.search);
1917
+ return params.has("__trk_inspect__");
1918
+ } catch (unused) {
1919
+ return window.location.search.indexOf("__trk_inspect__") !== -1;
1920
+ }
1921
+ };
1997
1922
  var paymentTypeMap = [
1998
1923
  [
1999
1924
  "vale",
@@ -2092,27 +2017,103 @@ var AzzasTracker = function() {
2092
2017
  });
2093
2018
  })();
2094
2019
  };
2095
- // src/adapters/index.ts
2096
- var adapters = {
2097
- DataLayer: pushToDataLayer,
2098
- Dito: pushToDito
2020
+ var SIZE_ORDER = {
2021
+ alfabetico: [
2022
+ "PP",
2023
+ "P",
2024
+ "M",
2025
+ "G",
2026
+ "GG",
2027
+ "XG",
2028
+ "XGG",
2029
+ "EG",
2030
+ "EGG",
2031
+ "3G",
2032
+ "4G",
2033
+ "5G"
2034
+ ],
2035
+ infantil: [
2036
+ "RN",
2037
+ "0-3M",
2038
+ "3-6M",
2039
+ "6-9M",
2040
+ "9-12M",
2041
+ "12-18M",
2042
+ "18-24M",
2043
+ "P",
2044
+ "M",
2045
+ "G",
2046
+ "GG"
2047
+ ]
2099
2048
  };
2100
- var BRAND_CODES = {
2101
- farm: "farmrio",
2102
- "farm etc": "farmetc",
2103
- "farm rio": "farmrio"
2049
+ var detectSizeType = function(sizes) {
2050
+ if (sizes.every(function(s) {
2051
+ return /^\d+([.,]\d+)?$/.test(s);
2052
+ })) return "numerico";
2053
+ if (sizes.some(function(s) {
2054
+ return /^(RN|\d+-\d+M|\d+M)$/i.test(s);
2055
+ })) return "infantil";
2056
+ if (sizes.every(function(s) {
2057
+ return SIZE_ORDER.alfabetico.includes(s.toUpperCase());
2058
+ })) return "alfabetico";
2059
+ return "desconhecido";
2060
+ };
2061
+ var sortSizes = function(sizes) {
2062
+ var unique = _to_consumable_array(new Set(sizes.filter(Boolean)));
2063
+ var type = detectSizeType(unique);
2064
+ if (type === "numerico") {
2065
+ return unique.sort(function(a, b) {
2066
+ return parseFloat(a) - parseFloat(b);
2067
+ });
2068
+ }
2069
+ if (type === "alfabetico" || type === "infantil") {
2070
+ var order = SIZE_ORDER[type];
2071
+ return unique.sort(function(a, b) {
2072
+ var ia = order.indexOf(a.toUpperCase());
2073
+ var ib = order.indexOf(b.toUpperCase());
2074
+ return (ia === -1 ? 999 : ia) - (ib === -1 ? 999 : ib);
2075
+ });
2076
+ }
2077
+ return unique;
2104
2078
  };
2105
- // src/params/utils/itemListAttribution.ts
2106
- var LAST_SELECTED_ITEM_KEY = "last_selected_item";
2107
- var STORAGE_VIEWED = "last_viewed_item";
2108
- var CART_LIST_HISTORY_KEY = "cart_list_history";
2109
- var DAY_IN_MS = 24 * 60 * 60 * 1e3;
2110
- // src/params/index.ts
2079
+ var capitalize = function(str) {
2080
+ return str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
2081
+ };
2082
+ // src/params/userInfo.ts
2083
+ var PROD_DOMAINS = {
2084
+ "animale": {
2085
+ "store": "https://www.animale.com.br",
2086
+ "checkout": "https://secure.animale.com.br"
2087
+ },
2088
+ "farm": {
2089
+ "store": "https://lojafarm.myvtex.com"
2090
+ },
2091
+ "mariafilo": {
2092
+ "store": "https://mariafilo.myvtex.com",
2093
+ "checkout": "https://secure.mariafilo.com.br"
2094
+ },
2095
+ "lojacrisbarros": {
2096
+ "store": "https://lojacrisbarros.myvtex.com",
2097
+ "checkout": "https://secure.crisbarros.com.br"
2098
+ },
2099
+ "lojaoffpremium": {
2100
+ "store": "https://lojaoffpremium.myvtex.com",
2101
+ "checkout": "https://secure.offpremium.com.br"
2102
+ },
2103
+ "bynv": {
2104
+ "store": "https://bynv.myvtex.com"
2105
+ },
2106
+ "fabula": {
2107
+ "store": "https://lojafabula.myvtex.com"
2108
+ }
2109
+ };
2110
+ // src/params/legacy/index.ts
2111
2111
  var paramGetters = {
2112
2112
  brand: getBrand,
2113
2113
  items: getItems,
2114
2114
  payment_type: getPaymentType,
2115
2115
  user_info: getUserInfo,
2116
+ // global
2116
2117
  content_type: function(context, eventName) {
2117
2118
  if (context === null || context === void 0 ? void 0 : context.content_type) return context.content_type;
2118
2119
  return "regiao".concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
@@ -2364,6 +2365,592 @@ var AzzasTracker = function() {
2364
2365
  return context.type || null;
2365
2366
  }
2366
2367
  };
2368
+ // src/params/adapters/meta/index.ts
2369
+ var metaAdapters = {
2370
+ user_info: getUserInfo,
2371
+ brand: function(context) {
2372
+ return context.meta.brand || null;
2373
+ },
2374
+ content_type: function(context) {
2375
+ if (context === null || context === void 0 ? void 0 : context.content_type) return context.content_type;
2376
+ return "regiao".concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
2377
+ },
2378
+ region: function(context) {
2379
+ return context.meta.region || null;
2380
+ },
2381
+ pre_filled: function(context) {
2382
+ return !!context.preFilled;
2383
+ },
2384
+ currency: function(context) {
2385
+ if (context === null || context === void 0 ? void 0 : context.currency) return context.currency;
2386
+ return "BRL";
2387
+ },
2388
+ search_term: function(context) {
2389
+ return context.searchTerm || null;
2390
+ },
2391
+ search_found: function(context) {
2392
+ return !!context.searchFound;
2393
+ },
2394
+ search_quantity: function(context) {
2395
+ return context.searchQuantity || 0;
2396
+ },
2397
+ promotion_name: function(context) {
2398
+ return context.meta.promotion_name || null;
2399
+ },
2400
+ creative_name: function(context) {
2401
+ return context.meta.creative_name || null;
2402
+ },
2403
+ creative_slot: function(context) {
2404
+ return context.meta.creative_slot || null;
2405
+ },
2406
+ zipcode: function(context) {
2407
+ return context.zipCode || null;
2408
+ },
2409
+ size: function(context) {
2410
+ return context.size || null;
2411
+ },
2412
+ item_ref: function(context) {
2413
+ return context.itemRef || null;
2414
+ },
2415
+ method: function(context) {
2416
+ return context.method || null;
2417
+ },
2418
+ type: function(context) {
2419
+ return context.type || null;
2420
+ }
2421
+ };
2422
+ // src/params/adapters/orderForm/index.ts
2423
+ var orderFormAdapters = {
2424
+ // orderform
2425
+ payment_type: getPaymentType,
2426
+ total_discount: function(context) {
2427
+ var _context_orderForm, _context_orderForm1;
2428
+ if (context === null || context === void 0 ? void 0 : context.totalDiscount) return context.totalDiscount;
2429
+ var totalsList = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.totalizers) || ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totals) || [];
2430
+ var items = context.orderForm.items;
2431
+ var totalDiscount = items.reduce(function(acc, item) {
2432
+ var unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
2433
+ return acc + unitDiscount * item.quantity;
2434
+ }, 0);
2435
+ var discounts = totalsList.find(function(t) {
2436
+ return t.id === "Discounts";
2437
+ });
2438
+ return Math.abs(((discounts === null || discounts === void 0 ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
2439
+ },
2440
+ subtotal: function(context) {
2441
+ var _context_orderForm, _context_orderForm1;
2442
+ var totalsList = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.totalizers) || ((_context_orderForm1 = context.orderForm) === null || _context_orderForm1 === void 0 ? void 0 : _context_orderForm1.totals) || [];
2443
+ var subtotal = totalsList.filter(function(t) {
2444
+ return t.id === "Items";
2445
+ }).reduce(function(acc, t) {
2446
+ return acc + (t.value || 0);
2447
+ }, 0) / 100 || 0;
2448
+ return subtotal;
2449
+ },
2450
+ coupon_message: function(context) {
2451
+ var _context_orderForm;
2452
+ if (context.couponMessage) return context.couponMessage;
2453
+ var messages = ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : _context_orderForm.messages) || [];
2454
+ if (messages.length === 0) return null;
2455
+ var couponMessages = messages.filter(function(msg) {
2456
+ return msg.text.toLowerCase().includes("cupom");
2457
+ });
2458
+ if (couponMessages.length === 0) return null;
2459
+ return couponMessages.map(function(msg) {
2460
+ return msg.text;
2461
+ }).join(" | ");
2462
+ },
2463
+ flag_pickup: function(context) {
2464
+ var _orderForm_shippingData;
2465
+ var orderForm = context.orderForm;
2466
+ if (!orderForm) return null;
2467
+ var logisticsInfo = ((_orderForm_shippingData = orderForm.shippingData) === null || _orderForm_shippingData === void 0 ? void 0 : _orderForm_shippingData.logisticsInfo) || [];
2468
+ var hasPickup = logisticsInfo.some(function(info) {
2469
+ var _info_slas;
2470
+ return (_info_slas = info.slas) === null || _info_slas === void 0 ? void 0 : _info_slas.some(function(sla) {
2471
+ return sla.deliveryChannel === "pickup-in-point";
2472
+ });
2473
+ });
2474
+ return hasPickup;
2475
+ },
2476
+ shippings: function(context) {
2477
+ var orderForm = context.orderForm;
2478
+ if (!orderForm) return null;
2479
+ var groupShipping = {};
2480
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2481
+ try {
2482
+ for(var _iterator = orderForm.shippingData.logisticsInfo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2483
+ var info = _step.value;
2484
+ var item = orderForm.items[info.itemIndex];
2485
+ if (!item) continue;
2486
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2487
+ try {
2488
+ for(var _iterator1 = info.slas[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2489
+ var sla = _step1.value;
2490
+ var key = sla.name;
2491
+ if (!groupShipping[key]) {
2492
+ groupShipping[key] = {
2493
+ shipping_tier: sla.name,
2494
+ delivery_time: parseInt(sla.shippingEstimate),
2495
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
2496
+ line_items: []
2497
+ };
2498
+ }
2499
+ groupShipping[key].line_items.push(item.id);
2500
+ }
2501
+ } catch (err) {
2502
+ _didIteratorError1 = true;
2503
+ _iteratorError1 = err;
2504
+ } finally{
2505
+ try {
2506
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2507
+ _iterator1.return();
2508
+ }
2509
+ } finally{
2510
+ if (_didIteratorError1) {
2511
+ throw _iteratorError1;
2512
+ }
2513
+ }
2514
+ }
2515
+ }
2516
+ } catch (err) {
2517
+ _didIteratorError = true;
2518
+ _iteratorError = err;
2519
+ } finally{
2520
+ try {
2521
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2522
+ _iterator.return();
2523
+ }
2524
+ } finally{
2525
+ if (_didIteratorError) {
2526
+ throw _iteratorError;
2527
+ }
2528
+ }
2529
+ }
2530
+ var shippings = Object.values(groupShipping).map(function(s) {
2531
+ return {
2532
+ shipping: s.shipping,
2533
+ shipping_tier: s.shipping_tier,
2534
+ delivery_time: s.delivery_time,
2535
+ line_items: s.line_items.join(",")
2536
+ };
2537
+ });
2538
+ return shippings || null;
2539
+ },
2540
+ shipping: function(context) {
2541
+ var _ref;
2542
+ var _context_orderForm_shippingData, _context_orderForm;
2543
+ var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
2544
+ return logistics.reduce(function(total, item) {
2545
+ var _ref;
2546
+ var _item_slas;
2547
+ var selected = (_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
2548
+ return sla.id === item.selectedSla;
2549
+ });
2550
+ return total + ((_ref = selected === null || selected === void 0 ? void 0 : selected.price) !== null && _ref !== void 0 ? _ref : 0);
2551
+ }, 0);
2552
+ },
2553
+ shipping_tier: function(context) {
2554
+ var _ref;
2555
+ var _context_orderForm_shippingData, _context_orderForm;
2556
+ var logistics = (_ref = context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_shippingData = _context_orderForm.shippingData) === null || _context_orderForm_shippingData === void 0 ? void 0 : _context_orderForm_shippingData.logisticsInfo) !== null && _ref !== void 0 ? _ref : [];
2557
+ var selectedSlas = logistics.map(function(item) {
2558
+ var _item_slas;
2559
+ if (!item.selectedSla) return null;
2560
+ return ((_item_slas = item.slas) === null || _item_slas === void 0 ? void 0 : _item_slas.find(function(sla) {
2561
+ return sla.id === item.selectedSla;
2562
+ })) || null;
2563
+ }).filter(Boolean);
2564
+ if (selectedSlas.length === 0) return null;
2565
+ var uniqueTiers = Array.from(new Map(selectedSlas.map(function(sla) {
2566
+ var _sla_pickupStoreInfo;
2567
+ var key = sla.deliveryChannel === "pickup-in-point" ? "pickup:".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) || sla.name || "") : "delivery:".concat(sla.name || "");
2568
+ return [
2569
+ key,
2570
+ sla
2571
+ ];
2572
+ })).values());
2573
+ var sortedTiers = uniqueTiers.sort(function(a, b) {
2574
+ var _a_pickupStoreInfo, _b_pickupStoreInfo;
2575
+ var aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
2576
+ var bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
2577
+ if (aOrder !== bOrder) return aOrder - bOrder;
2578
+ var aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a_pickupStoreInfo = a.pickupStoreInfo) === null || _a_pickupStoreInfo === void 0 ? void 0 : _a_pickupStoreInfo.friendlyName) || a.name || "" : a.name || "";
2579
+ var bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b_pickupStoreInfo = b.pickupStoreInfo) === null || _b_pickupStoreInfo === void 0 ? void 0 : _b_pickupStoreInfo.friendlyName) || b.name || "" : b.name || "";
2580
+ return aLabel.localeCompare(bLabel, "pt-BR");
2581
+ });
2582
+ var shippingTier = sortedTiers.map(function(sla) {
2583
+ var _sla_pickupStoreInfo;
2584
+ return sla.deliveryChannel === "pickup-in-point" ? "retirada em loja".concat(((_sla_pickupStoreInfo = sla.pickupStoreInfo) === null || _sla_pickupStoreInfo === void 0 ? void 0 : _sla_pickupStoreInfo.friendlyName) ? ": ".concat(sla.pickupStoreInfo.friendlyName) : "") : sla.deliveryChannel === "delivery" ? "receba em casa".concat(sla.name ? ": ".concat(sla.name) : "") : null;
2585
+ }).filter(Boolean).join(", ");
2586
+ return shippingTier || null;
2587
+ },
2588
+ transaction_id: function(context) {
2589
+ var _context_orderForm_orderGroup, _context_orderForm;
2590
+ return ((_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_orderGroup = _context_orderForm.orderGroup) === null || _context_orderForm_orderGroup === void 0 ? void 0 : _context_orderForm_orderGroup.toString()) || null;
2591
+ },
2592
+ coupon: function(context) {
2593
+ var _context_orderForm_marketingData, _context_orderForm;
2594
+ return context.appliedCoupon || (context === null || context === void 0 ? void 0 : (_context_orderForm = context.orderForm) === null || _context_orderForm === void 0 ? void 0 : (_context_orderForm_marketingData = _context_orderForm.marketingData) === null || _context_orderForm_marketingData === void 0 ? void 0 : _context_orderForm_marketingData.coupon) || null;
2595
+ },
2596
+ seller_cod_name: function(context) {
2597
+ return context.appliedSellerCodName || (context === null || context === void 0 ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
2598
+ }
2599
+ };
2600
+ // src/params/adapters/deco/utils/index.ts
2601
+ var getItemCategory3 = function(item) {
2602
+ var _text_match;
2603
+ var value = item === null || item === void 0 ? void 0 : item.category;
2604
+ if (!value) return "Cole\xE7\xE3o";
2605
+ var text = Array.isArray(value) ? value.join(" ") : String(value);
2606
+ var match = (_text_match = text.match(/outlet|bazar|sale/i)) === null || _text_match === void 0 ? void 0 : _text_match[0].toLowerCase();
2607
+ return match !== null && match !== void 0 ? match : "Cole\xE7\xE3o";
2608
+ };
2609
+ var getItemCategory22 = function(item) {
2610
+ var _ref, _categories_, _validHierarchy_;
2611
+ var _item_category;
2612
+ var AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
2613
+ var categories = (_ref = (_item_category = item.category) === null || _item_category === void 0 ? void 0 : _item_category.split(">")) !== null && _ref !== void 0 ? _ref : [];
2614
+ var last = (_categories_ = categories[categories.length - 1]) !== null && _categories_ !== void 0 ? _categories_ : "";
2615
+ var validHierarchy = last.split("/").filter(function(c) {
2616
+ return c && !AVOID_CATEGORIES.test(c);
2617
+ });
2618
+ var deepest = (_validHierarchy_ = validHierarchy[validHierarchy.length - 1]) !== null && _validHierarchy_ !== void 0 ? _validHierarchy_ : "";
2619
+ return capitalize(deepest);
2620
+ };
2621
+ var resizeVtexImage2 = function(url) {
2622
+ var width = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 500, height = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 500;
2623
+ return url === null || url === void 0 ? void 0 : url.replace(/(\/arquivos\/ids\/\d+)-\d+-\d+\//, "$1-".concat(width, "-").concat(height, "/"));
2624
+ };
2625
+ // src/params/adapters/deco/index.ts
2626
+ var IN_STOCK_SCHEMA = "https://schema.org/InStock";
2627
+ var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
2628
+ var decoAdapter = _object_spread_props(_object_spread({}, metaAdapters, orderFormAdapters), {
2629
+ // orderform adapters
2630
+ items: function(context) {
2631
+ if (context === null || context === void 0 ? void 0 : context.items) return context.items;
2632
+ if (context === null || context === void 0 ? void 0 : context.products) {
2633
+ return context.products.map(function(item) {
2634
+ var _ref, _ref1, _item_alternateName, _ref2, _ref3, _ref4, _getItemCategory3, _getItemCategory22, _ref5, _item_sku, _item_url, _resizeVtexImage2, _ref6, _ref7;
2635
+ var _item_offers_offers__priceSpecification_find, _item_offers_offers, _item_offers, _item_brand_name, _item_brand, _item_offers1, _item_offers2, _item_name_split_, _item_name, _item_name1, _item_additionalProperty_find, _item_additionalProperty, _item_image, _item_offers_offers_, _item_offers_offers1, _item_offers3;
2636
+ var COLOR_REGEX = /^[^_]+_/;
2637
+ var listPrice = item === null || item === void 0 ? void 0 : (_item_offers = item.offers) === null || _item_offers === void 0 ? void 0 : (_item_offers_offers = _item_offers.offers) === null || _item_offers_offers === void 0 ? void 0 : (_item_offers_offers__priceSpecification_find = _item_offers_offers[0].priceSpecification.find(function(s) {
2638
+ return s.priceType === LIST_PRICE_SCHEMA;
2639
+ })) === null || _item_offers_offers__priceSpecification_find === void 0 ? void 0 : _item_offers_offers__priceSpecification_find.price;
2640
+ return {
2641
+ quantity: 1,
2642
+ index: (_ref = item === null || item === void 0 ? void 0 : item.index) !== null && _ref !== void 0 ? _ref : 0,
2643
+ item_brand: (_ref1 = (_item_brand = item.brand) === null || _item_brand === void 0 ? void 0 : (_item_brand_name = _item_brand.name) === null || _item_brand_name === void 0 ? void 0 : _item_brand_name.toLowerCase()) !== null && _ref1 !== void 0 ? _ref1 : null,
2644
+ item_name: (_item_alternateName = item.alternateName) !== null && _item_alternateName !== void 0 ? _item_alternateName : null,
2645
+ price: (_ref2 = (_item_offers1 = item.offers) === null || _item_offers1 === void 0 ? void 0 : _item_offers1.lowPrice) !== null && _ref2 !== void 0 ? _ref2 : null,
2646
+ discount: Number(listPrice) - Number(item === null || item === void 0 ? void 0 : (_item_offers2 = item.offers) === null || _item_offers2 === void 0 ? void 0 : _item_offers2.lowPrice),
2647
+ item_variant: (item === null || item === void 0 ? void 0 : (_item_name = item.name) === null || _item_name === void 0 ? void 0 : (_item_name_split_ = _item_name.split(" - ")[0]) === null || _item_name_split_ === void 0 ? void 0 : _item_name_split_.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
2648
+ // cor
2649
+ item_variant2: (_ref3 = item === null || item === void 0 ? void 0 : (_item_name1 = item.name) === null || _item_name1 === void 0 ? void 0 : _item_name1.split(" - ")[1]) !== null && _ref3 !== void 0 ? _ref3 : null,
2650
+ // tamanho
2651
+ item_shipping_tier: getItemShippingTier2(),
2652
+ item_ref: (_ref4 = (_item_additionalProperty = item.additionalProperty) === null || _item_additionalProperty === void 0 ? void 0 : (_item_additionalProperty_find = _item_additionalProperty.find(function(i) {
2653
+ return i.name === "RefId";
2654
+ })) === null || _item_additionalProperty_find === void 0 ? void 0 : _item_additionalProperty_find.value) !== null && _ref4 !== void 0 ? _ref4 : null,
2655
+ item_category: (_getItemCategory3 = getItemCategory3(item)) !== null && _getItemCategory3 !== void 0 ? _getItemCategory3 : null,
2656
+ item_category2: (_getItemCategory22 = getItemCategory22(item)) !== null && _getItemCategory22 !== void 0 ? _getItemCategory22 : null,
2657
+ item_id: (_ref5 = item === null || item === void 0 ? void 0 : item.inProductGroupWithID) !== null && _ref5 !== void 0 ? _ref5 : null,
2658
+ item_sku: (_item_sku = item.sku) !== null && _item_sku !== void 0 ? _item_sku : null,
2659
+ item_url: (_item_url = item.url) !== null && _item_url !== void 0 ? _item_url : null,
2660
+ image_url: (_resizeVtexImage2 = resizeVtexImage2(item === null || item === void 0 ? void 0 : (_item_image = item.image) === null || _item_image === void 0 ? void 0 : _item_image[0].url)) !== null && _resizeVtexImage2 !== void 0 ? _resizeVtexImage2 : null,
2661
+ seller_id: (_ref6 = (_item_offers3 = item.offers) === null || _item_offers3 === void 0 ? void 0 : (_item_offers_offers1 = _item_offers3.offers) === null || _item_offers_offers1 === void 0 ? void 0 : (_item_offers_offers_ = _item_offers_offers1[0]) === null || _item_offers_offers_ === void 0 ? void 0 : _item_offers_offers_.seller) !== null && _ref6 !== void 0 ? _ref6 : null,
2662
+ item_list_name: (_ref7 = item === null || item === void 0 ? void 0 : item.item_list_name) !== null && _ref7 !== void 0 ? _ref7 : null
2663
+ };
2664
+ });
2665
+ }
2666
+ return null;
2667
+ },
2668
+ // brand: (context: DecoBrandContext) => {
2669
+ // if (context?.brand) return context.brand
2670
+ // if (context?.products) {
2671
+ // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
2672
+ // }
2673
+ // return null
2674
+ // },
2675
+ line_items: function(context) {
2676
+ if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
2677
+ if (context === null || context === void 0 ? void 0 : context.products) {
2678
+ return context.products.map(function(item) {
2679
+ return item === null || item === void 0 ? void 0 : item.inProductGroupWithID;
2680
+ }).filter(function(id) {
2681
+ return Boolean(id);
2682
+ });
2683
+ }
2684
+ return null;
2685
+ },
2686
+ value: function(context) {
2687
+ if (context === null || context === void 0 ? void 0 : context.value) return context.value;
2688
+ if (context === null || context === void 0 ? void 0 : context.products) {
2689
+ return context.products.map(function(item) {
2690
+ var _item_offers;
2691
+ return (_item_offers = item.offers) === null || _item_offers === void 0 ? void 0 : _item_offers.lowPrice;
2692
+ }).filter(function(price) {
2693
+ return price !== void 0;
2694
+ }).reduce(function(sum, price) {
2695
+ return sum + price;
2696
+ }, 0);
2697
+ }
2698
+ return null;
2699
+ },
2700
+ available_grid: function(context) {
2701
+ if (context === null || context === void 0 ? void 0 : context.available_grid) return context.available_grid;
2702
+ if (context === null || context === void 0 ? void 0 : context.products) {
2703
+ var sizes = context.products.flatMap(function(product) {
2704
+ var _ref;
2705
+ var _product_isVariantOf_hasVariant, _product_isVariantOf;
2706
+ return (_ref = (_product_isVariantOf = product.isVariantOf) === null || _product_isVariantOf === void 0 ? void 0 : (_product_isVariantOf_hasVariant = _product_isVariantOf.hasVariant) === null || _product_isVariantOf_hasVariant === void 0 ? void 0 : _product_isVariantOf_hasVariant.filter(function(variant) {
2707
+ var _variant_offers_offers, _variant_offers;
2708
+ return (_variant_offers = variant.offers) === null || _variant_offers === void 0 ? void 0 : (_variant_offers_offers = _variant_offers.offers) === null || _variant_offers_offers === void 0 ? void 0 : _variant_offers_offers.some(function(o) {
2709
+ return o.availability === IN_STOCK_SCHEMA;
2710
+ });
2711
+ }).map(function(variant) {
2712
+ var _variant_name;
2713
+ return (_variant_name = variant.name) === null || _variant_name === void 0 ? void 0 : _variant_name.split(" - ")[1];
2714
+ }).filter(function(name) {
2715
+ return Boolean(name);
2716
+ })) !== null && _ref !== void 0 ? _ref : [];
2717
+ });
2718
+ var result = sortSizes(sizes).join(",").trim();
2719
+ return result || null;
2720
+ }
2721
+ return null;
2722
+ }
2723
+ });
2724
+ // src/params/adapters/headless/utils/index.ts
2725
+ var getItemCategory5 = function(item) {
2726
+ var keywords = [
2727
+ "outlet",
2728
+ "bazar",
2729
+ "sale"
2730
+ ];
2731
+ var regex = new RegExp(keywords.join("|"), "i");
2732
+ var value = item === null || item === void 0 ? void 0 : item.categories;
2733
+ if (value) {
2734
+ var textToTest = Array.isArray(value) ? value.join(" ") : String(value);
2735
+ var match = textToTest.match(regex);
2736
+ if (match) {
2737
+ return match[0].toLowerCase();
2738
+ }
2739
+ }
2740
+ return "Cole\xE7\xE3o";
2741
+ };
2742
+ var getItemCategory23 = function(item) {
2743
+ var _ref, _reverse_find;
2744
+ var _item_categories;
2745
+ var avoidList = /outlet|bazar|sale/i;
2746
+ var lastCategory = (_ref = (_item_categories = item.categories) === null || _item_categories === void 0 ? void 0 : _item_categories[item.categories.length - 1]) !== null && _ref !== void 0 ? _ref : "";
2747
+ var categoryHierarchy = lastCategory.split("/").filter(Boolean);
2748
+ var deepestCategory = (_reverse_find = _to_consumable_array(categoryHierarchy).reverse().find(function(c) {
2749
+ return !avoidList.test(c);
2750
+ })) !== null && _reverse_find !== void 0 ? _reverse_find : "";
2751
+ return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
2752
+ };
2753
+ // src/params/adapters/headless/zones/PDP.ts
2754
+ var HeadlessPdpZone = {
2755
+ items: function(context) {
2756
+ if (context === null || context === void 0 ? void 0 : context.items) return context.items;
2757
+ if (context === null || context === void 0 ? void 0 : context.products) {
2758
+ return context.products.map(function(item) {
2759
+ var _ref, _item_brand, _item_productName, _ref1, _ref2, _item_productReference, _getItemCategory23, _ref3, _ref4, _item_link, _resizeVtexImage3, _ref5, _item_item_list_name;
2760
+ var _item_items__sellers, _item_items__sellers1, _item_items__name, _item_items_, _item_items__name1, _item_items_1, _item_items, _item_items__images, _item_items1, _item_items__sellers2, _item_items_2, _item_items2;
2761
+ var listPrice = item === null || item === void 0 ? void 0 : (_item_items__sellers = item.items[0].sellers) === null || _item_items__sellers === void 0 ? void 0 : _item_items__sellers[0].commertialOffer.ListPrice;
2762
+ var price = item === null || item === void 0 ? void 0 : (_item_items__sellers1 = item.items[0].sellers) === null || _item_items__sellers1 === void 0 ? void 0 : _item_items__sellers1[0].commertialOffer.Price;
2763
+ return {
2764
+ quantity: 1,
2765
+ index: (_ref = item === null || item === void 0 ? void 0 : item.index) !== null && _ref !== void 0 ? _ref : null,
2766
+ item_brand: (_item_brand = item.brand) !== null && _item_brand !== void 0 ? _item_brand : null,
2767
+ item_name: (_item_productName = item.productName) !== null && _item_productName !== void 0 ? _item_productName : null,
2768
+ price: price !== null && price !== void 0 ? price : null,
2769
+ discount: Number(listPrice) - Number(price),
2770
+ item_variant: (_ref1 = (_item_items_ = item.items[0]) === null || _item_items_ === void 0 ? void 0 : (_item_items__name = _item_items_.name) === null || _item_items__name === void 0 ? void 0 : _item_items__name.split(" - ")[0]) !== null && _ref1 !== void 0 ? _ref1 : null,
2771
+ item_variant2: (_ref2 = (_item_items_1 = item.items[0]) === null || _item_items_1 === void 0 ? void 0 : (_item_items__name1 = _item_items_1.name) === null || _item_items__name1 === void 0 ? void 0 : _item_items__name1.split(" - ")[1]) !== null && _ref2 !== void 0 ? _ref2 : null,
2772
+ item_ref: (_item_productReference = item.productReference) !== null && _item_productReference !== void 0 ? _item_productReference : null,
2773
+ // sem ref no retorno do IS na multi-lib produtos PDC
2774
+ item_category: getItemCategory5(item),
2775
+ item_category2: (_getItemCategory23 = getItemCategory23(item)) !== null && _getItemCategory23 !== void 0 ? _getItemCategory23 : null,
2776
+ item_id: (_ref3 = item === null || item === void 0 ? void 0 : item.productId) !== null && _ref3 !== void 0 ? _ref3 : null,
2777
+ item_sku: (_ref4 = (_item_items = item.items) === null || _item_items === void 0 ? void 0 : _item_items[0].itemId) !== null && _ref4 !== void 0 ? _ref4 : null,
2778
+ item_url: (_item_link = item.link) !== null && _item_link !== void 0 ? _item_link : null,
2779
+ // sem link/url no retorno do IS na multi-lib produtos PDC
2780
+ image_url: (_resizeVtexImage3 = resizeVtexImage3(item === null || item === void 0 ? void 0 : (_item_items1 = item.items) === null || _item_items1 === void 0 ? void 0 : (_item_items__images = _item_items1[0].images) === null || _item_items__images === void 0 ? void 0 : _item_items__images[0].imageUrl)) !== null && _resizeVtexImage3 !== void 0 ? _resizeVtexImage3 : null,
2781
+ seller_id: (_ref5 = (_item_items2 = item.items) === null || _item_items2 === void 0 ? void 0 : (_item_items_2 = _item_items2[0]) === null || _item_items_2 === void 0 ? void 0 : (_item_items__sellers2 = _item_items_2.sellers) === null || _item_items__sellers2 === void 0 ? void 0 : _item_items__sellers2[0].sellerId) !== null && _ref5 !== void 0 ? _ref5 : null,
2782
+ item_list_name: (_item_item_list_name = item.item_list_name) !== null && _item_item_list_name !== void 0 ? _item_item_list_name : null
2783
+ };
2784
+ });
2785
+ }
2786
+ return null;
2787
+ },
2788
+ value: function(context) {
2789
+ if (context === null || context === void 0 ? void 0 : context.value) return context.value;
2790
+ if (context === null || context === void 0 ? void 0 : context.products) {
2791
+ return context.products.map(function(item) {
2792
+ var _item_items__sellers;
2793
+ return item === null || item === void 0 ? void 0 : (_item_items__sellers = item.items[0].sellers) === null || _item_items__sellers === void 0 ? void 0 : _item_items__sellers[0].commertialOffer.Price;
2794
+ }).filter(function(price) {
2795
+ return price !== void 0;
2796
+ }).reduce(function(sum, price) {
2797
+ return sum + price;
2798
+ }, 0);
2799
+ }
2800
+ return null;
2801
+ },
2802
+ line_items: function(context) {
2803
+ if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
2804
+ if (context === null || context === void 0 ? void 0 : context.products) {
2805
+ return context.products.map(function(item) {
2806
+ return item.productId;
2807
+ }).filter(function(id) {
2808
+ return Boolean(id);
2809
+ });
2810
+ }
2811
+ return null;
2812
+ },
2813
+ brand: function(context) {
2814
+ if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2815
+ if (context === null || context === void 0 ? void 0 : context.products) {
2816
+ return context.products.map(function(p) {
2817
+ return p.brand;
2818
+ }).join().trim();
2819
+ }
2820
+ return null;
2821
+ }
2822
+ };
2823
+ // src/params/adapters/headless/zones/PDC.ts
2824
+ var HeadlessPdcZone = {
2825
+ items: function(context) {
2826
+ if (context === null || context === void 0 ? void 0 : context.items) return context.items;
2827
+ if (context === null || context === void 0 ? void 0 : context.products) {
2828
+ return context.products.map(function(item) {
2829
+ var _ref, _item_brand_name, _item_name, _ref1, _ref2, _item_additionalProperty, _getItemCategory23, _item_isVariantOf_productGroupID, _item_sku, _resizeVtexImage3, _ref3, _item_item_list_name;
2830
+ var _item_isVariantOf_hasVariant, _item_isVariantOf, _find, _item_image, _item_offers_offers_find_seller, _item_offers_offers_find, _item_offers_offers, _item_offers;
2831
+ var listPrice = item.offers.highPrice;
2832
+ var price = item.offers.lowPrice;
2833
+ return {
2834
+ quantity: 1,
2835
+ index: (_ref = item === null || item === void 0 ? void 0 : item.index) !== null && _ref !== void 0 ? _ref : 0,
2836
+ item_brand: (_item_brand_name = item.brand.name) !== null && _item_brand_name !== void 0 ? _item_brand_name : null,
2837
+ item_name: (_item_name = item.name) !== null && _item_name !== void 0 ? _item_name : null,
2838
+ price: price !== null && price !== void 0 ? price : null,
2839
+ discount: Number(listPrice) - Number(price),
2840
+ item_variant: (_ref1 = (_item_isVariantOf = item.isVariantOf) === null || _item_isVariantOf === void 0 ? void 0 : (_item_isVariantOf_hasVariant = _item_isVariantOf.hasVariant) === null || _item_isVariantOf_hasVariant === void 0 ? void 0 : _item_isVariantOf_hasVariant[0].name.split(" - ")[0]) !== null && _ref1 !== void 0 ? _ref1 : null,
2841
+ item_variant2: (_ref2 = (_find = ((_item_additionalProperty = item.additionalProperty) !== null && _item_additionalProperty !== void 0 ? _item_additionalProperty : []).find(function(p) {
2842
+ return p.name === "Tamanho";
2843
+ })) === null || _find === void 0 ? void 0 : _find.value) !== null && _ref2 !== void 0 ? _ref2 : null,
2844
+ item_ref: null,
2845
+ // sem ref no retorno do IS na multi-lib produtos PDC
2846
+ item_category: getItemCategory5(item),
2847
+ item_category2: (_getItemCategory23 = getItemCategory23(item)) !== null && _getItemCategory23 !== void 0 ? _getItemCategory23 : null,
2848
+ item_id: (_item_isVariantOf_productGroupID = item.isVariantOf.productGroupID) !== null && _item_isVariantOf_productGroupID !== void 0 ? _item_isVariantOf_productGroupID : null,
2849
+ item_sku: (_item_sku = item.sku) !== null && _item_sku !== void 0 ? _item_sku : null,
2850
+ item_url: null,
2851
+ // sem link/url no retorno do IS na multi-lib produtos PDC
2852
+ image_url: (_resizeVtexImage3 = resizeVtexImage3(item === null || item === void 0 ? void 0 : (_item_image = item.image) === null || _item_image === void 0 ? void 0 : _item_image[0].url)) !== null && _resizeVtexImage3 !== void 0 ? _resizeVtexImage3 : null,
2853
+ seller_id: (_ref3 = (_item_offers = item.offers) === null || _item_offers === void 0 ? void 0 : (_item_offers_offers = _item_offers.offers) === null || _item_offers_offers === void 0 ? void 0 : (_item_offers_offers_find = _item_offers_offers.find(function(o) {
2854
+ return o.availability;
2855
+ })) === null || _item_offers_offers_find === void 0 ? void 0 : (_item_offers_offers_find_seller = _item_offers_offers_find.seller) === null || _item_offers_offers_find_seller === void 0 ? void 0 : _item_offers_offers_find_seller.identifier) !== null && _ref3 !== void 0 ? _ref3 : null,
2856
+ item_list_name: (_item_item_list_name = item.item_list_name) !== null && _item_item_list_name !== void 0 ? _item_item_list_name : null
2857
+ };
2858
+ });
2859
+ }
2860
+ return null;
2861
+ },
2862
+ value: function(context) {
2863
+ if (context === null || context === void 0 ? void 0 : context.value) return context.value;
2864
+ if (context === null || context === void 0 ? void 0 : context.products) {
2865
+ return context.products.map(function(item) {
2866
+ return item.offers.lowPrice;
2867
+ }).filter(function(price) {
2868
+ return price !== void 0;
2869
+ }).reduce(function(sum, price) {
2870
+ return sum + price;
2871
+ }, 0);
2872
+ }
2873
+ return null;
2874
+ },
2875
+ line_items: function(context) {
2876
+ if (context === null || context === void 0 ? void 0 : context.line_items) return context.line_items;
2877
+ if (context === null || context === void 0 ? void 0 : context.products) {
2878
+ return context.products.map(function(item) {
2879
+ return item.id;
2880
+ }).filter(function(id) {
2881
+ return Boolean(id);
2882
+ });
2883
+ }
2884
+ return null;
2885
+ },
2886
+ brand: function(context) {
2887
+ if (context === null || context === void 0 ? void 0 : context.brand) return context.brand;
2888
+ if (context === null || context === void 0 ? void 0 : context.products) {
2889
+ return context.products.map(function(p) {
2890
+ return p.brand.name;
2891
+ }).join().trim();
2892
+ }
2893
+ return null;
2894
+ }
2895
+ };
2896
+ // src/params/adapters/headless/index.ts
2897
+ var headlessAdapter = _object_spread_props(_object_spread({}, metaAdapters, orderFormAdapters), {
2898
+ // orderForm adapters, confirmar se no storefront tem evento que usa essses params
2899
+ brand: function(context) {
2900
+ if (context.zone === "PDP") {
2901
+ return HeadlessPdpZone.brand(context);
2902
+ }
2903
+ if (context.zone === "PDC") {
2904
+ return HeadlessPdcZone.brand(context);
2905
+ }
2906
+ return null;
2907
+ },
2908
+ line_items: function(context) {
2909
+ if (context.zone === "PDP") {
2910
+ return HeadlessPdpZone.line_items(context);
2911
+ }
2912
+ if (context.zone === "PDC") {
2913
+ return HeadlessPdcZone.line_items(context);
2914
+ }
2915
+ return null;
2916
+ },
2917
+ value: function(context) {
2918
+ if (context.zone === "PDP") {
2919
+ return HeadlessPdpZone.value(context);
2920
+ }
2921
+ if (context.zone === "PDC") {
2922
+ return HeadlessPdcZone.value(context);
2923
+ }
2924
+ return null;
2925
+ },
2926
+ items: function(context) {
2927
+ if (context.zone === "PDP") {
2928
+ return HeadlessPdpZone.items(context);
2929
+ }
2930
+ if (context.zone === "PDC") {
2931
+ return HeadlessPdcZone.items(context);
2932
+ }
2933
+ },
2934
+ // param used only in one Zone, the PDP; no need condition
2935
+ available_grid: function(context) {
2936
+ if (context === null || context === void 0 ? void 0 : context.available_grid) return context.available_grid;
2937
+ if (context === null || context === void 0 ? void 0 : context.products) {
2938
+ var sizes = context.products.flatMap(function(p) {
2939
+ return p.items.map(function(i) {
2940
+ return i.Tamanho[0];
2941
+ });
2942
+ });
2943
+ var result = sortSizes(sizes).join(",");
2944
+ return result || null;
2945
+ }
2946
+ return null;
2947
+ }
2948
+ });
2949
+ // src/formatter.ts
2950
+ var adapters = {
2951
+ DECO: decoAdapter,
2952
+ HEADLESS: headlessAdapter
2953
+ };
2367
2954
  var src_default = {
2368
2955
  trackWebEvent: trackWebEvent,
2369
2956
  EVENTS: EVENTS