Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions apps/agent-service/src/agent-service.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Test, TestingModule } from '@nestjs/testing';
import { AgentServiceService } from './agent-service.service';
import { AgentServiceRepository } from './repositories/agent-service.repository';
import { PrismaService } from '@credebl/prisma-service';
import { CommonService } from '@credebl/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { UserActivityRepository } from 'libs/user-activity/repositories';
import { NATSClient } from '@credebl/common/NATSClient';
import { RpcException } from '@nestjs/microservices';
import { ResponseMessages } from '@credebl/common/response-messages';
import { DidMethod } from '@credebl/enum/enum';

describe('AgentServiceService - createDid duplicate handling', () => {
let service: AgentServiceService;
let commonService: Partial<CommonService>;
let agentServiceRepository: Partial<AgentServiceRepository>;

beforeEach(async () => {
commonService = {
httpPost: jest.fn(),
decryptPassword: jest.fn().mockResolvedValue('decrypted-api-key')
};

agentServiceRepository = {
getOrgAgentDetails: jest.fn().mockResolvedValue({
id: 'agent-id-1',
agentEndPoint: 'http://localhost:3000',
ledgerId: null,
apiKey: 'encrypted-api-key'
}),
getLedgerByNameSpace: jest.fn().mockResolvedValue({ id: 'ledger-id-1' }),
getOrgDid: jest.fn().mockResolvedValue([]),
storeDidDetails: jest.fn(),
updateIsPrimaryDid: jest.fn(),
setPrimaryDid: jest.fn(),
getLedger: jest.fn().mockResolvedValue({ id: 'ledger-id-1' }),
updateLedgerId: jest.fn()
};

const module: TestingModule = await Test.createTestingModule({
providers: [
AgentServiceService,
{ provide: AgentServiceRepository, useValue: agentServiceRepository },
{ provide: PrismaService, useValue: {} },
{ provide: CommonService, useValue: commonService },
{ provide: 'NATS_CLIENT', useValue: { send: jest.fn() } },
{ provide: CACHE_MANAGER, useValue: { get: jest.fn(), set: jest.fn() } },
{ provide: UserActivityRepository, useValue: {} },
{ provide: NATSClient, useValue: {} }
]
}).compile();

service = module.get<AgentServiceService>(AgentServiceService);
jest.spyOn(service, 'getOrgAgentApiKey').mockResolvedValue('test-api-key');
});

const mockPayload = {
seed: '12345678901234567890123456789012',
keyType: 'ed25519',
method: DidMethod.INDY,
network: 'indicio:demonet',
role: 'endorser',
isPrimaryDid: false
};

const mockUser = {
id: 'user-id-1',
email: 'test@example.com'
} as any;

it('should throw 409 Conflict with "DID already exist" when Credo returns "CredoError: Key already exists"', async () => {
(commonService.httpPost as jest.Mock).mockRejectedValue({
response: {
status: 500,
error: 'CredoError: Key already exists'
}
});

try {
await service.createDid(mockPayload as any, 'org-id-1', mockUser);
fail('Expected RpcException to be thrown');
} catch (error) {
expect(error).toBeInstanceOf(RpcException);
const rpcError = error.getError();
expect(rpcError).toEqual({
statusCode: 409,
message: ResponseMessages.agent.error.didAlreadyExist,
error: 'Conflict'
});
}
});

it('should throw 409 Conflict when DID already exists in organization wallet database', async () => {
(commonService.httpPost as jest.Mock).mockResolvedValue({
did: 'did:indy:indicio:demonet:existing-did',
didDocument: {}
});

(agentServiceRepository.getOrgDid as jest.Mock).mockResolvedValue([{ did: 'did:indy:indicio:demonet:existing-did' }]);

try {
await service.createDid(mockPayload as any, 'org-id-1', mockUser);
fail('Expected RpcException to be thrown');
} catch (error) {
expect(error).toBeInstanceOf(RpcException);
const rpcError = error.getError();
expect(rpcError).toEqual({
statusCode: 409,
message: ResponseMessages.agent.error.didAlreadyExist,
error: 'Conflict'
});
}
});
});
26 changes: 22 additions & 4 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
private readonly natsClient: NATSClient
) {}

async ReplaceAt(input, search, replace, start, end): Promise<string> {

Check warning on line 104 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'ReplaceAt' has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63X&open=AaD3LGp-R_0OgvMtI63X&pullRequest=1769
return input.slice(0, start) + input.slice(start, end).replace(search, replace) + input.slice(end);
}

