import { IHandlerParameters , ImperativeError } from "@zowe/imperative" ; import { StartWorkflow , ListWorkflows } from "@zowe/zos-workflows-for-zowe-sdk" ; import { ZosmfBaseHandler } from "@zowe/zosmf-for-zowe-sdk" ; /**
 * Common handler to start a workflow instance in z/OSMF.
 * This is not something that is intended to be used outside of this npm package.
 */ export default class WorkflowStepHandler extends ZosmfBaseHandler { private type { * } memberof private arguments : any ; param { IHandlerParameters } params returns { Promise < void > } memberof public async processCmd ( params ) { let error ; let getWfKey ; this . arguments = params . arguments ; let sourceType ; if ( this . arguments . workflowKey ) { sourceType = "workflowKey" ; } else if ( this . arguments . workflowName ) { sourceType = "workflowName" ; } switch ( sourceType ) { case "workflowKey" : try { await StartWorkflow . startWorkflow ( this . mSession , this . arguments . workflowKey , this . arguments . resolveConflict , this . arguments . stepName , this . arguments . performFollowingSteps ) ; } catch ( err ) { error = "Start workflow: " + err ; throw error ; } params . response . data . setObj ( "Started." ) ; params . response . console . log ( "Workflow step started." ) ; break ; case "workflowName" : try { getWfKey = await ListWorkflows . getWfKey ( this . mSession , this . arguments . workflowName , undefined ) ; if ( getWfKey === null ) { throw new ImperativeError ( { msg : `No workflows match the provided workflow name.` , additionalDetails : JSON . stringify ( params ) } ) ; } await StartWorkflow . startWorkflow ( this . mSession , getWfKey , this . arguments . resolveConflict , this . arguments . stepName , this . arguments . performFollowingSteps ) ; } catch ( err ) { error = "Start workflow: " + err ; throw error ; } params . response . data . setObj ( "Started." ) ; params . response . console . log ( "Workflow step started." ) ; break ; default : throw new ImperativeError ( { msg : `Internal create error: Unable to determine the the criteria by which to run start workflow action. ` + `Please contact support.` , additionalDetails : JSON . stringify ( params ) } ) ; } } }