@posiwise/common-services 0.1.98 → 0.2.0

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.
@@ -1515,26 +1515,31 @@ class PermissionService {
1515
1515
  return (this.evaluateBooleanExpression(left) && this.evaluateBooleanExpression(right));
1516
1516
  }
1517
1517
  }
1518
+ // Strip matching outer parens - only when first ( and last ) are a pair
1518
1519
  if (expr.startsWith('(') && expr.endsWith(')')) {
1519
- let d = 0;
1520
- for (let j = 1; j < expr.length - 1; j++) {
1520
+ let depth = 0;
1521
+ for (let j = 0; j < expr.length; j++) {
1521
1522
  if (expr[j] === '(')
1522
- d++;
1523
- if (expr[j] === ')')
1524
- d--;
1525
- if (d < 0)
1526
- return false;
1523
+ depth++;
1524
+ else if (expr[j] === ')')
1525
+ depth--;
1526
+ if (depth === 0) {
1527
+ if (j === expr.length - 1) {
1528
+ return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
1529
+ }
1530
+ break; // First ( doesn't wrap entire expr
1531
+ }
1532
+ if (depth < 0)
1533
+ break;
1527
1534
  }
1528
- return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
1529
1535
  }
1536
+ // Unrecognized token - treat as false for safety
1530
1537
  return false;
1531
1538
  }
1532
1539
  handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug) {
1533
1540
  if (typeof permission !== 'boolean') {
1534
1541
  permission.split(' ').forEach(x => {
1535
1542
  const raw = x.trim();
1536
- if (!raw)
1537
- return; // Skip empty tokens (e.g. from double spaces) - avoids malformed expr
1538
1543
  if (['||', '&&', '(', ')'].includes(raw)) {
1539
1544
  expr += ` ${raw} `;
1540
1545
  }