Skip to content

Commit 62c5962

Browse files
Merge branch 'development' into sanity/update-token-expiry
2 parents 7e7c15e + 0e5105b commit 62c5962

File tree

18 files changed

+1701
-2155
lines changed

18 files changed

+1701
-2155
lines changed

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-node@v3
1515
with:
16-
node-version: '20.x'
16+
node-version: '22.x'
1717
registry-url: 'https://registry.npmjs.org'
1818
- run: npm ci
1919
- run: npm publish
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v3
2626
- uses: actions/setup-node@v3
2727
with:
28-
node-version: '20.x'
28+
node-version: '22.x'
2929
registry-url: 'https://npm.pkg.github.com'
3030
scope: '@contentstack'
3131
- run: npm ci

.github/workflows/unit-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v2 # checkout the repo
1414
- uses: actions/setup-node@v3
1515
with:
16-
node-version: '20.x'
16+
node-version: '22.x'
1717
registry-url: 'https://registry.npmjs.org'
1818
- run: npm ci # install packages
1919
- run: npm run test:unit:report:json # run tests (configured to use jest-junit reporter)

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# Changelog
2+
## [v1.18.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.4) (2024-11-22)
3+
- Enhancement
4+
- Added support for response headers.
5+
## [v1.18.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.3) (2024-11-8)
6+
- Fix
7+
- Fixed incorrect input type for bulk delete operation
8+
## [v1.18.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.2) (2024-10-3)
9+
- Fix
10+
- Variants testcases Added
11+
- Node v22 support
212
## [v1.18.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.1) (2024-09-27)
313
- Fix
414
- Variants testcases Added

lib/contentstackCollection.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export default class ContentstackCollection {
77
if (stackHeaders) {
88
data.stackHeaders = stackHeaders
99
}
10+
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
11+
data.stackHeaders = {
12+
...data.stackHeaders,
13+
responseHeaders: response.headers,
14+
};
15+
}
1016
if (wrapperCollection) {
1117
this.items = wrapperCollection(http, data)
1218
}

lib/entity.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const create = ({ http, params }) => {
8484
try {
8585
const response = await http.post(this.urlPath, data, headers)
8686
if (response.data) {
87-
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
87+
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
8888
} else {
8989
if (response.status >= 200 && response.status < 300) {
9090
return {
@@ -152,7 +152,7 @@ export const update = (http, type, params = {}) => {
152152
}
153153
})
154154
if (response.data) {
155-
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
155+
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
156156
} else {
157157
throw error(response)
158158
}
@@ -211,7 +211,7 @@ export const fetch = (http, type, params = {}) => {
211211
response.data[type]['content_type'] = response.data['content_type']
212212
response.data[type]['schema'] = response.data['schema']
213213
}
214-
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
214+
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
215215
} else {
216216
throw error(response)
217217
}
@@ -242,7 +242,7 @@ export const fetchAll = (http, wrapperCollection, params = {}) => {
242242
}
243243
}
244244

245-
export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid) {
245+
export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid, http) {
246246
const data = response.data || {}
247247
if (stackHeaders) {
248248
data.stackHeaders = stackHeaders
@@ -253,6 +253,12 @@ export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid)
253253
if (taxonomy_uid) {
254254
data.taxonomy_uid = taxonomy_uid
255255
}
256+
if (http?.httpClientParams?.headers?.includeResHeaders === true) {
257+
data.stackHeaders = {
258+
...data.stackHeaders,
259+
responseHeaders: response.headers,
260+
};
261+
}
256262
return data
257263
}
258264

@@ -300,7 +306,7 @@ export const move = (http, type, force = false, params = {}) => {
300306
}
301307
const response = await http.put(`${this.urlPath}/move`, updateData, headers)
302308
if (response.data) {
303-
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
309+
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid, http))
304310
} else {
305311
throw error(response)
306312
}

