@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,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.profileSchema = void 0;
3
+ exports.Profile = exports.profileSchema = void 0;
4
4
  const zod_1 = require("zod");
5
+ const frontend_core_1 = require("@temboplus/frontend-core");
5
6
  /**
6
7
  * Zod schema for validating user profile data.
7
8
  * Defines validation rules and constraints for each profile field.
@@ -9,20 +10,329 @@ const zod_1 = require("zod");
9
10
  * @const {ProfileType}
10
11
  *
11
12
  * @property {string} id - Unique identifier for the profile
12
- * @property {string} firstName - User's first name
13
- * @property {string} lastName - User's last name
13
+ * @property {string | null | undefined} firstName - User's first name, can be null or undefined
14
+ * @property {string | null | undefined} lastName - User's last name, can be null or undefined
14
15
  * @property {string} displayName - User's display name
15
- * @property {string} phone - User's contact phone number
16
+ * @property {string | null | undefined} phone - User's contact phone number, can be null or undefined
16
17
  * @property {string} accountNo - User's account number
17
- * @property {string} email - User's email address
18
+ * @property {string | null | undefined} email - User's email address, can be null or undefined
18
19
  */
19
20
  exports.profileSchema = zod_1.z.object({
20
- id: zod_1.z.string().uuid("Invalid profile ID format"),
21
- firstName: zod_1.z.string().min(1, "First name is required"),
22
- lastName: zod_1.z.string().min(1, "Last name is required"),
23
- displayName: zod_1.z.string().min(1, "Display name is required"),
24
- phone: zod_1.z.string().min(1, "Phone number is required")
25
- .regex(/^\+?[\d\s-]+$/, "Invalid phone number format"),
26
- accountNo: zod_1.z.string().min(1, "Account number is required"),
27
- email: zod_1.z.string().email("Invalid email format"),
21
+ id: zod_1.z.string(),
22
+ firstName: zod_1.z.string().optional().nullable(),
23
+ lastName: zod_1.z.string().optional().nullable(),
24
+ displayName: zod_1.z.string(),
25
+ phone: zod_1.z.string().optional().nullable(),
26
+ accountNo: zod_1.z.string().min(1),
27
+ email: zod_1.z.string().email().optional().nullable(),
28
28
  });
