Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@

fileignoreconfig:
- filename: packages/contentstack-import/src/import/modules/environments.ts
checksum: f61c635eaec8026e0cfa80a5ab8272f7946531f6d89505dc0d247b4c7ab0eab7
- filename: pnpm-lock.yaml
checksum: 2fd43b3eef46720de65d8c5f6ff782d5db78b73a49f106222a40d8c0a4ccf78a
- filename: package-lock.json
checksum: 73a5607658267002cdece1123c08fd201cb4b78d31ff889488adc7be7ccf30ad
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
checksum: 5ab20e057fa9c4c300f7a882d30e1c68bbc91ed19de520488107e8c37239682a
- filename: packages/contentstack-migration/README.md
checksum: 0deea9c8e43a89a4f20fb25ffe1a38cccd19020fe4fedae80f1ca24d34307f2b
- filename: packages/contentstack-import/src/import/modules/taxonomies.ts
checksum: f4f44b6031d2936ec2da98b39bb5f5c1bd0f3be34dbe498c75e64a35b7d25a33
- filename: packages/contentstack/README.md
checksum: 3a0fab964797476a71d2149ce261d265f410bd756eb9cde9400be9e5250fdc35
- filename: packages/contentstack-import/src/import/modules/environments.ts
checksum: f61c635eaec8026e0cfa80a5ab8272f7946531f6d89505dc0d247b4c7ab0eab7
- filename: pnpm-lock.yaml
checksum: 2fd43b3eef46720de65d8c5f6ff782d5db78b73a49f106222a40d8c0a4ccf78a
- filename: package-lock.json
checksum: fd21f6efef2abd10a22c2511ac61c7a3fa58ad47e33130bc76a6ed5f6c99f5b2
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
checksum: 5ab20e057fa9c4c300f7a882d30e1c68bbc91ed19de520488107e8c37239682a
- filename: packages/contentstack-migration/README.md
checksum: 0deea9c8e43a89a4f20fb25ffe1a38cccd19020fe4fedae80f1ca24d34307f2b
- filename: packages/contentstack-import/src/import/modules/taxonomies.ts
checksum: f4f44b6031d2936ec2da98b39bb5f5c1bd0f3be34dbe498c75e64a35b7d25a33
- filename: packages/contentstack/README.md
checksum: 3a0fab964797476a71d2149ce261d265f410bd756eb9cde9400be9e5250fdc35
- filename: packages/contentstack-config/src/utils/region-handler.ts
checksum: 7fb77272b01e48e0cde7a0b25d18a6a237bd59a8e2156aed8a8de5acd27f2465
version: '1.0'
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/contentstack-config/src/commands/config/set/region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
studio: _flags.string({
description: 'Custom host to set for Studio API',
}),
'asset-management': _flags.string({
description: 'Custom host to set for Asset Management API',
}),
};
static examples = [
'$ csdx config:set:region',
Expand All @@ -61,6 +64,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --personalize <custom_personalize_url>',
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --launch <custom_launch_url>',
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --studio <custom_studio_url>',
'$ csdx config:set:region --cma <custom_cma_host_url> --cda <custom_cda_host_url> --ui-host <custom_ui_host_url> --name "India" --asset-management <asset_management_url>',
'$ csdx config:set:region --cda <custom_cda_host_url> --cma <custom_cma_host_url> --ui-host <custom_ui_host_url> --name "India" --developer-hub <custom_developer_hub_url> --launch <custom_launch_url> --personalize <custom_personalize_url> --studio <custom_studio_url>',
];

