-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * wip * new components * pnpm.lock.yaml * fix import statement
- Loading branch information
1 parent
f35b601
commit 4bd5d9e
Showing
7 changed files
with
447 additions
and
4 deletions.
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 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. | ||
`, | ||
}, | ||
}, | ||
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; | ||
}, | ||
}; |
71 changes: 71 additions & 0 deletions
71
...ents/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs
This file contains 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,71 @@ | ||
import gocanvas from "../../gocanvas.app.mjs"; | ||
import { parse } from "csv-parse/sync"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
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 | ||
`, | ||
}, | ||
}, | ||
methods: { | ||
csvToXml(data) { | ||
const records = parse(data, { | ||
columns: true, | ||
trim: true, | ||
}); | ||
|
||
if (!records?.length) { | ||
throw new ConfigurationError("No data items found to create/update. Please enter column names and at least 1 row of data."); | ||
} | ||
|
||
// Extract columns | ||
const columns = Object.keys(records[0]); | ||
let result = "<Columns>"; | ||
result += columns.map((col) => `<c>${col}</c>`).join(""); | ||
result += "</Columns>\n<Rows>\n"; | ||
|
||
// 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; | ||
}, | ||
}, | ||
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; | ||
}, | ||
}; |
46 changes: 46 additions & 0 deletions
46
components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs
This file contains 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> | ||
`, | ||
}); | ||
$.export("$summary", `Successfully deleted dispatch with ID ${this.dispatchId}`); | ||
return response; | ||
}, | ||
}; |
This file contains 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}`, | ||
}, | ||
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); | ||
}, | ||
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]; | ||
}, | ||
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); | ||
}, | ||
}, | ||
}; |
This file contains 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 <[email protected]> (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.