Expand Down Expand Up @@ -132,7 +132,7 @@
await this.provisionWallet(agentSpinupDto, user);
return { agentSpinupStatus: AgentSpinUpStatus.DID_CREATED };
} catch (error) {
this.handleErrorOnWalletProvision(agentSpinupDto, error, agentProcess);

Check warning on line 135 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63Y&open=AaD3LGp-R_0OgvMtI63Y&pullRequest=1769
throw new RpcException(error.response ?? error);
}
}
Expand Down Expand Up @@ -233,16 +233,16 @@
agentProcess = await this.createOrgAgent(agentSpinUpStatus, userId, agentSpinupDto.orgId);

// Credo agent spin-up
this._agentSpinup(
walletProvisionPayload,
agentSpinupDto,
platformConfig?.sgApiKey,
orgData,
user,
socket,
agentSpinupDto.ledgerId,
agentProcess
);

Check warning on line 245 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63Z&open=AaD3LGp-R_0OgvMtI63Z&pullRequest=1769
} catch (error) {
this.handleErrorOnWalletProvision(agentSpinupDto, error, agentProcess);
throw error;
Expand Down Expand Up @@ -390,7 +390,7 @@
}
}

async prepareWalletProvisionPayload(

Check warning on line 393 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'prepareWalletProvisionPayload' has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63b&open=AaD3LGp-R_0OgvMtI63b&pullRequest=1769
agentSpinupDto: IAgentSpinupDto,
externalIp: string,
apiEndpoint: string,
Expand Down Expand Up @@ -429,7 +429,7 @@
return walletProvisionPayload;
}

