@miso.ai/server-wordpress 0.6.5-beta.5 → 0.6.5-beta.7

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.
package/cli/index.js CHANGED
@@ -4,6 +4,7 @@ import version from '../src/version.js';
4
4
  import { profile, init } from './profile.js';
5
5
  import taxonomies from './taxonomies.js';
6
6
  import entities from './entities.js';
7
+ import types from './types.js';
7
8
  import summarize from './summarize.js';
8
9
  import download from './download.js';
9
10
  import xml from './xml.js';
@@ -33,6 +34,7 @@ yargs.build(yargs => {
33
34
  .command(summarize)
34
35
  .command(download)
35
36
  .command(taxonomies)
37
+ .command(types)
36
38
  .command(entities)
37
39
  .version(version);
38
40
  });
package/cli/types.js ADDED
@@ -0,0 +1,20 @@
1
+ import { WordPressClient } from '../src/index.js';
2
+
3
+ function build(yargs) {
4
+ return yargs;
5
+ }
6
+
7
+ async function run(options) {
8
+ const client = new WordPressClient(options);
9
+ const types = await client.types({ noCache: true });
10
+ for (const type of types) {
11
+ console.log(JSON.stringify(type));
12
+ }
13
+ }
14
+
15
+ export default {
16
+ command: 'types',
17
+ desc: 'List all post types from WordPress REST API',
18
+ builder: build,
19
+ handler: run,
20
+ };
package/package.json CHANGED
@@ -17,12 +17,12 @@
17
17
  "simonpai <simon.pai@askmiso.com>"
18
18
  ],
19
19
  "dependencies": {
20
- "@miso.ai/server-commons": "0.6.5-beta.5",
20
+ "@miso.ai/server-commons": "0.6.5-beta.7",
21
21
  "axios": "^1.6.2",
22
22
  "axios-retry": "^3.3.1",
23
23
  "dotenv": "^16.4.5",
24
24
  "saxes": "^6.0.0",
25
25
  "split2": "^4.2.0"
26
26
  },
27
- "version": "0.6.5-beta.5"
27
+ "version": "0.6.5-beta.7"
28
28
  }
package/src/client.js CHANGED
@@ -52,6 +52,10 @@ export default class WordPressClient {
52
52
  return this._helpers.taxonomies(options);
53
53
  }
54
54
 
55
+ types(options) {
56
+ return this._helpers.types(options);
57
+ }
58
+
55
59
  get posts() {
56
60
  return this.entities('posts');
57
61
  }
package/src/helpers.js CHANGED
@@ -104,6 +104,21 @@ export default class Helpers {
104
104
  return Object.values(data);
105
105
  }
106
106
 
107
+ async types({ noCache = false } = {}) {
108
+ if (noCache || !this._types) {
109
+ // don't await, save the promise
110
+ this._types = this._fetchTypes();
111
+ }
112
+ return this._types;
113
+ }
114
+
115
+ async _fetchTypes() {
116
+ const url = await this.url.build('types');
117
+ const { data } = await this.axios.get(url);
118
+ this.debug(`Fetched types.`);
119
+ return Object.values(data);
120
+ }
121
+
107
122
  extractTerms(data) {
108
123
  return data._links['wp:term'] || [];
109
124
  }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.6.5-beta.5';
1
+ export default '0.6.5-beta.7';