akeyless-client-commons 1.0.181 → 1.0.183

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.
@@ -335,6 +335,9 @@ __export(index_exports, {
335
335
  chartsRegex: function() {
336
336
  return chartsRegex;
337
337
  },
338
+ checkUserPermissions: function() {
339
+ return checkUserPermissions;
340
+ },
338
341
  cleanNxSites: function() {
339
342
  return cleanNxSites;
340
343
  },
@@ -492,7 +495,7 @@ __export(index_exports, {
492
495
  return propsAreEqual;
493
496
  },
494
497
  query_document: function() {
495
- return query_document2;
498
+ return query_document;
496
499
  },
497
500
  query_document_by_conditions: function() {
498
501
  return query_document_by_conditions;
@@ -612,74 +615,25 @@ var is_iccid = function(number) {
612
615
  if (!number.startsWith("89")) return false;
613
616
  return true;
614
617
  };
615
- // src/helpers/global.ts
616
- var import_akeyless_types_commons = require("akeyless-types-commons");
617
- var import_axios = __toESM(require("axios"));
618
- var import_lodash = require("lodash");
619
- var import_meta = {};
620
- var calculateBearing = function(startLat, startLng, endLat, endLng) {
621
- if (startLat === endLat || startLng === endLng) {
622
- return 0;
618
+ // src/helpers/permissions.ts
619
+ var checkUserPermissions = function(userPermissions, entity, permissions, mode2) {
620
+ var userValues = userPermissions[entity];
621
+ if (!userValues) {
622
+ return false;
623
623
  }
624
- if (startLat === void 0 || startLng === void 0 || endLat === void 0 || endLng === void 0) {
625
- return 0;
624
+ if (!(permissions === null || permissions === void 0 ? void 0 : permissions.length)) {
625
+ return true;
626
626
  }
627
- var startLatRad = startLat * Math.PI / 180;
628
- var startLngRad = startLng * Math.PI / 180;
629
- var endLatRad = endLat * Math.PI / 180;
630
- var endLngRad = endLng * Math.PI / 180;
631
- var dLon = endLngRad - startLngRad;
632
- var y = Math.sin(dLon) * Math.cos(endLatRad);
633
- var x = Math.cos(startLatRad) * Math.sin(endLatRad) - Math.sin(startLatRad) * Math.cos(endLatRad) * Math.cos(dLon);
634
- var bearing = Math.atan2(y, x) * 180 / Math.PI;
635
- return (bearing + 360) % 360;
636
- };
637
- var renderOnce = function() {
638
- return true;
639
- };
640
- var propsAreEqual = function(prevProps, nextProps) {
641
- return (0, import_lodash.isEqual)(prevProps, nextProps);
642
- };
643
- var getUserCountryByIp = /*#__PURE__*/ function() {
644
- var _ref = _async_to_generator(function() {
645
- var response, error;
646
- return _ts_generator(this, function(_state) {
647
- switch(_state.label){
648
- case 0:
649
- _state.trys.push([
650
- 0,
651
- 2,
652
- ,
653
- 3
654
- ]);
655
- return [
656
- 4,
657
- import_axios.default.get("https://ipapi.co/json/")
658
- ];
659
- case 1:
660
- response = _state.sent();
661
- return [
662
- 2,
663
- (response.data.country_code || import_akeyless_types_commons.CountryOptions.IL).toLowerCase()
664
- ];
665
- case 2:
666
- error = _state.sent();
667
- console.error("Error fetching Country:", error);
668
- return [
669
- 2,
670
- import_akeyless_types_commons.CountryOptions.IL
671
- ];
672
- case 3:
673
- return [
674
- 2
675
- ];
676
- }
627
+ if (mode2 === "every") {
628
+ return permissions.every(function(permission) {
629
+ return userValues[permission];
677
630
  });
631
+ }
632
+ return permissions.some(function(permission) {
633
+ return userValues[permission];
678
634
  });
679
- return function getUserCountryByIp() {
680
- return _ref.apply(this, arguments);
681
- };
682
- }();
635
+ };
636
+ checkUserPermissions({}, "dashboard", []);
683
637
  var parsePermissions = function(object) {
684
638
  if (!(object === null || object === void 0 ? void 0 : object.features)) {
685
639
  return {};
@@ -778,93 +732,17 @@ var initializeUserPermissions = /*#__PURE__*/ function() {
778
732
  return _ref.apply(this, arguments);
779
733
  };
780
734
  }();
781
- var userNameFormat = function(user) {
782
- return "".concat((user === null || user === void 0 ? void 0 : user.first_name) || "", " ").concat((user === null || user === void 0 ? void 0 : user.last_name) || "").trim();
783
- };
784
- var multiStringFormat = function(str1, str2, str3) {
785
- return "".concat(str1, " ").concat(str2 || "", " ").concat(str3 || "").trim();
786
- };
787
- var getLocationUrl = function(lng, lat) {
788
- return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
789
- };
790
- var isNodeEnv = typeof process !== "undefined" && process.env;
791
- var _ref = {
792
- mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta.env.VITE_MODE,
793
- isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta.env.VITE_is_local) === "true"
794
- }, mode = _ref.mode, isLocal = _ref.isLocal;
795
- var getFixedNumber = function() {
796
- var number = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, fix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4;
797
- var sum_value = number % 1 === 0 ? number : number.toFixed(fix).replace(/\.?0+$/, "");
798
- return String(sum_value);
799
- };
800
- var getAddressByGeo = /*#__PURE__*/ function() {
801
- var _ref = _async_to_generator(function(param, currentLanguage) {
802
- var lat, lng, language, apiKey, url, _response_data, response, error;
803
- return _ts_generator(this, function(_state) {
804
- switch(_state.label){
805
- case 0:
806
- lat = param.lat, lng = param.lng;
807
- language = currentLanguage === import_akeyless_types_commons.LanguageOptions.He ? "iw" : "en";
808
- apiKey = isNodeEnv ? process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY : import_meta.env.VITE_api_google_key;
809
- url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=".concat(lat, ",").concat(lng, "&key=").concat(apiKey, "&language=").concat(language);
810
- _state.label = 1;
811
- case 1:
812
- _state.trys.push([
813
- 1,
814
- 3,
815
- ,
816
- 4
817
- ]);
818
- return [
819
- 4,
820
- import_axios.default.get(url)
821
- ];
822
- case 2:
823
- response = _state.sent();
824
- if (response === null || response === void 0 ? void 0 : (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.results[0]) {
825
- return [
826
- 2,
827
- response.data.results[0].formatted_address.slice(0, 35)
828
- ];
829
- } else {
830
- return [
831
- 2,
832
- "address not found"
833
- ];
834
- }
835
- return [
836
- 3,
837
- 4
838
- ];
839
- case 3:
840
- error = _state.sent();
841
- console.error("getAddressByGeo error:", error);
842
- return [
843
- 3,
844
- 4
845
- ];
846
- case 4:
847
- return [
848
- 2
849
- ];
850
- }
851
- });
852
- });
853
- return function getAddressByGeo(_, currentLanguage) {
854
- return _ref.apply(this, arguments);
855
- };
856
- }();
857
735
  // src/helpers/firebase.ts
858
- var import_meta2 = {};
736
+ var import_meta = {};
859
737
  var initApp = function() {
860
738
  var isNodeEnv2 = typeof process !== "undefined" && process.env;
861
739
  var firebaseConfig = {
862
- apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta2.env.VITE_API_KEY,
863
- authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta2.env.VITE_AUTH_DOMAIN,
864
- projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta2.env.VITE_PROJECT_ID,
865
- storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta2.env.VITE_STORAGE_BUCKET,
866
- messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta2.env.VITE_MESSAGING_SENDER_ID,
867
- appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta2.env.VITE_APP_ID
740
+ apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta.env.VITE_API_KEY,
741
+ authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta.env.VITE_AUTH_DOMAIN,
742
+ projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta.env.VITE_PROJECT_ID,
743
+ storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta.env.VITE_STORAGE_BUCKET,
744
+ messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta.env.VITE_MESSAGING_SENDER_ID,
745
+ appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta.env.VITE_APP_ID
868
746
  };
869
747
  try {
870
748
  var app2 = (0, import_app.initializeApp)(firebaseConfig);
@@ -873,7 +751,7 @@ var initApp = function() {
873
751
  var db2 = (0, import_firestore.getFirestore)(app2);
874
752
  var storage2 = (0, import_storage.getStorage)(app2);
875
753
  var googleLoginProvider2 = new import_auth.GoogleAuthProvider();
876
- var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta2.env.VITE_RECAPTCHA_SITE_KEY;
754
+ var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta.env.VITE_RECAPTCHA_SITE_KEY;
877
755
  var result = {
878
756
  db: db2,
879
757
  auth: auth2,
@@ -1274,7 +1152,7 @@ var delete_document = /*#__PURE__*/ function() {
1274
1152
  return _ref.apply(this, arguments);
1275
1153
  };
1276
1154
  }();
1277
- var query_document2 = /*#__PURE__*/ function() {
1155
+ var query_document = /*#__PURE__*/ function() {
1278
1156
  var _ref = _async_to_generator(function(collection_path, field_name, operator, value) {
1279
1157
  var ignore_log, q, query_snapshot, documents, error;
1280
1158
  var _arguments = arguments;
@@ -1323,7 +1201,7 @@ var query_document2 = /*#__PURE__*/ function() {
1323
1201
  }
1324
1202
  });
1325
1203
  });
1326
- return function query_document2(collection_path, field_name, operator, value) {
1204
+ return function query_document(collection_path, field_name, operator, value) {
1327
1205
  return _ref.apply(this, arguments);
1328
1206
  };
1329
1207
  }();
@@ -1698,7 +1576,7 @@ var getUserByPhone = /*#__PURE__*/ function() {
1698
1576
  ];
1699
1577
  return [
1700
1578
  4,
1701
- query_document2("nx-users", "phone_number", "in", phones, true)
1579
+ query_document("nx-users", "phone_number", "in", phones, true)
1702
1580
  ];
1703
1581
  case 1:
1704
1582
  return [
@@ -1719,7 +1597,7 @@ var getUserByEmail = /*#__PURE__*/ function() {
1719
1597
  case 0:
1720
1598
  return [
1721
1599
  4,
1722
- query_document2("nx-users", "email", "==", email, true)
1600
+ query_document("nx-users", "email", "==", email, true)
1723
1601
  ];
1724
1602
  case 1:
1725
1603
  return [
@@ -1867,6 +1745,150 @@ var validateUserStatusAndPermissions = function(user, app2) {
1867
1745
  }
1868
1746
  return userPermissions;
1869
1747
  };
1748
+ // src/helpers/global.ts
1749
+ var import_akeyless_types_commons = require("akeyless-types-commons");
1750
+ var import_axios = __toESM(require("axios"));
1751
+ var import_lodash = require("lodash");
1752
+ var import_meta2 = {};
1753
+ var calculateBearing = function(startLat, startLng, endLat, endLng) {
1754
+ if (startLat === endLat || startLng === endLng) {
1755
+ return 0;
1756
+ }
1757
+ if (startLat === void 0 || startLng === void 0 || endLat === void 0 || endLng === void 0) {
1758
+ return 0;
1759
+ }
1760
+ var startLatRad = startLat * Math.PI / 180;
1761
+ var startLngRad = startLng * Math.PI / 180;
1762
+ var endLatRad = endLat * Math.PI / 180;
1763
+ var endLngRad = endLng * Math.PI / 180;
1764
+ var dLon = endLngRad - startLngRad;
1765
+ var y = Math.sin(dLon) * Math.cos(endLatRad);
1766
+ var x = Math.cos(startLatRad) * Math.sin(endLatRad) - Math.sin(startLatRad) * Math.cos(endLatRad) * Math.cos(dLon);
1767
+ var bearing = Math.atan2(y, x) * 180 / Math.PI;
1768
+ return (bearing + 360) % 360;
1769
+ };
1770
+ var renderOnce = function() {
1771
+ return true;
1772
+ };
1773
+ var propsAreEqual = function(prevProps, nextProps) {
1774
+ return (0, import_lodash.isEqual)(prevProps, nextProps);
1775
+ };
1776
+ var getUserCountryByIp = /*#__PURE__*/ function() {
1777
+ var _ref = _async_to_generator(function() {
1778
+ var response, error;
1779
+ return _ts_generator(this, function(_state) {
1780
+ switch(_state.label){
1781
+ case 0:
1782
+ _state.trys.push([
1783
+ 0,
1784
+ 2,
1785
+ ,
1786
+ 3
1787
+ ]);
1788
+ return [
1789
+ 4,
1790
+ import_axios.default.get("https://ipapi.co/json/")
1791
+ ];
1792
+ case 1:
1793
+ response = _state.sent();
1794
+ return [
1795
+ 2,
1796
+ (response.data.country_code || import_akeyless_types_commons.CountryOptions.IL).toLowerCase()
1797
+ ];
1798
+ case 2:
1799
+ error = _state.sent();
1800
+ console.error("Error fetching Country:", error);
1801
+ return [
1802
+ 2,
1803
+ import_akeyless_types_commons.CountryOptions.IL
1804
+ ];
1805
+ case 3:
1806
+ return [
1807
+ 2
1808
+ ];
1809
+ }
1810
+ });
1811
+ });
1812
+ return function getUserCountryByIp() {
1813
+ return _ref.apply(this, arguments);
1814
+ };
1815
+ }();
1816
+ var userNameFormat = function(user) {
1817
+ return "".concat((user === null || user === void 0 ? void 0 : user.first_name) || "", " ").concat((user === null || user === void 0 ? void 0 : user.last_name) || "").trim();
1818
+ };
1819
+ var multiStringFormat = function(str1, str2, str3) {
1820
+ return "".concat(str1, " ").concat(str2 || "", " ").concat(str3 || "").trim();
1821
+ };
1822
+ var getLocationUrl = function(lng, lat) {
1823
+ return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
1824
+ };
1825
+ var isNodeEnv = typeof process !== "undefined" && process.env;
1826
+ var _ref = {
1827
+ mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta2.env.VITE_MODE,
1828
+ isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta2.env.VITE_is_local) === "true"
1829
+ }, mode = _ref.mode, isLocal = _ref.isLocal;
1830
+ var getFixedNumber = function() {
1831
+ var number = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, fix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4;
1832
+ var sum_value = number % 1 === 0 ? number : number.toFixed(fix).replace(/\.?0+$/, "");
1833
+ return String(sum_value);
1834
+ };
1835
+ var getAddressByGeo = /*#__PURE__*/ function() {
1836
+ var _ref = _async_to_generator(function(param, currentLanguage) {
1837
+ var lat, lng, language, apiKey, url, _response_data, response, error;
1838
+ return _ts_generator(this, function(_state) {
1839
+ switch(_state.label){
1840
+ case 0:
1841
+ lat = param.lat, lng = param.lng;
1842
+ language = currentLanguage === import_akeyless_types_commons.LanguageOptions.He ? "iw" : "en";
1843
+ apiKey = isNodeEnv ? process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY : import_meta2.env.VITE_api_google_key;
1844
+ url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=".concat(lat, ",").concat(lng, "&key=").concat(apiKey, "&language=").concat(language);
1845
+ _state.label = 1;
1846
+ case 1:
1847
+ _state.trys.push([
1848
+ 1,
1849
+ 3,
1850
+ ,
1851
+ 4
1852
+ ]);
1853
+ return [
1854
+ 4,
1855
+ import_axios.default.get(url)
1856
+ ];
1857
+ case 2:
1858
+ response = _state.sent();
1859
+ if (response === null || response === void 0 ? void 0 : (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.results[0]) {
1860
+ return [
1861
+ 2,
1862
+ response.data.results[0].formatted_address.slice(0, 35)
1863
+ ];
1864
+ } else {
1865
+ return [
1866
+ 2,
1867
+ "address not found"
1868
+ ];
1869
+ }
1870
+ return [
1871
+ 3,
1872
+ 4
1873
+ ];
1874
+ case 3:
1875
+ error = _state.sent();
1876
+ console.error("getAddressByGeo error:", error);
1877
+ return [
1878
+ 3,
1879
+ 4
1880
+ ];
1881
+ case 4:
1882
+ return [
1883
+ 2
1884
+ ];
1885
+ }
1886
+ });
1887
+ });
1888
+ return function getAddressByGeo(_, currentLanguage) {
1889
+ return _ref.apply(this, arguments);
1890
+ };
1891
+ }();
1870
1892
  // src/helpers/forms.ts
1871
1893
  var import_xregexp = __toESM(require("xregexp"));
1872
1894
  var textRegex = (0, import_xregexp.default)("[^\\p{L}\\s-]", "gu");
@@ -2150,6 +2172,7 @@ var nx_api_call = /*#__PURE__*/ function() {
2150
2172
  callCenterDomain: callCenterDomain,
2151
2173
  carsRegex: carsRegex,
2152
2174
  chartsRegex: chartsRegex,
2175
+ checkUserPermissions: checkUserPermissions,
2153
2176
  cleanNxSites: cleanNxSites,
2154
2177
  cn: cn,
2155
2178
  collections: collections,