Skip to content

Commit 255236a

Browse files
authored
refactor: changes agent endpoint (#1378)
Signed-off-by: Tipu_Singh <[email protected]>
1 parent 855603d commit 255236a

File tree

7 files changed

+62
-243
lines changed

7 files changed

+62
-243
lines changed

apps/agent-service/src/agent-service.service.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,7 @@ export class AgentServiceService {
930930
}
931931

932932
const getApiKey = await this.getOrgAgentApiKey(orgId);
933-
const getOrgAgentType = await this.agentServiceRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
934-
935-
const url = this.constructUrl(agentDetails, getOrgAgentType);
933+
const url = this.constructUrl(agentDetails);
936934

937935
if (createDidPayload.method === DidMethod.POLYGON) {
938936
createDidPayload.endpoint = agentDetails.agentEndPoint;
@@ -977,12 +975,8 @@ export class AgentServiceService {
977975
}
978976
}
979977

980-
private constructUrl(agentDetails, getOrgAgentType): string {
981-
if (getOrgAgentType.agent === OrgAgentType.DEDICATED) {
982-
return `${agentDetails.agentEndPoint}${CommonConstants.URL_AGENT_WRITE_DID}`;
983-
} else if (getOrgAgentType.agent === OrgAgentType.SHARED) {
984-
return `${agentDetails.agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_DID}${agentDetails.tenantId}`;
985-
}
978+
private constructUrl(agentDetails): string {
979+
return `${agentDetails.agentEndPoint}${CommonConstants.URL_AGENT_WRITE_DID}`;
986980
}
987981

988982
private async getDidDetails(url, payload, apiKey): Promise<object> {
@@ -1053,14 +1047,16 @@ export class AgentServiceService {
10531047
*/
10541048
async createSecp256k1KeyPair(orgId: string): Promise<object> {
10551049
try {
1056-
const platformAdminSpinnedUp = await this.agentServiceRepository.platformAdminAgent(
1057-
CommonConstants.PLATFORM_ADMIN_ORG
1058-
);
1059-
1060-
const getPlatformAgentEndPoint = platformAdminSpinnedUp.org_agents[0].agentEndPoint;
1061-
const getDcryptedToken = await this.commonService.decryptPassword(platformAdminSpinnedUp?.org_agents[0].apiKey);
1050+
const orgAgentDetails = await this.agentServiceRepository.getAgentApiKey(orgId);
1051+
if (!orgAgentDetails) {
1052+
throw new NotFoundException(ResponseMessages.agent.error.orgAgentNotFound, {
1053+
cause: new Error(),
1054+
description: ResponseMessages.errorMessages.notFound
1055+
});
1056+
}
1057+
const getDcryptedToken = await this.commonService.decryptPassword(orgAgentDetails.apiKey);
10621058

1063-
const url = `${getPlatformAgentEndPoint}${CommonConstants.CREATE_POLYGON_SECP256k1_KEY}`;
1059+
const url = `${orgAgentDetails.agentEndPoint}${CommonConstants.CREATE_POLYGON_SECP256k1_KEY}`;
10641060

10651061
const createKeyPairResponse = await this.commonService.httpPost(
10661062
url,
@@ -1226,7 +1222,7 @@ export class AgentServiceService {
12261222
});
12271223
});
12281224
} else if (OrgAgentType.SHARED === payload.agentType) {
1229-
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_SCHEMA}`.replace(
1225+
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_CREATE_SCHEMA}`.replace(
12301226
'#',
12311227
`${payload.tenantId}`
12321228
);
@@ -1267,9 +1263,10 @@ export class AgentServiceService {
12671263
.httpGet(url, { headers: { authorization: getApiKey } })
12681264
.then(async (schema) => schema);
12691265
} else if (OrgAgentType.SHARED === payload.agentType) {
1270-
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_GET_SCHEMA}`
1271-
.replace('@', `${payload.payload.schemaId}`)
1272-
.replace('#', `${payload.tenantId}`);
1266+
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID}`.replace(
1267+
'#',
1268+
`${payload.tenantId}`
1269+
);
12731270

12741271
schemaResponse = await this.commonService
12751272
.httpGet(url, { headers: { authorization: getApiKey } })
@@ -1299,10 +1296,7 @@ export class AgentServiceService {
12991296
.httpPost(url, credDefPayload, { headers: { authorization: getApiKey } })
13001297
.then(async (credDef) => credDef);
13011298
} else if (OrgAgentType.SHARED === payload.agentType) {
1302-
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_CRED_DEF}`.replace(
1303-
'#',
1304-
`${payload.tenantId}`
1305-
);
1299+
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_CREATE_CRED_DEF}`;
13061300
const credDefPayload = {
13071301
tag: payload.payload.tag,
13081302
schemaId: payload.payload.schemaId,
@@ -1334,9 +1328,10 @@ export class AgentServiceService {
13341328
.httpGet(url, { headers: { authorization: getApiKey } })
13351329
.then(async (credDef) => credDef);
13361330
} else if (OrgAgentType.SHARED === payload.agentType) {
1337-
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_GET_CRED_DEF}`
1338-
.replace('@', `${payload.payload.credentialDefinitionId}`)
1339-
.replace('#', `${payload.tenantId}`);
1331+
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_CRED_DEF_BY_ID}`.replace(
1332+
'#',
1333+
`${payload.payload.credentialDefinitionId}`
1334+
);
13401335
credDefResponse = await this.commonService
13411336
.httpGet(url, { headers: { authorization: getApiKey } })
13421337
.then(async (credDef) => credDef);

apps/connection/src/connection.service.ts

Lines changed: 8 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { ConnectionRepository } from './connection.repository';
1919
import { ResponseMessages } from '@credebl/common/response-messages';
2020
import { IUserRequest } from '@credebl/user-request/user-request.interface';
21-
import { OrgAgentType, ConnectionProcessState } from '@credebl/enum/enum';
21+
import { ConnectionProcessState } from '@credebl/enum/enum';
2222
import { Cache } from 'cache-manager';
2323
import { CACHE_MANAGER } from '@nestjs/cache-manager';
2424
import {
@@ -188,23 +188,13 @@ export class ConnectionService {
188188
try {
189189
const { alias, myDid, outOfBandId, state, theirDid, theirLabel } = connectionSearchCriteria;
190190
const agentDetails = await this.connectionRepository.getAgentEndPoint(orgId);
191-
const orgAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
192191
const { agentEndPoint } = agentDetails;
193192
if (!agentDetails) {
194193
throw new NotFoundException(ResponseMessages.issuance.error.agentEndPointNotFound);
195194
}
196195

197196
let url: string;
198-
if (orgAgentType === OrgAgentType.DEDICATED) {
199-
url = `${agentEndPoint}${CommonConstants.URL_CONN_GET_CONNECTIONS}`;
200-
} else if (orgAgentType === OrgAgentType.SHARED) {
201-
url = `${agentEndPoint}${CommonConstants.URL_SHAGENT_GET_CREATEED_INVITATIONS}`.replace(
202-
'#',
203-
agentDetails.tenantId
204-
);
205-
} else {
206-
throw new NotFoundException(ResponseMessages.connection.error.agentUrlNotFound);
207-
}
197+
url = `${agentEndPoint}${CommonConstants.URL_CONN_GET_CONNECTIONS}`;
208198

209199
//Create the dynamic URL for Search Criteria
210200
const criteriaParams = [];
@@ -263,24 +253,11 @@ export class ConnectionService {
263253
async getConnectionsById(user: IUserRequest, connectionId: string, orgId: string): Promise<IConnectionDetailsById> {
264254
try {
265255
const agentDetails = await this.connectionRepository.getAgentEndPoint(orgId);
266-
const orgAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
267-
268256
const { agentEndPoint } = agentDetails;
269257
if (!agentDetails) {
270258
throw new NotFoundException(ResponseMessages.issuance.error.agentEndPointNotFound);
271259
}
272-
273-
let url;
274-
if (orgAgentType === OrgAgentType.DEDICATED) {
275-
url = `${agentEndPoint}${CommonConstants.URL_CONN_GET_CONNECTION_BY_ID}`.replace('#', connectionId);
276-
} else if (orgAgentType === OrgAgentType.SHARED) {
277-
url = `${agentEndPoint}${CommonConstants.URL_SHAGENT_GET_CREATEED_INVITATION_BY_CONNECTIONID}`
278-
.replace('#', connectionId)
279-
.replace('@', agentDetails.tenantId);
280-
} else {
281-
throw new NotFoundException(ResponseMessages.connection.error.agentUrlNotFound);
282-
}
283-
260+
const url = `${agentEndPoint}${CommonConstants.URL_CONN_GET_CONNECTION_BY_ID}`.replace('#', connectionId);
284261
const createConnectionInvitation = await this._getConnectionsByConnectionId(url, orgId);
285262
return createConnectionInvitation?.response;
286263
} catch (error) {
@@ -301,14 +278,11 @@ export class ConnectionService {
301278
async getQuestionAnswersRecord(orgId: string): Promise<object> {
302279
try {
303280
const agentDetails = await this.connectionRepository.getAgentEndPoint(orgId);
304-
const orgAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
305281
const { agentEndPoint } = agentDetails;
306282
if (!agentDetails) {
307283
throw new NotFoundException(ResponseMessages.issuance.error.agentEndPointNotFound);
308284
}
309-
310-
const label = 'get-question-answer-record';
311-
const url = await this.getQuestionAnswerAgentUrl(label, orgAgentType, agentEndPoint, agentDetails?.tenantId);
285+
const url = await getAgentUrl(agentEndPoint, CommonConstants.GET_QUESTION_ANSWER_RECORD);
312286

313287
const record = await this._getQuestionAnswersRecord(url, orgId);
314288
return record;
@@ -336,54 +310,6 @@ export class ConnectionService {
336310
return this.natsCall(pattern, payload);
337311
}
338312

339-
async getQuestionAnswerAgentUrl(
340-
label: string,
341-
orgAgentType: string,
342-
agentEndPoint: string,
343-
tenantId?: string,
344-
connectionId?: string
345-
): Promise<string> {
346-
try {
347-
let url;
348-
switch (label) {
349-
case 'send-question': {
350-
url =
351-
orgAgentType === OrgAgentType.DEDICATED
352-
? `${agentEndPoint}${CommonConstants.URL_SEND_QUESTION}`.replace('#', connectionId)
353-
: orgAgentType === OrgAgentType.SHARED
354-
? `${agentEndPoint}${CommonConstants.URL_SHAGENT_SEND_QUESTION}`
355-
.replace('#', connectionId)
356-
.replace('@', tenantId)
357-
: null;
358-
break;
359-
}
360-
361-
case 'get-question-answer-record': {
362-
url =
363-
orgAgentType === OrgAgentType.DEDICATED
364-
? `${agentEndPoint}${CommonConstants.URL_QUESTION_ANSWER_RECORD}`
365-
: orgAgentType === OrgAgentType.SHARED
366-
? `${agentEndPoint}${CommonConstants.URL_SHAGENT_QUESTION_ANSWER_RECORD}`.replace('#', tenantId)
367-
: null;
368-
break;
369-
}
370-
371-
default: {
372-
break;
373-
}
374-
}
375-
376-
if (!url) {
377-
throw new NotFoundException(ResponseMessages.issuance.error.agentUrlNotFound);
378-
}
379-
380-
return url;
381-
} catch (error) {
382-
this.logger.error(`Error get question answer agent Url: ${JSON.stringify(error)}`);
383-
throw error;
384-
}
385-
}
386-
387313
async _getOrgAgentApiKey(orgId: string): Promise<{
388314
response: string;
389315
}> {
@@ -411,25 +337,11 @@ export class ConnectionService {
411337
): Promise<IReceiveInvitationResponse> {
412338
try {
413339
const agentDetails = await this.connectionRepository.getAgentEndPoint(orgId);
414-
const orgAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
415-
416340
const { agentEndPoint } = agentDetails;
417341
if (!agentDetails) {
418342
throw new NotFoundException(ResponseMessages.issuance.error.agentEndPointNotFound);
419343
}
420-
421-
let url;
422-
if (orgAgentType === OrgAgentType.DEDICATED) {
423-
url = `${agentEndPoint}${CommonConstants.URL_RECEIVE_INVITATION_URL}`;
424-
} else if (orgAgentType === OrgAgentType.SHARED) {
425-
url = `${agentEndPoint}${CommonConstants.URL_SHAGENT_RECEIVE_INVITATION_URL}`.replace(
426-
'#',
427-
agentDetails.tenantId
428-
);
429-
} else {
430-
throw new NotFoundException(ResponseMessages.connection.error.agentUrlNotFound);
431-
}
432-
344+
const url = `${agentEndPoint}${CommonConstants.URL_RECEIVE_INVITATION_URL}`;
433345
const createConnectionInvitation = await this._receiveInvitationUrl(url, orgId, receiveInvitationUrl);
434346
return createConnectionInvitation.response;
435347
} catch (error) {
@@ -485,22 +397,11 @@ export class ConnectionService {
485397
): Promise<IReceiveInvitationResponse> {
486398
try {
487399
const agentDetails = await this.connectionRepository.getAgentEndPoint(orgId);
488-
const orgAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
489-
490400
const { agentEndPoint } = agentDetails;
491401
if (!agentDetails) {
492402
throw new NotFoundException(ResponseMessages.issuance.error.agentEndPointNotFound);
493403
}
494-
495-
let url;
496-
if (orgAgentType === OrgAgentType.DEDICATED) {
497-
url = `${agentEndPoint}${CommonConstants.URL_RECEIVE_INVITATION}`;
498-
} else if (orgAgentType === OrgAgentType.SHARED) {
499-
url = `${agentEndPoint}${CommonConstants.URL_SHAGENT_RECEIVE_INVITATION}`.replace('#', agentDetails.tenantId);
500-
} else {
501-
throw new NotFoundException(ResponseMessages.connection.error.agentUrlNotFound);
502-
}
503-
404+
const url = `${agentEndPoint}${CommonConstants.URL_RECEIVE_INVITATION}`;
504405
const createConnectionInvitation = await this._receiveInvitation(url, orgId, receiveInvitation);
505406
return createConnectionInvitation?.response;
506407
} catch (error) {
@@ -553,15 +454,7 @@ export class ConnectionService {
553454
question
554455
};
555456

556-
const orgAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
557-
const label = 'send-question';
558-
const url = await this.getQuestionAnswerAgentUrl(
559-
label,
560-
orgAgentType,
561-
agentEndPoint,
562-
agentDetails?.tenantId,
563-
connectionId
564-
);
457+
const url = await getAgentUrl(agentEndPoint, CommonConstants.SEND_QUESTION, connectionId);
565458

566459
const createQuestion = await this._sendQuestion(questionPayload, url, orgId);
567460
return createQuestion;
@@ -833,16 +726,7 @@ export class ConnectionService {
833726
const questionPayload = {
834727
content
835728
};
836-
837-
const organizationAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId);
838-
const label = 'send-basic-message';
839-
const agentUrl = await this.commonService.sendBasicMessageAgentUrl(
840-
label,
841-
organizationAgentType,
842-
agentEndPoint,
843-
agentDetails?.tenantId,
844-
connectionId
845-
);
729+
const agentUrl = await getAgentUrl(agentEndPoint, CommonConstants.SEND_BASIC_MESSAGE, connectionId);
846730

847731
const sendBasicMessage = await this._sendBasicMessageToAgent(questionPayload, agentUrl, orgId);
848732
return sendBasicMessage;

apps/verification/src/verification.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ export class VerificationService {
762762
let credDefId;
763763
let schemaId;
764764
let certificate;
765-
const url = await getAgentUrl(getAgentDetails?.agentEndPoint, CommonConstants.GET_VERIFIED_PROOF);
765+
const url = await getAgentUrl(getAgentDetails?.agentEndPoint, CommonConstants.GET_VERIFIED_PROOF, proofId);
766766

767767
const payload = { orgId, url };
768768

0 commit comments

Comments
 (0)