@azzas/azzas-tracker-web 1.0.103 → 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.cjs +714 -129
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +1052 -217
- package/dist/mod.d.ts +1052 -217
- package/dist/mod.global.js +714 -129
- package/dist/mod.global.js.map +1 -1
- package/dist/mod.js +714 -129
- package/dist/mod.js.map +1 -1
- package/dist/mod.vtex.global.js +833 -165
- package/package.json +2 -2
package/dist/mod.global.js
CHANGED
|
@@ -142,8 +142,8 @@ var AzzasTracker = (() => {
|
|
|
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 AzzasTracker = (() => {
|
|
|
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: {
|
|
@@ -319,10 +319,22 @@ var AzzasTracker = (() => {
|
|
|
319
319
|
hasEcommerce: false,
|
|
320
320
|
destinations: ["DataLayer"],
|
|
321
321
|
requiredParams: ["brand", "line_items", "size", "item_ref"]
|
|
322
|
+
},
|
|
323
|
+
REFINE_RESULTS: {
|
|
324
|
+
name: "refine_results",
|
|
325
|
+
hasEcommerce: false,
|
|
326
|
+
destinations: ["DataLayer"],
|
|
327
|
+
requiredParams: ["brand", "region", "color", "price_range", "size", "category", "ordering"]
|
|
328
|
+
},
|
|
329
|
+
GRID_SIZE: {
|
|
330
|
+
name: "grid_size",
|
|
331
|
+
hasEcommerce: false,
|
|
332
|
+
destinations: ["DataLayer"],
|
|
333
|
+
requiredParams: ["brand", "slot_per_line"]
|
|
322
334
|
}
|
|
323
335
|
};
|
|
324
336
|
|
|
325
|
-
// src/
|
|
337
|
+
// src/pushToDatalayer.ts
|
|
326
338
|
function pushToDataLayer(event, context) {
|
|
327
339
|
const targetWindow = context.window || (typeof window !== "undefined" ? window : null);
|
|
328
340
|
if (!targetWindow) return;
|
|
@@ -333,74 +345,13 @@ var AzzasTracker = (() => {
|
|
|
333
345
|
targetWindow.dataLayer = targetWindow.dataLayer || [];
|
|
334
346
|
if (eventConfig == null ? void 0 : eventConfig.hasEcommerce) {
|
|
335
347
|
targetWindow.dataLayer.push({ ecommerce: null });
|
|
336
|
-
targetWindow.dataLayer.push({ event, ecommerce: payload });
|
|
348
|
+
targetWindow.dataLayer.push({ event: event.toLowerCase(), ecommerce: payload });
|
|
337
349
|
} else {
|
|
338
|
-
targetWindow.dataLayer.push(Object.assign({ event }, payload));
|
|
350
|
+
targetWindow.dataLayer.push(Object.assign({ event: event.toLowerCase() }, payload));
|
|
339
351
|
}
|
|
340
352
|
}
|
|
341
353
|
|
|
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
|
|
354
|
+
// src/params/legacy/utils/index.ts
|
|
404
355
|
async function getProductDataById(id) {
|
|
405
356
|
try {
|
|
406
357
|
const response = await fetch(
|
|
@@ -602,7 +553,7 @@ var AzzasTracker = (() => {
|
|
|
602
553
|
return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
|
|
603
554
|
}
|
|
604
555
|
|
|
605
|
-
// src/params/resolvers/brand/fromOrderForm.ts
|
|
556
|
+
// src/params/legacy/resolvers/brand/fromOrderForm.ts
|
|
606
557
|
function brandFromOrderForm(context) {
|
|
607
558
|
var _a;
|
|
608
559
|
if (!context.orderForm && !((_a = context.orderForm.items) == null ? void 0 : _a.length)) return null;
|
|
@@ -610,14 +561,14 @@ var AzzasTracker = (() => {
|
|
|
610
561
|
return normalizeBrand(items);
|
|
611
562
|
}
|
|
612
563
|
|
|
613
|
-
// src/params/resolvers/brand/fromItem.ts
|
|
564
|
+
// src/params/legacy/resolvers/brand/fromItem.ts
|
|
614
565
|
function brandFromItem(context) {
|
|
615
566
|
var _a;
|
|
616
567
|
const { item } = context;
|
|
617
568
|
return normalizeBrand(((_a = item == null ? void 0 : item.additionalInfo) == null ? void 0 : _a.brandName) || item.brand || item.item_brand);
|
|
618
569
|
}
|
|
619
570
|
|
|
620
|
-
// src/params/brand.ts
|
|
571
|
+
// src/params/legacy/brand.ts
|
|
621
572
|
function getBrand(context, eventName) {
|
|
622
573
|
if (context == null ? void 0 : context.brand) return normalizeBrand(context.brand) || context.brand || null;
|
|
623
574
|
switch (eventName) {
|
|
@@ -641,7 +592,7 @@ var AzzasTracker = (() => {
|
|
|
641
592
|
}
|
|
642
593
|
}
|
|
643
594
|
|
|
644
|
-
// src/params/utils/itemListAttribution.ts
|
|
595
|
+
// src/params/legacy/utils/itemListAttribution.ts
|
|
645
596
|
var LAST_SELECTED_ITEM_KEY = "last_selected_item";
|
|
646
597
|
var STORAGE_VIEWED = "last_viewed_item";
|
|
647
598
|
var CART_LIST_HISTORY_KEY = "cart_list_history";
|
|
@@ -822,7 +773,7 @@ var AzzasTracker = (() => {
|
|
|
822
773
|
saveSelectedItem(productId, listName);
|
|
823
774
|
}
|
|
824
775
|
|
|
825
|
-
// src/params/resolvers/items/fromOrderForm.ts
|
|
776
|
+
// src/params/legacy/resolvers/items/fromOrderForm.ts
|
|
826
777
|
async function itemsFromOrderForm(context) {
|
|
827
778
|
var _a;
|
|
828
779
|
const items = ((_a = context.orderForm) == null ? void 0 : _a.items) || [];
|
|
@@ -854,7 +805,7 @@ var AzzasTracker = (() => {
|
|
|
854
805
|
);
|
|
855
806
|
}
|
|
856
807
|
|
|
857
|
-
// src/params/resolvers/items/fromItem.ts
|
|
808
|
+
// src/params/legacy/resolvers/items/fromItem.ts
|
|
858
809
|
async function itemsFromItem(context, event) {
|
|
859
810
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
860
811
|
const { item, orderForm, itemListName } = context;
|
|
@@ -890,7 +841,7 @@ var AzzasTracker = (() => {
|
|
|
890
841
|
];
|
|
891
842
|
}
|
|
892
843
|
|
|
893
|
-
// src/params/resolvers/items/fromList.ts
|
|
844
|
+
// src/params/legacy/resolvers/items/fromList.ts
|
|
894
845
|
async function itemsFromList(context) {
|
|
895
846
|
return ((context == null ? void 0 : context.list) || []).map((item) => {
|
|
896
847
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
@@ -911,7 +862,7 @@ var AzzasTracker = (() => {
|
|
|
911
862
|
});
|
|
912
863
|
}
|
|
913
864
|
|
|
914
|
-
// src/params/resolvers/items/fromPdp.ts
|
|
865
|
+
// src/params/legacy/resolvers/items/fromPdp.ts
|
|
915
866
|
async function itemsFromPDP(context, event) {
|
|
916
867
|
var _a, _b, _c, _d;
|
|
917
868
|
const { item, value, brand } = context;
|
|
@@ -942,7 +893,7 @@ var AzzasTracker = (() => {
|
|
|
942
893
|
];
|
|
943
894
|
}
|
|
944
895
|
|
|
945
|
-
// src/params/resolvers/items/fromBanner.ts
|
|
896
|
+
// src/params/legacy/resolvers/items/fromBanner.ts
|
|
946
897
|
async function itemsFromBanner(context) {
|
|
947
898
|
var _a;
|
|
948
899
|
const isUrlFromPDP = isPDP(context == null ? void 0 : context.bannerUrl);
|
|
@@ -963,7 +914,7 @@ var AzzasTracker = (() => {
|
|
|
963
914
|
};
|
|
964
915
|
}
|
|
965
916
|
|
|
966
|
-
// src/params/items.ts
|
|
917
|
+
// src/params/legacy/items.ts
|
|
967
918
|
function getItems(context, eventName) {
|
|
968
919
|
if (context == null ? void 0 : context.items) return context.items;
|
|
969
920
|
switch (eventName) {
|
|
@@ -997,7 +948,72 @@ var AzzasTracker = (() => {
|
|
|
997
948
|
}
|
|
998
949
|
}
|
|
999
950
|
|
|
1000
|
-
// src/
|
|
951
|
+
// src/core/utils.ts
|
|
952
|
+
var isDebugMode = () => {
|
|
953
|
+
if (typeof window === "undefined") return false;
|
|
954
|
+
try {
|
|
955
|
+
const params = new URLSearchParams(window.location.search);
|
|
956
|
+
return params.has("__trk_inspect__");
|
|
957
|
+
} catch (e) {
|
|
958
|
+
return window.location.search.indexOf("__trk_inspect__") !== -1;
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
var paymentTypeMap = [
|
|
962
|
+
["vale", "vale cr\xE9dito"],
|
|
963
|
+
["pagaleve", "pix"],
|
|
964
|
+
["pix parcel", "pix parcelado"],
|
|
965
|
+
["pix", "pix"],
|
|
966
|
+
["apple", "apple pay"],
|
|
967
|
+
["google", "google pay"],
|
|
968
|
+
["boleto", "boleto"],
|
|
969
|
+
["paypal", "paypal"],
|
|
970
|
+
["cred", "cart\xE3o"],
|
|
971
|
+
["visa", "cart\xE3o"],
|
|
972
|
+
["master", "cart\xE3o"],
|
|
973
|
+
["amex", "cart\xE3o"],
|
|
974
|
+
["elo", "cart\xE3o"],
|
|
975
|
+
["hiper", "cart\xE3o"],
|
|
976
|
+
["diner", "cart\xE3o"],
|
|
977
|
+
["deb", "cart\xE3o"]
|
|
978
|
+
];
|
|
979
|
+
var toNum = (val) => typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
|
|
980
|
+
var documentToHash = async (document2) => {
|
|
981
|
+
if (!document2) return null;
|
|
982
|
+
const encoder = new TextEncoder();
|
|
983
|
+
const data = encoder.encode(document2);
|
|
984
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
985
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
986
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
987
|
+
};
|
|
988
|
+
var SIZE_ORDER = {
|
|
989
|
+
alfabetico: ["PP", "P", "M", "G", "GG", "XG", "XGG", "EG", "EGG", "3G", "4G", "5G"],
|
|
990
|
+
infantil: ["RN", "0-3M", "3-6M", "6-9M", "9-12M", "12-18M", "18-24M", "P", "M", "G", "GG"]
|
|
991
|
+
};
|
|
992
|
+
var detectSizeType = (sizes) => {
|
|
993
|
+
if (sizes.every((s) => /^\d+([.,]\d+)?$/.test(s))) return "numerico";
|
|
994
|
+
if (sizes.some((s) => /^(RN|\d+-\d+M|\d+M)$/i.test(s))) return "infantil";
|
|
995
|
+
if (sizes.every((s) => SIZE_ORDER.alfabetico.includes(s.toUpperCase()))) return "alfabetico";
|
|
996
|
+
return "desconhecido";
|
|
997
|
+
};
|
|
998
|
+
var sortSizes = (sizes) => {
|
|
999
|
+
const unique = [...new Set(sizes.filter(Boolean))];
|
|
1000
|
+
const type = detectSizeType(unique);
|
|
1001
|
+
if (type === "numerico") {
|
|
1002
|
+
return unique.sort((a, b) => parseFloat(a) - parseFloat(b));
|
|
1003
|
+
}
|
|
1004
|
+
if (type === "alfabetico" || type === "infantil") {
|
|
1005
|
+
const order = SIZE_ORDER[type];
|
|
1006
|
+
return unique.sort((a, b) => {
|
|
1007
|
+
const ia = order.indexOf(a.toUpperCase());
|
|
1008
|
+
const ib = order.indexOf(b.toUpperCase());
|
|
1009
|
+
return (ia === -1 ? 999 : ia) - (ib === -1 ? 999 : ib);
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
return unique;
|
|
1013
|
+
};
|
|
1014
|
+
var capitalize = (str) => str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
|
|
1015
|
+
|
|
1016
|
+
// src/params/legacy/resolvers/paymentType/fromOrderForm.ts
|
|
1001
1017
|
function paymentTypeFromOrderForm(context) {
|
|
1002
1018
|
var _a, _b, _c;
|
|
1003
1019
|
if (context.payment_type) return context.payment_type;
|
|
@@ -1014,7 +1030,7 @@ var AzzasTracker = (() => {
|
|
|
1014
1030
|
return match ? match[1] : null;
|
|
1015
1031
|
}
|
|
1016
1032
|
|
|
1017
|
-
// src/params/resolvers/paymentType/fromOrderGroup.ts
|
|
1033
|
+
// src/params/legacy/resolvers/paymentType/fromOrderGroup.ts
|
|
1018
1034
|
function paymentTypeFromOrderGroup(context) {
|
|
1019
1035
|
var _a, _b, _c, _d;
|
|
1020
1036
|
if (!context.orderForm) return null;
|
|
@@ -1027,7 +1043,7 @@ var AzzasTracker = (() => {
|
|
|
1027
1043
|
return match ? match[1] : null;
|
|
1028
1044
|
}
|
|
1029
1045
|
|
|
1030
|
-
// src/params/paymentType.ts
|
|
1046
|
+
// src/params/legacy/paymentType.ts
|
|
1031
1047
|
function getPaymentType(context, eventName) {
|
|
1032
1048
|
if (context == null ? void 0 : context.paymentType) return context.paymentType;
|
|
1033
1049
|
switch (eventName) {
|
|
@@ -1043,36 +1059,36 @@ var AzzasTracker = (() => {
|
|
|
1043
1059
|
}
|
|
1044
1060
|
|
|
1045
1061
|
// src/params/userInfo.ts
|
|
1046
|
-
|
|
1062
|
+
var PROD_DOMAINS = {
|
|
1063
|
+
"animale": {
|
|
1064
|
+
"store": "https://www.animale.com.br",
|
|
1065
|
+
"checkout": "https://secure.animale.com.br"
|
|
1066
|
+
},
|
|
1067
|
+
"farm": {
|
|
1068
|
+
"store": "https://lojafarm.myvtex.com"
|
|
1069
|
+
},
|
|
1070
|
+
"mariafilo": {
|
|
1071
|
+
"store": "https://mariafilo.myvtex.com",
|
|
1072
|
+
"checkout": "https://secure.mariafilo.com.br"
|
|
1073
|
+
},
|
|
1074
|
+
"lojacrisbarros": {
|
|
1075
|
+
"store": "https://lojacrisbarros.myvtex.com",
|
|
1076
|
+
"checkout": "https://secure.crisbarros.com.br"
|
|
1077
|
+
},
|
|
1078
|
+
"lojaoffpremium": {
|
|
1079
|
+
"store": "https://lojaoffpremium.myvtex.com",
|
|
1080
|
+
"checkout": "https://secure.offpremium.com.br"
|
|
1081
|
+
},
|
|
1082
|
+
"bynv": {
|
|
1083
|
+
"store": "https://bynv.myvtex.com"
|
|
1084
|
+
},
|
|
1085
|
+
"fabula": {
|
|
1086
|
+
"store": "https://lojafabula.myvtex.com"
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
async function getUserInfo(context) {
|
|
1047
1090
|
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"];
|
|
1091
|
+
const domain = (_a = PROD_DOMAINS[context.account || "animale"]) == null ? void 0 : _a[context.platform || "store"];
|
|
1076
1092
|
if (!domain) return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
|
|
1077
1093
|
try {
|
|
1078
1094
|
const api = `${domain}/_v/user-info`;
|
|
@@ -1130,12 +1146,13 @@ var AzzasTracker = (() => {
|
|
|
1130
1146
|
}
|
|
1131
1147
|
}
|
|
1132
1148
|
|
|
1133
|
-
// src/params/index.ts
|
|
1134
|
-
var
|
|
1149
|
+
// src/params/legacy/index.ts
|
|
1150
|
+
var legacyGetters = {
|
|
1135
1151
|
brand: getBrand,
|
|
1136
1152
|
items: getItems,
|
|
1137
1153
|
payment_type: getPaymentType,
|
|
1138
1154
|
user_info: getUserInfo,
|
|
1155
|
+
// global
|
|
1139
1156
|
content_type: (context, eventName) => {
|
|
1140
1157
|
if (context == null ? void 0 : context.content_type) return context.content_type;
|
|
1141
1158
|
return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
|
|
@@ -1331,30 +1348,598 @@ var AzzasTracker = (() => {
|
|
|
1331
1348
|
}
|
|
1332
1349
|
};
|
|
1333
1350
|
|
|
1334
|
-
// src/
|
|
1335
|
-
|
|
1351
|
+
// src/params/adapters/meta/index.ts
|
|
1352
|
+
var metaAdapters = {
|
|
1353
|
+
user_info: getUserInfo,
|
|
1354
|
+
brand: (context) => {
|
|
1355
|
+
return context.meta.brand || null;
|
|
1356
|
+
},
|
|
1357
|
+
content_type: (context) => {
|
|
1358
|
+
return context.meta.content_type || null;
|
|
1359
|
+
},
|
|
1360
|
+
region: (context) => {
|
|
1361
|
+
return context.meta.region || null;
|
|
1362
|
+
},
|
|
1363
|
+
pre_filled: (context) => {
|
|
1364
|
+
return !!context.preFilled;
|
|
1365
|
+
},
|
|
1366
|
+
currency: (context) => {
|
|
1367
|
+
if (context == null ? void 0 : context.currency) return context.currency;
|
|
1368
|
+
return "BRL";
|
|
1369
|
+
},
|
|
1370
|
+
slot_per_line: (context) => {
|
|
1371
|
+
var _a;
|
|
1372
|
+
return (_a = context.meta.slot_per_line) != null ? _a : null;
|
|
1373
|
+
},
|
|
1374
|
+
search_term: (context) => {
|
|
1375
|
+
return context.meta.search_term || null;
|
|
1376
|
+
},
|
|
1377
|
+
search_found: (context) => {
|
|
1378
|
+
return context.meta.search_found || null;
|
|
1379
|
+
},
|
|
1380
|
+
search_quantity: (context) => {
|
|
1381
|
+
return context.meta.search_quantity || 0;
|
|
1382
|
+
},
|
|
1383
|
+
promotion_name: (context) => {
|
|
1384
|
+
return context.meta.promotion_name || null;
|
|
1385
|
+
},
|
|
1386
|
+
creative_name: (context) => {
|
|
1387
|
+
return context.meta.creative_name || null;
|
|
1388
|
+
},
|
|
1389
|
+
creative_slot: (context) => {
|
|
1390
|
+
return context.meta.creative_slot || null;
|
|
1391
|
+
},
|
|
1392
|
+
size: (context) => {
|
|
1393
|
+
return context.size || null;
|
|
1394
|
+
},
|
|
1395
|
+
item_ref: (context) => {
|
|
1396
|
+
return context.itemRef || null;
|
|
1397
|
+
},
|
|
1398
|
+
method: (context) => {
|
|
1399
|
+
return context.method || null;
|
|
1400
|
+
},
|
|
1401
|
+
type: (context) => {
|
|
1402
|
+
return context.type || null;
|
|
1403
|
+
},
|
|
1404
|
+
color: (context) => {
|
|
1405
|
+
return context.meta.color || null;
|
|
1406
|
+
},
|
|
1407
|
+
price_range: (context) => {
|
|
1408
|
+
return context.meta.price_range || null;
|
|
1409
|
+
},
|
|
1410
|
+
category: (context) => {
|
|
1411
|
+
return context.meta.category || null;
|
|
1412
|
+
},
|
|
1413
|
+
ordering: (context) => {
|
|
1414
|
+
return context.meta.ordering || null;
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
// src/params/adapters/deco/utils.ts
|
|
1419
|
+
var getItemCategory3 = (item) => {
|
|
1420
|
+
var _a;
|
|
1421
|
+
const value = item == null ? void 0 : item.category;
|
|
1422
|
+
if (!value) return "Cole\xE7\xE3o";
|
|
1423
|
+
const text = Array.isArray(value) ? value.join(" ") : String(value);
|
|
1424
|
+
const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
|
|
1425
|
+
return match != null ? match : "Cole\xE7\xE3o";
|
|
1426
|
+
};
|
|
1427
|
+
var getItemCategory22 = (item) => {
|
|
1428
|
+
var _a, _b, _c, _d;
|
|
1429
|
+
const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
|
|
1430
|
+
const categories = (_b = (_a = item.category) == null ? void 0 : _a.split(">")) != null ? _b : [];
|
|
1431
|
+
const last = (_c = categories[categories.length - 1]) != null ? _c : "";
|
|
1432
|
+
const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES.test(c));
|
|
1433
|
+
const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
|
|
1434
|
+
return capitalize(deepest);
|
|
1435
|
+
};
|
|
1436
|
+
var resizeVtexImage2 = (url, width = 500, height = 500) => {
|
|
1437
|
+
return url == null ? void 0 : url.replace(
|
|
1438
|
+
/(\/arquivos\/ids\/\d+)-\d+-\d+\//,
|
|
1439
|
+
`$1-${width}-${height}/`
|
|
1440
|
+
);
|
|
1441
|
+
};
|
|
1442
|
+
function getItemShippingTier2() {
|
|
1443
|
+
return null;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
// src/params/adapters/deco/index.ts
|
|
1447
|
+
var IN_STOCK_SCHEMA = "https://schema.org/InStock";
|
|
1448
|
+
var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
|
|
1449
|
+
var decoAdapter = {
|
|
1450
|
+
...metaAdapters,
|
|
1451
|
+
// global adapters
|
|
1452
|
+
items: (context) => {
|
|
1453
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1454
|
+
if (context == null ? void 0 : context.products) {
|
|
1455
|
+
return context.products.map((item) => {
|
|
1456
|
+
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;
|
|
1457
|
+
const COLOR_REGEX = /^[^_]+_/;
|
|
1458
|
+
const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
|
|
1459
|
+
(s) => s.priceType === LIST_PRICE_SCHEMA
|
|
1460
|
+
)) == null ? void 0 : _c.price;
|
|
1461
|
+
return {
|
|
1462
|
+
quantity: 1,
|
|
1463
|
+
index: (_d = item == null ? void 0 : item.index) != null ? _d : 0,
|
|
1464
|
+
item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
|
|
1465
|
+
item_name: (_h = item.alternateName) != null ? _h : null,
|
|
1466
|
+
price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
|
|
1467
|
+
discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
|
|
1468
|
+
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,
|
|
1469
|
+
// cor
|
|
1470
|
+
item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
|
|
1471
|
+
// tamanho
|
|
1472
|
+
item_shipping_tier: getItemShippingTier2(),
|
|
1473
|
+
item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
|
|
1474
|
+
item_category: (_s = getItemCategory3(item)) != null ? _s : null,
|
|
1475
|
+
item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
|
|
1476
|
+
item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
|
|
1477
|
+
item_sku: (_v = item.sku) != null ? _v : null,
|
|
1478
|
+
item_url: (_w = item.url) != null ? _w : null,
|
|
1479
|
+
image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
|
|
1480
|
+
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,
|
|
1481
|
+
item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
return null;
|
|
1486
|
+
},
|
|
1487
|
+
// brand: (context: DecoBrandContext) => {
|
|
1488
|
+
// if (context?.brand) return context.brand
|
|
1489
|
+
// if (context?.products) {
|
|
1490
|
+
// return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
|
|
1491
|
+
// }
|
|
1492
|
+
// return null
|
|
1493
|
+
// },
|
|
1494
|
+
line_items: (context) => {
|
|
1495
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1496
|
+
if (context == null ? void 0 : context.products) {
|
|
1497
|
+
return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
|
|
1498
|
+
}
|
|
1499
|
+
return null;
|
|
1500
|
+
},
|
|
1501
|
+
value: (context) => {
|
|
1502
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1503
|
+
if (context == null ? void 0 : context.products) {
|
|
1504
|
+
return context.products.map((item) => {
|
|
1505
|
+
var _a;
|
|
1506
|
+
return (_a = item.offers) == null ? void 0 : _a.lowPrice;
|
|
1507
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1508
|
+
}
|
|
1509
|
+
return null;
|
|
1510
|
+
},
|
|
1511
|
+
available_grid: (context) => {
|
|
1512
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1513
|
+
if (context == null ? void 0 : context.products) {
|
|
1514
|
+
const sizes = context.products.flatMap(
|
|
1515
|
+
(product) => {
|
|
1516
|
+
var _a, _b, _c;
|
|
1517
|
+
return (_c = (_b = (_a = product.isVariantOf) == null ? void 0 : _a.hasVariant) == null ? void 0 : _b.filter(
|
|
1518
|
+
(variant) => {
|
|
1519
|
+
var _a2, _b2;
|
|
1520
|
+
return (_b2 = (_a2 = variant.offers) == null ? void 0 : _a2.offers) == null ? void 0 : _b2.some((o) => o.availability === IN_STOCK_SCHEMA);
|
|
1521
|
+
}
|
|
1522
|
+
).map((variant) => {
|
|
1523
|
+
var _a2;
|
|
1524
|
+
return (_a2 = variant.name) == null ? void 0 : _a2.split(" - ")[1];
|
|
1525
|
+
}).filter((name) => Boolean(name))) != null ? _c : [];
|
|
1526
|
+
}
|
|
1527
|
+
);
|
|
1528
|
+
const result = sortSizes(sizes).join(",").trim();
|
|
1529
|
+
return result || null;
|
|
1530
|
+
}
|
|
1531
|
+
return null;
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
// src/params/adapters/orderForm/index.ts
|
|
1536
|
+
var orderFormAdapters = {
|
|
1537
|
+
// orderform
|
|
1538
|
+
payment_type: getPaymentType,
|
|
1539
|
+
total_discount: (context) => {
|
|
1540
|
+
var _a, _b;
|
|
1541
|
+
if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
|
|
1542
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1543
|
+
const items = context.orderForm.items;
|
|
1544
|
+
const totalDiscount = items.reduce((acc, item) => {
|
|
1545
|
+
const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
1546
|
+
return acc + unitDiscount * item.quantity;
|
|
1547
|
+
}, 0);
|
|
1548
|
+
const discounts = totalsList.find((t) => t.id === "Discounts");
|
|
1549
|
+
return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
1550
|
+
},
|
|
1551
|
+
subtotal: (context) => {
|
|
1552
|
+
var _a, _b;
|
|
1553
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1554
|
+
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
1555
|
+
return subtotal;
|
|
1556
|
+
},
|
|
1557
|
+
coupon_message: (context) => {
|
|
1558
|
+
var _a;
|
|
1559
|
+
if (context.couponMessage) return context.couponMessage;
|
|
1560
|
+
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
1561
|
+
if (messages.length === 0) return null;
|
|
1562
|
+
const couponMessages = messages.filter(
|
|
1563
|
+
(msg) => msg.text.toLowerCase().includes("cupom")
|
|
1564
|
+
);
|
|
1565
|
+
if (couponMessages.length === 0) return null;
|
|
1566
|
+
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
1567
|
+
},
|
|
1568
|
+
flag_pickup: (context) => {
|
|
1569
|
+
var _a;
|
|
1570
|
+
const orderForm = context.orderForm;
|
|
1571
|
+
if (!orderForm) return null;
|
|
1572
|
+
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
1573
|
+
const hasPickup = logisticsInfo.some(
|
|
1574
|
+
(info) => {
|
|
1575
|
+
var _a2;
|
|
1576
|
+
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
1577
|
+
}
|
|
1578
|
+
);
|
|
1579
|
+
return hasPickup;
|
|
1580
|
+
},
|
|
1581
|
+
shippings: (context) => {
|
|
1582
|
+
const orderForm = context.orderForm;
|
|
1583
|
+
if (!orderForm) return null;
|
|
1584
|
+
const groupShipping = {};
|
|
1585
|
+
for (const info of orderForm.shippingData.logisticsInfo) {
|
|
1586
|
+
const item = orderForm.items[info.itemIndex];
|
|
1587
|
+
if (!item) continue;
|
|
1588
|
+
for (const sla of info.slas) {
|
|
1589
|
+
const key = sla.name;
|
|
1590
|
+
if (!groupShipping[key]) {
|
|
1591
|
+
groupShipping[key] = {
|
|
1592
|
+
shipping_tier: sla.name,
|
|
1593
|
+
delivery_time: parseInt(sla.shippingEstimate),
|
|
1594
|
+
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
1595
|
+
line_items: []
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
groupShipping[key].line_items.push(item.id);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
const shippings = Object.values(groupShipping).map((s) => ({
|
|
1602
|
+
shipping: s.shipping,
|
|
1603
|
+
shipping_tier: s.shipping_tier,
|
|
1604
|
+
delivery_time: s.delivery_time,
|
|
1605
|
+
line_items: s.line_items.join(",")
|
|
1606
|
+
}));
|
|
1607
|
+
return shippings || null;
|
|
1608
|
+
},
|
|
1609
|
+
shipping: (context) => {
|
|
1610
|
+
var _a, _b, _c;
|
|
1611
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1612
|
+
return logistics.reduce((total, item) => {
|
|
1613
|
+
var _a2, _b2;
|
|
1614
|
+
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
1615
|
+
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
1616
|
+
}, 0);
|
|
1617
|
+
},
|
|
1618
|
+
shipping_tier: (context) => {
|
|
1619
|
+
var _a, _b, _c;
|
|
1620
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1621
|
+
const selectedSlas = logistics.map((item) => {
|
|
1622
|
+
var _a2;
|
|
1623
|
+
if (!item.selectedSla) return null;
|
|
1624
|
+
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
1625
|
+
}).filter(Boolean);
|
|
1626
|
+
if (selectedSlas.length === 0) return null;
|
|
1627
|
+
const uniqueTiers = Array.from(
|
|
1628
|
+
new Map(
|
|
1629
|
+
selectedSlas.map((sla) => {
|
|
1630
|
+
var _a2;
|
|
1631
|
+
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
1632
|
+
return [key, sla];
|
|
1633
|
+
})
|
|
1634
|
+
).values()
|
|
1635
|
+
);
|
|
1636
|
+
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
1637
|
+
var _a2, _b2;
|
|
1638
|
+
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1639
|
+
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1640
|
+
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
1641
|
+
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
1642
|
+
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
1643
|
+
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
1644
|
+
});
|
|
1645
|
+
const shippingTier = sortedTiers.map((sla) => {
|
|
1646
|
+
var _a2;
|
|
1647
|
+
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;
|
|
1648
|
+
}).filter(Boolean).join(", ");
|
|
1649
|
+
return shippingTier || null;
|
|
1650
|
+
},
|
|
1651
|
+
transaction_id: (context) => {
|
|
1652
|
+
var _a, _b;
|
|
1653
|
+
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
1654
|
+
},
|
|
1655
|
+
coupon: (context) => {
|
|
1656
|
+
var _a, _b;
|
|
1657
|
+
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
1658
|
+
},
|
|
1659
|
+
seller_cod_name: (context) => {
|
|
1660
|
+
return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
// src/params/adapters/headless/utils.ts
|
|
1665
|
+
var getItemCategory5 = (item) => {
|
|
1666
|
+
const keywords = ["outlet", "bazar", "sale"];
|
|
1667
|
+
const regex = new RegExp(keywords.join("|"), "i");
|
|
1668
|
+
const value = item == null ? void 0 : item.categories;
|
|
1669
|
+
if (value) {
|
|
1670
|
+
const textToTest = Array.isArray(value) ? value.join(" ") : String(value);
|
|
1671
|
+
const match = textToTest.match(regex);
|
|
1672
|
+
if (match) {
|
|
1673
|
+
return match[0].toLowerCase();
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
return "Cole\xE7\xE3o";
|
|
1677
|
+
};
|
|
1678
|
+
var getItemCategory23 = (item) => {
|
|
1679
|
+
var _a, _b, _c;
|
|
1680
|
+
const avoidList = /outlet|bazar|sale/i;
|
|
1681
|
+
const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
|
|
1682
|
+
const categoryHierarchy = lastCategory.split("/").filter(Boolean);
|
|
1683
|
+
const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
|
|
1684
|
+
return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
|
|
1685
|
+
};
|
|
1686
|
+
function resizeVtexImage3(url, width = 500, height = 500) {
|
|
1687
|
+
return url == null ? void 0 : url.replace(
|
|
1688
|
+
/(\/arquivos\/ids\/\d+)-\d+-\d+\//,
|
|
1689
|
+
`$1-${width}-${height}/`
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
// src/params/adapters/headless/zones/PDP.ts
|
|
1694
|
+
var HeadlessPdpZone = {
|
|
1695
|
+
items: (context) => {
|
|
1696
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1697
|
+
if (context == null ? void 0 : context.products) {
|
|
1698
|
+
return context.products.map((item) => {
|
|
1699
|
+
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;
|
|
1700
|
+
const listPrice = (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.ListPrice;
|
|
1701
|
+
const price = (_b = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _b[0].commertialOffer.Price;
|
|
1702
|
+
return {
|
|
1703
|
+
quantity: 1,
|
|
1704
|
+
index: (_c = item == null ? void 0 : item.index) != null ? _c : null,
|
|
1705
|
+
item_brand: (_d = item.brand) != null ? _d : null,
|
|
1706
|
+
item_name: (_e = item.productName) != null ? _e : null,
|
|
1707
|
+
price: price != null ? price : null,
|
|
1708
|
+
discount: Number(listPrice) - Number(price),
|
|
1709
|
+
item_variant: (_h = (_g = (_f = item.items[0]) == null ? void 0 : _f.name) == null ? void 0 : _g.split(" - ")[0]) != null ? _h : null,
|
|
1710
|
+
item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
|
|
1711
|
+
item_ref: (_l = item.productReference) != null ? _l : null,
|
|
1712
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1713
|
+
item_category: getItemCategory5(item),
|
|
1714
|
+
item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
|
|
1715
|
+
item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
|
|
1716
|
+
item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
|
|
1717
|
+
item_url: (_q = item.link) != null ? _q : null,
|
|
1718
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1719
|
+
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,
|
|
1720
|
+
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,
|
|
1721
|
+
item_list_name: (_y = item.item_list_name) != null ? _y : null
|
|
1722
|
+
};
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
return null;
|
|
1726
|
+
},
|
|
1727
|
+
value: (context) => {
|
|
1728
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1729
|
+
if (context == null ? void 0 : context.products) {
|
|
1730
|
+
return context.products.map((item) => {
|
|
1731
|
+
var _a;
|
|
1732
|
+
return (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.Price;
|
|
1733
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1734
|
+
}
|
|
1735
|
+
return null;
|
|
1736
|
+
},
|
|
1737
|
+
line_items: (context) => {
|
|
1738
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1739
|
+
if (context == null ? void 0 : context.products) {
|
|
1740
|
+
return context.products.map((item) => item.productId).filter((id) => Boolean(id));
|
|
1741
|
+
}
|
|
1742
|
+
return null;
|
|
1743
|
+
},
|
|
1744
|
+
brand: (context) => {
|
|
1745
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1746
|
+
if (context == null ? void 0 : context.products) {
|
|
1747
|
+
return context.products.map((p) => p.brand).join().trim();
|
|
1748
|
+
}
|
|
1749
|
+
return null;
|
|
1750
|
+
}
|
|
1751
|
+
};
|
|
1752
|
+
|
|
1753
|
+
// src/params/adapters/headless/zones/PDC.ts
|
|
1754
|
+
var HeadlessPdcZone = {
|
|
1755
|
+
items: (context) => {
|
|
1756
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1757
|
+
if (context == null ? void 0 : context.products) {
|
|
1758
|
+
return context.products.map((item) => {
|
|
1759
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1760
|
+
const listPrice = item.offers.highPrice;
|
|
1761
|
+
const price = item.offers.lowPrice;
|
|
1762
|
+
return {
|
|
1763
|
+
quantity: 1,
|
|
1764
|
+
index: (_a = item == null ? void 0 : item.index) != null ? _a : 0,
|
|
1765
|
+
item_brand: (_b = item.brand.name) != null ? _b : null,
|
|
1766
|
+
item_name: (_c = item.name) != null ? _c : null,
|
|
1767
|
+
price: price != null ? price : null,
|
|
1768
|
+
discount: Number(listPrice) - Number(price),
|
|
1769
|
+
item_variant: (_f = (_e = (_d = item.isVariantOf) == null ? void 0 : _d.hasVariant) == null ? void 0 : _e[0].name.split(" - ")[0]) != null ? _f : null,
|
|
1770
|
+
item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
|
|
1771
|
+
item_ref: null,
|
|
1772
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1773
|
+
item_category: getItemCategory5(item),
|
|
1774
|
+
item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
|
|
1775
|
+
item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
|
|
1776
|
+
item_sku: (_l = item.sku) != null ? _l : null,
|
|
1777
|
+
item_url: null,
|
|
1778
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1779
|
+
image_url: (_n = resizeVtexImage3((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
|
|
1780
|
+
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,
|
|
1781
|
+
item_list_name: (_t = item.item_list_name) != null ? _t : null
|
|
1782
|
+
};
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
return null;
|
|
1786
|
+
},
|
|
1787
|
+
value: (context) => {
|
|
1788
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1789
|
+
if (context == null ? void 0 : context.products) {
|
|
1790
|
+
return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1791
|
+
}
|
|
1792
|
+
return null;
|
|
1793
|
+
},
|
|
1794
|
+
line_items: (context) => {
|
|
1795
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1796
|
+
if (context == null ? void 0 : context.products) {
|
|
1797
|
+
return context.products.map((item) => item.id).filter((id) => Boolean(id));
|
|
1798
|
+
}
|
|
1799
|
+
return null;
|
|
1800
|
+
},
|
|
1801
|
+
brand: (context) => {
|
|
1802
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1803
|
+
if (context == null ? void 0 : context.products) {
|
|
1804
|
+
return context.products.map((p) => p.brand.name).join().trim();
|
|
1805
|
+
}
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
|
|
1810
|
+
// src/params/adapters/headless/index.ts
|
|
1811
|
+
var headlessAdapter = {
|
|
1812
|
+
...metaAdapters,
|
|
1813
|
+
// global adapters
|
|
1814
|
+
...orderFormAdapters,
|
|
1815
|
+
// orderForm adapters, confirmar se no storefront tem evento que usa essses params
|
|
1816
|
+
brand: (context) => {
|
|
1817
|
+
if (context.zone === "PDP") {
|
|
1818
|
+
return HeadlessPdpZone.brand(context);
|
|
1819
|
+
}
|
|
1820
|
+
if (context.zone === "PDC") {
|
|
1821
|
+
return HeadlessPdcZone.brand(context);
|
|
1822
|
+
}
|
|
1823
|
+
return null;
|
|
1824
|
+
},
|
|
1825
|
+
line_items: (context) => {
|
|
1826
|
+
if (context.zone === "PDP") {
|
|
1827
|
+
return HeadlessPdpZone.line_items(context);
|
|
1828
|
+
}
|
|
1829
|
+
if (context.zone === "PDC") {
|
|
1830
|
+
return HeadlessPdcZone.line_items(context);
|
|
1831
|
+
}
|
|
1832
|
+
return null;
|
|
1833
|
+
},
|
|
1834
|
+
value: (context) => {
|
|
1835
|
+
if (context.zone === "PDP") {
|
|
1836
|
+
return HeadlessPdpZone.value(context);
|
|
1837
|
+
}
|
|
1838
|
+
if (context.zone === "PDC") {
|
|
1839
|
+
return HeadlessPdcZone.value(context);
|
|
1840
|
+
}
|
|
1841
|
+
return null;
|
|
1842
|
+
},
|
|
1843
|
+
items: (context) => {
|
|
1844
|
+
if (context.zone === "PDP") {
|
|
1845
|
+
return HeadlessPdpZone.items(context);
|
|
1846
|
+
}
|
|
1847
|
+
if (context.zone === "PDC") {
|
|
1848
|
+
return HeadlessPdcZone.items(context);
|
|
1849
|
+
}
|
|
1850
|
+
},
|
|
1851
|
+
// param used only in one Zone, the PDP; no need condition
|
|
1852
|
+
available_grid: (context) => {
|
|
1853
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1854
|
+
if (context == null ? void 0 : context.products) {
|
|
1855
|
+
const sizes = context.products.flatMap((p) => p.items.map((i) => i.Tamanho[0]));
|
|
1856
|
+
const result = sortSizes(sizes).join(",");
|
|
1857
|
+
return result || null;
|
|
1858
|
+
}
|
|
1859
|
+
return null;
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
|
|
1863
|
+
// src/params/adapters/pickup/utils.ts
|
|
1864
|
+
var getShippingTier = (sla) => {
|
|
1865
|
+
var _a, _b;
|
|
1866
|
+
const isPickup = sla.deliveryChannel === "pickup-in-point" /* PickupInPoint */;
|
|
1867
|
+
if (isPickup) {
|
|
1868
|
+
const storeName = (_b = (_a = sla.pickupStoreInfo) == null ? void 0 : _a.friendlyName) == null ? void 0 : _b.trim();
|
|
1869
|
+
return storeName ? `retirada em loja: ${storeName}` : "retirada em loja";
|
|
1870
|
+
}
|
|
1871
|
+
return sla.name ? `receba em casa: ${sla.name.toLowerCase()}` : "receba em casa";
|
|
1872
|
+
};
|
|
1873
|
+
var getDeliveryTime = (sla) => {
|
|
1874
|
+
const estimate = sla.shippingEstimate;
|
|
1875
|
+
if (!estimate) return 0;
|
|
1876
|
+
const days = parseInt(estimate, 10);
|
|
1877
|
+
return isNaN(days) ? 0 : days;
|
|
1878
|
+
};
|
|
1879
|
+
|
|
1880
|
+
// src/params/adapters/pickup/index.ts
|
|
1881
|
+
var pickupAdapter = {
|
|
1882
|
+
...metaAdapters,
|
|
1883
|
+
flag_pickup: (context) => {
|
|
1884
|
+
var _a;
|
|
1885
|
+
return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
|
|
1886
|
+
},
|
|
1887
|
+
shippings: (context) => {
|
|
1888
|
+
if (context.shippings) {
|
|
1889
|
+
return context.shippings.map((s) => {
|
|
1890
|
+
var _a, _b;
|
|
1891
|
+
return {
|
|
1892
|
+
line_items: (_a = s.line_items) != null ? _a : "",
|
|
1893
|
+
shipping: (_b = s.price) != null ? _b : 0,
|
|
1894
|
+
shipping_tier: getShippingTier(s),
|
|
1895
|
+
delivery_time: getDeliveryTime(s)
|
|
1896
|
+
};
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
return null;
|
|
1900
|
+
},
|
|
1901
|
+
zipcode: (context) => {
|
|
1902
|
+
var _a;
|
|
1903
|
+
return (_a = context.zipcode) != null ? _a : null;
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
// src/formatter.ts
|
|
1908
|
+
var adapters = {
|
|
1909
|
+
DECO: decoAdapter,
|
|
1910
|
+
HEADLESS: headlessAdapter,
|
|
1911
|
+
PICKUP: pickupAdapter
|
|
1912
|
+
};
|
|
1913
|
+
async function getParameters(context, eventName) {
|
|
1914
|
+
var _a;
|
|
1336
1915
|
const eventConfig = EVENTS[eventName];
|
|
1337
1916
|
if (!eventConfig) return;
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
)
|
|
1917
|
+
const currentAdapter = context.adapter;
|
|
1918
|
+
const getters = (_a = adapters[currentAdapter]) != null ? _a : legacyGetters;
|
|
1919
|
+
const entries = await Promise.all(
|
|
1920
|
+
eventConfig.requiredParams.map(async (param) => {
|
|
1921
|
+
const getter = getters[param];
|
|
1922
|
+
if (typeof getter !== "function") {
|
|
1923
|
+
console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
|
|
1924
|
+
return [param, null];
|
|
1925
|
+
}
|
|
1926
|
+
return [param, await getter(context, eventName)];
|
|
1927
|
+
})
|
|
1349
1928
|
);
|
|
1350
|
-
return
|
|
1929
|
+
return Object.fromEntries(entries);
|
|
1351
1930
|
}
|
|
1352
1931
|
|
|
1353
1932
|
// src/index.ts
|
|
1354
|
-
async function trackWebEvent(event, context
|
|
1933
|
+
async function trackWebEvent(event, context) {
|
|
1355
1934
|
try {
|
|
1356
1935
|
const parameters = await getParameters(context, event);
|
|
1357
|
-
|
|
1936
|
+
if (isDebugMode()) {
|
|
1937
|
+
console.log(`[DT v2] ${event}, context e parameters: `, {
|
|
1938
|
+
context,
|
|
1939
|
+
parameters
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
return await pushToDataLayer(
|
|
1358
1943
|
event,
|
|
1359
1944
|
Object.assign({}, parameters, { window: context.window })
|
|
1360
1945
|
);
|