ais_auth_lib 1.0.8 → 1.0.10
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/dist/conditions.d.ts +7 -5
- package/dist/conditions.js +92 -61
- package/dist/filter.d.ts +4 -3
- package/dist/filter.js +40 -36
- package/dist/index.d.ts +5 -4
- package/dist/index.js +21 -20
- package/dist/interfaces/company.d.ts +4 -0
- package/dist/interfaces/company.js +2 -0
- package/dist/interfaces/condition-group.d.ts +9 -9
- package/dist/interfaces/condition-group.js +2 -2
- package/dist/interfaces/condition.d.ts +11 -10
- package/dist/interfaces/condition.js +2 -2
- package/dist/interfaces/division.d.ts +5 -0
- package/dist/interfaces/division.js +2 -0
- package/dist/interfaces/employee.d.ts +12 -0
- package/dist/interfaces/employee.js +2 -0
- package/dist/interfaces/evaluation-context.d.ts +4 -0
- package/dist/interfaces/evaluation-context.js +2 -0
- package/dist/interfaces/post.d.ts +4 -0
- package/dist/interfaces/post.js +2 -0
- package/dist/interfaces/rule.d.ts +10 -10
- package/dist/interfaces/rule.js +2 -2
- package/dist/interfaces/user-to-company.d.ts +17 -0
- package/dist/interfaces/user-to-company.js +2 -0
- package/dist/interfaces/user.d.ts +18 -0
- package/dist/interfaces/user.js +9 -0
- package/dist/propertyFilter.d.ts +18 -18
- package/dist/propertyFilter.js +28 -28
- package/package.json +1 -1
package/dist/conditions.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Condition } from "./interfaces/condition";
|
|
2
|
-
import { ConditionGroup } from "./interfaces/condition-group";
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
5
|
-
export declare
|
|
1
|
+
import { Condition } from "./interfaces/condition";
|
|
2
|
+
import { ConditionGroup } from "./interfaces/condition-group";
|
|
3
|
+
import { EvaluationContext } from "./interfaces/evaluation-context";
|
|
4
|
+
export declare function resolveDynamicValue(condition: Condition, context?: EvaluationContext): string | string[];
|
|
5
|
+
export declare function evaluateCondition(obj: any, condition: Condition, context?: EvaluationContext): boolean;
|
|
6
|
+
export declare function evaluateConditionGroup(obj: any, group: ConditionGroup, context?: EvaluationContext): boolean;
|
|
7
|
+
export declare const getPropertiesByPath: (object: any, path: string) => any[];
|
package/dist/conditions.js
CHANGED
|
@@ -1,61 +1,92 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPropertiesByPath = exports.evaluateConditionGroup = exports.evaluateCondition = void 0;
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
case "
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPropertiesByPath = exports.evaluateConditionGroup = exports.evaluateCondition = exports.resolveDynamicValue = void 0;
|
|
4
|
+
function resolveDynamicValue(condition, context) {
|
|
5
|
+
if (!context)
|
|
6
|
+
return undefined;
|
|
7
|
+
switch (condition.attribute) {
|
|
8
|
+
case "userUid":
|
|
9
|
+
if (condition.value == "me") {
|
|
10
|
+
return context.user.uid;
|
|
11
|
+
}
|
|
12
|
+
break;
|
|
13
|
+
case "resources.*.companies.*.division.uid":
|
|
14
|
+
if (condition.value == "my_division") {
|
|
15
|
+
return context.user.companies.map((company) => company.division.uid);
|
|
16
|
+
}
|
|
17
|
+
if (condition.value == "parent_division") {
|
|
18
|
+
return context.user.companies
|
|
19
|
+
.map((company) => company.division.parentUid)
|
|
20
|
+
.filter((d) => d);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
exports.resolveDynamicValue = resolveDynamicValue;
|
|
26
|
+
function evaluateCondition(obj, condition, context) {
|
|
27
|
+
const { attribute, value, operator, valueType } = condition;
|
|
28
|
+
console.log("attr", (0, exports.getPropertiesByPath)(obj, attribute));
|
|
29
|
+
const attributeValues = (0, exports.getPropertiesByPath)(obj, attribute);
|
|
30
|
+
if (valueType === "dynamic" && !context) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const resolved = condition.valueType === "dynamic"
|
|
34
|
+
? resolveDynamicValue(condition, context)
|
|
35
|
+
: value;
|
|
36
|
+
if (resolved === undefined)
|
|
37
|
+
return false;
|
|
38
|
+
const compareValues = Array.isArray(resolved) ? resolved : [resolved];
|
|
39
|
+
switch (operator) {
|
|
40
|
+
case "Равно":
|
|
41
|
+
return attributeValues.some((v) => compareValues.includes(v));
|
|
42
|
+
case "Не равно":
|
|
43
|
+
return attributeValues.every((v) => !compareValues.includes(v));
|
|
44
|
+
case "Содержит":
|
|
45
|
+
return attributeValues.some((v) => typeof v === "string" && compareValues.some((c) => v.includes(c)));
|
|
46
|
+
case "Не содержит":
|
|
47
|
+
return attributeValues.every((v) => typeof v === "string" && compareValues.every((c) => !v.includes(c)));
|
|
48
|
+
default:
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.evaluateCondition = evaluateCondition;
|
|
53
|
+
function evaluateConditionGroup(obj, group, context) {
|
|
54
|
+
const { conditions } = group;
|
|
55
|
+
let result = evaluateCondition(obj, conditions[0], context);
|
|
56
|
+
for (let i = 1; i < conditions.length; i++) {
|
|
57
|
+
const condition = conditions[i];
|
|
58
|
+
const currentResult = evaluateCondition(obj, condition, context);
|
|
59
|
+
if (condition.logicalCondition === "ИЛИ") {
|
|
60
|
+
result = result || currentResult;
|
|
61
|
+
}
|
|
62
|
+
else if (condition.logicalCondition === "И") {
|
|
63
|
+
result = result && currentResult;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
exports.evaluateConditionGroup = evaluateConditionGroup;
|
|
69
|
+
const getPropertiesByPath = (object, path) => {
|
|
70
|
+
const properties = path.split(".");
|
|
71
|
+
let clone = object;
|
|
72
|
+
for (let i = 0; i < properties.length; i++) {
|
|
73
|
+
const property = properties[i];
|
|
74
|
+
if (clone) {
|
|
75
|
+
if (property === "*" && Array.isArray(clone)) {
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const item of clone) {
|
|
78
|
+
const values = (0, exports.getPropertiesByPath)(item, properties.slice(i + 1).join("."));
|
|
79
|
+
result.push(...values);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
if (property in clone) {
|
|
84
|
+
clone = clone[property];
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
return [clone];
|
|
91
|
+
};
|
|
92
|
+
exports.getPropertiesByPath = getPropertiesByPath;
|
package/dist/filter.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { EvaluationContext } from "./interfaces/evaluation-context";
|
|
2
|
+
import { Rule } from "./interfaces/rule";
|
|
3
|
+
export declare function filterObjects(objects: any[], rules: Rule[], context?: EvaluationContext): any[];
|
|
4
|
+
export declare function checkResourceMatchWithRules(obj: any, rules: Rule[], context?: EvaluationContext): any;
|
package/dist/filter.js
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkResourceMatchWithRules = exports.filterObjects = void 0;
|
|
4
|
-
const conditions_1 = require("./conditions");
|
|
5
|
-
function filterObjects(objects, rules) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkResourceMatchWithRules = exports.filterObjects = void 0;
|
|
4
|
+
const conditions_1 = require("./conditions");
|
|
5
|
+
function filterObjects(objects, rules, context) {
|
|
6
|
+
const rulesWithoutCreateAction = rules.map((rule) => ({
|
|
7
|
+
...rule,
|
|
8
|
+
actions: rule.actions.filter((action) => action !== "create"),
|
|
9
|
+
})).filter(rule => rule.actions.length > 0);
|
|
10
|
+
return objects.filter((obj) => {
|
|
11
|
+
return checkResourceMatchWithRules(obj, rulesWithoutCreateAction, context);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.filterObjects = filterObjects;
|
|
15
|
+
function checkResourceMatchWithRules(obj, rules, context) {
|
|
16
|
+
let overallResult = false;
|
|
17
|
+
const actions = new Set();
|
|
18
|
+
for (const rule of rules) {
|
|
19
|
+
let ruleResult = (0, conditions_1.evaluateConditionGroup)(obj, rule.conditionGroups[0], context);
|
|
20
|
+
for (let i = 1; i < rule.conditionGroups.length; i++) {
|
|
21
|
+
const group = rule.conditionGroups[i];
|
|
22
|
+
const currentResult = (0, conditions_1.evaluateConditionGroup)(obj, group, context);
|
|
23
|
+
if (group.logicalCondition === "ИЛИ") {
|
|
24
|
+
ruleResult = ruleResult || currentResult;
|
|
25
|
+
}
|
|
26
|
+
else if (group.logicalCondition === "И") {
|
|
27
|
+
ruleResult = ruleResult && currentResult;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (ruleResult) {
|
|
31
|
+
rule.actions.forEach((action) => actions.add(action));
|
|
32
|
+
}
|
|
33
|
+
overallResult = overallResult || ruleResult;
|
|
34
|
+
}
|
|
35
|
+
if (overallResult) {
|
|
36
|
+
obj.actions = Array.from(actions);
|
|
37
|
+
}
|
|
38
|
+
return overallResult ? obj : null;
|
|
39
|
+
}
|
|
40
|
+
exports.checkResourceMatchWithRules = checkResourceMatchWithRules;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export * from "./conditions";
|
|
2
|
-
export * from "./filter";
|
|
3
|
-
export * from "./interfaces/rule";
|
|
4
|
-
export * from "./propertyFilter";
|
|
1
|
+
export * from "./conditions";
|
|
2
|
+
export * from "./filter";
|
|
3
|
+
export * from "./interfaces/rule";
|
|
4
|
+
export * from "./propertyFilter";
|
|
5
|
+
export * from "./interfaces/evaluation-context";
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
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);
|
|
20
|
-
__exportStar(require("./propertyFilter"), exports);
|
|
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);
|
|
20
|
+
__exportStar(require("./propertyFilter"), exports);
|
|
21
|
+
__exportStar(require("./interfaces/evaluation-context"), exports);
|
|
@@ -1,9 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ConditionGroup } from "./condition-group";
|
|
2
|
-
export interface Condition {
|
|
3
|
-
uid: string;
|
|
4
|
-
attribute: string;
|
|
5
|
-
value: string;
|
|
6
|
-
operator: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { ConditionGroup } from "./condition-group";
|
|
2
|
+
export interface Condition {
|
|
3
|
+
uid: string;
|
|
4
|
+
attribute: string;
|
|
5
|
+
value: string;
|
|
6
|
+
operator: string;
|
|
7
|
+
valueType: "static" | "dynamic";
|
|
8
|
+
orderIndex: number;
|
|
9
|
+
logicalCondition: string;
|
|
10
|
+
conditionGroup?: ConditionGroup;
|
|
11
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Company } from "./company";
|
|
2
|
+
import { Division } from "./division";
|
|
3
|
+
import { Post } from "./post";
|
|
4
|
+
import { User } from "./user";
|
|
5
|
+
import { UserToCompany } from "./user-to-company";
|
|
6
|
+
export declare type Employee = User & {
|
|
7
|
+
companies: (UserToCompany & Company & {
|
|
8
|
+
division?: Division;
|
|
9
|
+
post?: Post;
|
|
10
|
+
head?: User;
|
|
11
|
+
})[];
|
|
12
|
+
};
|
|
@@ -1,10 +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
|
-
actions: string[];
|
|
8
|
-
description: string;
|
|
9
|
-
conditionGroups: ConditionGroup[];
|
|
10
|
-
}
|
|
1
|
+
import { ConditionGroup } from "./condition-group";
|
|
2
|
+
export interface Rule {
|
|
3
|
+
uid: string;
|
|
4
|
+
resource: string;
|
|
5
|
+
appName: string;
|
|
6
|
+
name: string;
|
|
7
|
+
actions: string[];
|
|
8
|
+
description: string;
|
|
9
|
+
conditionGroups: ConditionGroup[];
|
|
10
|
+
}
|
package/dist/interfaces/rule.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface UserToCompany {
|
|
2
|
+
userUid: string;
|
|
3
|
+
companyUid: string;
|
|
4
|
+
divisionUid: string | null;
|
|
5
|
+
postUid: string | null;
|
|
6
|
+
tNumber: string;
|
|
7
|
+
dateOfEmployment: string;
|
|
8
|
+
dateOfDismissal: string | null;
|
|
9
|
+
email1: string;
|
|
10
|
+
email2: string;
|
|
11
|
+
phone1: string;
|
|
12
|
+
phone2: string;
|
|
13
|
+
status: string;
|
|
14
|
+
typeOfEmployment: string;
|
|
15
|
+
isHead: boolean;
|
|
16
|
+
actions: string[];
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface User {
|
|
2
|
+
uid: string;
|
|
3
|
+
name: string;
|
|
4
|
+
type: UserType;
|
|
5
|
+
inn: string;
|
|
6
|
+
username: string;
|
|
7
|
+
email: string;
|
|
8
|
+
city: string;
|
|
9
|
+
avatarUrl: string;
|
|
10
|
+
avatarName: string;
|
|
11
|
+
dateOfBirth: string | null;
|
|
12
|
+
actions: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare enum UserType {
|
|
15
|
+
DEFAULT = "default",
|
|
16
|
+
VIRTUAL = "virtual",
|
|
17
|
+
VACANCY = "vacancy"
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserType = void 0;
|
|
4
|
+
var UserType;
|
|
5
|
+
(function (UserType) {
|
|
6
|
+
UserType["DEFAULT"] = "default";
|
|
7
|
+
UserType["VIRTUAL"] = "virtual";
|
|
8
|
+
UserType["VACANCY"] = "vacancy";
|
|
9
|
+
})(UserType = exports.UserType || (exports.UserType = {}));
|
package/dist/propertyFilter.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export interface Resource {
|
|
2
|
-
name: string;
|
|
3
|
-
alias: string;
|
|
4
|
-
attributes: Attribute[];
|
|
5
|
-
}
|
|
6
|
-
export interface Attribute {
|
|
7
|
-
name: string;
|
|
8
|
-
alias: string;
|
|
9
|
-
type: string;
|
|
10
|
-
}
|
|
11
|
-
export declare const filterProperties: (objects: any[], rules: {
|
|
12
|
-
resource: string;
|
|
13
|
-
propetiesAccess: {
|
|
14
|
-
property: string;
|
|
15
|
-
read: boolean;
|
|
16
|
-
write: boolean;
|
|
17
|
-
}[];
|
|
18
|
-
}[], resources: Resource[]) => {}[];
|
|
1
|
+
export interface Resource {
|
|
2
|
+
name: string;
|
|
3
|
+
alias: string;
|
|
4
|
+
attributes: Attribute[];
|
|
5
|
+
}
|
|
6
|
+
export interface Attribute {
|
|
7
|
+
name: string;
|
|
8
|
+
alias: string;
|
|
9
|
+
type: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const filterProperties: (objects: any[], rules: {
|
|
12
|
+
resource: string;
|
|
13
|
+
propetiesAccess: {
|
|
14
|
+
property: string;
|
|
15
|
+
read: boolean;
|
|
16
|
+
write: boolean;
|
|
17
|
+
}[];
|
|
18
|
+
}[], resources: Resource[]) => {}[];
|
package/dist/propertyFilter.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterProperties = void 0;
|
|
4
|
-
const filterProperties = (objects, rules, resources) => {
|
|
5
|
-
var _a;
|
|
6
|
-
if (rules.length > 0) {
|
|
7
|
-
const resource = rules[0].resource;
|
|
8
|
-
const properties = rules
|
|
9
|
-
.map((rule) => rule.propetiesAccess.map((pa) => pa.property))
|
|
10
|
-
.flat();
|
|
11
|
-
const allAttributes = (_a = resources
|
|
12
|
-
.find((r) => r.name === resource)) === null || _a === void 0 ? void 0 : _a.attributes.map((a) => a.name);
|
|
13
|
-
if (allAttributes) {
|
|
14
|
-
return objects.map((object) => {
|
|
15
|
-
return Object.keys(object).reduce((acc, key) => {
|
|
16
|
-
if (properties.includes(key) || !allAttributes.includes(key)) {
|
|
17
|
-
acc[key] = object[key];
|
|
18
|
-
}
|
|
19
|
-
return acc;
|
|
20
|
-
}, {});
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
else
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
return [];
|
|
27
|
-
};
|
|
28
|
-
exports.filterProperties = filterProperties;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterProperties = void 0;
|
|
4
|
+
const filterProperties = (objects, rules, resources) => {
|
|
5
|
+
var _a;
|
|
6
|
+
if (rules.length > 0) {
|
|
7
|
+
const resource = rules[0].resource;
|
|
8
|
+
const properties = rules
|
|
9
|
+
.map((rule) => rule.propetiesAccess.map((pa) => pa.property))
|
|
10
|
+
.flat();
|
|
11
|
+
const allAttributes = (_a = resources
|
|
12
|
+
.find((r) => r.name === resource)) === null || _a === void 0 ? void 0 : _a.attributes.map((a) => a.name);
|
|
13
|
+
if (allAttributes) {
|
|
14
|
+
return objects.map((object) => {
|
|
15
|
+
return Object.keys(object).reduce((acc, key) => {
|
|
16
|
+
if (properties.includes(key) || !allAttributes.includes(key)) {
|
|
17
|
+
acc[key] = object[key];
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
return [];
|
|
27
|
+
};
|
|
28
|
+
exports.filterProperties = filterProperties;
|