ais_auth_lib 1.0.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.
@@ -0,0 +1,4 @@
1
+ import { Condition } from "./interfaces/condition";
2
+ import { ConditionGroup } from "./interfaces/condition-group";
3
+ export declare function evaluateCondition(obj: any, condition: Condition): any;
4
+ export declare function evaluateConditionGroup(obj: any, group: ConditionGroup): any;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateConditionGroup = exports.evaluateCondition = void 0;
4
+ function evaluateCondition(obj, condition) {
5
+ const { attribute, value, operator } = condition;
6
+ switch (operator) {
7
+ case "Равно":
8
+ return obj[attribute] === value;
9
+ case "Не равно":
10
+ return obj[attribute] !== value;
11
+ case "Содержит":
12
+ return obj[attribute].includes(value);
13
+ case "Не содержит":
14
+ return !obj[attribute].includes(value);
15
+ default:
16
+ return false;
17
+ }
18
+ }
19
+ exports.evaluateCondition = evaluateCondition;
20
+ function evaluateConditionGroup(obj, group) {
21
+ const { conditions } = group;
22
+ let result = evaluateCondition(obj, conditions[0]);
23
+ for (let i = 1; i < conditions.length; i++) {
24
+ const condition = conditions[i];
25
+ const currentResult = evaluateCondition(obj, condition);
26
+ if (condition.logicalCondition === "ИЛИ") {
27
+ result = result || currentResult;
28
+ }
29
+ else if (condition.logicalCondition === "И") {
30
+ result = result && currentResult;
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ exports.evaluateConditionGroup = evaluateConditionGroup;
@@ -0,0 +1,2 @@
1
+ import { Rule } from "./interfaces/rule";
2
+ export declare function filterObjects(objects: any[], rules: Rule[]): any[];
package/dist/filter.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterObjects = void 0;
4
+ const conditions_1 = require("./conditions");
5
+ function filterObjects(objects, rules) {
6
+ return objects.filter((obj) => {
7
+ let overallResult = false;
8
+ for (const rule of rules) {
9
+ let ruleResult = (0, conditions_1.evaluateConditionGroup)(obj, rule.conditionGroups[0]);
10
+ for (let i = 1; i < rule.conditionGroups.length; i++) {
11
+ const group = rule.conditionGroups[i];
12
+ const currentResult = (0, conditions_1.evaluateConditionGroup)(obj, group);
13
+ if (group.logicalCondition === "ИЛИ") {
14
+ ruleResult = ruleResult || currentResult;
15
+ }
16
+ else if (group.logicalCondition === "И") {
17
+ ruleResult = ruleResult && currentResult;
18
+ }
19
+ }
20
+ overallResult = overallResult || ruleResult;
21
+ }
22
+ return overallResult;
23
+ });
24
+ }
25
+ exports.filterObjects = filterObjects;
@@ -0,0 +1,3 @@
1
+ export * from "./conditions";
2
+ export * from "./filter";
3
+ export * from "./interfaces/rule";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./conditions"), exports);
18
+ __exportStar(require("./filter"), exports);
19
+ __exportStar(require("./interfaces/rule"), exports);
@@ -0,0 +1,9 @@
1
+ import { Condition } from "./condition";
2
+ import { Rule } from "./rule";
3
+ export interface ConditionGroup {
4
+ uid: string;
5
+ logicalCondition: string | null;
6
+ orderIndex: number;
7
+ conditions: Condition[];
8
+ rule: Rule;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { ConditionGroup } from "./condition-group";
2
+ export interface Condition {
3
+ uid: string;
4
+ attribute: string;
5
+ value: string;
6
+ operator: string;
7
+ orderIndex: number;
8
+ logicalCondition: string;
9
+ conditionGroup: ConditionGroup;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { ConditionGroup } from "./condition-group";
2
+ export interface Rule {
3
+ uid: string;
4
+ resource: string;
5
+ appName: string;
6
+ name: string;
7
+ action: string;
8
+ description: string;
9
+ conditionGroups: ConditionGroup[];
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "ais_auth_lib",
3
+ "version": "1.0.0",
4
+ "description": "auth lib for microservices",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc"
12
+ }
13
+ }