Skip to content

Commit

Permalink
Merge branch 'development' into sanity/update-token-expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Dec 11, 2024
2 parents 7e7c15e + 0e5105b commit 62c5962
Show file tree
Hide file tree
Showing 18 changed files with 1,701 additions and 2,155 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20.x'
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish
Expand All @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20.x'
node-version: '22.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@contentstack'
- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2 # checkout the repo
- uses: actions/setup-node@v3
with:
node-version: '20.x'
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci # install packages
- run: npm run test:unit:report:json # run tests (configured to use jest-junit reporter)
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Changelog
## [v1.18.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.4) (2024-11-22)
- Enhancement
- Added support for response headers.
## [v1.18.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.3) (2024-11-8)
- Fix
- Fixed incorrect input type for bulk delete operation
## [v1.18.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.2) (2024-10-3)
- Fix
- Variants testcases Added
- Node v22 support
## [v1.18.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.1) (2024-09-27)
- Fix
- Variants testcases Added
Expand Down
6 changes: 6 additions & 0 deletions lib/contentstackCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export default class ContentstackCollection {
if (stackHeaders) {
data.stackHeaders = stackHeaders
}
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
data.stackHeaders = {
...data.stackHeaders,
responseHeaders: response.headers,
};
}
if (wrapperCollection) {
this.items = wrapperCollection(http, data)
}
Expand Down
16 changes: 11 additions & 5 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const create = ({ http, params }) => {
try {
const response = await http.post(this.urlPath, data, headers)
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
} else {
if (response.status >= 200 && response.status < 300) {
return {
Expand Down Expand Up @@ -152,7 +152,7 @@ export const update = (http, type, params = {}) => {
}
})
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
} else {
throw error(response)
}
Expand Down Expand Up @@ -211,7 +211,7 @@ export const fetch = (http, type, params = {}) => {
response.data[type]['content_type'] = response.data['content_type']
response.data[type]['schema'] = response.data['schema']
}
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
} else {
throw error(response)
}
Expand Down Expand Up @@ -242,7 +242,7 @@ export const fetchAll = (http, wrapperCollection, params = {}) => {
}
}

export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid) {
export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid, http) {
const data = response.data || {}
if (stackHeaders) {
data.stackHeaders = stackHeaders
Expand All @@ -253,6 +253,12 @@ export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid)
if (taxonomy_uid) {
data.taxonomy_uid = taxonomy_uid
}
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
data.stackHeaders = {
...data.stackHeaders,
responseHeaders: response.headers,
};
}
return data
}

Expand Down Expand Up @@ -300,7 +306,7 @@ export const move = (http, type, force = false, params = {}) => {
}
const response = await http.put(`${this.urlPath}/move`, updateData, headers)
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
} else {
throw error(response)
}
Expand Down
35 changes: 18 additions & 17 deletions lib/stack/variantGroup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,6 @@ export function VariantGroup (http, data = {}) {
*/
this.delete = deleteEntity(http)

/**
* @description The fetch VariantGroup call fetches VariantGroup details.
* @memberof VariantGroup
* @func fetch
* @returns {Promise<VariantGroup.VariantGroup>} Promise for VariantGroup instance
* @param {Int} version Enter the unique ID of the content type of which you want to retrieve the details. The UID is generated based on the title of the content type. The unique ID of a content type is unique across a stack.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').fetch()
* .then((variant_group) => console.log(variant_group))
*
*/
// this.fetch = fetch(http, 'variant_group')

/**
* @description Content type defines the structure or schema of a page or a section of your web or mobile property.
* @param {String} uid The UID of the ContentType you want to get details.
Expand Down Expand Up @@ -115,7 +99,24 @@ export function VariantGroup (http, data = {}) {
* client.stack().VariantGroup().create({ variant_group } )
* .then((variant_group) => console.log(variant_group))
*/
this.create = create({ http: http })
this.create = async (data) => {
try {
const response = await http.post(`${this.urlPath}`,
data ,
{
headers: {
...cloneDeep(this.stackHeaders)
}
})
if (response.data) {
return response.data
} else {
return error(response)
}
} catch (err) {
return error(err)
}
}

/**
* @description The Query on Variant Groups will allow to fetch details of all or specific Variant Groups
Expand Down
39 changes: 37 additions & 2 deletions lib/stack/variantGroup/variants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,25 @@ export function Variants(http, data = {}) {
* .then((variants) => console.log(variants))
*
*/
this.fetch = fetch(http, 'variants')
this.fetch = async (param = {}) => {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) },
params: {
...cloneDeep(param)
}
} || {}

const response = await http.get(this.urlPath, headers)
if (response.data) {
return response.data
} else {
throw error(response)
}
} catch (err) {
error(err)
}
}

/**
* @description The Delete Variant call is used to delete an existing Variant permanently from your Stack.
Expand Down Expand Up @@ -98,7 +116,24 @@ export function Variants(http, data = {}) {
* client.stack().VariantGroup('variant_group_uid').variants().create({ data } )
* .then((variants) => console.log(variants))
*/
this.create = create({ http: http })
this.create = async (data) => {
try {
const response = await http.post(`${this.urlPath}`,
data ,
{
headers: {
...cloneDeep(this.stackHeaders)
}
})
if (response.data) {
return response.data
} else {
return error(response)
}
} catch (err) {
return error(err)
}
}

/**
* @description The Query on Variant Groups will allow to fetch details of all or specific Variant Groups
Expand Down
39 changes: 37 additions & 2 deletions lib/stack/variants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,25 @@ export function Variants (http, data) {
* .then((variants) => console.log(variants))
*
*/
this.fetch = fetch(http, 'variants')
this.fetch = async (param = {}) => {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) },
params: {
...cloneDeep(param)
}
} || {}

const response = await http.get(this.urlPath, headers)
if (response.data) {
return response.data
} else {
throw error(response)
}
} catch (err) {
error(err)
}
}
} else {
/**
* @description The Create an variants call creates a new variants.
Expand All @@ -68,7 +86,24 @@ export function Variants (http, data) {
* client.stack().variants().create({ variants })
* .then((variants) => console.log(variants))
*/
this.create = create({ http })
this.create = async (data) => {
try {
const response = await http.post(`${this.urlPath}`,
data ,
{
headers: {
...cloneDeep(this.stackHeaders)
}
})
if (response.data) {
return response.data
} else {
return error(response)
}
} catch (err) {
return error(err)
}
}

/**
* @description The Query on Variants will allow to fetch details of all or specific Variants.
Expand Down
Loading

0 comments on commit 62c5962

Please sign in to comment.