@careflair/common 1.0.43 → 1.0.45

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,29 +1,19 @@
1
- import { PureAbility, MongoQuery } from "@casl/ability";
1
+ import { PureAbility } 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
- };
16
7
  /**
17
8
  * Subjects/resources that users act upon
18
- * Includes both string literals (for rule definition) and object types (for instance checking)
19
9
  */
20
- export type Subjects = "Job" | "Chat" | "NDISScreening" | "WorkingWithChildren" | "Profile" | "all" | Job | Profile;
10
+ export type Subjects = "Job" | "Chat" | "NDISScreening" | "WorkingWithChildren" | "Profile" | "Onboarding" | "all";
21
11
  /**
22
12
  * AppAbility type for type-safe permission checks
23
13
  * Uses PureAbility (modern API) + mongoQueryMatcher so we can define conditional rules
24
14
  * (e.g. { postedBy: user.id }) without runtime errors.
25
15
  */
26
- export type AppAbility = PureAbility<[Actions, Subjects], MongoQuery>;
16
+ export type AppAbility = PureAbility<[Actions, Subjects], any>;
27
17
  /**
28
18
  * User type for ability definition
29
19
  * Only requires id and role - minimal interface for permission checks
@@ -41,4 +31,3 @@ export type UserForAbility = {
41
31
  * @returns AppAbility instance with user's permissions
42
32
  */
43
33
  export declare function defineAbilitiesFor(user: UserForAbility): AppAbility;
44
- export {};
@@ -45,6 +45,8 @@ function defineAbilitiesFor(user) {
45
45
  // Profile
46
46
  can("read", "Profile", { user: user.id });
47
47
  can("update", "Profile", { user: user.id });
48
+ // Onboarding (role-based check, no resource condition)
49
+ can("update", "Onboarding");
48
50
  }
49
51
  // ============================================
50
52
  // WORKERS: PROVIDER
@@ -63,6 +65,8 @@ function defineAbilitiesFor(user) {
63
65
  // Profile
64
66
  can("read", "Profile", { user: user.id });
65
67
  can("update", "Profile", { user: user.id });
68
+ // Onboarding (role-based check, no resource condition)
69
+ can("update", "Onboarding");
66
70
  }
