@azzas/azzas-tracker-web 1.0.98 → 1.0.99-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.
@@ -322,7 +322,7 @@ var AzzasTracker = (() => {
322
322
  }
323
323
  };
324
324
 
325
- // src/adapters/datalayer.ts
325
+ // src/pushToDatalayer.ts
326
326
  function pushToDataLayer(event, context) {
327
327
  const targetWindow = context.window || (typeof window !== "undefined" ? window : null);
328
328
  if (!targetWindow) return;
@@ -333,74 +333,13 @@ var AzzasTracker = (() => {
333
333
  targetWindow.dataLayer = targetWindow.dataLayer || [];
334
334
  if (eventConfig == null ? void 0 : eventConfig.hasEcommerce) {
335
335
  targetWindow.dataLayer.push({ ecommerce: null });
336
- targetWindow.dataLayer.push({ event, ecommerce: payload });
336
+ targetWindow.dataLayer.push({ event: event.toLowerCase(), ecommerce: payload });
337
337
  } else {
338
- targetWindow.dataLayer.push(Object.assign({ event }, payload));
338
+ targetWindow.dataLayer.push(Object.assign({ event: event.toLowerCase() }, payload));
339
339
  }
340
340
  }
341
341
 
342
- // src/core/utils.ts
343
- function dataTrackingLog(data, color) {
344
- console.log(
345
- `%c[DT] EVENTO DISPARADO:%c `,
346
- `background: ${color}; color: white; font-weight: bold; padding: 2px 4px; border-radius: 3px;`,
347
- "color: #fff;",
348
- data || ""
349
- );
350
- }
351
- var paymentTypeMap = [
352
- ["vale", "vale cr\xE9dito"],
353
- ["pagaleve", "pix"],
354
- ["pix parcel", "pix parcelado"],
355
- ["pix", "pix"],
356
- ["apple", "apple pay"],
357
- ["google", "google pay"],
358
- ["boleto", "boleto"],
359
- ["paypal", "paypal"],
360
- ["cred", "cart\xE3o"],
361
- ["visa", "cart\xE3o"],
362
- ["master", "cart\xE3o"],
363
- ["amex", "cart\xE3o"],
364
- ["elo", "cart\xE3o"],
365
- ["hiper", "cart\xE3o"],
366
- ["diner", "cart\xE3o"],
367
- ["deb", "cart\xE3o"]
368
- ];
369
- var toNum = (val) => typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
370
- var documentToHash = async (document2) => {
371
- if (!document2) return null;
372
- const encoder = new TextEncoder();
373
- const data = encoder.encode(document2);
374
- const hashBuffer = await crypto.subtle.digest("SHA-256", data);
375
- const hashArray = Array.from(new Uint8Array(hashBuffer));
376
- return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
377
- };
378
-
379
- // src/adapters/dito.ts
380
- function pushToDito(event, ecomm) {
381
- dataTrackingLog({ id: event, custom_data: ecomm }, "#00c851");
382
- }
383
-
384
- // src/adapters/index.ts
385
- var adapters = {
386
- DataLayer: pushToDataLayer,
387
- Dito: pushToDito
388
- };
389
- async function dispatchTrackEvent(eventName, data) {
390
- const eventConfig = EVENTS[eventName];
391
- if (!eventConfig) return;
392
- await Promise.allSettled(
393
- eventConfig.destinations.map(async (dest) => {
394
- try {
395
- await adapters[dest](eventName.toLowerCase(), data);
396
- } catch (err) {
397
- console.error(`[DT] Failed to send ${eventName} to ${dest}:`, err);
398
- }
399
- })
400
- );
401
- }
402
-
403
- // src/params/utils/index.ts
342
+ // src/params/legacy/utils/index.ts
404
343
  async function getProductDataById(id) {
405
344
  try {
406
345
  const response = await fetch(
@@ -588,7 +527,7 @@ var AzzasTracker = (() => {
588
527
  return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
589
528
  }
590
529
 
591
- // src/params/resolvers/brand/fromOrderForm.ts
530
+ // src/params/legacy/resolvers/brand/fromOrderForm.ts
592
531
  function brandFromOrderForm(context) {
593
532
  var _a;
594
533
  if (!context.orderForm && !((_a = context.orderForm.items) == null ? void 0 : _a.length)) return null;
@@ -596,14 +535,14 @@ var AzzasTracker = (() => {
596
535
  return normalizeBrand(items);
597
536
  }
598
537
 
599
- // src/params/resolvers/brand/fromItem.ts
538
+ // src/params/legacy/resolvers/brand/fromItem.ts
600
539
  function brandFromItem(context) {
601
540
  var _a;
602
541
  const { item } = context;
603
542
  return normalizeBrand(((_a = item == null ? void 0 : item.additionalInfo) == null ? void 0 : _a.brandName) || item.brand || item.item_brand);
604
543
  }
605
544
 
606
- // src/params/brand.ts
545
+ // src/params/legacy/brand.ts
607
546
  function getBrand(context, eventName) {
608
547
  if (context == null ? void 0 : context.brand) return normalizeBrand(context.brand) || context.brand || null;
609
548
  switch (eventName) {
@@ -627,7 +566,7 @@ var AzzasTracker = (() => {
627
566
  }
628
567
  }
629
568
 
630
- // src/params/utils/itemListAttribution.ts
569
+ // src/params/legacy/utils/itemListAttribution.ts
631
570
  var LAST_SELECTED_ITEM_KEY = "last_selected_item";
632
571
  var STORAGE_VIEWED = "last_viewed_item";
633
572
  var CART_LIST_HISTORY_KEY = "cart_list_history";
@@ -808,7 +747,7 @@ var AzzasTracker = (() => {
808
747
  saveSelectedItem(productId, listName);
809
748
  }
810
749
 
811
- // src/params/resolvers/items/fromOrderForm.ts
750
+ // src/params/legacy/resolvers/items/fromOrderForm.ts
812
751
  async function itemsFromOrderForm(context) {
813
752
  var _a;
814
753
  const items = ((_a = context.orderForm) == null ? void 0 : _a.items) || [];
@@ -840,7 +779,7 @@ var AzzasTracker = (() => {
840
779
  );
841
780
  }
842
781
 
843
- // src/params/resolvers/items/fromItem.ts
782
+ // src/params/legacy/resolvers/items/fromItem.ts
844
783
  async function itemsFromItem(context, event) {
845
784
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
846
785
  const { item, orderForm, itemListName } = context;
@@ -876,7 +815,7 @@ var AzzasTracker = (() => {
876
815
  ];
877
816
  }
878
817
 
879
- // src/params/resolvers/items/fromList.ts
818
+ // src/params/legacy/resolvers/items/fromList.ts
880
819
  async function itemsFromList(context) {
881
820
  return ((context == null ? void 0 : context.list) || []).map((item) => {
882
821
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
@@ -897,7 +836,7 @@ var AzzasTracker = (() => {
897
836
  });
898
837
  }
899
838
 
900
- // src/params/resolvers/items/fromPdp.ts
839
+ // src/params/legacy/resolvers/items/fromPdp.ts
901
840
  async function itemsFromPDP(context, event) {
902
841
  var _a, _b, _c, _d;
903
842
  const { item, value, brand } = context;
@@ -928,7 +867,7 @@ var AzzasTracker = (() => {
928
867
  ];
929
868
  }
930
869
 
931
- // src/params/resolvers/items/fromBanner.ts
870
+ // src/params/legacy/resolvers/items/fromBanner.ts
932
871
  async function itemsFromBanner(context) {
933
872
  var _a;
934
873
  const isUrlFromPDP = isPDP(context == null ? void 0 : context.bannerUrl);
@@ -949,7 +888,7 @@ var AzzasTracker = (() => {
949
888
  };
950
889
  }
951
890
 
952
- // src/params/items.ts
891
+ // src/params/legacy/items.ts
953
892
  function getItems(context, eventName) {
954
893
  if (context == null ? void 0 : context.items) return context.items;
955
894
  switch (eventName) {
@@ -983,7 +922,36 @@ var AzzasTracker = (() => {
983
922
  }
984
923
  }
985
924
 
986
- // src/params/resolvers/paymentType/fromOrderForm.ts
925
+ // src/core/utils.ts
926
+ var paymentTypeMap = [
927
+ ["vale", "vale cr\xE9dito"],
928
+ ["pagaleve", "pix"],
929
+ ["pix parcel", "pix parcelado"],
930
+ ["pix", "pix"],
931
+ ["apple", "apple pay"],
932
+ ["google", "google pay"],
933
+ ["boleto", "boleto"],
934
+ ["paypal", "paypal"],
935
+ ["cred", "cart\xE3o"],
936
+ ["visa", "cart\xE3o"],
937
+ ["master", "cart\xE3o"],
938
+ ["amex", "cart\xE3o"],
939
+ ["elo", "cart\xE3o"],
940
+ ["hiper", "cart\xE3o"],
941
+ ["diner", "cart\xE3o"],
942
+ ["deb", "cart\xE3o"]
943
+ ];
944
+ var toNum = (val) => typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
945
+ var documentToHash = async (document2) => {
946
+ if (!document2) return null;
947
+ const encoder = new TextEncoder();
948
+ const data = encoder.encode(document2);
949
+ const hashBuffer = await crypto.subtle.digest("SHA-256", data);
950
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
951
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
952
+ };
953
+
954
+ // src/params/legacy/resolvers/paymentType/fromOrderForm.ts
987
955
  function paymentTypeFromOrderForm(context) {
988
956
  var _a, _b, _c;
989
957
  if (context.payment_type) return context.payment_type;
@@ -1000,7 +968,7 @@ var AzzasTracker = (() => {
1000
968
  return match ? match[1] : null;
1001
969
  }
1002
970
 
1003
- // src/params/resolvers/paymentType/fromOrderGroup.ts
971
+ // src/params/legacy/resolvers/paymentType/fromOrderGroup.ts
1004
972
  function paymentTypeFromOrderGroup(context) {
1005
973
  var _a, _b, _c, _d;
1006
974
  if (!context.orderForm) return null;
@@ -1013,7 +981,7 @@ var AzzasTracker = (() => {
1013
981
  return match ? match[1] : null;
1014
982
  }
1015
983
 
1016
- // src/params/paymentType.ts
984
+ // src/params/legacy/paymentType.ts
1017
985
  function getPaymentType(context, eventName) {
1018
986
  if (context == null ? void 0 : context.paymentType) return context.paymentType;
1019
987
  switch (eventName) {
@@ -1110,12 +1078,13 @@ var AzzasTracker = (() => {
1110
1078
  }
1111
1079
  }
1112
1080
 
1113
- // src/params/index.ts
1081
+ // src/params/legacy/index.ts
1114
1082
  var paramGetters = {
1115
1083
  brand: getBrand,
1116
1084
  items: getItems,
1117
1085
  payment_type: getPaymentType,
1118
1086
  user_info: getUserInfo,
1087
+ // global
1119
1088
  content_type: (context, eventName) => {
1120
1089
  if (context == null ? void 0 : context.content_type) return context.content_type;
1121
1090
  return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
@@ -1311,30 +1280,586 @@ var AzzasTracker = (() => {
1311
1280
  }
1312
1281
  };
1313
1282
 
1314
- // src/formatter/index.ts
1283
+ // src/params/adapters/deco/index.ts
1284
+ var IN_STOCK_SCHEMA = "https://schema.org/InStock";
1285
+ var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
1286
+ var decoAdapter = {
1287
+ brand: (context, eventName) => {
1288
+ var _a;
1289
+ if (context == null ? void 0 : context.brand) return context.brand;
1290
+ if (context == null ? void 0 : context.products) {
1291
+ return (_a = context.products[0].brand) == null ? void 0 : _a.name;
1292
+ }
1293
+ return null;
1294
+ },
1295
+ line_items: (context, eventName) => {
1296
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1297
+ if (context == null ? void 0 : context.products) {
1298
+ return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
1299
+ }
1300
+ return null;
1301
+ },
1302
+ currency: (context, eventName) => {
1303
+ var _a, _b;
1304
+ if (context == null ? void 0 : context.currency) return context.currency;
1305
+ if (context == null ? void 0 : context.products) {
1306
+ return ((_b = (_a = context.products) == null ? void 0 : _a[0].offers) == null ? void 0 : _b.priceCurrency) || null;
1307
+ }
1308
+ return null;
1309
+ },
1310
+ value: (context, eventName) => {
1311
+ if (context == null ? void 0 : context.value) return context.value;
1312
+ if (context == null ? void 0 : context.products) {
1313
+ return context.products.map((item) => {
1314
+ var _a;
1315
+ return (_a = item.offers) == null ? void 0 : _a.lowPrice;
1316
+ }).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1317
+ }
1318
+ return null;
1319
+ },
1320
+ available_grid: (context, eventName) => {
1321
+ if (context == null ? void 0 : context.available_grid) return context.available_grid;
1322
+ if (context == null ? void 0 : context.products) {
1323
+ const result = context.products.flatMap(
1324
+ (product) => {
1325
+ var _a, _b, _c;
1326
+ return (_c = (_b = (_a = product.isVariantOf) == null ? void 0 : _a.hasVariant) == null ? void 0 : _b.filter(
1327
+ (variant) => {
1328
+ var _a2, _b2;
1329
+ return (_b2 = (_a2 = variant.offers) == null ? void 0 : _a2.offers) == null ? void 0 : _b2.some((o) => o.availability === IN_STOCK_SCHEMA);
1330
+ }
1331
+ ).map((variant) => variant.name).filter((name) => Boolean(name))) != null ? _c : [];
1332
+ }
1333
+ ).join(",").trim();
1334
+ return result || null;
1335
+ }
1336
+ return null;
1337
+ },
1338
+ items: (context, eventName) => {
1339
+ if (context == null ? void 0 : context.items) return context.items;
1340
+ if (context == null ? void 0 : context.products) {
1341
+ return context.products.map((item) => {
1342
+ 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;
1343
+ const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
1344
+ (s) => s.priceType === LIST_PRICE_SCHEMA
1345
+ )) == null ? void 0 : _c.price;
1346
+ return {
1347
+ quantity: 1,
1348
+ item_brand: (_e = (_d = item.brand) == null ? void 0 : _d.name) != null ? _e : null,
1349
+ item_name: (_f = item.alternateName) != null ? _f : null,
1350
+ price: (_h = (_g = item.offers) == null ? void 0 : _g.lowPrice) != null ? _h : null,
1351
+ discount: Number(listPrice) - Number((_i = item == null ? void 0 : item.offers) == null ? void 0 : _i.lowPrice),
1352
+ item_variant: (_l = (_k = (_j = item.additionalProperty) == null ? void 0 : _j.find((p) => p.name === "Cores")) == null ? void 0 : _k.value) != null ? _l : null,
1353
+ item_ref: (_o = (_n = (_m = item.additionalProperty) == null ? void 0 : _m.find(((i) => i.name === "RefId"))) == null ? void 0 : _n.value) != null ? _o : null,
1354
+ item_category: getItemCategory3(item),
1355
+ item_category2: (_r = (_q = (_p = item.category) == null ? void 0 : _p.split(">").pop()) == null ? void 0 : _q.toLowerCase().replace(/^./, (c) => c.toUpperCase())) != null ? _r : null,
1356
+ item_id: (_t = (_s = item == null ? void 0 : item.isVariantOf) == null ? void 0 : _s.productGroupID) != null ? _t : null,
1357
+ item_sku: (_u = item.sku) != null ? _u : null,
1358
+ item_url: (_v = item.url) != null ? _v : null,
1359
+ image_url: (_x = resizeVtexImage2((_w = item == null ? void 0 : item.image) == null ? void 0 : _w[0].url)) != null ? _x : null,
1360
+ seller_id: (_B = (_A = (_z = (_y = item.offers) == null ? void 0 : _y.offers) == null ? void 0 : _z[0]) == null ? void 0 : _A.seller) != null ? _B : null,
1361
+ item_list_name: ""
1362
+ };
1363
+ });
1364
+ }
1365
+ return null;
1366
+ },
1367
+ // legacy/global params TO BE DONE (move to a global file or other adapter)
1368
+ payment_type: getPaymentType,
1369
+ user_info: getUserInfo,
1370
+ // global
1371
+ content_type: (context, eventName) => {
1372
+ if (context == null ? void 0 : context.content_type) return context.content_type;
1373
+ return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
1374
+ },
1375
+ region: (context, eventName) => {
1376
+ return context.region || null;
1377
+ },
1378
+ total_discount: (context, eventName) => {
1379
+ var _a, _b;
1380
+ if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
1381
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1382
+ const items = context.orderForm.items;
1383
+ const totalDiscount = items.reduce((acc, item) => {
1384
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1385
+ return acc + unitDiscount * item.quantity;
1386
+ }, 0);
1387
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1388
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1389
+ },
1390
+ subtotal: (context, eventName) => {
1391
+ var _a, _b;
1392
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1393
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1394
+ return subtotal;
1395
+ },
1396
+ coupon_message: (context, eventName) => {
1397
+ var _a;
1398
+ if (context.couponMessage) return context.couponMessage;
1399
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1400
+ if (messages.length === 0) return null;
1401
+ const couponMessages = messages.filter(
1402
+ (msg) => msg.text.toLowerCase().includes("cupom")
1403
+ );
1404
+ if (couponMessages.length === 0) return null;
1405
+ return couponMessages.map((msg) => msg.text).join(" | ");
1406
+ },
1407
+ seller_cod_name: (context, eventName) => {
1408
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1409
+ },
1410
+ coupon: (context, eventName) => {
1411
+ var _a, _b;
1412
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1413
+ },
1414
+ pre_filled: (context, eventName) => {
1415
+ return !!context.preFilled;
1416
+ },
1417
+ search_term: (context, eventName) => {
1418
+ return context.searchTerm || null;
1419
+ },
1420
+ search_found: (context, eventName) => {
1421
+ return !!context.searchFound;
1422
+ },
1423
+ search_quantity: (context, eventName) => {
1424
+ return context.searchQuantity || 0;
1425
+ },
1426
+ promotion_name: (context, eventName) => {
1427
+ return context.promotionName || null;
1428
+ },
1429
+ creative_name: (context, eventName) => {
1430
+ return context.creativeName || null;
1431
+ },
1432
+ creative_slot: (context, eventName) => {
1433
+ return context.creativeSlot || null;
1434
+ },
1435
+ zipcode: (context, eventName) => {
1436
+ return context.zipCode || null;
1437
+ },
1438
+ size: (context, eventName) => {
1439
+ return context.size || null;
1440
+ },
1441
+ item_ref: (context, eventName) => {
1442
+ return context.itemRef || null;
1443
+ },
1444
+ flag_pickup: (context, eventName) => {
1445
+ var _a;
1446
+ const orderForm = context.orderForm;
1447
+ if (!orderForm) return null;
1448
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1449
+ const hasPickup = logisticsInfo.some(
1450
+ (info) => {
1451
+ var _a2;
1452
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1453
+ }
1454
+ );
1455
+ return hasPickup;
1456
+ },
1457
+ shippings: (context, eventName) => {
1458
+ const orderForm = context.orderForm;
1459
+ if (!orderForm) return null;
1460
+ const groupShipping = {};
1461
+ for (const info of orderForm.shippingData.logisticsInfo) {
1462
+ const item = orderForm.items[info.itemIndex];
1463
+ if (!item) continue;
1464
+ for (const sla of info.slas) {
1465
+ const key = sla.name;
1466
+ if (!groupShipping[key]) {
1467
+ groupShipping[key] = {
1468
+ shipping_tier: sla.name,
1469
+ delivery_time: parseInt(sla.shippingEstimate),
1470
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1471
+ line_items: []
1472
+ };
1473
+ }
1474
+ groupShipping[key].line_items.push(item.id);
1475
+ }
1476
+ }
1477
+ const shippings = Object.values(groupShipping).map((s) => ({
1478
+ shipping: s.shipping,
1479
+ shipping_tier: s.shipping_tier,
1480
+ delivery_time: s.delivery_time,
1481
+ line_items: s.line_items.join(",")
1482
+ }));
1483
+ return shippings || null;
1484
+ },
1485
+ shipping: (context, eventName) => {
1486
+ var _a, _b, _c;
1487
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1488
+ return logistics.reduce((total, item) => {
1489
+ var _a2, _b2;
1490
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1491
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1492
+ }, 0);
1493
+ },
1494
+ shipping_tier: (context, eventName) => {
1495
+ var _a, _b, _c;
1496
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1497
+ const selectedSlas = logistics.map((item) => {
1498
+ var _a2;
1499
+ if (!item.selectedSla) return null;
1500
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1501
+ }).filter(Boolean);
1502
+ if (selectedSlas.length === 0) return null;
1503
+ const uniqueTiers = Array.from(
1504
+ new Map(
1505
+ selectedSlas.map((sla) => {
1506
+ var _a2;
1507
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1508
+ return [key, sla];
1509
+ })
1510
+ ).values()
1511
+ );
1512
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1513
+ var _a2, _b2;
1514
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1515
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1516
+ if (aOrder !== bOrder) return aOrder - bOrder;
1517
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1518
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1519
+ return aLabel.localeCompare(bLabel, "pt-BR");
1520
+ });
1521
+ const shippingTier = sortedTiers.map((sla) => {
1522
+ var _a2;
1523
+ 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;
1524
+ }).filter(Boolean).join(", ");
1525
+ return shippingTier || null;
1526
+ },
1527
+ transaction_id: (context, eventName) => {
1528
+ var _a, _b;
1529
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1530
+ },
1531
+ method: (context, eventName) => {
1532
+ return context.method || null;
1533
+ },
1534
+ type: (context, eventName) => {
1535
+ return context.type || null;
1536
+ }
1537
+ };
1538
+ var getItemCategory3 = (item) => {
1539
+ const keywords = ["outlet", "bazar", "sale"];
1540
+ const regex = new RegExp(keywords.join("|"), "i");
1541
+ const value = item == null ? void 0 : item.category;
1542
+ if (value) {
1543
+ const textToTest = Array.isArray(value) ? value.join(" ") : String(value);
1544
+ const match = textToTest.match(regex);
1545
+ if (match) {
1546
+ return match[0].toLowerCase();
1547
+ }
1548
+ }
1549
+ return "Cole\xE7\xE3o";
1550
+ };
1551
+ var resizeVtexImage2 = (url, width = 500, height = 500) => {
1552
+ return url == null ? void 0 : url.replace(
1553
+ /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1554
+ `$1-${width}-${height}/`
1555
+ );
1556
+ };
1557
+
1558
+ // src/params/adapters/IntelligentSearch/index.ts
1559
+ var intelligentSearchAdapter = {
1560
+ brand: (context, eventName) => {
1561
+ if (context == null ? void 0 : context.brand) return context.brand;
1562
+ if (context == null ? void 0 : context.products) {
1563
+ return context.products.map((p) => {
1564
+ const isPDP2 = "items" in p;
1565
+ return isPDP2 ? p.brand : p.brand.name;
1566
+ }).join().trim();
1567
+ }
1568
+ return null;
1569
+ },
1570
+ line_items: (context, eventName) => {
1571
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1572
+ if (context == null ? void 0 : context.products) {
1573
+ return context.products.map((item) => "productId" in item ? item.productId : item.id).filter((id) => Boolean(id));
1574
+ }
1575
+ return null;
1576
+ },
1577
+ currency: (context, eventName) => {
1578
+ if (context == null ? void 0 : context.currency) return context.currency;
1579
+ return "BRL";
1580
+ },
1581
+ value: (context, eventName) => {
1582
+ if (context == null ? void 0 : context.value) return context.value;
1583
+ if (context == null ? void 0 : context.products) {
1584
+ return context.products.map((item) => {
1585
+ var _a;
1586
+ return "items" in item ? (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.Price : item.offers.lowPrice;
1587
+ }).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1588
+ }
1589
+ return null;
1590
+ },
1591
+ available_grid: (context, eventName) => {
1592
+ var _a;
1593
+ if (context == null ? void 0 : context.available_grid) return context.available_grid;
1594
+ if (context == null ? void 0 : context.products) {
1595
+ const result = (_a = context == null ? void 0 : context.products) == null ? void 0 : _a.map((p) => {
1596
+ const isPDP2 = "items" in p;
1597
+ return isPDP2 ? p.items.map((i) => i.Tamanho[0]) : [];
1598
+ }).join(",").trim();
1599
+ return result || null;
1600
+ }
1601
+ return null;
1602
+ },
1603
+ items: (context, eventName) => {
1604
+ if (context == null ? void 0 : context.items) return context.items;
1605
+ if (context == null ? void 0 : context.products) {
1606
+ return context.products.map((item) => {
1607
+ 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;
1608
+ const isPDP2 = "items" in item;
1609
+ const listPrice = isPDP2 ? (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.ListPrice : item.offers.highPrice;
1610
+ const price = isPDP2 ? (_b = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _b[0].commertialOffer.Price : item.offers.lowPrice;
1611
+ return {
1612
+ quantity: 1,
1613
+ item_brand: isPDP2 ? item.brand : (_c = item.brand.name) != null ? _c : null,
1614
+ item_name: isPDP2 ? item.productName : (_d = item.name) != null ? _d : null,
1615
+ price: price != null ? price : null,
1616
+ discount: Number(listPrice) - Number(price),
1617
+ item_variant: isPDP2 ? (_f = (_e = item.items[0]) == null ? void 0 : _e.name) == null ? void 0 : _f.split(" - ")[0] : (_i = (_h = (_g = item.isVariantOf) == null ? void 0 : _g.hasVariant) == null ? void 0 : _h[0].name.split(" - ")[0]) != null ? _i : null,
1618
+ item_variant2: isPDP2 ? (_k = (_j = item.items[0]) == null ? void 0 : _j.name) == null ? void 0 : _k.split(" - ")[1] : (_m = (_l = item.additionalProperty.find((p) => p.name === "Tamanho")) == null ? void 0 : _l.value) != null ? _m : null,
1619
+ item_ref: isPDP2 ? item.productReference : null,
1620
+ // sem ref no retorno do IS na multi-lib produtos PDC
1621
+ item_category: getItemCategory5(item),
1622
+ item_category2: (_n = getItemCategory22(item)) != null ? _n : null,
1623
+ item_id: isPDP2 ? item == null ? void 0 : item.productId : (_o = item.isVariantOf.productGroupID) != null ? _o : null,
1624
+ item_sku: isPDP2 ? (_p = item.items) == null ? void 0 : _p[0].itemId : (_q = item.sku) != null ? _q : null,
1625
+ item_url: isPDP2 ? item.link : null,
1626
+ // sem link/url no retorno do IS na multi-lib produtos PDC
1627
+ image_url: isPDP2 ? resizeVtexImage3((_s = (_r = item == null ? void 0 : item.items) == null ? void 0 : _r[0].images) == null ? void 0 : _s[0].imageUrl) : (_u = resizeVtexImage3((_t = item == null ? void 0 : item.image) == null ? void 0 : _t[0].url)) != null ? _u : null,
1628
+ seller_id: isPDP2 ? (_x = (_w = (_v = item.items) == null ? void 0 : _v[0]) == null ? void 0 : _w.sellers) == null ? void 0 : _x[0].sellerId : (_C = (_B = (_A = (_z = (_y = item.offers) == null ? void 0 : _y.offers) == null ? void 0 : _z.find((o) => o.availability)) == null ? void 0 : _A.seller) == null ? void 0 : _B.identifier) != null ? _C : null,
1629
+ item_list_name: ""
1630
+ };
1631
+ });
1632
+ }
1633
+ return null;
1634
+ },
1635
+ // legacy/global params TO BE DONE (move to a global file or other adapter)
1636
+ payment_type: getPaymentType,
1637
+ user_info: getUserInfo,
1638
+ // global
1639
+ content_type: (context, eventName) => {
1640
+ if (context == null ? void 0 : context.content_type) return context.content_type;
1641
+ return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
1642
+ },
1643
+ region: (context, eventName) => {
1644
+ return context.region || null;
1645
+ },
1646
+ total_discount: (context, eventName) => {
1647
+ var _a, _b;
1648
+ if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
1649
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1650
+ const items = context.orderForm.items;
1651
+ const totalDiscount = items.reduce((acc, item) => {
1652
+ const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
1653
+ return acc + unitDiscount * item.quantity;
1654
+ }, 0);
1655
+ const discounts = totalsList.find((t) => t.id === "Discounts");
1656
+ return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
1657
+ },
1658
+ subtotal: (context, eventName) => {
1659
+ var _a, _b;
1660
+ const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
1661
+ const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
1662
+ return subtotal;
1663
+ },
1664
+ coupon_message: (context, eventName) => {
1665
+ var _a;
1666
+ if (context.couponMessage) return context.couponMessage;
1667
+ const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
1668
+ if (messages.length === 0) return null;
1669
+ const couponMessages = messages.filter(
1670
+ (msg) => msg.text.toLowerCase().includes("cupom")
1671
+ );
1672
+ if (couponMessages.length === 0) return null;
1673
+ return couponMessages.map((msg) => msg.text).join(" | ");
1674
+ },
1675
+ seller_cod_name: (context, eventName) => {
1676
+ return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
1677
+ },
1678
+ coupon: (context, eventName) => {
1679
+ var _a, _b;
1680
+ return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
1681
+ },
1682
+ pre_filled: (context, eventName) => {
1683
+ return !!context.preFilled;
1684
+ },
1685
+ search_term: (context, eventName) => {
1686
+ return context.searchTerm || null;
1687
+ },
1688
+ search_found: (context, eventName) => {
1689
+ return !!context.searchFound;
1690
+ },
1691
+ search_quantity: (context, eventName) => {
1692
+ return context.searchQuantity || 0;
1693
+ },
1694
+ promotion_name: (context, eventName) => {
1695
+ return context.promotionName || null;
1696
+ },
1697
+ creative_name: (context, eventName) => {
1698
+ return context.creativeName || null;
1699
+ },
1700
+ creative_slot: (context, eventName) => {
1701
+ return context.creativeSlot || null;
1702
+ },
1703
+ zipcode: (context, eventName) => {
1704
+ return context.zipCode || null;
1705
+ },
1706
+ size: (context, eventName) => {
1707
+ return context.size || null;
1708
+ },
1709
+ item_ref: (context, eventName) => {
1710
+ return context.itemRef || null;
1711
+ },
1712
+ flag_pickup: (context, eventName) => {
1713
+ var _a;
1714
+ const orderForm = context.orderForm;
1715
+ if (!orderForm) return null;
1716
+ const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
1717
+ const hasPickup = logisticsInfo.some(
1718
+ (info) => {
1719
+ var _a2;
1720
+ return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
1721
+ }
1722
+ );
1723
+ return hasPickup;
1724
+ },
1725
+ shippings: (context, eventName) => {
1726
+ const orderForm = context.orderForm;
1727
+ if (!orderForm) return null;
1728
+ const groupShipping = {};
1729
+ for (const info of orderForm.shippingData.logisticsInfo) {
1730
+ const item = orderForm.items[info.itemIndex];
1731
+ if (!item) continue;
1732
+ for (const sla of info.slas) {
1733
+ const key = sla.name;
1734
+ if (!groupShipping[key]) {
1735
+ groupShipping[key] = {
1736
+ shipping_tier: sla.name,
1737
+ delivery_time: parseInt(sla.shippingEstimate),
1738
+ shipping: parseFloat((sla.price / 100).toFixed(1)),
1739
+ line_items: []
1740
+ };
1741
+ }
1742
+ groupShipping[key].line_items.push(item.id);
1743
+ }
1744
+ }
1745
+ const shippings = Object.values(groupShipping).map((s) => ({
1746
+ shipping: s.shipping,
1747
+ shipping_tier: s.shipping_tier,
1748
+ delivery_time: s.delivery_time,
1749
+ line_items: s.line_items.join(",")
1750
+ }));
1751
+ return shippings || null;
1752
+ },
1753
+ shipping: (context, eventName) => {
1754
+ var _a, _b, _c;
1755
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1756
+ return logistics.reduce((total, item) => {
1757
+ var _a2, _b2;
1758
+ const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
1759
+ return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
1760
+ }, 0);
1761
+ },
1762
+ shipping_tier: (context, eventName) => {
1763
+ var _a, _b, _c;
1764
+ const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
1765
+ const selectedSlas = logistics.map((item) => {
1766
+ var _a2;
1767
+ if (!item.selectedSla) return null;
1768
+ return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
1769
+ }).filter(Boolean);
1770
+ if (selectedSlas.length === 0) return null;
1771
+ const uniqueTiers = Array.from(
1772
+ new Map(
1773
+ selectedSlas.map((sla) => {
1774
+ var _a2;
1775
+ const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
1776
+ return [key, sla];
1777
+ })
1778
+ ).values()
1779
+ );
1780
+ const sortedTiers = uniqueTiers.sort((a, b) => {
1781
+ var _a2, _b2;
1782
+ const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
1783
+ const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
1784
+ if (aOrder !== bOrder) return aOrder - bOrder;
1785
+ const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
1786
+ const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
1787
+ return aLabel.localeCompare(bLabel, "pt-BR");
1788
+ });
1789
+ const shippingTier = sortedTiers.map((sla) => {
1790
+ var _a2;
1791
+ 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;
1792
+ }).filter(Boolean).join(", ");
1793
+ return shippingTier || null;
1794
+ },
1795
+ transaction_id: (context, eventName) => {
1796
+ var _a, _b;
1797
+ return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
1798
+ },
1799
+ method: (context, eventName) => {
1800
+ return context.method || null;
1801
+ },
1802
+ type: (context, eventName) => {
1803
+ return context.type || null;
1804
+ }
1805
+ };
1806
+ var getItemCategory5 = (item) => {
1807
+ const keywords = ["outlet", "bazar", "sale"];
1808
+ const regex = new RegExp(keywords.join("|"), "i");
1809
+ const value = item == null ? void 0 : item.categories;
1810
+ if (value) {
1811
+ const textToTest = Array.isArray(value) ? value.join(" ") : String(value);
1812
+ const match = textToTest.match(regex);
1813
+ if (match) {
1814
+ return match[0].toLowerCase();
1815
+ }
1816
+ }
1817
+ return "Cole\xE7\xE3o";
1818
+ };
1819
+ var getItemCategory22 = (item) => {
1820
+ var _a, _b, _c;
1821
+ const avoidList = /outlet|bazar|sale/i;
1822
+ const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
1823
+ const categoryHierarchy = lastCategory.split("/").filter(Boolean);
1824
+ const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
1825
+ return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
1826
+ };
1827
+ function resizeVtexImage3(url, width = 500, height = 500) {
1828
+ return url == null ? void 0 : url.replace(
1829
+ /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1830
+ `$1-${width}-${height}/`
1831
+ );
1832
+ }
1833
+
1834
+ // src/formatter.ts
1835
+ var adapters = {
1836
+ DECO: decoAdapter,
1837
+ IS: intelligentSearchAdapter
1838
+ };
1315
1839
  async function getParameters(context = {}, eventName) {
1840
+ var _a;
1316
1841
  const eventConfig = EVENTS[eventName];
1317
1842
  if (!eventConfig) return;
1318
- const params = Object.fromEntries(
1319
- await Promise.all(
1320
- eventConfig.requiredParams.map(async (param) => {
1321
- const getter = paramGetters[param];
1322
- if (typeof getter !== "function") {
1323
- console.error(`[DT] Missing paramGetter for param: ${param}`);
1324
- return [param, null];
1325
- }
1326
- return [param, await getter(context, eventName)];
1327
- })
1328
- )
1843
+ const source = context.adapter;
1844
+ const sourceAdapters = (_a = adapters[source]) != null ? _a : paramGetters;
1845
+ const entries = await Promise.all(
1846
+ eventConfig.requiredParams.map(async (param) => {
1847
+ const adapter = sourceAdapters[param];
1848
+ if (typeof adapter !== "function") {
1849
+ console.error(`[DT] Missing adapter "${param}" for source "${source != null ? source : "default"}"`);
1850
+ return [param, null];
1851
+ }
1852
+ return [param, await adapter(context, eventName)];
1853
+ })
1329
1854
  );
1330
- return params;
1855
+ return Object.fromEntries(entries);
1331
1856
  }
1332
1857
 
1333
1858
  // src/index.ts
1334
1859
  async function trackWebEvent(event, context = {}) {
1335
1860
  try {
1336
1861
  const parameters = await getParameters(context, event);
1337
- return await dispatchTrackEvent(
1862
+ return await pushToDataLayer(
1338
1863
  event,
1339
1864
  Object.assign({}, parameters, { window: context.window })
1340
1865
  );