29
+ /**
30
+ * Represents a user profile in the system.
31
+ *
32
+ * This class provides methods for creating, validating, and manipulating user profile data.
33
+ * It integrates with the Zod schema validation for data integrity.
34
+ */
35
+ class Profile {
36
+ /**
37
+ * Gets the profile schema used for validation.
38
+ */
39
+ static get schema() {
40
+ return exports.profileSchema;
41
+ }
42
+ /**
43
+ * Creates a new Profile instance with the provided data.
44
+ *
45
+ * Private constructor to enforce use of static factory methods.
46
+ *
47
+ * @param data - Object containing profile information
48
+ */
49
+ constructor(data) {
50
+ /** Unique identifier for the profile */
51
+ Object.defineProperty(this, "_id", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ /** User's first name */
58
+ Object.defineProperty(this, "_firstName", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: void 0
63
+ });
64
+ /** User's last name */
65
+ Object.defineProperty(this, "_lastName", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
71
+ /** User's display name, can be used for presentation */
72
+ Object.defineProperty(this, "_displayName", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ /** User's phone number, stored as a PhoneNumber object */
79
+ Object.defineProperty(this, "_phone", {
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true,
83
+ value: void 0
84
+ });
85
+ /** User's account number */
86
+ Object.defineProperty(this, "_accountNo", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+ /** User's email address */
93
+ Object.defineProperty(this, "_email", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: void 0
98
+ });
99
+ this._id = data.id;
100
+ this._firstName = data.firstName;
101
+ this._lastName = data.lastName;
102
+ this._displayName = data.displayName;
103
+ this._phone = data.phone;
104
+ this._accountNo = data.accountNo;
105
+ this._email = data.email;
106
+ }
107
+ /**
108
+ * Creates a new Profile instance with the provided data.
109
+ *
110
+ * @param data - Object containing profile information.
111
+ */
112
+ static create(data) {
113
+ let phoneObj = undefined;
114
+ if (data.phone !== undefined && data.phone !== null) {
115
+ let phoneString = data.phone ?? "";
116
+ if (!phoneString.startsWith("+"))
117
+ phoneString = "+" + phoneString;
118
+ phoneObj = frontend_core_1.PhoneNumber.from(phoneString);
119
+ if (!phoneObj) {
120
+ console.error("Failed to parse phone number:", data.phone);
121
+ return undefined;
122
+ }
123
+ }
124
+ else {
125
+ phoneObj = data.phone; // Preserve null or undefined
126
+ }
127
+ return new Profile({
128
+ id: data.id,
129
+ firstName: data.firstName,
130
+ lastName: data.lastName,
131
+ displayName: data.displayName,
132
+ phone: phoneObj,
133
+ accountNo: data.accountNo,
134
+ email: data.email,
135
+ });
136
+ }
137
+ /**
138
+ * Gets the profile's unique identifier.
139
+ */
140
+ get id() {
141
+ return this._id;
142
+ }
143
+ /**
144
+ * Gets the user's first name.
145
+ */
146
+ get firstName() {
147
+ return this._firstName;
148
+ }
149
+ /**
150
+ * Gets the user's last name.
151
+ */
152
+ get lastName() {
153
+ return this._lastName;
154
+ }
155
+ /**
156
+ * Gets the user's display name.
157
+ */
158
+ get displayName() {
159
+ return this._displayName;
160
+ }
161
+ /**
162
+ * Gets the user's phone number object.
163
+ */
164
+ get phone() {
165
+ return this._phone;
166
+ }
167
+ /**
168
+ * Gets the user's account number.
169
+ */
170
+ get accountNo() {
171
+ return this._accountNo;
172
+ }
173
+ /**
174
+ * Gets the user's email address.
175
+ */
176
+ get email() {
177
+ return this._email;
178
+ }
179
+ /**
180
+ * Gets the user's formatted phone number in international format.
181
+ */
182
+ get formattedPhone() {
183
+ if (this._phone === undefined) {
184
+ return undefined;
185
+ }
186
+ return this._phone?.label ?? null;
187
+ }
188
+ /**
189
+ * Gets the user's name for display purposes.
190
+ * Returns the display name if it exists, otherwise returns the first and last name combined.
191
+ */
192
+ getName() {
193
+ if (this._displayName && this._displayName.trim() !== "") {
194
+ return this._displayName;
195
+ }
196
+ const firstName = this._firstName ?? "";
197
+ const lastName = this._lastName ?? "";
198
+ return `${firstName} ${lastName}`.trim();
199
+ }
200
+ /**
201
+ * Creates a plain object representation of the profile for validation or serialization.
202
+ *
203
+ * @returns A plain object matching the ProfileType interface
204
+ */
205
+ toObject() {
206
+ // Handle the phone specially to ensure we preserve undefined vs null
207
+ let phoneString = undefined;
208
+ if (this._phone !== undefined) {
209
+ phoneString = this._phone?.label ?? null;
210
+ }
211
+ return {
212
+ id: this._id,
213
+ firstName: this._firstName,
214
+ lastName: this._lastName,
215
+ displayName: this._displayName,
216
+ phone: phoneString,
217
+ accountNo: this._accountNo,
218
+ email: this._email,
219
+ };
220
+ }
221
+ /**
222
+ * Converts the profile to a JSON string.
223
+ *
224
+ * @returns A JSON string representation of the profile
225
+ */
226
+ toJSON() {
227
+ return JSON.stringify(this.toObject());
228
+ }
229
+ /**
230
+ * Validates the profile data against the Zod schema.
231
+ *
232
+ * @returns True if the profile is valid, false otherwise
233
+ */
234
+ validate() {
235
+ try {
236
+ const result = Profile.schema.safeParse(this.toObject());
237
+ return result.success;
238
+ }
239
+ catch (error) {
240
+ console.error("Profile validation error:", error);
241
+ return false;
242
+ }
243
+ }
244
+ /**
245
+ * Creates a Profile instance from a JSON string.
246
+ *
247
+ * @param jsonString - JSON string containing profile data
248
+ * @returns A new Profile instance, or undefined if parsing failed
249
+ */
250
+ static fromJSON(jsonString) {
251
+ try {
252
+ const data = JSON.parse(jsonString);
253
+ return Profile.from(data);
254
+ }
255
+ catch (error) {
256
+ console.error("Error parsing profile JSON:", error);
257
+ return undefined;
258
+ }
259
+ }
260
+ /**
261
+ * Creates a Profile instance from a plain object.
262
+ *
263
+ * @param data - Object containing profile data
264
+ * @returns A new Profile instance, or undefined if parsing failed
265
+ */
266
+ // deno-lint-ignore no-explicit-any
267
+ static from(data) {
268
+ try {
269
+ if (!data) {
270
+ console.error("Data is null or undefined");
271
+ return undefined;
272
+ }
273
+ if (typeof data !== "object") {
274
+ console.error("Data is not an object");
275
+ return undefined;
276
+ }
277
+ if (!data.id || !data.accountNo || !data.displayName) {
278
+ console.error("Missing required profile fields");
279
+ return undefined;
280
+ }
281
+ return Profile.create({
282
+ id: data.id,
283
+ firstName: data.firstName,
284
+ lastName: data.lastName,
285
+ displayName: data.displayName,
286
+ phone: data.phone,
287
+ accountNo: data.accountNo,
288
+ email: data.email,
289
+ });
290
+ }
291
+ catch (error) {
292
+ console.error("Error creating profile from object:", error);
293
+ return undefined;
294
+ }
295
+ }
296
+ /**
297
+ * Type guard to check if an unknown object is a valid Profile instance.
298
+ *
299
+ * @param obj - The object to check
300
+ * @returns Type predicate indicating if the object is a valid Profile
301
+ */
302
+ static is(obj) {
303
+ if (!obj || typeof obj !== "object")
304
+ return false;
305
+ const maybeProfile = obj;
306
+ // Check required properties
307
+ if (typeof maybeProfile._id !== "string" ||
308
+ typeof maybeProfile._displayName !== "string" ||
309
+ typeof maybeProfile._accountNo !== "string") {
310
+ return false;
311
+ }
312
+ // Check nullable/optional properties have the right type when present
313
+ if (maybeProfile._firstName !== null &&
314
+ maybeProfile._firstName !== undefined &&
315
+ typeof maybeProfile._firstName !== "string") {
316
+ return false;
317
+ }
318
+ if (maybeProfile._lastName !== null &&
319
+ maybeProfile._lastName !== undefined &&
320
+ typeof maybeProfile._lastName !== "string") {
321
+ return false;
322
+ }
323
+ if (maybeProfile._email !== null &&
324
+ maybeProfile._email !== undefined &&
325
+ typeof maybeProfile._email !== "string") {
326
+ return false;
327
+ }
328
+ // Check phone number
329
+ const phone = maybeProfile._phone;
330
+ if (phone !== null &&
331
+ phone !== undefined &&
332
+ !frontend_core_1.PhoneNumber.is(phone)) {
333
+ return false;
334
+ }
335
+ return true;
336
+ }
337
+ }
338
+ exports.Profile = Profile;
@@ -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;;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;IACH,OAAO;IA6BP;;;;;OAKG;IACI,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAIvC;;;;;;;;OAQG;IACI,MAAM,IAAI,MAAM;IAavB;;;;;OAKG;WACW,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAS5D;;;;;OAKG;WACW,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,GAAG,SAAS;CA4FhD"}
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.User = void 0;
4
+ // deno-lint-ignore-file no-explicit-any
4
5
  const permission_js_1 = require("../permission.js");
6
+ const profile_js_1 = require("./profile.js");
5
7
  /**
6
- * Represents a user in Afloat
8
+ * Represents a user in Afloat.
7
9
  *
8
10
  * This class centralizes user-related logic, simplifying interaction
9
11
  * with user-related data and ensuring consistent permission checks across the application.
@@ -12,7 +14,7 @@ class User {
12
14
  /**
13
15
  * Creates a new instance of the `User` class.
14
16
  *
15
- * @param userData - An object of type `CoreUser` containing the user's profile, token,
17
+ * @param userData - An object containing the user's profile, token,
16
18
  * permissions (access list), and the `resetPassword` flag.
17
19
  */
18
20
  constructor(data) {
@@ -75,12 +77,12 @@ class User {
75
77
  writable: true,
76
78
  value: void 0
77
79
  });
78
- const { profile, token, access, resetPassword } = data;
80
+ const { profile, token, access, resetPassword, name, identity } = data;
79
81
  this.profile = profile;
80
82
  this.token = token;
81
83
  this.resetPassword = resetPassword;
82
- this.name = data.loginCredentials.name;
83
- this.identity = data.loginCredentials.identity;
84
+ this.name = name;
85
+ this.identity = identity;
84
86
  // Initialize the permissions map
85
87
  this.permissionsMap = {};
86
88
  for (const permission of Object.values(permission_js_1.Permissions)) {
@@ -89,6 +91,9 @@ class User {
89
91
  this.permissionsMap[perm] = access.includes(perm);
90
92
  });
91
93
  }
94
+ else {
95
+ this.permissionsMap[permission] = access.includes(permission);
96
+ }
92
97
  }
