-
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.
* moaform init * [Components] moaform #14132 Sources - New Submission (Instant) * pnpm update * Fix retention days label Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * some adjusts --------- Co-authored-by: Leo Vu <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
bfbec2e
commit 8fc65e1
Showing
6 changed files
with
219 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const RETENTION_DAYS_OPTIONS = [ | ||
{ | ||
label: "1", | ||
value: 1, | ||
}, | ||
{ | ||
label: "3", | ||
value: 3, | ||
}, | ||
{ | ||
label: "5", | ||
value: 5, | ||
}, | ||
{ | ||
label: "7", | ||
value: 7, | ||
}, | ||
{ | ||
label: "10", | ||
value: 10, | ||
}, | ||
{ | ||
label: "15", | ||
value: 15, | ||
}, | ||
{ | ||
label: "30", | ||
value: 30, | ||
}, | ||
]; |
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,68 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "moaform", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
formId: { | ||
type: "string", | ||
label: "Form ID", | ||
description: "The ID of the form to monitor for new submissions", | ||
async options({ page }) { | ||
const { items } = await this.getForms({ | ||
params: { | ||
page: page + 1, | ||
}, | ||
}); | ||
return items.map(({ | ||
id: value, title: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.moaform.com/v1"; | ||
}, | ||
_headers() { | ||
return { | ||
Authorization: `Bearer ${this.$auth.api_key}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
getForms(opts = {}) { | ||
return this._makeRequest({ | ||
...opts, | ||
path: "/forms", | ||
}); | ||
}, | ||
createWebhook({ | ||
formId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/forms/${formId}/webhooks`, | ||
...opts, | ||
}); | ||
}, | ||
deleteWebhook({ | ||
formId, webhookId, | ||
}) { | ||
return this._makeRequest({ | ||
method: "DELETE", | ||
path: `/forms/${formId}/webhooks/${webhookId}`, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
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/moaform", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Moaform Components", | ||
"main": "moaform.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
components/moaform/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,100 @@ | ||
import crypto from "crypto"; | ||
import { RETENTION_DAYS_OPTIONS } from "../../common/constants.mjs"; | ||
import moaform from "../../moaform.app.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
key: "moaform-new-submission-instant", | ||
name: "New Submission (Instant)", | ||
description: "Emit new event every time a new form submission is received.", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
moaform, | ||
http: { | ||
type: "$.interface.http", | ||
customResponse: true, | ||
}, | ||
db: "$.service.db", | ||
formId: { | ||
propDefinition: [ | ||
moaform, | ||
"formId", | ||
], | ||
}, | ||
retentionDays: { | ||
type: "integer", | ||
label: "Retention Days", | ||
description: "Resend restriction days", | ||
options: RETENTION_DAYS_OPTIONS, | ||
optional: true, | ||
}, | ||
secret: { | ||
type: "string", | ||
label: "Secret Code", | ||
description: "This code is used to verify that the data received at the specified endpoint has indeed been sent from Moaform and has not been tampered with.", | ||
secret: true, | ||
optional: true, | ||
}, | ||
}, | ||
methods: { | ||
_getWebhookId() { | ||
return this.db.get("webhookId"); | ||
}, | ||
_setWebhookId(id) { | ||
this.db.set("webhookId", id); | ||
}, | ||
}, | ||
hooks: { | ||
async activate() { | ||
const response = await this.moaform.createWebhook({ | ||
formId: this.formId, | ||
data: { | ||
endpoint: this.http.endpoint, | ||
enabled: true, | ||
secret: this.secret, | ||
verify_ssl: true, | ||
retention_days: this.retentionDays, | ||
}, | ||
}); | ||
this._setWebhookId(response.id); | ||
}, | ||
async deactivate() { | ||
const webhookId = this.db.get("webhookId"); | ||
await this.moaform.deleteWebhook({ | ||
formId: this.formId, | ||
webhookId, | ||
}); | ||
}, | ||
}, | ||
async run({ | ||
bodyRaw, body, headers, | ||
}) { | ||
|
||
if (this.secret) { | ||
const signature = headers["moaform-signature"]; | ||
const receivedSig = signature.split("sha256=")[1]; | ||
|
||
const calculatedSig = crypto | ||
.createHmac("sha256", this.secret) | ||
.update(bodyRaw) | ||
.digest("base64"); | ||
|
||
if (receivedSig !== calculatedSig) { | ||
return this.http.respond({ | ||
status: 401, | ||
body: "Unauthorized", | ||
}); | ||
} | ||
} | ||
|
||
const ts = Date.parse(body.submitted_at); | ||
this.$emit(body, { | ||
id: body.event_id, | ||
summary: `New submission received for form ${this.formId}`, | ||
ts: ts, | ||
}); | ||
}, | ||
sampleEmit, | ||
}; |
18 changes: 18 additions & 0 deletions
18
components/moaform/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,18 @@ | ||
export default { | ||
"event_id": "105fa72f-9e6e-4667-8ead-22b0a3ed254a", | ||
"event_type": "response_completed", | ||
"hidden": {}, | ||
"response_id": "test#123-45-67890", | ||
"submitted_at": "2024-09-27T21:00:55Z", | ||
"form": { | ||
"id": "MG7eAk", | ||
"title": "form title", | ||
"report_url": "https://www.moaform.com/reports/q945EegynYD8G2xM", | ||
"answer_url": "https://moaform.com/q/not-started-collecting" | ||
}, | ||
"answers": [], | ||
"thankyou": { | ||
"id": "cm1l7axyf2t9x0fqrly27vdn7", | ||
"url": "https://answer.moaform.com/answers/MG7eAk/thankyou/Wo2b1Z09wx5" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.