Skip to content

Commit 9fdd9ef

Browse files
authored
biome autofix (#1478)
* biome autofix * types fix * remove unused imports * frontend tsc * fix ts type
1 parent 059e4c5 commit 9fdd9ef

File tree

323 files changed

+8832
-9652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+8832
-9652
lines changed

autoadmin-ws-server/src/constants/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const CONSTANTS = Object.freeze({
1919

2020
RES_CACHE_OPTIONS: {
2121
max: 5000,
22-
dispose: function(key, n) {
22+
dispose: (_key, n) => {
2323
n?.send('Connection was closed by timeout');
2424
},
2525
maxAge: 600000,

autoadmin-ws-server/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import axios from 'axios';
33
const app = express();
44
import { createServer } from 'http';
55
const httpServer = createServer(app);
6-
const wsServer = createServer((req, res) => {
6+
const wsServer = createServer((_req, res) => {
77
res.writeHead(200);
88
res.end();
99
});
1010
import WebSocket, { WebSocketServer } from 'ws';
11-
const router = Router();
11+
const _router = Router();
1212
import commandRoute from './routes/command.js';
1313
import {
1414
getCacheWsConnection,
@@ -29,7 +29,7 @@ const tokenCacheResult = new LRUCache(CONSTANTS.TOKEN_RESULT_CACHE_OPTIONS);
2929

3030
app.use(json());
3131

32-
app.get('/', (req, res) => {
32+
app.get('/', (_req, res) => {
3333
res.json({ status: CONSTANTS.API_IS_RUNNING });
3434
});
3535

@@ -42,7 +42,7 @@ wsServer.listen(wsPort, () => {
4242
const ws = new WebSocketServer({ server: wsServer });
4343

4444
ws.on('connection', (connection, req) => {
45-
const ip = req.socket.remoteAddress;
45+
const _ip = req.socket.remoteAddress;
4646
// console.log(`Connected ${ip}`);
4747

4848
connection.on('message', async (message) => {

backend/src/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
22
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
33
import { ScheduleModule } from '@nestjs/schedule';
4-
import { DataSource } from 'typeorm';
54
import { AppController } from './app.controller.js';
65
import { GlobalDatabaseContext } from './common/application/global-database-context.js';
76
import { BaseType, UseCaseType } from './common/data-injection.tokens.js';
@@ -107,7 +106,6 @@ import { SignInAuditModule } from './entities/user-sign-in-audit/sign-in-audit.m
107106
],
108107
})
109108
export class ApplicationModule implements NestModule {
110-
constructor(private dataSource: DataSource) {}
111109
configure(consumer: MiddlewareConsumer): void {
112110
consumer.apply(AppLoggerMiddleware).forRoutes('*');
113111
}

backend/src/authorization/auth-with-api.middleware.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import jwt from 'jsonwebtoken';
1919
import Sentry from '@sentry/minimal';
2020
import { Encryptor } from '../helpers/encryption/encryptor.js';
2121
import { EncryptionAlgorithmEnum } from '../enums/encryption-algorithm.enum.js';
22+
import { IRequestWithCognitoInfo } from './cognito-decoded.interface.js';
2223

2324
@Injectable()
2425
export class AuthWithApiMiddleware implements NestMiddleware {
@@ -27,7 +28,7 @@ export class AuthWithApiMiddleware implements NestMiddleware {
2728
private readonly userRepository: Repository<UserEntity>,
2829
) {}
2930

30-
async use(req: Request, res: Response, next: (err?: any, res?: any) => void): Promise<void> {
31+
async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
3132
try {
3233
await this.authenticateRequest(req);
3334
next();
@@ -37,7 +38,7 @@ export class AuthWithApiMiddleware implements NestMiddleware {
3738
}
3839
}
3940

40-
private async authenticateRequest(req: Request): Promise<void> {
41+
private async authenticateRequest(req: IRequestWithCognitoInfo): Promise<void> {
4142
const tokenFromCookie = this.getTokenFromCookie(req);
4243
if (tokenFromCookie) {
4344
await this.authenticateWithToken(tokenFromCookie, req);
@@ -57,15 +58,15 @@ export class AuthWithApiMiddleware implements NestMiddleware {
5758
throw new InternalServerErrorException(Messages.AUTHORIZATION_REJECTED);
5859
}
5960

60-
private async authenticateWithToken(tokenFromCookie: string, req: Request): Promise<void> {
61+
private async authenticateWithToken(tokenFromCookie: string, req: IRequestWithCognitoInfo): Promise<void> {
6162
try {
6263
const jwtSecret = process.env.JWT_SECRET;
63-
const data = jwt.verify(tokenFromCookie, jwtSecret);
64-
const userId = data['id'];
64+
const data = jwt.verify(tokenFromCookie, jwtSecret) as jwt.JwtPayload;
65+
const userId = data.id;
6566
if (!userId) {
6667
throw new UnauthorizedException('JWT verification failed');
6768
}
68-
const addedScope: Array<JwtScopesEnum> = data['scope'];
69+
const addedScope: Array<JwtScopesEnum> = data.scope;
6970
if (addedScope && addedScope.length > 0) {
7071
if (addedScope.includes(JwtScopesEnum.TWO_FA_ENABLE)) {
7172
throw new BadRequestException(Messages.TWO_FA_REQUIRED);
@@ -74,21 +75,21 @@ export class AuthWithApiMiddleware implements NestMiddleware {
7475

7576
const payload = {
7677
sub: userId,
77-
email: data['email'],
78-
exp: data['exp'],
79-
iat: data['iat'],
78+
email: data.email,
79+
exp: data.exp,
80+
iat: data.iat,
8081
};
8182
if (!payload || isObjectEmpty(payload)) {
8283
throw new UnauthorizedException('JWT verification failed');
8384
}
84-
req['decoded'] = payload;
85+
req.decoded = payload;
8586
} catch (error) {
8687
Sentry.captureException(error);
8788
throw error;
8889
}
8990
}
9091

91-
private async authenticateWithApiKey(req: Request): Promise<void> {
92+
private async authenticateWithApiKey(req: IRequestWithCognitoInfo): Promise<void> {
9293
let apiKey = req.headers?.['x-api-key'];
9394
if (Array.isArray(apiKey)) {
9495
apiKey = apiKey[0];
@@ -106,7 +107,7 @@ export class AuthWithApiMiddleware implements NestMiddleware {
106107
if (!foundUserByApiKey) {
107108
throw new NotFoundException(Messages.NO_AUTH_KEYS_FOUND);
108109
}
109-
req['decoded'] = {
110+
req.decoded = {
110111
sub: foundUserByApiKey.id,
111112
email: foundUserByApiKey.email,
112113
};

backend/src/authorization/auth.middleware.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
UnauthorizedException,
88
} from '@nestjs/common';
99
import { InjectRepository } from '@nestjs/typeorm';
10-
import { Request, Response } from 'express';
10+
import { Response } from 'express';
1111
import jwt from 'jsonwebtoken';
1212
import { Repository } from 'typeorm';
1313
import { LogOutEntity } from '../entities/log-out/log-out.entity.js';
@@ -17,16 +17,16 @@ import { isObjectEmpty } from '../helpers/index.js';
1717
import { Constants } from '../helpers/constants/constants.js';
1818
import Sentry from '@sentry/minimal';
1919
import { JwtScopesEnum } from '../entities/user/enums/jwt-scopes.enum.js';
20+
import { IRequestWithCognitoInfo } from './cognito-decoded.interface.js';
2021

2122
@Injectable()
2223
export class AuthMiddleware implements NestMiddleware {
2324
public constructor(
24-
@InjectRepository(UserEntity)
25-
private readonly userRepository: Repository<UserEntity>,
25+
@InjectRepository(UserEntity)readonly _userRepository: Repository<UserEntity>,
2626
@InjectRepository(LogOutEntity)
2727
private readonly logOutRepository: Repository<LogOutEntity>,
2828
) {}
29-
async use(req: Request, res: Response, next: (err?: any, res?: any) => void): Promise<void> {
29+
async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
3030
let token: string;
3131
try {
3232
token = req.cookies[Constants.JWT_COOKIE_KEY_NAME];
@@ -47,12 +47,12 @@ export class AuthMiddleware implements NestMiddleware {
4747

4848
try {
4949
const jwtSecret = process.env.JWT_SECRET;
50-
const data = jwt.verify(token, jwtSecret);
51-
const userId = data['id'];
50+
const data = jwt.verify(token, jwtSecret) as jwt.JwtPayload;
51+
const userId = data.id;
5252
if (!userId) {
5353
throw new UnauthorizedException('JWT verification failed');
5454
}
55-
const addedScope: Array<JwtScopesEnum> = data['scope'];
55+
const addedScope: Array<JwtScopesEnum> = data.scope;
5656
if (addedScope && addedScope.length > 0) {
5757
if (addedScope.includes(JwtScopesEnum.TWO_FA_ENABLE)) {
5858
throw new BadRequestException(Messages.TWO_FA_REQUIRED);
@@ -61,14 +61,14 @@ export class AuthMiddleware implements NestMiddleware {
6161

6262
const payload = {
6363
sub: userId,
64-
email: data['email'],
65-
exp: data['exp'],
66-
iat: data['iat'],
64+
email: data.email,
65+
exp: data.exp,
66+
iat: data.iat,
6767
};
6868
if (!payload || isObjectEmpty(payload)) {
6969
throw new UnauthorizedException('JWT verification failed');
7070
}
71-
req['decoded'] = payload;
71+
req.decoded = payload;
7272
next();
7373
} catch (e) {
7474
Sentry.captureException(e);

backend/src/authorization/basic-auth.middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Messages } from '../exceptions/text/messages.js';
55

66
@Injectable()
77
export class BasicAuthMiddleware implements NestMiddleware {
8-
use(req: Request, res: Response, next: (err?: any, res?: any) => void): void {
8+
use(req: Request, _res: Response, next: (err?: any, res?: any) => void): void {
99
const basicAuthLogin = process.env.BASIC_AUTH_LOGIN;
1010
const basicAuthPassword = process.env.BASIC_AUTH_PWD;
1111
const userCredentials = auth(req);

backend/src/authorization/cognito-decoded.interface.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import type { Request } from 'express';
12
export interface ICognitoDecodedData {
23
at_hash: string;
34
sub: string;
4-
aud: string;
5+
aud: string | string[];
56
email_verified: boolean;
67
event_id: string;
78
token_use: string;
@@ -15,6 +16,6 @@ export interface ICognitoDecodedData {
1516

1617
export interface IRequestWithCognitoInfo extends Request {
1718
query: any;
18-
decoded: ICognitoDecodedData;
19+
decoded: Partial<ICognitoDecodedData>;
1920
params: any;
2021
}

backend/src/authorization/non-scoped-auth.middleware.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ import {
66
UnauthorizedException,
77
} from '@nestjs/common';
88
import { InjectRepository } from '@nestjs/typeorm';
9-
import { Request, Response } from 'express';
9+
import { Response } from 'express';
1010
import jwt from 'jsonwebtoken';
1111
import { Repository } from 'typeorm';
1212
import { LogOutEntity } from '../entities/log-out/log-out.entity.js';
1313
import { Messages } from '../exceptions/text/messages.js';
1414
import { isObjectEmpty } from '../helpers/index.js';
1515
import { Constants } from '../helpers/constants/constants.js';
1616
import Sentry from '@sentry/minimal';
17+
import { IRequestWithCognitoInfo } from './cognito-decoded.interface.js';
1718

1819
@Injectable()
1920
export class NonScopedAuthMiddleware implements NestMiddleware {
2021
public constructor(
2122
@InjectRepository(LogOutEntity)
2223
private readonly logOutRepository: Repository<LogOutEntity>,
2324
) {}
24-
async use(req: Request, res: Response, next: (err?: any, res?: any) => void): Promise<void> {
25+
async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
2526
console.log(`auth middleware triggered ->: ${new Date().toISOString()}`);
2627
let token: string;
2728
try {
@@ -43,22 +44,22 @@ export class NonScopedAuthMiddleware implements NestMiddleware {
4344

4445
try {
4546
const jwtSecret = process.env.JWT_SECRET;
46-
const data = jwt.verify(token, jwtSecret);
47-
const userId = data['id'];
47+
const data = jwt.verify(token, jwtSecret) as jwt.JwtPayload;
48+
const userId = data.id;
4849
if (!userId) {
4950
throw new UnauthorizedException('JWT verification failed');
5051
}
5152

5253
const payload = {
5354
sub: userId,
54-
email: data['email'],
55-
exp: data['exp'],
56-
iat: data['iat'],
55+
email: data.email,
56+
exp: data.exp,
57+
iat: data.iat,
5758
};
5859
if (!payload || isObjectEmpty(payload)) {
5960
throw new UnauthorizedException('JWT verification failed');
6061
}
61-
req['decoded'] = payload;
62+
req.decoded = payload;
6263
next();
6364
} catch (e) {
6465
Sentry.captureException(e);

backend/src/authorization/saas-auth.middleware.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
2-
import { Request, Response } from 'express';
2+
import { Response } from 'express';
33
import jwt from 'jsonwebtoken';
44
import { Messages } from '../exceptions/text/messages.js';
55
import { extractTokenFromHeader } from './utils/extract-token-from-header.js';
6+
import { IRequestWithCognitoInfo } from './cognito-decoded.interface.js';
67

78
@Injectable()
89
export class SaaSAuthMiddleware implements NestMiddleware {
9-
use(req: Request, res: Response, next: (err?: any, res?: any) => void): void {
10+
use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): void {
1011
console.log(`saas auth middleware triggered ->: ${new Date().toISOString()}`);
1112
const token = extractTokenFromHeader(req);
1213
if (!token) {
1314
throw new UnauthorizedException('Token is missing');
1415
}
1516
try {
1617
const jwtSecret = process.env.MICROSERVICE_JWT_SECRET;
17-
const data = jwt.verify(token, jwtSecret);
18-
const requestId = data['request_id'];
18+
const data = jwt.verify(token, jwtSecret) as jwt.JwtPayload;
19+
const requestId = data.request_id;
1920

2021
if (!requestId) {
2122
throw new UnauthorizedException(Messages.AUTHORIZATION_REJECTED);
2223
}
2324

24-
req['decoded'] = data;
25+
req.decoded = data;
2526
next();
2627
} catch (_e) {
2728
throw new UnauthorizedException(Messages.AUTHORIZATION_REJECTED);

backend/src/authorization/temporary-auth.middleware.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
UnauthorizedException,
77
} from '@nestjs/common';
88
import { InjectRepository } from '@nestjs/typeorm';
9-
import { Request, Response } from 'express';
9+
import { Response } from 'express';
1010
import jwt from 'jsonwebtoken';
1111
import { Repository } from 'typeorm';
1212
import { LogOutEntity } from '../entities/log-out/log-out.entity.js';
@@ -15,16 +15,16 @@ import { Messages } from '../exceptions/text/messages.js';
1515
import { isObjectEmpty } from '../helpers/index.js';
1616
import Sentry from '@sentry/minimal';
1717
import { Constants } from '../helpers/constants/constants.js';
18+
import { IRequestWithCognitoInfo } from './cognito-decoded.interface.js';
1819

1920
@Injectable()
2021
export class TemporaryAuthMiddleware implements NestMiddleware {
2122
public constructor(
22-
@InjectRepository(UserEntity)
23-
private readonly userRepository: Repository<UserEntity>,
23+
@InjectRepository(UserEntity)readonly _userRepository: Repository<UserEntity>,
2424
@InjectRepository(LogOutEntity)
2525
private readonly logOutRepository: Repository<LogOutEntity>,
2626
) {}
27-
async use(req: Request, res: Response, next: (err?: any, res?: any) => void): Promise<void> {
27+
async use(req: IRequestWithCognitoInfo, _res: Response, next: (err?: any, res?: any) => void): Promise<void> {
2828
console.log(`temporary auth middleware triggered ->: ${new Date().toISOString()}`);
2929
let token: string;
3030
try {
@@ -46,21 +46,21 @@ export class TemporaryAuthMiddleware implements NestMiddleware {
4646

4747
try {
4848
const jwtSecret = process.env.TEMPORARY_JWT_SECRET;
49-
const data = jwt.verify(token, jwtSecret);
50-
const userId = data['id'];
49+
const data = jwt.verify(token, jwtSecret) as jwt.JwtPayload;
50+
const userId = data.id;
5151
if (!userId) {
5252
throw new UnauthorizedException('JWT verification failed');
5353
}
5454
const payload = {
5555
sub: userId,
56-
email: data['email'],
57-
exp: data['exp'],
58-
iat: data['iat'],
56+
email: data.email,
57+
exp: data.exp,
58+
iat: data.iat,
5959
};
6060
if (!payload || isObjectEmpty(payload)) {
6161
throw new UnauthorizedException('JWT verification failed');
6262
}
63-
req['decoded'] = payload;
63+
req.decoded = payload;
6464
next();
6565
} catch (e) {
6666
Sentry.captureException(e);

0 commit comments

Comments
 (0)