Skip to content
Closed
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
17 changes: 10 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# Changelog

## [v1.4.1](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.4.1) (2024-12-24)
## [v1.4.2](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.4.2) (2026-01-12)
- Enhancement: Improved error messages

## [v1.4.1](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.4.1) (2026-01-05)
- Fix: Security issues

## [v1.4.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.4.0) (2024-08-25)
## [v1.4.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.4.0) (2025-08-25)
- Enhancement: Retry logic to make use of x-ratelimit-remaining header

## [v1.3.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.3.0) (2024-08-11)
## [v1.3.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.3.0) (2025-08-11)
- Enh: Add search function to query apps by names

## [v1.2.9](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.9) (2024-08-04)
## [v1.2.9](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.9) (2025-08-04)
- Fix: Fixed the Linting issues
- Updated all the dependency to the latest version
- Added Pre-commit hook to run the snyk and talismand scans

## [v1.2.8](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.8) (2024-05-26)
## [v1.2.8](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.8) (2025-05-26)

- Fix: Added params support to getInstalledApps method for enhanced flexibility

## [v1.2.7](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.7) (2024-05-15)
## [v1.2.7](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.7) (2025-05-15)
- Fixed base URL path logic in contentstackClient to handle when region and host not provided

## [v1.2.6](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.6) (2024-03-03)
## [v1.2.6](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.6) (2025-03-03)
- Update sanity tests

