diff --git a/packages/nodes-base/credentials/WordpressApi.credentials.ts b/packages/nodes-base/credentials/WordpressApi.credentials.ts new file mode 100644 index 0000000000..abe75d55d1 --- /dev/null +++ b/packages/nodes-base/credentials/WordpressApi.credentials.ts @@ -0,0 +1,29 @@ +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; + +export class WordpressApi implements ICredentialType { + name = 'wordpressApi'; + displayName = 'Wordpress API'; + properties = [ + { + displayName: 'Username', + name: 'username', + type: 'string' as NodePropertyTypes, + default: '', + }, + { + displayName: 'Password', + name: 'password', + type: 'string' as NodePropertyTypes, + default: '', + }, + { + displayName: 'Domain', + name: 'domain', + type: 'string' as NodePropertyTypes, + default: '', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts b/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts new file mode 100644 index 0000000000..4a5d5550a5 --- /dev/null +++ b/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts @@ -0,0 +1,279 @@ +import { + IExecuteFunctions, +} from 'n8n-core'; +import { + IDataObject, + INodeTypeDescription, + INodeExecutionData, + INodeType, +} from 'n8n-workflow'; +// import { +// flowApiRequest, +// FlowApiRequestAllItems, +// } from './GenericFunctions'; +// import { +// taskOpeations, +// taskFields, +// } from './TaskDescription'; +// import { +// ITask, TaskInfo, +// } from './TaskInterface'; + +export class Wordpress implements INodeType { + description: INodeTypeDescription = { + displayName: 'Wordpress', + name: 'Wordpress', + icon: 'file:wordpress.png', + group: ['output'], + version: 1, + subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', + description: 'Consume Wordpress API', + defaults: { + name: 'Wordpress', + color: '#c02428', + }, + inputs: ['main'], + outputs: ['main'], + credentials: [ + { + name: 'wordpressApi', + required: true, + } + ], + properties: [ + { + displayName: 'Resource', + name: 'resource', + type: 'options', + options: [ + { + name: 'Post', + value: 'post', + description: `The primary unit within Flow; tasks track units of work and can be assigned, sorted, nested, and tagged.
+ Tasks can either be part of a List, or "private" (meaning "without a list", essentially).
+ Through this endpoint you are able to do anything you wish to your tasks in Flow, including create new ones.`, + }, + ], + default: 'task', + description: 'Resource to consume.', + }, + // ...taskOpeations, + // ...taskFields, + ], + }; + + async execute(this: IExecuteFunctions): Promise { + const credentials = this.getCredentials('flowApi'); + + if (credentials === undefined) { + throw new Error('No credentials got returned!'); + } + + const items = this.getInputData(); + const returnData: IDataObject[] = []; + const length = items.length as unknown as number; + let responseData; + const qs: IDataObject = {}; + const resource = this.getNodeParameter('resource', 0) as string; + const operation = this.getNodeParameter('operation', 0) as string; + + // for (let i = 0; i < length; i++) { + // if (resource === 'task') { + // //https://developer.getflow.com/api/#tasks_create-task + // if (operation === 'create') { + // const workspaceId = this.getNodeParameter('workspaceId', i) as string; + // const name = this.getNodeParameter('name', i) as string; + // const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + // const body: ITask = { + // organization_id: credentials.organizationId as number, + // }; + // const task: TaskInfo = { + // name, + // workspace_id: parseInt(workspaceId, 10) + // }; + // if (additionalFields.ownerId) { + // task.owner_id = parseInt(additionalFields.ownerId as string, 10); + // } + // if (additionalFields.listId) { + // task.list_id = parseInt(additionalFields.listId as string, 10); + // } + // if (additionalFields.startsOn) { + // task.starts_on = additionalFields.startsOn as string; + // } + // if (additionalFields.dueOn) { + // task.due_on = additionalFields.dueOn as string; + // } + // if (additionalFields.mirrorParentSubscribers) { + // task.mirror_parent_subscribers = additionalFields.mirrorParentSubscribers as boolean; + // } + // if (additionalFields.mirrorParentTags) { + // task.mirror_parent_tags = additionalFields.mirrorParentTags as boolean; + // } + // if (additionalFields.noteContent) { + // task.note_content = additionalFields.noteContent as string; + // } + // if (additionalFields.noteMimeType) { + // task.note_mime_type = additionalFields.noteMimeType as string; + // } + // if (additionalFields.parentId) { + // task.parent_id = parseInt(additionalFields.parentId as string, 10); + // } + // if (additionalFields.positionList) { + // task.position_list = additionalFields.positionList as number; + // } + // if (additionalFields.positionUpcoming) { + // task.position_upcoming = additionalFields.positionUpcoming as number; + // } + // if (additionalFields.position) { + // task.position = additionalFields.position as number; + // } + // if (additionalFields.sectionId) { + // task.section_id = additionalFields.sectionId as number; + // } + // if (additionalFields.tags) { + // task.tags = (additionalFields.tags as string).split(','); + // } + // body.task = task; + // try { + // responseData = await flowApiRequest.call(this, 'POST', '/tasks', body); + // responseData = responseData.task; + // } catch (err) { + // throw new Error(`Flow Error: ${err.message}`); + // } + // } + // //https://developer.getflow.com/api/#tasks_update-a-task + // if (operation === 'update') { + // const workspaceId = this.getNodeParameter('workspaceId', i) as string; + // const taskId = this.getNodeParameter('taskId', i) as string; + // const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; + // const body: ITask = { + // organization_id: credentials.organizationId as number, + // }; + // const task: TaskInfo = { + // workspace_id: parseInt(workspaceId, 10), + // id: parseInt(taskId, 10), + // }; + // if (updateFields.name) { + // task.name = updateFields.name as string; + // } + // if (updateFields.ownerId) { + // task.owner_id = parseInt(updateFields.ownerId as string, 10); + // } + // if (updateFields.listId) { + // task.list_id = parseInt(updateFields.listId as string, 10); + // } + // if (updateFields.startsOn) { + // task.starts_on = updateFields.startsOn as string; + // } + // if (updateFields.dueOn) { + // task.due_on = updateFields.dueOn as string; + // } + // if (updateFields.mirrorParentSubscribers) { + // task.mirror_parent_subscribers = updateFields.mirrorParentSubscribers as boolean; + // } + // if (updateFields.mirrorParentTags) { + // task.mirror_parent_tags = updateFields.mirrorParentTags as boolean; + // } + // if (updateFields.noteContent) { + // task.note_content = updateFields.noteContent as string; + // } + // if (updateFields.noteMimeType) { + // task.note_mime_type = updateFields.noteMimeType as string; + // } + // if (updateFields.parentId) { + // task.parent_id = parseInt(updateFields.parentId as string, 10); + // } + // if (updateFields.positionList) { + // task.position_list = updateFields.positionList as number; + // } + // if (updateFields.positionUpcoming) { + // task.position_upcoming = updateFields.positionUpcoming as number; + // } + // if (updateFields.position) { + // task.position = updateFields.position as number; + // } + // if (updateFields.sectionId) { + // task.section_id = updateFields.sectionId as number; + // } + // if (updateFields.tags) { + // task.tags = (updateFields.tags as string).split(','); + // } + // if (updateFields.completed) { + // task.completed = updateFields.completed as boolean; + // } + // body.task = task; + // try { + // responseData = await flowApiRequest.call(this, 'PUT', `/tasks/${taskId}`, body); + // responseData = responseData.task; + // } catch (err) { + // throw new Error(`Flow Error: ${err.message}`); + // } + // } + // //https://developer.getflow.com/api/#tasks_get-task + // if (operation === 'get') { + // const taskId = this.getNodeParameter('taskId', i) as string; + // const filters = this.getNodeParameter('filters', i) as IDataObject; + // qs.organization_id = credentials.organizationId as number; + // if (filters.include) { + // qs.include = (filters.include as string[]).join(','); + // } + // try { + // responseData = await flowApiRequest.call(this,'GET', `/tasks/${taskId}`, {}, qs); + // } catch (err) { + // throw new Error(`Flow Error: ${err.message}`); + // } + // } + // //https://developer.getflow.com/api/#tasks_get-tasks + // if (operation === 'getAll') { + // const returnAll = this.getNodeParameter('returnAll', i) as boolean; + // const filters = this.getNodeParameter('filters', i) as IDataObject; + // qs.organization_id = credentials.organizationId as number; + // if (filters.include) { + // qs.include = (filters.include as string[]).join(','); + // } + // if (filters.order) { + // qs.order = filters.order as string; + // } + // if (filters.workspaceId) { + // qs.workspace_id = filters.workspaceId as string; + // } + // if (filters.createdBefore) { + // qs.created_before = filters.createdBefore as string; + // } + // if (filters.createdAfter) { + // qs.created_after = filters.createdAfter as string; + // } + // if (filters.updateBefore) { + // qs.updated_before = filters.updateBefore as string; + // } + // if (filters.updateAfter) { + // qs.updated_after = filters.updateAfter as string; + // } + // if (filters.deleted) { + // qs.deleted = filters.deleted as boolean; + // } + // if (filters.cleared) { + // qs.cleared = filters.cleared as boolean; + // } + // try { + // if (returnAll === true) { + // responseData = await FlowApiRequestAllItems.call(this, 'tasks', 'GET', '/tasks', {}, qs); + // } else { + // qs.limit = this.getNodeParameter('limit', i) as number; + // responseData = await flowApiRequest.call(this, 'GET', '/tasks', {}, qs); + // responseData = responseData.tasks; + // } + // } catch (err) { + // throw new Error(`Flow Error: ${err.message}`); + // } + // } + // } + // if (Array.isArray(responseData)) { + // returnData.push.apply(returnData, responseData as IDataObject[]); + // } else { + // returnData.push(responseData as IDataObject); + // } + // } + return [this.helpers.returnJsonArray(returnData)]; + } +} diff --git a/packages/nodes-base/nodes/Wordpress/wordpress.png b/packages/nodes-base/nodes/Wordpress/wordpress.png new file mode 100644 index 0000000000..55005aedff Binary files /dev/null and b/packages/nodes-base/nodes/Wordpress/wordpress.png differ diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 8d89334a2a..d0539c25f2 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -73,7 +73,8 @@ "dist/credentials/MandrillApi.credentials.js", "dist/credentials/TodoistApi.credentials.js", "dist/credentials/TypeformApi.credentials.js", - "dist/credentials/VeroApi.credentials.js" + "dist/credentials/VeroApi.credentials.js", + "dist/credentials/WordpressApi.credentials.js" ], "nodes": [ "dist/nodes/ActiveCampaign/ActiveCampaign.node.js", @@ -125,7 +126,8 @@ "dist/nodes/MoveBinaryData.node.js", "dist/nodes/MongoDb/MongoDb.node.js", "dist/nodes/MySql/MySql.node.js", - "dist/nodes/NextCloud/NextCloud.node.js", + "dist/nodes/NextCloud/NextCloud.node.js", + "dist/nodes/Mandrill/Mandrill.node.js", "dist/nodes/NoOp.node.js", "dist/nodes/OpenWeatherMap.node.js", "dist/nodes/Pipedrive/Pipedrive.node.js", @@ -157,11 +159,9 @@ "dist/nodes/Typeform/TypeformTrigger.node.js", "dist/nodes/Vero/Vero.node.js", "dist/nodes/WriteBinaryFile.node.js", - "dist/nodes/Webhook.node.js", - "dist/nodes/Xml.node.js", - "dist/nodes/Mandrill/Mandrill.node.js", - "dist/nodes/Todoist/Todoist.node.js", - "dist/nodes/Xml.node.js" + "dist/nodes/Webhook.node.js", + "dist/nodes/Wordpress/Wordpress.node.js", + "dist/nodes/Xml.node.js" ] }, "devDependencies": {