Skip to content

Commit 1293e50

Browse files
Merge pull request #254 from contentstack/feat/dx-2040-entry-reference
Added support for fetching entry references
2 parents 6edd839 + 725273c commit 1293e50

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [v1.19.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.1) (2025-01-27)
4+
- Feature
5+
- Added support for get entry references
6+
- Added delay sanity testcases
7+
- Axios, webpack, form-data, qs version bump
8+
39
## [v1.19.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.19.0) (2025-01-13)
410
- Feature
511
- Release 2.0 feature

lib/stack/contentType/entry/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,35 @@ export function Entry (http, data) {
352352
}
353353
}
354354

355+
/**
356+
* @description The get references request allows to get the references of an entry.
357+
* @memberof Entry
358+
* @func references
359+
* @returns {Promise<Object>} Response Object.
360+
* @example 1
361+
* client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').references()
362+
* .then((response) => console.log(response));
363+
* @example 2
364+
* client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').references({locale: 'en-us'})
365+
* .then((response) => console.log(response));
366+
*/
367+
this.references = async (param = {}) => {
368+
const headers = {}
369+
if (this.stackHeaders) {
370+
headers.headers = this.stackHeaders
371+
}
372+
try {
373+
const response = await http.get(`${this.urlPath}/references`, {...headers, params: param,})
374+
if (response.data) {
375+
return response.data
376+
} else {
377+
throw error(response)
378+
}
379+
} catch (err) {
380+
throw error(err)
381+
}
382+
}
383+
355384
} else {
356385
/**
357386
* @description The Create an entry call creates a new entry for the selected content type.

test/sanity-check/api/entry-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ describe('Entry api Test', () => {
170170
.catch(done)
171171
})
172172

173+
it('should get references of the given Entry uid', done => {
174+
makeEntry(singlepageCT.content_type.uid, entryUTD).references()
175+
.then((reference) => {
176+
reference.references.forEach((references) => {
177+
expect(references.entry_uid).to.be.not.equal(null)
178+
expect(references.content_type_uid).to.be.not.equal(null)
179+
expect(references.content_type_title).to.be.not.equal(null)
180+
})
181+
done()
182+
})
183+
.catch(done)
184+
})
185+
173186
it('should unpublish localized entry', done => {
174187
makeEntry(singlepageCT.content_type.uid, entryUTD)
175188
.unpublish({

test/unit/entry-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,31 @@ describe('Contentstack Entry test', () => {
615615
})
616616
.catch(done)
617617
})
618+
it('should get references of the given Entry uid', done => {
619+
var mock = new MockAdapter(Axios)
620+
const references = [
621+
{
622+
entry_uid: "entry_uid",
623+
content_type_uid: "referred_content_type",
624+
locale: "en-us",
625+
title: "Jeff Goins",
626+
content_type_title: "Referred Content Type"
627+
}
628+
]
629+
mock.onGet('/content_types/content_type_uid/entries/UID/references').reply(200, {
630+
references
631+
})
632+
633+
makeEntry({ entry: { ...systemUidMock }, stackHeaders: stackHeadersMock }).references()
634+
.then((reference) => {
635+
expect(reference.references[0].entry_uid).to.be.equal('entry_uid')
636+
reference.references.forEach((references) => {
637+
expect(references.entry_uid).to.be.not.equal(null)
638+
})
639+
done()
640+
})
641+
.catch(done)
642+
})
618643
})
619644

620645
function makeEntry (data) {

types/stack/contentType/entry.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface Entry extends Publishable, Unpublishable, SystemFields, SystemF
1111
variants(uid: string): Variant
1212
setWorkflowStage(data: { workflow_stage: WorkflowStage, locale?:string}): Promise<Response>
1313
locales(): Promise<Locales>
14+
references(param: object): Promise<References>
1415
}
1516

1617
export interface Entries extends Queryable<Entry, {entry: EntryData}> {
@@ -38,4 +39,16 @@ export interface Locales {
3839
export interface Code extends AnyProperty {
3940
code: string;
4041
localized: boolean;
42+
}
43+
44+
export interface References {
45+
references: EntryReferences[];
46+
}
47+
48+
export interface EntryReferences extends AnyProperty {
49+
title: string;
50+
entry_uid: string;
51+
locale: string;
52+
content_type_uid: string;
53+
content_type_title: string;
4154
}

0 commit comments

Comments
 (0)