@tryghost/content-api 1.8.0 → 1.9.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.
@@ -2,11 +2,106 @@
2
2
 
3
3
  var axios = require('axios');
4
4
 
5
+ var name$1 = "@tryghost/content-api";
6
+ var version = "1.9.2";
7
+ var repository = "https://github.com/TryGhost/SDK/tree/master/packages/content-api";
8
+ var author = "Ghost Foundation";
9
+ var license = "MIT";
10
+ var main = "cjs/content-api.js";
11
+ var unpkg = "umd/content-api.min.js";
12
+ var module$1 = "es/content-api.js";
13
+ var source = "lib/content-api.js";
14
+ var files = [
15
+ "LICENSE",
16
+ "README.md",
17
+ "cjs/",
18
+ "lib/",
19
+ "umd/",
20
+ "es/"
21
+ ];
22
+ var scripts = {
23
+ dev: "echo \"Implement me!\"",
24
+ pretest: "yarn build",
25
+ test: "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'",
26
+ build: "rollup -c",
27
+ lint: "eslint . --ext .js --cache",
28
+ prepare: "NODE_ENV=production yarn build",
29
+ posttest: "yarn lint"
30
+ };
31
+ var publishConfig = {
32
+ access: "public"
33
+ };
34
+ var devDependencies = {
35
+ "@babel/core": "7.17.10",
36
+ "@babel/polyfill": "7.12.1",
37
+ "@babel/preset-env": "7.17.10",
38
+ "@rollup/plugin-json": "4.1.0",
39
+ c8: "7.11.2",
40
+ "core-js": "3.22.4",
41
+ "eslint-plugin-ghost": "2.13.0",
42
+ mocha: "10.0.0",
43
+ rollup: "2.71.1",
44
+ "rollup-plugin-babel": "4.4.0",
45
+ "rollup-plugin-commonjs": "10.1.0",
46
+ "rollup-plugin-node-resolve": "5.2.0",
47
+ "rollup-plugin-replace": "2.2.0",
48
+ "rollup-plugin-terser": "7.0.2",
49
+ should: "13.2.3",
50
+ sinon: "13.0.2"
51
+ };
52
+ var dependencies = {
53
+ axios: "^0.27.0"
54
+ };
55
+ var gitHead = "0a30384f3d568a43bfe0cee5fcf7e21c17a17842";
56
+ var packageInfo = {
57
+ name: name$1,
58
+ version: version,
59
+ repository: repository,
60
+ author: author,
61
+ license: license,
62
+ main: main,
63
+ "umd:main": "umd/content-api.min.js",
64
+ unpkg: unpkg,
65
+ module: module$1,
66
+ source: source,
67
+ files: files,
68
+ scripts: scripts,
69
+ publishConfig: publishConfig,
70
+ devDependencies: devDependencies,
71
+ dependencies: dependencies,
72
+ gitHead: gitHead
73
+ };
74
+
75
+ const packageVersion = packageInfo.version;
76
+
5
77
  // NOTE: bump this default when Ghost v5 is released
6
78
  const defaultAcceptVersionHeader = 'v4.0';
7
79
  const supportedVersions = ['v2', 'v3', 'v4', 'v5', 'canary'];
8
80
  const name = '@tryghost/content-api';
9
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
+
10
105
  const defaultMakeRequest = ({url, method, params, headers}) => {
11
106
  return axios[method](url, {
12
107
  params,
@@ -128,14 +223,13 @@ function GhostContentAPI({url, key, host, version, ghostPath = 'ghost', makeRequ
128
223
  Authorization: `GhostMembers ${membersToken}`
129
224
  } : {};
130
225
 
226
+ headers['User-Agent'] = `GhostContentSDK/${packageVersion}`;
131
227
  if (acceptVersionHeader) {
132
228
  headers['Accept-Version'] = acceptVersionHeader;
133
229
  }
134
230
 
135
231
  params = Object.assign({key}, params);
136
- const apiUrl = version
137
- ? `${url}/${ghostPath}/api/${version}/content/${resourceType}/${id ? id + '/' : ''}`
138
- : `${url}/${ghostPath}/api/content/${resourceType}/${id ? id + '/' : ''}`;
232
+ const apiUrl = `${url}/${ghostPath}/api${resolveAPIPrefix(version)}${resourceType}/${id ? id + '/' : ''}`;
139
233
 
140
234
  return makeRequest({
141
235
  url: apiUrl,