@temboplus/afloat 0.1.76-beta.0 → 0.1.77-beta.2

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 (33) hide show
  1. package/dist/index.cjs.js +1 -1
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.esm.js +1 -1
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/lib/error/error.permission.d.ts +1 -1
  7. package/dist/modules/auth/auth.contract.d.ts +4 -4
  8. package/dist/modules/auth/auth.manager.d.ts +1 -1
  9. package/dist/modules/auth/company-membership.model.d.ts +58 -0
  10. package/dist/modules/auth/index.d.ts +1 -1
  11. package/dist/modules/auth/user.model.d.ts +107 -33
  12. package/dist/modules/contact/contact.api-contract.d.ts +16 -16
  13. package/dist/modules/contact/contact.dtos.d.ts +4 -4
  14. package/dist/modules/login/index.d.ts +2 -0
  15. package/dist/modules/login/login.api-contract.d.ts +34 -5
  16. package/dist/modules/login/login.dtos.d.ts +85 -0
  17. package/dist/modules/login/login.model.d.ts +138 -1
  18. package/dist/modules/{auth → login}/permission.type.d.ts +8 -8
  19. package/dist/modules/payout/payout.api-contract.d.ts +46 -46
  20. package/dist/modules/payout/payout.dtos.d.ts +24 -24
  21. package/dist/modules/team-member/index.d.ts +4 -0
  22. package/dist/modules/{user → team-member}/role.model.d.ts +2 -2
  23. package/dist/modules/{user/user.contract.d.ts → team-member/team-member.contract.d.ts} +238 -127
  24. package/dist/modules/team-member/team-member.dtos.d.ts +261 -0
  25. package/dist/modules/team-member/team-member.model.d.ts +137 -0
  26. package/dist/modules/team-member/team-member.repository.d.ts +179 -0
  27. package/dist/modules/wallet/wallet.contract.d.ts +4 -4
  28. package/dist/modules/wallet/wallet.dtos.d.ts +8 -8
  29. package/package.json +1 -1
  30. package/dist/modules/user/index.d.ts +0 -4
  31. package/dist/modules/user/user.dtos.d.ts +0 -145
  32. package/dist/modules/user/user.model.d.ts +0 -108
  33. package/dist/modules/user/user.repository.d.ts +0 -179
