Skip to content

Commit 5a38f42

Browse files
committed
added contentLinkDepth parameter to item, list, page calls
1 parent 3a7d75a commit 5a38f42

File tree

10 files changed

+78
-50
lines changed

10 files changed

+78
-50
lines changed

package-lock.json

Lines changed: 12 additions & 31 deletions
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.5.1",
3+
"version": "0.5.2",
44
"description": "JavaScript library for the Agility Fetch API (node and browser)",
55
"main": "dist/agility-content-fetch.node.js",
66
"scripts": {

src/api-client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export default function createClient(userConfig) {
4141
}
4242

4343
let adapter = null;
44-
44+
4545
//should we turn on caching?
4646
if(config.caching.maxAge > 0) {
4747
const cache = setupCache({
48-
maxAge: config.caching.maxAge
48+
maxAge: config.caching.maxAge,
49+
exclude: { query: false }
4950
});
5051
adapter = cache.adapter;
5152
}
@@ -65,7 +66,7 @@ export default function createClient(userConfig) {
6566
data['fromCache'] = true;
6667
}
6768
return data;
68-
});
69+
});
6970
}
7071

7172
//export only these properties:

src/methods/getContentItem.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
66
* @param {Object} requestParams - The paramters for the API request.
77
* @param {number} requestParams.contentID - The contentID of the requested item in this 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.
910
* @returns {Promise<AgilityFetch.Types.ContentItem>} - Returns a content item object.
1011
* @example
1112
*
1213
* import agility from '@agility/content-fetch'
1314
*
1415
* const api = agility.getApi({
15-
* guid: '191309ca-e675-4be2-bb29-351879528707',
16-
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
16+
* guid: 'ade6cf3c',
17+
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
1718
* });
1819
*
1920
* api.getContentItem({
@@ -29,12 +30,19 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
2930
*
3031
*/
3132

33+
const defaultParams = {
34+
contentLinkDepth: 1
35+
}
36+
3237
function getContentItem(requestParams) {
3338

3439
validateRequestParams(requestParams);
3540

41+
//merge default params with request params
42+
requestParams = {...defaultParams, ...requestParams};
43+
3644
const req = {
37-
url: `/item/${requestParams.contentID}`,
45+
url: `/item/${requestParams.contentID}?contentLinkDepth=${requestParams.contentLinkDepth}`,
3846
method: 'get',
3947
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
4048
headers: buildAuthHeader(this.config),
@@ -50,6 +58,8 @@ function validateRequestParams(requestParams) {
5058
}
5159
else if(!requestParams.contentID) {
5260
throw new TypeError('You must include a contentID number in your request params.');
61+
} else if(requestParams.contentLinkDepth && (isNaN(requestParams.contentLinkDepth) || request.contentLinkDepth < 0)) {
62+
throw new TypeError('When specifying contentLinkDepth, it must be a number greater than 0.');
5363
} else {
5464
return;
5565
}

src/methods/getContentList.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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.
910
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **50**.
1011
* @param {number} [requestParams.skip] - The number of items to skip from the list. Default is **0**. Used for implementing pagination.
1112
* @param {string} [requestParams.sort] - The field to sort the results by. Example *fields.title* or *properties.created*.
@@ -18,8 +19,8 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
1819
* import agility from '@agility/content-fetch'
1920
*
2021
* const api = agility.getApi({
21-
* guid: '191309ca-e675-4be2-bb29-351879528707',
22-
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
22+
* guid: 'ade6cf3c',
23+
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
2324
* });
2425
*
2526
* api.getContentList({
@@ -56,13 +57,20 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
5657
* });
5758
*/
5859

60+
const defaultParams = {
61+
contentLinkDepth: 1
62+
}
63+
5964

6065
function getContentList(requestParams) {
6166

6267
validateRequestParams(requestParams);
6368

69+
//merge default params with request params
70+
requestParams = {...defaultParams, ...requestParams};
71+
6472
const req = {
65-
url: buildPathUrl("list", requestParams.referenceName, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator),
73+
url: buildPathUrl("list", requestParams.referenceName, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.contentLinkDepth),
6674
method: 'get',
6775
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
6876
headers: buildAuthHeader(this.config),

src/methods/getPage.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
66
* @param {Object} requestParams - The parameters for the API request.
77
* @param {number} requestParams.pageID - The unique page ID of the page you wish to retrieve in the current 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 2.
910
* @returns {Promise<AgilityFetch.Types.Page>} - Returns a page item object.
1011
* @example
1112
*
1213
* import agility from '@agility/content-fetch'
1314
*
1415
* const api = agility.getApi({
15-
* guid: '191309ca-e675-4be2-bb29-351879528707',
16-
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
16+
* guid: 'ade6cf3c',
17+
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
1718
* });
1819
*
1920
* api.getPage({
@@ -28,13 +29,20 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
2829
* });
2930
*/
3031

32+
const defaultParams = {
33+
contentLinkDepth: 2
34+
}
35+
3136

3237
function getPage(requestParams) {
3338

3439
validateRequestParams(requestParams);
3540

41+
//merge default params with request params
42+
requestParams = {...defaultParams, ...requestParams};
43+
3644
const req = {
37-
url: `/page/${requestParams.pageID}`,
45+
url: `/page/${requestParams.pageID}?contentLinkDepth=${requestParams.contentLinkDepth}`,
3846
method: 'get',
3947
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
4048
headers: buildAuthHeader(this.config),

src/methods/getSitemapFlat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
1212
* import agility from '@agility/content-fetch'
1313
*
1414
* const api = agility.getApi({
15-
* guid: '191309ca-e675-4be2-bb29-351879528707',
16-
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
15+
* guid: 'ade6cf3c',
16+
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
1717
* });
1818
*
1919
* api.getSitemapFlat({

src/methods/getSitemapNested.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
1212
* import agility from '@agility/content-fetch'
1313
*
1414
* const api = agility.getApi({
15-
* guid: '191309ca-e675-4be2-bb29-351879528707',
16-
* apiKey: 'aGd13M.fa30c36e553a36f871860407e902da9a7375322457acd6bcda038e60af699411',
15+
* guid: 'ade6cf3c',
16+
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
1717
* });
1818
*
1919
* api.getSitemapNested({

src/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ function buildRequestUrlPath(config, languageCode) {
1212
return urlPath;
1313
}
1414

15-
function buildPathUrl(contentType, referenceName, sort, direction, filters, filtersLogicOperator) {
16-
let url = `/${contentType}/${referenceName}?`;
15+
function buildPathUrl(contentType, referenceName, sort, direction, filters, filtersLogicOperator, contentLinkDepth) {
16+
let url = `/${contentType}/${referenceName}?contentLinkDepth=${contentLinkDepth}&`;
1717
filtersLogicOperator = filtersLogicOperator ? ` ${filtersLogicOperator} ` : ' AND ';
1818

1919
if (sort) {
20+
2021
url += `sort=${sort}&`;
2122

2223
if (direction) {

0 commit comments

Comments
 (0)