diff --git a/apps/connection-manager/src/app.module.spec.ts b/apps/connection-manager/src/app.module.spec.ts index 0298150668c95441ae21b87b2776c43742dc758a..e5e685cb147cd6c916d4e4e80feb77c92880f436 100644 --- a/apps/connection-manager/src/app.module.spec.ts +++ b/apps/connection-manager/src/app.module.spec.ts @@ -1,6 +1,8 @@ import type { INestApplication } from '@nestjs/common'; import type { TestingModule } from '@nestjs/testing'; + import { Test } from '@nestjs/testing'; + import AppModule from './app.module.js'; describe('App Module', () => { diff --git a/apps/connection-manager/src/app.module.ts b/apps/connection-manager/src/app.module.ts index a5356b928a27e0cefd7328c2f90e849be6b3ba4b..97bc1329d080b2d6ceb2a7fa7c629fdb078a2f27 100644 --- a/apps/connection-manager/src/app.module.ts +++ b/apps/connection-manager/src/app.module.ts @@ -1,9 +1,11 @@ import type { MiddlewareConsumer, NestModule } from '@nestjs/common'; + import { Module, RequestMethod } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { APP_FILTER } from '@nestjs/core'; import { ScheduleModule } from '@nestjs/schedule'; import { TerminusModule } from '@nestjs/terminus'; + import ExceptionHandler from './common/exception.handler.js'; import config from './config/config.js'; import validationSchema from './config/validation.js'; @@ -36,7 +38,7 @@ import PrismaModule from './prisma/prisma.module.js'; }) export default class AppModule implements NestModule { // eslint-disable-next-line class-methods-use-this - configure(consumer: MiddlewareConsumer) { + public configure(consumer: MiddlewareConsumer) { // eslint-disable-line consumer .apply(AuthMiddleware) diff --git a/apps/connection-manager/src/client/config.client.ts b/apps/connection-manager/src/client/config.client.ts index f4efc5ad73ebfc4ddb536192922f29040c13821c..b40504f420aa189ec679b52bea15a084ce635cac 100644 --- a/apps/connection-manager/src/client/config.client.ts +++ b/apps/connection-manager/src/client/config.client.ts @@ -4,14 +4,14 @@ export default class ConfigClient { * If there is no Limit to check expire till date return false * @returns Number to calculate end date */ - static checkExpireTill(): Date | false { + public static checkExpireTill(): Date | false { const days = 2; const tillDate = new Date(); tillDate.setDate(tillDate.getDate() - days); return tillDate; } - static getConnectionExpire(): Date | false { + public static getConnectionExpire(): Date | false { const min = 30; const connectionExpire = min * 60 * 1000; const compareDateTime = new Date(new Date().getTime() - connectionExpire); diff --git a/apps/connection-manager/src/client/nats.client.ts b/apps/connection-manager/src/client/nats.client.ts index 723c1fbe522bd524ef9d4866930554b64805c030..a982dae39f8157d70101e771230221dbce3922ab 100644 --- a/apps/connection-manager/src/client/nats.client.ts +++ b/apps/connection-manager/src/client/nats.client.ts @@ -1,21 +1,25 @@ +import type ResponseType from '../common/response.js'; +import type ConnectionSubscriptionEndpointDto from '../connections/entities/connectionSubscribeEndPoint.entity.js'; + import { Inject, Injectable } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { lastValueFrom } from 'rxjs'; + import { Attestation, NATSServices, Principal, ProofManager, } from '../common/constants.js'; -import type ResponseType from '../common/response.js'; -import type ConnectionSubscriptionEndpointDto from '../connections/entities/connectionSubscribeEndPoint.entity.js'; import logger from '../utils/logger.js'; @Injectable() export default class NatsClientService { - constructor(@Inject(NATSServices.SERVICE_NAME) private client: ClientProxy) {} + public constructor( + @Inject(NATSServices.SERVICE_NAME) private client: ClientProxy, + ) {} - sendConnectionStatusPrincipalManager( + public sendConnectionStatusPrincipalManager( status: string, connectionId: string, theirLabel: string, @@ -36,7 +40,7 @@ export default class NatsClientService { return lastValueFrom(this.client.send<ResponseType>(pattern, payload)); } - getIssueCredentials(connectionId: string) { + public getIssueCredentials(connectionId: string) { const pattern = { endpoint: `${Attestation.NATS_ENDPOINT}/${Attestation.GET_ISSUE_CREDENTIALS}`, }; @@ -46,7 +50,7 @@ export default class NatsClientService { return lastValueFrom(this.client.send<ResponseType>(pattern, payload)); } - sendMembershipProofRequestToProofManager(connectionId: string) { + public sendMembershipProofRequestToProofManager(connectionId: string) { const pattern = { endpoint: `${ProofManager.NATS_ENDPOINT}/${ProofManager.SEND_MEMBERSHIP_PROOF_REQUEST}`, }; @@ -56,7 +60,7 @@ export default class NatsClientService { return lastValueFrom(this.client.send<ResponseType>(pattern, payload)); } - getPresentProofs(connectionId: string) { + public getPresentProofs(connectionId: string) { const pattern = { endpoint: `${ProofManager.NATS_ENDPOINT}/${ProofManager.GET_PRESENT_PROOFS}`, }; @@ -66,7 +70,7 @@ export default class NatsClientService { return lastValueFrom(this.client.send<ResponseType>(pattern, payload)); } - publishConnection(data: ConnectionSubscriptionEndpointDto) { + public publishConnection(data: ConnectionSubscriptionEndpointDto) { this.client.emit( `${NATSServices.SERVICE_NAME}/${NATSServices.CONNECTION_SUBSCRIBER_ENDPOINT}`, data, diff --git a/apps/connection-manager/src/client/rest.client.ts b/apps/connection-manager/src/client/rest.client.ts index df5feb4b3d59ca6d1f6b22add89fa8fe079e0dd3..14c1329fcf0b3475a79cbc591f761e9cdc18c4a8 100644 --- a/apps/connection-manager/src/client/rest.client.ts +++ b/apps/connection-manager/src/client/rest.client.ts @@ -4,9 +4,9 @@ import { lastValueFrom, map } from 'rxjs'; @Injectable() export default class RestClientService { - constructor(private readonly httpService: HttpService) {} + public constructor(private readonly httpService: HttpService) {} - async post(url: string, payload: object) { + public async post(url: string, payload: object) { return lastValueFrom( this.httpService .post(url, payload) diff --git a/apps/connection-manager/src/common/constants.ts b/apps/connection-manager/src/common/constants.ts index 60d0d5a4f9825b0d0ff36a46604a5c310c7e9d46..c1a9f7672786af93ba19f85cf5950b126e41885a 100644 --- a/apps/connection-manager/src/common/constants.ts +++ b/apps/connection-manager/src/common/constants.ts @@ -5,7 +5,7 @@ export enum NATSServices { export enum LoggerConfig { FILE_PATH = 'logs/log.json', - lOG_DIR = './logs', + LOG_DIR = './logs', } export enum Abstraction { diff --git a/apps/connection-manager/src/common/exception.handler.ts b/apps/connection-manager/src/common/exception.handler.ts index d54e5be4a64ac7aa291a3312b69a29e31274504b..aab81f9f9089a2285c5195b16d2686fcdbe9b941 100644 --- a/apps/connection-manager/src/common/exception.handler.ts +++ b/apps/connection-manager/src/common/exception.handler.ts @@ -1,14 +1,15 @@ +import type ResponseType from './response.js'; import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'; + import { Catch, HttpException, HttpStatus } from '@nestjs/common'; import { HttpAdapterHost } from '@nestjs/core'; -import type ResponseType from './response.js'; @Catch() export default class ExceptionHandler implements ExceptionFilter { - constructor(private readonly httpAdapterHost: HttpAdapterHost) {} + public constructor(private readonly httpAdapterHost: HttpAdapterHost) {} // eslint-disable-next-line @typescript-eslint/no-explicit-any - catch(exception: any, host: ArgumentsHost): void { + public catch(exception: any, host: ArgumentsHost): void { // In certain situations `httpAdapter` might not be available in the // constructor method, thus we should resolve it here. const { httpAdapter } = this.httpAdapterHost; diff --git a/apps/connection-manager/src/connections/controller/controller.spec.ts b/apps/connection-manager/src/connections/controller/controller.spec.ts index d0b15d7523823af31469be8c52558c058ce5e720..f6839dd445d50c297e86ae51645b7637a10d3625 100644 --- a/apps/connection-manager/src/connections/controller/controller.spec.ts +++ b/apps/connection-manager/src/connections/controller/controller.spec.ts @@ -1,15 +1,18 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import type ConnectionStateDto from '../entities/connectionStateDto.entity.js'; +import type { TestingModule } from '@nestjs/testing'; + import { HttpModule } from '@nestjs/axios'; import { HttpStatus } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ClientsModule, Transport } from '@nestjs/microservices'; -import type { TestingModule } from '@nestjs/testing'; import { Test } from '@nestjs/testing'; -import httpMocks from 'node-mocks-http'; +import { createResponse } from 'node-mocks-http'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import { NATSServices } from '../../common/constants.js'; import PrismaService from '../../prisma/prisma.service.js'; -import type ConnectionStateDto from '../entities/connectionStateDto.entity.js'; import ConnectionsService from '../services/service.js'; import ConnectionsController from './controller.js'; @@ -51,11 +54,6 @@ describe.skip('ConnectionsController', () => { describe('Get all connections', () => { it('should return an array of connection', async () => { const param = {}; - const query = { - pageSize: '0', - page: '0', - participantId: '7780cd24-af13-423e-b1ff-ae944ab6fd71', - }; const serviceResult: any = [ 1, { @@ -88,7 +86,7 @@ describe.skip('ConnectionsController', () => { }, }; - const response = httpMocks.createResponse(); + const response = createResponse(); jest .spyOn(connectionService, 'findConnections') @@ -107,10 +105,6 @@ describe.skip('ConnectionsController', () => { it('If Not provided required parameter response should be bad request', async () => { const param = {}; - const query = { - pageSize: '0', - page: '0', - }; const serviceResult: any = [ 1, { @@ -127,7 +121,7 @@ describe.skip('ConnectionsController', () => { }, ]; - const response = httpMocks.createResponse(); + const response = createResponse(); jest .spyOn(connectionService, 'findConnections') @@ -146,7 +140,7 @@ describe.skip('ConnectionsController', () => { const param = { connectionId: '7b821264-2ae3-4459-b45f-19fa975d91f7', }; - const query = {}; + const serviceResult: any = { id: '1a7f0b09-b20e-4971-b9b1-7adde7256bbc', connectionId: '7b821264-2ae3-4459-b45f-19fa975d91f7', @@ -178,7 +172,7 @@ describe.skip('ConnectionsController', () => { }, }; - const response = httpMocks.createResponse(); + const response = createResponse(); jest .spyOn(connectionService, 'findConnections') .mockResolvedValueOnce(serviceResult); @@ -196,7 +190,6 @@ describe.skip('ConnectionsController', () => { const param = { connectionId: '7b821264-2ae3-4459-b45f-19fa975d91f7', }; - const query = {}; const serviceResult: any = { id: '1a7f0b09-b20e-4971-b9b1-7adde7256bbc', connectionId: '7b821264-2ae3-4459-b45f-19fa975d91f7', @@ -214,7 +207,7 @@ describe.skip('ConnectionsController', () => { message: 'No Data found', }; - const response = httpMocks.createResponse(); + const response = createResponse(); jest .spyOn(connectionService, 'findConnections') .mockResolvedValueOnce(serviceResult); @@ -230,12 +223,6 @@ describe.skip('ConnectionsController', () => { it('should return an array of connection with status filter', async () => { const param = {}; - const query = { - pageSize: '0', - page: '0', - participantId: '7780cd24-af13-423e-b1ff-ae944ab6fd71', - status: 'trusted,complete', - }; const serviceResult: any = [ 1, { @@ -268,7 +255,7 @@ describe.skip('ConnectionsController', () => { }, }; - const response = httpMocks.createResponse(); + const response = createResponse(); jest .spyOn(connectionService, 'findConnections') .mockResolvedValueOnce(serviceResult); @@ -719,7 +706,7 @@ describe.skip('ConnectionsController', () => { }, }; - const response = httpMocks.createResponse(); + const response = createResponse(); jest .spyOn(connectionService, 'createInvitationURL') .mockResolvedValueOnce(serviceResult); @@ -749,7 +736,7 @@ describe.skip('ConnectionsController', () => { message: 'Agent Data not found.', }; - const response = httpMocks.createResponse(); + const response = createResponse(); jest .spyOn(connectionService, 'createInvitationURL') .mockResolvedValueOnce(serviceResult); diff --git a/apps/connection-manager/src/connections/controller/controller.ts b/apps/connection-manager/src/connections/controller/controller.ts index 37e2e5409c5a9c1ff5e9239330c872696da03fad..0dc1b2d2268596e854c92041b8d5b16d62694d5d 100644 --- a/apps/connection-manager/src/connections/controller/controller.ts +++ b/apps/connection-manager/src/connections/controller/controller.ts @@ -2,6 +2,8 @@ import type ResponseType from '../../common/response.js'; import type ConnectionStateDto from '../entities/connectionStateDto.entity.js'; import type ConnectionSubscriptionEndpointDto from '../entities/connectionSubscribeEndPoint.entity.js'; import type ConnectionDto from '../entities/entity.js'; +// eslint-disable-next-line @typescript-eslint/consistent-type-imports +import type { Response } from 'express'; import { Body, @@ -23,7 +25,6 @@ import { ApiResponse, ApiTags, } from '@nestjs/swagger'; -import { Response } from 'express'; import { Abstraction, @@ -38,12 +39,14 @@ import ConnectionsService from '../services/service.js'; @ApiTags('Connections') @Controller() export default class ConnectionsController { - constructor(private readonly connectionsService: ConnectionsService) {} + public constructor(private readonly connectionsService: ConnectionsService) {} @MessagePattern({ endpoint: `${Abstraction.NATS_ENDPOINT}/${Abstraction.CONNECTION_STATE_CHANGED}`, }) - async createConnection(body: { connectionRecord: ConnectionStateDto }) { + public async createConnection(body: { + connectionRecord: ConnectionStateDto; + }) { const connection = body.connectionRecord; const connectionObj: ConnectionDto = { @@ -95,7 +98,7 @@ export default class ConnectionsController { logger.info( `connection.alias ===${ConnectionsService.connectionAlias.MEMBER}`, ); - this.connectionsService.sendConnectionStatusToPrincipal( + await this.connectionsService.sendConnectionStatusToPrincipal( connection.state, connection.id, connection.theirLabel, @@ -107,7 +110,7 @@ export default class ConnectionsController { if ( connection.alias === ConnectionsService.connectionAlias.SUBSCRIBER ) { - this.connectionsService.sendMembershipProofRequestToProofManager( + await this.connectionsService.sendMembershipProofRequestToProofManager( connection.id, ); } @@ -251,7 +254,7 @@ export default class ConnectionsController { }, }) @ApiQuery({ name: 'alias', required: true }) - async createConnectionInvitation( + public async createConnectionInvitation( @Body() connectionCreate: ConnectionCreateInvitationDto, @Query() query: { alias: string }, @Res() response: Response, @@ -304,7 +307,7 @@ export default class ConnectionsController { description: 'Get full url from short url id', }) @ApiExcludeEndpoint() - async redirectToConnectionUrl( + public async redirectToConnectionUrl( @Param() params: { id: string }, @Res() response: Response, ) { @@ -399,7 +402,7 @@ export default class ConnectionsController { }, }, }) - async getConnectionInformationRequest( + public async getConnectionInformationRequest( @Query() query: { connectionId: string; did: string }, @Res() response: Response, ) { @@ -501,7 +504,7 @@ export default class ConnectionsController { }, }, }) - async getConnectionLists( + public async getConnectionLists( @Param() params: { connectionId: string }, @Query() query: { @@ -611,7 +614,7 @@ export default class ConnectionsController { }, }, }) - async getConnection( + public async getConnection( @Param() params: { connectionId: string }, @Res() response: Response, ) { @@ -621,7 +624,7 @@ export default class ConnectionsController { @MessagePattern({ endpoint: `${NATSServices.SERVICE_NAME}/getConnectionById`, }) - async getConnectionById(data: { connectionId: string }) { + public async getConnectionById(data: { connectionId: string }) { const result = await this.connectionsService.findConnections( -1, -1, @@ -634,7 +637,7 @@ export default class ConnectionsController { @MessagePattern({ endpoint: `${NATSServices.SERVICE_NAME}/makeConnectionTrusted`, }) - async makeConnectionTrusted(data: { connectionId: string }) { + public async makeConnectionTrusted(data: { connectionId: string }) { const result = await this.connectionsService.makeConnectionTrusted( data.connectionId, ); @@ -741,7 +744,7 @@ export default class ConnectionsController { }, }, }) - async acceptConnectionInvitation( + public async acceptConnectionInvitation( @Body() body: AcceptConnectionInvitationBody, @Res() response: Response, ) { @@ -765,7 +768,7 @@ export default class ConnectionsController { @MessagePattern({ endpoint: `${NATSServices.SERVICE_NAME}/getReceivedConnections`, }) - async getReceivedConnections() { + public async getReceivedConnections() { let result: object[] = []; const connections = await this.connectionsService.getReceivedConnections(); if (connections[0]) { diff --git a/apps/connection-manager/src/connections/entities/AcceptConnectionInvitationBody.ts b/apps/connection-manager/src/connections/entities/AcceptConnectionInvitationBody.ts index 4cf37a86986dcf7c16a3128f0ba284af4d25e6c1..57c85fbcfbc19cfd07fb4e332477e550d93f12fe 100644 --- a/apps/connection-manager/src/connections/entities/AcceptConnectionInvitationBody.ts +++ b/apps/connection-manager/src/connections/entities/AcceptConnectionInvitationBody.ts @@ -2,8 +2,8 @@ import { ApiProperty } from '@nestjs/swagger'; export default class AcceptConnectionInvitationBody { @ApiProperty() - invitationUrl: string; + public invitationUrl: string; @ApiProperty() - autoAcceptConnection: boolean; + public autoAcceptConnection: boolean; } diff --git a/apps/connection-manager/src/connections/entities/InvitationDto.entity.ts b/apps/connection-manager/src/connections/entities/InvitationDto.entity.ts index b42ce40f668c508013cc2049a5571352687b841e..b10c4a25d36b67150e5945ad6c2b5be786877b95 100644 --- a/apps/connection-manager/src/connections/entities/InvitationDto.entity.ts +++ b/apps/connection-manager/src/connections/entities/InvitationDto.entity.ts @@ -2,20 +2,20 @@ import { IsString } from 'class-validator'; export default class InvitationDTO { @IsString() - serviceEndpoint?: string; + public serviceEndpoint?: string; @IsString() - ['@type']?: string; + public ['@type']?: string; @IsString() - ['@id']?: string; + public ['@id']?: string; @IsString() - label?: string; + public label?: string; @IsString() - recipientKeys?: [string]; + public recipientKeys?: [string]; @IsString() - routingKeys?: []; + public routingKeys?: []; } diff --git a/apps/connection-manager/src/connections/entities/connectionCreateInvitationDto.entity.ts b/apps/connection-manager/src/connections/entities/connectionCreateInvitationDto.entity.ts index 9569d0377ef8763e2b42b7fec721b0a2606d4f46..1f41f25d874c5ffaf3e1e1895f8d2d0ef5c6ed43 100644 --- a/apps/connection-manager/src/connections/entities/connectionCreateInvitationDto.entity.ts +++ b/apps/connection-manager/src/connections/entities/connectionCreateInvitationDto.entity.ts @@ -4,17 +4,17 @@ import { IsString } from 'class-validator'; export default class ConnectionCreateInvitationDto { @IsString() @ApiProperty() - autoAcceptConnection?: boolean; + public autoAcceptConnection?: boolean; @IsString() @ApiProperty() - alias?: string; + public alias?: string; @IsString() @ApiProperty() - myLabel?: string; + public myLabel?: string; @IsString() @ApiProperty() - myImageUrl?: string; + public myImageUrl?: string; } diff --git a/apps/connection-manager/src/connections/entities/connectionStateDto.entity.ts b/apps/connection-manager/src/connections/entities/connectionStateDto.entity.ts index 86c89e65ce0e5640df4e76b1d44e99cf64c6e952..d6380acfc8932838589ef7c421b7aa3e2a93972e 100644 --- a/apps/connection-manager/src/connections/entities/connectionStateDto.entity.ts +++ b/apps/connection-manager/src/connections/entities/connectionStateDto.entity.ts @@ -4,48 +4,48 @@ import InvitationDTO from './InvitationDto.entity.js'; export default class ConnectionStateDto { @IsString() - _tags?: string; + public _tags?: string; @IsString() - metadata?: string; + public metadata?: string; @IsString() - didDoc?: string; + public didDoc?: string; @IsString() - verkey?: string; + public verkey?: string; @IsString() - createdAt?: string; + public createdAt?: string; @IsString() @IsNotEmpty() - role: string; + public role: string; @IsString() @IsNotEmpty() - state: string; + public state: string; @IsString() @IsNotEmpty() - id: string; + public id: string; @IsString() @IsNotEmpty() - did: string; + public did: string; @IsString() - theirDid: string; + public theirDid: string; @IsString() - theirLabel: string; + public theirLabel: string; @IsString() - invitation: InvitationDTO; + public invitation: InvitationDTO; @IsString() - alias: string; + public alias: string; @IsBooleanString() - multiUseInvitation?: boolean; + public multiUseInvitation?: boolean; } diff --git a/apps/connection-manager/src/connections/entities/connectionSubscribeEndPoint.entity.ts b/apps/connection-manager/src/connections/entities/connectionSubscribeEndPoint.entity.ts index fe7cb31f38bbcfbb2fa40fe5f6a132ae176ab0e8..cbd2454ba268faef6abbda1ac8d57e37c45315ef 100644 --- a/apps/connection-manager/src/connections/entities/connectionSubscribeEndPoint.entity.ts +++ b/apps/connection-manager/src/connections/entities/connectionSubscribeEndPoint.entity.ts @@ -3,9 +3,9 @@ import { IsString, IsNotEmpty } from 'class-validator'; export default class ConnectionSubscriptionEndpointDto { @IsString() @IsNotEmpty() - connectionId: string; + public connectionId: string; @IsString() @IsNotEmpty() - status: string; + public status: string; } diff --git a/apps/connection-manager/src/connections/entities/entity.ts b/apps/connection-manager/src/connections/entities/entity.ts index 79e5674273bbb41019c71c670ae753c66d5932c0..a683edac6e7491eb269e0db1a7c4e27658a58950 100644 --- a/apps/connection-manager/src/connections/entities/entity.ts +++ b/apps/connection-manager/src/connections/entities/entity.ts @@ -4,38 +4,38 @@ import InvitationDTO from './InvitationDto.entity.js'; export default class ConnectionDto { @IsString() - id?: string; + public id?: string; @IsDate() - connectionDate?: Date; + public connectionDate?: Date; @IsDate() - createdDate?: Date; + public createdDate?: Date; @IsDate() - updatedDate?: Date; + public updatedDate?: Date; @IsString() @IsNotEmpty() - participantDid: string; + public participantDid: string; @IsString() @IsNotEmpty() - status: string; + public status: string; @IsString() @IsNotEmpty() - connectionId: string; + public connectionId: string; @IsString() - theirDid: string; + public theirDid: string; @IsString() - theirLabel: string; + public theirLabel: string; @IsBoolean() - isReceived: boolean; + public isReceived: boolean; @IsString() - invitation?: InvitationDTO; + public invitation?: InvitationDTO; } diff --git a/apps/connection-manager/src/connections/repository/connection.repository.ts b/apps/connection-manager/src/connections/repository/connection.repository.ts index d0fabcb7c3081259b603d49a7cb69b3a7ee7f546..f1cfb5855cef1c0eb6c50cb5e010706241fd3953 100644 --- a/apps/connection-manager/src/connections/repository/connection.repository.ts +++ b/apps/connection-manager/src/connections/repository/connection.repository.ts @@ -6,25 +6,25 @@ import PrismaService from '../../prisma/prisma.service.js'; @Injectable() export default class ConnectionRepository { - constructor(private readonly prismaService: PrismaService) {} + public constructor(private readonly prismaService: PrismaService) {} - async createConnection(data: Prisma.ConnectionCreateInput) { + public async createConnection(data: Prisma.ConnectionCreateInput) { return this.prismaService.connection.create({ data }); } - async createShortUrl(connectionUrl: string) { + public async createShortUrl(connectionUrl: string) { return this.prismaService.shortUrlConnection.create({ data: { connectionUrl }, }); } - async getShortUrl(id: string) { + public async getShortUrl(id: string) { return this.prismaService.shortUrlConnection.findUnique({ where: { id }, }); } - async updateConnection(params: { + public async updateConnection(params: { where: Prisma.ConnectionWhereUniqueInput; data: Prisma.ConnectionUpdateInput; }) { @@ -36,7 +36,7 @@ export default class ConnectionRepository { }); } - async updateManyConnection(params: { + public async updateManyConnection(params: { where: Prisma.ConnectionWhereInput; data: Prisma.ConnectionUpdateInput; }) { @@ -48,7 +48,7 @@ export default class ConnectionRepository { }); } - async findConnections(params: { + public async findConnections(params: { skip?: number; take?: number; cursor?: Prisma.ConnectionWhereUniqueInput; @@ -75,7 +75,7 @@ export default class ConnectionRepository { ]); } - async findUniqueConnection(params: { + public async findUniqueConnection(params: { where: Prisma.ConnectionWhereUniqueInput; }) { const { where } = params; @@ -85,12 +85,12 @@ export default class ConnectionRepository { }); } - findByConnectionId(connectionId: string) { + public findByConnectionId(connectionId: string) { const query = { where: { connectionId } }; return this.findUniqueConnection(query); } - findByConnectionByParticipantDID(participantDid: string) { + public findByConnectionByParticipantDID(participantDid: string) { const query = { where: { participantDid } }; return this.findUniqueConnection(query); } diff --git a/apps/connection-manager/src/connections/scheduler/scheduler.service.ts b/apps/connection-manager/src/connections/scheduler/scheduler.service.ts index 465a1593821598bd23d0f5185994f8022d92ed32..69492c4bdf3ad1b4ff546383620b669844b311d9 100644 --- a/apps/connection-manager/src/connections/scheduler/scheduler.service.ts +++ b/apps/connection-manager/src/connections/scheduler/scheduler.service.ts @@ -16,12 +16,12 @@ import ConnectionsService from '../services/service.js'; export default class SchedulerService { private connectionRepository; - constructor(private readonly prismaService: PrismaService) { + public constructor(private readonly prismaService: PrismaService) { this.connectionRepository = new ConnectionRepository(this.prismaService); } @Cron(CronExpression.EVERY_30_SECONDS) - async expireNonCompleteConnection() { + public async expireNonCompleteConnection() { const compareDateTime = ConfigClient.getConnectionExpire(); if (compareDateTime) { const checkExpireTillDateTime = ConfigClient.checkExpireTill(); @@ -68,7 +68,7 @@ export default class SchedulerService { } @Cron(CronExpression.EVERY_30_SECONDS) - async expireNonTrustedConnection() { + public async expireNonTrustedConnection() { const compareDateTime = ConfigClient.getConnectionExpire(); if (compareDateTime) { const checkExpireTillDateTime = ConfigClient.checkExpireTill(); diff --git a/apps/connection-manager/src/connections/services/service.spec.ts b/apps/connection-manager/src/connections/services/service.spec.ts index 13c916d4c83baf083196a0c85bee72df396cab77..ac71026624bf3ec13cdb6f9d72dfb9dc8d12ce0e 100644 --- a/apps/connection-manager/src/connections/services/service.spec.ts +++ b/apps/connection-manager/src/connections/services/service.spec.ts @@ -1,5 +1,6 @@ -import type { TestingModule } from '@nestjs/testing'; +/* eslint-disable @typescript-eslint/no-explicit-any */ import type ConnectionDto from '../entities/entity.js'; +import type { TestingModule } from '@nestjs/testing'; import { HttpModule } from '@nestjs/axios'; import { ConfigModule } from '@nestjs/config'; diff --git a/apps/connection-manager/src/connections/services/service.ts b/apps/connection-manager/src/connections/services/service.ts index 57f09b5866fb0d97b44e68546048108f231747c6..1bfe8a484a07dd695ff57dfa141410f2c18fe5af 100644 --- a/apps/connection-manager/src/connections/services/service.ts +++ b/apps/connection-manager/src/connections/services/service.ts @@ -17,7 +17,7 @@ import ConnectionRepository from '../repository/connection.repository.js'; export default class ConnectionsService { private connectionRepository: ConnectionRepository; - constructor( + public constructor( private readonly prismaService: PrismaService, private readonly natsClient: NatsClientService, private readonly restClient: RestClientService, @@ -26,13 +26,13 @@ export default class ConnectionsService { this.connectionRepository = new ConnectionRepository(this.prismaService); } - static readonly connectionAlias = { + public static readonly connectionAlias = { MEMBER: 'member', SUBSCRIBER: 'subscriber', TRUST: 'trust', }; - static readonly status = { + public static readonly status = { DEFAULT: 'invited', INVITED: 'invited', REQUESTED: 'requested', @@ -41,12 +41,12 @@ export default class ConnectionsService { TRUSTED: 'trusted', }; - static readonly roles = { + public static readonly roles = { INVITER: 'inviter', INVITEE: 'invitee', }; - async createConnections(connection: ConnectionDto) { + public async createConnections(connection: ConnectionDto) { logger.info( `connection service create connection connection?.invitation?.serviceEndpoint is ${connection?.invitation?.serviceEndpoint}`, ); @@ -59,7 +59,7 @@ export default class ConnectionsService { }); } - async sendConnectionStatusToPrincipal( + public async sendConnectionStatusToPrincipal( status: string, connectionId: string, theirLabel: string, @@ -82,7 +82,7 @@ export default class ConnectionsService { } } - async sendMembershipProofRequestToProofManager(connectionId: string) { + public async sendMembershipProofRequestToProofManager(connectionId: string) { try { const response = await this.natsClient.sendMembershipProofRequestToProofManager( @@ -95,7 +95,7 @@ export default class ConnectionsService { } } - async updateStatusByConnectionId(connection: ConnectionDto) { + public async updateStatusByConnectionId(connection: ConnectionDto) { return this.connectionRepository.updateConnection({ where: { connectionId: connection.connectionId }, data: { @@ -107,19 +107,19 @@ export default class ConnectionsService { }); } - getConnectionByID(connectionId: string) { + public getConnectionByID(connectionId: string) { return this.connectionRepository.findByConnectionId(connectionId); } - getAgentUrl() { + public getAgentUrl() { return this.configService.get('agent'); } - getAppUrl() { + public getAppUrl() { return this.configService.get('APP_URL'); } - async findConnections( + public async findConnections( pageSize: number, page: number, status: string | false, @@ -154,7 +154,9 @@ export default class ConnectionsService { return this.connectionRepository.findConnections(query); } - async createInvitationURL(connectionCreate: ConnectionCreateInvitationDto) { + public async createInvitationURL( + connectionCreate: ConnectionCreateInvitationDto, + ) { const { agentUrl } = this.getAgentUrl(); const appUrl = this.getAppUrl(); const responseData = await this.restClient.post( @@ -169,11 +171,11 @@ export default class ConnectionsService { return responseData; } - async findConnectionByShortUrlId(id: string) { + public async findConnectionByShortUrlId(id: string) { return this.connectionRepository.getShortUrl(id); } - async getConnectionInformationRequest(connectionId = '', did = '') { + public async getConnectionInformationRequest(connectionId = '', did = '') { try { let connectionDetails: Connection | null = null; @@ -225,7 +227,7 @@ export default class ConnectionsService { } } - async makeConnectionTrusted(connectionId: string) { + public async makeConnectionTrusted(connectionId: string) { return this.connectionRepository.updateConnection({ where: { connectionId }, data: { @@ -235,11 +237,13 @@ export default class ConnectionsService { }); } - publishConnectionSubscriberEndpoint(data: ConnectionSubscriptionEndpointDto) { + public publishConnectionSubscriberEndpoint( + data: ConnectionSubscriptionEndpointDto, + ) { this.natsClient.publishConnection(data); } - async acceptConnectionInvitation( + public async acceptConnectionInvitation( agentURL: string, payload: { invitationUrl: string; @@ -253,7 +257,7 @@ export default class ConnectionsService { ); } - async getReceivedConnections() { + public async getReceivedConnections() { return this.connectionRepository.findConnections({ where: { isReceived: true }, select: { connectionId: true }, diff --git a/apps/connection-manager/src/health/health.controller.ts b/apps/connection-manager/src/health/health.controller.ts index 9c3454b10991f407d18c2a1c29422ad8d56157bc..d298ca31b48f7cde89bea7fb2b6d7a602efce3e9 100644 --- a/apps/connection-manager/src/health/health.controller.ts +++ b/apps/connection-manager/src/health/health.controller.ts @@ -5,7 +5,7 @@ import { ApiOperation, ApiResponse } from '@nestjs/swagger'; @Controller('health') export default class HealthController { - res: ResponseType; + private res: ResponseType; @Version(['1']) @Get() @@ -32,7 +32,7 @@ export default class HealthController { }, }, }) - getHealth() { + public getHealth() { this.res = { statusCode: HttpStatus.OK, message: `${new Date()}`, diff --git a/apps/connection-manager/src/main.ts b/apps/connection-manager/src/main.ts index 26244996e75276a43413a5859691dad5f519e153..9049f6299b80a17cb1d9893aef477c8158db6b9d 100644 --- a/apps/connection-manager/src/main.ts +++ b/apps/connection-manager/src/main.ts @@ -1,48 +1,46 @@ +import type { MicroserviceOptions } from '@nestjs/microservices'; + import { VersioningType } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { HttpAdapterHost, NestFactory } from '@nestjs/core'; -import type { MicroserviceOptions } from '@nestjs/microservices'; import { Transport } from '@nestjs/microservices'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; + import AppModule from './app.module.js'; import AllExceptionsFilter from './utils/exceptionsFilter.js'; import logger from './utils/logger.js'; -async function bootstrap() { - const app = await NestFactory.create(AppModule); - const configService = app.get(ConfigService); - app.enableCors(); - - app.connectMicroservice<MicroserviceOptions>({ - transport: Transport.NATS, - options: { - servers: [configService.get('nats').url], - }, - }); +const app = await NestFactory.create(AppModule); +const configService = app.get(ConfigService); +app.enableCors(); - app.enableVersioning({ - defaultVersion: ['1', '2'], - type: VersioningType.URI, - }); +app.connectMicroservice<MicroserviceOptions>({ + transport: Transport.NATS, + options: { + servers: [configService.get('nats').url], + }, +}); - const swaggerConfig = new DocumentBuilder() - .setTitle('Gaia-x Connection Manager API') - .setDescription('API documentation for GAIA-X Connection Manager') - .setVersion('1.0') - .addServer(`http://localhost:${configService.get('PORT')}`) - .build(); +app.enableVersioning({ + defaultVersion: ['1', '2'], + type: VersioningType.URI, +}); - const document = SwaggerModule.createDocument(app, swaggerConfig); +const swaggerConfig = new DocumentBuilder() + .setTitle('Gaia-x Connection Manager API') + .setDescription('API documentation for GAIA-X Connection Manager') + .setVersion('1.0') + .addServer(`http://localhost:${configService.get('PORT')}`) + .build(); - SwaggerModule.setup('/swagger', app, document); - await app.startAllMicroservices(); +const document = SwaggerModule.createDocument(app, swaggerConfig); - const httpAdapter = app.get(HttpAdapterHost); - app.useGlobalFilters(new AllExceptionsFilter(httpAdapter)); +SwaggerModule.setup('/swagger', app, document); +await app.startAllMicroservices(); - await app.listen(configService.get('PORT') || 3000, () => { - logger.info(`Listening on Port:${configService.get('PORT')}` || 3000); - }); -} +const httpAdapter = app.get(HttpAdapterHost); +app.useGlobalFilters(new AllExceptionsFilter(httpAdapter)); -bootstrap(); +await app.listen(configService.get('PORT') || 3000, () => { + logger.info(`Listening on Port:${configService.get('PORT')}` || 3000); +}); diff --git a/apps/connection-manager/src/middleware/auth.middleware.ts b/apps/connection-manager/src/middleware/auth.middleware.ts index 2e9f7887749934cc99253fcf21cfdc973a1bbc07..40549bfd6bb55ef9f200f7a427ac0c5d06c50cee 100644 --- a/apps/connection-manager/src/middleware/auth.middleware.ts +++ b/apps/connection-manager/src/middleware/auth.middleware.ts @@ -10,7 +10,7 @@ import logger from '../utils/logger.js'; @Injectable() export class AuthMiddleware implements NestMiddleware { - constructor(private readonly configService: ConfigService) {} + public constructor(private readonly configService: ConfigService) {} /* eslint-disable */ async use(req: Request, res: Response, next: NextFunction) { diff --git a/apps/connection-manager/src/prisma/prisma.service.ts b/apps/connection-manager/src/prisma/prisma.service.ts index 8adb0ecae9a3050db33ecfbea4536f6f1df34a3a..b27f2bfb34a97ca4d9e37ad58782e1b53f710d20 100644 --- a/apps/connection-manager/src/prisma/prisma.service.ts +++ b/apps/connection-manager/src/prisma/prisma.service.ts @@ -9,7 +9,7 @@ export default class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { - constructor(private configService: ConfigService) { + public constructor(private configService: ConfigService) { super({ datasources: { db: { @@ -19,11 +19,11 @@ export default class PrismaService }); } - async onModuleInit() { + public async onModuleInit() { await this.$connect(); } - async onModuleDestroy() { + public async onModuleDestroy() { await this.$disconnect(); } } diff --git a/apps/connection-manager/src/utils/exceptionsFilter.ts b/apps/connection-manager/src/utils/exceptionsFilter.ts index ce1289b1da711ef40d89862187fca3ff2203acb8..196efcabd241b3a03e30f88b6c01660a76a1b073 100644 --- a/apps/connection-manager/src/utils/exceptionsFilter.ts +++ b/apps/connection-manager/src/utils/exceptionsFilter.ts @@ -9,10 +9,10 @@ const { PrismaClientKnownRequestError, PrismaClientValidationError } = Prisma; @Catch() export default class AllExceptionsFilter implements ExceptionFilter { - constructor(private readonly httpAdapterHost: HttpAdapterHost) {} + public constructor(private readonly httpAdapterHost: HttpAdapterHost) {} // eslint-disable-next-line @typescript-eslint/no-explicit-any - catch(exception: any, host: ArgumentsHost): void { + public catch(exception: any, host: ArgumentsHost): void { const { httpAdapter } = this.httpAdapterHost; const ctx = host.switchToHttp(); diff --git a/apps/connection-manager/src/utils/logger.ts b/apps/connection-manager/src/utils/logger.ts index 8892609a95ba4be04717bbdec232d331ef1b83c6..b1958d564a6e6657405384d03400e8485b2bcc43 100644 --- a/apps/connection-manager/src/utils/logger.ts +++ b/apps/connection-manager/src/utils/logger.ts @@ -1,20 +1,16 @@ import type { Logger } from 'winston'; import { ecsFormat } from '@elastic/ecs-winston-format'; -import { mkdirSync } from 'node:fs'; -import winston from 'winston'; +import { createLogger, transports } from 'winston'; -import { LoggerConfig } from '../common/constants.js'; - -mkdirSync(LoggerConfig.lOG_DIR, { recursive: true }); - -const logger: Logger = winston.createLogger({ +const logger: Logger = createLogger({ format: ecsFormat({ convertReqRes: true }), - transports: [new winston.transports.Console()], + transports: [new transports.Console()], }); logger.on('error', (error) => { + // eslint-disable-next-line no-console console.error('Error in logger caught', error); }); diff --git a/apps/connection-manager/src/utils/nats.ts b/apps/connection-manager/src/utils/nats.ts index 1847a2345bfb3743f01aa625daf74c7c388b1f6c..6eede1a7a549399219b2e060172427e7c95708fc 100644 --- a/apps/connection-manager/src/utils/nats.ts +++ b/apps/connection-manager/src/utils/nats.ts @@ -1,4 +1,5 @@ import type { NatsConnection } from 'nats'; + import { connect, StringCodec } from 'nats'; const sc = StringCodec(); @@ -29,13 +30,9 @@ export default class Nats { ) { if (this.nc) { const sub = this.nc.subscribe(subject); - (async () => { - // airbnb rule for this lint is outdated - // eslint-disable-next-line - for await (const m of sub) { - cb(sc.decode(m.data)); - } - })(); + for await (const m of sub) { + cb(sc.decode(m.data)); + } } else { throw new Error('Initialize Nats First!!'); } diff --git a/apps/connection-manager/test/app.e2e-spec.ts b/apps/connection-manager/test/app.e2e-spec.ts index 762e16320004e34f9643ccdd947b153e43636623..071ca4ed95a2f6f19141de5f08fe4f6a546196f9 100644 --- a/apps/connection-manager/test/app.e2e-spec.ts +++ b/apps/connection-manager/test/app.e2e-spec.ts @@ -1,7 +1,10 @@ +import type { INestApplication } from '@nestjs/common'; +import type { TestingModule } from '@nestjs/testing'; + import { afterEach, beforeEach, describe, it } from '@jest/globals'; -import { INestApplication } from '@nestjs/common'; -import { Test, TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; import request from 'supertest'; + import AppModule from '../src/app.module.js'; describe('AppController (e2e)', () => {