-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Open
wrktbiz
wants to merge
6
commits into
PipedreamHQ:master
Choose a base branch
from
wrktbiz:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added Component Form.taxi #18198
Changes from all commits
Commits
Show all changes
6 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 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
type: "app", | ||
app: "form_taxi", | ||
name: "Form.taxi", | ||
description: "Receive submissions from Form.taxi", | ||
} |
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,23 @@ | ||
{ | ||
"name": "@pipedream/form_taxi", | ||
"version": "0.0.1", | ||
"description": "Pipedream Form.taxi Components", | ||
"main": "form_taxi.app.mjs", | ||
"keywords": [ | ||
"pipedream", | ||
"form_taxi" | ||
], | ||
"homepage": "https://pipedream.com/apps/form-taxi", | ||
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"dependencies": { | ||
"@pipedream/platform": "^3.1.0", | ||
"axios": "^1.11.0" | ||
}, | ||
"gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"package": "^1.0.1" | ||
} | ||
} |
245 changes: 245 additions & 0 deletions
245
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,245 @@ | ||
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, | ||
}, | ||
}, | ||
wrktbiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 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}`); | ||
} | ||
}, | ||
}, | ||
|
||
hooks: { | ||
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 }), | ||
}); | ||
|
||
wrktbiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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, | ||
}); | ||
}, | ||
}; |
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.