Skip to content

Commit

Permalink
feat: Register organization specific webhook and Dispatch organizatio…
Browse files Browse the repository at this point in the history
…n-specific webhook data to the registered URL (#428)

* feat:updated webhook design

Signed-off-by: pallavicoder <[email protected]>

* chore:added http status code

Signed-off-by: pallavicoder <[email protected]>

* refact:added success ans error messages inside agent

Signed-off-by: pallavicoder <[email protected]>

* refact:added validation,errors and exceptions

Signed-off-by: pallavicoder <[email protected]>

* feat:added retry logic for send webhook responses

Signed-off-by: pallavicoder <[email protected]>

---------

Signed-off-by: pallavicoder <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
pallavighule authored and KulkarniShashank committed Sep 11, 2024
1 parent 1fc4d02 commit 8369bf0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
18 changes: 9 additions & 9 deletions apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IConnectionSearchinterface } from '../interfaces/ISchemaSearch.interfac
import { ApiResponseDto } from '../dtos/apiResponse.dto';
import { IConnectionSearchCriteria } from '../interfaces/IConnectionSearch.interface';
import { SortFields } from 'apps/connection/src/enum/connection.enum';
import { ClientProxy} from '@nestjs/microservices';
import { ClientProxy, RpcException} from '@nestjs/microservices';

@UseFilters(CustomExceptionFilter)
@Controller()
Expand Down Expand Up @@ -158,14 +158,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 @@ -176,4 +176,4 @@ export class ConnectionController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}
}

}
15 changes: 8 additions & 7 deletions apps/api-gateway/src/issuance/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,16 @@ 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 = {
Expand Down Expand Up @@ -649,3 +649,4 @@ export class IssuanceController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}
}
}
17 changes: 9 additions & 8 deletions apps/api-gateway/src/verification/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ 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)
Expand Down Expand Up @@ -281,21 +282,21 @@ 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,
message: ResponseMessages.verification.success.create,
data: webhookProofPresentation
};
return res.status(HttpStatus.CREATED).json(finalResponse);

}
}

async validateAttribute(
Expand Down

0 comments on commit 8369bf0

Please sign in to comment.