@temboplus/afloat 0.1.13 → 0.1.30
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.
- package/esm/src/features/auth/access/contract.d.ts +14 -0
- package/esm/src/features/auth/access/contract.d.ts.map +1 -0
- package/esm/src/features/auth/access/contract.js +14 -0
- package/esm/src/features/auth/contract.d.ts +20 -20
- package/esm/src/features/auth/contract.js +2 -2
- package/esm/src/features/auth/identity/contract.d.ts +0 -7
- package/esm/src/features/auth/identity/contract.d.ts.map +1 -1
- package/esm/src/features/auth/identity/contract.js +0 -1
- package/esm/src/features/auth/identity/repository.d.ts +2 -2
- package/esm/src/features/auth/identity/repository.d.ts.map +1 -1
- package/esm/src/features/auth/identity/repository.js +5 -5
- package/esm/src/features/auth/manager.js +1 -1
- package/esm/src/features/auth/profile/contract.d.ts +17 -25
- package/esm/src/features/auth/profile/contract.d.ts.map +1 -1
- package/esm/src/features/auth/profile/contract.js +2 -4
- package/esm/src/features/auth/repository.d.ts +0 -1
- package/esm/src/features/auth/repository.d.ts.map +1 -1
- package/esm/src/features/auth/repository.js +3 -11
- package/esm/src/features/auth/storage/server_token_handler.d.ts +7 -6
- package/esm/src/features/auth/storage/server_token_handler.d.ts.map +1 -1
- package/esm/src/features/auth/storage/server_token_handler.js +73 -26
- package/esm/src/features/contact/contract.d.ts +10 -10
- package/esm/src/features/payout/contract.d.ts +12 -12
- package/esm/src/features/wallet/repository.d.ts +1 -28
- package/esm/src/features/wallet/repository.d.ts.map +1 -1
- package/esm/src/features/wallet/repository.js +0 -51
- package/esm/src/models/contact/derivatives/contact.js +2 -2
- package/esm/src/models/contact/derivatives/contact_info.d.ts +8 -8
- package/esm/src/models/contact/derivatives/contact_info.d.ts.map +1 -1
- package/esm/src/models/contact/derivatives/contact_info.js +12 -12
- package/esm/src/models/payout/channel.d.ts +4 -4
- package/esm/src/models/payout/channel.d.ts.map +1 -1
- package/esm/src/models/payout/channel.js +2 -2
- package/esm/src/models/payout/derivatives/payout.d.ts.map +1 -1
- package/esm/src/models/payout/derivatives/payout.js +2 -2
- package/esm/src/models/user/profile.d.ts +135 -12
- package/esm/src/models/user/profile.d.ts.map +1 -1
- package/esm/src/models/user/profile.js +318 -12
- package/esm/src/models/user/user.d.ts +14 -17
- package/esm/src/models/user/user.d.ts.map +1 -1
- package/esm/src/models/user/user.js +109 -26
- package/esm/src/models/wallet/index.d.ts +0 -1
- package/esm/src/models/wallet/index.d.ts.map +1 -1
- package/esm/src/models/wallet/index.js +0 -1
- package/esm/src/shared/token_required_repository.d.ts +78 -0
- package/esm/src/shared/token_required_repository.d.ts.map +1 -0
- package/esm/src/shared/token_required_repository.js +128 -0
- package/package.json +7 -7
- package/script/src/features/auth/access/contract.d.ts +14 -0
- package/script/src/features/auth/access/contract.d.ts.map +1 -0
- package/script/src/features/auth/access/contract.js +17 -0
- package/script/src/features/auth/contract.d.ts +20 -20
- package/script/src/features/auth/contract.js +1 -1
- package/script/src/features/auth/identity/contract.d.ts +0 -7
- package/script/src/features/auth/identity/contract.d.ts.map +1 -1
- package/script/src/features/auth/identity/contract.js +0 -1
- package/script/src/features/auth/identity/repository.d.ts +2 -2
- package/script/src/features/auth/identity/repository.d.ts.map +1 -1
- package/script/src/features/auth/identity/repository.js +5 -5
- package/script/src/features/auth/manager.js +1 -1
- package/script/src/features/auth/profile/contract.d.ts +17 -25
- package/script/src/features/auth/profile/contract.d.ts.map +1 -1
- package/script/src/features/auth/profile/contract.js +1 -3
- package/script/src/features/auth/repository.d.ts +0 -1
- package/script/src/features/auth/repository.d.ts.map +1 -1
- package/script/src/features/auth/repository.js +3 -11
- package/script/src/features/auth/storage/server_token_handler.d.ts +7 -6
- package/script/src/features/auth/storage/server_token_handler.d.ts.map +1 -1
- package/script/src/features/auth/storage/server_token_handler.js +72 -25
- package/script/src/features/contact/contract.d.ts +10 -10
- package/script/src/features/payout/contract.d.ts +12 -12
- package/script/src/features/wallet/repository.d.ts +1 -28
- package/script/src/features/wallet/repository.d.ts.map +1 -1
- package/script/src/features/wallet/repository.js +0 -51
- package/script/src/models/contact/derivatives/contact.js +1 -1
- package/script/src/models/contact/derivatives/contact_info.d.ts +8 -8
- package/script/src/models/contact/derivatives/contact_info.d.ts.map +1 -1
- package/script/src/models/contact/derivatives/contact_info.js +11 -11
- package/script/src/models/payout/channel.d.ts +4 -4
- package/script/src/models/payout/channel.d.ts.map +1 -1
- package/script/src/models/payout/channel.js +2 -2
- package/script/src/models/payout/derivatives/payout.d.ts.map +1 -1
- package/script/src/models/payout/derivatives/payout.js +1 -1
- package/script/src/models/user/profile.d.ts +135 -12
- package/script/src/models/user/profile.d.ts.map +1 -1
- package/script/src/models/user/profile.js +320 -13
- package/script/src/models/user/user.d.ts +14 -17
- package/script/src/models/user/user.d.ts.map +1 -1
- package/script/src/models/user/user.js +109 -26
- package/script/src/models/wallet/index.d.ts +0 -1
- package/script/src/models/wallet/index.d.ts.map +1 -1
- package/script/src/models/wallet/index.js +0 -1
- package/script/src/shared/token_required_repository.d.ts +78 -0
- package/script/src/shared/token_required_repository.d.ts.map +1 -0
- package/script/src/shared/token_required_repository.js +132 -0
- package/esm/src/features/auth/profile/repository.d.ts +0 -11
- package/esm/src/features/auth/profile/repository.d.ts.map +0 -1
- package/esm/src/features/auth/profile/repository.js +0 -21
- package/esm/src/features/files-gen/contract.d.ts +0 -67
- package/esm/src/features/files-gen/contract.d.ts.map +0 -1
- package/esm/src/features/files-gen/contract.js +0 -40
- package/esm/src/features/files-gen/repository.d.ts +0 -50
- package/esm/src/features/files-gen/repository.d.ts.map +0 -1
- package/esm/src/features/files-gen/repository.js +0 -56
- package/esm/src/models/wallet/statement.d.ts +0 -27
- package/esm/src/models/wallet/statement.d.ts.map +0 -1
- package/esm/src/models/wallet/statement.js +0 -13
- package/script/src/features/auth/profile/repository.d.ts +0 -11
- package/script/src/features/auth/profile/repository.d.ts.map +0 -1
- package/script/src/features/auth/profile/repository.js +0 -25
- package/script/src/features/files-gen/contract.d.ts +0 -67
- package/script/src/features/files-gen/contract.d.ts.map +0 -1
- package/script/src/features/files-gen/contract.js +0 -43
- package/script/src/features/files-gen/repository.d.ts +0 -50
- package/script/src/features/files-gen/repository.d.ts.map +0 -1
- package/script/src/features/files-gen/repository.js +0 -60
- package/script/src/models/wallet/statement.d.ts +0 -27
- package/script/src/models/wallet/statement.d.ts.map +0 -1
- package/script/src/models/wallet/statement.js +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payout.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/payout/derivatives/payout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"payout.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/payout/derivatives/payout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,sBAAsB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG1E;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAElC;;OAEG;IACH,OAAO;IAKP,uCAAuC;IACvC,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,qDAAqD;IACrD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,kCAAkC;IAClC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,2CAA2C;IAC3C,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,+CAA+C;IAC/C,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,wCAAwC;IACxC,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,iDAAiD;IACjD,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAED;;;;;;;;;;;OAWG;IACH,IAAI,MAAM,IAAI,aAAa,CAe1B;IAED,2DAA2D;IAC3D,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,iDAAiD;IACjD,IAAI,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAEzC;IAED,wCAAwC;IACxC,IAAI,SAAS,IAAI,IAAI,CAEpB;IAED,6CAA6C;IAC7C,IAAI,SAAS,IAAI,IAAI,CAEpB;IAED,4CAA4C;IAC5C,IAAI,cAAc,IAAI,sBAAsB,CAE3C;IAED,+CAA+C;IAC/C,IAAI,SAAS,IAAI,cAAc,GAAG,SAAS,CAE1C;IAED,qDAAqD;IACrD,IAAI,UAAU,IAAI,cAAc,GAAG,SAAS,CAE3C;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,IAAI,WAAW,IAAI,WAAW,GAAG,SAAS,CA8BzC;IAED;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAIvC;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE;IAIpD;;;OAGG;WACW,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI;IAQzD;;;;;;;;;;;;;;;;;;;;;OAqBG;WACW,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;IAUvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;IAO7C;;OAEG;IACI,MAAM,IAAI,UAAU;CAG5B"}
|
|
@@ -136,7 +136,7 @@ class Payout {
|
|
|
136
136
|
get contactInfo() {
|
|
137
137
|
let contactInfo;
|
|
138
138
|
// extracting mobile contact information
|
|
139
|
-
const phone = frontend_core_1.
|
|
139
|
+
const phone = frontend_core_1.TZPhoneNumber.from(this.data.msisdn);
|
|
140
140
|
if (phone) {
|
|
141
141
|
contactInfo = new index_js_1.MobileContactInfo(this.data.payeeName, phone);
|
|
142
142
|
}
|
|
@@ -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
|
|
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:
|
|
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
|
-
*
|
|
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
|
|
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;
|
|
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;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;GAGG;AACH,KAAK,oBAAoB,GAAG,CAAC,CAAC,SAAS,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC;IAChB,SAAS,EAAE,CAAC,C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ict";
|
|
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,326 @@ 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()
|
|
21
|
-
firstName: zod_1.z.string().
|
|
22
|
-
lastName: zod_1.z.string().
|
|
23
|
-
displayName: zod_1.z.string()
|
|
24
|
-
phone: zod_1.z.string().
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
phoneObj = frontend_core_1.PhoneNumber.from(data.phone);
|
|
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
|
+
!frontend_core_1.PhoneNumber.is(phone)) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
exports.Profile = Profile;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
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
|
|
41
|
+
* @param userData - An object containing the user's profile, token,
|
|
42
42
|
* permissions (access list), and the `resetPassword` flag.
|
|
43
43
|
*/
|
|
44
|
-
constructor(
|
|
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":"
|
|
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"}
|