akeyless-client-commons 1.0.68 → 1.0.70

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,25 @@ interface DatePickerProps {
339
323
  buttonText?: string;
340
324
  }
341
325
 
326
+ interface GoogleSvgProps {
327
+ width?: string;
328
+ height?: string;
329
+ viewBox?: string;
330
+ }
331
+ type LoginWithGoogleCallback = (e: MouseEvent<HTMLButtonElement>, user: NxUser, token: string, userPermissions: TObject<TObject<boolean>>) => Promise<void>;
332
+ interface LoginWithGoogleButtonProps {
333
+ label: string;
334
+ onClick: LoginWithGoogleCallback;
335
+ className?: string;
336
+ containerClassName?: string;
337
+ loaderProps?: LoaderProps;
338
+ googleSvgProps?: GoogleSvgProps;
339
+ onError?: (error: any) => void;
340
+ buttonProps?: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
341
+ appName: AppName;
342
+ }
343
+ declare const LoginWithGoogleButton: ({ label, className, containerClassName, onClick, onError, loaderProps, googleSvgProps, buttonProps, appName, }: LoginWithGoogleButtonProps) => react_jsx_runtime.JSX.Element;
344
+
342
345
  interface FilterableColumn {
343
346
  header: string;
344
347
  dataKey: string;
@@ -542,4 +545,4 @@ interface CodeInputProps {
542
545
  }
543
546
  declare function CodeInput({ codeValue, setCodeValue, className, slotContainerClassName, direction }: CodeInputProps): react_jsx_runtime.JSX.Element;
544
547
 
545
- export { Badge, type BadgeProps, BooleanUi, Button, ButtonDisplay, Checkbox, CodeInput, ConfirmForm, DatePicker, DurationUI, ElementLabel, ErrorBoundary, ExportToExcel, Filter, type FilterProps, GeoUi, type GeoUiProps, Input, InputContainer, InternationalPhonePicker, Loader, type LoaderProps, LoginWithGoogleButton, MaxRowsLabel, ModularForm, MultiSelect, type MultipleSelectorOption, type MultipleSelectorProps, type MultipleSelectorRef, NumberUI, type NumberUIProps, PhoneUI, ProgressComponent, Search, type SearchSelectOptions, type SearchSelectProps, SelectContainer, SelectWithSearch, Summary, Table, TableBody, TableButton, TableCell, TableContext, TableHead, type TableProps, TableProvider, type TableProviderType, TableRow, TextAreaContainer, TimesUI, type UseFilterProps, Version, badgeVariants, buttonVariants, getFixedNumber, useDebounce, useSortValues };
548
+ export { Badge, type BadgeProps, BooleanUi, Button, ButtonDisplay, Checkbox, CodeInput, ConfirmForm, DatePicker, DurationUI, ElementLabel, ErrorBoundary, ExportToExcel, Filter, type FilterProps, GeoUi, type GeoUiProps, Input, InputContainer, InternationalPhonePicker, Loader, type LoaderProps, LoginWithGoogleButton, type LoginWithGoogleCallback, MaxRowsLabel, ModularForm, MultiSelect, type MultipleSelectorOption, type MultipleSelectorProps, type MultipleSelectorRef, NumberUI, type NumberUIProps, PhoneUI, ProgressComponent, Search, type SearchSelectOptions, type SearchSelectProps, SelectContainer, SelectWithSearch, Summary, Table, TableBody, TableButton, TableCell, TableContext, TableHead, type TableProps, TableProvider, type TableProviderType, TableRow, TextAreaContainer, TimesUI, type UseFilterProps, Version, badgeVariants, buttonVariants, getFixedNumber, useDebounce, useSortValues };
@@ -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,25 @@ interface DatePickerProps {
339
323
  buttonText?: string;
340
324
  }
341
325
 
326
+ interface GoogleSvgProps {
327
+ width?: string;
328
+ height?: string;
329
+ viewBox?: string;
330
+ }
331
+ type LoginWithGoogleCallback = (e: MouseEvent<HTMLButtonElement>, user: NxUser, token: string, userPermissions: TObject<TObject<boolean>>) => Promise<void>;
332
+ interface LoginWithGoogleButtonProps {
333
+ label: string;
334
+ onClick: LoginWithGoogleCallback;
335
+ className?: string;
336
+ containerClassName?: string;
337
+ loaderProps?: LoaderProps;
338
+ googleSvgProps?: GoogleSvgProps;
339
+ onError?: (error: any) => void;
340
+ buttonProps?: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
341
+ appName: AppName;
342
+ }
343
+ declare const LoginWithGoogleButton: ({ label, className, containerClassName, onClick, onError, loaderProps, googleSvgProps, buttonProps, appName, }: LoginWithGoogleButtonProps) => react_jsx_runtime.JSX.Element;
344
+
342
345
  interface FilterableColumn {
343
346
  header: string;
344
347
  dataKey: string;
@@ -542,4 +545,4 @@ interface CodeInputProps {
542
545
  }
543
546
  declare function CodeInput({ codeValue, setCodeValue, className, slotContainerClassName, direction }: CodeInputProps): react_jsx_runtime.JSX.Element;
544
547
 
545
- export { Badge, type BadgeProps, BooleanUi, Button, ButtonDisplay, Checkbox, CodeInput, ConfirmForm, DatePicker, DurationUI, ElementLabel, ErrorBoundary, ExportToExcel, Filter, type FilterProps, GeoUi, type GeoUiProps, Input, InputContainer, InternationalPhonePicker, Loader, type LoaderProps, LoginWithGoogleButton, MaxRowsLabel, ModularForm, MultiSelect, type MultipleSelectorOption, type MultipleSelectorProps, type MultipleSelectorRef, NumberUI, type NumberUIProps, PhoneUI, ProgressComponent, Search, type SearchSelectOptions, type SearchSelectProps, SelectContainer, SelectWithSearch, Summary, Table, TableBody, TableButton, TableCell, TableContext, TableHead, type TableProps, TableProvider, type TableProviderType, TableRow, TextAreaContainer, TimesUI, type UseFilterProps, Version, badgeVariants, buttonVariants, getFixedNumber, useDebounce, useSortValues };
548
+ export { Badge, type BadgeProps, BooleanUi, Button, ButtonDisplay, Checkbox, CodeInput, ConfirmForm, DatePicker, DurationUI, ElementLabel, ErrorBoundary, ExportToExcel, Filter, type FilterProps, GeoUi, type GeoUiProps, Input, InputContainer, InternationalPhonePicker, Loader, type LoaderProps, LoginWithGoogleButton, type LoginWithGoogleCallback, MaxRowsLabel, ModularForm, MultiSelect, type MultipleSelectorOption, type MultipleSelectorProps, type MultipleSelectorRef, NumberUI, type NumberUIProps, PhoneUI, ProgressComponent, Search, type SearchSelectOptions, type SearchSelectProps, SelectContainer, SelectWithSearch, Summary, Table, TableBody, TableButton, TableCell, TableContext, TableHead, type TableProps, TableProvider, type TableProviderType, TableRow, TextAreaContainer, TimesUI, type UseFilterProps, Version, badgeVariants, buttonVariants, getFixedNumber, useDebounce, useSortValues };
@@ -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
  };
@@ -792,6 +813,52 @@ var simpleExtractData = function(doc2) {
792
813
  id: doc2.id
793
814
  });
