@careflair/common 1.0.38 → 1.0.40

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,32 @@
1
+ import { PureAbility } from "@casl/ability";
2
+ import { UserRole } from "../enums";
3
+ /**
4
+ * Actions that users can perform
5
+ */
6
+ export type Actions = "create" | "read" | "update" | "delete" | "apply" | "initiate" | "respond" | "submit" | "manage";
7
+ /**
8
+ * Subjects/resources that users act upon
9
+ */
10
+ export type Subjects = "Job" | "Chat" | "NDISScreening" | "WorkingWithChildren" | "Profile" | "all";
11
+ /**
12
+ * AppAbility type for type-safe permission checks
13
+ * Uses PureAbility (modern API) instead of deprecated Ability
14
+ */
15
+ export type AppAbility = PureAbility<[Actions, Subjects]>;
16
+ /**
17
+ * User interface for ability definition
18
+ * Only requires id and role - minimal interface for permission checks
19
+ */
20
+ export interface UserForAbility {
21
+ id: string;
22
+ role: UserRole;
23
+ }
24
+ /**
25
+ * Define abilities for a user based on their role
26
+ * This is the SINGLE SOURCE OF TRUTH for permissions
27
+ * Used by backend, frontend, and mobile app
28
+ *
29
+ * @param user - User object with id and role
30
+ * @returns AppAbility instance with user's permissions
31
+ */
32
+ export declare function defineAbilitiesFor(user: UserForAbility): AppAbility;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineAbilitiesFor = defineAbilitiesFor;
4
+ const ability_1 = require("@casl/ability");
5
+ const enums_1 = require("../enums");
6
+ /**
7
+ * Define abilities for a user based on their role
8
+ * This is the SINGLE SOURCE OF TRUTH for permissions
9
+ * Used by backend, frontend, and mobile app
10
+ *
11
+ * @param user - User object with id and role
12
+ * @returns AppAbility instance with user's permissions
13
+ */
14
+ function defineAbilitiesFor(user) {
15
+ const { can, cannot, build } = new ability_1.AbilityBuilder(ability_1.PureAbility);
16
+ // ============================================
17
+ // HIRERS: PARTICIPANT and SUPPORT_PERSON
18
+ // ============================================
19
+ if (user.role === enums_1.UserRole.PARTICIPANT ||
20
+ user.role === enums_1.UserRole.SUPPORT_PERSON) {
21
+ // Jobs
22
+ can("create", "Job");
23
+ can("read", "Job");
24
+ can("update", "Job", { postedBy: user.id }); // Only own jobs
25
+ can("delete", "Job", { postedBy: user.id }); // Only own jobs
26
+ // Chat
27
+ can("initiate", "Chat"); // Can start conversations
28
+ can("read", "Chat");
29
+ // Profile
30
+ can("read", "Profile", { user: user.id });
31
+ }
32
+ // ============================================
33
+ // WORKERS: SUPPORT_WORKER
34
+ // ============================================
35
+ if (user.role === enums_1.UserRole.SUPPORT_WORKER) {
36
+ // Jobs
37
+ can("read", "Job");
38
+ can("apply", "Job");
39
+ // Chat
40
+ can("respond", "Chat"); // Can respond to messages
41
+ cannot("initiate", "Chat"); // Cannot start conversations
42
+ // Verifications
43
+ can("submit", "NDISScreening");
44
+ can("submit", "WorkingWithChildren");
45
+ // Profile
46
+ can("read", "Profile", { user: user.id });
47
+ can("update", "Profile", { user: user.id });
48
+ }
49
+ // ============================================
50
+ // WORKERS: PROVIDER
51
+ // Same permissions as SUPPORT_WORKER for now
52
+ // ============================================
53
+ if (user.role === enums_1.UserRole.PROVIDER) {
54
+ // Jobs
55
+ can("read", "Job");
56
+ can("apply", "Job");
57
+ // Chat
58
+ can("respond", "Chat"); // Can respond to messages
59
+ cannot("initiate", "Chat"); // Cannot start conversations
60
+ // Verifications
61
+ can("submit", "NDISScreening");
62
+ can("submit", "WorkingWithChildren");
63
+ // Profile
64
+ can("read", "Profile", { user: user.id });
65
+ can("update", "Profile", { user: user.id });
66
+ }
67
+ return build();
68
+ }
package/dist/index.d.ts CHANGED
@@ -4,5 +4,6 @@ export { WorkHistoryInputValidation, WorkHistorySchema, } from "./schemas/workHi
4
4
  export { AvailabilitiesSchemaZod, AvailabilityZodInput, } from "./schemas/availabilitySchemaValidation";