@@ -1,4 +1,4 @@
1
- import { Permission } from "@/modules/auth/permission.type.js";
1
+ import { Permission } from "@/modules/login/permission.type.js";
2
2
  /**
3
3
  * Custom error class representing an error caused by missing required permissions.
4
4
  * Extends the built-in {@link Error} class to include the `requiredPermissions` property.
@@ -54,6 +54,7 @@ export declare const authContract: {
54
54
  resetPassword: z.ZodBoolean;
55
55
  }, "strip", z.ZodTypeAny, {
56
56
  resetPassword: boolean;
57
+ access: string[];
57
58
  profile: {
58
59
  id: string;
59
60
  displayName: string;
@@ -65,9 +66,9 @@ export declare const authContract: {
65
66
  autoApprove?: boolean | null | undefined;
66
67
  };
67
68
  token: string;
68
- access: string[];
69
69
  }, {
70
70
  resetPassword: boolean;
71
+ access: string[];
71
72
  profile: {
72
73
  id: string;
73
74
  displayName: string;
@@ -79,7 +80,6 @@ export declare const authContract: {
79
80
  autoApprove?: boolean | null | undefined;
80
81
  };
81
82
  token: string;
82
- access: string[];
83
83
  }>;
84
84
  400: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
85
85
  };
@@ -97,11 +97,11 @@ export declare const authContract: {
97
97
  currentPassword: z.ZodString;
98
98
  newPassword: z.ZodString;
99
99
  }, "strip", z.ZodTypeAny, {
100
- currentPassword: string;
101
100
  newPassword: string;
102
- }, {
103
101
  currentPassword: string;
102
+ }, {
104
103
  newPassword: string;
104
+ currentPassword: string;
105
105
  }>;
106
106
  path: "/password";
107
107
  responses: {};
@@ -1,4 +1,4 @@
1
- import { Permission } from "@/modules/auth/permission.type.js";
1
+ import { Permission } from "@/modules/login/permission.type.js";
2
2
  import { User } from "@/modules/auth/user.model.js";
3
3
  /**
4
4
  * Clean authentication manager for client-side usage only.
@@ -0,0 +1,58 @@
1
+ import { Profile } from "../profile/profile.model.js";
2
+ import { Role } from "../team-member/role.model.js";
3
+ export interface CompanyMembershipData {
4
+ companyProfile: Profile;
5
+ role?: Role;
6
+ }
7
+ /**
8
+ * Represents a user's membership within a company.
9
+ *
10
+ * This class encapsulates the relationship between a user and their company:
11
+ * - The company profile the user belongs to
12
+ * - The user's role within that company (optional - depends on permissions)
13
+ *
14
+ * Note: Permissions are stored in LogIn.access, not here.
15
+ * This model focuses purely on the company-user relationship.
16
+ *
17
+ * The role may be undefined if the user doesn't have permission to view
18
+ * role details (Permissions.Role.ViewRole).
19
+ */
20
+ export declare class CompanyMembership {
21
+ private readonly _companyProfile;
22
+ private readonly _role?;
23
+ private constructor();
24
+ /**
25
+ * Creates a CompanyMembership instance from the required data.
26
+ *
27
+ * @param data - The membership data
28
+ * @returns A new CompanyMembership instance, or undefined if invalid
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const membership = CompanyMembership.from({
33
+ * companyProfile: profile,
34
+ * role: role // optional
35
+ * });
36
+ * ```
37
+ */
38
+ static from(data: CompanyMembershipData): CompanyMembership | undefined;
39
+ /**
40
+ * Gets the company profile.
41
+ */
42
+ get companyProfile(): Profile;
43
+ /**
44
+ * Gets the user's role (may be undefined if user lacks permission to view it).
45
+ */
46
+ get role(): Role | undefined;
47
+ /**
48
+ * Converts the membership to a plain object.
49
+ */
50
+ toObject(): {
51
+ companyProfile: ReturnType<Profile['toObject']>;
52
+ role?: ReturnType<Role['toJSON']>;
53
+ };
54
+ /**
55
+ * Converts the membership to a JSON string.
56
+ */
57
+ toJson(): string;
58
+ }
@@ -1,4 +1,4 @@
1
1
  export * from "./auth.manager.js";
2
2
  export * from "./auth.repository.js";
3
- export * from "./permission.type.js";
4
3
  export * from "./user.model.js";
4
+ export * from "./company-membership.model.js";
@@ -1,66 +1,140 @@
1
- import { Permission } from "./permission.type.js";
1
+ import { Permission } from "../login/permission.type.js";
2
2
  import { Profile } from "../profile/profile.model.js";
3
+ import { LogIn } from "../login/login.model.js";
4
+ import { CompanyMembership } from "./company-membership.model.js";
5
+ import { Role } from "../team-member/role.model.js";
6
+ export interface UserData {
7
+ logIn: LogIn;
8
+ companyProfile: Profile;
9
+ role?: Role;
10
+ token: string;
11
+ }
3
12
  /**
4
- * Represents a user in Afloat.
13
+ * Represents the currently authenticated user session.
14
+ *
15
+ * This class combines:
16
+ * - LogIn: User account data (identity, permissions, resetPassword, etc.)
17
+ * - CompanyMembership: User's relationship to their company (company profile + role)
18
+ * - Token: Session authentication token
19
+ *
20
+ * The User represents "who is logged in right now" with their full context.
5
21
  *
6
- * This class centralizes user-related logic, simplifying interaction
7
- * with user-related data and ensuring consistent access checks across the application.
22
+ * Note: The role in CompanyMembership may be undefined if the user doesn't have
23
+ * permission to view role details (Permissions.Role.ViewRole).
8
24
  */
