@careflair/common 1.0.41 → 1.0.43

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.
@@ -1,26 +1,37 @@
1
- import { PureAbility } from "@casl/ability";
1
+ import { PureAbility, MongoQuery } from "@casl/ability";
2
2
  import { UserRole } from "../enums";
3
3
  /**
4
4
  * Actions that users can perform
5
5
  */
6
6
  export type Actions = "create" | "read" | "update" | "delete" | "apply" | "initiate" | "respond" | "submit" | "manage";
7
+ /**
8
+ * Subject types with their fields for conditional checks
9
+ */
10
+ type Job = {
11
+ postedBy: string;
12
+ };
13
+ type Profile = {
14
+ user: string;
15
+ };
7
16
  /**
8
17
  * Subjects/resources that users act upon
18
+ * Includes both string literals (for rule definition) and object types (for instance checking)
9
19
  */
10
- export type Subjects = "Job" | "Chat" | "NDISScreening" | "WorkingWithChildren" | "Profile" | "all";
20
+ export type Subjects = "Job" | "Chat" | "NDISScreening" | "WorkingWithChildren" | "Profile" | "all" | Job | Profile;
11
21
  /**
12
22
  * AppAbility type for type-safe permission checks
13
- * Uses PureAbility (modern API) instead of deprecated Ability
23
+ * Uses PureAbility (modern API) + mongoQueryMatcher so we can define conditional rules
24
+ * (e.g. { postedBy: user.id }) without runtime errors.
14
25
  */
15
- export type AppAbility = PureAbility<[Actions, Subjects]>;
26
+ export type AppAbility = PureAbility<[Actions, Subjects], MongoQuery>;
16
27
  /**
17
- * User interface for ability definition
28
+ * User type for ability definition
18
29
  * Only requires id and role - minimal interface for permission checks
19
30
  */
20
- export interface UserForAbility {
31
+ export type UserForAbility = {
21
32
  id: string;
22
33
  role: UserRole;
23
- }
34
+ };
24
35
  /**
25
36
  * Define abilities for a user based on their role
26
37
  * This is the SINGLE SOURCE OF TRUTH for permissions
@@ -30,3 +41,4 @@ export interface UserForAbility {
30
41
  * @returns AppAbility instance with user's permissions
31
42
  */
32
43
  export declare function defineAbilitiesFor(user: UserForAbility): AppAbility;
44
+ export {};
@@ -64,5 +64,7 @@ function defineAbilitiesFor(user) {
64
64
  can("read", "Profile", { user: user.id });
65
65
  can("update", "Profile", { user: user.id });
66
66
  }
67
- return build();
67
+ return build({
68
+ conditionsMatcher: ability_1.mongoQueryMatcher,
69
+ });
68
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@careflair/common",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "Shared assets for CareFlair",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",