@@ -8,12 +8,13 @@ import getUserAgent from './core/Util.js'
88import contentstackClient from './contentstackClient.js'
99import httpClient from './core/contentstackHTTPClient.js'
1010const regionHostMap = {
11- NA : 'api.contentstack.io' ,
12- EU : 'eu-api.contentstack.com' ,
13- AZURE_NA : 'azure-na-api.contentstack.com' ,
14- AZURE_EU : 'azure-eu-api.contentstack.com' ,
15- GCP_NA : 'gcp-na-api.contentstack.com' ,
16- GCP_EU : 'gcp-eu-api.contentstack.com'
11+ NA : 'api.contentstack.io' ,
12+ EU : 'eu-api.contentstack.com' ,
13+ AU : 'au-api.contentstack.com' ,
14+ AZURE_NA : 'azure-na-api.contentstack.com' ,
15+ AZURE_EU : 'azure-eu-api.contentstack.com' ,
16+ GCP_NA : 'gcp-na-api.contentstack.com' ,
17+ GCP_EU : 'gcp-eu-api.contentstack.com'
1718}
1819
1920/**
@@ -168,56 +169,56 @@ const regionHostMap = {
168169 * @prop {string= } params.integration - Integration name and version e.g react/version
169170 * @returns Contentstack.Client
170171 */
171- export function client ( params = { } ) {
172- let defaultHostName
172+ export function client ( params = { } ) {
173+ let defaultHostName
173174
174- if ( params . region ) {
175- const region = params . region . toUpperCase ( )
176- if ( ! regionHostMap [ region ] ) {
177- throw new Error ( `Invalid region '${ params . region } ' provided. Allowed regions are: ${ Object . keys ( regionHostMap ) . join ( ', ' ) } ` )
175+ if ( params . region ) {
176+ const region = params . region . toUpperCase ( )
177+ if ( ! regionHostMap [ region ] ) {
178+ throw new Error ( `Invalid region '${ params . region } ' provided. Allowed regions are: ${ Object . keys ( regionHostMap ) . join ( ', ' ) } ` )
179+ }
180+ defaultHostName = regionHostMap [ region ]
181+ } else if ( params . host ) {
182+ defaultHostName = params . host
183+ } else {
184+ defaultHostName = regionHostMap [ 'NA' ]
178185 }
179- defaultHostName = regionHostMap [ region ]
180- } else if ( params . host ) {
181- defaultHostName = params . host
182- } else {
183- defaultHostName = regionHostMap [ 'NA' ]
184- }
185186
186- const defaultParameter = {
187- defaultHostName : defaultHostName
188- }
187+ const defaultParameter = {
188+ defaultHostName : defaultHostName
189+ }
189190
190- const sdkAgent = `contentstack-management-javascript/${ packages . version } `
191- const userAgentHeader = getUserAgent ( sdkAgent ,
192- params . application ,
193- params . integration ,
194- params . feature
195- )
196- const requiredHeaders = {
197- 'X-User-Agent' : sdkAgent ,
198- 'User-Agent' : userAgentHeader
199- }
191+ const sdkAgent = `contentstack-management-javascript/${ packages . version } `
192+ const userAgentHeader = getUserAgent ( sdkAgent ,
193+ params . application ,
194+ params . integration ,
195+ params . feature
196+ )
197+ const requiredHeaders = {
198+ 'X-User-Agent' : sdkAgent ,
199+ 'User-Agent' : userAgentHeader
200+ }
200201
201- if ( params . authtoken ) {
202- requiredHeaders . authtoken = params . authtoken
203- }
204- if ( params . authorization ) {
205- requiredHeaders . authorization = params . authorization
206- }
207- if ( params . early_access ) {
208- requiredHeaders . early_access = params . early_access . join ( ',' )
209- }
210- params = {
211- ...defaultParameter ,
212- ...clonedeep ( params )
213- }
202+ if ( params . authtoken ) {
203+ requiredHeaders . authtoken = params . authtoken
204+ }
205+ if ( params . authorization ) {
206+ requiredHeaders . authorization = params . authorization
207+ }
208+ if ( params . early_access ) {
209+ requiredHeaders . early_access = params . early_access . join ( ',' )
210+ }
211+ params = {
212+ ...defaultParameter ,
213+ ...clonedeep ( params )
214+ }
214215
215- params . headers = {
216- ...params . headers ,
217- ...requiredHeaders
218- }
219- const http = httpClient ( params )
220- return contentstackClient ( {
221- http : http
222- } )
216+ params . headers = {
217+ ...params . headers ,
218+ ...requiredHeaders
219+ }
220+ const http = httpClient ( params )
221+ return contentstackClient ( {
222+ http : http
223+ } )
223224}
0 commit comments