55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
77import { EOL } from 'os' ;
8- import { URL } from 'url' ;
98
109import { flags , FlagsConfig , SfdxCommand } from '@salesforce/command' ;
11- import { Messages , Org , MyDomainResolver , SfdxError , sfdc } from '@salesforce/core' ;
12- import { Env , Duration } from '@salesforce/kit' ;
10+ import { Messages , Org , SfdcUrl , SfdxError } from '@salesforce/core' ;
11+ import { Duration , Env } from '@salesforce/kit' ;
1312import { openUrl } from '../../../shared/utils' ;
1413
1514Messages . importMessagesDirectory ( __dirname ) ;
@@ -51,7 +50,22 @@ export class OrgOpenCommand extends SfdxCommand {
5150 return output ;
5251 }
5352 // we actually need to open the org
54- await this . checkLightningDomain ( url ) ;
53+ try {
54+ this . ux . startSpinner ( messages . getMessage ( 'domainWaiting' ) ) ;
55+ const sfdcUrl = new SfdcUrl ( url ) ;
56+ await sfdcUrl . checkLightningDomain ( ) ;
57+ } catch ( err ) {
58+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
59+ if ( err . message ?. includes ( 'timeout' ) ) {
60+ const domain = `https://${ / h t t p s ? : \/ \/ ( [ ^ . ] * ) / . exec ( url ) [ 1 ] } .lightning.force.com` ;
61+ const timeout = new Duration ( new Env ( ) . getNumber ( 'SFDX_DOMAIN_RETRY' , 240 ) , Duration . Unit . SECONDS ) ;
62+ this . logger . debug ( `Did not find IP for ${ domain } after ${ timeout . seconds } seconds` ) ;
63+ throw new SfdxError ( messages . getMessage ( 'domainTimeoutError' ) , 'domainTimeoutError' , [
64+ messages . getMessage ( 'domainTimeoutAction' ) ,
65+ ] ) ;
66+ }
67+ throw SfdxError . wrap ( err ) ;
68+ }
5569 await openUrl ( url ) ;
5670 return output ;
5771 }
@@ -64,32 +78,6 @@ export class OrgOpenCommand extends SfdxCommand {
6478 const instanceUrlClean = instanceUrl . replace ( / \/ $ / , '' ) ;
6579 return `${ instanceUrlClean } /secur/frontdoor.jsp?sid=${ accessToken } ` ;
6680 }
67-
68- private async checkLightningDomain ( url : string ) : Promise < void > {
69- const domain = `https://${ / h t t p s ? : \/ \/ ( [ ^ . ] * ) / . exec ( url ) [ 1 ] } .lightning.force.com` ;
70- const timeout = new Duration ( new Env ( ) . getNumber ( 'SFDX_DOMAIN_RETRY' , 240 ) , Duration . Unit . SECONDS ) ;
71- if ( sfdc . isInternalUrl ( url ) || timeout . seconds === 0 ) {
72- return ;
73- }
74-
75- const resolver = await MyDomainResolver . create ( {
76- url : new URL ( domain ) ,
77- timeout,
78- frequency : new Duration ( 1 , Duration . Unit . SECONDS ) ,
79- } ) ;
80- this . ux . startSpinner ( messages . getMessage ( 'domainWaiting' ) ) ;
81-
82- try {
83- const ip = await resolver . resolve ( ) ;
84- this . logger . debug ( `Found IP ${ ip } for ${ domain } ` ) ;
85- return ;
86- } catch ( error ) {
87- this . logger . debug ( `Did not find IP for ${ domain } after ${ timeout . seconds } seconds` ) ;
88- throw new SfdxError ( messages . getMessage ( 'domainTimeoutError' ) , 'domainTimeoutError' , [
89- messages . getMessage ( 'domainTimeoutAction' ) ,
90- ] ) ;
91- }
92- }
9381}
9482
9583interface OrgOpenOutput {
0 commit comments