Skip to content

Commit b1d6a4d

Browse files
Merge pull request #1520 from contentstack/feat/dx-562-set-get-urls
dx | 562 set get personalization and developer hub url
2 parents 6cb2ac6 + 1b53d48 commit b1d6a4d

File tree

12 files changed

+108
-28
lines changed

12 files changed

+108
-28
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-branches/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"devDependencies": {
2828
"@contentstack/cli-auth": "~1.3.19",
29-
"@contentstack/cli-config": "~1.6.4",
29+
"@contentstack/cli-config": "~1.7.0",
3030
"@contentstack/cli-dev-dependencies": "~1.2.4",
3131
"@oclif/plugin-help": "^5.1.19",
3232
"@oclif/test": "^2.5.6",

packages/contentstack-config/README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version)
21-
@contentstack/cli-config/1.6.5 darwin-arm64 node-v22.2.0
21+
@contentstack/cli-config/1.7.0 darwin-arm64 node-v22.2.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND
@@ -265,18 +265,23 @@ Set region for CLI
265265

266266
```
267267
USAGE
268-
$ csdx config:set:region [REGION] [-d <value> -m <value> --ui-host <value> -n <value>]
268+
$ csdx config:set:region [REGION] [-d <value> -m <value> --ui-host <value> -n <value>] [--developer-hub <value>]
269+
[--personalize <value>] [--launch <value>]
269270
270271
ARGUMENTS
271272
REGION Name for the region
272273
273274
FLAGS
274-
-d, --cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and name
275-
flags are required
276-
-m, --cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host and name
277-
flags are required
278-
-n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
279-
--ui-host=<value> Custom UI host to set for CLI, if this flag is added then cda, cma and name flags are required
275+
-d, --cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and name
276+
flags are required
277+
-m, --cma=<value> Custom host to set for content management API, , if this flag is added then cda, ui-host and
278+
name flags are required
279+
-n, --name=<value> Name for the region, if this flag is added then cda, cma and ui-host flags are required
280+
--developer-hub=<value> Custom host to set for developer hub API
281+
--launch=<value> Custom host to set for launch API
282+
--personalize=<value> Custom host to set for personalization API
283+
--ui-host=<value> Custom UI host to set for CLI, if this flag is added then cda, cma and name flags are
284+
required
280285
281286
DESCRIPTION
282287
Set region for CLI
@@ -295,6 +300,14 @@ EXAMPLES
295300
$ csdx config:set:region GCP-NA
296301
297302
$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India"
303+
304+
$ 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>
305+
306+
$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --personalize <personalize_url>
307+
308+
$ csdx config:set:region --cma <contentstack_cma_endpoint> --cda <contentstack_cda_endpoint> --ui-host <contentstack_ui_host_endpoint> --name "India" --launch <launch_url>
309+
310+
$ 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>
298311
```
299312

300313
_See code: [src/commands/config/set/region.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-config/src/commands/config/set/region.ts)_

packages/contentstack-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-config",
33
"description": "Contentstack CLI plugin for configuration",
4-
"version": "1.6.5",
4+
"version": "1.7.0",
55
"author": "Contentstack",
66
"scripts": {
77
"build": "npm run clean && npm run compile",

packages/contentstack-config/src/commands/config/get/region.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default class RegionGetCommand extends BaseCommand<typeof RegionGetComman
1818
cliux.print(`CDA HOST: ${currentRegion.cda}`);
1919
cliux.print(`CMA HOST: ${currentRegion.cma}`);
2020
cliux.print(`UI HOST: ${currentRegion.uiHost}`);
21+
cliux.print(`Developer Hub URL: ${currentRegion.developerHubUrl}`);
22+
cliux.print(`Launch URL: ${currentRegion.launchHubUrl}`);
23+
cliux.print(`Personalize URL: ${currentRegion.personalizeUrl}`);
2124
this.logger.error(`Currently using ${currentRegion.name} region`);
2225

2326
}

packages/contentstack-config/src/commands/config/set/region.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

packages/contentstack-config/src/interfaces/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ export interface Region {
1515
cma: string;
1616
cda: string;
1717
uiHost: string;
18+
developerHubUrl: string;
19+
personalizeUrl: string;
20+
launchHubUrl: string;
1821
}

