Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: register org specific webhook #439

Merged
merged 9 commits into from
Jan 16, 2024
19 changes: 9 additions & 10 deletions apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { GetAllConnectionsDto } from './dtos/get-all-connections.dto';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
import { IConnectionSearchCriteria } from '../interfaces/IConnectionSearch.interface';
import { SortFields } from 'apps/connection/src/enum/connection.enum';
import { ClientProxy, RpcException} from '@nestjs/microservices';
import { ClientProxy} from '@nestjs/microservices';

@UseFilters(CustomExceptionFilter)
@Controller()
Expand Down Expand Up @@ -156,14 +156,14 @@ export class ConnectionController {
): Promise<Response> {
this.logger.debug(`connectionDto ::: ${JSON.stringify(connectionDto)} ${orgId}`);

const webhookUrl = await this.connectionService._getWebhookUrl(connectionDto.contextCorrelationId);
// const webhookUrl = await this.connectionService._getWebhookUrl(connectionDto.contextCorrelationId);

if (webhookUrl) {
try {
await this.connectionService._postWebhookResponse(webhookUrl, { data: connectionDto });
} catch (error) {
throw new RpcException(error.response ? error.response : error);
}
// if (webhookUrl) {
// try {
// await this.connectionService._postWebhookResponse(webhookUrl, { data: connectionDto });
// } catch (error) {
// throw new RpcException(error.response ? error.response : error);
// }
const connectionData = await this.connectionService.getConnectionWebhook(connectionDto, orgId);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
Expand All @@ -173,5 +173,4 @@ export class ConnectionController {

return res.status(HttpStatus.CREATED).json(finalResponse);
}
}
}
}
2 changes: 1 addition & 1 deletion apps/api-gateway/src/issuance/dtos/issuance.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsArray, IsNotEmpty, IsOptional, IsString, IsEmail, ArrayMaxSize, ValidateNested, ArrayNotEmpty, MinLength, ArrayMinSize } from 'class-validator';
import { IsArray, IsNotEmpty, IsOptional, IsString, IsEmail, ArrayMaxSize, ValidateNested, ArrayMinSize } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { toNumber, trim } from '@credebl/common/cast.helper';
Expand Down
27 changes: 13 additions & 14 deletions apps/api-gateway/src/issuance/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class IssuanceController {
private readonly imageServiceService: ImageServiceService,
private readonly awsService: AwsService,
private readonly commonService: CommonService
) {}
) { }
private readonly logger = new Logger('IssuanceController');
private readonly PAGE: number = 1;

Expand Down Expand Up @@ -181,7 +181,7 @@ export class IssuanceController {
.header('Content-Disposition', `attachment; filename="${exportedData.fileName}.csv"`)
.status(200)
.send(exportedData.fileContent);
} catch (error) {}
} catch (error) { }
}

@Post('/orgs/:orgId/bulk/upload')
Expand Down Expand Up @@ -569,7 +569,7 @@ export class IssuanceController {

if (credOffer.every(offer => (!offer?.attributes || 0 === offer?.attributes?.length ||
!offer?.attributes?.every(item => item?.name)
))
))
) {
throw new BadRequestException(ResponseMessages.issuance.error.attributesNotPresent);
}
Expand Down Expand Up @@ -603,17 +603,17 @@ export class IssuanceController {
@Param('id') id: string,
@Res() res: Response
): Promise<Response> {
const webhookUrl = await this.issueCredentialService._getWebhookUrl(issueCredentialDto.contextCorrelationId);
// const webhookUrl = await this.issueCredentialService._getWebhookUrl(issueCredentialDto.contextCorrelationId);

this.logger.debug(`issueCredentialDto ::: ${JSON.stringify(issueCredentialDto)}`);
if (webhookUrl) {
try {
await this.issueCredentialService._postWebhookResponse(webhookUrl, {data:issueCredentialDto});
} catch (error) {
throw new RpcException(error.response ? error.response : error);
}

// if (webhookUrl) {
// try {
// await this.issueCredentialService._postWebhookResponse(webhookUrl, {data:issueCredentialDto});
// } catch (error) {
// throw new RpcException(error.response ? error.response : error);
// }

const getCredentialDetails = await this.issueCredentialService.getIssueCredentialWebhook(issueCredentialDto, id);
const finalResponse: IResponseType = {
statusCode: HttpStatus.CREATED,
Expand Down Expand Up @@ -653,4 +653,3 @@ export class IssuanceController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}
}
}
110 changes: 54 additions & 56 deletions apps/api-gateway/src/verification/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { User } from '../authz/decorators/user.decorator';
import { GetAllProofRequestsDto } from './dto/get-all-proof-requests.dto';
import { IProofRequestSearchCriteria } from './interfaces/verification.interface';
import { SortFields } from './enum/verification.enum';
import { RpcException } from '@nestjs/microservices';

