@azzas/azzas-tracker-web 1.0.88 → 1.0.90

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.
@@ -1198,6 +1198,147 @@ var AzzasTracker = function() {
1198
1198
  return null;
1199
1199
  }
1200
1200
  };
1201
+ var getUserInfo = // src/params/userInfo.ts
1202
+ function getUserInfo(context, eventName) {
1203
+ return _async_to_generator(function() {
1204
+ var _context_manuallyInfo, _PROD_DOMAINS_, _context_manuallyInfo1, cpf, birthDate, phone, firstName, lastName, email, document2, hashedDocument, PROD_DOMAINS, domain, _res_customer_document, _res_customer, api, response, res, document21, hashedDocument1, _;
1205
+ return _ts_generator(this, function(_state) {
1206
+ switch(_state.label){
1207
+ case 0:
1208
+ if (!((context === null || context === void 0 ? void 0 : context.manuallyInfo) && ((_context_manuallyInfo = context.manuallyInfo) === null || _context_manuallyInfo === void 0 ? void 0 : _context_manuallyInfo.cpf))) return [
1209
+ 3,
1210
+ 2
1211
+ ];
1212
+ _context_manuallyInfo1 = context.manuallyInfo, cpf = _context_manuallyInfo1.cpf, birthDate = _context_manuallyInfo1.birthDate, phone = _context_manuallyInfo1.phone, firstName = _context_manuallyInfo1.firstName, lastName = _context_manuallyInfo1.lastName, email = _context_manuallyInfo1.email;
1213
+ document2 = cpf === null || cpf === void 0 ? void 0 : cpf.replace(/\D/g, "");
1214
+ return [
1215
+ 4,
1216
+ documentToHash(document2)
1217
+ ];
1218
+ case 1:
1219
+ hashedDocument = _state.sent();
1220
+ return [
1221
+ 2,
1222
+ {
1223
+ address: null,
1224
+ customer: {
1225
+ email: email,
1226
+ phone: phone,
1227
+ lastName: lastName,
1228
+ birthDate: birthDate,
1229
+ firstName: firstName,
1230
+ homePhone: phone,
1231
+ document: hashedDocument
1232
+ }
1233
+ }
1234
+ ];
1235
+ case 2:
1236
+ PROD_DOMAINS = {
1237
+ "animale": {
1238
+ "store": "https://www.animale.com.br",
1239
+ "checkout": "https://secure.animale.com.br"
1240
+ },
1241
+ "farm": {
1242
+ "store": "https://lojafarm.myvtex.com"
1243
+ },
1244
+ "mariafilo": {
1245
+ "store": "https://mariafilo.myvtex.com",
1246
+ "checkout": "https://secure.mariafilo.com.br"
1247
+ },
1248
+ "lojacrisbarros": {
1249
+ "store": "https://lojacrisbarros.myvtex.com",
1250
+ "checkout": "https://secure.crisbarros.com.br"
1251
+ },
1252
+ "lojaoffpremium": {
1253
+ "store": "https://lojaoffpremium.myvtex.com",
1254
+ "checkout": "https://secure.lojaoffpremium.com.br"
1255
+ }
1256
+ };
1257
+ domain = (_PROD_DOMAINS_ = PROD_DOMAINS[context.account || "https://www.animale.com.br"]) === null || _PROD_DOMAINS_ === void 0 ? void 0 : _PROD_DOMAINS_[context.platform || "store"];
1258
+ if (!domain) return [
1259
+ 2,
1260
+ {
1261
+ customer: {
1262
+ email: context.userEmail,
1263
+ id: context === null || context === void 0 ? void 0 : context.userId
1264
+ },
1265
+ address: null
1266
+ }
1267
+ ];
1268
+ _state.label = 3;
1269
+ case 3:
1270
+ _state.trys.push([
1271
+ 3,
1272
+ 7,
1273
+ ,
1274
+ 8
1275
+ ]);
1276
+ api = "".concat(domain, "/_v/user-info");
1277
+ return [
1278
+ 4,
1279
+ fetch(api, {
1280
+ method: "POST",
1281
+ body: JSON.stringify({
1282
+ email: context.userEmail
1283
+ })
1284
+ })
1285
+ ];
1286
+ case 4:
1287
+ response = _state.sent();
1288
+ if (response.status !== 200) {
1289
+ return [
1290
+ 2,
1291
+ {
1292
+ customer: {
1293
+ email: context.userEmail,
1294
+ id: context === null || context === void 0 ? void 0 : context.userId
1295
+ },
1296
+ address: null
1297
+ }
1298
+ ];
1299
+ }
1300
+ return [
1301
+ 4,
1302
+ response.json()
1303
+ ];
1304
+ case 5:
1305
+ res = _state.sent();
1306
+ document21 = res === null || res === void 0 ? void 0 : (_res_customer = res.customer) === null || _res_customer === void 0 ? void 0 : (_res_customer_document = _res_customer.document) === null || _res_customer_document === void 0 ? void 0 : _res_customer_document.replace(/\D/g, "");
1307
+ return [
1308
+ 4,
1309
+ documentToHash(document21)
1310
+ ];
1311
+ case 6:
1312
+ hashedDocument1 = _state.sent();
1313
+ return [
1314
+ 2,
1315
+ _object_spread_props(_object_spread({}, res), {
1316
+ customer: _object_spread_props(_object_spread({}, res.customer), {
1317
+ cpf: hashedDocument1,
1318
+ document: document21
1319
+ })
1320
+ })
1321
+ ];
1322
+ case 7:
1323
+ _ = _state.sent();
1324
+ return [
1325
+ 2,
1326
+ {
1327
+ customer: {
1328
+ email: context.userEmail,
1329
+ id: context === null || context === void 0 ? void 0 : context.userId
1330
+ },
1331
+ address: null
1332
+ }
1333
+ ];
1334
+ case 8:
1335
+ return [
1336
+ 2
1337
+ ];
1338
+ }
1339
+ });
1340
+ })();
1341
+ };
1201
1342
  var getParameters = // src/formatter/index.ts
