Skip to content

Commit 7f240b2

Browse files
New Components - peerdom (#16405)
* peerdom init * [Components] peerdom #16400 Sources - New Role - New Member Actions - Create Role - Assign Member To Role - Update Role * pnpm update * pnpm update * Update components/peerdom/peerdom.app.mjs Co-authored-by: Guilherme Falcão <[email protected]> * Update components/peerdom/peerdom.app.mjs Co-authored-by: Guilherme Falcão <[email protected]> * Update components/peerdom/peerdom.app.mjs Co-authored-by: Guilherme Falcão <[email protected]> * Update components/peerdom/peerdom.app.mjs Co-authored-by: Guilherme Falcão <[email protected]> * some adjusts --------- Co-authored-by: Guilherme Falcão <[email protected]>
1 parent 2d2d4ab commit 7f240b2

File tree

13 files changed

+691
-7
lines changed

13 files changed

+691
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import peerdom from "../../peerdom.app.mjs";
2+
3+
export default {
4+
key: "peerdom-assign-member-to-role",
5+
name: "Assign Member to Role",
6+
description: "Assigns a member to a role within a circle using the Peerdom API. [See the documentation](https://api.peerdom.org/v1/docs)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
peerdom,
11+
roleId: {
12+
propDefinition: [
13+
peerdom,
14+
"roleId",
15+
],
16+
},
17+
memberId: {
18+
propDefinition: [
19+
peerdom,
20+
"memberId",
21+
],
22+
},
23+
percentage: {
24+
type: "integer",
25+
label: "Percentage",
26+
description: "The percentage of the role assigned to the member",
27+
optional: true,
28+
min: 0,
29+
max: 100,
30+
},
31+
focus: {
32+
type: "string",
33+
label: "Focus",
34+
description: "The focus of the role assigned to the member",
35+
optional: true,
36+
},
37+
electedUntil: {
38+
type: "string",
39+
label: "Elected Until",
40+
description: "The date until which the member is elected to the role (YYYY-MM-DD)",
41+
optional: true,
42+
},
43+
},
44+
async run({ $ }) {
45+
const response = await this.peerdom.assignMemberToRole({
46+
$,
47+
roleId: this.roleId,
48+
data: {
49+
peerId: this.memberId,
50+
percentage: this.percentage,
51+
focus: this.focus,
52+
electedUntil: this.electedUntil,
53+
},
54+
});
55+
56+
$.export("$summary", `Successfully assigned member with ID ${this.memberId} to role with ID ${this.roleId}`);
57+
return response;
58+
},
59+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import peerdom from "../../peerdom.app.mjs";
4+
5+
export default {
6+
key: "peerdom-create-role",
7+
name: "Create Role",
8+
description: "Create a new role within a specified circle. [See the documentation](https://api.peerdom.org/v1/docs)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
peerdom,
13+
name: {
14+
propDefinition: [
15+
peerdom,
16+
"name",
17+
],
18+
},
19+
mapId: {
20+
propDefinition: [
21+
peerdom,
22+
"mapId",
23+
],
24+
},
25+
parentId: {
26+
propDefinition: [
27+
peerdom,
28+
"groupId",
29+
],
30+
},
31+
electable: {
32+
propDefinition: [
33+
peerdom,
34+
"electable",
35+
],
36+
optional: true,
37+
},
38+
external: {
39+
propDefinition: [
40+
peerdom,
41+
"external",
42+
],
43+
optional: true,
44+
},
45+
color: {
46+
propDefinition: [
47+
peerdom,
48+
"color",
49+
],
50+
optional: true,
51+
},
52+
shape: {
53+
propDefinition: [
54+
peerdom,
55+
"shape",
56+
],
57+
optional: true,
58+
},
59+
customFields: {
60+
propDefinition: [
61+
peerdom,
62+
"customFields",
63+
],
64+
optional: true,
65+
},
66+
groupEmail: {
67+
propDefinition: [
68+
peerdom,
69+
"groupEmail",
70+
],
71+
optional: true,
72+
},
73+
},
74+
async run({ $ }) {
75+
try {
76+
const {
77+
peerdom,
78+
customFields,
79+
...data
80+
} = this;
81+
82+
const response = await peerdom.createRole({
83+
$,
84+
data: {
85+
...data,
86+
customFields: parseObject(customFields),
87+
},
88+
});
89+
90+
$.export("$summary", `Successfully created role: ${response.name}`);
91+
return response;
92+
} catch ({ response }) {
93+
throw new ConfigurationError(response.data.message);
94+
}
95+
},
96+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import peerdom from "../../peerdom.app.mjs";
4+
5+
export default {
6+
key: "peerdom-update-role",
7+
name: "Update Role",
8+
description: "Update an existing role's attributes such as name, description, or linked domains. [See the documentation](https://api.peerdom.org/v1/docs)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
peerdom,
13+
roleId: {
14+
propDefinition: [
15+
peerdom,
16+
"roleId",
17+
],
18+
},
19+
name: {
20+
propDefinition: [
21+
peerdom,
22+
"name",
23+
],
24+
optional: true,
25+
},
26+
parentId: {
27+
propDefinition: [
28+
peerdom,
29+
"groupId",
30+
],
31+
},
32+
electable: {
33+
propDefinition: [
34+
peerdom,
35+
"electable",
36+
],
37+
optional: true,
38+
},
39+
external: {
40+
propDefinition: [
41+
peerdom,
42+
"external",
43+
],
44+
optional: true,
45+
},
46+
color: {
47+
propDefinition: [
48+
peerdom,
49+
"color",
50+
],
51+
optional: true,
52+
},
53+
shape: {
54+
propDefinition: [
55+
peerdom,
56+
"shape",
57+
],
58+
optional: true,
59+
},
60+
customFields: {
61+
propDefinition: [
62+
peerdom,
63+
"customFields",
64+
],
65+
optional: true,
66+
},
67+
groupEmail: {
68+
propDefinition: [
69+
peerdom,
70+
"groupEmail",
71+
],
72+
optional: true,
73+
},
74+
},
75+
async run({ $ }) {
76+
try {
77+
const {
78+
peerdom,
79+
roleId,
80+
customFields,
81+
...data
82+
} = this;
83+
84+
const response = await peerdom.updateRole({
85+
$,
86+
roleId,
87+
data: {
88+
...data,
89+
customFields: parseObject(customFields),
90+
},
91+
});
92+
93+
$.export("$summary", `Successfully updated role with ID ${this.roleId}`);
94+
return response;
95+
} catch ({ response }) {
96+
throw new ConfigurationError(response.data.message);
97+
}
98+
},
99+
};
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const LIMIT = 100;
2+
3+
export const SHAPE_OPTIONS = [
4+
"circle",
5+
"hexagon",
6+
];

components/peerdom/common/utils.mjs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/peerdom/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/peerdom",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Peerdom Components",
55
"main": "peerdom.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)