@via-profit/ability 3.5.4 → 3.6.1
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 +0 -30
- package/dist/index.d.ts +435 -201
- package/dist/index.js +1871 -852
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type AbilityCompareCodeType = 'and' | 'or';
|
|
10
|
-
declare class AbilityCompare extends AbilityCode<AbilityCompareCodeType> {
|
|
11
|
-
static and: AbilityCompare;
|
|
12
|
-
static or: AbilityCompare;
|
|
13
|
-
}
|
|
1
|
+
type AbilityCompareCode = 'and' | 'or';
|
|
2
|
+
type AbilityCompareType = AbilityCompareCode & {
|
|
3
|
+
__brand: 'AbilityCompare';
|
|
4
|
+
};
|
|
5
|
+
declare const AbilityCompare: {
|
|
6
|
+
readonly or: AbilityCompareType;
|
|
7
|
+
readonly and: AbilityCompareType;
|
|
8
|
+
};
|
|
14
9
|
|
|
15
|
-
type
|
|
16
|
-
type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
type AbilityConditionCode = '=' | '<>' | '>' | '<' | '>=' | '<=' | 'in' | 'not in' | 'contains' | 'not contains' | 'length greater than' | 'length less than' | 'length equals' | 'always' | 'never';
|
|
11
|
+
type AbilityConditionLiteral = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'in' | 'not_in' | 'greater_than' | 'less_than' | 'less_or_equal' | 'greater_or_equal' | 'length_greater_than' | 'length_less_than' | 'length_equals' | 'always' | 'never';
|
|
12
|
+
type AbilityConditionType = AbilityConditionCode & {
|
|
13
|
+
__brand: 'AbilityCondition';
|
|
14
|
+
};
|
|
15
|
+
declare const AbilityCondition: {
|
|
16
|
+
readonly equals: AbilityConditionType;
|
|
17
|
+
readonly not_equals: AbilityConditionType;
|
|
18
|
+
readonly greater_than: AbilityConditionType;
|
|
19
|
+
readonly less_than: AbilityConditionType;
|
|
20
|
+
readonly less_or_equal: AbilityConditionType;
|
|
21
|
+
readonly greater_or_equal: AbilityConditionType;
|
|
22
|
+
readonly in: AbilityConditionType;
|
|
23
|
+
readonly not_in: AbilityConditionType;
|
|
24
|
+
readonly contains: AbilityConditionType;
|
|
25
|
+
readonly not_contains: AbilityConditionType;
|
|
26
|
+
readonly length_greater_than: AbilityConditionType;
|
|
27
|
+
readonly length_less_than: AbilityConditionType;
|
|
28
|
+
readonly length_equals: AbilityConditionType;
|
|
29
|
+
readonly always: AbilityConditionType;
|
|
30
|
+
readonly never: AbilityConditionType;
|
|
31
|
+
};
|
|
32
|
+
declare function fromLiteral(literal: AbilityConditionLiteral): AbilityConditionType;
|
|
33
|
+
declare function toLiteral(cond: AbilityConditionType): AbilityConditionLiteral;
|
|
34
|
+
declare function isConditionEqual(a: AbilityConditionType | null, b: AbilityConditionType | null): boolean;
|
|
35
|
+
declare function isConditionNotEqual(a: AbilityConditionType | null, b: AbilityConditionType | null): boolean;
|
|
36
36
|
|
|
37
37
|
declare class AbilityError extends Error {
|
|
38
38
|
constructor(message: string, options?: ErrorOptions);
|
|
@@ -41,16 +41,22 @@ declare class AbilityParserError extends Error {
|
|
|
41
41
|
constructor(message: string, options?: ErrorOptions);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
type AbilityMatchCode = 'pending' | 'match' | 'mismatch' | 'except-mismatch' | 'disabled';
|
|
45
|
+
type AbilityMatchType = AbilityMatchCode & {
|
|
46
|
+
__brand: 'AbilityMatch';
|
|
47
|
+
};
|
|
48
|
+
declare const AbilityMatch: {
|
|
49
|
+
readonly pending: AbilityMatchType;
|
|
50
|
+
readonly match: AbilityMatchType;
|
|
51
|
+
readonly mismatch: AbilityMatchType;
|
|
52
|
+
readonly exceptMismatch: AbilityMatchType;
|
|
53
|
+
readonly disabled: AbilityMatchType;
|
|
54
|
+
};
|
|
50
55
|
|
|
51
56
|
type AbilityRuleConfig = {
|
|
52
57
|
readonly id?: string | null;
|
|
53
58
|
readonly name?: string | null;
|
|
59
|
+
readonly description?: string | null;
|
|
54
60
|
/**
|
|
55
61
|
* Subject key path like a 'user.name'
|
|
56
62
|
*/
|
|
@@ -59,15 +65,16 @@ type AbilityRuleConfig = {
|
|
|
59
65
|
* Resource key path like a 'user.name' or value
|
|
60
66
|
*/
|
|
61
67
|
readonly resource: string | number | boolean | null | (string | number | boolean | null)[];
|
|
62
|
-
readonly condition:
|
|
68
|
+
readonly condition: AbilityConditionType;
|
|
69
|
+
readonly disabled?: boolean;
|
|
63
70
|
};
|
|
64
71
|
type AbilityRuleConstructorProps = Omit<AbilityRuleConfig, 'condition'> & {
|
|
65
|
-
readonly condition:
|
|
72
|
+
readonly condition: AbilityConditionType;
|
|
66
73
|
};
|
|
67
74
|
/**
|
|
68
75
|
* Represents a rule that defines a condition to be checked against a subject and resource.
|
|
69
76
|
*/
|
|
70
|
-
declare class AbilityRule<Resources extends object = object, Environment =
|
|
77
|
+
declare class AbilityRule<Resources extends object = object, Environment extends object = object> {
|
|
71
78
|
/**
|
|
72
79
|
* Subject key path like a 'user.name'
|
|
73
80
|
*/
|
|
@@ -76,10 +83,12 @@ declare class AbilityRule<Resources extends object = object, Environment = unkno
|
|
|
76
83
|
* Resource key path like a 'user.name' or value
|
|
77
84
|
*/
|
|
78
85
|
resource: AbilityRuleConfig['resource'];
|
|
79
|
-
condition:
|
|
86
|
+
condition: AbilityConditionType;
|
|
80
87
|
name: string;
|
|
88
|
+
description?: string | null;
|
|
81
89
|
id: string;
|
|
82
|
-
state:
|
|
90
|
+
state: AbilityMatchType;
|
|
91
|
+
disabled: boolean;
|
|
83
92
|
/**
|
|
84
93
|
* Creates an instance of AbilityRule.
|
|
85
94
|
* @param {string} params.id - The unique identifier of the rule.
|
|
@@ -87,26 +96,29 @@ declare class AbilityRule<Resources extends object = object, Environment = unkno
|
|
|
87
96
|
* @param {AbilityCondition} params.condition - The condition to evaluate.
|
|
88
97
|
* @param {string} params.subject - The subject of the rule.
|
|
89
98
|
* @param {string} params.resource - The resource to compare against.
|
|
99
|
+
* @param {boolean} params.disabled - Disabling flag.
|
|
90
100
|
* @param params
|
|
91
101
|
*/
|
|
92
102
|
constructor(params: AbilityRuleConstructorProps);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
static isPrimitive(v: unknown): v is string | number | boolean | null;
|
|
104
|
+
static isNumber(v: unknown): v is number;
|
|
105
|
+
static isString(v: unknown): v is string;
|
|
106
|
+
static valueLen: (v: unknown) => number | null;
|
|
107
|
+
static operatorHandlers: { [K in AbilityConditionLiteral]: (a: unknown, b: unknown) => boolean; };
|
|
98
108
|
/**
|
|
99
109
|
* Check if the rule is matched
|
|
100
110
|
* @param resource - The resource to check
|
|
101
111
|
* @param environment
|
|
102
112
|
*/
|
|
103
|
-
check(resource: Resources | null, environment?: Environment):
|
|
113
|
+
check(resource: Resources | null, environment?: Environment): AbilityMatchType;
|
|
104
114
|
/**
|
|
105
115
|
* Extract values from the resourceData
|
|
106
116
|
* @param resourceData - The resourceData to extract values from
|
|
107
117
|
* @param environment - Environment data
|
|
108
118
|
*/
|
|
109
119
|
extractValues(resourceData: Resources | null, environment?: Environment | null): [AbilityRuleConfig['resource'] | undefined, AbilityRuleConfig['resource'] | undefined];
|
|
120
|
+
private static readonly _pathCache;
|
|
121
|
+
private static _parsePath;
|
|
110
122
|
/**
|
|
111
123
|
* Get the value of the object by dot notation
|
|
112
124
|
* @param resource - The object to get the value from
|
|
@@ -117,86 +129,101 @@ declare class AbilityRule<Resources extends object = object, Environment = unkno
|
|
|
117
129
|
copyWith(props: Partial<{
|
|
118
130
|
id: string | null;
|
|
119
131
|
name: string | null;
|
|
132
|
+
description: string | null;
|
|
120
133
|
subject: string;
|
|
121
134
|
resource: AbilityRuleConfig['resource'];
|
|
122
|
-
condition:
|
|
135
|
+
condition: AbilityConditionType;
|
|
123
136
|
}>): AbilityRule<Resources, Environment>;
|
|
124
|
-
|
|
125
|
-
static
|
|
126
|
-
static
|
|
127
|
-
static
|
|
128
|
-
static
|
|
129
|
-
static
|
|
130
|
-
static
|
|
131
|
-
static
|
|
132
|
-
static
|
|
133
|
-
static
|
|
134
|
-
static
|
|
137
|
+
hash(): string;
|
|
138
|
+
static equals<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
139
|
+
static notEquals<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
140
|
+
static contains<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
141
|
+
static notContains<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
142
|
+
static notIn<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
143
|
+
static in<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
144
|
+
static notEqual<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
145
|
+
static lessThan<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
146
|
+
static lessOrEqual<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
147
|
+
static moreThan<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
148
|
+
static moreOrEqual<Resources extends object = object, Environment extends object = object>(subject: string, resource: AbilityRuleConfig['resource']): AbilityRule<Resources, Environment>;
|
|
135
149
|
}
|
|
136
150
|
|
|
137
151
|
type AbilityRuleSetConfig = {
|
|
138
152
|
readonly id?: string | null;
|
|
139
153
|
readonly name?: string | null;
|
|
140
|
-
readonly
|
|
154
|
+
readonly description?: string | null;
|
|
155
|
+
readonly compareMethod: AbilityCompareType;
|
|
141
156
|
readonly rules: readonly AbilityRuleConfig[];
|
|
157
|
+
readonly disabled?: boolean;
|
|
142
158
|
};
|
|
143
159
|
type AbilityRuleSetConstructorProps = {
|
|
144
160
|
readonly id?: string | null;
|
|
145
161
|
readonly name?: string | null;
|
|
146
|
-
readonly
|
|
162
|
+
readonly description?: string | null;
|
|
163
|
+
readonly compareMethod: AbilityCompareType;
|
|
164
|
+
readonly isExcept?: boolean;
|
|
165
|
+
readonly disabled?: boolean;
|
|
147
166
|
};
|
|
148
|
-
declare class AbilityRuleSet<
|
|
149
|
-
state:
|
|
167
|
+
declare class AbilityRuleSet<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>> {
|
|
168
|
+
state: AbilityMatchType;
|
|
150
169
|
/**
|
|
151
170
|
* List of rules
|
|
152
171
|
*/
|
|
153
|
-
rules: AbilityRule<
|
|
172
|
+
rules: AbilityRule<R, E>[];
|
|
154
173
|
/**
|
|
155
174
|
* Rules compare method.\
|
|
156
175
|
* For the «and» method the rule will be permitted if all\
|
|
157
176
|
* rules will be returns «permit» status and for the «or» - if\
|
|
158
177
|
* one of the rules returns as «permit»
|
|
159
178
|
*/
|
|
160
|
-
compareMethod:
|
|
179
|
+
compareMethod: AbilityCompareType;
|
|
161
180
|
/**
|
|
162
181
|
* Group name
|
|
163
182
|
*/
|
|
164
183
|
name: string;
|
|
184
|
+
description?: string | null;
|
|
165
185
|
/**
|
|
166
186
|
* Group ID
|
|
167
187
|
*/
|
|
168
188
|
id: string;
|
|
189
|
+
readonly isExcept?: boolean;
|
|
190
|
+
disabled: boolean;
|
|
169
191
|
constructor(params: AbilityRuleSetConstructorProps);
|
|
170
|
-
addRule(rule: AbilityRule<
|
|
171
|
-
addRules(rules: AbilityRule<
|
|
172
|
-
check(resources:
|
|
192
|
+
addRule(rule: AbilityRule<R, E>): this;
|
|
193
|
+
addRules(rules: AbilityRule<R, E>[]): this;
|
|
194
|
+
check(resources: R | null, environment?: E): AbilityMatchType;
|
|
173
195
|
toString(): string;
|
|
174
196
|
copyWith(props: Partial<{
|
|
175
197
|
id: string | null;
|
|
176
198
|
name: string | null;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
199
|
+
description: string | null;
|
|
200
|
+
compareMethod: AbilityCompareType;
|
|
201
|
+
rules: AbilityRule<R, E>[];
|
|
202
|
+
}>): AbilityRuleSet<R, E>;
|
|
203
|
+
hash(): string;
|
|
204
|
+
static and(rules: AbilityRule[]): AbilityRuleSet<Record<string, unknown>, Record<string, unknown>>;
|
|
205
|
+
static or(rules: AbilityRule[]): AbilityRuleSet<Record<string, unknown>, Record<string, unknown>>;
|
|
182
206
|
}
|
|
183
207
|
|
|
184
|
-
type
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
208
|
+
type AbilityPolicyEffectCode = 'deny' | 'permit';
|
|
209
|
+
type AbilityPolicyEffectType = AbilityPolicyEffectCode & {
|
|
210
|
+
__brand: 'AbilityPolicyEffect';
|
|
211
|
+
};
|
|
212
|
+
declare const AbilityPolicyEffect: {
|
|
213
|
+
readonly deny: AbilityPolicyEffectType;
|
|
214
|
+
readonly permit: AbilityPolicyEffectType;
|
|
215
|
+
};
|
|
189
216
|
|
|
190
217
|
type AbilityExplainConfig = {
|
|
191
218
|
readonly type: AbilityExplainType;
|
|
192
219
|
readonly name: string;
|
|
193
|
-
readonly match:
|
|
220
|
+
readonly match: AbilityMatchType;
|
|
194
221
|
};
|
|
195
222
|
declare class AbilityExplain {
|
|
196
223
|
readonly type: AbilityExplainType;
|
|
197
224
|
readonly children: AbilityExplain[];
|
|
198
225
|
readonly name: string;
|
|
199
|
-
readonly match:
|
|
226
|
+
readonly match: AbilityMatchType;
|
|
200
227
|
constructor(config: AbilityExplainConfig, children?: AbilityExplain[]);
|
|
201
228
|
toString(indent?: number): string;
|
|
202
229
|
}
|
|
@@ -211,77 +238,96 @@ declare class AbilityExplainPolicy extends AbilityExplain {
|
|
|
211
238
|
}
|
|
212
239
|
type AbilityExplainType = 'policy' | 'rule' | 'ruleSet';
|
|
213
240
|
|
|
214
|
-
type AbilityPolicyConfig = {
|
|
241
|
+
type AbilityPolicyConfig<TTag extends string = string> = {
|
|
215
242
|
readonly permission: string;
|
|
216
|
-
readonly effect:
|
|
217
|
-
readonly compareMethod:
|
|
243
|
+
readonly effect: AbilityPolicyEffectType;
|
|
244
|
+
readonly compareMethod: AbilityCompareType;
|
|
218
245
|
readonly ruleSet: readonly AbilityRuleSetConfig[];
|
|
219
246
|
readonly id: string;
|
|
220
247
|
readonly name: string;
|
|
248
|
+
readonly description?: string | null;
|
|
249
|
+
readonly priority: number;
|
|
250
|
+
readonly disabled?: boolean;
|
|
251
|
+
readonly tags?: readonly TTag[];
|
|
221
252
|
};
|
|
222
|
-
type AbilityPolicyConstructorProps = {
|
|
223
|
-
id: string;
|
|
224
|
-
name: string;
|
|
253
|
+
type AbilityPolicyConstructorProps<TTag extends string = string> = {
|
|
254
|
+
id: string | null;
|
|
255
|
+
name: string | null;
|
|
256
|
+
description?: string | null;
|
|
225
257
|
permission: string;
|
|
226
|
-
effect:
|
|
227
|
-
compareMethod?:
|
|
258
|
+
effect: AbilityPolicyEffectType;
|
|
259
|
+
compareMethod?: AbilityCompareType;
|
|
260
|
+
priority?: number | null;
|
|
261
|
+
disabled?: boolean;
|
|
262
|
+
tags?: readonly TTag[];
|
|
228
263
|
};
|
|
229
|
-
declare class AbilityPolicy<
|
|
230
|
-
matchState:
|
|
264
|
+
declare class AbilityPolicy<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>, TTag extends string = string> {
|
|
265
|
+
matchState: AbilityMatchType;
|
|
231
266
|
/**
|
|
232
267
|
* List of rules
|
|
233
268
|
*/
|
|
234
|
-
ruleSet: AbilityRuleSet<
|
|
269
|
+
ruleSet: AbilityRuleSet<R, E>[];
|
|
235
270
|
/**
|
|
236
271
|
* Policy effect
|
|
237
272
|
*/
|
|
238
|
-
effect:
|
|
273
|
+
effect: AbilityPolicyEffectType;
|
|
239
274
|
/**
|
|
240
275
|
* Rules compare method.\
|
|
241
276
|
* For the «and» method the rule will be permitted if all\
|
|
242
277
|
* rules will be returns «permit» status and for the «or» - if\
|
|
243
278
|
* one of the rules returns as «permit»
|
|
244
279
|
*/
|
|
245
|
-
compareMethod:
|
|
246
|
-
/**
|
|
247
|
-
* Policy name
|
|
248
|
-
*/
|
|
249
|
-
name: string;
|
|
280
|
+
compareMethod: AbilityCompareType;
|
|
250
281
|
/**
|
|
251
282
|
* Policy ID
|
|
252
283
|
*/
|
|
253
284
|
id: string;
|
|
285
|
+
/**
|
|
286
|
+
* Policy name
|
|
287
|
+
*/
|
|
288
|
+
name: string;
|
|
289
|
+
description?: string | null;
|
|
254
290
|
/**
|
|
255
291
|
* Running the `enforce` or `resolve` method
|
|
256
292
|
* will select only those from all passed policies that fall under the specified permission key.
|
|
257
293
|
*/
|
|
258
294
|
permission: string;
|
|
295
|
+
priority: number;
|
|
296
|
+
disabled: boolean;
|
|
297
|
+
tags: readonly TTag[];
|
|
259
298
|
constructor(params: AbilityPolicyConstructorProps);
|
|
260
299
|
/**
|
|
261
300
|
* Add rule set to the policy
|
|
262
301
|
* @param ruleSet - The rule set to add
|
|
263
302
|
*/
|
|
264
|
-
addRuleSet(ruleSet: AbilityRuleSet<
|
|
303
|
+
addRuleSet(ruleSet: AbilityRuleSet<R, E>): this;
|
|
265
304
|
/**
|
|
266
305
|
* Add rule set to the policy
|
|
267
306
|
* @param ruleSets - The array of rule set to add
|
|
268
307
|
*/
|
|
269
|
-
addRuleSets(ruleSets: readonly AbilityRuleSet<
|
|
308
|
+
addRuleSets(ruleSets: readonly AbilityRuleSet<R, E>[]): this;
|
|
309
|
+
/**
|
|
310
|
+
* Extract all rules of all ruleSets of this policy
|
|
311
|
+
*/
|
|
312
|
+
extractRules(): readonly AbilityRule[];
|
|
270
313
|
/**
|
|
271
314
|
* Check if the policy is matched
|
|
272
315
|
* @param resource - The resource to check
|
|
273
316
|
* @param environment - The user environment object
|
|
274
317
|
*/
|
|
275
|
-
check(resource:
|
|
318
|
+
check(resource: R, environment?: E): AbilityMatchType;
|
|
276
319
|
explain(): AbilityExplain;
|
|
277
320
|
copyWith(props: Partial<{
|
|
278
321
|
id: string;
|
|
279
322
|
name: string;
|
|
323
|
+
description?: string | null;
|
|
324
|
+
priority: number;
|
|
280
325
|
permission: string;
|
|
281
|
-
effect:
|
|
282
|
-
compareMethod:
|
|
283
|
-
ruleSet: AbilityRuleSet<
|
|
284
|
-
}>): AbilityPolicy<
|
|
326
|
+
effect: AbilityPolicyEffectType;
|
|
327
|
+
compareMethod: AbilityCompareType;
|
|
328
|
+
ruleSet: AbilityRuleSet<R, E>[];
|
|
329
|
+
}>): AbilityPolicy<R, E>;
|
|
330
|
+
hash(): string;
|
|
285
331
|
}
|
|
286
332
|
|
|
287
333
|
type Primitive = string | number | boolean | null | undefined;
|
|
@@ -289,15 +335,18 @@ type NestedDict<T = Primitive> = {
|
|
|
289
335
|
[key: string]: NestedDict<T> | T;
|
|
290
336
|
};
|
|
291
337
|
type ResourceObject = Record<string, unknown>;
|
|
338
|
+
type EnvironmentObject = Record<string, unknown>;
|
|
292
339
|
type ResourcesMap = Record<string, ResourceObject>;
|
|
293
340
|
declare class AbilityTypeGenerator {
|
|
294
341
|
readonly policies: readonly AbilityPolicy[];
|
|
342
|
+
private readonly policyEntries;
|
|
295
343
|
constructor(policies: readonly AbilityPolicy[]);
|
|
296
344
|
/**
|
|
297
345
|
* Generates TypeScript type definitions based on the provided policies.
|
|
298
346
|
* @returns A generated type definitions.
|
|
299
347
|
*/
|
|
300
348
|
generateTypeDefs(): string;
|
|
349
|
+
private isPath;
|
|
301
350
|
/**
|
|
302
351
|
* Determines TypeScript type based on the rule
|
|
303
352
|
* @param rule - The rule to analyze
|
|
@@ -310,6 +359,7 @@ declare class AbilityTypeGenerator {
|
|
|
310
359
|
* @returns TypeScript array type as string
|
|
311
360
|
*/
|
|
312
361
|
private getArrayType;
|
|
362
|
+
private getInArrayType;
|
|
313
363
|
/**
|
|
314
364
|
* Gets primitive TypeScript type for a value
|
|
315
365
|
* @param value - The value to analyze
|
|
@@ -326,6 +376,8 @@ declare class AbilityTypeGenerator {
|
|
|
326
376
|
/**
|
|
327
377
|
* Formats type structure into a string
|
|
328
378
|
* @param structure - Nested type structure
|
|
379
|
+
* @param environment
|
|
380
|
+
* @param allTags
|
|
329
381
|
* @returns Formatted TypeScript type definition string
|
|
330
382
|
*/
|
|
331
383
|
private formatTypeDefinitions;
|
|
@@ -338,19 +390,24 @@ declare class AbilityTypeGenerator {
|
|
|
338
390
|
private formatNestedObject;
|
|
339
391
|
}
|
|
340
392
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
393
|
+
declare abstract class AbilityStrategy<Resource extends ResourceObject = Record<string, unknown>, Environment extends EnvironmentObject = Record<string, unknown>> {
|
|
394
|
+
readonly policies: readonly AbilityPolicy<Resource, Environment>[];
|
|
395
|
+
private readonly matched;
|
|
396
|
+
constructor(policies: readonly AbilityPolicy<Resource, Environment>[]);
|
|
397
|
+
abstract evaluate(): AbilityPolicyEffectType;
|
|
398
|
+
matchedPolicies(): readonly AbilityPolicy<Resource, Environment, string>[];
|
|
399
|
+
protected firstMatched(): AbilityPolicy<Resource, Environment> | null;
|
|
400
|
+
protected lastMatched(): AbilityPolicy<Resource, Environment> | null;
|
|
401
|
+
protected hasPermit(): boolean;
|
|
402
|
+
protected hasDeny(): boolean;
|
|
403
|
+
isAllowed(): boolean;
|
|
404
|
+
isDenied(): boolean;
|
|
346
405
|
}
|
|
347
406
|
|
|
348
|
-
declare class AbilityResult<
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
readonly policies: readonly AbilityPolicy<Resource>[];
|
|
353
|
-
constructor(policies: readonly AbilityPolicy<Resource>[]);
|
|
407
|
+
declare class AbilityResult<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>> {
|
|
408
|
+
protected readonly effect: AbilityPolicyEffectType;
|
|
409
|
+
protected readonly strategy: AbilityStrategy<R, E>;
|
|
410
|
+
constructor(effect: AbilityPolicyEffectType, strategy: AbilityStrategy<R, E>);
|
|
354
411
|
/**
|
|
355
412
|
* Returns a list of explanations for each policy involved in the ability evaluation.
|
|
356
413
|
* Each item describes how a specific policy contributed to the final permission result.
|
|
@@ -358,19 +415,26 @@ declare class AbilityResult<Resource extends ResourceObject = Record<string, unk
|
|
|
358
415
|
* Useful for debugging, logging, or building UI tools that visualize permission logic.
|
|
359
416
|
*/
|
|
360
417
|
explain(): readonly AbilityExplain[];
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
isAllowed(): boolean;
|
|
364
|
-
isDenied(): boolean;
|
|
418
|
+
isAllowed: () => boolean;
|
|
419
|
+
isDenied: () => boolean;
|
|
365
420
|
}
|
|
366
421
|
|
|
367
|
-
|
|
368
|
-
|
|
422
|
+
interface AbilityResolverOptions<TTags extends string> {
|
|
423
|
+
tags?: readonly TTags[];
|
|
424
|
+
}
|
|
425
|
+
type ExtractResources<P> = P extends AbilityPolicy<infer R, any, any> ? R : never;
|
|
426
|
+
type ExtractEnvironment<P> = P extends AbilityPolicy<any, infer E, any> ? E : never;
|
|
427
|
+
type ExtractPermission<R> = R extends AbilityResolver<infer P, any, any> ? keyof ExtractResources<P> & string : never;
|
|
428
|
+
type ExtractResourceByPermission<P, Perm extends string> = P extends AbilityPolicy<infer R, any, any> ? (Perm extends keyof R ? R[Perm] : never) : never;
|
|
429
|
+
type ExtractEnvironmentByPermission<P, Perm extends string> = P extends AbilityPolicy<any, infer E, any> ? (Perm extends keyof E ? E[Perm] : never) : never;
|
|
430
|
+
declare class AbilityResolver<P extends AbilityPolicy<any, any, any>, S extends AbilityStrategy<P extends AbilityPolicy<infer R, infer E, any> ? R : never, P extends AbilityPolicy<any, infer E, any> ? E : never>, TTags extends string = P extends AbilityPolicy<any, any, infer T> ? T : never> {
|
|
431
|
+
private readonly StrategyClass;
|
|
432
|
+
private readonly policyEntries;
|
|
369
433
|
constructor(
|
|
370
434
|
/**
|
|
371
435
|
* `Important!` The incorrect Resources type was intentionally passed to AbilityPolicy so that TypeScript could suggest the name of the permission and the structure of its resource in the parse method.
|
|
372
436
|
*/
|
|
373
|
-
policyOrListOfPolicies: readonly
|
|
437
|
+
policyOrListOfPolicies: readonly P[] | P, strategy: new (policies: readonly P[]) => S, options?: AbilityResolverOptions<TTags>);
|
|
374
438
|
/**
|
|
375
439
|
* Resolve policy for the resource and permission key
|
|
376
440
|
*
|
|
@@ -378,14 +442,19 @@ declare class AbilityResolver<Resources extends ResourcesMap, Environment = unkn
|
|
|
378
442
|
* @param resource - Resource
|
|
379
443
|
* @param environment
|
|
380
444
|
*/
|
|
381
|
-
resolve<Permission extends keyof
|
|
382
|
-
enforce<Permission extends keyof
|
|
445
|
+
resolve<Permission extends keyof ExtractResources<P> & string>(permission: Permission, resource: ExtractResourceByPermission<P, Permission>, environment?: ExtractEnvironmentByPermission<P, Permission>): AbilityResult<ExtractResourceByPermission<P, Permission>, ExtractEnvironment<P>>;
|
|
446
|
+
enforce<Permission extends keyof ExtractResources<P> & string>(permission: Permission, resource: ExtractResourceByPermission<P, Permission>, environment?: ExtractEnvironmentByPermission<P, Permission>): void | never;
|
|
383
447
|
/**
|
|
448
|
+
* @deprecated - will be removed
|
|
449
|
+
*
|
|
384
450
|
* Check if the permission key is contained in another permission key
|
|
385
451
|
* @param permissionA - The first permission to check
|
|
386
452
|
* @param permissionB - The second permission to check
|
|
387
453
|
*/
|
|
388
454
|
static isInPermissionContain(permissionA: string, permissionB: string): boolean;
|
|
455
|
+
private toArray;
|
|
456
|
+
static normalizePermission(permission: string): string;
|
|
457
|
+
static matchPermissions(policySegments: string[], inputSegments: string[]): boolean;
|
|
389
458
|
}
|
|
390
459
|
|
|
391
460
|
declare class AbilityJSONParser {
|
|
@@ -394,13 +463,13 @@ declare class AbilityJSONParser {
|
|
|
394
463
|
* @param configs - Array of policy configurations
|
|
395
464
|
* @returns Array of AbilityPolicy instances
|
|
396
465
|
*/
|
|
397
|
-
static parse<
|
|
398
|
-
static parsePolicy<
|
|
399
|
-
static parseRule<
|
|
466
|
+
static parse<R extends ResourceObject, E extends EnvironmentObject, T extends string = string>(configs: readonly AbilityPolicyConfig[]): AbilityPolicy<R, E, T>[];
|
|
467
|
+
static parsePolicy<R extends ResourceObject, E extends EnvironmentObject, T extends string = string>(config: AbilityPolicyConfig): AbilityPolicy<R, E, T>;
|
|
468
|
+
static parseRule<R extends ResourceObject, E extends EnvironmentObject>(config: AbilityRuleConfig): AbilityRule<R, E>;
|
|
400
469
|
/**
|
|
401
470
|
* Parse the config JSON format to Group class instance
|
|
402
471
|
*/
|
|
403
|
-
static parseRuleSet<
|
|
472
|
+
static parseRuleSet<R extends ResourceObject, E extends EnvironmentObject>(config: AbilityRuleSetConfig): AbilityRuleSet<R, E>;
|
|
404
473
|
static ruleToJSON(rule: AbilityRule): AbilityRuleConfig;
|
|
405
474
|
static ruleSetToJSON(ruleSet: AbilityRuleSet): AbilityRuleSetConfig;
|
|
406
475
|
static policyToJSON(policy: AbilityPolicy): AbilityPolicyConfig;
|
|
@@ -423,17 +492,17 @@ declare class AbilityJSONParser {
|
|
|
423
492
|
* Operators can be simple (equals, contains, in) or
|
|
424
493
|
* composed (is null, is not null, greater than, less than or equal, etc.).
|
|
425
494
|
*/
|
|
426
|
-
declare class AbilityDSLParser<
|
|
427
|
-
private dsl;
|
|
428
|
-
private
|
|
429
|
-
private
|
|
430
|
-
private
|
|
495
|
+
declare class AbilityDSLParser<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>, T extends string = string> {
|
|
496
|
+
private readonly dsl;
|
|
497
|
+
private stream;
|
|
498
|
+
private annBuffer;
|
|
499
|
+
private aliasBuffer;
|
|
431
500
|
constructor(dsl: string);
|
|
432
501
|
/**
|
|
433
502
|
* Main entry point: tokenize the input and parse all policies.
|
|
434
503
|
* @returns Array of AbilityPolicy instances.
|
|
435
504
|
*/
|
|
436
|
-
parse(): readonly AbilityPolicy<
|
|
505
|
+
parse(): readonly AbilityPolicy<R, E, T>[];
|
|
437
506
|
/**
|
|
438
507
|
* Parses a single policy from the current token position.
|
|
439
508
|
*
|
|
@@ -449,6 +518,7 @@ declare class AbilityDSLParser<Resource extends ResourceObject = Record<string,
|
|
|
449
518
|
* Parses a single group, e.g. "all of:" or "any of:", and returns a RuleSet.
|
|
450
519
|
*/
|
|
451
520
|
private parseGroup;
|
|
521
|
+
private parseExceptGroup;
|
|
452
522
|
/**
|
|
453
523
|
* Parses a single rule: subject operator value
|
|
454
524
|
*/
|
|
@@ -476,76 +546,69 @@ declare class AbilityDSLParser<Resource extends ResourceObject = Record<string,
|
|
|
476
546
|
*/
|
|
477
547
|
private parseArray;
|
|
478
548
|
private consumeLeadingComments;
|
|
479
|
-
private
|
|
549
|
+
private consumeLeadingAliases;
|
|
550
|
+
private consumeLeadingAnnotations;
|
|
480
551
|
private takeAnnotations;
|
|
481
|
-
private syntaxError;
|
|
482
|
-
private suggest;
|
|
483
|
-
private levenshteinDistance;
|
|
484
|
-
private consumeOneOf;
|
|
485
|
-
private consume;
|
|
486
|
-
private check;
|
|
487
552
|
private isStartOfPolicy;
|
|
488
553
|
private isStartOfGroup;
|
|
489
|
-
private
|
|
490
|
-
private
|
|
491
|
-
private isAtEnd;
|
|
554
|
+
private isStartOfExcept;
|
|
555
|
+
private isStartOfAlias;
|
|
492
556
|
}
|
|
493
557
|
|
|
494
|
-
type
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
558
|
+
type TokenTypeCode = 'EFFECT' | 'IF' | 'PERMISSION' | 'IDENTIFIER' | 'COLON' | 'COMMA' | 'DOT' | 'LBRACKET' | 'RBRACKET' | 'ALL' | 'ANY' | 'OF' | 'EOF' | 'COMMENT' | 'EQ' | 'CONTAINS' | 'IN' | 'NOT_IN' | 'NOT_CONTAINS' | 'GT' | 'GTE' | 'LT' | 'LTE' | 'NULL' | 'EQ_NULL' | 'NOT_EQ_NULL' | 'NOT_EQ' | 'LEN_GT' | 'LEN_LT' | 'LEN_EQ' | 'ALWAYS' | 'NEVER' | 'EXCEPT' | 'ANNOTATION' | 'STRING' | 'NUMBER' | 'BOOLEAN' | 'SYMBOL' | 'KEYWORD' | 'ALIAS' | 'UNKNOWN';
|
|
559
|
+
type TokenType = TokenTypeCode & {
|
|
560
|
+
__brand: 'TokenType';
|
|
561
|
+
};
|
|
562
|
+
declare const TokenTypes: {
|
|
563
|
+
readonly EFFECT: TokenType;
|
|
564
|
+
readonly IF: TokenType;
|
|
565
|
+
readonly PERMISSION: TokenType;
|
|
566
|
+
readonly IDENTIFIER: TokenType;
|
|
567
|
+
readonly COLON: TokenType;
|
|
568
|
+
readonly COMMA: TokenType;
|
|
569
|
+
readonly DOT: TokenType;
|
|
570
|
+
readonly LBRACKET: TokenType;
|
|
571
|
+
readonly RBRACKET: TokenType;
|
|
572
|
+
readonly ALL: TokenType;
|
|
573
|
+
readonly ANY: TokenType;
|
|
574
|
+
readonly OF: TokenType;
|
|
575
|
+
readonly EOF: TokenType;
|
|
576
|
+
readonly COMMENT: TokenType;
|
|
577
|
+
readonly EQ: TokenType;
|
|
578
|
+
readonly CONTAINS: TokenType;
|
|
579
|
+
readonly IN: TokenType;
|
|
580
|
+
readonly NOT_IN: TokenType;
|
|
581
|
+
readonly NOT_CONTAINS: TokenType;
|
|
582
|
+
readonly GT: TokenType;
|
|
583
|
+
readonly GTE: TokenType;
|
|
584
|
+
readonly LT: TokenType;
|
|
585
|
+
readonly LTE: TokenType;
|
|
586
|
+
readonly NULL: TokenType;
|
|
587
|
+
readonly EQ_NULL: TokenType;
|
|
588
|
+
readonly NOT_EQ_NULL: TokenType;
|
|
589
|
+
readonly NOT_EQ: TokenType;
|
|
590
|
+
readonly LEN_GT: TokenType;
|
|
591
|
+
readonly LEN_LT: TokenType;
|
|
592
|
+
readonly LEN_EQ: TokenType;
|
|
593
|
+
readonly ALWAYS: TokenType;
|
|
594
|
+
readonly NEVER: TokenType;
|
|
595
|
+
readonly EXCEPT: TokenType;
|
|
596
|
+
readonly ANNOTATION: TokenType;
|
|
597
|
+
readonly STRING: TokenType;
|
|
598
|
+
readonly NUMBER: TokenType;
|
|
599
|
+
readonly BOOLEAN: TokenType;
|
|
600
|
+
readonly SYMBOL: TokenType;
|
|
601
|
+
readonly KEYWORD: TokenType;
|
|
602
|
+
readonly ALIAS: TokenType;
|
|
603
|
+
readonly UNKNOWN: TokenType;
|
|
604
|
+
};
|
|
605
|
+
declare class AbilityDSLToken {
|
|
606
|
+
readonly type: TokenType;
|
|
501
607
|
readonly value: string;
|
|
502
|
-
/** The line number in DSL */
|
|
503
608
|
readonly line: number;
|
|
504
|
-
/** The column in dsl */
|
|
505
609
|
readonly column: number;
|
|
506
|
-
constructor(type:
|
|
507
|
-
/**
|
|
508
|
-
* Returns a human-readable representation of the token, useful for debugging.
|
|
509
|
-
* Example output: "AbilityDSLToken([EFFECT] permit"
|
|
510
|
-
*/
|
|
610
|
+
constructor(type: TokenType, value: string, line: number, column: number);
|
|
511
611
|
toString(): string;
|
|
512
|
-
static readonly EFFECT: TokenType;
|
|
513
|
-
static readonly IF: TokenType;
|
|
514
|
-
static readonly PERMISSION: TokenType;
|
|
515
|
-
static readonly IDENTIFIER: TokenType;
|
|
516
|
-
static readonly COLON: TokenType;
|
|
517
|
-
static readonly COMMA: TokenType;
|
|
518
|
-
static readonly DOT: TokenType;
|
|
519
|
-
static readonly LBRACKET: TokenType;
|
|
520
|
-
static readonly RBRACKET: TokenType;
|
|
521
|
-
static readonly ALL: TokenType;
|
|
522
|
-
static readonly ANY: TokenType;
|
|
523
|
-
static readonly OF: TokenType;
|
|
524
|
-
static readonly EOF: TokenType;
|
|
525
|
-
static readonly COMMENT: TokenType;
|
|
526
|
-
static readonly EQ: TokenType;
|
|
527
|
-
static readonly CONTAINS: TokenType;
|
|
528
|
-
static readonly IN: TokenType;
|
|
529
|
-
static readonly NOT_IN: TokenType;
|
|
530
|
-
static readonly NOT_CONTAINS: TokenType;
|
|
531
|
-
static readonly GT: TokenType;
|
|
532
|
-
static readonly GTE: TokenType;
|
|
533
|
-
static readonly LT: TokenType;
|
|
534
|
-
static readonly LTE: TokenType;
|
|
535
|
-
static readonly NULL: TokenType;
|
|
536
|
-
static readonly EQ_NULL: TokenType;
|
|
537
|
-
static readonly NOT_EQ_NULL: TokenType;
|
|
538
|
-
static readonly LEN_GT: TokenType;
|
|
539
|
-
static readonly LEN_LT: TokenType;
|
|
540
|
-
static readonly LEN_EQ: TokenType;
|
|
541
|
-
static readonly NOT_EQ: TokenType;
|
|
542
|
-
static readonly ALWAYS: TokenType;
|
|
543
|
-
static readonly NEVER: TokenType;
|
|
544
|
-
static readonly STRING: TokenType;
|
|
545
|
-
static readonly NUMBER: TokenType;
|
|
546
|
-
static readonly BOOLEAN: TokenType;
|
|
547
|
-
static readonly SYMBOL: TokenType;
|
|
548
|
-
static readonly KEYWORD: TokenType;
|
|
549
612
|
}
|
|
550
613
|
|
|
551
614
|
declare class AbilityDSLLexer {
|
|
@@ -558,6 +621,7 @@ declare class AbilityDSLLexer {
|
|
|
558
621
|
constructor(input: string);
|
|
559
622
|
tokenize(): AbilityDSLToken[];
|
|
560
623
|
private readComment;
|
|
624
|
+
private readAnnotation;
|
|
561
625
|
private readString;
|
|
562
626
|
private readNumber;
|
|
563
627
|
private readSymbol;
|
|
@@ -572,5 +636,175 @@ declare class AbilityDSLLexer {
|
|
|
572
636
|
private isAtEnd;
|
|
573
637
|
}
|
|
574
638
|
|
|
575
|
-
|
|
576
|
-
|
|
639
|
+
declare function ability<R extends ResourceObject = Record<string, unknown>, E extends EnvironmentObject = Record<string, unknown>, T extends string = string>(strings: TemplateStringsArray, ...expr: any[]): readonly AbilityPolicy<R, E, T>[];
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* AllMustPermitStrategy
|
|
643
|
+
*
|
|
644
|
+
* This strategy requires *every applicable policy* to return "permit".
|
|
645
|
+
* If at least one policy returns "deny" or "not applicable", the final result is "deny".
|
|
646
|
+
*
|
|
647
|
+
* Use this strategy when:
|
|
648
|
+
* - You want strict, conservative access control.
|
|
649
|
+
* - All rules must explicitly allow the action.
|
|
650
|
+
*
|
|
651
|
+
* Example:
|
|
652
|
+
* Policies:
|
|
653
|
+
* P1 → permit
|
|
654
|
+
* P2 → permit
|
|
655
|
+
* P3 → deny
|
|
656
|
+
* Result: deny (because not all policies permitted)
|
|
657
|
+
*/
|
|
658
|
+
declare class AllMustPermitStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
659
|
+
evaluate(): AbilityPolicyEffectType;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* AnyPermitStrategy
|
|
664
|
+
*
|
|
665
|
+
* This strategy returns "permit" as soon as *any* applicable policy permits the action.
|
|
666
|
+
* If no policy permits, the result is "deny".
|
|
667
|
+
*
|
|
668
|
+
* Use this strategy when:
|
|
669
|
+
* - You want optimistic access control.
|
|
670
|
+
* - A single positive rule should be enough to grant access.
|
|
671
|
+
*
|
|
672
|
+
* Example:
|
|
673
|
+
* Policies:
|
|
674
|
+
* P1 → deny
|
|
675
|
+
* P2 → permit
|
|
676
|
+
* P3 → deny
|
|
677
|
+
* Result: permit (because at least one policy permitted)
|
|
678
|
+
*/
|
|
679
|
+
declare class AnyPermitStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
680
|
+
evaluate(): AbilityPolicyEffectType;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* DenyOverridesStrategy
|
|
685
|
+
*
|
|
686
|
+
* This strategy gives absolute priority to "deny".
|
|
687
|
+
* If any applicable policy returns "deny", the final result is "deny".
|
|
688
|
+
* Otherwise, if at least one policy permits, the result is "permit".
|
|
689
|
+
*
|
|
690
|
+
* Use this strategy when:
|
|
691
|
+
* - Security is critical.
|
|
692
|
+
* - A single denial must block access.
|
|
693
|
+
*
|
|
694
|
+
* Example:
|
|
695
|
+
* Policies:
|
|
696
|
+
* P1 → permit
|
|
697
|
+
* P2 → deny
|
|
698
|
+
* P3 → permit
|
|
699
|
+
* Result: deny (because deny overrides everything)
|
|
700
|
+
*/
|
|
701
|
+
declare class DenyOverridesStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
702
|
+
evaluate(): AbilityPolicyEffectType;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* FirstMatchStrategy
|
|
707
|
+
*
|
|
708
|
+
* This strategy evaluates policies in order and returns the result of the *first applicable* policy.
|
|
709
|
+
* Remaining policies are ignored.
|
|
710
|
+
*
|
|
711
|
+
* Use this strategy when:
|
|
712
|
+
* - Policy order matters.
|
|
713
|
+
* - You want predictable, sequential rule evaluation.
|
|
714
|
+
*
|
|
715
|
+
* Example:
|
|
716
|
+
* Policies:
|
|
717
|
+
* P1 → not applicable
|
|
718
|
+
* P2 → permit
|
|
719
|
+
* P3 → deny
|
|
720
|
+
* Result: permit (P2 is the first applicable)
|
|
721
|
+
*/
|
|
722
|
+
declare class FirstMatchStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
723
|
+
evaluate(): AbilityPolicyEffectType;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* OnlyOneApplicableStrategy
|
|
728
|
+
*
|
|
729
|
+
* This strategy requires that *exactly one* policy is applicable.
|
|
730
|
+
* If zero or more than one policy applies, the result is "deny".
|
|
731
|
+
*
|
|
732
|
+
* Use this strategy when:
|
|
733
|
+
* - Policies must be mutually exclusive.
|
|
734
|
+
* - You want to detect ambiguous or conflicting rules.
|
|
735
|
+
*
|
|
736
|
+
* Example:
|
|
737
|
+
* Policies:
|
|
738
|
+
* P1 → applicable
|
|
739
|
+
* P2 → applicable
|
|
740
|
+
* Result: deny (more than one applicable policy)
|
|
741
|
+
*/
|
|
742
|
+
declare class OnlyOneApplicableStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
743
|
+
evaluate(): AbilityPolicyEffectType;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* PermitOverridesStrategy
|
|
748
|
+
*
|
|
749
|
+
* This strategy gives priority to "permit".
|
|
750
|
+
* If any applicable policy permits, the final result is "permit".
|
|
751
|
+
* Deny is returned only if no policy permits.
|
|
752
|
+
*
|
|
753
|
+
* Use this strategy when:
|
|
754
|
+
* - You want permissive behavior.
|
|
755
|
+
* - A single positive rule should override denials.
|
|
756
|
+
*
|
|
757
|
+
* Example:
|
|
758
|
+
* Policies:
|
|
759
|
+
* P1 → deny
|
|
760
|
+
* P2 → permit
|
|
761
|
+
* P3 → deny
|
|
762
|
+
* Result: permit (permit overrides deny)
|
|
763
|
+
*/
|
|
764
|
+
declare class PermitOverridesStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
765
|
+
evaluate(): AbilityPolicyEffectType;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* SequentialLastMatchStrategy
|
|
770
|
+
*
|
|
771
|
+
* This strategy evaluates all applicable policies in order and returns the result of the *last* applicable one.
|
|
772
|
+
*
|
|
773
|
+
* Use this strategy when:
|
|
774
|
+
* - Later policies should override earlier ones.
|
|
775
|
+
* - You want a "last rule wins" behavior.
|
|
776
|
+
*
|
|
777
|
+
* Example:
|
|
778
|
+
* Policies:
|
|
779
|
+
* P1 → permit
|
|
780
|
+
* P2 → deny
|
|
781
|
+
* P3 → permit
|
|
782
|
+
* Result: permit (P3 is the last applicable)
|
|
783
|
+
*/
|
|
784
|
+
declare class SequentialLastMatchStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
785
|
+
evaluate(): AbilityPolicyEffectType;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* PriorityStrategy
|
|
790
|
+
*
|
|
791
|
+
* This strategy evaluates policies based on their numeric priority.
|
|
792
|
+
* The policy with the highest priority (lowest number or highest number depending on implementation)
|
|
793
|
+
* determines the final result.
|
|
794
|
+
*
|
|
795
|
+
* Use this strategy when:
|
|
796
|
+
* - Policies have explicit priority levels.
|
|
797
|
+
* - You want deterministic resolution based on ranking.
|
|
798
|
+
*
|
|
799
|
+
* Example:
|
|
800
|
+
* Policies:
|
|
801
|
+
* P1 (priority 10) → deny
|
|
802
|
+
* P2 (priority 1) → permit
|
|
803
|
+
* Result: permit (P2 has higher priority)
|
|
804
|
+
*/
|
|
805
|
+
declare class PriorityStrategy<R extends ResourceObject, E extends EnvironmentObject = Record<string, unknown>> extends AbilityStrategy<R, E> {
|
|
806
|
+
evaluate(): AbilityPolicyEffectType;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
export { AbilityCompare, AbilityCondition, AbilityDSLLexer, AbilityDSLParser, AbilityDSLToken, AbilityError, AbilityExplain, AbilityExplainPolicy, AbilityExplainRule, AbilityExplainRuleSet, AbilityJSONParser, AbilityMatch, AbilityParserError, AbilityPolicy, AbilityPolicyEffect, AbilityResolver, AbilityResult, AbilityRule, AbilityRuleSet, AbilityStrategy, AbilityTypeGenerator, AllMustPermitStrategy, AnyPermitStrategy, DenyOverridesStrategy, FirstMatchStrategy, OnlyOneApplicableStrategy, PermitOverridesStrategy, PriorityStrategy, SequentialLastMatchStrategy, TokenTypes, ability, fromLiteral, isConditionEqual, isConditionNotEqual, toLiteral };
|
|
810
|
+
export type { AbilityCompareType, AbilityConditionCode, AbilityConditionLiteral, AbilityConditionType, AbilityExplainConfig, AbilityExplainType, AbilityMatchType, AbilityPolicyConfig, AbilityPolicyConstructorProps, AbilityPolicyEffectType, AbilityResolverOptions, AbilityRuleConfig, AbilityRuleConstructorProps, AbilityRuleSetConfig, AbilityRuleSetConstructorProps, EnvironmentObject, ExtractEnvironment, ExtractEnvironmentByPermission, ExtractPermission, ExtractResourceByPermission, ExtractResources, NestedDict, Primitive, ResourceObject, ResourcesMap, TokenType, TokenTypeCode };
|