diff --git a/CHANGELOG.md b/CHANGELOG.md index 41175cf4..7052ece9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [v1.16.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-04-09) + - Feature + - Get languages of an entry ## [v1.15.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-03-28) - Fixes and Enhancement - delete stack implemetation and test cases diff --git a/lib/stack/contentType/entry/index.js b/lib/stack/contentType/entry/index.js index 8113a96f..de34aad3 100644 --- a/lib/stack/contentType/entry/index.js +++ b/lib/stack/contentType/entry/index.js @@ -243,6 +243,7 @@ export function Entry (http, data) { * client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').setWorkflowStage({ workflow_stage, locale: 'en-us'}) * .then((response) => console.log(response.notice)); */ + this.setWorkflowStage = async ({ workflow_stage, locale }) => { const publishDetails = { workflow: { workflow_stage } @@ -265,6 +266,35 @@ export function Entry (http, data) { throw error(err) } } + + /** + * @description The get locales request allows to get the languages of an entry. + * @memberof Entry + * @func locales + * @returns {Promise} Response Object. + * @example + * import * as contentstack from '@contentstack/management' + * const client = contentstack.client() + * + * client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').locales() + * .then((response) => console.log(response)); + */ + this.locales = async () => { + const headers = {} + if (this.stackHeaders) { + headers.headers = this.stackHeaders + } + try { + const response = await http.get(`${this.urlPath}/locales`, headers) + if (response.data) { + return response.data + } else { + throw error(response) + } + } catch (err) { + throw error(err) + } + } } else { /** * @description The Create an entry call creates a new entry for the selected content type. diff --git a/package-lock.json b/package-lock.json index b9484372..3d6b8925 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/management", - "version": "1.15.4", + "version": "1.16.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.15.4", + "version": "1.16.0", "license": "MIT", "dependencies": { "@slack/bolt": "^3.17.1", diff --git a/package.json b/package.json index c8ed9ca8..5cdfc447 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.15.4", + "version": "1.16.0", "description": "The Content Management API is used to manage the content of your Contentstack account", "main": "./dist/node/contentstack-management.js", "browser": "./dist/web/contentstack-management.js", diff --git a/test/sanity-check/api/entry-test.js b/test/sanity-check/api/entry-test.js index e22da61b..ef395cae 100644 --- a/test/sanity-check/api/entry-test.js +++ b/test/sanity-check/api/entry-test.js @@ -163,6 +163,18 @@ describe('Entry api Test', () => { .catch(done) }) + it('should get languages of the given Entry uid', done => { + makeEntry(singlepageCT.content_type.uid, entryUTD).locales() + .then((locale) => { + expect(locale.locales[0].code).to.be.equal('en-us') + locale.locales.forEach((locales) => { + expect(locales.code).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + it('should unpublish localized entry', done => { makeEntry(singlepageCT.content_type.uid, entryUTD) .unpublish({ publishDetails: { diff --git a/test/unit/entry-test.js b/test/unit/entry-test.js index 5515c2e0..6e739f1f 100644 --- a/test/unit/entry-test.js +++ b/test/unit/entry-test.js @@ -566,6 +566,38 @@ describe('Contentstack Entry test', () => { expect(result).to.deep.equal(expectedResult); done(); }) + + it('should get languages of the given Entry uid', done => { + var mock = new MockAdapter(Axios) + const locales = [ + { + code: 'en-us' + }, + { + code: 'hi-in' + }, + { + code: 'en-at', + localized: true + }, + { + code: 'ja-jp' + } + ] + mock.onGet('/content_types/content_type_uid/entries/UID/locales').reply(200, { + locales + }) + + makeEntry({ entry: { ...systemUidMock }, stackHeaders: stackHeadersMock }).locales() + .then((locale) => { + expect(locale.locales[0].code).to.be.equal('en-us') + locale.locales.forEach((locales) => { + expect(locales.code).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) }) function makeEntry (data) {