Skip to content

Commit 87b6a53

Browse files
committed
new components
1 parent d72e32f commit 87b6a53

File tree

11 files changed

+590
-19
lines changed

11 files changed

+590
-19
lines changed

components/smartsuite/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import smartsuite from "../../smartsuite.app.mjs";
2+
3+
export default {
4+
key: "smartsuite-create-record",
5+
name: "Create Record",
6+
description: "Creates a new record. [See the documentation](https://developers.smartsuite.com/docs/solution-data/records/create-record)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
smartsuite,
11+
tableId: {
12+
propDefinition: [
13+
smartsuite,
14+
"tableId",
15+
],
16+
reloadProps: true,
17+
},
18+
},
19+
async additionalProps() {
20+
const props = {};
21+
if (!this.tableId) {
22+
return props;
23+
}
24+
const { structure: fields } = await this.smartsuite.listFields({
25+
tableId: this.tableId,
26+
});
27+
for (const field of fields) {
28+
if (!field.params.is_auto_generated
29+
&& !field.params.system
30+
&& field.field_type !== "linkedrecordfield"
31+
&& field.field_type !== "filefield"
32+
&& field.field_type !== "userfield"
33+
) {
34+
props[field.slug] = {
35+
type: "string",
36+
label: field.label,
37+
optional: !field.params.required,
38+
options: field.params.choices
39+
? field.params.choices.map(({
40+
value, label,
41+
}) => ({
42+
value,
43+
label,
44+
}))
45+
: undefined,
46+
};
47+
}
48+
}
49+
return props;
50+
},
51+
async run({ $ }) {
52+
const {
53+
smartsuite,
54+
tableId,
55+
...data
56+
} = this;
57+
58+
const response = await smartsuite.createRecord({
59+
$,
60+
tableId,
61+
data,
62+
});
63+
$.export("$summary", `Successfully created record with ID: ${response.id}`);
64+
return response;
65+
},
66+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import smartsuite from "../../smartsuite.app.mjs";
2+
3+
export default {
4+
key: "smartsuite-find-records",
5+
name: "Find Records",
6+
description: "Search for records based on matching field(s). [See the documentation](https://developers.smartsuite.com/docs/solution-data/records/list-records)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
smartsuite,
11+
tableId: {
12+
propDefinition: [
13+
smartsuite,
14+
"tableId",
15+
],
16+
},
17+
fieldIds: {
18+
propDefinition: [
19+
smartsuite,
20+
"fieldIds",
21+
(c) => ({
22+
tableId: c.tableId,
23+
}),
24+
],
25+
reloadProps: true,
26+
},
27+
},
28+
async additionalProps() {
29+
const props = {};
30+
if (!this.tableId || !this.fieldIds?.length) {
31+
return props;
32+
}
33+
const { structure: fields } = await this.smartsuite.listFields({
34+
tableId: this.tableId,
35+
});
36+
for (const fieldId of this.fieldIds) {
37+
const field = fields.find(({ slug }) => slug === fieldId);
38+
props[fieldId] = {
39+
type: "string",
40+
label: field.label,
41+
};
42+
}
43+
return props;
44+
},
45+
async run({ $ }) {
46+
const fields = this.fieldIds?.length
47+
? this.fieldIds.map((field) => ({
48+
comparison: "is",
49+
field,
50+
value: this[field],
51+
}))
52+
: undefined;
53+
const { items } = await this.smartsuite.listRecords({
54+
$,
55+
tableId: this.tableId,
56+
data: {
57+
filter: {
58+
operator: "and",
59+
fields,
60+
},
61+
},
62+
});
63+
if (items?.length) {
64+
$.export("$summary", `Successfully found ${items.length} record${items.length === 1
65+
? ""
66+
: "s"}`);
67+
}
68+
return items;
69+
},
70+
};

