Skip to content

Commit d843cdd

Browse files
committed
Added actions
1 parent 925f252 commit d843cdd

File tree

5 files changed

+206
-6
lines changed

5 files changed

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

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: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,110 @@
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.map((client) => ({
24+
label: client.Name,
25+
value: client.UUID,
26+
}));
27+
},
28+
},
29+
name: {
30+
type: "string",
31+
label: "Name",
32+
description: "Name of the client group",
33+
},
34+
taxable: {
35+
type: "boolean",
36+
label: "Taxable",
37+
description: "Wheter the client group is taxable",
38+
},
39+
clientGroupUuid: {
40+
type: "string",
41+
label: "Client Group",
42+
description: "UUID of the client group",
43+
async options() {
44+
const responseXml = await this.getClientGroups();
45+
const result = await parseStringPromise(responseXml, {
46+
explicitArray: false,
47+
});
48+
const groups = result.Response.Groups.Group;
49+
const groupsArray = Array.isArray(groups)
50+
? groups
51+
: [
52+
groups,
53+
];
54+
return groupsArray.map((group) => ({
55+
label: group.Name,
56+
value: group.UUID,
57+
}));
58+
},
59+
},
60+
},
561
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
62+
_baseUrl() {
63+
return "https://api.workflowmax2.com";
64+
},
65+
async _makeRequest(opts = {}) {
66+
const {
67+
$ = this,
68+
path,
69+
headers,
70+
...otherOpts
71+
} = opts;
72+
return axios($, {
73+
...otherOpts,
74+
url: this._baseUrl() + path,
75+
headers: {
76+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
77+
"Content-Type": "application/xml",
78+
"account_id": `${this.$auth.account_id}`,
79+
...headers,
80+
},
81+
});
82+
},
83+
async createClientGroup(args = {}) {
84+
return this._makeRequest({
85+
path: "/clientgroup.api/add",
86+
method: "post",
87+
...args,
88+
});
89+
},
90+
async getClients(args = {}) {
91+
return this._makeRequest({
92+
path: "/client.api/list",
93+
...args,
94+
});
95+
},
96+
async getClientGroups(args = {}) {
97+
return this._makeRequest({
98+
path: "/clientgroup.api/list",
99+
...args,
100+
});
101+
},
102+
async deleteClientGroup(args = {}) {
103+
return this._makeRequest({
104+
path: "/clientgroup.api/delete",
105+
method: "post",
106+
...args,
107+
});
9108
},
10109
},
11110
};

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)