Skip to content

Commit 89d98c7

Browse files
authored
Merge pull request #197 from contentstack/staging
Updated node version 22 support and fixed testcases (#195) (#196)
2 parents 76f7db7 + 0be13ff commit 89d98c7

15 files changed

+193
-153
lines changed

.github/workflows/npm-publish.yml

+2-2
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

+1-1
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

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## [v1.18.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.2) (2024-10-3)
3+
- Fix
4+
- Variants testcases Added
5+
- Node v22 support
26
## [v1.18.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.18.1) (2024-09-27)
37
- Fix
48
- Variants testcases Added

lib/stack/variantGroup/index.js

+18-17
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

+37-2
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

+37-2
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)