@solidxai/core 0.1.9-beta.8 → 0.1.10-alpha.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/LICENSE +89 -0
- package/README.md +3 -1
- package/dist/commands/run-tests.command.d.ts +2 -0
- package/dist/commands/run-tests.command.d.ts.map +1 -1
- package/dist/commands/run-tests.command.js +49 -17
- package/dist/commands/run-tests.command.js.map +1 -1
- package/dist/controllers/action-metadata.controller.js +1 -1
- package/dist/controllers/action-metadata.controller.js.map +1 -1
- package/dist/controllers/facebook-authentication.controller.js +1 -1
- package/dist/controllers/facebook-authentication.controller.js.map +1 -1
- package/dist/controllers/google-authentication.controller.js +1 -1
- package/dist/controllers/google-authentication.controller.js.map +1 -1
- package/dist/controllers/menu-item-metadata.controller.js +1 -1
- package/dist/controllers/menu-item-metadata.controller.js.map +1 -1
- package/dist/controllers/microsoft-authentication.controller.js +1 -1
- package/dist/controllers/microsoft-authentication.controller.js.map +1 -1
- package/dist/controllers/mq-message-queue.controller.js +1 -1
- package/dist/controllers/mq-message-queue.controller.js.map +1 -1
- package/dist/controllers/mq-message.controller.js +1 -1
- package/dist/controllers/mq-message.controller.js.map +1 -1
- package/dist/controllers/user.controller.d.ts.map +1 -1
- package/dist/controllers/user.controller.js.map +1 -1
- package/dist/controllers/view-metadata.controller.js +1 -1
- package/dist/controllers/view-metadata.controller.js.map +1 -1
- package/dist/helpers/bootstrap.helper.d.ts.map +1 -1
- package/dist/helpers/bootstrap.helper.js +2 -0
- package/dist/helpers/bootstrap.helper.js.map +1 -1
- package/dist/helpers/field-crud-managers/BigIntFieldCrudManager.js.map +1 -1
- package/dist/helpers/field-crud-managers/SelectionDynamicFieldCrudManager.js.map +1 -1
- package/dist/helpers/module-metadata-helper.service.js.map +1 -1
- package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js.map +1 -1
- package/dist/passport-strategies/facebook-oauth.strategy.d.ts +5 -3
- package/dist/passport-strategies/facebook-oauth.strategy.d.ts.map +1 -1
- package/dist/passport-strategies/facebook-oauth.strategy.js +41 -18
- package/dist/passport-strategies/facebook-oauth.strategy.js.map +1 -1
- package/dist/repository/security-rule.repository.js.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/permission-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +14 -3
- package/dist/services/authentication.service.d.ts +12 -13
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +42 -18
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/chatter-message.service.js.map +1 -1
- package/dist/services/crud.service.js.map +1 -1
- package/dist/services/csv.service.js.map +1 -1
- package/dist/services/dashboard.service.js.map +1 -1
- package/dist/services/database/database-bootstrap.service.js.map +1 -1
- package/dist/services/excel.service.js.map +1 -1
- package/dist/services/export-transaction.service.js.map +1 -1
- package/dist/services/field-metadata.service.js +2 -2
- package/dist/services/field-metadata.service.js.map +1 -1
- package/dist/services/fixtures.service.js.map +1 -1
- package/dist/services/import-transaction.service.js.map +1 -1
- package/dist/services/list-of-values.service.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +3 -13
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/module-metadata.service.js.map +1 -1
- package/dist/services/queues/database-publisher.service.js +3 -3
- package/dist/services/queues/database-publisher.service.js.map +1 -1
- package/dist/services/queues/database-subscriber.service.js +3 -3
- package/dist/services/queues/database-subscriber.service.js.map +1 -1
- package/dist/services/queues/rabbitmq-publisher.service.js +3 -3
- package/dist/services/queues/rabbitmq-publisher.service.js.map +1 -1
- package/dist/services/queues/rabbitmq-subscriber.service.js +4 -4
- package/dist/services/queues/rabbitmq-subscriber.service.js.map +1 -1
- package/dist/services/queues/redis-publisher.service.d.ts.map +1 -1
- package/dist/services/queues/redis-publisher.service.js +4 -1
- package/dist/services/queues/redis-publisher.service.js.map +1 -1
- package/dist/services/queues/redis-subscriber.service.d.ts.map +1 -1
- package/dist/services/queues/redis-subscriber.service.js +4 -1
- package/dist/services/queues/redis-subscriber.service.js.map +1 -1
- package/dist/services/role-metadata.service.js.map +1 -1
- package/dist/services/scheduled-jobs/scheduler.service.js.map +1 -1
- package/dist/services/settings/default-settings-provider.service.d.ts +74 -8
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +96 -16
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/services/sms/TwilioSMSService.js.map +1 -1
- package/dist/services/solid-introspect.service.js.map +1 -1
- package/dist/services/user-activity-history.service.js.map +1 -1
- package/dist/services/user.service.d.ts +10 -8
- package/dist/services/user.service.d.ts.map +1 -1
- package/dist/services/user.service.js +85 -46
- package/dist/services/user.service.js.map +1 -1
- package/dist/services/view-metadata.service.d.ts.map +1 -1
- package/dist/services/view-metadata.service.js +17 -2
- package/dist/services/view-metadata.service.js.map +1 -1
- package/dist/solid-core.module.d.ts +1 -0
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +1 -0
- package/dist/solid-core.module.js.map +1 -1
- package/dist/subscribers/computed-entity-field.subscriber.js.map +1 -1
- package/dist/subscribers/security-rule.subscriber.d.ts.map +1 -1
- package/dist/subscribers/security-rule.subscriber.js.map +1 -1
- package/dist/subscribers/view-metadata.subscriber.js.map +1 -1
- package/dist/testing/core/testing-engine.js.map +1 -1
- package/dist/testing/reporter/webhook-reporter.d.ts +54 -0
- package/dist/testing/reporter/webhook-reporter.d.ts.map +1 -0
- package/dist/testing/reporter/webhook-reporter.js +74 -0
- package/dist/testing/reporter/webhook-reporter.js.map +1 -0
- package/package.json +6 -2
- package/src/commands/run-tests.command.ts +45 -17
- package/src/controllers/action-metadata.controller.ts +1 -1
- package/src/controllers/facebook-authentication.controller.ts +1 -1
- package/src/controllers/google-authentication.controller.ts +1 -1
- package/src/controllers/menu-item-metadata.controller.ts +1 -1
- package/src/controllers/microsoft-authentication.controller.ts +1 -1
- package/src/controllers/mq-message-queue.controller.ts +1 -1
- package/src/controllers/mq-message.controller.ts +1 -1
- package/src/controllers/user.controller.ts +16 -16
- package/src/controllers/view-metadata.controller.ts +1 -1
- package/src/helpers/bootstrap.helper.ts +3 -0
- package/src/helpers/field-crud-managers/BigIntFieldCrudManager.ts +1 -1
- package/src/helpers/field-crud-managers/SelectionDynamicFieldCrudManager.ts +1 -1
- package/src/helpers/module-metadata-helper.service.ts +1 -1
- package/src/jobs/database/trigger-mcp-client-subscriber-database.service.ts +1 -1
- package/src/passport-strategies/facebook-oauth.strategy.ts +82 -31
- package/src/repository/security-rule.repository.ts +1 -1
- package/src/seeders/module-metadata-seeder.service.ts +4 -4
- package/src/seeders/permission-metadata-seeder.service.ts +1 -1
- package/src/seeders/seed-data/solid-core-metadata.json +14 -3
- package/src/services/authentication.service.ts +215 -151
- package/src/services/chatter-message.service.ts +1 -1
- package/src/services/crud.service.ts +3 -3
- package/src/services/csv.service.ts +1 -1
- package/src/services/dashboard.service.ts +1 -1
- package/src/services/database/database-bootstrap.service.ts +1 -1
- package/src/services/excel.service.ts +1 -1
- package/src/services/export-transaction.service.ts +2 -2
- package/src/services/field-metadata.service.ts +3 -3
- package/src/services/fixtures.service.ts +2 -2
- package/src/services/import-transaction.service.ts +2 -2
- package/src/services/list-of-values.service.ts +1 -1
- package/src/services/model-metadata.service.ts +22 -21
- package/src/services/module-metadata.service.ts +7 -7
- package/src/services/queues/database-publisher.service.ts +4 -4
- package/src/services/queues/database-subscriber.service.ts +7 -7
- package/src/services/queues/rabbitmq-publisher.service.ts +7 -7
- package/src/services/queues/rabbitmq-subscriber.service.ts +13 -13
- package/src/services/queues/redis-publisher.service.ts +7 -4
- package/src/services/queues/redis-subscriber.service.ts +9 -6
- package/src/services/role-metadata.service.ts +1 -1
- package/src/services/scheduled-jobs/scheduler.service.ts +5 -5
- package/src/services/settings/default-settings-provider.service.ts +101 -21
- package/src/services/sms/TwilioSMSService.ts +2 -2
- package/src/services/solid-introspect.service.ts +2 -2
- package/src/services/user-activity-history.service.ts +1 -1
- package/src/services/user.service.ts +149 -77
- package/src/services/view-metadata.service.ts +25 -8
- package/src/solid-core.module.ts +1 -0
- package/src/subscribers/computed-entity-field.subscriber.ts +1 -1
- package/src/subscribers/security-rule.subscriber.ts +8 -8
- package/src/subscribers/view-metadata.subscriber.ts +1 -1
- package/src/testing/core/testing-engine.ts +2 -2
- package/src/testing/reporter/webhook-reporter.ts +116 -0
- package/dev-grooming-docs/ozzy-prompts.txt +0 -70
|
@@ -38,16 +38,19 @@ import { SignInDto } from "../dtos/sign-in.dto";
|
|
|
38
38
|
import { SignUpDto } from "../dtos/sign-up.dto";
|
|
39
39
|
import { User } from "../entities/user.entity";
|
|
40
40
|
import { EventDetails, EventType } from "../interfaces";
|
|
41
|
-
import { ActiveUserData } from
|
|
42
|
-
import { HashingService } from
|
|
43
|
-
import {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
41
|
+
import { ActiveUserData } from "../interfaces/active-user-data.interface";
|
|
42
|
+
import { HashingService } from "./hashing.service";
|
|
43
|
+
import {
|
|
44
|
+
InvalidatedRefreshTokenError,
|
|
45
|
+
RefreshTokenIdsStorageService,
|
|
46
|
+
} from "./refresh-token-ids-storage.service";
|
|
47
|
+
import { SsoCodeStorageService } from "./sso-code-storage.service";
|
|
48
|
+
import { RoleMetadataService } from "./role-metadata.service";
|
|
49
|
+
import { SettingService } from "./setting.service";
|
|
50
|
+
import { UserActivityHistoryService } from "./user-activity-history.service";
|
|
51
|
+
import { UserService } from "./user.service";
|
|
52
|
+
import { SmsFactory } from "src/factories/sms.factory";
|
|
53
|
+
import { SolidRegistry } from "src/helpers/solid-registry";
|
|
51
54
|
|
|
52
55
|
enum LoginProvider {
|
|
53
56
|
LOCAL = "local",
|
|
@@ -62,32 +65,32 @@ interface otp {
|
|
|
62
65
|
|
|
63
66
|
@Injectable()
|
|
64
67
|
export class AuthenticationService {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
68
|
+
private readonly logger = new Logger(AuthenticationService.name);
|
|
69
|
+
// private readonly mailService: IMail;
|
|
70
|
+
constructor(
|
|
71
|
+
private readonly userService: UserService,
|
|
72
|
+
// @InjectRepository(User) private readonly userRepository: Repository<User>,
|
|
73
|
+
private readonly userRepository: UserRepository,
|
|
74
|
+
private readonly hashingService: HashingService,
|
|
75
|
+
private readonly jwtService: JwtService,
|
|
76
|
+
private readonly refreshTokenIdsStorage: RefreshTokenIdsStorageService,
|
|
77
|
+
private readonly httpService: HttpService,
|
|
78
|
+
// private readonly mailService: SMTPEMailService,
|
|
79
|
+
private readonly mailServiceFactory: MailFactory,
|
|
80
|
+
// private readonly smsService: Msg91OTPService,
|
|
81
|
+
private readonly smsFactory: SmsFactory,
|
|
82
|
+
private readonly eventEmitter: EventEmitter2,
|
|
83
|
+
private readonly settingService: SettingService,
|
|
84
|
+
private readonly roleMetadataService: RoleMetadataService,
|
|
85
|
+
private readonly userActivityHistoryService: UserActivityHistoryService,
|
|
86
|
+
private readonly ssoCodeStorage: SsoCodeStorageService,
|
|
87
|
+
|
|
88
|
+
@InjectDataSource()
|
|
89
|
+
private readonly dataSource: DataSource,
|
|
90
|
+
private readonly solidRegistry: SolidRegistry,
|
|
91
|
+
) {
|
|
92
|
+
// this.mailService = this.mailServiceFactory.getMailService();
|
|
93
|
+
}
|
|
91
94
|
|
|
92
95
|
private async getCompanyLogo(): Promise<string> {
|
|
93
96
|
return this.settingService.getConfigValue<SolidCoreSetting>("companylogo");
|
|
@@ -153,58 +156,90 @@ export class AuthenticationService {
|
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
|
|
156
|
-
|
|
159
|
+
private static readonly SIGNUP_DTO_KEYS = new Set([
|
|
160
|
+
"username",
|
|
161
|
+
"email",
|
|
162
|
+
"password",
|
|
163
|
+
"fullName",
|
|
164
|
+
"mobile",
|
|
165
|
+
"roles",
|
|
166
|
+
"forcePasswordChange",
|
|
167
|
+
"isAllowedToGenerateApiKeys",
|
|
168
|
+
"failedLoginAttempts",
|
|
169
|
+
]);
|
|
157
170
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var { user, pwd, autoGeneratedPwd } = await this.populateForSignup<T>(entity, signUpDto, activateUserOnRegistration, onForcePasswordChange);
|
|
181
|
-
const privateDto = signUpDto as { isAllowedToGenerateApiKeys?: boolean };
|
|
182
|
-
if (privateDto.isAllowedToGenerateApiKeys !== undefined) {
|
|
183
|
-
user.isAllowedToGenerateApiKeys = privateDto.isAllowedToGenerateApiKeys;
|
|
184
|
-
}
|
|
185
|
-
const savedUser = await repo.save(user);
|
|
186
|
-
const userRoles = signUpDto.roles ?? [];
|
|
187
|
-
if ((signUpDto.roles?.length ?? 0) === 0 && signUpDto.username !== 'sa' && defaultRole) {
|
|
188
|
-
userRoles.push(defaultRole);
|
|
189
|
-
}
|
|
190
|
-
await this.handlePostSignup(savedUser, userRoles, pwd, autoGeneratedPwd);
|
|
191
|
-
|
|
192
|
-
return savedUser;
|
|
193
|
-
} catch (err) {
|
|
194
|
-
const pgUniqueViolationErrorCode = '23505';
|
|
195
|
-
if (err.code === pgUniqueViolationErrorCode) {
|
|
196
|
-
throw new ConflictException(parseUniqueConstraintError(err.detail || ERROR_MESSAGES.UNIQUE_CONSTRAINT_VIOLATION));
|
|
197
|
-
}
|
|
198
|
-
throw err;
|
|
199
|
-
}
|
|
171
|
+
async signUp(
|
|
172
|
+
signUpDto: SignUpDto & Record<string, any>,
|
|
173
|
+
activeUser: ActiveUserData = null,
|
|
174
|
+
): Promise<User> {
|
|
175
|
+
const hasExtensionFields = Object.keys(signUpDto).some(
|
|
176
|
+
(k) => !AuthenticationService.SIGNUP_DTO_KEYS.has(k),
|
|
177
|
+
);
|
|
178
|
+
if (hasExtensionFields) {
|
|
179
|
+
const provider = this.solidRegistry.getExtensionUserCreationProvider();
|
|
180
|
+
if (!provider) {
|
|
181
|
+
throw new InternalServerErrorException(
|
|
182
|
+
"No ExtensionUserCreationProvider registered. Register one to handle extension user creation.",
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const entity = await provider.buildExtensionEntity(signUpDto);
|
|
186
|
+
const effectiveDto = { ...signUpDto, roles: provider.roles(signUpDto) };
|
|
187
|
+
return this.performSignUp(
|
|
188
|
+
effectiveDto,
|
|
189
|
+
entity,
|
|
190
|
+
provider.repo as Repository<User>,
|
|
191
|
+
);
|
|
200
192
|
}
|
|
193
|
+
return this.performSignUp(signUpDto, new User(), this.userRepository);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private async performSignUp<T extends User>(signUpDto: SignUpDto, entity: T, repo: Repository<T>): Promise<T> {
|
|
197
|
+
try {
|
|
198
|
+
const onForcePasswordChange = this.settingService.getConfigValue<SolidCoreSetting>("forceChangePasswordOnFirstLogin");
|
|
199
|
+
const activateUserOnRegistration = this.settingService.getConfigValue<SolidCoreSetting>("activateUserOnRegistration");
|
|
200
|
+
const defaultRole = this.settingService.getConfigValue<SolidCoreSetting>("defaultRole");
|
|
201
|
+
|
|
202
|
+
var { user, pwd, autoGeneratedPwd } = await this.populateForSignup<T>(
|
|
203
|
+
entity,
|
|
204
|
+
signUpDto,
|
|
205
|
+
activateUserOnRegistration,
|
|
206
|
+
onForcePasswordChange,
|
|
207
|
+
);
|
|
208
|
+
const privateDto = signUpDto as { isAllowedToGenerateApiKeys?: boolean };
|
|
209
|
+
if (privateDto.isAllowedToGenerateApiKeys !== undefined) {
|
|
210
|
+
user.isAllowedToGenerateApiKeys = privateDto.isAllowedToGenerateApiKeys;
|
|
211
|
+
}
|
|
212
|
+
const savedUser = await repo.save(user);
|
|
213
|
+
const userRoles = signUpDto.roles ?? [];
|
|
214
|
+
if ((signUpDto.roles?.length ?? 0) === 0 && signUpDto.username !== "sa" && defaultRole) {
|
|
215
|
+
userRoles.push(defaultRole);
|
|
216
|
+
}
|
|
217
|
+
await this.handlePostSignup(savedUser, userRoles, pwd, autoGeneratedPwd);
|
|
201
218
|
|
|
202
|
-
|
|
203
|
-
async signupForExtensionUser<T extends User, U extends CreateUserDto>(signUpDto: SignUpDto, extensionUserDto: U, extensionUserRepo: Repository<T>): Promise<T> {
|
|
204
|
-
// @ts-ignore
|
|
205
|
-
const entity = extensionUserRepo.merge(extensionUserRepo.create() as T, extensionUserDto);
|
|
206
|
-
return this.performSignUp(signUpDto, entity, extensionUserRepo);
|
|
219
|
+
return savedUser;
|
|
207
220
|
}
|
|
221
|
+
catch (err: any) {
|
|
222
|
+
const pgUniqueViolationErrorCode = "23505";
|
|
223
|
+
if (err.code === pgUniqueViolationErrorCode) {
|
|
224
|
+
throw new ConflictException(
|
|
225
|
+
parseUniqueConstraintError(
|
|
226
|
+
err.detail || ERROR_MESSAGES.UNIQUE_CONSTRAINT_VIOLATION,
|
|
227
|
+
),
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** @deprecated Use IExtensionUserCreationProvider instead. Kept for backward compatibility. */
|
|
235
|
+
async signupForExtensionUser<T extends User>(
|
|
236
|
+
signUpDto: SignUpDto,
|
|
237
|
+
extensionUserDto: DeepPartial<T>,
|
|
238
|
+
extensionUserRepo: Repository<T>,
|
|
239
|
+
): Promise<T> {
|
|
240
|
+
const entity = extensionUserRepo.create(extensionUserDto);
|
|
241
|
+
return this.performSignUp(signUpDto, entity, extensionUserRepo);
|
|
242
|
+
}
|
|
208
243
|
|
|
209
244
|
private async populateForSignup<T extends User>(
|
|
210
245
|
user: T,
|
|
@@ -438,7 +473,7 @@ export class AuthenticationService {
|
|
|
438
473
|
validationSource,
|
|
439
474
|
);
|
|
440
475
|
await this.notifyUserOnOtpInitiateRegistration(user, validationSource);
|
|
441
|
-
} catch (err) {
|
|
476
|
+
} catch (err: any) {
|
|
442
477
|
if (err.code === "23505") {
|
|
443
478
|
throw new ConflictException(ERROR_MESSAGES.USER_ALREADY_EXISTS);
|
|
444
479
|
}
|
|
@@ -489,20 +524,27 @@ export class AuthenticationService {
|
|
|
489
524
|
);
|
|
490
525
|
}
|
|
491
526
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
527
|
+
private async upsertUserWithRegistrationVerificationTokens(
|
|
528
|
+
existingUser: User,
|
|
529
|
+
signUpDto: OTPSignUpDto,
|
|
530
|
+
validationSource: string,
|
|
531
|
+
): Promise<User> {
|
|
532
|
+
let user = existingUser;
|
|
533
|
+
if (isEmpty(user)) {
|
|
534
|
+
user = this.createUser(signUpDto);
|
|
535
|
+
user.active = false; // User will be activated only after OTP verification, hence setting active to false for new user.
|
|
536
|
+
await this.assignRegistrationOtp(validationSource, user);
|
|
537
|
+
await this.userRepository.save(user);
|
|
538
|
+
await this.userService.addRoleToUser(
|
|
539
|
+
user.username,
|
|
540
|
+
this.settingService.getConfigValue<SolidCoreSetting>("defaultRole"),
|
|
541
|
+
);
|
|
542
|
+
} else {
|
|
543
|
+
await this.assignRegistrationOtp(validationSource, user);
|
|
544
|
+
await this.userRepository.save(user);
|
|
505
545
|
}
|
|
546
|
+
return user;
|
|
547
|
+
}
|
|
506
548
|
|
|
507
549
|
// Create a new user entity.
|
|
508
550
|
private createUser(signUpDto: OTPSignUpDto) {
|
|
@@ -1068,16 +1110,16 @@ export class AuthenticationService {
|
|
|
1068
1110
|
}
|
|
1069
1111
|
}
|
|
1070
1112
|
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1113
|
+
private buildUserPayload(user: User) {
|
|
1114
|
+
const { id, username, email, mobile, lastLoginProvider } = user;
|
|
1115
|
+
const roles = user.roles.map((role) => role.name);
|
|
1116
|
+
return { id, username, email, mobile, lastLoginProvider, roles };
|
|
1117
|
+
}
|
|
1076
1118
|
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1119
|
+
private async buildLoginTokenResponse(user: User) {
|
|
1120
|
+
const { accessToken, refreshToken } = await this.generateTokens(user);
|
|
1121
|
+
return { accessToken, refreshToken, user: this.buildUserPayload(user) };
|
|
1122
|
+
}
|
|
1081
1123
|
|
|
1082
1124
|
async changePassword(
|
|
1083
1125
|
changePasswordDto: ChangePasswordDto,
|
|
@@ -1252,7 +1294,7 @@ export class AuthenticationService {
|
|
|
1252
1294
|
// Assuming all users do not have mobile as mandatory.
|
|
1253
1295
|
if (
|
|
1254
1296
|
forgotPasswordSendVerificationTokenOn ==
|
|
1255
|
-
|
|
1297
|
+
ForgotPasswordSendVerificationTokenOn.MOBILE &&
|
|
1256
1298
|
user.mobile
|
|
1257
1299
|
) {
|
|
1258
1300
|
const smsService = this.smsFactory.getSmsService();
|
|
@@ -1282,11 +1324,11 @@ export class AuthenticationService {
|
|
|
1282
1324
|
confirmForgotPasswordDto.verificationToken,
|
|
1283
1325
|
);
|
|
1284
1326
|
if (!user)
|
|
1285
|
-
throw new UnauthorizedException(
|
|
1327
|
+
throw new UnauthorizedException("Invalid verification token");
|
|
1286
1328
|
if (user.lastLoginProvider !== "local")
|
|
1287
1329
|
throw new UnauthorizedException(ERROR_MESSAGES.INVALID_CREDENTIALS);
|
|
1288
1330
|
if (!user.active)
|
|
1289
|
-
throw new UnauthorizedException(
|
|
1331
|
+
throw new UnauthorizedException("User is inactive");
|
|
1290
1332
|
|
|
1291
1333
|
// 1) Atomically consume the token (only one request can succeed)
|
|
1292
1334
|
const { affected } = await m
|
|
@@ -1378,7 +1420,7 @@ export class AuthenticationService {
|
|
|
1378
1420
|
// Assuming all users do not have mobile as mandatory.
|
|
1379
1421
|
if (
|
|
1380
1422
|
forgotPasswordSendVerificationTokenOn ==
|
|
1381
|
-
|
|
1423
|
+
ForgotPasswordSendVerificationTokenOn.MOBILE &&
|
|
1382
1424
|
user.mobile
|
|
1383
1425
|
) {
|
|
1384
1426
|
const smsService = this.smsFactory.getSmsService();
|
|
@@ -1494,7 +1536,7 @@ export class AuthenticationService {
|
|
|
1494
1536
|
accessToken: await this.generateAccessToken(user),
|
|
1495
1537
|
refreshToken: currentRefreshToken,
|
|
1496
1538
|
};
|
|
1497
|
-
} catch (err) {
|
|
1539
|
+
} catch (err: any) {
|
|
1498
1540
|
if (err instanceof InvalidatedRefreshTokenError) {
|
|
1499
1541
|
// Take action: notify user that his refresh token might have been stolen?
|
|
1500
1542
|
throw new UnauthorizedException(ERROR_MESSAGES.ACCESS_DENIED);
|
|
@@ -1545,7 +1587,7 @@ export class AuthenticationService {
|
|
|
1545
1587
|
} else {
|
|
1546
1588
|
throw new UnauthorizedException(ERROR_MESSAGES.INVALID_USER_PROFILE);
|
|
1547
1589
|
}
|
|
1548
|
-
} catch (error) {
|
|
1590
|
+
} catch (error: any) {
|
|
1549
1591
|
throw new UnauthorizedException(
|
|
1550
1592
|
ERROR_MESSAGES.GOOGLE_OAUTH_PROFILE_FETCH_FAILED,
|
|
1551
1593
|
);
|
|
@@ -1590,9 +1632,19 @@ export class AuthenticationService {
|
|
|
1590
1632
|
}
|
|
1591
1633
|
|
|
1592
1634
|
async validateUserUsingFacebook(user: User) {
|
|
1635
|
+
if (!user.facebookAccessToken || !user.facebookId) {
|
|
1636
|
+
throw new UnauthorizedException(ERROR_MESSAGES.USER_NOT_FOUND);
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1593
1639
|
try {
|
|
1594
1640
|
const response = await this.httpService.axiosRef.get(
|
|
1595
|
-
`https://graph.facebook.com/me
|
|
1641
|
+
`https://graph.facebook.com/me`,
|
|
1642
|
+
{
|
|
1643
|
+
params: { fields: "id,name,email" },
|
|
1644
|
+
headers: {
|
|
1645
|
+
Authorization: `Bearer ${user.facebookAccessToken}`,
|
|
1646
|
+
},
|
|
1647
|
+
},
|
|
1596
1648
|
);
|
|
1597
1649
|
const userProfile = response.data;
|
|
1598
1650
|
|
|
@@ -1604,8 +1656,11 @@ export class AuthenticationService {
|
|
|
1604
1656
|
} else {
|
|
1605
1657
|
throw new UnauthorizedException(ERROR_MESSAGES.INVALID_USER_PROFILE);
|
|
1606
1658
|
}
|
|
1607
|
-
} catch (error) {
|
|
1608
|
-
|
|
1659
|
+
} catch (error: any) {
|
|
1660
|
+
if (error instanceof UnauthorizedException) {
|
|
1661
|
+
throw error;
|
|
1662
|
+
}
|
|
1663
|
+
throw new UnauthorizedException(ERROR_MESSAGES.USER_NOT_FOUND);
|
|
1609
1664
|
}
|
|
1610
1665
|
}
|
|
1611
1666
|
|
|
@@ -1666,7 +1721,7 @@ export class AuthenticationService {
|
|
|
1666
1721
|
} else {
|
|
1667
1722
|
throw new UnauthorizedException(ERROR_MESSAGES.INVALID_USER_PROFILE);
|
|
1668
1723
|
}
|
|
1669
|
-
} catch (error) {
|
|
1724
|
+
} catch (error: any) {
|
|
1670
1725
|
throw new UnauthorizedException("Microsoft OAuth profile fetch failed");
|
|
1671
1726
|
}
|
|
1672
1727
|
}
|
|
@@ -1813,7 +1868,7 @@ export class AuthenticationService {
|
|
|
1813
1868
|
await this.userActivityHistoryService.logEvent("logout", user);
|
|
1814
1869
|
|
|
1815
1870
|
return { message: SUCCESS_MESSAGES.LOGOUT_SUCCESS };
|
|
1816
|
-
} catch (err) {
|
|
1871
|
+
} catch (err: any) {
|
|
1817
1872
|
throw err instanceof UnauthorizedException ||
|
|
1818
1873
|
err instanceof InternalServerErrorException
|
|
1819
1874
|
? err
|
|
@@ -1846,43 +1901,52 @@ export class AuthenticationService {
|
|
|
1846
1901
|
const refreshTokenState =
|
|
1847
1902
|
await this.refreshTokenIdsStorage.getCurrentRefreshTokenState(user.id);
|
|
1848
1903
|
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1904
|
+
const response = {
|
|
1905
|
+
user: {
|
|
1906
|
+
email: user.email,
|
|
1907
|
+
mobile: user.mobile,
|
|
1908
|
+
username: user.username,
|
|
1909
|
+
// forcePasswordChange: user.forcePasswordChange,
|
|
1910
|
+
id: user.id,
|
|
1911
|
+
roles: user.roles.map((role) => role.name),
|
|
1912
|
+
},
|
|
1913
|
+
refreshToken: refreshTokenState.currentRefreshToken,
|
|
1914
|
+
// ...tokens
|
|
1915
|
+
};
|
|
1916
|
+
return response;
|
|
1917
|
+
}
|
|
1863
1918
|
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
return { ssoCode };
|
|
1919
|
+
async generateSsoCode(
|
|
1920
|
+
activeUser: ActiveUserData,
|
|
1921
|
+
rawAccessToken: string,
|
|
1922
|
+
): Promise<{ ssoCode: string }> {
|
|
1923
|
+
const refreshTokenState =
|
|
1924
|
+
await this.refreshTokenIdsStorage.getCurrentRefreshTokenState(
|
|
1925
|
+
activeUser.sub,
|
|
1926
|
+
);
|
|
1927
|
+
if (!refreshTokenState?.currentRefreshToken) {
|
|
1928
|
+
throw new UnauthorizedException("No active session found");
|
|
1875
1929
|
}
|
|
1930
|
+
const ssoCode = await this.ssoCodeStorage.generateCode(
|
|
1931
|
+
activeUser.sub,
|
|
1932
|
+
rawAccessToken,
|
|
1933
|
+
refreshTokenState.currentRefreshToken,
|
|
1934
|
+
);
|
|
1935
|
+
return { ssoCode };
|
|
1936
|
+
}
|
|
1876
1937
|
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1938
|
+
async exchangeSsoCode(code: string) {
|
|
1939
|
+
const { userId, accessToken, refreshToken } =
|
|
1940
|
+
await this.ssoCodeStorage.consumeCode(code);
|
|
1941
|
+
const user = await this.userRepository.findOne({
|
|
1942
|
+
where: { id: userId },
|
|
1943
|
+
relations: { roles: true },
|
|
1944
|
+
});
|
|
1945
|
+
if (!user) {
|
|
1946
|
+
throw new UnauthorizedException("User not found");
|
|
1884
1947
|
}
|
|
1885
|
-
|
|
1948
|
+
return { accessToken, refreshToken, user: this.buildUserPayload(user) };
|
|
1949
|
+
}
|
|
1886
1950
|
}
|
|
1887
1951
|
|
|
1888
1952
|
function parseUniqueConstraintError(detail: string): string {
|
|
@@ -421,7 +421,7 @@ export class ChatterMessageService extends CRUDService<ChatterMessage> {
|
|
|
421
421
|
if (value.id) {
|
|
422
422
|
return value.id.toString();
|
|
423
423
|
}
|
|
424
|
-
} catch (error) {
|
|
424
|
+
} catch (error: any) {
|
|
425
425
|
console.error('Error fetching related model metadata:', error);
|
|
426
426
|
return value.id ? value.id.toString() : '';
|
|
427
427
|
}
|
|
@@ -129,7 +129,7 @@ export class CRUDService<T extends CommonEntity> { // Add two generic value i.e
|
|
|
129
129
|
await this.saveMedia(model, files, savedEntity);
|
|
130
130
|
}
|
|
131
131
|
return savedEntity;
|
|
132
|
-
} catch (error) {
|
|
132
|
+
} catch (error: any) {
|
|
133
133
|
if (error instanceof QueryFailedError && error.message.includes('duplicate key value violates unique constraint')) {
|
|
134
134
|
throw new BadRequestException(ERROR_MESSAGES.DUPLICATE_ENTRY);
|
|
135
135
|
}
|
|
@@ -920,7 +920,7 @@ export class CRUDService<T extends CommonEntity> { // Add two generic value i.e
|
|
|
920
920
|
);
|
|
921
921
|
|
|
922
922
|
return { message: SUCCESS_MESSAGES.RECORD_RECOVERED, data: softDeletedRows };
|
|
923
|
-
} catch (error) {
|
|
923
|
+
} catch (error: any) {
|
|
924
924
|
if (error instanceof QueryFailedError) {
|
|
925
925
|
if ((error as any).code === '23505') {
|
|
926
926
|
throw new Error(ERROR_MESSAGES.CONFLICTING_RECORD_ON_UNARCHIVE);
|
|
@@ -966,7 +966,7 @@ export class CRUDService<T extends CommonEntity> { // Add two generic value i.e
|
|
|
966
966
|
);
|
|
967
967
|
|
|
968
968
|
return { message: SUCCESS_MESSAGES.SELECTED_RECORDS_RECOVERED, recoveredIds: ids };
|
|
969
|
-
} catch (error) {
|
|
969
|
+
} catch (error: any) {
|
|
970
970
|
if (error instanceof QueryFailedError) {
|
|
971
971
|
if ((error as any).code === "23505") {
|
|
972
972
|
throw new Error(ERROR_MESSAGES.CONFLICTING_RECORD_ON_UNARCHIVE);
|
|
@@ -68,7 +68,7 @@ export class CsvService {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
csvStream.end(); // ✅ Ensure CSV stream is finalized
|
|
71
|
-
} catch (error) {
|
|
71
|
+
} catch (error: any) {
|
|
72
72
|
this.logger.error(`❌ Error writing CSV: ${error.message}`);
|
|
73
73
|
passThrough.destroy(error); // ✅ Properly destroy stream on error
|
|
74
74
|
throw error;
|
|
@@ -117,7 +117,7 @@ export class DashboardService extends CRUDService<Dashboard> {
|
|
|
117
117
|
const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);
|
|
118
118
|
try {
|
|
119
119
|
await fs.access(filePath);
|
|
120
|
-
} catch (error) {
|
|
120
|
+
} catch (error: any) {
|
|
121
121
|
throw new Error(`Configuration file not found for module: ${moduleName}`);
|
|
122
122
|
}
|
|
123
123
|
const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
|
|
@@ -80,7 +80,7 @@ export class DatabaseBootstrapService implements OnModuleInit {
|
|
|
80
80
|
await this.dataSource.query(sql);
|
|
81
81
|
|
|
82
82
|
this.logger.debug(`[${this.dataSource.name}] Applied ${fileName}`);
|
|
83
|
-
} catch (error) {
|
|
83
|
+
} catch (error: any) {
|
|
84
84
|
// DO NOT THROW — continue with next file
|
|
85
85
|
this.logger.error(
|
|
86
86
|
`[${this.dataSource.name}] Failed ${fileName}`,
|
|
@@ -93,7 +93,7 @@ export class ExcelService {
|
|
|
93
93
|
|
|
94
94
|
workbook.commit();
|
|
95
95
|
// passThrough.end(); // ✅ Properly close the stream
|
|
96
|
-
} catch (error) {
|
|
96
|
+
} catch (error: any) {
|
|
97
97
|
this.logger.error(`❌ Error writing Excel: ${error.message}`);
|
|
98
98
|
passThrough.destroy(error); // Destroy stream
|
|
99
99
|
throw error;
|
|
@@ -90,7 +90,7 @@ export class ExportTransactionService extends CRUDService<ExportTransaction> {
|
|
|
90
90
|
const fileName = this.getFileName(templateName, uuid, templateFormat);
|
|
91
91
|
const mimeType = this.getMimeType(templateFormat);
|
|
92
92
|
return { exportStream, fileName, mimeType, exportTransaction };
|
|
93
|
-
} catch (error) {
|
|
93
|
+
} catch (error: any) {
|
|
94
94
|
this.updateExportTransaction(id, ExportStatus.FAILED, error.message);
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
@@ -114,7 +114,7 @@ export class ExportTransactionService extends CRUDService<ExportTransaction> {
|
|
|
114
114
|
// Store the file using the appropriate storage provider
|
|
115
115
|
await this.storeExportStream(exportStream, exportTransaction, this.getFileName(templateName, uuid, templateFormat));
|
|
116
116
|
this.updateExportTransaction(id, ExportStatus.COMPLETED);
|
|
117
|
-
} catch (error) {
|
|
117
|
+
} catch (error: any) {
|
|
118
118
|
this.updateExportTransaction(id, ExportStatus.FAILED, error.message);
|
|
119
119
|
throw error;
|
|
120
120
|
|
|
@@ -745,6 +745,8 @@ export class FieldMetadataService implements OnApplicationBootstrap {
|
|
|
745
745
|
"type",
|
|
746
746
|
"ormType",
|
|
747
747
|
"isSystem",
|
|
748
|
+
"regexPattern",
|
|
749
|
+
"regexPatternNotMatchingErrorMsg",
|
|
748
750
|
"defaultValue",
|
|
749
751
|
"min",
|
|
750
752
|
"max",
|
|
@@ -772,8 +774,6 @@ export class FieldMetadataService implements OnApplicationBootstrap {
|
|
|
772
774
|
"regexPattern",
|
|
773
775
|
"regexPatternNotMatchingErrorMsg",
|
|
774
776
|
"defaultValue",
|
|
775
|
-
"min",
|
|
776
|
-
"max",
|
|
777
777
|
"required",
|
|
778
778
|
"unique",
|
|
779
779
|
"index",
|
|
@@ -1256,7 +1256,7 @@ export class FieldMetadataService implements OnApplicationBootstrap {
|
|
|
1256
1256
|
// Write the updated object back to the file
|
|
1257
1257
|
const updatedContent = JSON.stringify(metaData, null, 2);
|
|
1258
1258
|
await fs.writeFile(filePath, updatedContent);
|
|
1259
|
-
} catch (error) {
|
|
1259
|
+
} catch (error: any) {
|
|
1260
1260
|
this.logger.error('File creation failed:', error);
|
|
1261
1261
|
throw new Error(ERROR_MESSAGES.FILE_WRITE_FAILED); // Trigger rollback
|
|
1262
1262
|
}
|
|
@@ -35,7 +35,7 @@ export class FixturesService {
|
|
|
35
35
|
// Create the model instance in the database
|
|
36
36
|
const createdInstance = await modelServiceInstance.create(modelFixture.data);
|
|
37
37
|
this.logger.log(`Successfully created fixture for model: ${modelFixture.singularName} with ID: ${createdInstance.id}`);
|
|
38
|
-
} catch (error) {
|
|
38
|
+
} catch (error: any) {
|
|
39
39
|
this.logger.error(`Error creating fixture for model: ${modelFixture.singularName} - ${error.message}`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -59,7 +59,7 @@ export class FixturesService {
|
|
|
59
59
|
const deleteCriteria = modelFixture.data; // This should be adjusted based on actual criteria
|
|
60
60
|
await modelServiceInstance.delete(deleteCriteria);
|
|
61
61
|
this.logger.log(`Successfully deleted fixture for model: ${modelFixture.singularName}`);
|
|
62
|
-
} catch (error) {
|
|
62
|
+
} catch (error: any) {
|
|
63
63
|
this.logger.error(`Error deleting fixture for model: ${modelFixture.singularName} - ${error.message}`);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -25,7 +25,7 @@ import { SolidIntrospectService } from './solid-introspect.service';
|
|
|
25
25
|
import { ModelMetadataHelperService } from 'src/helpers/model-metadata-helper.service';
|
|
26
26
|
import { getUserExcludedFields } from 'src/helpers/user-helper';
|
|
27
27
|
import { ActiveUserData } from 'src/interfaces/active-user-data.interface';
|
|
28
|
-
import {upperFirst, camelCase} from 'lodash';
|
|
28
|
+
import { upperFirst, camelCase } from 'lodash';
|
|
29
29
|
import { classify } from '../helpers/string.helper';
|
|
30
30
|
|
|
31
31
|
interface ImportTemplateFileInfo {
|
|
@@ -557,7 +557,7 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
|
|
|
557
557
|
const createdRecord = await this.insertRecord(record, JSON.parse(importTransaction.mapping) as ImportMapping[], importTransaction.modelMetadata, modelService);
|
|
558
558
|
ids.push(createdRecord.id); // Add the ID of the created record to the ids array
|
|
559
559
|
}
|
|
560
|
-
catch (error) {
|
|
560
|
+
catch (error: any) {
|
|
561
561
|
this.logger.debug(`Error inserting record: ${JSON.stringify(record)}. Error: ${error.message}`);
|
|
562
562
|
// Get the Import transaction error log repo
|
|
563
563
|
const errorLog = await this.createErrorLogEntry(importTransaction, record, error);
|