akeyless-client-commons 1.0.68 → 1.0.69

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.
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React$1 from 'react';
3
- import React__default, { MouseEvent, DetailedHTMLProps, ButtonHTMLAttributes, ReactNode, Dispatch, SetStateAction } from 'react';
3
+ import React__default, { ReactNode, Dispatch, SetStateAction, MouseEvent, DetailedHTMLProps, ButtonHTMLAttributes } from 'react';
4
4
  import { NxUser, TObject, Geo } from 'akeyless-types-commons';
5
5
  import { Command as Command$1 } from 'cmdk';
6
6
  import * as RPNInput from 'react-phone-number-input';
@@ -46,23 +46,6 @@ declare const Version: ({ version, className }: {
46
46
  className?: string;
47
47
  }) => react_jsx_runtime.JSX.Element;
48
48
 
49
- interface GoogleSvgProps {
50
- width?: string;
51
- height?: string;
52
- viewBox?: string;
53
- }
54
- interface LoginWithGoogleButtonProps {
55
- label: string;
56
- onClick: (e: MouseEvent<HTMLButtonElement>, user: NxUser, token: string) => Promise<void>;
57
- className?: string;
58
- containerClassName?: string;
59
- loaderProps?: LoaderProps;
60
- googleSvgProps?: GoogleSvgProps;
61
- onError?: (error: any) => void;
62
- buttonProps?: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
63
- }
64
- declare const LoginWithGoogleButton: ({ label, className, containerClassName, onClick, onError, loaderProps, googleSvgProps, buttonProps, }: LoginWithGoogleButtonProps) => react_jsx_runtime.JSX.Element;
65
-
66
49
  declare const Command: React$1.ForwardRefExoticComponent<Omit<{
67
50
  children?: React$1.ReactNode;
68
51
  } & Pick<Pick<React$1.DetailedHTMLProps<React$1.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React$1.HTMLAttributes<HTMLDivElement>> & {
@@ -128,6 +111,7 @@ interface MultipleSelectorRef {
128
111
  }
129
112
 
130
113
  type Direction = "rtl" | "ltr";
114
+ type AppName = "installer" | "toolbox" | "dashboard";
131
115
 
132
116
  type ValidationType = "text" | "numbers" | "numbersOnly" | "price" | "textNumbers" | "email" | "color" | "address" | "cars" | "charts" | (string & {});
133
117
 
@@ -339,6 +323,24 @@ interface DatePickerProps {
339
323
  buttonText?: string;
340
324
  }
341
325
 
326
+ interface GoogleSvgProps {
327
+ width?: string;
328
+ height?: string;
329
+ viewBox?: string;
330
+ }
331
+ interface LoginWithGoogleButtonProps {
332
+ label: string;
333
+ onClick: (e: MouseEvent<HTMLButtonElement>, user: NxUser, token: string, userPermissions: TObject<TObject<boolean>>) => Promise<void>;
334
+ className?: string;
335
+ containerClassName?: string;
336
+ loaderProps?: LoaderProps;
337
+ googleSvgProps?: GoogleSvgProps;
338
+ onError?: (error: any) => void;
339
+ buttonProps?: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
340
+ appName: AppName;
341
+ }
342
+ declare const LoginWithGoogleButton: ({ label, className, containerClassName, onClick, onError, loaderProps, googleSvgProps, buttonProps, appName, }: LoginWithGoogleButtonProps) => react_jsx_runtime.JSX.Element;
343
+
342
344
  interface FilterableColumn {
343
345
  header: string;
344
346
  dataKey: string;
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React$1 from 'react';
3
- import React__default, { MouseEvent, DetailedHTMLProps, ButtonHTMLAttributes, ReactNode, Dispatch, SetStateAction } from 'react';
3
+ import React__default, { ReactNode, Dispatch, SetStateAction, MouseEvent, DetailedHTMLProps, ButtonHTMLAttributes } from 'react';
4
4
  import { NxUser, TObject, Geo } from 'akeyless-types-commons';
5
5
  import { Command as Command$1 } from 'cmdk';
6
6
  import * as RPNInput from 'react-phone-number-input';
@@ -46,23 +46,6 @@ declare const Version: ({ version, className }: {
46
46
  className?: string;
47
47
  }) => react_jsx_runtime.JSX.Element;
48
48
 
49
- interface GoogleSvgProps {
50
- width?: string;
51
- height?: string;
52
- viewBox?: string;
53
- }
54
- interface LoginWithGoogleButtonProps {
55
- label: string;
56
- onClick: (e: MouseEvent<HTMLButtonElement>, user: NxUser, token: string) => Promise<void>;
57
- className?: string;
58
- containerClassName?: string;
59
- loaderProps?: LoaderProps;
60
- googleSvgProps?: GoogleSvgProps;
61
- onError?: (error: any) => void;
62
- buttonProps?: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
63
- }
64
- declare const LoginWithGoogleButton: ({ label, className, containerClassName, onClick, onError, loaderProps, googleSvgProps, buttonProps, }: LoginWithGoogleButtonProps) => react_jsx_runtime.JSX.Element;
65
-
66
49
  declare const Command: React$1.ForwardRefExoticComponent<Omit<{
67
50
  children?: React$1.ReactNode;
68
51
  } & Pick<Pick<React$1.DetailedHTMLProps<React$1.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React$1.HTMLAttributes<HTMLDivElement>> & {
@@ -128,6 +111,7 @@ interface MultipleSelectorRef {
128
111
  }
129
112
 
130
113
  type Direction = "rtl" | "ltr";
114
+ type AppName = "installer" | "toolbox" | "dashboard";
131
115
 
132
116
  type ValidationType = "text" | "numbers" | "numbersOnly" | "price" | "textNumbers" | "email" | "color" | "address" | "cars" | "charts" | (string & {});
133
117
 
@@ -339,6 +323,24 @@ interface DatePickerProps {
339
323
  buttonText?: string;
340
324
  }
341
325
 
326
+ interface GoogleSvgProps {
327
+ width?: string;
328
+ height?: string;
329
+ viewBox?: string;
330
+ }
331
+ interface LoginWithGoogleButtonProps {
332
+ label: string;
333
+ onClick: (e: MouseEvent<HTMLButtonElement>, user: NxUser, token: string, userPermissions: TObject<TObject<boolean>>) => Promise<void>;
334
+ className?: string;
335
+ containerClassName?: string;
336
+ loaderProps?: LoaderProps;
337
+ googleSvgProps?: GoogleSvgProps;
338
+ onError?: (error: any) => void;
339
+ buttonProps?: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
340
+ appName: AppName;
341
+ }
342
+ declare const LoginWithGoogleButton: ({ label, className, containerClassName, onClick, onError, loaderProps, googleSvgProps, buttonProps, appName, }: LoginWithGoogleButtonProps) => react_jsx_runtime.JSX.Element;
343
+
342
344
  interface FilterableColumn {
343
345
  header: string;
344
346
  dataKey: string;
@@ -685,6 +685,27 @@ var import_meta = {};
685
685
  var renderOnce = function() {
686
686
  return true;
687
687
  };
688
+ var parsePermissions = function(object) {
689
+ if (!(object === null || object === void 0 ? void 0 : object.features)) {
690
+ return {};
691
+ }
692
+ var features = object.features;
693
+ var result = {};
694
+ features.forEach(function(feature) {
695
+ if (!feature.includes("__")) {
696
+ return;
697
+ }
698
+ var _feature_split = _sliced_to_array(feature.split("__"), 2), featureType = _feature_split[0], featureName = _feature_split[1];
699
+ if (!featureType || !featureName) {
700
+ return;
701
+ }
702
+ if (!result[featureType]) {
703
+ result[featureType] = {};
704
+ }
705
+ result[featureType][featureName] = true;
706
+ });
707
+ return result;
708
+ };
688
709
  var getLocationUrl = function(lng, lat) {
689
710
  return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
690
711
  };
@@ -927,6 +948,16 @@ var getUserByIdentifier = /*#__PURE__*/ function() {
927
948
  return _ref.apply(this, arguments);
928
949
  };
929
950
  }();
951
+ var validateUserStatusAndPermissions = function(user, app2) {
952
+ if (!user || user.status === "deleted") {
953
+ throw new Error("user_not_found");
954
+ }
955
+ var userPermissions = parsePermissions(user);
956
+ if (!userPermissions[app2]) {
957
+ throw new Error("user_without_permission");
958
+ }
959
+ return userPermissions;
960
+ };
930
961
  // src/helpers/forms.ts
931
962
  var import_xregexp = __toESM(require("xregexp"));
932
963
  var textRegex = (0, import_xregexp.default)("[^\\p{L}\\s-]", "gu");
@@ -1107,12 +1138,12 @@ var GoogleSvg = function(param) {
1107
1138
  var LoginWithGoogleButton = function(param) {
1108
1139
  var label = param.label, className = param.className, containerClassName = param.containerClassName, onClick = param.onClick, onError = param.onError, _param_loaderProps = param.loaderProps, loaderProps = _param_loaderProps === void 0 ? {
1109
1140
  color: "#000"
1110
- } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps;
1141
+ } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps, appName = param.appName;
1111
1142
  var signInWithGoogle = useLoginWithGoogle();
1112
1143
  var _ref = _sliced_to_array((0, import_react3.useState)(false), 2), isLoading = _ref[0], setIsLoading = _ref[1];
1113
1144
  var onLoginClick = /*#__PURE__*/ function() {
1114
1145
  var _ref = _async_to_generator(function(e) {
1115
- var user, dbUser, token, error;
1146
+ var user, dbUser, token, userPermissions, error;
1116
1147
  return _ts_generator(this, function(_state) {
1117
1148
  switch(_state.label){
1118
1149
  case 0:
@@ -1141,12 +1172,10 @@ var LoginWithGoogleButton = function(param) {
1141
1172
  ];
1142
1173
  case 3:
1143
1174
  token = _state.sent();
1144
- if (!dbUser) {
1145
- throw "user_not_found";
1146
- }
1175
+ userPermissions = validateUserStatusAndPermissions(dbUser, appName);
1147
1176
  return [
1148
1177
  4,
1149
- onClick(e, dbUser, token)
1178
+ onClick(e, dbUser, token, userPermissions)
1150
1179
  ];
1151
1180
  case 4:
1152
1181
  _state.sent();
@@ -485,6 +485,27 @@ import { isEqual } from "lodash";
485
485
  var renderOnce = function() {
486
486
  return true;
487
487
  };
488
+ var parsePermissions = function(object) {
489
+ if (!(object === null || object === void 0 ? void 0 : object.features)) {
490
+ return {};
491
+ }
492
+ var features = object.features;
493
+ var result = {};
494
+ features.forEach(function(feature) {
495
+ if (!feature.includes("__")) {
496
+ return;
497
+ }
498
+ var _feature_split = _sliced_to_array(feature.split("__"), 2), featureType = _feature_split[0], featureName = _feature_split[1];
499
+ if (!featureType || !featureName) {
500
+ return;
501
+ }
502
+ if (!result[featureType]) {
503
+ result[featureType] = {};
504
+ }
505
+ result[featureType][featureName] = true;
506
+ });
507
+ return result;
508
+ };
488
509
  var getLocationUrl = function(lng, lat) {
489
510
  return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
490
511
  };
@@ -726,6 +747,16 @@ var getUserByIdentifier = /*#__PURE__*/ function() {
726
747
  return _ref.apply(this, arguments);
727
748
  };
728
749
  }();
750
+ var validateUserStatusAndPermissions = function(user, app2) {
751
+ if (!user || user.status === "deleted") {
752
+ throw new Error("user_not_found");
753
+ }
754
+ var userPermissions = parsePermissions(user);
755
+ if (!userPermissions[app2]) {
756
+ throw new Error("user_without_permission");
757
+ }
758
+ return userPermissions;
759
+ };
729
760
  // src/helpers/forms.ts
730
761
  import XRegExp from "xregexp";
731
762
  var textRegex = XRegExp("[^\\p{L}\\s-]", "gu");
@@ -906,12 +937,12 @@ var GoogleSvg = function(param) {
906
937
  var LoginWithGoogleButton = function(param) {
907
938
  var label = param.label, className = param.className, containerClassName = param.containerClassName, onClick = param.onClick, onError = param.onError, _param_loaderProps = param.loaderProps, loaderProps = _param_loaderProps === void 0 ? {
908
939
  color: "#000"
909
- } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps;
940
+ } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps, appName = param.appName;
910
941
  var signInWithGoogle = useLoginWithGoogle();
911
942
  var _useState = _sliced_to_array(useState(false), 2), isLoading = _useState[0], setIsLoading = _useState[1];
912
943
  var onLoginClick = /*#__PURE__*/ function() {
913
944
  var _ref = _async_to_generator(function(e) {
914
- var user, dbUser, token, error;
945
+ var user, dbUser, token, userPermissions, error;
915
946
  return _ts_generator(this, function(_state) {
916
947
  switch(_state.label){
917
948
  case 0:
@@ -940,12 +971,10 @@ var LoginWithGoogleButton = function(param) {
940
971
  ];
941
972
  case 3:
942
973
  token = _state.sent();
943
- if (!dbUser) {
944
- throw "user_not_found";
945
- }
974
+ userPermissions = validateUserStatusAndPermissions(dbUser, appName);
946
975
  return [
947
976
  4,
948
- onClick(e, dbUser, token)
977
+ onClick(e, dbUser, token, userPermissions)
949
978
  ];
950
979
  case 4:
951
980
  _state.sent();
@@ -1776,11 +1776,11 @@ var addAuditRecord = /*#__PURE__*/ function() {
1776
1776
  }();
1777
1777
  var validateUserStatusAndPermissions = function(user, app2) {
1778
1778
  if (!user || user.status === "deleted") {
1779
- throw "number_not_in_system";
1779
+ throw new Error("user_not_found");
1780
1780
  }
1781
1781
  var userPermissions = parsePermissions(user);
1782
1782
  if (!userPermissions[app2]) {
1783
- throw "user_without_permission";
1783
+ throw new Error("user_without_permission");
1784
1784
  }
1785
1785
  return userPermissions;
1786
1786
  };
@@ -1457,11 +1457,11 @@ var addAuditRecord = /*#__PURE__*/ function() {
1457
1457
  }();
1458
1458
  var validateUserStatusAndPermissions = function(user, app2) {
1459
1459
  if (!user || user.status === "deleted") {
1460
- throw "number_not_in_system";
1460
+ throw new Error("user_not_found");
1461
1461
  }
1462
1462
  var userPermissions = parsePermissions(user);
1463
1463
  if (!userPermissions[app2]) {
1464
- throw "user_without_permission";
1464
+ throw new Error("user_without_permission");
1465
1465
  }
1466
1466
  return userPermissions;
1467
1467
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akeyless-client-commons",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "scripts": {
5
5
  "build": "tsup",
6
6
  "deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",