diff --git a/components/opnform/opnform.app.mjs b/components/opnform/opnform.app.mjs index 5d7a7fb15c1ce..2f182b96df28f 100644 --- a/components/opnform/opnform.app.mjs +++ b/components/opnform/opnform.app.mjs @@ -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, + }); }, }, }; diff --git a/components/opnform/package.json b/components/opnform/package.json index 5aa0ca20c8e7e..bdb9666195ab1 100644 --- a/components/opnform/package.json +++ b/components/opnform/package.json @@ -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 (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/opnform/sources/new-submission-instant/new-submission-instant.mjs b/components/opnform/sources/new-submission-instant/new-submission-instant.mjs new file mode 100644 index 0000000000000..e37adeb66f873 --- /dev/null +++ b/components/opnform/sources/new-submission-instant/new-submission-instant.mjs @@ -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, +}; diff --git a/components/opnform/sources/new-submission-instant/test-event.mjs b/components/opnform/sources/new-submission-instant/test-event.mjs new file mode 100644 index 0000000000000..4f17754a4ce18 --- /dev/null +++ b/components/opnform/sources/new-submission-instant/test-event.mjs @@ -0,0 +1,24 @@ +export default { + "form_title": "My Form", + "form_slug": "my-form-dtewbq", + "submission": { + "Name": "User Name", + "Email": "user@email.com", + "Message": "User Message" + }, + "data": { + "3cc8fbba-1234-1234-979d-0e81d8f6845c": { + "value": "USer Name", + "name": "Name" + }, + "9a1778ff-1234-1234-a62c-197dae1ed3c0": { + "value": "user@email.com", + "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." +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 25f2f4f8316b0..4c982a0f5efbe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6660,8 +6660,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/kindo: - specifiers: {} + components/kindo: {} components/kingsumo: dependencies: @@ -7871,8 +7870,7 @@ importers: components/mindmeister: {} - components/mindstudio: - specifiers: {} + components/mindstudio: {} components/minio: {} @@ -8787,7 +8785,11 @@ importers: specifier: ^0.9.0 version: 0.9.0 - components/opnform: {} + components/opnform: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/opsgenie: dependencies: @@ -12295,8 +12297,7 @@ importers: components/synthflow: {} - components/systeme_io: - specifiers: {} + components/systeme_io: {} components/t2m_url_shortener: {}