Skip to content

Commit 6d47284

Browse files
committed
peerdom init
1 parent d285e5f commit 6d47284

File tree

7 files changed

+417
-6
lines changed

7 files changed

+417
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import peerdom from "../../peerdom.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "peerdom-assign-member-to-role",
6+
name: "Assign Member to Role",
7+
description: "Assigns a member to a role within a circle using the Peerdom API. [See the documentation](https://api.peerdom.org/v1/docs)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
peerdom,
12+
roleId: {
13+
propDefinition: [
14+
peerdom,
15+
"roleId",
16+
],
17+
},
18+
memberId: {
19+
propDefinition: [
20+
peerdom,
21+
"memberId",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.peerdom.assignMemberToRole({
27+
roleId: this.roleId,
28+
memberId: this.memberId,
29+
});
30+
31+
$.export("$summary", `Successfully assigned member with ID ${this.memberId} to role with ID ${this.roleId}`);
32+
return response;
33+
},
34+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import peerdom from "../../peerdom.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "peerdom-create-role",
6+
name: "Create Role",
7+
description: "Create a new role within a specified circle. [See the documentation](https://api.peerdom.org/v1/docs)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
peerdom,
12+
circleId: {
13+
propDefinition: [
14+
peerdom,
15+
"circleId",
16+
],
17+
},
18+
roleName: {
19+
propDefinition: [
20+
peerdom,
21+
"roleName",
22+
],
23+
},
24+
description: {
25+
propDefinition: [
26+
peerdom,
27+
"description",
28+
],
29+
optional: true,
30+
},
31+
linkedDomains: {
32+
propDefinition: [
33+
peerdom,
34+
"linkedDomains",
35+
],
36+
optional: true,
37+
},
38+
},
39+
async run({ $ }) {
40+
const response = await this.peerdom.createRole({
41+
circleId: this.circleId,
42+
roleName: this.roleName,
43+
description: this.description,
44+
linkedDomains: this.linkedDomains,
45+
});
46+
47+
$.export("$summary", `Successfully created role: ${response.name}`);
48+
return response;
49+
},
50+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import peerdom from "../../peerdom.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "peerdom-update-role",
6+
name: "Update Role",
7+
description: "Update an existing role's attributes such as name, description, or linked domains. [See the documentation](https://api.peerdom.org/v1/docs)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
peerdom,
12+
roleId: {
13+
propDefinition: [
14+
peerdom,
15+
"roleId",
16+
],
17+
},
18+
roleName: {
19+
propDefinition: [
20+
peerdom,
21+
"roleName",
22+
],
23+
optional: true,
24+
},
25+
description: {
26+
propDefinition: [
27+
peerdom,
28+
"description",
29+
],
30+
optional: true,
31+
},
32+
linkedDomains: {
33+
propDefinition: [
34+
peerdom,
35+
"linkedDomains",
36+
],
37+
optional: true,
38+
},
39+
},
40+
async run({ $ }) {
41+
const data = {
42+
...(this.roleName && {
43+
name: this.roleName,
44+
}),
45+
...(this.description && {
46+
customFields: {
47+
Description: this.description,
48+
},
49+
}),
50+
...(this.linkedDomains && {
51+
customFields: {
52+
LinkedDomains: this.linkedDomains,
53+
},
54+
}),
55+
};
56+
57+
const response = await this.peerdom.updateRole({
58+
roleId: this.roleId,
59+
...data,
60+
});
61+
62+
$.export("$summary", `Successfully updated role with ID ${this.roleId}`);
63+
return response;
64+
},
65+
};

components/peerdom/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

components/peerdom/peerdom.app.mjs

