@tryghost/admin-api 1.9.0 → 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.
Files changed (2) hide show
  1. package/lib/index.js +10 -5
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -3,6 +3,9 @@ const FormData = require('form-data');
3
3
  const fs = require('fs');
4
4
  const token = require('./token');
5
5
 
6
+ const packageInfo = require('../package.json');
7
+ const packageVersion = packageInfo.version;
8
+
6
9
  // NOTE: bump this default when Ghost v5 is released
7
10
  const defaultAcceptVersionHeader = 'v4.0';
8
11
  const supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
@@ -33,7 +36,7 @@ const resolveAPIPrefix = (version) => {
33
36
  * @param {Object} options
34
37
  * @param {String} options.url
35
38
  * @param {String} [options.ghostPath]
36
- * @param {String|Boolean} [options.version] - a version string like v3.2, v4.1, v5.8 or boolean 'false' value identifying no Accept-Version header
39
+ * @param {String|Boolean} options.version - a version string like v3.2, v4.1, v5.8 or boolean value identifying presence of Accept-Version header
37
40
  * @param {Function} [options.makeRequest]
38
41
  * @param {Function} [options.generateToken]
39
42
  * @param {String} [options.host] Deprecated
@@ -46,7 +49,6 @@ module.exports = function GhostAdminAPI(options) {
46
49
  const defaultConfig = {
47
50
  ghostPath: 'ghost',
48
51
  generateToken: token,
49
- sendAcceptVersionHeader: true,
50
52
  makeRequest({url, method, data, params = {}, headers = {}}) {
51
53
  return axios({
52
54
  url,
@@ -88,8 +90,6 @@ module.exports = function GhostAdminAPI(options) {
88
90
  }
89
91
 
90
92
  if (typeof config.version === 'boolean') {
91
- config.sendAcceptVersionHeader = config.version;
92
-
93
93
  if (config.version === true) {
94
94
  config.acceptVersionHeader = defaultAcceptVersionHeader;
95
95
  }
@@ -141,6 +141,10 @@ module.exports = function GhostAdminAPI(options) {
141
141
  'users'
142
142
  ];
143
143
 
144
+ if (typeof config.version === 'string' && config.version.startsWith('v2')) {
145
+ resources.push('subscribers');
146
+ }
147
+
144
148
  const api = resources.reduce((apiObject, resourceType) => {
145
149
  function add(data, queryParams = {}) {
146
150
  if (!data || !Object.keys(data).length) {
@@ -416,7 +420,8 @@ module.exports = function GhostAdminAPI(options) {
416
420
  authorizationHeader = `Ghost ${config.generateToken(key, audience)}`;
417
421
 
418
422
  const ghostHeaders = {
419
- Authorization: authorizationHeader
423
+ Authorization: authorizationHeader,
424
+ 'User-Agent': `GhostAdminSDK/${packageVersion}`
420
425
  };
421
426
 
422
427
  if (config.acceptVersionHeader) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/admin-api",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "repository": "https://github.com/TryGhost/SDK/tree/master/packages/admin-api",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -31,5 +31,5 @@
31
31
  "form-data": "^4.0.0",
32
32
  "jsonwebtoken": "^8.4.0"
33
33
  },
34
- "gitHead": "b4c9597d781809903118a07e5fba16a106ec6053"
34
+ "gitHead": "db46574e3958a2487e8ccdcfb735fbe5de2a2731"
35
35
  }