-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* opnform init * [Components] opnform #15639 Sources - New Submission (Instant) * pnpm update
- Loading branch information
1 parent
a8b768c
commit 79be8f3
Showing
5 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,83 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "opnform", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
workspaceId: { | ||
type: "string", | ||
label: "Workspace ID", | ||
description: "The ID of the workspace containing the forms.", | ||
async options() { | ||
const worspaces = await this.listWorkspaces(); | ||
return worspaces.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
formId: { | ||
type: "string", | ||
label: "Form", | ||
description: "Select the form to monitor for new submissions.", | ||
async options({ workspaceId }) { | ||
const forms = await this.listForms({ | ||
params: { | ||
workspace_id: workspaceId, | ||
}, | ||
}); | ||
return forms.map((form) => ({ | ||
label: form.name, | ||
value: form.id, | ||
})); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.opnform.com/external/zapier"; | ||
}, | ||
_headers() { | ||
return { | ||
Authorization: `Bearer ${this.$auth.api_key}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
listForms(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/forms", | ||
...opts, | ||
}); | ||
}, | ||
listWorkspaces(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/workspaces", | ||
...opts, | ||
}); | ||
}, | ||
createWebhook(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/webhook", | ||
...opts, | ||
}); | ||
}, | ||
deleteWebhook(opts = {}) { | ||
return this._makeRequest({ | ||
method: "DELETE", | ||
path: "/webhook", | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains 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,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/opnform", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream OpnForm Components", | ||
"main": "opnform.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
components/opnform/sources/new-submission-instant/new-submission-instant.mjs
This file contains 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,58 @@ | ||
import opnform from "../../opnform.app.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
key: "opnform-new-submission-instant", | ||
name: "New Submission Instant", | ||
description: "Emit new event when a form receives a submission.", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
opnform, | ||
http: "$.interface.http", | ||
db: "$.service.db", | ||
workspaceId: { | ||
propDefinition: [ | ||
opnform, | ||
"workspaceId", | ||
], | ||
}, | ||
formId: { | ||
propDefinition: [ | ||
opnform, | ||
"formId", | ||
({ workspaceId }) => ({ | ||
workspaceId, | ||
}), | ||
], | ||
}, | ||
}, | ||
hooks: { | ||
async activate() { | ||
await this.opnform.createWebhook({ | ||
data: { | ||
hookUrl: this.http.endpoint, | ||
form_id: this.formId, | ||
}, | ||
}); | ||
}, | ||
async deactivate() { | ||
await this.opnform.deleteWebhook({ | ||
data: { | ||
hookUrl: this.http.endpoint, | ||
form_id: this.formId, | ||
}, | ||
}); | ||
}, | ||
}, | ||
async run({ body }) { | ||
const ts = Date.now(); | ||
this.$emit(body, { | ||
id: `${body.form_slug}-${ts}`, | ||
summary: `New submission for "${body.form_title}"`, | ||
ts, | ||
}); | ||
}, | ||
sampleEmit, | ||
}; |
24 changes: 24 additions & 0 deletions
24
components/opnform/sources/new-submission-instant/test-event.mjs
This file contains 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,24 @@ | ||
export default { | ||
"form_title": "My Form", | ||
"form_slug": "my-form-dtewbq", | ||
"submission": { | ||
"Name": "User Name", | ||
"Email": "[email protected]", | ||
"Message": "User Message" | ||
}, | ||
"data": { | ||
"3cc8fbba-1234-1234-979d-0e81d8f6845c": { | ||
"value": "USer Name", | ||
"name": "Name" | ||
}, | ||
"9a1778ff-1234-1234-a62c-197dae1ed3c0": { | ||
"value": "[email protected]", | ||
"name": "Email" | ||
}, | ||
"ddd28630-1234-1234-bbe5-4f58c485d470": { | ||
"value": "USer Message", | ||
"name": "Message" | ||
} | ||
}, | ||
"message": "Please do not use the `submission` field. It is deprecated and will be removed in the future." | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.