@posiwise/common-services 0.1.42 → 0.1.43

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.
@@ -868,7 +868,7 @@ class PermissionService {
868
868
  setCurrentSubscription(subscription) {
869
869
  PermissionService.selectedSubscription = subscription;
870
870
  }
871
- isGranted(permissionName, productKey = null, permission_key = null) {
871
+ isGranted(permissionName, productKey = null, permission_key = null, productSlug = null) {
872
872
  if (this.user) {
873
873
  const { user } = this;
874
874
  // Admin have access to all the menus.
@@ -876,6 +876,20 @@ class PermissionService {
876
876
  if (this.isSuperAdmin()) {
877
877
  return true;
878
878
  }
879
+ if (permissionName) {
880
+ const selectedProduct = PermissionService?.selectedProduct || this.getCurrentProduct();
881
+ const subscriptionSlug = selectedProduct?.subscription_slug;
882
+ let slugToCheck;
883
+ if (!productSlug) {
884
+ slugToCheck = `Pages.Product.${subscriptionSlug}.`;
885
+ }
886
+ else {
887
+ slugToCheck = productSlug;
888
+ }
889
+ if (!permissionName.includes(slugToCheck)) {
890
+ permissionName = permissionName.replace('Pages.Product.', slugToCheck);
891
+ }
892
+ }
879
893
  // Returning true if user has a given permission
880
894
  // E.g., Pages.Role.CloudOlive.SalesManager
881
895
  // or Pages.Beta or Pages.Alpha
@@ -917,7 +931,7 @@ class PermissionService {
917
931
  grantedPermissionNames: Object.keys(data.granted)
918
932
  };
919
933
  }
920
- evaluatePermissions(permission, productKey = null, permission_key = null) {
934
+ evaluatePermissions(permission, productKey = null, permission_key = null, productSlug = null) {
921
935
  if (!permission) {
922
936
  return false;
923
937
  }
@@ -956,7 +970,7 @@ class PermissionService {
956
970
  let raw = x;
957
971
  if (x.includes('Pages')) {
958
972
  if (productKey) {
959
- raw = `this.isGranted('${x}', '${productKey}', '${permission_key}')`;
973
+ raw = `this.isGranted('${x}', '${productKey}', '${permission_key}', '${productSlug}')`;
960
974
  }
961
975
  else {
962
976
  raw = `this.isGranted('${x}')`;
@@ -987,7 +1001,9 @@ class PermissionService {
987
1001
  if (!product) {
988
1002
  product = this.getCurrentProduct();
989
1003
  }
990
- return !!this.user.auth.granted[`Pages.Product.${product.permission_key}.${product.feature_key}.SubscriptionOwner`];
1004
+ const selectedProduct = PermissionService?.selectedProduct;
1005
+ const subscriptionSlug = selectedProduct?.subscription_slug;
1006
+ return !!this.user.auth.granted[`Pages.Product.${subscriptionSlug}.${product.permission_key}.${product.feature_key}.SubscriptionOwner`];
991
1007
  }
992
1008
  /**
993
1009
  * Any Product Admin regardless of the product being master product or not.
@@ -998,8 +1014,10 @@ class PermissionService {
998
1014
  if (!product) {
999
1015
  product = this.getCurrentProduct();
1000
1016
  }
1001
- return (!!this.user.auth.granted[`Pages.Product.${product.permission_key}.${product.feature_key}.SubscriptionAdmin`] ||
1002
- !!this.user.auth.granted[`Pages.Product.${product.permission_key}.${product.feature_key}.SubscriptionOwner`]);
1017
+ const selectedProduct = PermissionService?.selectedProduct;
1018
+ const subscriptionSlug = selectedProduct?.subscription_slug;
1019
+ return (!!this.user.auth.granted[`Pages.Product.${subscriptionSlug}.${product.permission_key}.${product.feature_key}.SubscriptionAdmin`] ||
1020
+ !!this.user.auth.granted[`Pages.Product.${subscriptionSlug}.${product.permission_key}.${product.feature_key}.SubscriptionOwner`]);
1003
1021
  }
1004
1022
  /**
1005
1023
  * Any Product Admin of the product being the master product
@@ -1008,8 +1026,16 @@ class PermissionService {
1008
1026
  if (!product) {
1009
1027
  product = this.getCurrentProduct();
1010
1028
  }
1011
- return (!!this.user.auth.granted[`Pages.Product.${product.permission_key}.${product.feature_key}.SubscriptionSuperAdmin`] ||
1012
- !!this.user.auth.granted[`Pages.Product.${product.permission_key}.${product.feature_key}.SubscriptionSuperOwner`]);
1029
+ const selectedProduct = PermissionService?.selectedProduct;
1030
+ const subscriptionSlug = selectedProduct?.subscription_slug;
1031
+ return (!!this.user.auth.granted[`Pages.Product.${subscriptionSlug}.${product.permission_key}.${product.feature_key}.SubscriptionSuperAdmin`] ||
1032
+ !!this.user.auth.granted[`Pages.Product.${subscriptionSlug}.${product.permission_key}.${product.feature_key}.SubscriptionSuperOwner`]);
1033
+ }
1034
+ isUserMasterSubscriptionSuperAdmin(product) {
1035
+ if (!product) {
1036
+ product = this.getCurrentProduct();
1037
+ }
1038
+ return !!this.user.auth.granted[`Pages.Product.${product.permission_key}.${product.feature_key}.SubscriptionSuperAdmin`];
1013
1039
  }
1014
1040
  /**
1015
1041
  * Any Product Admin of the product being the master product
@@ -1018,14 +1044,17 @@ class PermissionService {
1018
1044
  if (!product) {
1019
1045
  product = this.getCurrentProduct();
1020
1046
  }
1021
- return !!this.user.auth.granted[`Pages.Product.${product.permission_key}.${product.feature_key}.SubscriptionSuperOwner`];
1047
+ const selectedProduct = PermissionService?.selectedProduct;
1048
+ const subscriptionSlug = selectedProduct?.subscription_slug;
1049
+ return !!this.user.auth.granted[`Pages.Product.${subscriptionSlug}.${product.permission_key}.${product.feature_key}.SubscriptionSuperOwner`];
1022
1050
  }
1023
1051
  setCurrentProduct(product) {
1024
1052
  localStorage.setItem('product', JSON.stringify({
1025
1053
  id: product.id,
1026
1054
  permission_key: product.permission_key,
1027
1055
  feature_key: product.feature_key,
1028
- subscriptionId: product.subscriptionId
1056
+ subscriptionId: product.subscriptionId,
1057
+ subscription_slug: product.subscription_slug
1029
1058
  }));
1030
1059
  }
1031
1060
  getCurrentProduct() {
@@ -1585,10 +1614,10 @@ class CommonService {
1585
1614
  ...HelperService.getPagingParams(paging)
1586
1615
  });
1587
1616
  }
1588
- getIncidentsAdmin(paging, subsriptionId) {
1617
+ getIncidentsAdmin(paging, subscriptionId) {
1589
1618
  return this.api.getWithParams(`${INCIDENTS_PATH_ADMIN}/get_all`, {
1590
1619
  ...HelperService.getPagingParams(paging),
1591
- subscription_id: subsriptionId
1620
+ subscription_id: subscriptionId
1592
1621
  });
1593
1622
  }
1594
1623
  addIncident(data) {
@@ -2510,7 +2539,7 @@ class SentryErrorHandler {
2510
2539
  // Ensure all errors have a proper message
2511
2540
  this.errorMessageFormatter(error);
2512
2541
  // Existing Sentry initialization logic
2513
- this.sentryIntilization(error, incomingError);
2542
+ this.sentryInitialization(error, incomingError);
2514
2543
  }
2515
2544
  handleNonHttpErrorResponse(error) {
2516
2545
  if (typeof error === 'object' && 'message' in error) {
@@ -2534,7 +2563,7 @@ class SentryErrorHandler {
2534
2563
  error = new Error(enhancedErrorMessage); // NOSONAR
2535
2564
  }
2536
2565
  }
2537
- sentryIntilization(error, incomingError) {
2566
+ sentryInitialization(error, incomingError) {
2538
2567
  if (!SentryErrorHandler.sentryInitialized) {
2539
2568
  this.initializeSentryAsync()
2540
2569
  .then(() => {
@@ -2579,6 +2608,9 @@ class SentryErrorHandler {
2579
2608
  });
2580
2609
  }
2581
2610
  handleNonStandardError(error) {
2611
+ if ('isTrusted' in error) {
2612
+ return;
2613
+ }
2582
2614
  // If it's an object but not a standard Error, attempt to log its properties safely
2583
2615
  let errorMessage = 'Captured non-standard error with no message'; // NOSONAR
2584
2616
  // Try to extract any message-like property safely