Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a7bd19e61f | ||
![]() |
3d4a9865fe | ||
![]() |
c191b7a3cf | ||
![]() |
69416c24e2 | ||
![]() |
2460e9f281 | ||
![]() |
fbae83f4de | ||
![]() |
1dc9646894 |
262
packages/backend/src/apps/wordpress/actions/create-post/index.js
Normal file
262
packages/backend/src/apps/wordpress/actions/create-post/index.js
Normal file
@@ -0,0 +1,262 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
import isEmpty from 'lodash/isEmpty.js';
|
||||
import omitBy from 'lodash/omitBy.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create post',
|
||||
key: 'createPost',
|
||||
description: 'Creates a new post.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Title',
|
||||
key: 'title',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Content',
|
||||
key: 'content',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Excerpt',
|
||||
key: 'excerpt',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Password',
|
||||
key: 'password',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: 'A password to protect access to the content and excerpt.',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Author',
|
||||
key: 'author',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listUsers',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Featured Media',
|
||||
key: 'featuredMedia',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listMedia',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Comment Status',
|
||||
key: 'commentStatus',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Open', value: 'open' },
|
||||
{ label: 'Closed', value: 'closed' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Ping Status',
|
||||
key: 'pingStatus',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Open', value: 'open' },
|
||||
{ label: 'Closed', value: 'closed' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Format',
|
||||
key: 'format',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Standard', value: 'standard' },
|
||||
{ label: 'Aside', value: 'aside' },
|
||||
{ label: 'Chat', value: 'chat' },
|
||||
{ label: 'Gallery', value: 'gallery' },
|
||||
{ label: 'Link', value: 'link' },
|
||||
{ label: 'Image', value: 'image' },
|
||||
{ label: 'Quote', value: 'quote' },
|
||||
{ label: 'Status', value: 'status' },
|
||||
{ label: 'Status', value: 'status' },
|
||||
{ label: 'Video', value: 'video' },
|
||||
{ label: 'Audio', value: 'audio' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Sticky',
|
||||
key: 'sticky',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'False', value: 'false' },
|
||||
{ label: 'True', value: 'true' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Categories',
|
||||
key: 'categoryIds',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
description: '',
|
||||
fields: [
|
||||
{
|
||||
label: 'Category',
|
||||
key: 'categoryId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listCategories',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Tags',
|
||||
key: 'tagIds',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
description: '',
|
||||
fields: [
|
||||
{
|
||||
label: 'Tag',
|
||||
key: 'tagId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listTags',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Status',
|
||||
key: 'status',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listStatuses',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Date',
|
||||
key: 'date',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: "Post publish date in the site's timezone",
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const {
|
||||
title,
|
||||
content,
|
||||
excerpt,
|
||||
password,
|
||||
author,
|
||||
featuredMedia,
|
||||
commentStatus,
|
||||
pingStatus,
|
||||
format,
|
||||
sticky,
|
||||
categoryIds,
|
||||
tagIds,
|
||||
status,
|
||||
date,
|
||||
} = $.step.parameters;
|
||||
|
||||
const allCategoryIds = categoryIds
|
||||
?.map((categoryId) => categoryId.categoryId)
|
||||
.filter(Boolean);
|
||||
|
||||
const allTagIds = tagIds?.map((tagId) => tagId.tagId).filter(Boolean);
|
||||
|
||||
let body = {
|
||||
title,
|
||||
content,
|
||||
excerpt,
|
||||
password,
|
||||
author,
|
||||
featured_media: featuredMedia,
|
||||
comment_status: commentStatus,
|
||||
ping_status: pingStatus,
|
||||
format,
|
||||
sticky,
|
||||
categories: allCategoryIds,
|
||||
tags: allTagIds,
|
||||
status,
|
||||
date,
|
||||
};
|
||||
|
||||
body = omitBy(body, isEmpty);
|
||||
|
||||
const response = await $.http.post('?rest_route=/wp/v2/posts', body);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
135
packages/backend/src/apps/wordpress/actions/create-user/index.js
Normal file
135
packages/backend/src/apps/wordpress/actions/create-user/index.js
Normal file
@@ -0,0 +1,135 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
import isEmpty from 'lodash/isEmpty.js';
|
||||
import omitBy from 'lodash/omitBy.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create user',
|
||||
key: 'createUser',
|
||||
description: 'Creates a new user.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Email',
|
||||
key: 'email',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Username',
|
||||
key: 'username',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Password',
|
||||
key: 'password',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'First Name',
|
||||
key: 'firstName',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Last Name',
|
||||
key: 'lastName',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Display Name',
|
||||
key: 'displayName',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Nickname',
|
||||
key: 'nickname',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Description',
|
||||
key: 'description',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Website',
|
||||
key: 'website',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Role',
|
||||
key: 'role',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Administrator', value: 'administrator' },
|
||||
{ label: 'Author', value: 'author' },
|
||||
{ label: 'Contributor', value: 'contributor' },
|
||||
{ label: 'Editor', value: 'editor' },
|
||||
{ label: 'Subscriber', value: 'subscriber' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const {
|
||||
email,
|
||||
username,
|
||||
password,
|
||||
firstName,
|
||||
lastName,
|
||||
displayName,
|
||||
nickname,
|
||||
description,
|
||||
website,
|
||||
role,
|
||||
} = $.step.parameters;
|
||||
|
||||
let body = {
|
||||
email,
|
||||
username,
|
||||
password,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
name: displayName,
|
||||
nickname,
|
||||
description,
|
||||
url: website,
|
||||
};
|
||||
|
||||
if (role) {
|
||||
body.roles = [role];
|
||||
}
|
||||
|
||||
body = omitBy(body, isEmpty);
|
||||
|
||||
const response = await $.http.post('?rest_route=/wp/v2/users', body);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
@@ -0,0 +1,35 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Find post',
|
||||
key: 'findPost',
|
||||
description: 'Finds a post.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Post ID',
|
||||
key: 'postId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: 'Choose a post to update.',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listPosts',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const { postId } = $.step.parameters;
|
||||
|
||||
const response = await $.http.get(`?rest_route=/wp/v2/posts/${postId}`);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
@@ -0,0 +1,35 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Find user',
|
||||
key: 'findUser',
|
||||
description: 'Finds a user.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'User ID',
|
||||
key: 'userId',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listUsers',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const userId = $.step.parameters.userId;
|
||||
|
||||
const response = await $.http.get(`?rest_route=/wp/v2/users/${userId}`);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
7
packages/backend/src/apps/wordpress/actions/index.js
Normal file
7
packages/backend/src/apps/wordpress/actions/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import createPost from './create-post/index.js';
|
||||
import createUser from './create-user/index.js';
|
||||
import findPost from './find-post/index.js';
|
||||
import findUser from './find-user/index.js';
|
||||
import updatePost from './update-post/index.js';
|
||||
|
||||
export default [createPost, createUser, findPost, findUser, updatePost];
|
284
packages/backend/src/apps/wordpress/actions/update-post/index.js
Normal file
284
packages/backend/src/apps/wordpress/actions/update-post/index.js
Normal file
@@ -0,0 +1,284 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
import isEmpty from 'lodash/isEmpty.js';
|
||||
import omitBy from 'lodash/omitBy.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Update post',
|
||||
key: 'updatePost',
|
||||
description: 'Updates a post.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Post',
|
||||
key: 'postId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: 'Choose a post to update.',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listPosts',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Title',
|
||||
key: 'title',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Content',
|
||||
key: 'content',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Excerpt',
|
||||
key: 'excerpt',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Password',
|
||||
key: 'password',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: 'A password to protect access to the content and excerpt.',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Author',
|
||||
key: 'author',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listUsers',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Featured Media',
|
||||
key: 'featuredMedia',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listMedia',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Comment Status',
|
||||
key: 'commentStatus',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Open', value: 'open' },
|
||||
{ label: 'Closed', value: 'closed' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Ping Status',
|
||||
key: 'pingStatus',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Open', value: 'open' },
|
||||
{ label: 'Closed', value: 'closed' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Format',
|
||||
key: 'format',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'Standard', value: 'standard' },
|
||||
{ label: 'Aside', value: 'aside' },
|
||||
{ label: 'Chat', value: 'chat' },
|
||||
{ label: 'Gallery', value: 'gallery' },
|
||||
{ label: 'Link', value: 'link' },
|
||||
{ label: 'Image', value: 'image' },
|
||||
{ label: 'Quote', value: 'quote' },
|
||||
{ label: 'Status', value: 'status' },
|
||||
{ label: 'Status', value: 'status' },
|
||||
{ label: 'Video', value: 'video' },
|
||||
{ label: 'Audio', value: 'audio' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Sticky',
|
||||
key: 'sticky',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{ label: 'False', value: 'false' },
|
||||
{ label: 'True', value: 'true' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Categories',
|
||||
key: 'categoryIds',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
description: '',
|
||||
fields: [
|
||||
{
|
||||
label: 'Category',
|
||||
key: 'categoryId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listCategories',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Tags',
|
||||
key: 'tagIds',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
description: '',
|
||||
fields: [
|
||||
{
|
||||
label: 'Tag',
|
||||
key: 'tagId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listTags',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Status',
|
||||
key: 'status',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listStatuses',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Date',
|
||||
key: 'date',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: "Post publish date in the site's timezone",
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const {
|
||||
postId,
|
||||
title,
|
||||
content,
|
||||
excerpt,
|
||||
password,
|
||||
author,
|
||||
featuredMedia,
|
||||
commentStatus,
|
||||
pingStatus,
|
||||
format,
|
||||
sticky,
|
||||
categoryIds,
|
||||
tagIds,
|
||||
status,
|
||||
date,
|
||||
} = $.step.parameters;
|
||||
|
||||
const allCategoryIds = categoryIds
|
||||
?.map((categoryId) => categoryId.categoryId)
|
||||
.filter(Boolean);
|
||||
|
||||
const allTagIds = tagIds?.map((tagId) => tagId.tagId).filter(Boolean);
|
||||
|
||||
let body = {
|
||||
title,
|
||||
content,
|
||||
excerpt,
|
||||
password,
|
||||
author,
|
||||
featured_media: featuredMedia,
|
||||
comment_status: commentStatus,
|
||||
ping_status: pingStatus,
|
||||
format,
|
||||
sticky,
|
||||
categories: allCategoryIds,
|
||||
tags: allTagIds,
|
||||
status,
|
||||
date,
|
||||
};
|
||||
|
||||
body = omitBy(body, isEmpty);
|
||||
|
||||
const response = await $.http.post(
|
||||
`?rest_route=/wp/v2/posts/${postId}`,
|
||||
body
|
||||
);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
@@ -1,3 +1,15 @@
|
||||
import listCategories from './list-categories/index.js';
|
||||
import listMedia from './list-media/index.js';
|
||||
import listPosts from './list-posts/index.js';
|
||||
import listStatuses from './list-statuses/index.js';
|
||||
import listTags from './list-tags/index.js';
|
||||
import listUsers from './list-users/index.js';
|
||||
|
||||
export default [listStatuses];
|
||||
export default [
|
||||
listCategories,
|
||||
listMedia,
|
||||
listPosts,
|
||||
listStatuses,
|
||||
listTags,
|
||||
listUsers,
|
||||
];
|
||||
|
@@ -0,0 +1,40 @@
|
||||
export default {
|
||||
name: 'List categories',
|
||||
key: 'listCategories',
|
||||
|
||||
async run($) {
|
||||
const categories = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
order: 'desc',
|
||||
};
|
||||
|
||||
let totalPages = 1;
|
||||
do {
|
||||
const { data, headers } = await $.http.get(
|
||||
'?rest_route=/wp/v2/categories',
|
||||
{
|
||||
params,
|
||||
}
|
||||
);
|
||||
|
||||
params.page = params.page + 1;
|
||||
totalPages = Number(headers['x-wp-totalpages']);
|
||||
|
||||
if (data) {
|
||||
for (const category of data) {
|
||||
categories.data.push({
|
||||
value: category.id,
|
||||
name: category.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.page <= totalPages);
|
||||
|
||||
return categories;
|
||||
},
|
||||
};
|
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
name: 'List media',
|
||||
key: 'listMedia',
|
||||
|
||||
async run($) {
|
||||
const media = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
order: 'desc',
|
||||
};
|
||||
|
||||
let totalPages = 1;
|
||||
do {
|
||||
const { data, headers } = await $.http.get('?rest_route=/wp/v2/media', {
|
||||
params,
|
||||
});
|
||||
|
||||
params.page = params.page + 1;
|
||||
totalPages = Number(headers['x-wp-totalpages']);
|
||||
|
||||
if (data) {
|
||||
for (const medium of data) {
|
||||
media.data.push({
|
||||
value: medium.id,
|
||||
name: medium.slug,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.page <= totalPages);
|
||||
|
||||
return media;
|
||||
},
|
||||
};
|
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
name: 'List posts',
|
||||
key: 'listPosts',
|
||||
|
||||
async run($) {
|
||||
const posts = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
order: 'desc',
|
||||
};
|
||||
|
||||
let totalPages = 1;
|
||||
do {
|
||||
const { data, headers } = await $.http.get('?rest_route=/wp/v2/posts', {
|
||||
params,
|
||||
});
|
||||
|
||||
params.page = params.page + 1;
|
||||
totalPages = Number(headers['x-wp-totalpages']);
|
||||
|
||||
if (data) {
|
||||
for (const post of data) {
|
||||
posts.data.push({
|
||||
value: post.id,
|
||||
name: post.title.rendered,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.page <= totalPages);
|
||||
|
||||
return posts;
|
||||
},
|
||||
};
|
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
name: 'List tags',
|
||||
key: 'listTags',
|
||||
|
||||
async run($) {
|
||||
const tags = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
order: 'desc',
|
||||
};
|
||||
|
||||
let totalPages = 1;
|
||||
do {
|
||||
const { data, headers } = await $.http.get('?rest_route=/wp/v2/tags', {
|
||||
params,
|
||||
});
|
||||
|
||||
params.page = params.page + 1;
|
||||
totalPages = Number(headers['x-wp-totalpages']);
|
||||
|
||||
if (data) {
|
||||
for (const tag of data) {
|
||||
tags.data.push({
|
||||
value: tag.id,
|
||||
name: tag.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.page <= totalPages);
|
||||
|
||||
return tags;
|
||||
},
|
||||
};
|
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
name: 'List users',
|
||||
key: 'listUsers',
|
||||
|
||||
async run($) {
|
||||
const users = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
order: 'desc',
|
||||
};
|
||||
|
||||
let totalPages = 1;
|
||||
do {
|
||||
const { data, headers } = await $.http.get('?rest_route=/wp/v2/users', {
|
||||
params,
|
||||
});
|
||||
|
||||
params.page = params.page + 1;
|
||||
totalPages = Number(headers['x-wp-totalpages']);
|
||||
|
||||
if (data) {
|
||||
for (const user of data) {
|
||||
users.data.push({
|
||||
value: user.id,
|
||||
name: user.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.page <= totalPages);
|
||||
|
||||
return users;
|
||||
},
|
||||
};
|
@@ -4,6 +4,7 @@ import setBaseUrl from './common/set-base-url.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'WordPress',
|
||||
@@ -18,4 +19,5 @@ export default defineApp({
|
||||
auth,
|
||||
triggers,
|
||||
dynamicData,
|
||||
actions,
|
||||
});
|
||||
|
@@ -0,0 +1,11 @@
|
||||
export async function up(knex) {
|
||||
return knex.schema.alterTable('datastore', (table) => {
|
||||
table.text('value').alter();
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex) {
|
||||
return knex.schema.alterTable('datastore', (table) => {
|
||||
table.string('value').alter();
|
||||
});
|
||||
}
|
@@ -518,6 +518,7 @@ export default defineConfig({
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [
|
||||
{ text: 'Actions', link: '/apps/wordpress/actions' },
|
||||
{ text: 'Triggers', link: '/apps/wordpress/triggers' },
|
||||
{ text: 'Connection', link: '/apps/wordpress/connection' },
|
||||
],
|
||||
|
20
packages/docs/pages/apps/wordpress/actions.md
Normal file
20
packages/docs/pages/apps/wordpress/actions.md
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
favicon: /favicons/wordpress.svg
|
||||
items:
|
||||
- name: Create post
|
||||
desc: Creates a new post.
|
||||
- name: Create user
|
||||
desc: Creates a new user.
|
||||
- name: Find post
|
||||
desc: Finds a post.
|
||||
- name: Find user
|
||||
desc: Finds a user.
|
||||
- name: Update post
|
||||
desc: Updates a post.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
Reference in New Issue
Block a user