@tryghost/content-api 1.7.3 → 1.8.0
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/cjs/content-api.js +31 -4
- package/es/content-api.js +432 -145
- package/es/content-api.js.map +1 -1
- package/lib/index.js +31 -4
- package/package.json +2 -2
- package/umd/content-api.min.js +1 -1
- package/umd/content-api.min.js.map +1 -1
package/cjs/content-api.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var axios = require('axios');
|
|
4
4
|
|
|
5
|
+
// NOTE: bump this default when Ghost v5 is released
|
|
6
|
+
const defaultAcceptVersionHeader = 'v4.0';
|
|
5
7
|
const supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
|
|
6
8
|
const name = '@tryghost/content-api';
|
|
7
9
|
|
|
@@ -24,7 +26,7 @@ const defaultMakeRequest = ({url, method, params, headers}) => {
|
|
|
24
26
|
* @param {String} options.url
|
|
25
27
|
* @param {String} options.key
|
|
26
28
|
* @param {String} [options.ghostPath]
|
|
27
|
-
* @param {String}
|
|
29
|
+
* @param {String|Boolean} options.version - a version string like v3, v4, v5 or boolean value identifying presence of Accept-Version header
|
|
28
30
|
* @param {Function} [options.makeRequest]
|
|
29
31
|
* @param {String} [options.host] Deprecated
|
|
30
32
|
*/
|
|
@@ -45,9 +47,34 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
|
|
|
45
47
|
return GhostContentAPI({url, key, version, ghostPath, makeRequest});
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
if (version
|
|
50
|
+
if (version === undefined) {
|
|
51
|
+
throw new Error(`${name} Config Missing: 'version' is required. E.g. ${supportedVersions.join(',')}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let acceptVersionHeader;
|
|
55
|
+
if (typeof version === 'boolean') {
|
|
56
|
+
if (version === true) {
|
|
57
|
+
acceptVersionHeader = defaultAcceptVersionHeader;
|
|
58
|
+
}
|
|
59
|
+
version = undefined;
|
|
60
|
+
} else if (version && !supportedVersions.includes(version) && !(version.match(/^v\d+\.\d+/))) {
|
|
49
61
|
throw new Error(`${name} Config Invalid: 'version' ${version} is not supported`);
|
|
62
|
+
} else {
|
|
63
|
+
if (version === 'canary') {
|
|
64
|
+
// eslint-disable-next-line
|
|
65
|
+
console.warn(`${name}: The 'version' parameter has a deprecated format 'canary', please use 'v{major}.{minor}' format instead`);
|
|
66
|
+
|
|
67
|
+
acceptVersionHeader = defaultAcceptVersionHeader;
|
|
68
|
+
} else if (version.match(/^v\d+$/)) {
|
|
69
|
+
// eslint-disable-next-line
|
|
70
|
+
console.warn(`${name}: The 'version' parameter has a deprecated format 'v{major}', please use 'v{major}.{minor}' format instead`);
|
|
71
|
+
|
|
72
|
+
acceptVersionHeader = `${version}.0`;
|
|
73
|
+
} else {
|
|
74
|
+
acceptVersionHeader = version;
|
|
75
|
+
}
|
|
50
76
|
}
|
|
77
|
+
|
|
51
78
|
if (!url) {
|
|
52
79
|
throw new Error(`${name} Config Missing: 'url' is required. E.g. 'https://site.com'`);
|
|
53
80
|
}
|
|
@@ -101,8 +128,8 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
|
|
|
101
128
|
Authorization: `GhostMembers ${membersToken}`
|
|
102
129
|
} : {};
|
|
103
130
|
|
|
104
|
-
if (
|
|
105
|
-
headers['Accept-Version'] =
|
|
131
|
+
if (acceptVersionHeader) {
|
|
132
|
+
headers['Accept-Version'] = acceptVersionHeader;
|
|
106
133
|
}
|
|
107
134
|
|
|
108
135
|
params = Object.assign({key}, params);
|