Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/credebl/platform into de…
Browse files Browse the repository at this point in the history
…v-to-main-oob
  • Loading branch information
bhavanakarwade committed Dec 20, 2023
2 parents 0ec4353 + bf3c732 commit 3cb813a
Show file tree
Hide file tree
Showing 106 changed files with 4,498 additions and 1,868 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ coverage
libs/prisma-service/prisma/data/credebl-master-table.json
uploadedFles/exports
uploadedFles/import
uploadedFles/export
uploadedFles/export
nats-server.conf
7 changes: 3 additions & 4 deletions apps/agent-provisioning/src/agent-provisioning.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { AgentProvisioningController } from './agent-provisioning.controller';
import { AgentProvisioningService } from './agent-provisioning.service';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ConfigModule } from '@nestjs/config';

import { getNatsOptions } from '@credebl/common/nats.config';
@Module({
imports: [
ConfigModule.forRoot(),
ClientsModule.register([
{
name: 'NATS_CLIENT',
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
options: getNatsOptions(process.env.AGENT_PROVISIONING_NKEY_SEED)

}
])
],
Expand Down
6 changes: 2 additions & 4 deletions apps/agent-provisioning/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { HttpExceptionFilter } from 'libs/http-exception.filter';
import { Logger } from '@nestjs/common';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { AgentProvisioningModule } from './agent-provisioning.module';

import { getNatsOptions } from '@credebl/common/nats.config';
const logger = new Logger();

async function bootstrap(): Promise<void> {

const app = await NestFactory.createMicroservice<MicroserviceOptions>(AgentProvisioningModule, {
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
options: getNatsOptions(process.env.AGENT_PROVISIONING_NKEY_SEED)
});
app.useGlobalFilters(new HttpExceptionFilter());

Expand Down
5 changes: 2 additions & 3 deletions apps/agent-service/src/agent-service.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AgentServiceRepository } from './repositories/agent-service.repository'
import { ConfigModule } from '@nestjs/config';
import { ConnectionService } from 'apps/connection/src/connection.service';
import { ConnectionRepository } from 'apps/connection/src/connection.repository';
import { getNatsOptions } from '@credebl/common/nats.config';

@Module({
imports: [
Expand All @@ -16,9 +17,7 @@ import { ConnectionRepository } from 'apps/connection/src/connection.repository'
{
name: 'NATS_CLIENT',
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
options: getNatsOptions(process.env.AGENT_SERVICE_NKEY_SEED)
}
]),
CommonModule
Expand Down
6 changes: 3 additions & 3 deletions apps/agent-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AgentServiceModule } from './agent-service.module';
import { AgentServiceService } from './agent-service.service';
import { IAgentSpinupDto, IUserRequestInterface } from './interface/agent-service.interface';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { getNatsOptions } from '@credebl/common/nats.config';
import { CommonConstants } from '@credebl/common/common.constant';
import { Ledgers } from '@credebl/enum/enum';

Expand All @@ -14,9 +15,8 @@ async function bootstrap(): Promise<void> {

const app = await NestFactory.createMicroservice<MicroserviceOptions>(AgentServiceModule, {
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
options: getNatsOptions(process.env.AGENT_SERVICE_NKEY_SEED)

});
app.useGlobalFilters(new HttpExceptionFilter());

Expand Down
63 changes: 41 additions & 22 deletions apps/api-gateway/common/exception-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Catch, ArgumentsHost, HttpException, HttpStatus, Logger } from '@nestjs/common';
import { BaseExceptionFilter } from '@nestjs/core';
import { isArray } from 'class-validator';

@Catch()
export class CustomExceptionFilter extends BaseExceptionFilter {
Expand All @@ -20,12 +21,18 @@ export class CustomExceptionFilter extends BaseExceptionFilter {
}

let errorResponse;
if (exception && exception["statusCode"] === HttpStatus.INTERNAL_SERVER_ERROR) {
if (exception.message && exception.message["message"]) {
if (isArray(exception)) {
errorResponse = {
statusCode: status,
message: exception[0],
error: exception[0]
};
} else if (exception && exception['statusCode'] === HttpStatus.INTERNAL_SERVER_ERROR) {
if (exception.message && exception.message['message']) {
errorResponse = {
statusCode: status,
message: exception.message["message"],
error: exception.message["message"]
message: exception.message['message'],
error: exception.message['message']
};
} else {
errorResponse = {
Expand All @@ -34,45 +41,57 @@ export class CustomExceptionFilter extends BaseExceptionFilter {
error: 'Oops! Something went wrong. Please try again'
};
}
} else if (exception && exception["error"] && exception["error"].message && (exception["error"].statusCode || exception["error"].code)) {

const statusCode = exception["error"].statusCode || exception["error"].code || status;
} else if (
exception &&
exception['error'] &&
exception['error'].message &&
(exception['error'].statusCode || exception['error'].code)
) {
const statusCode = exception['error'].statusCode || exception['error'].code || status;
errorResponse = {
statusCode,
message: exception["error"].message || 'Internal server error',
error: exception["error"].message || 'Internal server error'
message: exception['error'].message || 'Internal server error',
error: exception['error'].message || 'Internal server error'
};
} else if (exception && exception["statusCode"] === undefined && status === HttpStatus.INTERNAL_SERVER_ERROR) {
} else if (exception && exception['statusCode'] === undefined && status === HttpStatus.INTERNAL_SERVER_ERROR) {
errorResponse = {
statusCode: status,
message: 'Oops! Something went wrong. Please try again',
error: 'Oops! Something went wrong. Please try again'
};
} else {
if (exception && exception["response"] && exception.message) {

if (Array.isArray(exception["response"].message)) {

if (exception && exception['response'] && exception.message) {
if (Array.isArray(exception['response'].message)) {
errorResponse = {
statusCode: exception["statusCode"] ? exception["statusCode"] : status,
statusCode: exception['statusCode'] ? exception['statusCode'] : status,
message: exception.message ? exception.message : 'Internal server error',
error: exception["response"].message ? exception["response"].message : exception["response"] ? exception["response"] : 'Internal server error'
error: exception['response'].message
? exception['response'].message
: exception['response']
? exception['response']
: 'Internal server error'
};
} else {
errorResponse = {
statusCode: exception["statusCode"] ? exception["statusCode"] : status,
message: exception["response"].message ? exception["response"].message : exception["response"] ? exception["response"] : 'Internal server error',
error: exception["response"].message ? exception["response"].message : exception["response"] ? exception["response"] : 'Internal server error'
statusCode: exception['statusCode'] ? exception['statusCode'] : status,
message: exception['response'].message
? exception['response'].message
: exception['response']
? exception['response']
: 'Internal server error',
error: exception['response'].message
? exception['response'].message
: exception['response']
? exception['response']
: 'Internal server error'
};
}
} else if (exception && exception.message) {

errorResponse = {
statusCode: exception["statusCode"] ? exception["statusCode"] : status,
statusCode: exception['statusCode'] ? exception['statusCode'] : status,
message: exception.message || 'Internal server error',
error: exception.message || 'Internal server error'
};

}
}

Expand Down
6 changes: 3 additions & 3 deletions apps/api-gateway/src/agent-service/agent-service.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CommonService } from '../../../../libs/common/src/common.service';
import { ConfigModule } from '@nestjs/config';
import { AgentController } from './agent-service.controller';
import { AgentService } from './agent-service.service';
import { getNatsOptions } from '@credebl/common/nats.config';

@Module({
imports: [
Expand All @@ -15,9 +16,8 @@ import { AgentService } from './agent-service.service';
{
name: 'NATS_CLIENT',
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
options: getNatsOptions(process.env.API_GATEWAY_NKEY_SEED)

},
CommonModule
])
Expand Down
8 changes: 5 additions & 3 deletions apps/api-gateway/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthzMiddleware } from './authz/authz.middleware';
import { AuthzModule } from './authz/authz.module';
import { ClientsModule } from '@nestjs/microservices';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ConfigModule } from '@nestjs/config';
import { CredentialDefinitionModule } from './credential-definition/credential-definition.module';
import { FidoModule } from './fido/fido.module';
Expand All @@ -16,10 +16,11 @@ import { VerificationModule } from './verification/verification.module';
import { RevocationController } from './revocation/revocation.controller';
import { RevocationModule } from './revocation/revocation.module';
import { SchemaModule } from './schema/schema.module';
import { commonNatsOptions } from 'libs/service/nats.options';
// import { commonNatsOptions } from 'libs/service/nats.options';
import { UserModule } from './user/user.module';
import { ConnectionModule } from './connection/connection.module';
import { EcosystemModule } from './ecosystem/ecosystem.module';
import { getNatsOptions } from '@credebl/common/nats.config';
import { BullModule } from '@nestjs/bull';
import { CacheModule } from '@nestjs/cache-manager';
import * as redisStore from 'cache-manager-redis-store';
Expand All @@ -30,7 +31,8 @@ import * as redisStore from 'cache-manager-redis-store';
ClientsModule.register([
{
name: 'NATS_CLIENT',
...commonNatsOptions('AGENT_SERVICE:REQUESTER')
transport: Transport.NATS,
options: getNatsOptions(process.env.API_GATEWAY_NKEY_SEED)
}
]),
AgentModule,
Expand Down
7 changes: 2 additions & 5 deletions apps/api-gateway/src/authz/authz.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { UserModule } from '../user/user.module';
import { UserService } from '../user/user.service';
import { VerificationService } from '../verification/verification.service';
import { EcosystemService } from '../ecosystem/ecosystem.service';

//import { WebhookService } from "../../../platform-service/src/webhook/webhook.service";
import { getNatsOptions } from '@credebl/common/nats.config';

@Module({
imports: [
Expand All @@ -31,9 +30,7 @@ import { EcosystemService } from '../ecosystem/ecosystem.service';
{
name: 'NATS_CLIENT',
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
options: getNatsOptions(process.env.API_GATEWAY_NKEY_SEED)
},
CommonModule
]),
Expand Down
71 changes: 39 additions & 32 deletions apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IResponseType from '@credebl/common/interfaces/response.interface';
import { ResponseMessages } from '@credebl/common/response-messages';
import { Controller, Logger, Post, Body, UseGuards, HttpStatus, Res, Get, Param, Query, UseFilters } from '@nestjs/common';
import { Controller, Logger, Post, Body, UseGuards, HttpStatus, Res, Get, Param, UseFilters, Query } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiExcludeEndpoint, ApiForbiddenResponse, ApiOperation, ApiQuery, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { User } from '../authz/decorators/user.decorator';
Expand All @@ -11,12 +11,13 @@ import { ConnectionService } from './connection.service';
import { ConnectionDto, CreateConnectionDto } from './dtos/connection.dto';
import { IUserRequestInterface } from './interfaces';
import { Response } from 'express';
import { Connections } from './enums/connections.enum';
import { IUserRequest } from '@credebl/user-request/user-request.interface';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { OrgRoles } from 'libs/org-roles/enums';
import { Roles } from '../authz/decorators/roles.decorator';
import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { GetAllConnectionsDto } from './dtos/get-all-connections.dto';
import { IConnectionSearchinterface } from '../interfaces/ISchemaSearch.interface';

@UseFilters(CustomExceptionFilter)
@Controller()
Expand Down Expand Up @@ -64,9 +65,6 @@ export class ConnectionController {
/**
* Description: Get all connections
* @param user
* @param threadId
* @param connectionId
* @param state
* @param orgId
*
*/
Expand All @@ -77,40 +75,48 @@ export class ConnectionController {
summary: `Fetch all connection details`,
description: `Fetch all connection details`
})
@ApiQuery({
name: 'pageNumber',
type: Number,
required: false
})
@ApiQuery({
name: 'searchByText',
type: String,
required: false
})
@ApiQuery({
name: 'pageSize',
type: Number,
required: false
})
@ApiQuery({
name: 'sorting',
type: String,
required: false
})
@ApiQuery({
name: 'sortByValue',
type: String,
required: false
})
@ApiResponse({ status: 200, description: 'Success', type: AuthTokenResponse })
@ApiQuery(
{ name: 'outOfBandId', required: false }
)
@ApiQuery(
{ name: 'alias', required: false }
)
@ApiQuery(
{ name: 'state', enum: Connections, required: false }
)
@ApiQuery(
{ name: 'myDid', required: false }
)
@ApiQuery(
{ name: 'theirDid', required: false }
)
@ApiQuery(
{ name: 'theirLabel', required: false }
)
async getConnections(
@Query() getAllConnectionsDto: GetAllConnectionsDto,
@User() user: IUserRequest,
@Query('outOfBandId') outOfBandId: string,
@Query('alias') alias: string,
@Query('state') state: string,
@Query('myDid') myDid: string,
@Query('theirDid') theirDid: string,
@Query('theirLabel') theirLabel: string,
@Param('orgId') orgId: string,
@Res() res: Response
): Promise<Response> {

// eslint-disable-next-line no-param-reassign
state = state || undefined;
const connectionDetails = await this.connectionService.getConnections(user, outOfBandId, alias, state, myDid, theirDid, theirLabel, orgId);
const { pageSize, searchByText, pageNumber, sorting, sortByValue } = getAllConnectionsDto;
const connectionSearchCriteria: IConnectionSearchinterface = {
pageNumber,
searchByText,
pageSize,
sorting,
sortByValue
};
const connectionDetails = await this.connectionService.getConnections(connectionSearchCriteria, user, orgId);

const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
Expand Down Expand Up @@ -149,6 +155,7 @@ export class ConnectionController {

}


/**
* Catch connection webhook responses.
* @Body connectionDto
Expand Down
5 changes: 2 additions & 3 deletions apps/api-gateway/src/connection/connection.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getNatsOptions } from '@credebl/common/nats.config';
import { ConnectionController } from './connection.controller';
import { ConnectionService } from './connection.service';
import { Module } from '@nestjs/common';
Expand All @@ -10,9 +11,7 @@ import { ClientsModule, Transport } from '@nestjs/microservices';
{
name: 'NATS_CLIENT',
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
options: getNatsOptions(process.env.API_GATEWAY_NKEY_SEED)
}
])
],
Expand Down
Loading

0 comments on commit 3cb813a

Please sign in to comment.