@tryghost/content-api 1.9.8 → 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.
@@ -3,7 +3,7 @@
3
3
  var axios = require('axios');
4
4
 
5
5
  var name$1 = "@tryghost/content-api";
6
- var version = "1.9.8";
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";
@@ -32,18 +32,19 @@ var publishConfig = {
32
32
  access: "public"
33
33
  };
34
34
  var devDependencies = {
35
- "@babel/core": "7.17.10",
35
+ "@babel/core": "7.18.2",
36
36
  "@babel/polyfill": "7.12.1",
37
- "@babel/preset-env": "7.17.10",
37
+ "@babel/preset-env": "7.18.2",
38
38
  "@rollup/plugin-json": "4.1.0",
39
39
  c8: "7.11.3",
40
- "core-js": "3.22.5",
40
+ "core-js": "3.22.7",
41
41
  "eslint-plugin-ghost": "2.14.0",
42
42
  mocha: "10.0.0",
43
- rollup: "2.73.0",
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": "0.9.0",
47
48
  "rollup-plugin-replace": "2.2.0",
48
49
  "rollup-plugin-terser": "7.0.2",
49
50
  should: "13.2.3",
@@ -52,7 +53,7 @@ var devDependencies = {
52
53
  var dependencies = {
53
54
  axios: "^0.27.0"
54
55
  };
55
- var gitHead = "31e2a37039377b1c785be278a78085cbf0a494f1";
56
+ var gitHead = "a1f560e288bf67886483f9b5d483eecd749c09cc";
56
57
  var packageInfo = {
57
58
  name: name$1,
58
59
  version: version,
@@ -72,10 +73,12 @@ var packageInfo = {
72
73
  gitHead: gitHead
73
74
  };
74
75
 
76
+ // @NOTE: this value is dynamically replaced based on browser/node environment
77
+ const USER_AGENT_DEFAULT = true;
78
+
75
79
  const packageVersion = packageInfo.version;
76
80
 
77
- // NOTE: bump this default when Ghost v5 is released
78
- const defaultAcceptVersionHeader = 'v4.0';
81
+ const defaultAcceptVersionHeader = 'v5.0';
79
82
  const supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
80
83
  const name = '@tryghost/content-api';
81
84
 
@@ -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,7 +189,12 @@ 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
  }
188
- const api = ['posts', 'authors', 'tags', 'pages', 'settings'].reduce((apiObject, resourceType) => {
192
+
193
+ if (userAgent === undefined) {
194
+ userAgent = USER_AGENT_DEFAULT;
195
+ }
196
+
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);
191
200
  }
@@ -207,7 +216,11 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
207
216
  });
208
217
  }, {});
209
218
 
219
+ // Settings, tiers & newsletters only have browse methods, offers only has read
210
220
  delete api.settings.read;
221
+ delete api.tiers.read;
222
+ delete api.newsletters.read;
223
+ delete api.offers.browse;
211
224
 
212
225
  return api;
213
226
 
@@ -223,7 +236,14 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
223
236
  Authorization: `GhostMembers ${membersToken}`
224
237
  } : {};
225
238
 
226
- 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
+
227
247
  if (acceptVersionHeader) {
228
248
  headers['Accept-Version'] = acceptVersionHeader;
229
249
  }