@tc-libs/user 0.42.0 → 0.44.0

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/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@tc-libs/user",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
- "@tc-libs/authentication": "0.42.0",
7
- "@tc-libs/service": "0.42.0",
8
- "@tc-libs/database": "0.42.0",
6
+ "@tc-libs/authentication": "0.44.0",
7
+ "@tc-libs/service": "0.44.0",
8
+ "@tc-libs/database": "0.44.0",
9
9
  "@nestjs/common": "^10.0.2"
10
10
  },
11
11
  "type": "commonjs",
@@ -1,6 +1,6 @@
1
1
  import { ENUM_AUTH_ACCESS_FOR } from '@tc-libs/authentication';
2
2
  import { IUserGetSerialization } from './user.get.serialization.interface';
3
- export interface IUserPayloadSerialization extends Omit<IUserGetSerialization, 'Role' | 'role' | 'confirmation' | 'confirmed' | 'agreements' | 'notifications' | 'authProvidersts' | 'active' | 'authProviders' | 'inactiveDate' | 'blocked' | 'createdAt' | 'updatedAt'> {
3
+ export interface IUserPayloadSerialization extends Omit<IUserGetSerialization, 'Role' | 'role' | 'confirmation' | 'flags' | 'agreements' | 'notifications' | 'authProvidersts' | 'authProviders' | 'createdAt' | 'updatedAt'> {
4
4
  rememberMe: boolean;
5
5
  accessFor: ENUM_AUTH_ACCESS_FOR;
6
6
  }
@@ -1,6 +1,29 @@
1
1
  import { IBaseUser } from '../user.base.interface';
2
2
  import { IUserService } from './user.base.service.interface';
3
+ /**
4
+ * Interface representing the administrative services for user management.
5
+ * Extends the basic user service interface.
6
+ */
3
7
  export interface IUserAdminService extends IUserService {
8
+ /**
9
+ * Toggles the confirmation status of a user.
10
+ *
11
+ * @param user - The user whose confirmation status is to be toggled.
12
+ * @returns A promise that resolves to a boolean indicating the success of the operation.
13
+ */
4
14
  toggleConfirm(user: IBaseUser): Promise<boolean>;
5
- toggleBlocked(user: IBaseUser): Promise<boolean>;
15
+ /**
16
+ * Blocks a user.
17
+ *
18
+ * @param user - The user to be blocked.
19
+ * @returns A promise that resolves to the blocked user.
20
+ */
21
+ blocked(user: IBaseUser): Promise<IBaseUser>;
22
+ /**
23
+ * Unblocks a user.
24
+ *
25
+ * @param user - The user to be unblocked.
26
+ * @returns A promise that resolves to the unblocked user.
27
+ */
28
+ unblocked(user: IBaseUser): Promise<IBaseUser>;
6
29
  }
@@ -1,21 +1,66 @@
1
1
  import { IBaseUser } from '../user.base.interface';
2
2
  import { IUserPayloadSerialization } from '../serializations/user.payload.serialization.interface';
3
3
  import { IUserService } from './user.base.service.interface';
4
+ /**
5
+ * Interface representing the user authentication service.
6
+ * Extends the IUserService interface.
7
+ */
4
8
  export interface IUserAuthService extends IUserService {
9
+ /**
10
+ * Serializes the payload data.
11
+ * @param data - The data to be serialized.
12
+ * @returns The serialized user payload.
13
+ */
5
14
  payloadSerialization(data: any): IUserPayloadSerialization;
15
+ /**
16
+ * Signs in a user with the provided credentials.
17
+ * @param email - The email of the user.
18
+ * @param password - The password of the user.
19
+ * @param rememberMe - Whether to remember the user for future sessions.
20
+ * @param ip - The IP address of the user.
21
+ * @param ua - The user agent of the user.
22
+ * @returns A promise that resolves to an object containing token information.
23
+ */
6
24
  signin(email: string, password: string, rememberMe: boolean, ip: string, ua: string): Promise<{
7
25
  tokenType: string;
8
26
  expiresIn: number;
9
27
  accessToken: string;
10
28
  refreshToken: string;
11
29
  }>;
30
+ /**
31
+ * Refreshes the authentication token for a user.
32
+ * @param user - The user object.
33
+ * @param refreshToken - The refresh token.
34
+ * @param rememberMe - Whether to remember the user for future sessions.
35
+ * @param loginDate - The date of the login.
36
+ * @returns A promise that resolves to an object containing token information.
37
+ */
12
38
  refreshToken(user: IBaseUser, refreshToken: string, rememberMe: boolean, loginDate: Date): Promise<{
13
39
  tokenType: string;
14
40
  expiresIn: number;
15
41
  accessToken: string;
16
42
  refreshToken: string;
17
43
  }>;
44
+ /**
45
+ * Signs up a new user with the provided information.
46
+ * @param body - The signup information.
47
+ * @param forceConfirmed - Whether to force the user to be confirmed.
48
+ * @param forceRole - The role to be assigned to the user, if any.
49
+ * @returns A promise that resolves to the signup result.
50
+ */
18
51
  signup(body: any, forceConfirmed: boolean, forceRole: string | null): Promise<any>;
52
+ /**
53
+ * Increases the password attempt count for a user.
54
+ * @param userId - The ID of the user.
55
+ * @returns A promise that resolves when the operation is complete.
56
+ */
19
57
  increasePasswordAttempt(userId: string): Promise<void>;
58
+ /**
59
+ * Updates the login data after a successful signin.
60
+ * @param userId - The ID of the user.
61
+ * @param ip - The IP address of the user.
62
+ * @param ua - The user agent of the user.
63
+ * @returns A promise that resolves when the operation is complete.
64
+ */
20
65
  updateLoginDataAfterSignin(userId: string, ip: string, ua: string): Promise<void>;
21
66
  }
@@ -1,11 +1,45 @@
1
1
  import { IService } from '@tc-libs/service';
2
2
  import { IBaseUser, IUserBirthday } from '../user.base.interface';
3
+ /**
4
+ * Interface representing the user service.
5
+ * Extends the generic IService interface with IBaseUser as the type parameter.
6
+ */
3
7
  export interface IUserService extends IService<IBaseUser> {
8
+ /**
9
+ * Finds a user by their email address.
10
+ *
11
+ * @param email - The email address of the user to find.
12
+ * @returns A promise that resolves to the found user.
13
+ */
4
14
  findByEmail(email: string): Promise<IBaseUser>;
15
+ /**
16
+ * Computes the birthday details of a user.
17
+ *
18
+ * @param day - The day of the month.
19
+ * @param month - The month of the year.
20
+ * @param year - The year.
21
+ * @returns An object representing the user's birthday.
22
+ */
5
23
  computeBDay(day: number, month: number, year: number): IUserBirthday;
6
- active(repository: IBaseUser): Promise<IBaseUser>;
7
- inactive(repository: IBaseUser): Promise<IBaseUser>;
8
- blocked(repository: IBaseUser): Promise<IBaseUser>;
9
- unblocked(repository: IBaseUser): Promise<IBaseUser>;
10
- joinWithRole(repository: IBaseUser): Promise<IBaseUser>;
24
+ /**
25
+ * Marks a user as inactive.
26
+ *
27
+ * @param user - The user to mark as inactive.
28
+ * @returns A promise that resolves to the updated user.
29
+ */
30
+ inactive(user: IBaseUser): Promise<IBaseUser>;
31
+ /**
32
+ * Marks a user as active.
33
+ *
34
+ * @param user - The user to mark as active.
35
+ * @returns A promise that resolves to the updated user.
36
+ */
37
+ active(user: IBaseUser): Promise<IBaseUser>;
38
+ /**
39
+ * Joins a user with their role.
40
+ *
41
+ * @param user - The user to join with a role.
42
+ * @returns A promise that resolves to the updated user.
43
+ */
44
+ joinWithRole(user: IBaseUser): Promise<IBaseUser>;
11
45
  }
@@ -1,9 +1,38 @@
1
1
  import { IUserConfirmResendSerialization, IUserConfirmSerialization } from '../serializations/user.confirm.serialization.interface';
2
2
  import { IBaseUser } from '../user.base.interface';
3
3
  import { IUserService } from './user.base.service.interface';
4
+ /**
5
+ * Interface representing the user confirmation service.
6
+ * Extends the base user service interface.
7
+ */
4
8
  export interface IUserConfirmService extends IUserService {
9
+ /**
10
+ * Resets the confirmation code for a given email.
11
+ *
12
+ * @param email - The email address for which to reset the confirmation code.
13
+ * @returns A promise that resolves to the new confirmation code as a string.
14
+ */
5
15
  resetConfirmCode(email: string): Promise<string>;
16
+ /**
17
+ * Resends the confirmation details to the user.
18
+ *
19
+ * @param user - The user object containing the necessary information.
20
+ * @returns A promise that resolves to the serialization of the resend confirmation response.
21
+ */
6
22
  resendConfirm(user: IBaseUser): Promise<IUserConfirmResendSerialization>;
23
+ /**
24
+ * Retrieves a user by their email and confirmation code.
25
+ *
26
+ * @param email - The email address of the user.
27
+ * @param uuid - The confirmation code associated with the user.
28
+ * @returns A promise that resolves to the base user object.
29
+ */
7
30
  getUserByEmailAndConfirmCode(email: string, uuid: string): Promise<IBaseUser>;
31
+ /**
32
+ * Confirms the user.
33
+ *
34
+ * @param user - The user object to be confirmed.
35
+ * @returns A promise that resolves to the serialization of the confirmation response.
36
+ */
8
37
  confirm(user: IBaseUser): Promise<IUserConfirmSerialization>;
9
38
  }
@@ -2,8 +2,31 @@ import { IUserResetPasswordDto } from '../dtos/user.reset-password.dto.interface
2
2
  import { IUserResetPasswordConfirmSerialization, IUserResetPasswordSerialization } from '../serializations/user.reset-password.serialization.interface';
3
3
  import { IBaseUser } from '../user.base.interface';
4
4
  import { IUserService } from './user.base.service.interface';
5
+ /**
6
+ * Interface representing the user reset password service.
7
+ * Extends the base user service interface.
8
+ */
5
9
  export interface IUserResetPasswordService extends IUserService {
10
+ /**
11
+ * Retrieves a user by their email and reset confirmation code.
12
+ *
13
+ * @param email - The email of the user.
14
+ * @param uuid - The reset confirmation code.
15
+ * @returns A promise that resolves to the base user object.
16
+ */
6
17
  getUserByEmailAndResetConfirmCode(email: string, uuid: string): Promise<IBaseUser>;
18
+ /**
19
+ * Resets the user's password.
20
+ *
21
+ * @param resetPasswordDto - The data transfer object containing the reset password information.
22
+ * @returns A promise that resolves to the reset password serialization object.
23
+ */
7
24
  resetPassword(resetPasswordDto: IUserResetPasswordDto): Promise<IUserResetPasswordSerialization>;
25
+ /**
26
+ * Confirms the user's password reset.
27
+ *
28
+ * @param user - The base user object.
29
+ * @returns A promise that resolves to the reset password confirmation serialization object.
30
+ */
8
31
  confirmResetPassword(user: IBaseUser): Promise<IUserResetPasswordConfirmSerialization>;
9
32
  }
@@ -11,45 +11,116 @@ export declare enum AUTH_PROVIDERS {
11
11
  MI = "microsoft",
12
12
  PP = "paypal"
13
13
  }
14
+ /**
15
+ * Interface representing the acceptance of a flag.
16
+ *
17
+ * @interface IFlagAcceptance
18
+ *
19
+ * @property {boolean} enabled - Indicates whether the flag is enabled.
20
+ * @property {Date} ts - The timestamp when the flag was accepted.
21
+ * @property {string} version - The version of the flag acceptance.
22
+ */
14
23
  export interface IFlagAcceptance {
15
24
  enabled: boolean;
16
25
  ts: Date;
17
26
  version: string;
18
27
  }
28
+ /**
29
+ * Interface representing user notifications settings.
30
+ * @property {IFlagAcceptance} newsletter - User's acceptance of newsletter.
31
+ */
19
32
  export interface IUserNotifications {
20
33
  newsletter: IFlagAcceptance;
21
34
  }
35
+ /**
36
+ * Interface representing user agreements.
37
+ *
38
+ * @interface IUserAgreements
39
+ *
40
+ * @property {IFlagAcceptance} terms - User's acceptance of the terms and conditions.
41
+ * @property {IFlagAcceptance} privacy - User's acceptance of the privacy policy.
42
+ * @property {IFlagAcceptance} commercial - User's acceptance of commercial communications.
43
+ */
22
44
  export interface IUserAgreements {
23
45
  terms: IFlagAcceptance;
24
46
  privacy: IFlagAcceptance;
25
47
  commercial: IFlagAcceptance;
26
48
  }
27
49
  export interface IUserBirthday {
28
- day: number;
29
- month: number;
30
- year: number;
31
- date: Date;
50
+ day?: number;
51
+ month?: number;
52
+ year?: number;
53
+ date?: Date;
32
54
  }
55
+ /**
56
+ * Interface representing the structure of user reset password details.
57
+ *
58
+ * @interface IUserResetPassword
59
+ *
60
+ * @property {string} [code] - The reset password code.
61
+ * @property {string} [tmpPassword] - The temporary password assigned to the user.
62
+ * @property {Date} [ts] - The timestamp when the reset password was requested.
63
+ */
33
64
  export interface IUserResetPassword {
34
- code: string;
35
- tmpPassword: string;
36
- ts: Date;
65
+ code?: string;
66
+ tmpPassword?: string;
67
+ ts?: Date;
37
68
  }
69
+ /**
70
+ * Interface representing the history of user passwords.
71
+ *
72
+ * @interface IUserPasswordHistory
73
+ *
74
+ * @property {string} password - The user's previous password.
75
+ * @property {Date} ts - The timestamp when the password was changed.
76
+ */
38
77
  export interface IUserPasswordHistory {
39
78
  password: string;
40
79
  ts: Date;
41
80
  }
81
+ /**
82
+ * Interface representing the structure of user email confirmation details.
83
+ * @interface IUserEmailConfirmation
84
+ * @property {string} [code] - The confirmation code.
85
+ * @property {Date} [ts] - The timestamp of the confirmation code.
86
+ */
42
87
  export interface IUserEmailConfirmation {
43
88
  code?: string;
44
89
  ts?: Date;
45
90
  }
91
+ /**
92
+ * Interface representing user login information.
93
+ *
94
+ * @interface IUserLoginInfo
95
+ *
96
+ * @property {number} attempt - The number of unsuccessful login attempts made by the user.
97
+ * @property {number} count - The count of successful logins.
98
+ * @property {string} [ip] - The IP address from which the user attempted to log in.
99
+ * @property {string} [ua] - The user agent string of the browser or device used for login.
100
+ * @property {Date} [lastLogin] - The date and time of the last successful login.
101
+ */
46
102
  export interface IUserLoginInfo {
47
103
  attempt: number;
48
104
  count: number;
49
- ip: string;
50
- ua: string;
51
- lastLogin: Date;
105
+ ip?: string;
106
+ ua?: string;
107
+ lastLogin?: Date;
52
108
  }
109
+ /**
110
+ * Interface representing a user's social media information.
111
+ *
112
+ * @interface IUserSocialInfo
113
+ *
114
+ * @property {string} facebookId - The user's Facebook ID.
115
+ * @property {string} twitterId - The user's Twitter ID.
116
+ * @property {string} githubId - The user's GitHub ID.
117
+ * @property {string} linkedinId - The user's LinkedIn ID.
118
+ * @property {string} amazonId - The user's Amazon ID.
119
+ * @property {string} googleId - The user's Google ID.
120
+ * @property {string} bitbucketId - The user's Bitbucket ID.
121
+ * @property {string} microsoftId - The user's Microsoft ID.
122
+ * @property {string} paypalId - The user's PayPal ID.
123
+ */
53
124
  export interface IUserSocialInfo {
54
125
  facebookId: string;
55
126
  twitterId: string;
@@ -61,6 +132,46 @@ export interface IUserSocialInfo {
61
132
  microsoftId: string;
62
133
  paypalId: string;
63
134
  }
135
+ /**
136
+ * Interface representing the flags associated with a user.
137
+ *
138
+ * @property {boolean} confirmed - Indicates if the user has confirmed their account by the email.
139
+ * @property {boolean} [iddqd] - Optional flag for a special status (e.g., god mode).
140
+ * @property {boolean} blocked - Indicates if the user is blocked by admin.
141
+ * @property {Date} [blockedDate] - Optional date when the user was blocked.
142
+ * @property {boolean} active - Indicates if the user is inactivated by itself.
143
+ * @property {Date} [inactiveDate] - Optional date when the user became inactivated by itself.
144
+ */
145
+ export interface IUserFlags {
146
+ confirmed: boolean;
147
+ iddqd?: boolean;
148
+ blocked: boolean;
149
+ blockedDate?: Date;
150
+ active: boolean;
151
+ inactiveDate?: Date;
152
+ }
153
+ /**
154
+ * Interface representing the base structure of a user entity.
155
+ *
156
+ * @extends IDatabaseMongoBaseEntityAbstract
157
+ *
158
+ * @property {string} email - The email address of the user.
159
+ * @property {string} password - The password of the user.
160
+ * @property {string} role - The role assigned to the user.
161
+ * @property {string} [firstName] - The first name of the user.
162
+ * @property {string} [lastName] - The last name of the user.
163
+ * @property {string} [lang] - The preferred language of the user.
164
+ * @property {IUserFlags} flags - The flags associated with the user.
165
+ * @property {IUserResetPassword} [resetPassword] - Information related to password reset.
166
+ * @property {IUserEmailConfirmation} confirmation - Information related to email confirmation.
167
+ * @property {IUserPasswordHistory[]} [passwordHistory] - History of the user's passwords.
168
+ * @property {IUserLoginInfo} [login] - Information related to user login attempts.
169
+ * @property {IUserSocialInfo} [social] - Information related to user's social media accounts.
170
+ * @property {IUserAgreements} agreements - User's acceptance of various agreements.
171
+ * @property {IUserNotifications} notifications - User's notification preferences.
172
+ * @property {IUserBirthday} [birthday] - User's birthday information.
173
+ * @property {string[]} authProviders - List of authentication providers associated with the user.
174
+ */
64
175
  export interface IBaseUser extends IDatabaseMongoBaseEntityAbstract {
65
176
  email: string;
66
177
  password: string;
@@ -68,12 +179,7 @@ export interface IBaseUser extends IDatabaseMongoBaseEntityAbstract {
68
179
  firstName?: string;
69
180
  lastName?: string;
70
181
  lang?: string;
71
- iddqd?: boolean;
72
- confirmed: boolean;
73
- blocked: boolean;
74
- blockedDate?: Date;
75
- active: boolean;
76
- inactiveDate?: Date;
182
+ flags: IUserFlags;
77
183
  resetPassword?: IUserResetPassword;
78
184
  confirmation: IUserEmailConfirmation;
79
185
  passwordHistory?: IUserPasswordHistory[];