-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathadalo.app.mjs
77 lines (74 loc) · 1.73 KB
/
adalo.app.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { axios } from "@pipedream/platform";
export default {
type: "app",
app: "adalo",
methods: {
_collectionId() {
return this.$auth.collection_id;
},
_apiKey() {
return this.$auth.api_key;
},
_appId() {
return this.$auth.appId;
},
_apiUrl() {
return `https://api.adalo.com/v0/apps/${this._appId()}`;
},
async _makeRequest({
$ = this, path, ...args
} = {}) {
return axios($, {
url: `${this._apiUrl()}${path}`,
headers: {
"Authorization": `Bearer ${this._apiKey()}`,
"Content-Type": "application/json",
},
...args,
});
},
async paginateResources({
requestFn, requestArgs, resourceName, mapper,
}) {
const limit = requestArgs.params?.limit ?? 100;
const offset = (requestArgs.params?.offset ?? 0) + limit;
const { [resourceName]: resources } =
await requestFn({
...requestArgs,
params: {
limit,
...requestArgs.params,
},
});
return {
options: resources.map(mapper),
context: {
offset,
total: resources.length,
},
};
},
getRecords(args = {}) {
return this._makeRequest({
path: `/collections/${this._collectionId()}`,
...args,
});
},
createRecord(args = {}) {
return this._makeRequest({
path: `/collections/${this._collectionId()}`,
method: "post",
...args,
});
},
updateRecord({
recordId, ...args
} = {}) {
return this._makeRequest({
path: `/collections/${this._collectionId()}/${recordId}`,
method: "put",
...args,
});
},
},
};