@posiwise/common-services 0.1.77 → 0.1.79
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.
- package/esm2022/lib/auth.service.mjs +7 -1
- package/esm2022/lib/permission.service.mjs +3 -158
- package/fesm2022/posiwise-common-services.mjs +8 -157
- package/fesm2022/posiwise-common-services.mjs.map +1 -1
- package/lib/auth.service.d.ts +4 -0
- package/lib/permission.service.d.ts +0 -27
- package/package.json +1 -1
|
@@ -965,6 +965,12 @@ class AuthService {
|
|
|
965
965
|
clearTokens() {
|
|
966
966
|
return this.secureTokenStorage.clearTokens();
|
|
967
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* Remove only impersonation tokens (not all tokens)
|
|
970
|
+
*/
|
|
971
|
+
removeImpersonationTokens() {
|
|
972
|
+
return this.secureTokenStorage.removeImpersonatedTokens();
|
|
973
|
+
}
|
|
968
974
|
getToken$() {
|
|
969
975
|
return this.secureTokenStorage.getToken$();
|
|
970
976
|
}
|
|
@@ -1271,8 +1277,8 @@ class PermissionService {
|
|
|
1271
1277
|
}
|
|
1272
1278
|
expr = this.handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug);
|
|
1273
1279
|
// Now expr is made of true/false values with &&, ||, ()
|
|
1274
|
-
//
|
|
1275
|
-
return
|
|
1280
|
+
// eslint-disable-next-line no-eval
|
|
1281
|
+
return eval(expr); // NOSONAR
|
|
1276
1282
|
}
|
|
1277
1283
|
handleNonBooleanPermissions(permission, expr, productKey, permission_key, productSlug) {
|
|
1278
1284
|
if (typeof permission !== 'boolean') {
|
|
@@ -1379,161 +1385,6 @@ class PermissionService {
|
|
|
1379
1385
|
getCurrentProduct() {
|
|
1380
1386
|
return JSON.parse(localStorage.getItem('product'));
|
|
1381
1387
|
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Safely evaluates boolean expressions without using eval()
|
|
1384
|
-
* Supports: true, false, &&, ||, (, )
|
|
1385
|
-
* @param expr - Boolean expression string like "true && false || (true && false)"
|
|
1386
|
-
* @returns boolean result
|
|
1387
|
-
*/
|
|
1388
|
-
evaluateBooleanExpression(expr) {
|
|
1389
|
-
if (!expr || typeof expr !== 'string') {
|
|
1390
|
-
return false;
|
|
1391
|
-
}
|
|
1392
|
-
try {
|
|
1393
|
-
// Clean up the expression - remove extra spaces and normalize
|
|
1394
|
-
const cleanExpr = expr.trim().replace(/\s+/g, ' ');
|
|
1395
|
-
// Simple tokenizer for boolean expressions
|
|
1396
|
-
const tokens = this.tokenizeBooleanExpression(cleanExpr);
|
|
1397
|
-
// Parse and evaluate the expression
|
|
1398
|
-
return this.parseBooleanExpression(tokens);
|
|
1399
|
-
}
|
|
1400
|
-
catch (error) {
|
|
1401
|
-
console.warn('Error evaluating boolean expression:', expr, error);
|
|
1402
|
-
return false;
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
/**
|
|
1406
|
-
* Tokenizes a boolean expression string
|
|
1407
|
-
*/
|
|
1408
|
-
tokenizeBooleanExpression(expr) {
|
|
1409
|
-
const tokens = [];
|
|
1410
|
-
let i = 0;
|
|
1411
|
-
while (i < expr.length) {
|
|
1412
|
-
const char = expr[i];
|
|
1413
|
-
if (this.isWhitespace(char)) {
|
|
1414
|
-
i++;
|
|
1415
|
-
}
|
|
1416
|
-
else if (this.isParenthesis(char)) {
|
|
1417
|
-
tokens.push(char);
|
|
1418
|
-
i++;
|
|
1419
|
-
}
|
|
1420
|
-
else if (this.isDoubleOperator(expr, i, '&')) {
|
|
1421
|
-
tokens.push('&&');
|
|
1422
|
-
i += 2;
|
|
1423
|
-
}
|
|
1424
|
-
else if (this.isDoubleOperator(expr, i, '|')) {
|
|
1425
|
-
tokens.push('||');
|
|
1426
|
-
i += 2;
|
|
1427
|
-
}
|
|
1428
|
-
else {
|
|
1429
|
-
const token = this.collectToken(expr, i);
|
|
1430
|
-
if (token.value) {
|
|
1431
|
-
tokens.push(token.value);
|
|
1432
|
-
}
|
|
1433
|
-
i = token.nextIndex;
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
return tokens;
|
|
1437
|
-
}
|
|
1438
|
-
isWhitespace(char) {
|
|
1439
|
-
return char === ' ';
|
|
1440
|
-
}
|
|
1441
|
-
isParenthesis(char) {
|
|
1442
|
-
return char === '(' || char === ')';
|
|
1443
|
-
}
|
|
1444
|
-
isDoubleOperator(expr, index, operator) {
|
|
1445
|
-
return expr[index] === operator && expr[index + 1] === operator;
|
|
1446
|
-
}
|
|
1447
|
-
collectToken(expr, startIndex) {
|
|
1448
|
-
let current = '';
|
|
1449
|
-
let i = startIndex;
|
|
1450
|
-
while (i < expr.length && ![' ', '(', ')', '&', '|'].includes(expr[i])) {
|
|
1451
|
-
current += expr[i];
|
|
1452
|
-
i++;
|
|
1453
|
-
}
|
|
1454
|
-
return { value: current, nextIndex: i };
|
|
1455
|
-
}
|
|
1456
|
-
/**
|
|
1457
|
-
* Parses and evaluates boolean expression tokens
|
|
1458
|
-
*/
|
|
1459
|
-
parseBooleanExpression(tokens) {
|
|
1460
|
-
// Handle simple cases first
|
|
1461
|
-
if (tokens.length === 1) {
|
|
1462
|
-
return tokens[0] === 'true';
|
|
1463
|
-
}
|
|
1464
|
-
// Convert to postfix notation and evaluate
|
|
1465
|
-
const postfix = this.infixToPostfix(tokens);
|
|
1466
|
-
return this.evaluatePostfix(postfix);
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Converts infix notation to postfix (Reverse Polish Notation)
|
|
1470
|
-
*/
|
|
1471
|
-
infixToPostfix(tokens) {
|
|
1472
|
-
const output = [];
|
|
1473
|
-
const operators = [];
|
|
1474
|
-
const precedence = { '||': 1, '&&': 2 };
|
|
1475
|
-
for (const token of tokens) {
|
|
1476
|
-
if (token === 'true' || token === 'false') {
|
|
1477
|
-
output.push(token);
|
|
1478
|
-
}
|
|
1479
|
-
else if (token === '(') {
|
|
1480
|
-
operators.push(token);
|
|
1481
|
-
}
|
|
1482
|
-
else if (token === ')') {
|
|
1483
|
-
while (operators.length > 0 && operators[operators.length - 1] !== '(') {
|
|
1484
|
-
const op = operators.pop();
|
|
1485
|
-
if (op)
|
|
1486
|
-
output.push(op);
|
|
1487
|
-
}
|
|
1488
|
-
operators.pop(); // Remove '('
|
|
1489
|
-
}
|
|
1490
|
-
else if (token === '&&' || token === '||') {
|
|
1491
|
-
while (operators.length > 0 &&
|
|
1492
|
-
operators[operators.length - 1] !== '(' &&
|
|
1493
|
-
precedence[operators[operators.length - 1]] >= precedence[token]) {
|
|
1494
|
-
const op = operators.pop();
|
|
1495
|
-
if (op)
|
|
1496
|
-
output.push(op);
|
|
1497
|
-
}
|
|
1498
|
-
operators.push(token);
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
while (operators.length > 0) {
|
|
1502
|
-
const op = operators.pop();
|
|
1503
|
-
if (op)
|
|
1504
|
-
output.push(op);
|
|
1505
|
-
}
|
|
1506
|
-
return output;
|
|
1507
|
-
}
|
|
1508
|
-
/**
|
|
1509
|
-
* Evaluates postfix boolean expression
|
|
1510
|
-
*/
|
|
1511
|
-
evaluatePostfix(postfix) {
|
|
1512
|
-
const stack = [];
|
|
1513
|
-
for (const token of postfix) {
|
|
1514
|
-
if (token === 'true') {
|
|
1515
|
-
stack.push(true);
|
|
1516
|
-
}
|
|
1517
|
-
else if (token === 'false') {
|
|
1518
|
-
stack.push(false);
|
|
1519
|
-
}
|
|
1520
|
-
else if (token === '&&') {
|
|
1521
|
-
const b = stack.pop();
|
|
1522
|
-
const a = stack.pop();
|
|
1523
|
-
if (a !== undefined && b !== undefined) {
|
|
1524
|
-
stack.push(a && b);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
else if (token === '||') {
|
|
1528
|
-
const b = stack.pop();
|
|
1529
|
-
const a = stack.pop();
|
|
1530
|
-
if (a !== undefined && b !== undefined) {
|
|
1531
|
-
stack.push(a || b);
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
return stack[0] || false;
|
|
1536
|
-
}
|
|
1537
1388
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: PermissionService, deps: [{ token: MainApiHttpService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1538
1389
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.11", ngImport: i0, type: PermissionService, providedIn: 'root' }); }
|
|
1539
1390
|
}
|