@tryghost/content-api 1.10.1 → 1.11.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 +23 -7
- package/es/content-api.js +20 -5
- package/es/content-api.js.map +1 -1
- package/es/test.html +36 -0
- package/lib/content-api.js +19 -3
- package/package.json +4 -4
- package/umd/content-api.min.js +1 -1
- package/umd/content-api.min.js.map +1 -1
package/cjs/content-api.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var axios = require('axios');
|
|
4
4
|
|
|
5
5
|
var name$1 = "@tryghost/content-api";
|
|
6
|
-
var version = "1.
|
|
6
|
+
var version = "1.11.0";
|
|
7
7
|
var repository = "https://github.com/TryGhost/SDK/tree/master/packages/content-api";
|
|
8
8
|
var author = "Ghost Foundation";
|
|
9
9
|
var license = "MIT";
|
|
@@ -40,11 +40,11 @@ var devDependencies = {
|
|
|
40
40
|
"core-js": "3.22.7",
|
|
41
41
|
"eslint-plugin-ghost": "2.14.0",
|
|
42
42
|
mocha: "10.0.0",
|
|
43
|
-
rollup: "2.
|
|
43
|
+
rollup: "2.75.4",
|
|
44
44
|
"rollup-plugin-babel": "4.4.0",
|
|
45
45
|
"rollup-plugin-commonjs": "10.1.0",
|
|
46
46
|
"rollup-plugin-node-resolve": "5.2.0",
|
|
47
|
-
"rollup-plugin-polyfill-node": "
|
|
47
|
+
"rollup-plugin-polyfill-node": "0.9.0",
|
|
48
48
|
"rollup-plugin-replace": "2.2.0",
|
|
49
49
|
"rollup-plugin-terser": "7.0.2",
|
|
50
50
|
should: "13.2.3",
|
|
@@ -53,7 +53,7 @@ var devDependencies = {
|
|
|
53
53
|
var dependencies = {
|
|
54
54
|
axios: "^0.27.0"
|
|
55
55
|
};
|
|
56
|
-
var gitHead = "
|
|
56
|
+
var gitHead = "a1f560e288bf67886483f9b5d483eecd749c09cc";
|
|
57
57
|
var packageInfo = {
|
|
58
58
|
name: name$1,
|
|
59
59
|
version: version,
|
|
@@ -73,6 +73,9 @@ var packageInfo = {
|
|
|
73
73
|
gitHead: gitHead
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
// @NOTE: this value is dynamically replaced based on browser/node environment
|
|
77
|
+
const USER_AGENT_DEFAULT = true;
|
|
78
|
+
|
|
76
79
|
const packageVersion = packageInfo.version;
|
|
77
80
|
|
|
78
81
|
const defaultAcceptVersionHeader = 'v5.0';
|
|
@@ -122,10 +125,11 @@ const defaultMakeRequest = ({url, method, params, headers}) => {
|
|
|
122
125
|
* @param {String} options.key
|
|
123
126
|
* @param {String} [options.ghostPath]
|
|
124
127
|
* @param {String|Boolean} options.version - a version string like v3, v4, v5 or boolean value identifying presence of Accept-Version header
|
|
128
|
+
* @param {String|Boolean} [options.userAgent] - value controlling the 'User-Agent' header should be sent with a request
|
|
125
129
|
* @param {Function} [options.makeRequest]
|
|
126
130
|
* @param {String} [options.host] Deprecated
|
|
127
131
|
*/
|
|
128
|
-
function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequest = defaultMakeRequest}) {
|
|
132
|
+
function GhostContentAPI({url, key, host, version, userAgent, ghostPath = 'ghost', makeRequest = defaultMakeRequest}) {
|
|
129
133
|
/**
|
|
130
134
|
* host parameter is deprecated
|
|
131
135
|
* @deprecated use "url" instead
|
|
@@ -139,7 +143,7 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
|
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
if (this instanceof GhostContentAPI) {
|
|
142
|
-
return GhostContentAPI({url, key, version, ghostPath, makeRequest});
|
|
146
|
+
return GhostContentAPI({url, key, version, userAgent, ghostPath, makeRequest});
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
if (version === undefined) {
|
|
@@ -185,6 +189,11 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
|
|
|
185
189
|
if (key && !/[0-9a-f]{26}/.test(key)) {
|
|
186
190
|
throw new Error(`${name} Config Invalid: 'key' ${key} must have 26 hex characters`);
|
|
187
191
|
}
|
|
192
|
+
|
|
193
|
+
if (userAgent === undefined) {
|
|
194
|
+
userAgent = USER_AGENT_DEFAULT;
|
|
195
|
+
}
|
|
196
|
+
|
|
188
197
|
const api = ['posts', 'authors', 'tags', 'pages', 'settings', 'tiers', 'newsletters', 'offers'].reduce((apiObject, resourceType) => {
|
|
189
198
|
function browse(options = {}, memberToken) {
|
|
190
199
|
return makeApiRequest(resourceType, options, null, memberToken);
|
|
@@ -227,7 +236,14 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
|
|
|
227
236
|
Authorization: `GhostMembers ${membersToken}`
|
|
228
237
|
} : {};
|
|
229
238
|
|
|
230
|
-
|
|
239
|
+
if (userAgent) {
|
|
240
|
+
if (typeof userAgent === 'boolean') {
|
|
241
|
+
headers['User-Agent'] = `GhostContentSDK/${packageVersion}`;
|
|
242
|
+
} else {
|
|
243
|
+
headers['User-Agent'] = userAgent;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
231
247
|
if (acceptVersionHeader) {
|
|
232
248
|
headers['Accept-Version'] = acceptVersionHeader;
|
|
233
249
|
}
|
package/es/content-api.js
CHANGED
|
@@ -6008,7 +6008,7 @@ axios_1.default = default_1;
|
|
|
6008
6008
|
var axios = axios_1;
|
|
6009
6009
|
|
|
6010
6010
|
var name$1 = "@tryghost/content-api";
|
|
6011
|
-
var version = "1.
|
|
6011
|
+
var version = "1.11.0";
|
|
6012
6012
|
var repository = "https://github.com/TryGhost/SDK/tree/master/packages/content-api";
|
|
6013
6013
|
var author = "Ghost Foundation";
|
|
6014
6014
|
var license = "MIT";
|
|
@@ -6045,11 +6045,11 @@ var devDependencies = {
|
|
|
6045
6045
|
"core-js": "3.22.7",
|
|
6046
6046
|
"eslint-plugin-ghost": "2.14.0",
|
|
6047
6047
|
mocha: "10.0.0",
|
|
6048
|
-
rollup: "2.
|
|
6048
|
+
rollup: "2.75.4",
|
|
6049
6049
|
"rollup-plugin-babel": "4.4.0",
|
|
6050
6050
|
"rollup-plugin-commonjs": "10.1.0",
|
|
6051
6051
|
"rollup-plugin-node-resolve": "5.2.0",
|
|
6052
|
-
"rollup-plugin-polyfill-node": "
|
|
6052
|
+
"rollup-plugin-polyfill-node": "0.9.0",
|
|
6053
6053
|
"rollup-plugin-replace": "2.2.0",
|
|
6054
6054
|
"rollup-plugin-terser": "7.0.2",
|
|
6055
6055
|
should: "13.2.3",
|
|
@@ -6058,7 +6058,7 @@ var devDependencies = {
|
|
|
6058
6058
|
var dependencies = {
|
|
6059
6059
|
axios: "^0.27.0"
|
|
6060
6060
|
};
|
|
6061
|
-
var gitHead = "
|
|
6061
|
+
var gitHead = "a1f560e288bf67886483f9b5d483eecd749c09cc";
|
|
6062
6062
|
var packageInfo = {
|
|
6063
6063
|
name: name$1,
|
|
6064
6064
|
version: version,
|
|
@@ -6078,6 +6078,7 @@ var packageInfo = {
|
|
|
6078
6078
|
gitHead: gitHead
|
|
6079
6079
|
};
|
|
6080
6080
|
|
|
6081
|
+
var USER_AGENT_DEFAULT = false;
|
|
6081
6082
|
var packageVersion = packageInfo.version;
|
|
6082
6083
|
var defaultAcceptVersionHeader = 'v5.0';
|
|
6083
6084
|
var supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
|
|
@@ -6128,6 +6129,7 @@ var defaultMakeRequest = function defaultMakeRequest(_ref) {
|
|
|
6128
6129
|
* @param {String} options.key
|
|
6129
6130
|
* @param {String} [options.ghostPath]
|
|
6130
6131
|
* @param {String|Boolean} options.version - a version string like v3, v4, v5 or boolean value identifying presence of Accept-Version header
|
|
6132
|
+
* @param {String|Boolean} [options.userAgent] - value controlling the 'User-Agent' header should be sent with a request
|
|
6131
6133
|
* @param {Function} [options.makeRequest]
|
|
6132
6134
|
* @param {String} [options.host] Deprecated
|
|
6133
6135
|
*/
|
|
@@ -6138,6 +6140,7 @@ function GhostContentAPI(_ref2) {
|
|
|
6138
6140
|
key = _ref2.key,
|
|
6139
6141
|
host = _ref2.host,
|
|
6140
6142
|
version = _ref2.version,
|
|
6143
|
+
userAgent = _ref2.userAgent,
|
|
6141
6144
|
_ref2$ghostPath = _ref2.ghostPath,
|
|
6142
6145
|
ghostPath = _ref2$ghostPath === void 0 ? 'ghost' : _ref2$ghostPath,
|
|
6143
6146
|
_ref2$makeRequest = _ref2.makeRequest,
|
|
@@ -6161,6 +6164,7 @@ function GhostContentAPI(_ref2) {
|
|
|
6161
6164
|
url: url,
|
|
6162
6165
|
key: key,
|
|
6163
6166
|
version: version,
|
|
6167
|
+
userAgent: userAgent,
|
|
6164
6168
|
ghostPath: ghostPath,
|
|
6165
6169
|
makeRequest: makeRequest
|
|
6166
6170
|
});
|
|
@@ -6214,6 +6218,10 @@ function GhostContentAPI(_ref2) {
|
|
|
6214
6218
|
throw new Error("".concat(name, " Config Invalid: 'key' ").concat(key, " must have 26 hex characters"));
|
|
6215
6219
|
}
|
|
6216
6220
|
|
|
6221
|
+
if (userAgent === undefined) {
|
|
6222
|
+
userAgent = USER_AGENT_DEFAULT;
|
|
6223
|
+
}
|
|
6224
|
+
|
|
6217
6225
|
var api = ['posts', 'authors', 'tags', 'pages', 'settings', 'tiers', 'newsletters', 'offers'].reduce(function (apiObject, resourceType) {
|
|
6218
6226
|
function browse() {
|
|
6219
6227
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -6256,7 +6264,14 @@ function GhostContentAPI(_ref2) {
|
|
|
6256
6264
|
var headers = membersToken ? {
|
|
6257
6265
|
Authorization: "GhostMembers ".concat(membersToken)
|
|
6258
6266
|
} : {};
|
|
6259
|
-
|
|
6267
|
+
|
|
6268
|
+
if (userAgent) {
|
|
6269
|
+
if (typeof userAgent === 'boolean') {
|
|
6270
|
+
headers['User-Agent'] = "GhostContentSDK/".concat(packageVersion);
|
|
6271
|
+
} else {
|
|
6272
|
+
headers['User-Agent'] = userAgent;
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6260
6275
|
|
|
6261
6276
|
if (acceptVersionHeader) {
|
|
6262
6277
|
headers['Accept-Version'] = acceptVersionHeader;
|