Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ fileignoreconfig:
ignore_detectors:
- filecontent
- filename: package-lock.json
checksum: 1475ee2c6a615f4e6f8393f4a209398aa6b827e7d036302c6fc065d5914e8292
checksum: 15d4ccb9d96488282d6867bf6f2e157cad4a1e49f44e4c2b9ba591f14ea6e557
- filename: test/unit/ContentstackHTTPClient-test.js
checksum: c3c149cd016e3668b730aa64b0f067ab05cbd615328757faedfcea52f1fc6f51
- filename: .husky/pre-commit
checksum: 52a664f536cf5d1be0bea19cb6031ca6e8107b45b6314fe7d47b7fad7d800632
- filename: test/sanity-check/api/user-test.js
Expand Down
211 changes: 0 additions & 211 deletions lib/assets/regions.json

This file was deleted.

7 changes: 4 additions & 3 deletions lib/contentstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/
import packages from '../package.json'
import clonedeep from 'lodash/cloneDeep'
import getUserAgent, { getRegionEndpoint } from './core/Util.js'
import getUserAgent from './core/Util.js'
import contentstackClient from './contentstackClient.js'
import httpClient from './core/contentstackHTTPClient.js'
import { getContentstackEndpoint } from '@contentstack/utils'

/**
* Create client instance
Expand Down Expand Up @@ -161,11 +162,11 @@ import httpClient from './core/contentstackHTTPClient.js'
* @returns Contentstack.Client
*/
export function client (params = {}) {
let defaultHostName = getRegionEndpoint('na')
let defaultHostName = getContentstackEndpoint('aws-na', 'contentManagement', true)

if (params.region) {
params.region = params.region.toLowerCase()
defaultHostName = getRegionEndpoint(params.region)
defaultHostName = getContentstackEndpoint(params.region, 'contentManagement', true)
}

const defaultParameter = {
Expand Down
12 changes: 0 additions & 12 deletions lib/core/Util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { platform, release } from 'os'
import regionHostMap from '../assets/regions.json'

const HOST_REGEX = /^(?!(?:(?:https?|ftp):\/\/|internal|localhost|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))(?:[\w-]+\.contentstack\.(?:io|com)(?::[^\/\s:]+)?|[\w-]+(?:\.[\w-]+)*(?::[^\/\s:]+)?)(?![\/?#])$/ // eslint-disable-line

Expand Down Expand Up @@ -237,14 +236,3 @@ export const validateAndSanitizeConfig = (config) => {
url: config.url.trim() // Sanitize URL by removing whitespace
}
}

export const getRegionEndpoint = (region, service = 'contentManagement') => {
const regionData = regionHostMap.regions.find(r =>
r.id === region ||
r.alias.some(alias => alias === region)
)
if (!regionData) {
throw new Error(`Invalid region '${region}' provided. Allowed regions are: ${regionHostMap.regions.map(r => r.id).join(', ')}`)
}
return regionData.endpoints[service]?.replace(/^https?:\/\//, '')
}
Loading
Loading