@pipedream/peerdom 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
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.2",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
13
+ type: "action",
14
+ props: {
15
+ peerdom,
16
+ roleId: {
17
+ propDefinition: [
18
+ peerdom,
19
+ "roleId",
20
+ ],
21
+ },
22
+ memberId: {
23
+ propDefinition: [
24
+ peerdom,
25
+ "memberId",
26
+ ],
27
+ },
28
+ percentage: {
29
+ type: "integer",
30
+ label: "Percentage",
31
+ description: "The percentage of the role assigned to the member",
32
+ optional: true,
33
+ min: 0,
34
+ max: 100,
35
+ },
36
+ focus: {
37
+ type: "string",
38
+ label: "Focus",
39
+ description: "The focus of the role assigned to the member",
40
+ optional: true,
41
+ },
42
+ electedUntil: {
43
+ type: "string",
44
+ label: "Elected Until",
45
+ description: "The date until which the member is elected to the role (YYYY-MM-DD)",
46
+ optional: true,
47
+ },
48
+ },
49
+ async run({ $ }) {
50
+ const response = await this.peerdom.assignMemberToRole({
51
+ $,
52
+ roleId: this.roleId,
53
+ data: {
54
+ peerId: this.memberId,
55
+ percentage: this.percentage,
56
+ focus: this.focus,
57
+ electedUntil: this.electedUntil,
58
+ },
59
+ });
60
+
61
+ $.export("$summary", `Successfully assigned member with ID ${this.memberId} to role with ID ${this.roleId}`);
62
+ return response;
63
+ },
64
+ };
@@ -0,0 +1,101 @@
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.2",
10
+ annotations: {
11
+ destructiveHint: false,
12
+ openWorldHint: true,
13
+ readOnlyHint: false,
14
+ },
15
+ type: "action",
16
+ props: {
17
+ peerdom,
18
+ name: {
19
+ propDefinition: [
20
+ peerdom,
21
+ "name",
22
+ ],
23
+ },
24
+ mapId: {
25
+ propDefinition: [
26
+ peerdom,
27
+ "mapId",
28
+ ],
29
+ },
30
+ parentId: {
31
+ propDefinition: [
32
+ peerdom,
33
+ "groupId",
34
+ ],
35
+ },
36
+ electable: {
37
+ propDefinition: [
38
+ peerdom,
39
+ "electable",
40
+ ],
41
+ optional: true,
42
+ },
43
+ external: {
44
+ propDefinition: [
45
+ peerdom,
46
+ "external",
47
+ ],
48
+ optional: true,
49
+ },
50
+ color: {
51
+ propDefinition: [
52
+ peerdom,
53
+ "color",
54
+ ],
55
+ optional: true,
56
+ },
57
+ shape: {
58
+ propDefinition: [
59
+ peerdom,
60
+ "shape",
61
+ ],
62
+ optional: true,
63
+ },
64
+ customFields: {
65
+ propDefinition: [
66
+ peerdom,
67
+ "customFields",
68
+ ],
69
+ optional: true,
70
+ },
71
+ groupEmail: {
72
+ propDefinition: [
73
+ peerdom,
74
+ "groupEmail",
75
+ ],
76
+ optional: true,
77
+ },
78
+ },
79
+ async run({ $ }) {
80
+ try {
81
+ const {
82
+ peerdom,
83
+ customFields,
84
+ ...data
85
+ } = this;
86
+
87
+ const response = await peerdom.createRole({
88
+ $,
89
+ data: {
90
+ ...data,
91
+ customFields: parseObject(customFields),
92
+ },
93
+ });
94
+
95
+ $.export("$summary", `Successfully created role: ${response.name}`);
96
+ return response;
97
+ } catch ({ response }) {
98
+ throw new ConfigurationError(response.data.message);
99
+ }
100
+ },
101
+ };
@@ -0,0 +1,24 @@
1
+ import peerdom from "../../peerdom.app.mjs";
2
+
3
+ export default {
4
+ key: "peerdom-list-group-id-options",
5
+ name: "List Group ID Options",
6
+ description: "Retrieves available options for the Group ID field.",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
14
+ props: {
15
+ peerdom,
16
+ },
17
+ async run({ $ }) {
18
+ const options = await peerdom.propDefinitions.groupId.options.call(this.peerdom);
19
+ $.export("$summary", `Successfully retrieved ${options.length} option${options.length === 1
20
+ ? ""
21
+ : "s"}`);
22
+ return options;
23
+ },
24
+ };
@@ -0,0 +1,24 @@
1
+ import peerdom from "../../peerdom.app.mjs";
2
+
3
+ export default {
4
+ key: "peerdom-list-map-id-options",
5
+ name: "List Map ID Options",
6
+ description: "Retrieves available options for the Map ID field.",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
14
+ props: {
15
+ peerdom,
16
+ },
17
+ async run({ $ }) {
18
+ const options = await peerdom.propDefinitions.mapId.options.call(this.peerdom);
19
+ $.export("$summary", `Successfully retrieved ${options.length} option${options.length === 1
20
+ ? ""
21
+ : "s"}`);
22
+ return options;
23
+ },
24
+ };
@@ -0,0 +1,104 @@
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.2",
10
+ annotations: {
11
+ destructiveHint: true,
12
+ openWorldHint: true,
13
+ readOnlyHint: false,
14
+ },
15
+ type: "action",
16
+ props: {
17
+ peerdom,
18
+ roleId: {
19
+ propDefinition: [
20
+ peerdom,
21
+ "roleId",
22
+ ],
23
+ },
24
+ name: {
25
+ propDefinition: [
26
+ peerdom,
27
+ "name",
28
+ ],
29
+ optional: true,
30
+ },
31
+ parentId: {
32
+ propDefinition: [
33
+ peerdom,
34
+ "groupId",
35
+ ],
36
+ },
37
+ electable: {
38
+ propDefinition: [
39
+ peerdom,
40
+ "electable",
41
+ ],
42
+ optional: true,
43
+ },
44
+ external: {
45
+ propDefinition: [
46
+ peerdom,
47
+ "external",
48
+ ],
49
+ optional: true,
50
+ },
51
+ color: {
52
+ propDefinition: [
53
+ peerdom,
54
+ "color",
55
+ ],
56
+ optional: true,
57
+ },
58
+ shape: {
59
+ propDefinition: [
60
+ peerdom,
61
+ "shape",
62
+ ],
63
+ optional: true,
64
+ },
65
+ customFields: {
66
+ propDefinition: [
67
+ peerdom,
68
+ "customFields",
69
+ ],
70
+ optional: true,
71
+ },
72
+ groupEmail: {
73
+ propDefinition: [
74
+ peerdom,
75
+ "groupEmail",
76
+ ],
77
+ optional: true,
78
+ },
79
+ },
80
+ async run({ $ }) {
81
+ try {
82
+ const {
83
+ peerdom,
84
+ roleId,
85
+ customFields,
86
+ ...data
87
+ } = this;
88
+
89
+ const response = await peerdom.updateRole({
90
+ $,
91
+ roleId,
92
+ data: {
93
+ ...data,
94
+ customFields: parseObject(customFields),
95
+ },
96
+ });
97
+
98
+ $.export("$summary", `Successfully updated role with ID ${this.roleId}`);
99
+ return response;
100
+ } catch ({ response }) {
101
+ throw new ConfigurationError(response.data.message);
102
+ }
103
+ },
104
+ };
@@ -0,0 +1,6 @@
1
+ export const LIMIT = 100;
2
+
3
+ export const SHAPE_OPTIONS = [
4
+ "circle",
5
+ "hexagon",
6
+ ];
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/peerdom",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Pipedream Peerdom Components",
5
5
  "main": "peerdom.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.1.1"
