@via-profit/ability 1.1.0 → 2.0.0-rc.2
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/README.md +155 -310
- package/assets/ability-01.drawio.png +0 -0
- package/build/playground.js +910 -0
- package/build/playground.js.map +1 -0
- package/dist/AbilityCode.d.ts +7 -0
- package/dist/AbilityCompare.d.ts +6 -0
- package/dist/AbilityCondition.d.ts +12 -0
- package/dist/AbilityError.d.ts +9 -0
- package/dist/AbilityMatch.d.ts +7 -0
- package/dist/AbilityParser.d.ts +33 -0
- package/dist/AbilityPolicy.d.ts +42 -51
- package/dist/AbilityPolicyEffect.d.ts +6 -0
- package/dist/AbilityPolicyResult.d.ts +6 -0
- package/dist/AbilityResolver.d.ts +30 -0
- package/dist/AbilityRule.d.ts +24 -95
- package/dist/AbilityRuleSet.d.ts +44 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +626 -379
- package/dist/playground.d.ts +26 -0
- package/package.json +4 -2
- package/dist/AbilityService.d.ts +0 -74
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type Resources = {
|
|
2
|
+
readonly ['account.read']: {
|
|
3
|
+
readonly account: {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly roles: readonly string[];
|
|
6
|
+
} | null;
|
|
7
|
+
readonly resource: {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
readonly ['access.auth']: {
|
|
12
|
+
readonly token: {
|
|
13
|
+
readonly type: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
} | null;
|
|
16
|
+
};
|
|
17
|
+
readonly ['order.update']: {
|
|
18
|
+
readonly account: {
|
|
19
|
+
readonly roles: readonly string[];
|
|
20
|
+
readonly department: string;
|
|
21
|
+
} | null;
|
|
22
|
+
readonly order: {
|
|
23
|
+
readonly status: string;
|
|
24
|
+
} | null;
|
|
25
|
+
};
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@via-profit/ability",
|
|
3
3
|
"support": "https://via-profit.ru",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-rc.2",
|
|
5
5
|
"description": "Via-Profit Ability service",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"ability",
|
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
"pretty": "prettier --write ./src",
|
|
19
19
|
"build:dev": "cross-env NODE_ENV=development webpack --config ./webpack/webpack-config.ts --color --progress",
|
|
20
20
|
"build:dist": "cross-env NODE_ENV=production webpack --config ./webpack/webpack-config.ts --color --progress",
|
|
21
|
+
"build:playground": "cross-env NODE_ENV=development webpack --config ./webpack/webpack-config-playground.ts --color --progress",
|
|
22
|
+
"playground": "npm run build:playground -- --watch",
|
|
21
23
|
"test": "jest"
|
|
22
24
|
},
|
|
23
25
|
"repository": {
|
|
24
26
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/via-profit/
|
|
27
|
+
"url": "https://github.com/via-profit/ability.git"
|
|
26
28
|
},
|
|
27
29
|
"author": {
|
|
28
30
|
"name": "Via Profit",
|
package/dist/AbilityService.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import AbilityRule, { AbilityRuleStatus } from './AbilityRule';
|
|
2
|
-
import AbilityPolicy, { AbilityCompareMethod, AbilityPolicyResult } from './AbilityPolicy';
|
|
3
|
-
export type AbilityEnforceResult = {
|
|
4
|
-
readonly permission: AbilityRuleStatus;
|
|
5
|
-
readonly deniedRules: readonly AbilityRule[];
|
|
6
|
-
readonly deniedPolicies: readonly AbilityPolicy[];
|
|
7
|
-
};
|
|
8
|
-
declare class AbilityService {
|
|
9
|
-
/**
|
|
10
|
-
* Create the rule to compare
|
|
11
|
-
*
|
|
12
|
-
* @param ruleName {string} - The rule name
|
|
13
|
-
* @param effect {AbilityRuleStatus} - Return value
|
|
14
|
-
* @param matches {AbilityRuleMatches} - The matching rule he matching rule can be on of the format:
|
|
15
|
-
* \
|
|
16
|
-
* For example, be compared two's data\
|
|
17
|
-
* \
|
|
18
|
-
* _The subject_
|
|
19
|
-
* ```json
|
|
20
|
-
* {"userID": "1", "userDepartament": "NBC"}
|
|
21
|
-
* ```
|
|
22
|
-
* and _The resource_
|
|
23
|
-
* ```json
|
|
24
|
-
* {"departamentID": "154", "departamentName": "NBC"}
|
|
25
|
-
* ```
|
|
26
|
-
* \
|
|
27
|
-
* Now we can make the matching rule:
|
|
28
|
-
* ```json
|
|
29
|
-
* ["subject.userDepartament", "=", "resource.departamentName"]
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* \
|
|
33
|
-
* **Example 2.**\
|
|
34
|
-
* In this case will be compared resource and string:
|
|
35
|
-
* \
|
|
36
|
-
* _The subject_
|
|
37
|
-
* ```json
|
|
38
|
-
* {"userID": "1", "userDepartament": "NBC"}
|
|
39
|
-
* ```
|
|
40
|
-
* and _The resource_ will be «undefined».\
|
|
41
|
-
* Now we can make the matching rule:
|
|
42
|
-
* ```json
|
|
43
|
-
* ["subject.userDepartament", "=", "NBC"]
|
|
44
|
-
* ```
|
|
45
|
-
* \
|
|
46
|
-
* **Example 3.**\
|
|
47
|
-
* In this case will be compared resource and array of string:\
|
|
48
|
-
* \
|
|
49
|
-
* _The subject_
|
|
50
|
-
* ```json
|
|
51
|
-
* {"userID": "1", "userDepartament": "NBC"}
|
|
52
|
-
* ```
|
|
53
|
-
* and _The resource_
|
|
54
|
-
* ```json
|
|
55
|
-
* ["FOX", "NBC", "AONE"]
|
|
56
|
-
* ```
|
|
57
|
-
* \
|
|
58
|
-
* Now we can make the matching rule:
|
|
59
|
-
* ```json
|
|
60
|
-
* ["subject.userDepartament", "=", "resource"]
|
|
61
|
-
* ```
|
|
62
|
-
* **Note: In this rule whe set the resource field as the «resource» string.\
|
|
63
|
-
* This means that we will compare the entire resource as a whole,\
|
|
64
|
-
* and not search for it by field name.**
|
|
65
|
-
*/
|
|
66
|
-
createRule(...args: ConstructorParameters<typeof AbilityRule>): AbilityRule;
|
|
67
|
-
/**
|
|
68
|
-
* Create the Policy class instance
|
|
69
|
-
*/
|
|
70
|
-
createPolicy(...args: ConstructorParameters<typeof AbilityPolicy>): AbilityPolicy;
|
|
71
|
-
checkPolicies(policiesResult: readonly AbilityPolicyResult[], compareMethod?: AbilityCompareMethod | undefined): AbilityEnforceResult;
|
|
72
|
-
enforcePolicies(policiesResult: readonly AbilityPolicyResult[], compareMethod?: AbilityCompareMethod | undefined): void | never;
|
|
73
|
-
}
|
|
74
|
-
export default AbilityService;
|