Skip to content

Feat/cs 44220 variants support #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Change log

### Version: 3.20.0
#### Date: March-12-2024
##### New Features:
- Variants Feature support added

### Version: 3.19.1
#### Date: March-06-2024
##### Dependency:
Expand Down
3,539 changes: 1,777 additions & 1,762 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.19.1",
"version": "3.20.0",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down
18 changes: 18 additions & 0 deletions src/core/modules/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,22 @@ export default class Entry {
if (this.fetchOptions.debug) this.fetchOptions.logHandler('error', "Kindly provide an entry uid. e.g. .Entry('asset_uid')");
}
}

/**
* @method Variants
* @memberOf Entry
* @param {String} uid - uid of the variants entry
* @description An initializer is responsible for creating Variants Entry object
* @returns {Variants}
* @instance
*/
Variants(variant_headers) {
if (Array.isArray(variant_headers) && variant_headers.length > 0) {
this.headers['x-cs-variant-uid'] = variant_headers.join(',')
}else{
this.headers['x-cs-variant-uid'] = variant_headers;
}
return this;
}

}
16 changes: 16 additions & 0 deletions src/core/modules/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,4 +828,20 @@ export default class Query extends Entry {
return Utils.sendRequest(Utils.mergeDeep({}, this), options);
}

/**
* @method Variants
* @memberOf Query
* @param {String} uid - uid of the variants entry
* @description An initializer is responsible for creating Variants Entry object
* @returns {Variants}
* @instance
*/
Variants(variant_headers) {
if (Array.isArray(variant_headers) && variant_headers.length > 0) {
this.headers['x-cs-variant-uid'] = variant_headers.join(',')
}else{
this.headers['x-cs-variant-uid'] = variant_headers;
}
return this;
}
}
18 changes: 17 additions & 1 deletion test/entry/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -1658,4 +1658,20 @@ test('CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding
assert.fail("CT Taxonomies Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)");
assert.end();
})
})
})

test('Variants in entry', function (t) {
let Query = Stack.ContentType('source').Query();
Query
.Variants('variant_entry_1', 'variant_entry_2')
.toJSON()
.find()
.then(entries => {
assert.ok(entries[0].length, 'Variant entries present in the resultset');
assert.end();
}, err => {
console.error("error :", err);
assert.fail("Variant Entries are not present in the CT");
assert.end();
})
});