Skip to content

Commit cd772d0

Browse files
authored
Tettra new components (#17264)
* Tettra new components * Adding async options to tettra components * file structure adjustment * pnpm
1 parent 3b99517 commit cd772d0

File tree

7 files changed

+208
-20
lines changed

7 files changed

+208
-20
lines changed

components/tettra/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import tettra from "../../tettra.app.mjs";
2+
3+
export default {
4+
key: "tettra-create-page",
5+
name: "Create Page",
6+
description: "Creates a new page in Tettra. [See the documentation](https://support.tettra.co/api-overview/api-endpoint-create-page)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
tettra,
11+
title: {
12+
type: "string",
13+
label: "Title",
14+
description: "The title of the page",
15+
},
16+
body: {
17+
type: "string",
18+
label: "Body",
19+
description: "The body of the page formatted as HTML",
20+
},
21+
categoryId: {
22+
propDefinition: [
23+
tettra,
24+
"categoryId",
25+
],
26+
},
27+
subcategoryId: {
28+
propDefinition: [
29+
tettra,
30+
"subcategoryId",
31+
({ categoryId }) => ({
32+
categoryId,
33+
}),
34+
],
35+
},
36+
},
37+
async run({ $ }) {
38+
const response = await this.tettra.createPage({
39+
$,
40+
data: {
41+
title: this.title,
42+
body: this.body,
43+
category_id: this.categoryId,
44+
subcategory_id: this.subcategoryId,
45+
},
46+
});
47+
48+
$.export("$summary", `Successfully created page "${this.title}"`);
49+
return response;
50+
},
51+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import tettra from "../../tettra.app.mjs";
2+
3+
export default {
4+
key: "tettra-suggest-page",
5+
name: "Suggest Page",
6+
description: "Creates a new page suggestion in Tettra. [See the documentation](https://support.tettra.co/api-overview/api-endpoint-suggest-a-new-page)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
tettra,
11+
title: {
12+
type: "string",
13+
label: "Title",
14+
description: "Title of the page suggestion",
15+
},
16+
description: {
17+
type: "string",
18+
label: "Description",
19+
description: "More context about the suggested page",
20+
optional: true,
21+
},
22+
category: {
23+
propDefinition: [
24+
tettra,
25+
"categoryId",
26+
],
27+
},
28+
assignableId: {
29+
propDefinition: [
30+
tettra,
31+
"userId",
32+
],
33+
label: "Assignable ID",
34+
description: "Select a user to assign the suggestion, or provide a user ID",
35+
},
36+
},
37+
async run({ $ }) {
38+
const response = await this.tettra.suggestPage({
39+
$,
40+
data: {
41+
title: this.title,
42+
description: this.description,
43+
category: this.category,
44+
assignable_id: this.assignableId,
45+
},
46+
});
47+
48+
$.export("$summary", `Successfully created page suggestion "${this.title}"`);
49+
return response;
50+
},
51+
};

components/tettra/app/tettra.app.ts

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

components/tettra/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/tettra",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Tettra Components",
5-
"main": "dist/app/tettra.app.mjs",
5+
"main": "tettra.app.mjs",
66
"keywords": [
77
"pipedream",
88
"tettra"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/tettra",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1517
}
1618
}

components/tettra/tettra.app.mjs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "tettra",
6+
propDefinitions: {
7+
categoryId: {
8+
type: "string",
9+
label: "Category ID",
10+
description: "Select a category or provide a category ID",
11+
optional: true,
12+
async options() {
13+
const { categories } = await this.getCategories();
14+
return categories.map((category) => ({
15+
label: category.name,
16+
value: category.id,
17+
}));
18+
},
19+
},
20+
subcategoryId: {
21+
type: "string",
22+
label: "Subcategory ID",
23+
description: "Select a subcategory or provide a subcategory ID",
24+
optional: true,
25+
async options({ categoryId }) {
26+
const { categoryItems } = await this.getCategory(categoryId);
27+
return categoryItems.filter((item) => item.type === "Subcategory").map((item) => ({
28+
label: item.title,
29+
value: item.id,
30+
}));
31+
},
32+
},
33+
userId: {
34+
type: "string",
35+
label: "User ID",
36+
description: "Select a user or provide a user ID",
37+
optional: true,
38+
async options() {
39+
const { users } = await this.getUsers();
40+
return users.map((user) => ({
41+
label: user.display_name ?? user.email,
42+
value: user.id,
43+
}));
44+
},
45+
},
46+
},
47+
methods: {
48+
async _makeRequest({
49+
$ = this,
50+
data,
51+
...args
52+
}) {
53+
const response = await axios($, {
54+
baseURL: `https://app.tettra.co/api/teams/${this.$auth.team_id}`,
55+
headers: {
56+
"Content-Type": "application/json",
57+
},
58+
data: {
59+
...data,
60+
api_key: this.$auth.api_key,
61+
},
62+
...args,
63+
});
64+
return response;
65+
},
66+
async createPage(args) {
67+
return this._makeRequest({
68+
url: "/pages",
69+
method: "POST",
70+
...args,
71+
});
72+
},
73+
async suggestPage(args) {
74+
return this._makeRequest({
75+
url: "/suggestions",
76+
method: "POST",
77+
...args,
78+
});
79+
},
80+
async getCategories() {
81+
return this._makeRequest({
82+
url: "/categories",
83+
});
84+
},
85+
async getCategory(categoryId) {
86+
return this._makeRequest({
87+
url: `/categories/${categoryId}`,
88+
});
89+
},
90+
async getUsers() {
91+
return this._makeRequest({
92+
url: "/users",
93+
});
94+
},
95+
},
96+
};

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)