Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { InviteUserInCompanyAndConnectionGroupDs } from '../application/data-str
import { IInviteUserInCompanyAndConnectionGroup } from './company-info-use-cases.interface.js';
import { InvitedUserInCompanyAndConnectionGroupDs } from '../application/data-structures/invited-user-in-company-and-connection-group.ds.js';
import { Messages } from '../../../exceptions/text/messages.js';
import { Logger } from '../../../helpers/logging/Logger.js';
import { isSaaS } from '../../../helpers/app/is-saas.js';
import { SaasCompanyGatewayService } from '../../../microservices/gateways/saas-gateway.ts/saas-company-gateway.service.js';
import { isTest } from '../../../helpers/app/is-test.js';
import { EmailService } from '../../email/email/email.service.js';
import { CompanyInfoHelperService } from '../company-info-helper.service.js';
import { WinstonLogger } from '../../logging/winston-logger.js';

@Injectable({ scope: Scope.REQUEST })
export class InviteUserInCompanyAndConnectionGroupUseCase
Expand All @@ -24,6 +24,7 @@ export class InviteUserInCompanyAndConnectionGroupUseCase
private readonly saasCompanyGatewayService: SaasCompanyGatewayService,
private readonly emailService: EmailService,
private readonly companyInfoHelperService: CompanyInfoHelperService,
private readonly logger: WinstonLogger,
) {
super();
}
Expand Down Expand Up @@ -90,7 +91,7 @@ export class InviteUserInCompanyAndConnectionGroupUseCase
}

if (!isSaaS()) {
Logger.printTechString(`Invitation verification string: ${renewedEmailVerification.verification_string}`);
this.logger.printTechString(`Invitation verification string: ${renewedEmailVerification.verification_string}`);
}
throw new HttpException(
{
Expand Down
29 changes: 15 additions & 14 deletions backend/src/entities/email/email/email.service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { IMessage } from './email.interface.js';
import { EmailTransporterService } from '../transporter/email-transporter-service.js';
import { EmailGenerator } from './email.generator.js';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import { EmailLetter } from '../email-messages/email-message.js';
import { Inject, Injectable } from '@nestjs/common';
import * as nunjucks from 'nunjucks';
import * as Sentry from '@sentry/node';
import { getProcessVariable } from '../../../helpers/get-process-variable.js';
import { Constants } from '../../../helpers/constants/constants.js';
import { BaseType } from '../../../common/data-injection.tokens.js';
import { Logger } from '../../../helpers/logging/Logger.js';
import PQueue from 'p-queue';
import Mail from 'nodemailer/lib/mailer/index.js';
import { EMAIL_TEXT } from '../email-text/email-text.js';
import { escapeHtml } from '../utils/escape-html.util.js';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import * as nunjucks from 'nunjucks';
import PQueue from 'p-queue';
import { BaseType } from '../../../common/data-injection.tokens.js';
import { TableActionEventEnum } from '../../../enums/table-action-event-enum.js';
import { Constants } from '../../../helpers/constants/constants.js';
import { getProcessVariable } from '../../../helpers/get-process-variable.js';
import { WinstonLogger } from '../../logging/winston-logger.js';
import { UserInfoMessageData } from '../../table-actions/table-actions-module/table-action-activation.service.js';
import { EmailLetter } from '../email-messages/email-message.js';
import { EMAIL_TEXT } from '../email-text/email-text.js';
import { EmailTransporterService } from '../transporter/email-transporter-service.js';
import { escapeHtml } from '../utils/escape-html.util.js';
import { EmailGenerator } from './email.generator.js';
import { IMessage } from './email.interface.js';

export interface ICronMessagingResults {
messageId?: string;
Expand All @@ -30,6 +30,7 @@ export class EmailService {
@Inject(BaseType.NUNJUCKS)
private readonly nunjucksEnv: nunjucks.Environment,
private readonly emailTransporterService: EmailTransporterService,
private readonly logger: WinstonLogger,
) {}

public async sendEmailToUser(letterContent: IMessage): Promise<SMTPTransport.SentMessageInfo | null> {
Expand Down Expand Up @@ -106,7 +107,7 @@ export class EmailService {
);
return mailingResults;
} catch (error) {
Logger.logError(error);
this.logger.error(error);
}
}

Expand Down
18 changes: 11 additions & 7 deletions backend/src/entities/logging/winston-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,38 @@ export class WinstonLogger implements LoggerService {
});
}