14
17
  }
15
18
  }
package/peerdom.app.mjs CHANGED
@@ -1,11 +1,227 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import {
3
+ LIMIT, SHAPE_OPTIONS,
4
+ } from "./common/constants.mjs";
5
+
1
6
  export default {
2
7
  type: "app",
3
8
  app: "peerdom",
4
- propDefinitions: {},
9
+ propDefinitions: {
10
+ groupId: {
11
+ type: "string",
12
+ label: "Parent ID",
13
+ description: "The ID should be a valid group ID.",
14
+ async options() {
15
+ const data = await this.listGroups();
16
+
17
+ return data.map(({
18
+ id: value, name: label,
19
+ }) => ({
20
+ label,
21
+ value,
22
+ }));
23
+ },
24
+ },
25
+ mapId: {
26
+ type: "string",
27
+ label: "Map ID",
28
+ description: "The ID of the map",
29
+ async options() {
30
+ const data = await this.listMaps();
31
+
32
+ return data.map(({
33
+ id: value, name: label,
34
+ }) => ({
35
+ label,
36
+ value,
37
+ }));
38
+ },
39
+ },
40
+ roleId: {
41
+ type: "string",
42
+ label: "Role ID",
43
+ description: "ID of role to update.",
44
+ async options() {
45
+ const data = await this.listRoles();
46
+
47
+ return data.map(({
48
+ id: value, name: label,
49
+ }) => ({
50
+ label,
51
+ value,
52
+ }));
53
+ },
54
+ },
55
+ memberId: {
56
+ type: "string",
57
+ label: "Member ID",
58
+ description: "The ID of the member",
59
+ async options() {
60
+ const data = await this.listPeers();
61
+
62
+ return data.map(({
63
+ id: value, firstName, lastName,
64
+ }) => ({
65
+ label: `${firstName} ${lastName}`,
66
+ value,
67
+ }));
68
+ },
69
+ },
70
+ name: {
71
+ type: "string",
72
+ label: "Name",
73
+ description: "The name of the role to be created",
74
+ },
75
+ electable: {
76
+ type: "boolean",
77
+ label: "Electable",
78
+ description: "Whether the role is electable or not",
79
+ },
80
+ external: {
81
+ type: "boolean",
82
+ label: "External",
83
+ description: "Set to `true` if node is outside of the organization",
84
+ },
85
+ color: {
86
+ type: "string",
87
+ label: "Color",
88
+ description: "The choice of color for the node in hexadecimal string format, e.g. `#f3a935`",
89
+ },
90
+ shape: {
91
+ type: "string",
92
+ label: "Shape",
93
+ description: "Specifies the shape of the node that determines the visual representation of the node within the interface",
94
+ options: SHAPE_OPTIONS,
95
+ optional: true,
96
+ },
97
+ customFields: {
98
+ type: "object",
99
+ label: "Custom Fields",
100
+ description: "The custom fields for a group/role. You can add the properties from the predefined custom fields. [See the documentation](https://api.peerdom.org/v1/docs#tag/Roles/operation/postRole) for further details.",
101
+ },
102
+ groupEmail: {
103
+ type: "string",
104
+ label: "Group Email",
105
+ description: "Email for node (group/role) communication",
106
+ optional: true,
107
+ },
108
+
109
+ circleId: {
110
+ type: "string",
111
+ label: "Circle ID",
112
+ description: "The ID of the circle (organization)",
113
+ },
114
+ roleName: {
115
+ type: "string",
116
+ label: "Role Name",
117
+ description: "The name of the role to be created",
118
+ },
119
+ description: {
120
+ type: "string",
121
+ label: "Description",
122
+ description: "Optional description for the role",
123
+ optional: true,
124
+ },
125
+ linkedDomains: {
126
+ type: "string[]",
127
+ label: "Linked Domains",
128
+ description: "Optional linked domains for the role",
129
+ optional: true,
130
+ },
131
+ },
5
132
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
133
+ _baseUrl() {
134
+ return "https://api.peerdom.org/v1";
135
+ },
136
+ _headers() {
137
+ return {
138
+ "content-type": "application/json",
139
+ "x-api-key": `${this.$auth.api_key}`,
140
+ };
141
+ },
142
+ _makeRequest({
143
+ $ = this, path, ...opts
144
+ }) {
145
+ return axios($, {
146
+ url: this._baseUrl() + path,
147
+ headers: this._headers(),
148
+ ...opts,
149
+ });
150
+ },
151
+ listGroups(opts = {}) {
152
+ return this._makeRequest({
153
+ path: "/groups",
154
+ ...opts,
155
+ });
156
+ },
157
+ listMaps(opts = {}) {
158
+ return this._makeRequest({
159
+ path: "/maps",
160
+ ...opts,
161
+ });
162
+ },
163
+ listRoles(opts = {}) {
164
+ return this._makeRequest({
165
+ path: "/roles",
166
+ ...opts,
167
+ });
168
+ },
169
+ listPeers(opts = {}) {
170
+ return this._makeRequest({
171
+ path: "/peers",
172
+ ...opts,
173
+ });
174
+ },
175
+ createRole(opts = {}) {
176
+ return this._makeRequest({
177
+ method: "POST",
178
+ path: "/roles",
179
+ ...opts,
180
+ });
181
+ },
182
+ updateRole({
183
+ roleId, ...opts
184
+ }) {
185
+ return this._makeRequest({
186
+ method: "PUT",
187
+ path: `/roles/${roleId}`,
188
+ ...opts,
189
+ });
190
+ },
191
+ async assignMemberToRole({
192
+ roleId, ...opts
193
+ }) {
194
+ return this._makeRequest({
195
+ method: "POST",
196
+ path: `/roles/${roleId}/peers`,
197
+ ...opts,
198
+ });
199
+ },
200
+ async *paginate({
201
+ fn, params = {}, maxResults = null, ...opts
202
+ }) {
203
+ let hasMore = false;
204
+ let count = 0;
205
+ let page = 0;
206
+
207
+ do {
208
+ params.limit = LIMIT;
209
+ params.offset = (LIMIT * page++) + 1;
210
+ const data = await fn({
211
+ params,
212
+ ...opts,
213
+ });
214
+ for (const d of data) {
215
+ yield d;
216
+
217
+ if (maxResults && ++count === maxResults) {
218
+ return count;
219
+ }
220
+ }
221
+
222
+ hasMore = data.length;
223
+
224
+ } while (hasMore);
9
225
  },
10
226
  },
