@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.js
CHANGED
|
@@ -114,8 +114,8 @@ var EVENTS = {
|
|
|
114
114
|
"currency",
|
|
115
115
|
"promotion_name",
|
|
116
116
|
"creative_slot",
|
|
117
|
-
"creative_name"
|
|
118
|
-
"items"
|
|
117
|
+
"creative_name"
|
|
118
|
+
// "items",
|
|
119
119
|
]
|
|
120
120
|
},
|
|
121
121
|
SELECT_PROMOTION: {
|
|
@@ -128,8 +128,8 @@ var EVENTS = {
|
|
|
128
128
|
"currency",
|
|
129
129
|
"promotion_name",
|
|
130
130
|
"creative_slot",
|
|
131
|
-
"creative_name"
|
|
132
|
-
"items"
|
|
131
|
+
"creative_name"
|
|
132
|
+
// "items",
|
|
133
133
|
]
|
|
134
134
|
},
|
|
135
135
|
SELECT_CONTENT: {
|
|
@@ -294,7 +294,7 @@ var EVENTS = {
|
|
|
294
294
|
}
|
|
295
295
|
};
|
|
296
296
|
|
|
297
|
-
// src/
|
|
297
|
+
// src/pushToDatalayer.ts
|
|
298
298
|
function pushToDataLayer(event, context) {
|
|
299
299
|
const targetWindow = context.window || (typeof window !== "undefined" ? window : null);
|
|
300
300
|
if (!targetWindow) return;
|
|
@@ -305,74 +305,13 @@ function pushToDataLayer(event, context) {
|
|
|
305
305
|
targetWindow.dataLayer = targetWindow.dataLayer || [];
|
|
306
306
|
if (eventConfig == null ? void 0 : eventConfig.hasEcommerce) {
|
|
307
307
|
targetWindow.dataLayer.push({ ecommerce: null });
|
|
308
|
-
targetWindow.dataLayer.push({ event, ecommerce: payload });
|
|
308
|
+
targetWindow.dataLayer.push({ event: event.toLowerCase(), ecommerce: payload });
|
|
309
309
|
} else {
|
|
310
|
-
targetWindow.dataLayer.push(Object.assign({ event }, payload));
|
|
310
|
+
targetWindow.dataLayer.push(Object.assign({ event: event.toLowerCase() }, payload));
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
// src/
|
|
315
|
-
function dataTrackingLog(data, color) {
|
|
316
|
-
console.log(
|
|
317
|
-
`%c[DT] EVENTO DISPARADO:%c `,
|
|
318
|
-
`background: ${color}; color: white; font-weight: bold; padding: 2px 4px; border-radius: 3px;`,
|
|
319
|
-
"color: #fff;",
|
|
320
|
-
data || ""
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
var paymentTypeMap = [
|
|
324
|
-
["vale", "vale cr\xE9dito"],
|
|
325
|
-
["pagaleve", "pix"],
|
|
326
|
-
["pix parcel", "pix parcelado"],
|
|
327
|
-
["pix", "pix"],
|
|
328
|
-
["apple", "apple pay"],
|
|
329
|
-
["google", "google pay"],
|
|
330
|
-
["boleto", "boleto"],
|
|
331
|
-
["paypal", "paypal"],
|
|
332
|
-
["cred", "cart\xE3o"],
|
|
333
|
-
["visa", "cart\xE3o"],
|
|
334
|
-
["master", "cart\xE3o"],
|
|
335
|
-
["amex", "cart\xE3o"],
|
|
336
|
-
["elo", "cart\xE3o"],
|
|
337
|
-
["hiper", "cart\xE3o"],
|
|
338
|
-
["diner", "cart\xE3o"],
|
|
339
|
-
["deb", "cart\xE3o"]
|
|
340
|
-
];
|
|
341
|
-
var toNum = (val) => typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
|
|
342
|
-
var documentToHash = async (document2) => {
|
|
343
|
-
if (!document2) return null;
|
|
344
|
-
const encoder = new TextEncoder();
|
|
345
|
-
const data = encoder.encode(document2);
|
|
346
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
347
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
348
|
-
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
// src/adapters/dito.ts
|
|
352
|
-
function pushToDito(event, ecomm) {
|
|
353
|
-
dataTrackingLog({ id: event, custom_data: ecomm }, "#00c851");
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// src/adapters/index.ts
|
|
357
|
-
var adapters = {
|
|
358
|
-
DataLayer: pushToDataLayer,
|
|
359
|
-
Dito: pushToDito
|
|
360
|
-
};
|
|
361
|
-
async function dispatchTrackEvent(eventName, data) {
|
|
362
|
-
const eventConfig = EVENTS[eventName];
|
|
363
|
-
if (!eventConfig) return;
|
|
364
|
-
await Promise.allSettled(
|
|
365
|
-
eventConfig.destinations.map(async (dest) => {
|
|
366
|
-
try {
|
|
367
|
-
await adapters[dest](eventName.toLowerCase(), data);
|
|
368
|
-
} catch (err) {
|
|
369
|
-
console.error(`[DT] Failed to send ${eventName} to ${dest}:`, err);
|
|
370
|
-
}
|
|
371
|
-
})
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// src/params/utils/index.ts
|
|
314
|
+
// src/params/legacy/utils/index.ts
|
|
376
315
|
async function getProductDataById(id) {
|
|
377
316
|
try {
|
|
378
317
|
const response = await fetch(
|
|
@@ -574,7 +513,7 @@ function normalizeBrand(input) {
|
|
|
574
513
|
return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
|
|
575
514
|
}
|
|
576
515
|
|
|
577
|
-
// src/params/resolvers/brand/fromOrderForm.ts
|
|
516
|
+
// src/params/legacy/resolvers/brand/fromOrderForm.ts
|
|
578
517
|
function brandFromOrderForm(context) {
|
|
579
518
|
var _a;
|
|
580
519
|
if (!context.orderForm && !((_a = context.orderForm.items) == null ? void 0 : _a.length)) return null;
|
|
@@ -582,14 +521,14 @@ function brandFromOrderForm(context) {
|
|
|
582
521
|
return normalizeBrand(items);
|
|
583
522
|
}
|
|
584
523
|
|
|
585
|
-
// src/params/resolvers/brand/fromItem.ts
|
|
524
|
+
// src/params/legacy/resolvers/brand/fromItem.ts
|
|
586
525
|
function brandFromItem(context) {
|
|
587
526
|
var _a;
|
|
588
527
|
const { item } = context;
|
|
589
528
|
return normalizeBrand(((_a = item == null ? void 0 : item.additionalInfo) == null ? void 0 : _a.brandName) || item.brand || item.item_brand);
|
|
590
529
|
}
|
|
591
530
|
|
|
592
|
-
// src/params/brand.ts
|
|
531
|
+
// src/params/legacy/brand.ts
|
|
593
532
|
function getBrand(context, eventName) {
|
|
594
533
|
if (context == null ? void 0 : context.brand) return normalizeBrand(context.brand) || context.brand || null;
|
|
595
534
|
switch (eventName) {
|
|
@@ -613,7 +552,7 @@ function getBrand(context, eventName) {
|
|
|
613
552
|
}
|
|
614
553
|
}
|
|
615
554
|
|
|
616
|
-
// src/params/utils/itemListAttribution.ts
|
|
555
|
+
// src/params/legacy/utils/itemListAttribution.ts
|
|
617
556
|
var LAST_SELECTED_ITEM_KEY = "last_selected_item";
|
|
618
557
|
var STORAGE_VIEWED = "last_viewed_item";
|
|
619
558
|
var CART_LIST_HISTORY_KEY = "cart_list_history";
|
|
@@ -794,7 +733,7 @@ function persistSelectItemOriginFromResolvedItems(items, source) {
|
|
|
794
733
|
saveSelectedItem(productId, listName);
|
|
795
734
|
}
|
|
796
735
|
|
|
797
|
-
// src/params/resolvers/items/fromOrderForm.ts
|
|
736
|
+
// src/params/legacy/resolvers/items/fromOrderForm.ts
|
|
798
737
|
async function itemsFromOrderForm(context) {
|
|
799
738
|
var _a;
|
|
800
739
|
const items = ((_a = context.orderForm) == null ? void 0 : _a.items) || [];
|
|
@@ -826,7 +765,7 @@ async function itemsFromOrderForm(context) {
|
|
|
826
765
|
);
|
|
827
766
|
}
|
|
828
767
|
|
|
829
|
-
// src/params/resolvers/items/fromItem.ts
|
|
768
|
+
// src/params/legacy/resolvers/items/fromItem.ts
|
|
830
769
|
async function itemsFromItem(context, event) {
|
|
831
770
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
832
771
|
const { item, orderForm, itemListName } = context;
|
|
@@ -862,7 +801,7 @@ async function itemsFromItem(context, event) {
|
|
|
862
801
|
];
|
|
863
802
|
}
|
|
864
803
|
|
|
865
|
-
// src/params/resolvers/items/fromList.ts
|
|
804
|
+
// src/params/legacy/resolvers/items/fromList.ts
|
|
866
805
|
async function itemsFromList(context) {
|
|
867
806
|
return ((context == null ? void 0 : context.list) || []).map((item) => {
|
|
868
807
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
@@ -883,7 +822,7 @@ async function itemsFromList(context) {
|
|
|
883
822
|
});
|
|
884
823
|
}
|
|
885
824
|
|
|
886
|
-
// src/params/resolvers/items/fromPdp.ts
|
|
825
|
+
// src/params/legacy/resolvers/items/fromPdp.ts
|
|
887
826
|
async function itemsFromPDP(context, event) {
|
|
888
827
|
var _a, _b, _c, _d;
|
|
889
828
|
const { item, value, brand } = context;
|
|
@@ -914,7 +853,7 @@ async function itemsFromPDP(context, event) {
|
|
|
914
853
|
];
|
|
915
854
|
}
|
|
916
855
|
|
|
917
|
-
// src/params/resolvers/items/fromBanner.ts
|
|
856
|
+
// src/params/legacy/resolvers/items/fromBanner.ts
|
|
918
857
|
async function itemsFromBanner(context) {
|
|
919
858
|
var _a;
|
|
920
859
|
const isUrlFromPDP = isPDP(context == null ? void 0 : context.bannerUrl);
|
|
@@ -935,7 +874,7 @@ async function itemsFromBanner(context) {
|
|
|
935
874
|
};
|
|
936
875
|
}
|
|
937
876
|
|
|
938
|
-
// src/params/items.ts
|
|
877
|
+
// src/params/legacy/items.ts
|
|
939
878
|
function getItems(context, eventName) {
|
|
940
879
|
if (context == null ? void 0 : context.items) return context.items;
|
|
941
880
|
switch (eventName) {
|
|
@@ -969,7 +908,72 @@ function getItems(context, eventName) {
|
|
|
969
908
|
}
|
|
970
909
|
}
|
|
971
910
|
|
|
972
|
-
// src/
|
|
911
|
+
// src/core/utils.ts
|
|
912
|
+
var isDebugMode = () => {
|
|
913
|
+
if (typeof window === "undefined") return false;
|
|
914
|
+
try {
|
|
915
|
+
const params = new URLSearchParams(window.location.search);
|
|
916
|
+
return params.has("__trk_inspect__");
|
|
917
|
+
} catch (e) {
|
|
918
|
+
return window.location.search.indexOf("__trk_inspect__") !== -1;
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
var paymentTypeMap = [
|
|
922
|
+
["vale", "vale cr\xE9dito"],
|
|
923
|
+
["pagaleve", "pix"],
|
|
924
|
+
["pix parcel", "pix parcelado"],
|
|
925
|
+
["pix", "pix"],
|
|
926
|
+
["apple", "apple pay"],
|
|
927
|
+
["google", "google pay"],
|
|
928
|
+
["boleto", "boleto"],
|
|
929
|
+
["paypal", "paypal"],
|
|
930
|
+
["cred", "cart\xE3o"],
|
|
931
|
+
["visa", "cart\xE3o"],
|
|
932
|
+
["master", "cart\xE3o"],
|
|
933
|
+
["amex", "cart\xE3o"],
|
|
934
|
+
["elo", "cart\xE3o"],
|
|
935
|
+
["hiper", "cart\xE3o"],
|
|
936
|
+
["diner", "cart\xE3o"],
|
|
937
|
+
["deb", "cart\xE3o"]
|
|
938
|
+
];
|
|
939
|
+
var toNum = (val) => typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
|
|
940
|
+
var documentToHash = async (document2) => {
|
|
941
|
+
if (!document2) return null;
|
|
942
|
+
const encoder = new TextEncoder();
|
|
943
|
+
const data = encoder.encode(document2);
|
|
944
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
945
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
946
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
947
|
+
};
|
|
948
|
+
var SIZE_ORDER = {
|
|
949
|
+
alfabetico: ["PP", "P", "M", "G", "GG", "XG", "XGG", "EG", "EGG", "3G", "4G", "5G"],
|
|
950
|
+
infantil: ["RN", "0-3M", "3-6M", "6-9M", "9-12M", "12-18M", "18-24M", "P", "M", "G", "GG"]
|
|
951
|
+
};
|
|
952
|
+
var detectSizeType = (sizes) => {
|
|
953
|
+
if (sizes.every((s) => /^\d+([.,]\d+)?$/.test(s))) return "numerico";
|
|
954
|
+
if (sizes.some((s) => /^(RN|\d+-\d+M|\d+M)$/i.test(s))) return "infantil";
|
|
955
|
+
if (sizes.every((s) => SIZE_ORDER.alfabetico.includes(s.toUpperCase()))) return "alfabetico";
|
|
956
|
+
return "desconhecido";
|
|
957
|
+
};
|
|
958
|
+
var sortSizes = (sizes) => {
|
|
959
|
+
const unique = [...new Set(sizes.filter(Boolean))];
|
|
960
|
+
const type = detectSizeType(unique);
|
|
961
|
+
if (type === "numerico") {
|
|
962
|
+
return unique.sort((a, b) => parseFloat(a) - parseFloat(b));
|
|
963
|
+
}
|
|
964
|
+
if (type === "alfabetico" || type === "infantil") {
|
|
965
|
+
const order = SIZE_ORDER[type];
|
|
966
|
+
return unique.sort((a, b) => {
|
|
967
|
+
const ia = order.indexOf(a.toUpperCase());
|
|
968
|
+
const ib = order.indexOf(b.toUpperCase());
|
|
969
|
+
return (ia === -1 ? 999 : ia) - (ib === -1 ? 999 : ib);
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
return unique;
|
|
973
|
+
};
|
|
974
|
+
var capitalize = (str) => str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
|
|
975
|
+
|
|
976
|
+
// src/params/legacy/resolvers/paymentType/fromOrderForm.ts
|
|
973
977
|
function paymentTypeFromOrderForm(context) {
|
|
974
978
|
var _a, _b, _c;
|
|
975
979
|
if (context.payment_type) return context.payment_type;
|
|
@@ -986,7 +990,7 @@ function paymentTypeFromOrderForm(context) {
|
|
|
986
990
|
return match ? match[1] : null;
|
|
987
991
|
}
|
|
988
992
|
|
|
989
|
-
// src/params/resolvers/paymentType/fromOrderGroup.ts
|
|
993
|
+
// src/params/legacy/resolvers/paymentType/fromOrderGroup.ts
|
|
990
994
|
function paymentTypeFromOrderGroup(context) {
|
|
991
995
|
var _a, _b, _c, _d;
|
|
992
996
|
if (!context.orderForm) return null;
|
|
@@ -999,7 +1003,7 @@ function paymentTypeFromOrderGroup(context) {
|
|
|
999
1003
|
return match ? match[1] : null;
|
|
1000
1004
|
}
|
|
1001
1005
|
|
|
1002
|
-
// src/params/paymentType.ts
|
|
1006
|
+
// src/params/legacy/paymentType.ts
|
|
1003
1007
|
function getPaymentType(context, eventName) {
|
|
1004
1008
|
if (context == null ? void 0 : context.paymentType) return context.paymentType;
|
|
1005
1009
|
switch (eventName) {
|
|
@@ -1015,36 +1019,36 @@ function getPaymentType(context, eventName) {
|
|
|
1015
1019
|
}
|
|
1016
1020
|
|
|
1017
1021
|
// src/params/userInfo.ts
|
|
1018
|
-
|
|
1022
|
+
var PROD_DOMAINS = {
|
|
1023
|
+
"animale": {
|
|
1024
|
+
"store": "https://www.animale.com.br",
|
|
1025
|
+
"checkout": "https://secure.animale.com.br"
|
|
1026
|
+
},
|
|
1027
|
+
"farm": {
|
|
1028
|
+
"store": "https://lojafarm.myvtex.com"
|
|
1029
|
+
},
|
|
1030
|
+
"mariafilo": {
|
|
1031
|
+
"store": "https://mariafilo.myvtex.com",
|
|
1032
|
+
"checkout": "https://secure.mariafilo.com.br"
|
|
1033
|
+
},
|
|
1034
|
+
"lojacrisbarros": {
|
|
1035
|
+
"store": "https://lojacrisbarros.myvtex.com",
|
|
1036
|
+
"checkout": "https://secure.crisbarros.com.br"
|
|
1037
|
+
},
|
|
1038
|
+
"lojaoffpremium": {
|
|
1039
|
+
"store": "https://lojaoffpremium.myvtex.com",
|
|
1040
|
+
"checkout": "https://secure.offpremium.com.br"
|
|
1041
|
+
},
|
|
1042
|
+
"bynv": {
|
|
1043
|
+
"store": "https://bynv.myvtex.com"
|
|
1044
|
+
},
|
|
1045
|
+
"fabula": {
|
|
1046
|
+
"store": "https://lojafabula.myvtex.com"
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
async function getUserInfo(context) {
|
|
1019
1050
|
var _a, _b, _c, _d, _e;
|
|
1020
|
-
const
|
|
1021
|
-
"animale": {
|
|
1022
|
-
"store": "https://www.animale.com.br",
|
|
1023
|
-
"checkout": "https://secure.animale.com.br"
|
|
1024
|
-
},
|
|
1025
|
-
"farm": {
|
|
1026
|
-
"store": "https://lojafarm.myvtex.com"
|
|
1027
|
-
},
|
|
1028
|
-
"mariafilo": {
|
|
1029
|
-
"store": "https://mariafilo.myvtex.com",
|
|
1030
|
-
"checkout": "https://secure.mariafilo.com.br"
|
|
1031
|
-
},
|
|
1032
|
-
"lojacrisbarros": {
|
|
1033
|
-
"store": "https://lojacrisbarros.myvtex.com",
|
|
1034
|
-
"checkout": "https://secure.crisbarros.com.br"
|
|
1035
|
-
},
|
|
1036
|
-
"lojaoffpremium": {
|
|
1037
|
-
"store": "https://lojaoffpremium.myvtex.com",
|
|
1038
|
-
"checkout": "https://secure.offpremium.com.br"
|
|
1039
|
-
},
|
|
1040
|
-
"bynv": {
|
|
1041
|
-
"store": "https://bynv.myvtex.com"
|
|
1042
|
-
},
|
|
1043
|
-
"fabula": {
|
|
1044
|
-
"store": "https://lojafabula.myvtex.com"
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
const domain = (_a = PROD_DOMAINS[context.account || "https://www.animale.com.br"]) == null ? void 0 : _a[context.platform || "store"];
|
|
1051
|
+
const domain = (_a = PROD_DOMAINS[context.account || "animale"]) == null ? void 0 : _a[context.platform || "store"];
|
|
1048
1052
|
if (!domain) return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
|
|
1049
1053
|
try {
|
|
1050
1054
|
const api = `${domain}/_v/user-info`;
|
|
@@ -1102,12 +1106,13 @@ async function getUserInfo(context, eventName) {
|
|
|
1102
1106
|
}
|
|
1103
1107
|
}
|
|
1104
1108
|
|
|
1105
|
-
// src/params/index.ts
|
|
1109
|
+
// src/params/legacy/index.ts
|
|
1106
1110
|
var paramGetters = {
|
|
1107
1111
|
brand: getBrand,
|
|
1108
1112
|
items: getItems,
|
|
1109
1113
|
payment_type: getPaymentType,
|
|
1110
1114
|
user_info: getUserInfo,
|
|
1115
|
+
// global
|
|
1111
1116
|
content_type: (context, eventName) => {
|
|
1112
1117
|
if (context == null ? void 0 : context.content_type) return context.content_type;
|
|
1113
1118
|
return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
|
|
@@ -1303,30 +1308,543 @@ var paramGetters = {
|
|
|
1303
1308
|
}
|
|
1304
1309
|
};
|
|
1305
1310
|
|
|
1306
|
-
// src/
|
|
1307
|
-
|
|
1311
|
+
// src/params/adapters/meta/index.ts
|
|
1312
|
+
var metaAdapters = {
|
|
1313
|
+
user_info: getUserInfo,
|
|
1314
|
+
brand: (context) => {
|
|
1315
|
+
return context.meta.brand || null;
|
|
1316
|
+
},
|
|
1317
|
+
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;
|
|
1320
|
+
},
|
|
1321
|
+
region: (context) => {
|
|
1322
|
+
return context.meta.region || null;
|
|
1323
|
+
},
|
|
1324
|
+
pre_filled: (context) => {
|
|
1325
|
+
return !!context.preFilled;
|
|
1326
|
+
},
|
|
1327
|
+
currency: (context) => {
|
|
1328
|
+
if (context == null ? void 0 : context.currency) return context.currency;
|
|
1329
|
+
return "BRL";
|
|
1330
|
+
},
|
|
1331
|
+
search_term: (context) => {
|
|
1332
|
+
return context.searchTerm || null;
|
|
1333
|
+
},
|
|
1334
|
+
search_found: (context) => {
|
|
1335
|
+
return !!context.searchFound;
|
|
1336
|
+
},
|
|
1337
|
+
search_quantity: (context) => {
|
|
1338
|
+
return context.searchQuantity || 0;
|
|
1339
|
+
},
|
|
1340
|
+
promotion_name: (context) => {
|
|
1341
|
+
return context.meta.promotion_name || null;
|
|
1342
|
+
},
|
|
1343
|
+
creative_name: (context) => {
|
|
1344
|
+
return context.meta.creative_name || null;
|
|
1345
|
+
},
|
|
1346
|
+
creative_slot: (context) => {
|
|
1347
|
+
return context.meta.creative_slot || null;
|
|
1348
|
+
},
|
|
1349
|
+
zipcode: (context) => {
|
|
1350
|
+
return context.zipCode || null;
|
|
1351
|
+
},
|
|
1352
|
+
size: (context) => {
|
|
1353
|
+
return context.size || null;
|
|
1354
|
+
},
|
|
1355
|
+
item_ref: (context) => {
|
|
1356
|
+
return context.itemRef || null;
|
|
1357
|
+
},
|
|
1358
|
+
method: (context) => {
|
|
1359
|
+
return context.method || null;
|
|
1360
|
+
},
|
|
1361
|
+
type: (context) => {
|
|
1362
|
+
return context.type || null;
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
// src/params/adapters/orderForm/index.ts
|
|
1367
|
+
var orderFormAdapters = {
|
|
1368
|
+
// orderform
|
|
1369
|
+
payment_type: getPaymentType,
|
|
1370
|
+
total_discount: (context) => {
|
|
1371
|
+
var _a, _b;
|
|
1372
|
+
if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
|
|
1373
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1374
|
+
const items = context.orderForm.items;
|
|
1375
|
+
const totalDiscount = items.reduce((acc, item) => {
|
|
1376
|
+
const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
1377
|
+
return acc + unitDiscount * item.quantity;
|
|
1378
|
+
}, 0);
|
|
1379
|
+
const discounts = totalsList.find((t) => t.id === "Discounts");
|
|
1380
|
+
return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
1381
|
+
},
|
|
1382
|
+
subtotal: (context) => {
|
|
1383
|
+
var _a, _b;
|
|
1384
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1385
|
+
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
1386
|
+
return subtotal;
|
|
1387
|
+
},
|
|
1388
|
+
coupon_message: (context) => {
|
|
1389
|
+
var _a;
|
|
1390
|
+
if (context.couponMessage) return context.couponMessage;
|
|
1391
|
+
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
1392
|
+
if (messages.length === 0) return null;
|
|
1393
|
+
const couponMessages = messages.filter(
|
|
1394
|
+
(msg) => msg.text.toLowerCase().includes("cupom")
|
|
1395
|
+
);
|
|
1396
|
+
if (couponMessages.length === 0) return null;
|
|
1397
|
+
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
1398
|
+
},
|
|
1399
|
+
flag_pickup: (context) => {
|
|
1400
|
+
var _a;
|
|
1401
|
+
const orderForm = context.orderForm;
|
|
1402
|
+
if (!orderForm) return null;
|
|
1403
|
+
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
1404
|
+
const hasPickup = logisticsInfo.some(
|
|
1405
|
+
(info) => {
|
|
1406
|
+
var _a2;
|
|
1407
|
+
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1410
|
+
return hasPickup;
|
|
1411
|
+
},
|
|
1412
|
+
shippings: (context) => {
|
|
1413
|
+
const orderForm = context.orderForm;
|
|
1414
|
+
if (!orderForm) return null;
|
|
1415
|
+
const groupShipping = {};
|
|
1416
|
+
for (const info of orderForm.shippingData.logisticsInfo) {
|
|
1417
|
+
const item = orderForm.items[info.itemIndex];
|
|
1418
|
+
if (!item) continue;
|
|
1419
|
+
for (const sla of info.slas) {
|
|
1420
|
+
const key = sla.name;
|
|
1421
|
+
if (!groupShipping[key]) {
|
|
1422
|
+
groupShipping[key] = {
|
|
1423
|
+
shipping_tier: sla.name,
|
|
1424
|
+
delivery_time: parseInt(sla.shippingEstimate),
|
|
1425
|
+
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
1426
|
+
line_items: []
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
groupShipping[key].line_items.push(item.id);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
const shippings = Object.values(groupShipping).map((s) => ({
|
|
1433
|
+
shipping: s.shipping,
|
|
1434
|
+
shipping_tier: s.shipping_tier,
|
|
1435
|
+
delivery_time: s.delivery_time,
|
|
1436
|
+
line_items: s.line_items.join(",")
|
|
1437
|
+
}));
|
|
1438
|
+
return shippings || null;
|
|
1439
|
+
},
|
|
1440
|
+
shipping: (context) => {
|
|
1441
|
+
var _a, _b, _c;
|
|
1442
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1443
|
+
return logistics.reduce((total, item) => {
|
|
1444
|
+
var _a2, _b2;
|
|
1445
|
+
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
1446
|
+
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
1447
|
+
}, 0);
|
|
1448
|
+
},
|
|
1449
|
+
shipping_tier: (context) => {
|
|
1450
|
+
var _a, _b, _c;
|
|
1451
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1452
|
+
const selectedSlas = logistics.map((item) => {
|
|
1453
|
+
var _a2;
|
|
1454
|
+
if (!item.selectedSla) return null;
|
|
1455
|
+
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
1456
|
+
}).filter(Boolean);
|
|
1457
|
+
if (selectedSlas.length === 0) return null;
|
|
1458
|
+
const uniqueTiers = Array.from(
|
|
1459
|
+
new Map(
|
|
1460
|
+
selectedSlas.map((sla) => {
|
|
1461
|
+
var _a2;
|
|
1462
|
+
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
1463
|
+
return [key, sla];
|
|
1464
|
+
})
|
|
1465
|
+
).values()
|
|
1466
|
+
);
|
|
1467
|
+
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
1468
|
+
var _a2, _b2;
|
|
1469
|
+
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1470
|
+
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1471
|
+
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
1472
|
+
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
1473
|
+
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
1474
|
+
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
1475
|
+
});
|
|
1476
|
+
const shippingTier = sortedTiers.map((sla) => {
|
|
1477
|
+
var _a2;
|
|
1478
|
+
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;
|
|
1479
|
+
}).filter(Boolean).join(", ");
|
|
1480
|
+
return shippingTier || null;
|
|
1481
|
+
},
|
|
1482
|
+
transaction_id: (context) => {
|
|
1483
|
+
var _a, _b;
|
|
1484
|
+
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
1485
|
+
},
|
|
1486
|
+
coupon: (context) => {
|
|
1487
|
+
var _a, _b;
|
|
1488
|
+
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
1489
|
+
},
|
|
1490
|
+
seller_cod_name: (context) => {
|
|
1491
|
+
return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
|
|
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
|
|
1615
|
+
var getItemCategory5 = (item) => {
|
|
1616
|
+
const keywords = ["outlet", "bazar", "sale"];
|
|
1617
|
+
const regex = new RegExp(keywords.join("|"), "i");
|
|
1618
|
+
const value = item == null ? void 0 : item.categories;
|
|
1619
|
+
if (value) {
|
|
1620
|
+
const textToTest = Array.isArray(value) ? value.join(" ") : String(value);
|
|
1621
|
+
const match = textToTest.match(regex);
|
|
1622
|
+
if (match) {
|
|
1623
|
+
return match[0].toLowerCase();
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return "Cole\xE7\xE3o";
|
|
1627
|
+
};
|
|
1628
|
+
var getItemCategory23 = (item) => {
|
|
1629
|
+
var _a, _b, _c;
|
|
1630
|
+
const avoidList = /outlet|bazar|sale/i;
|
|
1631
|
+
const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
|
|
1632
|
+
const categoryHierarchy = lastCategory.split("/").filter(Boolean);
|
|
1633
|
+
const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
|
|
1634
|
+
return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
|
|
1635
|
+
};
|
|
1636
|
+
function resizeVtexImage3(url, width = 500, height = 500) {
|
|
1637
|
+
return url == null ? void 0 : url.replace(
|
|
1638
|
+
/(\/arquivos\/ids\/\d+)-\d+-\d+\//,
|
|
1639
|
+
`$1-${width}-${height}/`
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// src/params/adapters/headless/zones/PDP.ts
|
|
1644
|
+
var HeadlessPdpZone = {
|
|
1645
|
+
items: (context) => {
|
|
1646
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1647
|
+
if (context == null ? void 0 : context.products) {
|
|
1648
|
+
return context.products.map((item) => {
|
|
1649
|
+
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;
|
|
1650
|
+
const listPrice = (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.ListPrice;
|
|
1651
|
+
const price = (_b = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _b[0].commertialOffer.Price;
|
|
1652
|
+
return {
|
|
1653
|
+
quantity: 1,
|
|
1654
|
+
index: (_c = item == null ? void 0 : item.index) != null ? _c : null,
|
|
1655
|
+
item_brand: (_d = item.brand) != null ? _d : null,
|
|
1656
|
+
item_name: (_e = item.productName) != null ? _e : null,
|
|
1657
|
+
price: price != null ? price : null,
|
|
1658
|
+
discount: Number(listPrice) - Number(price),
|
|
1659
|
+
item_variant: (_h = (_g = (_f = item.items[0]) == null ? void 0 : _f.name) == null ? void 0 : _g.split(" - ")[0]) != null ? _h : null,
|
|
1660
|
+
item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
|
|
1661
|
+
item_ref: (_l = item.productReference) != null ? _l : null,
|
|
1662
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1663
|
+
item_category: getItemCategory5(item),
|
|
1664
|
+
item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
|
|
1665
|
+
item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
|
|
1666
|
+
item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
|
|
1667
|
+
item_url: (_q = item.link) != null ? _q : null,
|
|
1668
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1669
|
+
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,
|
|
1670
|
+
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,
|
|
1671
|
+
item_list_name: (_y = item.item_list_name) != null ? _y : null
|
|
1672
|
+
};
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
return null;
|
|
1676
|
+
},
|
|
1677
|
+
value: (context) => {
|
|
1678
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1679
|
+
if (context == null ? void 0 : context.products) {
|
|
1680
|
+
return context.products.map((item) => {
|
|
1681
|
+
var _a;
|
|
1682
|
+
return (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.Price;
|
|
1683
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1684
|
+
}
|
|
1685
|
+
return null;
|
|
1686
|
+
},
|
|
1687
|
+
line_items: (context) => {
|
|
1688
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1689
|
+
if (context == null ? void 0 : context.products) {
|
|
1690
|
+
return context.products.map((item) => item.productId).filter((id) => Boolean(id));
|
|
1691
|
+
}
|
|
1692
|
+
return null;
|
|
1693
|
+
},
|
|
1694
|
+
brand: (context) => {
|
|
1695
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1696
|
+
if (context == null ? void 0 : context.products) {
|
|
1697
|
+
return context.products.map((p) => p.brand).join().trim();
|
|
1698
|
+
}
|
|
1699
|
+
return null;
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
|
|
1703
|
+
// src/params/adapters/headless/zones/PDC.ts
|
|
1704
|
+
var HeadlessPdcZone = {
|
|
1705
|
+
items: (context) => {
|
|
1706
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1707
|
+
if (context == null ? void 0 : context.products) {
|
|
1708
|
+
return context.products.map((item) => {
|
|
1709
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1710
|
+
const listPrice = item.offers.highPrice;
|
|
1711
|
+
const price = item.offers.lowPrice;
|
|
1712
|
+
return {
|
|
1713
|
+
quantity: 1,
|
|
1714
|
+
index: (_a = item == null ? void 0 : item.index) != null ? _a : 0,
|
|
1715
|
+
item_brand: (_b = item.brand.name) != null ? _b : null,
|
|
1716
|
+
item_name: (_c = item.name) != null ? _c : null,
|
|
1717
|
+
price: price != null ? price : null,
|
|
1718
|
+
discount: Number(listPrice) - Number(price),
|
|
1719
|
+
item_variant: (_f = (_e = (_d = item.isVariantOf) == null ? void 0 : _d.hasVariant) == null ? void 0 : _e[0].name.split(" - ")[0]) != null ? _f : null,
|
|
1720
|
+
item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
|
|
1721
|
+
item_ref: null,
|
|
1722
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1723
|
+
item_category: getItemCategory5(item),
|
|
1724
|
+
item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
|
|
1725
|
+
item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
|
|
1726
|
+
item_sku: (_l = item.sku) != null ? _l : null,
|
|
1727
|
+
item_url: null,
|
|
1728
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1729
|
+
image_url: (_n = resizeVtexImage3((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
|
|
1730
|
+
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,
|
|
1731
|
+
item_list_name: (_t = item.item_list_name) != null ? _t : null
|
|
1732
|
+
};
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
return null;
|
|
1736
|
+
},
|
|
1737
|
+
value: (context) => {
|
|
1738
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1739
|
+
if (context == null ? void 0 : context.products) {
|
|
1740
|
+
return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1741
|
+
}
|
|
1742
|
+
return null;
|
|
1743
|
+
},
|
|
1744
|
+
line_items: (context) => {
|
|
1745
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1746
|
+
if (context == null ? void 0 : context.products) {
|
|
1747
|
+
return context.products.map((item) => item.id).filter((id) => Boolean(id));
|
|
1748
|
+
}
|
|
1749
|
+
return null;
|
|
1750
|
+
},
|
|
1751
|
+
brand: (context) => {
|
|
1752
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1753
|
+
if (context == null ? void 0 : context.products) {
|
|
1754
|
+
return context.products.map((p) => p.brand.name).join().trim();
|
|
1755
|
+
}
|
|
1756
|
+
return null;
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
|
|
1760
|
+
// src/params/adapters/headless/index.ts
|
|
1761
|
+
var headlessAdapter = {
|
|
1762
|
+
...metaAdapters,
|
|
1763
|
+
// global adapters
|
|
1764
|
+
...orderFormAdapters,
|
|
1765
|
+
// orderForm adapters, confirmar se no storefront tem evento que usa essses params
|
|
1766
|
+
brand: (context) => {
|
|
1767
|
+
if (context.zone === "PDP") {
|
|
1768
|
+
return HeadlessPdpZone.brand(context);
|
|
1769
|
+
}
|
|
1770
|
+
if (context.zone === "PDC") {
|
|
1771
|
+
return HeadlessPdcZone.brand(context);
|
|
1772
|
+
}
|
|
1773
|
+
return null;
|
|
1774
|
+
},
|
|
1775
|
+
line_items: (context) => {
|
|
1776
|
+
if (context.zone === "PDP") {
|
|
1777
|
+
return HeadlessPdpZone.line_items(context);
|
|
1778
|
+
}
|
|
1779
|
+
if (context.zone === "PDC") {
|
|
1780
|
+
return HeadlessPdcZone.line_items(context);
|
|
1781
|
+
}
|
|
1782
|
+
return null;
|
|
1783
|
+
},
|
|
1784
|
+
value: (context) => {
|
|
1785
|
+
if (context.zone === "PDP") {
|
|
1786
|
+
return HeadlessPdpZone.value(context);
|
|
1787
|
+
}
|
|
1788
|
+
if (context.zone === "PDC") {
|
|
1789
|
+
return HeadlessPdcZone.value(context);
|
|
1790
|
+
}
|
|
1791
|
+
return null;
|
|
1792
|
+
},
|
|
1793
|
+
items: (context) => {
|
|
1794
|
+
if (context.zone === "PDP") {
|
|
1795
|
+
return HeadlessPdpZone.items(context);
|
|
1796
|
+
}
|
|
1797
|
+
if (context.zone === "PDC") {
|
|
1798
|
+
return HeadlessPdcZone.items(context);
|
|
1799
|
+
}
|
|
1800
|
+
},
|
|
1801
|
+
// param used only in one Zone, the PDP; no need condition
|
|
1802
|
+
available_grid: (context) => {
|
|
1803
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1804
|
+
if (context == null ? void 0 : context.products) {
|
|
1805
|
+
const sizes = context.products.flatMap((p) => p.items.map((i) => i.Tamanho[0]));
|
|
1806
|
+
const result = sortSizes(sizes).join(",");
|
|
1807
|
+
return result || null;
|
|
1808
|
+
}
|
|
1809
|
+
return null;
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
|
|
1813
|
+
// src/formatter.ts
|
|
1814
|
+
var adapters = {
|
|
1815
|
+
DECO: decoAdapter,
|
|
1816
|
+
HEADLESS: headlessAdapter
|
|
1817
|
+
};
|
|
1818
|
+
async function getParameters(context, eventName) {
|
|
1819
|
+
var _a;
|
|
1308
1820
|
const eventConfig = EVENTS[eventName];
|
|
1309
1821
|
if (!eventConfig) return;
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
)
|
|
1822
|
+
const currentAdapter = context.adapter;
|
|
1823
|
+
const getters = (_a = adapters[currentAdapter]) != null ? _a : paramGetters;
|
|
1824
|
+
const entries = await Promise.all(
|
|
1825
|
+
eventConfig.requiredParams.map(async (param) => {
|
|
1826
|
+
const getter = getters[param];
|
|
1827
|
+
if (typeof getter !== "function") {
|
|
1828
|
+
console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
|
|
1829
|
+
return [param, null];
|
|
1830
|
+
}
|
|
1831
|
+
return [param, await getter(context, eventName)];
|
|
1832
|
+
})
|
|
1321
1833
|
);
|
|
1322
|
-
return
|
|
1834
|
+
return Object.fromEntries(entries);
|
|
1323
1835
|
}
|
|
1324
1836
|
|
|
1325
1837
|
// src/index.ts
|
|
1326
|
-
async function trackWebEvent(event, context
|
|
1838
|
+
async function trackWebEvent(event, context) {
|
|
1327
1839
|
try {
|
|
1328
1840
|
const parameters = await getParameters(context, event);
|
|
1329
|
-
|
|
1841
|
+
if (isDebugMode()) {
|
|
1842
|
+
console.log(`[DT v2] ${event}, context e parameters: `, {
|
|
1843
|
+
context,
|
|
1844
|
+
parameters
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
return await pushToDataLayer(
|
|
1330
1848
|
event,
|
|
1331
1849
|
Object.assign({}, parameters, { window: context.window })
|
|
1332
1850
|
);
|