akeyless-client-commons 1.0.66 → 1.0.68

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.
@@ -480,7 +480,7 @@ __export(helpers_exports, {
480
480
  return propsAreEqual;
481
481
  },
482
482
  query_document: function() {
483
- return query_document;
483
+ return query_document2;
484
484
  },
485
485
  query_document_by_conditions: function() {
486
486
  return query_document_by_conditions;
@@ -538,6 +538,9 @@ __export(helpers_exports, {
538
538
  },
539
539
  userNameFormat: function() {
540
540
  return userNameFormat;
541
+ },
542
+ validateUserStatusAndPermissions: function() {
543
+ return validateUserStatusAndPermissions;
541
544
  }
542
545
  });
543
546
  module.exports = __toCommonJS(helpers_exports);
@@ -590,17 +593,197 @@ var is_iccid = function(number) {
590
593
  if (!number.startsWith("89")) return false;
591
594
  return true;
592
595
  };
593
- // src/helpers/firebase.ts
596
+ // src/helpers/global.ts
597
+ var import_akeyless_types_commons = require("akeyless-types-commons");
598
+ var import_axios = __toESM(require("axios"));
599
+ var import_lodash = require("lodash");
594
600
  var import_meta = {};
601
+ var calculateBearing = function(startLat, startLng, endLat, endLng) {
602
+ if (startLat === endLat || startLng === endLng) {
603
+ return 0;
604
+ }
605
+ if (startLat === void 0 || startLng === void 0 || endLat === void 0 || endLng === void 0) {
606
+ return 0;
607
+ }
608
+ var startLatRad = startLat * Math.PI / 180;
609
+ var startLngRad = startLng * Math.PI / 180;
610
+ var endLatRad = endLat * Math.PI / 180;
611
+ var endLngRad = endLng * Math.PI / 180;
612
+ var dLon = endLngRad - startLngRad;
613
+ var y = Math.sin(dLon) * Math.cos(endLatRad);
614
+ var x = Math.cos(startLatRad) * Math.sin(endLatRad) - Math.sin(startLatRad) * Math.cos(endLatRad) * Math.cos(dLon);
615
+ var bearing = Math.atan2(y, x) * 180 / Math.PI;
616
+ return (bearing + 360) % 360;
617
+ };
618
+ var renderOnce = function() {
619
+ return true;
620
+ };
621
+ var propsAreEqual = function(prevProps, nextProps) {
622
+ return (0, import_lodash.isEqual)(prevProps, nextProps);
623
+ };
624
+ var getUserCountryByIp = /*#__PURE__*/ function() {
625
+ var _ref = _async_to_generator(function() {
626
+ var response, error;
627
+ return _ts_generator(this, function(_state) {
628
+ switch(_state.label){
629
+ case 0:
630
+ _state.trys.push([
631
+ 0,
632
+ 2,
633
+ ,
634
+ 3
635
+ ]);
636
+ return [
637
+ 4,
638
+ import_axios.default.get("https://ipapi.co/json/")
639
+ ];
640
+ case 1:
641
+ response = _state.sent();
642
+ return [
643
+ 2,
644
+ (response.data.country_code || import_akeyless_types_commons.CountryOptions.IL).toLowerCase()
645
+ ];
646
+ case 2:
647
+ error = _state.sent();
648
+ console.error("Error fetching Country:", error);
649
+ return [
650
+ 2,
651
+ import_akeyless_types_commons.CountryOptions.IL
652
+ ];
653
+ case 3:
654
+ return [
655
+ 2
656
+ ];
657
+ }
658
+ });
659
+ });
660
+ return function getUserCountryByIp() {
661
+ return _ref.apply(this, arguments);
662
+ };
663
+ }();
664
+ var parsePermissions = function(object) {
665
+ if (!(object === null || object === void 0 ? void 0 : object.features)) {
666
+ return {};
667
+ }
668
+ var features = object.features;
669
+ var result = {};
670
+ features.forEach(function(feature) {
671
+ if (!feature.includes("__")) {
672
+ return;
673
+ }
674
+ var _feature_split = _sliced_to_array(feature.split("__"), 2), featureType = _feature_split[0], featureName = _feature_split[1];
675
+ if (!featureType || !featureName) {
676
+ return;
677
+ }
678
+ if (!result[featureType]) {
679
+ result[featureType] = {};
680
+ }
681
+ result[featureType][featureName] = true;
682
+ });
683
+ return result;
684
+ };
685
+ var initializeUserPermissions = /*#__PURE__*/ function() {
686
+ var _ref = _async_to_generator(function(param) {
687
+ var phoneNumber, email, firstTimeArray, getUpdatePermissions, unsubscribe, permissions, queryConditions, _snapshot, promise, unsubscribeSnapshot, error;
688
+ return _ts_generator(this, function(_state) {
689
+ switch(_state.label){
690
+ case 0:
691
+ phoneNumber = param.phoneNumber, email = param.email, firstTimeArray = param.firstTimeArray, getUpdatePermissions = param.getUpdatePermissions;
692
+ unsubscribe = null;
693
+ permissions = {};
694
+ _state.label = 1;
695
+ case 1:
696
+ _state.trys.push([
697
+ 1,
698
+ 3,
699
+ ,
700
+ 4
701
+ ]);
702
+ queryConditions = [
703
+ phoneNumber ? {
704
+ field_name: "phone_number",
705
+ operator: "in",
706
+ value: [
707
+ phoneNumber,
708
+ local_israel_phone_format(phoneNumber)
709
+ ]
710
+ } : {
711
+ field_name: "email",
712
+ operator: "==",
713
+ value: email
714
+ }
715
+ ];
716
+ _snapshot = snapshot({
717
+ collectionName: "nx-users",
718
+ conditions: queryConditions,
719
+ onFirstTime: function(docs) {
720
+ if (!docs.length) {
721
+ throw new Error("User not found");
722
+ }
723
+ permissions = parsePermissions(docs[0]);
724
+ getUpdatePermissions(parsePermissions(docs[0]));
725
+ },
726
+ onModify: function(docs) {
727
+ getUpdatePermissions(parsePermissions(docs[0]));
728
+ }
729
+ }, firstTimeArray), promise = _snapshot.promise, unsubscribeSnapshot = _snapshot.unsubscribe;
730
+ unsubscribe = unsubscribeSnapshot;
731
+ return [
732
+ 4,
733
+ promise
734
+ ];
735
+ case 2:
736
+ _state.sent();
737
+ return [
738
+ 2,
739
+ {
740
+ unsubscribe: unsubscribe,
741
+ permissions: permissions
742
+ }
743
+ ];
744
+ case 3:
745
+ error = _state.sent();
746
+ if (unsubscribe) {
747
+ unsubscribe();
748
+ }
749
+ console.error("Error initializing user permissions:", error.message);
750
+ throw error;
751
+ case 4:
752
+ return [
753
+ 2
754
+ ];
755
+ }
756
+ });
757
+ });
758
+ return function initializeUserPermissions(_) {
759
+ return _ref.apply(this, arguments);
760
+ };
761
+ }();
762
+ var userNameFormat = function(user) {
763
+ return "".concat((user === null || user === void 0 ? void 0 : user.first_name) || "", " ").concat((user === null || user === void 0 ? void 0 : user.last_name) || "").trim();
764
+ };
765
+ var multiStringFormat = function(str1, str2, str3) {
766
+ return "".concat(str1, " ").concat(str2 || "", " ").concat(str3 || "").trim();
767
+ };
768
+ var getLocationUrl = function(lng, lat) {
769
+ return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
770
+ };
771
+ var isNodeEnv = typeof process !== "undefined" && process.env;
772
+ var _ref = {
773
+ mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta.env.VITE_MODE,
774
+ isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta.env.VITE_is_local) === "true"
775
+ }, mode = _ref.mode, isLocal = _ref.isLocal;
776
+ // src/helpers/firebase.ts
777
+ var import_meta2 = {};
595
778
  var initApp = function() {
596
779
  var isNodeEnv2 = typeof process !== "undefined" && process.env;
597
780
  var firebaseConfig = {
598
- apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta.env.VITE_API_KEY,
599
- authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta.env.VITE_AUTH_DOMAIN,
600
- projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta.env.VITE_PROJECT_ID,
601
- storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta.env.VITE_STORAGE_BUCKET,
602
- messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta.env.VITE_MESSAGING_SENDER_ID,
603
- appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta.env.VITE_APP_ID
781
+ apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta2.env.VITE_API_KEY,
782
+ authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta2.env.VITE_AUTH_DOMAIN,
783
+ projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta2.env.VITE_PROJECT_ID,
784
+ storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta2.env.VITE_STORAGE_BUCKET,
785
+ messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta2.env.VITE_MESSAGING_SENDER_ID,
786
+ appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta2.env.VITE_APP_ID
604
787
  };
605
788
  try {
606
789
  var app2 = (0, import_app.initializeApp)(firebaseConfig);
@@ -609,7 +792,7 @@ var initApp = function() {
609
792
  var db2 = (0, import_firestore.getFirestore)(app2);
610
793
  var storage2 = (0, import_storage.getStorage)(app2);
611
794
  var googleLoginProvider2 = new import_auth.GoogleAuthProvider();
612
- var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta.env.VITE_RECAPTCHA_SITE_KEY;
795
+ var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta2.env.VITE_RECAPTCHA_SITE_KEY;
613
796
  var result = {
614
797
  db: db2,
615
798
  auth: auth2,
@@ -1010,7 +1193,7 @@ var delete_document = /*#__PURE__*/ function() {
1010
1193
  return _ref.apply(this, arguments);
1011
1194
  };
1012
1195
  }();
1013
- var query_document = /*#__PURE__*/ function() {
1196
+ var query_document2 = /*#__PURE__*/ function() {
1014
1197
  var _ref = _async_to_generator(function(collection_path, field_name, operator, value) {
1015
1198
  var ignore_log, q, query_snapshot, documents, error;
1016
1199
  var _arguments = arguments;
@@ -1059,7 +1242,7 @@ var query_document = /*#__PURE__*/ function() {
1059
1242
  }
1060
1243
  });
1061
1244
  });
1062
- return function query_document(collection_path, field_name, operator, value) {
1245
+ return function query_document2(collection_path, field_name, operator, value) {
1063
1246
  return _ref.apply(this, arguments);
1064
1247
  };
1065
1248
  }();
@@ -1434,7 +1617,7 @@ var getUserByPhone = /*#__PURE__*/ function() {
1434
1617
  ];
1435
1618
  return [
1436
1619
  4,
1437
- query_document("nx-users", "phone_number", "in", phones, true)
1620
+ query_document2("nx-users", "phone_number", "in", phones, true)
1438
1621
  ];
1439
1622
  case 1:
1440
1623
  return [
@@ -1455,7 +1638,7 @@ var getUserByEmail = /*#__PURE__*/ function() {
1455
1638
  case 0:
1456
1639
  return [
1457
1640
  4,
1458
- query_document("nx-users", "email", "==", email, true)
1641
+ query_document2("nx-users", "email", "==", email, true)
1459
1642
  ];
1460
1643
  case 1:
1461
1644
  return [
@@ -1591,186 +1774,16 @@ var addAuditRecord = /*#__PURE__*/ function() {
1591
1774
  return _ref.apply(this, arguments);
1592
1775
  };
1593
1776
  }();
1594
- // src/helpers/global.ts
1595
- var import_akeyless_types_commons = require("akeyless-types-commons");
1596
- var import_axios = __toESM(require("axios"));
1597
- var import_lodash = require("lodash");
1598
- var import_meta2 = {};
1599
- var calculateBearing = function(startLat, startLng, endLat, endLng) {
1600
- if (startLat === endLat || startLng === endLng) {
1601
- return 0;
1777
+ var validateUserStatusAndPermissions = function(user, app2) {
1778
+ if (!user || user.status === "deleted") {
1779
+ throw "number_not_in_system";
1602
1780
  }
1603
- if (startLat === void 0 || startLng === void 0 || endLat === void 0 || endLng === void 0) {
1604
- return 0;
1781
+ var userPermissions = parsePermissions(user);
1782
+ if (!userPermissions[app2]) {
1783
+ throw "user_without_permission";
1605
1784
  }
1606
- var startLatRad = startLat * Math.PI / 180;
1607
- var startLngRad = startLng * Math.PI / 180;
1608
- var endLatRad = endLat * Math.PI / 180;
1609
- var endLngRad = endLng * Math.PI / 180;
1610
- var dLon = endLngRad - startLngRad;
1611
- var y = Math.sin(dLon) * Math.cos(endLatRad);
1612
- var x = Math.cos(startLatRad) * Math.sin(endLatRad) - Math.sin(startLatRad) * Math.cos(endLatRad) * Math.cos(dLon);
1613
- var bearing = Math.atan2(y, x) * 180 / Math.PI;
1614
- return (bearing + 360) % 360;
1615
- };
1616
- var renderOnce = function() {
1617
- return true;
1618
- };
1619
- var propsAreEqual = function(prevProps, nextProps) {
1620
- return (0, import_lodash.isEqual)(prevProps, nextProps);
1621
- };
1622
- var getUserCountryByIp = /*#__PURE__*/ function() {
1623
- var _ref = _async_to_generator(function() {
1624
- var response, error;
1625
- return _ts_generator(this, function(_state) {
1626
- switch(_state.label){
1627
- case 0:
1628
- _state.trys.push([
1629
- 0,
1630
- 2,
1631
- ,
1632
- 3
1633
- ]);
1634
- return [
1635
- 4,
1636
- import_axios.default.get("https://ipapi.co/json/")
1637
- ];
1638
- case 1:
1639
- response = _state.sent();
1640
- return [
1641
- 2,
1642
- (response.data.country_code || import_akeyless_types_commons.CountryOptions.IL).toLowerCase()
1643
- ];
1644
- case 2:
1645
- error = _state.sent();
1646
- console.error("Error fetching Country:", error);
1647
- return [
1648
- 2,
1649
- import_akeyless_types_commons.CountryOptions.IL
1650
- ];
1651
- case 3:
1652
- return [
1653
- 2
1654
- ];
1655
- }
1656
- });
1657
- });
1658
- return function getUserCountryByIp() {
1659
- return _ref.apply(this, arguments);
1660
- };
1661
- }();
1662
- var parsePermissions = function(object) {
1663
- if (!(object === null || object === void 0 ? void 0 : object.features)) {
1664
- return {};
1665
- }
1666
- var features = object.features;
1667
- var result = {};
1668
- features.forEach(function(feature) {
1669
- if (!feature.includes("__")) {
1670
- return;
1671
- }
1672
- var _feature_split = _sliced_to_array(feature.split("__"), 2), featureType = _feature_split[0], featureName = _feature_split[1];
1673
- if (!featureType || !featureName) {
1674
- return;
1675
- }
1676
- if (!result[featureType]) {
1677
- result[featureType] = {};
1678
- }
1679
- result[featureType][featureName] = true;
1680
- });
1681
- return result;
1785
+ return userPermissions;
1682
1786
  };
1683
- var initializeUserPermissions = /*#__PURE__*/ function() {
1684
- var _ref = _async_to_generator(function(param) {
1685
- var phoneNumber, email, firstTimeArray, getUpdatePermissions, unsubscribe, permissions, queryConditions, _snapshot, promise, unsubscribeSnapshot, error;
1686
- return _ts_generator(this, function(_state) {
1687
- switch(_state.label){
1688
- case 0:
1689
- phoneNumber = param.phoneNumber, email = param.email, firstTimeArray = param.firstTimeArray, getUpdatePermissions = param.getUpdatePermissions;
1690
- unsubscribe = null;
1691
- permissions = {};
1692
- _state.label = 1;
1693
- case 1:
1694
- _state.trys.push([
1695
- 1,
1696
- 3,
1697
- ,
1698
- 4
1699
- ]);
1700
- queryConditions = [
1701
- phoneNumber ? {
1702
- field_name: "phone_number",
1703
- operator: "in",
1704
- value: [
1705
- phoneNumber,
1706
- local_israel_phone_format(phoneNumber)
1707
- ]
1708
- } : {
1709
- field_name: "email",
1710
- operator: "==",
1711
- value: email
1712
- }
1713
- ];
1714
- _snapshot = snapshot({
1715
- collectionName: "nx-users",
1716
- conditions: queryConditions,
1717
- onFirstTime: function(docs) {
1718
- if (!docs.length) {
1719
- throw new Error("User not found");
1720
- }
1721
- permissions = parsePermissions(docs[0]);
1722
- getUpdatePermissions(parsePermissions(docs[0]));
1723
- },
1724
- onModify: function(docs) {
1725
- getUpdatePermissions(parsePermissions(docs[0]));
1726
- }
1727
- }, firstTimeArray), promise = _snapshot.promise, unsubscribeSnapshot = _snapshot.unsubscribe;
1728
- unsubscribe = unsubscribeSnapshot;
1729
- return [
1730
- 4,
1731
- promise
1732
- ];
1733
- case 2:
1734
- _state.sent();
1735
- return [
1736
- 2,
1737
- {
1738
- unsubscribe: unsubscribe,
1739
- permissions: permissions
1740
- }
1741
- ];
1742
- case 3:
1743
- error = _state.sent();
1744
- if (unsubscribe) {
1745
- unsubscribe();
1746
- }
1747
- console.error("Error initializing user permissions:", error.message);
1748
- throw error;
1749
- case 4:
1750
- return [
1751
- 2
1752
- ];
1753
- }
1754
- });
1755
- });
1756
- return function initializeUserPermissions(_) {
1757
- return _ref.apply(this, arguments);
1758
- };
1759
- }();
1760
- var userNameFormat = function(user) {
1761
- return "".concat((user === null || user === void 0 ? void 0 : user.first_name) || "", " ").concat((user === null || user === void 0 ? void 0 : user.last_name) || "").trim();
1762
- };
1763
- var multiStringFormat = function(str1, str2, str3) {
1764
- return "".concat(str1, " ").concat(str2 || "", " ").concat(str3 || "").trim();
1765
- };
1766
- var getLocationUrl = function(lng, lat) {
1767
- return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
1768
- };
1769
- var isNodeEnv = typeof process !== "undefined" && process.env;
1770
- var _ref = {
1771
- mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta2.env.VITE_MODE,
1772
- isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta2.env.VITE_is_local) === "true"
1773
- }, mode = _ref.mode, isLocal = _ref.isLocal;
1774
1787
  // src/helpers/forms.ts
1775
1788
  var import_xregexp = __toESM(require("xregexp"));
1776
1789
  var textRegex = (0, import_xregexp.default)("[^\\p{L}\\s-]", "gu");
@@ -2103,6 +2116,7 @@ var nx_api_call = /*#__PURE__*/ function() {
2103
2116
  useLoginWithGoogle: useLoginWithGoogle,
2104
2117
  useStoreValues: useStoreValues,
2105
2118
  useValidation: useValidation,
2106
- userNameFormat: userNameFormat
2119
+ userNameFormat: userNameFormat,
2120
+ validateUserStatusAndPermissions: validateUserStatusAndPermissions
2107
2121
  });
2108
2122
  //# sourceMappingURL=index.js.map