file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license import { JsonMap } from '@salesforce/ts-types' ; import { SfdxFalconResult } from '../../../../sfdx-falcon-result' ; import { SfdxFalconResultOptions } from '../../../../sfdx-falcon-result' ; import { SfdxFalconResultType } from '../../../../sfdx-falcon-result' ; import { configureUser } from '../../../executors/hybrid' ; import { AppxEngineActionContext } from '../../appx' ; import { AppxEngineAction } from '../../appx/actions' ; import { CoreActionResultDetail } from '../../appx/actions' ; import { ActionOptions } from '../../../types/' ; import { ExecutorMessages } from '../../../types/' ; import { SfdxFalconActionType } from '../../../types/' ; import { readConfigFile } from '../../../../sfdx-falcon-util' ; import { getUsernameFromAlias } from '../../../../sfdx-falcon-util/sfdx' ; const dbgNs = 'ACTION:configure-admin-user:' ; interface extends CoreActionResultDetail description interface ActionResultDetail extends CoreActionResultDetail { userDefinition : JsonMap ; adminUsername : string ; } class extends AppxEngineAction description public export class ConfigureAdminUserAction extends AppxEngineAction { method returns { void } description protected protected initializeAction ( ) { this . actionType = SfdxFalconActionType . SFDC_API ; this . actionName = 'configure-admin-user' ; this . description = 'Configure Admin User' ; this . successDelay = 2 ; this . errorDelay = 2 ; this . progressDelay = 1000 ; } method param { ActionOptions } actionOptions returns { void } description protected protected validateActionOptions ( actionOptions ) { if ( typeof actionOptions . definitionFile === 'undefined' ) { throw new Error ( `ERROR_MISSING_OPTION: 'definitionFile'` ) ; } } method param { ActionOptions } actionOptions returns { Promise < SfdxFalconResult > } description protected async protected async executeAction ( actionContext , actionOptions = { } ) { const actionResult = this . createActionResult ( actionContext , actionOptions , { startNow : true , bubbleError : true , bubbleFailure : true , failureIsError : true } as SfdxFalconResultOptions ) ; actionResult . detail = { ... actionResult . detail , ... { executorMessages : null , userDefinition : null , adminUsername : null } } as ActionResultDetail ; actionResult . debugResult ( `Initialized` , `${ dbgNs }executeAction:` ) ; const actionResultDetail = actionResult . detail as ActionResultDetail ; const userDefinition = await readConfigFile ( actionContext . projectContext . configPath , actionOptions . definitionFile as string ) . catch ( rejectedPromise => { actionResult . addRejectedChild ( rejectedPromise , SfdxFalconResultType . UTILITY , `general:readConfigFile` ) ; } ) ; actionResultDetail . userDefinition = userDefinition as JsonMap ; actionResult . debugResult ( `User Definition File Read` , `${ dbgNs }executeAction:` ) ; const adminUsername = await getUsernameFromAlias ( actionContext . targetOrg . alias ) . catch ( error => { actionResult . throw ( error ) ; } ) as string ; actionResultDetail . adminUsername = adminUsername ; actionResult . debugResult ( `Determined Admin Username from Alias` , `${ dbgNs }executeAction:` ) ; const executorMessages = { progressMsg : `Configuring user '${ adminUsername }' in ${ actionContext . targetOrg . alias }` , errorMsg : `Failed to configure user '${ adminUsername }' in ${ actionContext . targetOrg . alias }` , successMsg : `User '${ adminUsername }' configured successfully` } as ExecutorMessages ; actionResultDetail . executorMessages = executorMessages ; actionResult . debugResult ( `Executor Messages Set` , `${ dbgNs }executeAction:` ) ; return await configureUser ( adminUsername , userDefinition as JsonMap , actionContext . targetOrg , executorMessages , actionContext . listrExecOptions . observer ) . catch ( rejectedPromise => actionResult . addRejectedChild ( rejectedPromise , SfdxFalconResultType . EXECUTOR , `hybrid:configureUser` ) ) . then ( resolvedPromise => { if ( resolvedPromise === actionResult ) { return actionResult ; } return actionResult . addResolvedChild ( resolvedPromise , SfdxFalconResultType . EXECUTOR , `hybrid:configureUser` ) ; } ) ; } }