@UseFilters(CustomExceptionFilter)
@Controller()
Expand Down Expand Up @@ -68,8 +67,8 @@ export class VerificationController {
@User() user: IUserRequest,
@Param('proofId') proofId: string,
@Param('orgId') orgId: string
): Promise<Response> {
const sendProofRequest = await this.verificationService.getVerifiedProofDetails(proofId, orgId, user);
): Promise<Response> {
const sendProofRequest = await this.verificationService.getVerifiedProofDetails(proofId, orgId, user);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.verification.success.verifiedProofDetails,
Expand Down Expand Up @@ -125,7 +124,7 @@ export class VerificationController {
name: 'sortField',
enum: SortFields,
required: false
})
})
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiUnauthorizedResponse({ status: HttpStatus.UNAUTHORIZED, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden', type: ForbiddenErrorDto })
Expand All @@ -138,13 +137,13 @@ export class VerificationController {
@User() user: IUserRequest,
@Param('orgId') orgId: string
): Promise<Response> {
const { pageSize, searchByText, pageNumber, sortField, sortBy } = getAllProofRequests;
const proofRequestsSearchCriteria: IProofRequestSearchCriteria = {
pageNumber,
searchByText,
pageSize,
sortField,
sortBy
const { pageSize, searchByText, pageNumber, sortField, sortBy } = getAllProofRequests;
const proofRequestsSearchCriteria: IProofRequestSearchCriteria = {
pageNumber,
searchByText,
pageSize,
sortField,
sortBy
};

const proofPresentationDetails = await this.verificationService.getProofPresentations(proofRequestsSearchCriteria, user, orgId);
Expand All @@ -156,43 +155,43 @@ export class VerificationController {
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Send proof request
* @param orgId
* @returns Requested proof presentation details
*/
@Post('/orgs/:orgId/proofs')
@ApiOperation({
summary: `Sends a proof request`,
description: `Sends a proof request`
})
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiUnauthorizedResponse({ status: HttpStatus.UNAUTHORIZED, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden', type: ForbiddenErrorDto })
@ApiBody({ type: RequestProofDto })
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.VERIFIER)
async sendPresentationRequest(
@Res() res: Response,
@User() user: IUserRequest,
@Param('orgId') orgId: string,
@Body() requestProof: RequestProofDto
): Promise<Response> {
/**
* Send proof request
* @param orgId
* @returns Requested proof presentation details
*/
@Post('/orgs/:orgId/proofs')
@ApiOperation({
summary: `Sends a proof request`,
description: `Sends a proof request`
})
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiUnauthorizedResponse({ status: HttpStatus.UNAUTHORIZED, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden', type: ForbiddenErrorDto })
@ApiBody({ type: RequestProofDto })
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.VERIFIER)
async sendPresentationRequest(
@Res() res: Response,
@User() user: IUserRequest,
@Param('orgId') orgId: string,
@Body() requestProof: RequestProofDto
): Promise<Response> {

for (const attrData of requestProof.attributes) {
await this.validateAttribute(attrData);
}

for (const attrData of requestProof.attributes) {
await this.validateAttribute(attrData);
requestProof.orgId = orgId;
await this.verificationService.sendProofRequest(requestProof, user);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.verification.success.send
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}

requestProof.orgId = orgId;
await this.verificationService.sendProofRequest(requestProof, user);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.verification.success.send
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}

/**
* Verify proof presentation
* @param proofId
Expand Down Expand Up @@ -281,13 +280,13 @@ export class VerificationController {
@Res() res: Response
): Promise<Response> {
this.logger.debug(`proofPresentationPayload ::: ${JSON.stringify(proofPresentationPayload)}`);
const webhookUrl = await this.verificationService._getWebhookUrl(proofPresentationPayload.contextCorrelationId);
if (webhookUrl) {
try {
await this.verificationService._postWebhookResponse(webhookUrl, {data:proofPresentationPayload});
} catch (error) {
throw new RpcException(error.response ? error.response : error);
}
// const webhookUrl = await this.verificationService._getWebhookUrl(proofPresentationPayload.contextCorrelationId);
// if (webhookUrl) {
// try {
// await this.verificationService._postWebhookResponse(webhookUrl, {data:proofPresentationPayload});
// } catch (error) {
// throw new RpcException(error.response ? error.response : error);
// }
const webhookProofPresentation = await this.verificationService.webhookProofPresentation(orgId, proofPresentationPayload);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
Expand All @@ -296,7 +295,6 @@ export class VerificationController {
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}
}

async validateAttribute(
attrData: object
Expand All @@ -313,7 +311,7 @@ export class VerificationController {
}

if (!attrData['credDefId']) {
throw new BadRequestException('credDefId must be required');
throw new BadRequestException('credDefId must be required');
}

if (undefined !== attrData['credDefId'] && '' === attrData['credDefId'].trim()) {
Expand All @@ -328,9 +326,9 @@ export class VerificationController {
throw new BadRequestException('value cannot be empty');
}

if (attrData['condition']) {
if (attrData['condition']) {
if (isNaN(attrData['value'])) {
throw new BadRequestException('value must be an integer');
throw new BadRequestException('value must be an integer');
}
}
}
Expand Down