9
25
  export declare class User {
26
+ private readonly _logIn;
27
+ private readonly _membership;
28
+ private readonly _token;
29
+ private readonly _permissionMap;
30
+ private constructor();
10
31
  /**
11
- * Logged-in user name.
32
+ * Creates a User instance from the provided data.
33
+ *
34
+ * @param data - User session data
35
+ * @returns A new User instance, or undefined if data is invalid
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const user = User.from({
40
+ * logIn: logIn,
41
+ * companyProfile: profile,
42
+ * role: role, // optional
43
+ * token: "auth-token"
44
+ * });
45
+ * ```
12
46
  */
13
- name: string;
47
+ static from(data: UserData): User | undefined;
14
48
  /**
15
- * Logged-in identity: phone number or email address.
49
+ * Creates a User instance from a JSON string.
50
+ *
51
+ * @param jsonString - JSON string containing user data
52
+ * @returns A new User instance, or undefined if parsing failed
16
53
  */
17
- identity: string;
54
+ static fromJson(jsonString: string): User | undefined;
18
55
  /**
19
- * The user's Afloat profile.
56
+ * Gets the user's login data.
20
57
  */
21
- profile: Profile;
58
+ get logIn(): LogIn;
22
59
  /**
23
- * The user's authentication token.
60
+ * Gets the user's company membership (includes company profile and role).
24
61
  */
25
- token: string;
62
+ get membership(): CompanyMembership;
26
63
  /**
27
- * Indicates whether the user must change their default password.
64
+ * Gets the user's authentication token.
28
65
  */
29
- resetPassword: boolean;
66
+ get token(): string;
30
67
  /**
31
- * A list of granted access keys (permissions).
68
+ * Convenience getter for the user's ID.
32
69
  */
33
- access: Permission[];
70
+ get id(): string;
34
71
  /**
35
- * A map of access keys to boolean values for fast permission checks.
72
+ * Convenience getter for the user's name.
36
73
  */
37
- private accessMap;
74
+ get name(): string;
38
75
  /**
39
- * Creates a new `User` instance.
76
+ * Convenience getter for the user's identity (email).
40
77
  */
41
- private constructor();
78
+ get identity(): string;
79
+ /**
80
+ * Convenience getter for the user's role ID.
81
+ */
82
+ get roleId(): string;
83
+ /**
84
+ * Convenience getter for whether the user must reset their password.
85
+ */
86
+ get resetPassword(): boolean;
87
+ /**
88
+ * Convenience getter for the company profile.
89
+ */
90
+ get profile(): Profile;
91
+ /**
92
+ * Convenience getter for the user's role (may be undefined).
93
+ */
94
+ get role(): Role | undefined;
95
+ /**
96
+ * Convenience getter for permissions array.
97
+ */
98
+ get access(): ReadonlyArray<string>;
42
99
  /**
43
- * Checks if the user has a specific access permission.
100
+ * Checks if the user has a specific permission.
44
101
  *
45
- * @param key - The access key to check.
46
- * @returns `true` if the user has the specified access, otherwise `false`.
102
+ * @param permission - The permission to check
103
+ * @returns true if the user has the permission
47
104
  */
48
- can(key: Permission): boolean;
105
+ can(permission: Permission): boolean;
49
106
  /**
50
- * Returns a plain object representation of the user.
51
- * This can safely be embedded in a JWT payload.
107
+ * Checks if the user has any of the specified permissions.
108
+ *
109
+ * @param permissions - Array of permissions to check
110
+ * @returns true if the user has at least one permission
52
111
  */
53
- toObject(): Record<string, any>;
112
+ canAny(permissions: Permission[]): boolean;
54
113
  /**
55
- * Serializes the `User` instance to a JSON string.
114
+ * Checks if the user has all of the specified permissions.
115
+ *
116
+ * @param permissions - Array of permissions to check
117
+ * @returns true if the user has all permissions
56
118
  */
57
- toJSON(): string;
119
+ canAll(permissions: Permission[]): boolean;
58
120
  /**
59
- * Creates a new `User` instance from a JSON string.
121
+ * Checks if the user can manage team members.
60
122
  */
61
- static fromJSON(jsonString: string): User | undefined;
123
+ canManageTeam(): boolean;
62
124
  /**
63
- * Creates a new `User` instance from a plain object.
125
+ * Checks if the user can view role details.
126
+ */
127
+ canViewRoles(): boolean;
128
+ /**
129
+ * Converts the User instance to a plain object.
130
+ *
131
+ * @returns A plain object representation suitable for serialization
132
+ */
133
+ toObject(): Record<string, any>;
134
+ /**
135
+ * Converts the User instance to a JSON string.
136
+ *
137
+ * @returns A JSON string representation
64
138
  */
65
- static from(data: any): User | undefined;
139
+ toJson(): string;
66
140
  }
