Skip to content

Commit

Permalink
Merge pull request #197 from contentstack/staging
Browse files Browse the repository at this point in the history
Updated node version 22 support and fixed testcases (#195) (#196)
  • Loading branch information
cs-raj authored Oct 7, 2024
2 parents ebd95f3 + fc215bd commit f584d37
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 153 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## [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
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 f584d37

Please sign in to comment.