diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f9a476a..9f0f6790 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
## Change log
+### Version: 3.21.0
+#### Date: September-09-2024
+##### Fix:
+ - Feat Variants support added
+
+### Version: 3.20.4
+#### Date: August-14-2024
+##### Fix:
+ - Fix file upload function in sanity report file
### Version: 3.20.3
#### Date: August-02-2024
diff --git a/README.md b/README.md
index 1defa8cb..7021fa05 100755
--- a/README.md
+++ b/README.md
@@ -19,11 +19,11 @@ For browsers, we recommend to download the library via npm or yarn to ensure 100
If you'd like to use a standalone built file you can use the following script tag or download it from [jsDelivr](https://www.jsdelivr.com/package/npm/contentstack), under the `dist` directory:
```html
-
+
```
You can also specify a specific version number.
```html
-
+
```
To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.
diff --git a/index.d.ts b/index.d.ts
index f9a1b78d..73132162 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -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;
}
diff --git a/package-lock.json b/package-lock.json
index ae9debb3..8075e335 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,20 +1,20 @@
{
"name": "contentstack",
- "version": "3.20.3",
+ "version": "3.21.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "contentstack",
- "version": "3.20.3",
+ "version": "3.21.0",
"license": "MIT",
"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"
},
"devDependencies": {
"@babel/core": "^7.23.3",
@@ -4239,20 +4239,24 @@
}
},
"node_modules/cheerio": {
- "version": "1.0.0-rc.12",
- "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz",
- "integrity": "sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==",
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0.tgz",
+ "integrity": "sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==",
"dependencies": {
"cheerio-select": "^2.1.0",
"dom-serializer": "^2.0.0",
"domhandler": "^5.0.3",
- "domutils": "^3.0.1",
- "htmlparser2": "^8.0.1",
- "parse5": "^7.0.0",
- "parse5-htmlparser2-tree-adapter": "^7.0.0"
+ "domutils": "^3.1.0",
+ "encoding-sniffer": "^0.2.0",
+ "htmlparser2": "^9.1.0",
+ "parse5": "^7.1.2",
+ "parse5-htmlparser2-tree-adapter": "^7.0.0",
+ "parse5-parser-stream": "^7.1.2",
+ "undici": "^6.19.5",
+ "whatwg-mimetype": "^4.0.0"
},
"engines": {
- "node": ">= 6"
+ "node": ">=18.17"
},
"funding": {
"url": "https://github.com/cheeriojs/cheerio?sponsor=1"
@@ -4399,9 +4403,9 @@
}
},
"node_modules/cheerio/node_modules/htmlparser2": {
- "version": "8.0.2",
- "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.2.tgz",
- "integrity": "sha512-GYdjWKDkbRLkZ5geuHs5NY1puJ+PXwP7+fHPRz06Eirsb9ugf6d8kkXav6ADhcODhFFPMIXyxkxSuMf3D6NCFA==",
+ "version": "9.1.0",
+ "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz",
+ "integrity": "sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==",
"funding": [
"https://github.com/fb55/htmlparser2?sponsor=1",
{
@@ -4412,8 +4416,8 @@
"dependencies": {
"domelementtype": "^2.3.0",
"domhandler": "^5.0.3",
- "domutils": "^3.0.1",
- "entities": "^4.4.0"
+ "domutils": "^3.1.0",
+ "entities": "^4.5.0"
}
},
"node_modules/chrome-trace-event": {
@@ -5235,6 +5239,29 @@
"node": ">= 0.8"
}
},
+ "node_modules/encoding-sniffer": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/encoding-sniffer/-/encoding-sniffer-0.2.0.tgz",
+ "integrity": "sha512-ju7Wq1kg04I3HtiYIOrUrdfdDvkyO9s5XM8QAj/bN61Yo/Vb4vgJxy5vi4Yxk01gWHbrofpPtpxM8bKger9jhg==",
+ "dependencies": {
+ "iconv-lite": "^0.6.3",
+ "whatwg-encoding": "^3.1.1"
+ },
+ "funding": {
+ "url": "https://github.com/fb55/encoding-sniffer?sponsor=1"
+ }
+ },
+ "node_modules/encoding-sniffer/node_modules/iconv-lite": {
+ "version": "0.6.3",
+ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
+ "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
+ "dependencies": {
+ "safer-buffer": ">= 2.1.2 < 3.0.0"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
"node_modules/enhanced-resolve": {
"version": "5.15.0",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz",
@@ -10047,6 +10074,17 @@
"url": "https://github.com/fb55/domhandler?sponsor=1"
}
},
+ "node_modules/parse5-parser-stream": {
+ "version": "7.1.2",
+ "resolved": "https://registry.npmjs.org/parse5-parser-stream/-/parse5-parser-stream-7.1.2.tgz",
+ "integrity": "sha512-JyeQc9iwFLn5TbvvqACIF/VXG6abODeB3Fwmv/TGdLk2LfbWkaySGY72at4+Ty7EkPZj854u4CrICqNk2qIbow==",
+ "dependencies": {
+ "parse5": "^7.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/inikulin/parse5?sponsor=1"
+ }
+ },
"node_modules/parse5/node_modules/entities": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
@@ -10410,9 +10448,9 @@
}
},
"node_modules/qs": {
- "version": "6.12.1",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.1.tgz",
- "integrity": "sha512-zWmv4RSuB9r2mYQw3zxQuHWeU+42aKi1wWig/j4ele4ygELZ7PEO6MM7rim9oAQH2A5MWfsAVf/jPvTPgCbvUQ==",
+ "version": "6.13.0",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
+ "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
"dependencies": {
"side-channel": "^1.0.6"
},
@@ -10807,8 +10845,7 @@
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
- "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
- "dev": true
+ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/schema-utils": {
"version": "4.2.0",
@@ -12063,6 +12100,14 @@
"integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==",
"dev": true
},
+ "node_modules/undici": {
+ "version": "6.19.8",
+ "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz",
+ "integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==",
+ "engines": {
+ "node": ">=18.17"
+ }
+ },
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
@@ -12424,11 +12469,41 @@
"url": "https://opencollective.com/webpack"
}
},
+ "node_modules/whatwg-encoding": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz",
+ "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==",
+ "dependencies": {
+ "iconv-lite": "0.6.3"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/whatwg-encoding/node_modules/iconv-lite": {
+ "version": "0.6.3",
+ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
+ "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
+ "dependencies": {
+ "safer-buffer": ">= 2.1.2 < 3.0.0"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
"node_modules/whatwg-fetch": {
"version": "3.6.19",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.19.tgz",
"integrity": "sha512-d67JP4dHSbm2TrpFj8AbO8DnL1JXL5J9u0Kq2xW6d0TFDbCA3Muhdt8orXC22utleTVj7Prqt82baN6RBvnEgw=="
},
+ "node_modules/whatwg-mimetype": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz",
+ "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==",
+ "engines": {
+ "node": ">=18"
+ }
+ },
"node_modules/whatwg-url": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-6.5.0.tgz",
diff --git a/package.json b/package.json
index 997508a3..c2393258 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "contentstack",
- "version": "3.20.3",
+ "version": "3.21.0",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
@@ -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"
}
}
diff --git a/sanity-report.js b/sanity-report.js
index 020b5801..6189bf9a 100644
--- a/sanity-report.js
+++ b/sanity-report.js
@@ -50,9 +50,9 @@ async function publishMessage (text, report) {
channel: process.env.SLACK_CHANNEL,
text: text
})
- await app.client.files.upload({
+ await app.client.files.uploadV2({
token: process.env.SLACK_BOT_TOKEN,
- channels: process.env.SLACK_CHANNEL,
+ channel_id: process.env.SLACK_CHANNEL_ID,
initial_comment: '*Here is the report generated*',
filetype: 'html',
filename: 'tap-html.html',
diff --git a/src/core/lib/request.js b/src/core/lib/request.js
index ac77555d..239c0048 100755
--- a/src/core/lib/request.js
+++ b/src/core/lib/request.js
@@ -9,28 +9,25 @@ export default function Request(stack, fetchOptions) {
let requestParams = stack.requestParams;
return new Promise(function(resolve, reject) {
let queryParams;
- let serialize = function(obj, prefix) {
-
- let str = [],
- p;
- if (typeof obj === "object" && obj.length !== undefined) {
- for (var i = 0, _i = obj.length; i < _i; i++) {
- str.push(prefix + '[]=' + obj[i]);
- }
- } else {
- for (const p in obj) {
- let k = prefix ? prefix + "[" + p + "]" : p,
- v = obj[p];
- str.push((v !== null && typeof v === "object" && p !== 'query') ?
- serialize(v, k) :
- k + "=" + encodeURIComponent(p !== 'query' ? v : JSON.stringify(v)));
- }
+
+ const params = new URLSearchParams();
+ let serialize = function (obj, prefix) {
+ if (typeof obj === 'object' && obj.length !== undefined) {
+ for (let i = 0, _i = obj.length; i < _i; i++) {
+ params.append(prefix + '[]', obj[i]);
+ }
+ } else {
+ for (const p in obj) {
+ let k = prefix ? prefix + '[' + p + ']' : p,
+ v = obj[p];
+ v !== null && typeof v === 'object' && p !== 'query'
+ ? serialize(v, k)
+ : params.append(k, p !== 'query' ? v : JSON.stringify(v));
}
- return str.join("&");
+ }
+ return params.toString();
};
-
-
// setting headers
requestParams.headers['Content-Type'] = 'application/json; charset=UTF-8';
requestParams.headers['X-User-Agent'] = 'contentstack-delivery-javascript-{{PLATFORM}}/' + version;
diff --git a/src/core/modules/entry.js b/src/core/modules/entry.js
index 6c5ecf49..644402e0 100755
--- a/src/core/modules/entry.js
+++ b/src/core/modules/entry.js
@@ -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
diff --git a/src/core/modules/query.js b/src/core/modules/query.js
index 434bcfa6..7194d51a 100755
--- a/src/core/modules/query.js
+++ b/src/core/modules/query.js
@@ -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
diff --git a/test/entry/find.js b/test/entry/find.js
index f7abb5b6..e6da6394 100755
--- a/test/entry/find.js
+++ b/test/entry/find.js
@@ -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();
})
-})
\ No newline at end of file
+})
+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();
+ })
+});
\ No newline at end of file
diff --git a/test/typescript/entry-query.test.ts b/test/typescript/entry-query.test.ts
index 3dbc494f..034abd0a 100644
--- a/test/typescript/entry-query.test.ts
+++ b/test/typescript/entry-query.test.ts
@@ -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());
});
@@ -466,4 +471,4 @@ function makeEntryQuery() {
function makeTaxonomyQuery() {
return stack.Taxonomies()
-}
\ No newline at end of file
+}