@@ -44,19 +44,19 @@ export declare const contract: {
44
44
  id: string;
45
45
  displayName: string;
46
46
  accountNo: string;
47
- createdAt: string;
48
47
  profileId: string;
49
- channel: string;
48
+ createdAt: string;
50
49
  updatedAt: string;
50
+ channel: string;
51
51
  }, {
52
52
  type: import("./contact.dtos.js").ContactType;
53
53
  id: string;
54
54
  displayName: string;
55
55
  accountNo: string;
56
- createdAt: string;
57
56
  profileId: string;
58
- channel: string;
57
+ createdAt: string;
59
58
  updatedAt: string;
59
+ channel: string;
60
60
  }>;
61
61
  };
62
62
  };
@@ -95,19 +95,19 @@ export declare const contract: {
95
95
  id: string;
96
96
  displayName: string;
97
97
  accountNo: string;
98
- createdAt: string;
99
98
  profileId: string;
100
- channel: string;
99
+ createdAt: string;
101
100
  updatedAt: string;
101
+ channel: string;
102
102
  }, {
103
103
  type: import("./contact.dtos.js").ContactType;
104
104
  id: string;
105
105
  displayName: string;
106
106
  accountNo: string;
107
- createdAt: string;
108
107
  profileId: string;
109
- channel: string;
108
+ createdAt: string;
110
109
  updatedAt: string;
110
+ channel: string;
111
111
  }>;
112
112
  };
113
113
  };
@@ -137,19 +137,19 @@ export declare const contract: {
137
137
  id: string;
138
138
  displayName: string;
139
139
  accountNo: string;
140
- createdAt: string;
141
140
  profileId: string;
142
- channel: string;
141
+ createdAt: string;
143
142
  updatedAt: string;
143
+ channel: string;
144
144
  }, {
145
145
  type: import("./contact.dtos.js").ContactType;
146
146
  id: string;
147
147
  displayName: string;
148
148
  accountNo: string;
149
- createdAt: string;
150
149
  profileId: string;
151
- channel: string;
150
+ createdAt: string;
152
151
  updatedAt: string;
152
+ channel: string;
153
153
  }>, "many">;
154
154
  };
155
155
  };
@@ -172,19 +172,19 @@ export declare const contract: {
172
172
  id: string;
173
173
  displayName: string;
174
174
  accountNo: string;
175
- createdAt: string;
176
175
  profileId: string;
177
- channel: string;
176
+ createdAt: string;
178
177
  updatedAt: string;
178
+ channel: string;
179
179
  }, {
180
180
  type: import("./contact.dtos.js").ContactType;
181
181
  id: string;
182
182
  displayName: string;
183
183
  accountNo: string;
184
- createdAt: string;
185
184
  profileId: string;
186
- channel: string;
185
+ createdAt: string;
187
186
  updatedAt: string;
187
+ channel: string;
188
188
  }>;
189
189
  };
190
190
  };
@@ -48,19 +48,19 @@ export declare const ContactDTOSchemas: {
48
48
  id: string;
49
49
  displayName: string;
50
50
  accountNo: string;
51
- createdAt: string;
52
51
  profileId: string;
53
- channel: string;
52
+ createdAt: string;
54
53
  updatedAt: string;
54
+ channel: string;
55
55
  }, {
56
56
  type: ContactType;
57
57
  id: string;
58
58
  displayName: string;
59
59
  accountNo: string;
60
- createdAt: string;
61
60
  profileId: string;
62
- channel: string;
61
+ createdAt: string;
63
62
  updatedAt: string;
63
+ channel: string;
64
64
  }>;
65
65
  /** Schema for contact input validation */