async initSocketConnection(socketHost: string): Promise<Socket> {

Check warning on line 432 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'initSocketConnection' has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63c&open=AaD3LGp-R_0OgvMtI63c&pullRequest=1769
const socket = io(socketHost, {
reconnection: true,
reconnectionDelay: 5000,
Expand Down Expand Up @@ -461,14 +461,14 @@
const socket = await this.initSocketConnection(`${process.env.SOCKET_HOST}`);

if (agentSpinupDto.clientSocketId) {
this.emitErrorInWalletCreationEvent(agentSpinupDto, socket, error);

Check warning on line 464 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63d&open=AaD3LGp-R_0OgvMtI63d&pullRequest=1769
}
this.agentServiceRepository.removeOrgAgent(agentProcess?.id);

Check warning on line 466 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63e&open=AaD3LGp-R_0OgvMtI63e&pullRequest=1769
this.logger.error(`Error in Agent spin up: ${JSON.stringify(error)}`);
}
}

async emitErrorInWalletCreationEvent(agentSpinupDto: IAgentSpinupDto, socket: Socket, error: Error): Promise<void> {

Check warning on line 471 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'emitErrorInWalletCreationEvent' has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63f&open=AaD3LGp-R_0OgvMtI63f&pullRequest=1769
try {
socket.emit('error-in-wallet-creation-process', { clientId: agentSpinupDto.clientSocketId, error });
this.logger.error(`Error in wallet creation process emitted for orgId ${agentSpinupDto.orgId}: ${error.message}`);
Expand Down Expand Up @@ -642,7 +642,7 @@
}

if (payload && payload?.id) {
this.agentServiceRepository.removeOrgAgent(payload?.id);

Check warning on line 645 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63g&open=AaD3LGp-R_0OgvMtI63g&pullRequest=1769
}

this.logger.error(`[_storeOrgAgentDetails] - Error in store agent details : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -827,20 +827,20 @@
// Get organization data
const getOrganization = await this.agentServiceRepository.getOrgDetails(payload.orgId);

this.notifyClientSocket('agent-spinup-process-completed', payload.clientSocketId);

Check warning on line 830 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63h&open=AaD3LGp-R_0OgvMtI63h&pullRequest=1769

const orgAgentDetails = await this.agentServiceRepository.storeOrgAgentDetails(storeOrgAgentData);

this.notifyClientSocket('invitation-url-creation-started', payload.clientSocketId);

Check warning on line 834 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63i&open=AaD3LGp-R_0OgvMtI63i&pullRequest=1769

// Create the legacy connection invitation
await this._createConnectionInvitation(payload.orgId, user, getOrganization.name);

this.notifyClientSocket('invitation-url-creation-success', payload.clientSocketId);

Check warning on line 839 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63j&open=AaD3LGp-R_0OgvMtI63j&pullRequest=1769

return orgAgentDetails;
} catch (error) {
this.handleError(error, payload.clientSocketId);

Check warning on line 843 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63k&open=AaD3LGp-R_0OgvMtI63k&pullRequest=1769
throw error;
}
}
Expand Down Expand Up @@ -932,6 +932,27 @@
} catch (error) {
this.logger.error(`error in create did : ${JSON.stringify(error)}`);

const errorText =
error?.response?.error?.message ??
error?.response?.error ??
error?.response?.data?.error ??
error?.response?.data?.message ??
error?.response?.data ??
error?.message ??
(typeof error === 'string' ? error : JSON.stringify(error));

const isDuplicateDid =
typeof errorText === 'string' &&
(errorText.includes('Key already exists') || errorText.includes('already exist'));

if (isDuplicateDid) {
throw new RpcException({
statusCode: HttpStatus.CONFLICT,
message: ResponseMessages.agent.error.didAlreadyExist,
error: 'Conflict'
});
}

if (error?.response?.error?.message) {
throw new RpcException({
statusCode: error?.response?.status,
Expand Down Expand Up @@ -965,10 +986,7 @@
private checkDidExistence(getDidByOrg, didDetails): void {
const didExist = getDidByOrg.some((orgDidExist) => orgDidExist.did === didDetails.did);
if (didExist) {
throw new ConflictException(ResponseMessages.agent.error.didAlreadyExist, {
cause: new Error(),
description: ResponseMessages.errorMessages.serverError
});
throw new ConflictException(ResponseMessages.agent.error.didAlreadyExist);
}
}

Expand Down Expand Up @@ -1157,7 +1175,7 @@
return didDetails;
}

private async createSocketInstance(): Promise<Socket> {

Check warning on line 1178 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'createSocketInstance' has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63l&open=AaD3LGp-R_0OgvMtI63l&pullRequest=1769
return io(`${process.env.SOCKET_HOST}`, {
reconnection: true,
reconnectionDelay: 5000,
Expand Down Expand Up @@ -1254,7 +1272,7 @@

schemaResponse = await this.commonService
.httpGet(url, { headers: { authorization: getApiKey } })
.then(async (schema) => schema);

Check warning on line 1275 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63p&open=AaD3LGp-R_0OgvMtI63p&pullRequest=1769
}
return schemaResponse;
} catch (error) {
Expand All @@ -1278,7 +1296,7 @@

credDefResponse = await this.commonService
.httpPost(url, credDefPayload, { headers: { authorization: getApiKey } })
.then(async (credDef) => credDef);

Check warning on line 1299 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63q&open=AaD3LGp-R_0OgvMtI63q&pullRequest=1769
} else if (OrgAgentType.SHARED === payload.agentType) {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_CREATE_CRED_DEF}`;
const credDefPayload = {
Expand All @@ -1288,7 +1306,7 @@
};
credDefResponse = await this.commonService
.httpPost(url, credDefPayload, { headers: { authorization: getApiKey } })
.then(async (credDef) => credDef);

Check warning on line 1309 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63r&open=AaD3LGp-R_0OgvMtI63r&pullRequest=1769
}

return credDefResponse;
Expand All @@ -1310,7 +1328,7 @@
)}`;
credDefResponse = await this.commonService
.httpGet(url, { headers: { authorization: getApiKey } })
.then(async (credDef) => credDef);

Check warning on line 1331 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63s&open=AaD3LGp-R_0OgvMtI63s&pullRequest=1769
} else if (OrgAgentType.SHARED === payload.agentType) {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_CRED_DEF_BY_ID}`.replace(
'#',
Expand All @@ -1318,7 +1336,7 @@
);
credDefResponse = await this.commonService
.httpGet(url, { headers: { authorization: getApiKey } })
.then(async (credDef) => credDef);

