From cf29b5b4d6cb222ab2d2fdf62a1a3966c59755a1 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 1 Nov 2024 15:25:46 -0400 Subject: [PATCH 1/5] init --- .../create-dispatch/create-dispatch.mjs | 20 +++++ .../delete-dispatch/delete-dispatch.mjs | 20 +++++ .../sync-reference-data.mjs | 25 ++++++ components/gocanvas/gocanvas.app.mjs | 82 ++++++++++++++++++- .../new-submission-instant.mjs | 60 ++++++++++++++ 5 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 components/gocanvas/actions/create-dispatch/create-dispatch.mjs create mode 100644 components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs create mode 100644 components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs create mode 100644 components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs diff --git a/components/gocanvas/actions/create-dispatch/create-dispatch.mjs b/components/gocanvas/actions/create-dispatch/create-dispatch.mjs new file mode 100644 index 0000000000000..f6a98f687fe10 --- /dev/null +++ b/components/gocanvas/actions/create-dispatch/create-dispatch.mjs @@ -0,0 +1,20 @@ +import gocanvas from "../../gocanvas.app.mjs"; + +export default { + key: "gocanvas-create-dispatch", + name: "Create Dispatch", + description: "Creates a dispatch item in GoCanvas.", + version: "0.0.1", + type: "action", + props: { + gocanvas, + dispatchApp: gocanvas.propDefinitions.dispatchApp, + }, + async run({ $ }) { + const response = await this.gocanvas.createDispatchItem({ + dispatchApp: this.dispatchApp, + }); + $.export("$summary", `Successfully created dispatch item in ${this.dispatchApp}`); + return response; + }, +}; diff --git a/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs b/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs new file mode 100644 index 0000000000000..4b7ca1a69c7da --- /dev/null +++ b/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs @@ -0,0 +1,20 @@ +import gocanvas from "../../gocanvas.app.mjs"; + +export default { + key: "gocanvas-delete-dispatch", + name: "Delete Dispatch", + description: "Removes a specific dispatch from GoCanvas. The 'description' of the dispatch to be deleted is a required prop.", + version: "0.0.{{ts}}", + type: "action", + props: { + gocanvas, + dispatchDescription: gocanvas.propDefinitions.dispatchDescription, + }, + async run({ $ }) { + const response = await this.gocanvas.removeDispatch({ + dispatchDescription: this.dispatchDescription, + }); + $.export("$summary", `Successfully deleted dispatch with description: ${this.dispatchDescription}`); + return response; + }, +}; diff --git a/components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs b/components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs new file mode 100644 index 0000000000000..c1efab18def13 --- /dev/null +++ b/components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs @@ -0,0 +1,25 @@ +import gocanvas from "../../gocanvas.app.mjs"; + +export default { + key: "gocanvas-sync-reference-data", + name: "Sync Reference Data", + 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/)", + version: "0.0.{{ts}}", + type: "action", + props: { + gocanvas, + referenceDataFile: { + propDefinition: [ + gocanvas, + "referenceDataFile", + ], + }, + }, + async run({ $ }) { + const response = await this.gocanvas.syncReferenceDataFile({ + referenceDataFile: this.referenceDataFile, + }); + $.export("$summary", `Successfully synced reference data file ${this.referenceDataFile}`); + return response; + }, +}; diff --git a/components/gocanvas/gocanvas.app.mjs b/components/gocanvas/gocanvas.app.mjs index 45e1ba69a4cb3..3b552a8d7c0a2 100644 --- a/components/gocanvas/gocanvas.app.mjs +++ b/components/gocanvas/gocanvas.app.mjs @@ -1,11 +1,89 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "gocanvas", - propDefinitions: {}, + propDefinitions: { + applicationId: { + type: "string", + label: "Application ID", + description: "The ID of the GoCanvas application", + }, + submissionId: { + type: "string", + label: "Submission ID", + description: "The ID of the submission to get dynamic fields", + optional: true, + }, + dispatchApp: { + type: "string", + label: "Dispatch App", + description: "The name of a dispatch-enabled GoCanvas app", + }, + dispatchDescription: { + type: "string", + label: "Dispatch Description", + description: "The 'description' of the dispatch to be deleted", + }, + referenceDataFile: { + type: "string", + label: "Reference Data File", + description: "The name of the GoCanvas reference data file to be synced", + }, + }, methods: { - // this.$auth contains connected account data authKeys() { console.log(Object.keys(this.$auth)); }, + _baseUrl() { + return "https://api.gocanvas.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "GET", path, headers, ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + }, + }); + }, + async emitNewEvent(opts = {}) { + return this._makeRequest({ + path: `/submissions/${opts.submissionId}`, + ...opts, + }); + }, + async createDispatchItem(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/dispatches", + data: { + app_name: opts.dispatchApp, + }, + ...opts, + }); + }, + async removeDispatch(opts = {}) { + return this._makeRequest({ + method: "DELETE", + path: "/dispatches", + params: { + description: opts.dispatchDescription, + }, + ...opts, + }); + }, + async syncReferenceDataFile(opts = {}) { + return this._makeRequest({ + method: "PUT", + path: `/reference_data_files/${opts.referenceDataFile}`, + ...opts, + }); + }, }, }; diff --git a/components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs b/components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs new file mode 100644 index 0000000000000..00edaf78a2d33 --- /dev/null +++ b/components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs @@ -0,0 +1,60 @@ +import gocanvas from "../../gocanvas.app.mjs"; + +export default { + key: "gocanvas-new-submission-instant", + name: "New Submission Instant", + description: "Emit new event when a new submission is uploaded to the specified GoCanvas application.", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + props: { + gocanvas, + db: "$.service.db", + applicationId: { + propDefinition: [ + gocanvas, + "applicationId", + ], + }, + submissionId: { + propDefinition: [ + gocanvas, + "submissionId", + (c) => ({ + applicationId: c.applicationId, + }), + ], + optional: true, + }, + }, + methods: { + generateMeta(data) { + const { + id, created_at, + } = data; + return { + id, + summary: `New Submission: ${id}`, + ts: Date.parse(created_at), + }; + }, + }, + async run(event) { + const { body } = event; + if (!body.submission || !body.submission.id) { + console.log("Ignoring event without submission id"); + return; + } + const applicationId = this.applicationId; + const submissionId = this.submissionId || body.submission.id; + if (applicationId !== body.submission.application_id) { + console.log("Ignoring submission from another application"); + return; + } + const data = await this.gocanvas.emitNewEvent({ + submissionId, + }); + const meta = this.generateMeta(data); + this.$emit(data, meta); + }, +}; From 81f0d8b851ccbe643a94ea1fc7d8a675ffe1676b Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Sun, 3 Nov 2024 09:57:03 -0500 Subject: [PATCH 2/5] wip --- .../delete-dispatch/delete-dispatch.mjs | 34 +++++- components/gocanvas/gocanvas.app.mjs | 109 +++++++++--------- components/gocanvas/package.json | 18 +++ 3 files changed, 99 insertions(+), 62 deletions(-) create mode 100644 components/gocanvas/package.json diff --git a/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs b/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs index 4b7ca1a69c7da..165afe1ca4d52 100644 --- a/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs +++ b/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs @@ -3,18 +3,42 @@ import gocanvas from "../../gocanvas.app.mjs"; export default { key: "gocanvas-delete-dispatch", name: "Delete Dispatch", - description: "Removes a specific dispatch from GoCanvas. The 'description' of the dispatch to be deleted is a required prop.", + description: "Removes a specific dispatch from GoCanvas. [See the documentation](https://help.gocanvas.com/hc/en-us/article_attachments/26468076609559)", version: "0.0.{{ts}}", type: "action", props: { gocanvas, - dispatchDescription: gocanvas.propDefinitions.dispatchDescription, + dispatchId: { + propDefinition: [ + gocanvas, + "dispatchId", + ], + }, }, async run({ $ }) { - const response = await this.gocanvas.removeDispatch({ - dispatchDescription: this.dispatchDescription, + const description = await this.gocanvas.getDispatchDescription({ + $, + dispatchId: this.dispatchId, }); - $.export("$summary", `Successfully deleted dispatch with description: ${this.dispatchDescription}`); + const response = await this.gocanvas.dispatchItems({ + $, + data: ` + + + + + + + + + + + + + + `, + }); + $.export("$summary", `Successfully deleted dispatch with ID ${this.dispatchId}`); return response; }, }; diff --git a/components/gocanvas/gocanvas.app.mjs b/components/gocanvas/gocanvas.app.mjs index 3b552a8d7c0a2..02ada216fb280 100644 --- a/components/gocanvas/gocanvas.app.mjs +++ b/components/gocanvas/gocanvas.app.mjs @@ -1,87 +1,82 @@ import { axios } from "@pipedream/platform"; +import xml2js from "xml2js"; export default { type: "app", app: "gocanvas", propDefinitions: { - applicationId: { + dispatchId: { type: "string", - label: "Application ID", - description: "The ID of the GoCanvas application", - }, - submissionId: { - type: "string", - label: "Submission ID", - description: "The ID of the submission to get dynamic fields", - optional: true, - }, - dispatchApp: { - type: "string", - label: "Dispatch App", - description: "The name of a dispatch-enabled GoCanvas app", - }, - dispatchDescription: { - type: "string", - label: "Dispatch Description", - description: "The 'description' of the dispatch to be deleted", - }, - referenceDataFile: { - type: "string", - label: "Reference Data File", - description: "The name of the GoCanvas reference data file to be synced", + label: "Dispatch ID", + description: "Identifier of a dispatch", + async options({ page }) { + const dispatches = await this.getActiveDispatches({ + data: { + page: page + 1, + }, + }); + return dispatches?.map(({ + $, Description: desc, + }) => ({ + value: $.Id, + label: desc[0], + })) || []; + }, }, }, methods: { - authKeys() { - console.log(Object.keys(this.$auth)); - }, _baseUrl() { - return "https://api.gocanvas.com"; + return "https://www.gocanvas.com/apiv2/"; }, - async _makeRequest(opts = {}) { + _makeRequest(opts = {}) { const { - $ = this, method = "GET", path, headers, ...otherOpts + $ = this, + path, + params, + ...otherOpts } = opts; return axios($, { ...otherOpts, - method, - url: this._baseUrl() + path, + url: `${this._baseUrl()}${path}`, + params: { + ...params, + username: `${this.$auth.username}`, + }, headers: { - ...headers, - "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + Authorization: `Bearer ${this.$auth.api_key}`, }, }); }, - async emitNewEvent(opts = {}) { - return this._makeRequest({ - path: `/submissions/${opts.submissionId}`, + async getActiveDispatches(opts = {}) { + const response = await this._makeRequest({ + path: "/dispatch_export", ...opts, }); + const { CanvasResult: { Dispatches: dispatches } } = await new xml2js + .Parser().parseStringPromise(response); + const dispatchList = []; + for (const dispatch of dispatches) { + if (!dispatch.Dispatch) { + continue; + } + const activeDispatches = dispatch.Dispatch.filter((d) => d.Status[0] !== "deleted"); + dispatchList.push(...activeDispatches); + } + return dispatchList; }, - async createDispatchItem(opts = {}) { - return this._makeRequest({ - method: "POST", - path: "/dispatches", - data: { - app_name: opts.dispatchApp, - }, + async getDispatchDescription({ + dispatchId, ...opts + }) { + const dispatches = await this.getActiveDispatches({ ...opts, }); + const dispatch = dispatches.find(({ $ }) => $.Id === dispatchId); + return dispatch.Description[0]; }, - async removeDispatch(opts = {}) { + dispatchItems(opts = {}) { return this._makeRequest({ - method: "DELETE", - path: "/dispatches", - params: { - description: opts.dispatchDescription, - }, - ...opts, - }); - }, - async syncReferenceDataFile(opts = {}) { - return this._makeRequest({ - method: "PUT", - path: `/reference_data_files/${opts.referenceDataFile}`, + method: "POST", + path: "/dispatch_items", ...opts, }); }, diff --git a/components/gocanvas/package.json b/components/gocanvas/package.json new file mode 100644 index 0000000000000..2a9293b259be2 --- /dev/null +++ b/components/gocanvas/package.json @@ -0,0 +1,18 @@ +{ + "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 (https://pipedream.com/)", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" + } +} From 5023061600f21b89488ad4f37dcacf712fdc2f40 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 4 Nov 2024 16:22:57 -0500 Subject: [PATCH 3/5] new components --- .../create-dispatch/create-dispatch.mjs | 39 ++++++- .../create-or-update-reference-data.mjs | 66 +++++++++++ .../delete-dispatch/delete-dispatch.mjs | 22 ++-- .../sync-reference-data.mjs | 25 ----- components/gocanvas/gocanvas.app.mjs | 87 +++++++++++++-- components/gocanvas/package.json | 4 +- .../new-submission-instant.mjs | 60 ---------- .../new-submission-received.mjs | 103 ++++++++++++++++++ 8 files changed, 295 insertions(+), 111 deletions(-) create mode 100644 components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs delete mode 100644 components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs delete mode 100644 components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs create mode 100644 components/gocanvas/sources/new-submission-received/new-submission-received.mjs diff --git a/components/gocanvas/actions/create-dispatch/create-dispatch.mjs b/components/gocanvas/actions/create-dispatch/create-dispatch.mjs index f6a98f687fe10..cc21e5d520f90 100644 --- a/components/gocanvas/actions/create-dispatch/create-dispatch.mjs +++ b/components/gocanvas/actions/create-dispatch/create-dispatch.mjs @@ -3,18 +3,47 @@ import gocanvas from "../../gocanvas.app.mjs"; export default { key: "gocanvas-create-dispatch", name: "Create Dispatch", - description: "Creates a dispatch item in GoCanvas.", + 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, - dispatchApp: gocanvas.propDefinitions.dispatchApp, + 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({ $ }) { - const response = await this.gocanvas.createDispatchItem({ - dispatchApp: this.dispatchApp, + let entriesString = ""; + for (const [ + key, + value, + ] of Object.entries(this.entries)) { + entriesString += ``; + } + const response = await this.gocanvas.dispatchItems({ + $, + data: ` + + + + ${entriesString} + + + `, }); - $.export("$summary", `Successfully created dispatch item in ${this.dispatchApp}`); + $.export("$summary", `Successfully created dispatch item in ${this.form}`); return response; }, }; diff --git a/components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs b/components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs new file mode 100644 index 0000000000000..f08945f16b749 --- /dev/null +++ b/components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs @@ -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 + `, + }, + }, + methods: { + csvToXml(data) { + const records = csvParse.parse(data, { + columns: true, + trim: true, + }); + + // Extract columns + const columns = Object.keys(records[0]); + let result = ""; + result += columns.map((col) => `${col}`).join(""); + result += "\n\n"; + + // Extract rows + result += records + .map((row) => { + const rowValues = columns.map((col) => `${row[col]}`).join(""); + return ` ${rowValues}`; + }) + .join("\n"); + + result += "\n"; + return result; + }, + }, + async run({ $ }) { + const response = await this.gocanvas.createUpdateReferenceData({ + $, + data: ` + + + ${await this.csvToXml(this.data)} + + `, + }); + $.export("$summary", "Successfully created/updated reference data"); + return response; + }, +}; diff --git a/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs b/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs index 165afe1ca4d52..ddafebef637d6 100644 --- a/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs +++ b/components/gocanvas/actions/delete-dispatch/delete-dispatch.mjs @@ -4,14 +4,23 @@ 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.{{ts}}", + version: "0.0.1", type: "action", props: { gocanvas, + form: { + propDefinition: [ + gocanvas, + "form", + ], + }, dispatchId: { propDefinition: [ gocanvas, "dispatchId", + (c) => ({ + form: c.form, + }), ], }, }, @@ -25,15 +34,8 @@ export default { data: ` - - - - - - - - - + + `, diff --git a/components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs b/components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs deleted file mode 100644 index c1efab18def13..0000000000000 --- a/components/gocanvas/actions/sync-reference-data/sync-reference-data.mjs +++ /dev/null @@ -1,25 +0,0 @@ -import gocanvas from "../../gocanvas.app.mjs"; - -export default { - key: "gocanvas-sync-reference-data", - name: "Sync Reference Data", - 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/)", - version: "0.0.{{ts}}", - type: "action", - props: { - gocanvas, - referenceDataFile: { - propDefinition: [ - gocanvas, - "referenceDataFile", - ], - }, - }, - async run({ $ }) { - const response = await this.gocanvas.syncReferenceDataFile({ - referenceDataFile: this.referenceDataFile, - }); - $.export("$summary", `Successfully synced reference data file ${this.referenceDataFile}`); - return response; - }, -}; diff --git a/components/gocanvas/gocanvas.app.mjs b/components/gocanvas/gocanvas.app.mjs index 02ada216fb280..40ec3505be34a 100644 --- a/components/gocanvas/gocanvas.app.mjs +++ b/components/gocanvas/gocanvas.app.mjs @@ -5,12 +5,24 @@ export default { type: "app", app: "gocanvas", 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 }) { + async options({ + page, form, + }) { const dispatches = await this.getActiveDispatches({ + form, data: { page: page + 1, }, @@ -47,22 +59,46 @@ export default { }, }); }, - async getActiveDispatches(opts = {}) { + async getActiveDispatches({ + form, ...opts + }) { const response = await this._makeRequest({ path: "/dispatch_export", ...opts, }); const { CanvasResult: { Dispatches: dispatches } } = await new xml2js .Parser().parseStringPromise(response); - const dispatchList = []; - for (const dispatch of dispatches) { - if (!dispatch.Dispatch) { - continue; - } - const activeDispatches = dispatch.Dispatch.filter((d) => d.Status[0] !== "deleted"); - dispatchList.push(...activeDispatches); + 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 dispatchList; + return submissions.flatMap((sub) => sub.Submission || []); }, async getDispatchDescription({ dispatchId, ...opts @@ -80,5 +116,36 @@ export default { ...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); + }, }, }; diff --git a/components/gocanvas/package.json b/components/gocanvas/package.json index 2a9293b259be2..d5437280de080 100644 --- a/components/gocanvas/package.json +++ b/components/gocanvas/package.json @@ -13,6 +13,8 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^3.0.3" + "@pipedream/platform": "^3.0.3", + "csv-parse": "^5.5.6", + "xml2js": "^0.6.2" } } diff --git a/components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs b/components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs deleted file mode 100644 index 00edaf78a2d33..0000000000000 --- a/components/gocanvas/sources/new-submission-instant/new-submission-instant.mjs +++ /dev/null @@ -1,60 +0,0 @@ -import gocanvas from "../../gocanvas.app.mjs"; - -export default { - key: "gocanvas-new-submission-instant", - name: "New Submission Instant", - description: "Emit new event when a new submission is uploaded to the specified GoCanvas application.", - version: "0.0.{{ts}}", - type: "source", - dedupe: "unique", - props: { - gocanvas, - db: "$.service.db", - applicationId: { - propDefinition: [ - gocanvas, - "applicationId", - ], - }, - submissionId: { - propDefinition: [ - gocanvas, - "submissionId", - (c) => ({ - applicationId: c.applicationId, - }), - ], - optional: true, - }, - }, - methods: { - generateMeta(data) { - const { - id, created_at, - } = data; - return { - id, - summary: `New Submission: ${id}`, - ts: Date.parse(created_at), - }; - }, - }, - async run(event) { - const { body } = event; - if (!body.submission || !body.submission.id) { - console.log("Ignoring event without submission id"); - return; - } - const applicationId = this.applicationId; - const submissionId = this.submissionId || body.submission.id; - if (applicationId !== body.submission.application_id) { - console.log("Ignoring submission from another application"); - return; - } - const data = await this.gocanvas.emitNewEvent({ - submissionId, - }); - const meta = this.generateMeta(data); - this.$emit(data, meta); - }, -}; diff --git a/components/gocanvas/sources/new-submission-received/new-submission-received.mjs b/components/gocanvas/sources/new-submission-received/new-submission-received.mjs new file mode 100644 index 0000000000000..5b655fb8f18df --- /dev/null +++ b/components/gocanvas/sources/new-submission-received/new-submission-received.mjs @@ -0,0 +1,103 @@ +import gocanvas from "../../gocanvas.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; + +export default { + key: "gocanvas-new-submission-received", + name: "New Submission Recieved", + description: "Emit new event when a new submission is uploaded to GoCanvas.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + gocanvas, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + form: { + propDefinition: [ + gocanvas, + "form", + ], + }, + }, + hooks: { + async deploy() { + await this.processEvent(25); + }, + }, + methods: { + _getLastSubmissionDate() { + return this.db.get("lastSubmissionDate"); + }, + _setLastSubmissionDate(lastSubmissionDate) { + this.db.set("lastSubmissionDate", lastSubmissionDate); + }, + generateMeta(submission) { + return { + id: submission.ResponseID, + summary: `New Submission: ${submission.ResponseID}`, + ts: Date.parse(submission.Date), + }; + }, + currentDate() { + const currentDate = new Date(); + return `${String(currentDate.getMonth() + 1) + .padStart(2, "0")}/${String(currentDate.getDate()) + .padStart(2, "0")}/${currentDate.getFullYear()}`; + }, + formatResponse(obj) { + if (Array.isArray(obj) && obj.length === 1) { + return this.formatResponse(obj[0]); + } else if (typeof obj === "object" && obj !== null) { + return Object.fromEntries( + Object.entries(obj).map(([ + key, + value, + ]) => [ + key, + this.formatResponse(value), + ]), + ); + } else { + return obj; + } + }, + async processEvent(max) { + let lastSubmissionDate = this._getLastSubmissionDate(); + + const params = { + form_name: this.form, + }; + if (lastSubmissionDate) { + params.begin_date = new Date(lastSubmissionDate).toLocaleDateString("en-US"); + params.end_date = this.currentDate(); + } + + const results = this.gocanvas.paginate({ + fn: this.gocanvas.listSubmissions, + params, + max, + }); + + for await (const result of results) { + const submission = this.formatResponse(result); + const meta = this.generateMeta(submission); + this.$emit(submission, meta); + + if (!lastSubmissionDate + || Date.parse(submission.Date) >= Date.parse(lastSubmissionDate)) { + lastSubmissionDate = submission.Date; + } + } + + this._setLastSubmissionDate(lastSubmissionDate); + }, + }, + async run() { + await this.processEvent(); + }, +}; From 0224554aac2b56d5221f7b8d284473c6ea10d97c Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 4 Nov 2024 16:26:15 -0500 Subject: [PATCH 4/5] pnpm.lock.yaml --- pnpm-lock.yaml | 116 +++++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1fcea59661dea..6abde7a0090f3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4023,6 +4023,16 @@ importers: components/gobio_link: specifiers: {} + components/gocanvas: + specifiers: + '@pipedream/platform': ^3.0.3 + csv-parse: ^5.5.6 + xml2js: ^0.6.2 + dependencies: + '@pipedream/platform': 3.0.3 + csv-parse: 5.5.6 + xml2js: 0.6.2 + components/godaddy: specifiers: {} @@ -13228,6 +13238,55 @@ packages: - aws-crt dev: false + /@aws-sdk/client-sso-oidc/3.600.0_tdq3komn4zwyd65w7klbptsu34: + resolution: {integrity: sha512-7+I8RWURGfzvChyNQSyj5/tKrqRbzRl7H+BnTOf/4Vsw1nFOi5ROhlhD4X/Y0QCTacxnaoNcIrqnY7uGGvVRzw==} + engines: {node: '>=16.0.0'} + dependencies: + '@aws-crypto/sha256-browser': 5.2.0 + '@aws-crypto/sha256-js': 5.2.0 + '@aws-sdk/client-sts': 3.600.0 + '@aws-sdk/core': 3.598.0 + '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 + '@aws-sdk/middleware-host-header': 3.598.0 + '@aws-sdk/middleware-logger': 3.598.0 + '@aws-sdk/middleware-recursion-detection': 3.598.0 + '@aws-sdk/middleware-user-agent': 3.598.0 + '@aws-sdk/region-config-resolver': 3.598.0 + '@aws-sdk/types': 3.598.0 + '@aws-sdk/util-endpoints': 3.598.0 + '@aws-sdk/util-user-agent-browser': 3.598.0 + '@aws-sdk/util-user-agent-node': 3.598.0 + '@smithy/config-resolver': 3.0.3 + '@smithy/core': 2.2.3 + '@smithy/fetch-http-handler': 3.2.1 + '@smithy/hash-node': 3.0.2 + '@smithy/invalid-dependency': 3.0.2 + '@smithy/middleware-content-length': 3.0.2 + '@smithy/middleware-endpoint': 3.0.4 + '@smithy/middleware-retry': 3.0.6 + '@smithy/middleware-serde': 3.0.3 + '@smithy/middleware-stack': 3.0.3 + '@smithy/node-config-provider': 3.1.3 + '@smithy/node-http-handler': 3.1.2 + '@smithy/protocol-http': 4.0.3 + '@smithy/smithy-client': 3.1.6 + '@smithy/types': 3.3.0 + '@smithy/url-parser': 3.0.3 + '@smithy/util-base64': 3.0.0 + '@smithy/util-body-length-browser': 3.0.0 + '@smithy/util-body-length-node': 3.0.0 + '@smithy/util-defaults-mode-browser': 3.0.6 + '@smithy/util-defaults-mode-node': 3.0.6 + '@smithy/util-endpoints': 2.0.3 + '@smithy/util-middleware': 3.0.3 + '@smithy/util-retry': 3.0.2 + '@smithy/util-utf8': 3.0.0 + tslib: 2.6.3 + transitivePeerDependencies: + - '@aws-sdk/client-sts' + - aws-crt + dev: false + /@aws-sdk/client-sso/3.423.0: resolution: {integrity: sha512-znIufHkwhCIePgaYciIs3x/+BpzR57CZzbCKHR9+oOvGyufEPPpUT5bFLvbwTgfiVkTjuk6sG/ES3U5Bc+xtrA==} engines: {node: '>=14.0.0'} @@ -13463,7 +13522,7 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 + '@aws-sdk/client-sso-oidc': 3.600.0_tdq3komn4zwyd65w7klbptsu34 '@aws-sdk/core': 3.598.0 '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 '@aws-sdk/middleware-host-header': 3.598.0 @@ -13505,55 +13564,6 @@ packages: - aws-crt dev: false - /@aws-sdk/client-sts/3.600.0_dseaa2p5u2yk67qiepewcq3hkq: - resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} - engines: {node: '>=16.0.0'} - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.600.0 - '@aws-sdk/core': 3.598.0 - '@aws-sdk/credential-provider-node': 3.600.0_f7n47caigsrjd2lr2szmwfuee4 - '@aws-sdk/middleware-host-header': 3.598.0 - '@aws-sdk/middleware-logger': 3.598.0 - '@aws-sdk/middleware-recursion-detection': 3.598.0 - '@aws-sdk/middleware-user-agent': 3.598.0 - '@aws-sdk/region-config-resolver': 3.598.0 - '@aws-sdk/types': 3.598.0 - '@aws-sdk/util-endpoints': 3.598.0 - '@aws-sdk/util-user-agent-browser': 3.598.0 - '@aws-sdk/util-user-agent-node': 3.598.0 - '@smithy/config-resolver': 3.0.3 - '@smithy/core': 2.2.3 - '@smithy/fetch-http-handler': 3.2.1 - '@smithy/hash-node': 3.0.2 - '@smithy/invalid-dependency': 3.0.2 - '@smithy/middleware-content-length': 3.0.2 - '@smithy/middleware-endpoint': 3.0.4 - '@smithy/middleware-retry': 3.0.6 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.3 - '@smithy/node-http-handler': 3.1.2 - '@smithy/protocol-http': 4.0.3 - '@smithy/smithy-client': 3.1.6 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.6 - '@smithy/util-defaults-mode-node': 3.0.6 - '@smithy/util-endpoints': 2.0.3 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.2 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - '@aws-sdk/client-sso-oidc' - - aws-crt - dev: false - /@aws-sdk/core/3.556.0: resolution: {integrity: sha512-vJaSaHw2kPQlo11j/Rzuz0gk1tEaKdz+2ser0f0qZ5vwFlANjt08m/frU17ctnVKC1s58bxpctO/1P894fHLrA==} engines: {node: '>=14.0.0'} @@ -17846,7 +17856,7 @@ packages: '@aws-sdk/client-sns': 3.423.0 '@aws-sdk/client-sqs': 3.423.0 '@aws-sdk/client-ssm': 3.423.0 - '@aws-sdk/client-sts': 3.600.0_dseaa2p5u2yk67qiepewcq3hkq + '@aws-sdk/client-sts': 3.600.0 '@aws-sdk/s3-request-presigner': 3.609.0 '@pipedream/helper_functions': 0.3.12 '@pipedream/platform': 1.6.6 @@ -24041,6 +24051,10 @@ packages: resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==} dev: false + /csv-parse/5.5.6: + resolution: {integrity: sha512-uNpm30m/AGSkLxxy7d9yRXpJQFrZzVWLFBkS+6ngPcZkw/5k3L/jjFuj7tVnEpRn+QgmiXr21nDlhCiUK4ij2A==} + dev: false + /current-module-paths/1.1.1: resolution: {integrity: sha512-8Ga5T8oMXBaSsHq9Gj+bddX7kHSaJKsl2vaAd3ep51eQLkr4W18eFEmEZM5bLo1zrz8tt3jE1U8QK9QGhaLR4g==} engines: {node: '>=12.17'} From fce38e0c72089b88eb80c5603618dc024899c9df Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 6 Nov 2024 12:04:33 -0500 Subject: [PATCH 5/5] fix import statement --- .../create-or-update-reference-data.mjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs b/components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs index f08945f16b749..3280cc055cde4 100644 --- a/components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs +++ b/components/gocanvas/actions/create-or-update-reference-data/create-or-update-reference-data.mjs @@ -1,5 +1,6 @@ import gocanvas from "../../gocanvas.app.mjs"; -import * as csvParse from "csv-parse"; +import { parse } from "csv-parse/sync"; +import { ConfigurationError } from "@pipedream/platform"; export default { key: "gocanvas-create-or-update-reference-data", @@ -27,11 +28,15 @@ export default { }, methods: { csvToXml(data) { - const records = csvParse.parse(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 = "";