From d8cd67a3b56a1ee52326ad4154013c8027a3bdde Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 5 May 2025 14:29:36 -0400 Subject: [PATCH 1/2] new components --- .../get-recent-submissions.mjs | 30 +++++++ components/widgetform/package.json | 7 +- .../new-submission-instant.mjs | 81 +++++++++++++++++++ components/widgetform/widgetform.app.mjs | 51 ++++++++++-- 4 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 components/widgetform/actions/get-recent-submissions/get-recent-submissions.mjs create mode 100644 components/widgetform/sources/new-submission-instant/new-submission-instant.mjs diff --git a/components/widgetform/actions/get-recent-submissions/get-recent-submissions.mjs b/components/widgetform/actions/get-recent-submissions/get-recent-submissions.mjs new file mode 100644 index 0000000000000..5fd7a7eda5a12 --- /dev/null +++ b/components/widgetform/actions/get-recent-submissions/get-recent-submissions.mjs @@ -0,0 +1,30 @@ +import widgetform from "../../widgetform.app.mjs"; + +export default { + key: "widgetform-get-recent-submissions", + name: "Get Recent Submissions", + description: "Retrieves the 10 most recent submissions. [See the documentation](https://usewidgetform.notion.site/Zapier-API-185312164ccf808eb902f411608aa35d)", + version: "0.0.1", + type: "action", + props: { + widgetform, + form: { + propDefinition: [ + widgetform, + "form", + ], + }, + }, + async run({ $ }) { + const response = await this.widgetform.listResponses({ + $, + }); + const submissions = this.form + ? response.filter(({ form_name }) => form_name === this.form) + : response; + $.export("$summary", `Successfully retrieved ${submissions.length} submission${submissions.length === 1 + ? "" + : "s"}`); + return submissions; + }, +}; diff --git a/components/widgetform/package.json b/components/widgetform/package.json index e88b4f861757d..fde4688072ed8 100644 --- a/components/widgetform/package.json +++ b/components/widgetform/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/widgetform", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Widgetform Components", "main": "widgetform.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/widgetform/sources/new-submission-instant/new-submission-instant.mjs b/components/widgetform/sources/new-submission-instant/new-submission-instant.mjs new file mode 100644 index 0000000000000..9170d84f47f2f --- /dev/null +++ b/components/widgetform/sources/new-submission-instant/new-submission-instant.mjs @@ -0,0 +1,81 @@ +import widgetform from "../../widgetform.app.mjs"; + +export default { + key: "widgetform-new-submission-instant", + name: "New Form Submission (Instant)", + description: "Emit new event when a form submission is received. [See the documentation](https://usewidgetform.notion.site/Zapier-API-185312164ccf808eb902f411608aa35d)", + version: "0.0.1", + type: "source", + props: { + widgetform, + db: "$.service.db", + http: "$.interface.http", + form: { + propDefinition: [ + widgetform, + "form", + ], + }, + }, + hooks: { + async activate() { + const { id } = await this.widgetform.createSubscription({ + data: { + hook_url: this.http.endpoint, + }, + }); + if (!id) { + throw new Error("Error creating subscription"); + } + this._setSubscriptionId(id); + }, + async deactivate() { + const id = this._getSubscriptionId(); + if (!id) { + return; + } + await this.widgetform.deleteSubscription({ + data: { + subscription_id: id, + }, + }); + }, + async deploy() { + const response = await this.widgetform.listResponses(); + if (!response?.length) { + return; + } + const submissions = this.form + ? response.filter(({ form_name }) => form_name === this.form) + : response; + submissions.reverse().forEach((submission) => { + const meta = this.generateMeta(submission); + this.$emit(submission, meta); + }); + }, + }, + methods: { + _getSubscriptionId() { + return this.db.get("subscriptionId"); + }, + _setSubscriptionId(subscriptionId) { + this.db.set("subscriptionId", subscriptionId); + }, + generateMeta(submission) { + const ts = Date.now(); + return { + id: ts, + summary: `New Submission for ${submission.form_name}`, + ts, + }; + }, + }, + async run(event) { + const submission = event.body; + if (!submission || (this.form && (submission.form_name !== this.form))) { + return; + } + const meta = this.generateMeta(submission); + this.$emit(submission, meta); + }, +}; diff --git a/components/widgetform/widgetform.app.mjs b/components/widgetform/widgetform.app.mjs index 3df6a895b8bc2..ae69eaee1585d 100644 --- a/components/widgetform/widgetform.app.mjs +++ b/components/widgetform/widgetform.app.mjs @@ -1,11 +1,52 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "widgetform", - propDefinitions: {}, + propDefinitions: { + form: { + type: "string", + label: "Form", + description: "Filter results by form name", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://usewidgetform.com/api/v1"; + }, + _makeRequest({ + $ = this, + path, + ...otherOpts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "x-api-key": this.$auth.api_key, + }, + ...otherOpts, + }); + }, + listResponses(opts = {}) { + return this._makeRequest({ + path: "/hooks/zapier/responses", + ...opts, + }); + }, + createSubscription(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/hooks/zapier/subscription", + ...opts, + }); + }, + deleteSubscription(opts = {}) { + return this._makeRequest({ + method: "DELETE", + path: "/hooks/zapier/subscription", + ...opts, + }); }, }, -}; \ No newline at end of file +}; From 52710bce04c76f934c02835eaf2d75e0350f73cd Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Mon, 5 May 2025 14:33:23 -0400 Subject: [PATCH 2/2] pnpm-lock.yaml --- pnpm-lock.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0248a3592dd6a..6175cccc4b8fb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9221,8 +9221,7 @@ importers: components/osu: {} - components/oto: - specifiers: {} + components/oto: {} components/otter_waiver: dependencies: @@ -13062,11 +13061,9 @@ importers: components/test_apps_for_checking_something_001: {} - components/test_apps_for_checking_something_005: - specifiers: {} + components/test_apps_for_checking_something_005: {} - components/test_apps_for_checking_something_006: - specifiers: {} + components/test_apps_for_checking_something_006: {} components/test_apps_for_switching_appslug_009: {} @@ -13440,8 +13437,7 @@ importers: components/translate_com: {} - components/transloadit: - specifiers: {} + components/transloadit: {} components/travis_ci: dependencies: @@ -14348,7 +14344,11 @@ importers: components/wicked_reports: {} - components/widgetform: {} + components/widgetform: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/wildapricot: dependencies: