Skip to content

Commit 059fd94

Browse files
committed
added expandAllContentLinks and test
1 parent 6efbeb2 commit 059fd94

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agility/content-fetch",
3-
"version": "0.8.2",
3+
"version": "0.9.0",
44
"description": "JavaScript library for the Agility Fetch API (node and browser)",
55
"main": "dist/agility-content-fetch.node.js",
66
"scripts": {

src/methods/getContentList.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
66
* @param {Object} requestParams - The parameters for the API request.
77
* @param {string} requestParams.referenceName - The unique reference name of the content list you wish to retrieve in the specified language.
88
* @param {string} requestParams.languageCode - The language code of the content you want to retrieve.
9-
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is 1.
9+
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is *1*.
10+
* @param {boolean} [requestParams.expandAllContentLinks] - Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link. Default is *false*
1011
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **50**.
1112
* @param {number} [requestParams.skip] - The number of items to skip from the list. Default is **0**. Used for implementing pagination.
1213
* @param {string} [requestParams.sort] - The field to sort the results by. Example *fields.title* or *properties.modified*.
@@ -64,7 +65,7 @@ function getContentList(requestParams) {
6465
requestParams = {...defaultParams, ...requestParams};
6566

6667
const req = {
67-
url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.contentLinkDepth),
68+
url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
6869
method: 'get',
6970
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
7071
headers: buildAuthHeader(this.config),
@@ -117,13 +118,16 @@ function validateRequestParams(requestParams) {
117118
}
118119
} else if (requestParams.filtersLogicOperator && requestParams.filtersLogicOperator.toLowerCase() !== 'and' && requestParams.filtersLogicOperator.toLowerCase() !== 'or') {
119120
throw new TypeError('FiltersLogicOperator parameter must have a value of "AND" or "OR"');
121+
} else if(requestParams.expandAllContentLinks && typeof requestParams.expandAllContentLinks !== 'boolean') {
122+
throw new TypeError('ExpandAllContentLinks parameter must be a value of true or false');
120123
}
121124

122125
return true;
123126
}
124127

125128
const defaultParams = {
126-
contentLinkDepth: 1
129+
contentLinkDepth: 1,
130+
expandAllContentLinks: false
127131
}
128132

129133
export default getContentList;

src/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function buildRequestUrlPath(config, languageCode) {
1919
return urlPath;
2020
}
2121

22-
function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, contentLinkDepth) {
22+
function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, contentLinkDepth, expandAllContentLinks) {
2323
let url = `/${contentType}/${referenceName}?contentLinkDepth=${contentLinkDepth}&`;
2424
filtersLogicOperator = filtersLogicOperator ? ` ${filtersLogicOperator} ` : ' AND ';
2525

@@ -46,6 +46,11 @@ function buildPathUrl(contentType, referenceName, skip, take, sort, direction, f
4646
}
4747
url += '&';
4848
}
49+
50+
if(expandAllContentLinks) {
51+
url += `expandAllContentLinks=${expandAllContentLinks}&`;
52+
}
53+
4954
return url;
5055
}
5156

test/getContentList.tests.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,25 @@ describe('getContentList:', function() {
302302
filters: [{property: 'contentID', operator: api.types.FilterOperators.EQUAL_TO, value: '16'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}],
303303
filtersLogicOperator: api.types.FilterLogicOperators.AND
304304
})
305-
.then(function(contentList) {
306-
assert.strictEqual(contentList.items[0].contentID, 16);
307-
assert.strictEqual(contentList.items.length, 1);
308-
done();
309-
})
310-
.catch(done);
305+
.then(function(contentList) {
306+
assert.strictEqual(contentList.items[0].contentID, 16);
307+
assert.strictEqual(contentList.items.length, 1);
308+
done();
309+
})
310+
.catch(done);
311311
});
312+
313+
it('should expand all content links when expandContentLinks are set to true', function(done) {
314+
var api = createApiClient();
315+
api.getContentList({
316+
referenceName: 'posts',
317+
languageCode: 'en-us',
318+
expandAllContentLinks: true
319+
})
320+
.then(function(contentList) {
321+
console.log(contentList);
322+
done();
323+
})
324+
.catch(done);
325+
})
312326
});

0 commit comments

Comments
 (0)