Skip to content

Commit 1ad795f

Browse files
wrktbizcoderabbitai[bot]GTFalcaolcaresia
authored
Added Component Form.taxi (#18198)
* Added Form.taxi * Update components/form_taxi/package.json Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/form_taxi/sources/new-form-submission/new-form-submission.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update package.json * Update new-form-submission.mjs Hook Correction * Apply suggestion from @lcaresia Co-authored-by: Lucas Caresia <[email protected]> * Apply suggestion from @lcaresia Co-authored-by: Lucas Caresia <[email protected]> * Update Form.taxi component with latest code revisions * Update Form.taxi Pipedream source with latest version * Update Form.taxi Pipedream source with latest version * Update Form.taxi Pipedream source with latest version * Update Form.taxi Pipedream source with latest version * Update components/form_taxi/sources/new-form-submission/new-form-submission.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/sources/common/base.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/sources/common/base.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/sources/common/base.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/sources/common/base.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/sources/common/base.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/form_taxi.app.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/sources/common/base.mjs Co-authored-by: Lucas Caresia <[email protected]> * Update components/form_taxi/package.json Co-authored-by: Lucas Caresia <[email protected]> * Update Form.taxi Pipedream source with latest version * Update Form.taxi Pipedream source with latest version * Update Form.taxi Pipedream source with latest version * Update Form.taxi component with latest code changes * update pnpm-lock --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Guilherme Falcão <[email protected]> Co-authored-by: Lucas Caresia <[email protected]> Co-authored-by: GTFalcao <[email protected]>
1 parent b616f42 commit 1ad795f

File tree

6 files changed

+268
-12
lines changed

6 files changed

+268
-12
lines changed

components/form_taxi/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Overview
2+
3+
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.
4+
5+
# Troubleshooting
6+
7+
If you have issues with this integration, please reach out at [[email protected]](mailto:[email protected]).
Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
4+
propDefinitions: {},
25
type: "app",
36
app: "form_taxi",
4-
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_baseUrl() {
9+
return "https://form.taxi/int/pipedream/api/";
10+
},
11+
_makeRequest({
12+
$ = this, path, headers, ...opts
13+
}) {
14+
return axios($, {
15+
url: this._baseUrl() + path,
16+
headers: {
17+
...headers,
18+
"Accept": "application/json",
19+
"Content-Type": "application/json",
20+
"Api-Key": this.$auth.api_key,
21+
},
22+
...opts,
23+
});
24+
},
25+
async createWebhook(hook_url) {
26+
return this._makeRequest({
27+
method: "POST",
28+
path: this.$auth.form_code,
29+
data: {
30+
hook_url,
31+
},
32+
});
33+
},
34+
async deleteWebhook(id) {
35+
return this._makeRequest({
36+
method: "DELETE",
37+
path: this.$auth.form_code,
38+
params: {
39+
"hook_id": id,
40+
},
41+
});
42+
},
43+
async getSampleData() {
44+
return this._makeRequest({
45+
method: "GET",
46+
path: this.$auth.form_code,
47+
});
948
},
1049
},
11-
};
50+
};

