@agility/content-fetch 1.1.0 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +1 -7
- package/.vscode/launch.json +35 -0
- package/README.md +2 -1
- package/dist/agility-content-fetch.browser.js +416 -6
- package/dist/agility-content-fetch.node.js +7111 -799
- package/package.json +9 -3
- package/src/api-client.js +23 -17
- package/src/content-fetch.js +5 -5
- package/src/methods/getContentItem.js +6 -5
- package/src/methods/getContentList.js +16 -15
- package/src/methods/getPage.js +6 -5
- package/src/methods/getSitemapFlat.js +6 -5
- package/src/methods/getSitemapNested.js +6 -5
- package/src/methods/getSyncContent.js +6 -5
- package/src/methods/getSyncPages.js +6 -5
- package/src/types/ContentList.js +1 -1
- package/src/utils.js +2 -2
- package/test/apiClients.config.js +17 -2
- package/test/getApi.tests.js +15 -0
- package/test/getContentItem.tests.js +37 -10
- package/test/getContentList.tests.js +27 -27
- package/test/getPage.tests.js +6 -6
- package/test/getSitemapFlat.tests.js +5 -5
- package/test/getSitemapNested.tests.js +5 -5
- package/test/getSyncContentItems.tests.js +2 -2
- package/test/getSyncPageItems.tests.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agility/content-fetch",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "JavaScript library for the Agility Fetch API (node and browser)",
|
|
5
5
|
"main": "dist/agility-content-fetch.node.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,12 @@
|
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "git+https://github.com/agility/agility-content-fetch-js-sdk.git"
|
|
18
18
|
},
|
|
19
|
-
"author": "
|
|
19
|
+
"author": "Agility CMS",
|
|
20
|
+
"contributors": [
|
|
21
|
+
"James Vidler",
|
|
22
|
+
"Joel Varty",
|
|
23
|
+
"Joshua Isaac"
|
|
24
|
+
],
|
|
20
25
|
"license": "MIT",
|
|
21
26
|
"bugs": {
|
|
22
27
|
"url": "https://github.com/agility/agility-content-fetch-js-sdk/issues"
|
|
@@ -38,6 +43,7 @@
|
|
|
38
43
|
"webpack-cli": "^3.2.3"
|
|
39
44
|
},
|
|
40
45
|
"dependencies": {
|
|
41
|
-
"axios": "^0.21.1"
|
|
46
|
+
"axios": "^0.21.1",
|
|
47
|
+
"axios-cache-adapter": "^2.4.1"
|
|
42
48
|
}
|
|
43
49
|
}
|
package/src/api-client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
+
import { setupCache } from 'axios-cache-adapter'
|
|
2
3
|
import getSitemapFlat from './methods/getSitemapFlat'
|
|
3
4
|
import getSitemapNested from './methods/getSitemapNested'
|
|
4
5
|
import getContentItem from './methods/getContentItem'
|
|
@@ -20,7 +21,7 @@ const defaultConfig = {
|
|
|
20
21
|
isPreview: false,
|
|
21
22
|
guid: null,
|
|
22
23
|
apiKey: null,
|
|
23
|
-
|
|
24
|
+
locale: null,
|
|
24
25
|
headers: {},
|
|
25
26
|
requiresGuidInHeaders: false,
|
|
26
27
|
debug: false,
|
|
@@ -93,24 +94,20 @@ export default function createClient(userConfig) {
|
|
|
93
94
|
|
|
94
95
|
let adapter = null;
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
//should we turn on caching?
|
|
98
|
+
if (config.caching.maxAge > 0) {
|
|
99
|
+
const cache = setupCache({
|
|
100
|
+
maxAge: config.caching.maxAge,
|
|
101
|
+
exclude: { query: false }
|
|
102
|
+
});
|
|
103
|
+
adapter = cache.adapter;
|
|
104
|
+
}
|
|
98
105
|
|
|
99
106
|
let api = null;
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
httpsAgent: new https.Agent({
|
|
105
|
-
rejectUnauthorized: false
|
|
106
|
-
})
|
|
107
|
-
})
|
|
108
|
-
} else {
|
|
109
|
-
//we can't use the https.Agent
|
|
110
|
-
api = axios.create({})
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
api = axios.create({
|
|
109
|
+
adapter: adapter,
|
|
110
|
+
})
|
|
114
111
|
|
|
115
112
|
//the function that actually makes ALL our requests
|
|
116
113
|
function makeRequest(reqConfig) {
|
|
@@ -123,12 +120,21 @@ export default function createClient(userConfig) {
|
|
|
123
120
|
return api(reqConfig).then(async (response) => {
|
|
124
121
|
|
|
125
122
|
let data = response.data;
|
|
123
|
+
//if our response is from cache, inject that property in the data response
|
|
124
|
+
if (response.request.fromCache) {
|
|
125
|
+
data['fromCache'] = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (config.debug) {
|
|
129
|
+
data['agilityResponseHeaders'] = response.headers;
|
|
130
|
+
}
|
|
131
|
+
|
|
126
132
|
return data;
|
|
127
133
|
|
|
128
134
|
|
|
129
135
|
})
|
|
130
136
|
.catch(async (error) => {
|
|
131
|
-
logError(`AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error}
|
|
137
|
+
logError(`AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error} ... Does the item exist?`)
|
|
132
138
|
});
|
|
133
139
|
}
|
|
134
140
|
|
package/src/content-fetch.js
CHANGED
|
@@ -49,6 +49,8 @@ import { isHttps } from './utils'
|
|
|
49
49
|
* @param {string} config.guid - The guid that represents your instance.
|
|
50
50
|
* @param {string} config.apiKey - The secret token that represents your application.
|
|
51
51
|
* @param {boolean} [config.isPreview] - If your access token is for preview, then set this to true.
|
|
52
|
+
* @param {Object} [config.caching] - Optional Caching options. Caching is disabled by default.
|
|
53
|
+
* @param {number} [config.caching.maxAge] - In miliseconds. Default value is *0* (disabled). Recommeded value is *180000* (3 mins). Requests are cached in memory only (node or browser).
|
|
52
54
|
* @param {string} [config.baseUrl] - Optionally override the default API Base Url.
|
|
53
55
|
* @return {AgilityFetch.Client}
|
|
54
56
|
* @example
|
|
@@ -69,14 +71,12 @@ function getApi(config) {
|
|
|
69
71
|
|
|
70
72
|
function validateConfigParams(configParams) {
|
|
71
73
|
|
|
72
|
-
if(configParams.caching) {
|
|
73
|
-
console.warn('The built-in caching has been deprecated from @agility/content-fetch as of version `1.1.0`. The `caching` parameter will have no effect.');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
74
|
if(!configParams.guid || configParams.guid.length == 0) {
|
|
77
75
|
throw new TypeError('You must provide an guid.');
|
|
78
76
|
} else if(!configParams.apiKey || configParams.apiKey.length == 0) {
|
|
79
|
-
throw new TypeError('You must provide an access token.');
|
|
77
|
+
throw new TypeError('You must provide an access token.');
|
|
78
|
+
} else if(configParams.caching && isNaN(configParams.caching.maxAge)) {
|
|
79
|
+
throw new TypeError('When specifying a cache maxAge, you must set a number value in miliseconds, i.e. 180000 (3 mins).');
|
|
80
80
|
} else if(configParams.baseUrl && !isHttps(configParams.baseUrl)) {
|
|
81
81
|
throw new TypeError(`When specifying a baseUrl (${configParams.baseUrl}), it must be over HTTPs.`);
|
|
82
82
|
} else {
|
|
@@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
5
5
|
* @memberof AgilityFetch.Client.Content
|
|
6
6
|
* @param {Object} requestParams - The paramters for the API request.
|
|
7
7
|
* @param {number} requestParams.contentID - The contentID of the requested item in this language.
|
|
8
|
-
* @param {string} requestParams.
|
|
8
|
+
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
|
|
9
|
+
* @param {string} requestParams.languageCode DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
|
|
9
10
|
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is **1**.
|
|
10
11
|
* @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**
|
|
11
12
|
* @returns {Promise<AgilityFetch.Types.ContentItem>} - Returns a content item object.
|
|
@@ -20,7 +21,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
20
21
|
*
|
|
21
22
|
* api.getContentItem({
|
|
22
23
|
* contentID: 22,
|
|
23
|
-
*
|
|
24
|
+
* locale: 'en-us'
|
|
24
25
|
* })
|
|
25
26
|
* .then(function(contentItem) {
|
|
26
27
|
* console.log(contentItem);
|
|
@@ -40,7 +41,7 @@ function getContentItem(requestParams) {
|
|
|
40
41
|
const req = {
|
|
41
42
|
url: `/item/${requestParams.contentID}?contentLinkDepth=${requestParams.contentLinkDepth}&expandAllContentLinks=${requestParams.expandAllContentLinks}`,
|
|
42
43
|
method: 'get',
|
|
43
|
-
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
|
|
44
|
+
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
|
|
44
45
|
headers: buildAuthHeader(this.config),
|
|
45
46
|
params:{}
|
|
46
47
|
};
|
|
@@ -49,8 +50,8 @@ function getContentItem(requestParams) {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
function validateRequestParams(requestParams) {
|
|
52
|
-
if(!requestParams.languageCode) {
|
|
53
|
-
throw new TypeError('You must include a
|
|
53
|
+
if(!requestParams.languageCode && !requestParams.locale) {
|
|
54
|
+
throw new TypeError('You must include a locale in your request params.')
|
|
54
55
|
}
|
|
55
56
|
else if(!requestParams.contentID) {
|
|
56
57
|
throw new TypeError('You must include a contentID number in your request params.');
|
|
@@ -5,10 +5,11 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
5
5
|
* @memberof AgilityFetch.Client.Content
|
|
6
6
|
* @param {Object} requestParams - The parameters for the API request.
|
|
7
7
|
* @param {string} requestParams.referenceName - The unique reference name of the content list you wish to retrieve in the specified language.
|
|
8
|
-
* @param {string} requestParams.
|
|
8
|
+
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
|
|
9
|
+
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
|
|
9
10
|
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is **1**.
|
|
10
11
|
* @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**
|
|
11
|
-
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **
|
|
12
|
+
* @param {number} [requestParams.take] - The maximum number of items to retrieve in this request. Default is **10**. Maximum allowed is **250**.
|
|
12
13
|
* @param {number} [requestParams.skip] - The number of items to skip from the list. Default is **0**. Used for implementing pagination.
|
|
13
14
|
* @param {string} [requestParams.sort] - The field to sort the results by. Example **fields.title** or **properties.modified**.
|
|
14
15
|
* @param {AgilityFetch.Types.SortDirection} [requestParams.direction] - The direction to sort the results by.
|
|
@@ -16,17 +17,17 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
16
17
|
* @param {AgilityFetch.Types.FilterLogicOperator} [requestParams.filtersLogicOperator] - The logic operator to combine multiple filters.
|
|
17
18
|
* @returns {Promise<AgilityFetch.Types.ContentList>} - Returns a list of content items.
|
|
18
19
|
* @example
|
|
19
|
-
*
|
|
20
|
+
*
|
|
20
21
|
* import agility from '@agility/content-fetch'
|
|
21
|
-
*
|
|
22
|
+
*
|
|
22
23
|
* const api = agility.getApi({
|
|
23
24
|
* guid: 'ade6cf3c',
|
|
24
25
|
* apiKey: 'defaultlive.201ffdd0841cacad5bb647e76547e918b0c9ecdb8b5ddb3cf92e9a79b03623cb',
|
|
25
26
|
* });
|
|
26
|
-
*
|
|
27
|
+
*
|
|
27
28
|
* api.getContentList({
|
|
28
29
|
* referenceName: 'posts',
|
|
29
|
-
*
|
|
30
|
+
* locale: 'en-us',
|
|
30
31
|
* take: 50,
|
|
31
32
|
* skip: 0,
|
|
32
33
|
* sort: 'properties.modified',
|
|
@@ -41,7 +42,7 @@ import {buildPathUrl, buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
41
42
|
*
|
|
42
43
|
* api.getContentList({
|
|
43
44
|
* referenceName: 'posts',
|
|
44
|
-
*
|
|
45
|
+
* locale: 'en-us',
|
|
45
46
|
* take: 50,
|
|
46
47
|
* skip: 0,
|
|
47
48
|
* filters: [
|
|
@@ -69,12 +70,12 @@ function getContentList(requestParams) {
|
|
|
69
70
|
const req = {
|
|
70
71
|
url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
|
|
71
72
|
method: 'get',
|
|
72
|
-
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
|
|
73
|
+
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
|
|
73
74
|
headers: buildAuthHeader(this.config),
|
|
74
75
|
params:{}
|
|
75
76
|
};
|
|
76
|
-
|
|
77
|
-
return this.makeRequest(req);
|
|
77
|
+
|
|
78
|
+
return this.makeRequest(req);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
function sanitizeReferenceName(referenceName) {
|
|
@@ -82,8 +83,8 @@ function sanitizeReferenceName(referenceName) {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
function validateRequestParams(requestParams) {
|
|
85
|
-
if(!requestParams.languageCode) {
|
|
86
|
-
throw new TypeError('You must include a
|
|
86
|
+
if(!requestParams.languageCode && !requestParams.locale) {
|
|
87
|
+
throw new TypeError('You must include a locale in your request params.')
|
|
87
88
|
}
|
|
88
89
|
else if(!requestParams.referenceName) {
|
|
89
90
|
//must have a referenceName
|
|
@@ -94,9 +95,9 @@ function validateRequestParams(requestParams) {
|
|
|
94
95
|
} else if((requestParams.take || requestParams.take == 0) && !isNaN(requestParams.take) && requestParams.take < 1) {
|
|
95
96
|
//take parameter must be greater than 0
|
|
96
97
|
throw new TypeError('Take parameter must be greater than 0.');
|
|
97
|
-
} else if(requestParams.take && !isNaN(requestParams.take) && requestParams.take >
|
|
98
|
-
//take parameter cannot be greater than
|
|
99
|
-
throw new TypeError('Take parameter must be
|
|
98
|
+
} else if(requestParams.take && !isNaN(requestParams.take) && requestParams.take > 250) {
|
|
99
|
+
//take parameter cannot be greater than 250
|
|
100
|
+
throw new TypeError('Take parameter must be 250 or less.');
|
|
100
101
|
} else if(requestParams.skip && isNaN(requestParams.skip)) {
|
|
101
102
|
//skip parameter must be a number
|
|
102
103
|
throw new TypeError('Skip parameter must be a number.');
|
package/src/methods/getPage.js
CHANGED
|
@@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
5
5
|
* @memberof AgilityFetch.Client.Pages
|
|
6
6
|
* @param {Object} requestParams - The parameters for the API request.
|
|
7
7
|
* @param {number} requestParams.pageID - The unique page ID of the page you wish to retrieve in the current language.
|
|
8
|
-
* @param {string} requestParams.
|
|
8
|
+
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
|
|
9
|
+
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
|
|
9
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**
|
|
10
11
|
* @param {number} [requestParams.contentLinkDepth] - The depth, representing the levels in which you want linked content auto-resolved. Default is **2**.
|
|
11
12
|
* @returns {Promise<AgilityFetch.Types.Page>} - Returns a page item object.
|
|
@@ -20,7 +21,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
20
21
|
*
|
|
21
22
|
* api.getPage({
|
|
22
23
|
* pageID: 1,
|
|
23
|
-
*
|
|
24
|
+
* locale: 'en-us'
|
|
24
25
|
* })
|
|
25
26
|
* .then(function(page) {
|
|
26
27
|
* console.log(page);
|
|
@@ -39,7 +40,7 @@ function getPage(requestParams) {
|
|
|
39
40
|
const req = {
|
|
40
41
|
url: `/page/${requestParams.pageID}?contentLinkDepth=${requestParams.contentLinkDepth}&expandAllContentLinks=${requestParams.expandAllContentLinks}`,
|
|
41
42
|
method: 'get',
|
|
42
|
-
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
|
|
43
|
+
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
|
|
43
44
|
headers: buildAuthHeader(this.config),
|
|
44
45
|
params:{}
|
|
45
46
|
};
|
|
@@ -48,8 +49,8 @@ function getPage(requestParams) {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
function validateRequestParams(requestParams) {
|
|
51
|
-
if(!requestParams.languageCode) {
|
|
52
|
-
throw new TypeError('You must include a
|
|
52
|
+
if(!requestParams.languageCode && !requestParams.locale) {
|
|
53
|
+
throw new TypeError('You must include a locale in your request params.')
|
|
53
54
|
} else if(!requestParams.pageID) {
|
|
54
55
|
throw new TypeError('You must include a pageID in your request params.');
|
|
55
56
|
} else if(requestParams.expandAllContentLinks && typeof requestParams.expandAllContentLinks !== 'boolean') {
|
|
@@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
5
5
|
* @memberof AgilityFetch.Client.Pages
|
|
6
6
|
* @param {Object} requestParams - The parameters for the API request.
|
|
7
7
|
* @param {number} requestParams.channelName - The reference name of the digital channel of the sitemap to return. If you only have one channel, your channel reference name is likely *website*.
|
|
8
|
-
* @param {string} requestParams.
|
|
8
|
+
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
|
|
9
|
+
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
|
|
9
10
|
* @returns {Promise<AgilityFetch.Types.SitemapFlat>} - The sitemap response in a flat format.
|
|
10
11
|
* @example
|
|
11
12
|
*
|
|
@@ -18,7 +19,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
18
19
|
*
|
|
19
20
|
* api.getSitemapFlat({
|
|
20
21
|
* channelName: 'website',
|
|
21
|
-
*
|
|
22
|
+
* locale: 'en-us'
|
|
22
23
|
* })
|
|
23
24
|
* .then(function(sitemap) {
|
|
24
25
|
* console.log(sitemap);
|
|
@@ -35,7 +36,7 @@ function getSitemapFlat(requestParams) {
|
|
|
35
36
|
const req = {
|
|
36
37
|
url: `/sitemap/flat/${requestParams.channelName}`,
|
|
37
38
|
method: 'get',
|
|
38
|
-
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
|
|
39
|
+
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
|
|
39
40
|
headers: buildAuthHeader(this.config),
|
|
40
41
|
params:{}
|
|
41
42
|
};
|
|
@@ -44,8 +45,8 @@ function getSitemapFlat(requestParams) {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
function validateRequestParams(requestParams) {
|
|
47
|
-
if(!requestParams.languageCode) {
|
|
48
|
-
throw new TypeError('You must include a
|
|
48
|
+
if(!requestParams.languageCode && !requestParams.locale) {
|
|
49
|
+
throw new TypeError('You must include a locale in your request params.')
|
|
49
50
|
} else if(!requestParams.channelName) {
|
|
50
51
|
throw new TypeError('You must include a channelName in your request params.');
|
|
51
52
|
} else {
|
|
@@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
5
5
|
* @memberof AgilityFetch.Client.Pages
|
|
6
6
|
* @param {Object} requestParams - The parameters for the API request.
|
|
7
7
|
* @param {number} requestParams.channelName - The reference name of the digital channel of the sitemap to return. If you only have one channel, your channel reference name is likely *website*.
|
|
8
|
-
* @param {string} requestParams.
|
|
8
|
+
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
|
|
9
|
+
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
|
|
9
10
|
* @returns {Promise<AgilityFetch.Types.SitemapNested>} - The array of sitemap items returned.
|
|
10
11
|
* @example
|
|
11
12
|
*
|
|
@@ -18,7 +19,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
18
19
|
*
|
|
19
20
|
* api.getSitemapNested({
|
|
20
21
|
* channelName: 'website',
|
|
21
|
-
*
|
|
22
|
+
* locale: 'en-us'
|
|
22
23
|
* })
|
|
23
24
|
* .then(function(sitemap) {
|
|
24
25
|
* console.log(sitemap);
|
|
@@ -35,7 +36,7 @@ function getSitemapNested(requestParams) {
|
|
|
35
36
|
const req = {
|
|
36
37
|
url: `/sitemap/nested/${requestParams.channelName}`,
|
|
37
38
|
method: 'get',
|
|
38
|
-
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
|
|
39
|
+
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
|
|
39
40
|
headers: buildAuthHeader(this.config),
|
|
40
41
|
params:{}
|
|
41
42
|
};
|
|
@@ -44,8 +45,8 @@ function getSitemapNested(requestParams) {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
function validateRequestParams(requestParams) {
|
|
47
|
-
if(!requestParams.languageCode) {
|
|
48
|
-
throw new TypeError('You must include a
|
|
48
|
+
if(!requestParams.languageCode && !requestParams.locale) {
|
|
49
|
+
throw new TypeError('You must include a locale in your request params.')
|
|
49
50
|
} else if(!requestParams.channelName) {
|
|
50
51
|
throw new TypeError('You must include a channelName in your request params.');
|
|
51
52
|
}
|
|
@@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
5
5
|
* @memberof AgilityFetch.Client.Sync
|
|
6
6
|
* @param {Object} requestParams - The paramters for the API request.
|
|
7
7
|
* @param {number} requestParams.syncToken - The sync token provided in the response to a previous sync API call. To start a new sync, use the value of '0'.
|
|
8
|
-
* @param {string} requestParams.
|
|
8
|
+
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
|
|
9
|
+
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
|
|
9
10
|
* @param {number} [requestParams.pageSize] - The number of items to return back with each call. Default is 500.
|
|
10
11
|
* @returns {Promise<AgilityFetch.Types.SyncContent>} - Returns a list of content item objects.
|
|
11
12
|
* @example
|
|
@@ -19,7 +20,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
19
20
|
*
|
|
20
21
|
* api.getSyncContent({
|
|
21
22
|
* syncToken: '0', //to start a new sync
|
|
22
|
-
*
|
|
23
|
+
* locale: 'en-us',
|
|
23
24
|
* pageSize: 500
|
|
24
25
|
* })
|
|
25
26
|
* .then(function(contentList) {
|
|
@@ -39,7 +40,7 @@ function getSyncContent(requestParams) {
|
|
|
39
40
|
const req = {
|
|
40
41
|
url: `/sync/items?pageSize=${requestParams.pageSize}&syncToken=${requestParams.syncToken}`,
|
|
41
42
|
method: 'get',
|
|
42
|
-
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
|
|
43
|
+
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
|
|
43
44
|
headers: buildAuthHeader(this.config),
|
|
44
45
|
params: {}
|
|
45
46
|
};
|
|
@@ -48,8 +49,8 @@ function getSyncContent(requestParams) {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
function validateRequestParams(requestParams) {
|
|
51
|
-
if (!requestParams.languageCode) {
|
|
52
|
-
throw new TypeError('You must include a
|
|
52
|
+
if (!requestParams.languageCode && !requestParams.locale) {
|
|
53
|
+
throw new TypeError('You must include a locale in your request params.')
|
|
53
54
|
}
|
|
54
55
|
else if (requestParams.syncToken == undefined || requestParams.syncToken == null) {
|
|
55
56
|
throw new TypeError('You must include a syncToken value your request params. Use zero (0) to start a new sync.');
|
|
@@ -5,7 +5,8 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
5
5
|
* @memberof AgilityFetch.Client.Sync
|
|
6
6
|
* @param {Object} requestParams - The paramters for the API request.
|
|
7
7
|
* @param {number} requestParams.syncToken - The sync token provided in the response to a previous sync API call. To start a new sync, use the value of '0'.
|
|
8
|
-
* @param {string} requestParams.
|
|
8
|
+
* @param {string} requestParams.locale - The locale code of the content you want to retrieve.
|
|
9
|
+
* @param {string} requestParams.languageCode - DEPRECATED: Use locale instead - The language code of the content you want to retrieve.
|
|
9
10
|
* @param {number} [requestParams.pageSize] - The number of items to return back with each call. Default is 1000.
|
|
10
11
|
* @returns {Promise<AgilityFetch.Types.Page>} - Returns a list of content item objects.
|
|
11
12
|
* @example
|
|
@@ -19,7 +20,7 @@ import { buildRequestUrlPath, buildAuthHeader } from '../utils'
|
|
|
19
20
|
*
|
|
20
21
|
* api.getSyncPages({
|
|
21
22
|
* syncToken: '0', //to start a new sync
|
|
22
|
-
*
|
|
23
|
+
* locale: 'en-us',
|
|
23
24
|
* pageSize: 500
|
|
24
25
|
* })
|
|
25
26
|
* .then(function(pages) {
|
|
@@ -39,7 +40,7 @@ function getSyncPages(requestParams) {
|
|
|
39
40
|
const req = {
|
|
40
41
|
url: `/sync/pages?pageSize=${requestParams.pageSize}&syncToken=${requestParams.syncToken}`,
|
|
41
42
|
method: 'get',
|
|
42
|
-
baseURL: buildRequestUrlPath(this.config, requestParams.languageCode),
|
|
43
|
+
baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
|
|
43
44
|
headers: buildAuthHeader(this.config),
|
|
44
45
|
params: {}
|
|
45
46
|
};
|
|
@@ -48,8 +49,8 @@ function getSyncPages(requestParams) {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
function validateRequestParams(requestParams) {
|
|
51
|
-
if (!requestParams.languageCode) {
|
|
52
|
-
throw new TypeError('You must include a
|
|
52
|
+
if (!requestParams.languageCode && !requestParams.locale) {
|
|
53
|
+
throw new TypeError('You must include a locale in your request params.')
|
|
53
54
|
}
|
|
54
55
|
else if (requestParams.syncToken == undefined || requestParams.syncToken == null) {
|
|
55
56
|
throw new TypeError('You must include a syncToken value your request params. Use zero (0) to start a new sync.');
|
package/src/types/ContentList.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Defines a **Content List** in the CMS.
|
|
3
3
|
* @typedef ContentList
|
|
4
4
|
* @memberof AgilityFetch.Types
|
|
5
|
-
* @property {Array.<AgilityFetch.Types.ContentItem>} items - The paginated array of items returned by the request. Default *take* is **10** unless otherwise specified (Maximum allowed it **
|
|
5
|
+
* @property {Array.<AgilityFetch.Types.ContentItem>} items - The paginated array of items returned by the request. Default *take* is **10** unless otherwise specified (Maximum allowed it **250**)
|
|
6
6
|
* @property {number} totalCount - The total amount of items in the list. Use this along with *skip* and *take* for pagination.
|
|
7
7
|
*/
|
|
8
8
|
|
package/src/utils.js
CHANGED
|
@@ -6,7 +6,7 @@ function logDebug(consoleMessage) {
|
|
|
6
6
|
console.log('\x1b[33m%s\x1b[0m', consoleMessage);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function buildRequestUrlPath(config,
|
|
9
|
+
function buildRequestUrlPath(config, locale) {
|
|
10
10
|
let apiFetchOrPreview = null;
|
|
11
11
|
|
|
12
12
|
if(config.isPreview === true || config.isPreview === 'true') {
|
|
@@ -15,7 +15,7 @@ function buildRequestUrlPath(config, languageCode) {
|
|
|
15
15
|
apiFetchOrPreview = 'fetch';
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${
|
|
18
|
+
let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${locale}`;
|
|
19
19
|
return urlPath;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -9,7 +9,8 @@ const apiKeyPreview = 'UnitTestsPreview.69e6bca345ced0b7ca5ab358b351ea5c870790a5
|
|
|
9
9
|
function createApiClient() {
|
|
10
10
|
var api = agility.getApi({
|
|
11
11
|
guid: guid,
|
|
12
|
-
|
|
12
|
+
apiKey: apiKeyFetch,
|
|
13
|
+
baseUrl: `https://api-dev.aglty.io/${guid}`
|
|
13
14
|
});
|
|
14
15
|
return api;
|
|
15
16
|
}
|
|
@@ -22,17 +23,31 @@ function createApiClientWithNewCdn() {
|
|
|
22
23
|
return api;
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
function createCachedApiClient() {
|
|
27
|
+
var api = agility.getApi({
|
|
28
|
+
guid: guid,
|
|
29
|
+
apiKey: apiKeyFetch,
|
|
30
|
+
caching: {
|
|
31
|
+
maxAge: 5 * 60 * 1000 //==5mins
|
|
32
|
+
},
|
|
33
|
+
baseUrl: `https://api-dev.aglty.io/${guid}`
|
|
34
|
+
});
|
|
35
|
+
return api;
|
|
36
|
+
}
|
|
37
|
+
|
|
25
38
|
function createPreviewApiClient() {
|
|
26
39
|
var api = agility.getApi({
|
|
27
40
|
guid: guid,
|
|
28
41
|
apiKey: apiKeyPreview,
|
|
29
|
-
isPreview: true
|
|
42
|
+
isPreview: true,
|
|
43
|
+
baseUrl: `https://api-dev.aglty.io/${guid}`
|
|
30
44
|
});
|
|
31
45
|
return api;
|
|
32
46
|
}
|
|
33
47
|
|
|
34
48
|
export {
|
|
35
49
|
createApiClient,
|
|
50
|
+
createCachedApiClient,
|
|
36
51
|
createPreviewApiClient,
|
|
37
52
|
createApiClientWithNewCdn
|
|
38
53
|
}
|
package/test/getApi.tests.js
CHANGED
|
@@ -153,6 +153,21 @@ describe('getApi:', function() {
|
|
|
153
153
|
done();
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
+
it('should throw an error if caching maxAge is passed-in and is not a number', function(done) {
|
|
157
|
+
expect(function() {
|
|
158
|
+
var api = agility.getApi({
|
|
159
|
+
guid: 'some-guid',
|
|
160
|
+
apiKey: 'some-access-token',
|
|
161
|
+
caching: {
|
|
162
|
+
maxAge: 'ten thousand miliseconds'
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
assert.strictEqual(typeof(api), "object");
|
|
166
|
+
done();
|
|
167
|
+
}).to.throw( TypeError );
|
|
168
|
+
done();
|
|
169
|
+
});
|
|
170
|
+
|
|
156
171
|
|
|
157
172
|
it('should throw an error if baseUrl is passed-in and is does not start with "https"', function(done) {
|
|
158
173
|
expect(function() {
|