import USER_ROLE from '../enum/userRole'; import WORKFLOW_STAGE from '../enum/workflowStage'; import { getNodeProfile } from '../env/nodeProfile'; import { API } from './API'; import { retryWithCondition } from './common'; import { checkForIdentitySwitching } from './generateDC/multiIdentityUtil'; import { HTTP_METHOD } from './httpMethod'; import { makeAuthenticatedRequest } from './loginUtil'; import scenarioContext from './scenarioContext'; function checkValidTransactionId(response: { id: string }) { if (response.id == null) { return false; } const draftIdMatcher = /[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}/g; return !response.id.match(draftIdMatcher); } export async function executeDraftAndMapNewId(node: string, responseId: string) { logger.debug(`switch to correct identity to call execute API..`); await checkForIdentitySwitching(scenarioContext().currentParty, node, getNodeProfile(node), USER_ROLE.ADMIN1); logger.debug(`executeDraftAndMapNewId party: ${node} responseId: ${responseId}`); await makeAuthenticatedRequest(node, USER_ROLE.ADMIN1, API.EXECUTE + responseId, HTTP_METHOD.POST, null); const responseJson = await retryWithCondition( 30, makeAuthenticatedRequest, [node, USER_ROLE.ADMIN1, 'draft/execute/' + responseId + '/status', HTTP_METHOD.GET, null], checkValidTransactionId ); const locAppRef = responseJson.workflowStage == WORKFLOW_STAGE.locapp || responseJson.workflowStage == WORKFLOW_STAGE.locdraft ? (await responseJson.id) + '(0)' : (await responseJson.id) + '(1)'; const dcObjectJson = await makeAuthenticatedRequest( node, USER_ROLE.ADMIN1, 'locapp/ref/' + locAppRef, HTTP_METHOD.GET, null ); if (dcObjectJson.ref == locAppRef) { scenarioContext().dc.appRefId = locAppRef; scenarioContext().dc.uuid = dcObjectJson._data.linearId.id; } logger.info('scenarioContext().dc.uuid = ' + scenarioContext().dc.uuid); logger.info('scenarioContext().dc.appRefId = ' + scenarioContext().dc.appRefId); }