93
98
  }
94
99
  /**
@@ -104,14 +109,14 @@ class User {
104
109
  * Serializes the `User` instance to a JSON string.
105
110
  *
106
111
  * @returns A JSON string representation of the `User` instance, including:
107
- * - `profile`: The user's profile information.
112
+ * - `profile`: The user's profile information. (Requires profile.toJSON() method)
108
113
  * - `token`: The user's authentication token.
109
114
  * - `resetPassword`: Indicates whether the user must reset their password.
110
115
  * - `permissions`: An array of permission keys the user has.
111
116
  */
112
117
  toJSON() {
113
118
  return JSON.stringify({
114
- profile: this.profile,
119
+ profile: this.profile.toObject(),
115
120
  token: this.token,
116
121
  resetPassword: this.resetPassword,
117
122
  name: this.name,
@@ -123,29 +128,107 @@ class User {
123
128
  * Creates a new `User` instance from a JSON string.
124
129
  *
125
130
  * @param jsonString - A JSON string containing user data.
126
- * @returns A `User` instance reconstructed from the JSON data.
127
- * @throws Will throw an error if the JSON data is invalid or incomplete.
131
+ * @returns A `User` instance reconstructed from the JSON data, or undefined if jsonString is invalid.
128
132
  */
129
133
  static fromJSON(jsonString) {
130
- const data = JSON.parse(jsonString);
131
- if (!data.profile ||
132
- !data.token ||
133
- !data.name ||
134
- !data.identity ||
135
- !Array.isArray(data.permissions) ||
136
- typeof data.resetPassword !== "boolean") {
137
- throw new Error("Invalid JSON data for User");
134
+ try {
135
+ return User.from(JSON.parse(jsonString));
136
+ }
137
+ catch (e) {
138
+ console.error("Invalid JSON string:", e);
139
+ return undefined;
140
+ }
141
+ }
142
+ /**
143
+ * Creates a new `User` instance from a data object, JSON string, or object with a Profile instance/object.
144
+ *
145
+ * @param data - The data object, JSON string, or object with Profile instance/object containing user information.
146
+ * @returns A `User` instance, or undefined if data is invalid.
147
+ */
148
+ static from(data) {
149
+ let parsedData;
150
+ // Parse JSON string if needed
151
+ if (typeof data === "string") {
152
+ try {
153
+ parsedData = JSON.parse(data);
154
+ }
155
+ catch (error) {
156
+ console.error("Invalid JSON string:", error);
157
+ return undefined;
158
+ }
159
+ }
160
+ else {
161
+ parsedData = data;
162
+ }
163
+ if (!parsedData) {
164
+ console.error("Data is null or undefined.");
165
+ return undefined;
166
+ }
167
+ // Handle different profile formats
168
+ let profile;
169
+ let rawProfile = parsedData.profile;
170
+ // Handle stringified profile (the case in the provided sample)
171
+ if (typeof rawProfile === "string") {
172
+ try {
173
+ // Attempt to parse the stringified profile
174
+ rawProfile = JSON.parse(rawProfile);
175
+ }
176
+ catch (error) {
177
+ console.error("Failed to parse profile JSON string:", error);
178
+ return undefined;
179
+ }
180
+ }
181
+ // Create Profile instance based on what we received
182
+ if (profile_js_1.Profile.is(rawProfile)) {
183
+ // Already a Profile instance
184
+ profile = rawProfile;
185
+ }
186
+ else if (typeof rawProfile === "object" && rawProfile !== null) {
187
+ // Convert object to Profile instance
188
+ profile = profile_js_1.Profile.from(rawProfile);
189
+ if (!profile) {
190
+ console.error("Failed to create Profile from data:", rawProfile);
191
+ return undefined;
192
+ }
193
+ }
194
+ else if (typeof rawProfile === "string") {
195
+ profile = profile_js_1.Profile.fromJSON(rawProfile);
196
+ if (!profile) {
197
+ console.error("Failed to create Profile from JSON data:", rawProfile);
198
+ return undefined;
199
+ }
200
+ }
201
+ else {
202
+ console.error("Invalid profile format:", typeof rawProfile);
203
+ return undefined;
204
+ }
205
+ // Validate other required fields
206
+ if (!parsedData.token || typeof parsedData.token !== "string" ||
207
+ !parsedData.name || typeof parsedData.name !== "string" ||
208
+ !parsedData.identity || typeof parsedData.identity !== "string" ||
209
+ !Array.isArray(parsedData.permissions) &&
210
+ !Array.isArray(parsedData.access) ||
211
+ typeof parsedData.resetPassword !== "boolean") {
212
+ console.error("Missing or invalid required User fields:", {
213
+ token: typeof parsedData.token,
214
+ name: typeof parsedData.name,
215
+ identity: typeof parsedData.identity,
216
+ permissions: Array.isArray(parsedData.permissions),
217
+ access: Array.isArray(parsedData.access),
218
+ resetPassword: typeof parsedData.resetPassword,
219
+ });
220
+ return undefined;
138
221
  }
139
- // Reconstruct the CoreUser structure
222
+ // Support both 'permissions' and 'access' field names
223
+ const access = parsedData.access || parsedData.permissions;
224
+ // Create and return the User instance
140
225
  const args = {
141
- profile: data.profile,
142
- token: data.token,
143
- access: data.permissions,
144
- resetPassword: data.resetPassword,
145
- loginCredentials: {
146
- name: data.name,
147
- identity: data.identity,
148
- },
226
+ profile: profile,
227
+ token: parsedData.token,
228
+ access: access,
229
+ resetPassword: parsedData.resetPassword,
230
+ name: parsedData.name,
231
+ identity: parsedData.identity,
149
232
  };
150
233
  return new User(args);
151
234
  }
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/guards.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAEtB;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,mBAAmB,EAAE,CAG/B"}
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/guards.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAEtB;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,mBAAmB,EAAE,CAQ/B"}
@@ -12,6 +12,12 @@ const schemas_js_1 = require("./schemas.js");
12
12
  * false otherwise
13
13
  */
14
14
  function isWalletStatementItemArray(data) {
15
- const result = zod_1.z.array(schemas_js_1.WalletSchemas.statementEntry).safeParse(data);
16
- return result.success;
15
+ try {
16
+ zod_1.z.array(schemas_js_1.WalletSchemas.statementEntry).parse(data);
17
+ return true;
18
+ }
19
+ catch (error) {
20
+ console.log("isWalletStatementItemArray?: false. Why?: ", error);
21
+ return false;
22
+ }
17
23
  }
@@ -1,4 +1,3 @@
1
1
  export * from "./guards.js";
2
2
  export * from "./schemas.js";
3
- export * from "./statement.js";
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./guards.js"), exports);
18
18
  __exportStar(require("./schemas.js"), exports);
19
- __exportStar(require("./statement.js"), exports);
@@ -4,8 +4,7 @@ import { z } from "zod";
4
4
  * This is used as a TypeScript type helper for the actual schema implementation.
5
5
  */
6
6
  type _StatementEntryType = z.ZodObject<{
7
- accountNo: z.ZodEffects<z.ZodOptional<z.ZodString>>;
8
- cbaRefNo: z.ZodEffects<z.ZodOptional<z.ZodString>>;
7
+ accountNo: z.ZodString;
9
8
  debitOrCredit: z.ZodString;
10
9
  tranRefNo: z.ZodString;
11
10
  narration: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB;;;GAGG;AACH,KAAK,mBAAmB,GAAG,CAAC,CAAC,SAAS,CAAC;IACrC,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACpD,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACnD,aA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