Expand All @@ -78,6 +82,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
let personalizeUrl = regionSetFlags['personalize'];
let launchHubUrl = regionSetFlags['launch'];
let composableStudioUrl = regionSetFlags['studio'];
let assetManagementUrl = regionSetFlags['asset-management'];
let selectedRegion = args.region;
if (!(cda && cma && uiHost && name) && !selectedRegion) {
selectedRegion = await interactive.askRegions();
Expand Down Expand Up @@ -108,6 +113,9 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
if (!composableStudioUrl) {
composableStudioUrl = this.transformUrl(cma, 'composable-studio-api');
}
if (!assetManagementUrl) {
assetManagementUrl = this.transformUrl(cma, 'am-api');
}
let customRegion: Region = {
cda,
cma,
Expand All @@ -117,6 +125,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
personalizeUrl,
launchHubUrl,
composableStudioUrl,
assetManagementUrl,
};
customRegion = regionHandler.setCustomRegion(customRegion);
await authHandler.setConfigData('logout'); //Todo: Handle this logout flow well through logout command call
Expand All @@ -128,6 +137,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
cliux.success(`Personalize URL: ${customRegion.personalizeUrl}`);
cliux.success(`Launch URL: ${customRegion.launchHubUrl}`);
cliux.success(`Studio URL: ${customRegion.composableStudioUrl}`);
cliux.success(`Asset Management URL: ${customRegion.assetManagementUrl}`);
} catch (error) {
handleAndLogError(error, { ...this.contextDetails, module: 'config-set-region' });
}
Expand All @@ -146,6 +156,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
cliux.success(`Personalize URL: ${regionDetails.personalizeUrl}`);
cliux.success(`Launch URL: ${regionDetails.launchHubUrl}`);
cliux.success(`Studio URL: ${regionDetails.composableStudioUrl}`);
cliux.success(`Asset Management URL: ${regionDetails.assetManagementUrl}`);
} else {
cliux.error(`Invalid region specified.`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-config/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface Region {
personalizeUrl: string;
launchHubUrl: string;
composableStudioUrl: string;
assetManagementUrl?: string;
}

export interface Limit {
Expand Down
19 changes: 5 additions & 14 deletions packages/contentstack-config/src/utils/region-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function getRegionObject(regionKey: string): Region {
try {
// getContentstackEndpoint handles all aliases defined in regions.json
const endpoints = getContentstackEndpoint(regionKey) as any;

if (typeof endpoints === 'string') {
throw new Error('Invalid endpoint response');
}
Expand All @@ -40,6 +40,7 @@ function getRegionObject(regionKey: string): Region {
launchHubUrl: endpoints.launch,
personalizeUrl: endpoints.personalizeManagement,
composableStudioUrl: endpoints.composableStudio,
assetManagementUrl: endpoints.assetManagement,
};
} catch (error) {
return null;
Expand All @@ -51,21 +52,10 @@ function getRegionObject(regionKey: string): Region {
* This creates a regions object similar to the old hardcoded one but using @contentstack/utils
*/
function getAvailableRegions() {
const regionKeys = [
'NA',
'AWS-NA',
'EU',
'AWS-EU',
'AU',
'AWS-AU',
'AZURE-NA',
'AZURE-EU',
'GCP-NA',
'GCP-EU',
];
const regionKeys = ['NA', 'AWS-NA', 'EU', 'AWS-EU', 'AU', 'AWS-AU', 'AZURE-NA', 'AZURE-EU', 'GCP-NA', 'GCP-EU'];

const regions: RegionsMap = {};

for (const key of regionKeys) {
const regionObj = getRegionObject(key);
if (regionObj) {
Expand Down Expand Up @@ -166,6 +156,7 @@ class UserConfig {
personalizeUrl: regionObject['personalizeUrl'],
launchHubUrl: regionObject['launchHubUrl'],
composableStudioUrl: regionObject['composableStudioUrl'],
assetManagementUrl: regionObject['assetManagementUrl'],
};

return sanitizedRegion;
Expand Down
18 changes: 10 additions & 8 deletions packages/contentstack-config/test/unit/commands/region.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Region command', function () {
launchHubUrl: 'https://launch-api.contentstack.com',
personalizeUrl: 'https://personalization-api.contentstack.com',
composableStudioUrl: 'https://composable-studio-api.contentstack.com',
assetManagementUrl: 'https://am-api.contentstack.com',
};
let cliuxPrintStub: sinon.SinonStub;
let configGetStub: sinon.SinonStub;
Expand All @@ -43,32 +44,32 @@ describe('Region command', function () {
});
it('should log an error and exit when the region is not set', async function () {
const command = new GetRegionCommand([], {} as any);

// Stub the region property to return undefined
sinon.stub(command, 'region').get(() => undefined);

// Stub the exit method to throw to stop execution
const exitStub = sinon.stub(command, 'exit').throws(new Error('EXIT_CALLED'));

// Stub cliux.error to capture error calls
const errorStub = sinon.stub(cliux, 'error');

// Reset cliuxPrintStub to capture new calls
cliuxPrintStub.reset();

// Call the run method directly, expect it to throw
try {
await command.run();
} catch (error) {
// Expected to throw due to exit stub
}

// Verify that cliux.error was called with the correct message
expect(errorStub.calledWith('CLI_CONFIG_GET_REGION_NOT_FOUND')).to.be.true;

// Verify exit was called
expect(exitStub.called).to.be.true;

errorStub.restore();
});

Expand Down Expand Up @@ -309,6 +310,7 @@ describe('Region command', function () {
personalizeUrl: 'https://custom-personalize.com',
launchHubUrl: 'https://custom-launch.com',
composableStudioUrl: 'https://custom-composable-studio.com',
assetManagementUrl: 'https://custom-asset-management.com',
};
const result = UserConfig.setCustomRegion(customRegion);
expect(result).to.deep.equal(customRegion);
Expand Down