-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New Components - gocanvas #14544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - gocanvas #14544
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
components/gocanvas/actions/create-dispatch/create-dispatch.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import gocanvas from "../../gocanvas.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "gocanvas-create-dispatch", | ||
| name: "Create Dispatch", | ||
| description: "Creates a dispatch item in GoCanvas. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| gocanvas, | ||
| form: { | ||
| propDefinition: [ | ||
| gocanvas, | ||
| "form", | ||
| ], | ||
| description: "The name of the form you want to create a prepopulated submission for", | ||
| }, | ||
| entries: { | ||
| type: "object", | ||
| label: "Entries", | ||
| description: `DIEntry elements consisting of label/value pairs. | ||
| \n Label: Either the Export Label or plain Label field attribute (caseinsensitive) as defined in the form builder. | ||
| \n Value: The value assigned to this Dispatch Item entry. | ||
| `, | ||
| }, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async run({ $ }) { | ||
| let entriesString = ""; | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(this.entries)) { | ||
| entriesString += `<DIEntry Label="${key}" Value="${value}"/>`; | ||
| } | ||
| const response = await this.gocanvas.dispatchItems({ | ||
| $, | ||
| data: ` | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <List> | ||
| <DI FormName="${this.form}"> | ||
| ${entriesString} | ||
| </DI> | ||
| </List> | ||
| `, | ||
| }); | ||
| $.export("$summary", `Successfully created dispatch item in ${this.form}`); | ||
| return response; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
66 changes: 66 additions & 0 deletions
66
...ents/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import gocanvas from "../../gocanvas.app.mjs"; | ||
| import * as csvParse from "csv-parse"; | ||
|
|
||
| export default { | ||
| key: "gocanvas-create-or-update-reference-data", | ||
| name: "Create or Update Reference Data", | ||
| description: "Creates or updates GoCanvas reference data. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| gocanvas, | ||
| name: { | ||
| type: "string", | ||
| label: "Reference Data Name", | ||
| description: "The attribute name of the dataset to operate on. Will be created if it doesn't already exist.", | ||
| }, | ||
| data: { | ||
| type: "string", | ||
| label: "Data", | ||
| description: `A string of comma separated values representing the data to create/update. **Include Column names**: | ||
| \n Example: | ||
| \n Column1,Column2,Column3 | ||
| \n Data1Column1,Data1Column2,Data1Column3 | ||
| \n Data2Column1,Data2Column2,Data3Column3 | ||
| `, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| methods: { | ||
| csvToXml(data) { | ||
| const records = csvParse.parse(data, { | ||
| columns: true, | ||
| trim: true, | ||
| }); | ||
|
|
||
| // Extract columns | ||
| const columns = Object.keys(records[0]); | ||
| let result = "<Columns>"; | ||
| result += columns.map((col) => `<c>${col}</c>`).join(""); | ||
| result += "</Columns>\n<Rows>\n"; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Extract rows | ||
| result += records | ||
| .map((row) => { | ||
| const rowValues = columns.map((col) => `<v>${row[col]}</v>`).join(""); | ||
| return ` <r>${rowValues}</r>`; | ||
| }) | ||
| .join("\n"); | ||
|
|
||
| result += "\n</Rows>"; | ||
| return result; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.gocanvas.createUpdateReferenceData({ | ||
| $, | ||
| data: ` | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <List Name="${this.name}"> | ||
| ${await this.csvToXml(this.data)} | ||
| </List> | ||
| `, | ||
| }); | ||
| $.export("$summary", "Successfully created/updated reference data"); | ||
| return response; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
46 changes: 46 additions & 0 deletions
46
components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import gocanvas from "../../gocanvas.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "gocanvas-delete-dispatch", | ||
| name: "Delete Dispatch", | ||
| description: "Removes a specific dispatch from GoCanvas. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| gocanvas, | ||
| form: { | ||
| propDefinition: [ | ||
| gocanvas, | ||
| "form", | ||
| ], | ||
| }, | ||
| dispatchId: { | ||
| propDefinition: [ | ||
| gocanvas, | ||
| "dispatchId", | ||
| (c) => ({ | ||
| form: c.form, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const description = await this.gocanvas.getDispatchDescription({ | ||
| $, | ||
| dispatchId: this.dispatchId, | ||
| }); | ||
| const response = await this.gocanvas.dispatchItems({ | ||
| $, | ||
| data: ` | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <List> | ||
| <DI FormName="${this.form}" Action="Delete" OriginalDescription="${description}"> | ||
| <DIEntry Label="Date" Value="${Date.now()}"/> | ||
| </DI> | ||
| </List> | ||
| `, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| $.export("$summary", `Successfully deleted dispatch with ID ${this.dispatchId}`); | ||
| return response; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,151 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import xml2js from "xml2js"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "gocanvas", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| form: { | ||
| type: "string", | ||
| label: "Form", | ||
| description: "The identifier of a form", | ||
| async options() { | ||
| const forms = await this.listForms(); | ||
| return forms?.map((form) => form.Name[0]) || []; | ||
| }, | ||
| }, | ||
| dispatchId: { | ||
| type: "string", | ||
| label: "Dispatch ID", | ||
| description: "Identifier of a dispatch", | ||
| async options({ | ||
| page, form, | ||
| }) { | ||
| const dispatches = await this.getActiveDispatches({ | ||
| form, | ||
| data: { | ||
| page: page + 1, | ||
| }, | ||
| }); | ||
| return dispatches?.map(({ | ||
| $, Description: desc, | ||
| }) => ({ | ||
| value: $.Id, | ||
| label: desc[0], | ||
| })) || []; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://www.gocanvas.com/apiv2/"; | ||
| }, | ||
| _makeRequest(opts = {}) { | ||
| const { | ||
| $ = this, | ||
| path, | ||
| params, | ||
| ...otherOpts | ||
| } = opts; | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: `${this._baseUrl()}${path}`, | ||
| params: { | ||
| ...params, | ||
| username: `${this.$auth.username}`, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| headers: { | ||
| Authorization: `Bearer ${this.$auth.api_key}`, | ||
| }, | ||
| }); | ||
| }, | ||
| async getActiveDispatches({ | ||
| form, ...opts | ||
| }) { | ||
| const response = await this._makeRequest({ | ||
| path: "/dispatch_export", | ||
| ...opts, | ||
| }); | ||
| const { CanvasResult: { Dispatches: dispatches } } = await new xml2js | ||
| .Parser().parseStringPromise(response); | ||
| if (!dispatches?.length) { | ||
| return []; | ||
| } | ||
| return dispatches | ||
| .flatMap((d) => d.Dispatch || []) | ||
| .filter((d) => d.Status[0] !== "deleted") | ||
| .filter((d) => !form || d.Form[0] === form); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async listForms(opts = {}) { | ||
| const response = await this._makeRequest({ | ||
| path: "/forms", | ||
| ...opts, | ||
| }); | ||
| const { CanvasResult: { Forms: forms } } = await new xml2js | ||
| .Parser().parseStringPromise(response); | ||
| if (!forms?.length) { | ||
| return []; | ||
| } | ||
| return forms.flatMap((form) => form.Form || []); | ||
| }, | ||
| async listSubmissions(opts = {}) { | ||
| const response = await this._makeRequest({ | ||
| path: "/submissions", | ||
| ...opts, | ||
| }); | ||
| const { CanvasResult: { Submissions: submissions } } = await new xml2js | ||
| .Parser().parseStringPromise(response); | ||
| if (!submissions?.length) { | ||
| return []; | ||
| } | ||
| return submissions.flatMap((sub) => sub.Submission || []); | ||
| }, | ||
| async getDispatchDescription({ | ||
| dispatchId, ...opts | ||
| }) { | ||
| const dispatches = await this.getActiveDispatches({ | ||
| ...opts, | ||
| }); | ||
| const dispatch = dispatches.find(({ $ }) => $.Id === dispatchId); | ||
| return dispatch.Description[0]; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| dispatchItems(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/dispatch_items", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createUpdateReferenceData(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/reference_datas", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, | ||
| params, | ||
| max, | ||
| }) { | ||
| params = { | ||
| ...params, | ||
| page: 1, | ||
| }; | ||
| let total, count = 0; | ||
| do { | ||
| const results = await fn({ | ||
| params, | ||
| }); | ||
| for (const item of results) { | ||
| yield item; | ||
| if (max && ++count >= max) { | ||
| return; | ||
| } | ||
| } | ||
| total = results?.length; | ||
| params.page++; | ||
| } while (total); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "@pipedream/gocanvas", | ||
| "version": "0.0.1", | ||
| "description": "Pipedream GoCanvas Components", | ||
| "main": "gocanvas.app.mjs", | ||
| "keywords": [ | ||
| "pipedream", | ||
| "gocanvas" | ||
| ], | ||
| "homepage": "https://pipedream.com/apps/gocanvas", | ||
| "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3", | ||
| "csv-parse": "^5.5.6", | ||
| "xml2js": "^0.6.2" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.