@tryghost/content-api 1.7.2 → 1.9.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 +104 -5
- package/es/content-api.js +674 -373
- package/es/content-api.js.map +1 -1
- package/lib/index.js +35 -5
- package/package.json +6 -5
- 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,80 @@
|
|
|
2
2
|
|
|
3
3
|
var axios = require('axios');
|
|
4
4
|
|
|
5
|
+
var name$1 = "@tryghost/content-api";
|
|
6
|
+
var version = "1.9.0";
|
|
7
|
+
var repository = "https://github.com/TryGhost/SDK/tree/master/packages/content-api";
|
|
8
|
+
var author = "Ghost Foundation";
|
|
9
|
+
var license = "MIT";
|
|
10
|
+
var main = "cjs/content-api.js";
|
|
11
|
+
var unpkg = "umd/content-api.min.js";
|
|
12
|
+
var module$1 = "es/content-api.js";
|
|
13
|
+
var source = "lib/index.js";
|
|
14
|
+
var files = [
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md",
|
|
17
|
+
"cjs/",
|
|
18
|
+
"lib/",
|
|
19
|
+
"umd/",
|
|
20
|
+
"es/"
|
|
21
|
+
];
|
|
22
|
+
var scripts = {
|
|
23
|
+
dev: "echo \"Implement me!\"",
|
|
24
|
+
pretest: "yarn build",
|
|
25
|
+
test: "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'",
|
|
26
|
+
build: "rollup -c",
|
|
27
|
+
lint: "eslint . --ext .js --cache",
|
|
28
|
+
prepare: "NODE_ENV=production yarn build",
|
|
29
|
+
posttest: "yarn lint"
|
|
30
|
+
};
|
|
31
|
+
var publishConfig = {
|
|
32
|
+
access: "public"
|
|
33
|
+
};
|
|
34
|
+
var devDependencies = {
|
|
35
|
+
"@babel/core": "7.17.9",
|
|
36
|
+
"@babel/polyfill": "7.12.1",
|
|
37
|
+
"@babel/preset-env": "7.16.11",
|
|
38
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
39
|
+
c8: "7.11.0",
|
|
40
|
+
"core-js": "3.22.0",
|
|
41
|
+
"eslint-plugin-ghost": "1.5.0",
|
|
42
|
+
mocha: "7.2.0",
|
|
43
|
+
rollup: "2.70.2",
|
|
44
|
+
"rollup-plugin-babel": "4.4.0",
|
|
45
|
+
"rollup-plugin-commonjs": "10.1.0",
|
|
46
|
+
"rollup-plugin-node-resolve": "5.2.0",
|
|
47
|
+
"rollup-plugin-replace": "2.2.0",
|
|
48
|
+
"rollup-plugin-terser": "7.0.2",
|
|
49
|
+
should: "13.2.3",
|
|
50
|
+
sinon: "9.2.4"
|
|
51
|
+
};
|
|
52
|
+
var dependencies = {
|
|
53
|
+
axios: "^0.21.1"
|
|
54
|
+
};
|
|
55
|
+
var gitHead = "f699f18279c596be384760adccbbf90a659bd4bc";
|
|
56
|
+
var packageInfo = {
|
|
57
|
+
name: name$1,
|
|
58
|
+
version: version,
|
|
59
|
+
repository: repository,
|
|
60
|
+
author: author,
|
|
61
|
+
license: license,
|
|
62
|
+
main: main,
|
|
63
|
+
"umd:main": "umd/content-api.min.js",
|
|
64
|
+
unpkg: unpkg,
|
|
65
|
+
module: module$1,
|
|
66
|
+
source: source,
|
|
67
|
+
files: files,
|
|
68
|
+
scripts: scripts,
|
|
69
|
+
publishConfig: publishConfig,
|
|
70
|
+
devDependencies: devDependencies,
|
|
71
|
+
dependencies: dependencies,
|
|
72
|
+
gitHead: gitHead
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const packageVersion = packageInfo.version;
|
|
76
|
+
|
|
77
|
+
// NOTE: bump this default when Ghost v5 is released
|
|
78
|
+
const defaultAcceptVersionHeader = 'v4.0';
|
|
5
79
|
const supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
|
|
6
80
|
const name = '@tryghost/content-api';
|
|
7
81
|
|
|
@@ -24,10 +98,9 @@ const defaultMakeRequest = ({url, method, params, headers}) => {
|
|
|
24
98
|
* @param {String} options.url
|
|
25
99
|
* @param {String} options.key
|
|
26
100
|
* @param {String} [options.ghostPath]
|
|
27
|
-
* @param {String}
|
|
101
|
+
* @param {String|Boolean} options.version - a version string like v3, v4, v5 or boolean value identifying presence of Accept-Version header
|
|
28
102
|
* @param {Function} [options.makeRequest]
|
|
29
103
|
* @param {String} [options.host] Deprecated
|
|
30
|
-
* @returns
|
|
31
104
|
*/
|
|
32
105
|
function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequest = defaultMakeRequest}) {
|
|
33
106
|
/**
|
|
@@ -46,9 +119,34 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
|
|
|
46
119
|
return GhostContentAPI({url, key, version, ghostPath, makeRequest});
|
|
47
120
|
}
|
|
48
121
|
|
|
49
|
-
if (version
|
|
122
|
+
if (version === undefined) {
|
|
123
|
+
throw new Error(`${name} Config Missing: 'version' is required. E.g. ${supportedVersions.join(',')}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let acceptVersionHeader;
|
|
127
|
+
if (typeof version === 'boolean') {
|
|
128
|
+
if (version === true) {
|
|
129
|
+
acceptVersionHeader = defaultAcceptVersionHeader;
|
|
130
|
+
}
|
|
131
|
+
version = undefined;
|
|
132
|
+
} else if (version && !supportedVersions.includes(version) && !(version.match(/^v\d+\.\d+/))) {
|
|
50
133
|
throw new Error(`${name} Config Invalid: 'version' ${version} is not supported`);
|
|
134
|
+
} else {
|
|
135
|
+
if (version === 'canary') {
|
|
136
|
+
// eslint-disable-next-line
|
|
137
|
+
console.warn(`${name}: The 'version' parameter has a deprecated format 'canary', please use 'v{major}.{minor}' format instead`);
|
|
138
|
+
|
|
139
|
+
acceptVersionHeader = defaultAcceptVersionHeader;
|
|
140
|
+
} else if (version.match(/^v\d+$/)) {
|
|
141
|
+
// eslint-disable-next-line
|
|
142
|
+
console.warn(`${name}: The 'version' parameter has a deprecated format 'v{major}', please use 'v{major}.{minor}' format instead`);
|
|
143
|
+
|
|
144
|
+
acceptVersionHeader = `${version}.0`;
|
|
145
|
+
} else {
|
|
146
|
+
acceptVersionHeader = version;
|
|
147
|
+
}
|
|
51
148
|
}
|
|
149
|
+
|
|
52
150
|
if (!url) {
|
|
53
151
|
throw new Error(`${name} Config Missing: 'url' is required. E.g. 'https://site.com'`);
|
|
54
152
|
}
|
|
@@ -102,8 +200,9 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
|
|
|
102
200
|
Authorization: `GhostMembers ${membersToken}`
|
|
103
201
|
} : {};
|
|
104
202
|
|
|
105
|
-
|
|
106
|
-
|
|
203
|
+
headers['User-Agent'] = `GhostContentSDK/${packageVersion}`;
|
|
204
|
+
if (acceptVersionHeader) {
|
|
205
|
+
headers['Accept-Version'] = acceptVersionHeader;
|
|
107
206
|
}
|
|
108
207
|
|
|
109
208
|
params = Object.assign({key}, params);
|