+121-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,127 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "peerdom",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
circleId: {
8+
type: "string",
9+
label: "Circle ID",
10+
description: "The ID of the circle (organization)",
11+
},
12+
roleId: {
13+
type: "string",
14+
label: "Role ID",
15+
description: "The ID of the role",
16+
},
17+
memberId: {
18+
type: "string",
19+
label: "Member ID",
20+
description: "The ID of the member",
21+
},
22+
roleName: {
23+
type: "string",
24+
label: "Role Name",
25+
description: "The name of the role to be created",
26+
},
27+
description: {
28+
type: "string",
29+
label: "Description",
30+
description: "Optional description for the role",
31+
optional: true,
32+
},
33+
linkedDomains: {
34+
type: "string[]",
35+
label: "Linked Domains",
36+
description: "Optional linked domains for the role",
37+
optional: true,
38+
},
39+
},
540
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
41+
_baseUrl() {
42+
return "https://api.peerdom.org/v1";
43+
},
44+
async _makeRequest(opts = {}) {
45+
const {
46+
$ = this, method = "GET", path = "/", headers, ...otherOpts
47+
} = opts;
48+
return axios($, {
49+
...otherOpts,
50+
method,
51+
url: this._baseUrl() + path,
52+
headers: {
53+
...headers,
54+
"X-Api-Key": this.$auth.api_key,
55+
},
56+
});
57+
},
58+
async createRole({
59+
circleId, roleName, description, linkedDomains,
60+
}) {
61+
const data = {
62+
name: roleName,
63+
parentId: circleId,
64+
...(description && {
65+
customFields: {
66+
Description: description,
67+
},
68+
}),
69+
...(linkedDomains && {
70+
customFields: {
71+
LinkedDomains: linkedDomains,
72+
},
73+
}),
74+
};
75+
return this._makeRequest({
76+
method: "POST",
77+
path: "/roles",
78+
data,
79+
});
80+
},
81+
async assignMemberToRole({
82+
roleId, memberId,
83+
}) {
84+
const data = {
85+
roleId,
86+
memberId,
87+
};
88+
return this._makeRequest({
89+
method: "POST",
90+
path: `/roles/${roleId}/assign`,
91+
data,
92+
});
93+
},
94+
async updateRole({
95+
roleId, name, description, linkedDomains,
96+
}) {
97+
const data = {
98+
...(name && {
99+
name,
100+
}),
101+
...(description && {
102+
customFields: {
103+
Description: description,
104+
},
105+
}),
106+
...(linkedDomains && {
107+
customFields: {
108+
LinkedDomains: linkedDomains,
109+
},
110+
}),
111+
};
112+
return this._makeRequest({
113+
method: "PATCH",
114+
path: `/roles/${roleId}`,
115+
data,
116+
});
117+
},
118+
async emitNewRoleEvent({ circleId }) {
119+
// Logic to listen for a new role event
120+
// and emit the event
121+
},
122+
async emitNewMemberEvent({ circleId }) {
123+
// Logic to listen for a new member event
124+
// and emit the event
9125
},
10126
},
11-
};
127+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import {
2+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
3+
} from "@pipedream/platform";
4+
import peerdom from "../../peerdom.app.mjs";
5+
6+
export default {
7+
key: "peerdom-new-member",
8+
name: "New Member Added",
9+
description: "Emit new event when a new member is added to a circle or assigned to a role. [See the documentation](https://api.peerdom.org/v1/docs)",
10+
version: "0.0.{{ts}}",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
peerdom,
15+
db: "$.service.db",
16+
timer: {
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
circleId: {
23+
propDefinition: [
24+
peerdom,
25+
"circleId",
26+
],
27+
},
28+
},
29+
methods: {
30+
_getLastTimestamp() {
31+
return this.db.get("lastTimestamp") || 0;
32+
},
33+
_setLastTimestamp(ts) {
34+
this.db.set("lastTimestamp", ts);
35+
},
36+
async _getNewMembers(circleId, since) {
37+
return this.peerdom._makeRequest({
38+
path: `/circles/${circleId}/members?since=${since}`,
39+
});
40+
},
41+
},
42+
hooks: {
43+
async deploy() {
44+
const currentTimestamp = Date.now();
45+
const newMembers = await this._getNewMembers(this.circleId, 0);
46+
47+
newMembers.slice(0, 50).forEach((member) => {
48+
this.$emit(member, {
49+
id: member.id,
50+
summary: `New Member Added: ${member.name}`,
51+
ts: Date.parse(member.createdAt),
52+
});
53+
});
54+
55+
this._setLastTimestamp(currentTimestamp);
56+
},
57+
async activate() {
58+
// No activation needed for polling
59+
},
60+
async deactivate() {
61+
// No deactivation needed for polling
62+
},
63+
},
64+
async run() {
65+
const lastTimestamp = this._getLastTimestamp();
66+
const newMembers = await this._getNewMembers(this.circleId, lastTimestamp);
67+
68+
newMembers.forEach((member) => {
69+
this.$emit(member, {
70+
id: member.id,
71+
summary: `New Member Added: ${member.name}`,
72+
ts: Date.parse(member.createdAt),
73+
});
74+
});
75+
76+
if (newMembers.length) {
77+
const latestTimestamp = Date.parse(newMembers[newMembers.length - 1].createdAt);
78+
this._setLastTimestamp(latestTimestamp);
79+
}
80+
},
81+
};

0 commit comments

Comments
 (0)