Skip to content

Commit 62bab10

Browse files
Refactor region-handler to remove getComposableStudioUrl function and use endpoints.composableStudio directly
1 parent a15ddf6 commit 62bab10

1 file changed

Lines changed: 1 addition & 34 deletions

File tree

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

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,6 @@ function validURL(str) {
2020
return pattern.test(str);
2121
}
2222

23-
/**
24-
* Helper function to get composable studio URL from CMA endpoint
25-
* Since composableStudio endpoint is not yet in @contentstack/utils, we construct it manually
26-
* by extracting the region prefix from the CMA URL
27-
* @param {string} cmaUrl - Content Management API URL (e.g., 'https://eu-api.contentstack.com')
28-
* @returns {string} Composable Studio URL for the region
29-
*/
30-
function getComposableStudioUrl(cmaUrl: string): string {
31-
// Extract hostname from URL (e.g., "eu-api.contentstack.com")
32-
const match = cmaUrl.match(/https?:\/\/([^/]+)/);
33-
if (!match) {
34-
return 'https://composable-studio-api.contentstack.com';
35-
}
36-
37-
const hostname = match[1];
38-
39-
// For default NA region: api.contentstack.io or api.contentstack.com
40-
if (hostname === 'api.contentstack.io' || hostname === 'api.contentstack.com') {
41-
return 'https://composable-studio-api.contentstack.com';
42-
}
43-
44-
// For other regions: {region}-api.contentstack.com
45-
// Extract the region prefix before "-api"
46-
const prefixMatch = hostname.match(/^(.+?)-api\.contentstack\.(com|io)$/);
47-
const regionPrefix = prefixMatch ? prefixMatch[1] : '';
48-
49-
if (!regionPrefix) {
50-
return 'https://composable-studio-api.contentstack.com';
51-
}
52-
53-
return `https://${regionPrefix}-composable-studio-api.contentstack.com`;
54-
}
55-
5623
/**
5724
* Helper function to build region object from @contentstack/utils
5825
* @param {string} regionKey - Region identifier
@@ -75,7 +42,7 @@ function getRegionObject(regionKey: string): Region {
7542
developerHubUrl: endpoints.developerHub,
7643
launchHubUrl: endpoints.launch,
7744
personalizeUrl: endpoints.personalizeManagement,
78-
composableStudioUrl: getComposableStudioUrl(endpoints.contentManagement),
45+
composableStudioUrl: endpoints.composableStudio,
7946
};
8047
} catch (error) {
8148
return null;

0 commit comments

Comments
 (0)