Check warning on line 1339 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63t&open=AaD3LGp-R_0OgvMtI63t&pullRequest=1769
}
return credDefResponse;
} catch (error) {
Expand Down Expand Up @@ -1350,7 +1368,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpPost(url, issueData, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1371 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63v&open=AaD3LGp-R_0OgvMtI63v&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in sendCredentialCreateOffer in agent service : ${JSON.stringify(error)}`);
Expand All @@ -1375,7 +1393,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpPost(url, issueData, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1396 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63x&open=AaD3LGp-R_0OgvMtI63x&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in oidcIssuerCreate in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -1429,7 +1447,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpPost(url, credentialPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1450 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI630&open=AaD3LGp-R_0OgvMtI630&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in oidcCreateCredentialOffer in agent service : ${JSON.stringify(error)}`);
Expand All @@ -1442,7 +1460,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpPut(url, issuanceMetadata, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1463 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI631&open=AaD3LGp-R_0OgvMtI631&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in _oidcUpdateCredentialOffer in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -1481,7 +1499,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpDelete(`${url}`, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1502 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI634&open=AaD3LGp-R_0OgvMtI634&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in _oidcDeleteCredentialOffer in agent service : ${JSON.stringify(error)}`);
Expand All @@ -1494,7 +1512,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpPost(`${url}`, {}, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1515 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI635&open=AaD3LGp-R_0OgvMtI635&pullRequest=1769
return data;
} catch (error) {
const errorMsg = error.response ? JSON.stringify(error.response.data) : error.message;
Expand All @@ -1508,7 +1526,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpPut(url, templatePayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1529 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI636&open=AaD3LGp-R_0OgvMtI636&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in oidcIssuerTemplate in agent service : ${JSON.stringify(error)}`);
Expand All @@ -1520,7 +1538,7 @@
try {
const data = await this.commonService
.httpGet(url, { headers: { authorization: apiKey } })
.then(async (response) => response);

Check warning on line 1541 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI637&open=AaD3LGp-R_0OgvMtI637&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in getIssueCredentials in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -1587,7 +1605,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const data = await this.commonService
.httpGet(url, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1608 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI63_&open=AaD3LGp-R_0OgvMtI63_&pullRequest=1769
return data;
} catch (error) {
this.logger.error(`Error in getConnections in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -1638,7 +1656,7 @@
.httpGet(`${orgAgentDetails.agentEndPoint}${CommonConstants.URL_AGENT_STATUS}`, {
headers: { authorization: agentApiKey }
})
.then(async (response) => response);

Check warning on line 1659 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64A&open=AaD3LGp-R_0OgvMtI64A&pullRequest=1769

return agentHealthData;
} catch (error) {
Expand Down Expand Up @@ -1698,7 +1716,7 @@
headers: { authorization: agentApiKey }
}
)
.then(async (response) => response);

Check warning on line 1719 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64B&open=AaD3LGp-R_0OgvMtI64B&pullRequest=1769

return signedDataFromAgent;
} catch (error) {
Expand Down Expand Up @@ -1741,7 +1759,7 @@
.httpPost(`${url}`, data, {
headers: { authorization: agentApiKey }
})
.then(async (response) => response);

Check warning on line 1762 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64C&open=AaD3LGp-R_0OgvMtI64C&pullRequest=1769

return signedDataFromAgent;
} catch (error) {
Expand Down Expand Up @@ -1769,7 +1787,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const sendProofRequest = await this.commonService
.httpPost(url, proofRequestPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1790 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64D&open=AaD3LGp-R_0OgvMtI64D&pullRequest=1769
return sendProofRequest;
} catch (error) {
this.logger.error(`Error in send out of band proof request in agent service : ${JSON.stringify(error)}`);
Expand All @@ -1792,7 +1810,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const schemaRequest = await this.commonService
.httpPost(url, requestSchemaPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1813 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64E&open=AaD3LGp-R_0OgvMtI64E&pullRequest=1769
return schemaRequest;
} catch (error) {
this.logger.error(`Error in schema endorsement request in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -1820,7 +1838,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const signEndorsementTransaction = await this.commonService
.httpPost(url, signEndorsementPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1841 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64G&open=AaD3LGp-R_0OgvMtI64G&pullRequest=1769

return signEndorsementTransaction;
} catch (error) {
Expand All @@ -1834,7 +1852,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const signEndorsementTransaction = await this.commonService
.httpPost(url, submitEndorsementPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1855 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64H&open=AaD3LGp-R_0OgvMtI64H&pullRequest=1769

return signEndorsementTransaction;
} catch (error) {
Expand All @@ -1852,7 +1870,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const sendOutOfbandCredentialOffer = await this.commonService
.httpPost(url, outOfBandIssuancePayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 1873 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64I&open=AaD3LGp-R_0OgvMtI64I&pullRequest=1769
return sendOutOfbandCredentialOffer;
} catch (error) {
this.logger.error(`Error in out-of-band credential in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -1983,7 +2001,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const receiveInvitationUrlRes = await this.commonService
.httpPost(url, receiveInvitationUrl, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2004 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64K&open=AaD3LGp-R_0OgvMtI64K&pullRequest=1769
return receiveInvitationUrlRes;
} catch (error) {
this.logger.error(`Error in receive invitation in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -2072,7 +2090,7 @@
}
}

async handleAgentSpinupStatusErrors(error: string): Promise<object> {

Check warning on line 2093 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'handleAgentSpinupStatusErrors' has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64M&open=AaD3LGp-R_0OgvMtI64M&pullRequest=1769
if (error && Object.keys(error).length === 0) {
throw new InternalServerErrorException(ResponseMessages.agent.error.agentDown, {
cause: new Error(),
Expand All @@ -2088,7 +2106,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const sendQuestionRes = await this.commonService
.httpPost(url, questionPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2109 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64N&open=AaD3LGp-R_0OgvMtI64N&pullRequest=1769
return sendQuestionRes;
} catch (error) {
this.logger.error(`Error in send question in agent service : ${JSON.stringify(error)}`);
Expand All @@ -2101,7 +2119,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const basicMessageRes = await this.commonService
.httpPost(url, messagePayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2122 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64O&open=AaD3LGp-R_0OgvMtI64O&pullRequest=1769
return basicMessageRes;
} catch (error) {
this.logger.error(`Error in sendBasicMessage in agent service : ${JSON.stringify(error)}`);
Expand All @@ -2124,7 +2142,7 @@

const data = await this.commonService
.httpGet(url, { headers: { authorization: getApiKey } })
.then(async (response) => response)

Check warning on line 2145 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64P&open=AaD3LGp-R_0OgvMtI64P&pullRequest=1769
.catch((error) => this.handleAgentSpinupStatusErrors(error));

return data;
Expand All @@ -2135,7 +2153,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const schemaRequest = await this.commonService
.httpPost(url, schemaRequestPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2156 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64Q&open=AaD3LGp-R_0OgvMtI64Q&pullRequest=1769
return schemaRequest;
} catch (error) {
this.logger.error(`Error in createW3CSchema request in agent service : ${JSON.stringify(error)}`);
Expand All @@ -2152,7 +2170,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const createConnectionInvitation = await this.commonService
.httpPost(url, connectionPayload, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2173 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64R&open=AaD3LGp-R_0OgvMtI64R&pullRequest=1769
return createConnectionInvitation;
} catch (error) {
this.logger.error(`Error in create connection invitation in agent service : ${JSON.stringify(error)}`);
Expand All @@ -2160,7 +2178,7 @@
}
}

private async tokenEncryption(token: string): Promise<string> {

Check warning on line 2181 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async method 'tokenEncryption' has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64S&open=AaD3LGp-R_0OgvMtI64S&pullRequest=1769
try {
const secret = process.env.CRYPTO_PRIVATE_KEY;
if (!secret) {
Expand All @@ -2182,7 +2200,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const x509Certificate = await this.commonService
.httpPost(url, options, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2203 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64T&open=AaD3LGp-R_0OgvMtI64T&pullRequest=1769
return x509Certificate;
} catch (error) {
this.logger.error(`Error in creating x509 certificate in agent service : ${JSON.stringify(error)}`);
Expand All @@ -2197,7 +2215,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const x509Certificate = await this.commonService
.httpPost(url, options, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2218 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64U&open=AaD3LGp-R_0OgvMtI64U&pullRequest=1769
return x509Certificate;
} catch (error) {
this.logger.error(`Error in decoding x509 certificate in agent service : ${JSON.stringify(error)}`);
Expand All @@ -2212,7 +2230,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const x509Certificate = await this.commonService
.httpPost(url, options, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2233 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64V&open=AaD3LGp-R_0OgvMtI64V&pullRequest=1769
return x509Certificate;
} catch (error) {
this.logger.error(`Error in creating x509 certificate in agent service : ${JSON.stringify(error)}`);
Expand Down Expand Up @@ -2256,7 +2274,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const updateVerifier = await this.commonService
.httpPut(url, verifierDetails, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2277 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64X&open=AaD3LGp-R_0OgvMtI64X&pullRequest=1769
return updateVerifier;
} catch (error) {
this.logger.error(
Expand Down Expand Up @@ -2290,7 +2308,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const createSession = await this.commonService
.httpPost(url, sessionRequest, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2311 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64Z&open=AaD3LGp-R_0OgvMtI64Z&pullRequest=1769
return createSession;
} catch (error) {
this.logger.error(
Expand All @@ -2312,7 +2330,7 @@
const getApiKey = await this.getOrgAgentApiKey(orgId);
const verifySession = await this.commonService
.httpPost(url, verifyAuthorizationResponse, { headers: { authorization: getApiKey } })
.then(async (response) => response);

Check warning on line 2333 in apps/agent-service/src/agent-service.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Async arrow function has no 'await' expression.

See more on https://sonarcloud.io/project/issues?id=credebl_platform&issues=AaD3LGp-R_0OgvMtI64a&open=AaD3LGp-R_0OgvMtI64a&pullRequest=1769
return verifySession;
} catch (error) {
this.logger.error(
Expand Down