Skip to content

Commit 79be8f3

Browse files
authored
New Components - opnform (#15734)
* opnform init * [Components] opnform #15639 Sources - New Submission (Instant) * pnpm update
1 parent a8b768c commit 79be8f3

File tree

5 files changed

+167
-6
lines changed

5 files changed

+167
-6
lines changed

components/opnform/opnform.app.mjs

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,83 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "opnform",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
workspaceId: {
8+
type: "string",
9+
label: "Workspace ID",
10+
description: "The ID of the workspace containing the forms.",
11+
async options() {
12+
const worspaces = await this.listWorkspaces();
13+
return worspaces.map(({
14+
id: value, name: label,
15+
}) => ({
16+
label,
17+
value,
18+
}));
19+
},
20+
},
21+
formId: {
22+
type: "string",
23+
label: "Form",
24+
description: "Select the form to monitor for new submissions.",
25+
async options({ workspaceId }) {
26+
const forms = await this.listForms({
27+
params: {
28+
workspace_id: workspaceId,
29+
},
30+
});
31+
return forms.map((form) => ({
32+
label: form.name,
33+
value: form.id,
34+
}));
35+
},
36+
},
37+
},
538
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
39+
_baseUrl() {
40+
return "https://api.opnform.com/external/zapier";
41+
},
42+
_headers() {
43+
return {
44+
Authorization: `Bearer ${this.$auth.api_key}`,
45+
};
46+
},
47+
_makeRequest({
48+
$ = this, path, ...opts
49+
}) {
50+
return axios($, {
51+
url: this._baseUrl() + path,
52+
headers: this._headers(),
53+
...opts,
54+
});
55+
},
56+
listForms(opts = {}) {
57+
return this._makeRequest({
58+
path: "/forms",
59+
...opts,
60+
});
61+
},
62+
listWorkspaces(opts = {}) {
63+
return this._makeRequest({
64+
path: "/workspaces",
65+
...opts,
66+
});
67+
},
68+
createWebhook(opts = {}) {
69+
return this._makeRequest({
70+
method: "POST",
71+
path: "/webhook",
72+
...opts,
73+
});
74+
},
75+
deleteWebhook(opts = {}) {
76+
return this._makeRequest({
77+
method: "DELETE",
78+
path: "/webhook",
79+
...opts,
80+
});
981
},
1082
},
1183
};

components/opnform/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/opnform",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream OpnForm Components",
55
"main": "opnform.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import opnform from "../../opnform.app.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
key: "opnform-new-submission-instant",
6+
name: "New Submission Instant",
7+
description: "Emit new event when a form receives a submission.",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
opnform,
13+
http: "$.interface.http",
14+
db: "$.service.db",
15+
workspaceId: {
16+
propDefinition: [
17+
opnform,
18+
"workspaceId",
19+
],
20+
},
21+
formId: {
22+
propDefinition: [
23+
opnform,
24+
"formId",
25+
({ workspaceId }) => ({
26+
workspaceId,
27+
}),
28+
],
29+
},
30+
},
31+
hooks: {
32+
async activate() {
33+
await this.opnform.createWebhook({
34+
data: {
35+
hookUrl: this.http.endpoint,
36+
form_id: this.formId,
37+
},
38+
});
39+
},
40+
async deactivate() {
41+
await this.opnform.deleteWebhook({
42+
data: {
43+
hookUrl: this.http.endpoint,
44+
form_id: this.formId,
45+
},
46+
});
47+
},
48+
},
49+
async run({ body }) {
50+
const ts = Date.now();
51+
this.$emit(body, {
52+
id: `${body.form_slug}-${ts}`,
53+
summary: `New submission for "${body.form_title}"`,
54+
ts,
55+
});
56+
},
57+
sampleEmit,
58+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default {
2+
"form_title": "My Form",
3+
"form_slug": "my-form-dtewbq",
4+
"submission": {
5+
"Name": "User Name",
6+
"Email": "user@email.com",
7+
"Message": "User Message"
8+
},
9+
"data": {
10+
"3cc8fbba-1234-1234-979d-0e81d8f6845c": {
11+
"value": "USer Name",
12+
"name": "Name"
13+
},
14+
"9a1778ff-1234-1234-a62c-197dae1ed3c0": {
15+
"value": "user@email.com",
16+
"name": "Email"
17+
},
18+
"ddd28630-1234-1234-bbe5-4f58c485d470": {
19+
"value": "USer Message",
20+
"name": "Message"
21+
}
22+
},
23+
"message": "Please do not use the `submission` field. It is deprecated and will be removed in the future."
24+
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)