Skip to content

Commit cf29b5b

Browse files
committed
init
1 parent 02197b3 commit cf29b5b

File tree

5 files changed

+205
-2
lines changed

5 files changed

+205
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import gocanvas from "../../gocanvas.app.mjs";
2+
3+
export default {
4+
key: "gocanvas-create-dispatch",
5+
name: "Create Dispatch",
6+
description: "Creates a dispatch item in GoCanvas.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
gocanvas,
11+
dispatchApp: gocanvas.propDefinitions.dispatchApp,
12+
},
13+
async run({ $ }) {
14+
const response = await this.gocanvas.createDispatchItem({
15+
dispatchApp: this.dispatchApp,
16+
});
17+
$.export("$summary", `Successfully created dispatch item in ${this.dispatchApp}`);
18+
return response;
19+
},
20+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import gocanvas from "../../gocanvas.app.mjs";
2+
3+
export default {
4+
key: "gocanvas-delete-dispatch",
5+
name: "Delete Dispatch",
6+
description: "Removes a specific dispatch from GoCanvas. The 'description' of the dispatch to be deleted is a required prop.",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
gocanvas,
11+
dispatchDescription: gocanvas.propDefinitions.dispatchDescription,
12+
},
13+
async run({ $ }) {
14+
const response = await this.gocanvas.removeDispatch({
15+
dispatchDescription: this.dispatchDescription,
16+
});
17+
$.export("$summary", `Successfully deleted dispatch with description: ${this.dispatchDescription}`);
18+
return response;
19+
},
20+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import gocanvas from "../../gocanvas.app.mjs";
2+
3+
export default {
4+
key: "gocanvas-sync-reference-data",
5+
name: "Sync Reference Data",
6+
description: "Synchronizes GoCanvas reference data file with Google Sheets. [See the documentation](https://www.gocanvas.com/content/faq/post/how-to-use-reference-data-in-your-mobile-business-apps/)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
gocanvas,
11+
referenceDataFile: {
12+
propDefinition: [
13+
gocanvas,
14+
"referenceDataFile",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.gocanvas.syncReferenceDataFile({
20+
referenceDataFile: this.referenceDataFile,
21+
});
22+
$.export("$summary", `Successfully synced reference data file ${this.referenceDataFile}`);
23+
return response;
24+
},
25+
};
Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,89 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "gocanvas",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
applicationId: {
8+
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",
32+
},
33+
},
534
methods: {
6-
// this.$auth contains connected account data
735
authKeys() {
836
console.log(Object.keys(this.$auth));
937
},
38+
_baseUrl() {
39+
return "https://api.gocanvas.com";
40+
},
41+
async _makeRequest(opts = {}) {
42+
const {
43+
$ = this, method = "GET", path, headers, ...otherOpts
44+
} = opts;
45+
return axios($, {
46+
...otherOpts,
47+
method,
48+
url: this._baseUrl() + path,
49+
headers: {
50+
...headers,
51+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
52+
},
53+
});
54+
},
55+
async emitNewEvent(opts = {}) {
56+
return this._makeRequest({
57+
path: `/submissions/${opts.submissionId}`,
58+
...opts,
59+
});
60+
},
61+
async createDispatchItem(opts = {}) {
62+
return this._makeRequest({
63+
method: "POST",
64+
path: "/dispatches",
65+
data: {
66+
app_name: opts.dispatchApp,
67+
},
68+
...opts,
69+
});
70+
},
71+
async removeDispatch(opts = {}) {
72+
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}`,
85+
...opts,
86+
});
87+
},
1088
},
1189
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import gocanvas from "../../gocanvas.app.mjs";
2+
3+
export default {
4+
key: "gocanvas-new-submission-instant",
5+
name: "New Submission Instant",
6+
description: "Emit new event when a new submission is uploaded to the specified GoCanvas application.",
7+
version: "0.0.{{ts}}",
8+
type: "source",
9+
dedupe: "unique",
10+
props: {
11+
gocanvas,
12+
db: "$.service.db",
13+
applicationId: {
14+
propDefinition: [
15+
gocanvas,
16+
"applicationId",
17+
],
18+
},
19+
submissionId: {
20+
propDefinition: [
21+
gocanvas,
22+
"submissionId",
23+
(c) => ({
24+
applicationId: c.applicationId,
25+
}),
26+
],
27+
optional: true,
28+
},
29+
},
30+
methods: {
31+
generateMeta(data) {
32+
const {
33+
id, created_at,
34+
} = data;
35+
return {
36+
id,
37+
summary: `New Submission: ${id}`,
38+
ts: Date.parse(created_at),
39+
};
40+
},
41+
},
42+
async run(event) {
43+
const { body } = event;
44+
if (!body.submission || !body.submission.id) {
45+
console.log("Ignoring event without submission id");
46+
return;
47+
}
48+
const applicationId = this.applicationId;
49+
const submissionId = this.submissionId || body.submission.id;
50+
if (applicationId !== body.submission.application_id) {
51+
console.log("Ignoring submission from another application");
52+
return;
53+
}
54+
const data = await this.gocanvas.emitNewEvent({
55+
submissionId,
56+
});
57+
const meta = this.generateMeta(data);
58+
this.$emit(data, meta);
59+
},
60+
};

0 commit comments

Comments
 (0)