Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fileignoreconfig:
- filename: packages/contentstack-import/src/import/modules/environments.ts
checksum: f61c635eaec8026e0cfa80a5ab8272f7946531f6d89505dc0d247b4c7ab0eab7
- filename: pnpm-lock.yaml
checksum: 0b3c36327f58da95cce698d23a5321d86bb4908f3310b57167a8e206c653e3fa
checksum: e96e05b21091fede31e67eea7814321cb9a887dfd2c8f9b81e4bc8a47ebf1624
- filename: package-lock.json
checksum: 270916294e02bdf230fbdd3f6d7c370ff326697ff7a98754c3a9904420b8c7f4
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
Expand Down
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.

17 changes: 17 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(uiHost, '/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,11 +156,18 @@ 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.`);
}
}
transformUrl(url: string, replacement: string): string {
// If replacement contains '/', treat it as a path to append to the base URL
if (replacement.includes('/')) {
const baseUrl = url.replace(/\/$/, ''); // Remove trailing slash if present
return `${baseUrl}${replacement}`;
}

let transformedUrl = url.replace('api', replacement);
if (transformedUrl.startsWith('http')) {
transformedUrl = transformedUrl.split('//')[1];
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
2 changes: 2 additions & 0 deletions packages/contentstack-config/src/utils/region-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function getRegionObject(regionKey: string): Region {
launchHubUrl: endpoints.launch,
personalizeUrl: endpoints.personalizeManagement,
composableStudioUrl: endpoints.composableStudio,
assetManagementUrl: endpoints.assetManagement || (endpoints.application ? `${endpoints.application.replace(/\/$/, '')}/am/api` : undefined),
};
} catch (error) {
return null;
Expand Down Expand Up @@ -166,6 +167,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://asset-management-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