@via-profit/ability 2.1.0 → 3.1.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/CONTRIBUTING.md +14 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1058 -319
  5. package/SECURITY.md +33 -0
  6. package/dist/cache/AbilityCacheAdapter.d.ts +8 -0
  7. package/dist/cache/AbilityInMemoryCache.d.ts +12 -0
  8. package/dist/core/AbilityCondition.d.ts +21 -0
  9. package/dist/core/AbilityExplain.d.ts +27 -0
  10. package/dist/core/AbilityParser.d.ts +61 -0
  11. package/dist/core/AbilityPolicy.d.ts +84 -0
  12. package/dist/core/AbilityResolver.d.ts +35 -0
  13. package/dist/core/AbilityResult.d.ts +27 -0
  14. package/dist/core/AbilityRule.d.ts +77 -0
  15. package/dist/{AbilityRuleSet.d.ts → core/AbilityRuleSet.d.ts} +14 -11
  16. package/dist/index.d.ts +19 -11
  17. package/dist/index.js +2097 -303
  18. package/dist/parsers/dsl/AbilityDSLLexer.d.ts +24 -0
  19. package/dist/parsers/dsl/AbilityDSLParser.d.ts +86 -0
  20. package/dist/parsers/dsl/AbilityDSLSyntaxError.d.ts +13 -0
  21. package/dist/parsers/dsl/AbilityDSLToken.d.ts +55 -0
  22. package/dist/parsers/json/AbilityJSONParser.d.ts +22 -0
  23. package/package.json +15 -4
  24. package/assets/ability-01.drawio.png +0 -0
  25. package/build/playground.js +0 -456
  26. package/build/playground.js.map +0 -1
  27. package/dist/AbilityCondition.d.ts +0 -16
  28. package/dist/AbilityParser.d.ts +0 -18
  29. package/dist/AbilityPolicy.d.ts +0 -65
  30. package/dist/AbilityResolver.d.ts +0 -30
  31. package/dist/AbilityRule.d.ts +0 -70
  32. /package/dist/{AbilityCode.d.ts → core/AbilityCode.d.ts} +0 -0
  33. /package/dist/{AbilityCompare.d.ts → core/AbilityCompare.d.ts} +0 -0
  34. /package/dist/{AbilityError.d.ts → core/AbilityError.d.ts} +0 -0
  35. /package/dist/{AbilityMatch.d.ts → core/AbilityMatch.d.ts} +0 -0
  36. /package/dist/{AbilityPolicyEffect.d.ts → core/AbilityPolicyEffect.d.ts} +0 -0
@@ -1,70 +0,0 @@
1
- import AbilityMatch from './AbilityMatch';
2
- import AbilityCondition, { AbilityConditionCodeType } from './AbilityCondition';
3
- export type AbilityRuleConfig = {
4
- readonly id: string;
5
- readonly name: string;
6
- /**
7
- * Subject key path like a 'user.name'
8
- */
9
- readonly subject: string;
10
- /**
11
- * Resource key path like a 'user.name' or value
12
- */
13
- readonly resource: string | number | boolean | (string | number)[];
14
- readonly condition: AbilityConditionCodeType;
15
- };
16
- export type AbilityRuleConstructorProps = Omit<AbilityRuleConfig, 'condition'> & {
17
- readonly condition: AbilityCondition;
18
- };
19
- /**
20
- * Represents a rule that defines a condition to be checked against a subject and resource.
21
- */
22
- export declare class AbilityRule<Resources extends object = object> {
23
- /**
24
- * Subject key path like a 'user.name'
25
- */
26
- subject: string;
27
- /**
28
- * Resource key path like a 'user.name' or value
29
- */
30
- resource: string | number | boolean | (string | number)[];
31
- condition: AbilityCondition;
32
- name: string;
33
- id: string;
34
- state: AbilityMatch;
35
- /**
36
- * Creates an instance of AbilityRule.
37
- * @param {string} options.id - The unique identifier of the rule.
38
- * @param {string} options.name - The name of the rule.
39
- * @param {AbilityCondition} options.condition - The condition to evaluate.
40
- * @param {string} options.subject - The subject of the rule.
41
- * @param {string} options.resource - The resource to compare against.
42
- * @param params
43
- */
44
- constructor(params: AbilityRuleConstructorProps);
45
- /**
46
- * Check if the rule is matched
47
- * @param resource - The resource to check
48
- */
49
- check(resource: Resources | null): AbilityMatch;
50
- /**
51
- * Extract values from the resourceData
52
- * @param resourceData - The resourceData to extract values from
53
- */
54
- extractValues(resourceData: Resources | null): [
55
- string | number | boolean | (string | number)[] | null | undefined,
56
- string | number | boolean | (string | number)[] | null | undefined
57
- ];
58
- /**
59
- * Get the value of the object by dot notation
60
- * @param resource - The object to get the value from
61
- * @param desc - The dot notation string
62
- */
63
- getDotNotationValue<T = unknown>(resource: unknown, desc: string): T | undefined;
64
- static parse<Resources extends object>(config: AbilityRuleConfig): AbilityRule<Resources>;
65
- /**
66
- * Export the rule to config object
67
- */
68
- export(): AbilityRuleConfig;
69
- }
70
- export default AbilityRule;