@@ -16,100 +16,6 @@ function validURL(str) {
1616 return pattern . test ( str ) ;
1717}
1818
19- // Available region list
20- const regions = {
21- NA : {
22- name : 'NA' ,
23- cma : 'https://api.contentstack.io' ,
24- cda : 'https://cdn.contentstack.io' ,
25- uiHost : 'https://app.contentstack.com' ,
26- developerHubUrl : 'https://developerhub-api.contentstack.com' ,
27- launchHubUrl : 'https://launch-api.contentstack.com' ,
28- personalizeUrl : 'https://personalize-api.contentstack.com' ,
29- } ,
30- 'AWS-NA' : {
31- name : 'AWS-NA' ,
32- cma : 'https://api.contentstack.io' ,
33- cda : 'https://cdn.contentstack.io' ,
34- uiHost : 'https://app.contentstack.com' ,
35- developerHubUrl : 'https://developerhub-api.contentstack.com' ,
36- launchHubUrl : 'https://launch-api.contentstack.com' ,
37- personalizeUrl : 'https://personalize-api.contentstack.com' ,
38- } ,
39- EU : {
40- name : 'EU' ,
41- cma : 'https://eu-api.contentstack.com' ,
42- cda : 'https://eu-cdn.contentstack.com' ,
43- uiHost : 'https://eu-app.contentstack.com' ,
44- developerHubUrl : 'https://eu-developerhub-api.contentstack.com' ,
45- launchHubUrl : 'https://eu-launch-api.contentstack.com' ,
46- personalizeUrl : 'https://eu-personalize-api.contentstack.com' ,
47- } ,
48- 'AWS-EU' : {
49- name : 'AWS-EU' ,
50- cma : 'https://eu-api.contentstack.com' ,
51- cda : 'https://eu-cdn.contentstack.com' ,
52- uiHost : 'https://eu-app.contentstack.com' ,
53- developerHubUrl : 'https://eu-developerhub-api.contentstack.com' ,
54- launchHubUrl : 'https://eu-launch-api.contentstack.com' ,
55- personalizeUrl : 'https://eu-personalize-api.contentstack.com' ,
56- } ,
57- AU : {
58- name : 'AU' ,
59- cma : 'https://au-api.contentstack.com' ,
60- cda : 'https://au-cdn.contentstack.com' ,
61- uiHost : 'https://au-app.contentstack.com' ,
62- developerHubUrl : 'https://au-developerhub-api.contentstack.com' ,
63- launchHubUrl : 'https://au-launch-api.contentstack.com' ,
64- personalizeUrl : 'https://au-personalize-api.contentstack.com' ,
65- } ,
66- 'AWS-AU' : {
67- name : 'AWS-AU' ,
68- cma : 'https://au-api.contentstack.com' ,
69- cda : 'https://au-cdn.contentstack.com' ,
70- uiHost : 'https://au-app.contentstack.com' ,
71- developerHubUrl : 'https://au-developerhub-api.contentstack.com' ,
72- launchHubUrl : 'https://au-launch-api.contentstack.com' ,
73- personalizeUrl : 'https://au-personalize-api.contentstack.com' ,
74- } ,
75- 'AZURE-NA' : {
76- name : 'AZURE-NA' ,
77- cma : 'https://azure-na-api.contentstack.com' ,
78- cda : 'https://azure-na-cdn.contentstack.com' ,
79- uiHost : 'https://azure-na-app.contentstack.com' ,
80- developerHubUrl : 'https://azure-na-developerhub-api.contentstack.com' ,
81- launchHubUrl : 'https://azure-na-launch-api.contentstack.com' ,
82- personalizeUrl : 'https://azure-na-personalize-api.contentstack.com' ,
83- } ,
84- 'AZURE-EU' : {
85- name : 'AZURE-EU' ,
86- cma : 'https://azure-eu-api.contentstack.com' ,
87- cda : 'https://azure-eu-cdn.contentstack.com' ,
88- uiHost : 'https://azure-eu-app.contentstack.com' ,
89- developerHubUrl : 'https://azure-eu-developerhub-api.contentstack.com' ,
90- launchHubUrl : 'https://azure-eu-launch-api.contentstack.com' ,
91- personalizeUrl : 'https://azure-eu-personalize-api.contentstack.com' ,
92- } ,
93- 'GCP-NA' : {
94- name : 'GCP-NA' ,
95- cma : 'https://gcp-na-api.contentstack.com' ,
96- cda : 'https://gcp-na-cdn.contentstack.com' ,
97- uiHost : 'https://gcp-na-app.contentstack.com' ,
98- developerHubUrl : 'https://gcp-na-developerhub-api.contentstack.com' ,
99- launchHubUrl : 'https://gcp-na-launch-api.contentstack.com' ,
100- personalizeUrl : 'https://gcp-na-personalize-api.contentstack.com' ,
101- } ,
102- 'GCP-EU' : {
103- name : 'GCP-EU' ,
104- cma : 'https://gcp-eu-api.contentstack.com' ,
105- cda : 'https://gcp-eu-cdn.contentstack.com' ,
106- uiHost : 'https://gcp-eu-app.contentstack.com' ,
107- developerHubUrl : 'https://gcp-eu-developerhub-api.contentstack.com' ,
108- launchHubUrl : 'https://gcp-eu-launch-api.contentstack.com' ,
109- personalizeUrl : 'https://gcp-eu-personalize-api.contentstack.com' ,
110- } ,
111- } ;
112-
11319class UserConfig {
11420 /**
11521 *
@@ -118,19 +24,24 @@ class UserConfig {
11824 * @returns {object } region object with cma, cda, region property
11925 */
12026 setRegion ( region ) {
121- const endpointsObj = Utils . getEndpointsByRegion ( region ) ;
122- if ( endpointsObj ) {
123- const regionObj = {
124- name : region . toUpperCase ( ) ,
125- cma : endpointsObj . contentManagement ,
126- cda : endpointsObj . contentDelivery ,
127- uiHost : endpointsObj . application ,
128- developerHubUrl : endpointsObj . developerHub ,
129- launchHubUrl : endpointsObj . launch ,
130- personalizeUrl : endpointsObj . personalizeManagement ,
27+ try {
28+ const endpointsObj = Utils . getContentstackEndpoint ( region ) ;
29+ if ( endpointsObj ) {
30+ const regionObj = {
31+ name : region . toUpperCase ( ) ,
32+ cma : endpointsObj . contentManagement ,
33+ cda : endpointsObj . contentDelivery ,
34+ uiHost : endpointsObj . application ,
35+ developerHubUrl : endpointsObj . developerHub ,
36+ launchHubUrl : endpointsObj . launch ,
37+ personalizeUrl : endpointsObj . personalizeManagement ,
38+ }
39+ configHandler . set ( 'region' , regionObj ) ;
40+ return regionObj ;
13141 }
132- configHandler . set ( 'region' , regionObj ) ;
133- return regionObj ;
42+ } catch ( error ) {
43+ // Return undefined for invalid regions
44+ return undefined ;
13445 }
13546 }
13647
@@ -144,7 +55,19 @@ class UserConfig {
14455 if ( regionDetails ) return regionDetails ;
14556
14657 // returns AWS-NA region if not found in config
147- return regions [ 'AWS-NA' ] ;
58+ const defaultEndpoints = Utils . getContentstackEndpoint ( 'AWS-NA' ) ;
59+ if ( defaultEndpoints ) {
60+ return {
61+ name : 'AWS-NA' ,
62+ cma : defaultEndpoints . contentManagement ,
63+ cda : defaultEndpoints . contentDelivery ,
64+ uiHost : defaultEndpoints . application ,
65+ developerHubUrl : defaultEndpoints . developerHub ,
66+ launchHubUrl : defaultEndpoints . launch ,
67+ personalizeUrl : defaultEndpoints . personalizeManagement ,
68+ } ;
69+ }
70+ throw new TypeError ( 'Region is not set yet, Please set the region first' ) ;
14871 }
14972
15073 /**
@@ -211,7 +134,4 @@ class UserConfig {
211134 }
212135}
213136
214- // Export the regions object for use in other packages
215- export { regions } ;
216-
217137export default new UserConfig ( ) ;
0 commit comments