1202
1343
  function getParameters(_0) {
1203
1344
  return _async_to_generator(function() {
@@ -1819,18 +1960,16 @@ var AzzasTracker = function() {
1819
1960
  var toNum = function(val) {
1820
1961
  return typeof val === "string" ? Number(val.replace(/[^\d,]/g, "").replace(",", ".")) : val;
1821
1962
  };
1822
- var setLocalStorage = function(key, value) {
1823
- localStorage.setItem(key, value);
1824
- };
1825
- var getLocalStorage = function(key) {
1826
- return localStorage.getItem(key);
1827
- };
1828
1963
  var documentToHash = function(document2) {
1829
1964
  return _async_to_generator(function() {
1830
1965
  var encoder, data, hashBuffer, hashArray;
1831
1966
  return _ts_generator(this, function(_state) {
1832
1967
  switch(_state.label){
1833
1968
  case 0:
1969
+ if (!document2) return [
1970
+ 2,
1971
+ null
1972
+ ];
1834
1973
  encoder = new TextEncoder();
1835
1974
  data = encoder.encode(document2);
1836
1975
  return [
@@ -1870,137 +2009,7 @@ var AzzasTracker = function() {
1870
2009
  brand: getBrand,
1871
2010
  items: getItems,
1872
2011
  payment_type: getPaymentType,
1873
- user_info: function(context, eventName) {
1874
- return _async_to_generator(function() {
1875
- var _PROD_DOMAINS_, PROD_DOMAINS, domain, api, response, res, cpfFromStorage, hashedDocument, _;
1876
- return _ts_generator(this, function(_state) {
1877
- switch(_state.label){
1878
- case 0:
1879
- PROD_DOMAINS = {
1880
- "animale": {
1881
- "store": "https://www.animale.com.br",
1882
- "checkout": "https://secure.animale.com.br"
1883
- },
1884
- "farm": {
1885
- "store": "https://lojafarm.myvtex.com"
1886
- },
1887
- "mariafilo": {
1888
- "store": "https://mariafilo.myvtex.com",
1889
- "checkout": "https://secure.mariafilo.com.br"
1890
- },
1891
- "lojacrisbarros": {
1892
- "store": "https://lojacrisbarros.myvtex.com",
1893
- "checkout": "https://secure.crisbarros.com.br"
1894
- },
1895
- "lojaoffpremium": {
1896
- "store": "https://lojaoffpremium.myvtex.com",
1897
- "checkout": "https://secure.lojaoffpremium.com.br"
1898
- }
1899
- };
1900
- domain = (_PROD_DOMAINS_ = PROD_DOMAINS[context.account || "https://www.animale.com.br"]) === null || _PROD_DOMAINS_ === void 0 ? void 0 : _PROD_DOMAINS_[context.platform || "store"];
1901
- if (!domain) return [
1902
- 2,
1903
- {
1904
- customer: {
1905
- email: context.userEmail,
1906
- id: context === null || context === void 0 ? void 0 : context.userId
1907
- },
1908
- address: null
1909
- }
1910
- ];
1911
- _state.label = 1;
1912
- case 1:
1913
- _state.trys.push([
1914
- 1,
1915
- 7,
1916
- ,
1917
- 8
1918
- ]);
1919
- api = "".concat(domain, "/_v/user-info");
1920
- return [
1921
- 4,
1922
- fetch(api, {
1923
- method: "POST",
1924
- body: JSON.stringify({
1925
- email: context.userEmail
1926
- })
1927
- })
1928
- ];
1929
- case 2:
1930
- response = _state.sent();
1931
- if (response.status !== 200) {
1932
- return [
1933
- 2,
1934
- {
1935
- customer: {
1936
- email: context.userEmail,
1937
- id: context === null || context === void 0 ? void 0 : context.userId
1938
- },
1939
- address: null
1940
- }
1941
- ];
1942
- }
1943
- return [
1944
- 4,
1945
- response.json()
1946
- ];
1947
- case 3:
1948
- res = _state.sent();
1949
- cpfFromStorage = getLocalStorage("user_doc_dt");
1950
- if (!cpfFromStorage) return [
1951
- 3,
1952
- 4
1953
- ];
1954
- return [
1955
- 2,
1956
- _object_spread_props(_object_spread({}, res), {
1957
- customer: _object_spread_props(_object_spread({}, res.customer), {
1958
- cpf: cpfFromStorage
1959
- })
1960
- })
1961
- ];
1962
- case 4:
1963
- return [
1964
- 4,
1965
- documentToHash(res.customer.document)
1966
- ];
1967
- case 5:
1968
- hashedDocument = _state.sent();
1969
- console.log("[DT] set localstorage");
1970
- setLocalStorage("user_doc_dt", hashedDocument);
1971
- return [
1972
- 2,
1973
- _object_spread_props(_object_spread({}, res), {
1974
- customer: _object_spread_props(_object_spread({}, res.customer), {
1975
- cpf: hashedDocument
1976
- })
1977
- })
1978
- ];
1979
- case 6:
1980
- return [
1981
- 3,
1982
- 8
1983
- ];
1984
- case 7:
1985
- _ = _state.sent();
1986
- return [
1987
- 2,
1988
- {
1989
- customer: {
1990
- email: context.userEmail,
1991
- id: context === null || context === void 0 ? void 0 : context.userId
1992
- },
1993
- address: null
1994
- }
1995
- ];
1996
- case 8:
1997
- return [
1998
- 2
1999
- ];
2000
- }
2001
- });
2002
- })();
2003
- },
2012
+ user_info: getUserInfo,
2004
2013
  content_type: function(context, eventName) {
2005
2014
  return "regiao".concat(":" + context.category).concat(context.subcategory ? ":" + context.subcategory : "").concat(":" + context.componentName) || null;
2006
2015
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azzas/azzas-tracker-web",
3
- "version": "1.0.88",
3
+ "version": "1.0.90",
4
4
  "type": "module",
5
5
  "main": "./dist/mod.cjs",
6
6
  "module": "./dist/mod.js",