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
4 changes: 2 additions & 2 deletions backend/src/authorization/auth-with-api.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import Sentry from '@sentry/minimal';
import { Request, Response } from 'express';
import { NextFunction, Request, Response } from 'express';
import jwt from 'jsonwebtoken';
import { Repository } from 'typeorm';
import { JwtScopesEnum } from '../entities/user/enums/jwt-scopes.enum.js';
Expand All @@ -29,7 +29,7 @@ export class AuthWithApiMiddleware implements NestMiddleware {
private readonly userRepository: Repository<UserEntity>,
) {}

async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
async use(req: IRequestWithCognitoInfo, _res: Response, next: NextFunction): Promise<void> {
try {
await this.authenticateRequest(req);
next();
Expand Down
4 changes: 2 additions & 2 deletions backend/src/authorization/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import Sentry from '@sentry/minimal';
import { Response } from 'express';
import { NextFunction, Response } from 'express';
import jwt from 'jsonwebtoken';
import { Repository } from 'typeorm';
import { LogOutEntity } from '../entities/log-out/log-out.entity.js';
Expand All @@ -29,7 +29,7 @@ export class AuthMiddleware implements NestMiddleware {
@InjectRepository(LogOutEntity)
private readonly logOutRepository: Repository<LogOutEntity>,
) {}
async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
async use(req: IRequestWithCognitoInfo, _res: Response, next: NextFunction): Promise<void> {
let token: string;
try {
token = req.cookies[Constants.JWT_COOKIE_KEY_NAME];
Expand Down
4 changes: 2 additions & 2 deletions backend/src/authorization/basic-auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
import auth from 'basic-auth';
import { Request, Response } from 'express';
import { NextFunction, Request, Response } from 'express';
import { Messages } from '../exceptions/text/messages.js';
import { appConfig } from '../shared/config/app-config.js';

@Injectable()
export class BasicAuthMiddleware implements NestMiddleware {
use(req: Request, _res: Response, next: (err?: any, res?: any) => void): void {
use(req: Request, _res: Response, next: NextFunction): void {
const basicAuthLogin = appConfig.auth.basicAuthLogin;
const basicAuthPassword = appConfig.auth.basicAuthPassword;
const userCredentials = auth(req);
Expand Down
15 changes: 12 additions & 3 deletions backend/src/authorization/cognito-decoded.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Request } from 'express';

export interface ICognitoDecodedData {
at_hash: string;
sub: string;
Expand All @@ -14,8 +15,16 @@ export interface ICognitoDecodedData {
email: string;
}

export interface IRequestWithCognitoInfo extends Request {
query: any;
/**
* Request type with the cognito-derived JWT payload attached by auth middleware.
*
* `params` and `query` are narrowed to `Record<string, string | undefined>`. Express's stock
* `query` type is `ParsedQs` (allows arrays and nested objects), but this codebase only
* issues simple `?key=value` URLs — narrowing here surfaces accidental multi-value usage
* without forcing every callsite to narrow inline.
*/
export interface IRequestWithCognitoInfo extends Omit<Request, 'query' | 'params'> {
query: Record<string, string | undefined>;
params: Record<string, string | undefined>;
decoded: Partial<ICognitoDecodedData>;
params: any;
}
4 changes: 2 additions & 2 deletions backend/src/authorization/non-scoped-auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import Sentry from '@sentry/minimal';
import { Response } from 'express';
import { NextFunction, Response } from 'express';
import jwt from 'jsonwebtoken';
import { Repository } from 'typeorm';
import { LogOutEntity } from '../entities/log-out/log-out.entity.js';
Expand All @@ -24,7 +24,7 @@ export class NonScopedAuthMiddleware implements NestMiddleware {
@InjectRepository(LogOutEntity)
private readonly logOutRepository: Repository<LogOutEntity>,
) {}
async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
async use(req: IRequestWithCognitoInfo, _res: Response, next: NextFunction): Promise<void> {
console.log(`auth middleware triggered ->: ${new Date().toISOString()}`);
let token: string;
try {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/authorization/saas-auth.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
import { Response } from 'express';
import { NextFunction, Response } from 'express';
import jwt from 'jsonwebtoken';
import { Messages } from '../exceptions/text/messages.js';
import { appConfig } from '../shared/config/app-config.js';
Expand All @@ -8,7 +8,7 @@ import { extractTokenFromHeader } from './utils/extract-token-from-header.js';

@Injectable()
export class SaaSAuthMiddleware implements NestMiddleware {
use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): void {
use(req: IRequestWithCognitoInfo, _res: Response, next: NextFunction): void {
console.log(`saas auth middleware triggered ->: ${new Date().toISOString()}`);
const token = extractTokenFromHeader(req);
if (!token) {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/authorization/temporary-auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import Sentry from '@sentry/minimal';
import { Response } from 'express';
import { NextFunction, Response } from 'express';
import jwt from 'jsonwebtoken';
import { Repository } from 'typeorm';
import { LogOutEntity } from '../entities/log-out/log-out.entity.js';
Expand All @@ -26,7 +26,7 @@ export class TemporaryAuthMiddleware implements NestMiddleware {
@InjectRepository(LogOutEntity)
private readonly logOutRepository: Repository<LogOutEntity>,
) {}
async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
async use(req: IRequestWithCognitoInfo, _res: Response, next: NextFunction): Promise<void> {
console.log(`temporary auth middleware triggered ->: ${new Date().toISOString()}`);
let token: string;
try {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/decorators/body-email.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Messages } from '../exceptions/text/messages.js';
import { isObjectPropertyExists } from '../helpers/validators/is-object-property-exists-validator.js';
import { ValidationHelper } from '../helpers/validators/validation-helper.js';

export const BodyEmail = createParamDecorator((_data: any, ctx: ExecutionContext): string => {
export const BodyEmail = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {
const request: IRequestWithCognitoInfo = ctx.switchToHttp().getRequest();
const body = request.body;
if (isObjectPropertyExists(body, 'email')) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/decorators/gclid-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { IRequestWithCognitoInfo } from '../authorization/cognito-decoded.interface.js';

export const GCLlId = createParamDecorator((_data: any, ctx: ExecutionContext): string => {
export const GCLlId = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {
const request: IRequestWithCognitoInfo = ctx.switchToHttp().getRequest();
if (request.headers) {
return (request.headers.gclid as string | undefined) ?? null;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/decorators/master-password.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { IRequestWithCognitoInfo } from '../authorization/cognito-decoded.interface.js';

export const MasterPassword = createParamDecorator((_data: any, ctx: ExecutionContext): string => {
export const MasterPassword = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {
const request: IRequestWithCognitoInfo = ctx.switchToHttp().getRequest();
const masterPwd = request.headers.masterpwd as string | undefined;
return masterPwd ? masterPwd : null;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/decorators/user-id.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IRequestWithCognitoInfo } from '../authorization/cognito-decoded.interf
import { Messages } from '../exceptions/text/messages.js';
import { ValidationHelper } from '../helpers/validators/validation-helper.js';

export const UserId = createParamDecorator((_data: any, ctx: ExecutionContext): string => {
export const UserId = createParamDecorator((_data: unknown, ctx: ExecutionContext): string => {
const request: IRequestWithCognitoInfo = ctx.switchToHttp().getRequest();
const userId = request.decoded?.sub;
if (!userId) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/entities/ai/ai.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { UserAIRequestsControllerV2 } from './user-ai-requests-v2.controller.js'
controllers: [UserAIRequestsControllerV2, UserAiChatController],
})
export class AIModule implements NestModule {
public configure(consumer: MiddlewareConsumer): any {
public configure(consumer: MiddlewareConsumer): void {
consumer
.apply(AuthMiddleware)
.forRoutes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import AbstractUseCase from '../../../common/abstract-use.case.js';
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
import { BaseType } from '../../../common/data-injection.tokens.js';
import { Messages } from '../../../exceptions/text/messages.js';
import { getErrorMessage } from '../../../helpers/get-error-message.js';
import { isConnectionTypeAgent } from '../../../helpers/is-connection-entity-agent.js';
import { slackPostMessage } from '../../../helpers/slack/slack-post-message.js';
import { ConnectionEntity } from '../../connection/connection.entity.js';
Expand Down Expand Up @@ -192,7 +193,7 @@ export class RequestInfoFromTableWithAIUseCaseV7

depth++;
} catch (loopError) {
this.logger.error(`Error in tool loop at depth ${depth + 1}: ${(loopError as Error).message}`);
this.logger.error(`Error in tool loop at depth ${depth + 1}: ${getErrorMessage(loopError)}`);
throw loopError;
}
}
Expand Down Expand Up @@ -290,7 +291,7 @@ export class RequestInfoFromTableWithAIUseCaseV7
result = encodeError({ error: `Unknown tool: ${toolCall.name}` });
}
} catch (error) {
const errMessage = (error as Error).message;
const errMessage = getErrorMessage(error);
this.logger.error(`Tool call ${toolCall.name} (${toolCall.id}) failed: ${errMessage}`);
result = encodeError({ error: errMessage });
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/entities/api-key/api-key.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class ApiKeyController {
description: 'Api key is valid.',
})
@Get('/check/apikey')
public async checkApiKey(): Promise<any> {
public async checkApiKey(): Promise<{ result: boolean; message: string }> {
return {
result: true,
message: 'Api key is valid',
Expand Down
2 changes: 1 addition & 1 deletion backend/src/entities/api-key/api-key.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { GetUserApiKeyUseCase } from './use-cases/get-user-api-key.use.case.js';
controllers: [ApiKeyController],
})
export class ApiKeyModule implements NestModule {
public configure(consumer: MiddlewareConsumer): any {
public configure(consumer: MiddlewareConsumer): void {
consumer
.apply(AuthMiddleware)
.forRoutes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IGlobalDatabaseContext } from '../../common/application/global-database
import { BaseType } from '../../common/data-injection.tokens.js';
import { Messages } from '../../exceptions/text/messages.js';
import { Cacher } from '../../helpers/cache/cacher.js';
import { getErrorMessage } from '../../helpers/get-error-message.js';
import { GroupEntity } from '../group/group.entity.js';
import { IComplexPermission } from '../permission/permission.interface.js';
import {
Expand Down Expand Up @@ -198,7 +199,7 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
}
} catch (e) {
if (e instanceof HttpException) throw e;
throw new HttpException({ message: `Invalid cedar schema: ${(e as Error).message}` }, HttpStatus.BAD_REQUEST);
throw new HttpException({ message: `Invalid cedar schema: ${getErrorMessage(e)}` }, HttpStatus.BAD_REQUEST);
}
}

Expand Down Expand Up @@ -296,7 +297,7 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
};
cedarWasm.isAuthorized(testCall as Parameters<typeof cedarWasm.isAuthorized>[0]);
} catch (e) {
throw new HttpException({ message: `Invalid cedar policy: ${(e as Error).message}` }, HttpStatus.BAD_REQUEST);
throw new HttpException({ message: `Invalid cedar policy: ${getErrorMessage(e)}` }, HttpStatus.BAD_REQUEST);
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/entities/company-info/company-info.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ import { VerifyInviteUserInCompanyAndConnectionGroupUseCase } from './use-cases/
controllers: [CompanyInfoController],
})
export class CompanyInfoModule implements NestModule {
public configure(consumer: MiddlewareConsumer): any {
public configure(consumer: MiddlewareConsumer): void {
consumer
.apply(AuthMiddleware)
.forRoutes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BaseType } from '../../../common/data-injection.tokens.js';
import { ExceptionOperations } from '../../../exceptions/custom-exceptions/exception-operation.js';
import { UnknownSQLException } from '../../../exceptions/custom-exceptions/unknown-sql-exception.js';
import { Messages } from '../../../exceptions/text/messages.js';
import { getErrorMessage } from '../../../helpers/get-error-message.js';
import { isConnectionTypeAgent } from '../../../helpers/is-connection-entity-agent.js';
import { GetConnectionDiagramDs } from '../application/data-structures/get-connection-diagram.ds.js';
import { ConnectionDiagramResponseDTO } from '../application/dto/connection-diagram-response.dto.js';
Expand Down Expand Up @@ -52,7 +53,7 @@ export class GetConnectionDiagramUseCase
try {
tables = await dao.getTablesFromDB(userEmail);
} catch (e) {
throw new UnknownSQLException((e as Error).message, ExceptionOperations.FAILED_TO_GET_TABLES);
throw new UnknownSQLException(getErrorMessage(e), ExceptionOperations.FAILED_TO_GET_TABLES);
}

const realTables = tables.filter((t) => !t.isView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BaseType } from '../../../common/data-injection.tokens.js';
import { ExceptionOperations } from '../../../exceptions/custom-exceptions/exception-operation.js';
import { UnknownSQLException } from '../../../exceptions/custom-exceptions/unknown-sql-exception.js';
import { Messages } from '../../../exceptions/text/messages.js';
import { getErrorMessage } from '../../../helpers/get-error-message.js';
import { isConnectionTypeAgent } from '../../../helpers/is-connection-entity-agent.js';
import { PreviewConnectionDiagramDs } from '../application/data-structures/preview-connection-diagram.ds.js';
import { ConnectionDiagramPreviewResponseDTO } from '../application/dto/connection-diagram-preview-response.dto.js';
Expand Down Expand Up @@ -53,7 +54,7 @@ export class PreviewConnectionDiagramUseCase
try {
tables = await dao.getTablesFromDB(userEmail);
} catch (e) {
throw new UnknownSQLException((e as Error).message, ExceptionOperations.FAILED_TO_GET_TABLES);
throw new UnknownSQLException(getErrorMessage(e), ExceptionOperations.FAILED_TO_GET_TABLES);
}

const realTables = tables.filter((t) => !t.isView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PrimaryKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-laye
import { TableStructureDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/table-structure.ds.js';
import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js';
import sqlParser from 'node-sql-parser';
import { getErrorMessage } from '../../../helpers/get-error-message.js';
import { connectionTypeToParserDialect } from '../../table-schema/utils/assert-dialect-supported.js';
import { MermaidTableInput } from './build-mermaid-er-diagram.util.js';

Expand Down Expand Up @@ -65,7 +66,7 @@ export function applyProposedDdl(
diff.statementResults.push({
sql,
status: 'error',
message: `parse error: ${(err as Error).message}`,
message: `parse error: ${getErrorMessage(err)}`,
});
continue;
}
Expand All @@ -82,7 +83,7 @@ export function applyProposedDdl(
diff.statementResults.push({
sql,
status: 'error',
message: (err as Error).message,
message: getErrorMessage(err),
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions backend/src/entities/convention/conversion.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ export class ConversionController {
) {}

@Get('/conversions')
async getConversions(@Res() res: Response): Promise<any> {
async getConversions(@Res() res: Response): Promise<void> {
const csvData = await this.getConversionsUseCase.execute(undefined, InTransactionEnum.OFF);
res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename=conversions.csv');
res.status(200).end(csvData);
return;
}
}
2 changes: 1 addition & 1 deletion backend/src/entities/convention/conversion.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { GetConversionsUseCase } from './use-cases/get-conversions.use.case.js';
controllers: [ConversionController],
})
export class ConversionModule implements NestModule {
public configure(consumer: MiddlewareConsumer): any {
public configure(consumer: MiddlewareConsumer): void {
consumer.apply(BasicAuthMiddleware).forRoutes({ path: '/conversions', method: RequestMethod.GET });
}
}
2 changes: 1 addition & 1 deletion backend/src/entities/custom-field/custom-field.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { UpdateCustomFieldUseCase } from './use-cases/update-custom-field.use.ca
exports: [],
})
export class CustomFieldModule {
public configure(consumer: MiddlewareConsumer): any {
public configure(consumer: MiddlewareConsumer): void {
consumer
.apply(AuthMiddleware)
.forRoutes(
Expand Down
3 changes: 2 additions & 1 deletion backend/src/entities/demo-data/demo-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TableActionEventEnum } from '../../enums/table-action-event-enum.js';
import { TableActionTypeEnum } from '../../enums/table-action-type.enum.js';
import { isTest } from '../../helpers/app/is-test.js';
import { Constants } from '../../helpers/constants/constants.js';
import { getErrorMessage } from '../../helpers/get-error-message.js';
import { slackPostMessage } from '../../helpers/slack/slack-post-message.js';
import { generateCedarPolicyForGroup } from '../cedar-authorization/cedar-policy-generator.js';
import { ConnectionEntity } from '../connection/connection.entity.js';
Expand Down Expand Up @@ -43,7 +44,7 @@ export class DemoDataService {
return await this.createDemoData(userId);
} catch (error) {
console.error(`Error during demo data creation for user with ID ${userId}:`, error);
await slackPostMessage(`Error during demo data creation for user with ID ${userId}: ${(error as Error).message}`);
await slackPostMessage(`Error during demo data creation for user with ID ${userId}: ${getErrorMessage(error)}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/entities/demo-data/demo-deta.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ import { DemoDataService } from './demo-data.service.js';
exports: [DemoDataService],
})
export class DemoDataModule {
public configure(_consumer: MiddlewareConsumer): any {}
public configure(_consumer: MiddlewareConsumer): void {}
}
3 changes: 2 additions & 1 deletion backend/src/entities/email/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BaseType } from '../../../common/data-injection.tokens.js';
import { TableActionEventEnum } from '../../../enums/table-action-event-enum.js';
import { isTest } from '../../../helpers/app/is-test.js';
import { Constants } from '../../../helpers/constants/constants.js';
import { getErrorMessage } from '../../../helpers/get-error-message.js';
import { appConfig } from '../../../shared/config/app-config.js';
import { WinstonLogger } from '../../logging/winston-logger.js';
import { UserInfoMessageData } from '../../table-actions/table-actions-module/table-action-activation.service.js';
Expand Down Expand Up @@ -92,7 +93,7 @@ export class EmailService {
});
mailingResults.push(result);
} catch (error) {
this.logger.error(`Failed to send reminder to ${email}: ${(error as Error).message}`);
this.logger.error(`Failed to send reminder to ${email}: ${getErrorMessage(error)}`);
Sentry.captureException(error);
mailingResults.push(null);
}
Expand Down
Loading
Loading