@pipedream/wordpress_org 0.3.7 → 0.4.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.
- package/actions/create-post/create-post.mjs +17 -2
- package/actions/create-user/create-user.mjs +2 -2
- package/actions/get-user/get-user.mjs +2 -2
- package/actions/search-posts/search-posts.mjs +2 -2
- package/actions/update-post/update-post.mjs +17 -2
- package/actions/update-user/update-user.mjs +2 -2
- package/actions/upload-media/upload-media.mjs +55 -0
- package/common/constants.mjs +4 -0
- package/common/utils.mjs +22 -0
- package/package.json +1 -1
- package/wordpress_org.app.mjs +33 -2
@@ -1,10 +1,11 @@
|
|
1
1
|
import wordpress from "../../wordpress_org.app.mjs";
|
2
|
+
import utils from "../../common/utils.mjs";
|
2
3
|
|
3
4
|
export default {
|
4
5
|
key: "wordpress_org-create-post",
|
5
6
|
name: "Create Post",
|
6
|
-
description: "Creates a post. [See the
|
7
|
-
version: "0.0.
|
7
|
+
description: "Creates a post. [See the documentation](https://developer.wordpress.org/rest-api/reference/posts/#create-a-post)",
|
8
|
+
version: "0.0.4",
|
8
9
|
type: "action",
|
9
10
|
props: {
|
10
11
|
wordpress,
|
@@ -50,6 +51,18 @@ export default {
|
|
50
51
|
"commentStatus",
|
51
52
|
],
|
52
53
|
},
|
54
|
+
meta: {
|
55
|
+
propDefinition: [
|
56
|
+
wordpress,
|
57
|
+
"meta",
|
58
|
+
],
|
59
|
+
},
|
60
|
+
media: {
|
61
|
+
propDefinition: [
|
62
|
+
wordpress,
|
63
|
+
"media",
|
64
|
+
],
|
65
|
+
},
|
53
66
|
},
|
54
67
|
async run({ $ }) {
|
55
68
|
const params = {
|
@@ -60,6 +73,8 @@ export default {
|
|
60
73
|
categories: this.categories,
|
61
74
|
excerpt: this.excerpt,
|
62
75
|
comment_status: this.commentStatus,
|
76
|
+
meta: utils.parseObj(this.meta),
|
77
|
+
featured_media: this.media,
|
63
78
|
};
|
64
79
|
|
65
80
|
const resp = await this.wordpress.createPost(params);
|
@@ -3,8 +3,8 @@ import wordpress from "../../wordpress_org.app.mjs";
|
|
3
3
|
export default {
|
4
4
|
key: "wordpress_org-create-user",
|
5
5
|
name: "Create User",
|
6
|
-
description: "Creates a user. [See the
|
7
|
-
version: "0.0.
|
6
|
+
description: "Creates a user. [See the documentation](https://developer.wordpress.org/rest-api/reference/users/#create-a-user)",
|
7
|
+
version: "0.0.5",
|
8
8
|
type: "action",
|
9
9
|
props: {
|
10
10
|
wordpress,
|
@@ -3,8 +3,8 @@ import wordpress from "../../wordpress_org.app.mjs";
|
|
3
3
|
export default {
|
4
4
|
key: "wordpress_org-get-user",
|
5
5
|
name: "Get User",
|
6
|
-
description: "Retrieves information for a user. [See the
|
7
|
-
version: "0.0.
|
6
|
+
description: "Retrieves information for a user. [See the documentation](https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user-2)",
|
7
|
+
version: "0.0.3",
|
8
8
|
type: "action",
|
9
9
|
props: {
|
10
10
|
wordpress,
|
@@ -3,8 +3,8 @@ import wordpress from "../../wordpress_org.app.mjs";
|
|
3
3
|
export default {
|
4
4
|
key: "wordpress_org-search-posts",
|
5
5
|
name: "Search Posts",
|
6
|
-
description: "Searches for specific posts. [See the
|
7
|
-
version: "0.0.
|
6
|
+
description: "Searches for specific posts. [See the documentation](https://developer.wordpress.org/rest-api/reference/posts/#list-posts)",
|
7
|
+
version: "0.0.4",
|
8
8
|
type: "action",
|
9
9
|
props: {
|
10
10
|
wordpress,
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import wordpress from "../../wordpress_org.app.mjs";
|
2
|
+
import utils from "../../common/utils.mjs";
|
2
3
|
|
3
4
|
export default {
|
4
5
|
key: "wordpress_org-update-post",
|
5
6
|
name: "Update Post",
|
6
|
-
description: "Updates a post specified by its ID. [See the
|
7
|
-
version: "0.0.
|
7
|
+
description: "Updates a post specified by its ID. [See the documentation](https://developer.wordpress.org/rest-api/reference/posts/#update-a-post)",
|
8
|
+
version: "0.0.4",
|
8
9
|
type: "action",
|
9
10
|
props: {
|
10
11
|
wordpress,
|
@@ -58,6 +59,18 @@ export default {
|
|
58
59
|
"commentStatus",
|
59
60
|
],
|
60
61
|
},
|
62
|
+
meta: {
|
63
|
+
propDefinition: [
|
64
|
+
wordpress,
|
65
|
+
"meta",
|
66
|
+
],
|
67
|
+
},
|
68
|
+
media: {
|
69
|
+
propDefinition: [
|
70
|
+
wordpress,
|
71
|
+
"media",
|
72
|
+
],
|
73
|
+
},
|
61
74
|
},
|
62
75
|
async run({ $ }) {
|
63
76
|
const params = {
|
@@ -68,6 +81,8 @@ export default {
|
|
68
81
|
categories: this.categories,
|
69
82
|
excerpt: this.excerpt,
|
70
83
|
comment_status: this.commentStatus,
|
84
|
+
meta: utils.parseObj(this.meta),
|
85
|
+
featured_media: this.media,
|
71
86
|
};
|
72
87
|
|
73
88
|
const resp = await this.wordpress.updatePost(this.post, params);
|
@@ -4,8 +4,8 @@ import pickBy from "lodash.pickby";
|
|
4
4
|
export default {
|
5
5
|
key: "wordpress_org-update-user",
|
6
6
|
name: "Update User",
|
7
|
-
description: "Updates the information of a user. [See the
|
8
|
-
version: "0.0.
|
7
|
+
description: "Updates the information of a user. [See the documentation](https://developer.wordpress.org/rest-api/reference/users/#update-a-user-2)",
|
8
|
+
version: "0.0.3",
|
9
9
|
type: "action",
|
10
10
|
props: {
|
11
11
|
wordpress,
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import wordpress from "../../wordpress_org.app.mjs";
|
2
|
+
import utils from "../../common/utils.mjs";
|
3
|
+
import fs from "fs";
|
4
|
+
|
5
|
+
export default {
|
6
|
+
key: "wordpress_org-upload-media",
|
7
|
+
name: "Upload Media",
|
8
|
+
description: "Upload a media item to your WordPress media library. Returns a media ID to be used in creating or updating posts.[See the documentation](https://www.npmjs.com/package/wpapi#uploading-media)",
|
9
|
+
version: "0.0.1",
|
10
|
+
type: "action",
|
11
|
+
props: {
|
12
|
+
wordpress,
|
13
|
+
filePath: {
|
14
|
+
type: "string",
|
15
|
+
label: "File Path",
|
16
|
+
description: "The path to a document file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#the-tmp-directory).",
|
17
|
+
},
|
18
|
+
title: {
|
19
|
+
propDefinition: [
|
20
|
+
wordpress,
|
21
|
+
"title",
|
22
|
+
],
|
23
|
+
description: "Title of the media item",
|
24
|
+
optional: true,
|
25
|
+
},
|
26
|
+
altText: {
|
27
|
+
type: "string",
|
28
|
+
label: "Alt Text",
|
29
|
+
description: "Alternative text to display when media is not displayed",
|
30
|
+
optional: true,
|
31
|
+
},
|
32
|
+
description: {
|
33
|
+
propDefinition: [
|
34
|
+
wordpress,
|
35
|
+
"description",
|
36
|
+
],
|
37
|
+
description: "Description of the media item",
|
38
|
+
optional: true,
|
39
|
+
},
|
40
|
+
},
|
41
|
+
async run({ $ }) {
|
42
|
+
const content = fs.createReadStream(utils.getFilePath(this.filePath));
|
43
|
+
|
44
|
+
const params = utils.cleanObj({
|
45
|
+
title: this.title,
|
46
|
+
alt_text: this.altText,
|
47
|
+
description: this.description,
|
48
|
+
});
|
49
|
+
const response = await this.wordpress.createMedia(content, params);
|
50
|
+
|
51
|
+
$.export("$summary", "Successfully uploaded media.");
|
52
|
+
|
53
|
+
return response;
|
54
|
+
},
|
55
|
+
};
|
package/common/constants.mjs
CHANGED
package/common/utils.mjs
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
export default {
|
2
|
+
parseObj(obj) {
|
3
|
+
return !obj
|
4
|
+
? undefined
|
5
|
+
: typeof obj === "string"
|
6
|
+
? JSON.parse(obj)
|
7
|
+
: obj;
|
8
|
+
},
|
9
|
+
cleanObj(o) {
|
10
|
+
for (var k in o || {}) {
|
11
|
+
if (typeof o[k] === "undefined") {
|
12
|
+
delete o[k];
|
13
|
+
}
|
14
|
+
}
|
15
|
+
return o;
|
16
|
+
},
|
17
|
+
getFilePath(path) {
|
18
|
+
return path.includes("tmp/")
|
19
|
+
? path
|
20
|
+
: `/tmp/${path}`;
|
21
|
+
},
|
22
|
+
};
|
package/package.json
CHANGED
package/wordpress_org.app.mjs
CHANGED
@@ -29,9 +29,10 @@ export default {
|
|
29
29
|
optional: true,
|
30
30
|
},
|
31
31
|
commentStatus: {
|
32
|
-
type: "
|
32
|
+
type: "string",
|
33
33
|
label: "Comment Status",
|
34
34
|
description: "Whether or not comments are allowed on the post",
|
35
|
+
options: constants.COMMENT_STATUS,
|
35
36
|
optional: true,
|
36
37
|
},
|
37
38
|
username: {
|
@@ -60,7 +61,7 @@ export default {
|
|
60
61
|
email: {
|
61
62
|
type: "string",
|
62
63
|
label: "Email",
|
63
|
-
description: "
|
64
|
+
description: "The email address for the user",
|
64
65
|
},
|
65
66
|
url: {
|
66
67
|
type: "string",
|
@@ -149,6 +150,25 @@ export default {
|
|
149
150
|
}));
|
150
151
|
},
|
151
152
|
},
|
153
|
+
media: {
|
154
|
+
type: "string",
|
155
|
+
label: "Featured Media",
|
156
|
+
description: "Identifier of an uploaded media item",
|
157
|
+
optional: true,
|
158
|
+
async options({ page }) {
|
159
|
+
const media = await this.listMedia(page + 1);
|
160
|
+
return media.map((item) => ({
|
161
|
+
label: item?.title?.rendered || item.id,
|
162
|
+
value: item.id,
|
163
|
+
}));
|
164
|
+
},
|
165
|
+
},
|
166
|
+
meta: {
|
167
|
+
type: "object",
|
168
|
+
label: "Meta",
|
169
|
+
description: "Metafields for the post. Note: Metafield keys must be registered in your Wordpress instance.",
|
170
|
+
optional: true,
|
171
|
+
},
|
152
172
|
},
|
153
173
|
methods: {
|
154
174
|
async getClient() {
|
@@ -231,5 +251,16 @@ export default {
|
|
231
251
|
const wp = await this.getClient();
|
232
252
|
return wp.users().create(params);
|
233
253
|
},
|
254
|
+
async createMedia(file, params) {
|
255
|
+
const wp = await this.getClient();
|
256
|
+
return wp.media()
|
257
|
+
.file(file)
|
258
|
+
.create(params);
|
259
|
+
},
|
260
|
+
async listMedia(page) {
|
261
|
+
const wp = await this.getClient();
|
262
|
+
return wp.media().perPage(PER_PAGE)
|
263
|
+
.page(page);
|
264
|
+
},
|
234
265
|
},
|
235
266
|
};
|