diff --git a/components/workflow_max/actions/create-client-group/create-client-group.mjs b/components/workflow_max/actions/create-client-group/create-client-group.mjs new file mode 100644 index 0000000000000..2409eb8d6d08b --- /dev/null +++ b/components/workflow_max/actions/create-client-group/create-client-group.mjs @@ -0,0 +1,56 @@ +import app from "../../workflow_max.app.mjs"; +import { parseStringPromise } from "xml2js"; + +export default { + key: "workflow_max-create-client-group", + name: "Create Client Group", + description: "Creates a new Client Group in Workflow Max. [See the documentation](https://app.swaggerhub.com/apis-docs/WorkflowMax-BlueRock/WorkflowMax-BlueRock-OpenAPI3/0.1#/Client/createClient)", + version: "0.0.1", + type: "action", + props: { + app, + clientUuid: { + propDefinition: [ + app, + "clientUuid", + ], + }, + name: { + propDefinition: [ + app, + "name", + ], + }, + taxable: { + propDefinition: [ + app, + "taxable", + ], + }, + }, + async run({ $ }) { + const xmlBody = ` + + ${this.clientUuid} + ${this.name} + ${this.taxable + ? "Yes" + : "No"} + + `.trim(); + const response = await this.app.createClientGroup({ + $, + data: xmlBody, + }); + + const status = response.match(/(.*?)<\/Status>/)?.[1]; + const error = response.match(/(.*?)<\/Error>/)?.[1]; + + if (status !== "OK") { + throw new Error(`Workflow Max couldn't create the client group: ${error}`); + } + + $.export("$summary", "Successfully created the client group: " + this.name); + return await parseStringPromise(response); + }, +}; diff --git a/components/workflow_max/actions/delete-client-group/delete-client-group.mjs b/components/workflow_max/actions/delete-client-group/delete-client-group.mjs new file mode 100644 index 0000000000000..03e896c1866f6 --- /dev/null +++ b/components/workflow_max/actions/delete-client-group/delete-client-group.mjs @@ -0,0 +1,40 @@ +import app from "../../workflow_max.app.mjs"; +import { parseStringPromise } from "xml2js"; + +export default { + key: "workflow_max-delete-client-group", + name: "Delete Client Group", + description: "Deletes the specified client group. [See the documentation](https://app.swaggerhub.com/apis-docs/WorkflowMax-BlueRock/WorkflowMax-BlueRock-OpenAPI3/0.1#/Client%20Group/deleteClientGroup)", + version: "0.0.1", + type: "action", + props: { + app, + clientGroupUuid: { + propDefinition: [ + app, + "clientGroupUuid", + ], + }, + }, + async run({ $ }) { + const xmlBody = ` + + ${this.clientGroupUuid} + + `.trim(); + const response = await this.app.deleteClientGroup({ + $, + data: xmlBody, + }); + + const status = response.match(/(.*?)<\/Status>/)?.[1]; + const error = response.match(/(.*?)<\/Error>/)?.[1]; + + if (status !== "OK") { + throw new Error(`Workflow Max couldn't delete the client group: ${error}`); + } + + $.export("$summary", "Successfully deleted the client group: " + this.name); + return await parseStringPromise(response); + }, +}; diff --git a/components/workflow_max/package.json b/components/workflow_max/package.json index f2f7f8bca8e90..1cd3055edf414 100644 --- a/components/workflow_max/package.json +++ b/components/workflow_max/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/workflow_max", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Workflow Max Components", "main": "workflow_max.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/components/workflow_max/workflow_max.app.mjs b/components/workflow_max/workflow_max.app.mjs index 55595e2ee87f7..d9ac23caefcfd 100644 --- a/components/workflow_max/workflow_max.app.mjs +++ b/components/workflow_max/workflow_max.app.mjs @@ -1,11 +1,112 @@ +import { axios } from "@pipedream/platform"; +import { parseStringPromise } from "xml2js"; + export default { type: "app", app: "workflow_max", - propDefinitions: {}, + propDefinitions: { + clientUuid: { + type: "string", + label: "Client UUID", + description: "UUID of the client", + async options() { + const responseXml = await this.getClients(); + const result = await parseStringPromise(responseXml, { + explicitArray: false, + }); + const clients = result.Response.Clients.Client; + const clientsArray = Array.isArray(clients) + ? clients + : [ + clients, + ]; + return clientsArray + .filter((client) => client && client.Name && client.UUID) + .map((client) => ({ + label: client.Name, + value: client.UUID, + })); + }, + }, + name: { + type: "string", + label: "Name", + description: "Name of the client group", + }, + taxable: { + type: "boolean", + label: "Taxable", + description: "Wheter the client group is taxable", + }, + clientGroupUuid: { + type: "string", + label: "Client Group", + description: "UUID of the client group", + async options() { + const responseXml = await this.getClientGroups(); + const result = await parseStringPromise(responseXml, { + explicitArray: false, + }); + const groups = result.Response.Groups.Group; + const groupsArray = Array.isArray(groups) + ? groups + : [ + groups, + ]; + return groupsArray.filter((group) => group && group.Name && group.UUID).map((group) => ({ + label: group.Name, + value: group.UUID, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.workflowmax2.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + "Content-Type": "application/xml", + "account_id": `${this.$auth.account_id}`, + ...headers, + }, + }); + }, + async createClientGroup(args = {}) { + return this._makeRequest({ + path: "/clientgroup.api/add", + method: "post", + ...args, + }); + }, + async getClients(args = {}) { + return this._makeRequest({ + path: "/client.api/list", + ...args, + }); + }, + async getClientGroups(args = {}) { + return this._makeRequest({ + path: "/clientgroup.api/list", + ...args, + }); + }, + async deleteClientGroup(args = {}) { + return this._makeRequest({ + path: "/clientgroup.api/delete", + method: "post", + ...args, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49e507710d189..dd3dc0e8b126a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15078,7 +15078,11 @@ importers: specifier: ^1.1.1 version: 1.6.6 - components/workflow_max: {} + components/workflow_max: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/workiom: {}