Skip to content

Commit d969700

Browse files
committed
types fix
1 parent 2f5bb80 commit d969700

19 files changed

+46
-46
lines changed

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

Lines changed: 6 additions & 5 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,10 +58,10 @@ 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 data = jwt.verify(tokenFromCookie, jwtSecret) as jwt.JwtPayload;
6465
const userId = data.id;
6566
if (!userId) {
6667
throw new UnauthorizedException('JWT verification failed');
@@ -88,7 +89,7 @@ export class AuthWithApiMiddleware implements NestMiddleware {
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];

backend/src/authorization/auth.middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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 {
@@ -25,7 +26,7 @@ export class AuthMiddleware implements NestMiddleware {
2526
@InjectRepository(LogOutEntity)
2627
private readonly logOutRepository: Repository<LogOutEntity>,
2728
) {}
28-
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> {
2930
let token: string;
3031
try {
3132
token = req.cookies[Constants.JWT_COOKIE_KEY_NAME];
@@ -46,7 +47,7 @@ export class AuthMiddleware implements NestMiddleware {
4647

4748
try {
4849
const jwtSecret = process.env.JWT_SECRET;
49-
const data = jwt.verify(token, jwtSecret);
50+
const data = jwt.verify(token, jwtSecret) as jwt.JwtPayload;
5051
const userId = data.id;
5152
if (!userId) {
5253
throw new UnauthorizedException('JWT verification failed');

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ 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,7 +44,7 @@ export class NonScopedAuthMiddleware implements NestMiddleware {
4344

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import { Request, 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 data = jwt.verify(token, jwtSecret) as jwt.JwtPayload;
1819
const requestId = data.request_id;
1920

2021
if (!requestId) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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 {
@@ -23,7 +24,7 @@ export class TemporaryAuthMiddleware implements NestMiddleware {
2324
@InjectRepository(LogOutEntity)
2425
private readonly logOutRepository: Repository<LogOutEntity>,
2526
) {}
26-
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> {
2728
console.log(`temporary auth middleware triggered ->: ${new Date().toISOString()}`);
2829
let token: string;
2930
try {
@@ -45,7 +46,7 @@ export class TemporaryAuthMiddleware implements NestMiddleware {
4546

4647
try {
4748
const jwtSecret = process.env.TEMPORARY_JWT_SECRET;
48-
const data = jwt.verify(token, jwtSecret);
49+
const data = jwt.verify(token, jwtSecret) as jwt.JwtPayload;
4950
const userId = data.id;
5051
if (!userId) {
5152
throw new UnauthorizedException('JWT verification failed');

backend/src/decorators/gclid-decorator.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { IRequestWithCognitoInfo } from '../authorization/index.js';
44
export const GCLlId = createParamDecorator((_data: any, ctx: ExecutionContext): string => {
55
const request: IRequestWithCognitoInfo = ctx.switchToHttp().getRequest();
66
if (request.headers) {
7-
return request.headers.GCLID
8-
? request.headers.GCLID
9-
: request.headers.gclid
10-
? request.headers.gclid
11-
: null;
7+
return request.headers.gclid as string | undefined ?? null;
128
}
139
return null;
1410
});

backend/src/decorators/master-password.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { IRequestWithCognitoInfo } from '../authorization/index.js';
33

44
export const MasterPassword = createParamDecorator((_data: any, ctx: ExecutionContext): string => {
55
const request: IRequestWithCognitoInfo = ctx.switchToHttp().getRequest();
6-
const masterPwd = request.headers.masterpwd;
6+
const masterPwd = request.headers.masterpwd as string | undefined;
77
return masterPwd ? masterPwd : null;
88
});

backend/src/entities/email/email/abstract-email-letter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IMessage } from './email.interface.js';
44
export abstract class AbstractEmailLetter<TParams extends {}> {
55
protected readonly _params: TParams;
66

7-
protected constructor(params: TParams) {
7+
constructor(params: TParams) {
88
this._params = params;
99
}
1010

backend/src/entities/table-logs/application/data-structures/find-logs.ds.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LogOperationTypeEnum } from '../../../../enums/index.js';
22

33
export class FindLogsDs {
44
connectionId: string;
5-
query: string;
5+
query: Record<string, string>;
66
userId: string;
77
operationTypes: Array<LogOperationTypeEnum>;
88
}

0 commit comments

Comments
 (0)