Skip to content
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

New Components - smartsuite #14273

Merged
merged 2 commits into from
Oct 11, 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/smartsuite/.gitignore

This file was deleted.

66 changes: 66 additions & 0 deletions components/smartsuite/actions/create-record/create-record.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import smartsuite from "../../smartsuite.app.mjs";

export default {
key: "smartsuite-create-record",
name: "Create Record",
description: "Creates a new record. [See the documentation](https://developers.smartsuite.com/docs/solution-data/records/create-record)",
version: "0.0.1",
type: "action",
props: {
smartsuite,
tableId: {
propDefinition: [
smartsuite,
"tableId",
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (!this.tableId) {
return props;
}
const { structure: fields } = await this.smartsuite.listFields({
tableId: this.tableId,
});
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
for (const field of fields) {
if (!field.params.is_auto_generated
&& !field.params.system
&& field.field_type !== "linkedrecordfield"
&& field.field_type !== "filefield"
&& field.field_type !== "userfield"
) {
props[field.slug] = {
type: "string",
label: field.label,
optional: !field.params.required,
options: field.params.choices
? field.params.choices.map(({
value, label,
}) => ({
value,
label,
}))
: undefined,
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
};
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
}
}
return props;
},
async run({ $ }) {
const {
smartsuite,
tableId,
...data
} = this;
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved

const response = await smartsuite.createRecord({
$,
tableId,
data,
});
$.export("$summary", `Successfully created record with ID: ${response.id}`);
return response;
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
};
70 changes: 70 additions & 0 deletions components/smartsuite/actions/find-records/find-records.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import smartsuite from "../../smartsuite.app.mjs";

export default {
key: "smartsuite-find-records",
name: "Find Records",
description: "Search for records based on matching field(s). [See the documentation](https://developers.smartsuite.com/docs/solution-data/records/list-records)",
version: "0.0.1",
type: "action",
props: {
smartsuite,
tableId: {
propDefinition: [
smartsuite,
"tableId",
],
},
fieldIds: {
propDefinition: [
smartsuite,
"fieldIds",
(c) => ({
tableId: c.tableId,
}),
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (!this.tableId || !this.fieldIds?.length) {
return props;
}
const { structure: fields } = await this.smartsuite.listFields({
tableId: this.tableId,
});
for (const fieldId of this.fieldIds) {
const field = fields.find(({ slug }) => slug === fieldId);
props[fieldId] = {
type: "string",
label: field.label,
};
}
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
return props;
},
async run({ $ }) {
const fields = this.fieldIds?.length
? this.fieldIds.map((field) => ({
comparison: "is",
field,
value: this[field],
}))
: undefined;
const { items } = await this.smartsuite.listRecords({
$,
tableId: this.tableId,
data: {
filter: {
operator: "and",
fields,
},
},
});
if (items?.length) {
$.export("$summary", `Successfully found ${items.length} record${items.length === 1
? ""
: "s"}`);
}
return items;
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
};
13 changes: 0 additions & 13 deletions components/smartsuite/app/smartsuite.app.ts

This file was deleted.

8 changes: 5 additions & 3 deletions components/smartsuite/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/smartsuite",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream SmartSuite Components",
"main": "dist/app/smartsuite.app.mjs",
"main": "smartsuite.app.mjs",
"keywords": [
"pipedream",
"smartsuite"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/smartsuite",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
145 changes: 145 additions & 0 deletions components/smartsuite/smartsuite.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { axios } from "@pipedream/platform";
const DEFAULT_LIMIT = 50;

export default {
type: "app",
app: "smartsuite",
propDefinitions: {
tableId: {
type: "string",
label: "Table ID",
description: "The identifier of a table",
async options({ page }) {
const { results: tables } = await this.listTables({
params: {
limit: DEFAULT_LIMIT,
offset: page * DEFAULT_LIMIT,
},
});
return tables?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
fieldIds: {
type: "string[]",
label: "Field IDs",
description: "The field ID(s) (\"slug\") to search by",
optional: true,
async options({ tableId }) {
const { structure: fields } = await this.listFields({
tableId,
});
return fields?.map(({
slug: value, label,
}) => ({
value,
label,
})) || [];
},
},
solutionId: {
type: "string",
label: "Solution ID",
description: "The identifier of a solution",
async options() {
const solutions = await this.listSolutions();
return solutions?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
},
methods: {
_baseUrl() {
return "https://app.smartsuite.com/api/v1";
},
_baseWebhookUrl() {
return "https://webhooks.smartsuite.com/smartsuite.webhooks.engine.Webhooks";
},
_headers() {
return {
"Authorization": `Token ${this.$auth.api_token}`,
"ACCOUNT-ID": `${this.$auth.account_id}`,
"Content-Type": "application/json",
};
},
_makeRequest({
$ = this,
url,
path,
...opts
}) {
return axios($, {
url: url || `${this._baseUrl()}${path}`,
headers: this._headers(),
...opts,
});
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
createWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
url: `${this._baseWebhookUrl()}/CreateWebhook`,
...opts,
});
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
deleteWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
url: `${this._baseWebhookUrl()}/DeleteWebhook`,
...opts,
});
},
listWebhookEvents(opts = {}) {
return this._makeRequest({
method: "POST",
url: `${this._baseWebhookUrl()}/ListEvents`,
...opts,
});
},
listTables(opts = {}) {
return this._makeRequest({
path: "/applications",
...opts,
});
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
listSolutions(opts = {}) {
return this._makeRequest({
path: "/solutions",
...opts,
});
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
listFields({
tableId, ...opts
}) {
return this._makeRequest({
path: `/applications/${tableId}`,
...opts,
});
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
listRecords({
tableId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/applications/${tableId}/records/list/`,
...opts,
});
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
createRecord({
tableId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/applications/${tableId}/records/`,
...opts,
});
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
},
};
Loading
Loading