66
66
  contactInputDTO: z.ZodObject<{
@@ -1,2 +1,4 @@
1
+ export * from "./login.dtos.js";
1
2
  export * from "./login.model.js";
2
3
  export * from "./login.repository.js";
4
+ export * from "./permission.type.js";
@@ -1,4 +1,3 @@
1
- import { z } from "zod";
2
1
  /**
3
2
  * Identity API contract
4
3
  */
@@ -7,15 +6,45 @@ export declare const identityContract: {
7
6
  method: "GET";
8
7
  path: "/me";
9
8
  responses: {
10
- 200: z.ZodObject<{
11
- name: z.ZodString;
12
- identity: z.ZodString;
13
- }, "strip", z.ZodTypeAny, {
9
+ 200: import("zod").ZodObject<{
10
+ id: import("zod").ZodString;
11
+ profileId: import("zod").ZodString;
12
+ name: import("zod").ZodString;
13
+ identity: import("zod").ZodString;
14
+ type: import("zod").ZodString;
15
+ roleId: import("zod").ZodString;
16
+ isActive: import("zod").ZodBoolean;
17
+ isArchived: import("zod").ZodBoolean;
18
+ resetPassword: import("zod").ZodBoolean;
19
+ createdAt: import("zod").ZodString;
20
+ updatedAt: import("zod").ZodString;
21
+ access: import("zod").ZodArray<import("zod").ZodString, "many">;
22
+ }, "strip", import("zod").ZodTypeAny, {
23
+ type: string;
14
24
  name: string;
25
+ id: string;
26
+ profileId: string;
15
27
  identity: string;
28
+ roleId: string;
29
+ isActive: boolean;
30
+ isArchived: boolean;
31
+ resetPassword: boolean;
32
+ createdAt: string;
33
+ updatedAt: string;
34
+ access: string[];
16
35
  }, {
36
+ type: string;
17
37
  name: string;
38
+ id: string;
39
+ profileId: string;
18
40
  identity: string;
41
+ roleId: string;
42
+ isActive: boolean;
43
+ isArchived: boolean;
44
+ resetPassword: boolean;
45
+ createdAt: string;
46
+ updatedAt: string;
47
+ access: string[];
19
48
  }>;
20
49
  };
21
50
  };
@@ -0,0 +1,85 @@
1
+ import z from "zod";
2
+ declare const LogInDTOSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ profileId: z.ZodString;
5
+ name: z.ZodString;
6
+ identity: z.ZodString;
7
+ type: z.ZodString;
8
+ roleId: z.ZodString;
9
+ isActive: z.ZodBoolean;
10
+ isArchived: z.ZodBoolean;
11
+ resetPassword: z.ZodBoolean;
12
+ createdAt: z.ZodString;
13
+ updatedAt: z.ZodString;
14
+ access: z.ZodArray<z.ZodString, "many">;
15
+ }, "strip", z.ZodTypeAny, {
16
+ type: string;
17
+ name: string;
18
+ id: string;
19
+ profileId: string;
20
+ identity: string;
21
+ roleId: string;
22
+ isActive: boolean;
23
+ isArchived: boolean;
24
+ resetPassword: boolean;
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ access: string[];
28
+ }, {
29
+ type: string;
30
+ name: string;
31
+ id: string;
32
+ profileId: string;
33
+ identity: string;
34
+ roleId: string;
35
+ isActive: boolean;
36
+ isArchived: boolean;
37
+ resetPassword: boolean;
38
+ createdAt: string;
39
+ updatedAt: string;
40
+ access: string[];
41
+ }>;
42
+ export declare const LogInSchemas: {
43
+ loginDTO: z.ZodObject<{
44
+ id: z.ZodString;
45
+ profileId: z.ZodString;
46
+ name: z.ZodString;
47
+ identity: z.ZodString;
48
+ type: z.ZodString;
49
+ roleId: z.ZodString;
50
+ isActive: z.ZodBoolean;
51
+ isArchived: z.ZodBoolean;
52
+ resetPassword: z.ZodBoolean;
53
+ createdAt: z.ZodString;
54
+ updatedAt: z.ZodString;
55
+ access: z.ZodArray<z.ZodString, "many">;
56
+ }, "strip", z.ZodTypeAny, {
57
+ type: string;
58
+ name: string;
59
+ id: string;
60
+ profileId: string;
61
+ identity: string;
62
+ roleId: string;
63
+ isActive: boolean;
64
+ isArchived: boolean;
65
+ resetPassword: boolean;
66
+ createdAt: string;
67
+ updatedAt: string;
68
+ access: string[];
69
+ }, {
70
+ type: string;
71
+ name: string;
72
+ id: string;
73
+ profileId: string;
74
+ identity: string;
75
+ roleId: string;
76
+ isActive: boolean;
77
+ isArchived: boolean;
78
+ resetPassword: boolean;
79
+ createdAt: string;
80
+ updatedAt: string;
81
+ access: string[];
82
+ }>;
83
+ };
84
+ export type LogInDTO = z.infer<typeof LogInDTOSchema>;
85
+ export {};