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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mod.js CHANGED
@@ -291,6 +291,18 @@ var EVENTS = {
291
291
  hasEcommerce: false,
292
292
  destinations: ["DataLayer"],
293
293
  requiredParams: ["brand", "line_items", "size", "item_ref"]
294
+ },
295
+ REFINE_RESULTS: {
296
+ name: "refine_results",
297
+ hasEcommerce: false,
298
+ destinations: ["DataLayer"],
299
+ requiredParams: ["brand", "region", "color", "price_range", "size", "category", "ordering"]
300
+ },
301
+ GRID_SIZE: {
302
+ name: "grid_size",
303
+ hasEcommerce: false,
304
+ destinations: ["DataLayer"],
305
+ requiredParams: ["brand", "slot_per_line"]
294
306
  }
295
307
  };
296
308
 
@@ -1107,7 +1119,7 @@ async function getUserInfo(context) {
1107
1119
  }
1108
1120
 
1109
1121
  // src/params/legacy/index.ts
1110
- var paramGetters = {
1122
+ var legacyGetters = {
1111
1123
  brand: getBrand,
1112
1124
  items: getItems,
1113
1125
  payment_type: getPaymentType,
@@ -1315,8 +1327,7 @@ var metaAdapters = {
1315
1327
  return context.meta.brand || null;
1316
1328
  },
1317
1329
  content_type: (context) => {
1318
- if (context == null ? void 0 : context.content_type) return context.content_type;
1319
- return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
1330
+ return context.meta.content_type || null;
1320
1331
  },
1321
1332
  region: (context) => {
1322
1333
  return context.meta.region || null;
@@ -1328,14 +1339,18 @@ var metaAdapters = {
1328
1339
  if (context == null ? void 0 : context.currency) return context.currency;
1329
1340
  return "BRL";
1330
1341
  },
1342
+ slot_per_line: (context) => {
1343
+ var _a;
1344
+ return (_a = context.meta.slot_per_line) != null ? _a : null;
1345
+ },
1331
1346
  search_term: (context) => {
1332
- return context.searchTerm || null;
1347
+ return context.meta.search_term || null;
1333
1348
  },
1334
1349
  search_found: (context) => {
1335
- return !!context.searchFound;
1350
+ return context.meta.search_found || null;
1336
1351
  },
1337
1352
  search_quantity: (context) => {
1338
- return context.searchQuantity || 0;
1353
+ return context.meta.search_quantity || 0;
1339
1354
  },
1340
1355
  promotion_name: (context) => {
1341
1356
  return context.meta.promotion_name || null;
@@ -1346,9 +1361,6 @@ var metaAdapters = {
1346
1361
  creative_slot: (context) => {
1347
1362
  return context.meta.creative_slot || null;
1348
1363
  },
1349
- zipcode: (context) => {
1350
- return context.zipCode || null;
1351
- },
1352
1364
  size: (context) => {
1353
1365
  return context.size || null;
1354
1366
  },
@@ -1360,6 +1372,135 @@ var metaAdapters = {
1360
1372
  },
1361
1373
  type: (context) => {
1362
1374
  return context.type || null;
1375
+ },
1376
+ color: (context) => {
1377
+ return context.meta.color || null;
1378
+ },
1379
+ price_range: (context) => {
1380
+ return context.meta.price_range || null;
1381
+ },
1382
+ category: (context) => {
1383
+ return context.meta.category || null;
1384
+ },
1385
+ ordering: (context) => {
1386
+ return context.meta.ordering || null;
1387
+ }
1388
+ };
1389
+
1390
+ // src/params/adapters/deco/utils.ts
1391
+ var getItemCategory3 = (item) => {
1392
+ var _a;
1393
+ const value = item == null ? void 0 : item.category;
1394
+ if (!value) return "Cole\xE7\xE3o";
1395
+ const text = Array.isArray(value) ? value.join(" ") : String(value);
1396
+ const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1397
+ return match != null ? match : "Cole\xE7\xE3o";
1398
+ };
1399
+ var getItemCategory22 = (item) => {
1400
+ var _a, _b, _c, _d;
1401
+ const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
1402
+ const categories = (_b = (_a = item.category) == null ? void 0 : _a.split(">")) != null ? _b : [];
1403
+ const last = (_c = categories[categories.length - 1]) != null ? _c : "";
1404
+ const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES.test(c));
1405
+ const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1406
+ return capitalize(deepest);
1407
+ };
1408
+ var resizeVtexImage2 = (url, width = 500, height = 500) => {
1409
+ return url == null ? void 0 : url.replace(
1410
+ /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1411
+ `$1-${width}-${height}/`
1412
+ );
1413
+ };
1414
+ function getItemShippingTier2() {
1415
+ return null;
1416
+ }
1417
+
1418
+ // src/params/adapters/deco/index.ts
1419
+ var IN_STOCK_SCHEMA = "https://schema.org/InStock";
1420
+ var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
1421
+ var decoAdapter = {
1422
+ ...metaAdapters,
1423
+ // global adapters
1424
+ items: (context) => {
1425
+ if (context == null ? void 0 : context.items) return context.items;
1426
+ if (context == null ? void 0 : context.products) {
1427
+ return context.products.map((item) => {
1428
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
1429
+ const COLOR_REGEX = /^[^_]+_/;
1430
+ const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
1431
+ (s) => s.priceType === LIST_PRICE_SCHEMA
1432
+ )) == null ? void 0 : _c.price;
1433
+ return {
1434
+ quantity: 1,
1435
+ index: (_d = item == null ? void 0 : item.index) != null ? _d : 0,
1436
+ item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
1437
+ item_name: (_h = item.alternateName) != null ? _h : null,
1438
+ price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
1439
+ discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
1440
+ item_variant: ((_m = (_l = item == null ? void 0 : item.name) == null ? void 0 : _l.split(" - ")[0]) == null ? void 0 : _m.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
1441
+ // cor
1442
+ item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
1443
+ // tamanho
1444
+ item_shipping_tier: getItemShippingTier2(),
1445
+ item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
1446
+ item_category: (_s = getItemCategory3(item)) != null ? _s : null,
1447
+ item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
1448
+ item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
1449
+ item_sku: (_v = item.sku) != null ? _v : null,
1450
+ item_url: (_w = item.url) != null ? _w : null,
1451
+ image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
1452
+ seller_id: (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) != null ? _C : null,
1453
+ item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
1454
+ };
1455
+ });
1456
+ }
1457
+ return null;
1458
+ },
1459
+ // brand: (context: DecoBrandContext) => {
1460
+ // if (context?.brand) return context.brand
1461
+ // if (context?.products) {
1462
+ // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1463
+ // }
1464
+ // return null
1465
+ // },
1466
+ line_items: (context) => {
1467
+ if (context == null ? void 0 : context.line_items) return context.line_items;
1468
+ if (context == null ? void 0 : context.products) {
1469
+ return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
1470
+ }
1471
+ return null;
1472
+ },
1473
+ value: (context) => {
1474
+ if (context == null ? void 0 : context.value) return context.value;
1475
+ if (context == null ? void 0 : context.products) {
1476
+ return context.products.map((item) => {
1477
+ var _a;
1478
+ return (_a = item.offers) == null ? void 0 : _a.lowPrice;
1479
+ }).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1480
+ }
1481
+ return null;
1482
+ },
1483
+ available_grid: (context) => {
1484
+ if (context == null ? void 0 : context.available_grid) return context.available_grid;
1485
+ if (context == null ? void 0 : context.products) {
1486
+ const sizes = context.products.flatMap(
1487
+ (product) => {
1488
+ var _a, _b, _c;
1489
+ return (_c = (_b = (_a = product.isVariantOf) == null ? void 0 : _a.hasVariant) == null ? void 0 : _b.filter(
1490
+ (variant) => {
1491
+ var _a2, _b2;
1492
+ return (_b2 = (_a2 = variant.offers) == null ? void 0 : _a2.offers) == null ? void 0 : _b2.some((o) => o.availability === IN_STOCK_SCHEMA);
1493
+ }
1494
+ ).map((variant) => {
1495
+ var _a2;
1496
+ return (_a2 = variant.name) == null ? void 0 : _a2.split(" - ")[1];
1497
+ }).filter((name) => Boolean(name))) != null ? _c : [];
1498
+ }
1499
+ );
1500
+ const result = sortSizes(sizes).join(",").trim();
1501
+ return result || null;
1502
+ }
1503
+ return null;
1363
1504
  }
1364
1505
  };
1365
1506
 
@@ -1492,126 +1633,7 @@ var orderFormAdapters = {
1492
1633
  }
1493
1634
  };
1494
1635
 
1495
- // src/params/adapters/deco/utils/index.ts
1496
- var getItemCategory3 = (item) => {
1497
- var _a;
1498
- const value = item == null ? void 0 : item.category;
1499
- if (!value) return "Cole\xE7\xE3o";
1500
- const text = Array.isArray(value) ? value.join(" ") : String(value);
1501
- const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
1502
- return match != null ? match : "Cole\xE7\xE3o";
1503
- };
1504
- var getItemCategory22 = (item) => {
1505
- var _a, _b, _c, _d;
1506
- const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
1507
- const categories = (_b = (_a = item.category) == null ? void 0 : _a.split(">")) != null ? _b : [];
1508
- const last = (_c = categories[categories.length - 1]) != null ? _c : "";
1509
- const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES.test(c));
1510
- const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
1511
- return capitalize(deepest);
1512
- };
1513
- var resizeVtexImage2 = (url, width = 500, height = 500) => {
1514
- return url == null ? void 0 : url.replace(
1515
- /(\/arquivos\/ids\/\d+)-\d+-\d+\//,
1516
- `$1-${width}-${height}/`
1517
- );
1518
- };
1519
- function getItemShippingTier2() {
1520
- return null;
1521
- }
1522
-
1523
- // src/params/adapters/deco/index.ts
1524
- var IN_STOCK_SCHEMA = "https://schema.org/InStock";
1525
- var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
1526
- var decoAdapter = {
1527
- ...metaAdapters,
1528
- // global adapters
1529
- ...orderFormAdapters,
1530
- // orderform adapters
1531
- items: (context) => {
1532
- if (context == null ? void 0 : context.items) return context.items;
1533
- if (context == null ? void 0 : context.products) {
1534
- return context.products.map((item) => {
1535
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
1536
- const COLOR_REGEX = /^[^_]+_/;
1537
- const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
1538
- (s) => s.priceType === LIST_PRICE_SCHEMA
1539
- )) == null ? void 0 : _c.price;
1540
- return {
1541
- quantity: 1,
1542
- index: (_d = item == null ? void 0 : item.index) != null ? _d : 0,
1543
- item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
1544
- item_name: (_h = item.alternateName) != null ? _h : null,
1545
- price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
1546
- discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
1547
- item_variant: ((_m = (_l = item == null ? void 0 : item.name) == null ? void 0 : _l.split(" - ")[0]) == null ? void 0 : _m.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
1548
- // cor
1549
- item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
1550
- // tamanho
1551
- item_shipping_tier: getItemShippingTier2(),
1552
- item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
1553
- item_category: (_s = getItemCategory3(item)) != null ? _s : null,
1554
- item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
1555
- item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
1556
- item_sku: (_v = item.sku) != null ? _v : null,
1557
- item_url: (_w = item.url) != null ? _w : null,
1558
- image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
1559
- seller_id: (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) != null ? _C : null,
1560
- item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
1561
- };
1562
- });
1563
- }
1564
- return null;
1565
- },
1566
- // brand: (context: DecoBrandContext) => {
1567
- // if (context?.brand) return context.brand
1568
- // if (context?.products) {
1569
- // return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
1570
- // }
1571
- // return null
1572
- // },
1573
- line_items: (context) => {
1574
- if (context == null ? void 0 : context.line_items) return context.line_items;
1575
- if (context == null ? void 0 : context.products) {
1576
- return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
1577
- }
1578
- return null;
1579
- },
1580
- value: (context) => {
1581
- if (context == null ? void 0 : context.value) return context.value;
1582
- if (context == null ? void 0 : context.products) {
1583
- return context.products.map((item) => {
1584
- var _a;
1585
- return (_a = item.offers) == null ? void 0 : _a.lowPrice;
1586
- }).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
1587
- }
1588
- return null;
1589
- },
1590
- available_grid: (context) => {
1591
- if (context == null ? void 0 : context.available_grid) return context.available_grid;
1592
- if (context == null ? void 0 : context.products) {
1593
- const sizes = context.products.flatMap(
1594
- (product) => {
1595
- var _a, _b, _c;
1596
- return (_c = (_b = (_a = product.isVariantOf) == null ? void 0 : _a.hasVariant) == null ? void 0 : _b.filter(
1597
- (variant) => {
1598
- var _a2, _b2;
1599
- return (_b2 = (_a2 = variant.offers) == null ? void 0 : _a2.offers) == null ? void 0 : _b2.some((o) => o.availability === IN_STOCK_SCHEMA);
1600
- }
1601
- ).map((variant) => {
1602
- var _a2;
1603
- return (_a2 = variant.name) == null ? void 0 : _a2.split(" - ")[1];
1604
- }).filter((name) => Boolean(name))) != null ? _c : [];
1605
- }
1606
- );
1607
- const result = sortSizes(sizes).join(",").trim();
1608
- return result || null;
1609
- }
1610
- return null;
1611
- }
1612
- };
1613
-
1614
- // src/params/adapters/headless/utils/index.ts
1636
+ // src/params/adapters/headless/utils.ts
1615
1637
  var getItemCategory5 = (item) => {
1616
1638
  const keywords = ["outlet", "bazar", "sale"];
1617
1639
  const regex = new RegExp(keywords.join("|"), "i");
@@ -1810,17 +1832,62 @@ var headlessAdapter = {
1810
1832
  }
1811
1833
  };
