@temboplus/afloat 0.1.56 → 0.1.57

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.
@@ -3,80 +3,63 @@ import { Profile } from "./profile.model";
3
3
  * Represents a user in Afloat.
4
4
  *
5
5
  * This class centralizes user-related logic, simplifying interaction
6
- * with user-related data and ensuring consistent permission checks across the application.
6
+ * with user-related data and ensuring consistent access checks across the application.
7
7
  */
8
8
  export declare class User {
9
9
  /**
10
- * Logged-in user name
10
+ * Logged-in user name.
11
11
  */
12
12
  name: string;
13
13
  /**
14
- * Logged-in identity: phone-number or email address
14
+ * Logged-in identity: phone number or email address.
15
15
  */
16
16
  identity: string;
17
17
  /**
18
- * The user's Afloat profile, containing personal information such as name, contact details, and account information.
18
+ * The user's Afloat profile.
19
19
  */
20
20
  profile: Profile;
21
21
  /**
22
- * The user's authentication token. This token must be passed in the request headers
23
- * for all authenticated API endpoints.
22
+ * The user's authentication token.
24
23
  */
25
24
  token: string;
26
25
  /**
27
- * Indicates whether the user is required to change their default password.
26
+ * Indicates whether the user must change their default password.
28
27
  */
29
28
  resetPassword: boolean;
30
29
  /**
31
- * A map of permission keys to boolean values, indicating whether the user has access
32
- * to specific actions or features in the system.
30
+ * A list of granted access keys (permissions).
33
31
  */
34
- private permissionsMap;
32
+ access: string[];
35
33
  /**
36
- * Creates a new instance of the `User` class.
37
- *
38
- * @param userData - An object containing the user's profile, token,
39
- * permissions (access list), and the `resetPassword` flag.
34
+ * A map of access keys to boolean values for fast permission checks.
40
35
  */
41
- private constructor();
36
+ private accessMap;
42
37
  /**
43
- * Checks if the user has a specific permission.
44
- *
45
- * @param permission - The permission key to check.
46
- * @returns `true` if the user has the specified permission, otherwise `false`.
38
+ * Creates a new `User` instance.
47
39
  */
48
- can(permission: string): boolean;
40
+ private constructor();
49
41
  /**
50
- * Returns all permissions the user has.
42
+ * Checks if the user has a specific access permission.
51
43
  *
52
- * @returns An array of permission keys granted to the user.
44
+ * @param key - The access key to check.
45
+ * @returns `true` if the user has the specified access, otherwise `false`.
53
46
  */
54
- getPermissions(): string[];
47
+ can(key: string): boolean;
55
48
  /**
56
49
  * Returns a plain object representation of the user.
57
- * Unlike `toJSON()`, this does not stringify the object.
58
- *
59
- * @returns An object representing the current User instance.
50
+ * This can safely be embedded in a JWT payload.
60
51
  */
61
52
  toObject(): Record<string, any>;
62
53
  /**
63
54
  * Serializes the `User` instance to a JSON string.
64
- *
65
- * @returns A JSON string representation of the `User` instance.
66
55
  */
67
56
  toJSON(): string;
68
57
  /**
69
58
  * Creates a new `User` instance from a JSON string.
70
- *
71
- * @param jsonString - A JSON string containing user data.
72
- * @returns A `User` instance reconstructed from the JSON data, or `undefined` if invalid.
73
59
  */
74
60
  static fromJSON(jsonString: string): User | undefined;
75
61
  /**
76
- * Creates a new `User` instance from a data object, JSON string, or object with a Profile instance/object.
77
- *
78
- * @param data - The data object or stringified JSON containing user information.
79
- * @returns A `User` instance, or `undefined` if the data is invalid or incomplete.
62
+ * Creates a new `User` instance from a plain object.
80
63
  */
81
64
  static from(data: any): User | undefined;
82
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temboplus/afloat",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "description": "A foundational library for Temboplus-Afloat projects.",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.esm.js",