@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.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: {
|
|
@@ -291,10 +291,22 @@ var EVENTS = {
|
|
|
291
291
|
hasEcommerce: false,
|
|
292
292
|
destinations: ["DataLayer"],
|
|
293
293
|
requiredParams: ["brand", "line_items", "size", "item_ref"]
|
|
294
|
+
},
|
|
295
|
+
REFINE_RESULTS: {
|
|
296
|
+
name: "refine_results",
|
|
297
|
+
hasEcommerce: false,
|
|
298
|
+
destinations: ["DataLayer"],
|
|
299
|
+
requiredParams: ["brand", "region", "color", "price_range", "size", "category", "ordering"]
|
|
300
|
+
},
|
|
301
|
+
GRID_SIZE: {
|
|
302
|
+
name: "grid_size",
|
|
303
|
+
hasEcommerce: false,
|
|
304
|
+
destinations: ["DataLayer"],
|
|
305
|
+
requiredParams: ["brand", "slot_per_line"]
|
|
294
306
|
}
|
|
295
307
|
};
|
|
296
308
|
|
|
297
|
-
// src/
|
|
309
|
+
// src/pushToDatalayer.ts
|
|
298
310
|
function pushToDataLayer(event, context) {
|
|
299
311
|
const targetWindow = context.window || (typeof window !== "undefined" ? window : null);
|
|
300
312
|
if (!targetWindow) return;
|
|
@@ -305,74 +317,13 @@ function pushToDataLayer(event, context) {
|
|
|
305
317
|
targetWindow.dataLayer = targetWindow.dataLayer || [];
|
|
306
318
|
if (eventConfig == null ? void 0 : eventConfig.hasEcommerce) {
|
|
307
319
|
targetWindow.dataLayer.push({ ecommerce: null });
|
|
308
|
-
targetWindow.dataLayer.push({ event, ecommerce: payload });
|
|
320
|
+
targetWindow.dataLayer.push({ event: event.toLowerCase(), ecommerce: payload });
|
|
309
321
|
} else {
|
|
310
|
-
targetWindow.dataLayer.push(Object.assign({ event }, payload));
|
|
322
|
+
targetWindow.dataLayer.push(Object.assign({ event: event.toLowerCase() }, payload));
|
|
311
323
|
}
|
|
312
324
|
}
|
|
313
325
|
|
|
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
|
|
326
|
+
// src/params/legacy/utils/index.ts
|
|
376
327
|
async function getProductDataById(id) {
|
|
377
328
|
try {
|
|
378
329
|
const response = await fetch(
|
|
@@ -574,7 +525,7 @@ function normalizeBrand(input) {
|
|
|
574
525
|
return uniqueSortedCodes.length > 0 ? uniqueSortedCodes.join("_") : null;
|
|
575
526
|
}
|
|
576
527
|
|
|
577
|
-
// src/params/resolvers/brand/fromOrderForm.ts
|
|
528
|
+
// src/params/legacy/resolvers/brand/fromOrderForm.ts
|
|
578
529
|
function brandFromOrderForm(context) {
|
|
579
530
|
var _a;
|
|
580
531
|
if (!context.orderForm && !((_a = context.orderForm.items) == null ? void 0 : _a.length)) return null;
|
|
@@ -582,14 +533,14 @@ function brandFromOrderForm(context) {
|
|
|
582
533
|
return normalizeBrand(items);
|
|
583
534
|
}
|
|
584
535
|
|
|
585
|
-
// src/params/resolvers/brand/fromItem.ts
|
|
536
|
+
// src/params/legacy/resolvers/brand/fromItem.ts
|
|
586
537
|
function brandFromItem(context) {
|
|
587
538
|
var _a;
|
|
588
539
|
const { item } = context;
|
|
589
540
|
return normalizeBrand(((_a = item == null ? void 0 : item.additionalInfo) == null ? void 0 : _a.brandName) || item.brand || item.item_brand);
|
|
590
541
|
}
|
|
591
542
|
|
|
592
|
-
// src/params/brand.ts
|
|
543
|
+
// src/params/legacy/brand.ts
|
|
593
544
|
function getBrand(context, eventName) {
|
|
594
545
|
if (context == null ? void 0 : context.brand) return normalizeBrand(context.brand) || context.brand || null;
|
|
595
546
|
switch (eventName) {
|
|
@@ -613,7 +564,7 @@ function getBrand(context, eventName) {
|
|
|
613
564
|
}
|
|
614
565
|
}
|
|
615
566
|
|
|
616
|
-
// src/params/utils/itemListAttribution.ts
|
|
567
|
+
// src/params/legacy/utils/itemListAttribution.ts
|
|
617
568
|
var LAST_SELECTED_ITEM_KEY = "last_selected_item";
|
|
618
569
|
var STORAGE_VIEWED = "last_viewed_item";
|
|
619
570
|
var CART_LIST_HISTORY_KEY = "cart_list_history";
|
|
@@ -794,7 +745,7 @@ function persistSelectItemOriginFromResolvedItems(items, source) {
|
|
|
794
745
|
saveSelectedItem(productId, listName);
|
|
795
746
|
}
|
|
796
747
|
|
|
797
|
-
// src/params/resolvers/items/fromOrderForm.ts
|
|
748
|
+
// src/params/legacy/resolvers/items/fromOrderForm.ts
|
|
798
749
|
async function itemsFromOrderForm(context) {
|
|
799
750
|
var _a;
|
|
800
751
|
const items = ((_a = context.orderForm) == null ? void 0 : _a.items) || [];
|
|
@@ -826,7 +777,7 @@ async function itemsFromOrderForm(context) {
|
|
|
826
777
|
);
|
|
827
778
|
}
|
|
828
779
|
|
|
829
|
-
// src/params/resolvers/items/fromItem.ts
|
|
780
|
+
// src/params/legacy/resolvers/items/fromItem.ts
|
|
830
781
|
async function itemsFromItem(context, event) {
|
|
831
782
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
832
783
|
const { item, orderForm, itemListName } = context;
|
|
@@ -862,7 +813,7 @@ async function itemsFromItem(context, event) {
|
|
|
862
813
|
];
|
|
863
814
|
}
|
|
864
815
|
|
|
865
|
-
// src/params/resolvers/items/fromList.ts
|
|
816
|
+
// src/params/legacy/resolvers/items/fromList.ts
|
|
866
817
|
async function itemsFromList(context) {
|
|
867
818
|
return ((context == null ? void 0 : context.list) || []).map((item) => {
|
|
868
819
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
@@ -883,7 +834,7 @@ async function itemsFromList(context) {
|
|
|
883
834
|
});
|
|
884
835
|
}
|
|
885
836
|
|
|
886
|
-
// src/params/resolvers/items/fromPdp.ts
|
|
837
|
+
// src/params/legacy/resolvers/items/fromPdp.ts
|
|
887
838
|
async function itemsFromPDP(context, event) {
|
|
888
839
|
var _a, _b, _c, _d;
|
|
889
840
|
const { item, value, brand } = context;
|
|
@@ -914,7 +865,7 @@ async function itemsFromPDP(context, event) {
|
|
|
914
865
|
];
|
|
915
866
|
}
|
|
916
867
|
|
|
917
|
-
// src/params/resolvers/items/fromBanner.ts
|
|
868
|
+
// src/params/legacy/resolvers/items/fromBanner.ts
|
|
918
869
|
async function itemsFromBanner(context) {
|
|
919
870
|
var _a;
|
|
920
871
|
const isUrlFromPDP = isPDP(context == null ? void 0 : context.bannerUrl);
|
|
@@ -935,7 +886,7 @@ async function itemsFromBanner(context) {
|
|
|
935
886
|
};
|
|
936
887
|
}
|
|
937
888
|
|
|
938
|
-
// src/params/items.ts
|
|
889
|
+
// src/params/legacy/items.ts
|
|
939
890
|
function getItems(context, eventName) {
|
|
940
891
|
if (context == null ? void 0 : context.items) return context.items;
|
|
941
892
|
switch (eventName) {
|
|
@@ -969,7 +920,72 @@ function getItems(context, eventName) {
|
|
|
969
920
|
}
|
|
970
921
|
}
|
|
971
922
|
|
|
972
|
-
// src/
|
|
923
|
+
// src/core/utils.ts
|
|
924
|
+
var isDebugMode = () => {
|
|
925
|
+
if (typeof window === "undefined") return false;
|
|
926
|
+
try {
|
|
927
|
+
const params = new URLSearchParams(window.location.search);
|
|
928
|
+
return params.has("__trk_inspect__");
|
|
929
|
+
} catch (e) {
|
|
930
|
+
return window.location.search.indexOf("__trk_inspect__") !== -1;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
var paymentTypeMap = [
|
|
934
|
+
["vale", "vale cr\xE9dito"],
|
|
935
|
+
["pagaleve", "pix"],
|
|
936
|
+
["pix parcel", "pix parcelado"],
|
|
937
|
+
["pix", "pix"],
|
|
938
|
+
["apple", "apple pay"],
|
|
939
|
+
["google", "google pay"],
|
|
940
|
+
["boleto", "boleto"],
|
|
941
|
+
["paypal", "paypal"],
|
|
942
|
+
["cred", "cart\xE3o"],
|
|
943
|
+
["visa", "cart\xE3o"],
|
|
944
|
+
["master", "cart\xE3o"],
|
|
945
|
+
["amex", "cart\xE3o"],
|
|
946
|
+
["elo", "cart\xE3o"],
|
|
947
|
+
["hiper", "cart\xE3o"],
|
|
948
|
+
["diner", "cart\xE3o"],
|
|
949
|
+
["deb", "cart\xE3o"]
|
|
950
|
+
];
|
|
951
|
+
var toNum = (val) => typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
|
|
952
|
+
var documentToHash = async (document2) => {
|
|
953
|
+
if (!document2) return null;
|
|
954
|
+
const encoder = new TextEncoder();
|
|
955
|
+
const data = encoder.encode(document2);
|
|
956
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
957
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
958
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
959
|
+
};
|
|
960
|
+
var SIZE_ORDER = {
|
|
961
|
+
alfabetico: ["PP", "P", "M", "G", "GG", "XG", "XGG", "EG", "EGG", "3G", "4G", "5G"],
|
|
962
|
+
infantil: ["RN", "0-3M", "3-6M", "6-9M", "9-12M", "12-18M", "18-24M", "P", "M", "G", "GG"]
|
|
963
|
+
};
|
|
964
|
+
var detectSizeType = (sizes) => {
|
|
965
|
+
if (sizes.every((s) => /^\d+([.,]\d+)?$/.test(s))) return "numerico";
|
|
966
|
+
if (sizes.some((s) => /^(RN|\d+-\d+M|\d+M)$/i.test(s))) return "infantil";
|
|
967
|
+
if (sizes.every((s) => SIZE_ORDER.alfabetico.includes(s.toUpperCase()))) return "alfabetico";
|
|
968
|
+
return "desconhecido";
|
|
969
|
+
};
|
|
970
|
+
var sortSizes = (sizes) => {
|
|
971
|
+
const unique = [...new Set(sizes.filter(Boolean))];
|
|
972
|
+
const type = detectSizeType(unique);
|
|
973
|
+
if (type === "numerico") {
|
|
974
|
+
return unique.sort((a, b) => parseFloat(a) - parseFloat(b));
|
|
975
|
+
}
|
|
976
|
+
if (type === "alfabetico" || type === "infantil") {
|
|
977
|
+
const order = SIZE_ORDER[type];
|
|
978
|
+
return unique.sort((a, b) => {
|
|
979
|
+
const ia = order.indexOf(a.toUpperCase());
|
|
980
|
+
const ib = order.indexOf(b.toUpperCase());
|
|
981
|
+
return (ia === -1 ? 999 : ia) - (ib === -1 ? 999 : ib);
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
return unique;
|
|
985
|
+
};
|
|
986
|
+
var capitalize = (str) => str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
|
|
987
|
+
|
|
988
|
+
// src/params/legacy/resolvers/paymentType/fromOrderForm.ts
|
|
973
989
|
function paymentTypeFromOrderForm(context) {
|
|
974
990
|
var _a, _b, _c;
|
|
975
991
|
if (context.payment_type) return context.payment_type;
|
|
@@ -986,7 +1002,7 @@ function paymentTypeFromOrderForm(context) {
|
|
|
986
1002
|
return match ? match[1] : null;
|
|
987
1003
|
}
|
|
988
1004
|
|
|
989
|
-
// src/params/resolvers/paymentType/fromOrderGroup.ts
|
|
1005
|
+
// src/params/legacy/resolvers/paymentType/fromOrderGroup.ts
|
|
990
1006
|
function paymentTypeFromOrderGroup(context) {
|
|
991
1007
|
var _a, _b, _c, _d;
|
|
992
1008
|
if (!context.orderForm) return null;
|
|
@@ -999,7 +1015,7 @@ function paymentTypeFromOrderGroup(context) {
|
|
|
999
1015
|
return match ? match[1] : null;
|
|
1000
1016
|
}
|
|
1001
1017
|
|
|
1002
|
-
// src/params/paymentType.ts
|
|
1018
|
+
// src/params/legacy/paymentType.ts
|
|
1003
1019
|
function getPaymentType(context, eventName) {
|
|
1004
1020
|
if (context == null ? void 0 : context.paymentType) return context.paymentType;
|
|
1005
1021
|
switch (eventName) {
|
|
@@ -1015,36 +1031,36 @@ function getPaymentType(context, eventName) {
|
|
|
1015
1031
|
}
|
|
1016
1032
|
|
|
1017
1033
|
// src/params/userInfo.ts
|
|
1018
|
-
|
|
1034
|
+
var PROD_DOMAINS = {
|
|
1035
|
+
"animale": {
|
|
1036
|
+
"store": "https://www.animale.com.br",
|
|
1037
|
+
"checkout": "https://secure.animale.com.br"
|
|
1038
|
+
},
|
|
1039
|
+
"farm": {
|
|
1040
|
+
"store": "https://lojafarm.myvtex.com"
|
|
1041
|
+
},
|
|
1042
|
+
"mariafilo": {
|
|
1043
|
+
"store": "https://mariafilo.myvtex.com",
|
|
1044
|
+
"checkout": "https://secure.mariafilo.com.br"
|
|
1045
|
+
},
|
|
1046
|
+
"lojacrisbarros": {
|
|
1047
|
+
"store": "https://lojacrisbarros.myvtex.com",
|
|
1048
|
+
"checkout": "https://secure.crisbarros.com.br"
|
|
1049
|
+
},
|
|
1050
|
+
"lojaoffpremium": {
|
|
1051
|
+
"store": "https://lojaoffpremium.myvtex.com",
|
|
1052
|
+
"checkout": "https://secure.offpremium.com.br"
|
|
1053
|
+
},
|
|
1054
|
+
"bynv": {
|
|
1055
|
+
"store": "https://bynv.myvtex.com"
|
|
1056
|
+
},
|
|
1057
|
+
"fabula": {
|
|
1058
|
+
"store": "https://lojafabula.myvtex.com"
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
async function getUserInfo(context) {
|
|
1019
1062
|
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"];
|
|
1063
|
+
const domain = (_a = PROD_DOMAINS[context.account || "animale"]) == null ? void 0 : _a[context.platform || "store"];
|
|
1048
1064
|
if (!domain) return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
|
|
1049
1065
|
try {
|
|
1050
1066
|
const api = `${domain}/_v/user-info`;
|
|
@@ -1102,12 +1118,13 @@ async function getUserInfo(context, eventName) {
|
|
|
1102
1118
|
}
|
|
1103
1119
|
}
|
|
1104
1120
|
|
|
1105
|
-
// src/params/index.ts
|
|
1106
|
-
var
|
|
1121
|
+
// src/params/legacy/index.ts
|
|
1122
|
+
var legacyGetters = {
|
|
1107
1123
|
brand: getBrand,
|
|
1108
1124
|
items: getItems,
|
|
1109
1125
|
payment_type: getPaymentType,
|
|
1110
1126
|
user_info: getUserInfo,
|
|
1127
|
+
// global
|
|
1111
1128
|
content_type: (context, eventName) => {
|
|
1112
1129
|
if (context == null ? void 0 : context.content_type) return context.content_type;
|
|
1113
1130
|
return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
|
|
@@ -1303,30 +1320,598 @@ var paramGetters = {
|
|
|
1303
1320
|
}
|
|
1304
1321
|
};
|
|
1305
1322
|
|
|
1306
|
-
// src/
|
|
1307
|
-
|
|
1323
|
+
// src/params/adapters/meta/index.ts
|
|
1324
|
+
var metaAdapters = {
|
|
1325
|
+
user_info: getUserInfo,
|
|
1326
|
+
brand: (context) => {
|
|
1327
|
+
return context.meta.brand || null;
|
|
1328
|
+
},
|
|
1329
|
+
content_type: (context) => {
|
|
1330
|
+
return context.meta.content_type || null;
|
|
1331
|
+
},
|
|
1332
|
+
region: (context) => {
|
|
1333
|
+
return context.meta.region || null;
|
|
1334
|
+
},
|
|
1335
|
+
pre_filled: (context) => {
|
|
1336
|
+
return !!context.preFilled;
|
|
1337
|
+
},
|
|
1338
|
+
currency: (context) => {
|
|
1339
|
+
if (context == null ? void 0 : context.currency) return context.currency;
|
|
1340
|
+
return "BRL";
|
|
1341
|
+
},
|
|
1342
|
+
slot_per_line: (context) => {
|
|
1343
|
+
var _a;
|
|
1344
|
+
return (_a = context.meta.slot_per_line) != null ? _a : null;
|
|
1345
|
+
},
|
|
1346
|
+
search_term: (context) => {
|
|
1347
|
+
return context.meta.search_term || null;
|
|
1348
|
+
},
|
|
1349
|
+
search_found: (context) => {
|
|
1350
|
+
return context.meta.search_found || null;
|
|
1351
|
+
},
|
|
1352
|
+
search_quantity: (context) => {
|
|
1353
|
+
return context.meta.search_quantity || 0;
|
|
1354
|
+
},
|
|
1355
|
+
promotion_name: (context) => {
|
|
1356
|
+
return context.meta.promotion_name || null;
|
|
1357
|
+
},
|
|
1358
|
+
creative_name: (context) => {
|
|
1359
|
+
return context.meta.creative_name || null;
|
|
1360
|
+
},
|
|
1361
|
+
creative_slot: (context) => {
|
|
1362
|
+
return context.meta.creative_slot || null;
|
|
1363
|
+
},
|
|
1364
|
+
size: (context) => {
|
|
1365
|
+
return context.size || null;
|
|
1366
|
+
},
|
|
1367
|
+
item_ref: (context) => {
|
|
1368
|
+
return context.itemRef || null;
|
|
1369
|
+
},
|
|
1370
|
+
method: (context) => {
|
|
1371
|
+
return context.method || null;
|
|
1372
|
+
},
|
|
1373
|
+
type: (context) => {
|
|
1374
|
+
return context.type || null;
|
|
1375
|
+
},
|
|
1376
|
+
color: (context) => {
|
|
1377
|
+
return context.meta.color || null;
|
|
1378
|
+
},
|
|
1379
|
+
price_range: (context) => {
|
|
1380
|
+
return context.meta.price_range || null;
|
|
1381
|
+
},
|
|
1382
|
+
category: (context) => {
|
|
1383
|
+
return context.meta.category || null;
|
|
1384
|
+
},
|
|
1385
|
+
ordering: (context) => {
|
|
1386
|
+
return context.meta.ordering || null;
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
// src/params/adapters/deco/utils.ts
|
|
1391
|
+
var getItemCategory3 = (item) => {
|
|
1392
|
+
var _a;
|
|
1393
|
+
const value = item == null ? void 0 : item.category;
|
|
1394
|
+
if (!value) return "Cole\xE7\xE3o";
|
|
1395
|
+
const text = Array.isArray(value) ? value.join(" ") : String(value);
|
|
1396
|
+
const match = (_a = text.match(/outlet|bazar|sale/i)) == null ? void 0 : _a[0].toLowerCase();
|
|
1397
|
+
return match != null ? match : "Cole\xE7\xE3o";
|
|
1398
|
+
};
|
|
1399
|
+
var getItemCategory22 = (item) => {
|
|
1400
|
+
var _a, _b, _c, _d;
|
|
1401
|
+
const AVOID_CATEGORIES = /^(outlet|bazar|sale)$/i;
|
|
1402
|
+
const categories = (_b = (_a = item.category) == null ? void 0 : _a.split(">")) != null ? _b : [];
|
|
1403
|
+
const last = (_c = categories[categories.length - 1]) != null ? _c : "";
|
|
1404
|
+
const validHierarchy = last.split("/").filter((c) => c && !AVOID_CATEGORIES.test(c));
|
|
1405
|
+
const deepest = (_d = validHierarchy[validHierarchy.length - 1]) != null ? _d : "";
|
|
1406
|
+
return capitalize(deepest);
|
|
1407
|
+
};
|
|
1408
|
+
var resizeVtexImage2 = (url, width = 500, height = 500) => {
|
|
1409
|
+
return url == null ? void 0 : url.replace(
|
|
1410
|
+
/(\/arquivos\/ids\/\d+)-\d+-\d+\//,
|
|
1411
|
+
`$1-${width}-${height}/`
|
|
1412
|
+
);
|
|
1413
|
+
};
|
|
1414
|
+
function getItemShippingTier2() {
|
|
1415
|
+
return null;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
// src/params/adapters/deco/index.ts
|
|
1419
|
+
var IN_STOCK_SCHEMA = "https://schema.org/InStock";
|
|
1420
|
+
var LIST_PRICE_SCHEMA = "https://schema.org/ListPrice";
|
|
1421
|
+
var decoAdapter = {
|
|
1422
|
+
...metaAdapters,
|
|
1423
|
+
// global adapters
|
|
1424
|
+
items: (context) => {
|
|
1425
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1426
|
+
if (context == null ? void 0 : context.products) {
|
|
1427
|
+
return context.products.map((item) => {
|
|
1428
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
|
|
1429
|
+
const COLOR_REGEX = /^[^_]+_/;
|
|
1430
|
+
const listPrice = (_c = (_b = (_a = item == null ? void 0 : item.offers) == null ? void 0 : _a.offers) == null ? void 0 : _b[0].priceSpecification.find(
|
|
1431
|
+
(s) => s.priceType === LIST_PRICE_SCHEMA
|
|
1432
|
+
)) == null ? void 0 : _c.price;
|
|
1433
|
+
return {
|
|
1434
|
+
quantity: 1,
|
|
1435
|
+
index: (_d = item == null ? void 0 : item.index) != null ? _d : 0,
|
|
1436
|
+
item_brand: (_g = (_f = (_e = item.brand) == null ? void 0 : _e.name) == null ? void 0 : _f.toLowerCase()) != null ? _g : null,
|
|
1437
|
+
item_name: (_h = item.alternateName) != null ? _h : null,
|
|
1438
|
+
price: (_j = (_i = item.offers) == null ? void 0 : _i.lowPrice) != null ? _j : null,
|
|
1439
|
+
discount: Number(listPrice) - Number((_k = item == null ? void 0 : item.offers) == null ? void 0 : _k.lowPrice),
|
|
1440
|
+
item_variant: ((_m = (_l = item == null ? void 0 : item.name) == null ? void 0 : _l.split(" - ")[0]) == null ? void 0 : _m.replace(COLOR_REGEX, "").replace(/_/g, " ")) || null,
|
|
1441
|
+
// cor
|
|
1442
|
+
item_variant2: (_o = (_n = item == null ? void 0 : item.name) == null ? void 0 : _n.split(" - ")[1]) != null ? _o : null,
|
|
1443
|
+
// tamanho
|
|
1444
|
+
item_shipping_tier: getItemShippingTier2(),
|
|
1445
|
+
item_ref: (_r = (_q = (_p = item.additionalProperty) == null ? void 0 : _p.find(((i) => i.name === "RefId"))) == null ? void 0 : _q.value) != null ? _r : null,
|
|
1446
|
+
item_category: (_s = getItemCategory3(item)) != null ? _s : null,
|
|
1447
|
+
item_category2: (_t = getItemCategory22(item)) != null ? _t : null,
|
|
1448
|
+
item_id: (_u = item == null ? void 0 : item.inProductGroupWithID) != null ? _u : null,
|
|
1449
|
+
item_sku: (_v = item.sku) != null ? _v : null,
|
|
1450
|
+
item_url: (_w = item.url) != null ? _w : null,
|
|
1451
|
+
image_url: (_y = resizeVtexImage2((_x = item == null ? void 0 : item.image) == null ? void 0 : _x[0].url)) != null ? _y : null,
|
|
1452
|
+
seller_id: (_C = (_B = (_A = (_z = item.offers) == null ? void 0 : _z.offers) == null ? void 0 : _A[0]) == null ? void 0 : _B.seller) != null ? _C : null,
|
|
1453
|
+
item_list_name: (_D = item == null ? void 0 : item.item_list_name) != null ? _D : null
|
|
1454
|
+
};
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
return null;
|
|
1458
|
+
},
|
|
1459
|
+
// brand: (context: DecoBrandContext) => {
|
|
1460
|
+
// if (context?.brand) return context.brand
|
|
1461
|
+
// if (context?.products) {
|
|
1462
|
+
// return context.products[0].brand?.name // tem que ajustar FARM por conta de FARM_ETC
|
|
1463
|
+
// }
|
|
1464
|
+
// return null
|
|
1465
|
+
// },
|
|
1466
|
+
line_items: (context) => {
|
|
1467
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1468
|
+
if (context == null ? void 0 : context.products) {
|
|
1469
|
+
return context.products.map((item) => item == null ? void 0 : item.inProductGroupWithID).filter((id) => Boolean(id));
|
|
1470
|
+
}
|
|
1471
|
+
return null;
|
|
1472
|
+
},
|
|
1473
|
+
value: (context) => {
|
|
1474
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1475
|
+
if (context == null ? void 0 : context.products) {
|
|
1476
|
+
return context.products.map((item) => {
|
|
1477
|
+
var _a;
|
|
1478
|
+
return (_a = item.offers) == null ? void 0 : _a.lowPrice;
|
|
1479
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1480
|
+
}
|
|
1481
|
+
return null;
|
|
1482
|
+
},
|
|
1483
|
+
available_grid: (context) => {
|
|
1484
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1485
|
+
if (context == null ? void 0 : context.products) {
|
|
1486
|
+
const sizes = context.products.flatMap(
|
|
1487
|
+
(product) => {
|
|
1488
|
+
var _a, _b, _c;
|
|
1489
|
+
return (_c = (_b = (_a = product.isVariantOf) == null ? void 0 : _a.hasVariant) == null ? void 0 : _b.filter(
|
|
1490
|
+
(variant) => {
|
|
1491
|
+
var _a2, _b2;
|
|
1492
|
+
return (_b2 = (_a2 = variant.offers) == null ? void 0 : _a2.offers) == null ? void 0 : _b2.some((o) => o.availability === IN_STOCK_SCHEMA);
|
|
1493
|
+
}
|
|
1494
|
+
).map((variant) => {
|
|
1495
|
+
var _a2;
|
|
1496
|
+
return (_a2 = variant.name) == null ? void 0 : _a2.split(" - ")[1];
|
|
1497
|
+
}).filter((name) => Boolean(name))) != null ? _c : [];
|
|
1498
|
+
}
|
|
1499
|
+
);
|
|
1500
|
+
const result = sortSizes(sizes).join(",").trim();
|
|
1501
|
+
return result || null;
|
|
1502
|
+
}
|
|
1503
|
+
return null;
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
// src/params/adapters/orderForm/index.ts
|
|
1508
|
+
var orderFormAdapters = {
|
|
1509
|
+
// orderform
|
|
1510
|
+
payment_type: getPaymentType,
|
|
1511
|
+
total_discount: (context) => {
|
|
1512
|
+
var _a, _b;
|
|
1513
|
+
if (context == null ? void 0 : context.totalDiscount) return context.totalDiscount;
|
|
1514
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1515
|
+
const items = context.orderForm.items;
|
|
1516
|
+
const totalDiscount = items.reduce((acc, item) => {
|
|
1517
|
+
const unitDiscount = Math.max(0, item.listPrice - item.sellingPrice);
|
|
1518
|
+
return acc + unitDiscount * item.quantity;
|
|
1519
|
+
}, 0);
|
|
1520
|
+
const discounts = totalsList.find((t) => t.id === "Discounts");
|
|
1521
|
+
return Math.abs(((discounts == null ? void 0 : discounts.value) || 0) + totalDiscount) / 100 || null;
|
|
1522
|
+
},
|
|
1523
|
+
subtotal: (context) => {
|
|
1524
|
+
var _a, _b;
|
|
1525
|
+
const totalsList = ((_a = context.orderForm) == null ? void 0 : _a.totalizers) || ((_b = context.orderForm) == null ? void 0 : _b.totals) || [];
|
|
1526
|
+
const subtotal = totalsList.filter((t) => t.id === "Items").reduce((acc, t) => acc + (t.value || 0), 0) / 100 || 0;
|
|
1527
|
+
return subtotal;
|
|
1528
|
+
},
|
|
1529
|
+
coupon_message: (context) => {
|
|
1530
|
+
var _a;
|
|
1531
|
+
if (context.couponMessage) return context.couponMessage;
|
|
1532
|
+
const messages = ((_a = context.orderForm) == null ? void 0 : _a.messages) || [];
|
|
1533
|
+
if (messages.length === 0) return null;
|
|
1534
|
+
const couponMessages = messages.filter(
|
|
1535
|
+
(msg) => msg.text.toLowerCase().includes("cupom")
|
|
1536
|
+
);
|
|
1537
|
+
if (couponMessages.length === 0) return null;
|
|
1538
|
+
return couponMessages.map((msg) => msg.text).join(" | ");
|
|
1539
|
+
},
|
|
1540
|
+
flag_pickup: (context) => {
|
|
1541
|
+
var _a;
|
|
1542
|
+
const orderForm = context.orderForm;
|
|
1543
|
+
if (!orderForm) return null;
|
|
1544
|
+
const logisticsInfo = ((_a = orderForm.shippingData) == null ? void 0 : _a.logisticsInfo) || [];
|
|
1545
|
+
const hasPickup = logisticsInfo.some(
|
|
1546
|
+
(info) => {
|
|
1547
|
+
var _a2;
|
|
1548
|
+
return (_a2 = info.slas) == null ? void 0 : _a2.some((sla) => sla.deliveryChannel === "pickup-in-point");
|
|
1549
|
+
}
|
|
1550
|
+
);
|
|
1551
|
+
return hasPickup;
|
|
1552
|
+
},
|
|
1553
|
+
shippings: (context) => {
|
|
1554
|
+
const orderForm = context.orderForm;
|
|
1555
|
+
if (!orderForm) return null;
|
|
1556
|
+
const groupShipping = {};
|
|
1557
|
+
for (const info of orderForm.shippingData.logisticsInfo) {
|
|
1558
|
+
const item = orderForm.items[info.itemIndex];
|
|
1559
|
+
if (!item) continue;
|
|
1560
|
+
for (const sla of info.slas) {
|
|
1561
|
+
const key = sla.name;
|
|
1562
|
+
if (!groupShipping[key]) {
|
|
1563
|
+
groupShipping[key] = {
|
|
1564
|
+
shipping_tier: sla.name,
|
|
1565
|
+
delivery_time: parseInt(sla.shippingEstimate),
|
|
1566
|
+
shipping: parseFloat((sla.price / 100).toFixed(1)),
|
|
1567
|
+
line_items: []
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
groupShipping[key].line_items.push(item.id);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
const shippings = Object.values(groupShipping).map((s) => ({
|
|
1574
|
+
shipping: s.shipping,
|
|
1575
|
+
shipping_tier: s.shipping_tier,
|
|
1576
|
+
delivery_time: s.delivery_time,
|
|
1577
|
+
line_items: s.line_items.join(",")
|
|
1578
|
+
}));
|
|
1579
|
+
return shippings || null;
|
|
1580
|
+
},
|
|
1581
|
+
shipping: (context) => {
|
|
1582
|
+
var _a, _b, _c;
|
|
1583
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1584
|
+
return logistics.reduce((total, item) => {
|
|
1585
|
+
var _a2, _b2;
|
|
1586
|
+
const selected = (_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla);
|
|
1587
|
+
return total + ((_b2 = selected == null ? void 0 : selected.price) != null ? _b2 : 0);
|
|
1588
|
+
}, 0);
|
|
1589
|
+
},
|
|
1590
|
+
shipping_tier: (context) => {
|
|
1591
|
+
var _a, _b, _c;
|
|
1592
|
+
const logistics = (_c = (_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.shippingData) == null ? void 0 : _b.logisticsInfo) != null ? _c : [];
|
|
1593
|
+
const selectedSlas = logistics.map((item) => {
|
|
1594
|
+
var _a2;
|
|
1595
|
+
if (!item.selectedSla) return null;
|
|
1596
|
+
return ((_a2 = item.slas) == null ? void 0 : _a2.find((sla) => sla.id === item.selectedSla)) || null;
|
|
1597
|
+
}).filter(Boolean);
|
|
1598
|
+
if (selectedSlas.length === 0) return null;
|
|
1599
|
+
const uniqueTiers = Array.from(
|
|
1600
|
+
new Map(
|
|
1601
|
+
selectedSlas.map((sla) => {
|
|
1602
|
+
var _a2;
|
|
1603
|
+
const key = sla.deliveryChannel === "pickup-in-point" ? `pickup:${((_a2 = sla.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || sla.name || ""}` : `delivery:${sla.name || ""}`;
|
|
1604
|
+
return [key, sla];
|
|
1605
|
+
})
|
|
1606
|
+
).values()
|
|
1607
|
+
);
|
|
1608
|
+
const sortedTiers = uniqueTiers.sort((a, b) => {
|
|
1609
|
+
var _a2, _b2;
|
|
1610
|
+
const aOrder = a.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1611
|
+
const bOrder = b.deliveryChannel === "pickup-in-point" ? 0 : 1;
|
|
1612
|
+
if (aOrder !== bOrder) return aOrder - bOrder;
|
|
1613
|
+
const aLabel = a.deliveryChannel === "pickup-in-point" ? ((_a2 = a.pickupStoreInfo) == null ? void 0 : _a2.friendlyName) || a.name || "" : a.name || "";
|
|
1614
|
+
const bLabel = b.deliveryChannel === "pickup-in-point" ? ((_b2 = b.pickupStoreInfo) == null ? void 0 : _b2.friendlyName) || b.name || "" : b.name || "";
|
|
1615
|
+
return aLabel.localeCompare(bLabel, "pt-BR");
|
|
1616
|
+
});
|
|
1617
|
+
const shippingTier = sortedTiers.map((sla) => {
|
|
1618
|
+
var _a2;
|
|
1619
|
+
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;
|
|
1620
|
+
}).filter(Boolean).join(", ");
|
|
1621
|
+
return shippingTier || null;
|
|
1622
|
+
},
|
|
1623
|
+
transaction_id: (context) => {
|
|
1624
|
+
var _a, _b;
|
|
1625
|
+
return ((_b = (_a = context.orderForm) == null ? void 0 : _a.orderGroup) == null ? void 0 : _b.toString()) || null;
|
|
1626
|
+
},
|
|
1627
|
+
coupon: (context) => {
|
|
1628
|
+
var _a, _b;
|
|
1629
|
+
return context.appliedCoupon || ((_b = (_a = context == null ? void 0 : context.orderForm) == null ? void 0 : _a.marketingData) == null ? void 0 : _b.coupon) || null;
|
|
1630
|
+
},
|
|
1631
|
+
seller_cod_name: (context) => {
|
|
1632
|
+
return context.appliedSellerCodName || (context == null ? void 0 : context.orderForm.marketingData.utmiCampaign) || null;
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
// src/params/adapters/headless/utils.ts
|
|
1637
|
+
var getItemCategory5 = (item) => {
|
|
1638
|
+
const keywords = ["outlet", "bazar", "sale"];
|
|
1639
|
+
const regex = new RegExp(keywords.join("|"), "i");
|
|
1640
|
+
const value = item == null ? void 0 : item.categories;
|
|
1641
|
+
if (value) {
|
|
1642
|
+
const textToTest = Array.isArray(value) ? value.join(" ") : String(value);
|
|
1643
|
+
const match = textToTest.match(regex);
|
|
1644
|
+
if (match) {
|
|
1645
|
+
return match[0].toLowerCase();
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return "Cole\xE7\xE3o";
|
|
1649
|
+
};
|
|
1650
|
+
var getItemCategory23 = (item) => {
|
|
1651
|
+
var _a, _b, _c;
|
|
1652
|
+
const avoidList = /outlet|bazar|sale/i;
|
|
1653
|
+
const lastCategory = (_b = (_a = item.categories) == null ? void 0 : _a[item.categories.length - 1]) != null ? _b : "";
|
|
1654
|
+
const categoryHierarchy = lastCategory.split("/").filter(Boolean);
|
|
1655
|
+
const deepestCategory = (_c = [...categoryHierarchy].reverse().find((c) => !avoidList.test(c))) != null ? _c : "";
|
|
1656
|
+
return deepestCategory && deepestCategory[0].toUpperCase() + deepestCategory.slice(1).toLowerCase();
|
|
1657
|
+
};
|
|
1658
|
+
function resizeVtexImage3(url, width = 500, height = 500) {
|
|
1659
|
+
return url == null ? void 0 : url.replace(
|
|
1660
|
+
/(\/arquivos\/ids\/\d+)-\d+-\d+\//,
|
|
1661
|
+
`$1-${width}-${height}/`
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// src/params/adapters/headless/zones/PDP.ts
|
|
1666
|
+
var HeadlessPdpZone = {
|
|
1667
|
+
items: (context) => {
|
|
1668
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1669
|
+
if (context == null ? void 0 : context.products) {
|
|
1670
|
+
return context.products.map((item) => {
|
|
1671
|
+
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;
|
|
1672
|
+
const listPrice = (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.ListPrice;
|
|
1673
|
+
const price = (_b = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _b[0].commertialOffer.Price;
|
|
1674
|
+
return {
|
|
1675
|
+
quantity: 1,
|
|
1676
|
+
index: (_c = item == null ? void 0 : item.index) != null ? _c : null,
|
|
1677
|
+
item_brand: (_d = item.brand) != null ? _d : null,
|
|
1678
|
+
item_name: (_e = item.productName) != null ? _e : null,
|
|
1679
|
+
price: price != null ? price : null,
|
|
1680
|
+
discount: Number(listPrice) - Number(price),
|
|
1681
|
+
item_variant: (_h = (_g = (_f = item.items[0]) == null ? void 0 : _f.name) == null ? void 0 : _g.split(" - ")[0]) != null ? _h : null,
|
|
1682
|
+
item_variant2: (_k = (_j = (_i = item.items[0]) == null ? void 0 : _i.name) == null ? void 0 : _j.split(" - ")[1]) != null ? _k : null,
|
|
1683
|
+
item_ref: (_l = item.productReference) != null ? _l : null,
|
|
1684
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1685
|
+
item_category: getItemCategory5(item),
|
|
1686
|
+
item_category2: (_m = getItemCategory23(item)) != null ? _m : null,
|
|
1687
|
+
item_id: (_n = item == null ? void 0 : item.productId) != null ? _n : null,
|
|
1688
|
+
item_sku: (_p = (_o = item.items) == null ? void 0 : _o[0].itemId) != null ? _p : null,
|
|
1689
|
+
item_url: (_q = item.link) != null ? _q : null,
|
|
1690
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1691
|
+
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,
|
|
1692
|
+
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,
|
|
1693
|
+
item_list_name: (_y = item.item_list_name) != null ? _y : null
|
|
1694
|
+
};
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
return null;
|
|
1698
|
+
},
|
|
1699
|
+
value: (context) => {
|
|
1700
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1701
|
+
if (context == null ? void 0 : context.products) {
|
|
1702
|
+
return context.products.map((item) => {
|
|
1703
|
+
var _a;
|
|
1704
|
+
return (_a = item == null ? void 0 : item.items[0].sellers) == null ? void 0 : _a[0].commertialOffer.Price;
|
|
1705
|
+
}).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1706
|
+
}
|
|
1707
|
+
return null;
|
|
1708
|
+
},
|
|
1709
|
+
line_items: (context) => {
|
|
1710
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1711
|
+
if (context == null ? void 0 : context.products) {
|
|
1712
|
+
return context.products.map((item) => item.productId).filter((id) => Boolean(id));
|
|
1713
|
+
}
|
|
1714
|
+
return null;
|
|
1715
|
+
},
|
|
1716
|
+
brand: (context) => {
|
|
1717
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1718
|
+
if (context == null ? void 0 : context.products) {
|
|
1719
|
+
return context.products.map((p) => p.brand).join().trim();
|
|
1720
|
+
}
|
|
1721
|
+
return null;
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
|
|
1725
|
+
// src/params/adapters/headless/zones/PDC.ts
|
|
1726
|
+
var HeadlessPdcZone = {
|
|
1727
|
+
items: (context) => {
|
|
1728
|
+
if (context == null ? void 0 : context.items) return context.items;
|
|
1729
|
+
if (context == null ? void 0 : context.products) {
|
|
1730
|
+
return context.products.map((item) => {
|
|
1731
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
1732
|
+
const listPrice = item.offers.highPrice;
|
|
1733
|
+
const price = item.offers.lowPrice;
|
|
1734
|
+
return {
|
|
1735
|
+
quantity: 1,
|
|
1736
|
+
index: (_a = item == null ? void 0 : item.index) != null ? _a : 0,
|
|
1737
|
+
item_brand: (_b = item.brand.name) != null ? _b : null,
|
|
1738
|
+
item_name: (_c = item.name) != null ? _c : null,
|
|
1739
|
+
price: price != null ? price : null,
|
|
1740
|
+
discount: Number(listPrice) - Number(price),
|
|
1741
|
+
item_variant: (_f = (_e = (_d = item.isVariantOf) == null ? void 0 : _d.hasVariant) == null ? void 0 : _e[0].name.split(" - ")[0]) != null ? _f : null,
|
|
1742
|
+
item_variant2: (_i = (_h = ((_g = item.additionalProperty) != null ? _g : []).find((p) => p.name === "Tamanho")) == null ? void 0 : _h.value) != null ? _i : null,
|
|
1743
|
+
item_ref: null,
|
|
1744
|
+
// sem ref no retorno do IS na multi-lib produtos PDC
|
|
1745
|
+
item_category: getItemCategory5(item),
|
|
1746
|
+
item_category2: (_j = getItemCategory23(item)) != null ? _j : null,
|
|
1747
|
+
item_id: (_k = item.isVariantOf.productGroupID) != null ? _k : null,
|
|
1748
|
+
item_sku: (_l = item.sku) != null ? _l : null,
|
|
1749
|
+
item_url: null,
|
|
1750
|
+
// sem link/url no retorno do IS na multi-lib produtos PDC
|
|
1751
|
+
image_url: (_n = resizeVtexImage3((_m = item == null ? void 0 : item.image) == null ? void 0 : _m[0].url)) != null ? _n : null,
|
|
1752
|
+
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,
|
|
1753
|
+
item_list_name: (_t = item.item_list_name) != null ? _t : null
|
|
1754
|
+
};
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
return null;
|
|
1758
|
+
},
|
|
1759
|
+
value: (context) => {
|
|
1760
|
+
if (context == null ? void 0 : context.value) return context.value;
|
|
1761
|
+
if (context == null ? void 0 : context.products) {
|
|
1762
|
+
return context.products.map((item) => item.offers.lowPrice).filter((price) => price !== void 0).reduce((sum, price) => sum + price, 0);
|
|
1763
|
+
}
|
|
1764
|
+
return null;
|
|
1765
|
+
},
|
|
1766
|
+
line_items: (context) => {
|
|
1767
|
+
if (context == null ? void 0 : context.line_items) return context.line_items;
|
|
1768
|
+
if (context == null ? void 0 : context.products) {
|
|
1769
|
+
return context.products.map((item) => item.id).filter((id) => Boolean(id));
|
|
1770
|
+
}
|
|
1771
|
+
return null;
|
|
1772
|
+
},
|
|
1773
|
+
brand: (context) => {
|
|
1774
|
+
if (context == null ? void 0 : context.brand) return context.brand;
|
|
1775
|
+
if (context == null ? void 0 : context.products) {
|
|
1776
|
+
return context.products.map((p) => p.brand.name).join().trim();
|
|
1777
|
+
}
|
|
1778
|
+
return null;
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
|
|
1782
|
+
// src/params/adapters/headless/index.ts
|
|
1783
|
+
var headlessAdapter = {
|
|
1784
|
+
...metaAdapters,
|
|
1785
|
+
// global adapters
|
|
1786
|
+
...orderFormAdapters,
|
|
1787
|
+
// orderForm adapters, confirmar se no storefront tem evento que usa essses params
|
|
1788
|
+
brand: (context) => {
|
|
1789
|
+
if (context.zone === "PDP") {
|
|
1790
|
+
return HeadlessPdpZone.brand(context);
|
|
1791
|
+
}
|
|
1792
|
+
if (context.zone === "PDC") {
|
|
1793
|
+
return HeadlessPdcZone.brand(context);
|
|
1794
|
+
}
|
|
1795
|
+
return null;
|
|
1796
|
+
},
|
|
1797
|
+
line_items: (context) => {
|
|
1798
|
+
if (context.zone === "PDP") {
|
|
1799
|
+
return HeadlessPdpZone.line_items(context);
|
|
1800
|
+
}
|
|
1801
|
+
if (context.zone === "PDC") {
|
|
1802
|
+
return HeadlessPdcZone.line_items(context);
|
|
1803
|
+
}
|
|
1804
|
+
return null;
|
|
1805
|
+
},
|
|
1806
|
+
value: (context) => {
|
|
1807
|
+
if (context.zone === "PDP") {
|
|
1808
|
+
return HeadlessPdpZone.value(context);
|
|
1809
|
+
}
|
|
1810
|
+
if (context.zone === "PDC") {
|
|
1811
|
+
return HeadlessPdcZone.value(context);
|
|
1812
|
+
}
|
|
1813
|
+
return null;
|
|
1814
|
+
},
|
|
1815
|
+
items: (context) => {
|
|
1816
|
+
if (context.zone === "PDP") {
|
|
1817
|
+
return HeadlessPdpZone.items(context);
|
|
1818
|
+
}
|
|
1819
|
+
if (context.zone === "PDC") {
|
|
1820
|
+
return HeadlessPdcZone.items(context);
|
|
1821
|
+
}
|
|
1822
|
+
},
|
|
1823
|
+
// param used only in one Zone, the PDP; no need condition
|
|
1824
|
+
available_grid: (context) => {
|
|
1825
|
+
if (context == null ? void 0 : context.available_grid) return context.available_grid;
|
|
1826
|
+
if (context == null ? void 0 : context.products) {
|
|
1827
|
+
const sizes = context.products.flatMap((p) => p.items.map((i) => i.Tamanho[0]));
|
|
1828
|
+
const result = sortSizes(sizes).join(",");
|
|
1829
|
+
return result || null;
|
|
1830
|
+
}
|
|
1831
|
+
return null;
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
|
|
1835
|
+
// src/params/adapters/pickup/utils.ts
|
|
1836
|
+
var getShippingTier = (sla) => {
|
|
1837
|
+
var _a, _b;
|
|
1838
|
+
const isPickup = sla.deliveryChannel === "pickup-in-point" /* PickupInPoint */;
|
|
1839
|
+
if (isPickup) {
|
|
1840
|
+
const storeName = (_b = (_a = sla.pickupStoreInfo) == null ? void 0 : _a.friendlyName) == null ? void 0 : _b.trim();
|
|
1841
|
+
return storeName ? `retirada em loja: ${storeName}` : "retirada em loja";
|
|
1842
|
+
}
|
|
1843
|
+
return sla.name ? `receba em casa: ${sla.name.toLowerCase()}` : "receba em casa";
|
|
1844
|
+
};
|
|
1845
|
+
var getDeliveryTime = (sla) => {
|
|
1846
|
+
const estimate = sla.shippingEstimate;
|
|
1847
|
+
if (!estimate) return 0;
|
|
1848
|
+
const days = parseInt(estimate, 10);
|
|
1849
|
+
return isNaN(days) ? 0 : days;
|
|
1850
|
+
};
|
|
1851
|
+
|
|
1852
|
+
// src/params/adapters/pickup/index.ts
|
|
1853
|
+
var pickupAdapter = {
|
|
1854
|
+
...metaAdapters,
|
|
1855
|
+
flag_pickup: (context) => {
|
|
1856
|
+
var _a;
|
|
1857
|
+
return (_a = context == null ? void 0 : context.flag_pickup) != null ? _a : null;
|
|
1858
|
+
},
|
|
1859
|
+
shippings: (context) => {
|
|
1860
|
+
if (context.shippings) {
|
|
1861
|
+
return context.shippings.map((s) => {
|
|
1862
|
+
var _a, _b;
|
|
1863
|
+
return {
|
|
1864
|
+
line_items: (_a = s.line_items) != null ? _a : "",
|
|
1865
|
+
shipping: (_b = s.price) != null ? _b : 0,
|
|
1866
|
+
shipping_tier: getShippingTier(s),
|
|
1867
|
+
delivery_time: getDeliveryTime(s)
|
|
1868
|
+
};
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
return null;
|
|
1872
|
+
},
|
|
1873
|
+
zipcode: (context) => {
|
|
1874
|
+
var _a;
|
|
1875
|
+
return (_a = context.zipcode) != null ? _a : null;
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
// src/formatter.ts
|
|
1880
|
+
var adapters = {
|
|
1881
|
+
DECO: decoAdapter,
|
|
1882
|
+
HEADLESS: headlessAdapter,
|
|
1883
|
+
PICKUP: pickupAdapter
|
|
1884
|
+
};
|
|
1885
|
+
async function getParameters(context, eventName) {
|
|
1886
|
+
var _a;
|
|
1308
1887
|
const eventConfig = EVENTS[eventName];
|
|
1309
1888
|
if (!eventConfig) return;
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
)
|
|
1889
|
+
const currentAdapter = context.adapter;
|
|
1890
|
+
const getters = (_a = adapters[currentAdapter]) != null ? _a : legacyGetters;
|
|
1891
|
+
const entries = await Promise.all(
|
|
1892
|
+
eventConfig.requiredParams.map(async (param) => {
|
|
1893
|
+
const getter = getters[param];
|
|
1894
|
+
if (typeof getter !== "function") {
|
|
1895
|
+
console.error(`[DT] Missing getter "${param}" for adapter "${currentAdapter}"`);
|
|
1896
|
+
return [param, null];
|
|
1897
|
+
}
|
|
1898
|
+
return [param, await getter(context, eventName)];
|
|
1899
|
+
})
|
|
1321
1900
|
);
|
|
1322
|
-
return
|
|
1901
|
+
return Object.fromEntries(entries);
|
|
1323
1902
|
}
|
|
1324
1903
|
|
|
1325
1904
|
// src/index.ts
|
|
1326
|
-
async function trackWebEvent(event, context
|
|
1905
|
+
async function trackWebEvent(event, context) {
|
|
1327
1906
|
try {
|
|
1328
1907
|
const parameters = await getParameters(context, event);
|
|
1329
|
-
|
|
1908
|
+
if (isDebugMode()) {
|
|
1909
|
+
console.log(`[DT v2] ${event}, context e parameters: `, {
|
|
1910
|
+
context,
|
|
1911
|
+
parameters
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
return await pushToDataLayer(
|
|
1330
1915
|
event,
|
|
1331
1916
|
Object.assign({}, parameters, { window: context.window })
|
|
1332
1917
|
);
|