-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - paperform #14306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - paperform #14306
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,18 +1,18 @@ | ||
{ | ||
"name": "@pipedream/paperform", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Pipedream PaperForm Components", | ||
"main": "dist/app/paperform.app.mjs", | ||
"main": "paperform.app.mjs", | ||
"keywords": [ | ||
"pipedream", | ||
"paperform" | ||
], | ||
"files": [ | ||
"dist" | ||
], | ||
"homepage": "https://pipedream.com/apps/paperform", | ||
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} |
This file contains hidden or 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,88 @@ | ||
import { axios } from "@pipedream/platform"; | ||
const DEFAULT_LIMIT = 100; | ||
|
||
export default { | ||
type: "app", | ||
app: "paperform", | ||
propDefinitions: { | ||
formId: { | ||
type: "string", | ||
label: "Form ID", | ||
description: "The ID of the form to monitor", | ||
async options({ page }) { | ||
const { results: { forms } } = await this.listForms({ | ||
params: { | ||
limit: DEFAULT_LIMIT, | ||
skip: page * DEFAULT_LIMIT, | ||
}, | ||
}); | ||
return forms?.map(({ | ||
id: value, title: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})) || []; | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_baseUrl() { | ||
return "https://api.paperform.co/v1"; | ||
}, | ||
_makeRequest(opts = {}) { | ||
const { | ||
$ = this, | ||
path, | ||
...otherOpts | ||
} = opts; | ||
return axios($, { | ||
...otherOpts, | ||
url: `${this._baseUrl()}${path}`, | ||
headers: { | ||
Authorization: `Bearer ${this.$auth.api_key}`, | ||
}, | ||
}); | ||
}, | ||
listForms(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/forms", | ||
...opts, | ||
}); | ||
}, | ||
listSubmissions({ | ||
formId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/forms/${formId}/submissions`, | ||
...opts, | ||
}); | ||
}, | ||
async *paginate({ | ||
fn, args, resourceKey, max, | ||
}) { | ||
args = { | ||
...args, | ||
params: { | ||
...args?.params, | ||
limit: DEFAULT_LIMIT, | ||
skip: 0, | ||
}, | ||
}; | ||
let hasMore, count = 0; | ||
do { | ||
const { | ||
results, has_more: more, | ||
} = await fn(args); | ||
const items = results[resourceKey]; | ||
for (const item of items) { | ||
yield item; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (max && ++count >= max) { | ||
return; | ||
} | ||
} | ||
hasMore = more; | ||
args.params.skip += args.params.limit; | ||
} while (hasMore); | ||
}, | ||
}, | ||
}; |
83 changes: 83 additions & 0 deletions
83
components/paperform/sources/new-submission/new-submission.mjs
This file contains hidden or 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,83 @@ | ||
import paperform from "../../paperform.app.mjs"; | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
|
||
export default { | ||
key: "paperform-new-submission", | ||
name: "New Submission", | ||
description: "Emit new event when a new submission is made on the specified form in Paperform. [See the documentation](https://paperform.readme.io/reference/listformsubmissions)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
paperform, | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
db: "$.service.db", | ||
formId: { | ||
propDefinition: [ | ||
paperform, | ||
"formId", | ||
], | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
await this.processEvent(25); | ||
}, | ||
}, | ||
methods: { | ||
_getLastTs() { | ||
return this.db.get("lastTs") || 0; | ||
}, | ||
_setLastTs(lastTs) { | ||
this.db.set("lastTs", lastTs); | ||
}, | ||
generateMeta(submission) { | ||
return { | ||
id: submission.id, | ||
summary: `New Submission ID: ${submission.id}`, | ||
ts: Date.parse(submission.created_at), | ||
}; | ||
}, | ||
async processEvent(max) { | ||
const lastTs = this._getLastTs(); | ||
|
||
const items = this.paperform.paginate({ | ||
fn: this.paperform.listSubmissions, | ||
args: { | ||
formId: this.formId, | ||
}, | ||
resourceKey: "submissions", | ||
max, | ||
}); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const submissions = []; | ||
for await (const item of items) { | ||
const ts = Date.parse(item.created_at); | ||
if (ts >= lastTs) { | ||
submissions.push(item); | ||
} else { | ||
break; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
if (!submissions?.length) { | ||
return; | ||
} | ||
|
||
this._setLastTs(Date.parse(submissions[0].created_at)); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
submissions.forEach((submission) => { | ||
const meta = this.generateMeta(submission); | ||
this.$emit(submission, meta); | ||
}); | ||
}, | ||
}, | ||
async run() { | ||
await this.processEvent(); | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.