@tryghost/content-api 1.10.0 → 1.11.1

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.
@@ -3,7 +3,7 @@
3
3
  var axios = require('axios');
4
4
 
5
5
  var name$1 = "@tryghost/content-api";
6
- var version = "1.10.0";
6
+ var version = "1.11.1";
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";
@@ -32,19 +32,19 @@ var publishConfig = {
32
32
  access: "public"
33
33
  };
34
34
  var devDependencies = {
35
- "@babel/core": "7.18.2",
35
+ "@babel/core": "7.18.10",
36
36
  "@babel/polyfill": "7.12.1",
37
- "@babel/preset-env": "7.18.2",
37
+ "@babel/preset-env": "7.18.10",
38
38
  "@rollup/plugin-json": "4.1.0",
39
- c8: "7.11.3",
40
- "core-js": "3.22.7",
39
+ c8: "7.12.0",
40
+ "core-js": "3.24.1",
41
41
  "eslint-plugin-ghost": "2.14.0",
42
42
  mocha: "10.0.0",
43
- rollup: "2.74.1",
43
+ rollup: "2.77.2",
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": "^0.9.0",
47
+ "rollup-plugin-polyfill-node": "0.10.2",
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 = "f5a8a2c81a4afc3640f922ef221ea1b6ddfa216a";
56
+ var gitHead = "9251588cb81347205c5dab850636bba4c86fe58d";
57
57
  var packageInfo = {
58
58
  name: name$1,
59
59
  version: version,
@@ -73,10 +73,12 @@ 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
- // NOTE: bump this default when Ghost v5 is released
79
- const defaultAcceptVersionHeader = 'v4.0';
81
+ const defaultAcceptVersionHeader = 'v5.0';
80
82
  const supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
81
83
  const name = '@tryghost/content-api';
82
84
 
@@ -123,10 +125,11 @@ const defaultMakeRequest = ({url, method, params, headers}) => {
123
125
  * @param {String} options.key
124
126
  * @param {String} [options.ghostPath]
125
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
126
129
  * @param {Function} [options.makeRequest]
127
130
  * @param {String} [options.host] Deprecated
128
131
  */
129
- function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequest = defaultMakeRequest}) {
132
+ function GhostContentAPI({url, key, host, version, userAgent, ghostPath = 'ghost', makeRequest = defaultMakeRequest}) {
130
133
  /**
131
134
  * host parameter is deprecated
132
135
  * @deprecated use "url" instead
@@ -140,7 +143,7 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
140
143
  }
141
144
 
142
145
  if (this instanceof GhostContentAPI) {
143
- return GhostContentAPI({url, key, version, ghostPath, makeRequest});
146
+ return GhostContentAPI({url, key, version, userAgent, ghostPath, makeRequest});
144
147
  }
145
148
 
146
149
  if (version === undefined) {
@@ -186,6 +189,11 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
186
189
  if (key && !/[0-9a-f]{26}/.test(key)) {
187
190
  throw new Error(`${name} Config Invalid: 'key' ${key} must have 26 hex characters`);
188
191
  }
192
+
193
+ if (userAgent === undefined) {
194
+ userAgent = USER_AGENT_DEFAULT;
195
+ }
196
+
189
197
  const api = ['posts', 'authors', 'tags', 'pages', 'settings', 'tiers', 'newsletters', 'offers'].reduce((apiObject, resourceType) => {
190
198
  function browse(options = {}, memberToken) {
191
199
  return makeApiRequest(resourceType, options, null, memberToken);
@@ -228,7 +236,14 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
228
236
  Authorization: `GhostMembers ${membersToken}`
229
237
  } : {};
230
238
 
231
- headers['User-Agent'] = `GhostContentSDK/${packageVersion}`;
239
+ if (userAgent) {
240
+ if (typeof userAgent === 'boolean') {
241
+ headers['User-Agent'] = `GhostContentSDK/${packageVersion}`;
242
+ } else {
243
+ headers['User-Agent'] = userAgent;
244
+ }
245
+ }
246
+
232
247
  if (acceptVersionHeader) {
233
248
  headers['Accept-Version'] = acceptVersionHeader;
234
249
  }