@anarchitects/auth-angular 0.4.0 → 0.5.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.
- package/README.md +88 -10
- package/data-access/README.md +10 -0
- package/feature/README.md +32 -3
- package/fesm2022/anarchitects-auth-angular-data-access.mjs +84 -65
- package/fesm2022/anarchitects-auth-angular-data-access.mjs.map +1 -1
- package/fesm2022/anarchitects-auth-angular-feature.mjs +61 -6
- package/fesm2022/anarchitects-auth-angular-feature.mjs.map +1 -1
- package/fesm2022/anarchitects-auth-angular-state.mjs +194 -47
- package/fesm2022/anarchitects-auth-angular-state.mjs.map +1 -1
- package/fesm2022/anarchitects-auth-angular-ui.mjs +338 -262
- package/fesm2022/anarchitects-auth-angular-ui.mjs.map +1 -1
- package/fesm2022/anarchitects-auth-angular-util.mjs +36 -3
- package/fesm2022/anarchitects-auth-angular-util.mjs.map +1 -1
- package/package.json +4 -4
- package/state/README.md +36 -1
- package/types/anarchitects-auth-angular-data-access.d.ts +19 -3
- package/types/anarchitects-auth-angular-feature.d.ts +4 -2
- package/types/anarchitects-auth-angular-state.d.ts +25 -8
- package/types/anarchitects-auth-angular-ui.d.ts +11 -11
- package/types/anarchitects-auth-angular-util.d.ts +11 -13
- package/util/README.md +28 -2
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import * as _casl_ability from '@casl/ability';
|
|
2
|
-
import { MongoAbility } from '@casl/ability';
|
|
3
1
|
import { Action, Subject, PolicyRule } from '@anarchitects/auth-ts/models';
|
|
2
|
+
import { MongoAbility } from '@casl/ability';
|
|
4
3
|
|
|
5
|
-
type AbilitySubject = Subject |
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
declare const createAppAbility: (rules: PolicyRule[]) => MongoAbility<_casl_ability.AbilityTuple, Record<string, unknown>>;
|
|
4
|
+
type AbilitySubject = Subject | object;
|
|
5
|
+
type AbilityResource = Record<string, unknown>;
|
|
6
|
+
type AppAbility = MongoAbility<[Action, AbilitySubject]>;
|
|
7
|
+
declare const createAppAbility: (rules: PolicyRule[]) => AppAbility;
|
|
8
|
+
declare const asAppAbilitySubject: <TResource extends AbilityResource>(subjectName: Subject, resource: TResource) => TResource & {
|
|
9
|
+
__caslSubjectType__: Subject;
|
|
10
|
+
};
|
|
11
|
+
declare const canAccessResource: <TResource extends AbilityResource>(ability: AppAbility | undefined, action: Action, subjectName: Subject, resource: TResource) => boolean;
|
|
12
|
+
declare const canAccessResourceField: <TResource extends AbilityResource>(ability: AppAbility | undefined, action: Action, subjectName: Subject, field: string, resource: TResource) => boolean;
|
|
15
13
|
|
|
16
|
-
export { createAppAbility };
|
|
14
|
+
export { asAppAbilitySubject, canAccessResource, canAccessResourceField, createAppAbility };
|
|
17
15
|
export type { AppAbility };
|
package/util/README.md
CHANGED
|
@@ -5,12 +5,28 @@ Utility layer for Angular auth. Re-exported via `@anarchitects/auth-angular/util
|
|
|
5
5
|
## Exports
|
|
6
6
|
|
|
7
7
|
- `createAppAbility(rules: PolicyRule[])`: wraps `createMongoAbility` and returns the typed `AppAbility` used throughout the auth domain.
|
|
8
|
+
- `canAccessResource(...)`: checks a concrete resource instance against the current ability.
|
|
9
|
+
- `canAccessResourceField(...)`: checks whether a specific field-level action is allowed for a concrete resource.
|
|
8
10
|
- `AppAbility`: CASL ability type configured for `Action`/`Subject` pairs defined in `@anarchitects/auth-ts/models`.
|
|
9
11
|
|
|
12
|
+
## When To Use These Helpers
|
|
13
|
+
|
|
14
|
+
Use this layer for concrete resource decisions, not coarse route metadata:
|
|
15
|
+
|
|
16
|
+
- `createAppAbility(rules)` builds the frontend CASL ability from validated RBAC rules
|
|
17
|
+
- `canAccessResource(...)` answers instance-level questions such as "may this user edit this post?"
|
|
18
|
+
- `canAccessResourceField(...)` answers field-sensitive UI questions such as inline title editing
|
|
19
|
+
|
|
20
|
+
If you only need coarse route-attempt semantics, use `policyGuard` and `RoutePolicy` instead of calling CASL directly here.
|
|
21
|
+
|
|
10
22
|
## Usage
|
|
11
23
|
|
|
12
24
|
```ts
|
|
13
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
canAccessResource,
|
|
27
|
+
canAccessResourceField,
|
|
28
|
+
createAppAbility,
|
|
29
|
+
} from '@anarchitects/auth-angular/util';
|
|
14
30
|
import type { PolicyRule } from '@anarchitects/auth-ts/models';
|
|
15
31
|
|
|
16
32
|
const rules: PolicyRule[] = [
|
|
@@ -23,6 +39,16 @@ const ability = createAppAbility(rules);
|
|
|
23
39
|
if (ability.can('manage', 'Project')) {
|
|
24
40
|
// guarded feature logic
|
|
25
41
|
}
|
|
42
|
+
|
|
43
|
+
const post = { id: 'post-1', authorId: 'user-1', title: 'Draft' };
|
|
44
|
+
|
|
45
|
+
if (canAccessResource(ability, 'update', 'Post', post)) {
|
|
46
|
+
// show edit button
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (canAccessResourceField(ability, 'update', 'Post', 'title', post)) {
|
|
50
|
+
// allow inline title editing
|
|
51
|
+
}
|
|
26
52
|
```
|
|
27
53
|
|
|
28
|
-
|
|
54
|
+
Use these helpers for frontend instance-level decisions such as edit buttons, row actions, and resolved edit routes. Coarse route gating still belongs to `policyGuard`, and the backend must still enforce the final instance-level decision.
|