@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.
- package/dist/mod.cjs +646 -128
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +1028 -217
- package/dist/mod.d.ts +1028 -217
- package/dist/mod.global.js +646 -128
- package/dist/mod.global.js.map +1 -1
- package/dist/mod.js +646 -128
- package/dist/mod.js.map +1 -1
- package/dist/mod.vtex.global.js +751 -164
- package/package.json +2 -2
package/dist/mod.cjs
CHANGED
|
@@ -142,8 +142,8 @@ var EVENTS = {
|
|
|
142
142
|
"currency",
|
|
143
143
|
"promotion_name",
|
|
144
144
|
"creative_slot",
|
|
145
|
-
"creative_name"
|
|
146
|
-
"items"
|
|
145
|
+
"creative_name"
|
|
146
|
+
// "items",
|
|
147
147
|
]
|
|
148
148
|
},
|
|
149
149
|
SELECT_PROMOTION: {
|
|
@@ -156,8 +156,8 @@ var EVENTS = {
|
|
|
156
156
|
"currency",
|
|
157
157
|
"promotion_name",
|
|
158
158
|
"creative_slot",
|
|
159
|
-
"creative_name"
|
|
160
|
-
"items"
|
|
159
|
+
"creative_name"
|
|
160
|
+
// "items",
|
|
161
161
|
]
|
|
162
162
|
},
|
|
163
163
|
SELECT_CONTENT: {
|
|
@@ -322,7 +322,7 @@ var EVENTS = {
|
|
|
322
322
|
}
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
-
// src/
|
|
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 @@ function pushToDataLayer(event, context) {
|
|
|
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/
|
|
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(
|
|
@@ -602,7 +541,7 @@ function normalizeBrand(input) {
|
|
|
602
541
|
return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
|
|
603
542
|
}
|
|
604
543
|
|
|
605
|
-
// src/params/resolvers/brand/fromOrderForm.ts
|
|
544
|
+
// src/params/legacy/resolvers/brand/fromOrderForm.ts
|
|
606
545
|
function brandFromOrderForm(context) {
|
|
607
546
|
var _a;
|
|
608
547
|
if (!context.orderForm && !((_a = context.orderForm.items) == null ? void 0 : _a.length)) return null;
|
|
@@ -610,14 +549,14 @@ function brandFromOrderForm(context) {
|
|
|
610
549
|
return normalizeBrand(items);
|
|
611
550
|
}
|
|
612
551
|
|
|
613
|
-
// src/params/resolvers/brand/fromItem.ts
|
|
552
|
+
// src/params/legacy/resolvers/brand/fromItem.ts
|
|
614
553
|
function brandFromItem(context) {
|
|
615
554
|
var _a;
|
|
616
555
|
const { item } = context;
|
|
617
556
|
return normalizeBrand(((_a = item == null ? void 0 : item.additionalInfo) == null ? void 0 : _a.brandName) || item.brand || item.item_brand);
|
|
618
557
|
}
|
|
619
558
|
|
|
620
|
-
// src/params/brand.ts
|
|
559
|
+
// src/params/legacy/brand.ts
|
|
621
560
|
function getBrand(context, eventName) {
|
|
622
561
|
if (context == null ? void 0 : context.brand) return normalizeBrand(context.brand) || context.brand || null;
|
|
623
562
|
switch (eventName) {
|
|
@@ -641,7 +580,7 @@ function getBrand(context, eventName) {
|
|
|
641
580
|
}
|
|
642
581
|
}
|
|
643
582
|
|
|
644
|
-
// src/params/utils/itemListAttribution.ts
|
|
583
|
+
// src/params/legacy/utils/itemListAttribution.ts
|
|
645
584
|
var LAST_SELECTED_ITEM_KEY = "last_selected_item";
|
|
646
585
|
var STORAGE_VIEWED = "last_viewed_item";
|
|
647
586
|
var CART_LIST_HISTORY_KEY = "cart_list_history";
|
|
@@ -822,7 +761,7 @@ function persistSelectItemOriginFromResolvedItems(items, source) {
|
|
|
822
761
|
saveSelectedItem(productId, listName);
|
|
823
762
|
}
|
|
824
763
|
|
|
825
|
-
// src/params/resolvers/items/fromOrderForm.ts
|
|
764
|
+
// src/params/legacy/resolvers/items/fromOrderForm.ts
|
|
826
765
|
async function itemsFromOrderForm(context) {
|
|
827
766
|
var _a;
|
|
828
767
|
const items = ((_a = context.orderForm) == null ? void 0 : _a.items) || [];
|
|
@@ -854,7 +793,7 @@ async function itemsFromOrderForm(context) {
|
|
|
854
793
|
);
|
|
855
794
|
}
|
|
856
795
|
|
|
857
|
-
// src/params/resolvers/items/fromItem.ts
|
|
796
|
+
// src/params/legacy/resolvers/items/fromItem.ts
|
|
858
797
|
async function itemsFromItem(context, event) {
|
|
859
798
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
860
799
|
const { item, orderForm, itemListName } = context;
|
|
@@ -890,7 +829,7 @@ async function itemsFromItem(context, event) {
|
|
|
890
829
|
];
|
|
891
830
|
}
|
|
892
831
|
|
|
893
|
-
// src/params/resolvers/items/fromList.ts
|
|
832
|
+
// src/params/legacy/resolvers/items/fromList.ts
|
|
894
833
|
async function itemsFromList(context) {
|
|
895
834
|
return ((context == null ? void 0 : context.list) || []).map((item) => {
|
|
896
835
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
@@ -911,7 +850,7 @@ async function itemsFromList(context) {
|
|
|
911
850
|
});
|
|
912
851
|
}
|
|
913
852
|
|
|
914
|
-
// src/params/resolvers/items/fromPdp.ts
|
|
853
|
+
// src/params/legacy/resolvers/items/fromPdp.ts
|
|
915
854
|
async function itemsFromPDP(context, event) {
|
|
916
855
|
var _a, _b, _c, _d;
|
|
917
856
|
const { item, value, brand } = context;
|
|
@@ -942,7 +881,7 @@ async function itemsFromPDP(context, event) {
|
|
|
942
881
|
];
|
|
943
882
|
}
|
|
944
883
|
|
|
945
|
-
// src/params/resolvers/items/fromBanner.ts
|
|
884
|
+
// src/params/legacy/resolvers/items/fromBanner.ts
|
|
946
885
|
async function itemsFromBanner(context) {
|
|
947
886
|
var _a;
|
|
948
887
|
const isUrlFromPDP = isPDP(context == null ? void 0 : context.bannerUrl);
|
|
@@ -963,7 +902,7 @@ async function itemsFromBanner(context) {
|
|
|
963
902
|
};
|
|
964
903
|
}
|
|
965
904
|
|
|
966
|
-
// src/params/items.ts
|
|
905
|
+
// src/params/legacy/items.ts
|
|
967
906
|
function getItems(context, eventName) {
|
|
968
907
|
if (context == null ? void 0 : context.items) return context.items;
|
|
969
908
|
switch (eventName) {
|
|
@@ -997,7 +936,72 @@ function getItems(context, eventName) {
|
|
|
997
936
|
}
|
|
998
937
|
}
|
|
999
938
|
|
|
1000
|
-
// src/
|
|
939
|
+
// src/core/utils.ts
|
|
940
|
+
var isDebugMode = () => {
|
|
941
|
+
if (typeof window === "undefined") return false;
|
|
942
|
+
try {
|
|
943
|
+
const params = new URLSearchParams(window.location.search);
|
|
944
|
+
return params.has("__trk_inspect__");
|
|
945
|
+
} catch (e) {
|
|
946
|
+
return window.location.search.indexOf("__trk_inspect__") !== -1;
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
var paymentTypeMap = [
|
|
950
|
+
["vale", "vale cr\xE9dito"],
|
|
951
|
+
["pagaleve", "pix"],
|
|
952
|
+
["pix parcel", "pix parcelado"],
|
|
953
|
+
["pix", "pix"],
|
|
954
|
+
["apple", "apple pay"],
|
|
955
|
+
["google", "google pay"],
|
|
956
|
+
["boleto", "boleto"],
|
|
957
|
+
["paypal", "paypal"],
|
|
958
|
+
["cred", "cart\xE3o"],
|
|
959
|
+
["visa", "cart\xE3o"],
|
|
960
|
+
["master", "cart\xE3o"],
|
|
961
|
+
["amex", "cart\xE3o"],
|
|
962
|
+
["elo", "cart\xE3o"],
|
|
963
|
+
["hiper", "cart\xE3o"],
|
|
964
|
+
["diner", "cart\xE3o"],
|
|
965
|
+
["deb", "cart\xE3o"]
|
|
966
|
+
];
|
|
967
|
+
var toNum = (val) => typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
|
|
968
|
+
var documentToHash = async (document2) => {
|
|
969
|
+
if (!document2) return null;
|
|
970
|
+
const encoder = new TextEncoder();
|
|
971
|
+
const data = encoder.encode(document2);
|
|
972
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
973
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
974
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
975
|
+
};
|
|
976
|
+
var SIZE_ORDER = {
|
|
977
|
+
alfabetico: ["PP", "P", "M", "G", "GG", "XG", "XGG", "EG", "EGG", "3G", "4G", "5G"],
|
|
978
|
+
infantil: ["RN", "0-3M", "3-6M", "6-9M", "9-12M", "12-18M", "18-24M", "P", "M", "G", "GG"]
|
|
979
|
+
};
|
|
980
|
+
var detectSizeType = (sizes) => {
|
|
981
|
+
if (sizes.every((s) => /^\d+([.,]\d+)?$/.test(s))) return "numerico";
|
|
982
|
+
if (sizes.some((s) => /^(RN|\d+-\d+M|\d+M)$/i.test(s))) return "infantil";
|
|
983
|
+
if (sizes.every((s) => SIZE_ORDER.alfabetico.includes(s.toUpperCase()))) return "alfabetico";
|
|
984
|
+
return "desconhecido";
|
|
985
|
+
};
|
|
986
|
+
var sortSizes = (sizes) => {
|
|
987
|
+
const unique = [...new Set(sizes.filter(Boolean))];
|
|
988
|
+
const type = detectSizeType(unique);
|
|
989
|
+
if (type === "numerico") {
|
|
990
|
+
return unique.sort((a, b) => parseFloat(a) - parseFloat(b));
|
|
991
|
+
}
|
|
992
|
+
if (type === "alfabetico" || type === "infantil") {
|
|
993
|
+
const order = SIZE_ORDER[type];
|
|
994
|
+
return unique.sort((a, b) => {
|
|
995
|
+
const ia = order.indexOf(a.toUpperCase());
|
|
996
|
+
const ib = order.indexOf(b.toUpperCase());
|
|
997
|
+
return (ia === -1 ? 999 : ia) - (ib === -1 ? 999 : ib);
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
return unique;
|
|
1001
|
+
};
|
|
1002
|
+
var capitalize = (str) => str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
|
|
1003
|
+
|
|
1004
|
+
// src/params/legacy/resolvers/paymentType/fromOrderForm.ts
|
|
1001
1005
|
function paymentTypeFromOrderForm(context) {
|
|
1002
1006
|
var _a, _b, _c;
|
|
1003
1007
|
if (context.payment_type) return context.payment_type;
|
|
@@ -1014,7 +1018,7 @@ function paymentTypeFromOrderForm(context) {
|
|
|
1014
1018
|
return match ? match[1] : null;
|
|
1015
1019
|
}
|
|
1016
1020
|
|
|
1017
|
-
// src/params/resolvers/paymentType/fromOrderGroup.ts
|
|
1021
|
+
// src/params/legacy/resolvers/paymentType/fromOrderGroup.ts
|
|
1018
1022
|
function paymentTypeFromOrderGroup(context) {
|
|
1019
1023
|
var _a, _b, _c, _d;
|
|
1020
1024
|
if (!context.orderForm) return null;
|
|
@@ -1027,7 +1031,7 @@ function paymentTypeFromOrderGroup(context) {
|
|
|
1027
1031
|
return match ? match[1] : null;
|
|
1028
1032
|
}
|
|
1029
1033
|
|
|
1030
|
-
// src/params/paymentType.ts
|
|
1034
|
+
// src/params/legacy/paymentType.ts
|
|
1031
1035
|
function getPaymentType(context, eventName) {
|
|
1032
1036
|
if (context == null ? void 0 : context.paymentType) return context.paymentType;
|
|
1033
1037
|
switch (eventName) {
|
|
@@ -1043,36 +1047,36 @@ function getPaymentType(context, eventName) {
|
|
|
1043
1047
|
}
|
|
1044
1048
|
|
|
1045
1049
|
// src/params/userInfo.ts
|
|
1046
|
-
|
|
1050
|
+
var PROD_DOMAINS = {
|
|
1051
|
+
"animale": {
|
|
1052
|
+
"store": "https://www.animale.com.br",
|
|
1053
|
+
"checkout": "https://secure.animale.com.br"
|
|
1054
|
+
},
|
|
1055
|
+
"farm": {
|
|
1056
|
+
"store": "https://lojafarm.myvtex.com"
|
|
1057
|
+
},
|
|
1058
|
+
"mariafilo": {
|
|
1059
|
+
"store": "https://mariafilo.myvtex.com",
|
|
1060
|
+
"checkout": "https://secure.mariafilo.com.br"
|
|
1061
|
+
},
|
|
1062
|
+
"lojacrisbarros": {
|
|
1063
|
+
"store": "https://lojacrisbarros.myvtex.com",
|
|
1064
|
+
"checkout": "https://secure.crisbarros.com.br"
|
|
1065
|
+
},
|
|
1066
|
+
"lojaoffpremium": {
|
|
1067
|
+
"store": "https://lojaoffpremium.myvtex.com",
|
|
1068
|
+
"checkout": "https://secure.offpremium.com.br"
|
|
1069
|
+
},
|
|
1070
|
+
"bynv": {
|
|
1071
|
+
"store": "https://bynv.myvtex.com"
|
|
1072
|
+
},
|
|
1073
|
+
"fabula": {
|
|
1074
|
+
"store": "https://lojafabula.myvtex.com"
|
|
1075
|
+
}
|
|
1076
|
+
};
|
|
1077
|
+
async function getUserInfo(context) {
|
|
1047
1078
|
var _a, _b, _c, _d, _e;
|
|
1048
|
-
const
|
|
1049
|
-
"animale": {
|
|
1050
|
-
"store": "https://www.animale.com.br",
|
|
1051
|
-
"checkout": "https://secure.animale.com.br"
|
|
1052
|
-
},
|
|
1053
|
-
"farm": {
|
|
1054
|
-
"store": "https://lojafarm.myvtex.com"
|
|
1055
|
-
},
|
|
1056
|
-
"mariafilo": {
|
|
1057
|
-
"store": "https://mariafilo.myvtex.com",
|
|
1058
|
-
"checkout": "https://secure.mariafilo.com.br"
|
|
1059
|
-
},
|
|
1060
|
-
"lojacrisbarros": {
|
|
1061
|
-
"store": "https://lojacrisbarros.myvtex.com",
|
|
1062
|
-
"checkout": "https://secure.crisbarros.com.br"
|
|
1063
|
-
},
|
|
1064
|
-
"lojaoffpremium": {
|
|
1065
|
-
"store": "https://lojaoffpremium.myvtex.com",
|
|
1066
|
-
"checkout": "https://secure.offpremium.com.br"
|
|
1067
|
-
},
|
|
1068
|
-
"bynv": {
|
|
1069
|
-
"store": "https://bynv.myvtex.com"
|
|
1070
|
-
},
|
|
1071
|
-
"fabula": {
|
|
1072
|
-
"store": "https://lojafabula.myvtex.com"
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
const domain = (_a = PROD_DOMAINS[context.account || "https://www.animale.com.br"]) == null ? void 0 : _a[context.platform || "store"];
|
|
1079
|
+
const domain = (_a = PROD_DOMAINS[context.account || "animale"]) == null ? void 0 : _a[context.platform || "store"];
|
|
1076
1080
|
if (!domain) return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
|
|
1077
1081
|
try {
|
|
1078
1082
|
const api = `${domain}/_v/user-info`;
|
|
@@ -1130,12 +1134,13 @@ async function getUserInfo(context, eventName) {
|
|
|
1130
1134
|
}
|
|
1131
1135
|
}
|
|
1132
1136
|
|
|
1133
|
-
// src/params/index.ts
|
|
1137
|
+
// src/params/legacy/index.ts
|
|
1134
1138
|
var paramGetters = {
|
|
1135
1139
|
brand: getBrand,
|
|
1136
1140
|
items: getItems,
|
|
1137
1141
|
payment_type: getPaymentType,
|
|
1138
1142
|
user_info: getUserInfo,
|
|
1143
|
+
// global
|
|
1139
1144
|
content_type: (context, eventName) => {
|
|
1140
1145
|
if (context == null ? void 0 : context.content_type) return context.content_type;
|
|
1141
1146
|
return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
|
|
@@ -1331,30 +1336,543 @@ var paramGetters = {
|
|
|
1331
1336
|
}
|
|
1332
1337
|
};
|
|
1333
1338
|
|
|
1334
|
-
// src/
|
|
1335
|
-
|
|
1339
|
+
// src/params/adapters/meta/index.ts
|
|
1340
|
+
var metaAdapters = {
|
|
1341
|
+
user_info: getUserInfo,
|
|
1342
|
+
brand: (context) => {
|
|
1343
|
+
return context.meta.brand || null;
|
|
1344
|
+
},
|
|
1345
|
+
content_type: (context) => {
|
|
1346
|
+
if (context == null ? void 0 : context.content_type) return context.content_type;
|
|
1347
|
+
return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
|
|
1348
|
+
},
|
|
1349
|
+
region: (context) => {
|
|
1350
|
+
return context.meta.region || null;
|
|
1351
|
+
},
|
|
1352
|
+
pre_filled: (context) => {
|
|
1353
|
+
return !!context.preFilled;
|
|
1354
|
+
},
|
|
1355
|
+
currency: (context) => {
|
|
1356
|
+
if (context == null ? void 0 : context.currency) return context.currency;
|
|
1357
|
+
return "BRL";
|
|
1358
|
+
},
|
|
1359
|
+
search_term: (context) => {
|
|
1360
|
+
return context.searchTerm || null;
|
|
1361
|
+
},
|
|
1362
|
+
search_found: (context) => {
|
|
1363
|
+
return !!context.searchFound;
|
|
1364
|
+
},
|
|
1365
|
+
search_quantity: (context) => {
|
|
1366
|
+
return context.searchQuantity || 0;
|
|
1367
|
+
},
|
|
1368
|
+
promotion_name: (context) => {
|
|
1369
|
+
return context.meta.promotion_name || null;
|
|
1370
|
+
},
|
|
1371
|
+
creative_name: (context) => {
|
|
1372
|
+
return context.meta.creative_name || null;
|
|
1373
|
+
},
|
|
1374
|
+
creative_slot: (context) => {
|
|
1375
|
+
return context.meta.creative_slot || null;
|
|
1376
|
+
},
|
|
1377
|
+
zipcode: (context) => {
|
|
1378
|
+
return context.zipCode || null;
|
|
1379
|
+
},
|
|
1380
|
+
size: (context) => {
|
|
1381
|
+
return context.size || null;
|
|
1382
|
+
},
|
|
1383
|
+
item_ref: (context) => {
|
|
1384
|
+
return context.itemRef || null;
|
|
1385
|
+
},
|
|
1386
|
+
method: (context) => {
|
|
1387
|
+
return context.method || null;
|
|
1388
|
+
},
|
|
1389
|
+
type: (context) => {
|
|
1390
|
+
return context.type || null;
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
// src/params/adapters/orderForm/index.ts
|
|
1395
|
+
var orderFormAdapters = {
|
|
1396
|
+
// orderform
|
|
1397
|
+
payment_type: getPaymentType,
|
|
1398
|
+
total_discount: (context) => {
|
|
1399
|
+
var _a, _b;
|
|
1400
|
+
if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
|
|
1401
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1402
|
+
const items = context.orderForm.items;
|
|
1403
|
+
const totalDiscount = items.reduce((acc, item) => {
|
|
1404
|
+
const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
1405
|
+
return acc + unitDiscount * item.quantity;
|
|
1406
|
+
}, 0);
|
|
1407
|
+
const discounts = totalsList.find((t) => t.id === "Discounts");
|
|
1408
|
+
return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
1409
|
+
},
|
|
1410
|
+
subtotal: (context) => {
|
|
1411
|
+
var _a, _b;
|
|
1412
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1413
|
+
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
1414
|
+
return subtotal;
|
|
1415
|
+
},
|
|
1416
|
+
coupon_message: (context) => {
|
|
1417
|
+
var _a;
|
|
1418
|
+
if (context.couponMessage) return context.couponMessage;
|
|
1419
|
+
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
1420
|
+
if (messages.length === 0) return null;
|
|
1421
|
+
const couponMessages = messages.filter(
|
|
1422
|
+
(msg) => msg.text.toLowerCase().includes("cupom")
|
|
1423
|
+
);
|
|
1424
|
+
if (couponMessages.length === 0) return null;
|
|
1425
|
+
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
1426
|
+
},
|
|
1427
|
+
flag_pickup: (context) => {
|
|
1428
|
+
var _a;
|
|
1429
|
+
const orderForm = context.orderForm;
|
|
1430
|
+
if (!orderForm) return null;
|
|
1431
|
+
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
1432
|
+
const hasPickup = logisticsInfo.some(
|
|
1433
|
+
(info) => {
|
|
1434
|
+
var _a2;
|
|
1435
|
+
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
1436
|
+
}
|
|
1437
|
+
);
|
|
1438
|
+
return hasPickup;
|
|
1439
|
+
},
|
|
1440
|
+
shippings: (context) => {
|
|
1441
|
+
const orderForm = context.orderForm;
|
|
1442
|
+
if (!orderForm) return null;
|
|
1443
|
+
const groupShipping = {};
|
|
1444
|
+
for (const info of orderForm.shippingData.logisticsInfo) {
|
|
1445
|
+
const item = orderForm.items[info.itemIndex];
|
|
1446
|
+
if (!item) continue;
|
|
1447
|
+
for (const sla of info.slas) {
|
|
1448
|
+
const key = sla.name;
|
|
1449
|
+
if (!groupShipping[key]) {
|
|
1450
|
+
groupShipping[key] = {
|
|
1451
|
+
shipping_tier: sla.name,
|
|
1452
|
+
delivery_time: parseInt(sla.shippingEstimate),
|
|
1453
|
+
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
1454
|
+
line_items: []
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
groupShipping[key].line_items.push(item.id);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
const shippings = Object.values(groupShipping).map((s) => ({
|
|
1461
|
+
shipping: s.shipping,
|
|
1462
|
+
shipping_tier: s.shipping_tier,
|
|
1463
|
+
delivery_time: s.delivery_time,
|
|
1464
|
+
line_items: s.line_items.join(",")
|
|
1465
|
+
}));
|
|
1466
|
+
return shippings || null;
|
|
1467
|
+
},
|
|
1468
|
+
shipping: (context) => {
|
|
1469
|
+
var _a, _b, _c;
|
|
1470
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1471
|
+
return logistics.reduce((total, item) => {
|
|
1472
|
+
var _a2, _b2;
|
|
1473
|
+
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
1474
|
+
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
1475
|
+
}, 0);
|
|
1476
|
+
},
|
|
1477
|
+
shipping_tier: (context) => {
|
|
1478
|
+
var _a, _b, _c;
|
|
1479
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1480
|
+
const selectedSlas = logistics.map((item) => {
|
|
1481
|
+
var _a2;
|
|
1482
|
+
if (!item.selectedSla) return null;
|
|
1483
|
+
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
1484
|
+
}).filter(Boolean);
|
|
1485
|
+
if (selectedSlas.length === 0) return null;
|
|
1486
|
+
const uniqueTiers = Array.from(
|
|
1487
|
+
new Map(
|
|
1488
|
+
selectedSlas.map((sla) => {
|
|
1489
|
+
var _a2;
|
|
1490
|
+
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
1491
|
+
return [key, sla];
|
|
1492
|
+
})
|
|
1493
|
+
).values()
|
|
1494
|
+
);
|
|
1495
|
+
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
1496
|
+
var _a2, _b2;
|
|
1497
|
+
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1498
|
+
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1499
|
+
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
1500
|
+
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
1501
|
+
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
1502
|
+
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
1503
|
+
});
|
|
1504
|
+
const shippingTier = sortedTiers.map((sla) => {
|
|
1505
|
+
var _a2;
|
|
1506
|
+
return sla.deliveryChannel === "pickup-in-point" ? `retirada em loja${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) ? `: ${sla.pickupStoreInfo.friendlyName}` : ""}` : sla.deliveryChannel === "delivery" ? `receba em casa${sla.name ? `: ${sla.name}` : ""}` : null;
|
|
1507
|
+
}).filter(Boolean).join(", ");
|
|
1508
|
+
return shippingTier || null;
|
|
1509
|
+
},
|
|
1510
|
+
transaction_id: (context) => {
|
|
1511
|
+
var _a, _b;
|
|
1512
|
+
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
1513
|
+
},
|
|
1514
|
+
coupon: (context) => {
|
|
1515
|
+
var _a, _b;
|
|
1516
|
+
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
1517
|
+
},
|
|
1518
|
+
seller_cod_name: (context) => {
|
|
1519
|
+
return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
// src/params/adapters/deco/utils/index.ts
|
|
1524
|
+
var getItemCategory3 = (item) => {
|
|
1525
|
+
var _a;
|
|
1526
|
+
const value = item == null ? void 0 : item.category;
|
|
1527
|
+
if (!value) return "Cole\xE7\xE3o";
|
|
1528
|
+
const text = Array.isArray(value) ? value.join(" ") : String(value);
|
|
1529
|
+
const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
|
|
1530
|
+
return match != null ? match : "Cole\xE7\xE3o";
|
|
1531
|
+
};
|
|
1532
|
+
var getItemCategory22 = (item) => {
|
|
1533
|
+
var _a, _b, _c, _d;
|
|
1534
|
+
const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
|
|
1535
|
+
const categories = (_b = (_a = item.category) == null ? void 0 : _a.split(">")) != null ? _b : [];
|
|
1536
|
+
const last = (_c = categories[categories.length - 1]) != null ? _c : "";
|
|
1537
|
+
const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES.test(c));
|
|
1538
|
+
const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
|
|
1539
|
+
return capitalize(deepest);
|
|
1540
|
+
};
|
|
1541
|
+
var resizeVtexImage2 = (url, width = 500, height = 500) => {
|
|
1542
|
+
return url == null ? void 0 : url.replace(
|
|
1543
|
+
/(\/arquivos\/ids\/\d+)-\d+-\d+\//,
|
|
1544
|
+
`$1-${width}-${height}/`
|
|
1545
|
+
);
|
|
1546
|
+
};
|
|
1547
|
+
function getItemShippingTier2() {
|
|
1548
|
+
return null;
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
// src/params/adapters/deco/index.ts
|
|
1552
|
+
var IN_STOCK_SCHEMA = "https://schema.org/InStock";
|
|
1553
|
+
var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
|
|
1554
|
+
var decoAdapter = {
|
|
1555
|
+
...metaAdapters,
|
|
1556
|
+
// global adapters
|
|
1557
|
+
...orderFormAdapters,
|
|
1558
|
+
// orderform adapters
|
|
1559
|
+
items: (context) => {
|
|
1560
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1561
|
+
if (context == null ? void 0 : context.products) {
|
|
1562
|
+
return context.products.map((item) => {
|
|
1563
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
|
|
1564
|
+
const COLOR_REGEX = /^[^_]+_/;
|
|
1565
|
+
const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
|
|
1566
|
+
(s) => s.priceType === LIST_PRICE_SCHEMA
|
|
1567
|
+
)) == null ? void 0 : _c.price;
|
|
1568
|
+
return {
|
|
1569
|
+
quantity: 1,
|
|
1570
|
+
index: (_d = item == null ? void 0 : item.index) != null ? _d : 0,
|
|
1571
|
+
item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
|
|
1572
|
+
item_name: (_h = item.alternateName) != null ? _h : null,
|
|
1573
|
+
price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
|
|
1574
|
+
discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
|
|
1575
|
+
item_variant: ((_m = (_l = item == null ? void 0 : item.name) == null ? void 0 : _l.split(" - ")[0]) == null ? void 0 : _m.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
|
|
1576
|
+
// cor
|
|
1577
|
+
item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
|
|
1578
|
+
// tamanho
|
|
1579
|
+
item_shipping_tier: getItemShippingTier2(),
|
|
1580
|
+
item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
|
|
1581
|
+
item_category: (_s = getItemCategory3(item)) != null ? _s : null,
|
|
1582
|
+
item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
|
|
1583
|
+
item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
|
|
1584
|
+
item_sku: (_v = item.sku) != null ? _v : null,
|
|
1585
|
+
item_url: (_w = item.url) != null ? _w : null,
|
|
1586
|
+
image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
|
|
1587
|
+
seller_id: (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) != null ? _C : null,
|
|
1588
|
+
item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
|
|
1589
|
+
};
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
return null;
|
|
1593
|
+
},
|
|
1594
|
+
// brand: (context: DecoBrandContext) => {
|
|
1595
|
+
// if (context?.brand) return context.brand
|
|
1596
|
+
// if (context?.products) {
|
|
1597
|
+
// return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
|
|
1598
|
+
// }
|
|
1599
|
+
// return null
|
|
1600
|
+
// },
|
|
1601
|
+
line_items: (context) => {
|
|
1602
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1603
|
+
if (context == null ? void 0 : context.products) {
|
|
1604
|
+
return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
|
|
1605
|
+
}
|
|
1606
|
+
return null;
|
|
1607
|
+
},
|
|
1608
|
+
value: (context) => {
|
|
1609
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1610
|
+
if (context == null ? void 0 : context.products) {
|
|
1611
|
+
return context.products.map((item) => {
|
|
1612
|
+
var _a;
|
|
1613
|
+
return (_a = item.offers) == null ? void 0 : _a.lowPrice;
|
|
1614
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1615
|
+
}
|
|
1616
|
+
return null;
|
|
1617
|
+
},
|
|
1618
|
+
available_grid: (context) => {
|
|
1619
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1620
|
+
if (context == null ? void 0 : context.products) {
|
|
1621
|
+
const sizes = context.products.flatMap(
|
|
1622
|
+
(product) => {
|
|
1623
|
+
var _a, _b, _c;
|
|
1624
|
+
return (_c = (_b = (_a = product.isVariantOf) == null ? void 0 : _a.hasVariant) == null ? void 0 : _b.filter(
|
|
1625
|
+
(variant) => {
|
|
1626
|
+
var _a2, _b2;
|
|
1627
|
+
return (_b2 = (_a2 = variant.offers) == null ? void 0 : _a2.offers) == null ? void 0 : _b2.some((o) => o.availability === IN_STOCK_SCHEMA);
|
|
1628
|
+
}
|
|
1629
|
+
).map((variant) => {
|
|
1630
|
+
var _a2;
|
|
1631
|
+
return (_a2 = variant.name) == null ? void 0 : _a2.split(" - ")[1];
|
|
1632
|
+
}).filter((name) => Boolean(name))) != null ? _c : [];
|
|
1633
|
+
}
|
|
1634
|
+
);
|
|
1635
|
+
const result = sortSizes(sizes).join(",").trim();
|
|
1636
|
+
return result || null;
|
|
1637
|
+
}
|
|
1638
|
+
return null;
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
|
|
1642
|
+
// src/params/adapters/headless/utils/index.ts
|
|
1643
|
+
var getItemCategory5 = (item) => {
|
|
1644
|
+
const keywords = ["outlet", "bazar", "sale"];
|
|
1645
|
+
const regex = new RegExp(keywords.join("|"), "i");
|
|
1646
|
+
const value = item == null ? void 0 : item.categories;
|
|
1647
|
+
if (value) {
|
|
1648
|
+
const textToTest = Array.isArray(value) ? value.join(" ") : String(value);
|
|
1649
|
+
const match = textToTest.match(regex);
|
|
1650
|
+
if (match) {
|
|
1651
|
+
return match[0].toLowerCase();
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return "Cole\xE7\xE3o";
|
|
1655
|
+
};
|
|
1656
|
+
var getItemCategory23 = (item) => {
|
|
1657
|
+
var _a, _b, _c;
|
|
1658
|
+
const avoidList = /outlet|bazar|sale/i;
|
|
1659
|
+
const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
|
|
1660
|
+
const categoryHierarchy = lastCategory.split("/").filter(Boolean);
|
|
1661
|
+
const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
|
|
1662
|
+
return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
|
|
1663
|
+
};
|
|
1664
|
+
function resizeVtexImage3(url, width = 500, height = 500) {
|
|
1665
|
+
return url == null ? void 0 : url.replace(
|
|
1666
|
+
/(\/arquivos\/ids\/\d+)-\d+-\d+\//,
|
|
1667
|
+
`$1-${width}-${height}/`
|
|
1668
|
+
);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// src/params/adapters/headless/zones/PDP.ts
|
|
1672
|
+
var HeadlessPdpZone = {
|
|
1673
|
+
items: (context) => {
|
|
1674
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1675
|
+
if (context == null ? void 0 : context.products) {
|
|
1676
|
+
return context.products.map((item) => {
|
|
1677
|
+
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;
|
|
1678
|
+
const listPrice = (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.ListPrice;
|
|
1679
|
+
const price = (_b = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _b[0].commertialOffer.Price;
|
|
1680
|
+
return {
|
|
1681
|
+
quantity: 1,
|
|
1682
|
+
index: (_c = item == null ? void 0 : item.index) != null ? _c : null,
|
|
1683
|
+
item_brand: (_d = item.brand) != null ? _d : null,
|
|
1684
|
+
item_name: (_e = item.productName) != null ? _e : null,
|
|
1685
|
+
price: price != null ? price : null,
|
|
1686
|
+
discount: Number(listPrice) - Number(price),
|
|
1687
|
+
item_variant: (_h = (_g = (_f = item.items[0]) == null ? void 0 : _f.name) == null ? void 0 : _g.split(" - ")[0]) != null ? _h : null,
|
|
1688
|
+
item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
|
|
1689
|
+
item_ref: (_l = item.productReference) != null ? _l : null,
|
|
1690
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1691
|
+
item_category: getItemCategory5(item),
|
|
1692
|
+
item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
|
|
1693
|
+
item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
|
|
1694
|
+
item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
|
|
1695
|
+
item_url: (_q = item.link) != null ? _q : null,
|
|
1696
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1697
|
+
image_url: (_t = resizeVtexImage3((_s = (_r = item == null ? void 0 : item.items) == null ? void 0 : _r[0].images) == null ? void 0 : _s[0].imageUrl)) != null ? _t : null,
|
|
1698
|
+
seller_id: (_x = (_w = (_v = (_u = item.items) == null ? void 0 : _u[0]) == null ? void 0 : _v.sellers) == null ? void 0 : _w[0].sellerId) != null ? _x : null,
|
|
1699
|
+
item_list_name: (_y = item.item_list_name) != null ? _y : null
|
|
1700
|
+
};
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
return null;
|
|
1704
|
+
},
|
|
1705
|
+
value: (context) => {
|
|
1706
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1707
|
+
if (context == null ? void 0 : context.products) {
|
|
1708
|
+
return context.products.map((item) => {
|
|
1709
|
+
var _a;
|
|
1710
|
+
return (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.Price;
|
|
1711
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1712
|
+
}
|
|
1713
|
+
return null;
|
|
1714
|
+
},
|
|
1715
|
+
line_items: (context) => {
|
|
1716
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1717
|
+
if (context == null ? void 0 : context.products) {
|
|
1718
|
+
return context.products.map((item) => item.productId).filter((id) => Boolean(id));
|
|
1719
|
+
}
|
|
1720
|
+
return null;
|
|
1721
|
+
},
|
|
1722
|
+
brand: (context) => {
|
|
1723
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1724
|
+
if (context == null ? void 0 : context.products) {
|
|
1725
|
+
return context.products.map((p) => p.brand).join().trim();
|
|
1726
|
+
}
|
|
1727
|
+
return null;
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
// src/params/adapters/headless/zones/PDC.ts
|
|
1732
|
+
var HeadlessPdcZone = {
|
|
1733
|
+
items: (context) => {
|
|
1734
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1735
|
+
if (context == null ? void 0 : context.products) {
|
|
1736
|
+
return context.products.map((item) => {
|
|
1737
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1738
|
+
const listPrice = item.offers.highPrice;
|
|
1739
|
+
const price = item.offers.lowPrice;
|
|
1740
|
+
return {
|
|
1741
|
+
quantity: 1,
|
|
1742
|
+
index: (_a = item == null ? void 0 : item.index) != null ? _a : 0,
|
|
1743
|
+
item_brand: (_b = item.brand.name) != null ? _b : null,
|
|
1744
|
+
item_name: (_c = item.name) != null ? _c : null,
|
|
1745
|
+
price: price != null ? price : null,
|
|
1746
|
+
discount: Number(listPrice) - Number(price),
|
|
1747
|
+
item_variant: (_f = (_e = (_d = item.isVariantOf) == null ? void 0 : _d.hasVariant) == null ? void 0 : _e[0].name.split(" - ")[0]) != null ? _f : null,
|
|
1748
|
+
item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
|
|
1749
|
+
item_ref: null,
|
|
1750
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1751
|
+
item_category: getItemCategory5(item),
|
|
1752
|
+
item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
|
|
1753
|
+
item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
|
|
1754
|
+
item_sku: (_l = item.sku) != null ? _l : null,
|
|
1755
|
+
item_url: null,
|
|
1756
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1757
|
+
image_url: (_n = resizeVtexImage3((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
|
|
1758
|
+
seller_id: (_s = (_r = (_q = (_p = (_o = item.offers) == null ? void 0 : _o.offers) == null ? void 0 : _p.find((o) => o.availability)) == null ? void 0 : _q.seller) == null ? void 0 : _r.identifier) != null ? _s : null,
|
|
1759
|
+
item_list_name: (_t = item.item_list_name) != null ? _t : null
|
|
1760
|
+
};
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
return null;
|
|
1764
|
+
},
|
|
1765
|
+
value: (context) => {
|
|
1766
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1767
|
+
if (context == null ? void 0 : context.products) {
|
|
1768
|
+
return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1769
|
+
}
|
|
1770
|
+
return null;
|
|
1771
|
+
},
|
|
1772
|
+
line_items: (context) => {
|
|
1773
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1774
|
+
if (context == null ? void 0 : context.products) {
|
|
1775
|
+
return context.products.map((item) => item.id).filter((id) => Boolean(id));
|
|
1776
|
+
}
|
|
1777
|
+
return null;
|
|
1778
|
+
},
|
|
1779
|
+
brand: (context) => {
|
|
1780
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1781
|
+
if (context == null ? void 0 : context.products) {
|
|
1782
|
+
return context.products.map((p) => p.brand.name).join().trim();
|
|
1783
|
+
}
|
|
1784
|
+
return null;
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1788
|
+
// src/params/adapters/headless/index.ts
|
|
1789
|
+
var headlessAdapter = {
|
|
1790
|
+
...metaAdapters,
|
|
1791
|
+
// global adapters
|
|
1792
|
+
...orderFormAdapters,
|
|
1793
|
+
// orderForm adapters, confirmar se no storefront tem evento que usa essses params
|
|
1794
|
+
brand: (context) => {
|
|
1795
|
+
if (context.zone === "PDP") {
|
|
1796
|
+
return HeadlessPdpZone.brand(context);
|
|
1797
|
+
}
|
|
1798
|
+
if (context.zone === "PDC") {
|
|
1799
|
+
return HeadlessPdcZone.brand(context);
|
|
1800
|
+
}
|
|
1801
|
+
return null;
|
|
1802
|
+
},
|
|
1803
|
+
line_items: (context) => {
|
|
1804
|
+
if (context.zone === "PDP") {
|
|
1805
|
+
return HeadlessPdpZone.line_items(context);
|
|
1806
|
+
}
|
|
1807
|
+
if (context.zone === "PDC") {
|
|
1808
|
+
return HeadlessPdcZone.line_items(context);
|
|
1809
|
+
}
|
|
1810
|
+
return null;
|
|
1811
|
+
},
|
|
1812
|
+
value: (context) => {
|
|
1813
|
+
if (context.zone === "PDP") {
|
|
1814
|
+
return HeadlessPdpZone.value(context);
|
|
1815
|
+
}
|
|
1816
|
+
if (context.zone === "PDC") {
|
|
1817
|
+
return HeadlessPdcZone.value(context);
|
|
1818
|
+
}
|
|
1819
|
+
return null;
|
|
1820
|
+
},
|
|
1821
|
+
items: (context) => {
|
|
1822
|
+
if (context.zone === "PDP") {
|
|
1823
|
+
return HeadlessPdpZone.items(context);
|
|
1824
|
+
}
|
|
1825
|
+
if (context.zone === "PDC") {
|
|
1826
|
+
return HeadlessPdcZone.items(context);
|
|
1827
|
+
}
|
|
1828
|
+
},
|
|
1829
|
+
// param used only in one Zone, the PDP; no need condition
|
|
1830
|
+
available_grid: (context) => {
|
|
1831
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1832
|
+
if (context == null ? void 0 : context.products) {
|
|
1833
|
+
const sizes = context.products.flatMap((p) => p.items.map((i) => i.Tamanho[0]));
|
|
1834
|
+
const result = sortSizes(sizes).join(",");
|
|
1835
|
+
return result || null;
|
|
1836
|
+
}
|
|
1837
|
+
return null;
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
// src/formatter.ts
|
|
1842
|
+
var adapters = {
|
|
1843
|
+
DECO: decoAdapter,
|
|
1844
|
+
HEADLESS: headlessAdapter
|
|
1845
|
+
};
|
|
1846
|
+
async function getParameters(context, eventName) {
|
|
1847
|
+
var _a;
|
|
1336
1848
|
const eventConfig = EVENTS[eventName];
|
|
1337
1849
|
if (!eventConfig) return;
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
)
|
|
1850
|
+
const currentAdapter = context.adapter;
|
|
1851
|
+
const getters = (_a = adapters[currentAdapter]) != null ? _a : paramGetters;
|
|
1852
|
+
const entries = await Promise.all(
|
|
1853
|
+
eventConfig.requiredParams.map(async (param) => {
|
|
1854
|
+
const getter = getters[param];
|
|
1855
|
+
if (typeof getter !== "function") {
|
|
1856
|
+
console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
|
|
1857
|
+
return [param, null];
|
|
1858
|
+
}
|
|
1859
|
+
return [param, await getter(context, eventName)];
|
|
1860
|
+
})
|
|
1349
1861
|
);
|
|
1350
|
-
return
|
|
1862
|
+
return Object.fromEntries(entries);
|
|
1351
1863
|
}
|
|
1352
1864
|
|
|
1353
1865
|
// src/index.ts
|
|
1354
|
-
async function trackWebEvent(event, context
|
|
1866
|
+
async function trackWebEvent(event, context) {
|
|
1355
1867
|
try {
|
|
1356
1868
|
const parameters = await getParameters(context, event);
|
|
1357
|
-
|
|
1869
|
+
if (isDebugMode()) {
|
|
1870
|
+
console.log(`[DT v2] ${event}, context e parameters: `, {
|
|
1871
|
+
context,
|
|
1872
|
+
parameters
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
return await pushToDataLayer(
|
|
1358
1876
|
event,
|
|
1359
1877
|
Object.assign({}, parameters, { window: context.window })
|
|
1360
1878
|
);
|