1812
1834
 
1835
+ // src/params/adapters/pickup/utils.ts
1836
+ var getShippingTier = (sla) => {
1837
+ var _a, _b;
1838
+ const isPickup = sla.deliveryChannel === "pickup-in-point" /* PickupInPoint */;
1839
+ if (isPickup) {
1840
+ const storeName = (_b = (_a = sla.pickupStoreInfo) == null ? void 0 : _a.friendlyName) == null ? void 0 : _b.trim();
1841
+ return storeName ? `retirada em loja: ${storeName}` : "retirada em loja";
1842
+ }
1843
+ return sla.name ? `receba em casa: ${sla.name.toLowerCase()}` : "receba em casa";
1844
+ };
1845
+ var getDeliveryTime = (sla) => {
1846
+ const estimate = sla.shippingEstimate;
1847
+ if (!estimate) return 0;
1848
+ const days = parseInt(estimate, 10);
1849
+ return isNaN(days) ? 0 : days;
1850
+ };
1851
+
1852
+ // src/params/adapters/pickup/index.ts
1853
+ var pickupAdapter = {
1854
+ ...metaAdapters,
1855
+ flag_pickup: (context) => {
1856
+ var _a;
1857
+ return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
1858
+ },
1859
+ shippings: (context) => {
1860
+ if (context.shippings) {
1861
+ return context.shippings.map((s) => {
1862
+ var _a, _b;
1863
+ return {
1864
+ line_items: (_a = s.line_items) != null ? _a : "",
1865
+ shipping: (_b = s.price) != null ? _b : 0,
1866
+ shipping_tier: getShippingTier(s),
1867
+ delivery_time: getDeliveryTime(s)
1868
+ };
1869
+ });
1870
+ }
1871
+ return null;
1872
+ },
1873
+ zipcode: (context) => {
1874
+ var _a;
1875
+ return (_a = context.zipcode) != null ? _a : null;
1876
+ }
1877
+ };
1878
+
1813
1879
  // src/formatter.ts
1814
1880
  var adapters = {
1815
1881
  DECO: decoAdapter,
1816
- HEADLESS: headlessAdapter
1882
+ HEADLESS: headlessAdapter,
1883
+ PICKUP: pickupAdapter
1817
1884
  };
1818
1885
  async function getParameters(context, eventName) {
1819
1886
  var _a;
1820
1887
  const eventConfig = EVENTS[eventName];
1821
1888
  if (!eventConfig) return;
1822
1889
  const currentAdapter = context.adapter;
1823
- const getters = (_a = adapters[currentAdapter]) != null ? _a : paramGetters;
1890
+ const getters = (_a = adapters[currentAdapter]) != null ? _a : legacyGetters;
1824
1891
  const entries = await Promise.all(
1825
1892
  eventConfig.requiredParams.map(async (param) => {
1826
1893
  const getter = getters[param];