components/smartsuite/app/smartsuite.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/smartsuite/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/smartsuite",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream SmartSuite Components",
5-
"main": "dist/app/smartsuite.app.mjs",
5+
"main": "smartsuite.app.mjs",
66
"keywords": [
77
"pipedream",
88
"smartsuite"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/smartsuite",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1517
}
1618
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { axios } from "@pipedream/platform";
2+
const DEFAULT_LIMIT = 50;
3+
4+
export default {
5+
type: "app",
6+
app: "smartsuite",
7+
propDefinitions: {
8+
tableId: {
9+
type: "string",
10+
label: "Table ID",
11+
description: "The identifier of a table",
12+
async options({ page }) {
13+
const { results: tables } = await this.listTables({
14+
params: {
15+
limit: DEFAULT_LIMIT,
16+
offset: page * DEFAULT_LIMIT,
17+
},
18+
});
19+
return tables?.map(({
20+
id: value, name: label,
21+
}) => ({
22+
value,
23+
label,
24+
})) || [];
25+
},
26+
},
27+
fieldIds: {
28+
type: "string[]",
29+
label: "Field IDs",
30+
description: "The field ID(s) (\"slug\") to search by",
31+
optional: true,
32+
async options({ tableId }) {
33+
const { structure: fields } = await this.listFields({
34+
tableId,
35+
});
36+
return fields?.map(({
37+
slug: value, label,
38+
}) => ({
39+
value,
40+
label,
41+
})) || [];
42+
},
43+
},
44+
solutionId: {
45+
type: "string",
46+
label: "Solution ID",
47+
description: "The identifier of a solution",
48+
async options() {
49+
const solutions = await this.listSolutions();
50+
return solutions?.map(({
51+
id: value, name: label,
52+
}) => ({
53+
value,
54+
label,
55+
})) || [];
56+
},
57+
},
58+
},
59+
methods: {
60+
_baseUrl() {
61+
return "https://app.smartsuite.com/api/v1";
62+
},
63+
_baseWebhookUrl() {
64+
return "https://webhooks.smartsuite.com/smartsuite.webhooks.engine.Webhooks";
65+
},
66+
_headers() {
67+
return {
68+
"Authorization": `Token ${this.$auth.api_token}`,
69+
"ACCOUNT-ID": `${this.$auth.account_id}`,
70+
"Content-Type": "application/json",
71+
};
72+
},
73+
_makeRequest({
74+
$ = this,
75+
url,
76+
path,
77+
...opts
78+
}) {
79+
return axios($, {
80+
url: url || `${this._baseUrl()}${path}`,
81+
headers: this._headers(),
82+
...opts,
83+
});
84+
},
85+
createWebhook(opts = {}) {
86+
return this._makeRequest({
87+
method: "POST",
88+
url: `${this._baseWebhookUrl()}/CreateWebhook`,
89+
...opts,
90+
});
91+
},
92+
deleteWebhook(opts = {}) {
93+
return this._makeRequest({
94+
method: "POST",
95+
url: `${this._baseWebhookUrl()}/DeleteWebhook`,
96+
...opts,
97+
});
98+
},
99+
listWebhookEvents(opts = {}) {
100+
return this._makeRequest({
101+
method: "POST",
102+
url: `${this._baseWebhookUrl()}/ListEvents`,
103+
...opts,
104+
});
105+
},
106+
listTables(opts = {}) {
107+
return this._makeRequest({
108+
path: "/applications",
109+
...opts,
110+
});
111+
},
112+
listSolutions(opts = {}) {
113+
return this._makeRequest({
114+
path: "/solutions",
115+
...opts,
116+
});
117+
},
118+
listFields({
119+
tableId, ...opts
120+
}) {
121+
return this._makeRequest({
122+
path: `/applications/${tableId}`,
123+
...opts,
124+
});
125+
},
126+
listRecords({
127+
tableId, ...opts
128+
}) {
129+
return this._makeRequest({
130+
method: "POST",
131+
path: `/applications/${tableId}/records/list/`,
132+
...opts,
133+
});
134+
},
135+
createRecord({
136+
tableId, ...opts
137+
}) {
138+
return this._makeRequest({
139+
method: "POST",
140+
path: `/applications/${tableId}/records/`,
141+
...opts,
142+
});
143+
},
144+
},
145+
};

0 commit comments

Comments
 (0)