Skip to content

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 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions components/paperform/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions components/paperform/app/paperform.app.ts

This file was deleted.

10 changes: 5 additions & 5 deletions components/paperform/package.json
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"
}
}
88 changes: 88 additions & 0 deletions components/paperform/paperform.app.mjs
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;
if (max && ++count >= max) {
return;
}
}
hasMore = more;
args.params.skip += args.params.limit;
} while (hasMore);
},
},
};
83 changes: 83 additions & 0 deletions components/paperform/sources/new-submission/new-submission.mjs
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,
});

const submissions = [];
for await (const item of items) {
const ts = Date.parse(item.created_at);
if (ts >= lastTs) {
submissions.push(item);
} else {
break;
}
}

if (!submissions?.length) {
return;
}

this._setLastTs(Date.parse(submissions[0].created_at));

submissions.forEach((submission) => {
const meta = this.generateMeta(submission);
this.$emit(submission, meta);
});
},
},
async run() {
await this.processEvent();
},
};
107 changes: 55 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading