@tryghost/content-api 1.9.0 → 1.9.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.9.0";
6
+ var version = "1.9.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";
@@ -35,7 +35,7 @@ var devDependencies = {
35
35
  "@babel/core": "7.17.9",
36
36
  "@babel/polyfill": "7.12.1",
37
37
  "@babel/preset-env": "7.16.11",
38
- "@rollup/plugin-json": "^4.1.0",
38
+ "@rollup/plugin-json": "4.1.0",
39
39
  c8: "7.11.0",
40
40
  "core-js": "3.22.0",
41
41
  "eslint-plugin-ghost": "1.5.0",
@@ -52,7 +52,7 @@ var devDependencies = {
52
52
  var dependencies = {
53
53
  axios: "^0.21.1"
54
54
  };
55
- var gitHead = "f699f18279c596be384760adccbbf90a659bd4bc";
55
+ var gitHead = "6c0165f2588537f0e00e76567c2ed2f526f7faff";
56
56
  var packageInfo = {
57
57
  name: name$1,
58
58
  version: version,
@@ -79,6 +79,29 @@ const defaultAcceptVersionHeader = 'v4.0';
79
79
  const supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
80
80
  const name = '@tryghost/content-api';
81
81
 
82
+ /**
83
+ * This method can go away in favor of only sending 'Accept-Version` headers
84
+ * once the Ghost API removes a concept of version from it's URLS (with Ghost v5)
85
+ *
86
+ * @param {string} [version] version in `v{major}` format
87
+ * @returns {string}
88
+ */
89
+ const resolveAPIPrefix = (version) => {
90
+ let prefix;
91
+
92
+ // NOTE: the "version.match(/^v5\.\d+/)" expression should be changed to "version.match(/^v\d+\.\d+/)" once Ghost v5 is out
93
+ if (version === 'v5' || version === undefined || version.match(/^v5\.\d+/)) {
94
+ prefix = `/content/`;
95
+ } else if (version.match(/^v\d+\.\d+/)) {
96
+ const versionPrefix = /^(v\d+)\.\d+/.exec(version)[1];
97
+ prefix = `/${versionPrefix}/content/`;
98
+ } else {
99
+ prefix = `/${version}/content/`;
100
+ }
101
+
102
+ return prefix;
103
+ };
104
+
82
105
  const defaultMakeRequest = ({url, method, params, headers}) => {
83
106
  return axios[method](url, {
84
107
  params,
@@ -206,9 +229,7 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
206
229
  }
207
230
 
208
231
  params = Object.assign({key}, params);
209
- const apiUrl = version
210
- ? `${url}/${ghostPath}/api/${version}/content/${resourceType}/${id ? id + '/' : ''}`
211
- : `${url}/${ghostPath}/api/content/${resourceType}/${id ? id + '/' : ''}`;
232
+ const apiUrl = `${url}/${ghostPath}/api${resolveAPIPrefix(version)}${resourceType}/${id ? id + '/' : ''}`;
212
233
 
213
234
  return makeRequest({
214
235
  url: apiUrl,