Skip to content

Commit 69b8f27

Browse files
authored
chore: add dubug logs (#1474)
* fix: add dubug logs Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com> * fix: add dubug logs Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com> --------- Signed-off-by: Krishna Waske <krishna.waske@ayanworks.com>
1 parent 6f4be27 commit 69b8f27

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

apps/issuance/libs/helpers/attributes.validator.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
/* eslint-disable no-console */
12
import { W3CSchemaDataType } from '@credebl/enum/enum';
2-
import { BadRequestException } from '@nestjs/common';
3+
import { BadRequestException, Logger } from '@nestjs/common';
34
import { IIssuanceAttributes, ISchemaAttributes } from 'apps/issuance/interfaces/issuance.interfaces';
45

56
export function validateW3CSchemaAttributes(
67
filteredIssuanceAttributes: IIssuanceAttributes,
7-
schemaUrlAttributes: ISchemaAttributes[]
8+
schemaUrlAttributes: ISchemaAttributes[],
9+
logger: Logger
810
): void {
11+
logger.debug('Validating w3c schema attributes');
912
const mismatchedAttributes: string[] = [];
1013
const missingAttributes: string[] = [];
1114
const extraAttributes: string[] = [];
@@ -30,9 +33,10 @@ export function validateW3CSchemaAttributes(
3033
const actualType = typeof attributeValue;
3134

3235
// Check if the schemaDataType is 'datetime-local' and treat it as a string
33-
if ((W3CSchemaDataType.DATE_TIME === schemaDataType && W3CSchemaDataType.STRING !== actualType) ||
34-
(W3CSchemaDataType.DATE_TIME !== schemaDataType && actualType !== schemaDataType)) {
35-
36+
if (
37+
(W3CSchemaDataType.DATE_TIME === schemaDataType && W3CSchemaDataType.STRING !== actualType) ||
38+
(W3CSchemaDataType.DATE_TIME !== schemaDataType && actualType !== schemaDataType)
39+
) {
3640
mismatchedAttributes.push(
3741
`Attribute ${attributeName} has type ${actualType} but expected type ${schemaDataType}`
3842
);
@@ -57,4 +61,6 @@ export function validateW3CSchemaAttributes(
5761
if (0 < extraAttributes.length) {
5862
throw new BadRequestException(`Validation failed: ${extraAttributes.join(', ')}`);
5963
}
64+
// TODO: Maybe we can have a try catch here, so that instead of directly throwing the erros
65+
logger.debug('W3c schema attributes validated successfully');
6066
}

apps/issuance/src/issuance.controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import {
1515
IIssuedCredential
1616
} from '@credebl/common/interfaces/issuance.interface';
1717

18-
import { Controller } from '@nestjs/common';
18+
import { Controller, Logger } from '@nestjs/common';
1919
import { IssuanceService } from './issuance.service';
2020
import { MessagePattern } from '@nestjs/microservices';
2121
import { OOBIssueCredentialDto } from 'apps/api-gateway/src/issuance/dtos/issuance.dto';
2222
import { user } from '@prisma/client';
2323

2424
@Controller()
2525
export class IssuanceController {
26+
private readonly logger = new Logger('IssueCredentialController');
2627
constructor(private readonly issuanceService: IssuanceService) {}
2728

2829
@MessagePattern({ cmd: 'get-issuance-records' })
@@ -61,6 +62,7 @@ export class IssuanceController {
6162
@MessagePattern({ cmd: 'out-of-band-credential-offer' })
6263
async outOfBandCredentialOffer(payload: OutOfBandCredentialOffer): Promise<boolean> {
6364
const { outOfBandCredentialDto } = payload;
65+
this.logger.debug('Request reached issuance microservice controller, issuing oob credential');
6466
return this.issuanceService.outOfBandCredentialOffer(outOfBandCredentialDto);
6567
}
6668

apps/issuance/src/issuance.service.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class IssuanceService {
125125
}
126126

127127
async getW3CSchemaAttributes(schemaUrl: string): Promise<ISchemaAttributes[]> {
128+
this.logger.debug('Getting w3c schema attributes from schemaUrl', schemaUrl);
128129
const schemaRequest = await this.commonService.httpGet(schemaUrl).then(async (response) => response);
129130
if (!schemaRequest) {
130131
throw new NotFoundException(ResponseMessages.schema.error.W3CSchemaNotFOund, {
@@ -140,6 +141,7 @@ export class IssuanceService {
140141
}
141142

142143
const schemaAttributes = JSON.parse(getSchemaDetails?.attributes);
144+
this.logger.debug('Schema attributes fetched successfully', JSON.stringify(schemaAttributes, null, 2));
143145

144146
return schemaAttributes;
145147
}
@@ -246,7 +248,7 @@ export class IssuanceService {
246248
const schemaUrlAttributes = await this.getW3CSchemaAttributes(schemaServerUrl);
247249

248250
if (isValidateSchema) {
249-
validateW3CSchemaAttributes(filteredIssuanceAttributes, schemaUrlAttributes);
251+
validateW3CSchemaAttributes(filteredIssuanceAttributes, schemaUrlAttributes, this.logger);
250252
}
251253
}
252254

@@ -447,7 +449,7 @@ export class IssuanceService {
447449
const schemaUrlAttributes = await this.getW3CSchemaAttributes(schemaServerUrl);
448450

449451
if (isValidateSchema) {
450-
validateW3CSchemaAttributes(filteredIssuanceAttributes, schemaUrlAttributes);
452+
validateW3CSchemaAttributes(filteredIssuanceAttributes, schemaUrlAttributes, this.logger);
451453
}
452454
}
453455
const credentialCreateOfferDetails = await this._outOfBandCredentialOffer(issueData, url, orgId);
@@ -762,21 +764,27 @@ export class IssuanceService {
762764
isValidateSchema
763765
} = outOfBandCredential;
764766

767+
this.logger.debug('Request reaced isuance microservice service');
765768
const agentDetails = await this.issuanceRepository.getAgentEndPoint(orgId);
766769

770+
this.logger.debug('The credential to be issued is of type:', credentialType);
767771
if (IssueCredentialType.JSONLD === credentialType) {
768772
await validateAndUpdateIssuanceDates(credentialOffer);
769773

774+
this.logger.debug('Validated/Updated Issuance dates credential offer');
770775
const schemaIds = credentialOffer?.map((item) => {
771776
const context: string[] = item?.credential?.['@context'];
772777
return Array.isArray(context) && 1 < context.length ? context[1] : undefined;
773778
});
774779

780+
this.logger.debug('Issuing credential with schemaIds', schemaIds);
775781
const schemaDetails = await this._getSchemaDetails(schemaIds);
776782

777783
const ledgerIds = schemaDetails?.map((item) => item?.ledgerId);
784+
this.logger.debug('Issuance will be done with the following schemas: ', JSON.stringify(schemaDetails, null, 2));
778785

779786
for (const ledgerId of ledgerIds) {
787+
this.logger.debug('Checking ledger compatibility of schemas and issuer agent');
780788
if (agentDetails?.ledgerId !== ledgerId) {
781789
throw new BadRequestException(ResponseMessages.issuance.error.ledgerMismatched);
782790
}
@@ -787,6 +795,10 @@ export class IssuanceService {
787795
const schemaResponse: SchemaDetails =
788796
await this.issuanceRepository.getCredentialDefinitionDetails(credentialDefinitionId);
789797

798+
this.logger.debug(
799+
'Schema details for indy based credential received:',
800+
JSON.stringify(schemaResponse, null, 2)
801+
);
790802
let attributesArray: IAttributes[] = [];
791803
if (schemaResponse?.attributes) {
792804
attributesArray = JSON.parse(schemaResponse.attributes);
@@ -803,6 +815,7 @@ export class IssuanceService {
803815
}
804816
});
805817
if (0 < attrError.length) {
818+
this.logger.debug('Error validating attributes. Number of errors:', attrError.length);
806819
throw new BadRequestException(attrError);
807820
}
808821
}
@@ -839,6 +852,7 @@ export class IssuanceService {
839852
throw new NotFoundException(ResponseMessages.issuance.error.organizationNotFound);
840853
}
841854
const errors = [];
855+
this.logger.debug('Creating offer response for agent on url: ', url);
842856
let credentialOfferResponse;
843857
const arraycredentialOfferResponse = [];
844858
const sendEmailCredentialOffer: {
@@ -890,12 +904,14 @@ export class IssuanceService {
890904
};
891905

892906
if (credentialOffer) {
907+
this.logger.debug('Iterating over credentials offers: ', credentialOffer.entries());
893908
for (const [index, iterator] of credentialOffer.entries()) {
894909
sendEmailCredentialOffer['iterator'] = iterator;
895910
sendEmailCredentialOffer['emailId'] = iterator.emailId;
896911
sendEmailCredentialOffer['index'] = index;
897912

898913
await this.delay(500); // Wait for 0.5 seconds
914+
this.logger.debug(`Sending offer number: index: ${index}, iterator: ${iterator}`);
899915
const sendOobOffer = await this.sendEmailForCredentialOffer(sendEmailCredentialOffer);
900916
arraycredentialOfferResponse.push(sendOobOffer);
901917
}
@@ -905,6 +921,7 @@ export class IssuanceService {
905921

906922
return arraycredentialOfferResponse.every((result) => true === result);
907923
} else {
924+
this.logger.debug('Sending a single OOB email offer');
908925
credentialOfferResponse = await this.sendEmailForCredentialOffer(sendEmailCredentialOffer);
909926
return credentialOfferResponse;
910927
}
@@ -957,6 +974,7 @@ export class IssuanceService {
957974
try {
958975
let invitationDid: string | undefined;
959976
if (true === isReuseConnection) {
977+
this.logger.debug('This is a reuse connection, fetching invitation did');
960978
const data: agent_invitations[] = await this.issuanceRepository.getInvitationDidByOrgId(orgId);
961979
if (data && 0 < data.length) {
962980
const [firstElement] = data;
@@ -965,6 +983,7 @@ export class IssuanceService {
965983
}
966984

967985
let outOfBandIssuancePayload;
986+
this.logger.debug('This is an email issuance of type', credentialType);
968987
if (IssueCredentialType.INDY === credentialType) {
969988
outOfBandIssuancePayload = {
970989
protocolVersion: protocolVersion || 'v1',
@@ -1016,20 +1035,24 @@ export class IssuanceService {
10161035
const schemaUrlAttributes = await this.getW3CSchemaAttributes(schemaServerUrl);
10171036

10181037
if (isValidateSchema) {
1019-
validateW3CSchemaAttributes(filteredIssuanceAttributes, schemaUrlAttributes);
1038+
validateW3CSchemaAttributes(filteredIssuanceAttributes, schemaUrlAttributes, this.logger);
10201039
}
10211040
}
1041+
this.logger.debug('Payload created for issuance');
10221042
const credentialCreateOfferDetails = await this._outOfBandCredentialOffer(outOfBandIssuancePayload, url, orgId);
1043+
this.logger.debug('Offer created successfully');
10231044

10241045
if (!credentialCreateOfferDetails) {
10251046
errors.push(new NotFoundException(ResponseMessages.issuance.error.credentialOfferNotFound));
10261047
return false;
10271048
}
10281049

10291050
const invitationUrl: string = credentialCreateOfferDetails.response?.invitationUrl;
1051+
this.logger.debug('Shortening invitation url');
10301052
const shortenUrl: string = await this.storeIssuanceObjectReturnUrl(invitationUrl);
10311053

10321054
const deepLinkURL = convertUrlToDeepLinkUrl(shortenUrl);
1055+
this.logger.debug('Deeplink URL created successfully');
10331056

10341057
if (!invitationUrl) {
10351058
errors.push(new NotFoundException(ResponseMessages.issuance.error.invitationNotFound));
@@ -1061,6 +1084,7 @@ export class IssuanceService {
10611084
disposition: 'attachment'
10621085
}
10631086
];
1087+
this.logger.debug('Invitation url and deeplink created successfully. Sending email');
10641088

10651089
const isEmailSent = await sendEmail(this.emailData);
10661090

@@ -1084,6 +1108,10 @@ export class IssuanceService {
10841108
}
10851109
}
10861110
}
1111+
this.logger.debug(
1112+
'Email sent successfully for credential threadId:',
1113+
credentialCreateOfferDetails.response.credentialRequestThId ?? ''
1114+
);
10871115

10881116
return isEmailSent;
10891117
} catch (error) {
@@ -1123,9 +1151,12 @@ export class IssuanceService {
11231151
response;
11241152
}> {
11251153
try {
1154+
this.logger.debug('Issuance service call to the agent controller for creating an OOB offer');
11261155
const pattern = { cmd: 'agent-out-of-band-credential-offer' };
11271156
const payload = { outOfBandIssuancePayload, url, orgId };
1128-
return await this.natsCall(pattern, payload);
1157+
const result = await this.natsCall(pattern, payload);
1158+
this.logger.debug('Success: Issuance service call to the agent controller for creating an OOB offer');
1159+
return result;
11291160
} catch (error) {
11301161
this.logger.error(`[_outOfBandCredentialOffer] [NATS call]- error in out of band : ${JSON.stringify(error)}`);
11311162
throw error;

0 commit comments

Comments
 (0)