packages/contentstack-config/src/utils/region-handler.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { configHandler } from '@contentstack/cli-utilities';
33
function validURL(str) {
44
const pattern = new RegExp(
55
'^(https?:\\/\\/)?' + // protocol (http or https)
6-
'([a-zA-Z0-9.-]+|' + // domain name
7-
'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))' + // IP address
8-
'(:\\d+)?' + // port
9-
'(/[-a-zA-Z0-9_.~+-]*)*' + // path
10-
'(\\?[;&a-zA-Z0-9_.~+=-]*)?' + // query string
11-
'(\\#[-a-zA-Z0-9_]*)?$', // fragment
6+
'([a-zA-Z0-9.-]+|' + // domain name
7+
'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))' + // IP address
8+
'(:\\d+)?' + // port
9+
'(/[-a-zA-Z0-9_.~+-]*)*' + // path
10+
'(\\?[;&a-zA-Z0-9_.~+=-]*)?' + // query string
11+
'(\\#[-a-zA-Z0-9_]*)?$', // fragment
1212
'i',
1313
);
1414

@@ -22,30 +22,45 @@ const regions = {
2222
cda: 'https://cdn.contentstack.io',
2323
uiHost: 'https://app.contentstack.com',
2424
name: 'NA',
25+
'developerHubUrl': 'https://developerhub-api.contentstack.com',
26+
'launchHubUrl': 'https://launch-api.contentstack.com',
27+
'personalizeUrl': 'https://personalization-api.contentstack.com',
2528
},
2629
EU: {
2730
cma: 'https://eu-api.contentstack.com',
2831
cda: 'https://eu-cdn.contentstack.com',
2932
uiHost: 'https://eu-app.contentstack.com',
3033
name: 'EU',
34+
'developerHubUrl': 'https://eu-developerhub-api.contentstack.com',
35+
'launchHubUrl': 'https://eu-launch-api.contentstack.com',
36+
'personalizeUrl': '',
3137
},
3238
'AZURE-NA': {
3339
cma: 'https://azure-na-api.contentstack.com',
3440
cda: 'https://azure-na-cdn.contentstack.com',
3541
uiHost: 'https://azure-na-app.contentstack.com',
3642
name: 'AZURE-NA',
43+
'developerHubUrl': 'https://azure-na-developerhub-api.contentstack.com',
44+
'launchHubUrl': 'https://azure-na-launch-api.contentstack.com',
45+
'personalizeUrl': '',
3746
},
3847
'AZURE-EU': {
3948
cma: 'https://azure-eu-api.contentstack.com',
4049
cda: 'https://azure-eu-cdn.contentstack.com',
4150
uiHost: 'https://azure-eu-app.contentstack.com',
4251
name: 'AZURE-EU',
52+
'developerHubUrl': 'https://azure-eu-developerhub-api.contentstack.com',
53+
'launchHubUrl': 'https://azure-eu-launch-api.contentstack.com',
54+
'personalizeUrl': '',
4355
},
4456
'GCP-NA': {
4557
cma: 'https://gcp-na-api.contentstack.com',
4658
cda: 'https://gcp-na-cdn.contentstack.com',
4759
uiHost: 'https://gcp-na-app.contentstack.com',
4860
name: 'GCP-NA',
61+
'developerHubUrl': 'https://gcp-na-developerhub-api.contentstack.com',
62+
'launchHubUrl': '',
63+
'personalizeUrl': '',
4964
},
5065
};
5166

@@ -133,6 +148,9 @@ class UserConfig {
133148
cda: regionObject.cda,
134149
uiHost: regionObject.uiHost,
135150
name: regionObject.name,
151+
developerHubUrl: regionObject['developerHubUrl'],
152+
personalizeUrl: regionObject['personalizeUrl'],
153+
launchHubUrl: regionObject['launchHubUrl'],
136154
};
137155

138156
return sanitizedRegion;

packages/contentstack-config/test/unit/commands/region.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ describe('Region command', function () {
1313
cma: 'https://api.contentstack.com',
1414
cda: 'https://cda.contentstack.com',
1515
uiHost: '',
16+
'developerHubUrl': 'https://developerhub-api.contentstack.com',
17+
'launchHubUrl': 'https://launch-api.contentstack.com',
18+
'personalizeUrl': 'https://personalization-api.contentstack.com',
1619
};
1720
let cliuxPrintStub;
1821
beforeEach(function () {

packages/contentstack-export/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"devDependencies": {
2727
"@contentstack/cli-auth": "~1.3.19",
28-
"@contentstack/cli-config": "~1.6.4",
28+
"@contentstack/cli-config": "~1.7.0",
2929
"@contentstack/cli-dev-dependencies": "~1.2.4",
3030
"@oclif/plugin-help": "^5.1.19",
3131
"@oclif/test": "^2.5.6",

0 commit comments

Comments
 (0)