Skip to content

Commit 0a09fa5

Browse files
authored
Enhance Aidaform component with new sources for monitoring form creation and responses. Added New Form Created and New Form Response sources, enabling event emission for new forms and responses. Updated aidaform.app.mjs with new prop definitions and methods for form management. Bump version to 0.7.0 in package.json. (#19055)
1 parent d0fc909 commit 0a09fa5

File tree

4 files changed

+214
-5
lines changed

4 files changed

+214
-5
lines changed
Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,84 @@
1+
import { axios } from "@pipedream/platform";
2+
const LIMIT = 100;
3+
14
export default {
25
type: "app",
36
app: "aidaform",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
formId: {
9+
type: "string",
10+
label: "Form ID",
11+
description: "The ID of the form to monitor for new responses",
12+
async options() {
13+
const { items } = await this.listForms();
14+
return items.map(({
15+
id, data: { name },
16+
}) => ({
17+
label: name,
18+
value: id,
19+
}));
20+
},
21+
},
22+
},
523
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
24+
_apiUrl() {
25+
return "https://api.aidaform.com/v1";
26+
},
27+
_getHeaders() {
28+
return {
29+
"Authorization": `${this.$auth.api_key}`,
30+
};
31+
},
32+
_makeRequest({
33+
$ = this, path, ...opts
34+
}) {
35+
return axios($, {
36+
url: `${this._apiUrl()}/${path}`,
37+
headers: this._getHeaders(),
38+
...opts,
39+
});
40+
},
41+
listForms(args = {}) {
42+
return this._makeRequest({
43+
path: "forms",
44+
...args,
45+
});
46+
},
47+
listResponses({
48+
formId, ...args
49+
}) {
50+
return this._makeRequest({
51+
path: `forms/${formId}/responses`,
52+
...args,
53+
});
54+
},
55+
async *paginate({
56+
fn, params = {}, maxResults = null, ...opts
57+
}) {
58+
let hasMore = null;
59+
let count = 0;
60+
61+
do {
62+
params.limit = LIMIT;
63+
params.marker = hasMore;
64+
const {
65+
items, marker: nextMarker,
66+
} = await fn({
67+
params,
68+
...opts,
69+
});
70+
71+
for (const d of items) {
72+
yield d;
73+
74+
if (maxResults && ++count === maxResults) {
75+
return count;
76+
}
77+
}
78+
79+
hasMore = nextMarker;
80+
81+
} while (hasMore);
982
},
1083
},
1184
};

components/aidaform/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/aidaform",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Pipedream aidaform Components",
55
"main": "aidaform.app.mjs",
66
"keywords": [
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import aidaform from "../../aidaform.app.mjs";
3+
4+
export default {
5+
key: "aidaform-new-form-response",
6+
name: "New Form Response",
7+
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)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
aidaform,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
formId: {
21+
propDefinition: [
22+
aidaform,
23+
"formId",
24+
],
25+
},
26+
},
27+
methods: {
28+
_getLastDate() {
29+
return this.db.get("lastDate");
30+
},
31+
_setLastDate(lastDate) {
32+
this.db.set("lastDate", lastDate);
33+
},
34+
async emitEvent(maxResults = false) {
35+
const lastDate = this._getLastDate() || 0;
36+
const response = this.aidaform.paginate({
37+
fn: this.aidaform.listResponses,
38+
formId: this.formId,
39+
params: {
40+
from: lastDate,
41+
},
42+
});
43+
44+
let responseArray = [];
45+
for await (const item of response) {
46+
responseArray.push(item);
47+
}
48+
49+
responseArray = responseArray
50+
.sort((a, b) => b.created_at - a.created_at);
51+
52+
if (responseArray.length) {
53+
if (maxResults && (responseArray.length > maxResults)) {
54+
responseArray.length = maxResults;
55+
}
56+
this._setLastDate(Date.parse(responseArray[0].created_at));
57+
}
58+
59+
for (const item of responseArray.reverse()) {
60+
this.$emit(item, {
61+
id: item.id,
62+
summary: `New form response with ID: ${item.id}`,
63+
ts: Date.parse(item.created_at),
64+
});
65+
}
66+
},
67+
},
68+
hooks: {
69+
async deploy() {
70+
await this.emitEvent(25);
71+
},
72+
},
73+
async run() {
74+
await this.emitEvent();
75+
},
76+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import aidaform from "../../aidaform.app.mjs";
3+
4+
export default {
5+
key: "aidaform-new-form",
6+
name: "New Form Created",
7+
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)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
aidaform,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
},
21+
methods: {
22+
_getLastDate() {
23+
return this.db.get("lastDate");
24+
},
25+
_setLastDate(lastDate) {
26+
this.db.set("lastDate", lastDate);
27+
},
28+
async emitEvent(maxResults = false) {
29+
const lastDate = this._getLastDate() || 0;
30+
let { items: responseArray } = await this.aidaform.listForms();
31+
32+
responseArray = responseArray
33+
.filter((item) => item.created_at > lastDate)
34+
.sort((a, b) => b.created_at - a.created_at);
35+
36+
if (responseArray.length) {
37+
if (maxResults && (responseArray.length > maxResults)) {
38+
responseArray.length = maxResults;
39+
}
40+
this._setLastDate(Date.parse(responseArray[0].created_at));
41+
}
42+
43+
for (const item of responseArray.reverse()) {
44+
this.$emit(item, {
45+
id: item.id,
46+
summary: `New form created: ${item.data.name}`,
47+
ts: Date.parse(item.created_at),
48+
});
49+
}
50+
},
51+
},
52+
hooks: {
53+
async deploy() {
54+
await this.emitEvent(25);
55+
},
56+
},
57+
async run() {
58+
await this.emitEvent();
59+
},
60+
};

0 commit comments

Comments
 (0)