components/form_taxi/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
{
22
"name": "@pipedream/form_taxi",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Form.taxi Components",
55
"main": "form_taxi.app.mjs",
66
"keywords": [
77
"pipedream",
88
"form_taxi"
99
],
10-
"homepage": "https://pipedream.com/apps/form_taxi",
10+
"homepage": "https://pipedream.com/apps/form-taxi",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
15-
}
18+
}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import formTaxi from "../../form_taxi.app.mjs";
2+
3+
export default {
4+
props: {
5+
formTaxi,
6+
db: "$.service.db",
7+
http: {
8+
type: "$.interface.http",
9+
customResponse: true,
10+
},
11+
},
12+
methods: {
13+
async registerWebhook() {
14+
const targetUrl = this.http.endpoint;
15+
const resp = await this.formTaxi.createWebhook(targetUrl);
16+
17+
if (resp.status < 200 || resp.status >= 300) {
18+
const msg = resp?.data?.message || "Unknown error";
19+
throw new Error(
20+
`Error (${resp.status}): ${msg}`,
21+
);
22+
}
23+
24+
const id = resp?.id;
25+
const expires_at = resp?.expires_at;
26+
27+
if (!id) throw new Error("Response without id!");
28+
if (!expires_at) throw new Error("Response without Expire-Date!");
29+
30+
await this.db.set("webhookId", id);
31+
await this.db.set("webhookExpiresAt", expires_at);
32+
33+
return resp;
34+
},
35+
async deleteWebhookById(hookId) {
36+
if (!hookId) return;
37+
const resp = await this.formTaxi.deleteWebhook(hookId);
38+
if (resp.status >= 400) {
39+
const msg = resp?.message || "Unknown error";
40+
console.warn(`Webhook-Delete failed: ${resp.status} ${msg}`);
41+
}
42+
},
43+
async deleteWebhook() {
44+
const webhookId = await this.db.get("webhookId");
45+
if (!webhookId) return;
46+
await this.deleteWebhookById(webhookId);
47+
},
48+
msUntilExpiry(expiresAtIso) {
49+
if (!expiresAtIso) return null;
50+
const expMs = Date.parse(expiresAtIso);
51+
if (Number.isNaN(expMs)) return null;
52+
return expMs - Date.now();
53+
},
54+
async ensureWebhookFresh() {
55+
const webhookId = await this.db.get("webhookId");
56+
const expiresAt = await this.db.get("webhookExpiresAt");
57+
58+
const msLeft = this.msUntilExpiry(expiresAt);
59+
const windowMs = 60 * 60 * 1000;
60+
61+
const shouldRenew =
62+
!webhookId ||
63+
!msLeft ||
64+
msLeft <= 0 ||
65+
msLeft < windowMs;
66+
67+
if (!shouldRenew) return;
68+
69+
try {
70+
const oldId = webhookId;
71+
const res = await this.registerWebhook();
72+
73+
if (oldId && res?.id && res.id !== oldId) {
74+
await this.deleteWebhookById(oldId);
75+
}
76+
77+
console.log(`Webhook renewed. New ID: ${res?.id || "unknown"}, expires at: ${res?.expires_at || "unknown"}`);
78+
} catch (err) {
79+
console.error(`Automatic renewal failed: ${err.message}`);
80+
}
81+
},
82+
eventIdFromBody(body) {
83+
return (
84+
body?._id ||
85+
`${Date.now()}-${Math.random()
86+
.toString(36)
87+
.slice(2)}`
88+
);
89+
},
90+
async fetchAndEmitSamples() {
91+
try {
92+
const resp = await this.formTaxi.getSampleData();
93+
if (resp.status < 200 || resp.status >= 300) {
94+
const msg = resp?.message || "Unknown error";
95+
console.warn(`Sample-GET failed (${resp.status}): ${msg}`);
96+
return;
97+
}
98+
99+
const data = resp;
100+
if (!data) {
101+
console.warn("Sample-GET: empty response");
102+
return;
103+
}
104+
105+
const emitOne = (obj) => {
106+
const id = this.eventIdFromBody(obj || {}) || `sample-${Date.now()}`;
107+
const ts =
108+
(obj?.created_at && Date.parse(obj.created_at)) ||
109+
Date.now();
110+
111+
this.$emit(
112+
{
113+
headers: {
114+
"x-sample": "true",
115+
},
116+
query: {},
117+
body: obj,
118+
received_at: new Date().toISOString(),
119+
source: "Form.taxi",
120+
sample: true,
121+
},
122+
{
123+
id,
124+
summary: "Sample submission",
125+
ts,
126+
},
127+
);
128+
};
129+
130+
if (Array.isArray(data)) {
131+
data.forEach(emitOne);
132+
} else if (typeof data === "object") {
133+
emitOne(data);
134+
} else {
135+
console.warn("Sample-GET: unknown format", data);
136+
}
137+
} catch (err) {
138+
console.error(`Sample-GET Exception: ${err.message}`);
139+
}
140+
},
141+
},
142+
hooks: {
143+
async deploy() {
144+
await this.fetchAndEmitSamples();
145+
},
146+
async activate() {
147+
const res = await this.registerWebhook();
148+
console.log("Webhook registered:", res);
149+
},
150+
async deactivate() {
151+
try {
152+
await this.deleteWebhook();
153+
} catch (err) {
154+
console.warn("Error removing the webhook:", err.message);
155+
}
156+
},
157+
},
158+
async run(event) {
159+
await this.ensureWebhookFresh();
160+
161+
await this.http.respond({
162+
status: 200,
163+
headers: {
164+
"Content-Type": "application/json",
165+
},
166+
body: JSON.stringify({
167+
ok: true,
168+
}),
169+
});
170+
171+
const id = this.eventIdFromBody(event.body || {});
172+
const summary = `Form Submission ID: ${id}`;
173+
const ts = (event.body?.created_at && Date.parse(event.body.created_at)) || Date.now();
174+
175+
const payload = {
176+
headers: event.headers,
177+
query: event.query,
178+
body: event.body,
179+
received_at: new Date().toISOString(),
180+
source: "Form.taxi",
181+
};
182+
183+
this.$emit(payload, {
184+
id,
185+
summary: summary,
186+
ts,
187+
});
188+
},
189+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import base from "../common/base.mjs";
2+
3+
export default {
4+
...base,
5+
type: "source",
6+
name: "New Form Submission",
7+
key: "form_taxi-new-form-submission",
8+
version: "0.0.1",
9+
description: "Emit new event when Form.taxi receives a new form submission. [About Form.taxi](https://form.taxi/en/backend)",
10+
dedupe: "unique",
11+
methods: {
12+
...base.methods,
13+
},
14+
};

pnpm-lock.yaml

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)