@azzas/azzas-tracker-web 1.0.95 → 1.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mod.js CHANGED
@@ -166,7 +166,8 @@ var EVENTS = {
166
166
  AUTH_ACTION: {
167
167
  name: "auth_action",
168
168
  hasEcommerce: false,
169
- requiredParams: ["region"]
169
+ requiredParams: ["region"],
170
+ destinations: ["DataLayer"]
170
171
  },
171
172
  ADD_PERSONAL_INFO: {
172
173
  name: "add_personal_info",
@@ -973,89 +974,84 @@ function getPaymentType(context, eventName) {
973
974
  }
974
975
 
975
976
  // src/params/userInfo.ts
976
- var PROD_DOMAINS = {
977
- "animale": {
978
- "store": "https://www.animale.com.br",
979
- "checkout": "https://secure.animale.com.br"
980
- },
981
- "farm": {
982
- "store": "https://lojafarm.myvtex.com"
983
- },
984
- "mariafilo": {
985
- "store": "https://mariafilo.myvtex.com",
986
- "checkout": "https://secure.mariafilo.com.br"
987
- },
988
- "lojacrisbarros": {
989
- "store": "https://lojacrisbarros.myvtex.com",
990
- "checkout": "https://secure.crisbarros.com.br"
991
- },
992
- "lojaoffpremium": {
993
- "store": "https://lojaoffpremium.myvtex.com",
994
- "checkout": "https://secure.lojaoffpremium.com.br"
995
- }
996
- };
997
- async function getManuallyInfo(info) {
998
- if (!(info == null ? void 0 : info.cpf)) return null;
999
- const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = info;
1000
- const document2 = cpf == null ? void 0 : cpf.replace(/\D/g, "");
1001
- const hashedDocument = await documentToHash(document2);
1002
- let formattedBirthDate = null;
1003
- if (birthDate) {
1004
- const [day, month, year] = birthDate.split("/");
1005
- if (day && month && year && !isNaN(Number(year))) {
1006
- formattedBirthDate = `${year}-${month}-${day}T00:00:00Z`;
1007
- } else {
1008
- console.warn("[DT - user_info] Invalid birthDate format from manuallyInfo:", birthDate);
1009
- }
1010
- }
1011
- return {
1012
- address: null,
1013
- customer: {
1014
- email,
1015
- phone,
1016
- document: document2,
1017
- lastName,
1018
- birthDate: formattedBirthDate,
1019
- firstName,
1020
- homePhone: phone,
1021
- cpf: hashedDocument,
1022
- ...email_optin && { email_optin }
977
+ async function getUserInfo(context, eventName) {
978
+ var _a, _b, _c, _d, _e;
979
+ const PROD_DOMAINS = {
980
+ "animale": {
981
+ "store": "https://www.animale.com.br",
982
+ "checkout": "https://secure.animale.com.br"
983
+ },
984
+ "farm": {
985
+ "store": "https://lojafarm.myvtex.com"
986
+ },
987
+ "mariafilo": {
988
+ "store": "https://mariafilo.myvtex.com",
989
+ "checkout": "https://secure.mariafilo.com.br"
990
+ },
991
+ "lojacrisbarros": {
992
+ "store": "https://lojacrisbarros.myvtex.com",
993
+ "checkout": "https://secure.crisbarros.com.br"
994
+ },
995
+ "lojaoffpremium": {
996
+ "store": "https://lojaoffpremium.myvtex.com",
997
+ "checkout": "https://secure.lojaoffpremium.com.br"
1023
998
  }
1024
999
  };
1025
- }
1026
- function getFallbackUserInfo(userEmail, userId) {
1027
- return {
1028
- customer: { email: userEmail, id: userId },
1029
- address: null
1030
- };
1031
- }
1032
- async function getUserInfo(context, eventName) {
1033
- var _a, _b, _c;
1034
- const domain = (_a = PROD_DOMAINS[(context == null ? void 0 : context.account) || "https://www.animale.com.br"]) == null ? void 0 : _a[(context == null ? void 0 : context.platform) || "store"];
1035
- if (!domain) return getFallbackUserInfo(context.userEmail, context == null ? void 0 : context.userId);
1000
+ const domain = (_a = PROD_DOMAINS[context.account || "https://www.animale.com.br"]) == null ? void 0 : _a[context.platform || "store"];
1001
+ if (!domain) return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
1036
1002
  try {
1037
1003
  const api = `${domain}/_v/user-info`;
1038
1004
  const response = await fetch(api, {
1039
1005
  method: "POST",
1040
1006
  body: JSON.stringify({ email: context.userEmail })
1041
1007
  });
1042
- if (response.status === 200) {
1043
- const res = await response.json();
1044
- const document2 = (_c = (_b = res == null ? void 0 : res.customer) == null ? void 0 : _b.document) == null ? void 0 : _c.replace(/\D/g, "");
1045
- const hashedDocument = await documentToHash(document2);
1046
- return { ...res, customer: { ...res.customer, cpf: hashedDocument, document: document2 } };
1047
- }
1048
- const manuallyInfoResult = await getManuallyInfo(context == null ? void 0 : context.manuallyInfo);
1049
- if (manuallyInfoResult) {
1050
- return manuallyInfoResult;
1008
+ if (response.status !== 200) {
1009
+ if ((context == null ? void 0 : context.manuallyInfo) && ((_b = context.manuallyInfo) == null ? void 0 : _b.cpf)) {
1010
+ const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = context.manuallyInfo;
1011
+ const document3 = cpf == null ? void 0 : cpf.replace(/\D/g, "");
1012
+ const hashedDocument2 = await documentToHash(document3);
1013
+ return {
1014
+ address: null,
1015
+ customer: {
1016
+ email,
1017
+ phone,
1018
+ document: document3,
1019
+ lastName,
1020
+ birthDate,
1021
+ firstName,
1022
+ email_optin,
1023
+ homePhone: phone,
1024
+ cpf: hashedDocument2
1025
+ }
1026
+ };
1027
+ }
1028
+ return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
1051
1029
  }
1052
- return getFallbackUserInfo(context.userEmail, context == null ? void 0 : context.userId);
1030
+ const res = await response.json();
1031
+ const document2 = (_d = (_c = res == null ? void 0 : res.customer) == null ? void 0 : _c.document) == null ? void 0 : _d.replace(/\D/g, "");
1032
+ const hashedDocument = await documentToHash(document2);
1033
+ return { ...res, customer: { ...res.customer, cpf: hashedDocument, document: document2 } };
1053
1034
  } catch (_) {
1054
- const manuallyInfoResult = await getManuallyInfo(context == null ? void 0 : context.manuallyInfo);
1055
- if (manuallyInfoResult) {
1056
- return manuallyInfoResult;
1035
+ if ((context == null ? void 0 : context.manuallyInfo) && ((_e = context.manuallyInfo) == null ? void 0 : _e.cpf)) {
1036
+ const { cpf, birthDate, phone, firstName, lastName, email, email_optin } = context.manuallyInfo;
1037
+ const document2 = cpf == null ? void 0 : cpf.replace(/\D/g, "");
1038
+ const hashedDocument = await documentToHash(document2);
1039
+ return {
1040
+ address: null,
1041
+ customer: {
1042
+ email,
1043
+ phone,
1044
+ document: document2,
1045
+ lastName,
1046
+ birthDate,
1047
+ firstName,
1048
+ email_optin,
1049
+ homePhone: phone,
1050
+ cpf: hashedDocument
1051
+ }
1052
+ };
1057
1053
  }
1058
- return getFallbackUserInfo(context.userEmail, context == null ? void 0 : context.userId);
1054
+ return { customer: { email: context.userEmail, id: context == null ? void 0 : context.userId }, address: null };
1059
1055
  }
1060
1056
  }
1061
1057
 
@@ -1066,6 +1062,7 @@ var paramGetters = {
1066
1062
  payment_type: getPaymentType,
1067
1063
  user_info: getUserInfo,
1068
1064
  content_type: (context, eventName) => {
1065
+ if (context == null ? void 0 : context.content_type) return context.content_type;
1069
1066
  return `regiao`.concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
1070
1067
  },
1071
1068
  region: (context, eventName) => {