Skip to content

Commit af19436

Browse files
authored
[Components] workflow_max #14568 (#17450)
* Added actions * Added actions * Added actions
1 parent d9dfa2e commit af19436

File tree

5 files changed

+210
-6
lines changed

5 files changed

+210
-6
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import app from "../../workflow_max.app.mjs";
2+
import { parseStringPromise } from "xml2js";
3+
4+
export default {
5+
key: "workflow_max-create-client-group",
6+
name: "Create Client Group",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
clientUuid: {
13+
propDefinition: [
14+
app,
15+
"clientUuid",
16+
],
17+
},
18+
name: {
19+
propDefinition: [
20+
app,
21+
"name",
22+
],
23+
},
24+
taxable: {
25+
propDefinition: [
26+
app,
27+
"taxable",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const xmlBody = `
33+
<Group>
34+
<ClientUUID>${this.clientUuid}</ClientUUID>
35+
<Name>${this.name}</Name>
36+
<Taxable>${this.taxable
37+
? "Yes"
38+
: "No"}</Taxable>
39+
</Group>
40+
`.trim();
41+
const response = await this.app.createClientGroup({
42+
$,
43+
data: xmlBody,
44+
});
45+
46+
const status = response.match(/<Status>(.*?)<\/Status>/)?.[1];
47+
const error = response.match(/<Error>(.*?)<\/Error>/)?.[1];
48+
49+
if (status !== "OK") {
50+
throw new Error(`Workflow Max couldn't create the client group: ${error}`);
51+
}
52+
53+
$.export("$summary", "Successfully created the client group: " + this.name);
54+
return await parseStringPromise(response);
55+
},
56+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import app from "../../workflow_max.app.mjs";
2+
import { parseStringPromise } from "xml2js";
3+
4+
export default {
5+
key: "workflow_max-delete-client-group",
6+
name: "Delete Client Group",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
clientGroupUuid: {
13+
propDefinition: [
14+
app,
15+
"clientGroupUuid",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const xmlBody = `
21+
<Group>
22+
<UUID>${this.clientGroupUuid}</UUID>
23+
</Group>
24+
`.trim();
25+
const response = await this.app.deleteClientGroup({
26+
$,
27+
data: xmlBody,
28+
});
29+
30+
const status = response.match(/<Status>(.*?)<\/Status>/)?.[1];
31+
const error = response.match(/<Error>(.*?)<\/Error>/)?.[1];
32+
33+
if (status !== "OK") {
34+
throw new Error(`Workflow Max couldn't delete the client group: ${error}`);
35+
}
36+
37+
$.export("$summary", "Successfully deleted the client group: " + this.name);
38+
return await parseStringPromise(response);
39+
},
40+
};

components/workflow_max/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/workflow_max",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Workflow Max Components",
55
"main": "workflow_max.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
1518
}
Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,112 @@
1+
import { axios } from "@pipedream/platform";
2+
import { parseStringPromise } from "xml2js";
3+
14
export default {
25
type: "app",
36
app: "workflow_max",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
clientUuid: {
9+
type: "string",
10+
label: "Client UUID",
11+
description: "UUID of the client",
12+
async options() {
13+
const responseXml = await this.getClients();
14+
const result = await parseStringPromise(responseXml, {
15+
explicitArray: false,
16+
});
17+
const clients = result.Response.Clients.Client;
18+
const clientsArray = Array.isArray(clients)
19+
? clients
20+
: [
21+
clients,
22+
];
23+
return clientsArray
24+
.filter((client) => client && client.Name && client.UUID)
25+
.map((client) => ({
26+
label: client.Name,
27+
value: client.UUID,
28+
}));
29+
},
30+
},
31+
name: {
32+
type: "string",
33+
label: "Name",
34+
description: "Name of the client group",
35+
},
36+
taxable: {
37+
type: "boolean",
38+
label: "Taxable",
39+
description: "Wheter the client group is taxable",
40+
},
41+
clientGroupUuid: {
42+
type: "string",
43+
label: "Client Group",
44+
description: "UUID of the client group",
45+
async options() {
46+
const responseXml = await this.getClientGroups();
47+
const result = await parseStringPromise(responseXml, {
48+
explicitArray: false,
49+
});
50+
const groups = result.Response.Groups.Group;
51+
const groupsArray = Array.isArray(groups)
52+
? groups
53+
: [
54+
groups,
55+
];
56+
return groupsArray.filter((group) => group && group.Name && group.UUID).map((group) => ({
57+
label: group.Name,
58+
value: group.UUID,
59+
}));
60+
},
61+
},
62+
},
563
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
64+
_baseUrl() {
65+
return "https://api.workflowmax2.com";
66+
},
67+
async _makeRequest(opts = {}) {
68+
const {
69+
$ = this,
70+
path,
71+
headers,
72+
...otherOpts
73+
} = opts;
74+
return axios($, {
75+
...otherOpts,
76+
url: this._baseUrl() + path,
77+
headers: {
78+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
79+
"Content-Type": "application/xml",
80+
"account_id": `${this.$auth.account_id}`,
81+
...headers,
82+
},
83+
});
84+
},
85+
async createClientGroup(args = {}) {
86+
return this._makeRequest({
87+
path: "/clientgroup.api/add",
88+
method: "post",
89+
...args,
90+
});
91+
},
92+
async getClients(args = {}) {
93+
return this._makeRequest({
94+
path: "/client.api/list",
95+
...args,
96+
});
97+
},
98+
async getClientGroups(args = {}) {
99+
return this._makeRequest({
100+
path: "/clientgroup.api/list",
101+
...args,
102+
});
103+
},
104+
async deleteClientGroup(args = {}) {
105+
return this._makeRequest({
106+
path: "/clientgroup.api/delete",
107+
method: "post",
108+
...args,
109+
});
9110
},
10111
},
11112
};

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)