Skip to content

Commit 2cb8220

Browse files
committed
Added actions
1 parent 5f75543 commit 2cb8220

File tree

9 files changed

+288
-32
lines changed

9 files changed

+288
-32
lines changed

components/favro/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import app from "../../favro.app.mjs";
2+
3+
export default {
4+
key: "favro-create-organization",
5+
name: "Create Organization",
6+
description: "Creates a new organization. [See the documentation](https://favro.com/developer/#create-an-organization)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name",
15+
],
16+
},
17+
organizationId: {
18+
propDefinition: [
19+
app,
20+
"organizationId",
21+
],
22+
description: "Organization of the user that will be associated to the new organization",
23+
24+
},
25+
userId: {
26+
propDefinition: [
27+
app,
28+
"userId",
29+
(c) => ({
30+
organizationId: c.organizationId,
31+
}),
32+
],
33+
},
34+
role: {
35+
propDefinition: [
36+
app,
37+
"role",
38+
],
39+
},
40+
},
41+
42+
async run({ $ }) {
43+
const response = await this.app.createOrganization({
44+
$,
45+
data: {
46+
name: this.name,
47+
shareToUsers: [
48+
{
49+
userId: this.userId,
50+
role: this.role,
51+
},
52+
],
53+
},
54+
});
55+
56+
$.export("$summary", `Successfully created organization named ${this.name}'`);
57+
58+
return response;
59+
},
60+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import app from "../../favro.app.mjs";
2+
3+
export default {
4+
key: "favro-list-users",
5+
name: "List Users",
6+
description: "List all users in the organization. [See the documentation](https://docs.x.ai/api/endpoints#get-model)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
organizationId: {
12+
propDefinition: [
13+
app,
14+
"organizationId",
15+
],
16+
},
17+
},
18+
19+
async run({ $ }) {
20+
const response = await this.app.listUsers({
21+
$,
22+
organizationId: this.organizationId,
23+
});
24+
25+
$.export("$summary", `Successfully retrieved ${response.entities.length} user(s)`);
26+
27+
return response;
28+
},
29+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import app from "../../favro.app.mjs";
2+
3+
export default {
4+
key: "favro-post-upsate-organization",
5+
name: "Update Organization",
6+
description: "Updates an existing organization. [See the documentation](https://favro.com/developer/#update-an-organization)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
organizationId: {
12+
propDefinition: [
13+
app,
14+
"organizationId",
15+
],
16+
},
17+
name: {
18+
propDefinition: [
19+
app,
20+
"name",
21+
],
22+
},
23+
userId: {
24+
propDefinition: [
25+
app,
26+
"userId",
27+
(c) => ({
28+
organizationId: c.organizationId,
29+
}),
30+
],
31+
},
32+
role: {
33+
propDefinition: [
34+
app,
35+
"role",
36+
],
37+
},
38+
},
39+
40+
async run({ $ }) {
41+
const response = await this.app.updateOrganization({
42+
$,
43+
headers: {
44+
organizationId: this.organizationId,
45+
},
46+
data: {
47+
name: this.name,
48+
shareToUsers: [
49+
{
50+
userId: this.userId,
51+
role: this.role,
52+
},
53+
],
54+
},
55+
});
56+
57+
$.export("$summary", `Successfully updated organization with ID '${this.organizationId}'`);
58+
59+
return response;
60+
},
61+
};

components/favro/app/favro.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
USER_ROLES: [
3+
"administrator",
4+
"fullMember",
5+
"externalMember",
6+
"guest",
7+
"disabled",
8+
],
9+
};

components/favro/favro.app.mjs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/contants.mjs";
3+
4+
export default {
5+
type: "app",
6+
app: "favro",
7+
propDefinitions: {
8+
organizationId: {
9+
type: "string",
10+
label: "Organization ID",
11+
description: "ID of the organization",
12+
async options() {
13+
const response = await this.listOrganizations();
14+
const usersIds = response.entities;
15+
return usersIds.map(({
16+
organizationId, name,
17+
}) => ({
18+
value: organizationId,
19+
label: name,
20+
}));
21+
},
22+
},
23+
userId: {
24+
type: "string",
25+
label: "User ID",
26+
description: "ID of the user",
27+
async options({ organizationId }) {
28+
const response = await this.listUsers({
29+
organizationId,
30+
});
31+
const usersIds = response.entities;
32+
return usersIds.map(({
33+
userId, name,
34+
}) => ({
35+
value: userId,
36+
label: name,
37+
}));
38+
},
39+
},
40+
name: {
41+
type: "string",
42+
label: "Name",
43+
description: "Name of the organization",
44+
},
45+
role: {
46+
type: "string",
47+
label: "Role",
48+
description: "Role of the user",
49+
options: constants.USER_ROLES,
50+
},
51+
},
52+
methods: {
53+
_baseUrl() {
54+
return "https://favro.com/api";
55+
},
56+
async _makeRequest(opts = {}) {
57+
const {
58+
$ = this,
59+
path,
60+
...otherOpts
61+
} = opts;
62+
return axios($, {
63+
...otherOpts,
64+
url: this._baseUrl() + path,
65+
auth: {
66+
username: `${this.$auth.username}`,
67+
password: `${this.$auth.api_token}`,
68+
},
69+
});
70+
},
71+
async createOrganization(args = {}) {
72+
return this._makeRequest({
73+
path: "/v1/organizations",
74+
method: "post",
75+
...args,
76+
});
77+
},
78+
async updateOrganization({
79+
organizationId, ...args
80+
}) {
81+
return this._makeRequest({
82+
path: `/v1/organizations/${organizationId}`,
83+
method: "put",
84+
...args,
85+
});
86+
},
87+
async listOrganizations(args = {}) {
88+
return this._makeRequest({
89+
path: "/v1/organizations",
90+
...args,
91+
});
92+
},
93+
async listUsers({
94+
organizationId, ...args
95+
}) {
96+
return this._makeRequest({
97+
path: "/v1/users",
98+
headers: {
99+
organizationId,
100+
},
101+
...args,
102+
});
103+
},
104+
},
105+
};

components/favro/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
22
"name": "@pipedream/favro",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Favro Components",
5-
"main": "dist/app/favro.app.mjs",
5+
"main": "favro.app.mjs",
66
"keywords": [
77
"pipedream",
88
"favro"
99
],
10-
"files": ["dist"],
10+
"files": [
11+
"dist"
12+
],
1113
"homepage": "https://pipedream.com/apps/favro",
1214
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1315
"publishConfig": {
1416
"access": "public"
17+
},
18+
"dependencies": {
19+
"@pipedream/platform": "^3.0.3"
1520
}
1621
}

pnpm-lock.yaml

Lines changed: 16 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)