Skip to content

Commit 5023061

Browse files
committed
new components
1 parent 81f0d8b commit 5023061

File tree

8 files changed

+295
-111
lines changed

8 files changed

+295
-111
lines changed

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,47 @@ import gocanvas from "../../gocanvas.app.mjs";
33
export default {
44
key: "gocanvas-create-dispatch",
55
name: "Create Dispatch",
6-
description: "Creates a dispatch item in GoCanvas.",
6+
description: "Creates a dispatch item in GoCanvas. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)",
77
version: "0.0.1",
88
type: "action",
99
props: {
1010
gocanvas,
11-
dispatchApp: gocanvas.propDefinitions.dispatchApp,
11+
form: {
12+
propDefinition: [
13+
gocanvas,
14+
"form",
15+
],
16+
description: "The name of the form you want to create a prepopulated submission for",
17+
},
18+
entries: {
19+
type: "object",
20+
label: "Entries",
21+
description: `DIEntry elements consisting of label/value pairs.
22+
\n Label: Either the Export Label or plain Label field attribute (caseinsensitive) as defined in the form builder.
23+
\n Value: The value assigned to this Dispatch Item entry.
24+
`,
25+
},
1226
},
1327
async run({ $ }) {
14-
const response = await this.gocanvas.createDispatchItem({
15-
dispatchApp: this.dispatchApp,
28+
let entriesString = "";
29+
for (const [
30+
key,
31+
value,
32+
] of Object.entries(this.entries)) {
33+
entriesString += `<DIEntry Label="${key}" Value="${value}"/>`;
34+
}
35+
const response = await this.gocanvas.dispatchItems({
36+
$,
37+
data: `
38+
<?xml version="1.0" encoding="utf-8"?>
39+
<List>
40+
<DI FormName="${this.form}">
41+
${entriesString}
42+
</DI>
43+
</List>
44+
`,
1645
});
17-
$.export("$summary", `Successfully created dispatch item in ${this.dispatchApp}`);
46+
$.export("$summary", `Successfully created dispatch item in ${this.form}`);
1847
return response;
1948
},
2049
};
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import gocanvas from "../../gocanvas.app.mjs";
2+
import * as csvParse from "csv-parse";
3+
4+
export default {
5+
key: "gocanvas-create-or-update-reference-data",
6+
name: "Create or Update Reference Data",
7+
description: "Creates or updates GoCanvas reference data. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
gocanvas,
12+
name: {
13+
type: "string",
14+
label: "Reference Data Name",
15+
description: "The attribute name of the dataset to operate on. Will be created if it doesn't already exist.",
16+
},
17+
data: {
18+
type: "string",
19+
label: "Data",
20+
description: `A string of comma separated values representing the data to create/update. **Include Column names**:
21+
\n Example:
22+
\n Column1,Column2,Column3
23+
\n Data1Column1,Data1Column2,Data1Column3
24+
\n Data2Column1,Data2Column2,Data3Column3
25+
`,
26+
},
27+
},
28+
methods: {
29+
csvToXml(data) {
30+
const records = csvParse.parse(data, {
31+
columns: true,
32+
trim: true,
33+
});
34+
35+
// Extract columns
36+
const columns = Object.keys(records[0]);
37+
let result = "<Columns>";
38+
result += columns.map((col) => `<c>${col}</c>`).join("");
39+
result += "</Columns>\n<Rows>\n";
40+
41+
// Extract rows
42+
result += records
43+
.map((row) => {
44+
const rowValues = columns.map((col) => `<v>${row[col]}</v>`).join("");
45+
return ` <r>${rowValues}</r>`;
46+
})
47+
.join("\n");
48+
49+
result += "\n</Rows>";
50+
return result;
51+
},
52+
},
53+
async run({ $ }) {
54+
const response = await this.gocanvas.createUpdateReferenceData({
55+
$,
56+
data: `
57+
<?xml version="1.0" encoding="utf-8"?>
58+
<List Name="${this.name}">
59+
${await this.csvToXml(this.data)}
60+
</List>
61+
`,
62+
});
63+
$.export("$summary", "Successfully created/updated reference data");
64+
return response;
65+
},
66+
};

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ export default {
44
key: "gocanvas-delete-dispatch",
55
name: "Delete Dispatch",
66
description: "Removes a specific dispatch from GoCanvas. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)",
7-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
gocanvas,
11+
form: {
12+
propDefinition: [
13+
gocanvas,
14+
"form",
15+
],
16+
},
1117
dispatchId: {
1218
propDefinition: [
1319
gocanvas,
1420
"dispatchId",
21+
(c) => ({
22+
form: c.form,
23+
}),
1524
],
1625
},
1726
},
@@ -25,15 +34,8 @@ export default {
2534
data: `
2635
<?xml version="1.0" encoding="utf-8"?>
2736
<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 FormName="${this.form}" Action="Delete" OriginalDescription="${description}">
38+
<DIEntry Label="Date" Value="${Date.now()}"/>
3739
</DI>
3840
</List>
3941
`,

components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs

Lines changed: 0 additions & 25 deletions
This file was deleted.

components/gocanvas/gocanvas.app.mjs

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ export default {
55
type: "app",
66
app: "gocanvas",
77
propDefinitions: {
8+
form: {
9+
type: "string",
10+
label: "Form",
11+
description: "The identifier of a form",
12+
async options() {
13+
const forms = await this.listForms();
14+
return forms?.map((form) => form.Name[0]) || [];
15+
},
16+
},
817
dispatchId: {
918
type: "string",
1019
label: "Dispatch ID",
1120
description: "Identifier of a dispatch",
12-
async options({ page }) {
21+
async options({
22+
page, form,
23+
}) {
1324
const dispatches = await this.getActiveDispatches({
25+
form,
1426
data: {
1527
page: page + 1,
1628
},
@@ -47,22 +59,46 @@ export default {
4759
},
4860
});
4961
},
50-
async getActiveDispatches(opts = {}) {
62+
async getActiveDispatches({
63+
form, ...opts
64+
}) {
5165
const response = await this._makeRequest({
5266
path: "/dispatch_export",
5367
...opts,
5468
});
5569
const { CanvasResult: { Dispatches: dispatches } } = await new xml2js
5670
.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);
71+
if (!dispatches?.length) {
72+
return [];
73+
}
74+
return dispatches
75+
.flatMap((d) => d.Dispatch || [])
76+
.filter((d) => d.Status[0] !== "deleted")
77+
.filter((d) => !form || d.Form[0] === form);
78+
},
79+
async listForms(opts = {}) {
80+
const response = await this._makeRequest({
81+
path: "/forms",
82+
...opts,
83+
});
84+
const { CanvasResult: { Forms: forms } } = await new xml2js
85+
.Parser().parseStringPromise(response);
86+
if (!forms?.length) {
87+
return [];
88+
}
89+
return forms.flatMap((form) => form.Form || []);
90+
},
91+
async listSubmissions(opts = {}) {
92+
const response = await this._makeRequest({
93+
path: "/submissions",
94+
...opts,
95+
});
96+
const { CanvasResult: { Submissions: submissions } } = await new xml2js
97+
.Parser().parseStringPromise(response);
98+
if (!submissions?.length) {
99+
return [];
64100
}
65-
return dispatchList;
101+
return submissions.flatMap((sub) => sub.Submission || []);
66102
},
67103
async getDispatchDescription({
68104
dispatchId, ...opts
@@ -80,5 +116,36 @@ export default {
80116
...opts,
81117
});
82118
},
119+
createUpdateReferenceData(opts = {}) {
120+
return this._makeRequest({
121+
method: "POST",
122+
path: "/reference_datas",
123+
...opts,
124+
});
125+
},
126+
async *paginate({
127+
fn,
128+
params,
129+
max,
130+
}) {
131+
params = {
132+
...params,
133+
page: 1,
134+
};
135+
let total, count = 0;
136+
do {
137+
const results = await fn({
138+
params,
139+
});
140+
for (const item of results) {
141+
yield item;
142+
if (max && ++count >= max) {
143+
return;
144+
}
145+
}
146+
total = results?.length;
147+
params.page++;
148+
} while (total);
149+
},
83150
},
84151
};

components/gocanvas/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.3"
16+
"@pipedream/platform": "^3.0.3",
17+
"csv-parse": "^5.5.6",
18+
"xml2js": "^0.6.2"
1719
}
1820
}

components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)