From 44b1cf0c400b4bd7fefc53033c78ca69b79b0d0e Mon Sep 17 00:00:00 2001 From: bhavanakarwade Date: Tue, 9 Jul 2024 19:33:55 +0530 Subject: [PATCH 1/2] refactor: endorsement flow for key and web method Signed-off-by: bhavanakarwade --- .../agent-service/src/agent-service.service.ts | 15 +++++++++------ .../src/ecosystem/ecosystem.controller.ts | 5 +++-- apps/ecosystem/src/ecosystem.service.ts | 18 ++++++++++++------ apps/ledger/src/schema/schema.service.ts | 2 +- libs/common/src/response-messages/index.ts | 3 ++- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/apps/agent-service/src/agent-service.service.ts b/apps/agent-service/src/agent-service.service.ts index 1b220e9a2..034db1331 100644 --- a/apps/agent-service/src/agent-service.service.ts +++ b/apps/agent-service/src/agent-service.service.ts @@ -802,9 +802,14 @@ export class AgentServiceService { let agentProcess; let ledgerIdData = []; try { - if (payload.method !== DidMethod.KEY && payload.method !== DidMethod.WEB) { + let ledger; const { network } = payload; - const ledger = await ledgerName(network); + if (network) { + ledger = await ledgerName(network); + } else { + ledger = Ledgers.Not_Applicable; + } + const ledgerList = (await this._getALlLedgerDetails()) as unknown as LedgerListResponse; const isLedgerExist = ledgerList.response.find((existingLedgers) => existingLedgers.name === ledger); if (!isLedgerExist) { @@ -813,10 +818,8 @@ export class AgentServiceService { description: ResponseMessages.errorMessages.notFound }); } - ledgerIdData = await this.agentServiceRepository.getLedgerDetails(ledger); - } - + const agentSpinUpStatus = AgentSpinUpStatus.PROCESSED; // Create and stored agent details @@ -859,7 +862,7 @@ export class AgentServiceService { orgAgentTypeId, tenantId: tenantDetails.walletResponseDetails['id'], walletName: payload.label, - ledgerId: ledgerIdData ? ledgerIdData.map((item) => item.id) : null, + ledgerId: ledgerIdData.map((item) => item.id), id: agentProcess?.id }; diff --git a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts index 5c2118605..ce2b69543 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts @@ -453,10 +453,11 @@ export class EcosystemController { @Res() res: Response ): Promise { const transactionResponse = await this.ecosystemService.submitTransaction(endorsementId, ecosystemId, orgId, user); + const finalResponse: IResponse = { statusCode: HttpStatus.CREATED, - message: ResponseMessages.ecosystem.success.submit, - data: transactionResponse + message: transactionResponse?.['responseMessage'], + data: transactionResponse?.['txnPayload'] }; return res.status(HttpStatus.CREATED).json(finalResponse); } diff --git a/apps/ecosystem/src/ecosystem.service.ts b/apps/ecosystem/src/ecosystem.service.ts index c368f08bd..ffb6ac2c0 100644 --- a/apps/ecosystem/src/ecosystem.service.ts +++ b/apps/ecosystem/src/ecosystem.service.ts @@ -22,7 +22,7 @@ import { EcosystemInviteTemplate } from '../templates/EcosystemInviteTemplate'; import { EmailDto } from '@credebl/common/dtos/email.dto'; import { sendEmail } from '@credebl/common/send-grid-helper-file'; import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosysteminvitation.dto'; -import { EcosystemConfigSettings, Invitation, JSONSchemaType, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum'; +import { EcosystemConfigSettings, Invitation, LedgerLessConstant, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum'; import { DeploymentModeType, EcosystemOrgStatus, @@ -136,7 +136,7 @@ export class EcosystemService { throw new NotFoundException(ResponseMessages.ecosystem.error.orgDidNotExist); } - const ecosystemLedgers = orgDetails.org_agents.map((agent) => agent.ledgers.id); + const ecosystemLedgers = orgDetails.org_agents.map((agent) => agent.ledgers?.id); const createEcosystem = await this.ecosystemRepository.createNewEcosystem(createEcosystemDto, ecosystemLedgers); if (!createEcosystem) { @@ -1604,7 +1604,7 @@ export class EcosystemService { return this.ecosystemRepository.updateTransactionStatus(endorsementId, endorsementTransactionStatus.SUBMITED); } - async submitTransaction(transactionPayload: ITransactionData): Promise { + async submitTransaction(transactionPayload: ITransactionData): Promise<{txnPayload: object, responseMessage: string}> { try { let txnPayload; @@ -1624,13 +1624,19 @@ export class EcosystemService { throw new ConflictException(ResponseMessages.ecosystem.error.transactionSubmitted); } + const parsedRequestPayload = JSON.parse(endorsementPayload?.requestPayload); + + const responseMessage = LedgerLessConstant.NO_LEDGER === parsedRequestPayload?.schemaType + ? ResponseMessages.ecosystem.success.submitNoLedgerSchema + : ResponseMessages.ecosystem.success.submit; + if (endorsementPayload?.type === endorsementTransactionType.W3C_SCHEMA) { txnPayload = await this.submitW3CTransaction(transactionPayload); } else { txnPayload = await this.submitIndyTransaction(transactionPayload); } - return txnPayload; + return { txnPayload, responseMessage }; } catch (error) { this.logger.error(`In submit transaction: ${JSON.stringify(error)}`); if (error?.error) { @@ -1773,11 +1779,11 @@ export class EcosystemService { schemaPayload: { schemaName: w3cEndorsementTransactionPayload?.requestBody?.['schemaName'], attributes: w3cEndorsementTransactionPayload?.requestBody?.['attributes'], - schemaType: JSONSchemaType.POLYGON_W3C, + schemaType: w3cEndorsementTransactionPayload?.requestBody?.['schemaType'], description: w3cEndorsementTransactionPayload?.requestBody?.['description'] } }, - orgId: transactionPayload?.orgId, + orgId: w3cEndorsementTransactionPayload?.['ecosystemOrgs']?.orgId, user: transactionPayload?.user }; diff --git a/apps/ledger/src/schema/schema.service.ts b/apps/ledger/src/schema/schema.service.ts index 963273c13..e6b7c699c 100644 --- a/apps/ledger/src/schema/schema.service.ts +++ b/apps/ledger/src/schema/schema.service.ts @@ -260,7 +260,7 @@ export class SchemaService extends BaseService { async createW3CSchema(orgId:string, schemaPayload: ICreateW3CSchema, user: string): Promise { try { let createSchema; - + const { description, attributes, schemaName} = schemaPayload; const agentDetails = await this.schemaRepository.getAgentDetailsByOrgId(orgId); if (!agentDetails) { diff --git a/libs/common/src/response-messages/index.ts b/libs/common/src/response-messages/index.ts index 99ae5a2cb..62f218fb7 100644 --- a/libs/common/src/response-messages/index.ts +++ b/libs/common/src/response-messages/index.ts @@ -374,7 +374,8 @@ export const ResponseMessages = { schemaRequest: 'Schema transaction request created successfully', credDefRequest: 'Credential definition transaction request created successfully', sign: 'Endorsement request approved', - submit: 'Endorsement request submitted to ledger', + submit: 'Endorsement request is submitted to ledger', + submitNoLedgerSchema: 'Endorsement request is submitted', invitationReject: 'Ecosystem invitation rejected', invitationAccept: 'Ecosystem invitation accepted successfully', deleteEcosystemMember: 'You are deleted as a ecosystem member', From 9646ab83619625491f3bfa3edfc1d99c6c748843 Mon Sep 17 00:00:00 2001 From: bhavanakarwade Date: Wed, 10 Jul 2024 11:22:43 +0530 Subject: [PATCH 2/2] refactor: send email for issuance Signed-off-by: bhavanakarwade --- apps/issuance/src/issuance.service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/issuance/src/issuance.service.ts b/apps/issuance/src/issuance.service.ts index 33ee1667d..55b48a28a 100644 --- a/apps/issuance/src/issuance.service.ts +++ b/apps/issuance/src/issuance.service.ts @@ -32,7 +32,7 @@ import { ICredentialOfferResponse, IDeletedIssuanceRecords, IIssuedCredential, I import { OOBIssueCredentialDto } from 'apps/api-gateway/src/issuance/dtos/issuance.dto'; import { RecordType, agent_invitations, organisation, user } from '@prisma/client'; import { createOobJsonldIssuancePayload, validateEmail } from '@credebl/common/cast.helper'; -// import { sendEmail } from '@credebl/common/send-grid-helper-file'; +import { sendEmail } from '@credebl/common/send-grid-helper-file'; import * as pLimit from 'p-limit'; import { UserActivityRepository } from 'libs/user-activity/repositories'; import { validateW3CSchemaAttributes } from '../libs/helpers/attributes.validator'; @@ -804,8 +804,7 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO } ]; - const isEmailSent = true; // change this after testing on local - // const isEmailSent = await sendEmail(this.emailData); + const isEmailSent = await sendEmail(this.emailData); this.logger.log(`isEmailSent ::: ${JSON.stringify(isEmailSent)}-${this.counter}`); this.counter++;