@solidstarters/solid-core 1.2.143 → 1.2.145
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/dist/config/common.config.d.ts +2 -0
- package/dist/config/common.config.d.ts.map +1 -1
- package/dist/config/common.config.js +3 -2
- package/dist/config/common.config.js.map +1 -1
- package/dist/constants/error-messages.d.ts +83 -0
- package/dist/constants/error-messages.d.ts.map +1 -0
- package/dist/constants/error-messages.js +86 -0
- package/dist/constants/error-messages.js.map +1 -0
- package/dist/constants/success-messages.d.ts +11 -0
- package/dist/constants/success-messages.d.ts.map +1 -0
- package/dist/constants/success-messages.js +14 -0
- package/dist/constants/success-messages.js.map +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/jobs/api-email-subscriber.service.d.ts +1 -1
- package/dist/jobs/api-email-subscriber.service.d.ts.map +1 -1
- package/dist/jobs/api-email-subscriber.service.js +2 -2
- package/dist/jobs/api-email-subscriber.service.js.map +1 -1
- package/dist/jobs/database/api-email-subscriber-database.service.d.ts +1 -1
- package/dist/jobs/database/api-email-subscriber-database.service.d.ts.map +1 -1
- package/dist/jobs/database/api-email-subscriber-database.service.js +2 -2
- package/dist/jobs/database/api-email-subscriber-database.service.js.map +1 -1
- package/dist/jobs/database/email-subscriber-database.service.d.ts +1 -1
- package/dist/jobs/database/email-subscriber-database.service.d.ts.map +1 -1
- package/dist/jobs/database/email-subscriber-database.service.js +2 -2
- package/dist/jobs/database/email-subscriber-database.service.js.map +1 -1
- package/dist/jobs/email-subscriber.service.d.ts +1 -1
- package/dist/jobs/email-subscriber.service.d.ts.map +1 -1
- package/dist/jobs/email-subscriber.service.js +2 -2
- package/dist/jobs/email-subscriber.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +12 -12
- package/dist/services/ai-interaction.service.d.ts.map +1 -1
- package/dist/services/ai-interaction.service.js +4 -3
- package/dist/services/ai-interaction.service.js.map +1 -1
- package/dist/services/authentication.service.d.ts +1 -1
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +68 -66
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/crud-helper.service.d.ts.map +1 -1
- package/dist/services/crud-helper.service.js +3 -2
- package/dist/services/crud-helper.service.js.map +1 -1
- package/dist/services/crud.service.d.ts.map +1 -1
- package/dist/services/crud.service.js +23 -21
- package/dist/services/crud.service.js.map +1 -1
- package/dist/services/csv.service.d.ts.map +1 -1
- package/dist/services/csv.service.js +3 -2
- package/dist/services/csv.service.js.map +1 -1
- package/dist/services/excel.service.d.ts.map +1 -1
- package/dist/services/excel.service.js +3 -2
- package/dist/services/excel.service.js.map +1 -1
- package/dist/services/export-transaction.service.d.ts.map +1 -1
- package/dist/services/export-transaction.service.js +2 -1
- package/dist/services/export-transaction.service.js.map +1 -1
- package/dist/services/field-metadata.service.d.ts.map +1 -1
- package/dist/services/field-metadata.service.js +9 -8
- package/dist/services/field-metadata.service.js.map +1 -1
- package/dist/services/file.service.d.ts.map +1 -1
- package/dist/services/file.service.js +5 -4
- package/dist/services/file.service.js.map +1 -1
- package/dist/services/import-transaction.service.d.ts.map +1 -1
- package/dist/services/import-transaction.service.js +11 -9
- package/dist/services/import-transaction.service.js.map +1 -1
- package/dist/services/mail/{ElasticEmailService.d.ts → elastic-email.service.d.ts} +1 -1
- package/dist/services/mail/elastic-email.service.d.ts.map +1 -0
- package/dist/services/mail/{ElasticEmailService.js → elastic-email.service.js} +1 -1
- package/dist/services/mail/elastic-email.service.js.map +1 -0
- package/dist/services/mail/{SMTPEmailService.d.ts → smtp-email.service.d.ts} +3 -3
- package/dist/services/mail/smtp-email.service.d.ts.map +1 -0
- package/dist/services/mail/{SMTPEmailService.js → smtp-email.service.js} +8 -6
- package/dist/services/mail/smtp-email.service.js.map +1 -0
- package/dist/services/media-storage-provider-metadata.service.d.ts.map +1 -1
- package/dist/services/media-storage-provider-metadata.service.js +4 -3
- package/dist/services/media-storage-provider-metadata.service.js.map +1 -1
- package/dist/services/media.service.d.ts.map +1 -1
- package/dist/services/media.service.js +2 -1
- package/dist/services/media.service.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +11 -10
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/module-metadata.service.d.ts.map +1 -1
- package/dist/services/module-metadata.service.js +11 -10
- package/dist/services/module-metadata.service.js.map +1 -1
- package/dist/services/role-metadata.service.d.ts.map +1 -1
- package/dist/services/role-metadata.service.js +3 -2
- package/dist/services/role-metadata.service.js.map +1 -1
- package/dist/services/sql-expression-resolver.service.d.ts.map +1 -1
- package/dist/services/sql-expression-resolver.service.js +2 -1
- package/dist/services/sql-expression-resolver.service.js.map +1 -1
- package/dist/services/user.service.d.ts.map +1 -1
- package/dist/services/user.service.js +11 -10
- package/dist/services/user.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +9 -7
- package/dist/solid-core.module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/config/common.config.ts +3 -2
- package/src/constants/error-messages.ts +123 -0
- package/src/constants/success-messages.ts +13 -0
- package/src/index.ts +10 -4
- package/src/interfaces.ts +3 -3
- package/src/jobs/api-email-subscriber.service.ts +1 -1
- package/src/jobs/database/api-email-subscriber-database.service.ts +1 -1
- package/src/jobs/database/email-subscriber-database.service.ts +1 -1
- package/src/jobs/email-subscriber.service.ts +1 -1
- package/src/seeders/seed-data/solid-core-metadata.json +12 -12
- package/src/services/ai-interaction.service.ts +4 -3
- package/src/services/authentication.service.ts +67 -65
- package/src/services/crud-helper.service.ts +3 -2
- package/src/services/crud.service.ts +23 -23
- package/src/services/csv.service.ts +3 -2
- package/src/services/excel.service.ts +3 -2
- package/src/services/export-transaction.service.ts +2 -1
- package/src/services/field-metadata.service.ts +9 -8
- package/src/services/file.service.ts +5 -4
- package/src/services/import-transaction.service.ts +11 -9
- package/src/services/mail/{SMTPEmailService.ts → smtp-email.service.ts} +7 -5
- package/src/services/media-storage-provider-metadata.service.ts +4 -3
- package/src/services/media.service.ts +2 -1
- package/src/services/model-metadata.service.ts +11 -10
- package/src/services/module-metadata.service.ts +11 -10
- package/src/services/role-metadata.service.ts +3 -2
- package/src/services/sql-expression-resolver.service.ts +2 -1
- package/src/services/user.service.ts +11 -10
- package/src/solid-core.module.ts +5 -3
- package/dist/services/mail/ElasticEmailService.d.ts.map +0 -1
- package/dist/services/mail/ElasticEmailService.js.map +0 -1
- package/dist/services/mail/SMTPEmailService.d.ts.map +0 -1
- package/dist/services/mail/SMTPEmailService.js.map +0 -1
- /package/src/services/mail/{ElasticEmailService.ts → elastic-email.service.ts} +0 -0
|
@@ -24,7 +24,7 @@ const jwt_1 = require("@nestjs/jwt");
|
|
|
24
24
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
25
25
|
const class_validator_1 = require("class-validator");
|
|
26
26
|
const crypto_1 = require("crypto");
|
|
27
|
-
const
|
|
27
|
+
const smtp_email_service_1 = require("./mail/smtp-email.service");
|
|
28
28
|
const Msg91OTPService_1 = require("./sms/Msg91OTPService");
|
|
29
29
|
const typeorm_2 = require("typeorm");
|
|
30
30
|
const iam_config_1 = require("../config/iam.config");
|
|
@@ -40,6 +40,8 @@ const role_metadata_service_1 = require("./role-metadata.service");
|
|
|
40
40
|
const common_config_1 = __importDefault(require("../config/common.config"));
|
|
41
41
|
const user_activity_history_service_1 = require("./user-activity-history.service");
|
|
42
42
|
const request_context_service_1 = require("./request-context.service");
|
|
43
|
+
const error_messages_1 = require("../constants/error-messages");
|
|
44
|
+
const success_messages_1 = require("../constants/success-messages");
|
|
43
45
|
var LoginProvider;
|
|
44
46
|
(function (LoginProvider) {
|
|
45
47
|
LoginProvider["LOCAL"] = "local";
|
|
@@ -87,20 +89,20 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
87
89
|
async validateUser(signInDto) {
|
|
88
90
|
const user = await this.resolveUser(signInDto.username, signInDto.email);
|
|
89
91
|
if (!user) {
|
|
90
|
-
throw new common_1.UnauthorizedException(
|
|
92
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
91
93
|
}
|
|
92
94
|
if (!user.active) {
|
|
93
|
-
throw new common_1.UnauthorizedException(
|
|
95
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_ACTIVE);
|
|
94
96
|
}
|
|
95
97
|
const isEqual = await this.hashingService.compare(signInDto.password, user.password);
|
|
96
98
|
if (!isEqual) {
|
|
97
|
-
throw new common_1.UnauthorizedException(
|
|
99
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.PASSWORD_INCORRECT);
|
|
98
100
|
}
|
|
99
101
|
return user;
|
|
100
102
|
}
|
|
101
103
|
async signUp(signUpDto, activeUser = null) {
|
|
102
104
|
if (!(await this.settingService.getConfigValue('allowPublicRegistration')) && !activeUser) {
|
|
103
|
-
throw new common_1.BadRequestException(
|
|
105
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PUBLIC_REGISTRATION_DISABLED);
|
|
104
106
|
}
|
|
105
107
|
try {
|
|
106
108
|
const onForcePasswordChange = await this.getConfig('forceChangePasswordOnFirstLogin');
|
|
@@ -116,7 +118,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
116
118
|
catch (err) {
|
|
117
119
|
const pgUniqueViolationErrorCode = '23505';
|
|
118
120
|
if (err.code === pgUniqueViolationErrorCode) {
|
|
119
|
-
throw new common_1.ConflictException();
|
|
121
|
+
throw new common_1.ConflictException(error_messages_1.ERROR_MESSAGES.USER_ALREADY_EXISTS);
|
|
120
122
|
}
|
|
121
123
|
throw err;
|
|
122
124
|
}
|
|
@@ -133,7 +135,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
133
135
|
catch (err) {
|
|
134
136
|
const pgUniqueViolationErrorCode = '23505';
|
|
135
137
|
if (err.code === pgUniqueViolationErrorCode) {
|
|
136
|
-
throw new common_1.ConflictException(parseUniqueConstraintError(err.detail ||
|
|
138
|
+
throw new common_1.ConflictException(parseUniqueConstraintError(err.detail || error_messages_1.ERROR_MESSAGES.UNIQUE_CONSTRAINT_VIOLATION));
|
|
137
139
|
}
|
|
138
140
|
throw err;
|
|
139
141
|
}
|
|
@@ -206,16 +208,16 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
206
208
|
async otpInitiateRegistration(signUpDto) {
|
|
207
209
|
try {
|
|
208
210
|
if (!this.isPasswordlessRegistrationEnabled()) {
|
|
209
|
-
throw new common_1.BadRequestException(
|
|
211
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
210
212
|
}
|
|
211
213
|
if ((0, class_validator_1.isEmpty)(signUpDto.mobile) && (0, class_validator_1.isEmpty)(signUpDto.email)) {
|
|
212
|
-
throw new common_1.BadRequestException(
|
|
214
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.REGISTRATION_REQUIRES_CONTACT);
|
|
213
215
|
}
|
|
214
216
|
if (signUpDto.validationSources.includes(constants_1.TransactionalRegistrationValidationSource.EMAIL) && (0, class_validator_1.isEmpty)(signUpDto.email)) {
|
|
215
|
-
throw new common_1.BadRequestException(
|
|
217
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.EMAIL_REQUIRED_FOR_VALIDATION);
|
|
216
218
|
}
|
|
217
219
|
if (signUpDto.validationSources.includes(constants_1.TransactionalRegistrationValidationSource.MOBILE) && (0, class_validator_1.isEmpty)(signUpDto.mobile)) {
|
|
218
|
-
throw new common_1.BadRequestException(
|
|
220
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.MOBILE_REQUIRED_FOR_VALIDATION);
|
|
219
221
|
}
|
|
220
222
|
const existingUser = await this.userRepository.findOne({
|
|
221
223
|
where: [
|
|
@@ -225,7 +227,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
225
227
|
]
|
|
226
228
|
});
|
|
227
229
|
if ((0, class_validator_1.isNotEmpty)(existingUser) && existingUser.active) {
|
|
228
|
-
throw new common_1.ConflictException(
|
|
230
|
+
throw new common_1.ConflictException(error_messages_1.ERROR_MESSAGES.USER_ALREADY_EXISTS);
|
|
229
231
|
}
|
|
230
232
|
const finalRegistrationVerificationSources = this.calculateVerificationSources(this.iamConfiguration.passwordlessRegistrationValidateWhat, signUpDto);
|
|
231
233
|
let user = existingUser;
|
|
@@ -240,12 +242,12 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
240
242
|
await this.userRepository.save(user);
|
|
241
243
|
}
|
|
242
244
|
this.notifyUserOnOtpInitiateRegistration(user, finalRegistrationVerificationSources);
|
|
243
|
-
return { message:
|
|
245
|
+
return { message: success_messages_1.SUCCESS_MESSAGES.OTP_SENT_SUCCESS_REGISTRATION };
|
|
244
246
|
}
|
|
245
247
|
catch (err) {
|
|
246
248
|
const pgUniqueViolationErrorCode = '23505';
|
|
247
249
|
if (err.code === pgUniqueViolationErrorCode) {
|
|
248
|
-
throw new common_1.ConflictException();
|
|
250
|
+
throw new common_1.ConflictException(error_messages_1.ERROR_MESSAGES.USER_ALREADY_EXISTS);
|
|
249
251
|
}
|
|
250
252
|
throw err;
|
|
251
253
|
}
|
|
@@ -268,7 +270,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
268
270
|
}
|
|
269
271
|
populateVerificationTokens(finalRegistrationValidationSources, user) {
|
|
270
272
|
if (finalRegistrationValidationSources.length === 0) {
|
|
271
|
-
throw new common_1.BadRequestException(
|
|
273
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.VALIDATION_SOURCE_REQUIRED);
|
|
272
274
|
}
|
|
273
275
|
if (finalRegistrationValidationSources.includes(constants_1.TransactionalRegistrationValidationSource.EMAIL)) {
|
|
274
276
|
const { token, expiresAt } = this.otp();
|
|
@@ -316,7 +318,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
316
318
|
}
|
|
317
319
|
async otpConfirmRegistration(confirmSignUpDto) {
|
|
318
320
|
if (!this.isPasswordlessRegistrationEnabled()) {
|
|
319
|
-
throw new common_1.BadRequestException(
|
|
321
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
320
322
|
}
|
|
321
323
|
if (confirmSignUpDto.type === constants_1.RegistrationValidationSource.EMAIL) {
|
|
322
324
|
const user = await this.userRepository.findOne({
|
|
@@ -325,13 +327,13 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
325
327
|
}
|
|
326
328
|
});
|
|
327
329
|
if (!user) {
|
|
328
|
-
throw new common_1.UnauthorizedException(
|
|
330
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
329
331
|
}
|
|
330
332
|
if (user.emailVerificationTokenOnRegistration !== confirmSignUpDto.otp) {
|
|
331
|
-
throw new common_1.UnauthorizedException(
|
|
333
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
332
334
|
}
|
|
333
335
|
if (user.emailVerificationTokenOnRegistrationExpiresAt < new Date()) {
|
|
334
|
-
throw new common_1.UnauthorizedException(
|
|
336
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.OTP_EXPIRED);
|
|
335
337
|
}
|
|
336
338
|
user.emailVerifiedOnRegistrationAt = new Date();
|
|
337
339
|
user.emailVerificationTokenOnRegistration = null;
|
|
@@ -348,13 +350,13 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
348
350
|
}
|
|
349
351
|
});
|
|
350
352
|
if (!user) {
|
|
351
|
-
throw new common_1.UnauthorizedException(
|
|
353
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
352
354
|
}
|
|
353
355
|
if (user.mobileVerificationTokenOnRegistration !== confirmSignUpDto.otp) {
|
|
354
|
-
throw new common_1.UnauthorizedException(
|
|
356
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
355
357
|
}
|
|
356
358
|
if (user.mobileVerificationTokenOnRegistrationExpiresAt < new Date()) {
|
|
357
|
-
throw new common_1.UnauthorizedException(
|
|
359
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
358
360
|
}
|
|
359
361
|
user.mobileVerifiedOnRegistrationAt = new Date();
|
|
360
362
|
user.mobileVerificationTokenOnRegistration = null;
|
|
@@ -364,7 +366,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
364
366
|
this.triggerRegistrationEvent(savedUser);
|
|
365
367
|
return { active: savedUser.active, message: `User registration verified for ${confirmSignUpDto.type}` };
|
|
366
368
|
}
|
|
367
|
-
throw new common_1.BadRequestException(
|
|
369
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
368
370
|
}
|
|
369
371
|
triggerRegistrationEvent(savedUser) {
|
|
370
372
|
const event = new interfaces_1.EventDetails(interfaces_1.EventType.USER_REGISTERED, savedUser);
|
|
@@ -410,7 +412,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
410
412
|
}
|
|
411
413
|
async otpInitiateLogin(signInDto) {
|
|
412
414
|
if (!this.isPasswordlessRegistrationEnabled()) {
|
|
413
|
-
throw new common_1.BadRequestException(
|
|
415
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
414
416
|
}
|
|
415
417
|
if (signInDto.type === constants_1.RegistrationValidationSource.EMAIL) {
|
|
416
418
|
const user = await this.userRepository.findOne({
|
|
@@ -419,10 +421,10 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
419
421
|
}
|
|
420
422
|
});
|
|
421
423
|
if (!user) {
|
|
422
|
-
throw new common_1.UnauthorizedException(
|
|
424
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
423
425
|
}
|
|
424
426
|
if (!user.active) {
|
|
425
|
-
throw new common_1.UnauthorizedException(
|
|
427
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
426
428
|
}
|
|
427
429
|
const { token, expiresAt } = this.otp();
|
|
428
430
|
user.emailVerificationTokenOnLogin = token;
|
|
@@ -437,7 +439,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
437
439
|
}
|
|
438
440
|
});
|
|
439
441
|
if (!user) {
|
|
440
|
-
throw new common_1.UnauthorizedException(
|
|
442
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
441
443
|
}
|
|
442
444
|
const { token, expiresAt } = this.otp();
|
|
443
445
|
user.mobileVerificationTokenOnLogin = token;
|
|
@@ -446,9 +448,9 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
446
448
|
this.notifyUserOnOtpInititateLogin(user, constants_1.RegistrationValidationSource.MOBILE);
|
|
447
449
|
}
|
|
448
450
|
else {
|
|
449
|
-
throw new common_1.BadRequestException(
|
|
451
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
450
452
|
}
|
|
451
|
-
return { message:
|
|
453
|
+
return { message: success_messages_1.SUCCESS_MESSAGES.OTP_SENT_SUCCESS_LOGIN };
|
|
452
454
|
}
|
|
453
455
|
async notifyUserOnOtpInititateLogin(user, loginType) {
|
|
454
456
|
const companyLogo = await this.getCompanyLogo();
|
|
@@ -477,7 +479,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
477
479
|
}
|
|
478
480
|
async otpConfirmLogin(confirmSignInDto) {
|
|
479
481
|
if (!this.isPasswordlessRegistrationEnabled()) {
|
|
480
|
-
throw new common_1.BadRequestException(
|
|
482
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
481
483
|
}
|
|
482
484
|
if (confirmSignInDto.type === constants_1.RegistrationValidationSource.EMAIL) {
|
|
483
485
|
const user = await this.userRepository.findOne({
|
|
@@ -487,16 +489,16 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
487
489
|
relations: ['roles']
|
|
488
490
|
});
|
|
489
491
|
if (!user) {
|
|
490
|
-
throw new common_1.UnauthorizedException(
|
|
492
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
491
493
|
}
|
|
492
494
|
if (!user.active) {
|
|
493
|
-
throw new common_1.UnauthorizedException(
|
|
495
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
494
496
|
}
|
|
495
497
|
if (user.emailVerificationTokenOnLogin !== confirmSignInDto.otp) {
|
|
496
|
-
throw new common_1.UnauthorizedException(
|
|
498
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
497
499
|
}
|
|
498
500
|
if (user.emailVerificationTokenOnLoginExpiresAt < new Date()) {
|
|
499
|
-
throw new common_1.UnauthorizedException(
|
|
501
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
500
502
|
}
|
|
501
503
|
user.emailVerifiedOnLoginAt = new Date();
|
|
502
504
|
user.emailVerificationTokenOnLogin = null;
|
|
@@ -515,16 +517,16 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
515
517
|
relations: ['roles']
|
|
516
518
|
});
|
|
517
519
|
if (!user) {
|
|
518
|
-
throw new common_1.UnauthorizedException(
|
|
520
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_ACTIVE);
|
|
519
521
|
}
|
|
520
522
|
if (!user.active) {
|
|
521
|
-
throw new common_1.UnauthorizedException(
|
|
523
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
522
524
|
}
|
|
523
525
|
if (user.mobileVerificationTokenOnLogin !== confirmSignInDto.otp) {
|
|
524
|
-
throw new common_1.UnauthorizedException(
|
|
526
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
525
527
|
}
|
|
526
528
|
if (user.mobileVerificationTokenOnLoginExpiresAt < new Date()) {
|
|
527
|
-
throw new common_1.UnauthorizedException(
|
|
529
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
528
530
|
}
|
|
529
531
|
user.mobileVerifiedOnLoginAt = new Date();
|
|
530
532
|
user.mobileVerificationTokenOnLogin = null;
|
|
@@ -535,36 +537,36 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
535
537
|
const roles = user.roles.map((role) => role.name);
|
|
536
538
|
return { accessToken, refreshToken, user: { id, username, email, mobile, lastLoginProvider, roles } };
|
|
537
539
|
}
|
|
538
|
-
throw new common_1.BadRequestException(
|
|
540
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
539
541
|
}
|
|
540
542
|
async changePassword(changePasswordDto, activeUser) {
|
|
541
543
|
const user = await this.userRepository.findOne({
|
|
542
544
|
where: { id: changePasswordDto.id }
|
|
543
545
|
});
|
|
544
546
|
if (!user) {
|
|
545
|
-
throw new common_1.NotFoundException(
|
|
547
|
+
throw new common_1.NotFoundException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
546
548
|
}
|
|
547
549
|
if (!user.active) {
|
|
548
|
-
throw new common_1.UnauthorizedException(
|
|
550
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
549
551
|
}
|
|
550
552
|
if (user.lastLoginProvider !== 'local') {
|
|
551
|
-
throw new common_1.BadRequestException(
|
|
553
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.NON_LOCAL_PROVIDER);
|
|
552
554
|
}
|
|
553
555
|
if (!(user.id === activeUser.sub)) {
|
|
554
|
-
throw new common_1.BadRequestException(
|
|
556
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.USER_ID_MISMATCH);
|
|
555
557
|
}
|
|
556
558
|
if (!(user.username === activeUser.username)) {
|
|
557
|
-
throw new common_1.BadRequestException(
|
|
559
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.USERNAME_MISMATCH);
|
|
558
560
|
}
|
|
559
561
|
const isEqual = await this.hashingService.compare(changePasswordDto.currentPassword, user.password);
|
|
560
562
|
if (!isEqual) {
|
|
561
|
-
throw new common_1.UnauthorizedException(
|
|
563
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INCORRECT_CURRENT_PASSWORD);
|
|
562
564
|
}
|
|
563
565
|
const newPwd = await this.hashingService.hash(changePasswordDto.newPassword);
|
|
564
566
|
user.password = changePasswordDto.newPassword;
|
|
565
567
|
user.forcePasswordChange = false;
|
|
566
568
|
if (await this.isPasswordDuplicate(user)) {
|
|
567
|
-
throw new common_1.BadRequestException(
|
|
569
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORD_REUSED);
|
|
568
570
|
}
|
|
569
571
|
await this.deleteOldPasswords(user);
|
|
570
572
|
user.password = newPwd;
|
|
@@ -578,13 +580,13 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
578
580
|
async initiateForgotPassword(initiateForgotPasswordDto) {
|
|
579
581
|
const user = await this.resolveUser(initiateForgotPasswordDto.username, initiateForgotPasswordDto.email);
|
|
580
582
|
if (!user) {
|
|
581
|
-
throw new common_1.NotFoundException(
|
|
583
|
+
throw new common_1.NotFoundException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
582
584
|
}
|
|
583
585
|
if (!user.active) {
|
|
584
|
-
throw new common_1.UnauthorizedException(
|
|
586
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
585
587
|
}
|
|
586
588
|
if (user.lastLoginProvider !== 'local') {
|
|
587
|
-
throw new common_1.BadRequestException(
|
|
589
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.NON_LOCAL_PROVIDER);
|
|
588
590
|
}
|
|
589
591
|
const { token, expiresAt } = this.otp();
|
|
590
592
|
user.verificationTokenOnForgotPassword = token;
|
|
@@ -593,7 +595,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
593
595
|
this.notifyUserOnForgotPassword(user);
|
|
594
596
|
return {
|
|
595
597
|
status: 'success',
|
|
596
|
-
message:
|
|
598
|
+
message: success_messages_1.SUCCESS_MESSAGES.FORGOT_PASSWORD_TOKEN_SENT,
|
|
597
599
|
error: '',
|
|
598
600
|
errorCode: '',
|
|
599
601
|
data: {
|
|
@@ -631,19 +633,19 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
631
633
|
async confirmForgotPassword(confirmForgotPasswordDto) {
|
|
632
634
|
const user = await this.resolveUser(confirmForgotPasswordDto.username, confirmForgotPasswordDto.email);
|
|
633
635
|
if (!user) {
|
|
634
|
-
throw new common_1.NotFoundException(
|
|
636
|
+
throw new common_1.NotFoundException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
635
637
|
}
|
|
636
638
|
if (user.lastLoginProvider !== 'local') {
|
|
637
|
-
throw new common_1.BadRequestException(
|
|
639
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.NON_LOCAL_PROVIDER);
|
|
638
640
|
}
|
|
639
641
|
if (!user.active) {
|
|
640
|
-
throw new common_1.UnauthorizedException(
|
|
642
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
641
643
|
}
|
|
642
644
|
if (user.verificationTokenOnForgotPassword !== confirmForgotPasswordDto.verificationToken) {
|
|
643
|
-
throw new common_1.UnauthorizedException(
|
|
645
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TOKEN);
|
|
644
646
|
}
|
|
645
647
|
if (user.verificationTokenOnForgotPasswordExpiresAt < new Date()) {
|
|
646
|
-
throw new common_1.UnauthorizedException(
|
|
648
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TOKEN);
|
|
647
649
|
}
|
|
648
650
|
user.forgotPasswordConfirmedAt = new Date();
|
|
649
651
|
user.verificationTokenOnForgotPassword = null;
|
|
@@ -651,7 +653,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
651
653
|
const pwd = await this.hashingService.hash(confirmForgotPasswordDto.password);
|
|
652
654
|
user.password = confirmForgotPasswordDto.password;
|
|
653
655
|
if (await this.isPasswordDuplicate(user)) {
|
|
654
|
-
throw new common_1.BadRequestException(
|
|
656
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORD_REUSED);
|
|
655
657
|
}
|
|
656
658
|
await this.deleteOldPasswords(user);
|
|
657
659
|
user.password = pwd;
|
|
@@ -662,7 +664,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
662
664
|
await this.userPasswordHistoryRepository.save(userPasswordHistory);
|
|
663
665
|
return {
|
|
664
666
|
status: 'success',
|
|
665
|
-
message:
|
|
667
|
+
message: success_messages_1.SUCCESS_MESSAGES.FORGOT_PASSWORD_CONFIRMED,
|
|
666
668
|
error: '',
|
|
667
669
|
errorCode: '',
|
|
668
670
|
data: {}
|
|
@@ -731,7 +733,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
731
733
|
}
|
|
732
734
|
});
|
|
733
735
|
if (!user) {
|
|
734
|
-
throw new common_1.UnauthorizedException();
|
|
736
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.SESSION_INVALID);
|
|
735
737
|
}
|
|
736
738
|
const currentRefreshToken = await this.refreshTokenIdsStorage.validateAndRotate(user, refreshTokenDto.refreshToken);
|
|
737
739
|
await this.userActivityHistoryService.logEvent('tokenRefreshed', user);
|
|
@@ -742,9 +744,9 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
742
744
|
}
|
|
743
745
|
catch (err) {
|
|
744
746
|
if (err instanceof refresh_token_ids_storage_service_1.InvalidatedRefreshTokenError) {
|
|
745
|
-
throw new common_1.UnauthorizedException(
|
|
747
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.ACCESS_DENIED);
|
|
746
748
|
}
|
|
747
|
-
throw new common_1.UnauthorizedException();
|
|
749
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.SESSION_EXPIRED);
|
|
748
750
|
}
|
|
749
751
|
}
|
|
750
752
|
async signToken(userId, expiresIn, payload) {
|
|
@@ -766,11 +768,11 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
766
768
|
return userProfile;
|
|
767
769
|
}
|
|
768
770
|
else {
|
|
769
|
-
throw new common_1.UnauthorizedException(
|
|
771
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_USER_PROFILE);
|
|
770
772
|
}
|
|
771
773
|
}
|
|
772
774
|
catch (error) {
|
|
773
|
-
throw new common_1.UnauthorizedException(
|
|
775
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.GOOGLE_OAUTH_PROFILE_FETCH_FAILED);
|
|
774
776
|
}
|
|
775
777
|
}
|
|
776
778
|
async signInUsingGoogle(accessCode) {
|
|
@@ -809,18 +811,18 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
809
811
|
});
|
|
810
812
|
await this.refreshTokenIdsStorage.invalidate(userId);
|
|
811
813
|
await this.userActivityHistoryService.logEvent('logout', user);
|
|
812
|
-
return { message:
|
|
814
|
+
return { message: success_messages_1.SUCCESS_MESSAGES.LOGOUT_SUCCESS };
|
|
813
815
|
}
|
|
814
816
|
catch (err) {
|
|
815
817
|
throw err instanceof common_1.UnauthorizedException || err instanceof common_1.InternalServerErrorException
|
|
816
818
|
? err
|
|
817
|
-
: new common_1.InternalServerErrorException(
|
|
819
|
+
: new common_1.InternalServerErrorException(error_messages_1.ERROR_MESSAGES.LOGOUT_FAILED);
|
|
818
820
|
}
|
|
819
821
|
}
|
|
820
822
|
async activateUser(userId) {
|
|
821
823
|
const user = await this.userService.findOne(userId, {});
|
|
822
824
|
if (!user) {
|
|
823
|
-
throw new common_1.NotFoundException(
|
|
825
|
+
throw new common_1.NotFoundException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
824
826
|
}
|
|
825
827
|
user.active = true;
|
|
826
828
|
await this.userRepository.save(user);
|
|
@@ -862,7 +864,7 @@ exports.AuthenticationService = AuthenticationService = AuthenticationService_1
|
|
|
862
864
|
hashing_service_1.HashingService,
|
|
863
865
|
jwt_1.JwtService, void 0, void 0, refresh_token_ids_storage_service_1.RefreshTokenIdsStorageService,
|
|
864
866
|
axios_1.HttpService,
|
|
865
|
-
|
|
867
|
+
smtp_email_service_1.SMTPEMailService,
|
|
866
868
|
Msg91OTPService_1.Msg91OTPService,
|
|
867
869
|
event_emitter_1.EventEmitter2,
|
|
868
870
|
setting_service_1.SettingService,
|