log(message: any, ...optionalParams: any[]) {
public log(message: any, ...optionalParams: any[]) {
this.logger.info(message, ...optionalParams);
}

error(message: any, ...optionalParams: any[]) {
public error(message: any, ...optionalParams: any[]) {
this.logger.error(message, ...optionalParams);
}

warn(message: any, ...optionalParams: any[]) {
public warn(message: any, ...optionalParams: any[]) {
this.logger.warn(message, ...optionalParams);
}

logWithSlack(message: any, ...optionalParams: any[]) {
public logWithSlack(message: any, ...optionalParams: any[]) {
this.logger.error(message, ...optionalParams);
slackPostMessage(message).catch((error) => {
this.logger.error('Failed to send Slack message', error);
});
}

debug(message: any, ...optionalParams: any[]) {
public printTechString(str: string): void {
this.logger.info(`\n ${str} \n`);
}

public debug(message: any, ...optionalParams: any[]) {
this.logger.debug(message, ...optionalParams);
}

verbose(message: any, ...optionalParams: any[]) {
public verbose(message: any, ...optionalParams: any[]) {
this.logger.verbose(message, ...optionalParams);
}

fatal(message: any, ...optionalParams: any[]) {
public fatal(message: any, ...optionalParams: any[]) {
this.logger.error(message, ...optionalParams);
slackPostMessage(message).catch((error) => {
this.logger.error('Failed to send Slack message', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ExceptionOperations } from '../../../exceptions/custom-exceptions/excep
import { UnknownSQLException } from '../../../exceptions/custom-exceptions/unknown-sql-exception.js';
import { Messages } from '../../../exceptions/text/messages.js';
import { isConnectionTypeAgent } from '../../../helpers/index.js';
import { Logger } from '../../../helpers/logging/Logger.js';
import { isObjectPropertyExists } from '../../../helpers/validators/is-object-property-exists-validator.js';
import { AmplitudeService } from '../../amplitude/amplitude.service.js';
import { ConnectionEntity } from '../../connection/connection.entity.js';
Expand All @@ -24,6 +23,7 @@ import { FindTablesDs } from '../application/data-structures/find-tables.ds.js';
import { FoundTableDs } from '../application/data-structures/found-table.ds.js';
import { buildTableFieldInfoEntity, buildTableInfoEntity } from '../utils/save-tables-info-in-database.util.js';
import { IFindTablesInConnection } from './table-use-cases.interface.js';
import { WinstonLogger } from '../../logging/winston-logger.js';

@Injectable()
export class FindTablesInConnectionUseCase
Expand All @@ -34,6 +34,7 @@ export class FindTablesInConnectionUseCase
@Inject(BaseType.GLOBAL_DB_CONTEXT)
protected _dbContext: IGlobalDatabaseContext,
private amplitudeService: AmplitudeService,
private readonly logger: WinstonLogger,
) {
super();
}
Expand Down Expand Up @@ -87,7 +88,7 @@ export class FindTablesInConnectionUseCase
throw new UnknownSQLException(e.message, ExceptionOperations.FAILED_TO_GET_TABLES);
} finally {
if (!connection.isTestConnection && tables && tables.length) {
Logger.logInfo({
this.logger.log({
tables: tables.map((table) => table.tableName),
connectionId: connectionId,
connectionType: connection.type,
Expand Down
14 changes: 10 additions & 4 deletions backend/src/entities/widget/utils/validate-create-widgets-ds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,25 @@ export async function validateCreateWidgetsDs(
}
}
const { widget_type } = widgetDS;

// if (widget_type) {
// if (!Object.keys(WidgetTypeEnum).find((key) => key === widget_type)) {
// errors.push(Messages.WIDGET_TYPE_INCORRECT);
// }
// }
if (widget_type && widget_type === WidgetTypeEnum.Password) {
let { widget_params } = widgetDS;
if (typeof widget_params === 'string') {
widget_params = JSON5.parse(widget_params);
}

if (
widgetDS.widget_params['algorithm'] &&
!Object.keys(EncryptionAlgorithmEnum).find((key) => key === widgetDS.widget_params['algorithm'])
widget_params['algorithm'] &&
!Object.keys(EncryptionAlgorithmEnum).find((key) => key === widget_params['algorithm'])
) {
errors.push(Messages.ENCRYPTION_ALGORITHM_INCORRECT(widgetDS.widget_params['algorithm']));
errors.push(Messages.ENCRYPTION_ALGORITHM_INCORRECT(widget_params['algorithm']));
}
if (widgetDS.widget_params['encrypt'] === undefined) {
if (widget_params['encrypt'] === undefined) {
errors.push(Messages.WIDGET_REQUIRED_PARAMETER_MISSING('encrypt'));
}
}
Expand Down
6 changes: 4 additions & 2 deletions backend/src/exceptions/all-exceptions.filter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ArgumentsHost, Catch, ExceptionFilter, HttpException, HttpStatus } from '@nestjs/common';
import { Logger } from '../helpers/logging/Logger.js';

import { processExceptionMessage } from './utils/process-exception-message.js';
import Sentry from '@sentry/minimal';
import { Messages } from './text/messages.js';
import { WinstonLogger } from '../entities/logging/winston-logger.js';

export type ExceptionType = 'no_master_key' | 'invalid_master_key' | 'query_timeout';
@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
constructor(private readonly logger: WinstonLogger) {}
async catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
Expand All @@ -28,7 +30,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
Sentry.captureException(exception, sentryContextObject);

if (status === 500 || status === 408) {
Logger.logError(exception);
this.logger.error(exception);
}

const customExceptionType = this.getErrorType(text);
Expand Down
31 changes: 0 additions & 31 deletions backend/src/helpers/logging/Logger.ts

This file was deleted.

2 changes: 1 addition & 1 deletion backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function bootstrap() {
const globalPrefix = process.env.GLOBAL_PREFIX || '/';
app.setGlobalPrefix(globalPrefix);

app.useGlobalFilters(new AllExceptionsFilter());
app.useGlobalFilters(new AllExceptionsFilter(app.get(WinstonLogger)));

app.use(helmet());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { nanoid } from 'nanoid';
import { Constants } from '../../../src/helpers/constants/constants.js';
import { Messages } from '../../../src/exceptions/text/messages.js';
import { Cacher } from '../../../src/helpers/cache/cacher.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

const mockFactory = new MockFactory();
let app: INestApplication;
Expand All @@ -36,7 +37,7 @@ test.before(async () => {
testUtils = moduleFixture.get<TestUtils>(TestUtils);

app.use(cookieParser());
app.useGlobalFilters(new AllExceptionsFilter());
app.useGlobalFilters(new AllExceptionsFilter(app.get(WinstonLogger)));
app.useGlobalPipes(
new ValidationPipe({
exceptionFactory(validationErrors: ValidationError[] = []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ValidationException } from '../../../src/exceptions/custom-exceptions/v
import { ValidationError } from 'class-validator';
import { ErrorsMessages } from '../../../src/exceptions/custom-exceptions/messages/custom-errors-messages.js';
import { Cacher } from '../../../src/helpers/cache/cacher.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

const mockFactory = new MockFactory();
let app: INestApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { setSaasEnvVariable } from '../../utils/set-saas-env-variable.js';
import { ValidationException } from '../../../src/exceptions/custom-exceptions/validation-exception.js';
import { ValidationError } from 'class-validator';
import { Cacher } from '../../../src/helpers/cache/cacher.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

const mockFactory = new MockFactory();
let app: INestApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import { ValidationException } from '../../../src/exceptions/custom-exceptions/v
import { ValidationError } from 'class-validator';
import { ErrorsMessages } from '../../../src/exceptions/custom-exceptions/messages/custom-errors-messages.js';
import { Cacher } from '../../../src/helpers/cache/cacher.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

let app: INestApplication;
let testUtils: TestUtils;

const mockFactory = new MockFactory();

const masterPwd = 'ahalaimahalai';
Expand All @@ -46,7 +48,7 @@ test.before(async () => {
testUtils = moduleFixture.get<TestUtils>(TestUtils);

app.use(cookieParser());
app.useGlobalFilters(new AllExceptionsFilter());
app.useGlobalFilters(new AllExceptionsFilter(app.get(WinstonLogger)));
app.useGlobalPipes(
new ValidationPipe({
exceptionFactory(validationErrors: ValidationError[] = []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import { ValidationException } from '../../../src/exceptions/custom-exceptions/v
import { ValidationError } from 'class-validator';
import { ErrorsMessages } from '../../../src/exceptions/custom-exceptions/messages/custom-errors-messages.js';
import { Cacher } from '../../../src/helpers/cache/cacher.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

let app: INestApplication;
let testUtils: TestUtils;

const mockFactory = new MockFactory();

test.before(async () => {
Expand All @@ -38,7 +40,7 @@ test.before(async () => {
testUtils = moduleFixture.get<TestUtils>(TestUtils);

app.use(cookieParser());
app.useGlobalFilters(new AllExceptionsFilter());
app.useGlobalFilters(new AllExceptionsFilter(app.get(WinstonLogger)));

app.useGlobalPipes(
new ValidationPipe({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { setSaasEnvVariable } from '../../utils/set-saas-env-variable.js';
import { ValidationException } from '../../../src/exceptions/custom-exceptions/validation-exception.js';
import { ValidationError } from 'class-validator';
import { Cacher } from '../../../src/helpers/cache/cacher.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

let app: INestApplication;
let testUtils: TestUtils;
Expand All @@ -36,7 +37,7 @@ test.before(async () => {
testUtils = moduleFixture.get<TestUtils>(TestUtils);

app.use(cookieParser());
app.useGlobalFilters(new AllExceptionsFilter());
app.useGlobalFilters(new AllExceptionsFilter(app.get(WinstonLogger)));
app.useGlobalPipes(
new ValidationPipe({
exceptionFactory(validationErrors: ValidationError[] = []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { setSaasEnvVariable } from '../../utils/set-saas-env-variable.js';
import { ValidationException } from '../../../src/exceptions/custom-exceptions/validation-exception.js';
import { ValidationError } from 'class-validator';
import { Cacher } from '../../../src/helpers/cache/cacher.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

const mockFactory = new MockFactory();
let app: INestApplication;
Expand All @@ -37,7 +38,7 @@ test.before(async () => {
testUtils = moduleFixture.get<TestUtils>(TestUtils);

app.use(cookieParser());
app.useGlobalFilters(new AllExceptionsFilter());
app.useGlobalFilters(new AllExceptionsFilter(app.get(WinstonLogger)));
app.useGlobalPipes(
new ValidationPipe({
exceptionFactory(validationErrors: ValidationError[] = []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { getTestData } from '../../utils/get-test-data.js';
import { registerUserAndReturnUserInfo } from '../../utils/register-user-and-return-user-info.js';
import { TestUtils } from '../../utils/test.utils.js';
import { setSaasEnvVariable } from '../../utils/set-saas-env-variable.js';
import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

Expand All @@ -46,7 +48,7 @@ test.before(async () => {
testUtils = moduleFixture.get<TestUtils>(TestUtils);

app.use(cookieParser());
app.useGlobalFilters(new AllExceptionsFilter());
app.useGlobalFilters(new AllExceptionsFilter(app.get(WinstonLogger)));
app.useGlobalPipes(
new ValidationPipe({
exceptionFactory(validationErrors: ValidationError[] = []) {
Expand Down
Loading