Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions lib/stack/contentType/entry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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<Object>} 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.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 12 additions & 0 deletions test/sanity-check/api/entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
18 changes: 17 additions & 1 deletion test/typescript/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function getEntries(stack: Stack) {
})

test('Fetch Entry', done => {
stack.contentType(singlepageCT.content_type.uid).entry(entryUTD)
stack.contentType('product').entry('blt7d6fae845bfc55d4')
.fetch({include_content_type: true})
.then((response) => {
expect(response.uid).to.be.not.equal(null)
Expand Down Expand Up @@ -132,6 +132,22 @@ export function getEntries(stack: Stack) {
})
}

export function getEntryLocales(stack: Stack) {
describe('Entry get', () => {
test('to get locales of an entry', done => {
stack.contentType(singlepageCT.content_type.uid).entry(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)
})
})
}

export function publishUnpublishEntry(stack: Stack) {
describe('Unpublish/Publish Entry', () => {
test('Publish Entry', done => {
Expand Down
3 changes: 2 additions & 1 deletion test/typescript/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { organization, organizations } from './organization';
import * as dotenv from 'dotenv'
import { shareStack, stacks, stackTest, unshareStack } from './stack';
import { contentType, createContentType, queryContentType } from './contentType';
import { createEntry, getEntries, importEntry, publishUnpublishEntry } from './entry';
import { createEntry, getEntries, importEntry, publishUnpublishEntry, getEntryLocales } from './entry';
import { createAsset, deleteAsset, downloadAsset, getAssets, publishUnpublishAsset, queryOnAsset, replaceAsset } from './asset';
import { createGlobalField, globalField, queryGlobalField } from './globalField';
import { createBranch, deleteBranch, queryBranch } from './branch';
Expand Down Expand Up @@ -103,6 +103,7 @@ describe('Typescript API test', () => {

createEntry(stack)
getEntries(stack)
getEntryLocales(stack)
publishUnpublishEntry(stack)
importEntry(stack)

Expand Down
32 changes: 32 additions & 0 deletions test/unit/entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions types/stack/contentType/entry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Unpublishable } from "../../utility/unpublish";

export interface Entry extends Publishable, Unpublishable, SystemFields, SystemFunction<Entry> {
setWorkflowStage(data: { workflow_stage: WorkflowStage, locale?:string}): Promise<Response>
locales(): Promise<Locales>
}

export interface Entries extends Queryable<Entry, {entry: EntryData}> {
Expand All @@ -25,4 +26,13 @@ export interface WorkflowStage extends AnyProperty {
notify?: boolean
assign_to?: Array<any>
assigned_by_roles?: Array<any>
}

export interface Locales {
locales: Code[];
}

export interface Code extends AnyProperty {
code: string;
localized: boolean;
}