file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license import { Aliases } from '@salesforce/core' ; import { AuthInfo } from '@salesforce/core' ; import { Connection } from '@salesforce/core' ; import { AnyJson } from '@salesforce/ts-types' ; import { SfdxFalconDebug } from '../sfdx-falcon-debug' ; import { SfdxFalconError } from '../sfdx-falcon-error' ; import { SfdxCliError } from '../sfdx-falcon-error' ; import { ShellError } from '../sfdx-falcon-error' ; import { SfdxFalconResult } from '../sfdx-falcon-result' ; import { SfdxFalconResultType } from '../sfdx-falcon-result' ; import { safeParse } from '../sfdx-falcon-util' ; import { waitASecond } from '../sfdx-falcon-util/async' ; import { describeSignupRequest } from '../sfdx-falcon-util/jsforce' ; import { getPackages } from '../sfdx-falcon-util/jsforce' ; import { AliasOrConnection } from '../sfdx-falcon-types' ; import { MetadataPackage } from '../sfdx-falcon-types' ; import { MetadataPackageVersion } from '../sfdx-falcon-types' ; import { PackageVersionMap } from '../sfdx-falcon-types' ; import { QueryResult } from '../sfdx-falcon-types' ; import { RawSfdxOrgInfo } from '../sfdx-falcon-types' ; import { ResolvedConnection } from '../sfdx-falcon-types' ; import { SfdxOrgInfoMap } from '../sfdx-falcon-types' ; import { SfdxOrgInfoSetup } from '../sfdx-falcon-types' ; const shell = require ( 'shelljs' ) ; const dbgNs = 'UTILITY:sfdx:' ; /**
 * Interface. Represents the expected possible input and output of a generic Salesforce CLI call.
 */ export interface SfdxUtilityResultDetail { sfdxCommandString : string ; stdOutParsed : AnyJson ; stdOutBuffer : string ; stdErrBuffer : string ; error : Error ; } class summary description public export class SfdxOrgInfo { public readonly alias : string ; public readonly username : string ; public readonly orgId : string ; public readonly connectedStatus : string ; private _isDevHub : boolean ; private _isPkgOrg : boolean ; private _isEnvHub : boolean ; private _nsPrefix : string ; private _packages : MetadataPackage [ ] ; private _pkgVersionMap : PackageVersionMap ; private _metadataPackageResults : QueryResult < MetadataPackage > ; public get isDevHub ( ) : boolean { return this . _isDevHub ? true : false ; } public get isEnvHub ( ) : boolean { return this . _isEnvHub ? true : false ; } public get isPkgOrg ( ) : boolean { return this . _isPkgOrg ? true : false ; } public get latestManagedBetaPkgVersion ( ) : MetadataPackageVersion { return this . getLatestPackageVersion ( this . managedPkgId , 'Beta' ) ; } public get latestManagedReleasedPkgVersion ( ) : MetadataPackageVersion { return this . getLatestPackageVersion ( this . managedPkgId , 'Released' ) ; } public get managedPkgId ( ) : string { for ( const packageObj of this . _packages ) { if ( packageObj . NamespacePrefix ) { return packageObj . Id ; } } return '' ; } public get managedPkgName ( ) : string { for ( const packageObj of this . _packages ) { if ( packageObj . NamespacePrefix ) { return packageObj . Name ; } } return '' ; } public get nsPrefix ( ) : string { return this . _nsPrefix || '' ; } public get packages ( ) : MetadataPackage [ ] { return this . _packages ; } constructs param { SfdxOrgInfoSetup } opts description public constructor ( opts ) { this . alias = opts . alias ; this . username = opts . username ; this . orgId = opts . orgId ; this . connectedStatus = opts . connectedStatus ; this . _isDevHub = opts . isDevHub ? true : false ; this . _isPkgOrg = false ; this . _isEnvHub = false ; this . _metadataPackageResults = opts . metadataPackageResults ; this . _packages = this . extractPackages ( this . _metadataPackageResults ) ; this . _pkgVersionMap = this . mapPackageVersions ( this . _packages ) ; this . _isPkgOrg = ( this . _packages . length > 0 ) ; if ( typeof this . alias !== 'string' || this . alias . length < 1 ) { this . alias = this . username ; } } method returns { Promise < boolean } description public async public async determineEnvHubStatus ( ) { const signupRequestDescribe = await describeSignupRequest ( this . alias ) ; SfdxFalconDebug . obj ( `${ dbgNs }determineEnvHubStatus:signupRequestDescribe:` , signupRequestDescribe , `signupRequestDescribe: ` ) ; if ( signupRequestDescribe . createable === true ) { this . _isEnvHub = true ; } else { this . _isEnvHub = false ; } return this . _isEnvHub ; } method returns { Promise < boolean } description public async public async determinePkgOrgStatus ( ) { if ( this . _packages . length > 0 ) { return this . _isPkgOrg = true ; } this . _metadataPackageResults = await getPackages ( this . alias ) ; SfdxFalconDebug . obj ( `${ dbgNs }SfdxOrgInfo:determinePkgOrgStatus:` , this . _metadataPackageResults , `this._metadataPackageResults: ` ) ; this . _packages = this . extractPackages ( this . _metadataPackageResults ) ; SfdxFalconDebug . obj ( `${ dbgNs }SfdxOrgInfo:determinePkgOrgStatus:` , this . _packages , `this._packages: ` ) ; this . _pkgVersionMap = this . mapPackageVersions ( this . _packages ) ; SfdxFalconDebug . obj ( `${ dbgNs }SfdxOrgInfo:determinePkgOrgStatus:` , this . _pkgVersionMap , `this._pkgVersionMap: ` ) ; for ( const packageObj of this . _packages ) { if ( packageObj . NamespacePrefix ) { this . _nsPrefix = packageObj . NamespacePrefix ; break ; } } return this . _isPkgOrg = ( this . _packages . length > 0 ) ; } method param { string } metadataPackageId param { string } releaseState returns { MetadataPackageVersion } description public public getLatestPackageVersion ( metadataPackageId , releaseState = '' ) { const metadataPackageVersions = this . _pkgVersionMap . get ( metadataPackageId ) ; if ( Array . isArray ( metadataPackageVersions ) !== true || metadataPackageVersions . length < 1 ) { return null ; } if ( ! releaseState ) { return metadataPackageVersions . values [ 0 ] ; } for ( const metadataPackageVersion of metadataPackageVersions ) { if ( metadataPackageVersion . ReleaseState === releaseState ) { return metadataPackageVersion ; } } return null ; } method param { QueryResult < MetadataPackage > } metadataPackages returns { MetadataPackage [ ] } description private private extractPackages ( metadataPackages ) { SfdxFalconDebug . obj ( `${ dbgNs }SfdxOrgInfo:extractPackages:arguments:` , arguments , `arguments: ` ) ; if ( typeof metadataPackages === 'undefined' || Array . isArray ( metadataPackages . records ) !== true ) { return [ ] ; } const packages = new Array < MetadataPackage > ( ) ; for ( const metadataPackageRecord of metadataPackages . records ) { const metadataPackage = { Id : metadataPackageRecord . Id , Name : metadataPackageRecord . Name , NamespacePrefix : metadataPackageRecord . NamespacePrefix , MetadataPackageVersions : metadataPackageRecord . MetadataPackageVersions ? metadataPackageRecord . MetadataPackageVersions [ 'records' ] as MetadataPackageVersion [ ] : [ ] as MetadataPackageVersion [ ] } ; packages . push ( metadataPackage ) ; } return packages ; } method param { MetadataPackage [ ] } packageObjs returns { PackageVersionMap } description private private mapPackageVersions ( packageObjs ) { const pkgVersionMap = new Map < string , MetadataPackageVersion [ ] > ( ) ; for ( const packageObj of packageObjs ) { if ( Array . isArray ( packageObj . MetadataPackageVersions ) !== true || packageObj . MetadataPackageVersions . length < 1 ) { pkgVersionMap . set ( packageObj . Id , [ ] as MetadataPackageVersion [ ] ) ; continue ; } packageObj . MetadataPackageVersions . sort ( ( a , b ) => { const aMajorVersion = Number . isNaN ( a . MajorVersion ) ? 0 : Number ( a . MajorVersion ) ; const bMajorVersion = Number . isNaN ( b . MajorVersion ) ? 0 : Number ( b . MajorVersion ) ; const aMinorVersion = Number . isNaN ( a . MinorVersion ) ? 0 : Number ( a . MinorVersion ) ; const bMinorVersion = Number . isNaN ( b . MinorVersion ) ? 0 : Number ( b . MinorVersion ) ; const aPatchVersion = Number . isNaN ( a . PatchVersion ) ? 0 : Number ( a . PatchVersion ) ; const bPatchVersion = Number . isNaN ( b . PatchVersion ) ? 0 : Number ( b . PatchVersion ) ; if ( aMajorVersion < bMajorVersion ) return - 1 ; if ( aMajorVersion > bMajorVersion ) return 1 ; if ( aMinorVersion < bMinorVersion ) return - 1 ; if ( aMinorVersion > bMinorVersion ) return 1 ; if ( aPatchVersion < bPatchVersion ) return - 1 ; if ( aPatchVersion > bPatchVersion ) return 1 ; return 0 ; } ) ; packageObj . MetadataPackageVersions . reverse ( ) ; pkgVersionMap . set ( packageObj . Id , packageObj . MetadataPackageVersions ) ; } return pkgVersionMap ; } } function param { RawSfdxOrgInfo [ ] } rawSfdxOrgList returns { SfdxOrgInfoMap } description public export function buildSfdxOrgInfoMap ( rawSfdxOrgList ) { SfdxFalconDebug . obj ( `${ dbgNs }buildSfdxOrgInfoMap:arguments:` , arguments , `arguments: ` ) ; if ( Array . isArray ( rawSfdxOrgList ) !== true ) { throw new SfdxFalconError ( `Expected rawSfdxOrgList to an Array but got type '${ typeof rawSfdxOrgList }' instead.` , `TypeError` , `${ dbgNs }buildSfdxOrgInfoMap` ) ; } const sfdxOrgInfoMap = new Map < string , SfdxOrgInfo > ( ) ; for ( const rawOrgInfo of rawSfdxOrgList ) { if ( rawOrgInfo . connectedStatus === 'Connected' ) { sfdxOrgInfoMap . set ( rawOrgInfo . username , new SfdxOrgInfo ( { alias : rawOrgInfo . alias , username : rawOrgInfo . username , orgId : rawOrgInfo . orgId , connectedStatus : rawOrgInfo . connectedStatus , isDevHub : rawOrgInfo . isDevHub } ) ) ; } else { SfdxFalconDebug . str ( `${ dbgNs }buildSfdxOrgInfoMap:` , `${ rawOrgInfo . alias }(${ rawOrgInfo . username })` , `ORG NOT CONNECTED!` ) ; } } SfdxFalconDebug . obj ( `${ dbgNs }buildSfdxOrgInfoMap:sfdxOrgInfoMap:` , sfdxOrgInfoMap , `sfdxOrgInfoMap: ` ) ; return sfdxOrgInfoMap ; } function param { unknown } thingToCheck returns { boolean } description public export function detectSalesforceCliError ( thingToCheck ) { SfdxFalconDebug . obj ( `${ dbgNs }detectSalesforceCliError:arguments:` , arguments , `arguments: ` ) ; let possibleCliError ; if ( typeof thingToCheck === 'string' ) { possibleCliError = safeParse ( thingToCheck ) ; } else { possibleCliError = thingToCheck as object ; } SfdxFalconDebug . obj ( `${ dbgNs }detectSalesforceCliError:possibleCliError:` , possibleCliError , `possibleCliError: ` ) ; if ( possibleCliError [ 'status' ] && possibleCliError [ 'status' ] !== 0 ) { return true ; } else { return false ; } } function param { string } sfdxCommandString param { SfdxFalconResult } utilityResult param { object } messages returns { Promise < SfdxFalconResult > } description public async export async function executeSfdxCommand ( sfdxCommandString , utilityResult , messages = { } ) { const utilityResultDetail = utilityResult . detail as SfdxUtilityResultDetail ; const failureMessage = messages [ 'failureMessage' ] || 'Salesforce CLI Command Failed' ; const successMessage = messages [ 'successMessage' ] || 'Salesforce CLI Command Succeeded' ; const mixedMessage = messages [ 'mixedMessage' ] || 'Salesforce CLI Command failed but returned a Success Response' ; return new Promise ( ( resolve , reject ) => { let stdOutBuffer = '' ; let stdErrBuffer = '' ; shell . env [ 'FORCE_COLOR' ] = 0 ; shell . env [ 'SFDX_JSON_TO_STDOUT' ] = 'true' ; shell . env [ 'SFDX_AUTOUPDATE_DISABLE' ] = 'true' ; const childProcess = shell . exec ( sfdxCommandString , { silent : true , async : true } ) ; childProcess . stdout . on ( 'data' , ( stdOutDataStream ) => { stdOutBuffer += stdOutDataStream ; } ) ; childProcess . stderr . on ( 'data' , ( stdErrDataStream ) => { stdErrBuffer += stdErrDataStream ; } ) ; childProcess . on ( 'close' , ( code , signal ) => { utilityResultDetail . stdOutBuffer = stdOutBuffer ; utilityResultDetail . stdErrBuffer = stdErrBuffer ; if ( code !== 0 ) { if ( detectSalesforceCliError ( stdOutBuffer ) ) { utilityResultDetail . error = new SfdxCliError ( sfdxCommandString , stdOutBuffer , `${ failureMessage }` , `${ dbgNs }executeSfdxCommand` ) ; } else { utilityResultDetail . error = new ShellError ( sfdxCommandString , code , signal , stdErrBuffer , stdOutBuffer , `${ dbgNs }executeSfdxCommand` ) ; } utilityResult . error ( utilityResultDetail . error ) ; utilityResult . debugResult ( `${ failureMessage }` , `${ dbgNs }executeSfdxCommand:` ) ; reject ( utilityResult ) ; } else { const stdOutJsonResponse = stdOutBuffer . substring ( stdOutBuffer . indexOf ( '{' ) , stdOutBuffer . lastIndexOf ( '}' ) + 1 ) ; const parsedCliResponse = safeParse ( stdOutJsonResponse ) as AnyJson ; if ( parsedCliResponse [ 'unparsed' ] ) { utilityResultDetail . error = new ShellError ( sfdxCommandString , code , signal , stdErrBuffer , stdOutBuffer , `${ dbgNs }executeSfdxCommand` ) ; utilityResult . error ( utilityResultDetail . error ) ; reject ( utilityResult ) ; } if ( detectSalesforceCliError ( parsedCliResponse ) ) { utilityResultDetail . error = new SfdxCliError ( sfdxCommandString , stdOutJsonResponse , `${ failureMessage }` , `${ dbgNs }executeSfdxCommand:` ) ; utilityResult . error ( utilityResultDetail . error ) ; utilityResult . debugResult ( `${ mixedMessage }` , `${ dbgNs }executeSfdxCommand:` ) ; reject ( utilityResult ) ; } utilityResultDetail . stdOutParsed = parsedCliResponse ; utilityResult . success ( ) ; utilityResult . debugResult ( `${ successMessage }` , `${ dbgNs }executeSfdxCommand:` ) ; resolve ( utilityResult ) ; } } ) ; } ) as Promise < SfdxFalconResult > ; } function param { string } aliasOrUsername param { string [ ] } packageNames param { string } retrieveTargetDir returns { Promise < SfdxFalconResult > } description public async export async function fetchMetadataPackages ( aliasOrUsername , packageNames , retrieveTargetDir ) { const sfdxCommandString = `sfdx force:mdapi:retrieve ` + ` --targetusername ${ aliasOrUsername }` + ` --packagenames "${ packageNames . join ( '","' ) }"` + ( packageNames . length === 1 ? ' --singlepackage' : '' ) + ` --retrievetargetdir ${ retrieveTargetDir }` + ` --wait 10` + ` --loglevel debug` + ` --json` ; await waitASecond ( 3 ) ; const utilityResult = new SfdxFalconResult ( `sfdx:fetchMetadataPackages` , SfdxFalconResultType . UTILITY ) ; const utilityResultDetail = { sfdxCommandString : sfdxCommandString , stdOutParsed : null , stdOutBuffer : null , stdErrBuffer : null , error : null } as SfdxUtilityResultDetail ; utilityResult . detail = utilityResultDetail ; utilityResult . debugResult ( 'Utility Result Initialized' , `${ dbgNs }fetchMetadataPackages:` ) ; const messages = { failureMessage : 'Package Retrieval Failed' , successMessage : 'Package Retrieval Succeeded' , mixedMessage : 'Package retrieval failed but the CLI returned a Success Response' } ; return executeSfdxCommand ( sfdxCommandString , utilityResult , messages ) ; } function param { string } orgAlias param { string } apiVersion returns { Promise < Connection > } description public async export async function getConnection ( aliasOrUsername , apiVersion ? ) { SfdxFalconDebug . obj ( `${ dbgNs }getConnection:arguments:` , arguments , `arguments: ` ) ; let username = await getUsernameFromAlias ( aliasOrUsername ) ; if ( typeof username === 'undefined' ) { username = aliasOrUsername ; } SfdxFalconDebug . str ( `${ dbgNs }getConnection:username:` , username , `username: ` ) ; const authInfo = await AuthInfo . create ( { username : username } ) ; const connection = await Connection . create ( { authInfo : authInfo } ) ; if ( typeof apiVersion !== 'undefined' ) { SfdxFalconDebug . str ( `${ dbgNs }getConnection:apiVersion:` , apiVersion , `apiVersion: ` ) ; connection . setApiVersion ( apiVersion ) ; } return connection ; } function param { string } sfdxAlias returns { Promise < string > } description public async export async function getUsernameFromAlias ( sfdxAlias ) { const username = await Aliases . fetch ( sfdxAlias ) ; return username ; } function param { SfdxOrgInfoMap } sfdxOrgInfoMap returns { SfdxOrgInfo [ ] } description public export function identifyDevHubOrgs ( sfdxOrgInfoMap ) { SfdxFalconDebug . obj ( `${ dbgNs }identifyDevHubOrgs:arguments:` , arguments , `arguments: ` ) ; if ( ( sfdxOrgInfoMap instanceof Map ) !== true ) { throw new SfdxFalconError ( `Expected sfdxOrgInfoMap to a Map but got a '${ typeof sfdxOrgInfoMap !== 'undefined' ? sfdxOrgInfoMap . constructor . name : 'undefined' }' instead.` , `TypeError` , `${ dbgNs }identifyDevHubOrgs` ) ; } const devHubOrgInfos = new Array < SfdxOrgInfo > ( ) ; for ( const orgInfo of sfdxOrgInfoMap . values ( ) ) { if ( orgInfo . isDevHub ) { SfdxFalconDebug . str ( `${ dbgNs }identifyDevHubOrgs:` , `${ orgInfo . alias }(${ orgInfo . username })` , `DEVELOPER HUB FOUND: ` ) ; devHubOrgInfos . push ( orgInfo ) ; } else { SfdxFalconDebug . str ( `${ dbgNs }identifyDevHubOrgs:` , `${ orgInfo . alias }(${ orgInfo . username })` , `NOT A DEVELOPER HUB: ` ) ; } } SfdxFalconDebug . obj ( `${ dbgNs }identifyDevHubOrgs:devHubOrgInfos` , devHubOrgInfos , `devHubOrgInfos: ` ) ; return devHubOrgInfos ; } function param { SfdxOrgInfoMap } sfdxOrgInfoMap returns { Promise < SfdxOrgInfo [ ] > } description public async export async function identifyEnvHubOrgs ( sfdxOrgInfoMap ) { SfdxFalconDebug . obj ( `${ dbgNs }identifyEnvHubOrgs:arguments:` , arguments , `arguments: ` ) ; if ( ( sfdxOrgInfoMap instanceof Map ) !== true ) { throw new SfdxFalconError ( `Expected sfdxOrgInfoMap to a Map but got a '${ typeof sfdxOrgInfoMap !== 'undefined' ? sfdxOrgInfoMap . constructor . name : 'undefined' }' instead.` , `TypeError` , `${ dbgNs }identifyEnvHubOrgs` ) ; } const envHubOrgInfos = new Array < SfdxOrgInfo > ( ) ; for ( const orgInfo of sfdxOrgInfoMap . values ( ) ) { if ( await orgInfo . determineEnvHubStatus ( ) ) { SfdxFalconDebug . str ( `${ dbgNs }identifyEnvHubOrgs:` , `${ orgInfo . alias }(${ orgInfo . username })` , `ENVIRONMENT HUB FOUND: ` ) ; envHubOrgInfos . push ( orgInfo ) ; } else { SfdxFalconDebug . str ( `${ dbgNs }identifyEnvHubOrgs:` , `${ orgInfo . alias }(${ orgInfo . username })` , `NOT AN ENVIRONMENT HUB: ` ) ; } } SfdxFalconDebug . obj ( `${ dbgNs }identifyEnvHubOrgs:envHubOrgInfos` , envHubOrgInfos , `envHubOrgInfos: ` ) ; return envHubOrgInfos ; } function param { SfdxOrgInfoMap } sfdxOrgInfoMap returns { Promise < SfdxOrgInfo [ ] > } description public async export async function identifyPkgOrgs ( sfdxOrgInfoMap ) { SfdxFalconDebug . obj ( `${ dbgNs }identifyPkgOrgs:arguments:` , arguments , `arguments: ` ) ; if ( ( sfdxOrgInfoMap instanceof Map ) !== true ) { throw new SfdxFalconError ( `Expected sfdxOrgInfoMap to a Map but got a '${ typeof sfdxOrgInfoMap !== 'undefined' ? sfdxOrgInfoMap . constructor . name : 'undefined' }' instead.` , `TypeError` , `${ dbgNs }identifyPkgOrgs` ) ; } const pkgOrgInfos = new Array < SfdxOrgInfo > ( ) ; for ( const orgInfo of sfdxOrgInfoMap . values ( ) ) { if ( await orgInfo . determinePkgOrgStatus ( ) ) { SfdxFalconDebug . str ( `${ dbgNs }identifyPkgOrgs:` , `${ orgInfo . alias }(${ orgInfo . username })` , `PACKAGING ORG FOUND: ` ) ; pkgOrgInfos . push ( orgInfo ) ; } else { SfdxFalconDebug . str ( `${ dbgNs }identifyPkgOrgs:` , `${ orgInfo . alias }(${ orgInfo . username })` , `NOT A PACKAGING ORG: ` ) ; } } SfdxFalconDebug . obj ( `${ dbgNs }identifyPkgOrgs:pkgOrgInfos` , pkgOrgInfos , `pkgOrgInfos: ` ) ; return pkgOrgInfos ; } function param { string } mdapiSourceRootDir param { string } sfdxSourceOutputDir returns { Promise < SfdxFalconResult > } description public async export async function mdapiConvert ( mdapiSourceRootDir , sfdxSourceOutputDir ) { const sfdxCommandString = `sfdx force:mdapi:convert ` + ` --rootdir ${ mdapiSourceRootDir }` + ` --outputdir ${ sfdxSourceOutputDir }` + ` --loglevel debug` + ` --json` ; await waitASecond ( 3 ) ; const utilityResult = new SfdxFalconResult ( `sfdx:mdapiConvert` , SfdxFalconResultType . UTILITY ) ; const utilityResultDetail = { sfdxCommandString : sfdxCommandString , stdOutParsed : null , stdOutBuffer : null , stdErrBuffer : null , error : null } as SfdxUtilityResultDetail ; utilityResult . detail = utilityResultDetail ; utilityResult . debugResult ( 'Utility Result Initialized' , `${ dbgNs }mdapiConvert:` ) ; const messages = { failureMessage : 'MDAPI Source Conversion Failed' , successMessage : 'MDAPI Source Conversion Succeeded' , mixedMessage : 'MDAPI Source Conversion failed but the CLI returned a Success Response' } ; return executeSfdxCommand ( sfdxCommandString , utilityResult , messages ) ; } function param { AliasOrConnection } aliasOrConnection returns { Promise < ResolvedConnection > } description public async export async function resolveConnection ( aliasOrConnection ) { if ( typeof aliasOrConnection !== 'string' && ( typeof aliasOrConnection === 'object' && ( ( aliasOrConnection as object ) instanceof Connection ) !== true ) ) { throw new SfdxFalconError ( `Expected aliasOrConnection to be a string or Connection Object. Got '${ typeof aliasOrConnection }' instead. ` , `TypeError` , `${ dbgNs }resolveConnection` ) ; } let connection ; let orgIdentifier ; if ( typeof aliasOrConnection === 'string' ) { orgIdentifier = aliasOrConnection ; connection = await getConnection ( aliasOrConnection ) ; } else { connection = aliasOrConnection ; orgIdentifier = connection . getUsername ( ) ; } return { connection : connection , orgIdentifier : orgIdentifier } ; } function returns { Promise < SfdxFalconResult > } description public async export async function scanConnectedOrgs ( ) { const sfdxCommandString = `sfdx force:org:list --json` ; const utilityResult = new SfdxFalconResult ( `sfdx:executeSfdxCommand` , SfdxFalconResultType . UTILITY ) ; const utilityResultDetail = { sfdxCommandString : sfdxCommandString , stdOutParsed : null , stdOutBuffer : null , stdErrBuffer : null , error : null } as SfdxUtilityResultDetail ; utilityResult . detail = utilityResultDetail ; utilityResult . debugResult ( 'Utility Result Initialized' , `${ dbgNs }scanConnectedOrgs:` ) ; const messages = { failureMessage : 'Unable to scan Connected Orgs' , successMessage : 'Scan Connected Orgs Succeeded' , mixedMessage : 'Scan Connected Orgs Failed but the CLI Returned a Success Response' } ; return executeSfdxCommand ( sfdxCommandString , utilityResult , messages ) ; }