@temboplus/afloat 0.1.13 → 0.1.31

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 (145) hide show
  1. package/esm/src/features/auth/access/contract.d.ts +14 -0
  2. package/esm/src/features/auth/access/contract.d.ts.map +1 -0
  3. package/esm/src/features/auth/access/contract.js +14 -0
  4. package/esm/src/features/auth/contract.d.ts +20 -20
  5. package/esm/src/features/auth/contract.js +2 -2
  6. package/esm/src/features/auth/identity/contract.d.ts +0 -7
  7. package/esm/src/features/auth/identity/contract.d.ts.map +1 -1
  8. package/esm/src/features/auth/identity/contract.js +0 -1
  9. package/esm/src/features/auth/identity/repository.d.ts +2 -2
  10. package/esm/src/features/auth/identity/repository.d.ts.map +1 -1
  11. package/esm/src/features/auth/identity/repository.js +5 -5
  12. package/esm/src/features/auth/manager.js +1 -1
  13. package/esm/src/features/auth/profile/contract.d.ts +17 -25
  14. package/esm/src/features/auth/profile/contract.d.ts.map +1 -1
  15. package/esm/src/features/auth/profile/contract.js +2 -4
  16. package/esm/src/features/auth/repository.d.ts +0 -1
  17. package/esm/src/features/auth/repository.d.ts.map +1 -1
  18. package/esm/src/features/auth/repository.js +3 -11
  19. package/esm/src/features/auth/storage/server_token_handler.d.ts +7 -6
  20. package/esm/src/features/auth/storage/server_token_handler.d.ts.map +1 -1
  21. package/esm/src/features/auth/storage/server_token_handler.js +73 -26
  22. package/esm/src/features/contact/contract.d.ts +10 -10
  23. package/esm/src/features/payout/contract.d.ts +16 -16
  24. package/esm/src/features/wallet/contract.d.ts +3 -6
  25. package/esm/src/features/wallet/contract.d.ts.map +1 -1
  26. package/esm/src/features/wallet/repository.d.ts +1 -28
  27. package/esm/src/features/wallet/repository.d.ts.map +1 -1
  28. package/esm/src/features/wallet/repository.js +0 -51
  29. package/esm/src/models/contact/derivatives/contact.js +2 -2
  30. package/esm/src/models/contact/derivatives/contact_info.d.ts +8 -8
  31. package/esm/src/models/contact/derivatives/contact_info.d.ts.map +1 -1
  32. package/esm/src/models/contact/derivatives/contact_info.js +12 -12
  33. package/esm/src/models/payout/channel.d.ts +4 -4
  34. package/esm/src/models/payout/channel.d.ts.map +1 -1
  35. package/esm/src/models/payout/channel.js +10 -3
  36. package/esm/src/models/payout/derivatives/payout.d.ts.map +1 -1
  37. package/esm/src/models/payout/derivatives/payout.js +2 -2
  38. package/esm/src/models/payout/schemas.d.ts +2 -1
  39. package/esm/src/models/payout/schemas.d.ts.map +1 -1
  40. package/esm/src/models/payout/schemas.js +1 -0
  41. package/esm/src/models/payout/status.d.ts +1 -0
  42. package/esm/src/models/payout/status.d.ts.map +1 -1
  43. package/esm/src/models/payout/status.js +1 -0
  44. package/esm/src/models/user/profile.d.ts +135 -12
  45. package/esm/src/models/user/profile.d.ts.map +1 -1
  46. package/esm/src/models/user/profile.js +321 -12
  47. package/esm/src/models/user/user.d.ts +14 -17
  48. package/esm/src/models/user/user.d.ts.map +1 -1
  49. package/esm/src/models/user/user.js +109 -26
  50. package/esm/src/models/wallet/guards.d.ts.map +1 -1
  51. package/esm/src/models/wallet/guards.js +8 -2
  52. package/esm/src/models/wallet/index.d.ts +0 -1
  53. package/esm/src/models/wallet/index.d.ts.map +1 -1
  54. package/esm/src/models/wallet/index.js +0 -1
  55. package/esm/src/models/wallet/schemas.d.ts +1 -2
  56. package/esm/src/models/wallet/schemas.d.ts.map +1 -1
  57. package/esm/src/models/wallet/schemas.js +3 -12
  58. package/esm/src/shared/token_required_repository.d.ts +78 -0
  59. package/esm/src/shared/token_required_repository.d.ts.map +1 -0
  60. package/esm/src/shared/token_required_repository.js +128 -0
  61. package/package.json +7 -7
  62. package/script/src/features/auth/access/contract.d.ts +14 -0
  63. package/script/src/features/auth/access/contract.d.ts.map +1 -0
  64. package/script/src/features/auth/access/contract.js +17 -0
  65. package/script/src/features/auth/contract.d.ts +20 -20
  66. package/script/src/features/auth/contract.js +1 -1
  67. package/script/src/features/auth/identity/contract.d.ts +0 -7
  68. package/script/src/features/auth/identity/contract.d.ts.map +1 -1
  69. package/script/src/features/auth/identity/contract.js +0 -1
  70. package/script/src/features/auth/identity/repository.d.ts +2 -2
  71. package/script/src/features/auth/identity/repository.d.ts.map +1 -1
  72. package/script/src/features/auth/identity/repository.js +5 -5
  73. package/script/src/features/auth/manager.js +1 -1
  74. package/script/src/features/auth/profile/contract.d.ts +17 -25
  75. package/script/src/features/auth/profile/contract.d.ts.map +1 -1
  76. package/script/src/features/auth/profile/contract.js +1 -3
  77. package/script/src/features/auth/repository.d.ts +0 -1
  78. package/script/src/features/auth/repository.d.ts.map +1 -1
  79. package/script/src/features/auth/repository.js +3 -11
  80. package/script/src/features/auth/storage/server_token_handler.d.ts +7 -6
  81. package/script/src/features/auth/storage/server_token_handler.d.ts.map +1 -1
  82. package/script/src/features/auth/storage/server_token_handler.js +72 -25
  83. package/script/src/features/contact/contract.d.ts +10 -10
  84. package/script/src/features/payout/contract.d.ts +16 -16
  85. package/script/src/features/wallet/contract.d.ts +3 -6
  86. package/script/src/features/wallet/contract.d.ts.map +1 -1
  87. package/script/src/features/wallet/repository.d.ts +1 -28
  88. package/script/src/features/wallet/repository.d.ts.map +1 -1
  89. package/script/src/features/wallet/repository.js +0 -51
  90. package/script/src/models/contact/derivatives/contact.js +1 -1
  91. package/script/src/models/contact/derivatives/contact_info.d.ts +8 -8
  92. package/script/src/models/contact/derivatives/contact_info.d.ts.map +1 -1
  93. package/script/src/models/contact/derivatives/contact_info.js +11 -11
  94. package/script/src/models/payout/channel.d.ts +4 -4
  95. package/script/src/models/payout/channel.d.ts.map +1 -1
  96. package/script/src/models/payout/channel.js +10 -3
  97. package/script/src/models/payout/derivatives/payout.d.ts.map +1 -1
  98. package/script/src/models/payout/derivatives/payout.js +1 -1
  99. package/script/src/models/payout/schemas.d.ts +2 -1
  100. package/script/src/models/payout/schemas.d.ts.map +1 -1
  101. package/script/src/models/payout/schemas.js +1 -0
  102. package/script/src/models/payout/status.d.ts +1 -0
  103. package/script/src/models/payout/status.d.ts.map +1 -1
  104. package/script/src/models/payout/status.js +1 -0
  105. package/script/src/models/user/profile.d.ts +135 -12
  106. package/script/src/models/user/profile.d.ts.map +1 -1
  107. package/script/src/models/user/profile.js +323 -13
  108. package/script/src/models/user/user.d.ts +14 -17
  109. package/script/src/models/user/user.d.ts.map +1 -1
  110. package/script/src/models/user/user.js +109 -26
  111. package/script/src/models/wallet/guards.d.ts.map +1 -1
  112. package/script/src/models/wallet/guards.js +8 -2
  113. package/script/src/models/wallet/index.d.ts +0 -1
  114. package/script/src/models/wallet/index.d.ts.map +1 -1
  115. package/script/src/models/wallet/index.js +0 -1
  116. package/script/src/models/wallet/schemas.d.ts +1 -2
  117. package/script/src/models/wallet/schemas.d.ts.map +1 -1
  118. package/script/src/models/wallet/schemas.js +3 -12
  119. package/script/src/shared/token_required_repository.d.ts +78 -0
  120. package/script/src/shared/token_required_repository.d.ts.map +1 -0
  121. package/script/src/shared/token_required_repository.js +132 -0
  122. package/esm/src/features/auth/profile/repository.d.ts +0 -11
  123. package/esm/src/features/auth/profile/repository.d.ts.map +0 -1
  124. package/esm/src/features/auth/profile/repository.js +0 -21
  125. package/esm/src/features/files-gen/contract.d.ts +0 -67
  126. package/esm/src/features/files-gen/contract.d.ts.map +0 -1
  127. package/esm/src/features/files-gen/contract.js +0 -40
  128. package/esm/src/features/files-gen/repository.d.ts +0 -50
  129. package/esm/src/features/files-gen/repository.d.ts.map +0 -1
  130. package/esm/src/features/files-gen/repository.js +0 -56
  131. package/esm/src/models/wallet/statement.d.ts +0 -27
  132. package/esm/src/models/wallet/statement.d.ts.map +0 -1
  133. package/esm/src/models/wallet/statement.js +0 -13
  134. package/script/src/features/auth/profile/repository.d.ts +0 -11
  135. package/script/src/features/auth/profile/repository.d.ts.map +0 -1
  136. package/script/src/features/auth/profile/repository.js +0 -25
  137. package/script/src/features/files-gen/contract.d.ts +0 -67
  138. package/script/src/features/files-gen/contract.d.ts.map +0 -1
  139. package/script/src/features/files-gen/contract.js +0 -43
  140. package/script/src/features/files-gen/repository.d.ts +0 -50
  141. package/script/src/features/files-gen/repository.d.ts.map +0 -1
  142. package/script/src/features/files-gen/repository.js +0 -60
  143. package/script/src/models/wallet/statement.d.ts +0 -27
  144. package/script/src/models/wallet/statement.d.ts.map +0 -1
  145. package/script/src/models/wallet/statement.js +0 -16
