@tryghost/content-api 1.10.1 → 1.11.2

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.1";
6
+ var version = "1.11.2";
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.19.0",
36
36
  "@babel/polyfill": "7.12.1",
37
- "@babel/preset-env": "7.18.2",
37
+ "@babel/preset-env": "7.19.0",
38
38
  "@rollup/plugin-json": "4.1.0",
39
- c8: "7.11.3",
40
- "core-js": "3.22.7",
41
- "eslint-plugin-ghost": "2.14.0",
39
+ c8: "7.12.0",
40
+ "core-js": "3.25.0",
41
+ "eslint-plugin-ghost": "2.15.1",
42
42
  mocha: "10.0.0",
43
- rollup: "2.74.1",
43
+ rollup: "2.79.0",
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 = "ce790579ad1f191b24c05733d8a0a56f0b9f96d2";
56
+ var gitHead = "3547712bea5948482aabe9cbe484561501885de9";
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
- 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
+
231
247
  if (acceptVersionHeader) {
232
248
  headers['Accept-Version'] = acceptVersionHeader;
233
249
  }