@@ -39,6 +39,15 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
3939 description : 'Name for the region, if this flag is added then cda, cma and ui-host flags are required' ,
4040 dependsOn : [ 'cda' , 'cma' , 'ui-host' ] ,
4141 } ) ,
42+ 'developer-hub' : _flags . string ( {
43+ description : 'Custom host to set for developer hub API' ,
44+ } ) ,
45+ 'personalize' : _flags . string ( {
46+ description : 'Custom host to set for personalization API' ,
47+ } ) ,
48+ 'launch' : _flags . string ( {
49+ description : 'Custom host to set for launch API' ,
50+ } ) ,
4251 } ;
4352 static examples = [
4453 '$ csdx config:set:region' ,
@@ -48,6 +57,10 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
4857 '$ csdx config:set:region AZURE-EU' ,
4958 '$ csdx config:set:region GCP-NA' ,
5059 '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India"' ,
60+ '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --developer-hub <developer_hub_url>' ,
61+ '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --personalize <personalize_url>' ,
62+ '$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --launch <launch_url>' ,
63+ '$ csdx config:set:region --cda <contentstack_cda_endpoint> --cma <contentstack_cma_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --developer-hub <developer_hub_url> --personalize <personalize_url> --launch <launch_url>' ,
5164 ] ;
5265
5366 static args : ArgInput = {
@@ -60,6 +73,9 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
6073 let cma = regionSetFlags . cma ;
6174 let name = regionSetFlags . name ;
6275 let uiHost = regionSetFlags [ 'ui-host' ] ;
76+ let developerHubUrl = regionSetFlags [ 'developer-hub' ] ;
77+ let personalizeUrl = regionSetFlags [ 'personalize' ] ;
78+ let launchHubUrl = regionSetFlags [ 'launch' ] ;
6379 let selectedRegion = args . region ;
6480 if ( ! ( cda && cma && uiHost && name ) && ! selectedRegion ) {
6581 selectedRegion = await interactive . askRegions ( ) ;
@@ -78,13 +94,25 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
7894 // Custom flag will get first priority over region argument
7995 if ( cda && cma && uiHost && name ) {
8096 try {
81- let customRegion : Region = { cda, cma, uiHost, name } ;
97+ if ( ! developerHubUrl ) {
98+ developerHubUrl = this . transformUrl ( cma , 'developerhub-api' ) ;
99+ }
100+ if ( ! launchHubUrl ) {
101+ launchHubUrl = this . transformUrl ( cma , 'launch-api' ) ;
102+ }
103+ if ( ! personalizeUrl ) {
104+ personalizeUrl = this . transformUrl ( cma , 'personalize-api' ) ;
105+ }
106+ let customRegion : Region = { cda, cma, uiHost, name, developerHubUrl, personalizeUrl, launchHubUrl } ;
82107 customRegion = regionHandler . setCustomRegion ( customRegion ) ;
83108 await authHandler . setConfigData ( 'logout' ) ; //Todo: Handle this logout flow well through logout command call
84109 cliux . success ( `Custom region has been set to ${ customRegion . name } ` ) ;
85110 cliux . success ( `CMA HOST: ${ customRegion . cma } ` ) ;
86111 cliux . success ( `CDA HOST: ${ customRegion . cda } ` ) ;
87112 cliux . success ( `UI HOST: ${ customRegion . uiHost } ` ) ;
113+ cliux . success ( `Developer Hub URL: ${ customRegion . developerHubUrl } ` ) ;
114+ cliux . success ( `Personalization URL: ${ customRegion . personalizeUrl } ` ) ;
115+ cliux . success ( `Launch URL: ${ customRegion . launchHubUrl } ` ) ;
88116 } catch ( error ) {
89117 this . logger . error ( 'failed to set the region' , error ) ;
90118 cliux . error ( `Failed to set region due to: ${ error . message } ` ) ;
@@ -96,8 +124,20 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
96124 cliux . success ( `CDA HOST: ${ regionDetails . cda } ` ) ;
97125 cliux . success ( `CMA HOST: ${ regionDetails . cma } ` ) ;
98126 cliux . success ( `UI HOST: ${ regionDetails . uiHost } ` ) ;
127+ cliux . success ( `Developer Hub URL: ${ regionDetails . developerHubUrl } ` ) ;
128+ cliux . success ( `Personalization URL: ${ regionDetails . personalizeUrl } ` ) ;
129+ cliux . success ( `Launch URL: ${ regionDetails . launchHubUrl } ` ) ;
99130 } else {
100131 cliux . error ( `Invalid region is given` ) ;
101132 }
102133 }
134+ transformUrl ( url : string , replacement : string ) : string {
135+ let transformedUrl = url . replace ( 'api' , replacement ) ;
136+ if ( transformedUrl . startsWith ( 'http' ) ) {
137+ transformedUrl = transformedUrl . split ( '//' ) [ 1 ] ;
138+ }
139+ transformedUrl = transformedUrl . startsWith ( 'dev11' ) ? transformedUrl . replace ( 'dev11' , 'dev' ) : transformedUrl ;
140+ transformedUrl = transformedUrl . endsWith ( 'io' ) ? transformedUrl . replace ( 'io' , 'com' ) : transformedUrl ;
141+ return `https://${ transformedUrl } `
142+ }
103143}
0 commit comments