From 37ca88738517b8d668db96cba8bfdb8bbbf6938a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20S=C3=B6llradl?= <7169663+wrktbiz@users.noreply.github.com> Date: Wed, 27 Aug 2025 17:43:11 +0200 Subject: [PATCH 1/5] Added Form.taxi --- components/form_taxi/README.md | 7 + components/form_taxi/form_taxi.app.mjs | 6 + components/form_taxi/package.json | 22 ++ .../new-form-submission.mjs | 247 ++++++++++++++++++ 4 files changed, 282 insertions(+) create mode 100644 components/form_taxi/README.md create mode 100644 components/form_taxi/form_taxi.app.mjs create mode 100644 components/form_taxi/package.json create mode 100644 components/form_taxi/sources/new-form-submission/new-form-submission.mjs diff --git a/components/form_taxi/README.md b/components/form_taxi/README.md new file mode 100644 index 0000000000000..6326aaf180d7b --- /dev/null +++ b/components/form_taxi/README.md @@ -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 [support@form.taxi](mailto:support@form.taxi). \ No newline at end of file diff --git a/components/form_taxi/form_taxi.app.mjs b/components/form_taxi/form_taxi.app.mjs new file mode 100644 index 0000000000000..b3b90af408a6f --- /dev/null +++ b/components/form_taxi/form_taxi.app.mjs @@ -0,0 +1,6 @@ +export default { + type: "app", + app: "form_taxi", + name: "Form.taxi", + description: "Receive submissions from Form.taxi", +} \ No newline at end of file diff --git a/components/form_taxi/package.json b/components/form_taxi/package.json new file mode 100644 index 0000000000000..bf5600245282c --- /dev/null +++ b/components/form_taxi/package.json @@ -0,0 +1,22 @@ +{ + "name": "@pipedream/form_taxi", + "version": "0.0.1", + "description": "Pipedream Form.taxi Components", + "main": "form_taxi.app.js", + "keywords": [ + "pipedream", + "form_taxi" + ], + "homepage": "https://pipedream.com/apps/form_taxi", + "author": "Pipedream (https://pipedream.com/)", + "dependencies": { + "@pipedream/platform": "^3.1.0" + }, + "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535", + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "package": "^1.0.1" + } +} diff --git a/components/form_taxi/sources/new-form-submission/new-form-submission.mjs b/components/form_taxi/sources/new-form-submission/new-form-submission.mjs new file mode 100644 index 0000000000000..86653d4ec97cd --- /dev/null +++ b/components/form_taxi/sources/new-form-submission/new-form-submission.mjs @@ -0,0 +1,247 @@ +import form_taxi from "../../form_taxi.app.mjs"; +import axios from "axios"; + +export default { + 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)", + + props: { + db: { type: "$.service.db", label: "Database" }, + http: { type: "$.interface.http", label: "HTTP Interface", customResponse: true }, + alert: { + type: "alert", + alertType: "info", + content: "Open the [Form.taxi Panel](https://form.taxi/panel/forms) to retrieve the Form Code and API Key. These are displayed in the form settings under Information.", + }, + form_code: { + type: "string", + label: "Form Code", + }, + form_taxi_api_key: { + type: "string", + label: "API Key", + secret: true, + }, + }, + + dedupe: "unique", + + methods: { + api() { + return axios.create({ + headers: { + "Api-Key": this.form_taxi_api_key, + "Content-Type": "application/json", + }, + timeout: 10000, + validateStatus: () => true, + }); + }, + + subscriptionBaseUrl() { + return `https://form.taxi/int/pipedream/webhook_subscription/${encodeURIComponent(this.form_code)}`; + }, + + async registerWebhook() { + const targetUrl = this.http.endpoint; + const resp = await this.api().post(this.subscriptionBaseUrl(), { hook_url: 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?.data?.id; + const expires_at = resp?.data?.expires_at; // ISO-8601 erwartet + + 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.data; + }, + + async deleteWebhookById(hookId) { + if (!hookId) return; + const url = `${this.subscriptionBaseUrl()}?hook_id=${encodeURIComponent(hookId)}`; + const resp = await this.api().delete(url); + if (resp.status >= 400) { + const msg = resp?.data?.message || "Unknown error"; + console.warn(`Webhook-Delete fehlgeschlagen: ${resp.status} ${msg}`); + } + }, + + async deleteWebhook() { + const webhookId = await this.db.get("webhookId"); + if (!webhookId) return; + await this.deleteWebhookById(webhookId); + }, + + // ---- Ablaufprüfung & Erneuerung ---- + 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"); + + // Wenn wir kein Ablaufdatum kennen, machen wir nichts (oder könnten aggressiv erneuern). + const msLeft = this.msUntilExpiry(expiresAt); + const windowMs = 60 * 60 * 1000; // 60 Minuten + + // Erneuerungsbedingungen: + // - kein webhookId (unerwartet) ODER + // - kein expiresAt bekannt ODER + // - bereits abgelaufen ODER + // - Restlaufzeit < renewal window + const shouldRenew = + !webhookId || + !msLeft || + msLeft <= 0 || + msLeft < windowMs; + + if (!shouldRenew) return; + + try { + // Neu registrieren + const oldId = webhookId; + const res = await this.registerWebhook(); + + // Alten Hook bereinigen (best effort), wenn wir eine neue ID haben + if (oldId && res?.id && res.id !== oldId) { + await this.deleteWebhookById(oldId); + } + + console.log( + `Webhook erstellt/erneuert. Neue ID: ${res?.id || "unbekannt"}, läuft bis: ${res?.expires_at || "unbekannt"}` + ); + } catch (err) { + console.error(`Automatische Erneuerung fehlgeschlagen: ${err.message}`); + } + }, + + eventIdFromBody(body) { + return ( + body?._id || + `${Date.now()}-${Math.random().toString(36).slice(2)}` + ); + }, + + async fetchAndEmitSamples() { + try { + const resp = await this.api().get(this.subscriptionBaseUrl()); + if (resp.status < 200 || resp.status >= 300) { + const msg = resp?.data?.message || "Unknown error"; + console.warn(`Sample-GET fehlgeschlagen (${resp.status}): ${msg}`); + return; + } + + const data = resp.data; + if (!data) { + console.warn("Sample-GET: leere Antwort"); + return; + } + + const emitOne = (obj) => { + const id = this.eventIdFromBody(obj || {}) || `sample-${Date.now()}`; + const ts = + (obj?.created_at && Date.parse(obj.created_at)) || + Date.now(); + + // Wir packen die Daten in das gleiche Format wie echte Events + 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: unbekanntes Format", data); + } + } catch (err) { + console.error(`Sample-GET Exception: ${err.message}`); + } + }, + }, + + async hooks() { + return { + async deploy() { + + // Unmittelbar Sample-Daten laden und emittieren + await this.fetchAndEmitSamples(); + }, + async activate() { + + // Webhook frisch registrieren + const res = await this.registerWebhook(); + console.log("Webhook registriert:", res); + }, + async deactivate() { + try { + await this.deleteWebhook(); + } catch (err) { + console.warn("Fehler beim Entfernen des Webhooks:", err.message); + } + }, + }; + }, + + async run(event) { + // Vor der Verarbeitung prüfen, ob der Hook bald abläuft und ggf. erneuern + await this.ensureWebhookFresh(); + + // Sofort ACK an Form.taxi + await this.http.respond({ + status: 200, + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ ok: true }), + }); + + // Event emittieren + 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, + }); + }, +}; \ No newline at end of file From 2670165a2d374cbb7f9e509d4463ddd992e01ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20S=C3=B6llradl?= <7169663+wrktbiz@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:30:49 +0200 Subject: [PATCH 2/5] Update components/form_taxi/package.json Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- components/form_taxi/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/form_taxi/package.json b/components/form_taxi/package.json index bf5600245282c..6c515e3960bd4 100644 --- a/components/form_taxi/package.json +++ b/components/form_taxi/package.json @@ -2,7 +2,7 @@ "name": "@pipedream/form_taxi", "version": "0.0.1", "description": "Pipedream Form.taxi Components", - "main": "form_taxi.app.js", + "main": "form_taxi.app.mjs", "keywords": [ "pipedream", "form_taxi" From 132174294881a3ec47cdc99ad64c3408bac7d68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20S=C3=B6llradl?= <7169663+wrktbiz@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:36:23 +0200 Subject: [PATCH 3/5] Update components/form_taxi/sources/new-form-submission/new-form-submission.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../new-form-submission.mjs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/components/form_taxi/sources/new-form-submission/new-form-submission.mjs b/components/form_taxi/sources/new-form-submission/new-form-submission.mjs index 86653d4ec97cd..969bb5db8fb10 100644 --- a/components/form_taxi/sources/new-form-submission/new-form-submission.mjs +++ b/components/form_taxi/sources/new-form-submission/new-form-submission.mjs @@ -190,27 +190,25 @@ export default { }, }, - async hooks() { - return { - async deploy() { + hooks: { + async deploy() { - // Unmittelbar Sample-Daten laden und emittieren - await this.fetchAndEmitSamples(); - }, - async activate() { + // Unmittelbar Sample-Daten laden und emittieren + await this.fetchAndEmitSamples(); + }, + async activate() { - // Webhook frisch registrieren - const res = await this.registerWebhook(); - console.log("Webhook registriert:", res); - }, - async deactivate() { - try { - await this.deleteWebhook(); - } catch (err) { - console.warn("Fehler beim Entfernen des Webhooks:", err.message); - } - }, - }; + // Webhook frisch registrieren + const res = await this.registerWebhook(); + console.log("Webhook registriert:", res); + }, + async deactivate() { + try { + await this.deleteWebhook(); + } catch (err) { + console.warn("Fehler beim Entfernen des Webhooks:", err.message); + } + }, }, async run(event) { From ee654b5728a71eb64aaa257d716c550cfa60c7b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20S=C3=B6llradl?= <7169663+wrktbiz@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:50:54 +0200 Subject: [PATCH 4/5] Update package.json --- components/form_taxi/package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/form_taxi/package.json b/components/form_taxi/package.json index 6c515e3960bd4..9d74497291d26 100644 --- a/components/form_taxi/package.json +++ b/components/form_taxi/package.json @@ -7,10 +7,11 @@ "pipedream", "form_taxi" ], - "homepage": "https://pipedream.com/apps/form_taxi", + "homepage": "https://pipedream.com/apps/form-taxi", "author": "Pipedream (https://pipedream.com/)", "dependencies": { - "@pipedream/platform": "^3.1.0" + "@pipedream/platform": "^3.1.0", + "axios": "^1.11.0" }, "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535", "publishConfig": { From efcedd7191e598a549d66ff66a81ae4131c7e8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20S=C3=B6llradl?= <7169663+wrktbiz@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:51:45 +0200 Subject: [PATCH 5/5] Update new-form-submission.mjs Hook Correction --- .../new-form-submission.mjs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/components/form_taxi/sources/new-form-submission/new-form-submission.mjs b/components/form_taxi/sources/new-form-submission/new-form-submission.mjs index 969bb5db8fb10..ecba32d497f87 100644 --- a/components/form_taxi/sources/new-form-submission/new-form-submission.mjs +++ b/components/form_taxi/sources/new-form-submission/new-form-submission.mjs @@ -124,7 +124,7 @@ export default { } console.log( - `Webhook erstellt/erneuert. Neue ID: ${res?.id || "unbekannt"}, läuft bis: ${res?.expires_at || "unbekannt"}` + `Webhook erneuert. Neue ID: ${res?.id || "unbekannt"}, läuft bis: ${res?.expires_at || "unbekannt"}` ); } catch (err) { console.error(`Automatische Erneuerung fehlgeschlagen: ${err.message}`); @@ -191,24 +191,24 @@ export default { }, hooks: { - async deploy() { + async deploy() { - // Unmittelbar Sample-Daten laden und emittieren - await this.fetchAndEmitSamples(); - }, - async activate() { + // Unmittelbar Sample-Daten laden und emittieren + await this.fetchAndEmitSamples(); + }, + async activate() { - // Webhook frisch registrieren - const res = await this.registerWebhook(); - console.log("Webhook registriert:", res); - }, - async deactivate() { - try { - await this.deleteWebhook(); - } catch (err) { - console.warn("Fehler beim Entfernen des Webhooks:", err.message); - } - }, + // Webhook frisch registrieren + const res = await this.registerWebhook(); + console.log("Webhook registriert:", res); + }, + async deactivate() { + try { + await this.deleteWebhook(); + } catch (err) { + console.warn("Fehler beim Entfernen des Webhooks:", err.message); + } + }, }, async run(event) {