## [v1.2.5](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.5) (2025-01-17)
Expand Down
229 changes: 229 additions & 0 deletions lib/assets/regions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
{
"regions": [
{
"id": "na",
"name": "AWS North America",
"cloudProvider": "AWS",
"location": "North America",
"alias": [
"na",
"us",
"aws-na",
"aws_na",
"NA",
"US",
"AWS-NA",
"AWS_NA"
],
"isDefault": true,
"endpoints": {
"application": "https://app.contentstack.com",
"contentDelivery": "https://cdn.contentstack.io",
"contentManagement": "https://api.contentstack.io",
"auth": "https://auth-api.contentstack.com",
"graphqlDelivery": "https://graphql.contentstack.com",
"preview": "https://rest-preview.contentstack.com",
"graphqlPreview": "https://graphql-preview.contentstack.com",
"images": "https://images.contentstack.io",
"assets": "https://assets.contentstack.io",
"automate": "https://automations-api.contentstack.com",
"launch": "https://launch-api.contentstack.com",
"developerHub": "https://developerhub-api.contentstack.com",
"brandKit": "https://brand-kits-api.contentstack.com",
"genAI": "https://ai.contentstack.com/brand-kits",
"personalizeManagement": "https://personalize-api.contentstack.com",
"personalizeEdge": "https://personalize-edge.contentstack.com"
}
},
{
"id": "eu",
"name": "AWS Europe",
"cloudProvider": "AWS",
"location": "Europe",
"alias": [
"eu",
"aws-eu",
"aws_eu",
"EU",
"AWS-EU",
"AWS_EU"
],
"isDefault": false,
"endpoints": {
"application": "https://eu-app.contentstack.com",
"contentDelivery": "https://eu-cdn.contentstack.com",
"contentManagement": "https://eu-api.contentstack.com",
"auth": "https://eu-auth-api.contentstack.com",
"graphqlDelivery": "https://eu-graphql.contentstack.com",
"preview": "https://eu-rest-preview.contentstack.com",
"graphqlPreview": "https://eu-graphql-preview.contentstack.com",
"images": "https://eu-images.contentstack.com",
"assets": "https://eu-assets.contentstack.com",
"automate": "https://eu-prod-automations-api.contentstack.com",
"launch": "https://eu-launch-api.contentstack.com",
"developerHub": "https://eu-developerhub-api.contentstack.com",
"brandKit": "https://eu-brand-kits-api.contentstack.com",
"genAI": "https://eu-ai.contentstack.com/brand-kits",
"personalizeManagement": "https://eu-personalize-api.contentstack.com",
"personalizeEdge": "https://eu-personalize-edge.contentstack.com"
}
},
{
"id": "au",
"name": "AWS Australia",
"cloudProvider": "AWS",
"location": "Australia",
"alias": [
"au",
"aws-au",
"aws_au",
"AU",
"AWS-AU",
"AWS_AU"
],
"isDefault": false,
"endpoints": {
"application": "https://au-app.contentstack.com",
"contentDelivery": "https://au-cdn.contentstack.com",
"contentManagement": "https://au-api.contentstack.com",
"auth": "https://au-auth-api.contentstack.com",
"graphqlDelivery": "https://au-graphql.contentstack.com",
"preview": "https://au-rest-preview.contentstack.com",
"graphqlPreview": "https://au-graphql-preview.contentstack.com",
"images": "https://au-images.contentstack.com",
"assets": "https://au-assets.contentstack.com",
"automate": "https://au-prod-automations-api.contentstack.com",
"launch": "https://au-launch-api.contentstack.com",
"developerHub": "https://au-developerhub-api.contentstack.com",
"brandKit": "https://au-brand-kits-api.contentstack.com",
"genAI": "https://au-ai.contentstack.com/brand-kits",
"personalizeManagement": "https://au-personalize-api.contentstack.com",
"personalizeEdge": "https://au-personalize-edge.contentstack.com"
}
},
{
"id": "azure-na",
"name": "Azure North America",
"cloudProvider": "Azure",
"location": "North America",
"alias": [
"azure-na",
"azure_na",
"AZURE-NA",
"AZURE_NA"
],
"isDefault": false,
"endpoints": {
"application": "https://azure-na-app.contentstack.com",
"contentDelivery": "https://azure-na-cdn.contentstack.com",
"contentManagement": "https://azure-na-api.contentstack.com",
"auth": "https://azure-na-auth-api.contentstack.com",
"graphqlDelivery": "https://azure-na-graphql.contentstack.com",
"preview": "https://azure-na-rest-preview.contentstack.com",
"graphqlPreview": "https://azure-na-graphql-preview.contentstack.com",
"images": "https://azure-na-images.contentstack.com",
"assets": "https://azure-na-assets.contentstack.com",
"automate": "https://azure-na-automations-api.contentstack.com",
"launch": "https://azure-na-launch-api.contentstack.com",
"developerHub": "https://azure-na-developerhub-api.contentstack.com",
"brandKit": "https://azure-na-brand-kits-api.contentstack.com",
"genAI": "https://azure-na-ai.contentstack.com/brand-kits",
"personalizeManagement": "https://azure-na-personalize-api.contentstack.com",
"personalizeEdge": "https://azure-na-personalize-edge.contentstack.com"
}
},
{
"id": "azure-eu",
"name": "Azure Europe",
"cloudProvider": "Azure",
"location": "Europe",
"alias": [
"azure-eu",
"azure_eu",
"AZURE-EU",
"AZURE_EU"
],
"isDefault": false,
"endpoints": {
"application": "https://azure-eu-app.contentstack.com",
"contentDelivery": "https://azure-eu-cdn.contentstack.com",
"contentManagement": "https://azure-eu-api.contentstack.com",
"auth": "https://azure-eu-auth-api.contentstack.com",
"graphqlDelivery": "https://azure-eu-graphql.contentstack.com",
"preview": "https://azure-eu-rest-preview.contentstack.com",
"graphqlPreview": "https://azure-eu-graphql-preview.contentstack.com",
"images": "https://azure-eu-images.contentstack.com",
"assets": "https://azure-eu-assets.contentstack.com",
"automate": "https://azure-eu-automations-api.contentstack.com",
"launch": "https://azure-eu-launch-api.contentstack.com",
"developerHub": "https://azure-eu-developerhub-api.contentstack.com",
"brandKit": "https://azure-eu-brand-kits-api.contentstack.com",
"genAI": "https://azure-eu-ai.contentstack.com/brand-kits",
"personalizeManagement": "https://azure-eu-personalize-api.contentstack.com",
"personalizeEdge": "https://azure-eu-personalize-edge.contentstack.com"
}
},
{
"id": "gcp-na",
"name": "GCP North America",
"cloudProvider": "GCP",
"location": "North America",
"alias": [
"gcp-na",
"gcp_na",
"GCP-NA",
"GCP_NA"
],
"isDefault": false,
"endpoints": {
"application": "https://gcp-na-app.contentstack.com",
"contentDelivery": "https://gcp-na-cdn.contentstack.com",
"contentManagement": "https://gcp-na-api.contentstack.com",
"auth": "https://gcp-na-auth-api.contentstack.com",
"graphqlDelivery": "https://gcp-na-graphql.contentstack.com",
"preview": "https://gcp-na-rest-preview.contentstack.com",
"graphqlPreview": "https://gcp-na-graphql-preview.contentstack.com",
"images": "https://gcp-na-images.contentstack.com",
"assets": "https://gcp-na-assets.contentstack.com",
"automate": "https://gcp-na-automations-api.contentstack.com",
"launch": "https://gcp-na-launch-api.contentstack.com",
"developerHub": "https://gcp-na-developerhub-api.contentstack.com",
"brandKit": "https://gcp-na-brand-kits-api.contentstack.com",
"genAI": "https://gcp-na-ai.contentstack.com/brand-kits",
"personalizeManagement": "https://gcp-na-personalize-api.contentstack.com",
"personalizeEdge": "https://gcp-na-personalize-edge.contentstack.com"
}
},
{
"id": "gcp-eu",
"name": "GCP Europe",
"cloudProvider": "GCP",
"location": "Europe",
"alias": [
"gcp-eu",
"gcp_eu",
"GCP-EU",
"GCP_EU"
],
"isDefault": false,
"endpoints": {
"application": "https://gcp-eu-app.contentstack.com",
"contentDelivery": "https://gcp-eu-cdn.contentstack.com",
"contentManagement": "https://gcp-eu-api.contentstack.com",
"auth": "https://gcp-eu-auth-api.contentstack.com",
"graphqlDelivery": "https://gcp-eu-graphql.contentstack.com",
"preview": "https://gcp-eu-rest-preview.contentstack.com",
"graphqlPreview": "https://gcp-eu-graphql-preview.contentstack.com",
"images": "https://gcp-eu-images.contentstack.com",
"assets": "https://gcp-eu-assets.contentstack.com",
"automate": "https://gcp-eu-automations-api.contentstack.com",
"launch": "https://gcp-eu-launch-api.contentstack.com",
"developerHub": "https://gcp-eu-developerhub-api.contentstack.com",
"brandKit": "https://gcp-eu-brand-kits-api.contentstack.com",
"genAI": "https://gcp-eu-ai.contentstack.com/brand-kits",
"personalizeManagement": "https://gcp-eu-personalize-api.contentstack.com",
"personalizeEdge": "https://gcp-eu-personalize-edge.contentstack.com"
}
}
]
}
15 changes: 5 additions & 10 deletions lib/contentstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import packages from '../package.json'
import clonedeep from 'lodash/cloneDeep'
import getUserAgent from './core/Util.js'
import getUserAgent, { getRegionEndpoint } from './core/Util.js'
import contentstackClient from './contentstackClient.js'
import httpClient from './core/contentstackHTTPClient.js'
import Region from './core/region.js'
Expand Down Expand Up @@ -111,14 +111,8 @@ import Region from './core/region.js'
* @prop {function=} params.logHandler - A log handler function to process given log messages & errors.
* @example //Set the `logHandler`
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ logHandler: (level, data) => {
if (level === 'error' && data) {
const title = [data.name, data.message].filter((a) => a).join(' - ')
console.error(`[error] ${title}`)
return
}
console.log(`[${level}] ${data}`)
} })
* import { logHandler } from '@contentstack/management/core/messageHandler'
* const client = contentstack.client({ logHandler: logHandler })
*
* @prop {function=} params.refreshToken - Optional function used to refresh token.
* @example // OAuth example
Expand Down Expand Up @@ -157,8 +151,9 @@ import Region from './core/region.js'
* @returns Contentstack.Client
*/
function client (params = {}) {
const devHubHost = params.region ? getRegionEndpoint(params.region.toLowerCase(), 'developerHub') : getRegionEndpoint("na", 'developerHub')
const defaultParameter = {
defaultHostName: 'developerhub-api.contentstack.com'
defaultHostName: devHubHost
}

const sdkAgent = `contentstack-marketplace-sdk/${packages.version}`
Expand Down
17 changes: 9 additions & 8 deletions lib/contentstackClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import error from './core/contentstackError'
import { Marketplace } from './marketplace/index.js'
import { Region } from './contentstack.js'
import { MESSAGES } from './core/messageHandler.js'

export default function contentstackClient ({ http }) {
/**
Expand All @@ -20,8 +21,8 @@ export default function contentstackClient ({ http }) {
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.login({ email: <emailid>, password: <password> })
* .then(() => console.log('Logged in successfully'))
* client.login({ email: <emailid>, password: <password> })
* .then(() => console.log(MESSAGES.LOGIN_SUCCESS))
*
* client.marketplace()
*/
Expand Down Expand Up @@ -59,8 +60,8 @@ export default function contentstackClient ({ http }) {
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization().findAll()
* .then((organization) => console.log(organization))
* client.organization().findAll()
* .then((organization) => console.log(MESSAGES.ORGANIZATION_LOADED))
*
* @example
* import * as contentstack from '@contentstack/management'
Expand All @@ -84,14 +85,14 @@ export default function contentstackClient ({ http }) {
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.logout()
* .then((response) => console.log(response))
* client.logout()
* .then((response) => console.log(MESSAGES.API_RESPONSE_SUCCESS))
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.logout('AUTHTOKEN')
* .then((response) => console.log(response))
* client.logout('AUTHTOKEN')
* .then((response) => console.log(MESSAGES.API_RESPONSE_SUCCESS))
* */
function logout (authtoken) {
http.defaults.versioningStrategy = 'path'
Expand Down
14 changes: 14 additions & 0 deletions lib/core/Util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { platform, release } from 'os'
import regionHostMap from '../assets/regions.json'


const HOST_REGEX = /^(?!\w+:\/\/)([\w-:]+\.)+([\w-:]+)(?::(\d+))?(?!:)$/

export function isHost (host) {
Expand Down Expand Up @@ -100,3 +103,14 @@ export default function getUserAgent (sdk, application, integration, feature) {

return `${headerParts.filter((item) => item !== '').join('; ')};`
}

export const getRegionEndpoint = (region, service = 'developerHub') => {
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