@via-profit/ability 1.0.3 → 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.
@@ -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": "1.0.3",
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/crm.graphql.git"
27
+ "url": "https://github.com/via-profit/ability.git"
26
28
  },
27
29
  "author": {
28
30
  "name": "Via Profit",
@@ -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;
@@ -1,98 +0,0 @@
1
- export type AbilityStatementStatus = 'permit' | 'deny';
2
- type SubjectPrefix = 'subject.' | 'environment.';
3
- export type AbilityStatementMatches = [
4
- `${SubjectPrefix}${string}`,
5
- AbilityCondition,
6
- string | number | boolean
7
- ];
8
- export type AbilityCondition = '=' | '<>' | '>' | '<' | '<=' | '>=' | 'in';
9
- declare class AbilityStatement {
10
- matches: AbilityStatementMatches;
11
- name: string;
12
- effect: AbilityStatementStatus;
13
- /**
14
- * Create the statement to compare
15
- *
16
- * @param statementName {string} - The statement name
17
- * @param effect {AbilityStatementStatus} - Return value
18
- * @param matches {AbilityStatementMatches} - The matching rule he matching rule can be on of the format:
19
- * \
20
- * For example, be compared two's data\
21
- * \
22
- * _The subject_
23
- * ```json
24
- * {"userID": "1", "userDepartament": "NBC"}
25
- * ```
26
- * and _The resource_
27
- * ```json
28
- * {"departamentID": "154", "departamentName": "NBC"}
29
- * ```
30
- * \
31
- * Now we can make the matching rule:
32
- * ```json
33
- * ["subject.userDepartament", "=", "resource.departamentName"]
34
- * ```
35
- *
36
- * \
37
- * **Example 2.**\
38
- * In this case will be compared resource and string:
39
- * \
40
- * _The subject_
41
- * ```json
42
- * {"userID": "1", "userDepartament": "NBC"}
43
- * ```
44
- * and _The resource_ will be «undefined».\
45
- * Now we can make the matching rule:
46
- * ```json
47
- * ["subject.userDepartament", "=", "NBC"]
48
- * ```
49
- * \
50
- * **Example 3.**\
51
- * In this case will be compared resource and array of string:\
52
- * \
53
- * _The subject_
54
- * ```json
55
- * {"userID": "1", "userDepartament": "NBC"}
56
- * ```
57
- * and _The resource_
58
- * ```json
59
- * ["FOX", "NBC", "AONE"]
60
- * ```
61
- * \
62
- * Now we can make the matching rule:
63
- * ```json
64
- * ["subject.userDepartament", "=", "resource"]
65
- * ```
66
- * **Note: In this rule whe set the resource field as the «resource» string.\
67
- * This means that we will compare the entire resource as a whole,\
68
- * and not search for it by field name.**
69
- * \
70
- * **Example 4.**\
71
- * In this case will be compared resource and array of string:\
72
- * \
73
- * _The subject_
74
- * ```json
75
- * {"user": {"account": {"roles": ["admin", "viewer"]}}}
76
- * ```
77
- * and _The resource_
78
- * ```json
79
- * undefined
80
- * ```
81
- * \
82
- * Now we can make the matching rule:
83
- * ```json
84
- * ["subject.user.account.roles", "in", "admin"]
85
- */
86
- constructor(statementName: string, matches: AbilityStatementMatches, effect?: AbilityStatementStatus);
87
- getName(): string;
88
- getEffect(): AbilityStatementStatus;
89
- isPermit(...args: Parameters<AbilityStatement['check']>): boolean;
90
- isDeny(...args: Parameters<AbilityStatement['check']>): boolean;
91
- check(subject: unknown, resource?: unknown | undefined, environment?: unknown | undefined): AbilityStatementStatus;
92
- extractValues(sub: unknown, res?: unknown | undefined, env?: unknown | undefined): [
93
- string | number | boolean | (string | number)[] | null | undefined,
94
- string | number | boolean | (string | number)[] | null | undefined
95
- ];
96
- getDotNotationValue(resource: unknown, desc: string): unknown;
97
- }
98
- export default AbilityStatement;