lib/stack/variantGroup/index.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,6 @@ export function VariantGroup (http, data = {}) {
5959
*/
6060
this.delete = deleteEntity(http)
6161

62-
/**
63-
* @description The fetch VariantGroup call fetches VariantGroup details.
64-
* @memberof VariantGroup
65-
* @func fetch
66-
* @returns {Promise<VariantGroup.VariantGroup>} Promise for VariantGroup instance
67-
* @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.
68-
* @example
69-
* import * as contentstack from '@contentstack/management'
70-
* const client = contentstack.client()
71-
*
72-
* client.stack({ api_key: 'api_key'}).VariantGroup('variant_group_uid').fetch()
73-
* .then((variant_group) => console.log(variant_group))
74-
*
75-
*/
76-
// this.fetch = fetch(http, 'variant_group')
77-
7862
/**
7963
* @description Content type defines the structure or schema of a page or a section of your web or mobile property.
8064
* @param {String} uid The UID of the ContentType you want to get details.
@@ -115,7 +99,24 @@ export function VariantGroup (http, data = {}) {
11599
* client.stack().VariantGroup().create({ variant_group } )
116100
* .then((variant_group) => console.log(variant_group))
117101
*/
118-
this.create = create({ http: http })
102+
this.create = async (data) => {
103+
try {
104+
const response = await http.post(`${this.urlPath}`,
105+
data ,
106+
{
107+
headers: {
108+
...cloneDeep(this.stackHeaders)
109+
}
110+
})
111+
if (response.data) {
112+
return response.data
113+
} else {
114+
return error(response)
115+
}
116+
} catch (err) {
117+
return error(err)
118+
}
119+
}
119120

120121
/**
121122
* @description The Query on Variant Groups will allow to fetch details of all or specific Variant Groups

lib/stack/variantGroup/variants/index.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,25 @@ export function Variants(http, data = {}) {
6060
* .then((variants) => console.log(variants))
6161
*
6262
*/
63-
this.fetch = fetch(http, 'variants')
63+
this.fetch = async (param = {}) => {
64+
try {
65+
const headers = {
66+
headers: { ...cloneDeep(this.stackHeaders) },
67+
params: {
68+
...cloneDeep(param)
69+
}
70+
} || {}
71+
72+
const response = await http.get(this.urlPath, headers)
73+
if (response.data) {
74+
return response.data
75+
} else {
76+
throw error(response)
77+
}
78+
} catch (err) {
79+
error(err)
80+
}
81+
}
6482

6583
/**
6684
* @description The Delete Variant call is used to delete an existing Variant permanently from your Stack.
@@ -98,7 +116,24 @@ export function Variants(http, data = {}) {
98116
* client.stack().VariantGroup('variant_group_uid').variants().create({ data } )
99117
* .then((variants) => console.log(variants))
100118
*/
101-
this.create = create({ http: http })
119+
this.create = async (data) => {
120+
try {
121+
const response = await http.post(`${this.urlPath}`,
122+
data ,
123+
{
124+
headers: {
125+
...cloneDeep(this.stackHeaders)
126+
}
127+
})
128+
if (response.data) {
129+
return response.data
130+
} else {
131+
return error(response)
132+
}
133+
} catch (err) {
134+
return error(err)
135+
}
136+
}
102137

103138
/**
104139
* @description The Query on Variant Groups will allow to fetch details of all or specific Variant Groups

lib/stack/variants/index.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,25 @@ export function Variants (http, data) {
4444
* .then((variants) => console.log(variants))
4545
*
4646
*/
47-
this.fetch = fetch(http, 'variants')
47+
this.fetch = async (param = {}) => {
48+
try {
49+
const headers = {
50+
headers: { ...cloneDeep(this.stackHeaders) },
51+
params: {
52+
...cloneDeep(param)
53+
}
54+
} || {}
55+
56+
const response = await http.get(this.urlPath, headers)
57+
if (response.data) {
58+
return response.data
59+
} else {
60+
throw error(response)
61+
}
62+
} catch (err) {
63+
error(err)
64+
}
65+
}
4866
} else {
4967
/**
5068
* @description The Create an variants call creates a new variants.
@@ -68,7 +86,24 @@ export function Variants (http, data) {
6886
* client.stack().variants().create({ variants })
6987
* .then((variants) => console.log(variants))
7088
*/
71-
this.create = create({ http })
89+
this.create = async (data) => {
90+
try {
91+
const response = await http.post(`${this.urlPath}`,
92+
data ,
93+
{
94+
headers: {
95+
...cloneDeep(this.stackHeaders)
96+
}
97+
})
98+
if (response.data) {
99+
return response.data
100+
} else {
101+
return error(response)
102+
}
103+
} catch (err) {
104+
return error(err)
105+
}
106+
}
72107

73108
/**
74109
* @description The Query on Variants will allow to fetch details of all or specific Variants.

0 commit comments

Comments
 (0)