Skip to content
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
81 changes: 77 additions & 4 deletions components/aidaform/aidaform.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,84 @@
import { axios } from "@pipedream/platform";
const LIMIT = 100;

export default {
type: "app",
app: "aidaform",
propDefinitions: {},
propDefinitions: {
formId: {
type: "string",
label: "Form ID",
description: "The ID of the form to monitor for new responses",
async options() {
const { items } = await this.listForms();
return items.map(({
id, data: { name },
}) => ({
label: name,
value: id,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_apiUrl() {
return "https://api.aidaform.com/v1";
},
_getHeaders() {
return {
"Authorization": `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._apiUrl()}/${path}`,
headers: this._getHeaders(),
...opts,
});
},
listForms(args = {}) {
return this._makeRequest({
path: "forms",
...args,
});
},
listResponses({
formId, ...args
}) {
return this._makeRequest({
path: `forms/${formId}/responses`,
...args,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = null;
let count = 0;

do {
params.limit = LIMIT;
params.marker = hasMore;
const {
items, marker: nextMarker,
} = await fn({
params,
...opts,
});

for (const d of items) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = nextMarker;

} while (hasMore);
},
},
};
2 changes: 1 addition & 1 deletion components/aidaform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/aidaform",
"version": "0.6.0",
"version": "0.7.0",
"description": "Pipedream aidaform Components",
"main": "aidaform.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import aidaform from "../../aidaform.app.mjs";

export default {
key: "aidaform-new-form-response",
name: "New Form Response",
description: "Emit new event when a new form is responded to. [See the documentation](https://app.swaggerhub.com/apis/aidaform/AidaForm/1.1.0#/default/RetrieveResponsesList)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
aidaform,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
formId: {
propDefinition: [
aidaform,
"formId",
],
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate");
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate() || 0;
const response = this.aidaform.paginate({
fn: this.aidaform.listResponses,
formId: this.formId,
params: {
from: lastDate,
},
});

let responseArray = [];
for await (const item of response) {
responseArray.push(item);
}

responseArray = responseArray
.sort((a, b) => b.created_at - a.created_at);

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastDate(Date.parse(responseArray[0].created_at));
}

for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item.id,
summary: `New form response with ID: ${item.id}`,
ts: Date.parse(item.created_at),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
60 changes: 60 additions & 0 deletions components/aidaform/sources/new-form/new-form.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import aidaform from "../../aidaform.app.mjs";

export default {
key: "aidaform-new-form",
name: "New Form Created",
description: "Emit new event when a new form is created. [See the documentation](https://app.swaggerhub.com/apis/aidaform/AidaForm/1.1.0#/default/RetrieveFormsList)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
aidaform,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate");
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate() || 0;
let { items: responseArray } = await this.aidaform.listForms();

responseArray = responseArray
.filter((item) => item.created_at > lastDate)
.sort((a, b) => b.created_at - a.created_at);

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastDate(Date.parse(responseArray[0].created_at));
}

for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item.id,
summary: `New form created: ${item.data.name}`,
ts: Date.parse(item.created_at),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
Loading