Skip to content

Commit 81f0d8b

Browse files
committed
wip
1 parent cf29b5b commit 81f0d8b

File tree

3 files changed

+99
-62
lines changed

3 files changed

+99
-62
lines changed

components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,42 @@ import gocanvas from "../../gocanvas.app.mjs";
33
export default {
44
key: "gocanvas-delete-dispatch",
55
name: "Delete Dispatch",
6-
description: "Removes a specific dispatch from GoCanvas. The 'description' of the dispatch to be deleted is a required prop.",
6+
description: "Removes a specific dispatch from GoCanvas. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)",
77
version: "0.0.{{ts}}",
88
type: "action",
99
props: {
1010
gocanvas,
11-
dispatchDescription: gocanvas.propDefinitions.dispatchDescription,
11+
dispatchId: {
12+
propDefinition: [
13+
gocanvas,
14+
"dispatchId",
15+
],
16+
},
1217
},
1318
async run({ $ }) {
14-
const response = await this.gocanvas.removeDispatch({
15-
dispatchDescription: this.dispatchDescription,
19+
const description = await this.gocanvas.getDispatchDescription({
20+
$,
21+
dispatchId: this.dispatchId,
1622
});
17-
$.export("$summary", `Successfully deleted dispatch with description: ${this.dispatchDescription}`);
23+
const response = await this.gocanvas.dispatchItems({
24+
$,
25+
data: `
26+
<?xml version="1.0" encoding="utf-8"?>
27+
<List>
28+
<DI FormName="Daily Report" Action="Delete" OriginalDescription="${description}">
29+
<DIEntry />
30+
<DIListItems>
31+
<DIListItem>
32+
<DIEntries>
33+
<DIEntry Label="Date" Value="${Date.now()}"/>
34+
</DIEntries>
35+
</DIListItem>
36+
</DIListItems>
37+
</DI>
38+
</List>
39+
`,
40+
});
41+
$.export("$summary", `Successfully deleted dispatch with ID ${this.dispatchId}`);
1842
return response;
1943
},
2044
};

components/gocanvas/gocanvas.app.mjs

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,82 @@
11
import { axios } from "@pipedream/platform";
2+
import xml2js from "xml2js";
23

34
export default {
45
type: "app",
56
app: "gocanvas",
67
propDefinitions: {
7-
applicationId: {
8+
dispatchId: {
89
type: "string",
9-
label: "Application ID",
10-
description: "The ID of the GoCanvas application",
11-
},
12-
submissionId: {
13-
type: "string",
14-
label: "Submission ID",
15-
description: "The ID of the submission to get dynamic fields",
16-
optional: true,
17-
},
18-
dispatchApp: {
19-
type: "string",
20-
label: "Dispatch App",
21-
description: "The name of a dispatch-enabled GoCanvas app",
22-
},
23-
dispatchDescription: {
24-
type: "string",
25-
label: "Dispatch Description",
26-
description: "The 'description' of the dispatch to be deleted",
27-
},
28-
referenceDataFile: {
29-
type: "string",
30-
label: "Reference Data File",
31-
description: "The name of the GoCanvas reference data file to be synced",
10+
label: "Dispatch ID",
11+
description: "Identifier of a dispatch",
12+
async options({ page }) {
13+
const dispatches = await this.getActiveDispatches({
14+
data: {
15+
page: page + 1,
16+
},
17+
});
18+
return dispatches?.map(({
19+
$, Description: desc,
20+
}) => ({
21+
value: $.Id,
22+
label: desc[0],
23+
})) || [];
24+
},
3225
},
3326
},
3427
methods: {
35-
authKeys() {
36-
console.log(Object.keys(this.$auth));
37-
},
3828
_baseUrl() {
39-
return "https://api.gocanvas.com";
29+
return "https://www.gocanvas.com/apiv2/";
4030
},
41-
async _makeRequest(opts = {}) {
31+
_makeRequest(opts = {}) {
4232
const {
43-
$ = this, method = "GET", path, headers, ...otherOpts
33+
$ = this,
34+
path,
35+
params,
36+
...otherOpts
4437
} = opts;
4538
return axios($, {
4639
...otherOpts,
47-
method,
48-
url: this._baseUrl() + path,
40+
url: `${this._baseUrl()}${path}`,
41+
params: {
42+
...params,
43+
username: `${this.$auth.username}`,
44+
},
4945
headers: {
50-
...headers,
51-
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
46+
Authorization: `Bearer ${this.$auth.api_key}`,
5247
},
5348
});
5449
},
55-
async emitNewEvent(opts = {}) {
56-
return this._makeRequest({
57-
path: `/submissions/${opts.submissionId}`,
50+
async getActiveDispatches(opts = {}) {
51+
const response = await this._makeRequest({
52+
path: "/dispatch_export",
5853
...opts,
5954
});
55+
const { CanvasResult: { Dispatches: dispatches } } = await new xml2js
56+
.Parser().parseStringPromise(response);
57+
const dispatchList = [];
58+
for (const dispatch of dispatches) {
59+
if (!dispatch.Dispatch) {
60+
continue;
61+
}
62+
const activeDispatches = dispatch.Dispatch.filter((d) => d.Status[0] !== "deleted");
63+
dispatchList.push(...activeDispatches);
64+
}
65+
return dispatchList;
6066
},
61-
async createDispatchItem(opts = {}) {
62-
return this._makeRequest({
63-
method: "POST",
64-
path: "/dispatches",
65-
data: {
66-
app_name: opts.dispatchApp,
67-
},
67+
async getDispatchDescription({
68+
dispatchId, ...opts
69+
}) {
70+
const dispatches = await this.getActiveDispatches({
6871
...opts,
6972
});
73+
const dispatch = dispatches.find(({ $ }) => $.Id === dispatchId);
74+
return dispatch.Description[0];
7075
},
71-
async removeDispatch(opts = {}) {
76+
dispatchItems(opts = {}) {
7277
return this._makeRequest({
73-
method: "DELETE",
74-
path: "/dispatches",
75-
params: {
76-
description: opts.dispatchDescription,
77-
},
78-
...opts,
79-
});
80-
},
81-
async syncReferenceDataFile(opts = {}) {
82-
return this._makeRequest({
83-
method: "PUT",
84-
path: `/reference_data_files/${opts.referenceDataFile}`,
78+
method: "POST",
79+
path: "/dispatch_items",
8580
...opts,
8681
});
8782
},

components/gocanvas/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/gocanvas",
3+
"version": "0.0.1",
4+
"description": "Pipedream GoCanvas Components",
5+
"main": "gocanvas.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"gocanvas"
9+
],
10+
"homepage": "https://pipedream.com/apps/gocanvas",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}

0 commit comments

Comments
 (0)