794
815
  };
816
+ var set_document = /*#__PURE__*/ function() {
817
+ var _ref = _async_to_generator(function(collection_path, doc_id, data) {
818
+ var doc_ref, error;
819
+ return _ts_generator(this, function(_state) {
820
+ switch(_state.label){
821
+ case 0:
822
+ _state.trys.push([
823
+ 0,
824
+ 2,
825
+ ,
826
+ 3
827
+ ]);
828
+ doc_ref = (0, import_firestore.doc)(db, collection_path, doc_id);
829
+ return [
830
+ 4,
831
+ (0, import_firestore.setDoc)(doc_ref, data, {
832
+ merge: true
833
+ })
834
+ ];
835
+ case 1:
836
+ _state.sent();
837
+ return [
838
+ 2,
839
+ true
840
+ ];
841
+ case 2:
842
+ error = _state.sent();
843
+ console.error("Failed to create document by id: ".concat(doc_id, " in collection: ").concat(collection_path), {
844
+ error: error,
845
+ data: data
846
+ });
847
+ return [
848
+ 2,
849
+ false
850
+ ];
851
+ case 3:
852
+ return [
853
+ 2
854
+ ];
855
+ }
856
+ });
857
+ });
858
+ return function set_document(collection_path, doc_id, data) {
859
+ return _ref.apply(this, arguments);
860
+ };
861
+ }();
795
862
  var query_document2 = /*#__PURE__*/ function() {
796
863
  var _ref = _async_to_generator(function(collection_path, field_name, operator, value) {
797
864
  var ignore_log, q, query_snapshot, documents, error;
@@ -927,6 +994,103 @@ var getUserByIdentifier = /*#__PURE__*/ function() {
927
994
  return _ref.apply(this, arguments);
928
995
  };
929
996
  }();
997
+ var addLoginAudit = /*#__PURE__*/ function() {
998
+ var _ref = _async_to_generator(function(user, app2, loginBy) {
999
+ var details;
1000
+ return _ts_generator(this, function(_state) {
1001
+ switch(_state.label){
1002
+ case 0:
1003
+ details = {
1004
+ app: app2,
1005
+ login_by: loginBy
1006
+ };
1007
+ return [
1008
+ 4,
1009
+ set_document("nx-users", user.id, {
1010
+ last_login: fire_base_TIME_TEMP()
1011
+ })
1012
+ ];
1013
+ case 1:
1014
+ _state.sent();
1015
+ return [
1016
+ 4,
1017
+ addAuditRecord("login", app2, details, user)
1018
+ ];
1019
+ case 2:
1020
+ _state.sent();
1021
+ return [
1022
+ 2
1023
+ ];
1024
+ }
1025
+ });
1026
+ });
1027
+ return function addLoginAudit(user, app2, loginBy) {
1028
+ return _ref.apply(this, arguments);
1029
+ };
1030
+ }();
1031
+ var addAuditRecord = /*#__PURE__*/ function() {
1032
+ var _ref = _async_to_generator(function(action, entity, details, user) {
1033
+ var ref, data, error;
1034
+ return _ts_generator(this, function(_state) {
1035
+ switch(_state.label){
1036
+ case 0:
1037
+ _state.trys.push([
1038
+ 0,
1039
+ 2,
1040
+ ,
1041
+ 3
1042
+ ]);
1043
+ ref = (0, import_firestore.doc)(collections.audit);
1044
+ data = {
1045
+ action: action,
1046
+ entity: entity,
1047
+ details: details,
1048
+ user: user ? {
1049
+ id: user.id,
1050
+ name: "".concat(user.first_name || "", " ").concat(user.last_name || "").trim(),
1051
+ clients: user.clients
1052
+ } : null
1053
+ };
1054
+ return [
1055
+ 4,
1056
+ (0, import_firestore.setDoc)(ref, _object_spread_props(_object_spread({}, data), {
1057
+ datetime: fire_base_TIME_TEMP()
1058
+ }))
1059
+ ];
1060
+ case 1:
1061
+ _state.sent();
1062
+ return [
1063
+ 2,
1064
+ data
1065
+ ];
1066
+ case 2:
1067
+ error = _state.sent();
1068
+ console.log(error);
1069
+ return [
1070
+ 3,
1071
+ 3
1072
+ ];
1073
+ case 3:
1074
+ return [
1075
+ 2
1076
+ ];
1077
+ }
1078
+ });
1079
+ });
1080
+ return function addAuditRecord(action, entity, details, user) {
1081
+ return _ref.apply(this, arguments);
1082
+ };
1083
+ }();
1084
+ var validateUserStatusAndPermissions = function(user, app2) {
1085
+ if (!user || user.status === "deleted") {
1086
+ throw new Error("user_not_found");
1087
+ }
1088
+ var userPermissions = parsePermissions(user);
1089
+ if (!userPermissions[app2]) {
1090
+ throw new Error("user_without_permission");
1091
+ }
1092
+ return userPermissions;
1093
+ };
930
1094
  // src/helpers/forms.ts
931
1095
  var import_xregexp = __toESM(require("xregexp"));
932
1096
  var textRegex = (0, import_xregexp.default)("[^\\p{L}\\s-]", "gu");
@@ -1107,20 +1271,20 @@ var GoogleSvg = function(param) {
1107
1271
  var LoginWithGoogleButton = function(param) {
1108
1272
  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
1273
  color: "#000"
1110
- } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps;
1274
+ } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps, appName = param.appName;
1111
1275
  var signInWithGoogle = useLoginWithGoogle();
1112
1276
  var _ref = _sliced_to_array((0, import_react3.useState)(false), 2), isLoading = _ref[0], setIsLoading = _ref[1];
1113
1277
  var onLoginClick = /*#__PURE__*/ function() {
1114
1278
  var _ref = _async_to_generator(function(e) {
1115
- var user, dbUser, token, error;
1279
+ var user, dbUser, token, userPermissions, error;
1116
1280
  return _ts_generator(this, function(_state) {
1117
1281
  switch(_state.label){
1118
1282
  case 0:
1119
1283
  _state.trys.push([
1120
1284
  0,
1121
- 5,
1122
1285
  6,
1123
- 7
1286
+ 7,
1287
+ 8
1124
1288
  ]);
1125
1289
  setIsLoading(true);
1126
1290
  return [
@@ -1141,33 +1305,37 @@ var LoginWithGoogleButton = function(param) {
1141
1305
  ];
1142
1306
  case 3:
1143
1307
  token = _state.sent();
1144
- if (!dbUser) {
1145
- throw "user_not_found";
1146
- }
1308
+ userPermissions = validateUserStatusAndPermissions(dbUser, appName);
1147
1309
  return [
1148
1310
  4,
1149
- onClick(e, dbUser, token)
1311
+ addLoginAudit(dbUser, appName, "google")
1150
1312
  ];
1151
1313
  case 4:
1152
1314
  _state.sent();
1153
1315
  return [
1154
- 3,
1155
- 7
1316
+ 4,
1317
+ onClick(e, dbUser, token, userPermissions)
1156
1318
  ];
1157
1319
  case 5:
1320
+ _state.sent();
1321
+ return [
1322
+ 3,
1323
+ 8
1324
+ ];
1325
+ case 6:
1158
1326
  error = _state.sent();
1159
1327
  console.error("error from login with google:", error);
1160
1328
  onError === null || onError === void 0 ? void 0 : onError(error);
1161
1329
  return [
1162
1330
  3,
1163
- 7
1331
+ 8
1164
1332
  ];
1165
- case 6:
1333
+ case 7:
1166
1334
  setIsLoading(false);
1167
1335
  return [
1168
1336
  7
1169
1337
  ];
1170
- case 7:
1338
+ case 8:
1171
1339
  return [
1172
1340
  2
1173
1341
  ];
@@ -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
  };
@@ -591,6 +612,52 @@ var simpleExtractData = function(doc2) {
591
612
  id: doc2.id
592
613
  });
593
614
  };
615
+ var set_document = /*#__PURE__*/ function() {
616
+ var _ref = _async_to_generator(function(collection_path, doc_id, data) {
617
+ var doc_ref, error;
618
+ return _ts_generator(this, function(_state) {
619
+ switch(_state.label){
620
+ case 0:
621
+ _state.trys.push([
622
+ 0,
623
+ 2,
624
+ ,
625
+ 3
626
+ ]);
627
+ doc_ref = doc(db, collection_path, doc_id);
628
+ return [
629
+ 4,
630
+ setDoc(doc_ref, data, {
631
+ merge: true
632
+ })
633
+ ];
634
+ case 1:
635
+ _state.sent();
636
+ return [
637
+ 2,
638
+ true
639
+ ];
640
+ case 2:
641
+ error = _state.sent();
642
+ console.error("Failed to create document by id: ".concat(doc_id, " in collection: ").concat(collection_path), {
643
+ error: error,
644
+ data: data
645
+ });
646
+ return [
647
+ 2,
648
+ false
649
+ ];
650
+ case 3:
651
+ return [
652
+ 2
653
+ ];
654
+ }
655
+ });
656
+ });
657
+ return function set_document(collection_path, doc_id, data) {
658
+ return _ref.apply(this, arguments);
659
+ };
660
+ }();
594
661
  var query_document2 = /*#__PURE__*/ function() {
595
662
  var _ref = _async_to_generator(function(collection_path, field_name, operator, value) {
596
663
  var ignore_log, q, query_snapshot, documents, error;
@@ -726,6 +793,103 @@ var getUserByIdentifier = /*#__PURE__*/ function() {
726
793
  return _ref.apply(this, arguments);
727
794
  };
728
795
  }();
796
+ var addLoginAudit = /*#__PURE__*/ function() {
797
+ var _ref = _async_to_generator(function(user, app2, loginBy) {
798
+ var details;
799
+ return _ts_generator(this, function(_state) {
800
+ switch(_state.label){
801
+ case 0:
802
+ details = {
803
+ app: app2,
804
+ login_by: loginBy
805
+ };
806
+ return [
807
+ 4,
808
+ set_document("nx-users", user.id, {
809
+ last_login: fire_base_TIME_TEMP()
810
+ })
811
+ ];
812
+ case 1:
813
+ _state.sent();
814
+ return [
815
+ 4,
816
+ addAuditRecord("login", app2, details, user)
817
+ ];
818
+ case 2:
819
+ _state.sent();
820
+ return [
821
+ 2
822
+ ];
823
+ }
824
+ });
825
+ });
826
+ return function addLoginAudit(user, app2, loginBy) {
827
+ return _ref.apply(this, arguments);
828
+ };
829
+ }();
830
+ var addAuditRecord = /*#__PURE__*/ function() {
831
+ var _ref = _async_to_generator(function(action, entity, details, user) {
832
+ var ref, data, error;
833
+ return _ts_generator(this, function(_state) {
834
+ switch(_state.label){
835
+ case 0:
836
+ _state.trys.push([
837
+ 0,
838
+ 2,
839
+ ,
840
+ 3
841
+ ]);
842
+ ref = doc(collections.audit);
843
+ data = {
844
+ action: action,
845
+ entity: entity,
846
+ details: details,
847
+ user: user ? {
848
+ id: user.id,
849
+ name: "".concat(user.first_name || "", " ").concat(user.last_name || "").trim(),
850
+ clients: user.clients
851
+ } : null
852
+ };
853
+ return [
854
+ 4,
855
+ setDoc(ref, _object_spread_props(_object_spread({}, data), {
856
+ datetime: fire_base_TIME_TEMP()
857
+ }))
858
+ ];
859
+ case 1:
860
+ _state.sent();
861
+ return [
862
+ 2,
863
+ data
864
+ ];
865
+ case 2:
866
+ error = _state.sent();
867
+ console.log(error);
868
+ return [
869
+ 3,
870
+ 3
871
+ ];
872
+ case 3:
873
+ return [
874
+ 2
875
+ ];
876
+ }
877
+ });
878
+ });
879
+ return function addAuditRecord(action, entity, details, user) {
880
+ return _ref.apply(this, arguments);
881
+ };
882
+ }();
883
+ var validateUserStatusAndPermissions = function(user, app2) {
884
+ if (!user || user.status === "deleted") {
885
+ throw new Error("user_not_found");
886
+ }
887
+ var userPermissions = parsePermissions(user);
888
+ if (!userPermissions[app2]) {
889
+ throw new Error("user_without_permission");
890
+ }
891
+ return userPermissions;
892
+ };
729
893
  // src/helpers/forms.ts
730
894
  import XRegExp from "xregexp";
731
895
  var textRegex = XRegExp("[^\\p{L}\\s-]", "gu");
@@ -906,20 +1070,20 @@ var GoogleSvg = function(param) {
906
1070
  var LoginWithGoogleButton = function(param) {
907
1071
  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
1072
  color: "#000"
909
- } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps;
1073
+ } : _param_loaderProps, googleSvgProps = param.googleSvgProps, buttonProps = param.buttonProps, appName = param.appName;
910
1074
  var signInWithGoogle = useLoginWithGoogle();
911
1075
  var _useState = _sliced_to_array(useState(false), 2), isLoading = _useState[0], setIsLoading = _useState[1];
912
1076
  var onLoginClick = /*#__PURE__*/ function() {
913
1077
  var _ref = _async_to_generator(function(e) {
914
- var user, dbUser, token, error;
1078
+ var user, dbUser, token, userPermissions, error;
915
1079
  return _ts_generator(this, function(_state) {
916
1080
  switch(_state.label){
917
1081
  case 0:
918
1082
  _state.trys.push([
919
1083
  0,
920
- 5,
921
1084
  6,
922
- 7
1085
+ 7,
1086
+ 8
923
1087
  ]);
924
1088
  setIsLoading(true);
925
1089
  return [
@@ -940,33 +1104,37 @@ var LoginWithGoogleButton = function(param) {
940
1104
  ];
941
1105
  case 3:
942
1106
  token = _state.sent();
943
- if (!dbUser) {
944
- throw "user_not_found";
945
- }
1107
+ userPermissions = validateUserStatusAndPermissions(dbUser, appName);
946
1108
  return [
947
1109
  4,
948
- onClick(e, dbUser, token)
1110
+ addLoginAudit(dbUser, appName, "google")
949
1111
  ];
950
1112
  case 4:
951
1113
  _state.sent();
952
1114
  return [
953
- 3,
954
- 7
1115
+ 4,
1116
+ onClick(e, dbUser, token, userPermissions)
955
1117
  ];
956
1118
  case 5:
1119
+ _state.sent();
1120
+ return [
1121
+ 3,
1122
+ 8
1123
+ ];
1124
+ case 6:
957
1125
  error = _state.sent();
958
1126
  console.error("error from login with google:", error);
959
1127
  onError === null || onError === void 0 ? void 0 : onError(error);
960
1128
  return [
961
1129
  3,
962
- 7
1130
+ 8
963
1131
  ];
964
- case 6:
1132
+ case 7:
965
1133
  setIsLoading(false);
966
1134
  return [
967
1135
  7
968
1136
  ];
969
- case 7:
1137
+ case 8:
970
1138
  return [
971
1139
  2
972
1140
  ];
@@ -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.70",
4
4
  "scripts": {
5
5
  "build": "tsup",
6
6
  "deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",