67
71
  return build({
68
72
  conditionsMatcher: ability_1.mongoQueryMatcher,
@@ -7,3 +7,5 @@ export * from "./video";
7
7
  export * from "./onboarding";
8
8
  export * from "./html";
9
9
  export * from "./labels";
10
+ export * from "./user-role.utils";
11
+ export * from "./role-fields.utils";
@@ -32,3 +32,7 @@ __exportStar(require("./onboarding"), exports);
32
32
  __exportStar(require("./html"), exports);
33
33
  // Label helper utilities
34
34
  __exportStar(require("./labels"), exports);
35
+ // User role utilities
36
+ __exportStar(require("./user-role.utils"), exports);
37
+ // Role-based field restrictions utilities
38
+ __exportStar(require("./role-fields.utils"), exports);
@@ -0,0 +1,24 @@
1
+ import { UserRole } from "../enums";
2
+ /**
3
+ * Fields that are restricted for PROVIDER role
4
+ * These fields are only applicable to SUPPORT_WORKER
5
+ */
6
+ export declare const PROVIDER_RESTRICTED_FIELDS: readonly ["yearsOfExperience", "hourlyRate", "genderOfAttendants", "languages", "availabilities"];
7
+ /**
8
+ * Onboarding steps that are restricted for PROVIDER role
9
+ * These steps should be skipped in the onboarding flow for providers
10
+ */
11
+ export declare const PROVIDER_RESTRICTED_ONBOARDING_STEPS: readonly ["EXPERIENCE", "HOURLY_RATE", "GENDER", "LANGUAGES"];
12
+ /**
13
+ * Check if a field is restricted for the given role
14
+ */
15
+ export declare function isFieldRestrictedForRole(fieldName: string, role: UserRole): boolean;
16
+ /**
17
+ * Check if an onboarding step is restricted for the given role
18
+ */
19
+ export declare function isOnboardingStepRestrictedForRole(step: string, role: UserRole): boolean;
20
+ /**
21
+ * Get allowed onboarding steps for a role
22
+ * Filters out restricted steps based on role
23
+ */
24
+ export declare function getAllowedOnboardingSteps(allSteps: string[], role: UserRole): string[];
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROVIDER_RESTRICTED_ONBOARDING_STEPS = exports.PROVIDER_RESTRICTED_FIELDS = void 0;
4
+ exports.isFieldRestrictedForRole = isFieldRestrictedForRole;
5
+ exports.isOnboardingStepRestrictedForRole = isOnboardingStepRestrictedForRole;
6
+ exports.getAllowedOnboardingSteps = getAllowedOnboardingSteps;
7
+ const enums_1 = require("../enums");
8
+ /**
9
+ * Fields that are restricted for PROVIDER role
10
+ * These fields are only applicable to SUPPORT_WORKER
11
+ */
12
+ exports.PROVIDER_RESTRICTED_FIELDS = [
13
+ "yearsOfExperience",
14
+ "hourlyRate",
15
+ "genderOfAttendants",
16
+ "languages",
17
+ "availabilities",
18
+ // Note: Education and Work History are in User schema, not Business
19
+ ];
20
+ /**
21
+ * Onboarding steps that are restricted for PROVIDER role
22
+ * These steps should be skipped in the onboarding flow for providers
23
+ */
24
+ exports.PROVIDER_RESTRICTED_ONBOARDING_STEPS = [
25
+ "EXPERIENCE",
26
+ "HOURLY_RATE",
27
+ "GENDER",
28
+ "LANGUAGES",
29
+ // Note: Education and Work History are separate user profile fields
30
+ ];
31
+ /**
32
+ * Check if a field is restricted for the given role
33
+ */
34
+ function isFieldRestrictedForRole(fieldName, role) {
35
+ if (role === enums_1.UserRole.PROVIDER) {
36
+ return exports.PROVIDER_RESTRICTED_FIELDS.includes(fieldName);
37
+ }
38
+ return false;
39
+ }
40
+ /**
41
+ * Check if an onboarding step is restricted for the given role
42
+ */
43
+ function isOnboardingStepRestrictedForRole(step, role) {
44
+ if (role === enums_1.UserRole.PROVIDER) {
45
+ return exports.PROVIDER_RESTRICTED_ONBOARDING_STEPS.includes(step);
46
+ }
47
+ return false;
48
+ }
49
+ /**
50
+ * Get allowed onboarding steps for a role
51
+ * Filters out restricted steps based on role
52
+ */
53
+ function getAllowedOnboardingSteps(allSteps, role) {
54
+ if (role === enums_1.UserRole.PROVIDER) {
55
+ return allSteps.filter((step) => !isOnboardingStepRestrictedForRole(step, role));
56
+ }
57
+ return allSteps;
58
+ }
@@ -0,0 +1,35 @@
1
+ import { UserRole } from "../enums";
2
+ /**
3
+ * Check if user role is a worker (SUPPORT_WORKER or PROVIDER)
4
+ * Both roles have the same privileges and business logic
5
+ */
6
+ export declare function isWorkerRole(role: UserRole): boolean;
7
+ /**
8
+ * Check if user is a worker (SUPPORT_WORKER or PROVIDER)
9
+ * Accepts any object with a role property
10
+ */
11
+ export declare function isWorker(user: {
12
+ role: UserRole;
13
+ }): boolean;
14
+ /**
15
+ * Get array of worker roles for MongoDB $in queries
16
+ * Use this in MongoDB queries to filter for both SUPPORT_WORKER and PROVIDER
17
+ */
18
+ export declare function getWorkerRoles(): UserRole[];
19
+ /**
20
+ * Check if user role is a hirer (PARTICIPANT or SUPPORT_PERSON)
21
+ * Hirers can create jobs and initiate conversations
22
+ */
23
+ export declare function isHirerRole(role: UserRole): boolean;
24
+ /**
25
+ * Check if user is a hirer (PARTICIPANT or SUPPORT_PERSON)
26
+ * Accepts any object with a role property
27
+ */
28
+ export declare function isHirer(user: {
29
+ role: UserRole;
30
+ }): boolean;
31
+ /**
32
+ * Get array of hirer roles for MongoDB $in queries
33
+ * Use this in MongoDB queries to filter for both PARTICIPANT and SUPPORT_PERSON
34
+ */
35
+ export declare function getHirerRoles(): UserRole[];
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWorkerRole = isWorkerRole;
4
+ exports.isWorker = isWorker;
5
+ exports.getWorkerRoles = getWorkerRoles;
6
+ exports.isHirerRole = isHirerRole;
7
+ exports.isHirer = isHirer;
8
+ exports.getHirerRoles = getHirerRoles;
9
+ const enums_1 = require("../enums");
10
+ // ============================================================================
11
+ // WORKER ROLES (SUPPORT_WORKER and PROVIDER)
12
+ // ============================================================================
13
+ /**
14
+ * Check if user role is a worker (SUPPORT_WORKER or PROVIDER)
15
+ * Both roles have the same privileges and business logic
16
+ */
17
+ function isWorkerRole(role) {
18
+ return role === enums_1.UserRole.SUPPORT_WORKER || role === enums_1.UserRole.PROVIDER;
19
+ }
20
+ /**
21
+ * Check if user is a worker (SUPPORT_WORKER or PROVIDER)
22
+ * Accepts any object with a role property
23
+ */
24
+ function isWorker(user) {
25
+ return isWorkerRole(user.role);
26
+ }
27
+ /**
28
+ * Get array of worker roles for MongoDB $in queries
29
+ * Use this in MongoDB queries to filter for both SUPPORT_WORKER and PROVIDER
30
+ */
31
+ function getWorkerRoles() {
32
+ return [enums_1.UserRole.SUPPORT_WORKER, enums_1.UserRole.PROVIDER];
33
+ }
34
+ // ============================================================================
35
+ // HIRER ROLES (PARTICIPANT and SUPPORT_PERSON)
36
+ // ============================================================================
37
+ /**
38
+ * Check if user role is a hirer (PARTICIPANT or SUPPORT_PERSON)
39
+ * Hirers can create jobs and initiate conversations
40
+ */
41
+ function isHirerRole(role) {
42
+ return role === enums_1.UserRole.PARTICIPANT || role === enums_1.UserRole.SUPPORT_PERSON;
43
+ }
44
+ /**
45
+ * Check if user is a hirer (PARTICIPANT or SUPPORT_PERSON)
46
+ * Accepts any object with a role property
47
+ */
48
+ function isHirer(user) {
49
+ return isHirerRole(user.role);
50
+ }
51
+ /**
52
+ * Get array of hirer roles for MongoDB $in queries
53
+ * Use this in MongoDB queries to filter for both PARTICIPANT and SUPPORT_PERSON
54
+ */
55
+ function getHirerRoles() {
56
+ return [enums_1.UserRole.PARTICIPANT, enums_1.UserRole.SUPPORT_PERSON];
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@careflair/common",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "Shared assets for CareFlair",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",