5
5
  export { HourlyRateInputZod, HourlyRateInputZodType, } from "./schemas/hourlyRateSchemaValidation";
6
6
  export { ServicesSchema, validateServices, } from "./schemas/businessServicesValidation";
7
- export { VideoProvider, VideoValidationResult, detectVideoProvider, extractYouTubeVideoId, isValidCommunityVideoUrl, isValidYouTubeOrVimeoUrl, normalizeYouTubeUrl, validateVideoLink, } from "./utils/videoValidation";
7
+ export { detectVideoProvider, extractYouTubeVideoId, isValidCommunityVideoUrl, isValidYouTubeOrVimeoUrl, normalizeYouTubeUrl, validateVideoLink, VideoProvider, VideoValidationResult, } from "./utils/videoValidation";
8
8
  export { ApplicationFormValues, applicationSchema, isValidVideoUrl, } from "./schemas/applicationSchema";
9
+ export { defineAbilitiesFor, type Actions, type AppAbility, type Subjects, type UserForAbility, } from "./abilities";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidVideoUrl = exports.applicationSchema = exports.validateVideoLink = exports.normalizeYouTubeUrl = exports.isValidYouTubeOrVimeoUrl = exports.isValidCommunityVideoUrl = exports.extractYouTubeVideoId = exports.detectVideoProvider = exports.validateServices = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
3
+ exports.defineAbilitiesFor = exports.isValidVideoUrl = exports.applicationSchema = exports.validateVideoLink = exports.normalizeYouTubeUrl = exports.isValidYouTubeOrVimeoUrl = exports.isValidCommunityVideoUrl = exports.extractYouTubeVideoId = exports.detectVideoProvider = exports.validateServices = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
4
4
  var userValiationSchema_1 = require("./schemas/userValiationSchema");
5
5
  Object.defineProperty(exports, "UserRegistrationSchema", { enumerable: true, get: function () { return userValiationSchema_1.UserRegistrationSchema; } });
6
6
  var educationSchemas_1 = require("./schemas/educationSchemas");
@@ -24,3 +24,6 @@ Object.defineProperty(exports, "validateVideoLink", { enumerable: true, get: fun
24
24
  var applicationSchema_1 = require("./schemas/applicationSchema");
25
25
  Object.defineProperty(exports, "applicationSchema", { enumerable: true, get: function () { return applicationSchema_1.applicationSchema; } });
26
26
  Object.defineProperty(exports, "isValidVideoUrl", { enumerable: true, get: function () { return applicationSchema_1.isValidVideoUrl; } });
27
+ // CASL Abilities
28
+ var abilities_1 = require("./abilities");
29
+ Object.defineProperty(exports, "defineAbilitiesFor", { enumerable: true, get: function () { return abilities_1.defineAbilitiesFor; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@careflair/common",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
4
4
  "description": "Shared assets for CareFlair",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,6 +18,7 @@
18
18
  "author": "Farhan Hossain",
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
+ "@casl/ability": "^6.7.5",
21
22
  "date-fns": "^4.1.0",
22
23
  "libphonenumber-js": "^1.12.25"
23
24
  },
@@ -71,6 +72,10 @@
71
72
  "./interfaces/*": {
72
73
  "types": "./dist/interfaces/*.d.ts",
73
74
  "default": "./dist/interfaces/*.js"
75
+ },
76
+ "./abilities": {
77
+ "types": "./dist/abilities/index.d.ts",
78
+ "default": "./dist/abilities/index.js"
74
79
  }
75
80
  },
76
81
  "typesVersions": {