-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Added Component Form.taxi #18198
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
Added Component Form.taxi #18198
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
37ca887
Added Form.taxi
wrktbiz 2670165
Update components/form_taxi/package.json
wrktbiz 1321742
Update components/form_taxi/sources/new-form-submission/new-form-subm…
wrktbiz ee654b5
Update package.json
wrktbiz efcedd7
Update new-form-submission.mjs
wrktbiz 1271a44
Merge branch 'master' into master
wrktbiz a3a51c0
Merge branch 'master' into master
GTFalcao d35a65d
Apply suggestion from @lcaresia
wrktbiz 6ef0cdd
Apply suggestion from @lcaresia
wrktbiz daa2845
Merge branch 'master' into master
wrktbiz 99cca8f
Update Form.taxi component with latest code revisions
wrktbiz f4d3504
Update Form.taxi Pipedream source with latest version
wrktbiz 5f3b6ac
Update Form.taxi Pipedream source with latest version
wrktbiz 880cd3f
Update Form.taxi Pipedream source with latest version
wrktbiz 470b004
Update Form.taxi Pipedream source with latest version
wrktbiz cc4a1e1
Update components/form_taxi/sources/new-form-submission/new-form-subm…
wrktbiz bda8825
Merge branch 'master' into master
lcaresia 64c791d
Update components/form_taxi/sources/common/base.mjs
wrktbiz 318ba9b
Update components/form_taxi/sources/common/base.mjs
wrktbiz 18a7e1c
Update components/form_taxi/sources/common/base.mjs
wrktbiz bb50890
Update components/form_taxi/sources/common/base.mjs
wrktbiz b757694
Update components/form_taxi/sources/common/base.mjs
wrktbiz 9ccccb3
Update components/form_taxi/form_taxi.app.mjs
wrktbiz df0a156
Update components/form_taxi/sources/common/base.mjs
wrktbiz 0482fcc
Update components/form_taxi/package.json
wrktbiz 419e694
Update Form.taxi Pipedream source with latest version
wrktbiz d1aa9ff
Update Form.taxi Pipedream source with latest version
wrktbiz daa368d
Update Form.taxi Pipedream source with latest version
wrktbiz 8c5294b
Merge branch 'master' into master
lcaresia 0d35ce3
Update Form.taxi component with latest code changes
wrktbiz 7c94805
update pnpm-lock
GTFalcao 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
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,7 @@ | ||
| # Overview | ||
|
|
||
| Form.taxi provides a simple and secure way to handle form submissions without writing any server-side code. With Form.taxi, you can quickly connect your HTML forms and deliver submissions or integrate them into your existing workflows. By using Pipedream, you can automate actions in response to new form submissions—such as storing data, sending notifications, or connecting with third-party apps—making it easy to streamline processes and boost productivity. | ||
|
|
||
| # Troubleshooting | ||
|
|
||
| If you have issues with this integration, please reach out at [[email protected]](mailto:[email protected]). |
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,50 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| propDefinitions: {}, | ||
| type: "app", | ||
| app: "form_taxi", | ||
| propDefinitions: {}, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://form.taxi/int/pipedream/api/"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, headers, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: { | ||
| ...headers, | ||
| "Accept": "application/json", | ||
| "Content-Type": "application/json", | ||
| "Api-Key": this.$auth.api_key, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async createWebhook(hook_url) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: this.$auth.form_code, | ||
| data: { | ||
| hook_url, | ||
| }, | ||
| }); | ||
| }, | ||
| async deleteWebhook(id) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: this.$auth.form_code, | ||
| params: { | ||
| "hook_id": id, | ||
| }, | ||
| }); | ||
| }, | ||
| async getSampleData() { | ||
| return this._makeRequest({ | ||
| method: "GET", | ||
| path: this.$auth.form_code, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; |
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,15 +1,18 @@ | ||
| { | ||
| "name": "@pipedream/form_taxi", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Form.taxi Components", | ||
| "main": "form_taxi.app.mjs", | ||
| "keywords": [ | ||
| "pipedream", | ||
| "form_taxi" | ||
| ], | ||
| "homepage": "https://pipedream.com/apps/form_taxi", | ||
| "homepage": "https://pipedream.com/apps/form-taxi", | ||
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.1" | ||
| } | ||
wrktbiz 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,189 @@ | ||
| import formTaxi from "../../form_taxi.app.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| formTaxi, | ||
| db: "$.service.db", | ||
| http: { | ||
| type: "$.interface.http", | ||
| customResponse: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| async registerWebhook() { | ||
| const targetUrl = this.http.endpoint; | ||
| const resp = await this.formTaxi.createWebhook(targetUrl); | ||
|
|
||
| if (resp.status < 200 || resp.status >= 300) { | ||
| const msg = resp?.data?.message || "Unknown error"; | ||
| throw new Error( | ||
| `Error (${resp.status}): ${msg}`, | ||
| ); | ||
| } | ||
|
|
||
| const id = resp?.id; | ||
| const expires_at = resp?.expires_at; | ||
|
|
||
| if (!id) throw new Error("Response without id!"); | ||
| if (!expires_at) throw new Error("Response without Expire-Date!"); | ||
|
|
||
| await this.db.set("webhookId", id); | ||
| await this.db.set("webhookExpiresAt", expires_at); | ||
|
|
||
| return resp; | ||
| }, | ||
| async deleteWebhookById(hookId) { | ||
| if (!hookId) return; | ||
| const resp = await this.formTaxi.deleteWebhook(hookId); | ||
| if (resp.status >= 400) { | ||
| const msg = resp?.message || "Unknown error"; | ||
| console.warn(`Webhook-Delete failed: ${resp.status} ${msg}`); | ||
| } | ||
| }, | ||
| async deleteWebhook() { | ||
| const webhookId = await this.db.get("webhookId"); | ||
| if (!webhookId) return; | ||
| await this.deleteWebhookById(webhookId); | ||
| }, | ||
| msUntilExpiry(expiresAtIso) { | ||
| if (!expiresAtIso) return null; | ||
| const expMs = Date.parse(expiresAtIso); | ||
| if (Number.isNaN(expMs)) return null; | ||
| return expMs - Date.now(); | ||
| }, | ||
| async ensureWebhookFresh() { | ||
| const webhookId = await this.db.get("webhookId"); | ||
| const expiresAt = await this.db.get("webhookExpiresAt"); | ||
|
|
||
| const msLeft = this.msUntilExpiry(expiresAt); | ||
| const windowMs = 60 * 60 * 1000; | ||
|
|
||
| const shouldRenew = | ||
| !webhookId || | ||
| !msLeft || | ||
| msLeft <= 0 || | ||
| msLeft < windowMs; | ||
|
|
||
| if (!shouldRenew) return; | ||
|
|
||
| try { | ||
| const oldId = webhookId; | ||
| const res = await this.registerWebhook(); | ||
|
|
||
| if (oldId && res?.id && res.id !== oldId) { | ||
| await this.deleteWebhookById(oldId); | ||
| } | ||
|
|
||
| console.log(`Webhook renewed. New ID: ${res?.id || "unknown"}, expires at: ${res?.expires_at || "unknown"}`); | ||
| } catch (err) { | ||
| console.error(`Automatic renewal failed: ${err.message}`); | ||
| } | ||
| }, | ||
| eventIdFromBody(body) { | ||
| return ( | ||
| body?._id || | ||
| `${Date.now()}-${Math.random() | ||
| .toString(36) | ||
| .slice(2)}` | ||
| ); | ||
| }, | ||
| async fetchAndEmitSamples() { | ||
| try { | ||
| const resp = await this.formTaxi.getSampleData(); | ||
| if (resp.status < 200 || resp.status >= 300) { | ||
| const msg = resp?.message || "Unknown error"; | ||
| console.warn(`Sample-GET failed (${resp.status}): ${msg}`); | ||
| return; | ||
| } | ||
|
|
||
| const data = resp; | ||
| if (!data) { | ||
| console.warn("Sample-GET: empty response"); | ||
| return; | ||
| } | ||
|
|
||
| const emitOne = (obj) => { | ||
| const id = this.eventIdFromBody(obj || {}) || `sample-${Date.now()}`; | ||
| const ts = | ||
| (obj?.created_at && Date.parse(obj.created_at)) || | ||
| Date.now(); | ||
|
|
||
| this.$emit( | ||
| { | ||
| headers: { | ||
| "x-sample": "true", | ||
| }, | ||
| query: {}, | ||
| body: obj, | ||
| received_at: new Date().toISOString(), | ||
| source: "Form.taxi", | ||
| sample: true, | ||
| }, | ||
| { | ||
| id, | ||
| summary: "Sample submission", | ||
| ts, | ||
| }, | ||
| ); | ||
| }; | ||
|
|
||
| if (Array.isArray(data)) { | ||
| data.forEach(emitOne); | ||
| } else if (typeof data === "object") { | ||
| emitOne(data); | ||
| } else { | ||
| console.warn("Sample-GET: unknown format", data); | ||
| } | ||
| } catch (err) { | ||
| console.error(`Sample-GET Exception: ${err.message}`); | ||
| } | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.fetchAndEmitSamples(); | ||
| }, | ||
| async activate() { | ||
| const res = await this.registerWebhook(); | ||
| console.log("Webhook registered:", res); | ||
| }, | ||
| async deactivate() { | ||
| try { | ||
| await this.deleteWebhook(); | ||
| } catch (err) { | ||
| console.warn("Error removing the webhook:", err.message); | ||
| } | ||
| }, | ||
| }, | ||
| async run(event) { | ||
| await this.ensureWebhookFresh(); | ||
|
|
||
| await this.http.respond({ | ||
| status: 200, | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| }, | ||
| body: JSON.stringify({ | ||
| ok: true, | ||
| }), | ||
| }); | ||
|
|
||
| const id = this.eventIdFromBody(event.body || {}); | ||
| const summary = `Form Submission ID: ${id}`; | ||
| const ts = (event.body?.created_at && Date.parse(event.body.created_at)) || Date.now(); | ||
|
|
||
| const payload = { | ||
| headers: event.headers, | ||
| query: event.query, | ||
| body: event.body, | ||
| received_at: new Date().toISOString(), | ||
| source: "Form.taxi", | ||
| }; | ||
|
|
||
| this.$emit(payload, { | ||
| id, | ||
| summary: summary, | ||
| ts, | ||
| }); | ||
| }, | ||
| }; |
14 changes: 14 additions & 0 deletions
14
components/form_taxi/sources/new-form-submission/new-form-submission.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,14 @@ | ||
| import base from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...base, | ||
| type: "source", | ||
| name: "New Form Submission", | ||
| key: "form_taxi-new-form-submission", | ||
| version: "0.0.1", | ||
| description: "Emit new event when Form.taxi receives a new form submission. [About Form.taxi](https://form.taxi/en/backend)", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...base.methods, | ||
| }, | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.