@@ -1,16 +1,17 @@
1
1
  import { z } from "zod";
2
+ import { PhoneNumber } from "@temboplus/frontend-core";
2
3
  /**
3
4
  * Type definition for profile schema using Zod.
4
5
  * This type helper ensures type safety when implementing the actual schema.
5
6
  */
6
- type ProfileType = z.ZodObject<{
7
+ type ProfileZodSchemaType = z.ZodObject<{
7
8
  id: z.ZodString;
8
- firstName: z.ZodString;
9
- lastName: z.ZodString;
9
+ firstName: z.ZodNullable<z.ZodOptional<z.ZodString>>;
10
+ lastName: z.ZodNullable<z.ZodOptional<z.ZodString>>;
10
11
  displayName: z.ZodString;
11
- phone: z.ZodString;
12
+ phone: z.ZodNullable<z.ZodOptional<z.ZodString>>;
12
13
  accountNo: z.ZodString;
13
- email: z.ZodString;
14
+ email: z.ZodNullable<z.ZodOptional<z.ZodString>>;
14
15
  }>;
15
16
  /**
16
17
  * Zod schema for validating user profile data.
@@ -19,20 +20,142 @@ type ProfileType = z.ZodObject<{
19
20
  * @const {ProfileType}
20
21
  *
21
22
  * @property {string} id - Unique identifier for the profile
22
- * @property {string} firstName - User's first name
23
- * @property {string} lastName - User's last name
23
+ * @property {string | null | undefined} firstName - User's first name, can be null or undefined
24
+ * @property {string | null | undefined} lastName - User's last name, can be null or undefined
24
25
  * @property {string} displayName - User's display name
25
- * @property {string} phone - User's contact phone number
26
+ * @property {string | null | undefined} phone - User's contact phone number, can be null or undefined
26
27
  * @property {string} accountNo - User's account number
27
- * @property {string} email - User's email address
28
+ * @property {string | null | undefined} email - User's email address, can be null or undefined
28
29
  */
29
- export declare const profileSchema: ProfileType;
30
+ export declare const profileSchema: ProfileZodSchemaType;
30
31
  /**
31
32
  * TypeScript type representing a validated user profile.
32
33
  * Use this type for profile instances that have been validated against the schema.
34
+ */
35
+ export type ProfileType = z.infer<typeof profileSchema>;
36
+ /**
37
+ * Represents a user profile in the system.
33
38
  *
34
- * @see {@link profileSchema} for validation rules
39
+ * This class provides methods for creating, validating, and manipulating user profile data.
40
+ * It integrates with the Zod schema validation for data integrity.
35
41
  */
36
- export type Profile = z.infer<typeof profileSchema>;
42
+ export declare class Profile {
43
+ /** Unique identifier for the profile */
44
+ private _id;
45
+ /** User's first name */
46
+ private _firstName?;
47
+ /** User's last name */
48
+ private _lastName?;
49
+ /** User's display name, can be used for presentation */
50
+ private _displayName;
51
+ /** User's phone number, stored as a PhoneNumber object */
52
+ private _phone?;
53
+ /** User's account number */
54
+ private _accountNo;
55
+ /** User's email address */
56
+ private _email?;
57
+ /**
58
+ * Gets the profile schema used for validation.
59
+ */
60
+ static get schema(): ProfileZodSchemaType;
61
+ /**
62
+ * Creates a new Profile instance with the provided data.
63
+ *
64
+ * Private constructor to enforce use of static factory methods.
65
+ *
66
+ * @param data - Object containing profile information
67
+ */
68
+ private constructor();
69
+ /**
70
+ * Creates a new Profile instance with the provided data.
71
+ *
72
+ * @param data - Object containing profile information.
73
+ */
74
+ static create(data: {
75
+ id: string;
76
+ firstName?: string | null;
77
+ lastName?: string | null;
78
+ displayName: string;
79
+ phone?: string | null;
80
+ accountNo: string;
81
+ email?: string | null;
82
+ }): Profile | undefined;
83
+ /**
84
+ * Gets the profile's unique identifier.
85
+ */
86
+ get id(): string;
87
+ /**
88
+ * Gets the user's first name.
89
+ */
90
+ get firstName(): string | null | undefined;
91
+ /**
92
+ * Gets the user's last name.
93
+ */
94
+ get lastName(): string | null | undefined;
95
+ /**
96
+ * Gets the user's display name.
97
+ */
98
+ get displayName(): string;
99
+ /**
100
+ * Gets the user's phone number object.
101
+ */
102
+ get phone(): PhoneNumber | null | undefined;
103
+ /**
104
+ * Gets the user's account number.
105
+ */
106
+ get accountNo(): string;
107
+ /**
108
+ * Gets the user's email address.
109
+ */
110
+ get email(): string | null | undefined;
111
+ /**
112
+ * Gets the user's formatted phone number in international format.
113
+ */
114
+ get formattedPhone(): string | null | undefined;
115
+ /**
116
+ * Gets the user's name for display purposes.
117
+ * Returns the display name if it exists, otherwise returns the first and last name combined.
118
+ */
119
+ getName(): string;
120
+ /**
121
+ * Creates a plain object representation of the profile for validation or serialization.
122
+ *
123
+ * @returns A plain object matching the ProfileType interface
124
+ */
125
+ toObject(): ProfileType;
126
+ /**
127
+ * Converts the profile to a JSON string.
128
+ *
129
+ * @returns A JSON string representation of the profile
130
+ */
131
+ toJSON(): string;
132
+ /**
133
+ * Validates the profile data against the Zod schema.
134
+ *
135
+ * @returns True if the profile is valid, false otherwise
136
+ */
137
+ validate(): boolean;
138
+ /**
139
+ * Creates a Profile instance from a JSON string.
140
+ *
141
+ * @param jsonString - JSON string containing profile data
142
+ * @returns A new Profile instance, or undefined if parsing failed
143
+ */
144
+ static fromJSON(jsonString: string): Profile | undefined;
145
+ /**
146
+ * Creates a Profile instance from a plain object.
147
+ *
148
+ * @param data - Object containing profile data
149
+ * @returns A new Profile instance, or undefined if parsing failed
150
+ */
151
+ static from(data: any): Profile | undefined;
152
+ /**
153
+ * Type guard to check if an unknown object is a valid Profile instance.
154
+ *
155
+ * @param obj - The object to check
156
+ * @returns Type predicate indicating if the object is a valid Profile
157
+ */
158
+ static is(obj: unknown): obj is Profile;
159
+ }
37
160
  export {};
38
161
  //# sourceMappingURL=profile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../../src/src/models/user/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,KAAK,WAAW,GAAG,CAAC,CAAC,SAAS,CAAC;IAC7B,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC;IAChB,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC;IACvB,QAAQ,EAAE,CAAC,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E1C;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS,CAErC;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS,CAK9C;IAED;;;OAGG;IACH,OAAO,IAAI,MAAM;IAWjB;;;;OAIG;IACH,QAAQ,IAAI,WAAW;IAkBvB;;;;OAIG;IACH,MAAM,IAAI,MAAM;IAIhB;;;;OAIG;IACH,QAAQ,IAAI,OAAO;IAUnB;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAUxD;;;;;OAKG;IAEH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,GAAG,SAAS;IAgC3C;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO;CAmDxC"}
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { PhoneNumber } from "@temboplus/frontend-core";
2
3
  /**
3
4
  * Zod schema for validating user profile data.
4
5
  * Defines validation rules and constraints for each profile field.
@@ -6,20 +7,328 @@ import { z } from "zod";
6
7
  * @const {ProfileType}
7
8
  *
8
9
  * @property {string} id - Unique identifier for the profile
9
- * @property {string} firstName - User's first name
10
- * @property {string} lastName - User's last name
10
+ * @property {string | null | undefined} firstName - User's first name, can be null or undefined
11
+ * @property {string | null | undefined} lastName - User's last name, can be null or undefined
11
12
  * @property {string} displayName - User's display name
12
- * @property {string} phone - User's contact phone number
13
+ * @property {string | null | undefined} phone - User's contact phone number, can be null or undefined
13
14
  * @property {string} accountNo - User's account number
14
- * @property {string} email - User's email address
15
+ * @property {string | null | undefined} email - User's email address, can be null or undefined
15
16
  */
16
17
  export const profileSchema = z.object({
17
- id: z.string().uuid("Invalid profile ID format"),
18
- firstName: z.string().min(1, "First name is required"),
19
- lastName: z.string().min(1, "Last name is required"),
20
- displayName: z.string().min(1, "Display name is required"),
21
- phone: z.string().min(1, "Phone number is required")
22
- .regex(/^\+?[\d\s-]+$/, "Invalid phone number format"),
23
- accountNo: z.string().min(1, "Account number is required"),
24
- email: z.string().email("Invalid email format"),
18
+ id: z.string(),
19
+ firstName: z.string().optional().nullable(),
20
+ lastName: z.string().optional().nullable(),
21
+ displayName: z.string(),
22
+ phone: z.string().optional().nullable(),
23
+ accountNo: z.string().min(1),
24
+ email: z.string().email().optional().nullable(),
25
25
  });
26
+ /**
27
+ * Represents a user profile in the system.
28
+ *
29
+ * This class provides methods for creating, validating, and manipulating user profile data.
30
+ * It integrates with the Zod schema validation for data integrity.
31
+ */
32
+ export class Profile {
33
+ /**
34
+ * Gets the profile schema used for validation.
35
+ */
36
+ static get schema() {
37
+ return profileSchema;
38
+ }
39
+ /**
40
+ * Creates a new Profile instance with the provided data.
41
+ *
42
+ * Private constructor to enforce use of static factory methods.
43
+ *
44
+ * @param data - Object containing profile information
45
+ */
46
+ constructor(data) {
47
+ /** Unique identifier for the profile */
48
+ Object.defineProperty(this, "_id", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ /** User's first name */
55
+ Object.defineProperty(this, "_firstName", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ /** User's last name */
62
+ Object.defineProperty(this, "_lastName", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ /** User's display name, can be used for presentation */
69
+ Object.defineProperty(this, "_displayName", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ /** User's phone number, stored as a PhoneNumber object */
76
+ Object.defineProperty(this, "_phone", {
77
+ enumerable: true,
78
+ configurable: true,
79
+ writable: true,
80
+ value: void 0
81
+ });
82
+ /** User's account number */
83
+ Object.defineProperty(this, "_accountNo", {
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true,
87
+ value: void 0
88
+ });
89
+ /** User's email address */
90
+ Object.defineProperty(this, "_email", {
91
+ enumerable: true,
92
+ configurable: true,
93
+ writable: true,
94
+ value: void 0
95
+ });
96
+ this._id = data.id;
97
+ this._firstName = data.firstName;
98
+ this._lastName = data.lastName;
99
+ this._displayName = data.displayName;
100
+ this._phone = data.phone;
101
+ this._accountNo = data.accountNo;
102
+ this._email = data.email;
103
+ }
104
+ /**
105
+ * Creates a new Profile instance with the provided data.
106
+ *
107
+ * @param data - Object containing profile information.
108
+ */
109
+ static create(data) {
110
+ let phoneObj = undefined;
111
+ if (data.phone !== undefined && data.phone !== null) {
112
+ let phoneString = data.phone ?? "";
113
+ if (!phoneString.startsWith("+"))
114
+ phoneString = "+" + phoneString;
115
+ phoneObj = PhoneNumber.from(phoneString);
116
+ if (!phoneObj) {
117
+ console.error("Failed to parse phone number:", data.phone);
118
+ return undefined;
119
+ }
120
+ }
121
+ else {
122
+ phoneObj = data.phone; // Preserve null or undefined
123
+ }
124
+ return new Profile({
125
+ id: data.id,
126
+ firstName: data.firstName,
127
+ lastName: data.lastName,
128
+ displayName: data.displayName,
129
+ phone: phoneObj,
130
+ accountNo: data.accountNo,
131
+ email: data.email,
132
+ });
133
+ }
134
+ /**
135
+ * Gets the profile's unique identifier.
136
+ */
137
+ get id() {
138
+ return this._id;
139
+ }
140
+ /**
141
+ * Gets the user's first name.
142
+ */
143
+ get firstName() {
144
+ return this._firstName;
145
+ }
146
+ /**
147
+ * Gets the user's last name.
148
+ */
149
+ get lastName() {
150
+ return this._lastName;
151
+ }
152
+ /**
153
+ * Gets the user's display name.
154
+ */
155
+ get displayName() {
156
+ return this._displayName;
157
+ }
158
+ /**
159
+ * Gets the user's phone number object.
160
+ */
161
+ get phone() {
162
+ return this._phone;
163
+ }
164
+ /**
165
+ * Gets the user's account number.
166
+ */
167
+ get accountNo() {
168
+ return this._accountNo;
169
+ }
170
+ /**
171
+ * Gets the user's email address.
172
+ */
173
+ get email() {
174
+ return this._email;
175
+ }
176
+ /**
177
+ * Gets the user's formatted phone number in international format.
178
+ */
179
+ get formattedPhone() {
180
+ if (this._phone === undefined) {
181
+ return undefined;
182
+ }
183
+ return this._phone?.label ?? null;
184
+ }
185
+ /**
186
+ * Gets the user's name for display purposes.
187
+ * Returns the display name if it exists, otherwise returns the first and last name combined.
188
+ */
189
+ getName() {
190
+ if (this._displayName && this._displayName.trim() !== "") {
191
+ return this._displayName;
192
+ }
193
+ const firstName = this._firstName ?? "";
194
+ const lastName = this._lastName ?? "";
195
+ return `${firstName} ${lastName}`.trim();
196
+ }
197
+ /**
198
+ * Creates a plain object representation of the profile for validation or serialization.
199
+ *
200
+ * @returns A plain object matching the ProfileType interface
201
+ */
202
+ toObject() {
203
+ // Handle the phone specially to ensure we preserve undefined vs null
204
+ let phoneString = undefined;
205
+ if (this._phone !== undefined) {
206
+ phoneString = this._phone?.label ?? null;
207
+ }
208
+ return {
209
+ id: this._id,
210
+ firstName: this._firstName,
211
+ lastName: this._lastName,
212
+ displayName: this._displayName,
213
+ phone: phoneString,
214
+ accountNo: this._accountNo,
215
+ email: this._email,
216
+ };
217
+ }
218
+ /**
219
+ * Converts the profile to a JSON string.
220
+ *
221
+ * @returns A JSON string representation of the profile
222
+ */
223
+ toJSON() {
224
+ return JSON.stringify(this.toObject());
225
+ }
226
+ /**
227
+ * Validates the profile data against the Zod schema.
228
+ *
229
+ * @returns True if the profile is valid, false otherwise
230
+ */
231
+ validate() {
232
+ try {
233
+ const result = Profile.schema.safeParse(this.toObject());
234
+ return result.success;
235
+ }
236
+ catch (error) {
237
+ console.error("Profile validation error:", error);
238
+ return false;
239
+ }
240
+ }
241
+ /**
242
+ * Creates a Profile instance from a JSON string.
243
+ *
244
+ * @param jsonString - JSON string containing profile data
245
+ * @returns A new Profile instance, or undefined if parsing failed
246
+ */
247
+ static fromJSON(jsonString) {
248
+ try {
249
+ const data = JSON.parse(jsonString);
250
+ return Profile.from(data);
251
+ }
252
+ catch (error) {
253
+ console.error("Error parsing profile JSON:", error);
254
+ return undefined;
255
+ }
256
+ }
257
+ /**
258
+ * Creates a Profile instance from a plain object.
259
+ *
260
+ * @param data - Object containing profile data
261
+ * @returns A new Profile instance, or undefined if parsing failed
262
+ */
263
+ // deno-lint-ignore no-explicit-any
264
+ static from(data) {
265
+ try {
266
+ if (!data) {
267
+ console.error("Data is null or undefined");
268
+ return undefined;
269
+ }
270
+ if (typeof data !== "object") {
271
+ console.error("Data is not an object");
272
+ return undefined;
273
+ }
274
+ if (!data.id || !data.accountNo || !data.displayName) {
275
+ console.error("Missing required profile fields");
276
+ return undefined;
277
+ }
278
+ return Profile.create({
279
+ id: data.id,
280
+ firstName: data.firstName,
281
+ lastName: data.lastName,
282
+ displayName: data.displayName,
283
+ phone: data.phone,
284
+ accountNo: data.accountNo,
285
+ email: data.email,
286
+ });
287
+ }
288
+ catch (error) {
289
+ console.error("Error creating profile from object:", error);
290
+ return undefined;
291
+ }
292
+ }
293
+ /**
294
+ * Type guard to check if an unknown object is a valid Profile instance.
295
+ *
296
+ * @param obj - The object to check
297
+ * @returns Type predicate indicating if the object is a valid Profile
298
+ */
299
+ static is(obj) {
300
+ if (!obj || typeof obj !== "object")
301
+ return false;
302
+ const maybeProfile = obj;
303
+ // Check required properties
304
+ if (typeof maybeProfile._id !== "string" ||
305
+ typeof maybeProfile._displayName !== "string" ||
306
+ typeof maybeProfile._accountNo !== "string") {
307
+ return false;
308
+ }
309
+ // Check nullable/optional properties have the right type when present
310
+ if (maybeProfile._firstName !== null &&
311
+ maybeProfile._firstName !== undefined &&
312
+ typeof maybeProfile._firstName !== "string") {
313
+ return false;
314
+ }
315
+ if (maybeProfile._lastName !== null &&
316
+ maybeProfile._lastName !== undefined &&
317
+ typeof maybeProfile._lastName !== "string") {
318
+ return false;
319
+ }
320
+ if (maybeProfile._email !== null &&
321
+ maybeProfile._email !== undefined &&
322
+ typeof maybeProfile._email !== "string") {
323
+ return false;
324
+ }
325
+ // Check phone number
326
+ const phone = maybeProfile._phone;
327
+ if (phone !== null &&
328
+ phone !== undefined &&
329
+ !PhoneNumber.is(phone)) {
330
+ return false;
331
+ }
332
+ return true;
333
+ }
334
+ }
@@ -1,6 +1,6 @@
1
- import type { Profile } from "./profile.js";
1
+ import { Profile } from "./profile.js";
2
2
  /**
3
- * Represents a user in Afloat
3
+ * Represents a user in Afloat.
4
4
  *
5
5
  * This class centralizes user-related logic, simplifying interaction
6
6
  * with user-related data and ensuring consistent permission checks across the application.
@@ -38,19 +38,10 @@ export declare class User {
38
38
  /**
39
39
  * Creates a new instance of the `User` class.
40
40
  *
41
- * @param userData - An object of type `CoreUser` containing the user's profile, token,
41
+ * @param userData - An object containing the user's profile, token,
42
42
  * permissions (access list), and the `resetPassword` flag.
43
43
  */
44
- constructor(data: {
45
- profile: Profile;
46
- token: string;
47
- access: string[];
48
- resetPassword: boolean;
49
- loginCredentials: {
50
- name: string;
51
- identity: string;
52
- };
53
- });
44
+ private constructor();
54
45
  /**
55
46
  * Checks if the user has a specific permission.
56
47
  *
@@ -62,7 +53,7 @@ export declare class User {
62
53
  * Serializes the `User` instance to a JSON string.
63
54
  *
64
55
  * @returns A JSON string representation of the `User` instance, including:
65
- * - `profile`: The user's profile information.
56
+ * - `profile`: The user's profile information. (Requires profile.toJSON() method)
66
57
  * - `token`: The user's authentication token.
67
58
  * - `resetPassword`: Indicates whether the user must reset their password.
68
59
  * - `permissions`: An array of permission keys the user has.
@@ -72,9 +63,15 @@ export declare class User {
72
63
  * Creates a new `User` instance from a JSON string.
73
64
  *
74
65
  * @param jsonString - A JSON string containing user data.
75
- * @returns A `User` instance reconstructed from the JSON data.
76
- * @throws Will throw an error if the JSON data is invalid or incomplete.
66
+ * @returns A `User` instance reconstructed from the JSON data, or undefined if jsonString is invalid.
77
67
  */
78
- static fromJSON(jsonString: string): User;
68
+ static fromJSON(jsonString: string): User | undefined;
69
+ /**
70
+ * Creates a new `User` instance from a data object, JSON string, or object with a Profile instance/object.
71
+ *
72
+ * @param data - The data object, JSON string, or object with Profile instance/object containing user information.
73
+ * @returns A `User` instance, or undefined if data is invalid.
74
+ */
75
+ static from(data: any): User | undefined;
79
76
  }
80
77
  //# sourceMappingURL=user.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../../src/src/models/user/user.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;GAKG;AACH,qBAAa,IAAI;IACf;;OAEG;IACI,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACI,QAAQ,EAAE,MAAM,CAAC;IAExB;;OAEG;IACI,OAAO,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACI,KAAK,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACI,aAAa,EAAE,OAAO,CAAC;IAE9B;;;OAGG;IACH,OAAO,CAAC,cAAc,CAA0B;IAEhD;;;;;OAKG;gBACS,IAAI,EAAE;QAChB,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,aAAa,EAAE,OAAO,CAAC;QACvB,gBAAgB,EAAE;YAChB,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;KACH;IAqBD;;;;;OAKG;IACI,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAIvC;;;;;;;;OAQG;IACI,MAAM,IAAI,MAAM;IAavB;;;;;;OAMG;WACW,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;CA4BjD"}
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../../src/src/models/user/user.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,IAAI;IACf;;O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