11
- };
227
+ };
@@ -0,0 +1,61 @@
1
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
+ import peerdom from "../../peerdom.app.mjs";
3
+
4
+ export default {
5
+ props: {
6
+ peerdom,
7
+ db: "$.service.db",
8
+ timer: {
9
+ type: "$.interface.timer",
10
+ default: {
11
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12
+ },
13
+ },
14
+ },
15
+ methods: {
16
+ _getLastId() {
17
+ return this.db.get("lastId") || "";
18
+ },
19
+ _setLastId(lastId) {
20
+ this.db.set("lastId", lastId);
21
+ },
22
+ sortItems(items) {
23
+ return items;
24
+ },
25
+ async emitEvent(maxResults = false) {
26
+ const lastId = this._getLastId();
27
+ const fn = this.getFunction();
28
+
29
+ const response = this.sortItems(await fn());
30
+
31
+ let responseArray = [];
32
+ for (const item of response.reverse()) {
33
+ if (item.id == lastId) break;
34
+ responseArray.push(item);
35
+ }
36
+
37
+ if (responseArray.length) {
38
+ if (maxResults && (responseArray.length > maxResults)) {
39
+ responseArray.length = maxResults;
40
+ }
41
+ this._setLastId(responseArray[0].id);
42
+ }
43
+
44
+ for (const item of responseArray.reverse()) {
45
+ this.$emit(item, {
46
+ id: item.id,
47
+ summary: this.getSummary(item),
48
+ ts: Date.now(),
49
+ });
50
+ }
51
+ },
52
+ },
53
+ hooks: {
54
+ async deploy() {
55
+ await this.emitEvent(25);
56
+ },
57
+ },
58
+ async run() {
59
+ await this.emitEvent();
60
+ },
61
+ };
@@ -0,0 +1,22 @@
1
+ import common from "../common/base.mjs";
2
+ import sampleEmit from "./test-event.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "peerdom-new-member",
7
+ name: "New Member Added",
8
+ description: "Emit new event when a new member is added to a group. [See the documentation](https://api.peerdom.org/v1/docs#tag/Peers/operation/getPeers)",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ methods: {
13
+ ...common.methods,
14
+ getFunction() {
15
+ return this.peerdom.listPeers;
16
+ },
17
+ getSummary(item) {
18
+ return `New Member: ${item.firstName} ${item.lastName || ""}`;
19
+ },
20
+ },
21
+ sampleEmit,
22
+ };
@@ -0,0 +1,19 @@
1
+ export default {
2
+ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
3
+ "firstName": "string",
4
+ "lastName": "string",
5
+ "nickName": "string",
6
+ "slug": "string",
7
+ "avatarUrl": "string",
8
+ "birthdate": "2019-08-24T14:15:22Z",
9
+ "contribution": 0,
10
+ "contributionUnit": "string",
11
+ "customFields": [
12
+ {
13
+ "name": "string",
14
+ "values": [
15
+ "string"
16
+ ]
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,25 @@
1
+ import common from "../common/base.mjs";
2
+ import sampleEmit from "./test-event.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "peerdom-new-role",
7
+ name: "New Role Created",
8
+ description: "Emit new event when a new role is created in a circle. [See the documentation](https://api.peerdom.org/v1/docs)",
9
+ version: "0.0.1",
10
+ type: "source",
11
+ dedupe: "unique",
12
+ methods: {
13
+ ...common.methods,
14
+ getFunction() {
15
+ return this.peerdom.listRoles;
16
+ },
17
+ getSummary(item) {
18
+ return `New Role Created: ${item.name}`;
19
+ },
20
+ sortItems(items) {
21
+ return items.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
22
+ },
23
+ },
24
+ sampleEmit,
25
+ };
@@ -0,0 +1,50 @@
1
+ export default {
2
+ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
3
+ "name": "string",
4
+ "color": "string",
5
+ "createdAt": "2019-08-24T14:15:22Z",
6
+ "parentId": "70850378-7d3c-4f45-91b7-942d4dfbbd43",
7
+ "slug": "string",
8
+ "external": true,
9
+ "electable": true,
10
+ "salaryLevel": "string",
11
+ "mirrored": true,
12
+ "shape": "string",
13
+ "customFields": [
14
+ {
15
+ "name": "string",
16
+ "values": [
17
+ "string"
18
+ ]
19
+ }
20
+ ],
21
+ "holders": [
22
+ {
23
+ "peerId": "60a07d40-746d-414c-b70b-908ca16e7459",
24
+ "contribution": 0,
25
+ "contributionUnit": "string"
26
+ }
27
+ ],
28
+ "goals": [
29
+ {
30
+ "endedAt": "2019-05-17",
31
+ "startedAt": "2019-05-17",
32
+ "archived": true,
33
+ "data": {
34
+ "order": "string",
35
+ "name": "string",
36
+ "isComplete": true,
37
+ "subgoals": [
38
+ {
39
+ "name": "string",
40
+ "percentComplete": 0,
41
+ "isComplete": true,
42
+ "amountComplete": 0,
43
+ "targetAmount": 0
44
+ }
45
+ ]
46
+ }
47
+ }
48
+ ],
49
+ "groupEmail": "string"
50
+ }