Skip to content

Commit

Permalink
Merge pull request #24 from Bhutan-NDI/feat/threadId-proofreq-email
Browse files Browse the repository at this point in the history
Add thread id proof request to be sent via email
  • Loading branch information
ankita-p17 authored Dec 10, 2024
2 parents 91ea898 + edff9e2 commit 495a063
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
33 changes: 24 additions & 9 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import { BadRequestException, HttpException, Inject, Injectable, InternalServerErrorException, Logger, NotFoundException } from '@nestjs/common';
import { BadRequestException, HttpException, HttpStatus, Inject, Injectable, InternalServerErrorException, Logger, NotFoundException } from '@nestjs/common';
import { ClientProxy, RpcException } from '@nestjs/microservices';
import { map } from 'rxjs/operators';
import { IGetAllProofPresentations, IProofRequestSearchCriteria, IGetProofPresentationById, IProofPresentation, IProofRequestPayload, IRequestProof, ISendProofRequestPayload, IVerifyPresentation, IVerifiedProofData, IInvitation } from './interfaces/verification.interface';
Expand Down Expand Up @@ -455,8 +455,8 @@ export class VerificationService {
}

if (emailId) {
await this.sendEmailInBatches(payload, emailId, getAgentDetails, getOrganization);
return true;
const emailResponse = await this.sendEmailInBatches(payload, emailId, getAgentDetails, getOrganization);
return emailResponse;
} else {
const presentationProof: IInvitation = await this.generateOOBProofReq(payload);
const proofRequestInvitationUrl: string = presentationProof.invitationUrl;
Expand Down Expand Up @@ -499,13 +499,16 @@ export class VerificationService {


// Currently batch size is not used, as length of emails sent is restricted to '10'
async sendEmailInBatches(payload: IProofRequestPayload, emailIds: string[], getAgentDetails: org_agents, organizationDetails: organisation): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async sendEmailInBatches(payload: IProofRequestPayload, emailIds: string[], getAgentDetails: org_agents, organizationDetails: organisation): Promise<any> {
try {
const accumulatedErrors = [];
const accumulatedResponse = [];

for (const email of emailIds) {
try {
await this.sendOutOfBandProofRequest(payload, email, getAgentDetails, organizationDetails);
const response = await this.sendOutOfBandProofRequest(payload, email, getAgentDetails, organizationDetails);
accumulatedResponse.push({email, ...response});
await this.delay(500);
} catch (error) {
this.logger.error(`Error sending email to ${email}::::::`, error);
Expand All @@ -518,6 +521,8 @@ export class VerificationService {
throw new Error(ResponseMessages.verification.error.emailSend);
}

return accumulatedResponse;

} catch (error) {
this.logger.error('[sendEmailInBatches] - error in sending email in batches');
throw new Error(ResponseMessages.verification.error.batchEmailSend);
Expand All @@ -526,8 +531,9 @@ export class VerificationService {


// This function is specifically for OOB verification using email
async sendOutOfBandProofRequest(payload: IProofRequestPayload, email: string, getAgentDetails: org_agents, organizationDetails: organisation): Promise<boolean> {
const getProofPresentation = await this._sendOutOfBandProofRequest(payload);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async sendOutOfBandProofRequest(payload: IProofRequestPayload, email: string, getAgentDetails: org_agents, organizationDetails: organisation): Promise<any> {
const getProofPresentation = await this._sendOutOfBandProofRequest(payload);

if (!getProofPresentation) {
throw new Error(ResponseMessages.verification.error.proofPresentationNotFound);
Expand Down Expand Up @@ -565,7 +571,11 @@ export class VerificationService {
throw new Error(ResponseMessages.verification.error.emailSend);
}

return isEmailSent;
return {
isEmailSent,
outOfBandRecordId: getProofPresentation?.response?.outOfBandRecord?.id,
proofRecordThId: getProofPresentation?.response?.proofRecordThId
};
}


Expand Down Expand Up @@ -977,9 +987,14 @@ export class VerificationService {

verificationErrorHandling(error): void {
if (!error && !error?.status && !error?.status?.message && !error?.status?.message?.error) {

throw new RpcException(error.response ? error.response : error);
} else {
if (error?.message) {
throw new RpcException({
message: error?.message,
statusCode: HttpStatus.INTERNAL_SERVER_ERROR
});
}
throw new RpcException({
message: error?.status?.message?.error?.reason ? error?.status?.message?.error?.reason : error?.status?.message?.error,
statusCode: error?.status?.code
Expand Down
16 changes: 5 additions & 11 deletions apps/verification/templates/out-of-band-verification.template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class OutOfBandVerification {

public outOfBandVerification(email: string, orgName: string, deeplLinkURL: string): string {
public outOfBandVerification(email: string, orgName: string, deepLinkURL: string): string {
try {
return `<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -45,27 +45,21 @@ export class OutOfBandVerification {
</li>
<li>Complete the onboarding process in ${process.env.MOBILE_APP}.</li>
<li>Open the “Share Credential” link below in this email <i>(This will open the link in the ${process.env.MOBILE_APP} App)</i></li>
<li>Tap the <b>"Send Proof"</b> button in ${process.env.MOBILE_APP} to share you credential data.</li>
<li>Tap the <b>"Share"</b> button in ${process.env.MOBILE_APP} to share you credential data.</li>
</ul>
<div style="text-align: center; padding-bottom: 20px;">
<a clicktracking=off href="${deeplLinkURL}"
<a clicktracking=off href="${deepLinkURL}"
class="mobile-button"
style="padding: 10px 20px 10px 20px;color: #fff;background: #1F4EAD;border-radius: 5px;text-decoration: none;">
style="padding: 10px 20px 10px 20px;color: #fff;background: #124143;border-radius: 5px;text-decoration: none;">
Share Credential
</a>
<a clicktracking=off href="${process.env.MOBILE_APP_DOWNLOAD_URL}"
class="desktop-button"
style="padding: 10px 20px 10px 20px;color: #fff;background: #1F4EAD;border-radius: 5px;text-decoration: none;">
Download App
</a>
</div>
</p>
<p>
<b>Note:</b> If the above steps do not work for you, please open the <b>attached QR Code image</b> in this email on another device, and scan the QR code using the ${process.env.MOBILE_APP_NAME} on your mobile device.
<b>Note:</b> Alternatively, you will find a <b>QR Code image attached</b> to this email. You can open the QR code on another device and scan the QR code using the ${process.env.MOBILE_APP} App on your mobile device.
<u> The QR Code is single-use.</u>
</p>
<hr style="border-top:1px solid #e8e8e8" />
<footer style="padding-top: 20px;">
Expand Down

0 comments on commit 495a063

Please sign in to comment.