Skip to content

Added variants support #211

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

Merged
merged 8 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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.21.0
#### Date: September-09-2024
##### Fix:
- Feat Variants support added

### Version: 3.20.4
#### Date: August-14-2024
##### Fix:
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class Entry {
includeOwner(): this;
toJSON(): this;
addParam(key: string, value: any): this;
variants(variant_headers: string | string[]): this;
fetch(fetchOptions?: object): Promise<any>;
}

Expand Down
119 changes: 97 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.20.5",
"version": "3.21.0",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down Expand Up @@ -100,10 +100,10 @@
},
"dependencies": {
"@contentstack/utils": "^1.3.10",
"cheerio": "^1.0.0-rc.12",
"cheerio": "^1.0.0",
"es6-promise": "^4.1.1",
"isomorphic-fetch": "^3.0.0",
"localStorage": "1.0.4",
"qs": "^6.12.1"
"qs": "^6.12.3"
}
}
16 changes: 16 additions & 0 deletions src/core/modules/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,22 @@ export default class Entry {
}
}

/**
* @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;
}

/**
* @method fetch
Expand Down
16 changes: 16 additions & 0 deletions src/core/modules/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,22 @@ export default class Query extends Entry {
var options = Utils.mergeDeep(this.fetchOptions, fetchOptions);
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;
}

/**
* @method findOne
Expand Down
17 changes: 16 additions & 1 deletion test/entry/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -1658,4 +1658,19 @@ 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();
})
});
7 changes: 6 additions & 1 deletion test/typescript/entry-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ describe('Entry Query Test', () => {
done();
});

test('Variants Query: Get variant Entries', done => {
makeEntryQuery().variants(['variantEntryUid1', 'variantEntryUid2']).find().then((response) => done()).catch((error) => done());
done();
});

test('Taxonomy find test', done => {
makeTaxonomyQuery().find().then((response) => done()).catch((error) => done());
});
Expand All @@ -466,4 +471,4 @@ function makeEntryQuery() {

function makeTaxonomyQuery() {
return stack.Taxonomies()
}
}
Loading