From 789d10980dc5e04fb895510680627ee809d1fc5c Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 4 Jul 2024 12:05:45 -0300 Subject: [PATCH] New Components - fillout (#12690) * fillout init * [Components] fillout #12553 Sources - New Submission (Instant) * pnpm update --- components/fillout/fillout.app.mjs | 55 +++++++++++++-- components/fillout/package.json | 8 ++- .../new-submission-instant.mjs | 54 +++++++++++++++ .../new-submission-instant/test-event.mjs | 69 +++++++++++++++++++ pnpm-lock.yaml | 5 +- 5 files changed, 184 insertions(+), 7 deletions(-) create mode 100644 components/fillout/sources/new-submission-instant/new-submission-instant.mjs create mode 100644 components/fillout/sources/new-submission-instant/test-event.mjs diff --git a/components/fillout/fillout.app.mjs b/components/fillout/fillout.app.mjs index 999b6c44a925a..3eec1a5a6d3b2 100644 --- a/components/fillout/fillout.app.mjs +++ b/components/fillout/fillout.app.mjs @@ -1,11 +1,58 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "fillout", - propDefinitions: {}, + propDefinitions: { + formId: { + type: "string", + label: "Form ID", + description: "The ID of the form", + async options() { + const forms = await this.getForms(); + return forms.map((form) => ({ + label: form.name, + value: form.formId, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.fillout.com/v1/api"; + }, + _headers() { + return { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + headers: this._headers(), + ...opts, + }); + }, + getForms() { + return this._makeRequest({ + path: "/forms", + }); + }, + createWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/webhook/create", + ...opts, + }); + }, + deleteWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/webhook/delete", + ...opts, + }); }, }, }; diff --git a/components/fillout/package.json b/components/fillout/package.json index 67beade9a5420..2a242824c843a 100644 --- a/components/fillout/package.json +++ b/components/fillout/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/fillout", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Fillout Components", "main": "fillout.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.0" } -} \ No newline at end of file +} + diff --git a/components/fillout/sources/new-submission-instant/new-submission-instant.mjs b/components/fillout/sources/new-submission-instant/new-submission-instant.mjs new file mode 100644 index 0000000000000..12a3d5d2341b1 --- /dev/null +++ b/components/fillout/sources/new-submission-instant/new-submission-instant.mjs @@ -0,0 +1,54 @@ +import fillout from "../../fillout.app.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "fillout-new-submission-instant", + name: "New Submission (Instant)", + description: "Emit new event when a form receives a new submission.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + fillout, + http: { + type: "$.interface.http", + customResponse: false, + }, + db: "$.service.db", + formId: { + propDefinition: [ + fillout, + "formId", + ], + }, + }, + hooks: { + async activate() { + const data = await this.fillout.createWebhook({ + data: { + formId: this.formId, + url: this.http.endpoint, + }, + }); + this.db.set("webhookId", data.id); + }, + async deactivate() { + const webhookId = this.db.get("webhookId"); + if (webhookId) { + await this.fillout.deleteWebhook({ + data: { + webhookId, + }, + }); + } + }, + }, + async run({ body }) { + this.$emit(body, { + id: body.submission.submissionId, + summary: `New submission from form ${body.submission.submissionId}`, + ts: body.submission.submissionTime, + }); + }, + sampleEmit, +}; diff --git a/components/fillout/sources/new-submission-instant/test-event.mjs b/components/fillout/sources/new-submission-instant/test-event.mjs new file mode 100644 index 0000000000000..627e4ad660d69 --- /dev/null +++ b/components/fillout/sources/new-submission-instant/test-event.mjs @@ -0,0 +1,69 @@ +export default { + "formId": "m5q5df45apus", + "formName": "Form Name", + "submission": { + "submissionId": "abc", + "submissionTime": "2024-05-16T23:20:05.324Z", + "lastUpdatedAt": "2024-05-16T23:20:05.324Z", + "questions": [ + { + "id": "abcdef", + "name": "What's your name?", + "type": "ShortAnswer", + "value": "Timmy" + }, + ], + "calculations": [ + { + "id": "calculation1", + "name": "price", + "type": "number", + "value": "12.50" + } + ], + "urlParameters": [ + { + "id": "email", + "name": "email", + "value": "example@example.com", + } + ], + "quiz": { + "score": 5, + "maxScore": 10 + }, + "scheduling": [ + { + "id": "nLJtxBJgPA", + "name": "30 min meeting", + "value": { + "fullName": "John Smith", + "email": "john@smith.com", + "timezone": "Europe/London", + "eventStartTime": "2024-05-20T09:00:00.000Z", + "eventEndTime": "2024-05-20T09:30:00.000Z", + "eventId": "du5ckkaeacd5dlj16d7ajepp8g", + "eventUrl": "https://www.google.com/calendar/event?eid=ZHU1Y2trYWVhY2Q1ZGxqMTZkN2FqZXBwOGcgYXJjaGllQGZpbGxvdXQuY29t&authuser=john%40smith.com" + } + } + ], + "payments": [ + { + "id": "cLJtxCKgdL", + "name": "Complete checkout", + "value": { + "stripeCustomerId": "cus_Ppjz3Z80000000", + "stripeCustomerUrl": "https://dashboard.stripe.com/customers/cus_Ppjz3Z80000000", + "stripePaymentUrl": "https://dashboard.stripe.com/payments/pi_3PRF2cFMP2ckdpfG0s0ZdJqf", + "totalAmount": 1000, + "currency": "USD", + "email": "john@doe.com", + "discountCode": "10OFF", + "status": "succeeded", + "paymentId": "pi_3PRF2cFMP2ckdpfG0s0ZdJqf", + "stripeSubscriptionId": "sub_Ppjz3Z80000000" + } + } + ], + } +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1647870096e4f..43522baccd42e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2986,7 +2986,10 @@ importers: '@pipedream/platform': 1.6.0 components/fillout: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.0 + dependencies: + '@pipedream/platform': 3.0.0 components/filter: specifiers: