From 4cd56e50d2eafff6161dcffbb89a219b21c36324 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 3 Apr 2024 11:59:41 +0530 Subject: [PATCH 1/4] feat: :sparkles: get languages of an entry implementation --- lib/stack/contentType/entry/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/stack/contentType/entry/index.js b/lib/stack/contentType/entry/index.js index 8113a96f..8f70e128 100644 --- a/lib/stack/contentType/entry/index.js +++ b/lib/stack/contentType/entry/index.js @@ -265,6 +265,22 @@ export function Entry (http, data) { throw error(err) } } + 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. From b4355655f76889f2caaa4d37295fca5fc483c02e Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 3 Apr 2024 12:00:08 +0530 Subject: [PATCH 2/4] test: :white_check_mark: added unit and api test cases --- test/sanity-check/api/entry-test.js | 12 +++++++++++ test/unit/entry-test.js | 32 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) 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) { From df340b1979f4e002ec5fec9efc409ef3bb047279 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 3 Apr 2024 12:04:02 +0530 Subject: [PATCH 3/4] docs: :memo: added docs for get locales --- lib/stack/contentType/entry/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/stack/contentType/entry/index.js b/lib/stack/contentType/entry/index.js index 8f70e128..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,19 @@ 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) { From b9041d05f14b1ab55c1099650b833565d5ca1330 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Wed, 3 Apr 2024 12:11:29 +0530 Subject: [PATCH 4/4] chore: updated package version and changeLog --- CHANGELOG.md | 3 +++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) 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/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",